@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.
package/dist/index.js CHANGED
@@ -1189,10 +1189,11 @@ function fetchTransport(options = {}) {
1189
1189
  const send = options.fetch ?? globalThis.fetch.bind(globalThis);
1190
1190
  const Socket = options.webSocket === true ? globalThis.WebSocket : options.webSocket || void 0;
1191
1191
  const headers = options.webSocketHeaders === true;
1192
- const redirect = options.redirect ?? "follow";
1192
+ const instance = options.redirect ?? "follow";
1193
1193
  return {
1194
1194
  traits: {
1195
- manualRedirects: redirect === "manual",
1195
+ manualRedirects: instance === "manual",
1196
+ redirectPolicy: true,
1196
1197
  encodedBodies: false,
1197
1198
  maxRequestBody: options.maxRequestBody ?? MAX_REQUEST_BODY,
1198
1199
  crossOrigin: "cors",
@@ -1208,7 +1209,7 @@ function fetchTransport(options = {}) {
1208
1209
  headers: joinHeaders(request.headers),
1209
1210
  ...requestBody(request),
1210
1211
  signal: request.signal,
1211
- redirect,
1212
+ redirect: request.redirect ?? instance,
1212
1213
  credentials: "omit",
1213
1214
  mode: "cors"
1214
1215
  });
@@ -1232,6 +1233,7 @@ function fetchTransport(options = {}) {
1232
1233
  const body = chunks(response.body, options.bodyIdleMs ?? BODY_IDLE_MS);
1233
1234
  return {
1234
1235
  ...response.redirected ? { url: response.url, redirected: true } : {},
1236
+ ...response.type === "opaqueredirect" ? { opaqueRedirect: true } : {},
1235
1237
  status: response.status,
1236
1238
  statusText: response.statusText,
1237
1239
  headers: headers2,
@@ -1267,6 +1269,19 @@ function uploadsFor(peer) {
1267
1269
  });
1268
1270
  return { of, answer: (call) => pulls.get(call.nid)?.(call) };
1269
1271
  }
1272
+ function headOf(nid, response) {
1273
+ return {
1274
+ net: "head",
1275
+ nid,
1276
+ ...response.url !== void 0 ? { url: response.url } : {},
1277
+ ...response.redirected !== void 0 ? { redirected: response.redirected } : {},
1278
+ ...response.redirects ? { redirects: response.redirects } : {},
1279
+ ...response.opaqueRedirect ? { opaqueRedirect: true } : {},
1280
+ status: response.status,
1281
+ statusText: response.statusText,
1282
+ headers: response.headers
1283
+ };
1284
+ }
1270
1285
  function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
1271
1286
  const open = /* @__PURE__ */ new Map();
1272
1287
  const fail = (nid, e) => {
@@ -1292,6 +1307,7 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
1292
1307
  method: call.method,
1293
1308
  headers: call.headers,
1294
1309
  ...call.streamed ? { bodyStream: uploads.of(call.nid, abort.signal) } : call.body ? { body: call.body } : {},
1310
+ ...call.redirect !== void 0 ? { redirect: call.redirect } : {},
1295
1311
  signal: abort.signal
1296
1312
  });
1297
1313
  if (!open.has(call.nid)) {
@@ -1299,15 +1315,7 @@ function serveTransport(peer, transport, { closeWaitMs = CLOSE_WAIT_MS } = {}) {
1299
1315
  return;
1300
1316
  }
1301
1317
  open.set(call.nid, { abort, body: response.body[Symbol.asyncIterator](), response });
1302
- peer.postMessage({
1303
- net: "head",
1304
- nid: call.nid,
1305
- ...response.redirected ? { url: response.url, redirected: true } : {},
1306
- ...response.redirects ? { redirects: response.redirects } : {},
1307
- status: response.status,
1308
- statusText: response.statusText,
1309
- headers: response.headers
1310
- });
1318
+ peer.postMessage(headOf(call.nid, response));
1311
1319
  } catch (e) {
1312
1320
  fail(call.nid, e);
1313
1321
  }
@@ -1461,6 +1469,18 @@ var TransportError = class extends Error {
1461
1469
  this.detail = detail === "transport" ? detail : void 0;
1462
1470
  }
1463
1471
  };
1472
+ function unfollowed(redirect) {
1473
+ return redirect !== void 0 && redirect !== "follow";
1474
+ }
1475
+ function honors(traits, redirect) {
1476
+ if (traits.redirectPolicy === true) return true;
1477
+ const hops = traits.redirectHops;
1478
+ const raw = traits.manualRedirects === true && (hops === void 0 || hops === false);
1479
+ return redirect === "manual" && raw;
1480
+ }
1481
+ function refused(message) {
1482
+ return new TransportError(message, 502, void 0, "transport");
1483
+ }
1464
1484
  var RemoteTransport = class {
1465
1485
  traits;
1466
1486
  port;
@@ -1546,8 +1566,11 @@ var RemoteTransport = class {
1546
1566
  }
1547
1567
  async fetch(request) {
1548
1568
  const nid = ++this.nextId;
1549
- const { signal } = request;
1569
+ const { signal, redirect } = request;
1550
1570
  signal.throwIfAborted();
1571
+ if (unfollowed(redirect) && !honors(this.traits, redirect)) {
1572
+ throw refused(`this transport cannot honor redirect: ${redirect}`);
1573
+ }
1551
1574
  let finished = false;
1552
1575
  const abort = () => {
1553
1576
  finished = true;
@@ -1570,13 +1593,14 @@ var RemoteTransport = class {
1570
1593
  url: request.url,
1571
1594
  method: request.method,
1572
1595
  headers: request.headers,
1573
- ...request.bodyStream ? { streamed: true } : request.body ? { body: request.body } : {}
1596
+ ...request.bodyStream ? { streamed: true } : request.body ? { body: request.body } : {},
1597
+ ...redirect !== void 0 ? { redirect } : {}
1574
1598
  });
1575
1599
  } catch (e) {
1576
1600
  finish();
1577
1601
  throw e;
1578
1602
  }
1579
- const { status, statusText, headers, url, redirected, redirects } = head;
1603
+ const { status, statusText, headers, url, redirected, redirects, opaqueRedirect } = head;
1580
1604
  const read = async () => {
1581
1605
  if (finished) return void 0;
1582
1606
  const reply = await this.ask({ net: "read", nid }).catch((e) => {
@@ -1592,9 +1616,15 @@ var RemoteTransport = class {
1592
1616
  finish();
1593
1617
  this.cancel(nid);
1594
1618
  };
1619
+ if (unfollowed(redirect) && (redirected || redirects?.length)) {
1620
+ await cancel();
1621
+ throw refused(`this transport followed a redirect despite redirect: ${redirect}`);
1622
+ }
1595
1623
  return {
1596
- ...redirected ? { url, redirected } : {},
1624
+ ...url !== void 0 ? { url } : {},
1625
+ ...redirected !== void 0 ? { redirected } : {},
1597
1626
  ...redirects ? { redirects } : {},
1627
+ ...opaqueRedirect ? { opaqueRedirect } : {},
1598
1628
  status,
1599
1629
  statusText,
1600
1630
  headers,
@@ -2054,9 +2084,9 @@ async function greet(channel, lock, timeoutMs, requests) {
2054
2084
  } finally {
2055
2085
  clearTimeout(timer);
2056
2086
  }
2057
- const refused = hello.error ?? versionError(hello.protocol);
2058
- if (refused) {
2059
- const error = new Error(refused);
2087
+ const refused2 = hello.error ?? versionError(hello.protocol);
2088
+ if (refused2) {
2089
+ const error = new Error(refused2);
2060
2090
  channel.end(error);
2061
2091
  throw error;
2062
2092
  }