glitch-javascript-sdk 4.0.0 → 4.1.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 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
@@ -17324,14 +17324,19 @@ function requireNode () {
17324
17324
  * treat as a browser.
17325
17325
  */
17326
17326
 
17327
- if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
17328
- src$1.exports = requireBrowser();
17329
- } else {
17330
- src$1.exports = requireNode();
17327
+ var hasRequiredSrc;
17328
+
17329
+ function requireSrc () {
17330
+ if (hasRequiredSrc) return src$1.exports;
17331
+ hasRequiredSrc = 1;
17332
+ if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
17333
+ src$1.exports = requireBrowser();
17334
+ } else {
17335
+ src$1.exports = requireNode();
17336
+ }
17337
+ return src$1.exports;
17331
17338
  }
17332
17339
 
17333
- var srcExports = src$1.exports;
17334
-
17335
17340
  var promisify$1 = {};
17336
17341
 
17337
17342
  Object.defineProperty(promisify$1, "__esModule", { value: true });
@@ -17355,7 +17360,7 @@ var __importDefault$3 = (commonjsGlobal && commonjsGlobal.__importDefault) || fu
17355
17360
  return (mod && mod.__esModule) ? mod : { "default": mod };
17356
17361
  };
17357
17362
  const events_1 = require$$0$3;
17358
- const debug_1$3 = __importDefault$3(srcExports);
17363
+ const debug_1$3 = __importDefault$3(requireSrc());
17359
17364
  const promisify_1 = __importDefault$3(promisify$1);
17360
17365
  const debug$4 = debug_1$3.default('agent-base');
17361
17366
  function isAgent(v) {
@@ -17559,7 +17564,7 @@ var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || fu
17559
17564
  return (mod && mod.__esModule) ? mod : { "default": mod };
17560
17565
  };
17561
17566
  Object.defineProperty(parseProxyResponse$1, "__esModule", { value: true });
17562
- const debug_1$2 = __importDefault$2(srcExports);
17567
+ const debug_1$2 = __importDefault$2(requireSrc());
17563
17568
  const debug$3 = debug_1$2.default('https-proxy-agent:parse-proxy-response');
17564
17569
  function parseProxyResponse(socket) {
17565
17570
  return new Promise((resolve, reject) => {
@@ -17637,7 +17642,7 @@ const net_1 = __importDefault$1(require$$0$4);
17637
17642
  const tls_1 = __importDefault$1(require$$1$2);
17638
17643
  const url_1 = __importDefault$1(require$$5);
17639
17644
  const assert_1 = __importDefault$1(require$$3);
17640
- const debug_1$1 = __importDefault$1(srcExports);
17645
+ const debug_1$1 = __importDefault$1(requireSrc());
17641
17646
  const agent_base_1 = src;
17642
17647
  const parse_proxy_response_1 = __importDefault$1(parseProxyResponse$1);
17643
17648
  const debug$2 = debug_1$1.default('https-proxy-agent:agent');
@@ -17820,7 +17825,7 @@ var debug_1 = function () {
17820
17825
  if (!debug$1) {
17821
17826
  try {
17822
17827
  /* eslint global-require: off */
17823
- debug$1 = srcExports("follow-redirects");
17828
+ debug$1 = requireSrc()("follow-redirects");
17824
17829
  }
17825
17830
  catch (error) { /* */ }
17826
17831
  if (typeof debug$1 !== "function") {
@@ -39851,8 +39856,9 @@ var MicrotransactionsRoute = /** @class */ (function () {
39851
39856
  }());
39852
39857
 
39853
39858
  /**
39854
- * Provider-neutral, title-scoped commerce. Configure with user JWT; purchases
39855
- * use a recoverable user account and limited checkout capability. Install/title
39859
+ * Provider-neutral, title-scoped commerce. Guest games configure only the API
39860
+ * base URL, never global account/admin auth. Hosted account pages use their own
39861
+ * user JWT and limited checkout capability; playerToken overrides auth per request. Install/title
39856
39862
  * tokens cannot authorize money, ownership, refunds, or catalog changes.
39857
39863
  *
39858
39864
  * Each result preserves payment versus fulfillment versus settlement. Redirects
@@ -39940,13 +39946,13 @@ var Microtransactions = /** @class */ (function () {
39940
39946
  if (data === void 0) { data = {}; }
39941
39947
  return this.call('replayDelivery', title_id, data, { delivery_id: delivery_id }, undefined, options);
39942
39948
  };
39943
- /** Public eligible catalog. Sandbox is restricted by backend environment/admin policy. */
39949
+ /** Guest catalog on the exact approved game Origin. Sandbox requires enabled sandbox settings; the backend enforces environment policy. */
39944
39950
  Microtransactions.catalog = function (title_id, params, options) { return this.call('catalog', title_id, undefined, {}, params, options); };
39945
39951
  /** User-authenticated quote. Clients select product/quantity, never monetary values or seller accounts. */
39946
39952
  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. */
39953
+ /** 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
39954
  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. */
39955
+ /** 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
39956
  Microtransactions.createRestoreSession = function (title_id, data, options) { return this.call('createRestoreSession', title_id, data, {}, undefined, options); };
39951
39957
  /** Read the session using its limited capability. Cannot mutate user identity or declare payment. */
39952
39958
  Microtransactions.getCheckoutSession = function (title_id, session_id, options) { return this.call('checkoutSession', title_id, undefined, { session_id: session_id }, undefined, options); };
@@ -40038,6 +40044,119 @@ var Microtransactions = /** @class */ (function () {
40038
40044
  return Microtransactions;
40039
40045
  }());
40040
40046
 
40047
+ var PreordersRoute = /** @class */ (function () {
40048
+ function PreordersRoute() {
40049
+ }
40050
+ PreordersRoute.routes = {
40051
+ catalog: { url: '/titles/{title_id}/preorders', method: HTTP_METHODS.GET },
40052
+ purchase: { url: '/titles/{title_id}/preorders/{offer_id}/purchase', method: HTTP_METHODS.POST },
40053
+ myOrders: { url: '/titles/{title_id}/preorders/me/orders', method: HTTP_METHODS.GET },
40054
+ order: { url: '/titles/{title_id}/preorders/orders/{order_id}', method: HTTP_METHODS.GET },
40055
+ refundMine: { url: '/titles/{title_id}/preorders/orders/{order_id}/refund', method: HTTP_METHODS.POST },
40056
+ resendMine: { url: '/titles/{title_id}/preorders/orders/{order_id}/resend-access', method: HTTP_METHODS.POST },
40057
+ settings: { url: '/titles/{title_id}/preorders/settings', method: HTTP_METHODS.GET },
40058
+ updateSettings: { url: '/titles/{title_id}/preorders/settings', method: HTTP_METHODS.PUT },
40059
+ offers: { url: '/titles/{title_id}/preorders/admin/offers', method: HTTP_METHODS.GET },
40060
+ createOffer: { url: '/titles/{title_id}/preorders/admin/offers', method: HTTP_METHODS.POST },
40061
+ offer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}', method: HTTP_METHODS.GET },
40062
+ updateOffer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}', method: HTTP_METHODS.PUT },
40063
+ activateOffer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/activate', method: HTTP_METHODS.POST },
40064
+ pauseOffer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/pause', method: HTTP_METHODS.POST },
40065
+ archiveOffer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/archive', method: HTTP_METHODS.POST },
40066
+ inventory: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/keys', method: HTTP_METHODS.GET },
40067
+ importKeys: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/keys/import', method: HTTP_METHODS.POST },
40068
+ retireKey: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/keys/{key_id}/retire', method: HTTP_METHODS.POST },
40069
+ adminOrders: { url: '/titles/{title_id}/preorders/admin/orders', method: HTTP_METHODS.GET },
40070
+ readiness: { url: '/titles/{title_id}/preorders/admin/readiness', method: HTTP_METHODS.GET },
40071
+ adminOrderAction: { url: '/titles/{title_id}/preorders/admin/orders/{order_id}/{action}', method: HTTP_METHODS.POST },
40072
+ mcpCapabilities: { url: '/mcp/v1/titles/{title_id}/preorders/capabilities', method: HTTP_METHODS.GET },
40073
+ mcpOperation: { url: '/mcp/v1/titles/{title_id}/preorders/operations/{operation}', method: HTTP_METHODS.POST },
40074
+ };
40075
+ return PreordersRoute;
40076
+ }());
40077
+
40078
+ var Preorders = /** @class */ (function () {
40079
+ function Preorders() {
40080
+ }
40081
+ Preorders.catalog = function (title_id, options) {
40082
+ return Requests.processRoute(PreordersRoute.routes.catalog, undefined, { title_id: title_id }, undefined, options);
40083
+ };
40084
+ Preorders.purchase = function (title_id, offer_id, data, options) {
40085
+ return Requests.processRoute(PreordersRoute.routes.purchase, data, { title_id: title_id, offer_id: offer_id }, undefined, options);
40086
+ };
40087
+ Preorders.myOrders = function (title_id, options) {
40088
+ return Requests.processRoute(PreordersRoute.routes.myOrders, undefined, { title_id: title_id }, undefined, options);
40089
+ };
40090
+ Preorders.order = function (title_id, order_id, options) {
40091
+ return Requests.processRoute(PreordersRoute.routes.order, undefined, { title_id: title_id, order_id: order_id }, undefined, options);
40092
+ };
40093
+ Preorders.refundMine = function (title_id, order_id, options) {
40094
+ return Requests.processRoute(PreordersRoute.routes.refundMine, {}, { title_id: title_id, order_id: order_id }, undefined, options);
40095
+ };
40096
+ Preorders.resendMine = function (title_id, order_id, options) {
40097
+ return Requests.processRoute(PreordersRoute.routes.resendMine, {}, { title_id: title_id, order_id: order_id }, undefined, options);
40098
+ };
40099
+ Preorders.settings = function (title_id, options) {
40100
+ return Requests.processRoute(PreordersRoute.routes.settings, undefined, { title_id: title_id }, undefined, options);
40101
+ };
40102
+ Preorders.updateSettings = function (title_id, data, options) {
40103
+ return Requests.processRoute(PreordersRoute.routes.updateSettings, data, { title_id: title_id }, undefined, options);
40104
+ };
40105
+ Preorders.offers = function (title_id, options) {
40106
+ return Requests.processRoute(PreordersRoute.routes.offers, undefined, { title_id: title_id }, undefined, options);
40107
+ };
40108
+ Preorders.offer = function (title_id, offer_id, options) {
40109
+ return Requests.processRoute(PreordersRoute.routes.offer, undefined, { title_id: title_id, offer_id: offer_id }, undefined, options);
40110
+ };
40111
+ Preorders.createOffer = function (title_id, data, options) {
40112
+ return Requests.processRoute(PreordersRoute.routes.createOffer, data, { title_id: title_id }, undefined, options);
40113
+ };
40114
+ Preorders.updateOffer = function (title_id, offer_id, data, options) {
40115
+ return Requests.processRoute(PreordersRoute.routes.updateOffer, data, { title_id: title_id, offer_id: offer_id }, undefined, options);
40116
+ };
40117
+ Preorders.activateOffer = function (title_id, offer_id, options) {
40118
+ return Requests.processRoute(PreordersRoute.routes.activateOffer, {}, { title_id: title_id, offer_id: offer_id }, undefined, options);
40119
+ };
40120
+ Preorders.pauseOffer = function (title_id, offer_id, options) {
40121
+ return Requests.processRoute(PreordersRoute.routes.pauseOffer, {}, { title_id: title_id, offer_id: offer_id }, undefined, options);
40122
+ };
40123
+ Preorders.archiveOffer = function (title_id, offer_id, options) {
40124
+ return Requests.processRoute(PreordersRoute.routes.archiveOffer, {}, { title_id: title_id, offer_id: offer_id }, undefined, options);
40125
+ };
40126
+ Preorders.inventory = function (title_id, offer_id, options) {
40127
+ return Requests.processRoute(PreordersRoute.routes.inventory, undefined, { title_id: title_id, offer_id: offer_id }, undefined, options);
40128
+ };
40129
+ Preorders.importKeys = function (title_id, offer_id, keys, options) {
40130
+ return Requests.processRoute(PreordersRoute.routes.importKeys, { keys: keys }, { title_id: title_id, offer_id: offer_id }, undefined, options);
40131
+ };
40132
+ Preorders.importKeyFile = function (title_id, offer_id, file) {
40133
+ var url = PreordersRoute.routes.importKeys.url
40134
+ .replace('{title_id}', title_id)
40135
+ .replace('{offer_id}', offer_id);
40136
+ return Requests.uploadFile(url, 'key_file', file, {}, undefined, undefined, { excludeCommunityContext: true });
40137
+ };
40138
+ Preorders.retireKey = function (title_id, offer_id, key_id, reason, options) {
40139
+ return Requests.processRoute(PreordersRoute.routes.retireKey, { reason: reason }, { title_id: title_id, offer_id: offer_id, key_id: key_id }, undefined, options);
40140
+ };
40141
+ Preorders.adminOrders = function (title_id, filters, options) {
40142
+ return Requests.processRoute(PreordersRoute.routes.adminOrders, undefined, { title_id: title_id }, filters, options);
40143
+ };
40144
+ Preorders.readiness = function (title_id, options) {
40145
+ return Requests.processRoute(PreordersRoute.routes.readiness, undefined, { title_id: title_id }, undefined, options);
40146
+ };
40147
+ Preorders.adminOrderAction = function (title_id, order_id, action, options) {
40148
+ return Requests.processRoute(PreordersRoute.routes.adminOrderAction, {}, { title_id: title_id, order_id: order_id, action: action }, undefined, options);
40149
+ };
40150
+ Preorders.mcpCapabilities = function (title_id, options) {
40151
+ return Requests.processRoute(PreordersRoute.routes.mcpCapabilities, undefined, { title_id: title_id }, undefined, options);
40152
+ };
40153
+ Preorders.mcpOperation = function (title_id, operation, argumentsData, options) {
40154
+ if (argumentsData === void 0) { argumentsData = {}; }
40155
+ return Requests.processRoute(PreordersRoute.routes.mcpOperation, { arguments: argumentsData }, { title_id: title_id, operation: operation }, undefined, options);
40156
+ };
40157
+ return Preorders;
40158
+ }());
40159
+
40041
40160
  /** Generate a 256-bit browser nonce. Fails closed without secure Web Crypto. */
40042
40161
  function createMicrotransactionNonce() {
40043
40162
  var _a;
@@ -40194,6 +40313,8 @@ function openMicrotransactionOverlay(options) {
40194
40313
  if (activeOverlays.has(doc))
40195
40314
  throw new Error('A checkout is already open. Resume or close that same purchase first.');
40196
40315
  var session = options.session;
40316
+ // Older purchase-session creation responses need not include an intent.
40317
+ var restoring = session.intent === 'restore';
40197
40318
  var parsed = new URL(session.hosted_url);
40198
40319
  var path = "/games/".concat(encodeURIComponent(options.titleId), "/checkout/").concat(encodeURIComponent(session.id));
40199
40320
  if (parsed.origin !== options.checkoutOrigin || parsed.pathname !== path || parsed.search || parsed.username || parsed.password ||
@@ -40212,41 +40333,48 @@ function openMicrotransactionOverlay(options) {
40212
40333
  dialog.setAttribute('aria-modal', 'true');
40213
40334
  dialog.setAttribute('aria-labelledby', "".concat(id, "-title"));
40214
40335
  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;';
40336
+ 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
40337
  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}}");
40338
+ 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 }");
40339
+ // Natural-height chrome can wrap/scroll without consuming the entire frame.
40340
+ // No fixed header/status subtraction; the iframe owns all remaining space.
40341
+ var chrome = doc.createElement('div');
40342
+ chrome.style.cssText = 'flex:0 1 auto;min-width:0;min-height:0;max-height:50%;overflow:auto;overscroll-behavior:contain;';
40218
40343
  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;';
40344
+ 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
40345
  var heading = doc.createElement('h2');
40221
40346
  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;';
40347
+ heading.textContent = options.label || (restoring ? 'Restore game purchases' : 'Secure game checkout');
40348
+ 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
40349
  var closeButton = doc.createElement('button');
40225
40350
  closeButton.type = 'button';
40226
40351
  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;';
40352
+ closeButton.setAttribute('aria-label', restoring ? 'Close restore and return to game' : 'Close checkout and return to game');
40353
+ 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
40354
  var retryButton = doc.createElement('button');
40230
40355
  retryButton.type = 'button';
40231
40356
  retryButton.textContent = 'Retry';
40232
- retryButton.setAttribute('aria-label', 'Reload this same checkout without starting another purchase');
40357
+ retryButton.setAttribute('aria-label', restoring ? 'Reload this same restore session' : 'Reload this same checkout without starting another purchase');
40233
40358
  retryButton.style.cssText = closeButton.style.cssText;
40359
+ closeButton.style.background = '#172033';
40360
+ closeButton.style.color = '#fff';
40234
40361
  var controls = doc.createElement('div');
40235
- controls.style.cssText = 'display:flex;gap:8px;';
40362
+ controls.style.cssText = 'display:flex;flex-wrap:wrap;gap:8px;min-width:0;max-width:100%;margin-left:auto;';
40236
40363
  controls.append(retryButton, closeButton);
40237
40364
  header.append(heading, controls);
40238
40365
  var status = doc.createElement('div');
40239
40366
  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…';
40367
+ 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;';
40368
+ status.textContent = restoring ? 'Your game stays open. Loading secure restore…' : 'Your game stays open. Loading secure checkout…';
40242
40369
  var iframe = doc.createElement('iframe');
40243
40370
  iframe.title = heading.textContent;
40244
40371
  iframe.setAttribute('allow', 'payment');
40245
40372
  iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox');
40246
40373
  iframe.referrerPolicy = 'no-referrer';
40247
- iframe.style.cssText = 'display:block;width:100%;height:calc(100% - 84px);border:0;background:#fff;';
40374
+ 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
40375
  iframe.src = session.hosted_url;
40249
- dialog.append(style, header, status, iframe);
40376
+ chrome.append(header, status);
40377
+ dialog.append(style, chrome, iframe);
40250
40378
  doc.body.append(dialog);
40251
40379
  var frameWindow = iframe.contentWindow;
40252
40380
  if (!frameWindow) {
@@ -40260,6 +40388,19 @@ function openMicrotransactionOverlay(options) {
40260
40388
  var frameLoadTimer;
40261
40389
  var appReadyTimer;
40262
40390
  var applicationReady = false;
40391
+ var retryPhase = 'idle';
40392
+ var retryReady = false;
40393
+ var isBlankDocument = function () {
40394
+ var _a;
40395
+ // about:blank inherits our origin. A src attribute alone says nothing about
40396
+ // which document emitted load; an old checkout load can still be queued.
40397
+ try {
40398
+ return ((_a = iframe.contentDocument) === null || _a === void 0 ? void 0 : _a.URL) === 'about:blank' && iframe.contentDocument.readyState === 'complete';
40399
+ }
40400
+ catch (_b) {
40401
+ return false;
40402
+ }
40403
+ };
40263
40404
  var blocked = [];
40264
40405
  var report = function (error) { var _a; try {
40265
40406
  (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
@@ -40277,21 +40418,32 @@ function openMicrotransactionOverlay(options) {
40277
40418
  if (closed)
40278
40419
  return;
40279
40420
  clearWatchdogs();
40421
+ if (retryPhase !== 'idle') {
40422
+ retryPhase = 'failed';
40423
+ retryReady = false;
40424
+ }
40280
40425
  status.setAttribute('role', 'alert');
40426
+ var flow = restoring ? 'Restore' : 'Checkout';
40281
40427
  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.'));
40428
+ ? "".concat(flow, " did not become ready. Retry this same session or Close; your game remains open.")
40429
+ : "".concat(flow, " could not load here. Retry this same session or Close; your game remains open.");
40430
+ report(new Error(restoring
40431
+ ? "Embedded restore ".concat(reason === 'ready' ? 'readiness timed out' : 'loading unavailable', "; no navigation was attempted.")
40432
+ : reason === 'ready'
40433
+ ? 'Embedded checkout readiness timed out; no navigation or new payment was attempted.'
40434
+ : 'Embedded checkout loading unavailable; no navigation or new payment was attempted.'));
40287
40435
  };
40288
40436
  var markApplicationReady = function () {
40289
40437
  if (closed)
40290
40438
  return;
40439
+ // A verified claim from the previous document may finish while Retry is
40440
+ // navigating. Keep that claim, but it cannot certify the new document UI.
40441
+ if (retryPhase !== 'idle')
40442
+ return;
40291
40443
  applicationReady = true;
40292
40444
  clearWatchdogs();
40293
40445
  status.setAttribute('role', 'status');
40294
- status.textContent = 'Checkout is ready. Your game remains open underneath.';
40446
+ status.textContent = restoring ? 'Restore is ready. Your game remains open underneath.' : 'Checkout is ready. Your game remains open underneath.';
40295
40447
  };
40296
40448
  var armLoadWatchdog = function () {
40297
40449
  clearWatchdogs();
@@ -40393,7 +40545,8 @@ function openMicrotransactionOverlay(options) {
40393
40545
  event.preventDefault();
40394
40546
  void overlay.close();
40395
40547
  }
40396
- if (event.key === 'Tab' && !closed) {
40548
+ // Keep the trap while close waits for an in-flight claim/inventory callback.
40549
+ if (event.key === 'Tab' && dialog.isConnected) {
40397
40550
  if (event.shiftKey && doc.activeElement === retryButton) {
40398
40551
  event.preventDefault();
40399
40552
  iframe.focus();
@@ -40405,6 +40558,8 @@ function openMicrotransactionOverlay(options) {
40405
40558
  }
40406
40559
  };
40407
40560
  var onCancel = function (event) { event.preventDefault(); void overlay.close(); };
40561
+ // Keyboard events inside the cross-origin document do not reach onKey.
40562
+ // The hosted UI forwards Escape via this existing, strictly bound close message.
40408
40563
  var onCloseMessage = function (event) {
40409
40564
  if (closed || event.origin !== options.checkoutOrigin || event.source !== frameWindow || !event.data || typeof event.data !== 'object')
40410
40565
  return;
@@ -40413,24 +40568,53 @@ function openMicrotransactionOverlay(options) {
40413
40568
  message.checkout_session_id !== session.id || message.nonce !== session.nonce)
40414
40569
  return;
40415
40570
  if (message.type === 'glitch.microtransaction.ready') {
40416
- markApplicationReady();
40571
+ if (retryPhase === 'checkout' && !isBlankDocument())
40572
+ retryReady = true;
40573
+ else if (retryPhase === 'idle')
40574
+ markApplicationReady();
40417
40575
  return;
40418
40576
  }
40419
40577
  if (message.type !== 'glitch.microtransaction.close')
40420
40578
  return;
40421
40579
  void overlay.close(verified ? 'completed' : 'dismissed');
40422
40580
  };
40423
- var onFrameError = function () { unavailable('error'); };
40581
+ var onFrameError = function () {
40582
+ // Events from the document being left cannot fail the blank navigation.
40583
+ // Its watchdog still bounds a missing/failed intermediate load.
40584
+ if (retryPhase === 'blank' || (retryPhase === 'checkout' && isBlankDocument()))
40585
+ return;
40586
+ unavailable('error');
40587
+ };
40424
40588
  var onFrameLoad = function () {
40425
40589
  if (closed)
40426
40590
  return;
40591
+ if (retryPhase === 'failed')
40592
+ return;
40593
+ if (retryPhase === 'blank') {
40594
+ if (!isBlankDocument())
40595
+ return;
40596
+ retryPhase = 'checkout';
40597
+ armLoadWatchdog();
40598
+ iframe.src = session.hosted_url;
40599
+ return;
40600
+ }
40601
+ if (retryPhase === 'checkout') {
40602
+ if (isBlankDocument())
40603
+ return;
40604
+ retryPhase = 'idle';
40605
+ if (retryReady) {
40606
+ retryReady = false;
40607
+ markApplicationReady();
40608
+ return;
40609
+ }
40610
+ }
40427
40611
  if (frameLoadTimer !== undefined)
40428
40612
  win.clearTimeout(frameLoadTimer);
40429
40613
  frameLoadTimer = undefined;
40430
40614
  if (applicationReady)
40431
40615
  return;
40432
40616
  status.setAttribute('role', 'status');
40433
- status.textContent = 'Checkout document loaded. Waiting for the secure checkout interface…';
40617
+ status.textContent = restoring ? 'Restore document loaded. Waiting for the secure restore interface…' : 'Checkout document loaded. Waiting for the secure checkout interface…';
40434
40618
  // A document load is not proof the app rendered. Repeated loads cannot
40435
40619
  // indefinitely extend this bounded wait; only explicit Retry resets it.
40436
40620
  if (appReadyTimer === undefined)
@@ -40441,12 +40625,18 @@ function openMicrotransactionOverlay(options) {
40441
40625
  iframe: iframe,
40442
40626
  refresh: refresh,
40443
40627
  retry: function () {
40444
- if (closed)
40628
+ if (closed || retryPhase === 'blank' || retryPhase === 'checkout')
40445
40629
  return;
40446
- status.textContent = 'Retrying the same secure checkout. Your game stays open.';
40630
+ status.textContent = restoring ? 'Retrying the same secure restore session. Your game stays open.' : 'Retrying the same secure checkout. Your game stays open.';
40447
40631
  status.setAttribute('role', 'status');
40632
+ retryPhase = 'blank';
40633
+ retryReady = false;
40448
40634
  armLoadWatchdog();
40449
- iframe.src = session.hosted_url;
40635
+ // Bootstrap removes #token with replaceState. Reassigning the original
40636
+ // URL then only changes the fragment; it does not reload checkout/API.
40637
+ // Commit a harmless blank document first, then navigate this SAME iframe
40638
+ // to the exact original capability URL. Its WindowProxy/bridge stay pinned.
40639
+ iframe.src = 'about:blank';
40450
40640
  },
40451
40641
  close: function (reason) {
40452
40642
  if (reason === void 0) { reason = 'dismissed'; }
@@ -40456,7 +40646,10 @@ function openMicrotransactionOverlay(options) {
40456
40646
  return Promise.resolve();
40457
40647
  closed = true;
40458
40648
  clearWatchdogs();
40459
- status.textContent = 'Finishing secure purchase verification. Your game stays open.';
40649
+ retryPhase = 'failed';
40650
+ retryReady = false;
40651
+ status.setAttribute('role', 'status');
40652
+ status.textContent = restoring ? 'Finishing secure restore verification. Your game stays open.' : 'Finishing secure purchase verification. Your game stays open.';
40460
40653
  closing = (function () { return __awaiter$1(_this, void 0, void 0, function () {
40461
40654
  var error_1, error_2, _i, blocked_1, item, error_3;
40462
40655
  var _a;
@@ -48557,6 +48750,7 @@ var Glitch = /** @class */ (function () {
48557
48750
  Hosting: Hosting,
48558
48751
  GameDesign: GameDesign,
48559
48752
  Microtransactions: Microtransactions,
48753
+ Preorders: Preorders,
48560
48754
  };
48561
48755
  Glitch.util = {
48562
48756
  Requests: Requests,