@sanity/client 5.0.0-esm.0 → 5.0.0-esm.2

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.cjs CHANGED
@@ -16,7 +16,7 @@ function _interopDefaultCompat(e) {
16
16
  }
17
17
  var polyfilledEventSource__default = /*#__PURE__*/_interopDefaultCompat(polyfilledEventSource);
18
18
  var name = "@sanity/client";
19
- var version = "5.0.0-esm.0";
19
+ var version = "5.0.0-esm.2";
20
20
  const middleware = [middleware$1.debug({
21
21
  verbose: true,
22
22
  namespace: "sanity:client"
@@ -217,23 +217,23 @@ var encodeQueryString = _ref => {
217
217
  return options[option] ? "".concat(qs, "&").concat(enc(option), "=").concat(enc(options[option])) : qs;
218
218
  }, qString);
219
219
  };
220
- var __accessCheck$4 = (obj, member, msg) => {
220
+ var __accessCheck$5 = (obj, member, msg) => {
221
221
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
222
222
  };
223
- var __privateGet$3 = (obj, member, getter) => {
224
- __accessCheck$4(obj, member, "read from private field");
223
+ var __privateGet$4 = (obj, member, getter) => {
224
+ __accessCheck$5(obj, member, "read from private field");
225
225
  return getter ? getter.call(obj) : member.get(obj);
226
226
  };
227
- var __privateAdd$4 = (obj, member, value) => {
227
+ var __privateAdd$5 = (obj, member, value) => {
228
228
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
229
229
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
230
230
  };
231
- var __privateSet$3 = (obj, member, value, setter) => {
232
- __accessCheck$4(obj, member, "write to private field");
231
+ var __privateSet$4 = (obj, member, value, setter) => {
232
+ __accessCheck$5(obj, member, "write to private field");
233
233
  setter ? setter.call(obj, value) : member.set(obj, value);
234
234
  return value;
235
235
  };
236
- var _client$2, _client2$2;
236
+ var _client$3, _client2$3;
237
237
  class BasePatch {
238
238
  constructor(selection) {
239
239
  let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -324,16 +324,16 @@ class BasePatch {
324
324
  const _ObservablePatch = class extends BasePatch {
325
325
  constructor(selection, operations, client) {
326
326
  super(selection, operations);
327
- __privateAdd$4(this, _client$2, void 0);
328
- __privateSet$3(this, _client$2, client);
327
+ __privateAdd$5(this, _client$3, void 0);
328
+ __privateSet$4(this, _client$3, client);
329
329
  }
330
330
  clone() {
331
331
  return new _ObservablePatch(this.selection, {
332
332
  ...this.operations
333
- }, __privateGet$3(this, _client$2));
333
+ }, __privateGet$4(this, _client$3));
334
334
  }
335
335
  commit(options) {
336
- if (!__privateGet$3(this, _client$2)) {
336
+ if (!__privateGet$4(this, _client$3)) {
337
337
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
338
338
  }
339
339
  const returnFirst = typeof this.selection === "string";
@@ -341,26 +341,26 @@ const _ObservablePatch = class extends BasePatch {
341
341
  returnFirst,
342
342
  returnDocuments: true
343
343
  }, options);
344
- return __privateGet$3(this, _client$2).mutate({
344
+ return __privateGet$4(this, _client$3).mutate({
345
345
  patch: this.serialize()
346
346
  }, opts);
347
347
  }
348
348
  };
349
349
  let ObservablePatch = _ObservablePatch;
350
- _client$2 = new WeakMap();
350
+ _client$3 = new WeakMap();
351
351
  const _Patch = class extends BasePatch {
352
352
  constructor(selection, operations, client) {
353
353
  super(selection, operations);
354
- __privateAdd$4(this, _client2$2, void 0);
355
- __privateSet$3(this, _client2$2, client);
354
+ __privateAdd$5(this, _client2$3, void 0);
355
+ __privateSet$4(this, _client2$3, client);
356
356
  }
357
357
  clone() {
358
358
  return new _Patch(this.selection, {
359
359
  ...this.operations
360
- }, __privateGet$3(this, _client2$2));
360
+ }, __privateGet$4(this, _client2$3));
361
361
  }
362
362
  commit(options) {
363
- if (!__privateGet$3(this, _client2$2)) {
363
+ if (!__privateGet$4(this, _client2$3)) {
364
364
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
365
365
  }
366
366
  const returnFirst = typeof this.selection === "string";
@@ -368,30 +368,30 @@ const _Patch = class extends BasePatch {
368
368
  returnFirst,
369
369
  returnDocuments: true
370
370
  }, options);
371
- return __privateGet$3(this, _client2$2).mutate({
371
+ return __privateGet$4(this, _client2$3).mutate({
372
372
  patch: this.serialize()
373
373
  }, opts);
374
374
  }
375
375
  };
376
376
  let Patch = _Patch;
377
- _client2$2 = new WeakMap();
378
- var __accessCheck$3 = (obj, member, msg) => {
377
+ _client2$3 = new WeakMap();
378
+ var __accessCheck$4 = (obj, member, msg) => {
379
379
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
380
380
  };
381
- var __privateGet$2 = (obj, member, getter) => {
382
- __accessCheck$3(obj, member, "read from private field");
381
+ var __privateGet$3 = (obj, member, getter) => {
382
+ __accessCheck$4(obj, member, "read from private field");
383
383
  return getter ? getter.call(obj) : member.get(obj);
384
384
  };
385
- var __privateAdd$3 = (obj, member, value) => {
385
+ var __privateAdd$4 = (obj, member, value) => {
386
386
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
387
387
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
388
388
  };
389
- var __privateSet$2 = (obj, member, value, setter) => {
390
- __accessCheck$3(obj, member, "write to private field");
389
+ var __privateSet$3 = (obj, member, value, setter) => {
390
+ __accessCheck$4(obj, member, "write to private field");
391
391
  setter ? setter.call(obj, value) : member.set(obj, value);
392
392
  return value;
393
393
  };
394
- var _client$1, _client2$1;
394
+ var _client$2, _client2$2;
395
395
  const defaultMutateOptions = {
396
396
  returnDocuments: false
397
397
  };
@@ -457,17 +457,17 @@ class BaseTransaction {
457
457
  const _Transaction = class extends BaseTransaction {
458
458
  constructor(operations, client, transactionId) {
459
459
  super(operations, transactionId);
460
- __privateAdd$3(this, _client$1, void 0);
461
- __privateSet$2(this, _client$1, client);
460
+ __privateAdd$4(this, _client$2, void 0);
461
+ __privateSet$3(this, _client$2, client);
462
462
  }
463
463
  clone() {
464
- return new _Transaction([...this.operations], __privateGet$2(this, _client$1), this.trxId);
464
+ return new _Transaction([...this.operations], __privateGet$3(this, _client$2), this.trxId);
465
465
  }
466
466
  commit(options) {
467
- if (!__privateGet$2(this, _client$1)) {
467
+ if (!__privateGet$3(this, _client$2)) {
468
468
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
469
469
  }
470
- return __privateGet$2(this, _client$1).mutate(this.serialize(), Object.assign({
470
+ return __privateGet$3(this, _client$2).mutate(this.serialize(), Object.assign({
471
471
  transactionId: this.trxId
472
472
  }, defaultMutateOptions, options || {}));
473
473
  }
@@ -480,7 +480,7 @@ const _Transaction = class extends BaseTransaction {
480
480
  });
481
481
  }
482
482
  if (isBuilder) {
483
- const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$2(this, _client$1)));
483
+ const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$3(this, _client$2)));
484
484
  if (!(patch instanceof Patch)) {
485
485
  throw new Error("function passed to `patch()` must return the patch");
486
486
  }
@@ -497,21 +497,21 @@ const _Transaction = class extends BaseTransaction {
497
497
  }
498
498
  };
499
499
  let Transaction = _Transaction;
500
- _client$1 = new WeakMap();
500
+ _client$2 = new WeakMap();
501
501
  const _ObservableTransaction = class extends BaseTransaction {
502
502
  constructor(operations, client, transactionId) {
503
503
  super(operations, transactionId);
504
- __privateAdd$3(this, _client2$1, void 0);
505
- __privateSet$2(this, _client2$1, client);
504
+ __privateAdd$4(this, _client2$2, void 0);
505
+ __privateSet$3(this, _client2$2, client);
506
506
  }
507
507
  clone() {
508
- return new _ObservableTransaction([...this.operations], __privateGet$2(this, _client2$1), this.trxId);
508
+ return new _ObservableTransaction([...this.operations], __privateGet$3(this, _client2$2), this.trxId);
509
509
  }
510
510
  commit(options) {
511
- if (!__privateGet$2(this, _client2$1)) {
511
+ if (!__privateGet$3(this, _client2$2)) {
512
512
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
513
513
  }
514
- return __privateGet$2(this, _client2$1).mutate(this.serialize(), Object.assign({
514
+ return __privateGet$3(this, _client2$2).mutate(this.serialize(), Object.assign({
515
515
  transactionId: this.trxId
516
516
  }, defaultMutateOptions, options || {}));
517
517
  }
@@ -524,7 +524,7 @@ const _ObservableTransaction = class extends BaseTransaction {
524
524
  });
525
525
  }
526
526
  if (isBuilder) {
527
- const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$2(this, _client2$1)));
527
+ const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$3(this, _client2$2)));
528
528
  if (!(patch instanceof ObservablePatch)) {
529
529
  throw new Error("function passed to `patch()` must return the patch");
530
530
  }
@@ -541,7 +541,7 @@ const _ObservableTransaction = class extends BaseTransaction {
541
541
  }
542
542
  };
543
543
  let ObservableTransaction = _ObservableTransaction;
544
- _client2$1 = new WeakMap();
544
+ _client2$2 = new WeakMap();
545
545
  const excludeFalsey = (param, defValue) => {
546
546
  const value = typeof param === "undefined" ? defValue : param;
547
547
  return param === false ? void 0 : value;
@@ -695,50 +695,50 @@ function _request(client, httpRequest, options) {
695
695
  const observable = _requestObservable(client, httpRequest, options).pipe(operators.filter(event => event.type === "response"), operators.map(event => event.body));
696
696
  return observable;
697
697
  }
698
- var __accessCheck$2 = (obj, member, msg) => {
698
+ var __accessCheck$3 = (obj, member, msg) => {
699
699
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
700
700
  };
701
- var __privateGet$1 = (obj, member, getter) => {
702
- __accessCheck$2(obj, member, "read from private field");
701
+ var __privateGet$2 = (obj, member, getter) => {
702
+ __accessCheck$3(obj, member, "read from private field");
703
703
  return getter ? getter.call(obj) : member.get(obj);
704
704
  };
705
- var __privateAdd$2 = (obj, member, value) => {
705
+ var __privateAdd$3 = (obj, member, value) => {
706
706
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
707
707
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
708
708
  };
709
- var __privateSet$1 = (obj, member, value, setter) => {
710
- __accessCheck$2(obj, member, "write to private field");
709
+ var __privateSet$2 = (obj, member, value, setter) => {
710
+ __accessCheck$3(obj, member, "write to private field");
711
711
  setter ? setter.call(obj, value) : member.set(obj, value);
712
712
  return value;
713
713
  };
714
- var _client, _httpRequest$1, _client2, _httpRequest2$1;
714
+ var _client$1, _httpRequest$2, _client2$1, _httpRequest2$2;
715
715
  class ObservableAssetsClient {
716
716
  constructor(client, httpRequest) {
717
- __privateAdd$2(this, _client, void 0);
718
- __privateAdd$2(this, _httpRequest$1, void 0);
719
- __privateSet$1(this, _client, client);
720
- __privateSet$1(this, _httpRequest$1, httpRequest);
717
+ __privateAdd$3(this, _client$1, void 0);
718
+ __privateAdd$3(this, _httpRequest$2, void 0);
719
+ __privateSet$2(this, _client$1, client);
720
+ __privateSet$2(this, _httpRequest$2, httpRequest);
721
721
  }
722
722
  upload(assetType, body, options) {
723
- return _upload(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), assetType, body, options);
723
+ return _upload(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), assetType, body, options);
724
724
  }
725
725
  }
726
- _client = new WeakMap();
727
- _httpRequest$1 = new WeakMap();
726
+ _client$1 = new WeakMap();
727
+ _httpRequest$2 = new WeakMap();
728
728
  class AssetsClient {
729
729
  constructor(client, httpRequest) {
730
- __privateAdd$2(this, _client2, void 0);
731
- __privateAdd$2(this, _httpRequest2$1, void 0);
732
- __privateSet$1(this, _client2, client);
733
- __privateSet$1(this, _httpRequest2$1, httpRequest);
730
+ __privateAdd$3(this, _client2$1, void 0);
731
+ __privateAdd$3(this, _httpRequest2$2, void 0);
732
+ __privateSet$2(this, _client2$1, client);
733
+ __privateSet$2(this, _httpRequest2$2, httpRequest);
734
734
  }
735
735
  upload(assetType, body, options) {
736
- const observable = _upload(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), assetType, body, options);
736
+ const observable = _upload(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), assetType, body, options);
737
737
  return rxjs.lastValueFrom(observable.pipe(operators.filter(event => event.type === "response"), operators.map(event => event.body.document)));
738
738
  }
739
739
  }
740
- _client2 = new WeakMap();
741
- _httpRequest2$1 = new WeakMap();
740
+ _client2$1 = new WeakMap();
741
+ _httpRequest2$2 = new WeakMap();
742
742
  function _upload(client, httpRequest, assetType, body) {
743
743
  let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
744
744
  validateAssetType(assetType);
@@ -792,31 +792,65 @@ function optionsFromFile(opts, file) {
792
792
  contentType: file.type
793
793
  }, opts);
794
794
  }
795
- class BaseAuthClient {
795
+ var __accessCheck$2 = (obj, member, msg) => {
796
+ if (!member.has(obj)) throw TypeError("Cannot " + msg);
797
+ };
798
+ var __privateGet$1 = (obj, member, getter) => {
799
+ __accessCheck$2(obj, member, "read from private field");
800
+ return getter ? getter.call(obj) : member.get(obj);
801
+ };
802
+ var __privateAdd$2 = (obj, member, value) => {
803
+ if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
804
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
805
+ };
806
+ var __privateSet$1 = (obj, member, value, setter) => {
807
+ __accessCheck$2(obj, member, "write to private field");
808
+ setter ? setter.call(obj, value) : member.set(obj, value);
809
+ return value;
810
+ };
811
+ var _client, _httpRequest$1, _client2, _httpRequest2$1;
812
+ class ObservableAuthClient {
813
+ constructor(client, httpRequest) {
814
+ __privateAdd$2(this, _client, void 0);
815
+ __privateAdd$2(this, _httpRequest$1, void 0);
816
+ __privateSet$1(this, _client, client);
817
+ __privateSet$1(this, _httpRequest$1, httpRequest);
818
+ }
796
819
  getLoginProviders() {
797
- return this.client.request({
820
+ return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
798
821
  uri: "/auth/providers"
799
822
  });
800
823
  }
801
824
  logout() {
802
- return this.client.request({
825
+ return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
803
826
  uri: "/auth/logout",
804
827
  method: "POST"
805
828
  });
806
829
  }
807
830
  }
808
- class ObservableAuthClient extends BaseAuthClient {
809
- constructor(client) {
810
- super();
811
- this.client = client;
831
+ _client = new WeakMap();
832
+ _httpRequest$1 = new WeakMap();
833
+ class AuthClient {
834
+ constructor(client, httpRequest) {
835
+ __privateAdd$2(this, _client2, void 0);
836
+ __privateAdd$2(this, _httpRequest2$1, void 0);
837
+ __privateSet$1(this, _client2, client);
838
+ __privateSet$1(this, _httpRequest2$1, httpRequest);
812
839
  }
813
- }
814
- class AuthClient extends BaseAuthClient {
815
- constructor(client) {
816
- super();
817
- this.client = client;
840
+ getLoginProviders() {
841
+ return rxjs.lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
842
+ uri: "/auth/providers"
843
+ }));
844
+ }
845
+ logout() {
846
+ return rxjs.lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
847
+ uri: "/auth/logout",
848
+ method: "POST"
849
+ }));
818
850
  }
819
851
  }
852
+ _client2 = new WeakMap();
853
+ _httpRequest2$1 = new WeakMap();
820
854
  const BASE_URL = "https://docs.sanity.io/help/";
821
855
  function generateHelpUrl(slug) {
822
856
  return BASE_URL + slug;
@@ -1160,11 +1194,21 @@ var __privateSet = (obj, member, value, setter) => {
1160
1194
  setter ? setter.call(obj, value) : member.set(obj, value);
1161
1195
  return value;
1162
1196
  };
1163
- var _clientConfig, _httpRequest, _httpRequest2;
1164
- class BaseSanityClient {
1165
- constructor(config) {
1197
+ var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
1198
+ const _ObservableSanityClient = class {
1199
+ constructor(httpRequest, config) {
1166
1200
  __privateAdd(this, _clientConfig, void 0);
1201
+ __privateAdd(this, _httpRequest, void 0);
1167
1202
  this.config(config);
1203
+ __privateSet(this, _httpRequest, httpRequest);
1204
+ this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
1205
+ this.auth = new ObservableAuthClient(this, __privateGet(this, _httpRequest));
1206
+ this.datasets = new ObservableDatasetsClient(this);
1207
+ this.projects = new ObservableProjectsClient(this);
1208
+ this.users = new ObservableUsersClient(this);
1209
+ }
1210
+ clone() {
1211
+ return new _ObservableSanityClient(__privateGet(this, _httpRequest), this.config());
1168
1212
  }
1169
1213
  config(newConfig) {
1170
1214
  if (newConfig === void 0) {
@@ -1178,40 +1222,6 @@ class BaseSanityClient {
1178
1222
  __privateSet(this, _clientConfig, initConfig(newConfig, __privateGet(this, _clientConfig) || {}));
1179
1223
  return this;
1180
1224
  }
1181
- isPromiseAPI() {
1182
- return this instanceof SanityClient;
1183
- }
1184
- getUrl(uri) {
1185
- let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1186
- const base = canUseCdn ? __privateGet(this, _clientConfig).cdnUrl : __privateGet(this, _clientConfig).url;
1187
- return "".concat(base, "/").concat(uri.replace(/^\//, ""));
1188
- }
1189
- getDataUrl(operation, path) {
1190
- const config = this.config();
1191
- const catalog = hasDataset(config);
1192
- const baseUri = "/".concat(operation, "/").concat(catalog);
1193
- const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
1194
- return "/data".concat(uri).replace(/\/($|\?)/, "$1");
1195
- }
1196
- }
1197
- _clientConfig = new WeakMap();
1198
- const _ObservableSanityClient = class extends BaseSanityClient {
1199
- constructor(httpRequest, config) {
1200
- super(config);
1201
- __privateAdd(this, _httpRequest, void 0);
1202
- __privateSet(this, _httpRequest, httpRequest);
1203
- this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
1204
- this.auth = new ObservableAuthClient(this);
1205
- this.datasets = new ObservableDatasetsClient(this);
1206
- this.projects = new ObservableProjectsClient(this);
1207
- this.users = new ObservableUsersClient(this);
1208
- }
1209
- clone() {
1210
- return new _ObservableSanityClient(__privateGet(this, _httpRequest), this.config());
1211
- }
1212
- config(newConfig) {
1213
- return super.config(newConfig);
1214
- }
1215
1225
  withConfig(newConfig) {
1216
1226
  return new _ObservableSanityClient(__privateGet(this, _httpRequest), {
1217
1227
  ...this.config(),
@@ -1252,30 +1262,51 @@ const _ObservableSanityClient = class extends BaseSanityClient {
1252
1262
  request(options) {
1253
1263
  return _request(this, __privateGet(this, _httpRequest), options);
1254
1264
  }
1265
+ getUrl(uri) {
1266
+ let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1267
+ const base = canUseCdn ? __privateGet(this, _clientConfig).cdnUrl : __privateGet(this, _clientConfig).url;
1268
+ return "".concat(base, "/").concat(uri.replace(/^\//, ""));
1269
+ }
1270
+ getDataUrl(operation, path) {
1271
+ const config = this.config();
1272
+ const catalog = hasDataset(config);
1273
+ const baseUri = "/".concat(operation, "/").concat(catalog);
1274
+ const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
1275
+ return "/data".concat(uri).replace(/\/($|\?)/, "$1");
1276
+ }
1255
1277
  };
1256
1278
  let ObservableSanityClient = _ObservableSanityClient;
1279
+ _clientConfig = new WeakMap();
1257
1280
  _httpRequest = new WeakMap();
1258
- const _SanityClient = class extends BaseSanityClient {
1281
+ const _SanityClient = class {
1259
1282
  constructor(httpRequest, config) {
1260
- super(config);
1283
+ __privateAdd(this, _clientConfig2, void 0);
1261
1284
  __privateAdd(this, _httpRequest2, void 0);
1262
1285
  this.listen = _listen;
1286
+ this.observable = new ObservableSanityClient(httpRequest, config);
1287
+ this.config(config);
1263
1288
  __privateSet(this, _httpRequest2, httpRequest);
1264
1289
  this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
1265
- this.auth = new AuthClient(this);
1290
+ this.auth = new AuthClient(this, __privateGet(this, _httpRequest2));
1266
1291
  this.datasets = new DatasetsClient(this);
1267
1292
  this.projects = new ProjectsClient(this);
1268
1293
  this.users = new UsersClient(this);
1269
- this.observable = new ObservableSanityClient(httpRequest, this.config());
1270
1294
  }
1271
1295
  clone() {
1272
1296
  return new _SanityClient(__privateGet(this, _httpRequest2), this.config());
1273
1297
  }
1274
1298
  config(newConfig) {
1275
- if (newConfig) {
1276
- this.observable.config(newConfig);
1299
+ if (newConfig === void 0) {
1300
+ return {
1301
+ ...__privateGet(this, _clientConfig2)
1302
+ };
1277
1303
  }
1278
- return super.config(newConfig);
1304
+ if (__privateGet(this, _clientConfig2) && __privateGet(this, _clientConfig2).allowReconfigure === false) {
1305
+ throw new Error("Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client");
1306
+ }
1307
+ this.observable.config(newConfig);
1308
+ __privateSet(this, _clientConfig2, initConfig(newConfig, __privateGet(this, _clientConfig2) || {}));
1309
+ return this;
1279
1310
  }
1280
1311
  withConfig(newConfig) {
1281
1312
  return new _SanityClient(__privateGet(this, _httpRequest2), {
@@ -1320,8 +1351,21 @@ const _SanityClient = class extends BaseSanityClient {
1320
1351
  dataRequest(endpoint, body, options) {
1321
1352
  return rxjs.lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
1322
1353
  }
1354
+ getUrl(uri) {
1355
+ let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1356
+ const base = canUseCdn ? __privateGet(this, _clientConfig2).cdnUrl : __privateGet(this, _clientConfig2).url;
1357
+ return "".concat(base, "/").concat(uri.replace(/^\//, ""));
1358
+ }
1359
+ getDataUrl(operation, path) {
1360
+ const config = this.config();
1361
+ const catalog = hasDataset(config);
1362
+ const baseUri = "/".concat(operation, "/").concat(catalog);
1363
+ const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
1364
+ return "/data".concat(uri).replace(/\/($|\?)/, "$1");
1365
+ }
1323
1366
  };
1324
1367
  let SanityClient = _SanityClient;
1368
+ _clientConfig2 = new WeakMap();
1325
1369
  _httpRequest2 = new WeakMap();
1326
1370
  const httpRequest = defineHttpRequest(middleware);
1327
1371
  const requester = httpRequest.defaultRequester;
@@ -1329,7 +1373,6 @@ function createClient(config) {
1329
1373
  return new SanityClient(httpRequest, config);
1330
1374
  }
1331
1375
  exports.BasePatch = BasePatch;
1332
- exports.BaseSanityClient = BaseSanityClient;
1333
1376
  exports.BaseTransaction = BaseTransaction;
1334
1377
  exports.ClientError = ClientError;
1335
1378
  exports.ObservablePatch = ObservablePatch;
package/dist/index.cjs.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import cjs from './index.cjs';
2
2
 
3
3
  export const BasePatch = cjs.BasePatch;
4
- export const BaseSanityClient = cjs.BaseSanityClient;
5
4
  export const BaseTransaction = cjs.BaseTransaction;
6
5
  export const ClientError = cjs.ClientError;
7
6
  export const ObservablePatch = cjs.ObservablePatch;