@sanity/client 7.5.0 → 7.7.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.d.cts CHANGED
@@ -698,6 +698,30 @@ export declare interface ClientConfig {
698
698
  */
699
699
  headers?: Record<string, string>
700
700
  ignoreBrowserTokenWarning?: boolean
701
+ /**
702
+ * Ignore specific warning messages from the client.
703
+ *
704
+ * @remarks
705
+ * - String values perform substring matching (not exact matching) against warning messages
706
+ * - RegExp values are tested against the full warning message
707
+ * - Array values allow multiple patterns to be specified
708
+ *
709
+ * @example
710
+ * ```typescript
711
+ * // Ignore warnings containing "experimental"
712
+ * ignoreWarnings: 'experimental'
713
+ *
714
+ * // Ignore multiple warning types
715
+ * ignoreWarnings: ['experimental', 'deprecated']
716
+ *
717
+ * // Use regex for exact matching
718
+ * ignoreWarnings: /^This is an experimental API version$/
719
+ *
720
+ * // Mix strings and regex patterns
721
+ * ignoreWarnings: ['rate limit', /^deprecated/i]
722
+ * ```
723
+ */
724
+ ignoreWarnings?: string | RegExp | Array<string | RegExp>
701
725
  withCredentials?: boolean
702
726
  allowReconfigure?: boolean
703
727
  timeout?: number
@@ -1278,6 +1302,26 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
1278
1302
  */
1279
1303
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
1280
1304
 
1305
+ /**
1306
+ * A string constant containing the experimental API version warning message.
1307
+ * Use this with the `ignoreWarnings` option to suppress warnings when using experimental API versions.
1308
+ *
1309
+ * @example
1310
+ * ```typescript
1311
+ * import { createClient, EXPERIMENTAL_API_WARNING } from '@sanity/client'
1312
+ *
1313
+ * const client = createClient({
1314
+ * projectId: 'your-project-id',
1315
+ * dataset: 'production',
1316
+ * apiVersion: 'vX', // experimental version
1317
+ * ignoreWarnings: EXPERIMENTAL_API_WARNING
1318
+ * })
1319
+ * ```
1320
+ *
1321
+ * @public
1322
+ */
1323
+ export declare const EXPERIMENTAL_API_WARNING = 'This is an experimental API version'
1324
+
1281
1325
  /**
1282
1326
  *
1283
1327
  *
@@ -1693,6 +1737,25 @@ export declare interface GroqAgentActionParam {
1693
1737
  params?: Record<string, string>
1694
1738
  }
1695
1739
 
1740
+ /**
1741
+ * Shared properties for HTTP errors (eg both ClientError and ServerError)
1742
+ * Use `isHttpError` for type narrowing and accessing response properties.
1743
+ *
1744
+ * @public
1745
+ */
1746
+ export declare interface HttpError {
1747
+ statusCode: number
1748
+ message: string
1749
+ response: {
1750
+ body: unknown
1751
+ url: string
1752
+ method: string
1753
+ headers: Record<string, string>
1754
+ statusCode: number
1755
+ statusMessage: string | null
1756
+ }
1757
+ }
1758
+
1696
1759
  /** @public */
1697
1760
  export declare type HttpRequest = {
1698
1761
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1715,7 +1778,7 @@ export declare type IdentifiedSanityDocumentStub<
1715
1778
  * @see #TransformOperation
1716
1779
  * @beta
1717
1780
  */
1718
- export declare interface ImageDescriptionOperation {
1781
+ export declare type ImageDescriptionOperation = {
1719
1782
  type: 'image-description'
1720
1783
  /**
1721
1784
  * When omitted, parent image value will be inferred from the arget path.
@@ -1726,7 +1789,32 @@ export declare interface ImageDescriptionOperation {
1726
1789
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1727
1790
  */
1728
1791
  sourcePath?: AgentActionPath
1729
- }
1792
+ } & (
1793
+ | {
1794
+ /**
1795
+ * When omitted, parent image value will be inferred from the target path.
1796
+ *
1797
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1798
+ * - `['image']`
1799
+ * - `['wrapper', 'mainImage']`
1800
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1801
+ *
1802
+ * Incompatible with `imageUrl`
1803
+ *
1804
+ */
1805
+ sourcePath?: AgentActionPath
1806
+ imageUrl?: never
1807
+ }
1808
+ | {
1809
+ /**
1810
+ * When specified, the image source to be described will be fetched from the URL.
1811
+ *
1812
+ * Incompatible with `sourcePath`
1813
+ */
1814
+ imageUrl?: `https://${string}`
1815
+ sourcePath?: never
1816
+ }
1817
+ )
1730
1818
 
1731
1819
  /** @public */
1732
1820
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -1777,6 +1865,15 @@ export declare type InsertPatch =
1777
1865
  items: Any[]
1778
1866
  }
1779
1867
 
1868
+ /**
1869
+ * Checks if the provided error is an HTTP error.
1870
+ *
1871
+ * @param error - The error to check.
1872
+ * @returns `true` if the error is an HTTP error, `false` otherwise.
1873
+ * @public
1874
+ */
1875
+ export declare function isHttpError(error: unknown): error is HttpError
1876
+
1780
1877
  /** @internal */
1781
1878
  export declare function isQueryParseError(error: object): error is QueryParseError
1782
1879
 
@@ -5557,6 +5654,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5557
5654
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5558
5655
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5559
5656
  *
5657
+ * ### Targeting images outside the document (URL)
5658
+ * If the source image is available on a https URL outside the target document, it is possible to get a description for it using `imageUrl`.
5659
+ *
5660
+ * Example:
5661
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5560
5662
  * @beta
5561
5663
  */
5562
5664
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
package/dist/index.d.ts CHANGED
@@ -698,6 +698,30 @@ export declare interface ClientConfig {
698
698
  */
699
699
  headers?: Record<string, string>
700
700
  ignoreBrowserTokenWarning?: boolean
701
+ /**
702
+ * Ignore specific warning messages from the client.
703
+ *
704
+ * @remarks
705
+ * - String values perform substring matching (not exact matching) against warning messages
706
+ * - RegExp values are tested against the full warning message
707
+ * - Array values allow multiple patterns to be specified
708
+ *
709
+ * @example
710
+ * ```typescript
711
+ * // Ignore warnings containing "experimental"
712
+ * ignoreWarnings: 'experimental'
713
+ *
714
+ * // Ignore multiple warning types
715
+ * ignoreWarnings: ['experimental', 'deprecated']
716
+ *
717
+ * // Use regex for exact matching
718
+ * ignoreWarnings: /^This is an experimental API version$/
719
+ *
720
+ * // Mix strings and regex patterns
721
+ * ignoreWarnings: ['rate limit', /^deprecated/i]
722
+ * ```
723
+ */
724
+ ignoreWarnings?: string | RegExp | Array<string | RegExp>
701
725
  withCredentials?: boolean
702
726
  allowReconfigure?: boolean
703
727
  timeout?: number
@@ -1278,6 +1302,26 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
1278
1302
  */
1279
1303
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
1280
1304
 
1305
+ /**
1306
+ * A string constant containing the experimental API version warning message.
1307
+ * Use this with the `ignoreWarnings` option to suppress warnings when using experimental API versions.
1308
+ *
1309
+ * @example
1310
+ * ```typescript
1311
+ * import { createClient, EXPERIMENTAL_API_WARNING } from '@sanity/client'
1312
+ *
1313
+ * const client = createClient({
1314
+ * projectId: 'your-project-id',
1315
+ * dataset: 'production',
1316
+ * apiVersion: 'vX', // experimental version
1317
+ * ignoreWarnings: EXPERIMENTAL_API_WARNING
1318
+ * })
1319
+ * ```
1320
+ *
1321
+ * @public
1322
+ */
1323
+ export declare const EXPERIMENTAL_API_WARNING = 'This is an experimental API version'
1324
+
1281
1325
  /**
1282
1326
  *
1283
1327
  *
@@ -1693,6 +1737,25 @@ export declare interface GroqAgentActionParam {
1693
1737
  params?: Record<string, string>
1694
1738
  }
1695
1739
 
1740
+ /**
1741
+ * Shared properties for HTTP errors (eg both ClientError and ServerError)
1742
+ * Use `isHttpError` for type narrowing and accessing response properties.
1743
+ *
1744
+ * @public
1745
+ */
1746
+ export declare interface HttpError {
1747
+ statusCode: number
1748
+ message: string
1749
+ response: {
1750
+ body: unknown
1751
+ url: string
1752
+ method: string
1753
+ headers: Record<string, string>
1754
+ statusCode: number
1755
+ statusMessage: string | null
1756
+ }
1757
+ }
1758
+
1696
1759
  /** @public */
1697
1760
  export declare type HttpRequest = {
1698
1761
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1715,7 +1778,7 @@ export declare type IdentifiedSanityDocumentStub<
1715
1778
  * @see #TransformOperation
1716
1779
  * @beta
1717
1780
  */
1718
- export declare interface ImageDescriptionOperation {
1781
+ export declare type ImageDescriptionOperation = {
1719
1782
  type: 'image-description'
1720
1783
  /**
1721
1784
  * When omitted, parent image value will be inferred from the arget path.
@@ -1726,7 +1789,32 @@ export declare interface ImageDescriptionOperation {
1726
1789
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1727
1790
  */
1728
1791
  sourcePath?: AgentActionPath
1729
- }
1792
+ } & (
1793
+ | {
1794
+ /**
1795
+ * When omitted, parent image value will be inferred from the target path.
1796
+ *
1797
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1798
+ * - `['image']`
1799
+ * - `['wrapper', 'mainImage']`
1800
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1801
+ *
1802
+ * Incompatible with `imageUrl`
1803
+ *
1804
+ */
1805
+ sourcePath?: AgentActionPath
1806
+ imageUrl?: never
1807
+ }
1808
+ | {
1809
+ /**
1810
+ * When specified, the image source to be described will be fetched from the URL.
1811
+ *
1812
+ * Incompatible with `sourcePath`
1813
+ */
1814
+ imageUrl?: `https://${string}`
1815
+ sourcePath?: never
1816
+ }
1817
+ )
1730
1818
 
1731
1819
  /** @public */
1732
1820
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -1777,6 +1865,15 @@ export declare type InsertPatch =
1777
1865
  items: Any[]
1778
1866
  }
1779
1867
 
1868
+ /**
1869
+ * Checks if the provided error is an HTTP error.
1870
+ *
1871
+ * @param error - The error to check.
1872
+ * @returns `true` if the error is an HTTP error, `false` otherwise.
1873
+ * @public
1874
+ */
1875
+ export declare function isHttpError(error: unknown): error is HttpError
1876
+
1780
1877
  /** @internal */
1781
1878
  export declare function isQueryParseError(error: object): error is QueryParseError
1782
1879
 
@@ -5557,6 +5654,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5557
5654
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5558
5655
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5559
5656
  *
5657
+ * ### Targeting images outside the document (URL)
5658
+ * If the source image is available on a https URL outside the target document, it is possible to get a description for it using `imageUrl`.
5659
+ *
5660
+ * Example:
5661
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5560
5662
  * @beta
5561
5663
  */
5562
5664
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
package/dist/index.js CHANGED
@@ -77,6 +77,12 @@ function columnToLine(column, lines) {
77
77
  };
78
78
  }
79
79
  const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
80
+ function isHttpError(error) {
81
+ if (!isRecord(error))
82
+ return !1;
83
+ const response = error.response;
84
+ return !(typeof error.statusCode != "number" || typeof error.message != "string" || !isRecord(response) || typeof response.body > "u" || typeof response.url != "string" || typeof response.method != "string" || typeof response.headers != "object" || typeof response.statusCode != "number");
85
+ }
80
86
  class ClientError extends Error {
81
87
  response;
82
88
  statusCode = 400;
@@ -177,22 +183,22 @@ const httpError = {
177
183
  return res;
178
184
  }
179
185
  };
180
- function printWarnings() {
181
- const seen = {};
186
+ function printWarnings(config = {}) {
187
+ const seen = {}, shouldIgnoreWarning = (message) => config.ignoreWarnings === void 0 ? !1 : (Array.isArray(config.ignoreWarnings) ? config.ignoreWarnings : [config.ignoreWarnings]).some((pattern) => typeof pattern == "string" ? message.includes(pattern) : pattern instanceof RegExp ? pattern.test(message) : !1);
182
188
  return {
183
189
  onResponse: (res) => {
184
190
  const warn = res.headers["x-sanity-warning"], warnings = Array.isArray(warn) ? warn : [warn];
185
191
  for (const msg of warnings)
186
- !msg || seen[msg] || (seen[msg] = !0, console.warn(msg));
192
+ !msg || seen[msg] || shouldIgnoreWarning(msg) || (seen[msg] = !0, console.warn(msg));
187
193
  return res;
188
194
  }
189
195
  };
190
196
  }
191
- function defineHttpRequest(envMiddleware) {
197
+ function defineHttpRequest(envMiddleware, config = {}) {
192
198
  return getIt([
193
199
  retry({ shouldRetry }),
194
200
  ...envMiddleware,
195
- printWarnings(),
201
+ printWarnings(config),
196
202
  jsonRequest(),
197
203
  jsonResponse(),
198
204
  progress(),
@@ -205,6 +211,7 @@ function shouldRetry(err, attempt, options) {
205
211
  const isSafe = options.method === "GET" || options.method === "HEAD", isQuery2 = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
206
212
  return (isSafe || isQuery2) && isRetriableResponse ? !0 : retry.shouldRetry(err, attempt, options);
207
213
  }
214
+ const EXPERIMENTAL_API_WARNING = "This is an experimental API version";
208
215
  class ConnectionFailedError extends Error {
209
216
  name = "ConnectionFailedError";
210
217
  }
@@ -2493,7 +2500,9 @@ class SanityClient {
2493
2500
  }
2494
2501
  function defineCreateClientExports(envMiddleware, ClassConstructor) {
2495
2502
  return { requester: defineHttpRequest(envMiddleware), createClient: (config) => {
2496
- const clientRequester = defineHttpRequest(envMiddleware);
2503
+ const clientRequester = defineHttpRequest(envMiddleware, {
2504
+ ignoreWarnings: config.ignoreWarnings
2505
+ });
2497
2506
  return new ClassConstructor(
2498
2507
  (options, requester2) => (requester2 || clientRequester)({
2499
2508
  maxRedirects: 0,
@@ -2510,7 +2519,7 @@ function defineDeprecatedCreateClient(createClient2) {
2510
2519
  return printNoDefaultExport(), createClient2(config);
2511
2520
  };
2512
2521
  }
2513
- var name = "@sanity/client", version = "7.5.0";
2522
+ var name = "@sanity/client", version = "7.7.0";
2514
2523
  const middleware = [
2515
2524
  debug({ verbose: !0, namespace: "sanity:client" }),
2516
2525
  headers({ "User-Agent": `${name} ${version}` }),
@@ -2536,6 +2545,7 @@ export {
2536
2545
  ConnectionFailedError,
2537
2546
  CorsOriginError,
2538
2547
  DisconnectError,
2548
+ EXPERIMENTAL_API_WARNING,
2539
2549
  MessageError,
2540
2550
  MessageParseError,
2541
2551
  ObservablePatch,
@@ -2549,6 +2559,7 @@ export {
2549
2559
  createClient,
2550
2560
  deprecatedCreateClient as default,
2551
2561
  formatQueryParseError,
2562
+ isHttpError,
2552
2563
  isQueryParseError,
2553
2564
  requester,
2554
2565
  adapter as unstable__adapter,