@dnsid-ai/transport 0.27.0 → 0.28.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.cjs CHANGED
@@ -217,8 +217,31 @@ function createSsrfSafeFetch(config = {}, options = {}) {
217
217
  for (const item of Array.isArray(value) ? value : value === void 0 ? [] : [value]) headers.append(name, item);
218
218
  }
219
219
  const noBody = request.method === "HEAD" || [204, 205, 304].includes(response.statusCode);
220
+ let body = null;
220
221
  if (noBody) await response.body.dump();
221
- return new Response(noBody ? null : import_node_stream.Readable.toWeb(response.body), { status: response.statusCode, statusText: response.statusText, headers });
222
+ else {
223
+ const iterator = response.body[Symbol.asyncIterator]();
224
+ let canceled = false;
225
+ response.body.on("error", () => {
226
+ });
227
+ body = new ReadableStream({
228
+ async pull(controller) {
229
+ try {
230
+ const { value, done } = await iterator.next();
231
+ if (canceled) return;
232
+ if (done) controller.close();
233
+ else controller.enqueue(new Uint8Array(value));
234
+ } catch (error) {
235
+ if (!canceled) controller.error(error);
236
+ }
237
+ },
238
+ cancel() {
239
+ canceled = true;
240
+ response.body.destroy();
241
+ }
242
+ });
243
+ }
244
+ return new Response(body, { status: response.statusCode, statusText: response.statusText, headers });
222
245
  }
223
246
  return fetchWithSafeLookup(input, { ...init, redirect: "manual" });
224
247
  };
@@ -523,7 +546,8 @@ function fetchWithRedirects(url, opts, depth) {
523
546
  signal: opts.signal,
524
547
  rejectUnauthorized: true,
525
548
  headers: {
526
- "User-Agent": DNSID_USER_AGENT
549
+ "User-Agent": DNSID_USER_AGENT,
550
+ ...opts.revalidate ? { "Cache-Control": "no-cache" } : {}
527
551
  },
528
552
  lookup: createSsrfSafeLookup(opts.dnsServer, (opts.privateAddressHosts ?? []).map(import_protocol2.normalizePrivateAddressHost))
529
553
  };
package/dist/index.d.cts CHANGED
@@ -13,6 +13,8 @@ interface FetchResult {
13
13
  }
14
14
  /** Options controlling {@link fetchJson}. */
15
15
  interface HTTPSFetchOptions {
16
+ /** Bypass local caches and revalidate upstream evidence. */
17
+ revalidate?: boolean;
16
18
  /** Shared verification deadline/cancellation, including redirects. */
17
19
  signal?: AbortSignal;
18
20
  /** If set, the URL host (and every redirect host) must match this host exactly. */
package/dist/index.d.ts CHANGED
@@ -13,6 +13,8 @@ interface FetchResult {
13
13
  }
14
14
  /** Options controlling {@link fetchJson}. */
15
15
  interface HTTPSFetchOptions {
16
+ /** Bypass local caches and revalidate upstream evidence. */
17
+ revalidate?: boolean;
16
18
  /** Shared verification deadline/cancellation, including redirects. */
17
19
  signal?: AbortSignal;
18
20
  /** If set, the URL host (and every redirect host) must match this host exactly. */
package/dist/index.js CHANGED
@@ -175,8 +175,31 @@ function createSsrfSafeFetch(config = {}, options = {}) {
175
175
  for (const item of Array.isArray(value) ? value : value === void 0 ? [] : [value]) headers.append(name, item);
176
176
  }
177
177
  const noBody = request.method === "HEAD" || [204, 205, 304].includes(response.statusCode);
178
+ let body = null;
178
179
  if (noBody) await response.body.dump();
179
- return new Response(noBody ? null : Readable.toWeb(response.body), { status: response.statusCode, statusText: response.statusText, headers });
180
+ else {
181
+ const iterator = response.body[Symbol.asyncIterator]();
182
+ let canceled = false;
183
+ response.body.on("error", () => {
184
+ });
185
+ body = new ReadableStream({
186
+ async pull(controller) {
187
+ try {
188
+ const { value, done } = await iterator.next();
189
+ if (canceled) return;
190
+ if (done) controller.close();
191
+ else controller.enqueue(new Uint8Array(value));
192
+ } catch (error) {
193
+ if (!canceled) controller.error(error);
194
+ }
195
+ },
196
+ cancel() {
197
+ canceled = true;
198
+ response.body.destroy();
199
+ }
200
+ });
201
+ }
202
+ return new Response(body, { status: response.statusCode, statusText: response.statusText, headers });
180
203
  }
181
204
  return fetchWithSafeLookup(input, { ...init, redirect: "manual" });
182
205
  };
@@ -481,7 +504,8 @@ function fetchWithRedirects(url, opts, depth) {
481
504
  signal: opts.signal,
482
505
  rejectUnauthorized: true,
483
506
  headers: {
484
- "User-Agent": DNSID_USER_AGENT
507
+ "User-Agent": DNSID_USER_AGENT,
508
+ ...opts.revalidate ? { "Cache-Control": "no-cache" } : {}
485
509
  },
486
510
  lookup: createSsrfSafeLookup(opts.dnsServer, (opts.privateAddressHosts ?? []).map(normalizePrivateAddressHost))
487
511
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnsid-ai/transport",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "description": "Node.js DNS and HTTPS transport implementations for DNSid.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "typecheck": "tsc --noEmit"
39
39
  },
40
40
  "dependencies": {
41
- "@dnsid-ai/protocol": "^0.27.0",
41
+ "@dnsid-ai/protocol": "^0.28.0",
42
42
  "dns-packet": "5.6.1",
43
43
  "undici": "^8.11.0"
44
44
  },