Guide

Notifiche

Gestione notifiche SDI

Notifiche

Recupero notifiche SDI per fatture inviate e ricevute.

Setup

import { ArubaClient } from '@fatturazione-elettronica-aruba/core';
import { NotificationsClient } from '@fatturazione-elettronica-aruba/notifications';

const client = new ArubaClient({ environment: 'demo' });
await client.auth.signin('username', 'password');

const notifications = new NotificationsClient(client.http);

Notifiche Fatture Inviate

const result = await notifications.getSentNotifications({
  invoiceFilename: 'IT01234567890_00001.xml',
});

for (const n of result.notifications) {
  console.log(`${n.docType}: ${n.filename}`);
}

// Dettaglio
const detail = await notifications.getSentNotificationDetail({
  filename: 'IT01234567890_00001_RC_001.xml',
});

Notifiche Fatture Ricevute

const result = await notifications.getReceivedNotifications({
  invoiceFilename: 'IT09876543210_00001.xml',
});

const detail = await notifications.getReceivedNotificationDetail({
  filename: 'IT09876543210_00001_NE_001.xml',
});

Tipi di Notifica

CodiceNomeDescrizione
RCRicevuta di ConsegnaFattura consegnata al destinatario
NSNotifica di ScartoFattura scartata per errori
MCMancata ConsegnaImpossibile consegnare
NENotifica EsitoEsito committente (EC01/EC02)
DTDecorrenza TerminiNessun esito entro 15 giorni
ATAttestazione TrasmissioneConferma trasmissione PA

Polling Notifiche

async function waitForDelivery(filename: string): Promise<boolean> {
  for (let i = 0; i < 10; i++) {
    const result = await notifications.getSentNotifications({
      invoiceFilename: filename,
    });

    if (result.notifications.some(n => n.docType === 'RC')) {
      return true; // Consegnata
    }

    if (result.notifications.some(n => n.docType === 'NS')) {
      return false; // Scartata
    }

    await new Promise(r => setTimeout(r, 60000));
  }

  return false;
}

Decodifica Contenuto

import { decodeBase64ToString } from '@fatturazione-elettronica-aruba/utils';

const detail = await notifications.getSentNotificationDetail({
  filename: 'IT01234567890_00001_RC_001.xml',
});

const xmlContent = decodeBase64ToString(detail.file);
console.log(xmlContent);