@ai-sdk/provider-utils 4.0.65 → 4.0.67

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/provider-utils",
3
- "version": "4.0.65",
3
+ "version": "4.0.67",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -3,7 +3,7 @@ import { DownloadError } from './download-error';
3
3
  import type { FetchFunction } from './fetch-function';
4
4
  import { isBrowserRuntime } from './is-browser-runtime';
5
5
  import { isSameOrigin } from './is-same-origin';
6
- import { getDefaultDownloadFetch } from './safe-node-fetch';
6
+ import { getDefaultDownloadFetch, isNodeRuntime } from './safe-node-fetch';
7
7
  import { sanitizeRequestHeaders } from './sanitize-request-headers';
8
8
  import { validateDownloadUrl } from './validate-download-url';
9
9
 
@@ -39,6 +39,7 @@ export async function fetchWithValidatedEndpoint({
39
39
  fetch: customFetch,
40
40
  trustedOrigin,
41
41
  redirect = 'error',
42
+ requireDnsValidation = false,
42
43
  }: {
43
44
  url: string | URL;
44
45
  init?: RequestInit;
@@ -49,6 +50,11 @@ export async function fetchWithValidatedEndpoint({
49
50
  */
50
51
  trustedOrigin?: string;
51
52
  redirect?: 'error' | 'manual';
53
+ /**
54
+ * Reject untrusted URLs on server runtimes without a DNS-pinned default
55
+ * transport unless an explicit custom fetch provides equivalent validation.
56
+ */
57
+ requireDnsValidation?: boolean;
52
58
  }): Promise<Response> {
53
59
  const urlText = url.toString();
54
60
  const isTrusted =
@@ -56,6 +62,20 @@ export async function fetchWithValidatedEndpoint({
56
62
 
57
63
  if (!isTrusted) {
58
64
  validateDownloadUrl(urlText);
65
+
66
+ if (
67
+ requireDnsValidation &&
68
+ (customFetch == null || customFetch === globalThis.fetch) &&
69
+ !isNodeRuntime() &&
70
+ // A window alias alone does not distinguish older Deno from a browser.
71
+ !(isBrowserRuntime() && typeof document !== 'undefined')
72
+ ) {
73
+ throw new DownloadError({
74
+ url: urlText,
75
+ message:
76
+ 'This server runtime requires a custom fetch with connect-time DNS validation for untrusted URLs',
77
+ });
78
+ }
59
79
  }
60
80
 
61
81
  const fetch =
package/src/schema.ts CHANGED
@@ -176,7 +176,8 @@ function standardSchema<OBJECT>(
176
176
  {
177
177
  validate: async value => {
178
178
  const result = await standardSchema['~standard'].validate(value);
179
- return 'value' in result
179
+ // Failed Standard Schema results can also contain a value.
180
+ return result.issues === undefined && 'value' in result
180
181
  ? { success: true, value: result.value }
181
182
  : {
182
183
  success: false,