@wix/himalaya-cli 0.1723.0 → 0.1725.0

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.
Files changed (84) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-config.d.ts +1 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-module.d.ts +2 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/godot/src/index.d.ts +3 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/attendance-classifier.d.ts +1 -1
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments-contract.d.ts +9 -43
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/location/src/index.d.ts +5 -3
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/on-device-ai/src/index.d.ts +19 -7
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/sdk-types/src/capabilities.generated.d.ts +1 -1
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/define-app.d.ts +10 -0
  10. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/index.d.ts +2 -0
  11. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/preview-surfaces.d.ts +24 -0
  12. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-web-sdk.d.ts +37 -0
  13. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/site-web-sdk.generated.d.ts +1 -0
  14. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/wrapped-app-link.d.ts +13 -0
  15. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/checkout-source.d.ts +5 -3
  16. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-order-backend.d.ts +0 -2
  17. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/attendance.d.ts +2 -8
  18. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/index.d.ts +4 -13
  19. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/videos.d.ts +31 -1
  20. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/index.d.ts +1 -1
  21. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/audio-record.mjs +1 -1
  22. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calendar.mjs +1 -1
  23. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calls.mjs +1 -1
  24. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/contacts.mjs +1 -1
  25. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +175 -1
  26. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap-checkout.mjs +127 -509
  27. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap.mjs +5 -26
  28. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/location.mjs +1 -1
  29. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/motion.mjs +1 -1
  30. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/on-device-ai.mjs +49 -3
  31. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/photos.mjs +1 -1
  32. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/screens.mjs +150 -644
  33. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdk-types.mjs +1 -1
  34. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +1 -0
  35. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/tasks.mjs +1 -1
  36. package/dist/browser-plane/assets.json +7 -7
  37. package/dist/browser-plane/package-reader.js +4 -4
  38. package/dist/browser-plane/preview-deferred/{74e5b76ecf38392d7eb3f9a9512d60a0675de85d411c9c56293e123152b3f70b.bin → 49dfd582c5a8fb38ceabd1c544343d87fd478063c04f90c4e7a4ed5ee774f1eb.bin} +1 -1
  39. package/dist/browser-plane/sw.js +9 -9
  40. package/dist/browser-plane/t5-frame.html +16 -0
  41. package/dist/browser-plane/t5-worker-frame.html +16 -0
  42. package/dist/cli.mjs +3039 -1831
  43. package/dist/preview-assets.generated.bin +0 -0
  44. package/guides/capabilities.md +2 -2
  45. package/guides/headless-loop.md +2 -1
  46. package/guides/himi-json-output.md +6 -2
  47. package/guides/iap-products.md +2 -2
  48. package/guides/iap-screen-adoption.md +5 -5
  49. package/guides/sdk-reference.json +47 -82
  50. package/guides/skill.md +1 -1
  51. package/guides/testing-himi-apps.md +4 -3
  52. package/guides/web-page-sdk-reference.md +1 -1
  53. package/guides/webview-page-sdk.md +14 -0
  54. package/guides/wix-business-context.md +24 -0
  55. package/guides/wix-site-to-himi-app.md +2 -1
  56. package/package.json +2 -2
  57. package/templates/beauty-salon/tier5-src/himi-store-account/index.ts +2 -2
  58. package/templates/beauty-salon/tier5-src/himi-store-product/index.ts +5 -8
  59. package/templates/branded-lite/dev/index.ts +35 -0
  60. package/templates/branded-lite/tier5-src/himi-branded-lite-video/index.ts +82 -12
  61. package/templates/branded-lite/tier5-src/himi-store-account/index.ts +2 -2
  62. package/templates/branded-lite/tier5-src/himi-store-product/index.ts +5 -8
  63. package/templates/brandy/README.md +13 -0
  64. package/templates/brandy/config.ts +15 -1
  65. package/templates/brandy/dev/index.ts +10 -7
  66. package/templates/community-club/tier5-src/himi-store-account/index.ts +2 -2
  67. package/templates/conference/tier5-src/himi-store-account/index.ts +2 -2
  68. package/templates/events-meetups/tier5-src/himi-store-account/index.ts +2 -2
  69. package/templates/gym-fitness/tier5-src/himi-store-account/index.ts +2 -2
  70. package/templates/gym-fitness/tier5-src/himi-store-product/index.ts +5 -8
  71. package/templates/nonprofit-cause/tier5-src/himi-store-account/index.ts +2 -2
  72. package/templates/podcast-creator/tier5-src/himi-store-account/index.ts +2 -2
  73. package/templates/portfolio-creative/tier5-src/himi-store-account/index.ts +2 -2
  74. package/templates/portfolio-creative/tier5-src/himi-store-product/index.ts +5 -8
  75. package/templates/restaurant/tier5-src/himi-store-account/index.ts +2 -2
  76. package/templates/retail-store/tier5-src/himi-store-account/index.ts +2 -2
  77. package/templates/retail-store/tier5-src/himi-store-product/index.ts +5 -8
  78. package/templates/salon-spa/tier5-src/himi-store-account/index.ts +2 -2
  79. package/templates/wholesale-store/tier5-src/himi-store-account/index.ts +2 -2
  80. package/templates/wholesale-store/tier5-src/himi-store-product/index.ts +5 -8
  81. package/templates/yoga-studio/tier5-src/himi-store-account/index.ts +2 -2
  82. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/attendance-orders.d.ts +0 -10
  83. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/online-programs-orders.d.ts +0 -2
  84. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans-orders.d.ts +0 -2
@@ -161,9 +161,9 @@ function createPurchaseCoordinator(deps) {
161
161
  if (session.kind !== "member") return requireSignIn();
162
162
  if (listing === "listed") clearReconcileProblem();
163
163
  const now = deps.clock.now();
164
- const eligible3 = itemsWhere((item) => isAwaitingDelivery(item) && (item.state.nextAttemptAt === null || item.state.nextAttemptAt <= now));
165
- eligible3.forEach(restartAttemptBudget);
166
- await settleDelivery(session, await deliver(session, eligible3));
164
+ const eligible2 = itemsWhere((item) => isAwaitingDelivery(item) && (item.state.nextAttemptAt === null || item.state.nextAttemptAt <= now));
165
+ eligible2.forEach(restartAttemptBudget);
166
+ await settleDelivery(session, await deliver(session, eligible2));
167
167
  }
168
168
  async function settleDelivery(session, delivered) {
169
169
  applyDelivered(delivered);
@@ -713,36 +713,25 @@ var sameReference = (value, reference) => isObject2(value) && value.kind === ref
713
713
 
714
714
  // ../../core/sdk/iap/src/wix-payments-contract.ts
715
715
  var HIMALAYA_SERVE_IAP_ROUTE = { prefix: "/himalaya-serve/v1/iap" };
716
- var BOOKINGS_APPLE_SALES_ENABLED = true;
717
- var EVENTS_APPLE_SALES_ENABLED = true;
718
716
  var ATTENDANCE_SALE_RULE = { appProductId: (id) => id, productType: "CONSUMABLE" };
719
- var STORES_APPLE_SALES_ENABLED = true;
720
717
  var STORES_PRODUCT_SALE_RULE = { appProductId: (id) => id, productType: "NON_CONSUMABLE" };
721
718
  var ONLINE_PROGRAM_SALE_RULE = { appProductId: (id) => id, productType: "NON_CONSUMABLE" };
722
- var PRICING_PLAN_APPLE_SALES_ENABLED = true;
723
719
  var PRICING_PLAN_SALE_RULE = { appProductId: (id) => id, productType: "NON_CONSUMABLE" };
724
720
  var VIDEOS_APPLE_SALES_ENABLED = false;
725
- var PRICING_PLAN_ITEM_PAYMENT_ENABLED = false;
726
- var ONLINE_PROGRAM_ITEM_PAYMENT_ENABLED = false;
727
- var BOOKINGS_ITEM_PAYMENT_ENABLED = false;
728
- var EVENTS_ITEM_PAYMENT_ENABLED = false;
729
- var CANCEL_PAYMENT_ENABLED = false;
730
721
  var VIDEO_SALE_RULE = { appProductId: (id) => id, productType: "NON_CONSUMABLE" };
731
722
  function appleSaleRules(options = {}) {
732
723
  return {
733
724
  onlineProgram: ONLINE_PROGRAM_SALE_RULE,
734
- ...options.storesAppleSalesEnabled ?? STORES_APPLE_SALES_ENABLED ? { storesProduct: STORES_PRODUCT_SALE_RULE } : {},
735
- ...options.pricingPlanAppleSalesEnabled ?? PRICING_PLAN_APPLE_SALES_ENABLED ? { pricingPlan: PRICING_PLAN_SALE_RULE } : {},
736
- ...options.bookingsAppleSalesEnabled ?? BOOKINGS_APPLE_SALES_ENABLED ? { bookingsService: ATTENDANCE_SALE_RULE } : {},
737
- ...options.eventsAppleSalesEnabled ?? EVENTS_APPLE_SALES_ENABLED ? { eventsTicket: ATTENDANCE_SALE_RULE } : {},
725
+ storesProduct: STORES_PRODUCT_SALE_RULE,
726
+ pricingPlan: PRICING_PLAN_SALE_RULE,
727
+ bookingsService: ATTENDANCE_SALE_RULE,
728
+ eventsTicket: ATTENDANCE_SALE_RULE,
738
729
  ...options.videosAppleSalesEnabled ?? VIDEOS_APPLE_SALES_ENABLED ? { wixVideo: VIDEO_SALE_RULE } : {}
739
730
  };
740
731
  }
741
732
  var APPLE_SALE_RULES = appleSaleRules();
742
733
  var APPLE_PROVISIONING_RULES = {
743
734
  ...APPLE_SALE_RULES,
744
- bookingsService: ATTENDANCE_SALE_RULE,
745
- eventsTicket: ATTENDANCE_SALE_RULE,
746
735
  wixVideo: VIDEO_SALE_RULE
747
736
  };
748
737
  var APPLE_PRICING_RULES = { ...APPLE_SALE_RULES, wixVideo: VIDEO_SALE_RULE };
@@ -1541,48 +1530,6 @@ function describesNoPlace(address) {
1541
1530
  });
1542
1531
  }
1543
1532
  var ONLINE_LABEL = /^(online|virtual)(\s+(class|classes|classroom|course|session|sessions|meeting|lesson|training|workshop|event))?$/i;
1544
- function ticketAttendanceOf(event, definition) {
1545
- const e = object(event);
1546
- const t = object(definition);
1547
- const pricing = object(t.pricingMethod);
1548
- const price = object(pricing.fixedPrice);
1549
- const registration = object(e.registration);
1550
- const type = text(registration.type) ?? text(registration.initialType) ?? text(e.eventType);
1551
- const status = text(e.status) ?? text(e.eventStatus);
1552
- return {
1553
- kind: "eventsTicket",
1554
- location: text(object(e.location).type),
1555
- registration: type === "TICKETS" || type === "RSVP_AND_TICKETS" ? "TICKETING" : type,
1556
- eventStatus: status === "SCHEDULED" ? "UPCOMING" : status,
1557
- saleStatus: text(t.saleStatus),
1558
- hidden: boolean(t.hidden),
1559
- priceType: text(pricing.pricingType),
1560
- amount: text(price.value),
1561
- currency: text(price.currency)
1562
- };
1563
- }
1564
- function availableTicketAttendanceOf(event, ticket) {
1565
- const e = object(event);
1566
- const t = object(ticket);
1567
- const v3 = t.pricingMethod !== void 0;
1568
- const pricing = object(v3 ? t.pricingMethod : t.pricing);
1569
- const fixed = object(pricing.fixedPrice);
1570
- const amount = v3 ? fixed.value : fixed.amount;
1571
- const price = object(t.price);
1572
- const listed = v3 ? t.hidden === false && t.state === void 0 : Array.isArray(t.state) && t.state.length === 0;
1573
- const visible = listed && object(t.dashboard).hidden !== true && typeof t.id === "string" && t.id.length > 0 && typeof e.id === "string" && e.id.length > 0 && t.eventId === e.id;
1574
- const fixedPrice = t.free === false && (!v3 || pricing.free === false) && pricing.pricingType === "STANDARD" && sameTicketAmount(amount, price.amount) && fixed.currency === price.currency;
1575
- return ticketAttendanceOf(e, {
1576
- hidden: visible ? false : void 0,
1577
- saleStatus: t.saleStatus,
1578
- pricingMethod: { pricingType: fixedPrice ? "STANDARD" : void 0, fixedPrice: { value: amount, currency: fixed.currency } }
1579
- });
1580
- }
1581
- function sameTicketAmount(left, right) {
1582
- const valid = (value) => typeof value === "string" && /^\d+(?:\.\d+)?$/.test(value);
1583
- const normalized = (value) => value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
1584
- return valid(left) && valid(right) && normalized(left) === normalized(right);
1585
- }
1586
1533
  function object(value) {
1587
1534
  return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
1588
1535
  }
@@ -1710,7 +1657,10 @@ function appleIapCheckoutEnabled() {
1710
1657
  return appleIapCheckoutRoutes() !== null;
1711
1658
  }
1712
1659
  function storesAppleSalesEnabled() {
1713
- return STORES_APPLE_SALES_ENABLED;
1660
+ return true;
1661
+ }
1662
+ function videosAppleSalesEnabled() {
1663
+ return VIDEOS_APPLE_SALES_ENABLED;
1714
1664
  }
1715
1665
 
1716
1666
  // ../../stdlib/flows/iap-checkout/src/cashier-charges.ts
@@ -2263,7 +2213,7 @@ function createWixOrderBackend(deps) {
2263
2213
  case "approved":
2264
2214
  return alreadyPaid(sale, ref);
2265
2215
  case "closed":
2266
- return options.reordered ? stopWith("rejected", "orderClosed") : reorder(sale);
2216
+ return options.reordered ? stopWith("rejected", "orderClosed") : reorder(sale, ref.cashierOrderId);
2267
2217
  case "inOtherPayment":
2268
2218
  return stopWith("rejected", "orderRefused");
2269
2219
  case "refused":
@@ -2277,10 +2227,11 @@ function createWixOrderBackend(deps) {
2277
2227
  return retry("unavailable");
2278
2228
  }
2279
2229
  }
2280
- async function reorder(sale) {
2230
+ async function reorder(sale, closedOrderId) {
2281
2231
  if (sale.adapter.repeatable) return stopWith("rejected", "orderClosed");
2282
2232
  if (!forget(sale, sale.catalogRef)) return stopWith("rejected", "storageUnavailable");
2283
2233
  const attempt3 = await sale.adapter.openOrder(sale.item, sale.bridge);
2234
+ if (attempt3.status === "open" && attempt3.cashierOrderId === closedOrderId) return stopWith("rejected", "needsSupport");
2284
2235
  const recorded = recordOrder(sale, void 0, attempt3);
2285
2236
  return isStop(recorded) ? recorded : chargeFor(sale, recorded, { reordered: true, placed: isPlaced(attempt3) });
2286
2237
  }
@@ -2498,7 +2449,7 @@ function createWixOrderBackend(deps) {
2498
2449
  if (ref?.stage !== "started" || !ref.paymentId) return;
2499
2450
  const adapter = adapterFor(ref.kind);
2500
2451
  if (!adapter || !paidByItem(adapter)) return;
2501
- if (!(deps.cancelPaymentEnabled ?? CANCEL_PAYMENT_ENABLED) || adapter.reusesPayment) {
2452
+ if (adapter.reusesPayment) {
2502
2453
  const current = refAt(partition, catalogRef);
2503
2454
  if (current?.stage === "started" && current.paymentId === ref.paymentId && current.updatedAt === ref.updatedAt) handBackToGuard(partition, adapter, ref);
2504
2455
  return;
@@ -2816,7 +2767,7 @@ function enabledCheckout(deps) {
2816
2767
  if (!isCurrent(session)) return;
2817
2768
  if (ref.stage === "needsSupport") setPayment(ref.key, "needsSupport");
2818
2769
  if (ref.stage === "fulfilled" && !options.dueOnly) {
2819
- const access = await accessOf4(session, ref);
2770
+ const access = await accessOf2(session, ref);
2820
2771
  if (!isCurrent(session)) return;
2821
2772
  if (access === "granted") setPayment(ref.key, "granted");
2822
2773
  else if (access === "none") payments.delete(ref.key);
@@ -2876,7 +2827,7 @@ function enabledCheckout(deps) {
2876
2827
  if (isFinalRefusal(payment.status)) return markNeedsSupport(partition, ref);
2877
2828
  if (payment.status !== "approved") return backOff(partition, ref, false);
2878
2829
  if (!ref.kind) return settleUnassociated(partition, ref);
2879
- const access = await accessOf4(session, ref);
2830
+ const access = await accessOf2(session, ref);
2880
2831
  if (!isCurrent(session)) return;
2881
2832
  if (access === "granted") return grant(partition, ref);
2882
2833
  backOff(partition, ref, access === "none");
@@ -2892,7 +2843,7 @@ function enabledCheckout(deps) {
2892
2843
  partition.remove(ref.key);
2893
2844
  setPayment(ref.key, "accessUnknown");
2894
2845
  }
2895
- async function accessOf4(session, ref) {
2846
+ async function accessOf2(session, ref) {
2896
2847
  const adapter = deps.adapters.find((candidate) => candidate.kind === ref.kind);
2897
2848
  if (!adapter || !ref.verticalRef) return "unavailable";
2898
2849
  return adapter.readAccess(ref.verticalRef, bindBridge(session, deps.session, bridge));
@@ -3383,9 +3334,6 @@ function accessRefused(refusal) {
3383
3334
  function isRefusal(outcome) {
3384
3335
  return outcome.status !== "ok";
3385
3336
  }
3386
- function isHttp(outcome, httpStatus) {
3387
- return outcome.status === "http" && outcome.httpStatus === httpStatus;
3388
- }
3389
3337
  function bodyObject(outcome, name) {
3390
3338
  const body = outcome.body;
3391
3339
  return isObject7(body) && isObject7(body[name]) ? body[name] : null;
@@ -3458,121 +3406,13 @@ var NO_ACCESS_STATUS = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPEN
3458
3406
  var ENDED_STATUS = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED"]);
3459
3407
  var NO_ACCESS_PAYMENT = /* @__PURE__ */ new Set(["PAYMENT_FAILED", "PAYMENT_CANCELED"]);
3460
3408
 
3461
- // ../../stdlib/flows/iap-checkout/src/iap-verticals/online-programs-orders.ts
3462
- var KIND2 = "onlineProgram";
3463
- var BASE2 = "/online-programs/participants/v3/join-applications";
3464
- var onlineProgramClientOrders = {
3465
- kind: KIND2,
3466
- eligibility: (item) => singleUnitOf(KIND2, item),
3467
- openOrder,
3468
- reopenOrder,
3469
- readAccess: readAccess2,
3470
- currentAccess: currentAccess2
3471
- };
3472
- async function openOrder(item, bridge) {
3473
- const found = await currentApplication(item.reference.id, bridge);
3474
- if ("attempt" in found) return found.attempt;
3475
- const read2 = found.application ? { application: found.application } : await createdApplication(item.reference.id, bridge);
3476
- if ("attempt" in read2) return read2.attempt;
3477
- return orderOf(read2.application, bridge, { mayPrepare: true });
3478
- }
3479
- async function reopenOrder(order, bridge) {
3480
- const read2 = await applicationById(order.verticalRef.joinApplicationId, bridge);
3481
- if ("attempt" in read2) return read2.attempt;
3482
- const attempt3 = await orderOf(read2.application, bridge, { mayPrepare: false });
3483
- return attempt3.status === "open" && attempt3.cashierOrderId !== order.cashierOrderId ? ORDER_CLOSED : attempt3;
3484
- }
3485
- async function readAccess2(verticalRef, bridge) {
3486
- if (!isNonEmpty3(verticalRef.joinApplicationId)) return "unavailable";
3487
- const answer = await bridge.call("GET", `${BASE2}/${encodeURIComponent(verticalRef.joinApplicationId)}`);
3488
- if (isRefusal(answer)) return accessRefused(answer);
3489
- const application = bodyObject(answer, "joinApplication");
3490
- return application ? accessOf2(application) : "unavailable";
3491
- }
3492
- async function currentAccess2(item, bridge) {
3493
- const answer = await bridge.call("GET", `${BASE2}/current/${encodeURIComponent(item.reference.id)}`);
3494
- if (isRefusal(answer)) return accessRefused(answer);
3495
- const application = bodyObject(answer, "joinApplication");
3496
- if (!application) return "unavailable";
3497
- const access = accessOf2(application);
3498
- return access !== "granted" && ENDED_STATUS2.has(String(application.status)) ? "none" : access;
3499
- }
3500
- function accessOf2(application) {
3501
- const paid = application.paymentStatus === "PAYMENT_SUCCESSFUL" || application.paymentStatus === "NO_PAYMENT_REQUIRED";
3502
- if (application.status === "APPROVED" && paid && isNonEmpty3(application.participantId)) return "granted";
3503
- if (paid || PAYMENT_UNDER_WAY2.has(String(application.paymentStatus))) return "pending";
3504
- return NO_ACCESS_STATUS2.has(String(application.status)) || NO_ACCESS_PAYMENT2.has(String(application.paymentStatus)) ? "none" : "unavailable";
3505
- }
3506
- async function orderOf(application, bridge, options) {
3507
- if (accessOf2(application) === "granted") return GRANTED;
3508
- if (application.status === "APPROVAL_PENDING" || application.status === "INVITED") return { status: "refused", reason: "approvalRequired" };
3509
- if (application.status !== "APPROVED" && application.status !== "SUSPENDED") return ORDER_CLOSED;
3510
- const payment = String(application.paymentStatus);
3511
- if (payment === "NO_PAYMENT_REQUIRED" || payment === "PAYMENT_SUCCESSFUL") return { status: "refused", reason: "paymentInProgress" };
3512
- if (payment === "PENDING_OWNER_APPROVAL") return { status: "refused", reason: "approvalRequired" };
3513
- if (payment === "PAYMENT_IN_PROGRESS") return inProgressOrder(application);
3514
- if (!PREPARABLE.has(payment) || !options.mayPrepare) return ORDER_CLOSED;
3515
- return preparedOrder(application, bridge);
3516
- }
3517
- function inProgressOrder(application) {
3518
- const info = application.paymentInfo;
3519
- const orderId = info?.paymentOrderId;
3520
- if (!isNonEmpty3(orderId) || !isNonEmpty3(application.id)) return ORDER_REFUSED;
3521
- return { status: "open", cashierOrderId: orderId, verticalRef: { joinApplicationId: application.id, programId: String(application.programId ?? "") } };
3522
- }
3523
- async function preparedOrder(application, bridge) {
3524
- const id = String(application.id ?? "");
3525
- const answer = await bridge.call("POST", `${BASE2}/${encodeURIComponent(id)}/prepare-payment`, { paymentType: "SINGLE_PAYMENT" });
3526
- if (isHttp(answer, 428)) return reopenAfterRace(id, bridge);
3527
- if (isRefusal(answer)) return attemptRefused(answer);
3528
- const prepared = bodyObject(answer, "joinApplication");
3529
- return prepared ? orderOf(prepared, bridge, { mayPrepare: false }) : ORDER_REFUSED;
3530
- }
3531
- async function reopenAfterRace(id, bridge) {
3532
- const read2 = await applicationById(id, bridge);
3533
- return "attempt" in read2 ? read2.attempt : orderOf(read2.application, bridge, { mayPrepare: false });
3534
- }
3535
- async function currentApplication(programId, bridge) {
3536
- const answer = await bridge.call("GET", `${BASE2}/current/${encodeURIComponent(programId)}`);
3537
- if (isHttp(answer, 404)) return { application: null };
3538
- if (isRefusal(answer)) return { attempt: attemptRefused(answer) };
3539
- const application = bodyObject(answer, "joinApplication");
3540
- return application ? { application } : { attempt: ORDER_REFUSED };
3541
- }
3542
- async function createdApplication(programId, bridge) {
3543
- const answer = await bridge.call("POST", BASE2, { joinApplication: { programId } });
3544
- if (isHttp(answer, 409)) {
3545
- const existing = await currentApplication(programId, bridge);
3546
- if ("attempt" in existing) return existing;
3547
- return existing.application ? { application: existing.application } : { attempt: ORDER_REFUSED };
3548
- }
3549
- if (isRefusal(answer)) return { attempt: attemptRefused(answer) };
3550
- return applicationIn(answer);
3551
- }
3552
- async function applicationById(id, bridge) {
3553
- if (!isNonEmpty3(id)) return { attempt: ORDER_CLOSED };
3554
- const answer = await bridge.call("GET", `${BASE2}/${encodeURIComponent(id)}`);
3555
- if (isHttp(answer, 404)) return { attempt: ORDER_CLOSED };
3556
- if (isRefusal(answer)) return { attempt: attemptRefused(answer) };
3557
- return applicationIn(answer);
3558
- }
3559
- function applicationIn(answer) {
3560
- const application = bodyObject(answer, "joinApplication");
3561
- return application ? { application } : { attempt: ORDER_REFUSED };
3562
- }
3563
- var PREPARABLE = /* @__PURE__ */ new Set(["PAYMENT_PENDING", "PAYMENT_FAILED", "PAYMENT_CANCELED"]);
3564
- var PAYMENT_UNDER_WAY2 = /* @__PURE__ */ new Set(["PAYMENT_PENDING", "PAYMENT_IN_PROGRESS", "PENDING_OWNER_APPROVAL"]);
3565
- var NO_ACCESS_STATUS2 = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED", "INVITED", "APPROVAL_PENDING"]);
3566
- var ENDED_STATUS2 = /* @__PURE__ */ new Set(["CANCELLED", "DECLINED", "SUSPENDED"]);
3567
- var NO_ACCESS_PAYMENT2 = /* @__PURE__ */ new Set(["PAYMENT_FAILED", "PAYMENT_CANCELED"]);
3568
-
3569
3409
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans.ts
3570
- var KIND3 = "pricingPlan";
3410
+ var KIND2 = "pricingPlan";
3571
3411
  var PRICING_PLANS_APP = "1522827f-c56c-a5c9-2ac9-00f9e6ae12d3";
3572
3412
  var MEMBER_ORDERS = "/pricing-plans/v2/member/orders";
3573
3413
  var pricingPlanItemPayments = {
3574
- kind: KIND3,
3575
- eligibility: (item) => singleUnitOf(KIND3, item),
3414
+ kind: KIND2,
3415
+ eligibility: (item) => singleUnitOf(KIND2, item),
3576
3416
  itemPayment: itemPayment2,
3577
3417
  readAccess: (verticalRef, bridge) => isNonEmpty3(verticalRef.planId) ? planAccess(verticalRef.planId, bridge) : Promise.resolve("unavailable"),
3578
3418
  currentAccess: (item, bridge) => planAccess(item.reference.id, bridge)
@@ -3607,87 +3447,9 @@ async function planAccess(planId, bridge) {
3607
3447
  }
3608
3448
  }
3609
3449
 
3610
- // ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans-orders.ts
3611
- var KIND4 = "pricingPlan";
3612
- var CHECKOUT = "/pricing-plans/v2/checkout/orders";
3613
- var MEMBER_ORDERS2 = "/pricing-plans/v2/member/orders";
3614
- var pricingPlanClientOrders = {
3615
- kind: KIND4,
3616
- eligibility: (item) => singleUnitOf(KIND4, item),
3617
- openOrder: openOrder2,
3618
- reopenOrder: reopenOrder2,
3619
- readAccess: readAccess3,
3620
- currentAccess: currentAccess3
3621
- };
3622
- async function currentAccess3(item, bridge) {
3623
- let pending = false;
3624
- const pages = /* @__PURE__ */ new Set();
3625
- for (let offset = 0; ; offset += 50) {
3626
- const answer = await bridge.call("GET", `${MEMBER_ORDERS2}?orderStatuses=ACTIVE&orderStatuses=PENDING&orderStatuses=DRAFT&limit=50&offset=${offset}`);
3627
- if (isRefusal(answer)) return accessRefused(answer);
3628
- const orders = answer.body?.orders;
3629
- if (!Array.isArray(orders)) return "unavailable";
3630
- const page = JSON.stringify(orders.map((order) => [order.id, order.planId, order.status]));
3631
- if (orders.length === 50 && pages.has(page)) return "unavailable";
3632
- pages.add(page);
3633
- const selected = orders.filter((order) => order.planId === item.reference.id);
3634
- if (selected.some((order) => order.status === "ACTIVE")) return "granted";
3635
- pending || (pending = selected.some((order) => order.status === "PENDING" || order.status === "DRAFT"));
3636
- if (orders.length < 50) return pending ? "pending" : "none";
3637
- }
3638
- }
3639
- async function openOrder2(item, bridge) {
3640
- const planId = item.reference.id;
3641
- const preview = await bridge.call("POST", `${CHECKOUT}/preview-online`, { planId });
3642
- if (isRefusal(preview)) return attemptRefused(preview);
3643
- if (!isOneTimeUnlimited(bodyObject(preview, "order"))) return { status: "refused", reason: "unsupportedItem" };
3644
- const created = await bridge.call("POST", `${CHECKOUT}/online`, { planId });
3645
- if (isRefusal(created)) return attemptRefused(created);
3646
- return orderOf2(bodyObject(created, "order"), planId);
3647
- }
3648
- async function reopenOrder2(order, bridge) {
3649
- const read2 = await memberOrder(order.verticalRef.orderId, bridge);
3650
- if ("attempt" in read2) return read2.attempt;
3651
- const attempt3 = orderOf2(read2.order, order.verticalRef.planId ?? "");
3652
- return attempt3.status === "open" && attempt3.cashierOrderId !== order.cashierOrderId ? ORDER_CLOSED : attempt3;
3653
- }
3654
- async function readAccess3(verticalRef, bridge) {
3655
- if (!isNonEmpty3(verticalRef.orderId)) return isNonEmpty3(verticalRef.planId) ? planAccess(verticalRef.planId, bridge) : "unavailable";
3656
- const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(verticalRef.orderId)}`);
3657
- if (isRefusal(answer)) return accessRefused(answer);
3658
- const order = bodyObject(answer, "order");
3659
- return order ? accessOf3(order) : "unavailable";
3660
- }
3661
- function accessOf3(order) {
3662
- if (order.status === "ACTIVE") return "granted";
3663
- if (order.status === "PENDING") return "pending";
3664
- if (order.status === "DRAFT") return "pending";
3665
- return NO_ACCESS.has(String(order.status)) ? "none" : "unavailable";
3666
- }
3667
- var NO_ACCESS = /* @__PURE__ */ new Set(["CANCELED", "ENDED", "PAUSED"]);
3668
- function orderOf2(order, planId) {
3669
- if (!order || !isNonEmpty3(order.id)) return ORDER_REFUSED;
3670
- if (accessOf3(order) === "granted") return GRANTED;
3671
- if (order.status === "PENDING") return { status: "refused", reason: "paymentInProgress" };
3672
- if (order.status !== "DRAFT") return ORDER_CLOSED;
3673
- if (!isNonEmpty3(order.wixPayOrderId)) return ORDER_REFUSED;
3674
- return { status: "open", cashierOrderId: order.wixPayOrderId, verticalRef: { orderId: order.id, planId } };
3675
- }
3676
- async function memberOrder(orderId, bridge) {
3677
- if (!isNonEmpty3(orderId)) return { attempt: ORDER_CLOSED };
3678
- const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(orderId)}`);
3679
- if (isRefusal(answer)) return { attempt: answer.status === "http" && answer.httpStatus === 404 ? ORDER_CLOSED : attemptRefused(answer) };
3680
- return { order: bodyObject(answer, "order") };
3681
- }
3682
- function isOneTimeUnlimited(order) {
3683
- const pricing = order?.pricing;
3684
- return pricing?.singlePaymentUnlimited === true;
3685
- }
3686
-
3687
3450
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/attendance.ts
3688
3451
  var BOOKING = "bookingsService";
3689
3452
  var TICKET = "eventsTicket";
3690
- var NOT_ENABLED = { status: "refused", reason: "notEnabled" };
3691
3453
  var WIX_BOOKINGS_APP = "13d21c63-b5ec-5912-8397-c3a5ddb27a97";
3692
3454
  var CHANGED = { status: "refused", reason: "productChanged" };
3693
3455
  var WIX_EVENTS_APP = "140603ad-af8d-84a5-2c80-a0f60cb47351";
@@ -3695,34 +3457,28 @@ var RELEASE_MARGIN_MS = 3e5;
3695
3457
  var PAYMENT_TAKEN = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
3696
3458
  var HAS_OFFSET = /(?:Z|[+-]\d{2}:?\d{2})$/i;
3697
3459
  var LATEST_ZONE_MS = 432e5;
3698
- function attendanceOrdersWith(options) {
3699
- return {
3700
- bookingOrders: {
3701
- kind: BOOKING,
3702
- repeatable: true,
3703
- eligibility: (item) => eligible(item, BOOKING, options.bookingsEnabled),
3704
- itemPayment: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? bookingPayment(item, bridge, beforeCreate, afterCreate) : NOT_ENABLED,
3705
- resolveOpening: resolveBookingOpening,
3706
- readAccess: bookingAccess
3707
- },
3708
- eventTicketOrders: {
3709
- kind: TICKET,
3710
- repeatable: true,
3711
- eligibility: (item) => eligible(item, TICKET, options.eventsEnabled),
3712
- itemPayment: ticketPayment,
3713
- readAccess: ticketAccess
3714
- }
3715
- };
3716
- }
3717
- var { bookingOrders: bookingItemPayments, eventTicketOrders: eventTicketItemPayments } = /* @__PURE__ */ attendanceOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
3718
- function eligible(item, kind, enabled) {
3719
- if (!enabled) return { eligible: false, reason: "notEnabled" };
3460
+ var bookingItemPayments = {
3461
+ kind: BOOKING,
3462
+ repeatable: true,
3463
+ eligibility: (item) => eligible(item, BOOKING),
3464
+ itemPayment: bookingPayment,
3465
+ resolveOpening: resolveBookingOpening,
3466
+ readAccess: bookingAccess
3467
+ };
3468
+ var eventTicketItemPayments = {
3469
+ kind: TICKET,
3470
+ repeatable: true,
3471
+ eligibility: (item) => eligible(item, TICKET),
3472
+ itemPayment: ticketPayment,
3473
+ readAccess: ticketAccess
3474
+ };
3475
+ function eligible(item, kind) {
3720
3476
  if (!singleUnitOf(kind, item).eligible || !isNonEmpty3(item.attemptId) || !item.attendance) return UNSUPPORTED;
3721
3477
  if (kind === TICKET) return isNonEmpty3(item.attendance.ticket?.eventId) ? { eligible: true } : UNSUPPORTED;
3722
3478
  return item.attendance.booking ? { eligible: true } : UNSUPPORTED;
3723
3479
  }
3724
3480
  async function bookingPayment(item, bridge, beforeCreate, afterCreate) {
3725
- if (!eligible(item, BOOKING, true).eligible) return notCreated(ORDER_REFUSED);
3481
+ if (!eligible(item, BOOKING).eligible) return notCreated(ORDER_REFUSED);
3726
3482
  const selected = item.attendance.booking;
3727
3483
  if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated(ORDER_REFUSED);
3728
3484
  const read2 = await bridge.call("GET", `/bookings/v2/services/${encodeURIComponent(item.reference.id)}`);
@@ -3837,224 +3593,17 @@ function notCreated(attempt3) {
3837
3593
  return { ...attempt3, noOrderCreated: true };
3838
3594
  }
3839
3595
 
3840
- // ../../stdlib/flows/iap-checkout/src/iap-verticals/attendance-orders.ts
3841
- var BOOKING2 = "bookingsService";
3842
- var TICKET2 = "eventsTicket";
3843
- var NOT_ENABLED2 = { status: "refused", reason: "notEnabled" };
3844
- var CHANGED2 = { status: "refused", reason: "productChanged" };
3845
- var MINUTE_MS = 6e4;
3846
- var RELEASE_MARGIN_MS2 = 3e5;
3847
- var DEFAULT_RESERVATION_MINUTES = 60;
3848
- var PAYMENT_TAKEN2 = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
3849
- var HAS_OFFSET2 = /(?:Z|[+-]\d{2}:?\d{2})$/i;
3850
- var LATEST_ZONE_MS2 = 432e5;
3851
- function attendanceClientOrdersWith(options) {
3852
- const now = options.now ?? Date.now;
3853
- return {
3854
- bookingOrders: {
3855
- kind: BOOKING2,
3856
- repeatable: true,
3857
- eligibility: (item) => eligible2(item, BOOKING2, options.bookingsEnabled),
3858
- openOrder: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? openBooking(item, bridge, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
3859
- resolveOpening: resolveBookingOpening2,
3860
- readAccess: bookingAccess2,
3861
- reopenOrder: (order, bridge) => reopen(order, bridge, bookingAccess2)
3862
- },
3863
- eventTicketOrders: {
3864
- kind: TICKET2,
3865
- repeatable: true,
3866
- eligibility: (item) => eligible2(item, TICKET2, options.eventsEnabled),
3867
- openOrder: (item, bridge, beforeCreate, afterCreate) => options.eventsEnabled ? openTicket(item, bridge, now, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
3868
- readAccess: ticketAccess2,
3869
- reopenOrder: (order, bridge) => reopen(order, bridge, ticketAccess2, now)
3870
- }
3871
- };
3872
- }
3873
- var { bookingOrders: bookingClientOrders, eventTicketOrders: eventTicketClientOrders } = /* @__PURE__ */ attendanceClientOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
3874
- function eligible2(item, kind, enabled) {
3875
- if (!enabled) return { eligible: false, reason: "notEnabled" };
3876
- if (!singleUnitOf(kind, item).eligible || !isNonEmpty3(item.attemptId) || !item.attendance) return UNSUPPORTED;
3877
- const selection = kind === BOOKING2 ? item.attendance.booking : item.attendance.ticket;
3878
- return selection ? { eligible: true } : UNSUPPORTED;
3879
- }
3880
- async function openBooking(item, bridge, beforeCreate, afterCreate) {
3881
- if (!eligible2(item, BOOKING2, true).eligible) return notCreated2(ORDER_REFUSED);
3882
- const selected = item.attendance.booking;
3883
- if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated2(ORDER_REFUSED);
3884
- const read2 = await bridge.call("GET", `/bookings/v2/services/${encodeURIComponent(item.reference.id)}`);
3885
- if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
3886
- const service = bodyObject(read2, "service");
3887
- const metadata = bookingAttendanceOf(service);
3888
- if (classifyForApple(metadata, item.attendance.currency) !== "appleIap" || !samePrice2({ amount: metadata.amount, currency: metadata.currency }, item)) return notCreated2(CHANGED2);
3889
- if (isObject7(service?.onlineBooking) && service.onlineBooking.requireManualApproval === true) return notCreated2({ status: "refused", reason: "approvalRequired" });
3890
- const availability = await bridge.call("POST", "/bookings/v1/availability/query", { query: { filter: { serviceId: [item.reference.id], startDate: selected.slot.startDate, endDate: selected.slot.endDate, bookable: true } } });
3891
- if (isRefusal(availability)) return notCreated2(attemptRefused(availability));
3892
- const entries = isObject7(availability.body) ? availability.body.availabilityEntries : void 0;
3893
- if (!Array.isArray(entries) || !entries.some((entry) => isObject7(entry) && entry.bookable === true && matchesSlot2(entry.slot, selected.slot))) return notCreated2(CHANGED2);
3894
- if (beforeCreate && !beforeCreate(slotGuard2(selected.slot))) return notCreated2({ status: "refused", reason: "storageUnavailable" });
3895
- const created = await bridge.call("POST", "/bookings/v2/bookings", { booking: { bookedEntity: { slot: selected.slot }, contactDetails: selected.contactDetails, totalParticipants: 1, selectedPaymentOption: "ONLINE", ...selected.formInfo ? { formInfo: selected.formInfo } : {} } });
3896
- if (isRefusal(created)) return creationRefused2(created);
3897
- const bookingId = bodyObject(created, "booking")?.id;
3898
- if (!isNonEmpty3(bookingId)) return ORDER_REFUSED;
3899
- if (afterCreate?.({ verticalRef: { bookingId } }) === false) return { status: "unavailable" };
3900
- return bookingCheckout(item, bookingId, bridge);
3901
- }
3902
- function slotGuard2(slot) {
3903
- const verticalRef = {};
3904
- for (const key of ["sessionId", "startDate"]) if (isNonEmpty3(slot[key])) verticalRef[key] = slot[key];
3905
- const ends = latestInstant2(String(slot.endDate));
3906
- return Number.isFinite(ends) ? { verticalRef, releaseAt: ends + RELEASE_MARGIN_MS2 } : { verticalRef };
3907
- }
3908
- function latestInstant2(value) {
3909
- if (HAS_OFFSET2.test(value)) return Date.parse(value);
3910
- return Date.parse(`${value}Z`) + LATEST_ZONE_MS2;
3911
- }
3912
- async function resolveBookingOpening2(guard, item, bridge, options) {
3913
- const scope = sameSlot2(guard.verticalRef, item?.attendance?.booking?.slot) ? "held" : "unrelated";
3914
- const bookingId = guard.verticalRef?.bookingId;
3915
- if (!bookingId || !options.settled) return scope;
3916
- const released2 = await releaseBooking2(bookingId, bridge, options.claim);
3917
- return released2 === "held" || released2 === "unavailable" && scope === "unrelated" ? scope : released2;
3918
- }
3919
- async function releaseBooking2(bookingId, bridge, claim) {
3920
- const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: bookingId } } } });
3921
- if (isRefusal(read2)) return read2.status === "http" && read2.httpStatus === 404 ? "released" : openingRefused2(read2);
3922
- const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
3923
- const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === bookingId) : void 0;
3924
- if (!isObject7(booking)) return "held";
3925
- if (["CANCELED", "CANCELLED", "DECLINED"].includes(String(booking.status)) || PAYMENT_TAKEN2.includes(String(booking.paymentStatus))) return "released";
3926
- if (booking.status !== "CREATED" || !claim()) return "held";
3927
- const cancelled = await bridge.call("POST", `/bookings/v2/bookings/${encodeURIComponent(bookingId)}/cancel`, { participantNotification: { notifyParticipants: false }, revision: booking.revision });
3928
- return isRefusal(cancelled) ? openingRefused2(cancelled) : "released";
3929
- }
3930
- function openingRefused2(refusal) {
3931
- if (refusal.status === "sessionChanged") return "sessionChanged";
3932
- return refusal.status === "unavailable" ? "unavailable" : "held";
3933
- }
3934
- function sameSlot2(guarded, slot) {
3935
- if (!guarded || !slot) return true;
3936
- return guarded.sessionId === slot.sessionId && Date.parse(guarded.startDate ?? "") === Date.parse(String(slot.startDate));
3937
- }
3938
- async function bookingCheckout(item, bookingId, bridge) {
3939
- const checkout = await bridge.call("POST", "/ecom/v1/checkouts", { lineItems: [{ quantity: 1, catalogReference: { appId: "13d21c63-b5ec-5912-8397-c3a5ddb27a97", catalogItemId: bookingId } }], channelType: "OTHER_PLATFORM" });
3940
- if (isRefusal(checkout)) return attemptRefused(checkout);
3941
- const entity = bodyObject(checkout, "checkout");
3942
- const total = isObject7(entity?.priceSummary) ? entity.priceSummary.total : void 0;
3943
- if (!isObject7(total) || !samePrice2({ amount: total.amount, currency: entity?.currency }, item)) return CHANGED2;
3944
- if (!isNonEmpty3(entity?.id)) return ORDER_REFUSED;
3945
- const placed = await bridge.call("POST", `/ecom/v1/checkouts/${encodeURIComponent(entity.id)}/create-order`, {});
3946
- if (isRefusal(placed)) return attemptRefused(placed);
3947
- const body = placed.body;
3948
- if (!isObject7(body) || !isNonEmpty3(body.orderId) || !isNonEmpty3(body.paymentGatewayOrderId)) return ORDER_REFUSED;
3949
- return { status: "open", cashierOrderId: body.paymentGatewayOrderId, verticalRef: { serviceId: item.reference.id, bookingId, orderId: body.orderId } };
3950
- }
3951
- async function bookingAccess2(ref, bridge) {
3952
- if (!ref.bookingId || !ref.orderId) return "unavailable";
3953
- const order = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(ref.orderId)}`);
3954
- if (isRefusal(order)) return accessRefused(order);
3955
- const payment = bodyObject(order, "order")?.paymentStatus;
3956
- if (payment === "FULLY_REFUNDED" || payment === "PARTIALLY_REFUNDED") return "none";
3957
- const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: ref.bookingId } } } });
3958
- if (isRefusal(read2)) return accessRefused(read2);
3959
- const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
3960
- const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === ref.bookingId) : void 0;
3961
- if (!isObject7(booking)) return "unavailable";
3962
- if (booking.status === "CANCELED" || booking.status === "CANCELLED" || booking.status === "DECLINED") return "none";
3963
- return payment === "PAID" && booking.status === "CONFIRMED" && booking.paymentStatus === "PAID" ? "granted" : "pending";
3964
- }
3965
- async function openTicket(item, bridge, now, beforeCreate, afterCreate) {
3966
- if (!eligible2(item, TICKET2, true).eligible) return notCreated2(ORDER_REFUSED);
3967
- const selected = item.attendance.ticket;
3968
- if (!isNonEmpty3(selected.eventId)) return notCreated2(ORDER_REFUSED);
3969
- const read2 = await bridge.call("GET", `/events/v3/events/${encodeURIComponent(selected.eventId)}?fields=REGISTRATION&fields=DETAILS&fields=FORM`);
3970
- if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
3971
- const available = await bridge.call("POST", "/events/v1/checkout/available-tickets/query", { filter: { eventId: selected.eventId }, limit: 100, offset: 0 });
3972
- if (isRefusal(available)) return notCreated2(attemptRefused(available));
3973
- const definitions = isObject7(available.body) ? available.body.definitions : void 0;
3974
- const live = Array.isArray(definitions) ? definitions.find((t) => isObject7(t) && t.id === item.reference.id && t.saleStatus === "SALE_STARTED") : void 0;
3975
- if (!isObject7(live) || !samePrice2(live.price, item)) return notCreated2(CHANGED2);
3976
- const event = bodyObject(read2, "event");
3977
- if (live.eventId !== selected.eventId || classifyForApple(availableTicketAttendanceOf(event, live), item.attendance.currency) !== "appleIap") return notCreated2(ORDER_REFUSED);
3978
- if (beforeCreate && !beforeCreate({ releaseAt: now() + reservationMinutes(event) * MINUTE_MS + RELEASE_MARGIN_MS2 })) return notCreated2({ status: "refused", reason: "storageUnavailable" });
3979
- return reserveTicket(item, bridge, now, afterCreate);
3980
- }
3981
- function reservationMinutes(event) {
3982
- const registration = isObject7(event?.registration) ? event.registration : void 0;
3983
- const minutes = isObject7(registration?.tickets) ? registration.tickets.reservationDurationInMinutes : void 0;
3984
- return typeof minutes === "number" && minutes > 0 ? minutes : DEFAULT_RESERVATION_MINUTES;
3985
- }
3986
- async function reserveTicket(item, bridge, now, afterCreate) {
3987
- const selected = item.attendance.ticket;
3988
- const held = await bridge.call("POST", "/events/v1/checkout/reservations", { eventId: selected.eventId, ticketQuantities: [{ ticketDefinitionId: item.reference.id, quantity: 1 }], ignoreLimits: false, allowHiddenTickets: false });
3989
- if (isRefusal(held)) return creationRefused2(held);
3990
- const reservation = held.body;
3991
- if (!isObject7(reservation) || !isNonEmpty3(reservation.id) || !future(reservation.expires, now)) return ORDER_CLOSED;
3992
- if (afterCreate?.({ verticalRef: { reservationId: reservation.id }, releaseAt: Date.parse(reservation.expires) + RELEASE_MARGIN_MS2 }) === false) return { status: "unavailable" };
3993
- if (!heldAsSelected(reservation, item)) return CHANGED2;
3994
- const placed = await bridge.call("POST", "/events/v1/checkout", { eventId: selected.eventId, reservationId: reservation.id, buyer: selected.buyer, ...selected.guests ? { guests: selected.guests } : {}, ...selected.buyerSubmission ? { buyerSubmission: selected.buyerSubmission } : {}, ...selected.guestSubmissions ? { guestSubmissions: selected.guestSubmissions } : {}, options: { silent: false, payInPerson: false, ignoreFormValidation: false, markAsPaid: false } });
3995
- if (isRefusal(placed)) return attemptRefused(placed);
3996
- const order = bodyObject(placed, "order");
3997
- if (!samePrice2(order?.totalPrice, item)) return CHANGED2;
3998
- const expires = isObject7(placed.body) && placed.body.expires || reservation.expires;
3999
- if (!future(expires, now) || !isNonEmpty3(order?.snapshotId) || !isNonEmpty3(order?.orderNumber)) return ORDER_CLOSED;
4000
- return { status: "open", cashierOrderId: order.snapshotId, verticalRef: { eventId: selected.eventId, ticketDefinitionId: item.reference.id, reservationId: reservation.id, orderNumber: order.orderNumber, expires: String(expires) } };
4001
- }
4002
- async function ticketAccess2(ref, bridge) {
4003
- if (isNonEmpty3(ref.orderId)) return ecomOrderAccess(ref.orderId, bridge);
4004
- if (!ref.eventId || !ref.orderNumber || !ref.ticketDefinitionId) return "unavailable";
4005
- const read2 = await bridge.call("GET", `/events/v1/events/${encodeURIComponent(ref.eventId)}/orders/${encodeURIComponent(ref.orderNumber)}?fieldset=DETAILS&fieldset=TICKETS`);
4006
- if (isRefusal(read2)) return accessRefused(read2);
4007
- const order = bodyObject(read2, "order");
4008
- if (order?.status === "CANCELED" || order?.status === "CANCELLED" || order?.status === "REFUNDED") return "none";
4009
- const issued = Array.isArray(order?.tickets) && order.tickets.some((t) => isObject7(t) && isNonEmpty3(t.ticketNumber) && t.orderStatus === "PAID" && t.ticketDefinitionId === ref.ticketDefinitionId);
4010
- return order?.status === "PAID" && issued ? "granted" : order ? "pending" : "unavailable";
4011
- }
4012
- async function reopen(order, bridge, accessOf4, now) {
4013
- const access = await accessOf4(order.verticalRef, bridge);
4014
- if (access === "granted") return GRANTED;
4015
- if (access === "unavailable" || access === "sessionChanged") return { status: access };
4016
- if (access === "none" || now && !future(order.verticalRef.expires, now)) return ORDER_CLOSED;
4017
- return { status: "open", ...order };
4018
- }
4019
- function heldAsSelected(reservation, item) {
4020
- if (isObject7(reservation.invoice)) return samePrice2(reservation.invoice.grandTotal ?? reservation.invoice.total, item);
4021
- const lines = reservation.reservations;
4022
- if (!Array.isArray(lines) || lines.length !== 1 || !isObject7(lines[0]) || lines[0].quantity !== 1) return false;
4023
- const held = lines[0].ticket;
4024
- return isObject7(held) && held.id === item.reference.id && samePrice2(held.price, item);
4025
- }
4026
- function samePrice2(value, item) {
4027
- return isObject7(value) && value.currency === item.attendance?.currency && decimal2(value.amount) !== null && decimal2(value.amount) === decimal2(item.attendance?.amount);
4028
- }
4029
- function decimal2(value) {
4030
- if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return null;
4031
- return value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
4032
- }
4033
- function future(value, now) {
4034
- return typeof value === "string" && Number.isFinite(Date.parse(value)) && Date.parse(value) > now();
4035
- }
4036
- function matchesSlot2(value, selected) {
4037
- return isObject7(value) && ["serviceId", "sessionId"].every((key) => value[key] === selected[key]) && ["startDate", "endDate"].every((key) => typeof value[key] === "string" && Date.parse(value[key]) === Date.parse(String(selected[key])));
4038
- }
4039
- function creationRefused2(refusal) {
4040
- const attempt3 = attemptRefused(refusal);
4041
- return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated2(attempt3) : attempt3;
4042
- }
4043
- function notCreated2(attempt3) {
4044
- return { ...attempt3, noOrderCreated: true };
4045
- }
4046
-
4047
3596
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/stores.ts
4048
- var KIND5 = "storesProduct";
3597
+ var KIND3 = "storesProduct";
4049
3598
  var WIX_STORES_APP = "215238eb-22a5-4c36-9e7b-e7c08025e04e";
4050
3599
  var storesProductOrders = {
4051
- kind: KIND5,
3600
+ kind: KIND3,
4052
3601
  eligibility,
4053
3602
  itemPayment: itemPayment3,
4054
- readAccess: readAccess4
3603
+ readAccess: readAccess2
4055
3604
  };
4056
3605
  function eligibility(item) {
4057
- const single = singleUnitOf(KIND5, item);
3606
+ const single = singleUnitOf(KIND3, item);
4058
3607
  if (!single.eligible) return single;
4059
3608
  const catalog = item.catalogReference;
4060
3609
  const variant = catalog?.options && Object.keys(catalog.options).length > 0;
@@ -4069,30 +3618,98 @@ function classifyCart(lines) {
4069
3618
  if (apple.length === 0) return "regular";
4070
3619
  return lines.length === 1 && apple[0].quantity === 1 ? "appleIap" : "mixedRefused";
4071
3620
  }
4072
- function readAccess4(verticalRef, bridge) {
3621
+ function readAccess2(verticalRef, bridge) {
4073
3622
  return ecomOrderAccess(verticalRef.orderId, bridge);
4074
3623
  }
4075
3624
 
4076
3625
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/videos.ts
4077
- var KIND6 = "wixVideo";
4078
- var NOT_ENABLED3 = { status: "refused", reason: "notEnabled" };
4079
- var NO_ORDER_STEP = { status: "refused", reason: "notConfigured" };
3626
+ var KIND4 = "wixVideo";
3627
+ var NOT_ENABLED = { status: "refused", reason: "notEnabled" };
3628
+ var VIDEO_GRAPHQL_URL = "https://manage.wix.com/_api/vod/public/graphql";
3629
+ var graphqlVideoPort = (bridge) => ({
3630
+ async openSaleOrder(videoId) {
3631
+ const answer = await bridge.call("POST", VIDEO_GRAPHQL_URL, { query: CREATE_ORDER, variables: { videoId } });
3632
+ if (isRefusal(answer)) return answer;
3633
+ const created = dataAt(answer.body, ["purchase", "order", "create"]);
3634
+ if (!created) return { status: "unavailable" };
3635
+ const orderId = isObject7(created.entity) ? created.entity.id : void 0;
3636
+ if (created.status === "SUCCESS" && isNonEmpty3(orderId)) return { status: "ok", orderId };
3637
+ const message = typeof created.message === "string" ? created.message : "";
3638
+ return { status: "refused", reason: message === PENDING_MESSAGE ? "pending" : message === ACTIVE_MESSAGE ? "active" : "other" };
3639
+ },
3640
+ async salePurchase(videoId) {
3641
+ const answer = await bridge.call("POST", VIDEO_GRAPHQL_URL, { query: SALE_PURCHASE, variables: { videoId } });
3642
+ if (isRefusal(answer)) return answer;
3643
+ const data = isObject7(answer.body) && isObject7(answer.body.data) ? answer.body.data : null;
3644
+ if (!data || !("purchase" in data)) return { status: "unavailable" };
3645
+ const found = isObject7(data.purchase) ? data.purchase : null;
3646
+ if (!found) return { status: "ok", purchase: null };
3647
+ if (!isNonEmpty3(found.status)) return { status: "unavailable" };
3648
+ return { status: "ok", purchase: { status: found.status, orderId: isNonEmpty3(found.orderId) ? found.orderId : null } };
3649
+ }
3650
+ });
4080
3651
  function videoOrdersWith(options) {
4081
- return {
4082
- kind: KIND6,
4083
- eligibility: (item) => options.enabled ? singleUnitOf(KIND6, item) : { eligible: false, reason: "notEnabled" },
4084
- openOrder: async () => options.enabled ? NO_ORDER_STEP : NOT_ENABLED3,
4085
- reopenOrder: async () => ORDER_CLOSED,
4086
- readAccess: async () => "unavailable"
3652
+ const portOf = options.port ?? graphqlVideoPort;
3653
+ const adapter = {
3654
+ kind: KIND4,
3655
+ eligibility: (item) => options.enabled ? singleUnitOf(KIND4, item) : { eligible: false, reason: "notEnabled" },
3656
+ openOrder: async (item, bridge) => options.enabled ? openOrder(item, portOf(bridge)) : NOT_ENABLED,
3657
+ reopenOrder: async (order, bridge) => options.enabled ? reopenOrder(order.verticalRef, portOf(bridge)) : ORDER_CLOSED,
3658
+ readAccess: async (verticalRef, bridge) => options.enabled ? readAccess3(verticalRef, portOf(bridge)) : "unavailable"
4087
3659
  };
4088
- }
4089
- var wixVideoOrders = /* @__PURE__ */ videoOrdersWith({ enabled: VIDEOS_APPLE_SALES_ENABLED });
3660
+ return adapter;
3661
+ }
3662
+ async function openOrder(item, port) {
3663
+ const videoId = item.reference.id;
3664
+ const answer = await port.openSaleOrder(videoId);
3665
+ if (answer.status === "ok") return { status: "open", cashierOrderId: answer.orderId, verticalRef: { videoId, orderId: answer.orderId } };
3666
+ if (answer.status !== "refused") return attemptRefused(answer);
3667
+ if (answer.reason === "active") return GRANTED;
3668
+ return answer.reason === "pending" ? { status: "refused", reason: "paymentInProgress" } : ORDER_REFUSED;
3669
+ }
3670
+ async function reopenOrder(verticalRef, port) {
3671
+ const { videoId, orderId } = verticalRef;
3672
+ if (!isNonEmpty3(videoId) || !isNonEmpty3(orderId)) return ORDER_CLOSED;
3673
+ const answer = await port.salePurchase(videoId);
3674
+ if (answer.status !== "ok") return attemptRefused(answer);
3675
+ const purchase = answer.purchase;
3676
+ if (purchase?.status === "ACTIVE") return GRANTED;
3677
+ if (purchase && purchase.orderId === orderId && UNPAID.has(purchase.status)) return { status: "open", cashierOrderId: orderId, verticalRef: { videoId, orderId } };
3678
+ return ORDER_CLOSED;
3679
+ }
3680
+ async function readAccess3(verticalRef, port) {
3681
+ const { videoId, orderId } = verticalRef;
3682
+ if (!isNonEmpty3(videoId) || !isNonEmpty3(orderId)) return "unavailable";
3683
+ const answer = await port.salePurchase(videoId);
3684
+ if (answer.status !== "ok") return accessRefused(answer);
3685
+ const purchase = answer.purchase;
3686
+ if (purchase?.status === "ACTIVE") return "granted";
3687
+ if (!purchase || purchase.orderId !== orderId) return "unavailable";
3688
+ if (UNPAID.has(purchase.status)) return "pending";
3689
+ return ENDED.has(purchase.status) ? "none" : "unavailable";
3690
+ }
3691
+ function dataAt(body, path) {
3692
+ let node = isObject7(body) && isObject7(body.data) ? body.data : body;
3693
+ for (const key of path) node = isObject7(node) ? node[key] : void 0;
3694
+ return isObject7(node) ? node : null;
3695
+ }
3696
+ var ENDED = /* @__PURE__ */ new Set(["DECLINED", "EXPIRED", "CANCELED", "REFUNDED", "FAILED"]);
3697
+ var UNPAID = /* @__PURE__ */ new Set(["INITIALIZED", "PENDING"]);
3698
+ var PENDING_MESSAGE = "Pending payment for the purchase";
3699
+ var ACTIVE_MESSAGE = "Active purchase already existed";
3700
+ var CREATE_ORDER = `mutation HimiVideoSaleOrder($videoId: ID!) {
3701
+ purchase { order { create(input: {id: $videoId, type: SALE}) { status message entity { id } } } }
3702
+ }`;
3703
+ var SALE_PURCHASE = `query HimiVideoSalePurchase($videoId: ID!) {
3704
+ purchase(filter: {id: $videoId, type: SALE}) { status orderId }
3705
+ }`;
3706
+ var wixVideoOrders = /* @__PURE__ */ videoOrdersWith({ enabled: videosAppleSalesEnabled() });
4090
3707
 
4091
3708
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/index.ts
4092
- var onlineProgramOrders = ONLINE_PROGRAM_ITEM_PAYMENT_ENABLED ? onlineProgramItemPayments : onlineProgramClientOrders;
4093
- var pricingPlanOrders = PRICING_PLAN_ITEM_PAYMENT_ENABLED ? pricingPlanItemPayments : pricingPlanClientOrders;
4094
- var bookingOrders = BOOKINGS_ITEM_PAYMENT_ENABLED ? bookingItemPayments : bookingClientOrders;
4095
- var eventTicketOrders = EVENTS_ITEM_PAYMENT_ENABLED ? eventTicketItemPayments : eventTicketClientOrders;
3709
+ var onlineProgramOrders = onlineProgramItemPayments;
3710
+ var pricingPlanOrders = pricingPlanItemPayments;
3711
+ var bookingOrders = bookingItemPayments;
3712
+ var eventTicketOrders = eventTicketItemPayments;
4096
3713
  export {
4097
3714
  bookingOrders,
4098
3715
  classifyCart,
@@ -4105,6 +3722,7 @@ export {
4105
3722
  pricingPlanOrders,
4106
3723
  storesAppleSalesEnabled,
4107
3724
  storesProductOrders,
3725
+ videosAppleSalesEnabled,
4108
3726
  wixVideoOrders
4109
3727
  };
4110
3728
  //# sourceMappingURL=iap-checkout.mjs.map