@classytic/pos 0.3.1 → 0.4.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 (59) hide show
  1. package/CHANGELOG.md +236 -10
  2. package/LICENSE +75 -21
  3. package/README.md +11 -4
  4. package/dist/domain/enums/cash-movement-reason.enum.d.mts +15 -1
  5. package/dist/domain/enums/closed-by.enum.d.mts +1 -1
  6. package/dist/domain/enums/payment-method.enum.d.mts +23 -9
  7. package/dist/domain/enums/payment-method.enum.mjs +27 -7
  8. package/dist/domain/enums/shift-state.enum.d.mts +1 -1
  9. package/dist/domain/errors/pos.errors.d.mts +53 -10
  10. package/dist/domain/errors/pos.errors.mjs +58 -13
  11. package/dist/domain/index.d.mts +5 -5
  12. package/dist/domain/index.mjs +5 -4
  13. package/dist/domain/ports/common.d.mts +0 -1
  14. package/dist/domain/ports/ledger.bridge.d.mts +42 -8
  15. package/dist/domain/ports/ledger.bridge.mjs +14 -0
  16. package/dist/domain/ports/notification.bridge.d.mts +0 -1
  17. package/dist/domain/ports/policy.bridge.d.mts +0 -1
  18. package/dist/domain/state-machines/shift.fsm.d.mts +1 -2
  19. package/dist/domain/value-objects/cash-movement.vo.d.mts +0 -1
  20. package/dist/domain/value-objects/payment-breakdown.vo.d.mts +4 -1
  21. package/dist/domain/value-objects/shift-policy.vo.d.mts +31 -3
  22. package/dist/domain/value-objects/shift-policy.vo.mjs +35 -1
  23. package/dist/engine/define-pos.d.mts +9 -0
  24. package/dist/engine/define-pos.mjs +126 -0
  25. package/dist/engine/engine-types.d.mts +84 -36
  26. package/dist/engine/index.d.mts +4 -3
  27. package/dist/engine/index.mjs +2 -2
  28. package/dist/events/event-catalog.d.mts +6 -7
  29. package/dist/events/event-constants.d.mts +8 -8
  30. package/dist/events/event-payloads.d.mts +0 -1
  31. package/dist/events/helpers.d.mts +0 -1
  32. package/dist/events/helpers.mjs +5 -5
  33. package/dist/events/in-process-bus.d.mts +4 -15
  34. package/dist/events/in-process-bus.mjs +14 -32
  35. package/dist/events/outbox-store.d.mts +3 -19
  36. package/dist/events/outbox-store.mjs +1 -27
  37. package/dist/index.d.mts +15 -10
  38. package/dist/index.mjs +8 -6
  39. package/dist/models/create-models.d.mts +31 -4
  40. package/dist/models/create-models.mjs +80 -13
  41. package/dist/models/hide-soft-delete.mjs +11 -0
  42. package/dist/models/inject-tenant.d.mts +2 -2
  43. package/dist/models/inject-tenant.mjs +4 -10
  44. package/dist/models/register.model.d.mts +37 -0
  45. package/dist/models/register.model.mjs +82 -0
  46. package/dist/models/shift-sale-dedupe.model.d.mts +16 -0
  47. package/dist/models/shift-sale-dedupe.model.mjs +57 -0
  48. package/dist/models/shift.model.d.mts +48 -2
  49. package/dist/models/shift.model.mjs +88 -25
  50. package/dist/repositories/register.repository.d.mts +22 -0
  51. package/dist/repositories/register.repository.mjs +25 -0
  52. package/dist/repositories/shift.repository.d.mts +217 -12
  53. package/dist/repositories/shift.repository.mjs +480 -85
  54. package/dist/schemas/shift.d.mts +7 -18
  55. package/dist/schemas/shift.mjs +1 -2
  56. package/dist/testing/fixtures.d.mts +0 -1
  57. package/package.json +13 -10
  58. package/dist/engine/create-pos.d.mts +0 -6
  59. package/dist/engine/create-pos.mjs +0 -82
@@ -1,5 +1,4 @@
1
1
  import { z } from "zod";
2
-
3
2
  //#region src/schemas/shift.d.ts
4
3
  declare const objectIdString: z.ZodString;
5
4
  declare const openShiftBody: z.ZodObject<{
@@ -17,13 +16,13 @@ declare const recordCashMovementBody: z.ZodObject<{
17
16
  }>;
18
17
  amount: z.ZodNumber;
19
18
  reasonCode: z.ZodEnum<{
20
- safe_drop: "safe_drop";
21
- petty_cash: "petty_cash";
22
- owner_withdrawal: "owner_withdrawal";
23
- correction: "correction";
24
19
  bank_deposit: "bank_deposit";
25
- till_top_up: "till_top_up";
20
+ correction: "correction";
26
21
  other: "other";
22
+ owner_withdrawal: "owner_withdrawal";
23
+ petty_cash: "petty_cash";
24
+ safe_drop: "safe_drop";
25
+ till_top_up: "till_top_up";
27
26
  }>;
28
27
  note: z.ZodDefault<z.ZodString>;
29
28
  cashierId: z.ZodString;
@@ -31,23 +30,13 @@ declare const recordCashMovementBody: z.ZodObject<{
31
30
  timestamp: z.ZodOptional<z.ZodUnion<readonly [z.ZodISODateTime, z.ZodISODate]>>;
32
31
  }, z.core.$strip>;
33
32
  declare const blindCloseBody: z.ZodObject<{
34
- countedByMethod: z.ZodRecord<z.ZodEnum<{
35
- cash: "cash";
36
- card: "card";
37
- mfs: "mfs";
38
- bank_transfer: "bank_transfer";
39
- }>, z.ZodNumber>;
33
+ countedByMethod: z.ZodRecord<z.ZodString, z.ZodNumber>;
40
34
  closingCashierId: z.ZodString;
41
35
  closingCashierName: z.ZodString;
42
36
  notes: z.ZodOptional<z.ZodString>;
43
37
  }, z.core.$strip>;
44
38
  declare const closeBody: z.ZodObject<{
45
- countedByMethod: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
46
- cash: "cash";
47
- card: "card";
48
- mfs: "mfs";
49
- bank_transfer: "bank_transfer";
50
- }>, z.ZodNumber>>;
39
+ countedByMethod: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
51
40
  varianceOverride: z.ZodOptional<z.ZodObject<{
52
41
  overriddenBy: z.ZodString;
53
42
  reason: z.ZodString;
@@ -1,6 +1,5 @@
1
1
  import { CASH_MOVEMENT_REASON_CODES } from "../domain/enums/cash-movement-reason.enum.mjs";
2
2
  import { CLOSED_BY_VALUES } from "../domain/enums/closed-by.enum.mjs";
3
- import { SHIFT_PAYMENT_METHODS } from "../domain/enums/payment-method.enum.mjs";
4
3
  import { z } from "zod";
5
4
  //#region src/schemas/shift.ts
6
5
  /**
@@ -31,7 +30,7 @@ const recordCashMovementBody = z.object({
31
30
  cashierName: z.string().min(1),
32
31
  timestamp: isoDate.optional()
33
32
  });
34
- const countedByMethodSchema = z.record(z.enum(SHIFT_PAYMENT_METHODS), minorUnits.min(0));
33
+ const countedByMethodSchema = z.record(z.string().min(1), minorUnits.min(0));
35
34
  const blindCloseBody = z.object({
36
35
  countedByMethod: countedByMethodSchema,
37
36
  closingCashierId: z.string().min(1),
@@ -1,6 +1,5 @@
1
1
  import { ShiftPolicy } from "../domain/value-objects/shift-policy.vo.mjs";
2
2
  import { OpenShiftInput } from "../repositories/shift.repository.mjs";
3
-
4
3
  //#region src/testing/fixtures.d.ts
5
4
  declare const TEST_ORG_ID: string;
6
5
  declare function makePolicy(overrides?: Partial<ShiftPolicy>): ShiftPolicy;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classytic/pos",
3
- "version": "0.3.1",
3
+ "version": "0.4.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,23 +71,26 @@
71
71
  "release": "npm run push -- main && npm run release:tag && npm publish"
72
72
  },
73
73
  "peerDependencies": {
74
- "@classytic/mongokit": ">=3.22.0",
75
- "@classytic/primitives": ">=0.11.0",
76
- "@classytic/repo-core": ">=0.13.0",
74
+ "@classytic/mongokit": ">=3.33.0",
75
+ "@classytic/primitives": ">=0.23.0",
76
+ "@classytic/repo-core": ">=0.24.0",
77
+ "@classytic/validation": ">=0.2.0",
77
78
  "mongoose": ">=9.4.1",
78
79
  "zod": ">=4.0.0"
79
80
  },
80
81
  "devDependencies": {
81
82
  "@classytic/dev-tools": "^0.2.0",
82
- "@classytic/mongokit": "^3.22.0",
83
- "@classytic/primitives": "^0.11.0",
84
- "@classytic/repo-core": "^0.13.0",
83
+ "@classytic/mongokit": "^3.33.0",
84
+ "@classytic/primitives": ">=0.23.0",
85
+ "@classytic/repo-core": ">=0.24.0",
86
+ "@classytic/validation": ">=0.4.0",
85
87
  "@types/node": "^25.5.0",
86
88
  "@vitest/coverage-v8": "^3.2.4",
87
89
  "mongodb-memory-server": "^10.2.3",
88
90
  "mongoose": "^9.4.1",
89
- "tsdown": "^0.21.5",
90
- "typescript": "^5.7.0",
91
+ "publint": "^0.3.23",
92
+ "tsdown": "^0.22.14",
93
+ "typescript": "^7.0.2",
91
94
  "vitest": "^3.0.0",
92
95
  "zod": "^4.3.6"
93
96
  },
@@ -106,5 +109,5 @@
106
109
  "mongodb",
107
110
  "mongoose"
108
111
  ],
109
- "license": "MIT"
112
+ "license": "SEE LICENSE IN LICENSE"
110
113
  }
@@ -1,6 +0,0 @@
1
- import { PosConfig, PosEngine } from "./engine-types.mjs";
2
-
3
- //#region src/engine/create-pos.d.ts
4
- declare function createPosEngine(config: PosConfig): PosEngine;
5
- //#endregion
6
- export { createPosEngine };
@@ -1,82 +0,0 @@
1
- import { InProcessPosBus } from "../events/in-process-bus.mjs";
2
- import { PosCapabilityError } from "../domain/errors/pos.errors.mjs";
3
- import { resolvePosTenant } from "../models/inject-tenant.mjs";
4
- import { createPosModels } from "../models/create-models.mjs";
5
- import { ShiftRepository } from "../repositories/shift.repository.mjs";
6
- import { multiTenantPlugin } from "@classytic/mongokit";
7
- //#region src/engine/create-pos.ts
8
- /**
9
- * createPosEngine — factory entry point.
10
- *
11
- * import { createPosEngine } from '@classytic/pos';
12
- * const pos = createPosEngine({ connection, defaultPolicy });
13
- * await pos.repositories.shift.open({ ... }, ctx);
14
- *
15
- * The engine returns a closed-over object — no class, no inheritance.
16
- * Hosts wire arc adapters directly off `pos.repositories.shift` (auto-CRUD)
17
- * and call domain verbs for state changes.
18
- *
19
- * Multi-tenant scoping is ON by default. The mongokit `multiTenantPlugin`
20
- * runs at `policy` priority on every read/write; cross-tenant leakage is
21
- * impossible to forget. Hosts that genuinely need single-tenant deployments
22
- * pass `multiTenant: false`.
23
- */
24
- /**
25
- * Runtime capabilities the transactional close pipeline requires at boot
26
- * (PACKAGE_RULES "Runtime capabilities"). `close` / `forceClose` move state
27
- * via `repo.claim` CAS and hosts routinely wrap multi-doc writes (shift +
28
- * outbox row) in a transaction — assert the backend declares `transactions`
29
- * here instead of failing with a cryptic driver error on the first close.
30
- */
31
- const REQUIRED_CAPABILITIES = ["transactions"];
32
- function createPosEngine(config) {
33
- if (!config.connection) throw new Error("createPosEngine: config.connection is required");
34
- if (!config.defaultPolicy) throw new Error("createPosEngine: config.defaultPolicy is required");
35
- const logger = config.logger ?? console;
36
- const events = config.eventTransport ?? new InProcessPosBus({ logger });
37
- const bridges = config.bridges ?? {};
38
- const tenant = resolvePosTenant({
39
- multiTenant: config.multiTenant === false ? false : true,
40
- tenantFieldType: config.tenantFieldType ?? "objectId",
41
- ...typeof config.multiTenant === "object" ? config.multiTenant : {}
42
- });
43
- const models = createPosModels({
44
- connection: config.connection,
45
- tenant,
46
- ...config.collectionPrefix !== void 0 ? { collectionPrefix: config.collectionPrefix } : {},
47
- ...config.autoIndex !== void 0 ? { autoIndex: config.autoIndex } : {},
48
- ...config.forceRecreate !== void 0 ? { forceRecreate: config.forceRecreate } : {}
49
- });
50
- const tenantPlugins = config.multiTenant === false ? [] : [multiTenantPlugin({
51
- ...typeof config.multiTenant === "object" ? config.multiTenant : {},
52
- fieldType: tenant.fieldType
53
- })];
54
- const shiftRepo = new ShiftRepository({
55
- model: models.Shift,
56
- plugins: tenantPlugins,
57
- defaultPolicy: config.defaultPolicy,
58
- ...bridges.ledger ? { ledgerBridge: bridges.ledger } : {},
59
- ...bridges.policy ? { policyBridge: bridges.policy } : {},
60
- ...bridges.notification ? { notificationBridge: bridges.notification } : {},
61
- eventTransport: events,
62
- ...config.outbox ? { outbox: config.outbox } : {},
63
- logger
64
- });
65
- if (config.allowNonTransactional !== true) {
66
- const caps = shiftRepo.capabilities;
67
- if (!caps) throw new PosCapabilityError(["capabilities descriptor (repo-core 0.6 / mongokit 3.16+)"]);
68
- const missing = REQUIRED_CAPABILITIES.filter((flag) => caps[flag] !== true);
69
- if (missing.length > 0) throw new PosCapabilityError(missing);
70
- }
71
- return {
72
- config: Object.freeze({ ...config }),
73
- bridges: Object.freeze({ ...bridges }),
74
- events,
75
- outbox: config.outbox,
76
- models,
77
- repositories: { shift: shiftRepo },
78
- defaultPolicy: config.defaultPolicy
79
- };
80
- }
81
- //#endregion
82
- export { createPosEngine };