@final-commerce/common 2.12.0-staging.6 → 2.12.1-preprod.1

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/index.js CHANGED
@@ -31,18 +31,17 @@ __export(index_exports, {
31
31
  AttributeType: () => AttributeType,
32
32
  BNPL_METHOD_STATUS: () => BNPL_METHOD_STATUS,
33
33
  BNPL_SKIP_REASON: () => BNPL_SKIP_REASON,
34
- BookingArriveLeave: () => BookingArriveLeave,
35
- BookingDurationUnit: () => BookingDurationUnit,
36
34
  BookingRatePeriod: () => BookingRatePeriod,
37
35
  BookingResourceKind: () => BookingResourceKind,
38
36
  BookingResourceStatus: () => BookingResourceStatus,
39
37
  BookingRulesError: () => BookingRulesError,
40
- BookingSessionSale: () => BookingSessionSale,
41
38
  BookingType: () => BookingType,
42
39
  CANADA_PROVINCES: () => CANADA_PROVINCES,
43
40
  CONDITION_OPERATORS: () => CONDITION_OPERATORS,
44
41
  COUNTRY_CURRENCIES: () => COUNTRY_CURRENCIES,
45
42
  CURRENCY_CONFIG: () => CURRENCY_CONFIG,
43
+ CUSTOMER_CONTACT_VERIFIED: () => CUSTOMER_CONTACT_VERIFIED,
44
+ CUSTOMER_EMAIL_TAKEN: () => CUSTOMER_EMAIL_TAKEN,
46
45
  CompanyType: () => CompanyType,
47
46
  CurrencyCode: () => CurrencyCode,
48
47
  CustomTableAvailability: () => CustomTableAvailability,
@@ -52,6 +51,7 @@ __export(index_exports, {
52
51
  DEFAULT_DISPLAY_STATE_MAP: () => DEFAULT_DISPLAY_STATE_MAP,
53
52
  DEFAULT_HOLD_MINUTES: () => DEFAULT_HOLD_MINUTES,
54
53
  DEFAULT_RESOLVED_CONFIG: () => DEFAULT_RESOLVED_CONFIG,
54
+ DEFAULT_SHELL_SETTINGS: () => DEFAULT_SHELL_SETTINGS,
55
55
  DEFAULT_UNIT_ID: () => DEFAULT_UNIT_ID,
56
56
  DualWriteStrategy: () => DualWriteStrategy,
57
57
  EUFixedRates: () => EUFixedRates,
@@ -80,6 +80,7 @@ __export(index_exports, {
80
80
  ORDER_STATE_TOPIC: () => ORDER_STATE_TOPIC,
81
81
  OrderPlatform: () => OrderPlatform,
82
82
  OtherFixedRates: () => OtherFixedRates,
83
+ OutOfProvinceTaxes: () => OutOfProvinceTaxes,
83
84
  OwnerType: () => OwnerType,
84
85
  PATH_MODES: () => PATH_MODES,
85
86
  PAYMENT_CHANNELS: () => PAYMENT_CHANNELS,
@@ -107,7 +108,18 @@ __export(index_exports, {
107
108
  ResidualPaymentMethod: () => ResidualPaymentMethod,
108
109
  ResidualStatus: () => ResidualStatus,
109
110
  ResourceAvailabilityState: () => ResourceAvailabilityState,
111
+ SHELL_FLOW_SETTINGS_PREFIX: () => SHELL_FLOW_SETTINGS_PREFIX,
112
+ SHELL_FLOW_TIPS_KEY: () => SHELL_FLOW_TIPS_KEY,
113
+ SHELL_TIP_LABEL_MAX_LENGTH: () => SHELL_TIP_LABEL_MAX_LENGTH,
114
+ SHELL_TIP_PERCENT_MAX: () => SHELL_TIP_PERCENT_MAX,
115
+ SHELL_TIP_PERCENT_MIN: () => SHELL_TIP_PERCENT_MIN,
110
116
  SHIPPING_COUNTRIES: () => SHIPPING_COUNTRIES,
117
+ SHOPPER_CONSENT_SOURCES: () => SHOPPER_CONSENT_SOURCES,
118
+ SHOPPER_ERROR_CODES: () => SHOPPER_ERROR_CODES,
119
+ SHOPPER_RETURN_DECLINE_REASON_MAX: () => SHOPPER_RETURN_DECLINE_REASON_MAX,
120
+ SHOPPER_RETURN_METHODS: () => SHOPPER_RETURN_METHODS,
121
+ SHOPPER_RETURN_STATUSES: () => SHOPPER_RETURN_STATUSES,
122
+ STANDARD_TAX_TYPE: () => STANDARD_TAX_TYPE,
111
123
  STATE_SCHEMA: () => STATE_SCHEMA,
112
124
  STRIPE_SUPPORTED_COUNTRIES: () => STRIPE_SUPPORTED_COUNTRIES,
113
125
  SYSTEM_FAMILIES: () => SYSTEM_FAMILIES,
@@ -125,9 +137,13 @@ __export(index_exports, {
125
137
  StationStatus: () => StationStatus,
126
138
  StripeCurrencyCode: () => StripeCurrencyCode,
127
139
  StripeStatus: () => StripeStatus,
140
+ TAX_EXCEPTION_REASON_MAX: () => TAX_EXCEPTION_REASON_MAX,
141
+ TaxExceptionSource: () => TaxExceptionSource,
142
+ TaxRegistrationKind: () => TaxRegistrationKind,
143
+ TaxSource: () => TaxSource,
144
+ TaxWarningCode: () => TaxWarningCode,
128
145
  TimePeriod: () => TimePeriod,
129
146
  TopMetericsSort: () => TopMetericsSort,
130
- UNLIMITED_PLACES: () => UNLIMITED_PLACES,
131
147
  UserTypes: () => UserTypes,
132
148
  addAmounts: () => addAmounts,
133
149
  addressPlaceKeys: () => addressPlaceKeys,
@@ -136,32 +152,27 @@ __export(index_exports, {
136
152
  adyenStoreRequiresStateOrProvince: () => adyenStoreRequiresStateOrProvince,
137
153
  adyenSupportsTaxNumberAbsent: () => adyenSupportsTaxNumberAbsent,
138
154
  adyenTaxNumberFormat: () => adyenTaxNumberFormat,
139
- allowedDurationUnits: () => allowedDurationUnits,
140
155
  amountToString: () => amountToString,
141
156
  ancestorChain: () => ancestorChain,
142
157
  applyAssignment: () => applyAssignment,
143
158
  assertUnitSane: () => assertUnitSane,
159
+ automaticTaxTableVersion: () => automaticTaxTableVersion,
144
160
  availableIn: () => availableIn,
145
161
  baseFor: () => baseFor,
146
162
  baseFulfillmentDefinitions: () => baseFulfillmentDefinitions,
147
163
  baseOf: () => baseOf,
148
164
  basePaymentDefinitions: () => basePaymentDefinitions,
149
- bookingMethodOf: () => bookingMethodOf,
150
- bookingRuleParts: () => bookingRuleParts,
165
+ buildAutomaticTaxTable: () => buildAutomaticTaxTable,
151
166
  buildAvailability: () => buildAvailability,
152
167
  buildGrid: () => buildGrid,
153
168
  buildOrderContext: () => buildOrderContext,
154
169
  buildPosPresetConfig: () => buildPosPresetConfig,
155
170
  buildResolvedConfig: () => buildResolvedConfig,
156
171
  calculatePercentage: () => calculatePercentage,
157
- calendarDate: () => calendarDate,
158
172
  canTransition: () => canTransition,
159
- capacityOf: () => capacityOf,
160
- cellChainOf: () => cellChainOf,
173
+ cardFromProcessorData: () => cardFromProcessorData,
161
174
  cheapestCompositeItem: () => cheapestCompositeItem,
162
175
  cheapestCompositePrice: () => cheapestCompositePrice,
163
- checkPartySize: () => checkPartySize,
164
- checkQtyPerBooking: () => checkQtyPerBooking,
165
176
  compositeItemCost: () => compositeItemCost,
166
177
  compositeItemUnavailable: () => compositeItemUnavailable,
167
178
  compositeMakeable: () => compositeMakeable,
@@ -170,10 +181,6 @@ __export(index_exports, {
170
181
  compositeVariantInStock: () => compositeVariantInStock,
171
182
  conditionSummary: () => conditionSummary,
172
183
  convertFixedFeeToLocalCurrency: () => convertFixedFeeToLocalCurrency,
173
- courseSessions: () => courseSessions,
174
- courseSpan: () => courseSpan,
175
- courseStarted: () => courseStarted,
176
- courseStartedInZone: () => courseStartedInZone,
177
184
  createAmount: () => createAmount,
178
185
  crossAxisRuleApplies: () => crossAxisRuleApplies,
179
186
  currentAssignees: () => currentAssignees,
@@ -182,17 +189,17 @@ __export(index_exports, {
182
189
  deriveUnitId: () => deriveUnitId,
183
190
  displayRuleMatchesPair: () => displayRuleMatchesPair,
184
191
  divideAmount: () => divideAmount,
185
- durationProblems: () => durationProblems,
186
- durationText: () => durationText,
192
+ emailKey: () => emailKey,
187
193
  evaluateCondition: () => evaluateCondition,
188
194
  evaluateConditionSet: () => evaluateConditionSet,
189
195
  extendPrice: () => extendPrice,
190
196
  extendPriceFor: () => extendPriceFor,
191
- fewestFreeOver: () => fewestFreeOver,
197
+ flowSettingsFromShellSettings: () => flowSettingsFromShellSettings,
192
198
  formatCurrency: () => formatCurrency,
193
199
  formatInUnit: () => formatInUnit,
194
200
  formatMinorUnitsToString: () => formatMinorUnitsToString,
195
201
  formatQuantity: () => formatQuantity,
202
+ formatShippingDuration: () => formatShippingDuration,
196
203
  fromBase: () => fromBase,
197
204
  fromMinorUnits: () => fromMinorUnits,
198
205
  generateMongoID: () => generateMongoID,
@@ -222,6 +229,7 @@ __export(index_exports, {
222
229
  isFulfillmentState: () => isFulfillmentState,
223
230
  isInCart: () => isInCart,
224
231
  isPaymentState: () => isPaymentState,
232
+ isShellTipPercent: () => isShellTipPercent,
225
233
  isSupportedCurrency: () => isSupportedCurrency,
226
234
  isSystemFamilyCode: () => isSystemFamilyCode,
227
235
  isValidQuantity: () => isValidQuantity,
@@ -230,9 +238,7 @@ __export(index_exports, {
230
238
  listCountries: () => listCountries,
231
239
  listProvinces: () => listProvinces,
232
240
  listShippingCountries: () => listShippingCountries,
233
- longestMinutesOf: () => longestMinutesOf,
234
241
  mapToLegacyStatus: () => mapToLegacyStatus,
235
- maxAdvanceMinutesOf: () => maxAdvanceMinutesOf,
236
242
  maxPrecisionFor: () => maxPrecisionFor,
237
243
  mergeFragment: () => mergeFragment,
238
244
  modifiersSellable: () => modifiersSellable,
@@ -243,16 +249,14 @@ __export(index_exports, {
243
249
  normalizeMongoIdString: () => normalizeMongoIdString,
244
250
  normalizePostCode: () => normalizePostCode,
245
251
  normalizeProvince: () => normalizeProvince,
252
+ normalizeShopperEmail: () => normalizeShopperEmail,
246
253
  occupancyIn: () => occupancyIn,
247
- occupiedAtOutlet: () => occupiedAtOutlet,
248
- oldMaxAdvanceOf: () => oldMaxAdvanceOf,
249
254
  orderAssignments: () => orderAssignments,
250
255
  parseAmountToMinorUnits: () => parseAmountToMinorUnits,
251
256
  parseCurrencyCode: () => parseCurrencyCode,
252
257
  parseStripeCurrencyCode: () => parseStripeCurrencyCode,
253
- pickFreeResource: () => pickFreeResource,
258
+ phoneKey: () => phoneKey,
254
259
  placeKey: () => placeKey,
255
- planCourse: () => planCourse,
256
260
  planWindow: () => planWindow,
257
261
  poolDemand: () => poolDemand,
258
262
  poolOf: () => poolOf,
@@ -262,27 +266,31 @@ __export(index_exports, {
262
266
  presentAt: () => presentAt,
263
267
  priceForTotal: () => priceForTotal,
264
268
  provincesForPostCode: () => provincesForPostCode,
269
+ readShellTipSettings: () => readShellTipSettings,
270
+ registrationPlacesByKind: () => registrationPlacesByKind,
265
271
  removeFragment: () => removeFragment,
266
- rentalEnds: () => rentalEnds,
267
272
  resolveFamily: () => resolveFamily,
268
273
  resolveModifiersForProduct: () => resolveModifiersForProduct,
274
+ resolveShellSettings: () => resolveShellSettings,
275
+ resolveShellSettingsWithSources: () => resolveShellSettingsWithSources,
269
276
  resolveShipping: () => resolveShipping,
270
277
  resolveTemplate: () => resolveTemplate,
271
278
  resolveUnit: () => resolveUnit,
272
279
  roundToPrecision: () => roundToPrecision,
273
- ruleDurationsOf: () => ruleDurationsOf,
274
- ruleInNewShape: () => ruleInNewShape,
275
280
  sameFamily: () => sameFamily,
276
- sessionCells: () => sessionCells,
277
281
  setOrderState: () => setOrderState,
282
+ sha1Hex: () => sha1Hex,
283
+ shellSettingsFromCompanyTips: () => shellSettingsFromCompanyTips,
284
+ shellSettingsFromFlowSettings: () => shellSettingsFromFlowSettings,
285
+ shellSettingsProblems: () => shellSettingsProblems,
286
+ shellTipSettingsProblems: () => shellTipSettingsProblems,
287
+ shippingDuration: () => shippingDuration,
278
288
  shipsToCountry: () => shipsToCountry,
279
289
  shopDayKey: () => shopDayKey,
280
290
  shopDayRange: () => shopDayRange,
281
- shortestMinutesOf: () => shortestMinutesOf,
291
+ shopperPaymentsOf: () => shopperPaymentsOf,
282
292
  signReportForDisplay: () => signReportForDisplay,
283
293
  slotsForWindow: () => slotsForWindow,
284
- soldAsCourse: () => soldAsCourse,
285
- startsPastMaxAdvance: () => startsPastMaxAdvance,
286
294
  stringifyMinorUnits: () => stringifyMinorUnits,
287
295
  subtractAmounts: () => subtractAmounts,
288
296
  toBase: () => toBase,
@@ -291,10 +299,9 @@ __export(index_exports, {
291
299
  validateFragmentCompatibility: () => validateFragmentCompatibility,
292
300
  validateOrderStatuses: () => validateOrderStatuses,
293
301
  validateShippingZone: () => validateShippingZone,
302
+ verifiedContactChange: () => verifiedContactChange,
294
303
  violatesFinancialInvariant: () => violatesFinancialInvariant,
295
304
  windowEndsAt: () => windowEndsAt,
296
- windowEndsAtInZone: () => windowEndsAtInZone,
297
- windowForPeriods: () => windowForPeriods,
298
305
  withinPresence: () => withinPresence
299
306
  });
300
307
  module.exports = __toCommonJS(index_exports);
@@ -755,42 +762,21 @@ var PaymentProcessor = /* @__PURE__ */ ((PaymentProcessor2) => {
755
762
  })(PaymentProcessor || {});
756
763
 
757
764
  // enums/booking.enum.ts
758
- var BookingType = /* @__PURE__ */ ((BookingType2) => {
759
- BookingType2["RENTAL"] = "rental";
760
- BookingType2["APPOINTMENT"] = "appointment";
761
- BookingType2["OVERNIGHT"] = "overnight";
762
- BookingType2["GROUP"] = "group";
763
- return BookingType2;
765
+ var BookingType = /* @__PURE__ */ ((BookingType3) => {
766
+ BookingType3["RENTAL"] = "rental";
767
+ BookingType3["APPOINTMENT"] = "appointment";
768
+ BookingType3["OVERNIGHT"] = "overnight";
769
+ BookingType3["GROUP"] = "group";
770
+ return BookingType3;
764
771
  })(BookingType || {});
765
772
  var BookingRatePeriod = /* @__PURE__ */ ((BookingRatePeriod2) => {
766
773
  BookingRatePeriod2["SLOT"] = "slot";
767
- BookingRatePeriod2["HOUR"] = "hour";
768
- BookingRatePeriod2["SESSION"] = "session";
769
774
  BookingRatePeriod2["DAY"] = "day";
770
775
  BookingRatePeriod2["NIGHT"] = "night";
771
776
  BookingRatePeriod2["WEEK"] = "week";
772
777
  BookingRatePeriod2["MONTH"] = "month";
773
778
  return BookingRatePeriod2;
774
779
  })(BookingRatePeriod || {});
775
- var BookingDurationUnit = /* @__PURE__ */ ((BookingDurationUnit2) => {
776
- BookingDurationUnit2["MINUTE"] = "minute";
777
- BookingDurationUnit2["HOUR"] = "hour";
778
- BookingDurationUnit2["DAY"] = "day";
779
- BookingDurationUnit2["NIGHT"] = "night";
780
- BookingDurationUnit2["WEEK"] = "week";
781
- BookingDurationUnit2["MONTH"] = "month";
782
- return BookingDurationUnit2;
783
- })(BookingDurationUnit || {});
784
- var BookingSessionSale = /* @__PURE__ */ ((BookingSessionSale2) => {
785
- BookingSessionSale2["SESSION"] = "session";
786
- BookingSessionSale2["COURSE"] = "course";
787
- return BookingSessionSale2;
788
- })(BookingSessionSale || {});
789
- var BookingArriveLeave = /* @__PURE__ */ ((BookingArriveLeave2) => {
790
- BookingArriveLeave2["SET_TIMES"] = "set-times";
791
- BookingArriveLeave2["OPENING_HOURS"] = "opening-hours";
792
- return BookingArriveLeave2;
793
- })(BookingArriveLeave || {});
794
780
  var BookingResourceKind = /* @__PURE__ */ ((BookingResourceKind2) => {
795
781
  BookingResourceKind2["ASSET"] = "asset";
796
782
  BookingResourceKind2["ROOM"] = "room";
@@ -863,6 +849,30 @@ var ShippingZoneError = /* @__PURE__ */ ((ShippingZoneError2) => {
863
849
  return ShippingZoneError2;
864
850
  })(ShippingZoneError || {});
865
851
 
852
+ // enums/tax.enum.ts
853
+ var TaxRegistrationKind = /* @__PURE__ */ ((TaxRegistrationKind2) => {
854
+ TaxRegistrationKind2["GST_HST"] = "GST_HST";
855
+ TaxRegistrationKind2["PST"] = "PST";
856
+ TaxRegistrationKind2["QST"] = "QST";
857
+ return TaxRegistrationKind2;
858
+ })(TaxRegistrationKind || {});
859
+ var TaxSource = /* @__PURE__ */ ((TaxSource2) => {
860
+ TaxSource2["MERCHANT"] = "merchant";
861
+ TaxSource2["AUTOMATIC"] = "automatic";
862
+ return TaxSource2;
863
+ })(TaxSource || {});
864
+ var OutOfProvinceTaxes = /* @__PURE__ */ ((OutOfProvinceTaxes2) => {
865
+ OutOfProvinceTaxes2["AUTOMATIC"] = "automatic";
866
+ OutOfProvinceTaxes2["HOME"] = "home";
867
+ return OutOfProvinceTaxes2;
868
+ })(OutOfProvinceTaxes || {});
869
+ var TaxWarningCode = /* @__PURE__ */ ((TaxWarningCode2) => {
870
+ TaxWarningCode2["NOT_REGISTERED"] = "NOT_REGISTERED";
871
+ TaxWarningCode2["NO_RULES_FOR_PLACE"] = "NO_RULES_FOR_PLACE";
872
+ TaxWarningCode2["NO_TABLE"] = "NO_TABLE";
873
+ return TaxWarningCode2;
874
+ })(TaxWarningCode || {});
875
+
866
876
  // enums/sales-line.enum.ts
867
877
  var SalesLineAction = /* @__PURE__ */ ((SalesLineAction2) => {
868
878
  SalesLineAction2["SALE"] = "sale";
@@ -2103,6 +2113,183 @@ function lineStockMoves(item, quantity, reservations = []) {
2103
2113
  });
2104
2114
  }
2105
2115
 
2116
+ // utils/shell-settings.util.ts
2117
+ var DEFAULT_SHELL_SETTINGS = {
2118
+ pinSwitchUser: false,
2119
+ pinSession: false,
2120
+ stationLock: 0,
2121
+ buildTimeout: 0,
2122
+ lockedAccess: false,
2123
+ cashManagement: true,
2124
+ tips: {
2125
+ enabled: true,
2126
+ tip1: { label: "Good", value: 15 },
2127
+ tip2: { label: "Great", value: 18 },
2128
+ tip3: { label: "Amazing!", value: 25 },
2129
+ customTipLabel: "Custom",
2130
+ noTipLabel: "No tip"
2131
+ }
2132
+ };
2133
+ var FIELD_ORDER = ["station"];
2134
+ var TIP_ORDER = ["station", "outlet", "flow", "company"];
2135
+ var TOP_FIELDS = [
2136
+ "pinSwitchUser",
2137
+ "pinSession",
2138
+ "stationLock",
2139
+ "buildTimeout",
2140
+ "lockedAccess",
2141
+ "cashManagement"
2142
+ ];
2143
+ var TIP_FIELDS = ["enabled", "tip1", "tip2", "tip3", "customTipLabel", "noTipLabel"];
2144
+ function pick(levels, order, read, fallback) {
2145
+ for (const level of order) {
2146
+ const settings = levels[level];
2147
+ if (!settings) continue;
2148
+ const value = read(settings);
2149
+ if (value !== void 0 && value !== null) return { value, source: level };
2150
+ }
2151
+ return { value: fallback, source: "default" };
2152
+ }
2153
+ function resolveShellSettingsWithSources(levels) {
2154
+ const settings = { ...DEFAULT_SHELL_SETTINGS, tips: { ...DEFAULT_SHELL_SETTINGS.tips } };
2155
+ const sources = { fields: {}, tips: {} };
2156
+ for (const field of TOP_FIELDS) {
2157
+ const { value, source } = pick(levels, FIELD_ORDER, (s) => s[field], DEFAULT_SHELL_SETTINGS[field]);
2158
+ settings[field] = value;
2159
+ sources.fields[field] = source;
2160
+ }
2161
+ for (const field of TIP_FIELDS) {
2162
+ const { value, source } = pick(levels, TIP_ORDER, (s) => s.tips?.[field], DEFAULT_SHELL_SETTINGS.tips[field]);
2163
+ settings.tips[field] = value;
2164
+ sources.tips[field] = source;
2165
+ }
2166
+ return { settings, sources };
2167
+ }
2168
+ function resolveShellSettings(levels) {
2169
+ return resolveShellSettingsWithSources(levels).settings;
2170
+ }
2171
+ var SHELL_TIP_PERCENT_MIN = 1;
2172
+ var SHELL_TIP_PERCENT_MAX = 100;
2173
+ var SHELL_TIP_LABEL_MAX_LENGTH = 20;
2174
+ var isLabel = (raw) => typeof raw === "string" && raw.trim().length > 0 && raw.length <= SHELL_TIP_LABEL_MAX_LENGTH;
2175
+ var isShellTipPercent = (raw) => typeof raw === "number" && Number.isInteger(raw) && raw >= SHELL_TIP_PERCENT_MIN && raw <= SHELL_TIP_PERCENT_MAX;
2176
+ function shellTipSettingsProblems(tips) {
2177
+ if (!tips) return [];
2178
+ const problems = [];
2179
+ if (tips.enabled !== void 0 && typeof tips.enabled !== "boolean") {
2180
+ problems.push({ field: "tips.enabled", code: "boolean" });
2181
+ }
2182
+ for (const key of ["tip1", "tip2", "tip3"]) {
2183
+ const option = tips[key];
2184
+ if (option === void 0) continue;
2185
+ if (!option || typeof option !== "object") {
2186
+ problems.push({ field: `tips.${key}`, code: "preset" });
2187
+ continue;
2188
+ }
2189
+ if (!isShellTipPercent(option.value)) problems.push({ field: `tips.${key}`, code: "percent" });
2190
+ if (!isLabel(option.label)) problems.push({ field: `tips.${key}`, code: "label" });
2191
+ }
2192
+ for (const key of ["customTipLabel", "noTipLabel"]) {
2193
+ if (tips[key] !== void 0 && !isLabel(tips[key])) problems.push({ field: `tips.${key}`, code: "label" });
2194
+ }
2195
+ return problems;
2196
+ }
2197
+ function shellSettingsProblems(settings) {
2198
+ if (!settings) return [];
2199
+ const problems = [];
2200
+ for (const field of ["pinSwitchUser", "pinSession", "lockedAccess", "cashManagement"]) {
2201
+ if (settings[field] !== void 0 && typeof settings[field] !== "boolean")
2202
+ problems.push({ field, code: "boolean" });
2203
+ }
2204
+ for (const field of ["stationLock", "buildTimeout"]) {
2205
+ const value = settings[field];
2206
+ if (value !== void 0 && !(typeof value === "number" && Number.isInteger(value) && value >= 0)) {
2207
+ problems.push({ field, code: "timeout" });
2208
+ }
2209
+ }
2210
+ return [...problems, ...shellTipSettingsProblems(settings.tips)];
2211
+ }
2212
+ var SHELL_FLOW_SETTINGS_PREFIX = "flowSettingsKey";
2213
+ var SHELL_FLOW_TIPS_KEY = `${SHELL_FLOW_SETTINGS_PREFIX}.tips`;
2214
+ var readBoolean = (raw) => {
2215
+ if (raw === void 0 || raw === "") return void 0;
2216
+ const v = raw.trim().toLowerCase();
2217
+ if (v === "true") return true;
2218
+ if (v === "false") return false;
2219
+ return void 0;
2220
+ };
2221
+ function readTipOption(raw) {
2222
+ if (!raw || typeof raw !== "object") return void 0;
2223
+ const { label, value } = raw;
2224
+ const n = typeof value === "number" ? value : parseFloat(String(value ?? ""));
2225
+ if (typeof label !== "string" || !Number.isFinite(n) || n < 0) return void 0;
2226
+ return { label, value: n };
2227
+ }
2228
+ function readShellTipSettings(raw) {
2229
+ if (!raw || typeof raw !== "object") return void 0;
2230
+ const r = raw;
2231
+ const tips = {};
2232
+ if (typeof r.enabled === "boolean") tips.enabled = r.enabled;
2233
+ const tip1 = readTipOption(r.tip1);
2234
+ const tip2 = readTipOption(r.tip2);
2235
+ const tip3 = readTipOption(r.tip3);
2236
+ if (tip1) tips.tip1 = tip1;
2237
+ if (tip2) tips.tip2 = tip2;
2238
+ if (tip3) tips.tip3 = tip3;
2239
+ if (typeof r.customTipLabel === "string") tips.customTipLabel = r.customTipLabel;
2240
+ if (typeof r.noTipLabel === "string") tips.noTipLabel = r.noTipLabel;
2241
+ return Object.keys(tips).length > 0 ? tips : void 0;
2242
+ }
2243
+ var parseJson = (raw) => {
2244
+ if (!raw) return void 0;
2245
+ try {
2246
+ return JSON.parse(raw);
2247
+ } catch {
2248
+ return void 0;
2249
+ }
2250
+ };
2251
+ function shellSettingsFromFlowSettings(dict) {
2252
+ const tips = readShellTipSettings(parseJson(dict?.[SHELL_FLOW_TIPS_KEY]));
2253
+ return tips ? { tips } : {};
2254
+ }
2255
+ function flowSettingsFromShellSettings(settings) {
2256
+ return settings.tips && Object.keys(settings.tips).length > 0 ? { [SHELL_FLOW_TIPS_KEY]: JSON.stringify(settings.tips) } : {};
2257
+ }
2258
+ function shellSettingsFromCompanyTips(enabled, options) {
2259
+ const tips = {
2260
+ ...readShellTipSettings(typeof options === "string" ? parseJson(options) : options)
2261
+ };
2262
+ const on = typeof enabled === "boolean" ? enabled : readBoolean(typeof enabled === "string" ? enabled : void 0);
2263
+ if (on !== void 0) tips.enabled = on;
2264
+ return Object.keys(tips).length > 0 ? { tips } : {};
2265
+ }
2266
+
2267
+ // utils/contact-keys.util.ts
2268
+ function emailKey(email) {
2269
+ const key = email?.trim().toLowerCase();
2270
+ return key && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(key) ? key : null;
2271
+ }
2272
+ function phoneKey(phone) {
2273
+ const raw = phone?.trim();
2274
+ if (!raw) return null;
2275
+ const digits = raw.replace(/\D/g, "");
2276
+ if (raw.startsWith("+")) return digits.length >= 8 && digits.length <= 15 ? `+${digits}` : null;
2277
+ if (digits.length === 10) return `+1${digits}`;
2278
+ if (digits.length === 11 && digits.startsWith("1")) return `+${digits}`;
2279
+ return null;
2280
+ }
2281
+ var CUSTOMER_CONTACT_VERIFIED = "CUSTOMER_CONTACT_VERIFIED";
2282
+ var CUSTOMER_EMAIL_TAKEN = "CUSTOMER_EMAIL_TAKEN";
2283
+ function sameContact(a, b, key) {
2284
+ return (key(a) ?? a?.trim().toLowerCase() ?? "") === (key(b) ?? b?.trim().toLowerCase() ?? "");
2285
+ }
2286
+ function verifiedContactChange(existing, change) {
2287
+ if (!existing.verifiedShopperAt) return null;
2288
+ if (change.email !== void 0 && !sameContact(existing.email, change.email, emailKey)) return "email";
2289
+ if (change.phone !== void 0 && !sameContact(existing.phone, change.phone, phoneKey)) return "phone";
2290
+ return null;
2291
+ }
2292
+
2106
2293
  // units/family-code.ts
2107
2294
  var MAX_SLUG_LENGTH = 32;
2108
2295
  var FALLBACK_SLUG = "family";
@@ -2145,6 +2332,7 @@ var FULFILLMENT_STATES = [
2145
2332
  "in_progress",
2146
2333
  "fulfilled",
2147
2334
  "partially_fulfilled",
2335
+ "return_pending",
2148
2336
  "returned",
2149
2337
  "partially_returned",
2150
2338
  "cancelled"
@@ -2170,10 +2358,7 @@ var CONDITION_OPERATORS = [
2170
2358
  function isConditionOperator(value) {
2171
2359
  return CONDITION_OPERATORS.includes(value);
2172
2360
  }
2173
- var PATH_MODES = [
2174
- "strict",
2175
- "permissive"
2176
- ];
2361
+ var PATH_MODES = ["strict", "permissive"];
2177
2362
 
2178
2363
  // order-state-machine/state-schema.ts
2179
2364
  var PAYMENT_DEFS = [
@@ -2194,6 +2379,9 @@ var FULFILLMENT_DEFS = [
2194
2379
  { id: "in_progress", label: "In Progress", terminal: false },
2195
2380
  { id: "fulfilled", label: "Fulfilled", terminal: true },
2196
2381
  { id: "partially_fulfilled", label: "Partially Fulfilled", terminal: false },
2382
+ // The store accepted the shopper's return request: the goods are on their way back, no money has moved yet.
2383
+ // The refund lands `partially_returned` / `returned` as it does from `fulfilled`.
2384
+ { id: "return_pending", label: "Return Accepted", terminal: false },
2197
2385
  { id: "returned", label: "Returned", terminal: true },
2198
2386
  { id: "partially_returned", label: "Partially Returned", terminal: false },
2199
2387
  { id: "cancelled", label: "Cancelled", terminal: true }
@@ -2223,6 +2411,8 @@ var STATE_SCHEMA = Object.freeze({
2223
2411
  var REFUND_ALLOWED_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "returned", "partially_returned", "cancelled"]);
2224
2412
  var PAYMENT_COLLECTION_ORDER = ["unpaid", "partially_paid", "paid"];
2225
2413
  var UNRETURNED_MONEY_STATES = /* @__PURE__ */ new Set(["partially_paid", "paid", "partially_refunded"]);
2414
+ var RETURN_FROM_FULFILLMENT = /* @__PURE__ */ new Set(["fulfilled", "partially_fulfilled", "partially_returned"]);
2415
+ var RETURN_PENDING_PAYMENTS = /* @__PURE__ */ new Set(["paid", "partially_refunded"]);
2226
2416
  var REFUNDED_FULFILLMENT_LANDINGS = /* @__PURE__ */ new Set(["returned", "cancelled"]);
2227
2417
  var FINANCIAL_INVARIANTS = [
2228
2418
  {
@@ -2270,6 +2460,11 @@ var FINANCIAL_INVARIANTS = [
2270
2460
  description: "A voided order exists only at cancelled fulfillment: a voided order cannot re-enter fulfillment, and a voided \xD7 non-cancelled pair cannot be materialized from nothing (complements no-leave-voided, which only freezes the payment axis). Moves INTO voided from a live payment state are the void flow\u2019s concern, not this rule\u2019s",
2271
2461
  check: (from, to) => (from === null || from.payment === "voided") && to.payment === "voided" && to.fulfillment !== "cancelled"
2272
2462
  },
2463
+ {
2464
+ id: "return-pending-needs-goods-out",
2465
+ description: "Fulfillment enters return_pending (return accepted) only from fulfilled, partially_fulfilled or partially_returned, and holds it only while payment is paid or partially_refunded \u2014 goods must have gone out and money must still be held",
2466
+ check: (from, to) => to.fulfillment === "return_pending" && (!RETURN_PENDING_PAYMENTS.has(to.payment) || from?.fulfillment !== "return_pending" && !(from && RETURN_FROM_FULFILLMENT.has(from.fulfillment)))
2467
+ },
2273
2468
  {
2274
2469
  id: "no-reopen-refunded-fulfillment",
2275
2470
  description: "A fully refunded order cannot re-enter fulfillment \u2014 it may only relabel between its canonical landings, returned and cancelled (complements no-leave-refunded, which only freezes the payment axis)",
@@ -2361,7 +2556,9 @@ var DISPLAY_LABEL_OVERRIDES = {
2361
2556
  "paid|on_hold": "Parked - Paid",
2362
2557
  "paid|fulfilled": "Completed",
2363
2558
  "partially_refunded|fulfilled": "Partially Refunded",
2364
- "partially_refunded|partially_returned": "Partially Refunded"
2559
+ "partially_refunded|partially_returned": "Partially Refunded",
2560
+ "paid|return_pending": "Return Accepted",
2561
+ "partially_refunded|return_pending": "Return Accepted"
2365
2562
  };
2366
2563
  var TERMINAL_LABEL_OVERRIDES = {
2367
2564
  voided: "Cancelled"
@@ -2503,6 +2700,7 @@ function buildOrderContext(order, extras) {
2503
2700
  }
2504
2701
 
2505
2702
  // order-state-machine/display-state.ts
2703
+ var ATOMS_ADDED_AFTER_SNAPSHOT = /* @__PURE__ */ new Set(["return_pending"]);
2506
2704
  function atomLabel(atom, defs) {
2507
2705
  return defs.find((d) => d.id === atom)?.label ?? atom;
2508
2706
  }
@@ -2516,6 +2714,10 @@ function deriveDisplayState(payment, fulfillment, config) {
2516
2714
  return { label: rule.label, color: rule.color, icon: rule.icon };
2517
2715
  }
2518
2716
  }
2717
+ if (ATOMS_ADDED_AFTER_SNAPSHOT.has(fulfillment)) {
2718
+ const fallback = DEFAULT_DISPLAY_STATE_MAP.find((rule) => displayRuleMatchesPair(rule, payment, fulfillment));
2719
+ if (fallback) return { label: fallback.label, color: fallback.color, icon: fallback.icon };
2720
+ }
2519
2721
  return {
2520
2722
  label: `${atomLabel(payment, STATE_SCHEMA.paymentStates)} / ${atomLabel(fulfillment, STATE_SCHEMA.fulfillmentStates)}`
2521
2723
  };
@@ -3651,7 +3853,6 @@ var ORDER_STATE_EVENTS = {
3651
3853
  };
3652
3854
 
3653
3855
  // booking/types.ts
3654
- var UNLIMITED_PLACES = Number.MAX_SAFE_INTEGER;
3655
3856
  var BookingRulesError = class extends Error {
3656
3857
  constructor(message) {
3657
3858
  super(message);
@@ -3720,39 +3921,153 @@ function atZonedMinute(dayStart, minutes, timeZone) {
3720
3921
  const { year, month, day } = zonedParts(dayStart, timeZone);
3721
3922
  return instantFromLocal(year, month, day, minutes, timeZone);
3722
3923
  }
3723
- function sameDayMonthsLaterDate(year, month, day, months) {
3724
- const target = new Date(Date.UTC(year, month - 1 + months, 1));
3725
- const lastDay = new Date(Date.UTC(target.getUTCFullYear(), target.getUTCMonth() + 1, 0)).getUTCDate();
3726
- return [target.getUTCFullYear(), target.getUTCMonth() + 1, Math.min(day, lastDay)];
3924
+
3925
+ // booking/grid.ts
3926
+ var MINUTE2 = 6e4;
3927
+ var MAX_RANGE_DAYS = 366;
3928
+ var asTime = (value, field) => {
3929
+ if (value == null) return void 0;
3930
+ const time = new Date(value).getTime();
3931
+ if (Number.isNaN(time)) throw new BookingRulesError(`Booking rules: ${field} is not a date, got "${String(value)}"`);
3932
+ return time;
3933
+ };
3934
+ function parseHhMm(value, field) {
3935
+ const [hours, minutes] = value.split(":").map(Number);
3936
+ if (!Number.isInteger(hours) || !Number.isInteger(minutes)) {
3937
+ throw new BookingRulesError(`Booking rules: ${field} must be "HH:mm", got "${value}"`);
3938
+ }
3939
+ return hours * 60 + minutes;
3727
3940
  }
3728
- function addClockDuration(from, { count, unit: unit2 }) {
3729
- if (unit2 === "minute" /* MINUTE */) return new Date(from.getTime() + count * MINUTE);
3730
- if (unit2 === "hour" /* HOUR */) return new Date(from.getTime() + count * 60 * MINUTE);
3731
- throw new BookingRulesError(
3732
- `Booking rules: ${count} ${unit2} is not minutes or hours \u2014 it needs the shop's time zone`
3941
+ function windowEndsAt(rule, now) {
3942
+ const { maxAdvanceDays, bookableTo } = rule.window;
3943
+ const ends = Math.min(
3944
+ maxAdvanceDays ? now.getTime() + maxAdvanceDays * 1440 * MINUTE2 : Number.POSITIVE_INFINITY,
3945
+ asTime(bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
3733
3946
  );
3947
+ return Number.isFinite(ends) ? new Date(ends) : null;
3734
3948
  }
3735
- var DAYS_IN = {
3736
- ["day" /* DAY */]: 1,
3737
- ["night" /* NIGHT */]: 1,
3738
- ["week" /* WEEK */]: 7
3739
- };
3740
- function addDuration(from, duration, timeZone) {
3741
- const { count, unit: unit2 } = duration;
3742
- if (unit2 === "minute" /* MINUTE */ || unit2 === "hour" /* HOUR */) return addClockDuration(from, duration);
3743
- const days = DAYS_IN[unit2];
3744
- if (days === void 0 && unit2 !== "month" /* MONTH */) {
3745
- throw new BookingRulesError(`Booking rules: "${unit2}" is not a duration unit`);
3746
- }
3747
- if (!Number.isInteger(count)) throw new BookingRulesError(`Booking rules: ${count} ${unit2} is not a whole number`);
3748
- const { year, month, day, hour, minute, second } = zonedParts(from, timeZone);
3749
- const [toYear, toMonth, toDay] = days === void 0 ? sameDayMonthsLaterDate(year, month, day, count) : [year, month, day + days * count];
3750
- const wallClock = instantFromLocal(toYear, toMonth, toDay, hour * 60 + minute, timeZone);
3751
- return new Date(wallClock.getTime() + second * 1e3 + from.getUTCMilliseconds());
3949
+ function periodSlot(dayStart, timeZone, rule, openMinute, closeMinute) {
3950
+ const { ratePeriod, slot, checkInTime, checkOutTime } = rule;
3951
+ const at = (minutes) => atZonedMinute(dayStart, minutes, timeZone);
3952
+ if (ratePeriod === "night" /* NIGHT */) {
3953
+ if (!checkInTime || !checkOutTime) {
3954
+ throw new BookingRulesError("Overnight booking rules need both checkInTime and checkOutTime");
3955
+ }
3956
+ const checkIn = parseHhMm(checkInTime, "checkInTime");
3957
+ const checkOut = parseHhMm(checkOutTime, "checkOutTime");
3958
+ return {
3959
+ startAt: at(checkIn),
3960
+ endAt: at(1440 + checkOut),
3961
+ // Housekeeping sits between check-out and the next check-in: it costs no night.
3962
+ bufferEndAt: at(1440 + checkIn),
3963
+ canStart: true
3964
+ };
3965
+ }
3966
+ const from = ratePeriod === "day" /* DAY */ ? openMinute ?? 0 : 0;
3967
+ const to = ratePeriod === "day" /* DAY */ ? closeMinute ?? 1440 : 1440;
3968
+ return {
3969
+ startAt: at(from),
3970
+ endAt: at(to),
3971
+ bufferEndAt: at(to + (slot.bufferMinutes ?? 0)),
3972
+ canStart: true
3973
+ };
3974
+ }
3975
+ function freeGaps(openAt, closeAt, busy) {
3976
+ const inside = busy.map(({ startAt, bufferEndAt }) => ({ from: +startAt, to: +bufferEndAt })).filter(({ from, to }) => to > openAt && from < closeAt).sort((first, second) => first.from - second.from);
3977
+ const gaps = [];
3978
+ let cursor = openAt;
3979
+ for (const { from, to } of inside) {
3980
+ if (from > cursor) gaps.push({ from: cursor, to: from, endsAtBooking: true });
3981
+ cursor = Math.max(cursor, to);
3982
+ if (cursor >= closeAt) break;
3983
+ }
3984
+ if (cursor < closeAt) gaps.push({ from: cursor, to: closeAt, endsAtBooking: false });
3985
+ return gaps;
3986
+ }
3987
+ function buildGrid(rule, timeZone, from, to, now, busy = []) {
3988
+ if (to.getTime() - from.getTime() > MAX_RANGE_DAYS * 1440 * MINUTE2) {
3989
+ throw new BookingRulesError(`A booking range may span at most ${MAX_RANGE_DAYS} days`);
3990
+ }
3991
+ const { availability, slot, window, ratePeriod } = rule;
3992
+ const periodMode = ratePeriod !== "slot" /* SLOT */;
3993
+ const weeklyHours = availability.weeklyHours ?? [];
3994
+ const notBefore = Math.max(
3995
+ now.getTime() + (window.minNoticeMinutes ?? 0) * MINUTE2,
3996
+ asTime(window.bookableFrom, "window.bookableFrom") ?? 0,
3997
+ asTime(availability.availableFrom, "availability.availableFrom") ?? 0
3998
+ );
3999
+ const notAfter = windowEndsAt(rule, now)?.getTime() ?? Number.POSITIVE_INFINITY;
4000
+ const blocked = (availability.offMarket ?? []).map(({ from: blockFrom, to: blockTo }) => ({
4001
+ from: asTime(blockFrom, "availability.offMarket.from"),
4002
+ to: asTime(blockTo, "availability.offMarket.to")
4003
+ }));
4004
+ const arrivalDays = availability.arrivalDays;
4005
+ const step = slot.lengthMinutes + (slot.bufferMinutes ?? 0);
4006
+ const slots = [];
4007
+ const lastDay = startOfZonedDay(to, timeZone).getTime();
4008
+ let dayStart = startOfZonedDay(from, timeZone);
4009
+ while (dayStart.getTime() <= lastDay) {
4010
+ const weekday = zonedParts(dayStart, timeZone).weekday;
4011
+ const rows = weeklyHours.filter((entry) => entry.weekday === weekday);
4012
+ if (periodMode) {
4013
+ const openToday = weeklyHours.length === 0 || rows.length > 0;
4014
+ if (openToday) {
4015
+ const built = periodSlot(dayStart, timeZone, rule, rows[0]?.openMinute, rows[0]?.closeMinute);
4016
+ slots.push({ ...built, canStart: !arrivalDays?.length || arrivalDays.includes(weekday) });
4017
+ }
4018
+ } else {
4019
+ for (const row of rows) {
4020
+ const openAt = +atZonedMinute(dayStart, row.openMinute, timeZone);
4021
+ const closeAt = +atZonedMinute(dayStart, row.closeMinute, timeZone);
4022
+ for (const gap of freeGaps(openAt, closeAt, busy)) {
4023
+ const mustFit = (gap.endsAtBooking ? step : slot.lengthMinutes) * MINUTE2;
4024
+ for (let start = gap.from; start + mustFit <= gap.to; start += step * MINUTE2) {
4025
+ slots.push({
4026
+ startAt: new Date(start),
4027
+ endAt: new Date(start + slot.lengthMinutes * MINUTE2),
4028
+ bufferEndAt: new Date(start + step * MINUTE2),
4029
+ canStart: true
4030
+ });
4031
+ }
4032
+ }
4033
+ }
4034
+ }
4035
+ dayStart = nextZonedDay(dayStart, timeZone);
4036
+ }
4037
+ const askedFrom = from.getTime();
4038
+ const askedTo = to.getTime();
4039
+ return slots.filter(({ startAt, bufferEndAt }) => {
4040
+ const start = startAt.getTime();
4041
+ if (start < askedFrom || start >= askedTo) return false;
4042
+ if (start < notBefore || start > notAfter) return false;
4043
+ return !blocked.some(
4044
+ ({ from: blockFrom, to: blockTo }) => start < blockTo && bufferEndAt.getTime() > blockFrom
4045
+ );
4046
+ }).sort((first, second) => +first.startAt - +second.startAt);
4047
+ }
4048
+ function slotsForWindow(grid, startAt, endAt) {
4049
+ const startIndex = grid.findIndex((entry) => entry.startAt.getTime() === startAt.getTime());
4050
+ if (startIndex < 0) {
4051
+ throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
4052
+ }
4053
+ if (!grid[startIndex].canStart) {
4054
+ throw new BookingRulesError(`${startAt.toISOString()} is not an arrival day for these rules`);
4055
+ }
4056
+ const covered = [];
4057
+ for (let index = startIndex; index < grid.length; index++) {
4058
+ const entry = grid[index];
4059
+ const previous = covered[covered.length - 1];
4060
+ if (previous && entry.startAt.getTime() !== previous.bufferEndAt.getTime()) break;
4061
+ covered.push(entry);
4062
+ if (entry.endAt.getTime() === endAt.getTime()) return covered;
4063
+ if (entry.endAt.getTime() > endAt.getTime()) break;
4064
+ }
4065
+ throw new BookingRulesError(
4066
+ `${startAt.toISOString()} \u2192 ${endAt.toISOString()} does not line up with the bookable grid`
4067
+ );
3752
4068
  }
3753
4069
 
3754
4070
  // booking/availability.ts
3755
- var placesOnTheWire = (entry) => Number.isFinite(entry.capacity) ? entry : { ...entry, capacity: UNLIMITED_PLACES, free: UNLIMITED_PLACES, unlimited: true };
3756
4071
  var withinPresence = (slot, timeZone, presence) => {
3757
4072
  if (!presence?.length) return true;
3758
4073
  const dayStart = startOfZonedDay(slot.startAt, timeZone);
@@ -3770,11 +4085,6 @@ function occupancyIn(occupied, productId, startAt, bufferEndAt, shared) {
3770
4085
  foreignProductId: foreign?.productId
3771
4086
  };
3772
4087
  }
3773
- var inEveryOutletPool = (entry) => !entry.outletId;
3774
- function occupiedAtOutlet(occupied, rule, outletId) {
3775
- if (bookingMethodOf(rule) !== "sessions" || !outletId) return occupied;
3776
- return occupied.filter((entry) => inEveryOutletPool(entry) || entry.outletId === outletId);
3777
- }
3778
4088
  var stateFor = (hasShift, offerable, free) => {
3779
4089
  if (offerable === 0) {
3780
4090
  return hasShift() ? "fullyBooked" /* FULLY_BOOKED */ : "noHoursInRange" /* NO_HOURS_IN_RANGE */;
@@ -3804,36 +4114,26 @@ function shopDayRange(fromDayKey, count, timeZone) {
3804
4114
  function buildAvailability({
3805
4115
  productId,
3806
4116
  bookingRulesId,
4117
+ bookingType,
3807
4118
  rule,
3808
4119
  resources,
3809
- occupied: everyOutlet,
3810
- outletId,
4120
+ occupied,
3811
4121
  from,
3812
4122
  to,
3813
- now,
3814
- timeZone
4123
+ now
3815
4124
  }) {
3816
- const occupied = occupiedAtOutlet(everyOutlet, rule, outletId);
3817
4125
  const shared = rule.slot.sharedAcrossProducts ?? false;
3818
- const bookableUntil = windowEndsAtInZone(rule, now, timeZone ?? null);
3819
- const parts = bookingRuleParts(rule);
4126
+ const bookableUntil = windowEndsAt(rule, now);
3820
4127
  const header = {
3821
4128
  productId,
3822
4129
  bookingRulesId,
4130
+ bookingType,
3823
4131
  ratePeriod: rule.ratePeriod,
3824
- // Time slots / sessions / date ranges — so a reader never re-classifies `ratePeriod` itself.
3825
- bookingMethod: bookingMethodOf(rule),
3826
4132
  // Passed through for the UI to label: a group slot under minimumToRun may not run.
3827
4133
  minimumToRun: rule.slot.minimumToRun,
3828
4134
  minStay: rule.slot.minStay,
3829
4135
  maxStay: rule.slot.maxStay,
3830
- // The same limits with their own units, both rule shapes. `minStay` / `maxStay` above go at B13 step 9.
3831
- minStayLength: parts.method === "date-ranges" ? parts.minStay : void 0,
3832
- maxStayLength: parts.method === "date-ranges" ? parts.maxStay : void 0,
3833
- // The per-booking limits, so a stepper is bounded by the rules (G7) instead of a number in the flow.
3834
- maxQtyPerBooking: rule.slot.maxQtyPerBooking,
3835
- maxPartySize: rule.slot.maxPartySize,
3836
- // Why a day can come back empty. Past this instant the rule refuses every start, so the UI
4136
+ // Why a day can come back empty. Past this instant the rule refuses everything, so the UI
3837
4137
  // can say "beyond the booking window" where it would otherwise claim "nothing free".
3838
4138
  bookableUntil,
3839
4139
  // The comparison itself, not just the boundary: deciding whether a day lies past the
@@ -3856,7 +4156,7 @@ function buildAvailability({
3856
4156
  const byInstant = /* @__PURE__ */ new Map();
3857
4157
  const freeSlotsPerResource = /* @__PURE__ */ new Map();
3858
4158
  for (const { resource, slots: slots2 } of grids) {
3859
- const capacity = capacityOf(rule, resource);
4159
+ const capacity = resource.seats ?? 1;
3860
4160
  const mine = byResource.get(resource.id) ?? [];
3861
4161
  for (const slot of slots2) {
3862
4162
  const { taken, foreignProductId } = occupancyIn(mine, productId, slot.startAt, slot.bufferEndAt, shared);
@@ -3873,9 +4173,7 @@ function buildAvailability({
3873
4173
  entry.booked += foreignProductId ? capacity : taken;
3874
4174
  entry.free += free;
3875
4175
  entry.canStart = entry.canStart || slot.canStart;
3876
- entry.resources.push(
3877
- placesOnTheWire({ resourceId: resource.id, name: resource.name, capacity, booked: taken, free })
3878
- );
4176
+ entry.resources.push({ resourceId: resource.id, name: resource.name, capacity, booked: taken, free });
3879
4177
  if (free > 0) freeSlotsPerResource.set(resource.id, (freeSlotsPerResource.get(resource.id) ?? 0) + 1);
3880
4178
  byInstant.set(+slot.startAt, entry);
3881
4179
  }
@@ -3897,10 +4195,9 @@ function buildAvailability({
3897
4195
  )
3898
4196
  };
3899
4197
  });
3900
- const slots = [...byInstant.values()].map(placesOnTheWire).map((slot) => withMaxQtyNow(slot, slot.resources, rule.slot.maxQtyPerBooking)).sort((first, second) => +first.startAt - +second.startAt);
4198
+ const slots = [...byInstant.values()].sort((first, second) => +first.startAt - +second.startAt);
3901
4199
  return {
3902
4200
  ...header,
3903
- course: soldAsCourse(rule) ? courseAvailability(rule, resources, byResource, productId, shared, now) : void 0,
3904
4201
  resources: inWindow,
3905
4202
  slots,
3906
4203
  /**
@@ -3912,53 +4209,6 @@ function buildAvailability({
3912
4209
  days: [...new Set(slots.map((slot) => slot.dayKey))]
3913
4210
  };
3914
4211
  }
3915
- function courseAvailability(rule, resources, byResource, productId, shared, now) {
3916
- if (resources.length === 0) return void 0;
3917
- const sessions = courseSessions(rule, resources[0].timeZone);
3918
- const alreadyStarted = courseStartedInZone(rule, sessions, now, resources[0].timeZone);
3919
- const beyondWindow = startsPastMaxAdvance(rule, sessions[0].startAt, now, resources[0].timeZone);
3920
- const free = resources.map((resource) => {
3921
- const mine = byResource.get(resource.id) ?? [];
3922
- const everySession = sessions.every((session) => withinPresence(session, resource.timeZone, resource.presence));
3923
- const freePerSession = sessions.map((session) => {
3924
- const { taken, foreignProductId } = occupancyIn(mine, productId, session.startAt, session.bufferEndAt, shared);
3925
- return foreignProductId ? 0 : Math.max(capacityOf(rule, resource) - taken, 0);
3926
- });
3927
- const fewest = everySession && !alreadyStarted && !beyondWindow ? Math.min(...freePerSession) : 0;
3928
- return Number.isFinite(fewest) ? { resourceId: resource.id, free: fewest } : { resourceId: resource.id, free: UNLIMITED_PLACES, unlimited: true };
3929
- });
3930
- return withMaxQtyNow(
3931
- {
3932
- sessions: sessions.length,
3933
- alreadyStarted,
3934
- beyondWindow,
3935
- sessionTimes: sessions.map(({ startAt, endAt }) => ({ startAt, endAt })),
3936
- startAt: sessions[0].startAt,
3937
- endAt: sessions[sessions.length - 1].endAt,
3938
- resources: free
3939
- },
3940
- free,
3941
- rule.slot.maxQtyPerBooking
3942
- );
3943
- }
3944
- function pickFreeResource(slot, qty = 1) {
3945
- return slot.resources.find((entry) => entry.free >= qty);
3946
- }
3947
- function withMaxQtyNow(entry, resources, maxQtyPerBooking) {
3948
- const largest = resources.some((resource) => resource.unlimited) ? Number.POSITIVE_INFINITY : Math.max(0, ...resources.map((resource) => resource.free));
3949
- const maxQtyNow = Math.min(largest, maxQtyPerBooking ?? Number.POSITIVE_INFINITY);
3950
- return Number.isFinite(maxQtyNow) ? { ...entry, maxQtyNow } : entry;
3951
- }
3952
- function fewestFreeOver(slots, from, to) {
3953
- const cells = slots.filter(({ startAt, endAt }) => +startAt >= +from && +endAt <= +to);
3954
- if (cells.length === 0) return [];
3955
- return cells[0].resources.map((resource) => ({
3956
- ...resource,
3957
- free: Math.min(
3958
- ...cells.map((cell) => cell.resources.find(({ resourceId }) => resourceId === resource.resourceId)?.free ?? 0)
3959
- )
3960
- }));
3961
- }
3962
4212
  function presentAt(resources, rows, outletId) {
3963
4213
  const byResource = /* @__PURE__ */ new Map();
3964
4214
  for (const row of rows) {
@@ -3972,852 +4222,24 @@ function presentAt(resources, rows, outletId) {
3972
4222
  });
3973
4223
  }
3974
4224
 
3975
- // booking/durations.ts
3976
- var { MINUTE: MINUTE2, HOUR, DAY, NIGHT, WEEK, MONTH } = BookingDurationUnit;
3977
- var NONE = [];
3978
- var CLOCK = [MINUTE2, HOUR];
3979
- var everyType = (units) => Object.fromEntries(Object.values(BookingRatePeriod).map((ratePeriod) => [ratePeriod, units]));
3980
- var STAY = {
3981
- slot: NONE,
3982
- session: NONE,
3983
- hour: [HOUR, DAY, WEEK],
3984
- night: [NIGHT, WEEK, MONTH],
3985
- day: [DAY, WEEK, MONTH],
3986
- week: [WEEK],
3987
- month: [MONTH]
3988
- };
3989
- var ALLOWED_UNITS = {
3990
- "timeSlots.length": { ...everyType(NONE), slot: CLOCK },
3991
- "slot.buffer": { ...everyType(CLOCK), night: NONE },
3992
- "window.hold": everyType(CLOCK),
3993
- "window.minNotice": everyType([MINUTE2, HOUR, DAY, WEEK]),
3994
- "window.maxAdvance": everyType([MINUTE2, HOUR, DAY, WEEK, MONTH]),
3995
- "dateRanges.minStay": STAY,
3996
- "dateRanges.maxStay": STAY
3997
- };
3998
- function allowedDurationUnits(rule, field) {
3999
- const units = ALLOWED_UNITS[field]?.[rule.ratePeriod];
4000
- if (!units) throw new BookingRulesError(`Booking rules: no duration "${field}" for rate period "${rule.ratePeriod}"`);
4001
- return units;
4002
- }
4003
- var DURATION_AT = {
4004
- "timeSlots.length": (rule) => rule.timeSlots?.length,
4005
- "slot.buffer": (rule) => rule.slot.buffer,
4006
- "window.hold": (rule) => rule.window.hold,
4007
- "window.minNotice": (rule) => rule.window.minNotice,
4008
- "window.maxAdvance": (rule) => rule.window.maxAdvance,
4009
- "dateRanges.minStay": (rule) => rule.dateRanges?.minStay,
4010
- "dateRanges.maxStay": (rule) => rule.dateRanges?.maxStay
4011
- };
4012
- function durationProblems(rule) {
4013
- const problems = Object.keys(DURATION_AT).flatMap((field) => {
4014
- const duration = DURATION_AT[field](rule);
4015
- const problem = duration && problemOf(field, duration, allowedDurationUnits(rule, field), rule.ratePeriod);
4016
- return problem ? [problem] : [];
4017
- });
4018
- if (problems.length > 0) return problems;
4019
- return [stayAboveMax(rule.dateRanges?.minStay, rule.dateRanges?.maxStay), noticeAboveAdvance(rule.window)].filter(
4020
- (problem) => !!problem
4021
- );
4022
- }
4023
- function problemOf(field, duration, allowed, ratePeriod) {
4024
- if (!Number.isInteger(duration.count) || duration.count < 1) {
4025
- const message = `${field}: count must be a whole number of at least 1, got ${String(duration.count)}`;
4026
- return { field, kind: "count", message };
4027
- }
4028
- if (allowed.length === 0) {
4029
- return { field, kind: "not-for-type", message: `${field}: does not apply to ${ratePeriod} rules` };
4030
- }
4031
- if (!allowed.includes(duration.unit)) {
4032
- return { field, kind: "unit", allowed, message: `${field}: takes ${allowed.join(", ")}, got ${duration.unit}` };
4033
- }
4034
- return void 0;
4035
- }
4036
- var MINUTES_RANGE = {
4037
- minute: [1, 1],
4038
- hour: [60, 60],
4039
- day: [1440, 1440],
4040
- night: [1440, 1440],
4041
- week: [7 * 1440, 7 * 1440],
4042
- month: [28 * 1440, 31 * 1440]
4043
- };
4044
- var clockShiftOf = (unit2) => unit2 === MINUTE2 || unit2 === HOUR ? 0 : 60;
4045
- var shortestMinutesOf = ({ count, unit: unit2 }) => count * MINUTES_RANGE[unit2][0] - clockShiftOf(unit2);
4046
- var longestMinutesOf = ({ count, unit: unit2 }) => count * MINUTES_RANGE[unit2][1] + clockShiftOf(unit2);
4047
- var durationText = ({ count, unit: unit2 }) => `${count} ${unit2}${count === 1 ? "" : "s"}`;
4048
- var DAYS_IN_UNIT = { day: 1, night: 1, week: 7 };
4049
- var MINUTES_IN_UNIT = { minute: 1, hour: 60 };
4050
- function exactly(min, max) {
4051
- if (min.unit === max.unit) return [min.count, max.count];
4052
- for (const table of [DAYS_IN_UNIT, MINUTES_IN_UNIT]) {
4053
- const [minSize, maxSize] = [table[min.unit], table[max.unit]];
4054
- if (minSize && maxSize) return [min.count * minSize, max.count * maxSize];
4055
- }
4056
- return void 0;
4057
- }
4058
- function minLongerThanMax(min, max) {
4059
- const exact = exactly(min, max);
4060
- return exact ? exact[0] > exact[1] : longestMinutesOf(min) > shortestMinutesOf(max);
4061
- }
4062
- function stayAboveMax(min, max) {
4063
- if (!min || !max || !minLongerThanMax(min, max)) return void 0;
4064
- const message = `dateRanges.maxStay: Max ${durationText(max)} can be shorter than Min ${durationText(min)}`;
4065
- return { field: "dateRanges.maxStay", kind: "min-above-max", min, max, message };
4066
- }
4067
- function noticeAboveAdvance({
4068
- minNotice,
4069
- maxAdvance
4070
- }) {
4071
- if (!minNotice || !maxAdvance || !minLongerThanMax(minNotice, maxAdvance)) return void 0;
4072
- const message = `window.maxAdvance: ${durationText(maxAdvance)} ahead can be shorter than the notice of ${durationText(minNotice)}`;
4073
- return { field: "window.maxAdvance", kind: "min-above-max", min: minNotice, max: maxAdvance, message };
4074
- }
4075
-
4076
4225
  // booking/plan.ts
4077
4226
  var DEFAULT_HOLD_MINUTES = 10;
4078
4227
  function planWindow({ rule, timeZone, presence, startAt, endAt, now, busy = [] }) {
4079
- if (!soldAsCourse(rule)) checkStartWithinMaxAdvance(rule, timeZone, startAt, now);
4080
4228
  const grid = buildGrid(rule, timeZone, startAt, endAt, now, busy).filter(
4081
4229
  (slot) => withinPresence(slot, timeZone, presence)
4082
4230
  );
4083
- const slots = slotsForWindow(grid, startAt, endAt, cellChainOf(rule, timeZone));
4084
- const last = slots[slots.length - 1];
4085
- const parts = bookingRuleParts(rule);
4086
- const wholePeriods = parts.method === "date-ranges" && parts.wholePeriods;
4087
- const periods = wholePeriods ? wholePeriodsIn(rule.ratePeriod, timeZone, startAt, last.endAt, slots.length) : slots.length;
4088
- checkStay(parts, timeZone, startAt, periods);
4089
- const { buffer } = ruleDurationsOf(rule);
4090
- const bufferEndAt = rule.ratePeriod === "hour" /* HOUR */ || wholePeriods ? buffer ? addDuration(last.endAt, buffer, timeZone) : new Date(last.endAt.getTime()) : last.bufferEndAt;
4091
- return { slots, periods, endAt: last.endAt, bufferEndAt };
4092
- }
4093
- function checkStartWithinMaxAdvance(rule, timeZone, startAt, now) {
4094
- if (startsPastMaxAdvance(rule, startAt, now, timeZone)) {
4095
- throw new BookingRulesError(`${startAt.toISOString()} is past the booking window of these rules`);
4096
- }
4097
- }
4098
- function checkStay(parts, timeZone, startAt, periods) {
4099
- if (parts.method !== "date-ranges") return;
4100
- const stay = { count: periods, unit: periodUnitOf(parts) };
4101
- const length = (duration) => stayLength(parts.ratePeriod, duration, startAt, timeZone);
4102
- const { minStay, maxStay } = parts;
4103
- if (minStay && length(stay) < length(minStay)) {
4104
- throw new BookingRulesError(
4105
- `These rules ask for a stay of at least ${durationText(minStay)}, got ${durationText(stay)}`
4106
- );
4107
- }
4108
- if (maxStay && length(stay) > length(maxStay)) {
4109
- throw new BookingRulesError(
4110
- `These rules allow a stay of at most ${durationText(maxStay)}, got ${durationText(stay)}`
4111
- );
4112
- }
4113
- }
4114
- function stayLength(ratePeriod, duration, startAt, timeZone) {
4115
- if (ratePeriod === "hour" /* HOUR */) return addDuration(startAt, duration, timeZone).getTime();
4116
- const { count, unit: unit2 } = duration;
4117
- if (unit2 === "day" /* DAY */ || unit2 === "night" /* NIGHT */) return count;
4118
- if (unit2 === "week" /* WEEK */) return 7 * count;
4119
- if (unit2 !== "month" /* MONTH */) {
4120
- throw new BookingRulesError(`Booking rules: a ${ratePeriod} stay cannot be counted in ${unit2}s`);
4121
- }
4122
- const { year, month, day } = zonedParts(startAt, timeZone);
4123
- const [toYear, toMonth, toDay] = sameDayMonthsLaterDate(year, month, day, count);
4124
- return (Date.UTC(toYear, toMonth - 1, toDay) - Date.UTC(year, month - 1, day)) / 864e5;
4125
- }
4126
- function windowForPeriods({ rule, timeZone, startAt, periods, now }) {
4127
- if (!Number.isInteger(periods) || periods < 1) {
4128
- throw new BookingRulesError(`periods must be a whole number of at least 1, got ${String(periods)}`);
4129
- }
4130
- checkStartWithinMaxAdvance(rule, timeZone, startAt, now);
4131
- const parts = bookingRuleParts(rule);
4132
- checkStay(parts, timeZone, startAt, periods);
4133
- const wholePeriods = parts.method === "date-ranges" && parts.wholePeriods;
4134
- const monthsEnd = wholePeriods && rule.ratePeriod === "month" /* MONTH */ ? sameDayMonthsLater(startAt, periods, timeZone) : null;
4135
- const cells = wholePeriods && rule.ratePeriod === "week" /* WEEK */ ? periods * 7 : periods;
4136
- const lastDay = monthsEnd ?? new Date(startAt.getTime() + (cells + 2) * 1440 * 6e4);
4137
- const grid = buildGrid(
4138
- rule,
4139
- timeZone,
4140
- startAt,
4141
- new Date(Math.min(lastDay.getTime() + 1440 * 6e4, startAt.getTime() + 366 * 1440 * 6e4)),
4142
- now
4143
- );
4144
- const startIndex = grid.findIndex((cell) => cell.startAt.getTime() === startAt.getTime());
4145
- if (startIndex < 0)
4146
- throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
4147
- const endAt = monthsEnd ?? grid[startIndex + cells - 1]?.endAt;
4148
- if (!endAt)
4149
- throw new BookingRulesError(`${periods} period(s) from ${startAt.toISOString()} run past the bookable grid`);
4150
- slotsForWindow(grid, startAt, endAt, cellChainOf(rule, timeZone));
4151
- return { startAt, endAt };
4152
- }
4153
- function rentalEnds(input) {
4154
- const { rule, timeZone, startAt, now, untilDay } = input;
4155
- const parts = bookingRuleParts(rule);
4156
- if (parts.method !== "date-ranges") throw new BookingRulesError("Only date-range rules book a stay");
4157
- checkStartWithinMaxAdvance(rule, timeZone, startAt, now);
4158
- const horizon = shopDayRange(untilDay, 1, timeZone).to;
4159
- if (horizon <= startAt) throw new BookingRulesError(`untilDay ${untilDay} is before the stay starts`);
4160
- const gridUntil = (end) => buildGrid(rule, timeZone, startAt, new Date(Math.min(end, startAt.getTime() + 366 * 1440 * 6e4)), now);
4161
- let walk = walkRentalEnds(gridUntil(horizon.getTime() + 1440 * 6e4), input, parts, horizon);
4162
- if (!walk.ends.length && walk.refusal && walk.ranOut)
4163
- walk = walkRentalEnds(gridUntil(Infinity), input, parts, horizon);
4164
- if (walk.ends.length) return walk.ends;
4165
- throw walk.refusal ?? new BookingRulesError(
4166
- `No stay from ${startAt.toISOString()} fits these rules: the bookable days run out before the shortest allowed stay`
4167
- );
4168
- }
4169
- function walkRentalEnds(grid, { rule, timeZone, startAt, untilDay }, parts, horizon) {
4170
- const startIndex = grid.findIndex((cell) => cell.startAt.getTime() === startAt.getTime());
4171
- if (startIndex < 0) {
4172
- throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
4173
- }
4174
- slotsForWindow(grid, startAt, grid[startIndex].endAt);
4175
- const ends = [];
4176
- let refusal;
4177
- for (const cell of grid.slice(startIndex)) {
4178
- if (cell.endAt > horizon && (ends.length || !refusal)) {
4179
- refusal ??= new BookingRulesError(`No stay from ${startAt.toISOString()} ends on or before ${untilDay}`);
4180
- return { ends, refusal, ranOut: false };
4181
- }
4182
- const slots = refusalOr(() => slotsForWindow(grid, startAt, cell.endAt, cellChainOf(rule, timeZone)));
4183
- if (slots instanceof BookingRulesError) return { ends, refusal, ranOut: false };
4184
- const periods = refusalOr(
4185
- () => parts.wholePeriods ? wholePeriodsIn(rule.ratePeriod, timeZone, startAt, cell.endAt, slots.length) : slots.length
4186
- );
4187
- if (periods instanceof BookingRulesError) continue;
4188
- const stay = refusalOr(() => checkStay(parts, timeZone, startAt, periods));
4189
- if (stay instanceof BookingRulesError) {
4190
- if (ends.length) return { ends, refusal, ranOut: false };
4191
- refusal = stay;
4192
- continue;
4193
- }
4194
- ends.push(rentalEndOf(slots, periods, timeZone));
4195
- }
4196
- return { ends, refusal, ranOut: true };
4197
- }
4198
- function rentalEndOf(slots, periods, timeZone) {
4199
- const endAt = slots[slots.length - 1].endAt;
4200
- return {
4201
- periods,
4202
- endAt: endAt.toISOString(),
4203
- lastDayKey: shopDayKey(new Date(endAt.getTime() - 1), timeZone),
4204
- coveredSlots: slots.map((slot) => ({
4205
- startAt: slot.startAt.toISOString(),
4206
- dayKey: shopDayKey(slot.startAt, timeZone)
4207
- }))
4208
- };
4209
- }
4210
- function refusalOr(run) {
4211
- try {
4212
- return run();
4213
- } catch (error) {
4214
- if (error instanceof BookingRulesError) return error;
4215
- throw error;
4216
- }
4217
- }
4218
- function sameDayMonthsLater(startAt, months, timeZone) {
4219
- const { year, month, day } = zonedParts(startAt, timeZone);
4220
- return instantFromLocal(...sameDayMonthsLaterDate(year, month, day, months), 0, timeZone);
4221
- }
4222
- function wholePeriodsIn(ratePeriod, timeZone, startAt, endAt, days) {
4223
- if (ratePeriod === "week" /* WEEK */) {
4224
- if (days % 7 !== 0) throw new BookingRulesError(`Book whole weeks: ${days} day(s) is not a number of weeks`);
4225
- return days / 7;
4226
- }
4227
- if (ratePeriod !== "month" /* MONTH */) {
4228
- throw new BookingRulesError("Whole periods are for week and month rules only");
4229
- }
4230
- const start = zonedParts(startAt, timeZone);
4231
- const end = zonedParts(endAt, timeZone);
4232
- const months = (end.year - start.year) * 12 + (end.month - start.month);
4233
- const lastDayOfEndMonth = new Date(Date.UTC(end.year, end.month, 0)).getUTCDate();
4234
- if (months < 1 || end.day !== Math.min(start.day, lastDayOfEndMonth)) {
4235
- throw new BookingRulesError("Book whole months: the stay must end on the same day of a later month");
4236
- }
4237
- return months;
4238
- }
4239
- function courseSessions(rule, timeZone) {
4240
- const [from, to] = rule.sessions?.weekly?.length ? weeklyCourseRange(rule) : datesCourseRange(rule.sessions?.dates ?? [], timeZone);
4241
- const sessions = sessionCells(rule, timeZone, from, to).sort((first, second) => +first.startAt - +second.startAt);
4242
- if (sessions.length === 0) throw new BookingRulesError("These course dates hold no session");
4243
- return sessions;
4244
- }
4245
- function courseSpan(rule, timeZone) {
4246
- const sessions = courseSessions(rule, timeZone);
4247
- return { from: sessions[0].startAt, to: sessions[sessions.length - 1].bufferEndAt };
4248
- }
4249
- function weeklyCourseRange(rule) {
4250
- const { bookableFrom, bookableTo } = rule.window;
4251
- if (!bookableFrom || !bookableTo) throw new BookingRulesError("A course needs both course dates");
4252
- return [new Date(bookableFrom), new Date(bookableTo)];
4253
- }
4254
- function datesCourseRange(dates, timeZone) {
4255
- if (dates.length === 0) throw new BookingRulesError("A course needs its sessions");
4256
- const days = dates.map(({ date }) => date).sort();
4257
- const [firstYear, firstMonth, firstDay] = calendarDate(days[0]);
4258
- const [lastYear, lastMonth, lastDay] = calendarDate(days[days.length - 1]);
4259
- return [
4260
- instantFromLocal(firstYear, firstMonth, firstDay, 0, timeZone),
4261
- instantFromLocal(lastYear, lastMonth, lastDay + 1, 0, timeZone)
4262
- ];
4263
- }
4264
- var courseStarted = (rule, sessions, now) => sessions[0].startAt.getTime() < now.getTime() + (rule.window.minNoticeMinutes ?? 0) * 6e4;
4265
- function courseStartedInZone(rule, sessions, now, timeZone) {
4266
- const { minNotice } = ruleDurationsOf(rule);
4267
- return sessions[0].startAt.getTime() < (minNotice ? addDuration(now, minNotice, timeZone) : now).getTime();
4268
- }
4269
- function planCourse({ rule, timeZone, presence, now }) {
4270
- const sessions = courseSessions(rule, timeZone);
4271
- if (!sessions.every((session) => withinPresence(session, timeZone, presence))) {
4272
- throw new BookingRulesError("This resource is not there for every session of the course");
4273
- }
4274
- if (courseStartedInZone(rule, sessions, now, timeZone))
4275
- throw new BookingRulesError("This course has already started");
4276
- if (startsPastMaxAdvance(rule, sessions[0].startAt, now, timeZone)) {
4277
- throw new BookingRulesError("This course starts past the booking window of these rules");
4278
- }
4279
- return sessions;
4280
- }
4281
- function holdExpiresAt(rule, now) {
4282
- return addClockDuration(now, holdOf(rule) ?? DEFAULT_HOLD);
4283
- }
4284
- var DEFAULT_HOLD = { count: DEFAULT_HOLD_MINUTES, unit: "minute" /* MINUTE */ };
4285
- function holdOf(rule) {
4286
- const { hold } = ruleDurationsOf(rule);
4287
- if (!hold) return void 0;
4288
- const field = rule.window.hold ? "window.hold" : "window.holdMinutes";
4289
- if (!Number.isInteger(hold.count)) {
4290
- throw new BookingRulesError(`${field} must be a whole number of ${hold.unit}s, got ${hold.count}`);
4291
- }
4292
- if (hold.count < 1) throw new BookingRulesError(`${field} must be at least 1 ${hold.unit}, got ${hold.count}`);
4293
- return hold;
4294
- }
4295
- function checkQtyPerBooking(rule, qty) {
4296
- const max = rule.slot.maxQtyPerBooking;
4297
- if (max !== void 0 && qty > max) {
4298
- throw new BookingRulesError(`These rules allow at most ${max} per booking, got ${qty}`);
4299
- }
4300
- }
4301
- function checkPartySize(rule, partySize) {
4302
- const max = rule.slot.maxPartySize;
4303
- if (max !== void 0 && partySize > max) {
4304
- throw new BookingRulesError(`These rules allow at most ${max} people per booking, got ${partySize}`);
4305
- }
4306
- }
4307
- function bookingMethodOf(rule) {
4308
- if (rule.ratePeriod === "slot" /* SLOT */) return "time-slots";
4309
- if (rule.ratePeriod === "session" /* SESSION */) return "sessions";
4310
- return "date-ranges";
4311
- }
4312
- var soldAsCourse = (rule) => rule.ratePeriod === "session" /* SESSION */ && rule.sessions?.sold === "course" /* COURSE */;
4313
- function capacityOf(rule, resource) {
4314
- if (rule.ratePeriod !== "session" /* SESSION */) return resource.seats ?? 1;
4315
- if (!rule.sessions) throw new BookingRulesError("Scheduled-session rules need their sessions");
4316
- return rule.sessions.spots ?? Number.POSITIVE_INFINITY;
4317
- }
4318
- function bookingRuleParts(rule) {
4319
- const method = bookingMethodOf(rule);
4320
- if (method === "sessions") {
4321
- if (!rule.sessions) throw new BookingRulesError("Scheduled-session rules need their sessions");
4322
- return { method, sessions: rule.sessions };
4323
- }
4324
- if (method === "time-slots") {
4325
- const timeSlots = rule.timeSlots ? newTimeSlotsOf(rule.timeSlots) : oldTimeSlotsOf(rule);
4326
- const { count } = timeSlots.length;
4327
- if (!Number.isInteger(count) || count < 1) {
4328
- const field = rule.timeSlots ? "timeSlots.length" : "slot.lengthMinutes";
4329
- throw new BookingRulesError(`Booking rules: ${field} must be a whole number of at least 1, got ${count}`);
4330
- }
4331
- return { method, ...timeSlots };
4332
- }
4333
- if (!rule.dateRanges) return { method, ratePeriod: rule.ratePeriod, ...oldDateRangesOf(rule) };
4334
- const wholePeriods = rule.ratePeriod === "week" /* WEEK */ || rule.ratePeriod === "month" /* MONTH */;
4335
- return { method, ratePeriod: rule.ratePeriod, wholePeriods, ...rule.dateRanges };
4336
- }
4337
- function newTimeSlotsOf({ length, weeklyHours }) {
4338
- if (!weeklyHours?.length) throw new BookingRulesError("Booking rules: timeSlots.weeklyHours needs at least one day");
4339
- return { length, weeklyHours };
4340
- }
4341
- function oldTimeSlotsOf({ slot, availability }) {
4342
- if (slot.lengthMinutes == null) throw new BookingRulesError("Time-slot rules need their slot length");
4343
- return {
4344
- length: { count: slot.lengthMinutes, unit: "minute" /* MINUTE */ },
4345
- weeklyHours: availability.weeklyHours ?? []
4346
- };
4347
- }
4348
- function oldDateRangesOf(rule) {
4349
- const { slot, availability } = rule;
4350
- const wholePeriods = slot.wholePeriods ?? false;
4351
- const stay = (count) => count ? { count, unit: periodUnitOf({ ratePeriod: rule.ratePeriod, wholePeriods }) } : void 0;
4352
- return {
4353
- // Old `[]` meant "open every day" — the new form says that by having no rows.
4354
- weeklyHours: availability.weeklyHours?.length ? availability.weeklyHours : void 0,
4355
- arrivalDays: availability.arrivalDays,
4356
- checkInTime: rule.checkInTime,
4357
- checkOutTime: rule.checkOutTime,
4358
- checkTimesByWeekday: rule.checkTimesByWeekday,
4359
- minStay: stay(slot.minStay),
4360
- maxStay: stay(slot.maxStay),
4361
- wholePeriods
4362
- };
4363
- }
4364
- function periodUnitOf({
4365
- ratePeriod,
4366
- wholePeriods
4367
- }) {
4368
- const units = {
4369
- ["hour" /* HOUR */]: "hour" /* HOUR */,
4370
- ["night" /* NIGHT */]: "night" /* NIGHT */,
4371
- ["day" /* DAY */]: "day" /* DAY */,
4372
- ["week" /* WEEK */]: wholePeriods ? "week" /* WEEK */ : "day" /* DAY */,
4373
- ["month" /* MONTH */]: wholePeriods ? "month" /* MONTH */ : "day" /* DAY */
4374
- };
4375
- const unit2 = units[ratePeriod];
4376
- if (!unit2) throw new BookingRulesError(`Booking rules: "${ratePeriod}" is not a date-range rate period`);
4377
- return unit2;
4378
- }
4379
- var OLD_BUFFER = {
4380
- path: "slot.bufferMinutes",
4381
- home: {
4382
- "time-slots": "slot.buffer",
4383
- sessions: "slot.buffer",
4384
- // The old night grid never read it: housekeeping is the gap between check-out and check-in (O-1).
4385
- "date-ranges": ({ ratePeriod }) => ratePeriod === "night" /* NIGHT */ ? { unread: "nights clean between check-out and check-in" } : "slot.buffer"
4386
- }
4387
- };
4388
- var OLD_FIELDS = [
4389
- {
4390
- path: "slot.lengthMinutes",
4391
- home: {
4392
- "time-slots": "timeSlots.length",
4393
- sessions: { unread: "placeholder" },
4394
- "date-ranges": { unread: "placeholder" }
4395
- }
4396
- },
4397
- OLD_BUFFER,
4398
- {
4399
- path: "slot.minStay",
4400
- home: {
4401
- "time-slots": { dropped: "time-slots rules have no stay limits" },
4402
- sessions: { dropped: "sessions rules have no stay limits" },
4403
- "date-ranges": "dateRanges.minStay"
4404
- }
4405
- },
4406
- {
4407
- path: "slot.maxStay",
4408
- home: {
4409
- "time-slots": { dropped: "time-slots rules have no stay limits" },
4410
- sessions: { dropped: "sessions rules have no stay limits" },
4411
- "date-ranges": "dateRanges.maxStay"
4412
- }
4413
- },
4414
- {
4415
- path: "window.holdMinutes",
4416
- home: { "time-slots": "window.hold", sessions: "window.hold", "date-ranges": "window.hold" }
4417
- },
4418
- {
4419
- path: "window.minNoticeMinutes",
4420
- home: { "time-slots": "window.minNotice", sessions: "window.minNotice", "date-ranges": "window.minNotice" }
4421
- },
4422
- // The two old max-advance fields are one fact, as the old readers took it: minutes, else days × 1440.
4423
- ...["window.maxAdvanceMinutes", "window.maxAdvanceDays"].map((path) => ({
4424
- path,
4425
- carried: maxAdvanceMinutesOf,
4426
- home: { "time-slots": "window.maxAdvance", sessions: "window.maxAdvance", "date-ranges": "window.maxAdvance" }
4427
- })),
4428
- {
4429
- path: "availability.weeklyHours",
4430
- home: {
4431
- "time-slots": "timeSlots.weeklyHours",
4432
- sessions: { unread: "sessions read their timetable" },
4433
- "date-ranges": "dateRanges.weeklyHours"
4434
- }
4435
- },
4436
- {
4437
- path: "availability.arrivalDays",
4438
- home: {
4439
- "time-slots": { unread: "date ranges only" },
4440
- sessions: { unread: "date ranges only" },
4441
- "date-ranges": "dateRanges.arrivalDays"
4442
- }
4443
- },
4444
- // An `opening-hours` night has no check times (FC-1503): switching to it drops the old ones, said in a note.
4445
- ...["checkInTime", "checkOutTime", "checkTimesByWeekday"].map((path) => ({
4446
- path,
4447
- home: {
4448
- "time-slots": { unread: "date ranges only" },
4449
- sessions: { unread: "date ranges only" },
4450
- "date-ranges": ({ dateRanges }) => dateRanges?.arriveLeave === "opening-hours" /* OPENING_HOURS */ ? { dropped: "opening-hours nights have no check times" } : `dateRanges.${path}`
4451
- }
4452
- }))
4453
- ];
4454
- var homeOf = (field, rule) => {
4455
- const home = field.home[bookingMethodOf(rule)];
4456
- return typeof home === "function" ? home(rule) : home;
4457
- };
4458
- var carriedValueOf = (rule, field) => field.carried ? field.carried(rule) : valueAt(rule, field.path);
4459
- var carries = (value) => value != null && value !== 0 && !(Array.isArray(value) && value.length === 0);
4460
- function ruleInNewShape(rule) {
4461
- const set = { ...typePartInNewShape(rule), ...durationsInNewShape(rule) };
4462
- const unset = [...OLD_FIELDS.map(({ path }) => path), "slot.wholePeriods"].filter(
4463
- (path) => valueAt(rule, path) !== void 0
4464
- );
4465
- const written = writtenRule(rule, set, unset);
4466
- bookingRuleParts(written);
4467
- refuseLostValues(rule, written);
4468
- const changesBehaviour = sellsOneDayOfWeekOrMonth(rule) ? "whole-periods" : void 0;
4469
- const notes = [
4470
- ...droppedFieldNotes(rule, written),
4471
- ...changesBehaviour ? [`${rule.ratePeriod} rule now sells whole ${rule.ratePeriod}s, was one day per booking`] : []
4472
- ];
4473
- return { set, unset, problems: durationProblems(written), notes, ...changesBehaviour && { changesBehaviour } };
4474
- }
4475
- function typePartInNewShape(rule) {
4476
- const method = bookingMethodOf(rule);
4477
- if (method === "sessions") return {};
4478
- if (method === "time-slots") return { timeSlots: newTimeSlotsOf(rule.timeSlots ?? oldTimeSlotsOf(rule)) };
4479
- if (rule.dateRanges) return { dateRanges: rule.dateRanges };
4480
- const dateRanges = oldDateRangesOf(rule);
4481
- delete dateRanges.wholePeriods;
4482
- return { dateRanges: definedOnly(dateRanges) };
4483
- }
4484
- function durationsInNewShape(rule) {
4485
- const { buffer, minNotice } = ruleDurationsOf(rule);
4486
- return definedOnly({
4487
- "slot.buffer": rule.slot.buffer ?? (typeof homeOf(OLD_BUFFER, rule) === "string" ? buffer : void 0),
4488
- "window.hold": holdOf(rule) ?? DEFAULT_HOLD,
4489
- "window.minNotice": minNotice,
4490
- "window.maxAdvance": ruleDurationsOf(rule).maxAdvance
4491
- });
4492
- }
4493
- var sellsOneDayOfWeekOrMonth = ({ ratePeriod, slot, dateRanges }) => !dateRanges && (ratePeriod === "week" /* WEEK */ || ratePeriod === "month" /* MONTH */) && !slot.wholePeriods;
4494
- function droppedFieldNotes(rule, written) {
4495
- const weekOrMonth = rule.ratePeriod === "week" /* WEEK */ || rule.ratePeriod === "month" /* MONTH */;
4496
- return [
4497
- ...OLD_FIELDS.flatMap((field) => {
4498
- const home = homeOf(field, rule);
4499
- const dropped = typeof home === "object" && "dropped" in home && carries(carriedValueOf(rule, field));
4500
- return dropped ? [`${field.path} is dropped: ${home.dropped}`] : [];
4501
- }),
4502
- ...rule.slot.wholePeriods && !weekOrMonth ? ["slot.wholePeriods is dropped: only week and month rules have it"] : [],
4503
- ...rule.ratePeriod === "hour" /* HOUR */ && !written.dateRanges?.weeklyHours?.length ? ["hour rule has no opening hours: nothing can be booked"] : [],
4504
- ...rule.window.holdMinutes == null && !rule.window.hold ? [`window.hold is set to the default ${DEFAULT_HOLD_MINUTES} minutes`] : []
4505
- ];
4506
- }
4507
- function writtenRule(rule, set, unset) {
4508
- const written = {
4509
- ...rule,
4510
- slot: { ...rule.slot },
4511
- window: { ...rule.window },
4512
- availability: { ...rule.availability }
4513
- };
4514
- for (const path of unset) {
4515
- const [head, leaf] = path.split(".");
4516
- if (leaf) delete written[head][leaf];
4517
- else delete written[head];
4518
- }
4519
- for (const [path, value] of Object.entries(set)) {
4520
- const [head, leaf] = path.split(".");
4521
- if (leaf) written[head][leaf] = value;
4522
- else written[head] = value;
4523
- }
4524
- return written;
4525
- }
4526
- function refuseLostValues(rule, written) {
4527
- for (const field of OLD_FIELDS) {
4528
- const home = homeOf(field, rule);
4529
- if (typeof home === "string" && carries(carriedValueOf(rule, field)) && valueAt(written, home) == null) {
4530
- throw new BookingRulesError(`Booking rules: ${home} is missing \u2014 the rule's old value would be lost`);
4531
- }
4532
- }
4533
- }
4534
- var definedOnly = (value) => Object.fromEntries(Object.entries(value).filter(([, entry]) => entry != null));
4535
- var valueAt = (rule, path) => path.split(".").reduce((node, key) => node?.[key], rule);
4536
-
4537
- // booking/grid.ts
4538
- var MINUTE3 = 6e4;
4539
- var HOUR_MINUTES = 60;
4540
- var MAX_RANGE_DAYS = 366;
4541
- var asTime = (value, field) => {
4542
- if (value == null) return void 0;
4543
- const time = new Date(value).getTime();
4544
- if (Number.isNaN(time)) throw new BookingRulesError(`Booking rules: ${field} is not a date, got "${String(value)}"`);
4545
- return time;
4546
- };
4547
- function parseHhMm(value, field) {
4548
- const [hours, minutes] = value.split(":").map(Number);
4549
- if (!Number.isInteger(hours) || !Number.isInteger(minutes)) {
4550
- throw new BookingRulesError(`Booking rules: ${field} must be "HH:mm", got "${value}"`);
4551
- }
4552
- return hours * 60 + minutes;
4553
- }
4554
- function windowEndsAt(rule, now) {
4555
- const maxAdvanceMinutes = maxAdvanceMinutesOf(rule);
4556
- const ends = Math.min(
4557
- maxAdvanceMinutes ? now.getTime() + maxAdvanceMinutes * MINUTE3 : Number.POSITIVE_INFINITY,
4558
- asTime(rule.window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
4559
- );
4560
- return Number.isFinite(ends) ? new Date(ends) : null;
4561
- }
4562
- function windowEndsAtInZone(rule, now, timeZone) {
4563
- const ends = Math.min(
4564
- lastStartOf(rule, now, timeZone),
4565
- asTime(rule.window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY
4566
- );
4567
- return Number.isFinite(ends) ? new Date(ends) : null;
4568
- }
4569
- function lastStartOf(rule, now, timeZone) {
4570
- const { maxAdvance } = ruleDurationsOf(rule);
4571
- if (!maxAdvance) return Number.POSITIVE_INFINITY;
4572
- const reached = addInZone(now, maxAdvance, timeZone, "window.maxAdvance");
4573
- if (maxAdvance.unit === "minute" /* MINUTE */ || maxAdvance.unit === "hour" /* HOUR */) {
4574
- return reached.getTime();
4575
- }
4576
- const zone = timeZone;
4577
- return nextZonedDay(startOfZonedDay(reached, zone), zone).getTime() - 1;
4578
- }
4579
- var startsPastMaxAdvance = (rule, startAt, now, timeZone) => startAt.getTime() > lastStartOf(rule, now, timeZone);
4580
- function addInZone(from, duration, timeZone, field) {
4581
- if (timeZone) return addDuration(from, duration, timeZone);
4582
- if (duration.unit === "minute" /* MINUTE */ || duration.unit === "hour" /* HOUR */) {
4583
- return addClockDuration(from, duration);
4584
- }
4585
- throw new BookingRulesError(`Booking rules: ${field} in ${duration.unit}s needs the shop's time zone`);
4586
- }
4587
- function maxAdvanceMinutesOf(rule) {
4588
- const { maxAdvanceMinutes, maxAdvanceDays } = rule.window;
4589
- return maxAdvanceMinutes ?? (maxAdvanceDays ?? 0) * 1440;
4590
- }
4591
- var asMinutes = (minutes) => minutes == null ? void 0 : { count: minutes, unit: "minute" /* MINUTE */ };
4592
- var inMinutes = (minutes) => minutes === 0 ? void 0 : asMinutes(minutes);
4593
- function notNegative(duration, field) {
4594
- if (duration && !(Number.isFinite(duration.count) && duration.count >= 0)) {
4595
- throw new BookingRulesError(`Booking rules: ${field} must be a number of at least 0, got ${duration.count}`);
4596
- }
4597
- return duration;
4598
- }
4599
- function ruleDurationsOf(rule) {
4600
- const { slot, window } = rule;
4601
- return {
4602
- buffer: notNegative(
4603
- slot.buffer ?? inMinutes(slot.bufferMinutes),
4604
- slot.buffer ? "slot.buffer" : "slot.bufferMinutes"
4605
- ),
4606
- hold: window.hold ?? asMinutes(window.holdMinutes),
4607
- minNotice: notNegative(
4608
- window.minNotice ?? inMinutes(window.minNoticeMinutes),
4609
- window.minNotice ? "window.minNotice" : "window.minNoticeMinutes"
4610
- ),
4611
- maxAdvance: window.maxAdvance ?? oldMaxAdvanceOf(window)
4612
- };
4613
- }
4614
- function oldMaxAdvanceOf({
4615
- maxAdvanceMinutes,
4616
- maxAdvanceDays
4617
- }) {
4618
- const days = maxAdvanceDays ?? 0;
4619
- if (maxAdvanceMinutes == null || days > 0 && maxAdvanceMinutes === days * 1440) {
4620
- return days > 0 ? { count: days, unit: "day" /* DAY */ } : void 0;
4621
- }
4622
- return maxAdvanceMinutes ? { count: maxAdvanceMinutes, unit: "minute" /* MINUTE */ } : void 0;
4623
- }
4624
- function periodSlot(dayStart, timeZone, parts, buffer, openMinute, closeMinute) {
4625
- const { ratePeriod } = parts;
4626
- const at = (minutes) => atZonedMinute(dayStart, minutes, timeZone);
4627
- if (ratePeriod === "night" /* NIGHT */ && parts.arriveLeave !== "opening-hours" /* OPENING_HOURS */) {
4628
- const arrival = zonedParts(dayStart, timeZone).weekday;
4629
- const departure = (arrival + 1) % 7;
4630
- return {
4631
- startAt: at(checkTimesOf(parts, arrival).checkIn),
4632
- endAt: at(1440 + checkTimesOf(parts, departure).checkOut),
4633
- // Housekeeping sits between check-out and the next check-in: it costs no night.
4634
- bufferEndAt: at(1440 + checkTimesOf(parts, departure).checkIn),
4635
- canStart: true
4636
- };
4637
- }
4638
- const from = ratePeriod === "day" /* DAY */ ? openMinute ?? 0 : 0;
4639
- const to = ratePeriod === "day" /* DAY */ ? closeMinute ?? 1440 : 1440;
4640
- const turnaround = parts.wholePeriods || ratePeriod === "night" /* NIGHT */ ? void 0 : buffer;
4641
- return {
4642
- startAt: at(from),
4643
- endAt: at(to),
4644
- bufferEndAt: turnaround ? addDuration(at(to), turnaround, timeZone) : at(to),
4645
- canStart: true
4646
- };
4647
- }
4648
- function checkTimesOf(rule, weekday) {
4649
- const row = rule.checkTimesByWeekday?.find((entry) => entry.weekday === weekday);
4650
- const checkInTime = row?.checkInTime ?? rule.checkInTime;
4651
- const checkOutTime = row?.checkOutTime ?? rule.checkOutTime;
4652
- if (!checkInTime || !checkOutTime) {
4653
- throw new BookingRulesError("Overnight booking rules need both checkInTime and checkOutTime");
4654
- }
4655
- return { checkIn: parseHhMm(checkInTime, "checkInTime"), checkOut: parseHhMm(checkOutTime, "checkOutTime") };
4656
- }
4657
- function freeGaps(openAt, closeAt, busy) {
4658
- const inside = busy.map(({ startAt, bufferEndAt }) => ({ from: +startAt, to: +bufferEndAt })).filter(({ from, to }) => to > openAt && from < closeAt).sort((first, second) => first.from - second.from);
4659
- const gaps = [];
4660
- let cursor = openAt;
4661
- for (const { from, to } of inside) {
4662
- if (from > cursor) gaps.push({ from: cursor, to: from, endsAtBooking: true });
4663
- cursor = Math.max(cursor, to);
4664
- if (cursor >= closeAt) break;
4665
- }
4666
- if (cursor < closeAt) gaps.push({ from: cursor, to: closeAt, endsAtBooking: false });
4667
- return gaps;
4668
- }
4669
- function sessionCells(rule, timeZone, from, to) {
4670
- if (!rule.sessions) throw new BookingRulesError("Scheduled-session rules need their sessions");
4671
- const { weekly = [], dates = [] } = rule.sessions;
4672
- const { buffer } = ruleDurationsOf(rule);
4673
- const cell = (startAt, endAt) => ({
4674
- startAt: new Date(startAt),
4675
- endAt: new Date(endAt),
4676
- bufferEndAt: buffer ? addDuration(new Date(endAt), buffer, timeZone) : new Date(endAt),
4677
- canStart: true
4678
- });
4679
- const cells = dates.map(({ date, startMinute, endMinute }) => {
4680
- const [year, month, day] = calendarDate(date);
4681
- return cell(
4682
- +instantFromLocal(year, month, day, startMinute, timeZone),
4683
- +instantFromLocal(year, month, day, endMinute, timeZone)
4684
- );
4685
- });
4686
- const lastDay = startOfZonedDay(to, timeZone).getTime();
4687
- for (let day = startOfZonedDay(from, timeZone); day.getTime() <= lastDay; day = nextZonedDay(day, timeZone)) {
4688
- const weekday = zonedParts(day, timeZone).weekday;
4689
- for (const row of weekly.filter((entry) => entry.weekday === weekday)) {
4690
- cells.push(cell(+atZonedMinute(day, row.startMinute, timeZone), +atZonedMinute(day, row.endMinute, timeZone)));
4691
- }
4692
- }
4693
- const blocked = offMarketOf(rule);
4694
- return cells.filter(({ startAt, bufferEndAt }) => {
4695
- const start = startAt.getTime();
4696
- return start >= from.getTime() && start <= to.getTime() && !isBlocked(blocked, start, bufferEndAt.getTime());
4697
- });
4698
- }
4699
- function calendarDate(value) {
4700
- const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value ?? "");
4701
- const [year, month, day] = match ? match.slice(1).map(Number) : [];
4702
- const real = match && new Date(Date.UTC(year, month - 1, day)).toISOString().slice(0, 10) === value;
4703
- if (!real) throw new BookingRulesError(`Booking rules: "${value}" is not a date (YYYY-MM-DD)`);
4704
- return [year, month, day];
4705
- }
4706
- var offMarketOf = (rule) => (rule.availability.offMarket ?? []).map(({ from: blockFrom, to: blockTo }) => ({
4707
- from: asTime(blockFrom, "availability.offMarket.from"),
4708
- to: asTime(blockTo, "availability.offMarket.to")
4709
- }));
4710
- var isBlocked = (blocked, start, bufferEnd) => blocked.some(({ from, to }) => start < to && bufferEnd > from);
4711
- function hourCells(openAt, closeAt) {
4712
- const cells = [];
4713
- for (let start = openAt; start + HOUR_MINUTES * MINUTE3 <= closeAt; start += HOUR_MINUTES * MINUTE3) {
4714
- const endAt = new Date(start + HOUR_MINUTES * MINUTE3);
4715
- cells.push({ startAt: new Date(start), endAt, bufferEndAt: endAt, canStart: true });
4716
- }
4717
- return cells;
4718
- }
4719
- function cellsOf(rule, parts, timeZone, from, to, busy) {
4720
- if (parts.method === "sessions") return sessionCells(rule, timeZone, from, to);
4721
- const { buffer } = ruleDurationsOf(rule);
4722
- const cells = [];
4723
- const lastDay = startOfZonedDay(to, timeZone).getTime();
4724
- for (let day = startOfZonedDay(from, timeZone); day.getTime() <= lastDay; day = nextZonedDay(day, timeZone)) {
4725
- cells.push(
4726
- ...parts.method === "time-slots" ? timeSlotCells(parts, buffer, day, timeZone, busy) : periodCells(parts, buffer, day, timeZone)
4727
- );
4728
- }
4729
- return cells;
4730
- }
4731
- function timeSlotCells(parts, buffer, dayStart, timeZone, busy) {
4732
- const weekday = zonedParts(dayStart, timeZone).weekday;
4733
- return parts.weeklyHours.filter((entry) => entry.weekday === weekday).flatMap(
4734
- (row) => freeGaps(
4735
- +atZonedMinute(dayStart, row.openMinute, timeZone),
4736
- +atZonedMinute(dayStart, row.closeMinute, timeZone),
4737
- busy
4738
- ).flatMap((gap) => cellsInGap(gap, parts.length, buffer, timeZone))
4739
- );
4740
- }
4741
- function cellsInGap(gap, length, buffer, timeZone) {
4742
- const cells = [];
4743
- for (let start = gap.from; ; ) {
4744
- const endAt = addDuration(new Date(start), length, timeZone);
4745
- const bufferEndAt = buffer ? addDuration(endAt, buffer, timeZone) : new Date(endAt.getTime());
4746
- if ((gap.endsAtBooking ? bufferEndAt : endAt).getTime() > gap.to) return cells;
4747
- cells.push({ startAt: new Date(start), endAt, bufferEndAt, canStart: true });
4748
- start = bufferEndAt.getTime();
4749
- }
4750
- }
4751
- function periodCells(parts, buffer, dayStart, timeZone) {
4752
- const weekday = zonedParts(dayStart, timeZone).weekday;
4753
- const rows = (parts.weeklyHours ?? []).filter((entry) => entry.weekday === weekday);
4754
- if (parts.ratePeriod === "hour" /* HOUR */) {
4755
- return rows.flatMap(
4756
- (row) => hourCells(
4757
- +atZonedMinute(dayStart, row.openMinute, timeZone),
4758
- +atZonedMinute(dayStart, row.closeMinute, timeZone)
4759
- )
4760
- );
4761
- }
4762
- if (parts.weeklyHours?.length && rows.length === 0) return [];
4763
- const built = periodSlot(dayStart, timeZone, parts, buffer, rows[0]?.openMinute, rows[0]?.closeMinute);
4764
- return [{ ...built, canStart: !parts.arrivalDays?.length || parts.arrivalDays.includes(weekday) }];
4765
- }
4766
- function buildGrid(rule, timeZone, from, to, now, busy = []) {
4767
- if (to.getTime() - from.getTime() > MAX_RANGE_DAYS * 1440 * MINUTE3) {
4768
- throw new BookingRulesError(`A booking range may span at most ${MAX_RANGE_DAYS} days`);
4769
- }
4770
- const { availability, window } = rule;
4771
- const { minNotice } = ruleDurationsOf(rule);
4772
- const notBefore = Math.max(
4773
- (minNotice ? addDuration(now, minNotice, timeZone) : now).getTime(),
4774
- asTime(window.bookableFrom, "window.bookableFrom") ?? 0,
4775
- asTime(availability.availableFrom, "availability.availableFrom") ?? 0
4776
- );
4777
- const notAfter = asTime(window.bookableTo, "window.bookableTo") ?? Number.POSITIVE_INFINITY;
4778
- const lastStart = lastStartOf(rule, now, timeZone);
4779
- const blocked = offMarketOf(rule);
4780
- const slots = cellsOf(rule, bookingRuleParts(rule), timeZone, from, to, busy);
4781
- const askedFrom = from.getTime();
4782
- const askedTo = to.getTime();
4783
- return slots.filter(({ startAt, bufferEndAt }) => {
4784
- const start = startAt.getTime();
4785
- if (start < askedFrom || start >= askedTo) return false;
4786
- if (start < notBefore || start > notAfter) return false;
4787
- return !isBlocked(blocked, start, bufferEndAt.getTime());
4788
- }).flatMap((cell) => cell.startAt.getTime() > lastStart ? pastMaxAdvance(cell, rule) : [cell]).sort((first, second) => +first.startAt - +second.startAt);
4789
- }
4790
- function pastMaxAdvance(cell, rule) {
4791
- if (soldAsCourse(rule)) return [cell];
4792
- return bookingMethodOf(rule) === "date-ranges" ? [{ ...cell, canStart: false }] : [];
4793
- }
4794
- var endToStart = (previous, next) => next.startAt.getTime() === previous.bufferEndAt.getTime();
4795
- function cellChainOf(rule, timeZone) {
4796
- if (rule.ratePeriod !== "day" /* DAY */) return endToStart;
4797
- const dayOf = (slot) => startOfZonedDay(slot.startAt, timeZone);
4798
- return (previous, next) => +dayOf(next) === +nextZonedDay(dayOf(previous), timeZone);
4799
- }
4800
- function slotsForWindow(grid, startAt, endAt, chain = endToStart) {
4801
- const startIndex = grid.findIndex((entry) => entry.startAt.getTime() === startAt.getTime());
4802
- if (startIndex < 0) {
4803
- throw new BookingRulesError(`${startAt.toISOString()} is not a bookable slot start for these rules`);
4804
- }
4805
- if (!grid[startIndex].canStart) {
4806
- throw new BookingRulesError(`${startAt.toISOString()} is not an arrival day for these rules`);
4231
+ const slots = slotsForWindow(grid, startAt, endAt);
4232
+ const { minStay, maxStay } = rule.slot;
4233
+ if (minStay && slots.length < minStay) {
4234
+ throw new BookingRulesError(`These rules ask for at least ${minStay} period(s), got ${slots.length}`);
4807
4235
  }
4808
- const covered = [];
4809
- for (let index = startIndex; index < grid.length; index++) {
4810
- const entry = grid[index];
4811
- const previous = covered[covered.length - 1];
4812
- if (previous && !chain(previous, entry)) break;
4813
- covered.push(entry);
4814
- if (entry.endAt.getTime() === endAt.getTime()) return covered;
4815
- if (entry.endAt.getTime() > endAt.getTime()) break;
4236
+ if (maxStay && slots.length > maxStay) {
4237
+ throw new BookingRulesError(`These rules allow at most ${maxStay} period(s), got ${slots.length}`);
4816
4238
  }
4817
- throw new BookingRulesError(
4818
- `${startAt.toISOString()} \u2192 ${endAt.toISOString()} does not line up with the bookable grid`
4819
- );
4239
+ const last = slots[slots.length - 1];
4240
+ return { slots, endAt: last.endAt, bufferEndAt: last.bufferEndAt };
4820
4241
  }
4242
+ var holdExpiresAt = (rule, now) => new Date(now.getTime() + (rule.window.holdMinutes ?? DEFAULT_HOLD_MINUTES) * 6e4);
4821
4243
 
4822
4244
  // shipping/fold-text.ts
4823
4245
  function foldText(value) {
@@ -5083,6 +4505,8 @@ function quote(option, zoneId, itemsTotal) {
5083
4505
  amountToFree: freeOver != null && amount > 0 ? freeOver - itemsTotal : null,
5084
4506
  minDays: option.minDays ?? null,
5085
4507
  maxDays: option.maxDays ?? null,
4508
+ minMinutes: option.minMinutes ?? null,
4509
+ maxMinutes: option.maxMinutes ?? null,
5086
4510
  outletId: option.outletId ?? null
5087
4511
  };
5088
4512
  }
@@ -5097,6 +4521,21 @@ function countriesShippedTo(zones) {
5097
4521
  return [...countries].sort();
5098
4522
  }
5099
4523
 
4524
+ // shipping/time.ts
4525
+ function shippingDuration(minMinutes, maxMinutes) {
4526
+ const min = minMinutes ?? maxMinutes;
4527
+ const max = maxMinutes ?? minMinutes;
4528
+ if (min == null || max == null) return null;
4529
+ const wholeHours = max > 0 && min % 60 === 0 && max % 60 === 0;
4530
+ return wholeHours ? { unit: "hour", min: min / 60, max: max / 60 } : { unit: "minute", min, max };
4531
+ }
4532
+ function formatShippingDuration(minMinutes, maxMinutes, locale, display = "long") {
4533
+ const duration = shippingDuration(minMinutes, maxMinutes);
4534
+ if (!duration) return null;
4535
+ const unit2 = new Intl.NumberFormat(locale ?? "en", { style: "unit", unit: duration.unit, unitDisplay: display });
4536
+ return duration.min === duration.max ? unit2.format(duration.max) : `${duration.min}\u2013${unit2.format(duration.max)}`;
4537
+ }
4538
+
5100
4539
  // shipping/validate.ts
5101
4540
  function validateShippingZone(zone) {
5102
4541
  const problems = [...placeProblems(zone)];
@@ -5125,7 +4564,15 @@ function fitsKind(place, kind) {
5125
4564
  return false;
5126
4565
  }
5127
4566
  var isAmount = (value) => Number.isInteger(value) && value >= 0;
5128
- var isDays = (value) => value == null || isAmount(value);
4567
+ var isTime = (value) => value == null || isAmount(value);
4568
+ var inOrder = (min, max) => (min ?? 0) <= (max ?? Infinity);
4569
+ function timeIsValid(option) {
4570
+ const { minDays, maxDays, minMinutes, maxMinutes } = option;
4571
+ if (![minDays, maxDays, minMinutes, maxMinutes].every(isTime)) return false;
4572
+ const hasDays = minDays != null || maxDays != null;
4573
+ const hasMinutes = minMinutes != null || maxMinutes != null;
4574
+ return !(hasDays && hasMinutes) && inOrder(minDays, maxDays) && inOrder(minMinutes, maxMinutes);
4575
+ }
5129
4576
  function optionProblems(option) {
5130
4577
  const problems = [];
5131
4578
  const isPickup = option.type === "pickup" /* PICKUP */;
@@ -5133,9 +4580,7 @@ function optionProblems(option) {
5133
4580
  problems.push("INVALID_PRICE" /* INVALID_PRICE */);
5134
4581
  }
5135
4582
  if (!isPickup && !option.name?.trim()) problems.push("MISSING_NAME" /* MISSING_NAME */);
5136
- if (!isDays(option.minDays) || !isDays(option.maxDays) || (option.minDays ?? 0) > (option.maxDays ?? Infinity)) {
5137
- problems.push("INVALID_DAYS" /* INVALID_DAYS */);
5138
- }
4583
+ if (!timeIsValid(option)) problems.push("INVALID_DAYS" /* INVALID_DAYS */);
5139
4584
  if (!tiersAreValid(option)) problems.push("INVALID_TIERS" /* INVALID_TIERS */);
5140
4585
  if (option.channels.length === 0) problems.push("NO_CHANNEL" /* NO_CHANNEL */);
5141
4586
  if (isPickup && !option.outletId) problems.push("PICKUP_WITHOUT_STORE" /* PICKUP_WITHOUT_STORE */);
@@ -5147,6 +4592,224 @@ function tiersAreValid(option) {
5147
4592
  return tiers.every((tier) => Number.isInteger(tier.from) && tier.from > 0 && isAmount(tier.price)) && new Set(froms).size === froms.length;
5148
4593
  }
5149
4594
 
4595
+ // tax/sha1.ts
4596
+ function utf8Bytes(text) {
4597
+ const bytes = [];
4598
+ for (const char of text) {
4599
+ const cp = char.codePointAt(0);
4600
+ if (cp < 128) bytes.push(cp);
4601
+ else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
4602
+ else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
4603
+ else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
4604
+ }
4605
+ return bytes;
4606
+ }
4607
+ var rotl = (x, n) => x << n | x >>> 32 - n;
4608
+ function sha1Hex(text) {
4609
+ const bytes = utf8Bytes(text);
4610
+ const bitLength = bytes.length * 8;
4611
+ bytes.push(128);
4612
+ while (bytes.length % 64 !== 56) bytes.push(0);
4613
+ const high = Math.floor(bitLength / 4294967296);
4614
+ for (const word of [high, bitLength >>> 0])
4615
+ bytes.push(word >>> 24 & 255, word >>> 16 & 255, word >>> 8 & 255, word & 255);
4616
+ const h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
4617
+ const w = new Array(80);
4618
+ for (let offset = 0; offset < bytes.length; offset += 64) {
4619
+ for (let i = 0; i < 16; i++) {
4620
+ const j = offset + i * 4;
4621
+ w[i] = bytes[j] << 24 | bytes[j + 1] << 16 | bytes[j + 2] << 8 | bytes[j + 3];
4622
+ }
4623
+ for (let i = 16; i < 80; i++) w[i] = rotl(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
4624
+ let [a, b, c, d, e] = h;
4625
+ for (let i = 0; i < 80; i++) {
4626
+ const [f, k] = i < 20 ? [b & c | ~b & d, 1518500249] : i < 40 ? [b ^ c ^ d, 1859775393] : i < 60 ? [b & c | b & d | c & d, 2400959708] : [b ^ c ^ d, 3395469782];
4627
+ const t = rotl(a, 5) + f + e + k + w[i] | 0;
4628
+ e = d;
4629
+ d = c;
4630
+ c = rotl(b, 30);
4631
+ b = a;
4632
+ a = t;
4633
+ }
4634
+ h[0] = h[0] + a | 0;
4635
+ h[1] = h[1] + b | 0;
4636
+ h[2] = h[2] + c | 0;
4637
+ h[3] = h[3] + d | 0;
4638
+ h[4] = h[4] + e | 0;
4639
+ }
4640
+ return h.map((x) => (x >>> 0).toString(16).padStart(8, "0")).join("");
4641
+ }
4642
+
4643
+ // tax/table.ts
4644
+ var STANDARD_TAX_TYPE = "standard";
4645
+ var TYPE_FIELDS = ["key", "name", "description", "sortOrder", "active"];
4646
+ var RATE_FIELDS = [
4647
+ "code",
4648
+ "name",
4649
+ "kind",
4650
+ "places",
4651
+ "rate",
4652
+ "from",
4653
+ "to",
4654
+ "order",
4655
+ "compound",
4656
+ "registrationPlace",
4657
+ "harmonized",
4658
+ "parts",
4659
+ "sourceUrl",
4660
+ "status"
4661
+ ];
4662
+ var RULE_FIELDS = ["taxType", "codes", "rate", "from", "to", "sourceUrl", "status", "note"];
4663
+ function canonical(row, fields) {
4664
+ return JSON.stringify(fields.map((field) => row[field] ?? null));
4665
+ }
4666
+ var sortedCanonical = (rows, fields) => rows.map((row) => canonical(row, fields)).sort();
4667
+ function automaticTaxTableVersion(table) {
4668
+ return sha1Hex(
4669
+ JSON.stringify([
4670
+ sortedCanonical(table.types, TYPE_FIELDS),
4671
+ sortedCanonical(table.rates, RATE_FIELDS),
4672
+ sortedCanonical(table.rules, RULE_FIELDS)
4673
+ ])
4674
+ );
4675
+ }
4676
+ var toTypeRow = ({ key, name, description, sortOrder, active }) => ({
4677
+ key,
4678
+ name,
4679
+ description,
4680
+ sortOrder,
4681
+ active
4682
+ });
4683
+ var toRateRow = (rate) => ({
4684
+ code: rate.code,
4685
+ name: rate.name,
4686
+ kind: rate.kind,
4687
+ places: rate.places,
4688
+ rate: rate.rate,
4689
+ from: rate.from,
4690
+ to: rate.to,
4691
+ order: rate.order,
4692
+ compound: rate.compound,
4693
+ registrationPlace: rate.registrationPlace,
4694
+ harmonized: rate.harmonized,
4695
+ parts: rate.parts?.map(({ code, name, rate: partRate, level }) => ({ code, name, rate: partRate, level })),
4696
+ sourceUrl: rate.sourceUrl,
4697
+ status: rate.status
4698
+ });
4699
+ var toRuleRow = ({
4700
+ taxType,
4701
+ codes: codes2,
4702
+ rate,
4703
+ from,
4704
+ to,
4705
+ sourceUrl,
4706
+ status,
4707
+ note
4708
+ }) => ({
4709
+ taxType,
4710
+ codes: codes2,
4711
+ rate,
4712
+ from,
4713
+ to,
4714
+ sourceUrl,
4715
+ status,
4716
+ note
4717
+ });
4718
+ function buildAutomaticTaxTable(rows) {
4719
+ const table = {
4720
+ types: [...rows.types].sort((a, b) => a.sortOrder - b.sortOrder).map(toTypeRow),
4721
+ rates: rows.rates.map(toRateRow),
4722
+ rules: rows.rules.map(toRuleRow)
4723
+ };
4724
+ return { version: automaticTaxTableVersion(table), ...table };
4725
+ }
4726
+ function registrationPlacesByKind(rates) {
4727
+ const places = /* @__PURE__ */ new Map();
4728
+ for (const rate of rates) {
4729
+ const list = places.get(rate.kind) ?? [];
4730
+ if (!list.includes(rate.registrationPlace)) list.push(rate.registrationPlace);
4731
+ places.set(rate.kind, list);
4732
+ }
4733
+ return places;
4734
+ }
4735
+
4736
+ // tax/exceptions.ts
4737
+ var TaxExceptionSource = /* @__PURE__ */ ((TaxExceptionSource2) => {
4738
+ TaxExceptionSource2["PRODUCT"] = "product";
4739
+ TaxExceptionSource2["CATEGORY"] = "category";
4740
+ return TaxExceptionSource2;
4741
+ })(TaxExceptionSource || {});
4742
+ var TAX_EXCEPTION_REASON_MAX = 200;
4743
+
4744
+ // shopper/types.ts
4745
+ var SHOPPER_CONSENT_SOURCES = ["checkout", "my-account", "store-account"];
4746
+ var SHOPPER_RETURN_METHODS = ["mail", "in-store"];
4747
+ var SHOPPER_RETURN_STATUSES = ["requested", "accepted", "declined"];
4748
+ var SHOPPER_RETURN_DECLINE_REASON_MAX = 500;
4749
+ var SHOPPER_ERROR_CODES = {
4750
+ ORDER_NOT_FOUND: "ORDER_NOT_FOUND",
4751
+ RETURN_ALREADY_REQUESTED: "RETURN_ALREADY_REQUESTED",
4752
+ RETURN_NOT_ALLOWED: "RETURN_NOT_ALLOWED",
4753
+ RETURN_ALREADY_DECIDED: "RETURN_ALREADY_DECIDED",
4754
+ STORE_HAS_NO_SUPPORT_EMAIL: "STORE_HAS_NO_SUPPORT_EMAIL",
4755
+ TOO_MANY_ADDRESSES: "TOO_MANY_ADDRESSES",
4756
+ STORE_NOT_LINKED: "STORE_NOT_LINKED",
4757
+ STORED_METHOD_NOT_FOUND: "STORED_METHOD_NOT_FOUND"
4758
+ };
4759
+
4760
+ // shopper/email.ts
4761
+ function normalizeShopperEmail(email) {
4762
+ if (typeof email !== "string") return null;
4763
+ const value = email.trim().toLowerCase();
4764
+ return /^[^\s@]+@[^\s@]+$/.test(value) ? value : null;
4765
+ }
4766
+
4767
+ // shopper/card.ts
4768
+ function cardFromProcessorData(processorData) {
4769
+ if (typeof processorData !== "string" || !processorData) return {};
4770
+ let data;
4771
+ try {
4772
+ data = JSON.parse(processorData);
4773
+ } catch {
4774
+ return {};
4775
+ }
4776
+ if (!data || typeof data !== "object") return {};
4777
+ const fields = new Map(Object.entries(data));
4778
+ const text = (...keys) => keys.map((key) => fields.get(key)).find((value) => typeof value === "string" && !!value.trim());
4779
+ const brand = text("Brand", "brand")?.trim();
4780
+ const digits = text("Card Number", "card", "card_number")?.replace(/\D/g, "");
4781
+ const issuer = text("Issuer", "issuer")?.trim();
4782
+ return {
4783
+ ...brand ? { cardBrand: brand.charAt(0).toUpperCase() + brand.slice(1) } : {},
4784
+ ...digits && digits.length >= 4 ? { cardLastFour: digits.slice(-4) } : {},
4785
+ ...issuer ? { cardIssuer: issuer } : {}
4786
+ };
4787
+ }
4788
+
4789
+ // shopper/payments.ts
4790
+ var CARD_TYPES = /* @__PURE__ */ new Set(["card", "terminal", "taptopay", "moto", "cloud", "bluetooth"]);
4791
+ function kindOf(paymentType) {
4792
+ if (paymentType === "cash") return "cash";
4793
+ if (paymentType === "redeem") return "gift_card";
4794
+ if (paymentType === "pay_later") return "pay_later";
4795
+ if (CARD_TYPES.has(paymentType)) return "card";
4796
+ return "other";
4797
+ }
4798
+ function shopperPaymentsOf(legs) {
4799
+ return (legs ?? []).map((leg) => {
4800
+ const type = (leg.paymentType ?? "").trim();
4801
+ const kind = kindOf(type.toLowerCase());
4802
+ const card = kind === "card" ? cardFromProcessorData(leg.emv) : {};
4803
+ return {
4804
+ kind,
4805
+ // Cards: the issuer's name, else the brand. Other tenders the store named itself keep that name.
4806
+ name: kind === "card" ? card.cardIssuer ?? card.cardBrand ?? null : kind === "other" ? type || null : null,
4807
+ lastFour: card.cardLastFour ?? null,
4808
+ amount: (leg.amount ?? 0) + (leg.tip?.amount ?? 0)
4809
+ };
4810
+ });
4811
+ }
4812
+
5150
4813
  // constants/adyen.constants.ts
5151
4814
  var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
5152
4815
  function isAdyenRolloutCountry(alpha2) {
@@ -5254,18 +4917,17 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5254
4917
  AttributeType,
5255
4918
  BNPL_METHOD_STATUS,
5256
4919
  BNPL_SKIP_REASON,
5257
- BookingArriveLeave,
5258
- BookingDurationUnit,
5259
4920
  BookingRatePeriod,
5260
4921
  BookingResourceKind,
5261
4922
  BookingResourceStatus,
5262
4923
  BookingRulesError,
5263
- BookingSessionSale,
5264
4924
  BookingType,
5265
4925
  CANADA_PROVINCES,
5266
4926
  CONDITION_OPERATORS,
5267
4927
  COUNTRY_CURRENCIES,
5268
4928
  CURRENCY_CONFIG,
4929
+ CUSTOMER_CONTACT_VERIFIED,
4930
+ CUSTOMER_EMAIL_TAKEN,
5269
4931
  CompanyType,
5270
4932
  CurrencyCode,
5271
4933
  CustomTableAvailability,
@@ -5275,6 +4937,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5275
4937
  DEFAULT_DISPLAY_STATE_MAP,
5276
4938
  DEFAULT_HOLD_MINUTES,
5277
4939
  DEFAULT_RESOLVED_CONFIG,
4940
+ DEFAULT_SHELL_SETTINGS,
5278
4941
  DEFAULT_UNIT_ID,
5279
4942
  DualWriteStrategy,
5280
4943
  EUFixedRates,
@@ -5303,6 +4966,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5303
4966
  ORDER_STATE_TOPIC,
5304
4967
  OrderPlatform,
5305
4968
  OtherFixedRates,
4969
+ OutOfProvinceTaxes,
5306
4970
  OwnerType,
5307
4971
  PATH_MODES,
5308
4972
  PAYMENT_CHANNELS,
@@ -5330,7 +4994,18 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5330
4994
  ResidualPaymentMethod,
5331
4995
  ResidualStatus,
5332
4996
  ResourceAvailabilityState,
4997
+ SHELL_FLOW_SETTINGS_PREFIX,
4998
+ SHELL_FLOW_TIPS_KEY,
4999
+ SHELL_TIP_LABEL_MAX_LENGTH,
5000
+ SHELL_TIP_PERCENT_MAX,
5001
+ SHELL_TIP_PERCENT_MIN,
5333
5002
  SHIPPING_COUNTRIES,
5003
+ SHOPPER_CONSENT_SOURCES,
5004
+ SHOPPER_ERROR_CODES,
5005
+ SHOPPER_RETURN_DECLINE_REASON_MAX,
5006
+ SHOPPER_RETURN_METHODS,
5007
+ SHOPPER_RETURN_STATUSES,
5008
+ STANDARD_TAX_TYPE,
5334
5009
  STATE_SCHEMA,
5335
5010
  STRIPE_SUPPORTED_COUNTRIES,
5336
5011
  SYSTEM_FAMILIES,
@@ -5348,9 +5023,13 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5348
5023
  StationStatus,
5349
5024
  StripeCurrencyCode,
5350
5025
  StripeStatus,
5026
+ TAX_EXCEPTION_REASON_MAX,
5027
+ TaxExceptionSource,
5028
+ TaxRegistrationKind,
5029
+ TaxSource,
5030
+ TaxWarningCode,
5351
5031
  TimePeriod,
5352
5032
  TopMetericsSort,
5353
- UNLIMITED_PLACES,
5354
5033
  UserTypes,
5355
5034
  addAmounts,
5356
5035
  addressPlaceKeys,
@@ -5359,32 +5038,27 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5359
5038
  adyenStoreRequiresStateOrProvince,
5360
5039
  adyenSupportsTaxNumberAbsent,
5361
5040
  adyenTaxNumberFormat,
5362
- allowedDurationUnits,
5363
5041
  amountToString,
5364
5042
  ancestorChain,
5365
5043
  applyAssignment,
5366
5044
  assertUnitSane,
5045
+ automaticTaxTableVersion,
5367
5046
  availableIn,
5368
5047
  baseFor,
5369
5048
  baseFulfillmentDefinitions,
5370
5049
  baseOf,
5371
5050
  basePaymentDefinitions,
5372
- bookingMethodOf,
5373
- bookingRuleParts,
5051
+ buildAutomaticTaxTable,
5374
5052
  buildAvailability,
5375
5053
  buildGrid,
5376
5054
  buildOrderContext,
5377
5055
  buildPosPresetConfig,
5378
5056
  buildResolvedConfig,
5379
5057
  calculatePercentage,
5380
- calendarDate,
5381
5058
  canTransition,
5382
- capacityOf,
5383
- cellChainOf,
5059
+ cardFromProcessorData,
5384
5060
  cheapestCompositeItem,
5385
5061
  cheapestCompositePrice,
5386
- checkPartySize,
5387
- checkQtyPerBooking,
5388
5062
  compositeItemCost,
5389
5063
  compositeItemUnavailable,
5390
5064
  compositeMakeable,
@@ -5393,10 +5067,6 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5393
5067
  compositeVariantInStock,
5394
5068
  conditionSummary,
5395
5069
  convertFixedFeeToLocalCurrency,
5396
- courseSessions,
5397
- courseSpan,
5398
- courseStarted,
5399
- courseStartedInZone,
5400
5070
  createAmount,
5401
5071
  crossAxisRuleApplies,
5402
5072
  currentAssignees,
@@ -5405,17 +5075,17 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5405
5075
  deriveUnitId,
5406
5076
  displayRuleMatchesPair,
5407
5077
  divideAmount,
5408
- durationProblems,
5409
- durationText,
5078
+ emailKey,
5410
5079
  evaluateCondition,
5411
5080
  evaluateConditionSet,
5412
5081
  extendPrice,
5413
5082
  extendPriceFor,
5414
- fewestFreeOver,
5083
+ flowSettingsFromShellSettings,
5415
5084
  formatCurrency,
5416
5085
  formatInUnit,
5417
5086
  formatMinorUnitsToString,
5418
5087
  formatQuantity,
5088
+ formatShippingDuration,
5419
5089
  fromBase,
5420
5090
  fromMinorUnits,
5421
5091
  generateMongoID,
@@ -5445,6 +5115,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5445
5115
  isFulfillmentState,
5446
5116
  isInCart,
5447
5117
  isPaymentState,
5118
+ isShellTipPercent,
5448
5119
  isSupportedCurrency,
5449
5120
  isSystemFamilyCode,
5450
5121
  isValidQuantity,
@@ -5453,9 +5124,7 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5453
5124
  listCountries,
5454
5125
  listProvinces,
5455
5126
  listShippingCountries,
5456
- longestMinutesOf,
5457
5127
  mapToLegacyStatus,
5458
- maxAdvanceMinutesOf,
5459
5128
  maxPrecisionFor,
5460
5129
  mergeFragment,
5461
5130
  modifiersSellable,
@@ -5466,16 +5135,14 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5466
5135
  normalizeMongoIdString,
5467
5136
  normalizePostCode,
5468
5137
  normalizeProvince,
5138
+ normalizeShopperEmail,
5469
5139
  occupancyIn,
5470
- occupiedAtOutlet,
5471
- oldMaxAdvanceOf,
5472
5140
  orderAssignments,
5473
5141
  parseAmountToMinorUnits,
5474
5142
  parseCurrencyCode,
5475
5143
  parseStripeCurrencyCode,
5476
- pickFreeResource,
5144
+ phoneKey,
5477
5145
  placeKey,
5478
- planCourse,
5479
5146
  planWindow,
5480
5147
  poolDemand,
5481
5148
  poolOf,
@@ -5485,27 +5152,31 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5485
5152
  presentAt,
5486
5153
  priceForTotal,
5487
5154
  provincesForPostCode,
5155
+ readShellTipSettings,
5156
+ registrationPlacesByKind,
5488
5157
  removeFragment,
5489
- rentalEnds,
5490
5158
  resolveFamily,
5491
5159
  resolveModifiersForProduct,
5160
+ resolveShellSettings,
5161
+ resolveShellSettingsWithSources,
5492
5162
  resolveShipping,
5493
5163
  resolveTemplate,
5494
5164
  resolveUnit,
5495
5165
  roundToPrecision,
5496
- ruleDurationsOf,
5497
- ruleInNewShape,
5498
5166
  sameFamily,
5499
- sessionCells,
5500
5167
  setOrderState,
5168
+ sha1Hex,
5169
+ shellSettingsFromCompanyTips,
5170
+ shellSettingsFromFlowSettings,
5171
+ shellSettingsProblems,
5172
+ shellTipSettingsProblems,
5173
+ shippingDuration,
5501
5174
  shipsToCountry,
5502
5175
  shopDayKey,
5503
5176
  shopDayRange,
5504
- shortestMinutesOf,
5177
+ shopperPaymentsOf,
5505
5178
  signReportForDisplay,
5506
5179
  slotsForWindow,
5507
- soldAsCourse,
5508
- startsPastMaxAdvance,
5509
5180
  stringifyMinorUnits,
5510
5181
  subtractAmounts,
5511
5182
  toBase,
@@ -5514,10 +5185,9 @@ var EXPENSE_DEFAULT_CATEGORIES = [
5514
5185
  validateFragmentCompatibility,
5515
5186
  validateOrderStatuses,
5516
5187
  validateShippingZone,
5188
+ verifiedContactChange,
5517
5189
  violatesFinancialInvariant,
5518
5190
  windowEndsAt,
5519
- windowEndsAtInZone,
5520
- windowForPeriods,
5521
5191
  withinPresence
5522
5192
  });
5523
5193
  //# sourceMappingURL=index.js.map