@classytic/pos 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.0] — 2026-08-26
4
+
5
+ ### Fixed — CRITICAL: cash drawer identified by kind, not by code spelling
6
+
7
+ Five call sites in `ShiftRepository` located the cash breakdown row with
8
+ `r.method === 'cash'`. On any deployment whose cash code is not literally
9
+ `"cash"` — a Spanish till (`'efectivo'`), a French one (`'espèces'`), or the
10
+ package's own documented `'cash_register_3'` — every comparison matched nothing
11
+ silently:
12
+
13
+ - the opening float was written to no row (`open()`)
14
+ - `recordCashMovement` could not find a row to increment
15
+ - `expectedCash` read `null` on every close projection
16
+ - the variance gate skipped entirely (`if (expectedAmount != null)` never fired)
17
+ - the till closed unreconciled with no error
18
+
19
+ The row already carried the right answer: `open()` resolves `methodKind` on the
20
+ line immediately above the first of those comparisons.
21
+
22
+ **Fix:** `isCashRow(r)` keys on `r.methodKind === PAYMENT_METHOD_KIND.CASH` from
23
+ `@classytic/primitives/payment-method-kind`. Legacy rows written before
24
+ `methodKind` existed (Mongoose default `'other'` for absent field) fall back to
25
+ `r.method === 'cash'` so an in-flight shift from an older deployment remains
26
+ reconcilable. All five call sites replaced. Covered by
27
+ `tests/unit/cash-row-is-kind-not-code.test.ts` with non-English codes on purpose
28
+ — a test seeding `'cash'` passes with or without the fix and proves nothing.
29
+
3
30
  ## [0.4.0] — 2026-08-17
4
31
 
5
32
  ### Fixed — CRITICAL: the Z-report journal entry could post twice
@@ -11,6 +11,7 @@ import { repoOptionsFromCtx } from "./repo-options.mjs";
11
11
  import { isTransitionRace, shiftMachine } from "./shift-transition-support.mjs";
12
12
  import { Repository, methodRegistryPlugin, softDeletePlugin } from "@classytic/mongokit";
13
13
  import { isValidObjectId } from "mongoose";
14
+ import { PAYMENT_METHOD_KIND } from "@classytic/primitives/payment-method-kind";
14
15
  import { applyDecision, createChain } from "@classytic/primitives/approval";
15
16
  //#region src/repositories/shift.repository.ts
16
17
  /**
@@ -57,6 +58,28 @@ import { applyDecision, createChain } from "@classytic/primitives/approval";
57
58
  * required field the compiler enforces on every implementation.
58
59
  */
59
60
  /**
61
+ * Is this breakdown row the DRAWER — i.e. physical cash?
62
+ *
63
+ * Keyed on the resolved `methodKind`, never on the method CODE. Method codes are
64
+ * OPEN by design (this package's own enum docblock offers `'cash_register_3'` as
65
+ * a legitimate one, and a non-English deployment will use `'efectivo'`,
66
+ * `'espèces'`, `'contanti'`, …); the universal KIND is what the docblock says
67
+ * exists "for reconciliation".
68
+ *
69
+ * Five call sites used to test `r.method === 'cash'`. On any deployment whose
70
+ * cash code is not literally `"cash"` that matched NOTHING, and every
71
+ * consequence was silent: the opening float landed on no row, cash movements
72
+ * could not find one, `expectedCash` read null — and because the variance gate
73
+ * only runs when `expectedAmount != null`, **the till closed unreconciled with
74
+ * no error at all**. The row already carried the right answer: `open()` resolves
75
+ * `methodKind` one line above the first of those comparisons.
76
+ *
77
+ * A legacy row written before `methodKind` existed defaults to `'other'` in the
78
+ * schema, so it falls back to the code — that keeps an in-flight shift from an
79
+ * older deployment reconcilable instead of silently losing its drawer.
80
+ */
81
+ const isCashRow = (r) => r.methodKind === PAYMENT_METHOD_KIND.CASH || r.methodKind === void 0 && r.method === "cash";
82
+ /**
60
83
  * Mongoose DocumentArrays don't spread (`...row`) cleanly — coerce to plain
61
84
  * objects so spreads and numeric ops see every field. One definition; the
62
85
  * close, forceClose and compensation paths all read it, and they diverged
@@ -109,7 +132,7 @@ var ShiftRepository = class extends Repository {
109
132
  const seedBreakdown = policy.allowedPaymentMethods.map((method) => ({
110
133
  method,
111
134
  methodKind: resolveMethodKind(method, policy.paymentMethodKinds?.[method]),
112
- openingAmount: method === "cash" ? input.openingCash : 0,
135
+ openingAmount: resolveMethodKind(method, policy.paymentMethodKinds?.[method]) === PAYMENT_METHOD_KIND.CASH ? input.openingCash : 0,
113
136
  salesAmount: 0,
114
137
  taxAmount: 0,
115
138
  refundAmount: 0,
@@ -158,7 +181,7 @@ var ShiftRepository = class extends Repository {
158
181
  ...input.movement,
159
182
  timestamp: input.movement.timestamp ?? /* @__PURE__ */ new Date()
160
183
  };
161
- const cashRow = shift.paymentBreakdown.find((r) => r.method === "cash");
184
+ const cashRow = shift.paymentBreakdown.find(isCashRow);
162
185
  if (!cashRow) {}
163
186
  const update = { $push: { cashMovements: movement } };
164
187
  if (cashRow) update.$inc = movement.type === "in" ? { "paymentBreakdown.$[cashElem].cashInAmount": movement.amount } : { "paymentBreakdown.$[cashElem].cashOutAmount": movement.amount };
@@ -265,7 +288,7 @@ var ShiftRepository = class extends Repository {
265
288
  const shift = await this.requireActive(input.shiftId, ctx);
266
289
  if (shift.state !== "open") throw new IllegalShiftTransitionError(shift.state, "blindClose");
267
290
  const updatedBreakdown = this.applyCounts(shift.paymentBreakdown, input.countedByMethod, true);
268
- const cashRow = updatedBreakdown.find((r) => r.method === "cash");
291
+ const cashRow = updatedBreakdown.find(isCashRow);
269
292
  const updated = await this.applyTransition(String(shift._id), shiftMachine("blindClose"), {
270
293
  field: "state",
271
294
  from: "open",
@@ -304,7 +327,7 @@ var ShiftRepository = class extends Repository {
304
327
  if (!canTransition(shift.state, "close")) throw new IllegalShiftTransitionError(shift.state, "close");
305
328
  if (shift.state === "open" && input.countedByMethod === void 0) throw new ShiftCountsRequiredError(input.shiftId);
306
329
  const breakdown = input.countedByMethod ? this.applyCounts(shift.paymentBreakdown, input.countedByMethod, true) : shift.paymentBreakdown;
307
- const cashRow = breakdown.find((r) => r.method === "cash");
330
+ const cashRow = breakdown.find(isCashRow);
308
331
  let varianceExceeded = false;
309
332
  if (cashRow?.expectedAmount != null && cashRow.countedAmount != null) {
310
333
  varianceExceeded = !isWithinVarianceThreshold(cashRow.difference ?? 0, cashRow.expectedAmount, shift.policySnapshot);
@@ -483,7 +506,7 @@ var ShiftRepository = class extends Repository {
483
506
  difference: 0
484
507
  };
485
508
  });
486
- const cashRow = breakdown.find((r) => r.method === "cash");
509
+ const cashRow = breakdown.find(isCashRow);
487
510
  const fromState = shift.state;
488
511
  const pending = this.buildPendingLedgerPost(shift, "forceClose");
489
512
  let claimed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/pos",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Multi-vertical POS / register-session kernel for MongoDB — shift lifecycle, cash-drawer reconciliation, payment-method breakdown, variance detection, FSM. Works for retail, restaurant, clinic, service-booking, car-wash and any vertical with a 'shift opens, shift closes, money is reconciled' workflow.",
5
5
  "author": "Classytic",
6
6
  "type": "module",