@stackin-io/stackin-node-sdk 0.11.0 → 0.12.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/README.md +32 -1
- package/dist/br/index.d.ts +1 -1
- package/dist/br/index.d.ts.map +1 -1
- package/dist/client.d.ts +31 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +78 -67
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/reference.d.ts +81 -0
- package/dist/reference.d.ts.map +1 -0
- package/dist/reference.js +136 -0
- package/dist/reference.js.map +1 -0
- package/dist/taxpayer.d.ts +25 -0
- package/dist/taxpayer.d.ts.map +1 -0
- package/dist/taxpayer.js +36 -0
- package/dist/taxpayer.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -250,6 +250,37 @@ Realizada. Only the last one takes a reason, and it requires one — both rules
|
|
|
250
250
|
checked locally, before the request goes out, because a round trip to be told a
|
|
251
251
|
fixed rule is a round trip wasted.
|
|
252
252
|
|
|
253
|
+
## Looking up a code, or who a CNPJ belongs to
|
|
254
|
+
|
|
255
|
+
Two more clients, for the tables an issuer reads while filling a document. Neither writes anything.
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
import { FiscalReference, Taxpayer } from "@stackin-io/stackin-node-sdk";
|
|
259
|
+
|
|
260
|
+
const ref = new FiscalReference({ apiKey: "..." }); // country "BR" by default
|
|
261
|
+
|
|
262
|
+
await ref.ncm.get("84716052"); // one code
|
|
263
|
+
await ref.ncm.search({ term: "teclado", limit: 5 }); // a page of matches
|
|
264
|
+
await ref.cfop.get("5102");
|
|
265
|
+
await ref.kinds(); // what this country has
|
|
266
|
+
await ref.kind("ibs_cbs_class").get("000001"); // any kind, named or not
|
|
267
|
+
await ref.search({ term: "teclado" }); // every kind at once
|
|
268
|
+
|
|
269
|
+
await new Taxpayer({ apiKey: "..." }).get("00000000000191");
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
`cfop`, `ncm`, `cest`, `cst`, `csosn`, `issService`, `icmsFuel` and `ibsCbsClass` have accessors. **`kind(name)` reaches anything else**, including a classification published after this release — ask `kinds()` rather than trusting this list.
|
|
273
|
+
|
|
274
|
+
`metadata` comes back as the API sends it and differs per kind: `utrib` on an NCM, `ncm_code` on a CEST, `tax_type` on a CST, `null` on an ISS service.
|
|
275
|
+
|
|
276
|
+
Three things worth knowing before you loop:
|
|
277
|
+
|
|
278
|
+
- **These share the invoice read allowance** — 600 calls a minute per key, the same bucket `consult()`, `history()`, `received()` and `pdf()` draw from. One `search()` page beats N `get()` calls.
|
|
279
|
+
- **Ordering is fixed** (kind, then code, ascending). Unlike `history()`, `SearchQuery` has no `sortBy`/`orderBy`.
|
|
280
|
+
- **A 404 from `Taxpayer` does not mean the company does not exist.** That registry reloads monthly, so a recently registered CNPJ is simply not in it yet. Do not build a validation rule on it.
|
|
281
|
+
|
|
282
|
+
`Taxpayer` has one method and keeps one: the registry holds the names and addresses of real people, so there is no search over it, by design.
|
|
283
|
+
|
|
253
284
|
## Errors
|
|
254
285
|
|
|
255
286
|
- `APIError` — the API responded with a non-2xx status (`statusCode`, `detail`) — a 401 here means `apiKey` is missing, wrong, or was rotated.
|
|
@@ -260,6 +291,6 @@ Building the full fiscal document (issuer data, service code, tax groups, schema
|
|
|
260
291
|
|
|
261
292
|
## Examples
|
|
262
293
|
|
|
263
|
-
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. `examples/consult_invoice.ts`, `examples/cancel_invoice.ts`, and `examples/reissue_invoice.ts` cover the operations that act on an already-issued document.
|
|
294
|
+
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. `examples/consult_invoice.ts`, `examples/cancel_invoice.ts`, and `examples/reissue_invoice.ts` cover the operations that act on an already-issued document. `examples/lookup_fiscal_reference.ts` and `examples/lookup_taxpayer.ts` cover the two read-only clients.
|
|
264
295
|
|
|
265
296
|
Commit convention lives in [`CONTRIBUTING.md`](CONTRIBUTING.md), not here.
|
package/dist/br/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Product } from "./product";
|
|
2
|
-
export type { IbsCbsFields,
|
|
2
|
+
export type { IbsCbsFields, PresumedCredit, ProductFields } from "./product";
|
|
3
3
|
export { Tax, cofinsAliq, cofinsNt, cofinsOutr, cofinsQtde, cofinsSt, icms00, icms02, icms10, icms15, icms20, icms30, icms40, icms51, icms53, icms60, icms61, icms70, icms90, icmsPart, icmsSn101, icmsSn102, icmsSn201, icmsSn202, icmsSn500, icmsSn900, icmsSt, icmsUfDest, ipi, ipiNt, ipiTrib, pisAliq, pisNt, pisOutr, pisQtde, pisSt, } from "./tax";
|
|
4
4
|
export type { CofinsAliqFields, CofinsNtFields, CofinsOutrFields, CofinsQtdeFields, CofinsStFields, Icms00Fields, Icms02Fields, Icms10Fields, Icms15Fields, Icms20Fields, Icms30Fields, Icms40Fields, Icms51Fields, Icms53Fields, Icms60Fields, Icms61Fields, Icms70Fields, Icms90Fields, IcmsPartFields, IcmsSn101Fields, IcmsSn102Fields, IcmsSn201Fields, IcmsSn202Fields, IcmsSn500Fields, IcmsSn900Fields, IcmsStFields, IcmsUfDestFields, IpiFields, IpiNtFields, IpiTribFields, PisAliqFields, PisNtFields, PisOutrFields, PisQtdeFields, PisStFields, TaxFields, TaxGroup, } from "./tax";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/br/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/br/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/br/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC7E,OAAO,EACL,GAAG,EACH,UAAU,EACV,QAAQ,EACR,UAAU,EACV,UAAU,EACV,QAAQ,EACR,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,MAAM,EACN,UAAU,EACV,GAAG,EACH,KAAK,EACL,OAAO,EACP,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,KAAK,GACN,MAAM,OAAO,CAAC;AACf,YAAY,EACV,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,aAAa,EACb,aAAa,EACb,WAAW,EACX,aAAa,EACb,aAAa,EACb,WAAW,EACX,SAAS,EACT,QAAQ,GACT,MAAM,OAAO,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -2,13 +2,20 @@ import { Address } from "./address";
|
|
|
2
2
|
import { Product } from "./br/product";
|
|
3
3
|
import { DocumentType, Environment, Manifestation } from "./types";
|
|
4
4
|
export declare const DEFAULT_BASE_URL = "https://sdk.stackin.io";
|
|
5
|
-
export interface
|
|
5
|
+
export interface ClientOptions {
|
|
6
6
|
apiKey?: string;
|
|
7
7
|
baseUrl?: string;
|
|
8
8
|
environment?: Environment;
|
|
9
9
|
timeoutMs?: number;
|
|
10
10
|
fetch?: typeof fetch;
|
|
11
|
+
/**
|
|
12
|
+
* ISO 3166-1 alpha-2 code FiscalReference and Taxpayer look codes up
|
|
13
|
+
* under. Defaults to BR. Invoice ignores it: a fiscal document
|
|
14
|
+
* carries its issuer's country already.
|
|
15
|
+
*/
|
|
16
|
+
country?: string;
|
|
11
17
|
}
|
|
18
|
+
export type InvoiceOptions = ClientOptions;
|
|
12
19
|
export interface IssueRequest {
|
|
13
20
|
documentType: DocumentType;
|
|
14
21
|
clientName: string;
|
|
@@ -25,12 +32,32 @@ export interface IssueRequest {
|
|
|
25
32
|
*/
|
|
26
33
|
idempotencyKey?: string;
|
|
27
34
|
}
|
|
28
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Where an api key becomes an HTTP call, for every entry point.
|
|
37
|
+
*
|
|
38
|
+
* Not re-exported from the package index: a caller instantiates
|
|
39
|
+
* Invoice, FiscalReference or Taxpayer, never this.
|
|
40
|
+
*/
|
|
41
|
+
export declare class Client {
|
|
29
42
|
readonly baseUrl: string;
|
|
30
43
|
readonly apiKey?: string;
|
|
31
44
|
readonly timeoutMs: number;
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
readonly country: string;
|
|
46
|
+
protected readonly fetchImpl: typeof fetch;
|
|
47
|
+
constructor(options?: ClientOptions);
|
|
48
|
+
protected headers(idempotencyKey?: string): Record<string, string>;
|
|
49
|
+
protected request(method: string, path: string, opts?: {
|
|
50
|
+
body?: unknown;
|
|
51
|
+
query?: Record<string, string>;
|
|
52
|
+
idempotencyKey?: string;
|
|
53
|
+
}): Promise<Record<string, unknown>>;
|
|
54
|
+
protected send(method: string, path: string, opts?: {
|
|
55
|
+
body?: unknown;
|
|
56
|
+
query?: Record<string, string>;
|
|
57
|
+
idempotencyKey?: string;
|
|
58
|
+
}): Promise<Response>;
|
|
59
|
+
}
|
|
60
|
+
export declare class Invoice extends Client {
|
|
34
61
|
issue(request: IssueRequest): Promise<Record<string, unknown>>;
|
|
35
62
|
consult(accessKey: string, options: {
|
|
36
63
|
documentType: DocumentType;
|
|
@@ -63,7 +90,6 @@ export declare class Invoice {
|
|
|
63
90
|
reissue(invoiceId: string, options?: {
|
|
64
91
|
idempotencyKey?: string;
|
|
65
92
|
}): Promise<Record<string, unknown>>;
|
|
66
|
-
private headers;
|
|
67
93
|
/**
|
|
68
94
|
* Documents other companies issued against this one.
|
|
69
95
|
*
|
|
@@ -112,7 +138,6 @@ export declare class Invoice {
|
|
|
112
138
|
pdf(accessKey: string, options: {
|
|
113
139
|
documentType: DocumentType;
|
|
114
140
|
}): Promise<Uint8Array>;
|
|
115
|
-
private request;
|
|
116
141
|
/**
|
|
117
142
|
* Every attempt made for one invoice, with what the authorizer answered.
|
|
118
143
|
*
|
|
@@ -121,6 +146,5 @@ export declare class Invoice {
|
|
|
121
146
|
* has no access key to look it up by.
|
|
122
147
|
*/
|
|
123
148
|
submissions(invoiceId: string): Promise<Array<Record<string, unknown>>>;
|
|
124
|
-
private send;
|
|
125
149
|
}
|
|
126
150
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +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;AAOvC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEnE,eAAO,MAAM,gBAAgB,2BAA2B,CAAC;AAkBzD,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sour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E,YAAY,EAAE,YAAY,CAAA;KAAE,GACtC,OAAO,CAAC,UAAU,CAAC;IAOtB;;;;;;OAMG;IACG,WAAW,CACf,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAgB3C"}
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Invoice = exports.DEFAULT_BASE_URL = void 0;
|
|
3
|
+
exports.Invoice = exports.Client = exports.DEFAULT_BASE_URL = void 0;
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
5
|
const types_1 = require("./types");
|
|
6
6
|
exports.DEFAULT_BASE_URL = "https://sdk.stackin.io";
|
|
@@ -40,17 +40,93 @@ function validateNfeAddress(address) {
|
|
|
40
40
|
throw new errors_1.ValidationError(`recipientAddress is missing required fields for NFE: ${missing.join(", ")}`);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Where an api key becomes an HTTP call, for every entry point.
|
|
45
|
+
*
|
|
46
|
+
* Not re-exported from the package index: a caller instantiates
|
|
47
|
+
* Invoice, FiscalReference or Taxpayer, never this.
|
|
48
|
+
*/
|
|
49
|
+
class Client {
|
|
44
50
|
baseUrl;
|
|
45
51
|
apiKey;
|
|
46
52
|
timeoutMs;
|
|
53
|
+
country;
|
|
47
54
|
fetchImpl;
|
|
48
55
|
constructor(options = {}) {
|
|
49
56
|
this.baseUrl = resolveBaseUrl(options.baseUrl, options.environment).replace(/\/+$/, "");
|
|
50
57
|
this.apiKey = options.apiKey ?? process.env.STACKIN_API_KEY;
|
|
51
58
|
this.timeoutMs = options.timeoutMs ?? 30_000;
|
|
59
|
+
this.country = options.country ?? "BR";
|
|
52
60
|
this.fetchImpl = options.fetch ?? fetch;
|
|
53
61
|
}
|
|
62
|
+
headers(idempotencyKey) {
|
|
63
|
+
const headers = {
|
|
64
|
+
"Content-Type": "application/json",
|
|
65
|
+
};
|
|
66
|
+
if (this.apiKey) {
|
|
67
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
68
|
+
}
|
|
69
|
+
if (idempotencyKey) {
|
|
70
|
+
headers["Idempotency-Key"] = idempotencyKey;
|
|
71
|
+
}
|
|
72
|
+
return headers;
|
|
73
|
+
}
|
|
74
|
+
async request(method, path, opts = {}) {
|
|
75
|
+
const response = await this.send(method, path, opts);
|
|
76
|
+
let body = {};
|
|
77
|
+
const text = await response.text();
|
|
78
|
+
if (text) {
|
|
79
|
+
try {
|
|
80
|
+
body = JSON.parse(text);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
body = {};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return body.result ?? body;
|
|
87
|
+
}
|
|
88
|
+
async send(method, path, opts = {}) {
|
|
89
|
+
let url = `${this.baseUrl}/api/v1${path}`;
|
|
90
|
+
if (opts.query) {
|
|
91
|
+
const params = new URLSearchParams(opts.query);
|
|
92
|
+
url += `?${params.toString()}`;
|
|
93
|
+
}
|
|
94
|
+
const controller = new AbortController();
|
|
95
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
96
|
+
let response;
|
|
97
|
+
try {
|
|
98
|
+
response = await this.fetchImpl(url, {
|
|
99
|
+
method,
|
|
100
|
+
headers: this.headers(opts.idempotencyKey),
|
|
101
|
+
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
102
|
+
signal: controller.signal,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
throw new errors_1.ConnectionFailedError(err instanceof Error ? err.message : String(err));
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
}
|
|
111
|
+
if (!response.ok) {
|
|
112
|
+
const text = await response.text();
|
|
113
|
+
let body = {};
|
|
114
|
+
if (text) {
|
|
115
|
+
try {
|
|
116
|
+
body = JSON.parse(text);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
body = {};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const detail = typeof body.detail === "string" ? body.detail : text;
|
|
123
|
+
throw new errors_1.APIError(response.status, detail);
|
|
124
|
+
}
|
|
125
|
+
return response;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.Client = Client;
|
|
129
|
+
class Invoice extends Client {
|
|
54
130
|
async issue(request) {
|
|
55
131
|
if (!request.items || request.items.length === 0) {
|
|
56
132
|
throw new errors_1.ValidationError("items can't be empty");
|
|
@@ -142,18 +218,6 @@ class Invoice {
|
|
|
142
218
|
idempotencyKey: options.idempotencyKey,
|
|
143
219
|
});
|
|
144
220
|
}
|
|
145
|
-
headers(idempotencyKey) {
|
|
146
|
-
const headers = {
|
|
147
|
-
"Content-Type": "application/json",
|
|
148
|
-
};
|
|
149
|
-
if (this.apiKey) {
|
|
150
|
-
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
151
|
-
}
|
|
152
|
-
if (idempotencyKey) {
|
|
153
|
-
headers["Idempotency-Key"] = idempotencyKey;
|
|
154
|
-
}
|
|
155
|
-
return headers;
|
|
156
|
-
}
|
|
157
221
|
/**
|
|
158
222
|
* Documents other companies issued against this one.
|
|
159
223
|
*
|
|
@@ -228,20 +292,6 @@ class Invoice {
|
|
|
228
292
|
});
|
|
229
293
|
return new Uint8Array(await response.arrayBuffer());
|
|
230
294
|
}
|
|
231
|
-
async request(method, path, opts = {}) {
|
|
232
|
-
const response = await this.send(method, path, opts);
|
|
233
|
-
let body = {};
|
|
234
|
-
const text = await response.text();
|
|
235
|
-
if (text) {
|
|
236
|
-
try {
|
|
237
|
-
body = JSON.parse(text);
|
|
238
|
-
}
|
|
239
|
-
catch {
|
|
240
|
-
body = {};
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return body.result ?? body;
|
|
244
|
-
}
|
|
245
295
|
/**
|
|
246
296
|
* Every attempt made for one invoice, with what the authorizer answered.
|
|
247
297
|
*
|
|
@@ -260,45 +310,6 @@ class Invoice {
|
|
|
260
310
|
}
|
|
261
311
|
return body;
|
|
262
312
|
}
|
|
263
|
-
async send(method, path, opts = {}) {
|
|
264
|
-
let url = `${this.baseUrl}/api/v1${path}`;
|
|
265
|
-
if (opts.query) {
|
|
266
|
-
const params = new URLSearchParams(opts.query);
|
|
267
|
-
url += `?${params.toString()}`;
|
|
268
|
-
}
|
|
269
|
-
const controller = new AbortController();
|
|
270
|
-
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
271
|
-
let response;
|
|
272
|
-
try {
|
|
273
|
-
response = await this.fetchImpl(url, {
|
|
274
|
-
method,
|
|
275
|
-
headers: this.headers(opts.idempotencyKey),
|
|
276
|
-
body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,
|
|
277
|
-
signal: controller.signal,
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
catch (err) {
|
|
281
|
-
throw new errors_1.ConnectionFailedError(err instanceof Error ? err.message : String(err));
|
|
282
|
-
}
|
|
283
|
-
finally {
|
|
284
|
-
clearTimeout(timer);
|
|
285
|
-
}
|
|
286
|
-
if (!response.ok) {
|
|
287
|
-
const text = await response.text();
|
|
288
|
-
let body = {};
|
|
289
|
-
if (text) {
|
|
290
|
-
try {
|
|
291
|
-
body = JSON.parse(text);
|
|
292
|
-
}
|
|
293
|
-
catch {
|
|
294
|
-
body = {};
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
const detail = typeof body.detail === "string" ? body.detail : text;
|
|
298
|
-
throw new errors_1.APIError(response.status, detail);
|
|
299
|
-
}
|
|
300
|
-
return response;
|
|
301
|
-
}
|
|
302
313
|
}
|
|
303
314
|
exports.Invoice = Invoice;
|
|
304
315
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAEA,qCAKkB;AAClB,mCAAmE;AAEtD,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;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAEA,qCAKkB;AAClB,mCAAmE;AAEtD,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;AAoCF,SAAS,cAAc,CACrB,OAA2B,EAC3B,WAAoC;IAEpC,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAC5C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,mBAA8C,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ptions, IssueRequest } from "./client";
|
|
2
|
+
export type { ClientOptions, InvoiceOptions, IssueRequest } from "./client";
|
|
3
|
+
export { FiscalReference, Kind, KINDS } from "./reference";
|
|
4
|
+
export type { SearchQuery } from "./reference";
|
|
5
|
+
export { Taxpayer } from "./taxpayer";
|
|
3
6
|
export { Address } from "./address";
|
|
4
7
|
export type { AddressFields } from "./address";
|
|
5
8
|
export { DocumentType, Environment, Manifestation } from "./types";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,qBAAqB,EACrB,eAAe,GAChB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,MAAM,MAAM,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -33,10 +33,16 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.br = exports.ValidationError = exports.ConnectionFailedError = exports.APIError = exports.InvoiceError = exports.Manifestation = exports.Environment = exports.DocumentType = exports.Address = exports.DEFAULT_BASE_URL = exports.Invoice = void 0;
|
|
36
|
+
exports.br = exports.ValidationError = exports.ConnectionFailedError = exports.APIError = exports.InvoiceError = exports.Manifestation = exports.Environment = exports.DocumentType = exports.Address = exports.Taxpayer = exports.KINDS = exports.Kind = exports.FiscalReference = exports.DEFAULT_BASE_URL = exports.Invoice = void 0;
|
|
37
37
|
var client_1 = require("./client");
|
|
38
38
|
Object.defineProperty(exports, "Invoice", { enumerable: true, get: function () { return client_1.Invoice; } });
|
|
39
39
|
Object.defineProperty(exports, "DEFAULT_BASE_URL", { enumerable: true, get: function () { return client_1.DEFAULT_BASE_URL; } });
|
|
40
|
+
var reference_1 = require("./reference");
|
|
41
|
+
Object.defineProperty(exports, "FiscalReference", { enumerable: true, get: function () { return reference_1.FiscalReference; } });
|
|
42
|
+
Object.defineProperty(exports, "Kind", { enumerable: true, get: function () { return reference_1.Kind; } });
|
|
43
|
+
Object.defineProperty(exports, "KINDS", { enumerable: true, get: function () { return reference_1.KINDS; } });
|
|
44
|
+
var taxpayer_1 = require("./taxpayer");
|
|
45
|
+
Object.defineProperty(exports, "Taxpayer", { enumerable: true, get: function () { return taxpayer_1.Taxpayer; } });
|
|
40
46
|
var address_1 = require("./address");
|
|
41
47
|
Object.defineProperty(exports, "Address", { enumerable: true, get: function () { return address_1.Address; } });
|
|
42
48
|
var types_1 = require("./types");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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,iCAAmE;AAA1D,qGAAA,YAAY,OAAA;AAAE,oGAAA,WAAW,OAAA;AAAE,sGAAA,aAAa,OAAA;AACjD,mCAKkB;AAJhB,sGAAA,YAAY,OAAA;AACZ,kGAAA,QAAQ,OAAA;AACR,+GAAA,qBAAqB,OAAA;AACrB,yGAAA,eAAe,OAAA;AAEjB,2CAA2B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAqD;AAA5C,iGAAA,OAAO,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAElC,yCAA2D;AAAlD,4GAAA,eAAe,OAAA;AAAE,iGAAA,IAAI,OAAA;AAAE,kGAAA,KAAK,OAAA;AAErC,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA;AACjB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAEhB,iCAAmE;AAA1D,qGAAA,YAAY,OAAA;AAAE,oGAAA,WAAW,OAAA;AAAE,sGAAA,aAAa,OAAA;AACjD,mCAKkB;AAJhB,sGAAA,YAAY,OAAA;AACZ,kGAAA,QAAQ,OAAA;AACR,+GAAA,qBAAqB,OAAA;AACrB,yGAAA,eAAe,OAAA;AAEjB,2CAA2B"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Client, ClientOptions } from "./client";
|
|
2
|
+
/**
|
|
3
|
+
* One path segment, escaped, refusing the ones that would leave it.
|
|
4
|
+
*
|
|
5
|
+
* encodeURIComponent leaves "." alone — RFC 3986 calls it unreserved —
|
|
6
|
+
* so the dot segments have to be refused rather than escaped, or the
|
|
7
|
+
* HTTP client collapses ".." into a different endpoint.
|
|
8
|
+
*/
|
|
9
|
+
export declare function segment(value: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* The classifications with a named accessor on FiscalReference.
|
|
12
|
+
*
|
|
13
|
+
* Not the whole truth and not meant to be: ask kinds() for what the API
|
|
14
|
+
* actually has, because a classification published after this release
|
|
15
|
+
* is reachable through kind() with no release at all.
|
|
16
|
+
*/
|
|
17
|
+
export declare const KINDS: readonly ["cfop", "ncm", "cest", "cst", "csosn", "iss_service", "icms_fuel", "ibs_cbs_class"];
|
|
18
|
+
/**
|
|
19
|
+
* Narrows a classification listing.
|
|
20
|
+
*
|
|
21
|
+
* There is no sortBy or orderBy: the route accepts both and discards
|
|
22
|
+
* them, so rows always come back ordered by kind then code. history()
|
|
23
|
+
* on Invoice does honour them, which is why the difference is spelled
|
|
24
|
+
* out here rather than left to be discovered.
|
|
25
|
+
*/
|
|
26
|
+
export interface SearchQuery {
|
|
27
|
+
term?: string;
|
|
28
|
+
country?: string;
|
|
29
|
+
limit?: number;
|
|
30
|
+
offset?: number;
|
|
31
|
+
}
|
|
32
|
+
type Call = (path: string, query: Record<string, string>) => Promise<Record<string, unknown>>;
|
|
33
|
+
/** One classification, bound to a country. */
|
|
34
|
+
export declare class Kind {
|
|
35
|
+
private readonly call;
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly country: string;
|
|
38
|
+
constructor(call: Call, name: string, country: string);
|
|
39
|
+
/**
|
|
40
|
+
* One code. A code that does not exist is a 404, which arrives as an
|
|
41
|
+
* APIError — there is no separate not-found type.
|
|
42
|
+
*/
|
|
43
|
+
get(code: string, country?: string): Promise<Record<string, unknown>>;
|
|
44
|
+
/**
|
|
45
|
+
* A page of this classification, filtered by the query's term when it
|
|
46
|
+
* has one. An empty term is no term: the route rejects search="" with
|
|
47
|
+
* a 422, and sending it would invent a failure the caller cannot read.
|
|
48
|
+
*/
|
|
49
|
+
search(query?: SearchQuery): Promise<Record<string, unknown>>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reads the published classification tables. Nothing here is the
|
|
53
|
+
* company's own data and nothing here is writable.
|
|
54
|
+
*/
|
|
55
|
+
export declare class FiscalReference extends Client {
|
|
56
|
+
readonly cfop: Kind;
|
|
57
|
+
readonly ncm: Kind;
|
|
58
|
+
readonly cest: Kind;
|
|
59
|
+
readonly cst: Kind;
|
|
60
|
+
readonly csosn: Kind;
|
|
61
|
+
readonly issService: Kind;
|
|
62
|
+
readonly icmsFuel: Kind;
|
|
63
|
+
readonly ibsCbsClass: Kind;
|
|
64
|
+
constructor(options?: ClientOptions);
|
|
65
|
+
/**
|
|
66
|
+
* Which classifications this country has rows for. The only honest
|
|
67
|
+
* answer to "what else is there" — a hard-coded list goes stale the
|
|
68
|
+
* next time the ETL grows one.
|
|
69
|
+
*/
|
|
70
|
+
kinds(country?: string): Promise<string[]>;
|
|
71
|
+
/** Any classification by name, including one with no accessor. */
|
|
72
|
+
kind(name: string, country?: string): Kind;
|
|
73
|
+
/**
|
|
74
|
+
* Every classification at once, which no accessor can express. The
|
|
75
|
+
* most expensive call the endpoint accepts: the whole country's
|
|
76
|
+
* tables, not one of them.
|
|
77
|
+
*/
|
|
78
|
+
search(query?: SearchQuery): Promise<Record<string, unknown>>;
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=reference.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../src/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGjD;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK7C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,+FASR,CAAC;AAEX;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAA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AAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ1C;;;;OAIG;IACG,MAAM,CAAC,KAAK,GAAE,WAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAKxE"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FiscalReference = exports.Kind = exports.KINDS = void 0;
|
|
4
|
+
exports.segment = segment;
|
|
5
|
+
const client_1 = require("./client");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
|
+
/**
|
|
8
|
+
* One path segment, escaped, refusing the ones that would leave it.
|
|
9
|
+
*
|
|
10
|
+
* encodeURIComponent leaves "." alone — RFC 3986 calls it unreserved —
|
|
11
|
+
* so the dot segments have to be refused rather than escaped, or the
|
|
12
|
+
* HTTP client collapses ".." into a different endpoint.
|
|
13
|
+
*/
|
|
14
|
+
function segment(value) {
|
|
15
|
+
if (value === "" || value === "." || value === "..") {
|
|
16
|
+
throw new errors_1.ValidationError(`"${value}" is not a usable path segment`);
|
|
17
|
+
}
|
|
18
|
+
return encodeURIComponent(value);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The classifications with a named accessor on FiscalReference.
|
|
22
|
+
*
|
|
23
|
+
* Not the whole truth and not meant to be: ask kinds() for what the API
|
|
24
|
+
* actually has, because a classification published after this release
|
|
25
|
+
* is reachable through kind() with no release at all.
|
|
26
|
+
*/
|
|
27
|
+
exports.KINDS = [
|
|
28
|
+
"cfop",
|
|
29
|
+
"ncm",
|
|
30
|
+
"cest",
|
|
31
|
+
"cst",
|
|
32
|
+
"csosn",
|
|
33
|
+
"iss_service",
|
|
34
|
+
"icms_fuel",
|
|
35
|
+
"ibs_cbs_class",
|
|
36
|
+
];
|
|
37
|
+
function searchParams(kind, fallback, query) {
|
|
38
|
+
const params = {
|
|
39
|
+
country: query.country ?? fallback,
|
|
40
|
+
};
|
|
41
|
+
if (kind)
|
|
42
|
+
params.kind = kind;
|
|
43
|
+
if (query.term)
|
|
44
|
+
params.search = query.term;
|
|
45
|
+
if (query.limit !== undefined)
|
|
46
|
+
params.limit = String(query.limit);
|
|
47
|
+
if (query.offset !== undefined)
|
|
48
|
+
params.offset = String(query.offset);
|
|
49
|
+
return params;
|
|
50
|
+
}
|
|
51
|
+
/** One classification, bound to a country. */
|
|
52
|
+
class Kind {
|
|
53
|
+
call;
|
|
54
|
+
name;
|
|
55
|
+
country;
|
|
56
|
+
constructor(call, name, country) {
|
|
57
|
+
this.call = call;
|
|
58
|
+
this.name = name;
|
|
59
|
+
this.country = country;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* One code. A code that does not exist is a 404, which arrives as an
|
|
63
|
+
* APIError — there is no separate not-found type.
|
|
64
|
+
*/
|
|
65
|
+
async get(code, country) {
|
|
66
|
+
return this.call(`/fiscal-references/${segment(this.name)}/${segment(code)}`, { country: country ?? this.country });
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A page of this classification, filtered by the query's term when it
|
|
70
|
+
* has one. An empty term is no term: the route rejects search="" with
|
|
71
|
+
* a 422, and sending it would invent a failure the caller cannot read.
|
|
72
|
+
*/
|
|
73
|
+
async search(query = {}) {
|
|
74
|
+
return this.call("/fiscal-references", searchParams(this.name, this.country, query));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.Kind = Kind;
|
|
78
|
+
/**
|
|
79
|
+
* Reads the published classification tables. Nothing here is the
|
|
80
|
+
* company's own data and nothing here is writable.
|
|
81
|
+
*/
|
|
82
|
+
class FiscalReference extends client_1.Client {
|
|
83
|
+
cfop;
|
|
84
|
+
ncm;
|
|
85
|
+
cest;
|
|
86
|
+
cst;
|
|
87
|
+
csosn;
|
|
88
|
+
issService;
|
|
89
|
+
icmsFuel;
|
|
90
|
+
ibsCbsClass;
|
|
91
|
+
constructor(options = {}) {
|
|
92
|
+
super(options);
|
|
93
|
+
this.cfop = this.kind("cfop");
|
|
94
|
+
this.ncm = this.kind("ncm");
|
|
95
|
+
this.cest = this.kind("cest");
|
|
96
|
+
this.cst = this.kind("cst");
|
|
97
|
+
this.csosn = this.kind("csosn");
|
|
98
|
+
this.issService = this.kind("iss_service");
|
|
99
|
+
this.icmsFuel = this.kind("icms_fuel");
|
|
100
|
+
this.ibsCbsClass = this.kind("ibs_cbs_class");
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Which classifications this country has rows for. The only honest
|
|
104
|
+
* answer to "what else is there" — a hard-coded list goes stale the
|
|
105
|
+
* next time the ETL grows one.
|
|
106
|
+
*/
|
|
107
|
+
async kinds(country) {
|
|
108
|
+
const response = await this.send("GET", "/fiscal-references/kinds", {
|
|
109
|
+
query: { country: country ?? this.country },
|
|
110
|
+
});
|
|
111
|
+
const text = await response.text();
|
|
112
|
+
if (!text)
|
|
113
|
+
return [];
|
|
114
|
+
const body = JSON.parse(text);
|
|
115
|
+
if (!Array.isArray(body)) {
|
|
116
|
+
throw new Error("unexpected response shape: expected a list");
|
|
117
|
+
}
|
|
118
|
+
return body;
|
|
119
|
+
}
|
|
120
|
+
/** Any classification by name, including one with no accessor. */
|
|
121
|
+
kind(name, country) {
|
|
122
|
+
return new Kind((path, query) => this.request("GET", path, { query }), name, country ?? this.country);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Every classification at once, which no accessor can express. The
|
|
126
|
+
* most expensive call the endpoint accepts: the whole country's
|
|
127
|
+
* tables, not one of them.
|
|
128
|
+
*/
|
|
129
|
+
async search(query = {}) {
|
|
130
|
+
return this.request("GET", "/fiscal-references", {
|
|
131
|
+
query: searchParams(null, this.country, query),
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.FiscalReference = FiscalReference;
|
|
136
|
+
//# sourceMappingURL=reference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference.js","sourceRoot":"","sources":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ClientOptions } from "./client";
|
|
2
|
+
/**
|
|
3
|
+
* Reads the taxpayer registry, one tax id at a time.
|
|
4
|
+
*
|
|
5
|
+
* One method, and it stays one method. The registry names and addresses
|
|
6
|
+
* real people and companies: an exact lookup answers the question an
|
|
7
|
+
* issuer has — who is this CNPJ I am about to invoice — and answers
|
|
8
|
+
* nothing else. A prefix or wildcard search over the same table is a
|
|
9
|
+
* bulk export wearing the costume of a query. Do not add one, not for
|
|
10
|
+
* parity with FiscalReference, not "just by name", not "just within one
|
|
11
|
+
* state".
|
|
12
|
+
*/
|
|
13
|
+
export declare class Taxpayer extends Client {
|
|
14
|
+
constructor(options?: ClientOptions);
|
|
15
|
+
/**
|
|
16
|
+
* One taxpayer, by exact tax id.
|
|
17
|
+
*
|
|
18
|
+
* A 404 arrives as an APIError and does not mean the taxpayer does
|
|
19
|
+
* not exist: the registry reloads monthly, so a company registered in
|
|
20
|
+
* the last few weeks is simply not in it yet. Never build a
|
|
21
|
+
* validation rule on top of it.
|
|
22
|
+
*/
|
|
23
|
+
get(taxId: string, country?: string): Promise<Record<string, unknown>>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=taxpayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taxpayer.d.ts","sourceRoot":"","sources":["../src/taxpayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAGjD;;;;;;;;;;GAUG;AACH,qBAAa,QAAS,SAAQ,MAAM;gBACtB,OAAO,GAAE,aAAkB;IAIvC;;;;;;;OAOG;IACG,GAAG,CACP,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAKpC"}
|
package/dist/taxpayer.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Taxpayer = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
const reference_1 = require("./reference");
|
|
6
|
+
/**
|
|
7
|
+
* Reads the taxpayer registry, one tax id at a time.
|
|
8
|
+
*
|
|
9
|
+
* One method, and it stays one method. The registry names and addresses
|
|
10
|
+
* real people and companies: an exact lookup answers the question an
|
|
11
|
+
* issuer has — who is this CNPJ I am about to invoice — and answers
|
|
12
|
+
* nothing else. A prefix or wildcard search over the same table is a
|
|
13
|
+
* bulk export wearing the costume of a query. Do not add one, not for
|
|
14
|
+
* parity with FiscalReference, not "just by name", not "just within one
|
|
15
|
+
* state".
|
|
16
|
+
*/
|
|
17
|
+
class Taxpayer extends client_1.Client {
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
super(options);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* One taxpayer, by exact tax id.
|
|
23
|
+
*
|
|
24
|
+
* A 404 arrives as an APIError and does not mean the taxpayer does
|
|
25
|
+
* not exist: the registry reloads monthly, so a company registered in
|
|
26
|
+
* the last few weeks is simply not in it yet. Never build a
|
|
27
|
+
* validation rule on top of it.
|
|
28
|
+
*/
|
|
29
|
+
async get(taxId, country) {
|
|
30
|
+
return this.request("GET", `/taxpayers/${(0, reference_1.segment)(taxId)}`, {
|
|
31
|
+
query: { country: country ?? this.country },
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Taxpayer = Taxpayer;
|
|
36
|
+
//# sourceMappingURL=taxpayer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taxpayer.js","sourceRoot":"","sources":["../src/taxpayer.ts"],"names":[],"mappings":";;;AAAA,qCAAiD;AACjD,2CAAsC;AAEtC;;;;;;;;;;GAUG;AACH,MAAa,QAAS,SAAQ,eAAM;IAClC,YAAY,UAAyB,EAAE;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CACP,KAAa,EACb,OAAgB;QAEhB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,IAAA,mBAAO,EAAC,KAAK,CAAC,EAAE,EAAE;YACzD,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;CACF;AArBD,4BAqBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackin-io/stackin-node-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
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
5
|
"keywords": [
|
|
6
6
|
"stackin",
|