@blob-solutions/vcr-am-sdk 0.16.0 → 0.18.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
@@ -4,6 +4,20 @@ type RequestOptions = {
4
4
  signal?: AbortSignal;
5
5
  /** Override per-request timeout in ms. `null` disables the timeout. */
6
6
  timeoutMs?: number | null;
7
+ /**
8
+ * Opt-in replay protection for the document-creating endpoints
9
+ * (`registerSale`, `registerSaleRefund`, `registerPrepayment`,
10
+ * `registerPrepaymentRefund`). Retrying a request that carries the same key
11
+ * returns the original response instead of registering a second document.
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.
15
+ *
16
+ * The SDK deliberately does not generate this for you: the value must stay
17
+ * **stable across your retries**, so it has to come from something you own —
18
+ * typically your order id (`order-4821`) — not from a fresh UUID per call.
19
+ */
20
+ idempotencyKey?: string;
7
21
  };
8
22
 
9
23
  declare const registerSaleResponseSchema: z.ZodObject<{
@@ -191,9 +205,36 @@ declare const offerListResponseSchema: z.ZodArray<z.ZodObject<{
191
205
  archivedAt: z.ZodNullable<z.ZodString>;
192
206
  createdAt: z.ZodString;
193
207
  }, z.core.$strip>>;
208
+ /**
209
+ * 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.
211
+ *
212
+ * - `accepted` — SRC registered it. Terminal and final; a fiscal receipt exists.
213
+ * - `rejected` — SRC refused the document itself. Terminal: resending the same
214
+ * 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.
218
+ *
219
+ * A plain enum rather than a boolean because "not accepted" spans three very
220
+ * different situations, and the one that matters most (`pending`) is the one
221
+ * that looks like failure but must not be treated as one.
222
+ */
223
+ declare const srcStatusSchema: z.ZodEnum<{
224
+ pending: "pending";
225
+ accepted: "accepted";
226
+ rejected: "rejected";
227
+ needs_decision: "needs_decision";
228
+ }>;
194
229
  declare const saleDetailResponseSchema: z.ZodObject<{
195
230
  id: z.ZodNumber;
196
231
  createdAt: z.ZodString;
232
+ srcStatus: z.ZodEnum<{
233
+ pending: "pending";
234
+ accepted: "accepted";
235
+ rejected: "rejected";
236
+ needs_decision: "needs_decision";
237
+ }>;
197
238
  buyerTin: z.ZodNullable<z.ZodString>;
198
239
  comment: z.ZodNullable<z.ZodString>;
199
240
  cashAmount: z.ZodNumber;
@@ -337,6 +378,12 @@ declare const prepaymentStateSchema: z.ZodEnum<{
337
378
  declare const prepaymentDetailResponseSchema: z.ZodObject<{
338
379
  id: z.ZodNumber;
339
380
  createdAt: z.ZodString;
381
+ srcStatus: z.ZodEnum<{
382
+ pending: "pending";
383
+ accepted: "accepted";
384
+ rejected: "rejected";
385
+ needs_decision: "needs_decision";
386
+ }>;
340
387
  buyerTin: z.ZodNullable<z.ZodString>;
341
388
  cashAmount: z.ZodNumber;
342
389
  nonCashAmount: z.ZodNumber;
@@ -437,6 +484,7 @@ type CashierListItem = z.infer<typeof cashierListItemSchema>;
437
484
  type ClassifierSearchItem = z.infer<typeof classifierSearchItemSchema>;
438
485
  type Whoami = z.infer<typeof whoamiResponseSchema>;
439
486
  type OfferListItem = z.infer<typeof offerListItemSchema>;
487
+ type SrcStatus = z.infer<typeof srcStatusSchema>;
440
488
  type SaleDetail = z.infer<typeof saleDetailResponseSchema>;
441
489
  type PrepaymentDetail = z.infer<typeof prepaymentDetailResponseSchema>;
442
490
  type PrepaymentListItem = z.infer<typeof prepaymentListItemSchema>;
@@ -536,7 +584,24 @@ type NewOffer = {
536
584
  type Offer = NewOffer | ExistingOfferByExternalId | ExistingOfferById;
537
585
  type SaleItem = {
538
586
  offer: Offer;
539
- department: DepartmentInput;
587
+ /**
588
+ * Department to book this line under. **Omit it** unless you have a reason
589
+ * not to: the line then inherits the department of the offer it references
590
+ * (`defaultDepartment`), which for an inline new offer is the one you just
591
+ * declared on it.
592
+ *
593
+ * The department — not the offer — decides the tax regime printed on the
594
+ * receipt, and every register is created with one department per regime.
595
+ * So a hard-coded `{ id: 1 }` copied from an example is not a harmless
596
+ * default: on a register that owes no VAT it books the sale under the VAT
597
+ * department anyway, and the receipt shows a VAT line the merchant does not
598
+ * owe. Nothing rejects it, and a fiscal receipt can only be refunded and
599
+ * reissued, never corrected.
600
+ *
601
+ * Set it explicitly only to override the offer — selling the same SKU out
602
+ * of a second department (a VAT payer booking an exempt transaction, say).
603
+ */
604
+ department?: DepartmentInput;
540
605
  quantity: string;
541
606
  /**
542
607
  * Unit price. AMD by default. When {@link SaleItem.currency} is set to a
@@ -865,6 +930,21 @@ type ApiErrorIssue = {
865
930
  message: string;
866
931
  code: string;
867
932
  };
933
+ /**
934
+ * A document VCR persisted and queued for automatic resubmission to SRC.
935
+ *
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.
940
+ */
941
+ type PendingResource = {
942
+ /** Which collection `id` belongs to, e.g. `"sale"` or `"prepayment"`. */
943
+ type: string;
944
+ id: number;
945
+ /** Path to poll for the outcome, e.g. `/api/v1/sales/5122`. */
946
+ statusUrl: string;
947
+ };
868
948
  type ApiErrorBody = {
869
949
  error: string;
870
950
  issues?: Array<ApiErrorIssue>;
@@ -874,6 +954,11 @@ type ApiErrorBody = {
874
954
  * and Sentry event can be located.
875
955
  */
876
956
  requestId?: string;
957
+ /**
958
+ * Set when the request was persisted despite the error. Its absence on an
959
+ * error means nothing was created.
960
+ */
961
+ pending?: PendingResource;
877
962
  };
878
963
  /**
879
964
  * Base class for every error thrown by the SDK.
@@ -920,4 +1005,4 @@ declare class VCRNetworkError extends VCRError {
920
1005
  });
921
1006
  }
922
1007
 
923
- export { AVAILABLE_LANGUAGES, type ApiErrorBody, type ApiErrorIssue, type AutoSettle, type Buyer, type CashierId, type CashierListItem, type ClassifierSearchItem, type ClassifierType, type CreateCashierInput, type CreateCashierResponse, type CreateDepartmentInput, type CreateDepartmentResponse, type CreateOfferInput, type CreateOfferInputProduct, type CreateOfferInputService, type CreateOfferResponse, type CreateOfferTitle, type CustomerPrepaymentBalance, DEFAULT_API_URL, DEFAULT_TIMEOUT_MS, type DepartmentInput, type DepartmentListItem, type Discounts, type ExchangeRate, type Language, type LegacyOfferTitle, type ListOffersFilter, type ListPrepaymentsFilter, type LocalizedName, type NewOffer, type Offer, type OfferListItem, type OfferTitle, type PrepaymentAmount, type PrepaymentDetail, type PrepaymentListItem, type PrepaymentState, REFUND_REASONS, type RefundAmount, type RefundItemInput, type RefundReason, type RegisterPrepaymentInput, type RegisterPrepaymentRefundInput, type RegisterPrepaymentRefundResponse, type RegisterPrepaymentResponse, type RegisterSaleInput, type RegisterSaleRefundInput, type RegisterSaleRefundResponse, type RegisterSaleResponse, type RequestOptions, type SaleAmount, type SaleData, type SaleDetail, type SaleItem, type SalePayment, type SearchClassifierInput, type SendReceiptToBuyer, TAX_REGIMES, type TaxRegime, type Unit, type UpdateOfferInput, VCRApiError, VCRClient, type VCRClientOptions, VCRError, VCRNetworkError, VCRValidationError, type Whoami, cashierListItemSchema, cashierListResponseSchema, classifierSearchItemSchema, classifierSearchResponseSchema, createCashierResponseSchema, createDepartmentResponseSchema, createOfferResponseSchema, customerPrepaymentBalanceResponseSchema, departmentListItemSchema, departmentListResponseSchema, exchangeRateResponseSchema, offerListItemSchema, offerListResponseSchema, prepaymentDetailResponseSchema, prepaymentListItemSchema, prepaymentListResponseSchema, prepaymentStateSchema, registerPrepaymentRefundResponseSchema, registerPrepaymentResponseSchema, registerSaleRefundResponseSchema, registerSaleResponseSchema, saleDetailResponseSchema, unitsKeys, whoamiResponseSchema };
1008
+ export { AVAILABLE_LANGUAGES, type ApiErrorBody, type ApiErrorIssue, type AutoSettle, type Buyer, type CashierId, type CashierListItem, type ClassifierSearchItem, type ClassifierType, type CreateCashierInput, type CreateCashierResponse, type CreateDepartmentInput, type CreateDepartmentResponse, type CreateOfferInput, type CreateOfferInputProduct, type CreateOfferInputService, type CreateOfferResponse, type CreateOfferTitle, type CustomerPrepaymentBalance, DEFAULT_API_URL, DEFAULT_TIMEOUT_MS, type DepartmentInput, type DepartmentListItem, type Discounts, type ExchangeRate, type Language, type LegacyOfferTitle, type ListOffersFilter, type ListPrepaymentsFilter, type LocalizedName, type NewOffer, type Offer, type OfferListItem, type OfferTitle, type PendingResource, type PrepaymentAmount, type PrepaymentDetail, type PrepaymentListItem, type PrepaymentState, REFUND_REASONS, type RefundAmount, type RefundItemInput, type RefundReason, type RegisterPrepaymentInput, type RegisterPrepaymentRefundInput, type RegisterPrepaymentRefundResponse, type RegisterPrepaymentResponse, type RegisterSaleInput, type RegisterSaleRefundInput, type RegisterSaleRefundResponse, type RegisterSaleResponse, type RequestOptions, type SaleAmount, type SaleData, type SaleDetail, type SaleItem, type SalePayment, type SearchClassifierInput, type SendReceiptToBuyer, type SrcStatus, TAX_REGIMES, type TaxRegime, type Unit, type UpdateOfferInput, VCRApiError, VCRClient, type VCRClientOptions, VCRError, VCRNetworkError, VCRValidationError, type Whoami, cashierListItemSchema, cashierListResponseSchema, classifierSearchItemSchema, classifierSearchResponseSchema, createCashierResponseSchema, createDepartmentResponseSchema, createOfferResponseSchema, customerPrepaymentBalanceResponseSchema, departmentListItemSchema, departmentListResponseSchema, exchangeRateResponseSchema, offerListItemSchema, offerListResponseSchema, prepaymentDetailResponseSchema, prepaymentListItemSchema, prepaymentListResponseSchema, prepaymentStateSchema, registerPrepaymentRefundResponseSchema, registerPrepaymentResponseSchema, registerSaleRefundResponseSchema, registerSaleResponseSchema, saleDetailResponseSchema, srcStatusSchema, unitsKeys, whoamiResponseSchema };
package/lib/index.d.ts CHANGED
@@ -4,6 +4,20 @@ type RequestOptions = {
4
4
  signal?: AbortSignal;
5
5
  /** Override per-request timeout in ms. `null` disables the timeout. */
6
6
  timeoutMs?: number | null;
7
+ /**
8
+ * Opt-in replay protection for the document-creating endpoints
9
+ * (`registerSale`, `registerSaleRefund`, `registerPrepayment`,
10
+ * `registerPrepaymentRefund`). Retrying a request that carries the same key
11
+ * returns the original response instead of registering a second document.
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.
15
+ *
16
+ * The SDK deliberately does not generate this for you: the value must stay
17
+ * **stable across your retries**, so it has to come from something you own —
18
+ * typically your order id (`order-4821`) — not from a fresh UUID per call.
19
+ */
20
+ idempotencyKey?: string;
7
21
  };
8
22
 
9
23
  declare const registerSaleResponseSchema: z.ZodObject<{
@@ -191,9 +205,36 @@ declare const offerListResponseSchema: z.ZodArray<z.ZodObject<{
191
205
  archivedAt: z.ZodNullable<z.ZodString>;
192
206
  createdAt: z.ZodString;
193
207
  }, z.core.$strip>>;
208
+ /**
209
+ * 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.
211
+ *
212
+ * - `accepted` — SRC registered it. Terminal and final; a fiscal receipt exists.
213
+ * - `rejected` — SRC refused the document itself. Terminal: resending the same
214
+ * 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.
218
+ *
219
+ * A plain enum rather than a boolean because "not accepted" spans three very
220
+ * different situations, and the one that matters most (`pending`) is the one
221
+ * that looks like failure but must not be treated as one.
222
+ */
223
+ declare const srcStatusSchema: z.ZodEnum<{
224
+ pending: "pending";
225
+ accepted: "accepted";
226
+ rejected: "rejected";
227
+ needs_decision: "needs_decision";
228
+ }>;
194
229
  declare const saleDetailResponseSchema: z.ZodObject<{
195
230
  id: z.ZodNumber;
196
231
  createdAt: z.ZodString;
232
+ srcStatus: z.ZodEnum<{
233
+ pending: "pending";
234
+ accepted: "accepted";
235
+ rejected: "rejected";
236
+ needs_decision: "needs_decision";
237
+ }>;
197
238
  buyerTin: z.ZodNullable<z.ZodString>;
198
239
  comment: z.ZodNullable<z.ZodString>;
199
240
  cashAmount: z.ZodNumber;
@@ -337,6 +378,12 @@ declare const prepaymentStateSchema: z.ZodEnum<{
337
378
  declare const prepaymentDetailResponseSchema: z.ZodObject<{
338
379
  id: z.ZodNumber;
339
380
  createdAt: z.ZodString;
381
+ srcStatus: z.ZodEnum<{
382
+ pending: "pending";
383
+ accepted: "accepted";
384
+ rejected: "rejected";
385
+ needs_decision: "needs_decision";
386
+ }>;
340
387
  buyerTin: z.ZodNullable<z.ZodString>;
341
388
  cashAmount: z.ZodNumber;
342
389
  nonCashAmount: z.ZodNumber;
@@ -437,6 +484,7 @@ type CashierListItem = z.infer<typeof cashierListItemSchema>;
437
484
  type ClassifierSearchItem = z.infer<typeof classifierSearchItemSchema>;
438
485
  type Whoami = z.infer<typeof whoamiResponseSchema>;
439
486
  type OfferListItem = z.infer<typeof offerListItemSchema>;
487
+ type SrcStatus = z.infer<typeof srcStatusSchema>;
440
488
  type SaleDetail = z.infer<typeof saleDetailResponseSchema>;
441
489
  type PrepaymentDetail = z.infer<typeof prepaymentDetailResponseSchema>;
442
490
  type PrepaymentListItem = z.infer<typeof prepaymentListItemSchema>;
@@ -536,7 +584,24 @@ type NewOffer = {
536
584
  type Offer = NewOffer | ExistingOfferByExternalId | ExistingOfferById;
537
585
  type SaleItem = {
538
586
  offer: Offer;
539
- department: DepartmentInput;
587
+ /**
588
+ * Department to book this line under. **Omit it** unless you have a reason
589
+ * not to: the line then inherits the department of the offer it references
590
+ * (`defaultDepartment`), which for an inline new offer is the one you just
591
+ * declared on it.
592
+ *
593
+ * The department — not the offer — decides the tax regime printed on the
594
+ * receipt, and every register is created with one department per regime.
595
+ * So a hard-coded `{ id: 1 }` copied from an example is not a harmless
596
+ * default: on a register that owes no VAT it books the sale under the VAT
597
+ * department anyway, and the receipt shows a VAT line the merchant does not
598
+ * owe. Nothing rejects it, and a fiscal receipt can only be refunded and
599
+ * reissued, never corrected.
600
+ *
601
+ * Set it explicitly only to override the offer — selling the same SKU out
602
+ * of a second department (a VAT payer booking an exempt transaction, say).
603
+ */
604
+ department?: DepartmentInput;
540
605
  quantity: string;
541
606
  /**
542
607
  * Unit price. AMD by default. When {@link SaleItem.currency} is set to a
@@ -865,6 +930,21 @@ type ApiErrorIssue = {
865
930
  message: string;
866
931
  code: string;
867
932
  };
933
+ /**
934
+ * A document VCR persisted and queued for automatic resubmission to SRC.
935
+ *
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.
940
+ */
941
+ type PendingResource = {
942
+ /** Which collection `id` belongs to, e.g. `"sale"` or `"prepayment"`. */
943
+ type: string;
944
+ id: number;
945
+ /** Path to poll for the outcome, e.g. `/api/v1/sales/5122`. */
946
+ statusUrl: string;
947
+ };
868
948
  type ApiErrorBody = {
869
949
  error: string;
870
950
  issues?: Array<ApiErrorIssue>;
@@ -874,6 +954,11 @@ type ApiErrorBody = {
874
954
  * and Sentry event can be located.
875
955
  */
876
956
  requestId?: string;
957
+ /**
958
+ * Set when the request was persisted despite the error. Its absence on an
959
+ * error means nothing was created.
960
+ */
961
+ pending?: PendingResource;
877
962
  };
878
963
  /**
879
964
  * Base class for every error thrown by the SDK.
@@ -920,4 +1005,4 @@ declare class VCRNetworkError extends VCRError {
920
1005
  });
921
1006
  }
922
1007
 
923
- export { AVAILABLE_LANGUAGES, type ApiErrorBody, type ApiErrorIssue, type AutoSettle, type Buyer, type CashierId, type CashierListItem, type ClassifierSearchItem, type ClassifierType, type CreateCashierInput, type CreateCashierResponse, type CreateDepartmentInput, type CreateDepartmentResponse, type CreateOfferInput, type CreateOfferInputProduct, type CreateOfferInputService, type CreateOfferResponse, type CreateOfferTitle, type CustomerPrepaymentBalance, DEFAULT_API_URL, DEFAULT_TIMEOUT_MS, type DepartmentInput, type DepartmentListItem, type Discounts, type ExchangeRate, type Language, type LegacyOfferTitle, type ListOffersFilter, type ListPrepaymentsFilter, type LocalizedName, type NewOffer, type Offer, type OfferListItem, type OfferTitle, type PrepaymentAmount, type PrepaymentDetail, type PrepaymentListItem, type PrepaymentState, REFUND_REASONS, type RefundAmount, type RefundItemInput, type RefundReason, type RegisterPrepaymentInput, type RegisterPrepaymentRefundInput, type RegisterPrepaymentRefundResponse, type RegisterPrepaymentResponse, type RegisterSaleInput, type RegisterSaleRefundInput, type RegisterSaleRefundResponse, type RegisterSaleResponse, type RequestOptions, type SaleAmount, type SaleData, type SaleDetail, type SaleItem, type SalePayment, type SearchClassifierInput, type SendReceiptToBuyer, TAX_REGIMES, type TaxRegime, type Unit, type UpdateOfferInput, VCRApiError, VCRClient, type VCRClientOptions, VCRError, VCRNetworkError, VCRValidationError, type Whoami, cashierListItemSchema, cashierListResponseSchema, classifierSearchItemSchema, classifierSearchResponseSchema, createCashierResponseSchema, createDepartmentResponseSchema, createOfferResponseSchema, customerPrepaymentBalanceResponseSchema, departmentListItemSchema, departmentListResponseSchema, exchangeRateResponseSchema, offerListItemSchema, offerListResponseSchema, prepaymentDetailResponseSchema, prepaymentListItemSchema, prepaymentListResponseSchema, prepaymentStateSchema, registerPrepaymentRefundResponseSchema, registerPrepaymentResponseSchema, registerSaleRefundResponseSchema, registerSaleResponseSchema, saleDetailResponseSchema, unitsKeys, whoamiResponseSchema };
1008
+ export { AVAILABLE_LANGUAGES, type ApiErrorBody, type ApiErrorIssue, type AutoSettle, type Buyer, type CashierId, type CashierListItem, type ClassifierSearchItem, type ClassifierType, type CreateCashierInput, type CreateCashierResponse, type CreateDepartmentInput, type CreateDepartmentResponse, type CreateOfferInput, type CreateOfferInputProduct, type CreateOfferInputService, type CreateOfferResponse, type CreateOfferTitle, type CustomerPrepaymentBalance, DEFAULT_API_URL, DEFAULT_TIMEOUT_MS, type DepartmentInput, type DepartmentListItem, type Discounts, type ExchangeRate, type Language, type LegacyOfferTitle, type ListOffersFilter, type ListPrepaymentsFilter, type LocalizedName, type NewOffer, type Offer, type OfferListItem, type OfferTitle, type PendingResource, type PrepaymentAmount, type PrepaymentDetail, type PrepaymentListItem, type PrepaymentState, REFUND_REASONS, type RefundAmount, type RefundItemInput, type RefundReason, type RegisterPrepaymentInput, type RegisterPrepaymentRefundInput, type RegisterPrepaymentRefundResponse, type RegisterPrepaymentResponse, type RegisterSaleInput, type RegisterSaleRefundInput, type RegisterSaleRefundResponse, type RegisterSaleResponse, type RequestOptions, type SaleAmount, type SaleData, type SaleDetail, type SaleItem, type SalePayment, type SearchClassifierInput, type SendReceiptToBuyer, type SrcStatus, TAX_REGIMES, type TaxRegime, type Unit, type UpdateOfferInput, VCRApiError, VCRClient, type VCRClientOptions, VCRError, VCRNetworkError, VCRValidationError, type Whoami, cashierListItemSchema, cashierListResponseSchema, classifierSearchItemSchema, classifierSearchResponseSchema, createCashierResponseSchema, createDepartmentResponseSchema, createOfferResponseSchema, customerPrepaymentBalanceResponseSchema, departmentListItemSchema, departmentListResponseSchema, exchangeRateResponseSchema, offerListItemSchema, offerListResponseSchema, prepaymentDetailResponseSchema, prepaymentListItemSchema, prepaymentListResponseSchema, prepaymentStateSchema, registerPrepaymentRefundResponseSchema, registerPrepaymentResponseSchema, registerSaleRefundResponseSchema, registerSaleResponseSchema, saleDetailResponseSchema, srcStatusSchema, unitsKeys, whoamiResponseSchema };