The @fatturazione-elettronica-aruba/core package is the foundation of the SDK. It provides the HTTP client, OAuth2 authentication, and all base types used across other packages.
pnpm add @fatturazione-elettronica-aruba/core
Main entry point that combines HTTP client and authentication.
import { ArubaClient } from '@fatturazione-elettronica-aruba/core';
const client = new ArubaClient({
environment: 'production',
timeout: 30000,
maxRetries: 3,
});
| Property | Type | Default | Description |
|---|---|---|---|
environment | 'demo' | 'production' | Required | API environment |
timeout | number | 30000 | Request timeout in milliseconds |
maxRetries | number | 3 | Max retries for rate limit errors |
tokenStorage | TokenStorage | MemoryTokenStorage | Custom token storage implementation |
autoRefresh | boolean | true | Auto-refresh expired tokens |
refreshMargin | number | 60 | Seconds before expiry to refresh |
| Property | Type | Description |
|---|---|---|
auth | AuthClient | Authentication client |
http | HttpClient | HTTP client for direct API calls |
// Check if client is authenticated
client.isAuthenticated(): boolean
Handles OAuth2 authentication and token management.
Authenticates with Aruba credentials and stores the token.
const token = await client.auth.signIn('user@example.com', 'password');
// Token is automatically stored and used for subsequent requests
Returns: AuthToken
Refreshes the access token. If no refresh token is provided, uses the stored one.
const newToken = await client.auth.refresh();
// Or with explicit refresh token
const newToken = await client.auth.refresh('refresh_token_value');
Returns: AuthToken
Retrieves information about the authenticated user.
const info = await client.auth.getUserInfo();
console.log(info.vatCode); // VAT number
console.log(info.fiscalCode); // Fiscal code
console.log(info.accountStatus.expired); // Account status
console.log(info.usageStatus.usedSpaceKB); // Used storage
Returns: UserInfo
Retrieves the list of companies for multi-company accounts (Premium feature).
const result = await client.auth.getMulticedenti({
page: 0,
size: 20,
status: 'ACTIVE',
});
for (const company of result.content) {
console.log(company.vatCode, company.description);
}
Returns: PagedResponse<Multicedente>
Checks if a valid token is stored.
if (client.auth.isAuthenticated()) {
// Token is available
}
Low-level HTTP client for direct API calls. Usually you don't need to use this directly.
const http = client.http;
// GET request
const data = await http.get<ResponseType>('ws', '/api/v2/endpoint', { param: 'value' });
// POST request
const result = await http.post<ResponseType>('ws', '/api/v2/endpoint', { body: 'data' });
| Property | Type | Default | Description |
|---|---|---|---|
environment | Environment | Required | API environment |
timeout | number | 30000 | Request timeout in ms |
maxRetries | number | 3 | Max retries for 429 errors |
retryDelay | number | 1000 | Base delay between retries |
headers | Record<string, string> | - | Additional headers |
// GET with query parameters
http.get<T>(baseType: 'auth' | 'ws', path: string, params?: object, options?: RequestOptions): Promise<T>
// POST with JSON body
http.post<T>(baseType: 'auth' | 'ws', path: string, body?: unknown, options?: RequestOptions): Promise<T>
// POST with form data
http.postForm<T>(baseType: 'auth' | 'ws', path: string, data: Record<string, string>, options?: RequestOptions): Promise<T>
// Token management
http.setAccessToken(token: string | null): void
http.getAccessToken(): string | null
Interface for custom token persistence. Implement this to store tokens in localStorage, database, etc.
interface TokenStorage {
getToken(): AuthToken | null;
setToken(token: AuthToken): void;
clearToken(): void;
}
Default in-memory implementation (tokens lost on restart).
import { MemoryTokenStorage } from '@fatturazione-elettronica-aruba/core';
const storage = new MemoryTokenStorage();
class RedisTokenStorage implements TokenStorage {
constructor(private redis: RedisClient, private key: string) {}
getToken(): AuthToken | null {
const data = this.redis.get(this.key);
return data ? JSON.parse(data) : null;
}
setToken(token: AuthToken): void {
this.redis.set(this.key, JSON.stringify(token));
}
clearToken(): void {
this.redis.del(this.key);
}
}
const client = new ArubaClient({
environment: 'production',
tokenStorage: new RedisTokenStorage(redis, 'aruba:token'),
});
type Environment = 'demo' | 'production';
interface AuthToken {
access_token: string;
token_type: 'bearer';
expires_in: number; // Seconds (typically 1800 = 30 min)
refresh_token: string;
userName: string;
'as:client_id': string;
'.issued': string;
'.expires': string;
}
interface UserInfo {
username: string;
pec: string;
userDescription: string;
countryCode: string;
vatCode: string;
fiscalCode: string;
accountStatus: AccountStatus;
usageStatus: UsageStatus;
}
interface AccountStatus {
expired: boolean;
expirationDate: string;
}
interface UsageStatus {
usedSpaceKB: number;
maxSpaceKB: number;
}
interface Multicedente {
id: string;
description: string;
countryCode: string;
vatCode: string;
usedSpaceKB: number;
creationDate: string;
status: MulticedenteStatus;
}
type MulticedenteStatus =
| 'ACTIVE'
| 'INACTIVE'
| 'PENDING'
| 'REQUESTED_FOR_ACTIVATION'
| 'REQUESTED_FOR_DEACTIVATION';
Generic paginated response type used across the SDK.
interface PagedResponse<T> {
content: T[];
totalElements: number;
totalPages: number;
size: number;
number: number; // Current page (0-indexed)
}
import { ENVIRONMENT_URLS } from '@fatturazione-elettronica-aruba/core';
ENVIRONMENT_URLS.demo.authUrl // 'https://demoauth.fatturazioneelettronica.aruba.it'
ENVIRONMENT_URLS.demo.wsUrl // 'https://demows.fatturazioneelettronica.aruba.it'
ENVIRONMENT_URLS.production.authUrl // 'https://auth.fatturazioneelettronica.aruba.it'
ENVIRONMENT_URLS.production.wsUrl // 'https://ws.fatturazioneelettronica.aruba.it'
import { RATE_LIMITS } from '@fatturazione-elettronica-aruba/core';
RATE_LIMITS.auth // 1 request/minute
RATE_LIMITS.upload // 30 requests/minute
RATE_LIMITS.search // 12 requests/minute
import { FILE_LIMITS } from '@fatturazione-elettronica-aruba/core';
FILE_LIMITS.maxFileSize // 5242880 (5 MB)
Constants needed when building invoices for Aruba's intermediary service.
import { ARUBA_CONSTANTS } from '@fatturazione-elettronica-aruba/core';
ARUBA_CONSTANTS.codiceDestinatario // 'KRRH6B9'
ARUBA_CONSTANTS.idTrasmittente // 'IT01879020517'
Or import individually:
import {
ARUBA_ID_TRASMITTENTE, // '01879020517'
ARUBA_CODICE_DESTINATARIO, // 'KRRH6B9'
ARUBA_COUNTRY_CODE, // 'IT'
} from '@fatturazione-elettronica-aruba/core';