@wix/himalaya-cli 0.1262.0 → 0.1264.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 (48) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/builder.d.ts +1 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/index.d.ts +2 -0
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments-contract.d.ts +104 -0
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments-wire.d.ts +44 -0
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/iap/src/wix-payments.d.ts +47 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/schema.d.ts +2 -0
  7. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/tokens.d.ts +4 -0
  8. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +26 -0
  9. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/iap.mjs +280 -10
  10. package/dist/cli.mjs +155 -38
  11. package/dist/preview-assets.generated.bin +0 -0
  12. package/guides/component-reference.json +1 -1
  13. package/guides/component-reference.md +2 -0
  14. package/guides/sdk-reference.json +135 -0
  15. package/package.json +2 -2
  16. package/templates/beauty-salon-owner/dev/index.ts +256 -87
  17. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  18. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  19. package/templates/community-club-owner/dev/index.ts +192 -71
  20. package/templates/community-club-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  21. package/templates/community-club-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  22. package/templates/events-meetups-owner/dev/index.ts +96 -47
  23. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  24. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  25. package/templates/gym-fitness-owner/dev/index.ts +288 -95
  26. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  27. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  28. package/templates/nonprofit-cause-owner/dev/index.ts +192 -71
  29. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  30. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  31. package/templates/owner-lite/dev/index.ts +288 -95
  32. package/templates/owner-lite/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  33. package/templates/owner-lite/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  34. package/templates/podcast-creator-owner/dev/index.ts +192 -71
  35. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  36. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  37. package/templates/portfolio-creative-owner/dev/index.ts +256 -87
  38. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  39. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  40. package/templates/restaurant-owner/dev/index.ts +288 -95
  41. package/templates/restaurant-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  42. package/templates/restaurant-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  43. package/templates/retail-store-owner/dev/index.ts +160 -63
  44. package/templates/retail-store-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  45. package/templates/retail-store-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
  46. package/templates/yoga-studio-owner/dev/index.ts +192 -71
  47. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-ask/index.ts +5 -0
  48. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-drawer/logic.ts +3 -0
@@ -442,6 +442,7 @@ export declare function button(props: {
442
442
  title: string;
443
443
  action: ActionShape;
444
444
  style?: string;
445
+ role?: "destructive" | "cancel";
445
446
  disabled?: boolean;
446
447
  /** #3117 — `$service:`/`$item.` bool binding, OR'd with `disabled`/`loading`. */
447
448
  disabledPath?: string;
@@ -7,6 +7,8 @@ export * from "./catalog-pricing-contract.js";
7
7
  export * from "./catalog-pricing.js";
8
8
  export * from "./catalog-price-fields.js";
9
9
  export * from "./catalog-adapters/online-programs.js";
10
+ export * from "./wix-payments-contract.js";
11
+ export * from "./wix-payments.js";
10
12
  /** The three store product categories. */
11
13
  export type ProductType = "subscription" | "nonConsumable" | "consumable";
12
14
  export interface Product {
@@ -0,0 +1,104 @@
1
+ import type { SessionSnapshot } from "./delivery-contract.js";
2
+ /** This Himalaya app's registration in the purchases service. Produced once by trusted
3
+ * provisioning, never by a worker; no production source exists yet. */
4
+ export interface PurchasesAppBinding {
5
+ /** The purchases service's app UUID (RegisterApp's `app.id`), which Payments calls `appId`. */
6
+ purchasesAppId: string;
7
+ himalayaAppId: string;
8
+ bundleId: string;
9
+ /** Wix metaSiteId the app was registered on. */
10
+ siteId: string;
11
+ }
12
+ export interface AppBindingSource {
13
+ /** Null when the app was never registered. */
14
+ current(): Promise<PurchasesAppBinding | null>;
15
+ }
16
+ /** The running app's own identity; a binding for anything else is refused. */
17
+ export interface IapAppHost {
18
+ appId: string;
19
+ bundleId: string;
20
+ siteId: string;
21
+ }
22
+ /** Where the Payments service is reachable through the Wix gateway. */
23
+ export interface WixIapRoute {
24
+ /** The gateway path that maps to the service's `/v1`, without a trailing slash. No public route
25
+ * was in the generated gateway metadata on 2026-10-08, so there is deliberately no default. */
26
+ prefix: string;
27
+ }
28
+ /** The host's Wix REST bridge (`himalaya.wixApi`). Resolves the parsed body of a 2xx and
29
+ * rejects with `HTTP <status> [<code>]: <message>` otherwise. Credentials are attached
30
+ * natively, never in TypeScript. */
31
+ export interface WixTransport {
32
+ call(method: "GET" | "POST", path: string, body?: unknown, headers?: Record<string, string>): Promise<unknown>;
33
+ }
34
+ /** Optional, from a trusted host only: the Wix member id signed in for a captured session. Used to
35
+ * refuse an answer about someone else, never sent: the server derives the member itself. */
36
+ export interface MemberIdentitySource {
37
+ memberId(session: SessionSnapshot): Promise<string | null>;
38
+ }
39
+ export type WixIapPaymentStatus = "pending" | "approving" | "approved" | "canceling" | "canceled" | "refunding" | "refunded";
40
+ /** One Wix Payments transaction being paid with a store purchase. `approving` means the server
41
+ * has claimed the purchase and is still reporting it: not paid, and no access. */
42
+ export interface WixIapPayment {
43
+ paymentId: string;
44
+ appId: string;
45
+ memberId: string;
46
+ wixTransactionId: string;
47
+ /** The store product the payment sells; absent until the server resolves one. */
48
+ appProductId?: string;
49
+ status: WixIapPaymentStatus;
50
+ cancelReason?: "expired" | "rejected";
51
+ /** The purchases service's record UUID, not Apple's transaction id. */
52
+ purchaseTransactionId?: string;
53
+ expiresDate?: string;
54
+ approvedDate?: string;
55
+ canceledDate?: string;
56
+ refundedDate?: string;
57
+ }
58
+ export type WixIapOperation = "startPayment" | "completePayment" | "getCustomerId" | "getPayment";
59
+ export type StartPaymentErrorCode = "NOT_PENDING" | "WRONG_PAYMENT_METHOD" | "NOT_ORDER_BUYER" | "UNSUPPORTED_ORDER" | "PRODUCT_NOT_AVAILABLE" | "ALREADY_OWNED";
60
+ export type CompletePaymentErrorCode = "INVALID_PURCHASE" | "OWNED_BY_ANOTHER_CUSTOMER" | "PURCHASE_REVOKED" | "NOT_PURCHASED" | "ZERO_PRICE" | "NO_MATCHING_PAYMENT" | "APP_NOT_CONFIGURED";
61
+ export type GetCustomerIdErrorCode = "APP_NOT_CONFIGURED";
62
+ export type GetPaymentErrorCode = "NOT_FOUND";
63
+ /** Why a call gave no usable answer, other than a named application error.
64
+ * `unavailable` and `sessionChanged` say nothing about whether the request took effect.
65
+ * `unrecognized` is an HTTP refusal this client cannot name: never treat it as terminal.
66
+ * `invalidArgument`, `environmentUnsupported`, `notProvisioned` and `authRequired` from a
67
+ * local check are decided before anything is sent. */
68
+ export type WixIapFailureKind = "notEnabled" | "notProvisioned" | "authRequired" | "notPermitted" | "invalidArgument" | "environmentUnsupported" | "sessionChanged" | "unavailable" | "unrecognized" | "invalidResponse";
69
+ /** A failure carries the operation, a kind, the service's own code when it named one, and the
70
+ * HTTP status when there was one. Never the server's message, the proof or a credential. */
71
+ export type WixIapFailure<Code extends string> = {
72
+ status: "failed";
73
+ operation: WixIapOperation;
74
+ kind: "application";
75
+ code: Code;
76
+ httpStatus: number;
77
+ } | {
78
+ status: "failed";
79
+ operation: WixIapOperation;
80
+ kind: WixIapFailureKind;
81
+ httpStatus?: number;
82
+ };
83
+ /** `customerId` goes to StoreKit as `appAccountToken` (the customer id is the token, D59). Keep it
84
+ * out of screen state. */
85
+ export type StartPaymentResult = {
86
+ status: "started";
87
+ payment: WixIapPayment;
88
+ storeProductId: string;
89
+ customerId: string;
90
+ } | WixIapFailure<StartPaymentErrorCode>;
91
+ /** `matched`: the server verified the proof and matched it to `payment`, which may not be the one
92
+ * this device started. Its status may still be `approving`. */
93
+ export type CompletePaymentResult = {
94
+ status: "matched";
95
+ payment: WixIapPayment;
96
+ } | WixIapFailure<CompletePaymentErrorCode>;
97
+ export type CustomerIdResult = {
98
+ status: "found";
99
+ customerId: string;
100
+ } | WixIapFailure<GetCustomerIdErrorCode>;
101
+ export type GetPaymentResult = {
102
+ status: "found";
103
+ payment: WixIapPayment;
104
+ } | WixIapFailure<GetPaymentErrorCode>;
@@ -0,0 +1,44 @@
1
+ import type { PurchasesAppBinding, WixIapFailure, WixIapFailureKind, WixIapOperation, WixIapPayment } from "./wix-payments-contract.js";
2
+ export interface WixIapCall {
3
+ method: "GET" | "POST";
4
+ path: string;
5
+ body?: Record<string, unknown>;
6
+ headers: Record<string, string>;
7
+ }
8
+ export interface CallScope {
9
+ binding: PurchasesAppBinding;
10
+ prefix: string;
11
+ }
12
+ export declare function startPaymentCall(scope: CallScope, wixTransactionId: string): WixIapCall;
13
+ /** The JWS goes byte-for-byte: the server derives the member, and the proof names the product. */
14
+ export declare function completePaymentCall(scope: CallScope, signedTransaction: string): WixIapCall;
15
+ export declare function customerIdCall(scope: CallScope): WixIapCall;
16
+ export declare function paymentCall(scope: CallScope, paymentId: string): WixIapCall;
17
+ /** A gateway path such as `/_api/<service>/v1`: absolute, no trailing slash, query or scheme. */
18
+ export declare function isRoutePrefix(prefix: string): boolean;
19
+ export interface PaymentExpectation {
20
+ appId: string;
21
+ /** Checked only when a trusted host supplied it. */
22
+ memberId: string | null;
23
+ paymentId?: string;
24
+ wixTransactionId?: string;
25
+ }
26
+ export interface StartedPayment {
27
+ payment: WixIapPayment;
28
+ storeProductId: string;
29
+ customerId: string;
30
+ }
31
+ export declare function decodeStarted(raw: unknown, expected: PaymentExpectation): StartedPayment | null;
32
+ /** CompletePayment's and GetPayment's answer: `{payment}`. */
33
+ export declare function decodePaymentAnswer(raw: unknown, expected: PaymentExpectation): WixIapPayment | null;
34
+ /** D59: the customer's id is the StoreKit `appAccountToken`; no other field may stand in for it. */
35
+ export declare function decodeCustomerId(raw: unknown): string | null;
36
+ /** Maps a bridge rejection to a failure. The message itself is never kept: the bridge copies up
37
+ * to 300 characters of the response, which can echo the request. */
38
+ export declare function classifyFailure<Code extends string>(error: unknown, operation: WixIapOperation, codes: readonly Code[]): WixIapFailure<Code>;
39
+ export declare function failure(operation: WixIapOperation, kind: WixIapFailureKind): {
40
+ status: "failed";
41
+ operation: WixIapOperation;
42
+ kind: WixIapFailureKind;
43
+ };
44
+ export declare function isUUID(value: unknown): value is string;
@@ -0,0 +1,47 @@
1
+ import type { AppleTransaction } from "./index.js";
2
+ import type { SessionProvider } from "./delivery-contract.js";
3
+ import type { AppBindingSource, CompletePaymentResult, CustomerIdResult, GetPaymentResult, IapAppHost, MemberIdentitySource, StartPaymentResult, WixIapRoute, WixTransport } from "./wix-payments-contract.js";
4
+ export interface WixIapClientDependencies {
5
+ /** The trusted host session; each call is bound to the generation current when it starts. */
6
+ session: SessionProvider;
7
+ binding: AppBindingSource;
8
+ host: IapAppHost;
9
+ route: WixIapRoute;
10
+ /** Defaults to the host's Wix REST bridge (`himalaya.wixApi`, capability `wix_api`). */
11
+ transport?: WixTransport;
12
+ /** Optional cross-check that every Payment answered is the signed-in member's own. */
13
+ identity?: MemberIdentitySource;
14
+ }
15
+ export interface WixIapClient {
16
+ /** StartPayment for a pending `appleIAP` Wix Payments transaction the member placed. Returns the
17
+ * store product to sell and the customer id to pass to StoreKit as `appAccountToken`. */
18
+ startPayment(input: {
19
+ wixTransactionId: string;
20
+ }): Promise<StartPaymentResult>;
21
+ /** CompletePayment with held Apple proof, sent unchanged. Success can still be `approving`. */
22
+ completePayment(transaction: AppleTransaction): Promise<CompletePaymentResult>;
23
+ /** GetCustomerId: the member's customer id, for recovering held purchases. Creates the customer
24
+ * when there is none. */
25
+ getCustomerId(): Promise<CustomerIdResult>;
26
+ /** GetPayment: one of the member's own Payments. */
27
+ getPayment(input: {
28
+ paymentId: string;
29
+ }): Promise<GetPaymentResult>;
30
+ }
31
+ /**
32
+ * Creates a client for Wix's in-app-purchase payments service (`mobile-apps-wix-iap`), which pays
33
+ * a Wix order with a store purchase the member makes in the app.
34
+ *
35
+ * NOT ENABLED and not production-ready. No app wires it, and no call reaches the service: it has
36
+ * no public gateway route yet, so `route` must be supplied and there is no default. It calls
37
+ * StartPayment (`POST …/payments/start`), CompletePayment (`POST …/payments/complete`),
38
+ * GetCustomerId (`GET …/customer-id`) and GetPayment (`GET …/payments/{id}`) through the
39
+ * `wix_api` bridge. A matched or approved Payment is not durable access and never finishes the
40
+ * store transaction.
41
+ *
42
+ * Production use is blocked on pending prerequisites: a public route and member authorization on
43
+ * the service, the service's own app identity and permissions, a trusted provisioning flow for the
44
+ * app binding, and a native bridge that binds each request to the session generation across
45
+ * authorization, send and retry. Its checks here protect only this client's own flow.
46
+ */
47
+ export declare function createWixIapClient(deps: WixIapClientDependencies): WixIapClient;
@@ -693,6 +693,8 @@ export interface IconProps {
693
693
  contentDescription?: string;
694
694
  }
695
695
  export interface ButtonProps {
696
+ /** RFC 0068 — destructive/cancel role independent of style; unknown values warn and behave as absent. */
697
+ role?: string;
696
698
  /** Button label — binding-aware ("$item."/"$service:") on web, iOS and Android. */
697
699
  title: string;
698
700
  action: Action;
@@ -428,3 +428,7 @@ export interface TokenViolation {
428
428
  kind: "color" | "spacing" | "typography" | "radius";
429
429
  name: string;
430
430
  }
431
+ /** RFC 0068 — shared web/RN Button presentation families. Legacy keys remain token keys. */
432
+ export declare const BUTTON_VARIANTS: readonly ["filled", "tonal", "outlined", "text", "elevated", "bordered", "prominent", "plain", "glass"];
433
+ export declare const BUTTON_LEGACY_STYLES: readonly ["primary", "secondary", "tertiary", "link", "destructive"];
434
+ export declare function buttonVariant(style: string | undefined): "text" | "filled" | "tonal" | "outlined" | "elevated" | "glass";
@@ -7985,6 +7985,29 @@ var TYPOGRAPHY_TOKEN_PROPS = {
7985
7985
  Label: ["style"],
7986
7986
  Marquee: ["style"]
7987
7987
  };
7988
+ var BUTTON_VARIANTS = ["filled", "tonal", "outlined", "text", "elevated", "bordered", "prominent", "plain", "glass"];
7989
+ var BUTTON_LEGACY_STYLES = ["primary", "secondary", "tertiary", "link", "destructive"];
7990
+ function buttonVariant(style) {
7991
+ switch (style ?? "primary") {
7992
+ case "primary":
7993
+ case "destructive":
7994
+ case "filled":
7995
+ case "prominent":
7996
+ return "filled";
7997
+ case "secondary":
7998
+ case "outlined":
7999
+ case "bordered":
8000
+ return "outlined";
8001
+ case "tonal":
8002
+ return "tonal";
8003
+ case "elevated":
8004
+ return "elevated";
8005
+ case "glass":
8006
+ return "glass";
8007
+ default:
8008
+ return "text";
8009
+ }
8010
+ }
7988
8011
 
7989
8012
  // ../../core/ts/src/widget-vocabulary.ts
7990
8013
  var WIDGET_FAMILIES = ["ios_home", "ios_lock", "android_home", "web_card", "ios_live_activity", "watch_complication", "car_list"];
@@ -13434,8 +13457,10 @@ export {
13434
13457
  APP_ID_PATTERN,
13435
13458
  AppRegistryClient,
13436
13459
  BASE44_ORIGINS,
13460
+ BUTTON_LEGACY_STYLES,
13437
13461
  BUTTON_MIN_HIT_TARGET,
13438
13462
  BUTTON_SIZES,
13463
+ BUTTON_VARIANTS,
13439
13464
  CHASSIS_GEOMETRY,
13440
13465
  CORE_COMPONENTS,
13441
13466
  DEFAULT_DISTRIBUTION,
@@ -13496,6 +13521,7 @@ export {
13496
13521
  buildPlayerPreviewUrl,
13497
13522
  buildTokenRegistry,
13498
13523
  buttonHitSlop,
13524
+ buttonVariant,
13499
13525
  chassisOuterSize,
13500
13526
  checkTierCaps,
13501
13527
  chooseCandidate,
@@ -836,6 +836,275 @@ function onlineProgramItem(program, commerceDisplayPrice) {
836
836
  return { reference: { kind: ONLINE_PROGRAM, id }, ...commerceDisplayPrice ? { commerceDisplayPrice } : {} };
837
837
  }
838
838
 
839
+ // ../../core/sdk/iap/src/wix-payments-wire.ts
840
+ function startPaymentCall(scope, wixTransactionId) {
841
+ return post(scope, "/payments/start", { appId: scope.binding.purchasesAppId, wixTransactionId });
842
+ }
843
+ function completePaymentCall(scope, signedTransaction) {
844
+ return post(scope, "/payments/complete", { appId: scope.binding.purchasesAppId, apple: { signedTransaction } });
845
+ }
846
+ function customerIdCall(scope) {
847
+ return get(scope, `/customer-id?appId=${encodeURIComponent(scope.binding.purchasesAppId)}`);
848
+ }
849
+ function paymentCall(scope, paymentId) {
850
+ return get(scope, `/payments/${encodeURIComponent(paymentId)}`);
851
+ }
852
+ function isRoutePrefix(prefix) {
853
+ return /^\/[A-Za-z0-9._~\-/]*[A-Za-z0-9._~-]$/.test(prefix);
854
+ }
855
+ function decodeStarted(raw, expected) {
856
+ if (!isObject3(raw) || !isStoreProductId(raw.storeProductId) || !isUUID(raw.customerId)) return null;
857
+ const payment = decodePayment(raw.payment, expected);
858
+ return payment && { payment, storeProductId: raw.storeProductId, customerId: raw.customerId };
859
+ }
860
+ function decodePaymentAnswer(raw, expected) {
861
+ return isObject3(raw) ? decodePayment(raw.payment, expected) : null;
862
+ }
863
+ function decodeCustomerId(raw) {
864
+ return isObject3(raw) && isUUID(raw.customerId) ? raw.customerId : null;
865
+ }
866
+ function decodePayment(raw, expected) {
867
+ if (!isObject3(raw) || !hasPaymentIds(raw) || !echoes(raw, expected) || !hasValidOptionals(raw)) return null;
868
+ const status = STATUSES[String(raw.status)];
869
+ return status ? toPayment(raw, status) : null;
870
+ }
871
+ function hasPaymentIds(raw) {
872
+ return isUUID(raw.id) && isUUID(raw.appId) && isUUID(raw.memberId) && isUUID(raw.wixTransactionId);
873
+ }
874
+ function echoes(raw, expected) {
875
+ return sameUUID(raw.appId, expected.appId) && (expected.memberId === null || sameUUID(raw.memberId, expected.memberId)) && (expected.paymentId === void 0 || sameUUID(raw.id, expected.paymentId)) && (expected.wixTransactionId === void 0 || sameUUID(raw.wixTransactionId, expected.wixTransactionId));
876
+ }
877
+ function hasValidOptionals(raw) {
878
+ return (raw.appProductId === void 0 || isStoreProductId(raw.appProductId)) && (raw.purchaseTransactionId === void 0 || isUUID(raw.purchaseTransactionId)) && TIMESTAMPS.every((field) => raw[field] === void 0 || isTimestamp(raw[field]));
879
+ }
880
+ function toPayment(raw, status) {
881
+ const optional = {
882
+ appProductId: raw.appProductId,
883
+ cancelReason: CANCEL_REASONS[String(raw.cancelReason)],
884
+ purchaseTransactionId: raw.purchaseTransactionId,
885
+ expiresDate: raw.expiresDate,
886
+ approvedDate: raw.approvedDate,
887
+ canceledDate: raw.canceledDate,
888
+ refundedDate: raw.refundedDate
889
+ };
890
+ const ids = { paymentId: raw.id, appId: raw.appId, memberId: raw.memberId, wixTransactionId: raw.wixTransactionId };
891
+ return { ...ids, status, ...withoutUndefined(optional) };
892
+ }
893
+ function classifyFailure(error, operation, codes) {
894
+ const message = messageOf(error);
895
+ if (BRIDGE_REFUSAL.test(message)) return failure(operation, "notEnabled");
896
+ if (PRINCIPAL_CHANGED.test(message)) return failure(operation, "sessionChanged");
897
+ const http = /^HTTP (\d{3})(?: \[([^\]]+)\])?:/.exec(message);
898
+ if (!http) return failure(operation, "unavailable");
899
+ return classifyHttp({ operation, codes, httpStatus: Number(http[1]), code: http[2] ?? "" });
900
+ }
901
+ function failure(operation, kind) {
902
+ return { status: "failed", operation, kind };
903
+ }
904
+ function classifyHttp(refusal) {
905
+ const { operation, codes, httpStatus, code } = refusal;
906
+ if (code === "PRINCIPAL_CHANGED") return failure(operation, "sessionChanged");
907
+ if (isOneOf(codes, code)) return { status: "failed", operation, kind: "application", code, httpStatus };
908
+ return { status: "failed", operation, kind: kindForStatus(httpStatus, code), httpStatus };
909
+ }
910
+ function kindForStatus(httpStatus, code) {
911
+ if (code === "UNAVAILABLE" || httpStatus === 408 || httpStatus === 429 || httpStatus >= 500) return "unavailable";
912
+ if (httpStatus === 401 || code === "UNAUTHENTICATED") return "authRequired";
913
+ if (httpStatus === 403 || code === "PERMISSION_DENIED") return "notPermitted";
914
+ return "unrecognized";
915
+ }
916
+ function post(scope, route, body) {
917
+ return { method: "POST", path: `${scope.prefix}${route}`, body, headers: siteHeaders(scope.binding) };
918
+ }
919
+ function get(scope, route) {
920
+ return { method: "GET", path: `${scope.prefix}${route}`, headers: siteHeaders(scope.binding) };
921
+ }
922
+ function siteHeaders(binding) {
923
+ return { "wix-site-id": binding.siteId };
924
+ }
925
+ function messageOf(error) {
926
+ const message = error?.message;
927
+ return typeof message === "string" ? message : "";
928
+ }
929
+ function withoutUndefined(value) {
930
+ const kept = {};
931
+ for (const key of Object.keys(value)) {
932
+ if (value[key] !== void 0) kept[key] = value[key];
933
+ }
934
+ return kept;
935
+ }
936
+ function isOneOf(codes, code) {
937
+ return codes.includes(code);
938
+ }
939
+ function isObject3(value) {
940
+ return value !== null && typeof value === "object" && !Array.isArray(value);
941
+ }
942
+ function isUUID(value) {
943
+ return typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
944
+ }
945
+ function sameUUID(value, expected) {
946
+ return isUUID(value) && value.toLowerCase() === expected.toLowerCase();
947
+ }
948
+ function isStoreProductId(value) {
949
+ return typeof value === "string" && value.length > 0 && value.length <= 255;
950
+ }
951
+ function isTimestamp(value) {
952
+ return typeof value === "string" && !Number.isNaN(Date.parse(value));
953
+ }
954
+ var STATUSES = {
955
+ PENDING: "pending",
956
+ APPROVING: "approving",
957
+ APPROVED: "approved",
958
+ CANCELING: "canceling",
959
+ CANCELED: "canceled",
960
+ REFUNDING: "refunding",
961
+ REFUNDED: "refunded"
962
+ };
963
+ var CANCEL_REASONS = { EXPIRED: "expired", REJECTED: "rejected" };
964
+ var TIMESTAMPS = ["createdDate", "updatedDate", "expiresDate", "approvedDate", "canceledDate", "refundedDate"];
965
+ var BRIDGE_REFUSAL = /^(wixApi not enabled|capability wix_api not allowed)\b|^NotInstalled\(\)$/;
966
+ var PRINCIPAL_CHANGED = /^PRINCIPAL_CHANGED\b/;
967
+
968
+ // ../../core/sdk/iap/src/wix-payments.ts
969
+ function createWixIapClient(deps) {
970
+ function startPayment(input) {
971
+ if (!isUUID(input.wixTransactionId)) return Promise.resolve(failure("startPayment", "invalidArgument"));
972
+ return run({
973
+ operation: "startPayment",
974
+ codes: START_PAYMENT_CODES,
975
+ request: (scope) => startPaymentCall(scope, input.wixTransactionId),
976
+ decode: (raw, scope) => {
977
+ const started = decodeStarted(raw, { ...expectationOf(scope), wixTransactionId: input.wixTransactionId });
978
+ return started && { status: "started", ...started };
979
+ }
980
+ });
981
+ }
982
+ function completePayment(transaction) {
983
+ const refusal = refuseProof(transaction);
984
+ if (refusal) return Promise.resolve(refusal);
985
+ return run({
986
+ operation: "completePayment",
987
+ codes: COMPLETE_PAYMENT_CODES,
988
+ request: (scope) => completePaymentCall(scope, transaction.signedTransaction),
989
+ decode: (raw, scope) => {
990
+ const payment = decodePaymentAnswer(raw, expectationOf(scope));
991
+ return payment && { status: "matched", payment };
992
+ }
993
+ });
994
+ }
995
+ function getCustomerId() {
996
+ return run({
997
+ operation: "getCustomerId",
998
+ codes: GET_CUSTOMER_ID_CODES,
999
+ request: customerIdCall,
1000
+ decode: (raw) => {
1001
+ const customerId = decodeCustomerId(raw);
1002
+ return customerId ? { status: "found", customerId } : null;
1003
+ }
1004
+ });
1005
+ }
1006
+ function getPayment(input) {
1007
+ if (!isUUID(input.paymentId)) return Promise.resolve(failure("getPayment", "invalidArgument"));
1008
+ return run({
1009
+ operation: "getPayment",
1010
+ codes: GET_PAYMENT_CODES,
1011
+ request: (scope) => paymentCall(scope, input.paymentId),
1012
+ decode: (raw, scope) => {
1013
+ const payment = decodePaymentAnswer(raw, { ...expectationOf(scope), paymentId: input.paymentId });
1014
+ return payment && { status: "found", payment };
1015
+ }
1016
+ });
1017
+ }
1018
+ async function run(spec) {
1019
+ const scope = await resolveScope(deps.session.current(), spec.operation);
1020
+ if ("failure" in scope) return scope.failure;
1021
+ const sent = await send(scope, spec);
1022
+ if ("failure" in sent) return sent.failure;
1023
+ return spec.decode(sent.answer, scope) ?? failure(spec.operation, "invalidResponse");
1024
+ }
1025
+ async function resolveScope(session, operation) {
1026
+ if (session.kind !== "member") return refused(operation, "authRequired");
1027
+ if (!isRoutePrefix(deps.route.prefix)) return refused(operation, "notProvisioned");
1028
+ const binding = await read(() => deps.binding.current(), operation);
1029
+ if ("failure" in binding) return binding;
1030
+ if (!binding.value || !isBindingFor(binding.value, deps.host)) return refused(operation, "notProvisioned");
1031
+ const member = await expectedMember(session, operation);
1032
+ if ("failure" in member) return member;
1033
+ return { session, binding: binding.value, prefix: deps.route.prefix, memberId: member.memberId };
1034
+ }
1035
+ async function expectedMember(session, operation) {
1036
+ const identity = deps.identity;
1037
+ if (!identity) return { memberId: null };
1038
+ const memberId = await read(() => identity.memberId(session), operation);
1039
+ if ("failure" in memberId) return memberId;
1040
+ return memberId.value ? { memberId: memberId.value } : refused(operation, "authRequired");
1041
+ }
1042
+ async function send(scope, spec) {
1043
+ const transport = deps.transport ?? bridgeTransport();
1044
+ if (!transport) return refused(spec.operation, "notEnabled");
1045
+ if (!isCurrent(scope.session)) return refused(spec.operation, "sessionChanged");
1046
+ const outcome = await attempt(transport, spec.request(scope), spec);
1047
+ return isCurrent(scope.session) ? outcome : refused(spec.operation, "sessionChanged");
1048
+ }
1049
+ function isCurrent(session) {
1050
+ return deps.session.current().generation === session.generation;
1051
+ }
1052
+ return { startPayment, completePayment, getCustomerId, getPayment };
1053
+ }
1054
+ async function attempt(transport, call, spec) {
1055
+ try {
1056
+ return { answer: await transport.call(call.method, call.path, call.body, call.headers) };
1057
+ } catch (error) {
1058
+ return { failure: classifyFailure(error, spec.operation, spec.codes) };
1059
+ }
1060
+ }
1061
+ async function read(call, operation) {
1062
+ try {
1063
+ return { value: await call() };
1064
+ } catch (error) {
1065
+ return { failure: classifyFailure(error, operation, []) };
1066
+ }
1067
+ }
1068
+ function refused(operation, kind) {
1069
+ return { failure: failure(operation, kind) };
1070
+ }
1071
+ function expectationOf(scope) {
1072
+ return { appId: scope.binding.purchasesAppId, memberId: scope.memberId };
1073
+ }
1074
+ function refuseProof(transaction) {
1075
+ if (transaction.environment !== "production" && transaction.environment !== "sandbox") return failure("completePayment", "environmentUnsupported");
1076
+ const signed = transaction.signedTransaction;
1077
+ return typeof signed === "string" && signed.length > 0 && signed.length <= MAX_SIGNED_TRANSACTION ? null : failure("completePayment", "invalidArgument");
1078
+ }
1079
+ function isBindingFor(binding, host) {
1080
+ return binding.himalayaAppId === host.appId && binding.bundleId === host.bundleId && binding.siteId === host.siteId;
1081
+ }
1082
+ function bridgeTransport() {
1083
+ const himalaya = globalThis.himalaya;
1084
+ const bridge = himalaya ? himalaya.wixApi : void 0;
1085
+ return typeof bridge?.call === "function" ? bridge : void 0;
1086
+ }
1087
+ var MAX_SIGNED_TRANSACTION = 2e4;
1088
+ var START_PAYMENT_CODES = [
1089
+ "NOT_PENDING",
1090
+ "WRONG_PAYMENT_METHOD",
1091
+ "NOT_ORDER_BUYER",
1092
+ "UNSUPPORTED_ORDER",
1093
+ "PRODUCT_NOT_AVAILABLE",
1094
+ "ALREADY_OWNED"
1095
+ ];
1096
+ var COMPLETE_PAYMENT_CODES = [
1097
+ "INVALID_PURCHASE",
1098
+ "OWNED_BY_ANOTHER_CUSTOMER",
1099
+ "PURCHASE_REVOKED",
1100
+ "NOT_PURCHASED",
1101
+ "ZERO_PRICE",
1102
+ "NO_MATCHING_PAYMENT",
1103
+ "APP_NOT_CONFIGURED"
1104
+ ];
1105
+ var GET_CUSTOMER_ID_CODES = ["APP_NOT_CONFIGURED"];
1106
+ var GET_PAYMENT_CODES = ["NOT_FOUND"];
1107
+
839
1108
  // ../../core/sdk/iap/src/index.ts
840
1109
  async function getPaywallConfig() {
841
1110
  const r = await dispatch("capability.iap.getPaywallConfig");
@@ -883,7 +1152,7 @@ function normalizeStatus(s) {
883
1152
  }
884
1153
  var version = 2;
885
1154
  async function purchaseForVerification(input) {
886
- if (!nonempty2(input?.productId) || !isUUID(input?.appAccountToken)) return failure("invalidArgument");
1155
+ if (!nonempty2(input?.productId) || !isUUID2(input?.appAccountToken)) return failure2("invalidArgument");
887
1156
  const result = await managedDispatch(() => dispatch("capability.iap.purchaseForVerification", input));
888
1157
  if (result?.status === "purchased" && isAppleTransaction(result.transaction)) {
889
1158
  return { status: "purchased", transaction: decodeTransaction(result.transaction) };
@@ -899,31 +1168,31 @@ async function getUnfinishedTransactions() {
899
1168
  return decodeFailure(result);
900
1169
  }
901
1170
  async function finishTransaction(input) {
902
- if (!nonempty2(input?.transactionId)) return failure("invalidArgument");
1171
+ if (!nonempty2(input?.transactionId)) return failure2("invalidArgument");
903
1172
  const result = await managedDispatch(() => dispatch("capability.iap.finishTransaction", input));
904
1173
  if (result?.status === "finished" || result?.status === "notFound") return { status: result.status };
905
1174
  return decodeFailure(result);
906
1175
  }
907
1176
  var appleManagedStore = { purchaseForVerification, getUnfinishedTransactions, finishTransaction };
908
1177
  var transactionErrors = /* @__PURE__ */ new Set(["unsupported", "unavailable", "invalidArgument", "invalidResponse", "notEnabled", "unsupportedProductType", "unknownProduct", "verificationFailed", "persistenceFailed", "ownershipConflict", "storeError", "busy"]);
909
- var failure = (code) => ({ status: "failed", code });
1178
+ var failure2 = (code) => ({ status: "failed", code });
910
1179
  var nonempty2 = (value) => typeof value === "string" && value.trim().length > 0;
911
- var isUUID = (value) => typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value) && value.length === 36;
912
- var isObject3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
1180
+ var isUUID2 = (value) => typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value) && value.length === 36;
1181
+ var isObject4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
913
1182
  async function managedDispatch(invoke) {
914
1183
  try {
915
1184
  const value = await invoke();
916
- return isObject3(value) ? value : null;
1185
+ return isObject4(value) ? value : null;
917
1186
  } catch {
918
- return failure("unavailable");
1187
+ return failure2("unavailable");
919
1188
  }
920
1189
  }
921
1190
  function decodeFailure(value) {
922
- return value?.status === "failed" && transactionErrors.has(value.code) ? failure(value.code) : failure("invalidResponse");
1191
+ return value?.status === "failed" && transactionErrors.has(value.code) ? failure2(value.code) : failure2("invalidResponse");
923
1192
  }
924
1193
  function isAppleTransaction(value) {
925
- if (!isObject3(value)) return false;
926
- return value.store === "apple" && typeof value.signedTransaction === "string" && /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value.signedTransaction) && nonempty2(value.transactionId) && nonempty2(value.originalTransactionId) && nonempty2(value.productId) && (value.appAccountToken === null || isUUID(value.appAccountToken)) && ["production", "sandbox", "xcode", "unknown"].includes(value.environment);
1194
+ if (!isObject4(value)) return false;
1195
+ return value.store === "apple" && typeof value.signedTransaction === "string" && /^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(value.signedTransaction) && nonempty2(value.transactionId) && nonempty2(value.originalTransactionId) && nonempty2(value.productId) && (value.appAccountToken === null || isUUID2(value.appAccountToken)) && ["production", "sandbox", "xcode", "unknown"].includes(value.environment);
927
1196
  }
928
1197
  function decodeTransaction(value) {
929
1198
  const { store, signedTransaction, transactionId, originalTransactionId, productId, appAccountToken, environment } = value;
@@ -938,6 +1207,7 @@ export {
938
1207
  createIapCatalogPricing,
939
1208
  createPricingController,
940
1209
  createPurchaseCoordinator,
1210
+ createWixIapClient,
941
1211
  entitlements,
942
1212
  finishTransaction,
943
1213
  getPaywallConfig,