UNPKG

@whop/iframe

Version:

Powers communication between Whop and your embedded app

463 lines (455 loc) 14.5 kB
import { z } from 'zod'; import { V as ValidZodEventSchema, S as ServerImplementation, T as Transport, C as ClientSDK, c as createSDK } from './whop-server-CCmOBRgb.mjs'; export { w as whopServerSchema } from './whop-server-CCmOBRgb.mjs'; declare function createHandler<Schema extends ValidZodEventSchema, ForceCompleteness extends boolean = false>({ schema, forceCompleteness, handlers, }: { schema: Schema; forceCompleteness?: ForceCompleteness; handlers: Schema extends ValidZodEventSchema ? ServerImplementation<Schema, ForceCompleteness> : undefined; }): (event: string, data: unknown) => Promise<(Schema extends ValidZodEventSchema ? z.TypeOf<Schema>["response"] : undefined) | undefined>; declare const MESSAGE_TAG = "typed-transport"; declare function postmessageTransport<ServerSchema extends ValidZodEventSchema | undefined = undefined>({ remoteWindow, targetOrigins, }: { remoteWindow: Window | undefined; targetOrigins: string[]; }): Transport<ServerSchema>; declare class TimeoutError extends Error { constructor(); } declare const index_ClientSDK: typeof ClientSDK; declare const index_MESSAGE_TAG: typeof MESSAGE_TAG; declare const index_ServerImplementation: typeof ServerImplementation; type index_TimeoutError = TimeoutError; declare const index_TimeoutError: typeof TimeoutError; declare const index_Transport: typeof Transport; declare const index_ValidZodEventSchema: typeof ValidZodEventSchema; declare const index_createHandler: typeof createHandler; declare const index_createSDK: typeof createSDK; declare const index_postmessageTransport: typeof postmessageTransport; declare namespace index { export { index_ClientSDK as ClientSDK, index_MESSAGE_TAG as MESSAGE_TAG, index_ServerImplementation as ServerImplementation, index_TimeoutError as TimeoutError, index_Transport as Transport, index_ValidZodEventSchema as ValidZodEventSchema, index_createHandler as createHandler, index_createSDK as createSDK, index_postmessageTransport as postmessageTransport }; } declare const appsServerSchema: z.ZodDiscriminatedUnion<"event", [z.ZodObject<{ event: z.ZodLiteral<"appPing">; request: z.ZodLiteral<"app_ping">; response: z.ZodLiteral<"app_pong">; }, "strip", z.ZodTypeAny, { event: "appPing"; request: "app_ping"; response: "app_pong"; }, { event: "appPing"; request: "app_ping"; response: "app_pong"; }>, z.ZodObject<{ event: z.ZodLiteral<"onColorThemeChange">; request: z.ZodObject<{ appearance: z.ZodOptional<z.ZodEnum<["light", "dark"]>>; accentColor: z.ZodOptional<z.ZodString>; dangerColor: z.ZodOptional<z.ZodString>; grayColor: z.ZodOptional<z.ZodString>; infoColor: z.ZodOptional<z.ZodString>; successColor: z.ZodOptional<z.ZodString>; warningColor: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { appearance?: "light" | "dark" | undefined; accentColor?: string | undefined; dangerColor?: string | undefined; grayColor?: string | undefined; infoColor?: string | undefined; successColor?: string | undefined; warningColor?: string | undefined; }, { appearance?: "light" | "dark" | undefined; accentColor?: string | undefined; dangerColor?: string | undefined; grayColor?: string | undefined; infoColor?: string | undefined; successColor?: string | undefined; warningColor?: string | undefined; }>; response: z.ZodVoid; }, "strip", z.ZodTypeAny, { event: "onColorThemeChange"; request: { appearance?: "light" | "dark" | undefined; accentColor?: string | undefined; dangerColor?: string | undefined; grayColor?: string | undefined; infoColor?: string | undefined; successColor?: string | undefined; warningColor?: string | undefined; }; response?: void | undefined; }, { event: "onColorThemeChange"; request: { appearance?: "light" | "dark" | undefined; accentColor?: string | undefined; dangerColor?: string | undefined; grayColor?: string | undefined; infoColor?: string | undefined; successColor?: string | undefined; warningColor?: string | undefined; }; response?: void | undefined; }>]>; /** * Create an iframe SDK for a client app. This will communicate with the parent * window which is required to be whop.com. */ declare function createSdk({ onMessage, appId, overrideParentOrigins, }: { onMessage?: ServerImplementation<typeof appsServerSchema, false>; appId?: string; overrideParentOrigins?: string[]; }): ClientSDK<z.ZodDiscriminatedUnion<"event", [z.ZodObject<{ event: z.ZodLiteral<"ping">; request: z.ZodLiteral<"ping">; response: z.ZodLiteral<"pong">; }, "strip", z.ZodTypeAny, { event: "ping"; request: "ping"; response: "pong"; }, { event: "ping"; request: "ping"; response: "pong"; }>, z.ZodObject<{ event: z.ZodLiteral<"getTopLevelUrlData">; request: z.ZodOptional<z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>>; response: z.ZodObject<{ companyRoute: z.ZodString; experienceRoute: z.ZodString; experienceId: z.ZodString; viewType: z.ZodEnum<["app", "admin", "analytics", "preview"]>; baseHref: z.ZodString; fullHref: z.ZodString; }, "strip", z.ZodTypeAny, { companyRoute: string; experienceRoute: string; experienceId: string; viewType: "app" | "admin" | "analytics" | "preview"; baseHref: string; fullHref: string; }, { companyRoute: string; experienceRoute: string; experienceId: string; viewType: "app" | "admin" | "analytics" | "preview"; baseHref: string; fullHref: string; }>; }, "strip", z.ZodTypeAny, { event: "getTopLevelUrlData"; response: { companyRoute: string; experienceRoute: string; experienceId: string; viewType: "app" | "admin" | "analytics" | "preview"; baseHref: string; fullHref: string; }; request?: {} | undefined; }, { event: "getTopLevelUrlData"; response: { companyRoute: string; experienceRoute: string; experienceId: string; viewType: "app" | "admin" | "analytics" | "preview"; baseHref: string; fullHref: string; }; request?: {} | undefined; }>, z.ZodObject<{ event: z.ZodLiteral<"openExternalUrl">; request: z.ZodObject<{ newTab: z.ZodOptional<z.ZodBoolean>; url: z.ZodString; }, "strip", z.ZodTypeAny, { url: string; newTab?: boolean | undefined; }, { url: string; newTab?: boolean | undefined; }>; response: z.ZodLiteral<"ok">; }, "strip", z.ZodTypeAny, { event: "openExternalUrl"; request: { url: string; newTab?: boolean | undefined; }; response: "ok"; }, { event: "openExternalUrl"; request: { url: string; newTab?: boolean | undefined; }; response: "ok"; }>, z.ZodObject<{ event: z.ZodLiteral<"onHrefChange">; request: z.ZodObject<{ href: z.ZodString; }, "strip", z.ZodTypeAny, { href: string; }, { href: string; }>; response: z.ZodLiteral<"ok">; }, "strip", z.ZodTypeAny, { event: "onHrefChange"; request: { href: string; }; response: "ok"; }, { event: "onHrefChange"; request: { href: string; }; response: "ok"; }>, z.ZodObject<{ event: z.ZodLiteral<"inAppPurchase">; request: z.ZodObject<{ id: z.ZodOptional<z.ZodString>; planId: z.ZodString; }, "strip", z.ZodTypeAny, { planId: string; id?: string | undefined; }, { planId: string; id?: string | undefined; }>; response: z.ZodDiscriminatedUnion<"status", [z.ZodObject<{ status: z.ZodLiteral<"ok">; data: z.ZodObject<{ sessionId: z.ZodString; receiptId: z.ZodString; }, "strip", z.ZodTypeAny, { sessionId: string; receiptId: string; }, { sessionId: string; receiptId: string; }>; }, "strip", z.ZodTypeAny, { status: "ok"; data: { sessionId: string; receiptId: string; }; }, { status: "ok"; data: { sessionId: string; receiptId: string; }; }>, z.ZodObject<{ status: z.ZodLiteral<"error">; error: z.ZodString; }, "strip", z.ZodTypeAny, { status: "error"; error: string; }, { status: "error"; error: string; }>]>; }, "strip", z.ZodTypeAny, { event: "inAppPurchase"; request: { planId: string; id?: string | undefined; }; response: { status: "ok"; data: { sessionId: string; receiptId: string; }; } | { status: "error"; error: string; }; }, { event: "inAppPurchase"; request: { planId: string; id?: string | undefined; }; response: { status: "ok"; data: { sessionId: string; receiptId: string; }; } | { status: "error"; error: string; }; }>, z.ZodObject<{ event: z.ZodLiteral<"closeApp">; request: z.ZodNull; response: z.ZodLiteral<"ok">; }, "strip", z.ZodTypeAny, { event: "closeApp"; request: null; response: "ok"; }, { event: "closeApp"; request: null; response: "ok"; }>, z.ZodObject<{ event: z.ZodLiteral<"openHelpChat">; request: z.ZodNull; response: z.ZodLiteral<"ok">; }, "strip", z.ZodTypeAny, { event: "openHelpChat"; request: null; response: "ok"; }, { event: "openHelpChat"; request: null; response: "ok"; }>, z.ZodObject<{ event: z.ZodLiteral<"getColorTheme">; request: z.ZodVoid; response: z.ZodObject<{ appearance: z.ZodOptional<z.ZodEnum<["light", "dark"]>>; accentColor: z.ZodOptional<z.ZodString>; dangerColor: z.ZodOptional<z.ZodString>; grayColor: z.ZodOptional<z.ZodString>; infoColor: z.ZodOptional<z.ZodString>; successColor: z.ZodOptional<z.ZodString>; warningColor: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { appearance?: "light" | "dark" | undefined; accentColor?: string | undefined; dangerColor?: string | undefined; grayColor?: string | undefined; infoColor?: string | undefined; successColor?: string | undefined; warningColor?: string | undefined; }, { appearance?: "light" | "dark" | undefined; accentColor?: string | undefined; dangerColor?: string | undefined; grayColor?: string | undefined; infoColor?: string | undefined; successColor?: string | undefined; warningColor?: string | undefined; }>; }, "strip", z.ZodTypeAny, { event: "getColorTheme"; response: { appearance?: "light" | "dark" | undefined; accentColor?: string | undefined; dangerColor?: string | undefined; grayColor?: string | undefined; infoColor?: string | undefined; successColor?: string | undefined; warningColor?: string | undefined; }; request?: void | undefined; }, { event: "getColorTheme"; response: { appearance?: "light" | "dark" | undefined; accentColor?: string | undefined; dangerColor?: string | undefined; grayColor?: string | undefined; infoColor?: string | undefined; successColor?: string | undefined; warningColor?: string | undefined; }; request?: void | undefined; }>, z.ZodObject<{ event: z.ZodLiteral<"earliestUnreadNotification">; request: z.ZodObject<{ experienceId: z.ZodString; }, "strip", z.ZodTypeAny, { experienceId: string; }, { experienceId: string; }>; response: z.ZodNullable<z.ZodObject<{ externalId: z.ZodString; }, "strip", z.ZodTypeAny, { externalId: string; }, { externalId: string; }>>; }, "strip", z.ZodTypeAny, { event: "earliestUnreadNotification"; request: { experienceId: string; }; response: { externalId: string; } | null; }, { event: "earliestUnreadNotification"; request: { experienceId: string; }; response: { externalId: string; } | null; }>, z.ZodObject<{ event: z.ZodLiteral<"markExperienceRead">; request: z.ZodObject<{ experienceId: z.ZodString; notificationExternalId: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { experienceId: string; notificationExternalId?: string | undefined; }, { experienceId: string; notificationExternalId?: string | undefined; }>; response: z.ZodLiteral<"ok">; }, "strip", z.ZodTypeAny, { event: "markExperienceRead"; request: { experienceId: string; notificationExternalId?: string | undefined; }; response: "ok"; }, { event: "markExperienceRead"; request: { experienceId: string; notificationExternalId?: string | undefined; }; response: "ok"; }>, z.ZodObject<{ event: z.ZodLiteral<"performHaptic">; request: z.ZodObject<{ type: z.ZodEnum<["selection", "impact", "notification"]>; style: z.ZodEnum<["light", "medium", "heavy"]>; }, "strip", z.ZodTypeAny, { type: "selection" | "impact" | "notification"; style: "light" | "medium" | "heavy"; }, { type: "selection" | "impact" | "notification"; style: "light" | "medium" | "heavy"; }>; response: z.ZodLiteral<"ok">; }, "strip", z.ZodTypeAny, { event: "performHaptic"; request: { type: "selection" | "impact" | "notification"; style: "light" | "medium" | "heavy"; }; response: "ok"; }, { event: "performHaptic"; request: { type: "selection" | "impact" | "notification"; style: "light" | "medium" | "heavy"; }; response: "ok"; }>]>, true> & { _cleanupTransport: () => void; }; type WhopIframeSdk = ReturnType<typeof createSdk>; export { type WhopIframeSdk, appsServerSchema, createSdk, index as transport };