consultame-sdk 1.1.2 → 1.2.0
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/README.md +168 -4
- package/dist/index.js +161 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +161 -0
- package/dist/index.mjs.map +1 -1
- package/dist/shared/functions/functions.utils.d.ts +2 -1
- package/dist/shared/functions/functions.utils.d.ts.map +1 -1
- package/dist/sifen/applications/dtos/index.d.ts +1 -0
- package/dist/sifen/applications/dtos/index.d.ts.map +1 -1
- package/dist/sifen/applications/dtos/nominationInvoice.dto.d.ts +31 -0
- package/dist/sifen/applications/dtos/nominationInvoice.dto.d.ts.map +1 -0
- package/dist/sifen/applications/services/sifen.service.d.ts +3 -1
- package/dist/sifen/applications/services/sifen.service.d.ts.map +1 -1
- package/dist/sifen/domain/repository/sifen.repository.d.ts +2 -1
- package/dist/sifen/domain/repository/sifen.repository.d.ts.map +1 -1
- package/dist/sifen/domain/useCases/index.d.ts +1 -0
- package/dist/sifen/domain/useCases/index.d.ts.map +1 -1
- package/dist/sifen/domain/useCases/nominationInvoice.useCase.d.ts +8 -0
- package/dist/sifen/domain/useCases/nominationInvoice.useCase.d.ts.map +1 -0
- package/dist/sifen/infrastructure/persistence/sifen.persistence.d.ts +2 -1
- package/dist/sifen/infrastructure/persistence/sifen.persistence.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -94,6 +94,18 @@ var SignedXmlUseCase = class {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
+
// src/sifen/domain/useCases/nominationInvoice.useCase.ts
|
|
98
|
+
var NominationInvoiceUseCase = class {
|
|
99
|
+
constructor(sifenRepository) {
|
|
100
|
+
this.sifenRepository = sifenRepository;
|
|
101
|
+
}
|
|
102
|
+
sifenRepository;
|
|
103
|
+
execute(nominationInvoiceDto) {
|
|
104
|
+
const xml = this.sifenRepository.nominationInvoice(nominationInvoiceDto);
|
|
105
|
+
return xml;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
97
109
|
// src/shared/utils/dictionary.utils.ts
|
|
98
110
|
var TIPOS_DOCUMENTOS = [
|
|
99
111
|
{
|
|
@@ -8131,6 +8143,139 @@ var generateConsultBatchXml = (consultBatchDto) => {
|
|
|
8131
8143
|
</env:Envelope>
|
|
8132
8144
|
`;
|
|
8133
8145
|
};
|
|
8146
|
+
var validateNominationInvoice = (dto) => {
|
|
8147
|
+
if (!/^\d{44}$/.test(dto.cdc)) {
|
|
8148
|
+
throw new Error("El CDC debe tener 44 d\xEDgitos");
|
|
8149
|
+
}
|
|
8150
|
+
if (dto.motivo.trim().length < 5 || dto.motivo.trim().length > 500) {
|
|
8151
|
+
throw new Error("El motivo debe tener entre 5 y 500 caracteres");
|
|
8152
|
+
}
|
|
8153
|
+
if (dto.razonSocial.trim().length < 4 || dto.razonSocial.trim().length > 255) {
|
|
8154
|
+
throw new Error("La raz\xF3n social debe tener entre 4 y 255 caracteres");
|
|
8155
|
+
}
|
|
8156
|
+
if (dto.esContribuyente !== (dto.idTipoReceptor === 1)) {
|
|
8157
|
+
throw new Error(
|
|
8158
|
+
"idTipoReceptor (1 = contribuyente, 2 = no contribuyente) no coincide con esContribuyente"
|
|
8159
|
+
);
|
|
8160
|
+
}
|
|
8161
|
+
if (![1, 2, 4].includes(dto.idTipoOperacion)) {
|
|
8162
|
+
throw new Error("idTipoOperacion debe ser 1 (B2B), 2 (B2C) o 4 (B2F)");
|
|
8163
|
+
}
|
|
8164
|
+
if (dto.esContribuyente !== (dto.idTipoOperacion === 1)) {
|
|
8165
|
+
throw new Error(
|
|
8166
|
+
"B2B exige receptor contribuyente; B2C y B2F exigen no contribuyente"
|
|
8167
|
+
);
|
|
8168
|
+
}
|
|
8169
|
+
if (dto.idTipoOperacion === 4 === (dto.idPais === "PRY")) {
|
|
8170
|
+
throw new Error(
|
|
8171
|
+
"idPais debe ser PRY, salvo en B2F donde debe ser distinto de PRY"
|
|
8172
|
+
);
|
|
8173
|
+
}
|
|
8174
|
+
if (dto.esContribuyente) {
|
|
8175
|
+
if (!dto.idTipoContribuyente || !dto.ruc || dto.digitoVerificado === void 0) {
|
|
8176
|
+
throw new Error(
|
|
8177
|
+
"Receptor contribuyente: idTipoContribuyente, ruc y digitoVerificado son obligatorios"
|
|
8178
|
+
);
|
|
8179
|
+
}
|
|
8180
|
+
} else if (!dto.idTipoDocumento || !dto.numeroDocumento) {
|
|
8181
|
+
throw new Error(
|
|
8182
|
+
"Receptor no contribuyente: idTipoDocumento y numeroDocumento son obligatorios"
|
|
8183
|
+
);
|
|
8184
|
+
}
|
|
8185
|
+
if (dto.idTipoOperacion === 4 && !dto.direccion) {
|
|
8186
|
+
throw new Error("B2F: la direcci\xF3n del receptor es obligatoria");
|
|
8187
|
+
}
|
|
8188
|
+
if (dto.direccion && !dto.numeroCasa) {
|
|
8189
|
+
throw new Error("numeroCasa es obligatorio si se informa la direcci\xF3n");
|
|
8190
|
+
}
|
|
8191
|
+
};
|
|
8192
|
+
var generateNominationInvoiceXml = (dto) => {
|
|
8193
|
+
validateNominationInvoice(dto);
|
|
8194
|
+
const pais = PAISES.find((item) => item.codigo === dto.idPais).descripcion;
|
|
8195
|
+
const rGEveNom = {
|
|
8196
|
+
Id: dto.cdc,
|
|
8197
|
+
mOtEve: dto.motivo.trim(),
|
|
8198
|
+
iNatRec: dto.idTipoReceptor,
|
|
8199
|
+
iTiOpe: dto.idTipoOperacion,
|
|
8200
|
+
cPaisRec: dto.idPais,
|
|
8201
|
+
dDesPaisRe: pais
|
|
8202
|
+
};
|
|
8203
|
+
if (dto.esContribuyente) {
|
|
8204
|
+
rGEveNom.iTiContRec = dto.idTipoContribuyente;
|
|
8205
|
+
rGEveNom.dRucRec = dto.ruc;
|
|
8206
|
+
rGEveNom.dDVRec = dto.digitoVerificado;
|
|
8207
|
+
} else {
|
|
8208
|
+
rGEveNom.iTipIDRec = dto.idTipoDocumento;
|
|
8209
|
+
rGEveNom.dDTipIDRec = dto.idTipoDocumento === 9 && dto.otroTipoDocumento ? dto.otroTipoDocumento : TIPOS_DOCUMENTOS.find((item) => item.codigo === dto.idTipoDocumento).descripcion;
|
|
8210
|
+
rGEveNom.dNumIDRec = dto.numeroDocumento.trim();
|
|
8211
|
+
}
|
|
8212
|
+
rGEveNom.dNomRec = dto.razonSocial.trim();
|
|
8213
|
+
if (dto.nombreFantasia) rGEveNom.dNomFanRec = dto.nombreFantasia.trim();
|
|
8214
|
+
if (dto.direccion) {
|
|
8215
|
+
rGEveNom.dDirRec = dto.direccion.trim();
|
|
8216
|
+
rGEveNom.dNumCasRec = dto.numeroCasa.trim();
|
|
8217
|
+
}
|
|
8218
|
+
if (dto.idTipoOperacion !== 4) {
|
|
8219
|
+
if (dto.idDepartamento) {
|
|
8220
|
+
rGEveNom.cDepRec = dto.idDepartamento;
|
|
8221
|
+
rGEveNom.dDesDepRec = DEPARTAMENTOS.find(
|
|
8222
|
+
(item) => item.codigo === dto.idDepartamento
|
|
8223
|
+
).descripcion;
|
|
8224
|
+
}
|
|
8225
|
+
if (dto.idDistricto) {
|
|
8226
|
+
rGEveNom.cDisRec = dto.idDistricto;
|
|
8227
|
+
rGEveNom.dDesDisRec = DISTRICTOS.find(
|
|
8228
|
+
(item) => item.codigo === dto.idDistricto
|
|
8229
|
+
).descripcion;
|
|
8230
|
+
}
|
|
8231
|
+
if (dto.idCiudad) {
|
|
8232
|
+
rGEveNom.cCiuRec = dto.idCiudad;
|
|
8233
|
+
rGEveNom.dDesCiuRec = CIUDADES.find(
|
|
8234
|
+
(item) => item.codigo === dto.idCiudad
|
|
8235
|
+
).descripcion;
|
|
8236
|
+
}
|
|
8237
|
+
}
|
|
8238
|
+
if (dto.telefono) rGEveNom.dTelRec = dto.telefono.trim();
|
|
8239
|
+
if (dto.celular) rGEveNom.dCelRec = dto.celular.trim();
|
|
8240
|
+
if (dto.email) rGEveNom.dEmailRec = dto.email.trim();
|
|
8241
|
+
if (dto.codigoCliente) rGEveNom.dCodCliente = dto.codigoCliente.trim();
|
|
8242
|
+
const xsd = "http://ekuatia.set.gov.py/sifen/xsd";
|
|
8243
|
+
const schemaLocation = `${xsd} siRecepEvento_v150.xsd`;
|
|
8244
|
+
const envelope = {
|
|
8245
|
+
"env:Envelope": {
|
|
8246
|
+
$: { "xmlns:env": "http://www.w3.org/2003/05/soap-envelope" },
|
|
8247
|
+
"env:Header": {},
|
|
8248
|
+
"env:Body": {
|
|
8249
|
+
rEnviEventoDe: {
|
|
8250
|
+
$: { xmlns: xsd },
|
|
8251
|
+
dId: dto.id,
|
|
8252
|
+
dEvReg: {
|
|
8253
|
+
gGroupGesEve: {
|
|
8254
|
+
$: {
|
|
8255
|
+
xmlns: xsd,
|
|
8256
|
+
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
|
|
8257
|
+
"xsi:schemaLocation": schemaLocation
|
|
8258
|
+
},
|
|
8259
|
+
rGesEve: {
|
|
8260
|
+
$: { "xsi:schemaLocation": schemaLocation },
|
|
8261
|
+
rEve: {
|
|
8262
|
+
$: { Id: dto.id },
|
|
8263
|
+
dFecFirma: convertToFormatDateSET(/* @__PURE__ */ new Date()),
|
|
8264
|
+
dVerFor: 150,
|
|
8265
|
+
gGroupTiEvt: { rGEveNom }
|
|
8266
|
+
}
|
|
8267
|
+
}
|
|
8268
|
+
}
|
|
8269
|
+
}
|
|
8270
|
+
}
|
|
8271
|
+
}
|
|
8272
|
+
}
|
|
8273
|
+
};
|
|
8274
|
+
const builder = new xml2js.Builder({
|
|
8275
|
+
xmldec: { version: "1.0", encoding: "UTF-8", standalone: false }
|
|
8276
|
+
});
|
|
8277
|
+
return normalizeXML(builder.buildObject(envelope));
|
|
8278
|
+
};
|
|
8134
8279
|
var OIDS_KEYS = [forge.pki.oids.pkcs8ShroudedKeyBag, forge.pki.oids.keyBag];
|
|
8135
8280
|
var obtainBags = (almacen) => almacen.safeContents.flatMap((contenido) => contenido.safeBags);
|
|
8136
8281
|
var readDigitalSign = (digitalSignDto) => {
|
|
@@ -9950,6 +10095,14 @@ var SifenPersistence = class {
|
|
|
9950
10095
|
throw error;
|
|
9951
10096
|
}
|
|
9952
10097
|
}
|
|
10098
|
+
nominationInvoice(nominationInvoiceDto) {
|
|
10099
|
+
try {
|
|
10100
|
+
return generateNominationInvoiceXml(nominationInvoiceDto);
|
|
10101
|
+
} catch (error) {
|
|
10102
|
+
console.log(error);
|
|
10103
|
+
throw error;
|
|
10104
|
+
}
|
|
10105
|
+
}
|
|
9953
10106
|
obtainDigitalSign(digitalSignDto) {
|
|
9954
10107
|
try {
|
|
9955
10108
|
const digitalSign = readDigitalSign(digitalSignDto);
|
|
@@ -10000,6 +10153,7 @@ var SifenService = class {
|
|
|
10000
10153
|
generateQrUseCase;
|
|
10001
10154
|
generateDocumentUseCase;
|
|
10002
10155
|
signedXmlUseCase;
|
|
10156
|
+
nominationInvoiceUseCase;
|
|
10003
10157
|
sifenRepository;
|
|
10004
10158
|
constructor() {
|
|
10005
10159
|
this.sifenRepository = new SifenPersistence();
|
|
@@ -10016,6 +10170,9 @@ var SifenService = class {
|
|
|
10016
10170
|
);
|
|
10017
10171
|
this.signedXmlUseCase = new SignedXmlUseCase(this.sifenRepository);
|
|
10018
10172
|
this.generateQrUseCase = new GenerateQrUseCase(this.sifenRepository);
|
|
10173
|
+
this.nominationInvoiceUseCase = new NominationInvoiceUseCase(
|
|
10174
|
+
this.sifenRepository
|
|
10175
|
+
);
|
|
10019
10176
|
}
|
|
10020
10177
|
consultRuc(consultRucDto) {
|
|
10021
10178
|
const ruc = this.consultRucUseCase.execute(consultRucDto);
|
|
@@ -10029,6 +10186,10 @@ var SifenService = class {
|
|
|
10029
10186
|
const invoice = this.consultDocumentUseCase.execute(consultDocumentDto);
|
|
10030
10187
|
return invoice;
|
|
10031
10188
|
}
|
|
10189
|
+
nominationInvoice(nominationInvoiceDto) {
|
|
10190
|
+
const xml = this.nominationInvoiceUseCase.execute(nominationInvoiceDto);
|
|
10191
|
+
return xml;
|
|
10192
|
+
}
|
|
10032
10193
|
obtainDigitalSign(digitalSignDto) {
|
|
10033
10194
|
const digitalSign = this.obtainDigitalSignUseCase.execute(digitalSignDto);
|
|
10034
10195
|
return digitalSign;
|