@ai-ecoverse/slicc-kernel 1.170.4 → 1.172.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.
@@ -305,6 +305,18 @@ var TransportError = class extends Error {
305
305
  this.detail = detail === "transport" ? detail : void 0;
306
306
  }
307
307
  };
308
+ function unfollowed(redirect) {
309
+ return redirect !== void 0 && redirect !== "follow";
310
+ }
311
+ function honors(traits, redirect) {
312
+ if (traits.redirectPolicy === true) return true;
313
+ const hops = traits.redirectHops;
314
+ const raw = traits.manualRedirects === true && (hops === void 0 || hops === false);
315
+ return redirect === "manual" && raw;
316
+ }
317
+ function refused(message) {
318
+ return new TransportError(message, 502, void 0, "transport");
319
+ }
308
320
  var RemoteTransport = class {
309
321
  traits;
310
322
  port;
@@ -388,10 +400,13 @@ var RemoteTransport = class {
388
400
  waiter?.reject(new TransportError("the request was cancelled"));
389
401
  this.port.postMessage({ net: "cancel", nid });
390
402
  }
391
- async fetch(request) {
403
+ async fetch(request, owner, stamp) {
392
404
  const nid = ++this.nextId;
393
- const { signal } = request;
405
+ const { signal, redirect } = request;
394
406
  signal.throwIfAborted();
407
+ if (unfollowed(redirect) && !honors(this.traits, redirect)) {
408
+ throw refused(`this transport cannot honor redirect: ${redirect}`);
409
+ }
395
410
  let finished = false;
396
411
  const abort = () => {
397
412
  finished = true;
@@ -414,13 +429,16 @@ var RemoteTransport = class {
414
429
  url: request.url,
415
430
  method: request.method,
416
431
  headers: request.headers,
417
- ...request.bodyStream ? { streamed: true } : request.body ? { body: request.body } : {}
432
+ ...request.bodyStream ? { streamed: true } : request.body ? { body: request.body } : {},
433
+ ...redirect !== void 0 ? { redirect } : {},
434
+ ...owner !== void 0 ? { owner } : {},
435
+ ...stamp ? { stamp } : {}
418
436
  });
419
437
  } catch (e) {
420
438
  finish();
421
439
  throw e;
422
440
  }
423
- const { status, statusText, headers, url, redirected, redirects } = head;
441
+ const { status, statusText, headers, url, redirected, redirects, opaqueRedirect } = head;
424
442
  const read = async () => {
425
443
  if (finished) return void 0;
426
444
  const reply = await this.ask({ net: "read", nid }).catch((e) => {
@@ -436,9 +454,15 @@ var RemoteTransport = class {
436
454
  finish();
437
455
  this.cancel(nid);
438
456
  };
457
+ if (unfollowed(redirect) && (redirected || redirects?.length)) {
458
+ await cancel();
459
+ throw refused(`this transport followed a redirect despite redirect: ${redirect}`);
460
+ }
439
461
  return {
440
- ...redirected ? { url, redirected } : {},
462
+ ...url !== void 0 ? { url } : {},
463
+ ...redirected !== void 0 ? { redirected } : {},
441
464
  ...redirects ? { redirects } : {},
465
+ ...opaqueRedirect ? { opaqueRedirect } : {},
442
466
  status,
443
467
  statusText,
444
468
  headers,
@@ -1197,9 +1221,9 @@ async function greet(channel, lock, timeoutMs, requests) {
1197
1221
  } finally {
1198
1222
  clearTimeout(timer);
1199
1223
  }
1200
- const refused2 = hello.error ?? versionError(hello.protocol);
1201
- if (refused2) {
1202
- const error = new Error(refused2);
1224
+ const refused3 = hello.error ?? versionError(hello.protocol);
1225
+ if (refused3) {
1226
+ const error = new Error(refused3);
1203
1227
  channel.end(error);
1204
1228
  throw error;
1205
1229
  }
@@ -1346,9 +1370,9 @@ function serveFilesystem(port, handlers, capabilities = {}, options = {}) {
1346
1370
  let open = false;
1347
1371
  const reply = (message, transfer = []) => port.postMessage(message, transfer);
1348
1372
  async function hello(message) {
1349
- const refused2 = driverVersionError(message.protocol);
1350
- if (refused2) {
1351
- reply({ hello: { protocol: DRIVER_PROTOCOL, error: refused2, errno: "EPROTO" } });
1373
+ const refused3 = driverVersionError(message.protocol);
1374
+ if (refused3) {
1375
+ reply({ hello: { protocol: DRIVER_PROTOCOL, error: refused3, errno: "EPROTO" } });
1352
1376
  return;
1353
1377
  }
1354
1378
  try {
@@ -1862,7 +1886,7 @@ function zeroedBuffers(buffer) {
1862
1886
  poolSize: fixed(0)
1863
1887
  });
1864
1888
  }
1865
- function refused(specifier) {
1889
+ function refused2(specifier) {
1866
1890
  return Object.assign(new Error(`slicc-kernel: a JS program cannot import ${specifier}`), {
1867
1891
  code: "ERR_ACCESS_DENIED"
1868
1892
  });
@@ -1877,12 +1901,12 @@ function refuseModules() {
1877
1901
  registerHooks({
1878
1902
  resolve(specifier, context, next) {
1879
1903
  if (specifier.startsWith(SOURCE_MODULE)) {
1880
- if (!sources.has(specifier)) throw refused(specifier);
1904
+ if (!sources.has(specifier)) throw refused2(specifier);
1881
1905
  return { url: specifier, shortCircuit: true };
1882
1906
  }
1883
- if (isBuiltin(specifier)) throw refused(specifier);
1907
+ if (isBuiltin(specifier)) throw refused2(specifier);
1884
1908
  const resolved = next(specifier, context);
1885
- if (!resolved.url.startsWith("data:")) throw refused(resolved.url);
1909
+ if (!resolved.url.startsWith("data:")) throw refused2(resolved.url);
1886
1910
  return resolved;
1887
1911
  },
1888
1912
  load(url, context, next) {