@blob-solutions/vcr-am-sdk 0.17.0 → 0.20.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/lib/index.d.cts CHANGED
@@ -10,8 +10,9 @@ type RequestOptions = {
10
10
  * `registerPrepaymentRefund`). Retrying a request that carries the same key
11
11
  * returns the original response instead of registering a second document.
12
12
  *
13
- * Strongly recommended. Without it, retrying after a 502 produces a
14
- * duplicate fiscal receipt, which can only be undone by issuing a refund.
13
+ * Strongly recommended. Without it, retrying after a 502 or a 409 that
14
+ * carried a `pending` handle produces a duplicate fiscal receipt, which can
15
+ * only be undone by issuing a refund.
15
16
  *
16
17
  * The SDK deliberately does not generate this for you: the value must stay
17
18
  * **stable across your retries**, so it has to come from something you own —
@@ -20,12 +21,25 @@ type RequestOptions = {
20
21
  idempotencyKey?: string;
21
22
  };
22
23
 
24
+ /**
25
+ * Public receipt page for the buyer — safe to email, print as a QR, or put on
26
+ * an order-confirmation page: it carries no account access. The page picks the
27
+ * reader's own language.
28
+ *
29
+ * Optional, and deliberately so: the field was added to the API after this
30
+ * schema shipped, and a client that required it would fail to parse a
31
+ * perfectly good receipt from a server that predates it. A convenience field
32
+ * must never be the reason a fiscal call errors. It is always present from
33
+ * vcr.am today; build it yourself from `crn` and `urlId` if you need a
34
+ * fallback.
35
+ */
23
36
  declare const registerSaleResponseSchema: z.ZodObject<{
24
37
  urlId: z.ZodString;
25
38
  saleId: z.ZodNumber;
26
39
  crn: z.ZodString;
27
40
  srcReceiptId: z.ZodNumber;
28
41
  fiscal: z.ZodString;
42
+ receiptUrl: z.ZodOptional<z.ZodString>;
29
43
  }, z.core.$strip>;
30
44
  declare const registerSaleRefundResponseSchema: z.ZodObject<{
31
45
  urlId: z.ZodString;
@@ -33,6 +47,7 @@ declare const registerSaleRefundResponseSchema: z.ZodObject<{
33
47
  crn: z.ZodNullable<z.ZodString>;
34
48
  receiptId: z.ZodNumber;
35
49
  fiscal: z.ZodNullable<z.ZodString>;
50
+ receiptUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
36
51
  }, z.core.$strip>;
37
52
  declare const registerPrepaymentResponseSchema: z.ZodObject<{
38
53
  urlId: z.ZodString;
@@ -40,6 +55,7 @@ declare const registerPrepaymentResponseSchema: z.ZodObject<{
40
55
  crn: z.ZodNullable<z.ZodString>;
41
56
  receiptId: z.ZodNumber;
42
57
  fiscal: z.ZodNullable<z.ZodString>;
58
+ receiptUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
43
59
  }, z.core.$strip>;
44
60
  declare const registerPrepaymentRefundResponseSchema: z.ZodObject<{
45
61
  urlId: z.ZodString;
@@ -47,6 +63,7 @@ declare const registerPrepaymentRefundResponseSchema: z.ZodObject<{
47
63
  crn: z.ZodNullable<z.ZodString>;
48
64
  receiptId: z.ZodNumber;
49
65
  fiscal: z.ZodNullable<z.ZodString>;
66
+ receiptUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
50
67
  }, z.core.$strip>;
51
68
  declare const createOfferResponseSchema: z.ZodObject<{
52
69
  offerId: z.ZodNumber;
@@ -207,14 +224,21 @@ declare const offerListResponseSchema: z.ZodArray<z.ZodObject<{
207
224
  }, z.core.$strip>>;
208
225
  /**
209
226
  * Where a document stands with the tax authority, derived from its submission
210
- * log. This is the field to poll after a 502 that carried a `pending` handle.
227
+ * log. This is the field to poll after any response that carried a `pending`
228
+ * handle (502 or 409).
211
229
  *
212
230
  * - `accepted` — SRC registered it. Terminal and final; a fiscal receipt exists.
213
231
  * - `rejected` — SRC refused the document itself. Terminal: resending the same
214
232
  * payload gets the same refusal, so something has to change.
215
- * - `pending` — no answer from SRC yet. VCR owns the retry; do NOT resend.
216
- * - `needs_decision` — the automatic retry window (24h) closed without an
217
- * answer. Still not resendable blind — check the document before acting.
233
+ * - `pending` — no answer from SRC yet, and VCR still owns the document: it
234
+ * may already be registered there, or VCR is going to send it again. Do NOT
235
+ * resend.
236
+ * - `needs_decision` — nothing is going to submit this document on its own.
237
+ * Either the merchant has late fiscalization off (the default), in which
238
+ * case SRC registered nothing and it is yours to send again, or the 24h
239
+ * automatic window closed. The `502` that created it told you which via
240
+ * `pending.mayResubmit`; if you no longer have that response, check the
241
+ * document before acting rather than resending blind.
218
242
  *
219
243
  * A plain enum rather than a boolean because "not accepted" spans three very
220
244
  * different situations, and the one that matters most (`pending`) is the one
@@ -584,7 +608,24 @@ type NewOffer = {
584
608
  type Offer = NewOffer | ExistingOfferByExternalId | ExistingOfferById;
585
609
  type SaleItem = {
586
610
  offer: Offer;
587
- department: DepartmentInput;
611
+ /**
612
+ * Department to book this line under. **Omit it** unless you have a reason
613
+ * not to: the line then inherits the department of the offer it references
614
+ * (`defaultDepartment`), which for an inline new offer is the one you just
615
+ * declared on it.
616
+ *
617
+ * The department — not the offer — decides the tax regime printed on the
618
+ * receipt, and every register is created with one department per regime.
619
+ * So a hard-coded `{ id: 1 }` copied from an example is not a harmless
620
+ * default: on a register that owes no VAT it books the sale under the VAT
621
+ * department anyway, and the receipt shows a VAT line the merchant does not
622
+ * owe. Nothing rejects it, and a fiscal receipt can only be refunded and
623
+ * reissued, never corrected.
624
+ *
625
+ * Set it explicitly only to override the offer — selling the same SKU out
626
+ * of a second department (a VAT payer booking an exempt transaction, say).
627
+ */
628
+ department?: DepartmentInput;
588
629
  quantity: string;
589
630
  /**
590
631
  * Unit price. AMD by default. When {@link SaleItem.currency} is set to a
@@ -666,11 +707,19 @@ type AutoSettle = {
666
707
  type PayByAmount = {
667
708
  amount: SaleAmount;
668
709
  autoSettle?: never;
710
+ /**
711
+ * The prepayment `amount.prepayment` is spent from. Without it the sale
712
+ * consumes the oldest open prepayments, which for a buyer with no TIN means
713
+ * anyone's. A prepayment that cannot cover the amount refuses the sale with
714
+ * a `400` and nothing saved.
715
+ */
716
+ prepaymentId?: number;
669
717
  };
670
718
  /** VCR derives the AMD total onto one tender. Mutually exclusive with `amount`. */
671
719
  type PayByAutoSettle = {
672
720
  autoSettle: AutoSettle;
673
721
  amount?: never;
722
+ prepaymentId?: never;
674
723
  };
675
724
  /**
676
725
  * A sale settles EITHER by explicit `amount` OR by `autoSettle` — exactly one,
@@ -728,6 +777,11 @@ type RegisterPrepaymentInput = {
728
777
  type RegisterPrepaymentRefundInput = {
729
778
  cashier: CashierId;
730
779
  prepaymentId: number;
780
+ /**
781
+ * Return all that sales left of the prepayment. Without it, a prepayment a
782
+ * sale has used is refused. There is no amount: the rest cannot stay behind.
783
+ */
784
+ returnRemainder?: true;
731
785
  receipt?: SendReceiptToBuyer;
732
786
  reason?: RefundReason;
733
787
  reasonNote?: string;
@@ -914,19 +968,47 @@ type ApiErrorIssue = {
914
968
  code: string;
915
969
  };
916
970
  /**
917
- * A document VCR persisted and queued for automatic resubmission to SRC.
971
+ * A document VCR persisted despite the error. Its presence means the request
972
+ * was NOT lost, so never resend blindly — read `mayResubmit` first.
918
973
  *
919
- * Present on a 502 when SRC was merely unreachable. It means the request was
920
- * NOT lost: VCR owns the work and a background sweep usually completes it
921
- * within minutes. Poll `statusUrl` to find out; do NOT resend the request,
922
- * which would produce a second fiscal receipt.
974
+ * Present on two statuses:
975
+ *
976
+ * - **502** — SRC was unreachable. What to do next is `mayResubmit`.
977
+ * - **409** — SRC answered and refused the document on business grounds (for
978
+ * example 196, the cash register is not activated at SRC). `mayResubmit` is
979
+ * always false here: the same payload earns the same refusal. Read the SRC
980
+ * code in `error`, fix the cause, then send the corrected document.
923
981
  */
924
982
  type PendingResource = {
925
- /** Which collection `id` belongs to, e.g. `"sale"` or `"prepayment"`. */
983
+ /**
984
+ * Which collection `id` belongs to: `"sale"`, `"prepayment"`, or
985
+ * `"sale_refund"`. Deliberately a plain string — a server that adds a type
986
+ * must not break parsing in an older SDK.
987
+ */
926
988
  type: string;
927
989
  id: number;
928
- /** Path to poll for the outcome, e.g. `/api/v1/sales/5122`. */
990
+ /**
991
+ * Path to poll for the outcome, e.g. `/api/v1/sales/5122`. For
992
+ * `"sale_refund"` this is the PARENT SALE: find your refund by `id` in the
993
+ * response's `refunds` array.
994
+ */
929
995
  statusUrl: string;
996
+ /**
997
+ * Whether sending this exact request again is safe.
998
+ *
999
+ * `false` — the document is still VCR's to settle: SRC may have registered
1000
+ * it already, or VCR will submit it again for you. Resending risks a second
1001
+ * fiscal receipt for one sale. Poll `statusUrl` instead.
1002
+ *
1003
+ * `true` — SRC registered nothing and VCR will not send it again (the
1004
+ * merchant has late fiscalization off, which is the default). Nothing
1005
+ * further happens server-side; resubmitting is how the document gets
1006
+ * fiscalized.
1007
+ *
1008
+ * Absent when the server predates the field. Treat that as `false` — the
1009
+ * conservative reading, and what those servers did.
1010
+ */
1011
+ mayResubmit?: boolean;
930
1012
  };
931
1013
  type ApiErrorBody = {
932
1014
  error: string;
package/lib/index.d.ts CHANGED
@@ -10,8 +10,9 @@ type RequestOptions = {
10
10
  * `registerPrepaymentRefund`). Retrying a request that carries the same key
11
11
  * returns the original response instead of registering a second document.
12
12
  *
13
- * Strongly recommended. Without it, retrying after a 502 produces a
14
- * duplicate fiscal receipt, which can only be undone by issuing a refund.
13
+ * Strongly recommended. Without it, retrying after a 502 or a 409 that
14
+ * carried a `pending` handle produces a duplicate fiscal receipt, which can
15
+ * only be undone by issuing a refund.
15
16
  *
16
17
  * The SDK deliberately does not generate this for you: the value must stay
17
18
  * **stable across your retries**, so it has to come from something you own —
@@ -20,12 +21,25 @@ type RequestOptions = {
20
21
  idempotencyKey?: string;
21
22
  };
22
23
 
24
+ /**
25
+ * Public receipt page for the buyer — safe to email, print as a QR, or put on
26
+ * an order-confirmation page: it carries no account access. The page picks the
27
+ * reader's own language.
28
+ *
29
+ * Optional, and deliberately so: the field was added to the API after this
30
+ * schema shipped, and a client that required it would fail to parse a
31
+ * perfectly good receipt from a server that predates it. A convenience field
32
+ * must never be the reason a fiscal call errors. It is always present from
33
+ * vcr.am today; build it yourself from `crn` and `urlId` if you need a
34
+ * fallback.
35
+ */
23
36
  declare const registerSaleResponseSchema: z.ZodObject<{
24
37
  urlId: z.ZodString;
25
38
  saleId: z.ZodNumber;
26
39
  crn: z.ZodString;
27
40
  srcReceiptId: z.ZodNumber;
28
41
  fiscal: z.ZodString;
42
+ receiptUrl: z.ZodOptional<z.ZodString>;
29
43
  }, z.core.$strip>;
30
44
  declare const registerSaleRefundResponseSchema: z.ZodObject<{
31
45
  urlId: z.ZodString;
@@ -33,6 +47,7 @@ declare const registerSaleRefundResponseSchema: z.ZodObject<{
33
47
  crn: z.ZodNullable<z.ZodString>;
34
48
  receiptId: z.ZodNumber;
35
49
  fiscal: z.ZodNullable<z.ZodString>;
50
+ receiptUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
36
51
  }, z.core.$strip>;
37
52
  declare const registerPrepaymentResponseSchema: z.ZodObject<{
38
53
  urlId: z.ZodString;
@@ -40,6 +55,7 @@ declare const registerPrepaymentResponseSchema: z.ZodObject<{
40
55
  crn: z.ZodNullable<z.ZodString>;
41
56
  receiptId: z.ZodNumber;
42
57
  fiscal: z.ZodNullable<z.ZodString>;
58
+ receiptUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
43
59
  }, z.core.$strip>;
44
60
  declare const registerPrepaymentRefundResponseSchema: z.ZodObject<{
45
61
  urlId: z.ZodString;
@@ -47,6 +63,7 @@ declare const registerPrepaymentRefundResponseSchema: z.ZodObject<{
47
63
  crn: z.ZodNullable<z.ZodString>;
48
64
  receiptId: z.ZodNumber;
49
65
  fiscal: z.ZodNullable<z.ZodString>;
66
+ receiptUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
50
67
  }, z.core.$strip>;
51
68
  declare const createOfferResponseSchema: z.ZodObject<{
52
69
  offerId: z.ZodNumber;
@@ -207,14 +224,21 @@ declare const offerListResponseSchema: z.ZodArray<z.ZodObject<{
207
224
  }, z.core.$strip>>;
208
225
  /**
209
226
  * Where a document stands with the tax authority, derived from its submission
210
- * log. This is the field to poll after a 502 that carried a `pending` handle.
227
+ * log. This is the field to poll after any response that carried a `pending`
228
+ * handle (502 or 409).
211
229
  *
212
230
  * - `accepted` — SRC registered it. Terminal and final; a fiscal receipt exists.
213
231
  * - `rejected` — SRC refused the document itself. Terminal: resending the same
214
232
  * payload gets the same refusal, so something has to change.
215
- * - `pending` — no answer from SRC yet. VCR owns the retry; do NOT resend.
216
- * - `needs_decision` — the automatic retry window (24h) closed without an
217
- * answer. Still not resendable blind — check the document before acting.
233
+ * - `pending` — no answer from SRC yet, and VCR still owns the document: it
234
+ * may already be registered there, or VCR is going to send it again. Do NOT
235
+ * resend.
236
+ * - `needs_decision` — nothing is going to submit this document on its own.
237
+ * Either the merchant has late fiscalization off (the default), in which
238
+ * case SRC registered nothing and it is yours to send again, or the 24h
239
+ * automatic window closed. The `502` that created it told you which via
240
+ * `pending.mayResubmit`; if you no longer have that response, check the
241
+ * document before acting rather than resending blind.
218
242
  *
219
243
  * A plain enum rather than a boolean because "not accepted" spans three very
220
244
  * different situations, and the one that matters most (`pending`) is the one
@@ -584,7 +608,24 @@ type NewOffer = {
584
608
  type Offer = NewOffer | ExistingOfferByExternalId | ExistingOfferById;
585
609
  type SaleItem = {
586
610
  offer: Offer;
587
- department: DepartmentInput;
611
+ /**
612
+ * Department to book this line under. **Omit it** unless you have a reason
613
+ * not to: the line then inherits the department of the offer it references
614
+ * (`defaultDepartment`), which for an inline new offer is the one you just
615
+ * declared on it.
616
+ *
617
+ * The department — not the offer — decides the tax regime printed on the
618
+ * receipt, and every register is created with one department per regime.
619
+ * So a hard-coded `{ id: 1 }` copied from an example is not a harmless
620
+ * default: on a register that owes no VAT it books the sale under the VAT
621
+ * department anyway, and the receipt shows a VAT line the merchant does not
622
+ * owe. Nothing rejects it, and a fiscal receipt can only be refunded and
623
+ * reissued, never corrected.
624
+ *
625
+ * Set it explicitly only to override the offer — selling the same SKU out
626
+ * of a second department (a VAT payer booking an exempt transaction, say).
627
+ */
628
+ department?: DepartmentInput;
588
629
  quantity: string;
589
630
  /**
590
631
  * Unit price. AMD by default. When {@link SaleItem.currency} is set to a
@@ -666,11 +707,19 @@ type AutoSettle = {
666
707
  type PayByAmount = {
667
708
  amount: SaleAmount;
668
709
  autoSettle?: never;
710
+ /**
711
+ * The prepayment `amount.prepayment` is spent from. Without it the sale
712
+ * consumes the oldest open prepayments, which for a buyer with no TIN means
713
+ * anyone's. A prepayment that cannot cover the amount refuses the sale with
714
+ * a `400` and nothing saved.
715
+ */
716
+ prepaymentId?: number;
669
717
  };
670
718
  /** VCR derives the AMD total onto one tender. Mutually exclusive with `amount`. */
671
719
  type PayByAutoSettle = {
672
720
  autoSettle: AutoSettle;
673
721
  amount?: never;
722
+ prepaymentId?: never;
674
723
  };
675
724
  /**
676
725
  * A sale settles EITHER by explicit `amount` OR by `autoSettle` — exactly one,
@@ -728,6 +777,11 @@ type RegisterPrepaymentInput = {
728
777
  type RegisterPrepaymentRefundInput = {
729
778
  cashier: CashierId;
730
779
  prepaymentId: number;
780
+ /**
781
+ * Return all that sales left of the prepayment. Without it, a prepayment a
782
+ * sale has used is refused. There is no amount: the rest cannot stay behind.
783
+ */
784
+ returnRemainder?: true;
731
785
  receipt?: SendReceiptToBuyer;
732
786
  reason?: RefundReason;
733
787
  reasonNote?: string;
@@ -914,19 +968,47 @@ type ApiErrorIssue = {
914
968
  code: string;
915
969
  };
916
970
  /**
917
- * A document VCR persisted and queued for automatic resubmission to SRC.
971
+ * A document VCR persisted despite the error. Its presence means the request
972
+ * was NOT lost, so never resend blindly — read `mayResubmit` first.
918
973
  *
919
- * Present on a 502 when SRC was merely unreachable. It means the request was
920
- * NOT lost: VCR owns the work and a background sweep usually completes it
921
- * within minutes. Poll `statusUrl` to find out; do NOT resend the request,
922
- * which would produce a second fiscal receipt.
974
+ * Present on two statuses:
975
+ *
976
+ * - **502** — SRC was unreachable. What to do next is `mayResubmit`.
977
+ * - **409** — SRC answered and refused the document on business grounds (for
978
+ * example 196, the cash register is not activated at SRC). `mayResubmit` is
979
+ * always false here: the same payload earns the same refusal. Read the SRC
980
+ * code in `error`, fix the cause, then send the corrected document.
923
981
  */
924
982
  type PendingResource = {
925
- /** Which collection `id` belongs to, e.g. `"sale"` or `"prepayment"`. */
983
+ /**
984
+ * Which collection `id` belongs to: `"sale"`, `"prepayment"`, or
985
+ * `"sale_refund"`. Deliberately a plain string — a server that adds a type
986
+ * must not break parsing in an older SDK.
987
+ */
926
988
  type: string;
927
989
  id: number;
928
- /** Path to poll for the outcome, e.g. `/api/v1/sales/5122`. */
990
+ /**
991
+ * Path to poll for the outcome, e.g. `/api/v1/sales/5122`. For
992
+ * `"sale_refund"` this is the PARENT SALE: find your refund by `id` in the
993
+ * response's `refunds` array.
994
+ */
929
995
  statusUrl: string;
996
+ /**
997
+ * Whether sending this exact request again is safe.
998
+ *
999
+ * `false` — the document is still VCR's to settle: SRC may have registered
1000
+ * it already, or VCR will submit it again for you. Resending risks a second
1001
+ * fiscal receipt for one sale. Poll `statusUrl` instead.
1002
+ *
1003
+ * `true` — SRC registered nothing and VCR will not send it again (the
1004
+ * merchant has late fiscalization off, which is the default). Nothing
1005
+ * further happens server-side; resubmitting is how the document gets
1006
+ * fiscalized.
1007
+ *
1008
+ * Absent when the server predates the field. Treat that as `false` — the
1009
+ * conservative reading, and what those servers did.
1010
+ */
1011
+ mayResubmit?: boolean;
930
1012
  };
931
1013
  type ApiErrorBody = {
932
1014
  error: string;