@wix/himalaya-cli 0.1320.0 → 0.1321.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 (47) 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 +3 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/biometrics/src/index.d.ts +11 -1
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/catalog-pricing-contract.d.ts +4 -0
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/host-session.d.ts +4 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/index.d.ts +13 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/mapping-source.d.ts +8 -3
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments.d.ts +5 -4
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/sdk-types/src/capabilities.generated.d.ts +1 -1
  10. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/tokens.d.ts +9 -1
  11. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/apple-iap-contract.d.ts +5 -0
  12. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/apple-iap-core.d.ts +3 -1
  13. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/checkout-source.d.ts +4 -0
  14. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/commerce-contract.d.ts +83 -0
  15. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/commerce-core.d.ts +36 -0
  16. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/commerce.d.ts +8 -0
  17. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/index.d.ts +3 -0
  18. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/flows/iap-checkout/src/purchase-fields.d.ts +4 -0
  19. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/audio-record.mjs +1 -1
  20. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calendar.mjs +1 -1
  21. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/calls.mjs +1 -1
  22. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/contacts.mjs +1 -1
  23. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap-checkout.mjs +1205 -71
  24. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap.mjs +125 -13
  25. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/location.mjs +1 -1
  26. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/motion.mjs +1 -1
  27. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/photos.mjs +1 -1
  28. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdk-types.mjs +1 -1
  29. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +1 -0
  30. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/tasks.mjs +1 -1
  31. package/dist/cli.mjs +62 -23
  32. package/dist/preview-assets.generated.bin +0 -0
  33. package/guides/getting-started.md +4 -2
  34. package/guides/himi-skill.md +4 -2
  35. package/guides/iap-pricing.md +33 -26
  36. package/guides/index.json +2 -1
  37. package/guides/sdk-reference.json +17 -5
  38. package/guides/tokens.md +22 -1
  39. package/package.json +2 -2
  40. package/templates/branded-lite/dev/index.ts +41 -0
  41. package/templates/branded-lite/tier5-src/_shared/iap-worker.ts +21 -44
  42. package/templates/branded-lite/tier5-src/himi-branded-lite-program/index.ts +77 -47
  43. package/templates/branded-lite/tier5-src/himi-branded-lite-programs/index.ts +24 -38
  44. package/templates/yoga-studio/dev/index.ts +41 -0
  45. package/templates/yoga-studio/tier5-src/_shared/iap-worker.ts +21 -44
  46. package/templates/yoga-studio/tier5-src/himi-branded-lite-program/index.ts +77 -47
  47. package/templates/yoga-studio/tier5-src/himi-branded-lite-programs/index.ts +24 -38
@@ -514,8 +514,8 @@ function createSerialQueue() {
514
514
  return {
515
515
  /** Callers joined onto a shared job all receive that job's result. */
516
516
  run(name, job, { joinRunning = false }) {
517
- const shared = waiting.get(name) ?? (joinRunning ? running.get(name) : void 0);
518
- if (shared) return shared;
517
+ const shared2 = waiting.get(name) ?? (joinRunning ? running.get(name) : void 0);
518
+ if (shared2) return shared2;
519
519
  const scheduled = tail.then(() => execute(name, scheduled, job));
520
520
  waiting.set(name, scheduled);
521
521
  tail = scheduled;
@@ -661,9 +661,72 @@ var sameReference = (value, reference) => isObject2(value) && value.kind === ref
661
661
  // ../../core/sdk/iap/src/catalog-pricing-contract.ts
662
662
  var IAP_CATALOG_KINDS = ["onlineProgram", "storesProduct", "pricingPlan"];
663
663
 
664
+ // ../../core/sdk/iap/src/wix-payments-contract.ts
665
+ var HIMALAYA_SERVE_IAP_ROUTE = { prefix: "/himalaya-serve/v1/iap" };
666
+ var APPLE_SALE_RULES = {
667
+ onlineProgram: { appProductId: (id) => id, productType: "NON_CONSUMABLE" }
668
+ };
669
+
664
670
  // ../../core/sdk/iap/src/mapping-source.ts
665
671
  function iapMappingSource() {
666
- return void 0;
672
+ return createWixIapMappingSource({ binding: sharedHostAppBindingSource(), call: hostWixCall });
673
+ }
674
+ function createWixIapMappingSource(deps) {
675
+ return {
676
+ // Only a binding the host actually returned: a read that failed is re-asked on the next load.
677
+ active: async () => await deps.binding.current() !== null,
678
+ mapping: {
679
+ resolve: async ({ scope, references }) => {
680
+ const binding = await deps.binding.current();
681
+ if (!binding) return references.map((reference) => ({ reference, route: "regular" }));
682
+ if (scope.siteId && !sameId(scope.siteId, binding.siteId)) return references.map((reference) => ({ reference, route: "unavailable" }));
683
+ const asked = [...new Set(references.flatMap((reference) => appProductIdOf(reference) ?? []))];
684
+ const mapped = await resolveAll(deps.call, binding, asked);
685
+ return references.map((reference) => decide(reference, binding, mapped));
686
+ }
687
+ }
688
+ };
689
+ }
690
+ function appProductIdOf(reference) {
691
+ return reference.id ? APPLE_SALE_RULES[reference.kind]?.appProductId(reference.id) : void 0;
692
+ }
693
+ var PATH = `${HIMALAYA_SERVE_IAP_ROUTE.prefix}/mappings`;
694
+ var BATCH = 100;
695
+ async function resolveAll(call, binding, ids) {
696
+ const mapped = /* @__PURE__ */ new Map();
697
+ const wanted = new Set(ids);
698
+ for (let at = 0; at < ids.length; at += BATCH) {
699
+ const batch = ids.slice(at, at + BATCH);
700
+ const reply = await call("POST", PATH, { appId: binding.purchasesAppId, appProductIds: batch }, { "wix-site-id": binding.siteId });
701
+ for (const [id, mapping] of decodeMappings(reply)) if (wanted.has(id)) mapped.set(id, mapping);
702
+ }
703
+ return mapped;
704
+ }
705
+ function decodeMappings(reply) {
706
+ const list = reply?.mappings;
707
+ if (!Array.isArray(list)) throw new Error("the mapping route answered without a mappings list");
708
+ return list.map((raw) => {
709
+ const m = raw;
710
+ if (typeof m?.appProductId !== "string" || typeof m.storeProductId !== "string" || !m.storeProductId) {
711
+ throw new Error("the mapping route answered a mapping without its ids");
712
+ }
713
+ return [m.appProductId, { storeProductId: m.storeProductId, type: String(m.type ?? ""), active: m.active === true }];
714
+ });
715
+ }
716
+ function decide(reference, binding, mapped) {
717
+ const id = appProductIdOf(reference);
718
+ const mapping = id ? mapped.get(id) : void 0;
719
+ if (!mapping) return { reference, route: "regular" };
720
+ if (!mapping.active || mapping.type !== APPLE_SALE_RULES[reference.kind]?.productType) return { reference, route: "unavailable" };
721
+ return { reference, route: "appleIap", productId: mapping.storeProductId, mappingRevision: `${binding.purchasesAppId}:${mapping.storeProductId}` };
722
+ }
723
+ function sameId(a, b) {
724
+ return a.toLowerCase() === b.toLowerCase();
725
+ }
726
+ function hostWixCall(method, path, body, headers) {
727
+ const bridge = globalThis.himalaya?.wixApi;
728
+ if (!bridge) return Promise.reject(new Error("the host did not install the wixApi bridge"));
729
+ return bridge.call(method, path, body, headers);
667
730
  }
668
731
 
669
732
  // ../../core/sdk/iap/src/catalog-pricing-core.ts
@@ -702,6 +765,7 @@ function enabledPricing(source, deps) {
702
765
  if (!unanswered(answered)) settled.set(referenceKey(item.reference), answered);
703
766
  }
704
767
  };
768
+ let selling = "active";
705
769
  let lookupRevision = 0;
706
770
  let answeredRoutes;
707
771
  const mapping = {
@@ -727,21 +791,30 @@ function enabledPricing(source, deps) {
727
791
  deps.onChange?.();
728
792
  }
729
793
  }));
730
- const view = (reference) => disposed ? blockedView(reference, "unavailable") : viewOf(reference, controller && itemFor(controller.getState().items, reference));
794
+ const view = (reference) => disposed ? blockedView(reference, "unavailable") : selling === "inactive" ? disabledView(reference) : selling === "unknown" ? sellingUnknownView(reference) : viewOf(reference, controller && itemFor(controller.getState().items, reference));
795
+ const load = async (input) => {
796
+ if (disposed) return;
797
+ selling = source.active ? await source.active().then((active) => active ? "active" : "inactive", () => "unknown") : "active";
798
+ if (selling !== "active") {
799
+ deps.onChange?.();
800
+ return;
801
+ }
802
+ await ensureController().load(pricingInput(input, source));
803
+ };
731
804
  const continueCheckoutGuard = (reference) => {
732
805
  const current = view(reference);
733
- if (!unanswered(current)) return decisionOf(current);
806
+ if (!unanswered(current) || selling !== "active") return decisionOf(current);
734
807
  if (answeredRoutes) return routeDecision(answeredRoutes.get(referenceKey(reference)) ?? "unavailable");
735
808
  return decisionOf(settled.get(referenceKey(reference)) ?? current);
736
809
  };
737
810
  return {
738
811
  enabled: true,
739
- load: (input) => disposed ? Promise.resolve() : ensureController().load(pricingInput(input, source)),
812
+ load,
740
813
  refresh: () => controller?.refresh() ?? Promise.resolve(),
741
814
  view,
742
815
  checkoutGuard: (reference) => decisionOf(view(reference)),
743
816
  continueCheckoutGuard,
744
- appleProduct: (reference) => disposed ? null : appleProductOf(controller && itemFor(controller.getState().items, reference)),
817
+ appleProduct: (reference) => disposed || selling !== "active" ? null : appleProductOf(controller && itemFor(controller.getState().items, reference)),
745
818
  pollDirective: (action) => ({ id: POLL_ID, action, intervalMs: POLL_INTERVAL_MS, immediate: true }),
746
819
  dispose: () => {
747
820
  disposed = true;
@@ -808,6 +881,9 @@ function blockedView(reference, route) {
808
881
  function regularView(reference) {
809
882
  return { ...blockedView(reference, "regular"), canStartRegularCheckout: true };
810
883
  }
884
+ function sellingUnknownView(reference) {
885
+ return { ...blockedView(reference, "unavailable"), reason: "mappingUnavailable", retryable: true };
886
+ }
811
887
  function disabledView(reference) {
812
888
  return { ...blockedView(reference, "disabled"), canStartRegularCheckout: true };
813
889
  }
@@ -852,12 +928,6 @@ function onlineProgramItem(program, commerceDisplayPrice) {
852
928
  return { reference: { kind: ONLINE_PROGRAM, id }, ...commerceDisplayPrice ? { commerceDisplayPrice } : {} };
853
929
  }
854
930
 
855
- // ../../core/sdk/iap/src/wix-payments-contract.ts
856
- var HIMALAYA_SERVE_IAP_ROUTE = { prefix: "/himalaya-serve/v1/iap" };
857
- var APPLE_SALE_RULES = {
858
- onlineProgram: { appProductId: (id) => id, productType: "NON_CONSUMABLE" }
859
- };
860
-
861
931
  // ../../core/sdk/iap/src/host-session.ts
862
932
  var SIGNED_OUT = {
863
933
  generation: 0,
@@ -892,6 +962,10 @@ function createHostSession(source) {
892
962
  pull();
893
963
  return byGeneration.get(session.generation) ?? null;
894
964
  },
965
+ site() {
966
+ const snap = pull();
967
+ return snap.ready ? snap.siteId : null;
968
+ },
895
969
  subscribe(listener) {
896
970
  return source.subscribe(() => {
897
971
  const before = seen;
@@ -1277,6 +1351,42 @@ async function finishTransaction(input) {
1277
1351
  return decodeFailure(result);
1278
1352
  }
1279
1353
  var appleManagedStore = { purchaseForVerification, getUnfinishedTransactions, finishTransaction };
1354
+ function hostAppBindingSource() {
1355
+ let read2;
1356
+ return {
1357
+ current: () => read2 ?? (read2 = readHostBinding().catch((error) => {
1358
+ read2 = void 0;
1359
+ throw error;
1360
+ }))
1361
+ };
1362
+ }
1363
+ async function readHostBinding() {
1364
+ let answer;
1365
+ try {
1366
+ answer = await dispatch("capability.iap.appBinding");
1367
+ } catch (error) {
1368
+ if (bindingNotOffered(error)) return null;
1369
+ throw new Error("the host could not read the app binding");
1370
+ }
1371
+ if (!isObject4(answer)) throw new Error("the host could not read the app binding");
1372
+ if (answer.status === "bound") return decodeBinding(answer.binding);
1373
+ if (answer.status === "unbound" || answer.status === "failed" && answer.code === "unsupported") return null;
1374
+ throw new Error("the host could not read the app binding");
1375
+ }
1376
+ function bindingNotOffered(error) {
1377
+ const message = error instanceof Error ? error.message : String(error);
1378
+ return /(unknown|no capability handler for|needs a fixture for)\W[^\n]{0,20}capability\.iap\.appBinding|capability iap not allowed/i.test(message);
1379
+ }
1380
+ var shared;
1381
+ function sharedHostAppBindingSource() {
1382
+ return shared ?? (shared = hostAppBindingSource());
1383
+ }
1384
+ function decodeBinding(raw) {
1385
+ if (!isObject4(raw)) return null;
1386
+ const { purchasesAppId, himalayaAppId, bundleId, siteId } = raw;
1387
+ if (!isUUID2(purchasesAppId) || !isUUID2(siteId) || !nonempty2(himalayaAppId) || !nonempty2(bundleId)) return null;
1388
+ return { purchasesAppId, himalayaAppId, bundleId, siteId };
1389
+ }
1280
1390
  var transactionErrors = /* @__PURE__ */ new Set(["unsupported", "unavailable", "invalidArgument", "invalidResponse", "notEnabled", "unsupportedProductType", "unknownProduct", "verificationFailed", "persistenceFailed", "ownershipConflict", "storeError", "busy"]);
1281
1391
  var failure2 = (code) => ({ status: "failed", code });
1282
1392
  var nonempty2 = (value) => typeof value === "string" && value.trim().length > 0;
@@ -1319,6 +1429,7 @@ export {
1319
1429
  getPaywallConfig,
1320
1430
  getProducts,
1321
1431
  getUnfinishedTransactions,
1432
+ hostAppBindingSource,
1322
1433
  hostSessionFromGlobal,
1323
1434
  iapPriceFields,
1324
1435
  memberIdentityOf,
@@ -1327,6 +1438,7 @@ export {
1327
1438
  purchaseForVerification,
1328
1439
  readIdentityBound,
1329
1440
  restore,
1441
+ sharedHostAppBindingSource,
1330
1442
  version
1331
1443
  };
1332
1444
  //# sourceMappingURL=iap.mjs.map
@@ -31,7 +31,7 @@ var CAPABILITY_REGISTRY = {
31
31
  "haptic": ["play"],
32
32
  "health": ["availability", "getPermissionStatus", "query", "requestPermission", "saveWorkout"],
33
33
  "himi_apps": ["canOpen", "current", "hostInfo", "open"],
34
- "iap": ["consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
34
+ "iap": ["appBinding", "consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
35
35
  "keyboard": ["dismiss"],
36
36
  "live_activity": ["end", "start", "update"],
37
37
  "local_database": ["availability", "count", "get", "getAll", "purge", "query", "queueDepth", "queueDrain", "queueEnqueue", "remove", "upsert"],
@@ -31,7 +31,7 @@ var CAPABILITY_REGISTRY = {
31
31
  "haptic": ["play"],
32
32
  "health": ["availability", "getPermissionStatus", "query", "requestPermission", "saveWorkout"],
33
33
  "himi_apps": ["canOpen", "current", "hostInfo", "open"],
34
- "iap": ["consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
34
+ "iap": ["appBinding", "consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
35
35
  "keyboard": ["dismiss"],
36
36
  "live_activity": ["end", "start", "update"],
37
37
  "local_database": ["availability", "count", "get", "getAll", "purge", "query", "queueDepth", "queueDrain", "queueEnqueue", "remove", "upsert"],
@@ -31,7 +31,7 @@ var CAPABILITY_REGISTRY = {
31
31
  "haptic": ["play"],
32
32
  "health": ["availability", "getPermissionStatus", "query", "requestPermission", "saveWorkout"],
33
33
  "himi_apps": ["canOpen", "current", "hostInfo", "open"],
34
- "iap": ["consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
34
+ "iap": ["appBinding", "consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
35
35
  "keyboard": ["dismiss"],
36
36
  "live_activity": ["end", "start", "update"],
37
37
  "local_database": ["availability", "count", "get", "getAll", "purge", "query", "queueDepth", "queueDrain", "queueEnqueue", "remove", "upsert"],
@@ -16,7 +16,7 @@ var CAPABILITY_REGISTRY = {
16
16
  "haptic": ["play"],
17
17
  "health": ["availability", "getPermissionStatus", "query", "requestPermission", "saveWorkout"],
18
18
  "himi_apps": ["canOpen", "current", "hostInfo", "open"],
19
- "iap": ["consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
19
+ "iap": ["appBinding", "consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
20
20
  "keyboard": ["dismiss"],
21
21
  "live_activity": ["end", "start", "update"],
22
22
  "local_database": ["availability", "count", "get", "getAll", "purge", "query", "queueDepth", "queueDrain", "queueEnqueue", "remove", "upsert"],
@@ -9120,6 +9120,7 @@ function deriveAppMeta(name, m, platforms = {}, provisioning = {}) {
9120
9120
  auth: config.auth,
9121
9121
  iap: config.iap,
9122
9122
  base44: config.base44,
9123
+ wixIap: config.wixIap,
9123
9124
  // RFC 0042 Phase 2 — optional per-app Wix Platform productionization block.
9124
9125
  // Read loosely (AppConfig in @himalaya/core doesn't type it yet) so apps can
9125
9126
  // opt in without a core-types bump; absent ⇒ all members keep the dev seam.
@@ -31,7 +31,7 @@ var CAPABILITY_REGISTRY = {
31
31
  "haptic": ["play"],
32
32
  "health": ["availability", "getPermissionStatus", "query", "requestPermission", "saveWorkout"],
33
33
  "himi_apps": ["canOpen", "current", "hostInfo", "open"],
34
- "iap": ["consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
34
+ "iap": ["appBinding", "consume", "entitlements", "finishTransaction", "getPaywallConfig", "getProducts", "getUnfinishedTransactions", "purchase", "purchaseForVerification", "restore"],
35
35
  "keyboard": ["dismiss"],
36
36
  "live_activity": ["end", "start", "update"],
37
37
  "local_database": ["availability", "count", "get", "getAll", "purge", "query", "queueDepth", "queueDrain", "queueEnqueue", "remove", "upsert"],