@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.
@@ -1,50 +1,50 @@
1
1
  import fs from 'fs'
2
- import { ATV } from "@src/ATV"
2
+ import { ATV } from '@src/ATV'
3
3
  import 'jest-xml-matcher'
4
- import { createDocumentInputStub } from "@test/stubs/createDocument.stub"
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
- beforeAll(() => {
11
- jest.useFakeTimers();
12
- jest.setSystemTime(new Date(2024, 3, 1, 0, 0, 0, 0));
13
- })
10
+ beforeAll(() => {
11
+ jest.useFakeTimers()
12
+ jest.setSystemTime(new Date(2024, 3, 1, 0, 0, 0, 0))
13
+ })
14
14
 
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' }
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
- 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
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
+ })
@@ -43,7 +43,7 @@ async function main(): Promise<void> {
43
43
  }
44
44
  const data = await confirmXML({
45
45
  token: token.data.access_token,
46
- consecutivo: consecutivo,
46
+ consecutivo,
47
47
  xmlStr: xml,
48
48
  tipoDocKey: 'CCE',
49
49
  pemOpt: {
@@ -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 => {
@@ -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.8-beta",
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",
@@ -13,7 +13,7 @@ type ClaveProps = {
13
13
  }
14
14
 
15
15
  export class Clave {
16
- private props: ClaveProps;
16
+ private props: ClaveProps
17
17
 
18
18
  get value(): string {
19
19
  const claveObj = genClaveObj({
@@ -27,7 +27,7 @@ type OrderLineSum = {
27
27
  }
28
28
 
29
29
  export class Document {
30
- public readonly props: InvoiceProps;
30
+ public readonly props: InvoiceProps
31
31
  constructor(props: InvoiceProps) {
32
32
  this.props = props
33
33
  }
@@ -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
@@ -8,7 +8,7 @@ type FullConsecutiveProps = {
8
8
  }
9
9
 
10
10
  export class FullConsecutive {
11
- private props: FullConsecutiveProps;
11
+ private props: FullConsecutiveProps
12
12
 
13
13
  get value(): string {
14
14
  return consecutivoStr({
@@ -20,7 +20,7 @@ type OrderLineProps = {
20
20
  }
21
21
 
22
22
  export class OrderLine {
23
- props: OrderLineProps;
23
+ props: OrderLineProps
24
24
 
25
25
  constructor(props: OrderLineProps) {
26
26
  this.props = props
@@ -25,7 +25,7 @@ export type PersonProps = {
25
25
  }
26
26
 
27
27
  export class Person {
28
- props: PersonProps;
28
+ props: PersonProps
29
29
  constructor(props: PersonProps) {
30
30
  this.props = props
31
31
  }
@@ -17,4 +17,4 @@ export type SummaryProps = {
17
17
  totalNetSale?: number; // TotalVentaNeta
18
18
  totalTaxes: number; // TotalImpuesto
19
19
  totalVoucher: number; // TotalComprobante
20
- }
20
+ }
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
@@ -34,4 +34,4 @@ export type ConfirmationMessage = {
34
34
  receiverIdentifierId: string;
35
35
  taxesTotalAmount: string;
36
36
  totalInvoiceAmount: string;
37
- }
37
+ }
@@ -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: clave,
75
+ clave,
76
76
  fullConsecutive: fullConsective,
77
- orderLines: orderLines,
77
+ orderLines,
78
78
  activityCode: document.activityCode,
79
79
  issueDate: new Date(),
80
- emitter: emitter,
81
- receiver: receiver,
80
+ emitter,
81
+ receiver,
82
82
  conditionSale: '01',
83
83
  paymentMethod: '01'
84
84
  })
@@ -1,5 +1,5 @@
1
1
  import { PersonProps } from '@src/ATV/core/Person'
2
- import { DocumentNames } from '@src/ATV/core/documentNames.types';
2
+ import { DocumentNames } from '@src/ATV/core/documentNames.types'
3
3
  import { Method } from 'axios'
4
4
 
5
5
  type PersonInput = PersonProps;
@@ -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: 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: url,
23
+ url,
24
24
  method: 'get',
25
25
  headers: {
26
26
  Authorization: 'bearer ' + token,
@@ -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: 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: elements
87
+ elements
88
88
  }
89
89
  return newObject
90
90
  }