@managesome/eposmatic-toolkit 0.4.60 → 0.4.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +254 -4
  2. package/esm/constants/TENANT_ENUMS.js +15 -0
  3. package/esm/constants/WORKER_ENDPOINTS.js +12 -0
  4. package/esm/helpers/materialized-reports/index.js +8 -0
  5. package/esm/helpers/materialized-reports/materialized-day-readiness.js +2 -2
  6. package/esm/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +557 -0
  7. package/esm/helpers/materialized-reports/materialized-dinein-classification-helpers.js +447 -0
  8. package/esm/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +372 -0
  9. package/esm/helpers/materialized-reports/materialized-dinein-compile-helpers.js +500 -0
  10. package/esm/helpers/materialized-reports/materialized-dinein-entry-pages.js +218 -0
  11. package/esm/helpers/materialized-reports/materialized-dinein-key-helpers.js +87 -0
  12. package/esm/helpers/materialized-reports/materialized-index-bootstrap.js +7 -1
  13. package/esm/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
  14. package/esm/helpers/materialized-reports/materialized-report-runs.js +143 -0
  15. package/esm/helpers/materialized-reports/report-platform/definition.js +93 -1
  16. package/esm/helpers/materialized-reports/tenant-dinein-formatter.js +240 -0
  17. package/esm/helpers/reporting-contract/report-contract.js +3 -0
  18. package/esm/schemas/models/index.js +3 -0
  19. package/esm/schemas/models/materialized_tenant_dinein_entries.js +57 -0
  20. package/esm/schemas/models/materialized_tenant_dinein_reports.js +73 -0
  21. package/esm/schemas/models/materialized_tenant_report_runs.js +105 -0
  22. package/esm/schemas/models/tenant_active_jobs.js +19 -1
  23. package/esm/schemas/types/index.js +3 -0
  24. package/esm/schemas/types/materialized_report_drilldown_rows.js +1 -0
  25. package/esm/schemas/types/materialized_tenant_dinein_entries.js +1 -0
  26. package/esm/schemas/types/materialized_tenant_dinein_reports.js +6 -0
  27. package/esm/schemas/types/materialized_tenant_report_runs.js +1 -0
  28. package/lib/constants/MATERIALIZED_REPORTS.d.ts +229 -4
  29. package/lib/constants/MATERIALIZED_REPORTS.js +255 -5
  30. package/lib/constants/TENANT_ENUMS.d.ts +14 -0
  31. package/lib/constants/TENANT_ENUMS.js +16 -1
  32. package/lib/constants/WORKER_ENDPOINTS.d.ts +12 -0
  33. package/lib/constants/WORKER_ENDPOINTS.js +12 -0
  34. package/lib/helpers/materialized-reports/index.d.ts +8 -0
  35. package/lib/helpers/materialized-reports/index.js +8 -0
  36. package/lib/helpers/materialized-reports/materialized-day-readiness.d.ts +1 -1
  37. package/lib/helpers/materialized-reports/materialized-day-readiness.js +2 -2
  38. package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.d.ts +67 -0
  39. package/lib/helpers/materialized-reports/materialized-dinein-accumulator-helpers.js +582 -0
  40. package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.d.ts +245 -0
  41. package/lib/helpers/materialized-reports/materialized-dinein-classification-helpers.js +469 -0
  42. package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.d.ts +110 -0
  43. package/lib/helpers/materialized-reports/materialized-dinein-close-day-helpers.js +384 -0
  44. package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.d.ts +73 -0
  45. package/lib/helpers/materialized-reports/materialized-dinein-compile-helpers.js +504 -0
  46. package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.d.ts +69 -0
  47. package/lib/helpers/materialized-reports/materialized-dinein-entry-pages.js +231 -0
  48. package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.d.ts +44 -0
  49. package/lib/helpers/materialized-reports/materialized-dinein-key-helpers.js +96 -0
  50. package/lib/helpers/materialized-reports/materialized-index-bootstrap.js +6 -0
  51. package/lib/helpers/materialized-reports/materialized-report-drilldown-rows.js +8 -0
  52. package/lib/helpers/materialized-reports/materialized-report-runs.d.ts +105 -0
  53. package/lib/helpers/materialized-reports/materialized-report-runs.js +156 -0
  54. package/lib/helpers/materialized-reports/report-platform/definition.js +92 -0
  55. package/lib/helpers/materialized-reports/tenant-dinein-formatter.d.ts +225 -0
  56. package/lib/helpers/materialized-reports/tenant-dinein-formatter.js +243 -0
  57. package/lib/helpers/reporting-contract/report-contract.d.ts +1 -0
  58. package/lib/helpers/reporting-contract/report-contract.js +3 -0
  59. package/lib/helpers/types/workers.d.ts +65 -0
  60. package/lib/schemas/models/index.d.ts +3 -0
  61. package/lib/schemas/models/index.js +3 -0
  62. package/lib/schemas/models/materialized_tenant_day_readiness.d.ts +3 -3
  63. package/lib/schemas/models/materialized_tenant_dinein_entries.d.ts +100 -0
  64. package/lib/schemas/models/materialized_tenant_dinein_entries.js +60 -0
  65. package/lib/schemas/models/materialized_tenant_dinein_reports.d.ts +111 -0
  66. package/lib/schemas/models/materialized_tenant_dinein_reports.js +76 -0
  67. package/lib/schemas/models/materialized_tenant_report_runs.d.ts +97 -0
  68. package/lib/schemas/models/materialized_tenant_report_runs.js +108 -0
  69. package/lib/schemas/models/tenant_active_jobs.d.ts +12 -3
  70. package/lib/schemas/models/tenant_active_jobs.js +18 -0
  71. package/lib/schemas/types/index.d.ts +3 -0
  72. package/lib/schemas/types/index.js +3 -0
  73. package/lib/schemas/types/materialized_report_drilldown_rows.d.ts +1 -1
  74. package/lib/schemas/types/materialized_report_drilldown_rows.js +1 -0
  75. package/lib/schemas/types/materialized_tenant_dinein_entries.d.ts +127 -0
  76. package/lib/schemas/types/materialized_tenant_dinein_entries.js +2 -0
  77. package/lib/schemas/types/materialized_tenant_dinein_reports.d.ts +326 -0
  78. package/lib/schemas/types/materialized_tenant_dinein_reports.js +9 -0
  79. package/lib/schemas/types/materialized_tenant_report_runs.d.ts +55 -0
  80. package/lib/schemas/types/materialized_tenant_report_runs.js +2 -0
  81. package/lib/schemas/types/tenant_active_jobs.d.ts +15 -1
  82. package/lib/tests/materialized-reports/dinein-fixtures.d.ts +29 -0
  83. package/lib/tests/materialized-reports/dinein-fixtures.js +130 -0
  84. package/lib/tests/materialized-reports/materialized-day-readiness.test.js +3 -2
  85. package/lib/tests/materialized-reports/materialized-dinein-compile.test.d.ts +1 -0
  86. package/lib/tests/materialized-reports/materialized-dinein-compile.test.js +807 -0
  87. package/lib/tests/materialized-reports/materialized-dinein-plan.test.d.ts +1 -0
  88. package/lib/tests/materialized-reports/materialized-dinein-plan.test.js +419 -0
  89. package/lib/tests/materialized-reports/materialized-report-runs.test.d.ts +1 -0
  90. package/lib/tests/materialized-reports/materialized-report-runs.test.js +116 -0
  91. package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.d.ts +1 -0
  92. package/lib/tests/materialized-reports/materialized-tenant-dinein-schema.test.js +185 -0
  93. package/lib/tests/materialized-reports/report-platform/registry-conformance.test.js +15 -2
  94. package/lib/tests/materialized-reports/tenant-dinein-formatter.test.d.ts +1 -0
  95. package/lib/tests/materialized-reports/tenant-dinein-formatter.test.js +458 -0
  96. package/package.json +1 -1
@@ -682,6 +682,8 @@ export var MATERIALIZED_REPORT_TYPE_ENUM;
682
682
  MATERIALIZED_REPORT_TYPE_ENUM["TENANT_PAYMENTS_COMPARISON_ENTRIES"] = "TENANT_PAYMENTS_COMPARISON_ENTRIES";
683
683
  MATERIALIZED_REPORT_TYPE_ENUM["TENANT_DIALER_REPORTS"] = "TENANT_DIALER_REPORTS";
684
684
  MATERIALIZED_REPORT_TYPE_ENUM["TENANT_DIALER_ENTRIES"] = "TENANT_DIALER_ENTRIES";
685
+ MATERIALIZED_REPORT_TYPE_ENUM["TENANT_DINEIN_REPORTS"] = "TENANT_DINEIN_REPORTS";
686
+ MATERIALIZED_REPORT_TYPE_ENUM["TENANT_DINEIN_ENTRIES"] = "TENANT_DINEIN_ENTRIES";
685
687
  })(MATERIALIZED_REPORT_TYPE_ENUM || (MATERIALIZED_REPORT_TYPE_ENUM = {}));
686
688
  export const ALL_MATERIALIZED_REPORT_TYPES = Object.values(MATERIALIZED_REPORT_TYPE_ENUM);
687
689
  /* =====================> Sales Comparison report <===================== */
@@ -899,11 +901,175 @@ export const MATERIALIZED_DIALER_HOUR_KEYS = Array.from({ length: 24 }, (_, hour
899
901
  export const MATERIALIZED_DIALER_REPORT_MAX_BSON_BYTES = 15 * 1024 * 1024;
900
902
  export const MATERIALIZED_DIALER_ENTRY_MAX_BSON_BYTES = 15 * 1024 * 1024;
901
903
  /* ======================================================================== */
902
- /* Day readiness (five production writers) */
904
+ /* Dinein report (M5) */
903
905
  /* ======================================================================== */
904
906
  /**
905
- * COMMITTED-READINESS ledger for the five reports written by END_TENANT_DAY and
906
- * the range sync: Overview, Discounts, Prep Time, Delivery and Dialer.
907
+ * The Dinein report: covers, checks, seated occupancy, courses, split bills,
908
+ * reservations and guest experience for the dine-in population.
909
+ *
910
+ * ## Population
911
+ *
912
+ * `orders` with `dinein_details != null` for the order's OWN `localDate`. The
913
+ * deleted split PARENT is excluded from sales/order counts (the children are the
914
+ * collectable checks) and is read only for rating/review discovery.
915
+ *
916
+ * ## Two collections, one report
917
+ *
918
+ * `materialized_tenant_dinein_reports` is COUNTERS ONLY, keyed by
919
+ * `<ORDER_STATUS>:<PLATFORM>` (`sale_type_key_filters`); the reservation block is
920
+ * day-level because a reservation has no order and must never be dropped by an
921
+ * order-status/platform filter. `materialized_tenant_dinein_entries` holds ONE
922
+ * PAGE per source day (the discounts/delivery/dialer page model).
923
+ */
924
+ /**
925
+ * The two collections are named/versioned by their model modules
926
+ * (`materialized_tenant_dinein_reports` / `..._entries`), exactly like the other
927
+ * materialized report collections.
928
+ */
929
+ /**
930
+ * Scopes materialized by `materialized_tenant_dinein_reports`.
931
+ *
932
+ * NO `localHour`: the hour dimension is the `by_hour` map inside the document
933
+ * (the sales/covers-by-hour chart), exactly like Delivery. `localDate` is the day
934
+ * the ORDER was sold on (`order.localDate`), never the fingerprint's creation
935
+ * day: a table can close after midnight and still belong to the day it was sold.
936
+ */
937
+ export const MATERIALIZED_DINEIN_REPORT_SCOPES = [
938
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
939
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK,
940
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK_OF_YEAR,
941
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
942
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_QUARTER,
943
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_SEMESTER,
944
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_YEAR,
945
+ ];
946
+ /**
947
+ * Entry scopes. A PERIOD entry document is PAGE-PARTITIONED by source day
948
+ * (`page = <source localDate>`) so a document is bounded by ONE day's checks; a
949
+ * month is covered by its 28-31 pages. There is no quarter/semester/year entry
950
+ * document, and a broad details selection is served from the month pages it
951
+ * touches (never refused).
952
+ */
953
+ export const MATERIALIZED_DINEIN_ENTRY_SCOPES = [
954
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
955
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK,
956
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_WEEK_OF_YEAR,
957
+ MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_MONTH,
958
+ ];
959
+ /** Page key of the DAY-scoped entry document (the day scope is already one day). */
960
+ export const MATERIALIZED_DINEIN_ENTRY_PAGE_ALL = 'all';
961
+ /**
962
+ * Ordered key filters of the dinein report (`COMPLETED:POS_DINE-IN`) — the SAME
963
+ * two dimensions every order-shaped materialized counter document declares. They
964
+ * are the only filters the SUMMARY can apply exactly, because they are the key
965
+ * grammar; origin / table / floor / split / offline are ROW filters and are
966
+ * declared `appliesTo: DETAILS` (a summary request that sends one is REJECTED,
967
+ * never silently answered unfiltered).
968
+ */
969
+ export const DINEIN_KEY_FILTERS = [
970
+ MATERIALIZED_REPORT_KEY_FILTER_ENUM.ORDER_STATUS,
971
+ MATERIALIZED_REPORT_KEY_FILTER_ENUM.PLATFORM,
972
+ ];
973
+ /** Token for a missing key/row dimension. A missing dimension is never dropped. */
974
+ export const MATERIALIZED_DINEIN_UNKNOWN_TOKEN = 'UNKNOWN';
975
+ /** Key-component separator (`<ORDER_STATUS>:<PLATFORM>`). */
976
+ export const MATERIALIZED_DINEIN_KEY_SEPARATOR = ':';
977
+ /**
978
+ * Token of the ONE overflow row every BOUNDED map keeps after its top-N
979
+ * (tables / floors / courses / service-charge rates), so a capped map still
980
+ * reconciles against the document totals instead of silently dropping rows.
981
+ */
982
+ export const MATERIALIZED_DINEIN_OTHER_TOKEN = '__OTHER__';
983
+ /** Per-document caps of the bounded maps (ranked `key ASC` after the metric). */
984
+ export const MATERIALIZED_DINEIN_TABLE_LIMIT = 200;
985
+ export const MATERIALIZED_DINEIN_FLOOR_LIMIT = 50;
986
+ export const MATERIALIZED_DINEIN_COURSE_LIMIT = 50;
987
+ export const MATERIALIZED_DINEIN_SERVICE_CHARGE_RATE_LIMIT = 50;
988
+ /**
989
+ * Caps of the two BOUNDED SUMMARY SNAPSHOTS.
990
+ *
991
+ * `upcoming_reservations` and `top_edited_checks` are display-only tables, not a
992
+ * second pagination source (the Orders tab always uses the cursor read). The DAY
993
+ * document keeps its own top-N; a PERIOD document re-ranks the union of its day
994
+ * documents' snapshots and keeps top-N again, so a month cannot grow the arrays.
995
+ */
996
+ export const MATERIALIZED_DINEIN_UPCOMING_RESERVATION_LIMIT = 10;
997
+ export const MATERIALIZED_DINEIN_TOP_EDITED_CHECK_LIMIT = 10;
998
+ /** The 24 hour keys of `by_hour`, initialized to 0 so absence is unambiguously zero. */
999
+ export const MATERIALIZED_DINEIN_HOUR_KEYS = Array.from({ length: 24 }, (_, hour) => String(hour));
1000
+ /**
1001
+ * `delete_reason` of a split parent that was auto-deleted by the split flow.
1002
+ *
1003
+ * The parent still carries the rating/review of the visit but is NOT a
1004
+ * collectable check: it never contributes sales or an order count.
1005
+ */
1006
+ export const MATERIALIZED_DINEIN_SPLIT_PARENT_DELETE_REASON = 'Auto Deleted on Split';
1007
+ /**
1008
+ * Where the first version of a check was taken. Derived from the OLDEST
1009
+ * iteration (or the current order when it has none) — see
1010
+ * `classifyMaterializedDineinOrigin`.
1011
+ */
1012
+ export var MATERIALIZED_DINEIN_ORIGIN_ENUM;
1013
+ (function (MATERIALIZED_DINEIN_ORIGIN_ENUM) {
1014
+ /** `POS_DINE-IN` — a terminal the guest ordered at. */
1015
+ MATERIALIZED_DINEIN_ORIGIN_ENUM["POS_DIRECT"] = "POS_DIRECT";
1016
+ /** `APP_DINE-IN` / `WEB_DINE-IN` WITH a staff or order-taker — a staff tablet. */
1017
+ MATERIALIZED_DINEIN_ORIGIN_ENUM["STAFF_TABLET"] = "STAFF_TABLET";
1018
+ /** `APP_DINE-IN` / `WEB_DINE-IN`, no staff, but a consumer phone — QR self-order. */
1019
+ MATERIALIZED_DINEIN_ORIGIN_ENUM["QR_SELF_ORDER"] = "QR_SELF_ORDER";
1020
+ /** Anything else. Never invented into one of the three real origins. */
1021
+ MATERIALIZED_DINEIN_ORIGIN_ENUM["UNKNOWN_ORIGIN"] = "UNKNOWN_ORIGIN";
1022
+ })(MATERIALIZED_DINEIN_ORIGIN_ENUM || (MATERIALIZED_DINEIN_ORIGIN_ENUM = {}));
1023
+ export const ALL_MATERIALIZED_DINEIN_ORIGINS = Object.values(MATERIALIZED_DINEIN_ORIGIN_ENUM);
1024
+ /** The role a counted check plays in a split bill. The parent never appears as a row. */
1025
+ export var MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM;
1026
+ (function (MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM) {
1027
+ MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM["NONE"] = "NONE";
1028
+ MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM["CHILD"] = "CHILD";
1029
+ })(MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM || (MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM = {}));
1030
+ export const ALL_MATERIALIZED_DINEIN_SPLIT_ROLES = Object.values(MATERIALIZED_DINEIN_SPLIT_ROLE_ENUM);
1031
+ /** Payment classification used by `card_amount` / `cash_amount` / `other_amount`. */
1032
+ export var MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM;
1033
+ (function (MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM) {
1034
+ MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM["CASH"] = "CASH";
1035
+ MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM["CARD"] = "CARD";
1036
+ MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM["OTHER"] = "OTHER";
1037
+ })(MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM || (MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM = {}));
1038
+ export const ALL_MATERIALIZED_DINEIN_PAYMENT_CLASSES = Object.values(MATERIALIZED_DINEIN_PAYMENT_CLASS_ENUM);
1039
+ /**
1040
+ * Per-collection BSON budgets (bytes). MongoDB's hard limit is 16 MiB per
1041
+ * document; 15 MiB is the owner-approved practical ceiling for the dinein
1042
+ * report and each entry page (same as Delivery/Dialer). A writer that exceeds
1043
+ * its budget fails at COMPILE/PLAN time with the collection + day + scope in the
1044
+ * message — never midway through the close transaction with a server-side
1045
+ * "object too large" error.
1046
+ */
1047
+ export const MATERIALIZED_DINEIN_REPORT_MAX_BSON_BYTES = 15 * 1024 * 1024;
1048
+ export const MATERIALIZED_DINEIN_ENTRY_MAX_BSON_BYTES = 15 * 1024 * 1024;
1049
+ /**
1050
+ * SOURCE-collection indexes the Dinein writer needs, DECLARED ONLY.
1051
+ *
1052
+ * The services run with `autoIndex: false`; nothing here is applied at runtime.
1053
+ * `dinein_tables_fingerprints` is queried by the day's order ids (session join)
1054
+ * and by `createdAt` (the table-close event scan); `reservations` is queried by
1055
+ * the tenant-local `reservation_time` day. Creating these indexes is an OWNER
1056
+ * deploy step (see the operations index plan).
1057
+ */
1058
+ export const MATERIALIZED_DINEIN_FINGERPRINTS_ORDER_INDEX_OPTIONS = [
1059
+ { key: { tenant_id: 1, order_id: 1 }, name: 'tenant_id__order_id' },
1060
+ ];
1061
+ export const MATERIALIZED_DINEIN_FINGERPRINTS_CREATED_AT_INDEX_OPTIONS = [
1062
+ { key: { tenant_id: 1, createdAt: -1 }, name: 'tenant_id__createdAt' },
1063
+ ];
1064
+ export const MATERIALIZED_DINEIN_RESERVATIONS_TIME_INDEX_OPTIONS = [
1065
+ { key: { tenant_id: 1, reservation_time: 1 }, name: 'tenant_id__reservation_time' },
1066
+ ];
1067
+ /* ======================================================================== */
1068
+ /* Day readiness (six production writers) */
1069
+ /* ======================================================================== */
1070
+ /**
1071
+ * COMMITTED-READINESS ledger for the SIX reports written by END_TENANT_DAY and
1072
+ * the range sync: Overview, Discounts, Prep Time, Delivery, Dialer and Dinein.
907
1073
  *
908
1074
  * One row per (tenant_id, localDate, report_key, schema_version). The row is
909
1075
  * written in the SAME transaction/session as the report documents, so it can
@@ -938,4 +1104,88 @@ export const ALL_MATERIALIZED_REPORT_READINESS_STATUSES = Object.values(MATERIAL
938
1104
  * The ONLY reports that own a readiness row. Adding another report here means
939
1105
  * giving it a writer that participates in the same day transaction.
940
1106
  */
941
- export const MATERIALIZED_READINESS_REPORT_KEYS = ['OVERVIEW', 'DISCOUNTS', 'PREP_TIME', 'DELIVERY', 'DIALER'];
1107
+ export const MATERIALIZED_READINESS_REPORT_KEYS = [
1108
+ 'OVERVIEW',
1109
+ 'DISCOUNTS',
1110
+ 'PREP_TIME',
1111
+ 'DELIVERY',
1112
+ 'DIALER',
1113
+ 'DINEIN',
1114
+ ];
1115
+ /* ======================================================================== */
1116
+ /* Report run ledger (ONE row per report execution) */
1117
+ /* ======================================================================== */
1118
+ /**
1119
+ * DURABLE OPERATIONAL LEDGER of one report's execution, SEPARATE from
1120
+ * readiness.
1121
+ *
1122
+ * Readiness answers "may a historical read treat this tenant-day-report as
1123
+ * final?" (only COMMITTED / NEEDS_RECONCILIATION ever appear there).
1124
+ * This ledger answers "what happened to the execution?" and is the ONLY place
1125
+ * a failed attempt is recorded (PENDING / RUNNING / RETRYING / COMMITTED /
1126
+ * FAILED), so a FAILED report never - and can never - look materialized.
1127
+ *
1128
+ * One row per `(tenant_id, localDate, report_key, schema_version)`. The row is
1129
+ * operational state: it is written OUTSIDE the report transaction (a rollback
1130
+ * must not erase the fact that the attempt happened). Readiness is written
1131
+ * INSIDE the report transaction. The two therefore have different lifecycles
1132
+ * and are deliberately different collections.
1133
+ *
1134
+ * Phase 1 replaces the one all-report END_TENANT_DAY transaction with one
1135
+ * transaction per report: each report commits (or fails) on its own, and this
1136
+ * ledger is the operator-visible record of that per-report outcome.
1137
+ */
1138
+ export const MATERIALIZED_TENANT_REPORT_RUNS_COLLECTION_NAME = 'materialized_tenant_report_runs';
1139
+ /** Version of the report-run row shape. Pinned to 1 with the other collections. */
1140
+ export const MATERIALIZED_TENANT_REPORT_RUNS_SCHEMA_VERSION = 1;
1141
+ /** The execution state of one tenant-day-report run. */
1142
+ export var MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM;
1143
+ (function (MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM) {
1144
+ /** The row exists but no attempt has started yet. */
1145
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["PENDING"] = "PENDING";
1146
+ /** An attempt is executing (its own transaction is open or about to open). */
1147
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["RUNNING"] = "RUNNING";
1148
+ /** A transient failure happened; another attempt is starting. */
1149
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["RETRYING"] = "RETRYING";
1150
+ /** The report transaction committed: documents + readiness are durable. */
1151
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["COMMITTED"] = "COMMITTED";
1152
+ /** Every allowed attempt was exhausted; readiness was NOT written. */
1153
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM["FAILED"] = "FAILED";
1154
+ })(MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM || (MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM = {}));
1155
+ export const ALL_MATERIALIZED_TENANT_REPORT_RUN_STATUSES = Object.values(MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM);
1156
+ /** States in which an execution currently owns the report (retry is refused). */
1157
+ export const MATERIALIZED_TENANT_REPORT_RUN_IN_FLIGHT_STATUSES = [
1158
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.PENDING,
1159
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.RUNNING,
1160
+ MATERIALIZED_TENANT_REPORT_RUN_STATUS_ENUM.RETRYING,
1161
+ ];
1162
+ /**
1163
+ * Bounded attempt budget of ONE report execution (transient errors only).
1164
+ * A deterministic code/compile error is NEVER retried inside the job.
1165
+ */
1166
+ export const MATERIALIZED_TENANT_REPORT_RUN_MAX_ATTEMPTS = 2;
1167
+ /** Bounded size of the stored `last_error` (single-line, PII-redacted). */
1168
+ export const MATERIALIZED_TENANT_REPORT_RUN_ERROR_MAX_LENGTH = 500;
1169
+ /**
1170
+ * Stale window of a report-run row (RUNNING / RETRYING).
1171
+ *
1172
+ * A run that has not reached a terminal state within this window MAY have been
1173
+ * interrupted (process crash). Recovery NEVER trusts the age alone: it also
1174
+ * requires the tenant's active-job heartbeat to be stale, so a live long-running
1175
+ * report is never taken over. The value mirrors the active-job lease window
1176
+ * (30 minutes) so both fences agree.
1177
+ */
1178
+ export const MATERIALIZED_TENANT_REPORT_RUN_STALE_MS = 30 * 60 * 1000;
1179
+ /**
1180
+ * Durable `last_error` of a run recovered after an interruption with NO
1181
+ * readiness row (the report transaction provably did not commit).
1182
+ */
1183
+ export const MATERIALIZED_REPORT_RUN_INTERRUPTED_ERROR = 'INTERRUPTED_RUN';
1184
+ /**
1185
+ * Durable `last_error` of a run whose transaction COMMIT outcome is UNKNOWN.
1186
+ *
1187
+ * Such a run is deliberately left NON-terminal (`RUNNING`): the transaction may
1188
+ * have committed. Stale-run recovery settles it from ownership-checked
1189
+ * readiness (`readiness.run_id === run.run_id`), never by guessing here.
1190
+ */
1191
+ export const MATERIALIZED_REPORT_RUN_COMMIT_OUTCOME_UNKNOWN_ERROR = 'COMMIT_OUTCOME_UNKNOWN';
@@ -88,3 +88,18 @@ export var TENANT_ACTIVE_JOBS_ENUM;
88
88
  TENANT_ACTIVE_JOBS_ENUM["Z_REPORT"] = "Z_REPORT";
89
89
  })(TENANT_ACTIVE_JOBS_ENUM || (TENANT_ACTIVE_JOBS_ENUM = {}));
90
90
  export const ALL_TENANT_ACTIVE_JOBS_NAMES = Object.values(TENANT_ACTIVE_JOBS_ENUM);
91
+ /**
92
+ * Terminal outcome of ONE close/retry run that owned the tenant's CALENDAR job.
93
+ *
94
+ * `PARTIAL` is the per-report model's outcome: at least one report FAILED while
95
+ * others committed. It is NEVER a readiness status - readiness keeps only
96
+ * COMMITTED / NEEDS_RECONCILIATION; the failed report lives in the operational
97
+ * run ledger (`materialized_tenant_report_runs`).
98
+ */
99
+ export var TENANT_DAY_JOB_OUTCOME_ENUM;
100
+ (function (TENANT_DAY_JOB_OUTCOME_ENUM) {
101
+ TENANT_DAY_JOB_OUTCOME_ENUM["COMPLETED"] = "COMPLETED";
102
+ TENANT_DAY_JOB_OUTCOME_ENUM["PARTIAL"] = "PARTIAL";
103
+ TENANT_DAY_JOB_OUTCOME_ENUM["FAILED"] = "FAILED";
104
+ })(TENANT_DAY_JOB_OUTCOME_ENUM || (TENANT_DAY_JOB_OUTCOME_ENUM = {}));
105
+ export const ALL_TENANT_DAY_JOB_OUTCOMES = Object.values(TENANT_DAY_JOB_OUTCOME_ENUM);
@@ -77,4 +77,16 @@ export const WORKER_ENDPOINTS = {
77
77
  // ========================>> Shift / Business Day / Cash Drawer (compile) <<======================= //
78
78
  END_INSTORE_SHIFT: '/end-instore-shift',
79
79
  END_TENANT_DAY: '/end-tenant-day',
80
+ /**
81
+ * INTERNAL, report-scoped retry of ONE failed END_TENANT_DAY report.
82
+ * Operations-service is the only caller (POST /materialization/reports/retry).
83
+ * Never a whole-day retry.
84
+ */
85
+ RETRY_MATERIALIZED_REPORT: '/internal/materialization/reports/retry',
86
+ /**
87
+ * INTERNAL, worker-owned recovery of INTERRUPTED report runs (RUNNING /
88
+ * RETRYING). Called before the retry API rejects a RUNNING report and before
89
+ * listing runs for the admin page. Never fabricates readiness.
90
+ */
91
+ RECONCILE_MATERIALIZED_REPORT_RUNS: '/internal/materialization/reports/reconcile',
80
92
  };
@@ -1,6 +1,7 @@
1
1
  export * from './key-helpers';
2
2
  export * from './materialized-credit-bills-helpers';
3
3
  export * from './materialized-day-readiness';
4
+ export * from './materialized-report-runs';
4
5
  export * from './materialized-index-bootstrap';
5
6
  export * from './materialized-integer-contract';
6
7
  export * from './materialized-discount-accumulator-helpers';
@@ -31,6 +32,12 @@ export * from './materialized-dialer-compile-helpers';
31
32
  export * from './materialized-dialer-entry-pages';
32
33
  export * from './materialized-dialer-key-helpers';
33
34
  export * from './materialized-dialer-masking';
35
+ export * from './materialized-dinein-accumulator-helpers';
36
+ export * from './materialized-dinein-classification-helpers';
37
+ export * from './materialized-dinein-close-day-helpers';
38
+ export * from './materialized-dinein-compile-helpers';
39
+ export * from './materialized-dinein-entry-pages';
40
+ export * from './materialized-dinein-key-helpers';
34
41
  export * from './materialized-day-input-signature';
35
42
  export * from './materialized-cash-classification-helpers';
36
43
  export * from './materialized-cash-close-day-helpers';
@@ -58,6 +65,7 @@ export * from './tenant-discount-source-formatter';
58
65
  export * from './tenant-cash-in-out-formatter';
59
66
  export * from './tenant-delivery-formatter';
60
67
  export * from './tenant-dialer-formatter';
68
+ export * from './tenant-dinein-formatter';
61
69
  export * from './tenant-prep-time-formatter';
62
70
  export * from './tenant-sales-overview-formatter';
63
71
  export * from './tenant-sales-overview-helpers';
@@ -1,6 +1,6 @@
1
1
  import { MATERIALIZED_READINESS_REPORT_KEYS, MATERIALIZED_REPORT_READINESS_STATUS_ENUM, MATERIALIZED_TENANT_DAY_READINESS_SCHEMA_VERSION, } from '../../constants/MATERIALIZED_REPORTS';
2
2
  const uniqueSorted = (values) => [...new Set(values)].sort();
3
- /** Whether `report` is one of the FIVE reports that own readiness rows. */
3
+ /** Whether `report` is one of the SIX reports that own readiness rows. */
4
4
  export function isMaterializedReadinessReportKey(report) {
5
5
  return MATERIALIZED_READINESS_REPORT_KEYS.includes(report);
6
6
  }
@@ -80,7 +80,7 @@ export function buildMaterializedDayReadinessDocument(input) {
80
80
  if (!isMaterializedReadinessReportKey(String(input.reportKey))) {
81
81
  throw new Error('buildMaterializedDayReadinessDocument: report ' +
82
82
  String(input.reportKey) +
83
- ' is outside the five report readiness contract');
83
+ ' is outside the six report readiness contract');
84
84
  }
85
85
  return {
86
86
  tenant_id: String(input.tenantId),