@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.
@@ -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 };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@whop/iframe",
3
+ "version": "0.0.1",
4
+ "main": "./dist/index.cjs",
5
+ "module": "./dist/index.mjs",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ },
16
+ "./host": {
17
+ "import": "./dist/host.mjs",
18
+ "require": "./dist/host.js",
19
+ "types": "./dist/host.d.ts"
20
+ }
21
+ },
22
+ "dependencies": {
23
+ "zod": "3.22.1"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "latest",
27
+ "tsup": "8.5.0",
28
+ "typescript": "latest"
29
+ },
30
+ "engines": {
31
+ "node": "22.x",
32
+ "pnpm": "9.15.9"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "scripts": {
38
+ "build": "tsup",
39
+ "dev": "tsup --watch",
40
+ "check-types": "tsc --noEmit",
41
+ "lint:fix": "biome check --write --unsafe"
42
+ }
43
+ }