@blob-solutions/vcr-am-sdk 0.14.0 → 0.15.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/CHANGELOG.md CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
3
  All notable changes to `@blob-solutions/vcr-am-sdk`. The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project follows [Semantic Versioning](https://semver.org/).
4
4
 
5
+ ## [0.15.0] — 2026-07-09
6
+
7
+ Fixes the foreign-currency request contract, which 0.14.0 modeled incorrectly, and closes the last two gaps against `/api/v1` (`autoSettle` and `GET /exchange-rate`).
8
+
9
+ ### Fixed — foreign-currency contract (breaking, but 0.14.0's shape never worked)
10
+
11
+ - **Removed `RegisterSaleInput.currencyConversion` and the `CurrencyConversionInput` type.** The API never accepted a top-level `currencyConversion` block — `POST /sales` silently stripped it, so a "foreign-currency" sale sent via 0.14.0 was fiscalized with no HO-234-N conversion trail at all. The real contract is **per-item**: set `SaleItem.currency` (ISO 4217, e.g. `"USD"`) and denominate that item's `price` in the foreign currency; VCR converts every line to AMD server-side at the previous-business-day CBA rate. All foreign-priced items in one sale must share one currency, and mixing AMD with foreign lines is rejected.
12
+
13
+ ```diff
14
+ - items: [{ offer: { id: 5 }, department: { id: 1 }, quantity: "1", price: "4000", unit: "pc" }],
15
+ - currencyConversion: { currency: "USD", ratePerUnit: "400", rateDate: "2026-07-07", lines: [{ foreignUnitPrice: "10" }] },
16
+ - amount: { cash: "4000" },
17
+ + items: [{ offer: { id: 5 }, department: { id: 1 }, quantity: "1", price: "10", currency: "USD", unit: "pc" }],
18
+ + autoSettle: { tender: "cash" },
19
+ ```
20
+
21
+ ### Added
22
+
23
+ - `SaleItem.currency?: string` — per-item ISO 4217 input currency (see above). Omit or `"AMD"` for a native AMD line.
24
+ - `RegisterSaleInput.autoSettle?: { tender: "cash" | "nonCash" }` — derived-total payment: VCR computes the AMD cart total and charges the whole of it to one tender. A sale now carries **exactly one** of `amount` (explicit AMD) or `autoSettle`; the types enforce the XOR, mirroring the server's cross-field validation. The essential companion to foreign-currency sales, where the AMD total is not knowable client-side. New exported types `AutoSettle`, `SalePayment`.
25
+ - `getExchangeRate({ currency })` — wraps `GET /exchange-rate`. Previews the AMD conversion rate VCR would apply to a foreign-currency sale registered now (CBA mid-market rate, previous business day, HO-234-N). Read-only; rejects `AMD`. New type `ExchangeRate`, new schema `exchangeRateResponseSchema`.
26
+
27
+ ### Changed
28
+
29
+ - `RegisterSaleInput.amount` is no longer required on its own — it is one arm of the `amount` / `autoSettle` union. Existing `{ ..., amount }` call sites are unaffected.
30
+ - Dev tooling patch bumps (`@tsconfig/node24`, `@tsconfig/strictest`, `vite`). No change to the published package. TypeScript 7, pnpm 11, and `@types/node` 26 are available but intentionally deferred (kept aligned with the platform monorepo, which pins TypeScript 5.9).
31
+
5
32
  ## [0.14.0] — 2026-07-08
6
33
 
7
34
  Closes the drift that had accumulated against `/api/v1` since 0.13.0. Everything here is additive — no call-site changes required.
package/README.md CHANGED
@@ -125,23 +125,23 @@ const refund = await vcr.registerSaleRefund({
125
125
  });
126
126
  ```
127
127
 
128
+ **Payment: `amount` or `autoSettle`.** A sale settles by *exactly one* of these — never both (the types enforce it):
129
+
130
+ - `amount` — explicit AMD per tender (`{ cash?, nonCash?, prepayment?, compensation? }`), as in the quick-start.
131
+ - `autoSettle: { tender: "cash" | "nonCash" }` — VCR computes the AMD cart total and charges the whole of it to that one tender. Zero-tap: you don't sum the cart yourself, and it's the only sane option for a foreign-currency sale (you can't know the AMD total up front).
132
+
128
133
  **eMark codes** (marked goods, Govt Decision 1976-N) go on each sale item as `emarks: string[]`; the same codes are echoed on refund items.
129
134
 
130
- **Foreign-currency sales** (HO-234-N): pass a `currencyConversion` block alongside the AMD `items`. VCR re-resolves the previous-business-day CBA rate and rejects the sale if the rate you sent is stale. The AMD `price` values in `items[]` remain the authoritative fiscal figures.
135
+ **Foreign-currency sales** (HO-234-N): set `currency` on each item and price that item in the foreign currency. VCR converts every line to AMD server-side at the previous-business-day CBA mid-market rate; the fiscal receipt is always AMD. All foreign-priced items in one sale must share the same currency, and mixing AMD with foreign lines is rejected. Preview the rate first with [`getExchangeRate`](#exchange-rate).
131
136
 
132
137
  ```typescript
133
138
  await vcr.registerSale({
134
139
  cashier: { id: 1 },
135
140
  items: [
136
- { offer: { id: 5 }, department: { id: 1 }, quantity: "1", price: "4000", unit: "pc" },
141
+ // price is in USD; VCR converts to AMD.
142
+ { offer: { id: 5 }, department: { id: 1 }, quantity: "1", price: "10", currency: "USD", unit: "pc" },
137
143
  ],
138
- currencyConversion: {
139
- currency: "USD", // ISO 4217; not AMD
140
- ratePerUnit: "400", // AMD per 1 USD (CBA, previous business day)
141
- rateDate: "2026-07-07", // YYYY-MM-DD
142
- lines: [{ foreignUnitPrice: "10" }], // index-aligned to items[]
143
- },
144
- amount: { cash: "4000" },
144
+ autoSettle: { tender: "cash" }, // AMD total is server-derived
145
145
  buyer: { type: "individual" },
146
146
  });
147
147
  ```
@@ -212,6 +212,20 @@ const matches = await vcr.searchClassifier({
212
212
  });
213
213
  ```
214
214
 
215
+ ### Exchange rate
216
+
217
+ | Method | Endpoint | Returns |
218
+ | ----------------------------------- | -------------------- | -------------- |
219
+ | `getExchangeRate({ currency })` | `GET /exchange-rate` | `ExchangeRate` |
220
+
221
+ Previews the AMD conversion rate VCR would apply to a foreign-currency sale registered now — the CBA mid-market rate published on the previous business day (HO-234-N). Read-only; it does not fiscalize anything. `currency` is a 3-letter ISO 4217 code (case-insensitive); `AMD` is rejected.
222
+
223
+ ```typescript
224
+ const rate = await vcr.getExchangeRate({ currency: "USD" });
225
+ // { currency: "USD", ratePerUnit: 397.12, amount: 1, rateDate: "2026-07-08", ... }
226
+ const amdEquivalent = Number(usdPrice) * rate.ratePerUnit;
227
+ ```
228
+
215
229
  ## Error handling
216
230
 
217
231
  All SDK errors derive from `VCRError`. Catch the base class for a single handler, or narrow on the specific subclass.
@@ -262,7 +276,7 @@ The whole request flow — connection, body read, schema parse — is bounded by
262
276
 
263
277
  ## Idempotency and retries
264
278
 
265
- **The SDK does not retry.** This is intentional. The fiscal API does not currently support idempotency keys, so retrying a `registerSale` after a network blip can double-fiscalize a receipt. Implement application-level retry only on operations you have confirmed are safe to repeat (typically reads: `whoami`, `getSale`, `getPrepayment`, `listPrepayments`, `listCashiers`, `listOffers`, `getOffer`, `listDepartments`, `searchClassifier`).
279
+ **The SDK does not retry.** This is intentional. The fiscal API does not currently support idempotency keys, so retrying a `registerSale` after a network blip can double-fiscalize a receipt. Implement application-level retry only on operations you have confirmed are safe to repeat (typically reads: `whoami`, `getSale`, `getPrepayment`, `listPrepayments`, `listCashiers`, `listOffers`, `getOffer`, `listDepartments`, `searchClassifier`, `getExchangeRate`).
266
280
 
267
281
  ## Browser usage
268
282
 
package/lib/index.cjs CHANGED
@@ -155,6 +155,21 @@ var createDepartmentResponseSchema = zod.z.object({
155
155
  message: zod.z.string(),
156
156
  department: zod.z.number().int().nonnegative()
157
157
  });
158
+ var exchangeRateResponseSchema = zod.z.object({
159
+ /** ISO 4217 code, uppercased (echoes the requested currency). */
160
+ currency: zod.z.string(),
161
+ /** AMD per one unit of `currency` (CBA rate / amount). */
162
+ ratePerUnit: zod.z.number(),
163
+ /** CBA multi-lot multiplier (1, 100, 1000, ...). */
164
+ amount: zod.z.number().int(),
165
+ /** Yerevan date whose rate was applied — the previous business day. */
166
+ rateDate: zod.z.string(),
167
+ /** Yerevan calendar date the rate resolves for (server time). */
168
+ saleDate: zod.z.string(),
169
+ /** Legal rule version applied (e.g. "HO-234-N"). */
170
+ ruleVersion: zod.z.string(),
171
+ source: zod.z.literal("CBA")
172
+ });
158
173
  var whoamiResponseSchema = zod.z.object({
159
174
  vcrId: zod.z.number().int().nonnegative(),
160
175
  // `null` until the VCR is activated (freshly-imported registers have no CRN).
@@ -585,6 +600,23 @@ var VCRClient = class {
585
600
  searchClassifierCategory(query, type, language, options = {}) {
586
601
  return this.searchClassifier({ query, type, language }, options);
587
602
  }
603
+ // ─── Exchange rate ────────────────────────────────────────────────────────
604
+ /**
605
+ * Preview the AMD conversion rate VCR would apply to a foreign-currency sale
606
+ * registered now — the CBA mid-market rate published on the previous business
607
+ * day (Tax Code art. 16, HO-234-N). Use it to show a buyer the AMD equivalent
608
+ * before charging. The sale itself is converted server-side from each item's
609
+ * `currency` + `price` (see {@link RegisterSaleInput}); this endpoint is a
610
+ * read-only preview and does not fiscalize anything.
611
+ *
612
+ * `currency` is a 3-letter ISO 4217 code, case-insensitive. `AMD` is rejected
613
+ * (it is the native receipt currency and needs no conversion).
614
+ */
615
+ getExchangeRate(input, options = {}) {
616
+ return this.#json("GET", "/exchange-rate", exchangeRateResponseSchema, void 0, options, {
617
+ currency: input.currency
618
+ });
619
+ }
588
620
  // ─── Internal ─────────────────────────────────────────────────────────────
589
621
  #json(method, path, schema, body, options, query) {
590
622
  const url = query === void 0 ? `${this.#baseUrl}${path}` : appendQuery(`${this.#baseUrl}${path}`, query);
@@ -635,6 +667,7 @@ exports.createOfferResponseSchema = createOfferResponseSchema;
635
667
  exports.customerPrepaymentBalanceResponseSchema = customerPrepaymentBalanceResponseSchema;
636
668
  exports.departmentListItemSchema = departmentListItemSchema;
637
669
  exports.departmentListResponseSchema = departmentListResponseSchema;
670
+ exports.exchangeRateResponseSchema = exchangeRateResponseSchema;
638
671
  exports.offerListItemSchema = offerListItemSchema;
639
672
  exports.offerListResponseSchema = offerListResponseSchema;
640
673
  exports.prepaymentDetailResponseSchema = prepaymentDetailResponseSchema;
package/lib/index.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/constants.ts","../src/errors.ts","../src/schemas.ts","../src/fetch.ts","../src/client.ts"],"names":["z"],"mappings":";;;;;AAAO,IAAM,SAAA,GAAY;AAAA,EACvB,IAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,IAAA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AAA,IAAI,CAAC,MAAA,CAAO,SAAA,CAAU,KAAK,CAAA,IAAK,QAAQ,CAAA,EAAG;AACzC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,IAAI,CAAA,qCAAA,EAAwC,KAAK,CAAA,CAAA,CAAG,CAAA;AAAA,EACzE;AACF","file":"index.cjs","sourcesContent":["export const unitsKeys = [\n \"pc\",\n \"unit\",\n \"set\",\n \"box\",\n \"pack\",\n \"case\",\n \"hr\",\n \"sess\",\n \"proj\",\n \"sub\",\n \"kg\",\n \"l\",\n \"m\",\n \"g\",\n \"ml\",\n \"cm\",\n \"bottle\",\n \"can\",\n \"jar\",\n \"bag\",\n \"m2\",\n \"dozen\",\n \"pair\",\n \"mm\",\n \"roll\",\n \"tube\",\n \"km\",\n \"ton\",\n \"m3\",\n \"pallet\",\n \"other\",\n] as const;\n\nexport const AVAILABLE_LANGUAGES = [\"hy\", \"ru\", \"en\"] as const;\n\nexport const REFUND_REASONS = [\n \"customer_request\",\n \"defective_goods\",\n \"wrong_goods\",\n \"cashier_error\",\n \"duplicate_receipt\",\n \"other\",\n] as const;\n\nexport const TAX_REGIMES = [\"vat\", \"vat_exempt\", \"turnover_tax\", \"micro_enterprise\"] as const;\n\nexport const DEFAULT_API_URL = \"https://vcr.am/api/v1\";\nexport const DEFAULT_TIMEOUT_MS = 30_000;\n","import type { z } from \"zod\";\n\nexport type ApiErrorIssue = {\n path: Array<string | number>;\n message: string;\n code: string;\n};\n\nexport type ApiErrorBody = {\n error: string;\n issues?: Array<ApiErrorIssue>;\n /**\n * Server-generated correlation ID, present on unexpected 5xx responses.\n * Include it when reporting the issue to support so the matching log entry\n * and Sentry event can be located.\n */\n requestId?: string;\n};\n\n/**\n * Base class for every error thrown by the SDK.\n * Catch this if you want a single catch-all.\n */\nexport abstract class VCRError extends Error {\n abstract readonly kind: string;\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\n/**\n * Server returned a non-2xx response with a parseable JSON error body.\n * Mirrors the unified `{ error, issues? }` envelope from /api/v1.\n */\nexport class VCRApiError extends VCRError {\n readonly kind = \"api\" as const;\n\n constructor(\n readonly status: number,\n readonly body: ApiErrorBody,\n readonly url: string,\n ) {\n super(`VCR API ${status}: ${body.error}`);\n }\n}\n\n/**\n * Server returned a non-2xx response that did not match the error envelope,\n * or a 2xx response whose body did not match the expected schema.\n */\nexport class VCRValidationError extends VCRError {\n readonly kind = \"validation\" as const;\n\n constructor(\n message: string,\n readonly status: number,\n readonly url: string,\n readonly issues: z.ZodIssue[],\n readonly raw: unknown,\n ) {\n super(message);\n }\n}\n\n/**\n * Network-level failure: DNS, connection refused, timeout, abort.\n * The request never produced a parseable HTTP response.\n */\nexport class VCRNetworkError extends VCRError {\n readonly kind = \"network\" as const;\n\n constructor(\n message: string,\n readonly url: string,\n options: { cause: unknown },\n ) {\n super(message, options);\n }\n}\n","import { z } from \"zod\";\n\nimport { AVAILABLE_LANGUAGES, TAX_REGIMES, unitsKeys } from \"./constants\";\n\nexport const apiErrorBodySchema = z.object({\n error: z.string(),\n issues: z\n .array(\n z.object({\n path: z.array(z.union([z.string(), z.number()])),\n message: z.string(),\n code: z.string(),\n }),\n )\n .optional(),\n // Server-generated correlation ID present on unexpected 5xx responses.\n // Kept lenient (plain string, not `.uuid()`) so a malformed value can never\n // make the error envelope fail to parse and mask the real API error.\n requestId: z.string().optional(),\n});\n\nconst isoDateTimeSchema = z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/, \"Invalid ISO datetime\");\n\n// Detail responses use Prisma's `Language` enum, which is wider than\n// AVAILABLE_LANGUAGES — it also includes \"multi\" for cross-language content.\nconst detailLanguageSchema = z.enum([...AVAILABLE_LANGUAGES, \"multi\"]);\n\nconst localizationEntrySchema = z.object({\n id: z.number().int(),\n language: detailLanguageSchema,\n content: z.string(),\n});\n\nconst offerTypeSchema = z.enum([\"product\", \"service\"]);\nconst unitSchema = z.enum(unitsKeys);\nconst taxRegimeSchema = z.enum(TAX_REGIMES);\nconst discountTypeSchema = z.enum([\"percent\", \"price\", \"total\"]).nullable();\nconst additionalDiscountTypeSchema = z.enum([\"percent\", \"total\"]).nullable();\n\n// ─── Action responses ────────────────────────────────────────────────────────\n\nexport const registerSaleResponseSchema = z.object({\n urlId: z.string(),\n saleId: z.number().int().nonnegative(),\n crn: z.string(),\n srcReceiptId: z.number().int().nonnegative(),\n fiscal: z.string(),\n});\n\nexport const registerSaleRefundResponseSchema = z.object({\n urlId: z.string(),\n saleRefundId: z.number().int().nonnegative(),\n crn: z.string().nullable(),\n receiptId: z.number().int().nonnegative(),\n fiscal: z.string().nullable(),\n});\n\nexport const registerPrepaymentResponseSchema = z.object({\n urlId: z.string(),\n prepaymentId: z.number().int().nonnegative(),\n crn: z.string().nullable(),\n receiptId: z.number().int().nonnegative(),\n fiscal: z.string().nullable(),\n});\n\nexport const registerPrepaymentRefundResponseSchema = z.object({\n urlId: z.string(),\n prepaymentRefundId: z.number().int().nonnegative(),\n crn: z.string().nullable(),\n receiptId: z.number().int().nonnegative(),\n fiscal: z.string().nullable(),\n});\n\nexport const createOfferResponseSchema = z.object({\n offerId: z.number().int().nonnegative(),\n});\n\nexport const createCashierResponseSchema = z.object({\n id: z.number().int().nonnegative(),\n deskId: z.string(),\n});\n\nexport const createDepartmentResponseSchema = z.object({\n message: z.string(),\n department: z.number().int().nonnegative(),\n});\n\n// ─── Account ──────────────────────────────────────────────────────────────────\n\nexport const whoamiResponseSchema = z.object({\n vcrId: z.number().int().nonnegative(),\n // `null` until the VCR is activated (freshly-imported registers have no CRN).\n crn: z.string().nullable(),\n mode: z.enum([\"production\", \"sandbox\"]),\n tradingPlatformName: z.string(),\n businessEntity: z.object({\n tin: z.string(),\n name: z.string(),\n }),\n});\n\n// ─── List & search ──────────────────────────────────────────────────────────\n\nconst cashierNameLocalizationSchema = z.object({\n language: z.enum([...AVAILABLE_LANGUAGES, \"multi\"]),\n content: z.string(),\n});\n\nexport const cashierListItemSchema = z.object({\n deskId: z.string(),\n internalId: z.number().int().nonnegative(),\n name: z.record(z.string(), cashierNameLocalizationSchema),\n});\n\nexport const cashierListResponseSchema = z.array(cashierListItemSchema);\n\nexport const departmentListItemSchema = z.object({\n internalId: z.number().int().nonnegative(),\n externalId: z.string().nullable(),\n taxRegime: taxRegimeSchema,\n // Map from language code -> { language, content }, matching the wire\n // format produced by makeLocalizationObject on the server. May be empty\n // for legacy departments created before titles were mandatory.\n title: z.record(z.string(), localizationEntrySchema),\n});\n\nexport const departmentListResponseSchema = z.array(departmentListItemSchema);\n\nexport const classifierSearchItemSchema = z.object({\n code: z.string(),\n // Optional: server may emit `{ code }` without `title` when the classifier\n // entry exists in fuse but lacks a translation in the requested language.\n title: z.string().optional(),\n});\n\nexport const classifierSearchResponseSchema = z.array(classifierSearchItemSchema);\n\n// Offer list/detail rows carry their title as an array of localization\n// entries (matching the detail endpoints), NOT the language-keyed record used\n// by the cashier / department lists.\nexport const offerListItemSchema = z.object({\n id: z.number().int().nonnegative(),\n externalId: z.string().nullable(),\n type: offerTypeSchema,\n classifierCode: z.string(),\n // Server types this as a plain string (not the unit enum) to stay faithful\n // to whatever is stored; mirror it so a legacy unit can never fail parsing.\n defaultMeasureUnit: z.string(),\n defaultDepartment: z.object({ internalId: z.number().int().nonnegative() }),\n title: z.array(localizationEntrySchema),\n archivedAt: isoDateTimeSchema.nullable(),\n createdAt: isoDateTimeSchema,\n});\n\nexport const offerListResponseSchema = z.array(offerListItemSchema);\n\n// ─── Detail responses ───────────────────────────────────────────────────────\n//\n// Mirror the `pick + extend` shape produced by serializeForWire on the server.\n// Decimal columns (Prisma) arrive as numbers (z.number()), bigint as numeric\n// strings, and dates as ISO strings — matching the prisma-zod-generator output\n// the server validates against before responding.\n\nconst receiptPickSchema = z.object({\n srcId: z.number().int(),\n time: z.string().regex(/^\\d+$/, \"Invalid bigint string\"),\n tin: z.string(),\n fiscal: z.string().nullable(),\n sn: z.string(),\n address: z.string().nullable(),\n total: z.number(),\n taxpayer: z.string(),\n change: z.number(),\n});\n\nconst cashierPickSchema = z.object({\n internalId: z.number().int().nonnegative(),\n deskId: z.string(),\n name: z.array(localizationEntrySchema),\n});\n\nconst departmentPickSchema = z.object({\n internalId: z.number().int().nonnegative(),\n taxRegime: taxRegimeSchema,\n title: z.array(localizationEntrySchema),\n});\n\nconst offerPickSchema = z.object({\n type: offerTypeSchema,\n classifierCode: z.string(),\n title: z.array(localizationEntrySchema),\n});\n\nconst saleItemPickSchema = z.object({\n srcId: z.number().int(),\n quantity: z.number(),\n price: z.number(),\n unit: unitSchema,\n discount: z.number().nullable(),\n discountType: discountTypeSchema,\n additionalDiscount: z.number().nullable(),\n additionalDiscountType: additionalDiscountTypeSchema,\n department: departmentPickSchema,\n offer: offerPickSchema,\n});\n\nconst saleRefundPickSchema = z.object({\n nonCashAmount: z.number(),\n cashAmount: z.number(),\n receipt: receiptPickSchema.nullable(),\n items: z.array(z.object({ quantity: z.number() })),\n});\n\nexport const saleDetailResponseSchema = z.object({\n id: z.number().int().nonnegative(),\n createdAt: isoDateTimeSchema,\n buyerTin: z.string().nullable(),\n cashAmount: z.number(),\n nonCashAmount: z.number(),\n prepaymentAmount: z.number(),\n compensationAmount: z.number(),\n receipt: receiptPickSchema.nullable(),\n refunds: z.array(saleRefundPickSchema),\n cashier: cashierPickSchema,\n items: z.array(saleItemPickSchema),\n});\n\nconst prepaymentRefundPickSchema = z.object({\n nonCashAmount: z.number(),\n cashAmount: z.number(),\n receipt: receiptPickSchema.nullable(),\n});\n\n// `open` — remaining > 0; can still be applied or refunded.\n// `consumed` — fully applied to subsequent sales.\n// `refunded` — a PrepaymentRefund row exists (always full per AM Annex 3 §29).\nexport const prepaymentStateSchema = z.enum([\"open\", \"consumed\", \"refunded\"]);\n\nexport const prepaymentDetailResponseSchema = z.object({\n id: z.number().int().nonnegative(),\n createdAt: isoDateTimeSchema,\n buyerTin: z.string().nullable(),\n cashAmount: z.number(),\n nonCashAmount: z.number(),\n receipt: receiptPickSchema.nullable(),\n refund: prepaymentRefundPickSchema.nullable(),\n cashier: cashierPickSchema,\n /** SUM(amount) across all ledger rows for this prepayment. */\n remaining: z.number(),\n state: prepaymentStateSchema,\n});\n\nexport const prepaymentListItemSchema = z.object({\n id: z.number().int().nonnegative(),\n createdAt: isoDateTimeSchema,\n buyerTin: z.string().nullable(),\n cashAmount: z.number(),\n nonCashAmount: z.number(),\n remaining: z.number(),\n state: prepaymentStateSchema,\n});\n\nexport const prepaymentListResponseSchema = z.array(prepaymentListItemSchema);\n\nconst customerOpenPrepaymentSchema = z.object({\n prepaymentId: z.number().int().nonnegative(),\n createdAt: isoDateTimeSchema,\n cashAmount: z.number(),\n nonCashAmount: z.number(),\n buyerTin: z.string().nullable(),\n remaining: z.number(),\n});\n\nexport const customerPrepaymentBalanceResponseSchema = z.object({\n entityId: z.number().int().nonnegative(),\n customerRef: z.string(),\n /** Total remaining across all open prepayments matching customerRef. */\n balance: z.number(),\n /** FIFO-ordered open prepayments contributing to the balance. */\n openPrepayments: z.array(customerOpenPrepaymentSchema),\n});\n\n// ─── Inferred types ─────────────────────────────────────────────────────────\n\nexport type RegisterSaleResponse = z.infer<typeof registerSaleResponseSchema>;\nexport type RegisterSaleRefundResponse = z.infer<typeof registerSaleRefundResponseSchema>;\nexport type RegisterPrepaymentResponse = z.infer<typeof registerPrepaymentResponseSchema>;\nexport type RegisterPrepaymentRefundResponse = z.infer<\n typeof registerPrepaymentRefundResponseSchema\n>;\nexport type CreateOfferResponse = z.infer<typeof createOfferResponseSchema>;\nexport type CreateCashierResponse = z.infer<typeof createCashierResponseSchema>;\nexport type CreateDepartmentResponse = z.infer<typeof createDepartmentResponseSchema>;\nexport type CashierListItem = z.infer<typeof cashierListItemSchema>;\nexport type ClassifierSearchItem = z.infer<typeof classifierSearchItemSchema>;\nexport type Whoami = z.infer<typeof whoamiResponseSchema>;\nexport type OfferListItem = z.infer<typeof offerListItemSchema>;\nexport type SaleDetail = z.infer<typeof saleDetailResponseSchema>;\nexport type PrepaymentDetail = z.infer<typeof prepaymentDetailResponseSchema>;\nexport type PrepaymentListItem = z.infer<typeof prepaymentListItemSchema>;\nexport type PrepaymentState = z.infer<typeof prepaymentStateSchema>;\nexport type CustomerPrepaymentBalance = z.infer<typeof customerPrepaymentBalanceResponseSchema>;\nexport type DepartmentListItem = z.infer<typeof departmentListItemSchema>;\n","import type { z } from \"zod\";\n\nimport { type ApiErrorBody, VCRApiError, VCRNetworkError, VCRValidationError } from \"./errors\";\nimport { apiErrorBodySchema } from \"./schemas\";\n\nexport type RequestOptions = {\n signal?: AbortSignal;\n /** Override per-request timeout in ms. `null` disables the timeout. */\n timeoutMs?: number | null;\n};\n\nexport type FetchInit = {\n method: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n url: string;\n apiKey: string;\n body?: unknown;\n fetchImpl: typeof fetch;\n defaultTimeoutMs: number | null;\n} & RequestOptions;\n\nexport async function requestJson<TSchema extends z.ZodTypeAny>(\n schema: TSchema,\n init: FetchInit,\n): Promise<z.infer<TSchema>> {\n const { url, method, apiKey, body, fetchImpl, signal: externalSignal } = init;\n\n const effectiveTimeout = init.timeoutMs === undefined ? init.defaultTimeoutMs : init.timeoutMs;\n\n const timeoutController = effectiveTimeout !== null ? new AbortController() : undefined;\n const timeoutHandle =\n timeoutController !== undefined && effectiveTimeout !== null\n ? setTimeout(() => timeoutController.abort(new Error(\"Request timeout\")), effectiveTimeout)\n : undefined;\n\n const signal = mergeSignals(externalSignal, timeoutController?.signal);\n\n const headers: Record<string, string> = {\n \"x-api-key\": apiKey,\n accept: \"application/json\",\n };\n\n const requestInit: RequestInit = { method, headers };\n if (body !== undefined) {\n headers[\"content-type\"] = \"application/json\";\n requestInit.body = JSON.stringify(body);\n }\n if (signal !== undefined) {\n requestInit.signal = signal;\n }\n\n // The whole flow — connect, body read, parse — must be bounded by the same\n // timeout. Clearing the timer earlier (e.g. after fetch resolves) leaves\n // body reading and parsing unprotected against slow/hanging servers.\n try {\n let response: Response;\n let rawText: string;\n try {\n response = await fetchImpl(url, requestInit);\n rawText = await response.text();\n } catch (cause) {\n throw new VCRNetworkError(\n cause instanceof Error ? cause.message : \"Network request failed\",\n url,\n { cause },\n );\n }\n\n const rawJson = rawText.length === 0 ? undefined : safeJsonParse(rawText);\n\n if (!response.ok) {\n throw buildApiError(response.status, rawJson, url);\n }\n\n const parsed = schema.safeParse(rawJson);\n if (!parsed.success) {\n throw new VCRValidationError(\n `VCR response did not match expected schema for ${method} ${url}`,\n response.status,\n url,\n parsed.error.issues,\n rawJson,\n );\n }\n\n return parsed.data;\n } finally {\n if (timeoutHandle !== undefined) {\n clearTimeout(timeoutHandle);\n }\n }\n}\n\nfunction buildApiError(\n status: number,\n rawJson: unknown,\n url: string,\n): VCRApiError | VCRValidationError {\n const parsed = apiErrorBodySchema.safeParse(rawJson);\n if (parsed.success) {\n const body: ApiErrorBody = {\n error: parsed.data.error,\n ...(parsed.data.issues !== undefined && { issues: parsed.data.issues }),\n ...(parsed.data.requestId !== undefined && { requestId: parsed.data.requestId }),\n };\n return new VCRApiError(status, body, url);\n }\n\n return new VCRValidationError(\n `VCR returned ${status} but the error body did not match the expected envelope`,\n status,\n url,\n parsed.error.issues,\n rawJson,\n );\n}\n\nfunction safeJsonParse(text: string): unknown {\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n}\n\nfunction mergeSignals(...signals: ReadonlyArray<AbortSignal | undefined>): AbortSignal | undefined {\n const present = signals.filter((signal): signal is AbortSignal => signal !== undefined);\n if (present.length === 0) {\n return undefined;\n }\n return AbortSignal.any(present);\n}\n","import type { z } from \"zod\";\nimport { DEFAULT_API_URL, DEFAULT_TIMEOUT_MS } from \"./constants\";\nimport { type RequestOptions, requestJson } from \"./fetch\";\nimport {\n type CashierListItem,\n type ClassifierSearchItem,\n type CreateCashierResponse,\n type CreateDepartmentResponse,\n type CreateOfferResponse,\n type CustomerPrepaymentBalance,\n cashierListResponseSchema,\n classifierSearchResponseSchema,\n createCashierResponseSchema,\n createDepartmentResponseSchema,\n createOfferResponseSchema,\n customerPrepaymentBalanceResponseSchema,\n type DepartmentListItem,\n departmentListResponseSchema,\n type OfferListItem,\n offerListItemSchema,\n offerListResponseSchema,\n type PrepaymentDetail,\n type PrepaymentListItem,\n type PrepaymentState,\n prepaymentDetailResponseSchema,\n prepaymentListResponseSchema,\n type RegisterPrepaymentRefundResponse,\n type RegisterPrepaymentResponse,\n type RegisterSaleRefundResponse,\n type RegisterSaleResponse,\n registerPrepaymentRefundResponseSchema,\n registerPrepaymentResponseSchema,\n registerSaleRefundResponseSchema,\n registerSaleResponseSchema,\n type SaleDetail,\n saleDetailResponseSchema,\n type Whoami,\n whoamiResponseSchema,\n} from \"./schemas\";\nimport type {\n ClassifierType,\n CreateCashierInput,\n CreateDepartmentInput,\n CreateOfferInput,\n Language,\n ListOffersFilter,\n RegisterPrepaymentInput,\n RegisterPrepaymentRefundInput,\n RegisterSaleInput,\n RegisterSaleRefundInput,\n SearchClassifierInput,\n UpdateOfferInput,\n} from \"./types\";\n\nexport type ListPrepaymentsFilter = {\n /** Exact-match filter against ledger.customerRef (TIN / phone / email). */\n customerRef?: string;\n /**\n * Filter by derived lifecycle state. `all` (the default) returns every\n * prepayment; the other values filter to a single lifecycle stage.\n */\n state?: PrepaymentState | \"all\";\n};\n\nexport type VCRClientOptions = {\n /** Base URL for the VCR API. Defaults to https://vcr.am/api/v1. */\n baseUrl?: string;\n /** Custom fetch implementation. Defaults to the global `fetch`. */\n fetch?: typeof fetch;\n /** Default request timeout in ms. Pass `null` to disable. Default 30s. */\n timeoutMs?: number | null;\n};\n\ntype Method = \"GET\" | \"POST\" | \"PATCH\";\n\nexport class VCRClient {\n readonly #apiKey: string;\n readonly #baseUrl: string;\n readonly #fetch: typeof fetch;\n readonly #defaultTimeoutMs: number | null;\n\n constructor(apiKey: string, options: VCRClientOptions = {}) {\n if (apiKey.length === 0) {\n throw new Error(\"VCRClient requires a non-empty apiKey\");\n }\n this.#apiKey = apiKey;\n this.#baseUrl = stripTrailingSlash(options.baseUrl ?? DEFAULT_API_URL);\n\n const candidate = options.fetch ?? globalThis.fetch;\n if (typeof candidate !== \"function\") {\n throw new Error(\n \"No fetch implementation available. Provide options.fetch or use a runtime that exposes a global fetch.\",\n );\n }\n // Only bind the global fetch, which on some runtimes requires `this ===\n // globalThis`. A user-supplied fetch keeps its own `this` so wrappers\n // (e.g. class methods, fetch with closure state) keep working.\n this.#fetch = options.fetch === undefined ? candidate.bind(globalThis) : candidate;\n\n this.#defaultTimeoutMs =\n options.timeoutMs === undefined ? DEFAULT_TIMEOUT_MS : options.timeoutMs;\n }\n\n // ─── Account ──────────────────────────────────────────────────────────────\n\n /**\n * Resolve which VCR the calling API key belongs to. Returns the register's\n * identity, its `mode` (`production` / `sandbox`), and the owning business\n * entity. Works on freshly-imported VCRs that have not been activated yet\n * (in which case `crn` is `null`) — handy as a cheap SDK health-check and to\n * tell production keys apart from sandbox ones.\n */\n whoami(options: RequestOptions = {}): Promise<Whoami> {\n return this.#json(\"GET\", \"/whoami\", whoamiResponseSchema, undefined, options);\n }\n\n // ─── Sales ─────────────────────────────────────────────────────────────────\n\n registerSale(\n data: RegisterSaleInput,\n options: RequestOptions = {},\n ): Promise<RegisterSaleResponse> {\n return this.#json(\"POST\", \"/sales\", registerSaleResponseSchema, data, options);\n }\n\n getSale(saleId: number, options: RequestOptions = {}): Promise<SaleDetail> {\n assertNonNegativeInt(saleId, \"saleId\");\n return this.#json(\"GET\", `/sales/${saleId}`, saleDetailResponseSchema, undefined, options);\n }\n\n registerSaleRefund(\n data: RegisterSaleRefundInput,\n options: RequestOptions = {},\n ): Promise<RegisterSaleRefundResponse> {\n return this.#json(\"POST\", \"/sales/refund\", registerSaleRefundResponseSchema, data, options);\n }\n\n // ─── Prepayments ──────────────────────────────────────────────────────────\n\n registerPrepayment(\n data: RegisterPrepaymentInput,\n options: RequestOptions = {},\n ): Promise<RegisterPrepaymentResponse> {\n return this.#json(\"POST\", \"/prepayments\", registerPrepaymentResponseSchema, data, options);\n }\n\n getPrepayment(prepaymentId: number, options: RequestOptions = {}): Promise<PrepaymentDetail> {\n assertNonNegativeInt(prepaymentId, \"prepaymentId\");\n return this.#json(\n \"GET\",\n `/prepayments/${prepaymentId}`,\n prepaymentDetailResponseSchema,\n undefined,\n options,\n );\n }\n\n registerPrepaymentRefund(\n data: RegisterPrepaymentRefundInput,\n options: RequestOptions = {},\n ): Promise<RegisterPrepaymentRefundResponse> {\n return this.#json(\n \"POST\",\n \"/prepayments/refund\",\n registerPrepaymentRefundResponseSchema,\n data,\n options,\n );\n }\n\n /**\n * List prepayments registered through the calling VCR. Server caps the\n * response at 500 rows; for larger sets, narrow with `customerRef` or\n * paginate by `id` outside the SDK.\n *\n * `remaining` and `state` are derived from the ledger — call this whenever\n * you want a current snapshot rather than caching the result.\n */\n listPrepayments(\n filter: ListPrepaymentsFilter = {},\n options: RequestOptions = {},\n ): Promise<PrepaymentListItem[]> {\n const query: Record<string, string> = {};\n if (filter.customerRef !== undefined) query[\"customerRef\"] = filter.customerRef;\n if (filter.state !== undefined) query[\"state\"] = filter.state;\n return this.#json(\n \"GET\",\n \"/prepayments\",\n prepaymentListResponseSchema,\n undefined,\n options,\n Object.keys(query).length > 0 ? query : undefined,\n );\n }\n\n /**\n * Get a customer's open prepayment balance scoped to the BusinessEntity\n * that owns the calling VCR's API key. Because the ledger is entity-scoped,\n * the result reflects deposits made through any VCR belonging to the same\n * entity — merchants who run more than one VCR see a single wallet.\n *\n * `customerRef` is matched exactly against the ledger — typically a TIN,\n * normalized E.164 phone, or lowercased email. Use whichever identifier the\n * customer gave at deposit time; identities are not auto-merged across\n * different ref types.\n */\n getCustomerPrepaymentBalance(\n input: { customerRef: string },\n options: RequestOptions = {},\n ): Promise<CustomerPrepaymentBalance> {\n return this.#json(\n \"GET\",\n \"/prepayments/balance\",\n customerPrepaymentBalanceResponseSchema,\n undefined,\n options,\n { customerRef: input.customerRef },\n );\n }\n\n // ─── Cashiers ─────────────────────────────────────────────────────────────\n\n listCashiers(options: RequestOptions = {}): Promise<CashierListItem[]> {\n return this.#json(\"GET\", \"/cashiers\", cashierListResponseSchema, undefined, options);\n }\n\n createCashier(\n data: CreateCashierInput,\n options: RequestOptions = {},\n ): Promise<CreateCashierResponse> {\n return this.#json(\"POST\", \"/cashiers\", createCashierResponseSchema, data, options);\n }\n\n // ─── Offers / Departments ─────────────────────────────────────────────────\n\n createOffer(data: CreateOfferInput, options: RequestOptions = {}): Promise<CreateOfferResponse> {\n return this.#json(\"POST\", \"/offers\", createOfferResponseSchema, data, options);\n }\n\n /**\n * List offers belonging to the calling VCR. Server caps the response at 500\n * rows; narrow with `externalId` / `type` for larger catalogs. Archived\n * offers are excluded unless `includeArchived` is set.\n *\n * A common use is checking whether an offer already exists (by `externalId`)\n * before creating it.\n */\n listOffers(\n filter: ListOffersFilter = {},\n options: RequestOptions = {},\n ): Promise<OfferListItem[]> {\n const query: Record<string, string> = {};\n if (filter.externalId !== undefined) query[\"externalId\"] = filter.externalId;\n if (filter.type !== undefined) query[\"type\"] = filter.type;\n if (filter.includeArchived !== undefined) {\n query[\"includeArchived\"] = filter.includeArchived ? \"true\" : \"false\";\n }\n return this.#json(\n \"GET\",\n \"/offers\",\n offerListResponseSchema,\n undefined,\n options,\n Object.keys(query).length > 0 ? query : undefined,\n );\n }\n\n getOffer(offerId: number, options: RequestOptions = {}): Promise<OfferListItem> {\n assertNonNegativeInt(offerId, \"offerId\");\n return this.#json(\"GET\", `/offers/${offerId}`, offerListItemSchema, undefined, options);\n }\n\n /**\n * Rename an offer's title. Affects only future receipts — already-issued\n * receipts keep the title they were created with, and the SRC fiscal record\n * is unchanged. Missing `en`/`ru` are filled per `localizationStrategy`,\n * exactly as on offer creation. Returns the updated offer.\n */\n updateOffer(\n offerId: number,\n data: UpdateOfferInput,\n options: RequestOptions = {},\n ): Promise<OfferListItem> {\n assertNonNegativeInt(offerId, \"offerId\");\n return this.#json(\"PATCH\", `/offers/${offerId}`, offerListItemSchema, data, options);\n }\n\n createDepartment(\n data: CreateDepartmentInput,\n options: RequestOptions = {},\n ): Promise<CreateDepartmentResponse> {\n return this.#json(\"POST\", \"/departments\", createDepartmentResponseSchema, data, options);\n }\n\n /**\n * List departments configured on the calling VCR — `internalId`,\n * `externalId`, `taxRegime`, and the localized `title`. Mirrors the\n * dashboard catalog: only departments confirmed by the tax service are\n * returned, so the `internalId` field is safe to reference from a sale\n * item's `department.id`.\n */\n listDepartments(options: RequestOptions = {}): Promise<DepartmentListItem[]> {\n return this.#json(\"GET\", \"/departments\", departmentListResponseSchema, undefined, options);\n }\n\n // ─── Classifier search ────────────────────────────────────────────────────\n\n searchClassifier(\n input: SearchClassifierInput,\n options: RequestOptions = {},\n ): Promise<ClassifierSearchItem[]> {\n return this.#json(\n \"GET\",\n \"/searchByClassifier\",\n classifierSearchResponseSchema,\n undefined,\n options,\n { query: input.query, type: input.type, language: input.language },\n );\n }\n\n /**\n * @deprecated Use {@link searchClassifier} with an options object. Will be\n * removed in 1.0. The new signature accepts `{ query, type, language }` so\n * future params can be added without breaking the call site.\n */\n searchClassifierCategory(\n query: string,\n type: ClassifierType,\n language: Language,\n options: RequestOptions = {},\n ): Promise<ClassifierSearchItem[]> {\n return this.searchClassifier({ query, type, language }, options);\n }\n\n // ─── Internal ─────────────────────────────────────────────────────────────\n\n #json<TSchema extends z.ZodTypeAny>(\n method: Method,\n path: string,\n schema: TSchema,\n body: unknown,\n options: RequestOptions,\n query?: Record<string, string>,\n ): Promise<z.infer<TSchema>> {\n const url =\n query === undefined\n ? `${this.#baseUrl}${path}`\n : appendQuery(`${this.#baseUrl}${path}`, query);\n\n return requestJson(schema, {\n method,\n url,\n apiKey: this.#apiKey,\n ...(body !== undefined && { body }),\n fetchImpl: this.#fetch,\n defaultTimeoutMs: this.#defaultTimeoutMs,\n ...options,\n });\n }\n}\n\nfunction appendQuery(url: string, query: Record<string, string>): string {\n const u = new URL(url);\n for (const [key, value] of Object.entries(query)) {\n u.searchParams.set(key, value);\n }\n return u.toString();\n}\n\nfunction stripTrailingSlash(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\nfunction assertNonNegativeInt(value: number, name: string): void {\n if (!Number.isInteger(value) || value < 0) {\n throw new Error(`${name} must be a non-negative integer (got ${value})`);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/constants.ts","../src/errors.ts","../src/schemas.ts","../src/fetch.ts","../src/client.ts"],"names":["z"],"mappings":";;;;;AAAO,IAAM,SAAA,GAAY;AAAA,EACvB,IAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,IAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,IAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA,GAAA;AAAA,EACA,IAAA;AAAA,EACA,IAAA;AAAA,EACA,QAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,IAAA;AAAA,EACA,OAAA;AAAA,EACA,MAAA;AAAA,EACA,IAAA;AAAA,EACA,MAAA;AAAA,EACA,MAAA;AAAA,EACA,IAAA;AAAA,EACA,KAAA;AAAA,EACA,IAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF;AAEO,IAAM,mBAAA,GAAsB,CAAC,IAAA,EAAM,IAAA,EAAM,IAAI;AAE7C,IAAM,cAAA,GAAiB;AAAA,EAC5B,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,aAAA;AAAA,EACA,eAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF;AAEO,IAAM,WAAA,GAAc,CAAC,KAAA,EAAO,YAAA,EAAc,gBAAgB,kBAAkB;AAE5E,IAAM,eAAA,GAAkB;AACxB,IAAM,kBAAA,GAAqB;;;ACzB3B,IAAe,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AC,MAAA,CAAO,SAAA,CAAU,KAAK,CAAA,IAAK,QAAQ,CAAA,EAAG;AACzC,IAAA,MAAM,IAAI,KAAA,CAAM,CAAA,EAAG,IAAI,CAAA,qCAAA,EAAwC,KAAK,CAAA,CAAA,CAAG,CAAA;AAAA,EACzE;AACF","file":"index.cjs","sourcesContent":["export const unitsKeys = [\n \"pc\",\n \"unit\",\n \"set\",\n \"box\",\n \"pack\",\n \"case\",\n \"hr\",\n \"sess\",\n \"proj\",\n \"sub\",\n \"kg\",\n \"l\",\n \"m\",\n \"g\",\n \"ml\",\n \"cm\",\n \"bottle\",\n \"can\",\n \"jar\",\n \"bag\",\n \"m2\",\n \"dozen\",\n \"pair\",\n \"mm\",\n \"roll\",\n \"tube\",\n \"km\",\n \"ton\",\n \"m3\",\n \"pallet\",\n \"other\",\n] as const;\n\nexport const AVAILABLE_LANGUAGES = [\"hy\", \"ru\", \"en\"] as const;\n\nexport const REFUND_REASONS = [\n \"customer_request\",\n \"defective_goods\",\n \"wrong_goods\",\n \"cashier_error\",\n \"duplicate_receipt\",\n \"other\",\n] as const;\n\nexport const TAX_REGIMES = [\"vat\", \"vat_exempt\", \"turnover_tax\", \"micro_enterprise\"] as const;\n\nexport const DEFAULT_API_URL = \"https://vcr.am/api/v1\";\nexport const DEFAULT_TIMEOUT_MS = 30_000;\n","import type { z } from \"zod\";\n\nexport type ApiErrorIssue = {\n path: Array<string | number>;\n message: string;\n code: string;\n};\n\nexport type ApiErrorBody = {\n error: string;\n issues?: Array<ApiErrorIssue>;\n /**\n * Server-generated correlation ID, present on unexpected 5xx responses.\n * Include it when reporting the issue to support so the matching log entry\n * and Sentry event can be located.\n */\n requestId?: string;\n};\n\n/**\n * Base class for every error thrown by the SDK.\n * Catch this if you want a single catch-all.\n */\nexport abstract class VCRError extends Error {\n abstract readonly kind: string;\n\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options);\n this.name = new.target.name;\n }\n}\n\n/**\n * Server returned a non-2xx response with a parseable JSON error body.\n * Mirrors the unified `{ error, issues? }` envelope from /api/v1.\n */\nexport class VCRApiError extends VCRError {\n readonly kind = \"api\" as const;\n\n constructor(\n readonly status: number,\n readonly body: ApiErrorBody,\n readonly url: string,\n ) {\n super(`VCR API ${status}: ${body.error}`);\n }\n}\n\n/**\n * Server returned a non-2xx response that did not match the error envelope,\n * or a 2xx response whose body did not match the expected schema.\n */\nexport class VCRValidationError extends VCRError {\n readonly kind = \"validation\" as const;\n\n constructor(\n message: string,\n readonly status: number,\n readonly url: string,\n readonly issues: z.ZodIssue[],\n readonly raw: unknown,\n ) {\n super(message);\n }\n}\n\n/**\n * Network-level failure: DNS, connection refused, timeout, abort.\n * The request never produced a parseable HTTP response.\n */\nexport class VCRNetworkError extends VCRError {\n readonly kind = \"network\" as const;\n\n constructor(\n message: string,\n readonly url: string,\n options: { cause: unknown },\n ) {\n super(message, options);\n }\n}\n","import { z } from \"zod\";\n\nimport { AVAILABLE_LANGUAGES, TAX_REGIMES, unitsKeys } from \"./constants\";\n\nexport const apiErrorBodySchema = z.object({\n error: z.string(),\n issues: z\n .array(\n z.object({\n path: z.array(z.union([z.string(), z.number()])),\n message: z.string(),\n code: z.string(),\n }),\n )\n .optional(),\n // Server-generated correlation ID present on unexpected 5xx responses.\n // Kept lenient (plain string, not `.uuid()`) so a malformed value can never\n // make the error envelope fail to parse and mask the real API error.\n requestId: z.string().optional(),\n});\n\nconst isoDateTimeSchema = z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/, \"Invalid ISO datetime\");\n\n// Detail responses use Prisma's `Language` enum, which is wider than\n// AVAILABLE_LANGUAGES — it also includes \"multi\" for cross-language content.\nconst detailLanguageSchema = z.enum([...AVAILABLE_LANGUAGES, \"multi\"]);\n\nconst localizationEntrySchema = z.object({\n id: z.number().int(),\n language: detailLanguageSchema,\n content: z.string(),\n});\n\nconst offerTypeSchema = z.enum([\"product\", \"service\"]);\nconst unitSchema = z.enum(unitsKeys);\nconst taxRegimeSchema = z.enum(TAX_REGIMES);\nconst discountTypeSchema = z.enum([\"percent\", \"price\", \"total\"]).nullable();\nconst additionalDiscountTypeSchema = z.enum([\"percent\", \"total\"]).nullable();\n\n// ─── Action responses ────────────────────────────────────────────────────────\n\nexport const registerSaleResponseSchema = z.object({\n urlId: z.string(),\n saleId: z.number().int().nonnegative(),\n crn: z.string(),\n srcReceiptId: z.number().int().nonnegative(),\n fiscal: z.string(),\n});\n\nexport const registerSaleRefundResponseSchema = z.object({\n urlId: z.string(),\n saleRefundId: z.number().int().nonnegative(),\n crn: z.string().nullable(),\n receiptId: z.number().int().nonnegative(),\n fiscal: z.string().nullable(),\n});\n\nexport const registerPrepaymentResponseSchema = z.object({\n urlId: z.string(),\n prepaymentId: z.number().int().nonnegative(),\n crn: z.string().nullable(),\n receiptId: z.number().int().nonnegative(),\n fiscal: z.string().nullable(),\n});\n\nexport const registerPrepaymentRefundResponseSchema = z.object({\n urlId: z.string(),\n prepaymentRefundId: z.number().int().nonnegative(),\n crn: z.string().nullable(),\n receiptId: z.number().int().nonnegative(),\n fiscal: z.string().nullable(),\n});\n\nexport const createOfferResponseSchema = z.object({\n offerId: z.number().int().nonnegative(),\n});\n\nexport const createCashierResponseSchema = z.object({\n id: z.number().int().nonnegative(),\n deskId: z.string(),\n});\n\nexport const createDepartmentResponseSchema = z.object({\n message: z.string(),\n department: z.number().int().nonnegative(),\n});\n\n// ─── Exchange rate ────────────────────────────────────────────────────────────\n\n// Mirrors the server's ExchangeRate response. `rateDate` / `saleDate` are kept\n// as plain strings (not a date-format regex) so a wire value can never make the\n// response fail to parse — the server already guarantees `YYYY-MM-DD`.\nexport const exchangeRateResponseSchema = z.object({\n /** ISO 4217 code, uppercased (echoes the requested currency). */\n currency: z.string(),\n /** AMD per one unit of `currency` (CBA rate / amount). */\n ratePerUnit: z.number(),\n /** CBA multi-lot multiplier (1, 100, 1000, ...). */\n amount: z.number().int(),\n /** Yerevan date whose rate was applied — the previous business day. */\n rateDate: z.string(),\n /** Yerevan calendar date the rate resolves for (server time). */\n saleDate: z.string(),\n /** Legal rule version applied (e.g. \"HO-234-N\"). */\n ruleVersion: z.string(),\n source: z.literal(\"CBA\"),\n});\n\n// ─── Account ──────────────────────────────────────────────────────────────────\n\nexport const whoamiResponseSchema = z.object({\n vcrId: z.number().int().nonnegative(),\n // `null` until the VCR is activated (freshly-imported registers have no CRN).\n crn: z.string().nullable(),\n mode: z.enum([\"production\", \"sandbox\"]),\n tradingPlatformName: z.string(),\n businessEntity: z.object({\n tin: z.string(),\n name: z.string(),\n }),\n});\n\n// ─── List & search ──────────────────────────────────────────────────────────\n\nconst cashierNameLocalizationSchema = z.object({\n language: z.enum([...AVAILABLE_LANGUAGES, \"multi\"]),\n content: z.string(),\n});\n\nexport const cashierListItemSchema = z.object({\n deskId: z.string(),\n internalId: z.number().int().nonnegative(),\n name: z.record(z.string(), cashierNameLocalizationSchema),\n});\n\nexport const cashierListResponseSchema = z.array(cashierListItemSchema);\n\nexport const departmentListItemSchema = z.object({\n internalId: z.number().int().nonnegative(),\n externalId: z.string().nullable(),\n taxRegime: taxRegimeSchema,\n // Map from language code -> { language, content }, matching the wire\n // format produced by makeLocalizationObject on the server. May be empty\n // for legacy departments created before titles were mandatory.\n title: z.record(z.string(), localizationEntrySchema),\n});\n\nexport const departmentListResponseSchema = z.array(departmentListItemSchema);\n\nexport const classifierSearchItemSchema = z.object({\n code: z.string(),\n // Optional: server may emit `{ code }` without `title` when the classifier\n // entry exists in fuse but lacks a translation in the requested language.\n title: z.string().optional(),\n});\n\nexport const classifierSearchResponseSchema = z.array(classifierSearchItemSchema);\n\n// Offer list/detail rows carry their title as an array of localization\n// entries (matching the detail endpoints), NOT the language-keyed record used\n// by the cashier / department lists.\nexport const offerListItemSchema = z.object({\n id: z.number().int().nonnegative(),\n externalId: z.string().nullable(),\n type: offerTypeSchema,\n classifierCode: z.string(),\n // Server types this as a plain string (not the unit enum) to stay faithful\n // to whatever is stored; mirror it so a legacy unit can never fail parsing.\n defaultMeasureUnit: z.string(),\n defaultDepartment: z.object({ internalId: z.number().int().nonnegative() }),\n title: z.array(localizationEntrySchema),\n archivedAt: isoDateTimeSchema.nullable(),\n createdAt: isoDateTimeSchema,\n});\n\nexport const offerListResponseSchema = z.array(offerListItemSchema);\n\n// ─── Detail responses ───────────────────────────────────────────────────────\n//\n// Mirror the `pick + extend` shape produced by serializeForWire on the server.\n// Decimal columns (Prisma) arrive as numbers (z.number()), bigint as numeric\n// strings, and dates as ISO strings — matching the prisma-zod-generator output\n// the server validates against before responding.\n\nconst receiptPickSchema = z.object({\n srcId: z.number().int(),\n time: z.string().regex(/^\\d+$/, \"Invalid bigint string\"),\n tin: z.string(),\n fiscal: z.string().nullable(),\n sn: z.string(),\n address: z.string().nullable(),\n total: z.number(),\n taxpayer: z.string(),\n change: z.number(),\n});\n\nconst cashierPickSchema = z.object({\n internalId: z.number().int().nonnegative(),\n deskId: z.string(),\n name: z.array(localizationEntrySchema),\n});\n\nconst departmentPickSchema = z.object({\n internalId: z.number().int().nonnegative(),\n taxRegime: taxRegimeSchema,\n title: z.array(localizationEntrySchema),\n});\n\nconst offerPickSchema = z.object({\n type: offerTypeSchema,\n classifierCode: z.string(),\n title: z.array(localizationEntrySchema),\n});\n\nconst saleItemPickSchema = z.object({\n srcId: z.number().int(),\n quantity: z.number(),\n price: z.number(),\n unit: unitSchema,\n discount: z.number().nullable(),\n discountType: discountTypeSchema,\n additionalDiscount: z.number().nullable(),\n additionalDiscountType: additionalDiscountTypeSchema,\n department: departmentPickSchema,\n offer: offerPickSchema,\n});\n\nconst saleRefundPickSchema = z.object({\n nonCashAmount: z.number(),\n cashAmount: z.number(),\n receipt: receiptPickSchema.nullable(),\n items: z.array(z.object({ quantity: z.number() })),\n});\n\nexport const saleDetailResponseSchema = z.object({\n id: z.number().int().nonnegative(),\n createdAt: isoDateTimeSchema,\n buyerTin: z.string().nullable(),\n cashAmount: z.number(),\n nonCashAmount: z.number(),\n prepaymentAmount: z.number(),\n compensationAmount: z.number(),\n receipt: receiptPickSchema.nullable(),\n refunds: z.array(saleRefundPickSchema),\n cashier: cashierPickSchema,\n items: z.array(saleItemPickSchema),\n});\n\nconst prepaymentRefundPickSchema = z.object({\n nonCashAmount: z.number(),\n cashAmount: z.number(),\n receipt: receiptPickSchema.nullable(),\n});\n\n// `open` — remaining > 0; can still be applied or refunded.\n// `consumed` — fully applied to subsequent sales.\n// `refunded` — a PrepaymentRefund row exists (always full per AM Annex 3 §29).\nexport const prepaymentStateSchema = z.enum([\"open\", \"consumed\", \"refunded\"]);\n\nexport const prepaymentDetailResponseSchema = z.object({\n id: z.number().int().nonnegative(),\n createdAt: isoDateTimeSchema,\n buyerTin: z.string().nullable(),\n cashAmount: z.number(),\n nonCashAmount: z.number(),\n receipt: receiptPickSchema.nullable(),\n refund: prepaymentRefundPickSchema.nullable(),\n cashier: cashierPickSchema,\n /** SUM(amount) across all ledger rows for this prepayment. */\n remaining: z.number(),\n state: prepaymentStateSchema,\n});\n\nexport const prepaymentListItemSchema = z.object({\n id: z.number().int().nonnegative(),\n createdAt: isoDateTimeSchema,\n buyerTin: z.string().nullable(),\n cashAmount: z.number(),\n nonCashAmount: z.number(),\n remaining: z.number(),\n state: prepaymentStateSchema,\n});\n\nexport const prepaymentListResponseSchema = z.array(prepaymentListItemSchema);\n\nconst customerOpenPrepaymentSchema = z.object({\n prepaymentId: z.number().int().nonnegative(),\n createdAt: isoDateTimeSchema,\n cashAmount: z.number(),\n nonCashAmount: z.number(),\n buyerTin: z.string().nullable(),\n remaining: z.number(),\n});\n\nexport const customerPrepaymentBalanceResponseSchema = z.object({\n entityId: z.number().int().nonnegative(),\n customerRef: z.string(),\n /** Total remaining across all open prepayments matching customerRef. */\n balance: z.number(),\n /** FIFO-ordered open prepayments contributing to the balance. */\n openPrepayments: z.array(customerOpenPrepaymentSchema),\n});\n\n// ─── Inferred types ─────────────────────────────────────────────────────────\n\nexport type RegisterSaleResponse = z.infer<typeof registerSaleResponseSchema>;\nexport type RegisterSaleRefundResponse = z.infer<typeof registerSaleRefundResponseSchema>;\nexport type RegisterPrepaymentResponse = z.infer<typeof registerPrepaymentResponseSchema>;\nexport type RegisterPrepaymentRefundResponse = z.infer<\n typeof registerPrepaymentRefundResponseSchema\n>;\nexport type CreateOfferResponse = z.infer<typeof createOfferResponseSchema>;\nexport type CreateCashierResponse = z.infer<typeof createCashierResponseSchema>;\nexport type CreateDepartmentResponse = z.infer<typeof createDepartmentResponseSchema>;\nexport type CashierListItem = z.infer<typeof cashierListItemSchema>;\nexport type ClassifierSearchItem = z.infer<typeof classifierSearchItemSchema>;\nexport type Whoami = z.infer<typeof whoamiResponseSchema>;\nexport type OfferListItem = z.infer<typeof offerListItemSchema>;\nexport type SaleDetail = z.infer<typeof saleDetailResponseSchema>;\nexport type PrepaymentDetail = z.infer<typeof prepaymentDetailResponseSchema>;\nexport type PrepaymentListItem = z.infer<typeof prepaymentListItemSchema>;\nexport type PrepaymentState = z.infer<typeof prepaymentStateSchema>;\nexport type CustomerPrepaymentBalance = z.infer<typeof customerPrepaymentBalanceResponseSchema>;\nexport type DepartmentListItem = z.infer<typeof departmentListItemSchema>;\nexport type ExchangeRate = z.infer<typeof exchangeRateResponseSchema>;\n","import type { z } from \"zod\";\n\nimport { type ApiErrorBody, VCRApiError, VCRNetworkError, VCRValidationError } from \"./errors\";\nimport { apiErrorBodySchema } from \"./schemas\";\n\nexport type RequestOptions = {\n signal?: AbortSignal;\n /** Override per-request timeout in ms. `null` disables the timeout. */\n timeoutMs?: number | null;\n};\n\nexport type FetchInit = {\n method: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n url: string;\n apiKey: string;\n body?: unknown;\n fetchImpl: typeof fetch;\n defaultTimeoutMs: number | null;\n} & RequestOptions;\n\nexport async function requestJson<TSchema extends z.ZodTypeAny>(\n schema: TSchema,\n init: FetchInit,\n): Promise<z.infer<TSchema>> {\n const { url, method, apiKey, body, fetchImpl, signal: externalSignal } = init;\n\n const effectiveTimeout = init.timeoutMs === undefined ? init.defaultTimeoutMs : init.timeoutMs;\n\n const timeoutController = effectiveTimeout !== null ? new AbortController() : undefined;\n const timeoutHandle =\n timeoutController !== undefined && effectiveTimeout !== null\n ? setTimeout(() => timeoutController.abort(new Error(\"Request timeout\")), effectiveTimeout)\n : undefined;\n\n const signal = mergeSignals(externalSignal, timeoutController?.signal);\n\n const headers: Record<string, string> = {\n \"x-api-key\": apiKey,\n accept: \"application/json\",\n };\n\n const requestInit: RequestInit = { method, headers };\n if (body !== undefined) {\n headers[\"content-type\"] = \"application/json\";\n requestInit.body = JSON.stringify(body);\n }\n if (signal !== undefined) {\n requestInit.signal = signal;\n }\n\n // The whole flow — connect, body read, parse — must be bounded by the same\n // timeout. Clearing the timer earlier (e.g. after fetch resolves) leaves\n // body reading and parsing unprotected against slow/hanging servers.\n try {\n let response: Response;\n let rawText: string;\n try {\n response = await fetchImpl(url, requestInit);\n rawText = await response.text();\n } catch (cause) {\n throw new VCRNetworkError(\n cause instanceof Error ? cause.message : \"Network request failed\",\n url,\n { cause },\n );\n }\n\n const rawJson = rawText.length === 0 ? undefined : safeJsonParse(rawText);\n\n if (!response.ok) {\n throw buildApiError(response.status, rawJson, url);\n }\n\n const parsed = schema.safeParse(rawJson);\n if (!parsed.success) {\n throw new VCRValidationError(\n `VCR response did not match expected schema for ${method} ${url}`,\n response.status,\n url,\n parsed.error.issues,\n rawJson,\n );\n }\n\n return parsed.data;\n } finally {\n if (timeoutHandle !== undefined) {\n clearTimeout(timeoutHandle);\n }\n }\n}\n\nfunction buildApiError(\n status: number,\n rawJson: unknown,\n url: string,\n): VCRApiError | VCRValidationError {\n const parsed = apiErrorBodySchema.safeParse(rawJson);\n if (parsed.success) {\n const body: ApiErrorBody = {\n error: parsed.data.error,\n ...(parsed.data.issues !== undefined && { issues: parsed.data.issues }),\n ...(parsed.data.requestId !== undefined && { requestId: parsed.data.requestId }),\n };\n return new VCRApiError(status, body, url);\n }\n\n return new VCRValidationError(\n `VCR returned ${status} but the error body did not match the expected envelope`,\n status,\n url,\n parsed.error.issues,\n rawJson,\n );\n}\n\nfunction safeJsonParse(text: string): unknown {\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n}\n\nfunction mergeSignals(...signals: ReadonlyArray<AbortSignal | undefined>): AbortSignal | undefined {\n const present = signals.filter((signal): signal is AbortSignal => signal !== undefined);\n if (present.length === 0) {\n return undefined;\n }\n return AbortSignal.any(present);\n}\n","import type { z } from \"zod\";\nimport { DEFAULT_API_URL, DEFAULT_TIMEOUT_MS } from \"./constants\";\nimport { type RequestOptions, requestJson } from \"./fetch\";\nimport {\n type CashierListItem,\n type ClassifierSearchItem,\n type CreateCashierResponse,\n type CreateDepartmentResponse,\n type CreateOfferResponse,\n type CustomerPrepaymentBalance,\n cashierListResponseSchema,\n classifierSearchResponseSchema,\n createCashierResponseSchema,\n createDepartmentResponseSchema,\n createOfferResponseSchema,\n customerPrepaymentBalanceResponseSchema,\n type DepartmentListItem,\n departmentListResponseSchema,\n type ExchangeRate,\n exchangeRateResponseSchema,\n type OfferListItem,\n offerListItemSchema,\n offerListResponseSchema,\n type PrepaymentDetail,\n type PrepaymentListItem,\n type PrepaymentState,\n prepaymentDetailResponseSchema,\n prepaymentListResponseSchema,\n type RegisterPrepaymentRefundResponse,\n type RegisterPrepaymentResponse,\n type RegisterSaleRefundResponse,\n type RegisterSaleResponse,\n registerPrepaymentRefundResponseSchema,\n registerPrepaymentResponseSchema,\n registerSaleRefundResponseSchema,\n registerSaleResponseSchema,\n type SaleDetail,\n saleDetailResponseSchema,\n type Whoami,\n whoamiResponseSchema,\n} from \"./schemas\";\nimport type {\n ClassifierType,\n CreateCashierInput,\n CreateDepartmentInput,\n CreateOfferInput,\n Language,\n ListOffersFilter,\n RegisterPrepaymentInput,\n RegisterPrepaymentRefundInput,\n RegisterSaleInput,\n RegisterSaleRefundInput,\n SearchClassifierInput,\n UpdateOfferInput,\n} from \"./types\";\n\nexport type ListPrepaymentsFilter = {\n /** Exact-match filter against ledger.customerRef (TIN / phone / email). */\n customerRef?: string;\n /**\n * Filter by derived lifecycle state. `all` (the default) returns every\n * prepayment; the other values filter to a single lifecycle stage.\n */\n state?: PrepaymentState | \"all\";\n};\n\nexport type VCRClientOptions = {\n /** Base URL for the VCR API. Defaults to https://vcr.am/api/v1. */\n baseUrl?: string;\n /** Custom fetch implementation. Defaults to the global `fetch`. */\n fetch?: typeof fetch;\n /** Default request timeout in ms. Pass `null` to disable. Default 30s. */\n timeoutMs?: number | null;\n};\n\ntype Method = \"GET\" | \"POST\" | \"PATCH\";\n\nexport class VCRClient {\n readonly #apiKey: string;\n readonly #baseUrl: string;\n readonly #fetch: typeof fetch;\n readonly #defaultTimeoutMs: number | null;\n\n constructor(apiKey: string, options: VCRClientOptions = {}) {\n if (apiKey.length === 0) {\n throw new Error(\"VCRClient requires a non-empty apiKey\");\n }\n this.#apiKey = apiKey;\n this.#baseUrl = stripTrailingSlash(options.baseUrl ?? DEFAULT_API_URL);\n\n const candidate = options.fetch ?? globalThis.fetch;\n if (typeof candidate !== \"function\") {\n throw new Error(\n \"No fetch implementation available. Provide options.fetch or use a runtime that exposes a global fetch.\",\n );\n }\n // Only bind the global fetch, which on some runtimes requires `this ===\n // globalThis`. A user-supplied fetch keeps its own `this` so wrappers\n // (e.g. class methods, fetch with closure state) keep working.\n this.#fetch = options.fetch === undefined ? candidate.bind(globalThis) : candidate;\n\n this.#defaultTimeoutMs =\n options.timeoutMs === undefined ? DEFAULT_TIMEOUT_MS : options.timeoutMs;\n }\n\n // ─── Account ──────────────────────────────────────────────────────────────\n\n /**\n * Resolve which VCR the calling API key belongs to. Returns the register's\n * identity, its `mode` (`production` / `sandbox`), and the owning business\n * entity. Works on freshly-imported VCRs that have not been activated yet\n * (in which case `crn` is `null`) — handy as a cheap SDK health-check and to\n * tell production keys apart from sandbox ones.\n */\n whoami(options: RequestOptions = {}): Promise<Whoami> {\n return this.#json(\"GET\", \"/whoami\", whoamiResponseSchema, undefined, options);\n }\n\n // ─── Sales ─────────────────────────────────────────────────────────────────\n\n registerSale(\n data: RegisterSaleInput,\n options: RequestOptions = {},\n ): Promise<RegisterSaleResponse> {\n return this.#json(\"POST\", \"/sales\", registerSaleResponseSchema, data, options);\n }\n\n getSale(saleId: number, options: RequestOptions = {}): Promise<SaleDetail> {\n assertNonNegativeInt(saleId, \"saleId\");\n return this.#json(\"GET\", `/sales/${saleId}`, saleDetailResponseSchema, undefined, options);\n }\n\n registerSaleRefund(\n data: RegisterSaleRefundInput,\n options: RequestOptions = {},\n ): Promise<RegisterSaleRefundResponse> {\n return this.#json(\"POST\", \"/sales/refund\", registerSaleRefundResponseSchema, data, options);\n }\n\n // ─── Prepayments ──────────────────────────────────────────────────────────\n\n registerPrepayment(\n data: RegisterPrepaymentInput,\n options: RequestOptions = {},\n ): Promise<RegisterPrepaymentResponse> {\n return this.#json(\"POST\", \"/prepayments\", registerPrepaymentResponseSchema, data, options);\n }\n\n getPrepayment(prepaymentId: number, options: RequestOptions = {}): Promise<PrepaymentDetail> {\n assertNonNegativeInt(prepaymentId, \"prepaymentId\");\n return this.#json(\n \"GET\",\n `/prepayments/${prepaymentId}`,\n prepaymentDetailResponseSchema,\n undefined,\n options,\n );\n }\n\n registerPrepaymentRefund(\n data: RegisterPrepaymentRefundInput,\n options: RequestOptions = {},\n ): Promise<RegisterPrepaymentRefundResponse> {\n return this.#json(\n \"POST\",\n \"/prepayments/refund\",\n registerPrepaymentRefundResponseSchema,\n data,\n options,\n );\n }\n\n /**\n * List prepayments registered through the calling VCR. Server caps the\n * response at 500 rows; for larger sets, narrow with `customerRef` or\n * paginate by `id` outside the SDK.\n *\n * `remaining` and `state` are derived from the ledger — call this whenever\n * you want a current snapshot rather than caching the result.\n */\n listPrepayments(\n filter: ListPrepaymentsFilter = {},\n options: RequestOptions = {},\n ): Promise<PrepaymentListItem[]> {\n const query: Record<string, string> = {};\n if (filter.customerRef !== undefined) query[\"customerRef\"] = filter.customerRef;\n if (filter.state !== undefined) query[\"state\"] = filter.state;\n return this.#json(\n \"GET\",\n \"/prepayments\",\n prepaymentListResponseSchema,\n undefined,\n options,\n Object.keys(query).length > 0 ? query : undefined,\n );\n }\n\n /**\n * Get a customer's open prepayment balance scoped to the BusinessEntity\n * that owns the calling VCR's API key. Because the ledger is entity-scoped,\n * the result reflects deposits made through any VCR belonging to the same\n * entity — merchants who run more than one VCR see a single wallet.\n *\n * `customerRef` is matched exactly against the ledger — typically a TIN,\n * normalized E.164 phone, or lowercased email. Use whichever identifier the\n * customer gave at deposit time; identities are not auto-merged across\n * different ref types.\n */\n getCustomerPrepaymentBalance(\n input: { customerRef: string },\n options: RequestOptions = {},\n ): Promise<CustomerPrepaymentBalance> {\n return this.#json(\n \"GET\",\n \"/prepayments/balance\",\n customerPrepaymentBalanceResponseSchema,\n undefined,\n options,\n { customerRef: input.customerRef },\n );\n }\n\n // ─── Cashiers ─────────────────────────────────────────────────────────────\n\n listCashiers(options: RequestOptions = {}): Promise<CashierListItem[]> {\n return this.#json(\"GET\", \"/cashiers\", cashierListResponseSchema, undefined, options);\n }\n\n createCashier(\n data: CreateCashierInput,\n options: RequestOptions = {},\n ): Promise<CreateCashierResponse> {\n return this.#json(\"POST\", \"/cashiers\", createCashierResponseSchema, data, options);\n }\n\n // ─── Offers / Departments ─────────────────────────────────────────────────\n\n createOffer(data: CreateOfferInput, options: RequestOptions = {}): Promise<CreateOfferResponse> {\n return this.#json(\"POST\", \"/offers\", createOfferResponseSchema, data, options);\n }\n\n /**\n * List offers belonging to the calling VCR. Server caps the response at 500\n * rows; narrow with `externalId` / `type` for larger catalogs. Archived\n * offers are excluded unless `includeArchived` is set.\n *\n * A common use is checking whether an offer already exists (by `externalId`)\n * before creating it.\n */\n listOffers(\n filter: ListOffersFilter = {},\n options: RequestOptions = {},\n ): Promise<OfferListItem[]> {\n const query: Record<string, string> = {};\n if (filter.externalId !== undefined) query[\"externalId\"] = filter.externalId;\n if (filter.type !== undefined) query[\"type\"] = filter.type;\n if (filter.includeArchived !== undefined) {\n query[\"includeArchived\"] = filter.includeArchived ? \"true\" : \"false\";\n }\n return this.#json(\n \"GET\",\n \"/offers\",\n offerListResponseSchema,\n undefined,\n options,\n Object.keys(query).length > 0 ? query : undefined,\n );\n }\n\n getOffer(offerId: number, options: RequestOptions = {}): Promise<OfferListItem> {\n assertNonNegativeInt(offerId, \"offerId\");\n return this.#json(\"GET\", `/offers/${offerId}`, offerListItemSchema, undefined, options);\n }\n\n /**\n * Rename an offer's title. Affects only future receipts — already-issued\n * receipts keep the title they were created with, and the SRC fiscal record\n * is unchanged. Missing `en`/`ru` are filled per `localizationStrategy`,\n * exactly as on offer creation. Returns the updated offer.\n */\n updateOffer(\n offerId: number,\n data: UpdateOfferInput,\n options: RequestOptions = {},\n ): Promise<OfferListItem> {\n assertNonNegativeInt(offerId, \"offerId\");\n return this.#json(\"PATCH\", `/offers/${offerId}`, offerListItemSchema, data, options);\n }\n\n createDepartment(\n data: CreateDepartmentInput,\n options: RequestOptions = {},\n ): Promise<CreateDepartmentResponse> {\n return this.#json(\"POST\", \"/departments\", createDepartmentResponseSchema, data, options);\n }\n\n /**\n * List departments configured on the calling VCR — `internalId`,\n * `externalId`, `taxRegime`, and the localized `title`. Mirrors the\n * dashboard catalog: only departments confirmed by the tax service are\n * returned, so the `internalId` field is safe to reference from a sale\n * item's `department.id`.\n */\n listDepartments(options: RequestOptions = {}): Promise<DepartmentListItem[]> {\n return this.#json(\"GET\", \"/departments\", departmentListResponseSchema, undefined, options);\n }\n\n // ─── Classifier search ────────────────────────────────────────────────────\n\n searchClassifier(\n input: SearchClassifierInput,\n options: RequestOptions = {},\n ): Promise<ClassifierSearchItem[]> {\n return this.#json(\n \"GET\",\n \"/searchByClassifier\",\n classifierSearchResponseSchema,\n undefined,\n options,\n { query: input.query, type: input.type, language: input.language },\n );\n }\n\n /**\n * @deprecated Use {@link searchClassifier} with an options object. Will be\n * removed in 1.0. The new signature accepts `{ query, type, language }` so\n * future params can be added without breaking the call site.\n */\n searchClassifierCategory(\n query: string,\n type: ClassifierType,\n language: Language,\n options: RequestOptions = {},\n ): Promise<ClassifierSearchItem[]> {\n return this.searchClassifier({ query, type, language }, options);\n }\n\n // ─── Exchange rate ────────────────────────────────────────────────────────\n\n /**\n * Preview the AMD conversion rate VCR would apply to a foreign-currency sale\n * registered now — the CBA mid-market rate published on the previous business\n * day (Tax Code art. 16, HO-234-N). Use it to show a buyer the AMD equivalent\n * before charging. The sale itself is converted server-side from each item's\n * `currency` + `price` (see {@link RegisterSaleInput}); this endpoint is a\n * read-only preview and does not fiscalize anything.\n *\n * `currency` is a 3-letter ISO 4217 code, case-insensitive. `AMD` is rejected\n * (it is the native receipt currency and needs no conversion).\n */\n getExchangeRate(\n input: { currency: string },\n options: RequestOptions = {},\n ): Promise<ExchangeRate> {\n return this.#json(\"GET\", \"/exchange-rate\", exchangeRateResponseSchema, undefined, options, {\n currency: input.currency,\n });\n }\n\n // ─── Internal ─────────────────────────────────────────────────────────────\n\n #json<TSchema extends z.ZodTypeAny>(\n method: Method,\n path: string,\n schema: TSchema,\n body: unknown,\n options: RequestOptions,\n query?: Record<string, string>,\n ): Promise<z.infer<TSchema>> {\n const url =\n query === undefined\n ? `${this.#baseUrl}${path}`\n : appendQuery(`${this.#baseUrl}${path}`, query);\n\n return requestJson(schema, {\n method,\n url,\n apiKey: this.#apiKey,\n ...(body !== undefined && { body }),\n fetchImpl: this.#fetch,\n defaultTimeoutMs: this.#defaultTimeoutMs,\n ...options,\n });\n }\n}\n\nfunction appendQuery(url: string, query: Record<string, string>): string {\n const u = new URL(url);\n for (const [key, value] of Object.entries(query)) {\n u.searchParams.set(key, value);\n }\n return u.toString();\n}\n\nfunction stripTrailingSlash(url: string): string {\n return url.endsWith(\"/\") ? url.slice(0, -1) : url;\n}\n\nfunction assertNonNegativeInt(value: number, name: string): void {\n if (!Number.isInteger(value) || value < 0) {\n throw new Error(`${name} must be a non-negative integer (got ${value})`);\n }\n}\n"]}
package/lib/index.d.cts CHANGED
@@ -45,6 +45,15 @@ declare const createDepartmentResponseSchema: z.ZodObject<{
45
45
  message: z.ZodString;
46
46
  department: z.ZodNumber;
47
47
  }, z.core.$strip>;
48
+ declare const exchangeRateResponseSchema: z.ZodObject<{
49
+ currency: z.ZodString;
50
+ ratePerUnit: z.ZodNumber;
51
+ amount: z.ZodNumber;
52
+ rateDate: z.ZodString;
53
+ saleDate: z.ZodString;
54
+ ruleVersion: z.ZodString;
55
+ source: z.ZodLiteral<"CBA">;
56
+ }, z.core.$strip>;
48
57
  declare const whoamiResponseSchema: z.ZodObject<{
49
58
  vcrId: z.ZodNumber;
50
59
  crn: z.ZodNullable<z.ZodString>;
@@ -433,6 +442,7 @@ type PrepaymentListItem = z.infer<typeof prepaymentListItemSchema>;
433
442
  type PrepaymentState = z.infer<typeof prepaymentStateSchema>;
434
443
  type CustomerPrepaymentBalance = z.infer<typeof customerPrepaymentBalanceResponseSchema>;
435
444
  type DepartmentListItem = z.infer<typeof departmentListItemSchema>;
445
+ type ExchangeRate = z.infer<typeof exchangeRateResponseSchema>;
436
446
 
437
447
  declare const unitsKeys: readonly ["pc", "unit", "set", "box", "pack", "case", "hr", "sess", "proj", "sub", "kg", "l", "m", "g", "ml", "cm", "bottle", "can", "jar", "bag", "m2", "dozen", "pair", "mm", "roll", "tube", "km", "ton", "m3", "pallet", "other"];
438
448
  declare const AVAILABLE_LANGUAGES: readonly ["hy", "ru", "en"];
@@ -527,7 +537,27 @@ type SaleItem = {
527
537
  offer: Offer;
528
538
  department: DepartmentInput;
529
539
  quantity: string;
540
+ /**
541
+ * Unit price. AMD by default. When {@link SaleItem.currency} is set to a
542
+ * non-AMD code, this value is denominated in that foreign currency and VCR
543
+ * converts it to AMD server-side at the authoritative CBA rate — never send
544
+ * a pre-converted AMD figure alongside a `currency`.
545
+ */
530
546
  price: string;
547
+ /**
548
+ * Optional ISO 4217 input currency for foreign-currency sales (HO-234-N,
549
+ * server-side conversion). Omit — or set to `"AMD"` — for a native AMD line.
550
+ *
551
+ * When set to a non-AMD code (e.g. `"USD"`, `"RUB"`), `price` is read in that
552
+ * currency and VCR converts every line to AMD at the previous-business-day
553
+ * CBA mid-market rate; the fiscal receipt is always issued in AMD. All
554
+ * foreign-priced items in one sale MUST share the same currency — mixing two
555
+ * currencies, or AMD and foreign lines, in a single sale is rejected. Pair
556
+ * with `autoSettle` (see {@link RegisterSaleInput}) so you don't have to know
557
+ * the AMD total up front, and preview the applied rate via
558
+ * {@link VCRClient.getExchangeRate}. Normalized to uppercase server-side.
559
+ */
560
+ currency?: string;
531
561
  unit: Unit;
532
562
  discounts?: Discounts;
533
563
  totalAmountTolerance?: string;
@@ -537,27 +567,6 @@ type SaleItem = {
537
567
  */
538
568
  emarks?: string[];
539
569
  };
540
- /**
541
- * Foreign-currency input trail (HO-234-N). Present only when the sale was
542
- * entered in a non-AMD currency; omit it entirely for native-AMD sales.
543
- *
544
- * The AMD `price` values in `items[]` remain the authoritative fiscal figures.
545
- * This block carries the raw foreign inputs plus the CBA rate the client used;
546
- * the server re-resolves the previous-business-day rate and rejects the sale
547
- * if the supplied rate is stale.
548
- */
549
- type CurrencyConversionInput = {
550
- /** 3-letter ISO 4217 code (normalized to uppercase server-side). Not AMD. */
551
- currency: string;
552
- /** AMD per one unit of `currency` (CBA rate / amount). */
553
- ratePerUnit: string;
554
- /** Rate date in `YYYY-MM-DD` (CBA previous business day). */
555
- rateDate: string;
556
- /** Per-line foreign unit prices, index-aligned to `items[]`. At least one. */
557
- lines: Array<{
558
- foreignUnitPrice: string;
559
- }>;
560
- };
561
570
  type SaleAmount = RequireAtLeastOne<{
562
571
  prepayment?: string;
563
572
  compensation?: string;
@@ -594,17 +603,37 @@ type LegalEntityBuyer = BuyerContact & {
594
603
  receipt?: SendReceiptToBuyer;
595
604
  };
596
605
  type Buyer = IndividualBuyer | LegalEntityBuyer;
606
+ /**
607
+ * Derived-total payment: name a single tender and VCR settles the whole
608
+ * server-computed AMD cart total on it. Only `cash` / `nonCash` — `prepayment`
609
+ * and `compensation` are ledger draws that must be stated explicitly via
610
+ * {@link SaleAmount}. Ideal for foreign-currency sales (the AMD total isn't
611
+ * known client-side) or any sale that would rather not sum the cart itself.
612
+ */
613
+ type AutoSettle = {
614
+ tender: "cash" | "nonCash";
615
+ };
616
+ /** Explicit AMD amount per tender. Mutually exclusive with `autoSettle`. */
617
+ type PayByAmount = {
618
+ amount: SaleAmount;
619
+ autoSettle?: never;
620
+ };
621
+ /** VCR derives the AMD total onto one tender. Mutually exclusive with `amount`. */
622
+ type PayByAutoSettle = {
623
+ autoSettle: AutoSettle;
624
+ amount?: never;
625
+ };
626
+ /**
627
+ * A sale settles EITHER by explicit `amount` OR by `autoSettle` — exactly one,
628
+ * never both. The `never` guards make passing both a compile error, mirroring
629
+ * the server's cross-field validation.
630
+ */
631
+ type SalePayment = PayByAmount | PayByAutoSettle;
597
632
  type RegisterSaleInput = {
598
633
  cashier: CashierId;
599
634
  items: SaleItem[];
600
- /**
601
- * Optional foreign-currency input. Absent => native-AMD sale, byte-identical
602
- * to the pre-existing behaviour. See {@link CurrencyConversionInput}.
603
- */
604
- currencyConversion?: CurrencyConversionInput;
605
- amount: SaleAmount;
606
635
  buyer: Buyer;
607
- };
636
+ } & SalePayment;
608
637
  /** @deprecated Use {@link RegisterSaleInput} instead. Will be removed in 1.0. */
609
638
  type SaleData = RegisterSaleInput;
610
639
  type ClassifierType = "product" | "service";
@@ -807,6 +836,20 @@ declare class VCRClient {
807
836
  * future params can be added without breaking the call site.
808
837
  */
809
838
  searchClassifierCategory(query: string, type: ClassifierType, language: Language, options?: RequestOptions): Promise<ClassifierSearchItem[]>;
839
+ /**
840
+ * Preview the AMD conversion rate VCR would apply to a foreign-currency sale
841
+ * registered now — the CBA mid-market rate published on the previous business
842
+ * day (Tax Code art. 16, HO-234-N). Use it to show a buyer the AMD equivalent
843
+ * before charging. The sale itself is converted server-side from each item's
844
+ * `currency` + `price` (see {@link RegisterSaleInput}); this endpoint is a
845
+ * read-only preview and does not fiscalize anything.
846
+ *
847
+ * `currency` is a 3-letter ISO 4217 code, case-insensitive. `AMD` is rejected
848
+ * (it is the native receipt currency and needs no conversion).
849
+ */
850
+ getExchangeRate(input: {
851
+ currency: string;
852
+ }, options?: RequestOptions): Promise<ExchangeRate>;
810
853
  }
811
854
 
812
855
  type ApiErrorIssue = {
@@ -869,4 +912,4 @@ declare class VCRNetworkError extends VCRError {
869
912
  });
870
913
  }
871
914
 
872
- export { AVAILABLE_LANGUAGES, type ApiErrorBody, type ApiErrorIssue, 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 CurrencyConversionInput, type CustomerPrepaymentBalance, DEFAULT_API_URL, DEFAULT_TIMEOUT_MS, type DepartmentInput, type DepartmentListItem, type Discounts, 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 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, offerListItemSchema, offerListResponseSchema, prepaymentDetailResponseSchema, prepaymentListItemSchema, prepaymentListResponseSchema, prepaymentStateSchema, registerPrepaymentRefundResponseSchema, registerPrepaymentResponseSchema, registerSaleRefundResponseSchema, registerSaleResponseSchema, saleDetailResponseSchema, unitsKeys, whoamiResponseSchema };
915
+ 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 };