@facturacr/atv-sdk 0.0.8-beta → 0.0.9-beta
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/__tests__/tests/ATV/index.test.ts +39 -39
- package/examples/confirmXML.ts +1 -1
- package/examples/createAndSend.ts +1 -1
- package/examples/getToken.ts +2 -2
- package/package.json +1 -1
- package/src/ATV/core/Clave.ts +1 -1
- package/src/ATV/core/Document.ts +1 -1
- package/src/ATV/core/DocumentType.ts +1 -1
- package/src/ATV/core/FullConsecutive.ts +1 -1
- package/src/ATV/core/OrderLine.ts +1 -1
- package/src/ATV/core/Person.ts +1 -1
- package/src/ATV/core/Summary.type.ts +1 -1
- package/src/ATV/index.ts +1 -2
- package/src/ATV/types.ts +1 -1
- package/src/ATV/useCases/createDocument/index.ts +5 -5
- package/src/ATV/useCases/createDocument/types.ts +1 -1
- package/src/lib/genJSON/confirmXML.ts +1 -1
- package/src/services/getToken/GetToken.ts +1 -1
- package/src/services/send/index.ts +1 -1
- package/tools/xsdToJsonSchema.ts +2 -2
|
@@ -1,50 +1,50 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
|
-
import { ATV } from
|
|
2
|
+
import { ATV } from '@src/ATV'
|
|
3
3
|
import 'jest-xml-matcher'
|
|
4
|
-
import { createDocumentInputStub } from
|
|
4
|
+
import { createDocumentInputStub } from '@test/stubs/createDocument.stub'
|
|
5
5
|
const fakePem = fs.readFileSync('__tests__/stubs/dummyKeys/client-identity.p12', 'binary')
|
|
6
6
|
const fakePassword = '1234'
|
|
7
7
|
const expectXml = fs.readFileSync('__tests__/stubs/commonExpectedXml.xml', 'utf-8')
|
|
8
8
|
|
|
9
9
|
describe('Create Document (Invoice)', () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
beforeAll(() => {
|
|
11
|
+
jest.useFakeTimers()
|
|
12
|
+
jest.setSystemTime(new Date(2024, 3, 1, 0, 0, 0, 0))
|
|
13
|
+
})
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})
|
|
35
|
-
expect(createdDoc.command.data.comprobanteXml).toBeDefined()
|
|
36
|
-
expect(createdDoc.extraData.xml).toBeDefined()
|
|
15
|
+
it('should create document and generate a correct command', async () => {
|
|
16
|
+
const atv = new ATV({}, 'stg')
|
|
17
|
+
const createdDoc = await atv.createDocumentCommand({
|
|
18
|
+
document: createDocumentInputStub,
|
|
19
|
+
token: 'fake-token',
|
|
20
|
+
signatureOptions: {
|
|
21
|
+
buffer: fakePem,
|
|
22
|
+
password: fakePassword
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
expect(createdDoc.command).toMatchObject({
|
|
26
|
+
url: 'https://api-sandbox.comprobanteselectronicos.go.cr/recepcion/v1/recepcion',
|
|
27
|
+
method: 'post'
|
|
28
|
+
})
|
|
29
|
+
expect(createdDoc.command.data).toMatchObject({
|
|
30
|
+
clave: '50601042400020692014200100001010000000002100000001',
|
|
31
|
+
fecha: '2024-04-01T00:00:00.000Z',
|
|
32
|
+
emisor: { tipoIdentificacion: '01', numeroIdentificacion: '206920142' },
|
|
33
|
+
receptor: { tipoIdentificacion: '02', numeroIdentificacion: '3102759157' }
|
|
37
34
|
})
|
|
35
|
+
expect(createdDoc.command.data.comprobanteXml).toBeDefined()
|
|
36
|
+
expect(createdDoc.extraData.xml).toBeDefined()
|
|
37
|
+
})
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
expect(createdDoc.command.data.comprobanteXml).toMatchSnapshot()
|
|
48
|
-
expect(createdDoc.extraData.xml).toEqualXML(expectXml)
|
|
39
|
+
it('should create document and generate a correct command', async () => {
|
|
40
|
+
const atv = new ATV({}, 'stg')
|
|
41
|
+
// @ts-ignore just for testing
|
|
42
|
+
const createdDoc = await atv.createDocumentCommand({
|
|
43
|
+
document: createDocumentInputStub,
|
|
44
|
+
token: 'fake-token',
|
|
45
|
+
signatureOptions: undefined
|
|
49
46
|
})
|
|
50
|
-
|
|
47
|
+
expect(createdDoc.command.data.comprobanteXml).toMatchSnapshot()
|
|
48
|
+
expect(createdDoc.extraData.xml).toEqualXML(expectXml)
|
|
49
|
+
})
|
|
50
|
+
})
|
package/examples/confirmXML.ts
CHANGED
|
@@ -19,7 +19,7 @@ const pem = fs.readFileSync(SOURCE_P12_URI, 'binary')
|
|
|
19
19
|
console.log('requestStub consecutivo', createDocumentInputStub.consecutiveIdentifier)
|
|
20
20
|
|
|
21
21
|
// TODO: dynamic param --identifier 1 args[x]
|
|
22
|
-
createDocumentInputStub.consecutiveIdentifier = '1'
|
|
22
|
+
createDocumentInputStub.consecutiveIdentifier = '1'
|
|
23
23
|
|
|
24
24
|
function getConfimation(atv: ATV, token: string, location: string, ms: number): Promise<any> {
|
|
25
25
|
return new Promise((resolve, reject): any => {
|
package/examples/getToken.ts
CHANGED
|
@@ -4,8 +4,8 @@ const IS_STG = process.env.IS_STG
|
|
|
4
4
|
const USERNAME_TEST = process.env.USERNAME_TEST
|
|
5
5
|
const PASSWORD_TEST = process.env.PASSWORD_TEST
|
|
6
6
|
console.log('process.env.IS_STG', IS_STG)
|
|
7
|
-
console.log('password', PASSWORD_TEST)
|
|
8
|
-
const mode = IS_STG ? 'stg' : undefined
|
|
7
|
+
console.log('password', PASSWORD_TEST)
|
|
8
|
+
const mode = IS_STG ? 'stg' : undefined
|
|
9
9
|
const atv = new ATV({}, mode)
|
|
10
10
|
const tokenData = atv.getToken({
|
|
11
11
|
username: USERNAME_TEST,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@facturacr/atv-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9-beta",
|
|
4
4
|
"description": "Librería (SDK) de Javascript/NodeJS para acceder al API de Administración Tributaria Virtual (ATV) del Ministerio de Hacienda.",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
package/src/ATV/core/Clave.ts
CHANGED
package/src/ATV/core/Document.ts
CHANGED
|
@@ -10,7 +10,7 @@ const map: {[key: string]: DocumentTypeValues} = {
|
|
|
10
10
|
type DocumentTypeValues = 'FE' | 'ND' | 'NC' | 'TE'
|
|
11
11
|
|
|
12
12
|
export class DocumentType {
|
|
13
|
-
value: DocumentTypeValues
|
|
13
|
+
value: DocumentTypeValues
|
|
14
14
|
|
|
15
15
|
constructor(value: DocumentTypeValues) {
|
|
16
16
|
this.value = value
|
package/src/ATV/core/Person.ts
CHANGED
package/src/ATV/index.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import axios from 'axios'
|
|
3
2
|
import { GetToken } from '../services/getToken/GetToken'
|
|
4
3
|
import { GetTokenDto, GetTokenResponse } from '../services/getToken/types'
|
|
@@ -48,7 +47,7 @@ export class ATV {
|
|
|
48
47
|
public async sendConfirmation(input: SendConfirmationInput) {
|
|
49
48
|
try {
|
|
50
49
|
const response = await axios(input)
|
|
51
|
-
console.log('response', response)
|
|
50
|
+
console.log('response', response)
|
|
52
51
|
const xmlResponse = response.data['respuesta-xml']
|
|
53
52
|
if (!xmlResponse) {
|
|
54
53
|
const state = response.data['ind-estado']
|
package/src/ATV/types.ts
CHANGED
|
@@ -20,7 +20,7 @@ const options: { [key: string]: { serviceUrl: string}} = {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export class CreateDocumentCommand {
|
|
23
|
-
private readonly serviceUrl: string
|
|
23
|
+
private readonly serviceUrl: string
|
|
24
24
|
|
|
25
25
|
constructor(scope: ATV) {
|
|
26
26
|
this.serviceUrl = options[scope.mode].serviceUrl
|
|
@@ -72,13 +72,13 @@ export class CreateDocumentCommand {
|
|
|
72
72
|
const fullConsective = this.createFullConsecutive(document, documentType)
|
|
73
73
|
const orderLines = this.createOrderLines(document)
|
|
74
74
|
return Document.create({
|
|
75
|
-
clave
|
|
75
|
+
clave,
|
|
76
76
|
fullConsecutive: fullConsective,
|
|
77
|
-
orderLines
|
|
77
|
+
orderLines,
|
|
78
78
|
activityCode: document.activityCode,
|
|
79
79
|
issueDate: new Date(),
|
|
80
|
-
emitter
|
|
81
|
-
receiver
|
|
80
|
+
emitter,
|
|
81
|
+
receiver,
|
|
82
82
|
conditionSale: '01',
|
|
83
83
|
paymentMethod: '01'
|
|
84
84
|
})
|
|
@@ -41,7 +41,7 @@ export function getFinalMessage(fullInvoice: any, consecutivoReceptor: string, x
|
|
|
41
41
|
tipoIdentificacion: fullInvoice.Emisor.Identificacion.Tipo,
|
|
42
42
|
numeroIdentificacion: fullInvoice.Emisor.Identificacion.Numero
|
|
43
43
|
},
|
|
44
|
-
consecutivoReceptor
|
|
44
|
+
consecutivoReceptor,
|
|
45
45
|
comprobanteXml: xmlBase64
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -16,7 +16,7 @@ const options: { [key: string]: GetTokenInternalProps} = {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export class GetToken {
|
|
19
|
-
private readonly props: GetTokenInternalProps
|
|
19
|
+
private readonly props: GetTokenInternalProps
|
|
20
20
|
constructor(scope: ATV) {
|
|
21
21
|
this.props = this.initProps(scope.mode)
|
|
22
22
|
}
|
|
@@ -20,7 +20,7 @@ export function send(token: string, postOptions: any): Record<string, any> {
|
|
|
20
20
|
|
|
21
21
|
export function sendToCustomURL(token: string, url: string): Record<string, any> {
|
|
22
22
|
return axios({
|
|
23
|
-
url
|
|
23
|
+
url,
|
|
24
24
|
method: 'get',
|
|
25
25
|
headers: {
|
|
26
26
|
Authorization: 'bearer ' + token,
|
package/tools/xsdToJsonSchema.ts
CHANGED
|
@@ -73,7 +73,7 @@ function processElementsFromComplexType(array: Array<any>): any {
|
|
|
73
73
|
if (propKey) {
|
|
74
74
|
newObj[propKey] = {
|
|
75
75
|
description: element?.annotation?.documentation,
|
|
76
|
-
simpleType
|
|
76
|
+
simpleType
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -84,7 +84,7 @@ function processComplexType(object: any): any {
|
|
|
84
84
|
const elements = processElementsFromComplexType(object?.sequence?.element)
|
|
85
85
|
const newObject = {}
|
|
86
86
|
newObject[object?.attributes?.name] = {
|
|
87
|
-
elements
|
|
87
|
+
elements
|
|
88
88
|
}
|
|
89
89
|
return newObject
|
|
90
90
|
}
|