@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.
Files changed (28) hide show
  1. package/dist/StorefrontProvider.d.ts +20 -0
  2. package/dist/booking-period-time-slots.d.ts +23 -38
  3. package/dist/booking-period.d.ts +20 -0
  4. package/dist/booking.d.ts +18 -0
  5. package/dist/checkoutSubmit.d.ts +36 -0
  6. package/dist/chunks/pkg/booking-engine/dist/schemas/{booking-engine-configuration-CnBdp3jk.js → booking-engine-configuration-BKlzwJJX.js} +20 -19
  7. package/dist/chunks/pkg/booking-engine/dist/schemas/{cart-inputs-DYgEGJ5M.js → cart-inputs-ByBK0IVJ.js} +2 -2
  8. package/dist/chunks/pkg/booking-engine/dist/schemas/{public-booking-engine-configuration-C9VB-WhU.js → public-booking-engine-configuration-DKoak4s5.js} +2 -2
  9. package/dist/chunks/pkg/booking-engine/dist/schemas/shop-opening-hours-DqNWstqT.js +51 -0
  10. package/dist/components/BookingPeriodSelector/useBookingPeriodController.js +76 -80
  11. package/dist/index.js +308 -298
  12. package/dist/lib/booking-period-time-slots.d.ts +0 -31
  13. package/dist/lib/booking-period-time-slots.js +122 -221
  14. package/dist/lib/booking-period.d.ts +14 -0
  15. package/dist/lib/booking-period.js +168 -150
  16. package/dist/lib/booking.d.ts +3 -0
  17. package/dist/lib/booking.js +102 -89
  18. package/dist/lib/checkoutSubmit.d.ts +34 -0
  19. package/dist/lib/checkoutSubmit.js +17 -15
  20. package/dist/lib/storefrontTimeSlots.d.ts +43 -0
  21. package/dist/lib/storefrontTimeSlots.js +26 -0
  22. package/dist/storefront.css +1 -1
  23. package/dist/storefrontSchemas.d.ts +8 -0
  24. package/dist/storefrontSchemas.js +4 -4
  25. package/dist/storefrontTimeSlots.d.ts +53 -0
  26. package/dist/whatsapp.d.ts +8 -0
  27. package/package.json +1 -1
  28. package/dist/chunks/pkg/booking-engine/dist/schemas/shop-opening-hours-B47MMaoD.js +0 -45
@@ -13,37 +13,6 @@ export type TimeSlot = TimeSlotBase & {
13
13
  isDisabled: boolean;
14
14
  disabledReason?: string;
15
15
  };
16
- export interface DisabledTimeSlotRule {
17
- startMinutes?: number;
18
- endMinutes?: number;
19
- values?: string[];
20
- reason?: string;
21
- dates?: string[];
22
- weekdays?: number[];
23
- }
24
- export interface DisabledTimeSlotRuleContext {
25
- date?: string;
26
- slotInterval: number;
27
- }
28
- export declare const staticDisabledTimeSlotRules: DisabledTimeSlotRule[];
29
- export declare const getDisabledTimeSlotRulesSync: (_context: DisabledTimeSlotRuleContext) => DisabledTimeSlotRule[];
30
- export declare const getDisabledTimeSlotRules: (context: DisabledTimeSlotRuleContext) => Promise<DisabledTimeSlotRule[]>;
31
- export interface ExtraTimeSlotRule {
32
- startMinutes: number;
33
- endMinutes?: number;
34
- extraAmount: number;
35
- dates?: string[];
36
- weekdays?: number[];
37
- journeyTypes?: JourneyType[];
38
- }
39
- export interface ExtraTimeSlotRuleContext {
40
- date?: string;
41
- slotInterval: number;
42
- journeyType?: JourneyType;
43
- }
44
- export declare const staticExtraTimeSlotRules: ExtraTimeSlotRule[];
45
- export declare const getExtraTimeSlotRulesSync: (_context: ExtraTimeSlotRuleContext) => ExtraTimeSlotRule[];
46
- export declare const getExtraTimeSlotRules: (context: ExtraTimeSlotRuleContext) => Promise<ExtraTimeSlotRule[]>;
47
16
  export declare const toBusinessDateString: (date: string) => string;
48
17
  export declare const getBookingPeriodTimeSlotsSync: (bookingPeriodConfig: BookingPeriodConfig, { date, }?: {
49
18
  date?: string;
@@ -1,273 +1,174 @@
1
- import * as z from "./booking-period.js";
2
- const { businessDateStringToDate: A, createBookingPeriodConstants: B, minutesToTimeString: y } = z, C = [], E = (e) => [], H = async (e) => E(), L = [
3
- {
4
- startMinutes: 1140,
5
- extraAmount: 1e3,
6
- journeyTypes: ["end"]
7
- },
8
- {
9
- startMinutes: 1170,
10
- extraAmount: 2e3,
11
- journeyTypes: ["end"]
12
- }
13
- ], w = (e) => [], P = async (e) => w(), M = /^\d{4}-\d{2}-\d{2}$/, N = "closed", W = (e) => {
14
- if (!M.test(e))
1
+ import * as $ from "./booking-period.js";
2
+ const { businessDateStringToDate: A, createBookingPeriodConstants: W, minutesToTimeString: g } = $, p = /^\d{4}-\d{2}-\d{2}$/, w = "closed", D = (t) => {
3
+ if (!p.test(t))
15
4
  throw new Error("Invalid time slot date parameter format");
16
- return e;
17
- }, k = (e) => M.test(e) ? e : /^\d{8}$/.test(e) ? `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}` : e, D = (e) => {
18
- if (!e)
5
+ return t;
6
+ }, v = (t) => p.test(t) ? t : /^\d{8}$/.test(t) ? `${t.slice(0, 4)}-${t.slice(4, 6)}-${t.slice(6, 8)}` : t, z = (t) => {
7
+ if (!t)
19
8
  return { dateString: void 0, weekday: void 0 };
20
- const t = k(e);
9
+ const e = v(t);
21
10
  let s;
22
11
  try {
23
- s = W(t);
12
+ s = D(e);
24
13
  } catch {
25
14
  return { dateString: void 0, weekday: void 0 };
26
15
  }
27
- const i = A(s);
28
- return Number.isNaN(i.getTime()) ? { dateString: void 0, weekday: void 0 } : { dateString: s, weekday: (i.getDay() + 6) % 7 };
29
- }, v = (e, t, s, i) => {
30
- const { dateString: r, weekday: l } = D(e), n = t.getNormalizedOpeningHours({
16
+ const n = A(s);
17
+ return Number.isNaN(n.getTime()) ? { dateString: void 0, weekday: void 0 } : { dateString: s, weekday: (n.getDay() + 6) % 7 };
18
+ }, E = (t, e, s, n) => {
19
+ const { dateString: r, weekday: o } = z(t), a = e.getNormalizedOpeningHours({
31
20
  dateString: r
32
- }), o = typeof l == "number" ? l : n.days.find((d) => !d.isClosed && d.openingSlots.length)?.day ?? t.defaultWeekday, a = t.getIntervalsForWeekday(o, {
21
+ }), l = typeof o == "number" ? o : a.days.find((c) => !c.isClosed && c.openingSlots.length)?.day ?? e.defaultWeekday, d = e.getIntervalsForWeekday(l, {
33
22
  dateString: r
34
23
  });
35
- if (i?.fillGaps) {
36
- if (!a.length)
24
+ if (n?.fillGaps) {
25
+ if (!d.length)
37
26
  return [];
38
- const d = a.reduce((u, S) => S.startMinutes < u.startMinutes ? S : u), g = a.reduce((u, S) => S.endMinutes > u.endMinutes ? S : u), m = [], f = Math.ceil(d.startMinutes / s) * s, b = Math.max(f, g.endMinutes - s);
39
- if (b < f)
40
- return m;
41
- for (let u = f; u <= b; u += s) {
42
- const S = y(u), T = u + s, $ = y(T);
43
- m.push({
44
- value: S,
45
- label: `${S} - ${$}`,
46
- startMinutes: u,
47
- endMinutes: T,
27
+ const c = d.reduce((i, u) => u.startMinutes < i.startMinutes ? u : i), x = d.reduce((i, u) => u.endMinutes > i.endMinutes ? u : i), S = [], m = Math.ceil(c.startMinutes / s) * s, M = Math.max(m, x.endMinutes - s);
28
+ if (M < m)
29
+ return S;
30
+ for (let i = m; i <= M; i += s) {
31
+ const u = g(i), b = i + s, T = g(b);
32
+ S.push({
33
+ value: u,
34
+ label: `${u} - ${T}`,
35
+ startMinutes: i,
36
+ endMinutes: b,
48
37
  isExtra: !1
49
38
  });
50
39
  }
51
- return m;
40
+ return S;
52
41
  }
53
- const c = [];
54
- for (const d of a) {
55
- const g = Math.ceil(d.startMinutes / s) * s, m = d.endMinutes - s;
56
- if (!(m < g))
57
- for (let f = g; f <= m; f += s) {
58
- const b = y(f), u = f + s, S = y(u);
59
- c.push({
60
- value: b,
61
- label: `${b} - ${S}`,
62
- startMinutes: f,
63
- endMinutes: u,
42
+ const f = [];
43
+ for (const c of d) {
44
+ const x = Math.ceil(c.startMinutes / s) * s, S = c.endMinutes - s;
45
+ if (!(S < x))
46
+ for (let m = x; m <= S; m += s) {
47
+ const M = g(m), i = m + s, u = g(i);
48
+ f.push({
49
+ value: M,
50
+ label: `${M} - ${u}`,
51
+ startMinutes: m,
52
+ endMinutes: i,
64
53
  isExtra: !1
65
54
  });
66
55
  }
67
56
  }
68
- return c;
69
- }, O = (e, t, s) => {
70
- if (t.dates?.length && (!s.dateString || !t.dates.some((n) => {
71
- const o = k(n);
72
- return M.test(o) ? o === s.dateString : !1;
73
- })) || t.weekdays?.length && (s.weekday == null || !t.weekdays.includes(s.weekday)))
74
- return !1;
75
- const i = t.values?.includes(e.value) ?? !1;
76
- let r = !1;
77
- if (typeof t.startMinutes == "number") {
78
- const l = typeof t.endMinutes == "number" ? t.endMinutes : t.startMinutes + s.slotInterval;
79
- r = e.startMinutes >= t.startMinutes && e.startMinutes < l;
80
- }
81
- return !!(t.values?.length && i || typeof t.startMinutes == "number" && r);
82
- }, F = (e, t) => !(e.dates?.length && (!t.dateString || !e.dates.some((i) => {
83
- const r = k(i);
84
- return M.test(r) ? r === t.dateString : !1;
85
- })) || e.weekdays?.length && (t.weekday == null || !e.weekdays.includes(t.weekday)) || e.journeyTypes?.length && (!t.journeyType || !e.journeyTypes.includes(t.journeyType))), x = ({
86
- slots: e,
87
- rules: t,
88
- date: s,
89
- slotInterval: i
90
- }) => {
91
- if (!t.length)
92
- return e.map((n) => ({
93
- ...n,
94
- isDisabled: !1
95
- }));
96
- const { dateString: r, weekday: l } = D(s);
97
- return e.map((n) => {
98
- const o = t.find(
99
- (a) => O(n, a, {
100
- dateString: r,
101
- weekday: l,
102
- slotInterval: i
103
- })
104
- );
105
- return o ? {
106
- ...n,
107
- isDisabled: !0,
108
- disabledReason: o.reason
109
- } : {
110
- ...n,
111
- isDisabled: !1
112
- };
113
- });
114
- }, I = ({
115
- slots: e,
116
- rules: t,
117
- date: s,
118
- slotInterval: i,
119
- journeyType: r
120
- }) => {
121
- if (!t.length)
122
- return e.map((a) => ({
123
- ...a
124
- }));
125
- const { dateString: l, weekday: n } = D(s), o = e.map((a) => ({
126
- ...a
57
+ return f;
58
+ }, N = (t, e, s, n) => {
59
+ if (n !== "end" || t.length === 0 || e.length === 0)
60
+ return [];
61
+ const r = e.reduce(
62
+ (o, a) => Math.max(o, a.endMinutes),
63
+ 0
64
+ );
65
+ return [...t].sort((o, a) => o.minutesAfterClose - a.minutesAfterClose).map((o) => ({
66
+ startMinutes: Math.max(r, r + o.minutesAfterClose - s),
67
+ endMinutes: r + o.minutesAfterClose,
68
+ extraAmount: o.extraAmount
127
69
  }));
128
- for (const a of t) {
129
- if (!F(a, {
130
- dateString: l,
131
- weekday: n,
132
- journeyType: r
133
- }))
134
- continue;
135
- const c = typeof a.endMinutes == "number" ? a.endMinutes : a.startMinutes + i, d = o.findIndex((f) => f.startMinutes === a.startMinutes), g = y(a.startMinutes), m = y(c);
136
- if (d >= 0) {
137
- o[d] = {
138
- ...o[d],
139
- endMinutes: c,
140
- label: `${g} - ${m}`,
70
+ }, B = (t, e) => {
71
+ const s = t.map((n) => ({
72
+ ...n
73
+ }));
74
+ for (const n of e) {
75
+ const r = g(n.startMinutes), o = g(n.endMinutes), a = s.findIndex((l) => l.startMinutes === n.startMinutes);
76
+ if (a >= 0) {
77
+ s[a] = {
78
+ ...s[a],
79
+ endMinutes: n.endMinutes,
80
+ label: `${r} - ${o}`,
141
81
  isExtra: !0,
142
- extraAmount: a.extraAmount
82
+ extraAmount: n.extraAmount
143
83
  };
144
84
  continue;
145
85
  }
146
- o.push({
147
- value: g,
148
- label: `${g} - ${m}`,
149
- startMinutes: a.startMinutes,
150
- endMinutes: c,
86
+ s.push({
87
+ value: r,
88
+ label: `${r} - ${o}`,
89
+ startMinutes: n.startMinutes,
90
+ endMinutes: n.endMinutes,
151
91
  isExtra: !0,
152
- extraAmount: a.extraAmount
92
+ extraAmount: n.extraAmount
153
93
  });
154
94
  }
155
- return o.sort((a, c) => a.startMinutes - c.startMinutes);
156
- }, V = (e, t) => {
157
- if (e.length <= 1)
158
- return e;
95
+ return s.sort((n, r) => n.startMinutes - r.startMinutes);
96
+ }, C = (t, e) => {
97
+ if (t.length <= 1)
98
+ return t;
159
99
  const s = [];
160
- let i = 0;
161
- for (; i < e.length; ) {
162
- const r = e[i];
100
+ let n = 0;
101
+ for (; n < t.length; ) {
102
+ const r = t[n];
163
103
  if (r.isDisabled && !r.isExtra && r.disabledReason == null) {
164
- let l = r, n = i + 1;
165
- for (; n < e.length && e[n].isDisabled && !e[n].isExtra && e[n].disabledReason == null && e[n].startMinutes === l.startMinutes + t; )
166
- l = e[n], n += 1;
167
- const o = r.startMinutes, a = l.endMinutes, c = y(o), d = y(a);
104
+ let o = r, a = n + 1;
105
+ for (; a < t.length && t[a].isDisabled && !t[a].isExtra && t[a].disabledReason == null && t[a].startMinutes === o.startMinutes + e; )
106
+ o = t[a], a += 1;
107
+ const l = r.startMinutes, d = o.endMinutes, f = g(l), c = g(d);
168
108
  s.push({
169
109
  ...r,
170
- value: c,
171
- label: `${c} - ${d}`,
172
- startMinutes: o,
173
- endMinutes: a,
110
+ value: f,
111
+ label: `${f} - ${c}`,
112
+ startMinutes: l,
113
+ endMinutes: d,
174
114
  isDisabled: !0,
175
- disabledReason: N
176
- }), i = n;
115
+ disabledReason: w
116
+ }), n = a;
177
117
  continue;
178
118
  }
179
- s.push(r), i += 1;
119
+ s.push(r), n += 1;
180
120
  }
181
121
  return s;
182
122
  }, h = ({
183
- slots: e,
184
- baselineSlots: t,
123
+ slots: t,
124
+ baselineSlots: e,
185
125
  slotInterval: s
186
126
  }) => {
187
- const i = new Set(e.map((n) => n.startMinutes)), r = t.filter((n) => !i.has(n.startMinutes)).map((n) => ({
188
- ...n,
127
+ const n = new Set(t.map((a) => a.startMinutes)), r = e.filter((a) => !n.has(a.startMinutes)).map((a) => ({
128
+ ...a,
189
129
  isDisabled: !0
190
- })), l = [...e, ...r].sort((n, o) => n.startMinutes - o.startMinutes);
191
- return V(l, s);
192
- }, _ = (e, t) => v(e, {
193
- getNormalizedOpeningHours: t.getNormalizedOpeningHours,
194
- getIntervalsForWeekday: t.getIntervalsForWeekday,
195
- defaultWeekday: t.defaultWeekday
196
- }, t.slotIntervalMinutes), R = (e, t) => v(
197
- e,
130
+ })), o = [...t, ...r].sort((a, l) => a.startMinutes - l.startMinutes);
131
+ return C(o, s);
132
+ }, O = (t, e) => E(t, {
133
+ getNormalizedOpeningHours: e.getNormalizedOpeningHours,
134
+ getIntervalsForWeekday: e.getIntervalsForWeekday,
135
+ defaultWeekday: e.defaultWeekday
136
+ }, e.slotIntervalMinutes), F = (t, e) => E(
137
+ t,
198
138
  {
199
- getNormalizedOpeningHours: t.getSeasonNormalizedOpeningHours,
200
- getIntervalsForWeekday: t.getSeasonIntervalsForWeekday,
201
- defaultWeekday: t.defaultSeasonWeekday
139
+ getNormalizedOpeningHours: e.getSeasonNormalizedOpeningHours,
140
+ getIntervalsForWeekday: e.getSeasonIntervalsForWeekday,
141
+ defaultWeekday: e.defaultSeasonWeekday
202
142
  },
203
- t.slotIntervalMinutes,
143
+ e.slotIntervalMinutes,
204
144
  { fillGaps: !0 }
205
- ), p = (e, t, s) => {
206
- const i = t.slotIntervalMinutes, r = _(e, t), l = w();
207
- return I({
208
- slots: r,
209
- rules: l,
210
- date: e,
211
- slotInterval: i,
212
- journeyType: s
213
- });
214
- }, j = (e, {
215
- date: t
145
+ ), y = (t, e, s, n) => {
146
+ const r = e.slotIntervalMinutes, o = O(t, e), a = N(n, o, r, s);
147
+ return B(o, a);
148
+ }, k = (t) => t.map((e) => ({
149
+ ...e,
150
+ isDisabled: !1
151
+ })), I = (t, {
152
+ date: e
216
153
  } = {}) => {
217
- const s = B(e), i = s.slotIntervalMinutes, r = p(void 0, s, "start"), l = p(void 0, s, "end"), n = R(void 0, s), o = {
218
- startTimeSlots: h({
219
- slots: r.map((u) => ({
220
- ...u,
221
- isDisabled: !1
222
- })),
223
- baselineSlots: n,
224
- slotInterval: i
225
- }),
226
- endTimeSlots: h({
227
- slots: l.map((u) => ({
228
- ...u,
229
- isDisabled: !1
230
- })),
231
- baselineSlots: n,
232
- slotInterval: i
233
- })
234
- };
235
- if (!t || !M.test(t))
236
- return o;
237
- const a = W(t), c = p(a, s, "start"), d = p(a, s, "end"), g = R(a, s), m = E(), f = x({
238
- slots: c,
239
- rules: m,
240
- date: a,
241
- slotInterval: i
242
- }), b = x({
243
- slots: d,
244
- rules: m,
245
- date: a,
246
- slotInterval: i
247
- });
154
+ const s = W(t), n = s.slotIntervalMinutes, r = t.extraTimeSlots ?? [], o = e && p.test(e) ? D(e) : void 0, a = y(o, s, "start", r), l = y(o, s, "end", r), d = F(o, s);
248
155
  return {
249
156
  startTimeSlots: h({
250
- slots: f,
251
- baselineSlots: g,
252
- slotInterval: i
157
+ slots: k(a),
158
+ baselineSlots: d,
159
+ slotInterval: n
253
160
  }),
254
161
  endTimeSlots: h({
255
- slots: b,
256
- baselineSlots: g,
257
- slotInterval: i
162
+ slots: k(l),
163
+ baselineSlots: d,
164
+ slotInterval: n
258
165
  })
259
166
  };
260
- }, G = async (e, {
261
- date: t
262
- } = {}) => j(e, { date: t });
167
+ }, R = async (t, {
168
+ date: e
169
+ } = {}) => I(t, { date: e });
263
170
  export {
264
- G as getBookingPeriodTimeSlots,
265
- j as getBookingPeriodTimeSlotsSync,
266
- H as getDisabledTimeSlotRules,
267
- E as getDisabledTimeSlotRulesSync,
268
- P as getExtraTimeSlotRules,
269
- w as getExtraTimeSlotRulesSync,
270
- C as staticDisabledTimeSlotRules,
271
- L as staticExtraTimeSlotRules,
272
- W as toBusinessDateString
171
+ R as getBookingPeriodTimeSlots,
172
+ I as getBookingPeriodTimeSlotsSync,
173
+ D as toBusinessDateString
273
174
  };
@@ -58,11 +58,16 @@ export type NormalizeOpeningHoursOptions = {
58
58
  referenceDate?: Date | string | null;
59
59
  };
60
60
  export declare const normalizeOpeningHours: (openingHours: StoreOpeningHours, openingHoursOverrides: StoreOpeningOverride[], options?: NormalizeOpeningHoursOptions) => NormalizedOpeningHours;
61
+ export type BookingPeriodExtraTimeSlotRule = {
62
+ minutesAfterClose: number;
63
+ extraAmount: number;
64
+ };
61
65
  export type BookingPeriodConfig = {
62
66
  timing: BookingTimingConfig;
63
67
  openingHours: StoreOpeningHours;
64
68
  openingHoursOverrides: StoreOpeningOverride[];
65
69
  timeZone: string;
70
+ extraTimeSlots?: BookingPeriodExtraTimeSlotRule[];
66
71
  };
67
72
  export type BookingPeriodConstants = ReturnType<typeof createBookingPeriodConstants>;
68
73
  export declare const createBookingPeriodConstants: (config: BookingPeriodConfig) => {
@@ -110,6 +115,14 @@ export declare const createBookingPeriodConstants: (config: BookingPeriodConfig)
110
115
  dateString?: string;
111
116
  }) => NormalizedOpeningHours;
112
117
  };
118
+ export declare const instantToBusinessDateTimeParts: (date: Date, timeZone: string) => {
119
+ dateString: string;
120
+ timeString: string;
121
+ minutesFromMidnight: number;
122
+ } | undefined;
123
+ export declare const normalizeBusinessDateString: (dateString: string) => string | undefined;
124
+ export declare const calendarDateToBusinessDateString: (date: Date | null | undefined) => string | undefined;
125
+ export declare const instantToBusinessDateString: (date: Date, timeZone: string) => string | undefined;
113
126
  export interface DefaultBookingPeriod {
114
127
  startDate: Date;
115
128
  startTime: string;
@@ -123,6 +136,7 @@ export interface DefaultBookingPeriodOptions {
123
136
  export declare const getDefaultBookingPeriod: (options: DefaultBookingPeriodOptions) => DefaultBookingPeriod;
124
137
  export declare const dateToBusinessDateString: (date: Date | string | null | undefined, timeZone: string) => string | undefined;
125
138
  export declare const businessDateStringToDate: (dateString: string) => Date;
139
+ export declare const getWeekdayFromDateString: (dateString: string) => Weekday;
126
140
  export interface BookingPeriodInput {
127
141
  startDate?: Date | string | null;
128
142
  startTime?: string | null;