@managesome/eposmatic-toolkit 0.4.5 → 0.4.7
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.
- package/esm/constants/REPORT_CALENDAR.js +47 -0
- package/esm/constants/index.js +1 -0
- package/esm/helpers/materialized-reports/index.js +1 -0
- package/esm/helpers/materialized-reports/materialized-reports-read-helpers.js +1 -76
- package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +473 -0
- package/esm/helpers/types/index.js +1 -0
- package/lib/constants/REPORT_CALENDAR.d.ts +31 -0
- package/lib/constants/REPORT_CALENDAR.js +50 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/index.js +1 -0
- package/lib/helpers/materialized-reports/index.d.ts +1 -0
- package/lib/helpers/materialized-reports/index.js +1 -0
- package/lib/helpers/materialized-reports/materialized-reports-read-helpers.d.ts +0 -30
- package/lib/helpers/materialized-reports/materialized-reports-read-helpers.js +0 -76
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.d.ts +25 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +479 -0
- package/lib/helpers/types/index.d.ts +1 -0
- package/lib/helpers/types/index.js +1 -0
- package/lib/helpers/types/materialized-reports-apis.d.ts +14 -12
- package/lib/helpers/types/report-calendar.d.ts +20 -0
- package/lib/helpers/types/report-calendar.js +2 -0
- package/lib/schemas/models/materialized_tenant_sales_overview_reports.d.ts +3 -3
- package/lib/tests/materialized-reports/materialized-reports-selection-helpers.test.d.ts +1 -0
- package/lib/tests/materialized-reports/materialized-reports-selection-helpers.test.js +166 -0
- package/package.json +1 -1
- package/lib/tests/materialized-reports/materialized-reports-read-helpers.test.js +0 -100
- /package/{lib/tests/materialized-reports/materialized-reports-read-helpers.test.d.ts → esm/helpers/types/report-calendar.js} +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ENUMS_1 = require("../../constants/ENUMS");
|
|
4
|
+
const REPORT_CALENDAR_1 = require("../../constants/REPORT_CALENDAR");
|
|
5
|
+
const materialized_reports_selection_helpers_1 = require("../../helpers/materialized-reports/materialized-reports-selection-helpers");
|
|
6
|
+
const selection = (over = {}) => ({
|
|
7
|
+
mode: REPORT_CALENDAR_1.CALENDAR_MODE_ENUM.HISTORICAL,
|
|
8
|
+
view: REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.DATE_RANGE,
|
|
9
|
+
rangeStart: null,
|
|
10
|
+
rangeEnd: null,
|
|
11
|
+
selectedDates: [],
|
|
12
|
+
timeStart: null,
|
|
13
|
+
timeEnd: null,
|
|
14
|
+
selectedPeriods: [],
|
|
15
|
+
weekdays: [],
|
|
16
|
+
...over,
|
|
17
|
+
});
|
|
18
|
+
const hourLabels = (dayKey) => [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4, 5].map((hour) => `${dayKey} ${`${hour}`.padStart(2, '0')}`);
|
|
19
|
+
describe('buildMaterializedReportScopeGroupsFromSelection', () => {
|
|
20
|
+
test('LIVE reads the running day as its 24 exact hour labels', () => {
|
|
21
|
+
const groups = (0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
|
|
22
|
+
mode: REPORT_CALENDAR_1.CALENDAR_MODE_ENUM.LIVE,
|
|
23
|
+
rangeStart: '2026-09-30',
|
|
24
|
+
}));
|
|
25
|
+
expect(groups).toEqual([{ scope_context: 'localHour', scope_field: hourLabels('2026-09-30') }]);
|
|
26
|
+
});
|
|
27
|
+
test('LIVE without a committed day cannot be served', () => {
|
|
28
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({ mode: REPORT_CALENDAR_1.CALENDAR_MODE_ENUM.LIVE }))).toBeNull();
|
|
29
|
+
});
|
|
30
|
+
test('single day → direct localDate value', () => {
|
|
31
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({ rangeStart: '2026-10-14' }))).toEqual([
|
|
32
|
+
{ scope_context: 'localDate', scope_field: ['2026-10-14'] },
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
test('a full month run compacts to its localMonth value', () => {
|
|
36
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({ rangeStart: '2026-09-01', rangeEnd: '2026-09-30' }))).toEqual([{ scope_context: 'localMonth', scope_field: ['2026-09'] }]);
|
|
37
|
+
});
|
|
38
|
+
test('a full quarter run compacts to its localQuarter value', () => {
|
|
39
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({ rangeStart: '2026-07-01', rangeEnd: '2026-09-30' }))).toEqual([{ scope_context: 'localQuarter', scope_field: ['2026-Q3'] }]);
|
|
40
|
+
});
|
|
41
|
+
test('MULTI_DATE: an exact full week folds to its week-start', () => {
|
|
42
|
+
// Sun 2026-09-27 … Sat 2026-10-03
|
|
43
|
+
const week = ['2026-09-27', '2026-09-28', '2026-09-29', '2026-09-30', '2026-10-01', '2026-10-02', '2026-10-03'];
|
|
44
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({ view: REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.MULTI_DATE, selectedDates: week }))).toEqual([{ scope_context: 'localWeek', scope_field: ['2026-09-27'] }]);
|
|
45
|
+
});
|
|
46
|
+
test('MONTH view enumerates the exact month keys of the range', () => {
|
|
47
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
|
|
48
|
+
view: REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.MONTH,
|
|
49
|
+
rangeStart: '2026-09-01',
|
|
50
|
+
rangeEnd: '2026-11-15',
|
|
51
|
+
}))).toEqual([{ scope_context: 'localMonth', scope_field: ['2026-09', '2026-10', '2026-11'] }]);
|
|
52
|
+
});
|
|
53
|
+
test('YEAR and DIFFERENT_MONTHS views read their exact period keys', () => {
|
|
54
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
|
|
55
|
+
view: REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.YEAR,
|
|
56
|
+
rangeStart: '2024-01-01',
|
|
57
|
+
rangeEnd: '2026-06-01',
|
|
58
|
+
}))).toEqual([{ scope_context: 'localYear', scope_field: ['2024', '2025', '2026'] }]);
|
|
59
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
|
|
60
|
+
view: REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.DIFFERENT_MONTHS,
|
|
61
|
+
selectedPeriods: ['2026-03', '2026-01'],
|
|
62
|
+
}))).toEqual([{ scope_context: 'localMonth', scope_field: ['2026-03', '2026-01'] }]);
|
|
63
|
+
});
|
|
64
|
+
test('weekday refinement narrows the day set before compiling (localDate fallback)', () => {
|
|
65
|
+
const groups = (0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
|
|
66
|
+
rangeStart: '2026-10-01',
|
|
67
|
+
rangeEnd: '2026-10-31',
|
|
68
|
+
weekdays: [ENUMS_1.DAY_INDEX_ENUM.MON],
|
|
69
|
+
}));
|
|
70
|
+
// Oct 2026 Mondays — period docs carry no day_index, so the read stays on
|
|
71
|
+
// standalone day documents.
|
|
72
|
+
expect(groups).toEqual([
|
|
73
|
+
{
|
|
74
|
+
scope_context: 'localDate',
|
|
75
|
+
scope_field: ['2026-10-05', '2026-10-12', '2026-10-19', '2026-10-26'],
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
78
|
+
});
|
|
79
|
+
test('a 7-day weekday list is treated as “every day” (no refinement)', () => {
|
|
80
|
+
const groups = (0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
|
|
81
|
+
rangeStart: '2026-09-01',
|
|
82
|
+
rangeEnd: '2026-09-30',
|
|
83
|
+
weekdays: [
|
|
84
|
+
ENUMS_1.DAY_INDEX_ENUM.MON,
|
|
85
|
+
ENUMS_1.DAY_INDEX_ENUM.TUE,
|
|
86
|
+
ENUMS_1.DAY_INDEX_ENUM.WED,
|
|
87
|
+
ENUMS_1.DAY_INDEX_ENUM.THU,
|
|
88
|
+
ENUMS_1.DAY_INDEX_ENUM.FRI,
|
|
89
|
+
ENUMS_1.DAY_INDEX_ENUM.SAT,
|
|
90
|
+
ENUMS_1.DAY_INDEX_ENUM.SUN,
|
|
91
|
+
],
|
|
92
|
+
}));
|
|
93
|
+
expect(groups).toEqual([{ scope_context: 'localMonth', scope_field: ['2026-09'] }]);
|
|
94
|
+
});
|
|
95
|
+
test('dedicated window view repeats the SAME hours on every selected day', () => {
|
|
96
|
+
const groups = (0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
|
|
97
|
+
view: REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.DATE_RANGE_TIME_WINDOW,
|
|
98
|
+
rangeStart: '2026-09-01',
|
|
99
|
+
rangeEnd: '2026-09-02',
|
|
100
|
+
timeStart: '16:00',
|
|
101
|
+
timeEnd: '18:00',
|
|
102
|
+
}));
|
|
103
|
+
expect(groups).toEqual([
|
|
104
|
+
{
|
|
105
|
+
scope_context: 'localHour',
|
|
106
|
+
scope_field: ['2026-09-01 16', '2026-09-01 17', '2026-09-02 16', '2026-09-02 17'],
|
|
107
|
+
},
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
test('range-like window view compiles a CONTINUOUS span (boundary hours + compacted middle)', () => {
|
|
111
|
+
const groups = (0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
|
|
112
|
+
rangeStart: '2026-09-01',
|
|
113
|
+
rangeEnd: '2026-09-03',
|
|
114
|
+
timeStart: '18:00',
|
|
115
|
+
timeEnd: '20:00',
|
|
116
|
+
}));
|
|
117
|
+
expect(groups).not.toBeNull();
|
|
118
|
+
// The middle whole day folds into its localDate value…
|
|
119
|
+
expect(groups).toContainEqual({
|
|
120
|
+
scope_context: 'localDate',
|
|
121
|
+
scope_field: ['2026-09-02'],
|
|
122
|
+
});
|
|
123
|
+
// …while the boundary days carry their exact hour labels: the start day
|
|
124
|
+
// contributes its business-day tail (00–05) plus the hours from the window
|
|
125
|
+
// start through 23; the end day contributes 06 through the hour before the
|
|
126
|
+
// window end.
|
|
127
|
+
const hourGroup = groups?.find((group) => group.scope_context === 'localHour');
|
|
128
|
+
expect(hourGroup).toBeDefined();
|
|
129
|
+
const asLabels = (day, hours) => hours.map((hour) => `${day} ${hour}`);
|
|
130
|
+
expect(hourGroup?.scope_field).toEqual([
|
|
131
|
+
...asLabels('2026-09-01', ['00', '01', '02', '03', '04', '05']),
|
|
132
|
+
...asLabels('2026-09-01', ['18', '19', '20', '21', '22', '23']),
|
|
133
|
+
...asLabels('2026-09-03', ['06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19']),
|
|
134
|
+
]);
|
|
135
|
+
});
|
|
136
|
+
test('an incomplete dedicated window falls back to the plain range read', () => {
|
|
137
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
|
|
138
|
+
view: REPORT_CALENDAR_1.CALENDAR_VIEW_MODE_ENUM.DATE_RANGE_TIME_WINDOW,
|
|
139
|
+
rangeStart: '2026-09-01',
|
|
140
|
+
rangeEnd: '2026-09-30',
|
|
141
|
+
timeStart: '04:00',
|
|
142
|
+
timeEnd: '08:00', // crosses the 06:00 business-morning boundary → unservable
|
|
143
|
+
}))).toEqual([{ scope_context: 'localMonth', scope_field: ['2026-09'] }]);
|
|
144
|
+
});
|
|
145
|
+
test('an empty selection cannot be served', () => {
|
|
146
|
+
expect((0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection())).toBeNull();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
describe('getDayKeysFromCalendarSelection', () => {
|
|
150
|
+
test('expands a range, applies the weekday filter, and keeps order', () => {
|
|
151
|
+
expect((0, materialized_reports_selection_helpers_1.getDayKeysFromCalendarSelection)(selection({
|
|
152
|
+
rangeStart: '2026-10-03',
|
|
153
|
+
rangeEnd: '2026-10-06',
|
|
154
|
+
weekdays: [ENUMS_1.DAY_INDEX_ENUM.SAT, ENUMS_1.DAY_INDEX_ENUM.SUN],
|
|
155
|
+
}))).toEqual(['2026-10-03', '2026-10-04']);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('isValidBusinessHourWindow', () => {
|
|
159
|
+
test('accepts same-day and midnight-wrap windows, rejects boundary walks', () => {
|
|
160
|
+
expect((0, materialized_reports_selection_helpers_1.isValidBusinessHourWindow)(16, 18)).toBe(true);
|
|
161
|
+
expect((0, materialized_reports_selection_helpers_1.isValidBusinessHourWindow)(22, 2)).toBe(true);
|
|
162
|
+
expect((0, materialized_reports_selection_helpers_1.isValidBusinessHourWindow)(4, 8)).toBe(false);
|
|
163
|
+
expect((0, materialized_reports_selection_helpers_1.isValidBusinessHourWindow)(16, 16)).toBe(false);
|
|
164
|
+
expect((0, materialized_reports_selection_helpers_1.isValidBusinessHourWindow)(-1, 5)).toBe(false);
|
|
165
|
+
});
|
|
166
|
+
});
|
package/package.json
CHANGED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const MATERIALIZED_REPORTS_1 = require("../../constants/MATERIALIZED_REPORTS");
|
|
4
|
-
const materialized_reports_read_helpers_1 = require("../../helpers/materialized-reports/materialized-reports-read-helpers");
|
|
5
|
-
describe('buildMaterializedReportReadBody', () => {
|
|
6
|
-
test('builds the canonical body, normalizing tenants and merging same-context groups', () => {
|
|
7
|
-
const body = (0, materialized_reports_read_helpers_1.buildMaterializedReportReadBody)({
|
|
8
|
-
tenants: ['tenant-b', 'tenant-a', 'tenant-b'],
|
|
9
|
-
groups: [
|
|
10
|
-
{
|
|
11
|
-
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR,
|
|
12
|
-
scope_field: ['2026-09-02 18', '2026-09-01 21', '2026-09-02 18'],
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
// same context → merged into the first group (values unioned)
|
|
16
|
-
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR,
|
|
17
|
-
scope_field: ['2026-09-01 21', '2026-09-03 09'],
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
21
|
-
scope_field: ['2026-09-02', '2026-09-01'],
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
});
|
|
25
|
-
expect(body).toEqual({
|
|
26
|
-
tenants: ['tenant-b', 'tenant-a'], // deduped, order kept
|
|
27
|
-
scope_groups: [
|
|
28
|
-
{
|
|
29
|
-
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_HOUR,
|
|
30
|
-
scope_field: ['2026-09-01 21', '2026-09-02 18', '2026-09-03 09'], // deduped + sorted
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
34
|
-
scope_field: ['2026-09-01', '2026-09-02'],
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
test('resolves omitted scope_context to localDate and MERGES it with explicit localDate groups', () => {
|
|
40
|
-
const body = (0, materialized_reports_read_helpers_1.buildMaterializedReportReadBody)({
|
|
41
|
-
tenants: ['tenant-a'],
|
|
42
|
-
groups: [
|
|
43
|
-
{ scope_field: ['2026-09-01'] },
|
|
44
|
-
{ scope_field: ['2026-09-02', '2026-09-01'] },
|
|
45
|
-
{
|
|
46
|
-
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
47
|
-
scope_field: ['2026-09-03', '2026-09-01'],
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
});
|
|
51
|
-
// ONE localDate group — an omitted context IS `localDate`; keeping it
|
|
52
|
-
// separate would make the backend double-count the shared documents.
|
|
53
|
-
expect(body).toEqual({
|
|
54
|
-
tenants: ['tenant-a'],
|
|
55
|
-
scope_groups: [
|
|
56
|
-
{
|
|
57
|
-
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
58
|
-
scope_field: ['2026-09-01', '2026-09-02', '2026-09-03'],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
test('trims tenants and scope values (whitespace-only is invalid)', () => {
|
|
64
|
-
const body = (0, materialized_reports_read_helpers_1.buildMaterializedReportReadBody)({
|
|
65
|
-
tenants: [' tenant-a ', 'tenant-a', 'tenant-a '],
|
|
66
|
-
groups: [{ scope_field: [' 2026-09-01 '] }],
|
|
67
|
-
});
|
|
68
|
-
expect(body).toEqual({
|
|
69
|
-
tenants: ['tenant-a'],
|
|
70
|
-
scope_groups: [
|
|
71
|
-
{
|
|
72
|
-
scope_context: MATERIALIZED_REPORTS_1.MATERIALIZED_REPORT_SCOPE_ENUM.LOCAL_DATE,
|
|
73
|
-
scope_field: ['2026-09-01'],
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
test('returns null (never throws) for invalid input', () => {
|
|
79
|
-
const invalidInputs = [
|
|
80
|
-
null,
|
|
81
|
-
undefined,
|
|
82
|
-
{},
|
|
83
|
-
{ tenants: [], groups: [{ scope_field: ['2026-09'] }] },
|
|
84
|
-
{ tenants: [1], groups: [{ scope_field: ['2026-09'] }] },
|
|
85
|
-
{ tenants: ['tenant-a'], groups: [] },
|
|
86
|
-
{ tenants: ['tenant-a'], groups: [{ scope_field: [] }] },
|
|
87
|
-
{ tenants: ['tenant-a'], groups: [{ scope_field: [''] }] },
|
|
88
|
-
{ tenants: ['tenant-a'], groups: [{ scope_field: [' '] }] },
|
|
89
|
-
{ tenants: [' '], groups: [{ scope_field: ['2026-09'] }] },
|
|
90
|
-
{ tenants: ['tenant-a'], groups: [{ scope_field: [null] }] },
|
|
91
|
-
{
|
|
92
|
-
tenants: ['tenant-a'],
|
|
93
|
-
groups: [{ scope_context: 'nope', scope_field: ['2026-09'] }],
|
|
94
|
-
},
|
|
95
|
-
];
|
|
96
|
-
invalidInputs.forEach((input) => {
|
|
97
|
-
expect((0, materialized_reports_read_helpers_1.buildMaterializedReportReadBody)(input)).toBeNull();
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|