@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.
@@ -89,6 +89,12 @@ function columnToLine(column, lines) {
89
89
  };
90
90
  }
91
91
  const MAX_ITEMS_IN_ERROR_MESSAGE = 5;
92
+ function isHttpError(error) {
93
+ if (!stegaClean.isRecord(error))
94
+ return !1;
95
+ const response = error.response;
96
+ return !(typeof error.statusCode != "number" || typeof error.message != "string" || !stegaClean.isRecord(response) || typeof response.body > "u" || typeof response.url != "string" || typeof response.method != "string" || typeof response.headers != "object" || typeof response.statusCode != "number");
97
+ }
92
98
  class ClientError extends Error {
93
99
  response;
94
100
  statusCode = 400;
@@ -189,22 +195,22 @@ const httpError = {
189
195
  return res;
190
196
  }
191
197
  };
192
- function printWarnings() {
193
- const seen = {};
198
+ function printWarnings(config = {}) {
199
+ 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);
194
200
  return {
195
201
  onResponse: (res) => {
196
202
  const warn = res.headers["x-sanity-warning"], warnings = Array.isArray(warn) ? warn : [warn];
197
203
  for (const msg of warnings)
198
- !msg || seen[msg] || (seen[msg] = !0, console.warn(msg));
204
+ !msg || seen[msg] || shouldIgnoreWarning(msg) || (seen[msg] = !0, console.warn(msg));
199
205
  return res;
200
206
  }
201
207
  };
202
208
  }
203
- function defineHttpRequest(envMiddleware2) {
209
+ function defineHttpRequest(envMiddleware2, config = {}) {
204
210
  return getIt.getIt([
205
211
  middleware.retry({ shouldRetry }),
206
212
  ...envMiddleware2,
207
- printWarnings(),
213
+ printWarnings(config),
208
214
  middleware.jsonRequest(),
209
215
  middleware.jsonResponse(),
210
216
  middleware.progress(),
@@ -294,7 +300,7 @@ const VALID_ASSET_TYPES = ["image", "file"], VALID_INSERT_LOCATIONS = ["before",
294
300
  }, resourceGuard = (service, config) => {
295
301
  if (config["~experimental_resource"])
296
302
  throw new Error(`\`${service}\` does not support resource-based operations`);
297
- };
303
+ }, EXPERIMENTAL_API_WARNING = "This is an experimental API version";
298
304
  function once(fn) {
299
305
  let didCall = !1, returnValue;
300
306
  return (...args) => (didCall || (returnValue = fn(...args), didCall = !0), returnValue);
@@ -2677,7 +2683,9 @@ class SanityClient {
2677
2683
  }
2678
2684
  function defineCreateClientExports(envMiddleware2, ClassConstructor) {
2679
2685
  return { requester: defineHttpRequest(envMiddleware2), createClient: (config) => {
2680
- const clientRequester = defineHttpRequest(envMiddleware2);
2686
+ const clientRequester = defineHttpRequest(envMiddleware2, {
2687
+ ignoreWarnings: config.ignoreWarnings
2688
+ });
2681
2689
  return new ClassConstructor(
2682
2690
  (options, requester2) => (requester2 || clientRequester)({
2683
2691
  maxRedirects: 0,
@@ -2715,6 +2723,7 @@ exports.ClientError = ClientError;
2715
2723
  exports.ConnectionFailedError = ConnectionFailedError;
2716
2724
  exports.CorsOriginError = CorsOriginError;
2717
2725
  exports.DisconnectError = DisconnectError;
2726
+ exports.EXPERIMENTAL_API_WARNING = EXPERIMENTAL_API_WARNING;
2718
2727
  exports.MessageError = MessageError;
2719
2728
  exports.MessageParseError = MessageParseError;
2720
2729
  exports.ObservablePatch = ObservablePatch;
@@ -2728,6 +2737,7 @@ exports.connectEventSource = connectEventSource;
2728
2737
  exports.createClient = createClient;
2729
2738
  exports.default = deprecatedCreateClient;
2730
2739
  exports.formatQueryParseError = formatQueryParseError;
2740
+ exports.isHttpError = isHttpError;
2731
2741
  exports.isQueryParseError = isQueryParseError;
2732
2742
  exports.requester = requester;
2733
2743
  exports.validateApiPerspective = validateApiPerspective;