@final-commerce/common 2.5.1-preprod.6 → 2.5.1-preprod.8

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.mjs CHANGED
@@ -2503,19 +2503,27 @@ function isInCart(order) {
2503
2503
  }
2504
2504
 
2505
2505
  // order-state-machine/order-status.ts
2506
+ var STATUS_KEY = /^[a-z0-9][a-z0-9_-]*$/;
2506
2507
  function validateOrderStatuses(statuses) {
2507
2508
  if (!Array.isArray(statuses)) {
2508
2509
  return [{ index: -1, field: "orderStatuses", message: "must be an array" }];
2509
2510
  }
2510
2511
  const errors = [];
2511
- const seen = /* @__PURE__ */ new Set();
2512
+ const seenIds = /* @__PURE__ */ new Set();
2513
+ const seenKeys = /* @__PURE__ */ new Set();
2512
2514
  statuses.forEach((raw, index) => {
2513
2515
  const s = raw ?? {};
2514
2516
  const add = (field, message) => errors.push({ index, field, message });
2515
2517
  if (typeof s.id !== "string" || !s.id.trim()) add("id", "must be a non-empty string");
2516
- else if (seen.has(s.id)) add("id", `duplicate id "${s.id}"`);
2517
- else seen.add(s.id);
2518
- if (typeof s.label !== "string" || !s.label.trim()) add("label", "must be a non-empty string");
2518
+ else if (seenIds.has(s.id)) add("id", `duplicate id "${s.id}"`);
2519
+ else seenIds.add(s.id);
2520
+ if (typeof s.key !== "string" || !STATUS_KEY.test(s.key)) {
2521
+ add("key", 'must be lowercase letters, digits, "-" or "_"');
2522
+ } else if (seenKeys.has(s.key)) add("key", `duplicate key "${s.key}"`);
2523
+ else seenKeys.add(s.key);
2524
+ if (typeof s.defaultLabel !== "string" || !s.defaultLabel.trim()) {
2525
+ add("defaultLabel", "must be a non-empty string");
2526
+ }
2519
2527
  for (const field of ["color", "icon"]) {
2520
2528
  if (s[field] !== void 0 && typeof s[field] !== "string") add(field, "must be a string");
2521
2529
  }
@@ -3048,7 +3056,9 @@ function buildGrid(rule, timeZone, from, to, now, busy = []) {
3048
3056
  const start = startAt.getTime();
3049
3057
  if (start < askedFrom || start >= askedTo) return false;
3050
3058
  if (start < notBefore || start > notAfter) return false;
3051
- return !blocked.some(({ from: blockFrom, to: blockTo }) => start < blockTo && bufferEndAt.getTime() > blockFrom);
3059
+ return !blocked.some(
3060
+ ({ from: blockFrom, to: blockTo }) => start < blockTo && bufferEndAt.getTime() > blockFrom
3061
+ );
3052
3062
  }).sort((first, second) => +first.startAt - +second.startAt);
3053
3063
  }
3054
3064
  function slotsForWindow(grid, startAt, endAt) {
@@ -3167,7 +3177,14 @@ function buildAvailability({
3167
3177
  for (const slot of slots2) {
3168
3178
  const { taken, foreignProductId } = occupancyIn(mine, productId, slot.startAt, slot.bufferEndAt, shared);
3169
3179
  const free = foreignProductId ? 0 : Math.max(capacity - taken, 0);
3170
- const entry = byInstant.get(+slot.startAt) ?? { ...slot, capacity: 0, booked: 0, free: 0, resources: [], dayKey: shopDayKey(slot.startAt, resource.timeZone) };
3180
+ const entry = byInstant.get(+slot.startAt) ?? {
3181
+ ...slot,
3182
+ capacity: 0,
3183
+ booked: 0,
3184
+ free: 0,
3185
+ resources: [],
3186
+ dayKey: shopDayKey(slot.startAt, resource.timeZone)
3187
+ };
3171
3188
  entry.capacity += capacity;
3172
3189
  entry.booked += foreignProductId ? capacity : taken;
3173
3190
  entry.free += free;
@@ -3245,6 +3262,29 @@ var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
3245
3262
  function isAdyenRolloutCountry(alpha2) {
3246
3263
  return ADYEN_ROLLOUT_COUNTRY_CODES.has(alpha2);
3247
3264
  }
3265
+ var ADYEN_STORE_STATE_PROVINCE_COUNTRIES = /* @__PURE__ */ new Set(["AU", "BR", "CA", "IN", "MX", "NZ", "US"]);
3266
+ function adyenStoreRequiresStateOrProvince(alpha2) {
3267
+ return !!alpha2 && ADYEN_STORE_STATE_PROVINCE_COUNTRIES.has(alpha2);
3268
+ }
3269
+ var ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES = /* @__PURE__ */ new Set(["AU", "BR", "CA", "IN", "MX", "NZ", "US"]);
3270
+ function adyenLegalEntityRequiresStateOrProvince(alpha2) {
3271
+ return !!alpha2 && ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES.has(alpha2);
3272
+ }
3273
+ var ADYEN_NO_TAX_NUMBER_ABSENT_COUNTRIES = /* @__PURE__ */ new Set(["CA"]);
3274
+ function adyenSupportsTaxNumberAbsent(alpha2) {
3275
+ return !!alpha2 && !ADYEN_NO_TAX_NUMBER_ABSENT_COUNTRIES.has(alpha2);
3276
+ }
3277
+ var ADYEN_TAX_NUMBER_FORMATS = {
3278
+ CA: { pattern: /^\d{9}$/, length: 9 }
3279
+ };
3280
+ function adyenTaxNumberFormat(alpha2) {
3281
+ return alpha2 ? ADYEN_TAX_NUMBER_FORMATS[alpha2] : void 0;
3282
+ }
3283
+ var ADYEN_TAX_NUMBER_MIN_LENGTH = 5;
3284
+ var ADYEN_JOB_TITLE_ASSOCIATION_TYPES = ["signatory", "uboThroughControl"];
3285
+ function adyenRequiresJobTitle(associationType) {
3286
+ return ADYEN_JOB_TITLE_ASSOCIATION_TYPES.includes(associationType);
3287
+ }
3248
3288
  var AFFIRM_PRICE_PLANS = ["core", "standard", "signature"];
3249
3289
  function isAffirmPricePlan(value) {
3250
3290
  return typeof value === "string" && AFFIRM_PRICE_PLANS.includes(value);
@@ -3266,7 +3306,13 @@ var BNPL_SKIP_REASON = {
3266
3306
  NO_BUSINESS_LINE: "no_business_line"
3267
3307
  };
3268
3308
  export {
3309
+ ADYEN_JOB_TITLE_ASSOCIATION_TYPES,
3310
+ ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES,
3311
+ ADYEN_NO_TAX_NUMBER_ABSENT_COUNTRIES,
3269
3312
  ADYEN_ROLLOUT_COUNTRY_CODES,
3313
+ ADYEN_STORE_STATE_PROVINCE_COUNTRIES,
3314
+ ADYEN_TAX_NUMBER_FORMATS,
3315
+ ADYEN_TAX_NUMBER_MIN_LENGTH,
3270
3316
  AFFIRM_COUNTRY_CODES,
3271
3317
  AFFIRM_PRICE_PLANS,
3272
3318
  AttributeType,
@@ -3348,6 +3394,11 @@ export {
3348
3394
  TopMetericsSort,
3349
3395
  UserTypes,
3350
3396
  addAmounts,
3397
+ adyenLegalEntityRequiresStateOrProvince,
3398
+ adyenRequiresJobTitle,
3399
+ adyenStoreRequiresStateOrProvince,
3400
+ adyenSupportsTaxNumberAbsent,
3401
+ adyenTaxNumberFormat,
3351
3402
  amountToString,
3352
3403
  assertUnitSane,
3353
3404
  availableIn,