@loczer/storefront-sdk 0.150.0 → 0.152.0
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/dist/StorefrontProvider.d.ts +20 -0
- package/dist/booking-period-time-slots.d.ts +23 -38
- package/dist/booking-period.d.ts +20 -0
- package/dist/booking.d.ts +18 -0
- package/dist/checkoutSubmit.d.ts +36 -0
- package/dist/chunks/pkg/booking-engine/dist/schemas/{booking-engine-configuration-CnBdp3jk.js → booking-engine-configuration-BKlzwJJX.js} +20 -19
- package/dist/chunks/pkg/booking-engine/dist/schemas/{cart-inputs-DYgEGJ5M.js → cart-inputs-ByBK0IVJ.js} +2 -2
- package/dist/chunks/pkg/booking-engine/dist/schemas/{public-booking-engine-configuration-C9VB-WhU.js → public-booking-engine-configuration-DKoak4s5.js} +2 -2
- package/dist/chunks/pkg/booking-engine/dist/schemas/shop-opening-hours-DqNWstqT.js +51 -0
- package/dist/components/BookingPeriodSelector/useBookingPeriodController.js +76 -80
- package/dist/index.js +308 -298
- package/dist/lib/booking-period-time-slots.d.ts +0 -31
- package/dist/lib/booking-period-time-slots.js +122 -221
- package/dist/lib/booking-period.d.ts +14 -0
- package/dist/lib/booking-period.js +168 -150
- package/dist/lib/booking.d.ts +3 -0
- package/dist/lib/booking.js +102 -89
- package/dist/lib/checkoutSubmit.d.ts +34 -0
- package/dist/lib/checkoutSubmit.js +17 -15
- package/dist/lib/storefrontTimeSlots.d.ts +43 -0
- package/dist/lib/storefrontTimeSlots.js +26 -0
- package/dist/storefront.css +1 -1
- package/dist/storefrontSchemas.d.ts +8 -0
- package/dist/storefrontSchemas.js +4 -4
- package/dist/storefrontTimeSlots.d.ts +53 -0
- package/dist/whatsapp.d.ts +8 -0
- package/package.json +1 -1
- package/dist/chunks/pkg/booking-engine/dist/schemas/shop-opening-hours-B47MMaoD.js +0 -45
|
@@ -3,52 +3,52 @@ const k = (t) => {
|
|
|
3
3
|
return `${String(n).padStart(2, "0")}:${String(a).padStart(2, "0")}`;
|
|
4
4
|
}, O = (t) => {
|
|
5
5
|
if (!t) return null;
|
|
6
|
-
const [e, n] = t.split(":"), a = Number(e),
|
|
7
|
-
return !Number.isFinite(a) || !Number.isFinite(
|
|
8
|
-
},
|
|
6
|
+
const [e, n] = t.split(":"), a = Number(e), i = Number(n);
|
|
7
|
+
return !Number.isFinite(a) || !Number.isFinite(i) || a < 0 || i < 0 ? null : a * 60 + i;
|
|
8
|
+
}, tt = (t) => {
|
|
9
9
|
const e = t.includes("-") ? t.replace(/-/g, "") : t;
|
|
10
10
|
return /^\d{8}$/.test(e) ? Number(e) : null;
|
|
11
11
|
}, Z = (t) => {
|
|
12
12
|
const e = String(Math.trunc(t)).padStart(8, "0");
|
|
13
13
|
return `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}`;
|
|
14
14
|
}, H = (t) => {
|
|
15
|
-
const e = t.getFullYear(), n = t.getMonth() + 1, a = t.getDate(),
|
|
16
|
-
return +`${e}${
|
|
17
|
-
},
|
|
15
|
+
const e = t.getFullYear(), n = t.getMonth() + 1, a = t.getDate(), i = String(n).padStart(2, "0"), r = String(a).padStart(2, "0");
|
|
16
|
+
return +`${e}${i}${r}`;
|
|
17
|
+
}, x = (t) => {
|
|
18
18
|
if (!t)
|
|
19
19
|
return null;
|
|
20
20
|
if (t instanceof Date)
|
|
21
21
|
return Number.isNaN(t.getTime()) ? null : H(t);
|
|
22
|
-
const e =
|
|
22
|
+
const e = tt(t);
|
|
23
23
|
if (e != null)
|
|
24
24
|
return e;
|
|
25
25
|
const n = new Date(t);
|
|
26
26
|
return Number.isNaN(n.getTime()) ? null : H(n);
|
|
27
|
-
},
|
|
28
|
-
const n = t ?
|
|
27
|
+
}, W = (t, e) => {
|
|
28
|
+
const n = t ? x(t) : null;
|
|
29
29
|
return n != null ? Z(n) : t || Z(e);
|
|
30
|
-
},
|
|
31
|
-
const e = Z(t), [n, a,
|
|
30
|
+
}, et = (t) => {
|
|
31
|
+
const e = Z(t), [n, a, i] = e.split("-").map(Number), o = new Date(n, (a || 1) - 1, i || 1).getDay();
|
|
32
32
|
return Number.isNaN(o) ? 0 : (o + 6) % 7;
|
|
33
|
-
},
|
|
33
|
+
}, R = (t) => Array.isArray(t) ? t.map((e) => {
|
|
34
34
|
if (!e || typeof e != "object")
|
|
35
35
|
return null;
|
|
36
36
|
const n = typeof e.start == "string" ? e.start : "", a = typeof e.end == "string" ? e.end : "";
|
|
37
37
|
return !n || !a ? null : { start: n, end: a };
|
|
38
|
-
}).filter((e) => !!e) : [],
|
|
38
|
+
}).filter((e) => !!e) : [], nt = (t) => {
|
|
39
39
|
const e = O(t.start), n = O(t.end);
|
|
40
40
|
if (e == null || n == null || n <= e)
|
|
41
41
|
return null;
|
|
42
|
-
const a = k(e),
|
|
42
|
+
const a = k(e), i = k(n);
|
|
43
43
|
return {
|
|
44
44
|
startMinutes: e,
|
|
45
45
|
endMinutes: n,
|
|
46
46
|
startLabel: a,
|
|
47
|
-
endLabel:
|
|
48
|
-
rangeLabel: `${a} - ${
|
|
47
|
+
endLabel: i,
|
|
48
|
+
rangeLabel: `${a} - ${i}`
|
|
49
49
|
};
|
|
50
|
-
},
|
|
51
|
-
const n = e.map(
|
|
50
|
+
}, at = (t, e) => {
|
|
51
|
+
const n = e.map(nt).filter((r) => !!r).sort((r, o) => r.startMinutes - o.startMinutes);
|
|
52
52
|
if (!n.length)
|
|
53
53
|
return {
|
|
54
54
|
day: t,
|
|
@@ -58,55 +58,55 @@ const k = (t) => {
|
|
|
58
58
|
closingMinutes: null,
|
|
59
59
|
summaryLabel: null
|
|
60
60
|
};
|
|
61
|
-
const a = n[0],
|
|
61
|
+
const a = n[0], i = n[n.length - 1];
|
|
62
62
|
return {
|
|
63
63
|
day: t,
|
|
64
64
|
isClosed: !1,
|
|
65
65
|
openingSlots: n,
|
|
66
66
|
openingMinutes: a.startMinutes,
|
|
67
|
-
closingMinutes:
|
|
67
|
+
closingMinutes: i.endMinutes,
|
|
68
68
|
summaryLabel: n.map((r) => r.rangeLabel).join(" / ")
|
|
69
69
|
};
|
|
70
|
-
},
|
|
71
|
-
const a = Array.isArray(t) ? t : [],
|
|
72
|
-
for (const
|
|
73
|
-
if (!
|
|
70
|
+
}, v = (t, e, n = {}) => {
|
|
71
|
+
const a = Array.isArray(t) ? t : [], i = Array.isArray(e) ? e : [], r = /* @__PURE__ */ new Map();
|
|
72
|
+
for (const s of i) {
|
|
73
|
+
if (!s || typeof s != "object")
|
|
74
74
|
continue;
|
|
75
|
-
const
|
|
76
|
-
|
|
75
|
+
const u = x(s.date);
|
|
76
|
+
u != null && r.set(u, R(s.openingSlots));
|
|
77
77
|
}
|
|
78
|
-
const o =
|
|
78
|
+
const o = x(n.referenceDate) ?? H(/* @__PURE__ */ new Date()), y = et(o), c = r.get(o);
|
|
79
79
|
let f, m;
|
|
80
|
-
for (const
|
|
81
|
-
if (!
|
|
80
|
+
for (const s of a) {
|
|
81
|
+
if (!s || typeof s != "object")
|
|
82
82
|
continue;
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
m || (m =
|
|
83
|
+
const u = x(s.startDate), N = x(s.endDate);
|
|
84
|
+
if (u == null || N == null) {
|
|
85
|
+
m || (m = s);
|
|
86
86
|
continue;
|
|
87
87
|
}
|
|
88
|
-
const
|
|
89
|
-
if (o >=
|
|
90
|
-
f =
|
|
88
|
+
const C = Math.min(u, N), F = Math.max(u, N);
|
|
89
|
+
if (o >= C && o <= F) {
|
|
90
|
+
f = s;
|
|
91
91
|
break;
|
|
92
92
|
}
|
|
93
|
-
m || (m =
|
|
93
|
+
m || (m = s);
|
|
94
94
|
}
|
|
95
|
-
const
|
|
96
|
-
for (const
|
|
97
|
-
if (!
|
|
95
|
+
const l = f ?? m ?? null, S = Array.isArray(l?.openingHours) ? l.openingHours : [], M = /* @__PURE__ */ new Map();
|
|
96
|
+
for (const s of S) {
|
|
97
|
+
if (!s || typeof s.day != "number")
|
|
98
98
|
continue;
|
|
99
|
-
const
|
|
100
|
-
M.set(
|
|
99
|
+
const u = (s.day % 7 + 7) % 7, N = R(s.openingSlots);
|
|
100
|
+
M.set(u, N);
|
|
101
101
|
}
|
|
102
102
|
c && M.set(y, c);
|
|
103
103
|
const b = [];
|
|
104
|
-
for (let
|
|
105
|
-
const
|
|
106
|
-
b.push(
|
|
104
|
+
for (let s = 0; s < 7; s += 1) {
|
|
105
|
+
const u = s, N = M.get(u) ?? [];
|
|
106
|
+
b.push(at(u, N));
|
|
107
107
|
}
|
|
108
|
-
const
|
|
109
|
-
if (!
|
|
108
|
+
const h = b.flatMap((s) => s.openingSlots);
|
|
109
|
+
if (!h.length)
|
|
110
110
|
return {
|
|
111
111
|
days: b,
|
|
112
112
|
defaultOpeningMinutes: 0,
|
|
@@ -114,68 +114,68 @@ const k = (t) => {
|
|
|
114
114
|
defaultOpeningLabel: "00:00",
|
|
115
115
|
defaultClosingLabel: "00:00",
|
|
116
116
|
defaultSummaryLabel: "",
|
|
117
|
-
season:
|
|
118
|
-
name: typeof
|
|
119
|
-
startDate:
|
|
120
|
-
endDate:
|
|
117
|
+
season: l ? {
|
|
118
|
+
name: typeof l.name == "string" ? l.name : void 0,
|
|
119
|
+
startDate: W(l.startDate, o),
|
|
120
|
+
endDate: W(l.endDate, o)
|
|
121
121
|
} : null
|
|
122
122
|
};
|
|
123
|
-
const
|
|
123
|
+
const w = h.reduce((s, u) => u.startMinutes < s.startMinutes ? u : s), B = h.reduce((s, u) => u.endMinutes > s.endMinutes ? u : s), g = b.find((s) => !s.isClosed && s.summaryLabel) ?? b[0];
|
|
124
124
|
return {
|
|
125
125
|
days: b,
|
|
126
|
-
defaultOpeningMinutes:
|
|
127
|
-
defaultClosingMinutes:
|
|
128
|
-
defaultOpeningLabel:
|
|
129
|
-
defaultClosingLabel:
|
|
130
|
-
defaultSummaryLabel: g.summaryLabel ?? `${
|
|
131
|
-
season:
|
|
132
|
-
name: typeof
|
|
133
|
-
startDate:
|
|
134
|
-
endDate:
|
|
126
|
+
defaultOpeningMinutes: w.startMinutes,
|
|
127
|
+
defaultClosingMinutes: B.endMinutes,
|
|
128
|
+
defaultOpeningLabel: w.startLabel,
|
|
129
|
+
defaultClosingLabel: B.endLabel,
|
|
130
|
+
defaultSummaryLabel: g.summaryLabel ?? `${w.startLabel} - ${B.endLabel}`,
|
|
131
|
+
season: l ? {
|
|
132
|
+
name: typeof l.name == "string" ? l.name : void 0,
|
|
133
|
+
startDate: W(l.startDate, o),
|
|
134
|
+
endDate: W(l.endDate, o)
|
|
135
135
|
} : null
|
|
136
136
|
};
|
|
137
137
|
}, G = (t) => {
|
|
138
|
-
const { timing: e, openingHours: n, openingHoursOverrides: a, timeZone:
|
|
138
|
+
const { timing: e, openingHours: n, openingHoursOverrides: a, timeZone: i } = t, r = e.slotIntervalMinutes, o = v(n, a), y = v(n, []), c = (d) => d?.dateString ? v(n, a, {
|
|
139
139
|
referenceDate: d.dateString
|
|
140
|
-
}) : o, f = (d) => d?.dateString ?
|
|
140
|
+
}) : o, f = (d) => d?.dateString ? v(n, [], {
|
|
141
141
|
referenceDate: d.dateString
|
|
142
|
-
}) : y, m = (d, D) => c(D).days.find((p) => p.day === d),
|
|
143
|
-
const p =
|
|
142
|
+
}) : y, m = (d, D) => c(D).days.find((p) => p.day === d), l = (d, D) => m(d, D)?.openingSlots ?? [], S = (d, D) => f(D).days.find((p) => p.day === d), M = (d, D) => S(d, D)?.openingSlots ?? [], b = (d, D, L) => {
|
|
143
|
+
const p = l(d, L);
|
|
144
144
|
if (!p.length)
|
|
145
145
|
return null;
|
|
146
146
|
const z = typeof D == "number" ? Math.max(D, 0) : Number.NEGATIVE_INFINITY;
|
|
147
147
|
for (const $ of p) {
|
|
148
|
-
const
|
|
149
|
-
if (
|
|
148
|
+
const T = $.startMinutes, Y = $.endMinutes - r;
|
|
149
|
+
if (Y < T)
|
|
150
150
|
continue;
|
|
151
|
-
const
|
|
152
|
-
if (!(
|
|
153
|
-
return
|
|
151
|
+
const X = Math.max(T, z), j = Math.ceil(X / r) * r;
|
|
152
|
+
if (!(j < T) && !(j > Y))
|
|
153
|
+
return j;
|
|
154
154
|
}
|
|
155
155
|
return null;
|
|
156
|
-
},
|
|
157
|
-
const L =
|
|
156
|
+
}, h = (d, D) => {
|
|
157
|
+
const L = l(d, D);
|
|
158
158
|
for (let p = L.length - 1; p >= 0; p -= 1) {
|
|
159
|
-
const z = L[p], $ = z.startMinutes,
|
|
160
|
-
if (!(
|
|
161
|
-
return
|
|
159
|
+
const z = L[p], $ = z.startMinutes, T = z.endMinutes - r;
|
|
160
|
+
if (!(T < $))
|
|
161
|
+
return T;
|
|
162
162
|
}
|
|
163
163
|
return null;
|
|
164
|
-
},
|
|
164
|
+
}, w = (d, D, L) => {
|
|
165
165
|
if (D == null)
|
|
166
166
|
return !1;
|
|
167
|
-
const p =
|
|
167
|
+
const p = l(d, L);
|
|
168
168
|
return p.length ? p.some((z) => {
|
|
169
|
-
const $ = z.startMinutes,
|
|
170
|
-
return
|
|
169
|
+
const $ = z.startMinutes, T = z.endMinutes - r;
|
|
170
|
+
return T < $ ? !1 : D >= $ && D <= T;
|
|
171
171
|
}) : !1;
|
|
172
|
-
}, g = o.days.find((d) => !d.isClosed && d.openingSlots.length)?.day ?? o.days[0]?.day ?? 0,
|
|
173
|
-
let F =
|
|
174
|
-
const
|
|
175
|
-
(!Number.isFinite(F) || F > _) && (F =
|
|
176
|
-
const
|
|
172
|
+
}, g = o.days.find((d) => !d.isClosed && d.openingSlots.length)?.day ?? o.days[0]?.day ?? 0, u = y.days.find((d) => !d.isClosed && d.openingSlots.length)?.day ?? y.days[0]?.day ?? 0, N = Math.ceil(Math.max(0, o.defaultOpeningMinutes) / r) * r, C = b(g) ?? N;
|
|
173
|
+
let F = C + r;
|
|
174
|
+
const Q = Math.floor(Math.max(0, o.defaultClosingMinutes - r) / r) * r, _ = h(g) ?? Q;
|
|
175
|
+
(!Number.isFinite(F) || F > _) && (F = C), Number.isFinite(F) || (F = Math.max(0, o.defaultOpeningMinutes));
|
|
176
|
+
const P = Math.max(0, F), V = Math.max(P, _);
|
|
177
177
|
return {
|
|
178
|
-
timeZone:
|
|
178
|
+
timeZone: i,
|
|
179
179
|
slotIntervalMinutes: r,
|
|
180
180
|
autoFillCutoffMinutes: e.autoFillCutoffMinutes,
|
|
181
181
|
pastToleranceMinutes: e.pastToleranceMinutes,
|
|
@@ -186,25 +186,25 @@ const k = (t) => {
|
|
|
186
186
|
defaultClosingLabel: o.defaultClosingLabel,
|
|
187
187
|
defaultSummaryLabel: o.defaultSummaryLabel,
|
|
188
188
|
defaultWeekday: g,
|
|
189
|
-
defaultSeasonWeekday:
|
|
190
|
-
defaultStartMinutes:
|
|
191
|
-
defaultStartTime: k(
|
|
192
|
-
defaultEndMinutes:
|
|
193
|
-
defaultEndTime: k(
|
|
189
|
+
defaultSeasonWeekday: u,
|
|
190
|
+
defaultStartMinutes: P,
|
|
191
|
+
defaultStartTime: k(P),
|
|
192
|
+
defaultEndMinutes: V,
|
|
193
|
+
defaultEndTime: k(V),
|
|
194
194
|
getDayHours: m,
|
|
195
|
-
getIntervalsForWeekday:
|
|
195
|
+
getIntervalsForWeekday: l,
|
|
196
196
|
getSeasonDayHours: S,
|
|
197
197
|
getSeasonIntervalsForWeekday: M,
|
|
198
198
|
getFirstStartMinutesForWeekday: b,
|
|
199
|
-
getLastStartMinutesForWeekday:
|
|
200
|
-
isValidStartMinutesForWeekday:
|
|
199
|
+
getLastStartMinutesForWeekday: h,
|
|
200
|
+
isValidStartMinutesForWeekday: w,
|
|
201
201
|
getNormalizedOpeningHours: c,
|
|
202
202
|
getSeasonNormalizedOpeningHours: f
|
|
203
203
|
};
|
|
204
|
-
},
|
|
204
|
+
}, rt = (t, e, n) => new Intl.DateTimeFormat("en-CA", {
|
|
205
205
|
timeZone: e,
|
|
206
206
|
...n
|
|
207
|
-
}).format(t),
|
|
207
|
+
}).format(t), E = (t, e) => {
|
|
208
208
|
const a = new Intl.DateTimeFormat("en-CA", {
|
|
209
209
|
timeZone: e,
|
|
210
210
|
hour12: !1,
|
|
@@ -213,59 +213,72 @@ const k = (t) => {
|
|
|
213
213
|
day: "2-digit",
|
|
214
214
|
hour: "2-digit",
|
|
215
215
|
minute: "2-digit"
|
|
216
|
-
}).formatToParts(t),
|
|
216
|
+
}).formatToParts(t), i = Object.fromEntries(a.map((c) => [c.type, c.value])), r = `${i.year}-${i.month}-${i.day}`, o = `${i.hour}:${i.minute}`, y = Number(i.hour) * 60 + Number(i.minute);
|
|
217
217
|
return { dateString: r, timeString: o, minutesFromMidnight: y };
|
|
218
218
|
}, q = (t) => {
|
|
219
219
|
const n = (t.includes("-") ? t.replace(/-/g, "") : t).match(/^(\d{4})(\d{2})(\d{2})$/);
|
|
220
220
|
if (!n)
|
|
221
221
|
return { year: Number.NaN, month: Number.NaN, day: Number.NaN };
|
|
222
|
-
const [, a,
|
|
223
|
-
return { year: Number(a), month: Number(
|
|
224
|
-
},
|
|
222
|
+
const [, a, i, r] = n;
|
|
223
|
+
return { year: Number(a), month: Number(i), day: Number(r) };
|
|
224
|
+
}, ct = (t, e) => {
|
|
225
|
+
if (!Number.isNaN(t.getTime()))
|
|
226
|
+
return E(t, e);
|
|
227
|
+
}, J = (t, e, n) => `${String(t).padStart(4, "0")}-${String(e).padStart(2, "0")}-${String(n).padStart(2, "0")}`, st = (t, e, n) => {
|
|
228
|
+
if (!Number.isInteger(t) || !Number.isInteger(e) || !Number.isInteger(n))
|
|
229
|
+
return !1;
|
|
230
|
+
const a = new Date(t, e - 1, n);
|
|
231
|
+
return a.getFullYear() === t && a.getMonth() === e - 1 && a.getDate() === n;
|
|
232
|
+
}, it = (t) => {
|
|
233
|
+
const { year: e, month: n, day: a } = q(t);
|
|
234
|
+
if (st(e, n, a))
|
|
235
|
+
return J(e, n, a);
|
|
236
|
+
}, ot = (t) => {
|
|
237
|
+
if (!(!t || Number.isNaN(t.getTime())))
|
|
238
|
+
return J(t.getFullYear(), t.getMonth() + 1, t.getDate());
|
|
239
|
+
}, mt = (t, e) => {
|
|
240
|
+
if (!Number.isNaN(t.getTime()))
|
|
241
|
+
return rt(t, e, { year: "numeric", month: "2-digit", day: "2-digit" });
|
|
242
|
+
}, ut = (t, e) => {
|
|
225
243
|
const n = new Date(t.getTime());
|
|
226
244
|
return n.setUTCDate(n.getUTCDate() + e), n;
|
|
227
|
-
},
|
|
228
|
-
const { dateString: n, minutesFromMidnight: a } =
|
|
229
|
-
if (Number.isNaN(
|
|
245
|
+
}, lt = (t, e) => {
|
|
246
|
+
const { dateString: n, minutesFromMidnight: a } = E(t, e.timeZone), i = I(n);
|
|
247
|
+
if (Number.isNaN(i.getTime()))
|
|
230
248
|
return { baseDate: /* @__PURE__ */ new Date(), minutesFromMidnight: a };
|
|
231
|
-
const r = new Date(
|
|
249
|
+
const r = new Date(i.getFullYear(), i.getMonth(), i.getDate());
|
|
232
250
|
return a >= e.autoFillCutoffMinutes && r.setDate(r.getDate() + 1), { baseDate: r, minutesFromMidnight: a };
|
|
233
|
-
},
|
|
234
|
-
const e = t.referenceDate ?? /* @__PURE__ */ new Date(), n = G(t.config), { baseDate: a } =
|
|
251
|
+
}, ft = (t) => {
|
|
252
|
+
const e = t.referenceDate ?? /* @__PURE__ */ new Date(), n = G(t.config), { baseDate: a } = lt(e, n), i = new Date(a.getTime()), r = new Date(a.getTime()), o = n.defaultStartTime, y = n.defaultEndTime, c = dt(
|
|
235
253
|
{
|
|
236
|
-
startDate:
|
|
254
|
+
startDate: i,
|
|
237
255
|
startTime: o,
|
|
238
256
|
endDate: r,
|
|
239
257
|
endTime: y
|
|
240
258
|
},
|
|
241
259
|
{ referenceDate: e, config: t.config }
|
|
242
|
-
), f = c.startDateString ?
|
|
260
|
+
), f = c.startDateString ? I(c.startDateString) : i, m = c.shouldResetEnd ? new Date(f.getTime()) : c.endDateString ? I(c.endDateString) : r, l = c.startTime ?? o, S = c.endTime ?? y;
|
|
243
261
|
return {
|
|
244
262
|
startDate: new Date(f.getTime()),
|
|
245
|
-
startTime:
|
|
263
|
+
startTime: l,
|
|
246
264
|
endDate: new Date(m.getTime()),
|
|
247
265
|
endTime: S
|
|
248
266
|
};
|
|
249
267
|
}, U = (t, e) => {
|
|
250
|
-
if (t)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
return !Number.isFinite(n) || !Number.isFinite(a) || !Number.isFinite(s) ? void 0 : `${String(n).padStart(4, "0")}-${String(a).padStart(2, "0")}-${String(s).padStart(2, "0")}`;
|
|
254
|
-
}
|
|
255
|
-
return at(t, e, { year: "numeric", month: "2-digit", day: "2-digit" });
|
|
256
|
-
}
|
|
257
|
-
}, W = (t) => {
|
|
268
|
+
if (t)
|
|
269
|
+
return typeof t == "string" ? it(t) : ot(t);
|
|
270
|
+
}, I = (t) => {
|
|
258
271
|
const { year: e, month: n, day: a } = q(t);
|
|
259
272
|
return new Date(e, n - 1, a);
|
|
260
|
-
},
|
|
261
|
-
const n =
|
|
273
|
+
}, A = (t) => {
|
|
274
|
+
const n = I(t).getDay();
|
|
262
275
|
return Number.isNaN(n) ? 0 : (n + 6) % 7;
|
|
263
|
-
},
|
|
264
|
-
const { dateString: a, minutesFromMidnight:
|
|
265
|
-
let c = Math.ceil(Math.max(y, 0) / r) * r, f = t, m = a,
|
|
276
|
+
}, K = (t, e, n) => {
|
|
277
|
+
const { dateString: a, minutesFromMidnight: i } = E(t, e.timeZone), r = e.slotIntervalMinutes, o = A(a), y = typeof n == "number" ? n : i + e.minBufferMinutes;
|
|
278
|
+
let c = Math.ceil(Math.max(y, 0) / r) * r, f = t, m = a, l = o, S = 0;
|
|
266
279
|
for (; S < 14; ) {
|
|
267
280
|
const M = e.getFirstStartMinutesForWeekday(
|
|
268
|
-
|
|
281
|
+
l,
|
|
269
282
|
S === 0 ? c : null,
|
|
270
283
|
{ dateString: m }
|
|
271
284
|
);
|
|
@@ -274,14 +287,14 @@ const k = (t) => {
|
|
|
274
287
|
dateString: m,
|
|
275
288
|
time: k(M)
|
|
276
289
|
};
|
|
277
|
-
S += 1, f =
|
|
290
|
+
S += 1, f = ut(f, 1), m = E(f, e.timeZone).dateString, l = A(m), c = 0;
|
|
278
291
|
}
|
|
279
292
|
return {
|
|
280
293
|
dateString: a,
|
|
281
294
|
time: k(e.defaultStartMinutes)
|
|
282
295
|
};
|
|
283
|
-
},
|
|
284
|
-
const n = e.referenceDate ?? /* @__PURE__ */ new Date(), a = G(e.config),
|
|
296
|
+
}, dt = (t, e) => {
|
|
297
|
+
const n = e.referenceDate ?? /* @__PURE__ */ new Date(), a = G(e.config), i = e.toleranceMinutes ?? a.pastToleranceMinutes, r = U(t.startDate, a.timeZone), o = U(t.endDate, a.timeZone), y = t.startTime ?? null;
|
|
285
298
|
if (!r)
|
|
286
299
|
return {
|
|
287
300
|
startDateString: r,
|
|
@@ -291,59 +304,64 @@ const k = (t) => {
|
|
|
291
304
|
wasAdjusted: !1,
|
|
292
305
|
shouldResetEnd: !1
|
|
293
306
|
};
|
|
294
|
-
const c =
|
|
295
|
-
let f = r, m = y,
|
|
307
|
+
const c = E(n, a.timeZone);
|
|
308
|
+
let f = r, m = y, l, S = !1;
|
|
296
309
|
if (r < c.dateString) {
|
|
297
|
-
const g =
|
|
298
|
-
f = g.dateString, m = g.time,
|
|
310
|
+
const g = K(n, a);
|
|
311
|
+
f = g.dateString, m = g.time, l = "start_date_in_past", S = !0;
|
|
299
312
|
} else if (r === c.dateString) {
|
|
300
|
-
const g = O(y),
|
|
301
|
-
if (g == null || g <
|
|
302
|
-
const
|
|
303
|
-
f =
|
|
313
|
+
const g = O(y), s = c.minutesFromMidnight - i;
|
|
314
|
+
if (g == null || g < s) {
|
|
315
|
+
const u = K(n, a);
|
|
316
|
+
f = u.dateString, m = u.time, l = "start_time_in_past", S = !0;
|
|
304
317
|
}
|
|
305
318
|
}
|
|
306
319
|
const M = f ?? r;
|
|
307
320
|
if (M) {
|
|
308
|
-
const g =
|
|
309
|
-
if (!a.isValidStartMinutesForWeekday(g,
|
|
321
|
+
const g = A(M), s = O(m);
|
|
322
|
+
if (!a.isValidStartMinutesForWeekday(g, s, {
|
|
310
323
|
dateString: M
|
|
311
324
|
})) {
|
|
312
|
-
const
|
|
325
|
+
const u = a.getFirstStartMinutesForWeekday(g, null, {
|
|
313
326
|
dateString: M
|
|
314
327
|
});
|
|
315
|
-
if (typeof
|
|
316
|
-
m = k(
|
|
328
|
+
if (typeof u == "number")
|
|
329
|
+
m = k(u), S = !0;
|
|
317
330
|
else {
|
|
318
|
-
const
|
|
319
|
-
f =
|
|
331
|
+
const N = I(M), C = K(N, a, 0);
|
|
332
|
+
f = C.dateString, m = C.time, S = !0;
|
|
320
333
|
}
|
|
321
334
|
}
|
|
322
335
|
}
|
|
323
|
-
const b = S,
|
|
336
|
+
const b = S, h = b ? void 0 : o, w = (() => {
|
|
324
337
|
const g = f ?? r;
|
|
325
338
|
if (!g)
|
|
326
339
|
return a.defaultEndTime;
|
|
327
|
-
const
|
|
328
|
-
return typeof
|
|
329
|
-
})(),
|
|
340
|
+
const s = A(g), u = a.getLastStartMinutesForWeekday(s, { dateString: g });
|
|
341
|
+
return typeof u == "number" ? k(u) : a.defaultEndTime;
|
|
342
|
+
})(), B = b ? w : t.endTime ?? null;
|
|
330
343
|
return {
|
|
331
344
|
startDateString: f,
|
|
332
345
|
startTime: m,
|
|
333
|
-
endDateString:
|
|
334
|
-
endTime:
|
|
346
|
+
endDateString: h,
|
|
347
|
+
endTime: B,
|
|
335
348
|
wasAdjusted: S,
|
|
336
|
-
adjustmentReason:
|
|
349
|
+
adjustmentReason: l,
|
|
337
350
|
shouldResetEnd: b
|
|
338
351
|
};
|
|
339
352
|
};
|
|
340
353
|
export {
|
|
341
|
-
|
|
342
|
-
|
|
354
|
+
dt as adjustBookingPeriod,
|
|
355
|
+
I as businessDateStringToDate,
|
|
356
|
+
ot as calendarDateToBusinessDateString,
|
|
343
357
|
G as createBookingPeriodConstants,
|
|
344
358
|
U as dateToBusinessDateString,
|
|
345
|
-
|
|
359
|
+
ft as getDefaultBookingPeriod,
|
|
360
|
+
A as getWeekdayFromDateString,
|
|
361
|
+
mt as instantToBusinessDateString,
|
|
362
|
+
ct as instantToBusinessDateTimeParts,
|
|
346
363
|
k as minutesToTimeString,
|
|
347
|
-
|
|
364
|
+
it as normalizeBusinessDateString,
|
|
365
|
+
v as normalizeOpeningHours,
|
|
348
366
|
O as parseTimeToMinutes
|
|
349
367
|
};
|
package/dist/lib/booking.d.ts
CHANGED
|
@@ -14,6 +14,9 @@ export type StorefrontBookingParams = {
|
|
|
14
14
|
type BookingSearchStorage = Pick<Storage, "getItem" | "removeItem" | "setItem"> | null | undefined;
|
|
15
15
|
export declare const TIME_OPTIONS: string[];
|
|
16
16
|
export declare const getDefaultBookingParams: (now?: Date) => StorefrontBookingParams;
|
|
17
|
+
export declare const createBookingPeriodConfigFromBookingEngineConfiguration: (bookingEngine: StorefrontConfiguration["bookingEngine"], options?: {
|
|
18
|
+
sameDayCutoff?: string;
|
|
19
|
+
}) => BookingPeriodConfig;
|
|
17
20
|
export declare const createBookingPeriodConfigFromStorefrontConfiguration: (storefrontConfiguration: StorefrontConfiguration) => BookingPeriodConfig;
|
|
18
21
|
export declare const getDefaultBookingParamsForStorefrontConfiguration: (storefrontConfiguration: StorefrontConfiguration, now?: Date) => StorefrontBookingParams;
|
|
19
22
|
export declare const getBookingParamsFromSearch: (searchParams: URLSearchParams, fallback?: Partial<StorefrontBookingParams>) => StorefrontBookingParams;
|