@managesome/eposmatic-toolkit 0.4.5 → 0.4.8

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 (68) hide show
  1. package/esm/constants/MATERIALIZED_REPORTS.js +33 -0
  2. package/esm/constants/REPORT_CALENDAR.js +47 -0
  3. package/esm/constants/index.js +1 -0
  4. package/esm/helpers/materialized-reports/index.js +2 -0
  5. package/esm/helpers/materialized-reports/materialized-credit-bills-helpers.js +982 -0
  6. package/esm/helpers/materialized-reports/materialized-reports-read-helpers.js +1 -76
  7. package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +716 -0
  8. package/esm/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +327 -41
  9. package/esm/helpers/materialized-reports/tenant-sales-overview-formatter.js +72 -11
  10. package/esm/helpers/materialized-reports/tenant-sales-overview-helpers.js +118 -235
  11. package/esm/helpers/types/index.js +1 -0
  12. package/esm/schemas/models/index.js +1 -0
  13. package/esm/schemas/models/materialized_credit_bills.js +265 -0
  14. package/esm/schemas/models/materialized_tenant_reports_iterations.js +13 -0
  15. package/esm/schemas/models/materialized_tenant_sales_overview_reports.js +39 -97
  16. package/esm/schemas/types/index.js +1 -0
  17. package/esm/schemas/types/materialized_credit_bills.js +1 -0
  18. package/lib/constants/MATERIALIZED_REPORTS.d.ts +28 -2
  19. package/lib/constants/MATERIALIZED_REPORTS.js +34 -1
  20. package/lib/constants/REPORT_CALENDAR.d.ts +31 -0
  21. package/lib/constants/REPORT_CALENDAR.js +50 -0
  22. package/lib/constants/index.d.ts +1 -0
  23. package/lib/constants/index.js +1 -0
  24. package/lib/helpers/materialized-reports/index.d.ts +2 -0
  25. package/lib/helpers/materialized-reports/index.js +2 -0
  26. package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.d.ts +307 -0
  27. package/lib/helpers/materialized-reports/materialized-credit-bills-helpers.js +1003 -0
  28. package/lib/helpers/materialized-reports/materialized-reports-read-helpers.d.ts +0 -30
  29. package/lib/helpers/materialized-reports/materialized-reports-read-helpers.js +0 -76
  30. package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.d.ts +59 -0
  31. package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +723 -0
  32. package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.d.ts +66 -8
  33. package/lib/helpers/materialized-reports/tenant-sales-overview-close-day-helpers.js +326 -40
  34. package/lib/helpers/materialized-reports/tenant-sales-overview-formatter.d.ts +18 -2
  35. package/lib/helpers/materialized-reports/tenant-sales-overview-formatter.js +72 -11
  36. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.d.ts +46 -37
  37. package/lib/helpers/materialized-reports/tenant-sales-overview-helpers.js +119 -238
  38. package/lib/helpers/types/index.d.ts +1 -0
  39. package/lib/helpers/types/index.js +1 -0
  40. package/lib/helpers/types/materialized-reports-apis.d.ts +46 -17
  41. package/lib/helpers/types/report-calendar.d.ts +20 -0
  42. package/lib/helpers/types/report-calendar.js +2 -0
  43. package/lib/schemas/models/index.d.ts +1 -0
  44. package/lib/schemas/models/index.js +1 -0
  45. package/lib/schemas/models/materialized_credit_bills.d.ts +337 -0
  46. package/lib/schemas/models/materialized_credit_bills.js +268 -0
  47. package/lib/schemas/models/materialized_tenant_reports_iterations.d.ts +20 -6
  48. package/lib/schemas/models/materialized_tenant_reports_iterations.js +14 -1
  49. package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +37 -165
  50. package/lib/schemas/models/materialized_tenant_sales_overview_reports.js +40 -98
  51. package/lib/schemas/types/index.d.ts +1 -0
  52. package/lib/schemas/types/index.js +1 -0
  53. package/lib/schemas/types/materialized_credit_bills.d.ts +139 -0
  54. package/lib/schemas/types/materialized_credit_bills.js +2 -0
  55. package/lib/schemas/types/materialized_tenant_sales_overview_reports.d.ts +32 -77
  56. package/lib/tests/materialized-reports/materialized-credit-bills-helpers.test.d.ts +1 -0
  57. package/lib/tests/materialized-reports/materialized-credit-bills-helpers.test.js +715 -0
  58. package/lib/tests/materialized-reports/materialized-reports-selection-helpers.test.d.ts +1 -0
  59. package/lib/tests/materialized-reports/materialized-reports-selection-helpers.test.js +262 -0
  60. package/lib/tests/materialized-reports/materialized-tenant-reports-iterations-schema.test.js +9 -0
  61. package/lib/tests/materialized-reports/materialized-tenant-sales-overview-reports-schema.test.js +23 -24
  62. package/lib/tests/materialized-reports/tenant-sales-overview-close-day-helpers.test.js +327 -22
  63. package/lib/tests/materialized-reports/tenant-sales-overview-formatter-aggregated.test.js +27 -2
  64. package/lib/tests/materialized-reports/tenant-sales-overview-formatter.test.js +12 -27
  65. package/lib/tests/materialized-reports/tenant-sales-overview-helpers.test.js +79 -146
  66. package/package.json +1 -1
  67. package/lib/tests/materialized-reports/materialized-reports-read-helpers.test.js +0 -100
  68. /package/{lib/tests/materialized-reports/materialized-reports-read-helpers.test.d.ts → esm/helpers/types/report-calendar.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { ALL_MATERIALIZED_REPORT_SCOPES, MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
1
+ import { MATERIALIZED_REPORT_SCOPE_ENUM } from '../../constants/MATERIALIZED_REPORTS';
2
2
  import { getMaterializedHourScopeField, parseMaterializedLocalDate } from './scope-helpers';
3
3
  /**
4
4
  * Read-side helpers for materialized-report documents — the frontend-facing
@@ -149,78 +149,3 @@ export function filterMaterializedTenantSalesOverviewReportsByScopeFields(docs,
149
149
  const wanted = new Set(scopeFields);
150
150
  return docs.filter((doc) => doc != null && wanted.has(doc.scope_field));
151
151
  }
152
- /**
153
- * Builds the canonical body of a materialized reports READ call —
154
- * `{ tenants, scope_groups }`, the shared shape of every report endpoint.
155
- *
156
- * Normalization (invalid input → `null`, never throws):
157
- * - tenants are trimmed + deduped (whitespace-only tenants are rejected);
158
- * - each group's `scope_context` is RESOLVED to its server default
159
- * (`localDate`) BEFORE bucketing, so an omitted context and an explicit
160
- * `localDate` group merge into ONE — never two semantically identical
161
- * groups (the backend merges branch rows with `$sum`, so overlapping
162
- * groups would double-count every shared document);
163
- * - values are trimmed + deduped + sorted (lexicographic order is
164
- * chronological for the fixed-width period formats; hour labels are
165
- * `$in`-matched, so their order is cosmetic only);
166
- * - groups with the same context are merged (values unioned); every emitted
167
- * group carries an explicit `scope_context`.
168
- *
169
- * The body carries NO response-mode switch: every read is answered with
170
- * the aggregated record(s). Per group, `scope_field.length` only picks the
171
- * backend's query strategy (a single value → direct equality; multiple →
172
- * `$in`).
173
- *
174
- * Returns `null` (never throws) for invalid input — `null` means the caller
175
- * passed invalid data.
176
- */
177
- export function buildMaterializedReportReadBody(input) {
178
- if (input == null)
179
- return null;
180
- const { tenants, groups } = input;
181
- if (!Array.isArray(tenants) || tenants.length === 0)
182
- return null;
183
- if (tenants.some((tenantId) => typeof tenantId !== 'string' || tenantId.trim() === '')) {
184
- return null;
185
- }
186
- if (!Array.isArray(groups) || groups.length === 0)
187
- return null;
188
- const buckets = new Map();
189
- for (const group of groups) {
190
- if (group == null || !Array.isArray(group.scope_field) || group.scope_field.length === 0)
191
- return null;
192
- const { scope_context } = group;
193
- if (scope_context != null && !ALL_MATERIALIZED_REPORT_SCOPES.includes(scope_context))
194
- return null;
195
- // Resolve the context default BEFORE bucketing — an omitted context IS
196
- // `localDate` (the server default), so it must merge with an explicit
197
- // `localDate` group instead of surviving as a second, overlapping group.
198
- const context = scope_context ?? MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE;
199
- let values = buckets.get(context);
200
- if (values == null) {
201
- values = new Set();
202
- buckets.set(context, values);
203
- }
204
- for (const field of group.scope_field) {
205
- if (typeof field !== 'string')
206
- return null;
207
- const trimmed = field.trim();
208
- if (trimmed === '')
209
- return null;
210
- values.add(trimmed);
211
- }
212
- }
213
- const scope_groups = [];
214
- for (const [scope_context, values] of buckets) {
215
- const scope_field = [...values].sort();
216
- if (scope_field.length === 0)
217
- continue;
218
- scope_groups.push({ scope_context, scope_field });
219
- }
220
- if (scope_groups.length === 0)
221
- return null;
222
- return {
223
- tenants: Array.from(new Set(tenants.map((tenantId) => tenantId.trim()))),
224
- scope_groups,
225
- };
226
- }