@genex-ai/embed-sdk 0.30.1 → 0.32.0
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 +249 -3
- package/dist/{chunk-FBJN7DGJ.js → chunk-NBCL5P5V.js} +809 -67
- package/dist/chunk-QBCWKMVQ.js +534 -0
- package/dist/development.d.ts +1 -1
- package/dist/development.js +1 -1
- package/dist/index.d.ts +276 -10
- package/dist/index.js +26 -2
- package/dist/{runtime-generation-sXuSFc3c.d.ts → runtime-generation-B3oFDmCp.d.ts} +8 -0
- package/dist/sentry.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-MJPLBT3T.js +0 -264
|
@@ -1,15 +1,575 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AUTHORIZE_ENTRY_REF_PARAM,
|
|
3
|
+
DASHBOARD_RESERVED_KEYS,
|
|
4
|
+
EMBED_REFERRER_PARAM,
|
|
5
|
+
ENTRY_HASH_KEY,
|
|
6
|
+
ENTRY_REFERRER_KEY,
|
|
7
|
+
MAX_ENTRY_QUERY_LENGTH,
|
|
8
|
+
MAX_RETURN_TO_LENGTH,
|
|
2
9
|
NATIVE_CHANNEL,
|
|
3
10
|
NATIVE_PROTOCOL_VERSION,
|
|
4
11
|
NATIVE_RECEIVER,
|
|
12
|
+
PLATFORM_PROTOCOL_VERSION,
|
|
13
|
+
PLATFORM_REQUEST_TYPE,
|
|
14
|
+
RESERVED_QUERY_PREFIX,
|
|
15
|
+
SAVE_MAX_BYTES,
|
|
16
|
+
createBridgeId,
|
|
5
17
|
encodeBridgeMessage,
|
|
6
18
|
hasNativeMarker,
|
|
7
19
|
isGenerationId,
|
|
8
20
|
isGenerationTerminal,
|
|
21
|
+
isPlatformUrl,
|
|
22
|
+
isSaveName,
|
|
9
23
|
parseGenerationStreamEvent,
|
|
24
|
+
parsePlatformRequest,
|
|
25
|
+
parsePlatformResult,
|
|
10
26
|
readBridgeNativeCommand,
|
|
11
|
-
readNativeEntry
|
|
12
|
-
|
|
27
|
+
readNativeEntry,
|
|
28
|
+
readPlatformCaps,
|
|
29
|
+
sanitizeEntryHash,
|
|
30
|
+
sanitizeEntryReferrer,
|
|
31
|
+
sanitizePassthroughQuery,
|
|
32
|
+
savableMime,
|
|
33
|
+
stripNativeEntry,
|
|
34
|
+
stripReturnMarker
|
|
35
|
+
} from "./chunk-QBCWKMVQ.js";
|
|
36
|
+
|
|
37
|
+
// src/platform.ts
|
|
38
|
+
var ctx = null;
|
|
39
|
+
function _initPlatform(c) {
|
|
40
|
+
ctx = c;
|
|
41
|
+
}
|
|
42
|
+
var replyTimeoutMs = 3e3;
|
|
43
|
+
var confirmTimeoutMs = 18e4;
|
|
44
|
+
var SAVE_URL_LIFETIME_MS = 6e4;
|
|
45
|
+
var pending = /* @__PURE__ */ new Map();
|
|
46
|
+
var listening = null;
|
|
47
|
+
var wakeWanted = false;
|
|
48
|
+
var wakeSentinel = null;
|
|
49
|
+
var wakeRequest = null;
|
|
50
|
+
var wakeHook = null;
|
|
51
|
+
var shareParamsWarned = false;
|
|
52
|
+
function win() {
|
|
53
|
+
return globalThis.window;
|
|
54
|
+
}
|
|
55
|
+
function doc() {
|
|
56
|
+
return globalThis.document;
|
|
57
|
+
}
|
|
58
|
+
function shell() {
|
|
59
|
+
return ctx ? ctx.getShell() : "standalone";
|
|
60
|
+
}
|
|
61
|
+
function localTest() {
|
|
62
|
+
if (!ctx) return false;
|
|
63
|
+
return ctx.isLocalTest ? ctx.isLocalTest() : ctx.getShell() === "local";
|
|
64
|
+
}
|
|
65
|
+
function fail(error) {
|
|
66
|
+
return { ok: false, error };
|
|
67
|
+
}
|
|
68
|
+
async function settled(run, fallback) {
|
|
69
|
+
try {
|
|
70
|
+
return await run();
|
|
71
|
+
} catch {
|
|
72
|
+
return fallback;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function share(options) {
|
|
76
|
+
let url = "";
|
|
77
|
+
try {
|
|
78
|
+
url = shareUrl(options?.params);
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
return settled(
|
|
82
|
+
async () => {
|
|
83
|
+
const nav = win()?.navigator;
|
|
84
|
+
if (url && nav && !localTest() && typeof nav.share === "function") {
|
|
85
|
+
const data = { url };
|
|
86
|
+
if (typeof options?.text === "string" && options.text) data.text = options.text;
|
|
87
|
+
if (canShare(nav, data)) {
|
|
88
|
+
try {
|
|
89
|
+
await nav.share(data);
|
|
90
|
+
return { status: "shared", url };
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error?.name === "AbortError") {
|
|
93
|
+
return { status: "dismissed", url };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (url && (await copyText(url)).ok) return { status: "copied", url };
|
|
99
|
+
return { status: "unavailable", url };
|
|
100
|
+
},
|
|
101
|
+
{ status: "unavailable", url }
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
function canShare(nav, data) {
|
|
105
|
+
if (typeof nav.canShare !== "function") return true;
|
|
106
|
+
try {
|
|
107
|
+
return nav.canShare(data);
|
|
108
|
+
} catch {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function shareUrl(params) {
|
|
113
|
+
const base = shareBase();
|
|
114
|
+
if (!base) return "";
|
|
115
|
+
const query = shareQuery(params);
|
|
116
|
+
return query ? `${base}?${query}` : base;
|
|
117
|
+
}
|
|
118
|
+
function shareBase() {
|
|
119
|
+
const w = win();
|
|
120
|
+
if (!w) return "";
|
|
121
|
+
const page = httpAddress(w.__GENEX__?.pageUrl);
|
|
122
|
+
if (page) return page;
|
|
123
|
+
const dashboard = trustedParent();
|
|
124
|
+
const config3 = ctx?.getConfig();
|
|
125
|
+
if (dashboard !== null && config3) {
|
|
126
|
+
const built = pageOnDashboard(dashboard, config3.slug);
|
|
127
|
+
if (built) return built;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
return httpAddress(w.location.origin + w.location.pathname);
|
|
131
|
+
} catch {
|
|
132
|
+
return "";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function pageOnDashboard(dashboard, slug) {
|
|
136
|
+
try {
|
|
137
|
+
return httpAddress(`${new URL(dashboard).origin}/${encodeURIComponent(slug)}`);
|
|
138
|
+
} catch {
|
|
139
|
+
return "";
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function httpAddress(value) {
|
|
143
|
+
if (typeof value !== "string") return "";
|
|
144
|
+
try {
|
|
145
|
+
const url = new URL(value);
|
|
146
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") return "";
|
|
147
|
+
if (url.username || url.password) return "";
|
|
148
|
+
return url.origin + url.pathname;
|
|
149
|
+
} catch {
|
|
150
|
+
return "";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function shareQuery(params) {
|
|
154
|
+
if (!params || typeof params !== "object") return "";
|
|
155
|
+
const pairs = [];
|
|
156
|
+
let leftOut = false;
|
|
157
|
+
for (const key of Object.keys(params)) {
|
|
158
|
+
const value = params[key];
|
|
159
|
+
const kind = typeof value;
|
|
160
|
+
if (!key || kind !== "string" && kind !== "number" && kind !== "boolean") {
|
|
161
|
+
leftOut = true;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
pairs.push(`${queryPart(key)}=${queryPart(String(value))}`);
|
|
166
|
+
} catch {
|
|
167
|
+
leftOut = true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const asked = pairs.join("&");
|
|
171
|
+
const kept = asked.length <= MAX_ENTRY_QUERY_LENGTH ? sanitizePassthroughQuery(asked, DASHBOARD_RESERVED_KEYS) : "";
|
|
172
|
+
if ((leftOut || kept !== asked) && !shareParamsWarned) {
|
|
173
|
+
shareParamsWarned = true;
|
|
174
|
+
try {
|
|
175
|
+
console.warn(
|
|
176
|
+
"[genex] share(): some params were left out of the link. embed, ref, s, from, remix, slug and names starting genex_ are reserved, values are strings, numbers or booleans, and the whole query is capped at 1024 characters."
|
|
177
|
+
);
|
|
178
|
+
} catch {
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return kept;
|
|
182
|
+
}
|
|
183
|
+
function queryPart(text) {
|
|
184
|
+
return encodeURIComponent(text).replace(/'/g, "%27");
|
|
185
|
+
}
|
|
186
|
+
function copyText(text) {
|
|
187
|
+
return settled(async () => {
|
|
188
|
+
if (typeof text !== "string" || text.length === 0) return fail("invalid_request");
|
|
189
|
+
const d = doc();
|
|
190
|
+
const clipboard = win()?.navigator?.clipboard;
|
|
191
|
+
let tried = false;
|
|
192
|
+
if (clipboard && typeof clipboard.writeText === "function") {
|
|
193
|
+
tried = true;
|
|
194
|
+
try {
|
|
195
|
+
await clipboard.writeText(text);
|
|
196
|
+
return { ok: true };
|
|
197
|
+
} catch {
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (d && typeof d.execCommand === "function") {
|
|
201
|
+
tried = true;
|
|
202
|
+
if (selectionCopy(d, text)) return { ok: true };
|
|
203
|
+
}
|
|
204
|
+
return fail(tried ? "needs_gesture" : "unsupported");
|
|
205
|
+
}, fail("unsupported"));
|
|
206
|
+
}
|
|
207
|
+
function selectionCopy(d, text) {
|
|
208
|
+
const host = d.body ?? d.documentElement;
|
|
209
|
+
if (!host) return false;
|
|
210
|
+
const focused = d.activeElement;
|
|
211
|
+
const field = d.createElement("textarea");
|
|
212
|
+
field.value = text;
|
|
213
|
+
field.setAttribute("readonly", "");
|
|
214
|
+
field.setAttribute("aria-hidden", "true");
|
|
215
|
+
field.style.cssText = "position:fixed;top:0;left:0;width:1px;height:1px;padding:0;border:0;opacity:0;font-size:16px;";
|
|
216
|
+
host.appendChild(field);
|
|
217
|
+
let copied = false;
|
|
218
|
+
try {
|
|
219
|
+
field.focus({ preventScroll: true });
|
|
220
|
+
field.select();
|
|
221
|
+
field.setSelectionRange(0, text.length);
|
|
222
|
+
copied = d.execCommand("copy");
|
|
223
|
+
} catch {
|
|
224
|
+
copied = false;
|
|
225
|
+
}
|
|
226
|
+
field.remove();
|
|
227
|
+
try {
|
|
228
|
+
if (focused && typeof focused.focus === "function") focused.focus({ preventScroll: true });
|
|
229
|
+
} catch {
|
|
230
|
+
}
|
|
231
|
+
return copied;
|
|
232
|
+
}
|
|
233
|
+
function keepAwake(on2) {
|
|
234
|
+
return settled(() => {
|
|
235
|
+
if (shell() === "app") return { ok: true };
|
|
236
|
+
if (!on2) {
|
|
237
|
+
wakeWanted = false;
|
|
238
|
+
releaseWake();
|
|
239
|
+
return { ok: true };
|
|
240
|
+
}
|
|
241
|
+
const d = doc();
|
|
242
|
+
const lock = win()?.navigator?.wakeLock;
|
|
243
|
+
if (!d || !lock || typeof lock.request !== "function") return fail("unsupported");
|
|
244
|
+
wakeWanted = true;
|
|
245
|
+
hookWake(d);
|
|
246
|
+
return acquireWake(d, lock);
|
|
247
|
+
}, fail("unsupported"));
|
|
248
|
+
}
|
|
249
|
+
function acquireWake(d, lock) {
|
|
250
|
+
if (wakeRequest) return wakeRequest;
|
|
251
|
+
if (wakeSentinel && !wakeSentinel.released) return Promise.resolve({ ok: true });
|
|
252
|
+
if (d.visibilityState === "hidden") return Promise.resolve({ ok: true });
|
|
253
|
+
const request2 = (async () => {
|
|
254
|
+
try {
|
|
255
|
+
const sentinel = await lock.request("screen");
|
|
256
|
+
if (wakeWanted) holdSentinel(sentinel);
|
|
257
|
+
else dropSentinel(sentinel);
|
|
258
|
+
return { ok: true };
|
|
259
|
+
} catch {
|
|
260
|
+
if (d.visibilityState === "hidden") return { ok: true };
|
|
261
|
+
wakeWanted = false;
|
|
262
|
+
return fail("unsupported");
|
|
263
|
+
}
|
|
264
|
+
})();
|
|
265
|
+
wakeRequest = request2;
|
|
266
|
+
void request2.then(() => {
|
|
267
|
+
if (wakeRequest === request2) wakeRequest = null;
|
|
268
|
+
});
|
|
269
|
+
return request2;
|
|
270
|
+
}
|
|
271
|
+
function holdSentinel(sentinel) {
|
|
272
|
+
wakeSentinel = sentinel;
|
|
273
|
+
try {
|
|
274
|
+
sentinel.addEventListener?.("release", () => {
|
|
275
|
+
if (wakeSentinel === sentinel) wakeSentinel = null;
|
|
276
|
+
});
|
|
277
|
+
} catch {
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function hookWake(d) {
|
|
281
|
+
if (wakeHook || typeof d.addEventListener !== "function") return;
|
|
282
|
+
const onVisibility = () => {
|
|
283
|
+
const lock = win()?.navigator?.wakeLock;
|
|
284
|
+
if (wakeWanted && lock && d.visibilityState === "visible") void acquireWake(d, lock);
|
|
285
|
+
};
|
|
286
|
+
d.addEventListener("visibilitychange", onVisibility);
|
|
287
|
+
wakeHook = { d, onVisibility };
|
|
288
|
+
}
|
|
289
|
+
function releaseWake() {
|
|
290
|
+
const sentinel = wakeSentinel;
|
|
291
|
+
wakeSentinel = null;
|
|
292
|
+
if (sentinel && !sentinel.released) dropSentinel(sentinel);
|
|
293
|
+
}
|
|
294
|
+
function dropSentinel(sentinel) {
|
|
295
|
+
try {
|
|
296
|
+
void sentinel.release().catch(() => {
|
|
297
|
+
});
|
|
298
|
+
} catch {
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
var HAPTIC_PATTERNS = {
|
|
302
|
+
selection: [8],
|
|
303
|
+
light: [12],
|
|
304
|
+
medium: [20],
|
|
305
|
+
heavy: [35],
|
|
306
|
+
success: [12, 60, 24],
|
|
307
|
+
warning: [24, 80, 24],
|
|
308
|
+
error: [35, 60, 35, 60, 35]
|
|
309
|
+
};
|
|
310
|
+
function haptic(kind) {
|
|
311
|
+
try {
|
|
312
|
+
if (shell() === "app") return;
|
|
313
|
+
const nav = win()?.navigator;
|
|
314
|
+
if (!nav || typeof nav.vibrate !== "function") return;
|
|
315
|
+
if (!Object.prototype.hasOwnProperty.call(HAPTIC_PATTERNS, kind)) return;
|
|
316
|
+
if (nav.userActivation && nav.userActivation.hasBeenActive === false) return;
|
|
317
|
+
nav.vibrate(HAPTIC_PATTERNS[kind]);
|
|
318
|
+
} catch {
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function openExternal(url) {
|
|
322
|
+
return settled(() => {
|
|
323
|
+
const href = serialisedLink(url);
|
|
324
|
+
if (href === null) return fail("invalid_request");
|
|
325
|
+
const where = shell();
|
|
326
|
+
if (where === "app") return fail("unsupported");
|
|
327
|
+
if (where === "page") {
|
|
328
|
+
return askShell("open", (id) => ({ ...requestHead(id), cap: "open", url: href }));
|
|
329
|
+
}
|
|
330
|
+
const w = win();
|
|
331
|
+
if (!w || typeof w.open !== "function") return fail("unsupported");
|
|
332
|
+
const tab = w.open("", "_blank");
|
|
333
|
+
if (!tab) return fail("needs_gesture");
|
|
334
|
+
try {
|
|
335
|
+
tab.opener = null;
|
|
336
|
+
tab.location.replace(href);
|
|
337
|
+
} catch {
|
|
338
|
+
try {
|
|
339
|
+
tab.close();
|
|
340
|
+
} catch {
|
|
341
|
+
}
|
|
342
|
+
return fail("unsupported");
|
|
343
|
+
}
|
|
344
|
+
return { ok: true };
|
|
345
|
+
}, fail("unsupported"));
|
|
346
|
+
}
|
|
347
|
+
function serialisedLink(url) {
|
|
348
|
+
if (typeof url !== "string") return null;
|
|
349
|
+
let href;
|
|
350
|
+
try {
|
|
351
|
+
href = new URL(url).href;
|
|
352
|
+
} catch {
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
return isPlatformUrl(href) ? href : null;
|
|
356
|
+
}
|
|
357
|
+
function saveFile(file, name) {
|
|
358
|
+
return settled(() => {
|
|
359
|
+
if (!isSaveName(name) || !isBlob(file)) return fail("invalid_request");
|
|
360
|
+
if (file.size > SAVE_MAX_BYTES) return fail("too_large");
|
|
361
|
+
const mime = savableMime(file.type);
|
|
362
|
+
if (mime === null) return fail("invalid_request");
|
|
363
|
+
const where = shell();
|
|
364
|
+
if (where === "app") return fail("unsupported");
|
|
365
|
+
if (where === "page") {
|
|
366
|
+
return askShell("save", (id) => ({ ...requestHead(id), cap: "save", name, file }));
|
|
367
|
+
}
|
|
368
|
+
return downloadHere(file, withExtension(name, mime));
|
|
369
|
+
}, fail("unsupported"));
|
|
370
|
+
}
|
|
371
|
+
function isBlob(value) {
|
|
372
|
+
if (typeof value !== "object" || value === null) return false;
|
|
373
|
+
const tag = Object.prototype.toString.call(value);
|
|
374
|
+
return (tag === "[object Blob]" || tag === "[object File]") && typeof value.size === "number";
|
|
375
|
+
}
|
|
376
|
+
var SAVE_EXTENSIONS = {
|
|
377
|
+
"image/png": ["png"],
|
|
378
|
+
"image/jpeg": ["jpg", "jpeg"],
|
|
379
|
+
"image/webp": ["webp"],
|
|
380
|
+
"video/webm": ["webm"],
|
|
381
|
+
"video/mp4": ["mp4"],
|
|
382
|
+
"application/json": ["json"],
|
|
383
|
+
"text/plain": ["txt"]
|
|
384
|
+
};
|
|
385
|
+
function withExtension(name, mime) {
|
|
386
|
+
const extensions = SAVE_EXTENSIONS[mime];
|
|
387
|
+
const dot = name.lastIndexOf(".");
|
|
388
|
+
const current = dot === -1 ? "" : name.slice(dot + 1).toLowerCase();
|
|
389
|
+
return extensions.includes(current) ? name : `${name}.${extensions[0]}`;
|
|
390
|
+
}
|
|
391
|
+
function downloadHere(file, name) {
|
|
392
|
+
const w = win();
|
|
393
|
+
const d = doc();
|
|
394
|
+
const urls = w?.URL;
|
|
395
|
+
const host = d?.body ?? d?.documentElement;
|
|
396
|
+
if (!d || !host || !urls || typeof urls.createObjectURL !== "function") return fail("unsupported");
|
|
397
|
+
const href = urls.createObjectURL(file);
|
|
398
|
+
try {
|
|
399
|
+
const link = d.createElement("a");
|
|
400
|
+
link.href = href;
|
|
401
|
+
link.download = name;
|
|
402
|
+
link.style.display = "none";
|
|
403
|
+
host.appendChild(link);
|
|
404
|
+
link.click();
|
|
405
|
+
link.remove();
|
|
406
|
+
} finally {
|
|
407
|
+
const timer = setTimeout(() => {
|
|
408
|
+
try {
|
|
409
|
+
urls.revokeObjectURL(href);
|
|
410
|
+
} catch {
|
|
411
|
+
}
|
|
412
|
+
}, SAVE_URL_LIFETIME_MS);
|
|
413
|
+
timer.unref?.();
|
|
414
|
+
}
|
|
415
|
+
return { ok: true };
|
|
416
|
+
}
|
|
417
|
+
function setFullscreen(on2) {
|
|
418
|
+
return settled(() => {
|
|
419
|
+
if (typeof on2 !== "boolean") return fail("invalid_request");
|
|
420
|
+
const where = shell();
|
|
421
|
+
if (where === "app") return fail("unsupported");
|
|
422
|
+
if (where === "page" && shellOffers("fullscreen")) {
|
|
423
|
+
return askShell("fullscreen", (id) => ({ ...requestHead(id), cap: "fullscreen", on: on2 }));
|
|
424
|
+
}
|
|
425
|
+
return fullscreenHere(on2);
|
|
426
|
+
}, fail("unsupported"));
|
|
427
|
+
}
|
|
428
|
+
function fullscreenAllowed(d) {
|
|
429
|
+
const root = d.documentElement;
|
|
430
|
+
const request2 = root?.requestFullscreen ?? root?.webkitRequestFullscreen;
|
|
431
|
+
return typeof request2 === "function" && (d.fullscreenEnabled ?? d.webkitFullscreenEnabled) !== false;
|
|
432
|
+
}
|
|
433
|
+
async function fullscreenHere(on2) {
|
|
434
|
+
const d = doc();
|
|
435
|
+
if (!d) return fail("unsupported");
|
|
436
|
+
const current = d.fullscreenElement ?? d.webkitFullscreenElement ?? null;
|
|
437
|
+
if (!on2) {
|
|
438
|
+
if (!current) return { ok: true };
|
|
439
|
+
const exit = d.exitFullscreen ?? d.webkitExitFullscreen;
|
|
440
|
+
if (typeof exit !== "function") return fail("unsupported");
|
|
441
|
+
await exit.call(d);
|
|
442
|
+
return { ok: true };
|
|
443
|
+
}
|
|
444
|
+
if (!fullscreenAllowed(d)) return fail("unsupported");
|
|
445
|
+
if (current) return { ok: true };
|
|
446
|
+
const root = d.documentElement;
|
|
447
|
+
try {
|
|
448
|
+
await (root.requestFullscreen ?? root.webkitRequestFullscreen).call(root, { navigationUI: "hide" });
|
|
449
|
+
return { ok: true };
|
|
450
|
+
} catch {
|
|
451
|
+
return fail("needs_gesture");
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
function trustedParent() {
|
|
455
|
+
const origin = ctx?.getParentOrigin() ?? null;
|
|
456
|
+
const allowed = ctx?.getConfig()?.dashboardOrigins;
|
|
457
|
+
return origin !== null && allowed !== void 0 && allowed.includes(origin) ? origin : null;
|
|
458
|
+
}
|
|
459
|
+
function shellOffers(cap) {
|
|
460
|
+
return trustedParent() !== null && (ctx?.getShellCaps().includes(cap) ?? false);
|
|
461
|
+
}
|
|
462
|
+
function requestHead(id) {
|
|
463
|
+
return { type: PLATFORM_REQUEST_TYPE, v: PLATFORM_PROTOCOL_VERSION, id };
|
|
464
|
+
}
|
|
465
|
+
function askShell(cap, build) {
|
|
466
|
+
const w = win();
|
|
467
|
+
const origin = trustedParent();
|
|
468
|
+
if (!w || origin === null || !shellOffers(cap)) return fail("unsupported");
|
|
469
|
+
for (const waiting of pending.values()) {
|
|
470
|
+
if (waiting.cap === cap) return fail("busy");
|
|
471
|
+
}
|
|
472
|
+
const request2 = parsePlatformRequest(build(createBridgeId()));
|
|
473
|
+
if (!request2) return fail("invalid_request");
|
|
474
|
+
return new Promise((resolve) => {
|
|
475
|
+
const timer = setTimeout(
|
|
476
|
+
() => settle(request2.id, fail("timeout")),
|
|
477
|
+
cap === "fullscreen" ? replyTimeoutMs : confirmTimeoutMs
|
|
478
|
+
);
|
|
479
|
+
pending.set(request2.id, { cap, origin, resolve, timer });
|
|
480
|
+
if (!listening && typeof w.addEventListener === "function") {
|
|
481
|
+
w.addEventListener("message", onShellMessage);
|
|
482
|
+
listening = w;
|
|
483
|
+
}
|
|
484
|
+
if (cap !== "fullscreen") _releasePointer();
|
|
485
|
+
try {
|
|
486
|
+
w.parent.postMessage(request2, origin);
|
|
487
|
+
} catch {
|
|
488
|
+
settle(request2.id, fail("unsupported"));
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
function _releasePointer() {
|
|
493
|
+
try {
|
|
494
|
+
doc()?.exitPointerLock?.();
|
|
495
|
+
} catch {
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
function settle(id, outcome2) {
|
|
499
|
+
const waiting = pending.get(id);
|
|
500
|
+
if (!waiting) return;
|
|
501
|
+
pending.delete(id);
|
|
502
|
+
clearTimeout(waiting.timer);
|
|
503
|
+
waiting.resolve(outcome2);
|
|
504
|
+
}
|
|
505
|
+
function onShellMessage(event) {
|
|
506
|
+
const w = win();
|
|
507
|
+
if (!w || event.source !== w.parent) return;
|
|
508
|
+
const result = parsePlatformResult(event.data);
|
|
509
|
+
if (!result) return;
|
|
510
|
+
const waiting = pending.get(result.id);
|
|
511
|
+
if (!waiting || event.origin !== waiting.origin) return;
|
|
512
|
+
settle(result.id, result.ok ? { ok: true } : fail(result.code));
|
|
513
|
+
}
|
|
514
|
+
function supports(feature) {
|
|
515
|
+
try {
|
|
516
|
+
const w = win();
|
|
517
|
+
const d = doc();
|
|
518
|
+
if (!w || !d) return false;
|
|
519
|
+
const nav = w.navigator;
|
|
520
|
+
const where = shell();
|
|
521
|
+
const copy = typeof nav?.clipboard?.writeText === "function" || typeof d.execCommand === "function";
|
|
522
|
+
switch (feature) {
|
|
523
|
+
case "copy":
|
|
524
|
+
return copy;
|
|
525
|
+
case "share": {
|
|
526
|
+
const url = shareUrl(void 0);
|
|
527
|
+
if (!url) return false;
|
|
528
|
+
const sheet = !localTest() && !!nav && typeof nav.share === "function" && canShare(nav, { url });
|
|
529
|
+
return sheet || copy;
|
|
530
|
+
}
|
|
531
|
+
case "awake":
|
|
532
|
+
return where === "app" || typeof nav?.wakeLock?.request === "function";
|
|
533
|
+
case "haptic":
|
|
534
|
+
return where !== "app" && typeof nav?.vibrate === "function";
|
|
535
|
+
case "open":
|
|
536
|
+
return where === "page" ? shellOffers("open") : where !== "app" && typeof w.open === "function";
|
|
537
|
+
case "save":
|
|
538
|
+
return where === "page" ? shellOffers("save") : where !== "app" && typeof w.URL?.createObjectURL === "function";
|
|
539
|
+
case "fullscreen":
|
|
540
|
+
if (where === "app") return false;
|
|
541
|
+
return where === "page" && shellOffers("fullscreen") || fullscreenAllowed(d);
|
|
542
|
+
default:
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
} catch {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
function _resetPlatform(overrides) {
|
|
550
|
+
for (const waiting of pending.values()) clearTimeout(waiting.timer);
|
|
551
|
+
pending.clear();
|
|
552
|
+
if (listening) {
|
|
553
|
+
try {
|
|
554
|
+
listening.removeEventListener("message", onShellMessage);
|
|
555
|
+
} catch {
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
listening = null;
|
|
559
|
+
if (wakeHook) {
|
|
560
|
+
try {
|
|
561
|
+
wakeHook.d.removeEventListener("visibilitychange", wakeHook.onVisibility);
|
|
562
|
+
} catch {
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
wakeHook = null;
|
|
566
|
+
wakeWanted = false;
|
|
567
|
+
wakeSentinel = null;
|
|
568
|
+
wakeRequest = null;
|
|
569
|
+
shareParamsWarned = false;
|
|
570
|
+
replyTimeoutMs = overrides?.replyTimeoutMs ?? 3e3;
|
|
571
|
+
confirmTimeoutMs = overrides?.confirmTimeoutMs ?? 18e4;
|
|
572
|
+
}
|
|
13
573
|
|
|
14
574
|
// src/commerce.ts
|
|
15
575
|
var cfg = null;
|
|
@@ -84,6 +644,7 @@ function openConfirmSurface(view) {
|
|
|
84
644
|
if (!w) return { ok: false, reason: "no_window" };
|
|
85
645
|
if (c.isNative()) return { ok: false, reason: "native_unsupported" };
|
|
86
646
|
if (c.isEmbedded() && w.parent) {
|
|
647
|
+
_releasePointer();
|
|
87
648
|
for (const origin of c.dashboardOrigins) {
|
|
88
649
|
try {
|
|
89
650
|
w.parent.postMessage({ type: "genex:commerce:confirm", v: 1, intentId: view.id }, origin);
|
|
@@ -262,7 +823,11 @@ async function request(path, body) {
|
|
|
262
823
|
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
263
824
|
});
|
|
264
825
|
const result = await response.json().catch(() => ({}));
|
|
265
|
-
if (!response.ok)
|
|
826
|
+
if (!response.ok) {
|
|
827
|
+
const error = new Error(typeof result.error === "string" ? result.error : "generation_unavailable");
|
|
828
|
+
error.status = response.status;
|
|
829
|
+
throw error;
|
|
830
|
+
}
|
|
266
831
|
return result;
|
|
267
832
|
}
|
|
268
833
|
function validEstimateCoins(value) {
|
|
@@ -437,6 +1002,7 @@ async function startGeneration(path, body, timeoutMs, readOutcome, workflow, res
|
|
|
437
1002
|
if (popup && dashboard) {
|
|
438
1003
|
if (!popup.closed) popup.location.href = `${dashboard.origin}/play/generate/${encodeURIComponent(view.id)}`;
|
|
439
1004
|
} else if (parentOrigin2) {
|
|
1005
|
+
_releasePointer();
|
|
440
1006
|
window.parent.postMessage({ type: "genex:generation:confirm", v: 1, generationId: view.id }, parentOrigin2);
|
|
441
1007
|
}
|
|
442
1008
|
if (result) return result;
|
|
@@ -473,7 +1039,8 @@ function invalidGrantOptions(options) {
|
|
|
473
1039
|
function grantOutcome(view) {
|
|
474
1040
|
if (LIVE_GRANT_STATUSES.includes(view.status)) return { status: "active", grantId: view.id, grant: view };
|
|
475
1041
|
switch (view.status) {
|
|
476
|
-
// The player closing the sheet, or stopping later, is a normal outcome
|
|
1042
|
+
// The player closing the sheet, or stopping later, is a normal outcome —
|
|
1043
|
+
// whatever reason the server recorded for the stop.
|
|
477
1044
|
case "stopped":
|
|
478
1045
|
return { status: "canceled", grantId: view.id, grant: view };
|
|
479
1046
|
case "expired":
|
|
@@ -490,6 +1057,16 @@ function getSpendGrant(grantId) {
|
|
|
490
1057
|
if (!isGrantId(grantId)) return Promise.reject(new Error("invalid_grant_id"));
|
|
491
1058
|
return request(`/grants/${encodeURIComponent(grantId)}`);
|
|
492
1059
|
}
|
|
1060
|
+
async function getActiveSpendGrant() {
|
|
1061
|
+
try {
|
|
1062
|
+
const view = await request("/grants/current");
|
|
1063
|
+
if (!isGrantId(view.id)) throw new Error("invalid_grant_response");
|
|
1064
|
+
return view;
|
|
1065
|
+
} catch (error) {
|
|
1066
|
+
if (error.status === 404) return null;
|
|
1067
|
+
throw error;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
493
1070
|
function stopSpendGrant(grantId) {
|
|
494
1071
|
if (!isGrantId(grantId)) return Promise.reject(new Error("invalid_grant_id"));
|
|
495
1072
|
return request(`/grants/${encodeURIComponent(grantId)}/stop`, {});
|
|
@@ -537,14 +1114,15 @@ async function requestSpendGrant(options) {
|
|
|
537
1114
|
...options.judge !== void 0 ? { judge: { enabled: options.judge.enabled, estimatedCallsPerPeriod: options.judge.estimatedCallsPerPeriod } } : {}
|
|
538
1115
|
});
|
|
539
1116
|
if (!isGrantId(view.id)) throw new Error("invalid_grant_response");
|
|
540
|
-
const
|
|
541
|
-
if (
|
|
1117
|
+
const settled2 = grantOutcome(view);
|
|
1118
|
+
if (settled2) {
|
|
542
1119
|
popup?.close();
|
|
543
|
-
return
|
|
1120
|
+
return settled2;
|
|
544
1121
|
}
|
|
545
1122
|
if (popup && dashboard) {
|
|
546
1123
|
if (!popup.closed) popup.location.href = `${dashboard.origin}/play/grant/${encodeURIComponent(view.id)}`;
|
|
547
1124
|
} else if (parentOrigin2) {
|
|
1125
|
+
_releasePointer();
|
|
548
1126
|
window.parent.postMessage({ type: "genex:grant:confirm", v: 1, grantId: view.id }, parentOrigin2);
|
|
549
1127
|
}
|
|
550
1128
|
return pollGrant(view.id, options.timeoutMs ?? 6e5, popup);
|
|
@@ -708,8 +1286,8 @@ async function judge(options) {
|
|
|
708
1286
|
});
|
|
709
1287
|
if (!isGenerationId(view.generationId) || view.grantId !== options.grantId) throw new Error("invalid_judgment_response");
|
|
710
1288
|
if (view.status === "dispatching") {
|
|
711
|
-
const
|
|
712
|
-
return
|
|
1289
|
+
const settled2 = await poll(view.generationId, (options.timeoutMs ?? 2e4) + 1e4, judgeOutcome);
|
|
1290
|
+
return settled2.status === "pending" ? { ...settled2, billing: view.billing } : settled2;
|
|
713
1291
|
}
|
|
714
1292
|
return {
|
|
715
1293
|
status: view.status,
|
|
@@ -916,8 +1494,10 @@ var PROTOCOL_VERSION = 1;
|
|
|
916
1494
|
var RETRY_FLAG = "genex:embed:retry";
|
|
917
1495
|
var POPOVER_DISMISSED_FLAG = "genex:guest:popover-dismissed";
|
|
918
1496
|
var LOCAL_AUTH_FLAG = "genex:embed:local-auth";
|
|
1497
|
+
var ENTRY_REFERRER_MEMO = "genex:embed:entry-referrer";
|
|
1498
|
+
var ENTRY_REFERRER_NONE = "none";
|
|
919
1499
|
var PLAYER_ID_KEY = "genex:player";
|
|
920
|
-
var SDK_VERSION = "0.
|
|
1500
|
+
var SDK_VERSION = "0.32.0";
|
|
921
1501
|
var config2 = null;
|
|
922
1502
|
var state = "pending";
|
|
923
1503
|
var user = null;
|
|
@@ -930,11 +1510,13 @@ var nativeBootAt = 0;
|
|
|
930
1510
|
var embedToken;
|
|
931
1511
|
var colyseusUrls;
|
|
932
1512
|
var parentOrigin = null;
|
|
1513
|
+
var shellCaps = [];
|
|
933
1514
|
var initialized = false;
|
|
934
1515
|
var redeeming = false;
|
|
935
1516
|
var requestingGuest = false;
|
|
936
1517
|
var identityEpoch = 0;
|
|
937
1518
|
var handshakeTimeoutMs = 1e4;
|
|
1519
|
+
var standaloneWatchdogGraceMs = 2e3;
|
|
938
1520
|
var refreshDelayMs = 10 * 6e4;
|
|
939
1521
|
var refreshRetryMs = 6e4;
|
|
940
1522
|
var overlayTextDelayMs = 500;
|
|
@@ -945,6 +1527,10 @@ var refreshTimer;
|
|
|
945
1527
|
var unattendedWaiterTimer;
|
|
946
1528
|
var earlyWaiterWarned = false;
|
|
947
1529
|
var messageHandler;
|
|
1530
|
+
var entrySnapshot = null;
|
|
1531
|
+
var closingListeners = /* @__PURE__ */ new Set();
|
|
1532
|
+
var closingHooks = null;
|
|
1533
|
+
var closingFired = false;
|
|
948
1534
|
var listeners = /* @__PURE__ */ new Map();
|
|
949
1535
|
var authWaiters = [];
|
|
950
1536
|
var playerWaiters = [];
|
|
@@ -954,10 +1540,10 @@ var popoverMinimizeTimer;
|
|
|
954
1540
|
var pendingPlayerSave;
|
|
955
1541
|
var hasPendingPlayerSave = false;
|
|
956
1542
|
var pendingScores = /* @__PURE__ */ new Map();
|
|
957
|
-
function
|
|
1543
|
+
function win2() {
|
|
958
1544
|
return globalThis.window;
|
|
959
1545
|
}
|
|
960
|
-
function
|
|
1546
|
+
function doc2() {
|
|
961
1547
|
return globalThis.document;
|
|
962
1548
|
}
|
|
963
1549
|
function doFetch(input, init, timeoutMs) {
|
|
@@ -973,52 +1559,67 @@ function doFetch(input, init, timeoutMs) {
|
|
|
973
1559
|
}
|
|
974
1560
|
function readRetryFlag() {
|
|
975
1561
|
try {
|
|
976
|
-
return
|
|
1562
|
+
return win2()?.sessionStorage?.getItem(RETRY_FLAG) === "1";
|
|
977
1563
|
} catch {
|
|
978
1564
|
return false;
|
|
979
1565
|
}
|
|
980
1566
|
}
|
|
981
1567
|
function writeRetryFlag() {
|
|
982
1568
|
try {
|
|
983
|
-
|
|
1569
|
+
win2()?.sessionStorage?.setItem(RETRY_FLAG, "1");
|
|
984
1570
|
} catch {
|
|
985
1571
|
}
|
|
986
1572
|
}
|
|
987
1573
|
function clearRetryFlag() {
|
|
988
1574
|
try {
|
|
989
|
-
|
|
1575
|
+
win2()?.sessionStorage?.removeItem(RETRY_FLAG);
|
|
990
1576
|
} catch {
|
|
991
1577
|
}
|
|
992
1578
|
}
|
|
993
1579
|
function readLocalAuthFlag() {
|
|
994
1580
|
try {
|
|
995
|
-
return
|
|
1581
|
+
return win2()?.sessionStorage?.getItem(LOCAL_AUTH_FLAG) === "1";
|
|
996
1582
|
} catch {
|
|
997
1583
|
return false;
|
|
998
1584
|
}
|
|
999
1585
|
}
|
|
1000
1586
|
function writeLocalAuthFlag() {
|
|
1001
1587
|
try {
|
|
1002
|
-
|
|
1588
|
+
win2()?.sessionStorage?.setItem(LOCAL_AUTH_FLAG, "1");
|
|
1589
|
+
} catch {
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
function readEntryReferrerMemo() {
|
|
1593
|
+
try {
|
|
1594
|
+
const stored = win2()?.sessionStorage?.getItem(ENTRY_REFERRER_MEMO);
|
|
1595
|
+
if (stored === null || stored === void 0) return void 0;
|
|
1596
|
+
return sanitizeEntryReferrer(stored);
|
|
1597
|
+
} catch {
|
|
1598
|
+
return void 0;
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
function writeEntryReferrerMemo(referrer) {
|
|
1602
|
+
try {
|
|
1603
|
+
win2()?.sessionStorage?.setItem(ENTRY_REFERRER_MEMO, referrer ?? ENTRY_REFERRER_NONE);
|
|
1003
1604
|
} catch {
|
|
1004
1605
|
}
|
|
1005
1606
|
}
|
|
1006
1607
|
function readPopoverDismissed() {
|
|
1007
1608
|
try {
|
|
1008
|
-
return
|
|
1609
|
+
return win2()?.sessionStorage?.getItem(POPOVER_DISMISSED_FLAG) === "1";
|
|
1009
1610
|
} catch {
|
|
1010
1611
|
return false;
|
|
1011
1612
|
}
|
|
1012
1613
|
}
|
|
1013
1614
|
function writePopoverDismissed() {
|
|
1014
1615
|
try {
|
|
1015
|
-
|
|
1616
|
+
win2()?.sessionStorage?.setItem(POPOVER_DISMISSED_FLAG, "1");
|
|
1016
1617
|
} catch {
|
|
1017
1618
|
}
|
|
1018
1619
|
}
|
|
1019
1620
|
function playerId() {
|
|
1020
1621
|
try {
|
|
1021
|
-
const store =
|
|
1622
|
+
const store = win2()?.localStorage;
|
|
1022
1623
|
if (!store) return "no-storage";
|
|
1023
1624
|
let id = store.getItem(PLAYER_ID_KEY);
|
|
1024
1625
|
if (!id) {
|
|
@@ -1031,7 +1632,7 @@ function playerId() {
|
|
|
1031
1632
|
}
|
|
1032
1633
|
}
|
|
1033
1634
|
function initEmbed(cfg2) {
|
|
1034
|
-
const w =
|
|
1635
|
+
const w = win2();
|
|
1035
1636
|
if (!w) return;
|
|
1036
1637
|
if (initialized) return;
|
|
1037
1638
|
initialized = true;
|
|
@@ -1045,6 +1646,7 @@ function initEmbed(cfg2) {
|
|
|
1045
1646
|
dashboardOrigins: [...cfg2.dashboardOrigins]
|
|
1046
1647
|
};
|
|
1047
1648
|
state = "pending";
|
|
1649
|
+
rememberEntry(w);
|
|
1048
1650
|
_initCommerce({
|
|
1049
1651
|
apiUrl: config2.apiUrl,
|
|
1050
1652
|
dashboardOrigins: config2.dashboardOrigins,
|
|
@@ -1079,7 +1681,7 @@ function initEmbed(cfg2) {
|
|
|
1079
1681
|
}
|
|
1080
1682
|
}
|
|
1081
1683
|
function isEmbedded() {
|
|
1082
|
-
const w =
|
|
1684
|
+
const w = win2();
|
|
1083
1685
|
if (!w) return false;
|
|
1084
1686
|
try {
|
|
1085
1687
|
return w.self !== w.top;
|
|
@@ -1087,6 +1689,31 @@ function isEmbedded() {
|
|
|
1087
1689
|
return true;
|
|
1088
1690
|
}
|
|
1089
1691
|
}
|
|
1692
|
+
function getEntry() {
|
|
1693
|
+
const w = win2();
|
|
1694
|
+
const entry = w ? rememberEntry(w) : { search: "", hash: "", referrer: null };
|
|
1695
|
+
return {
|
|
1696
|
+
search: entry.search,
|
|
1697
|
+
params: new URLSearchParams(entry.search),
|
|
1698
|
+
hash: entry.hash,
|
|
1699
|
+
referrer: entry.referrer
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
function getShell() {
|
|
1703
|
+
const w = win2();
|
|
1704
|
+
if (!w) return "standalone";
|
|
1705
|
+
if (isEmbedded()) return "page";
|
|
1706
|
+
if (inNativeMode() || nativeBridge(w)) return "app";
|
|
1707
|
+
if (initialized) return localTestMode ? "local" : "standalone";
|
|
1708
|
+
return wantsLocalTestMode(w, false) ? "local" : "standalone";
|
|
1709
|
+
}
|
|
1710
|
+
function onShellClosing(cb) {
|
|
1711
|
+
closingListeners.add(cb);
|
|
1712
|
+
hookShellClosing();
|
|
1713
|
+
return () => {
|
|
1714
|
+
closingListeners.delete(cb);
|
|
1715
|
+
};
|
|
1716
|
+
}
|
|
1090
1717
|
function getAuthState() {
|
|
1091
1718
|
return state;
|
|
1092
1719
|
}
|
|
@@ -1421,12 +2048,90 @@ async function flushGuestQueue() {
|
|
|
1421
2048
|
emit("error", { error });
|
|
1422
2049
|
}
|
|
1423
2050
|
}
|
|
1424
|
-
function emit(event,
|
|
2051
|
+
function emit(event, ctx2) {
|
|
1425
2052
|
const set = listeners.get(event);
|
|
1426
2053
|
if (!set) return;
|
|
1427
2054
|
for (const cb of [...set]) {
|
|
1428
2055
|
try {
|
|
1429
|
-
cb(
|
|
2056
|
+
cb(ctx2);
|
|
2057
|
+
} catch {
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
var ENTRY_HIDDEN_KEYS = ["embed"];
|
|
2062
|
+
function readReturnFragment(hash, ownOrigin) {
|
|
2063
|
+
const empty = { ticket: null, guest: false, entryHash: "", entryReferrer: null };
|
|
2064
|
+
if (!hash || hash.length < 2) return empty;
|
|
2065
|
+
try {
|
|
2066
|
+
const params = new URLSearchParams(hash.slice(1));
|
|
2067
|
+
return {
|
|
2068
|
+
ticket: params.get("genex_ticket"),
|
|
2069
|
+
guest: params.get("genex_guest") === "1",
|
|
2070
|
+
entryHash: sanitizeEntryHash(params.get(ENTRY_HASH_KEY)),
|
|
2071
|
+
entryReferrer: sanitizeEntryReferrer(params.get(ENTRY_REFERRER_KEY), ownOrigin)
|
|
2072
|
+
};
|
|
2073
|
+
} catch {
|
|
2074
|
+
return empty;
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
function queryValue(search, key) {
|
|
2078
|
+
try {
|
|
2079
|
+
return new URLSearchParams(search).get(key);
|
|
2080
|
+
} catch {
|
|
2081
|
+
return null;
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
function rememberEntry(w) {
|
|
2085
|
+
if (entrySnapshot) return entrySnapshot;
|
|
2086
|
+
let search = "";
|
|
2087
|
+
let hash = "";
|
|
2088
|
+
let ownOrigin = null;
|
|
2089
|
+
try {
|
|
2090
|
+
search = w.location.search ?? "";
|
|
2091
|
+
hash = stashedTicketHash ?? w.location.hash ?? "";
|
|
2092
|
+
ownOrigin = w.location.origin ?? null;
|
|
2093
|
+
} catch {
|
|
2094
|
+
}
|
|
2095
|
+
const embedded = isEmbedded();
|
|
2096
|
+
const carried = readReturnFragment(hash, ownOrigin);
|
|
2097
|
+
const returnTrip = !embedded && (!!carried.ticket || carried.guest);
|
|
2098
|
+
const pairs = sanitizePassthroughQuery(search, ENTRY_HIDDEN_KEYS);
|
|
2099
|
+
entrySnapshot = {
|
|
2100
|
+
search: pairs ? `?${pairs}` : "",
|
|
2101
|
+
// Anywhere else the fragment is the game's as it stands, unless it names a
|
|
2102
|
+
// Genex key: that namespace is the platform's in a fragment too.
|
|
2103
|
+
hash: returnTrip ? carried.entryHash : hash.includes(RESERVED_QUERY_PREFIX) ? "" : hash,
|
|
2104
|
+
referrer: resolveEntryReferrer(search, embedded, returnTrip, carried.entryReferrer, ownOrigin)
|
|
2105
|
+
};
|
|
2106
|
+
return entrySnapshot;
|
|
2107
|
+
}
|
|
2108
|
+
function resolveEntryReferrer(search, embedded, returnTrip, carried, ownOrigin) {
|
|
2109
|
+
const known = readEntryReferrerMemo();
|
|
2110
|
+
if (known !== void 0) return known;
|
|
2111
|
+
let referrer;
|
|
2112
|
+
if (embedded) referrer = sanitizeEntryReferrer(queryValue(search, EMBED_REFERRER_PARAM), ownOrigin);
|
|
2113
|
+
else if (returnTrip) referrer = carried;
|
|
2114
|
+
else referrer = sanitizeEntryReferrer(doc2()?.referrer, ownOrigin);
|
|
2115
|
+
writeEntryReferrerMemo(referrer);
|
|
2116
|
+
return referrer;
|
|
2117
|
+
}
|
|
2118
|
+
function hookShellClosing() {
|
|
2119
|
+
const w = win2();
|
|
2120
|
+
if (!w || closingHooks || typeof w.addEventListener !== "function") return;
|
|
2121
|
+
const hide = () => fireShellClosing();
|
|
2122
|
+
const show = () => {
|
|
2123
|
+
closingFired = false;
|
|
2124
|
+
};
|
|
2125
|
+
w.addEventListener("pagehide", hide);
|
|
2126
|
+
w.addEventListener("pageshow", show);
|
|
2127
|
+
closingHooks = { w, hide, show };
|
|
2128
|
+
}
|
|
2129
|
+
function fireShellClosing() {
|
|
2130
|
+
if (closingFired || closingListeners.size === 0) return;
|
|
2131
|
+
closingFired = true;
|
|
2132
|
+
for (const cb of [...closingListeners]) {
|
|
2133
|
+
try {
|
|
2134
|
+
cb();
|
|
1430
2135
|
} catch {
|
|
1431
2136
|
}
|
|
1432
2137
|
}
|
|
@@ -1461,6 +2166,7 @@ async function handleParentMessage(event) {
|
|
|
1461
2166
|
}
|
|
1462
2167
|
if (handshakeTimer !== void 0) clearTimeout(handshakeTimer);
|
|
1463
2168
|
parentOrigin = event.origin;
|
|
2169
|
+
shellCaps = readPlatformCaps(data.caps);
|
|
1464
2170
|
if (isGuest) {
|
|
1465
2171
|
await requestGuestSession();
|
|
1466
2172
|
return;
|
|
@@ -1489,7 +2195,7 @@ function inNativeMode() {
|
|
|
1489
2195
|
return nativeEntry !== null;
|
|
1490
2196
|
}
|
|
1491
2197
|
function postToNative(message) {
|
|
1492
|
-
const w =
|
|
2198
|
+
const w = win2();
|
|
1493
2199
|
if (!w || !config2 || !nativeEntry) return;
|
|
1494
2200
|
const bridge = nativeBridge(w);
|
|
1495
2201
|
if (!bridge) return;
|
|
@@ -1541,6 +2247,7 @@ async function handleNativeCommand(payload) {
|
|
|
1541
2247
|
return;
|
|
1542
2248
|
case "cancel":
|
|
1543
2249
|
stopNativeTimers();
|
|
2250
|
+
fireShellClosing();
|
|
1544
2251
|
return;
|
|
1545
2252
|
case "foreground":
|
|
1546
2253
|
case "network":
|
|
@@ -1582,7 +2289,7 @@ function clearNativeReauth() {
|
|
|
1582
2289
|
nativeReauthTimer = void 0;
|
|
1583
2290
|
}
|
|
1584
2291
|
function postToParent(message, targetOrigin) {
|
|
1585
|
-
const w =
|
|
2292
|
+
const w = win2();
|
|
1586
2293
|
if (!w || !isEmbedded()) return;
|
|
1587
2294
|
try {
|
|
1588
2295
|
w.parent.postMessage(message, targetOrigin);
|
|
@@ -1609,47 +2316,30 @@ function armStandaloneWatchdog() {
|
|
|
1609
2316
|
handshakeTimer = setTimeout(() => {
|
|
1610
2317
|
handshakeTimer = void 0;
|
|
1611
2318
|
if (state === "pending") enterBlocked("no-identity");
|
|
1612
|
-
}, handshakeTimeoutMs);
|
|
2319
|
+
}, handshakeTimeoutMs + standaloneWatchdogGraceMs);
|
|
1613
2320
|
}
|
|
1614
2321
|
var stashedTicketHash = null;
|
|
1615
2322
|
function _stashTicketFromUrl() {
|
|
1616
|
-
const w =
|
|
2323
|
+
const w = win2();
|
|
1617
2324
|
if (!w) return;
|
|
1618
2325
|
const hash = w.location.hash;
|
|
1619
2326
|
if (!hash || !hash.includes("genex_")) return;
|
|
1620
2327
|
stashedTicketHash = hash;
|
|
1621
2328
|
try {
|
|
1622
|
-
w.history.replaceState(null, "", cleanUrl(w));
|
|
2329
|
+
w.history.replaceState(w.history.state ?? null, "", cleanUrl(w) + readReturnFragment(hash).entryHash);
|
|
1623
2330
|
} catch {
|
|
1624
2331
|
}
|
|
1625
2332
|
}
|
|
1626
2333
|
function cleanUrl(w) {
|
|
1627
|
-
|
|
1628
|
-
try {
|
|
1629
|
-
const params = new URLSearchParams(search);
|
|
1630
|
-
params.delete("genex_r");
|
|
1631
|
-
const rest = params.toString();
|
|
1632
|
-
search = rest ? `?${rest}` : "";
|
|
1633
|
-
} catch {
|
|
1634
|
-
}
|
|
1635
|
-
return w.location.pathname + search;
|
|
2334
|
+
return w.location.pathname + stripReturnMarker(w.location.search);
|
|
1636
2335
|
}
|
|
1637
2336
|
function readFragment(w) {
|
|
1638
2337
|
const hash = stashedTicketHash ?? w.location.hash;
|
|
1639
2338
|
stashedTicketHash = null;
|
|
1640
|
-
|
|
1641
|
-
let ticket = null;
|
|
1642
|
-
let guest = false;
|
|
1643
|
-
try {
|
|
1644
|
-
const params = new URLSearchParams(hash.slice(1));
|
|
1645
|
-
ticket = params.get("genex_ticket");
|
|
1646
|
-
guest = params.get("genex_guest") === "1";
|
|
1647
|
-
} catch {
|
|
1648
|
-
return { ticket: null, guest: false };
|
|
1649
|
-
}
|
|
2339
|
+
const { ticket, guest, entryHash } = readReturnFragment(hash);
|
|
1650
2340
|
if (ticket || guest) {
|
|
1651
2341
|
try {
|
|
1652
|
-
w.history.replaceState(null, "", cleanUrl(w));
|
|
2342
|
+
w.history.replaceState(w.history.state ?? null, "", cleanUrl(w) + entryHash);
|
|
1653
2343
|
} catch {
|
|
1654
2344
|
}
|
|
1655
2345
|
}
|
|
@@ -1663,9 +2353,19 @@ async function redirectToAuthorize(w, opts) {
|
|
|
1663
2353
|
enterBlocked();
|
|
1664
2354
|
return;
|
|
1665
2355
|
}
|
|
1666
|
-
|
|
2356
|
+
let returnTo = w.location.origin + w.location.pathname;
|
|
2357
|
+
const query = stripNativeEntry(stripReturnMarker(w.location.search));
|
|
2358
|
+
if (
|
|
2359
|
+
// The cap is on the pairs; `query` is '' or starts with the one `?`.
|
|
2360
|
+
query.length - 1 <= MAX_ENTRY_QUERY_LENGTH && returnTo.length + query.length <= MAX_RETURN_TO_LENGTH && query.indexOf("#") === -1
|
|
2361
|
+
) {
|
|
2362
|
+
returnTo += query;
|
|
2363
|
+
}
|
|
1667
2364
|
const guestParam = opts?.guestOk ? "&guest=ok" : "";
|
|
1668
|
-
|
|
2365
|
+
let url = `${origin}/play/authorize?returnTo=${encodeURIComponent(returnTo)}&slug=${encodeURIComponent(config2.slug)}${guestParam}`;
|
|
2366
|
+
const referrer = rememberEntry(w).referrer;
|
|
2367
|
+
if (referrer) url += `&${AUTHORIZE_ENTRY_REF_PARAM}=${encodeURIComponent(referrer)}`;
|
|
2368
|
+
url += sanitizeEntryHash(w.location.hash);
|
|
1669
2369
|
w.location.replace(url);
|
|
1670
2370
|
}
|
|
1671
2371
|
async function fetchDashboardOrigins() {
|
|
@@ -1725,10 +2425,10 @@ async function redeemTicket(ticket) {
|
|
|
1725
2425
|
startHeartbeat();
|
|
1726
2426
|
}
|
|
1727
2427
|
if (upgradingFromGuest) await flushGuestQueue();
|
|
1728
|
-
const
|
|
1729
|
-
for (const waiter of authWaiters.splice(0)) waiter.resolve(
|
|
2428
|
+
const ctx2 = { user };
|
|
2429
|
+
for (const waiter of authWaiters.splice(0)) waiter.resolve(ctx2);
|
|
1730
2430
|
for (const waiter of playerWaiters.splice(0)) waiter.resolve({ user, guest: false });
|
|
1731
|
-
emit("authenticated",
|
|
2431
|
+
emit("authenticated", ctx2);
|
|
1732
2432
|
} catch (error) {
|
|
1733
2433
|
if (epoch !== identityEpoch) return;
|
|
1734
2434
|
emit("error", { error });
|
|
@@ -1790,9 +2490,9 @@ function enterGuest() {
|
|
|
1790
2490
|
showGuestPopover();
|
|
1791
2491
|
}
|
|
1792
2492
|
if (user) {
|
|
1793
|
-
const
|
|
2493
|
+
const ctx2 = { user };
|
|
1794
2494
|
for (const waiter of playerWaiters.splice(0)) waiter.resolve({ user, guest: true });
|
|
1795
|
-
emit("guest",
|
|
2495
|
+
emit("guest", ctx2);
|
|
1796
2496
|
}
|
|
1797
2497
|
}
|
|
1798
2498
|
function isLoopbackLocation(w) {
|
|
@@ -1803,7 +2503,7 @@ function isLoopbackLocation(w) {
|
|
|
1803
2503
|
return false;
|
|
1804
2504
|
}
|
|
1805
2505
|
}
|
|
1806
|
-
function wantsLocalTestMode(w) {
|
|
2506
|
+
function wantsLocalTestMode(w, latch = true) {
|
|
1807
2507
|
if (isEmbedded()) return false;
|
|
1808
2508
|
if (detectNativeEntry(w)) return false;
|
|
1809
2509
|
if (!isLoopbackLocation(w)) return false;
|
|
@@ -1814,7 +2514,7 @@ function wantsLocalTestMode(w) {
|
|
|
1814
2514
|
}
|
|
1815
2515
|
if (params?.get("genex_local_test") === "1") return true;
|
|
1816
2516
|
if (params?.get("genex_auth") === "1") {
|
|
1817
|
-
writeLocalAuthFlag();
|
|
2517
|
+
if (latch) writeLocalAuthFlag();
|
|
1818
2518
|
return false;
|
|
1819
2519
|
}
|
|
1820
2520
|
if (readLocalAuthFlag()) return false;
|
|
@@ -1841,7 +2541,7 @@ function enterLocalTestMode(w) {
|
|
|
1841
2541
|
emit("guest", { user: localUser });
|
|
1842
2542
|
}
|
|
1843
2543
|
async function handleRedeemFailure() {
|
|
1844
|
-
const w =
|
|
2544
|
+
const w = win2();
|
|
1845
2545
|
if (handshakeTimer !== void 0) clearTimeout(handshakeTimer);
|
|
1846
2546
|
handshakeTimer = void 0;
|
|
1847
2547
|
if (inNativeMode()) {
|
|
@@ -1967,7 +2667,7 @@ function scrambleNoise(length) {
|
|
|
1967
2667
|
}
|
|
1968
2668
|
function scrambleStatic() {
|
|
1969
2669
|
try {
|
|
1970
|
-
const w =
|
|
2670
|
+
const w = win2();
|
|
1971
2671
|
if (!w || typeof w.matchMedia !== "function") return true;
|
|
1972
2672
|
return w.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1973
2673
|
} catch {
|
|
@@ -2024,7 +2724,7 @@ function ensureOverlayFont(d) {
|
|
|
2024
2724
|
if (overlayFontRequested) return;
|
|
2025
2725
|
overlayFontRequested = true;
|
|
2026
2726
|
try {
|
|
2027
|
-
const FF =
|
|
2727
|
+
const FF = win2()?.FontFace;
|
|
2028
2728
|
const fonts = d.fonts;
|
|
2029
2729
|
if (!FF || !fonts?.add) return;
|
|
2030
2730
|
const face = new FF("Geist Mono", `url(${OVERLAY_FONT_URL}) format('woff2')`, {
|
|
@@ -2037,7 +2737,7 @@ function ensureOverlayFont(d) {
|
|
|
2037
2737
|
}
|
|
2038
2738
|
}
|
|
2039
2739
|
function showOverlay(kind) {
|
|
2040
|
-
const d =
|
|
2740
|
+
const d = doc2();
|
|
2041
2741
|
if (!d?.createElement) return;
|
|
2042
2742
|
try {
|
|
2043
2743
|
if (!overlayEl) overlayEl = buildOverlay(d);
|
|
@@ -2085,7 +2785,7 @@ function buildOverlay(d) {
|
|
|
2085
2785
|
button.style.background = "#4b60bf";
|
|
2086
2786
|
});
|
|
2087
2787
|
button.addEventListener("click", () => {
|
|
2088
|
-
const w =
|
|
2788
|
+
const w = win2();
|
|
2089
2789
|
if (!w) return;
|
|
2090
2790
|
button.disabled = true;
|
|
2091
2791
|
clearRetryFlag();
|
|
@@ -2138,7 +2838,7 @@ function buildOverlay(d) {
|
|
|
2138
2838
|
};
|
|
2139
2839
|
}
|
|
2140
2840
|
function showGuestPopover() {
|
|
2141
|
-
const d =
|
|
2841
|
+
const d = doc2();
|
|
2142
2842
|
if (!d?.createElement || popoverEl) return;
|
|
2143
2843
|
try {
|
|
2144
2844
|
popoverEl = buildGuestPopover(d);
|
|
@@ -2161,7 +2861,7 @@ function buildGuestPopover(d) {
|
|
|
2161
2861
|
ensureOverlayFont(d);
|
|
2162
2862
|
let mobile = false;
|
|
2163
2863
|
try {
|
|
2164
|
-
const w =
|
|
2864
|
+
const w = win2();
|
|
2165
2865
|
const nav = w?.navigator;
|
|
2166
2866
|
if (w && nav) {
|
|
2167
2867
|
const coarse = w.matchMedia?.("(pointer: coarse)").matches ?? false;
|
|
@@ -2191,7 +2891,7 @@ function buildGuestPopover(d) {
|
|
|
2191
2891
|
signIn.style.background = "#4b60bf";
|
|
2192
2892
|
});
|
|
2193
2893
|
signIn.addEventListener("click", () => {
|
|
2194
|
-
const w =
|
|
2894
|
+
const w = win2();
|
|
2195
2895
|
if (!w) return;
|
|
2196
2896
|
signIn.disabled = true;
|
|
2197
2897
|
clearRetryFlag();
|
|
@@ -2232,7 +2932,7 @@ function buildGuestPopover(d) {
|
|
|
2232
2932
|
return { root };
|
|
2233
2933
|
}
|
|
2234
2934
|
function __resetForTests(overrides) {
|
|
2235
|
-
const w =
|
|
2935
|
+
const w = win2();
|
|
2236
2936
|
if (w && messageHandler) w.removeEventListener("message", messageHandler);
|
|
2237
2937
|
messageHandler = void 0;
|
|
2238
2938
|
if (handshakeTimer !== void 0) clearTimeout(handshakeTimer);
|
|
@@ -2257,6 +2957,7 @@ function __resetForTests(overrides) {
|
|
|
2257
2957
|
embedToken = void 0;
|
|
2258
2958
|
colyseusUrls = void 0;
|
|
2259
2959
|
parentOrigin = null;
|
|
2960
|
+
shellCaps = [];
|
|
2260
2961
|
initialized = false;
|
|
2261
2962
|
redeeming = false;
|
|
2262
2963
|
requestingGuest = false;
|
|
@@ -2265,18 +2966,55 @@ function __resetForTests(overrides) {
|
|
|
2265
2966
|
authWaiters = [];
|
|
2266
2967
|
playerWaiters = [];
|
|
2267
2968
|
stashedTicketHash = null;
|
|
2969
|
+
entrySnapshot = null;
|
|
2970
|
+
if (closingHooks) {
|
|
2971
|
+
try {
|
|
2972
|
+
closingHooks.w.removeEventListener("pagehide", closingHooks.hide);
|
|
2973
|
+
closingHooks.w.removeEventListener("pageshow", closingHooks.show);
|
|
2974
|
+
} catch {
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
closingHooks = null;
|
|
2978
|
+
closingListeners.clear();
|
|
2979
|
+
closingFired = false;
|
|
2268
2980
|
pendingPlayerSave = void 0;
|
|
2269
2981
|
hasPendingPlayerSave = false;
|
|
2270
2982
|
pendingScores.clear();
|
|
2271
2983
|
handshakeTimeoutMs = overrides?.handshakeTimeoutMs ?? 1e4;
|
|
2984
|
+
standaloneWatchdogGraceMs = overrides?.standaloneWatchdogGraceMs ?? 2e3;
|
|
2272
2985
|
refreshDelayMs = overrides?.refreshDelayMs ?? 10 * 6e4;
|
|
2273
2986
|
refreshRetryMs = overrides?.refreshRetryMs ?? 6e4;
|
|
2274
2987
|
overlayTextDelayMs = overrides?.overlayTextDelayMs ?? 500;
|
|
2275
2988
|
nativeReauthTimeoutMs = overrides?.nativeReauthTimeoutMs ?? 3e4;
|
|
2276
2989
|
heartbeatIntervalMs = overrides?.heartbeatIntervalMs ?? 3e4;
|
|
2990
|
+
_resetPlatform({
|
|
2991
|
+
replyTimeoutMs: overrides?.platformReplyTimeoutMs,
|
|
2992
|
+
confirmTimeoutMs: overrides?.platformConfirmTimeoutMs
|
|
2993
|
+
});
|
|
2277
2994
|
}
|
|
2995
|
+
_initPlatform({
|
|
2996
|
+
getShell,
|
|
2997
|
+
// getShell()'s own reading of local test mode, without its `app` answer
|
|
2998
|
+
// in front: a dev server inside a React Native WebView is both.
|
|
2999
|
+
isLocalTest: () => {
|
|
3000
|
+
const w = win2();
|
|
3001
|
+
if (!w || isEmbedded()) return false;
|
|
3002
|
+
return initialized ? localTestMode : wantsLocalTestMode(w, false);
|
|
3003
|
+
},
|
|
3004
|
+
getConfig: () => config2,
|
|
3005
|
+
getParentOrigin: () => parentOrigin,
|
|
3006
|
+
getShellCaps: () => shellCaps
|
|
3007
|
+
});
|
|
2278
3008
|
|
|
2279
3009
|
export {
|
|
3010
|
+
share,
|
|
3011
|
+
copyText,
|
|
3012
|
+
keepAwake,
|
|
3013
|
+
haptic,
|
|
3014
|
+
openExternal,
|
|
3015
|
+
saveFile,
|
|
3016
|
+
setFullscreen,
|
|
3017
|
+
supports,
|
|
2280
3018
|
getShop,
|
|
2281
3019
|
getEntitlements,
|
|
2282
3020
|
consumeEntitlement,
|
|
@@ -2289,6 +3027,7 @@ export {
|
|
|
2289
3027
|
requestWorkflow,
|
|
2290
3028
|
resumeWorkflow,
|
|
2291
3029
|
getSpendGrant,
|
|
3030
|
+
getActiveSpendGrant,
|
|
2292
3031
|
stopSpendGrant,
|
|
2293
3032
|
requestSpendGrant,
|
|
2294
3033
|
generateStream,
|
|
@@ -2296,6 +3035,9 @@ export {
|
|
|
2296
3035
|
generationErrorMessage,
|
|
2297
3036
|
initEmbed,
|
|
2298
3037
|
isEmbedded,
|
|
3038
|
+
getEntry,
|
|
3039
|
+
getShell,
|
|
3040
|
+
onShellClosing,
|
|
2299
3041
|
getAuthState,
|
|
2300
3042
|
getUser,
|
|
2301
3043
|
getEmbedToken,
|