@classytic/pos 0.4.0 → 0.6.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,44 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.0] — 2026-09-04
4
+
5
+ ### Added
6
+
7
+ - `ShiftRepository.findActiveByBranch(organizationId)` — returns all active shifts for a branch (dashboard "registers open now" widget); routed through `findAll` so the tenant plugin injects and casts `organizationId`
8
+
9
+ ### Changed — peer floors raised to current
10
+
11
+ - `@classytic/mongokit` `>=3.33.0` → **`>=3.36.0`**
12
+ - `@classytic/primitives` `>=0.23.0` → **`>=0.26.4`**
13
+ - `@classytic/repo-core` `>=0.24.0` → **`>=0.26.0`**
14
+
15
+ ## [0.5.0] — 2026-08-26
16
+
17
+ ### Fixed — CRITICAL: cash drawer identified by kind, not by code spelling
18
+
19
+ Five call sites in `ShiftRepository` located the cash breakdown row with
20
+ `r.method === 'cash'`. On any deployment whose cash code is not literally
21
+ `"cash"` — a Spanish till (`'efectivo'`), a French one (`'espèces'`), or the
22
+ package's own documented `'cash_register_3'` — every comparison matched nothing
23
+ silently:
24
+
25
+ - the opening float was written to no row (`open()`)
26
+ - `recordCashMovement` could not find a row to increment
27
+ - `expectedCash` read `null` on every close projection
28
+ - the variance gate skipped entirely (`if (expectedAmount != null)` never fired)
29
+ - the till closed unreconciled with no error
30
+
31
+ The row already carried the right answer: `open()` resolves `methodKind` on the
32
+ line immediately above the first of those comparisons.
33
+
34
+ **Fix:** `isCashRow(r)` keys on `r.methodKind === PAYMENT_METHOD_KIND.CASH` from
35
+ `@classytic/primitives/payment-method-kind`. Legacy rows written before
36
+ `methodKind` existed (Mongoose default `'other'` for absent field) fall back to
37
+ `r.method === 'cash'` so an in-flight shift from an older deployment remains
38
+ reconcilable. All five call sites replaced. Covered by
39
+ `tests/unit/cash-row-is-kind-not-code.test.ts` with non-English codes on purpose
40
+ — a test seeding `'cash'` passes with or without the fix and proves nothing.
41
+
3
42
  ## [0.4.0] — 2026-08-17
4
43
 
5
44
  ### Fixed — CRITICAL: the Z-report journal entry could post twice
@@ -239,6 +239,12 @@ declare class ShiftRepository extends Repository<IShift> {
239
239
  * host-side shim carry its own `isValid` dance).
240
240
  */
241
241
  getActiveShift(ctx: PosContext, registerId?: string): Promise<ShiftDocument | null>;
242
+ /**
243
+ * Every active shift for ONE branch — the "/status" dashboard widget
244
+ * ("registers open now"). Routed through `findAll` so the tenant plugin
245
+ * injects and CASTS `organizationId`, same reasoning as `getActiveShift`.
246
+ */
247
+ findActiveByBranch(organizationId: string): Promise<ShiftDocument[]>;
242
248
  /**
243
249
  * Lean, DELIBERATELY UNSCOPED read by `_id`.
244
250
  *
@@ -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);
@@ -436,6 +459,18 @@ var ShiftRepository = class extends Repository {
436
459
  }))[0] ?? null;
437
460
  }
438
461
  /**
462
+ * Every active shift for ONE branch — the "/status" dashboard widget
463
+ * ("registers open now"). Routed through `findAll` so the tenant plugin
464
+ * injects and CASTS `organizationId`, same reasoning as `getActiveShift`.
465
+ */
466
+ async findActiveByBranch(organizationId) {
467
+ return await this.findAll({ state: { $in: [...ACTIVE_SHIFT_STATES] } }, {
468
+ organizationId,
469
+ select: "_id state registerId openingCashierId openedAt blindClosedAt salesCount salesTotal",
470
+ lean: true
471
+ });
472
+ }
473
+ /**
439
474
  * Lean, DELIBERATELY UNSCOPED read by `_id`.
440
475
  *
441
476
  * Exists so a host can distinguish "shift does not exist" (404) from "shift
@@ -483,7 +518,7 @@ var ShiftRepository = class extends Repository {
483
518
  difference: 0
484
519
  };
485
520
  });
486
- const cashRow = breakdown.find((r) => r.method === "cash");
521
+ const cashRow = breakdown.find(isCashRow);
487
522
  const fromState = shift.state;
488
523
  const pending = this.buildPendingLedgerPost(shift, "forceClose");
489
524
  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.6.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",
@@ -71,18 +71,18 @@
71
71
  "release": "npm run push -- main && npm run release:tag && npm publish"
72
72
  },
73
73
  "peerDependencies": {
74
- "@classytic/mongokit": ">=3.33.0",
75
- "@classytic/primitives": ">=0.23.0",
76
- "@classytic/repo-core": ">=0.24.0",
74
+ "@classytic/mongokit": ">=3.36.0",
75
+ "@classytic/primitives": ">=0.26.4",
76
+ "@classytic/repo-core": ">=0.26.0",
77
77
  "@classytic/validation": ">=0.2.0",
78
78
  "mongoose": ">=9.4.1",
79
79
  "zod": ">=4.0.0"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@classytic/dev-tools": "^0.2.0",
83
- "@classytic/mongokit": "^3.33.0",
84
- "@classytic/primitives": ">=0.23.0",
85
- "@classytic/repo-core": ">=0.24.0",
83
+ "@classytic/mongokit": "^3.36.0",
84
+ "@classytic/primitives": ">=0.26.4",
85
+ "@classytic/repo-core": ">=0.26.0",
86
86
  "@classytic/validation": ">=0.4.0",
87
87
  "@types/node": "^25.5.0",
88
88
  "@vitest/coverage-v8": "^3.2.4",