@whop/iframe 0.0.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/README.md +33 -0
- package/dist/chunk-DPDPUJJX.mjs +455 -0
- package/dist/chunk-DPDPUJJX.mjs.map +1 -0
- package/dist/host.d.mts +83 -0
- package/dist/host.d.ts +83 -0
- package/dist/host.js +417 -0
- package/dist/host.js.map +1 -0
- package/dist/host.mjs +33 -0
- package/dist/host.mjs.map +1 -0
- package/dist/index.d.mts +462 -0
- package/dist/index.d.ts +462 -0
- package/dist/index.js +580 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +119 -0
- package/dist/index.mjs.map +1 -0
- package/dist/whop-server-CCmOBRgb.d.mts +438 -0
- package/dist/whop-server-CCmOBRgb.d.ts +438 -0
- package/package.json +43 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appsServerSchema,
|
|
3
|
+
createSDK,
|
|
4
|
+
postmessageTransport,
|
|
5
|
+
reactNativeClientTransport,
|
|
6
|
+
transport_exports,
|
|
7
|
+
whopServerSchema
|
|
8
|
+
} from "./chunk-DPDPUJJX.mjs";
|
|
9
|
+
|
|
10
|
+
// src/sdk/mobile-app-postmessage.ts
|
|
11
|
+
function getReactNativePostMessage() {
|
|
12
|
+
const reactNativePostMessage = typeof window !== "undefined" && "ReactNativeWebView" in window && typeof window.ReactNativeWebView === "object" && window.ReactNativeWebView && "postMessage" in window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === "function" ? (data) => {
|
|
13
|
+
if (typeof window !== "undefined" && "ReactNativeWebView" in window && typeof window.ReactNativeWebView === "object" && window.ReactNativeWebView && "postMessage" in window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === "function")
|
|
14
|
+
window?.ReactNativeWebView?.postMessage(data);
|
|
15
|
+
} : void 0;
|
|
16
|
+
return reactNativePostMessage;
|
|
17
|
+
}
|
|
18
|
+
function getSwiftPostMessage() {
|
|
19
|
+
const swiftMessageHandler = typeof window !== "undefined" && "webkit" in window && typeof window.webkit === "object" && window.webkit !== null && "messageHandlers" in window.webkit && typeof window.webkit.messageHandlers === "object" && window.webkit.messageHandlers !== null && "SwiftWebView" in window.webkit.messageHandlers && typeof window.webkit.messageHandlers.SwiftWebView === "object" && window.webkit.messageHandlers.SwiftWebView !== null && "postMessage" in window.webkit.messageHandlers.SwiftWebView ? window.webkit.messageHandlers.SwiftWebView : null;
|
|
20
|
+
const swiftPostMessage = swiftMessageHandler ? (data) => {
|
|
21
|
+
if (typeof swiftMessageHandler.postMessage === "function") {
|
|
22
|
+
swiftMessageHandler.postMessage(data);
|
|
23
|
+
}
|
|
24
|
+
} : void 0;
|
|
25
|
+
return swiftPostMessage;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/sdk/sync-href.ts
|
|
29
|
+
function syncHref({
|
|
30
|
+
onChange
|
|
31
|
+
}) {
|
|
32
|
+
if (typeof window === "undefined") return;
|
|
33
|
+
const initialHref = window.location.href;
|
|
34
|
+
onChange({ href: initialHref }).catch(() => null);
|
|
35
|
+
let lastKnown = initialHref;
|
|
36
|
+
window.addEventListener("popstate", () => {
|
|
37
|
+
const { href } = window.location;
|
|
38
|
+
onChange({ href }).catch(() => null);
|
|
39
|
+
lastKnown = href;
|
|
40
|
+
});
|
|
41
|
+
if (window._whop_sync_href_interval) {
|
|
42
|
+
clearInterval(window._whop_sync_href_interval);
|
|
43
|
+
}
|
|
44
|
+
window._whop_sync_href_interval = setInterval(() => {
|
|
45
|
+
const { href } = window.location;
|
|
46
|
+
if (href === lastKnown) return;
|
|
47
|
+
onChange({ href }).catch(() => null);
|
|
48
|
+
lastKnown = href;
|
|
49
|
+
}, 250);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/sdk/index.ts
|
|
53
|
+
function setColorTheme(theme) {
|
|
54
|
+
document.documentElement.dispatchEvent(
|
|
55
|
+
new CustomEvent("frosted-ui:set-theme", {
|
|
56
|
+
detail: theme
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function createSdk({
|
|
61
|
+
onMessage = {},
|
|
62
|
+
appId = process.env.NEXT_PUBLIC_WHOP_APP_ID,
|
|
63
|
+
overrideParentOrigins
|
|
64
|
+
}) {
|
|
65
|
+
const mobileWebView = getSwiftPostMessage() ?? getReactNativePostMessage();
|
|
66
|
+
const remoteWindow = typeof window === "undefined" ? void 0 : window.parent;
|
|
67
|
+
if (!appId) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
"[createSdk]: appId is required. Please provide an appId or set the NEXT_PUBLIC_WHOP_APP_ID environment variable."
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const sdk = createSDK({
|
|
73
|
+
clientSchema: whopServerSchema,
|
|
74
|
+
serverSchema: appsServerSchema,
|
|
75
|
+
forceCompleteness: false,
|
|
76
|
+
serverImplementation: onMessage,
|
|
77
|
+
localAppId: appId,
|
|
78
|
+
remoteAppId: "app_whop",
|
|
79
|
+
transport: mobileWebView ? reactNativeClientTransport({
|
|
80
|
+
postMessage: mobileWebView,
|
|
81
|
+
targetOrigin: "com.whop.whopapp"
|
|
82
|
+
}) : postmessageTransport({
|
|
83
|
+
remoteWindow,
|
|
84
|
+
targetOrigins: overrideParentOrigins ?? [
|
|
85
|
+
"https://whop.com",
|
|
86
|
+
"https://dash.whop.com",
|
|
87
|
+
"http://localhost:8003"
|
|
88
|
+
]
|
|
89
|
+
}),
|
|
90
|
+
serverComplete: true,
|
|
91
|
+
serverMiddleware: [
|
|
92
|
+
{
|
|
93
|
+
onColorThemeChange: setColorTheme
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
timeout: 15e3,
|
|
97
|
+
timeouts: {
|
|
98
|
+
inAppPurchase: 1e3 * 60 * 60 * 24,
|
|
99
|
+
// 24 hours, we never want this to timeout.
|
|
100
|
+
onHrefChange: 500
|
|
101
|
+
// we don't really care about a response here.
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (typeof window !== "undefined") {
|
|
105
|
+
sdk.getColorTheme().then(setColorTheme).catch(() => null);
|
|
106
|
+
document.documentElement.addEventListener("frosted-ui:mounted", () => {
|
|
107
|
+
sdk.getColorTheme().then(setColorTheme).catch(() => null);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
syncHref({ onChange: sdk.onHrefChange });
|
|
111
|
+
return sdk;
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
appsServerSchema,
|
|
115
|
+
createSdk,
|
|
116
|
+
transport_exports as transport,
|
|
117
|
+
whopServerSchema
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/mobile-app-postmessage.ts","../src/sdk/sync-href.ts","../src/sdk/index.ts"],"sourcesContent":["export function getReactNativePostMessage() {\n\tconst reactNativePostMessage =\n\t\ttypeof window !== \"undefined\" &&\n\t\t\"ReactNativeWebView\" in window &&\n\t\ttypeof window.ReactNativeWebView === \"object\" &&\n\t\twindow.ReactNativeWebView &&\n\t\t\"postMessage\" in window.ReactNativeWebView &&\n\t\ttypeof window.ReactNativeWebView.postMessage === \"function\"\n\t\t\t? (data: string) => {\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof window !== \"undefined\" &&\n\t\t\t\t\t\t\"ReactNativeWebView\" in window &&\n\t\t\t\t\t\ttypeof window.ReactNativeWebView === \"object\" &&\n\t\t\t\t\t\twindow.ReactNativeWebView &&\n\t\t\t\t\t\t\"postMessage\" in window.ReactNativeWebView &&\n\t\t\t\t\t\ttypeof window.ReactNativeWebView.postMessage === \"function\"\n\t\t\t\t\t)\n\t\t\t\t\t\twindow?.ReactNativeWebView?.postMessage(data);\n\t\t\t\t}\n\t\t\t: undefined;\n\treturn reactNativePostMessage;\n}\n\nexport function getSwiftPostMessage() {\n\tconst swiftMessageHandler =\n\t\ttypeof window !== \"undefined\" &&\n\t\t\"webkit\" in window &&\n\t\ttypeof window.webkit === \"object\" &&\n\t\twindow.webkit !== null &&\n\t\t\"messageHandlers\" in window.webkit &&\n\t\ttypeof window.webkit.messageHandlers === \"object\" &&\n\t\twindow.webkit.messageHandlers !== null &&\n\t\t\"SwiftWebView\" in window.webkit.messageHandlers &&\n\t\ttypeof window.webkit.messageHandlers.SwiftWebView === \"object\" &&\n\t\twindow.webkit.messageHandlers.SwiftWebView !== null &&\n\t\t\"postMessage\" in window.webkit.messageHandlers.SwiftWebView\n\t\t\t? window.webkit.messageHandlers.SwiftWebView\n\t\t\t: null;\n\n\tconst swiftPostMessage = swiftMessageHandler\n\t\t? (data: string) => {\n\t\t\t\tif (typeof swiftMessageHandler.postMessage === \"function\") {\n\t\t\t\t\tswiftMessageHandler.postMessage(data);\n\t\t\t\t}\n\t\t\t}\n\t\t: undefined;\n\n\treturn swiftPostMessage;\n}\n","declare global {\n\tinterface Window {\n\t\t_whop_sync_href_interval?: ReturnType<typeof setInterval>;\n\t}\n}\n\nexport function syncHref({\n\tonChange,\n}: { onChange: (req: { href: string }) => Promise<\"ok\"> }) {\n\tif (typeof window === \"undefined\") return;\n\n\tconst initialHref = window.location.href;\n\tonChange({ href: initialHref }).catch(() => null);\n\tlet lastKnown = initialHref;\n\n\twindow.addEventListener(\"popstate\", () => {\n\t\tconst { href } = window.location;\n\t\tonChange({ href }).catch(() => null);\n\t\tlastKnown = href;\n\t});\n\n\tif (window._whop_sync_href_interval) {\n\t\tclearInterval(window._whop_sync_href_interval);\n\t}\n\twindow._whop_sync_href_interval = setInterval(() => {\n\t\tconst { href } = window.location;\n\t\tif (href === lastKnown) return;\n\t\tonChange({ href }).catch(() => null);\n\t\tlastKnown = href;\n\t}, 250);\n}\n","import { appsServerSchema } from \"@/sdk/apps-server\";\nimport {\n\tgetReactNativePostMessage,\n\tgetSwiftPostMessage,\n} from \"@/sdk/mobile-app-postmessage\";\nimport { syncHref } from \"@/sdk/sync-href\";\nimport {\n\ttype ServerImplementation,\n\tcreateSDK as createPostmessageSdk,\n\tpostmessageTransport,\n} from \"@/sdk/transport\";\nimport { reactNativeClientTransport } from \"@/sdk/transport/postmessage\";\nimport type { frostedV2Theme } from \"@/sdk/utils\";\nimport { whopServerSchema } from \"@/sdk/whop-server\";\nimport type { z } from \"zod\";\n\nexport { appsServerSchema, whopServerSchema };\n\nfunction setColorTheme(theme: z.infer<typeof frostedV2Theme>) {\n\tdocument.documentElement.dispatchEvent(\n\t\tnew CustomEvent(\"frosted-ui:set-theme\", {\n\t\t\tdetail: theme,\n\t\t}),\n\t);\n}\n\n/**\n * Create an iframe SDK for a client app. This will communicate with the parent\n * window which is required to be whop.com.\n */\nexport function createSdk({\n\tonMessage = {},\n\tappId = process.env.NEXT_PUBLIC_WHOP_APP_ID,\n\toverrideParentOrigins,\n}: {\n\tonMessage?: ServerImplementation<typeof appsServerSchema, false>;\n\tappId?: string;\n\toverrideParentOrigins?: string[];\n}) {\n\tconst mobileWebView = getSwiftPostMessage() ?? getReactNativePostMessage();\n\n\tconst remoteWindow =\n\t\ttypeof window === \"undefined\" ? undefined : window.parent;\n\n\tif (!appId) {\n\t\tthrow new Error(\n\t\t\t\"[createSdk]: appId is required. Please provide an appId or set the NEXT_PUBLIC_WHOP_APP_ID environment variable.\",\n\t\t);\n\t}\n\n\tconst sdk = createPostmessageSdk({\n\t\tclientSchema: whopServerSchema,\n\t\tserverSchema: appsServerSchema,\n\t\tforceCompleteness: false,\n\t\tserverImplementation: onMessage,\n\t\tlocalAppId: appId,\n\t\tremoteAppId: \"app_whop\",\n\t\ttransport: mobileWebView\n\t\t\t? reactNativeClientTransport({\n\t\t\t\t\tpostMessage: mobileWebView,\n\t\t\t\t\ttargetOrigin: \"com.whop.whopapp\",\n\t\t\t\t})\n\t\t\t: postmessageTransport({\n\t\t\t\t\tremoteWindow,\n\t\t\t\t\ttargetOrigins: overrideParentOrigins ?? [\n\t\t\t\t\t\t\"https://whop.com\",\n\t\t\t\t\t\t\"https://dash.whop.com\",\n\t\t\t\t\t\t\"http://localhost:8003\",\n\t\t\t\t\t],\n\t\t\t\t}),\n\t\tserverComplete: true,\n\t\tserverMiddleware: [\n\t\t\t{\n\t\t\t\tonColorThemeChange: setColorTheme,\n\t\t\t},\n\t\t],\n\t\ttimeout: 15000,\n\t\ttimeouts: {\n\t\t\tinAppPurchase: 1000 * 60 * 60 * 24, // 24 hours, we never want this to timeout.\n\t\t\tonHrefChange: 500, // we don't really care about a response here.\n\t\t},\n\t});\n\n\tif (typeof window !== \"undefined\") {\n\t\tsdk\n\t\t\t.getColorTheme()\n\t\t\t.then(setColorTheme)\n\t\t\t.catch(() => null);\n\t\tdocument.documentElement.addEventListener(\"frosted-ui:mounted\", () => {\n\t\t\tsdk\n\t\t\t\t.getColorTheme()\n\t\t\t\t.then(setColorTheme)\n\t\t\t\t.catch(() => null);\n\t\t});\n\t}\n\n\tsyncHref({ onChange: sdk.onHrefChange });\n\n\treturn sdk;\n}\n\nexport type WhopIframeSdk = ReturnType<typeof createSdk>;\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { ZodDiscriminatedUnion, ZodObject, ZodLiteral, ZodTypeAny, ZodRawShape, z } from 'zod';
|
|
2
|
+
|
|
3
|
+
type ValidZodEventSchema = ZodDiscriminatedUnion<"event", ZodObject<{
|
|
4
|
+
event: ZodLiteral<string>;
|
|
5
|
+
request: ZodTypeAny;
|
|
6
|
+
response: ZodTypeAny;
|
|
7
|
+
} & ZodRawShape>[]>;
|
|
8
|
+
type MaybePromise<T> = Promise<T> | T;
|
|
9
|
+
type FullServerImplementation<Schema extends ValidZodEventSchema> = {
|
|
10
|
+
[K in NonNullable<z.infer<Schema>["event"]>]: (request: Extract<z.infer<Schema>, {
|
|
11
|
+
event: K;
|
|
12
|
+
}>["request"]) => MaybePromise<Extract<z.infer<Schema>, {
|
|
13
|
+
event: K;
|
|
14
|
+
}>["response"]>;
|
|
15
|
+
};
|
|
16
|
+
type ClientSDK<ClientSchema extends ValidZodEventSchema, Complete extends boolean> = {
|
|
17
|
+
[K in NonNullable<z.infer<ClientSchema>["event"]>]: (req: Extract<z.infer<ClientSchema>, {
|
|
18
|
+
event: K;
|
|
19
|
+
}>["request"]) => Promise<Complete extends true ? Extract<z.infer<ClientSchema>, {
|
|
20
|
+
event: K;
|
|
21
|
+
}>["response"] : Extract<z.infer<ClientSchema>, {
|
|
22
|
+
event: K;
|
|
23
|
+
}>["response"] | undefined>;
|
|
24
|
+
};
|
|
25
|
+
type ServerImplementation<Schema extends ValidZodEventSchema, ForceCompleteness extends boolean = false> = ForceCompleteness extends true ? FullServerImplementation<Schema> : Partial<FullServerImplementation<Schema>>;
|
|
26
|
+
type FullServerMiddlewareImplementation<Schema extends ValidZodEventSchema, ForceCompleteness extends boolean = false> = {
|
|
27
|
+
[K in NonNullable<z.infer<Schema>["event"]>]: (request: Extract<z.infer<Schema>, {
|
|
28
|
+
event: K;
|
|
29
|
+
}>["request"], next: ForceCompleteness extends true ? (request: Extract<z.infer<Schema>, {
|
|
30
|
+
event: K;
|
|
31
|
+
}>["request"]) => MaybePromise<Extract<z.infer<Schema>, {
|
|
32
|
+
event: K;
|
|
33
|
+
}>["response"]> : ((request: Extract<z.infer<Schema>, {
|
|
34
|
+
event: K;
|
|
35
|
+
}>["request"]) => MaybePromise<Extract<z.infer<Schema>, {
|
|
36
|
+
event: K;
|
|
37
|
+
}>["response"]>) | undefined) => MaybePromise<ForceCompleteness extends true ? Extract<z.infer<Schema>, {
|
|
38
|
+
event: K;
|
|
39
|
+
}>["response"] : Extract<z.infer<Schema>, {
|
|
40
|
+
event: K;
|
|
41
|
+
}>["response"] | undefined>;
|
|
42
|
+
};
|
|
43
|
+
type ServerMiddleware<Schema extends ValidZodEventSchema, ForceCompleteness extends boolean = false> = Partial<FullServerMiddlewareImplementation<Schema, ForceCompleteness>>;
|
|
44
|
+
type Transport<ServerSchema extends ValidZodEventSchema | undefined> = {
|
|
45
|
+
send: (event: string, data: unknown, params: {
|
|
46
|
+
localAppId: string;
|
|
47
|
+
remoteAppId: string;
|
|
48
|
+
}) => unknown;
|
|
49
|
+
recv: (handler: (event: string, data: unknown) => Promise<(ServerSchema extends ValidZodEventSchema ? z.infer<ServerSchema>["response"] : undefined) | undefined>, params: {
|
|
50
|
+
localAppId: string;
|
|
51
|
+
remoteAppId: string;
|
|
52
|
+
}) => void | (() => void);
|
|
53
|
+
cleanup?: () => void;
|
|
54
|
+
};
|
|
55
|
+
declare function createSDK<ClientSchema extends ValidZodEventSchema | undefined, ServerSchema extends ValidZodEventSchema | undefined, ForceCompleteness extends boolean = false, ServerComplete extends boolean = false>({ clientSchema, serverSchema, serverComplete, transport, timeout, timeouts, localAppId, remoteAppId, serverImplementation, serverMiddleware, }: {
|
|
56
|
+
clientSchema: ClientSchema;
|
|
57
|
+
serverSchema: ServerSchema;
|
|
58
|
+
forceCompleteness?: ForceCompleteness;
|
|
59
|
+
serverComplete?: ServerComplete;
|
|
60
|
+
localAppId: string;
|
|
61
|
+
remoteAppId: string;
|
|
62
|
+
serverMiddleware?: ServerSchema extends ValidZodEventSchema ? ServerMiddleware<ServerSchema, ForceCompleteness>[] : undefined;
|
|
63
|
+
serverImplementation: ServerSchema extends ValidZodEventSchema ? ServerImplementation<ServerSchema, ForceCompleteness> : undefined;
|
|
64
|
+
transport: Transport<ServerSchema>;
|
|
65
|
+
timeout?: number;
|
|
66
|
+
timeouts?: ClientSchema extends ValidZodEventSchema ? {
|
|
67
|
+
[K in NonNullable<z.infer<ClientSchema>["event"]>]?: number;
|
|
68
|
+
} : never;
|
|
69
|
+
}): (ClientSchema extends ValidZodEventSchema ? ClientSDK<ClientSchema, ServerComplete> : object) & {
|
|
70
|
+
_cleanupTransport: () => void;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
declare const whopServerSchema: z.ZodDiscriminatedUnion<"event", [z.ZodObject<{
|
|
74
|
+
event: z.ZodLiteral<"ping">;
|
|
75
|
+
request: z.ZodLiteral<"ping">;
|
|
76
|
+
response: z.ZodLiteral<"pong">;
|
|
77
|
+
}, "strip", z.ZodTypeAny, {
|
|
78
|
+
event: "ping";
|
|
79
|
+
request: "ping";
|
|
80
|
+
response: "pong";
|
|
81
|
+
}, {
|
|
82
|
+
event: "ping";
|
|
83
|
+
request: "ping";
|
|
84
|
+
response: "pong";
|
|
85
|
+
}>, z.ZodObject<{
|
|
86
|
+
event: z.ZodLiteral<"getTopLevelUrlData">;
|
|
87
|
+
request: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>;
|
|
88
|
+
response: z.ZodObject<{
|
|
89
|
+
companyRoute: z.ZodString;
|
|
90
|
+
experienceRoute: z.ZodString;
|
|
91
|
+
experienceId: z.ZodString;
|
|
92
|
+
viewType: z.ZodEnum<["app", "admin", "analytics", "preview"]>;
|
|
93
|
+
baseHref: z.ZodString;
|
|
94
|
+
fullHref: z.ZodString;
|
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
|
96
|
+
companyRoute: string;
|
|
97
|
+
experienceRoute: string;
|
|
98
|
+
experienceId: string;
|
|
99
|
+
viewType: "app" | "admin" | "analytics" | "preview";
|
|
100
|
+
baseHref: string;
|
|
101
|
+
fullHref: string;
|
|
102
|
+
}, {
|
|
103
|
+
companyRoute: string;
|
|
104
|
+
experienceRoute: string;
|
|
105
|
+
experienceId: string;
|
|
106
|
+
viewType: "app" | "admin" | "analytics" | "preview";
|
|
107
|
+
baseHref: string;
|
|
108
|
+
fullHref: string;
|
|
109
|
+
}>;
|
|
110
|
+
}, "strip", z.ZodTypeAny, {
|
|
111
|
+
event: "getTopLevelUrlData";
|
|
112
|
+
response: {
|
|
113
|
+
companyRoute: string;
|
|
114
|
+
experienceRoute: string;
|
|
115
|
+
experienceId: string;
|
|
116
|
+
viewType: "app" | "admin" | "analytics" | "preview";
|
|
117
|
+
baseHref: string;
|
|
118
|
+
fullHref: string;
|
|
119
|
+
};
|
|
120
|
+
request?: {} | undefined;
|
|
121
|
+
}, {
|
|
122
|
+
event: "getTopLevelUrlData";
|
|
123
|
+
response: {
|
|
124
|
+
companyRoute: string;
|
|
125
|
+
experienceRoute: string;
|
|
126
|
+
experienceId: string;
|
|
127
|
+
viewType: "app" | "admin" | "analytics" | "preview";
|
|
128
|
+
baseHref: string;
|
|
129
|
+
fullHref: string;
|
|
130
|
+
};
|
|
131
|
+
request?: {} | undefined;
|
|
132
|
+
}>, z.ZodObject<{
|
|
133
|
+
event: z.ZodLiteral<"openExternalUrl">;
|
|
134
|
+
request: z.ZodObject<{
|
|
135
|
+
newTab: z.ZodOptional<z.ZodBoolean>;
|
|
136
|
+
url: z.ZodString;
|
|
137
|
+
}, "strip", z.ZodTypeAny, {
|
|
138
|
+
url: string;
|
|
139
|
+
newTab?: boolean | undefined;
|
|
140
|
+
}, {
|
|
141
|
+
url: string;
|
|
142
|
+
newTab?: boolean | undefined;
|
|
143
|
+
}>;
|
|
144
|
+
response: z.ZodLiteral<"ok">;
|
|
145
|
+
}, "strip", z.ZodTypeAny, {
|
|
146
|
+
event: "openExternalUrl";
|
|
147
|
+
request: {
|
|
148
|
+
url: string;
|
|
149
|
+
newTab?: boolean | undefined;
|
|
150
|
+
};
|
|
151
|
+
response: "ok";
|
|
152
|
+
}, {
|
|
153
|
+
event: "openExternalUrl";
|
|
154
|
+
request: {
|
|
155
|
+
url: string;
|
|
156
|
+
newTab?: boolean | undefined;
|
|
157
|
+
};
|
|
158
|
+
response: "ok";
|
|
159
|
+
}>, z.ZodObject<{
|
|
160
|
+
event: z.ZodLiteral<"onHrefChange">;
|
|
161
|
+
request: z.ZodObject<{
|
|
162
|
+
href: z.ZodString;
|
|
163
|
+
}, "strip", z.ZodTypeAny, {
|
|
164
|
+
href: string;
|
|
165
|
+
}, {
|
|
166
|
+
href: string;
|
|
167
|
+
}>;
|
|
168
|
+
response: z.ZodLiteral<"ok">;
|
|
169
|
+
}, "strip", z.ZodTypeAny, {
|
|
170
|
+
event: "onHrefChange";
|
|
171
|
+
request: {
|
|
172
|
+
href: string;
|
|
173
|
+
};
|
|
174
|
+
response: "ok";
|
|
175
|
+
}, {
|
|
176
|
+
event: "onHrefChange";
|
|
177
|
+
request: {
|
|
178
|
+
href: string;
|
|
179
|
+
};
|
|
180
|
+
response: "ok";
|
|
181
|
+
}>, z.ZodObject<{
|
|
182
|
+
event: z.ZodLiteral<"inAppPurchase">;
|
|
183
|
+
request: z.ZodObject<{
|
|
184
|
+
/**
|
|
185
|
+
* ID returned from the `chargeUser` API call.
|
|
186
|
+
* @example "ch_1234567890"
|
|
187
|
+
*/
|
|
188
|
+
id: z.ZodOptional<z.ZodString>;
|
|
189
|
+
/**
|
|
190
|
+
* ID of the plan returned from the `chargeUser` API call.
|
|
191
|
+
* @example "plan_1234567890"
|
|
192
|
+
*/
|
|
193
|
+
planId: z.ZodString;
|
|
194
|
+
}, "strip", z.ZodTypeAny, {
|
|
195
|
+
planId: string;
|
|
196
|
+
id?: string | undefined;
|
|
197
|
+
}, {
|
|
198
|
+
planId: string;
|
|
199
|
+
id?: string | undefined;
|
|
200
|
+
}>;
|
|
201
|
+
response: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{
|
|
202
|
+
status: z.ZodLiteral<"ok">;
|
|
203
|
+
data: z.ZodObject<{
|
|
204
|
+
sessionId: z.ZodString;
|
|
205
|
+
/**
|
|
206
|
+
* The receipt ID can be used to verify the purchase.
|
|
207
|
+
*
|
|
208
|
+
* NOTE: When receiving payments you should always listen to webhooks as a fallback
|
|
209
|
+
* to process the payment. Do not solely rely on the client to process payments. The receipt ID
|
|
210
|
+
* can be used to deduplicate payment events.
|
|
211
|
+
*/
|
|
212
|
+
receiptId: z.ZodString;
|
|
213
|
+
}, "strip", z.ZodTypeAny, {
|
|
214
|
+
sessionId: string;
|
|
215
|
+
receiptId: string;
|
|
216
|
+
}, {
|
|
217
|
+
sessionId: string;
|
|
218
|
+
receiptId: string;
|
|
219
|
+
}>;
|
|
220
|
+
}, "strip", z.ZodTypeAny, {
|
|
221
|
+
status: "ok";
|
|
222
|
+
data: {
|
|
223
|
+
sessionId: string;
|
|
224
|
+
receiptId: string;
|
|
225
|
+
};
|
|
226
|
+
}, {
|
|
227
|
+
status: "ok";
|
|
228
|
+
data: {
|
|
229
|
+
sessionId: string;
|
|
230
|
+
receiptId: string;
|
|
231
|
+
};
|
|
232
|
+
}>, z.ZodObject<{
|
|
233
|
+
status: z.ZodLiteral<"error">;
|
|
234
|
+
error: z.ZodString;
|
|
235
|
+
}, "strip", z.ZodTypeAny, {
|
|
236
|
+
status: "error";
|
|
237
|
+
error: string;
|
|
238
|
+
}, {
|
|
239
|
+
status: "error";
|
|
240
|
+
error: string;
|
|
241
|
+
}>]>;
|
|
242
|
+
}, "strip", z.ZodTypeAny, {
|
|
243
|
+
event: "inAppPurchase";
|
|
244
|
+
request: {
|
|
245
|
+
planId: string;
|
|
246
|
+
id?: string | undefined;
|
|
247
|
+
};
|
|
248
|
+
response: {
|
|
249
|
+
status: "ok";
|
|
250
|
+
data: {
|
|
251
|
+
sessionId: string;
|
|
252
|
+
receiptId: string;
|
|
253
|
+
};
|
|
254
|
+
} | {
|
|
255
|
+
status: "error";
|
|
256
|
+
error: string;
|
|
257
|
+
};
|
|
258
|
+
}, {
|
|
259
|
+
event: "inAppPurchase";
|
|
260
|
+
request: {
|
|
261
|
+
planId: string;
|
|
262
|
+
id?: string | undefined;
|
|
263
|
+
};
|
|
264
|
+
response: {
|
|
265
|
+
status: "ok";
|
|
266
|
+
data: {
|
|
267
|
+
sessionId: string;
|
|
268
|
+
receiptId: string;
|
|
269
|
+
};
|
|
270
|
+
} | {
|
|
271
|
+
status: "error";
|
|
272
|
+
error: string;
|
|
273
|
+
};
|
|
274
|
+
}>, z.ZodObject<{
|
|
275
|
+
event: z.ZodLiteral<"closeApp">;
|
|
276
|
+
request: z.ZodNull;
|
|
277
|
+
response: z.ZodLiteral<"ok">;
|
|
278
|
+
}, "strip", z.ZodTypeAny, {
|
|
279
|
+
event: "closeApp";
|
|
280
|
+
request: null;
|
|
281
|
+
response: "ok";
|
|
282
|
+
}, {
|
|
283
|
+
event: "closeApp";
|
|
284
|
+
request: null;
|
|
285
|
+
response: "ok";
|
|
286
|
+
}>, z.ZodObject<{
|
|
287
|
+
event: z.ZodLiteral<"openHelpChat">;
|
|
288
|
+
request: z.ZodNull;
|
|
289
|
+
response: z.ZodLiteral<"ok">;
|
|
290
|
+
}, "strip", z.ZodTypeAny, {
|
|
291
|
+
event: "openHelpChat";
|
|
292
|
+
request: null;
|
|
293
|
+
response: "ok";
|
|
294
|
+
}, {
|
|
295
|
+
event: "openHelpChat";
|
|
296
|
+
request: null;
|
|
297
|
+
response: "ok";
|
|
298
|
+
}>, z.ZodObject<{
|
|
299
|
+
event: z.ZodLiteral<"getColorTheme">;
|
|
300
|
+
request: z.ZodVoid;
|
|
301
|
+
response: z.ZodObject<{
|
|
302
|
+
appearance: z.ZodOptional<z.ZodEnum<["light", "dark"]>>;
|
|
303
|
+
accentColor: z.ZodOptional<z.ZodString>;
|
|
304
|
+
dangerColor: z.ZodOptional<z.ZodString>;
|
|
305
|
+
grayColor: z.ZodOptional<z.ZodString>;
|
|
306
|
+
infoColor: z.ZodOptional<z.ZodString>;
|
|
307
|
+
successColor: z.ZodOptional<z.ZodString>;
|
|
308
|
+
warningColor: z.ZodOptional<z.ZodString>;
|
|
309
|
+
}, "strip", z.ZodTypeAny, {
|
|
310
|
+
appearance?: "light" | "dark" | undefined;
|
|
311
|
+
accentColor?: string | undefined;
|
|
312
|
+
dangerColor?: string | undefined;
|
|
313
|
+
grayColor?: string | undefined;
|
|
314
|
+
infoColor?: string | undefined;
|
|
315
|
+
successColor?: string | undefined;
|
|
316
|
+
warningColor?: string | undefined;
|
|
317
|
+
}, {
|
|
318
|
+
appearance?: "light" | "dark" | undefined;
|
|
319
|
+
accentColor?: string | undefined;
|
|
320
|
+
dangerColor?: string | undefined;
|
|
321
|
+
grayColor?: string | undefined;
|
|
322
|
+
infoColor?: string | undefined;
|
|
323
|
+
successColor?: string | undefined;
|
|
324
|
+
warningColor?: string | undefined;
|
|
325
|
+
}>;
|
|
326
|
+
}, "strip", z.ZodTypeAny, {
|
|
327
|
+
event: "getColorTheme";
|
|
328
|
+
response: {
|
|
329
|
+
appearance?: "light" | "dark" | undefined;
|
|
330
|
+
accentColor?: string | undefined;
|
|
331
|
+
dangerColor?: string | undefined;
|
|
332
|
+
grayColor?: string | undefined;
|
|
333
|
+
infoColor?: string | undefined;
|
|
334
|
+
successColor?: string | undefined;
|
|
335
|
+
warningColor?: string | undefined;
|
|
336
|
+
};
|
|
337
|
+
request?: void | undefined;
|
|
338
|
+
}, {
|
|
339
|
+
event: "getColorTheme";
|
|
340
|
+
response: {
|
|
341
|
+
appearance?: "light" | "dark" | undefined;
|
|
342
|
+
accentColor?: string | undefined;
|
|
343
|
+
dangerColor?: string | undefined;
|
|
344
|
+
grayColor?: string | undefined;
|
|
345
|
+
infoColor?: string | undefined;
|
|
346
|
+
successColor?: string | undefined;
|
|
347
|
+
warningColor?: string | undefined;
|
|
348
|
+
};
|
|
349
|
+
request?: void | undefined;
|
|
350
|
+
}>, z.ZodObject<{
|
|
351
|
+
event: z.ZodLiteral<"earliestUnreadNotification">;
|
|
352
|
+
request: z.ZodObject<{
|
|
353
|
+
experienceId: z.ZodString;
|
|
354
|
+
}, "strip", z.ZodTypeAny, {
|
|
355
|
+
experienceId: string;
|
|
356
|
+
}, {
|
|
357
|
+
experienceId: string;
|
|
358
|
+
}>;
|
|
359
|
+
response: z.ZodNullable<z.ZodObject<{
|
|
360
|
+
externalId: z.ZodString;
|
|
361
|
+
}, "strip", z.ZodTypeAny, {
|
|
362
|
+
externalId: string;
|
|
363
|
+
}, {
|
|
364
|
+
externalId: string;
|
|
365
|
+
}>>;
|
|
366
|
+
}, "strip", z.ZodTypeAny, {
|
|
367
|
+
event: "earliestUnreadNotification";
|
|
368
|
+
request: {
|
|
369
|
+
experienceId: string;
|
|
370
|
+
};
|
|
371
|
+
response: {
|
|
372
|
+
externalId: string;
|
|
373
|
+
} | null;
|
|
374
|
+
}, {
|
|
375
|
+
event: "earliestUnreadNotification";
|
|
376
|
+
request: {
|
|
377
|
+
experienceId: string;
|
|
378
|
+
};
|
|
379
|
+
response: {
|
|
380
|
+
externalId: string;
|
|
381
|
+
} | null;
|
|
382
|
+
}>, z.ZodObject<{
|
|
383
|
+
event: z.ZodLiteral<"markExperienceRead">;
|
|
384
|
+
request: z.ZodObject<{
|
|
385
|
+
experienceId: z.ZodString;
|
|
386
|
+
notificationExternalId: z.ZodOptional<z.ZodString>;
|
|
387
|
+
}, "strip", z.ZodTypeAny, {
|
|
388
|
+
experienceId: string;
|
|
389
|
+
notificationExternalId?: string | undefined;
|
|
390
|
+
}, {
|
|
391
|
+
experienceId: string;
|
|
392
|
+
notificationExternalId?: string | undefined;
|
|
393
|
+
}>;
|
|
394
|
+
response: z.ZodLiteral<"ok">;
|
|
395
|
+
}, "strip", z.ZodTypeAny, {
|
|
396
|
+
event: "markExperienceRead";
|
|
397
|
+
request: {
|
|
398
|
+
experienceId: string;
|
|
399
|
+
notificationExternalId?: string | undefined;
|
|
400
|
+
};
|
|
401
|
+
response: "ok";
|
|
402
|
+
}, {
|
|
403
|
+
event: "markExperienceRead";
|
|
404
|
+
request: {
|
|
405
|
+
experienceId: string;
|
|
406
|
+
notificationExternalId?: string | undefined;
|
|
407
|
+
};
|
|
408
|
+
response: "ok";
|
|
409
|
+
}>, z.ZodObject<{
|
|
410
|
+
event: z.ZodLiteral<"performHaptic">;
|
|
411
|
+
request: z.ZodObject<{
|
|
412
|
+
type: z.ZodEnum<["selection", "impact", "notification"]>;
|
|
413
|
+
style: z.ZodEnum<["light", "medium", "heavy"]>;
|
|
414
|
+
}, "strip", z.ZodTypeAny, {
|
|
415
|
+
type: "selection" | "impact" | "notification";
|
|
416
|
+
style: "light" | "medium" | "heavy";
|
|
417
|
+
}, {
|
|
418
|
+
type: "selection" | "impact" | "notification";
|
|
419
|
+
style: "light" | "medium" | "heavy";
|
|
420
|
+
}>;
|
|
421
|
+
response: z.ZodLiteral<"ok">;
|
|
422
|
+
}, "strip", z.ZodTypeAny, {
|
|
423
|
+
event: "performHaptic";
|
|
424
|
+
request: {
|
|
425
|
+
type: "selection" | "impact" | "notification";
|
|
426
|
+
style: "light" | "medium" | "heavy";
|
|
427
|
+
};
|
|
428
|
+
response: "ok";
|
|
429
|
+
}, {
|
|
430
|
+
event: "performHaptic";
|
|
431
|
+
request: {
|
|
432
|
+
type: "selection" | "impact" | "notification";
|
|
433
|
+
style: "light" | "medium" | "heavy";
|
|
434
|
+
};
|
|
435
|
+
response: "ok";
|
|
436
|
+
}>]>;
|
|
437
|
+
|
|
438
|
+
export { type ClientSDK as C, type ServerImplementation as S, type Transport as T, type ValidZodEventSchema as V, createSDK as c, whopServerSchema as w };
|