@facturacr/atv-sdk 0.0.0-beta → 0.0.2-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/.env.example +7 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/pull_request_template.md +7 -0
- package/.github/workflows/ci.yml +3 -3
- package/CODE_OF_CONDUCT.md +128 -0
- package/LICENSE +21 -0
- package/README.md +8 -1
- package/__tests__/stubs/dummyKeys/README.md +19 -0
- package/__tests__/stubs/frontendRequest.stub.ts +6 -5
- package/__tests__/stubs/token.stub.ts +18 -0
- package/__tests__/tests/electronicBill.test.ts +28 -0
- package/__tests__/{unit → tests}/getClave.test.ts +2 -2
- package/__tests__/tests/lib/getClave.test.ts +11 -0
- package/__tests__/tests/services/getToken.test.ts +15 -0
- package/atv-structures/4.3/FacturaElectronicaExportacion_V4.3.xsd.xml +1747 -0
- package/atv-structures/4.3/FacturaElectronica_V4.3.xsd.xml +1781 -0
- package/dist/__tests__/stubs/frontendRequest.stub.d.ts +3 -0
- package/dist/__tests__/stubs/frontendRequest.stub.js +61 -0
- package/dist/__tests__/stubs/frontendRequest.stub.js.map +1 -0
- package/dist/__tests__/stubs/token.stub.d.ts +17 -0
- package/dist/__tests__/stubs/token.stub.js +21 -0
- package/dist/__tests__/stubs/token.stub.js.map +1 -0
- package/dist/__tests__/tests/electronicBill.test.d.ts +1 -0
- package/dist/__tests__/tests/electronicBill.test.js +38 -0
- package/dist/__tests__/tests/electronicBill.test.js.map +1 -0
- package/dist/__tests__/tests/getClave.test.d.ts +1 -0
- package/dist/__tests__/tests/getClave.test.js +15 -0
- package/dist/__tests__/tests/getClave.test.js.map +1 -0
- package/dist/__tests__/tests/getToken.test.d.ts +0 -0
- package/dist/__tests__/tests/getToken.test.js +28 -0
- package/dist/__tests__/tests/getToken.test.js.map +1 -0
- package/dist/__tests__/tests/lib/getClave.test.d.ts +1 -0
- package/dist/__tests__/tests/lib/getClave.test.js +15 -0
- package/dist/__tests__/tests/lib/getClave.test.js.map +1 -0
- package/dist/__tests__/tests/services/getToken.test.d.ts +1 -0
- package/dist/__tests__/tests/services/getToken.test.js +27 -0
- package/dist/__tests__/tests/services/getToken.test.js.map +1 -0
- package/dist/examples/confirmXML.d.ts +1 -0
- package/dist/examples/confirmXML.js +89 -0
- package/dist/examples/confirmXML.js.map +1 -0
- package/dist/examples/consultXML.d.ts +1 -0
- package/dist/examples/consultXML.js +55 -0
- package/dist/examples/consultXML.js.map +1 -0
- package/dist/examples/createAndSend.d.ts +1 -0
- package/dist/examples/createAndSend.js +78 -0
- package/dist/examples/createAndSend.js.map +1 -0
- package/dist/examples/createCreditNote.d.ts +1 -0
- package/dist/examples/createCreditNote.js +52 -0
- package/dist/examples/createCreditNote.js.map +1 -0
- package/dist/examples/createDebitNote.d.ts +1 -0
- package/dist/examples/createDebitNote.js +52 -0
- package/dist/examples/createDebitNote.js.map +1 -0
- package/dist/examples/genBasicXML.d.ts +1 -0
- package/dist/examples/genBasicXML.js +44 -0
- package/dist/examples/genBasicXML.js.map +1 -0
- package/dist/examples/getClave.d.ts +1 -0
- package/dist/examples/getClave.js +12 -0
- package/dist/examples/getClave.js.map +1 -0
- package/dist/examples/getToken.d.ts +1 -0
- package/dist/examples/getToken.js +22 -0
- package/dist/examples/getToken.js.map +1 -0
- package/dist/src/confirmXML.d.ts +8 -0
- package/dist/src/confirmXML.js +44 -0
- package/dist/src/confirmXML.js.map +1 -0
- package/dist/src/creditNote.d.ts +14 -0
- package/dist/src/creditNote.js +77 -0
- package/dist/src/creditNote.js.map +1 -0
- package/dist/src/data/codigoMoneda.d.ts +1 -0
- package/dist/src/data/codigoMoneda.js +184 -0
- package/dist/src/data/codigoMoneda.js.map +1 -0
- package/dist/src/data/exoneracion.d.ts +1 -0
- package/dist/src/data/exoneracion.js +15 -0
- package/dist/src/data/exoneracion.js.map +1 -0
- package/dist/src/data/impuestos.d.ts +25 -0
- package/dist/src/data/impuestos.js +51 -0
- package/dist/src/data/impuestos.js.map +1 -0
- package/dist/src/data/tipoCedula.d.ts +7 -0
- package/dist/src/data/tipoCedula.js +17 -0
- package/dist/src/data/tipoCedula.js.map +1 -0
- package/dist/src/data/tipoDocumento.d.ts +26 -0
- package/dist/src/data/tipoDocumento.js +30 -0
- package/dist/src/data/tipoDocumento.js.map +1 -0
- package/dist/src/data/unidadesMedida.d.ts +5 -0
- package/dist/src/data/unidadesMedida.js +141 -0
- package/dist/src/data/unidadesMedida.js.map +1 -0
- package/dist/src/debitNote.d.ts +14 -0
- package/dist/src/debitNote.js +77 -0
- package/dist/src/debitNote.js.map +1 -0
- package/dist/src/electronicBill.d.ts +3 -0
- package/dist/src/electronicBill.js +61 -0
- package/dist/src/electronicBill.js.map +1 -0
- package/dist/src/helpers/comprobantes.d.ts +7 -0
- package/dist/src/helpers/comprobantes.js +92 -0
- package/dist/src/helpers/comprobantes.js.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.js +42 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/genClave/index.d.ts +9 -0
- package/dist/src/lib/genClave/index.js +119 -0
- package/dist/src/lib/genClave/index.js.map +1 -0
- package/dist/src/lib/genJSON/confirmXML.d.ts +7 -0
- package/dist/src/lib/genJSON/confirmXML.js +46 -0
- package/dist/src/lib/genJSON/confirmXML.js.map +1 -0
- package/dist/src/lib/genJSON/index.d.ts +3 -0
- package/dist/src/lib/genJSON/index.js +133 -0
- package/dist/src/lib/genJSON/index.js.map +1 -0
- package/dist/src/lib/genXML/index.d.ts +7 -0
- package/dist/src/lib/genXML/index.js +51 -0
- package/dist/src/lib/genXML/index.js.map +1 -0
- package/dist/src/lib/genXML/sigXML/genKeysAndCert.d.ts +6 -0
- package/dist/src/lib/genXML/sigXML/genKeysAndCert.js +77 -0
- package/dist/src/lib/genXML/sigXML/genKeysAndCert.js.map +1 -0
- package/dist/src/lib/genXML/sigXML/index.d.ts +1 -0
- package/dist/src/lib/genXML/sigXML/index.js +86 -0
- package/dist/src/lib/genXML/sigXML/index.js.map +1 -0
- package/dist/src/lib/genXML/xmlConfig.d.ts +55 -0
- package/dist/src/lib/genXML/xmlConfig.js +36 -0
- package/dist/src/lib/genXML/xmlConfig.js.map +1 -0
- package/dist/src/services/getToken/index.d.ts +3 -0
- package/dist/src/services/getToken/index.js +22 -0
- package/dist/src/services/getToken/index.js.map +1 -0
- package/dist/src/services/send/index.d.ts +2 -0
- package/dist/src/services/send/index.js +40 -0
- package/dist/src/services/send/index.js.map +1 -0
- package/dist/src/types/xml/notaDeCredito.d.ts +21 -0
- package/dist/src/types/xml/notaDeCredito.js +3 -0
- package/dist/src/types/xml/notaDeCredito.js.map +1 -0
- package/dist/src/types/xml/notaDeDebito.d.ts +21 -0
- package/dist/src/types/xml/notaDeDebito.js +3 -0
- package/dist/src/types/xml/notaDeDebito.js.map +1 -0
- package/examples/README.md +54 -0
- package/{test/examples → examples}/createAndSend.ts +16 -12
- package/{test/examples → examples}/createCreditNote.ts +3 -3
- package/{test/examples → examples}/createDebitNote.ts +3 -3
- package/{test/examples → examples}/genBasicXML.ts +2 -2
- package/{test/examples → examples}/getClave.ts +2 -2
- package/examples/getToken.ts +15 -0
- package/jest.config.js +20 -3
- package/package.json +15 -18
- package/src/ATV.ts +28 -0
- package/src/confirmXML.ts +4 -4
- package/src/creditNote.ts +9 -9
- package/src/data/codigoMoneda.ts +180 -0
- package/src/data/exoneracion.ts +11 -0
- package/src/data/impuestos.ts +26 -0
- package/src/data/tipoCedula.ts +8 -0
- package/src/data/unidadesMedida.ts +99 -0
- package/src/debitNote.ts +9 -9
- package/src/electronicBill.ts +17 -9
- package/src/helpers/comprobantes.ts +7 -7
- package/src/lib/genClave/index.ts +7 -7
- package/src/lib/genJSON/confirmXML.ts +2 -2
- package/src/lib/genJSON/index.ts +23 -21
- package/src/lib/genXML/index.ts +3 -9
- package/src/lib/genXML/sigXML/genKeysAndCert.ts +1 -5
- package/src/lib/genXML/sigXML/index.ts +1 -1
- package/src/lib/genXML/xmlConfig.ts +14 -1
- package/src/services/getToken/GetToken.ts +54 -0
- package/src/services/getToken/__tests__/GetToken.test.ts +82 -0
- package/src/services/getToken/index.ts +1 -1
- package/src/services/getToken/types.ts +30 -0
- package/src/services/send/index.ts +2 -2
- package/src/types/{facturaInterfaces.ts → facturaInterfaces.d.ts} +18 -1
- package/src/types/globalInterfaces.d.ts +5 -2
- package/src/types/xml/notaDeCredito.ts +1 -1
- package/src/types/xml/notaDeDebito.ts +1 -1
- package/{test/tools → tools}/strToClave.ts +1 -1
- package/tools/xsdToJsonSchema.ts +108 -0
- package/tsconfig.json +5 -2
- package/test/examples/README.md +0 -43
- package/test/examples/getToken.ts +0 -18
- /package/__tests__/{unit → tests}/getToken.test.ts +0 -0
- /package/{test/examples → examples}/confirmXML.ts +0 -0
- /package/{test/examples → examples}/consultXML.ts +0 -0
- /package/{test/tools → tools}/readXML.ts +0 -0
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
const FE_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/facturaElectronica'
|
|
2
2
|
const FE_XML_SCHEMA_XSI = 'https://www.hacienda.go.cr/ATV/ComprobanteElectronico/docs/esquemas/2016/v4.3/FacturaElectronica_V4.3.xsd'
|
|
3
|
+
|
|
4
|
+
const FEE_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/facturaElectronicaExportacion'
|
|
5
|
+
const FEE_XML_SCHEMA_XSI = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/facturaElectronicaExportacion.xsd'
|
|
6
|
+
|
|
3
7
|
const MR_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/mensajeReceptor'
|
|
8
|
+
|
|
4
9
|
const NC_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/notaCreditoElectronica'
|
|
5
10
|
const NC_XML_SCHEMA_XSI = 'https://www.hacienda.go.cr/ATV/ComprobanteElectronico/docs/esquemas/2016/v4.3/NotaCreditoElectronica_V4.3.xsd'
|
|
11
|
+
|
|
6
12
|
const ND_XML_SCHEMA_NS = 'https://cdn.comprobanteselectronicos.go.cr/xml-schemas/v4.3/notaDebitoElectronica'
|
|
7
13
|
const ND_XML_SCHEMA_XSI = 'https://www.hacienda.go.cr/ATV/ComprobanteElectronico/docs/esquemas/2016/v4.3/NotaDebitoElectronica_V4.3.xsd'
|
|
8
14
|
|
|
@@ -24,6 +30,12 @@ const FE_XML_ATTRS = { // Factura Electronica
|
|
|
24
30
|
'xsi:schemaLocation': `${FE_XML_SCHEMA_NS} ${FE_XML_SCHEMA_XSI}`
|
|
25
31
|
}
|
|
26
32
|
|
|
33
|
+
const FEE_XML_ATTRS = { // Factura Electronica Exportación
|
|
34
|
+
xmlns: FE_XML_SCHEMA_NS,
|
|
35
|
+
...COMMON_STRUCTURE,
|
|
36
|
+
'xsi:schemaLocation': `${FEE_XML_SCHEMA_NS} ${FEE_XML_SCHEMA_XSI}`
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
const NC_XML_ATTRS = { // Nota Credito Electronica
|
|
28
40
|
xmlns: NC_XML_SCHEMA_NS,
|
|
29
41
|
...COMMON_STRUCTURE,
|
|
@@ -43,7 +55,8 @@ const MR_XML_ATTRS = { // Mensaje Receptor
|
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
export const xmlExtructures = {
|
|
46
|
-
|
|
58
|
+
FacturaElectronica: FE_XML_ATTRS,
|
|
59
|
+
FacturaElectronicaExportacion: FEE_XML_ATTRS,
|
|
47
60
|
NC: NC_XML_ATTRS,
|
|
48
61
|
ND: ND_XML_ATTRS,
|
|
49
62
|
CCE: MR_XML_ATTRS,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import qs from 'querystring'
|
|
3
|
+
import { GetTokenDto, GetTokenInternalProps, GetTokenRawResponse, GetTokenResponse } from './types'
|
|
4
|
+
import { ATV } from '@src/ATV'
|
|
5
|
+
|
|
6
|
+
const MAIN_DOMAIN = 'https://idp.comprobanteselectronicos.go.cr'
|
|
7
|
+
const options: { [key: string]: GetTokenInternalProps} = {
|
|
8
|
+
prod: {
|
|
9
|
+
serviceUrl: `${MAIN_DOMAIN}/auth/realms/rut/protocol/openid-connect/token`,
|
|
10
|
+
clientId: 'api'
|
|
11
|
+
},
|
|
12
|
+
stg: {
|
|
13
|
+
serviceUrl: `${MAIN_DOMAIN}/auth/realms/rut-stag/protocol/openid-connect/token`,
|
|
14
|
+
clientId: 'api-stag'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class GetToken {
|
|
19
|
+
private readonly props: GetTokenInternalProps;
|
|
20
|
+
constructor(scope: ATV) {
|
|
21
|
+
this.props = this.initProps(scope.mode)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public async execute({ username, password }: GetTokenDto): Promise<GetTokenResponse> {
|
|
25
|
+
const fetchResponse = await axios.post<GetTokenRawResponse>(this.props.serviceUrl, qs.stringify({
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
27
|
+
client_id: this.props.clientId,
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
29
|
+
grant_type: 'password',
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/camelcase
|
|
31
|
+
client_secret: '',
|
|
32
|
+
username,
|
|
33
|
+
password
|
|
34
|
+
}), {
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
37
|
+
}
|
|
38
|
+
})
|
|
39
|
+
const data = fetchResponse.data
|
|
40
|
+
return {
|
|
41
|
+
accessToken: data.access_token,
|
|
42
|
+
expiresIn: data.expires_in,
|
|
43
|
+
refreshToken: data.refresh_token,
|
|
44
|
+
refreshExpiresIn: data.refresh_expires_in,
|
|
45
|
+
sessionState: data.session_state,
|
|
46
|
+
tokenType: data.token_type,
|
|
47
|
+
scope: data.scope
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
private initProps(mode: string): GetTokenInternalProps {
|
|
52
|
+
return options[mode] || options.prod
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/camelcase */
|
|
2
|
+
import axios from 'axios'
|
|
3
|
+
import qs from 'querystring'
|
|
4
|
+
import { GetToken } from '../GetToken'
|
|
5
|
+
import { ATV } from '@src/ATV'
|
|
6
|
+
import { GetTokenDto } from '../types'
|
|
7
|
+
|
|
8
|
+
jest.mock('@src/ATV')
|
|
9
|
+
jest.mock('axios')
|
|
10
|
+
jest.mock('querystring')
|
|
11
|
+
|
|
12
|
+
const fetchResponse = {
|
|
13
|
+
data: {
|
|
14
|
+
access_token: 'access_token',
|
|
15
|
+
expires_in: 3600,
|
|
16
|
+
refresh_token: 'refresh_token',
|
|
17
|
+
refresh_expires_in: 1209600,
|
|
18
|
+
session_state: 'session_state',
|
|
19
|
+
token_type: 'Bearer',
|
|
20
|
+
scope: 'openid'
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
describe('GetToken', () => {
|
|
24
|
+
let atv: ATV
|
|
25
|
+
let getToken: GetToken
|
|
26
|
+
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
atv = new ATV()
|
|
29
|
+
getToken = new GetToken(atv)
|
|
30
|
+
;(axios.post as jest.Mock).mockResolvedValue(fetchResponse)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
jest.resetAllMocks()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should call axios.post with correct parameters', async () => {
|
|
38
|
+
// Arrange
|
|
39
|
+
const dto: GetTokenDto = {
|
|
40
|
+
username: 'testuser',
|
|
41
|
+
password: 'testpassword'
|
|
42
|
+
}
|
|
43
|
+
const expectedUrl = 'https://idp.comprobanteselectronicos.go.cr/auth/realms/rut/protocol/openid-connect/token'
|
|
44
|
+
const expectedData = qs.stringify({
|
|
45
|
+
client_id: 'api-stag',
|
|
46
|
+
grant_type: 'password',
|
|
47
|
+
client_secret: '',
|
|
48
|
+
username: 'testuser',
|
|
49
|
+
password: 'testpassword'
|
|
50
|
+
})
|
|
51
|
+
const expectedConfig = {
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Act
|
|
58
|
+
await getToken.execute(dto)
|
|
59
|
+
|
|
60
|
+
// Assert
|
|
61
|
+
expect(axios.post).toHaveBeenCalledWith(expectedUrl, expectedData, expectedConfig)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('should return expected response', async () => {
|
|
65
|
+
// Arrange
|
|
66
|
+
const expectedResponse = {
|
|
67
|
+
accessToken: 'access_token',
|
|
68
|
+
expiresIn: 3600,
|
|
69
|
+
refreshToken: 'refresh_token',
|
|
70
|
+
refreshExpiresIn: 1209600,
|
|
71
|
+
sessionState: 'session_state',
|
|
72
|
+
tokenType: 'Bearer',
|
|
73
|
+
scope: 'openid'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Act
|
|
77
|
+
const result = await getToken.execute({ username: 'testuser', password: 'testpassword' })
|
|
78
|
+
|
|
79
|
+
// Assert
|
|
80
|
+
expect(result).toEqual(expectedResponse)
|
|
81
|
+
})
|
|
82
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
2
|
import qs from 'querystring'
|
|
3
|
-
import { postTokenOptions } from '
|
|
3
|
+
import { postTokenOptions } from '@src/services/getToken/interfaces'
|
|
4
4
|
|
|
5
5
|
const MAIN_DOMAIN = 'https://idp.comprobanteselectronicos.go.cr'
|
|
6
6
|
const RUT = (process.env.IS_STG) ? 'rut-stag' : 'rut'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type GetTokenDto = {
|
|
2
|
+
username: string;
|
|
3
|
+
password: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type GetTokenInternalProps = {
|
|
7
|
+
serviceUrl: string;
|
|
8
|
+
clientId: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type GetTokenRawResponse = {
|
|
12
|
+
access_token: string;
|
|
13
|
+
expires_in: number;
|
|
14
|
+
refresh_expires_in: number;
|
|
15
|
+
refresh_token: string;
|
|
16
|
+
token_type: string;
|
|
17
|
+
'not-before-policy': number;
|
|
18
|
+
session_state: string;
|
|
19
|
+
scope: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type GetTokenResponse = {
|
|
23
|
+
accessToken: string;
|
|
24
|
+
expiresIn: number;
|
|
25
|
+
refreshExpiresIn: number;
|
|
26
|
+
refreshToken: string;
|
|
27
|
+
tokenType: string;
|
|
28
|
+
sessionState: string;
|
|
29
|
+
scope: string;
|
|
30
|
+
}
|
|
@@ -3,8 +3,8 @@ import axios from 'axios'
|
|
|
3
3
|
const MAIN_DOMAIN = 'https://api.comprobanteselectronicos.go.cr/'
|
|
4
4
|
const RUT = (process.env.IS_STG) ? 'recepcion-sandbox' : 'recepcion'
|
|
5
5
|
const PATH = `${RUT}/v1/recepcion/`
|
|
6
|
-
|
|
7
|
-
const URL = MAIN_DOMAIN + PATH
|
|
6
|
+
const SANBOX_URL = 'https://api-sandbox.comprobanteselectronicos.go.cr/recepcion/v1/recepcion'
|
|
7
|
+
const URL = (process.env.IS_STG) ? SANBOX_URL : MAIN_DOMAIN + PATH
|
|
8
8
|
|
|
9
9
|
export function send(token: string, postOptions: any): Record<string, any> {
|
|
10
10
|
return axios({
|
|
@@ -95,6 +95,23 @@ export interface FacturaElectronica {
|
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
export interface FacturaElectronicaExportacion {
|
|
99
|
+
Clave: string;
|
|
100
|
+
CodigoActividad: string;
|
|
101
|
+
NumeroConsecutivo: string;
|
|
102
|
+
FechaEmision?: Date;
|
|
103
|
+
Emisor: Persona;
|
|
104
|
+
Receptor: Persona;
|
|
105
|
+
CondicionVenta?: string;
|
|
106
|
+
PlazoCredito?: string;
|
|
107
|
+
MedioPago?: string;
|
|
108
|
+
DetalleServicio?: DetalleServicio;
|
|
109
|
+
ResumenFactura: Resumen;
|
|
110
|
+
Otros?: {
|
|
111
|
+
OtroTexto: string;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
98
115
|
export interface FacturaElectronicaContenedor {
|
|
99
|
-
FacturaElectronica: FacturaElectronica;
|
|
116
|
+
[key: 'FacturaElectronica' | 'FacturaElectronicaExportacion']: FacturaElectronica | FacturaElectronicaExportacion;
|
|
100
117
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Persona, LineaDetalle } from '
|
|
1
|
+
import { Persona, LineaDetalle } from '@src/types/facturaInterfaces'
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface ClientPayload {
|
|
4
4
|
Emisor: Persona;
|
|
5
5
|
Receptor: Persona;
|
|
6
6
|
sucursal?: string;
|
|
@@ -11,7 +11,10 @@ export interface FrontEndRequest {
|
|
|
11
11
|
consecutivo: string;
|
|
12
12
|
situationEC: string;
|
|
13
13
|
actividad: string;
|
|
14
|
+
total?: number; // deprecated
|
|
15
|
+
impuesto?: number; // deprecated
|
|
14
16
|
LineasDetalle: Array<LineaDetalle>;
|
|
17
|
+
facturaElectronicaType?: 'FacturaElectronica' | 'FacturaElectronicaExportacion';
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export interface ClaveOpts {
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/* ======================================= */
|
|
2
|
+
/* ============== WIP ==================== */
|
|
3
|
+
/* ======================================= */
|
|
4
|
+
/* Util to import ATV xsd and get some info like enums */
|
|
5
|
+
import fs from 'fs'
|
|
6
|
+
import * as Parser from 'fast-xml-parser'
|
|
7
|
+
|
|
8
|
+
const options = {
|
|
9
|
+
ignoreAttributes: false,
|
|
10
|
+
ignoreNameSpace: true,
|
|
11
|
+
parseNodeValue: false,
|
|
12
|
+
attrNodeName: 'attributes',
|
|
13
|
+
attributeNamePrefix: ''
|
|
14
|
+
}
|
|
15
|
+
const sourceURI = process.env.XSD_SOURCE
|
|
16
|
+
const xmlString = fs.readFileSync(sourceURI, 'utf8')
|
|
17
|
+
|
|
18
|
+
const json = Parser.parse(xmlString, options)
|
|
19
|
+
const originalShema = json?.schema
|
|
20
|
+
const parentElement = originalShema?.element
|
|
21
|
+
|
|
22
|
+
const complexElements = originalShema?.complexType
|
|
23
|
+
const singleElements = originalShema?.simpleType
|
|
24
|
+
|
|
25
|
+
function processEnumerations(array: Array<any>): any {
|
|
26
|
+
return array.map((enumeration) => {
|
|
27
|
+
return enumeration?.attributes?.value
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function processLoop(array: Array<any>): any {
|
|
32
|
+
const newObj = {}
|
|
33
|
+
for (let i = 0; i < array.length; i++) {
|
|
34
|
+
const element = array[i]
|
|
35
|
+
const propKey = element?.attributes?.name
|
|
36
|
+
if (propKey) {
|
|
37
|
+
newObj[propKey] = {
|
|
38
|
+
description: element?.annotation?.documentation
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return newObj
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function processObject(object: any): any {
|
|
46
|
+
const props = processLoop(object?.complexType?.sequence?.element)
|
|
47
|
+
const newObject = {}
|
|
48
|
+
newObject[object?.attributes?.name] = {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: props
|
|
51
|
+
}
|
|
52
|
+
return newObject
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function processSimpleType(object: any): any {
|
|
56
|
+
const newObject = {}
|
|
57
|
+
const enumeration = object.restriction?.enumeration || []
|
|
58
|
+
const enumationList = processEnumerations(enumeration)
|
|
59
|
+
newObject[object?.attributes?.name] = {
|
|
60
|
+
type: object.restriction?.attributes?.base,
|
|
61
|
+
enum: enumationList,
|
|
62
|
+
pattern: object.restriction?.pattern
|
|
63
|
+
}
|
|
64
|
+
return newObject
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function processElementsFromComplexType(array: Array<any>): any {
|
|
68
|
+
const newObj = {}
|
|
69
|
+
for (let i = 0; i < array.length; i++) {
|
|
70
|
+
const element = array[i]
|
|
71
|
+
const propKey = element?.attributes?.name
|
|
72
|
+
const simpleType = element?.simpleType ? processSimpleType(element?.simpleType) : {}
|
|
73
|
+
if (propKey) {
|
|
74
|
+
newObj[propKey] = {
|
|
75
|
+
description: element?.annotation?.documentation,
|
|
76
|
+
simpleType: simpleType
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return newObj
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function processComplexType(object: any): any {
|
|
84
|
+
const elements = processElementsFromComplexType(object?.sequence?.element)
|
|
85
|
+
const newObject = {}
|
|
86
|
+
newObject[object?.attributes?.name] = {
|
|
87
|
+
elements: elements
|
|
88
|
+
}
|
|
89
|
+
return newObject
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const schema: Record<string, any> = {
|
|
93
|
+
$schema: 'https://json-schema.org/draft/2020-12/schema',
|
|
94
|
+
$id: 'https://facere.cr/schema.json',
|
|
95
|
+
title: 'undefined',
|
|
96
|
+
description: 'undefined',
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties: {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
schema.properties = processObject(parentElement)
|
|
102
|
+
schema.singleElements = singleElements.map(processSimpleType)
|
|
103
|
+
schema.complexElements = complexElements.map(processComplexType)
|
|
104
|
+
|
|
105
|
+
const data = JSON.stringify(schema, null, 2)
|
|
106
|
+
fs.writeFile('./out.json', data, (err) => {
|
|
107
|
+
if (err) throw err
|
|
108
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -4,18 +4,21 @@
|
|
|
4
4
|
"esModuleInterop": true,
|
|
5
5
|
"target": "es6",
|
|
6
6
|
"moduleResolution": "node",
|
|
7
|
+
"declaration": true,
|
|
7
8
|
"module": "commonjs",
|
|
8
9
|
"sourceMap": true,
|
|
9
10
|
"rootDir": ".",
|
|
10
11
|
"outDir": "dist",
|
|
11
12
|
"baseUrl": ".",
|
|
13
|
+
"skipLibCheck": true,
|
|
12
14
|
"lib": [
|
|
13
15
|
"esnext", "dom"
|
|
14
16
|
],
|
|
15
17
|
"paths": {
|
|
16
18
|
"@src/*": ["src/*"],
|
|
17
|
-
"@test/*": ["
|
|
19
|
+
"@test/*": ["__tests__/*"]
|
|
18
20
|
}
|
|
19
21
|
},
|
|
20
|
-
"include": ["./src/**/*", "
|
|
22
|
+
"include": ["./src/**/*", "__tests__/**/*", "__tests__/stubs", "examples"],
|
|
23
|
+
"exclude": ["node_modules/**/*"]
|
|
21
24
|
}
|
package/test/examples/README.md
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
# Ejemplos con implementaciones para pruebas
|
|
2
|
-
|
|
3
|
-
Para probar crear y enviar factura
|
|
4
|
-
```
|
|
5
|
-
ts-node -r tsconfig-paths/register test/examples/createAndSend.ts
|
|
6
|
-
--require dotenv/config test/examples/createAndSend.ts
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
Para probar genJson HeaderXML
|
|
10
|
-
```
|
|
11
|
-
ts-node -r tsconfig-paths/register test/examples/createAndSend.ts
|
|
12
|
-
--require dotenv/config test/examples/genBasicXML.ts
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Generar la clave
|
|
16
|
-
```
|
|
17
|
-
ts-node -r tsconfig-paths/register test/examples/createAndSend.ts
|
|
18
|
-
--require dotenv/config test/examples/getClave.ts
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Para crear una nota de credito
|
|
22
|
-
```
|
|
23
|
-
ts-node -r tsconfig-paths/register test/examples/createAndSend.ts
|
|
24
|
-
--require dotenv/config test/examples/createCreditNote.ts
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Testing
|
|
28
|
-
Para probar las funcionalidades se recomienda crear un .env en donde se especifiquen datos de prueba.
|
|
29
|
-
```
|
|
30
|
-
USERNAME_TEST=
|
|
31
|
-
PASSWORD_TEST=
|
|
32
|
-
IS_STG=1
|
|
33
|
-
SOURCE_P12_URI=
|
|
34
|
-
SOURCE_P12_PASSPORT=
|
|
35
|
-
SOURCE_URI_XML_OUTPUT=
|
|
36
|
-
XML_TO_CONFIRM=
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
## Tools
|
|
40
|
-
Para usar readXML establecer en .env
|
|
41
|
-
```
|
|
42
|
-
SOURCE_URI=
|
|
43
|
-
```
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import getToken from '@src/services/getToken'
|
|
2
|
-
|
|
3
|
-
const IS_STG = process.env.IS_STG
|
|
4
|
-
const USERNAME_TEST = process.env.USERNAME_TEST
|
|
5
|
-
const PASSWORD_TEST = process.env.PASSWORD_TEST
|
|
6
|
-
console.log('process.env.IS_STG', IS_STG)
|
|
7
|
-
|
|
8
|
-
getToken({
|
|
9
|
-
client_id: 'api-stag', // eslint-disable-line @typescript-eslint/camelcase
|
|
10
|
-
client_secret: '', // eslint-disable-line @typescript-eslint/camelcase
|
|
11
|
-
grant_type: 'password', // eslint-disable-line @typescript-eslint/camelcase
|
|
12
|
-
username: USERNAME_TEST,
|
|
13
|
-
password: PASSWORD_TEST
|
|
14
|
-
}).then((result) => {
|
|
15
|
-
console.log('res', result.data)
|
|
16
|
-
}).catch((e) => {
|
|
17
|
-
console.log('e', e.response.data)
|
|
18
|
-
})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|