@dwast/verifactu-lib 0.1.0-beta.1 → 0.1.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/aeat/client.d.ts +115 -14
- package/dist/cjs/aeat/client.d.ts.map +1 -1
- package/dist/cjs/aeat/client.js +223 -47
- package/dist/cjs/aeat/client.js.map +1 -1
- package/dist/cjs/aeat/index.d.ts +1 -0
- package/dist/cjs/aeat/index.d.ts.map +1 -1
- package/dist/cjs/aeat/index.js +1 -0
- package/dist/cjs/aeat/index.js.map +1 -1
- package/dist/cjs/aeat/response.d.ts +80 -0
- package/dist/cjs/aeat/response.d.ts.map +1 -0
- package/dist/cjs/aeat/response.js +118 -0
- package/dist/cjs/aeat/response.js.map +1 -0
- package/dist/cjs/core/hash/chain.d.ts +42 -0
- package/dist/cjs/core/hash/chain.d.ts.map +1 -1
- package/dist/cjs/core/hash/chain.js +40 -0
- package/dist/cjs/core/hash/chain.js.map +1 -1
- package/dist/cjs/core/index.d.ts +2 -0
- package/dist/cjs/core/index.d.ts.map +1 -1
- package/dist/cjs/core/index.js +2 -0
- package/dist/cjs/core/index.js.map +1 -1
- package/dist/cjs/core/models/index.d.ts +0 -1
- package/dist/cjs/core/models/index.d.ts.map +1 -1
- package/dist/cjs/core/models/index.js +0 -1
- package/dist/cjs/core/models/index.js.map +1 -1
- package/dist/cjs/core/models/invoice.d.ts +42 -17
- package/dist/cjs/core/models/invoice.d.ts.map +1 -1
- package/dist/cjs/core/utils/date.d.ts +16 -0
- package/dist/cjs/core/utils/date.d.ts.map +1 -0
- package/dist/cjs/core/utils/date.js +27 -0
- package/dist/cjs/core/utils/date.js.map +1 -0
- package/dist/cjs/core/utils/index.d.ts +2 -0
- package/dist/cjs/core/utils/index.d.ts.map +1 -0
- package/dist/cjs/core/utils/index.js +18 -0
- package/dist/cjs/core/utils/index.js.map +1 -0
- package/dist/cjs/core/validation/index.d.ts +2 -0
- package/dist/cjs/core/validation/index.d.ts.map +1 -0
- package/dist/cjs/core/validation/index.js +18 -0
- package/dist/cjs/core/validation/index.js.map +1 -0
- package/dist/cjs/core/validation/validate.d.ts +18 -0
- package/dist/cjs/core/validation/validate.d.ts.map +1 -0
- package/dist/cjs/core/validation/validate.js +65 -0
- package/dist/cjs/core/validation/validate.js.map +1 -0
- package/dist/cjs/core/xml/generator.d.ts +117 -11
- package/dist/cjs/core/xml/generator.d.ts.map +1 -1
- package/dist/cjs/core/xml/generator.js +239 -64
- package/dist/cjs/core/xml/generator.js.map +1 -1
- package/dist/cjs/integration/accountability.d.ts +41 -0
- package/dist/cjs/integration/accountability.d.ts.map +1 -0
- package/dist/cjs/integration/accountability.js +92 -0
- package/dist/cjs/integration/accountability.js.map +1 -0
- package/dist/cjs/integration/index.d.ts +2 -0
- package/dist/cjs/integration/index.d.ts.map +1 -1
- package/dist/cjs/integration/index.js +2 -0
- package/dist/cjs/integration/index.js.map +1 -1
- package/dist/cjs/integration/p12.d.ts +58 -0
- package/dist/cjs/integration/p12.d.ts.map +1 -0
- package/dist/cjs/integration/p12.js +127 -0
- package/dist/cjs/integration/p12.js.map +1 -0
- package/dist/cjs/integration/repository.d.ts +4 -3
- package/dist/cjs/integration/repository.d.ts.map +1 -1
- package/dist/cjs/integration/service.d.ts +11 -2
- package/dist/cjs/integration/service.d.ts.map +1 -1
- package/dist/cjs/integration/service.js +115 -15
- package/dist/cjs/integration/service.js.map +1 -1
- package/dist/cjs/integration/tenant-credentials.d.ts +44 -0
- package/dist/cjs/integration/tenant-credentials.d.ts.map +1 -0
- package/dist/cjs/integration/tenant-credentials.js +62 -0
- package/dist/cjs/integration/tenant-credentials.js.map +1 -0
- package/dist/esm/aeat/client.d.ts +115 -14
- package/dist/esm/aeat/client.d.ts.map +1 -1
- package/dist/esm/aeat/client.js +218 -46
- package/dist/esm/aeat/client.js.map +1 -1
- package/dist/esm/aeat/index.d.ts +1 -0
- package/dist/esm/aeat/index.d.ts.map +1 -1
- package/dist/esm/aeat/index.js +1 -0
- package/dist/esm/aeat/index.js.map +1 -1
- package/dist/esm/aeat/response.d.ts +80 -0
- package/dist/esm/aeat/response.d.ts.map +1 -0
- package/dist/esm/aeat/response.js +115 -0
- package/dist/esm/aeat/response.js.map +1 -0
- package/dist/esm/core/hash/chain.d.ts +42 -0
- package/dist/esm/core/hash/chain.d.ts.map +1 -1
- package/dist/esm/core/hash/chain.js +37 -0
- package/dist/esm/core/hash/chain.js.map +1 -1
- package/dist/esm/core/index.d.ts +2 -0
- package/dist/esm/core/index.d.ts.map +1 -1
- package/dist/esm/core/index.js +2 -0
- package/dist/esm/core/index.js.map +1 -1
- package/dist/esm/core/models/index.d.ts +0 -1
- package/dist/esm/core/models/index.d.ts.map +1 -1
- package/dist/esm/core/models/index.js +0 -1
- package/dist/esm/core/models/index.js.map +1 -1
- package/dist/esm/core/models/invoice.d.ts +42 -17
- package/dist/esm/core/models/invoice.d.ts.map +1 -1
- package/dist/esm/core/utils/date.d.ts +16 -0
- package/dist/esm/core/utils/date.d.ts.map +1 -0
- package/dist/esm/core/utils/date.js +24 -0
- package/dist/esm/core/utils/date.js.map +1 -0
- package/dist/esm/core/utils/index.d.ts +2 -0
- package/dist/esm/core/utils/index.d.ts.map +1 -0
- package/dist/esm/core/utils/index.js +2 -0
- package/dist/esm/core/utils/index.js.map +1 -0
- package/dist/esm/core/validation/index.d.ts +2 -0
- package/dist/esm/core/validation/index.d.ts.map +1 -0
- package/dist/esm/core/validation/index.js +2 -0
- package/dist/esm/core/validation/index.js.map +1 -0
- package/dist/esm/core/validation/validate.d.ts +18 -0
- package/dist/esm/core/validation/validate.d.ts.map +1 -0
- package/dist/esm/core/validation/validate.js +62 -0
- package/dist/esm/core/validation/validate.js.map +1 -0
- package/dist/esm/core/xml/generator.d.ts +117 -11
- package/dist/esm/core/xml/generator.d.ts.map +1 -1
- package/dist/esm/core/xml/generator.js +233 -64
- package/dist/esm/core/xml/generator.js.map +1 -1
- package/dist/esm/integration/accountability.d.ts +41 -0
- package/dist/esm/integration/accountability.d.ts.map +1 -0
- package/dist/esm/integration/accountability.js +88 -0
- package/dist/esm/integration/accountability.js.map +1 -0
- package/dist/esm/integration/index.d.ts +2 -0
- package/dist/esm/integration/index.d.ts.map +1 -1
- package/dist/esm/integration/index.js +2 -0
- package/dist/esm/integration/index.js.map +1 -1
- package/dist/esm/integration/p12.d.ts +58 -0
- package/dist/esm/integration/p12.d.ts.map +1 -0
- package/dist/esm/integration/p12.js +119 -0
- package/dist/esm/integration/p12.js.map +1 -0
- package/dist/esm/integration/repository.d.ts +4 -3
- package/dist/esm/integration/repository.d.ts.map +1 -1
- package/dist/esm/integration/service.d.ts +11 -2
- package/dist/esm/integration/service.d.ts.map +1 -1
- package/dist/esm/integration/service.js +117 -17
- package/dist/esm/integration/service.js.map +1 -1
- package/dist/esm/integration/tenant-credentials.d.ts +44 -0
- package/dist/esm/integration/tenant-credentials.d.ts.map +1 -0
- package/dist/esm/integration/tenant-credentials.js +58 -0
- package/dist/esm/integration/tenant-credentials.js.map +1 -0
- package/package.json +3 -1
- package/readme.md +731 -38
- package/src/aeat/client.ts +298 -57
- package/src/aeat/index.ts +1 -0
- package/src/aeat/response.ts +198 -0
- package/src/core/hash/chain.ts +68 -0
- package/src/core/index.ts +2 -0
- package/src/core/models/index.ts +0 -1
- package/src/core/models/invoice.ts +40 -18
- package/src/core/utils/date.ts +27 -0
- package/src/core/utils/index.ts +1 -0
- package/src/core/validation/index.ts +1 -0
- package/src/core/validation/validate.ts +71 -0
- package/src/core/xml/generator.ts +312 -73
- package/src/integration/accountability.ts +125 -0
- package/src/integration/index.ts +2 -0
- package/src/integration/p12.ts +155 -0
- package/src/integration/repository.ts +4 -3
- package/src/integration/schema.sql +0 -14
- package/src/integration/service.ts +134 -16
- package/src/core/models/event.ts +0 -25
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { generateInvoiceXml } from '../core/xml/generator.js';
|
|
2
|
+
import { computeRegistroAlta } from '../core/hash/chain.js';
|
|
3
|
+
import { buildQrPayload } from '../core/qr/qr.js';
|
|
4
|
+
import { nowIsoWithOffset } from '../core/utils/date.js';
|
|
5
|
+
import { VerifactuClient } from '../aeat/client.js';
|
|
6
|
+
import { readP12 } from './p12.js';
|
|
7
|
+
/**
|
|
8
|
+
* Integración de accountability (contabilidad) para Verifactu.
|
|
9
|
+
*
|
|
10
|
+
* Une las credenciales del certificado (`.p12`) con el cliente mTLS y la
|
|
11
|
+
* persistencia, para registrar facturas de forma verificable ante la AEAT.
|
|
12
|
+
*/
|
|
13
|
+
export class AccountabilityService {
|
|
14
|
+
repository;
|
|
15
|
+
client;
|
|
16
|
+
nif;
|
|
17
|
+
constructor(repository, config) {
|
|
18
|
+
this.repository = repository;
|
|
19
|
+
let cert;
|
|
20
|
+
let key;
|
|
21
|
+
if (config.p12Buffer && config.p12Password) {
|
|
22
|
+
const content = readP12(config.p12Buffer, config.p12Password);
|
|
23
|
+
cert = content.certificates[0];
|
|
24
|
+
key = content.keys[0];
|
|
25
|
+
}
|
|
26
|
+
else if (config.cert && config.key) {
|
|
27
|
+
cert = config.cert;
|
|
28
|
+
key = config.key;
|
|
29
|
+
}
|
|
30
|
+
if (!cert || !key) {
|
|
31
|
+
throw new Error('AccountabilityService requiere un .p12 (p12Buffer + p12Password) o cert/key PEM.');
|
|
32
|
+
}
|
|
33
|
+
this.nif = config.nif;
|
|
34
|
+
this.client = new VerifactuClient({ baseUrl: config.baseUrl, cert, key });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Registra una factura (alta) ante la AEAT, usando el certificado del
|
|
38
|
+
* emisor para autenticar el envío.
|
|
39
|
+
*/
|
|
40
|
+
async registerInvoice(invoice) {
|
|
41
|
+
// El NIF del emisor se toma del certificado (o del config).
|
|
42
|
+
const invoiceConNif = {
|
|
43
|
+
...invoice,
|
|
44
|
+
emisor: { ...invoice.emisor, nif: this.nif },
|
|
45
|
+
};
|
|
46
|
+
const last = await this.repository.getLastRecord();
|
|
47
|
+
const previousHash = last?.hash ?? null;
|
|
48
|
+
const xml = generateInvoiceXml(invoiceConNif, previousHash);
|
|
49
|
+
const fechaHoraHusoGenRegistro = nowIsoWithOffset();
|
|
50
|
+
const hash = computeRegistroAlta({
|
|
51
|
+
idEmisorFactura: this.nif,
|
|
52
|
+
numSerieFactura: `${invoice.id.serie ?? ''}${invoice.id.numero}`,
|
|
53
|
+
fechaExpedicionFactura: invoice.id.fechaExpedicion,
|
|
54
|
+
tipoFactura: invoice.tipoFactura,
|
|
55
|
+
cuotaTotal: invoice.desglose.cuotaTotal.toFixed(2),
|
|
56
|
+
importeTotal: invoice.desglose.importeTotal.toFixed(2),
|
|
57
|
+
huellaAnterior: previousHash,
|
|
58
|
+
fechaHoraHusoGenRegistro,
|
|
59
|
+
});
|
|
60
|
+
const now = new Date().toISOString();
|
|
61
|
+
const record = {
|
|
62
|
+
id: `${invoice.id.serie ?? ''}${invoice.id.numero}`,
|
|
63
|
+
invoiceId: `${invoice.id.serie ?? ''}${invoice.id.numero}`,
|
|
64
|
+
emisorNif: this.nif,
|
|
65
|
+
xml,
|
|
66
|
+
hash,
|
|
67
|
+
previousHash,
|
|
68
|
+
qrPayload: buildQrPayload(hash),
|
|
69
|
+
status: 'PENDING',
|
|
70
|
+
createdAt: now,
|
|
71
|
+
updatedAt: now,
|
|
72
|
+
};
|
|
73
|
+
await this.repository.saveRecord(record);
|
|
74
|
+
const result = await this.client.sendRecord(xml);
|
|
75
|
+
await this.repository.saveResponse({
|
|
76
|
+
id: `${record.id}-${Date.now()}`,
|
|
77
|
+
recordId: record.id,
|
|
78
|
+
operationId: result.operationId,
|
|
79
|
+
status: result.status,
|
|
80
|
+
message: result.message,
|
|
81
|
+
receivedAt: new Date().toISOString(),
|
|
82
|
+
});
|
|
83
|
+
const status = result.status === 'OK' ? 'CONFIRMED' : 'REJECTED';
|
|
84
|
+
await this.repository.updateRecordStatus(record.id, status);
|
|
85
|
+
return { ...record, status };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=accountability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountability.js","sourceRoot":"","sources":["../../../src/integration/accountability.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAyBnC;;;;;GAKG;AACH,MAAM,OAAO,qBAAqB;IAKb;IAJF,MAAM,CAAkB;IACxB,GAAG,CAAS;IAE7B,YACmB,UAA+B,EAChD,MAA4B;QADX,eAAU,GAAV,UAAU,CAAqB;QAGhD,IAAI,IAAwB,CAAC;QAC7B,IAAI,GAAuB,CAAC;QAE5B,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;YAC3C,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;YAC9D,IAAI,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC/B,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;aAAM,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;YACrC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;YACnB,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACnB,CAAC;QAED,IAAI,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;QACJ,CAAC;Q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.d.ts","sourceRoot":"","sources":["../../../src/integration/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/integration/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/integration/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/integration/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Un campo (bag) del `.p12`.
|
|
3
|
+
*/
|
|
4
|
+
export interface P12Bag {
|
|
5
|
+
/** Tipo del bag (certBag, keyBag, pkcs8ShroudedKeyBag, ...). */
|
|
6
|
+
type: string;
|
|
7
|
+
/** Contenido en formato PEM (si es un certificado o clave). */
|
|
8
|
+
pem?: string;
|
|
9
|
+
/** Valor en bruto (si no es PEM). */
|
|
10
|
+
value?: unknown;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Contenido completo de un `.p12`, con todos sus campos.
|
|
14
|
+
*/
|
|
15
|
+
export interface P12Content {
|
|
16
|
+
/** Todos los bags encontrados, en orden. */
|
|
17
|
+
bags: P12Bag[];
|
|
18
|
+
/** Certificados en PEM (conveniencia). */
|
|
19
|
+
certificates: string[];
|
|
20
|
+
/** Claves privadas en PEM (conveniencia). */
|
|
21
|
+
keys: string[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Lee un certificado `.p12`/`.pfx` e itera todos sus campos (bags),
|
|
25
|
+
* devolviéndolos todos. La librería no interpreta qué campo es cada cosa:
|
|
26
|
+
* simplemente expone el contenido para que la aplicación lo use.
|
|
27
|
+
*
|
|
28
|
+
* @param buffer Contenido del archivo `.p12`/`.pfx`.
|
|
29
|
+
* @param password Contraseña del `.p12`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function readP12(buffer: Buffer, password: string): P12Content;
|
|
32
|
+
/**
|
|
33
|
+
* Extrae el NIF de un certificado en PEM.
|
|
34
|
+
*
|
|
35
|
+
* El NIF suele aparecer en el `serialNumber` (p. ej. `IDCES-74654958V`) o como
|
|
36
|
+
* primer token del `commonName` (p. ej. `74654958V ANTONIO JOSE RECHE`).
|
|
37
|
+
* Devuelve `null` si no se puede determinar.
|
|
38
|
+
*/
|
|
39
|
+
export declare function extractNifFromCertificate(pem: string): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Información de un certificado en PEM: NIF y nombre/razón del titular.
|
|
42
|
+
*/
|
|
43
|
+
export interface CertificateInfo {
|
|
44
|
+
/** NIF del titular del certificado. */
|
|
45
|
+
nif: string;
|
|
46
|
+
/** Nombre o razón social del titular. */
|
|
47
|
+
nombreRazon: string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Extrae el NIF y el nombre/razón del titular de un certificado en PEM.
|
|
51
|
+
*
|
|
52
|
+
* El NIF se obtiene del `serialNumber` (p. ej. `IDCES-74654958V`) o del primer
|
|
53
|
+
* token del `commonName`. El nombre se compone de `givenName` + `surname`, o
|
|
54
|
+
* del `commonName` sin el prefijo de NIF. Devuelve `null` si no se puede
|
|
55
|
+
* determinar el NIF.
|
|
56
|
+
*/
|
|
57
|
+
export declare function extractCertificateInfo(pem: string): CertificateInfo | null;
|
|
58
|
+
//# sourceMappingURL=p12.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"p12.d.ts","sourceRoot":"","sources":["../../../src/integration/p12.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,gEAAgE;IAChE,IAAI,EAAE,MAAM,CAAC;IACb,+DAA+D;IAC/D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,0CAA0C;IAC1C,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CA6BpE;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAuBpE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,uCAAuC;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAuC1E"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import forge from 'node-forge';
|
|
2
|
+
/**
|
|
3
|
+
* Lee un certificado `.p12`/`.pfx` e itera todos sus campos (bags),
|
|
4
|
+
* devolviéndolos todos. La librería no interpreta qué campo es cada cosa:
|
|
5
|
+
* simplemente expone el contenido para que la aplicación lo use.
|
|
6
|
+
*
|
|
7
|
+
* @param buffer Contenido del archivo `.p12`/`.pfx`.
|
|
8
|
+
* @param password Contraseña del `.p12`.
|
|
9
|
+
*/
|
|
10
|
+
export function readP12(buffer, password) {
|
|
11
|
+
const asn1 = forge.asn1.fromDer(forge.util.createBuffer(new Uint8Array(buffer)));
|
|
12
|
+
const p12 = forge.pkcs12.pkcs12FromAsn1(asn1, password);
|
|
13
|
+
const bags = [];
|
|
14
|
+
const certificates = [];
|
|
15
|
+
const keys = [];
|
|
16
|
+
p12.safeContents.forEach((safe) => {
|
|
17
|
+
safe.safeBags.forEach((bag) => {
|
|
18
|
+
const type = bag.type ?? 'unknown';
|
|
19
|
+
let pem;
|
|
20
|
+
let value;
|
|
21
|
+
if (bag.cert) {
|
|
22
|
+
pem = forge.pki.certificateToPem(bag.cert);
|
|
23
|
+
certificates.push(pem);
|
|
24
|
+
}
|
|
25
|
+
else if (bag.key) {
|
|
26
|
+
pem = forge.pki.privateKeyToPem(bag.key);
|
|
27
|
+
keys.push(pem);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
value = bag.attributes;
|
|
31
|
+
}
|
|
32
|
+
bags.push({ type, pem, value });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
return { bags, certificates, keys };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Extrae el NIF de un certificado en PEM.
|
|
39
|
+
*
|
|
40
|
+
* El NIF suele aparecer en el `serialNumber` (p. ej. `IDCES-74654958V`) o como
|
|
41
|
+
* primer token del `commonName` (p. ej. `74654958V ANTONIO JOSE RECHE`).
|
|
42
|
+
* Devuelve `null` si no se puede determinar.
|
|
43
|
+
*/
|
|
44
|
+
export function extractNifFromCertificate(pem) {
|
|
45
|
+
try {
|
|
46
|
+
const cert = forge.pki.certificateFromPem(pem);
|
|
47
|
+
const attrs = cert.subject.attributes;
|
|
48
|
+
// serialNumber: "IDCES-74654958V" o directamente "B12345678"
|
|
49
|
+
const serial = attrs.find((a) => a.name === 'serialNumber')?.value;
|
|
50
|
+
if (serial) {
|
|
51
|
+
const m = String(serial).match(/IDCES-(\S+)/i) ?? String(serial).match(/^([A-Z0-9]{8,9})/i);
|
|
52
|
+
if (m && m[1])
|
|
53
|
+
return m[1];
|
|
54
|
+
}
|
|
55
|
+
// commonName: "74654958V ANTONIO JOSE RECHE (R: B18579458)"
|
|
56
|
+
const cn = attrs.find((a) => a.name === 'commonName')?.value;
|
|
57
|
+
if (cn) {
|
|
58
|
+
const m = String(cn).match(/^([A-Z0-9]{8,9})/i);
|
|
59
|
+
if (m && m[1])
|
|
60
|
+
return m[1];
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Extrae el NIF y el nombre/razón del titular de un certificado en PEM.
|
|
70
|
+
*
|
|
71
|
+
* El NIF se obtiene del `serialNumber` (p. ej. `IDCES-74654958V`) o del primer
|
|
72
|
+
* token del `commonName`. El nombre se compone de `givenName` + `surname`, o
|
|
73
|
+
* del `commonName` sin el prefijo de NIF. Devuelve `null` si no se puede
|
|
74
|
+
* determinar el NIF.
|
|
75
|
+
*/
|
|
76
|
+
export function extractCertificateInfo(pem) {
|
|
77
|
+
try {
|
|
78
|
+
const cert = forge.pki.certificateFromPem(pem);
|
|
79
|
+
const attrs = cert.subject.attributes;
|
|
80
|
+
// NIF
|
|
81
|
+
const serial = attrs.find((a) => a.name === 'serialNumber')?.value;
|
|
82
|
+
let nif = null;
|
|
83
|
+
if (serial) {
|
|
84
|
+
const m = String(serial).match(/IDCES-(\S+)/i) ?? String(serial).match(/^([A-Z0-9]{8,9})/i);
|
|
85
|
+
if (m && m[1])
|
|
86
|
+
nif = m[1];
|
|
87
|
+
}
|
|
88
|
+
if (!nif) {
|
|
89
|
+
const cn = attrs.find((a) => a.name === 'commonName')?.value;
|
|
90
|
+
if (cn) {
|
|
91
|
+
const m = String(cn).match(/^([A-Z0-9]{8,9})/i);
|
|
92
|
+
if (m && m[1])
|
|
93
|
+
nif = m[1];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (!nif)
|
|
97
|
+
return null;
|
|
98
|
+
// Nombre: givenName + surname, o commonName sin el NIF.
|
|
99
|
+
const given = attrs.find((a) => a.name === 'givenName')?.value;
|
|
100
|
+
const surname = attrs.find((a) => a.name === 'surname')?.value;
|
|
101
|
+
let nombreRazon = '';
|
|
102
|
+
if (given)
|
|
103
|
+
nombreRazon += given;
|
|
104
|
+
if (surname)
|
|
105
|
+
nombreRazon += (nombreRazon ? ' ' : '') + surname;
|
|
106
|
+
nombreRazon = nombreRazon.trim();
|
|
107
|
+
if (!nombreRazon) {
|
|
108
|
+
const cn = attrs.find((a) => a.name === 'commonName')?.value;
|
|
109
|
+
if (cn) {
|
|
110
|
+
nombreRazon = String(cn).replace(/^[A-Z0-9]{8,9}\s*/, '').split(' (R:')[0]?.trim() ?? '';
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return { nif, nombreRazon };
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=p12.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"p12.js","sourceRoot":"","sources":["../../../src/integration/p12.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,YAAY,CAAC;AA0B/B;;;;;;;GAOG;AACH,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,QAAgB;IACtD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACjF,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAExD,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,IAAI,GAAa,EAAE,CAAC;IAE1B,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,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AK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC,EAAE,KAAK,CAAC;YAC7D,IAAI,EAAE,EAAE,CAAC;gBACP,WAAW,GAAG,MAAM,CAAC,EAAG,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YAC5F,CAAC;QACH,CAAC;QAED,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Event } from '../core/models/event.js';
|
|
2
1
|
/**
|
|
3
2
|
* Estado de un registro de facturación en el sistema consumidor.
|
|
4
3
|
*/
|
|
@@ -11,6 +10,8 @@ export interface StoredRecord {
|
|
|
11
10
|
id: string;
|
|
12
11
|
/** Referencia a la factura (serie + número). */
|
|
13
12
|
invoiceId: string;
|
|
13
|
+
/** NIF del emisor de la factura. */
|
|
14
|
+
emisorNif: string;
|
|
14
15
|
/** XML Verifactu generado. */
|
|
15
16
|
xml: string;
|
|
16
17
|
/** Hash del propio registro (huella). */
|
|
@@ -19,6 +20,8 @@ export interface StoredRecord {
|
|
|
19
20
|
previousHash: string | null;
|
|
20
21
|
/** Payload del QR Verifactu (URL de verificación con el hash). */
|
|
21
22
|
qrPayload?: string;
|
|
23
|
+
/** `true` si la huella devuelta por AEAT coincide con la calculada. */
|
|
24
|
+
hashVerified?: boolean;
|
|
22
25
|
/** Estado del registro. */
|
|
23
26
|
status: RecordStatus;
|
|
24
27
|
/** Fecha/hora de creación. */
|
|
@@ -71,7 +74,5 @@ export interface VerifactuRepository {
|
|
|
71
74
|
saveResponse(response: StoredResponse): Promise<void>;
|
|
72
75
|
/** Obtiene las respuestas de un registro. */
|
|
73
76
|
getResponses(recordId: string): Promise<StoredResponse[]>;
|
|
74
|
-
/** Guarda un evento. */
|
|
75
|
-
saveEvent(event: Event): Promise<void>;
|
|
76
77
|
}
|
|
77
78
|
//# sourceMappingURL=repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../src/integration/repository.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../src/integration/repository.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,MAAM,GACN,WAAW,GACX,UAAU,GACV,UAAU,CAAC;AAEf;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,EAAE,EAAE,MAAM,CAAC;IACX,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,kEAAkE;IAClE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,2BAA2B;IAC3B,MAAM,EAAE,YAAY,CAAC;IACrB,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,yCAAyC;IACzC,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,0CAA0C;IAC1C,kBAAkB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,qCAAqC;IACrC,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACpD,kEAAkE;IAClE,aAAa,IAAI,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC9C,mCAAmC;IACnC,YAAY,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,6CAA6C;IAC7C,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;CAC3D"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Invoice } from '../core/models/invoice.js';
|
|
2
|
+
import { type EventoInput } from '../core/xml/generator.js';
|
|
2
3
|
import type { VerifactuClient } from '../aeat/client.js';
|
|
3
4
|
import type { VerifactuRepository, StoredRecord } from './repository.js';
|
|
4
5
|
/**
|
|
@@ -11,7 +12,8 @@ import type { VerifactuRepository, StoredRecord } from './repository.js';
|
|
|
11
12
|
export declare class VerifactuService {
|
|
12
13
|
private readonly repository;
|
|
13
14
|
private readonly client;
|
|
14
|
-
|
|
15
|
+
private readonly certificatePem?;
|
|
16
|
+
constructor(repository: VerifactuRepository, client: VerifactuClient, certificatePem?: string | undefined);
|
|
15
17
|
/**
|
|
16
18
|
* Registra una factura: genera el XML, calcula el hash encadenado, guarda
|
|
17
19
|
* el registro y lo envía a AEAT, persistiendo la respuesta.
|
|
@@ -23,7 +25,7 @@ export declare class VerifactuService {
|
|
|
23
25
|
* Genera un registro de anulación que referencia la factura anulada,
|
|
24
26
|
* lo envía a AEAT y marca la factura original como ANNULLED.
|
|
25
27
|
*/
|
|
26
|
-
annulInvoice(invoiceId: string): Promise<StoredRecord>;
|
|
28
|
+
annulInvoice(invoiceId: string, invoice?: Invoice): Promise<StoredRecord>;
|
|
27
29
|
/**
|
|
28
30
|
* Modifica una factura previamente registrada.
|
|
29
31
|
*
|
|
@@ -32,5 +34,12 @@ export declare class VerifactuService {
|
|
|
32
34
|
* envía la referencia a la factura original y la factura corregida.
|
|
33
35
|
*/
|
|
34
36
|
modifyInvoice(invoiceId: string, correctedInvoice: Invoice): Promise<StoredRecord>;
|
|
37
|
+
/**
|
|
38
|
+
* Registra un evento (RegistroEvento) ante AEAT.
|
|
39
|
+
*
|
|
40
|
+
* Genera el XML del evento, calcula su huella encadenada con el último
|
|
41
|
+
* registro, persiste el evento y lo envía a AEAT.
|
|
42
|
+
*/
|
|
43
|
+
registerEvent(evento: EventoInput): Promise<StoredRecord>;
|
|
35
44
|
}
|
|
36
45
|
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/integration/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/integration/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAqG,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAM/J,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAQzE;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAEzB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAFf,UAAU,EAAE,mBAAmB,EAC/B,MAAM,EAAE,eAAe,EACvB,cAAc,CAAC,EAAE,MAAM,YAAA;IAG1C;;;OAGG;IACG,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAoF9D;;;;;OAKG;IACG,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IA8E/E;;;;;;OAMG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAQxF;;;;;OAKG;IACG,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;CAoDhE"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { generateInvoiceXml, generateAnulacionXml } from '../core/xml/generator.js';
|
|
2
|
-
import { computeRegistroAlta, computeRegistroAnulacion } from '../core/hash/chain.js';
|
|
1
|
+
import { generateInvoiceXml, generateSuministroXml, buildCabecera, generateAnulacionXml, generateEventoXml } from '../core/xml/generator.js';
|
|
2
|
+
import { computeRegistroAlta, computeRegistroAnulacion, computeRegistroEvento, verifyRegistroAlta } from '../core/hash/chain.js';
|
|
3
3
|
import { buildQrPayload } from '../core/qr/qr.js';
|
|
4
|
+
import { nowIsoWithOffset } from '../core/utils/date.js';
|
|
5
|
+
import { validateInvoice } from '../core/validation/validate.js';
|
|
6
|
+
import { extractCertificateInfo } from './p12.js';
|
|
7
|
+
/** Convierte `YYYY-MM-DD` a `DD-MM-YYYY` (formato XSD `fecha` de AEAT). */
|
|
8
|
+
function toDdMmYyyy(iso) {
|
|
9
|
+
const [y, m, d] = iso.split('-');
|
|
10
|
+
return `${d}-${m}-${y}`;
|
|
11
|
+
}
|
|
4
12
|
/**
|
|
5
13
|
* Servicio de orquestación de Verifactu.
|
|
6
14
|
*
|
|
@@ -11,20 +19,30 @@ import { buildQrPayload } from '../core/qr/qr.js';
|
|
|
11
19
|
export class VerifactuService {
|
|
12
20
|
repository;
|
|
13
21
|
client;
|
|
14
|
-
|
|
22
|
+
certificatePem;
|
|
23
|
+
constructor(repository, client, certificatePem) {
|
|
15
24
|
this.repository = repository;
|
|
16
25
|
this.client = client;
|
|
26
|
+
this.certificatePem = certificatePem;
|
|
17
27
|
}
|
|
18
28
|
/**
|
|
19
29
|
* Registra una factura: genera el XML, calcula el hash encadenado, guarda
|
|
20
30
|
* el registro y lo envía a AEAT, persistiendo la respuesta.
|
|
21
31
|
*/
|
|
22
32
|
async registerInvoice(invoice) {
|
|
33
|
+
// 0. Validar la factura antes de generar el XML.
|
|
34
|
+
const validation = validateInvoice(invoice);
|
|
35
|
+
if (!validation.valid) {
|
|
36
|
+
throw new Error(`Factura inválida: ${validation.errors.join('; ')}`);
|
|
37
|
+
}
|
|
23
38
|
// 1. Obtener el hash del último registro para encadenar.
|
|
24
39
|
const last = await this.repository.getLastRecord();
|
|
25
40
|
const previousHash = last?.hash ?? null;
|
|
26
41
|
// 2. Generar XML y calcular la huella (hash) del registro.
|
|
27
|
-
const
|
|
42
|
+
const registroAltaXml = generateInvoiceXml(invoice, previousHash);
|
|
43
|
+
const cabecera = buildCabecera({ nombreRazon: invoice.emisor.nombreRazon, nif: invoice.emisor.nif }, this.certificatePem, extractCertificateInfo);
|
|
44
|
+
const xml = generateSuministroXml(registroAltaXml, cabecera);
|
|
45
|
+
const fechaHoraHusoGenRegistro = nowIsoWithOffset();
|
|
28
46
|
const hash = computeRegistroAlta({
|
|
29
47
|
idEmisorFactura: invoice.emisor.nif,
|
|
30
48
|
numSerieFactura: `${invoice.id.serie ?? ''}${invoice.id.numero}`,
|
|
@@ -33,13 +51,14 @@ export class VerifactuService {
|
|
|
33
51
|
cuotaTotal: invoice.desglose.cuotaTotal.toFixed(2),
|
|
34
52
|
importeTotal: invoice.desglose.importeTotal.toFixed(2),
|
|
35
53
|
huellaAnterior: previousHash,
|
|
36
|
-
fechaHoraHusoGenRegistro
|
|
54
|
+
fechaHoraHusoGenRegistro,
|
|
37
55
|
});
|
|
38
56
|
// 3. Persistir el registro como PENDING.
|
|
39
57
|
const now = new Date().toISOString();
|
|
40
58
|
const record = {
|
|
41
59
|
id: `${invoice.id.serie ?? ''}${invoice.id.numero}`,
|
|
42
60
|
invoiceId: `${invoice.id.serie ?? ''}${invoice.id.numero}`,
|
|
61
|
+
emisorNif: invoice.emisor.nif,
|
|
43
62
|
xml,
|
|
44
63
|
hash,
|
|
45
64
|
previousHash,
|
|
@@ -59,10 +78,24 @@ export class VerifactuService {
|
|
|
59
78
|
message: result.message,
|
|
60
79
|
receivedAt: new Date().toISOString(),
|
|
61
80
|
});
|
|
62
|
-
// 5.
|
|
81
|
+
// 5. Verificar la huella devuelta por AEAT (integridad del registro).
|
|
82
|
+
const aeatHash = result.registro?.huella;
|
|
83
|
+
const hashVerified = result.status === 'OK' && aeatHash !== undefined
|
|
84
|
+
? verifyRegistroAlta({
|
|
85
|
+
idEmisorFactura: invoice.emisor.nif,
|
|
86
|
+
numSerieFactura: `${invoice.id.serie ?? ''}${invoice.id.numero}`,
|
|
87
|
+
fechaExpedicionFactura: invoice.id.fechaExpedicion,
|
|
88
|
+
tipoFactura: invoice.tipoFactura,
|
|
89
|
+
cuotaTotal: invoice.desglose.cuotaTotal.toFixed(2),
|
|
90
|
+
importeTotal: invoice.desglose.importeTotal.toFixed(2),
|
|
91
|
+
huellaAnterior: previousHash,
|
|
92
|
+
fechaHoraHusoGenRegistro,
|
|
93
|
+
}, aeatHash)
|
|
94
|
+
: undefined;
|
|
95
|
+
// 6. Actualizar el estado del registro según la respuesta.
|
|
63
96
|
const status = result.status === 'OK' ? 'CONFIRMED' : 'REJECTED';
|
|
64
97
|
await this.repository.updateRecordStatus(record.id, status);
|
|
65
|
-
return { ...record, status };
|
|
98
|
+
return { ...record, status, hashVerified };
|
|
66
99
|
}
|
|
67
100
|
/**
|
|
68
101
|
* Anula una factura previamente registrada.
|
|
@@ -70,7 +103,7 @@ export class VerifactuService {
|
|
|
70
103
|
* Genera un registro de anulación que referencia la factura anulada,
|
|
71
104
|
* lo envía a AEAT y marca la factura original como ANNULLED.
|
|
72
105
|
*/
|
|
73
|
-
async annulInvoice(invoiceId) {
|
|
106
|
+
async annulInvoice(invoiceId, invoice) {
|
|
74
107
|
// 1. Obtener la factura original (para su huella) y el último registro.
|
|
75
108
|
const original = await this.repository.getRecord(invoiceId);
|
|
76
109
|
if (!original) {
|
|
@@ -78,25 +111,39 @@ export class VerifactuService {
|
|
|
78
111
|
}
|
|
79
112
|
const last = await this.repository.getLastRecord();
|
|
80
113
|
const previousHash = last?.hash ?? null;
|
|
114
|
+
const fechaHoraHusoGenRegistro = nowIsoWithOffset();
|
|
115
|
+
const fechaExpedicionFacturaAnulada = toDdMmYyyy(invoice?.id.fechaExpedicion ?? new Date().toISOString().slice(0, 10));
|
|
116
|
+
const sistemaInformatico = invoice?.sistemaInformatico ?? {
|
|
117
|
+
nombreRazon: 'Sistema',
|
|
118
|
+
nif: original.emisorNif,
|
|
119
|
+
nombreSistemaInformatico: 'SIF',
|
|
120
|
+
idSistemaInformatico: '01',
|
|
121
|
+
version: '1.0',
|
|
122
|
+
numeroInstalacion: '1',
|
|
123
|
+
};
|
|
81
124
|
// 2. Generar XML de anulación y calcular la huella.
|
|
82
|
-
const xml = generateAnulacionXml({
|
|
83
|
-
idEmisorFacturaAnulada: original.invoiceId,
|
|
84
|
-
numSerieFacturaAnulada: original.invoiceId,
|
|
85
|
-
fechaExpedicionFacturaAnulada: new Date().toISOString().slice(0, 10),
|
|
86
|
-
huellaFacturaAnulada: original.hash,
|
|
87
|
-
}, previousHash);
|
|
88
125
|
const hash = computeRegistroAnulacion({
|
|
89
|
-
idEmisorFacturaAnulada: original.
|
|
126
|
+
idEmisorFacturaAnulada: original.emisorNif,
|
|
90
127
|
numSerieFacturaAnulada: original.invoiceId,
|
|
91
|
-
fechaExpedicionFacturaAnulada
|
|
128
|
+
fechaExpedicionFacturaAnulada,
|
|
92
129
|
huellaAnterior: previousHash,
|
|
93
|
-
fechaHoraHusoGenRegistro
|
|
130
|
+
fechaHoraHusoGenRegistro,
|
|
94
131
|
});
|
|
132
|
+
const xml = generateAnulacionXml({
|
|
133
|
+
idEmisorFacturaAnulada: original.emisorNif,
|
|
134
|
+
numSerieFacturaAnulada: original.invoiceId,
|
|
135
|
+
fechaExpedicionFacturaAnulada,
|
|
136
|
+
huellaFacturaAnulada: original.hash,
|
|
137
|
+
sistemaInformatico,
|
|
138
|
+
fechaHoraHusoGenRegistro,
|
|
139
|
+
huella: hash,
|
|
140
|
+
}, previousHash);
|
|
95
141
|
// 3. Persistir el registro de anulación como PENDING.
|
|
96
142
|
const now = new Date().toISOString();
|
|
97
143
|
const record = {
|
|
98
144
|
id: `${invoiceId}-ANUL`,
|
|
99
145
|
invoiceId,
|
|
146
|
+
emisorNif: original.emisorNif,
|
|
100
147
|
xml,
|
|
101
148
|
hash,
|
|
102
149
|
previousHash,
|
|
@@ -136,5 +183,58 @@ export class VerifactuService {
|
|
|
136
183
|
// 2. Emitir la factura corregida como un nuevo alta.
|
|
137
184
|
return this.registerInvoice(correctedInvoice);
|
|
138
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Registra un evento (RegistroEvento) ante AEAT.
|
|
188
|
+
*
|
|
189
|
+
* Genera el XML del evento, calcula su huella encadenada con el último
|
|
190
|
+
* registro, persiste el evento y lo envía a AEAT.
|
|
191
|
+
*/
|
|
192
|
+
async registerEvent(evento) {
|
|
193
|
+
// 1. Obtener el hash del último registro para encadenar.
|
|
194
|
+
const last = await this.repository.getLastRecord();
|
|
195
|
+
const previousHash = last?.hash ?? null;
|
|
196
|
+
// 2. Generar XML y calcular la huella del evento.
|
|
197
|
+
const si = evento.sistemaInformatico;
|
|
198
|
+
const hash = computeRegistroEvento({
|
|
199
|
+
nifSistemaInformatico: si.nif,
|
|
200
|
+
id: '',
|
|
201
|
+
idSistemaInformatico: si.idSistemaInformatico,
|
|
202
|
+
version: si.version,
|
|
203
|
+
numeroInstalacion: si.numeroInstalacion,
|
|
204
|
+
nifObligado: evento.obligadoEmision.nif,
|
|
205
|
+
tipoEvento: evento.tipoEvento,
|
|
206
|
+
huellaAnterior: previousHash,
|
|
207
|
+
fechaHoraHusoGenEvento: evento.fechaHoraHusoGenEvento,
|
|
208
|
+
});
|
|
209
|
+
const xml = generateEventoXml({ ...evento, huellaEvento: hash });
|
|
210
|
+
// 3. Persistir el evento.
|
|
211
|
+
const now = new Date().toISOString();
|
|
212
|
+
const record = {
|
|
213
|
+
id: `EV-${evento.tipoEvento}-${Date.now()}`,
|
|
214
|
+
invoiceId: evento.obligadoEmision.nif,
|
|
215
|
+
emisorNif: evento.obligadoEmision.nif,
|
|
216
|
+
xml,
|
|
217
|
+
hash,
|
|
218
|
+
previousHash,
|
|
219
|
+
status: 'PENDING',
|
|
220
|
+
createdAt: now,
|
|
221
|
+
updatedAt: now,
|
|
222
|
+
};
|
|
223
|
+
await this.repository.saveRecord(record);
|
|
224
|
+
// 4. Enviar a AEAT y persistir la respuesta.
|
|
225
|
+
const result = await this.client.sendRecord(xml);
|
|
226
|
+
await this.repository.saveResponse({
|
|
227
|
+
id: `${record.id}-${Date.now()}`,
|
|
228
|
+
recordId: record.id,
|
|
229
|
+
operationId: result.operationId,
|
|
230
|
+
status: result.status,
|
|
231
|
+
message: result.message,
|
|
232
|
+
receivedAt: new Date().toISOString(),
|
|
233
|
+
});
|
|
234
|
+
// 5. Actualizar el estado.
|
|
235
|
+
const status = result.status === 'OK' ? 'CONFIRMED' : 'REJECTED';
|
|
236
|
+
await this.repository.updateRecordStatus(record.id, status);
|
|
237
|
+
return { ...record, status };
|
|
238
|
+
}
|
|
139
239
|
}
|
|
140
240
|
//# sourceMappingURL=service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/integration/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/integration/service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,aAAa,EAAE,oBAAoB,EAAE,iBAAiB,EAAoB,MAAM,0BAA0B,CAAC;AAC/J,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACjI,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAIlD,2EAA2E;AAC3E,SAAS,UAAU,CAAC,GAAW;IAC7B,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAER;IACA;IACA;IAHnB,YACmB,UAA+B,EAC/B,MAAuB,EACvB,cAAuB;QAFvB,eAAU,GAAV,UAAU,CAAqB;QAC/B,WAAM,GAAN,MAAM,CAAiB;QACvB,mBAAc,GAAd,cAAc,CAAS;IACvC,CAAC;I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