Il package @fatturazione-elettronica-aruba/notifications fornisce metodi per recuperare e gestire le notifiche SDI (Sistema di Interscambio) per fatture inviate e ricevute.
pnpm add @fatturazione-elettronica-aruba/notifications
import { NotificationsClient } from '@fatturazione-elettronica-aruba/notifications';
const notifications = new NotificationsClient({
httpClient: client.http,
});
Opzioni:
| Nome | Tipo | Richiesto | Descrizione |
|---|---|---|---|
httpClient | HttpClient | Sì | Istanza HTTP client da ArubaClient |
Recupera le notifiche per le fatture inviate.
async getSentNotifications(params: GetNotificationsParams): Promise<NotificationsResponse>
Parametri:
| Nome | Tipo | Richiesto | Descrizione |
|---|---|---|---|
id | string | No | Identificativo SDI della fattura |
filename | string | No | Nome file della fattura |
id o filename deve essere fornito.Esempio:
const response = await notifications.getSentNotifications({
filename: 'IT01234567890_00001.xml',
});
console.log(`Trovate ${response.count} notifiche`);
for (const notification of response.notifications) {
console.log(`${notification.docType}: ${notification.notificationDate}`);
}
Recupera il contenuto completo di una specifica notifica per una fattura inviata.
async getSentNotificationDetail(params: GetNotificationDetailParams): Promise<Notification>
Parametri:
| Nome | Tipo | Richiesto | Descrizione |
|---|---|---|---|
filename | string | Sì | Nome file della notifica |
Esempio:
const notification = await notifications.getSentNotificationDetail({
filename: 'IT01234567890_00001_RC_001.xml',
});
console.log('Contenuto file notifica:', notification.file);
Recupera le notifiche per le fatture ricevute.
async getReceivedNotifications(params: GetNotificationsParams): Promise<NotificationsResponse>
Parametri: Come getSentNotifications
Recupera il contenuto completo di una specifica notifica per una fattura ricevuta.
async getReceivedNotificationDetail(params: GetNotificationDetailParams): Promise<Notification>
Parametri: Come getSentNotificationDetail
Tipi di notifica SDI:
| Codice | Nome | Descrizione |
|---|---|---|
RC | Ricevuta di Consegna | La fattura è stata consegnata al destinatario |
NS | Notifica di Scarto | La fattura è stata scartata per errori di validazione |
MC | Mancata Consegna | La fattura non è stata consegnata (destinatario irraggiungibile) |
NE | Notifica Esito | Esito di accettazione/rifiuto del committente (EC01/EC02) |
DT | Decorrenza Termini | Scaduti i 15 giorni senza risposta del committente |
AT | Attestazione di Trasmissione | Certificato di trasmissione (per fatture PA) |
type NotificationType = 'RC' | 'NS' | 'MC' | 'NE' | 'DT' | 'AT';
Codici esito committente (usati nelle notifiche NE):
| Codice | Descrizione |
|---|---|
EC01 | Fattura accettata |
EC02 | Fattura rifiutata |
type EsitoResult = 'EC01' | 'EC02';
interface Notification {
date: string; // Data fattura
docType: NotificationType; // Tipo notifica (RC, NS, MC, ecc.)
file: string; // XML notifica codificato Base64
filename: string; // Nome file notifica
invoiceId: string; // Identificativo SDI
notificationDate: string; // Data ricezione notifica
number: string | null; // Numero fattura
result: EsitoResult | null; // EC01/EC02 (solo per notifiche NE)
}
interface NotificationsResponse {
count: number; // Numero totale di notifiche
notifications: Notification[]; // Array di notifiche
}
interface GetNotificationsParams {
id?: string; // Identificativo SDI
filename?: string; // Nome file fattura
}
interface GetNotificationDetailParams {
filename: string; // Nome file notifica
}
Fattura Inviata
│
▼
┌─────────┐
│ NS │──── Scartata (errori di validazione)
└────┬────┘
│ Valida
▼
┌─────────┐
│ RC / MC │──── Consegnata (RC) o Mancata consegna (MC)
└────┬────┘
│ Consegnata (RC)
▼
┌─────────┐
│ NE │──── Esito committente (EC01: accetta, EC02: rifiuta)
└────┬────┘
│ Nessuna risposta entro 15 giorni
▼
┌─────────┐
│ DT │──── Decorrenza termini (accettazione tacita)
└─────────┘
async function attendiConsegna(
notifications: NotificationsClient,
filename: string,
maxTentativi = 10,
intervalloMs = 30000
): Promise<Notification | null> {
for (let i = 0; i < maxTentativi; i++) {
const response = await notifications.getSentNotifications({ filename });
const consegna = response.notifications.find(
(n) => n.docType === 'RC' || n.docType === 'NS' || n.docType === 'MC'
);
if (consegna) {
return consegna;
}
await new Promise((resolve) => setTimeout(resolve, intervalloMs));
}
return null;
}