@isomorph.ai/app-sdk 1.11.0 → 1.12.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.
Files changed (2) hide show
  1. package/dist/index.js +20 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -189,7 +189,13 @@ class Transport {
189
189
  const response = await this.fetch(`${this.baseUrl}${path}`, {
190
190
  credentials: 'same-origin',
191
191
  ...init,
192
- headers: mergeHeaders({ 'content-type': 'application/json' }, runnerIdentityHeaders(this.identity), init.headers, onProgress ? { accept: PROGRESS_MEDIA_TYPE } : undefined),
192
+ headers: mergeHeaders(
193
+ // No content type on a request without a body: a browser GET that
194
+ // carries one is not a "simple" request, so it costs a CORS preflight
195
+ // (OPTIONS, one more round trip, on a separate uncredentialed
196
+ // connection a preconnect cannot warm) before the GET itself. Without
197
+ // it the identity GET and every other read is one round trip.
198
+ init.body === undefined && ['GET', 'HEAD'].includes((init.method ?? 'GET').toUpperCase()) ? {} : { 'content-type': 'application/json' }, runnerIdentityHeaders(this.identity), init.headers, onProgress ? { accept: PROGRESS_MEDIA_TYPE } : undefined),
193
199
  });
194
200
  if (onProgress && response.ok && response.body && response.headers.get('content-type')?.startsWith(PROGRESS_MEDIA_TYPE)) {
195
201
  return readProgress(response, onProgress);
@@ -492,6 +498,19 @@ export function createClient(options = {}) {
492
498
  },
493
499
  };
494
500
  }
501
+ // A kit page on its own API host pays for its first call three times over:
502
+ // a fresh connection (TCP, TLS, then a CORS preflight), the 401 → context
503
+ // refresh → resend detour once the context cookie has lapsed, and only then
504
+ // the call. Sending the identity GET now — the one the API host heals — opens
505
+ // the connection, renews a lapsed context and caches the user while the page
506
+ // is still rendering, so the first action rides an open connection with a
507
+ // live context; a refusal while it is in flight shares it (renew above). A
508
+ // page-relative base (isomorph dev, a git app on the shared edge) already has
509
+ // its connection and the edge heals its GETs, so nothing is sent there, and
510
+ // under Node the identity is a static token. Its outcome is the page's to
511
+ // read through identity.current() and onChange, never surfaced here.
512
+ if (transport.separateApiHost)
513
+ void refreshIdentity().catch(() => undefined);
495
514
  const scheduleIdentityRefresh = () => {
496
515
  if (refreshTimer !== undefined || authListeners.size === 0 || identityRefreshMs <= 0)
497
516
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isomorph.ai/app-sdk",
3
- "version": "1.11.0",
3
+ "version": "1.12.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",