@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/host.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as zod from 'zod';
|
|
2
|
+
import { S as ServerImplementation, w as whopServerSchema, C as ClientSDK } from './whop-server-CCmOBRgb.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create an iframe SDK for the container whop.com app.
|
|
6
|
+
* This will implement the functions required by client apps.
|
|
7
|
+
* Do not use this function when building apps
|
|
8
|
+
*/
|
|
9
|
+
declare function createSdkHost({ appId, onMessage, remoteWindow, remoteOrigin, }: {
|
|
10
|
+
appId: string;
|
|
11
|
+
remoteWindow: Window;
|
|
12
|
+
remoteOrigin: string;
|
|
13
|
+
onMessage: ServerImplementation<typeof whopServerSchema, true>;
|
|
14
|
+
isDevelopment?: boolean;
|
|
15
|
+
}): ClientSDK<zod.ZodDiscriminatedUnion<"event", [zod.ZodObject<{
|
|
16
|
+
event: zod.ZodLiteral<"appPing">;
|
|
17
|
+
request: zod.ZodLiteral<"app_ping">;
|
|
18
|
+
response: zod.ZodLiteral<"app_pong">;
|
|
19
|
+
}, "strip", zod.ZodTypeAny, {
|
|
20
|
+
event: "appPing";
|
|
21
|
+
request: "app_ping";
|
|
22
|
+
response: "app_pong";
|
|
23
|
+
}, {
|
|
24
|
+
event: "appPing";
|
|
25
|
+
request: "app_ping";
|
|
26
|
+
response: "app_pong";
|
|
27
|
+
}>, zod.ZodObject<{
|
|
28
|
+
event: zod.ZodLiteral<"onColorThemeChange">;
|
|
29
|
+
request: zod.ZodObject<{
|
|
30
|
+
appearance: zod.ZodOptional<zod.ZodEnum<["light", "dark"]>>;
|
|
31
|
+
accentColor: zod.ZodOptional<zod.ZodString>;
|
|
32
|
+
dangerColor: zod.ZodOptional<zod.ZodString>;
|
|
33
|
+
grayColor: zod.ZodOptional<zod.ZodString>;
|
|
34
|
+
infoColor: zod.ZodOptional<zod.ZodString>;
|
|
35
|
+
successColor: zod.ZodOptional<zod.ZodString>;
|
|
36
|
+
warningColor: zod.ZodOptional<zod.ZodString>;
|
|
37
|
+
}, "strip", zod.ZodTypeAny, {
|
|
38
|
+
appearance?: "light" | "dark" | undefined;
|
|
39
|
+
accentColor?: string | undefined;
|
|
40
|
+
dangerColor?: string | undefined;
|
|
41
|
+
grayColor?: string | undefined;
|
|
42
|
+
infoColor?: string | undefined;
|
|
43
|
+
successColor?: string | undefined;
|
|
44
|
+
warningColor?: string | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
appearance?: "light" | "dark" | undefined;
|
|
47
|
+
accentColor?: string | undefined;
|
|
48
|
+
dangerColor?: string | undefined;
|
|
49
|
+
grayColor?: string | undefined;
|
|
50
|
+
infoColor?: string | undefined;
|
|
51
|
+
successColor?: string | undefined;
|
|
52
|
+
warningColor?: string | undefined;
|
|
53
|
+
}>;
|
|
54
|
+
response: zod.ZodVoid;
|
|
55
|
+
}, "strip", zod.ZodTypeAny, {
|
|
56
|
+
event: "onColorThemeChange";
|
|
57
|
+
request: {
|
|
58
|
+
appearance?: "light" | "dark" | undefined;
|
|
59
|
+
accentColor?: string | undefined;
|
|
60
|
+
dangerColor?: string | undefined;
|
|
61
|
+
grayColor?: string | undefined;
|
|
62
|
+
infoColor?: string | undefined;
|
|
63
|
+
successColor?: string | undefined;
|
|
64
|
+
warningColor?: string | undefined;
|
|
65
|
+
};
|
|
66
|
+
response?: void | undefined;
|
|
67
|
+
}, {
|
|
68
|
+
event: "onColorThemeChange";
|
|
69
|
+
request: {
|
|
70
|
+
appearance?: "light" | "dark" | undefined;
|
|
71
|
+
accentColor?: string | undefined;
|
|
72
|
+
dangerColor?: string | undefined;
|
|
73
|
+
grayColor?: string | undefined;
|
|
74
|
+
infoColor?: string | undefined;
|
|
75
|
+
successColor?: string | undefined;
|
|
76
|
+
warningColor?: string | undefined;
|
|
77
|
+
};
|
|
78
|
+
response?: void | undefined;
|
|
79
|
+
}>]>, false> & {
|
|
80
|
+
_cleanupTransport: () => void;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export { createSdkHost };
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
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/host.ts
|
|
21
|
+
var host_exports = {};
|
|
22
|
+
__export(host_exports, {
|
|
23
|
+
createSdkHost: () => createSdkHost
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(host_exports);
|
|
26
|
+
|
|
27
|
+
// src/sdk/apps-server.ts
|
|
28
|
+
var import_zod2 = require("zod");
|
|
29
|
+
|
|
30
|
+
// src/sdk/utils.ts
|
|
31
|
+
var import_zod = require("zod");
|
|
32
|
+
var withError = (schema, error) => {
|
|
33
|
+
return import_zod.z.discriminatedUnion("status", [
|
|
34
|
+
import_zod.z.object({
|
|
35
|
+
status: import_zod.z.literal("ok"),
|
|
36
|
+
data: schema
|
|
37
|
+
}),
|
|
38
|
+
import_zod.z.object({
|
|
39
|
+
status: import_zod.z.literal("error"),
|
|
40
|
+
error
|
|
41
|
+
})
|
|
42
|
+
]);
|
|
43
|
+
};
|
|
44
|
+
var frostedV2Theme = import_zod.z.object({
|
|
45
|
+
appearance: import_zod.z.enum(["light", "dark"]),
|
|
46
|
+
accentColor: import_zod.z.string(),
|
|
47
|
+
dangerColor: import_zod.z.string(),
|
|
48
|
+
grayColor: import_zod.z.string(),
|
|
49
|
+
infoColor: import_zod.z.string(),
|
|
50
|
+
successColor: import_zod.z.string(),
|
|
51
|
+
warningColor: import_zod.z.string()
|
|
52
|
+
}).partial();
|
|
53
|
+
|
|
54
|
+
// src/sdk/apps-server.ts
|
|
55
|
+
var appsServerSchema = import_zod2.z.discriminatedUnion("event", [
|
|
56
|
+
import_zod2.z.object({
|
|
57
|
+
event: import_zod2.z.literal("appPing"),
|
|
58
|
+
request: import_zod2.z.literal("app_ping"),
|
|
59
|
+
response: import_zod2.z.literal("app_pong")
|
|
60
|
+
}),
|
|
61
|
+
import_zod2.z.object({
|
|
62
|
+
event: import_zod2.z.literal("onColorThemeChange"),
|
|
63
|
+
request: frostedV2Theme,
|
|
64
|
+
response: import_zod2.z.void()
|
|
65
|
+
})
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
// src/sdk/transport/utils.ts
|
|
69
|
+
var TimeoutError = class extends Error {
|
|
70
|
+
constructor() {
|
|
71
|
+
super("Timeout");
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
function randomId(length) {
|
|
75
|
+
const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
76
|
+
let str = "";
|
|
77
|
+
for (let i = 0; i < length; i++) {
|
|
78
|
+
str += alphabet[Math.floor(Math.random() * alphabet.length)];
|
|
79
|
+
}
|
|
80
|
+
return str;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/sdk/transport/sdk.ts
|
|
84
|
+
function createSDK({
|
|
85
|
+
clientSchema,
|
|
86
|
+
serverSchema,
|
|
87
|
+
serverComplete,
|
|
88
|
+
transport,
|
|
89
|
+
timeout = 1e3,
|
|
90
|
+
timeouts,
|
|
91
|
+
localAppId,
|
|
92
|
+
remoteAppId,
|
|
93
|
+
serverImplementation = {},
|
|
94
|
+
serverMiddleware
|
|
95
|
+
}) {
|
|
96
|
+
const callbacks = [];
|
|
97
|
+
const keys = clientSchema?.options.map(
|
|
98
|
+
(option) => option._def.shape().event._def.value
|
|
99
|
+
) ?? [];
|
|
100
|
+
const client = Object.fromEntries(
|
|
101
|
+
keys.map((key) => [
|
|
102
|
+
key,
|
|
103
|
+
async (req) => {
|
|
104
|
+
const eventId = `${localAppId}:${key}:${randomId(8)}`;
|
|
105
|
+
console.debug("[typed-transport] app. Created eventId", eventId);
|
|
106
|
+
const responseData = new Promise((resolve, reject) => {
|
|
107
|
+
const customTimeout = timeouts?.[key];
|
|
108
|
+
const timeoutId = setTimeout(() => {
|
|
109
|
+
const index = callbacks.findIndex((cb) => cb.id === eventId);
|
|
110
|
+
if (index !== -1) callbacks.splice(index, 1);
|
|
111
|
+
if (serverComplete) {
|
|
112
|
+
console.debug("[typed-transport] app. Timeout error");
|
|
113
|
+
reject(new TimeoutError());
|
|
114
|
+
} else resolve(void 0);
|
|
115
|
+
}, customTimeout ?? timeout);
|
|
116
|
+
if (customTimeout && customTimeout > timeout && !serverComplete) {
|
|
117
|
+
const timeoutId2 = setTimeout(() => {
|
|
118
|
+
const index = callbacks.findIndex((cb) => cb.id === eventId);
|
|
119
|
+
if (index !== -1) callbacks.splice(index, 1);
|
|
120
|
+
resolve(void 0);
|
|
121
|
+
}, timeout);
|
|
122
|
+
callbacks.push({
|
|
123
|
+
id: `${eventId}:processing`,
|
|
124
|
+
resolve: () => clearTimeout(timeoutId2)
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
callbacks.push({
|
|
128
|
+
id: eventId,
|
|
129
|
+
resolve: (data2) => {
|
|
130
|
+
clearTimeout(timeoutId);
|
|
131
|
+
resolve(data2);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
console.debug("[typed-transport] app sending event", {
|
|
136
|
+
eventId,
|
|
137
|
+
localAppId,
|
|
138
|
+
remoteAppId
|
|
139
|
+
});
|
|
140
|
+
await transport.send?.(eventId, req, { localAppId, remoteAppId });
|
|
141
|
+
const data = await responseData;
|
|
142
|
+
console.debug("[typed-transport] received response", data);
|
|
143
|
+
return data;
|
|
144
|
+
}
|
|
145
|
+
])
|
|
146
|
+
);
|
|
147
|
+
const cleanupRecv = transport.recv(
|
|
148
|
+
async (event, dataAny) => {
|
|
149
|
+
const [app, key, _randomId, type] = event.split(":");
|
|
150
|
+
if (app === localAppId) {
|
|
151
|
+
const idx = callbacks.findIndex((cb2) => cb2.id === event);
|
|
152
|
+
if (idx === -1) return;
|
|
153
|
+
const dataSchema = clientSchema?.optionsMap.get(key);
|
|
154
|
+
if (!dataSchema) return;
|
|
155
|
+
const cb = callbacks[idx];
|
|
156
|
+
if (type === "processing") {
|
|
157
|
+
cb.resolve(void 0);
|
|
158
|
+
} else {
|
|
159
|
+
const data = dataSchema.shape.response.parse(dataAny);
|
|
160
|
+
callbacks.splice(idx, 1);
|
|
161
|
+
cb.resolve(data);
|
|
162
|
+
}
|
|
163
|
+
} else if (app === remoteAppId) {
|
|
164
|
+
if (serverImplementation === void 0) return;
|
|
165
|
+
let handler = serverImplementation[key];
|
|
166
|
+
if (serverMiddleware) {
|
|
167
|
+
for (let i = serverMiddleware.length - 1; i >= 0; i--) {
|
|
168
|
+
const middlewareDef = serverMiddleware[i];
|
|
169
|
+
const middleware = middlewareDef[key];
|
|
170
|
+
if (!middleware) continue;
|
|
171
|
+
const ref = handler;
|
|
172
|
+
handler = (data2) => middleware(data2, ref);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (!handler) return;
|
|
176
|
+
const dataSchema = serverSchema?.optionsMap.get(key);
|
|
177
|
+
if (!dataSchema) return;
|
|
178
|
+
const data = dataSchema.shape.request.parse(dataAny);
|
|
179
|
+
const timeoutId = setTimeout(async () => {
|
|
180
|
+
await transport.send(
|
|
181
|
+
`${event}:processing`,
|
|
182
|
+
{},
|
|
183
|
+
{ localAppId, remoteAppId }
|
|
184
|
+
);
|
|
185
|
+
}, 50);
|
|
186
|
+
const response = await handler(data);
|
|
187
|
+
clearTimeout(timeoutId);
|
|
188
|
+
await transport.send(event, response, { localAppId, remoteAppId });
|
|
189
|
+
return response;
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
localAppId,
|
|
194
|
+
remoteAppId
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
const cleanupFunctions = [];
|
|
198
|
+
if (transport.cleanup) cleanupFunctions.push(transport.cleanup);
|
|
199
|
+
if (cleanupRecv) cleanupFunctions.push(cleanupRecv);
|
|
200
|
+
client._cleanupTransport = () => {
|
|
201
|
+
for (const fn of cleanupFunctions) fn();
|
|
202
|
+
};
|
|
203
|
+
return client;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/sdk/transport/postmessage.ts
|
|
207
|
+
var MESSAGE_TAG = "typed-transport";
|
|
208
|
+
function postmessageTransport({
|
|
209
|
+
remoteWindow,
|
|
210
|
+
targetOrigins
|
|
211
|
+
}) {
|
|
212
|
+
return {
|
|
213
|
+
send(event, data, { remoteAppId, localAppId }) {
|
|
214
|
+
if (!remoteWindow) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
"No remote window. Is the SDK running on a server without a global window object?"
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
console.debug(
|
|
220
|
+
"[typed-transport] postmessagetransport. Sending event",
|
|
221
|
+
event,
|
|
222
|
+
data
|
|
223
|
+
);
|
|
224
|
+
console.debug(
|
|
225
|
+
"[typed-transport] postmessagetransport. target origins =",
|
|
226
|
+
targetOrigins
|
|
227
|
+
);
|
|
228
|
+
for (const targetOrigin of targetOrigins) {
|
|
229
|
+
console.debug("[typed-transport] remoteWindow.postMessage", {
|
|
230
|
+
event,
|
|
231
|
+
libId: MESSAGE_TAG,
|
|
232
|
+
receiverAppId: remoteAppId,
|
|
233
|
+
senderAppId: localAppId
|
|
234
|
+
});
|
|
235
|
+
console.debug(
|
|
236
|
+
"[typed-transport] remoteWindow.postMessage.data",
|
|
237
|
+
data,
|
|
238
|
+
JSON.stringify(data)
|
|
239
|
+
);
|
|
240
|
+
remoteWindow.postMessage(
|
|
241
|
+
{
|
|
242
|
+
event,
|
|
243
|
+
data,
|
|
244
|
+
libId: MESSAGE_TAG,
|
|
245
|
+
receiverAppId: remoteAppId,
|
|
246
|
+
senderAppId: localAppId
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
targetOrigin
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
if (targetOrigins.length === 0) {
|
|
254
|
+
remoteWindow.postMessage({
|
|
255
|
+
event,
|
|
256
|
+
data,
|
|
257
|
+
libId: MESSAGE_TAG,
|
|
258
|
+
receiverAppId: remoteAppId,
|
|
259
|
+
senderAppId: localAppId
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
recv(handler, { localAppId, remoteAppId }) {
|
|
264
|
+
const listener = (event) => {
|
|
265
|
+
console.debug(
|
|
266
|
+
"[typed-transport] postmessagetransport. Receiving event",
|
|
267
|
+
event
|
|
268
|
+
);
|
|
269
|
+
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) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
handler(event.data.event, event.data.data);
|
|
273
|
+
};
|
|
274
|
+
if (typeof window === "undefined") {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
window.addEventListener("message", listener);
|
|
278
|
+
return () => {
|
|
279
|
+
window.removeEventListener("message", listener);
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/sdk/whop-server.ts
|
|
286
|
+
var import_zod3 = require("zod");
|
|
287
|
+
var whopServerSchema = import_zod3.z.discriminatedUnion("event", [
|
|
288
|
+
import_zod3.z.object({
|
|
289
|
+
event: import_zod3.z.literal("ping"),
|
|
290
|
+
request: import_zod3.z.literal("ping"),
|
|
291
|
+
response: import_zod3.z.literal("pong")
|
|
292
|
+
}),
|
|
293
|
+
import_zod3.z.object({
|
|
294
|
+
event: import_zod3.z.literal("getTopLevelUrlData"),
|
|
295
|
+
request: import_zod3.z.object({}).optional(),
|
|
296
|
+
response: import_zod3.z.object({
|
|
297
|
+
companyRoute: import_zod3.z.string(),
|
|
298
|
+
experienceRoute: import_zod3.z.string(),
|
|
299
|
+
experienceId: import_zod3.z.string(),
|
|
300
|
+
viewType: import_zod3.z.enum(["app", "admin", "analytics", "preview"]),
|
|
301
|
+
baseHref: import_zod3.z.string(),
|
|
302
|
+
fullHref: import_zod3.z.string()
|
|
303
|
+
})
|
|
304
|
+
}),
|
|
305
|
+
import_zod3.z.object({
|
|
306
|
+
event: import_zod3.z.literal("openExternalUrl"),
|
|
307
|
+
request: import_zod3.z.object({
|
|
308
|
+
newTab: import_zod3.z.boolean().optional(),
|
|
309
|
+
url: import_zod3.z.string()
|
|
310
|
+
}),
|
|
311
|
+
response: import_zod3.z.literal("ok")
|
|
312
|
+
}),
|
|
313
|
+
import_zod3.z.object({
|
|
314
|
+
event: import_zod3.z.literal("onHrefChange"),
|
|
315
|
+
request: import_zod3.z.object({
|
|
316
|
+
href: import_zod3.z.string()
|
|
317
|
+
}),
|
|
318
|
+
response: import_zod3.z.literal("ok")
|
|
319
|
+
}),
|
|
320
|
+
import_zod3.z.object({
|
|
321
|
+
event: import_zod3.z.literal("inAppPurchase"),
|
|
322
|
+
request: import_zod3.z.object({
|
|
323
|
+
/**
|
|
324
|
+
* ID returned from the `chargeUser` API call.
|
|
325
|
+
* @example "ch_1234567890"
|
|
326
|
+
*/
|
|
327
|
+
id: import_zod3.z.string().optional(),
|
|
328
|
+
/**
|
|
329
|
+
* ID of the plan returned from the `chargeUser` API call.
|
|
330
|
+
* @example "plan_1234567890"
|
|
331
|
+
*/
|
|
332
|
+
planId: import_zod3.z.string()
|
|
333
|
+
}),
|
|
334
|
+
response: withError(
|
|
335
|
+
import_zod3.z.object({
|
|
336
|
+
sessionId: import_zod3.z.string(),
|
|
337
|
+
/**
|
|
338
|
+
* The receipt ID can be used to verify the purchase.
|
|
339
|
+
*
|
|
340
|
+
* NOTE: When receiving payments you should always listen to webhooks as a fallback
|
|
341
|
+
* to process the payment. Do not solely rely on the client to process payments. The receipt ID
|
|
342
|
+
* can be used to deduplicate payment events.
|
|
343
|
+
*/
|
|
344
|
+
receiptId: import_zod3.z.string()
|
|
345
|
+
}),
|
|
346
|
+
import_zod3.z.string()
|
|
347
|
+
)
|
|
348
|
+
}),
|
|
349
|
+
import_zod3.z.object({
|
|
350
|
+
event: import_zod3.z.literal("closeApp"),
|
|
351
|
+
request: import_zod3.z.null(),
|
|
352
|
+
response: import_zod3.z.literal("ok")
|
|
353
|
+
}),
|
|
354
|
+
import_zod3.z.object({
|
|
355
|
+
event: import_zod3.z.literal("openHelpChat"),
|
|
356
|
+
request: import_zod3.z.null(),
|
|
357
|
+
response: import_zod3.z.literal("ok")
|
|
358
|
+
}),
|
|
359
|
+
import_zod3.z.object({
|
|
360
|
+
event: import_zod3.z.literal("getColorTheme"),
|
|
361
|
+
request: import_zod3.z.void(),
|
|
362
|
+
response: frostedV2Theme
|
|
363
|
+
}),
|
|
364
|
+
import_zod3.z.object({
|
|
365
|
+
event: import_zod3.z.literal("earliestUnreadNotification"),
|
|
366
|
+
request: import_zod3.z.object({
|
|
367
|
+
experienceId: import_zod3.z.string()
|
|
368
|
+
}),
|
|
369
|
+
response: import_zod3.z.object({
|
|
370
|
+
externalId: import_zod3.z.string()
|
|
371
|
+
}).nullable()
|
|
372
|
+
}),
|
|
373
|
+
import_zod3.z.object({
|
|
374
|
+
event: import_zod3.z.literal("markExperienceRead"),
|
|
375
|
+
request: import_zod3.z.object({
|
|
376
|
+
experienceId: import_zod3.z.string(),
|
|
377
|
+
notificationExternalId: import_zod3.z.string().optional()
|
|
378
|
+
}),
|
|
379
|
+
response: import_zod3.z.literal("ok")
|
|
380
|
+
}),
|
|
381
|
+
import_zod3.z.object({
|
|
382
|
+
event: import_zod3.z.literal("performHaptic"),
|
|
383
|
+
request: import_zod3.z.object({
|
|
384
|
+
type: import_zod3.z.enum(["selection", "impact", "notification"]),
|
|
385
|
+
style: import_zod3.z.enum(["light", "medium", "heavy"])
|
|
386
|
+
}),
|
|
387
|
+
response: import_zod3.z.literal("ok")
|
|
388
|
+
})
|
|
389
|
+
]);
|
|
390
|
+
|
|
391
|
+
// src/host.ts
|
|
392
|
+
function createSdkHost({
|
|
393
|
+
appId,
|
|
394
|
+
onMessage,
|
|
395
|
+
remoteWindow,
|
|
396
|
+
remoteOrigin
|
|
397
|
+
}) {
|
|
398
|
+
return createSDK({
|
|
399
|
+
clientSchema: appsServerSchema,
|
|
400
|
+
serverSchema: whopServerSchema,
|
|
401
|
+
forceCompleteness: true,
|
|
402
|
+
serverImplementation: onMessage,
|
|
403
|
+
localAppId: "app_whop",
|
|
404
|
+
remoteAppId: appId,
|
|
405
|
+
transport: postmessageTransport({
|
|
406
|
+
remoteWindow,
|
|
407
|
+
targetOrigins: [remoteOrigin]
|
|
408
|
+
}),
|
|
409
|
+
serverComplete: false,
|
|
410
|
+
timeout: 200
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
414
|
+
0 && (module.exports = {
|
|
415
|
+
createSdkHost
|
|
416
|
+
});
|
|
417
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host.ts","../src/sdk/apps-server.ts","../src/sdk/utils.ts","../src/sdk/transport/utils.ts","../src/sdk/transport/sdk.ts","../src/sdk/transport/postmessage.ts","../src/sdk/whop-server.ts"],"sourcesContent":["import { appsServerSchema } from \"@/sdk/apps-server\";\nimport {\n\ttype ServerImplementation,\n\tcreateSDK as createPostmessageSdk,\n\tpostmessageTransport,\n} from \"@/sdk/transport\";\nimport { whopServerSchema } from \"@/sdk/whop-server\";\n\n/**\n * Create an iframe SDK for the container whop.com app.\n * This will implement the functions required by client apps.\n * Do not use this function when building apps\n */\nexport function createSdkHost({\n\tappId,\n\tonMessage,\n\tremoteWindow,\n\tremoteOrigin,\n}: {\n\tappId: string;\n\tremoteWindow: Window;\n\tremoteOrigin: string;\n\tonMessage: ServerImplementation<typeof whopServerSchema, true>;\n\tisDevelopment?: boolean;\n}) {\n\treturn createPostmessageSdk({\n\t\tclientSchema: appsServerSchema,\n\t\tserverSchema: whopServerSchema,\n\t\tforceCompleteness: true,\n\t\tserverImplementation: onMessage,\n\t\tlocalAppId: \"app_whop\",\n\t\tremoteAppId: appId,\n\t\ttransport: postmessageTransport({\n\t\t\tremoteWindow: remoteWindow,\n\t\t\ttargetOrigins: [remoteOrigin],\n\t\t}),\n\t\tserverComplete: false,\n\t\ttimeout: 200,\n\t});\n}\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 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 { 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"],"mappings":";;;;;;;;;;;;;;;;;;;;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;AAAA,IACP,CAAC;AAAA,IACD,aAAE,OAAO;AAAA,MACR,QAAQ,aAAE,QAAQ,OAAO;AAAA,MACzB;AAAA,IACD,CAAC;AAAA,EACF,CAAC;AACF;AAEO,IAAM,iBAAiB,aAC5B,OAAO;AAAA,EACP,YAAY,aAAE,KAAK,CAAC,SAAS,MAAM,CAAC;AAAA,EACpC,aAAa,aAAE,OAAO;AAAA,EACtB,aAAa,a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;AAAA,IAC7C,SAAS,cAAE,OAAO;AAAA,MACjB,cAAc,cAAE,OAAO;AAAA,IACxB,CAAC;AAAA,IACD,UAAU,cACR,OAAO;AAAA,MACP,YAAY,cAAE,OAAO;AAAA,IACtB,CAAC,EACA,SAAS;AAAA,EACZ,CAAC;AAAA,EACD,cAAE,OAAO;AAAA,IACR,OAAO,cAAE,QAAQ,oBAAoB;AAAA,IACrC,SAAS,cAAE,OAAO;AAAA,MACjB,cAAc,cAAE,OAAO;AAAA,MACvB,wBAAwB,cAAE,OAAO,EAAE,SAAS;AAAA,IAC7C,CAAC;AAAA,IACD,UAAU,cAAE,QAAQ,IAAI;AAAA,EACzB,CAAC;AAAA,EACD,cAAE,OAAO;AAAA,IACR,OAAO,cAAE,QAAQ,eAAe;AAAA,IAChC,SAAS,cAAE,OAAO;AAAA,MACjB,MAAM,cAAE,KAAK,CAAC,aAAa,UAAU,cAAc,CAAC;AAAA,MACpD,OAAO,cAAE,KAAK,CAAC,SAAS,UAAU,OAAO,CAAC;AAAA,IAC3C,CAAC;AAAA,IACD,UAAU,cAAE,QAAQ,IAAI;AAAA,EACzB,CAAC;AACF,CAAC;;;AN9FM,SAAS,cAAc;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAMG;AACF,SAAO,UAAqB;AAAA,IAC3B,cAAc;AAAA,IACd,cAAc;AAAA,IACd,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,WAAW,qBAAqB;AAAA,MAC/B;AAAA,MACA,eAAe,CAAC,YAAY;AAAA,IAC7B,CAAC;AAAA,IACD,gBAAgB;AAAA,IAChB,SAAS;AAAA,EACV,CAAC;AACF;","names":["import_zod","timeoutId","data","cb","import_zod"]}
|
package/dist/host.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appsServerSchema,
|
|
3
|
+
createSDK,
|
|
4
|
+
postmessageTransport,
|
|
5
|
+
whopServerSchema
|
|
6
|
+
} from "./chunk-DPDPUJJX.mjs";
|
|
7
|
+
|
|
8
|
+
// src/host.ts
|
|
9
|
+
function createSdkHost({
|
|
10
|
+
appId,
|
|
11
|
+
onMessage,
|
|
12
|
+
remoteWindow,
|
|
13
|
+
remoteOrigin
|
|
14
|
+
}) {
|
|
15
|
+
return createSDK({
|
|
16
|
+
clientSchema: appsServerSchema,
|
|
17
|
+
serverSchema: whopServerSchema,
|
|
18
|
+
forceCompleteness: true,
|
|
19
|
+
serverImplementation: onMessage,
|
|
20
|
+
localAppId: "app_whop",
|
|
21
|
+
remoteAppId: appId,
|
|
22
|
+
transport: postmessageTransport({
|
|
23
|
+
remoteWindow,
|
|
24
|
+
targetOrigins: [remoteOrigin]
|
|
25
|
+
}),
|
|
26
|
+
serverComplete: false,
|
|
27
|
+
timeout: 200
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
createSdkHost
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=host.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host.ts"],"sourcesContent":["import { appsServerSchema } from \"@/sdk/apps-server\";\nimport {\n\ttype ServerImplementation,\n\tcreateSDK as createPostmessageSdk,\n\tpostmessageTransport,\n} from \"@/sdk/transport\";\nimport { whopServerSchema } from \"@/sdk/whop-server\";\n\n/**\n * Create an iframe SDK for the container whop.com app.\n * This will implement the functions required by client apps.\n * Do not use this function when building apps\n */\nexport function createSdkHost({\n\tappId,\n\tonMessage,\n\tremoteWindow,\n\tremoteOrigin,\n}: {\n\tappId: string;\n\tremoteWindow: Window;\n\tremoteOrigin: string;\n\tonMessage: ServerImplementation<typeof whopServerSchema, true>;\n\tisDevelopment?: boolean;\n}) {\n\treturn createPostmessageSdk({\n\t\tclientSchema: appsServerSchema,\n\t\tserverSchema: whopServerSchema,\n\t\tforceCompleteness: true,\n\t\tserverImplementation: onMessage,\n\t\tlocalAppId: \"app_whop\",\n\t\tremoteAppId: appId,\n\t\ttransport: postmessageTransport({\n\t\t\tremoteWindow: remoteWindow,\n\t\t\ttargetOrigins: [remoteOrigin],\n\t\t}),\n\t\tserverComplete: false,\n\t\ttimeout: 200,\n\t});\n}\n"],"mappings":";;;;;;;;AAaO,SAAS,cAAc;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAMG;AACF,SAAO,UAAqB;AAAA,IAC3B,cAAc;AAAA,IACd,cAAc;AAAA,IACd,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,YAAY;AAAA,IACZ,aAAa;AAAA,IACb,WAAW,qBAAqB;AAAA,MAC/B;AAAA,MACA,eAAe,CAAC,YAAY;AAAA,IAC7B,CAAC;AAAA,IACD,gBAAgB;AAAA,IAChB,SAAS;AAAA,EACV,CAAC;AACF;","names":[]}
|