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/dist/esm/index.js CHANGED
@@ -21752,8 +21752,9 @@ MicrotransactionsRoute.routes = {
21752
21752
  };
21753
21753
 
21754
21754
  /**
21755
- * Provider-neutral, title-scoped commerce. Configure with user JWT; purchases
21756
- * use a recoverable user account and limited checkout capability. Install/title
21755
+ * Provider-neutral, title-scoped commerce. Guest games configure only the API
21756
+ * base URL, never global account/admin auth. Hosted account pages use their own
21757
+ * user JWT and limited checkout capability; playerToken overrides auth per request. Install/title
21757
21758
  * tokens cannot authorize money, ownership, refunds, or catalog changes.
21758
21759
  *
21759
21760
  * Each result preserves payment versus fulfillment versus settlement. Redirects
@@ -21833,13 +21834,13 @@ class Microtransactions {
21833
21834
  }
21834
21835
  /** Replay the same immutable event. Receiver must deduplicate event_id. This cannot mint goods. */
21835
21836
  static replayDelivery(title_id, delivery_id, data = {}, options) { return this.call('replayDelivery', title_id, data, { delivery_id }, undefined, options); }
21836
- /** Public eligible catalog. Sandbox is restricted by backend environment/admin policy. */
21837
+ /** Guest catalog on the exact approved game Origin. Sandbox requires enabled sandbox settings; the backend enforces environment policy. */
21837
21838
  static catalog(title_id, params, options) { return this.call('catalog', title_id, undefined, {}, params, options); }
21838
21839
  /** User-authenticated quote. Clients select product/quantity, never monetary values or seller accounts. */
21839
21840
  static createQuote(title_id, data, options) { return this.call('createQuote', title_id, data, {}, undefined, options); }
21840
- /** Anonymous-safe opening step only. The hosted UI creates/logs into an account before payment. */
21841
+ /** 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. */
21841
21842
  static createCheckoutSession(title_id, data, options) { return this.call('createCheckoutSession', title_id, data, {}, undefined, options); }
21842
- /** Anonymous-safe inventory recovery. Opens an in-game hosted sign-in overlay, never creates a charge or requires the game's account JWT. */
21843
+ /** 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. */
21843
21844
  static createRestoreSession(title_id, data, options) { return this.call('createRestoreSession', title_id, data, {}, undefined, options); }
21844
21845
  /** Read the session using its limited capability. Cannot mutate user identity or declare payment. */
21845
21846
  static getCheckoutSession(title_id, session_id, options) { return this.call('checkoutSession', title_id, undefined, { session_id }, undefined, options); }
@@ -21926,6 +21927,112 @@ class Microtransactions {
21926
21927
  }
21927
21928
  }
21928
21929
 
21930
+ class PreordersRoute {
21931
+ }
21932
+ PreordersRoute.routes = {
21933
+ catalog: { url: '/titles/{title_id}/preorders', method: HTTP_METHODS.GET },
21934
+ purchase: { url: '/titles/{title_id}/preorders/{offer_id}/purchase', method: HTTP_METHODS.POST },
21935
+ myOrders: { url: '/titles/{title_id}/preorders/me/orders', method: HTTP_METHODS.GET },
21936
+ order: { url: '/titles/{title_id}/preorders/orders/{order_id}', method: HTTP_METHODS.GET },
21937
+ refundMine: { url: '/titles/{title_id}/preorders/orders/{order_id}/refund', method: HTTP_METHODS.POST },
21938
+ resendMine: { url: '/titles/{title_id}/preorders/orders/{order_id}/resend-access', method: HTTP_METHODS.POST },
21939
+ settings: { url: '/titles/{title_id}/preorders/settings', method: HTTP_METHODS.GET },
21940
+ updateSettings: { url: '/titles/{title_id}/preorders/settings', method: HTTP_METHODS.PUT },
21941
+ offers: { url: '/titles/{title_id}/preorders/admin/offers', method: HTTP_METHODS.GET },
21942
+ createOffer: { url: '/titles/{title_id}/preorders/admin/offers', method: HTTP_METHODS.POST },
21943
+ offer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}', method: HTTP_METHODS.GET },
21944
+ updateOffer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}', method: HTTP_METHODS.PUT },
21945
+ activateOffer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/activate', method: HTTP_METHODS.POST },
21946
+ pauseOffer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/pause', method: HTTP_METHODS.POST },
21947
+ archiveOffer: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/archive', method: HTTP_METHODS.POST },
21948
+ inventory: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/keys', method: HTTP_METHODS.GET },
21949
+ importKeys: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/keys/import', method: HTTP_METHODS.POST },
21950
+ retireKey: { url: '/titles/{title_id}/preorders/admin/offers/{offer_id}/keys/{key_id}/retire', method: HTTP_METHODS.POST },
21951
+ adminOrders: { url: '/titles/{title_id}/preorders/admin/orders', method: HTTP_METHODS.GET },
21952
+ readiness: { url: '/titles/{title_id}/preorders/admin/readiness', method: HTTP_METHODS.GET },
21953
+ adminOrderAction: { url: '/titles/{title_id}/preorders/admin/orders/{order_id}/{action}', method: HTTP_METHODS.POST },
21954
+ mcpCapabilities: { url: '/mcp/v1/titles/{title_id}/preorders/capabilities', method: HTTP_METHODS.GET },
21955
+ mcpOperation: { url: '/mcp/v1/titles/{title_id}/preorders/operations/{operation}', method: HTTP_METHODS.POST },
21956
+ };
21957
+
21958
+ class Preorders {
21959
+ static catalog(title_id, options) {
21960
+ return Requests.processRoute(PreordersRoute.routes.catalog, undefined, { title_id }, undefined, options);
21961
+ }
21962
+ static purchase(title_id, offer_id, data, options) {
21963
+ return Requests.processRoute(PreordersRoute.routes.purchase, data, { title_id, offer_id }, undefined, options);
21964
+ }
21965
+ static myOrders(title_id, options) {
21966
+ return Requests.processRoute(PreordersRoute.routes.myOrders, undefined, { title_id }, undefined, options);
21967
+ }
21968
+ static order(title_id, order_id, options) {
21969
+ return Requests.processRoute(PreordersRoute.routes.order, undefined, { title_id, order_id }, undefined, options);
21970
+ }
21971
+ static refundMine(title_id, order_id, options) {
21972
+ return Requests.processRoute(PreordersRoute.routes.refundMine, {}, { title_id, order_id }, undefined, options);
21973
+ }
21974
+ static resendMine(title_id, order_id, options) {
21975
+ return Requests.processRoute(PreordersRoute.routes.resendMine, {}, { title_id, order_id }, undefined, options);
21976
+ }
21977
+ static settings(title_id, options) {
21978
+ return Requests.processRoute(PreordersRoute.routes.settings, undefined, { title_id }, undefined, options);
21979
+ }
21980
+ static updateSettings(title_id, data, options) {
21981
+ return Requests.processRoute(PreordersRoute.routes.updateSettings, data, { title_id }, undefined, options);
21982
+ }
21983
+ static offers(title_id, options) {
21984
+ return Requests.processRoute(PreordersRoute.routes.offers, undefined, { title_id }, undefined, options);
21985
+ }
21986
+ static offer(title_id, offer_id, options) {
21987
+ return Requests.processRoute(PreordersRoute.routes.offer, undefined, { title_id, offer_id }, undefined, options);
21988
+ }
21989
+ static createOffer(title_id, data, options) {
21990
+ return Requests.processRoute(PreordersRoute.routes.createOffer, data, { title_id }, undefined, options);
21991
+ }
21992
+ static updateOffer(title_id, offer_id, data, options) {
21993
+ return Requests.processRoute(PreordersRoute.routes.updateOffer, data, { title_id, offer_id }, undefined, options);
21994
+ }
21995
+ static activateOffer(title_id, offer_id, options) {
21996
+ return Requests.processRoute(PreordersRoute.routes.activateOffer, {}, { title_id, offer_id }, undefined, options);
21997
+ }
21998
+ static pauseOffer(title_id, offer_id, options) {
21999
+ return Requests.processRoute(PreordersRoute.routes.pauseOffer, {}, { title_id, offer_id }, undefined, options);
22000
+ }
22001
+ static archiveOffer(title_id, offer_id, options) {
22002
+ return Requests.processRoute(PreordersRoute.routes.archiveOffer, {}, { title_id, offer_id }, undefined, options);
22003
+ }
22004
+ static inventory(title_id, offer_id, options) {
22005
+ return Requests.processRoute(PreordersRoute.routes.inventory, undefined, { title_id, offer_id }, undefined, options);
22006
+ }
22007
+ static importKeys(title_id, offer_id, keys, options) {
22008
+ return Requests.processRoute(PreordersRoute.routes.importKeys, { keys }, { title_id, offer_id }, undefined, options);
22009
+ }
22010
+ static importKeyFile(title_id, offer_id, file) {
22011
+ const url = PreordersRoute.routes.importKeys.url
22012
+ .replace('{title_id}', title_id)
22013
+ .replace('{offer_id}', offer_id);
22014
+ return Requests.uploadFile(url, 'key_file', file, {}, undefined, undefined, { excludeCommunityContext: true });
22015
+ }
22016
+ static retireKey(title_id, offer_id, key_id, reason, options) {
22017
+ return Requests.processRoute(PreordersRoute.routes.retireKey, { reason }, { title_id, offer_id, key_id }, undefined, options);
22018
+ }
22019
+ static adminOrders(title_id, filters, options) {
22020
+ return Requests.processRoute(PreordersRoute.routes.adminOrders, undefined, { title_id }, filters, options);
22021
+ }
22022
+ static readiness(title_id, options) {
22023
+ return Requests.processRoute(PreordersRoute.routes.readiness, undefined, { title_id }, undefined, options);
22024
+ }
22025
+ static adminOrderAction(title_id, order_id, action, options) {
22026
+ return Requests.processRoute(PreordersRoute.routes.adminOrderAction, {}, { title_id, order_id, action }, undefined, options);
22027
+ }
22028
+ static mcpCapabilities(title_id, options) {
22029
+ return Requests.processRoute(PreordersRoute.routes.mcpCapabilities, undefined, { title_id }, undefined, options);
22030
+ }
22031
+ static mcpOperation(title_id, operation, argumentsData = {}, options) {
22032
+ return Requests.processRoute(PreordersRoute.routes.mcpOperation, { arguments: argumentsData }, { title_id, operation }, undefined, options);
22033
+ }
22034
+ }
22035
+
21929
22036
  /** Generate a 256-bit browser nonce. Fails closed without secure Web Crypto. */
21930
22037
  function createMicrotransactionNonce() {
21931
22038
  var _a;
@@ -22072,6 +22179,8 @@ function openMicrotransactionOverlay(options) {
22072
22179
  if (activeOverlays.has(doc))
22073
22180
  throw new Error('A checkout is already open. Resume or close that same purchase first.');
22074
22181
  const session = options.session;
22182
+ // Older purchase-session creation responses need not include an intent.
22183
+ const restoring = session.intent === 'restore';
22075
22184
  const parsed = new URL(session.hosted_url);
22076
22185
  const path = `/games/${encodeURIComponent(options.titleId)}/checkout/${encodeURIComponent(session.id)}`;
22077
22186
  if (parsed.origin !== options.checkoutOrigin || parsed.pathname !== path || parsed.search || parsed.username || parsed.password ||
@@ -22090,41 +22199,55 @@ function openMicrotransactionOverlay(options) {
22090
22199
  dialog.setAttribute('aria-modal', 'true');
22091
22200
  dialog.setAttribute('aria-labelledby', `${id}-title`);
22092
22201
  dialog.setAttribute('role', 'dialog');
22093
- 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;';
22202
+ 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;';
22094
22203
  const style = doc.createElement('style');
22095
- style.textContent = `#${id}::backdrop{background:rgba(8,16,32,.72)}#${id} button:focus-visible{outline:3px solid #4263eb;outline-offset:3px}@media(max-width:600px){#${id}{inset:0!important;width:100vw!important;height:100dvh!important;border-radius:0!important}}`;
22204
+ style.textContent = `
22205
+ #${id}::backdrop{background:rgba(8,16,32,.72)}
22206
+ #${id} button:focus-visible{outline:3px solid #4263eb;outline-offset:3px}
22207
+ @supports(height:100dvh){#${id}{height:min(850px,calc(100dvh - 32px))!important}}
22208
+ @media(max-width:600px),(max-height:500px){
22209
+ #${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}
22210
+ @supports(height:100dvh){#${id}{height:100dvh!important}}
22211
+ }`;
22212
+ // Natural-height chrome can wrap/scroll without consuming the entire frame.
22213
+ // No fixed header/status subtraction; the iframe owns all remaining space.
22214
+ const chrome = doc.createElement('div');
22215
+ chrome.style.cssText = 'flex:0 1 auto;min-width:0;min-height:0;max-height:50%;overflow:auto;overscroll-behavior:contain;';
22096
22216
  const header = doc.createElement('div');
22097
- 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;';
22217
+ 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;';
22098
22218
  const heading = doc.createElement('h2');
22099
22219
  heading.id = `${id}-title`;
22100
- heading.textContent = options.label || (session.intent === 'restore' ? 'Restore game purchases' : 'Secure game checkout');
22101
- heading.style.cssText = 'margin:0;font:600 17px/1.3 system-ui,sans-serif;color:#172033;';
22220
+ heading.textContent = options.label || (restoring ? 'Restore game purchases' : 'Secure game checkout');
22221
+ 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;';
22102
22222
  const closeButton = doc.createElement('button');
22103
22223
  closeButton.type = 'button';
22104
22224
  closeButton.textContent = 'Close';
22105
- closeButton.setAttribute('aria-label', 'Close checkout and return to game');
22106
- 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;';
22225
+ closeButton.setAttribute('aria-label', restoring ? 'Close restore and return to game' : 'Close checkout and return to game');
22226
+ 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;';
22107
22227
  const retryButton = doc.createElement('button');
22108
22228
  retryButton.type = 'button';
22109
22229
  retryButton.textContent = 'Retry';
22110
- retryButton.setAttribute('aria-label', 'Reload this same checkout without starting another purchase');
22230
+ retryButton.setAttribute('aria-label', restoring ? 'Reload this same restore session' : 'Reload this same checkout without starting another purchase');
22111
22231
  retryButton.style.cssText = closeButton.style.cssText;
22232
+ closeButton.style.background = '#172033';
22233
+ closeButton.style.color = '#fff';
22112
22234
  const controls = doc.createElement('div');
22113
- controls.style.cssText = 'display:flex;gap:8px;';
22235
+ controls.style.cssText = 'display:flex;flex-wrap:wrap;gap:8px;min-width:0;max-width:100%;margin-left:auto;';
22114
22236
  controls.append(retryButton, closeButton);
22115
22237
  header.append(heading, controls);
22116
22238
  const status = doc.createElement('div');
22117
22239
  status.setAttribute('role', 'status');
22118
- 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;';
22119
- status.textContent = 'Your game stays open. Loading secure checkout…';
22240
+ 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;';
22241
+ status.textContent = restoring ? 'Your game stays open. Loading secure restore…' : 'Your game stays open. Loading secure checkout…';
22120
22242
  const iframe = doc.createElement('iframe');
22121
22243
  iframe.title = heading.textContent;
22122
22244
  iframe.setAttribute('allow', 'payment');
22123
22245
  iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox');
22124
22246
  iframe.referrerPolicy = 'no-referrer';
22125
- iframe.style.cssText = 'display:block;width:100%;height:calc(100% - 84px);border:0;background:#fff;';
22247
+ 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;';
22126
22248
  iframe.src = session.hosted_url;
22127
- dialog.append(style, header, status, iframe);
22249
+ chrome.append(header, status);
22250
+ dialog.append(style, chrome, iframe);
22128
22251
  doc.body.append(dialog);
22129
22252
  const frameWindow = iframe.contentWindow;
22130
22253
  if (!frameWindow) {
@@ -22138,6 +22261,19 @@ function openMicrotransactionOverlay(options) {
22138
22261
  let frameLoadTimer;
22139
22262
  let appReadyTimer;
22140
22263
  let applicationReady = false;
22264
+ let retryPhase = 'idle';
22265
+ let retryReady = false;
22266
+ const isBlankDocument = () => {
22267
+ var _a;
22268
+ // about:blank inherits our origin. A src attribute alone says nothing about
22269
+ // which document emitted load; an old checkout load can still be queued.
22270
+ try {
22271
+ return ((_a = iframe.contentDocument) === null || _a === void 0 ? void 0 : _a.URL) === 'about:blank' && iframe.contentDocument.readyState === 'complete';
22272
+ }
22273
+ catch (_b) {
22274
+ return false;
22275
+ }
22276
+ };
22141
22277
  const blocked = [];
22142
22278
  const report = (error) => { var _a; try {
22143
22279
  (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
@@ -22155,21 +22291,32 @@ function openMicrotransactionOverlay(options) {
22155
22291
  if (closed)
22156
22292
  return;
22157
22293
  clearWatchdogs();
22294
+ if (retryPhase !== 'idle') {
22295
+ retryPhase = 'failed';
22296
+ retryReady = false;
22297
+ }
22158
22298
  status.setAttribute('role', 'alert');
22299
+ const flow = restoring ? 'Restore' : 'Checkout';
22159
22300
  status.textContent = reason === 'ready'
22160
- ? 'Checkout did not become ready. Retry this same checkout or Close; your game remains open.'
22161
- : 'Checkout could not load here. Retry this same checkout or Close; your game remains open.';
22162
- report(new Error(reason === 'ready'
22163
- ? 'Embedded checkout readiness timed out; no navigation or new payment was attempted.'
22164
- : 'Embedded checkout loading unavailable; no navigation or new payment was attempted.'));
22301
+ ? `${flow} did not become ready. Retry this same session or Close; your game remains open.`
22302
+ : `${flow} could not load here. Retry this same session or Close; your game remains open.`;
22303
+ report(new Error(restoring
22304
+ ? `Embedded restore ${reason === 'ready' ? 'readiness timed out' : 'loading unavailable'}; no navigation was attempted.`
22305
+ : reason === 'ready'
22306
+ ? 'Embedded checkout readiness timed out; no navigation or new payment was attempted.'
22307
+ : 'Embedded checkout loading unavailable; no navigation or new payment was attempted.'));
22165
22308
  };
22166
22309
  const markApplicationReady = () => {
22167
22310
  if (closed)
22168
22311
  return;
22312
+ // A verified claim from the previous document may finish while Retry is
22313
+ // navigating. Keep that claim, but it cannot certify the new document UI.
22314
+ if (retryPhase !== 'idle')
22315
+ return;
22169
22316
  applicationReady = true;
22170
22317
  clearWatchdogs();
22171
22318
  status.setAttribute('role', 'status');
22172
- status.textContent = 'Checkout is ready. Your game remains open underneath.';
22319
+ status.textContent = restoring ? 'Restore is ready. Your game remains open underneath.' : 'Checkout is ready. Your game remains open underneath.';
22173
22320
  };
22174
22321
  const armLoadWatchdog = () => {
22175
22322
  clearWatchdogs();
@@ -22223,7 +22370,8 @@ function openMicrotransactionOverlay(options) {
22223
22370
  event.preventDefault();
22224
22371
  void overlay.close();
22225
22372
  }
22226
- if (event.key === 'Tab' && !closed) {
22373
+ // Keep the trap while close waits for an in-flight claim/inventory callback.
22374
+ if (event.key === 'Tab' && dialog.isConnected) {
22227
22375
  if (event.shiftKey && doc.activeElement === retryButton) {
22228
22376
  event.preventDefault();
22229
22377
  iframe.focus();
@@ -22235,6 +22383,8 @@ function openMicrotransactionOverlay(options) {
22235
22383
  }
22236
22384
  };
22237
22385
  const onCancel = (event) => { event.preventDefault(); void overlay.close(); };
22386
+ // Keyboard events inside the cross-origin document do not reach onKey.
22387
+ // The hosted UI forwards Escape via this existing, strictly bound close message.
22238
22388
  const onCloseMessage = (event) => {
22239
22389
  if (closed || event.origin !== options.checkoutOrigin || event.source !== frameWindow || !event.data || typeof event.data !== 'object')
22240
22390
  return;
@@ -22243,24 +22393,53 @@ function openMicrotransactionOverlay(options) {
22243
22393
  message.checkout_session_id !== session.id || message.nonce !== session.nonce)
22244
22394
  return;
22245
22395
  if (message.type === 'glitch.microtransaction.ready') {
22246
- markApplicationReady();
22396
+ if (retryPhase === 'checkout' && !isBlankDocument())
22397
+ retryReady = true;
22398
+ else if (retryPhase === 'idle')
22399
+ markApplicationReady();
22247
22400
  return;
22248
22401
  }
22249
22402
  if (message.type !== 'glitch.microtransaction.close')
22250
22403
  return;
22251
22404
  void overlay.close(verified ? 'completed' : 'dismissed');
22252
22405
  };
22253
- const onFrameError = () => { unavailable('error'); };
22406
+ const onFrameError = () => {
22407
+ // Events from the document being left cannot fail the blank navigation.
22408
+ // Its watchdog still bounds a missing/failed intermediate load.
22409
+ if (retryPhase === 'blank' || (retryPhase === 'checkout' && isBlankDocument()))
22410
+ return;
22411
+ unavailable('error');
22412
+ };
22254
22413
  const onFrameLoad = () => {
22255
22414
  if (closed)
22256
22415
  return;
22416
+ if (retryPhase === 'failed')
22417
+ return;
22418
+ if (retryPhase === 'blank') {
22419
+ if (!isBlankDocument())
22420
+ return;
22421
+ retryPhase = 'checkout';
22422
+ armLoadWatchdog();
22423
+ iframe.src = session.hosted_url;
22424
+ return;
22425
+ }
22426
+ if (retryPhase === 'checkout') {
22427
+ if (isBlankDocument())
22428
+ return;
22429
+ retryPhase = 'idle';
22430
+ if (retryReady) {
22431
+ retryReady = false;
22432
+ markApplicationReady();
22433
+ return;
22434
+ }
22435
+ }
22257
22436
  if (frameLoadTimer !== undefined)
22258
22437
  win.clearTimeout(frameLoadTimer);
22259
22438
  frameLoadTimer = undefined;
22260
22439
  if (applicationReady)
22261
22440
  return;
22262
22441
  status.setAttribute('role', 'status');
22263
- status.textContent = 'Checkout document loaded. Waiting for the secure checkout interface…';
22442
+ status.textContent = restoring ? 'Restore document loaded. Waiting for the secure restore interface…' : 'Checkout document loaded. Waiting for the secure checkout interface…';
22264
22443
  // A document load is not proof the app rendered. Repeated loads cannot
22265
22444
  // indefinitely extend this bounded wait; only explicit Retry resets it.
22266
22445
  if (appReadyTimer === undefined)
@@ -22269,12 +22448,18 @@ function openMicrotransactionOverlay(options) {
22269
22448
  const overlay = {
22270
22449
  element: dialog, iframe, refresh,
22271
22450
  retry: () => {
22272
- if (closed)
22451
+ if (closed || retryPhase === 'blank' || retryPhase === 'checkout')
22273
22452
  return;
22274
- status.textContent = 'Retrying the same secure checkout. Your game stays open.';
22453
+ status.textContent = restoring ? 'Retrying the same secure restore session. Your game stays open.' : 'Retrying the same secure checkout. Your game stays open.';
22275
22454
  status.setAttribute('role', 'status');
22455
+ retryPhase = 'blank';
22456
+ retryReady = false;
22276
22457
  armLoadWatchdog();
22277
- iframe.src = session.hosted_url;
22458
+ // Bootstrap removes #token with replaceState. Reassigning the original
22459
+ // URL then only changes the fragment; it does not reload checkout/API.
22460
+ // Commit a harmless blank document first, then navigate this SAME iframe
22461
+ // to the exact original capability URL. Its WindowProxy/bridge stay pinned.
22462
+ iframe.src = 'about:blank';
22278
22463
  },
22279
22464
  close: (reason = 'dismissed') => {
22280
22465
  if (closing)
@@ -22283,7 +22468,10 @@ function openMicrotransactionOverlay(options) {
22283
22468
  return Promise.resolve();
22284
22469
  closed = true;
22285
22470
  clearWatchdogs();
22286
- status.textContent = 'Finishing secure purchase verification. Your game stays open.';
22471
+ retryPhase = 'failed';
22472
+ retryReady = false;
22473
+ status.setAttribute('role', 'status');
22474
+ status.textContent = restoring ? 'Finishing secure restore verification. Your game stays open.' : 'Finishing secure purchase verification. Your game stays open.';
22287
22475
  closing = (() => __awaiter(this, void 0, void 0, function* () {
22288
22476
  var _a;
22289
22477
  try {
@@ -30393,6 +30581,7 @@ Glitch.api = {
30393
30581
  Hosting: Hosting,
30394
30582
  GameDesign: GameDesign,
30395
30583
  Microtransactions: Microtransactions,
30584
+ Preorders: Preorders,
30396
30585
  };
30397
30586
  Glitch.util = {
30398
30587
  Requests: Requests,