@classytic/pos 0.6.0 → 0.8.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 (75) hide show
  1. package/CHANGELOG.md +10 -350
  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 +230 -0
  5. package/dist/commands/pos-commands.mjs +357 -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/payment-method.enum.mjs +2 -2
  10. package/dist/domain/enums/shift-state.enum.d.mts +7 -8
  11. package/dist/domain/errors/pos.errors.d.mts +82 -34
  12. package/dist/domain/errors/pos.errors.mjs +108 -23
  13. package/dist/domain/index.d.mts +11 -3
  14. package/dist/domain/index.mjs +10 -3
  15. package/dist/domain/ports/common.d.mts +2 -3
  16. package/dist/domain/ports/ledger.bridge.d.mts +6 -7
  17. package/dist/domain/ports/notification.bridge.d.mts +5 -6
  18. package/dist/domain/ports/policy.bridge.d.mts +2 -3
  19. package/dist/domain/sale/discount.d.mts +62 -0
  20. package/dist/domain/sale/discount.mjs +58 -0
  21. package/dist/domain/sale/price-override.d.mts +51 -0
  22. package/dist/domain/sale/price-override.mjs +51 -0
  23. package/dist/domain/sale/quick-cash.d.mts +10 -0
  24. package/dist/domain/sale/quick-cash.mjs +27 -0
  25. package/dist/domain/sale/service-line.d.mts +7 -0
  26. package/dist/domain/sale/service-line.mjs +10 -0
  27. package/dist/domain/sale/tender.d.mts +256 -0
  28. package/dist/domain/sale/tender.mjs +242 -0
  29. package/dist/domain/shift/shift-decisions.d.mts +51 -0
  30. package/dist/domain/shift/shift-decisions.mjs +93 -0
  31. package/dist/domain/shift/shift-report.d.mts +127 -0
  32. package/dist/domain/shift/shift-report.mjs +95 -0
  33. package/dist/domain/shift/shift.types.d.mts +107 -0
  34. package/dist/domain/state-machines/shift.fsm.d.mts +6 -7
  35. package/dist/domain/value-objects/cash-movement.vo.d.mts +7 -3
  36. package/dist/domain/value-objects/payment-breakdown.vo.d.mts +4 -5
  37. package/dist/domain/value-objects/shift-policy.vo.d.mts +12 -13
  38. package/dist/domain/value-objects/shift-policy.vo.mjs +13 -7
  39. package/dist/engine/capability.errors.d.mts +23 -0
  40. package/dist/engine/capability.errors.mjs +28 -0
  41. package/dist/engine/define-pos.d.mts +2 -3
  42. package/dist/engine/define-pos.mjs +14 -3
  43. package/dist/engine/engine-types.d.mts +24 -9
  44. package/dist/engine/index.d.mts +2 -1
  45. package/dist/engine/index.mjs +2 -1
  46. package/dist/events/event-catalog.d.mts +18 -14
  47. package/dist/events/event-catalog.mjs +10 -4
  48. package/dist/events/event-constants.d.mts +3 -4
  49. package/dist/events/event-payloads.d.mts +9 -10
  50. package/dist/events/helpers.d.mts +6 -3
  51. package/dist/events/helpers.mjs +12 -2
  52. package/dist/events/in-process-bus.d.mts +3 -4
  53. package/dist/events/index.mjs +1 -1
  54. package/dist/grant/till-grant.d.mts +50 -0
  55. package/dist/grant/till-grant.mjs +47 -0
  56. package/dist/index.d.mts +15 -4
  57. package/dist/index.mjs +13 -4
  58. package/dist/models/create-models.d.mts +10 -6
  59. package/dist/models/create-models.mjs +16 -3
  60. package/dist/models/register.model.d.mts +7 -6
  61. package/dist/models/shift-sale-dedupe.model.d.mts +4 -5
  62. package/dist/models/shift.model.d.mts +4 -111
  63. package/dist/models/shift.model.mjs +27 -3
  64. package/dist/models/till-grant.model.d.mts +19 -0
  65. package/dist/models/till-grant.model.mjs +52 -0
  66. package/dist/repositories/register.repository.d.mts +3 -4
  67. package/dist/repositories/shift.repository.d.mts +90 -60
  68. package/dist/repositories/shift.repository.mjs +323 -150
  69. package/dist/repositories/till-grant.repository.d.mts +22 -0
  70. package/dist/repositories/till-grant.repository.mjs +41 -0
  71. package/dist/schemas/index.mjs +1 -2
  72. package/dist/schemas/shift.d.mts +9 -10
  73. package/dist/testing/fixtures.d.mts +4 -5
  74. package/dist/testing/index.mjs +1 -2
  75. package/package.json +50 -19
@@ -5,12 +5,13 @@ import { NotificationBridge } from "../domain/ports/notification.bridge.mjs";
5
5
  import { PosModels } from "../models/create-models.mjs";
6
6
  import { RegisterRepository } from "../repositories/register.repository.mjs";
7
7
  import { ShiftRepository } from "../repositories/shift.repository.mjs";
8
+ import { TillGrantRepository } from "../repositories/till-grant.repository.mjs";
8
9
  import { TenantConfig } from "@classytic/repo-core/tenant";
9
10
  import { Connection } from "mongoose";
10
11
  import { EventTransport } from "@classytic/primitives/events";
11
12
  import { OutboxStore } from "@classytic/primitives/outbox";
12
13
  //#region src/engine/engine-types.d.ts
13
- interface PosBridges {
14
+ export interface PosBridges {
14
15
  /**
15
16
  * Ledger bridge — host implements `onShiftClosed(shift, ctx)` to emit a
16
17
  * JournalEntry and return the resulting `journalEntryId`. Without this
@@ -23,7 +24,7 @@ interface PosBridges {
23
24
  /** Variance + orphan-close notifications. Best-effort; failures don't block state. */
24
25
  notification?: NotificationBridge;
25
26
  }
26
- interface PosLogger {
27
+ export interface PosLogger {
27
28
  error(message: string, ...args: unknown[]): void;
28
29
  }
29
30
  /**
@@ -31,7 +32,7 @@ interface PosLogger {
31
32
  * no connection or I/O to inspect. Nothing here opens a socket or reads a
32
33
  * secret — safe to call at import / module-composition time.
33
34
  */
34
- interface PosShape {
35
+ export interface PosShape {
35
36
  /** Default shift policy when neither `bridges.policy` nor a per-call override is supplied. */
36
37
  defaultPolicy: ShiftPolicy;
37
38
  /** Canonical persistence tenancy. Default `true`. */
@@ -58,7 +59,7 @@ interface PosShape {
58
59
  * outbox, logger or host bridge belongs here, not in the shape — each is a
59
60
  * runtime collaborator (may perform I/O, may be shared infrastructure).
60
61
  */
61
- interface PosRuntime {
62
+ export interface PosRuntime {
62
63
  /** Bridges — every method is opt-in; the package degrades gracefully without them. */
63
64
  bridges?: PosBridges | undefined;
64
65
  /** Inject your own event bus; otherwise an in-process bus is created (and owned). */
@@ -83,6 +84,17 @@ interface PosRuntime {
83
84
  * standalone-Mongo local dev where transactions are absent.
84
85
  */
85
86
  allowNonTransactional?: boolean | undefined;
87
+ /**
88
+ * Where a close's journal entry posts.
89
+ *
90
+ * - `'inline'` (default): the ledger bridge runs inside `close` / `forceClose`; a bridge failure rolls the close
91
+ * back (`close`) or keeps the marker (`forceClose`).
92
+ * - `'deferred'`: the close commits the shift, its `pendingLedgerPost` marker and a DURABLE `pos:shift.closed` /
93
+ * `pos:shift.force_closed` row (fixed id per shift) in ONE unit of work and answers; the host's subscriber to
94
+ * that event calls `shift.postPendingLedger(shiftId)`, which posts under the same idempotency key. A failed post
95
+ * is the subscriber's failure (the outbox failure policy), never a rolled-back close. Requires `outbox`.
96
+ */
97
+ ledgerPost?: 'inline' | 'deferred' | undefined;
86
98
  /** Custom logger; defaults to `console`. */
87
99
  logger?: PosLogger | undefined;
88
100
  }
@@ -90,7 +102,7 @@ interface PosRuntime {
90
102
  * The immutable, resolved describe+bind configuration surfaced on the engine
91
103
  * (`engine.config`). Excludes the live connection and secrets.
92
104
  */
93
- interface ResolvedPosConfig {
105
+ export interface ResolvedPosConfig {
94
106
  readonly defaultPolicy: ShiftPolicy;
95
107
  readonly tenant: import('@classytic/repo-core/tenant').ResolvedTenantConfig;
96
108
  readonly softDelete: false | {
@@ -100,12 +112,15 @@ interface ResolvedPosConfig {
100
112
  readonly autoIndex: boolean | undefined;
101
113
  readonly forceRecreate: boolean;
102
114
  readonly allowNonTransactional: boolean;
115
+ readonly ledgerPost: 'inline' | 'deferred';
103
116
  }
104
- interface PosRepositories {
117
+ export interface PosRepositories {
105
118
  shift: ShiftRepository;
106
119
  register: RegisterRepository;
120
+ /** Grants issued to paired tills. */
121
+ tillGrant: TillGrantRepository;
107
122
  }
108
- interface PosEngine {
123
+ export interface PosEngine {
109
124
  readonly config: ResolvedPosConfig;
110
125
  readonly bridges: Readonly<PosBridges>;
111
126
  readonly events: EventTransport;
@@ -125,7 +140,7 @@ interface PosEngine {
125
140
  */
126
141
  close(): Promise<void>;
127
142
  }
128
- interface PosBlueprint {
143
+ export interface PosBlueprint {
129
144
  readonly id: 'pos';
130
145
  /** The model names this blueprint registers — known without a connection. */
131
146
  readonly modelNames: readonly string[];
@@ -137,4 +152,4 @@ interface PosBlueprint {
137
152
  bind(connection: Connection, runtime?: PosRuntime): PosEngine;
138
153
  }
139
154
  //#endregion
140
- export { PosBlueprint, PosBridges, PosEngine, PosLogger, type PosModels, PosRepositories, PosRuntime, PosShape, ResolvedPosConfig };
155
+ export type { PosModels };
@@ -1,4 +1,5 @@
1
1
  import { PosModels } from "../models/create-models.mjs";
2
2
  import { PosBlueprint, PosBridges, PosEngine, PosLogger, PosRepositories, PosRuntime, PosShape, ResolvedPosConfig } from "./engine-types.mjs";
3
3
  import { definePos } from "./define-pos.mjs";
4
- export { type PosBlueprint, type PosBridges, type PosEngine, type PosLogger, type PosModels, type PosRepositories, type PosRuntime, type PosShape, type ResolvedPosConfig, definePos };
4
+ import { PosCapabilityError } from "./capability.errors.mjs";
5
+ export { type PosBlueprint, type PosBridges, PosCapabilityError, type PosEngine, type PosLogger, type PosModels, type PosRepositories, type PosRuntime, type PosShape, type ResolvedPosConfig, definePos };
@@ -1,2 +1,3 @@
1
+ import { PosCapabilityError } from "./capability.errors.mjs";
1
2
  import { definePos } from "./define-pos.mjs";
2
- export { definePos };
3
+ export { PosCapabilityError, definePos };
@@ -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,26 +5,37 @@ 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, 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";
34
+ import { PosCapabilityError } from "./engine/capability.errors.mjs";
24
35
  import { POS_EVENTS, PosEventName } from "./events/event-constants.mjs";
25
36
  import { CashMovementRecordedPayload, PosEventPayloads, ShiftBlindClosedPayload, ShiftClosedPayload, ShiftForceClosedPayload, ShiftOpenedPayload, ShiftStateChangedPayload, VarianceDetectedPayload } from "./events/event-payloads.mjs";
26
37
  import { createPosEvent } from "./events/helpers.mjs";
27
38
  import { InProcessPosBus } from "./events/in-process-bus.mjs";
28
39
  import { PosEventDefinition, PosEventPayloadOf, cashMovementRecordedEvent, posEventDefinitions, shiftBlindClosedEvent, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent } from "./events/event-catalog.mjs";
29
40
  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 };
41
+ 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 { PosCapabilityError } from "./engine/capability.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";
@@ -6,14 +6,23 @@ import { DEFAULT_METHOD_KINDS, PAYMENT_METHOD_KIND_VALUES, SHIFT_PAYMENT_METHODS
6
6
  import { ACTIVE_SHIFT_STATES, FINAL_SHIFT_STATES, SHIFT_STATES, isActiveShiftState, isFinalShiftState } from "./domain/enums/shift-state.enum.mjs";
7
7
  import { DEFAULT_COLLECTIONS, POS_MODEL_NAMES } from "./models/create-models.mjs";
8
8
  import { RegisterRepository } from "./repositories/register.repository.mjs";
9
+ import { ActiveShiftAlreadyOpenError, CashMovementInvalidError, CashMovementKeyReusedError, CashOutExceedsDrawerError, IllegalShiftTransitionError, OrderDiscountRefusedError, PosError, PriceOverrideRefusedError, ReasonCodePolicyInvalidError, RegisterRequiredError, ShiftCountsRequiredError, ShiftFinalizedError, ShiftNotFoundError, ShiftPausedError, TenderMethodRefusedError, TenderMismatchError, UnmanagedSessionError, VarianceExceededError } from "./domain/errors/pos.errors.mjs";
9
10
  import { shiftCloseIdempotencyKey } from "./domain/ports/ledger.bridge.mjs";
10
11
  import { SHIFT_VERBS, allowedVerbs, canTransition, nextState } from "./domain/state-machines/shift.fsm.mjs";
11
12
  import { computeDifference, computeExpected } from "./domain/value-objects/payment-breakdown.vo.mjs";
12
- import { defaultShiftPolicy, isWithinVarianceThreshold } from "./domain/value-objects/shift-policy.vo.mjs";
13
+ import { defaultShiftPolicy, isReasonCodeAllowed, isWithinVarianceThreshold } from "./domain/value-objects/shift-policy.vo.mjs";
14
+ import { applyCounts, decideBlindClose, decideShiftClose, isCashRow, seedBreakdown } from "./domain/shift/shift-decisions.mjs";
13
15
  import { POS_EVENTS } from "./events/event-constants.mjs";
16
+ import { cashMovementRecordedEvent, posEventDefinitions, shiftBlindClosedEvent, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent } from "./events/event-catalog.mjs";
14
17
  import { createPosEvent } from "./events/helpers.mjs";
15
18
  import { ShiftRepository } from "./repositories/shift.repository.mjs";
19
+ import { TillGrantRepository } from "./repositories/till-grant.repository.mjs";
16
20
  import { definePos } from "./engine/define-pos.mjs";
17
- import { cashMovementRecordedEvent, posEventDefinitions, shiftBlindClosedEvent, shiftClosedEvent, shiftForceClosedEvent, shiftOpenedEvent, shiftPausedEvent, shiftResumedEvent, varianceDetectedEvent } from "./events/event-catalog.mjs";
21
+ import { DEFAULT_TENDER_METHOD_RESOLVER, allocateTender, assertTenderSettles, createTenderMethodResolver, tenderSummary, tillTenderMethods, validateTenderLegs } from "./domain/sale/tender.mjs";
22
+ import { decideOrderDiscount, discountCeilingMinor } from "./domain/sale/discount.mjs";
23
+ import { PRICE_OVERRIDE_NOTE_MAX, PRICE_OVERRIDE_REASONS, PRICE_OVERRIDE_REASONS_NEEDING_NOTE, decideLinePrice, isPriceOverrideReason } from "./domain/sale/price-override.mjs";
24
+ import { serviceSku, serviceSlug } from "./domain/sale/service-line.mjs";
25
+ import { quickCashAmounts } from "./domain/sale/quick-cash.mjs";
26
+ import { buildShiftReport } from "./domain/shift/shift-report.mjs";
18
27
  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 };
28
+ 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