@final-commerce/common 2.6.0-staging.4 → 2.7.0-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.mjs CHANGED
@@ -2799,6 +2799,59 @@ function inferStatesFromLegacyStatus(order) {
2799
2799
  return { payment: "unpaid", fulfillment: "pending" };
2800
2800
  }
2801
2801
 
2802
+ // order-state-machine/in-cart.ts
2803
+ function hasInCartFlag(order) {
2804
+ return order.inCart != null;
2805
+ }
2806
+ function isInCart(order) {
2807
+ if (order.inCart != null) return order.inCart.active === true;
2808
+ if (order.fulfillmentState) return order.fulfillmentState === "draft";
2809
+ return (order.status ?? "").trim().toLowerCase() === "in-cart";
2810
+ }
2811
+
2812
+ // order-state-machine/order-status.ts
2813
+ var STATUS_KEY = /^[a-z0-9][a-z0-9_-]*$/;
2814
+ function validateOrderStatuses(statuses) {
2815
+ if (!Array.isArray(statuses)) {
2816
+ return [{ index: -1, field: "orderStatuses", message: "must be an array" }];
2817
+ }
2818
+ const errors = [];
2819
+ const seenIds = /* @__PURE__ */ new Set();
2820
+ const seenKeys = /* @__PURE__ */ new Set();
2821
+ statuses.forEach((raw, index) => {
2822
+ const s = raw ?? {};
2823
+ const add = (field, message) => errors.push({ index, field, message });
2824
+ if (typeof s.id !== "string" || !s.id.trim()) add("id", "must be a non-empty string");
2825
+ else if (seenIds.has(s.id)) add("id", `duplicate id "${s.id}"`);
2826
+ else seenIds.add(s.id);
2827
+ if (typeof s.key !== "string" || !STATUS_KEY.test(s.key)) {
2828
+ add("key", 'must be lowercase letters, digits, "-" or "_"');
2829
+ } else if (seenKeys.has(s.key)) add("key", `duplicate key "${s.key}"`);
2830
+ else seenKeys.add(s.key);
2831
+ if (typeof s.defaultLabel !== "string" || !s.defaultLabel.trim()) {
2832
+ add("defaultLabel", "must be a non-empty string");
2833
+ }
2834
+ for (const field of ["color", "icon"]) {
2835
+ if (s[field] !== void 0 && typeof s[field] !== "string") add(field, "must be a string");
2836
+ }
2837
+ if (s.fulfillmentState !== void 0 && !(typeof s.fulfillmentState === "string" && isFulfillmentState(s.fulfillmentState))) {
2838
+ add("fulfillmentState", `"${String(s.fulfillmentState)}" is not a fulfillment state`);
2839
+ }
2840
+ if (s.requiresPaymentState !== void 0) {
2841
+ if (!Array.isArray(s.requiresPaymentState) || s.requiresPaymentState.length === 0) {
2842
+ add("requiresPaymentState", "must be a non-empty array of payment states");
2843
+ } else {
2844
+ for (const p of s.requiresPaymentState) {
2845
+ if (!(typeof p === "string" && isPaymentState(p))) {
2846
+ add("requiresPaymentState", `"${String(p)}" is not a payment state`);
2847
+ }
2848
+ }
2849
+ }
2850
+ }
2851
+ });
2852
+ return errors;
2853
+ }
2854
+
2802
2855
  // order-state-machine/write-strategy.ts
2803
2856
  var LegacyWriteStrategy = class {
2804
2857
  applyState(_order) {
@@ -3516,6 +3569,29 @@ var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
3516
3569
  function isAdyenRolloutCountry(alpha2) {
3517
3570
  return ADYEN_ROLLOUT_COUNTRY_CODES.has(alpha2);
3518
3571
  }
3572
+ var ADYEN_STORE_STATE_PROVINCE_COUNTRIES = /* @__PURE__ */ new Set(["AU", "BR", "CA", "IN", "MX", "NZ", "US"]);
3573
+ function adyenStoreRequiresStateOrProvince(alpha2) {
3574
+ return !!alpha2 && ADYEN_STORE_STATE_PROVINCE_COUNTRIES.has(alpha2);
3575
+ }
3576
+ var ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES = /* @__PURE__ */ new Set(["AU", "BR", "CA", "IN", "MX", "NZ", "US"]);
3577
+ function adyenLegalEntityRequiresStateOrProvince(alpha2) {
3578
+ return !!alpha2 && ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES.has(alpha2);
3579
+ }
3580
+ var ADYEN_NO_TAX_NUMBER_ABSENT_COUNTRIES = /* @__PURE__ */ new Set(["CA"]);
3581
+ function adyenSupportsTaxNumberAbsent(alpha2) {
3582
+ return !!alpha2 && !ADYEN_NO_TAX_NUMBER_ABSENT_COUNTRIES.has(alpha2);
3583
+ }
3584
+ var ADYEN_TAX_NUMBER_FORMATS = {
3585
+ CA: { pattern: /^\d{9}$/, length: 9 }
3586
+ };
3587
+ function adyenTaxNumberFormat(alpha2) {
3588
+ return alpha2 ? ADYEN_TAX_NUMBER_FORMATS[alpha2] : void 0;
3589
+ }
3590
+ var ADYEN_TAX_NUMBER_MIN_LENGTH = 5;
3591
+ var ADYEN_JOB_TITLE_ASSOCIATION_TYPES = ["signatory", "uboThroughControl"];
3592
+ function adyenRequiresJobTitle(associationType) {
3593
+ return ADYEN_JOB_TITLE_ASSOCIATION_TYPES.includes(associationType);
3594
+ }
3519
3595
  var AFFIRM_PRICE_PLANS = ["core", "standard", "signature"];
3520
3596
  function isAffirmPricePlan(value) {
3521
3597
  return typeof value === "string" && AFFIRM_PRICE_PLANS.includes(value);
@@ -3537,7 +3613,13 @@ var BNPL_SKIP_REASON = {
3537
3613
  NO_BUSINESS_LINE: "no_business_line"
3538
3614
  };
3539
3615
  export {
3616
+ ADYEN_JOB_TITLE_ASSOCIATION_TYPES,
3617
+ ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES,
3618
+ ADYEN_NO_TAX_NUMBER_ABSENT_COUNTRIES,
3540
3619
  ADYEN_ROLLOUT_COUNTRY_CODES,
3620
+ ADYEN_STORE_STATE_PROVINCE_COUNTRIES,
3621
+ ADYEN_TAX_NUMBER_FORMATS,
3622
+ ADYEN_TAX_NUMBER_MIN_LENGTH,
3541
3623
  AFFIRM_COUNTRY_CODES,
3542
3624
  AFFIRM_PRICE_PLANS,
3543
3625
  AttributeType,
@@ -3619,6 +3701,11 @@ export {
3619
3701
  TopMetericsSort,
3620
3702
  UserTypes,
3621
3703
  addAmounts,
3704
+ adyenLegalEntityRequiresStateOrProvince,
3705
+ adyenRequiresJobTitle,
3706
+ adyenStoreRequiresStateOrProvince,
3707
+ adyenSupportsTaxNumberAbsent,
3708
+ adyenTaxNumberFormat,
3622
3709
  amountToString,
3623
3710
  ancestorChain,
3624
3711
  assertUnitSane,
@@ -3676,6 +3763,7 @@ export {
3676
3763
  getPricingRegionFromCountry,
3677
3764
  getSettlementTotal,
3678
3765
  getTotalCollected,
3766
+ hasInCartFlag,
3679
3767
  hasSellableChoice,
3680
3768
  holdExpiresAt,
3681
3769
  inferStatesFromLegacyStatus,
@@ -3685,6 +3773,7 @@ export {
3685
3773
  isChoiceAvailableAtOutlet,
3686
3774
  isConditionOperator,
3687
3775
  isFulfillmentState,
3776
+ isInCart,
3688
3777
  isPaymentState,
3689
3778
  isSupportedCurrency,
3690
3779
  isSystemFamilyCode,
@@ -3724,6 +3813,7 @@ export {
3724
3813
  toMinorUnits,
3725
3814
  validateConfig,
3726
3815
  validateFragmentCompatibility,
3816
+ validateOrderStatuses,
3727
3817
  violatesFinancialInvariant,
3728
3818
  windowEndsAt,
3729
3819
  withinPresence