sunat-engine-nest 1.0.7 → 1.0.8

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.
Files changed (2) hide show
  1. package/README.md +63 -79
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -54,6 +54,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
54
54
  imports: [ConfigModule],
55
55
  inject: [ConfigService],
56
56
  useFactory: (config: ConfigService) => ({
57
+ provider: config.get('PROVIDER'), // 'sunat' | 'ose'
57
58
  sunat: {
58
59
  ruc: config.get('SUNAT_RUC'),
59
60
  solUser: config.get('SUNAT_SOL_USER'),
@@ -67,6 +68,10 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
67
68
  clientId: config.get('GRE_CLIENT_ID'),
68
69
  clientSecret: config.get('GRE_CLIENT_SECRET'),
69
70
  },
71
+ ose: {
72
+ url: config.get('OSE_URL'),
73
+ token: config.get('OSE_TOKEN'),
74
+ },
70
75
  }),
71
76
  }),
72
77
  ],
@@ -74,19 +79,75 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
74
79
  export class AppModule {}
75
80
  ```
76
81
 
77
- ## Variables de entorno (sunat + GRE)
82
+ ## Variables de entorno
78
83
 
79
84
  ```env
85
+ # Credenciales SUNAT
80
86
  SUNAT_RUC=20123456789
81
87
  SUNAT_SOL_USER=MODDATOS
82
88
  SUNAT_SOL_PASS=moddatos
83
89
  SUNAT_CERT_PEM=BASE64_DEL_P12
84
90
  SUNAT_MODE=beta
85
91
 
92
+ # GRE (Guía de Remisión Electrónica)
86
93
  GRE_AUTH_URL=https://gre-test.nubefact.com/v1
87
94
  GRE_API_URL=https://gre-test.nubefact.com/v1
88
95
  GRE_CLIENT_ID=tu_client_id
89
96
  GRE_CLIENT_SECRET=tu_client_secret
97
+
98
+ # OSE (solo si provider=ose)
99
+ PROVIDER=ose
100
+ OSE_URL=https://api.tuose.com/v1/documents
101
+ OSE_TOKEN=tu_token_aqui
102
+ ```
103
+
104
+ ## Proveedor: SUNAT directo vs OSE
105
+
106
+ Puedes elegir enviar tus comprobantes **directamente a SUNAT** o a través de un **OSE (Operador de Servicios Electrónicos)** autorizado como Nubefact, EFACT, DigiFlow, Bizlinks, entre otros.
107
+
108
+ ```typescript
109
+ // Envío directo a SUNAT (por defecto)
110
+ SunatEngineModule.forRoot({
111
+ provider: 'sunat',
112
+ sunat: { ruc: '...', solUser: '...', solPass: '...', certPem: '...' },
113
+ })
114
+
115
+ // Envío a través de un OSE
116
+ SunatEngineModule.forRoot({
117
+ provider: 'ose',
118
+ sunat: { ruc: '...', certPem: '...' }, // solo se usa para firmar el XML
119
+ ose: {
120
+ url: 'https://api.tuose.com/v1/documents',
121
+ token: 'TU_TOKEN_OSE', // Bearer token
122
+ // o en lugar de token:
123
+ // username: 'usuario',
124
+ // password: 'clave',
125
+ },
126
+ })
127
+ ```
128
+
129
+ > El `OseClient` es genérico y compatible con cualquier OSE que acepte `{ fileName, contentFile }` (ZIP en base64) vía POST con autenticación Bearer o Basic.
130
+
131
+ ## Certificado digital
132
+
133
+ El motor acepta el certificado en tres formatos:
134
+
135
+ ```typescript
136
+ // Formato 1: ruta al archivo .p12 o .pem en disco
137
+ const credentials: CompanyCredentials = {
138
+ certPem: '/ruta/al/certificado.p12',
139
+ };
140
+
141
+ // Formato 2: ruta a cert PEM + ruta a clave privada PEM por separado
142
+ const credentials: CompanyCredentials = {
143
+ certPem: '/ruta/al/cert.pem',
144
+ certKey: '/ruta/al/key.pem',
145
+ };
146
+
147
+ // Formato 3: contenido directo en base64 (.p12) o texto PEM
148
+ const credentials: CompanyCredentials = {
149
+ certPem: 'MIIKJAIBAzCCCd4GCSqGSI...', // .p12 en base64
150
+ };
90
151
  ```
91
152
 
92
153
  ## Uso
@@ -111,7 +172,7 @@ export class InvoicesService {
111
172
  fechaEmision: '2026-07-20T00:00:00-05:00',
112
173
  tipoMoneda: 'PEN',
113
174
  company: {
114
- ruc: '20123456789',
175
+ ruc: '20123456789',
115
176
  razonSocial: 'MI EMPRESA S.A.C.',
116
177
  address: { direccion: 'Av. Principal 123, Lima' },
117
178
  },
@@ -161,8 +222,6 @@ return this.engine.sendInvoice(payload, {
161
222
  });
162
223
  ```
163
224
 
164
- ```
165
-
166
225
  ## Documentos soportados
167
226
 
168
227
  | Tipo | Método | Descripción |
@@ -194,28 +253,6 @@ export class InvoicesService {
194
253
  }
195
254
  ```
196
255
 
197
- ## Certificado digital
198
-
199
- El motor acepta el certificado en tres formatos:
200
-
201
- ```typescript
202
- // Formato 1: ruta al archivo .p12 o .pem en disco
203
- const credentials: CompanyCredentials = {
204
- certPem: '/ruta/al/certificado.p12',
205
- };
206
-
207
- // Formato 2: ruta a cert PEM + ruta a clave privada PEM por separado
208
- const credentials: CompanyCredentials = {
209
- certPem: '/ruta/al/cert.pem',
210
- certKey: '/ruta/al/key.pem',
211
- };
212
-
213
- // Formato 3: contenido directo en base64 (.p12) o texto PEM
214
- const credentials: CompanyCredentials = {
215
- certPem: 'MIIKJAIBAzCCCd4GCSqGSI...', // .p12 en base64
216
- };
217
- ```
218
-
219
256
  ## Respuesta del motor
220
257
 
221
258
  ```typescript
@@ -243,59 +280,6 @@ interface EngineResponse {
243
280
  | `beta` | e-beta.sunat.gob.pe | gre-test.nubefact.com |
244
281
  | `produccion` | e-factura.sunat.gob.pe | api-cpe.sunat.gob.pe |
245
282
 
246
- ## Proveedor: SUNAT directo vs OSE
247
-
248
- Puedes elegir enviar tus comprobantes **directamente a SUNAT** o a través de un **OSE (Operador de Servicios Electrónicos)** autorizado como Nubefact, EFACT, DigiFlow, Bizlinks, entre otros.
249
-
250
- ```typescript
251
- // Envío directo a SUNAT (por defecto)
252
- SunatEngineModule.forRoot({
253
- provider: 'sunat',
254
- sunat: { ruc: '...', solUser: '...', solPass: '...', certPem: '...' },
255
- })
256
-
257
- // Envío a través de un OSE
258
- SunatEngineModule.forRoot({
259
- provider: 'ose',
260
- sunat: { ruc: '...', certPem: '...' }, // solo se usa para firmar el XML
261
- ose: {
262
- url: 'https://api.tuose.com/v1/documents',
263
- token: 'TU_TOKEN_OSE', // Bearer token
264
- // o en lugar de token:
265
- // username: 'usuario',
266
- // password: 'clave',
267
- },
268
- })
269
- ```
270
-
271
- Con variables de entorno:
272
-
273
- ```typescript
274
- SunatEngineModule.forRootAsync({
275
- useFactory: (config: ConfigService) => ({
276
- provider: config.get('PROVIDER'), // 'sunat' | 'ose'
277
- sunat: {
278
- ruc: config.get('SUNAT_RUC'),
279
- solUser: config.get('SUNAT_SOL_USER'),
280
- solPass: config.get('SUNAT_SOL_PASS'),
281
- certPem: config.get('SUNAT_CERT_PEM'),
282
- },
283
- ose: {
284
- url: config.get('OSE_URL'),
285
- token: config.get('OSE_TOKEN'),
286
- },
287
- }),
288
- })
289
- ```
290
-
291
- ```env
292
- PROVIDER=ose
293
- OSE_URL=https://api.tuose.com/v1/documents
294
- OSE_TOKEN=tu_token_aqui
295
- ```
296
-
297
- > El `OseClient` es genérico y compatible con cualquier OSE que acepte `{ fileName, contentFile }` (ZIP en base64) vía POST con autenticación Bearer o Basic.
298
-
299
283
  ## Soporte y actualizaciones
300
284
 
301
285
  SUNAT actualiza continuamente sus esquemas, validaciones y normativas de facturación electrónica. Este paquete recibe mantenimiento activo para mantenerse alineado con cada cambio oficial, garantizando que tu integración siga funcionando sin interrupciones.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "type": "individual",
5
5
  "url": "https://wa.me/51907596305"
6
6
  },
7
- "version": "1.0.7",
7
+ "version": "1.0.8",
8
8
  "description": "Motor de Facturación Electrónica SUNAT UBL 2.1 para NestJS",
9
9
  "author": "carlosrojasramirez25-sketch",
10
10
  "license": "MIT",