@managesome/eposmatic-toolkit 0.4.54 → 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.
- package/esm/constants/MATERIALIZED_REPORTS.js +91 -0
- package/esm/helpers/materialized-reports/index.js +7 -0
- package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +18 -0
- package/esm/helpers/materialized-reports/materialized-dialer-accumulator-helpers.js +100 -0
- package/esm/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +328 -0
- package/esm/helpers/materialized-reports/materialized-dialer-compile-helpers.js +180 -0
- package/esm/helpers/materialized-reports/materialized-dialer-entry-pages.js +222 -0
- package/esm/helpers/materialized-reports/materialized-dialer-key-helpers.js +82 -0
- package/esm/helpers/materialized-reports/materialized-dialer-masking.js +54 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
- package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +13 -1
- package/esm/helpers/materialized-reports/report-platform/definition.js +85 -1
- package/esm/helpers/materialized-reports/tenant-dialer-formatter.js +95 -0
- package/esm/helpers/reporting-contract/report-contract.js +3 -0
- package/esm/schemas/models/index.js +3 -0
- package/esm/schemas/models/materialized_report_drilldown_rows.js +1 -0
- package/esm/schemas/models/materialized_tenant_dialer_entries.js +65 -0
- package/esm/schemas/models/materialized_tenant_dialer_reports.js +66 -0
- package/esm/schemas/models/tenant_dialer_events.js +133 -0
- package/esm/schemas/types/index.js +3 -0
- package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
- package/esm/schemas/types/materialized_tenant_dialer_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_dialer_reports.js +7 -0
- package/esm/schemas/types/tenant_dialer_events.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +72 -2
- package/lib/constants/MATERIALIZED_REPORTS.js +93 -1
- package/lib/helpers/materialized-reports/index.d.ts +7 -0
- package/lib/helpers/materialized-reports/index.js +7 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +1 -0
- package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +19 -0
- package/lib/helpers/materialized-reports/materialized-dialer-accumulator-helpers.d.ts +39 -0
- package/lib/helpers/materialized-reports/materialized-dialer-accumulator-helpers.js +110 -0
- package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.d.ts +90 -0
- package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +340 -0
- package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.d.ts +67 -0
- package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.js +183 -0
- package/lib/helpers/materialized-reports/materialized-dialer-entry-pages.d.ts +97 -0
- package/lib/helpers/materialized-reports/materialized-dialer-entry-pages.js +235 -0
- package/lib/helpers/materialized-reports/materialized-dialer-key-helpers.d.ts +51 -0
- package/lib/helpers/materialized-reports/materialized-dialer-key-helpers.js +90 -0
- package/lib/helpers/materialized-reports/materialized-dialer-masking.d.ts +35 -0
- package/lib/helpers/materialized-reports/materialized-dialer-masking.js +57 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +4 -0
- package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +13 -1
- package/lib/helpers/materialized-reports/report-platform/definition.js +84 -0
- package/lib/helpers/materialized-reports/tenant-dialer-formatter.d.ts +91 -0
- package/lib/helpers/materialized-reports/tenant-dialer-formatter.js +98 -0
- package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
- package/lib/helpers/reporting-contract/report-contract.js +3 -0
- package/lib/schemas/models/index.d.ts +3 -0
- package/lib/schemas/models/index.js +3 -0
- package/lib/schemas/models/materialized_report_drilldown_rows.js +1 -0
- package/lib/schemas/models/materialized_tenant_dialer_entries.d.ts +107 -0
- package/lib/schemas/models/materialized_tenant_dialer_entries.js +68 -0
- package/lib/schemas/models/materialized_tenant_dialer_reports.d.ts +100 -0
- package/lib/schemas/models/materialized_tenant_dialer_reports.js +69 -0
- package/lib/schemas/models/tenant-activity-logs.d.ts +3 -3
- package/lib/schemas/models/tenant_dialer_events.d.ts +130 -0
- package/lib/schemas/models/tenant_dialer_events.js +136 -0
- package/lib/schemas/models/warehouse-activity-logs.d.ts +3 -3
- package/lib/schemas/types/index.d.ts +3 -0
- package/lib/schemas/types/index.js +3 -0
- package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
- package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
- package/lib/schemas/types/materialized_tenant_dialer_entries.d.ts +83 -0
- package/lib/schemas/types/materialized_tenant_dialer_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_dialer_reports.d.ts +77 -0
- package/lib/schemas/types/materialized_tenant_dialer_reports.js +10 -0
- package/lib/schemas/types/tenant_dialer_events.d.ts +35 -0
- package/lib/schemas/types/tenant_dialer_events.js +2 -0
- package/lib/tests/materialized-reports/materialized-dialer-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dialer-compile.test.js +213 -0
- package/lib/tests/materialized-reports/materialized-dialer-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dialer-formatter.test.js +159 -0
- package/lib/tests/materialized-reports/materialized-dialer-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dialer-plan.test.js +223 -0
- package/lib/tests/materialized-reports/materialized-tenant-dialer-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-dialer-schema.test.js +183 -0
- package/lib/tests/materialized-reports/materialized-wipe-tooling.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-wipe-tooling.test.js +37 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +16 -3
- package/lib/tests/tenant-dialer-events-schema.test.d.ts +1 -0
- package/lib/tests/tenant-dialer-events-schema.test.js +191 -0
- package/package.json +1 -1
|
@@ -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
|
+
];
|
|
@@ -13,9 +13,9 @@ export declare const TenantActivityLogSchema: Schema<any, import("mongoose").Mod
|
|
|
13
13
|
updatedAt: NativeDate;
|
|
14
14
|
tenant_id: string;
|
|
15
15
|
title: string;
|
|
16
|
+
action: import("../../constants").TENANT_ACTIVITY_LOG_ACTION_ENUM;
|
|
16
17
|
entity_type: import("../../constants").TENANT_ACTIVITY_LOG_ENTITY_TYPE_ENUM;
|
|
17
18
|
entity_id: string;
|
|
18
|
-
action: import("../../constants").TENANT_ACTIVITY_LOG_ACTION_ENUM;
|
|
19
19
|
severity: TENANT_ACTIVITY_LOG_SEVERITY_ENUM;
|
|
20
20
|
changes: import("mongoose").Types.DocumentArray<{
|
|
21
21
|
field: string;
|
|
@@ -49,9 +49,9 @@ export declare const TenantActivityLogSchema: Schema<any, import("mongoose").Mod
|
|
|
49
49
|
updatedAt: NativeDate;
|
|
50
50
|
tenant_id: string;
|
|
51
51
|
title: string;
|
|
52
|
+
action: import("../../constants").TENANT_ACTIVITY_LOG_ACTION_ENUM;
|
|
52
53
|
entity_type: import("../../constants").TENANT_ACTIVITY_LOG_ENTITY_TYPE_ENUM;
|
|
53
54
|
entity_id: string;
|
|
54
|
-
action: import("../../constants").TENANT_ACTIVITY_LOG_ACTION_ENUM;
|
|
55
55
|
severity: TENANT_ACTIVITY_LOG_SEVERITY_ENUM;
|
|
56
56
|
changes: import("mongoose").Types.DocumentArray<{
|
|
57
57
|
field: string;
|
|
@@ -85,9 +85,9 @@ export declare const TenantActivityLogSchema: Schema<any, import("mongoose").Mod
|
|
|
85
85
|
updatedAt: NativeDate;
|
|
86
86
|
tenant_id: string;
|
|
87
87
|
title: string;
|
|
88
|
+
action: import("../../constants").TENANT_ACTIVITY_LOG_ACTION_ENUM;
|
|
88
89
|
entity_type: import("../../constants").TENANT_ACTIVITY_LOG_ENTITY_TYPE_ENUM;
|
|
89
90
|
entity_id: string;
|
|
90
|
-
action: import("../../constants").TENANT_ACTIVITY_LOG_ACTION_ENUM;
|
|
91
91
|
severity: TENANT_ACTIVITY_LOG_SEVERITY_ENUM;
|
|
92
92
|
changes: import("mongoose").Types.DocumentArray<{
|
|
93
93
|
field: string;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
/**
|
|
3
|
+
* Shape version of a `tenant_dialer_events` row. Bump only with a migration
|
|
4
|
+
* for already-stored source events.
|
|
5
|
+
*/
|
|
6
|
+
export declare const TENANT_DIALER_EVENTS_SCHEMA_VERSION = 1;
|
|
7
|
+
/**
|
|
8
|
+
* APPEND-ONLY source event stream for the future Dialer materialized report.
|
|
9
|
+
* Rows are written by items-service with
|
|
10
|
+
* `findOneAndUpdate({ tenant_id, request_id }, { $setOnInsert }, { upsert: true })`,
|
|
11
|
+
* so a retried request returns the ORIGINAL row and never rewrites
|
|
12
|
+
* `createdAt`, the local-time fields or any other stored value. No report
|
|
13
|
+
* fields (for example duration) live here.
|
|
14
|
+
*/
|
|
15
|
+
export declare const TenantDialerEventSchema: 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
|
+
_id: import("mongoose").Types.ObjectId;
|
|
24
|
+
createdAt: NativeDate;
|
|
25
|
+
updatedAt: NativeDate;
|
|
26
|
+
tenant_id: string;
|
|
27
|
+
phone_number: string;
|
|
28
|
+
pos_id: string;
|
|
29
|
+
schema_version: number;
|
|
30
|
+
action: import("../../constants").DIALER_TYPES_ENUM;
|
|
31
|
+
request_id: string;
|
|
32
|
+
staff_id?: string | null | undefined;
|
|
33
|
+
staff_phone?: string | null | undefined;
|
|
34
|
+
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
35
|
+
createdAt: NativeDate;
|
|
36
|
+
updatedAt: NativeDate;
|
|
37
|
+
} & {
|
|
38
|
+
_id: import("mongoose").Types.ObjectId;
|
|
39
|
+
createdAt: NativeDate;
|
|
40
|
+
updatedAt: NativeDate;
|
|
41
|
+
tenant_id: string;
|
|
42
|
+
phone_number: string;
|
|
43
|
+
pos_id: string;
|
|
44
|
+
schema_version: number;
|
|
45
|
+
action: import("../../constants").DIALER_TYPES_ENUM;
|
|
46
|
+
request_id: string;
|
|
47
|
+
staff_id?: string | null | undefined;
|
|
48
|
+
staff_phone?: string | null | undefined;
|
|
49
|
+
}>> & import("mongoose").FlatRecord<{
|
|
50
|
+
createdAt: NativeDate;
|
|
51
|
+
updatedAt: NativeDate;
|
|
52
|
+
} & {
|
|
53
|
+
_id: import("mongoose").Types.ObjectId;
|
|
54
|
+
createdAt: NativeDate;
|
|
55
|
+
updatedAt: NativeDate;
|
|
56
|
+
tenant_id: string;
|
|
57
|
+
phone_number: string;
|
|
58
|
+
pos_id: string;
|
|
59
|
+
schema_version: number;
|
|
60
|
+
action: import("../../constants").DIALER_TYPES_ENUM;
|
|
61
|
+
request_id: string;
|
|
62
|
+
staff_id?: string | null | undefined;
|
|
63
|
+
staff_phone?: string | null | undefined;
|
|
64
|
+
}> & Required<{
|
|
65
|
+
_id: import("mongoose").Types.ObjectId;
|
|
66
|
+
}> & {
|
|
67
|
+
__v: number;
|
|
68
|
+
}>;
|
|
69
|
+
export declare const TENANT_DIALER_EVENTS_COLLECTION_NAME = "tenant_dialer_events";
|
|
70
|
+
/**
|
|
71
|
+
* Describes the indexes for `tenant_dialer_events`. Values are Mongo key
|
|
72
|
+
* patterns that can be passed straight to `.hint()`.
|
|
73
|
+
* - `_id`: unique primary key.
|
|
74
|
+
* - `tenant_id__request_id`: UNIQUE idempotency key — one source event per
|
|
75
|
+
* tenant + request (native: `callId:action`, JS: UUID reused on retry).
|
|
76
|
+
* - `tenant_id__localDate__action`: future report reads per business day and
|
|
77
|
+
* action. Local fields may be absent for un-attributed events, so reads must
|
|
78
|
+
* tolerate a missing `localDate` (sparse-aware querying, not a partial
|
|
79
|
+
* index requirement).
|
|
80
|
+
* - `tenant_id__phone_number__createdAt`: future pairing/attribution reads for
|
|
81
|
+
* one caller phone ordered by the canonical receipt time.
|
|
82
|
+
*/
|
|
83
|
+
export declare const TENANT_DIALER_EVENTS_COLLECTION_INDEXES: {
|
|
84
|
+
_id: {
|
|
85
|
+
_id: number;
|
|
86
|
+
};
|
|
87
|
+
tenant_id__request_id: {
|
|
88
|
+
tenant_id: number;
|
|
89
|
+
request_id: number;
|
|
90
|
+
};
|
|
91
|
+
tenant_id__localDate__action: {
|
|
92
|
+
tenant_id: number;
|
|
93
|
+
localDate: number;
|
|
94
|
+
action: number;
|
|
95
|
+
};
|
|
96
|
+
tenant_id__phone_number__createdAt: {
|
|
97
|
+
tenant_id: number;
|
|
98
|
+
phone_number: number;
|
|
99
|
+
createdAt: number;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Index OPTIONS to DECLARE (never created at application startup). The
|
|
104
|
+
* materializer/ops path owns creation; `tenant_id__request_id` MUST be created
|
|
105
|
+
* with `unique: true` or concurrent retries could insert a second event.
|
|
106
|
+
*/
|
|
107
|
+
export declare const TENANT_DIALER_EVENTS_INDEX_OPTIONS: ({
|
|
108
|
+
key: {
|
|
109
|
+
tenant_id: number;
|
|
110
|
+
request_id: number;
|
|
111
|
+
};
|
|
112
|
+
name: string;
|
|
113
|
+
unique: boolean;
|
|
114
|
+
} | {
|
|
115
|
+
key: {
|
|
116
|
+
tenant_id: number;
|
|
117
|
+
localDate: number;
|
|
118
|
+
action: number;
|
|
119
|
+
};
|
|
120
|
+
name: string;
|
|
121
|
+
unique?: undefined;
|
|
122
|
+
} | {
|
|
123
|
+
key: {
|
|
124
|
+
tenant_id: number;
|
|
125
|
+
phone_number: number;
|
|
126
|
+
createdAt: number;
|
|
127
|
+
};
|
|
128
|
+
name: string;
|
|
129
|
+
unique?: undefined;
|
|
130
|
+
})[];
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TENANT_DIALER_EVENTS_INDEX_OPTIONS = exports.TENANT_DIALER_EVENTS_COLLECTION_INDEXES = exports.TENANT_DIALER_EVENTS_COLLECTION_NAME = exports.TenantDialerEventSchema = exports.TENANT_DIALER_EVENTS_SCHEMA_VERSION = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const common_models_1 = require("./common-models");
|
|
7
|
+
/**
|
|
8
|
+
* Shape version of a `tenant_dialer_events` row. Bump only with a migration
|
|
9
|
+
* for already-stored source events.
|
|
10
|
+
*/
|
|
11
|
+
exports.TENANT_DIALER_EVENTS_SCHEMA_VERSION = 1;
|
|
12
|
+
/**
|
|
13
|
+
* The shared `LocalTimeFieldsSchema` is required for every other model. The
|
|
14
|
+
* dialer source stream is the one place local fields are OPTIONAL: when the
|
|
15
|
+
* running business day is unavailable the event is still stored, un-attributed
|
|
16
|
+
* and WITHOUT any local-time field. Derive an optional copy locally instead of
|
|
17
|
+
* weakening the shared schema.
|
|
18
|
+
*/
|
|
19
|
+
const OptionalLocalTimeFieldsSchema = Object.fromEntries(Object.entries(common_models_1.LocalTimeFieldsSchema).map(([field, definition]) => [field, { ...definition, required: false }]));
|
|
20
|
+
/**
|
|
21
|
+
* APPEND-ONLY source event stream for the future Dialer materialized report.
|
|
22
|
+
* Rows are written by items-service with
|
|
23
|
+
* `findOneAndUpdate({ tenant_id, request_id }, { $setOnInsert }, { upsert: true })`,
|
|
24
|
+
* so a retried request returns the ORIGINAL row and never rewrites
|
|
25
|
+
* `createdAt`, the local-time fields or any other stored value. No report
|
|
26
|
+
* fields (for example duration) live here.
|
|
27
|
+
*/
|
|
28
|
+
exports.TenantDialerEventSchema = new mongoose_1.Schema({
|
|
29
|
+
_id: {
|
|
30
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
31
|
+
required: true,
|
|
32
|
+
immutable: true,
|
|
33
|
+
},
|
|
34
|
+
tenant_id: {
|
|
35
|
+
type: String,
|
|
36
|
+
required: true,
|
|
37
|
+
immutable: true,
|
|
38
|
+
ref: 'tenants',
|
|
39
|
+
},
|
|
40
|
+
request_id: {
|
|
41
|
+
type: String,
|
|
42
|
+
required: true,
|
|
43
|
+
immutable: true,
|
|
44
|
+
},
|
|
45
|
+
action: {
|
|
46
|
+
type: String,
|
|
47
|
+
enum: constants_1.ALL_DIALER_TYPE_EVENTS,
|
|
48
|
+
required: true,
|
|
49
|
+
immutable: true,
|
|
50
|
+
},
|
|
51
|
+
phone_number: {
|
|
52
|
+
type: String,
|
|
53
|
+
required: true,
|
|
54
|
+
immutable: true,
|
|
55
|
+
},
|
|
56
|
+
pos_id: {
|
|
57
|
+
type: String,
|
|
58
|
+
required: true,
|
|
59
|
+
immutable: true,
|
|
60
|
+
},
|
|
61
|
+
staff_id: {
|
|
62
|
+
type: String,
|
|
63
|
+
required: false,
|
|
64
|
+
default: null,
|
|
65
|
+
immutable: true,
|
|
66
|
+
},
|
|
67
|
+
staff_phone: {
|
|
68
|
+
type: String,
|
|
69
|
+
required: false,
|
|
70
|
+
default: null,
|
|
71
|
+
immutable: true,
|
|
72
|
+
},
|
|
73
|
+
schema_version: {
|
|
74
|
+
type: Number,
|
|
75
|
+
required: true,
|
|
76
|
+
enum: [exports.TENANT_DIALER_EVENTS_SCHEMA_VERSION],
|
|
77
|
+
default: exports.TENANT_DIALER_EVENTS_SCHEMA_VERSION,
|
|
78
|
+
immutable: true,
|
|
79
|
+
},
|
|
80
|
+
...OptionalLocalTimeFieldsSchema,
|
|
81
|
+
createdAt: {
|
|
82
|
+
type: mongoose_1.Schema.Types.Date,
|
|
83
|
+
required: true,
|
|
84
|
+
default: () => new Date(),
|
|
85
|
+
immutable: true,
|
|
86
|
+
},
|
|
87
|
+
updatedAt: {
|
|
88
|
+
type: mongoose_1.Schema.Types.Date,
|
|
89
|
+
required: true,
|
|
90
|
+
default: () => new Date(),
|
|
91
|
+
},
|
|
92
|
+
}, {
|
|
93
|
+
timestamps: true,
|
|
94
|
+
versionKey: false,
|
|
95
|
+
minimize: false,
|
|
96
|
+
});
|
|
97
|
+
exports.TENANT_DIALER_EVENTS_COLLECTION_NAME = 'tenant_dialer_events';
|
|
98
|
+
/**
|
|
99
|
+
* Describes the indexes for `tenant_dialer_events`. Values are Mongo key
|
|
100
|
+
* patterns that can be passed straight to `.hint()`.
|
|
101
|
+
* - `_id`: unique primary key.
|
|
102
|
+
* - `tenant_id__request_id`: UNIQUE idempotency key — one source event per
|
|
103
|
+
* tenant + request (native: `callId:action`, JS: UUID reused on retry).
|
|
104
|
+
* - `tenant_id__localDate__action`: future report reads per business day and
|
|
105
|
+
* action. Local fields may be absent for un-attributed events, so reads must
|
|
106
|
+
* tolerate a missing `localDate` (sparse-aware querying, not a partial
|
|
107
|
+
* index requirement).
|
|
108
|
+
* - `tenant_id__phone_number__createdAt`: future pairing/attribution reads for
|
|
109
|
+
* one caller phone ordered by the canonical receipt time.
|
|
110
|
+
*/
|
|
111
|
+
exports.TENANT_DIALER_EVENTS_COLLECTION_INDEXES = {
|
|
112
|
+
_id: { _id: 1 }, // Unique Index
|
|
113
|
+
tenant_id__request_id: { tenant_id: 1, request_id: 1 }, // Unique Index — ingestion idempotency
|
|
114
|
+
tenant_id__localDate__action: { tenant_id: 1, localDate: 1, action: 1 }, // per business day + action
|
|
115
|
+
tenant_id__phone_number__createdAt: { tenant_id: 1, phone_number: 1, createdAt: 1 }, // per caller phone over time
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Index OPTIONS to DECLARE (never created at application startup). The
|
|
119
|
+
* materializer/ops path owns creation; `tenant_id__request_id` MUST be created
|
|
120
|
+
* with `unique: true` or concurrent retries could insert a second event.
|
|
121
|
+
*/
|
|
122
|
+
exports.TENANT_DIALER_EVENTS_INDEX_OPTIONS = [
|
|
123
|
+
{
|
|
124
|
+
key: exports.TENANT_DIALER_EVENTS_COLLECTION_INDEXES.tenant_id__request_id,
|
|
125
|
+
name: 'tenant_id__request_id',
|
|
126
|
+
unique: true,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
key: exports.TENANT_DIALER_EVENTS_COLLECTION_INDEXES.tenant_id__localDate__action,
|
|
130
|
+
name: 'tenant_id__localDate__action',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
key: exports.TENANT_DIALER_EVENTS_COLLECTION_INDEXES.tenant_id__phone_number__createdAt,
|
|
134
|
+
name: 'tenant_id__phone_number__createdAt',
|
|
135
|
+
},
|
|
136
|
+
];
|
|
@@ -13,9 +13,9 @@ export declare const WarehouseActivityLogSchema: Schema<any, import("mongoose").
|
|
|
13
13
|
updatedAt: NativeDate;
|
|
14
14
|
title: string;
|
|
15
15
|
warehouse_id: string;
|
|
16
|
+
action: import("../../constants").WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM;
|
|
16
17
|
entity_type: import("../../constants").WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_ENUM;
|
|
17
18
|
entity_id: string;
|
|
18
|
-
action: import("../../constants").WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM;
|
|
19
19
|
severity: WAREHOUSE_ACTIVITY_LOG_SEVERITY_ENUM;
|
|
20
20
|
changes: import("mongoose").Types.DocumentArray<{
|
|
21
21
|
field: string;
|
|
@@ -49,9 +49,9 @@ export declare const WarehouseActivityLogSchema: Schema<any, import("mongoose").
|
|
|
49
49
|
updatedAt: NativeDate;
|
|
50
50
|
title: string;
|
|
51
51
|
warehouse_id: string;
|
|
52
|
+
action: import("../../constants").WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM;
|
|
52
53
|
entity_type: import("../../constants").WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_ENUM;
|
|
53
54
|
entity_id: string;
|
|
54
|
-
action: import("../../constants").WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM;
|
|
55
55
|
severity: WAREHOUSE_ACTIVITY_LOG_SEVERITY_ENUM;
|
|
56
56
|
changes: import("mongoose").Types.DocumentArray<{
|
|
57
57
|
field: string;
|
|
@@ -85,9 +85,9 @@ export declare const WarehouseActivityLogSchema: Schema<any, import("mongoose").
|
|
|
85
85
|
updatedAt: NativeDate;
|
|
86
86
|
title: string;
|
|
87
87
|
warehouse_id: string;
|
|
88
|
+
action: import("../../constants").WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM;
|
|
88
89
|
entity_type: import("../../constants").WAREHOUSE_ACTIVITY_LOG_ENTITY_TYPE_ENUM;
|
|
89
90
|
entity_id: string;
|
|
90
|
-
action: import("../../constants").WAREHOUSE_ACTIVITY_LOG_ACTION_ENUM;
|
|
91
91
|
severity: WAREHOUSE_ACTIVITY_LOG_SEVERITY_ENUM;
|
|
92
92
|
changes: import("mongoose").Types.DocumentArray<{
|
|
93
93
|
field: string;
|
|
@@ -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';
|
|
@@ -77,6 +79,7 @@ export * from './tenant_cash_in_out';
|
|
|
77
79
|
export * from './tenant_chart_of_accounts';
|
|
78
80
|
export * from './tenant_clients';
|
|
79
81
|
export * from './tenant_day_sessions';
|
|
82
|
+
export * from './tenant_dialer_events';
|
|
80
83
|
export * from './tenant_hr_attendance_records';
|
|
81
84
|
export * from './tenant_hr_biometric_enrollments';
|
|
82
85
|
export * from './tenant_hr_departments';
|
|
@@ -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);
|
|
@@ -93,6 +95,7 @@ __exportStar(require("./tenant_cash_in_out"), exports);
|
|
|
93
95
|
__exportStar(require("./tenant_chart_of_accounts"), exports);
|
|
94
96
|
__exportStar(require("./tenant_clients"), exports);
|
|
95
97
|
__exportStar(require("./tenant_day_sessions"), exports);
|
|
98
|
+
__exportStar(require("./tenant_dialer_events"), exports);
|
|
96
99
|
__exportStar(require("./tenant_hr_attendance_records"), exports);
|
|
97
100
|
__exportStar(require("./tenant_hr_biometric_enrollments"), exports);
|
|
98
101
|
__exportStar(require("./tenant_hr_departments"), 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,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
|
+
];
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DIALER_TYPES_ENUM } from '../../constants';
|
|
2
|
+
import { ILocalTimeFields } from '../../helpers';
|
|
3
|
+
/**
|
|
4
|
+
* One raw dialer event (`tenant_dialer_events`) — an APPEND-ONLY source event
|
|
5
|
+
* from the POS dialer, kept so a future Dialer materialized report can derive
|
|
6
|
+
* call duration / success rate from event pairs for the same phone number.
|
|
7
|
+
*
|
|
8
|
+
* This is a SOURCE collection, not a materialized report:
|
|
9
|
+
* - `request_id` is the dialer's idempotency key (native: `callId:action`,
|
|
10
|
+
* JS: a UUID reused for the retry); `(tenant_id, request_id)` is UNIQUE.
|
|
11
|
+
* - `createdAt` is the canonical event receipt time. There is no separate
|
|
12
|
+
* `received_at` field and no fallback business-day flag.
|
|
13
|
+
* - Local-time fields are OPTIONAL: they are populated only when
|
|
14
|
+
* `track_order_numbers.runningLocalDate` is a valid running business day and
|
|
15
|
+
* the tenant operational offset is usable. A missing/invalid running day is
|
|
16
|
+
* a valid un-attributed event (no local fields, never a fabricated
|
|
17
|
+
* `localDate`); a future materializer treats it as un-attributed.
|
|
18
|
+
*
|
|
19
|
+
* Duration is NOT stored here — it will be derived later from
|
|
20
|
+
* INCOMING_CALL -> CALL_ENDED / CALL_DECLINED / MISSED_CALL pairs for the same
|
|
21
|
+
* tenant + phone number.
|
|
22
|
+
*/
|
|
23
|
+
export interface ITenantDialerEvent extends Partial<ILocalTimeFields> {
|
|
24
|
+
_id: string;
|
|
25
|
+
tenant_id: string;
|
|
26
|
+
request_id: string;
|
|
27
|
+
action: DIALER_TYPES_ENUM;
|
|
28
|
+
phone_number: string;
|
|
29
|
+
pos_id: string;
|
|
30
|
+
staff_id: string | null;
|
|
31
|
+
staff_phone: string | null;
|
|
32
|
+
schema_version: 1;
|
|
33
|
+
createdAt: Date;
|
|
34
|
+
updatedAt: Date;
|
|
35
|
+
}
|