@sanity/client 7.6.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>
@@ -1798,6 +1861,15 @@ export declare type InsertPatch =
1798
1861
  items: Any[]
1799
1862
  }
1800
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
+
1801
1873
  /** @internal */
1802
1874
  export declare function isQueryParseError(error: object): error is QueryParseError
1803
1875
 
@@ -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>
@@ -1798,6 +1861,15 @@ export declare type InsertPatch =
1798
1861
  items: Any[]
1799
1862
  }
1800
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
+
1801
1873
  /** @internal */
1802
1874
  export declare function isQueryParseError(error: object): error is QueryParseError
1803
1875
 
@@ -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,