API Reference

Core

API reference for the Core package - HTTP client, authentication and base types.

Core Package

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.

Installation

pnpm add @fatturazione-elettronica-aruba/core

ArubaClient

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,
});

ArubaClientOptions

PropertyTypeDefaultDescription
environment'demo' | 'production'RequiredAPI environment
timeoutnumber30000Request timeout in milliseconds
maxRetriesnumber3Max retries for rate limit errors
tokenStorageTokenStorageMemoryTokenStorageCustom token storage implementation
autoRefreshbooleantrueAuto-refresh expired tokens
refreshMarginnumber60Seconds before expiry to refresh

Properties

PropertyTypeDescription
authAuthClientAuthentication client
httpHttpClientHTTP client for direct API calls

Methods

// Check if client is authenticated
client.isAuthenticated(): boolean

AuthClient

Handles OAuth2 authentication and token management.

signIn(username, password)

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

refresh(refreshToken?)

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

getUserInfo()

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

getMulticedenti(params?)

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>

isAuthenticated()

Checks if a valid token is stored.

if (client.auth.isAuthenticated()) {
  // Token is available
}

HttpClient

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' });

HttpClientOptions

PropertyTypeDefaultDescription
environmentEnvironmentRequiredAPI environment
timeoutnumber30000Request timeout in ms
maxRetriesnumber3Max retries for 429 errors
retryDelaynumber1000Base delay between retries
headersRecord<string, string>-Additional headers

Methods

// 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

TokenStorage

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;
}

MemoryTokenStorage

Default in-memory implementation (tokens lost on restart).

import { MemoryTokenStorage } from '@fatturazione-elettronica-aruba/core';

const storage = new MemoryTokenStorage();

Custom Implementation Example

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'),
});

Types

Environment

type Environment = 'demo' | 'production';

AuthToken

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;
}

UserInfo

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;
}

Multicedente

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';

PagedResponse

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)
}

Constants

Environment URLs

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'

Rate Limits

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

File Limits

import { FILE_LIMITS } from '@fatturazione-elettronica-aruba/core';

FILE_LIMITS.maxFileSize  // 5242880 (5 MB)

Aruba Constants

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';