@whop/elements 0.0.0 → 1.0.0-beta.1

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/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` (or a `checkoutConfiguration` you authored) 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.1",
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": "31ffc5bac2c4d883453f2e655b2c659c727d500b41c4cfae65e66e08988a9424"
10
85
  }