@managesome/eposmatic-toolkit 0.4.61 → 0.4.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +77 -0
  2. package/esm/constants/MATERIALIZED_SCHEMA_VERSIONS.js +17 -0
  3. package/esm/constants/TENANT_ENUMS.js +15 -0
  4. package/esm/constants/WORKER_ENDPOINTS.js +14 -2
  5. package/esm/helpers/materialized-reports/index.js +4 -0
  6. package/esm/helpers/materialized-reports/materialized-credit-bills-helpers.js +3 -3
  7. package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +5 -5
  8. package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +2 -2
  9. package/esm/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +5 -5
  10. package/esm/helpers/materialized-reports/materialized-dialer-compile-helpers.js +2 -2
  11. package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +5 -5
  12. package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +2 -2
  13. package/esm/helpers/materialized-reports/materialized-discount-compile-helpers.js +3 -3
  14. package/esm/helpers/materialized-reports/materialized-document-size.js +2 -2
  15. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +3 -1
  16. package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -3
  17. package/esm/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +3 -3
  18. package/esm/helpers/materialized-reports/materialized-report-runs.js +143 -0
  19. package/esm/helpers/materialized-reports/report-compile.js +38 -0
  20. package/esm/helpers/materialized-reports/tenant-sales-overview-bson.js +27 -0
  21. package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +3 -22
  22. package/esm/schemas/models/index.js +1 -0
  23. package/esm/schemas/models/materialized_credit_bills.js +2 -1
  24. package/esm/schemas/models/materialized_tenant_delivery_entries.js +2 -1
  25. package/esm/schemas/models/materialized_tenant_delivery_reports.js +2 -1
  26. package/esm/schemas/models/materialized_tenant_dialer_entries.js +2 -1
  27. package/esm/schemas/models/materialized_tenant_dialer_reports.js +2 -1
  28. package/esm/schemas/models/materialized_tenant_dinein_entries.js +2 -1
  29. package/esm/schemas/models/materialized_tenant_dinein_reports.js +2 -1
  30. package/esm/schemas/models/materialized_tenant_report_runs.js +105 -0
  31. package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +2 -1
  32. package/esm/schemas/models/tenant_active_jobs.js +19 -1
  33. package/esm/schemas/types/index.js +1 -0
  34. package/lib/constants/MATERIALIZED_REPORTS.d.ts +69 -0
  35. package/lib/constants/MATERIALIZED_REPORTS.js +78 -1
  36. package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.d.ts +17 -0
  37. package/lib/constants/MATERIALIZED_SCHEMA_VERSIONS.js +20 -0
  38. package/lib/constants/TENANT_ENUMS.d.ts +14 -0
  39. package/lib/constants/TENANT_ENUMS.js +16 -1
  40. package/lib/constants/WORKER_ENDPOINTS.d.ts +12 -2
  41. package/lib/constants/WORKER_ENDPOINTS.js +14 -2
  42. package/lib/helpers/materialized-reports/index.d.ts +3 -0
  43. package/lib/helpers/materialized-reports/index.js +27 -0
  44. package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.js +4 -4
  45. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +6 -6
  46. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +4 -4
  47. package/lib/helpers/materialized-reports/materialized-dialer-close-day-helpers.js +6 -6
  48. package/lib/helpers/materialized-reports/materialized-dialer-compile-helpers.js +6 -6
  49. package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +6 -6
  50. package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +6 -6
  51. package/lib/helpers/materialized-reports/materialized-discount-compile-helpers.js +3 -3
  52. package/lib/helpers/materialized-reports/materialized-document-size.js +2 -5
  53. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +2 -0
  54. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -3
  55. package/lib/helpers/materialized-reports/materialized-prep-time-compile-helpers.js +3 -3
  56. package/lib/helpers/materialized-reports/materialized-report-runs.d.ts +105 -0
  57. package/lib/helpers/materialized-reports/materialized-report-runs.js +156 -0
  58. package/lib/helpers/materialized-reports/report-compile.d.ts +38 -0
  59. package/lib/helpers/materialized-reports/report-compile.js +87 -0
  60. package/lib/helpers/materialized-reports/tenant-sales-overview-bson.d.ts +12 -0
  61. package/lib/helpers/materialized-reports/tenant-sales-overview-bson.js +33 -0
  62. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +1 -12
  63. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +4 -24
  64. package/lib/helpers/types/workers.d.ts +65 -0
  65. package/lib/schemas/models/index.d.ts +1 -0
  66. package/lib/schemas/models/index.js +1 -0
  67. package/lib/schemas/models/materialized_credit_bills.d.ts +29 -46
  68. package/lib/schemas/models/materialized_credit_bills.js +3 -2
  69. package/lib/schemas/models/materialized_tenant_cash_entries.d.ts +9 -9
  70. package/lib/schemas/models/materialized_tenant_cash_reports.d.ts +9 -9
  71. package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +11 -10
  72. package/lib/schemas/models/materialized_tenant_delivery_entries.js +3 -2
  73. package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +9 -9
  74. package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +6 -6
  75. package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +11 -10
  76. package/lib/schemas/models/materialized_tenant_delivery_reports.js +3 -2
  77. package/lib/schemas/models/materialized_tenant_dialer_entries.d.ts +8 -7
  78. package/lib/schemas/models/materialized_tenant_dialer_entries.js +3 -2
  79. package/lib/schemas/models/materialized_tenant_dialer_reports.d.ts +11 -10
  80. package/lib/schemas/models/materialized_tenant_dialer_reports.js +3 -2
  81. package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +8 -7
  82. package/lib/schemas/models/materialized_tenant_dinein_entries.js +3 -2
  83. package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +11 -10
  84. package/lib/schemas/models/materialized_tenant_dinein_reports.js +3 -2
  85. package/lib/schemas/models/materialized_tenant_discount_entries.d.ts +9 -9
  86. package/lib/schemas/models/materialized_tenant_discount_reports.d.ts +9 -9
  87. package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +9 -9
  88. package/lib/schemas/models/materialized_tenant_hourly_comparison_entries.d.ts +9 -9
  89. package/lib/schemas/models/materialized_tenant_hourly_comparison_reports.d.ts +9 -9
  90. package/lib/schemas/models/materialized_tenant_payments_comparison_entries.d.ts +9 -9
  91. package/lib/schemas/models/materialized_tenant_payments_comparison_reports.d.ts +9 -9
  92. package/lib/schemas/models/materialized_tenant_prep_time_entries.d.ts +9 -9
  93. package/lib/schemas/models/materialized_tenant_prep_time_reports.d.ts +9 -9
  94. package/lib/schemas/models/materialized_tenant_report_runs.d.ts +97 -0
  95. package/lib/schemas/models/materialized_tenant_report_runs.js +108 -0
  96. package/lib/schemas/models/materialized_tenant_sales_comparison_entries.d.ts +9 -9
  97. package/lib/schemas/models/materialized_tenant_sales_comparison_reports.d.ts +9 -9
  98. package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +11 -35
  99. package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +3 -2
  100. package/lib/schemas/models/tenant_active_jobs.d.ts +12 -3
  101. package/lib/schemas/models/tenant_active_jobs.js +18 -0
  102. package/lib/schemas/types/index.d.ts +1 -0
  103. package/lib/schemas/types/index.js +1 -0
  104. package/lib/schemas/types/materialized_tenant_report_runs.d.ts +55 -0
  105. package/lib/schemas/types/tenant_active_jobs.d.ts +15 -1
  106. package/lib/tests/materialized-reports/materialized-report-runs.test.js +116 -0
  107. package/lib/tests/materialized-reports/tenant-dinein-formatter.test.js +159 -0
  108. package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +2 -1
  109. package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +5 -4
  110. package/lib/tests/reporting-contract/no-live-transport.test.js +106 -0
  111. package/package.json +2 -1
  112. package/lib/helpers/order/payment-collection.d.ts +0 -25
  113. package/lib/helpers/order/payment-collection.js +0 -51
  114. package/lib/schemas/models/applied_order_discounts.d.ts +0 -80
  115. package/lib/schemas/models/applied_order_discounts.js +0 -106
  116. package/lib/schemas/types/applied_order_discounts.d.ts +0 -22
  117. package/lib/tests/payment-collection-timestamps.test.d.ts +0 -1
  118. package/lib/tests/payment-collection-timestamps.test.js +0 -71
  119. /package/{lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts → esm/schemas/types/materialized_tenant_report_runs.js} +0 -0
  120. /package/lib/schemas/types/{applied_order_discounts.js → materialized_tenant_report_runs.js} +0 -0
  121. /package/lib/tests/materialized-reports/{analytics-overview-helpers.test.d.ts → materialized-report-runs.test.d.ts} +0 -0
  122. /package/lib/tests/{materialized-reports/analytics-performance-helpers.test.d.ts → reporting-contract/no-live-transport.test.d.ts} +0 -0
@@ -0,0 +1,27 @@
1
+ import mongoose from 'mongoose';
2
+ import { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME, MaterializedTenantSalesOverviewReportSchema, } from '../../schemas/models/materialized_tenant_sales_overview_reports';
3
+ /**
4
+ * MAIN-THREAD-ONLY Overview persistence adapter.
5
+ *
6
+ * Deliberately SPLIT from `tenant-sales-overview-helpers.ts`: the compile
7
+ * helpers must stay mongoose-free for the workers-service Piscina compile
8
+ * graph, while the BSON casting step needs the mongoose schema. Importing this
9
+ * file is the ONLY way to pull mongoose into the Overview compile path — and
10
+ * the worker never imports it.
11
+ */
12
+ function getMaterializedTenantSalesOverviewReportModel() {
13
+ return (mongoose.models[MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME] ??
14
+ mongoose.model(MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME, MaterializedTenantSalesOverviewReportSchema, MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME));
15
+ }
16
+ /**
17
+ * Casts a JSON materialized report through the collection's mongoose schema,
18
+ * returning a hydrated document ready to be saved / bulk-written (the
19
+ * `sale_type_metrics` plain object becomes a `Map`, date strings become
20
+ * `Date` instances, etc.).
21
+ *
22
+ * The document is NOT validated here — `save()` / `Model.validate()` still
23
+ * runs the schema validators.
24
+ */
25
+ export function convertMaterializedTenantSalesOverviewReportJsonToBson(report) {
26
+ return new (getMaterializedTenantSalesOverviewReportModel())(report);
27
+ }
@@ -1,7 +1,7 @@
1
- import mongoose from 'mongoose';
1
+ import ObjectID from 'bson-objectid';
2
+ import { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
2
3
  import { PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM, REPORT_SALE_TYPE_ENUM } from '../../constants';
3
4
  import { MATERIALIZED_REPORT_SCOPE_ENUM, MATERIALIZED_REPORT_SCOPES_WITH_DAY_INDEX, SALES_OVERVIEW_KEY_FILTERS, } from '../../constants/MATERIALIZED_REPORTS';
4
- import { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME, MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION, MaterializedTenantSalesOverviewReportSchema, } from '../../schemas/models/materialized_tenant_sales_overview_reports';
5
5
  import { buildMaterializedReportKey } from './key-helpers';
6
6
  import { buildMaterializedDayInputSignature, } from './materialized-day-input-signature';
7
7
  import { buildCreditBillEventCandidatesFromOrder, buildCreditBillIssuedCandidatesFromOrder, isMaterializedCreditBillPayment, resolveOrderLocalHour, resolveReceivedLocalHour, } from './materialized-credit-bills-helpers';
@@ -328,7 +328,7 @@ const createEmptyReportDocument = (args) => {
328
328
  ? getDayIndexFromLocalDate(scopeField.split(' ')[0])
329
329
  : null;
330
330
  return {
331
- _id: new mongoose.Types.ObjectId().toString(),
331
+ _id: new ObjectID().toHexString(),
332
332
  tenant_id: tenantId,
333
333
  brand_id: brandId,
334
334
  scope_context: scopeContext,
@@ -533,25 +533,6 @@ export function convertOrdersToMaterializedTenantSalesOverviewReports(localDate,
533
533
  return { materializedReports, credit_bill_issues: creditBillIssues, credit_bill_events: creditEventCandidates };
534
534
  }
535
535
  /* ------------------------------------------------------------------------ */
536
- /* 2. JSON → BSON (mongoose document) */
537
- /* ------------------------------------------------------------------------ */
538
- function getMaterializedTenantSalesOverviewReportModel() {
539
- return (mongoose.models[MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME] ??
540
- mongoose.model(MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME, MaterializedTenantSalesOverviewReportSchema, MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_COLLECTION_NAME));
541
- }
542
- /**
543
- * Casts a JSON materialized report through the collection's mongoose schema,
544
- * returning a hydrated document ready to be saved / bulk-written (the
545
- * `sale_type_metrics` plain object becomes a `Map`, date strings become
546
- * `Date` instances, etc.).
547
- *
548
- * The document is NOT validated here — `save()` / `Model.validate()` still
549
- * runs the schema validators.
550
- */
551
- export function convertMaterializedTenantSalesOverviewReportJsonToBson(report) {
552
- return new (getMaterializedTenantSalesOverviewReportModel())(report);
553
- }
554
- /* ------------------------------------------------------------------------ */
555
536
  /* 3. Summing documents (period accumulation) */
556
537
  /* ------------------------------------------------------------------------ */
557
538
  const sumOrderMetrics = (target, source) => {
@@ -49,6 +49,7 @@ export * from './materialized_tenant_payments_comparison_entries';
49
49
  export * from './materialized_tenant_payments_comparison_reports';
50
50
  export * from './materialized_tenant_prep_time_entries';
51
51
  export * from './materialized_tenant_prep_time_reports';
52
+ export * from './materialized_tenant_report_runs';
52
53
  export * from './materialized_tenant_reports_iterations';
53
54
  export * from './materialized_tenant_sales_comparison_entries';
54
55
  export * from './materialized_tenant_sales_comparison_reports';
@@ -1,3 +1,5 @@
1
+ import { MATERIALIZED_CREDIT_BILLS_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
2
+ export { MATERIALIZED_CREDIT_BILLS_SCHEMA_VERSION };
1
3
  import { Schema } from 'mongoose';
2
4
  import { ALL_DAY_INDEX } from '../../constants/ENUMS';
3
5
  import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, MATERIALIZED_CREDIT_BILLS_SCOPES, SALES_OVERVIEW_KEY_FILTERS, } from '../../constants/MATERIALIZED_REPORTS';
@@ -19,7 +21,6 @@ import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, MATERIALIZED_CREDIT_BILLS_SCOPES,
19
21
  * documents must then be re-materialized. PRE-RELEASE: the collection has no
20
22
  * live tenants/consumers yet, so every change so far folds into version `1`.
21
23
  */
22
- export const MATERIALIZED_CREDIT_BILLS_SCHEMA_VERSION = 1;
23
24
  const CreditBillIssuedEntrySchema = new Schema({
24
25
  order_id: {
25
26
  type: String,
@@ -1,3 +1,5 @@
1
+ import { MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
2
+ export { MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION };
1
3
  import { Schema } from 'mongoose';
2
4
  import { ALL_DAY_INDEX } from '../../constants/ENUMS';
3
5
  import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, DELIVERY_KEY_FILTERS, MATERIALIZED_DELIVERY_ENTRY_SCOPES, } from '../../constants/MATERIALIZED_REPORTS';
@@ -19,7 +21,6 @@ import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, DELIVERY_KEY_FILTERS, MATERIALIZED
19
21
  * pre-launch contract. Schema versioning will be reintroduced only when a
20
22
  * future stored-shape change requires an explicit migration.
21
23
  */
22
- export const MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 1;
23
24
  export const MaterializedTenantDeliveryEntriesSchema = new Schema({
24
25
  tenant_id: { type: String, required: true },
25
26
  brand_id: { type: String, required: true },
@@ -1,3 +1,5 @@
1
+ import { MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
2
+ export { MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION };
1
3
  import { Schema } from 'mongoose';
2
4
  import { ALL_DAY_INDEX } from '../../constants/ENUMS';
3
5
  import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, DELIVERY_KEY_FILTERS, MATERIALIZED_DELIVERY_REPORT_SCOPES, } from '../../constants/MATERIALIZED_REPORTS';
@@ -17,7 +19,6 @@ import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, DELIVERY_KEY_FILTERS, MATERIALIZED
17
19
  * rows as the refund source. Schema versioning is reset to 1 across all
18
20
  * materialized collections for this pre-launch contract.
19
21
  */
20
- export const MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 1;
21
22
  export const MaterializedTenantDeliveryReportSchema = new Schema({
22
23
  tenant_id: { type: String, required: true },
23
24
  brand_id: { type: String, required: true },
@@ -1,3 +1,5 @@
1
+ import { MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
2
+ export { MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION };
1
3
  import { Schema } from 'mongoose';
2
4
  import { ALL_DAY_INDEX } from '../../constants/ENUMS';
3
5
  import { MATERIALIZED_DIALER_ENTRY_SCOPES } from '../../constants/MATERIALIZED_REPORTS';
@@ -13,7 +15,6 @@ import { MATERIALIZED_DIALER_ENTRY_SCOPES } from '../../constants/MATERIALIZED_R
13
15
  * sections whose keys are the report's `<ACTION>:<POS_ID>:<STAFF_ID>` grammar.
14
16
  */
15
17
  /** Document shape version. Bump with a migration for already-stored pages. */
16
- export const MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION = 1;
17
18
  export const MaterializedTenantDialerEntriesSchema = new Schema({
18
19
  tenant_id: { type: String, required: true },
19
20
  brand_id: { type: String, required: true },
@@ -1,3 +1,5 @@
1
+ import { MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
2
+ export { MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION };
1
3
  import { Schema } from 'mongoose';
2
4
  import { ALL_DAY_INDEX } from '../../constants/ENUMS';
3
5
  import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, DIALER_KEY_FILTERS, MATERIALIZED_DIALER_REPORT_SCOPES, } from '../../constants/MATERIALIZED_REPORTS';
@@ -12,7 +14,6 @@ import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, DIALER_KEY_FILTERS, MATERIALIZED_D
12
14
  * `materialized_tenant_dialer_entries` collection (one page per source day).
13
15
  */
14
16
  /** Document shape version. Bump on a key-grammar/metric change + backfill. */
15
- export const MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION = 1;
16
17
  export const MaterializedTenantDialerReportSchema = new Schema({
17
18
  tenant_id: { type: String, required: true },
18
19
  brand_id: { type: String, required: true },
@@ -1,3 +1,5 @@
1
+ import { MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
2
+ export { MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION };
1
3
  import { Schema } from 'mongoose';
2
4
  import { ALL_DAY_INDEX } from '../../constants/ENUMS';
3
5
  import { MATERIALIZED_DINEIN_ENTRY_SCOPES } from '../../constants/MATERIALIZED_REPORTS';
@@ -13,7 +15,6 @@ import { MATERIALIZED_DINEIN_ENTRY_SCOPES } from '../../constants/MATERIALIZED_R
13
15
  * `day_index: null`.
14
16
  */
15
17
  /** Document shape version. Bump on a row-shape change + backfill. */
16
- export const MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION = 1;
17
18
  export const MaterializedTenantDineinEntriesSchema = new Schema({
18
19
  tenant_id: { type: String, required: true },
19
20
  brand_id: { type: String, required: true },
@@ -1,3 +1,5 @@
1
+ import { MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
2
+ export { MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION };
1
3
  import { Schema } from 'mongoose';
2
4
  import { ALL_DAY_INDEX } from '../../constants/ENUMS';
3
5
  import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, DINEIN_KEY_FILTERS, MATERIALIZED_DINEIN_REPORT_SCOPES, } from '../../constants/MATERIALIZED_REPORTS';
@@ -14,7 +16,6 @@ import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, DINEIN_KEY_FILTERS, MATERIALIZED_D
14
16
  * `materialized_tenant_dinein_entries` collection (one page per source day).
15
17
  */
16
18
  /** Document shape version. Bump on a key-grammar/metric change + backfill. */
17
- export const MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION = 1;
18
19
  export const MaterializedTenantDineinReportSchema = new Schema({
19
20
  tenant_id: { type: String, required: true },
20
21
  brand_id: { type: String, required: true },
@@ -0,0 +1,105 @@
1
+ import { Schema } from 'mongoose';
2
+ import { ALL_MATERIALIZED_TENANT_REPORT_RUN_STATUSES, MATERIALIZED_READINESS_REPORT_KEYS, MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM, MATERIALIZED_TENANT_REPORT_RUNS_SCHEMA_VERSION, } from '../../constants/MATERIALIZED_REPORTS';
3
+ /**
4
+ * Mongoose schema for `materialized_tenant_report_runs` — the OPERATIONAL
5
+ * per-report execution ledger (PENDING / RUNNING / RETRYING / COMMITTED /
6
+ * FAILED).
7
+ *
8
+ * It is deliberately SEPARATE from `materialized_tenant_day_readiness`:
9
+ * readiness is the historical read gate and only ever carries COMMITTED /
10
+ * NEEDS_RECONCILIATION. A failed report must never look materialized, so its
11
+ * failure is recorded here, together with `attempts` and the redacted
12
+ * `last_error`.
13
+ *
14
+ * The row is written OUTSIDE the report transaction (a rollback must not erase
15
+ * the attempt), keyed by the unique compound
16
+ * `(tenant_id, localDate, report_key, schema_version)`.
17
+ */
18
+ export const MaterializedTenantReportRunSchema = new Schema({
19
+ tenant_id: { type: String, required: true },
20
+ localDate: { type: String, required: true },
21
+ report_key: {
22
+ type: String,
23
+ required: true,
24
+ enum: [...MATERIALIZED_READINESS_REPORT_KEYS],
25
+ },
26
+ schema_version: {
27
+ type: Number,
28
+ required: true,
29
+ immutable: true,
30
+ default: MATERIALIZED_TENANT_REPORT_RUNS_SCHEMA_VERSION,
31
+ },
32
+ status: {
33
+ type: String,
34
+ required: true,
35
+ enum: ALL_MATERIALIZED_TENANT_REPORT_RUN_STATUSES,
36
+ default: MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.PENDING,
37
+ },
38
+ attempts: {
39
+ type: Number,
40
+ required: true,
41
+ default: 0,
42
+ // Stored counters remain integers.
43
+ validate: {
44
+ validator: (value) => Number.isInteger(value) && value >= 0,
45
+ message: 'attempts must be a non-negative integer',
46
+ },
47
+ },
48
+ total_attempts: {
49
+ type: Number,
50
+ required: true,
51
+ default: 0,
52
+ // Stored counters remain integers.
53
+ validate: {
54
+ validator: (value) => Number.isInteger(value) && value >= 0,
55
+ message: 'total_attempts must be a non-negative integer',
56
+ },
57
+ },
58
+ last_error: { type: String, required: false, default: null },
59
+ run_id: { type: String, required: false, default: null },
60
+ started_at: { type: Schema.Types.Date, required: false, default: null },
61
+ finished_at: { type: Schema.Types.Date, required: false, default: null },
62
+ createdAt: {
63
+ type: Schema.Types.Date,
64
+ required: true,
65
+ default: () => new Date(),
66
+ immutable: true,
67
+ },
68
+ updatedAt: {
69
+ type: Schema.Types.Date,
70
+ required: true,
71
+ default: () => new Date(),
72
+ },
73
+ }, { timestamps: true, versionKey: false, minimize: false });
74
+ export const MATERIALIZED_TENANT_REPORT_RUNS_COLLECTION_INDEXES = {
75
+ _id: { _id: 1 },
76
+ tenant_id__localDate__report_key__schema_version: {
77
+ tenant_id: 1,
78
+ localDate: 1,
79
+ report_key: 1,
80
+ schema_version: 1,
81
+ },
82
+ };
83
+ /**
84
+ * Index OPTIONS the owner must CREATE (declared here, applied by a separate
85
+ * migration/deploy step — never by a read, a close or a retry at runtime).
86
+ */
87
+ export const MATERIALIZED_TENANT_REPORT_RUNS_INDEX_OPTIONS = [
88
+ {
89
+ key: { tenant_id: 1, localDate: 1, report_key: 1, schema_version: 1 },
90
+ name: 'tenant_id__localDate__report_key__schema_version',
91
+ unique: true,
92
+ },
93
+ // Admin materialization page: one tenant-day's reports, newest first.
94
+ {
95
+ key: { tenant_id: 1, localDate: 1, report_key: 1 },
96
+ name: 'tenant_id__localDate__report_key',
97
+ unique: false,
98
+ },
99
+ // Admin materialization page: the failed/running filters across tenants.
100
+ {
101
+ key: { status: 1, updatedAt: -1 },
102
+ name: 'status__updatedAt',
103
+ unique: false,
104
+ },
105
+ ];
@@ -1,3 +1,5 @@
1
+ import { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION } from '../../constants/MATERIALIZED_SCHEMA_VERSIONS';
2
+ export { MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION };
1
3
  import { Schema } from 'mongoose';
2
4
  import { REPORT_SALE_TYPE_ENUM } from '../../constants';
3
5
  import { ALL_DAY_INDEX } from '../../constants/ENUMS';
@@ -27,7 +29,6 @@ import { ALL_MATERIALIZED_REPORT_KEY_FILTERS, ALL_MATERIALIZED_REPORT_SCOPES, SA
27
29
  * this value during a rollout). PRE-RELEASE: the collection has no live
28
30
  * tenants/consumers yet, so every change so far folds into version `1`.
29
31
  */
30
- export const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
31
32
  const ReportDiscountByTypeSchema = new Schema({
32
33
  special_discount: {
33
34
  type: Number, // cents — Σ order_discount_details.special_discount
@@ -1,5 +1,5 @@
1
1
  import { Schema } from 'mongoose';
2
- import { ALL_TENANT_ACTIVE_JOBS_NAMES } from '../../constants';
2
+ import { ALL_TENANT_ACTIVE_JOBS_NAMES, ALL_TENANT_DAY_JOB_OUTCOMES } from '../../constants';
3
3
  export const TenantActiveJobSchema = new Schema({
4
4
  _id: {
5
5
  type: Schema.Types.ObjectId,
@@ -44,6 +44,24 @@ export const TenantActiveJobSchema = new Schema({
44
44
  type: Number,
45
45
  default: 0,
46
46
  },
47
+ // Per-report progress of the current run (Phase 1 per-report model).
48
+ current_report_key: {
49
+ type: String,
50
+ required: false,
51
+ default: null,
52
+ },
53
+ current_report_progress: {
54
+ type: Number,
55
+ required: false,
56
+ default: 0,
57
+ },
58
+ // Terminal outcome of the last run: COMPLETED | PARTIAL | FAILED.
59
+ outcome: {
60
+ type: String,
61
+ enum: [...ALL_TENANT_DAY_JOB_OUTCOMES, null],
62
+ required: false,
63
+ default: null,
64
+ },
47
65
  started_at: {
48
66
  type: Schema.Types.Date,
49
67
  default: null,
@@ -53,6 +53,7 @@ export * from './materialized_tenant_payments_comparison_entries';
53
53
  export * from './materialized_tenant_payments_comparison_reports';
54
54
  export * from './materialized_tenant_prep_time_entries';
55
55
  export * from './materialized_tenant_prep_time_reports';
56
+ export * from './materialized_tenant_report_runs';
56
57
  export * from './materialized_tenant_reports_iterations';
57
58
  export * from './materialized_tenant_sales_comparison_entries';
58
59
  export * from './materialized_tenant_sales_comparison_reports';
@@ -927,3 +927,72 @@ export declare const ALL_MATERIALIZED_REPORT_READINESS_STATUSES: MATERIALIZED_RE
927
927
  */
928
928
  export declare const MATERIALIZED_READINESS_REPORT_KEYS: readonly ["OVERVIEW", "DISCOUNTS", "PREP_TIME", "DELIVERY", "DIALER", "DINEIN"];
929
929
  export type TMaterializedReadinessReportKey = (typeof MATERIALIZED_READINESS_REPORT_KEYS)[number];
930
+ /**
931
+ * DURABLE OPERATIONAL LEDGER of one report's execution, SEPARATE from
932
+ * readiness.
933
+ *
934
+ * Readiness answers "may a historical read treat this tenant-day-report as
935
+ * final?" (only COMMITTED / NEEDS_RECONCILIATION ever appear there).
936
+ * This ledger answers "what happened to the execution?" and is the ONLY place
937
+ * a failed attempt is recorded (PENDING / RUNNING / RETRYING / COMMITTED /
938
+ * FAILED), so a FAILED report never - and can never - look materialized.
939
+ *
940
+ * One row per `(tenant_id, localDate, report_key, schema_version)`. The row is
941
+ * operational state: it is written OUTSIDE the report transaction (a rollback
942
+ * must not erase the fact that the attempt happened). Readiness is written
943
+ * INSIDE the report transaction. The two therefore have different lifecycles
944
+ * and are deliberately different collections.
945
+ *
946
+ * Phase 1 replaces the one all-report END_TENANT_DAY transaction with one
947
+ * transaction per report: each report commits (or fails) on its own, and this
948
+ * ledger is the operator-visible record of that per-report outcome.
949
+ */
950
+ export declare const MATERIALIZED_TENANT_REPORT_RUNS_COLLECTION_NAME = "materialized_tenant_report_runs";
951
+ /** Version of the report-run row shape. Pinned to 1 with the other collections. */
952
+ export declare const MATERIALIZED_TENANT_REPORT_RUNS_SCHEMA_VERSION = 1;
953
+ /** The execution state of one tenant-day-report run. */
954
+ export declare enum MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM {
955
+ /** The row exists but no attempt has started yet. */
956
+ PENDING = "PENDING",
957
+ /** An attempt is executing (its own transaction is open or about to open). */
958
+ RUNNING = "RUNNING",
959
+ /** A transient failure happened; another attempt is starting. */
960
+ RETRYING = "RETRYING",
961
+ /** The report transaction committed: documents + readiness are durable. */
962
+ COMMITTED = "COMMITTED",
963
+ /** Every allowed attempt was exhausted; readiness was NOT written. */
964
+ FAILED = "FAILED"
965
+ }
966
+ export declare const ALL_MATERIALIZED_TENANT_REPORT_RUN_STATUSES: MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM[];
967
+ /** States in which an execution currently owns the report (retry is refused). */
968
+ export declare const MATERIALIZED_TENANT_REPORT_RUN_IN_FLIGHT_STATUSES: readonly [MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.PENDING, MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.RUNNING, MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.RETRYING];
969
+ /**
970
+ * Bounded attempt budget of ONE report execution (transient errors only).
971
+ * A deterministic code/compile error is NEVER retried inside the job.
972
+ */
973
+ export declare const MATERIALIZED_TENANT_REPORT_RUN_MAX_ATTEMPTS = 2;
974
+ /** Bounded size of the stored `last_error` (single-line, PII-redacted). */
975
+ export declare const MATERIALIZED_TENANT_REPORT_RUN_ERROR_MAX_LENGTH = 500;
976
+ /**
977
+ * Stale window of a report-run row (RUNNING / RETRYING).
978
+ *
979
+ * A run that has not reached a terminal state within this window MAY have been
980
+ * interrupted (process crash). Recovery NEVER trusts the age alone: it also
981
+ * requires the tenant's active-job heartbeat to be stale, so a live long-running
982
+ * report is never taken over. The value mirrors the active-job lease window
983
+ * (30 minutes) so both fences agree.
984
+ */
985
+ export declare const MATERIALIZED_TENANT_REPORT_RUN_STALE_MS: number;
986
+ /**
987
+ * Durable `last_error` of a run recovered after an interruption with NO
988
+ * readiness row (the report transaction provably did not commit).
989
+ */
990
+ export declare const MATERIALIZED_REPORT_RUN_INTERRUPTED_ERROR = "INTERRUPTED_RUN";
991
+ /**
992
+ * Durable `last_error` of a run whose transaction COMMIT outcome is UNKNOWN.
993
+ *
994
+ * Such a run is deliberately left NON-terminal (`RUNNING`): the transaction may
995
+ * have committed. Stale-run recovery settles it from ownership-checked
996
+ * readiness (`readiness.run_id === run.run_id`), never by guessing here.
997
+ */
998
+ export declare const MATERIALIZED_REPORT_RUN_COMMIT_OUTCOME_UNKNOWN_ERROR = "COMMIT_OUTCOME_UNKNOWN";
@@ -12,7 +12,7 @@
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.MATERIALIZED_DELIVERY_GEO_SCOPES = exports.MATERIALIZED_DELIVERY_GEO_RESOLUTION = exports.MATERIALIZED_DELIVERY_GEO_MAX_KEYS = exports.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_SCHEMA_VERSION = exports.MATERIALIZED_DELIVERY_OTHER_TOKEN = exports.MATERIALIZED_DELIVERY_AREA_LIMIT = exports.MATERIALIZED_DELIVERY_RIDER_LIMIT = exports.MATERIALIZED_DELIVERY_DISTANCE_BUCKETS = exports.DELIVERY_KEY_FILTERS = exports.MATERIALIZED_DELIVERY_ENTRY_PAGE_ALL = exports.MATERIALIZED_DELIVERY_ENTRY_SCOPES = exports.MATERIALIZED_DELIVERY_REPORT_SCOPES = exports.MATERIALIZED_CASH_SOURCE_LIMIT = exports.CASH_KEY_FILTERS = exports.MATERIALIZED_CASH_REPORT_SCOPES = exports.ALL_MATERIALIZED_REPORT_CREDIT_BILL_EVENT_TYPES = exports.MATERIALIZED_REPORT_CREDIT_BILL_EVENT_TYPE_ENUM = exports.MATERIALIZED_CREDIT_SETTLEMENT_PAYMENT_TYPE = exports.MATERIALIZED_DISCOUNT_SOURCE_KEY_PREFIX = exports.MATERIALIZED_DISCOUNT_SOURCE_KEY = exports.ALL_MATERIALIZED_DISCOUNT_RATE_KINDS = exports.MATERIALIZED_DISCOUNT_RATE_KIND_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_SOURCE_CLASSES = exports.MATERIALIZED_DISCOUNT_SOURCE_CLASS_ENUM = exports.MATERIALIZED_DISCOUNT_PRICE_OVERRIDE_PREFIX = exports.MATERIALIZED_DISCOUNT_MANUAL_PREFIX = exports.MATERIALIZED_DISCOUNT_SPECIAL_DISCOUNT_ID = exports.MATERIALIZED_DISCOUNT_SOURCE_LIMIT = exports.ALL_MATERIALIZED_DISCOUNT_LEVELS = exports.MATERIALIZED_DISCOUNT_LEVEL_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_ENTRY_KINDS = exports.MATERIALIZED_DISCOUNT_ENTRY_KIND_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_SUB_KINDS = exports.MATERIALIZED_DISCOUNT_SUB_KIND_ENUM = exports.ALL_MATERIALIZED_DISCOUNT_SLOTS = exports.MATERIALIZED_DISCOUNT_SLOT_ENUM = exports.DISCOUNTS_KEY_FILTERS = exports.MATERIALIZED_DISCOUNT_REPORT_SCOPES = exports.MATERIALIZED_DISCOUNT_ENTRY_PAGE_ALL = exports.SALES_OVERVIEW_KEY_FILTERS = exports.ALL_MATERIALIZED_REPORT_KEY_FILTERS = exports.MATERIALIZED_REPORT_KEY_FILTER_ENUM = exports.MATERIALIZED_CREDIT_BILLS_SCOPES = exports.MATERIALIZED_REPORT_SCOPES_WITH_DAY_INDEX = exports.ALL_MATERIALIZED_REPORT_WINDOW_KINDS = exports.MATERIALIZED_REPORT_WINDOW_KIND_ENUM = exports.ALL_MATERIALIZED_REPORT_SCOPES = exports.MATERIALIZED_REPORT_SCOPE_ENUM = void 0;
14
14
  exports.MATERIALIZED_DIALER_ENTRY_PAGE_ALL = exports.MATERIALIZED_DIALER_ENTRY_SCOPES = exports.MATERIALIZED_DIALER_REPORT_SCOPES = exports.ALL_PAYMENTS_COMPARISON_METRICS = exports.PAYMENTS_COMPARISON_METRIC_ENUM = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_REPORTS_SCHEMA_VERSION = exports.PAYMENTS_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_PAYMENTS_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_PAYMENTS_COMPARISON_REPORTS_COLLECTION_NAME = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_SCHEMA_VERSION = exports.HOURLY_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_HOURLY_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_HOURLY_COMPARISON_REPORTS_COLLECTION_NAME = exports.ALL_SALES_COMPARISON_METRICS = exports.SALES_COMPARISON_METRIC_ENUM = exports.ALL_SALES_COMPARISON_BASELINES = exports.SALES_COMPARISON_BASELINE_ENUM = exports.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_SCHEMA_VERSION = exports.SALES_COMPARISON_KEY_FILTERS = exports.MATERIALIZED_SALES_COMPARISON_REPORT_SCOPES = exports.MATERIALIZED_TENANT_SALES_COMPARISON_ENTRIES_COLLECTION_NAME = exports.MATERIALIZED_TENANT_SALES_COMPARISON_REPORTS_COLLECTION_NAME = exports.ALL_MATERIALIZED_REPORT_TYPES = exports.MATERIALIZED_REPORT_TYPE_ENUM = exports.ALL_MATERIALIZED_PREP_TIME_TARGETS = exports.MATERIALIZED_PREP_TIME_TARGET_ENUM = exports.MATERIALIZED_PREP_TIME_ON_TIME_MAX_DELTA = exports.MATERIALIZED_PREP_TIME_TOP_BUCKET = exports.MATERIALIZED_PREP_TIME_MAX_MINUTES = exports.ALL_MATERIALIZED_PREP_TIME_BUCKET_LABELS = exports.MATERIALIZED_PREP_TIME_BUCKETS = exports.ALL_MATERIALIZED_PREP_TIME_ANCHORS = exports.MATERIALIZED_PREP_TIME_ANCHOR_ENUM = exports.PREP_TIME_KEY_FILTERS = exports.MATERIALIZED_PREP_TIME_ITEM_MAX_READ_DAYS = exports.MATERIALIZED_PREP_TIME_ITEM_SCOPES = exports.MATERIALIZED_PREP_TIME_REPORT_SCOPES = exports.MATERIALIZED_DELIVERY_GEO_CELL_MAX_BSON_BYTES = exports.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES = exports.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES = exports.MATERIALIZED_DELIVERY_GEO_UNKNOWN_CELL = exports.MATERIALIZED_DELIVERY_GEO_MONTH_RETENTION_MONTHS = exports.MATERIALIZED_DELIVERY_GEO_DAY_RETENTION_DAYS = exports.MATERIALIZED_DELIVERY_GEO_MAX_CELLS = exports.MATERIALIZED_DELIVERY_GEO_MIN_ORDERS = void 0;
15
- exports.MATERIALIZED_READINESS_REPORT_KEYS = exports.ALL_MATERIALIZED_REPORT_READINESS_STATUSES = exports.MATERIALIZED_REPORT_READINESS_STATUS_ENUM = exports.MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DAY_READINESS_COLLECTION_NAME = exports.MATERIALIZED_DINEIN_RESERVATIONS_TIME_INDEX_OPTIONS = exports.MATERIALIZED_DINEIN_FINGERPRINTS_CREATED_AT_INDEX_OPTIONS = exports.MATERIALIZED_DINEIN_FINGERPRINTS_ORDER_INDEX_OPTIONS = exports.MATERIALIZED_DINEIN_ENTRY_MAX_BSON_BYTES = exports.MATERIALIZED_DINEIN_REPORT_MAX_BSON_BYTES = exports.ALL_MATERIALIZED_DINEIN_PAYMENT_CLASSES = exports.MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM = exports.ALL_MATERIALIZED_DINEIN_SPLIT_ROLES = exports.MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM = exports.ALL_MATERIALIZED_DINEIN_ORIGINS = exports.MATERIALIZED_DINEIN_ORIGIN_ENUM = exports.MATERIALIZED_DINEIN_SPLIT_PARENT_DELETE_REASON = exports.MATERIALIZED_DINEIN_HOUR_KEYS = exports.MATERIALIZED_DINEIN_TOP_EDITED_CHECK_LIMIT = exports.MATERIALIZED_DINEIN_UPCOMING_RESERVATION_LIMIT = exports.MATERIALIZED_DINEIN_SERVICE_CHARGE_RATE_LIMIT = exports.MATERIALIZED_DINEIN_COURSE_LIMIT = exports.MATERIALIZED_DINEIN_FLOOR_LIMIT = exports.MATERIALIZED_DINEIN_TABLE_LIMIT = exports.MATERIALIZED_DINEIN_OTHER_TOKEN = exports.MATERIALIZED_DINEIN_KEY_SEPARATOR = exports.MATERIALIZED_DINEIN_UNKNOWN_TOKEN = exports.DINEIN_KEY_FILTERS = exports.MATERIALIZED_DINEIN_ENTRY_PAGE_ALL = exports.MATERIALIZED_DINEIN_ENTRY_SCOPES = exports.MATERIALIZED_DINEIN_REPORT_SCOPES = exports.MATERIALIZED_DIALER_ENTRY_MAX_BSON_BYTES = exports.MATERIALIZED_DIALER_REPORT_MAX_BSON_BYTES = exports.MATERIALIZED_DIALER_HOUR_KEYS = exports.MATERIALIZED_DIALER_KEY_SEPARATOR = exports.MATERIALIZED_DIALER_UNKNOWN_TOKEN = exports.DIALER_KEY_FILTERS = void 0;
15
+ exports.MATERIALIZED_REPORT_RUN_COMMIT_OUTCOME_UNKNOWN_ERROR = exports.MATERIALIZED_REPORT_RUN_INTERRUPTED_ERROR = exports.MATERIALIZED_TENANT_REPORT_RUN_STALE_MS = exports.MATERIALIZED_TENANT_REPORT_RUN_ERROR_MAX_LENGTH = exports.MATERIALIZED_TENANT_REPORT_RUN_MAX_ATTEMPTS = exports.MATERIALIZED_TENANT_REPORT_RUN_IN_FLIGHT_STATUSES = exports.ALL_MATERIALIZED_TENANT_REPORT_RUN_STATUSES = exports.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM = exports.MATERIALIZED_TENANT_REPORT_RUNS_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_REPORT_RUNS_COLLECTION_NAME = exports.MATERIALIZED_READINESS_REPORT_KEYS = exports.ALL_MATERIALIZED_REPORT_READINESS_STATUSES = exports.MATERIALIZED_REPORT_READINESS_STATUS_ENUM = exports.MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DAY_READINESS_COLLECTION_NAME = exports.MATERIALIZED_DINEIN_RESERVATIONS_TIME_INDEX_OPTIONS = exports.MATERIALIZED_DINEIN_FINGERPRINTS_CREATED_AT_INDEX_OPTIONS = exports.MATERIALIZED_DINEIN_FINGERPRINTS_ORDER_INDEX_OPTIONS = exports.MATERIALIZED_DINEIN_ENTRY_MAX_BSON_BYTES = exports.MATERIALIZED_DINEIN_REPORT_MAX_BSON_BYTES = exports.ALL_MATERIALIZED_DINEIN_PAYMENT_CLASSES = exports.MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM = exports.ALL_MATERIALIZED_DINEIN_SPLIT_ROLES = exports.MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM = exports.ALL_MATERIALIZED_DINEIN_ORIGINS = exports.MATERIALIZED_DINEIN_ORIGIN_ENUM = exports.MATERIALIZED_DINEIN_SPLIT_PARENT_DELETE_REASON = exports.MATERIALIZED_DINEIN_HOUR_KEYS = exports.MATERIALIZED_DINEIN_TOP_EDITED_CHECK_LIMIT = exports.MATERIALIZED_DINEIN_UPCOMING_RESERVATION_LIMIT = exports.MATERIALIZED_DINEIN_SERVICE_CHARGE_RATE_LIMIT = exports.MATERIALIZED_DINEIN_COURSE_LIMIT = exports.MATERIALIZED_DINEIN_FLOOR_LIMIT = exports.MATERIALIZED_DINEIN_TABLE_LIMIT = exports.MATERIALIZED_DINEIN_OTHER_TOKEN = exports.MATERIALIZED_DINEIN_KEY_SEPARATOR = exports.MATERIALIZED_DINEIN_UNKNOWN_TOKEN = exports.DINEIN_KEY_FILTERS = exports.MATERIALIZED_DINEIN_ENTRY_PAGE_ALL = exports.MATERIALIZED_DINEIN_ENTRY_SCOPES = exports.MATERIALIZED_DINEIN_REPORT_SCOPES = exports.MATERIALIZED_DIALER_ENTRY_MAX_BSON_BYTES = exports.MATERIALIZED_DIALER_REPORT_MAX_BSON_BYTES = exports.MATERIALIZED_DIALER_HOUR_KEYS = exports.MATERIALIZED_DIALER_KEY_SEPARATOR = exports.MATERIALIZED_DIALER_UNKNOWN_TOKEN = exports.DIALER_KEY_FILTERS = void 0;
16
16
  /**
17
17
  * Time-scope of a materialized report document. Every document covers exactly
18
18
  * one tenant × one scope context × one scope value (`scope_field`), and the
@@ -1117,3 +1117,80 @@ exports.MATERIALIZED_READINESS_REPORT_KEYS = [
1117
1117
  'DIALER',
1118
1118
  'DINEIN',
1119
1119
  ];
1120
+ /* ======================================================================== */
1121
+ /* Report run ledger (ONE row per report execution) */
1122
+ /* ======================================================================== */
1123
+ /**
1124
+ * DURABLE OPERATIONAL LEDGER of one report's execution, SEPARATE from
1125
+ * readiness.
1126
+ *
1127
+ * Readiness answers "may a historical read treat this tenant-day-report as
1128
+ * final?" (only COMMITTED / NEEDS_RECONCILIATION ever appear there).
1129
+ * This ledger answers "what happened to the execution?" and is the ONLY place
1130
+ * a failed attempt is recorded (PENDING / RUNNING / RETRYING / COMMITTED /
1131
+ * FAILED), so a FAILED report never - and can never - look materialized.
1132
+ *
1133
+ * One row per `(tenant_id, localDate, report_key, schema_version)`. The row is
1134
+ * operational state: it is written OUTSIDE the report transaction (a rollback
1135
+ * must not erase the fact that the attempt happened). Readiness is written
1136
+ * INSIDE the report transaction. The two therefore have different lifecycles
1137
+ * and are deliberately different collections.
1138
+ *
1139
+ * Phase 1 replaces the one all-report END_TENANT_DAY transaction with one
1140
+ * transaction per report: each report commits (or fails) on its own, and this
1141
+ * ledger is the operator-visible record of that per-report outcome.
1142
+ */
1143
+ exports.MATERIALIZED_TENANT_REPORT_RUNS_COLLECTION_NAME = 'materialized_tenant_report_runs';
1144
+ /** Version of the report-run row shape. Pinned to 1 with the other collections. */
1145
+ exports.MATERIALIZED_TENANT_REPORT_RUNS_SCHEMA_VERSION = 1;
1146
+ /** The execution state of one tenant-day-report run. */
1147
+ var MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM;
1148
+ (function (MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM) {
1149
+ /** The row exists but no attempt has started yet. */
1150
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["PENDING"] = "PENDING";
1151
+ /** An attempt is executing (its own transaction is open or about to open). */
1152
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["RUNNING"] = "RUNNING";
1153
+ /** A transient failure happened; another attempt is starting. */
1154
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["RETRYING"] = "RETRYING";
1155
+ /** The report transaction committed: documents + readiness are durable. */
1156
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["COMMITTED"] = "COMMITTED";
1157
+ /** Every allowed attempt was exhausted; readiness was NOT written. */
1158
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["FAILED"] = "FAILED";
1159
+ })(MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM || (exports.MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM = MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM = {}));
1160
+ exports.ALL_MATERIALIZED_TENANT_REPORT_RUN_STATUSES = Object.values(MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM);
1161
+ /** States in which an execution currently owns the report (retry is refused). */
1162
+ exports.MATERIALIZED_TENANT_REPORT_RUN_IN_FLIGHT_STATUSES = [
1163
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.PENDING,
1164
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.RUNNING,
1165
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.RETRYING,
1166
+ ];
1167
+ /**
1168
+ * Bounded attempt budget of ONE report execution (transient errors only).
1169
+ * A deterministic code/compile error is NEVER retried inside the job.
1170
+ */
1171
+ exports.MATERIALIZED_TENANT_REPORT_RUN_MAX_ATTEMPTS = 2;
1172
+ /** Bounded size of the stored `last_error` (single-line, PII-redacted). */
1173
+ exports.MATERIALIZED_TENANT_REPORT_RUN_ERROR_MAX_LENGTH = 500;
1174
+ /**
1175
+ * Stale window of a report-run row (RUNNING / RETRYING).
1176
+ *
1177
+ * A run that has not reached a terminal state within this window MAY have been
1178
+ * interrupted (process crash). Recovery NEVER trusts the age alone: it also
1179
+ * requires the tenant's active-job heartbeat to be stale, so a live long-running
1180
+ * report is never taken over. The value mirrors the active-job lease window
1181
+ * (30 minutes) so both fences agree.
1182
+ */
1183
+ exports.MATERIALIZED_TENANT_REPORT_RUN_STALE_MS = 30 * 60 * 1000;
1184
+ /**
1185
+ * Durable `last_error` of a run recovered after an interruption with NO
1186
+ * readiness row (the report transaction provably did not commit).
1187
+ */
1188
+ exports.MATERIALIZED_REPORT_RUN_INTERRUPTED_ERROR = 'INTERRUPTED_RUN';
1189
+ /**
1190
+ * Durable `last_error` of a run whose transaction COMMIT outcome is UNKNOWN.
1191
+ *
1192
+ * Such a run is deliberately left NON-terminal (`RUNNING`): the transaction may
1193
+ * have committed. Stale-run recovery settles it from ownership-checked
1194
+ * readiness (`readiness.run_id === run.run_id`), never by guessing here.
1195
+ */
1196
+ exports.MATERIALIZED_REPORT_RUN_COMMIT_OUTCOME_UNKNOWN_ERROR = 'COMMIT_OUTCOME_UNKNOWN';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * PURE materialized-report schema versions.
3
+ *
4
+ * The close-day plans stamp these versions on the documents they build, so the
5
+ * COMPILE graph must be able to read them without importing a mongoose schema
6
+ * model (the schema files re-export these constants for their existing API).
7
+ *
8
+ * Keep this module dependency-free: it is imported by the worker compile path.
9
+ */
10
+ export declare const MATERIALIZED_CREDIT_BILLS_SCHEMA_VERSION = 1;
11
+ export declare const MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 1;
12
+ export declare const MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 1;
13
+ export declare const MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION = 1;
14
+ export declare const MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION = 1;
15
+ export declare const MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION = 1;
16
+ export declare const MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION = 1;
17
+ export declare const MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = exports.MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = exports.MATERIALIZED_CREDIT_BILLS_SCHEMA_VERSION = void 0;
4
+ /**
5
+ * PURE materialized-report schema versions.
6
+ *
7
+ * The close-day plans stamp these versions on the documents they build, so the
8
+ * COMPILE graph must be able to read them without importing a mongoose schema
9
+ * model (the schema files re-export these constants for their existing API).
10
+ *
11
+ * Keep this module dependency-free: it is imported by the worker compile path.
12
+ */
13
+ exports.MATERIALIZED_CREDIT_BILLS_SCHEMA_VERSION = 1;
14
+ exports.MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 1;
15
+ exports.MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 1;
16
+ exports.MATERIALIZED_TENANT_DIALER_ENTRIES_SCHEMA_VERSION = 1;
17
+ exports.MATERIALIZED_TENANT_DIALER_REPORTS_SCHEMA_VERSION = 1;
18
+ exports.MATERIALIZED_TENANT_DINEIN_ENTRIES_SCHEMA_VERSION = 1;
19
+ exports.MATERIALIZED_TENANT_DINEIN_REPORTS_SCHEMA_VERSION = 1;
20
+ exports.MATERIALIZED_TENANT_SALES_OVERVIEW_REPORTS_SCHEMA_VERSION = 1;
@@ -78,3 +78,17 @@ export declare enum TENANT_ACTIVE_JOBS_ENUM {
78
78
  Z_REPORT = "Z_REPORT"
79
79
  }
80
80
  export declare const ALL_TENANT_ACTIVE_JOBS_NAMES: TENANT_ACTIVE_JOBS_ENUM[];
81
+ /**
82
+ * Terminal outcome of ONE close/retry run that owned the tenant's CALENDAR job.
83
+ *
84
+ * `PARTIAL` is the per-report model's outcome: at least one report FAILED while
85
+ * others committed. It is NEVER a readiness status - readiness keeps only
86
+ * COMMITTED / NEEDS_RECONCILIATION; the failed report lives in the operational
87
+ * run ledger (`materialized_tenant_report_runs`).
88
+ */
89
+ export declare enum TENANT_DAY_JOB_OUTCOME_ENUM {
90
+ COMPLETED = "COMPLETED",
91
+ PARTIAL = "PARTIAL",
92
+ FAILED = "FAILED"
93
+ }
94
+ export declare const ALL_TENANT_DAY_JOB_OUTCOMES: TENANT_DAY_JOB_OUTCOME_ENUM[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ALL_TENANT_ACTIVE_JOBS_NAMES = exports.TENANT_ACTIVE_JOBS_ENUM = exports.ALL_TENANT_ACTIVITY_LOG_SEVERITY_NAMES = exports.TENANT_ACTIVITY_LOG_SEVERITY_ENUM = exports.ALL_TENANT_ACTIVITY_LOG_ACTION_NAMES = exports.TENANT_ACTIVITY_LOG_ACTION_ENUM = exports.ALL_TENANT_ACTIVITY_LOG_ENTITY_TYPE_NAMES = exports.TENANT_ACTIVITY_LOG_ENTITY_TYPE_ENUM = exports.ALL_TENANT_PURCHASE_ORDER_VENDOR_RETURN_STATUS_NAMES = exports.TENANT_PURCHASE_ORDER_VENDOR_RETURN_STATUS_ENUM = exports.ALL_TENANT_PURCHASE_ORDER_STATUS_NAMES = exports.TENANT_PURCHASE_ORDER_STATUS_ENUM = void 0;
3
+ exports.ALL_TENANT_DAY_JOB_OUTCOMES = exports.TENANT_DAY_JOB_OUTCOME_ENUM = exports.ALL_TENANT_ACTIVE_JOBS_NAMES = exports.TENANT_ACTIVE_JOBS_ENUM = exports.ALL_TENANT_ACTIVITY_LOG_SEVERITY_NAMES = exports.TENANT_ACTIVITY_LOG_SEVERITY_ENUM = exports.ALL_TENANT_ACTIVITY_LOG_ACTION_NAMES = exports.TENANT_ACTIVITY_LOG_ACTION_ENUM = exports.ALL_TENANT_ACTIVITY_LOG_ENTITY_TYPE_NAMES = exports.TENANT_ACTIVITY_LOG_ENTITY_TYPE_ENUM = exports.ALL_TENANT_PURCHASE_ORDER_VENDOR_RETURN_STATUS_NAMES = exports.TENANT_PURCHASE_ORDER_VENDOR_RETURN_STATUS_ENUM = exports.ALL_TENANT_PURCHASE_ORDER_STATUS_NAMES = exports.TENANT_PURCHASE_ORDER_STATUS_ENUM = void 0;
4
4
  // ======================>> TENANT PURCHASE ORDER <<====================== //
5
5
  var TENANT_PURCHASE_ORDER_STATUS_ENUM;
6
6
  (function (TENANT_PURCHASE_ORDER_STATUS_ENUM) {
@@ -91,3 +91,18 @@ var TENANT_ACTIVE_JOBS_ENUM;
91
91
  TENANT_ACTIVE_JOBS_ENUM["Z_REPORT"] = "Z_REPORT";
92
92
  })(TENANT_ACTIVE_JOBS_ENUM || (exports.TENANT_ACTIVE_JOBS_ENUM = TENANT_ACTIVE_JOBS_ENUM = {}));
93
93
  exports.ALL_TENANT_ACTIVE_JOBS_NAMES = Object.values(TENANT_ACTIVE_JOBS_ENUM);
94
+ /**
95
+ * Terminal outcome of ONE close/retry run that owned the tenant's CALENDAR job.
96
+ *
97
+ * `PARTIAL` is the per-report model's outcome: at least one report FAILED while
98
+ * others committed. It is NEVER a readiness status - readiness keeps only
99
+ * COMMITTED / NEEDS_RECONCILIATION; the failed report lives in the operational
100
+ * run ledger (`materialized_tenant_report_runs`).
101
+ */
102
+ var TENANT_DAY_JOB_OUTCOME_ENUM;
103
+ (function (TENANT_DAY_JOB_OUTCOME_ENUM) {
104
+ TENANT_DAY_JOB_OUTCOME_ENUM["COMPLETED"] = "COMPLETED";
105
+ TENANT_DAY_JOB_OUTCOME_ENUM["PARTIAL"] = "PARTIAL";
106
+ TENANT_DAY_JOB_OUTCOME_ENUM["FAILED"] = "FAILED";
107
+ })(TENANT_DAY_JOB_OUTCOME_ENUM || (exports.TENANT_DAY_JOB_OUTCOME_ENUM = TENANT_DAY_JOB_OUTCOME_ENUM = {}));
108
+ exports.ALL_TENANT_DAY_JOB_OUTCOMES = Object.values(TENANT_DAY_JOB_OUTCOME_ENUM);
@@ -28,8 +28,6 @@ export declare const WORKER_ENDPOINTS: {
28
28
  readonly INCREMENT_CASH_IN_HAND: "/increment-cash-in-hand";
29
29
  readonly REMOVE_DINEIN_TABLE: "/remove-dinein-table";
30
30
  readonly UPDATE_MODIFIER_NAME_IN_ITEMS: "/update-modifier-name-in-items";
31
- readonly ITEMS_USING_MODIFIER: "/items-using-modifier";
32
- readonly AUDIT_ITEM_MODIFIERS: "/audit-item-modifiers";
33
31
  readonly PROCESS_SWITCHPAY_PAYMENT_FOR_ORDER: "/process-switchpay-payment-for-order";
34
32
  readonly COMMIT_SWITCHPAY_PAYMENT_FOR_ORDER: "/commit-switchpay-payment-for-order";
35
33
  readonly SYNC_SWITCHPAY_PAYMENT_SUCCESS: "/sync-switchpay-payment-success";
@@ -65,4 +63,16 @@ export declare const WORKER_ENDPOINTS: {
65
63
  readonly POST_WAREHOUSE_ACTIVITY_LOGS: "/post-warehouse-activity-logs";
66
64
  readonly END_INSTORE_SHIFT: "/end-instore-shift";
67
65
  readonly END_TENANT_DAY: "/end-tenant-day";
66
+ /**
67
+ * INTERNAL, report-scoped retry of ONE failed END_TENANT_DAY report.
68
+ * Operations-service is the only caller (POST /materialization/reports/retry).
69
+ * Never a whole-day retry.
70
+ */
71
+ readonly RETRY_MATERIALIZED_REPORT: "/internal/materialization/reports/retry";
72
+ /**
73
+ * INTERNAL, worker-owned recovery of INTERRUPTED report runs (RUNNING /
74
+ * RETRYING). Called before the retry API rejects a RUNNING report and before
75
+ * listing runs for the admin page. Never fabricates readiness.
76
+ */
77
+ readonly RECONCILE_MATERIALIZED_REPORT_RUNS: "/internal/materialization/reports/reconcile";
68
78
  };