@managesome/eposmatic-toolkit 0.3.10 → 0.4.0

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 (145) hide show
  1. package/esm/constants/ENUMS.js +17 -1988
  2. package/esm/constants/MATERIALIZED_REPORTS.js +105 -0
  3. package/esm/constants/enums/cash.js +45 -0
  4. package/esm/constants/enums/communications.js +329 -0
  5. package/esm/constants/enums/delivery.js +35 -0
  6. package/esm/constants/enums/geo.js +150 -0
  7. package/esm/constants/enums/hr.js +130 -0
  8. package/esm/constants/enums/internal.js +132 -0
  9. package/esm/constants/enums/items.js +126 -0
  10. package/esm/constants/enums/misc.js +35 -0
  11. package/esm/constants/enums/offers.js +102 -0
  12. package/esm/constants/enums/order.js +135 -0
  13. package/esm/constants/enums/payments.js +186 -0
  14. package/esm/constants/enums/platform.js +215 -0
  15. package/esm/constants/enums/printing.js +107 -0
  16. package/esm/constants/enums/users.js +245 -0
  17. package/esm/constants/enums/wallet.js +32 -0
  18. package/esm/helpers/materialized-reports/index.js +5 -0
  19. package/esm/helpers/materialized-reports/key-helpers.js +59 -0
  20. package/esm/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.js +60 -0
  21. package/esm/helpers/materialized-reports/scope-helpers.js +107 -0
  22. package/esm/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +251 -0
  23. package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +860 -0
  24. package/esm/helpers/store/cart-actions.js +1 -1
  25. package/esm/helpers/store/common-tenant-purchase-order-actions.js +7 -7
  26. package/esm/helpers/store/common-warehouse-purchase-order-actions.js +1 -1
  27. package/esm/helpers/store/common-warehouse-purchase-order-rfq-actions.js +1 -1
  28. package/esm/helpers/store/common-warehouse-sale-order-actions.js +1 -1
  29. package/esm/helpers/store/common-warehouse-sale-order-rfq-actions.js +1 -1
  30. package/esm/helpers/store/offline-ordering.js +1 -1
  31. package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +1 -1
  32. package/esm/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +1 -1
  33. package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +1 -1
  34. package/esm/helpers/store/warehouse-sale-order-rfq-cart-actions.js +1 -1
  35. package/esm/helpers/store/warehouse-sale-orders-cart-actions.js +1 -1
  36. package/esm/helpers/utils/cancellation-helpers.js +7 -0
  37. package/esm/helpers/utils/common.js +0 -46
  38. package/esm/helpers/utils/getFormFieldsDiff.js +1 -1
  39. package/esm/helpers/utils/index.js +2 -0
  40. package/esm/helpers/utils/phone-helpers.js +40 -0
  41. package/esm/helpers/utils/receipt-engine.js +3 -1
  42. package/esm/helpers/utils/specials-helpers.js +1 -1
  43. package/esm/helpers/utils/void-items-report-helpers.js +2 -1
  44. package/esm/schemas/models/materialized_tenant_reports_iterations.js +82 -0
  45. package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +399 -0
  46. package/esm/schemas/types/materialized_tenant_reports_iterations.js +1 -0
  47. package/esm/schemas/types/materialized_tenant_sales_overview_reports.js +1 -0
  48. package/lib/constants/ENUMS.d.ts +15 -1275
  49. package/lib/constants/ENUMS.js +31 -1994
  50. package/lib/constants/MATERIALIZED_REPORTS.d.ts +96 -0
  51. package/lib/constants/MATERIALIZED_REPORTS.js +108 -0
  52. package/lib/constants/enums/cash.d.ts +35 -0
  53. package/lib/constants/enums/cash.js +48 -0
  54. package/lib/constants/enums/communications.d.ts +79 -0
  55. package/lib/constants/enums/communications.js +332 -0
  56. package/lib/constants/enums/delivery.d.ts +26 -0
  57. package/lib/constants/enums/delivery.js +38 -0
  58. package/lib/constants/enums/geo.d.ts +133 -0
  59. package/lib/constants/enums/geo.js +153 -0
  60. package/lib/constants/enums/hr.d.ts +105 -0
  61. package/lib/constants/enums/hr.js +133 -0
  62. package/lib/constants/enums/internal.d.ts +104 -0
  63. package/lib/constants/enums/internal.js +135 -0
  64. package/lib/constants/enums/items.d.ts +94 -0
  65. package/lib/constants/enums/items.js +129 -0
  66. package/lib/constants/enums/misc.d.ts +25 -0
  67. package/lib/constants/enums/misc.js +38 -0
  68. package/lib/constants/enums/offers.d.ts +80 -0
  69. package/lib/constants/enums/offers.js +105 -0
  70. package/lib/constants/enums/order.d.ts +108 -0
  71. package/lib/constants/enums/order.js +138 -0
  72. package/lib/constants/enums/payments.d.ts +129 -0
  73. package/lib/constants/enums/payments.js +189 -0
  74. package/lib/constants/enums/platform.d.ts +100 -0
  75. package/lib/constants/enums/platform.js +218 -0
  76. package/lib/constants/enums/printing.d.ts +89 -0
  77. package/lib/constants/enums/printing.js +110 -0
  78. package/lib/constants/enums/users.d.ts +142 -0
  79. package/lib/constants/enums/users.js +248 -0
  80. package/lib/constants/enums/wallet.d.ts +26 -0
  81. package/lib/constants/enums/wallet.js +35 -0
  82. package/lib/helpers/materialized-reports/index.d.ts +5 -0
  83. package/lib/helpers/materialized-reports/index.js +21 -0
  84. package/lib/helpers/materialized-reports/key-helpers.d.ts +35 -0
  85. package/lib/helpers/materialized-reports/key-helpers.js +64 -0
  86. package/lib/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.d.ts +66 -0
  87. package/lib/helpers/materialized-reports/materialized-tenant-reports-iterations-helpers.js +63 -0
  88. package/lib/helpers/materialized-reports/scope-helpers.d.ts +57 -0
  89. package/lib/helpers/materialized-reports/scope-helpers.js +114 -0
  90. package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.d.ts +125 -0
  91. package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +256 -0
  92. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +223 -0
  93. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +875 -0
  94. package/lib/helpers/store/cart-actions.js +6 -6
  95. package/lib/helpers/store/common-tenant-purchase-order-actions.d.ts +2 -2
  96. package/lib/helpers/store/common-tenant-purchase-order-actions.js +10 -10
  97. package/lib/helpers/store/common-warehouse-purchase-order-actions.js +4 -4
  98. package/lib/helpers/store/common-warehouse-purchase-order-rfq-actions.js +4 -4
  99. package/lib/helpers/store/common-warehouse-sale-order-actions.js +4 -4
  100. package/lib/helpers/store/common-warehouse-sale-order-rfq-actions.js +4 -4
  101. package/lib/helpers/store/offline-ordering.js +2 -2
  102. package/lib/helpers/store/tenant-purchase-orders-cart-actions.js +2 -2
  103. package/lib/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +2 -2
  104. package/lib/helpers/store/warehouse-purchase-orders-cart-actions.js +2 -2
  105. package/lib/helpers/store/warehouse-sale-order-rfq-cart-actions.js +2 -2
  106. package/lib/helpers/store/warehouse-sale-orders-cart-actions.js +2 -2
  107. package/lib/helpers/utils/cancellation-helpers.d.ts +1 -0
  108. package/lib/helpers/utils/cancellation-helpers.js +13 -0
  109. package/lib/helpers/utils/common.d.ts +0 -6
  110. package/lib/helpers/utils/common.js +1 -54
  111. package/lib/helpers/utils/getFormFieldsDiff.js +5 -2
  112. package/lib/helpers/utils/index.d.ts +2 -0
  113. package/lib/helpers/utils/index.js +2 -0
  114. package/lib/helpers/utils/phone-helpers.d.ts +5 -0
  115. package/lib/helpers/utils/phone-helpers.js +46 -0
  116. package/lib/helpers/utils/receipt-engine.js +4 -2
  117. package/lib/helpers/utils/specials-helpers.js +2 -2
  118. package/lib/helpers/utils/void-items-report-helpers.js +3 -2
  119. package/lib/schemas/models/materialized_tenant_reports_iterations.d.ts +80 -0
  120. package/lib/schemas/models/materialized_tenant_reports_iterations.js +85 -0
  121. package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +569 -0
  122. package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +402 -0
  123. package/lib/schemas/types/materialized_tenant_reports_iterations.d.ts +62 -0
  124. package/lib/schemas/types/materialized_tenant_reports_iterations.js +2 -0
  125. package/lib/schemas/types/materialized_tenant_sales_overview_reports.d.ts +242 -0
  126. package/lib/schemas/types/materialized_tenant_sales_overview_reports.js +3 -0
  127. package/lib/tests/materialized-reports/fixtures.d.ts +81 -0
  128. package/lib/tests/materialized-reports/fixtures.js +87 -0
  129. package/lib/tests/materialized-reports/fixtures.test.d.ts +1 -0
  130. package/lib/tests/materialized-reports/fixtures.test.js +123 -0
  131. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-helpers.test.d.ts +1 -0
  132. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-helpers.test.js +75 -0
  133. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.d.ts +1 -0
  134. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.js +73 -0
  135. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.d.ts +1 -0
  136. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +207 -0
  137. package/lib/tests/materialized-reports/sales-overview-baseline.test.d.ts +1 -0
  138. package/lib/tests/materialized-reports/sales-overview-baseline.test.js +326 -0
  139. package/lib/tests/materialized-reports/sales-overview-reference.d.ts +63 -0
  140. package/lib/tests/materialized-reports/sales-overview-reference.js +131 -0
  141. package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.d.ts +1 -0
  142. package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +335 -0
  143. package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.d.ts +1 -0
  144. package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +885 -0
  145. package/package.json +5 -2
@@ -17,7 +17,9 @@ const moment_1 = __importDefault(require("moment"));
17
17
  const constants_1 = require("../../constants");
18
18
  const store_1 = require("../store");
19
19
  const cart_helpers_1 = require("./cart-helpers");
20
+ const cancellation_helpers_1 = require("./cancellation-helpers");
20
21
  const common_1 = require("./common");
22
+ const phone_helpers_1 = require("./phone-helpers");
21
23
  const payment_helpers_1 = require("./payment-helpers");
22
24
  // =========================><=========================
23
25
  function getDiscountLabel(discount_details) {
@@ -876,7 +878,7 @@ function receiptEngine(payload, mappedItems = {}) {
876
878
  let customerPhone = null;
877
879
  if (payload.order.consumer != null &&
878
880
  (payload.order.staff_details == null || payload.order.consumer.phone !== payload.order.staff_details.staff_mobile)) {
879
- const phoneNumber = (0, common_1.getNationalNumberFromPhone)(payload.order.consumer.phone);
881
+ const phoneNumber = (0, phone_helpers_1.getNationalNumberFromPhone)(payload.order.consumer.phone);
880
882
  customerName = `${payload.order.consumer.first_name} ${payload.order.consumer.last_name}`.trim();
881
883
  customerPhone = phoneNumber ?? payload.order.consumer.phone;
882
884
  }
@@ -932,7 +934,7 @@ function receiptEngine(payload, mappedItems = {}) {
932
934
  let delivery_instructions = null;
933
935
  let cancel_reason = null;
934
936
  if (payload.order.order_status === constants_1.ORDER_STATUS_ENUM.CANCELLED) {
935
- cancel_reason = (0, common_1.getFormattedCancellationReason)(payload.order.cancel_reason) ?? null;
937
+ cancel_reason = (0, cancellation_helpers_1.getFormattedCancellationReason)(payload.order.cancel_reason) ?? null;
936
938
  }
937
939
  else if (payload.order.delivery_details != null && payload.printer_settings.print_delivery_details) {
938
940
  delivery_instructions = `${payload.order.delivery_details.street}${payload.order.delivery_details.address_instructions.trim() !== ''
@@ -14,7 +14,7 @@ exports.convertSpecialItemToOrderItem = convertSpecialItemToOrderItem;
14
14
  exports.deStructureSpecialOrderItem = deStructureSpecialOrderItem;
15
15
  exports.convertSpecialToItem = convertSpecialToItem;
16
16
  const bson_objectid_1 = __importDefault(require("bson-objectid"));
17
- const lodash_1 = require("lodash");
17
+ const isEqual_1 = __importDefault(require("lodash/isEqual"));
18
18
  const constants_1 = require("../../constants");
19
19
  const store_1 = require("../store");
20
20
  const halfhalf_setup_helpers_1 = require("./halfhalf-setup-helpers");
@@ -318,7 +318,7 @@ function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity
318
318
  // (a mixed group stays as a free option + a paid option).
319
319
  const mergedEntries = [];
320
320
  for (const entry of entries) {
321
- const existing = mergedEntries.find((candidate) => candidate.option.is_free === entry.option.is_free && (0, lodash_1.isEqual)(candidate.comparable, entry.comparable));
321
+ const existing = mergedEntries.find((candidate) => candidate.option.is_free === entry.option.is_free && (0, isEqual_1.default)(candidate.comparable, entry.comparable));
322
322
  if (existing != null) {
323
323
  existing.option.quantity = (existing.option.quantity || 1) + (entry.option.quantity || 1);
324
324
  continue;
@@ -7,6 +7,7 @@ exports.getVoidItemsReportHtml = getVoidItemsReportHtml;
7
7
  exports.getVoidItemsReportReceiptHtml = getVoidItemsReportReceiptHtml;
8
8
  const moment_1 = __importDefault(require("moment"));
9
9
  const constants_1 = require("../../constants");
10
+ const cancellation_helpers_1 = require("./cancellation-helpers");
10
11
  const common_1 = require("./common");
11
12
  // Generate HTML template for void items report
12
13
  function getVoidItemsReportHtml(props) {
@@ -271,7 +272,7 @@ function getVoidItemsReportHtml(props) {
271
272
  <td>${item.name || 'N/A'}</td>
272
273
  ${hasPartyNameColumn ? `<td>${item.vendor_name || item.client_name || 'N/A'}</td>` : ''}
273
274
  <td class="text-right">${(0, common_1.localeAmount)(currency_symbol, voidAmount)}</td>
274
- <td class="void-reason">${item.void_reason ? (0, common_1.getFormattedCancellationReason)(item.void_reason) : 'N/A'}</td>
275
+ <td class="void-reason">${item.void_reason ? (0, cancellation_helpers_1.getFormattedCancellationReason)(item.void_reason) : 'N/A'}</td>
275
276
  <td>${item.staff_name || 'N/A'}</td>
276
277
  <td class="text-center">${item.quantity || 0}</td>
277
278
  <td class="text-center">${item.total_adjusted_quantity || 0}</td>
@@ -484,7 +485,7 @@ function getVoidItemsReportReceiptHtml(props) {
484
485
  <div class="item-detail reason">
485
486
  <span style='font-weight: bold;'>Reason:</span>
486
487
  <span class="reason-text">${(() => {
487
- const formattedReason = (0, common_1.getFormattedCancellationReason)(item.void_reason) || 'Unknown';
488
+ const formattedReason = (0, cancellation_helpers_1.getFormattedCancellationReason)(item.void_reason) || 'Unknown';
488
489
  return formattedReason.substring(0, 100) + (formattedReason.length > 100 ? '...' : '');
489
490
  })()}</span>
490
491
  </div>
@@ -0,0 +1,80 @@
1
+ import { Schema } from 'mongoose';
2
+ /**
3
+ * Mongoose schema for `materialized_tenant_reports_iterations` — the shared iteration
4
+ * history of every materialized report collection (see
5
+ * `MATERIALIZED_REPORTS.md`, "Iteration history").
6
+ *
7
+ * One append-only row per VERSIONED write of a report document; `snapshot`
8
+ * holds the full report document AFTER the write. `snapshot` is Mixed because
9
+ * the collection serves every report kind (`report_type` discriminates).
10
+ * Received-payment patches that change the ledger are versioned writes too
11
+ * (they bump `iteration` and append rows); no-op patches write nothing.
12
+ * Every row carries the backend-generated `reason` for the audit trail.
13
+ */
14
+ export declare const MaterializedTenantReportIterationSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
15
+ timestamps: true;
16
+ versionKey: false;
17
+ minimize: false;
18
+ }, {
19
+ createdAt: NativeDate;
20
+ updatedAt: NativeDate;
21
+ } & {
22
+ _id: import("mongoose").Types.ObjectId;
23
+ reason: string;
24
+ createdAt: NativeDate;
25
+ updatedAt: NativeDate;
26
+ iteration: number;
27
+ report_type: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_OVERVIEW;
28
+ report_id: import("mongoose").Types.ObjectId;
29
+ schema_version: number;
30
+ snapshot: any;
31
+ }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
32
+ createdAt: NativeDate;
33
+ updatedAt: NativeDate;
34
+ } & {
35
+ _id: import("mongoose").Types.ObjectId;
36
+ reason: string;
37
+ createdAt: NativeDate;
38
+ updatedAt: NativeDate;
39
+ iteration: number;
40
+ report_type: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_OVERVIEW;
41
+ report_id: import("mongoose").Types.ObjectId;
42
+ schema_version: number;
43
+ snapshot: any;
44
+ }>> & import("mongoose").FlatRecord<{
45
+ createdAt: NativeDate;
46
+ updatedAt: NativeDate;
47
+ } & {
48
+ _id: import("mongoose").Types.ObjectId;
49
+ reason: string;
50
+ createdAt: NativeDate;
51
+ updatedAt: NativeDate;
52
+ iteration: number;
53
+ report_type: import("../../constants/MATERIALIZED_REPORTS").MATERIALIZED_REPORT_TYPE_ENUM.TENANT_SALES_OVERVIEW;
54
+ report_id: import("mongoose").Types.ObjectId;
55
+ schema_version: number;
56
+ snapshot: any;
57
+ }> & Required<{
58
+ _id: import("mongoose").Types.ObjectId;
59
+ }> & {
60
+ __v: number;
61
+ }>;
62
+ export declare const MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME = "materialized_tenant_reports_iterations";
63
+ /**
64
+ * Indexes for `materialized_tenant_reports_iterations` (values are Mongo key patterns that
65
+ * can be passed straight to `.hint()`):
66
+ * - `_id`: unique primary key.
67
+ * - `report_id__iteration`: UNIQUE — one row per (report, iteration); serves
68
+ * per-report history reads (`{ report_id }` + `.sort({ iteration: -1 })`;
69
+ * the head row mirrors the live document) and doubles as the idempotent
70
+ * upsert key (`replaceOne({ report_id, iteration }, row, { upsert: true })`).
71
+ */
72
+ export declare const MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_INDEXES: {
73
+ _id: {
74
+ _id: number;
75
+ };
76
+ report_id__iteration: {
77
+ report_id: number;
78
+ iteration: number;
79
+ };
80
+ };
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_INDEXES = exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME = exports.MaterializedTenantReportIterationSchema = void 0;
4
+ const mongoose_1 = require("mongoose");
5
+ const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
6
+ /**
7
+ * Mongoose schema for `materialized_tenant_reports_iterations` — the shared iteration
8
+ * history of every materialized report collection (see
9
+ * `MATERIALIZED_REPORTS.md`, "Iteration history").
10
+ *
11
+ * One append-only row per VERSIONED write of a report document; `snapshot`
12
+ * holds the full report document AFTER the write. `snapshot` is Mixed because
13
+ * the collection serves every report kind (`report_type` discriminates).
14
+ * Received-payment patches that change the ledger are versioned writes too
15
+ * (they bump `iteration` and append rows); no-op patches write nothing.
16
+ * Every row carries the backend-generated `reason` for the audit trail.
17
+ */
18
+ exports.MaterializedTenantReportIterationSchema = new mongoose_1.Schema({
19
+ _id: {
20
+ type: mongoose_1.Schema.Types.ObjectId,
21
+ required: true,
22
+ immutable: true,
23
+ },
24
+ report_type: {
25
+ type: String,
26
+ enum: MATERIALIZED_REPORTS_1.ALL_MATERIALIZED_REPORT_TYPES,
27
+ required: true,
28
+ immutable: true,
29
+ },
30
+ report_id: {
31
+ type: mongoose_1.Schema.Types.ObjectId,
32
+ required: true,
33
+ immutable: true,
34
+ },
35
+ iteration: {
36
+ type: Number,
37
+ required: true,
38
+ min: 1,
39
+ },
40
+ schema_version: {
41
+ type: Number,
42
+ required: true,
43
+ },
44
+ // Why the iteration happened — backend-generated free string, e.g.
45
+ // 'NEW_DAY' | 'RECLOSE' | 'RECONCILE' | 'CREDIT_BILL_COLLECTED'.
46
+ reason: {
47
+ type: String,
48
+ required: true,
49
+ },
50
+ // Full report document as written — polymorphic across report kinds, so
51
+ // untyped/Mixed; narrow by `report_type` (see the type file).
52
+ snapshot: {
53
+ type: mongoose_1.Schema.Types.Mixed,
54
+ required: true,
55
+ },
56
+ createdAt: {
57
+ type: mongoose_1.Schema.Types.Date,
58
+ required: true,
59
+ default: () => new Date(),
60
+ immutable: true,
61
+ },
62
+ updatedAt: {
63
+ type: mongoose_1.Schema.Types.Date,
64
+ required: true,
65
+ default: () => new Date(),
66
+ },
67
+ }, {
68
+ timestamps: true,
69
+ versionKey: false,
70
+ minimize: false,
71
+ });
72
+ exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_NAME = 'materialized_tenant_reports_iterations';
73
+ /**
74
+ * Indexes for `materialized_tenant_reports_iterations` (values are Mongo key patterns that
75
+ * can be passed straight to `.hint()`):
76
+ * - `_id`: unique primary key.
77
+ * - `report_id__iteration`: UNIQUE — one row per (report, iteration); serves
78
+ * per-report history reads (`{ report_id }` + `.sort({ iteration: -1 })`;
79
+ * the head row mirrors the live document) and doubles as the idempotent
80
+ * upsert key (`replaceOne({ report_id, iteration }, row, { upsert: true })`).
81
+ */
82
+ exports.MATERIALIZED_TENANT_REPORTS_ITERATIONS_COLLECTION_INDEXES = {
83
+ _id: { _id: 1 }, // Unique Index
84
+ report_id__iteration: { report_id: 1, iteration: -1 }, // unique — one row per (report, iteration)
85
+ };