@whop/elements 0.0.0 → 1.0.0-beta.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.
package/checkout.d.cts ADDED
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Options for `whop.checkout.create()`: the controller's props plus its `on<Event>` callbacks. In React, these are the `<Checkout>` component's props.
3
+ * @example
4
+ * ```ts
5
+ * import { loadWhop } from "@whop/elements";
6
+ *
7
+ * const whop = (await loadWhop())({ locale: "en" });
8
+ * const checkout = whop.checkout.create({}); // options: props + on<Event> callbacks
9
+ * ```
10
+ * @see https://docs.whop.com/elements/latest/checkout/overview
11
+ */
12
+ export interface CheckoutOptions {
13
+ /**
14
+ * Existing plan ID, prefixed `plan_`. The element creates a checkout session for it, and the plan defines the price; nothing about amounts can be asserted client-side. Every checkout names one — omitting it refuses loudly at mount. Set at create only: the session is minted from it, and changing it later refuses.
15
+ */
16
+ plan?: string;
17
+ /**
18
+ * How many units to purchase. Plans that disallow multiples refuse values above 1. Set at create only: the session is minted with it, and changing it later refuses. @default 1
19
+ */
20
+ quantity?: number;
21
+ /**
22
+ * A promo code to apply before the buyer ever sees the price — the discount is on the first quote, and the buyer can still change or remove it. Pass the code a marketing link carried: a code that has expired or was never valid opens the checkout at full price with the reason on the promo row, never a checkout that will not open. Set at create only.
23
+ */
24
+ promoCode?: string;
25
+ /**
26
+ * The affiliate this checkout is attributed to. Set at create only.
27
+ */
28
+ affiliateCode?: string;
29
+ /**
30
+ * Where this sale came from, for the account's reporting: the campaign parameters of the link the buyer arrived on (`utmSource`, `utmMedium`, `utmCampaign`, `utmTerm`, `utmContent`, a Whop `trackingLinkId`, a `funnelId`, and your own `source`). Everything here is recorded against the order and is never shown to the buyer. Set at create only.
31
+ */
32
+ attribution?: CheckoutAttributionInput;
33
+ /**
34
+ * Your own key/value pairs to record against the order and read back on the payment — order IDs, cart IDs, or anything you reconcile against. Up to 40 string pairs. Set at create only.
35
+ */
36
+ metadata?: Record<string, string>;
37
+ /**
38
+ * Where the buyer lands after an off-site payment step. Https-only (http for localhost). Set at create only.
39
+ */
40
+ returnUrl?: string;
41
+ /**
42
+ * Runs when the grouped loading state changes. The value is `true` while any mounted element is still loading.
43
+ */
44
+ onLoadingChange?: ((loading: boolean) => void);
45
+ /**
46
+ * Visual customization for this group's elements. Overrides the global `WhopElements({ appearance })`. Change it live with `update({ appearance })`.
47
+ */
48
+ appearance?: import("./_framework.js").Appearance;
49
+ /**
50
+ * Locale for this group's element UI text. Set it to one of the app's built locales to override the global configuration. Any other value falls back to the default locale.
51
+ */
52
+ locale?: import("./_framework.js").WhopElementsLocale;
53
+ }
54
+
55
+ /**
56
+ * Consumer props for the "checkout" element. Set at create (or as `<CheckoutElement />` JSX props), and updatable live via `update()`.
57
+ * @see https://docs.whop.com/elements/latest/checkout/checkout
58
+ */
59
+ export interface CheckoutElementProps {}
60
+
61
+ /**
62
+ * The live handle for a mounted "checkout" element. Returned by `create("checkout")`; in React, the component's `ref`.
63
+ * @see https://docs.whop.com/elements/latest/checkout/checkout
64
+ */
65
+ export interface CheckoutElementHandle {
66
+ /**
67
+ * Mounts the element in `target` and starts loading. React components mount themselves.
68
+ */
69
+ mount: (target: string | HTMLElement) => void;
70
+ /**
71
+ * Removes the element and releases its frame and subscriptions. You can call it more than once. React removes the element automatically.
72
+ */
73
+ destroy: () => void;
74
+ /**
75
+ * Merges new props into the mounted element. In React, change the component props instead.
76
+ */
77
+ update: (options: Partial<CheckoutElementProps>) => void;
78
+ }
79
+
80
+ /**
81
+ * Options for `create("checkout")`: the consumer props plus event callbacks and lifecycle hooks.
82
+ * @example
83
+ * ```ts
84
+ * const checkout = checkout.create("checkout", {}); // this interface: props + on<Event> callbacks
85
+ * checkout.mount("#checkout-checkout");
86
+ * ```
87
+ * @see https://docs.whop.com/elements/latest/checkout/checkout
88
+ */
89
+ export interface CheckoutElementCreateOptions {
90
+ /**
91
+ * Runs after the loading skeleton first paints and before `onReady`.
92
+ */
93
+ onLoaderStart?: (() => void);
94
+ /**
95
+ * Runs after the element's first complete paint.
96
+ */
97
+ onReady?: (() => void);
98
+ /**
99
+ * Runs when the element fails to load or crashes. The fallback remains visible. Use `code` for programmatic handling. `sourceKey` identifies a failed host-state source.
100
+ */
101
+ onError?: ((e: { message: string; code?: string | undefined; sourceKey?: string | undefined; }) => void);
102
+ }
103
+
104
+ /**
105
+ * The Checkout handle, returned by `whop.checkout.create()` (React: `useCheckout()`). Mounts the elements and carries the controller's actions.
106
+ * @see https://docs.whop.com/elements/latest/checkout/overview
107
+ */
108
+ export interface CheckoutHandle {
109
+ /**
110
+ * The full checkout surface — order summary with the live quote, promo code entry, the currency the buyer pays in, everything this checkout has to collect from the buyer, the composed payment methods surface, and the pay flow. What it collects is whatever the account owner set up (email, their own questions, a phone number, a shipping address for physical goods, an explicit agreement to their terms), rendered together on one screen in the order they chose — so an account owner who starts asking for something new needs no change here. Renders the whole purchase; the checkout controller owns the session and the credential. After a payment that needs an off-site step, this same surface renders the outcome the server reports when the buyer comes back.
111
+ * Exclusive slot `entry`. Mount exactly one of: checkout.
112
+ */
113
+ create(name: "checkout", options?: CheckoutElementCreateOptions): CheckoutElementHandle;
114
+ /**
115
+ * Merges new handle options into every mounted element. In React, change the namespace props instead.
116
+ */
117
+ update(options: Partial<CheckoutOptions>): void;
118
+ }
119
+
120
+ /**
121
+ * Checkout's static actions, callable with nothing mounted: `whop.checkout.<method>()` (React: `useWhop().checkout.<method>()`).
122
+ * @see https://docs.whop.com/elements/latest/checkout/overview
123
+ */
124
+ export interface CheckoutStatics {}
125
+
126
+ /**
127
+ * Checkout attribution recorded with the session. The element maps these fields to `POST /api/v1/checkout_sessions`; empty values are omitted, and `country` is resolved by the API.
128
+ * Declared from the app's `CheckoutAttributionInput`, referenced by a host-capability surface.
129
+ */
130
+ export interface CheckoutAttributionInput {
131
+ utmSource?: string | undefined;
132
+ utmMedium?: string | undefined;
133
+ utmCampaign?: string | undefined;
134
+ utmTerm?: string | undefined;
135
+ utmContent?: string | undefined;
136
+ trackingLinkId?: string | undefined;
137
+ funnelId?: string | undefined;
138
+ source?: string | undefined;
139
+ }
package/checkout.d.ts ADDED
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Options for `whop.checkout.create()`: the controller's props plus its `on<Event>` callbacks. In React, these are the `<Checkout>` component's props.
3
+ * @example
4
+ * ```ts
5
+ * import { loadWhop } from "@whop/elements";
6
+ *
7
+ * const whop = (await loadWhop())({ locale: "en" });
8
+ * const checkout = whop.checkout.create({}); // options: props + on<Event> callbacks
9
+ * ```
10
+ * @see https://docs.whop.com/elements/latest/checkout/overview
11
+ */
12
+ export interface CheckoutOptions {
13
+ /**
14
+ * Existing plan ID, prefixed `plan_`. The element creates a checkout session for it, and the plan defines the price; nothing about amounts can be asserted client-side. Every checkout names one — omitting it refuses loudly at mount. Set at create only: the session is minted from it, and changing it later refuses.
15
+ */
16
+ plan?: string;
17
+ /**
18
+ * How many units to purchase. Plans that disallow multiples refuse values above 1. Set at create only: the session is minted with it, and changing it later refuses. @default 1
19
+ */
20
+ quantity?: number;
21
+ /**
22
+ * A promo code to apply before the buyer ever sees the price — the discount is on the first quote, and the buyer can still change or remove it. Pass the code a marketing link carried: a code that has expired or was never valid opens the checkout at full price with the reason on the promo row, never a checkout that will not open. Set at create only.
23
+ */
24
+ promoCode?: string;
25
+ /**
26
+ * The affiliate this checkout is attributed to. Set at create only.
27
+ */
28
+ affiliateCode?: string;
29
+ /**
30
+ * Where this sale came from, for the account's reporting: the campaign parameters of the link the buyer arrived on (`utmSource`, `utmMedium`, `utmCampaign`, `utmTerm`, `utmContent`, a Whop `trackingLinkId`, a `funnelId`, and your own `source`). Everything here is recorded against the order and is never shown to the buyer. Set at create only.
31
+ */
32
+ attribution?: CheckoutAttributionInput;
33
+ /**
34
+ * Your own key/value pairs to record against the order and read back on the payment — order IDs, cart IDs, or anything you reconcile against. Up to 40 string pairs. Set at create only.
35
+ */
36
+ metadata?: Record<string, string>;
37
+ /**
38
+ * Where the buyer lands after an off-site payment step. Https-only (http for localhost). Set at create only.
39
+ */
40
+ returnUrl?: string;
41
+ /**
42
+ * Runs when the grouped loading state changes. The value is `true` while any mounted element is still loading.
43
+ */
44
+ onLoadingChange?: ((loading: boolean) => void);
45
+ /**
46
+ * Visual customization for this group's elements. Overrides the global `WhopElements({ appearance })`. Change it live with `update({ appearance })`.
47
+ */
48
+ appearance?: import("./_framework.js").Appearance;
49
+ /**
50
+ * Locale for this group's element UI text. Set it to one of the app's built locales to override the global configuration. Any other value falls back to the default locale.
51
+ */
52
+ locale?: import("./_framework.js").WhopElementsLocale;
53
+ }
54
+
55
+ /**
56
+ * Consumer props for the "checkout" element. Set at create (or as `<CheckoutElement />` JSX props), and updatable live via `update()`.
57
+ * @see https://docs.whop.com/elements/latest/checkout/checkout
58
+ */
59
+ export interface CheckoutElementProps {}
60
+
61
+ /**
62
+ * The live handle for a mounted "checkout" element. Returned by `create("checkout")`; in React, the component's `ref`.
63
+ * @see https://docs.whop.com/elements/latest/checkout/checkout
64
+ */
65
+ export interface CheckoutElementHandle {
66
+ /**
67
+ * Mounts the element in `target` and starts loading. React components mount themselves.
68
+ */
69
+ mount: (target: string | HTMLElement) => void;
70
+ /**
71
+ * Removes the element and releases its frame and subscriptions. You can call it more than once. React removes the element automatically.
72
+ */
73
+ destroy: () => void;
74
+ /**
75
+ * Merges new props into the mounted element. In React, change the component props instead.
76
+ */
77
+ update: (options: Partial<CheckoutElementProps>) => void;
78
+ }
79
+
80
+ /**
81
+ * Options for `create("checkout")`: the consumer props plus event callbacks and lifecycle hooks.
82
+ * @example
83
+ * ```ts
84
+ * const checkout = checkout.create("checkout", {}); // this interface: props + on<Event> callbacks
85
+ * checkout.mount("#checkout-checkout");
86
+ * ```
87
+ * @see https://docs.whop.com/elements/latest/checkout/checkout
88
+ */
89
+ export interface CheckoutElementCreateOptions {
90
+ /**
91
+ * Runs after the loading skeleton first paints and before `onReady`.
92
+ */
93
+ onLoaderStart?: (() => void);
94
+ /**
95
+ * Runs after the element's first complete paint.
96
+ */
97
+ onReady?: (() => void);
98
+ /**
99
+ * Runs when the element fails to load or crashes. The fallback remains visible. Use `code` for programmatic handling. `sourceKey` identifies a failed host-state source.
100
+ */
101
+ onError?: ((e: { message: string; code?: string | undefined; sourceKey?: string | undefined; }) => void);
102
+ }
103
+
104
+ /**
105
+ * The Checkout handle, returned by `whop.checkout.create()` (React: `useCheckout()`). Mounts the elements and carries the controller's actions.
106
+ * @see https://docs.whop.com/elements/latest/checkout/overview
107
+ */
108
+ export interface CheckoutHandle {
109
+ /**
110
+ * The full checkout surface — order summary with the live quote, promo code entry, the currency the buyer pays in, everything this checkout has to collect from the buyer, the composed payment methods surface, and the pay flow. What it collects is whatever the account owner set up (email, their own questions, a phone number, a shipping address for physical goods, an explicit agreement to their terms), rendered together on one screen in the order they chose — so an account owner who starts asking for something new needs no change here. Renders the whole purchase; the checkout controller owns the session and the credential. After a payment that needs an off-site step, this same surface renders the outcome the server reports when the buyer comes back.
111
+ * Exclusive slot `entry`. Mount exactly one of: checkout.
112
+ */
113
+ create(name: "checkout", options?: CheckoutElementCreateOptions): CheckoutElementHandle;
114
+ /**
115
+ * Merges new handle options into every mounted element. In React, change the namespace props instead.
116
+ */
117
+ update(options: Partial<CheckoutOptions>): void;
118
+ }
119
+
120
+ /**
121
+ * Checkout's static actions, callable with nothing mounted: `whop.checkout.<method>()` (React: `useWhop().checkout.<method>()`).
122
+ * @see https://docs.whop.com/elements/latest/checkout/overview
123
+ */
124
+ export interface CheckoutStatics {}
125
+
126
+ /**
127
+ * Checkout attribution recorded with the session. The element maps these fields to `POST /api/v1/checkout_sessions`; empty values are omitted, and `country` is resolved by the API.
128
+ * Declared from the app's `CheckoutAttributionInput`, referenced by a host-capability surface.
129
+ */
130
+ export interface CheckoutAttributionInput {
131
+ utmSource?: string | undefined;
132
+ utmMedium?: string | undefined;
133
+ utmCampaign?: string | undefined;
134
+ utmTerm?: string | undefined;
135
+ utmContent?: string | undefined;
136
+ trackingLinkId?: string | undefined;
137
+ funnelId?: string | undefined;
138
+ source?: string | undefined;
139
+ }
package/index.cjs ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // ../../packages/elements-codegen/src/cli/build/npm-loader.ts
21
+ var npm_loader_exports = {};
22
+ __export(npm_loader_exports, {
23
+ SDK_URL: () => SDK_URL,
24
+ WHOP_ELEMENTS_LOCALES: () => WHOP_ELEMENTS_LOCALES,
25
+ loadWhop: () => loadWhop,
26
+ preloadHints: () => preloadHints
27
+ });
28
+ module.exports = __toCommonJS(npm_loader_exports);
29
+
30
+ // <define:__WHOP_ELEMENTS_LOCALES__>
31
+ var define_WHOP_ELEMENTS_LOCALES_default = ["en", "es", "zh", "nl", "pt", "de", "it", "fr", "ja", "pl", "tr"];
32
+
33
+ // ../../packages/elements-codegen/src/cli/build/npm-loader.ts
34
+ var ORIGIN = "https://js.whop.cloud";
35
+ var SDK_URL = "https://js.whop.cloud/elements/amber/elements.js";
36
+ var WHOP_ELEMENTS_LOCALES = define_WHOP_ELEMENTS_LOCALES_default;
37
+ function loadWhop() {
38
+ if (typeof window === "undefined") return Promise.reject(new Error("WhopElements requires a browser environment"));
39
+ const w = window;
40
+ if (w.WhopElements) return Promise.resolve(w.WhopElements);
41
+ let s = document.querySelector("script[data-whop-elements]");
42
+ const created = !s;
43
+ if (!s) {
44
+ s = document.createElement("script");
45
+ s.src = SDK_URL;
46
+ s.async = true;
47
+ s.setAttribute("data-whop-elements", "");
48
+ document.head.appendChild(s);
49
+ }
50
+ const script = s;
51
+ if (!script.__whopReady) {
52
+ script.__whopReady = new Promise((resolve, reject) => {
53
+ let timer = null;
54
+ function settle(fn, v) {
55
+ if (timer !== null) {
56
+ clearInterval(timer);
57
+ timer = null;
58
+ }
59
+ fn(v);
60
+ }
61
+ script.addEventListener("load", () => {
62
+ if (w.WhopElements) settle(resolve, w.WhopElements);
63
+ else settle(reject, new Error("WhopElements loaded but did not initialize"));
64
+ });
65
+ script.addEventListener("error", () => settle(reject, new Error("Failed to load " + SDK_URL)));
66
+ if (!created) {
67
+ let waited = 0;
68
+ timer = setInterval(() => {
69
+ if (w.WhopElements) {
70
+ settle(resolve, w.WhopElements);
71
+ return;
72
+ }
73
+ waited += 200;
74
+ if (waited >= 1e4) settle(reject, new Error("existing data-whop-elements script did not initialize within 10s \u2014 if its network load already failed before loadWhop() ran (check the console/CSP), no load/error event will ever fire on it"));
75
+ }, 200);
76
+ }
77
+ });
78
+ }
79
+ return script.__whopReady;
80
+ }
81
+ function preloadHints() {
82
+ return [
83
+ { rel: "preconnect", href: ORIGIN },
84
+ { rel: "preload", href: SDK_URL, as: "script" }
85
+ ];
86
+ }
package/index.d.cts ADDED
@@ -0,0 +1,61 @@
1
+ import type { FrameworkGlobals, WhopElementsLocale } from "./_framework.js";
2
+ import type { PaymentsHandle, PaymentsOptions, PaymentsStatics } from "./payments.js";
3
+ import type { CheckoutHandle, CheckoutOptions, CheckoutStatics } from "./checkout.js";
4
+ import type { AdsHandle, AdsOptions, AdsStatics } from "./ads.js";
5
+ import type { TrackingHandle, TrackingOptions, TrackingStatics } from "./tracking.js";
6
+ import type { WalletHandle, WalletOptions, WalletStatics } from "./wallet.js";
7
+ import type { WebsitesHandle, WebsitesOptions, WebsitesStatics } from "./websites.js";
8
+
9
+ /** Global configuration for `WhopElements(config)`, inherited by every namespace handle (`appearance`, `locale`, …). */
10
+ export interface WhopGlobalConfig extends FrameworkGlobals {}
11
+
12
+ /** The configured instance: one accessor per namespace, each carrying `create()` plus that namespace's static actions. */
13
+ export interface Whop {
14
+ /**
15
+ * Collect a payment from a `plan_` ID or inline currency and amount. Mount PaymentElement, CardElement, or CardFields, then call `payments.createConfirmationToken` with billing details. Wallet selections open their sheet automatically. Confirm the token server-side, then pass the payment's `client_secret` to `handleNextAction` for any pending step.
16
+ */
17
+ payments: { create(options: PaymentsOptions): PaymentsHandle } & PaymentsStatics;
18
+ /**
19
+ * Drives a full hosted checkout for one plan — price summary, promo codes, the currency the buyer pays in, and the whole payment collection surface (the payments elements, composed inside) — against the Whop checkout sessions API. Mount it with a `plan` and the element opens the checkout session itself; the session credential never leaves the element. The buyer pays inside the element, and a finished checkout redirects the current tab to `returnUrl`, including the page that contains the element. Fulfill from webhooks rather than a browser callback. Without a `returnUrl`, the buyer rests on the element’s own success face. The element automatically drives an off-site payment step, such as 3DS or a bank page. On whop.com, it brings the buyer back into the restored checkout; in an embed, the buyer returns to the same `returnUrl`. A failed payment reopens the same checkout with the reason shown, so the buyer can pay again. Every option is set at creation: the element mints a checkout session from these values when it mounts. Changing one later with `update()` or new React props fails instead of changing the existing order. Mount a new checkout to change the purchase.
20
+ */
21
+ checkout: { create(options: CheckoutOptions): CheckoutHandle } & CheckoutStatics;
22
+ /**
23
+ * An advertising account. Scope it to a Whop account with `accountId` — the ad account underneath is assigned server-side and never surfaces here — then mount `reporting` for what the account spent and what came back, or `campaign-creator` to build a campaign.
24
+ */
25
+ ads: { create(options: AdsOptions): AdsHandle } & AdsStatics;
26
+ /**
27
+ * An account's tracked audience: everyone its pixel has seen, and every event they performed. Scope it to an account with `accountId`, then mount `people`, `events`, or both — they read the same window and the same credit rule, so two surfaces side by side can never disagree about what they are showing. `links` wires their person links to your own pages.
28
+ */
29
+ tracking: { create(options: TrackingOptions): TrackingHandle } & TrackingStatics;
30
+ /**
31
+ * Drives an account's money surfaces. `deposit` returns live funding rails; `send` moves money to a recipient or creates a public claim link; `withdraw` collects a payout request; `balances` holds two faces — the holdings list, and the balance block drawing value over a window; `cards` lists issued cards; and `activity` lists ledger movements. Every surface but `deposit` can use the viewer's session when no token is provided.
32
+ */
33
+ wallet: { create(options: WalletOptions): WalletHandle } & WalletStatics;
34
+ /**
35
+ * An account's websites: every site built on whop.app plus every domain the Whop Pixel reports, with traffic and attributed revenue per domain. Mount `websites` and it lists them with visitors, page views, sales, revenue, trend, and most-viewed pages. Mount `pixel-setup` alongside it and a site whose pixel the wizard just proved live gets a waiting row automatically, because its first events take a few minutes to reach the stats API and the site would otherwise look lost — you wire nothing up for that, and the row is kept on your page so it is still there if the merchant reloads. Reading stats is privileged, so it needs an `accessToken` — except inside Whop's own app, where the viewer's session carries the read.
36
+ */
37
+ websites: { create(options: WebsitesOptions): WebsitesHandle } & WebsitesStatics;
38
+ }
39
+
40
+ /** The global `window.WhopElements`. Call it with the global config to get a `Whop` instance. */
41
+ export interface WhopConstructor {
42
+ (config?: WhopGlobalConfig): Whop;
43
+ }
44
+
45
+ /** The hosted SDK bundle `loadWhop()` loads. The URL carries the release train, so it follows this package's major. */
46
+ export declare const SDK_URL: string;
47
+
48
+ /** Load the hosted SDK: injects the `<script data-whop-elements>` tag once and resolves the global constructor. Safe to call any number of times: one script, one shared promise. */
49
+ export declare function loadWhop(): Promise<WhopConstructor>;
50
+
51
+ /** Resource hints (preconnect/preload) for the hosted SDK. Render them into `<head>` to start the fetch before `loadWhop()` runs. */
52
+ export declare function preloadHints(): { rel: string; href: string; as?: string }[];
53
+
54
+ /** The locales this app's elements are built with, the default locale first: exactly the values `locale` accepts. `includes()` accepts any string and narrows it to `WhopElementsLocale`, so use it to validate dynamic values; anything unlisted falls back to the default locale. */
55
+ export declare const WHOP_ELEMENTS_LOCALES: readonly WhopElementsLocale[] & {
56
+ includes(value: string, fromIndex?: number): value is WhopElementsLocale;
57
+ };
58
+
59
+ export type { WhopElementsLocale };
60
+
61
+ export type { Appearance, Theme, AccentColor, Classes, Variables, CSSProps, CSSValue, FrameworkGlobals } from "./_framework.js";
package/index.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ import type { FrameworkGlobals, WhopElementsLocale } from "./_framework.js";
2
+ import type { PaymentsHandle, PaymentsOptions, PaymentsStatics } from "./payments.js";
3
+ import type { CheckoutHandle, CheckoutOptions, CheckoutStatics } from "./checkout.js";
4
+ import type { AdsHandle, AdsOptions, AdsStatics } from "./ads.js";
5
+ import type { TrackingHandle, TrackingOptions, TrackingStatics } from "./tracking.js";
6
+ import type { WalletHandle, WalletOptions, WalletStatics } from "./wallet.js";
7
+ import type { WebsitesHandle, WebsitesOptions, WebsitesStatics } from "./websites.js";
8
+
9
+ /** Global configuration for `WhopElements(config)`, inherited by every namespace handle (`appearance`, `locale`, …). */
10
+ export interface WhopGlobalConfig extends FrameworkGlobals {}
11
+
12
+ /** The configured instance: one accessor per namespace, each carrying `create()` plus that namespace's static actions. */
13
+ export interface Whop {
14
+ /**
15
+ * Collect a payment from a `plan_` ID or inline currency and amount. Mount PaymentElement, CardElement, or CardFields, then call `payments.createConfirmationToken` with billing details. Wallet selections open their sheet automatically. Confirm the token server-side, then pass the payment's `client_secret` to `handleNextAction` for any pending step.
16
+ */
17
+ payments: { create(options: PaymentsOptions): PaymentsHandle } & PaymentsStatics;
18
+ /**
19
+ * Drives a full hosted checkout for one plan — price summary, promo codes, the currency the buyer pays in, and the whole payment collection surface (the payments elements, composed inside) — against the Whop checkout sessions API. Mount it with a `plan` and the element opens the checkout session itself; the session credential never leaves the element. The buyer pays inside the element, and a finished checkout redirects the current tab to `returnUrl`, including the page that contains the element. Fulfill from webhooks rather than a browser callback. Without a `returnUrl`, the buyer rests on the element’s own success face. The element automatically drives an off-site payment step, such as 3DS or a bank page. On whop.com, it brings the buyer back into the restored checkout; in an embed, the buyer returns to the same `returnUrl`. A failed payment reopens the same checkout with the reason shown, so the buyer can pay again. Every option is set at creation: the element mints a checkout session from these values when it mounts. Changing one later with `update()` or new React props fails instead of changing the existing order. Mount a new checkout to change the purchase.
20
+ */
21
+ checkout: { create(options: CheckoutOptions): CheckoutHandle } & CheckoutStatics;
22
+ /**
23
+ * An advertising account. Scope it to a Whop account with `accountId` — the ad account underneath is assigned server-side and never surfaces here — then mount `reporting` for what the account spent and what came back, or `campaign-creator` to build a campaign.
24
+ */
25
+ ads: { create(options: AdsOptions): AdsHandle } & AdsStatics;
26
+ /**
27
+ * An account's tracked audience: everyone its pixel has seen, and every event they performed. Scope it to an account with `accountId`, then mount `people`, `events`, or both — they read the same window and the same credit rule, so two surfaces side by side can never disagree about what they are showing. `links` wires their person links to your own pages.
28
+ */
29
+ tracking: { create(options: TrackingOptions): TrackingHandle } & TrackingStatics;
30
+ /**
31
+ * Drives an account's money surfaces. `deposit` returns live funding rails; `send` moves money to a recipient or creates a public claim link; `withdraw` collects a payout request; `balances` holds two faces — the holdings list, and the balance block drawing value over a window; `cards` lists issued cards; and `activity` lists ledger movements. Every surface but `deposit` can use the viewer's session when no token is provided.
32
+ */
33
+ wallet: { create(options: WalletOptions): WalletHandle } & WalletStatics;
34
+ /**
35
+ * An account's websites: every site built on whop.app plus every domain the Whop Pixel reports, with traffic and attributed revenue per domain. Mount `websites` and it lists them with visitors, page views, sales, revenue, trend, and most-viewed pages. Mount `pixel-setup` alongside it and a site whose pixel the wizard just proved live gets a waiting row automatically, because its first events take a few minutes to reach the stats API and the site would otherwise look lost — you wire nothing up for that, and the row is kept on your page so it is still there if the merchant reloads. Reading stats is privileged, so it needs an `accessToken` — except inside Whop's own app, where the viewer's session carries the read.
36
+ */
37
+ websites: { create(options: WebsitesOptions): WebsitesHandle } & WebsitesStatics;
38
+ }
39
+
40
+ /** The global `window.WhopElements`. Call it with the global config to get a `Whop` instance. */
41
+ export interface WhopConstructor {
42
+ (config?: WhopGlobalConfig): Whop;
43
+ }
44
+
45
+ /** The hosted SDK bundle `loadWhop()` loads. The URL carries the release train, so it follows this package's major. */
46
+ export declare const SDK_URL: string;
47
+
48
+ /** Load the hosted SDK: injects the `<script data-whop-elements>` tag once and resolves the global constructor. Safe to call any number of times: one script, one shared promise. */
49
+ export declare function loadWhop(): Promise<WhopConstructor>;
50
+
51
+ /** Resource hints (preconnect/preload) for the hosted SDK. Render them into `<head>` to start the fetch before `loadWhop()` runs. */
52
+ export declare function preloadHints(): { rel: string; href: string; as?: string }[];
53
+
54
+ /** The locales this app's elements are built with, the default locale first: exactly the values `locale` accepts. `includes()` accepts any string and narrows it to `WhopElementsLocale`, so use it to validate dynamic values; anything unlisted falls back to the default locale. */
55
+ export declare const WHOP_ELEMENTS_LOCALES: readonly WhopElementsLocale[] & {
56
+ includes(value: string, fromIndex?: number): value is WhopElementsLocale;
57
+ };
58
+
59
+ export type { WhopElementsLocale };
60
+
61
+ export type { Appearance, Theme, AccentColor, Classes, Variables, CSSProps, CSSValue, FrameworkGlobals } from "./_framework.js";
package/index.js ADDED
@@ -0,0 +1,63 @@
1
+ // <define:__WHOP_ELEMENTS_LOCALES__>
2
+ var define_WHOP_ELEMENTS_LOCALES_default = ["en", "es", "zh", "nl", "pt", "de", "it", "fr", "ja", "pl", "tr"];
3
+
4
+ // ../../packages/elements-codegen/src/cli/build/npm-loader.ts
5
+ var ORIGIN = "https://js.whop.cloud";
6
+ var SDK_URL = "https://js.whop.cloud/elements/amber/elements.js";
7
+ var WHOP_ELEMENTS_LOCALES = define_WHOP_ELEMENTS_LOCALES_default;
8
+ function loadWhop() {
9
+ if (typeof window === "undefined") return Promise.reject(new Error("WhopElements requires a browser environment"));
10
+ const w = window;
11
+ if (w.WhopElements) return Promise.resolve(w.WhopElements);
12
+ let s = document.querySelector("script[data-whop-elements]");
13
+ const created = !s;
14
+ if (!s) {
15
+ s = document.createElement("script");
16
+ s.src = SDK_URL;
17
+ s.async = true;
18
+ s.setAttribute("data-whop-elements", "");
19
+ document.head.appendChild(s);
20
+ }
21
+ const script = s;
22
+ if (!script.__whopReady) {
23
+ script.__whopReady = new Promise((resolve, reject) => {
24
+ let timer = null;
25
+ function settle(fn, v) {
26
+ if (timer !== null) {
27
+ clearInterval(timer);
28
+ timer = null;
29
+ }
30
+ fn(v);
31
+ }
32
+ script.addEventListener("load", () => {
33
+ if (w.WhopElements) settle(resolve, w.WhopElements);
34
+ else settle(reject, new Error("WhopElements loaded but did not initialize"));
35
+ });
36
+ script.addEventListener("error", () => settle(reject, new Error("Failed to load " + SDK_URL)));
37
+ if (!created) {
38
+ let waited = 0;
39
+ timer = setInterval(() => {
40
+ if (w.WhopElements) {
41
+ settle(resolve, w.WhopElements);
42
+ return;
43
+ }
44
+ waited += 200;
45
+ if (waited >= 1e4) settle(reject, new Error("existing data-whop-elements script did not initialize within 10s \u2014 if its network load already failed before loadWhop() ran (check the console/CSP), no load/error event will ever fire on it"));
46
+ }, 200);
47
+ }
48
+ });
49
+ }
50
+ return script.__whopReady;
51
+ }
52
+ function preloadHints() {
53
+ return [
54
+ { rel: "preconnect", href: ORIGIN },
55
+ { rel: "preload", href: SDK_URL, as: "script" }
56
+ ];
57
+ }
58
+ export {
59
+ SDK_URL,
60
+ WHOP_ELEMENTS_LOCALES,
61
+ loadWhop,
62
+ preloadHints
63
+ };
package/package.json CHANGED
@@ -1,10 +1,85 @@
1
1
  {
2
2
  "name": "@whop/elements",
3
- "version": "0.0.0",
3
+ "version": "1.0.0-beta.0",
4
4
  "description": "Whop Elements — vanilla-js loader + types. Loads the hosted SDK and exposes the typed WhopElements factory.",
5
+ "keywords": [
6
+ "checkout",
7
+ "elements",
8
+ "embed",
9
+ "payments",
10
+ "whop"
11
+ ],
12
+ "homepage": "https://docs.whop.com/elements/latest",
13
+ "bugs": "https://github.com/whopio/elements/issues",
5
14
  "license": "MIT",
6
- "publishConfig": {
7
- "access": "public",
8
- "tag": "stub"
9
- }
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/whopio/elements.git"
18
+ },
19
+ "type": "module",
20
+ "sideEffects": false,
21
+ "main": "./index.cjs",
22
+ "module": "./index.js",
23
+ "types": "./index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "import": {
27
+ "types": "./index.d.ts",
28
+ "default": "./index.js"
29
+ },
30
+ "require": {
31
+ "types": "./index.d.cts",
32
+ "default": "./index.cjs"
33
+ }
34
+ },
35
+ "./payments": {
36
+ "import": {
37
+ "types": "./payments.d.ts"
38
+ },
39
+ "require": {
40
+ "types": "./payments.d.cts"
41
+ }
42
+ },
43
+ "./checkout": {
44
+ "import": {
45
+ "types": "./checkout.d.ts"
46
+ },
47
+ "require": {
48
+ "types": "./checkout.d.cts"
49
+ }
50
+ },
51
+ "./ads": {
52
+ "import": {
53
+ "types": "./ads.d.ts"
54
+ },
55
+ "require": {
56
+ "types": "./ads.d.cts"
57
+ }
58
+ },
59
+ "./tracking": {
60
+ "import": {
61
+ "types": "./tracking.d.ts"
62
+ },
63
+ "require": {
64
+ "types": "./tracking.d.cts"
65
+ }
66
+ },
67
+ "./wallet": {
68
+ "import": {
69
+ "types": "./wallet.d.ts"
70
+ },
71
+ "require": {
72
+ "types": "./wallet.d.cts"
73
+ }
74
+ },
75
+ "./websites": {
76
+ "import": {
77
+ "types": "./websites.d.ts"
78
+ },
79
+ "require": {
80
+ "types": "./websites.d.cts"
81
+ }
82
+ }
83
+ },
84
+ "whopElementsApiHash": "6f00c3f1ef717575e3e56a392ace6dafc99c13d33b1dea86f12206ccdd4496a6"
10
85
  }