@final-commerce/common 2.5.1-preprod.1 → 2.5.1-preprod.3

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
@@ -2492,6 +2492,51 @@ function inferStatesFromLegacyStatus(order) {
2492
2492
  return { payment: "unpaid", fulfillment: "pending" };
2493
2493
  }
2494
2494
 
2495
+ // order-state-machine/in-cart.ts
2496
+ function hasInCartFlag(order) {
2497
+ return order.inCart != null;
2498
+ }
2499
+ function isInCart(order) {
2500
+ if (order.inCart != null) return order.inCart.active === true;
2501
+ if (order.fulfillmentState) return order.fulfillmentState === "draft";
2502
+ return (order.status ?? "").trim().toLowerCase() === "in-cart";
2503
+ }
2504
+
2505
+ // order-state-machine/order-status.ts
2506
+ function validateOrderStatuses(statuses) {
2507
+ if (!Array.isArray(statuses)) {
2508
+ return [{ index: -1, field: "orderStatuses", message: "must be an array" }];
2509
+ }
2510
+ const errors = [];
2511
+ const seen = /* @__PURE__ */ new Set();
2512
+ statuses.forEach((raw, index) => {
2513
+ const s = raw ?? {};
2514
+ const add = (field, message) => errors.push({ index, field, message });
2515
+ 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");
2519
+ for (const field of ["color", "icon"]) {
2520
+ if (s[field] !== void 0 && typeof s[field] !== "string") add(field, "must be a string");
2521
+ }
2522
+ if (s.fulfillmentState !== void 0 && !(typeof s.fulfillmentState === "string" && isFulfillmentState(s.fulfillmentState))) {
2523
+ add("fulfillmentState", `"${String(s.fulfillmentState)}" is not a fulfillment state`);
2524
+ }
2525
+ if (s.requiresPaymentState !== void 0) {
2526
+ if (!Array.isArray(s.requiresPaymentState) || s.requiresPaymentState.length === 0) {
2527
+ add("requiresPaymentState", "must be a non-empty array of payment states");
2528
+ } else {
2529
+ for (const p of s.requiresPaymentState) {
2530
+ if (!(typeof p === "string" && isPaymentState(p))) {
2531
+ add("requiresPaymentState", `"${String(p)}" is not a payment state`);
2532
+ }
2533
+ }
2534
+ }
2535
+ }
2536
+ });
2537
+ return errors;
2538
+ }
2539
+
2495
2540
  // order-state-machine/write-strategy.ts
2496
2541
  var LegacyWriteStrategy = class {
2497
2542
  applyState(_order) {
@@ -3200,8 +3245,13 @@ var ADYEN_ROLLOUT_COUNTRY_CODES = /* @__PURE__ */ new Set(["CA"]);
3200
3245
  function isAdyenRolloutCountry(alpha2) {
3201
3246
  return ADYEN_ROLLOUT_COUNTRY_CODES.has(alpha2);
3202
3247
  }
3248
+ var AFFIRM_PRICE_PLANS = ["core", "standard", "signature"];
3249
+ function isAffirmPricePlan(value) {
3250
+ return typeof value === "string" && AFFIRM_PRICE_PLANS.includes(value);
3251
+ }
3203
3252
  export {
3204
3253
  ADYEN_ROLLOUT_COUNTRY_CODES,
3254
+ AFFIRM_PRICE_PLANS,
3205
3255
  AttributeType,
3206
3256
  BookingRatePeriod,
3207
3257
  BookingResourceKind,
@@ -3327,11 +3377,14 @@ export {
3327
3377
  getPricingRegionFromCountry,
3328
3378
  getSettlementTotal,
3329
3379
  getTotalCollected,
3380
+ hasInCartFlag,
3330
3381
  holdExpiresAt,
3331
3382
  inferStatesFromLegacyStatus,
3332
3383
  isAdyenRolloutCountry,
3384
+ isAffirmPricePlan,
3333
3385
  isConditionOperator,
3334
3386
  isFulfillmentState,
3387
+ isInCart,
3335
3388
  isPaymentState,
3336
3389
  isSupportedCurrency,
3337
3390
  isSystemFamilyCode,
@@ -3365,6 +3418,7 @@ export {
3365
3418
  toMinorUnits,
3366
3419
  validateConfig,
3367
3420
  validateFragmentCompatibility,
3421
+ validateOrderStatuses,
3368
3422
  violatesFinancialInvariant,
3369
3423
  windowEndsAt,
3370
3424
  withinPresence