@managesome/eposmatic-toolkit 0.4.60 → 0.4.62
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 +254 -4
- package/esm/constants/TENANT_ENUMS.js +15 -0
- package/esm/constants/WORKER_ENDPOINTS.js +12 -0
- package/esm/helpers/materialized-reports/index.js +8 -0
- package/esm/helpers/materialized-reports/materialized-day-readiness.js +2 -2
- package/esm/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +557 -0
- package/esm/helpers/materialized-reports/materialized-dinein-classification-helpers.js +447 -0
- package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +372 -0
- package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +500 -0
- package/esm/helpers/materialized-reports/materialized-dinein-entry-pages.js +218 -0
- package/esm/helpers/materialized-reports/materialized-dinein-key-helpers.js +87 -0
- package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +7 -1
- package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
- package/esm/helpers/materialized-reports/materialized-report-runs.js +143 -0
- package/esm/helpers/materialized-reports/report-platform/definition.js +93 -1
- package/esm/helpers/materialized-reports/tenant-dinein-formatter.js +240 -0
- package/esm/helpers/reporting-contract/report-contract.js +3 -0
- package/esm/schemas/models/index.js +3 -0
- package/esm/schemas/models/materialized_tenant_dinein_entries.js +57 -0
- package/esm/schemas/models/materialized_tenant_dinein_reports.js +73 -0
- package/esm/schemas/models/materialized_tenant_report_runs.js +105 -0
- package/esm/schemas/models/tenant_active_jobs.js +19 -1
- 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_dinein_entries.js +1 -0
- package/esm/schemas/types/materialized_tenant_dinein_reports.js +6 -0
- package/esm/schemas/types/materialized_tenant_report_runs.js +1 -0
- package/lib/constants/MATERIALIZED_REPORTS.d.ts +229 -4
- package/lib/constants/MATERIALIZED_REPORTS.js +255 -5
- package/lib/constants/TENANT_ENUMS.d.ts +14 -0
- package/lib/constants/TENANT_ENUMS.js +16 -1
- package/lib/constants/WORKER_ENDPOINTS.d.ts +12 -0
- package/lib/constants/WORKER_ENDPOINTS.js +12 -0
- package/lib/helpers/materialized-reports/index.d.ts +8 -0
- package/lib/helpers/materialized-reports/index.js +8 -0
- package/lib/helpers/materialized-reports/materialized-day-readiness.d.ts +1 -1
- package/lib/helpers/materialized-reports/materialized-day-readiness.js +2 -2
- package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.d.ts +67 -0
- package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +582 -0
- package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.d.ts +245 -0
- package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.js +469 -0
- package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.d.ts +110 -0
- package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +384 -0
- package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.d.ts +73 -0
- package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +504 -0
- package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.d.ts +69 -0
- package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.js +231 -0
- package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.d.ts +44 -0
- package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.js +96 -0
- package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +6 -0
- package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
- package/lib/helpers/materialized-reports/materialized-report-runs.d.ts +105 -0
- package/lib/helpers/materialized-reports/materialized-report-runs.js +156 -0
- package/lib/helpers/materialized-reports/report-platform/definition.js +92 -0
- package/lib/helpers/materialized-reports/tenant-dinein-formatter.d.ts +225 -0
- package/lib/helpers/materialized-reports/tenant-dinein-formatter.js +243 -0
- package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
- package/lib/helpers/reporting-contract/report-contract.js +3 -0
- package/lib/helpers/types/workers.d.ts +65 -0
- package/lib/schemas/models/index.d.ts +3 -0
- package/lib/schemas/models/index.js +3 -0
- package/lib/schemas/models/materialized_tenant_day_readiness.d.ts +3 -3
- package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +100 -0
- package/lib/schemas/models/materialized_tenant_dinein_entries.js +60 -0
- package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +111 -0
- package/lib/schemas/models/materialized_tenant_dinein_reports.js +76 -0
- package/lib/schemas/models/materialized_tenant_report_runs.d.ts +97 -0
- package/lib/schemas/models/materialized_tenant_report_runs.js +108 -0
- package/lib/schemas/models/tenant_active_jobs.d.ts +12 -3
- package/lib/schemas/models/tenant_active_jobs.js +18 -0
- 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_dinein_entries.d.ts +127 -0
- package/lib/schemas/types/materialized_tenant_dinein_entries.js +2 -0
- package/lib/schemas/types/materialized_tenant_dinein_reports.d.ts +326 -0
- package/lib/schemas/types/materialized_tenant_dinein_reports.js +9 -0
- package/lib/schemas/types/materialized_tenant_report_runs.d.ts +55 -0
- package/lib/schemas/types/materialized_tenant_report_runs.js +2 -0
- package/lib/schemas/types/tenant_active_jobs.d.ts +15 -1
- package/lib/tests/materialized-reports/dinein-fixtures.d.ts +29 -0
- package/lib/tests/materialized-reports/dinein-fixtures.js +130 -0
- package/lib/tests/materialized-reports/materialized-day-readiness.test.js +3 -2
- package/lib/tests/materialized-reports/materialized-dinein-compile.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dinein-compile.test.js +807 -0
- package/lib/tests/materialized-reports/materialized-dinein-plan.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-dinein-plan.test.js +419 -0
- package/lib/tests/materialized-reports/materialized-report-runs.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-report-runs.test.js +116 -0
- package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.js +185 -0
- package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +15 -2
- package/lib/tests/materialized-reports/tenant-dinein-formatter.test.d.ts +1 -0
- package/lib/tests/materialized-reports/tenant-dinein-formatter.test.js +458 -0
- package/package.json +1 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.materializedReportRunKey = materializedReportRunKey;
|
|
4
|
+
exports.buildMaterializedReportRunFilter = buildMaterializedReportRunFilter;
|
|
5
|
+
exports.isMaterializedReportRunStatus = isMaterializedReportRunStatus;
|
|
6
|
+
exports.isMaterializedReportRunInFlight = isMaterializedReportRunInFlight;
|
|
7
|
+
exports.isMaterializedReportRunCommitOutcomeUnknown = isMaterializedReportRunCommitOutcomeUnknown;
|
|
8
|
+
exports.isMaterializedReadinessOwnedByRun = isMaterializedReadinessOwnedByRun;
|
|
9
|
+
exports.isMaterializedReportRunTerminal = isMaterializedReportRunTerminal;
|
|
10
|
+
exports.materializedReportRunStartedAt = materializedReportRunStartedAt;
|
|
11
|
+
exports.isMaterializedReportRunStale = isMaterializedReportRunStale;
|
|
12
|
+
exports.canRetryMaterializedReportRun = canRetryMaterializedReportRun;
|
|
13
|
+
exports.sanitizeMaterializedReportRunError = sanitizeMaterializedReportRunError;
|
|
14
|
+
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
15
|
+
/** Stable string key of one run row (Map keys / log correlation). */
|
|
16
|
+
function materializedReportRunKey(parts) {
|
|
17
|
+
return [
|
|
18
|
+
String(parts.tenantId),
|
|
19
|
+
String(parts.localDate),
|
|
20
|
+
String(parts.reportKey),
|
|
21
|
+
String(parts.schemaVersion ?? MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUNS_SCHEMA_VERSION),
|
|
22
|
+
].join('|');
|
|
23
|
+
}
|
|
24
|
+
/** The Mongo filter of the ONE run row of a report. */
|
|
25
|
+
function buildMaterializedReportRunFilter(parts) {
|
|
26
|
+
return {
|
|
27
|
+
tenant_id: String(parts.tenantId),
|
|
28
|
+
localDate: String(parts.localDate),
|
|
29
|
+
report_key: String(parts.reportKey),
|
|
30
|
+
schema_version: parts.schemaVersion ?? MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUNS_SCHEMA_VERSION,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function isMaterializedReportRunStatus(value) {
|
|
34
|
+
return Object.values(MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM).includes(value);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Is the report CURRENTLY being executed?
|
|
38
|
+
*
|
|
39
|
+
* Only a run that owns the report may be in this state; the retry API refuses
|
|
40
|
+
* it (409) instead of racing the executor.
|
|
41
|
+
*/
|
|
42
|
+
function isMaterializedReportRunInFlight(status) {
|
|
43
|
+
return (status === MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.PENDING ||
|
|
44
|
+
status === MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.RUNNING ||
|
|
45
|
+
status === MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.RETRYING);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Does this run carry the UNKNOWN-COMMIT marker?
|
|
49
|
+
*
|
|
50
|
+
* Such a run MUST stay non-terminal until recovery settles it from
|
|
51
|
+
* ownership-checked readiness (a ledger error alone must never decide it).
|
|
52
|
+
*/
|
|
53
|
+
function isMaterializedReportRunCommitOutcomeUnknown(run) {
|
|
54
|
+
return String(run?.last_error ?? '') === MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_RUN_COMMIT_OUTCOME_UNKNOWN_ERROR;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Proves that a readiness row belongs to the run that owns this report.
|
|
58
|
+
*
|
|
59
|
+
* The row identity is the tenant/day/report/schema; ownership is the RUN
|
|
60
|
+
* identity. A row written by an OLDER close/re-close carries a DIFFERENT
|
|
61
|
+
* `run_id` and therefore proves nothing about the current run: it must keep the
|
|
62
|
+
* old report readable while the current run is recorded as FAILED
|
|
63
|
+
* (`INTERRUPTED_RUN`) and stays retryable. Never delete that older row.
|
|
64
|
+
*/
|
|
65
|
+
function isMaterializedReadinessOwnedByRun(args) {
|
|
66
|
+
const readinessRun = args.readiness?.run_id;
|
|
67
|
+
const currentRun = args.run?.run_id;
|
|
68
|
+
return readinessRun != null && currentRun != null && String(readinessRun) === String(currentRun);
|
|
69
|
+
}
|
|
70
|
+
/** COMMITTED / FAILED: the execution reached a terminal state. */
|
|
71
|
+
function isMaterializedReportRunTerminal(status) {
|
|
72
|
+
return (status === MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.COMMITTED ||
|
|
73
|
+
status === MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.FAILED);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The instant a run started (its `started_at`, or `updatedAt` when a legacy /
|
|
77
|
+
* partial row has none).
|
|
78
|
+
*/
|
|
79
|
+
function materializedReportRunStartedAt(run) {
|
|
80
|
+
const candidate = run.started_at ?? run.updatedAt ?? null;
|
|
81
|
+
if (candidate == null)
|
|
82
|
+
return null;
|
|
83
|
+
const date = candidate instanceof Date ? candidate : new Date(candidate);
|
|
84
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Is an IN-FLIGHT run old enough that an interruption is plausible?
|
|
88
|
+
*
|
|
89
|
+
* AGE ALONE IS NEVER ENOUGH: recovery must also observe a STALE
|
|
90
|
+
* `tenant_active_jobs` heartbeat, otherwise a healthy long-running report would
|
|
91
|
+
* be taken over. This helper only answers the age question.
|
|
92
|
+
*/
|
|
93
|
+
function isMaterializedReportRunStale(args) {
|
|
94
|
+
if (!isMaterializedReportRunInFlight(args.run?.status))
|
|
95
|
+
return false;
|
|
96
|
+
const startedAt = materializedReportRunStartedAt(args.run);
|
|
97
|
+
if (startedAt == null)
|
|
98
|
+
return false;
|
|
99
|
+
const now = args.now ?? new Date();
|
|
100
|
+
const staleAfterMs = Number.isFinite(args.staleAfterMs) && args.staleAfterMs > 0
|
|
101
|
+
? args.staleAfterMs
|
|
102
|
+
: MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_STALE_MS;
|
|
103
|
+
return now.getTime() - startedAt.getTime() >= staleAfterMs;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* May this report be retried?
|
|
107
|
+
*
|
|
108
|
+
* A MISSING row is retryable (the report never ran: a failed day, a crash
|
|
109
|
+
* before the first attempt, or a pre-ledger day). A FAILED row is retryable.
|
|
110
|
+
* A COMMITTED row is NOT (the retry would be a no-op), and an in-flight row is
|
|
111
|
+
* NOT (the executor owns it).
|
|
112
|
+
*/
|
|
113
|
+
function canRetryMaterializedReportRun(status) {
|
|
114
|
+
if (status == null)
|
|
115
|
+
return true;
|
|
116
|
+
return status === MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.FAILED;
|
|
117
|
+
}
|
|
118
|
+
/* ------------------------------ PII safety ------------------------------ */
|
|
119
|
+
/**
|
|
120
|
+
* Patterns that must NEVER reach `last_error` (operator-visible, may be logged
|
|
121
|
+
* or exported): e-mail addresses, long digit runs (phone numbers / card-like
|
|
122
|
+
* values) and bearer/basic credentials.
|
|
123
|
+
*/
|
|
124
|
+
const PII_PATTERNS = [
|
|
125
|
+
[/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, '[redacted-email]'],
|
|
126
|
+
// 7+ digits with common separators (phone numbers, card fragments).
|
|
127
|
+
[/(?:\+?\d[\s().-]?){7,}\d/g, '[redacted-number]'],
|
|
128
|
+
[/\b(?:bearer|basic)\s+[A-Za-z0-9._~+/-]+=*/gi, '[redacted-credential]'],
|
|
129
|
+
[/\b(?:password|secret|token|api[_-]?key)\s*[:=]\s*\S+/gi, '[redacted-credential]'],
|
|
130
|
+
];
|
|
131
|
+
/**
|
|
132
|
+
* Sanitizes an execution error for durable storage / API output.
|
|
133
|
+
*
|
|
134
|
+
* Deliberately conservative: the message is single-lined, PII-redacted and
|
|
135
|
+
* bounded. The ERROR STACK and raw driver payload are never stored.
|
|
136
|
+
*/
|
|
137
|
+
function sanitizeMaterializedReportRunError(error) {
|
|
138
|
+
if (error == null)
|
|
139
|
+
return null;
|
|
140
|
+
const raw = typeof error === 'string'
|
|
141
|
+
? error
|
|
142
|
+
: typeof error.message === 'string'
|
|
143
|
+
? String(error.message)
|
|
144
|
+
: '';
|
|
145
|
+
let message = raw.replace(/\s+/g, ' ').trim();
|
|
146
|
+
if (message === '') {
|
|
147
|
+
message =
|
|
148
|
+
typeof error.name === 'string'
|
|
149
|
+
? String(error.name)
|
|
150
|
+
: 'UNKNOWN_ERROR';
|
|
151
|
+
}
|
|
152
|
+
for (const [pattern, replacement] of PII_PATTERNS) {
|
|
153
|
+
message = message.replace(pattern, replacement);
|
|
154
|
+
}
|
|
155
|
+
return message.slice(0, MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_REPORT_RUN_ERROR_MAX_LENGTH);
|
|
156
|
+
}
|
|
@@ -522,12 +522,103 @@ const DIALER_DEFINITION = {
|
|
|
522
522
|
'Writes a COMMITTED materialized_tenant_day_readiness row in the SAME transaction.',
|
|
523
523
|
],
|
|
524
524
|
};
|
|
525
|
+
const DINEIN_DEFINITION = {
|
|
526
|
+
key: report_contract_1.REPORT_KEY_ENUM.DINEIN,
|
|
527
|
+
segment: 'dinein',
|
|
528
|
+
reportType: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_TYPE_ENUM.TENANT_DINEIN_REPORTS,
|
|
529
|
+
capabilities: { live: true, historical: true, details: true },
|
|
530
|
+
status: REPORT_DEFINITION_STATUS.PRODUCTION,
|
|
531
|
+
report: {
|
|
532
|
+
name: 'materialized_tenant_dinein_reports',
|
|
533
|
+
schemaVersion: 1,
|
|
534
|
+
budgetBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_MAX_BSON_BYTES,
|
|
535
|
+
enforced: true,
|
|
536
|
+
validatorFile: null,
|
|
537
|
+
validatorDebt: 'No schema validator exists for the dinein report collection yet.',
|
|
538
|
+
indexOwner: 'toolkit:MATERIALIZED_TENANT_DINEIN_REPORTS_INDEX_OPTIONS',
|
|
539
|
+
migrationId: null,
|
|
540
|
+
},
|
|
541
|
+
entries: {
|
|
542
|
+
name: 'materialized_tenant_dinein_entries',
|
|
543
|
+
schemaVersion: 1,
|
|
544
|
+
budgetBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_MAX_BSON_BYTES,
|
|
545
|
+
enforced: true,
|
|
546
|
+
validatorFile: null,
|
|
547
|
+
validatorDebt: 'No schema validator exists for the dinein entry collection yet.',
|
|
548
|
+
indexOwner: 'toolkit:MATERIALIZED_TENANT_DINEIN_ENTRIES_INDEX_OPTIONS',
|
|
549
|
+
migrationId: null,
|
|
550
|
+
},
|
|
551
|
+
sideCollections: [FLAT_ROWS, FLAT_SCOPES],
|
|
552
|
+
reportScopes: [...MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_SCOPES],
|
|
553
|
+
entryScopes: [...MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_SCOPES],
|
|
554
|
+
entryStorage: REPORT_ENTRY_STORAGE.PAGE_PER_SOURCE_DAY,
|
|
555
|
+
entrySplit: REPORT_ENTRY_SPLIT.DETERMINISTIC_SUBPAGES,
|
|
556
|
+
maxReportScope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR,
|
|
557
|
+
maxEntryScope: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
|
|
558
|
+
projections: [REPORT_PROJECTION.FLAT_DRILLDOWN],
|
|
559
|
+
budgets: {
|
|
560
|
+
materialized_tenant_dinein_reports: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_REPORT_MAX_BSON_BYTES,
|
|
561
|
+
materialized_tenant_dinein_entries: MATERIALIZED_REPORTS_1.MATERIALIZED_DINEIN_ENTRY_MAX_BSON_BYTES,
|
|
562
|
+
materialized_report_drilldown_rows: DOCUMENT_BUDGET,
|
|
563
|
+
materialized_report_drilldown_scopes: DOCUMENT_BUDGET,
|
|
564
|
+
},
|
|
565
|
+
retention: [],
|
|
566
|
+
writeGuard: REPORT_WRITE_GUARD.WATERMARK,
|
|
567
|
+
liveSource: REPORT_LIVE_SOURCE.RAW,
|
|
568
|
+
historicalLens: REPORT_HISTORICAL_LENS.COUNTER_ROWS,
|
|
569
|
+
completeness: { summary: 'NONE', details: 'FLAT_PROJECTION' },
|
|
570
|
+
filters: [
|
|
571
|
+
{
|
|
572
|
+
id: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS,
|
|
573
|
+
kind: 'KEY_COMPONENT',
|
|
574
|
+
mode: 'SERVER',
|
|
575
|
+
appliesTo: 'BOTH',
|
|
576
|
+
},
|
|
577
|
+
{
|
|
578
|
+
id: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_KEY_FILTER_ENUM.PLATFORM,
|
|
579
|
+
kind: 'KEY_COMPONENT',
|
|
580
|
+
mode: 'SERVER',
|
|
581
|
+
appliesTo: 'BOTH',
|
|
582
|
+
},
|
|
583
|
+
// Origin / table / floor / split / offline are ROW filters: the SUMMARY
|
|
584
|
+
// cannot answer them exactly (the counters are keyed only by
|
|
585
|
+
// ORDER_STATUS:PLATFORM), so a summary request that sends one is REJECTED
|
|
586
|
+
// with 400 INVALID_REQUEST + details.unsupported_filters - never silently
|
|
587
|
+
// answered unfiltered.
|
|
588
|
+
{ id: 'origins', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
|
|
589
|
+
{ id: 'table_ids', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
|
|
590
|
+
{ id: 'floor_ids', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
|
|
591
|
+
{ id: 'split_types', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
|
|
592
|
+
{ id: 'offline', kind: 'ROW', mode: 'SERVER', appliesTo: 'DETAILS' },
|
|
593
|
+
{ id: 'DETAILS_VIEW', kind: 'REQUEST', mode: 'SERVER', appliesTo: 'DETAILS' },
|
|
594
|
+
],
|
|
595
|
+
cursor: REPORT_CURSOR_KIND.KEYSET_STRUCTURED,
|
|
596
|
+
adapters: {
|
|
597
|
+
writer: 'materializeDineinReport',
|
|
598
|
+
live: 'getLiveTenantDineinReports',
|
|
599
|
+
historical: 'getMaterializedTenantDineinReports',
|
|
600
|
+
details: 'getMaterializedDineinDetailsPage',
|
|
601
|
+
},
|
|
602
|
+
owner: 'reporting-platform',
|
|
603
|
+
notes: [
|
|
604
|
+
'Source day is order.localDate; a fingerprint never moves a check to the day its table closed.',
|
|
605
|
+
'Deleted split parents are excluded from sales/order counts and read only for rating discovery.',
|
|
606
|
+
'Covers come from the table-close fingerprint of the check, never from num_of_guests.',
|
|
607
|
+
'Sales = amount_earned, which already includes the service charge; the charge is a component.',
|
|
608
|
+
'Courses are current-state counts only: the order stores no call history or call timestamp.',
|
|
609
|
+
'Reservations are a document-level block with no order link and no seated/no-show state.',
|
|
610
|
+
'Origin / table / floor / split / offline are DETAILS row filters; the summary rejects them.',
|
|
611
|
+
'Page entries split deterministically into #N sub-pages; no quarter/semester/year entry scope.',
|
|
612
|
+
'Writes a COMMITTED materialized_tenant_day_readiness row in the SAME transaction.',
|
|
613
|
+
],
|
|
614
|
+
};
|
|
525
615
|
exports.REPORT_DEFINITIONS = {
|
|
526
616
|
[OVERVIEW_DEFINITION.key]: OVERVIEW_DEFINITION,
|
|
527
617
|
[DISCOUNTS_DEFINITION.key]: DISCOUNTS_DEFINITION,
|
|
528
618
|
[PREP_TIME_DEFINITION.key]: PREP_TIME_DEFINITION,
|
|
529
619
|
[DELIVERY_DEFINITION.key]: DELIVERY_DEFINITION,
|
|
530
620
|
[DIALER_DEFINITION.key]: DIALER_DEFINITION,
|
|
621
|
+
[DINEIN_DEFINITION.key]: DINEIN_DEFINITION,
|
|
531
622
|
};
|
|
532
623
|
exports.PRODUCTION_REPORT_DEFINITIONS = [
|
|
533
624
|
OVERVIEW_DEFINITION,
|
|
@@ -535,6 +626,7 @@ exports.PRODUCTION_REPORT_DEFINITIONS = [
|
|
|
535
626
|
PREP_TIME_DEFINITION,
|
|
536
627
|
DELIVERY_DEFINITION,
|
|
537
628
|
DIALER_DEFINITION,
|
|
629
|
+
DINEIN_DEFINITION,
|
|
538
630
|
];
|
|
539
631
|
exports.REPORT_REGISTRY_EXEMPTIONS = {
|
|
540
632
|
[report_contract_1.REPORT_KEY_ENUM.CASH_IN_OUT]: {
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { IMaterializedDineinBreakdownRow, IMaterializedDineinReservationCounters, IMaterializedDineinReservationHourRow, IMaterializedDineinTopEditedCheck, IMaterializedDineinUpcomingReservation, IMaterializedTenantDineinReport } from '../../schemas/types/materialized_tenant_dinein_reports';
|
|
2
|
+
import { IDineinKeyFilters } from './materialized-dinein-key-helpers';
|
|
3
|
+
/**
|
|
4
|
+
* Frontend formatter for `materialized_tenant_dinein_reports`.
|
|
5
|
+
*
|
|
6
|
+
* The stored documents hold integers only (counts, cents, minutes and the sums
|
|
7
|
+
* their averages need). EVERY ratio the page shows is derived HERE and never
|
|
8
|
+
* stored: average ticket, average covers per check, average seated occupancy,
|
|
9
|
+
* average rating, service-charge share, cancel rate, edit rate, call rate and
|
|
10
|
+
* every payment share.
|
|
11
|
+
*
|
|
12
|
+
* ## `tables_served` vs `tables_served_distinct`
|
|
13
|
+
*
|
|
14
|
+
* The stored `tables_served` counter is a DAY-grain distinct count, so a period
|
|
15
|
+
* document (folded from days) carries a table-DAYS sum. The formatter therefore
|
|
16
|
+
* reports BOTH: `tables_served` (the stored sum) and `tables_served_distinct`
|
|
17
|
+
* (the real distinct-table count for the scope, derived from the `by_table`
|
|
18
|
+
* keys). When the table map overflowed into `__OTHER__`, `tables_truncated` is
|
|
19
|
+
* true and the distinct count is a LOWER BOUND — never a silent exact number.
|
|
20
|
+
*
|
|
21
|
+
* ## Scope shape
|
|
22
|
+
*
|
|
23
|
+
* `documents` is the set of documents of ONE scope level (e.g. the `localMonth`
|
|
24
|
+
* documents of a selection, or the `localDate` documents of one day). Key
|
|
25
|
+
* filters are applied here as well, so a client that only has unfiltered
|
|
26
|
+
* documents still narrows them exactly like the server does.
|
|
27
|
+
*
|
|
28
|
+
* ## Reservations
|
|
29
|
+
*
|
|
30
|
+
* The document-level reservation block is summed from every document (it is not
|
|
31
|
+
* keyed by order status/platform, so a key filter never drops it). There is no
|
|
32
|
+
* seated / no-show state in the source, so no conversion rate is exposed.
|
|
33
|
+
*/
|
|
34
|
+
export interface IFormattedDineinSummary {
|
|
35
|
+
orders: number;
|
|
36
|
+
completed_orders: number;
|
|
37
|
+
cancelled_orders: number;
|
|
38
|
+
covers: number;
|
|
39
|
+
items: number;
|
|
40
|
+
/** `sales / orders` (money, 2dp); null when there is no check. */
|
|
41
|
+
average_ticket: number | null;
|
|
42
|
+
/** `covers / orders` (2dp); null when there is no check. */
|
|
43
|
+
average_covers_per_check: number | null;
|
|
44
|
+
/** `cancelled_orders / orders` as a percentage (2dp); null when there is no check. */
|
|
45
|
+
cancelled_rate: number | null;
|
|
46
|
+
sales: number;
|
|
47
|
+
discounts: number;
|
|
48
|
+
tax: number;
|
|
49
|
+
tips: number;
|
|
50
|
+
service_charge_amount: number;
|
|
51
|
+
service_charge_taxable_amount: number;
|
|
52
|
+
surcharge_amount: number;
|
|
53
|
+
refunds: number;
|
|
54
|
+
/** `service_charge_amount / sales` as a percentage (2dp); null when sales is 0. */
|
|
55
|
+
service_charge_share: number | null;
|
|
56
|
+
tables_served: number;
|
|
57
|
+
/** Real distinct tables for the scope, from `by_table`; lower bound when truncated. */
|
|
58
|
+
tables_served_distinct: number;
|
|
59
|
+
tables_truncated: boolean;
|
|
60
|
+
table_sessions: number;
|
|
61
|
+
occupancy_minutes_sum: number;
|
|
62
|
+
occupancy_sessions: number;
|
|
63
|
+
fallback_occupancy_sessions: number;
|
|
64
|
+
/**
|
|
65
|
+
* `occupancy_minutes_sum / (occupancy_sessions + fallback_occupancy_sessions)`
|
|
66
|
+
* (minutes, 1dp); null when no session was measurable.
|
|
67
|
+
*/
|
|
68
|
+
average_occupancy_minutes: number | null;
|
|
69
|
+
split_parents: number;
|
|
70
|
+
split_children: number;
|
|
71
|
+
split_checks: number;
|
|
72
|
+
split_sales: number;
|
|
73
|
+
split_type_counts: Record<string, number>;
|
|
74
|
+
/** `split_sales / sales` as a percentage (2dp); null when sales is 0. */
|
|
75
|
+
split_sales_share: number | null;
|
|
76
|
+
offline_orders: number;
|
|
77
|
+
offline_sales: number;
|
|
78
|
+
/** `offline_sales / sales` as a percentage (2dp); null when sales is 0. */
|
|
79
|
+
offline_sales_share: number | null;
|
|
80
|
+
origin_orders: number;
|
|
81
|
+
origin_sales: number;
|
|
82
|
+
origin_covers: number;
|
|
83
|
+
service_charge_orders: number;
|
|
84
|
+
service_charge_percentage_orders: number;
|
|
85
|
+
service_charge_fixed_orders: number;
|
|
86
|
+
service_charge_original_price_orders: number;
|
|
87
|
+
service_charge_rate_counts: Record<string, number>;
|
|
88
|
+
edited_orders: number;
|
|
89
|
+
total_edits: number;
|
|
90
|
+
item_additions: number;
|
|
91
|
+
item_removals: number;
|
|
92
|
+
net_item_change: number;
|
|
93
|
+
/** `edited_orders / orders` as a percentage (2dp). */
|
|
94
|
+
edit_rate: number | null;
|
|
95
|
+
/** `total_edits / orders` (2dp) — previous versions per check. */
|
|
96
|
+
average_edits_per_check: number | null;
|
|
97
|
+
courses_assigned: number;
|
|
98
|
+
courses_called: number;
|
|
99
|
+
courses_on_hold: number;
|
|
100
|
+
course_items: number;
|
|
101
|
+
/** `courses_called / courses_assigned` as a percentage (2dp). */
|
|
102
|
+
course_call_rate: number | null;
|
|
103
|
+
card_amount: number;
|
|
104
|
+
cash_amount: number;
|
|
105
|
+
other_amount: number;
|
|
106
|
+
card_orders: number;
|
|
107
|
+
cash_orders: number;
|
|
108
|
+
split_tender_orders: number;
|
|
109
|
+
card_share: number | null;
|
|
110
|
+
cash_share: number | null;
|
|
111
|
+
other_share: number | null;
|
|
112
|
+
rated_orders: number;
|
|
113
|
+
rating_sum: number;
|
|
114
|
+
rating_1: number;
|
|
115
|
+
rating_2: number;
|
|
116
|
+
rating_3: number;
|
|
117
|
+
rating_4: number;
|
|
118
|
+
rating_5: number;
|
|
119
|
+
review_count: number;
|
|
120
|
+
/** `rating_sum / rated_orders` (2dp); null when nothing was rated. */
|
|
121
|
+
average_rating: number | null;
|
|
122
|
+
}
|
|
123
|
+
export interface IFormattedDineinHourRow {
|
|
124
|
+
hour: number;
|
|
125
|
+
label: string;
|
|
126
|
+
orders: number;
|
|
127
|
+
sales: number;
|
|
128
|
+
covers: number;
|
|
129
|
+
}
|
|
130
|
+
export interface IFormattedDineinOriginRow {
|
|
131
|
+
origin: string;
|
|
132
|
+
orders: number;
|
|
133
|
+
sales: number;
|
|
134
|
+
covers: number;
|
|
135
|
+
}
|
|
136
|
+
export interface IFormattedDineinTableRow {
|
|
137
|
+
key: string;
|
|
138
|
+
table_id: string;
|
|
139
|
+
table_name: string;
|
|
140
|
+
floor_id: string;
|
|
141
|
+
orders: number;
|
|
142
|
+
sessions: number;
|
|
143
|
+
covers: number;
|
|
144
|
+
occupancy_minutes: number;
|
|
145
|
+
sales: number;
|
|
146
|
+
/** `occupancy_minutes / sessions` (1dp); null when there was no session. */
|
|
147
|
+
average_occupancy_minutes: number | null;
|
|
148
|
+
}
|
|
149
|
+
export interface IFormattedDineinFloorRow {
|
|
150
|
+
key: string;
|
|
151
|
+
floor_id: string;
|
|
152
|
+
orders: number;
|
|
153
|
+
sessions: number;
|
|
154
|
+
covers: number;
|
|
155
|
+
occupancy_minutes: number;
|
|
156
|
+
sales: number;
|
|
157
|
+
}
|
|
158
|
+
export interface IFormattedDineinCourseRow {
|
|
159
|
+
key: string;
|
|
160
|
+
course_id: string;
|
|
161
|
+
name: string;
|
|
162
|
+
assigned: number;
|
|
163
|
+
called: number;
|
|
164
|
+
on_hold: number;
|
|
165
|
+
items: number;
|
|
166
|
+
/** `called / assigned` as a percentage (2dp); null when nothing was assigned. */
|
|
167
|
+
call_rate: number | null;
|
|
168
|
+
}
|
|
169
|
+
export interface IFormattedDineinPaymentRow {
|
|
170
|
+
payment_type: string;
|
|
171
|
+
amount: number;
|
|
172
|
+
orders: number;
|
|
173
|
+
}
|
|
174
|
+
/** One hour of the reservations-by-hour chart (booked covers). */
|
|
175
|
+
export interface IFormattedDineinReservationHourRow extends IMaterializedDineinReservationHourRow {
|
|
176
|
+
hour: number;
|
|
177
|
+
label: string;
|
|
178
|
+
}
|
|
179
|
+
/** One row of the rich status/platform breakdown. */
|
|
180
|
+
export interface IFormattedDineinBreakdownRow extends IMaterializedDineinBreakdownRow {
|
|
181
|
+
key: string;
|
|
182
|
+
}
|
|
183
|
+
export interface IFormattedDineinReservationSummary extends IMaterializedDineinReservationCounters {
|
|
184
|
+
/** `reservation_covers / reservations` (2dp); null when there is no booking. */
|
|
185
|
+
average_party_size: number | null;
|
|
186
|
+
/** `reservation_lead_minutes_sum / reservation_lead_count` (1dp minutes). */
|
|
187
|
+
average_lead_minutes: number | null;
|
|
188
|
+
/** `reservation_duration_minutes_sum / reservation_duration_count` (1dp minutes). */
|
|
189
|
+
average_duration_minutes: number | null;
|
|
190
|
+
}
|
|
191
|
+
export interface IFormattedDineinPageData {
|
|
192
|
+
tenant_ids: string[];
|
|
193
|
+
summary: IFormattedDineinSummary;
|
|
194
|
+
/** All 24 hours, ascending — an absent hour is an explicit zero. */
|
|
195
|
+
by_hour: IFormattedDineinHourRow[];
|
|
196
|
+
by_origin: IFormattedDineinOriginRow[];
|
|
197
|
+
by_table: IFormattedDineinTableRow[];
|
|
198
|
+
by_floor: IFormattedDineinFloorRow[];
|
|
199
|
+
by_course: IFormattedDineinCourseRow[];
|
|
200
|
+
by_payment_type: IFormattedDineinPaymentRow[];
|
|
201
|
+
/** RICH breakdown rows (checks + covers + sales) per order status. */
|
|
202
|
+
by_status: IFormattedDineinBreakdownRow[];
|
|
203
|
+
/** RICH breakdown rows (checks + covers + sales) per platform. */
|
|
204
|
+
by_platform: IFormattedDineinBreakdownRow[];
|
|
205
|
+
reservations: IFormattedDineinReservationSummary;
|
|
206
|
+
/** The reservations-by-hour chart, folded from `reservation_counters.by_hour`. */
|
|
207
|
+
reservation_by_hour: IFormattedDineinReservationHourRow[];
|
|
208
|
+
/** Bounded, masked snapshots (deduped across the folded documents). */
|
|
209
|
+
upcoming_reservations: IMaterializedDineinUpcomingReservation[];
|
|
210
|
+
top_edited_checks: IMaterializedDineinTopEditedCheck[];
|
|
211
|
+
/** The scope level the documents covered (diagnostics for the page header). */
|
|
212
|
+
scopes: {
|
|
213
|
+
scope_context: string;
|
|
214
|
+
scope_field: string;
|
|
215
|
+
}[];
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Formats the report documents of one scope level into the page payload.
|
|
219
|
+
*
|
|
220
|
+
* Accepts the array returned by a live/historical read or a single stored
|
|
221
|
+
* document; it never throws and never mutates its input.
|
|
222
|
+
*/
|
|
223
|
+
export declare function formatMaterializedDineinReport(documents: readonly IMaterializedTenantDineinReport[] | null | undefined, options?: {
|
|
224
|
+
filters?: IDineinKeyFilters | null;
|
|
225
|
+
}): IFormattedDineinPageData;
|