@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,17 +161,17 @@ function businessContactPoint(contact) {
161
161
  return contact.isPhysical !== false && p && typeof p.latitude === "number" && Number.isFinite(p.latitude) && Math.abs(p.latitude) <= 90 && typeof p.longitude === "number" && Number.isFinite(p.longitude) && Math.abs(p.longitude) <= 180 ? { latitude: p.latitude, longitude: p.longitude } : void 0;
162
162
  }
163
163
  function businessContactLink(kind, value) {
164
- const text3 = clean(value);
165
- if (!text3 || /[\u0000-\u001f\u007f]/.test(text3)) return "";
164
+ const text2 = clean(value);
165
+ if (!text2 || /[\u0000-\u001f\u007f]/.test(text2)) return "";
166
166
  switch (kind) {
167
167
  case "website":
168
- return /^https?:\/\/[^\s/@]+(?:[/:?#]|$)/i.test(text3) && !/\s/.test(text3) && !/^https?:\/\/[^/]*@/i.test(text3) ? text3 : "";
168
+ return /^https?:\/\/[^\s/@]+(?:[/:?#]|$)/i.test(text2) && !/\s/.test(text2) && !/^https?:\/\/[^/]*@/i.test(text2) ? text2 : "";
169
169
  case "phone":
170
- return /^\+?[\d ()\-.]+$/.test(text3) && /\d/.test(text3) ? `tel:${text3.replace(/[ ()\-.]/g, "")}` : "";
170
+ return /^\+?[\d ()\-.]+$/.test(text2) && /\d/.test(text2) ? `tel:${text2.replace(/[ ()\-.]/g, "")}` : "";
171
171
  case "email":
172
- return /^[^\s@?&#]+@[^\s@?&#]+\.[^\s@?&#]+$/.test(text3) ? `mailto:${encodeURIComponent(text3)}` : "";
172
+ return /^[^\s@?&#]+@[^\s@?&#]+\.[^\s@?&#]+$/.test(text2) ? `mailto:${encodeURIComponent(text2)}` : "";
173
173
  case "directions":
174
- return `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(text3)}`;
174
+ return `https://www.google.com/maps/dir/?api=1&destination=${encodeURIComponent(text2)}`;
175
175
  default:
176
176
  return "";
177
177
  }
@@ -183,7 +183,7 @@ function businessContactSection(opts = {}) {
183
183
  const copy = { title: "Get in touch", message: "Message", directions: "Directions", unavailable: "Contact details unavailable", memberCountUnavailable: "Member count unavailable", member: "member", members: "members", ...opts.copy };
184
184
  const service = opts.service ?? "businessContact";
185
185
  const children = [];
186
- const text3 = (key, value, style = "body") => node(`${id2}.${key}`, "Text", { text: value, style, collapseWhenEmpty: true });
186
+ const text2 = (key, value, style = "body") => node(`${id2}.${key}`, "Text", { text: value, style, collapseWhenEmpty: true });
187
187
  const link = (key, label, value) => {
188
188
  if (businessContactLink(key, value)) children.push(node(`${id2}.${key}`, "Button", {
189
189
  title: label,
@@ -192,10 +192,10 @@ function businessContactSection(opts = {}) {
192
192
  action: { actionId: `tier5.${service}.open`, params: { kind: key, value, failureLabel: copy.unavailable } }
193
193
  }));
194
194
  };
195
- if (settings.isDescriptionVisible && clean(contact.description)) children.push(text3("description", clean(contact.description)));
195
+ if (settings.isDescriptionVisible && clean(contact.description)) children.push(text2("description", clean(contact.description)));
196
196
  if (settings.isGetInTouchVisible && opts.chatScreenId) {
197
- children.push(text3("title", clean(settings.getInTouchTitle) || copy.title, "title3"));
198
- if (clean(settings.getInTouchDescription)) children.push(text3("subtitle", clean(settings.getInTouchDescription)));
197
+ children.push(text2("title", clean(settings.getInTouchTitle) || copy.title, "title3"));
198
+ if (clean(settings.getInTouchDescription)) children.push(text2("subtitle", clean(settings.getInTouchDescription)));
199
199
  children.push(node(`${id2}.message`, "Button", {
200
200
  title: clean(settings.getInTouchButton) || copy.message,
201
201
  style: "primary",
@@ -208,7 +208,7 @@ function businessContactSection(opts = {}) {
208
208
  if (settings.isEmailVisible === true) link("email", clean(contact.email), clean(contact.email));
209
209
  if (settings.isAddressVisible) {
210
210
  const address = clean(contact.address);
211
- if (address) children.push(text3("address", address));
211
+ if (address) children.push(text2("address", address));
212
212
  const point = businessContactPoint(contact);
213
213
  if (settings.showMap && point) children.push(node(`${id2}.map`, "Map", {
214
214
  ...point,
@@ -221,9 +221,9 @@ function businessContactSection(opts = {}) {
221
221
  }
222
222
  const hasContent = children.length > 0;
223
223
  if (!(settings.isAddressVisible && clean(contact.address) && contact.isPhysical !== false)) {
224
- children.push({ ...text3("directions_copy", copy.directions), modifiers: { hidden: true } });
224
+ children.push({ ...text2("directions_copy", copy.directions), modifiers: { hidden: true } });
225
225
  }
226
- const unavailable2 = text3("unavailable", copy.unavailable);
226
+ const unavailable2 = text2("unavailable", copy.unavailable);
227
227
  if (hasContent) unavailable2.modifiers = { hidden: true };
228
228
  children.push(unavailable2);
229
229
  if (opts.showMemberCount !== void 0) {
@@ -231,8 +231,8 @@ function businessContactSection(opts = {}) {
231
231
  spacing: 4,
232
232
  alignment: "center",
233
233
  children: [
234
- text3(`count_${key}`, `$service:${service}.memberCount`, "footnote"),
235
- text3(`unit_${key}`, unit, "footnote")
234
+ text2(`count_${key}`, `$service:${service}.memberCount`, "footnote"),
235
+ text2(`unit_${key}`, unit, "footnote")
236
236
  ]
237
237
  });
238
238
  const count = node(`${id2}.member_count`, "FragmentSlot", {
@@ -241,13 +241,13 @@ function businessContactSection(opts = {}) {
241
241
  cases: [
242
242
  { id: "one", content: ready("one", copy.member) },
243
243
  { id: "other", content: ready("other", copy.members) },
244
- { id: "unavailable", content: text3("members_unavailable", copy.memberCountUnavailable, "footnote") }
244
+ { id: "unavailable", content: text2("members_unavailable", copy.memberCountUnavailable, "footnote") }
245
245
  ]
246
246
  });
247
247
  if (opts.showMemberCount === false) count.modifiers = { hidden: true };
248
248
  children.push(count);
249
249
  }
250
- children.push(text3("feedback", `$service:${service}.message`, "footnote"));
250
+ children.push(text2("feedback", `$service:${service}.message`, "footnote"));
251
251
  return node(id2, "VStack", { spacing: 12, alignment: "leading", children });
252
252
  }
253
253
 
@@ -482,8 +482,8 @@ function ricosToPlainText(doc) {
482
482
  const blocks = (nodes) => nodes.flatMap((node3) => node3.type === "PARAGRAPH" || node3.type === "HEADING" || node3.type === "TEXT" ? [inline(node3)] : blocks(kids(node3.nodes)));
483
483
  return blocks(kids(doc?.nodes)).join("\n\n");
484
484
  }
485
- function plainTextToRicos(text3) {
486
- return { nodes: text3.split("\n\n").map((t) => ({ type: "PARAGRAPH", nodes: [{ type: "TEXT", textData: { text: t, decorations: [] } }] })) };
485
+ function plainTextToRicos(text2) {
486
+ return { nodes: text2.split("\n\n").map((t) => ({ type: "PARAGRAPH", nodes: [{ type: "TEXT", textData: { text: t, decorations: [] } }] })) };
487
487
  }
488
488
  function encodeRichContent(doc, opts = {}) {
489
489
  if (doc === null || doc === void 0) return { json: "" };
@@ -699,13 +699,13 @@ function draftDocument(value) {
699
699
  const block2 = object(raw);
700
700
  if (typeof block2.text !== "string") return invalid();
701
701
  if (block2.depth !== void 0 && block2.depth !== 0) return unsupported();
702
- const text3 = block2.text;
702
+ const text2 = block2.text;
703
703
  const styles = block2.inlineStyleRanges ?? [];
704
704
  const ranges = block2.entityRanges ?? [];
705
705
  if (!Array.isArray(styles) || !Array.isArray(ranges) || styles.length + ranges.length > 500) return invalid();
706
706
  const spans = [...styles.map((v) => ({ ...object(v), kind: "style" })), ...ranges.map((v) => ({ ...object(v), kind: "entity" }))];
707
707
  for (const span of spans) {
708
- if (!Number.isInteger(span.offset) || !Number.isInteger(span.length) || Number(span.offset) < 0 || Number(span.length) < 0 || Number(span.offset) + Number(span.length) > text3.length) return invalid();
708
+ if (!Number.isInteger(span.offset) || !Number.isInteger(span.length) || Number(span.offset) < 0 || Number(span.length) < 0 || Number(span.offset) + Number(span.length) > text2.length) return invalid();
709
709
  }
710
710
  if (block2.type === "atomic") {
711
711
  if (ranges.length !== 1) return unsupported();
@@ -717,7 +717,7 @@ function draftDocument(value) {
717
717
  nodes.push({ type: "IMAGE", imageData: { image: { src: { url }, ...typeof data.width === "number" ? { width: data.width } : {}, ...typeof data.height === "number" ? { height: data.height } : {} }, ...typeof data.alt === "string" ? { altText: data.alt } : {} } });
718
718
  continue;
719
719
  }
720
- const cuts = [.../* @__PURE__ */ new Set([0, text3.length, ...spans.flatMap((s2) => [Number(s2.offset), Number(s2.offset) + Number(s2.length)])])].sort((a, b) => a - b);
720
+ const cuts = [.../* @__PURE__ */ new Set([0, text2.length, ...spans.flatMap((s2) => [Number(s2.offset), Number(s2.offset) + Number(s2.length)])])].sort((a, b) => a - b);
721
721
  const runs = [];
722
722
  for (let i = 1; i < cuts.length; i++) {
723
723
  const start = cuts[i - 1], end = cuts[i];
@@ -732,7 +732,7 @@ function draftDocument(value) {
732
732
  decorations.push({ type: "LINK", linkData: { link: { url: object(entity.data).url } } });
733
733
  }
734
734
  }
735
- runs.push({ type: "TEXT", textData: { text: text3.slice(start, end), decorations } });
735
+ runs.push({ type: "TEXT", textData: { text: text2.slice(start, end), decorations } });
736
736
  }
737
737
  const paragraph = { type: "PARAGRAPH", nodes: runs };
738
738
  if (block2.type === "unordered-list-item" || block2.type === "ordered-list-item") {
@@ -1810,9 +1810,9 @@ function createPurchaseCoordinator(deps) {
1810
1810
  if (session.kind !== "member") return requireSignIn();
1811
1811
  if (listing === "listed") clearReconcileProblem();
1812
1812
  const now = deps.clock.now();
1813
- const eligible3 = itemsWhere((item) => isAwaitingDelivery(item) && (item.state.nextAttemptAt === null || item.state.nextAttemptAt <= now));
1814
- eligible3.forEach(restartAttemptBudget);
1815
- await settleDelivery(session, await deliver(session, eligible3));
1813
+ const eligible = itemsWhere((item) => isAwaitingDelivery(item) && (item.state.nextAttemptAt === null || item.state.nextAttemptAt <= now));
1814
+ eligible.forEach(restartAttemptBudget);
1815
+ await settleDelivery(session, await deliver(session, eligible));
1816
1816
  }
1817
1817
  async function settleDelivery(session, delivered) {
1818
1818
  applyDelivered(delivered);
@@ -2362,33 +2362,25 @@ var sameReference = (value, reference) => isObject2(value) && value.kind === ref
2362
2362
 
2363
2363
  // ../../core/sdk/iap/src/wix-payments-contract.ts
2364
2364
  var HIMALAYA_SERVE_IAP_ROUTE = { prefix: "/himalaya-serve/v1/iap" };
2365
- var BOOKINGS_APPLE_SALES_ENABLED = true;
2366
- var EVENTS_APPLE_SALES_ENABLED = true;
2367
2365
  var ATTENDANCE_SALE_RULE = { appProductId: (id2) => id2, productType: "CONSUMABLE" };
2368
- var STORES_APPLE_SALES_ENABLED = true;
2369
2366
  var STORES_PRODUCT_SALE_RULE = { appProductId: (id2) => id2, productType: "NON_CONSUMABLE" };
2370
2367
  var ONLINE_PROGRAM_SALE_RULE = { appProductId: (id2) => id2, productType: "NON_CONSUMABLE" };
2371
- var PRICING_PLAN_APPLE_SALES_ENABLED = true;
2372
2368
  var PRICING_PLAN_SALE_RULE = { appProductId: (id2) => id2, productType: "NON_CONSUMABLE" };
2373
2369
  var VIDEOS_APPLE_SALES_ENABLED = false;
2374
- var PRICING_PLAN_ITEM_PAYMENT_ENABLED = false;
2375
- var CANCEL_PAYMENT_ENABLED = false;
2376
2370
  var VIDEO_SALE_RULE = { appProductId: (id2) => id2, productType: "NON_CONSUMABLE" };
2377
2371
  function appleSaleRules(options = {}) {
2378
2372
  return {
2379
2373
  onlineProgram: ONLINE_PROGRAM_SALE_RULE,
2380
- ...options.storesAppleSalesEnabled ?? STORES_APPLE_SALES_ENABLED ? { storesProduct: STORES_PRODUCT_SALE_RULE } : {},
2381
- ...options.pricingPlanAppleSalesEnabled ?? PRICING_PLAN_APPLE_SALES_ENABLED ? { pricingPlan: PRICING_PLAN_SALE_RULE } : {},
2382
- ...options.bookingsAppleSalesEnabled ?? BOOKINGS_APPLE_SALES_ENABLED ? { bookingsService: ATTENDANCE_SALE_RULE } : {},
2383
- ...options.eventsAppleSalesEnabled ?? EVENTS_APPLE_SALES_ENABLED ? { eventsTicket: ATTENDANCE_SALE_RULE } : {},
2374
+ storesProduct: STORES_PRODUCT_SALE_RULE,
2375
+ pricingPlan: PRICING_PLAN_SALE_RULE,
2376
+ bookingsService: ATTENDANCE_SALE_RULE,
2377
+ eventsTicket: ATTENDANCE_SALE_RULE,
2384
2378
  ...options.videosAppleSalesEnabled ?? VIDEOS_APPLE_SALES_ENABLED ? { wixVideo: VIDEO_SALE_RULE } : {}
2385
2379
  };
2386
2380
  }
2387
2381
  var APPLE_SALE_RULES = appleSaleRules();
2388
2382
  var APPLE_PROVISIONING_RULES = {
2389
2383
  ...APPLE_SALE_RULES,
2390
- bookingsService: ATTENDANCE_SALE_RULE,
2391
- eventsTicket: ATTENDANCE_SALE_RULE,
2392
2384
  wixVideo: VIDEO_SALE_RULE
2393
2385
  };
2394
2386
  var APPLE_PRICING_RULES = { ...APPLE_SALE_RULES, wixVideo: VIDEO_SALE_RULE };
@@ -3136,131 +3128,6 @@ var COMPLETE_PAYMENT_CODES = [
3136
3128
  ];
3137
3129
  var GET_PAYMENT_CODES = ["NOT_FOUND"];
3138
3130
 
3139
- // ../../core/sdk/iap/src/attendance-classifier.ts
3140
- function classifyForApple(item, currency) {
3141
- if (item.hidden !== false || item.attendance === "hybrid") return "decide";
3142
- if (item.kind === "bookingsService") return bookingRoute(item, currency);
3143
- return ticketRoute(item, currency);
3144
- }
3145
- var ADDRESSLESS_CUSTOM = "CUSTOM_WITHOUT_ADDRESS";
3146
- var PHYSICAL_LOCATIONS = ["BUSINESS", "CUSTOMER", "CUSTOM", ADDRESSLESS_CUSTOM];
3147
- function bookingRoute(item, currency) {
3148
- if (item.onlineBooking !== true) return "decide";
3149
- if (item.conferencing === false && item.locations?.length && item.locations.every((type) => PHYSICAL_LOCATIONS.includes(type))) {
3150
- return item.attendance === "online" ? "decide" : "wixPayments";
3151
- }
3152
- if (item.conferencing !== true || item.attendance === "physical") return "decide";
3153
- const addressed = item.locations?.filter((type) => type !== ADDRESSLESS_CUSTOM);
3154
- if (item.attendance !== "online" && (!addressed || addressed.length > 0)) return "decide";
3155
- if (item.type === "APPOINTMENT") {
3156
- return item.capacity === 1 && item.maxParticipantsPerBooking === 1 ? "wixPayments" : "decide";
3157
- }
3158
- if (item.type !== "CLASS" && item.type !== "COURSE" || !item.capacity || item.capacity <= 1) return "decide";
3159
- if (item.priceType === "NO_FEE" || zeroPrice(item.amount)) return "wixPayments";
3160
- if (item.onlinePayment !== true || item.deposit !== false || item.priceType !== "FIXED") return "decide";
3161
- return fixedPriceRoute(item, currency);
3162
- }
3163
- function ticketRoute(item, currency) {
3164
- if (item.location === "VENUE") return item.attendance === "online" ? "decide" : "wixPayments";
3165
- if (item.location !== "ONLINE" || item.attendance === "physical" || item.registration !== "TICKETING") return "decide";
3166
- if (item.eventStatus !== "UPCOMING" && item.eventStatus !== "STARTED") return "decide";
3167
- if (item.saleStatus !== "SALE_STARTED") return "decide";
3168
- if (zeroPrice(item.amount)) return "wixPayments";
3169
- return item.priceType === "STANDARD" ? fixedPriceRoute(item, currency) : "decide";
3170
- }
3171
- function fixedPriceRoute(item, currency) {
3172
- const amount = item.amount;
3173
- return typeof amount === "string" && /^\d+(?:\.\d+)?$/.test(amount) && Number.isFinite(Number(amount)) && Number(amount) > 0 && /^[A-Z]{3}$/.test(currency) && item.currency === currency ? "appleIap" : "decide";
3174
- }
3175
- function bookingAttendanceOf(raw) {
3176
- const s2 = object3(raw);
3177
- const payment = object3(s2.payment);
3178
- const fixed = object3(payment.fixed);
3179
- const price = object3(fixed.price);
3180
- const options = object3(payment.options);
3181
- const policy = object3(object3(s2.bookingPolicy).participantsPolicy);
3182
- return {
3183
- kind: "bookingsService",
3184
- type: text(s2.type),
3185
- capacity: numeric(s2.defaultCapacity),
3186
- maxParticipantsPerBooking: policy.enabled === true ? numeric(policy.maxParticipantsPerBooking) : void 0,
3187
- hidden: boolean(s2.hidden),
3188
- conferencing: boolean(object3(s2.conferencing).enabled),
3189
- locations: Array.isArray(s2.locations) ? s2.locations.map(locationType) : void 0,
3190
- onlineBooking: boolean(object3(s2.onlineBooking).enabled),
3191
- onlinePayment: boolean(options.online),
3192
- deposit: options.deposit === true || fixed.deposit !== void 0,
3193
- priceType: text(payment.rateType),
3194
- amount: text(price.value),
3195
- currency: text(price.currency)
3196
- };
3197
- }
3198
- function locationType(raw) {
3199
- const location = object3(raw);
3200
- const type = text(location.type) ?? "UNKNOWN";
3201
- const addresses = [object3(location.custom).address, location.calculatedAddress].map(object3);
3202
- return type === "CUSTOM" && addresses.every(describesNoPlace) ? ADDRESSLESS_CUSTOM : type;
3203
- }
3204
- function describesNoPlace(address) {
3205
- const parts = ["country", "subdivision", "city", "postalCode", "addressLine2", "streetAddress", "location"];
3206
- if (parts.some((key) => address[key] !== void 0 && address[key] !== "")) return false;
3207
- return [address.addressLine, address.formattedAddress].every((value) => {
3208
- if (value !== void 0 && typeof value !== "string") return false;
3209
- const description = value?.trim() ?? "";
3210
- return description === "" || ONLINE_LABEL.test(description);
3211
- });
3212
- }
3213
- var ONLINE_LABEL = /^(online|virtual)(\s+(class|classes|classroom|course|session|sessions|meeting|lesson|training|workshop|event))?$/i;
3214
- function ticketAttendanceOf(event, definition) {
3215
- const e = object3(event);
3216
- const t = object3(definition);
3217
- const pricing = object3(t.pricingMethod);
3218
- const price = object3(pricing.fixedPrice);
3219
- const registration = object3(e.registration);
3220
- const type = text(registration.type) ?? text(registration.initialType) ?? text(e.eventType);
3221
- const status = text(e.status) ?? text(e.eventStatus);
3222
- return {
3223
- kind: "eventsTicket",
3224
- location: text(object3(e.location).type),
3225
- registration: type === "TICKETS" || type === "RSVP_AND_TICKETS" ? "TICKETING" : type,
3226
- eventStatus: status === "SCHEDULED" ? "UPCOMING" : status,
3227
- saleStatus: text(t.saleStatus),
3228
- hidden: boolean(t.hidden),
3229
- priceType: text(pricing.pricingType),
3230
- amount: text(price.value),
3231
- currency: text(price.currency)
3232
- };
3233
- }
3234
- function availableTicketAttendanceOf(event, ticket) {
3235
- const e = object3(event);
3236
- const t = object3(ticket);
3237
- const v3 = t.pricingMethod !== void 0;
3238
- const pricing = object3(v3 ? t.pricingMethod : t.pricing);
3239
- const fixed = object3(pricing.fixedPrice);
3240
- const amount = v3 ? fixed.value : fixed.amount;
3241
- const price = object3(t.price);
3242
- const listed = v3 ? t.hidden === false && t.state === void 0 : Array.isArray(t.state) && t.state.length === 0;
3243
- const visible = listed && object3(t.dashboard).hidden !== true && typeof t.id === "string" && t.id.length > 0 && typeof e.id === "string" && e.id.length > 0 && t.eventId === e.id;
3244
- const fixedPrice = t.free === false && (!v3 || pricing.free === false) && pricing.pricingType === "STANDARD" && sameTicketAmount(amount, price.amount) && fixed.currency === price.currency;
3245
- return ticketAttendanceOf(e, {
3246
- hidden: visible ? false : void 0,
3247
- saleStatus: t.saleStatus,
3248
- pricingMethod: { pricingType: fixedPrice ? "STANDARD" : void 0, fixedPrice: { value: amount, currency: fixed.currency } }
3249
- });
3250
- }
3251
- function sameTicketAmount(left, right) {
3252
- const valid = (value) => typeof value === "string" && /^\d+(?:\.\d+)?$/.test(value);
3253
- const normalized = (value) => value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
3254
- return valid(left) && valid(right) && normalized(left) === normalized(right);
3255
- }
3256
- function object3(value) {
3257
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : {};
3258
- }
3259
- var text = (value) => typeof value === "string" ? value : void 0;
3260
- var numeric = (value) => typeof value === "number" ? value : void 0;
3261
- var boolean = (value) => typeof value === "boolean" ? value : void 0;
3262
- var zeroPrice = (value) => typeof value === "string" && /^0+(?:\.0+)?$/.test(value);
3263
-
3264
3131
  // ../../core/sdk/iap/src/index.ts
3265
3132
  async function storefrontCountryCode() {
3266
3133
  try {
@@ -3376,6 +3243,9 @@ var HIMALAYA_SERVE_CHECKOUT_ROUTES = {
3376
3243
  function appleIapCheckoutRoutes() {
3377
3244
  return HIMALAYA_SERVE_CHECKOUT_ROUTES;
3378
3245
  }
3246
+ function videosAppleSalesEnabled() {
3247
+ return VIDEOS_APPLE_SALES_ENABLED;
3248
+ }
3379
3249
 
3380
3250
  // ../../stdlib/flows/iap-checkout/src/cashier-charges.ts
3381
3251
  async function ensureAppleIapCharge(bridge, route, orderId) {
@@ -3632,11 +3502,11 @@ function partitionKey(key) {
3632
3502
  return `${PREFIX}.${key.purchasesAppId}.${key.siteId}.${memberKey(key.memberId)}`;
3633
3503
  }
3634
3504
  function memberKey(memberId) {
3635
- const text3 = memberId.toLowerCase();
3505
+ const text2 = memberId.toLowerCase();
3636
3506
  let h1 = 3735928559;
3637
3507
  let h2 = 1103547991;
3638
- for (let i = 0; i < text3.length; i++) {
3639
- const code = text3.charCodeAt(i);
3508
+ for (let i = 0; i < text2.length; i++) {
3509
+ const code = text2.charCodeAt(i);
3640
3510
  h1 = Math.imul(h1 ^ code, 2654435761);
3641
3511
  h2 = Math.imul(h2 ^ code, 1597334677);
3642
3512
  }
@@ -3719,10 +3589,10 @@ function isLiveHost(bridge) {
3719
3589
  }
3720
3590
  function refusalOf(error) {
3721
3591
  const message = error?.message;
3722
- const text3 = typeof message === "string" ? message : "";
3723
- if (BRIDGE_REFUSAL2.test(text3)) return { status: "notEnabled" };
3724
- if (PRINCIPAL_CHANGED2.test(text3)) return SESSION_CHANGED;
3725
- const http = /^HTTP (\d{3})(?: \[([^\]]+)\])?:/.exec(text3);
3592
+ const text2 = typeof message === "string" ? message : "";
3593
+ if (BRIDGE_REFUSAL2.test(text2)) return { status: "notEnabled" };
3594
+ if (PRINCIPAL_CHANGED2.test(text2)) return SESSION_CHANGED;
3595
+ const http = /^HTTP (\d{3})(?: \[([^\]]+)\])?:/.exec(text2);
3726
3596
  if (!http) return { status: "unavailable" };
3727
3597
  return httpRefusal(Number(http[1]), http[2] ?? "");
3728
3598
  }
@@ -3927,7 +3797,7 @@ function createWixOrderBackend(deps) {
3927
3797
  case "approved":
3928
3798
  return alreadyPaid(sale, ref);
3929
3799
  case "closed":
3930
- return options.reordered ? stopWith("rejected", "orderClosed") : reorder(sale);
3800
+ return options.reordered ? stopWith("rejected", "orderClosed") : reorder(sale, ref.cashierOrderId);
3931
3801
  case "inOtherPayment":
3932
3802
  return stopWith("rejected", "orderRefused");
3933
3803
  case "refused":
@@ -3941,10 +3811,11 @@ function createWixOrderBackend(deps) {
3941
3811
  return retry("unavailable");
3942
3812
  }
3943
3813
  }
3944
- async function reorder(sale) {
3814
+ async function reorder(sale, closedOrderId) {
3945
3815
  if (sale.adapter.repeatable) return stopWith("rejected", "orderClosed");
3946
3816
  if (!forget(sale, sale.catalogRef)) return stopWith("rejected", "storageUnavailable");
3947
3817
  const attempt4 = await sale.adapter.openOrder(sale.item, sale.bridge);
3818
+ if (attempt4.status === "open" && attempt4.cashierOrderId === closedOrderId) return stopWith("rejected", "needsSupport");
3948
3819
  const recorded = recordOrder(sale, void 0, attempt4);
3949
3820
  return isStop(recorded) ? recorded : chargeFor(sale, recorded, { reordered: true, placed: isPlaced(attempt4) });
3950
3821
  }
@@ -4162,7 +4033,7 @@ function createWixOrderBackend(deps) {
4162
4033
  if (ref?.stage !== "started" || !ref.paymentId) return;
4163
4034
  const adapter = adapterFor(ref.kind);
4164
4035
  if (!adapter || !paidByItem(adapter)) return;
4165
- if (!(deps.cancelPaymentEnabled ?? CANCEL_PAYMENT_ENABLED) || adapter.reusesPayment) {
4036
+ if (adapter.reusesPayment) {
4166
4037
  const current = refAt(partition, catalogRef);
4167
4038
  if (current?.stage === "started" && current.paymentId === ref.paymentId && current.updatedAt === ref.updatedAt) handBackToGuard(partition, adapter, ref);
4168
4039
  return;
@@ -4480,7 +4351,7 @@ function enabledCheckout(deps) {
4480
4351
  if (!isCurrent(session)) return;
4481
4352
  if (ref.stage === "needsSupport") setPayment(ref.key, "needsSupport");
4482
4353
  if (ref.stage === "fulfilled" && !options.dueOnly) {
4483
- const access = await accessOf2(session, ref);
4354
+ const access = await accessOf(session, ref);
4484
4355
  if (!isCurrent(session)) return;
4485
4356
  if (access === "granted") setPayment(ref.key, "granted");
4486
4357
  else if (access === "none") payments.delete(ref.key);
@@ -4540,7 +4411,7 @@ function enabledCheckout(deps) {
4540
4411
  if (isFinalRefusal(payment.status)) return markNeedsSupport(partition, ref);
4541
4412
  if (payment.status !== "approved") return backOff(partition, ref, false);
4542
4413
  if (!ref.kind) return settleUnassociated(partition, ref);
4543
- const access = await accessOf2(session, ref);
4414
+ const access = await accessOf(session, ref);
4544
4415
  if (!isCurrent(session)) return;
4545
4416
  if (access === "granted") return grant(partition, ref);
4546
4417
  backOff(partition, ref, access === "none");
@@ -4556,7 +4427,7 @@ function enabledCheckout(deps) {
4556
4427
  partition.remove(ref.key);
4557
4428
  setPayment(ref.key, "accessUnknown");
4558
4429
  }
4559
- async function accessOf2(session, ref) {
4430
+ async function accessOf(session, ref) {
4560
4431
  const adapter = deps.adapters.find((candidate) => candidate.kind === ref.kind);
4561
4432
  if (!adapter || !ref.verticalRef) return "unavailable";
4562
4433
  return adapter.readAccess(ref.verticalRef, bindBridge(session, deps.session, bridge));
@@ -5056,17 +4927,6 @@ var UNSUPPORTED = { eligible: false, reason: "unsupportedItem" };
5056
4927
  var ORDER_REFUSED = { status: "refused", reason: "orderRefused" };
5057
4928
  var ORDER_CLOSED = { status: "refused", reason: "orderClosed" };
5058
4929
  var GRANTED = { status: "granted" };
5059
- async function ecomOrderAccess(orderId, bridge) {
5060
- if (!isNonEmpty3(orderId)) return "unavailable";
5061
- const answer = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(orderId)}`);
5062
- if (isRefusal(answer)) return accessRefused(answer);
5063
- const status = String(bodyObject(answer, "order")?.paymentStatus);
5064
- if (status === "PAID") return "granted";
5065
- if (ECOM_PAYMENT_UNDER_WAY.has(status)) return "pending";
5066
- return ECOM_NO_ACCESS.has(status) ? "none" : "unavailable";
5067
- }
5068
- var ECOM_PAYMENT_UNDER_WAY = /* @__PURE__ */ new Set(["NOT_PAID", "PENDING", "PENDING_MERCHANT", "PARTIALLY_PAID"]);
5069
- var ECOM_NO_ACCESS = /* @__PURE__ */ new Set(["FULLY_REFUNDED", "PARTIALLY_REFUNDED", "CANCELED", "DECLINED", "VOIDED"]);
5070
4930
 
5071
4931
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans.ts
5072
4932
  var KIND = "pricingPlan";
@@ -5109,445 +4969,91 @@ async function planAccess(planId, bridge) {
5109
4969
  }
5110
4970
  }
5111
4971
 
5112
- // ../../stdlib/flows/iap-checkout/src/iap-verticals/pricing-plans-orders.ts
5113
- var KIND2 = "pricingPlan";
5114
- var CHECKOUT = "/pricing-plans/v2/checkout/orders";
5115
- var MEMBER_ORDERS2 = "/pricing-plans/v2/member/orders";
5116
- var pricingPlanClientOrders = {
5117
- kind: KIND2,
5118
- eligibility: (item) => singleUnitOf(KIND2, item),
5119
- openOrder,
5120
- reopenOrder,
5121
- readAccess,
5122
- currentAccess
5123
- };
5124
- async function currentAccess(item, bridge) {
5125
- let pending = false;
5126
- const pages = /* @__PURE__ */ new Set();
5127
- for (let offset = 0; ; offset += 50) {
5128
- const answer = await bridge.call("GET", `${MEMBER_ORDERS2}?orderStatuses=ACTIVE&orderStatuses=PENDING&orderStatuses=DRAFT&limit=50&offset=${offset}`);
5129
- if (isRefusal(answer)) return accessRefused(answer);
5130
- const orders = answer.body?.orders;
5131
- if (!Array.isArray(orders)) return "unavailable";
5132
- const page = JSON.stringify(orders.map((order) => [order.id, order.planId, order.status]));
5133
- if (orders.length === 50 && pages.has(page)) return "unavailable";
5134
- pages.add(page);
5135
- const selected = orders.filter((order) => order.planId === item.reference.id);
5136
- if (selected.some((order) => order.status === "ACTIVE")) return "granted";
5137
- pending || (pending = selected.some((order) => order.status === "PENDING" || order.status === "DRAFT"));
5138
- if (orders.length < 50) return pending ? "pending" : "none";
5139
- }
5140
- }
5141
- async function openOrder(item, bridge) {
5142
- const planId = item.reference.id;
5143
- const preview = await bridge.call("POST", `${CHECKOUT}/preview-online`, { planId });
5144
- if (isRefusal(preview)) return attemptRefused(preview);
5145
- if (!isOneTimeUnlimited(bodyObject(preview, "order"))) return { status: "refused", reason: "unsupportedItem" };
5146
- const created = await bridge.call("POST", `${CHECKOUT}/online`, { planId });
5147
- if (isRefusal(created)) return attemptRefused(created);
5148
- return orderOf(bodyObject(created, "order"), planId);
5149
- }
5150
- async function reopenOrder(order, bridge) {
5151
- const read2 = await memberOrder(order.verticalRef.orderId, bridge);
5152
- if ("attempt" in read2) return read2.attempt;
5153
- const attempt4 = orderOf(read2.order, order.verticalRef.planId ?? "");
5154
- return attempt4.status === "open" && attempt4.cashierOrderId !== order.cashierOrderId ? ORDER_CLOSED : attempt4;
5155
- }
5156
- async function readAccess(verticalRef, bridge) {
5157
- if (!isNonEmpty3(verticalRef.orderId)) return isNonEmpty3(verticalRef.planId) ? planAccess(verticalRef.planId, bridge) : "unavailable";
5158
- const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(verticalRef.orderId)}`);
5159
- if (isRefusal(answer)) return accessRefused(answer);
5160
- const order = bodyObject(answer, "order");
5161
- return order ? accessOf(order) : "unavailable";
5162
- }
5163
- function accessOf(order) {
5164
- if (order.status === "ACTIVE") return "granted";
5165
- if (order.status === "PENDING") return "pending";
5166
- if (order.status === "DRAFT") return "pending";
5167
- return NO_ACCESS.has(String(order.status)) ? "none" : "unavailable";
5168
- }
5169
- var NO_ACCESS = /* @__PURE__ */ new Set(["CANCELED", "ENDED", "PAUSED"]);
5170
- function orderOf(order, planId) {
5171
- if (!order || !isNonEmpty3(order.id)) return ORDER_REFUSED;
5172
- if (accessOf(order) === "granted") return GRANTED;
5173
- if (order.status === "PENDING") return { status: "refused", reason: "paymentInProgress" };
5174
- if (order.status !== "DRAFT") return ORDER_CLOSED;
5175
- if (!isNonEmpty3(order.wixPayOrderId)) return ORDER_REFUSED;
5176
- return { status: "open", cashierOrderId: order.wixPayOrderId, verticalRef: { orderId: order.id, planId } };
5177
- }
5178
- async function memberOrder(orderId, bridge) {
5179
- if (!isNonEmpty3(orderId)) return { attempt: ORDER_CLOSED };
5180
- const answer = await bridge.call("GET", `${MEMBER_ORDERS2}/${encodeURIComponent(orderId)}`);
5181
- if (isRefusal(answer)) return { attempt: answer.status === "http" && answer.httpStatus === 404 ? ORDER_CLOSED : attemptRefused(answer) };
5182
- return { order: bodyObject(answer, "order") };
5183
- }
5184
- function isOneTimeUnlimited(order) {
5185
- const pricing = order?.pricing;
5186
- return pricing?.singlePaymentUnlimited === true;
5187
- }
5188
-
5189
- // ../../stdlib/flows/iap-checkout/src/iap-verticals/attendance.ts
5190
- var BOOKING = "bookingsService";
5191
- var TICKET = "eventsTicket";
4972
+ // ../../stdlib/flows/iap-checkout/src/iap-verticals/videos.ts
4973
+ var KIND2 = "wixVideo";
5192
4974
  var NOT_ENABLED = { status: "refused", reason: "notEnabled" };
5193
- var WIX_BOOKINGS_APP = "13d21c63-b5ec-5912-8397-c3a5ddb27a97";
5194
- var CHANGED = { status: "refused", reason: "productChanged" };
5195
- var WIX_EVENTS_APP = "140603ad-af8d-84a5-2c80-a0f60cb47351";
5196
- var RELEASE_MARGIN_MS = 3e5;
5197
- var PAYMENT_TAKEN = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
5198
- var HAS_OFFSET = /(?:Z|[+-]\d{2}:?\d{2})$/i;
5199
- var LATEST_ZONE_MS = 432e5;
5200
- function attendanceOrdersWith(options) {
5201
- return {
5202
- bookingOrders: {
5203
- kind: BOOKING,
5204
- repeatable: true,
5205
- eligibility: (item) => eligible(item, BOOKING, options.bookingsEnabled),
5206
- itemPayment: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? bookingPayment(item, bridge, beforeCreate, afterCreate) : NOT_ENABLED,
5207
- resolveOpening: resolveBookingOpening,
5208
- readAccess: bookingAccess
5209
- },
5210
- eventTicketOrders: {
5211
- kind: TICKET,
5212
- repeatable: true,
5213
- eligibility: (item) => eligible(item, TICKET, options.eventsEnabled),
5214
- itemPayment: ticketPayment,
5215
- readAccess: ticketAccess
5216
- }
5217
- };
5218
- }
5219
- var { bookingOrders: bookingItemPayments, eventTicketOrders: eventTicketItemPayments } = /* @__PURE__ */ attendanceOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
5220
- function eligible(item, kind, enabled) {
5221
- if (!enabled) return { eligible: false, reason: "notEnabled" };
5222
- if (!singleUnitOf(kind, item).eligible || !isNonEmpty3(item.attemptId) || !item.attendance) return UNSUPPORTED;
5223
- if (kind === TICKET) return isNonEmpty3(item.attendance.ticket?.eventId) ? { eligible: true } : UNSUPPORTED;
5224
- return item.attendance.booking ? { eligible: true } : UNSUPPORTED;
5225
- }
5226
- async function bookingPayment(item, bridge, beforeCreate, afterCreate) {
5227
- if (!eligible(item, BOOKING, true).eligible) return notCreated(ORDER_REFUSED);
5228
- const selected = item.attendance.booking;
5229
- if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated(ORDER_REFUSED);
5230
- const read2 = await bridge.call("GET", `/bookings/v2/services/${encodeURIComponent(item.reference.id)}`);
5231
- if (isRefusal(read2)) return notCreated(attemptRefused(read2));
5232
- const service = bodyObject(read2, "service");
5233
- const metadata = bookingAttendanceOf(service);
5234
- if (classifyForApple(metadata, item.attendance.currency) !== "appleIap" || !samePrice({ amount: metadata.amount, currency: metadata.currency }, item)) return notCreated(CHANGED);
5235
- if (isObject7(service?.onlineBooking) && service.onlineBooking.requireManualApproval === true) return notCreated({ status: "refused", reason: "approvalRequired" });
5236
- const availability2 = await bridge.call("POST", "/bookings/v1/availability/query", { query: { filter: { serviceId: [item.reference.id], startDate: selected.slot.startDate, endDate: selected.slot.endDate, bookable: true } } });
5237
- if (isRefusal(availability2)) return notCreated(attemptRefused(availability2));
5238
- const entries = isObject7(availability2.body) ? availability2.body.availabilityEntries : void 0;
5239
- if (!Array.isArray(entries) || !entries.some((entry) => isObject7(entry) && entry.bookable === true && matchesSlot(entry.slot, selected.slot))) return notCreated(CHANGED);
5240
- if (beforeCreate && !beforeCreate(slotGuard(selected.slot))) return notCreated({ status: "refused", reason: "storageUnavailable" });
5241
- 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 } : {} } });
5242
- if (isRefusal(created)) return creationRefused(created);
5243
- const bookingId = bodyObject(created, "booking")?.id;
5244
- if (!isNonEmpty3(bookingId)) return ORDER_REFUSED;
5245
- if (afterCreate?.({ verticalRef: { bookingId } }) === false) return { status: "unavailable" };
5246
- const serviceId = item.reference.id;
5247
- return {
5248
- catalogItem: { catalogItemId: serviceId, catalogAppId: WIX_BOOKINGS_APP, options: { bookingId } },
5249
- verticalRefOf: ({ ecomOrderId }) => ecomOrderId ? { serviceId, bookingId, orderId: ecomOrderId } : null
5250
- };
5251
- }
5252
- function slotGuard(slot) {
5253
- const verticalRef = {};
5254
- for (const key of ["sessionId", "startDate"]) if (isNonEmpty3(slot[key])) verticalRef[key] = slot[key];
5255
- const ends = latestInstant(String(slot.endDate));
5256
- return Number.isFinite(ends) ? { verticalRef, releaseAt: ends + RELEASE_MARGIN_MS } : { verticalRef };
5257
- }
5258
- function latestInstant(value) {
5259
- if (HAS_OFFSET.test(value)) return Date.parse(value);
5260
- return Date.parse(`${value}Z`) + LATEST_ZONE_MS;
5261
- }
5262
- async function resolveBookingOpening(guard, item, bridge, options) {
5263
- const scope = sameSlot(guard.verticalRef, item?.attendance?.booking?.slot) ? "held" : "unrelated";
5264
- const bookingId = guard.verticalRef?.bookingId;
5265
- if (!bookingId || !options.settled) return scope;
5266
- const released2 = await releaseBooking(bookingId, bridge, options.claim);
5267
- return released2 === "held" || released2 === "unavailable" && scope === "unrelated" ? scope : released2;
5268
- }
5269
- async function releaseBooking(bookingId, bridge, claim) {
5270
- const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: bookingId } } } });
5271
- if (isRefusal(read2)) return read2.status === "http" && read2.httpStatus === 404 ? "released" : openingRefused(read2);
5272
- const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
5273
- const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === bookingId) : void 0;
5274
- if (!isObject7(booking)) return "held";
5275
- if (["CANCELED", "CANCELLED", "DECLINED"].includes(String(booking.status)) || PAYMENT_TAKEN.includes(String(booking.paymentStatus))) return "released";
5276
- if (booking.status !== "CREATED" || !claim()) return "held";
5277
- const cancelled = await bridge.call("POST", `/bookings/v2/bookings/${encodeURIComponent(bookingId)}/cancel`, { participantNotification: { notifyParticipants: false }, revision: booking.revision });
5278
- return isRefusal(cancelled) ? openingRefused(cancelled) : "released";
5279
- }
5280
- function openingRefused(refusal) {
5281
- if (refusal.status === "sessionChanged") return "sessionChanged";
5282
- return refusal.status === "unavailable" ? "unavailable" : "held";
5283
- }
5284
- function sameSlot(guarded, slot) {
5285
- if (!guarded || !slot) return true;
5286
- return guarded.sessionId === slot.sessionId && Date.parse(guarded.startDate ?? "") === Date.parse(String(slot.startDate));
5287
- }
5288
- async function bookingAccess(ref, bridge) {
5289
- if (!ref.bookingId || !ref.orderId) return "unavailable";
5290
- const order = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(ref.orderId)}`);
5291
- if (isRefusal(order)) return accessRefused(order);
5292
- const payment = bodyObject(order, "order")?.paymentStatus;
5293
- if (payment === "FULLY_REFUNDED" || payment === "PARTIALLY_REFUNDED") return "none";
5294
- const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: ref.bookingId } } } });
5295
- if (isRefusal(read2)) return accessRefused(read2);
5296
- const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
5297
- const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === ref.bookingId) : void 0;
5298
- if (!isObject7(booking)) return "unavailable";
5299
- if (booking.status === "CANCELED" || booking.status === "CANCELLED" || booking.status === "DECLINED") return "none";
5300
- return payment === "PAID" && booking.status === "CONFIRMED" && booking.paymentStatus === "PAID" ? "granted" : "pending";
5301
- }
5302
- async function ticketAccess(ref, bridge) {
5303
- if (isNonEmpty3(ref.orderId)) return ecomOrderAccess(ref.orderId, bridge);
5304
- if (!ref.eventId || !ref.orderNumber || !ref.ticketDefinitionId) return "unavailable";
5305
- const read2 = await bridge.call("GET", `/events/v1/events/${encodeURIComponent(ref.eventId)}/orders/${encodeURIComponent(ref.orderNumber)}?fieldset=DETAILS&fieldset=TICKETS`);
5306
- if (isRefusal(read2)) return accessRefused(read2);
5307
- const order = bodyObject(read2, "order");
5308
- if (order?.status === "CANCELED" || order?.status === "CANCELLED" || order?.status === "REFUNDED") return "none";
5309
- const issued = Array.isArray(order?.tickets) && order.tickets.some((t) => isObject7(t) && isNonEmpty3(t.ticketNumber) && t.orderStatus === "PAID" && t.ticketDefinitionId === ref.ticketDefinitionId);
5310
- return order?.status === "PAID" && issued ? "granted" : order ? "pending" : "unavailable";
5311
- }
5312
- function ticketPayment(item) {
5313
- const eventId = item.attendance.ticket.eventId;
5314
- const ticketDefinitionId = item.reference.id;
5315
- return {
5316
- catalogItem: { catalogItemId: ticketDefinitionId, catalogAppId: WIX_EVENTS_APP, options: { eventId } },
5317
- // eCom checkout: the eCom order. Classic checkout (catalyst-server #24882): the Events order number.
5318
- verticalRefOf: ({ ecomOrderId, eventsOrderNumber }) => {
5319
- if (ecomOrderId) return { orderId: ecomOrderId, eventId, ticketDefinitionId };
5320
- return eventsOrderNumber ? { orderNumber: eventsOrderNumber, eventId, ticketDefinitionId } : null;
5321
- }
5322
- };
5323
- }
5324
- function samePrice(value, item) {
5325
- return isObject7(value) && value.currency === item.attendance?.currency && decimal(value.amount) !== null && decimal(value.amount) === decimal(item.attendance?.amount);
5326
- }
5327
- function decimal(value) {
5328
- if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return null;
5329
- return value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
5330
- }
5331
- function matchesSlot(value, selected) {
5332
- 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])));
5333
- }
5334
- function creationRefused(refusal) {
5335
- const attempt4 = attemptRefused(refusal);
5336
- return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated(attempt4) : attempt4;
5337
- }
5338
- function notCreated(attempt4) {
5339
- return { ...attempt4, noOrderCreated: true };
5340
- }
5341
-
5342
- // ../../stdlib/flows/iap-checkout/src/iap-verticals/attendance-orders.ts
5343
- var BOOKING2 = "bookingsService";
5344
- var TICKET2 = "eventsTicket";
5345
- var NOT_ENABLED2 = { status: "refused", reason: "notEnabled" };
5346
- var CHANGED2 = { status: "refused", reason: "productChanged" };
5347
- var MINUTE_MS = 6e4;
5348
- var RELEASE_MARGIN_MS2 = 3e5;
5349
- var DEFAULT_RESERVATION_MINUTES = 60;
5350
- var PAYMENT_TAKEN2 = ["PAID", "PARTIALLY_PAID", "EXEMPT", "REFUNDED"];
5351
- var HAS_OFFSET2 = /(?:Z|[+-]\d{2}:?\d{2})$/i;
5352
- var LATEST_ZONE_MS2 = 432e5;
5353
- function attendanceClientOrdersWith(options) {
5354
- const now = options.now ?? Date.now;
5355
- return {
5356
- bookingOrders: {
5357
- kind: BOOKING2,
5358
- repeatable: true,
5359
- eligibility: (item) => eligible2(item, BOOKING2, options.bookingsEnabled),
5360
- openOrder: (item, bridge, beforeCreate, afterCreate) => options.bookingsEnabled ? openBooking(item, bridge, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
5361
- resolveOpening: resolveBookingOpening2,
5362
- readAccess: bookingAccess2,
5363
- reopenOrder: (order, bridge) => reopen(order, bridge, bookingAccess2)
5364
- },
5365
- eventTicketOrders: {
5366
- kind: TICKET2,
5367
- repeatable: true,
5368
- eligibility: (item) => eligible2(item, TICKET2, options.eventsEnabled),
5369
- openOrder: (item, bridge, beforeCreate, afterCreate) => options.eventsEnabled ? openTicket(item, bridge, now, beforeCreate, afterCreate) : Promise.resolve(NOT_ENABLED2),
5370
- readAccess: ticketAccess2,
5371
- reopenOrder: (order, bridge) => reopen(order, bridge, ticketAccess2, now)
5372
- }
4975
+ var VIDEO_GRAPHQL_URL = "https://manage.wix.com/_api/vod/public/graphql";
4976
+ var graphqlVideoPort = (bridge) => ({
4977
+ async openSaleOrder(videoId) {
4978
+ const answer = await bridge.call("POST", VIDEO_GRAPHQL_URL, { query: CREATE_ORDER, variables: { videoId } });
4979
+ if (isRefusal(answer)) return answer;
4980
+ const created = dataAt(answer.body, ["purchase", "order", "create"]);
4981
+ if (!created) return { status: "unavailable" };
4982
+ const orderId = isObject7(created.entity) ? created.entity.id : void 0;
4983
+ if (created.status === "SUCCESS" && isNonEmpty3(orderId)) return { status: "ok", orderId };
4984
+ const message = typeof created.message === "string" ? created.message : "";
4985
+ return { status: "refused", reason: message === PENDING_MESSAGE ? "pending" : message === ACTIVE_MESSAGE ? "active" : "other" };
4986
+ },
4987
+ async salePurchase(videoId) {
4988
+ const answer = await bridge.call("POST", VIDEO_GRAPHQL_URL, { query: SALE_PURCHASE, variables: { videoId } });
4989
+ if (isRefusal(answer)) return answer;
4990
+ const data = isObject7(answer.body) && isObject7(answer.body.data) ? answer.body.data : null;
4991
+ if (!data || !("purchase" in data)) return { status: "unavailable" };
4992
+ const found = isObject7(data.purchase) ? data.purchase : null;
4993
+ if (!found) return { status: "ok", purchase: null };
4994
+ if (!isNonEmpty3(found.status)) return { status: "unavailable" };
4995
+ return { status: "ok", purchase: { status: found.status, orderId: isNonEmpty3(found.orderId) ? found.orderId : null } };
4996
+ }
4997
+ });
4998
+ function videoOrdersWith(options) {
4999
+ const portOf = options.port ?? graphqlVideoPort;
5000
+ const adapter = {
5001
+ kind: KIND2,
5002
+ eligibility: (item) => options.enabled ? singleUnitOf(KIND2, item) : { eligible: false, reason: "notEnabled" },
5003
+ openOrder: async (item, bridge) => options.enabled ? openOrder(item, portOf(bridge)) : NOT_ENABLED,
5004
+ reopenOrder: async (order, bridge) => options.enabled ? reopenOrder(order.verticalRef, portOf(bridge)) : ORDER_CLOSED,
5005
+ readAccess: async (verticalRef, bridge) => options.enabled ? readAccess(verticalRef, portOf(bridge)) : "unavailable"
5373
5006
  };
5374
- }
5375
- var { bookingOrders: bookingClientOrders, eventTicketOrders: eventTicketClientOrders } = /* @__PURE__ */ attendanceClientOrdersWith({ bookingsEnabled: BOOKINGS_APPLE_SALES_ENABLED, eventsEnabled: EVENTS_APPLE_SALES_ENABLED });
5376
- function eligible2(item, kind, enabled) {
5377
- if (!enabled) return { eligible: false, reason: "notEnabled" };
5378
- if (!singleUnitOf(kind, item).eligible || !isNonEmpty3(item.attemptId) || !item.attendance) return UNSUPPORTED;
5379
- const selection = kind === BOOKING2 ? item.attendance.booking : item.attendance.ticket;
5380
- return selection ? { eligible: true } : UNSUPPORTED;
5381
- }
5382
- async function openBooking(item, bridge, beforeCreate, afterCreate) {
5383
- if (!eligible2(item, BOOKING2, true).eligible) return notCreated2(ORDER_REFUSED);
5384
- const selected = item.attendance.booking;
5385
- if (selected.slot.serviceId !== item.reference.id || !isNonEmpty3(selected.slot.startDate) || !isNonEmpty3(selected.slot.endDate)) return notCreated2(ORDER_REFUSED);
5386
- const read2 = await bridge.call("GET", `/bookings/v2/services/${encodeURIComponent(item.reference.id)}`);
5387
- if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
5388
- const service = bodyObject(read2, "service");
5389
- const metadata = bookingAttendanceOf(service);
5390
- if (classifyForApple(metadata, item.attendance.currency) !== "appleIap" || !samePrice2({ amount: metadata.amount, currency: metadata.currency }, item)) return notCreated2(CHANGED2);
5391
- if (isObject7(service?.onlineBooking) && service.onlineBooking.requireManualApproval === true) return notCreated2({ status: "refused", reason: "approvalRequired" });
5392
- const availability2 = await bridge.call("POST", "/bookings/v1/availability/query", { query: { filter: { serviceId: [item.reference.id], startDate: selected.slot.startDate, endDate: selected.slot.endDate, bookable: true } } });
5393
- if (isRefusal(availability2)) return notCreated2(attemptRefused(availability2));
5394
- const entries = isObject7(availability2.body) ? availability2.body.availabilityEntries : void 0;
5395
- if (!Array.isArray(entries) || !entries.some((entry) => isObject7(entry) && entry.bookable === true && matchesSlot2(entry.slot, selected.slot))) return notCreated2(CHANGED2);
5396
- if (beforeCreate && !beforeCreate(slotGuard2(selected.slot))) return notCreated2({ status: "refused", reason: "storageUnavailable" });
5397
- 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 } : {} } });
5398
- if (isRefusal(created)) return creationRefused2(created);
5399
- const bookingId = bodyObject(created, "booking")?.id;
5400
- if (!isNonEmpty3(bookingId)) return ORDER_REFUSED;
5401
- if (afterCreate?.({ verticalRef: { bookingId } }) === false) return { status: "unavailable" };
5402
- return bookingCheckout(item, bookingId, bridge);
5403
- }
5404
- function slotGuard2(slot) {
5405
- const verticalRef = {};
5406
- for (const key of ["sessionId", "startDate"]) if (isNonEmpty3(slot[key])) verticalRef[key] = slot[key];
5407
- const ends = latestInstant2(String(slot.endDate));
5408
- return Number.isFinite(ends) ? { verticalRef, releaseAt: ends + RELEASE_MARGIN_MS2 } : { verticalRef };
5409
- }
5410
- function latestInstant2(value) {
5411
- if (HAS_OFFSET2.test(value)) return Date.parse(value);
5412
- return Date.parse(`${value}Z`) + LATEST_ZONE_MS2;
5413
- }
5414
- async function resolveBookingOpening2(guard, item, bridge, options) {
5415
- const scope = sameSlot2(guard.verticalRef, item?.attendance?.booking?.slot) ? "held" : "unrelated";
5416
- const bookingId = guard.verticalRef?.bookingId;
5417
- if (!bookingId || !options.settled) return scope;
5418
- const released2 = await releaseBooking2(bookingId, bridge, options.claim);
5419
- return released2 === "held" || released2 === "unavailable" && scope === "unrelated" ? scope : released2;
5420
- }
5421
- async function releaseBooking2(bookingId, bridge, claim) {
5422
- const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: bookingId } } } });
5423
- if (isRefusal(read2)) return read2.status === "http" && read2.httpStatus === 404 ? "released" : openingRefused2(read2);
5424
- const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
5425
- const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === bookingId) : void 0;
5426
- if (!isObject7(booking)) return "held";
5427
- if (["CANCELED", "CANCELLED", "DECLINED"].includes(String(booking.status)) || PAYMENT_TAKEN2.includes(String(booking.paymentStatus))) return "released";
5428
- if (booking.status !== "CREATED" || !claim()) return "held";
5429
- const cancelled = await bridge.call("POST", `/bookings/v2/bookings/${encodeURIComponent(bookingId)}/cancel`, { participantNotification: { notifyParticipants: false }, revision: booking.revision });
5430
- return isRefusal(cancelled) ? openingRefused2(cancelled) : "released";
5431
- }
5432
- function openingRefused2(refusal) {
5433
- if (refusal.status === "sessionChanged") return "sessionChanged";
5434
- return refusal.status === "unavailable" ? "unavailable" : "held";
5435
- }
5436
- function sameSlot2(guarded, slot) {
5437
- if (!guarded || !slot) return true;
5438
- return guarded.sessionId === slot.sessionId && Date.parse(guarded.startDate ?? "") === Date.parse(String(slot.startDate));
5439
- }
5440
- async function bookingCheckout(item, bookingId, bridge) {
5441
- const checkout = await bridge.call("POST", "/ecom/v1/checkouts", { lineItems: [{ quantity: 1, catalogReference: { appId: "13d21c63-b5ec-5912-8397-c3a5ddb27a97", catalogItemId: bookingId } }], channelType: "OTHER_PLATFORM" });
5442
- if (isRefusal(checkout)) return attemptRefused(checkout);
5443
- const entity = bodyObject(checkout, "checkout");
5444
- const total = isObject7(entity?.priceSummary) ? entity.priceSummary.total : void 0;
5445
- if (!isObject7(total) || !samePrice2({ amount: total.amount, currency: entity?.currency }, item)) return CHANGED2;
5446
- if (!isNonEmpty3(entity?.id)) return ORDER_REFUSED;
5447
- const placed = await bridge.call("POST", `/ecom/v1/checkouts/${encodeURIComponent(entity.id)}/create-order`, {});
5448
- if (isRefusal(placed)) return attemptRefused(placed);
5449
- const body = placed.body;
5450
- if (!isObject7(body) || !isNonEmpty3(body.orderId) || !isNonEmpty3(body.paymentGatewayOrderId)) return ORDER_REFUSED;
5451
- return { status: "open", cashierOrderId: body.paymentGatewayOrderId, verticalRef: { serviceId: item.reference.id, bookingId, orderId: body.orderId } };
5452
- }
5453
- async function bookingAccess2(ref, bridge) {
5454
- if (!ref.bookingId || !ref.orderId) return "unavailable";
5455
- const order = await bridge.call("GET", `/ecom/v1/orders/${encodeURIComponent(ref.orderId)}`);
5456
- if (isRefusal(order)) return accessRefused(order);
5457
- const payment = bodyObject(order, "order")?.paymentStatus;
5458
- if (payment === "FULLY_REFUNDED" || payment === "PARTIALLY_REFUNDED") return "none";
5459
- const read2 = await bridge.call("POST", "/bookings/v2/bookings/query", { query: { filter: { id: { $eq: ref.bookingId } } } });
5460
- if (isRefusal(read2)) return accessRefused(read2);
5461
- const rows = isObject7(read2.body) ? read2.body.bookings : void 0;
5462
- const booking = Array.isArray(rows) ? rows.find((b) => isObject7(b) && b.id === ref.bookingId) : void 0;
5463
- if (!isObject7(booking)) return "unavailable";
5464
- if (booking.status === "CANCELED" || booking.status === "CANCELLED" || booking.status === "DECLINED") return "none";
5465
- return payment === "PAID" && booking.status === "CONFIRMED" && booking.paymentStatus === "PAID" ? "granted" : "pending";
5466
- }
5467
- async function openTicket(item, bridge, now, beforeCreate, afterCreate) {
5468
- if (!eligible2(item, TICKET2, true).eligible) return notCreated2(ORDER_REFUSED);
5469
- const selected = item.attendance.ticket;
5470
- if (!isNonEmpty3(selected.eventId)) return notCreated2(ORDER_REFUSED);
5471
- const read2 = await bridge.call("GET", `/events/v3/events/${encodeURIComponent(selected.eventId)}?fields=REGISTRATION&fields=DETAILS&fields=FORM`);
5472
- if (isRefusal(read2)) return notCreated2(attemptRefused(read2));
5473
- const available = await bridge.call("POST", "/events/v1/checkout/available-tickets/query", { filter: { eventId: selected.eventId }, limit: 100, offset: 0 });
5474
- if (isRefusal(available)) return notCreated2(attemptRefused(available));
5475
- const definitions = isObject7(available.body) ? available.body.definitions : void 0;
5476
- const live = Array.isArray(definitions) ? definitions.find((t) => isObject7(t) && t.id === item.reference.id && t.saleStatus === "SALE_STARTED") : void 0;
5477
- if (!isObject7(live) || !samePrice2(live.price, item)) return notCreated2(CHANGED2);
5478
- const event = bodyObject(read2, "event");
5479
- if (live.eventId !== selected.eventId || classifyForApple(availableTicketAttendanceOf(event, live), item.attendance.currency) !== "appleIap") return notCreated2(ORDER_REFUSED);
5480
- if (beforeCreate && !beforeCreate({ releaseAt: now() + reservationMinutes(event) * MINUTE_MS + RELEASE_MARGIN_MS2 })) return notCreated2({ status: "refused", reason: "storageUnavailable" });
5481
- return reserveTicket(item, bridge, now, afterCreate);
5482
- }
5483
- function reservationMinutes(event) {
5484
- const registration = isObject7(event?.registration) ? event.registration : void 0;
5485
- const minutes = isObject7(registration?.tickets) ? registration.tickets.reservationDurationInMinutes : void 0;
5486
- return typeof minutes === "number" && minutes > 0 ? minutes : DEFAULT_RESERVATION_MINUTES;
5487
- }
5488
- async function reserveTicket(item, bridge, now, afterCreate) {
5489
- const selected = item.attendance.ticket;
5490
- const held = await bridge.call("POST", "/events/v1/checkout/reservations", { eventId: selected.eventId, ticketQuantities: [{ ticketDefinitionId: item.reference.id, quantity: 1 }], ignoreLimits: false, allowHiddenTickets: false });
5491
- if (isRefusal(held)) return creationRefused2(held);
5492
- const reservation = held.body;
5493
- if (!isObject7(reservation) || !isNonEmpty3(reservation.id) || !future(reservation.expires, now)) return ORDER_CLOSED;
5494
- if (afterCreate?.({ verticalRef: { reservationId: reservation.id }, releaseAt: Date.parse(reservation.expires) + RELEASE_MARGIN_MS2 }) === false) return { status: "unavailable" };
5495
- if (!heldAsSelected(reservation, item)) return CHANGED2;
5496
- 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 } });
5497
- if (isRefusal(placed)) return attemptRefused(placed);
5498
- const order = bodyObject(placed, "order");
5499
- if (!samePrice2(order?.totalPrice, item)) return CHANGED2;
5500
- const expires = isObject7(placed.body) && placed.body.expires || reservation.expires;
5501
- if (!future(expires, now) || !isNonEmpty3(order?.snapshotId) || !isNonEmpty3(order?.orderNumber)) return ORDER_CLOSED;
5502
- return { status: "open", cashierOrderId: order.snapshotId, verticalRef: { eventId: selected.eventId, ticketDefinitionId: item.reference.id, reservationId: reservation.id, orderNumber: order.orderNumber, expires: String(expires) } };
5503
- }
5504
- async function ticketAccess2(ref, bridge) {
5505
- if (isNonEmpty3(ref.orderId)) return ecomOrderAccess(ref.orderId, bridge);
5506
- if (!ref.eventId || !ref.orderNumber || !ref.ticketDefinitionId) return "unavailable";
5507
- const read2 = await bridge.call("GET", `/events/v1/events/${encodeURIComponent(ref.eventId)}/orders/${encodeURIComponent(ref.orderNumber)}?fieldset=DETAILS&fieldset=TICKETS`);
5508
- if (isRefusal(read2)) return accessRefused(read2);
5509
- const order = bodyObject(read2, "order");
5510
- if (order?.status === "CANCELED" || order?.status === "CANCELLED" || order?.status === "REFUNDED") return "none";
5511
- const issued = Array.isArray(order?.tickets) && order.tickets.some((t) => isObject7(t) && isNonEmpty3(t.ticketNumber) && t.orderStatus === "PAID" && t.ticketDefinitionId === ref.ticketDefinitionId);
5512
- return order?.status === "PAID" && issued ? "granted" : order ? "pending" : "unavailable";
5513
- }
5514
- async function reopen(order, bridge, accessOf2, now) {
5515
- const access = await accessOf2(order.verticalRef, bridge);
5516
- if (access === "granted") return GRANTED;
5517
- if (access === "unavailable" || access === "sessionChanged") return { status: access };
5518
- if (access === "none" || now && !future(order.verticalRef.expires, now)) return ORDER_CLOSED;
5519
- return { status: "open", ...order };
5520
- }
5521
- function heldAsSelected(reservation, item) {
5522
- if (isObject7(reservation.invoice)) return samePrice2(reservation.invoice.grandTotal ?? reservation.invoice.total, item);
5523
- const lines = reservation.reservations;
5524
- if (!Array.isArray(lines) || lines.length !== 1 || !isObject7(lines[0]) || lines[0].quantity !== 1) return false;
5525
- const held = lines[0].ticket;
5526
- return isObject7(held) && held.id === item.reference.id && samePrice2(held.price, item);
5527
- }
5528
- function samePrice2(value, item) {
5529
- return isObject7(value) && value.currency === item.attendance?.currency && decimal2(value.amount) !== null && decimal2(value.amount) === decimal2(item.attendance?.amount);
5530
- }
5531
- function decimal2(value) {
5532
- if (typeof value !== "string" || !/^\d+(?:\.\d+)?$/.test(value)) return null;
5533
- return value.replace(/^0+(?=\d)/, "").replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
5534
- }
5535
- function future(value, now) {
5536
- return typeof value === "string" && Number.isFinite(Date.parse(value)) && Date.parse(value) > now();
5537
- }
5538
- function matchesSlot2(value, selected) {
5539
- 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])));
5540
- }
5541
- function creationRefused2(refusal) {
5542
- const attempt4 = attemptRefused(refusal);
5543
- return refusal.status === "http" && [400, 401, 403, 404, 405, 409, 410, 415, 422].includes(refusal.httpStatus) ? notCreated2(attempt4) : attempt4;
5544
- }
5545
- function notCreated2(attempt4) {
5546
- return { ...attempt4, noOrderCreated: true };
5547
- }
5007
+ return adapter;
5008
+ }
5009
+ async function openOrder(item, port) {
5010
+ const videoId = item.reference.id;
5011
+ const answer = await port.openSaleOrder(videoId);
5012
+ if (answer.status === "ok") return { status: "open", cashierOrderId: answer.orderId, verticalRef: { videoId, orderId: answer.orderId } };
5013
+ if (answer.status !== "refused") return attemptRefused(answer);
5014
+ if (answer.reason === "active") return GRANTED;
5015
+ return answer.reason === "pending" ? { status: "refused", reason: "paymentInProgress" } : ORDER_REFUSED;
5016
+ }
5017
+ async function reopenOrder(verticalRef, port) {
5018
+ const { videoId, orderId } = verticalRef;
5019
+ if (!isNonEmpty3(videoId) || !isNonEmpty3(orderId)) return ORDER_CLOSED;
5020
+ const answer = await port.salePurchase(videoId);
5021
+ if (answer.status !== "ok") return attemptRefused(answer);
5022
+ const purchase = answer.purchase;
5023
+ if (purchase?.status === "ACTIVE") return GRANTED;
5024
+ if (purchase && purchase.orderId === orderId && UNPAID.has(purchase.status)) return { status: "open", cashierOrderId: orderId, verticalRef: { videoId, orderId } };
5025
+ return ORDER_CLOSED;
5026
+ }
5027
+ async function readAccess(verticalRef, port) {
5028
+ const { videoId, orderId } = verticalRef;
5029
+ if (!isNonEmpty3(videoId) || !isNonEmpty3(orderId)) return "unavailable";
5030
+ const answer = await port.salePurchase(videoId);
5031
+ if (answer.status !== "ok") return accessRefused(answer);
5032
+ const purchase = answer.purchase;
5033
+ if (purchase?.status === "ACTIVE") return "granted";
5034
+ if (!purchase || purchase.orderId !== orderId) return "unavailable";
5035
+ if (UNPAID.has(purchase.status)) return "pending";
5036
+ return ENDED.has(purchase.status) ? "none" : "unavailable";
5037
+ }
5038
+ function dataAt(body, path) {
5039
+ let node3 = isObject7(body) && isObject7(body.data) ? body.data : body;
5040
+ for (const key of path) node3 = isObject7(node3) ? node3[key] : void 0;
5041
+ return isObject7(node3) ? node3 : null;
5042
+ }
5043
+ var ENDED = /* @__PURE__ */ new Set(["DECLINED", "EXPIRED", "CANCELED", "REFUNDED", "FAILED"]);
5044
+ var UNPAID = /* @__PURE__ */ new Set(["INITIALIZED", "PENDING"]);
5045
+ var PENDING_MESSAGE = "Pending payment for the purchase";
5046
+ var ACTIVE_MESSAGE = "Active purchase already existed";
5047
+ var CREATE_ORDER = `mutation HimiVideoSaleOrder($videoId: ID!) {
5048
+ purchase { order { create(input: {id: $videoId, type: SALE}) { status message entity { id } } } }
5049
+ }`;
5050
+ var SALE_PURCHASE = `query HimiVideoSalePurchase($videoId: ID!) {
5051
+ purchase(filter: {id: $videoId, type: SALE}) { status orderId }
5052
+ }`;
5053
+ var wixVideoOrders = /* @__PURE__ */ videoOrdersWith({ enabled: videosAppleSalesEnabled() });
5548
5054
 
5549
5055
  // ../../stdlib/flows/iap-checkout/src/iap-verticals/index.ts
5550
- var pricingPlanOrders = PRICING_PLAN_ITEM_PAYMENT_ENABLED ? pricingPlanItemPayments : pricingPlanClientOrders;
5056
+ var pricingPlanOrders = pricingPlanItemPayments;
5551
5057
 
5552
5058
  // ../../stdlib/wix-sdk/redirects-v1/src/index.ts
5553
5059
  function wixCallHeaders(opts) {
@@ -5599,7 +5105,7 @@ var hideWhen = (n, path) => ({
5599
5105
  ...n,
5600
5106
  modifiers: { ...n.modifiers ?? {}, hiddenPath: path }
5601
5107
  });
5602
- var text2 = (id2, value, style = "body") => node2(id2, "Text", { text: value, style });
5108
+ var text = (id2, value, style = "body") => node2(id2, "Text", { text: value, style });
5603
5109
  var vstack = (id2, children, spacing = 12, alignment = "leading") => node2(id2, "VStack", { spacing, alignment, children });
5604
5110
  var button = (id2, title, action2, style = "primary") => node2(id2, "Button", { title, style, fullWidth: true, action: action2 });
5605
5111
  var openScreen = (screenId) => ({ actionId: "himi.open", params: { screenId } });
@@ -5624,7 +5130,7 @@ function detailedHeader(opts) {
5624
5130
  spacing: 8,
5625
5131
  alignment: "center",
5626
5132
  children: [
5627
- text2(`${id2}.location`, opts.locationLabel, "caption"),
5133
+ text(`${id2}.location`, opts.locationLabel, "caption"),
5628
5134
  node2(`${id2}.location.action`, "Button", {
5629
5135
  title: opts.locationAction.label,
5630
5136
  style: opts.locationAction.style ?? "plain",
@@ -5634,7 +5140,7 @@ function detailedHeader(opts) {
5634
5140
  ]
5635
5141
  }));
5636
5142
  } else {
5637
- identity.push(text2(`${id2}.location`, opts.locationLabel, "caption"));
5143
+ identity.push(text(`${id2}.location`, opts.locationLabel, "caption"));
5638
5144
  }
5639
5145
  }
5640
5146
  cardChildren.push(node2(`${id2}.identity`, "HStack", { spacing: 12, alignment: "center", children: identity }));
@@ -5702,9 +5208,9 @@ function authScreen(opts) {
5702
5208
  ...extra
5703
5209
  });
5704
5210
  const children = [
5705
- text2(`${s2}.headline`, `$service:${s2}.headline`, "title1"),
5706
- text2(`${s2}.subhead`, `$service:${s2}.subhead`),
5707
- hideWhen(text2(`${s2}.notice`, `$service:${s2}.notice`, "bodyEmphasis"), `$service:${s2}.noNotice`),
5211
+ text(`${s2}.headline`, `$service:${s2}.headline`, "title1"),
5212
+ text(`${s2}.subhead`, `$service:${s2}.subhead`),
5213
+ hideWhen(text(`${s2}.notice`, `$service:${s2}.notice`, "bodyEmphasis"), `$service:${s2}.noNotice`),
5708
5214
  hideWhen(
5709
5215
  field("email", c.emailLabel ?? "Email", `tier5.${s2}.setEmail`, { keyboard: "email" }),
5710
5216
  `$service:${s2}.signedIn`
@@ -6187,18 +5693,18 @@ function checkoutScreen(opts) {
6187
5693
  const row = vstack(
6188
5694
  `${s2}.row`,
6189
5695
  [
6190
- hideWhen(text2(`${s2}.row_badge`, "$item.badge", "caption1"), "$item.noBadge"),
6191
- text2(`${s2}.row_name`, "$item.name", "title2"),
6192
- text2(`${s2}.row_price`, "$item.priceLine", "title1"),
6193
- text2(`${s2}.row_period`, "$item.periodLine", "caption1"),
6194
- text2(`${s2}.row_desc`, "$item.description"),
6195
- text2(`${s2}.row_note`, "$item.joinNote", "caption1"),
6196
- hideWhen(text2(`${s2}.row_perk1`, "$item.perk1"), "$item.noPerk1"),
6197
- hideWhen(text2(`${s2}.row_perk2`, "$item.perk2"), "$item.noPerk2"),
6198
- hideWhen(text2(`${s2}.row_perk3`, "$item.perk3"), "$item.noPerk3"),
5696
+ hideWhen(text(`${s2}.row_badge`, "$item.badge", "caption1"), "$item.noBadge"),
5697
+ text(`${s2}.row_name`, "$item.name", "title2"),
5698
+ text(`${s2}.row_price`, "$item.priceLine", "title1"),
5699
+ text(`${s2}.row_period`, "$item.periodLine", "caption1"),
5700
+ text(`${s2}.row_desc`, "$item.description"),
5701
+ text(`${s2}.row_note`, "$item.joinNote", "caption1"),
5702
+ hideWhen(text(`${s2}.row_perk1`, "$item.perk1"), "$item.noPerk1"),
5703
+ hideWhen(text(`${s2}.row_perk2`, "$item.perk2"), "$item.noPerk2"),
5704
+ hideWhen(text(`${s2}.row_perk3`, "$item.perk3"), "$item.noPerk3"),
6199
5705
  // The plan the member already holds shows a label, not a button. Selling
6200
5706
  // someone the thing they are currently paying for is the obvious next bug.
6201
- hideWhen(text2(`${s2}.row_joined`, "$item.joinedLabel", "bodyEmphasis"), "$item.notJoined"),
5707
+ hideWhen(text(`${s2}.row_joined`, "$item.joinedLabel", "bodyEmphasis"), "$item.notJoined"),
6202
5708
  hideWhen(
6203
5709
  node2(`${s2}.row_join`, "Button", {
6204
5710
  title: "$item.cta",
@@ -6213,21 +5719,21 @@ function checkoutScreen(opts) {
6213
5719
  6
6214
5720
  );
6215
5721
  const children = [
6216
- text2(`${s2}.headline`, `$service:${s2}.headline`, "title1"),
6217
- text2(`${s2}.subhead`, `$service:${s2}.subhead`),
6218
- hideWhen(text2(`${s2}.loading`, c.loadingText ?? "Loading plans\u2026"), `$service:${s2}.notLoading`),
5722
+ text(`${s2}.headline`, `$service:${s2}.headline`, "title1"),
5723
+ text(`${s2}.subhead`, `$service:${s2}.subhead`),
5724
+ hideWhen(text(`${s2}.loading`, c.loadingText ?? "Loading plans\u2026"), `$service:${s2}.notLoading`),
6219
5725
  // A site with no plans is a real state, not an impossible one, and hiding the
6220
5726
  // list alone leaves a headline over blank space. Bound to a flag the SERVICE
6221
5727
  // computes: `hiddenPath` is a single path, so nesting two hideWhen calls to
6222
5728
  // mean "ready AND empty" just overwrites the inner one and shows this line
6223
5729
  // during the first load.
6224
5730
  hideWhen(
6225
- text2(`${s2}.empty`, c.emptyText ?? "No plans are available right now."),
5731
+ text(`${s2}.empty`, c.emptyText ?? "No plans are available right now."),
6226
5732
  `$service:${s2}.notEmptyCatalog`
6227
5733
  ),
6228
- hideWhen(text2(`${s2}.error`, `$service:${s2}.error`), `$service:${s2}.noError`),
5734
+ hideWhen(text(`${s2}.error`, `$service:${s2}.error`), `$service:${s2}.noError`),
6229
5735
  // Result of a join attempt — never a dead button.
6230
- hideWhen(text2(`${s2}.notice`, `$service:${s2}.notice`, "bodyEmphasis"), `$service:${s2}.noNotice`)
5736
+ hideWhen(text(`${s2}.notice`, `$service:${s2}.notice`, "bodyEmphasis"), `$service:${s2}.noNotice`)
6231
5737
  ];
6232
5738
  if (opts.signInScreenId) {
6233
5739
  children.push(