@tallyui/core 5.0.0 → 5.1.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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as IceServer, D as DisplayAdvertisement, O as OrderFilterField, L as ListOrdersQuery, V as VariantSummary, C as CommandWarning, P as ProductTraits, S as StockReconcileAdapter, a as StockLevel, R as ReplicationAdapter, b as SyncContext, T as TallyConnector, c as TraitContext, d as CustomerTraits, M as MoneyFormat, e as Money, f as CalculateTaxesInput, g as CalculateTaxesResult, W as WooTaxRate, h as ItemizedTax, i as ResolvedTaxLocation, j as TAX_BASED_ON_META_KEY, k as TaxAddress, l as TaxBasedOn, m as TaxLocationOrder, n as normalizeTaxBasedOn, o as orderTaxLocation } from './refund-share-BZ_Ff9Zk.js';
2
- export { A as AnyCommandEnvelope, p as ApproverCredentials, q as AuthField, B as BatchTooLargeBody, r as CASHIER_PERMISSIONS, s as COMMANDS_PATH, t as CaptureMode, u as CaptureModeEntry, v as Cashier, w as CashierPermission, x as CatalogueReconcileAdapter, y as CatalogueReconcileEntry, z as ClosureReads, E as CollectionSync, F as CommandBatchRequest, G as CommandBatchResponse, H as CommandEnvelope, J as CommandError, K as CommandResult, N as CommandResultError, Q as CommandServerRefs, U as CommandStatus, X as CommandType, Y as ConnectivityState, Z as ConnectorAuth, _ as ConnectorSchemas, $ as ConnectorTraits, a0 as Correction, a1 as Customer, a2 as CustomerAddress, a3 as CustomerInput, a4 as CustomerPage, a5 as CustomerPatch, a6 as CustomerServiceError, a7 as CustomerTaxId, a8 as DISPLAY_PAIR_CAPABILITY, a9 as DisplayRecord, aa as DisplaySignalling, ab as DisplaySignallingContext, ac as DisplaySignallingError, ad as DisplaySignallingErrorCode, ae as EarlierRefund, af as FailureClass, ag as FingerprintReconcileAdapter, ah as IdReconcileAdapter, ai as ListRefundsQuery, aj as MAX_COMMANDS_PER_BATCH, ak as NEEDS_ADMIN_MESSAGE_MAX, al as ORDER_LINE_SKU_MAX, am as ORDER_META_KEY_MAX, an as ORDER_META_MAX, ao as ORDER_NOTE_MAX, ap as ORDER_TAX_IDS_MAX, aq as ORDER_TAX_ID_TYPE_MAX, ar as ORDER_TAX_ID_VALUE_MAX, as as OrderAddress, at as OrderCreateCoupon, au as OrderCreateCouponInvalidData, av as OrderCreateCouponLine, aw as OrderCreateDisplay, ax as OrderCreateEnvelope, ay as OrderCreateLine, az as OrderCreateMeta, aA as OrderCreatePayload, aB as OrderCreatePayment, aC as OrderCreateTaxId, aD as OrderCreateTaxRate, aE as OrderCreateTotalMismatchData, aF as OrderRefundAmountMismatchData, aG as OrderRefundEnvelope, aH as OrderRefundLine, aI as OrderRefundNoOpenSessionData, aJ as OrderRefundOrderStateData, aK as OrderRefundPayload, aL as OrderRefundQuantityExceedsData, aM as OrderRefundRejectionCode, aN as OrderRefundResult, aO as OrderReopenEnvelope, aP as OrderReopenOrderStateData, aQ as OrderReopenPayload, aR as OrderReopenPaymentInMotionData, aS as OrderReopenRejectionCode, aT as OrderReopenResult, aU as OrderUpdateEnvelope, aV as OrderUpdateFee, aW as OrderUpdateLine, aX as OrderUpdatePayload, aY as OrderUpdatePayment, aZ as OrderUpdateRejectionCode, a_ as OrderUpdateReopenRequiredData, a$ as OrderUpdateShipping, b0 as PROTOCOL_HEADER, b1 as PROTOCOL_VERSION, b2 as PaymentHardware, b3 as PaymentKind, b4 as PaymentMethodDescriptor, b5 as PaymentMethodKind, b6 as PaymentOfflineMode, b7 as PaymentRounding, b8 as PaymentTipsMode, b9 as PaymentTransport, ba as PendingPairing, bb as PricedRefund, bc as PricedRefundLine, bd as ProductCategory, be as ProductPrice, bf as ProductTerm, bg as ReceiptTemplate, bh as ReceiptTemplateKind, bi as RefundableLine, bj as RefundableOrderLine, bk as RegisterApprovalInvalidData, bl as RegisterApprovalRequiredData, bm as RegisterClosureSubmitPayload, bn as RegisterCommandEnvelope, bo as RegisterCommandResult, bp as RegisterCommandType, bq as RegisterInfo, br as RegisterMovementRecordPayload, bs as RegisterMovementVoidPayload, bt as RegisterSessionAlreadyOpenData, bu as RegisterSessionOpenPayload, bv as RegisterSessionSupersededData, bw as RegisterSessionTransitionPayload, bx as RemoteIdEntry, by as ResolvedPrice, bz as RoundingMode, bA as ServerCapabilities, bB as SignInResult, bC as SignalMessage, bD as StockStatus, bE as StoreClosure, bF as StoreOrder, bG as StoreOrderCharge, bH as StoreOrderLine, bI as StoreOrderPage, bJ as StoreOrderPayment, bK as StoreOrderRefund, bL as StoreOrderRefundLine, bM as StoreRefund, bN as StoreRefundOrphan, bO as StoreRefundPage, bP as StoreSettings, bQ as StoreSettingsChoice, bR as StoreTaxClass, bS as StoreTaxRate, bT as StoreTaxRateLocation, bU as TaxRounding, bV as TillDevice, bW as UpdateRequired, bX as VariantOptionGroup, bY as cashierPermissions, bZ as classifyFailure, b_ as currencySymbol, b$ as customerTraits, c0 as defaultPaymentMethods, c1 as deriveSessionFigures, c2 as deriveVariance, c3 as formatMoney, c4 as isCashierPermission, c5 as isCommandBatchResponse, c6 as legMethodId, c7 as minorToMajor, c8 as minorUnitDigits, c9 as moneyFromDecimalString, ca as moneyFromMajor, cb as moneyToMajor, cc as neutralFailureClass, cd as noResponse, ce as normalizeMoneyText, cf as parseCommandResult, cg as parseInfoCapabilities, ch as parseLineTax, ci as parseTaxRounding, cj as paymentMethodOf, ck as priceRefund, cl as ratePpmFromPercent, cm as refundableLines, cn as resolveCapabilities, co as resolvePrice, cp as resolvePriceRange, cq as roundRatio, cr as wireMethodOf } from './refund-share-BZ_Ff9Zk.js';
1
+ import { I as IceServer, D as DisplayAdvertisement, O as OrderFilterField, L as ListOrdersQuery, V as VariantSummary, C as CommandWarning, P as ProductTraits, S as StockReconcileAdapter, a as StockLevel, R as ReplicationAdapter, b as SyncContext, T as TallyConnector, c as TraitContext, d as CustomerTraits, M as MoneyFormat, e as Money, f as CalculateTaxesInput, g as CalculateTaxesResult, W as WooTaxRate, h as ItemizedTax, i as ResolvedTaxLocation, j as TAX_BASED_ON_META_KEY, k as TaxAddress, l as TaxBasedOn, m as TaxLocationOrder, n as normalizeTaxBasedOn, o as orderTaxLocation } from './refund-share-Cv_TgE1p.js';
2
+ export { A as AnyCommandEnvelope, p as ApproverCredentials, q as AuthField, B as BatchTooLargeBody, r as CASHIER_PERMISSIONS, s as COMMANDS_PATH, t as CaptureMode, u as CaptureModeEntry, v as Cashier, w as CashierPermission, x as CatalogueReconcileAdapter, y as CatalogueReconcileEntry, z as ClosureReads, E as CollectionSync, F as CommandBatchRequest, G as CommandBatchResponse, H as CommandEnvelope, J as CommandError, K as CommandResult, N as CommandResultError, Q as CommandServerRefs, U as CommandStatus, X as CommandType, Y as ConnectivityState, Z as ConnectorAuth, _ as ConnectorSchemas, $ as ConnectorTraits, a0 as Correction, a1 as Customer, a2 as CustomerAddress, a3 as CustomerInput, a4 as CustomerPage, a5 as CustomerPatch, a6 as CustomerServiceError, a7 as CustomerTaxId, a8 as DISPLAY_PAIR_CAPABILITY, a9 as DisplayRecord, aa as DisplaySignalling, ab as DisplaySignallingContext, ac as DisplaySignallingError, ad as DisplaySignallingErrorCode, ae as EarlierRefund, af as FailureClass, ag as FingerprintReconcileAdapter, ah as IdReconcileAdapter, ai as ListRefundsQuery, aj as MAX_COMMANDS_PER_BATCH, ak as NEEDS_ADMIN_MESSAGE_MAX, al as ORDER_LINE_SKU_MAX, am as ORDER_META_KEY_MAX, an as ORDER_META_MAX, ao as ORDER_NOTE_MAX, ap as ORDER_TAX_IDS_MAX, aq as ORDER_TAX_ID_TYPE_MAX, ar as ORDER_TAX_ID_VALUE_MAX, as as OrderAddress, at as OrderCreateCoupon, au as OrderCreateCouponInvalidData, av as OrderCreateCouponLine, aw as OrderCreateDisplay, ax as OrderCreateEnvelope, ay as OrderCreateLine, az as OrderCreateMeta, aA as OrderCreatePayload, aB as OrderCreatePayment, aC as OrderCreateTaxId, aD as OrderCreateTaxRate, aE as OrderCreateTotalMismatchData, aF as OrderRefundAmountMismatchData, aG as OrderRefundEnvelope, aH as OrderRefundLine, aI as OrderRefundNoOpenSessionData, aJ as OrderRefundOrderStateData, aK as OrderRefundPayload, aL as OrderRefundQuantityExceedsData, aM as OrderRefundRejectionCode, aN as OrderRefundResult, aO as OrderReopenEnvelope, aP as OrderReopenOrderStateData, aQ as OrderReopenPayload, aR as OrderReopenPaymentInMotionData, aS as OrderReopenRejectionCode, aT as OrderReopenResult, aU as OrderUpdateEnvelope, aV as OrderUpdateFee, aW as OrderUpdateLine, aX as OrderUpdatePayload, aY as OrderUpdatePayment, aZ as OrderUpdateRejectionCode, a_ as OrderUpdateReopenRequiredData, a$ as OrderUpdateShipping, b0 as PROTOCOL_HEADER, b1 as PROTOCOL_VERSION, b2 as PaymentHardware, b3 as PaymentKind, b4 as PaymentMethodDescriptor, b5 as PaymentMethodKind, b6 as PaymentOfflineMode, b7 as PaymentRounding, b8 as PaymentTipsMode, b9 as PaymentTransport, ba as PendingPairing, bb as PricedRefund, bc as PricedRefundLine, bd as ProductCategory, be as ProductPrice, bf as ProductTerm, bg as ReceiptTemplate, bh as ReceiptTemplateKind, bi as RefundableLine, bj as RefundableOrderLine, bk as RefusedOrderSettlement, bl as RegisterApprovalInvalidData, bm as RegisterApprovalRequiredData, bn as RegisterClosureSubmitPayload, bo as RegisterCommandEnvelope, bp as RegisterCommandResult, bq as RegisterCommandType, br as RegisterInfo, bs as RegisterMovementRecordPayload, bt as RegisterMovementVoidPayload, bu as RegisterSessionAlreadyOpenData, bv as RegisterSessionOpenPayload, bw as RegisterSessionSupersededData, bx as RegisterSessionTransitionPayload, by as RemoteIdEntry, bz as ResolvedPrice, bA as RoundingMode, bB as ServerCapabilities, bC as SettleCancelRequest, bD as SettleOutcome, bE as SettlePayRequest, bF as SettlePayResult, bG as SettlePayment, bH as SignInResult, bI as SignalMessage, bJ as StockStatus, bK as StoreClosure, bL as StoreOrder, bM as StoreOrderCharge, bN as StoreOrderLine, bO as StoreOrderPage, bP as StoreOrderPayment, bQ as StoreOrderRefund, bR as StoreOrderRefundLine, bS as StoreRefund, bT as StoreRefundOrphan, bU as StoreRefundPage, bV as StoreSettings, bW as StoreSettingsChoice, bX as StoreTaxClass, bY as StoreTaxRate, bZ as StoreTaxRateLocation, b_ as TaxRounding, b$ as TillDevice, c0 as UpdateRequired, c1 as VariantOptionGroup, c2 as cashierPermissions, c3 as classifyFailure, c4 as currencySymbol, c5 as customerTraits, c6 as defaultPaymentMethods, c7 as deriveSessionFigures, c8 as deriveVariance, c9 as formatMoney, ca as isCashierPermission, cb as isCommandBatchResponse, cc as legMethodId, cd as minorToMajor, ce as minorUnitDigits, cf as moneyFromDecimalString, cg as moneyFromMajor, ch as moneyToMajor, ci as neutralFailureClass, cj as noResponse, ck as normalizeMoneyText, cl as parseCommandResult, cm as parseInfoCapabilities, cn as parseLineTax, co as parseTaxRounding, cp as paymentMethodOf, cq as priceRefund, cr as ratePpmFromPercent, cs as refundableLines, ct as resolveCapabilities, cu as resolvePrice, cv as resolvePriceRange, cw as roundRatio, cx as wireMethodOf } from './refund-share-Cv_TgE1p.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import { ReactNode } from 'react';
5
5
  import 'rxdb';
@@ -2219,6 +2219,68 @@ interface ConnectorTraits {
2219
2219
  product: ProductTraits;
2220
2220
  customer?: CustomerTraits;
2221
2221
  }
2222
+ /** The answer to one `settleRefusedOrder` call. */
2223
+ type SettleOutcome =
2224
+ /** The order is cancelled. */
2225
+ {
2226
+ kind: 'done';
2227
+ status: string;
2228
+ }
2229
+ /** It is not a waiting unpaid order any more; nothing was cancelled. `capturedMinor` is what the store holds as captured. */
2230
+ | {
2231
+ kind: 'changed';
2232
+ status: string;
2233
+ capturedMinor: number;
2234
+ }
2235
+ /** The store or this check said no. */
2236
+ | {
2237
+ kind: 'refused';
2238
+ code: string;
2239
+ message: string;
2240
+ }
2241
+ /** The store no longer has it. */
2242
+ | {
2243
+ kind: 'gone';
2244
+ }
2245
+ /** No definite answer: try again later with the same `attemptId`. */
2246
+ | {
2247
+ kind: 'retry';
2248
+ reason: string;
2249
+ };
2250
+ /** Which order to settle: the store's id, the till's own order uuid, and the id of this attempt. */
2251
+ interface SettleCancelRequest {
2252
+ storeOrderId: string;
2253
+ clientOrderId: string;
2254
+ attemptId: string;
2255
+ }
2256
+ /** One till leg to record on the store order (#1101 slice 3): a new payment id, the till leg's method, amount and cash tendered. */
2257
+ interface SettlePayment {
2258
+ id: string;
2259
+ method: PaymentMethodKind;
2260
+ amountMinor: number;
2261
+ tenderedMinor?: number;
2262
+ }
2263
+ /** Record the till's unrecorded legs on the store order a refused sale left part paid. */
2264
+ interface SettlePayRequest extends SettleCancelRequest {
2265
+ currency: string;
2266
+ payments: readonly SettlePayment[];
2267
+ }
2268
+ /** `recorded`: the ids in `payments` the store holds as captured when the call ends, in request order. */
2269
+ interface SettlePayResult {
2270
+ outcome: SettleOutcome;
2271
+ recorded: readonly string[];
2272
+ }
2273
+ /** Settlement of an order the store created before it refused the sale. */
2274
+ interface RefusedOrderSettlement {
2275
+ cancel?: (context: SyncContext, request: SettleCancelRequest) => Promise<SettleOutcome>;
2276
+ /**
2277
+ * Records the till's unrecorded legs, money the customer already paid at the till, on a part-paid store order: no new
2278
+ * money is taken. `done` means every payment is recorded and the order reads `completed`; `changed` means nothing was
2279
+ * sent because the store's figures or status do not match; `gone` comes only from the uuid resolver's 404; `retry`
2280
+ * means no definite answer: send again with the same `attemptId` and payment ids.
2281
+ */
2282
+ pay?: (context: SyncContext, request: SettlePayRequest) => Promise<SettlePayResult>;
2283
+ }
2222
2284
  /**
2223
2285
  * The main connector interface.
2224
2286
  * Each backend (WooCommerce, Medusa, Vendure, etc.) implements this.
@@ -2349,6 +2411,14 @@ interface TallyConnector {
2349
2411
  * read-only; rejects as `listOrders`. `undefined` when the connector has no order history.
2350
2412
  */
2351
2413
  getOrders?: (context: SyncContext, ids: readonly string[]) => Promise<StoreOrder[]>;
2414
+ /**
2415
+ * Settles an order the store created before it refused the sale: online only, never through the outbox. `cancel`
2416
+ * cancels it only when the store's own current record shows nothing paid; `pay` records the till's unrecorded legs
2417
+ * only when the store's due is exactly their sum. `attemptId` identifies one attempt and is
2418
+ * sent again unchanged until a definite answer; `retry` means no definite answer. Rejects with
2419
+ * `ConnectorUnauthorizedError` for credentials. `undefined` when the connector can't settle refused orders.
2420
+ */
2421
+ settleRefusedOrder?: RefusedOrderSettlement;
2352
2422
  /**
2353
2423
  * The store's refunds, newest first, one page per call, dated by when each was made (ADR-081 decision 7): online only,
2354
2424
  * read-only. Rejects as `listOrders` does; a `dateRange` end that is not a UTC instant ending in Z is a TypeError
@@ -2521,4 +2591,4 @@ declare function refundableLines(lines: readonly RefundableOrderLine[], refunds:
2521
2591
  /** Prices requested quantities with cumulative shares, clamping them to what remains refundable. */
2522
2592
  declare function priceRefund(lines: readonly RefundableOrderLine[], refunds: readonly EarlierRefund[], request: readonly OrderRefundLine[]): PricedRefund;
2523
2593
 
2524
- export { type ConnectorTraits as $, type AnyCommandEnvelope as A, type BatchTooLargeBody as B, type CommandWarning as C, type DisplayAdvertisement as D, type CollectionSync as E, type CommandBatchRequest as F, type CommandBatchResponse as G, type CommandEnvelope as H, type IceServer as I, type CommandError as J, type CommandResult as K, type ListOrdersQuery as L, type MoneyFormat as M, CommandResultError as N, type OrderFilterField as O, type ProductTraits as P, type CommandServerRefs as Q, type ReplicationAdapter as R, type StockReconcileAdapter as S, type TallyConnector as T, type CommandStatus as U, type VariantSummary as V, type WooTaxRate as W, type CommandType as X, type ConnectivityState as Y, type ConnectorAuth as Z, type ConnectorSchemas as _, type StockLevel as a, type OrderUpdateShipping as a$, type Correction as a0, type Customer as a1, type CustomerAddress as a2, type CustomerInput as a3, type CustomerPage as a4, type CustomerPatch as a5, CustomerServiceError as a6, type CustomerTaxId as a7, DISPLAY_PAIR_CAPABILITY as a8, type DisplayRecord as a9, type OrderCreatePayload as aA, type OrderCreatePayment as aB, type OrderCreateTaxId as aC, type OrderCreateTaxRate as aD, type OrderCreateTotalMismatchData as aE, type OrderRefundAmountMismatchData as aF, type OrderRefundEnvelope as aG, type OrderRefundLine as aH, type OrderRefundNoOpenSessionData as aI, type OrderRefundOrderStateData as aJ, type OrderRefundPayload as aK, type OrderRefundQuantityExceedsData as aL, type OrderRefundRejectionCode as aM, type OrderRefundResult as aN, type OrderReopenEnvelope as aO, type OrderReopenOrderStateData as aP, type OrderReopenPayload as aQ, type OrderReopenPaymentInMotionData as aR, type OrderReopenRejectionCode as aS, type OrderReopenResult as aT, type OrderUpdateEnvelope as aU, type OrderUpdateFee as aV, type OrderUpdateLine as aW, type OrderUpdatePayload as aX, type OrderUpdatePayment as aY, type OrderUpdateRejectionCode as aZ, type OrderUpdateReopenRequiredData as a_, type DisplaySignalling as aa, type DisplaySignallingContext as ab, DisplaySignallingError as ac, type DisplaySignallingErrorCode as ad, type EarlierRefund as ae, type FailureClass as af, type FingerprintReconcileAdapter as ag, type IdReconcileAdapter as ah, type ListRefundsQuery as ai, MAX_COMMANDS_PER_BATCH as aj, NEEDS_ADMIN_MESSAGE_MAX as ak, ORDER_LINE_SKU_MAX as al, ORDER_META_KEY_MAX as am, ORDER_META_MAX as an, ORDER_NOTE_MAX as ao, ORDER_TAX_IDS_MAX as ap, ORDER_TAX_ID_TYPE_MAX as aq, ORDER_TAX_ID_VALUE_MAX as ar, type OrderAddress as as, type OrderCreateCoupon as at, type OrderCreateCouponInvalidData as au, type OrderCreateCouponLine as av, type OrderCreateDisplay as aw, type OrderCreateEnvelope as ax, type OrderCreateLine as ay, type OrderCreateMeta as az, type SyncContext as b, customerTraits as b$, PROTOCOL_HEADER as b0, PROTOCOL_VERSION as b1, type PaymentHardware as b2, type PaymentKind as b3, type PaymentMethodDescriptor as b4, type PaymentMethodKind as b5, type PaymentOfflineMode as b6, type PaymentRounding as b7, type PaymentTipsMode as b8, type PaymentTransport as b9, type ServerCapabilities as bA, type SignInResult as bB, type SignalMessage as bC, type StockStatus as bD, type StoreClosure as bE, type StoreOrder as bF, type StoreOrderCharge as bG, type StoreOrderLine as bH, type StoreOrderPage as bI, type StoreOrderPayment as bJ, type StoreOrderRefund as bK, type StoreOrderRefundLine as bL, type StoreRefund as bM, type StoreRefundOrphan as bN, type StoreRefundPage as bO, type StoreSettings as bP, type StoreSettingsChoice as bQ, type StoreTaxClass as bR, type StoreTaxRate as bS, type StoreTaxRateLocation as bT, type TaxRounding as bU, type TillDevice as bV, type UpdateRequired as bW, type VariantOptionGroup as bX, cashierPermissions as bY, classifyFailure as bZ, currencySymbol as b_, type PendingPairing as ba, type PricedRefund as bb, type PricedRefundLine as bc, type ProductCategory as bd, type ProductPrice as be, type ProductTerm as bf, type ReceiptTemplate as bg, type ReceiptTemplateKind as bh, type RefundableLine as bi, type RefundableOrderLine as bj, type RegisterApprovalInvalidData as bk, type RegisterApprovalRequiredData as bl, type RegisterClosureSubmitPayload as bm, type RegisterCommandEnvelope as bn, type RegisterCommandResult as bo, type RegisterCommandType as bp, type RegisterInfo as bq, type RegisterMovementRecordPayload as br, type RegisterMovementVoidPayload as bs, type RegisterSessionAlreadyOpenData as bt, type RegisterSessionOpenPayload as bu, type RegisterSessionSupersededData as bv, type RegisterSessionTransitionPayload as bw, type RemoteIdEntry as bx, type ResolvedPrice as by, type RoundingMode as bz, type TraitContext as c, defaultPaymentMethods as c0, deriveSessionFigures as c1, deriveVariance as c2, formatMoney as c3, isCashierPermission as c4, isCommandBatchResponse as c5, legMethodId as c6, minorToMajor as c7, minorUnitDigits as c8, moneyFromDecimalString as c9, moneyFromMajor as ca, moneyToMajor as cb, neutralFailureClass as cc, noResponse as cd, normalizeMoneyText as ce, parseCommandResult as cf, parseInfoCapabilities as cg, parseLineTax as ch, parseTaxRounding as ci, paymentMethodOf as cj, priceRefund as ck, ratePpmFromPercent as cl, refundableLines as cm, resolveCapabilities as cn, resolvePrice as co, resolvePriceRange as cp, roundRatio as cq, wireMethodOf as cr, currencyDecimals as cs, majorToMinor as ct, type CustomerTraits as d, type Money as e, type CalculateTaxesInput as f, type CalculateTaxesResult as g, type ItemizedTax as h, type ResolvedTaxLocation as i, TAX_BASED_ON_META_KEY as j, type TaxAddress as k, type TaxBasedOn as l, type TaxLocationOrder as m, normalizeTaxBasedOn as n, orderTaxLocation as o, type ApproverCredentials as p, type AuthField as q, CASHIER_PERMISSIONS as r, COMMANDS_PATH as s, type CaptureMode as t, type CaptureModeEntry as u, type Cashier as v, type CashierPermission as w, type CatalogueReconcileAdapter as x, type CatalogueReconcileEntry as y, type ClosureReads as z };
2594
+ export { type ConnectorTraits as $, type AnyCommandEnvelope as A, type BatchTooLargeBody as B, type CommandWarning as C, type DisplayAdvertisement as D, type CollectionSync as E, type CommandBatchRequest as F, type CommandBatchResponse as G, type CommandEnvelope as H, type IceServer as I, type CommandError as J, type CommandResult as K, type ListOrdersQuery as L, type MoneyFormat as M, CommandResultError as N, type OrderFilterField as O, type ProductTraits as P, type CommandServerRefs as Q, type ReplicationAdapter as R, type StockReconcileAdapter as S, type TallyConnector as T, type CommandStatus as U, type VariantSummary as V, type WooTaxRate as W, type CommandType as X, type ConnectivityState as Y, type ConnectorAuth as Z, type ConnectorSchemas as _, type StockLevel as a, type OrderUpdateShipping as a$, type Correction as a0, type Customer as a1, type CustomerAddress as a2, type CustomerInput as a3, type CustomerPage as a4, type CustomerPatch as a5, CustomerServiceError as a6, type CustomerTaxId as a7, DISPLAY_PAIR_CAPABILITY as a8, type DisplayRecord as a9, type OrderCreatePayload as aA, type OrderCreatePayment as aB, type OrderCreateTaxId as aC, type OrderCreateTaxRate as aD, type OrderCreateTotalMismatchData as aE, type OrderRefundAmountMismatchData as aF, type OrderRefundEnvelope as aG, type OrderRefundLine as aH, type OrderRefundNoOpenSessionData as aI, type OrderRefundOrderStateData as aJ, type OrderRefundPayload as aK, type OrderRefundQuantityExceedsData as aL, type OrderRefundRejectionCode as aM, type OrderRefundResult as aN, type OrderReopenEnvelope as aO, type OrderReopenOrderStateData as aP, type OrderReopenPayload as aQ, type OrderReopenPaymentInMotionData as aR, type OrderReopenRejectionCode as aS, type OrderReopenResult as aT, type OrderUpdateEnvelope as aU, type OrderUpdateFee as aV, type OrderUpdateLine as aW, type OrderUpdatePayload as aX, type OrderUpdatePayment as aY, type OrderUpdateRejectionCode as aZ, type OrderUpdateReopenRequiredData as a_, type DisplaySignalling as aa, type DisplaySignallingContext as ab, DisplaySignallingError as ac, type DisplaySignallingErrorCode as ad, type EarlierRefund as ae, type FailureClass as af, type FingerprintReconcileAdapter as ag, type IdReconcileAdapter as ah, type ListRefundsQuery as ai, MAX_COMMANDS_PER_BATCH as aj, NEEDS_ADMIN_MESSAGE_MAX as ak, ORDER_LINE_SKU_MAX as al, ORDER_META_KEY_MAX as am, ORDER_META_MAX as an, ORDER_NOTE_MAX as ao, ORDER_TAX_IDS_MAX as ap, ORDER_TAX_ID_TYPE_MAX as aq, ORDER_TAX_ID_VALUE_MAX as ar, type OrderAddress as as, type OrderCreateCoupon as at, type OrderCreateCouponInvalidData as au, type OrderCreateCouponLine as av, type OrderCreateDisplay as aw, type OrderCreateEnvelope as ax, type OrderCreateLine as ay, type OrderCreateMeta as az, type SyncContext as b, type TillDevice as b$, PROTOCOL_HEADER as b0, PROTOCOL_VERSION as b1, type PaymentHardware as b2, type PaymentKind as b3, type PaymentMethodDescriptor as b4, type PaymentMethodKind as b5, type PaymentOfflineMode as b6, type PaymentRounding as b7, type PaymentTipsMode as b8, type PaymentTransport as b9, type RoundingMode as bA, type ServerCapabilities as bB, type SettleCancelRequest as bC, type SettleOutcome as bD, type SettlePayRequest as bE, type SettlePayResult as bF, type SettlePayment as bG, type SignInResult as bH, type SignalMessage as bI, type StockStatus as bJ, type StoreClosure as bK, type StoreOrder as bL, type StoreOrderCharge as bM, type StoreOrderLine as bN, type StoreOrderPage as bO, type StoreOrderPayment as bP, type StoreOrderRefund as bQ, type StoreOrderRefundLine as bR, type StoreRefund as bS, type StoreRefundOrphan as bT, type StoreRefundPage as bU, type StoreSettings as bV, type StoreSettingsChoice as bW, type StoreTaxClass as bX, type StoreTaxRate as bY, type StoreTaxRateLocation as bZ, type TaxRounding as b_, type PendingPairing as ba, type PricedRefund as bb, type PricedRefundLine as bc, type ProductCategory as bd, type ProductPrice as be, type ProductTerm as bf, type ReceiptTemplate as bg, type ReceiptTemplateKind as bh, type RefundableLine as bi, type RefundableOrderLine as bj, type RefusedOrderSettlement as bk, type RegisterApprovalInvalidData as bl, type RegisterApprovalRequiredData as bm, type RegisterClosureSubmitPayload as bn, type RegisterCommandEnvelope as bo, type RegisterCommandResult as bp, type RegisterCommandType as bq, type RegisterInfo as br, type RegisterMovementRecordPayload as bs, type RegisterMovementVoidPayload as bt, type RegisterSessionAlreadyOpenData as bu, type RegisterSessionOpenPayload as bv, type RegisterSessionSupersededData as bw, type RegisterSessionTransitionPayload as bx, type RemoteIdEntry as by, type ResolvedPrice as bz, type TraitContext as c, type UpdateRequired as c0, type VariantOptionGroup as c1, cashierPermissions as c2, classifyFailure as c3, currencySymbol as c4, customerTraits as c5, defaultPaymentMethods as c6, deriveSessionFigures as c7, deriveVariance as c8, formatMoney as c9, isCashierPermission as ca, isCommandBatchResponse as cb, legMethodId as cc, minorToMajor as cd, minorUnitDigits as ce, moneyFromDecimalString as cf, moneyFromMajor as cg, moneyToMajor as ch, neutralFailureClass as ci, noResponse as cj, normalizeMoneyText as ck, parseCommandResult as cl, parseInfoCapabilities as cm, parseLineTax as cn, parseTaxRounding as co, paymentMethodOf as cp, priceRefund as cq, ratePpmFromPercent as cr, refundableLines as cs, resolveCapabilities as ct, resolvePrice as cu, resolvePriceRange as cv, roundRatio as cw, wireMethodOf as cx, currencyDecimals as cy, majorToMinor as cz, type CustomerTraits as d, type Money as e, type CalculateTaxesInput as f, type CalculateTaxesResult as g, type ItemizedTax as h, type ResolvedTaxLocation as i, TAX_BASED_ON_META_KEY as j, type TaxAddress as k, type TaxBasedOn as l, type TaxLocationOrder as m, normalizeTaxBasedOn as n, orderTaxLocation as o, type ApproverCredentials as p, type AuthField as q, CASHIER_PERMISSIONS as r, COMMANDS_PATH as s, type CaptureMode as t, type CaptureModeEntry as u, type Cashier as v, type CashierPermission as w, type CatalogueReconcileAdapter as x, type CatalogueReconcileEntry as y, type ClosureReads as z };
@@ -609,6 +609,224 @@ function shapeErrors() {
609
609
  return { errors, check: check2, noNul };
610
610
  }
611
611
 
612
+ // src/server/refund-payload-shape.ts
613
+ function refundPayloadErrors(payload) {
614
+ const { errors, check: check2, noNul } = shapeErrors();
615
+ if (!isPlainObject(payload)) return ["payload: expected an object"];
616
+ const fields = [
617
+ "clientRefundId",
618
+ "orderId",
619
+ "registerId",
620
+ "sessionId",
621
+ "clientOrderId",
622
+ "cashierRef",
623
+ "lines",
624
+ "shippingMinor",
625
+ "totalMinor",
626
+ "adjustmentMinor",
627
+ "destination",
628
+ "reason",
629
+ "createdAt"
630
+ ];
631
+ for (const key of Object.keys(payload)) {
632
+ if (!fields.includes(key) && errors.length < 10) {
633
+ errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
634
+ }
635
+ }
636
+ for (const field of ["clientRefundId", "orderId", "registerId", "sessionId", "clientOrderId", "cashierRef"]) {
637
+ const value = payload[field];
638
+ if (["clientOrderId", "cashierRef"].includes(field) && value === void 0) continue;
639
+ check2(
640
+ typeof value === "string" && value.length > 0 && value.length <= 64,
641
+ field,
642
+ "a non-empty string of at most 64 characters"
643
+ );
644
+ noNul(value, field);
645
+ }
646
+ check2(Array.isArray(payload.lines) && payload.lines.length <= 500, "lines", "an array of at most 500 lines");
647
+ const seen = /* @__PURE__ */ new Set();
648
+ if (Array.isArray(payload.lines)) payload.lines.forEach((line, index) => {
649
+ const path = `lines[${index}]`;
650
+ if (!isPlainObject(line)) {
651
+ check2(false, path, "an object");
652
+ return;
653
+ }
654
+ for (const key of Object.keys(line)) {
655
+ if (!["orderLineId", "quantity", "restock"].includes(key) && errors.length < 10) {
656
+ errors.push(`${path}.${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
657
+ }
658
+ }
659
+ check2(
660
+ typeof line.orderLineId === "string" && line.orderLineId.length > 0 && line.orderLineId.length <= 64,
661
+ `${path}.orderLineId`,
662
+ "a non-empty string of at most 64 characters"
663
+ );
664
+ noNul(line.orderLineId, `${path}.orderLineId`);
665
+ if (typeof line.orderLineId === "string") {
666
+ check2(!seen.has(line.orderLineId), `${path}.orderLineId`, "unique in lines");
667
+ seen.add(line.orderLineId);
668
+ }
669
+ check2(Number.isSafeInteger(line.quantity) && line.quantity >= 1, `${path}.quantity`, "a safe integer >= 1");
670
+ check2(typeof line.restock === "boolean", `${path}.restock`, "a boolean");
671
+ });
672
+ for (const field of ["shippingMinor", "totalMinor"]) {
673
+ check2(Number.isSafeInteger(payload[field]) && payload[field] >= 0, field, "a safe integer >= 0");
674
+ }
675
+ check2(Number.isSafeInteger(payload.adjustmentMinor), "adjustmentMinor", "a safe integer");
676
+ check2(payload.destination === "original_method" || payload.destination === "cash", "destination", "original_method or cash");
677
+ noNul(payload.destination, "destination");
678
+ check2(
679
+ typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
680
+ "reason",
681
+ "a non-empty string after trim of at most 500 characters"
682
+ );
683
+ noNul(payload.reason, "reason");
684
+ check2(
685
+ typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
686
+ "createdAt",
687
+ "a valid date"
688
+ );
689
+ noNul(payload.createdAt, "createdAt");
690
+ return errors;
691
+ }
692
+
693
+ // src/server/register-payload-shape.ts
694
+ function registerPayloadErrors(type, payload) {
695
+ const { errors, check: check2, noNul } = shapeErrors();
696
+ if (!isPlainObject(payload)) return ["payload: expected an object"];
697
+ const string = (field, optional = false) => {
698
+ const value = payload[field];
699
+ if (optional && value === void 0) return;
700
+ check2(typeof value === "string" && (optional || value.length > 0), field, optional ? "a string" : "a non-empty string");
701
+ if (typeof value === "string" && (field.endsWith("Id") || field === "voids")) check2(value.length <= 64, field, "at most 64 characters");
702
+ if (typeof value === "string" && ["openedAt", "at", "createdAt", "closedAt"].includes(field)) {
703
+ check2(!Number.isNaN(Date.parse(value)), field, "a valid date");
704
+ }
705
+ noNul(value, field);
706
+ };
707
+ const integer = (field, min = -Infinity) => check2(Number.isSafeInteger(payload[field]) && payload[field] >= min, field, `a safe integer >= ${min}`);
708
+ const record = (field) => {
709
+ const value = payload[field];
710
+ check2(isPlainObject(value), field, "a record of integers");
711
+ if (isPlainObject(value)) for (const [key, amount] of Object.entries(value)) {
712
+ check2(key.length > 0 && Number.isSafeInteger(amount), `${field}.${key}`, "a non-empty key with a safe integer");
713
+ noNul(key, `${field}.${JSON.stringify(key)}`);
714
+ }
715
+ };
716
+ string("sessionId");
717
+ switch (type) {
718
+ case "register.session.open":
719
+ for (const field of ["registerId", "openedAt"]) string(field);
720
+ for (const field of ["storeKey", "businessDay", "openedBy"]) string(field, true);
721
+ if (payload.deviceName !== void 0) {
722
+ check2(
723
+ typeof payload.deviceName === "string" && payload.deviceName.trim().length >= 1 && payload.deviceName.trim().length <= 64,
724
+ "deviceName",
725
+ "a string of 1 to 64 characters after trim"
726
+ );
727
+ noNul(payload.deviceName, "deviceName");
728
+ }
729
+ if (payload.supersedes !== void 0) {
730
+ check2(
731
+ typeof payload.supersedes === "string" && payload.supersedes.length > 0 && payload.supersedes.length <= 64,
732
+ "supersedes",
733
+ "a non-empty string of at most 64 characters"
734
+ );
735
+ noNul(payload.supersedes, "supersedes");
736
+ }
737
+ integer("countedFloatMinor", 0);
738
+ for (const field of ["expectedFloatMinor", "openingVarianceMinor"]) if (payload[field] !== void 0) integer(field);
739
+ break;
740
+ case "register.session.transition":
741
+ string("at");
742
+ check2(["open", "counting", "closed"].includes(payload.status), "status", "open, counting or closed");
743
+ for (const field of ["counted", "closedBy", "approvedBy"]) if (payload[field] !== void 0) {
744
+ check2(payload.status === "closed", field, "a closing transition");
745
+ if (field === "counted") record(field);
746
+ else string(field, true);
747
+ }
748
+ break;
749
+ case "register.movement.record":
750
+ case "register.movement.void":
751
+ for (const field of ["movementId", "createdAt"]) string(field);
752
+ string("createdBy", true);
753
+ if (type === "register.movement.void") string("voids");
754
+ else {
755
+ check2(
756
+ typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
757
+ "reason",
758
+ "a non-empty string after trim of at most 500 characters"
759
+ );
760
+ noNul(payload.reason, "reason");
761
+ check2(["paid_in", "paid_out", "no_sale"].includes(payload.type), "type", "paid_in, paid_out or no_sale");
762
+ integer("amountMinor", payload.type === "no_sale" ? 0 : 1);
763
+ if (payload.type === "no_sale") check2(payload.amountMinor === 0, "amountMinor", "0 for no_sale");
764
+ }
765
+ break;
766
+ case "register.closure.submit":
767
+ for (const field of ["closureId", "registerId", "openedAt", "closedAt", "softwareVersion"]) string(field);
768
+ for (const field of ["businessDay", "closedBy", "approvedBy"]) string(field, true);
769
+ if (payload.approval !== void 0) {
770
+ check2(typeof payload.approval === "string" && payload.approval.length > 0, "approval", "a non-empty string");
771
+ noNul(payload.approval, "approval");
772
+ }
773
+ integer("number", 1);
774
+ for (const field of [
775
+ "periodSalesTotalMinor",
776
+ "periodRefundsTotalMinor",
777
+ "perpetualSalesTotalMinor",
778
+ "perpetualRefundsTotalMinor",
779
+ "unsyncedCount",
780
+ "unsyncedTotalMinor"
781
+ ]) integer(field, 0);
782
+ for (const field of ["number", "unsyncedCount"])
783
+ check2(payload[field] <= 2147483647, field, "at most 2147483647");
784
+ for (const field of ["tillExpected", "counted"]) record(field);
785
+ for (const field of ["orderIds", "movementIds"]) {
786
+ const value = payload[field];
787
+ check2(Array.isArray(value), field, "an array of ids");
788
+ if (Array.isArray(value)) value.forEach((id, index) => {
789
+ check2(typeof id === "string" && id.length > 0 && id.length <= 64, `${field}[${index}]`, "a non-empty string of at most 64 characters");
790
+ noNul(id, `${field}[${index}]`);
791
+ });
792
+ }
793
+ break;
794
+ default:
795
+ check2(false, "type", "a register command type");
796
+ }
797
+ return errors;
798
+ }
799
+
800
+ // src/server/reopen-payload-shape.ts
801
+ function reopenPayloadErrors(payload) {
802
+ const { errors, check: check2, noNul } = shapeErrors();
803
+ if (!isPlainObject(payload)) return ["payload: expected an object"];
804
+ const fields = ["orderId", "clientOrderId", "baseRevision", "cashierRef", "registerId", "storeId", "createdAt"];
805
+ for (const key of Object.keys(payload)) {
806
+ if (!fields.includes(key) && errors.length < 10) {
807
+ errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.reopen version 1`);
808
+ }
809
+ }
810
+ for (const field of ["orderId", "cashierRef", "registerId", "clientOrderId", "baseRevision", "storeId"]) {
811
+ const value = payload[field];
812
+ if (["clientOrderId", "baseRevision", "storeId"].includes(field) && value === void 0) continue;
813
+ const max = field === "baseRevision" ? 128 : 64;
814
+ check2(
815
+ typeof value === "string" && value.length > 0 && value.length <= max,
816
+ field,
817
+ `a non-empty string of at most ${max} characters`
818
+ );
819
+ noNul(value, field);
820
+ }
821
+ check2(
822
+ typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
823
+ "createdAt",
824
+ "a valid date"
825
+ );
826
+ noNul(payload.createdAt, "createdAt");
827
+ return errors;
828
+ }
829
+
612
830
  // src/server/update-payload-shape.ts
613
831
  function updateOnlyErrors(payload) {
614
832
  const { errors, check: check2 } = shapeErrors();
@@ -695,6 +913,7 @@ function validateBatch(body) {
695
913
  }
696
914
  var rejected = (id, code, message, data) => ({ id, status: "rejected", error: data === void 0 ? { code, message } : { code, message, data } });
697
915
  var firstTen = (errors) => errors.slice(0, 10).join("; ");
916
+ var shapeRefusal = (id, errors) => errors.length ? rejected(id, "invalid_payload", firstTen(errors)) : void 0;
698
917
  function unsupportedOptional(envelope, key, versions, noun) {
699
918
  if (versions.includes(envelope.version)) return void 0;
700
919
  return rejected(
@@ -708,8 +927,12 @@ function precheckCommand(envelope, supported) {
708
927
  for (const key of ["orderCreate", "register"]) {
709
928
  if (!supported[key]?.length) throw new TypeError(`precheckCommand: supported.${key} must list at least one version`);
710
929
  }
711
- if (envelope.type === "order.refund") return unsupportedOptional(envelope, "orderRefund", supported.orderRefund ?? [], "refunds");
712
- if (envelope.type === "order.reopen") return unsupportedOptional(envelope, "orderReopen", supported.orderReopen ?? [], "reopens");
930
+ if (envelope.type === "order.refund") {
931
+ return unsupportedOptional(envelope, "orderRefund", supported.orderRefund ?? [], "refunds") ?? shapeRefusal(envelope.id, refundPayloadErrors(envelope.payload));
932
+ }
933
+ if (envelope.type === "order.reopen") {
934
+ return unsupportedOptional(envelope, "orderReopen", supported.orderReopen ?? [], "reopens") ?? shapeRefusal(envelope.id, reopenPayloadErrors(envelope.payload));
935
+ }
713
936
  if (envelope.type === "order.update") {
714
937
  const refusal = unsupportedOptional(envelope, "orderUpdate", supported.orderUpdate ?? [], "updates");
715
938
  if (refusal) return refusal;
@@ -729,7 +952,7 @@ function precheckCommand(envelope, supported) {
729
952
  { register: Math.max(...supported.register) }
730
953
  );
731
954
  }
732
- return void 0;
955
+ return shapeRefusal(envelope.id, registerPayloadErrors(envelope.type, envelope.payload));
733
956
  }
734
957
  const command = envelope;
735
958
  if (!supported.orderCreate.includes(command.version)) {
@@ -786,7 +1009,7 @@ function precheckCommand(envelope, supported) {
786
1009
  return rejected(command.id, "invalid_payload", firstTen(bounds));
787
1010
  }
788
1011
  const shape = payloadShapeErrors(payload);
789
- const errors = command.version >= 5 && shape.length ? shape : v3 && display !== void 0 && taxByRate !== void 0 && shape.length === 0 ? fiscalFiguresErrors(payload) : [];
1012
+ const errors = shape.length ? shape : v3 && display !== void 0 && taxByRate !== void 0 ? fiscalFiguresErrors(payload) : [];
790
1013
  if (errors.length) {
791
1014
  return rejected(command.id, "invalid_payload", firstTen(errors));
792
1015
  }
@@ -1002,224 +1225,6 @@ function parseCommandResult(value) {
1002
1225
  return result;
1003
1226
  }
1004
1227
 
1005
- // src/server/register-payload-shape.ts
1006
- function registerPayloadErrors(type, payload) {
1007
- const { errors, check: check2, noNul } = shapeErrors();
1008
- if (!isPlainObject(payload)) return ["payload: expected an object"];
1009
- const string = (field, optional = false) => {
1010
- const value = payload[field];
1011
- if (optional && value === void 0) return;
1012
- check2(typeof value === "string" && (optional || value.length > 0), field, optional ? "a string" : "a non-empty string");
1013
- if (typeof value === "string" && (field.endsWith("Id") || field === "voids")) check2(value.length <= 64, field, "at most 64 characters");
1014
- if (typeof value === "string" && ["openedAt", "at", "createdAt", "closedAt"].includes(field)) {
1015
- check2(!Number.isNaN(Date.parse(value)), field, "a valid date");
1016
- }
1017
- noNul(value, field);
1018
- };
1019
- const integer = (field, min = -Infinity) => check2(Number.isSafeInteger(payload[field]) && payload[field] >= min, field, `a safe integer >= ${min}`);
1020
- const record = (field) => {
1021
- const value = payload[field];
1022
- check2(isPlainObject(value), field, "a record of integers");
1023
- if (isPlainObject(value)) for (const [key, amount] of Object.entries(value)) {
1024
- check2(key.length > 0 && Number.isSafeInteger(amount), `${field}.${key}`, "a non-empty key with a safe integer");
1025
- noNul(key, `${field}.${JSON.stringify(key)}`);
1026
- }
1027
- };
1028
- string("sessionId");
1029
- switch (type) {
1030
- case "register.session.open":
1031
- for (const field of ["registerId", "openedAt"]) string(field);
1032
- for (const field of ["storeKey", "businessDay", "openedBy"]) string(field, true);
1033
- if (payload.deviceName !== void 0) {
1034
- check2(
1035
- typeof payload.deviceName === "string" && payload.deviceName.trim().length >= 1 && payload.deviceName.trim().length <= 64,
1036
- "deviceName",
1037
- "a string of 1 to 64 characters after trim"
1038
- );
1039
- noNul(payload.deviceName, "deviceName");
1040
- }
1041
- if (payload.supersedes !== void 0) {
1042
- check2(
1043
- typeof payload.supersedes === "string" && payload.supersedes.length > 0 && payload.supersedes.length <= 64,
1044
- "supersedes",
1045
- "a non-empty string of at most 64 characters"
1046
- );
1047
- noNul(payload.supersedes, "supersedes");
1048
- }
1049
- integer("countedFloatMinor", 0);
1050
- for (const field of ["expectedFloatMinor", "openingVarianceMinor"]) if (payload[field] !== void 0) integer(field);
1051
- break;
1052
- case "register.session.transition":
1053
- string("at");
1054
- check2(["open", "counting", "closed"].includes(payload.status), "status", "open, counting or closed");
1055
- for (const field of ["counted", "closedBy", "approvedBy"]) if (payload[field] !== void 0) {
1056
- check2(payload.status === "closed", field, "a closing transition");
1057
- if (field === "counted") record(field);
1058
- else string(field, true);
1059
- }
1060
- break;
1061
- case "register.movement.record":
1062
- case "register.movement.void":
1063
- for (const field of ["movementId", "createdAt"]) string(field);
1064
- string("createdBy", true);
1065
- if (type === "register.movement.void") string("voids");
1066
- else {
1067
- check2(
1068
- typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
1069
- "reason",
1070
- "a non-empty string after trim of at most 500 characters"
1071
- );
1072
- noNul(payload.reason, "reason");
1073
- check2(["paid_in", "paid_out", "no_sale"].includes(payload.type), "type", "paid_in, paid_out or no_sale");
1074
- integer("amountMinor", payload.type === "no_sale" ? 0 : 1);
1075
- if (payload.type === "no_sale") check2(payload.amountMinor === 0, "amountMinor", "0 for no_sale");
1076
- }
1077
- break;
1078
- case "register.closure.submit":
1079
- for (const field of ["closureId", "registerId", "openedAt", "closedAt", "softwareVersion"]) string(field);
1080
- for (const field of ["businessDay", "closedBy", "approvedBy"]) string(field, true);
1081
- if (payload.approval !== void 0) {
1082
- check2(typeof payload.approval === "string" && payload.approval.length > 0, "approval", "a non-empty string");
1083
- noNul(payload.approval, "approval");
1084
- }
1085
- integer("number", 1);
1086
- for (const field of [
1087
- "periodSalesTotalMinor",
1088
- "periodRefundsTotalMinor",
1089
- "perpetualSalesTotalMinor",
1090
- "perpetualRefundsTotalMinor",
1091
- "unsyncedCount",
1092
- "unsyncedTotalMinor"
1093
- ]) integer(field, 0);
1094
- for (const field of ["number", "unsyncedCount"])
1095
- check2(payload[field] <= 2147483647, field, "at most 2147483647");
1096
- for (const field of ["tillExpected", "counted"]) record(field);
1097
- for (const field of ["orderIds", "movementIds"]) {
1098
- const value = payload[field];
1099
- check2(Array.isArray(value), field, "an array of ids");
1100
- if (Array.isArray(value)) value.forEach((id, index) => {
1101
- check2(typeof id === "string" && id.length > 0 && id.length <= 64, `${field}[${index}]`, "a non-empty string of at most 64 characters");
1102
- noNul(id, `${field}[${index}]`);
1103
- });
1104
- }
1105
- break;
1106
- default:
1107
- check2(false, "type", "a register command type");
1108
- }
1109
- return errors;
1110
- }
1111
-
1112
- // src/server/refund-payload-shape.ts
1113
- function refundPayloadErrors(payload) {
1114
- const { errors, check: check2, noNul } = shapeErrors();
1115
- if (!isPlainObject(payload)) return ["payload: expected an object"];
1116
- const fields = [
1117
- "clientRefundId",
1118
- "orderId",
1119
- "registerId",
1120
- "sessionId",
1121
- "clientOrderId",
1122
- "cashierRef",
1123
- "lines",
1124
- "shippingMinor",
1125
- "totalMinor",
1126
- "adjustmentMinor",
1127
- "destination",
1128
- "reason",
1129
- "createdAt"
1130
- ];
1131
- for (const key of Object.keys(payload)) {
1132
- if (!fields.includes(key) && errors.length < 10) {
1133
- errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
1134
- }
1135
- }
1136
- for (const field of ["clientRefundId", "orderId", "registerId", "sessionId", "clientOrderId", "cashierRef"]) {
1137
- const value = payload[field];
1138
- if (["clientOrderId", "cashierRef"].includes(field) && value === void 0) continue;
1139
- check2(
1140
- typeof value === "string" && value.length > 0 && value.length <= 64,
1141
- field,
1142
- "a non-empty string of at most 64 characters"
1143
- );
1144
- noNul(value, field);
1145
- }
1146
- check2(Array.isArray(payload.lines) && payload.lines.length <= 500, "lines", "an array of at most 500 lines");
1147
- const seen = /* @__PURE__ */ new Set();
1148
- if (Array.isArray(payload.lines)) payload.lines.forEach((line, index) => {
1149
- const path = `lines[${index}]`;
1150
- if (!isPlainObject(line)) {
1151
- check2(false, path, "an object");
1152
- return;
1153
- }
1154
- for (const key of Object.keys(line)) {
1155
- if (!["orderLineId", "quantity", "restock"].includes(key) && errors.length < 10) {
1156
- errors.push(`${path}.${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.refund version 1`);
1157
- }
1158
- }
1159
- check2(
1160
- typeof line.orderLineId === "string" && line.orderLineId.length > 0 && line.orderLineId.length <= 64,
1161
- `${path}.orderLineId`,
1162
- "a non-empty string of at most 64 characters"
1163
- );
1164
- noNul(line.orderLineId, `${path}.orderLineId`);
1165
- if (typeof line.orderLineId === "string") {
1166
- check2(!seen.has(line.orderLineId), `${path}.orderLineId`, "unique in lines");
1167
- seen.add(line.orderLineId);
1168
- }
1169
- check2(Number.isSafeInteger(line.quantity) && line.quantity >= 1, `${path}.quantity`, "a safe integer >= 1");
1170
- check2(typeof line.restock === "boolean", `${path}.restock`, "a boolean");
1171
- });
1172
- for (const field of ["shippingMinor", "totalMinor"]) {
1173
- check2(Number.isSafeInteger(payload[field]) && payload[field] >= 0, field, "a safe integer >= 0");
1174
- }
1175
- check2(Number.isSafeInteger(payload.adjustmentMinor), "adjustmentMinor", "a safe integer");
1176
- check2(payload.destination === "original_method" || payload.destination === "cash", "destination", "original_method or cash");
1177
- noNul(payload.destination, "destination");
1178
- check2(
1179
- typeof payload.reason === "string" && payload.reason.trim().length > 0 && payload.reason.length <= 500,
1180
- "reason",
1181
- "a non-empty string after trim of at most 500 characters"
1182
- );
1183
- noNul(payload.reason, "reason");
1184
- check2(
1185
- typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
1186
- "createdAt",
1187
- "a valid date"
1188
- );
1189
- noNul(payload.createdAt, "createdAt");
1190
- return errors;
1191
- }
1192
-
1193
- // src/server/reopen-payload-shape.ts
1194
- function reopenPayloadErrors(payload) {
1195
- const { errors, check: check2, noNul } = shapeErrors();
1196
- if (!isPlainObject(payload)) return ["payload: expected an object"];
1197
- const fields = ["orderId", "clientOrderId", "baseRevision", "cashierRef", "registerId", "storeId", "createdAt"];
1198
- for (const key of Object.keys(payload)) {
1199
- if (!fields.includes(key) && errors.length < 10) {
1200
- errors.push(`${key.includes("\0") ? JSON.stringify(key) : key}: unknown field for order.reopen version 1`);
1201
- }
1202
- }
1203
- for (const field of ["orderId", "cashierRef", "registerId", "clientOrderId", "baseRevision", "storeId"]) {
1204
- const value = payload[field];
1205
- if (["clientOrderId", "baseRevision", "storeId"].includes(field) && value === void 0) continue;
1206
- const max = field === "baseRevision" ? 128 : 64;
1207
- check2(
1208
- typeof value === "string" && value.length > 0 && value.length <= max,
1209
- field,
1210
- `a non-empty string of at most ${max} characters`
1211
- );
1212
- noNul(value, field);
1213
- }
1214
- check2(
1215
- typeof payload.createdAt === "string" && payload.createdAt.length > 0 && !Number.isNaN(Date.parse(payload.createdAt)),
1216
- "createdAt",
1217
- "a valid date"
1218
- );
1219
- noNul(payload.createdAt, "createdAt");
1220
- return errors;
1221
- }
1222
-
1223
1228
  // src/server/register-figures.ts
1224
1229
  function deriveSessionFigures(input) {
1225
1230
  const expected = Object.assign(/* @__PURE__ */ Object.create(null), { cash: input.countedFloatMinor });
@@ -871,8 +871,10 @@ declare function validateBatch(body: unknown): {
871
871
  * claim, in the executor (order.create; register commands follow ADR-068). It pushes any result
872
872
  * one of those steps returns and moves on.
873
873
  *
874
- * For order.update the shape check is updatePayloadErrors (ADR-090): it adds the update's store ids, and below
875
- * createVersion 5 precheckCommand does not repeat it.
874
+ * For order.update the shape check is updatePayloadErrors (ADR-090): it adds the update's store ids; for order.refund
875
+ * refundPayloadErrors, for order.reopen reopenPayloadErrors, for a register command registerPayloadErrors.
876
+ * precheckCommand repeats the shape check for every command type at every version, after the version answer, as a
877
+ * backstop (#1344, #1346): for order.update's create part too.
876
878
  *
877
879
  * The replay lookup goes before precheckCommand so an already-applied command always replays
878
880
  * as `duplicate`, even once a later @tallyui/core tightens what precheckCommand accepts.