@classytic/pos 0.6.0 → 0.7.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 (71) hide show
  1. package/CHANGELOG.md +103 -0
  2. package/dist/commands/index.d.mts +2 -0
  3. package/dist/commands/index.mjs +1 -0
  4. package/dist/commands/pos-commands.d.mts +228 -0
  5. package/dist/commands/pos-commands.mjs +355 -0
  6. package/dist/domain/enums/cash-movement-reason.enum.d.mts +3 -4
  7. package/dist/domain/enums/closed-by.enum.d.mts +3 -4
  8. package/dist/domain/enums/payment-method.enum.d.mts +6 -7
  9. package/dist/domain/enums/shift-state.enum.d.mts +7 -8
  10. package/dist/domain/errors/pos.errors.d.mts +82 -13
  11. package/dist/domain/errors/pos.errors.mjs +111 -1
  12. package/dist/domain/index.d.mts +11 -3
  13. package/dist/domain/index.mjs +10 -3
  14. package/dist/domain/ports/common.d.mts +2 -3
  15. package/dist/domain/ports/ledger.bridge.d.mts +6 -7
  16. package/dist/domain/ports/notification.bridge.d.mts +5 -6
  17. package/dist/domain/ports/policy.bridge.d.mts +2 -3
  18. package/dist/domain/sale/discount.d.mts +62 -0
  19. package/dist/domain/sale/discount.mjs +58 -0
  20. package/dist/domain/sale/price-override.d.mts +51 -0
  21. package/dist/domain/sale/price-override.mjs +51 -0
  22. package/dist/domain/sale/quick-cash.d.mts +10 -0
  23. package/dist/domain/sale/quick-cash.mjs +27 -0
  24. package/dist/domain/sale/service-line.d.mts +7 -0
  25. package/dist/domain/sale/service-line.mjs +10 -0
  26. package/dist/domain/sale/tender.d.mts +256 -0
  27. package/dist/domain/sale/tender.mjs +242 -0
  28. package/dist/domain/shift/shift-decisions.d.mts +52 -0
  29. package/dist/domain/shift/shift-decisions.mjs +93 -0
  30. package/dist/domain/shift/shift-report.d.mts +127 -0
  31. package/dist/domain/shift/shift-report.mjs +95 -0
  32. package/dist/domain/shift/shift.types.d.mts +109 -0
  33. package/dist/domain/state-machines/shift.fsm.d.mts +6 -7
  34. package/dist/domain/value-objects/cash-movement.vo.d.mts +7 -3
  35. package/dist/domain/value-objects/payment-breakdown.vo.d.mts +4 -5
  36. package/dist/domain/value-objects/shift-policy.vo.d.mts +11 -7
  37. package/dist/domain/value-objects/shift-policy.vo.mjs +12 -1
  38. package/dist/engine/define-pos.d.mts +2 -3
  39. package/dist/engine/define-pos.mjs +13 -2
  40. package/dist/engine/engine-types.d.mts +24 -9
  41. package/dist/engine/index.mjs +1 -2
  42. package/dist/events/event-catalog.d.mts +18 -14
  43. package/dist/events/event-catalog.mjs +10 -4
  44. package/dist/events/event-constants.d.mts +3 -4
  45. package/dist/events/event-payloads.d.mts +9 -10
  46. package/dist/events/helpers.d.mts +6 -3
  47. package/dist/events/helpers.mjs +12 -2
  48. package/dist/events/in-process-bus.d.mts +3 -4
  49. package/dist/events/index.mjs +1 -1
  50. package/dist/grant/till-grant.d.mts +50 -0
  51. package/dist/grant/till-grant.mjs +47 -0
  52. package/dist/index.d.mts +14 -4
  53. package/dist/index.mjs +12 -4
  54. package/dist/models/create-models.d.mts +10 -6
  55. package/dist/models/create-models.mjs +16 -3
  56. package/dist/models/register.model.d.mts +7 -6
  57. package/dist/models/shift-sale-dedupe.model.d.mts +4 -5
  58. package/dist/models/shift.model.d.mts +4 -111
  59. package/dist/models/shift.model.mjs +26 -2
  60. package/dist/models/till-grant.model.d.mts +19 -0
  61. package/dist/models/till-grant.model.mjs +52 -0
  62. package/dist/repositories/register.repository.d.mts +3 -4
  63. package/dist/repositories/shift.repository.d.mts +71 -30
  64. package/dist/repositories/shift.repository.mjs +295 -108
  65. package/dist/repositories/till-grant.repository.d.mts +22 -0
  66. package/dist/repositories/till-grant.repository.mjs +41 -0
  67. package/dist/schemas/index.mjs +1 -2
  68. package/dist/schemas/shift.d.mts +9 -10
  69. package/dist/testing/fixtures.d.mts +4 -5
  70. package/dist/testing/index.mjs +1 -2
  71. package/package.json +50 -19
@@ -0,0 +1,355 @@
1
+ import { computeExpected } from "../domain/value-objects/payment-breakdown.vo.mjs";
2
+ import { isCashRow } from "../domain/shift/shift-decisions.mjs";
3
+ //#region src/commands/pos-commands.ts
4
+ const POS_COMMAND = {
5
+ shiftOpen: "pos.shift.open",
6
+ sale: "pos.sale",
7
+ refund: "pos.refund",
8
+ shiftClose: "pos.shift.close",
9
+ customerUpsert: "pos.customer.upsert"
10
+ };
11
+ const docKey = (collection, id) => `${collection}/${id}`;
12
+ /** A server refusal. `rejection: true` + `code` is arc-sync's structural rejection contract. */
13
+ var PosCommandRejection = class extends Error {
14
+ rejection = true;
15
+ code;
16
+ constructor(code, message = code) {
17
+ super(message);
18
+ this.name = "PosCommandRejection";
19
+ this.code = code;
20
+ }
21
+ };
22
+ const phoneOf = (customer) => customer.contact?.phone?.trim() || void 0;
23
+ /** The stock with `quantity` taken off — from nothing when the product has no stock document yet. */
24
+ function takeFromStock(current, productId, variantSku, quantity) {
25
+ const stock = current ?? {
26
+ _id: productId,
27
+ productId,
28
+ quantity: 0,
29
+ variants: []
30
+ };
31
+ const variants = stock.variants ?? [];
32
+ const nextVariants = variantSku ? variants.some((v) => v.sku === variantSku) ? variants.map((v) => v.sku === variantSku ? {
33
+ ...v,
34
+ quantity: v.quantity - quantity
35
+ } : v) : [...variants, {
36
+ sku: variantSku,
37
+ quantity: -quantity
38
+ }] : variants;
39
+ const nextQuantity = stock.quantity - quantity;
40
+ return {
41
+ ...stock,
42
+ quantity: nextQuantity,
43
+ inStock: nextQuantity > 0,
44
+ variants: nextVariants
45
+ };
46
+ }
47
+ /** The stock documents a sale's lines leave behind, from the current ones. */
48
+ function takenStock(sale, current) {
49
+ const stock = new Map(current);
50
+ for (const line of sale.stock) stock.set(line.productId, takeFromStock(stock.get(line.productId), line.productId, line.variantSku, line.quantity));
51
+ return [...new Set(sale.stock.map((line) => line.productId))].map((id) => ({
52
+ collection: "stock",
53
+ id,
54
+ doc: {
55
+ ...stock.get(id),
56
+ updatedAt: sale.at
57
+ }
58
+ }));
59
+ }
60
+ /** The shift with a sale's takings added: count, total, and each method's sales. */
61
+ function addTakings(shift, takings, at) {
62
+ const rows = new Map(shift.paymentBreakdown.map((row) => [row.method, { ...row }]));
63
+ for (const { method, amountMinor } of takings.byMethod) {
64
+ const row = rows.get(method) ?? {
65
+ method,
66
+ openingAmount: 0,
67
+ salesAmount: 0,
68
+ refundAmount: 0,
69
+ cashInAmount: 0,
70
+ cashOutAmount: 0,
71
+ expectedAmount: null,
72
+ countedAmount: null,
73
+ difference: null
74
+ };
75
+ row.salesAmount += amountMinor;
76
+ rows.set(method, row);
77
+ }
78
+ const paymentBreakdown = [...rows.values()];
79
+ const cash = paymentBreakdown.find(isCashRow);
80
+ return {
81
+ ...shift,
82
+ paymentBreakdown,
83
+ salesCount: shift.salesCount + 1,
84
+ salesTotal: shift.salesTotal + takings.totalMinor,
85
+ expectedCash: cash ? computeExpected(cash) : shift.openingCash,
86
+ updatedAt: at
87
+ };
88
+ }
89
+ /** What an order still has to refund: charged less refunded. */
90
+ const refundableOf = (order) => Math.max(0, order.paymentState.totalCharged.amount - order.paymentState.totalRefunded.amount);
91
+ /** The order with a refund recorded as the server projects one; fully refunded ⇒ `refunded`. */
92
+ function addRefund(order, refund) {
93
+ const { currency } = order.paymentState.totalRefunded;
94
+ const totalRefunded = order.paymentState.totalRefunded.amount + refund.amountMinor;
95
+ const full = totalRefunded >= order.totals.grandTotal.amount && order.totals.grandTotal.amount > 0;
96
+ return {
97
+ ...order,
98
+ status: full ? "refunded" : order.status,
99
+ paymentState: {
100
+ ...order.paymentState,
101
+ totalRefunded: {
102
+ amount: totalRefunded,
103
+ currency
104
+ },
105
+ transactionRefs: [...order.paymentState.transactionRefs, ...refund.byMethod.map((leg, i) => ({
106
+ transactionId: `refund-${refund.refundId}${refund.byMethod.length > 1 ? `-${i}` : ""}`,
107
+ type: "refund",
108
+ amount: {
109
+ amount: leg.amountMinor,
110
+ currency
111
+ },
112
+ status: "verified",
113
+ gateway: leg.method,
114
+ methodKind: leg.methodKind,
115
+ createdAt: refund.at,
116
+ metadata: {
117
+ source: "pos",
118
+ operationId: refund.refundId
119
+ }
120
+ }))]
121
+ },
122
+ metadata: {
123
+ ...order.metadata,
124
+ refundedAt: refund.at,
125
+ refundedAmount: totalRefunded,
126
+ refundReason: refund.reason,
127
+ refundIsPartial: !full
128
+ },
129
+ updatedAt: refund.at
130
+ };
131
+ }
132
+ /** The shift with a refund paid out of its drawer: each method's refunds, count and total. */
133
+ function addRefundToShift(shift, refund) {
134
+ const rows = new Map(shift.paymentBreakdown.map((row) => [row.method, { ...row }]));
135
+ for (const { method, amountMinor } of refund.byMethod) {
136
+ const row = rows.get(method) ?? {
137
+ method,
138
+ openingAmount: 0,
139
+ salesAmount: 0,
140
+ refundAmount: 0,
141
+ cashInAmount: 0,
142
+ cashOutAmount: 0,
143
+ expectedAmount: null,
144
+ countedAmount: null,
145
+ difference: null
146
+ };
147
+ row.refundAmount += amountMinor;
148
+ rows.set(method, row);
149
+ }
150
+ const paymentBreakdown = [...rows.values()];
151
+ const cash = paymentBreakdown.find(isCashRow);
152
+ return {
153
+ ...shift,
154
+ paymentBreakdown,
155
+ refundCount: (shift.refundCount ?? 0) + 1,
156
+ refundTotal: (shift.refundTotal ?? 0) + refund.amountMinor,
157
+ expectedCash: cash ? computeExpected(cash) : shift.expectedCash,
158
+ updatedAt: refund.at
159
+ };
160
+ }
161
+ /**
162
+ * Every write a recorded refund makes. The drawer is charged only while the sale's shift is open —
163
+ * a closed shift's count already stands, so a later refund shows as the open drawer's difference.
164
+ */
165
+ function recordRefundWrites(refund, current) {
166
+ return [{
167
+ collection: "orders",
168
+ id: refund.orderId,
169
+ doc: addRefund(current.order, refund)
170
+ }, ...current.shift?.state === "open" ? [{
171
+ collection: "shifts",
172
+ id: current.shift._id,
173
+ doc: addRefundToShift(current.shift, refund)
174
+ }] : []];
175
+ }
176
+ /** Every write a recorded sale makes, from the current documents it touches. */
177
+ function recordSaleWrites(sale, current, options = {}) {
178
+ const order = options.unresolved ? {
179
+ ...sale.order,
180
+ metadata: {
181
+ ...sale.order.metadata,
182
+ unresolved: true
183
+ }
184
+ } : sale.order;
185
+ return [
186
+ {
187
+ collection: "orders",
188
+ id: sale.order._id,
189
+ doc: order
190
+ },
191
+ ...takenStock(sale, current.stock),
192
+ {
193
+ collection: "shifts",
194
+ id: current.shift._id,
195
+ doc: addTakings(current.shift, sale.takings, sale.at)
196
+ }
197
+ ];
198
+ }
199
+ const read = (state, collection, id) => state.get(docKey(collection, id));
200
+ function stockFor(state, sale) {
201
+ const stock = /* @__PURE__ */ new Map();
202
+ for (const line of sale.stock) {
203
+ const doc = read(state, "stock", line.productId);
204
+ if (doc) stock.set(line.productId, doc);
205
+ }
206
+ return stock;
207
+ }
208
+ function loadForSale(state, sale) {
209
+ return {
210
+ shift: read(state, "shifts", sale.order.metadata.shiftId),
211
+ stock: stockFor(state, sale)
212
+ };
213
+ }
214
+ /** Where a shift is open on a register, if anywhere — a server must not open a second one. */
215
+ function openShiftOn(state, registerId) {
216
+ for (const [key, doc] of state) {
217
+ if (!key.startsWith("shifts/")) continue;
218
+ const shift = doc;
219
+ if (shift.registerId === registerId && shift.state === "open") return shift;
220
+ }
221
+ }
222
+ const posCommandPack = {
223
+ [POS_COMMAND.customerUpsert]: {
224
+ /** A refused customer is administrative — it stops showing; sales keep their customer snapshot. */
225
+ whenRefused: "suppressed",
226
+ apply: (_state, command) => [{
227
+ collection: "customers",
228
+ id: command.payload.customer._id,
229
+ doc: command.payload.customer
230
+ }],
231
+ handle(state, command) {
232
+ const { customer } = command.payload;
233
+ const phone = phoneOf(customer);
234
+ for (const [key, doc] of state) {
235
+ if (!key.startsWith("customers/") || doc._id === customer._id) continue;
236
+ if (phone && phoneOf(doc) === phone) return [];
237
+ }
238
+ return [{
239
+ collection: "customers",
240
+ id: customer._id,
241
+ doc: customer
242
+ }];
243
+ }
244
+ },
245
+ [POS_COMMAND.shiftOpen]: {
246
+ /** A refused open is an administrative change — it stops showing; the server's shift stands. */
247
+ whenRefused: "suppressed",
248
+ apply: (_state, command) => [{
249
+ collection: "shifts",
250
+ id: command.payload.shift._id,
251
+ doc: command.payload.shift
252
+ }],
253
+ handle(state, command) {
254
+ const existing = openShiftOn(state, command.payload.shift.registerId);
255
+ if (existing && existing._id !== command.payload.shift._id) throw new PosCommandRejection("pos.shift.already_open");
256
+ return [{
257
+ collection: "shifts",
258
+ id: command.payload.shift._id,
259
+ doc: command.payload.shift
260
+ }];
261
+ }
262
+ },
263
+ [POS_COMMAND.sale]: {
264
+ /** A refused sale is a physical fact — the goods and money moved; it stays visible, unresolved. */
265
+ whenRefused: "unresolved",
266
+ apply(state, command, unresolved) {
267
+ const { shift, stock } = loadForSale(state, command.payload);
268
+ if (!shift) return recordSaleWrites(command.payload, {
269
+ shift: placeholderShift(command.payload),
270
+ stock
271
+ }, { unresolved }).filter((w) => w.collection !== "shifts");
272
+ return recordSaleWrites(command.payload, {
273
+ shift,
274
+ stock
275
+ }, { unresolved });
276
+ },
277
+ /**
278
+ * After the server records the sale, its stock still leaves the shelf HERE until the server's own
279
+ * count includes it: the order's `metadata.stockIssue` reaches `posted` only after the branch's
280
+ * stock documents were republished. `failed` keeps the subtraction — the shelf really is emptier.
281
+ */
282
+ pending(state, command) {
283
+ if (read(state, "orders", command.payload.order._id)?.metadata?.stockIssue === "posted") return [];
284
+ return takenStock(command.payload, stockFor(state, command.payload));
285
+ },
286
+ handle(state, command) {
287
+ const { shift, stock } = loadForSale(state, command.payload);
288
+ if (!shift) throw new PosCommandRejection("pos.shift.unknown");
289
+ if (shift.state !== "open") throw new PosCommandRejection("pos.shift.not_open");
290
+ return recordSaleWrites(command.payload, {
291
+ shift,
292
+ stock
293
+ });
294
+ }
295
+ },
296
+ [POS_COMMAND.refund]: {
297
+ /** A refused refund is a physical fact — the money was handed back; it stays visible, unresolved. */
298
+ whenRefused: "unresolved",
299
+ apply(state, command) {
300
+ const order = read(state, "orders", command.payload.orderId);
301
+ if (!order) return [];
302
+ return recordRefundWrites(command.payload, {
303
+ order,
304
+ shift: read(state, "shifts", command.payload.shiftId)
305
+ });
306
+ },
307
+ handle(state, command) {
308
+ const order = read(state, "orders", command.payload.orderId);
309
+ if (!order) throw new PosCommandRejection("pos.refund.order_unknown");
310
+ if (!(command.payload.amountMinor > 0) || command.payload.amountMinor > refundableOf(order)) throw new PosCommandRejection("pos.refund.exceeds_refundable");
311
+ return recordRefundWrites(command.payload, {
312
+ order,
313
+ shift: read(state, "shifts", command.payload.shiftId)
314
+ });
315
+ }
316
+ },
317
+ [POS_COMMAND.shiftClose]: {
318
+ /** A refused close is a physical fact — the drawer was counted; it stays visible, unresolved. */
319
+ whenRefused: "unresolved",
320
+ apply: (_state, command, unresolved) => [{
321
+ collection: "shifts",
322
+ id: command.payload.shift._id,
323
+ doc: unresolved ? {
324
+ ...command.payload.shift,
325
+ unresolved: true
326
+ } : command.payload.shift
327
+ }],
328
+ handle(state, command) {
329
+ const closed = command.payload.shift;
330
+ const current = read(state, "shifts", closed._id);
331
+ if (!current) throw new PosCommandRejection("pos.shift.unknown");
332
+ if (current.state !== "open") throw new PosCommandRejection("pos.shift.not_open");
333
+ if (current.salesCount !== closed.salesCount || current.salesTotal !== closed.salesTotal) throw new PosCommandRejection("pos.shift.close_basis_changed");
334
+ return [{
335
+ collection: "shifts",
336
+ id: closed._id,
337
+ doc: closed
338
+ }];
339
+ }
340
+ }
341
+ };
342
+ function placeholderShift(sale) {
343
+ return {
344
+ _id: sale.order.metadata.shiftId,
345
+ registerId: sale.order.metadata.registerId,
346
+ state: "unknown",
347
+ openingCash: 0,
348
+ salesCount: 0,
349
+ salesTotal: 0,
350
+ expectedCash: null,
351
+ paymentBreakdown: []
352
+ };
353
+ }
354
+ //#endregion
355
+ export { POS_COMMAND, PosCommandRejection, addRefund, addRefundToShift, addTakings, docKey, posCommandPack, recordRefundWrites, recordSaleWrites, refundableOf, takeFromStock };
@@ -6,7 +6,7 @@
6
6
  * every cash-in / cash-out call. Hosts can scope the allowed subset per
7
7
  * branch via `policy.allowedReasonCodes`.
8
8
  */
9
- declare const CASH_MOVEMENT_REASON_CODES: readonly [
9
+ export declare const CASH_MOVEMENT_REASON_CODES: readonly [
10
10
  /** Money moved from drawer to safe mid-shift. */
11
11
  'safe_drop',
12
12
  /** Operational expense paid from drawer (utility bill, ad-hoc supply). */
@@ -21,6 +21,5 @@ declare const CASH_MOVEMENT_REASON_CODES: readonly [
21
21
  'till_top_up',
22
22
  /** Free-form; note required. */
23
23
  'other'];
24
- type CashMovementReasonCode = (typeof CASH_MOVEMENT_REASON_CODES)[number];
25
- //#endregion
26
- export { CASH_MOVEMENT_REASON_CODES, CashMovementReasonCode };
24
+ export type CashMovementReasonCode = (typeof CASH_MOVEMENT_REASON_CODES)[number];
25
+ //#endregion
@@ -7,7 +7,6 @@
7
7
  * manager — a manager closed (typically post blind_close reconcile)
8
8
  * system_auto — EOD cron / forceClose (orphaned_closed)
9
9
  */
10
- declare const CLOSED_BY_VALUES: readonly ['cashier', 'manager', 'system_auto'];
11
- type ClosedBy = (typeof CLOSED_BY_VALUES)[number];
12
- //#endregion
13
- export { CLOSED_BY_VALUES, ClosedBy };
10
+ export declare const CLOSED_BY_VALUES: readonly ['cashier', 'manager', 'system_auto'];
11
+ export type ClosedBy = (typeof CLOSED_BY_VALUES)[number];
12
+ //#endregion
@@ -11,18 +11,17 @@ import { PaymentMethodKind } from "@classytic/primitives/payment-method-kind";
11
11
  * `SHIFT_PAYMENT_METHODS` is only the out-of-the-box DEFAULT policy + the seed
12
12
  * for kind resolution — never a hard constraint on what a host may accept.
13
13
  */
14
- declare const SHIFT_PAYMENT_METHODS: readonly ['cash', 'card', 'mfs', 'bank_transfer'];
14
+ export declare const SHIFT_PAYMENT_METHODS: readonly ['cash', 'card', 'mfs', 'bank_transfer'];
15
15
  /** A payment method CODE (open string). Baseline defaults in {@link SHIFT_PAYMENT_METHODS}. */
16
- type ShiftPaymentMethod = string;
16
+ export type ShiftPaymentMethod = string;
17
17
  /** Default baseline code → universal kind. */
18
- declare const DEFAULT_METHOD_KINDS: Readonly<Record<string, PaymentMethodKind>>;
18
+ export declare const DEFAULT_METHOD_KINDS: Readonly<Record<string, PaymentMethodKind>>;
19
19
  /** Every valid kind value — for the mongoose enum on `paymentBreakdown.methodKind`. */
20
- declare const PAYMENT_METHOD_KIND_VALUES: readonly PaymentMethodKind[];
20
+ export declare const PAYMENT_METHOD_KIND_VALUES: readonly PaymentMethodKind[];
21
21
  /**
22
22
  * Resolve a code's universal kind: an explicit override wins, else the default
23
23
  * baseline map, else `other` (the always-valid fallback). Hosts pass explicit
24
24
  * kinds for custom codes via `ShiftPolicy.paymentMethodKinds`.
25
25
  */
26
- declare function resolveMethodKind(code: string, explicit?: PaymentMethodKind): PaymentMethodKind;
27
- //#endregion
28
- export { DEFAULT_METHOD_KINDS, PAYMENT_METHOD_KIND_VALUES, SHIFT_PAYMENT_METHODS, ShiftPaymentMethod, resolveMethodKind };
26
+ export declare function resolveMethodKind(code: string, explicit?: PaymentMethodKind): PaymentMethodKind;
27
+ //#endregion
@@ -14,13 +14,12 @@
14
14
  * orphaned_closed — auto-closed by EOD cron / forceClose; counts default to
15
15
  * expected; flagged for manager review
16
16
  */
17
- declare const SHIFT_STATES: readonly ['open', 'paused', 'blind_closed', 'closed', 'orphaned_closed'];
18
- type ShiftState = (typeof SHIFT_STATES)[number];
17
+ export declare const SHIFT_STATES: readonly ['open', 'paused', 'blind_closed', 'closed', 'orphaned_closed'];
18
+ export type ShiftState = (typeof SHIFT_STATES)[number];
19
19
  /** States that block opening a new shift for the same scope. */
20
- declare const ACTIVE_SHIFT_STATES: readonly ShiftState[];
20
+ export declare const ACTIVE_SHIFT_STATES: readonly ShiftState[];
21
21
  /** States considered final — no further state mutations permitted. */
22
- declare const FINAL_SHIFT_STATES: readonly ShiftState[];
23
- declare function isActiveShiftState(state: ShiftState): boolean;
24
- declare function isFinalShiftState(state: ShiftState): boolean;
25
- //#endregion
26
- export { ACTIVE_SHIFT_STATES, FINAL_SHIFT_STATES, SHIFT_STATES, ShiftState, isActiveShiftState, isFinalShiftState };
22
+ export declare const FINAL_SHIFT_STATES: readonly ShiftState[];
23
+ export declare function isActiveShiftState(state: ShiftState): boolean;
24
+ export declare function isFinalShiftState(state: ShiftState): boolean;
25
+ //#endregion
@@ -10,7 +10,7 @@ import { HttpError } from "@classytic/repo-core/errors";
10
10
  * Defaults to 422; subclasses override with `readonly status = N` (a subclass
11
11
  * field initializer runs after this constructor, so it wins).
12
12
  */
13
- declare class PosError extends Error implements HttpError {
13
+ export declare class PosError extends Error implements HttpError {
14
14
  readonly code: string;
15
15
  readonly status: number;
16
16
  constructor(code: string, message: string);
@@ -20,29 +20,47 @@ declare class PosError extends Error implements HttpError {
20
20
  * publishing mid-transaction leaks ghost events on rollback (§P8.1).
21
21
  * Session + outbox is legal durable-relay-only mode.
22
22
  */
23
- declare class UnmanagedSessionError extends PosError {
23
+ export declare class UnmanagedSessionError extends PosError {
24
24
  readonly status = 500;
25
25
  constructor();
26
26
  }
27
- declare class ShiftNotFoundError extends PosError {
27
+ export declare class ShiftNotFoundError extends PosError {
28
28
  readonly status = 404;
29
29
  constructor(id: string);
30
30
  }
31
- declare class IllegalShiftTransitionError extends PosError {
31
+ export declare class IllegalShiftTransitionError extends PosError {
32
32
  readonly status = 422;
33
33
  constructor(from: string, verb: string);
34
34
  }
35
- declare class ActiveShiftAlreadyOpenError extends PosError {
35
+ export declare class ActiveShiftAlreadyOpenError extends PosError {
36
36
  readonly status = 409;
37
37
  constructor(scope: string);
38
38
  }
39
- declare class VarianceExceededError extends PosError {
39
+ /** One open register, as offered to a till that must say which one it is. */
40
+ export interface ActiveRegister {
41
+ registerId: string | null;
42
+ shiftId: string;
43
+ state: string;
44
+ openedAt?: Date | undefined;
45
+ }
46
+ /**
47
+ * Several registers are active at the branch and the caller named none — picking one would
48
+ * ring the sale into another cashier's drawer. `meta.registers` lists the choices.
49
+ */
50
+ export declare class RegisterRequiredError extends PosError {
51
+ readonly status = 409;
52
+ readonly meta: {
53
+ registers: ActiveRegister[];
54
+ };
55
+ constructor(registers: ActiveRegister[]);
56
+ }
57
+ export declare class VarianceExceededError extends PosError {
40
58
  readonly status = 409;
41
59
  readonly difference: number;
42
60
  readonly expected: number;
43
61
  constructor(difference: number, expected: number);
44
62
  }
45
- declare class ShiftFinalizedError extends PosError {
63
+ export declare class ShiftFinalizedError extends PosError {
46
64
  readonly status = 409;
47
65
  constructor(id: string);
48
66
  }
@@ -52,7 +70,7 @@ declare class ShiftFinalizedError extends PosError {
52
70
  * corrections and remain allowed). Distinct from {@link ShiftFinalizedError}:
53
71
  * the shift is recoverable — resume it and retry.
54
72
  */
55
- declare class ShiftPausedError extends PosError {
73
+ export declare class ShiftPausedError extends PosError {
56
74
  readonly status = 409;
57
75
  constructor(id: string);
58
76
  }
@@ -64,15 +82,35 @@ declare class ShiftPausedError extends PosError {
64
82
  * pass `countedByMethod` (cash always, plus any non-cash tender being
65
83
  * reconciled) or blind-close first.
66
84
  */
67
- declare class ShiftCountsRequiredError extends PosError {
85
+ export declare class ShiftCountsRequiredError extends PosError {
68
86
  readonly status = 422;
69
87
  constructor(id: string);
70
88
  }
71
- declare class CashMovementInvalidError extends PosError {
89
+ /** A cash movement under a key already booked for a DIFFERENT movement — two commands, one key. */
90
+ export declare class CashMovementKeyReusedError extends PosError {
91
+ readonly status = 409;
92
+ constructor(movementKey: string);
93
+ }
94
+ export declare class CashMovementInvalidError extends PosError {
72
95
  readonly status = 422;
73
96
  constructor(reason: string);
74
97
  }
75
- declare class PosCapabilityError extends Error {
98
+ /**
99
+ * A cash-out the drawer cannot cover, refused by the write's own filter — so two
100
+ * concurrent cash-outs that each fit alone cannot both land.
101
+ */
102
+ export declare class CashOutExceedsDrawerError extends PosError {
103
+ readonly status = 409;
104
+ readonly amount: number;
105
+ readonly drawer: number;
106
+ constructor(amount: number, drawer: number);
107
+ }
108
+ /** A branch policy that allows no cash-movement reason code — `[]` is refused; any-code is `'*'`. */
109
+ export declare class ReasonCodePolicyInvalidError extends PosError {
110
+ readonly status = 409;
111
+ constructor();
112
+ }
113
+ export declare class PosCapabilityError extends Error {
76
114
  readonly code = "POS_CAPABILITY";
77
115
  readonly status = 422;
78
116
  readonly missing: readonly string[];
@@ -88,5 +126,36 @@ declare class PosCapabilityError extends Error {
88
126
  indeterminate?: boolean;
89
127
  });
90
128
  }
91
- //#endregion
92
- export { ActiveShiftAlreadyOpenError, CashMovementInvalidError, IllegalShiftTransitionError, PosCapabilityError, PosError, ShiftCountsRequiredError, ShiftFinalizedError, ShiftNotFoundError, ShiftPausedError, UnmanagedSessionError, VarianceExceededError };
129
+ /** The tender does not settle the sale, and the deployment's `TenderPolicy` does not permit that shape. */
130
+ export declare class TenderMismatchError extends PosError {
131
+ readonly status = 400;
132
+ readonly dueMinor: number;
133
+ readonly tenderedMinor: number;
134
+ readonly details: Record<string, unknown>;
135
+ constructor(dueMinor: number, tenderedMinor: number, detail: string);
136
+ }
137
+ /** A line price differs from the catalog without authority (403) or without a reason (400). */
138
+ export declare class PriceOverrideRefusedError extends PosError {
139
+ readonly status: number;
140
+ constructor(detail: string, status?: number);
141
+ }
142
+ /** Which requirement an order-level discount failed — each is fixed by a different person. */
143
+ export type OrderDiscountRefusal = 'authority' | 'reason' | 'limit' | 'full-comp';
144
+ /** An order-level discount was refused: 400 for a missing reason, 403 for every policy denial. */
145
+ export declare class OrderDiscountRefusedError extends PosError {
146
+ readonly status: number;
147
+ readonly missing: OrderDiscountRefusal;
148
+ readonly details: Record<string, unknown>;
149
+ constructor(missing: OrderDiscountRefusal, detail: string, details?: Record<string, unknown>);
150
+ }
151
+ /** Why a tender method was refused. */
152
+ export type TenderMethodRefusal = 'not-accepted' | 'reference-required' | 'zero-amount' | 'change-not-possible';
153
+ /** A tender row was refused by the method policy. 400 — every case is one the till can correct. */
154
+ export declare class TenderMethodRefusedError extends PosError {
155
+ readonly status = 400;
156
+ readonly method: string;
157
+ readonly reason: TenderMethodRefusal;
158
+ readonly details: Record<string, unknown>;
159
+ constructor(method: string, reason: TenderMethodRefusal, details?: Record<string, unknown>);
160
+ }
161
+ //#endregion