@loczer/storefront-sdk 0.150.0 → 0.151.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.
@@ -110,6 +110,14 @@ export declare const createBookingPeriodConstants: (config: BookingPeriodConfig)
110
110
  dateString?: string;
111
111
  }) => NormalizedOpeningHours;
112
112
  };
113
+ export declare const instantToBusinessDateTimeParts: (date: Date, timeZone: string) => {
114
+ dateString: string;
115
+ timeString: string;
116
+ minutesFromMidnight: number;
117
+ } | undefined;
118
+ export declare const normalizeBusinessDateString: (dateString: string) => string | undefined;
119
+ export declare const calendarDateToBusinessDateString: (date: Date | null | undefined) => string | undefined;
120
+ export declare const instantToBusinessDateString: (date: Date, timeZone: string) => string | undefined;
113
121
  export interface DefaultBookingPeriod {
114
122
  startDate: Date;
115
123
  startTime: string;
@@ -123,6 +131,7 @@ export interface DefaultBookingPeriodOptions {
123
131
  export declare const getDefaultBookingPeriod: (options: DefaultBookingPeriodOptions) => DefaultBookingPeriod;
124
132
  export declare const dateToBusinessDateString: (date: Date | string | null | undefined, timeZone: string) => string | undefined;
125
133
  export declare const businessDateStringToDate: (dateString: string) => Date;
134
+ export declare const getWeekdayFromDateString: (dateString: string) => Weekday;
126
135
  export interface BookingPeriodInput {
127
136
  startDate?: Date | string | null;
128
137
  startTime?: string | null;
@@ -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), s = Number(n);
7
- return !Number.isFinite(a) || !Number.isFinite(s) || a < 0 || s < 0 ? null : a * 60 + s;
8
- }, X = (t) => {
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(), s = String(n).padStart(2, "0"), r = String(a).padStart(2, "0");
16
- return +`${e}${s}${r}`;
17
- }, E = (t) => {
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 = X(t);
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
- }, B = (t, e) => {
28
- const n = t ? E(t) : null;
27
+ }, W = (t, e) => {
28
+ const n = t ? x(t) : null;
29
29
  return n != null ? Z(n) : t || Z(e);
30
- }, tt = (t) => {
31
- const e = Z(t), [n, a, s] = e.split("-").map(Number), o = new Date(n, (a || 1) - 1, s || 1).getDay();
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
- }, Y = (t) => Array.isArray(t) ? t.map((e) => {
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) : [], et = (t) => {
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), s = k(n);
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: s,
48
- rangeLabel: `${a} - ${s}`
47
+ endLabel: i,
48
+ rangeLabel: `${a} - ${i}`
49
49
  };
50
- }, nt = (t, e) => {
51
- const n = e.map(et).filter((r) => !!r).sort((r, o) => r.startMinutes - o.startMinutes);
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], s = n[n.length - 1];
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: s.endMinutes,
67
+ closingMinutes: i.endMinutes,
68
68
  summaryLabel: n.map((r) => r.rangeLabel).join(" / ")
69
69
  };
70
- }, I = (t, e, n = {}) => {
71
- const a = Array.isArray(t) ? t : [], s = Array.isArray(e) ? e : [], r = /* @__PURE__ */ new Map();
72
- for (const i of s) {
73
- if (!i || typeof i != "object")
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 l = E(i.date);
76
- l != null && r.set(l, Y(i.openingSlots));
75
+ const u = x(s.date);
76
+ u != null && r.set(u, R(s.openingSlots));
77
77
  }
78
- const o = E(n.referenceDate) ?? H(/* @__PURE__ */ new Date()), y = tt(o), c = r.get(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 i of a) {
81
- if (!i || typeof i != "object")
80
+ for (const s of a) {
81
+ if (!s || typeof s != "object")
82
82
  continue;
83
- const l = E(i.startDate), h = E(i.endDate);
84
- if (l == null || h == null) {
85
- m || (m = i);
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 w = Math.min(l, h), F = Math.max(l, h);
89
- if (o >= w && o <= F) {
90
- f = i;
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 = i);
93
+ m || (m = s);
94
94
  }
95
- const u = f ?? m ?? null, S = Array.isArray(u?.openingHours) ? u.openingHours : [], M = /* @__PURE__ */ new Map();
96
- for (const i of S) {
97
- if (!i || typeof i.day != "number")
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 l = (i.day % 7 + 7) % 7, h = Y(i.openingSlots);
100
- M.set(l, h);
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 i = 0; i < 7; i += 1) {
105
- const l = i, h = M.get(l) ?? [];
106
- b.push(nt(l, h));
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 T = b.flatMap((i) => i.openingSlots);
109
- if (!T.length)
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: u ? {
118
- name: typeof u.name == "string" ? u.name : void 0,
119
- startDate: B(u.startDate, o),
120
- endDate: B(u.endDate, o)
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 C = T.reduce((i, l) => l.startMinutes < i.startMinutes ? l : i), x = T.reduce((i, l) => l.endMinutes > i.endMinutes ? l : i), g = b.find((i) => !i.isClosed && i.summaryLabel) ?? b[0];
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: C.startMinutes,
127
- defaultClosingMinutes: x.endMinutes,
128
- defaultOpeningLabel: C.startLabel,
129
- defaultClosingLabel: x.endLabel,
130
- defaultSummaryLabel: g.summaryLabel ?? `${C.startLabel} - ${x.endLabel}`,
131
- season: u ? {
132
- name: typeof u.name == "string" ? u.name : void 0,
133
- startDate: B(u.startDate, o),
134
- endDate: B(u.endDate, o)
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: s } = t, r = e.slotIntervalMinutes, o = I(n, a), y = I(n, []), c = (d) => d?.dateString ? I(n, a, {
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 ? I(n, [], {
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), u = (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 = u(d, L);
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 N = $.startMinutes, V = $.endMinutes - r;
149
- if (V < N)
148
+ const T = $.startMinutes, Y = $.endMinutes - r;
149
+ if (Y < T)
150
150
  continue;
151
- const Q = Math.max(N, z), K = Math.ceil(Q / r) * r;
152
- if (!(K < N) && !(K > V))
153
- return K;
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
- }, T = (d, D) => {
157
- const L = u(d, D);
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, N = z.endMinutes - r;
160
- if (!(N < $))
161
- return N;
159
+ const z = L[p], $ = z.startMinutes, T = z.endMinutes - r;
160
+ if (!(T < $))
161
+ return T;
162
162
  }
163
163
  return null;
164
- }, C = (d, D, L) => {
164
+ }, w = (d, D, L) => {
165
165
  if (D == null)
166
166
  return !1;
167
- const p = u(d, L);
167
+ const p = l(d, L);
168
168
  return p.length ? p.some((z) => {
169
- const $ = z.startMinutes, N = z.endMinutes - r;
170
- return N < $ ? !1 : D >= $ && D <= N;
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, l = y.days.find((d) => !d.isClosed && d.openingSlots.length)?.day ?? y.days[0]?.day ?? 0, h = Math.ceil(Math.max(0, o.defaultOpeningMinutes) / r) * r, w = b(g) ?? h;
173
- let F = w + r;
174
- const J = Math.floor(Math.max(0, o.defaultClosingMinutes - r) / r) * r, _ = T(g) ?? J;
175
- (!Number.isFinite(F) || F > _) && (F = w), Number.isFinite(F) || (F = Math.max(0, o.defaultOpeningMinutes));
176
- const j = Math.max(0, F), R = Math.max(j, _);
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: s,
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: l,
190
- defaultStartMinutes: j,
191
- defaultStartTime: k(j),
192
- defaultEndMinutes: R,
193
- defaultEndTime: k(R),
189
+ defaultSeasonWeekday: u,
190
+ defaultStartMinutes: P,
191
+ defaultStartTime: k(P),
192
+ defaultEndMinutes: V,
193
+ defaultEndTime: k(V),
194
194
  getDayHours: m,
195
- getIntervalsForWeekday: u,
195
+ getIntervalsForWeekday: l,
196
196
  getSeasonDayHours: S,
197
197
  getSeasonIntervalsForWeekday: M,
198
198
  getFirstStartMinutesForWeekday: b,
199
- getLastStartMinutesForWeekday: T,
200
- isValidStartMinutesForWeekday: C,
199
+ getLastStartMinutesForWeekday: h,
200
+ isValidStartMinutesForWeekday: w,
201
201
  getNormalizedOpeningHours: c,
202
202
  getSeasonNormalizedOpeningHours: f
203
203
  };
204
- }, at = (t, e, n) => new Intl.DateTimeFormat("en-CA", {
204
+ }, rt = (t, e, n) => new Intl.DateTimeFormat("en-CA", {
205
205
  timeZone: e,
206
206
  ...n
207
- }).format(t), A = (t, e) => {
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), s = Object.fromEntries(a.map((c) => [c.type, c.value])), r = `${s.year}-${s.month}-${s.day}`, o = `${s.hour}:${s.minute}`, y = Number(s.hour) * 60 + Number(s.minute);
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, s, r] = n;
223
- return { year: Number(a), month: Number(s), day: Number(r) };
224
- }, rt = (t, e) => {
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
- }, st = (t, e) => {
228
- const { dateString: n, minutesFromMidnight: a } = A(t, e.timeZone), s = W(n);
229
- if (Number.isNaN(s.getTime()))
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(s.getFullYear(), s.getMonth(), s.getDate());
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
- }, ot = (t) => {
234
- const e = t.referenceDate ?? /* @__PURE__ */ new Date(), n = G(t.config), { baseDate: a } = st(e, n), s = new Date(a.getTime()), r = new Date(a.getTime()), o = n.defaultStartTime, y = n.defaultEndTime, c = it(
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: s,
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 ? W(c.startDateString) : s, m = c.shouldResetEnd ? new Date(f.getTime()) : c.endDateString ? W(c.endDateString) : r, u = c.startTime ?? o, S = c.endTime ?? y;
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: u,
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
- if (typeof t == "string") {
252
- const { year: n, month: a, day: s } = q(t);
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
- }, v = (t) => {
261
- const n = W(t).getDay();
273
+ }, A = (t) => {
274
+ const n = I(t).getDay();
262
275
  return Number.isNaN(n) ? 0 : (n + 6) % 7;
263
- }, P = (t, e, n) => {
264
- const { dateString: a, minutesFromMidnight: s } = A(t, e.timeZone), r = e.slotIntervalMinutes, o = v(a), y = typeof n == "number" ? n : s + e.minBufferMinutes;
265
- let c = Math.ceil(Math.max(y, 0) / r) * r, f = t, m = a, u = o, S = 0;
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
- u,
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 = rt(f, 1), m = A(f, e.timeZone).dateString, u = v(m), c = 0;
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
- }, it = (t, e) => {
284
- const n = e.referenceDate ?? /* @__PURE__ */ new Date(), a = G(e.config), s = e.toleranceMinutes ?? a.pastToleranceMinutes, r = U(t.startDate, a.timeZone), o = U(t.endDate, a.timeZone), y = t.startTime ?? null;
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 = A(n, a.timeZone);
295
- let f = r, m = y, u, S = !1;
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 = P(n, a);
298
- f = g.dateString, m = g.time, u = "start_date_in_past", S = !0;
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), i = c.minutesFromMidnight - s;
301
- if (g == null || g < i) {
302
- const l = P(n, a);
303
- f = l.dateString, m = l.time, u = "start_time_in_past", S = !0;
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 = v(M), i = O(m);
309
- if (!a.isValidStartMinutesForWeekday(g, i, {
321
+ const g = A(M), s = O(m);
322
+ if (!a.isValidStartMinutesForWeekday(g, s, {
310
323
  dateString: M
311
324
  })) {
312
- const l = a.getFirstStartMinutesForWeekday(g, null, {
325
+ const u = a.getFirstStartMinutesForWeekday(g, null, {
313
326
  dateString: M
314
327
  });
315
- if (typeof l == "number")
316
- m = k(l), S = !0;
328
+ if (typeof u == "number")
329
+ m = k(u), S = !0;
317
330
  else {
318
- const h = W(M), w = P(h, a, 0);
319
- f = w.dateString, m = w.time, S = !0;
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, T = b ? void 0 : o, C = (() => {
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 i = v(g), l = a.getLastStartMinutesForWeekday(i, { dateString: g });
328
- return typeof l == "number" ? k(l) : a.defaultEndTime;
329
- })(), x = b ? C : t.endTime ?? null;
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: T,
334
- endTime: x,
346
+ endDateString: h,
347
+ endTime: B,
335
348
  wasAdjusted: S,
336
- adjustmentReason: u,
349
+ adjustmentReason: l,
337
350
  shouldResetEnd: b
338
351
  };
339
352
  };
340
353
  export {
341
- it as adjustBookingPeriod,
342
- W as businessDateStringToDate,
354
+ dt as adjustBookingPeriod,
355
+ I as businessDateStringToDate,
356
+ ot as calendarDateToBusinessDateString,
343
357
  G as createBookingPeriodConstants,
344
358
  U as dateToBusinessDateString,
345
- ot as getDefaultBookingPeriod,
359
+ ft as getDefaultBookingPeriod,
360
+ A as getWeekdayFromDateString,
361
+ mt as instantToBusinessDateString,
362
+ ct as instantToBusinessDateTimeParts,
346
363
  k as minutesToTimeString,
347
- I as normalizeOpeningHours,
364
+ it as normalizeBusinessDateString,
365
+ v as normalizeOpeningHours,
348
366
  O as parseTimeToMinutes
349
367
  };
@@ -7,6 +7,40 @@ export declare const requestCheckoutItemSchema: z.ZodObject<{
7
7
  quantity: z.ZodNumber;
8
8
  }, z.core.$strip>;
9
9
  export type RequestCheckoutItem = z.infer<typeof requestCheckoutItemSchema>;
10
+ export declare const requestBaseSchema: z.ZodObject<{
11
+ storeSlug: z.ZodString;
12
+ schedule: z.ZodObject<{
13
+ startDate: z.ZodString;
14
+ endDate: z.ZodString;
15
+ startTime: z.ZodString;
16
+ endTime: z.ZodString;
17
+ }, z.core.$strip>;
18
+ fulfillment: z.ZodDefault<z.ZodEnum<{
19
+ pickup: "pickup";
20
+ delivery: "delivery";
21
+ }>>;
22
+ startAddress: z.ZodOptional<z.ZodString>;
23
+ endAddress: z.ZodOptional<z.ZodString>;
24
+ couponCode: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
25
+ couponAutoApplied: z.ZodOptional<z.ZodBoolean>;
26
+ customer: z.ZodObject<{
27
+ fullName: z.ZodString;
28
+ email: z.ZodString;
29
+ phone: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
30
+ notes: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
31
+ }, z.core.$strip>;
32
+ items: z.ZodArray<z.ZodObject<{
33
+ kind: any;
34
+ productId: z.ZodString;
35
+ productVariantId: z.ZodOptional<z.ZodString>;
36
+ quantity: z.ZodNumber;
37
+ }, z.core.$strip>>;
38
+ nowIso: z.ZodOptional<z.ZodString>;
39
+ }, z.core.$strip>;
40
+ export declare const requestDeliveryRefinement: (payload: {
41
+ fulfillment?: string;
42
+ startAddress?: string;
43
+ }, ctx: z.RefinementCtx) => void;
10
44
  export declare const requestSchema: z.ZodObject<{
11
45
  storeSlug: z.ZodString;
12
46
  schedule: z.ZodObject<{
@@ -1,6 +1,6 @@
1
1
  import { z as t } from "zod";
2
- import { bookingScheduleInputSchema as o } from "../chunks/pkg/booking-engine/dist/schemas/cart-inputs-DYgEGJ5M.js";
3
- import { productKindSchema as e } from "../chunks/pkg/booking-engine/dist/models/Product.shared-BiDGmurZ.js";
2
+ import { bookingScheduleInputSchema as r } from "../chunks/pkg/booking-engine/dist/schemas/cart-inputs-DYgEGJ5M.js";
3
+ import { productKindSchema as o } from "../chunks/pkg/booking-engine/dist/models/Product.shared-BiDGmurZ.js";
4
4
  import "../chunks/pkg/booking-engine/dist/models/LocalizedString--6q77SPQ.js";
5
5
  import "../chunks/pkg/booking-engine/dist/models/Price-BlFRDHXV.js";
6
6
  import "../chunks/pkg/booking-engine/dist/schemas/base-asset-GJ9eIvIL.js";
@@ -11,14 +11,14 @@ import "../chunks/pkg/booking-engine/dist/schemas/shop-opening-hours-B47MMaoD.js
11
11
  import "../chunks/pkg/booking-engine/dist/schemas/public-booking-engine-configuration-C9VB-WhU.js";
12
12
  import "../chunks/pkg/booking-engine/dist/schemas/booking-engine-configuration-CnBdp3jk.js";
13
13
  import { storefrontFulfillmentModeSchema as s } from "../storefrontSchemas.js";
14
- const k = "/api/public/storefront/checkout/submit", n = t.object({
15
- kind: e,
14
+ const x = "/api/public/storefront/checkout/submit", n = t.object({
15
+ kind: o,
16
16
  productId: t.string().trim().min(1),
17
17
  productVariantId: t.string().trim().min(1).optional(),
18
18
  quantity: t.number().int().positive()
19
- }), x = t.object({
19
+ }), m = t.object({
20
20
  storeSlug: t.string().trim().min(1).toLowerCase(),
21
- schedule: o,
21
+ schedule: r,
22
22
  fulfillment: s.default("pickup"),
23
23
  startAddress: t.string().trim().max(500).optional(),
24
24
  endAddress: t.string().trim().max(500).optional(),
@@ -34,13 +34,13 @@ const k = "/api/public/storefront/checkout/submit", n = t.object({
34
34
  // Test-only clock override: the server honors it outside production and
35
35
  // always uses its own clock in production.
36
36
  nowIso: t.string().datetime({ offset: !0 }).optional()
37
- }).superRefine((i, r) => {
38
- i.fulfillment === "delivery" && (i.startAddress?.trim() || r.addIssue({
37
+ }), a = (e, i) => {
38
+ e.fulfillment === "delivery" && (e.startAddress?.trim() || i.addIssue({
39
39
  code: t.ZodIssueCode.custom,
40
40
  message: "Delivery start address is required.",
41
41
  path: ["startAddress"]
42
42
  }));
43
- }), A = t.object({
43
+ }, A = m.superRefine(a), j = t.object({
44
44
  success: t.boolean(),
45
45
  message: t.string().optional(),
46
46
  checkout: t.object({
@@ -52,8 +52,10 @@ const k = "/api/public/storefront/checkout/submit", n = t.object({
52
52
  }).optional()
53
53
  });
54
54
  export {
55
- k as ROUTE,
55
+ x as ROUTE,
56
+ m as requestBaseSchema,
56
57
  n as requestCheckoutItemSchema,
57
- x as requestSchema,
58
- A as responseSchema
58
+ a as requestDeliveryRefinement,
59
+ A as requestSchema,
60
+ j as responseSchema
59
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loczer/storefront-sdk",
3
- "version": "0.150.0",
3
+ "version": "0.151.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"