@managesome/eposmatic-toolkit 0.4.53 → 0.4.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/helpers/materialized-reports/index.js +1 -0
- package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +18 -0
- package/esm/helpers/materialized-reports/report-platform/definition.js +508 -0
- package/esm/helpers/materialized-reports/report-platform/index.js +4 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/budget.js +27 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +12 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +121 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +14 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/index.js +8 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +10 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +42 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +28 -0
- package/esm/helpers/materialized-reports/report-platform/lifecycle/top-n.js +24 -0
- package/esm/helpers/materialized-reports/report-platform/registry.js +23 -0
- package/esm/helpers/materialized-reports/report-platform/validate-report-registry.js +214 -0
- package/esm/schemas/models/index.js +1 -0
- package/esm/schemas/models/tenant_dialer_events.js +133 -0
- package/esm/schemas/types/index.js +1 -0
- package/esm/schemas/types/tenant_dialer_events.js +1 -0
- package/lib/helpers/materialized-reports/index.d.ts +1 -0
- package/lib/helpers/materialized-reports/index.js +1 -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/report-platform/definition.d.ts +133 -0
- package/lib/helpers/materialized-reports/report-platform/definition.js +511 -0
- package/lib/helpers/materialized-reports/report-platform/index.d.ts +4 -0
- package/lib/helpers/materialized-reports/report-platform/index.js +20 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/budget.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/cap-metadata.js +16 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.d.ts +40 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/entry-pages.js +130 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.d.ts +22 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/flat-projection.js +17 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/index.d.ts +8 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/index.js +24 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/iteration-row.js +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.d.ts +20 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/run-stats.js +47 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/scope-refs.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.d.ts +16 -0
- package/lib/helpers/materialized-reports/report-platform/lifecycle/top-n.js +29 -0
- package/lib/helpers/materialized-reports/report-platform/registry.d.ts +13 -0
- package/lib/helpers/materialized-reports/report-platform/registry.js +31 -0
- package/lib/helpers/materialized-reports/report-platform/validate-report-registry.d.ts +20 -0
- package/lib/helpers/materialized-reports/report-platform/validate-report-registry.js +218 -0
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -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 +1 -0
- package/lib/schemas/types/index.js +1 -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/characterization/delivery.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/delivery.characterization.test.js +229 -0
- package/lib/tests/materialized-reports/characterization/discount.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/discount.characterization.test.js +99 -0
- package/lib/tests/materialized-reports/characterization/fixtures.d.ts +30 -0
- package/lib/tests/materialized-reports/characterization/fixtures.js +402 -0
- package/lib/tests/materialized-reports/characterization/golden.d.ts +18 -0
- package/lib/tests/materialized-reports/characterization/golden.js +127 -0
- package/lib/tests/materialized-reports/characterization/overview.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/overview.characterization.test.js +69 -0
- package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.d.ts +1 -0
- package/lib/tests/materialized-reports/characterization/prep-time.characterization.test.js +102 -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/lifecycle-primitives.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/lifecycle-primitives.test.js +177 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +214 -0
- package/lib/tests/materialized-reports/report-platform/registry-validation.test.d.ts +1 -0
- package/lib/tests/materialized-reports/report-platform/registry-validation.test.js +103 -0
- 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 +4 -2
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REPORT_REGISTRY_VALIDATION = void 0;
|
|
4
|
+
exports.validateReportRegistry = validateReportRegistry;
|
|
5
|
+
const MATERIALIZED_REPORTS_1 = require("../../../constants/MATERIALIZED_REPORTS");
|
|
6
|
+
const report_contract_1 = require("../../reporting-contract/report-contract");
|
|
7
|
+
const definition_1 = require("./definition");
|
|
8
|
+
const MATERIALIZED_PREFIX = 'materialized_';
|
|
9
|
+
const isPositiveInteger = (value) => typeof value === 'number' && Number.isInteger(value) && value > 0;
|
|
10
|
+
const isNonEmptyString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
11
|
+
function validateCollection(definition, label, collection, errors, warnings) {
|
|
12
|
+
if (!isNonEmptyString(collection.name)) {
|
|
13
|
+
errors.push(`${definition.key}: ${label} has no collection name`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (!collection.name.startsWith(MATERIALIZED_PREFIX)) {
|
|
17
|
+
errors.push(`${definition.key}: ${label} collection "${collection.name}" is not a materialized_* collection`);
|
|
18
|
+
}
|
|
19
|
+
if (!isPositiveInteger(collection.schemaVersion)) {
|
|
20
|
+
errors.push(`${definition.key}: ${label} has no positive schema version`);
|
|
21
|
+
}
|
|
22
|
+
if (!isPositiveInteger(collection.budgetBytes)) {
|
|
23
|
+
errors.push(`${definition.key}: ${label} has no positive budget`);
|
|
24
|
+
}
|
|
25
|
+
if (!isNonEmptyString(collection.indexOwner)) {
|
|
26
|
+
errors.push(`${definition.key}: ${label} has no index ownership`);
|
|
27
|
+
}
|
|
28
|
+
if (collection.validatorFile == null && !isNonEmptyString(collection.validatorDebt)) {
|
|
29
|
+
errors.push(`${definition.key}: ${label} has neither a validator file nor a declared validator debt`);
|
|
30
|
+
}
|
|
31
|
+
if (collection.validatorFile == null && isNonEmptyString(collection.validatorDebt)) {
|
|
32
|
+
warnings.push(`${definition.key}: ${label} validator debt: ${collection.validatorDebt}`);
|
|
33
|
+
}
|
|
34
|
+
if (definition.budgets[collection.name] == null || !isPositiveInteger(definition.budgets[collection.name])) {
|
|
35
|
+
errors.push(`${definition.key}: collection "${collection.name}" has no budget declaration in budgets`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function validateScopes(definition, label, scopes, errors) {
|
|
39
|
+
if (scopes.length === 0) {
|
|
40
|
+
errors.push(`${definition.key}: ${label} has no scopes`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const seen = new Set();
|
|
44
|
+
for (const scope of scopes) {
|
|
45
|
+
if (!MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_SCOPES.includes(scope)) {
|
|
46
|
+
errors.push(`${definition.key}: ${label} has unknown scope "${String(scope)}"`);
|
|
47
|
+
}
|
|
48
|
+
if (seen.has(String(scope))) {
|
|
49
|
+
errors.push(`${definition.key}: ${label} repeats scope "${String(scope)}"`);
|
|
50
|
+
}
|
|
51
|
+
seen.add(String(scope));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function validateReportRegistry(input = {}) {
|
|
55
|
+
const definitions = input.definitions ?? definition_1.REPORT_DEFINITIONS;
|
|
56
|
+
const exemptions = input.exemptions ?? definition_1.REPORT_REGISTRY_EXEMPTIONS;
|
|
57
|
+
const keys = input.keys ?? report_contract_1.ALL_REPORT_KEYS;
|
|
58
|
+
const errors = [];
|
|
59
|
+
const warnings = [];
|
|
60
|
+
for (const key of keys) {
|
|
61
|
+
const definition = definitions[key];
|
|
62
|
+
const exemption = exemptions[key];
|
|
63
|
+
if (definition == null && exemption == null) {
|
|
64
|
+
errors.push(`${key}: no report definition and no explicit exemption`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (definition != null && exemption != null) {
|
|
68
|
+
errors.push(`${key}: both a report definition and an exemption exist`);
|
|
69
|
+
}
|
|
70
|
+
if (definition == null)
|
|
71
|
+
continue;
|
|
72
|
+
if (definition.key !== key) {
|
|
73
|
+
errors.push(`${key}: definition key is "${definition.key}"`);
|
|
74
|
+
}
|
|
75
|
+
if (definition.status !== definition_1.REPORT_DEFINITION_STATUS.PRODUCTION &&
|
|
76
|
+
definition.status !== definition_1.REPORT_DEFINITION_STATUS.READ_ONLY) {
|
|
77
|
+
errors.push(`${key}: a concrete definition must be PRODUCTION or READ_ONLY`);
|
|
78
|
+
}
|
|
79
|
+
if (!isNonEmptyString(definition.owner))
|
|
80
|
+
errors.push(`${key}: no owner`);
|
|
81
|
+
if (!MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_TYPES.includes(definition.reportType)) {
|
|
82
|
+
errors.push(`${key}: unknown report type "${String(definition.reportType)}"`);
|
|
83
|
+
}
|
|
84
|
+
if (definition.segment !== report_contract_1.REPORT_ROUTE_SEGMENTS[definition.key]) {
|
|
85
|
+
errors.push(`${key}: segment "${definition.segment}" disagrees with REPORT_ROUTE_SEGMENTS`);
|
|
86
|
+
}
|
|
87
|
+
const expectedCapabilities = report_contract_1.REPORT_CAPABILITIES[definition.key];
|
|
88
|
+
if (expectedCapabilities == null ||
|
|
89
|
+
expectedCapabilities.live !== definition.capabilities.live ||
|
|
90
|
+
expectedCapabilities.historical !== definition.capabilities.historical ||
|
|
91
|
+
expectedCapabilities.details !== definition.capabilities.details) {
|
|
92
|
+
errors.push(`${key}: capabilities disagree with REPORT_CAPABILITIES`);
|
|
93
|
+
}
|
|
94
|
+
validateCollection(definition, 'report', definition.report, errors, warnings);
|
|
95
|
+
if (definition.entries != null) {
|
|
96
|
+
validateCollection(definition, 'entries', definition.entries, errors, warnings);
|
|
97
|
+
}
|
|
98
|
+
for (const side of definition.sideCollections) {
|
|
99
|
+
validateCollection(definition, 'side', side, errors, warnings);
|
|
100
|
+
}
|
|
101
|
+
const allCollections = [
|
|
102
|
+
definition.report,
|
|
103
|
+
...(definition.entries == null ? [] : [definition.entries]),
|
|
104
|
+
...definition.sideCollections,
|
|
105
|
+
].map((collection) => collection.name);
|
|
106
|
+
for (const collectionName of Object.keys(definition.budgets)) {
|
|
107
|
+
if (!allCollections.includes(collectionName)) {
|
|
108
|
+
warnings.push(`${key}: budget declared for unknown collection "${collectionName}"`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
validateScopes(definition, 'reportScopes', definition.reportScopes, errors);
|
|
112
|
+
if (definition.entryScopes.length > 0 || definition.entryStorage !== definition_1.REPORT_ENTRY_STORAGE.NONE) {
|
|
113
|
+
validateScopes(definition, 'entryScopes', definition.entryScopes, errors);
|
|
114
|
+
}
|
|
115
|
+
if (!definition.reportScopes.includes(definition.maxReportScope)) {
|
|
116
|
+
errors.push(`${key}: maxReportScope is not a declared report scope`);
|
|
117
|
+
}
|
|
118
|
+
if (definition.maxEntryScope != null && !definition.entryScopes.includes(definition.maxEntryScope)) {
|
|
119
|
+
errors.push(`${key}: maxEntryScope is not a declared entry scope`);
|
|
120
|
+
}
|
|
121
|
+
for (const scope of definition.entryScopes) {
|
|
122
|
+
if (!definition.reportScopes.includes(scope)) {
|
|
123
|
+
errors.push(`${key}: entry scope "${scope}" is outside reportScopes`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (definition.entryStorage === definition_1.REPORT_ENTRY_STORAGE.NONE) {
|
|
127
|
+
if (definition.entries != null) {
|
|
128
|
+
errors.push(`${key}: entryStorage NONE must not declare an entry collection`);
|
|
129
|
+
}
|
|
130
|
+
if (definition.entryScopes.length !== 0) {
|
|
131
|
+
errors.push(`${key}: entryStorage NONE must not declare entry scopes`);
|
|
132
|
+
}
|
|
133
|
+
if (definition.entrySplit !== definition_1.REPORT_ENTRY_SPLIT.NONE) {
|
|
134
|
+
errors.push(`${key}: entryStorage NONE must not split pages`);
|
|
135
|
+
}
|
|
136
|
+
if (definition.maxEntryScope != null) {
|
|
137
|
+
errors.push(`${key}: entryStorage NONE must not declare maxEntryScope`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
if (definition.entries == null) {
|
|
142
|
+
errors.push(`${key}: entry storage requires an entry collection`);
|
|
143
|
+
}
|
|
144
|
+
if (definition.entryScopes.length === 0) {
|
|
145
|
+
errors.push(`${key}: entry storage requires entry scopes`);
|
|
146
|
+
}
|
|
147
|
+
if (definition.maxEntryScope == null) {
|
|
148
|
+
errors.push(`${key}: entry storage requires maxEntryScope`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (definition.entrySplit === definition_1.REPORT_ENTRY_SPLIT.DETERMINISTIC_SUBPAGES &&
|
|
152
|
+
definition.entryStorage !== definition_1.REPORT_ENTRY_STORAGE.PAGE_PER_SOURCE_DAY) {
|
|
153
|
+
errors.push(`${key}: #N splitting requires page-per-source-day entries`);
|
|
154
|
+
}
|
|
155
|
+
if (definition.projections.includes(definition_1.REPORT_PROJECTION.FLAT_DRILLDOWN)) {
|
|
156
|
+
const names = definition.sideCollections.map((collection) => collection.name);
|
|
157
|
+
if (!names.includes('materialized_report_drilldown_rows') ||
|
|
158
|
+
!names.includes('materialized_report_drilldown_scopes')) {
|
|
159
|
+
errors.push(`${key}: FLAT_DRILLDOWN requires both flat collections`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (definition.projections.includes(definition_1.REPORT_PROJECTION.DISCOUNT_SOURCES) &&
|
|
163
|
+
!definition.sideCollections.some((collection) => collection.name === 'materialized_tenant_discount_sources')) {
|
|
164
|
+
errors.push(`${key}: DISCOUNT_SOURCES requires the source collection`);
|
|
165
|
+
}
|
|
166
|
+
if (definition.projections.includes(definition_1.REPORT_PROJECTION.DELIVERY_GEO)) {
|
|
167
|
+
const names = definition.sideCollections.map((collection) => collection.name);
|
|
168
|
+
if (!names.includes('materialized_tenant_delivery_geo_cells') ||
|
|
169
|
+
!names.includes('materialized_tenant_delivery_geo_scopes')) {
|
|
170
|
+
errors.push(`${key}: DELIVERY_GEO requires cells + cap metadata`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (definition.capabilities.details &&
|
|
174
|
+
(definition.adapters.details == null || !isNonEmptyString(definition.adapters.details))) {
|
|
175
|
+
errors.push(`${key}: capabilities.details is true but no details adapter is declared`);
|
|
176
|
+
}
|
|
177
|
+
if (!definition.capabilities.details && definition.adapters.details != null) {
|
|
178
|
+
errors.push(`${key}: details adapter declared without details capability`);
|
|
179
|
+
}
|
|
180
|
+
if (!isNonEmptyString(definition.adapters.writer))
|
|
181
|
+
errors.push(`${key}: no writer adapter`);
|
|
182
|
+
if (!isNonEmptyString(definition.adapters.live))
|
|
183
|
+
errors.push(`${key}: no live adapter`);
|
|
184
|
+
if (!isNonEmptyString(definition.adapters.historical)) {
|
|
185
|
+
errors.push(`${key}: no historical adapter`);
|
|
186
|
+
}
|
|
187
|
+
if (definition.completeness.details === 'FLAT_PROJECTION' &&
|
|
188
|
+
!definition.projections.includes(definition_1.REPORT_PROJECTION.FLAT_DRILLDOWN)) {
|
|
189
|
+
errors.push(`${key}: details completeness requires the flat projection`);
|
|
190
|
+
}
|
|
191
|
+
if (definition.filters.length === 0) {
|
|
192
|
+
errors.push(`${key}: no filter definitions`);
|
|
193
|
+
}
|
|
194
|
+
for (const filter of definition.filters) {
|
|
195
|
+
if (!isNonEmptyString(filter.id))
|
|
196
|
+
errors.push(`${key}: filter without an id`);
|
|
197
|
+
if (filter.mode !== 'CLIENT' && filter.mode !== 'SERVER') {
|
|
198
|
+
errors.push(`${key}: filter "${filter.id}" has an invalid mode`);
|
|
199
|
+
}
|
|
200
|
+
if (!['SUMMARY', 'DETAILS', 'BOTH'].includes(filter.appliesTo)) {
|
|
201
|
+
errors.push(`${key}: filter "${filter.id}" has an invalid appliesTo`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (definition.capabilities.details && definition.cursor === 'NONE') {
|
|
205
|
+
warnings.push(`${key}: details capability but cursor NONE`);
|
|
206
|
+
}
|
|
207
|
+
for (const rule of definition.retention) {
|
|
208
|
+
if (!allCollections.includes(rule.collection)) {
|
|
209
|
+
errors.push(`${key}: retention targets an unknown collection "${rule.collection}"`);
|
|
210
|
+
}
|
|
211
|
+
if (!isPositiveInteger(rule.amount)) {
|
|
212
|
+
errors.push(`${key}: retention amount must be a positive integer`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return { ok: errors.length === 0, errors, warnings };
|
|
217
|
+
}
|
|
218
|
+
exports.REPORT_REGISTRY_VALIDATION = validateReportRegistry();
|
|
@@ -72,6 +72,7 @@ export * from './tenant_cash_in_out';
|
|
|
72
72
|
export * from './tenant_chart_of_accounts';
|
|
73
73
|
export * from './tenant_clients';
|
|
74
74
|
export * from './tenant_day_sessions';
|
|
75
|
+
export * from './tenant_dialer_events';
|
|
75
76
|
export * from './tenant_hr_attendance_records';
|
|
76
77
|
export * from './tenant_hr_biometric_enrollments';
|
|
77
78
|
export * from './tenant_hr_departments';
|
|
@@ -88,6 +88,7 @@ __exportStar(require("./tenant_cash_in_out"), exports);
|
|
|
88
88
|
__exportStar(require("./tenant_chart_of_accounts"), exports);
|
|
89
89
|
__exportStar(require("./tenant_clients"), exports);
|
|
90
90
|
__exportStar(require("./tenant_day_sessions"), exports);
|
|
91
|
+
__exportStar(require("./tenant_dialer_events"), exports);
|
|
91
92
|
__exportStar(require("./tenant_hr_attendance_records"), exports);
|
|
92
93
|
__exportStar(require("./tenant_hr_biometric_enrollments"), exports);
|
|
93
94
|
__exportStar(require("./tenant_hr_departments"), exports);
|
|
@@ -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
|
+
request_id: string;
|
|
31
|
+
action: import("../../constants").DIALER_TYPES_ENUM;
|
|
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
|
+
request_id: string;
|
|
46
|
+
action: import("../../constants").DIALER_TYPES_ENUM;
|
|
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
|
+
request_id: string;
|
|
61
|
+
action: import("../../constants").DIALER_TYPES_ENUM;
|
|
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;
|
|
@@ -77,6 +77,7 @@ export * from './tenant_cash_in_out';
|
|
|
77
77
|
export * from './tenant_chart_of_accounts';
|
|
78
78
|
export * from './tenant_clients';
|
|
79
79
|
export * from './tenant_day_sessions';
|
|
80
|
+
export * from './tenant_dialer_events';
|
|
80
81
|
export * from './tenant_hr_attendance_records';
|
|
81
82
|
export * from './tenant_hr_biometric_enrollments';
|
|
82
83
|
export * from './tenant_hr_departments';
|
|
@@ -93,6 +93,7 @@ __exportStar(require("./tenant_cash_in_out"), exports);
|
|
|
93
93
|
__exportStar(require("./tenant_chart_of_accounts"), exports);
|
|
94
94
|
__exportStar(require("./tenant_clients"), exports);
|
|
95
95
|
__exportStar(require("./tenant_day_sessions"), exports);
|
|
96
|
+
__exportStar(require("./tenant_dialer_events"), exports);
|
|
96
97
|
__exportStar(require("./tenant_hr_attendance_records"), exports);
|
|
97
98
|
__exportStar(require("./tenant_hr_biometric_enrollments"), exports);
|
|
98
99
|
__exportStar(require("./tenant_hr_departments"), exports);
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|