@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
package/.env.example
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
USERNAME_TEST=USER@stag.comprobanteselectronicos.go.cr
|
|
2
|
+
PASSWORD_TEST=PASSWORD_PROVIDED_BY_ATV
|
|
3
|
+
IS_STG="1"
|
|
4
|
+
SOURCE_P12_URI=$PATH/#####.p12
|
|
5
|
+
SOURCE_P12_PASSPORT=1234
|
|
6
|
+
SOURCE_URI_XML_OUTPUT=$PATH/__test__/output/output.xml
|
|
7
|
+
XML_TO_CONFIRM=$PATH/__test__/input/Comprobante_Electronico_####_####.xml
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Create a report to help us improve
|
|
4
|
+
title: ''
|
|
5
|
+
labels: ''
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Describe the bug**
|
|
11
|
+
A clear and concise description of what the bug is.
|
|
12
|
+
|
|
13
|
+
**To Reproduce**
|
|
14
|
+
Steps to reproduce the behavior:
|
|
15
|
+
1. Go to '...'
|
|
16
|
+
2. Click on '....'
|
|
17
|
+
3. Scroll down to '....'
|
|
18
|
+
4. See error
|
|
19
|
+
|
|
20
|
+
**Expected behavior**
|
|
21
|
+
A clear and concise description of what you expected to happen.
|
|
22
|
+
|
|
23
|
+
**Screenshots**
|
|
24
|
+
If applicable, add screenshots to help explain your problem.
|
|
25
|
+
|
|
26
|
+
**Desktop (please complete the following information):**
|
|
27
|
+
- OS: [e.g. iOS]
|
|
28
|
+
- Browser [e.g. chrome, safari]
|
|
29
|
+
- Version [e.g. 22]
|
|
30
|
+
|
|
31
|
+
**Smartphone (please complete the following information):**
|
|
32
|
+
- Device: [e.g. iPhone6]
|
|
33
|
+
- OS: [e.g. iOS8.1]
|
|
34
|
+
- Browser [e.g. stock browser, safari]
|
|
35
|
+
- Version [e.g. 22]
|
|
36
|
+
|
|
37
|
+
**Additional context**
|
|
38
|
+
Add any other context about the problem here.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest an idea for this project
|
|
4
|
+
title: ''
|
|
5
|
+
labels: ''
|
|
6
|
+
assignees: ''
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
12
|
+
|
|
13
|
+
**Describe the solution you'd like**
|
|
14
|
+
A clear and concise description of what you want to happen.
|
|
15
|
+
|
|
16
|
+
**Describe alternatives you've considered**
|
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
|
18
|
+
|
|
19
|
+
**Additional context**
|
|
20
|
+
Add any other context or screenshots about the feature request here.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
|
|
2
|
+
- [ ] Make sure to open an issue as a [bug/issue](https://github.com/facturacr/facturar-costa-rica-lib/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
|
|
3
|
+
- [ ] Ensure the tests and linter pass
|
|
4
|
+
- [ ] Code coverage does not decrease (if any source code was changed)
|
|
5
|
+
- [ ] Appropriate docs were updated (if necessary)
|
|
6
|
+
|
|
7
|
+
Fixes #<issue_number_goes_here> 🦕
|
package/.github/workflows/ci.yml
CHANGED
|
@@ -13,13 +13,13 @@ jobs:
|
|
|
13
13
|
uses: actions/checkout@v2
|
|
14
14
|
- name: Install modules
|
|
15
15
|
run: yarn
|
|
16
|
-
- name: Run
|
|
17
|
-
run: yarn test
|
|
16
|
+
- name: Run testing
|
|
17
|
+
run: yarn test
|
|
18
18
|
run-on-ubuntu:
|
|
19
19
|
runs-on: ubuntu-latest
|
|
20
20
|
strategy:
|
|
21
21
|
matrix:
|
|
22
|
-
node: [
|
|
22
|
+
node: [12, 14, 16, 18]
|
|
23
23
|
steps:
|
|
24
24
|
- uses: actions/checkout@v2
|
|
25
25
|
- uses: actions/setup-node@v1
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity
|
|
10
|
+
and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the
|
|
26
|
+
overall community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or
|
|
31
|
+
advances of any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email
|
|
35
|
+
address, without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official e-mail address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series
|
|
86
|
+
of actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or
|
|
93
|
+
permanent ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
|
113
|
+
the community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.0, available at
|
|
119
|
+
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
|
122
|
+
enforcement ladder](https://github.com/mozilla/diversity).
|
|
123
|
+
|
|
124
|
+
[homepage]: https://www.contributor-covenant.org
|
|
125
|
+
|
|
126
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
127
|
+
https://www.contributor-covenant.org/faq. Translations are available at
|
|
128
|
+
https://www.contributor-covenant.org/translations.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 facturacr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
> 🛑 **Librería aún no es estable.** 🛑
|
|
3
|
+
|
|
1
4
|
# Librería Javascript - API de Administración Tributaria Virtual (ATV) del Ministerio de Hacienda.
|
|
2
5
|
|
|
3
6
|
## Descripción
|
|
4
7
|
Este proyecto tiene como fin facilitar la creación de la factura electrónica de Costa Rica. El proposito es simplificar el proceso y que está librería pueda ser utilizada como ayuda en otros proyectos que requieran el acceso al sistema de hacienda. Para esto ofrece herramienta para conectarse al API del Ministerio de Hacienda de Costa Rica.
|
|
5
8
|
|
|
6
9
|
|
|
7
|
-
Buscando
|
|
10
|
+
Buscando colaboración
|
|
11
|
+
|
|
12
|
+
-------
|
|
13
|
+
|
|
14
|
+
Para probar localmente leer [enlace](/examples/README.md).
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
## Steps for generating P12 dummy key
|
|
2
|
+
|
|
3
|
+
1. Generate 2048-bit RSA private key:
|
|
4
|
+
|
|
5
|
+
``` openssl genrsa -out key.pem 2048 ```
|
|
6
|
+
|
|
7
|
+
2. Generate a Certificate Signing Request:
|
|
8
|
+
|
|
9
|
+
``` openssl req -new -sha256 -key key.pem -out csr.csr ```
|
|
10
|
+
|
|
11
|
+
3. Generate a self-signed x509 certificate suitable for use on web servers:
|
|
12
|
+
|
|
13
|
+
``` openssl req -x509 -sha256 -days 365 -key key.pem -in csr.csr -out certificate.pem ```
|
|
14
|
+
|
|
15
|
+
4. Create SSL identity file in PKCS12 using pasword 1234:
|
|
16
|
+
|
|
17
|
+
``` openssl pkcs12 -export -out client-identity.p12 -inkey key.pem -in certificate.pem ```
|
|
18
|
+
|
|
19
|
+
Source: https://stackoverflow.com/a/65709104/2272082
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Impuesto, LineaDetalle, Persona } from '
|
|
2
|
-
import {
|
|
1
|
+
import { Impuesto, LineaDetalle, Persona } from '@src/types/facturaInterfaces'
|
|
2
|
+
import { ClientPayload } from '@src/types/globalInterfaces'
|
|
3
3
|
|
|
4
4
|
const impuestoStub: Impuesto = {
|
|
5
5
|
Codigo: '01',
|
|
@@ -48,18 +48,19 @@ const receiverStub: Persona = {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const requestStub:
|
|
51
|
+
const requestStub: ClientPayload = {
|
|
52
52
|
Emisor: transmitterStub,
|
|
53
53
|
Receptor: receiverStub,
|
|
54
54
|
sucursal: '001',
|
|
55
55
|
terminal: '00001',
|
|
56
56
|
tipoDocumento: 'FE',
|
|
57
57
|
codigoPais: '506',
|
|
58
|
-
consecutivo: '
|
|
58
|
+
consecutivo: '18', // In the examples this prop needs to be changed
|
|
59
59
|
codigoSeguridad: '00000001',
|
|
60
60
|
situationEC: '1',
|
|
61
61
|
actividad: '4',
|
|
62
|
-
LineasDetalle: [lineaDetalleStub]
|
|
62
|
+
LineasDetalle: [lineaDetalleStub],
|
|
63
|
+
facturaElectronicaType: 'FacturaElectronicaExportacion'
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
export default requestStub
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const postTokenOptions = {
|
|
2
|
+
client_id: 'api-stag', // eslint-disable-line @typescript-eslint/camelcase
|
|
3
|
+
client_secret: '', // eslint-disable-line @typescript-eslint/camelcase
|
|
4
|
+
grant_type: 'password', // eslint-disable-line @typescript-eslint/camelcase
|
|
5
|
+
username: 'cpj-1-111-654321@stag.comprobanteselectronicos.go.cr',
|
|
6
|
+
password: 'Rg-OQS)]Y00987654321'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const tokenStub = {
|
|
10
|
+
access_token: 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ4WERpTElEdW1DNUlKYkViZDRFRDlrMy1NS0Z6eUh4QW4xUWZYeEtSOWt3In0.eyJqdGkiOiIwMWE1NzY0Yy1lZGExLTRlNmEtOTg4MS1kNWJiYWQ5MTE3MjQiLCJleHAiOjE2MjE4MTIzNTcsIm5iZiI6MCwiaWF0IjoxNjIxODEyMDU3LCJpc3MiOiJodHRwOi8vaWRwLmNvbXByb2JhbnRlc2VsZWN0cm9uaWNvcy5nby5jci9hdXRoL3JlYWxtcy9ydXQtc3RhZyIsImF1ZCI6ImFjY291bnQiLCJzdWIiOiJiZDAyZmFiNS1hMjMwLTRlY2YtOWI3Zi1lMjA1NGM3YjhhMGYiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJhcGktc3RhZyIsImF1dGhfdGltZSI6MCwic2Vzc2lvbl9zdGF0ZSI6IjQ3Y2UyYzBhLTU2MDAtNDA0NS1hNDllLTQ1NDQwM2VmYzg2YiIsImFjciI6IjEiLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiJdfSwicmVzb3VyY2VfYWNjZXNzIjp7ImFjY291bnQiOnsicm9sZXMiOlsibWFuYWdlLWFjY291bnQiLCJtYW5hZ2UtYWNjb3VudC1saW5rcyIsInZpZXctcHJvZmlsZSJdfX0sInNjb3BlIjoiIiwibmFtZSI6IkNJRU5DSUEgREVMIFNBQk9SIFNPQ0lFREFEIERFIFJFU1BPTlNBQklMSURBRCBMSU1JVEFEQSIsInByZWZlcnJlZF91c2VybmFtZSI6ImNwai0zLTEwMi03NTkxNTdAc3RhZy5jb21wcm9iYW50ZXNlbGVjdHJvbmljb3MuZ28uY3IiLCJnaXZlbl9uYW1lIjoiQ0lFTkNJQSBERUwgU0FCT1IgU09DSUVEQUQgREUgUkVTUE9OU0FCSUxJREFEIExJTUlUQURBIiwicG9sIjoiNWI4MGI0NDc5ZWNlMzYwMzJiMDdkMmViIiwicG9saWN5LWlkIjoiNThhNjIwMzM3NmVhZTE0MDhjZTVlN2RkIiwiZW1haWwiOiJjcGotMy0xMDItNzU5MTU3QHN0YWcuY29tcHJvYmFudGVzZWxlY3Ryb25pY29zLmdvLmNyIn0.GBhbEkVQFGKgKr28H2SaB0QHMLIXcn8jmCj-VVTvSDGKmF7CLp7Dwi94oXiW72AoZAqvNBRnRr4hDJb7s8HZedhtD965O9x_pKPVYjgc6B_xXwczNqL6o4I2o3GKZ_1dY7E9KZgUTqv-dbZ3LmKmvB5dk_icRw-Kh5tGheUaF5cSdzIYa4VHy-ZgMcacdBnvl-G9mixkYlBShMJyszIQ-k2T9z4FFvOUdNstBiehwFiCBi7CS7HP_wn1w04O2uClyq-zHk9U8Qb25YROquFtZHV9IPrgg3LMA4MuLS6OhnKRjYHbqf0j4Elh_ucNYDs7Whz5Y76Ya33d3VhooUuDKA', // eslint-disable-line @typescript-eslint/camelcase
|
|
11
|
+
expires_in: 300, // eslint-disable-line @typescript-eslint/camelcase
|
|
12
|
+
refresh_expires_in: 1200, // eslint-disable-line @typescript-eslint/camelcase
|
|
13
|
+
refresh_token: 'eyJhbGciOiJIUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJmOThjMTk2Mi02ZGJkLTRjNDAtOTM5Ni00YTVmMDdjYTYxZTQifQ.eyJqdGkiOiJiZDMyMWYyNC02MGFlLTRiMmYtYWJlZS01ZDI1NWNlMDAyMDYiLCJleHAiOjE2MjE4MTMyNTcsIm5iZiI6MCwiaWF0IjoxNjIxODEyMDU3LCJpc3MiOiJodHRwOi8vaWRwLmNvbXByb2JhbnRlc2VsZWN0cm9uaWNvcy5nby5jci9hdXRoL3JlYWxtcy9ydXQtc3RhZyIsImF1ZCI6Imh0dHA6Ly9pZHAuY29tcHJvYmFudGVzZWxlY3Ryb25pY29zLmdvLmNyL2F1dGgvcmVhbG1zL3J1dC1zdGFnIiwic3ViIjoiYmQwMmZhYjUtYTIzMC00ZWNmLTliN2YtZTIwNTRjN2I4YTBmIiwidHlwIjoiUmVmcmVzaCIsImF6cCI6ImFwaS1zdGFnIiwiYXV0aF90aW1lIjowLCJzZXNzaW9uX3N0YXRlIjoiNDdjZTJjMGEtNTYwMC00MDQ1LWE0OWUtNDU0NDAzZWZjODZiIiwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbIm9mZmxpbmVfYWNjZXNzIiwidW1hX2F1dGhvcml6YXRpb24iXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6IiJ9.aQzWy0NHyizDSZwYz14oOXrwekSPlHOrkjiRdo_BvP4', // eslint-disable-line @typescript-eslint/camelcase
|
|
14
|
+
token_type: 'bearer', // eslint-disable-line @typescript-eslint/camelcase
|
|
15
|
+
'not-before-policy': 0,
|
|
16
|
+
session_state: '47ce2c0a-5600-4045-a49e-454403efc86b', // eslint-disable-line @typescript-eslint/camelcase
|
|
17
|
+
scope: ''
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { tokenStub } from '@test/stubs/token.stub'
|
|
2
|
+
import requestStub from '@test/stubs/frontendRequest.stub'
|
|
3
|
+
import eletronicBill from '@src/electronicBill'
|
|
4
|
+
import { send } from '@src/services/send/index'
|
|
5
|
+
import fs from 'fs'
|
|
6
|
+
import path from 'path'
|
|
7
|
+
const SOURCE_P12_URI = path.join(__dirname, '../stubs/dummyKeys/client-identity.p12')
|
|
8
|
+
|
|
9
|
+
jest.mock('@src/services/send/index')
|
|
10
|
+
|
|
11
|
+
const mockedSend = send as jest.MockedFunction<typeof send>
|
|
12
|
+
const pem = fs.readFileSync(SOURCE_P12_URI, 'binary')
|
|
13
|
+
|
|
14
|
+
describe('Get Token', () => {
|
|
15
|
+
it('should return a valid token', async () => {
|
|
16
|
+
mockedSend.mockImplementation(() => {
|
|
17
|
+
return Promise.resolve('')
|
|
18
|
+
})
|
|
19
|
+
const bill = await eletronicBill(tokenStub, requestStub, {
|
|
20
|
+
buffer: pem,
|
|
21
|
+
password: '1234'
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
console.log('bill', bill)
|
|
25
|
+
|
|
26
|
+
expect(bill).toEqual('')
|
|
27
|
+
})
|
|
28
|
+
})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getClave } from '../../src/lib/genClave'
|
|
2
2
|
import fe from '../stubs/frontendRequest.stub'
|
|
3
|
-
import {
|
|
3
|
+
import { ClientPayload } from '../../src/types/globalInterfaces'
|
|
4
4
|
|
|
5
5
|
describe('GET CLAVE', () => {
|
|
6
6
|
it('should create a new key with 50 characters', () => {
|
|
7
|
-
const frontEndRequest:
|
|
7
|
+
const frontEndRequest: ClientPayload = fe
|
|
8
8
|
const result = getClave(frontEndRequest)
|
|
9
9
|
expect(result.length).toBe(50)
|
|
10
10
|
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getClave } from '../../../src/lib/genClave'
|
|
2
|
+
import fe from '../../stubs/frontendRequest.stub'
|
|
3
|
+
import { ClientPayload } from '../../../src/types/globalInterfaces'
|
|
4
|
+
|
|
5
|
+
describe('GET CLAVE', () => {
|
|
6
|
+
it('should create a new key with 50 characters', () => {
|
|
7
|
+
const frontEndRequest: ClientPayload = fe
|
|
8
|
+
const result = getClave(frontEndRequest)
|
|
9
|
+
expect(result.length).toBe(50)
|
|
10
|
+
})
|
|
11
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import { tokenStub, postTokenOptions } from '@test/stubs/token.stub'
|
|
3
|
+
import getToken from '@src/services/getToken'
|
|
4
|
+
|
|
5
|
+
jest.mock('axios')
|
|
6
|
+
const mockedAxios = axios as jest.Mocked<typeof axios>
|
|
7
|
+
|
|
8
|
+
describe('Get Token', () => {
|
|
9
|
+
it('should return a valid token', async () => {
|
|
10
|
+
mockedAxios.post.mockResolvedValue({ data: tokenStub })
|
|
11
|
+
const token = await getToken(postTokenOptions)
|
|
12
|
+
|
|
13
|
+
expect(token).toEqual({ data: tokenStub })
|
|
14
|
+
})
|
|
15
|
+
})
|