@managesome/eposmatic-toolkit 0.4.55 → 0.4.56

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 (70) 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 +85 -1
  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_dialer_entries.js +65 -0
  17. package/esm/schemas/models/materialized_tenant_dialer_reports.js +66 -0
  18. package/esm/schemas/types/index.js +2 -0
  19. package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
  20. package/esm/schemas/types/materialized_tenant_dialer_entries.js +1 -0
  21. package/esm/schemas/types/materialized_tenant_dialer_reports.js +7 -0
  22. package/lib/constants/MATERIALIZED_REPORTS.d.ts +72 -2
  23. package/lib/constants/MATERIALIZED_REPORTS.js +93 -1
  24. package/lib/helpers/materialized-reports/index.d.ts +7 -0
  25. package/lib/helpers/materialized-reports/index.js +7 -0
  26. package/lib/helpers/materialized-reports/materialized-dialer-accumulator-helpers.d.ts +39 -0
  27. package/lib/helpers/materialized-reports/materialized-dialer-accumulator-helpers.js +110 -0
  28. package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.d.ts +90 -0
  29. package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +340 -0
  30. package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.d.ts +67 -0
  31. package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.js +183 -0
  32. package/lib/helpers/materialized-reports/materialized-dialer-entry-pages.d.ts +97 -0
  33. package/lib/helpers/materialized-reports/materialized-dialer-entry-pages.js +235 -0
  34. package/lib/helpers/materialized-reports/materialized-dialer-key-helpers.d.ts +51 -0
  35. package/lib/helpers/materialized-reports/materialized-dialer-key-helpers.js +90 -0
  36. package/lib/helpers/materialized-reports/materialized-dialer-masking.d.ts +35 -0
  37. package/lib/helpers/materialized-reports/materialized-dialer-masking.js +57 -0
  38. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
  39. package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +13 -1
  40. package/lib/helpers/materialized-reports/report-platform/definition.js +84 -0
  41. package/lib/helpers/materialized-reports/tenant-dialer-formatter.d.ts +91 -0
  42. package/lib/helpers/materialized-reports/tenant-dialer-formatter.js +98 -0
  43. package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
  44. package/lib/helpers/reporting-contract/report-contract.js +3 -0
  45. package/lib/schemas/models/index.d.ts +2 -0
  46. package/lib/schemas/models/index.js +2 -0
  47. package/lib/schemas/models/materialized_report_drilldown_rows.js +1 -0
  48. package/lib/schemas/models/materialized_tenant_dialer_entries.d.ts +107 -0
  49. package/lib/schemas/models/materialized_tenant_dialer_entries.js +68 -0
  50. package/lib/schemas/models/materialized_tenant_dialer_reports.d.ts +100 -0
  51. package/lib/schemas/models/materialized_tenant_dialer_reports.js +69 -0
  52. package/lib/schemas/models/tenant_dialer_events.d.ts +3 -3
  53. package/lib/schemas/types/index.d.ts +2 -0
  54. package/lib/schemas/types/index.js +2 -0
  55. package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
  56. package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
  57. package/lib/schemas/types/materialized_tenant_dialer_entries.d.ts +83 -0
  58. package/lib/schemas/types/materialized_tenant_dialer_entries.js +2 -0
  59. package/lib/schemas/types/materialized_tenant_dialer_reports.d.ts +77 -0
  60. package/lib/schemas/types/materialized_tenant_dialer_reports.js +10 -0
  61. package/lib/tests/materialized-reports/materialized-dialer-compile.test.d.ts +1 -0
  62. package/lib/tests/materialized-reports/materialized-dialer-compile.test.js +213 -0
  63. package/lib/tests/materialized-reports/materialized-dialer-formatter.test.d.ts +1 -0
  64. package/lib/tests/materialized-reports/materialized-dialer-formatter.test.js +159 -0
  65. package/lib/tests/materialized-reports/materialized-dialer-plan.test.d.ts +1 -0
  66. package/lib/tests/materialized-reports/materialized-dialer-plan.test.js +223 -0
  67. package/lib/tests/materialized-reports/materialized-tenant-dialer-schema.test.d.ts +1 -0
  68. package/lib/tests/materialized-reports/materialized-tenant-dialer-schema.test.js +183 -0
  69. package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +16 -3
  70. package/package.json +1 -1
@@ -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
+ ];
@@ -0,0 +1,100 @@
1
+ import { Schema } from 'mongoose';
2
+ /**
3
+ * Mongoose schema for `materialized_tenant_dialer_reports`.
4
+ *
5
+ * `dialer_counters` is `Mixed` on purpose: it is a key-addressed map of bounded
6
+ * counter blocks (`<ACTION>:<POS_ID>:<STAFF_ID>` → counters + `by_hour`), and
7
+ * the keys ARE the data — Mongoose cannot type them without a fixed key set.
8
+ *
9
+ * The collection holds COUNTERS only. Itemized event rows live in the sibling
10
+ * `materialized_tenant_dialer_entries` collection (one page per source day).
11
+ */
12
+ /** Document shape version. Bump on a key-grammar/metric change + backfill. */
13
+ export declare const MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION = 1;
14
+ export declare const MaterializedTenantDialerReportSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
15
+ timestamps: true;
16
+ versionKey: false;
17
+ minimize: false;
18
+ }, {
19
+ createdAt: NativeDate;
20
+ updatedAt: NativeDate;
21
+ } & {
22
+ createdAt: NativeDate;
23
+ updatedAt: NativeDate;
24
+ brand_id: string;
25
+ tenant_id: string;
26
+ day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
27
+ iteration: number;
28
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
29
+ scope_field: string;
30
+ sale_type_key_filters: string[];
31
+ schema_version: number;
32
+ source_watermark: NativeDate;
33
+ computed_at: NativeDate;
34
+ dialer_counters: any;
35
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
36
+ createdAt: NativeDate;
37
+ updatedAt: NativeDate;
38
+ } & {
39
+ createdAt: NativeDate;
40
+ updatedAt: NativeDate;
41
+ brand_id: string;
42
+ tenant_id: string;
43
+ day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
44
+ iteration: number;
45
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
46
+ scope_field: string;
47
+ sale_type_key_filters: string[];
48
+ schema_version: number;
49
+ source_watermark: NativeDate;
50
+ computed_at: NativeDate;
51
+ dialer_counters: any;
52
+ }>> & import("mongoose").FlatRecord<{
53
+ createdAt: NativeDate;
54
+ updatedAt: NativeDate;
55
+ } & {
56
+ createdAt: NativeDate;
57
+ updatedAt: NativeDate;
58
+ brand_id: string;
59
+ tenant_id: string;
60
+ day_index: import("../../constants/ENUMS").DAY_INDEX_ENUM | null;
61
+ iteration: number;
62
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
63
+ scope_field: string;
64
+ sale_type_key_filters: string[];
65
+ schema_version: number;
66
+ source_watermark: NativeDate;
67
+ computed_at: NativeDate;
68
+ dialer_counters: any;
69
+ }> & {
70
+ _id: import("mongoose").Types.ObjectId;
71
+ } & {
72
+ __v: number;
73
+ }>;
74
+ export declare const MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_NAME = "materialized_tenant_dialer_reports";
75
+ /**
76
+ * The single UNIQUE compound identity index, like every materialized report
77
+ * collection. Declared ONLY — no service calls `index()` or `ensureIndexes`, and
78
+ * the services run with `autoIndex: false`. Applying it is an owner deploy step.
79
+ */
80
+ export declare const MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_INDEXES: {
81
+ _id: {
82
+ _id: number;
83
+ };
84
+ tenant_id__scope_context__scope_field__day_index: {
85
+ tenant_id: number;
86
+ scope_context: number;
87
+ scope_field: number;
88
+ day_index: number;
89
+ };
90
+ };
91
+ export declare const MATERIALIZED_TENANT_DIALER_REPORTS_INDEX_OPTIONS: {
92
+ key: {
93
+ tenant_id: number;
94
+ scope_context: number;
95
+ scope_field: number;
96
+ day_index: number;
97
+ };
98
+ name: string;
99
+ unique: boolean;
100
+ }[];
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MATERIALIZED_TENANT_DIALER_REPORTS_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_NAME = exports.MaterializedTenantDialerReportSchema = exports.MATERIALIZED_TENANT_DIALER_REPORTS_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_reports`.
9
+ *
10
+ * `dialer_counters` is `Mixed` on purpose: it is a key-addressed map of bounded
11
+ * counter blocks (`<ACTION>:<POS_ID>:<STAFF_ID>` → counters + `by_hour`), and
12
+ * the keys ARE the data — Mongoose cannot type them without a fixed key set.
13
+ *
14
+ * The collection holds COUNTERS only. Itemized event rows live in the sibling
15
+ * `materialized_tenant_dialer_entries` collection (one page per source day).
16
+ */
17
+ /** Document shape version. Bump on a key-grammar/metric change + backfill. */
18
+ exports.MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION = 1;
19
+ exports.MaterializedTenantDialerReportSchema = new mongoose_1.Schema({
20
+ tenant_id: { type: String, required: true },
21
+ brand_id: { type: String, required: true },
22
+ scope_context: { type: String, required: true, enum: MATERIALIZED_REPORTS_1.MATERIALIZED_DIALER_REPORT_SCOPES },
23
+ scope_field: { type: String, required: true },
24
+ day_index: { type: String, default: null, enum: [...ENUMS_1.ALL_DAY_INDEX, null] },
25
+ sale_type_key_filters: {
26
+ type: [String],
27
+ required: true,
28
+ default: () => [...MATERIALIZED_REPORTS_1.DIALER_KEY_FILTERS],
29
+ validate: {
30
+ validator: (value) => value.length > 0 &&
31
+ value.every((entry) => MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_KEY_FILTERS.includes(entry)),
32
+ message: 'sale_type_key_filters must be a non-empty subset of the known key filters',
33
+ },
34
+ },
35
+ dialer_counters: { type: mongoose_1.Schema.Types.Mixed, required: true, default: null },
36
+ iteration: { type: Number, required: true, min: 1, default: 1 },
37
+ schema_version: {
38
+ type: Number,
39
+ required: true,
40
+ immutable: true,
41
+ default: exports.MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION,
42
+ },
43
+ source_watermark: { type: mongoose_1.Schema.Types.Date, required: true },
44
+ computed_at: { type: mongoose_1.Schema.Types.Date, required: true },
45
+ createdAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date(), immutable: true },
46
+ updatedAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date() },
47
+ }, { timestamps: true, versionKey: false, minimize: false });
48
+ exports.MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_NAME = 'materialized_tenant_dialer_reports';
49
+ /**
50
+ * The single UNIQUE compound identity index, like every materialized report
51
+ * collection. Declared ONLY — no service calls `index()` or `ensureIndexes`, and
52
+ * the services run with `autoIndex: false`. Applying it is an owner deploy step.
53
+ */
54
+ exports.MATERIALIZED_TENANT_DIALER_REPORTS_COLLECTION_INDEXES = {
55
+ _id: { _id: 1 },
56
+ tenant_id__scope_context__scope_field__day_index: {
57
+ tenant_id: 1,
58
+ scope_context: 1,
59
+ scope_field: 1,
60
+ day_index: 1,
61
+ },
62
+ };
63
+ exports.MATERIALIZED_TENANT_DIALER_REPORTS_INDEX_OPTIONS = [
64
+ {
65
+ key: { tenant_id: 1, scope_context: 1, scope_field: 1, day_index: 1 },
66
+ name: 'tenant_id__scope_context__scope_field__day_index',
67
+ unique: true,
68
+ },
69
+ ];
@@ -27,8 +27,8 @@ export declare const TenantDialerEventSchema: Schema<any, import("mongoose").Mod
27
27
  phone_number: string;
28
28
  pos_id: string;
29
29
  schema_version: number;
30
- request_id: string;
31
30
  action: import("../../constants").DIALER_TYPES_ENUM;
31
+ request_id: string;
32
32
  staff_id?: string | null | undefined;
33
33
  staff_phone?: string | null | undefined;
34
34
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
@@ -42,8 +42,8 @@ export declare const TenantDialerEventSchema: Schema<any, import("mongoose").Mod
42
42
  phone_number: string;
43
43
  pos_id: string;
44
44
  schema_version: number;
45
- request_id: string;
46
45
  action: import("../../constants").DIALER_TYPES_ENUM;
46
+ request_id: string;
47
47
  staff_id?: string | null | undefined;
48
48
  staff_phone?: string | null | undefined;
49
49
  }>> & import("mongoose").FlatRecord<{
@@ -57,8 +57,8 @@ export declare const TenantDialerEventSchema: Schema<any, import("mongoose").Mod
57
57
  phone_number: string;
58
58
  pos_id: string;
59
59
  schema_version: number;
60
- request_id: string;
61
60
  action: import("../../constants").DIALER_TYPES_ENUM;
61
+ request_id: string;
62
62
  staff_id?: string | null | undefined;
63
63
  staff_phone?: string | null | undefined;
64
64
  }> & Required<{
@@ -41,6 +41,8 @@ export * from './materialized_tenant_delivery_geo_scopes';
41
41
  export * from './materialized_tenant_delivery_reports';
42
42
  export * from './materialized_tenant_discount_entries';
43
43
  export * from './materialized_tenant_discount_reports';
44
+ export * from './materialized_tenant_dialer_entries';
45
+ export * from './materialized_tenant_dialer_reports';
44
46
  export * from './materialized_tenant_discount_sources';
45
47
  export * from './materialized_tenant_hourly_comparison_entries';
46
48
  export * from './materialized_tenant_hourly_comparison_reports';
@@ -57,6 +57,8 @@ __exportStar(require("./materialized_tenant_delivery_geo_scopes"), exports);
57
57
  __exportStar(require("./materialized_tenant_delivery_reports"), exports);
58
58
  __exportStar(require("./materialized_tenant_discount_entries"), exports);
59
59
  __exportStar(require("./materialized_tenant_discount_reports"), exports);
60
+ __exportStar(require("./materialized_tenant_dialer_entries"), exports);
61
+ __exportStar(require("./materialized_tenant_dialer_reports"), exports);
60
62
  __exportStar(require("./materialized_tenant_discount_sources"), exports);
61
63
  __exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
62
64
  __exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
@@ -13,7 +13,7 @@ import { MATERIALIZED_REPORT_SCOPE_ENUM, MATERIALIZED_REPORT_TYPE_ENUM } from '.
13
13
  * fields a page query needs: selection identity, sort anchor, and cursor
14
14
  * tie-break.
15
15
  */
16
- export type TDrilldownReportType = MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES;
16
+ export type TDrilldownReportType = MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DISCOUNT_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PREP_TIME_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_CASH_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DELIVERY_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES | MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DIALER_ENTRIES;
17
17
  export declare const ALL_DRILLDOWN_REPORT_TYPES: TDrilldownReportType[];
18
18
  /** One flattened itemized row. */
19
19
  export interface IMaterializedReportDrilldownRow {
@@ -10,4 +10,5 @@ exports.ALL_DRILLDOWN_REPORT_TYPES = [
10
10
  MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_COMPARISON_ENTRIES,
11
11
  MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_HOURLY_COMPARISON_ENTRIES,
12
12
  MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_PAYMENTS_COMPARISON_ENTRIES,
13
+ MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DIALER_ENTRIES,
13
14
  ];
@@ -0,0 +1,83 @@
1
+ import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
2
+ import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
3
+ /**
4
+ * Types for `materialized_tenant_dialer_entries`.
5
+ *
6
+ * ## One page per source day
7
+ *
8
+ * The entry collection follows the discounts/delivery page model exactly: the
9
+ * report document is counters only, and an entry document is ONE PAGE bounded
10
+ * by ONE source day.
11
+ *
12
+ * | scope | page |
13
+ * | --- | --- |
14
+ * | `localDate` | `'all'` (the scope is already one day) |
15
+ * | `localWeek` | `<source localDate>` |
16
+ * | `localWeekOfYear` | `<source localDate>` |
17
+ * | `localMonth` | `<source localDate>` |
18
+ *
19
+ * An oversized page splits into deterministic `page#0`, `page#1`, … sub-pages;
20
+ * the unsuffixed identity is used while the page fits.
21
+ *
22
+ * ## Phones are MASKED at compile time
23
+ *
24
+ * A materialized row (and therefore every API response built from it) carries
25
+ * only `phone_number_masked` / `staff_phone_masked`. The RAW source numbers are
26
+ * never copied into a materialized document.
27
+ */
28
+ export interface IDialerEntryRow {
29
+ /** Source event `_id` — the row identity and the keyset cursor tie-break. */
30
+ event_id: string;
31
+ request_id: string;
32
+ action: string;
33
+ /** Masked caller number — never the raw source value. */
34
+ phone_number_masked: string;
35
+ staff_id: string | null;
36
+ /** Masked staff number — never the raw source value. */
37
+ staff_phone_masked: string | null;
38
+ pos_id: string;
39
+ /** ISO-8601 instant of the source event (`createdAt`). */
40
+ created_at: string;
41
+ /** The event's own tenant-local business day (attributed events only). */
42
+ local_date: string;
43
+ /** The event's own tenant-local hour (`0`..`23`). */
44
+ local_hour: number;
45
+ }
46
+ /** Per-key row section of one entry page. */
47
+ export interface IDialerEntrySection {
48
+ rows: IDialerEntryRow[];
49
+ }
50
+ /** One `materialized_tenant_dialer_entries` PAGE. */
51
+ export interface IMaterializedTenantDialerEntry {
52
+ _id: string;
53
+ tenant_id: string;
54
+ brand_id: string;
55
+ /** One of `MATERIALIZED_DIALER_ENTRY_SCOPES`. */
56
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
57
+ scope_field: string;
58
+ /** `'all'` for the day scope; the source `YYYY-MM-DD` for a period scope. */
59
+ page: string;
60
+ /** Denormalized weekday — set ONLY on the `localDate` page. */
61
+ day_index: DAY_INDEX_ENUM | null;
62
+ /** One row section per observed `<ACTION>:<POS_ID>:<STAFF_ID>` key. */
63
+ dialer_entries: Record<string, IDialerEntrySection> | null;
64
+ /** Shared materialized-envelope field (structural version of THIS document). */
65
+ iteration?: number;
66
+ schema_version: number;
67
+ source_watermark: Date;
68
+ computed_at: Date;
69
+ createdAt: Date;
70
+ updatedAt: Date;
71
+ }
72
+ /** Attributed vs unattributed counts of one closing day (worker observability). */
73
+ export interface IDialerSourceDayCounts {
74
+ /** Events whose `localDate` is the closing day — materialized. */
75
+ attributed_events: number;
76
+ /**
77
+ * Events inside the closing day's opening→closing window that carry NO
78
+ * `localDate`. They are NEVER attributed to a day; the count is reported so
79
+ * the gap is visible. Late events (written after the close) are not counted
80
+ * here until a re-close.
81
+ */
82
+ unattributed_events: number;
83
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,77 @@
1
+ import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
2
+ import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
3
+ /**
4
+ * Types for `materialized_tenant_dialer_reports`.
5
+ *
6
+ * ## An EVENT report, not a call report
7
+ *
8
+ * The source (`tenant_dialer_events`) is append-only and stores ONE row per
9
+ * dialer action: `INCOMING_CALL`, `OUTGOING_CALL`, `CALL_ANSWERED`,
10
+ * `MISSED_CALL`, `CALL_DECLINED`, `CALL_ENDED`, `POS_PING`. There is no
11
+ * duration and no order attribution, so the counters count EVENTS and the
12
+ * page derives every rate itself. The approved contract is
13
+ * `outcome_denominator = answered + missed + declined`, with
14
+ * `answer_rate = answered / outcome_denominator` and
15
+ * `missed_rate = missed / outcome_denominator` (percentage, 2 decimals, null
16
+ * when the denominator is 0). Nothing derived is stored.
17
+ *
18
+ * ## Attributed events only
19
+ *
20
+ * A day is `event.localDate`. An event written without local fields is
21
+ * UNATTRIBUTED: it is never assigned to a guessed day, so it is excluded from
22
+ * every day/period document (the materializer reports its count separately).
23
+ *
24
+ * ## Key grammar
25
+ *
26
+ * `sale_type_key_filters` declares `<ACTION>:<POS_ID>:<STAFF_ID>`. A component
27
+ * the source does not carry is encoded as `UNKNOWN`, never omitted.
28
+ */
29
+ export interface IDialerCounters {
30
+ /** Every attributed event (`INCOMING_CALL` + `OUTGOING_CALL` + outcomes + pings). */
31
+ events: number;
32
+ incoming_calls: number;
33
+ outgoing_calls: number;
34
+ answered: number;
35
+ missed: number;
36
+ declined: number;
37
+ ended: number;
38
+ pos_pings: number;
39
+ /**
40
+ * Event count by the event's tenant-local hour: keys `"0"`..`"23"`.
41
+ *
42
+ * Every key is initialized to 0 so absence is unambiguously zero. An event
43
+ * with a `localDate` but no usable `localHour` still counts in `events`; it
44
+ * is not bucketed into an invented hour, so `Σ by_hour` can only be lower
45
+ * than `events` for malformed partial local fields.
46
+ */
47
+ by_hour: Record<string, number>;
48
+ }
49
+ /** The declared key dimensions, in grammar order. */
50
+ export type TDialerKeyFilters = [
51
+ MATERIALIZED_REPORT_KEY_FILTER_ENUM.ACTION,
52
+ MATERIALIZED_REPORT_KEY_FILTER_ENUM.POS_ID,
53
+ MATERIALIZED_REPORT_KEY_FILTER_ENUM.STAFF_ID
54
+ ];
55
+ /** One `materialized_tenant_dialer_reports` document (counters only). */
56
+ export interface IMaterializedTenantDialerReport {
57
+ _id: string;
58
+ tenant_id: string;
59
+ brand_id: string;
60
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
61
+ scope_field: string;
62
+ /** Denormalized weekday — set on the DAY document, null on every period. */
63
+ day_index: DAY_INDEX_ENUM | null;
64
+ /** The dimensions the key encodes, in grammar order. */
65
+ sale_type_key_filters: TDialerKeyFilters;
66
+ /** Keyed by `<ACTION>:<POS_ID>:<STAFF_ID>`. */
67
+ dialer_counters: Record<string, IDialerCounters>;
68
+ /** Shared materialized-envelope field (structural version of THIS document). */
69
+ iteration?: number;
70
+ schema_version: number;
71
+ source_watermark: Date;
72
+ computed_at: Date;
73
+ createdAt: Date;
74
+ updatedAt: Date;
75
+ }
76
+ /** The default key-filter declaration of a dialer document. */
77
+ export declare const MATERIALIZED_DIALER_REPORT_KEY_FILTERS: TDialerKeyFilters;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MATERIALIZED_DIALER_REPORT_KEY_FILTERS = void 0;
4
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
5
+ /** The default key-filter declaration of a dialer document. */
6
+ exports.MATERIALIZED_DIALER_REPORT_KEY_FILTERS = [
7
+ MATERIALIZED_REPORTS_1.DIALER_KEY_FILTERS[0],
8
+ MATERIALIZED_REPORTS_1.DIALER_KEY_FILTERS[1],
9
+ MATERIALIZED_REPORTS_1.DIALER_KEY_FILTERS[2],
10
+ ];