@blob-solutions/vcr-am-sdk 0.18.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.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
@@ -683,11 +707,19 @@ type AutoSettle = {
683
707
  type PayByAmount = {
684
708
  amount: SaleAmount;
685
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;
686
717
  };
687
718
  /** VCR derives the AMD total onto one tender. Mutually exclusive with `amount`. */
688
719
  type PayByAutoSettle = {
689
720
  autoSettle: AutoSettle;
690
721
  amount?: never;
722
+ prepaymentId?: never;
691
723
  };
692
724
  /**
693
725
  * A sale settles EITHER by explicit `amount` OR by `autoSettle` — exactly one,
@@ -745,6 +777,11 @@ type RegisterPrepaymentInput = {
745
777
  type RegisterPrepaymentRefundInput = {
746
778
  cashier: CashierId;
747
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;
748
785
  receipt?: SendReceiptToBuyer;
749
786
  reason?: RefundReason;
750
787
  reasonNote?: string;
@@ -931,19 +968,47 @@ type ApiErrorIssue = {
931
968
  code: string;
932
969
  };
933
970
  /**
934
- * 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.
935
973
  *
936
- * Present on a 502 when SRC was merely unreachable. It means the request was
937
- * NOT lost: VCR owns the work and a background sweep usually completes it
938
- * within minutes. Poll `statusUrl` to find out; do NOT resend the request,
939
- * 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.
940
981
  */
941
982
  type PendingResource = {
942
- /** 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
+ */
943
988
  type: string;
944
989
  id: number;
945
- /** 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
+ */
946
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;
947
1012
  };
948
1013
  type ApiErrorBody = {
949
1014
  error: string;