@stackin-io/stackin-node-sdk 0.19.0 → 0.21.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 CHANGED
@@ -33,13 +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.InsufficientPermissionError = exports.ConnectionFailedError = exports.CompanyRequiredError = exports.CompanyNotInScopeError = exports.ClientAlreadyExistsError = exports.APIError = exports.InvoiceError = exports.Purpose = exports.Manifestation = exports.Environment = exports.DocumentType = exports.Direction = exports.Address = exports.Taxpayer = exports.KINDS = exports.Kind = exports.FiscalReference = exports.Clients = exports.COMPANY_HEADER = exports.DEFAULT_BASE_URL = exports.Invoice = void 0;
36
+ exports.br = exports.ValidationError = exports.RateLimitedError = exports.PaymentRequiredError = exports.InsufficientPermissionError = exports.ConnectionFailedError = exports.CompanyRequiredError = exports.CompanyNotInScopeError = exports.ClientNotFoundError = exports.ClientInactiveError = exports.ClientAlreadyExistsError = exports.APIError = exports.InvoiceError = exports.Purpose = exports.Manifestation = exports.Environment = exports.DocumentType = exports.Direction = exports.Address = exports.Taxpayer = exports.KINDS = exports.Kind = exports.FiscalReference = exports.WEBHOOK_EVENTS = exports.Webhooks = exports.Clients = exports.COMPANY_HEADER = 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
40
  Object.defineProperty(exports, "COMPANY_HEADER", { enumerable: true, get: function () { return client_1.COMPANY_HEADER; } });
41
41
  var clients_1 = require("./clients");
42
42
  Object.defineProperty(exports, "Clients", { enumerable: true, get: function () { return clients_1.Clients; } });
43
+ var webhooks_1 = require("./webhooks");
44
+ Object.defineProperty(exports, "Webhooks", { enumerable: true, get: function () { return webhooks_1.Webhooks; } });
45
+ Object.defineProperty(exports, "WEBHOOK_EVENTS", { enumerable: true, get: function () { return webhooks_1.WEBHOOK_EVENTS; } });
43
46
  var reference_1 = require("./reference");
44
47
  Object.defineProperty(exports, "FiscalReference", { enumerable: true, get: function () { return reference_1.FiscalReference; } });
45
48
  Object.defineProperty(exports, "Kind", { enumerable: true, get: function () { return reference_1.Kind; } });
@@ -58,10 +61,14 @@ var errors_1 = require("./errors");
58
61
  Object.defineProperty(exports, "InvoiceError", { enumerable: true, get: function () { return errors_1.InvoiceError; } });
59
62
  Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return errors_1.APIError; } });
60
63
  Object.defineProperty(exports, "ClientAlreadyExistsError", { enumerable: true, get: function () { return errors_1.ClientAlreadyExistsError; } });
64
+ Object.defineProperty(exports, "ClientInactiveError", { enumerable: true, get: function () { return errors_1.ClientInactiveError; } });
65
+ Object.defineProperty(exports, "ClientNotFoundError", { enumerable: true, get: function () { return errors_1.ClientNotFoundError; } });
61
66
  Object.defineProperty(exports, "CompanyNotInScopeError", { enumerable: true, get: function () { return errors_1.CompanyNotInScopeError; } });
62
67
  Object.defineProperty(exports, "CompanyRequiredError", { enumerable: true, get: function () { return errors_1.CompanyRequiredError; } });
63
68
  Object.defineProperty(exports, "ConnectionFailedError", { enumerable: true, get: function () { return errors_1.ConnectionFailedError; } });
64
69
  Object.defineProperty(exports, "InsufficientPermissionError", { enumerable: true, get: function () { return errors_1.InsufficientPermissionError; } });
70
+ Object.defineProperty(exports, "PaymentRequiredError", { enumerable: true, get: function () { return errors_1.PaymentRequiredError; } });
71
+ Object.defineProperty(exports, "RateLimitedError", { enumerable: true, get: function () { return errors_1.RateLimitedError; } });
65
72
  Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
66
73
  exports.br = __importStar(require("./br"));
67
74
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAqE;AAA5D,iGAAA,OAAO,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAAE,wGAAA,cAAc,OAAA;AAQlD,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAOhB,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,iCAMiB;AALf,kGAAA,SAAS,OAAA;AACT,qGAAA,YAAY,OAAA;AACZ,oGAAA,WAAW,OAAA;AACX,sGAAA,aAAa,OAAA;AACb,gGAAA,OAAO,OAAA;AAGT,mCASkB;AARhB,sGAAA,YAAY,OAAA;AACZ,kGAAA,QAAQ,OAAA;AACR,kHAAA,wBAAwB,OAAA;AACxB,gHAAA,sBAAsB,OAAA;AACtB,8GAAA,oBAAoB,OAAA;AACpB,+GAAA,qBAAqB,OAAA;AACrB,qHAAA,2BAA2B,OAAA;AAC3B,yGAAA,eAAe,OAAA;AAEjB,2CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAqE;AAA5D,iGAAA,OAAO,OAAA;AAAE,0GAAA,gBAAgB,OAAA;AAAE,wGAAA,cAAc,OAAA;AAUlD,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAOhB,uCAAsD;AAA7C,oGAAA,QAAQ,OAAA;AAAE,0GAAA,cAAc,OAAA;AAEjC,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,iCAMiB;AALf,kGAAA,SAAS,OAAA;AACT,qGAAA,YAAY,OAAA;AACZ,oGAAA,WAAW,OAAA;AACX,sGAAA,aAAa,OAAA;AACb,gGAAA,OAAO,OAAA;AAQT,mCAakB;AAZhB,sGAAA,YAAY,OAAA;AACZ,kGAAA,QAAQ,OAAA;AACR,kHAAA,wBAAwB,OAAA;AACxB,6GAAA,mBAAmB,OAAA;AACnB,6GAAA,mBAAmB,OAAA;AACnB,gHAAA,sBAAsB,OAAA;AACtB,8GAAA,oBAAoB,OAAA;AACpB,+GAAA,qBAAqB,OAAA;AACrB,qHAAA,2BAA2B,OAAA;AAC3B,8GAAA,oBAAoB,OAAA;AACpB,0GAAA,gBAAgB,OAAA;AAChB,yGAAA,eAAe,OAAA;AAEjB,2CAA2B"}
@@ -1,12 +1,6 @@
1
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;
2
+ import { segment } from "./segment";
3
+ export { segment };
10
4
  /**
11
5
  * The classifications with a named accessor on FiscalReference.
12
6
  *
@@ -70,6 +64,19 @@ export declare class FiscalReference extends Client {
70
64
  kinds(country?: string): Promise<string[]>;
71
65
  /** Any classification by name, including one with no accessor. */
72
66
  kind(name: string, country?: string): Kind;
67
+ /**
68
+ * Municipalities whose name starts with name, with their code.
69
+ *
70
+ * Each row is {country, code, name, state}; for Brazil code is the
71
+ * 7-digit IBGE code an address's cityCode takes. Issuing resolves it
72
+ * from city and state by itself, so this is for the name that matches
73
+ * more than one. state narrows to one UF; the API answers at most 20
74
+ * rows.
75
+ */
76
+ cities(name: string, options?: {
77
+ state?: string;
78
+ country?: string;
79
+ }): Promise<Array<Record<string, unknown>>>;
73
80
  /**
74
81
  * Every classification at once, which no accessor can express. The
75
82
  * most expensive call the endpoint accepts: the whole country's
@@ -77,5 +84,4 @@ export declare class FiscalReference extends Client {
77
84
  */
78
85
  search(query?: SearchQuery): Promise<Record<string, unknown>>;
79
86
  }
80
- export {};
81
87
  //# sourceMappingURL=reference.d.ts.map
@@ -1 +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,CAAC;CACjB;AAiBD,KAAK,IAAI,GAAG,CACV,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAC1B,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEtC,8CAA8C;AAC9C,qBAAa,IAAI;IAEb,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM;gBAFP,IAAI,EAAE,IAAI,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM;IAG1B;;;OAGG;IACG,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC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,EAAE,CAAC;IAehD,kEAAkE;IAClE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ1C;;;;;;;;OAQG;IACG,MAAM,CACV,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GACjD,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAkB1C;;;;OAIG;IACG,MAAM,CAAC,KAAK,GAAE,WAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAKxE"}
package/dist/reference.js CHANGED
@@ -1,22 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FiscalReference = exports.Kind = exports.KINDS = void 0;
4
- exports.segment = segment;
3
+ exports.FiscalReference = exports.Kind = exports.KINDS = exports.segment = void 0;
5
4
  const client_1 = require("./client");
6
5
  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
- }
6
+ const segment_1 = require("./segment");
7
+ Object.defineProperty(exports, "segment", { enumerable: true, get: function () { return segment_1.segment; } });
20
8
  /**
21
9
  * The classifications with a named accessor on FiscalReference.
22
10
  *
@@ -63,7 +51,7 @@ class Kind {
63
51
  * APIError — there is no separate not-found type.
64
52
  */
65
53
  async get(code, country) {
66
- return this.call(`/fiscal-references/${segment(this.name)}/${segment(code)}`, { country: country ?? this.country });
54
+ return this.call(`/fiscal-references/${(0, segment_1.segment)(this.name)}/${(0, segment_1.segment)(code)}`, { country: country ?? this.country });
67
55
  }
68
56
  /**
69
57
  * A page of this classification, filtered by the query's term when it
@@ -121,6 +109,31 @@ class FiscalReference extends client_1.Client {
121
109
  kind(name, country) {
122
110
  return new Kind((path, query) => this.request("GET", path, { query }), name, country ?? this.country);
123
111
  }
112
+ /**
113
+ * Municipalities whose name starts with name, with their code.
114
+ *
115
+ * Each row is {country, code, name, state}; for Brazil code is the
116
+ * 7-digit IBGE code an address's cityCode takes. Issuing resolves it
117
+ * from city and state by itself, so this is for the name that matches
118
+ * more than one. state narrows to one UF; the API answers at most 20
119
+ * rows.
120
+ */
121
+ async cities(name, options = {}) {
122
+ const length = [...(name ?? "")].length;
123
+ if (length < 2 || length > 100) {
124
+ throw new errors_1.ValidationError("name must be 2 to 100 characters");
125
+ }
126
+ if (options.state !== undefined && options.state.length !== 2) {
127
+ throw new errors_1.ValidationError("state must be a two-letter code");
128
+ }
129
+ const query = {
130
+ name,
131
+ country: options.country ?? this.country,
132
+ };
133
+ if (options.state !== undefined)
134
+ query.state = options.state.toUpperCase();
135
+ return this.requestList("GET", "/cities", { query });
136
+ }
124
137
  /**
125
138
  * Every classification at once, which no accessor can express. The
126
139
  * most expensive call the endpoint accepts: the whole country's
@@ -1 +1 @@
1
- {"version":3,"file":"reference.js","sourceRoot":"","sources":["../src/reference.ts"],"names":[],"mappings":";;;AAUA,0BAKC;AAfD,qCAAiD;AACjD,qCAA2C;AAE3C;;;;;;GAMG;AACH,SAAgB,OAAO,CAAC,KAAa;IACnC,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpD,MAAM,IAAI,wBAAe,CAAC,IAAI,KAAK,gCAAgC,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACU,QAAA,KAAK,GAA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/C,KAAK,EAAE,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC;SAC/C,CAAC,CAAC;IACL,CAAC;CACF;AA5FD,0CA4FC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * One path segment, escaped, refusing the ones that would leave it.
3
+ *
4
+ * encodeURIComponent leaves "." alone — RFC 3986 calls it unreserved —
5
+ * so the dot segments have to be refused rather than escaped, or the
6
+ * HTTP client collapses ".." into a different endpoint.
7
+ */
8
+ export declare function segment(value: string): string;
9
+ //# sourceMappingURL=segment.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segment.d.ts","sourceRoot":"","sources":["../src/segment.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK7C"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.segment = segment;
4
+ const errors_1 = require("./errors");
5
+ /**
6
+ * One path segment, escaped, refusing the ones that would leave it.
7
+ *
8
+ * encodeURIComponent leaves "." alone — RFC 3986 calls it unreserved —
9
+ * so the dot segments have to be refused rather than escaped, or the
10
+ * HTTP client collapses ".." into a different endpoint.
11
+ */
12
+ function segment(value) {
13
+ if (value === "" || value === "." || value === "..") {
14
+ throw new errors_1.ValidationError(`"${value}" is not a usable path segment`);
15
+ }
16
+ return encodeURIComponent(value);
17
+ }
18
+ //# sourceMappingURL=segment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segment.js","sourceRoot":"","sources":["../src/segment.ts"],"names":[],"mappings":";;AASA,0BAKC;AAdD,qCAA2C;AAE3C;;;;;;GAMG;AACH,SAAgB,OAAO,CAAC,KAAa;IACnC,IAAI,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpD,MAAM,IAAI,wBAAe,CAAC,IAAI,KAAK,gCAAgC,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC"}
package/dist/types.d.ts CHANGED
@@ -42,4 +42,42 @@ export interface AuthorizedCompanies {
42
42
  environment: string;
43
43
  companies: AuthorizedCompany[];
44
44
  }
45
+ /**
46
+ * What GET /company/usage answers. Amounts are in cents; dates are ISO
47
+ * 8601 strings as the API sends them. Fields the API adds later come
48
+ * through untyped.
49
+ */
50
+ export interface Usage {
51
+ plan_name: string;
52
+ plan_slug: string;
53
+ included_invoices: number;
54
+ used_invoices: number;
55
+ /** Price of each issuance past the plan; null when the plan has none. */
56
+ overage_price_cents: number | null;
57
+ /** Received documents included each month. */
58
+ included_received: number;
59
+ used_received: number;
60
+ /** Price of each received document past the included ones. */
61
+ received_price_cents: number;
62
+ /** true when the account is exempt from received-document charges. */
63
+ received_free: boolean;
64
+ current_period_start: string;
65
+ current_period_end: string | null;
66
+ /** Account credit, in cents. */
67
+ credit_balance: number;
68
+ companies_on_account: number;
69
+ [field: string]: unknown;
70
+ }
71
+ /** What POST /received-invoices/sync answers. */
72
+ export interface ReceivedSync {
73
+ /** Documents stored by this sync. */
74
+ stored: number;
75
+ /** Distribution pages read from the SEFAZ. */
76
+ pages: number;
77
+ last_nsu: string;
78
+ max_nsu: string | null;
79
+ /** The earliest moment another sync is accepted, ISO 8601. */
80
+ next_sync_at: string | null;
81
+ [field: string]: unknown;
82
+ }
45
83
  //# sourceMappingURL=types.d.ts.map
@@ -1 +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,oEAAoE;AACpE,oBAAY,aAAa;IACvB,WAAW,WAAW;IACtB,OAAO,WAAW;IAClB,eAAe,WAAW;IAC1B,sBAAsB,WAAW;CAClC;AAED,6EAA6E;AAC7E,oBAAY,OAAO;IACjB,MAAM,WAAW;IACjB,aAAa,kBAAkB;IAC/B,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED;;;;GAIG;AACH,oBAAY,SAAS;IACnB,GAAG,QAAQ;IACX,EAAE,OAAO;CACV;AAED,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,UAAU,eAAe;CAC1B;AAED,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,wEAAwE;AACxE,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAChC"}
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,oEAAoE;AACpE,oBAAY,aAAa;IACvB,WAAW,WAAW;IACtB,OAAO,WAAW;IAClB,eAAe,WAAW;IAC1B,sBAAsB,WAAW;CAClC;AAED,6EAA6E;AAC7E,oBAAY,OAAO;IACjB,MAAM,WAAW;IACjB,aAAa,kBAAkB;IAC/B,UAAU,eAAe;IACzB,MAAM,WAAW;CAClB;AAED;;;;GAIG;AACH,oBAAY,SAAS;IACnB,GAAG,QAAQ;IACX,EAAE,OAAO;CACV;AAED,oBAAY,WAAW;IACrB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,UAAU,eAAe;CAC1B;AAED,iEAAiE;AACjE,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,wEAAwE;AACxE,MAAM,WAAW,mBAAmB;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAChC;AAED;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,8CAA8C;IAC9C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,oBAAoB,EAAE,MAAM,CAAC;IAC7B,sEAAsE;IACtE,aAAa,EAAE,OAAO,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,gCAAgC;IAChC,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,iDAAiD;AACjD,MAAM,WAAW,YAAY;IAC3B,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,8DAA8D;IAC9D,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Where the company's events are delivered: /webhooks.
3
+ *
4
+ * Company data, so every method takes company for one call over the
5
+ * client's own. An endpoint receives the events of the credential's own
6
+ * environment only. Every call needs the webhook:manage permission on an
7
+ * OAuth credential; an API key has it.
8
+ */
9
+ import { Client, CompanyOption, PageQuery } from "./client";
10
+ /** The events an endpoint can subscribe to. */
11
+ export declare const WEBHOOK_EVENTS: readonly ["invoice.authorized", "invoice.rejected", "invoice.cancelled", "invoice.corrected"];
12
+ export type WebhookEvent = (typeof WEBHOOK_EVENTS)[number];
13
+ /** An endpoint to register. */
14
+ export interface WebhookEndpoint extends CompanyOption {
15
+ /** An https:// URL, at most 500 characters. */
16
+ url: string;
17
+ /** 16 to 255 characters; signs every delivery and is never returned. */
18
+ secret: string;
19
+ /** What is sent, from WEBHOOK_EVENTS; left out, every event. */
20
+ events?: readonly string[];
21
+ }
22
+ /** Client for the company's webhook endpoints. */
23
+ export declare class Webhooks extends Client {
24
+ /**
25
+ * Registers an HTTPS endpoint for this company's events.
26
+ *
27
+ * The secret signs every delivery; it is never returned again, so
28
+ * keep it. The API refuses a URL that is not HTTPS or points at a
29
+ * private network.
30
+ */
31
+ create(endpoint: WebhookEndpoint): Promise<Record<string, unknown>>;
32
+ /**
33
+ * This company's endpoints in the credential's environment. A plain
34
+ * list, not a page. Secrets are never returned.
35
+ */
36
+ list(options?: CompanyOption): Promise<Array<Record<string, unknown>>>;
37
+ /**
38
+ * Stops delivery to one endpoint, keeping what was already sent. An
39
+ * id this company does not have is an APIError 404.
40
+ */
41
+ delete(endpointId: string, options?: CompanyOption): Promise<void>;
42
+ /**
43
+ * Every delivery attempt in the credential's environment, a page.
44
+ *
45
+ * Each row has the event, its status, attempts, the endpoint's
46
+ * response_status, last_error and when it was delivered or will be
47
+ * tried again.
48
+ */
49
+ deliveries(options?: PageQuery): Promise<Record<string, unknown>>;
50
+ }
51
+ //# sourceMappingURL=webhooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAa,MAAM,UAAU,CAAC;AAIvE,+CAA+C;AAC/C,eAAO,MAAM,cAAc,+FAKjB,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAM3D,+BAA+B;AAC/B,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,+CAA+C;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5B;AAED,kDAAkD;AAClD,qBAAa,QAAS,SAAQ,MAAM;IAClC;;;;;;OAMG;IACG,MAAM,CAAC,QAAQ,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAsCzE;;;OAGG;IACG,IAAI,CACR,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAI1C;;;OAGG;IACG,MAAM,CACV,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,IAAI,CAAC;IAMhB;;;;;;OAMG;IACG,UAAU,CAAC,OAAO,GAAE,SAAc,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAM5E"}
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Webhooks = exports.WEBHOOK_EVENTS = void 0;
4
+ /**
5
+ * Where the company's events are delivered: /webhooks.
6
+ *
7
+ * Company data, so every method takes company for one call over the
8
+ * client's own. An endpoint receives the events of the credential's own
9
+ * environment only. Every call needs the webhook:manage permission on an
10
+ * OAuth credential; an API key has it.
11
+ */
12
+ const client_1 = require("./client");
13
+ const errors_1 = require("./errors");
14
+ const segment_1 = require("./segment");
15
+ /** The events an endpoint can subscribe to. */
16
+ exports.WEBHOOK_EVENTS = [
17
+ "invoice.authorized",
18
+ "invoice.rejected",
19
+ "invoice.cancelled",
20
+ "invoice.corrected",
21
+ ];
22
+ const SECRET_MIN = 16;
23
+ const SECRET_MAX = 255;
24
+ const URL_MAX = 500;
25
+ /** Client for the company's webhook endpoints. */
26
+ class Webhooks extends client_1.Client {
27
+ /**
28
+ * Registers an HTTPS endpoint for this company's events.
29
+ *
30
+ * The secret signs every delivery; it is never returned again, so
31
+ * keep it. The API refuses a URL that is not HTTPS or points at a
32
+ * private network.
33
+ */
34
+ async create(endpoint) {
35
+ const url = endpoint.url ?? "";
36
+ if (!url.toLowerCase().startsWith("https://")) {
37
+ throw new errors_1.ValidationError("url must be an https:// URL");
38
+ }
39
+ if (url.length > URL_MAX) {
40
+ throw new errors_1.ValidationError(`url must be at most ${URL_MAX} characters`);
41
+ }
42
+ const secretLength = endpoint.secret?.length ?? 0;
43
+ if (secretLength < SECRET_MIN || secretLength > SECRET_MAX) {
44
+ throw new errors_1.ValidationError(`secret must be ${SECRET_MIN} to ${SECRET_MAX} characters`);
45
+ }
46
+ const body = { url, secret: endpoint.secret };
47
+ if (endpoint.events !== undefined) {
48
+ if (!Array.isArray(endpoint.events)) {
49
+ throw new errors_1.ValidationError("events must be a list of event names");
50
+ }
51
+ const known = exports.WEBHOOK_EVENTS;
52
+ const unknown = [
53
+ ...new Set(endpoint.events.filter((event) => !known.includes(event))),
54
+ ].sort();
55
+ if (unknown.length > 0) {
56
+ throw new errors_1.ValidationError(`unknown events: ${unknown.join(", ")}. Known: ${known.join(", ")}`);
57
+ }
58
+ body.events = [...endpoint.events];
59
+ }
60
+ return this.request("POST", "/webhooks", {
61
+ body,
62
+ company: endpoint.company,
63
+ });
64
+ }
65
+ /**
66
+ * This company's endpoints in the credential's environment. A plain
67
+ * list, not a page. Secrets are never returned.
68
+ */
69
+ async list(options = {}) {
70
+ return this.requestList("GET", "/webhooks", { company: options.company });
71
+ }
72
+ /**
73
+ * Stops delivery to one endpoint, keeping what was already sent. An
74
+ * id this company does not have is an APIError 404.
75
+ */
76
+ async delete(endpointId, options = {}) {
77
+ await this.send("DELETE", `/webhooks/${(0, segment_1.segment)(endpointId)}`, {
78
+ company: options.company,
79
+ });
80
+ }
81
+ /**
82
+ * Every delivery attempt in the credential's environment, a page.
83
+ *
84
+ * Each row has the event, its status, attempts, the endpoint's
85
+ * response_status, last_error and when it was delivered or will be
86
+ * tried again.
87
+ */
88
+ async deliveries(options = {}) {
89
+ return this.request("GET", "/webhooks/deliveries", {
90
+ query: (0, client_1.pageQuery)(options),
91
+ company: options.company,
92
+ });
93
+ }
94
+ }
95
+ exports.Webhooks = Webhooks;
96
+ //# sourceMappingURL=webhooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhooks.js","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,qCAAuE;AACvE,qCAA2C;AAC3C,uCAAoC;AAEpC,+CAA+C;AAClC,QAAA,cAAc,GAAG;IAC5B,oBAAoB;IACpB,kBAAkB;IAClB,mBAAmB;IACnB,mBAAmB;CACX,CAAC;AAIX,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,OAAO,GAAG,GAAG,CAAC;AAYpB,kDAAkD;AAClD,MAAa,QAAS,SAAQ,eAAM;IAClC;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CAAC,QAAyB;QACpC,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,IAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,wBAAe,CAAC,6BAA6B,CAAC,CAAC;QAC3D,CAAC;QACD,IAAI,GAAG,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC;YACzB,MAAM,IAAI,wBAAe,CAAC,uBAAuB,OAAO,aAAa,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,C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AAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,MAAM,CACV,UAAkB,EAClB,UAAyB,EAAE;QAE3B,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,aAAa,IAAA,iBAAO,EAAC,UAAU,CAAC,EAAE,EAAE;YAC5D,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,UAAU,CAAC,UAAqB,EAAE;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,sBAAsB,EAAE;YACjD,KAAK,EAAE,IAAA,kBAAS,EAAC,OAAO,CAAC;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC,CAAC;IACL,CAAC;CACF;AAlFD,4BAkFC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackin-io/stackin-node-sdk",
3
- "version": "0.19.0",
3
+ "version": "0.21.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",