@managesome/eposmatic-toolkit 0.4.69 → 0.4.73
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/helpers/utils/shift-window-helpers.js +24 -13
- package/lib/helpers/types/api-types.d.ts +36 -0
- package/lib/helpers/utils/shift-window-helpers.d.ts +13 -7
- package/lib/helpers/utils/shift-window-helpers.js +24 -13
- package/lib/tests/shift-window-helpers.test.js +23 -2
- package/package.json +1 -1
|
@@ -94,14 +94,20 @@ export function getFirstShiftStartPosition(shifts, dayMidnightMs, dayIndex) {
|
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Whether a new business day may be started for a CLOSED day (mirrors the POS
|
|
97
|
-
* `dayWindow` / the backend day guard)
|
|
98
|
-
* BEHIND the tenant's current local date
|
|
99
|
-
* elapsed
|
|
100
|
-
* closed day's weekday.
|
|
97
|
+
* `dayWindow` / the backend day guard). The closed day's `localDate` must be
|
|
98
|
+
* BEHIND the tenant's current local date and the closed day must have fully
|
|
99
|
+
* elapsed:
|
|
101
100
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
101
|
+
* - the closed day has scheduled shifts → `now` is past the LAST end position
|
|
102
|
+
* on that weekday. The next weekday's schedule is irrelevant; it may be an
|
|
103
|
+
* off-day, and the following business day must still become startable.
|
|
104
|
+
* - the closed day has NO scheduled shifts (off-day) → `now` is at or past the
|
|
105
|
+
* NEXT calendar day's FIRST shift start (the next business day has entered —
|
|
106
|
+
* the same boundary `hasNextDayFirstShiftStarted` uses).
|
|
107
|
+
*
|
|
108
|
+
* Returns `null` only when there is no anchor at all (no shift scheduled on
|
|
109
|
+
* either the closed day's weekday or the next day's weekday) — callers apply
|
|
110
|
+
* their legacy fallback (e.g. "a new day may start only when none is running").
|
|
105
111
|
*/
|
|
106
112
|
export function canStartNewBusinessDay(shifts, dayLocalDate, gmtOffset, now = new Date()) {
|
|
107
113
|
const frame = getTenantFramePosition(gmtOffset, now);
|
|
@@ -109,14 +115,19 @@ export function canStartNewBusinessDay(shifts, dayLocalDate, gmtOffset, now = ne
|
|
|
109
115
|
const nextDayMidnightMs = dayMidnightMs + MS_IN_DAY;
|
|
110
116
|
const dayIndex = ALL_DAY_INDEX[new Date(dayMidnightMs).getUTCDay()];
|
|
111
117
|
const nextDayIndex = ALL_DAY_INDEX[new Date(nextDayMidnightMs).getUTCDay()];
|
|
118
|
+
// A day only advances once the closed date is behind the tenant's date.
|
|
119
|
+
if (dayLocalDate >= formatLocalDateFromMidnight(frame.dayMidnightMs))
|
|
120
|
+
return false;
|
|
112
121
|
const lastEndPosition = getLastShiftEndPosition(shifts, dayMidnightMs, dayIndex);
|
|
113
122
|
const firstNextStartPosition = getFirstShiftStartPosition(shifts, nextDayMidnightMs, nextDayIndex);
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
// Off-day closed day: it has no window of its own to wait for, so the next
|
|
124
|
+
// business day's first shift start is the anchor.
|
|
125
|
+
if (lastEndPosition == null) {
|
|
126
|
+
return firstNextStartPosition == null ? null : frame.nowPos >= firstNextStartPosition;
|
|
127
|
+
}
|
|
128
|
+
// The closed day has fully elapsed once its own last shift ended. An off-day
|
|
129
|
+
// on the next weekday must not postpone the following business day.
|
|
130
|
+
return frame.nowPos > lastEndPosition;
|
|
120
131
|
}
|
|
121
132
|
/**
|
|
122
133
|
* Normalizes a shift time-range into coverage intervals on the
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CUSTOMER_TARGET_MODE_ENUM, DIALER_TYPES_ENUM, WALLET_ASSET_TYPE_ENUM, WALLET_ASSIGNMENT_BEHAVIOR_ENUM } from '../../constants';
|
|
2
|
+
import { ICustomer } from '../../schemas/types/customers';
|
|
2
3
|
/**
|
|
3
4
|
* Request/response contracts for backend service APIs, shared between apps and
|
|
4
5
|
* services (items-service, POS frontends, provider integrations).
|
|
@@ -309,3 +310,38 @@ export interface IGoogleMapsRouteResponse {
|
|
|
309
310
|
polyline?: [number, number][];
|
|
310
311
|
distanceMeters: number;
|
|
311
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* Response for `GET /customer-auth/session` (items-service).
|
|
315
|
+
*
|
|
316
|
+
* `uid` is the session's Firebase uid. When an email/Google credential maps to
|
|
317
|
+
* a phone-verified account, the backend returns `canonical_token`; signing in
|
|
318
|
+
* with it switches the session to that uid before wallet data is read.
|
|
319
|
+
* `needs_phone` is true when the account has no customer record yet.
|
|
320
|
+
*/
|
|
321
|
+
export interface ICustomerAccountSessionResponse {
|
|
322
|
+
uid: string;
|
|
323
|
+
email: string | null;
|
|
324
|
+
email_verified: boolean;
|
|
325
|
+
phone_number: string | null;
|
|
326
|
+
phone_verified: boolean;
|
|
327
|
+
needs_phone: boolean;
|
|
328
|
+
customer: ICustomer | null;
|
|
329
|
+
canonical_token: string | null;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Outcome of `POST /customer-auth/link-phone` (items-service).
|
|
333
|
+
*
|
|
334
|
+
* - `created`: the phone was free and a new unverified row was created.
|
|
335
|
+
* - `linked`: the row already belonged to this identity.
|
|
336
|
+
* - `requires_otp`: an unverified row owned by someone else; send a code via
|
|
337
|
+
* `/wa/auth/send-otp` or `/sms/auth/send-otp`, then call again with `otp`.
|
|
338
|
+
* - `conflict`: a verified row owned by another account.
|
|
339
|
+
* - `verified`: the submitted `otp` was accepted and the phone now belongs to
|
|
340
|
+
* this account.
|
|
341
|
+
*/
|
|
342
|
+
export type TCustomerPhoneLinkStatus = 'created' | 'linked' | 'requires_otp' | 'conflict' | 'verified';
|
|
343
|
+
export interface ICustomerPhoneLinkResponse {
|
|
344
|
+
status: TCustomerPhoneLinkStatus;
|
|
345
|
+
phone_number_verified: boolean;
|
|
346
|
+
customer?: ICustomer | null;
|
|
347
|
+
}
|
|
@@ -82,14 +82,20 @@ export declare function getLastShiftEndPosition(shifts: IShiftWindowSource[], da
|
|
|
82
82
|
export declare function getFirstShiftStartPosition(shifts: IShiftWindowSource[], dayMidnightMs: number, dayIndex: DAY_INDEX_ENUM): number | null;
|
|
83
83
|
/**
|
|
84
84
|
* Whether a new business day may be started for a CLOSED day (mirrors the POS
|
|
85
|
-
* `dayWindow` / the backend day guard)
|
|
86
|
-
* BEHIND the tenant's current local date
|
|
87
|
-
* elapsed
|
|
88
|
-
* closed day's weekday.
|
|
85
|
+
* `dayWindow` / the backend day guard). The closed day's `localDate` must be
|
|
86
|
+
* BEHIND the tenant's current local date and the closed day must have fully
|
|
87
|
+
* elapsed:
|
|
89
88
|
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
89
|
+
* - the closed day has scheduled shifts → `now` is past the LAST end position
|
|
90
|
+
* on that weekday. The next weekday's schedule is irrelevant; it may be an
|
|
91
|
+
* off-day, and the following business day must still become startable.
|
|
92
|
+
* - the closed day has NO scheduled shifts (off-day) → `now` is at or past the
|
|
93
|
+
* NEXT calendar day's FIRST shift start (the next business day has entered —
|
|
94
|
+
* the same boundary `hasNextDayFirstShiftStarted` uses).
|
|
95
|
+
*
|
|
96
|
+
* Returns `null` only when there is no anchor at all (no shift scheduled on
|
|
97
|
+
* either the closed day's weekday or the next day's weekday) — callers apply
|
|
98
|
+
* their legacy fallback (e.g. "a new day may start only when none is running").
|
|
93
99
|
*/
|
|
94
100
|
export declare function canStartNewBusinessDay(shifts: IShiftWindowSource[], dayLocalDate: string, gmtOffset: number, now?: Date): boolean | null;
|
|
95
101
|
/**
|
|
@@ -110,14 +110,20 @@ function getFirstShiftStartPosition(shifts, dayMidnightMs, dayIndex) {
|
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Whether a new business day may be started for a CLOSED day (mirrors the POS
|
|
113
|
-
* `dayWindow` / the backend day guard)
|
|
114
|
-
* BEHIND the tenant's current local date
|
|
115
|
-
* elapsed
|
|
116
|
-
* closed day's weekday.
|
|
113
|
+
* `dayWindow` / the backend day guard). The closed day's `localDate` must be
|
|
114
|
+
* BEHIND the tenant's current local date and the closed day must have fully
|
|
115
|
+
* elapsed:
|
|
117
116
|
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
117
|
+
* - the closed day has scheduled shifts → `now` is past the LAST end position
|
|
118
|
+
* on that weekday. The next weekday's schedule is irrelevant; it may be an
|
|
119
|
+
* off-day, and the following business day must still become startable.
|
|
120
|
+
* - the closed day has NO scheduled shifts (off-day) → `now` is at or past the
|
|
121
|
+
* NEXT calendar day's FIRST shift start (the next business day has entered —
|
|
122
|
+
* the same boundary `hasNextDayFirstShiftStarted` uses).
|
|
123
|
+
*
|
|
124
|
+
* Returns `null` only when there is no anchor at all (no shift scheduled on
|
|
125
|
+
* either the closed day's weekday or the next day's weekday) — callers apply
|
|
126
|
+
* their legacy fallback (e.g. "a new day may start only when none is running").
|
|
121
127
|
*/
|
|
122
128
|
function canStartNewBusinessDay(shifts, dayLocalDate, gmtOffset, now = new Date()) {
|
|
123
129
|
const frame = getTenantFramePosition(gmtOffset, now);
|
|
@@ -125,14 +131,19 @@ function canStartNewBusinessDay(shifts, dayLocalDate, gmtOffset, now = new Date(
|
|
|
125
131
|
const nextDayMidnightMs = dayMidnightMs + exports.MS_IN_DAY;
|
|
126
132
|
const dayIndex = constants_1.ALL_DAY_INDEX[new Date(dayMidnightMs).getUTCDay()];
|
|
127
133
|
const nextDayIndex = constants_1.ALL_DAY_INDEX[new Date(nextDayMidnightMs).getUTCDay()];
|
|
134
|
+
// A day only advances once the closed date is behind the tenant's date.
|
|
135
|
+
if (dayLocalDate >= formatLocalDateFromMidnight(frame.dayMidnightMs))
|
|
136
|
+
return false;
|
|
128
137
|
const lastEndPosition = getLastShiftEndPosition(shifts, dayMidnightMs, dayIndex);
|
|
129
138
|
const firstNextStartPosition = getFirstShiftStartPosition(shifts, nextDayMidnightMs, nextDayIndex);
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
139
|
+
// Off-day closed day: it has no window of its own to wait for, so the next
|
|
140
|
+
// business day's first shift start is the anchor.
|
|
141
|
+
if (lastEndPosition == null) {
|
|
142
|
+
return firstNextStartPosition == null ? null : frame.nowPos >= firstNextStartPosition;
|
|
143
|
+
}
|
|
144
|
+
// The closed day has fully elapsed once its own last shift ended. An off-day
|
|
145
|
+
// on the next weekday must not postpone the following business day.
|
|
146
|
+
return frame.nowPos > lastEndPosition;
|
|
136
147
|
}
|
|
137
148
|
/**
|
|
138
149
|
* Normalizes a shift time-range into coverage intervals on the
|
|
@@ -11,9 +11,17 @@ const shift = (start_time, end_time, day_indexes = constants_1.ALL_DAY_INDEX) =>
|
|
|
11
11
|
end_time,
|
|
12
12
|
});
|
|
13
13
|
const NO_MONDAY = constants_1.ALL_DAY_INDEX.filter((day) => day !== constants_1.DAY_INDEX_ENUM.MON);
|
|
14
|
+
const NO_SATURDAY = constants_1.ALL_DAY_INDEX.filter((day) => day !== constants_1.DAY_INDEX_ENUM.SAT);
|
|
14
15
|
// Production shift sets (Auckland Thai Lemon: Day 9:00-17:00, Night 17:00-27:00:59.999).
|
|
15
16
|
const R1 = [shift(32400000, 61199999), shift(61200000, 97259999)];
|
|
16
17
|
const R1_NO_MONDAY = [shift(32400000, 61199999, NO_MONDAY), shift(61200000, 97259999, NO_MONDAY)];
|
|
18
|
+
// Reported production shape: one 08:00 → 29:59:59.999 shift, Saturday off.
|
|
19
|
+
// 2026-10-31 = Saturday, 2026-11-01 = Sunday.
|
|
20
|
+
const R_SATURDAY_OFF = [shift(8 * HOUR, 29 * HOUR + 59 * MINUTE + 59 * 1000 + 999, NO_SATURDAY)];
|
|
21
|
+
// Only Wednesday is scheduled — a closed Saturday and the next-day Sunday both
|
|
22
|
+
// have no shift anchor.
|
|
23
|
+
const WEDNESDAY_ONLY = [constants_1.DAY_INDEX_ENUM.WED];
|
|
24
|
+
const R_WEDNESDAY_ONLY = [shift(8 * HOUR, 17 * HOUR, WEDNESDAY_ONLY)];
|
|
17
25
|
// 2026-09-13 = Sunday, 2026-09-14 = Monday, 2026-09-15 = Tuesday.
|
|
18
26
|
const at = (y, m, d, hh, mm, ss = 0) => new Date(Date.UTC(y, m - 1, d, hh, mm, ss));
|
|
19
27
|
describe('getShiftEndPosition', () => {
|
|
@@ -67,9 +75,22 @@ describe('canStartNewBusinessDay', () => {
|
|
|
67
75
|
it('blocks while the closed date is still the current date', () => {
|
|
68
76
|
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R1, '2026-09-13', 0, at(2026, 9, 13, 23, 0))).toBe(false);
|
|
69
77
|
});
|
|
70
|
-
it('
|
|
71
|
-
|
|
78
|
+
it('allows after the closed day window ends even when the next weekday is an off-day', () => {
|
|
79
|
+
// Monday has no shifts; Sunday's night window still ends at Mon 03:00:59.999.
|
|
80
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R1_NO_MONDAY, '2026-09-13', 0, at(2026, 9, 14, 0, 30))).toBe(false);
|
|
81
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R1_NO_MONDAY, '2026-09-13', 0, at(2026, 9, 14, 3, 0, 59))).toBe(false);
|
|
82
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R1_NO_MONDAY, '2026-09-13', 0, at(2026, 9, 14, 3, 1))).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
it('anchors an off-day closed day on the next day first shift start', () => {
|
|
85
|
+
// 2026-10-31 is Saturday (no Saturday shift); Sunday 2026-11-01 starts 08:00.
|
|
86
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_SATURDAY_OFF, '2026-10-31', 0, at(2026, 10, 31, 23, 0))).toBe(false);
|
|
87
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_SATURDAY_OFF, '2026-10-31', 0, at(2026, 11, 1, 7, 59))).toBe(false);
|
|
88
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_SATURDAY_OFF, '2026-10-31', 0, at(2026, 11, 1, 8, 0))).toBe(true);
|
|
89
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_SATURDAY_OFF, '2026-10-31', 0, at(2026, 11, 1, 16, 28))).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
it('returns null only when neither the closed day nor the next day has a shift anchor', () => {
|
|
72
92
|
expect((0, shift_window_helpers_1.canStartNewBusinessDay)([], '2026-09-13', 0, at(2026, 9, 14, 3, 1))).toBeNull();
|
|
93
|
+
expect((0, shift_window_helpers_1.canStartNewBusinessDay)(R_WEDNESDAY_ONLY, '2026-10-31', 0, at(2026, 11, 1, 16, 28))).toBeNull();
|
|
73
94
|
});
|
|
74
95
|
});
|
|
75
96
|
describe('getShiftCoverageIntervals / doShiftWindowsOverlap', () => {
|