@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.js
ADDED
|
@@ -0,0 +1,580 @@
|
|
|
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
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
appsServerSchema: () => appsServerSchema,
|
|
24
|
+
createSdk: () => createSdk,
|
|
25
|
+
transport: () => transport_exports,
|
|
26
|
+
whopServerSchema: () => whopServerSchema
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/sdk/apps-server.ts
|
|
31
|
+
var import_zod2 = require("zod");
|
|
32
|
+
|
|
33
|
+
// src/sdk/utils.ts
|
|
34
|
+
var import_zod = require("zod");
|
|
35
|
+
var withError = (schema, error) => {
|
|
36
|
+
return import_zod.z.discriminatedUnion("status", [
|
|
37
|
+
import_zod.z.object({
|
|
38
|
+
status: import_zod.z.literal("ok"),
|
|
39
|
+
data: schema
|
|
40
|
+
}),
|
|
41
|
+
import_zod.z.object({
|
|
42
|
+
status: import_zod.z.literal("error"),
|
|
43
|
+
error
|
|
44
|
+
})
|
|
45
|
+
]);
|
|
46
|
+
};
|
|
47
|
+
var frostedV2Theme = import_zod.z.object({
|
|
48
|
+
appearance: import_zod.z.enum(["light", "dark"]),
|
|
49
|
+
accentColor: import_zod.z.string(),
|
|
50
|
+
dangerColor: import_zod.z.string(),
|
|
51
|
+
grayColor: import_zod.z.string(),
|
|
52
|
+
infoColor: import_zod.z.string(),
|
|
53
|
+
successColor: import_zod.z.string(),
|
|
54
|
+
warningColor: import_zod.z.string()
|
|
55
|
+
}).partial();
|
|
56
|
+
|
|
57
|
+
// src/sdk/apps-server.ts
|
|
58
|
+
var appsServerSchema = import_zod2.z.discriminatedUnion("event", [
|
|
59
|
+
import_zod2.z.object({
|
|
60
|
+
event: import_zod2.z.literal("appPing"),
|
|
61
|
+
request: import_zod2.z.literal("app_ping"),
|
|
62
|
+
response: import_zod2.z.literal("app_pong")
|
|
63
|
+
}),
|
|
64
|
+
import_zod2.z.object({
|
|
65
|
+
event: import_zod2.z.literal("onColorThemeChange"),
|
|
66
|
+
request: frostedV2Theme,
|
|
67
|
+
response: import_zod2.z.void()
|
|
68
|
+
})
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
// src/sdk/mobile-app-postmessage.ts
|
|
72
|
+
function getReactNativePostMessage() {
|
|
73
|
+
const reactNativePostMessage = typeof window !== "undefined" && "ReactNativeWebView" in window && typeof window.ReactNativeWebView === "object" && window.ReactNativeWebView && "postMessage" in window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === "function" ? (data) => {
|
|
74
|
+
if (typeof window !== "undefined" && "ReactNativeWebView" in window && typeof window.ReactNativeWebView === "object" && window.ReactNativeWebView && "postMessage" in window.ReactNativeWebView && typeof window.ReactNativeWebView.postMessage === "function")
|
|
75
|
+
window?.ReactNativeWebView?.postMessage(data);
|
|
76
|
+
} : void 0;
|
|
77
|
+
return reactNativePostMessage;
|
|
78
|
+
}
|
|
79
|
+
function getSwiftPostMessage() {
|
|
80
|
+
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;
|
|
81
|
+
const swiftPostMessage = swiftMessageHandler ? (data) => {
|
|
82
|
+
if (typeof swiftMessageHandler.postMessage === "function") {
|
|
83
|
+
swiftMessageHandler.postMessage(data);
|
|
84
|
+
}
|
|
85
|
+
} : void 0;
|
|
86
|
+
return swiftPostMessage;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/sdk/sync-href.ts
|
|
90
|
+
function syncHref({
|
|
91
|
+
onChange
|
|
92
|
+
}) {
|
|
93
|
+
if (typeof window === "undefined") return;
|
|
94
|
+
const initialHref = window.location.href;
|
|
95
|
+
onChange({ href: initialHref }).catch(() => null);
|
|
96
|
+
let lastKnown = initialHref;
|
|
97
|
+
window.addEventListener("popstate", () => {
|
|
98
|
+
const { href } = window.location;
|
|
99
|
+
onChange({ href }).catch(() => null);
|
|
100
|
+
lastKnown = href;
|
|
101
|
+
});
|
|
102
|
+
if (window._whop_sync_href_interval) {
|
|
103
|
+
clearInterval(window._whop_sync_href_interval);
|
|
104
|
+
}
|
|
105
|
+
window._whop_sync_href_interval = setInterval(() => {
|
|
106
|
+
const { href } = window.location;
|
|
107
|
+
if (href === lastKnown) return;
|
|
108
|
+
onChange({ href }).catch(() => null);
|
|
109
|
+
lastKnown = href;
|
|
110
|
+
}, 250);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// src/sdk/transport/index.ts
|
|
114
|
+
var transport_exports = {};
|
|
115
|
+
__export(transport_exports, {
|
|
116
|
+
MESSAGE_TAG: () => MESSAGE_TAG,
|
|
117
|
+
TimeoutError: () => TimeoutError,
|
|
118
|
+
createHandler: () => createHandler,
|
|
119
|
+
createSDK: () => createSDK,
|
|
120
|
+
postmessageTransport: () => postmessageTransport
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// src/sdk/transport/utils.ts
|
|
124
|
+
var TimeoutError = class extends Error {
|
|
125
|
+
constructor() {
|
|
126
|
+
super("Timeout");
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function randomId(length) {
|
|
130
|
+
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
131
|
+
let str = "";
|
|
132
|
+
for (let i = 0; i < length; i++) {
|
|
133
|
+
str += alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
134
|
+
}
|
|
135
|
+
return str;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/sdk/transport/sdk.ts
|
|
139
|
+
function createSDK({
|
|
140
|
+
clientSchema,
|
|
141
|
+
serverSchema,
|
|
142
|
+
serverComplete,
|
|
143
|
+
transport,
|
|
144
|
+
timeout = 1e3,
|
|
145
|
+
timeouts,
|
|
146
|
+
localAppId,
|
|
147
|
+
remoteAppId,
|
|
148
|
+
serverImplementation = {},
|
|
149
|
+
serverMiddleware
|
|
150
|
+
}) {
|
|
151
|
+
const callbacks = [];
|
|
152
|
+
const keys = clientSchema?.options.map(
|
|
153
|
+
(option) => option._def.shape().event._def.value
|
|
154
|
+
) ?? [];
|
|
155
|
+
const client = Object.fromEntries(
|
|
156
|
+
keys.map((key) => [
|
|
157
|
+
key,
|
|
158
|
+
async (req) => {
|
|
159
|
+
const eventId = `${localAppId}:${key}:${randomId(8)}`;
|
|
160
|
+
console.debug("[typed-transport] app. Created eventId", eventId);
|
|
161
|
+
const responseData = new Promise((resolve, reject) => {
|
|
162
|
+
const customTimeout = timeouts?.[key];
|
|
163
|
+
const timeoutId = setTimeout(() => {
|
|
164
|
+
const index = callbacks.findIndex((cb) => cb.id === eventId);
|
|
165
|
+
if (index !== -1) callbacks.splice(index, 1);
|
|
166
|
+
if (serverComplete) {
|
|
167
|
+
console.debug("[typed-transport] app. Timeout error");
|
|
168
|
+
reject(new TimeoutError());
|
|
169
|
+
} else resolve(void 0);
|
|
170
|
+
}, customTimeout ?? timeout);
|
|
171
|
+
if (customTimeout && customTimeout > timeout && !serverComplete) {
|
|
172
|
+
const timeoutId2 = setTimeout(() => {
|
|
173
|
+
const index = callbacks.findIndex((cb) => cb.id === eventId);
|
|
174
|
+
if (index !== -1) callbacks.splice(index, 1);
|
|
175
|
+
resolve(void 0);
|
|
176
|
+
}, timeout);
|
|
177
|
+
callbacks.push({
|
|
178
|
+
id: `${eventId}:processing`,
|
|
179
|
+
resolve: () => clearTimeout(timeoutId2)
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
callbacks.push({
|
|
183
|
+
id: eventId,
|
|
184
|
+
resolve: (data2) => {
|
|
185
|
+
clearTimeout(timeoutId);
|
|
186
|
+
resolve(data2);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
console.debug("[typed-transport] app sending event", {
|
|
191
|
+
eventId,
|
|
192
|
+
localAppId,
|
|
193
|
+
remoteAppId
|
|
194
|
+
});
|
|
195
|
+
await transport.send?.(eventId, req, { localAppId, remoteAppId });
|
|
196
|
+
const data = await responseData;
|
|
197
|
+
console.debug("[typed-transport] received response", data);
|
|
198
|
+
return data;
|
|
199
|
+
}
|
|
200
|
+
])
|
|
201
|
+
);
|
|
202
|
+
const cleanupRecv = transport.recv(
|
|
203
|
+
async (event, dataAny) => {
|
|
204
|
+
const [app, key, _randomId, type] = event.split(":");
|
|
205
|
+
if (app === localAppId) {
|
|
206
|
+
const idx = callbacks.findIndex((cb2) => cb2.id === event);
|
|
207
|
+
if (idx === -1) return;
|
|
208
|
+
const dataSchema = clientSchema?.optionsMap.get(key);
|
|
209
|
+
if (!dataSchema) return;
|
|
210
|
+
const cb = callbacks[idx];
|
|
211
|
+
if (type === "processing") {
|
|
212
|
+
cb.resolve(void 0);
|
|
213
|
+
} else {
|
|
214
|
+
const data = dataSchema.shape.response.parse(dataAny);
|
|
215
|
+
callbacks.splice(idx, 1);
|
|
216
|
+
cb.resolve(data);
|
|
217
|
+
}
|
|
218
|
+
} else if (app === remoteAppId) {
|
|
219
|
+
if (serverImplementation === void 0) return;
|
|
220
|
+
let handler = serverImplementation[key];
|
|
221
|
+
if (serverMiddleware) {
|
|
222
|
+
for (let i = serverMiddleware.length - 1; i >= 0; i--) {
|
|
223
|
+
const middlewareDef = serverMiddleware[i];
|
|
224
|
+
const middleware = middlewareDef[key];
|
|
225
|
+
if (!middleware) continue;
|
|
226
|
+
const ref = handler;
|
|
227
|
+
handler = (data2) => middleware(data2, ref);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (!handler) return;
|
|
231
|
+
const dataSchema = serverSchema?.optionsMap.get(key);
|
|
232
|
+
if (!dataSchema) return;
|
|
233
|
+
const data = dataSchema.shape.request.parse(dataAny);
|
|
234
|
+
const timeoutId = setTimeout(async () => {
|
|
235
|
+
await transport.send(
|
|
236
|
+
`${event}:processing`,
|
|
237
|
+
{},
|
|
238
|
+
{ localAppId, remoteAppId }
|
|
239
|
+
);
|
|
240
|
+
}, 50);
|
|
241
|
+
const response = await handler(data);
|
|
242
|
+
clearTimeout(timeoutId);
|
|
243
|
+
await transport.send(event, response, { localAppId, remoteAppId });
|
|
244
|
+
return response;
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
localAppId,
|
|
249
|
+
remoteAppId
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
const cleanupFunctions = [];
|
|
253
|
+
if (transport.cleanup) cleanupFunctions.push(transport.cleanup);
|
|
254
|
+
if (cleanupRecv) cleanupFunctions.push(cleanupRecv);
|
|
255
|
+
client._cleanupTransport = () => {
|
|
256
|
+
for (const fn of cleanupFunctions) fn();
|
|
257
|
+
};
|
|
258
|
+
return client;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/sdk/transport/handler.ts
|
|
262
|
+
function createHandler({
|
|
263
|
+
schema,
|
|
264
|
+
forceCompleteness,
|
|
265
|
+
handlers
|
|
266
|
+
}) {
|
|
267
|
+
let eventHandler;
|
|
268
|
+
createSDK({
|
|
269
|
+
clientSchema: void 0,
|
|
270
|
+
serverSchema: schema,
|
|
271
|
+
localAppId: "client",
|
|
272
|
+
remoteAppId: "server",
|
|
273
|
+
forceCompleteness,
|
|
274
|
+
serverImplementation: handlers,
|
|
275
|
+
transport: {
|
|
276
|
+
send() {
|
|
277
|
+
},
|
|
278
|
+
recv(handler) {
|
|
279
|
+
eventHandler = handler;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
return (event, data) => {
|
|
284
|
+
return eventHandler(`server:${event}`, data);
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/sdk/transport/postmessage.ts
|
|
289
|
+
var MESSAGE_TAG = "typed-transport";
|
|
290
|
+
function postmessageTransport({
|
|
291
|
+
remoteWindow,
|
|
292
|
+
targetOrigins
|
|
293
|
+
}) {
|
|
294
|
+
return {
|
|
295
|
+
send(event, data, { remoteAppId, localAppId }) {
|
|
296
|
+
if (!remoteWindow) {
|
|
297
|
+
throw new Error(
|
|
298
|
+
"No remote window. Is the SDK running on a server without a global window object?"
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
console.debug(
|
|
302
|
+
"[typed-transport] postmessagetransport. Sending event",
|
|
303
|
+
event,
|
|
304
|
+
data
|
|
305
|
+
);
|
|
306
|
+
console.debug(
|
|
307
|
+
"[typed-transport] postmessagetransport. target origins =",
|
|
308
|
+
targetOrigins
|
|
309
|
+
);
|
|
310
|
+
for (const targetOrigin of targetOrigins) {
|
|
311
|
+
console.debug("[typed-transport] remoteWindow.postMessage", {
|
|
312
|
+
event,
|
|
313
|
+
libId: MESSAGE_TAG,
|
|
314
|
+
receiverAppId: remoteAppId,
|
|
315
|
+
senderAppId: localAppId
|
|
316
|
+
});
|
|
317
|
+
console.debug(
|
|
318
|
+
"[typed-transport] remoteWindow.postMessage.data",
|
|
319
|
+
data,
|
|
320
|
+
JSON.stringify(data)
|
|
321
|
+
);
|
|
322
|
+
remoteWindow.postMessage(
|
|
323
|
+
{
|
|
324
|
+
event,
|
|
325
|
+
data,
|
|
326
|
+
libId: MESSAGE_TAG,
|
|
327
|
+
receiverAppId: remoteAppId,
|
|
328
|
+
senderAppId: localAppId
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
targetOrigin
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
if (targetOrigins.length === 0) {
|
|
336
|
+
remoteWindow.postMessage({
|
|
337
|
+
event,
|
|
338
|
+
data,
|
|
339
|
+
libId: MESSAGE_TAG,
|
|
340
|
+
receiverAppId: remoteAppId,
|
|
341
|
+
senderAppId: localAppId
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
recv(handler, { localAppId, remoteAppId }) {
|
|
346
|
+
const listener = (event) => {
|
|
347
|
+
console.debug(
|
|
348
|
+
"[typed-transport] postmessagetransport. Receiving event",
|
|
349
|
+
event
|
|
350
|
+
);
|
|
351
|
+
if (event.source !== remoteWindow || !targetOrigins.includes(event.origin) && targetOrigins.length > 0 || !event.data || !event.data.event || event.data.libId !== MESSAGE_TAG || event.data.receiverAppId !== localAppId || event.data.senderAppId !== remoteAppId) {
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
handler(event.data.event, event.data.data);
|
|
355
|
+
};
|
|
356
|
+
if (typeof window === "undefined") {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
window.addEventListener("message", listener);
|
|
360
|
+
return () => {
|
|
361
|
+
window.removeEventListener("message", listener);
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function reactNativeClientTransport({
|
|
367
|
+
postMessage,
|
|
368
|
+
targetOrigin
|
|
369
|
+
}) {
|
|
370
|
+
return {
|
|
371
|
+
send(event, data, { remoteAppId, localAppId }) {
|
|
372
|
+
postMessage(
|
|
373
|
+
JSON.stringify({
|
|
374
|
+
event,
|
|
375
|
+
data,
|
|
376
|
+
libId: MESSAGE_TAG,
|
|
377
|
+
receiverAppId: remoteAppId,
|
|
378
|
+
senderAppId: localAppId
|
|
379
|
+
})
|
|
380
|
+
);
|
|
381
|
+
},
|
|
382
|
+
recv(handler, { localAppId, remoteAppId }) {
|
|
383
|
+
const listener = (event) => {
|
|
384
|
+
const dataString = typeof event.data === "string" ? event.data : null;
|
|
385
|
+
if (!dataString) return;
|
|
386
|
+
const data = JSON.parse(dataString);
|
|
387
|
+
if (event.origin !== targetOrigin || !data || !data.event || !data.data || data.libId !== MESSAGE_TAG || data.receiverAppId !== localAppId || data.senderAppId !== remoteAppId) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
handler(data.event, data.data);
|
|
391
|
+
};
|
|
392
|
+
if (typeof window === "undefined") {
|
|
393
|
+
console.warn(
|
|
394
|
+
"No window. Is the SDK running on a server without a global window object?"
|
|
395
|
+
);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
window.addEventListener("message", listener);
|
|
399
|
+
return () => {
|
|
400
|
+
window.removeEventListener("message", listener);
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// src/sdk/whop-server.ts
|
|
407
|
+
var import_zod3 = require("zod");
|
|
408
|
+
var whopServerSchema = import_zod3.z.discriminatedUnion("event", [
|
|
409
|
+
import_zod3.z.object({
|
|
410
|
+
event: import_zod3.z.literal("ping"),
|
|
411
|
+
request: import_zod3.z.literal("ping"),
|
|
412
|
+
response: import_zod3.z.literal("pong")
|
|
413
|
+
}),
|
|
414
|
+
import_zod3.z.object({
|
|
415
|
+
event: import_zod3.z.literal("getTopLevelUrlData"),
|
|
416
|
+
request: import_zod3.z.object({}).optional(),
|
|
417
|
+
response: import_zod3.z.object({
|
|
418
|
+
companyRoute: import_zod3.z.string(),
|
|
419
|
+
experienceRoute: import_zod3.z.string(),
|
|
420
|
+
experienceId: import_zod3.z.string(),
|
|
421
|
+
viewType: import_zod3.z.enum(["app", "admin", "analytics", "preview"]),
|
|
422
|
+
baseHref: import_zod3.z.string(),
|
|
423
|
+
fullHref: import_zod3.z.string()
|
|
424
|
+
})
|
|
425
|
+
}),
|
|
426
|
+
import_zod3.z.object({
|
|
427
|
+
event: import_zod3.z.literal("openExternalUrl"),
|
|
428
|
+
request: import_zod3.z.object({
|
|
429
|
+
newTab: import_zod3.z.boolean().optional(),
|
|
430
|
+
url: import_zod3.z.string()
|
|
431
|
+
}),
|
|
432
|
+
response: import_zod3.z.literal("ok")
|
|
433
|
+
}),
|
|
434
|
+
import_zod3.z.object({
|
|
435
|
+
event: import_zod3.z.literal("onHrefChange"),
|
|
436
|
+
request: import_zod3.z.object({
|
|
437
|
+
href: import_zod3.z.string()
|
|
438
|
+
}),
|
|
439
|
+
response: import_zod3.z.literal("ok")
|
|
440
|
+
}),
|
|
441
|
+
import_zod3.z.object({
|
|
442
|
+
event: import_zod3.z.literal("inAppPurchase"),
|
|
443
|
+
request: import_zod3.z.object({
|
|
444
|
+
/**
|
|
445
|
+
* ID returned from the `chargeUser` API call.
|
|
446
|
+
* @example "ch_1234567890"
|
|
447
|
+
*/
|
|
448
|
+
id: import_zod3.z.string().optional(),
|
|
449
|
+
/**
|
|
450
|
+
* ID of the plan returned from the `chargeUser` API call.
|
|
451
|
+
* @example "plan_1234567890"
|
|
452
|
+
*/
|
|
453
|
+
planId: import_zod3.z.string()
|
|
454
|
+
}),
|
|
455
|
+
response: withError(
|
|
456
|
+
import_zod3.z.object({
|
|
457
|
+
sessionId: import_zod3.z.string(),
|
|
458
|
+
/**
|
|
459
|
+
* The receipt ID can be used to verify the purchase.
|
|
460
|
+
*
|
|
461
|
+
* NOTE: When receiving payments you should always listen to webhooks as a fallback
|
|
462
|
+
* to process the payment. Do not solely rely on the client to process payments. The receipt ID
|
|
463
|
+
* can be used to deduplicate payment events.
|
|
464
|
+
*/
|
|
465
|
+
receiptId: import_zod3.z.string()
|
|
466
|
+
}),
|
|
467
|
+
import_zod3.z.string()
|
|
468
|
+
)
|
|
469
|
+
}),
|
|
470
|
+
import_zod3.z.object({
|
|
471
|
+
event: import_zod3.z.literal("closeApp"),
|
|
472
|
+
request: import_zod3.z.null(),
|
|
473
|
+
response: import_zod3.z.literal("ok")
|
|
474
|
+
}),
|
|
475
|
+
import_zod3.z.object({
|
|
476
|
+
event: import_zod3.z.literal("openHelpChat"),
|
|
477
|
+
request: import_zod3.z.null(),
|
|
478
|
+
response: import_zod3.z.literal("ok")
|
|
479
|
+
}),
|
|
480
|
+
import_zod3.z.object({
|
|
481
|
+
event: import_zod3.z.literal("getColorTheme"),
|
|
482
|
+
request: import_zod3.z.void(),
|
|
483
|
+
response: frostedV2Theme
|
|
484
|
+
}),
|
|
485
|
+
import_zod3.z.object({
|
|
486
|
+
event: import_zod3.z.literal("earliestUnreadNotification"),
|
|
487
|
+
request: import_zod3.z.object({
|
|
488
|
+
experienceId: import_zod3.z.string()
|
|
489
|
+
}),
|
|
490
|
+
response: import_zod3.z.object({
|
|
491
|
+
externalId: import_zod3.z.string()
|
|
492
|
+
}).nullable()
|
|
493
|
+
}),
|
|
494
|
+
import_zod3.z.object({
|
|
495
|
+
event: import_zod3.z.literal("markExperienceRead"),
|
|
496
|
+
request: import_zod3.z.object({
|
|
497
|
+
experienceId: import_zod3.z.string(),
|
|
498
|
+
notificationExternalId: import_zod3.z.string().optional()
|
|
499
|
+
}),
|
|
500
|
+
response: import_zod3.z.literal("ok")
|
|
501
|
+
}),
|
|
502
|
+
import_zod3.z.object({
|
|
503
|
+
event: import_zod3.z.literal("performHaptic"),
|
|
504
|
+
request: import_zod3.z.object({
|
|
505
|
+
type: import_zod3.z.enum(["selection", "impact", "notification"]),
|
|
506
|
+
style: import_zod3.z.enum(["light", "medium", "heavy"])
|
|
507
|
+
}),
|
|
508
|
+
response: import_zod3.z.literal("ok")
|
|
509
|
+
})
|
|
510
|
+
]);
|
|
511
|
+
|
|
512
|
+
// src/sdk/index.ts
|
|
513
|
+
function setColorTheme(theme) {
|
|
514
|
+
document.documentElement.dispatchEvent(
|
|
515
|
+
new CustomEvent("frosted-ui:set-theme", {
|
|
516
|
+
detail: theme
|
|
517
|
+
})
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
function createSdk({
|
|
521
|
+
onMessage = {},
|
|
522
|
+
appId = process.env.NEXT_PUBLIC_WHOP_APP_ID,
|
|
523
|
+
overrideParentOrigins
|
|
524
|
+
}) {
|
|
525
|
+
const mobileWebView = getSwiftPostMessage() ?? getReactNativePostMessage();
|
|
526
|
+
const remoteWindow = typeof window === "undefined" ? void 0 : window.parent;
|
|
527
|
+
if (!appId) {
|
|
528
|
+
throw new Error(
|
|
529
|
+
"[createSdk]: appId is required. Please provide an appId or set the NEXT_PUBLIC_WHOP_APP_ID environment variable."
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
const sdk = createSDK({
|
|
533
|
+
clientSchema: whopServerSchema,
|
|
534
|
+
serverSchema: appsServerSchema,
|
|
535
|
+
forceCompleteness: false,
|
|
536
|
+
serverImplementation: onMessage,
|
|
537
|
+
localAppId: appId,
|
|
538
|
+
remoteAppId: "app_whop",
|
|
539
|
+
transport: mobileWebView ? reactNativeClientTransport({
|
|
540
|
+
postMessage: mobileWebView,
|
|
541
|
+
targetOrigin: "com.whop.whopapp"
|
|
542
|
+
}) : postmessageTransport({
|
|
543
|
+
remoteWindow,
|
|
544
|
+
targetOrigins: overrideParentOrigins ?? [
|
|
545
|
+
"https://whop.com",
|
|
546
|
+
"https://dash.whop.com",
|
|
547
|
+
"http://localhost:8003"
|
|
548
|
+
]
|
|
549
|
+
}),
|
|
550
|
+
serverComplete: true,
|
|
551
|
+
serverMiddleware: [
|
|
552
|
+
{
|
|
553
|
+
onColorThemeChange: setColorTheme
|
|
554
|
+
}
|
|
555
|
+
],
|
|
556
|
+
timeout: 15e3,
|
|
557
|
+
timeouts: {
|
|
558
|
+
inAppPurchase: 1e3 * 60 * 60 * 24,
|
|
559
|
+
// 24 hours, we never want this to timeout.
|
|
560
|
+
onHrefChange: 500
|
|
561
|
+
// we don't really care about a response here.
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
if (typeof window !== "undefined") {
|
|
565
|
+
sdk.getColorTheme().then(setColorTheme).catch(() => null);
|
|
566
|
+
document.documentElement.addEventListener("frosted-ui:mounted", () => {
|
|
567
|
+
sdk.getColorTheme().then(setColorTheme).catch(() => null);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
syncHref({ onChange: sdk.onHrefChange });
|
|
571
|
+
return sdk;
|
|
572
|
+
}
|
|
573
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
574
|
+
0 && (module.exports = {
|
|
575
|
+
appsServerSchema,
|
|
576
|
+
createSdk,
|
|
577
|
+
transport,
|
|
578
|
+
whopServerSchema
|
|
579
|
+
});
|
|
580
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/sdk/apps-server.ts","../src/sdk/utils.ts","../src/sdk/mobile-app-postmessage.ts","../src/sdk/sync-href.ts","../src/sdk/transport/index.ts","../src/sdk/transport/utils.ts","../src/sdk/transport/sdk.ts","../src/sdk/transport/handler.ts","../src/sdk/transport/postmessage.ts","../src/sdk/whop-server.ts","../src/sdk/index.ts"],"sourcesContent":["export * from \"@/sdk\";\nexport * as transport from \"@/sdk/transport\";\n","import { z } from \"zod\";\nimport { frostedV2Theme } from \"./utils\";\n\nexport const appsServerSchema = z.discriminatedUnion(\"event\", [\n\tz.object({\n\t\tevent: z.literal(\"appPing\"),\n\t\trequest: z.literal(\"app_ping\"),\n\t\tresponse: z.literal(\"app_pong\"),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"onColorThemeChange\"),\n\t\trequest: frostedV2Theme,\n\t\tresponse: z.void(),\n\t}),\n]);\n\nexport type AppsServerSchema = z.TypeOf<typeof appsServerSchema>;\n","import { type ZodSchema, z } from \"zod\";\n\nexport const withError = <T extends ZodSchema, E extends ZodSchema>(\n\tschema: T,\n\terror: E,\n) => {\n\treturn z.discriminatedUnion(\"status\", [\n\t\tz.object({\n\t\t\tstatus: z.literal(\"ok\"),\n\t\t\tdata: schema,\n\t\t}),\n\t\tz.object({\n\t\t\tstatus: z.literal(\"error\"),\n\t\t\terror: error,\n\t\t}),\n\t]);\n};\n\nexport const frostedV2Theme = z\n\t.object({\n\t\tappearance: z.enum([\"light\", \"dark\"]),\n\t\taccentColor: z.string(),\n\t\tdangerColor: z.string(),\n\t\tgrayColor: z.string(),\n\t\tinfoColor: z.string(),\n\t\tsuccessColor: z.string(),\n\t\twarningColor: z.string(),\n\t})\n\t.partial();\n","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","export { createHandler } from \"./handler\";\nexport { MESSAGE_TAG, postmessageTransport } from \"./postmessage\";\nexport { createSDK } from \"./sdk\";\n\nexport type {\n\tClientSDK,\n\tServerImplementation,\n\tTransport,\n\tValidZodEventSchema,\n} from \"./sdk\";\n\nexport { TimeoutError } from \"./utils\";\n","export class TimeoutError extends Error {\n\tconstructor() {\n\t\tsuper(\"Timeout\");\n\t}\n}\n\nexport function randomId(length: number) {\n\tconst alphabet =\n\t\t\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\";\n\tlet str = \"\";\n\tfor (let i = 0; i < length; i++) {\n\t\tstr += alphabet[Math.floor(Math.random() * alphabet.length)];\n\t}\n\treturn str;\n}\n","import type {\n\tZodDiscriminatedUnion,\n\tZodLiteral,\n\tZodObject,\n\tZodRawShape,\n\tZodTypeAny,\n\tz,\n} from \"zod\";\nimport { TimeoutError, randomId } from \"./utils\";\n\nexport type ValidZodEventSchema = ZodDiscriminatedUnion<\n\t\"event\",\n\tZodObject<\n\t\t{\n\t\t\tevent: ZodLiteral<string>;\n\t\t\trequest: ZodTypeAny;\n\t\t\tresponse: ZodTypeAny;\n\t\t} & ZodRawShape\n\t>[]\n>;\n\ntype MaybePromise<T> = Promise<T> | T;\n\ntype T = z.infer<ValidZodEventSchema>;\n\ntype FullServerImplementation<Schema extends ValidZodEventSchema> = {\n\t[K in NonNullable<z.infer<Schema>[\"event\"]>]: (\n\t\trequest: Extract<z.infer<Schema>, { event: K }>[\"request\"],\n\t) => MaybePromise<Extract<z.infer<Schema>, { event: K }>[\"response\"]>;\n};\n\nexport type ClientSDK<\n\tClientSchema extends ValidZodEventSchema,\n\tComplete extends boolean,\n> = {\n\t[K in NonNullable<z.infer<ClientSchema>[\"event\"]>]: (\n\t\treq: Extract<z.infer<ClientSchema>, { event: K }>[\"request\"],\n\t) => Promise<\n\t\tComplete extends true\n\t\t\t? Extract<z.infer<ClientSchema>, { event: K }>[\"response\"]\n\t\t\t: Extract<z.infer<ClientSchema>, { event: K }>[\"response\"] | undefined\n\t>;\n};\n\nexport type ServerImplementation<\n\tSchema extends ValidZodEventSchema,\n\tForceCompleteness extends boolean = false,\n> = ForceCompleteness extends true\n\t? FullServerImplementation<Schema>\n\t: Partial<FullServerImplementation<Schema>>;\n\ntype FullServerMiddlewareImplementation<\n\tSchema extends ValidZodEventSchema,\n\tForceCompleteness extends boolean = false,\n> = {\n\t[K in NonNullable<z.infer<Schema>[\"event\"]>]: (\n\t\trequest: Extract<z.infer<Schema>, { event: K }>[\"request\"],\n\t\tnext: ForceCompleteness extends true\n\t\t\t? (\n\t\t\t\t\trequest: Extract<z.infer<Schema>, { event: K }>[\"request\"],\n\t\t\t\t) => MaybePromise<Extract<z.infer<Schema>, { event: K }>[\"response\"]>\n\t\t\t:\n\t\t\t\t\t| ((\n\t\t\t\t\t\t\trequest: Extract<z.infer<Schema>, { event: K }>[\"request\"],\n\t\t\t\t\t ) => MaybePromise<\n\t\t\t\t\t\t\tExtract<z.infer<Schema>, { event: K }>[\"response\"]\n\t\t\t\t\t >)\n\t\t\t\t\t| undefined,\n\t) => MaybePromise<\n\t\tForceCompleteness extends true\n\t\t\t? Extract<z.infer<Schema>, { event: K }>[\"response\"]\n\t\t\t: Extract<z.infer<Schema>, { event: K }>[\"response\"] | undefined\n\t>;\n};\nexport type ServerMiddleware<\n\tSchema extends ValidZodEventSchema,\n\tForceCompleteness extends boolean = false,\n> = Partial<FullServerMiddlewareImplementation<Schema, ForceCompleteness>>;\n\nexport type Transport<ServerSchema extends ValidZodEventSchema | undefined> = {\n\tsend: (\n\t\tevent: string,\n\t\tdata: unknown,\n\t\tparams: { localAppId: string; remoteAppId: string },\n\t) => unknown;\n\trecv: (\n\t\thandler: (\n\t\t\tevent: string,\n\t\t\tdata: unknown,\n\t\t) => Promise<\n\t\t\t| (ServerSchema extends ValidZodEventSchema\n\t\t\t\t\t? z.infer<ServerSchema>[\"response\"]\n\t\t\t\t\t: undefined)\n\t\t\t| undefined\n\t\t>,\n\t\tparams: { localAppId: string; remoteAppId: string },\n\t\t// biome-ignore lint/suspicious/noConfusingVoidType: idk\n\t) => void | (() => void);\n\tcleanup?: () => void;\n};\n\nexport function createSDK<\n\tClientSchema extends ValidZodEventSchema | undefined,\n\tServerSchema extends ValidZodEventSchema | undefined,\n\tForceCompleteness extends boolean = false,\n\tServerComplete extends boolean = false,\n>({\n\tclientSchema,\n\tserverSchema,\n\tserverComplete,\n\ttransport,\n\ttimeout = 1000,\n\ttimeouts,\n\tlocalAppId,\n\tremoteAppId,\n\tserverImplementation = {},\n\tserverMiddleware,\n}: {\n\tclientSchema: ClientSchema;\n\tserverSchema: ServerSchema;\n\tforceCompleteness?: ForceCompleteness;\n\tserverComplete?: ServerComplete;\n\tlocalAppId: string;\n\tremoteAppId: string;\n\tserverMiddleware?: ServerSchema extends ValidZodEventSchema\n\t\t? ServerMiddleware<ServerSchema, ForceCompleteness>[]\n\t\t: undefined;\n\tserverImplementation: ServerSchema extends ValidZodEventSchema\n\t\t? ServerImplementation<ServerSchema, ForceCompleteness>\n\t\t: undefined;\n\ttransport: Transport<ServerSchema>;\n\ttimeout?: number;\n\ttimeouts?: ClientSchema extends ValidZodEventSchema\n\t\t? {\n\t\t\t\t[K in NonNullable<z.infer<ClientSchema>[\"event\"]>]?: number;\n\t\t\t}\n\t\t: never;\n}): (ClientSchema extends ValidZodEventSchema\n\t? ClientSDK<ClientSchema, ServerComplete>\n\t: object) & {\n\t_cleanupTransport: () => void;\n} {\n\tconst callbacks: {\n\t\tid: string;\n\t\tresolve: (data: unknown) => void;\n\t}[] = [];\n\n\tconst keys =\n\t\tclientSchema?.options.map(\n\t\t\t(option) => option._def.shape().event._def.value,\n\t\t) ?? [];\n\n\tconst client = Object.fromEntries(\n\t\tkeys.map((key) => [\n\t\t\tkey,\n\t\t\tasync (req: unknown) => {\n\t\t\t\t// We make event id unique so that we can fire many requests at the same time.\n\t\t\t\tconst eventId = `${localAppId}:${key}:${randomId(8)}`;\n\n\t\t\t\tconsole.debug(\"[typed-transport] app. Created eventId\", eventId);\n\n\t\t\t\tconst responseData = new Promise((resolve, reject) => {\n\t\t\t\t\t// Timeout the request after the specified timeout\n\t\t\t\t\tconst customTimeout = timeouts?.[key];\n\n\t\t\t\t\tconst timeoutId = setTimeout(() => {\n\t\t\t\t\t\tconst index = callbacks.findIndex((cb) => cb.id === eventId);\n\t\t\t\t\t\tif (index !== -1) callbacks.splice(index, 1);\n\t\t\t\t\t\tif (serverComplete) {\n\t\t\t\t\t\t\tconsole.debug(\"[typed-transport] app. Timeout error\");\n\t\t\t\t\t\t\treject(new TimeoutError());\n\t\t\t\t\t\t} else resolve(undefined);\n\t\t\t\t\t}, customTimeout ?? timeout);\n\n\t\t\t\t\tif (customTimeout && customTimeout > timeout && !serverComplete) {\n\t\t\t\t\t\tconst timeoutId = setTimeout(() => {\n\t\t\t\t\t\t\tconst index = callbacks.findIndex((cb) => cb.id === eventId);\n\t\t\t\t\t\t\tif (index !== -1) callbacks.splice(index, 1);\n\t\t\t\t\t\t\tresolve(undefined);\n\t\t\t\t\t\t}, timeout);\n\t\t\t\t\t\tcallbacks.push({\n\t\t\t\t\t\t\tid: `${eventId}:processing`,\n\t\t\t\t\t\t\tresolve: () => clearTimeout(timeoutId),\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tcallbacks.push({\n\t\t\t\t\t\tid: eventId,\n\t\t\t\t\t\tresolve: (data) => {\n\t\t\t\t\t\t\tclearTimeout(timeoutId);\n\t\t\t\t\t\t\tresolve(data);\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\tconsole.debug(\"[typed-transport] app sending event\", {\n\t\t\t\t\teventId,\n\t\t\t\t\tlocalAppId,\n\t\t\t\t\tremoteAppId,\n\t\t\t\t});\n\t\t\t\tawait transport.send?.(eventId, req, { localAppId, remoteAppId });\n\n\t\t\t\tconst data = await responseData;\n\n\t\t\t\tconsole.debug(\"[typed-transport] received response\", data);\n\n\t\t\t\treturn data;\n\t\t\t},\n\t\t]),\n\t) as (ClientSchema extends ValidZodEventSchema\n\t\t? ClientSDK<ClientSchema, ServerComplete>\n\t\t: object) & {\n\t\t_cleanupTransport: () => void;\n\t};\n\n\tconst cleanupRecv = transport.recv(\n\t\tasync (event, dataAny) => {\n\t\t\tconst [app, key, _randomId, type] = event.split(\":\");\n\t\t\tif (app === localAppId) {\n\t\t\t\t// Here we are receiving a response from a request we made.\n\t\t\t\tconst idx = callbacks.findIndex((cb) => cb.id === event);\n\t\t\t\tif (idx === -1) return;\n\t\t\t\tconst dataSchema = clientSchema?.optionsMap.get(key);\n\t\t\t\tif (!dataSchema) return;\n\t\t\t\tconst cb = callbacks[idx];\n\t\t\t\tif (type === \"processing\") {\n\t\t\t\t\tcb.resolve(undefined);\n\t\t\t\t} else {\n\t\t\t\t\tconst data = dataSchema.shape.response.parse(dataAny);\n\t\t\t\t\tcallbacks.splice(idx, 1);\n\t\t\t\t\tcb.resolve(data);\n\t\t\t\t}\n\t\t\t} else if (app === remoteAppId) {\n\t\t\t\tif (serverImplementation === undefined) return;\n\t\t\t\t// Here we are responding to a request from a client.\n\n\t\t\t\t// final handler\n\t\t\t\tlet handler = (\n\t\t\t\t\tserverImplementation as unknown as Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t(data: unknown) => Promise<unknown>\n\t\t\t\t\t>\n\t\t\t\t)[key];\n\n\t\t\t\t// Build a linked list of middleware invocations that will call the final handler.\n\t\t\t\tif (serverMiddleware) {\n\t\t\t\t\tfor (let i = serverMiddleware.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tconst middlewareDef = serverMiddleware[i];\n\t\t\t\t\t\tconst middleware = middlewareDef[key] as (\n\t\t\t\t\t\t\tdata: unknown,\n\t\t\t\t\t\t\tnext: unknown,\n\t\t\t\t\t\t) => Promise<unknown>;\n\t\t\t\t\t\tif (!middleware) continue;\n\t\t\t\t\t\tconst ref = handler;\n\t\t\t\t\t\thandler = (data: unknown) => middleware(data, ref);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!handler) return;\n\t\t\t\tconst dataSchema = serverSchema?.optionsMap.get(key);\n\t\t\t\tif (!dataSchema) return;\n\t\t\t\tconst data = dataSchema.shape.request.parse(dataAny);\n\n\t\t\t\t// If our handler doesn't complete in 80% of the default message timeout, we send a message to the caller, saying that we are expecting an answer.\n\t\t\t\tconst timeoutId = setTimeout(async () => {\n\t\t\t\t\tawait transport.send(\n\t\t\t\t\t\t`${event}:processing`,\n\t\t\t\t\t\t{},\n\t\t\t\t\t\t{ localAppId, remoteAppId },\n\t\t\t\t\t);\n\t\t\t\t}, 50);\n\n\t\t\t\tconst response = await handler(data);\n\n\t\t\t\tclearTimeout(timeoutId);\n\n\t\t\t\tawait transport.send(event, response, { localAppId, remoteAppId });\n\t\t\t\t// biome-ignore lint/suspicious/noExplicitAny: will fix at some point\n\t\t\t\treturn response as any;\n\t\t\t}\n\t\t},\n\t\t{\n\t\t\tlocalAppId,\n\t\t\tremoteAppId,\n\t\t},\n\t);\n\n\tconst cleanupFunctions: (() => void)[] = [];\n\tif (transport.cleanup) cleanupFunctions.push(transport.cleanup);\n\tif (cleanupRecv) cleanupFunctions.push(cleanupRecv);\n\n\tclient._cleanupTransport = () => {\n\t\tfor (const fn of cleanupFunctions) fn();\n\t};\n\n\treturn client;\n}\n","import type { z } from \"zod\";\nimport {\n\ttype ServerImplementation,\n\ttype ValidZodEventSchema,\n\tcreateSDK,\n} from \"./sdk\";\n\nexport function createHandler<\n\tSchema extends ValidZodEventSchema,\n\tForceCompleteness extends boolean = false,\n>({\n\tschema,\n\tforceCompleteness,\n\thandlers,\n}: {\n\tschema: Schema;\n\tforceCompleteness?: ForceCompleteness;\n\thandlers: Schema extends ValidZodEventSchema\n\t\t? ServerImplementation<Schema, ForceCompleteness>\n\t\t: undefined;\n}) {\n\tlet eventHandler: (\n\t\tevent: string,\n\t\tdata: unknown,\n\t) => Promise<\n\t\t| (Schema extends ValidZodEventSchema\n\t\t\t\t? z.TypeOf<Schema>[\"response\"]\n\t\t\t\t: undefined)\n\t\t| undefined\n\t>;\n\n\tcreateSDK<undefined, Schema, ForceCompleteness, false>({\n\t\tclientSchema: undefined,\n\t\tserverSchema: schema,\n\t\tlocalAppId: \"client\",\n\t\tremoteAppId: \"server\",\n\t\tforceCompleteness,\n\t\tserverImplementation: handlers,\n\t\ttransport: {\n\t\t\tsend() {\n\t\t\t\t// empty, only handling incoming events\n\t\t\t},\n\t\t\trecv(handler) {\n\t\t\t\teventHandler = handler;\n\t\t\t},\n\t\t},\n\t});\n\n\treturn (event: string, data: unknown) => {\n\t\treturn eventHandler(`server:${event}`, data);\n\t};\n}\n","import type { Transport, ValidZodEventSchema } from \"./sdk\";\n\nexport const MESSAGE_TAG = \"typed-transport\";\n\nexport function postmessageTransport<\n\tServerSchema extends ValidZodEventSchema | undefined = undefined,\n>({\n\tremoteWindow,\n\ttargetOrigins,\n}: {\n\tremoteWindow: Window | undefined;\n\ttargetOrigins: string[];\n}): Transport<ServerSchema> {\n\treturn {\n\t\tsend(event, data, { remoteAppId, localAppId }) {\n\t\t\tif (!remoteWindow) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"No remote window. Is the SDK running on a server without a global window object?\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconsole.debug(\n\t\t\t\t\"[typed-transport] postmessagetransport. Sending event\",\n\t\t\t\tevent,\n\t\t\t\tdata,\n\t\t\t);\n\t\t\tconsole.debug(\n\t\t\t\t\"[typed-transport] postmessagetransport. target origins =\",\n\t\t\t\ttargetOrigins,\n\t\t\t);\n\n\t\t\tfor (const targetOrigin of targetOrigins) {\n\t\t\t\tconsole.debug(\"[typed-transport] remoteWindow.postMessage\", {\n\t\t\t\t\tevent,\n\t\t\t\t\tlibId: MESSAGE_TAG,\n\t\t\t\t\treceiverAppId: remoteAppId,\n\t\t\t\t\tsenderAppId: localAppId,\n\t\t\t\t});\n\t\t\t\tconsole.debug(\n\t\t\t\t\t\"[typed-transport] remoteWindow.postMessage.data\",\n\t\t\t\t\tdata,\n\t\t\t\t\tJSON.stringify(data),\n\t\t\t\t);\n\n\t\t\t\tremoteWindow.postMessage(\n\t\t\t\t\t{\n\t\t\t\t\t\tevent,\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tlibId: MESSAGE_TAG,\n\t\t\t\t\t\treceiverAppId: remoteAppId,\n\t\t\t\t\t\tsenderAppId: localAppId,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\ttargetOrigin,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (targetOrigins.length === 0) {\n\t\t\t\tremoteWindow.postMessage({\n\t\t\t\t\tevent,\n\t\t\t\t\tdata,\n\t\t\t\t\tlibId: MESSAGE_TAG,\n\t\t\t\t\treceiverAppId: remoteAppId,\n\t\t\t\t\tsenderAppId: localAppId,\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\trecv(handler, { localAppId, remoteAppId }) {\n\t\t\tconst listener = (event: MessageEvent) => {\n\t\t\t\tconsole.debug(\n\t\t\t\t\t\"[typed-transport] postmessagetransport. Receiving event\",\n\t\t\t\t\tevent,\n\t\t\t\t);\n\n\t\t\t\tif (\n\t\t\t\t\tevent.source !== remoteWindow ||\n\t\t\t\t\t(!targetOrigins.includes(event.origin) && targetOrigins.length > 0) ||\n\t\t\t\t\t!event.data ||\n\t\t\t\t\t!event.data.event ||\n\t\t\t\t\tevent.data.libId !== MESSAGE_TAG ||\n\t\t\t\t\tevent.data.receiverAppId !== localAppId ||\n\t\t\t\t\tevent.data.senderAppId !== remoteAppId\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\thandler(event.data.event, event.data.data);\n\t\t\t};\n\n\t\t\tif (typeof window === \"undefined\") {\n\t\t\t\t// Stop logging this as it's causing more confusion than it's worth.\n\t\t\t\t// console.warn(\n\t\t\t\t// 'No window. Is the SDK running on a server without a global window object?',\n\t\t\t\t// );\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\twindow.addEventListener(\"message\", listener);\n\n\t\t\treturn () => {\n\t\t\t\twindow.removeEventListener(\"message\", listener);\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport function reactNativeClientTransport<\n\tServerSchema extends ValidZodEventSchema | undefined = undefined,\n>({\n\tpostMessage,\n\ttargetOrigin,\n}: {\n\tpostMessage: (data: string) => void;\n\ttargetOrigin: string;\n}): Transport<ServerSchema> {\n\treturn {\n\t\tsend(event, data, { remoteAppId, localAppId }) {\n\t\t\tpostMessage(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tevent,\n\t\t\t\t\tdata,\n\t\t\t\t\tlibId: MESSAGE_TAG,\n\t\t\t\t\treceiverAppId: remoteAppId,\n\t\t\t\t\tsenderAppId: localAppId,\n\t\t\t\t}),\n\t\t\t);\n\t\t},\n\t\trecv(handler, { localAppId, remoteAppId }) {\n\t\t\tconst listener = (event: MessageEvent) => {\n\t\t\t\tconst dataString = typeof event.data === \"string\" ? event.data : null;\n\t\t\t\tif (!dataString) return;\n\n\t\t\t\tconst data = JSON.parse(dataString);\n\n\t\t\t\tif (\n\t\t\t\t\tevent.origin !== targetOrigin ||\n\t\t\t\t\t!data ||\n\t\t\t\t\t!data.event ||\n\t\t\t\t\t!data.data ||\n\t\t\t\t\tdata.libId !== MESSAGE_TAG ||\n\t\t\t\t\tdata.receiverAppId !== localAppId ||\n\t\t\t\t\tdata.senderAppId !== remoteAppId\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\thandler(data.event, data.data);\n\t\t\t};\n\n\t\t\tif (typeof window === \"undefined\") {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t\"No window. Is the SDK running on a server without a global window object?\",\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\twindow.addEventListener(\"message\", listener);\n\n\t\t\treturn () => {\n\t\t\t\twindow.removeEventListener(\"message\", listener);\n\t\t\t};\n\t\t},\n\t};\n}\n","import { z } from \"zod\";\nimport { frostedV2Theme, withError } from \"./utils\";\n\nexport const whopServerSchema = z.discriminatedUnion(\"event\", [\n\tz.object({\n\t\tevent: z.literal(\"ping\"),\n\t\trequest: z.literal(\"ping\"),\n\t\tresponse: z.literal(\"pong\"),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"getTopLevelUrlData\"),\n\t\trequest: z.object({}).optional(),\n\t\tresponse: z.object({\n\t\t\tcompanyRoute: z.string(),\n\t\t\texperienceRoute: z.string(),\n\t\t\texperienceId: z.string(),\n\t\t\tviewType: z.enum([\"app\", \"admin\", \"analytics\", \"preview\"]),\n\t\t\tbaseHref: z.string(),\n\t\t\tfullHref: z.string(),\n\t\t}),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"openExternalUrl\"),\n\t\trequest: z.object({\n\t\t\tnewTab: z.boolean().optional(),\n\t\t\turl: z.string(),\n\t\t}),\n\t\tresponse: z.literal(\"ok\"),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"onHrefChange\"),\n\t\trequest: z.object({\n\t\t\thref: z.string(),\n\t\t}),\n\t\tresponse: z.literal(\"ok\"),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"inAppPurchase\"),\n\t\trequest: z.object({\n\t\t\t/**\n\t\t\t * ID returned from the `chargeUser` API call.\n\t\t\t * @example \"ch_1234567890\"\n\t\t\t */\n\t\t\tid: z.string().optional(),\n\t\t\t/**\n\t\t\t * ID of the plan returned from the `chargeUser` API call.\n\t\t\t * @example \"plan_1234567890\"\n\t\t\t */\n\t\t\tplanId: z.string(),\n\t\t}),\n\t\tresponse: withError(\n\t\t\tz.object({\n\t\t\t\tsessionId: z.string(),\n\t\t\t\t/**\n\t\t\t\t * The receipt ID can be used to verify the purchase.\n\t\t\t\t *\n\t\t\t\t * NOTE: When receiving payments you should always listen to webhooks as a fallback\n\t\t\t\t * to process the payment. Do not solely rely on the client to process payments. The receipt ID\n\t\t\t\t * can be used to deduplicate payment events.\n\t\t\t\t */\n\t\t\t\treceiptId: z.string(),\n\t\t\t}),\n\t\t\tz.string(),\n\t\t),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"closeApp\"),\n\t\trequest: z.null(),\n\t\tresponse: z.literal(\"ok\"),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"openHelpChat\"),\n\t\trequest: z.null(),\n\t\tresponse: z.literal(\"ok\"),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"getColorTheme\"),\n\t\trequest: z.void(),\n\t\tresponse: frostedV2Theme,\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"earliestUnreadNotification\"),\n\t\trequest: z.object({\n\t\t\texperienceId: z.string(),\n\t\t}),\n\t\tresponse: z\n\t\t\t.object({\n\t\t\t\texternalId: z.string(),\n\t\t\t})\n\t\t\t.nullable(),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"markExperienceRead\"),\n\t\trequest: z.object({\n\t\t\texperienceId: z.string(),\n\t\t\tnotificationExternalId: z.string().optional(),\n\t\t}),\n\t\tresponse: z.literal(\"ok\"),\n\t}),\n\tz.object({\n\t\tevent: z.literal(\"performHaptic\"),\n\t\trequest: z.object({\n\t\t\ttype: z.enum([\"selection\", \"impact\", \"notification\"]),\n\t\t\tstyle: z.enum([\"light\", \"medium\", \"heavy\"]),\n\t\t}),\n\t\tresponse: z.literal(\"ok\"),\n\t}),\n]);\n\nexport type WhopServerSchema = z.TypeOf<typeof whopServerSchema>;\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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,cAAkB;;;ACAlB,iBAAkC;AAE3B,IAAM,YAAY,CACxB,QACA,UACI;AACJ,SAAO,aAAE,mBAAmB,UAAU;AAAA,IACrC,aAAE,OAAO;AAAA,MACR,QAAQ,aAAE,QAAQ,IAAI;AAAA,MACtB,MAAM;AAA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