@managesome/eposmatic-toolkit 0.4.55 → 0.4.57

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 (78) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +91 -0
  2. package/esm/helpers/materialized-reports/index.js +7 -0
  3. package/esm/helpers/materialized-reports/materialized-dialer-accumulator-helpers.js +100 -0
  4. package/esm/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +328 -0
  5. package/esm/helpers/materialized-reports/materialized-dialer-compile-helpers.js +180 -0
  6. package/esm/helpers/materialized-reports/materialized-dialer-entry-pages.js +222 -0
  7. package/esm/helpers/materialized-reports/materialized-dialer-key-helpers.js +82 -0
  8. package/esm/helpers/materialized-reports/materialized-dialer-masking.js +54 -0
  9. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
  10. package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +13 -1
  11. package/esm/helpers/materialized-reports/report-platform/definition.js +87 -3
  12. package/esm/helpers/materialized-reports/tenant-dialer-formatter.js +95 -0
  13. package/esm/helpers/reporting-contract/report-contract.js +3 -0
  14. package/esm/schemas/models/index.js +2 -0
  15. package/esm/schemas/models/materialized_report_drilldown_rows.js +1 -0
  16. package/esm/schemas/models/materialized_tenant_delivery_entries.js +5 -5
  17. package/esm/schemas/models/materialized_tenant_delivery_reports.js +7 -7
  18. package/esm/schemas/models/materialized_tenant_dialer_entries.js +65 -0
  19. package/esm/schemas/models/materialized_tenant_dialer_reports.js +66 -0
  20. package/esm/schemas/types/index.js +2 -0
  21. package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
  22. package/esm/schemas/types/materialized_tenant_dialer_entries.js +1 -0
  23. package/esm/schemas/types/materialized_tenant_dialer_reports.js +7 -0
  24. package/lib/constants/MATERIALIZED_REPORTS.d.ts +72 -2
  25. package/lib/constants/MATERIALIZED_REPORTS.js +93 -1
  26. package/lib/helpers/materialized-reports/index.d.ts +7 -0
  27. package/lib/helpers/materialized-reports/index.js +7 -0
  28. package/lib/helpers/materialized-reports/materialized-dialer-accumulator-helpers.d.ts +39 -0
  29. package/lib/helpers/materialized-reports/materialized-dialer-accumulator-helpers.js +110 -0
  30. package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.d.ts +90 -0
  31. package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +340 -0
  32. package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.d.ts +67 -0
  33. package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.js +183 -0
  34. package/lib/helpers/materialized-reports/materialized-dialer-entry-pages.d.ts +97 -0
  35. package/lib/helpers/materialized-reports/materialized-dialer-entry-pages.js +235 -0
  36. package/lib/helpers/materialized-reports/materialized-dialer-key-helpers.d.ts +51 -0
  37. package/lib/helpers/materialized-reports/materialized-dialer-key-helpers.js +90 -0
  38. package/lib/helpers/materialized-reports/materialized-dialer-masking.d.ts +35 -0
  39. package/lib/helpers/materialized-reports/materialized-dialer-masking.js +57 -0
  40. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
  41. package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +13 -1
  42. package/lib/helpers/materialized-reports/report-platform/definition.js +86 -2
  43. package/lib/helpers/materialized-reports/tenant-dialer-formatter.d.ts +91 -0
  44. package/lib/helpers/materialized-reports/tenant-dialer-formatter.js +98 -0
  45. package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
  46. package/lib/helpers/reporting-contract/report-contract.js +3 -0
  47. package/lib/schemas/models/index.d.ts +2 -0
  48. package/lib/schemas/models/index.js +2 -0
  49. package/lib/schemas/models/materialized_report_drilldown_rows.js +1 -0
  50. package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +5 -5
  51. package/lib/schemas/models/materialized_tenant_delivery_entries.js +5 -5
  52. package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +7 -7
  53. package/lib/schemas/models/materialized_tenant_delivery_reports.js +7 -7
  54. package/lib/schemas/models/materialized_tenant_dialer_entries.d.ts +107 -0
  55. package/lib/schemas/models/materialized_tenant_dialer_entries.js +68 -0
  56. package/lib/schemas/models/materialized_tenant_dialer_reports.d.ts +100 -0
  57. package/lib/schemas/models/materialized_tenant_dialer_reports.js +69 -0
  58. package/lib/schemas/models/tenant_dialer_events.d.ts +3 -3
  59. package/lib/schemas/types/index.d.ts +2 -0
  60. package/lib/schemas/types/index.js +2 -0
  61. package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
  62. package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
  63. package/lib/schemas/types/materialized_tenant_dialer_entries.d.ts +83 -0
  64. package/lib/schemas/types/materialized_tenant_dialer_entries.js +2 -0
  65. package/lib/schemas/types/materialized_tenant_dialer_reports.d.ts +77 -0
  66. package/lib/schemas/types/materialized_tenant_dialer_reports.js +10 -0
  67. package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +1 -1
  68. package/lib/tests/materialized-reports/materialized-delivery-practical.test.js +1 -1
  69. package/lib/tests/materialized-reports/materialized-dialer-compile.test.d.ts +1 -0
  70. package/lib/tests/materialized-reports/materialized-dialer-compile.test.js +213 -0
  71. package/lib/tests/materialized-reports/materialized-dialer-formatter.test.d.ts +1 -0
  72. package/lib/tests/materialized-reports/materialized-dialer-formatter.test.js +159 -0
  73. package/lib/tests/materialized-reports/materialized-dialer-plan.test.d.ts +1 -0
  74. package/lib/tests/materialized-reports/materialized-dialer-plan.test.js +223 -0
  75. package/lib/tests/materialized-reports/materialized-tenant-dialer-schema.test.d.ts +1 -0
  76. package/lib/tests/materialized-reports/materialized-tenant-dialer-schema.test.js +183 -0
  77. package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +16 -3
  78. package/package.json +1 -1
@@ -324,7 +324,7 @@ const DELIVERY_DEFINITION = {
324
324
  status: REPORT_DEFINITION_STATUS.PRODUCTION,
325
325
  report: {
326
326
  name: 'materialized_tenant_delivery_reports',
327
- schemaVersion: 2,
327
+ schemaVersion: 1,
328
328
  budgetBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES,
329
329
  enforced: true,
330
330
  validatorFile: 'materialized_tenant_delivery_reports.bson',
@@ -333,7 +333,7 @@ const DELIVERY_DEFINITION = {
333
333
  },
334
334
  entries: {
335
335
  name: 'materialized_tenant_delivery_entries',
336
- schemaVersion: 3,
336
+ schemaVersion: 1,
337
337
  budgetBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES,
338
338
  enforced: true,
339
339
  validatorFile: 'materialized_tenant_delivery_entries.bson',
@@ -430,17 +430,101 @@ const DELIVERY_DEFINITION = {
430
430
  'Historical totals do not pin schema_version today (baseline debt).',
431
431
  ],
432
432
  };
433
+ const DIALER_DEFINITION = {
434
+ key: report_contract_1.REPORT_KEY_ENUM.DIALER,
435
+ segment: 'dialer',
436
+ reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DIALER_REPORTS,
437
+ capabilities: { live: true, historical: true, details: true },
438
+ status: REPORT_DEFINITION_STATUS.PRODUCTION,
439
+ report: {
440
+ name: 'materialized_tenant_dialer_reports',
441
+ schemaVersion: 1,
442
+ budgetBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_REPORT_MAX_BSON_BYTES,
443
+ enforced: true,
444
+ validatorFile: null,
445
+ validatorDebt: 'No schema validator exists for the dialer report collection yet.',
446
+ indexOwner: 'toolkit:MATERIALIZED_TENANT_DIALER_REPORTS_INDEX_OPTIONS',
447
+ migrationId: null,
448
+ },
449
+ entries: {
450
+ name: 'materialized_tenant_dialer_entries',
451
+ schemaVersion: 1,
452
+ budgetBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_ENTRY_MAX_BSON_BYTES,
453
+ enforced: true,
454
+ validatorFile: null,
455
+ validatorDebt: 'No schema validator exists for the dialer entry collection yet.',
456
+ indexOwner: 'toolkit:MATERIALIZED_TENANT_DIALER_ENTRIES_INDEX_OPTIONS',
457
+ migrationId: null,
458
+ },
459
+ sideCollections: [FLAT_ROWS, FLAT_SCOPES],
460
+ reportScopes: [...MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_REPORT_SCOPES],
461
+ entryScopes: [...MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_ENTRY_SCOPES],
462
+ entryStorage: REPORT_ENTRY_STORAGE.PAGE_PER_SOURCE_DAY,
463
+ entrySplit: REPORT_ENTRY_SPLIT.DETERMINISTIC_SUBPAGES,
464
+ maxReportScope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR,
465
+ maxEntryScope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
466
+ projections: [REPORT_PROJECTION.FLAT_DRILLDOWN],
467
+ budgets: {
468
+ materialized_tenant_dialer_reports: MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_REPORT_MAX_BSON_BYTES,
469
+ materialized_tenant_dialer_entries: MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_ENTRY_MAX_BSON_BYTES,
470
+ materialized_report_drilldown_rows: DOCUMENT_BUDGET,
471
+ materialized_report_drilldown_scopes: DOCUMENT_BUDGET,
472
+ },
473
+ retention: [],
474
+ writeGuard: REPORT_WRITE_GUARD.WATERMARK,
475
+ liveSource: REPORT_LIVE_SOURCE.RAW,
476
+ historicalLens: REPORT_HISTORICAL_LENS.DOCUMENT_FOLD,
477
+ completeness: { summary: 'NONE', details: 'FLAT_PROJECTION' },
478
+ filters: [
479
+ {
480
+ id: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ACTION,
481
+ kind: 'KEY_COMPONENT',
482
+ mode: 'SERVER',
483
+ appliesTo: 'BOTH',
484
+ },
485
+ {
486
+ id: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.POS_ID,
487
+ kind: 'KEY_COMPONENT',
488
+ mode: 'SERVER',
489
+ appliesTo: 'BOTH',
490
+ },
491
+ {
492
+ id: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.STAFF_ID,
493
+ kind: 'KEY_COMPONENT',
494
+ mode: 'SERVER',
495
+ appliesTo: 'BOTH',
496
+ },
497
+ { id: 'DETAILS_VIEW', kind: 'REQUEST', mode: 'SERVER', appliesTo: 'DETAILS' },
498
+ ],
499
+ cursor: REPORT_CURSOR_KIND.KEYSET_STRUCTURED,
500
+ adapters: {
501
+ writer: 'materializeDialerReport',
502
+ live: 'getLiveTenantDialerReports',
503
+ historical: 'getMaterializedTenantDialerReports',
504
+ details: 'getMaterializedDialerDetailsPage',
505
+ },
506
+ owner: 'reporting-platform',
507
+ notes: [
508
+ 'Append-only event source: unattributed events (no localDate) are never assigned to a day.',
509
+ 'No duration and no order attribution exist; the page derives every rate.',
510
+ 'Counters are filtered by ACTION / POS_ID / STAFF_ID key components server-side.',
511
+ 'Page entries split deterministically into #N sub-pages when over the 15 MiB budget.',
512
+ 'Late events are not included until the day is re-closed.',
513
+ ],
514
+ };
433
515
  exports.REPORT_DEFINITIONS = {
434
516
  [OVERVIEW_DEFINITION.key]: OVERVIEW_DEFINITION,
435
517
  [DISCOUNTS_DEFINITION.key]: DISCOUNTS_DEFINITION,
436
518
  [PREP_TIME_DEFINITION.key]: PREP_TIME_DEFINITION,
437
519
  [DELIVERY_DEFINITION.key]: DELIVERY_DEFINITION,
520
+ [DIALER_DEFINITION.key]: DIALER_DEFINITION,
438
521
  };
439
522
  exports.PRODUCTION_REPORT_DEFINITIONS = [
440
523
  OVERVIEW_DEFINITION,
441
524
  DISCOUNTS_DEFINITION,
442
525
  PREP_TIME_DEFINITION,
443
526
  DELIVERY_DEFINITION,
527
+ DIALER_DEFINITION,
444
528
  ];
445
529
  exports.REPORT_REGISTRY_EXEMPTIONS = {
446
530
  [report_contract_1.REPORT_KEY_ENUM.CASH_IN_OUT]: {
@@ -0,0 +1,91 @@
1
+ import { IMaterializedTenantDialerReport } from '../../schemas/types/materialized_tenant_dialer_reports';
2
+ import { IDialerKeyFilters } from './materialized-dialer-key-helpers';
3
+ /**
4
+ * Frontend formatter for `materialized_tenant_dialer_reports`.
5
+ *
6
+ * The stored documents are COUNTS ONLY. Everything a page shows on top of the
7
+ * counts is DERIVED here (never stored): the answer rate, the missed rate and
8
+ * the per-action / per-terminal / per-staff groupings. There is no duration and
9
+ * no order attribution, so the formatter exposes none — inventing either would
10
+ * be a report-level lie.
11
+ *
12
+ * ## Approved rate contract
13
+ *
14
+ * `outcome_denominator = answered + missed + declined`, so
15
+ *
16
+ * - `answer_rate = answered / outcome_denominator`
17
+ * - `missed_rate = missed / outcome_denominator`
18
+ *
19
+ * A rate is a PERCENTAGE rounded to 2 decimals and is `null` when the
20
+ * denominator is 0. It is NEVER `answered / events`: `events` includes
21
+ * `INCOMING_CALL`, `OUTGOING_CALL`, `CALL_ENDED` and `POS_PING`, which are not
22
+ * call outcomes and would understate every rate. The same denominator applies to
23
+ * the summary AND every breakdown row.
24
+ *
25
+ * The formatter takes the documents of ONE scope level (e.g. the `localMonth`
26
+ * documents of a selection, or the `localDate` documents of one day) and folds
27
+ * them into one page payload. It is pure and never throws.
28
+ */
29
+ export interface IFormattedDialerSummary {
30
+ events: number;
31
+ incoming_calls: number;
32
+ outgoing_calls: number;
33
+ answered: number;
34
+ missed: number;
35
+ declined: number;
36
+ ended: number;
37
+ pos_pings: number;
38
+ /**
39
+ * `answered / (answered + missed + declined)` as a percentage (2dp) —
40
+ * DERIVED, never stored; null when the outcome denominator is 0.
41
+ */
42
+ answer_rate: number | null;
43
+ /**
44
+ * `missed / (answered + missed + declined)` as a percentage (2dp) —
45
+ * DERIVED, never stored; null when the outcome denominator is 0.
46
+ */
47
+ missed_rate: number | null;
48
+ }
49
+ /** One hour bucket of the call-activity series (`hour` 0..23, label `"0"`..`"23"`). */
50
+ export interface IFormattedDialerHourRow {
51
+ hour: number;
52
+ label: string;
53
+ events: number;
54
+ }
55
+ /** One grouped breakdown row (by action / terminal / staff). */
56
+ export interface IFormattedDialerBreakdownRow {
57
+ key: string;
58
+ events: number;
59
+ answered: number;
60
+ missed: number;
61
+ declined: number;
62
+ /**
63
+ * `answered / (answered + missed + declined)` as a percentage (2dp); null
64
+ * when the group has no outcome events. `events` is NOT the denominator.
65
+ */
66
+ answer_rate: number | null;
67
+ }
68
+ export interface IFormattedDialerPageData {
69
+ tenant_ids: string[];
70
+ summary: IFormattedDialerSummary;
71
+ /** All 24 hours, ascending — an absent hour is an explicit zero. */
72
+ by_hour: IFormattedDialerHourRow[];
73
+ by_action: IFormattedDialerBreakdownRow[];
74
+ by_pos: IFormattedDialerBreakdownRow[];
75
+ by_staff: IFormattedDialerBreakdownRow[];
76
+ /** The scope level the documents covered (diagnostics for the page header). */
77
+ scopes: {
78
+ scope_context: string;
79
+ scope_field: string;
80
+ }[];
81
+ }
82
+ /**
83
+ * Formats the report documents of one scope level into the page payload.
84
+ *
85
+ * `documents` may also be the single record returned by a live/historical read
86
+ * for one tenant. Key filters are applied here as well, so a client that only
87
+ * has unfiltered documents can still narrow them consistently with the server.
88
+ */
89
+ export declare function formatMaterializedDialerReport(documents: readonly IMaterializedTenantDialerReport[] | null | undefined, options?: {
90
+ filters?: IDialerKeyFilters | null;
91
+ }): IFormattedDialerPageData;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatMaterializedDialerReport = formatMaterializedDialerReport;
4
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
5
+ const materialized_dialer_accumulator_helpers_1 = require("./materialized-dialer-accumulator-helpers");
6
+ const materialized_dialer_key_helpers_1 = require("./materialized-dialer-key-helpers");
7
+ const percent = (numerator, denominator) => {
8
+ if (!Number.isFinite(denominator) || denominator <= 0)
9
+ return null;
10
+ return Math.round((numerator / denominator) * 10000) / 100;
11
+ };
12
+ /**
13
+ * The ONLY rate denominator of the Dialer contract:
14
+ * `answered + missed + declined`. Every other event (incoming/outgoing/ended/
15
+ * ping) is activity, not an outcome, and must not dilute the rate.
16
+ */
17
+ const outcomeDenominator = (answered, missed, declined) => (Number(answered) || 0) + (Number(missed) || 0) + (Number(declined) || 0);
18
+ const summaryOf = (counters) => ({
19
+ events: counters.events,
20
+ incoming_calls: counters.incoming_calls,
21
+ outgoing_calls: counters.outgoing_calls,
22
+ answered: counters.answered,
23
+ missed: counters.missed,
24
+ declined: counters.declined,
25
+ ended: counters.ended,
26
+ pos_pings: counters.pos_pings,
27
+ answer_rate: percent(counters.answered, outcomeDenominator(counters.answered, counters.missed, counters.declined)),
28
+ missed_rate: percent(counters.missed, outcomeDenominator(counters.answered, counters.missed, counters.declined)),
29
+ });
30
+ const addBreakdown = (target, counters) => {
31
+ target.events += counters.events;
32
+ target.answered += counters.answered;
33
+ target.missed += counters.missed;
34
+ target.declined += counters.declined;
35
+ };
36
+ const breakdownRows = (map) => [...map.entries()]
37
+ .map(([key, value]) => ({
38
+ key,
39
+ events: value.events,
40
+ answered: value.answered,
41
+ missed: value.missed,
42
+ declined: value.declined,
43
+ answer_rate: percent(value.answered, outcomeDenominator(value.answered, value.missed, value.declined)),
44
+ }))
45
+ .sort((a, b) => b.events - a.events || (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
46
+ /**
47
+ * Formats the report documents of one scope level into the page payload.
48
+ *
49
+ * `documents` may also be the single record returned by a live/historical read
50
+ * for one tenant. Key filters are applied here as well, so a client that only
51
+ * has unfiltered documents can still narrow them consistently with the server.
52
+ */
53
+ function formatMaterializedDialerReport(documents, options = {}) {
54
+ const docs = (documents ?? []).filter((doc) => doc != null);
55
+ const filters = options.filters ?? null;
56
+ const total = (0, materialized_dialer_accumulator_helpers_1.freshDialerCounters)();
57
+ const byAction = new Map();
58
+ const byPos = new Map();
59
+ const byStaff = new Map();
60
+ const tenantIds = new Set();
61
+ const scopes = new Set();
62
+ const bump = (map, key, counters) => {
63
+ const target = map.get(key) ?? { events: 0, answered: 0, missed: 0, declined: 0 };
64
+ addBreakdown(target, counters);
65
+ map.set(key, target);
66
+ };
67
+ for (const doc of docs) {
68
+ if (doc.tenant_id != null)
69
+ tenantIds.add(String(doc.tenant_id));
70
+ scopes.add(`${String(doc.scope_context)}|${String(doc.scope_field)}`);
71
+ for (const [key, block] of Object.entries(doc.dialer_counters ?? {})) {
72
+ if (!(0, materialized_dialer_key_helpers_1.dialerKeyPassesFilters)(key, filters))
73
+ continue;
74
+ (0, materialized_dialer_accumulator_helpers_1.mergeDialerCounters)(total, block);
75
+ const parsed = (0, materialized_dialer_key_helpers_1.parseMaterializedDialerKey)(key);
76
+ bump(byAction, parsed?.action ?? key, block);
77
+ bump(byPos, parsed?.pos_id ?? key, block);
78
+ bump(byStaff, parsed?.staff_id ?? key, block);
79
+ }
80
+ }
81
+ const byHour = MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_HOUR_KEYS.map((label) => ({
82
+ hour: Number(label),
83
+ label,
84
+ events: Number(total.by_hour?.[label]) || 0,
85
+ }));
86
+ return {
87
+ tenant_ids: [...tenantIds].sort(),
88
+ summary: summaryOf(total),
89
+ by_hour: byHour,
90
+ by_action: breakdownRows(byAction),
91
+ by_pos: breakdownRows(byPos),
92
+ by_staff: breakdownRows(byStaff),
93
+ scopes: [...scopes].sort().map((identity) => {
94
+ const [scope_context, scope_field] = identity.split('|');
95
+ return { scope_context, scope_field };
96
+ }),
97
+ };
98
+ }
@@ -28,6 +28,7 @@ export declare enum REPORT_KEY_ENUM {
28
28
  PREP_TIME = "PREP_TIME",
29
29
  CASH_IN_OUT = "CASH_IN_OUT",
30
30
  DELIVERY = "DELIVERY",
31
+ DIALER = "DIALER",
31
32
  SALES_COMPARISON = "SALES_COMPARISON",
32
33
  HOURLY_COMPARISON = "HOURLY_COMPARISON",
33
34
  PAYMENTS_COMPARISON = "PAYMENTS_COMPARISON",
@@ -41,6 +41,7 @@ var REPORT_KEY_ENUM;
41
41
  REPORT_KEY_ENUM["PREP_TIME"] = "PREP_TIME";
42
42
  REPORT_KEY_ENUM["CASH_IN_OUT"] = "CASH_IN_OUT";
43
43
  REPORT_KEY_ENUM["DELIVERY"] = "DELIVERY";
44
+ REPORT_KEY_ENUM["DIALER"] = "DIALER";
44
45
  REPORT_KEY_ENUM["SALES_COMPARISON"] = "SALES_COMPARISON";
45
46
  REPORT_KEY_ENUM["HOURLY_COMPARISON"] = "HOURLY_COMPARISON";
46
47
  REPORT_KEY_ENUM["PAYMENTS_COMPARISON"] = "PAYMENTS_COMPARISON";
@@ -62,6 +63,7 @@ exports.REPORT_ROUTE_SEGMENTS = {
62
63
  [REPORT_KEY_ENUM.PREP_TIME]: 'prep-time',
63
64
  [REPORT_KEY_ENUM.CASH_IN_OUT]: 'cash-in-out',
64
65
  [REPORT_KEY_ENUM.DELIVERY]: 'delivery',
66
+ [REPORT_KEY_ENUM.DIALER]: 'dialer',
65
67
  [REPORT_KEY_ENUM.SALES_COMPARISON]: 'sales-comparison',
66
68
  [REPORT_KEY_ENUM.HOURLY_COMPARISON]: 'hourly-comparison',
67
69
  [REPORT_KEY_ENUM.PAYMENTS_COMPARISON]: 'payments-comparison',
@@ -92,6 +94,7 @@ exports.REPORT_CAPABILITIES = {
92
94
  [REPORT_KEY_ENUM.PREP_TIME]: { live: true, historical: true, details: true },
93
95
  [REPORT_KEY_ENUM.CASH_IN_OUT]: { live: true, historical: true, details: true },
94
96
  [REPORT_KEY_ENUM.DELIVERY]: { live: true, historical: true, details: true },
97
+ [REPORT_KEY_ENUM.DIALER]: { live: true, historical: true, details: true },
95
98
  [REPORT_KEY_ENUM.HOURLY_COMPARISON]: { live: true, historical: true, details: true },
96
99
  [REPORT_KEY_ENUM.PAYMENTS_COMPARISON]: { live: true, historical: true, details: true },
97
100
  [REPORT_KEY_ENUM.CREDIT_BILLS]: { live: false, historical: true, details: true },
@@ -37,6 +37,8 @@ export * from './materialized_tenant_delivery_geo_scopes';
37
37
  export * from './materialized_tenant_delivery_reports';
38
38
  export * from './materialized_tenant_discount_entries';
39
39
  export * from './materialized_tenant_discount_reports';
40
+ export * from './materialized_tenant_dialer_entries';
41
+ export * from './materialized_tenant_dialer_reports';
40
42
  export * from './materialized_tenant_discount_sources';
41
43
  export * from './materialized_tenant_hourly_comparison_entries';
42
44
  export * from './materialized_tenant_hourly_comparison_reports';
@@ -53,6 +53,8 @@ __exportStar(require("./materialized_tenant_delivery_geo_scopes"), exports);
53
53
  __exportStar(require("./materialized_tenant_delivery_reports"), exports);
54
54
  __exportStar(require("./materialized_tenant_discount_entries"), exports);
55
55
  __exportStar(require("./materialized_tenant_discount_reports"), exports);
56
+ __exportStar(require("./materialized_tenant_dialer_entries"), exports);
57
+ __exportStar(require("./materialized_tenant_dialer_reports"), exports);
56
58
  __exportStar(require("./materialized_tenant_discount_sources"), exports);
57
59
  __exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
58
60
  __exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
@@ -182,4 +182,5 @@ exports.DRILLDOWN_REPORT_TYPE_BY_ENTRY_COLLECTION = {
182
182
  materialized_tenant_sales_comparison_entries: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES,
183
183
  materialized_tenant_hourly_comparison_entries: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES,
184
184
  materialized_tenant_payments_comparison_entries: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES,
185
+ materialized_tenant_dialer_entries: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DIALER_ENTRIES,
185
186
  };
@@ -12,12 +12,12 @@ import { Schema } from 'mongoose';
12
12
  * a fixed key set - the keys ARE the data.
13
13
  */
14
14
  /**
15
- * v3 - PAGE-PARTITIONED entry documents (one page per source day, max scope
16
- * `localMonth`). v2 was one document per period scope, which made a month an unbounded
17
- * document. Historical v2 documents are not readable by the page-aware read layer and
18
- * must be re-materialized (re-close the days); the writer deletes the pages it owns.
15
+ * v1 - PAGE-PARTITIONED entry documents (one page per source day, max scope
16
+ * `localMonth`). All materialized collections use schema_version 1 for this
17
+ * pre-launch contract. Schema versioning will be reintroduced only when a
18
+ * future stored-shape change requires an explicit migration.
19
19
  */
20
- export declare const MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 3;
20
+ export declare const MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 1;
21
21
  export declare const MaterializedTenantDeliveryEntriesSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
22
22
  timestamps: true;
23
23
  versionKey: false;
@@ -17,12 +17,12 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
17
17
  * a fixed key set - the keys ARE the data.
18
18
  */
19
19
  /**
20
- * v3 - PAGE-PARTITIONED entry documents (one page per source day, max scope
21
- * `localMonth`). v2 was one document per period scope, which made a month an unbounded
22
- * document. Historical v2 documents are not readable by the page-aware read layer and
23
- * must be re-materialized (re-close the days); the writer deletes the pages it owns.
20
+ * v1 - PAGE-PARTITIONED entry documents (one page per source day, max scope
21
+ * `localMonth`). All materialized collections use schema_version 1 for this
22
+ * pre-launch contract. Schema versioning will be reintroduced only when a
23
+ * future stored-shape change requires an explicit migration.
24
24
  */
25
- exports.MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 3;
25
+ exports.MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 1;
26
26
  exports.MaterializedTenantDeliveryEntriesSchema = new mongoose_1.Schema({
27
27
  tenant_id: { type: String, required: true },
28
28
  brand_id: { type: String, required: true },
@@ -7,15 +7,15 @@ import { Schema } from 'mongoose';
7
7
  * cannot type precisely without a fixed key set - the keys ARE the data.
8
8
  */
9
9
  /**
10
- * v2 - the production day-close writer.
10
+ * v1 - the current production day-close writer.
11
11
  *
12
- * v1 was the pre-production shape. v2 splits the AREA row into the ORDER-side
13
- * (`delivery_orders`, net sale, fees) and the APP-side (`delivery_records`, payout)
14
- * populations, keys the demand heat on the joined ORDER's `localHour`, and fixes the
15
- * refund source to the payment rows. A v1 document is still readable: the formatter
16
- * falls back to the old `count` field for the record total.
12
+ * The stored shape splits the AREA row into the ORDER-side (`delivery_orders`,
13
+ * net sale, fees) and the APP-side (`delivery_records`, payout) populations,
14
+ * keys the demand heat on the joined ORDER's `localHour`, and uses the payment
15
+ * rows as the refund source. Schema versioning is reset to 1 across all
16
+ * materialized collections for this pre-launch contract.
17
17
  */
18
- export declare const MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 2;
18
+ export declare const MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 1;
19
19
  export declare const MaterializedTenantDeliveryReportSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
20
20
  timestamps: true;
21
21
  versionKey: false;
@@ -12,15 +12,15 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
12
12
  * cannot type precisely without a fixed key set - the keys ARE the data.
13
13
  */
14
14
  /**
15
- * v2 - the production day-close writer.
15
+ * v1 - the current production day-close writer.
16
16
  *
17
- * v1 was the pre-production shape. v2 splits the AREA row into the ORDER-side
18
- * (`delivery_orders`, net sale, fees) and the APP-side (`delivery_records`, payout)
19
- * populations, keys the demand heat on the joined ORDER's `localHour`, and fixes the
20
- * refund source to the payment rows. A v1 document is still readable: the formatter
21
- * falls back to the old `count` field for the record total.
17
+ * The stored shape splits the AREA row into the ORDER-side (`delivery_orders`,
18
+ * net sale, fees) and the APP-side (`delivery_records`, payout) populations,
19
+ * keys the demand heat on the joined ORDER's `localHour`, and uses the payment
20
+ * rows as the refund source. Schema versioning is reset to 1 across all
21
+ * materialized collections for this pre-launch contract.
22
22
  */
23
- exports.MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 2;
23
+ exports.MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 1;
24
24
  exports.MaterializedTenantDeliveryReportSchema = new mongoose_1.Schema({
25
25
  tenant_id: { type: String, required: true },
26
26
  brand_id: { type: String, required: true },
@@ -0,0 +1,107 @@
1
+ import { Schema } from 'mongoose';
2
+ /**
3
+ * Mongoose schema for `materialized_tenant_dialer_entries`.
4
+ *
5
+ * PAGE-PARTITIONED by source day, exactly like discounts/delivery entries: the
6
+ * day scope uses `page='all'` and every period entry scope (week / ISO week /
7
+ * month) uses `page=<source localDate>`, so a document is bounded by ONE day's
8
+ * event rows. There is no quarter / semester / year entry document.
9
+ *
10
+ * `dialer_entries` is `Mixed` on purpose: it is a key-addressed map of row
11
+ * sections whose keys are the report's `<ACTION>:<POS_ID>:<STAFF_ID>` grammar.
12
+ */
13
+ /** Document shape version. Bump with a migration for already-stored pages. */
14
+ export declare const MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION = 1;
15
+ export declare const MaterializedTenantDialerEntriesSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
16
+ timestamps: true;
17
+ versionKey: false;
18
+ minimize: false;
19
+ }, {
20
+ createdAt: NativeDate;
21
+ updatedAt: NativeDate;
22
+ } & {
23
+ createdAt: NativeDate;
24
+ updatedAt: NativeDate;
25
+ brand_id: string;
26
+ tenant_id: string;
27
+ day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
28
+ iteration: number;
29
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
30
+ scope_field: string;
31
+ schema_version: number;
32
+ source_watermark: NativeDate;
33
+ computed_at: NativeDate;
34
+ page: string;
35
+ dialer_entries?: any;
36
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
37
+ createdAt: NativeDate;
38
+ updatedAt: NativeDate;
39
+ } & {
40
+ createdAt: NativeDate;
41
+ updatedAt: NativeDate;
42
+ brand_id: string;
43
+ tenant_id: string;
44
+ day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
45
+ iteration: number;
46
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
47
+ scope_field: string;
48
+ schema_version: number;
49
+ source_watermark: NativeDate;
50
+ computed_at: NativeDate;
51
+ page: string;
52
+ dialer_entries?: any;
53
+ }>> & import("mongoose").FlatRecord<{
54
+ createdAt: NativeDate;
55
+ updatedAt: NativeDate;
56
+ } & {
57
+ createdAt: NativeDate;
58
+ updatedAt: NativeDate;
59
+ brand_id: string;
60
+ tenant_id: string;
61
+ day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
62
+ iteration: number;
63
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
64
+ scope_field: string;
65
+ schema_version: number;
66
+ source_watermark: NativeDate;
67
+ computed_at: NativeDate;
68
+ page: string;
69
+ dialer_entries?: any;
70
+ }> & {
71
+ _id: import("mongoose").Types.ObjectId;
72
+ } & {
73
+ __v: number;
74
+ }>;
75
+ export declare const MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_NAME = "materialized_tenant_dialer_entries";
76
+ /**
77
+ * ONE unique index per PAGE: `tenant_id + scope_context + scope_field + page`.
78
+ *
79
+ * Do NOT use the scope-only index here: every period page carries
80
+ * `day_index: null`, so `(tenant, scope, field, day_index)` would reject the
81
+ * second page of a month. The same key also serves the multi-page read (tenant
82
+ * + scope prefix, then pages).
83
+ *
84
+ * Declared ONLY — applying it is an owner deploy step; nothing calls
85
+ * `ensureIndexes` from a service.
86
+ */
87
+ export declare const MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_INDEXES: {
88
+ _id: {
89
+ _id: number;
90
+ };
91
+ tenant_id__scope_context__scope_field__page: {
92
+ tenant_id: number;
93
+ scope_context: number;
94
+ scope_field: number;
95
+ page: number;
96
+ };
97
+ };
98
+ export declare const MATERIALIZED_TENANT_DIALER_ENTRIES_INDEX_OPTIONS: {
99
+ key: {
100
+ tenant_id: number;
101
+ scope_context: number;
102
+ scope_field: number;
103
+ page: number;
104
+ };
105
+ name: string;
106
+ unique: boolean;
107
+ }[];
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MATERIALIZED_TENANT_DIALER_ENTRIES_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_NAME = exports.MaterializedTenantDialerEntriesSchema = exports.MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const ENUMS_1 = require("../../constants/ENUMS");
6
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
7
+ /**
8
+ * Mongoose schema for `materialized_tenant_dialer_entries`.
9
+ *
10
+ * PAGE-PARTITIONED by source day, exactly like discounts/delivery entries: the
11
+ * day scope uses `page='all'` and every period entry scope (week / ISO week /
12
+ * month) uses `page=<source localDate>`, so a document is bounded by ONE day's
13
+ * event rows. There is no quarter / semester / year entry document.
14
+ *
15
+ * `dialer_entries` is `Mixed` on purpose: it is a key-addressed map of row
16
+ * sections whose keys are the report's `<ACTION>:<POS_ID>:<STAFF_ID>` grammar.
17
+ */
18
+ /** Document shape version. Bump with a migration for already-stored pages. */
19
+ exports.MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION = 1;
20
+ exports.MaterializedTenantDialerEntriesSchema = new mongoose_1.Schema({
21
+ tenant_id: { type: String, required: true },
22
+ brand_id: { type: String, required: true },
23
+ scope_context: { type: String, required: true, enum: MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_ENTRY_SCOPES },
24
+ scope_field: { type: String, required: true },
25
+ /** `'all'` for the day scope; the source `YYYY-MM-DD` for a period scope. */
26
+ page: { type: String, required: true, immutable: true },
27
+ day_index: { type: String, default: null, enum: [...ENUMS_1.ALL_DAY_INDEX, null] },
28
+ dialer_entries: { type: mongoose_1.Schema.Types.Mixed, required: false, default: null },
29
+ iteration: { type: Number, required: true, min: 1, default: 1 },
30
+ schema_version: {
31
+ type: Number,
32
+ required: true,
33
+ immutable: true,
34
+ default: exports.MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION,
35
+ },
36
+ source_watermark: { type: mongoose_1.Schema.Types.Date, required: true },
37
+ computed_at: { type: mongoose_1.Schema.Types.Date, required: true },
38
+ createdAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date(), immutable: true },
39
+ updatedAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date() },
40
+ }, { timestamps: true, versionKey: false, minimize: false });
41
+ exports.MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_NAME = 'materialized_tenant_dialer_entries';
42
+ /**
43
+ * ONE unique index per PAGE: `tenant_id + scope_context + scope_field + page`.
44
+ *
45
+ * Do NOT use the scope-only index here: every period page carries
46
+ * `day_index: null`, so `(tenant, scope, field, day_index)` would reject the
47
+ * second page of a month. The same key also serves the multi-page read (tenant
48
+ * + scope prefix, then pages).
49
+ *
50
+ * Declared ONLY — applying it is an owner deploy step; nothing calls
51
+ * `ensureIndexes` from a service.
52
+ */
53
+ exports.MATERIALIZED_TENANT_DIALER_ENTRIES_COLLECTION_INDEXES = {
54
+ _id: { _id: 1 },
55
+ tenant_id__scope_context__scope_field__page: {
56
+ tenant_id: 1,
57
+ scope_context: 1,
58
+ scope_field: 1,
59
+ page: 1,
60
+ },
61
+ };
62
+ exports.MATERIALIZED_TENANT_DIALER_ENTRIES_INDEX_OPTIONS = [
63
+ {
64
+ key: { tenant_id: 1, scope_context: 1, scope_field: 1, page: 1 },
65
+ name: 'tenant_id__scope_context__scope_field__page',
66
+ unique: true,
67
+ },
68
+ ];