glitch-javascript-sdk 4.0.0 → 4.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 CHANGED
@@ -50,6 +50,7 @@ import Glitch from 'glitch-javascript-sdk';
50
50
  Glitch.config.Config.setBaseUrl("https://api.glitch.local/api/", true);
51
51
 
52
52
  //Set Auth JSON Web Token (if user has loggedin)
53
+ //Authenticated application context only, NOT a guest game checkout bundle.
53
54
  Glitch.config.Config.setAuthToken("some-jwt");
54
55
 
55
56
  //Make API Calls
@@ -71,3 +72,12 @@ Use `Glitch.api.Microtransactions` for title-scoped products, existing Media upl
71
72
  game-branded hosted checkout, verified account handoff, inventory and refunds.
72
73
  Read [the integration guide](guides/microtransactions.md) before handling purchases.
73
74
  Never treat a browser message as payment proof or ship an administrative token.
75
+ For guest commerce configure only the API base URL in an isolated credential-free
76
+ SDK context: configured global auth is inherited even on guest entry. Existing
77
+ supported install-purpose runtime tokens remain valid only for their documented
78
+ install/validation/heartbeat/telemetry endpoints, never commerce authentication or
79
+ paid ownership. Do not inject them into guest commerce, remove the game's unrelated
80
+ allowed token, or change global SDK auth as a commerce workaround. SDK3.15.0
81
+ supports the player flow; SDK4 management is separate. The guide documents exact
82
+ hosted HTTPS versus local/testing origins, optional integration evidence, the
83
+ published-version compatibility tests and the SDK 4.0.1 follow-up.
package/dist/cjs/index.js CHANGED
@@ -39851,8 +39851,9 @@ var MicrotransactionsRoute = /** @class */ (function () {
39851
39851
  }());
39852
39852
 
39853
39853
  /**
39854
- * Provider-neutral, title-scoped commerce. Configure with user JWT; purchases
39855
- * use a recoverable user account and limited checkout capability. Install/title
39854
+ * Provider-neutral, title-scoped commerce. Guest games configure only the API
39855
+ * base URL, never global account/admin auth. Hosted account pages use their own
39856
+ * user JWT and limited checkout capability; playerToken overrides auth per request. Install/title
39856
39857
  * tokens cannot authorize money, ownership, refunds, or catalog changes.
39857
39858
  *
39858
39859
  * Each result preserves payment versus fulfillment versus settlement. Redirects
@@ -39940,13 +39941,13 @@ var Microtransactions = /** @class */ (function () {
39940
39941
  if (data === void 0) { data = {}; }
39941
39942
  return this.call('replayDelivery', title_id, data, { delivery_id: delivery_id }, undefined, options);
39942
39943
  };
39943
- /** Public eligible catalog. Sandbox is restricted by backend environment/admin policy. */
39944
+ /** Guest catalog on the exact approved game Origin. Sandbox requires enabled sandbox settings; the backend enforces environment policy. */
39944
39945
  Microtransactions.catalog = function (title_id, params, options) { return this.call('catalog', title_id, undefined, {}, params, options); };
39945
39946
  /** User-authenticated quote. Clients select product/quantity, never monetary values or seller accounts. */
39946
39947
  Microtransactions.createQuote = function (title_id, data, options) { return this.call('createQuote', title_id, data, {}, undefined, options); };
39947
- /** Anonymous-safe opening step only. The hosted UI creates/logs into an account before payment. */
39948
+ /** Guest opening only: browser Origin must equal approved return_origin. Inherits configured global auth; use an isolated credential-free game context. Hosted UI authenticates before payment. */
39948
39949
  Microtransactions.createCheckoutSession = function (title_id, data, options) { return this.call('createCheckoutSession', title_id, data, {}, undefined, options); };
39949
- /** Anonymous-safe inventory recovery. Opens an in-game hosted sign-in overlay, never creates a charge or requires the game's account JWT. */
39950
+ /** Guest entry to hosted recovery, not inventory access. Exact approved Origin/return_origin required. Owning-account bind remains mandatory, including when commerce is off. Never install an account JWT in the game. */
39950
39951
  Microtransactions.createRestoreSession = function (title_id, data, options) { return this.call('createRestoreSession', title_id, data, {}, undefined, options); };
39951
39952
  /** Read the session using its limited capability. Cannot mutate user identity or declare payment. */
39952
39953
  Microtransactions.getCheckoutSession = function (title_id, session_id, options) { return this.call('checkoutSession', title_id, undefined, { session_id: session_id }, undefined, options); };
@@ -40194,6 +40195,8 @@ function openMicrotransactionOverlay(options) {
40194
40195
  if (activeOverlays.has(doc))
40195
40196
  throw new Error('A checkout is already open. Resume or close that same purchase first.');
40196
40197
  var session = options.session;
40198
+ // Older purchase-session creation responses need not include an intent.
40199
+ var restoring = session.intent === 'restore';
40197
40200
  var parsed = new URL(session.hosted_url);
40198
40201
  var path = "/games/".concat(encodeURIComponent(options.titleId), "/checkout/").concat(encodeURIComponent(session.id));
40199
40202
  if (parsed.origin !== options.checkoutOrigin || parsed.pathname !== path || parsed.search || parsed.username || parsed.password ||
@@ -40212,41 +40215,48 @@ function openMicrotransactionOverlay(options) {
40212
40215
  dialog.setAttribute('aria-modal', 'true');
40213
40216
  dialog.setAttribute('aria-labelledby', "".concat(id, "-title"));
40214
40217
  dialog.setAttribute('role', 'dialog');
40215
- dialog.style.cssText = 'position:fixed;inset:16px;margin:auto;padding:0;border:1px solid #cbd5e1;border-radius:16px;width:min(1100px,calc(100vw - 32px));height:min(850px,calc(100dvh - 32px));max-width:none;max-height:none;background:#fff;color:#172033;box-shadow:0 24px 90px #0008;z-index:2147483647;overflow:hidden;';
40218
+ dialog.style.cssText = 'position:fixed;inset:0;margin:auto;padding:0;border:1px solid #cbd5e1;border-radius:16px;box-sizing:border-box;display:flex;flex-direction:column;width:min(1100px,calc(100vw - 32px));height:min(850px,calc(100vh - 32px));min-width:0;min-height:0;max-width:none;max-height:none;background:#fff;color:#172033;box-shadow:0 24px 90px #0008;z-index:2147483647;overflow:hidden;';
40216
40219
  var style = doc.createElement('style');
40217
- style.textContent = "#".concat(id, "::backdrop{background:rgba(8,16,32,.72)}#").concat(id, " button:focus-visible{outline:3px solid #4263eb;outline-offset:3px}@media(max-width:600px){#").concat(id, "{inset:0!important;width:100vw!important;height:100dvh!important;border-radius:0!important}}");
40220
+ style.textContent = "\n #".concat(id, "::backdrop{background:rgba(8,16,32,.72)}\n #").concat(id, " button:focus-visible{outline:3px solid #4263eb;outline-offset:3px}\n @supports(height:100dvh){#").concat(id, "{height:min(850px,calc(100dvh - 32px))!important}}\n @media(max-width:600px),(max-height:500px){\n #").concat(id, "{width:100%!important;height:100vh!important;border:0!important;border-radius:0!important;padding:env(safe-area-inset-top,0px) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px)!important}\n @supports(height:100dvh){#").concat(id, "{height:100dvh!important}}\n }");
40221
+ // Natural-height chrome can wrap/scroll without consuming the entire frame.
40222
+ // No fixed header/status subtraction; the iframe owns all remaining space.
40223
+ var chrome = doc.createElement('div');
40224
+ chrome.style.cssText = 'flex:0 1 auto;min-width:0;min-height:0;max-height:50%;overflow:auto;overscroll-behavior:contain;';
40218
40225
  var header = doc.createElement('div');
40219
- header.style.cssText = 'display:flex;align-items:center;justify-content:space-between;gap:16px;padding:12px 16px;border-bottom:1px solid #e2e8f0;height:56px;box-sizing:border-box;';
40226
+ header.style.cssText = 'display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px 16px;padding:12px 16px;border-bottom:1px solid #e2e8f0;box-sizing:border-box;min-width:0;';
40220
40227
  var heading = doc.createElement('h2');
40221
40228
  heading.id = "".concat(id, "-title");
40222
- heading.textContent = options.label || (session.intent === 'restore' ? 'Restore game purchases' : 'Secure game checkout');
40223
- heading.style.cssText = 'margin:0;font:600 17px/1.3 system-ui,sans-serif;color:#172033;';
40229
+ heading.textContent = options.label || (restoring ? 'Restore game purchases' : 'Secure game checkout');
40230
+ heading.style.cssText = 'flex:1 1 10rem;min-width:0;margin:0;font:600 17px/1.3 system-ui,sans-serif;color:#172033;white-space:normal;overflow-wrap:anywhere;';
40224
40231
  var closeButton = doc.createElement('button');
40225
40232
  closeButton.type = 'button';
40226
40233
  closeButton.textContent = 'Close';
40227
- closeButton.setAttribute('aria-label', 'Close checkout and return to game');
40228
- closeButton.style.cssText = 'border:1px solid #cbd5e1;border-radius:8px;padding:7px 14px;background:#fff;color:#172033;font:600 14px system-ui,sans-serif;cursor:pointer;';
40234
+ closeButton.setAttribute('aria-label', restoring ? 'Close restore and return to game' : 'Close checkout and return to game');
40235
+ closeButton.style.cssText = 'box-sizing:border-box;flex:1 1 auto;min-width:44px;min-height:44px;max-width:100%;height:auto;margin:0;border:1px solid #cbd5e1;border-radius:8px;padding:10px 14px;background:#fff;color:#172033;font:600 14px/1.4 system-ui,sans-serif;white-space:normal;overflow-wrap:anywhere;cursor:pointer;';
40229
40236
  var retryButton = doc.createElement('button');
40230
40237
  retryButton.type = 'button';
40231
40238
  retryButton.textContent = 'Retry';
40232
- retryButton.setAttribute('aria-label', 'Reload this same checkout without starting another purchase');
40239
+ retryButton.setAttribute('aria-label', restoring ? 'Reload this same restore session' : 'Reload this same checkout without starting another purchase');
40233
40240
  retryButton.style.cssText = closeButton.style.cssText;
40241
+ closeButton.style.background = '#172033';
40242
+ closeButton.style.color = '#fff';
40234
40243
  var controls = doc.createElement('div');
40235
- controls.style.cssText = 'display:flex;gap:8px;';
40244
+ controls.style.cssText = 'display:flex;flex-wrap:wrap;gap:8px;min-width:0;max-width:100%;margin-left:auto;';
40236
40245
  controls.append(retryButton, closeButton);
40237
40246
  header.append(heading, controls);
40238
40247
  var status = doc.createElement('div');
40239
40248
  status.setAttribute('role', 'status');
40240
- status.style.cssText = 'padding:6px 16px;font:12px/1.4 system-ui,sans-serif;background:#f1f5f9;color:#172033;min-height:28px;box-sizing:border-box;';
40241
- status.textContent = 'Your game stays open. Loading secure checkout…';
40249
+ status.style.cssText = 'padding:6px 16px;font:12px/1.4 system-ui,sans-serif;background:#f1f5f9;color:#172033;box-sizing:border-box;white-space:normal;overflow-wrap:anywhere;';
40250
+ status.textContent = restoring ? 'Your game stays open. Loading secure restore…' : 'Your game stays open. Loading secure checkout…';
40242
40251
  var iframe = doc.createElement('iframe');
40243
40252
  iframe.title = heading.textContent;
40244
40253
  iframe.setAttribute('allow', 'payment');
40245
40254
  iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox');
40246
40255
  iframe.referrerPolicy = 'no-referrer';
40247
- iframe.style.cssText = 'display:block;width:100%;height:calc(100% - 84px);border:0;background:#fff;';
40256
+ iframe.style.cssText = 'display:block;flex:1 1 0%;min-width:0;min-height:0;width:100%;height:100%;margin:0;padding:0;border:0;background:#fff;';
40248
40257
  iframe.src = session.hosted_url;
40249
- dialog.append(style, header, status, iframe);
40258
+ chrome.append(header, status);
40259
+ dialog.append(style, chrome, iframe);
40250
40260
  doc.body.append(dialog);
40251
40261
  var frameWindow = iframe.contentWindow;
40252
40262
  if (!frameWindow) {
@@ -40260,6 +40270,19 @@ function openMicrotransactionOverlay(options) {
40260
40270
  var frameLoadTimer;
40261
40271
  var appReadyTimer;
40262
40272
  var applicationReady = false;
40273
+ var retryPhase = 'idle';
40274
+ var retryReady = false;
40275
+ var isBlankDocument = function () {
40276
+ var _a;
40277
+ // about:blank inherits our origin. A src attribute alone says nothing about
40278
+ // which document emitted load; an old checkout load can still be queued.
40279
+ try {
40280
+ return ((_a = iframe.contentDocument) === null || _a === void 0 ? void 0 : _a.URL) === 'about:blank' && iframe.contentDocument.readyState === 'complete';
40281
+ }
40282
+ catch (_b) {
40283
+ return false;
40284
+ }
40285
+ };
40263
40286
  var blocked = [];
40264
40287
  var report = function (error) { var _a; try {
40265
40288
  (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
@@ -40277,21 +40300,32 @@ function openMicrotransactionOverlay(options) {
40277
40300
  if (closed)
40278
40301
  return;
40279
40302
  clearWatchdogs();
40303
+ if (retryPhase !== 'idle') {
40304
+ retryPhase = 'failed';
40305
+ retryReady = false;
40306
+ }
40280
40307
  status.setAttribute('role', 'alert');
40308
+ var flow = restoring ? 'Restore' : 'Checkout';
40281
40309
  status.textContent = reason === 'ready'
40282
- ? 'Checkout did not become ready. Retry this same checkout or Close; your game remains open.'
40283
- : 'Checkout could not load here. Retry this same checkout or Close; your game remains open.';
40284
- report(new Error(reason === 'ready'
40285
- ? 'Embedded checkout readiness timed out; no navigation or new payment was attempted.'
40286
- : 'Embedded checkout loading unavailable; no navigation or new payment was attempted.'));
40310
+ ? "".concat(flow, " did not become ready. Retry this same session or Close; your game remains open.")
40311
+ : "".concat(flow, " could not load here. Retry this same session or Close; your game remains open.");
40312
+ report(new Error(restoring
40313
+ ? "Embedded restore ".concat(reason === 'ready' ? 'readiness timed out' : 'loading unavailable', "; no navigation was attempted.")
40314
+ : reason === 'ready'
40315
+ ? 'Embedded checkout readiness timed out; no navigation or new payment was attempted.'
40316
+ : 'Embedded checkout loading unavailable; no navigation or new payment was attempted.'));
40287
40317
  };
40288
40318
  var markApplicationReady = function () {
40289
40319
  if (closed)
40290
40320
  return;
40321
+ // A verified claim from the previous document may finish while Retry is
40322
+ // navigating. Keep that claim, but it cannot certify the new document UI.
40323
+ if (retryPhase !== 'idle')
40324
+ return;
40291
40325
  applicationReady = true;
40292
40326
  clearWatchdogs();
40293
40327
  status.setAttribute('role', 'status');
40294
- status.textContent = 'Checkout is ready. Your game remains open underneath.';
40328
+ status.textContent = restoring ? 'Restore is ready. Your game remains open underneath.' : 'Checkout is ready. Your game remains open underneath.';
40295
40329
  };
40296
40330
  var armLoadWatchdog = function () {
40297
40331
  clearWatchdogs();
@@ -40393,7 +40427,8 @@ function openMicrotransactionOverlay(options) {
40393
40427
  event.preventDefault();
40394
40428
  void overlay.close();
40395
40429
  }
40396
- if (event.key === 'Tab' && !closed) {
40430
+ // Keep the trap while close waits for an in-flight claim/inventory callback.
40431
+ if (event.key === 'Tab' && dialog.isConnected) {
40397
40432
  if (event.shiftKey && doc.activeElement === retryButton) {
40398
40433
  event.preventDefault();
40399
40434
  iframe.focus();
@@ -40405,6 +40440,8 @@ function openMicrotransactionOverlay(options) {
40405
40440
  }
40406
40441
  };
40407
40442
  var onCancel = function (event) { event.preventDefault(); void overlay.close(); };
40443
+ // Keyboard events inside the cross-origin document do not reach onKey.
40444
+ // The hosted UI forwards Escape via this existing, strictly bound close message.
40408
40445
  var onCloseMessage = function (event) {
40409
40446
  if (closed || event.origin !== options.checkoutOrigin || event.source !== frameWindow || !event.data || typeof event.data !== 'object')
40410
40447
  return;
@@ -40413,24 +40450,53 @@ function openMicrotransactionOverlay(options) {
40413
40450
  message.checkout_session_id !== session.id || message.nonce !== session.nonce)
40414
40451
  return;
40415
40452
  if (message.type === 'glitch.microtransaction.ready') {
40416
- markApplicationReady();
40453
+ if (retryPhase === 'checkout' && !isBlankDocument())
40454
+ retryReady = true;
40455
+ else if (retryPhase === 'idle')
40456
+ markApplicationReady();
40417
40457
  return;
40418
40458
  }
40419
40459
  if (message.type !== 'glitch.microtransaction.close')
40420
40460
  return;
40421
40461
  void overlay.close(verified ? 'completed' : 'dismissed');
40422
40462
  };
40423
- var onFrameError = function () { unavailable('error'); };
40463
+ var onFrameError = function () {
40464
+ // Events from the document being left cannot fail the blank navigation.
40465
+ // Its watchdog still bounds a missing/failed intermediate load.
40466
+ if (retryPhase === 'blank' || (retryPhase === 'checkout' && isBlankDocument()))
40467
+ return;
40468
+ unavailable('error');
40469
+ };
40424
40470
  var onFrameLoad = function () {
40425
40471
  if (closed)
40426
40472
  return;
40473
+ if (retryPhase === 'failed')
40474
+ return;
40475
+ if (retryPhase === 'blank') {
40476
+ if (!isBlankDocument())
40477
+ return;
40478
+ retryPhase = 'checkout';
40479
+ armLoadWatchdog();
40480
+ iframe.src = session.hosted_url;
40481
+ return;
40482
+ }
40483
+ if (retryPhase === 'checkout') {
40484
+ if (isBlankDocument())
40485
+ return;
40486
+ retryPhase = 'idle';
40487
+ if (retryReady) {
40488
+ retryReady = false;
40489
+ markApplicationReady();
40490
+ return;
40491
+ }
40492
+ }
40427
40493
  if (frameLoadTimer !== undefined)
40428
40494
  win.clearTimeout(frameLoadTimer);
40429
40495
  frameLoadTimer = undefined;
40430
40496
  if (applicationReady)
40431
40497
  return;
40432
40498
  status.setAttribute('role', 'status');
40433
- status.textContent = 'Checkout document loaded. Waiting for the secure checkout interface…';
40499
+ status.textContent = restoring ? 'Restore document loaded. Waiting for the secure restore interface…' : 'Checkout document loaded. Waiting for the secure checkout interface…';
40434
40500
  // A document load is not proof the app rendered. Repeated loads cannot
40435
40501
  // indefinitely extend this bounded wait; only explicit Retry resets it.
40436
40502
  if (appReadyTimer === undefined)
@@ -40441,12 +40507,18 @@ function openMicrotransactionOverlay(options) {
40441
40507
  iframe: iframe,
40442
40508
  refresh: refresh,
40443
40509
  retry: function () {
40444
- if (closed)
40510
+ if (closed || retryPhase === 'blank' || retryPhase === 'checkout')
40445
40511
  return;
40446
- status.textContent = 'Retrying the same secure checkout. Your game stays open.';
40512
+ status.textContent = restoring ? 'Retrying the same secure restore session. Your game stays open.' : 'Retrying the same secure checkout. Your game stays open.';
40447
40513
  status.setAttribute('role', 'status');
40514
+ retryPhase = 'blank';
40515
+ retryReady = false;
40448
40516
  armLoadWatchdog();
40449
- iframe.src = session.hosted_url;
40517
+ // Bootstrap removes #token with replaceState. Reassigning the original
40518
+ // URL then only changes the fragment; it does not reload checkout/API.
40519
+ // Commit a harmless blank document first, then navigate this SAME iframe
40520
+ // to the exact original capability URL. Its WindowProxy/bridge stay pinned.
40521
+ iframe.src = 'about:blank';
40450
40522
  },
40451
40523
  close: function (reason) {
40452
40524
  if (reason === void 0) { reason = 'dismissed'; }
@@ -40456,7 +40528,10 @@ function openMicrotransactionOverlay(options) {
40456
40528
  return Promise.resolve();
40457
40529
  closed = true;
40458
40530
  clearWatchdogs();
40459
- status.textContent = 'Finishing secure purchase verification. Your game stays open.';
40531
+ retryPhase = 'failed';
40532
+ retryReady = false;
40533
+ status.setAttribute('role', 'status');
40534
+ status.textContent = restoring ? 'Finishing secure restore verification. Your game stays open.' : 'Finishing secure purchase verification. Your game stays open.';
40460
40535
  closing = (function () { return __awaiter$1(_this, void 0, void 0, function () {
40461
40536
  var error_1, error_2, _i, blocked_1, item, error_3;
40462
40537
  var _a;