@genex-ai/embed-sdk 0.4.1 → 0.5.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/dist/{chunk-LWEYUUBS.js → chunk-GDJLPL6W.js} +43 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/sentry.js +1 -1
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ var POPOVER_DISMISSED_FLAG = "genex:guest:popover-dismissed";
|
|
|
5
5
|
var config = null;
|
|
6
6
|
var state = "pending";
|
|
7
7
|
var user = null;
|
|
8
|
+
var localTestMode = false;
|
|
8
9
|
var embedToken;
|
|
9
10
|
var colyseusUrl;
|
|
10
11
|
var parentOrigin = null;
|
|
@@ -77,6 +78,10 @@ function initEmbed(cfg) {
|
|
|
77
78
|
dashboardOrigins: [...cfg.dashboardOrigins]
|
|
78
79
|
};
|
|
79
80
|
state = "pending";
|
|
81
|
+
if (wantsLocalTest(w)) {
|
|
82
|
+
enterLocalTestMode(w);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
80
85
|
showOverlay("connecting");
|
|
81
86
|
if (isEmbedded()) {
|
|
82
87
|
startEmbeddedHandshake(w);
|
|
@@ -234,6 +239,7 @@ async function submitScore(score, opts) {
|
|
|
234
239
|
}
|
|
235
240
|
async function getLeaderboard(opts) {
|
|
236
241
|
if (!config) throw new Error("genex embed: call initEmbed() first");
|
|
242
|
+
if (localTestMode) return { items: [], me: null };
|
|
237
243
|
if (state === "pending") {
|
|
238
244
|
try {
|
|
239
245
|
await waitForPlayer();
|
|
@@ -383,7 +389,7 @@ function readFragment(w) {
|
|
|
383
389
|
return { ticket, guest };
|
|
384
390
|
}
|
|
385
391
|
async function redirectToAuthorize(w, opts) {
|
|
386
|
-
if (!config) return;
|
|
392
|
+
if (!config || localTestMode) return;
|
|
387
393
|
const origin = opts?.guestOk ? config.dashboardOrigins[0] ?? (await fetchDashboardOrigins())[0] : (await fetchDashboardOrigins())[0] ?? config.dashboardOrigins[0];
|
|
388
394
|
if (!origin) {
|
|
389
395
|
enterBlocked();
|
|
@@ -408,7 +414,7 @@ async function fetchDashboardOrigins() {
|
|
|
408
414
|
return config.dashboardOrigins;
|
|
409
415
|
}
|
|
410
416
|
async function redeemTicket(ticket) {
|
|
411
|
-
if (!config || redeeming || state !== "pending" && state !== "guest") return;
|
|
417
|
+
if (!config || localTestMode || redeeming || state !== "pending" && state !== "guest") return;
|
|
412
418
|
const upgradingFromGuest = state === "guest";
|
|
413
419
|
redeeming = true;
|
|
414
420
|
try {
|
|
@@ -448,7 +454,7 @@ async function redeemTicket(ticket) {
|
|
|
448
454
|
}
|
|
449
455
|
}
|
|
450
456
|
async function requestGuestSession() {
|
|
451
|
-
if (!config || requestingGuest || redeeming) return;
|
|
457
|
+
if (!config || localTestMode || requestingGuest || redeeming) return;
|
|
452
458
|
if (state !== "pending" && state !== "guest") return;
|
|
453
459
|
requestingGuest = true;
|
|
454
460
|
try {
|
|
@@ -494,6 +500,39 @@ function enterGuest() {
|
|
|
494
500
|
emit("guest", ctx);
|
|
495
501
|
}
|
|
496
502
|
}
|
|
503
|
+
function isLoopbackLocation(w) {
|
|
504
|
+
try {
|
|
505
|
+
const u = new URL(w.location.origin);
|
|
506
|
+
return u.protocol === "http:" && (u.hostname === "localhost" || u.hostname === "127.0.0.1" || u.hostname === "[::1]");
|
|
507
|
+
} catch {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function wantsLocalTest(w) {
|
|
512
|
+
if (isEmbedded()) return false;
|
|
513
|
+
if (!isLoopbackLocation(w)) return false;
|
|
514
|
+
try {
|
|
515
|
+
return new URLSearchParams(w.location.search).get("genex_local_test") === "1";
|
|
516
|
+
} catch {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function enterLocalTestMode(w) {
|
|
521
|
+
localTestMode = true;
|
|
522
|
+
readFragment(w);
|
|
523
|
+
const localUser = { id: "local:test", name: "Local Tester" };
|
|
524
|
+
user = localUser;
|
|
525
|
+
state = "guest";
|
|
526
|
+
removeOverlay();
|
|
527
|
+
try {
|
|
528
|
+
console.info(
|
|
529
|
+
"[genex] local test mode \u2014 local visuals and controls only. Auth, saves, leaderboards, and multiplayer are NOT validated here; no Genex credential exists."
|
|
530
|
+
);
|
|
531
|
+
} catch {
|
|
532
|
+
}
|
|
533
|
+
for (const waiter of playerWaiters.splice(0)) waiter.resolve({ user: localUser, guest: true });
|
|
534
|
+
emit("guest", { user: localUser });
|
|
535
|
+
}
|
|
497
536
|
async function handleRedeemFailure() {
|
|
498
537
|
const w = win();
|
|
499
538
|
if (w && !isEmbedded() && !readRetryFlag()) {
|
|
@@ -683,6 +722,7 @@ function __resetForTests(overrides) {
|
|
|
683
722
|
config = null;
|
|
684
723
|
state = "pending";
|
|
685
724
|
user = null;
|
|
725
|
+
localTestMode = false;
|
|
686
726
|
embedToken = void 0;
|
|
687
727
|
colyseusUrl = void 0;
|
|
688
728
|
parentOrigin = null;
|
package/dist/index.d.ts
CHANGED
|
@@ -98,6 +98,9 @@ declare function getAuthState(): AuthState;
|
|
|
98
98
|
/**
|
|
99
99
|
* The current player — non-null once 'authenticated' OR 'guest'. Guests have
|
|
100
100
|
* an `id` prefixed `guest:` and a server-assigned name like "Guest-1234".
|
|
101
|
+
* Local test mode is the one guest-state exception: `id` is `local:test`
|
|
102
|
+
* (a prefix that can never collide with `guest:` or account ids) and the
|
|
103
|
+
* name is "Local Tester".
|
|
101
104
|
*/
|
|
102
105
|
declare function getUser(): EmbedUser | null;
|
|
103
106
|
/**
|
package/dist/index.js
CHANGED
package/dist/sentry.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genex-ai/embed-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Player identity + durable game state for genex games — signed-in or guest play, per-player save slots, shared world state, and soft-trust leaderboards.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|