@tallyui/core 4.2.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.
@@ -100,6 +100,7 @@ type OrderRefundEnvelope<P = OrderRefundPayload> = Omit<CommandEnvelope<P>, 'typ
100
100
  interface OrderRefundResult {
101
101
  totalMinor: number;
102
102
  byMethod: Record<string, number>;
103
+ /** The platform refunds created, summing to totalMinor. Empty only for a stock-only return: totalMinor 0 and byMethod {} (ADR-080, #1330). */
103
104
  refunds: Array<{
104
105
  id: string;
105
106
  paymentId: string;
@@ -306,7 +307,7 @@ interface RegisterCommandResult {
306
307
  deviceId?: string;
307
308
  deviceName?: string;
308
309
  };
309
- /** The register's counters: a floor for the till's own, never lowered. */
310
+ /** The register's counters: a floor for the till's own, never lowered, with two exceptions for perpetual refunds. The till raises refunds only from answers at the highest closure number among the store's answers, and sets them to the largest store figure at its newest applied closure once nothing of its own is unsent (@tallyui/pos settleStoreRefunds). A closure refused for its number resets the counters outright (@tallyui/pos renumberClosures). */
310
311
  counters?: {
311
312
  lastClosureNumber: number;
312
313
  perpetualSalesTotalMinor: number;
@@ -490,6 +491,11 @@ interface OrderCreatePayload {
490
491
  taxMinor: number;
491
492
  totalMinor: number;
492
493
  payments: OrderCreatePayment[];
494
+ /** ADR-094: each cash leg's signed rounding, in minor units, already summed into `totalMinor`; sent at the order's content version, only for an order that has one, and only to a store whose connector declares `cashRounding` (a server without it refuses the field). */
495
+ cashRoundings?: Array<{
496
+ paymentId: string;
497
+ minor: number;
498
+ }>;
493
499
  /** Version 3+; both or neither. */
494
500
  display?: OrderCreateDisplay;
495
501
  /** Version 3+; both or neither. */
@@ -555,6 +561,28 @@ type BatchTooLargeBody = {
555
561
  message: string;
556
562
  };
557
563
 
564
+ /** A line of an order the store holds (ADR-081). Money in integer minor units of the order's currency, as the store
565
+ * records it: every amount excludes tax, and the tax is beside it.
566
+ * Each tax field is such that net + tax is the gross rounded once. */
567
+ interface StoreOrderLine {
568
+ /** The store's line id: what `OrderRefundLine.orderLineId` names. */
569
+ id: string;
570
+ /** The till's line id when a till created the line (its `clientLineId`); absent otherwise. */
571
+ clientLineId?: string;
572
+ productId?: string;
573
+ /** The sellable the till's `variantId` names (a WooCommerce variation, or the product itself when simple). */
574
+ variantId?: string;
575
+ name: string;
576
+ sku?: string;
577
+ quantity: number;
578
+ /** Before discounts, excluding tax. */
579
+ subtotalMinor: number;
580
+ subtotalTaxMinor: number;
581
+ /** After discounts, excluding tax. */
582
+ totalMinor: number;
583
+ taxMinor: number;
584
+ }
585
+
558
586
  /** One ICE server, in the shape `RTCPeerConnection` takes (ADR-085 d7). */
559
587
  interface IceServer {
560
588
  urls: string | string[];
@@ -734,6 +762,8 @@ interface ServerCapabilities {
734
762
  receiptEmail?: number;
735
763
  /** The platform plugin's own contract version, from `/tally/v1/info`'s top-level `pluginContract` (#1114). Absent when not sent or malformed; each connector says what a version adds. */
736
764
  pluginContract?: number;
765
+ /** True only when the store's connector carries order.create's `cashRoundings` (ADR-094). Absent: the till never rounds a cash leg, and finalize refuses an order with entries. */
766
+ cashRounding?: boolean;
737
767
  }
738
768
  /** #287, ADR-071. `custom`: the till computes as when absent; that server never emits `figures_mismatch` for subtotal or tax. */
739
769
  type TaxRounding = {
@@ -782,7 +812,11 @@ declare function fiscalFiguresErrors(payload: OrderCreatePayload): string[];
782
812
  * 12 is 11 plus the customer's tax ids, a catalogue line's edited SKU and order meta, as informational fields (ADR-092).
783
813
  */
784
814
  declare const SUPPORTED_ORDER_CREATE_VERSIONS: readonly number[];
785
- /** The till's capability for the contract versions shared by all five register commands; a server passes its own. */
815
+ /**
816
+ * The till's capability for the contract versions shared by all five register commands; a server passes its own.
817
+ * The till builds 1 (every command), 2 (session.open, contract ≥ 2) and 3 (session.open and closure.submit,
818
+ * contract ≥ 3; ADR-082).
819
+ */
786
820
  declare const SUPPORTED_REGISTER_VERSIONS: readonly number[];
787
821
  /** The till's capability for order.refund versions (ADR-080); a server passes its own. */
788
822
  declare const SUPPORTED_ORDER_REFUND_VERSIONS: readonly number[];
@@ -795,6 +829,8 @@ declare const SUPPORTED_ORDER_UPDATE_VERSIONS: readonly number[];
795
829
  declare const MAX_COMMANDS_PER_BATCH = 50;
796
830
  /** The longest order.create `note` (version 7, ADR-083), in UTF-16 code units. WCPOS v2's order note has no cap; this bounds the wire. */
797
831
  declare const ORDER_NOTE_MAX = 1000;
832
+ /** The most UTF-16 units of a `needs_admin` message the till keeps and shows (TallyUI #1280). */
833
+ declare const NEEDS_ADMIN_MESSAGE_MAX = 500;
798
834
 
799
835
  /** An envelope validateBatch accepted: every field's shape is checked, and its version is any positive
800
836
  * safe integer (precheckCommand decides which versions this server supports). */
@@ -835,8 +871,10 @@ declare function validateBatch(body: unknown): {
835
871
  * claim, in the executor (order.create; register commands follow ADR-068). It pushes any result
836
872
  * one of those steps returns and moves on.
837
873
  *
838
- * For order.update the shape check is updatePayloadErrors (ADR-090): it adds the update's store ids, and below
839
- * 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.
840
878
  *
841
879
  * The replay lookup goes before precheckCommand so an already-applied command always replays
842
880
  * as `duplicate`, even once a later @tallyui/core tightens what precheckCommand accepts.
@@ -844,6 +882,8 @@ declare function validateBatch(body: unknown): {
844
882
  * `supported` is the SERVER's own list (what its /info advertises), never core's constants, which are the
845
883
  * till's capability (#297). The version check, the `unsupported_version` message and its `data` all use it:
846
884
  * `precheckCommand(envelope, { orderCreate: [1, 2, 3], register: [1], orderRefund: [1], orderReopen: [1], orderUpdate: [1] })` (`orderRefund`, `orderReopen` and `orderUpdate` are optional).
885
+ * `cashRounding` is the server's own word too (ADR-094): without `true`, an order.create (or an order.update's create part)
886
+ * carrying `cashRoundings` is refused as `invalid_payload`, never sent on with the field dropped, which would be a wrong total.
847
887
  */
848
888
  declare function precheckCommand(envelope: Pick<AnyCommandEnvelope | ValidatedCommandEnvelope, 'id' | 'type' | 'version' | 'payload'>, supported: {
849
889
  orderCreate: readonly number[];
@@ -851,6 +891,7 @@ declare function precheckCommand(envelope: Pick<AnyCommandEnvelope | ValidatedCo
851
891
  orderRefund?: readonly number[];
852
892
  orderReopen?: readonly number[];
853
893
  orderUpdate?: readonly number[];
894
+ cashRounding?: boolean;
854
895
  }): CommandResult | undefined;
855
896
 
856
897
  /**
@@ -866,6 +907,14 @@ type BatchOutcome = {
866
907
  code: 'in_progress';
867
908
  id: string;
868
909
  };
910
+ } | {
911
+ status: 409;
912
+ body: {
913
+ code: 'needs_admin';
914
+ id: string;
915
+ reason: string;
916
+ message: string;
917
+ };
869
918
  } | {
870
919
  status: 503;
871
920
  body: {
@@ -875,6 +924,8 @@ type BatchOutcome = {
875
924
  };
876
925
  };
877
926
  declare function inProgressOutcome(id: string): BatchOutcome;
927
+ /** A command an admin must finish (TallyUI #1280). `reason` is snake_case; `message` is cut to NEEDS_ADMIN_MESSAGE_MAX. */
928
+ declare function needsAdminOutcome(id: string, reason: string, message: string): BatchOutcome;
878
929
  /** The message is fixed so a server never leaks its internal error (log that separately). */
879
930
  declare function transientOutcome(id: string): BatchOutcome;
880
931
 
@@ -1036,4 +1087,57 @@ declare function displaySignallingContract(makeHarness: () => Promise<DisplaySig
1036
1087
  run: () => Promise<void>;
1037
1088
  }>;
1038
1089
 
1039
- export { type BatchOutcome, type BatchTooLargeBody, type CommandErrorWithData, type CommandRejectionCode, CommandResultError, type DisplaySignallingHarness, MAX_COMMANDS_PER_BATCH, ORDER_NOTE_MAX, type OrderCreateDisplay, type OrderCreatePayloadV3, type OrderCreateTaxRate, type OrderRejectionCode, type RegisterConflictCode, type RegisterOutcome, type Rejection, SUPPORTED_ORDER_CREATE_VERSIONS, SUPPORTED_ORDER_REFUND_VERSIONS, SUPPORTED_ORDER_REOPEN_VERSIONS, SUPPORTED_ORDER_UPDATE_VERSIONS, SUPPORTED_REGISTER_VERSIONS, type ValidatedCommandEnvelope, canonicalJson, commandFingerprint, createMemoryDisplaySignalling, currencyDecimals, deriveSessionFigures, deriveVariance, displaySignallingContract, fiscalFiguresErrors, inProgressOutcome, internalErrorResult, majorToMinor, minorToMajor, minorUnitDigits, parseCommandResult, payloadBoundErrors, payloadShapeErrors, platformErrorResult, precheckCommand, ratePpmFromPercent, refundPayloadErrors, registerPayloadErrors, reopenPayloadErrors, totalWarnings, transientOutcome, updatePayloadErrors, validateBatch };
1090
+ /** #287: `half_up` is Math.round's rule, Vendure's DefaultMoneyStrategy (default-money-strategy.js:19-21). */
1091
+ type RoundingMode = 'half_away_from_zero' | 'half_up';
1092
+ /** `n / d` (d > 0) rounded to an integer in `mode`, exactly; the modes differ only on exact negative halves. */
1093
+ declare function roundRatio(n: bigint, d: bigint, mode?: RoundingMode): bigint;
1094
+
1095
+ /**
1096
+ * Ports v2 calculate-refund.ts (calculateLineItemRefund, computeRemainingRefundQuantity).
1097
+ * Amounts follow ADR-080 amendment 2's cumulative-share rule.
1098
+ */
1099
+
1100
+ /** The fields of an order line this needs; a StoreOrderLine fits. */
1101
+ type RefundableOrderLine = Pick<StoreOrderLine, 'id' | 'quantity' | 'totalMinor' | 'taxMinor'>;
1102
+ /** Earlier refund lines; negative quantities count by magnitude. */
1103
+ interface EarlierRefund {
1104
+ lines: ReadonlyArray<Pick<OrderRefundLine, 'orderLineId' | 'quantity'>>;
1105
+ }
1106
+ /** Remaining quantities and amounts, with earlier refund magnitudes capped at the line quantity. */
1107
+ interface RefundableLine {
1108
+ orderLineId: string;
1109
+ refundedQuantity: number;
1110
+ refundableQuantity: number;
1111
+ netMinor: number;
1112
+ taxMinor: number;
1113
+ }
1114
+ /** A selected quantity's cumulative shares of net and tax, and their sum. */
1115
+ interface PricedRefundLine {
1116
+ orderLineId: string;
1117
+ quantity: number;
1118
+ netMinor: number;
1119
+ taxMinor: number;
1120
+ totalMinor: number;
1121
+ }
1122
+ /** Payload-ready lines and their amounts; the caller adds shipping and adjustment to totalMinor. */
1123
+ interface PricedRefund {
1124
+ /** Exactly orderLineId, quantity (>= 1), and restock. */
1125
+ lines: OrderRefundLine[];
1126
+ /** Amounts in the same order as lines. */
1127
+ priced: PricedRefundLine[];
1128
+ /** Requests cut to availability, including unknown lines cut to zero. */
1129
+ clamped: Array<{
1130
+ orderLineId: string;
1131
+ requestedQuantity: number;
1132
+ quantity: number;
1133
+ }>;
1134
+ netMinor: number;
1135
+ taxMinor: number;
1136
+ totalMinor: number;
1137
+ }
1138
+ /** Returns the quantities and amounts still refundable, in order-line order. */
1139
+ declare function refundableLines(lines: readonly RefundableOrderLine[], refunds: readonly EarlierRefund[]): RefundableLine[];
1140
+ /** Prices requested quantities with cumulative shares, clamping them to what remains refundable. */
1141
+ declare function priceRefund(lines: readonly RefundableOrderLine[], refunds: readonly EarlierRefund[], request: readonly OrderRefundLine[]): PricedRefund;
1142
+
1143
+ export { type BatchOutcome, type BatchTooLargeBody, type CommandErrorWithData, type CommandRejectionCode, CommandResultError, type DisplaySignallingHarness, type EarlierRefund, MAX_COMMANDS_PER_BATCH, NEEDS_ADMIN_MESSAGE_MAX, ORDER_NOTE_MAX, type OrderCreateDisplay, type OrderCreatePayloadV3, type OrderCreateTaxRate, type OrderRejectionCode, type PricedRefund, type PricedRefundLine, type RefundableLine, type RefundableOrderLine, type RegisterConflictCode, type RegisterOutcome, type Rejection, type RoundingMode, SUPPORTED_ORDER_CREATE_VERSIONS, SUPPORTED_ORDER_REFUND_VERSIONS, SUPPORTED_ORDER_REOPEN_VERSIONS, SUPPORTED_ORDER_UPDATE_VERSIONS, SUPPORTED_REGISTER_VERSIONS, type ValidatedCommandEnvelope, canonicalJson, commandFingerprint, createMemoryDisplaySignalling, currencyDecimals, deriveSessionFigures, deriveVariance, displaySignallingContract, fiscalFiguresErrors, inProgressOutcome, internalErrorResult, majorToMinor, minorToMajor, minorUnitDigits, needsAdminOutcome, parseCommandResult, payloadBoundErrors, payloadShapeErrors, platformErrorResult, precheckCommand, priceRefund, ratePpmFromPercent, refundPayloadErrors, refundableLines, registerPayloadErrors, reopenPayloadErrors, roundRatio, totalWarnings, transientOutcome, updatePayloadErrors, validateBatch };
@@ -1,5 +1,5 @@
1
- import { J as CommandError, ax as OrderCreatePayload, H as CommandEnvelope, bg as RegisterCommandEnvelope, A as AnyCommandEnvelope, K as CommandResult, B as BatchTooLargeBody, G as CommandBatchResponse, C as CommandWarning, bh as RegisterCommandResult, aJ as OrderRefundRejectionCode, aP as OrderReopenRejectionCode, aW as OrderUpdateRejectionCode, aa as DisplaySignalling, b as SyncContext, ab as DisplaySignallingContext } from '../tax-rate-DCJhfJbZ.js';
2
- export { N as CommandResultError, ah as MAX_COMMANDS_PER_BATCH, al as ORDER_NOTE_MAX, at as OrderCreateDisplay, aA as OrderCreateTaxRate, cd as currencyDecimals, bR as deriveSessionFigures, bS as deriveVariance, ce as majorToMinor, bX as minorToMajor, bY as minorUnitDigits, c3 as parseCommandResult, c8 as ratePpmFromPercent } from '../tax-rate-DCJhfJbZ.js';
1
+ import { J as CommandError, aA as OrderCreatePayload, H as CommandEnvelope, bo as RegisterCommandEnvelope, A as AnyCommandEnvelope, K as CommandResult, B as BatchTooLargeBody, G as CommandBatchResponse, C as CommandWarning, bp as RegisterCommandResult, aM as OrderRefundRejectionCode, aS as OrderReopenRejectionCode, aZ as OrderUpdateRejectionCode, aa as DisplaySignalling, b as SyncContext, ab as DisplaySignallingContext } from '../refund-share-Cv_TgE1p.js';
2
+ export { N as CommandResultError, ae as EarlierRefund, aj as MAX_COMMANDS_PER_BATCH, ak as NEEDS_ADMIN_MESSAGE_MAX, ao as ORDER_NOTE_MAX, aw as OrderCreateDisplay, aD as OrderCreateTaxRate, bb as PricedRefund, bc as PricedRefundLine, bi as RefundableLine, bj as RefundableOrderLine, bA as RoundingMode, cy as currencyDecimals, c7 as deriveSessionFigures, c8 as deriveVariance, cz as majorToMinor, cd as minorToMajor, ce as minorUnitDigits, cl as parseCommandResult, cq as priceRefund, cr as ratePpmFromPercent, cs as refundableLines, cw as roundRatio } from '../refund-share-Cv_TgE1p.js';
3
3
  import 'rxdb';
4
4
  import 'rxjs';
5
5
 
@@ -47,7 +47,11 @@ declare function fiscalFiguresErrors(payload: OrderCreatePayload): string[];
47
47
  * 12 is 11 plus the customer's tax ids, a catalogue line's edited SKU and order meta, as informational fields (ADR-092).
48
48
  */
49
49
  declare const SUPPORTED_ORDER_CREATE_VERSIONS: readonly number[];
50
- /** The till's capability for the contract versions shared by all five register commands; a server passes its own. */
50
+ /**
51
+ * The till's capability for the contract versions shared by all five register commands; a server passes its own.
52
+ * The till builds 1 (every command), 2 (session.open, contract ≥ 2) and 3 (session.open and closure.submit,
53
+ * contract ≥ 3; ADR-082).
54
+ */
51
55
  declare const SUPPORTED_REGISTER_VERSIONS: readonly number[];
52
56
  /** The till's capability for order.refund versions (ADR-080); a server passes its own. */
53
57
  declare const SUPPORTED_ORDER_REFUND_VERSIONS: readonly number[];
@@ -95,8 +99,10 @@ declare function validateBatch(body: unknown): {
95
99
  * claim, in the executor (order.create; register commands follow ADR-068). It pushes any result
96
100
  * one of those steps returns and moves on.
97
101
  *
98
- * For order.update the shape check is updatePayloadErrors (ADR-090): it adds the update's store ids, and below
99
- * createVersion 5 precheckCommand does not repeat it.
102
+ * For order.update the shape check is updatePayloadErrors (ADR-090): it adds the update's store ids; for order.refund
103
+ * refundPayloadErrors, for order.reopen reopenPayloadErrors, for a register command registerPayloadErrors.
104
+ * precheckCommand repeats the shape check for every command type at every version, after the version answer, as a
105
+ * backstop (#1344, #1346): for order.update's create part too.
100
106
  *
101
107
  * The replay lookup goes before precheckCommand so an already-applied command always replays
102
108
  * as `duplicate`, even once a later @tallyui/core tightens what precheckCommand accepts.
@@ -104,6 +110,8 @@ declare function validateBatch(body: unknown): {
104
110
  * `supported` is the SERVER's own list (what its /info advertises), never core's constants, which are the
105
111
  * till's capability (#297). The version check, the `unsupported_version` message and its `data` all use it:
106
112
  * `precheckCommand(envelope, { orderCreate: [1, 2, 3], register: [1], orderRefund: [1], orderReopen: [1], orderUpdate: [1] })` (`orderRefund`, `orderReopen` and `orderUpdate` are optional).
113
+ * `cashRounding` is the server's own word too (ADR-094): without `true`, an order.create (or an order.update's create part)
114
+ * carrying `cashRoundings` is refused as `invalid_payload`, never sent on with the field dropped, which would be a wrong total.
107
115
  */
108
116
  declare function precheckCommand(envelope: Pick<AnyCommandEnvelope | ValidatedCommandEnvelope, 'id' | 'type' | 'version' | 'payload'>, supported: {
109
117
  orderCreate: readonly number[];
@@ -111,6 +119,7 @@ declare function precheckCommand(envelope: Pick<AnyCommandEnvelope | ValidatedCo
111
119
  orderRefund?: readonly number[];
112
120
  orderReopen?: readonly number[];
113
121
  orderUpdate?: readonly number[];
122
+ cashRounding?: boolean;
114
123
  }): CommandResult | undefined;
115
124
 
116
125
  /**
@@ -126,6 +135,14 @@ type BatchOutcome = {
126
135
  code: 'in_progress';
127
136
  id: string;
128
137
  };
138
+ } | {
139
+ status: 409;
140
+ body: {
141
+ code: 'needs_admin';
142
+ id: string;
143
+ reason: string;
144
+ message: string;
145
+ };
129
146
  } | {
130
147
  status: 503;
131
148
  body: {
@@ -135,6 +152,8 @@ type BatchOutcome = {
135
152
  };
136
153
  };
137
154
  declare function inProgressOutcome(id: string): BatchOutcome;
155
+ /** A command an admin must finish (TallyUI #1280). `reason` is snake_case; `message` is cut to NEEDS_ADMIN_MESSAGE_MAX. */
156
+ declare function needsAdminOutcome(id: string, reason: string, message: string): BatchOutcome;
138
157
  /** The message is fixed so a server never leaks its internal error (log that separately). */
139
158
  declare function transientOutcome(id: string): BatchOutcome;
140
159
 
@@ -256,4 +275,4 @@ declare function displaySignallingContract(makeHarness: () => Promise<DisplaySig
256
275
  run: () => Promise<void>;
257
276
  }>;
258
277
 
259
- export { type BatchOutcome, BatchTooLargeBody, type CommandErrorWithData, type CommandRejectionCode, type DisplaySignallingHarness, type OrderCreatePayloadV3, type OrderRejectionCode, type RegisterConflictCode, type RegisterOutcome, type Rejection, SUPPORTED_ORDER_CREATE_VERSIONS, SUPPORTED_ORDER_REFUND_VERSIONS, SUPPORTED_ORDER_REOPEN_VERSIONS, SUPPORTED_ORDER_UPDATE_VERSIONS, SUPPORTED_REGISTER_VERSIONS, type ValidatedCommandEnvelope, canonicalJson, commandFingerprint, createMemoryDisplaySignalling, displaySignallingContract, fiscalFiguresErrors, inProgressOutcome, internalErrorResult, payloadBoundErrors, payloadShapeErrors, platformErrorResult, precheckCommand, refundPayloadErrors, registerPayloadErrors, reopenPayloadErrors, totalWarnings, transientOutcome, updatePayloadErrors, validateBatch };
278
+ export { type BatchOutcome, BatchTooLargeBody, type CommandErrorWithData, type CommandRejectionCode, type DisplaySignallingHarness, type OrderCreatePayloadV3, type OrderRejectionCode, type RegisterConflictCode, type RegisterOutcome, type Rejection, SUPPORTED_ORDER_CREATE_VERSIONS, SUPPORTED_ORDER_REFUND_VERSIONS, SUPPORTED_ORDER_REOPEN_VERSIONS, SUPPORTED_ORDER_UPDATE_VERSIONS, SUPPORTED_REGISTER_VERSIONS, type ValidatedCommandEnvelope, canonicalJson, commandFingerprint, createMemoryDisplaySignalling, displaySignallingContract, fiscalFiguresErrors, inProgressOutcome, internalErrorResult, needsAdminOutcome, payloadBoundErrors, payloadShapeErrors, platformErrorResult, precheckCommand, refundPayloadErrors, registerPayloadErrors, reopenPayloadErrors, totalWarnings, transientOutcome, updatePayloadErrors, validateBatch };