@sanity/client 3.3.3-esm.6 → 3.3.3-esm.7

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.
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __esm = (fn, res) => function __init() {
8
6
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
@@ -22,82 +20,8 @@ var __copyProps = (to, from, except, desc) => {
22
20
  }
23
21
  return to;
24
22
  };
25
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
24
 
31
- // node_modules/object-assign/index.js
32
- var require_object_assign = __commonJS({
33
- "node_modules/object-assign/index.js"(exports, module) {
34
- "use strict";
35
- var getOwnPropertySymbols = Object.getOwnPropertySymbols;
36
- var hasOwnProperty = Object.prototype.hasOwnProperty;
37
- var propIsEnumerable = Object.prototype.propertyIsEnumerable;
38
- function toObject(val) {
39
- if (val === null || val === void 0) {
40
- throw new TypeError("Object.assign cannot be called with null or undefined");
41
- }
42
- return Object(val);
43
- }
44
- function shouldUseNative() {
45
- try {
46
- if (!Object.assign) {
47
- return false;
48
- }
49
- var test1 = new String("abc");
50
- test1[5] = "de";
51
- if (Object.getOwnPropertyNames(test1)[0] === "5") {
52
- return false;
53
- }
54
- var test2 = {};
55
- for (var i = 0; i < 10; i++) {
56
- test2["_" + String.fromCharCode(i)] = i;
57
- }
58
- var order2 = Object.getOwnPropertyNames(test2).map(function(n) {
59
- return test2[n];
60
- });
61
- if (order2.join("") !== "0123456789") {
62
- return false;
63
- }
64
- var test3 = {};
65
- "abcdefghijklmnopqrst".split("").forEach(function(letter) {
66
- test3[letter] = letter;
67
- });
68
- if (Object.keys(Object.assign({}, test3)).join("") !== "abcdefghijklmnopqrst") {
69
- return false;
70
- }
71
- return true;
72
- } catch (err) {
73
- return false;
74
- }
75
- }
76
- module.exports = shouldUseNative() ? Object.assign : function(target, source) {
77
- var from;
78
- var to = toObject(target);
79
- var symbols;
80
- for (var s = 1; s < arguments.length; s++) {
81
- from = Object(arguments[s]);
82
- for (var key in from) {
83
- if (hasOwnProperty.call(from, key)) {
84
- to[key] = from[key];
85
- }
86
- }
87
- if (getOwnPropertySymbols) {
88
- symbols = getOwnPropertySymbols(from);
89
- for (var i = 0; i < symbols.length; i++) {
90
- if (propIsEnumerable.call(from, symbols[i])) {
91
- to[symbols[i]] = from[symbols[i]];
92
- }
93
- }
94
- }
95
- }
96
- return to;
97
- };
98
- }
99
- });
100
-
101
25
  // src/util/observable-modern.js
102
26
  var observable_modern_exports = {};
103
27
  __export(observable_modern_exports, {
@@ -114,66 +38,83 @@ var init_observable_modern = __esm({
114
38
  });
115
39
 
116
40
  // src/util/getSelection.js
117
- var require_getSelection = __commonJS({
118
- "src/util/getSelection.js"(exports, module) {
119
- module.exports = function getSelection(sel) {
120
- if (typeof sel === "string" || Array.isArray(sel)) {
121
- return { id: sel };
122
- }
123
- if (sel && sel.query) {
124
- return "params" in sel ? { query: sel.query, params: sel.params } : { query: sel.query };
125
- }
126
- const selectionOpts = [
127
- "* Document ID (<docId>)",
128
- "* Array of document IDs",
129
- "* Object containing `query`"
130
- ].join("\n");
131
- throw new Error(`Unknown selection - must be one of:
41
+ var getSelection_exports = {};
42
+ __export(getSelection_exports, {
43
+ default: () => getSelection
44
+ });
45
+ function getSelection(sel) {
46
+ if (typeof sel === "string" || Array.isArray(sel)) {
47
+ return { id: sel };
48
+ }
49
+ if (sel && sel.query) {
50
+ return "params" in sel ? { query: sel.query, params: sel.params } : { query: sel.query };
51
+ }
52
+ const selectionOpts = [
53
+ "* Document ID (<docId>)",
54
+ "* Array of document IDs",
55
+ "* Object containing `query`"
56
+ ].join("\n");
57
+ throw new Error(`Unknown selection - must be one of:
132
58
 
133
59
  ${selectionOpts}`);
134
- };
60
+ }
61
+ var init_getSelection = __esm({
62
+ "src/util/getSelection.js"() {
135
63
  }
136
64
  });
137
65
 
138
66
  // src/validators.js
139
- var require_validators = __commonJS({
140
- "src/validators.js"(exports) {
141
- var VALID_ASSET_TYPES = ["image", "file"];
142
- var VALID_INSERT_LOCATIONS = ["before", "after", "replace"];
143
- exports.dataset = (name) => {
67
+ var validators_exports = {};
68
+ __export(validators_exports, {
69
+ dataset: () => dataset,
70
+ hasDataset: () => hasDataset,
71
+ projectId: () => projectId,
72
+ requestTag: () => requestTag,
73
+ requireDocumentId: () => requireDocumentId,
74
+ validateAssetType: () => validateAssetType,
75
+ validateDocumentId: () => validateDocumentId,
76
+ validateInsert: () => validateInsert,
77
+ validateObject: () => validateObject
78
+ });
79
+ var VALID_ASSET_TYPES, VALID_INSERT_LOCATIONS, dataset, projectId, validateAssetType, validateObject, validateDocumentId, requireDocumentId, validateInsert, hasDataset, requestTag;
80
+ var init_validators = __esm({
81
+ "src/validators.js"() {
82
+ VALID_ASSET_TYPES = ["image", "file"];
83
+ VALID_INSERT_LOCATIONS = ["before", "after", "replace"];
84
+ dataset = (name) => {
144
85
  if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
145
86
  throw new Error(
146
87
  "Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters"
147
88
  );
148
89
  }
149
90
  };
150
- exports.projectId = (id) => {
91
+ projectId = (id) => {
151
92
  if (!/^[-a-z0-9]+$/i.test(id)) {
152
93
  throw new Error("`projectId` can only contain only a-z, 0-9 and dashes");
153
94
  }
154
95
  };
155
- exports.validateAssetType = (type) => {
96
+ validateAssetType = (type) => {
156
97
  if (VALID_ASSET_TYPES.indexOf(type) === -1) {
157
98
  throw new Error(`Invalid asset type: ${type}. Must be one of ${VALID_ASSET_TYPES.join(", ")}`);
158
99
  }
159
100
  };
160
- exports.validateObject = (op, val) => {
101
+ validateObject = (op, val) => {
161
102
  if (val === null || typeof val !== "object" || Array.isArray(val)) {
162
103
  throw new Error(`${op}() takes an object of properties`);
163
104
  }
164
105
  };
165
- exports.requireDocumentId = (op, doc) => {
166
- if (!doc._id) {
167
- throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
168
- }
169
- exports.validateDocumentId(op, doc._id);
170
- };
171
- exports.validateDocumentId = (op, id) => {
106
+ validateDocumentId = (op, id) => {
172
107
  if (typeof id !== "string" || !/^[a-z0-9_.-]+$/i.test(id)) {
173
108
  throw new Error(`${op}(): "${id}" is not a valid document ID`);
174
109
  }
175
110
  };
176
- exports.validateInsert = (at, selector, items) => {
111
+ requireDocumentId = (op, doc) => {
112
+ if (!doc._id) {
113
+ throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
114
+ }
115
+ validateDocumentId(op, doc._id);
116
+ };
117
+ validateInsert = (at, selector, items) => {
177
118
  const signature = "insert(at, selector, items)";
178
119
  if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
179
120
  const valid = VALID_INSERT_LOCATIONS.map((loc) => `"${loc}"`).join(", ");
@@ -186,13 +127,13 @@ var require_validators = __commonJS({
186
127
  throw new Error(`${signature} takes an "items"-argument which must be an array`);
187
128
  }
188
129
  };
189
- exports.hasDataset = (config) => {
130
+ hasDataset = (config) => {
190
131
  if (!config.dataset) {
191
132
  throw new Error("`dataset` must be provided to perform queries");
192
133
  }
193
134
  return config.dataset || "";
194
135
  };
195
- exports.requestTag = (tag) => {
136
+ requestTag = (tag) => {
196
137
  if (typeof tag !== "string" || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
197
138
  throw new Error(
198
139
  `Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.`
@@ -206,10 +147,10 @@ var require_validators = __commonJS({
206
147
  // src/data/patch.js
207
148
  var require_patch = __commonJS({
208
149
  "src/data/patch.js"(exports, module) {
209
- var getSelection = require_getSelection();
210
- var validate2 = require_validators();
211
- var validateObject = validate2.validateObject;
212
- var validateInsert = validate2.validateInsert;
150
+ var getSelection2 = (init_getSelection(), __toCommonJS(getSelection_exports));
151
+ var validate = (init_validators(), __toCommonJS(validators_exports));
152
+ var validateObject2 = validate.validateObject;
153
+ var validateInsert2 = validate.validateInsert;
213
154
  function Patch(selection, operations = {}, client = null) {
214
155
  this.selection = selection;
215
156
  this.operations = Object.assign({}, operations);
@@ -223,7 +164,7 @@ var require_patch = __commonJS({
223
164
  return this.assign("set", props);
224
165
  },
225
166
  diffMatchPatch(props) {
226
- validateObject("diffMatchPatch", props);
167
+ validateObject2("diffMatchPatch", props);
227
168
  return this.assign("diffMatchPatch", props);
228
169
  },
229
170
  unset(attrs) {
@@ -237,7 +178,7 @@ var require_patch = __commonJS({
237
178
  return this.assign("setIfMissing", props);
238
179
  },
239
180
  replace(props) {
240
- validateObject("replace", props);
181
+ validateObject2("replace", props);
241
182
  return this._set("set", { $: props });
242
183
  },
243
184
  inc(props) {
@@ -247,7 +188,7 @@ var require_patch = __commonJS({
247
188
  return this.assign("dec", props);
248
189
  },
249
190
  insert(at, selector, items) {
250
- validateInsert(at, selector, items);
191
+ validateInsert2(at, selector, items);
251
192
  return this.assign("insert", { [at]: selector, items });
252
193
  },
253
194
  append(selector, items) {
@@ -269,7 +210,7 @@ var require_patch = __commonJS({
269
210
  return this;
270
211
  },
271
212
  serialize() {
272
- return Object.assign(getSelection(this.selection), this.operations);
213
+ return Object.assign(getSelection2(this.selection), this.operations);
273
214
  },
274
215
  toJSON() {
275
216
  return this.serialize();
@@ -292,7 +233,7 @@ var require_patch = __commonJS({
292
233
  return this.assign(op, props, false);
293
234
  },
294
235
  assign(op, props, merge = true) {
295
- validateObject(op, props);
236
+ validateObject2(op, props);
296
237
  this.operations = Object.assign({}, this.operations, {
297
238
  [op]: Object.assign({}, merge && this.operations[op] || {}, props)
298
239
  });
@@ -306,7 +247,7 @@ var require_patch = __commonJS({
306
247
  // src/data/transaction.js
307
248
  var require_transaction = __commonJS({
308
249
  "src/data/transaction.js"(exports, module) {
309
- var validators = require_validators();
250
+ var validators = (init_validators(), __toCommonJS(validators_exports));
310
251
  var Patch = require_patch();
311
252
  var defaultMutateOptions = { returnDocuments: false };
312
253
  function Transaction(operations = [], client, transactionId) {
@@ -391,10 +332,15 @@ var require_transaction = __commonJS({
391
332
  });
392
333
 
393
334
  // src/data/encodeQueryString.js
394
- var require_encodeQueryString = __commonJS({
395
- "src/data/encodeQueryString.js"(exports, module) {
396
- var enc = encodeURIComponent;
397
- module.exports = ({ query, params = {}, options = {} }) => {
335
+ var encodeQueryString_exports = {};
336
+ __export(encodeQueryString_exports, {
337
+ default: () => encodeQueryString_default
338
+ });
339
+ var enc, encodeQueryString_default;
340
+ var init_encodeQueryString = __esm({
341
+ "src/data/encodeQueryString.js"() {
342
+ enc = encodeURIComponent;
343
+ encodeQueryString_default = ({ query, params = {}, options = {} }) => {
398
344
  const { tag, ...opts } = options;
399
345
  const q = `query=${enc(query)}`;
400
346
  const base = tag ? `?tag=${enc(tag)}&${q}` : `?${q}`;
@@ -410,9 +356,14 @@ var require_encodeQueryString = __commonJS({
410
356
  });
411
357
 
412
358
  // src/util/pick.js
413
- var require_pick = __commonJS({
414
- "src/util/pick.js"(exports, module) {
415
- module.exports = (obj, props) => props.reduce((selection, prop) => {
359
+ var pick_exports = {};
360
+ __export(pick_exports, {
361
+ default: () => pick_default
362
+ });
363
+ var pick_default;
364
+ var init_pick = __esm({
365
+ "src/util/pick.js"() {
366
+ pick_default = (obj, props) => props.reduce((selection, prop) => {
416
367
  if (typeof obj[prop] === "undefined") {
417
368
  return selection;
418
369
  }
@@ -423,9 +374,14 @@ var require_pick = __commonJS({
423
374
  });
424
375
 
425
376
  // src/util/defaults.js
426
- var require_defaults = __commonJS({
427
- "src/util/defaults.js"(exports, module) {
428
- module.exports = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj)).reduce((target, prop) => {
377
+ var defaults_exports = {};
378
+ __export(defaults_exports, {
379
+ default: () => defaults_default
380
+ });
381
+ var defaults_default;
382
+ var init_defaults = __esm({
383
+ "src/util/defaults.js"() {
384
+ defaults_default = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj)).reduce((target, prop) => {
429
385
  target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
430
386
  return target;
431
387
  }, {});
@@ -437,9 +393,9 @@ import polyfilledEventSource from "@sanity/eventsource";
437
393
  var require_listen = __commonJS({
438
394
  "src/data/listen.js"(exports, module) {
439
395
  var { Observable: Observable2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
440
- var pick = require_pick();
441
- var defaults = require_defaults();
442
- var encodeQueryString = require_encodeQueryString();
396
+ var pick = (init_pick(), __toCommonJS(pick_exports));
397
+ var defaults = (init_defaults(), __toCommonJS(defaults_exports));
398
+ var encodeQueryString = (init_encodeQueryString(), __toCommonJS(encodeQueryString_exports));
443
399
  var MAX_URL_LENGTH = 16e3 - 1200;
444
400
  var EventSource = polyfilledEventSource;
445
401
  var possibleOptions = [
@@ -564,9 +520,9 @@ var require_listen = __commonJS({
564
520
  var require_dataMethods = __commonJS({
565
521
  "src/data/dataMethods.js"(exports, module) {
566
522
  var { map: map2, filter: filter2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
567
- var validators = require_validators();
568
- var getSelection = require_getSelection();
569
- var encodeQueryString = require_encodeQueryString();
523
+ var validators = (init_validators(), __toCommonJS(validators_exports));
524
+ var getSelection2 = (init_getSelection(), __toCommonJS(getSelection_exports));
525
+ var encodeQueryString = (init_encodeQueryString(), __toCommonJS(encodeQueryString_exports));
570
526
  var Transaction = require_transaction();
571
527
  var Patch = require_patch();
572
528
  var listen = require_listen();
@@ -640,7 +596,7 @@ var require_dataMethods = __commonJS({
640
596
  return new Patch(selector, operations, this);
641
597
  },
642
598
  delete(selection, options) {
643
- return this.dataRequest("mutate", { mutations: [{ delete: getSelection(selection) }] }, options);
599
+ return this.dataRequest("mutate", { mutations: [{ delete: getSelection2(selection) }] }, options);
644
600
  },
645
601
  mutate(mutations, options) {
646
602
  const mut = mutations instanceof Patch || mutations instanceof Transaction ? mutations.serialize() : mutations;
@@ -652,8 +608,8 @@ var require_dataMethods = __commonJS({
652
608
  return new Transaction(operations, this);
653
609
  },
654
610
  dataRequest(endpoint, body, options = {}) {
655
- const request = this._dataRequest(endpoint, body, options);
656
- return this.isPromiseAPI() ? toPromise(request) : request;
611
+ const request2 = this._dataRequest(endpoint, body, options);
612
+ return this.isPromiseAPI() ? toPromise(request2) : request2;
657
613
  },
658
614
  _dataRequest(endpoint, body, options = {}) {
659
615
  const isMutation = endpoint === "mutate";
@@ -709,7 +665,7 @@ var require_dataMethods = __commonJS({
709
665
  // src/datasets/datasetsClient.js
710
666
  var require_datasetsClient = __commonJS({
711
667
  "src/datasets/datasetsClient.js"(exports, module) {
712
- var validate2 = require_validators();
668
+ var validate = (init_validators(), __toCommonJS(validators_exports));
713
669
  function DatasetsClient(client) {
714
670
  this.request = client.request.bind(client);
715
671
  }
@@ -727,7 +683,7 @@ var require_datasetsClient = __commonJS({
727
683
  return this.request({ uri: "/datasets" });
728
684
  },
729
685
  _modify(method, name, body) {
730
- validate2.dataset(name);
686
+ validate.dataset(name);
731
687
  return this.request({ method, uri: `/datasets/${name}`, body });
732
688
  }
733
689
  });
@@ -736,11 +692,16 @@ var require_datasetsClient = __commonJS({
736
692
  });
737
693
 
738
694
  // src/projects/projectsClient.js
739
- var require_projectsClient = __commonJS({
740
- "src/projects/projectsClient.js"(exports, module) {
741
- function ProjectsClient(client) {
742
- this.client = client;
743
- }
695
+ var projectsClient_exports = {};
696
+ __export(projectsClient_exports, {
697
+ default: () => projectsClient_default
698
+ });
699
+ function ProjectsClient(client) {
700
+ this.client = client;
701
+ }
702
+ var projectsClient_default;
703
+ var init_projectsClient = __esm({
704
+ "src/projects/projectsClient.js"() {
744
705
  Object.assign(ProjectsClient.prototype, {
745
706
  list() {
746
707
  return this.client.request({ uri: "/projects" });
@@ -749,14 +710,19 @@ var require_projectsClient = __commonJS({
749
710
  return this.client.request({ uri: `/projects/${id}` });
750
711
  }
751
712
  });
752
- module.exports = ProjectsClient;
713
+ projectsClient_default = ProjectsClient;
753
714
  }
754
715
  });
755
716
 
756
717
  // src/http/queryString.js
757
- var require_queryString = __commonJS({
758
- "src/http/queryString.js"(exports, module) {
759
- module.exports = (params) => {
718
+ var queryString_exports = {};
719
+ __export(queryString_exports, {
720
+ default: () => queryString_default
721
+ });
722
+ var queryString_default;
723
+ var init_queryString = __esm({
724
+ "src/http/queryString.js"() {
725
+ queryString_default = (params) => {
760
726
  const qs = [];
761
727
  for (const key in params) {
762
728
  if (params.hasOwnProperty(key)) {
@@ -772,8 +738,8 @@ var require_queryString = __commonJS({
772
738
  var require_assetsClient = __commonJS({
773
739
  "src/assets/assetsClient.js"(exports, module) {
774
740
  var { map: map2, filter: filter2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
775
- var queryString = require_queryString();
776
- var validators = require_validators();
741
+ var queryString = (init_queryString(), __toCommonJS(queryString_exports));
742
+ var validators = (init_validators(), __toCommonJS(validators_exports));
777
743
  function AssetsClient(client) {
778
744
  this.client = client;
779
745
  }
@@ -796,7 +762,7 @@ var require_assetsClient = __commonJS({
796
762
  if (meta && !meta.length) {
797
763
  meta = ["none"];
798
764
  }
799
- const dataset = validators.hasDataset(this.client.clientConfig);
765
+ const dataset2 = validators.hasDataset(this.client.clientConfig);
800
766
  const assetEndpoint = assetType === "image" ? "images" : "files";
801
767
  const options = optionsFromFile(opts, body);
802
768
  const { tag, label, title, description, creditLine, filename, source } = options;
@@ -817,7 +783,7 @@ var require_assetsClient = __commonJS({
817
783
  tag,
818
784
  method: "POST",
819
785
  timeout: options.timeout || 0,
820
- uri: `/assets/${assetEndpoint}/${dataset}`,
786
+ uri: `/assets/${assetEndpoint}/${dataset2}`,
821
787
  headers: options.contentType ? { "Content-Type": options.contentType } : {},
822
788
  query,
823
789
  body
@@ -852,9 +818,9 @@ var require_assetsClient = __commonJS({
852
818
  }
853
819
  const [, assetId, size, format] = id.split("-");
854
820
  validators.hasDataset(this.client.clientConfig);
855
- const { projectId, dataset } = this.client.clientConfig;
821
+ const { projectId: projectId2, dataset: dataset2 } = this.client.clientConfig;
856
822
  const qs = query ? queryString(query) : "";
857
- return `https://cdn.sanity.io/images/${projectId}/${dataset}/${assetId}-${size}.${format}${qs}`;
823
+ return `https://cdn.sanity.io/images/${projectId2}/${dataset2}/${assetId}-${size}.${format}${qs}`;
858
824
  }
859
825
  });
860
826
  module.exports = AssetsClient;
@@ -862,17 +828,22 @@ var require_assetsClient = __commonJS({
862
828
  });
863
829
 
864
830
  // src/users/usersClient.js
865
- var require_usersClient = __commonJS({
866
- "src/users/usersClient.js"(exports, module) {
867
- function UsersClient(client) {
868
- this.client = client;
869
- }
831
+ var usersClient_exports = {};
832
+ __export(usersClient_exports, {
833
+ default: () => usersClient_default
834
+ });
835
+ function UsersClient(client) {
836
+ this.client = client;
837
+ }
838
+ var usersClient_default;
839
+ var init_usersClient = __esm({
840
+ "src/users/usersClient.js"() {
870
841
  Object.assign(UsersClient.prototype, {
871
842
  getById(id) {
872
843
  return this.client.request({ uri: `/users/${id}` });
873
844
  }
874
845
  });
875
- module.exports = UsersClient;
846
+ usersClient_default = UsersClient;
876
847
  }
877
848
  });
878
849
 
@@ -896,68 +867,79 @@ var require_authClient = __commonJS({
896
867
 
897
868
  // src/http/errors.js
898
869
  import makeError from "make-error";
899
- var require_errors = __commonJS({
900
- "src/http/errors.js"(exports) {
901
- function ClientError(res) {
902
- const props = extractErrorProps(res);
903
- ClientError.super.call(this, props.message);
904
- Object.assign(this, props);
905
- }
906
- function ServerError(res) {
907
- const props = extractErrorProps(res);
908
- ServerError.super.call(this, props.message);
909
- Object.assign(this, props);
910
- }
911
- function extractErrorProps(res) {
912
- const body = res.body;
913
- const props = {
914
- response: res,
915
- statusCode: res.statusCode,
916
- responseBody: stringifyBody(body, res)
917
- };
918
- if (body.error && body.message) {
919
- props.message = `${body.error} - ${body.message}`;
920
- return props;
921
- }
922
- if (body.error && body.error.description) {
923
- props.message = body.error.description;
924
- props.details = body.error;
925
- return props;
926
- }
927
- props.message = body.error || body.message || httpErrorMessage(res);
928
- return props;
929
- }
930
- function httpErrorMessage(res) {
931
- const statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
932
- return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}`;
933
- }
934
- function stringifyBody(body, res) {
935
- const contentType = (res.headers["content-type"] || "").toLowerCase();
936
- const isJson = contentType.indexOf("application/json") !== -1;
937
- return isJson ? JSON.stringify(body, null, 2) : body;
938
- }
870
+ function ClientError(res) {
871
+ const props = extractErrorProps(res);
872
+ ClientError.super.call(this, props.message);
873
+ Object.assign(this, props);
874
+ }
875
+ function ServerError(res) {
876
+ const props = extractErrorProps(res);
877
+ ServerError.super.call(this, props.message);
878
+ Object.assign(this, props);
879
+ }
880
+ function extractErrorProps(res) {
881
+ const body = res.body;
882
+ const props = {
883
+ response: res,
884
+ statusCode: res.statusCode,
885
+ responseBody: stringifyBody(body, res)
886
+ };
887
+ if (body.error && body.message) {
888
+ props.message = `${body.error} - ${body.message}`;
889
+ return props;
890
+ }
891
+ if (body.error && body.error.description) {
892
+ props.message = body.error.description;
893
+ props.details = body.error;
894
+ return props;
895
+ }
896
+ props.message = body.error || body.message || httpErrorMessage(res);
897
+ return props;
898
+ }
899
+ function httpErrorMessage(res) {
900
+ const statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
901
+ return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}`;
902
+ }
903
+ function stringifyBody(body, res) {
904
+ const contentType = (res.headers["content-type"] || "").toLowerCase();
905
+ const isJson = contentType.indexOf("application/json") !== -1;
906
+ return isJson ? JSON.stringify(body, null, 2) : body;
907
+ }
908
+ var init_errors = __esm({
909
+ "src/http/errors.js"() {
939
910
  makeError(ClientError);
940
911
  makeError(ServerError);
941
- exports.ClientError = ClientError;
942
- exports.ServerError = ServerError;
943
912
  }
944
913
  });
945
914
 
946
915
  // src/http/browserMiddleware.js
947
- var require_browserMiddleware = __commonJS({
948
- "src/http/browserMiddleware.js"(exports, module) {
949
- module.exports = [];
916
+ var browserMiddleware_exports = {};
917
+ __export(browserMiddleware_exports, {
918
+ default: () => browserMiddleware_default
919
+ });
920
+ var browserMiddleware_default;
921
+ var init_browserMiddleware = __esm({
922
+ "src/http/browserMiddleware.js"() {
923
+ browserMiddleware_default = [];
950
924
  }
951
925
  });
952
926
 
953
927
  // src/http/request.js
928
+ var request_exports = {};
929
+ __export(request_exports, {
930
+ default: () => request_default
931
+ });
954
932
  import getIt from "get-it";
955
933
  import { observable, jsonRequest, jsonResponse, progress } from "get-it/middleware";
956
- var require_request = __commonJS({
957
- "src/http/request.js"(exports, module) {
958
- var { Observable: Observable2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
959
- var { ClientError, ServerError } = require_errors();
960
- var httpError = {
934
+ function httpRequest(options, requester = request) {
935
+ return requester(Object.assign({ maxRedirects: 0 }, options));
936
+ }
937
+ var httpError, printWarnings, envSpecific, middleware, request, request_default;
938
+ var init_request = __esm({
939
+ "src/http/request.js"() {
940
+ init_observable_modern();
941
+ init_errors();
942
+ httpError = {
961
943
  onResponse: (res) => {
962
944
  if (res.statusCode >= 500) {
963
945
  throw new ServerError(res);
@@ -967,39 +949,41 @@ var require_request = __commonJS({
967
949
  return res;
968
950
  }
969
951
  };
970
- var printWarnings = {
952
+ printWarnings = {
971
953
  onResponse: (res) => {
972
954
  const warn = res.headers["x-sanity-warning"];
973
- const warnings2 = Array.isArray(warn) ? warn : [warn];
974
- warnings2.filter(Boolean).forEach((msg) => console.warn(msg));
955
+ const warnings = Array.isArray(warn) ? warn : [warn];
956
+ warnings.filter(Boolean).forEach((msg) => console.warn(msg));
975
957
  return res;
976
958
  }
977
959
  };
978
- var envSpecific = typeof EdgeRuntime === "string" ? require_browserMiddleware() : require_browserMiddleware();
979
- var middleware = envSpecific.concat([
960
+ envSpecific = typeof EdgeRuntime === "string" ? (init_browserMiddleware(), __toCommonJS(browserMiddleware_exports)) : (init_browserMiddleware(), __toCommonJS(browserMiddleware_exports));
961
+ middleware = envSpecific.concat([
980
962
  printWarnings,
981
963
  jsonRequest(),
982
964
  jsonResponse(),
983
965
  progress(),
984
966
  httpError,
985
- observable({ implementation: Observable2 })
967
+ observable({ implementation: Observable })
986
968
  ]);
987
- var request = getIt(middleware);
988
- function httpRequest(options, requester = request) {
989
- return requester(Object.assign({ maxRedirects: 0 }, options));
990
- }
969
+ request = getIt(middleware);
991
970
  httpRequest.defaultRequester = request;
992
971
  httpRequest.ClientError = ClientError;
993
972
  httpRequest.ServerError = ServerError;
994
- module.exports = httpRequest;
973
+ request_default = httpRequest;
995
974
  }
996
975
  });
997
976
 
998
977
  // src/http/requestOptions.js
999
- var require_requestOptions = __commonJS({
1000
- "src/http/requestOptions.js"(exports, module) {
1001
- var projectHeader = "X-Sanity-Project-ID";
1002
- module.exports = (config, overrides = {}) => {
978
+ var requestOptions_exports = {};
979
+ __export(requestOptions_exports, {
980
+ default: () => requestOptions_default
981
+ });
982
+ var projectHeader, requestOptions_default;
983
+ var init_requestOptions = __esm({
984
+ "src/http/requestOptions.js"() {
985
+ projectHeader = "X-Sanity-Project-ID";
986
+ requestOptions_default = (config, overrides = {}) => {
1003
987
  const headers = {};
1004
988
  const token = overrides.token || config.token;
1005
989
  if (token) {
@@ -1024,10 +1008,6 @@ var require_requestOptions = __commonJS({
1024
1008
  });
1025
1009
 
1026
1010
  // src/generateHelpUrl.js
1027
- var generateHelpUrl_exports = {};
1028
- __export(generateHelpUrl_exports, {
1029
- default: () => generateHelpUrl
1030
- });
1031
1011
  function generateHelpUrl(slug) {
1032
1012
  return BASE_URL + slug;
1033
1013
  }
@@ -1039,9 +1019,10 @@ var init_generateHelpUrl = __esm({
1039
1019
  });
1040
1020
 
1041
1021
  // src/util/once.js
1042
- var require_once = __commonJS({
1043
- "src/util/once.js"(exports, module) {
1044
- module.exports = (fn) => {
1022
+ var once_default;
1023
+ var init_once = __esm({
1024
+ "src/util/once.js"() {
1025
+ once_default = (fn) => {
1045
1026
  let didCall = false;
1046
1027
  let returnValue;
1047
1028
  return (...args) => {
@@ -1057,26 +1038,27 @@ var require_once = __commonJS({
1057
1038
  });
1058
1039
 
1059
1040
  // src/warnings.js
1060
- var require_warnings = __commonJS({
1061
- "src/warnings.js"(exports) {
1062
- var generateHelpUrl2 = (init_generateHelpUrl(), __toCommonJS(generateHelpUrl_exports));
1063
- var once = require_once();
1064
- var createWarningPrinter = (message) => once((...args) => console.warn(message.join(" "), ...args));
1065
- exports.printCdnWarning = createWarningPrinter([
1041
+ var createWarningPrinter, printCdnWarning, printBrowserTokenWarning, printNoApiVersionSpecifiedWarning;
1042
+ var init_warnings = __esm({
1043
+ "src/warnings.js"() {
1044
+ init_generateHelpUrl();
1045
+ init_once();
1046
+ createWarningPrinter = (message) => once_default((...args) => console.warn(message.join(" "), ...args));
1047
+ printCdnWarning = createWarningPrinter([
1066
1048
  "You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and",
1067
- `cheaper. Think about it! For more info, see ${generateHelpUrl2("js-client-cdn-configuration")}.`,
1049
+ `cheaper. Think about it! For more info, see ${generateHelpUrl("js-client-cdn-configuration")}.`,
1068
1050
  "To hide this warning, please set the `useCdn` option to either `true` or `false` when creating",
1069
1051
  "the client."
1070
1052
  ]);
1071
- exports.printBrowserTokenWarning = createWarningPrinter([
1053
+ printBrowserTokenWarning = createWarningPrinter([
1072
1054
  "You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
1073
- `See ${generateHelpUrl2(
1055
+ `See ${generateHelpUrl(
1074
1056
  "js-client-browser-token"
1075
1057
  )} for more information and how to hide this warning.`
1076
1058
  ]);
1077
- exports.printNoApiVersionSpecifiedWarning = createWarningPrinter([
1059
+ printNoApiVersionSpecifiedWarning = createWarningPrinter([
1078
1060
  "Using the Sanity client without specifying an API version is deprecated.",
1079
- `See ${generateHelpUrl2("js-client-api-version")}`
1061
+ `See ${generateHelpUrl("js-client-api-version")}`
1080
1062
  ]);
1081
1063
  }
1082
1064
  });
@@ -1088,12 +1070,12 @@ __export(config_exports, {
1088
1070
  initConfig: () => initConfig,
1089
1071
  validateApiVersion: () => validateApiVersion
1090
1072
  });
1091
- var import_validators, import_warnings, defaultCdnHost, defaultConfig, LOCALHOSTS, isLocal, validateApiVersion, initConfig;
1073
+ var defaultCdnHost, defaultConfig, LOCALHOSTS, isLocal, validateApiVersion, initConfig;
1092
1074
  var init_config = __esm({
1093
1075
  "src/config.js"() {
1094
1076
  init_generateHelpUrl();
1095
- import_validators = __toESM(require_validators());
1096
- import_warnings = __toESM(require_warnings());
1077
+ init_validators();
1078
+ init_warnings();
1097
1079
  defaultCdnHost = "apicdn.sanity.io";
1098
1080
  defaultConfig = {
1099
1081
  apiHost: "https://api.sanity.io",
@@ -1116,7 +1098,7 @@ var init_config = __esm({
1116
1098
  initConfig = (config, prevConfig) => {
1117
1099
  const specifiedConfig = Object.assign({}, prevConfig, config);
1118
1100
  if (!specifiedConfig.apiVersion) {
1119
- import_warnings.default.printNoApiVersionSpecifiedWarning();
1101
+ printNoApiVersionSpecifiedWarning();
1120
1102
  }
1121
1103
  const newConfig = Object.assign({}, defaultConfig, specifiedConfig);
1122
1104
  const projectBased = newConfig.useProjectHostname;
@@ -1130,18 +1112,18 @@ var init_config = __esm({
1130
1112
  const isBrowser = typeof window !== "undefined" && window.location && window.location.hostname;
1131
1113
  const isLocalhost = isBrowser && isLocal(window.location.hostname);
1132
1114
  if (isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true) {
1133
- import_warnings.default.printBrowserTokenWarning();
1115
+ printBrowserTokenWarning();
1134
1116
  } else if (typeof newConfig.useCdn === "undefined") {
1135
- import_warnings.default.printCdnWarning();
1117
+ printCdnWarning();
1136
1118
  }
1137
1119
  if (projectBased) {
1138
- import_validators.default.projectId(newConfig.projectId);
1120
+ projectId(newConfig.projectId);
1139
1121
  }
1140
1122
  if (newConfig.dataset) {
1141
- import_validators.default.dataset(newConfig.dataset);
1123
+ dataset(newConfig.dataset);
1142
1124
  }
1143
1125
  if ("requestTagPrefix" in newConfig) {
1144
- newConfig.requestTagPrefix = newConfig.requestTagPrefix ? import_validators.default.requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0;
1126
+ newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0;
1145
1127
  }
1146
1128
  newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, "");
1147
1129
  newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
@@ -1166,20 +1148,19 @@ var init_config = __esm({
1166
1148
  // src/sanityClient.js
1167
1149
  var require_sanityClient = __commonJS({
1168
1150
  "src/sanityClient.js"(exports, module) {
1169
- var import_object_assign = __toESM(require_object_assign());
1170
1151
  var { Observable: Observable2, map: map2, filter: filter2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
1171
1152
  var Patch = require_patch();
1172
1153
  var Transaction = require_transaction();
1173
1154
  var dataMethods = require_dataMethods();
1174
1155
  var DatasetsClient = require_datasetsClient();
1175
- var ProjectsClient = require_projectsClient();
1156
+ var ProjectsClient2 = (init_projectsClient(), __toCommonJS(projectsClient_exports));
1176
1157
  var AssetsClient = require_assetsClient();
1177
- var UsersClient = require_usersClient();
1158
+ var UsersClient2 = (init_usersClient(), __toCommonJS(usersClient_exports));
1178
1159
  var AuthClient = require_authClient();
1179
- var httpRequest = require_request();
1180
- var getRequestOptions = require_requestOptions();
1160
+ var httpRequest2 = (init_request(), __toCommonJS(request_exports));
1161
+ var getRequestOptions = (init_requestOptions(), __toCommonJS(requestOptions_exports));
1181
1162
  var { defaultConfig: defaultConfig2, initConfig: initConfig2 } = (init_config(), __toCommonJS(config_exports));
1182
- var validate2 = require_validators();
1163
+ var validate = (init_validators(), __toCommonJS(validators_exports));
1183
1164
  var toPromise = (observable2) => observable2.toPromise();
1184
1165
  function SanityClient(config = defaultConfig2) {
1185
1166
  if (!(this instanceof SanityClient)) {
@@ -1188,8 +1169,8 @@ var require_sanityClient = __commonJS({
1188
1169
  this.config(config);
1189
1170
  this.assets = new AssetsClient(this);
1190
1171
  this.datasets = new DatasetsClient(this);
1191
- this.projects = new ProjectsClient(this);
1192
- this.users = new UsersClient(this);
1172
+ this.projects = new ProjectsClient2(this);
1173
+ this.users = new UsersClient2(this);
1193
1174
  this.auth = new AuthClient(this);
1194
1175
  if (this.clientConfig.isPromiseAPI) {
1195
1176
  const observableConfig = Object.assign({}, this.clientConfig, { isPromiseAPI: false });
@@ -1228,7 +1209,7 @@ var require_sanityClient = __commonJS({
1228
1209
  const useCdn = this.clientConfig.useCdn && canUseCdn;
1229
1210
  const tag = options.tag && this.clientConfig.requestTagPrefix ? [this.clientConfig.requestTagPrefix, options.tag].join(".") : options.tag || this.clientConfig.requestTagPrefix;
1230
1211
  if (tag) {
1231
- options.query = { tag: validate2.requestTag(tag), ...options.query };
1212
+ options.query = { tag: validate.requestTag(tag), ...options.query };
1232
1213
  }
1233
1214
  const reqOptions = getRequestOptions(
1234
1215
  this.clientConfig,
@@ -1237,7 +1218,7 @@ var require_sanityClient = __commonJS({
1237
1218
  })
1238
1219
  );
1239
1220
  return new Observable2(
1240
- (subscriber) => httpRequest(reqOptions, this.clientConfig.requester).subscribe(subscriber)
1221
+ (subscriber) => httpRequest2(reqOptions, this.clientConfig.requester).subscribe(subscriber)
1241
1222
  );
1242
1223
  },
1243
1224
  request(options) {
@@ -1250,16 +1231,11 @@ var require_sanityClient = __commonJS({
1250
1231
  });
1251
1232
  SanityClient.Patch = Patch;
1252
1233
  SanityClient.Transaction = Transaction;
1253
- SanityClient.ClientError = httpRequest.ClientError;
1254
- SanityClient.ServerError = httpRequest.ServerError;
1255
- SanityClient.requester = httpRequest.defaultRequester;
1234
+ SanityClient.ClientError = httpRequest2.ClientError;
1235
+ SanityClient.ServerError = httpRequest2.ServerError;
1236
+ SanityClient.requester = httpRequest2.defaultRequester;
1256
1237
  module.exports = SanityClient;
1257
1238
  }
1258
1239
  });
1259
1240
  export default require_sanityClient();
1260
- /*
1261
- object-assign
1262
- (c) Sindre Sorhus
1263
- @license MIT
1264
- */
1265
1241
  //# sourceMappingURL=sanityClient.browser.mjs.map