@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.
@@ -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
@@ -1274,6 +1298,26 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
1274
1298
  */
1275
1299
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
1276
1300
 
1301
+ /**
1302
+ * A string constant containing the experimental API version warning message.
1303
+ * Use this with the `ignoreWarnings` option to suppress warnings when using experimental API versions.
1304
+ *
1305
+ * @example
1306
+ * ```typescript
1307
+ * import { createClient, EXPERIMENTAL_API_WARNING } from '@sanity/client'
1308
+ *
1309
+ * const client = createClient({
1310
+ * projectId: 'your-project-id',
1311
+ * dataset: 'production',
1312
+ * apiVersion: 'vX', // experimental version
1313
+ * ignoreWarnings: EXPERIMENTAL_API_WARNING
1314
+ * })
1315
+ * ```
1316
+ *
1317
+ * @public
1318
+ */
1319
+ export declare const EXPERIMENTAL_API_WARNING = 'This is an experimental API version'
1320
+
1277
1321
  /**
1278
1322
  *
1279
1323
  *
@@ -1689,6 +1733,25 @@ export declare interface GroqAgentActionParam {
1689
1733
  params?: Record<string, string>
1690
1734
  }
1691
1735
 
1736
+ /**
1737
+ * Shared properties for HTTP errors (eg both ClientError and ServerError)
1738
+ * Use `isHttpError` for type narrowing and accessing response properties.
1739
+ *
1740
+ * @public
1741
+ */
1742
+ export declare interface HttpError {
1743
+ statusCode: number
1744
+ message: string
1745
+ response: {
1746
+ body: unknown
1747
+ url: string
1748
+ method: string
1749
+ headers: Record<string, string>
1750
+ statusCode: number
1751
+ statusMessage: string | null
1752
+ }
1753
+ }
1754
+
1692
1755
  /** @public */
1693
1756
  export declare type HttpRequest = {
1694
1757
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1711,7 +1774,7 @@ export declare type IdentifiedSanityDocumentStub<
1711
1774
  * @see #TransformOperation
1712
1775
  * @beta
1713
1776
  */
1714
- export declare interface ImageDescriptionOperation {
1777
+ export declare type ImageDescriptionOperation = {
1715
1778
  type: 'image-description'
1716
1779
  /**
1717
1780
  * When omitted, parent image value will be inferred from the arget path.
@@ -1722,7 +1785,32 @@ export declare interface ImageDescriptionOperation {
1722
1785
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1723
1786
  */
1724
1787
  sourcePath?: AgentActionPath
1725
- }
1788
+ } & (
1789
+ | {
1790
+ /**
1791
+ * When omitted, parent image value will be inferred from the target path.
1792
+ *
1793
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1794
+ * - `['image']`
1795
+ * - `['wrapper', 'mainImage']`
1796
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1797
+ *
1798
+ * Incompatible with `imageUrl`
1799
+ *
1800
+ */
1801
+ sourcePath?: AgentActionPath
1802
+ imageUrl?: never
1803
+ }
1804
+ | {
1805
+ /**
1806
+ * When specified, the image source to be described will be fetched from the URL.
1807
+ *
1808
+ * Incompatible with `sourcePath`
1809
+ */
1810
+ imageUrl?: `https://${string}`
1811
+ sourcePath?: never
1812
+ }
1813
+ )
1726
1814
 
1727
1815
  /** @public */
1728
1816
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -1773,6 +1861,15 @@ export declare type InsertPatch =
1773
1861
  items: Any[]
1774
1862
  }
1775
1863
 
1864
+ /**
1865
+ * Checks if the provided error is an HTTP error.
1866
+ *
1867
+ * @param error - The error to check.
1868
+ * @returns `true` if the error is an HTTP error, `false` otherwise.
1869
+ * @public
1870
+ */
1871
+ export declare function isHttpError(error: unknown): error is HttpError
1872
+
1776
1873
  /** @internal */
1777
1874
  export declare function isQueryParseError(error: object): error is QueryParseError
1778
1875
 
@@ -5553,6 +5650,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5553
5650
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5554
5651
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5555
5652
  *
5653
+ * ### Targeting images outside the document (URL)
5654
+ * 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`.
5655
+ *
5656
+ * Example:
5657
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5556
5658
  * @beta
5557
5659
  */
5558
5660
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
@@ -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
@@ -1274,6 +1298,26 @@ export declare type EventSourceEvent<Name extends string> = ServerSentEvent<Name
1274
1298
  */
1275
1299
  export declare type EventSourceInstance = InstanceType<typeof globalThis.EventSource>
1276
1300
 
1301
+ /**
1302
+ * A string constant containing the experimental API version warning message.
1303
+ * Use this with the `ignoreWarnings` option to suppress warnings when using experimental API versions.
1304
+ *
1305
+ * @example
1306
+ * ```typescript
1307
+ * import { createClient, EXPERIMENTAL_API_WARNING } from '@sanity/client'
1308
+ *
1309
+ * const client = createClient({
1310
+ * projectId: 'your-project-id',
1311
+ * dataset: 'production',
1312
+ * apiVersion: 'vX', // experimental version
1313
+ * ignoreWarnings: EXPERIMENTAL_API_WARNING
1314
+ * })
1315
+ * ```
1316
+ *
1317
+ * @public
1318
+ */
1319
+ export declare const EXPERIMENTAL_API_WARNING = 'This is an experimental API version'
1320
+
1277
1321
  /**
1278
1322
  *
1279
1323
  *
@@ -1689,6 +1733,25 @@ export declare interface GroqAgentActionParam {
1689
1733
  params?: Record<string, string>
1690
1734
  }
1691
1735
 
1736
+ /**
1737
+ * Shared properties for HTTP errors (eg both ClientError and ServerError)
1738
+ * Use `isHttpError` for type narrowing and accessing response properties.
1739
+ *
1740
+ * @public
1741
+ */
1742
+ export declare interface HttpError {
1743
+ statusCode: number
1744
+ message: string
1745
+ response: {
1746
+ body: unknown
1747
+ url: string
1748
+ method: string
1749
+ headers: Record<string, string>
1750
+ statusCode: number
1751
+ statusMessage: string | null
1752
+ }
1753
+ }
1754
+
1692
1755
  /** @public */
1693
1756
  export declare type HttpRequest = {
1694
1757
  (options: RequestOptions, requester: Requester): ReturnType<Requester>
@@ -1711,7 +1774,7 @@ export declare type IdentifiedSanityDocumentStub<
1711
1774
  * @see #TransformOperation
1712
1775
  * @beta
1713
1776
  */
1714
- export declare interface ImageDescriptionOperation {
1777
+ export declare type ImageDescriptionOperation = {
1715
1778
  type: 'image-description'
1716
1779
  /**
1717
1780
  * When omitted, parent image value will be inferred from the arget path.
@@ -1722,7 +1785,32 @@ export declare interface ImageDescriptionOperation {
1722
1785
  * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1723
1786
  */
1724
1787
  sourcePath?: AgentActionPath
1725
- }
1788
+ } & (
1789
+ | {
1790
+ /**
1791
+ * When omitted, parent image value will be inferred from the target path.
1792
+ *
1793
+ * When specified, the `sourcePath` should be a path to an image (or image asset) field:
1794
+ * - `['image']`
1795
+ * - `['wrapper', 'mainImage']`
1796
+ * - `['heroImage', 'asset'] // the asset segment is optional, but supported`
1797
+ *
1798
+ * Incompatible with `imageUrl`
1799
+ *
1800
+ */
1801
+ sourcePath?: AgentActionPath
1802
+ imageUrl?: never
1803
+ }
1804
+ | {
1805
+ /**
1806
+ * When specified, the image source to be described will be fetched from the URL.
1807
+ *
1808
+ * Incompatible with `sourcePath`
1809
+ */
1810
+ imageUrl?: `https://${string}`
1811
+ sourcePath?: never
1812
+ }
1813
+ )
1726
1814
 
1727
1815
  /** @public */
1728
1816
  export declare interface InitializedClientConfig extends ClientConfig {
@@ -1773,6 +1861,15 @@ export declare type InsertPatch =
1773
1861
  items: Any[]
1774
1862
  }
1775
1863
 
1864
+ /**
1865
+ * Checks if the provided error is an HTTP error.
1866
+ *
1867
+ * @param error - The error to check.
1868
+ * @returns `true` if the error is an HTTP error, `false` otherwise.
1869
+ * @public
1870
+ */
1871
+ export declare function isHttpError(error: unknown): error is HttpError
1872
+
1776
1873
  /** @internal */
1777
1874
  export declare function isQueryParseError(error: object): error is QueryParseError
1778
1875
 
@@ -5553,6 +5650,11 @@ declare type TransformDocumentSync<T extends Record<string, Any> = Record<string
5553
5650
  * - `target: {path: ['wrapper', 'title'], operation: {type: 'image-description', sourcePath: ['array', {_key: 'abc'}, 'image'] }`
5554
5651
  * - `target: {path: ['wrapper'], include: ['portableTextField'], operation: {type: 'image-description', sourcePath: ['image', 'asset'] }, instruction: 'Use formatting and headings to describe the image in great detail' }`
5555
5652
  *
5653
+ * ### Targeting images outside the document (URL)
5654
+ * 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`.
5655
+ *
5656
+ * Example:
5657
+ * - `target: {path: ['description'], operation: operation: {type: 'image-description', imageUrL: 'https://www.sanity.io/static/images/favicons/android-icon-192x192.png?v=2' }`
5556
5658
  * @beta
5557
5659
  */
5558
5660
  export declare type TransformOperation = 'set' | ImageDescriptionOperation
@@ -75,6 +75,12 @@ function columnToLine(column, lines) {
75
75
  };
76
76
  }
77
77
  const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
78
+ function isHttpError(error) {
79
+ if (!isRecord(error))
80
+ return !1;
81
+ const response = error.response;
82
+ 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");
83
+ }
78
84
  class ClientError extends Error {
79
85
  response;
80
86
  statusCode = 400;
@@ -175,22 +181,22 @@ const httpError = {
175
181
  return res;
176
182
  }
177
183
  };
178
- function printWarnings() {
179
- const seen = {};
184
+ function printWarnings(config = {}) {
185
+ 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);
180
186
  return {
181
187
  onResponse: (res) => {
182
188
  const warn = res.headers["x-sanity-warning"], warnings = Array.isArray(warn) ? warn : [warn];
183
189
  for (const msg of warnings)
184
- !msg || seen[msg] || (seen[msg] = !0, console.warn(msg));
190
+ !msg || seen[msg] || shouldIgnoreWarning(msg) || (seen[msg] = !0, console.warn(msg));
185
191
  return res;
186
192
  }
187
193
  };
188
194
  }
189
- function defineHttpRequest(envMiddleware2) {
195
+ function defineHttpRequest(envMiddleware2, config = {}) {
190
196
  return getIt([
191
197
  retry({ shouldRetry }),
192
198
  ...envMiddleware2,
193
- printWarnings(),
199
+ printWarnings(config),
194
200
  jsonRequest(),
195
201
  jsonResponse(),
196
202
  progress(),
@@ -280,7 +286,7 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
280
286
  }, resourceGuard = (service, config) => {
281
287
  if (config["~experimental_resource"])
282
288
  throw new Error(`\`${service}\` does not support resource-based operations`);
283
- };
289
+ }, EXPERIMENTAL_API_WARNING = "This is an experimental API version";
284
290
  function once(fn) {
285
291
  let didCall = !1, returnValue;
286
292
  return (...args) => (didCall || (returnValue = fn(...args), didCall = !0), returnValue);
@@ -2661,7 +2667,9 @@ class SanityClient {
2661
2667
  }
2662
2668
  function defineCreateClientExports(envMiddleware2, ClassConstructor) {
2663
2669
  return { requester: defineHttpRequest(envMiddleware2), createClient: (config) => {
2664
- const clientRequester = defineHttpRequest(envMiddleware2);
2670
+ const clientRequester = defineHttpRequest(envMiddleware2, {
2671
+ ignoreWarnings: config.ignoreWarnings
2672
+ });
2665
2673
  return new ClassConstructor(
2666
2674
  (options, requester2) => (requester2 || clientRequester)({
2667
2675
  maxRedirects: 0,
@@ -2688,6 +2696,7 @@ export {
2688
2696
  ConnectionFailedError,
2689
2697
  CorsOriginError,
2690
2698
  DisconnectError,
2699
+ EXPERIMENTAL_API_WARNING,
2691
2700
  MessageError,
2692
2701
  MessageParseError,
2693
2702
  ObservablePatch,
@@ -2701,6 +2710,7 @@ export {
2701
2710
  createClient,
2702
2711
  deprecatedCreateClient as default,
2703
2712
  formatQueryParseError,
2713
+ isHttpError,
2704
2714
  isQueryParseError,
2705
2715
  requester,
2706
2716
  adapter as unstable__adapter,