sunat-engine-nest 1.0.3 → 1.0.5
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 +41 -24
- package/dist/sunat-engine.module.d.ts +9 -0
- package/dist/sunat-engine.module.js.map +1 -1
- package/dist/sunat-engine.service.d.ts +10 -7
- package/dist/sunat-engine.service.js +65 -45
- package/dist/sunat-engine.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ pnpm add sunat-engine-nest
|
|
|
14
14
|
|
|
15
15
|
## Configuración
|
|
16
16
|
|
|
17
|
-
Registra el módulo en tu `AppModule
|
|
17
|
+
Registra el módulo en tu `AppModule`. Puedes definir las credenciales de tu empresa **una sola vez** en el módulo usando el campo `sunat`, evitando repetirlas en cada llamada.
|
|
18
18
|
|
|
19
19
|
```typescript
|
|
20
20
|
import { SunatEngineModule } from 'sunat-engine-nest';
|
|
@@ -23,6 +23,13 @@ import { SunatEngineModule } from 'sunat-engine-nest';
|
|
|
23
23
|
@Module({
|
|
24
24
|
imports: [
|
|
25
25
|
SunatEngineModule.forRoot({
|
|
26
|
+
sunat: {
|
|
27
|
+
ruc: '20123456789',
|
|
28
|
+
solUser: 'MODDATOS',
|
|
29
|
+
solPass: 'moddatos',
|
|
30
|
+
certPem: 'BASE64_DEL_P12_O_PEM',
|
|
31
|
+
endpointMode: 'beta', // 'beta' | 'produccion'
|
|
32
|
+
},
|
|
26
33
|
gre: {
|
|
27
34
|
authUrl: 'https://gre-test.nubefact.com/v1',
|
|
28
35
|
apiUrl: 'https://gre-test.nubefact.com/v1',
|
|
@@ -47,6 +54,13 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
|
47
54
|
imports: [ConfigModule],
|
|
48
55
|
inject: [ConfigService],
|
|
49
56
|
useFactory: (config: ConfigService) => ({
|
|
57
|
+
sunat: {
|
|
58
|
+
ruc: config.get('SUNAT_RUC'),
|
|
59
|
+
solUser: config.get('SUNAT_SOL_USER'),
|
|
60
|
+
solPass: config.get('SUNAT_SOL_PASS'),
|
|
61
|
+
certPem: config.get('SUNAT_CERT_PEM'),
|
|
62
|
+
endpointMode: config.get('SUNAT_MODE') ?? 'beta',
|
|
63
|
+
},
|
|
50
64
|
gre: {
|
|
51
65
|
authUrl: config.get('GRE_AUTH_URL'),
|
|
52
66
|
apiUrl: config.get('GRE_API_URL'),
|
|
@@ -60,37 +74,35 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
|
60
74
|
export class AppModule {}
|
|
61
75
|
```
|
|
62
76
|
|
|
63
|
-
## Variables de entorno (GRE)
|
|
77
|
+
## Variables de entorno (sunat + GRE)
|
|
64
78
|
|
|
65
79
|
```env
|
|
80
|
+
SUNAT_RUC=20123456789
|
|
81
|
+
SUNAT_SOL_USER=MODDATOS
|
|
82
|
+
SUNAT_SOL_PASS=moddatos
|
|
83
|
+
SUNAT_CERT_PEM=BASE64_DEL_P12
|
|
84
|
+
SUNAT_MODE=beta
|
|
85
|
+
|
|
66
86
|
GRE_AUTH_URL=https://gre-test.nubefact.com/v1
|
|
67
87
|
GRE_API_URL=https://gre-test.nubefact.com/v1
|
|
68
88
|
GRE_CLIENT_ID=tu_client_id
|
|
69
89
|
GRE_CLIENT_SECRET=tu_client_secret
|
|
70
|
-
GRE_SCOPE=https://api-cpe.sunat.gob.pe
|
|
71
90
|
```
|
|
72
91
|
|
|
73
92
|
## Uso
|
|
74
93
|
|
|
75
|
-
Inyecta `SunatEngineService` en cualquier servicio o controlador:
|
|
94
|
+
Inyecta `SunatEngineService` en cualquier servicio o controlador. Si configuraste `sunat:{}` en el módulo, **no necesitas pasar credenciales en cada llamada**:
|
|
76
95
|
|
|
77
96
|
```typescript
|
|
78
97
|
import { Injectable } from '@nestjs/common';
|
|
79
|
-
import { SunatEngineService, InvoicePayload
|
|
98
|
+
import { SunatEngineService, InvoicePayload } from 'sunat-engine-nest';
|
|
80
99
|
|
|
81
100
|
@Injectable()
|
|
82
101
|
export class InvoicesService {
|
|
83
102
|
constructor(private readonly engine: SunatEngineService) {}
|
|
84
103
|
|
|
85
104
|
async sendInvoice() {
|
|
86
|
-
|
|
87
|
-
ruc: '20123456789',
|
|
88
|
-
solUser: 'MODDATOS',
|
|
89
|
-
solPass: 'moddatos',
|
|
90
|
-
certPem: 'BASE64_DEL_P12_O_PEM',
|
|
91
|
-
endpointMode: 'beta', // 'beta' | 'produccion'
|
|
92
|
-
};
|
|
93
|
-
|
|
105
|
+
// Sin credenciales — usa las del módulo automáticamente
|
|
94
106
|
const payload: InvoicePayload = {
|
|
95
107
|
tipoOperacion: '0101',
|
|
96
108
|
tipoDoc: '01', // 01=Factura, 03=Boleta
|
|
@@ -132,11 +144,25 @@ export class InvoicesService {
|
|
|
132
144
|
mtoImpVenta: 236,
|
|
133
145
|
};
|
|
134
146
|
|
|
135
|
-
return this.engine.sendInvoice(payload
|
|
147
|
+
return this.engine.sendInvoice(payload); // credenciales del módulo
|
|
136
148
|
}
|
|
137
149
|
}
|
|
138
150
|
```
|
|
139
151
|
|
|
152
|
+
También puedes sobreescribir las credenciales por llamada cuando manejas múltiples empresas:
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// Credenciales específicas para esta llamada (tienen prioridad sobre el módulo)
|
|
156
|
+
return this.engine.sendInvoice(payload, {
|
|
157
|
+
ruc: '20987654321',
|
|
158
|
+
solUser: 'OTRO_USUARIO',
|
|
159
|
+
solPass: 'otra_clave',
|
|
160
|
+
certPem: 'OTRO_CERT_BASE64',
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
|
|
140
166
|
## Documentos soportados
|
|
141
167
|
|
|
142
168
|
| Tipo | Método | Descripción |
|
|
@@ -222,16 +248,7 @@ Si este proyecto te ha sido útil y quieres apoyar su desarrollo continuo, puede
|
|
|
222
248
|
|
|
223
249
|
**Número:** `+51 907 596 305`
|
|
224
250
|
|
|
225
|
-
- [Escríbeme por WhatsApp](https://wa.me/51907596305) para consultas, soporte o
|
|
226
|
-
|
|
227
|
-
### Transferencia bancaria (BCP — Soles)
|
|
228
|
-
|
|
229
|
-
| Campo | Detalle |
|
|
230
|
-
|-------|---------|
|
|
231
|
-
| Banco | BCP |
|
|
232
|
-
| Moneda | Soles (PEN) |
|
|
233
|
-
| N° de cuenta | `19399752856058` |
|
|
234
|
-
| CCI | `00219319975285605810` |
|
|
251
|
+
- [Escríbeme por WhatsApp](https://wa.me/51907596305) para consultas, soporte o donaciones.
|
|
235
252
|
|
|
236
253
|
Cualquier aporte, por pequeño que sea, ayuda a mantener la librería actualizada y en funcionamiento. ¡Gracias por tu apoyo!
|
|
237
254
|
|
|
@@ -9,7 +9,16 @@ export interface SunatEngineGreOptions {
|
|
|
9
9
|
solPass?: string;
|
|
10
10
|
scope?: string;
|
|
11
11
|
}
|
|
12
|
+
export interface SunatEngineCredentialsOptions {
|
|
13
|
+
ruc?: string;
|
|
14
|
+
solUser?: string;
|
|
15
|
+
solPass?: string;
|
|
16
|
+
certPem?: string;
|
|
17
|
+
certKey?: string;
|
|
18
|
+
endpointMode?: 'beta' | 'produccion';
|
|
19
|
+
}
|
|
12
20
|
export interface SunatEngineOptions {
|
|
21
|
+
sunat?: SunatEngineCredentialsOptions;
|
|
13
22
|
gre?: SunatEngineGreOptions;
|
|
14
23
|
}
|
|
15
24
|
export interface SunatEngineAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sunat-engine.module.js","sourceRoot":"","sources":["../src/sunat-engine.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAA+E;AAC/E,iEAA4D;AAC5D,oEAA+D;AAC/D,gEAA2D;AAC3D,6DAAwD;AACxD,iEAA4D;AAC5D,qEAAgE;
|
|
1
|
+
{"version":3,"file":"sunat-engine.module.js","sourceRoot":"","sources":["../src/sunat-engine.module.ts"],"names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 @@ import { XmlSignerService } from './signer/xml-signer.service';
|
|
|
3
3
|
import { SunatSoapClient } from './soap/sunat-soap.client';
|
|
4
4
|
import { SunatGreClient } from './gre/sunat-gre.client';
|
|
5
5
|
import { CdrParserService } from './cdr/cdr-parser.service';
|
|
6
|
+
import { SunatEngineOptions } from './sunat-engine.module';
|
|
6
7
|
export declare class SunatEngineService {
|
|
7
8
|
private readonly signer;
|
|
8
9
|
private readonly soap;
|
|
9
10
|
private readonly gre;
|
|
10
11
|
private readonly cdrParser;
|
|
12
|
+
private readonly options;
|
|
11
13
|
private readonly logger;
|
|
12
|
-
constructor(signer: XmlSignerService, soap: SunatSoapClient, gre: SunatGreClient, cdrParser: CdrParserService);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
constructor(signer: XmlSignerService, soap: SunatSoapClient, gre: SunatGreClient, cdrParser: CdrParserService, options: SunatEngineOptions);
|
|
15
|
+
private resolveCredentials;
|
|
16
|
+
sendInvoice(payload: InvoicePayload, credentials?: Partial<CompanyCredentials>): Promise<EngineResponse>;
|
|
17
|
+
sendNote(payload: NotePayload, credentials?: Partial<CompanyCredentials>): Promise<EngineResponse>;
|
|
18
|
+
sendDespatch(payload: DespatchPayload, credentials?: Partial<CompanyCredentials>): Promise<EngineResponse>;
|
|
19
|
+
sendSummary(payload: SummaryPayload, credentials?: Partial<CompanyCredentials>): Promise<EngineResponse>;
|
|
20
|
+
sendVoided(payload: VoidedPayload, credentials?: Partial<CompanyCredentials>): Promise<EngineResponse>;
|
|
21
|
+
getTicketStatus(ticket: string, credentials?: Partial<CompanyCredentials>, endpointType?: 'factura' | 'guia'): Promise<EngineResponse>;
|
|
19
22
|
private signDocument;
|
|
20
23
|
}
|
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
var SunatEngineService_1;
|
|
12
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
16
|
exports.SunatEngineService = void 0;
|
|
@@ -21,25 +24,36 @@ const xml_signer_service_1 = require("./signer/xml-signer.service");
|
|
|
21
24
|
const sunat_soap_client_1 = require("./soap/sunat-soap.client");
|
|
22
25
|
const sunat_gre_client_1 = require("./gre/sunat-gre.client");
|
|
23
26
|
const cdr_parser_service_1 = require("./cdr/cdr-parser.service");
|
|
27
|
+
const sunat_engine_module_1 = require("./sunat-engine.module");
|
|
24
28
|
let SunatEngineService = SunatEngineService_1 = class SunatEngineService {
|
|
25
|
-
constructor(signer, soap, gre, cdrParser) {
|
|
29
|
+
constructor(signer, soap, gre, cdrParser, options) {
|
|
26
30
|
this.signer = signer;
|
|
27
31
|
this.soap = soap;
|
|
28
32
|
this.gre = gre;
|
|
29
33
|
this.cdrParser = cdrParser;
|
|
34
|
+
this.options = options;
|
|
30
35
|
this.logger = new common_1.Logger(SunatEngineService_1.name);
|
|
31
36
|
}
|
|
37
|
+
resolveCredentials(perCall) {
|
|
38
|
+
const global = this.options.sunat ?? {};
|
|
39
|
+
const merged = { ...global, ...perCall };
|
|
40
|
+
if (!merged.ruc || !merged.solUser || !merged.solPass || !merged.certPem) {
|
|
41
|
+
throw new Error('Credenciales incompletas: proporciona ruc, solUser, solPass y certPem en sunat:{} del módulo o en cada llamada');
|
|
42
|
+
}
|
|
43
|
+
return merged;
|
|
44
|
+
}
|
|
32
45
|
async sendInvoice(payload, credentials) {
|
|
46
|
+
const creds = this.resolveCredentials(credentials);
|
|
33
47
|
const xmlUnsigned = (0, invoice_builder_1.buildInvoiceXml)(payload);
|
|
34
|
-
const { signedXml, hash } = this.signDocument(xmlUnsigned,
|
|
35
|
-
const fileName = this.soap.buildZipFileName(
|
|
48
|
+
const { signedXml, hash } = this.signDocument(xmlUnsigned, creds);
|
|
49
|
+
const fileName = this.soap.buildZipFileName(creds.ruc, payload.tipoDoc, payload.serie, payload.correlativo);
|
|
36
50
|
const result = await this.soap.sendBill({
|
|
37
|
-
ruc:
|
|
38
|
-
solUser:
|
|
39
|
-
solPass:
|
|
51
|
+
ruc: creds.ruc,
|
|
52
|
+
solUser: creds.solUser,
|
|
53
|
+
solPass: creds.solPass,
|
|
40
54
|
fileName,
|
|
41
55
|
xmlSigned: signedXml,
|
|
42
|
-
mode:
|
|
56
|
+
mode: creds.endpointMode ?? 'beta',
|
|
43
57
|
});
|
|
44
58
|
if (!result.success) {
|
|
45
59
|
return { xml: Buffer.from(signedXml).toString('base64'), hash, sunatResponse: { success: false, error: result.error } };
|
|
@@ -58,16 +72,17 @@ let SunatEngineService = SunatEngineService_1 = class SunatEngineService {
|
|
|
58
72
|
};
|
|
59
73
|
}
|
|
60
74
|
async sendNote(payload, credentials) {
|
|
75
|
+
const creds = this.resolveCredentials(credentials);
|
|
61
76
|
const xmlUnsigned = (0, note_builder_1.buildNoteXml)(payload);
|
|
62
|
-
const { signedXml, hash } = this.signDocument(xmlUnsigned,
|
|
63
|
-
const fileName = this.soap.buildZipFileName(
|
|
77
|
+
const { signedXml, hash } = this.signDocument(xmlUnsigned, creds);
|
|
78
|
+
const fileName = this.soap.buildZipFileName(creds.ruc, payload.tipoDoc, payload.serie, payload.correlativo);
|
|
64
79
|
const result = await this.soap.sendBill({
|
|
65
|
-
ruc:
|
|
66
|
-
solUser:
|
|
67
|
-
solPass:
|
|
80
|
+
ruc: creds.ruc,
|
|
81
|
+
solUser: creds.solUser,
|
|
82
|
+
solPass: creds.solPass,
|
|
68
83
|
fileName,
|
|
69
84
|
xmlSigned: signedXml,
|
|
70
|
-
mode:
|
|
85
|
+
mode: creds.endpointMode ?? 'beta',
|
|
71
86
|
});
|
|
72
87
|
const cdrResponse = result.cdrZipBase64
|
|
73
88
|
? await this.cdrParser.parse(result.cdrZipBase64)
|
|
@@ -84,19 +99,20 @@ let SunatEngineService = SunatEngineService_1 = class SunatEngineService {
|
|
|
84
99
|
};
|
|
85
100
|
}
|
|
86
101
|
async sendDespatch(payload, credentials) {
|
|
102
|
+
const creds = this.resolveCredentials(credentials);
|
|
87
103
|
const xmlUnsigned = (0, despatch_builder_1.buildDespatchXml)(payload);
|
|
88
|
-
const { signedXml, hash } = this.signDocument(xmlUnsigned,
|
|
104
|
+
const { signedXml, hash } = this.signDocument(xmlUnsigned, creds);
|
|
89
105
|
const result = await this.gre.sendGRE({
|
|
90
|
-
ruc:
|
|
91
|
-
solUser:
|
|
92
|
-
solPass:
|
|
106
|
+
ruc: creds.ruc,
|
|
107
|
+
solUser: creds.solUser,
|
|
108
|
+
solPass: creds.solPass,
|
|
93
109
|
serie: payload.serie,
|
|
94
110
|
correlativo: payload.correlativo,
|
|
95
111
|
signedXml,
|
|
96
|
-
clientId:
|
|
97
|
-
clientSecret:
|
|
98
|
-
authUrl:
|
|
99
|
-
apiUrl:
|
|
112
|
+
clientId: creds.greClientId,
|
|
113
|
+
clientSecret: creds.greClientSecret,
|
|
114
|
+
authUrl: creds.greAuthUrl,
|
|
115
|
+
apiUrl: creds.greApiUrl,
|
|
100
116
|
});
|
|
101
117
|
return {
|
|
102
118
|
xml: Buffer.from(signedXml).toString('base64'),
|
|
@@ -109,17 +125,18 @@ let SunatEngineService = SunatEngineService_1 = class SunatEngineService {
|
|
|
109
125
|
};
|
|
110
126
|
}
|
|
111
127
|
async sendSummary(payload, credentials) {
|
|
128
|
+
const creds = this.resolveCredentials(credentials);
|
|
112
129
|
const xmlUnsigned = (0, summary_builder_1.buildSummaryXml)(payload);
|
|
113
|
-
const { signedXml, hash } = this.signDocument(xmlUnsigned,
|
|
130
|
+
const { signedXml, hash } = this.signDocument(xmlUnsigned, creds);
|
|
114
131
|
const fecha = payload.fecResumen.slice(0, 10);
|
|
115
|
-
const fileName = this.soap.buildSummaryFileName(
|
|
132
|
+
const fileName = this.soap.buildSummaryFileName(creds.ruc, 'RC', fecha, payload.correlativo);
|
|
116
133
|
const result = await this.soap.sendSummary({
|
|
117
|
-
ruc:
|
|
118
|
-
solUser:
|
|
119
|
-
solPass:
|
|
134
|
+
ruc: creds.ruc,
|
|
135
|
+
solUser: creds.solUser,
|
|
136
|
+
solPass: creds.solPass,
|
|
120
137
|
fileName,
|
|
121
138
|
xmlSigned: signedXml,
|
|
122
|
-
mode:
|
|
139
|
+
mode: creds.endpointMode ?? 'beta',
|
|
123
140
|
});
|
|
124
141
|
return {
|
|
125
142
|
xml: Buffer.from(signedXml).toString('base64'),
|
|
@@ -132,17 +149,18 @@ let SunatEngineService = SunatEngineService_1 = class SunatEngineService {
|
|
|
132
149
|
};
|
|
133
150
|
}
|
|
134
151
|
async sendVoided(payload, credentials) {
|
|
152
|
+
const creds = this.resolveCredentials(credentials);
|
|
135
153
|
const xmlUnsigned = (0, voided_builder_1.buildVoidedXml)(payload);
|
|
136
|
-
const { signedXml, hash } = this.signDocument(xmlUnsigned,
|
|
154
|
+
const { signedXml, hash } = this.signDocument(xmlUnsigned, creds);
|
|
137
155
|
const fecha = payload.fecGeneracion.slice(0, 10);
|
|
138
|
-
const fileName = this.soap.buildSummaryFileName(
|
|
156
|
+
const fileName = this.soap.buildSummaryFileName(creds.ruc, 'RA', fecha, payload.correlativo);
|
|
139
157
|
const result = await this.soap.sendSummary({
|
|
140
|
-
ruc:
|
|
141
|
-
solUser:
|
|
142
|
-
solPass:
|
|
158
|
+
ruc: creds.ruc,
|
|
159
|
+
solUser: creds.solUser,
|
|
160
|
+
solPass: creds.solPass,
|
|
143
161
|
fileName,
|
|
144
162
|
xmlSigned: signedXml,
|
|
145
|
-
mode:
|
|
163
|
+
mode: creds.endpointMode ?? 'beta',
|
|
146
164
|
});
|
|
147
165
|
return {
|
|
148
166
|
xml: Buffer.from(signedXml).toString('base64'),
|
|
@@ -155,16 +173,17 @@ let SunatEngineService = SunatEngineService_1 = class SunatEngineService {
|
|
|
155
173
|
};
|
|
156
174
|
}
|
|
157
175
|
async getTicketStatus(ticket, credentials, endpointType = 'factura') {
|
|
176
|
+
const creds = this.resolveCredentials(credentials);
|
|
158
177
|
if (endpointType === 'guia') {
|
|
159
178
|
const result = await this.gre.getStatus({
|
|
160
|
-
ruc:
|
|
161
|
-
solUser:
|
|
162
|
-
solPass:
|
|
179
|
+
ruc: creds.ruc,
|
|
180
|
+
solUser: creds.solUser,
|
|
181
|
+
solPass: creds.solPass,
|
|
163
182
|
ticket,
|
|
164
|
-
clientId:
|
|
165
|
-
clientSecret:
|
|
166
|
-
authUrl:
|
|
167
|
-
apiUrl:
|
|
183
|
+
clientId: creds.greClientId,
|
|
184
|
+
clientSecret: creds.greClientSecret,
|
|
185
|
+
authUrl: creds.greAuthUrl,
|
|
186
|
+
apiUrl: creds.greApiUrl,
|
|
168
187
|
});
|
|
169
188
|
const cdrResponse = result.cdrZipBase64
|
|
170
189
|
? await this.cdrParser.parse(result.cdrZipBase64)
|
|
@@ -179,11 +198,11 @@ let SunatEngineService = SunatEngineService_1 = class SunatEngineService {
|
|
|
179
198
|
};
|
|
180
199
|
}
|
|
181
200
|
const result = await this.soap.getStatus({
|
|
182
|
-
ruc:
|
|
183
|
-
solUser:
|
|
184
|
-
solPass:
|
|
201
|
+
ruc: creds.ruc,
|
|
202
|
+
solUser: creds.solUser,
|
|
203
|
+
solPass: creds.solPass,
|
|
185
204
|
ticket,
|
|
186
|
-
mode:
|
|
205
|
+
mode: creds.endpointMode ?? 'beta',
|
|
187
206
|
endpointType,
|
|
188
207
|
});
|
|
189
208
|
const cdrResponse = result.cdrZipBase64
|
|
@@ -220,9 +239,10 @@ let SunatEngineService = SunatEngineService_1 = class SunatEngineService {
|
|
|
220
239
|
exports.SunatEngineService = SunatEngineService;
|
|
221
240
|
exports.SunatEngineService = SunatEngineService = SunatEngineService_1 = __decorate([
|
|
222
241
|
(0, common_1.Injectable)(),
|
|
242
|
+
__param(4, (0, common_1.Inject)(sunat_engine_module_1.SUNAT_ENGINE_OPTIONS)),
|
|
223
243
|
__metadata("design:paramtypes", [xml_signer_service_1.XmlSignerService,
|
|
224
244
|
sunat_soap_client_1.SunatSoapClient,
|
|
225
245
|
sunat_gre_client_1.SunatGreClient,
|
|
226
|
-
cdr_parser_service_1.CdrParserService])
|
|
246
|
+
cdr_parser_service_1.CdrParserService, Object])
|
|
227
247
|
], SunatEngineService);
|
|
228
248
|
//# sourceMappingURL=sunat-engine.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sunat-engine.service.js","sourceRoot":"","sources":["../src/sunat-engine.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sunat-engine.service.js","sourceRoot":"","sources":["../src/sunat-engine.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA4D;AAU5D,2DAAwD;AACxD,qDAAkD;AAClD,6DAA0D;AAC1D,2DAAwD;AACxD,yDAAsD;AACtD,oEAA+D;AAC/D,gEAA2D;AAC3D,6DAAwD;AACxD,iEAA4D;AAC5D,+DAAiF;AAG1E,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAG7B,YACmB,MAAwB,EACxB,IAAqB,EACrB,GAAmB,EACnB,SAA2B,EACd,OAA4C;QAJzD,WAAM,GAAN,MAAM,CAAkB;QACxB,SAAI,GAAJ,IAAI,CAAiB;QACrB,QAAG,GAAH,GAAG,CAAgB;QACnB,cAAS,GAAT,SAAS,CAAkB;QACG,YAAO,GAAP,OAAO,CAAoB;QAP3D,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;IAQ3D,CAAC;IAEI,kBAAkB,CAAC,OAAqC;QAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QACxC,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,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