@ai-ecoverse/slicc-kernel 1.170.3 → 1.171.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;
@@ -390,8 +402,11 @@ var RemoteTransport = class {
390
402
  }
391
403
  async fetch(request) {
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,14 @@ 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 } : {}
418
434
  });
419
435
  } catch (e) {
420
436
  finish();
421
437
  throw e;
422
438
  }
423
- const { status, statusText, headers, url, redirected, redirects } = head;
439
+ const { status, statusText, headers, url, redirected, redirects, opaqueRedirect } = head;
424
440
  const read = async () => {
425
441
  if (finished) return void 0;
426
442
  const reply = await this.ask({ net: "read", nid }).catch((e) => {
@@ -436,9 +452,15 @@ var RemoteTransport = class {
436
452
  finish();
437
453
  this.cancel(nid);
438
454
  };
455
+ if (unfollowed(redirect) && (redirected || redirects?.length)) {
456
+ await cancel();
457
+ throw refused(`this transport followed a redirect despite redirect: ${redirect}`);
458
+ }
439
459
  return {
440
- ...redirected ? { url, redirected } : {},
460
+ ...url !== void 0 ? { url } : {},
461
+ ...redirected !== void 0 ? { redirected } : {},
441
462
  ...redirects ? { redirects } : {},
463
+ ...opaqueRedirect ? { opaqueRedirect } : {},
442
464
  status,
443
465
  statusText,
444
466
  headers,
@@ -1197,9 +1219,9 @@ async function greet(channel, lock, timeoutMs, requests) {
1197
1219
  } finally {
1198
1220
  clearTimeout(timer);
1199
1221
  }
1200
- const refused2 = hello.error ?? versionError(hello.protocol);
1201
- if (refused2) {
1202
- const error = new Error(refused2);
1222
+ const refused3 = hello.error ?? versionError(hello.protocol);
1223
+ if (refused3) {
1224
+ const error = new Error(refused3);
1203
1225
  channel.end(error);
1204
1226
  throw error;
1205
1227
  }
@@ -1346,9 +1368,9 @@ function serveFilesystem(port, handlers, capabilities = {}, options = {}) {
1346
1368
  let open = false;
1347
1369
  const reply = (message, transfer = []) => port.postMessage(message, transfer);
1348
1370
  async function hello(message) {
1349
- const refused2 = driverVersionError(message.protocol);
1350
- if (refused2) {
1351
- reply({ hello: { protocol: DRIVER_PROTOCOL, error: refused2, errno: "EPROTO" } });
1371
+ const refused3 = driverVersionError(message.protocol);
1372
+ if (refused3) {
1373
+ reply({ hello: { protocol: DRIVER_PROTOCOL, error: refused3, errno: "EPROTO" } });
1352
1374
  return;
1353
1375
  }
1354
1376
  try {
@@ -1862,7 +1884,7 @@ function zeroedBuffers(buffer) {
1862
1884
  poolSize: fixed(0)
1863
1885
  });
1864
1886
  }
1865
- function refused(specifier) {
1887
+ function refused2(specifier) {
1866
1888
  return Object.assign(new Error(`slicc-kernel: a JS program cannot import ${specifier}`), {
1867
1889
  code: "ERR_ACCESS_DENIED"
1868
1890
  });
@@ -1877,12 +1899,12 @@ function refuseModules() {
1877
1899
  registerHooks({
1878
1900
  resolve(specifier, context, next) {
1879
1901
  if (specifier.startsWith(SOURCE_MODULE)) {
1880
- if (!sources.has(specifier)) throw refused(specifier);
1902
+ if (!sources.has(specifier)) throw refused2(specifier);
1881
1903
  return { url: specifier, shortCircuit: true };
1882
1904
  }
1883
- if (isBuiltin(specifier)) throw refused(specifier);
1905
+ if (isBuiltin(specifier)) throw refused2(specifier);
1884
1906
  const resolved = next(specifier, context);
1885
- if (!resolved.url.startsWith("data:")) throw refused(resolved.url);
1907
+ if (!resolved.url.startsWith("data:")) throw refused2(resolved.url);
1886
1908
  return resolved;
1887
1909
  },
1888
1910
  load(url, context, next) {