@managesome/eposmatic-toolkit 0.4.52 → 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 (107) 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/schemas/models/applied_order_discounts.js +103 -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/applied_order_discounts.js +1 -0
  26. package/esm/schemas/types/index.js +14 -12
  27. package/esm/schemas/types/materialized_tenant_delivery_geo_cells.js +1 -0
  28. package/esm/schemas/types/materialized_tenant_delivery_geo_scopes.js +1 -0
  29. package/lib/constants/MATERIALIZED_REPORTS.d.ts +95 -1
  30. package/lib/constants/MATERIALIZED_REPORTS.js +108 -4
  31. package/lib/constants/enums/delivery.d.ts +9 -0
  32. package/lib/constants/enums/delivery.js +14 -1
  33. package/lib/helpers/materialized-reports/index.d.ts +5 -0
  34. package/lib/helpers/materialized-reports/index.js +5 -0
  35. package/lib/helpers/materialized-reports/materialized-delivery-accumulator-helpers.js +8 -62
  36. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.d.ts +36 -9
  37. package/lib/helpers/materialized-reports/materialized-delivery-classification-helpers.js +94 -72
  38. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.d.ts +23 -26
  39. package/lib/helpers/materialized-reports/materialized-delivery-close-day-helpers.js +121 -150
  40. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.d.ts +44 -5
  41. package/lib/helpers/materialized-reports/materialized-delivery-compile-helpers.js +306 -69
  42. package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.d.ts +128 -0
  43. package/lib/helpers/materialized-reports/materialized-delivery-entry-pages.js +322 -0
  44. package/lib/helpers/materialized-reports/materialized-delivery-index-migration.d.ts +48 -0
  45. package/lib/helpers/materialized-reports/materialized-delivery-index-migration.js +108 -0
  46. package/lib/helpers/materialized-reports/materialized-delivery-rows.d.ts +15 -0
  47. package/lib/helpers/materialized-reports/materialized-delivery-rows.js +115 -0
  48. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.d.ts +17 -0
  49. package/lib/helpers/materialized-reports/materialized-delivery-wipe-targets.js +35 -0
  50. package/lib/helpers/materialized-reports/materialized-document-size.d.ts +47 -0
  51. package/lib/helpers/materialized-reports/materialized-document-size.js +73 -0
  52. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +28 -13
  53. package/lib/helpers/materialized-reports/materialized-integer-contract.js +10 -1
  54. package/lib/helpers/materialized-reports/materialized-prep-time-close-day-helpers.js +2 -90
  55. package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.d.ts +186 -0
  56. package/lib/helpers/materialized-reports/materialized-tenant-delivery-geo-helpers.js +620 -0
  57. package/lib/helpers/materialized-reports/scope-helpers.d.ts +8 -0
  58. package/lib/helpers/materialized-reports/scope-helpers.js +99 -0
  59. package/lib/helpers/materialized-reports/tenant-delivery-formatter.d.ts +41 -0
  60. package/lib/helpers/materialized-reports/tenant-delivery-formatter.js +70 -20
  61. package/lib/helpers/order/payment-collection.d.ts +25 -0
  62. package/lib/helpers/order/payment-collection.js +51 -0
  63. package/lib/schemas/models/applied_order_discounts.d.ts +80 -0
  64. package/lib/schemas/models/applied_order_discounts.js +106 -0
  65. package/lib/schemas/models/index.d.ts +12 -10
  66. package/lib/schemas/models/index.js +12 -10
  67. package/lib/schemas/models/materialized_tenant_delivery_entries.d.ts +31 -9
  68. package/lib/schemas/models/materialized_tenant_delivery_entries.js +32 -11
  69. package/lib/schemas/models/materialized_tenant_delivery_geo_cells.d.ts +129 -0
  70. package/lib/schemas/models/materialized_tenant_delivery_geo_cells.js +86 -0
  71. package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.d.ts +71 -0
  72. package/lib/schemas/models/materialized_tenant_delivery_geo_scopes.js +38 -0
  73. package/lib/schemas/models/materialized_tenant_delivery_reports.d.ts +10 -1
  74. package/lib/schemas/models/materialized_tenant_delivery_reports.js +10 -1
  75. package/lib/schemas/models/materialized_tenant_discount_sources.d.ts +15 -15
  76. package/lib/schemas/types/applied_order_discounts.d.ts +22 -0
  77. package/lib/schemas/types/applied_order_discounts.js +2 -0
  78. package/lib/schemas/types/index.d.ts +14 -12
  79. package/lib/schemas/types/index.js +14 -12
  80. package/lib/schemas/types/materialized_tenant_delivery_entries.d.ts +36 -4
  81. package/lib/schemas/types/materialized_tenant_delivery_geo_cells.d.ts +178 -0
  82. package/lib/schemas/types/materialized_tenant_delivery_geo_cells.js +2 -0
  83. package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.d.ts +21 -0
  84. package/lib/schemas/types/materialized_tenant_delivery_geo_scopes.js +2 -0
  85. package/lib/schemas/types/materialized_tenant_delivery_reports.d.ts +49 -7
  86. package/lib/tests/materialized-reports/analytics-growth-helpers.test.d.ts +1 -0
  87. package/lib/tests/materialized-reports/analytics-overview-helpers.test.d.ts +1 -0
  88. package/lib/tests/materialized-reports/analytics-performance-helpers.test.d.ts +1 -0
  89. package/lib/tests/materialized-reports/materialized-delivery-accumulation.test.js +56 -19
  90. package/lib/tests/materialized-reports/materialized-delivery-budgets.test.d.ts +1 -0
  91. package/lib/tests/materialized-reports/materialized-delivery-budgets.test.js +91 -0
  92. package/lib/tests/materialized-reports/materialized-delivery-compile.test.js +271 -15
  93. package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.d.ts +1 -0
  94. package/lib/tests/materialized-reports/materialized-delivery-final-audit.test.js +128 -0
  95. package/lib/tests/materialized-reports/materialized-delivery-fold.test.js +42 -5
  96. package/lib/tests/materialized-reports/materialized-delivery-formatter.test.js +13 -1
  97. package/lib/tests/materialized-reports/materialized-delivery-geo.test.d.ts +1 -0
  98. package/lib/tests/materialized-reports/materialized-delivery-geo.test.js +446 -0
  99. package/lib/tests/materialized-reports/materialized-delivery-plan.test.js +117 -25
  100. package/lib/tests/materialized-reports/materialized-delivery-practical.test.d.ts +1 -0
  101. package/lib/tests/materialized-reports/materialized-delivery-practical.test.js +344 -0
  102. package/lib/tests/materialized-reports/materialized-integer-contract.test.js +14 -0
  103. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +1 -1
  104. package/lib/tests/offer-item-resolution.test.js +1 -4
  105. package/lib/tests/payment-collection-timestamps.test.d.ts +1 -0
  106. package/lib/tests/payment-collection-timestamps.test.js +71 -0
  107. package/package.json +4 -2
@@ -43,24 +43,26 @@ __exportStar(require("./item_transactions"), exports);
43
43
  __exportStar(require("./items"), exports);
44
44
  __exportStar(require("./marketing_fingerprints"), exports);
45
45
  __exportStar(require("./materialized_credit_bills"), exports);
46
- __exportStar(require("./materialized_tenant_discount_entries"), exports);
47
- __exportStar(require("./materialized_tenant_discount_reports"), exports);
48
- __exportStar(require("./materialized_tenant_discount_sources"), exports);
46
+ __exportStar(require("./materialized_report_drilldown_rows"), exports);
47
+ __exportStar(require("./materialized_rider_daily_reports"), exports);
49
48
  __exportStar(require("./materialized_tenant_cash_entries"), exports);
49
+ __exportStar(require("./materialized_tenant_cash_reports"), exports);
50
50
  __exportStar(require("./materialized_tenant_delivery_entries"), exports);
51
+ __exportStar(require("./materialized_tenant_delivery_geo_cells"), exports);
52
+ __exportStar(require("./materialized_tenant_delivery_geo_scopes"), exports);
51
53
  __exportStar(require("./materialized_tenant_delivery_reports"), exports);
52
- __exportStar(require("./materialized_rider_daily_reports"), exports);
53
- __exportStar(require("./materialized_tenant_cash_reports"), exports);
54
+ __exportStar(require("./materialized_tenant_discount_entries"), exports);
55
+ __exportStar(require("./materialized_tenant_discount_reports"), exports);
56
+ __exportStar(require("./materialized_tenant_discount_sources"), exports);
57
+ __exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
58
+ __exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
59
+ __exportStar(require("./materialized_tenant_payments_comparison_entries"), exports);
60
+ __exportStar(require("./materialized_tenant_payments_comparison_reports"), exports);
54
61
  __exportStar(require("./materialized_tenant_prep_time_entries"), exports);
55
62
  __exportStar(require("./materialized_tenant_prep_time_reports"), exports);
56
63
  __exportStar(require("./materialized_tenant_reports_iterations"), exports);
57
- __exportStar(require("./materialized_report_drilldown_rows"), exports);
58
64
  __exportStar(require("./materialized_tenant_sales_comparison_entries"), exports);
59
65
  __exportStar(require("./materialized_tenant_sales_comparison_reports"), exports);
60
- __exportStar(require("./materialized_tenant_hourly_comparison_entries"), exports);
61
- __exportStar(require("./materialized_tenant_hourly_comparison_reports"), exports);
62
- __exportStar(require("./materialized_tenant_payments_comparison_entries"), exports);
63
- __exportStar(require("./materialized_tenant_payments_comparison_reports"), exports);
64
66
  __exportStar(require("./materialized_tenant_sales_overview_reports"), exports);
65
67
  __exportStar(require("./menus"), exports);
66
68
  __exportStar(require("./messaging_devices"), exports);
@@ -2,11 +2,22 @@ import { Schema } from 'mongoose';
2
2
  /**
3
3
  * Mongoose schema for `materialized_tenant_delivery_entries` (M4).
4
4
  *
5
- * `delivery_entries` is `Mixed` on purpose: it is a key-addressed map of
6
- * bounded sub-documents (rider / area leaderboards with an hour heat map), which Mongoose
7
- * cannot type precisely without a fixed key set - the keys ARE the data.
5
+ * PAGE-PARTITIONED by source day, exactly like the discounts entries: the day scope uses
6
+ * `page='all'`, and every period entry scope (week / ISO week / month) uses
7
+ * `page=<source localDate>`, so a document is bounded by ONE day's rows. Quarter /
8
+ * semester / year entry documents do not exist.
9
+ *
10
+ * `delivery_entries` is `Mixed` on purpose: it is a key-addressed map of rows whose keys
11
+ * are the report's `ORDER_STATUS:PLATFORM:CITY` grammar, which Mongoose cannot type precisely without
12
+ * a fixed key set - the keys ARE the data.
13
+ */
14
+ /**
15
+ * v3 - PAGE-PARTITIONED entry documents (one page per source day, max scope
16
+ * `localMonth`). v2 was one document per period scope, which made a month an unbounded
17
+ * document. Historical v2 documents are not readable by the page-aware read layer and
18
+ * must be re-materialized (re-close the days); the writer deletes the pages it owns.
8
19
  */
9
- export declare const MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 1;
20
+ export declare const MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 3;
10
21
  export declare const MaterializedTenantDeliveryEntriesSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
11
22
  timestamps: true;
12
23
  versionKey: false;
@@ -28,6 +39,7 @@ export declare const MaterializedTenantDeliveryEntriesSchema: Schema<any, import
28
39
  source_watermark: NativeDate;
29
40
  computed_at: NativeDate;
30
41
  off_app_order_count: number;
42
+ page: string;
31
43
  delivery_entries?: any;
32
44
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
33
45
  createdAt: NativeDate;
@@ -46,6 +58,7 @@ export declare const MaterializedTenantDeliveryEntriesSchema: Schema<any, import
46
58
  source_watermark: NativeDate;
47
59
  computed_at: NativeDate;
48
60
  off_app_order_count: number;
61
+ page: string;
49
62
  delivery_entries?: any;
50
63
  }>> & import("mongoose").FlatRecord<{
51
64
  createdAt: NativeDate;
@@ -64,6 +77,7 @@ export declare const MaterializedTenantDeliveryEntriesSchema: Schema<any, import
64
77
  source_watermark: NativeDate;
65
78
  computed_at: NativeDate;
66
79
  off_app_order_count: number;
80
+ page: string;
67
81
  delivery_entries?: any;
68
82
  }> & {
69
83
  _id: import("mongoose").Types.ObjectId;
@@ -72,18 +86,26 @@ export declare const MaterializedTenantDeliveryEntriesSchema: Schema<any, import
72
86
  }>;
73
87
  export declare const MATERIALIZED_TENANT_DELIVERY_ENTRIES_COLLECTION_NAME = "materialized_tenant_delivery_entries";
74
88
  /**
75
- * The single UNIQUE compound identity index, like every materialized collection. No
76
- * `brand_id` index - a brand's scopes are resolved before the read.
89
+ * ONE unique index per PAGE: `tenant_id + scope_context + scope_field + page`.
90
+ *
91
+ * The OLD index `{ tenant_id, scope_context, scope_field, day_index }` must NOT survive:
92
+ * period pages all carry `day_index: null`, so it would reject the second page of a
93
+ * month. The OWNER deploy step
94
+ * (`simulations/migrate-delivery-report-indexes.ts --apply`) drops the legacy index by
95
+ * name/key before creating this one. No service calls `ensureMaterializedReportIndexes`
96
+ * automatically; the discounts entry collection has the same migration posture.
97
+ *
98
+ * The same key also serves the multi-page read (tenant + scope prefix, then the pages).
77
99
  */
78
100
  export declare const MATERIALIZED_TENANT_DELIVERY_ENTRIES_COLLECTION_INDEXES: {
79
101
  _id: {
80
102
  _id: number;
81
103
  };
82
- tenant_id__scope_context__scope_field__day_index: {
104
+ tenant_id__scope_context__scope_field__page: {
83
105
  tenant_id: number;
84
106
  scope_context: number;
85
107
  scope_field: number;
86
- day_index: number;
108
+ page: number;
87
109
  };
88
110
  };
89
111
  export declare const MATERIALIZED_TENANT_DELIVERY_ENTRIES_INDEX_OPTIONS: {
@@ -91,7 +113,7 @@ export declare const MATERIALIZED_TENANT_DELIVERY_ENTRIES_INDEX_OPTIONS: {
91
113
  tenant_id: number;
92
114
  scope_context: number;
93
115
  scope_field: number;
94
- day_index: number;
116
+ page: number;
95
117
  };
96
118
  name: string;
97
119
  unique: boolean;
@@ -7,16 +7,29 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
7
7
  /**
8
8
  * Mongoose schema for `materialized_tenant_delivery_entries` (M4).
9
9
  *
10
- * `delivery_entries` is `Mixed` on purpose: it is a key-addressed map of
11
- * bounded sub-documents (rider / area leaderboards with an hour heat map), which Mongoose
12
- * cannot type precisely without a fixed key set - the keys ARE the data.
10
+ * PAGE-PARTITIONED by source day, exactly like the discounts entries: the day scope uses
11
+ * `page='all'`, and every period entry scope (week / ISO week / month) uses
12
+ * `page=<source localDate>`, so a document is bounded by ONE day's rows. Quarter /
13
+ * semester / year entry documents do not exist.
14
+ *
15
+ * `delivery_entries` is `Mixed` on purpose: it is a key-addressed map of rows whose keys
16
+ * are the report's `ORDER_STATUS:PLATFORM:CITY` grammar, which Mongoose cannot type precisely without
17
+ * a fixed key set - the keys ARE the data.
18
+ */
19
+ /**
20
+ * v3 - PAGE-PARTITIONED entry documents (one page per source day, max scope
21
+ * `localMonth`). v2 was one document per period scope, which made a month an unbounded
22
+ * document. Historical v2 documents are not readable by the page-aware read layer and
23
+ * must be re-materialized (re-close the days); the writer deletes the pages it owns.
13
24
  */
14
- exports.MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 1;
25
+ exports.MATERIALIZED_TENANT_DELIVERY_ENTRIES_SCHEMA_VERSION = 3;
15
26
  exports.MaterializedTenantDeliveryEntriesSchema = new mongoose_1.Schema({
16
27
  tenant_id: { type: String, required: true },
17
28
  brand_id: { type: String, required: true },
18
- scope_context: { type: String, required: true, enum: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_REPORT_SCOPES },
29
+ scope_context: { type: String, required: true, enum: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_ENTRY_SCOPES },
19
30
  scope_field: { type: String, required: true },
31
+ /** `'all'` for the day scope; the source `YYYY-MM-DD` for a period scope. */
32
+ page: { type: String, required: true, immutable: true },
20
33
  day_index: { type: String, default: null, enum: [...ENUMS_1.ALL_DAY_INDEX, null] },
21
34
  sale_type_key_filters: {
22
35
  type: [String],
@@ -45,22 +58,30 @@ exports.MaterializedTenantDeliveryEntriesSchema = new mongoose_1.Schema({
45
58
  }, { timestamps: true, versionKey: false, minimize: false });
46
59
  exports.MATERIALIZED_TENANT_DELIVERY_ENTRIES_COLLECTION_NAME = 'materialized_tenant_delivery_entries';
47
60
  /**
48
- * The single UNIQUE compound identity index, like every materialized collection. No
49
- * `brand_id` index - a brand's scopes are resolved before the read.
61
+ * ONE unique index per PAGE: `tenant_id + scope_context + scope_field + page`.
62
+ *
63
+ * The OLD index `{ tenant_id, scope_context, scope_field, day_index }` must NOT survive:
64
+ * period pages all carry `day_index: null`, so it would reject the second page of a
65
+ * month. The OWNER deploy step
66
+ * (`simulations/migrate-delivery-report-indexes.ts --apply`) drops the legacy index by
67
+ * name/key before creating this one. No service calls `ensureMaterializedReportIndexes`
68
+ * automatically; the discounts entry collection has the same migration posture.
69
+ *
70
+ * The same key also serves the multi-page read (tenant + scope prefix, then the pages).
50
71
  */
51
72
  exports.MATERIALIZED_TENANT_DELIVERY_ENTRIES_COLLECTION_INDEXES = {
52
73
  _id: { _id: 1 },
53
- tenant_id__scope_context__scope_field__day_index: {
74
+ tenant_id__scope_context__scope_field__page: {
54
75
  tenant_id: 1,
55
76
  scope_context: 1,
56
77
  scope_field: 1,
57
- day_index: 1,
78
+ page: 1,
58
79
  },
59
80
  };
60
81
  exports.MATERIALIZED_TENANT_DELIVERY_ENTRIES_INDEX_OPTIONS = [
61
82
  {
62
- key: { tenant_id: 1, scope_context: 1, scope_field: 1, day_index: 1 },
63
- name: 'tenant_id__scope_context__scope_field__day_index',
83
+ key: { tenant_id: 1, scope_context: 1, scope_field: 1, page: 1 },
84
+ name: 'tenant_id__scope_context__scope_field__page',
64
85
  unique: true,
65
86
  },
66
87
  ];
@@ -0,0 +1,129 @@
1
+ import { Schema } from 'mongoose';
2
+ /**
3
+ * Mongoose schema for `materialized_tenant_delivery_geo_cells`.
4
+ *
5
+ * `location` is `Mixed` and DELIBERATELY has no default: the unknown bucket must be
6
+ * written WITHOUT the field, because a 2dsphere index cannot extract a geo key from
7
+ * `null`. A missing field is simply not indexed, which is exactly the intent - the
8
+ * unknown aggregate must never be plottable.
9
+ *
10
+ * `city` is nullable: an order whose joined `delivery_details` has no city still
11
+ * counts in the cell (the position is what the heat map plots), it just carries no
12
+ * label.
13
+ */
14
+ export declare const MaterializedTenantDeliveryGeoCellSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
15
+ timestamps: true;
16
+ versionKey: false;
17
+ }, {
18
+ createdAt: NativeDate;
19
+ updatedAt: NativeDate;
20
+ } & {
21
+ createdAt: NativeDate;
22
+ updatedAt: NativeDate;
23
+ brand_id: string;
24
+ tenant_id: string;
25
+ city: string;
26
+ orders: number;
27
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
28
+ scope_field: string;
29
+ schema_version: number;
30
+ computed_at: NativeDate;
31
+ resolution: number;
32
+ h3_cell: string;
33
+ app_orders: number;
34
+ delivery_records: number;
35
+ completed: number;
36
+ cancelled: number;
37
+ net_sale_amount: number;
38
+ delivery_charge_amount: number;
39
+ rider_revenue_amount: number;
40
+ location?: any;
41
+ by_key?: any;
42
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
43
+ createdAt: NativeDate;
44
+ updatedAt: NativeDate;
45
+ } & {
46
+ createdAt: NativeDate;
47
+ updatedAt: NativeDate;
48
+ brand_id: string;
49
+ tenant_id: string;
50
+ city: string;
51
+ orders: number;
52
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
53
+ scope_field: string;
54
+ schema_version: number;
55
+ computed_at: NativeDate;
56
+ resolution: number;
57
+ h3_cell: string;
58
+ app_orders: number;
59
+ delivery_records: number;
60
+ completed: number;
61
+ cancelled: number;
62
+ net_sale_amount: number;
63
+ delivery_charge_amount: number;
64
+ rider_revenue_amount: number;
65
+ location?: any;
66
+ by_key?: any;
67
+ }>> & import("mongoose").FlatRecord<{
68
+ createdAt: NativeDate;
69
+ updatedAt: NativeDate;
70
+ } & {
71
+ createdAt: NativeDate;
72
+ updatedAt: NativeDate;
73
+ brand_id: string;
74
+ tenant_id: string;
75
+ city: string;
76
+ orders: number;
77
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
78
+ scope_field: string;
79
+ schema_version: number;
80
+ computed_at: NativeDate;
81
+ resolution: number;
82
+ h3_cell: string;
83
+ app_orders: number;
84
+ delivery_records: number;
85
+ completed: number;
86
+ cancelled: number;
87
+ net_sale_amount: number;
88
+ delivery_charge_amount: number;
89
+ rider_revenue_amount: number;
90
+ location?: any;
91
+ by_key?: any;
92
+ }> & {
93
+ _id: import("mongoose").Types.ObjectId;
94
+ } & {
95
+ __v: number;
96
+ }>;
97
+ export declare const MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_COLLECTION_NAME = "materialized_tenant_delivery_geo_cells";
98
+ /**
99
+ * The indexes the heat reads/writes assume:
100
+ * 1. the UNIQUE cell identity (one document per tenant/scope/cell);
101
+ * 2. the map's read path - a scope, busiest cells first;
102
+ * 3. the 2dsphere index a future viewport `$geoWithin` read needs.
103
+ *
104
+ * The unknown bucket has no `location`, so it is absent from (3) by design.
105
+ */
106
+ export declare const MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_COLLECTION_INDEXES: {
107
+ _id: {
108
+ _id: number;
109
+ };
110
+ tenant_id__scope_context__scope_field__h3_cell: {
111
+ tenant_id: number;
112
+ scope_context: number;
113
+ scope_field: number;
114
+ h3_cell: number;
115
+ };
116
+ scope_context__scope_field__orders: {
117
+ scope_context: number;
118
+ scope_field: number;
119
+ orders: number;
120
+ };
121
+ location__2dsphere: {
122
+ location: string;
123
+ };
124
+ };
125
+ export declare const MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_INDEX_OPTIONS: ReadonlyArray<{
126
+ key: Record<string, number | string>;
127
+ name: string;
128
+ unique?: boolean;
129
+ }>;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_COLLECTION_NAME = exports.MaterializedTenantDeliveryGeoCellSchema = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
6
+ /**
7
+ * Mongoose schema for `materialized_tenant_delivery_geo_cells`.
8
+ *
9
+ * `location` is `Mixed` and DELIBERATELY has no default: the unknown bucket must be
10
+ * written WITHOUT the field, because a 2dsphere index cannot extract a geo key from
11
+ * `null`. A missing field is simply not indexed, which is exactly the intent - the
12
+ * unknown aggregate must never be plottable.
13
+ *
14
+ * `city` is nullable: an order whose joined `delivery_details` has no city still
15
+ * counts in the cell (the position is what the heat map plots), it just carries no
16
+ * label.
17
+ */
18
+ exports.MaterializedTenantDeliveryGeoCellSchema = new mongoose_1.Schema({
19
+ tenant_id: { type: String, required: true },
20
+ brand_id: { type: String, required: true },
21
+ scope_context: { type: String, required: true, enum: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_GEO_SCOPES },
22
+ scope_field: { type: String, required: true },
23
+ city: { type: String, default: null },
24
+ h3_cell: { type: String, required: true },
25
+ resolution: { type: Number, required: true, min: 0, max: 15 },
26
+ location: { type: mongoose_1.Schema.Types.Mixed, required: false },
27
+ /** Bounded ORDER_STATUS:PLATFORM:CITY counters; sum equals the top-level counters. */
28
+ by_key: { type: mongoose_1.Schema.Types.Mixed, required: false, default: null },
29
+ // ---- counters (integer counts; money in CENTS) ----
30
+ orders: { type: Number, required: true, min: 0, default: 0 },
31
+ app_orders: { type: Number, required: true, min: 0, default: 0 },
32
+ delivery_records: { type: Number, required: true, min: 0, default: 0 },
33
+ completed: { type: Number, required: true, min: 0, default: 0 },
34
+ cancelled: { type: Number, required: true, min: 0, default: 0 },
35
+ net_sale_amount: { type: Number, required: true, default: 0 },
36
+ delivery_charge_amount: { type: Number, required: true, default: 0 },
37
+ rider_revenue_amount: { type: Number, required: true, default: 0 },
38
+ schema_version: {
39
+ type: Number,
40
+ required: true,
41
+ immutable: true,
42
+ default: MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_SCHEMA_VERSION,
43
+ },
44
+ computed_at: { type: mongoose_1.Schema.Types.Date, required: true },
45
+ createdAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date(), immutable: true },
46
+ updatedAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date() },
47
+ }, { timestamps: true, versionKey: false });
48
+ exports.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_COLLECTION_NAME = 'materialized_tenant_delivery_geo_cells';
49
+ /**
50
+ * The indexes the heat reads/writes assume:
51
+ * 1. the UNIQUE cell identity (one document per tenant/scope/cell);
52
+ * 2. the map's read path - a scope, busiest cells first;
53
+ * 3. the 2dsphere index a future viewport `$geoWithin` read needs.
54
+ *
55
+ * The unknown bucket has no `location`, so it is absent from (3) by design.
56
+ */
57
+ exports.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_COLLECTION_INDEXES = {
58
+ _id: { _id: 1 },
59
+ tenant_id__scope_context__scope_field__h3_cell: {
60
+ tenant_id: 1,
61
+ scope_context: 1,
62
+ scope_field: 1,
63
+ h3_cell: 1,
64
+ },
65
+ scope_context__scope_field__orders: {
66
+ scope_context: 1,
67
+ scope_field: 1,
68
+ orders: -1,
69
+ },
70
+ location__2dsphere: { location: '2dsphere' },
71
+ };
72
+ exports.MATERIALIZED_TENANT_DELIVERY_GEO_CELLS_INDEX_OPTIONS = [
73
+ {
74
+ key: { tenant_id: 1, scope_context: 1, scope_field: 1, h3_cell: 1 },
75
+ name: 'tenant_id__scope_context__scope_field__h3_cell',
76
+ unique: true,
77
+ },
78
+ {
79
+ key: { scope_context: 1, scope_field: 1, orders: -1 },
80
+ name: 'scope_context__scope_field__orders',
81
+ },
82
+ {
83
+ key: { location: '2dsphere' },
84
+ name: 'location__2dsphere',
85
+ },
86
+ ];
@@ -0,0 +1,71 @@
1
+ import { Schema } from 'mongoose';
2
+ /** Per-scope cap metadata; never one document per cell. */
3
+ export declare const MaterializedTenantDeliveryGeoScopeSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
4
+ timestamps: true;
5
+ versionKey: false;
6
+ }, {
7
+ createdAt: NativeDate;
8
+ updatedAt: NativeDate;
9
+ } & {
10
+ createdAt: NativeDate;
11
+ updatedAt: NativeDate;
12
+ brand_id: string;
13
+ tenant_id: string;
14
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
15
+ scope_field: string;
16
+ schema_version: number;
17
+ computed_at: NativeDate;
18
+ capped_cell_count: number;
19
+ capped_order_count: number;
20
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
21
+ createdAt: NativeDate;
22
+ updatedAt: NativeDate;
23
+ } & {
24
+ createdAt: NativeDate;
25
+ updatedAt: NativeDate;
26
+ brand_id: string;
27
+ tenant_id: string;
28
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
29
+ scope_field: string;
30
+ schema_version: number;
31
+ computed_at: NativeDate;
32
+ capped_cell_count: number;
33
+ capped_order_count: number;
34
+ }>> & import("mongoose").FlatRecord<{
35
+ createdAt: NativeDate;
36
+ updatedAt: NativeDate;
37
+ } & {
38
+ createdAt: NativeDate;
39
+ updatedAt: NativeDate;
40
+ brand_id: string;
41
+ tenant_id: string;
42
+ scope_context: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_SCOPE_ENUM;
43
+ scope_field: string;
44
+ schema_version: number;
45
+ computed_at: NativeDate;
46
+ capped_cell_count: number;
47
+ capped_order_count: number;
48
+ }> & {
49
+ _id: import("mongoose").Types.ObjectId;
50
+ } & {
51
+ __v: number;
52
+ }>;
53
+ export declare const MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_COLLECTION_INDEXES: {
54
+ _id: {
55
+ _id: number;
56
+ };
57
+ tenant_id__scope_context__scope_field: {
58
+ tenant_id: number;
59
+ scope_context: number;
60
+ scope_field: number;
61
+ };
62
+ };
63
+ export declare const MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_INDEX_OPTIONS: {
64
+ key: {
65
+ tenant_id: number;
66
+ scope_context: number;
67
+ scope_field: number;
68
+ };
69
+ name: string;
70
+ unique: boolean;
71
+ }[];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_INDEX_OPTIONS = exports.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_COLLECTION_INDEXES = exports.MaterializedTenantDeliveryGeoScopeSchema = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
6
+ /** Per-scope cap metadata; never one document per cell. */
7
+ exports.MaterializedTenantDeliveryGeoScopeSchema = new mongoose_1.Schema({
8
+ tenant_id: { type: String, required: true },
9
+ brand_id: { type: String, required: true },
10
+ scope_context: { type: String, required: true, enum: MATERIALIZED_REPORTS_1.MATERIALIZED_DELIVERY_GEO_SCOPES },
11
+ scope_field: { type: String, required: true },
12
+ capped_cell_count: { type: Number, required: true, min: 0, default: 0 },
13
+ capped_order_count: { type: Number, required: true, min: 0, default: 0 },
14
+ schema_version: {
15
+ type: Number,
16
+ required: true,
17
+ immutable: true,
18
+ default: MATERIALIZED_REPORTS_1.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_SCHEMA_VERSION,
19
+ },
20
+ computed_at: { type: mongoose_1.Schema.Types.Date, required: true },
21
+ createdAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date(), immutable: true },
22
+ updatedAt: { type: mongoose_1.Schema.Types.Date, required: true, default: () => new Date() },
23
+ }, { timestamps: true, versionKey: false });
24
+ exports.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_COLLECTION_INDEXES = {
25
+ _id: { _id: 1 },
26
+ tenant_id__scope_context__scope_field: {
27
+ tenant_id: 1,
28
+ scope_context: 1,
29
+ scope_field: 1,
30
+ },
31
+ };
32
+ exports.MATERIALIZED_TENANT_DELIVERY_GEO_SCOPES_INDEX_OPTIONS = [
33
+ {
34
+ key: { tenant_id: 1, scope_context: 1, scope_field: 1 },
35
+ name: 'tenant_id__scope_context__scope_field',
36
+ unique: true,
37
+ },
38
+ ];
@@ -6,7 +6,16 @@ import { Schema } from 'mongoose';
6
6
  * bounded sub-documents (rider / area leaderboards with an hour heat map), which Mongoose
7
7
  * cannot type precisely without a fixed key set - the keys ARE the data.
8
8
  */
9
- export declare const MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 1;
9
+ /**
10
+ * v2 - the production day-close writer.
11
+ *
12
+ * v1 was the pre-production shape. v2 splits the AREA row into the ORDER-side
13
+ * (`delivery_orders`, net sale, fees) and the APP-side (`delivery_records`, payout)
14
+ * populations, keys the demand heat on the joined ORDER's `localHour`, and fixes the
15
+ * refund source to the payment rows. A v1 document is still readable: the formatter
16
+ * falls back to the old `count` field for the record total.
17
+ */
18
+ export declare const MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 2;
10
19
  export declare const MaterializedTenantDeliveryReportSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
11
20
  timestamps: true;
12
21
  versionKey: false;
@@ -11,7 +11,16 @@ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
11
11
  * bounded sub-documents (rider / area leaderboards with an hour heat map), which Mongoose
12
12
  * cannot type precisely without a fixed key set - the keys ARE the data.
13
13
  */
14
- exports.MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 1;
14
+ /**
15
+ * v2 - the production day-close writer.
16
+ *
17
+ * v1 was the pre-production shape. v2 splits the AREA row into the ORDER-side
18
+ * (`delivery_orders`, net sale, fees) and the APP-side (`delivery_records`, payout)
19
+ * populations, keys the demand heat on the joined ORDER's `localHour`, and fixes the
20
+ * refund source to the payment rows. A v1 document is still readable: the formatter
21
+ * falls back to the old `count` field for the record total.
22
+ */
23
+ exports.MATERIALIZED_TENANT_DELIVERY_REPORTS_SCHEMA_VERSION = 2;
15
24
  exports.MaterializedTenantDeliveryReportSchema = new mongoose_1.Schema({
16
25
  tenant_id: { type: String, required: true },
17
26
  brand_id: { type: String, required: true },