@306technologies/medusa-analytics-studio 0.0.0-stage → 0.1.1

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 (231) hide show
  1. package/.medusa/server/src/admin/index.css +95 -0
  2. package/.medusa/server/src/admin/index.js +7035 -0
  3. package/.medusa/server/src/admin/index.mjs +7012 -0
  4. package/.medusa/server/src/api/admin/analytics/dashboard/route.d.ts +5 -0
  5. package/.medusa/server/src/api/admin/analytics/dashboard/route.js +25 -0
  6. package/.medusa/server/src/api/admin/analytics/live/route.d.ts +3 -0
  7. package/.medusa/server/src/api/admin/analytics/live/route.js +27 -0
  8. package/.medusa/server/src/api/admin/analytics/query/route.d.ts +4 -0
  9. package/.medusa/server/src/api/admin/analytics/query/route.js +38 -0
  10. package/.medusa/server/src/api/admin/analytics/reports/[id]/route.d.ts +3 -0
  11. package/.medusa/server/src/api/admin/analytics/reports/[id]/route.js +12 -0
  12. package/.medusa/server/src/api/admin/analytics/reports/route.d.ts +4 -0
  13. package/.medusa/server/src/api/admin/analytics/reports/route.js +13 -0
  14. package/.medusa/server/src/api/admin/analytics/sql/route.d.ts +4 -0
  15. package/.medusa/server/src/api/admin/analytics/sql/route.js +27 -0
  16. package/.medusa/server/src/api/admin/analytics/sql/status/route.d.ts +3 -0
  17. package/.medusa/server/src/api/admin/analytics/sql/status/route.js +24 -0
  18. package/.medusa/server/src/api/admin/analytics/sql/views/route.d.ts +3 -0
  19. package/.medusa/server/src/api/admin/analytics/sql/views/route.js +10 -0
  20. package/.medusa/server/src/api/admin/analytics/workspace/route.d.ts +3 -0
  21. package/.medusa/server/src/api/admin/analytics/workspace/route.js +26 -0
  22. package/.medusa/server/src/api/middlewares.d.ts +2 -0
  23. package/.medusa/server/src/api/middlewares.js +29 -0
  24. package/.medusa/server/src/api/projections/analytics-dashboard.d.ts +3 -0
  25. package/.medusa/server/src/api/projections/analytics-dashboard.js +33 -0
  26. package/.medusa/server/src/api/projections/analytics-report.d.ts +6 -0
  27. package/.medusa/server/src/api/projections/analytics-report.js +38 -0
  28. package/.medusa/server/src/jobs/sales-facts-backfill.d.ts +18 -0
  29. package/.medusa/server/src/jobs/sales-facts-backfill.js +60 -0
  30. package/.medusa/server/src/jobs/sales-facts-drain.d.ts +19 -0
  31. package/.medusa/server/src/jobs/sales-facts-drain.js +72 -0
  32. package/.medusa/server/src/jobs/sales-facts-fx-rates.d.ts +6 -0
  33. package/.medusa/server/src/jobs/sales-facts-fx-rates.js +28 -0
  34. package/.medusa/server/src/jobs/sales-facts-reconcile.d.ts +14 -0
  35. package/.medusa/server/src/jobs/sales-facts-reconcile.js +62 -0
  36. package/.medusa/server/src/migration-scripts/analytics-core-indexes.d.ts +4 -0
  37. package/.medusa/server/src/migration-scripts/analytics-core-indexes.js +16 -0
  38. package/.medusa/server/src/modules/analytics-reader/engine/live.d.ts +51 -0
  39. package/.medusa/server/src/modules/analytics-reader/engine/live.js +140 -0
  40. package/.medusa/server/src/modules/analytics-reader/engine/metrics.d.ts +96 -0
  41. package/.medusa/server/src/modules/analytics-reader/engine/metrics.js +93 -0
  42. package/.medusa/server/src/modules/analytics-reader/engine/plan.d.ts +40 -0
  43. package/.medusa/server/src/modules/analytics-reader/engine/plan.js +372 -0
  44. package/.medusa/server/src/modules/analytics-reader/engine/report.d.ts +20 -0
  45. package/.medusa/server/src/modules/analytics-reader/engine/report.js +35 -0
  46. package/.medusa/server/src/modules/analytics-reader/engine/run-report.d.ts +18 -0
  47. package/.medusa/server/src/modules/analytics-reader/engine/run-report.js +325 -0
  48. package/.medusa/server/src/modules/analytics-reader/engine/sql-runner.d.ts +8 -0
  49. package/.medusa/server/src/modules/analytics-reader/engine/sql-runner.js +3 -0
  50. package/.medusa/server/src/modules/analytics-reader/index.d.ts +6 -0
  51. package/.medusa/server/src/modules/analytics-reader/index.js +13 -0
  52. package/.medusa/server/src/modules/analytics-reader/options.d.ts +15 -0
  53. package/.medusa/server/src/modules/analytics-reader/options.js +45 -0
  54. package/.medusa/server/src/modules/analytics-reader/read-only.d.ts +4 -0
  55. package/.medusa/server/src/modules/analytics-reader/read-only.js +42 -0
  56. package/.medusa/server/src/modules/analytics-reader/service.d.ts +29 -0
  57. package/.medusa/server/src/modules/analytics-reader/service.js +146 -0
  58. package/.medusa/server/src/modules/analytics-sql/index.d.ts +6 -0
  59. package/.medusa/server/src/modules/analytics-sql/index.js +13 -0
  60. package/.medusa/server/src/modules/analytics-sql/list-views.d.ts +3 -0
  61. package/.medusa/server/src/modules/analytics-sql/list-views.js +42 -0
  62. package/.medusa/server/src/modules/analytics-sql/reporting-role.d.ts +19 -0
  63. package/.medusa/server/src/modules/analytics-sql/reporting-role.js +89 -0
  64. package/.medusa/server/src/modules/analytics-sql/run-query.d.ts +16 -0
  65. package/.medusa/server/src/modules/analytics-sql/run-query.js +187 -0
  66. package/.medusa/server/src/modules/analytics-sql/service.d.ts +55 -0
  67. package/.medusa/server/src/modules/analytics-sql/service.js +391 -0
  68. package/.medusa/server/src/modules/analytics-workspace/index.d.ts +35 -0
  69. package/.medusa/server/src/modules/analytics-workspace/index.js +14 -0
  70. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261121223519.d.ts +5 -0
  71. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261121223519.js +21 -0
  72. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261122075443.d.ts +5 -0
  73. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261122075443.js +14 -0
  74. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261122075500.d.ts +5 -0
  75. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261122075500.js +38 -0
  76. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261122090000.d.ts +5 -0
  77. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261122090000.js +30 -0
  78. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261123210500.d.ts +5 -0
  79. package/.medusa/server/src/modules/analytics-workspace/migrations/Migration20261123210500.js +38 -0
  80. package/.medusa/server/src/modules/analytics-workspace/models/analytics-dashboard.d.ts +6 -0
  81. package/.medusa/server/src/modules/analytics-workspace/models/analytics-dashboard.js +19 -0
  82. package/.medusa/server/src/modules/analytics-workspace/models/analytics-report.d.ts +11 -0
  83. package/.medusa/server/src/modules/analytics-workspace/models/analytics-report.js +15 -0
  84. package/.medusa/server/src/modules/analytics-workspace/service.d.ts +35 -0
  85. package/.medusa/server/src/modules/analytics-workspace/service.js +39 -0
  86. package/.medusa/server/src/modules/sales-facts/fact-set.d.ts +16 -0
  87. package/.medusa/server/src/modules/sales-facts/fact-set.js +168 -0
  88. package/.medusa/server/src/modules/sales-facts/fx/frankfurter.d.ts +14 -0
  89. package/.medusa/server/src/modules/sales-facts/fx/frankfurter.js +161 -0
  90. package/.medusa/server/src/modules/sales-facts/fx/provider.d.ts +22 -0
  91. package/.medusa/server/src/modules/sales-facts/fx/provider.js +13 -0
  92. package/.medusa/server/src/modules/sales-facts/fx/rates.d.ts +25 -0
  93. package/.medusa/server/src/modules/sales-facts/fx/rates.js +73 -0
  94. package/.medusa/server/src/modules/sales-facts/index.d.ts +49 -0
  95. package/.medusa/server/src/modules/sales-facts/index.js +13 -0
  96. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122010914.d.ts +5 -0
  97. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122010914.js +15 -0
  98. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122011500.d.ts +5 -0
  99. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122011500.js +91 -0
  100. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122012257.d.ts +5 -0
  101. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122012257.js +28 -0
  102. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122013323.d.ts +5 -0
  103. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122013323.js +14 -0
  104. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122080000.d.ts +5 -0
  105. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261122080000.js +49 -0
  106. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123090000.d.ts +5 -0
  107. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123090000.js +38 -0
  108. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123100000.d.ts +5 -0
  109. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123100000.js +20 -0
  110. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123110000.d.ts +6 -0
  111. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123110000.js +28 -0
  112. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123120000.d.ts +5 -0
  113. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123120000.js +27 -0
  114. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123184118.d.ts +5 -0
  115. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123184118.js +20 -0
  116. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123200000.d.ts +5 -0
  117. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123200000.js +71 -0
  118. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123210000.d.ts +5 -0
  119. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123210000.js +148 -0
  120. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123220000.d.ts +5 -0
  121. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261123220000.js +37 -0
  122. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261124090000.d.ts +5 -0
  123. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261124090000.js +21 -0
  124. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261125090000.d.ts +5 -0
  125. package/.medusa/server/src/modules/sales-facts/migrations/Migration20261125090000.js +22 -0
  126. package/.medusa/server/src/modules/sales-facts/models/analytics-fact-state.d.ts +13 -0
  127. package/.medusa/server/src/modules/sales-facts/models/analytics-fact-state.js +17 -0
  128. package/.medusa/server/src/modules/sales-facts/models/analytics-line-fact.d.ts +16 -0
  129. package/.medusa/server/src/modules/sales-facts/models/analytics-line-fact.js +27 -0
  130. package/.medusa/server/src/modules/sales-facts/models/analytics-order-fact.d.ts +23 -0
  131. package/.medusa/server/src/modules/sales-facts/models/analytics-order-fact.js +36 -0
  132. package/.medusa/server/src/modules/sales-facts/order-totals.d.ts +13 -0
  133. package/.medusa/server/src/modules/sales-facts/order-totals.js +173 -0
  134. package/.medusa/server/src/modules/sales-facts/service.d.ts +140 -0
  135. package/.medusa/server/src/modules/sales-facts/service.js +1003 -0
  136. package/.medusa/server/src/schemas/analytics/index.d.ts +4 -0
  137. package/.medusa/server/src/schemas/analytics/index.js +21 -0
  138. package/.medusa/server/src/schemas/analytics/query-text.d.ts +39 -0
  139. package/.medusa/server/src/schemas/analytics/query-text.js +33 -0
  140. package/.medusa/server/src/schemas/analytics/run-report.schema.d.ts +5 -0
  141. package/.medusa/server/src/schemas/analytics/run-report.schema.js +9 -0
  142. package/.medusa/server/src/schemas/analytics/run-sql.schema.d.ts +6 -0
  143. package/.medusa/server/src/schemas/analytics/run-sql.schema.js +9 -0
  144. package/.medusa/server/src/schemas/analytics/save-dashboard.schema.d.ts +39 -0
  145. package/.medusa/server/src/schemas/analytics/save-dashboard.schema.js +26 -0
  146. package/.medusa/server/src/schemas/analytics/save-report.schema.d.ts +37 -0
  147. package/.medusa/server/src/schemas/analytics/save-report.schema.js +17 -0
  148. package/.medusa/server/src/scripts/setup-sql-role.d.ts +2 -0
  149. package/.medusa/server/src/scripts/setup-sql-role.js +39 -0
  150. package/.medusa/server/src/shared/analytics/assert-saved-query.d.ts +2 -0
  151. package/.medusa/server/src/shared/analytics/assert-saved-query.js +17 -0
  152. package/.medusa/server/src/shared/analytics/facts-format.d.ts +2 -0
  153. package/.medusa/server/src/shared/analytics/facts-format.js +8 -0
  154. package/.medusa/server/src/shared/analytics/facts-jobs.d.ts +2 -0
  155. package/.medusa/server/src/shared/analytics/facts-jobs.js +7 -0
  156. package/.medusa/server/src/shared/analytics/infrastructure.d.ts +2 -0
  157. package/.medusa/server/src/shared/analytics/infrastructure.js +40 -0
  158. package/.medusa/server/src/shared/analytics/lock-keys.d.ts +9 -0
  159. package/.medusa/server/src/shared/analytics/lock-keys.js +23 -0
  160. package/.medusa/server/src/shared/analytics/log.d.ts +11 -0
  161. package/.medusa/server/src/shared/analytics/log.js +33 -0
  162. package/.medusa/server/src/shared/analytics/query-language.d.ts +204 -0
  163. package/.medusa/server/src/shared/analytics/query-language.js +292 -0
  164. package/.medusa/server/src/shared/analytics/report-cache.d.ts +7 -0
  165. package/.medusa/server/src/shared/analytics/report-cache.js +60 -0
  166. package/.medusa/server/src/shared/analytics/report-context.d.ts +6 -0
  167. package/.medusa/server/src/shared/analytics/report-context.js +35 -0
  168. package/.medusa/server/src/shared/analytics/reporting-store.d.ts +6 -0
  169. package/.medusa/server/src/shared/analytics/reporting-store.js +8 -0
  170. package/.medusa/server/src/shared/analytics/reporting-view.d.ts +9 -0
  171. package/.medusa/server/src/shared/analytics/reporting-view.js +37 -0
  172. package/.medusa/server/src/shared/analytics/saved-report-limit.d.ts +1 -0
  173. package/.medusa/server/src/shared/analytics/saved-report-limit.js +5 -0
  174. package/.medusa/server/src/shared/analytics/timezone.d.ts +4 -0
  175. package/.medusa/server/src/shared/analytics/timezone.js +24 -0
  176. package/.medusa/server/src/shared/analytics/types.d.ts +170 -0
  177. package/.medusa/server/src/shared/analytics/types.js +25 -0
  178. package/.medusa/server/src/subscribers/sales-facts-order-changed.d.ts +8 -0
  179. package/.medusa/server/src/subscribers/sales-facts-order-changed.js +37 -0
  180. package/.medusa/server/src/subscribers/sales-facts-payment-refunded.d.ts +5 -0
  181. package/.medusa/server/src/subscribers/sales-facts-payment-refunded.js +34 -0
  182. package/.medusa/server/src/workflows/backfill-sales-facts/index.d.ts +4 -0
  183. package/.medusa/server/src/workflows/backfill-sales-facts/index.js +12 -0
  184. package/.medusa/server/src/workflows/backfill-sales-facts/steps/backfill-sales-facts-batch.d.ts +5 -0
  185. package/.medusa/server/src/workflows/backfill-sales-facts/steps/backfill-sales-facts-batch.js +43 -0
  186. package/.medusa/server/src/workflows/delete-analytics-report/index.d.ts +3 -0
  187. package/.medusa/server/src/workflows/delete-analytics-report/index.js +10 -0
  188. package/.medusa/server/src/workflows/delete-analytics-report/steps/delete-analytics-report.d.ts +5 -0
  189. package/.medusa/server/src/workflows/delete-analytics-report/steps/delete-analytics-report.js +25 -0
  190. package/.medusa/server/src/workflows/drain-sales-facts-queue/index.d.ts +4 -0
  191. package/.medusa/server/src/workflows/drain-sales-facts-queue/index.js +12 -0
  192. package/.medusa/server/src/workflows/drain-sales-facts-queue/steps/drain-sales-facts-queue.d.ts +5 -0
  193. package/.medusa/server/src/workflows/drain-sales-facts-queue/steps/drain-sales-facts-queue.js +28 -0
  194. package/.medusa/server/src/workflows/index.d.ts +9 -0
  195. package/.medusa/server/src/workflows/index.js +22 -0
  196. package/.medusa/server/src/workflows/queue-sales-facts-refresh/index.d.ts +4 -0
  197. package/.medusa/server/src/workflows/queue-sales-facts-refresh/index.js +10 -0
  198. package/.medusa/server/src/workflows/queue-sales-facts-refresh/steps/queue-sales-facts-refresh.d.ts +4 -0
  199. package/.medusa/server/src/workflows/queue-sales-facts-refresh/steps/queue-sales-facts-refresh.js +13 -0
  200. package/.medusa/server/src/workflows/refresh-sales-facts/index.d.ts +4 -0
  201. package/.medusa/server/src/workflows/refresh-sales-facts/index.js +15 -0
  202. package/.medusa/server/src/workflows/refresh-sales-facts/steps/refresh-sales-facts.d.ts +5 -0
  203. package/.medusa/server/src/workflows/refresh-sales-facts/steps/refresh-sales-facts.js +24 -0
  204. package/.medusa/server/src/workflows/reset-analytics-dashboard/index.d.ts +3 -0
  205. package/.medusa/server/src/workflows/reset-analytics-dashboard/index.js +10 -0
  206. package/.medusa/server/src/workflows/reset-analytics-dashboard/steps/reset-analytics-dashboard.d.ts +4 -0
  207. package/.medusa/server/src/workflows/reset-analytics-dashboard/steps/reset-analytics-dashboard.js +29 -0
  208. package/.medusa/server/src/workflows/save-analytics-dashboard/index.d.ts +10 -0
  209. package/.medusa/server/src/workflows/save-analytics-dashboard/index.js +10 -0
  210. package/.medusa/server/src/workflows/save-analytics-dashboard/steps/save-analytics-dashboard.d.ts +13 -0
  211. package/.medusa/server/src/workflows/save-analytics-dashboard/steps/save-analytics-dashboard.js +48 -0
  212. package/.medusa/server/src/workflows/save-analytics-report/index.d.ts +15 -0
  213. package/.medusa/server/src/workflows/save-analytics-report/index.js +10 -0
  214. package/.medusa/server/src/workflows/save-analytics-report/steps/save-analytics-report.d.ts +24 -0
  215. package/.medusa/server/src/workflows/save-analytics-report/steps/save-analytics-report.js +67 -0
  216. package/.medusa/server/src/workflows/shared-steps/resolve-reporting-timezone.d.ts +1 -0
  217. package/.medusa/server/src/workflows/shared-steps/resolve-reporting-timezone.js +18 -0
  218. package/.medusa/server/src/workflows/sync-fx-rates/index.d.ts +7 -0
  219. package/.medusa/server/src/workflows/sync-fx-rates/index.js +23 -0
  220. package/.medusa/server/src/workflows/sync-fx-rates/steps/fetch-fx-rates.d.ts +15 -0
  221. package/.medusa/server/src/workflows/sync-fx-rates/steps/fetch-fx-rates.js +95 -0
  222. package/.medusa/server/src/workflows/sync-fx-rates/steps/list-fx-quotes.d.ts +1 -0
  223. package/.medusa/server/src/workflows/sync-fx-rates/steps/list-fx-quotes.js +10 -0
  224. package/.medusa/server/src/workflows/sync-fx-rates/steps/resolve-store-currency.d.ts +1 -0
  225. package/.medusa/server/src/workflows/sync-fx-rates/steps/resolve-store-currency.js +22 -0
  226. package/.medusa/server/src/workflows/sync-fx-rates/steps/save-fx-rates.d.ts +5 -0
  227. package/.medusa/server/src/workflows/sync-fx-rates/steps/save-fx-rates.js +16 -0
  228. package/LICENSE +21 -0
  229. package/README.md +324 -2
  230. package/package.json +106 -4
  231. package/sql/create-indexes-concurrently.sql +37 -0
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.planRates = exports.lastFixedDay = exports.daysBetween = exports.addDays = exports.PROVISIONAL_DAYS = exports.MAX_DAILY_MOVE = void 0;
4
+ exports.MAX_DAILY_MOVE = 0.2;
5
+ exports.PROVISIONAL_DAYS = 2;
6
+ const OPENING_RATES = 5;
7
+ const addDays = (day, days) => {
8
+ const date = new Date(`${day}T00:00:00Z`);
9
+ date.setUTCDate(date.getUTCDate() + days);
10
+ return date.toISOString().slice(0, 10);
11
+ };
12
+ exports.addDays = addDays;
13
+ const daysBetween = (from, to) => {
14
+ const days = [];
15
+ for (let day = from; day <= to; day = (0, exports.addDays)(day, 1)) {
16
+ days.push(day);
17
+ }
18
+ return days;
19
+ };
20
+ exports.daysBetween = daysBetween;
21
+ const lastFixedDay = (today) => (0, exports.addDays)(today, -exports.PROVISIONAL_DAYS);
22
+ exports.lastFixedDay = lastFixedDay;
23
+ /** A move past MAX_DAILY_MOVE is kept only if the next rate agrees, refused if it doesn't, and left provisional while there is none. */
24
+ const planRates = (rates, from, to, today, previous) => {
25
+ const published = [...rates].sort((a, b) => (a.day < b.day ? -1 : 1));
26
+ const byDay = new Map(published.map((rate) => [rate.day, rate.rate]));
27
+ const opening = published
28
+ .filter((rate) => rate.day >= from && rate.day <= to)
29
+ .slice(0, OPENING_RATES)
30
+ .map((rate) => Number(rate.rate))
31
+ .sort((a, b) => a - b);
32
+ const median = opening.length ? opening[Math.floor(opening.length / 2)] : null;
33
+ const moved = (rate, against) => Math.abs(rate / against - 1) > exports.MAX_DAILY_MOVE;
34
+ const fixedUntil = (0, exports.lastFixedDay)(today);
35
+ const rows = [];
36
+ const rejected = [];
37
+ let last = previous;
38
+ let open = false;
39
+ for (const day of (0, exports.daysBetween)(from, to)) {
40
+ const fresh = byDay.get(day);
41
+ if (fresh !== undefined && Number(fresh) > 0) {
42
+ const against = last ? Number(last.rate) : median;
43
+ if (against === null || !moved(Number(fresh), against)) {
44
+ last = { rate: fresh, rate_day: day };
45
+ }
46
+ else {
47
+ const next = published.find((rate) => rate.day > day);
48
+ if (next && !moved(Number(next.rate), Number(fresh))) {
49
+ last = { rate: fresh, rate_day: day };
50
+ }
51
+ else {
52
+ rejected.push({
53
+ day,
54
+ rate: fresh,
55
+ previous: last?.rate ?? String(against),
56
+ });
57
+ open = open || next === undefined;
58
+ }
59
+ }
60
+ }
61
+ if (last) {
62
+ rows.push({
63
+ day,
64
+ rate: last.rate,
65
+ rate_day: last.rate_day,
66
+ fixed: day <= fixedUntil && !open,
67
+ });
68
+ }
69
+ }
70
+ return { rows, rejected };
71
+ };
72
+ exports.planRates = planRates;
73
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmF0ZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9meC9yYXRlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFFYSxRQUFBLGNBQWMsR0FBRyxHQUFHLENBQUE7QUFFcEIsUUFBQSxnQkFBZ0IsR0FBRyxDQUFDLENBQUE7QUFFakMsTUFBTSxhQUFhLEdBQUcsQ0FBQyxDQUFBO0FBY2hCLE1BQU0sT0FBTyxHQUFHLENBQUMsR0FBVyxFQUFFLElBQVksRUFBVSxFQUFFO0lBQzNELE1BQU0sSUFBSSxHQUFHLElBQUksSUFBSSxDQUFDLEdBQUcsR0FBRyxZQUFZLENBQUMsQ0FBQTtJQUN6QyxJQUFJLENBQUMsVUFBVSxDQUFDLElBQUksQ0FBQyxVQUFVLEVBQUUsR0FBRyxJQUFJLENBQUMsQ0FBQTtJQUN6QyxPQUFPLElBQUksQ0FBQyxXQUFXLEVBQUUsQ0FBQyxLQUFLLENBQUMsQ0FBQyxFQUFFLEVBQUUsQ0FBQyxDQUFBO0FBQ3hDLENBQUMsQ0FBQTtBQUpZLFFBQUEsT0FBTyxXQUluQjtBQUVNLE1BQU0sV0FBVyxHQUFHLENBQUMsSUFBWSxFQUFFLEVBQVUsRUFBWSxFQUFFO0lBQ2hFLE1BQU0sSUFBSSxHQUFhLEVBQUUsQ0FBQTtJQUN6QixLQUFLLElBQUksR0FBRyxHQUFHLElBQUksRUFBRSxHQUFHLElBQUksRUFBRSxFQUFFLEdBQUcsR0FBRyxJQUFBLGVBQU8sRUFBQyxHQUFHLEVBQUUsQ0FBQyxDQUFDLEVBQUUsQ0FBQztRQUN0RCxJQUFJLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFBO0lBQ2hCLENBQUM7SUFDRCxPQUFPLElBQUksQ0FBQTtBQUNiLENBQUMsQ0FBQTtBQU5ZLFFBQUEsV0FBVyxlQU12QjtBQUVNLE1BQU0sWUFBWSxHQUFHLENBQUMsS0FBYSxFQUFVLEVBQUUsQ0FDcEQsSUFBQSxlQUFPLEVBQUMsS0FBSyxFQUFFLENBQUMsd0JB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
@@ -0,0 +1,49 @@
1
+ import SalesFactsService from "./service";
2
+ export declare const SALES_FACTS_MODULE = "salesFacts";
3
+ declare const _default: import("@medusajs/types").ModuleExports<typeof SalesFactsService> & {
4
+ linkable: {
5
+ readonly analyticsFactState: {
6
+ id: {
7
+ serviceName: "salesFacts";
8
+ field: "analyticsFactState";
9
+ linkable: "analytics_fact_state_id";
10
+ primaryKey: "id";
11
+ };
12
+ toJSON: () => {
13
+ serviceName: "salesFacts";
14
+ field: "analyticsFactState";
15
+ linkable: "analytics_fact_state_id";
16
+ primaryKey: "id";
17
+ };
18
+ };
19
+ readonly analyticsOrderFact: {
20
+ id: {
21
+ serviceName: "salesFacts";
22
+ field: "analyticsOrderFact";
23
+ linkable: "analytics_order_fact_id";
24
+ primaryKey: "id";
25
+ };
26
+ toJSON: () => {
27
+ serviceName: "salesFacts";
28
+ field: "analyticsOrderFact";
29
+ linkable: "analytics_order_fact_id";
30
+ primaryKey: "id";
31
+ };
32
+ };
33
+ readonly analyticsLineFact: {
34
+ id: {
35
+ serviceName: "salesFacts";
36
+ field: "analyticsLineFact";
37
+ linkable: "analytics_line_fact_id";
38
+ primaryKey: "id";
39
+ };
40
+ toJSON: () => {
41
+ serviceName: "salesFacts";
42
+ field: "analyticsLineFact";
43
+ linkable: "analytics_line_fact_id";
44
+ primaryKey: "id";
45
+ };
46
+ };
47
+ };
48
+ };
49
+ export default _default;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SALES_FACTS_MODULE = void 0;
7
+ const utils_1 = require("@medusajs/framework/utils");
8
+ const service_1 = __importDefault(require("./service"));
9
+ exports.SALES_FACTS_MODULE = "salesFacts";
10
+ exports.default = (0, utils_1.Module)(exports.SALES_FACTS_MODULE, {
11
+ service: service_1.default,
12
+ });
13
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7QUFBQSxxREFBa0Q7QUFFbEQsd0RBQXlDO0FBRTVCLFFBQUEsa0JBQWtCLEdBQUcsWUFBWSxDQUFBO0FBRTlDLGtCQUFlLElBQUEsY0FBTSxFQUFDLDBCQUFrQixFQUFFO0lBQ3hDLE9BQU8sRUFBRSxpQkFBaUI7Q0FDM0IsQ0FBQyxDQUFBIn0=
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261122010914 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261122010914 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ class Migration20261122010914 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`create table if not exists "analytics_fact_state" ("id" text not null, "timezone" text not null, "data_version" integer not null default 0, "backfilled_at" timestamptz null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "analytics_fact_state_pkey" primary key ("id"));`);
8
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_analytics_fact_state_deleted_at" ON "analytics_fact_state" ("deleted_at") WHERE deleted_at IS NULL;`);
9
+ }
10
+ async down() {
11
+ this.addSql(`drop table if exists "analytics_fact_state" cascade;`);
12
+ }
13
+ }
14
+ exports.Migration20261122010914 = Migration20261122010914;
15
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjIwMTA5MTQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIyMDEwOTE0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFxRTtBQUVyRSxNQUFhLHVCQUF3QixTQUFRLHNCQUFTO0lBRTNDLEtBQUssQ0FBQyxFQUFFO1FBQ2YsSUFBSSxDQUFDLE1BQU0sQ0FBQyw0V0FBNFcsQ0FBQyxDQUFDO1FBQzFYLElBQUksQ0FBQyxNQUFNLENBQUMscUlBQXFJLENBQUMsQ0FBQztJQUNySixDQUFDO0lBRVEsS0FBSyxDQUFDLElBQUk7UUFDakIsSUFBSSxDQUFDLE1BQU0sQ0FBQyxzREFBc0QsQ0FBQyxDQUFDO0lBQ3RFLENBQUM7Q0FFRjtBQVhELDBEQVdDIn0=
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261122011500 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261122011500 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ /*
6
+ * The analytics rollup tables: fact rows summed per day or hour. Plain SQL
7
+ * rather than models, because a rollup row is identified by several columns
8
+ * together (currency, day, channel, ...), and a model would add an id,
9
+ * timestamps and soft-delete columns that a "delete the day, sum it again"
10
+ * table never uses. The fact tables they are built from are models (models/).
11
+ *
12
+ * Changing a rollup table means a new hand-written migration here, plus the
13
+ * matching SQL in service.ts (rollupSql). No model may use these table names:
14
+ * its generated "create table if not exists" would silently do nothing.
15
+ *
16
+ * local_day and local_hour are in the store's reporting timezone (see
17
+ * analytics_fact_state.timezone). Every table can be emptied and rebuilt from
18
+ * the fact tables, so nothing here is the source of truth.
19
+ */
20
+ class Migration20261122011500 extends migrations_1.Migration {
21
+ async up() {
22
+ // Per day, by the dimensions most reports split by.
23
+ this.addSql(`create table if not exists "analytics_sales_daily" (
24
+ "local_day" date not null,
25
+ "currency_code" text not null,
26
+ "sales_channel" text not null,
27
+ "country" text not null,
28
+ "customer_type" text not null,
29
+ "orders" integer not null,
30
+ "gross" numeric not null,
31
+ "discounts" numeric not null,
32
+ "refunded" numeric not null,
33
+ "shipping" numeric not null,
34
+ "tax" numeric not null,
35
+ "total" numeric not null,
36
+ "units" numeric not null,
37
+ "new_customers" integer not null,
38
+ constraint "analytics_sales_daily_pkey" primary key ("currency_code", "local_day", "sales_channel", "country", "customer_type")
39
+ );`);
40
+ this.addSql(`create index if not exists "IDX_analytics_sales_daily_local_day" on "analytics_sales_daily" ("local_day");`);
41
+ // Per hour, no other split: hour of day, today, yesterday.
42
+ this.addSql(`create table if not exists "analytics_sales_hourly" (
43
+ "local_day" date not null,
44
+ "local_hour" smallint not null,
45
+ "currency_code" text not null,
46
+ "orders" integer not null,
47
+ "gross" numeric not null,
48
+ "discounts" numeric not null,
49
+ "refunded" numeric not null,
50
+ "shipping" numeric not null,
51
+ "tax" numeric not null,
52
+ "total" numeric not null,
53
+ "units" numeric not null,
54
+ "new_customers" integer not null,
55
+ constraint "analytics_sales_hourly_pkey" primary key ("currency_code", "local_day", "local_hour")
56
+ );`);
57
+ this.addSql(`create index if not exists "IDX_analytics_sales_hourly_local_day" on "analytics_sales_hourly" ("local_day");`);
58
+ // Per day and product. "orders" counts orders containing the product.
59
+ this.addSql(`create table if not exists "analytics_product_daily" (
60
+ "local_day" date not null,
61
+ "currency_code" text not null,
62
+ "product_title" text not null,
63
+ "orders" integer not null,
64
+ "gross" numeric not null,
65
+ "units" numeric not null,
66
+ constraint "analytics_product_daily_pkey" primary key ("currency_code", "local_day", "product_title")
67
+ );`);
68
+ this.addSql(`create index if not exists "IDX_analytics_product_daily_local_day" on "analytics_product_daily" ("local_day");`);
69
+ // Per day and variant. Separate from products: an order with two variants
70
+ // of one product counts once per product, so the two can't share a table.
71
+ this.addSql(`create table if not exists "analytics_variant_daily" (
72
+ "local_day" date not null,
73
+ "currency_code" text not null,
74
+ "product_title" text not null,
75
+ "variant_title" text not null,
76
+ "orders" integer not null,
77
+ "gross" numeric not null,
78
+ "units" numeric not null,
79
+ constraint "analytics_variant_daily_pkey" primary key ("currency_code", "local_day", "product_title", "variant_title")
80
+ );`);
81
+ this.addSql(`create index if not exists "IDX_analytics_variant_daily_local_day" on "analytics_variant_daily" ("local_day");`);
82
+ }
83
+ async down() {
84
+ this.addSql(`drop table if exists "analytics_variant_daily";`);
85
+ this.addSql(`drop table if exists "analytics_product_daily";`);
86
+ this.addSql(`drop table if exists "analytics_sales_hourly";`);
87
+ this.addSql(`drop table if exists "analytics_sales_daily";`);
88
+ }
89
+ }
90
+ exports.Migration20261122011500 = Migration20261122011500;
91
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjIwMTE1MDAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIyMDExNTAwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFvRTtBQUVwRTs7Ozs7Ozs7Ozs7Ozs7R0FjRztBQUNILE1BQWEsdUJBQXdCLFNBQVEsc0JBQVM7SUFDM0MsS0FBSyxDQUFDLEVBQUU7UUFDZixvREFBb0Q7UUFDcEQsSUFBSSxDQUFDLE1BQU0sQ0FBQzs7Ozs7Ozs7Ozs7Ozs7OztPQWdCVCxDQUFDLENBQUE7UUFDSixJQUFJLENBQUMsTUFBTSxDQUNULDRHQUE0RyxDQUM3RyxDQUFBO1FBRUQsMkRBQTJEO1FBQzNELElBQUksQ0FBQyxNQUFNLENBQUM7Ozs7Ozs7Ozs7Ozs7O09BY1QsQ0FBQyxDQUFBO1FBQ0osSUFBSSxDQUFDLE1BQU0sQ0FDVCw4R0FBOEcsQ0FDL0csQ0FBQTtRQUVELHNFQUFzRTtRQUN0RSxJQUFJLENBQUMsTUFBTSxDQUFDOzs7Ozs7OztPQVFULENBQUMsQ0FBQTtRQUNKLElBQUksQ0FBQyxNQUFNLENBQ1QsZ0hBQWdILENBQ2pILENBQUE7UUFFRCwwRUFBMEU7UUFDMUUsMEVBQTBFO1FBQzFFLElBQUksQ0FBQyxNQUFNLENBQUM7Ozs7Ozs7OztPQVNULENBQUMsQ0FBQTtRQUNKLElBQUksQ0FBQyxNQUFNLENBQ1QsZ0hBQWdILENBQ2pILENBQUE7SUFDSCxDQUFDO0lBRVEsS0FBSyxDQUFDLElBQUk7UUFDakIsSUFBSSxDQUFDLE1BQU0sQ0FBQyxpREFBaUQsQ0FBQyxDQUFBO1FBQzlELElBQUksQ0FBQyxNQUFNLENBQUMsaURBQWlELENBQUMsQ0FBQTtRQUM5RCxJQUFJLENBQUMsTUFBTSxDQUFDLGdEQUFnRCxDQUFDLENBQUE7UUFDN0QsSUFBSSxDQUFDLE1BQU0sQ0FBQywrQ0FBK0MsQ0FBQyxDQUFBO0lBQzlELENBQUM7Q0FDRjtBQWpGRCwwREFpRkMifQ==
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261122012257 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261122012257 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ class Migration20261122012257 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`alter table if exists "analytics_order_fact" drop constraint if exists "analytics_order_fact_order_id_unique";`);
8
+ this.addSql(`alter table if exists "analytics_line_fact" drop constraint if exists "analytics_line_fact_order_id_item_id_unique";`);
9
+ this.addSql(`create table if not exists "analytics_line_fact" ("id" text not null, "order_id" text not null, "item_id" text not null, "currency_code" text not null, "order_created_at" timestamptz not null, "local_day" text not null, "local_hour" integer not null, "product_id" text null, "variant_id" text null, "product_title" text null, "variant_title" text null, "quantity" integer not null, "gross" numeric not null, "raw_gross" jsonb not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "analytics_line_fact_pkey" primary key ("id"));`);
10
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_analytics_line_fact_deleted_at" ON "analytics_line_fact" ("deleted_at") WHERE deleted_at IS NULL;`);
11
+ this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_analytics_line_fact_order_id_item_id_unique" ON "analytics_line_fact" ("order_id", "item_id") WHERE deleted_at IS NULL;`);
12
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_analytics_line_fact_currency_code_order_created_at" ON "analytics_line_fact" ("currency_code", "order_created_at") WHERE deleted_at IS NULL;`);
13
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_analytics_line_fact_local_day" ON "analytics_line_fact" ("local_day") WHERE deleted_at IS NULL;`);
14
+ this.addSql(`create table if not exists "analytics_order_fact" ("id" text not null, "order_id" text not null, "order_version" integer not null, "currency_code" text not null, "order_created_at" timestamptz not null, "local_day" text not null, "local_hour" integer not null, "customer_id" text null, "sales_channel_id" text null, "sales_channel" text not null, "country" text not null, "city" text not null, "is_new" boolean not null, "gross" numeric not null, "discounts" numeric not null, "refunded" numeric not null, "shipping" numeric not null, "tax" numeric not null, "total" numeric not null, "units" integer not null, "raw_gross" jsonb not null, "raw_discounts" jsonb not null, "raw_refunded" jsonb not null, "raw_shipping" jsonb not null, "raw_tax" jsonb not null, "raw_total" jsonb not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "analytics_order_fact_pkey" primary key ("id"));`);
15
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_analytics_order_fact_deleted_at" ON "analytics_order_fact" ("deleted_at") WHERE deleted_at IS NULL;`);
16
+ this.addSql(`CREATE UNIQUE INDEX IF NOT EXISTS "IDX_analytics_order_fact_order_id_unique" ON "analytics_order_fact" ("order_id") WHERE deleted_at IS NULL;`);
17
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_analytics_order_fact_currency_code_order_created_at" ON "analytics_order_fact" ("currency_code", "order_created_at") WHERE deleted_at IS NULL;`);
18
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_analytics_order_fact_currency_code_local_day" ON "analytics_order_fact" ("currency_code", "local_day") WHERE deleted_at IS NULL;`);
19
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_analytics_order_fact_local_day" ON "analytics_order_fact" ("local_day") WHERE deleted_at IS NULL;`);
20
+ this.addSql(`CREATE INDEX IF NOT EXISTS "IDX_analytics_order_fact_customer_id_order_created_at" ON "analytics_order_fact" ("customer_id", "order_created_at") WHERE deleted_at IS NULL;`);
21
+ }
22
+ async down() {
23
+ this.addSql(`drop table if exists "analytics_line_fact" cascade;`);
24
+ this.addSql(`drop table if exists "analytics_order_fact" cascade;`);
25
+ }
26
+ }
27
+ exports.Migration20261122012257 = Migration20261122012257;
28
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjIwMTIyNTcuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIyMDEyMjU3LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFxRTtBQUVyRSxNQUFhLHVCQUF3QixTQUFRLHNCQUFTO0lBRTNDLEtBQUssQ0FBQyxFQUFFO1FBQ2YsSUFBSSxDQUFDLE1BQU0sQ0FBQyxnSEFBZ0gsQ0FBQyxDQUFDO1FBQzlILElBQUksQ0FBQyxNQUFNLENBQUMsc0hBQXNILENBQUMsQ0FBQztRQUNwSSxJQUFJLENBQUMsTUFBTSxDQUFDLGluQkFBaW5CLENBQUMsQ0FBQztRQUMvbkIsSUFBSSxDQUFDLE1BQU0sQ0FBQyxtSUFBbUksQ0FBQyxDQUFDO1FBQ2pKLElBQUksQ0FBQyxNQUFNLENBQUMsZ0tBQWdLLENBQUMsQ0FBQztRQUM5SyxJQUFJLENBQUMsTUFBTSxDQUFDLDhLQUE4SyxDQUFDLENBQUM7UUFDNUwsSUFBSSxDQUFDLE1BQU0sQ0FBQyxpSUFBaUksQ0FBQyxDQUFDO1FBRS9JLElBQUksQ0FBQyxNQUFNLENBQUMsaTlCQUFpOUIsQ0FBQyxDQUFDO1FBQy85QixJQUFJLENBQUMsTUFBTSxDQUFDLHFJQUFxSSxDQUFDLENBQUM7UUFDbkosSUFBSSxDQUFDLE1BQU0sQ0FBQywrSUFBK0ksQ0FBQyxDQUFDO1FBQzdKLElBQUksQ0FBQyxNQUFNLENBQUMsZ0xBQWdMLENBQUMsQ0FBQztRQUM5TCxJQUFJLENBQUMsTUFBTSxDQUFDLGtLQUFrSyxDQUFDLENBQUM7UUFDaEwsSUFBSSxDQUFDLE1BQU0sQ0FBQyxtSUFBbUksQ0FBQyxDQUFDO1FBQ2pKLElBQUksQ0FBQyxNQUFNLENBQUMsNEtBQTRLLENBQUMsQ0FBQztJQUM1TCxDQUFDO0lBRVEsS0FBSyxDQUFDLElBQUk7UUFDakIsSUFBSSxDQUFDLE1BQU0sQ0FBQyxxREFBcUQsQ0FBQyxDQUFDO1FBRW5FLElBQUksQ0FBQyxNQUFNLENBQUMsc0RBQXNELENBQUMsQ0FBQztJQUN0RSxDQUFDO0NBRUY7QUExQkQsMERBMEJDIn0=
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261122013323 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261122013323 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ class Migration20261122013323 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql(`alter table if exists "analytics_fact_state" add column if not exists "backfill_cursor_created_at" timestamptz null, add column if not exists "backfill_cursor_order_id" text null;`);
8
+ }
9
+ async down() {
10
+ this.addSql(`alter table if exists "analytics_fact_state" drop column if exists "backfill_cursor_created_at", drop column if exists "backfill_cursor_order_id";`);
11
+ }
12
+ }
13
+ exports.Migration20261122013323 = Migration20261122013323;
14
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjIwMTMzMjMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIyMDEzMzIzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFxRTtBQUVyRSxNQUFhLHVCQUF3QixTQUFRLHNCQUFTO0lBRTNDLEtBQUssQ0FBQyxFQUFFO1FBQ2YsSUFBSSxDQUFDLE1BQU0sQ0FBQyxxTEFBcUwsQ0FBQyxDQUFDO0lBQ3JNLENBQUM7SUFFUSxLQUFLLENBQUMsSUFBSTtRQUNqQixJQUFJLENBQUMsTUFBTSxDQUFDLG9KQUFvSixDQUFDLENBQUM7SUFDcEssQ0FBQztDQUVGO0FBVkQsMERBVUMifQ==
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261122080000 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261122080000 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ const reporting_view_1 = require("../../../shared/analytics/reporting-view");
6
+ /*
7
+ * Reporting view: sales per store day, currency, sales channel and country,
8
+ * for SQL mode. Totals only: no order, customer or city detail.
9
+ * Hand-written (db:generate never creates views). See "Reporting views" in
10
+ * docs/conventions/backend.md.
11
+ */
12
+ class Migration20261122080000 extends migrations_1.Migration {
13
+ async up() {
14
+ this.addSql((0, reporting_view_1.reportingView)({
15
+ name: "sales_daily",
16
+ comment: "Sales per store day, currency, sales channel and country",
17
+ sql: `
18
+ select local_day::date as day,
19
+ currency_code as currency,
20
+ sales_channel,
21
+ country,
22
+ count(*) as orders,
23
+ count(*) filter (where is_new) as new_customer_orders,
24
+ sum(units) as units,
25
+ sum(gross) as gross_sales,
26
+ sum(discounts) as discounts,
27
+ sum(refunded) as refunds,
28
+ sum(shipping) as shipping,
29
+ sum(tax) as tax,
30
+ sum(total) as total_sales
31
+ from analytics_order_fact
32
+ where deleted_at is null
33
+ group by 1, 2, 3, 4`,
34
+ columns: {
35
+ day: "Day in the store's timezone",
36
+ currency: "Currency code; amounts are in this currency, never mixed",
37
+ orders: "Orders placed (not drafts or canceled)",
38
+ new_customer_orders: "Orders from first-time customers",
39
+ gross_sales: "Before discounts, refunds, shipping and tax",
40
+ total_sales: "What the customer paid",
41
+ },
42
+ }));
43
+ }
44
+ async down() {
45
+ this.addSql((0, reporting_view_1.dropReportingView)("sales_daily"));
46
+ }
47
+ }
48
+ exports.Migration20261122080000 = Migration20261122080000;
49
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjIwODAwMDAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIyMDgwMDAwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFvRTtBQUVwRSw2RUFHaUQ7QUFFakQ7Ozs7O0dBS0c7QUFDSCxNQUFhLHVCQUF3QixTQUFRLHNCQUFTO0lBQzNDLEtBQUssQ0FBQyxFQUFFO1FBQ2YsSUFBSSxDQUFDLE1BQU0sQ0FDVCxJQUFBLDhCQUFhLEVBQUM7WUFDWixJQUFJLEVBQUUsYUFBYTtZQUNuQixPQUFPLEVBQUUsMERBQTBEO1lBQ25FLEdBQUcsRUFBRTs7Ozs7Ozs7Ozs7Ozs7Ozs4QkFnQmlCO1lBQ3RCLE9BQU8sRUFBRTtnQkFDUCxHQUFHLEVBQUUsNkJBQTZCO2dCQUNsQyxRQUFRLEVBQUUsMERBQTBEO2dCQUNwRSxNQUFNLEVBQUUsd0NBQXdDO2dCQUNoRCxtQkFBbUIsRUFBRSxrQ0FBa0M7Z0JBQ3ZELFdBQVcsRUFBRSw2Q0FBNkM7Z0JBQzFELFdBQVcsRUFBRSx3QkFBd0I7YUFDdEM7U0FDRixDQUFDLENBQ0gsQ0FBQTtJQUNILENBQUM7SUFFUSxLQUFLLENBQUMsSUFBSTtRQUNqQixJQUFJLENBQUMsTUFBTSxDQUFDLElBQUEsa0NBQWlCLEVBQUMsYUFBYSxDQUFDLENBQUMsQ0FBQTtJQUMvQyxDQUFDO0NBQ0Y7QUF0Q0QsMERBc0NDIn0=
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261123090000 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261123090000 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ /*
6
+ * The refresh queue: orders whose facts need rebuilding. Order and refund
7
+ * subscribers add a row and return; the sales-facts-drain job refreshes the
8
+ * queued orders in batches. That way a subscriber never waits on the facts
9
+ * lock while holding one of the connections checkout needs.
10
+ *
11
+ * Plain SQL like the rollups: one row per order (the order id is the key),
12
+ * so a model's id, timestamps and soft delete would never be used.
13
+ *
14
+ * - include_customer_orders: also refresh the customer's other orders (set by
15
+ * a cancel, which can move their first order). Merged with OR on re-queue.
16
+ * - version: goes up when an order is queued again. The drain only removes
17
+ * the rows it read, at the version it read, so a change that arrives while
18
+ * a batch is refreshing stays queued for the next batch.
19
+ * - queued_at: when the order was first queued. Not moved on re-queue, so the
20
+ * oldest change is drained first and the queue's lag can be measured.
21
+ */
22
+ class Migration20261123090000 extends migrations_1.Migration {
23
+ async up() {
24
+ this.addSql(`create table if not exists "analytics_fact_queue" (
25
+ "order_id" text not null,
26
+ "include_customer_orders" boolean not null default false,
27
+ "version" integer not null default 1,
28
+ "queued_at" timestamptz not null default now(),
29
+ constraint "analytics_fact_queue_pkey" primary key ("order_id")
30
+ );`);
31
+ this.addSql(`create index if not exists "IDX_analytics_fact_queue_queued_at" on "analytics_fact_queue" ("queued_at");`);
32
+ }
33
+ async down() {
34
+ this.addSql(`drop table if exists "analytics_fact_queue";`);
35
+ }
36
+ }
37
+ exports.Migration20261123090000 = Migration20261123090000;
38
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjMwOTAwMDAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIzMDkwMDAwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFvRTtBQUVwRTs7Ozs7Ozs7Ozs7Ozs7OztHQWdCRztBQUNILE1BQWEsdUJBQXdCLFNBQVEsc0JBQVM7SUFDM0MsS0FBSyxDQUFDLEVBQUU7UUFDZixJQUFJLENBQUMsTUFBTSxDQUFDOzs7Ozs7T0FNVCxDQUFDLENBQUE7UUFDSixJQUFJLENBQUMsTUFBTSxDQUNULDBHQUEwRyxDQUMzRyxDQUFBO0lBQ0gsQ0FBQztJQUVRLEtBQUssQ0FBQyxJQUFJO1FBQ2pCLElBQUksQ0FBQyxNQUFNLENBQUMsOENBQThDLENBQUMsQ0FBQTtJQUM3RCxDQUFDO0NBQ0Y7QUFqQkQsMERBaUJDIn0=
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261123100000 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261123100000 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ /*
6
+ * Failed drain attempts per queued order. A batch that fails moves to the
7
+ * back of the queue with attempts + 1, so it can't hold up the orders behind
8
+ * it; after a few failures its rows are dropped and the nightly reconcile
9
+ * repairs them. See SalesFactsService.drainQueue.
10
+ */
11
+ class Migration20261123100000 extends migrations_1.Migration {
12
+ async up() {
13
+ this.addSql(`alter table if exists "analytics_fact_queue" add column if not exists "attempts" integer not null default 0;`);
14
+ }
15
+ async down() {
16
+ this.addSql(`alter table if exists "analytics_fact_queue" drop column if exists "attempts";`);
17
+ }
18
+ }
19
+ exports.Migration20261123100000 = Migration20261123100000;
20
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjMxMDAwMDAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIzMTAwMDAwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFvRTtBQUVwRTs7Ozs7R0FLRztBQUNILE1BQWEsdUJBQXdCLFNBQVEsc0JBQVM7SUFDM0MsS0FBSyxDQUFDLEVBQUU7UUFDZixJQUFJLENBQUMsTUFBTSxDQUNULDhHQUE4RyxDQUMvRyxDQUFBO0lBQ0gsQ0FBQztJQUVRLEtBQUssQ0FBQyxJQUFJO1FBQ2pCLElBQUksQ0FBQyxNQUFNLENBQ1QsZ0ZBQWdGLENBQ2pGLENBQUE7SUFDSCxDQUFDO0NBQ0Y7QUFaRCwwREFZQyJ9
@@ -0,0 +1,6 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261123110000 extends Migration {
3
+ isTransactional(): boolean;
4
+ up(): Promise<void>;
5
+ down(): Promise<void>;
6
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261123110000 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ // On an empty database this runs before Medusa's own tables exist; the analytics-core-indexes migration script adds the index later.
6
+ const tableExists = async (migration, table) => {
7
+ const [row] = await migration.execute(`select to_regclass('public."${table}"') is not null as present`);
8
+ return (typeof row === "object" &&
9
+ row !== null &&
10
+ "present" in row &&
11
+ row.present === true);
12
+ };
13
+ class Migration20261123110000 extends migrations_1.Migration {
14
+ isTransactional() {
15
+ return false;
16
+ }
17
+ async up() {
18
+ if (!(await tableExists(this, "cart"))) {
19
+ return;
20
+ }
21
+ this.addSql(`create index concurrently if not exists "IDX_analytics_cart_open_updated_at" on "cart" ("updated_at") where "deleted_at" is null and "completed_at" is null;`);
22
+ }
23
+ async down() {
24
+ this.addSql(`drop index concurrently if exists "IDX_analytics_cart_open_updated_at";`);
25
+ }
26
+ }
27
+ exports.Migration20261123110000 = Migration20261123110000;
28
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjMxMTAwMDAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIzMTEwMDAwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFvRTtBQXVCcEUscUlBQXFJO0FBQ3JJLE1BQU0sV0FBVyxHQUFHLEtBQUssRUFBRSxTQUFxQixFQUFFLEtBQWEsRUFBRSxFQUFFO0lBQ2pFLE1BQU0sQ0FBQyxHQUFHLENBQUMsR0FBRyxNQUFNLFNBQVMsQ0FBQyxPQUFPLENBQ25DLCtCQUErQixLQUFLLDRCQUE0QixDQUNqRSxDQUFBO0lBQ0QsT0FBTyxDQUNMLE9BQU8sR0FBRyxLQUFLLFFBQVE7UUFDdkIsR0FBRyxLQUFLLElBQUk7UUFDWixTQUFTLElBQUksR0FBRztRQUNoQixHQUFHLENBQUMsT0FBTyxLQUFLLElBQUksQ0FDckIsQ0FBQTtBQUNILENBQUMsQ0FBQTtBQUVELE1BQWEsdUJBQXdCLFNBQVEsc0JBQVM7SUFDM0MsZUFBZTtRQUN0QixPQUFPLEtBQUssQ0FBQTtJQUNkLENBQUM7SUFFUSxLQUFLLENBQUMsRUFBRTtRQUNmLElBQUksQ0FBQyxDQUFDLE1BQU0sV0FBVyxDQUFDLElBQUksRUFBRSxNQUFNLENBQUMsQ0FBQyxFQUFFLENBQUM7WUFDdkMsT0FBTTtRQUNSLENBQUM7UUFDRCxJQUFJLENBQUMsTUFBTSxDQUNULDhKQUE4SixDQUMvSixDQUFBO0lBQ0gsQ0FBQztJQUVRLEtBQUssQ0FBQyxJQUFJO1FBQ2pCLElBQUksQ0FBQyxNQUFNLENBQ1QseUVBQXlFLENBQzFFLENBQUE7SUFDSCxDQUFDO0NBQ0Y7QUFuQkQsMERBbUJDIn0=
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261123120000 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261123120000 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ /*
6
+ * Per-day data versions for the report cache. Every fact refresh stamps the
7
+ * days it rebuilt with the new global data_version (analytics_fact_state), so
8
+ * a report's cache key only changes when a day inside its window changed:
9
+ * today's orders no longer throw away every cached report about last month.
10
+ *
11
+ * Plain SQL like the rollups (one row per store-local day, YYYY-MM-DD like
12
+ * the facts' local_day). Emptied with the facts when a rebuild starts.
13
+ */
14
+ class Migration20261123120000 extends migrations_1.Migration {
15
+ async up() {
16
+ this.addSql(`create table if not exists "analytics_day_version" (
17
+ "local_day" text not null,
18
+ "version" bigint not null,
19
+ constraint "analytics_day_version_pkey" primary key ("local_day")
20
+ );`);
21
+ }
22
+ async down() {
23
+ this.addSql(`drop table if exists "analytics_day_version";`);
24
+ }
25
+ }
26
+ exports.Migration20261123120000 = Migration20261123120000;
27
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjMxMjAwMDAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIzMTIwMDAwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFvRTtBQUVwRTs7Ozs7Ozs7R0FRRztBQUNILE1BQWEsdUJBQXdCLFNBQVEsc0JBQVM7SUFDM0MsS0FBSyxDQUFDLEVBQUU7UUFDZixJQUFJLENBQUMsTUFBTSxDQUFDOzs7O09BSVQsQ0FBQyxDQUFBO0lBQ04sQ0FBQztJQUVRLEtBQUssQ0FBQyxJQUFJO1FBQ2pCLElBQUksQ0FBQyxNQUFNLENBQUMsK0NBQStDLENBQUMsQ0FBQTtJQUM5RCxDQUFDO0NBQ0Y7QUFaRCwwREFZQyJ9
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261123184118 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20261123184118 = void 0;
4
+ const migrations_1 = require("@medusajs/framework/mikro-orm/migrations");
5
+ /*
6
+ * How the stored facts were computed (FACTS_FORMAT in
7
+ * src/shared/analytics/facts-format.ts). Existing rows get 1, so the first
8
+ * backfill run after this release rebuilds every fact with Medusa's own
9
+ * totals (format 2) while reports read Medusa's order tables.
10
+ */
11
+ class Migration20261123184118 extends migrations_1.Migration {
12
+ async up() {
13
+ this.addSql(`alter table if exists "analytics_fact_state" add column if not exists "facts_format" integer not null default 1;`);
14
+ }
15
+ async down() {
16
+ this.addSql(`alter table if exists "analytics_fact_state" drop column if exists "facts_format";`);
17
+ }
18
+ }
19
+ exports.Migration20261123184118 = Migration20261123184118;
20
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWlncmF0aW9uMjAyNjExMjMxODQxMTguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9zcmMvbW9kdWxlcy9zYWxlcy1mYWN0cy9taWdyYXRpb25zL01pZ3JhdGlvbjIwMjYxMTIzMTg0MTE4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHlFQUFxRTtBQUVyRTs7Ozs7R0FLRztBQUNILE1BQWEsdUJBQXdCLFNBQVEsc0JBQVM7SUFFM0MsS0FBSyxDQUFDLEVBQUU7UUFDZixJQUFJLENBQUMsTUFBTSxDQUFDLGtIQUFrSCxDQUFDLENBQUM7SUFDbEksQ0FBQztJQUVRLEtBQUssQ0FBQyxJQUFJO1FBQ2pCLElBQUksQ0FBQyxNQUFNLENBQUMsb0ZBQW9GLENBQUMsQ0FBQztJQUNwRyxDQUFDO0NBRUY7QUFWRCwwREFVQyJ9
@@ -0,0 +1,5 @@
1
+ import { Migration } from "@medusajs/framework/mikro-orm/migrations";
2
+ export declare class Migration20261123200000 extends Migration {
3
+ up(): Promise<void>;
4
+ down(): Promise<void>;
5
+ }