@tallyui/core 3.20.1 → 4.0.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.
Files changed (43) hide show
  1. package/dist/chunk-XF3RD6GX.js +515 -0
  2. package/dist/index.d.ts +41 -47
  3. package/dist/index.js +119 -101
  4. package/dist/server/index.cjs +1923 -0
  5. package/dist/server/index.d.cts +1039 -0
  6. package/dist/server/index.d.ts +46 -48
  7. package/dist/server/index.js +516 -206
  8. package/dist/{command-result-E_nH57WD.d.ts → tax-rate-DCJhfJbZ.d.ts} +442 -26
  9. package/package.json +10 -5
  10. package/src/commands.ts +12 -0
  11. package/src/context/money-format-context.tsx +50 -0
  12. package/src/coupons/woocommerce/to-coupon-configs.ts +5 -8
  13. package/src/fnv1a32.ts +14 -0
  14. package/src/index.ts +18 -5
  15. package/src/known-warnings.ts +23 -0
  16. package/src/money.ts +85 -2
  17. package/src/server/batch.ts +63 -27
  18. package/src/server/command-result.ts +28 -1
  19. package/src/server/display-signalling/contract.ts +203 -78
  20. package/src/server/display-signalling/memory-server.ts +71 -23
  21. package/src/server/fiscal-figures.ts +1 -1
  22. package/src/server/index.ts +5 -1
  23. package/src/server/money.ts +4 -1
  24. package/src/server/order-payload-shape.ts +96 -5
  25. package/src/server/refund-payload-shape.ts +5 -11
  26. package/src/server/register-payload-shape.ts +6 -12
  27. package/src/server/rejection-codes.ts +4 -4
  28. package/src/server/reopen-payload-shape.ts +25 -0
  29. package/src/server/shape-errors.ts +17 -0
  30. package/src/server/tax-rate.ts +13 -0
  31. package/src/server/update-payload-shape.ts +51 -0
  32. package/src/server/versions.ts +9 -2
  33. package/src/types/closures.ts +34 -0
  34. package/src/types/commands.ts +93 -8
  35. package/src/types/connector.ts +37 -4
  36. package/src/types/display-signalling.ts +30 -14
  37. package/src/types/index.ts +6 -3
  38. package/src/types/orders.ts +25 -3
  39. package/src/types/payment-methods.ts +17 -0
  40. package/src/types/stock.ts +2 -0
  41. package/src/types/store-settings.ts +7 -0
  42. package/src/types/traits/product.ts +19 -0
  43. package/dist/chunk-27L7XLTT.js +0 -235
@@ -1,15 +1,8 @@
1
- import { H as CommandError, an as OrderCreatePayload, G as CommandEnvelope, aR as RegisterCommandEnvelope, A as AnyCommandEnvelope, J as CommandResult, B as BatchTooLargeBody, F as CommandBatchResponse, C as CommandWarning, aS as RegisterCommandResult, ay as OrderRefundRejectionCode, a8 as DisplaySignalling, d as SyncContext, a9 as DisplaySignallingContext } from '../command-result-E_nH57WD.js';
2
- export { K as CommandResultError, af as MAX_COMMANDS_PER_BATCH, ag as ORDER_NOTE_MAX, ak as OrderCreateDisplay, ap as OrderCreateTaxRate, bq as parseCommandResult } from '../command-result-E_nH57WD.js';
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';
3
3
  import 'rxdb';
4
4
  import 'rxjs';
5
5
 
6
- /** ISO 4217 minor-unit exponent as resolved by Intl (which rejects malformed codes); depends on the runtime's ICU data. */
7
- declare function currencyDecimals(currency: string): number;
8
- /** Converts a safe integer minor amount to an exact major-unit decimal string. */
9
- declare function minorToMajor(minor: number, decimals: number): string;
10
- /** Rounds a major-unit decimal to minor units, half away from zero, without float scaling. */
11
- declare function majorToMinor(value: string | number, decimals: number): number;
12
-
13
6
  /** JSON with recursively sorted object keys; arrays keep their order. */
14
7
  declare function canonicalJson(value: unknown): string;
15
8
  /** Lower-case hex SHA-256 of the canonical command content. */
@@ -27,9 +20,10 @@ declare function commandFingerprint(envelope: {
27
20
  * runs last, so the earlier checks' errors keep their order. */
28
21
  declare function payloadShapeErrors(payload: unknown): string[];
29
22
  /** Length-bound errors of an order.create payload, e.g. ['lines[0].title: expected at most 255
30
- * characters']; [] when every string is within its bound, at most ten. Bounds in UTF-16 code units:
23
+ * characters']; [] when every bound holds, at most ten. Bounds in UTF-16 code units:
31
24
  * `note` ORDER_NOTE_MAX (1000), `customer.email` 254, v8 address fields 255, v5 ids 36 and class/sku/method 64, other strings 255 (`customerId` and `sessionId` keep theirs in
32
- * payloadShapeErrors); only strings are checked. A plugin calls it through precheckCommand, after
25
+ * payloadShapeErrors); v12 (ADR-092) tax id type 32, value 64 and country 2, a line's `sku` 100, meta key 255 and value ORDER_NOTE_MAX.
26
+ * Each coupon's lines array is also capped at payload.lines.length, `customer.taxIds` at 10 entries and `meta` at 50. A plugin calls it through precheckCommand, after
33
27
  * its replay lookup, so a bound tightened later never turns an applied command's resend into
34
28
  * `invalid_payload`. */
35
29
  declare function payloadBoundErrors(payload: unknown): string[];
@@ -38,7 +32,7 @@ declare function payloadBoundErrors(payload: unknown): string[];
38
32
  type CommandErrorWithData = CommandError;
39
33
  /** @deprecated Use `OrderCreatePayload` from `@tallyui/core`; kept for plugins migrating from local copies. */
40
34
  type OrderCreatePayloadV3 = OrderCreatePayload;
41
- declare function fiscalFiguresErrors(payload: OrderCreatePayloadV3): string[];
35
+ declare function fiscalFiguresErrors(payload: OrderCreatePayload): string[];
42
36
 
43
37
  /**
44
38
  * The till's capability: the order.create versions `toOrderCreateEnvelope` can produce. It is not what a server
@@ -47,13 +41,20 @@ declare function fiscalFiguresErrors(payload: OrderCreatePayloadV3): string[];
47
41
  * advertises it only once it handles it.
48
42
  * 5 (ADR-075) adds fees, shipping and custom lines; 6 (ADR-077) adds coupons, regular prices, line
49
43
  * attributes and Any picks (#495); a plugin advertises each only once it handles it.
50
- * 7 (ADR-083) adds the sale note; 8 (#722) adds `taxAddress` and the customer's addresses.
44
+ * 7 (ADR-083) adds the sale note; 8 (#722) adds `taxAddress` and the customer's addresses; 9 (#790) adds each coupon's per-line amounts.
45
+ * 10 adds each payment's methodId (ruling A, 2026-11-18).
46
+ * 11 is 10 plus the customer's billing and shipping on a sale not taxed by address (ADR-086 d2 as amended 2026-11-19).
47
+ * 12 is 11 plus the customer's tax ids, a catalogue line's edited SKU and order meta, as informational fields (ADR-092).
51
48
  */
52
49
  declare const SUPPORTED_ORDER_CREATE_VERSIONS: readonly number[];
53
50
  /** The till's capability for the contract versions shared by all five register commands; a server passes its own. */
54
51
  declare const SUPPORTED_REGISTER_VERSIONS: readonly number[];
55
52
  /** The till's capability for order.refund versions (ADR-080); a server passes its own. */
56
53
  declare const SUPPORTED_ORDER_REFUND_VERSIONS: readonly number[];
54
+ /** The till's capability for order.reopen versions (ADR-090); a server passes its own. */
55
+ declare const SUPPORTED_ORDER_REOPEN_VERSIONS: readonly number[];
56
+ /** The till's capability for order.update versions (ADR-090); a server passes its own. */
57
+ declare const SUPPORTED_ORDER_UPDATE_VERSIONS: readonly number[];
57
58
 
58
59
  /** An envelope validateBatch accepted: every field's shape is checked, and its version is any positive
59
60
  * safe integer (precheckCommand decides which versions this server supports). */
@@ -63,6 +64,12 @@ type ValidatedCommandEnvelope = (Omit<CommandEnvelope<Record<string, unknown>>,
63
64
  }) | RegisterCommandEnvelope<Record<string, unknown>> | (Omit<CommandEnvelope<Record<string, unknown>>, 'type' | 'version'> & {
64
65
  type: 'order.refund';
65
66
  version: number;
67
+ }) | (Omit<CommandEnvelope<Record<string, unknown>>, 'type' | 'version'> & {
68
+ type: 'order.reopen';
69
+ version: number;
70
+ }) | (Omit<CommandEnvelope<Record<string, unknown>>, 'type' | 'version'> & {
71
+ type: 'order.update';
72
+ version: number;
66
73
  });
67
74
  /** Validates every envelope before any command is claimed. */
68
75
  declare function validateBatch(body: unknown): {
@@ -88,17 +95,22 @@ declare function validateBatch(body: unknown): {
88
95
  * claim, in the executor (order.create; register commands follow ADR-068). It pushes any result
89
96
  * one of those steps returns and moves on.
90
97
  *
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.
100
+ *
91
101
  * The replay lookup goes before precheckCommand so an already-applied command always replays
92
102
  * as `duplicate`, even once a later @tallyui/core tightens what precheckCommand accepts.
93
103
  *
94
104
  * `supported` is the SERVER's own list (what its /info advertises), never core's constants, which are the
95
105
  * till's capability (#297). The version check, the `unsupported_version` message and its `data` all use it:
96
- * `precheckCommand(envelope, { orderCreate: [1, 2, 3], register: [1], orderRefund: [1] })` (`orderRefund` is optional).
106
+ * `precheckCommand(envelope, { orderCreate: [1, 2, 3], register: [1], orderRefund: [1], orderReopen: [1], orderUpdate: [1] })` (`orderRefund`, `orderReopen` and `orderUpdate` are optional).
97
107
  */
98
108
  declare function precheckCommand(envelope: Pick<AnyCommandEnvelope | ValidatedCommandEnvelope, 'id' | 'type' | 'version' | 'payload'>, supported: {
99
109
  orderCreate: readonly number[];
100
110
  register: readonly number[];
101
111
  orderRefund?: readonly number[];
112
+ orderReopen?: readonly number[];
113
+ orderUpdate?: readonly number[];
102
114
  }): CommandResult | undefined;
103
115
 
104
116
  /**
@@ -139,36 +151,11 @@ declare function registerPayloadErrors(type: string, payload: unknown): string[]
139
151
  /** Strict shape errors per ADR-070 and ADR-080 for order.refund v1; plugins run this before any lookup. */
140
152
  declare function refundPayloadErrors(payload: unknown): string[];
141
153
 
142
- /**
143
- * A session's expected figures per method: the counted float in cash, plus each order's payments, plus paid_in
144
- * and minus paid_out movements that are not voided. The plugin chooses which orders count (for Medusa: completed,
145
- * archived and cancelled POS orders, so a received sale stays counted after an admin archives or cancels it) and
146
- * passes each order's recorded POS payments; this function only sums. Refunds made in the session (by the refund's
147
- * own sessionId, ADR-080) lower expected per method.
148
- */
149
- declare function deriveSessionFigures(input: {
150
- countedFloatMinor: number;
151
- orders: {
152
- payments: {
153
- method: string;
154
- amountMinor: number;
155
- }[];
156
- }[];
157
- movements: {
158
- id: string;
159
- type: 'paid_in' | 'paid_out' | 'no_sale' | 'void';
160
- amountMinor: number;
161
- voids: string | null;
162
- }[];
163
- refunds?: {
164
- byMethod: Record<string, number>;
165
- }[];
166
- }): {
167
- expected: Record<string, number>;
168
- salesCount: number;
169
- refundsTotalMinor?: number;
170
- };
171
- declare function deriveVariance(counted: Record<string, number>, expected: Record<string, number>): Record<string, number>;
154
+ /** Strict shape errors per ADR-070 and ADR-090 for order.reopen v1; plugins run this before any lookup. */
155
+ declare function reopenPayloadErrors(payload: unknown): string[];
156
+
157
+ /** Strict update identity and order.create body shape errors, at most ten (ADR-090). */
158
+ declare function updatePayloadErrors(payload: unknown): string[];
172
159
 
173
160
  type RegisterConflictCode = 'register_session_already_open' | 'register_session_superseded' | 'register_supersede_forbidden' | 'register_session_closed' | 'register_closure_exists' | 'register_closure_number_invalid' | 'register_approval_required' | 'register_approval_invalid';
174
161
  type RegisterOutcome = {
@@ -184,11 +171,11 @@ type RegisterOutcome = {
184
171
  };
185
172
 
186
173
  /** Every error.code a plugin may put on a rejected result (ADR-038 and its amendments, ADR-068, ADR-082). */
187
- type CommandRejectionCode = 'invalid_payload' | 'unsupported_version' | 'idempotency_mismatch' | 'store_configuration' | 'platform_error' | 'insufficient_stock' | 'unsupported_tax_mode' | 'internal_error' | 'coupon_invalid' | 'total_mismatch' | OrderRejectionCode | RegisterConflictCode | OrderRefundRejectionCode;
174
+ type CommandRejectionCode = 'invalid_payload' | 'unsupported_version' | 'idempotency_mismatch' | 'store_configuration' | 'platform_error' | 'insufficient_stock' | 'unsupported_tax_mode' | 'internal_error' | 'coupon_invalid' | 'total_mismatch' | OrderRejectionCode | RegisterConflictCode | OrderRefundRejectionCode | OrderReopenRejectionCode | OrderUpdateRejectionCode;
188
175
  /**
189
176
  * The rejected result for a platform-native error the plugin has judged permanent (a replay would fail
190
177
  * the same way, e.g. a Vendure ErrorResult code) and the contract has no code for. `platform_error` is
191
- * for `order.create` and `order.refund` (ADR-080): a rejected register command halts that register's queue until c2c,
178
+ * for `order.create` and `order.refund` (ADR-080) and `order.reopen` and `order.update` (ADR-090): a rejected register command halts that register's queue until c2c,
192
179
  * so register refusals use the ADR-068 codes.
193
180
  *
194
181
  * Return it only when the platform made no durable change for this command: the plugin threw so its
@@ -212,7 +199,7 @@ declare function platformErrorResult(id: string, platformCode: string, platformM
212
199
  * the correlation id links it to the plugin's log.
213
200
  *
214
201
  * Database, network, unknown-SQLSTATE and any other unclassifiable errors stay transient (503), never
215
- * `internal_error`. `order.create` and `order.refund` (ADR-080), as for `platform_error`.
202
+ * `internal_error`. `order.create` and `order.refund` (ADR-080) and `order.reopen` and `order.update` (ADR-090), as for `platform_error`.
216
203
  *
217
204
  * See ADR-038's `internal_error` amendment (needs-admin on a failed compensation; on Vendure only
218
205
  * before the first write).
@@ -238,7 +225,18 @@ interface DisplaySignallingHarness {
238
225
  pending: number;
239
226
  displays: number;
240
227
  snapshots: number;
228
+ devices: number;
229
+ }>;
230
+ /** Writes a pre-migration till: a device with no key, owning one paired display with a token. */
231
+ seedLegacyDevice(deviceId: string): Promise<{
232
+ displayId: string;
233
+ token: string;
241
234
  }>;
235
+ /** Every adoption of a pre-migration device id by `registerDevice`, in order. */
236
+ adoptionLog(): Promise<Array<{
237
+ deviceId: string;
238
+ cashierId: string;
239
+ }>>;
242
240
  }
243
241
  /** The ADR-085 U2 reference server: every rule of the seam, in memory, with lazy pruning on every call. */
244
242
  declare function createMemoryDisplaySignalling(options?: {
@@ -258,4 +256,4 @@ declare function displaySignallingContract(makeHarness: () => Promise<DisplaySig
258
256
  run: () => Promise<void>;
259
257
  }>;
260
258
 
261
- 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_REGISTER_VERSIONS, type ValidatedCommandEnvelope, canonicalJson, commandFingerprint, createMemoryDisplaySignalling, currencyDecimals, deriveSessionFigures, deriveVariance, displaySignallingContract, fiscalFiguresErrors, inProgressOutcome, internalErrorResult, majorToMinor, minorToMajor, payloadBoundErrors, payloadShapeErrors, platformErrorResult, precheckCommand, refundPayloadErrors, registerPayloadErrors, totalWarnings, transientOutcome, validateBatch };
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 };