@managesome/eposmatic-toolkit 0.4.53 → 0.4.55

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 (82) hide show
  1. package/esm/helpers/materialized-reports/index.js +1 -0
  2. package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +18 -0
  3. package/esm/helpers/materialized-reports/report-platform/definition.js +508 -0
  4. package/esm/helpers/materialized-reports/report-platform/index.js +4 -0
  5. package/esm/helpers/materialized-reports/report-platform/lifecycle/budget.js +27 -0
  6. package/esm/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +12 -0
  7. package/esm/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +121 -0
  8. package/esm/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +14 -0
  9. package/esm/helpers/materialized-reports/report-platform/lifecycle/index.js +8 -0
  10. package/esm/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +10 -0
  11. package/esm/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +42 -0
  12. package/esm/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +28 -0
  13. package/esm/helpers/materialized-reports/report-platform/lifecycle/top-n.js +24 -0
  14. package/esm/helpers/materialized-reports/report-platform/registry.js +23 -0
  15. package/esm/helpers/materialized-reports/report-platform/validate-report-registry.js +214 -0
  16. package/esm/schemas/models/index.js +1 -0
  17. package/esm/schemas/models/tenant_dialer_events.js +133 -0
  18. package/esm/schemas/types/index.js +1 -0
  19. package/esm/schemas/types/tenant_dialer_events.js +1 -0
  20. package/lib/helpers/materialized-reports/index.d.ts +1 -0
  21. package/lib/helpers/materialized-reports/index.js +1 -0
  22. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +1 -0
  23. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +19 -0
  24. package/lib/helpers/materialized-reports/report-platform/definition.d.ts +133 -0
  25. package/lib/helpers/materialized-reports/report-platform/definition.js +511 -0
  26. package/lib/helpers/materialized-reports/report-platform/index.d.ts +4 -0
  27. package/lib/helpers/materialized-reports/report-platform/index.js +20 -0
  28. package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.d.ts +8 -0
  29. package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.js +31 -0
  30. package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.d.ts +8 -0
  31. package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +16 -0
  32. package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.d.ts +40 -0
  33. package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +130 -0
  34. package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.d.ts +22 -0
  35. package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +17 -0
  36. package/lib/helpers/materialized-reports/report-platform/lifecycle/index.d.ts +8 -0
  37. package/lib/helpers/materialized-reports/report-platform/lifecycle/index.js +24 -0
  38. package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.d.ts +13 -0
  39. package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +13 -0
  40. package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.d.ts +20 -0
  41. package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +47 -0
  42. package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.d.ts +13 -0
  43. package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +31 -0
  44. package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.d.ts +16 -0
  45. package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.js +29 -0
  46. package/lib/helpers/materialized-reports/report-platform/registry.d.ts +13 -0
  47. package/lib/helpers/materialized-reports/report-platform/registry.js +31 -0
  48. package/lib/helpers/materialized-reports/report-platform/validate-report-registry.d.ts +20 -0
  49. package/lib/helpers/materialized-reports/report-platform/validate-report-registry.js +218 -0
  50. package/lib/schemas/models/index.d.ts +1 -0
  51. package/lib/schemas/models/index.js +1 -0
  52. package/lib/schemas/models/tenant-activity-logs.d.ts +3 -3
  53. package/lib/schemas/models/tenant_dialer_events.d.ts +130 -0
  54. package/lib/schemas/models/tenant_dialer_events.js +136 -0
  55. package/lib/schemas/models/warehouse-activity-logs.d.ts +3 -3
  56. package/lib/schemas/types/index.d.ts +1 -0
  57. package/lib/schemas/types/index.js +1 -0
  58. package/lib/schemas/types/tenant_dialer_events.d.ts +35 -0
  59. package/lib/schemas/types/tenant_dialer_events.js +2 -0
  60. package/lib/tests/materialized-reports/characterization/delivery.characterization.test.d.ts +1 -0
  61. package/lib/tests/materialized-reports/characterization/delivery.characterization.test.js +229 -0
  62. package/lib/tests/materialized-reports/characterization/discount.characterization.test.d.ts +1 -0
  63. package/lib/tests/materialized-reports/characterization/discount.characterization.test.js +99 -0
  64. package/lib/tests/materialized-reports/characterization/fixtures.d.ts +30 -0
  65. package/lib/tests/materialized-reports/characterization/fixtures.js +402 -0
  66. package/lib/tests/materialized-reports/characterization/golden.d.ts +18 -0
  67. package/lib/tests/materialized-reports/characterization/golden.js +127 -0
  68. package/lib/tests/materialized-reports/characterization/overview.characterization.test.d.ts +1 -0
  69. package/lib/tests/materialized-reports/characterization/overview.characterization.test.js +69 -0
  70. package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.d.ts +1 -0
  71. package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.js +102 -0
  72. package/lib/tests/materialized-reports/materialized-wipe-tooling.test.d.ts +1 -0
  73. package/lib/tests/materialized-reports/materialized-wipe-tooling.test.js +37 -0
  74. package/lib/tests/materialized-reports/report-platform/lifecycle-primitives.test.d.ts +1 -0
  75. package/lib/tests/materialized-reports/report-platform/lifecycle-primitives.test.js +177 -0
  76. package/lib/tests/materialized-reports/report-platform/registry-conformance.test.d.ts +1 -0
  77. package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +214 -0
  78. package/lib/tests/materialized-reports/report-platform/registry-validation.test.d.ts +1 -0
  79. package/lib/tests/materialized-reports/report-platform/registry-validation.test.js +103 -0
  80. package/lib/tests/tenant-dialer-events-schema.test.d.ts +1 -0
  81. package/lib/tests/tenant-dialer-events-schema.test.js +191 -0
  82. package/package.json +4 -2
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const mongoose_1 = __importDefault(require("mongoose"));
7
+ const constants_1 = require("../constants");
8
+ const tenant_dialer_events_1 = require("../schemas/models/tenant_dialer_events");
9
+ const Model = mongoose_1.default.models[tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_NAME] ??
10
+ mongoose_1.default.model(tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_NAME, tenant_dialer_events_1.TenantDialerEventSchema, tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_NAME);
11
+ const LOCAL_TIME_FIELDS = [
12
+ 'day_index',
13
+ 'localSecond',
14
+ 'localMinute',
15
+ 'localHour',
16
+ 'localDay',
17
+ 'localWeek',
18
+ 'localWeekOfYear',
19
+ 'localMonth',
20
+ 'localQuarter',
21
+ 'localSemester',
22
+ 'localYear',
23
+ 'localDate',
24
+ 'localTime',
25
+ 'localDayOfYear',
26
+ ];
27
+ /** Source fields only — a valid un-attributed event. Proves the `Partial` type. */
28
+ const baseRow = () => ({
29
+ _id: new mongoose_1.default.Types.ObjectId().toString(),
30
+ tenant_id: 'tenant-dialer-events',
31
+ request_id: 'call-123:INCOMING_CALL',
32
+ action: constants_1.DIALER_TYPES_ENUM.INCOMING_CALL,
33
+ phone_number: '+923001234567',
34
+ pos_id: 'pos-1',
35
+ staff_id: null,
36
+ staff_phone: null,
37
+ schema_version: 1,
38
+ createdAt: new Date('2026-03-10T20:30:45.000Z'),
39
+ updatedAt: new Date('2026-03-10T20:30:45.000Z'),
40
+ });
41
+ const localFields = () => ({
42
+ day_index: constants_1.DAY_INDEX_ENUM.TUE,
43
+ localSecond: 45,
44
+ localMinute: 30,
45
+ localHour: 1,
46
+ localDay: 2,
47
+ localWeek: 2,
48
+ localWeekOfYear: 11,
49
+ localMonth: 3,
50
+ localQuarter: 1,
51
+ localSemester: 1,
52
+ localYear: 2026,
53
+ localDate: '2026-03-10',
54
+ localTime: '01:30:45',
55
+ localDayOfYear: 69,
56
+ });
57
+ const attributedRow = () => ({ ...baseRow(), ...localFields() });
58
+ describe('tenant_dialer_events schema', () => {
59
+ it('exposes the agreed collection name', () => {
60
+ expect(tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_NAME).toBe('tenant_dialer_events');
61
+ });
62
+ it('is an un-attributed-valid Partial<ILocalTimeFields> event', () => {
63
+ // `baseRow()` has NO local-time fields and still satisfies the event type.
64
+ const unAttributed = baseRow();
65
+ expect(new Model(unAttributed).validateSync()).toBeUndefined();
66
+ for (const field of LOCAL_TIME_FIELDS) {
67
+ const path = tenant_dialer_events_1.TenantDialerEventSchema.path(field);
68
+ expect(path).toBeDefined();
69
+ expect(path.options.required).toBeFalsy();
70
+ expect(unAttributed).not.toHaveProperty(field);
71
+ }
72
+ });
73
+ it('validates a fully attributed source event with every local-time field', () => {
74
+ const doc = new Model(attributedRow());
75
+ expect(doc.validateSync()).toBeUndefined();
76
+ const stored = doc.toObject();
77
+ expect(stored).toMatchObject({
78
+ tenant_id: 'tenant-dialer-events',
79
+ request_id: 'call-123:INCOMING_CALL',
80
+ action: constants_1.DIALER_TYPES_ENUM.INCOMING_CALL,
81
+ phone_number: '+923001234567',
82
+ pos_id: 'pos-1',
83
+ staff_id: null,
84
+ staff_phone: null,
85
+ schema_version: 1,
86
+ localDate: '2026-03-10',
87
+ localTime: '01:30:45',
88
+ day_index: constants_1.DAY_INDEX_ENUM.TUE,
89
+ localSecond: 45,
90
+ localMinute: 30,
91
+ localHour: 1,
92
+ localDay: 2,
93
+ localWeek: 2,
94
+ localWeekOfYear: 11,
95
+ localMonth: 3,
96
+ localQuarter: 1,
97
+ localSemester: 1,
98
+ localYear: 2026,
99
+ localDayOfYear: 69,
100
+ });
101
+ });
102
+ it('has NO received_at and NO running_day_missing', () => {
103
+ expect(tenant_dialer_events_1.TenantDialerEventSchema.path('received_at')).toBeUndefined();
104
+ expect(tenant_dialer_events_1.TenantDialerEventSchema.path('running_day_missing')).toBeUndefined();
105
+ expect(attributedRow()).not.toHaveProperty('received_at');
106
+ expect(attributedRow()).not.toHaveProperty('running_day_missing');
107
+ });
108
+ it('keeps createdAt as the canonical receipt time (required, immutable)', () => {
109
+ const path = tenant_dialer_events_1.TenantDialerEventSchema.path('createdAt');
110
+ expect(path).toBeDefined();
111
+ expect(path.options.required).toBeTruthy();
112
+ expect(path.options.immutable).toBe(true);
113
+ const row = { ...baseRow() };
114
+ delete row.createdAt;
115
+ // Defaults fill the canonical time when omitted on a direct create.
116
+ expect(new Model(row).createdAt).toBeInstanceOf(Date);
117
+ });
118
+ it('accepts every DIALER_TYPES_ENUM action', () => {
119
+ for (const action of constants_1.ALL_DIALER_TYPE_EVENTS) {
120
+ const doc = new Model({ ...baseRow(), action });
121
+ expect(doc.validateSync()).toBeUndefined();
122
+ }
123
+ });
124
+ it('rejects an unknown action', () => {
125
+ const error = new Model({ ...baseRow(), action: 'NOT_A_DIALER_ACTION' }).validateSync();
126
+ expect(error?.errors).toHaveProperty('action');
127
+ });
128
+ it('rejects invalid local-time values but allows the fields to be absent', () => {
129
+ const badHour = new Model({ ...attributedRow(), localHour: 25 }).validateSync();
130
+ expect(badHour?.errors).toHaveProperty('localHour');
131
+ const badDate = new Model({ ...attributedRow(), localDate: undefined }).validateSync();
132
+ expect(badDate).toBeUndefined();
133
+ });
134
+ it('does not weaken the required source fields', () => {
135
+ for (const field of ['tenant_id', 'request_id', 'action', 'phone_number', 'pos_id']) {
136
+ const row = { ...baseRow() };
137
+ delete row[field];
138
+ expect(new Model(row).validateSync()?.errors).toHaveProperty(field);
139
+ }
140
+ for (const field of [
141
+ 'tenant_id',
142
+ 'request_id',
143
+ 'action',
144
+ 'phone_number',
145
+ 'pos_id',
146
+ 'schema_version',
147
+ 'createdAt',
148
+ 'updatedAt',
149
+ ]) {
150
+ const path = tenant_dialer_events_1.TenantDialerEventSchema.path(field);
151
+ expect(path).toBeDefined();
152
+ expect(path.options.required).toBeTruthy();
153
+ }
154
+ });
155
+ it('keeps staff fields nullable', () => {
156
+ expect(new Model(baseRow()).get('staff_id')).toBeNull();
157
+ expect(new Model(baseRow()).get('staff_phone')).toBeNull();
158
+ expect(new Model({ ...baseRow(), staff_id: 'staff-1', staff_phone: '+923007654321' }).validateSync()).toBeUndefined();
159
+ });
160
+ it('enforces schema_version = 1', () => {
161
+ expect(tenant_dialer_events_1.TENANT_DIALER_EVENTS_SCHEMA_VERSION).toBe(1);
162
+ expect(new Model({ ...baseRow(), schema_version: 2 }).validateSync()?.errors).toHaveProperty('schema_version');
163
+ });
164
+ it('does NOT declare duration_seconds (derived later, never stored)', () => {
165
+ expect(tenant_dialer_events_1.TenantDialerEventSchema.path('duration_seconds')).toBeUndefined();
166
+ expect(attributedRow()).not.toHaveProperty('duration_seconds');
167
+ });
168
+ it('declares the unique ingestion index plus the two source-read indexes', () => {
169
+ expect(tenant_dialer_events_1.TENANT_DIALER_EVENTS_COLLECTION_INDEXES).toEqual({
170
+ _id: { _id: 1 },
171
+ tenant_id__request_id: { tenant_id: 1, request_id: 1 },
172
+ tenant_id__localDate__action: { tenant_id: 1, localDate: 1, action: 1 },
173
+ tenant_id__phone_number__createdAt: { tenant_id: 1, phone_number: 1, createdAt: 1 },
174
+ });
175
+ expect(tenant_dialer_events_1.TENANT_DIALER_EVENTS_INDEX_OPTIONS).toEqual([
176
+ {
177
+ key: { tenant_id: 1, request_id: 1 },
178
+ name: 'tenant_id__request_id',
179
+ unique: true,
180
+ },
181
+ {
182
+ key: { tenant_id: 1, localDate: 1, action: 1 },
183
+ name: 'tenant_id__localDate__action',
184
+ },
185
+ {
186
+ key: { tenant_id: 1, phone_number: 1, createdAt: 1 },
187
+ name: 'tenant_id__phone_number__createdAt',
188
+ },
189
+ ]);
190
+ });
191
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.53",
3
+ "version": "0.4.55",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -27,7 +27,9 @@
27
27
  "fixtures:prep-time-parity": "tsx scripts/analyze-prep-time-parity.ts",
28
28
  "fixtures:delivery": "tsx scripts/analyze-delivery.ts",
29
29
  "sim:close-day": "tsx simulations/simulate-day-close.ts",
30
- "wipe:delivery": "tsx scripts/wipe-delivery-materialization.ts"
30
+ "wipe:delivery": "tsx scripts/wipe-delivery-materialization.ts",
31
+ "measure:report-scale": "npx tsx scripts/measure-report-practical-scale.ts",
32
+ "test:characterization": "jest --config jestconfig.json src/tests/materialized-reports/characterization --runInBand"
31
33
  },
32
34
  "dependencies": {
33
35
  "bson-objectid": "^2.0.4",