@managesome/eposmatic-toolkit 0.4.51 → 0.4.53

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 (97) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +106 -2
  2. package/esm/constants/enums/delivery.js +13 -0
  3. package/esm/helpers/materialized-reports/index.js +5 -0
  4. package/esm/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
  5. package/esm/helpers/materialized-reports/materialized-delivery-classification-helpers.js +95 -73
  6. package/esm/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +118 -146
  7. package/esm/helpers/materialized-reports/materialized-delivery-compile-helpers.js +304 -71
  8. package/esm/helpers/materialized-reports/materialized-delivery-entry-pages.js +307 -0
  9. package/esm/helpers/materialized-reports/materialized-delivery-index-migration.js +103 -0
  10. package/esm/helpers/materialized-reports/materialized-delivery-rows.js +109 -0
  11. package/esm/helpers/materialized-reports/materialized-delivery-wipe-targets.js +32 -0
  12. package/esm/helpers/materialized-reports/materialized-document-size.js +65 -0
  13. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +31 -16
  14. package/esm/helpers/materialized-reports/materialized-integer-contract.js +10 -1
  15. package/esm/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +3 -91
  16. package/esm/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +597 -0
  17. package/esm/helpers/materialized-reports/scope-helpers.js +98 -0
  18. package/esm/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
  19. package/esm/helpers/utils/offer-item-resolution.js +39 -0
  20. package/esm/schemas/models/index.js +12 -10
  21. package/esm/schemas/models/materialized_tenant_delivery_entries.js +33 -12
  22. package/esm/schemas/models/materialized_tenant_delivery_geo_cells.js +83 -0
  23. package/esm/schemas/models/materialized_tenant_delivery_geo_scopes.js +35 -0
  24. package/esm/schemas/models/materialized_tenant_delivery_reports.js +10 -1
  25. package/esm/schemas/types/index.js +14 -12
  26. package/esm/schemas/types/materialized_tenant_delivery_geo_cells.js +1 -0
  27. package/esm/schemas/types/materialized_tenant_delivery_geo_scopes.js +1 -0
  28. package/lib/constants/MATERIALIZED_REPORTS.d.ts +95 -1
  29. package/lib/constants/MATERIALIZED_REPORTS.js +108 -4
  30. package/lib/constants/enums/delivery.d.ts +9 -0
  31. package/lib/constants/enums/delivery.js +14 -1
  32. package/lib/helpers/materialized-reports/index.d.ts +5 -0
  33. package/lib/helpers/materialized-reports/index.js +5 -0
  34. package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
  35. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +36 -9
  36. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +94 -72
  37. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +23 -26
  38. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +121 -150
  39. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +44 -5
  40. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +306 -69
  41. package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.d.ts +128 -0
  42. package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.js +322 -0
  43. package/lib/helpers/materialized-reports/materialized-delivery-index-migration.d.ts +48 -0
  44. package/lib/helpers/materialized-reports/materialized-delivery-index-migration.js +108 -0
  45. package/lib/helpers/materialized-reports/materialized-delivery-rows.d.ts +15 -0
  46. package/lib/helpers/materialized-reports/materialized-delivery-rows.js +115 -0
  47. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +17 -0
  48. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +35 -0
  49. package/lib/helpers/materialized-reports/materialized-document-size.d.ts +47 -0
  50. package/lib/helpers/materialized-reports/materialized-document-size.js +73 -0
  51. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +28 -13
  52. package/lib/helpers/materialized-reports/materialized-integer-contract.js +10 -1
  53. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +2 -90
  54. package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.d.ts +186 -0
  55. package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +620 -0
  56. package/lib/helpers/materialized-reports/scope-helpers.d.ts +8 -0
  57. package/lib/helpers/materialized-reports/scope-helpers.js +99 -0
  58. package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +41 -0
  59. package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
  60. package/lib/helpers/utils/offer-item-resolution.d.ts +28 -0
  61. package/lib/helpers/utils/offer-item-resolution.js +41 -0
  62. package/lib/schemas/models/index.d.ts +12 -10
  63. package/lib/schemas/models/index.js +12 -10
  64. package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +31 -9
  65. package/lib/schemas/models/materialized_tenant_delivery_entries.js +32 -11
  66. package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +129 -0
  67. package/lib/schemas/models/materialized_tenant_delivery_geo_cells.js +86 -0
  68. package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +71 -0
  69. package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.js +38 -0
  70. package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +10 -1
  71. package/lib/schemas/models/materialized_tenant_delivery_reports.js +10 -1
  72. package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +15 -15
  73. package/lib/schemas/types/index.d.ts +14 -12
  74. package/lib/schemas/types/index.js +14 -12
  75. package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +36 -4
  76. package/lib/schemas/types/materialized_tenant_delivery_geo_cells.d.ts +178 -0
  77. package/lib/schemas/types/materialized_tenant_delivery_geo_cells.js +2 -0
  78. package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.d.ts +21 -0
  79. package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.js +2 -0
  80. package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +49 -7
  81. package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +56 -19
  82. package/lib/tests/materialized-reports/materialized-delivery-budgets.test.d.ts +1 -0
  83. package/lib/tests/materialized-reports/materialized-delivery-budgets.test.js +91 -0
  84. package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +271 -15
  85. package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.d.ts +1 -0
  86. package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.js +128 -0
  87. package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +42 -5
  88. package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +13 -1
  89. package/lib/tests/materialized-reports/materialized-delivery-geo.test.d.ts +1 -0
  90. package/lib/tests/materialized-reports/materialized-delivery-geo.test.js +446 -0
  91. package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +117 -25
  92. package/lib/tests/materialized-reports/materialized-delivery-practical.test.d.ts +1 -0
  93. package/lib/tests/materialized-reports/materialized-delivery-practical.test.js +344 -0
  94. package/lib/tests/materialized-reports/materialized-integer-contract.test.js +14 -0
  95. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +1 -1
  96. package/lib/tests/offer-item-resolution.test.js +57 -0
  97. package/package.json +4 -2
@@ -47,17 +47,26 @@ __exportStar(require("./item_transactions"), exports);
47
47
  __exportStar(require("./items"), exports);
48
48
  __exportStar(require("./marketing_fingerprints"), exports);
49
49
  __exportStar(require("./materialized_credit_bills"), exports);
50
- __exportStar(require("./materialized_tenant_discount_entries"), exports);
51
- __exportStar(require("./materialized_tenant_discount_reports"), exports);
52
- __exportStar(require("./materialized_tenant_discount_sources"), exports);
50
+ __exportStar(require("./materialized_report_drilldown_rows"), exports);
51
+ __exportStar(require("./materialized_rider_daily_reports"), exports);
53
52
  __exportStar(require("./materialized_tenant_cash_entries"), exports);
53
+ __exportStar(require("./materialized_tenant_cash_reports"), exports);
54
54
  __exportStar(require("./materialized_tenant_delivery_entries"), exports);
55
+ __exportStar(require("./materialized_tenant_delivery_geo_cells"), exports);
56
+ __exportStar(require("./materialized_tenant_delivery_geo_scopes"), exports);
55
57
  __exportStar(require("./materialized_tenant_delivery_reports"), exports);
56
- __exportStar(require("./materialized_rider_daily_reports"), exports);
57
- __exportStar(require("./materialized_tenant_cash_reports"), exports);
58
+ __exportStar(require("./materialized_tenant_discount_entries"), exports);
59
+ __exportStar(require("./materialized_tenant_discount_reports"), exports);
60
+ __exportStar(require("./materialized_tenant_discount_sources"), exports);
61
+ __exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
62
+ __exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
63
+ __exportStar(require("./materialized_tenant_payments_comparison_entries"), exports);
64
+ __exportStar(require("./materialized_tenant_payments_comparison_reports"), exports);
58
65
  __exportStar(require("./materialized_tenant_prep_time_entries"), exports);
59
66
  __exportStar(require("./materialized_tenant_prep_time_reports"), exports);
60
67
  __exportStar(require("./materialized_tenant_reports_iterations"), exports);
68
+ __exportStar(require("./materialized_tenant_sales_comparison_entries"), exports);
69
+ __exportStar(require("./materialized_tenant_sales_comparison_reports"), exports);
61
70
  __exportStar(require("./materialized_tenant_sales_overview_reports"), exports);
62
71
  __exportStar(require("./menus"), exports);
63
72
  __exportStar(require("./messaging_devices"), exports);
@@ -140,10 +149,3 @@ __exportStar(require("./warehouse_vendors"), exports);
140
149
  __exportStar(require("./warehouse_void_purchase_order_items"), exports);
141
150
  __exportStar(require("./warehouse_void_sale_order_items"), exports);
142
151
  __exportStar(require("./warehouses"), exports);
143
- __exportStar(require("./materialized_tenant_sales_comparison_reports"), exports);
144
- __exportStar(require("./materialized_tenant_sales_comparison_entries"), exports);
145
- __exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
146
- __exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
147
- __exportStar(require("./materialized_tenant_payments_comparison_reports"), exports);
148
- __exportStar(require("./materialized_tenant_payments_comparison_entries"), exports);
149
- __exportStar(require("./materialized_report_drilldown_rows"), exports);
@@ -2,7 +2,7 @@ import { DAY_INDEX_ENUM } from '../../constants/ENUMS';
2
2
  import { DELIVERY_STATUS_ENUM } from '../../constants/enums/delivery';
3
3
  import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
4
4
  /**
5
- * Types for `materialized_tenant_delivery_entries` (M4, decision (e4)).
5
+ * Types for `materialized_tenant_delivery_entries` (M4, page-partitioned).
6
6
  *
7
7
  * The statement rows behind the delivery drill-down. The POLYLINE IS NOT STORED: a GPS
8
8
  * trace per row would dominate the collection, so a row keeps only its POINT COUNT and a
@@ -12,6 +12,19 @@ import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } f
12
12
  * `order_id` at compile time, so the read needs no second lookup and the drill-down can
13
13
  * show what an operator recognises.
14
14
  *
15
+ * ## ONE PAGE PER SOURCE DAY
16
+ *
17
+ * A document is bounded by ONE day's rows, never a month's:
18
+ *
19
+ * | scope | page |
20
+ * | --- | --- |
21
+ * | `localDate` | `'all'` |
22
+ * | `localWeek` / `localWeekOfYear` / `localMonth` | `<source localDate>` |
23
+ *
24
+ * There are NO quarter / semester / year entry documents. A broad details selection is
25
+ * served by reading the month pages it touches and filtering rows to the exact selected
26
+ * days.
27
+ *
15
28
  * Null means UNMEASURED, never zero: `assigned_at` / `delivered_at` are null on any
16
29
  * document written before the metrics capture, and every derived duration is null rather
17
30
  * than 0 - reporting 0 would claim the delivery was instantaneous.
@@ -36,9 +49,18 @@ export interface IMaterializedDeliveryEntry {
36
49
  /** Trace SIZE only - the polyline itself is deliberately not stored. */
37
50
  polyline_point_count: number;
38
51
  platform: string;
52
+ /** ORDER_STATUS_ENUM of the joined order (or UNKNOWN). */
53
+ order_status: string;
39
54
  city: string | null;
40
55
  state: string | null;
41
- street: string | null;
56
+ /**
57
+ * Tenant-local source day of the row: the JOINED ORDER's `localDate`.
58
+ * Falls back to `delivery.localDate` only when the order is missing, and then
59
+ * `source_day_unattributed` is true.
60
+ */
61
+ source_local_date: string;
62
+ /** True when the order was missing and the source day fell back to the delivery. */
63
+ source_day_unattributed: boolean;
42
64
  /** CENTS. */
43
65
  net_sale_amount: number;
44
66
  collected_amount: number;
@@ -64,20 +86,30 @@ export interface IMaterializedDeliveryEntry {
64
86
  created_at: Date;
65
87
  /** Time-of-day stamp, mirroring the delivery document field. */
66
88
  created_at_mins: number | null;
67
- /** `YYYY-MM-DD HH` punch hour (null when unresolvable). */
89
+ /**
90
+ * Tenant-local stamp of the joined ORDER: `${YYYY-MM-DD} ${HH:MM}` when the
91
+ * order's minute is known, `${YYYY-MM-DD} ${HH}` when only the hour exists
92
+ * (never a synthetic `:00`), null when unresolvable.
93
+ */
68
94
  local_hour: string | null;
69
95
  }
70
96
  /** Per-key row section of one document. */
71
97
  export interface IMaterializedDeliveryKeySection {
72
98
  rows: IMaterializedDeliveryEntry[];
73
99
  }
74
- /** One `materialized_tenant_delivery_entries` document, capped at `LOCAL_MONTH`. */
100
+ /**
101
+ * One `materialized_tenant_delivery_entries` PAGE - tenant x scope context x scope
102
+ * value x source day. One page holds one day's rows; a month is covered by its days.
103
+ */
75
104
  export interface IMaterializedTenantDeliveryEntries {
76
105
  _id: string;
77
106
  tenant_id: string;
78
107
  brand_id: string;
108
+ /** One of `MATERIALIZED_DELIVERY_ENTRY_SCOPES` (date / week / ISO week / month). */
79
109
  scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
80
110
  scope_field: string;
111
+ /** `'all'` for the day scope; the source `YYYY-MM-DD` for a period scope. */
112
+ page: string;
81
113
  /** Denormalized weekday - set ONLY on `LOCAL_DATE` documents. */
82
114
  day_index?: DAY_INDEX_ENUM | null;
83
115
  sale_type_key_filters: MATERIALIZED_REPORT_KEY_FILTER_ENUM[];
@@ -0,0 +1,178 @@
1
+ import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
2
+ /**
3
+ * Types for `materialized_tenant_delivery_geo_cells` (delivery demand heat map).
4
+ *
5
+ * ## Why this is a SEPARATE collection
6
+ *
7
+ * The heat map is the only part of the delivery report whose cardinality depends on
8
+ * GEOGRAPHY rather than on a fixed dimension set. Embedding it in the report document
9
+ * would put an unbounded array of cells next to the counters and eventually breach the
10
+ * 16 MiB document limit. So the report document stays counters-only and the cells live
11
+ * here, one document per cell.
12
+ *
13
+ * ## One document per `tenant_id + scope_context + scope_field + h3_cell`
14
+ *
15
+ * `scope_context` is ONLY `localDate` or `localMonth`. Each document is a cell's
16
+ * aggregate for one day or one month - never a raw order, never a raw customer point.
17
+ *
18
+ * ## No raw coordinates, ever
19
+ *
20
+ * The only geometry stored is the cell's DERIVED CENTROID (the H3 cell centre), which
21
+ * is a property of the cell and identical for every order inside it. The unknown bucket
22
+ * (`__UNKNOWN__`) deliberately has NO `location` at all, so an unattributable order can
23
+ * never be plotted.
24
+ *
25
+ * ## Money and counts are integer CENTS / counts
26
+ *
27
+ * `net_sale_amount` / `delivery_charge_amount` / `rider_revenue_amount` are integer
28
+ * cents; every other numeric field is an integer count, per the toolkit's
29
+ * integer-only storage contract.
30
+ */
31
+ export interface IDeliveryGeoPoint {
32
+ type: 'Point';
33
+ /** `[lng, lat]` - GeoJSON order, required by the 2dsphere index. */
34
+ coordinates: [number, number];
35
+ }
36
+ /** The counters of ONE heat cell. All integers; money in CENTS. */
37
+ export interface IMaterializedDeliveryGeoCounters {
38
+ /** Delivery ORDERS in the cell (the adoption denominator / demand unit). */
39
+ orders: number;
40
+ /** Unique orders in the cell that produced at least one delivery document. */
41
+ app_orders: number;
42
+ /** Delivery documents / attempts in the cell (>= `app_orders` on reassignment). */
43
+ delivery_records: number;
44
+ completed: number;
45
+ cancelled: number;
46
+ net_sale_amount: number;
47
+ delivery_charge_amount: number;
48
+ rider_revenue_amount: number;
49
+ }
50
+ /** Counters for one `ORDER_STATUS:PLATFORM:CITY` dimension inside a cell. */
51
+ export type IMaterializedDeliveryGeoKeyCounters = IMaterializedDeliveryGeoCounters;
52
+ /**
53
+ * Bounded per-cell filter map. Key = `ORDER_STATUS:PLATFORM:CITY` - the SAME grammar as
54
+ * the report counters, with the RESOLVED city (top-N + `__OTHER__`, `UNKNOWN` when the
55
+ * order carries no city).
56
+ *
57
+ * Because the city is part of the key, a cell that holds orders from several cities can
58
+ * be filtered by city EXACTLY: the selected city's counters are summed out of the map
59
+ * instead of the cell being attributed to its dominant city.
60
+ *
61
+ * Sum(by_key) equals the cell's top-level counters (including the UNKNOWN token for
62
+ * orphan records). The map is capped (see MATERIALIZED_DELIVERY_GEO_MAX_KEYS).
63
+ */
64
+ export type TMaterializedDeliveryGeoByKey = Record<string, IMaterializedDeliveryGeoKeyCounters>;
65
+ /** One `materialized_tenant_delivery_geo_cells` document. */
66
+ export interface IMaterializedTenantDeliveryGeoCell extends IMaterializedDeliveryGeoCounters {
67
+ _id?: string;
68
+ tenant_id: string;
69
+ brand_id: string;
70
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
71
+ scope_field: string;
72
+ /**
73
+ * Dominant city of the cell's orders (max orders; ties resolved by city ASC), or
74
+ * `null` when the joined orders carry no city. The city is derived, never a key -
75
+ * filtering uses the by_key map, never this label.
76
+ */
77
+ city: string | null;
78
+ /** H3 cell index at `resolution`, or the sentinel `__UNKNOWN__`. */
79
+ h3_cell: string;
80
+ /** H3 resolution; `0` for the unknown bucket (which has no cell). */
81
+ resolution: number;
82
+ /**
83
+ * GeoJSON centroid of the cell. ABSENT for the unknown bucket - a document without
84
+ * `location` is simply not indexed by the 2dsphere index.
85
+ */
86
+ location?: IDeliveryGeoPoint;
87
+ /** Bounded ORDER_STATUS:PLATFORM:CITY map; sum equals the top-level counters. */
88
+ by_key?: TMaterializedDeliveryGeoByKey | null;
89
+ schema_version: number;
90
+ computed_at: Date;
91
+ createdAt?: Date;
92
+ updatedAt?: Date;
93
+ }
94
+ /**
95
+ * The heat-endpoint cell shape: aggregates ONLY.
96
+ *
97
+ * It intentionally omits `tenant_id` / `brand_id` / scope fields - the response is for
98
+ * one selection and one view, and repeating the selection on every cell would balloon
99
+ * the payload without telling the map anything.
100
+ *
101
+ * Only MAPPABLE cells appear: the response never carries a raw point and never carries a
102
+ * cell without a centroid. The difference between `total_orders` and the sum of the
103
+ * returned cells is capped / suppressed / unmappable demand - the totals are explicit so
104
+ * that gap is never mistaken for zero.
105
+ */
106
+ export interface IDeliveryGeoCellResponse {
107
+ h3_cell: string;
108
+ /**
109
+ * `[lng, lat]` derived cell centroid. ALWAYS present: a cell without geometry (the
110
+ * unknown aggregate) is not part of the map payload - the map cannot place it, and
111
+ * exposing it with a null centroid would break the frozen client contract.
112
+ */
113
+ centroid: [number, number];
114
+ resolution: number;
115
+ city: string | null;
116
+ orders: number;
117
+ app_orders: number;
118
+ delivery_records: number;
119
+ completed: number;
120
+ cancelled: number;
121
+ net_sale: number;
122
+ delivery_charge: number;
123
+ rider_revenue: number;
124
+ }
125
+ /**
126
+ * Why the heat map is intentionally disabled for a selection.
127
+ *
128
+ * `OTHER_AREAS`: `__OTHER__` is a KEY-FOLD bucket (cities beyond the report's top-50). It
129
+ * has no geography of its own, so the map cannot isolate it. Totals and tables are still
130
+ * valid; the UI must show the explanation instead of an empty map.
131
+ */
132
+ export type TDeliveryGeoMapDisabledReason = 'OTHER_AREAS';
133
+ /** `POST /reports/delivery/geo` response. */
134
+ export interface IDeliveryGeoResponse {
135
+ cells: IDeliveryGeoCellResponse[];
136
+ /** Cells hidden because `orders < MATERIALIZED_DELIVERY_GEO_MIN_ORDERS`. */
137
+ suppressed_cell_count: number;
138
+ /** Orders inside those hidden cells. */
139
+ suppressed_order_count: number;
140
+ /** Cells dropped because the scope exceeded `MATERIALIZED_DELIVERY_GEO_MAX_CELLS`. */
141
+ capped_cell_count: number;
142
+ /** Orders inside those capped cells. */
143
+ capped_order_count: number;
144
+ /**
145
+ * True when the cap counts describe the same population as the filters. Platform/
146
+ * order-status filters cannot be applied to a write-time cap, so they mark this false
147
+ * rather than silently returning 0.
148
+ */
149
+ capped_counts_exact: boolean;
150
+ /** Delivery ORDERS in the whole selected scope (from the report counters). */
151
+ total_orders: number;
152
+ /** Unique app orders in the whole selected scope. */
153
+ total_app_orders: number;
154
+ /**
155
+ * Granularity actually read for the cells.
156
+ *
157
+ * `DAY` - exact cells for the selected days (all days within day-cell retention);
158
+ * `MONTH` - whole-month cells because at least one selected day is older than the
159
+ * day-cell retention window. The UI must label a `MONTH` map as month-granular.
160
+ */
161
+ granularity: 'DAY' | 'MONTH';
162
+ /** True only when the cells cover exactly the selected days. */
163
+ exact_days: boolean;
164
+ /**
165
+ * Orders in the selected scope whose geometry could not be resolved. They are in the
166
+ * counters/totals but cannot be placed on a map; the UI must report them instead of
167
+ * silently showing a cell/total gap.
168
+ */
169
+ unknown_order_count: number;
170
+ /**
171
+ * True when the selection cannot be geographically isolated. When true, `cells` is
172
+ * ALWAYS empty and the UI must render the reason instead of a map; totals and tables
173
+ * remain valid. This is how a non-zero total with no cells is explained honestly.
174
+ */
175
+ map_disabled?: boolean;
176
+ /** Reason for `map_disabled`; null/absent when the map is available. */
177
+ map_disabled_reason?: TDeliveryGeoMapDisabledReason | null;
178
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,21 @@
1
+ import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
2
+ /**
3
+ * Small cap metadata document for ONE geo scope.
4
+ *
5
+ * The cell cap drops cells before persistence, so the dropped counts cannot be
6
+ * reconstructed at read time. This collection stores ONLY the counts, one document per
7
+ * tenant + scope + field; it never stores itemized cells or geometry.
8
+ */
9
+ export interface IMaterializedTenantDeliveryGeoScope {
10
+ _id?: string;
11
+ tenant_id: string;
12
+ brand_id: string;
13
+ scope_context: MATERIALIZED_REPORT_SCOPE_ENUM;
14
+ scope_field: string;
15
+ capped_cell_count: number;
16
+ capped_order_count: number;
17
+ schema_version: number;
18
+ computed_at: Date;
19
+ createdAt?: Date;
20
+ updatedAt?: Date;
21
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -11,7 +11,7 @@ import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } f
11
11
  * (`delivery_order_count` vs `delivered_via_app_count`) before it states any metric, and
12
12
  * `off_app_count` is published as the pool the app can win rather than as an error.
13
13
  *
14
- * KEY GRAMMAR is `<PLATFORM>:<CITY>`, both JOINED FROM THE ORDER: a delivery document
14
+ * KEY GRAMMAR is `<ORDER_STATUS>:<PLATFORM>:<CITY>`, all JOINED FROM THE ORDER: a delivery document
15
15
  * carries neither, so the report joins by `order_id` and keys on the order dimensions.
16
16
  * Rider is deliberately NOT a key dimension - rider ids are high-cardinality, so rider
17
17
  * analysis is a bounded `riders` map inside the document.
@@ -24,7 +24,7 @@ import { MATERIALIZED_REPORT_KEY_FILTER_ENUM, MATERIALIZED_REPORT_SCOPE_ENUM } f
24
24
  export interface IMaterializedDeliveryAdoption {
25
25
  /** Delivery ORDERS in scope - the denominator, from the orders stage. */
26
26
  delivery_order_count: number;
27
- /** Deliveries present in the `deliveries` collection - the numerator. */
27
+ /** UNIQUE delivery ORDERS with at least one delivery document - the numerator. */
28
28
  delivered_via_app_count: number;
29
29
  /** delivery orders with NO delivery document. NOT an error: the pool to win. */
30
30
  off_app_count: number;
@@ -55,7 +55,13 @@ export interface IMaterializedDeliveryMoney {
55
55
  tip_amount: number;
56
56
  /** Order-level discounts, in cents. */
57
57
  discount_amount: number;
58
- /** Refunded order money, in cents. */
58
+ /**
59
+ * Refunded order money, in cents - Σ `order.payments[].amount_refunded`.
60
+ *
61
+ * `IOrder` does NOT declare an order-level `amount_refunded`; refund money exists only
62
+ * on its payment rows. Reading an undeclared order field would silently report every
63
+ * refund as zero, so the accumulator sums the declared source.
64
+ */
59
65
  refund_amount: number;
60
66
  /** Tax on the delivery order, in cents. */
61
67
  tax_amount: number;
@@ -83,14 +89,44 @@ export interface IMaterializedDeliveryRiderRow {
83
89
  first_delivery_at: Date | null;
84
90
  last_delivery_at: Date | null;
85
91
  }
86
- /** One area row, carrying the hot-area hour histogram. */
92
+ /**
93
+ * One area row.
94
+ *
95
+ * AREA ROWS DISTINGUISH THE TWO POPULATIONS, because they are not the same population:
96
+ *
97
+ * - `delivery_orders` / `net_sale_amount` / `delivery_charge_amount` come from the
98
+ * ORDER side, so an OFF-APP delivery order is present (it is a real delivery sale the
99
+ * operator recognizes even when no rider-app document exists);
100
+ * - `delivery_records` / `completed_count` / `cancelled_count` / `rider_revenue_amount`
101
+ * come from the APP side (delivery documents/attempts).
102
+ *
103
+ * `app_orders` is the unique-order intersection, never the record count - one order may
104
+ * have several attempts after a reassignment and must still count once.
105
+ *
106
+ * `by_hour` is the DEMAND heat map: DELIVERY ORDERS bucketed by the JOINED ORDER's
107
+ * tenant-local `localHour` (`"00"`..`"23"`), NOT by any delivery-side hour. The delivery
108
+ * write path has no `localHour`, and deriving one from a server clock would silently
109
+ * shift the map in every non-UTC tenant.
110
+ */
87
111
  export interface IMaterializedDeliveryAreaRow {
88
- count: number;
112
+ /** All delivery ORDERS in this area - the adoption denominator and the demand unit. */
113
+ delivery_orders: number;
114
+ /** Unique orders in this area with at least one delivery document. */
115
+ app_orders: number;
116
+ /** Delivery orders in this area with NO delivery document. */
117
+ off_app_orders: number;
118
+ /** Delivery documents / attempts in this area (>= `app_orders` on reassignment). */
119
+ delivery_records: number;
89
120
  completed_count: number;
90
121
  cancelled_count: number;
122
+ /** CENTS, order side (includes off-app orders). */
123
+ net_sale_amount: number;
124
+ /** CENTS, order side (includes off-app orders). */
125
+ delivery_charge_amount: number;
126
+ /** CENTS, app side - finalized rider payout only. */
91
127
  rider_revenue_amount: number;
92
128
  distance_sum_meters: number;
93
- /** Keys are `"00"`..`"23"` - the hour dimension, as a heat map. */
129
+ /** Keys are `"00"`..`"23"` - delivery ORDERS by the order's local hour. */
94
130
  by_hour: Record<string, number>;
95
131
  }
96
132
  /**
@@ -98,8 +134,14 @@ export interface IMaterializedDeliveryAreaRow {
98
134
  * the capture has NO timing evidence, and reporting 0 would claim instant delivery.
99
135
  */
100
136
  export interface IMaterializedDeliveryTiming {
101
- /** Deliveries that contributed at least one timing figure. */
137
+ /** Deliveries that contributed at least one timing figure (compatibility total). */
102
138
  graded_count: number;
139
+ /** Deliveries with both an order creation instant and a delivery creation instant. */
140
+ dispatch_lag_count: number;
141
+ /** Completed deliveries whose completion instant is known (exact OR proxy). */
142
+ complete_count: number;
143
+ /** Completed deliveries with both an order creation instant and a completion. */
144
+ total_count: number;
103
145
  /** `delivery.createdAt - order.createdAt` - precise even without the capture. */
104
146
  dispatch_lag_sum_minutes: number;
105
147
  /** `delivered_at - delivery.createdAt`, EXACT once the capture has run. */
@@ -26,6 +26,7 @@ const delivery = (over = {}) => ({
26
26
  order_id: 'order-1',
27
27
  rider_id: 'rider-1',
28
28
  rider_name: 'Sam',
29
+ order_status: 'COMPLETED',
29
30
  status: 'COMPLETED',
30
31
  createdAt: new Date('2026-09-14T10:05:00.000Z'),
31
32
  updatedAt: new Date('2026-09-14T10:35:00.000Z'),
@@ -36,20 +37,28 @@ const delivery = (over = {}) => ({
36
37
  localHour: 10,
37
38
  ...over,
38
39
  });
39
- const KEY = 'POS_WALK-IN:Istanbul';
40
+ const KEY = 'COMPLETED:POS_WALK-IN:Istanbul';
40
41
  describe('M4 key grammar', () => {
41
- it('round-trips platform:city', () => {
42
- expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('POS', 'Istanbul')).toBe('POS:Istanbul');
43
- expect((0, materialized_delivery_classification_helpers_1.parseMaterializedDeliveryKey)('POS:Istanbul')).toEqual({ platform: 'POS', city: 'Istanbul' });
42
+ it('round-trips order_status:platform:city', () => {
43
+ expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('COMPLETED', 'POS', 'Istanbul')).toBe('COMPLETED:POS:Istanbul');
44
+ expect((0, materialized_delivery_classification_helpers_1.parseMaterializedDeliveryKey)('COMPLETED:POS:Istanbul')).toEqual({
45
+ order_status: 'COMPLETED',
46
+ platform: 'POS',
47
+ city: 'Istanbul',
48
+ });
44
49
  });
45
50
  it('falls back to UNKNOWN rather than dropping a row with no dimension', () => {
46
- expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)(null, 'Istanbul')).toBe('UNKNOWN:Istanbul');
47
- expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('POS', '')).toBe('POS:UNKNOWN');
48
- expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)(undefined, undefined)).toBe('UNKNOWN:UNKNOWN');
51
+ expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)(null, 'POS', 'Istanbul')).toBe('UNKNOWN:POS:Istanbul');
52
+ expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('COMPLETED', 'POS', '')).toBe('COMPLETED:POS:UNKNOWN');
53
+ expect((0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)(undefined, undefined, undefined)).toBe('UNKNOWN:UNKNOWN:UNKNOWN');
49
54
  });
50
55
  it('never lets the separator inside a component', () => {
51
- const key = (0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('PO:S', 'Is:tanbul');
52
- expect((0, materialized_delivery_classification_helpers_1.parseMaterializedDeliveryKey)(key)).toEqual({ platform: 'PO-S', city: 'Is-tanbul' });
56
+ const key = (0, materialized_delivery_classification_helpers_1.buildMaterializedDeliveryKey)('COMP:LETED', 'PO:S', 'Is:tanbul');
57
+ expect((0, materialized_delivery_classification_helpers_1.parseMaterializedDeliveryKey)(key)).toEqual({
58
+ order_status: 'COMP-LETED',
59
+ platform: 'PO-S',
60
+ city: 'Is-tanbul',
61
+ });
53
62
  });
54
63
  });
55
64
  describe('M4 adoption', () => {
@@ -107,18 +116,46 @@ describe('M4 accumulation', () => {
107
116
  expect((0, materialized_delivery_classification_helpers_1.deliveryDistanceBucketKey)(1999)).toBe('under_2km');
108
117
  expect((0, materialized_delivery_classification_helpers_1.deliveryDistanceBucketKey)(25000)).toBe('over_25km');
109
118
  });
110
- it('builds the rider leaderboard and the area hour heat map', () => {
119
+ it('builds the rider leaderboard and the ORDER-hour area demand heat', () => {
120
+ // One accumulator per ORDER_STATUS:PLATFORM:CITY key - the unit the compile builds.
121
+ const istanbul = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
122
+ const ankara = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
123
+ (0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(istanbul, order('order-1', { localHour: 10 }), KEY);
124
+ (0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(istanbul, order('order-2', { localHour: 10 }), KEY);
125
+ (0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(ankara, order('order-3', { localHour: 14 }), 'COMPLETED:POS:Ankara');
126
+ (0, materialized_delivery_classification_helpers_1.addDelivery)(istanbul, delivery({ _id: 'a', order_id: 'order-1' }), order('order-1', { localHour: 10 }), KEY);
127
+ (0, materialized_delivery_classification_helpers_1.addDelivery)(istanbul, delivery({ _id: 'b', order_id: 'order-2' }), order('order-2', { localHour: 10 }), KEY);
128
+ (0, materialized_delivery_classification_helpers_1.addDelivery)(ankara, delivery({ _id: 'c', order_id: 'order-3' }), order('order-3', { localHour: 14 }), 'COMPLETED:POS:Ankara');
129
+ const counters = (0, materialized_delivery_classification_helpers_1.finalizeDeliveryAccumulator)(istanbul);
130
+ const ankaraCounters = (0, materialized_delivery_classification_helpers_1.finalizeDeliveryAccumulator)(ankara);
131
+ expect(counters.riders['rider-1'].count).toBe(2);
132
+ expect(counters.riders['rider-1'].rider_revenue_amount).toBe(1400);
133
+ // areas are keyed by CITY from the JOINED key, and the hour is the ORDER's localHour.
134
+ expect(counters.areas['Istanbul'].by_hour['10']).toBe(2);
135
+ expect(ankaraCounters.areas['Ankara'].by_hour['14']).toBe(1);
136
+ // the area row separates ORDERS from RECORDS.
137
+ expect(counters.areas['Istanbul'].delivery_orders).toBe(2);
138
+ expect(counters.areas['Istanbul'].app_orders).toBe(2);
139
+ expect(counters.areas['Istanbul'].delivery_records).toBe(2);
140
+ expect(ankaraCounters.areas['Ankara'].delivery_records).toBe(1);
141
+ });
142
+ it('buckets demand by the ORDER local hour, never by a delivery-side clock', () => {
111
143
  const acc = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
112
- (0, materialized_delivery_classification_helpers_1.addDelivery)(acc, delivery({ _id: 'a', localHour: 10 }), null, KEY);
113
- (0, materialized_delivery_classification_helpers_1.addDelivery)(acc, delivery({ _id: 'b', localHour: 10 }), null, KEY);
114
- (0, materialized_delivery_classification_helpers_1.addDelivery)(acc, delivery({ _id: 'c', localHour: 14 }), null, 'POS:Ankara');
144
+ // The delivery document happens to be stamped at 18:00 UTC, but the tenant-local
145
+ // order hour is 02 and that is the only hour the report may use.
146
+ (0, materialized_delivery_classification_helpers_1.addDelivery)(acc, delivery({ createdAt: new Date('2026-09-14T18:05:00.000Z') }), order('order-1', { localHour: 2 }), KEY);
147
+ (0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(acc, order('order-1', { localHour: 2 }), KEY);
115
148
  const counters = (0, materialized_delivery_classification_helpers_1.finalizeDeliveryAccumulator)(acc);
116
- expect(counters.riders['rider-1'].count).toBe(3);
117
- expect(counters.riders['rider-1'].rider_revenue_amount).toBe(2100);
118
- // areas are keyed by CITY from the JOINED key.
119
- expect(counters.areas['Istanbul'].by_hour['10']).toBe(2);
120
- expect(counters.areas['Ankara'].by_hour['14']).toBe(1);
121
- expect(counters.areas['Istanbul'].count).toBe(2);
149
+ expect(counters.areas['Istanbul'].by_hour['02']).toBe(1);
150
+ expect(counters.areas['Istanbul'].by_hour['18']).toBeUndefined();
151
+ });
152
+ it('sums refunds from the payment rows, the only declared refund source', () => {
153
+ const acc = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
154
+ (0, materialized_delivery_classification_helpers_1.addDeliveryOrder)(acc, order('order-1', {
155
+ payments: [{ amount_refunded: 120 }, { amount_refunded: 80 }, { amount_refunded: 0 }],
156
+ }), KEY);
157
+ const counters = (0, materialized_delivery_classification_helpers_1.finalizeDeliveryAccumulator)(acc);
158
+ expect(counters.money.refund_amount).toBe(200);
122
159
  });
123
160
  it('marks a proxy completion as NOT exact, and an explicit one as exact', () => {
124
161
  const proxy = (0, materialized_delivery_classification_helpers_1.freshDeliveryAccumulator)();
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
4
+ const materialized_document_size_1 = require("../../helpers/materialized-reports/materialized-document-size");
5
+ const materialized_delivery_compile_helpers_1 = require("../../helpers/materialized-reports/materialized-delivery-compile-helpers");
6
+ /**
7
+ * DELIVERY BSON budgets.
8
+ *
9
+ * The previous revision used a single 15 MiB "almost the Mongo limit" budget. That is not
10
+ * a budget: the report document must stay small over time, one entry page is bounded by
11
+ * one day, and a geo cell is a tiny aggregate. Each shape gets its own named budget, and
12
+ * the failure names the collection + day + scope.
13
+ */
14
+ const TENANT = 'tenant-budget';
15
+ const BRAND = 'brand-budget';
16
+ const DAY = '2026-09-14';
17
+ const order = (id) => ({
18
+ _id: id,
19
+ tenant_id: TENANT,
20
+ platform: 'POS_DELIVERY',
21
+ order_number: 1,
22
+ createdAt: new Date(`${DAY}T10:00:00.000Z`),
23
+ localDate: DAY,
24
+ localHour: 10,
25
+ net_sale_amount: 5000,
26
+ amount_collected: 5000,
27
+ delivery_details: { city: 'Istanbul', state: 'Istanbul', delivery_cost: 300 },
28
+ });
29
+ const compile = () => (0, materialized_delivery_compile_helpers_1.compileTenantDeliveryReports)({
30
+ tenantId: TENANT,
31
+ brandId: BRAND,
32
+ localDate: DAY,
33
+ orders: [order('o1')],
34
+ deliveries: [
35
+ {
36
+ _id: 'd1',
37
+ tenant_id: TENANT,
38
+ order_id: 'o1',
39
+ rider_id: 'rider-1',
40
+ rider_name: 'Sam',
41
+ status: 'COMPLETED',
42
+ createdAt: new Date(`${DAY}T10:05:00.000Z`),
43
+ updatedAt: new Date(`${DAY}T10:30:00.000Z`),
44
+ delivered_at: new Date(`${DAY}T10:28:00.000Z`),
45
+ distance_in_meters_from_store: 3000,
46
+ },
47
+ ],
48
+ computedAt: new Date(`${DAY}T23:00:00.000Z`),
49
+ });
50
+ describe('delivery BSON budgets', () => {
51
+ it('uses the owner-approved 15 MiB report/page budgets and 2 MiB geo budget', () => {
52
+ expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES).toBe(15 * 1024 * 1024);
53
+ expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES).toBe(15 * 1024 * 1024);
54
+ expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_GEO_CELL_MAX_BSON_BYTES).toBe(2 * 1024 * 1024);
55
+ // MongoDB's hard limit is 16 MiB; the practical budget leaves headroom.
56
+ expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES).toBeLessThan(16 * 1024 * 1024);
57
+ expect(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES).toBeLessThan(16 * 1024 * 1024);
58
+ });
59
+ it('fails a REPORT document above the 15 MiB budget and names it', () => {
60
+ const oversized = { blob: 'x'.repeat(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES + 1024) };
61
+ expect((0, materialized_document_size_1.materializedDocumentBsonBytes)(oversized)).toBeGreaterThan(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES);
62
+ expect(() => (0, materialized_document_size_1.assertMaterializedDocumentSize)(oversized, {
63
+ label: `materialized_tenant_delivery_reports:${TENANT}:${DAY}`,
64
+ maxBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES,
65
+ })).toThrow(/materialized_tenant_delivery_reports:tenant-budget:2026-09-14/);
66
+ });
67
+ it('fails an ENTRY PAGE above the 15 MiB budget and names the day + scope', () => {
68
+ const oversized = { blob: 'x'.repeat(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES + 1024) };
69
+ expect(() => (0, materialized_document_size_1.assertMaterializedDocumentSize)(oversized, {
70
+ label: `materialized_tenant_delivery_entries:${TENANT}:${DAY}:localMonth:2026-09:page=${DAY}`,
71
+ maxBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES,
72
+ })).toThrow(/materialized_tenant_delivery_entries:tenant-budget:2026-09-14:localMonth:2026-09:page=2026-09-14/);
73
+ });
74
+ it('fails a GEO CELL above 2 MiB and names the cell', () => {
75
+ const oversized = { blob: 'x'.repeat(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_GEO_CELL_MAX_BSON_BYTES + 1024) };
76
+ expect(() => (0, materialized_document_size_1.assertMaterializedDocumentSize)(oversized, {
77
+ label: 'materialized_tenant_delivery_geo_cells:tenant-budget:localDate:2026-09-14:88194ad33dfffff',
78
+ maxBytes: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_GEO_CELL_MAX_BSON_BYTES,
79
+ })).toThrow(/materialized_tenant_delivery_geo_cells:tenant-budget/);
80
+ });
81
+ it('a normal day is comfortably inside every budget', () => {
82
+ const compiled = compile();
83
+ expect((0, materialized_document_size_1.materializedDocumentBsonBytes)(compiled.reports[0])).toBeLessThan(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_MAX_BSON_BYTES);
84
+ for (const page of compiled.entries) {
85
+ expect((0, materialized_document_size_1.materializedDocumentBsonBytes)(page)).toBeLessThan(MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_MAX_BSON_BYTES);
86
+ }
87
+ });
88
+ it('REQUIRES an explicit budget (there is no silent global default)', () => {
89
+ expect(() => (0, materialized_document_size_1.assertMaterializedDocumentSize)({ a: 1 }, { collection: 'x' })).toThrow(/explicit maxBytes budget is required/);
90
+ });
91
+ });