@genex-ai/embed-sdk 0.3.0 → 0.3.2

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.
@@ -1,7 +1,6 @@
1
1
  // src/index.ts
2
2
  var PROTOCOL_VERSION = 1;
3
3
  var RETRY_FLAG = "genex:embed:retry";
4
- var PREFER_AUTH_FLAG = "genex:prefer-auth";
5
4
  var POPOVER_DISMISSED_FLAG = "genex:guest:popover-dismissed";
6
5
  var config = null;
7
6
  var state = "pending";
@@ -51,19 +50,6 @@ function clearRetryFlag() {
51
50
  } catch {
52
51
  }
53
52
  }
54
- function readPreferAuth() {
55
- try {
56
- return win()?.localStorage?.getItem(PREFER_AUTH_FLAG) === "1";
57
- } catch {
58
- return false;
59
- }
60
- }
61
- function writePreferAuth() {
62
- try {
63
- win()?.localStorage?.setItem(PREFER_AUTH_FLAG, "1");
64
- } catch {
65
- }
66
- }
67
53
  function readPopoverDismissed() {
68
54
  try {
69
55
  return win()?.sessionStorage?.getItem(POPOVER_DISMISSED_FLAG) === "1";
@@ -207,12 +193,8 @@ async function startStandaloneFlow(w) {
207
193
  await requestGuestSession();
208
194
  return;
209
195
  }
210
- if (readPreferAuth()) {
211
- showOverlay("redirecting");
212
- await redirectToAuthorize(w, { guestOk: true });
213
- return;
214
- }
215
- await requestGuestSession();
196
+ showOverlay("redirecting");
197
+ await redirectToAuthorize(w, { guestOk: true });
216
198
  }
217
199
  var stashedTicketHash = null;
218
200
  function _stashTicketFromUrl() {
@@ -222,10 +204,21 @@ function _stashTicketFromUrl() {
222
204
  if (!hash || !hash.includes("genex_")) return;
223
205
  stashedTicketHash = hash;
224
206
  try {
225
- w.history.replaceState(null, "", w.location.pathname + w.location.search);
207
+ w.history.replaceState(null, "", cleanUrl(w));
226
208
  } catch {
227
209
  }
228
210
  }
211
+ function cleanUrl(w) {
212
+ let search = w.location.search;
213
+ try {
214
+ const params = new URLSearchParams(search);
215
+ params.delete("genex_r");
216
+ const rest = params.toString();
217
+ search = rest ? `?${rest}` : "";
218
+ } catch {
219
+ }
220
+ return w.location.pathname + search;
221
+ }
229
222
  function readFragment(w) {
230
223
  const hash = stashedTicketHash ?? w.location.hash;
231
224
  stashedTicketHash = null;
@@ -241,7 +234,7 @@ function readFragment(w) {
241
234
  }
242
235
  if (ticket || guest) {
243
236
  try {
244
- w.history.replaceState(null, "", w.location.pathname + w.location.search);
237
+ w.history.replaceState(null, "", cleanUrl(w));
245
238
  } catch {
246
239
  }
247
240
  }
@@ -249,8 +242,7 @@ function readFragment(w) {
249
242
  }
250
243
  async function redirectToAuthorize(w, opts) {
251
244
  if (!config) return;
252
- const origins = await fetchDashboardOrigins();
253
- const origin = origins[0] ?? config.dashboardOrigins[0];
245
+ const origin = opts?.guestOk ? config.dashboardOrigins[0] ?? (await fetchDashboardOrigins())[0] : (await fetchDashboardOrigins())[0] ?? config.dashboardOrigins[0];
254
246
  if (!origin) {
255
247
  enterBlocked();
256
248
  return;
@@ -295,7 +287,6 @@ async function redeemTicket(ticket) {
295
287
  void colyseusUrl;
296
288
  state = "authenticated";
297
289
  clearRetryFlag();
298
- writePreferAuth();
299
290
  removeOverlay();
300
291
  removeGuestPopover();
301
292
  scheduleRefresh();
@@ -365,7 +356,7 @@ async function handleRedeemFailure() {
365
356
  if (w && !isEmbedded() && !readRetryFlag()) {
366
357
  writeRetryFlag();
367
358
  showOverlay("redirecting");
368
- await redirectToAuthorize(w);
359
+ await redirectToAuthorize(w, { guestOk: true });
369
360
  return;
370
361
  }
371
362
  enterBlocked();
@@ -430,7 +421,9 @@ function enterBlocked() {
430
421
  }
431
422
  var OVERLAY_TEXT = {
432
423
  connecting: { title: "Connecting to Genex\u2026" },
433
- redirecting: { title: "Signing you in\u2026" },
424
+ // Neutral on purpose: the automatic bounce precedes GUEST play as often as
425
+ // sign-in — "signing you in" would be wrong for most visitors.
426
+ redirecting: { title: "Loading\u2026" },
434
427
  "blocked-standalone": { title: "Sign in to play", button: "Sign in" },
435
428
  "blocked-embedded": { title: "Sign in on the Genex dashboard to continue" }
436
429
  };
@@ -454,7 +447,7 @@ function removeOverlay() {
454
447
  function buildOverlay(d) {
455
448
  const root = d.createElement("div");
456
449
  root.setAttribute("data-genex-embed-overlay", "");
457
- root.style.cssText = "position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;flex-direction:column;gap:16px;background:rgba(8,10,20,0.92);color:#fff;font-family:system-ui,-apple-system,sans-serif;text-align:center;pointer-events:auto;user-select:none";
450
+ root.style.cssText = "position:fixed;inset:0;z-index:2147483647;display:flex;align-items:center;justify-content:center;flex-direction:column;gap:16px;background:#080a14;color:#fff;font-family:system-ui,-apple-system,sans-serif;text-align:center;pointer-events:auto;user-select:none";
458
451
  const title = d.createElement("div");
459
452
  title.style.cssText = "font-size:18px;font-weight:600;padding:0 24px";
460
453
  root.appendChild(title);
package/dist/index.d.ts CHANGED
@@ -28,10 +28,10 @@ interface EventContext {
28
28
  * identity (multiplayer connect, name UI) and waitForAuth() for anything that
29
29
  * needs a signed-in ACCOUNT (/state saves).
30
30
  *
31
- * Standalone (not in an iframe) with no return-trip ticket present, this
32
- * mints a guest session in place (published games) — sign-in happens on the
33
- * guest popover's own button, or automatically for returning account holders
34
- * (prefer-auth hint).
31
+ * Standalone (not in an iframe) with no return-trip fragment present, this
32
+ * bounces once through the dashboard's /play/authorize and comes straight
33
+ * back — signed-in visitors arrive authenticated (zero clicks, any game),
34
+ * everyone else arrives as a guest (published games; no login wall).
35
35
  */
36
36
  declare function initEmbed(cfg: EmbedConfig): void;
37
37
  /**
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  on,
11
11
  waitForAuth,
12
12
  waitForPlayer
13
- } from "./chunk-IB4PTSH5.js";
13
+ } from "./chunk-A2RFRR7H.js";
14
14
  export {
15
15
  __resetForTests,
16
16
  _stashTicketFromUrl,
package/dist/sentry.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  _stashTicketFromUrl,
3
3
  getUser,
4
4
  on
5
- } from "./chunk-IB4PTSH5.js";
5
+ } from "./chunk-A2RFRR7H.js";
6
6
 
7
7
  // src/sentry.ts
8
8
  import * as Sentry from "@sentry/browser";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genex-ai/embed-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "Player identity for genex games — signed-in (dashboard iframe postMessage handshake or sign-in redirect) or guest (accountless play for published games, sign in to save).",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",