@nfets/client 0.0.0

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/dist/index.js ADDED
@@ -0,0 +1,198 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // ../nfe/src/application/access-key/access-key-builder.ts
5
+ var AccessKeyBuilder = class {
6
+ static {
7
+ __name(this, "AccessKeyBuilder");
8
+ }
9
+ compile(payload) {
10
+ const cUF = payload.cUF.toString().padStart(2, "0");
11
+ const year = payload.year.toString().padStart(2, "0");
12
+ const month = payload.month.toString().padStart(2, "0");
13
+ const identification = (payload.identification ?? "").padStart(14, "0");
14
+ const mod = payload.mod.toString().padStart(2, "0");
15
+ const serie = payload.serie.toString().padStart(3, "0");
16
+ const nNF = payload.nNF.toString().padStart(9, "0");
17
+ const tpEmis = payload.tpEmis.toString().padStart(1, "0");
18
+ const cNF = (payload.cNF ?? this.code()).toString().padStart(8, "0");
19
+ const accessKey = `${cUF}${year}${month}${identification}${mod}${serie}${nNF}${tpEmis}${cNF}`;
20
+ return `${accessKey}${this.verifyingDigit(accessKey)}`;
21
+ }
22
+ decompile(accessKey) {
23
+ if (accessKey.length !== 44) return;
24
+ const regex = /^([0-9]{2})([0-9]{2})([0-9]{2})([A-Z0-9]{14})([0-9]{2})([0-9]{3})([0-9]{9})([0-9]{1})([0-9]{8})([0-9]{1})$/;
25
+ const matches = regex.exec(accessKey);
26
+ if (!matches) return;
27
+ const [_, cUF, year, month, identification, mod, serie, nNF, tpEmis, cNF, vd] = matches;
28
+ return {
29
+ cUF,
30
+ year,
31
+ month,
32
+ identification,
33
+ mod,
34
+ serie,
35
+ nNF,
36
+ tpEmis,
37
+ cNF,
38
+ vd
39
+ };
40
+ }
41
+ code() {
42
+ const code = Math.floor(Math.random() * 1e8).toString().padStart(8, "0");
43
+ if (this.isCodeValid(code)) return code;
44
+ return this.code();
45
+ }
46
+ isCodeValid(code) {
47
+ const invalid = [
48
+ "00000000",
49
+ "11111111",
50
+ "22222222",
51
+ "33333333",
52
+ "44444444",
53
+ "55555555",
54
+ "66666666",
55
+ "77777777",
56
+ "88888888",
57
+ "99999999",
58
+ "12345678",
59
+ "23456789",
60
+ "34567890",
61
+ "45678901",
62
+ "56789012",
63
+ "67890123",
64
+ "78901234",
65
+ "89012345",
66
+ "90123456",
67
+ "01234567"
68
+ ];
69
+ return !~invalid.indexOf(code);
70
+ }
71
+ verifyingDigit(accessKeyWithoutVerificationDigit) {
72
+ const multipliers = [
73
+ 4,
74
+ 3,
75
+ 2,
76
+ 9,
77
+ 8,
78
+ 7,
79
+ 6,
80
+ 5,
81
+ 4,
82
+ 3,
83
+ 2,
84
+ 9,
85
+ 8,
86
+ 7,
87
+ 6,
88
+ 5,
89
+ 4,
90
+ 3,
91
+ 2,
92
+ 9,
93
+ 8,
94
+ 7,
95
+ 6,
96
+ 5,
97
+ 4,
98
+ 3,
99
+ 2,
100
+ 9,
101
+ 8,
102
+ 7,
103
+ 6,
104
+ 5,
105
+ 4,
106
+ 3,
107
+ 2,
108
+ 9,
109
+ 8,
110
+ 7,
111
+ 6,
112
+ 5,
113
+ 4,
114
+ 3,
115
+ 2
116
+ ];
117
+ const baseValue = 48;
118
+ const accessKeyLengthWithoutVerificationDigit = 43;
119
+ let sum = 0;
120
+ for (let i = 0; i < accessKeyLengthWithoutVerificationDigit; i++) {
121
+ const asciiDigit = accessKeyWithoutVerificationDigit.charCodeAt(i) - baseValue;
122
+ sum += asciiDigit * multipliers[i];
123
+ }
124
+ const digit = sum % 11 < 2 ? 0 : 11 - sum % 11;
125
+ return digit;
126
+ }
127
+ };
128
+
129
+ // ../nfe/src/domain/entities/nfe/nfe.ts
130
+ var NfeCstatToProtocol = /* @__PURE__ */ (function(NfeCstatToProtocol2) {
131
+ NfeCstatToProtocol2["Autorizada"] = "100";
132
+ NfeCstatToProtocol2["AutorizadaForaDoPrazo"] = "150";
133
+ NfeCstatToProtocol2["UsoDenegado"] = "110";
134
+ NfeCstatToProtocol2["NfeDenegada"] = "205";
135
+ NfeCstatToProtocol2["DenegadaIrregularidadeEmissor"] = "301";
136
+ NfeCstatToProtocol2["DenegadaIrregularidadeDestinatario"] = "302";
137
+ NfeCstatToProtocol2["DenegadaNaoHabilitadaNaUf"] = "303";
138
+ return NfeCstatToProtocol2;
139
+ })({});
140
+
141
+ // ../core/src/domain/entities/brazil/state-code.ts
142
+ var StateCodes = {
143
+ AC: "12",
144
+ AL: "27",
145
+ AM: "13",
146
+ AP: "16",
147
+ BA: "29",
148
+ CE: "23",
149
+ DF: "53",
150
+ ES: "32",
151
+ GO: "52",
152
+ MA: "21",
153
+ MG: "31",
154
+ MS: "50",
155
+ MT: "51",
156
+ PA: "15",
157
+ PB: "25",
158
+ PE: "26",
159
+ PI: "22",
160
+ PR: "41",
161
+ RJ: "33",
162
+ RN: "24",
163
+ RO: "11",
164
+ RR: "14",
165
+ RS: "43",
166
+ SC: "42",
167
+ SE: "28",
168
+ SP: "35",
169
+ TO: "17"
170
+ };
171
+ var StateAcronyms = Object.keys(StateCodes);
172
+
173
+ // ../core/src/domain/entities/brazil/environment.ts
174
+ var Environment = {
175
+ Production: "1",
176
+ Homolog: "2"
177
+ };
178
+
179
+ // ../core/src/domain/entities/signer/algo.ts
180
+ var SignatureNamespace = "http://www.w3.org/2000/09/xmldsig#";
181
+ var CanonicalizationMethod = "http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
182
+ var SignatureMethod = /* @__PURE__ */ (function(SignatureMethod2) {
183
+ SignatureMethod2["RSA_SHA1"] = "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
184
+ SignatureMethod2["RSA_SHA256"] = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
185
+ return SignatureMethod2;
186
+ })({});
187
+ var SignatureAlgorithm = /* @__PURE__ */ (function(SignatureAlgorithm2) {
188
+ SignatureAlgorithm2["SHA1"] = "sha1";
189
+ SignatureAlgorithm2["SHA256"] = "sha256";
190
+ return SignatureAlgorithm2;
191
+ })({});
192
+ var DigestAlgorithm = /* @__PURE__ */ (function(DigestAlgorithm2) {
193
+ DigestAlgorithm2["SHA1"] = "http://www.w3.org/2000/09/xmldsig#sha1";
194
+ DigestAlgorithm2["SHA256"] = "http://www.w3.org/2001/04/xmlenc#sha256";
195
+ return DigestAlgorithm2;
196
+ })({});
197
+
198
+ export { AccessKeyBuilder, CanonicalizationMethod, DigestAlgorithm, Environment, NfeCstatToProtocol, SignatureAlgorithm, SignatureMethod, SignatureNamespace, StateAcronyms, StateCodes };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@nfets/client",
3
+ "version": "0.0.0",
4
+ "description": "Browser-safe NF-e types and helpers for client-side apps",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/nfets/nfets.git",
23
+ "directory": "packages/client"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "build": "tsup --config tsup.config.ts",
30
+ "typecheck": "tsc -p tsconfig.json --noEmit",
31
+ "test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --localstorage-file=/tmp/jest-localstorage.json\" jest --config jest.config.ts --passWithNoTests",
32
+ "test:coverage": "pnpm test --coverage"
33
+ }
34
+ }