@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
@@ -1,35 +1,40 @@
1
- import { DomainEvent } from "@classytic/primitives/events";
1
+ import { EventDurability } from "@classytic/primitives/durable-events";
2
2
  import { z } from "zod";
3
+ import { DomainEvent } from "@classytic/primitives/events";
3
4
  //#region src/events/event-catalog.d.ts
4
- interface PosEventDefinition<TSchema extends z.ZodType = z.ZodType> {
5
+ export interface PosEventDefinition<TSchema extends z.ZodType = z.ZodType> {
5
6
  readonly name: string;
6
7
  readonly version: number;
7
8
  readonly description?: string;
8
9
  readonly schema: Record<string, unknown>;
9
10
  readonly zodSchema: TSchema;
11
+ /** `durable`: the event books money, so it is written as an outbox row under a fixed id (`occurrence`). */
12
+ readonly durability: EventDurability;
13
+ /** Aggregate id plus step — the same occurrence always yields the same event id. Present iff `durable`. */
14
+ occurrence?(payload: z.infer<TSchema>): string;
10
15
  create(payload: z.infer<TSchema>, meta?: Partial<DomainEvent['meta']>): DomainEvent<z.infer<TSchema>>;
11
16
  readonly __payload?: z.infer<TSchema>;
12
17
  }
13
- type PosEventPayloadOf<D> = D extends PosEventDefinition<infer S> ? z.infer<S> : never;
14
- declare const shiftOpenedEvent: PosEventDefinition<z.ZodObject<{
18
+ export type PosEventPayloadOf<D> = D extends PosEventDefinition<infer S> ? z.infer<S> : never;
19
+ export declare const shiftOpenedEvent: PosEventDefinition<z.ZodObject<{
15
20
  shiftId: z.ZodString;
16
21
  registerId: z.ZodString;
17
22
  openingCashierId: z.ZodString;
18
23
  }, z.core.$strip>>;
19
- declare const shiftPausedEvent: PosEventDefinition<z.ZodObject<{
24
+ export declare const shiftPausedEvent: PosEventDefinition<z.ZodObject<{
20
25
  shiftId: z.ZodString;
21
26
  from: z.ZodString;
22
27
  to: z.ZodString;
23
28
  }, z.core.$strip>>;
24
- declare const shiftResumedEvent: PosEventDefinition<z.ZodObject<{
29
+ export declare const shiftResumedEvent: PosEventDefinition<z.ZodObject<{
25
30
  shiftId: z.ZodString;
26
31
  from: z.ZodString;
27
32
  to: z.ZodString;
28
33
  }, z.core.$strip>>;
29
- declare const shiftBlindClosedEvent: PosEventDefinition<z.ZodObject<{
34
+ export declare const shiftBlindClosedEvent: PosEventDefinition<z.ZodObject<{
30
35
  shiftId: z.ZodString;
31
36
  }, z.core.$strip>>;
32
- declare const shiftClosedEvent: PosEventDefinition<z.ZodObject<{
37
+ export declare const shiftClosedEvent: PosEventDefinition<z.ZodObject<{
33
38
  shiftId: z.ZodString;
34
39
  journalEntryId: z.ZodNullable<z.ZodString>;
35
40
  closedBy: z.ZodEnum<{
@@ -38,14 +43,14 @@ declare const shiftClosedEvent: PosEventDefinition<z.ZodObject<{
38
43
  system_auto: "system_auto";
39
44
  }>;
40
45
  }, z.core.$strip>>;
41
- declare const shiftForceClosedEvent: PosEventDefinition<z.ZodObject<{
46
+ export declare const shiftForceClosedEvent: PosEventDefinition<z.ZodObject<{
42
47
  shiftId: z.ZodString;
43
48
  reason: z.ZodEnum<{
44
49
  admin_override: "admin_override";
45
50
  orphan_eod: "orphan_eod";
46
51
  }>;
47
52
  }, z.core.$strip>>;
48
- declare const cashMovementRecordedEvent: PosEventDefinition<z.ZodObject<{
53
+ export declare const cashMovementRecordedEvent: PosEventDefinition<z.ZodObject<{
49
54
  shiftId: z.ZodString;
50
55
  type: z.ZodEnum<{
51
56
  in: "in";
@@ -62,7 +67,7 @@ declare const cashMovementRecordedEvent: PosEventDefinition<z.ZodObject<{
62
67
  till_top_up: "till_top_up";
63
68
  }>;
64
69
  }, z.core.$strip>>;
65
- declare const varianceDetectedEvent: PosEventDefinition<z.ZodObject<{
70
+ export declare const varianceDetectedEvent: PosEventDefinition<z.ZodObject<{
66
71
  shiftId: z.ZodString;
67
72
  difference: z.ZodNumber;
68
73
  expected: z.ZodNumber;
@@ -72,6 +77,5 @@ declare const varianceDetectedEvent: PosEventDefinition<z.ZodObject<{
72
77
  * `/events` subpath; the no-drift test asserts this covers every
73
78
  * `POS_EVENTS` constant.
74
79
  */
75
- declare const posEventDefinitions: ReadonlyArray<PosEventDefinition>;
76
- //#endregion
77
- export { PosEventDefinition, PosEventPayloadOf, cashMovementRecordedEvent, posEventDefinitions, shiftBlindClosedEvent, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent };
80
+ export declare const posEventDefinitions: ReadonlyArray<PosEventDefinition>;
81
+ //#endregion
@@ -1,8 +1,9 @@
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
3
  import { POS_EVENTS } from "./event-constants.mjs";
4
- import { createEvent } from "@classytic/primitives/events";
4
+ import { durableEventMeta } from "@classytic/primitives/durable-events";
5
5
  import { z } from "zod";
6
+ import { createEvent } from "@classytic/primitives/events";
6
7
  //#region src/events/event-catalog.ts
7
8
  /**
8
9
  * POS event catalog — every `pos:*` event defined with a Zod schema
@@ -20,16 +21,19 @@ import { z } from "zod";
20
21
  * (§25).
21
22
  */
22
23
  function definePosEvent(input) {
23
- const { name, version = 1, description, zodSchema } = input;
24
+ const { name, version = 1, description, zodSchema, occurrence } = input;
24
25
  return {
25
26
  name,
26
27
  version,
27
28
  ...description !== void 0 ? { description } : {},
28
29
  schema: z.toJSONSchema(zodSchema),
29
30
  zodSchema,
31
+ durability: occurrence ? "durable" : "ephemeral",
32
+ ...occurrence ? { occurrence } : {},
30
33
  create(payload, meta) {
31
34
  return createEvent(name, payload, {
32
35
  resource: "shift",
36
+ ...occurrence ? durableEventMeta(name, version, occurrence(payload)) : {},
33
37
  ...meta
34
38
  });
35
39
  }
@@ -89,12 +93,14 @@ const shiftBlindClosedEvent = definePosEvent({
89
93
  const shiftClosedEvent = definePosEvent({
90
94
  name: POS_EVENTS.SHIFT_CLOSED,
91
95
  description: "Shift reconciled and closed (Z-report); immutable thereafter",
92
- zodSchema: shiftClosedSchema
96
+ zodSchema: shiftClosedSchema,
97
+ occurrence: (p) => p.shiftId
93
98
  });
94
99
  const shiftForceClosedEvent = definePosEvent({
95
100
  name: POS_EVENTS.SHIFT_FORCE_CLOSED,
96
101
  description: "Orphaned shift auto-closed by EOD cron / admin; flagged for review",
97
- zodSchema: shiftForceClosedSchema
102
+ zodSchema: shiftForceClosedSchema,
103
+ occurrence: (p) => p.shiftId
98
104
  });
99
105
  const cashMovementRecordedEvent = definePosEvent({
100
106
  name: POS_EVENTS.CASH_MOVEMENT_RECORDED,
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * Naming follows PACKAGE_RULES §12: `package:resource.verb`.
8
8
  */
9
- declare const POS_EVENTS: {
9
+ export declare const POS_EVENTS: {
10
10
  readonly SHIFT_OPENED: 'pos:shift.opened';
11
11
  readonly SHIFT_PAUSED: 'pos:shift.paused';
12
12
  readonly SHIFT_RESUMED: 'pos:shift.resumed';
@@ -16,6 +16,5 @@ declare const POS_EVENTS: {
16
16
  readonly CASH_MOVEMENT_RECORDED: 'pos:cash_movement.recorded';
17
17
  readonly VARIANCE_DETECTED: 'pos:shift.variance.detected';
18
18
  };
19
- type PosEventName = (typeof POS_EVENTS)[keyof typeof POS_EVENTS];
20
- //#endregion
21
- export { POS_EVENTS, PosEventName };
19
+ export type PosEventName = (typeof POS_EVENTS)[keyof typeof POS_EVENTS];
20
+ //#endregion
@@ -1,40 +1,40 @@
1
1
  import { CashMovementReasonCode } from "../domain/enums/cash-movement-reason.enum.mjs";
2
2
  import { ClosedBy } from "../domain/enums/closed-by.enum.mjs";
3
3
  //#region src/events/event-payloads.d.ts
4
- interface ShiftOpenedPayload {
4
+ export interface ShiftOpenedPayload {
5
5
  shiftId: string;
6
6
  registerId: string;
7
7
  openingCashierId: string;
8
8
  }
9
- interface ShiftClosedPayload {
9
+ export interface ShiftClosedPayload {
10
10
  shiftId: string;
11
11
  journalEntryId: string | null;
12
12
  closedBy: ClosedBy;
13
13
  }
14
- interface ShiftBlindClosedPayload {
14
+ export interface ShiftBlindClosedPayload {
15
15
  shiftId: string;
16
16
  }
17
- interface ShiftForceClosedPayload {
17
+ export interface ShiftForceClosedPayload {
18
18
  shiftId: string;
19
19
  reason: 'orphan_eod' | 'admin_override';
20
20
  }
21
- interface ShiftStateChangedPayload {
21
+ export interface ShiftStateChangedPayload {
22
22
  shiftId: string;
23
23
  from: string;
24
24
  to: string;
25
25
  }
26
- interface CashMovementRecordedPayload {
26
+ export interface CashMovementRecordedPayload {
27
27
  shiftId: string;
28
28
  type: 'in' | 'out';
29
29
  amount: number;
30
30
  reasonCode: CashMovementReasonCode;
31
31
  }
32
- interface VarianceDetectedPayload {
32
+ export interface VarianceDetectedPayload {
33
33
  shiftId: string;
34
34
  difference: number;
35
35
  expected: number;
36
36
  }
37
- interface PosEventPayloads {
37
+ export interface PosEventPayloads {
38
38
  'pos:shift.opened': ShiftOpenedPayload;
39
39
  'pos:shift.paused': ShiftStateChangedPayload;
40
40
  'pos:shift.resumed': ShiftStateChangedPayload;
@@ -44,5 +44,4 @@ interface PosEventPayloads {
44
44
  'pos:cash_movement.recorded': CashMovementRecordedPayload;
45
45
  'pos:shift.variance.detected': VarianceDetectedPayload;
46
46
  }
47
- //#endregion
48
- export { CashMovementRecordedPayload, PosEventPayloads, ShiftBlindClosedPayload, ShiftClosedPayload, ShiftForceClosedPayload, ShiftOpenedPayload, ShiftStateChangedPayload, VarianceDetectedPayload };
47
+ //#endregion
@@ -1,5 +1,8 @@
1
1
  import { DomainEvent } from "@classytic/primitives/events";
2
2
  //#region src/events/helpers.d.ts
3
- declare function createPosEvent<T extends Record<string, unknown>>(name: string, payload: T): DomainEvent<T>;
4
- //#endregion
5
- export { createPosEvent };
3
+ /** `fixed` stamps the durable id (`${name}:v${version}:${occurrence}`): one occurrence is one row, however often it is written. */
4
+ export declare function createPosEvent<T extends Record<string, unknown>>(name: string, payload: T, fixed?: {
5
+ version: number;
6
+ occurrence: string;
7
+ }): DomainEvent<T>;
8
+ //#endregion
@@ -1,3 +1,4 @@
1
+ import { durableEventMeta } from "@classytic/primitives/durable-events";
1
2
  import { createScopedEvent } from "@classytic/primitives/events";
2
3
  //#region src/events/helpers.ts
3
4
  /**
@@ -5,8 +6,17 @@ import { createScopedEvent } from "@classytic/primitives/events";
5
6
  * event id / timestamp / source stamping live in one shared place. Internal —
6
7
  * the package's domain verbs call this.
7
8
  */
8
- function createPosEvent(name, payload) {
9
- return createScopedEvent("@classytic/pos", name, payload);
9
+ /** `fixed` stamps the durable id (`${name}:v${version}:${occurrence}`): one occurrence is one row, however often it is written. */
10
+ function createPosEvent(name, payload, fixed) {
11
+ const event = createScopedEvent("@classytic/pos", name, payload);
12
+ if (!fixed) return event;
13
+ return {
14
+ ...event,
15
+ meta: {
16
+ ...event.meta,
17
+ ...durableEventMeta(name, fixed.version, fixed.occurrence)
18
+ }
19
+ };
10
20
  }
11
21
  //#endregion
12
22
  export { createPosEvent };
@@ -1,8 +1,7 @@
1
1
  import { InProcessEventBus, InProcessEventBusOptions } from "@classytic/primitives/event-infra";
2
2
  //#region src/events/in-process-bus.d.ts
3
- type InProcessPosBusOptions = InProcessEventBusOptions;
4
- declare class InProcessPosBus extends InProcessEventBus {
3
+ export type InProcessPosBusOptions = InProcessEventBusOptions;
4
+ export declare class InProcessPosBus extends InProcessEventBus {
5
5
  constructor(options?: InProcessPosBusOptions);
6
6
  }
7
- //#endregion
8
- export { InProcessPosBus, InProcessPosBusOptions };
7
+ //#endregion
@@ -1,6 +1,6 @@
1
1
  import { InProcessPosBus } from "./in-process-bus.mjs";
2
2
  import { POS_EVENTS } from "./event-constants.mjs";
3
- import { createPosEvent } from "./helpers.mjs";
4
3
  import { cashMovementRecordedEvent, posEventDefinitions, shiftBlindClosedEvent, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent } from "./event-catalog.mjs";
4
+ import { createPosEvent } from "./helpers.mjs";
5
5
  import { InvalidOutboxEventError, MemoryOutboxStore, OutboxOwnershipError } from "./outbox-store.mjs";
6
6
  export { InProcessPosBus, InvalidOutboxEventError, MemoryOutboxStore, OutboxOwnershipError, POS_EVENTS, cashMovementRecordedEvent, createPosEvent, posEventDefinitions, shiftBlindClosedEvent, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent };
@@ -0,0 +1,50 @@
1
+ import { ShiftPolicy } from "../domain/value-objects/shift-policy.vo.mjs";
2
+ import { OrderDiscountLimits } from "../domain/sale/discount.mjs";
3
+ import { VerifiedToken } from "@classytic/primitives/signed-token";
4
+ //#region src/grant/till-grant.d.ts
5
+ export declare const TILL_GRANT_TYPE = "till-grant+jwt";
6
+ export interface TillGrant {
7
+ readonly v: 1;
8
+ /** The grant's id — what each offline command names. */
9
+ readonly jti: string;
10
+ /** The till it was issued to: its sn, which is also its sync stream. */
11
+ readonly sub: string;
12
+ /** Branch. */
13
+ readonly org: string;
14
+ /** Register the till is bound to. */
15
+ readonly reg: string;
16
+ readonly iat: number;
17
+ readonly exp: number;
18
+ readonly policy: ShiftPolicy;
19
+ readonly discount: OrderDiscountLimits;
20
+ /** A carry-out sale is never refused for its count (`@spinekit/pos` `isGoodsInHandSale`). */
21
+ readonly counterSaleGoodsInHand: boolean;
22
+ }
23
+ /** A grant for THIS till, verified and whole — or why not. */
24
+ export declare function readTillGrant(token: string, keyOf: (kid: string) => CryptoKey | undefined | Promise<CryptoKey | undefined>, options: {
25
+ sn: string;
26
+ now?: Date | undefined;
27
+ leewaySeconds?: number | undefined;
28
+ }): Promise<VerifiedToken<TillGrant> | {
29
+ readonly ok: false;
30
+ readonly reason: 'wrong_device';
31
+ }>;
32
+ /** What a recorded sale did outside the grant it names — each one a reason for review. */
33
+ export type GrantFinding = 'grant_expired' | 'discount_over_grant' | 'full_comp_not_granted';
34
+ /**
35
+ * Check a sale a till recorded offline against the grant it was made under. The sale happened, so
36
+ * a finding never undoes it; it sends it to review. Device time is evidence, not proof.
37
+ */
38
+ export declare function checkSaleAgainstGrant(input: {
39
+ grant: {
40
+ readonly expiresAt: Date;
41
+ readonly discount: OrderDiscountLimits;
42
+ };
43
+ occurredAt: Date;
44
+ discount?: {
45
+ readonly subtotalMinor: number;
46
+ readonly grantedMinor: number;
47
+ readonly fullComp?: boolean | undefined;
48
+ } | undefined;
49
+ }): GrantFinding[];
50
+ //#endregion
@@ -0,0 +1,47 @@
1
+ import { discountCeilingMinor } from "../domain/sale/discount.mjs";
2
+ import { verifyToken } from "@classytic/primitives/signed-token";
3
+ //#region src/grant/till-grant.ts
4
+ /**
5
+ * The till's offline grant: what the server signed that this device may do while it cannot ask —
6
+ * its branch and register, the shift policy, the discount ceiling and the counter-sale rule. The
7
+ * server issues a fresh one on every sync, so its `iat` is also the signed checkpoint of server
8
+ * time. A till acts offline only within the grant it holds, and every command it records names
9
+ * that grant (`actor.grantId` = `jti`).
10
+ */
11
+ const TILL_GRANT_TYPE = "till-grant+jwt";
12
+ /** A grant for THIS till, verified and whole — or why not. */
13
+ async function readTillGrant(token, keyOf, options) {
14
+ const read = await verifyToken(token, keyOf, {
15
+ typ: TILL_GRANT_TYPE,
16
+ now: options.now,
17
+ leewaySeconds: options.leewaySeconds
18
+ });
19
+ if (!read.ok) return read;
20
+ const g = read.claims;
21
+ if (!(g.v === 1 && typeof g.jti === "string" && typeof g.org === "string" && typeof g.reg === "string" && typeof g.iat === "number" && typeof g.policy === "object" && g.policy !== null && typeof g.discount === "object" && g.discount !== null && typeof g.counterSaleGoodsInHand === "boolean")) return {
22
+ ok: false,
23
+ reason: "malformed"
24
+ };
25
+ if (g.sub !== options.sn) return {
26
+ ok: false,
27
+ reason: "wrong_device"
28
+ };
29
+ return read;
30
+ }
31
+ /**
32
+ * Check a sale a till recorded offline against the grant it was made under. The sale happened, so
33
+ * a finding never undoes it; it sends it to review. Device time is evidence, not proof.
34
+ */
35
+ function checkSaleAgainstGrant(input) {
36
+ const findings = [];
37
+ if (input.occurredAt.getTime() >= input.grant.expiresAt.getTime()) findings.push("grant_expired");
38
+ const d = input.discount;
39
+ if (d && d.grantedMinor > 0) {
40
+ const ceiling = discountCeilingMinor(input.grant.discount, d.subtotalMinor);
41
+ if (ceiling !== void 0 && d.grantedMinor > ceiling) findings.push("discount_over_grant");
42
+ if (d.grantedMinor >= d.subtotalMinor && !input.grant.discount.allowFullComp) findings.push("full_comp_not_granted");
43
+ }
44
+ return findings;
45
+ }
46
+ //#endregion
47
+ export { TILL_GRANT_TYPE, checkSaleAgainstGrant, readTillGrant };
package/dist/index.d.mts CHANGED
@@ -5,20 +5,30 @@ import { CLOSED_BY_VALUES, ClosedBy } from "./domain/enums/closed-by.enum.mjs";
5
5
  import { SHIFT_VERBS, ShiftVerb, allowedVerbs, canTransition, nextState } from "./domain/state-machines/shift.fsm.mjs";
6
6
  import { CashMovement } from "./domain/value-objects/cash-movement.vo.mjs";
7
7
  import { PaymentBreakdown, computeDifference, computeExpected } from "./domain/value-objects/payment-breakdown.vo.mjs";
8
- import { ShiftPolicy, defaultShiftPolicy, isWithinVarianceThreshold } from "./domain/value-objects/shift-policy.vo.mjs";
9
- import { ActiveShiftAlreadyOpenError, CashMovementInvalidError, IllegalShiftTransitionError, PosCapabilityError, PosError, ShiftCountsRequiredError, ShiftFinalizedError, ShiftNotFoundError, ShiftPausedError, UnmanagedSessionError, VarianceExceededError } from "./domain/errors/pos.errors.mjs";
8
+ import { ShiftPolicy, defaultShiftPolicy, isReasonCodeAllowed, isWithinVarianceThreshold } from "./domain/value-objects/shift-policy.vo.mjs";
9
+ import { ActiveRegister, ActiveShiftAlreadyOpenError, CashMovementInvalidError, CashMovementKeyReusedError, CashOutExceedsDrawerError, IllegalShiftTransitionError, OrderDiscountRefusal, OrderDiscountRefusedError, PosCapabilityError, PosError, PriceOverrideRefusedError, ReasonCodePolicyInvalidError, RegisterRequiredError, ShiftCountsRequiredError, ShiftFinalizedError, ShiftNotFoundError, ShiftPausedError, TenderMethodRefusal, TenderMethodRefusedError, TenderMismatchError, UnmanagedSessionError, VarianceExceededError } from "./domain/errors/pos.errors.mjs";
10
+ import { AllocatedTenderLeg, DEFAULT_TENDER_METHOD_RESOLVER, PosTenderSummary, ResolvedTenderMethod, TenderAllocation, TenderLegInput, TenderMethodDeclaration, TenderMethodResolver, TenderMethodTableOptions, TenderPolicy, TenderSettlement, TillTenderMethod, ValidatedTenderLeg, allocateTender, assertTenderSettles, createTenderMethodResolver, tenderSummary, tillTenderMethods, validateTenderLegs } from "./domain/sale/tender.mjs";
11
+ import { DecideOrderDiscountInput, OrderDiscountDecision, OrderDiscountLimits, PosOrderDiscountRecord, decideOrderDiscount, discountCeilingMinor } from "./domain/sale/discount.mjs";
12
+ import { DecideLinePriceInput, LinePriceDecision, PRICE_OVERRIDE_NOTE_MAX, PRICE_OVERRIDE_REASONS, PRICE_OVERRIDE_REASONS_NEEDING_NOTE, PosPriceOverrideRecord, PriceOverrideReason, decideLinePrice, isPriceOverrideReason } from "./domain/sale/price-override.mjs";
13
+ import { serviceSku, serviceSlug } from "./domain/sale/service-line.mjs";
14
+ import { quickCashAmounts } from "./domain/sale/quick-cash.mjs";
15
+ import { CountableRow, ShiftCloseDecision, applyCounts, decideBlindClose, decideShiftClose, isCashRow, seedBreakdown } from "./domain/shift/shift-decisions.mjs";
16
+ import { ReportOrder, ReportShift, ShiftReport, buildShiftReport } from "./domain/shift/shift-report.mjs";
17
+ import { IShift, PendingLedgerPost, PendingLedgerPostTrigger, ShiftRecord } from "./domain/shift/shift.types.mjs";
10
18
  import { PosContext } from "./domain/ports/common.mjs";
11
- import { IShift, PendingLedgerPost, PendingLedgerPostTrigger, ShiftDocument, ShiftModel } from "./models/shift.model.mjs";
12
19
  import { LedgerBridge, ShiftClosePosting, shiftCloseIdempotencyKey } from "./domain/ports/ledger.bridge.mjs";
13
20
  import { PolicyBridge } from "./domain/ports/policy.bridge.mjs";
14
21
  import { NotificationBridge } from "./domain/ports/notification.bridge.mjs";
15
22
  import "./domain/index.mjs";
16
23
  import { IRegister, RegisterDocument, RegisterModel } from "./models/register.model.mjs";
17
24
  import { IShiftSaleDedupe, ShiftSaleDedupeDocument, ShiftSaleDedupeModel } from "./models/shift-sale-dedupe.model.mjs";
25
+ import { ITillGrant, TillGrantDocument, TillGrantModel } from "./models/till-grant.model.mjs";
18
26
  import { DEFAULT_COLLECTIONS, POS_MODEL_NAMES, PosModels } from "./models/create-models.mjs";
19
27
  import { RegisterRepository, RegisterRepositoryConfig } from "./repositories/register.repository.mjs";
20
28
  import { InvalidOutboxEventError, MemoryOutboxStore, OutboxAcknowledgeOptions, OutboxClaimOptions, OutboxFailOptions, OutboxOwnershipError, OutboxStore, OutboxWriteOptions } from "./events/outbox-store.mjs";
29
+ import { ShiftDocument, ShiftModel } from "./models/shift.model.mjs";
21
30
  import { BlindCloseInput, CloseShiftInput, CloseShiftResult, IncrementSalesInput, IncrementSalesResult, OpenShiftInput, RecordCashMovementInput, ShiftCloseOutcome, ShiftRepository, ShiftRepositoryConfig } from "./repositories/shift.repository.mjs";
31
+ import { TillGrantRepository } from "./repositories/till-grant.repository.mjs";
22
32
  import { PosBlueprint, PosBridges, PosEngine, PosLogger, PosRepositories, PosRuntime, PosShape, ResolvedPosConfig } from "./engine/engine-types.mjs";
23
33
  import { definePos } from "./engine/define-pos.mjs";
24
34
  import { POS_EVENTS, PosEventName } from "./events/event-constants.mjs";
@@ -27,4 +37,4 @@ import { createPosEvent } from "./events/helpers.mjs";
27
37
  import { InProcessPosBus } from "./events/in-process-bus.mjs";
28
38
  import { PosEventDefinition, PosEventPayloadOf, cashMovementRecordedEvent, posEventDefinitions, shiftBlindClosedEvent, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent } from "./events/event-catalog.mjs";
29
39
  import "./events/index.mjs";
30
- export { ACTIVE_SHIFT_STATES, ActiveShiftAlreadyOpenError, type BlindCloseInput, CASH_MOVEMENT_REASON_CODES, CLOSED_BY_VALUES, CashMovement, CashMovementInvalidError, CashMovementReasonCode, CashMovementRecordedPayload, type CloseShiftInput, type CloseShiftResult, ClosedBy, DEFAULT_COLLECTIONS, DEFAULT_METHOD_KINDS, FINAL_SHIFT_STATES, type IRegister, type IShift, type IShiftSaleDedupe, IllegalShiftTransitionError, InProcessPosBus, type IncrementSalesInput, type IncrementSalesResult, InvalidOutboxEventError, type LedgerBridge, MemoryOutboxStore, type NotificationBridge, type OpenShiftInput, type OutboxAcknowledgeOptions, type OutboxClaimOptions, type OutboxFailOptions, OutboxOwnershipError, type OutboxStore, type OutboxWriteOptions, PAYMENT_METHOD_KIND_VALUES, POS_EVENTS, POS_MODEL_NAMES, PaymentBreakdown, type PendingLedgerPost, type PendingLedgerPostTrigger, type PolicyBridge, type PosBlueprint, type PosBridges, PosCapabilityError, type PosContext, type PosEngine, PosError, type PosEventDefinition, PosEventName, type PosEventPayloadOf, PosEventPayloads, type PosLogger, type PosModels, type PosRepositories, type PosRuntime, type PosShape, type RecordCashMovementInput, type RegisterDocument, type RegisterModel, RegisterRepository, type RegisterRepositoryConfig, type ResolvedPosConfig, SHIFT_PAYMENT_METHODS, SHIFT_STATES, SHIFT_VERBS, ShiftBlindClosedPayload, type ShiftCloseOutcome, type ShiftClosePosting, ShiftClosedPayload, ShiftCountsRequiredError, type ShiftDocument, ShiftFinalizedError, ShiftForceClosedPayload, type ShiftModel, ShiftNotFoundError, ShiftOpenedPayload, ShiftPausedError, ShiftPaymentMethod, ShiftPolicy, ShiftRepository, type ShiftRepositoryConfig, type ShiftSaleDedupeDocument, type ShiftSaleDedupeModel, ShiftState, ShiftStateChangedPayload, ShiftVerb, UnmanagedSessionError, VarianceDetectedPayload, VarianceExceededError, allowedVerbs, canTransition, cashMovementRecordedEvent, computeDifference, computeExpected, createPosEvent, defaultShiftPolicy, definePos, isActiveShiftState, isFinalShiftState, isWithinVarianceThreshold, nextState, posEventDefinitions, resolveMethodKind, shiftBlindClosedEvent, shiftCloseIdempotencyKey, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent };
40
+ export { ACTIVE_SHIFT_STATES, ActiveRegister, ActiveShiftAlreadyOpenError, AllocatedTenderLeg, type BlindCloseInput, CASH_MOVEMENT_REASON_CODES, CLOSED_BY_VALUES, CashMovement, CashMovementInvalidError, CashMovementKeyReusedError, CashMovementReasonCode, CashMovementRecordedPayload, CashOutExceedsDrawerError, type CloseShiftInput, type CloseShiftResult, ClosedBy, CountableRow, DEFAULT_COLLECTIONS, DEFAULT_METHOD_KINDS, DEFAULT_TENDER_METHOD_RESOLVER, DecideLinePriceInput, DecideOrderDiscountInput, FINAL_SHIFT_STATES, type IRegister, type IShift, type IShiftSaleDedupe, type ITillGrant, IllegalShiftTransitionError, InProcessPosBus, type IncrementSalesInput, type IncrementSalesResult, InvalidOutboxEventError, type LedgerBridge, LinePriceDecision, MemoryOutboxStore, type NotificationBridge, type OpenShiftInput, OrderDiscountDecision, OrderDiscountLimits, OrderDiscountRefusal, OrderDiscountRefusedError, type OutboxAcknowledgeOptions, type OutboxClaimOptions, type OutboxFailOptions, OutboxOwnershipError, type OutboxStore, type OutboxWriteOptions, PAYMENT_METHOD_KIND_VALUES, POS_EVENTS, POS_MODEL_NAMES, PRICE_OVERRIDE_NOTE_MAX, PRICE_OVERRIDE_REASONS, PRICE_OVERRIDE_REASONS_NEEDING_NOTE, PaymentBreakdown, type PendingLedgerPost, type PendingLedgerPostTrigger, type PolicyBridge, type PosBlueprint, type PosBridges, PosCapabilityError, type PosContext, type PosEngine, PosError, type PosEventDefinition, PosEventName, type PosEventPayloadOf, PosEventPayloads, type PosLogger, type PosModels, PosOrderDiscountRecord, PosPriceOverrideRecord, type PosRepositories, type PosRuntime, type PosShape, PosTenderSummary, PriceOverrideReason, PriceOverrideRefusedError, ReasonCodePolicyInvalidError, type RecordCashMovementInput, type RegisterDocument, type RegisterModel, RegisterRepository, type RegisterRepositoryConfig, RegisterRequiredError, ReportOrder, ReportShift, type ResolvedPosConfig, ResolvedTenderMethod, SHIFT_PAYMENT_METHODS, SHIFT_STATES, SHIFT_VERBS, ShiftBlindClosedPayload, ShiftCloseDecision, type ShiftCloseOutcome, type ShiftClosePosting, ShiftClosedPayload, ShiftCountsRequiredError, type ShiftDocument, ShiftFinalizedError, ShiftForceClosedPayload, type ShiftModel, ShiftNotFoundError, ShiftOpenedPayload, ShiftPausedError, ShiftPaymentMethod, ShiftPolicy, type ShiftRecord, ShiftReport, ShiftRepository, type ShiftRepositoryConfig, type ShiftSaleDedupeDocument, type ShiftSaleDedupeModel, ShiftState, ShiftStateChangedPayload, ShiftVerb, TenderAllocation, TenderLegInput, TenderMethodDeclaration, TenderMethodRefusal, TenderMethodRefusedError, TenderMethodResolver, TenderMethodTableOptions, TenderMismatchError, TenderPolicy, TenderSettlement, type TillGrantDocument, type TillGrantModel, TillGrantRepository, TillTenderMethod, UnmanagedSessionError, ValidatedTenderLeg, VarianceDetectedPayload, VarianceExceededError, allocateTender, allowedVerbs, applyCounts, assertTenderSettles, buildShiftReport, canTransition, cashMovementRecordedEvent, computeDifference, computeExpected, createPosEvent, createTenderMethodResolver, decideBlindClose, decideLinePrice, decideOrderDiscount, decideShiftClose, defaultShiftPolicy, definePos, discountCeilingMinor, isActiveShiftState, isCashRow, isFinalShiftState, isPriceOverrideReason, isReasonCodeAllowed, isWithinVarianceThreshold, nextState, posEventDefinitions, quickCashAmounts, resolveMethodKind, seedBreakdown, serviceSku, serviceSlug, shiftBlindClosedEvent, shiftCloseIdempotencyKey, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, tenderSummary, tillTenderMethods, validateTenderLegs, varianceDetectedEvent };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ActiveShiftAlreadyOpenError, CashMovementInvalidError, IllegalShiftTransitionError, PosCapabilityError, PosError, ShiftCountsRequiredError, ShiftFinalizedError, ShiftNotFoundError, ShiftPausedError, UnmanagedSessionError, VarianceExceededError } from "./domain/errors/pos.errors.mjs";
1
+ import { ActiveShiftAlreadyOpenError, CashMovementInvalidError, CashMovementKeyReusedError, CashOutExceedsDrawerError, IllegalShiftTransitionError, OrderDiscountRefusedError, PosCapabilityError, PosError, PriceOverrideRefusedError, ReasonCodePolicyInvalidError, RegisterRequiredError, ShiftCountsRequiredError, ShiftFinalizedError, ShiftNotFoundError, ShiftPausedError, TenderMethodRefusedError, TenderMismatchError, UnmanagedSessionError, VarianceExceededError } from "./domain/errors/pos.errors.mjs";
2
2
  import { InProcessPosBus } from "./events/in-process-bus.mjs";
3
3
  import { CASH_MOVEMENT_REASON_CODES } from "./domain/enums/cash-movement-reason.enum.mjs";
4
4
  import { CLOSED_BY_VALUES } from "./domain/enums/closed-by.enum.mjs";
@@ -9,11 +9,19 @@ import { RegisterRepository } from "./repositories/register.repository.mjs";
9
9
  import { shiftCloseIdempotencyKey } from "./domain/ports/ledger.bridge.mjs";
10
10
  import { SHIFT_VERBS, allowedVerbs, canTransition, nextState } from "./domain/state-machines/shift.fsm.mjs";
11
11
  import { computeDifference, computeExpected } from "./domain/value-objects/payment-breakdown.vo.mjs";
12
- import { defaultShiftPolicy, isWithinVarianceThreshold } from "./domain/value-objects/shift-policy.vo.mjs";
12
+ import { defaultShiftPolicy, isReasonCodeAllowed, isWithinVarianceThreshold } from "./domain/value-objects/shift-policy.vo.mjs";
13
+ import { applyCounts, decideBlindClose, decideShiftClose, isCashRow, seedBreakdown } from "./domain/shift/shift-decisions.mjs";
13
14
  import { POS_EVENTS } from "./events/event-constants.mjs";
15
+ import { cashMovementRecordedEvent, posEventDefinitions, shiftBlindClosedEvent, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent } from "./events/event-catalog.mjs";
14
16
  import { createPosEvent } from "./events/helpers.mjs";
15
17
  import { ShiftRepository } from "./repositories/shift.repository.mjs";
18
+ import { TillGrantRepository } from "./repositories/till-grant.repository.mjs";
16
19
  import { definePos } from "./engine/define-pos.mjs";
17
- import { cashMovementRecordedEvent, posEventDefinitions, shiftBlindClosedEvent, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent } from "./events/event-catalog.mjs";
20
+ import { DEFAULT_TENDER_METHOD_RESOLVER, allocateTender, assertTenderSettles, createTenderMethodResolver, tenderSummary, tillTenderMethods, validateTenderLegs } from "./domain/sale/tender.mjs";
21
+ import { decideOrderDiscount, discountCeilingMinor } from "./domain/sale/discount.mjs";
22
+ import { PRICE_OVERRIDE_NOTE_MAX, PRICE_OVERRIDE_REASONS, PRICE_OVERRIDE_REASONS_NEEDING_NOTE, decideLinePrice, isPriceOverrideReason } from "./domain/sale/price-override.mjs";
23
+ import { serviceSku, serviceSlug } from "./domain/sale/service-line.mjs";
24
+ import { quickCashAmounts } from "./domain/sale/quick-cash.mjs";
25
+ import { buildShiftReport } from "./domain/shift/shift-report.mjs";
18
26
  import { InvalidOutboxEventError, MemoryOutboxStore, OutboxOwnershipError } from "./events/outbox-store.mjs";
19
- export { ACTIVE_SHIFT_STATES, ActiveShiftAlreadyOpenError, CASH_MOVEMENT_REASON_CODES, CLOSED_BY_VALUES, CashMovementInvalidError, DEFAULT_COLLECTIONS, DEFAULT_METHOD_KINDS, FINAL_SHIFT_STATES, IllegalShiftTransitionError, InProcessPosBus, InvalidOutboxEventError, MemoryOutboxStore, OutboxOwnershipError, PAYMENT_METHOD_KIND_VALUES, POS_EVENTS, POS_MODEL_NAMES, PosCapabilityError, PosError, RegisterRepository, SHIFT_PAYMENT_METHODS, SHIFT_STATES, SHIFT_VERBS, ShiftCountsRequiredError, ShiftFinalizedError, ShiftNotFoundError, ShiftPausedError, ShiftRepository, UnmanagedSessionError, VarianceExceededError, allowedVerbs, canTransition, cashMovementRecordedEvent, computeDifference, computeExpected, createPosEvent, defaultShiftPolicy, definePos, isActiveShiftState, isFinalShiftState, isWithinVarianceThreshold, nextState, posEventDefinitions, resolveMethodKind, shiftBlindClosedEvent, shiftCloseIdempotencyKey, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent };
27
+ export { ACTIVE_SHIFT_STATES, ActiveShiftAlreadyOpenError, CASH_MOVEMENT_REASON_CODES, CLOSED_BY_VALUES, CashMovementInvalidError, CashMovementKeyReusedError, CashOutExceedsDrawerError, DEFAULT_COLLECTIONS, DEFAULT_METHOD_KINDS, DEFAULT_TENDER_METHOD_RESOLVER, FINAL_SHIFT_STATES, IllegalShiftTransitionError, InProcessPosBus, InvalidOutboxEventError, MemoryOutboxStore, OrderDiscountRefusedError, OutboxOwnershipError, PAYMENT_METHOD_KIND_VALUES, POS_EVENTS, POS_MODEL_NAMES, PRICE_OVERRIDE_NOTE_MAX, PRICE_OVERRIDE_REASONS, PRICE_OVERRIDE_REASONS_NEEDING_NOTE, PosCapabilityError, PosError, PriceOverrideRefusedError, ReasonCodePolicyInvalidError, RegisterRepository, RegisterRequiredError, SHIFT_PAYMENT_METHODS, SHIFT_STATES, SHIFT_VERBS, ShiftCountsRequiredError, ShiftFinalizedError, ShiftNotFoundError, ShiftPausedError, ShiftRepository, TenderMethodRefusedError, TenderMismatchError, TillGrantRepository, UnmanagedSessionError, VarianceExceededError, allocateTender, allowedVerbs, applyCounts, assertTenderSettles, buildShiftReport, canTransition, cashMovementRecordedEvent, computeDifference, computeExpected, createPosEvent, createTenderMethodResolver, decideBlindClose, decideLinePrice, decideOrderDiscount, decideShiftClose, defaultShiftPolicy, definePos, discountCeilingMinor, isActiveShiftState, isCashRow, isFinalShiftState, isPriceOverrideReason, isReasonCodeAllowed, isWithinVarianceThreshold, nextState, posEventDefinitions, quickCashAmounts, resolveMethodKind, seedBreakdown, serviceSku, serviceSlug, shiftBlindClosedEvent, shiftCloseIdempotencyKey, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, tenderSummary, tillTenderMethods, validateTenderLegs, varianceDetectedEvent };
@@ -1,7 +1,8 @@
1
+ import { IShift } from "../domain/shift/shift.types.mjs";
1
2
  import "./inject-tenant.mjs";
2
- import { IShift } from "./shift.model.mjs";
3
3
  import { IRegister } from "./register.model.mjs";
4
4
  import { IShiftSaleDedupe } from "./shift-sale-dedupe.model.mjs";
5
+ import { ITillGrant } from "./till-grant.model.mjs";
5
6
  import "@classytic/mongokit";
6
7
  import { Model } from "mongoose";
7
8
  //#region src/models/create-models.d.ts
@@ -14,23 +15,26 @@ import { Model } from "mongoose";
14
15
  * the reader sees a plausible empty result. So the name is stated once, here, by
15
16
  * the package that owns the model, and consumers import it.
16
17
  */
17
- declare const POS_MODEL_NAMES: {
18
+ export declare const POS_MODEL_NAMES: {
18
19
  readonly Shift: 'Shift';
19
20
  readonly Register: 'Register';
20
21
  readonly ShiftSaleDedupe: 'ShiftSaleDedupe';
22
+ readonly TillGrant: 'TillGrant';
21
23
  };
22
24
  /** Single source of truth for collection names. Renaming = breaking change. */
23
- declare const DEFAULT_COLLECTIONS: {
25
+ export declare const DEFAULT_COLLECTIONS: {
24
26
  readonly Shift: 'pos_shifts';
25
27
  readonly Register: 'pos_registers';
26
28
  readonly ShiftSaleDedupe: 'pos_shift_sale_dedupe';
29
+ readonly TillGrant: 'pos_till_grants';
27
30
  };
28
31
  /** The typed model bag every bind produces — the engine's `models` surface. */
29
- interface PosModels {
32
+ export interface PosModels {
30
33
  Shift: Model<IShift>;
31
34
  Register: Model<IRegister>;
32
35
  /** incrementSales({ dedupeRef }) claim ledger — see shift-sale-dedupe.model.ts. */
33
36
  ShiftSaleDedupe: Model<IShiftSaleDedupe>;
37
+ /** Grants issued to paired tills — see till-grant.model.ts. */
38
+ TillGrant: Model<ITillGrant>;
34
39
  }
35
- //#endregion
36
- export { DEFAULT_COLLECTIONS, POS_MODEL_NAMES, PosModels };
40
+ //#endregion
@@ -1,5 +1,6 @@
1
1
  import { buildRegisterSchema } from "./register.model.mjs";
2
2
  import { buildShiftSaleDedupeSchema } from "./shift-sale-dedupe.model.mjs";
3
+ import { buildTillGrantSchema } from "./till-grant.model.mjs";
3
4
  import { buildShiftSchema } from "./shift.model.mjs";
4
5
  import { defineModels } from "@classytic/mongokit";
5
6
  //#region src/models/create-models.ts
@@ -30,13 +31,15 @@ import { defineModels } from "@classytic/mongokit";
30
31
  const POS_MODEL_NAMES = {
31
32
  Shift: "Shift",
32
33
  Register: "Register",
33
- ShiftSaleDedupe: "ShiftSaleDedupe"
34
+ ShiftSaleDedupe: "ShiftSaleDedupe",
35
+ TillGrant: "TillGrant"
34
36
  };
35
37
  /** Single source of truth for collection names. Renaming = breaking change. */
36
38
  const DEFAULT_COLLECTIONS = {
37
39
  Shift: "pos_shifts",
38
40
  Register: "pos_registers",
39
- ShiftSaleDedupe: "pos_shift_sale_dedupe"
41
+ ShiftSaleDedupe: "pos_shift_sale_dedupe",
42
+ TillGrant: "pos_till_grants"
40
43
  };
41
44
  /**
42
45
  * Describe the POS model set as a connection-free blueprint. Pure — builds no
@@ -74,12 +77,22 @@ function definePosModels(config) {
74
77
  collection: prefix + DEFAULT_COLLECTIONS.ShiftSaleDedupe,
75
78
  schema: () => buildShiftSaleDedupeSchema({ autoIndex }),
76
79
  existing
80
+ },
81
+ {
82
+ name: POS_MODEL_NAMES.TillGrant,
83
+ collection: prefix + DEFAULT_COLLECTIONS.TillGrant,
84
+ schema: () => buildTillGrantSchema({
85
+ tenant,
86
+ autoIndex
87
+ }),
88
+ existing
77
89
  }
78
90
  ],
79
91
  assemble: (models) => Object.freeze({
80
92
  Shift: models.get("Shift"),
81
93
  Register: models.get("Register"),
82
- ShiftSaleDedupe: models.get("ShiftSaleDedupe")
94
+ ShiftSaleDedupe: models.get("ShiftSaleDedupe"),
95
+ TillGrant: models.get("TillGrant")
83
96
  })
84
97
  });
85
98
  }
@@ -1,7 +1,9 @@
1
1
  import "./inject-tenant.mjs";
2
- import { HydratedDocument, Model, Schema } from "mongoose";
2
+ import { HydratedDocument, Model, Schema, Types } from "mongoose";
3
3
  //#region src/models/register.model.d.ts
4
- interface IRegister {
4
+ export interface IRegister {
5
+ /** The document id — every stored register has one, so a create or read returns it. */
6
+ _id: Types.ObjectId;
5
7
  /** Tenant scope (organizationId / branchId). Type set by tenant config. */
6
8
  organizationId: unknown;
7
9
  /**
@@ -31,7 +33,6 @@ interface IRegister {
31
33
  createdAt?: Date;
32
34
  updatedAt?: Date;
33
35
  }
34
- type RegisterDocument = HydratedDocument<IRegister>;
35
- type RegisterModel = Model<IRegister>;
36
- //#endregion
37
- export { IRegister, RegisterDocument, RegisterModel };
36
+ export type RegisterDocument = HydratedDocument<IRegister>;
37
+ export type RegisterModel = Model<IRegister>;
38
+ //#endregion
@@ -1,6 +1,6 @@
1
1
  import { HydratedDocument, Model, Schema } from "mongoose";
2
2
  //#region src/models/shift-sale-dedupe.model.d.ts
3
- interface IShiftSaleDedupe {
3
+ export interface IShiftSaleDedupe {
4
4
  /** Target shift `_id` (stringified) — one claim namespace per shift. */
5
5
  shiftId: string;
6
6
  /**
@@ -10,7 +10,6 @@ interface IShiftSaleDedupe {
10
10
  orderRef: string;
11
11
  createdAt: Date;
12
12
  }
13
- type ShiftSaleDedupeDocument = HydratedDocument<IShiftSaleDedupe>;
14
- type ShiftSaleDedupeModel = Model<IShiftSaleDedupe>;
15
- //#endregion
16
- export { IShiftSaleDedupe, ShiftSaleDedupeDocument, ShiftSaleDedupeModel };
13
+ export type ShiftSaleDedupeDocument = HydratedDocument<IShiftSaleDedupe>;
14
+ export type ShiftSaleDedupeModel = Model<IShiftSaleDedupe>;
15
+ //#endregion