@stackin-io/stackin-node-sdk 0.1.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/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/address.d.ts +21 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +41 -0
- package/dist/address.js.map +1 -0
- package/dist/br/index.d.ts +3 -0
- package/dist/br/index.d.ts.map +1 -0
- package/dist/br/index.js +6 -0
- package/dist/br/index.js.map +1 -0
- package/dist/br/product.d.ts +63 -0
- package/dist/br/product.d.ts.map +1 -0
- package/dist/br/product.js +147 -0
- package/dist/br/product.js.map +1 -0
- package/dist/client.d.ts +38 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +147 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +36 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fernando Celmer
|
|
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
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img src="https://raw.githubusercontent.com/stackin-io/stackin-node-sdk/master/docs/assets/stackin.png" width="120" />
|
|
4
|
+
|
|
5
|
+
**Integrate once. Issue everywhere.**
|
|
6
|
+
|
|
7
|
+
[](package.json)
|
|
8
|
+
[](https://www.npmjs.com/package/@stackin-io/stackin-node-sdk)
|
|
9
|
+
[](https://github.com/stackin-io/stackin-node-sdk)
|
|
10
|
+
|
|
11
|
+
[API Reference](https://docs.stackin.io) · [Node SDK guide](https://docs.stackin.io/blog/node-sdk)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
# stackin
|
|
18
|
+
|
|
19
|
+
Node/TypeScript SDK for fiscal document issuance — a handful of business fields, nothing about certificates, XML, XSD, signing or SOAP. The API resolves all of that from the issuer's own configuration, identified by `apiKey`.
|
|
20
|
+
|
|
21
|
+
**One class, `Invoice`** — `issue()`/`consult()`/`cancel()`, nothing else to instantiate. Each line item is a `br.Product` — `description`/`amount` are universal, everything else (`ncm`/`cfop`/`cest`/tax groups...) is Brazil-specific and only required for NFE; NFSE ignores it.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @stackin-io/stackin-node-sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
Get an `apiKey` from the [stackin dashboard](https://app.stackin.io) — select the issuing company, then Settings → API key (context `sdk`). One key per issuing company, shown once at creation. The API resolves the issuer (CNPJ, state, address, certificate, environment) entirely from it; nothing about the issuer is ever passed on a call. Defaults to `https://sdk.stackin.io`.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import {
|
|
35
|
+
Invoice,
|
|
36
|
+
DocumentType,
|
|
37
|
+
Address,
|
|
38
|
+
br,
|
|
39
|
+
} from "@stackin-io/stackin-node-sdk";
|
|
40
|
+
|
|
41
|
+
const client = new Invoice({ apiKey: "COMPANY_API_KEY" });
|
|
42
|
+
|
|
43
|
+
const invoice = await client.issue({
|
|
44
|
+
documentType: DocumentType.NFSE,
|
|
45
|
+
clientName: "John Doe",
|
|
46
|
+
taxId: "00000000000",
|
|
47
|
+
items: [new br.Product({ description: "Software development", amount: 5000.0 })],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const status = await client.consult("ACCESS_KEY...", {
|
|
51
|
+
documentType: DocumentType.NFSE,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await client.cancel("ACCESS_KEY...", {
|
|
55
|
+
documentType: DocumentType.NFSE,
|
|
56
|
+
reason: "Typo",
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// NFE requires ncm/cfop on every item, plus the buyer's full recipientAddress:
|
|
60
|
+
await client.issue({
|
|
61
|
+
documentType: DocumentType.NFE,
|
|
62
|
+
clientName: "Buyer Company Ltd",
|
|
63
|
+
taxId: "11111111111111",
|
|
64
|
+
items: [
|
|
65
|
+
new br.Product({
|
|
66
|
+
description: "Test product",
|
|
67
|
+
amount: 100.0,
|
|
68
|
+
ncm: "84713012",
|
|
69
|
+
cfop: "5102",
|
|
70
|
+
}),
|
|
71
|
+
],
|
|
72
|
+
recipientAddress: new Address({
|
|
73
|
+
street: "Avenida Atlantica",
|
|
74
|
+
number: "500",
|
|
75
|
+
neighborhood: "Copacabana",
|
|
76
|
+
city: "Rio de Janeiro",
|
|
77
|
+
state: "RJ",
|
|
78
|
+
zipCode: "22010000",
|
|
79
|
+
cityCode: "3304557",
|
|
80
|
+
}),
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`recipientAddress` is an `Address` — the buyer's address, **required for NFE** and ignored for NFSE. Every field is required, `cityCode` (the 7-digit IBGE municipality code) included: it becomes `enderDest` on the wire and the SEFAZ rejects a partial one. `state` is also what resolves `idDest` — a buyer in another state is emitted as an interstate operation automatically. A missing or incomplete address raises a `ValidationError` locally, before the request goes out.
|
|
85
|
+
|
|
86
|
+
`items` is an array of `br.Product` — `description`/`amount` apply to any document type; `ncm`/`cfop` (plus everything else on `Product`: `cest`, tax groups, presumed credits...) are Brazil-specific and required per item for NFE, ignored for NFSE (a service isn't a physical good).
|
|
87
|
+
|
|
88
|
+
## Errors
|
|
89
|
+
|
|
90
|
+
- `APIError` — the API responded with a non-2xx status (`statusCode`, `detail`) — a 401 here means `apiKey` is missing, wrong, or was rotated.
|
|
91
|
+
- `ConnectionFailedError` — the API didn't respond (network/DNS/timeout).
|
|
92
|
+
- `ValidationError` — `issue()`'s `items` is empty, missing `ncm`/`cfop` on an item for NFE, or a missing/incomplete `recipientAddress` on NFE.
|
|
93
|
+
|
|
94
|
+
Building the full fiscal document (issuer data, service code, tax groups, schema-accurate XML) is the API's job — configured once per company, not passed on every call.
|
|
95
|
+
|
|
96
|
+
## Examples
|
|
97
|
+
|
|
98
|
+
Runnable end-to-end scripts in [`examples/nfe/`](examples/nfe/) and [`examples/nfse/`](examples/nfse/) — one file per field variant, from the bare minimum to every field filled.
|
|
99
|
+
|
|
100
|
+
Commit convention lives in [`CONTRIBUTING.md`](CONTRIBUTING.md), not here.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface AddressFields {
|
|
2
|
+
street?: string;
|
|
3
|
+
number?: string;
|
|
4
|
+
neighborhood?: string;
|
|
5
|
+
city?: string;
|
|
6
|
+
state?: string;
|
|
7
|
+
zipCode?: string;
|
|
8
|
+
cityCode?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class Address {
|
|
11
|
+
street?: string;
|
|
12
|
+
number?: string;
|
|
13
|
+
neighborhood?: string;
|
|
14
|
+
city?: string;
|
|
15
|
+
state?: string;
|
|
16
|
+
zipCode?: string;
|
|
17
|
+
cityCode?: string;
|
|
18
|
+
constructor(fields?: AddressFields);
|
|
19
|
+
toJSON(): Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=address.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,OAAO;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;gBAEN,MAAM,GAAE,aAAkB;IAUtC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAWjC"}
|
package/dist/address.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Address = void 0;
|
|
4
|
+
class Address {
|
|
5
|
+
street;
|
|
6
|
+
number;
|
|
7
|
+
neighborhood;
|
|
8
|
+
city;
|
|
9
|
+
state;
|
|
10
|
+
zipCode;
|
|
11
|
+
cityCode;
|
|
12
|
+
constructor(fields = {}) {
|
|
13
|
+
this.street = fields.street;
|
|
14
|
+
this.number = fields.number;
|
|
15
|
+
this.neighborhood = fields.neighborhood;
|
|
16
|
+
this.city = fields.city;
|
|
17
|
+
this.state = fields.state;
|
|
18
|
+
this.zipCode = fields.zipCode;
|
|
19
|
+
this.cityCode = fields.cityCode;
|
|
20
|
+
}
|
|
21
|
+
toJSON() {
|
|
22
|
+
const out = {};
|
|
23
|
+
if (this.street)
|
|
24
|
+
out.street = this.street;
|
|
25
|
+
if (this.number)
|
|
26
|
+
out.number = this.number;
|
|
27
|
+
if (this.neighborhood)
|
|
28
|
+
out.neighborhood = this.neighborhood;
|
|
29
|
+
if (this.city)
|
|
30
|
+
out.city = this.city;
|
|
31
|
+
if (this.state)
|
|
32
|
+
out.state = this.state;
|
|
33
|
+
if (this.zipCode)
|
|
34
|
+
out.zip_code = this.zipCode;
|
|
35
|
+
if (this.cityCode)
|
|
36
|
+
out.city_code = this.cityCode;
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.Address = Address;
|
|
41
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":";;;AAUA,MAAa,OAAO;IAClB,MAAM,CAAU;IAChB,MAAM,CAAU;IAChB,YAAY,CAAU;IACtB,IAAI,CAAU;IACd,KAAK,CAAU;IACf,OAAO,CAAU;IACjB,QAAQ,CAAU;IAElB,YAAY,SAAwB,EAAE;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MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/br/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Product = void 0;
|
|
4
|
+
var product_1 = require("./product");
|
|
5
|
+
Object.defineProperty(exports, "Product", { enumerable: true, get: function () { return product_1.Product; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/br/index.ts"],"names":[],"mappings":";;;AAAA,qCAAoC;AAA3B,kGAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface ProductFields {
|
|
2
|
+
description: string;
|
|
3
|
+
amount: number;
|
|
4
|
+
unit?: string;
|
|
5
|
+
quantity?: number;
|
|
6
|
+
barcode?: string;
|
|
7
|
+
freight?: number;
|
|
8
|
+
insurance?: number;
|
|
9
|
+
discount?: number;
|
|
10
|
+
otherExpenses?: number;
|
|
11
|
+
usedMovableAsset?: boolean;
|
|
12
|
+
purchaseOrder?: string;
|
|
13
|
+
purchaseOrderItem?: string;
|
|
14
|
+
ncm?: string;
|
|
15
|
+
cfop?: string;
|
|
16
|
+
cest?: string;
|
|
17
|
+
nveCodes?: string[];
|
|
18
|
+
indEscala?: string;
|
|
19
|
+
manufacturerCnpj?: string;
|
|
20
|
+
taxBenefitCode?: string;
|
|
21
|
+
exTipi?: string;
|
|
22
|
+
importContentControlNumber?: string;
|
|
23
|
+
recopiNumber?: string;
|
|
24
|
+
extraGroups?: Record<string, unknown>;
|
|
25
|
+
tax?: Record<string, unknown>;
|
|
26
|
+
serviceCode?: string;
|
|
27
|
+
serviceDiscount?: number;
|
|
28
|
+
taxRetained?: boolean;
|
|
29
|
+
observations?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare class Product {
|
|
32
|
+
description: string;
|
|
33
|
+
amount: number;
|
|
34
|
+
unit: string;
|
|
35
|
+
quantity: number;
|
|
36
|
+
barcode?: string;
|
|
37
|
+
freight?: number;
|
|
38
|
+
insurance?: number;
|
|
39
|
+
discount?: number;
|
|
40
|
+
otherExpenses?: number;
|
|
41
|
+
usedMovableAsset: boolean;
|
|
42
|
+
purchaseOrder?: string;
|
|
43
|
+
purchaseOrderItem?: string;
|
|
44
|
+
ncm?: string;
|
|
45
|
+
cfop?: string;
|
|
46
|
+
cest?: string;
|
|
47
|
+
nveCodes?: string[];
|
|
48
|
+
indEscala?: string;
|
|
49
|
+
manufacturerCnpj?: string;
|
|
50
|
+
taxBenefitCode?: string;
|
|
51
|
+
exTipi?: string;
|
|
52
|
+
importContentControlNumber?: string;
|
|
53
|
+
recopiNumber?: string;
|
|
54
|
+
extraGroups?: Record<string, unknown>;
|
|
55
|
+
tax?: Record<string, unknown>;
|
|
56
|
+
serviceCode?: string;
|
|
57
|
+
serviceDiscount?: number;
|
|
58
|
+
taxRetained: boolean;
|
|
59
|
+
observations?: string;
|
|
60
|
+
constructor(fields: ProductFields);
|
|
61
|
+
toJSON(): Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=product.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.d.ts","sourceRoot":"","sources":["../../src/br/product.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gBAAg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AI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE9B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;gBAEV,MAAM,EAAE,aAAa;IAuCjC,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAkClC"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Product = void 0;
|
|
4
|
+
const BR_KEYS = [
|
|
5
|
+
"ncm",
|
|
6
|
+
"cfop",
|
|
7
|
+
"cest",
|
|
8
|
+
"nveCodes",
|
|
9
|
+
"indEscala",
|
|
10
|
+
"manufacturerCnpj",
|
|
11
|
+
"taxBenefitCode",
|
|
12
|
+
"exTipi",
|
|
13
|
+
"importContentControlNumber",
|
|
14
|
+
"recopiNumber",
|
|
15
|
+
"extraGroups",
|
|
16
|
+
"tax",
|
|
17
|
+
];
|
|
18
|
+
const CAMEL_TO_SNAKE = {
|
|
19
|
+
nveCodes: "nve_codes",
|
|
20
|
+
indEscala: "ind_escala",
|
|
21
|
+
manufacturerCnpj: "manufacturer_cnpj",
|
|
22
|
+
taxBenefitCode: "tax_benefit_code",
|
|
23
|
+
exTipi: "ex_tipi",
|
|
24
|
+
importContentControlNumber: "import_content_control_number",
|
|
25
|
+
recopiNumber: "recopi_number",
|
|
26
|
+
extraGroups: "extra_groups",
|
|
27
|
+
otherExpenses: "other_expenses",
|
|
28
|
+
usedMovableAsset: "used_movable_asset",
|
|
29
|
+
purchaseOrder: "purchase_order",
|
|
30
|
+
purchaseOrderItem: "purchase_order_item",
|
|
31
|
+
};
|
|
32
|
+
const PRODUCT_LEVEL_KEYS = [
|
|
33
|
+
"unit",
|
|
34
|
+
"quantity",
|
|
35
|
+
"barcode",
|
|
36
|
+
"freight",
|
|
37
|
+
"insurance",
|
|
38
|
+
"discount",
|
|
39
|
+
"otherExpenses",
|
|
40
|
+
"usedMovableAsset",
|
|
41
|
+
"purchaseOrder",
|
|
42
|
+
"purchaseOrderItem",
|
|
43
|
+
];
|
|
44
|
+
function snake(key) {
|
|
45
|
+
return CAMEL_TO_SNAKE[key] ?? key;
|
|
46
|
+
}
|
|
47
|
+
class Product {
|
|
48
|
+
description;
|
|
49
|
+
amount;
|
|
50
|
+
unit;
|
|
51
|
+
quantity;
|
|
52
|
+
barcode;
|
|
53
|
+
freight;
|
|
54
|
+
insurance;
|
|
55
|
+
discount;
|
|
56
|
+
otherExpenses;
|
|
57
|
+
usedMovableAsset;
|
|
58
|
+
purchaseOrder;
|
|
59
|
+
purchaseOrderItem;
|
|
60
|
+
ncm;
|
|
61
|
+
cfop;
|
|
62
|
+
cest;
|
|
63
|
+
nveCodes;
|
|
64
|
+
indEscala;
|
|
65
|
+
manufacturerCnpj;
|
|
66
|
+
taxBenefitCode;
|
|
67
|
+
exTipi;
|
|
68
|
+
importContentControlNumber;
|
|
69
|
+
recopiNumber;
|
|
70
|
+
extraGroups;
|
|
71
|
+
tax;
|
|
72
|
+
serviceCode;
|
|
73
|
+
serviceDiscount;
|
|
74
|
+
taxRetained;
|
|
75
|
+
observations;
|
|
76
|
+
constructor(fields) {
|
|
77
|
+
if (!fields.description || fields.description.length === 0) {
|
|
78
|
+
throw new Error("description must be a non-empty string");
|
|
79
|
+
}
|
|
80
|
+
if (!(fields.amount > 0)) {
|
|
81
|
+
throw new Error("amount must be greater than 0");
|
|
82
|
+
}
|
|
83
|
+
this.description = fields.description;
|
|
84
|
+
this.amount = fields.amount;
|
|
85
|
+
this.unit = fields.unit ?? "UN";
|
|
86
|
+
this.quantity = fields.quantity ?? 1.0;
|
|
87
|
+
this.barcode = fields.barcode;
|
|
88
|
+
this.freight = fields.freight;
|
|
89
|
+
this.insurance = fields.insurance;
|
|
90
|
+
this.discount = fields.discount;
|
|
91
|
+
this.otherExpenses = fields.otherExpenses;
|
|
92
|
+
this.usedMovableAsset = fields.usedMovableAsset ?? false;
|
|
93
|
+
this.purchaseOrder = fields.purchaseOrder;
|
|
94
|
+
this.purchaseOrderItem = fields.purchaseOrderItem;
|
|
95
|
+
this.ncm = fields.ncm;
|
|
96
|
+
this.cfop = fields.cfop;
|
|
97
|
+
this.cest = fields.cest;
|
|
98
|
+
this.nveCodes = fields.nveCodes;
|
|
99
|
+
this.indEscala = fields.indEscala;
|
|
100
|
+
this.manufacturerCnpj = fields.manufacturerCnpj;
|
|
101
|
+
this.taxBenefitCode = fields.taxBenefitCode;
|
|
102
|
+
this.exTipi = fields.exTipi;
|
|
103
|
+
this.importContentControlNumber = fields.importContentControlNumber;
|
|
104
|
+
this.recopiNumber = fields.recopiNumber;
|
|
105
|
+
this.extraGroups = fields.extraGroups;
|
|
106
|
+
this.tax = fields.tax;
|
|
107
|
+
this.serviceCode = fields.serviceCode;
|
|
108
|
+
this.serviceDiscount = fields.serviceDiscount;
|
|
109
|
+
this.taxRetained = fields.taxRetained ?? false;
|
|
110
|
+
this.observations = fields.observations;
|
|
111
|
+
}
|
|
112
|
+
toJSON() {
|
|
113
|
+
const product = {
|
|
114
|
+
unit: this.unit,
|
|
115
|
+
quantity: this.quantity,
|
|
116
|
+
};
|
|
117
|
+
for (const key of PRODUCT_LEVEL_KEYS) {
|
|
118
|
+
if (key === "unit" || key === "quantity")
|
|
119
|
+
continue;
|
|
120
|
+
const value = this[key];
|
|
121
|
+
if (value !== undefined && value !== null) {
|
|
122
|
+
product[snake(key)] = value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const br = {};
|
|
126
|
+
for (const key of BR_KEYS) {
|
|
127
|
+
const value = this[key];
|
|
128
|
+
if (value !== undefined && value !== null) {
|
|
129
|
+
br[snake(key)] = value;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (Object.keys(br).length > 0) {
|
|
133
|
+
product.br = br;
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
description: this.description,
|
|
137
|
+
amount: this.amount,
|
|
138
|
+
product,
|
|
139
|
+
service_code: this.serviceCode,
|
|
140
|
+
discount: this.serviceDiscount,
|
|
141
|
+
tax_retained: this.taxRetained,
|
|
142
|
+
observations: this.observations,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.Product = Product;
|
|
147
|
+
//# sourceMappingURL=product.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product.js","sourceRoot":"","sources":["../../src/br/product.ts"],"names":[],"mappings":";;;AAiCA,MAAM,OAAO,GAA+B;IAC1C,KAAK;IACL,MAAM;IACN,MAAM;IACN,UAAU;IACV,WAAW;IACX,kBAAkB;IAClB,gBAAgB;IAChB,QAAQ;IACR,4BAA4B;IAC5B,cAAc;IACd,aAAa;IACb,KAAK;CACN,CAAC;AAEF,MAAM,cAAc,GAA2B;IAC7C,QAAQ,EAAE,WAAW;IACrB,SAAS,EAAE,YAAY;IACvB,gBAAgB,EAAE,mBAAmB;IACrC,cAAc,EAAE,kBAAkB;IAClC,MAAM,EAAE,SAAS;IACjB,0BAA0B,EAAE,+BAA+B;IAC3D,YAAY,EAAE,eAAe;IAC7B,WAAW,EAAE,cAAc;IAC3B,aAAa,EAAE,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,CAAC;QAClB,CAAC;QAED,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO;YACP,YAAY,EAAE,IAAI,CAAC,WAAW;YAC9B,QAAQ,EAAE,IAAI,CAAC,eAAe;YAC9B,YAAY,EAAE,IAAI,CAAC,WAAW;YAC9B,YAAY,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC;IACJ,CAAC;CACF;AAzGD,0BAyGC"}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Address } from "./address";
|
|
2
|
+
import { Product } from "./br/product";
|
|
3
|
+
import { DocumentType, Environment } from "./types";
|
|
4
|
+
export declare const DEFAULT_BASE_URL = "https://sdk.stackin.io";
|
|
5
|
+
export interface InvoiceOptions {
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
environment?: Environment;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
fetch?: typeof fetch;
|
|
11
|
+
}
|
|
12
|
+
export interface IssueRequest {
|
|
13
|
+
documentType: DocumentType;
|
|
14
|
+
clientName: string;
|
|
15
|
+
taxId: string;
|
|
16
|
+
items: Product[];
|
|
17
|
+
recipientAddress?: Address;
|
|
18
|
+
series?: string;
|
|
19
|
+
number?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare class Invoice {
|
|
22
|
+
readonly baseUrl: string;
|
|
23
|
+
readonly apiKey?: string;
|
|
24
|
+
readonly timeoutMs: number;
|
|
25
|
+
private readonly fetchImpl;
|
|
26
|
+
constructor(options?: InvoiceOptions);
|
|
27
|
+
issue(request: IssueRequest): Promise<Record<string, unknown>>;
|
|
28
|
+
consult(accessKey: string, options: {
|
|
29
|
+
documentType: DocumentType;
|
|
30
|
+
}): Promise<Record<string, unknown>>;
|
|
31
|
+
cancel(accessKey: string, options: {
|
|
32
|
+
documentType: DocumentType;
|
|
33
|
+
reason: string;
|
|
34
|
+
}): Promise<Record<string, unknown>>;
|
|
35
|
+
private headers;
|
|
36
|
+
private request;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEpD,eAAO,MAAM,gBAAgB,2BAA2B,CAAC;AAkBzD,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AA6BD,qBAAa,OAAO;IAClB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;gBAE7B,OAAO,GAAE,cAAmB;IAUlC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAkC9D,OAAO,CACX,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;QAAE,YAAY,EAAE,YAAY,CAAA;KAAE,GACtC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAM7B,MAAM,CACV,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;QAAE,YAAY,EAAE,YAAY,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GACtD,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IASnC,OAAO,CAAC,OAAO;YAUD,OAAO;CAgDtB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Invoice = exports.DEFAULT_BASE_URL = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
exports.DEFAULT_BASE_URL = "https://sdk.stackin.io";
|
|
7
|
+
const ENVIRONMENT_URLS = {
|
|
8
|
+
[types_1.Environment.LOCAL]: "http://localhost:8000",
|
|
9
|
+
[types_1.Environment.TEST]: exports.DEFAULT_BASE_URL,
|
|
10
|
+
[types_1.Environment.PRODUCTION]: exports.DEFAULT_BASE_URL,
|
|
11
|
+
};
|
|
12
|
+
const NFE_ADDRESS_FIELDS = [
|
|
13
|
+
"street",
|
|
14
|
+
"number",
|
|
15
|
+
"neighborhood",
|
|
16
|
+
"city",
|
|
17
|
+
"state",
|
|
18
|
+
"zipCode",
|
|
19
|
+
"cityCode",
|
|
20
|
+
];
|
|
21
|
+
function resolveBaseUrl(baseUrl, environment) {
|
|
22
|
+
if (baseUrl)
|
|
23
|
+
return baseUrl;
|
|
24
|
+
const envUrl = process.env.STACKIN_BASE_URL;
|
|
25
|
+
if (envUrl)
|
|
26
|
+
return envUrl;
|
|
27
|
+
if (environment !== undefined)
|
|
28
|
+
return ENVIRONMENT_URLS[environment];
|
|
29
|
+
const envName = process.env.STACKIN_ENVIRONMENT;
|
|
30
|
+
if (envName && ENVIRONMENT_URLS[envName])
|
|
31
|
+
return ENVIRONMENT_URLS[envName];
|
|
32
|
+
return exports.DEFAULT_BASE_URL;
|
|
33
|
+
}
|
|
34
|
+
function validateNfeAddress(address) {
|
|
35
|
+
if (!address) {
|
|
36
|
+
throw new errors_1.ValidationError("recipientAddress is required for NFE");
|
|
37
|
+
}
|
|
38
|
+
const missing = NFE_ADDRESS_FIELDS.filter((field) => !address[field]);
|
|
39
|
+
if (missing.length > 0) {
|
|
40
|
+
throw new errors_1.ValidationError(`recipientAddress is missing required fields for NFE: ${missing.join(", ")}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
class Invoice {
|
|
44
|
+
baseUrl;
|
|
45
|
+
apiKey;
|
|
46
|
+
timeoutMs;
|
|
47
|
+
fetchImpl;
|
|
48
|
+
constructor(options = {}) {
|
|
49
|
+
this.baseUrl = resolveBaseUrl(options.baseUrl, options.environment).replace(/\/+$/, "");
|
|
50
|
+
this.apiKey = options.apiKey ?? process.env.STACKIN_API_KEY;
|
|
51
|
+
this.timeoutMs = options.timeoutMs ?? 30_000;
|
|
52
|
+
this.fetchImpl = options.fetch ?? fetch;
|
|
53
|
+
}
|
|
54
|
+
async issue(request) {
|
|
55
|
+
if (!request.items || request.items.length === 0) {
|
|
56
|
+
throw new errors_1.ValidationError("items can't be empty");
|
|
57
|
+
}
|
|
58
|
+
if (request.documentType === types_1.DocumentType.NFE) {
|
|
59
|
+
request.items.forEach((item, index) => {
|
|
60
|
+
if (!item.ncm) {
|
|
61
|
+
throw new errors_1.ValidationError(`items[${index}].ncm is required for NFE`);
|
|
62
|
+
}
|
|
63
|
+
if (!item.cfop) {
|
|
64
|
+
throw new errors_1.ValidationError(`items[${index}].cfop is required for NFE`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
validateNfeAddress(request.recipientAddress);
|
|
68
|
+
}
|
|
69
|
+
const payload = {
|
|
70
|
+
document_type: request.documentType,
|
|
71
|
+
client_name: request.clientName,
|
|
72
|
+
tax_id: request.taxId,
|
|
73
|
+
items: request.items.map((item) => item.toJSON()),
|
|
74
|
+
};
|
|
75
|
+
if (request.recipientAddress) {
|
|
76
|
+
payload.recipient_address = request.recipientAddress.toJSON();
|
|
77
|
+
}
|
|
78
|
+
if (request.series)
|
|
79
|
+
payload.series = request.series;
|
|
80
|
+
if (request.number)
|
|
81
|
+
payload.number = request.number;
|
|
82
|
+
return this.request("POST", "/invoices", { body: payload });
|
|
83
|
+
}
|
|
84
|
+
async consult(accessKey, options) {
|
|
85
|
+
return this.request("GET", `/invoices/${accessKey}`, {
|
|
86
|
+
query: { document_type: options.documentType },
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async cancel(accessKey, options) {
|
|
90
|
+
return this.request("POST", `/invoices/${accessKey}/cancel`, {
|
|
91
|
+
body: {
|
|
92
|
+
document_type: options.documentType,
|
|
93
|
+
reason: options.reason,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
headers() {
|
|
98
|
+
const headers = {
|
|
99
|
+
"Content-Type": "application/json",
|
|
100
|
+
};
|
|
101
|
+
if (this.apiKey) {
|
|
102
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
103
|
+
}
|
|
104
|
+
return headers;
|
|
105
|
+
}
|
|
106
|
+
async request(method, path, opts = {}) {
|
|
107
|
+
let url = `${this.baseUrl}/api/v1${path}`;
|
|
108
|
+
if (opts.query) {
|
|
109
|
+
const params = new URLSearchParams(opts.query);
|
|
110
|
+
url += `?${params.toString()}`;
|
|
111
|
+
}
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
114
|
+
let response;
|
|
115
|
+
try {
|
|
116
|
+
response = await this.fetchImpl(url, {
|
|
117
|
+
method,
|
|
118
|
+
headers: this.headers(),
|
|
119
|
+
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
120
|
+
signal: controller.signal,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
throw new errors_1.ConnectionFailedError(err instanceof Error ? err.message : String(err));
|
|
125
|
+
}
|
|
126
|
+
finally {
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
}
|
|
129
|
+
let body = {};
|
|
130
|
+
const text = await response.text();
|
|
131
|
+
if (text) {
|
|
132
|
+
try {
|
|
133
|
+
body = JSON.parse(text);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
body = {};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (!response.ok) {
|
|
140
|
+
const detail = typeof body.detail === "string" ? body.detail : text;
|
|
141
|
+
throw new errors_1.APIError(response.status, detail);
|
|
142
|
+
}
|
|
143
|
+
return body.result ?? body;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.Invoice = Invoice;
|
|
147
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAEA,qCAA4E;AAC5E,mCAAoD;AAEvC,QAAA,gBAAgB,GAAG,wBAAwB,CAAC;AAEzD,MAAM,gBAAgB,GAAgC;IACpD,CAAC,mBAAW,CAAC,KAAK,CAAC,EAAE,uBAAuB;IAC5C,CAAC,mBAAW,CAAC,IAAI,CAAC,EAAE,wBAAgB;IACpC,CAAC,mBAAW,CAAC,UAAU,CAAC,EAAE,wBAAgB;CAC3C,CAAC;AAEF,MAAM,kBAAkB,GAAyB;IAC/C,QAAQ;IACR,QAAQ;IACR,cAAc;IACd,MAAM;IACN,OAAO;IACP,SAAS;IACT,UAAU;CACX,CAAC;AAoBF,SAAS,cAAc,CACrB,OAA2B,EAC3B,WAAoC;IAEpC,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,MAAM,MAAM,GAAG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AAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;QAED,OAAQ,IAAI,CAAC,MAAkC,IAAI,IAAI,CAAC;IAC1D,CAAC;CACF;AAjID,0BAiIC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class InvoiceError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class APIError extends InvoiceError {
|
|
5
|
+
readonly statusCode: number;
|
|
6
|
+
readonly detail: string;
|
|
7
|
+
constructor(statusCode: number, detail: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class ConnectionFailedError extends InvoiceError {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class ValidationError extends InvoiceError {
|
|
13
|
+
constructor(message: string);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,QAAS,SAAQ,YAAY;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAM/C;AAED,qBAAa,qBAAsB,SAAQ,YAAY;gBACzC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,eAAgB,SAAQ,YAAY;gBACnC,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = exports.ConnectionFailedError = exports.APIError = exports.InvoiceError = void 0;
|
|
4
|
+
class InvoiceError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "InvoiceError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.InvoiceError = InvoiceError;
|
|
11
|
+
class APIError extends InvoiceError {
|
|
12
|
+
statusCode;
|
|
13
|
+
detail;
|
|
14
|
+
constructor(statusCode, detail) {
|
|
15
|
+
super(`[${statusCode}] ${detail}`);
|
|
16
|
+
this.name = "APIError";
|
|
17
|
+
this.statusCode = statusCode;
|
|
18
|
+
this.detail = detail;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.APIError = APIError;
|
|
22
|
+
class ConnectionFailedError extends InvoiceError {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = "ConnectionFailedError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.ConnectionFailedError = ConnectionFailedError;
|
|
29
|
+
class ValidationError extends InvoiceError {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = "ValidationError";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.ValidationError = ValidationError;
|
|
36
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC;AAED,MAAa,QAAS,SAAQ,YAAY;IAC/B,UAAU,CAAS;IACnB,MAAM,CAAS;IAExB,YAAY,UAAkB,EAAE,MAAc;QAC5C,KAAK,CAAC,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAVD,4BAUC;AAED,MAAa,qBAAsB,SAAQ,YAAY;IACrD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AALD,sDAKC;AAED,MAAa,eAAgB,SAAQ,YAAY;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Invoice, DEFAULT_BASE_URL } from "./client";
|
|
2
|
+
export type { InvoiceOptions, IssueRequest } from "./client";
|
|
3
|
+
export { Address } from "./address";
|
|
4
|
+
export type { AddressFields } from "./address";
|
|
5
|
+
export { DocumentType, Environment } from "./types";
|
|
6
|
+
export { InvoiceError, APIError, ConnectionFailedError, ValidationError, } from "./errors";
|
|
7
|
+
export * as br from "./br";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACrD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,qBAAqB,EACrB,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.br = exports.ValidationError = exports.ConnectionFailedError = exports.APIError = exports.InvoiceError = exports.Environment = exports.DocumentType = exports.Address = exports.DEFAULT_BASE_URL = exports.Invoice = void 0;
|
|
37
|
+
var client_1 = require("./client");
|
|
38
|
+
Object.defineProperty(exports, "Invoice", { enumerable: true, get: function () { return client_1.Invoice; } });
|
|
39
|
+
Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return client_1.DEFAULT_BASE_URL; } });
|
|
40
|
+
var address_1 = require("./address");
|
|
41
|
+
Object.defineProperty(exports, "Address", { enumerable: true, get: function () { return address_1.Address; } });
|
|
42
|
+
var types_1 = require("./types");
|
|
43
|
+
Object.defineProperty(exports, "DocumentType", { enumerable: true, get: function () { return types_1.DocumentType; } });
|
|
44
|
+
Object.defineProperty(exports, "Environment", { enumerable: true, get: function () { return types_1.Environment; } });
|
|
45
|
+
var errors_1 = require("./errors");
|
|
46
|
+
Object.defineProperty(exports, "InvoiceError", { enumerable: true, get: function () { return errors_1.InvoiceError; } });
|
|
47
|
+
Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_1.APIError; } });
|
|
48
|
+
Object.defineProperty(exports, "ConnectionFailedError", { enumerable: true, get: function () { return errors_1.ConnectionFailedError; } });
|
|
49
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
|
|
50
|
+
exports.br = __importStar(require("./br"));
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAqD;AAA5C,iGAAA,OAAO,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAElC,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,iCAAoD;AAA3C,qGAAA,YAAY,OAAA;AAAE,oGAAA,WAAW,OAAA;AAClC,mCAKkB;AAJhB,sGAAA,YAAY,OAAA;AACZ,kGAAA,QAAQ,OAAA;AACR,+GAAA,qBAAqB,OAAA;AACrB,yGAAA,eAAe,OAAA;AAEjB,2CAA2B"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,YAAY;IACtB,GAAG,QAAQ;IACX,IAAI,SAAS;CACd;AAED,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,UAAU,eAAe;CAC1B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Environment = exports.DocumentType = void 0;
|
|
4
|
+
var DocumentType;
|
|
5
|
+
(function (DocumentType) {
|
|
6
|
+
DocumentType["NFE"] = "nfe";
|
|
7
|
+
DocumentType["NFSE"] = "nfse";
|
|
8
|
+
})(DocumentType || (exports.DocumentType = DocumentType = {}));
|
|
9
|
+
var Environment;
|
|
10
|
+
(function (Environment) {
|
|
11
|
+
Environment["LOCAL"] = "local";
|
|
12
|
+
Environment["TEST"] = "test";
|
|
13
|
+
Environment["PRODUCTION"] = "production";
|
|
14
|
+
})(Environment || (exports.Environment = Environment = {}));
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,2BAAW,CAAA;IACX,6BAAa,CAAA;AACf,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAED,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,8BAAe,CAAA;IACf,4BAAa,CAAA;IACb,wCAAyB,CAAA;AAC3B,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stackin-io/stackin-node-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Node/TypeScript SDK for stackin — issue, consult and cancel Brazilian fiscal documents (NF-e, NFS-e) via a single Invoice client. No certificates, XML or SOAP.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"stackin",
|
|
7
|
+
"nfe",
|
|
8
|
+
"nf-e",
|
|
9
|
+
"nfse",
|
|
10
|
+
"nfs-e",
|
|
11
|
+
"invoice",
|
|
12
|
+
"fiscal",
|
|
13
|
+
"fatura",
|
|
14
|
+
"nota-fiscal",
|
|
15
|
+
"nota-fiscal-eletronica",
|
|
16
|
+
"sefaz",
|
|
17
|
+
"brazil",
|
|
18
|
+
"brasil",
|
|
19
|
+
"sdk",
|
|
20
|
+
"typescript",
|
|
21
|
+
"nodejs",
|
|
22
|
+
"api-client"
|
|
23
|
+
],
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "stackin-io",
|
|
26
|
+
"homepage": "https://github.com/stackin-io/stackin-node-sdk",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/stackin-io/stackin-node-sdk.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/stackin-io/stackin-node-sdk/issues"
|
|
33
|
+
},
|
|
34
|
+
"main": "dist/index.js",
|
|
35
|
+
"types": "dist/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public",
|
|
46
|
+
"registry": "https://registry.npmjs.org/"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -p .code_quality/tsconfig.json",
|
|
50
|
+
"clean": "rm -rf dist",
|
|
51
|
+
"lint": "eslint --config .code_quality/.eslintrc.json --no-eslintrc --ext .ts src tests examples",
|
|
52
|
+
"format": "prettier --config .code_quality/.prettierrc.json --check \"src/**/*.ts\" \"tests/**/*.ts\" \"examples/**/*.ts\"",
|
|
53
|
+
"format:write": "prettier --config .code_quality/.prettierrc.json --write \"src/**/*.ts\" \"tests/**/*.ts\" \"examples/**/*.ts\"",
|
|
54
|
+
"test": "vitest run"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^20.11.0",
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
59
|
+
"@typescript-eslint/parser": "^7.0.0",
|
|
60
|
+
"eslint": "^8.57.0",
|
|
61
|
+
"prettier": "^3.2.0",
|
|
62
|
+
"typescript": "^5.4.0",
|
|
63
|
+
"undici": "^6.28.1",
|
|
64
|
+
"vitest": "^1.4.0"
|
|
65
|
+
}
|
|
66
|
+
}
|