@facturino/node 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +295 -26
- package/dist/cjs/client.d.ts +1 -1
- package/dist/cjs/client.js +2 -2
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/resources/companies.d.ts +1 -1
- package/dist/cjs/resources/invoices.d.ts +31 -1
- package/dist/cjs/resources/invoices.js +51 -0
- package/dist/cjs/resources/taxDecisions.d.ts +31 -0
- package/dist/cjs/resources/taxDecisions.js +63 -0
- package/dist/cjs/types.d.ts +547 -20
- package/dist/esm/client.d.ts +1 -1
- package/dist/esm/client.js +2 -2
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resources/companies.d.ts +1 -1
- package/dist/esm/resources/companies.d.ts.map +1 -1
- package/dist/esm/resources/invoices.d.ts +31 -1
- package/dist/esm/resources/invoices.d.ts.map +1 -1
- package/dist/esm/resources/invoices.js +51 -0
- package/dist/esm/resources/invoices.js.map +1 -1
- package/dist/esm/resources/taxDecisions.d.ts +32 -0
- package/dist/esm/resources/taxDecisions.d.ts.map +1 -0
- package/dist/esm/resources/taxDecisions.js +60 -0
- package/dist/esm/resources/taxDecisions.js.map +1 -0
- package/dist/esm/types.d.ts +547 -20
- package/dist/esm/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaxDecisions = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Tax decisions — the fiscal position of one commercial operation.
|
|
6
|
+
*
|
|
7
|
+
* A decision fixes the VAT, the exact amount to charge and the three reporting
|
|
8
|
+
* axes, then never changes. Ask for one BEFORE you charge anything: the amount
|
|
9
|
+
* to debit is `amountToCharge`, not a total computed locally.
|
|
10
|
+
*
|
|
11
|
+
* The resource is immutable by design — there is no update and no delete. To
|
|
12
|
+
* re-decide the same operation after supplying missing evidence, create a new
|
|
13
|
+
* decision with `retryOfTaxDecisionId`.
|
|
14
|
+
*/
|
|
15
|
+
/** Maximum length the API accepts for `Idempotency-Key`. */
|
|
16
|
+
const MAX_IDEMPOTENCY_KEY_LENGTH = 255;
|
|
17
|
+
class TaxDecisions {
|
|
18
|
+
constructor(client) {
|
|
19
|
+
this.client = client;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Take a decision on a commercial operation.
|
|
23
|
+
*
|
|
24
|
+
* Business idempotency is durable here, beyond the 24-hour transport window,
|
|
25
|
+
* and it is keyed on the KEY — not on the operation. The SAME
|
|
26
|
+
* `idempotencyKey` with the SAME canonical body always replays the SAME
|
|
27
|
+
* decision, so a retry after a lost response costs nothing and charges
|
|
28
|
+
* nothing twice. Two DIFFERENT keys describing the same operation produce TWO
|
|
29
|
+
* decisions: nothing matches them up, and reusing one key with a different
|
|
30
|
+
* body answers `409`.
|
|
31
|
+
*
|
|
32
|
+
* Only a `final` decision carries amounts. On `pending_verification` or
|
|
33
|
+
* `unsupported`, `totals` and `amountToCharge` are `null` — never `0` — and
|
|
34
|
+
* `issues` says what is missing.
|
|
35
|
+
*/
|
|
36
|
+
async create(params, options) {
|
|
37
|
+
const key = typeof options?.idempotencyKey === 'string' ? options.idempotencyKey.trim() : '';
|
|
38
|
+
if (key.length === 0) {
|
|
39
|
+
throw new Error('Idempotency-Key is required to create a tax decision');
|
|
40
|
+
}
|
|
41
|
+
// The API caps the key at 255 characters. Checking it here turns a round
|
|
42
|
+
// trip and a 400 into an immediate, local error.
|
|
43
|
+
if (key.length > MAX_IDEMPOTENCY_KEY_LENGTH) {
|
|
44
|
+
throw new Error(`Idempotency-Key must be at most ${MAX_IDEMPOTENCY_KEY_LENGTH} characters (received ${key.length})`);
|
|
45
|
+
}
|
|
46
|
+
// 201 on creation, 200 when the same key already produced this decision.
|
|
47
|
+
// Both carry the decision itself, so the caller reads one shape either way;
|
|
48
|
+
// a different body under the same key answers 409 (ConflictError).
|
|
49
|
+
return this.client.post('/v1/tax-decisions', params, options);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Read a decision back — typically after a payment capture, to check that the
|
|
53
|
+
* captured amount, currency and buyer match what was decided.
|
|
54
|
+
*/
|
|
55
|
+
async retrieve(id) {
|
|
56
|
+
return this.client.get(`/v1/tax-decisions/${id}`);
|
|
57
|
+
}
|
|
58
|
+
/** Alias of {@link TaxDecisions.retrieve}, for consistency with the other resources. */
|
|
59
|
+
async get(id) {
|
|
60
|
+
return this.retrieve(id);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.TaxDecisions = TaxDecisions;
|