@final-commerce/common 2.6.0-staging.4 → 2.6.1-staging2

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,51 @@ 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
+ function validateOrderStatuses(statuses) {
2814
+ if (!Array.isArray(statuses)) {
2815
+ return [{ index: -1, field: "orderStatuses", message: "must be an array" }];
2816
+ }
2817
+ const errors = [];
2818
+ const seen = /* @__PURE__ */ new Set();
2819
+ statuses.forEach((raw, index) => {
2820
+ const s = raw ?? {};
2821
+ const add = (field, message) => errors.push({ index, field, message });
2822
+ if (typeof s.id !== "string" || !s.id.trim()) add("id", "must be a non-empty string");
2823
+ else if (seen.has(s.id)) add("id", `duplicate id "${s.id}"`);
2824
+ else seen.add(s.id);
2825
+ if (typeof s.label !== "string" || !s.label.trim()) add("label", "must be a non-empty string");
2826
+ for (const field of ["color", "icon"]) {
2827
+ if (s[field] !== void 0 && typeof s[field] !== "string") add(field, "must be a string");
2828
+ }
2829
+ if (s.fulfillmentState !== void 0 && !(typeof s.fulfillmentState === "string" && isFulfillmentState(s.fulfillmentState))) {
2830
+ add("fulfillmentState", `"${String(s.fulfillmentState)}" is not a fulfillment state`);
2831
+ }
2832
+ if (s.requiresPaymentState !== void 0) {
2833
+ if (!Array.isArray(s.requiresPaymentState) || s.requiresPaymentState.length === 0) {
2834
+ add("requiresPaymentState", "must be a non-empty array of payment states");
2835
+ } else {
2836
+ for (const p of s.requiresPaymentState) {
2837
+ if (!(typeof p === "string" && isPaymentState(p))) {
2838
+ add("requiresPaymentState", `"${String(p)}" is not a payment state`);
2839
+ }
2840
+ }
2841
+ }
2842
+ }
2843
+ });
2844
+ return errors;
2845
+ }
2846
+
2802
2847
  // order-state-machine/write-strategy.ts
2803
2848
  var LegacyWriteStrategy = class {
2804
2849
  applyState(_order) {
@@ -3516,6 +3561,29 @@ var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
3516
3561
  function isAdyenRolloutCountry(alpha2) {
3517
3562
  return ADYEN_ROLLOUT_COUNTRY_CODES.has(alpha2);
3518
3563
  }
3564
+ var ADYEN_STORE_STATE_PROVINCE_COUNTRIES = /* @__PURE__ */ new Set(["AU", "BR", "CA", "IN", "MX", "NZ", "US"]);
3565
+ function adyenStoreRequiresStateOrProvince(alpha2) {
3566
+ return !!alpha2 && ADYEN_STORE_STATE_PROVINCE_COUNTRIES.has(alpha2);
3567
+ }
3568
+ var ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES = /* @__PURE__ */ new Set(["AU", "BR", "CA", "IN", "MX", "NZ", "US"]);
3569
+ function adyenLegalEntityRequiresStateOrProvince(alpha2) {
3570
+ return !!alpha2 && ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES.has(alpha2);
3571
+ }
3572
+ var ADYEN_NO_TAX_NUMBER_ABSENT_COUNTRIES = /* @__PURE__ */ new Set(["CA"]);
3573
+ function adyenSupportsTaxNumberAbsent(alpha2) {
3574
+ return !!alpha2 && !ADYEN_NO_TAX_NUMBER_ABSENT_COUNTRIES.has(alpha2);
3575
+ }
3576
+ var ADYEN_TAX_NUMBER_FORMATS = {
3577
+ CA: { pattern: /^\d{9}$/, length: 9 }
3578
+ };
3579
+ function adyenTaxNumberFormat(alpha2) {
3580
+ return alpha2 ? ADYEN_TAX_NUMBER_FORMATS[alpha2] : void 0;
3581
+ }
3582
+ var ADYEN_TAX_NUMBER_MIN_LENGTH = 5;
3583
+ var ADYEN_JOB_TITLE_ASSOCIATION_TYPES = ["signatory", "uboThroughControl"];
3584
+ function adyenRequiresJobTitle(associationType) {
3585
+ return ADYEN_JOB_TITLE_ASSOCIATION_TYPES.includes(associationType);
3586
+ }
3519
3587
  var AFFIRM_PRICE_PLANS = ["core", "standard", "signature"];
3520
3588
  function isAffirmPricePlan(value) {
3521
3589
  return typeof value === "string" && AFFIRM_PRICE_PLANS.includes(value);
@@ -3537,7 +3605,13 @@ var BNPL_SKIP_REASON = {
3537
3605
  NO_BUSINESS_LINE: "no_business_line"
3538
3606
  };
3539
3607
  export {
3608
+ ADYEN_JOB_TITLE_ASSOCIATION_TYPES,
3609
+ ADYEN_LEGAL_ENTITY_STATE_PROVINCE_COUNTRIES,
3610
+ ADYEN_NO_TAX_NUMBER_ABSENT_COUNTRIES,
3540
3611
  ADYEN_ROLLOUT_COUNTRY_CODES,
3612
+ ADYEN_STORE_STATE_PROVINCE_COUNTRIES,
3613
+ ADYEN_TAX_NUMBER_FORMATS,
3614
+ ADYEN_TAX_NUMBER_MIN_LENGTH,
3541
3615
  AFFIRM_COUNTRY_CODES,
3542
3616
  AFFIRM_PRICE_PLANS,
3543
3617
  AttributeType,
@@ -3619,6 +3693,11 @@ export {
3619
3693
  TopMetericsSort,
3620
3694
  UserTypes,
3621
3695
  addAmounts,
3696
+ adyenLegalEntityRequiresStateOrProvince,
3697
+ adyenRequiresJobTitle,
3698
+ adyenStoreRequiresStateOrProvince,
3699
+ adyenSupportsTaxNumberAbsent,
3700
+ adyenTaxNumberFormat,
3622
3701
  amountToString,
3623
3702
  ancestorChain,
3624
3703
  assertUnitSane,
@@ -3676,6 +3755,7 @@ export {
3676
3755
  getPricingRegionFromCountry,
3677
3756
  getSettlementTotal,
3678
3757
  getTotalCollected,
3758
+ hasInCartFlag,
3679
3759
  hasSellableChoice,
3680
3760
  holdExpiresAt,
3681
3761
  inferStatesFromLegacyStatus,
@@ -3685,6 +3765,7 @@ export {
3685
3765
  isChoiceAvailableAtOutlet,
3686
3766
  isConditionOperator,
3687
3767
  isFulfillmentState,
3768
+ isInCart,
3688
3769
  isPaymentState,
3689
3770
  isSupportedCurrency,
3690
3771
  isSystemFamilyCode,
@@ -3724,6 +3805,7 @@ export {
3724
3805
  toMinorUnits,
3725
3806
  validateConfig,
3726
3807
  validateFragmentCompatibility,
3808
+ validateOrderStatuses,
3727
3809
  violatesFinancialInvariant,
3728
3810
  windowEndsAt,
3729
3811
  withinPresence