@sanity/client 5.0.0-esm.13 → 5.0.0-esm.14

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/README.md CHANGED
@@ -98,7 +98,7 @@ export async function updateDocumentTitle(_id, title) {
98
98
 
99
99
  Sanity Client transpiles syntax for [modern browsers]. The JavaScript runtime must support ES6 features such as [class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes), [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters), [spread syntax](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) and more. Most modern web frameworks, [browsers][modern browsers], and developer tooling supports ES6 today.
100
100
 
101
- For legacy ES5 environments you'll need to transpile `@sanity/client` and its `dependencies` with your own bundler, and have a global ES6-compliant `Promise` available. If your runtime environment doesn't provide a spec compliant `Promise` implementation, we recommend using [native-promise-only](https://www.npmjs.com/package/native-promise-only), [es6-promise](https://www.npmjs.com/package/es6-promise) or another [spec-compliant](https://promisesaplus.com/implementations) implementation. See [this article](https://www.sanity.io/help/js-client-promise-polyfill) for more information.
101
+ [For legacy ES5 environments we recommend v4.](https://github.com/sanity-io/client/tree/v4.0.0#sanityclient)
102
102
 
103
103
  ## Installation
104
104
 
@@ -1157,6 +1157,65 @@ client.createIfNotExists(doc, options)
1157
1157
  client.createOrReplace(doc, options)
1158
1158
  ```
1159
1159
 
1160
+ ### `client.patch.replace` is removed, replace with `client.createOrReplace`<!-- omit in toc -->
1161
+
1162
+ Before:
1163
+
1164
+ ```ts
1165
+ import createClient from '@sanity/client'
1166
+ const client = createClient()
1167
+
1168
+ client.patch('tropic-hab').replace({name: 'Tropical Habanero', ingredients: []}).commit()
1169
+ ```
1170
+
1171
+ After:
1172
+
1173
+ ```ts
1174
+ import {createClient} from '@sanity/client'
1175
+ const client = createClient()
1176
+
1177
+ client.createOrReplace({
1178
+ _id: 'tropic-hab',
1179
+ _type: 'hotsauce',
1180
+ name: 'Tropical Habanero',
1181
+ ingredients: [],
1182
+ })
1183
+ ```
1184
+
1185
+ ### `client.auth` is removed, replace with `client.request`<!-- omit in toc -->
1186
+
1187
+ Before:
1188
+
1189
+ ```ts
1190
+ import createClient from '@sanity/client'
1191
+ const client = createClient()
1192
+
1193
+ /**
1194
+ * Fetch available login providers
1195
+ */
1196
+ const loginProviders = await client.auth.getLoginProviders()
1197
+ /**
1198
+ * Revoke the configured session/token
1199
+ */
1200
+ await client.auth.logout()
1201
+ ```
1202
+
1203
+ After:
1204
+
1205
+ ```ts
1206
+ import {createclient, type AuthProviderResponse} from '@sanity/client'
1207
+ const client = createClient()
1208
+
1209
+ /**
1210
+ * Fetch available login providers
1211
+ */
1212
+ const loginProviders = await client.request<AuthProviderResponse>({uri: '/auth/providers'})
1213
+ /**
1214
+ * Revoke the configured session/token
1215
+ */
1216
+ await client.request<void>({uri: '/auth/logout', method: 'POST'})
1217
+ ```
1218
+
1160
1219
  [modern browsers]: https://browsersl.ist/#q=%3E+0.2%25+and+supports+es6-module+and+supports+es6-module-dynamic-import+and+not+dead+and+not+IE+11
1161
1220
  [Deno]: https://deno.land/
1162
1221
  [Edge Runtime]: https://edge-runtime.vercel.sh/
@@ -207,42 +207,29 @@ var encodeQueryString = _ref => {
207
207
  return options[option] ? "".concat(qs, "&").concat(enc(option), "=").concat(enc(options[option])) : qs;
208
208
  }, qString);
209
209
  };
210
- var __accessCheck$7 = (obj, member, msg) => {
210
+ var __accessCheck$6 = (obj, member, msg) => {
211
211
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
212
212
  };
213
- var __privateGet$7 = (obj, member, getter) => {
214
- __accessCheck$7(obj, member, "read from private field");
213
+ var __privateGet$6 = (obj, member, getter) => {
214
+ __accessCheck$6(obj, member, "read from private field");
215
215
  return getter ? getter.call(obj) : member.get(obj);
216
216
  };
217
- var __privateAdd$7 = (obj, member, value) => {
217
+ var __privateAdd$6 = (obj, member, value) => {
218
218
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
219
219
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
220
220
  };
221
- var __privateSet$7 = (obj, member, value, setter) => {
222
- __accessCheck$7(obj, member, "write to private field");
221
+ var __privateSet$6 = (obj, member, value, setter) => {
222
+ __accessCheck$6(obj, member, "write to private field");
223
223
  setter ? setter.call(obj, value) : member.set(obj, value);
224
224
  return value;
225
225
  };
226
- var _client$6, _client2$6;
226
+ var _client$5, _client2$5;
227
227
  class BasePatch {
228
228
  constructor(selection) {
229
229
  let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
230
230
  this.selection = selection;
231
231
  this.operations = operations;
232
232
  }
233
- /**
234
- * DEPRECATED: Don't use.
235
- * The operation is added to the current patch, ready to be commited by `commit()`
236
- *
237
- * @deprecated - Don't use.
238
- * @param attrs - Attributes to replace
239
- */
240
- replace(attrs) {
241
- validateObject("replace", attrs);
242
- return this._set("set", {
243
- $: attrs
244
- });
245
- }
246
233
  /**
247
234
  * Sets the given attributes to the document. Does NOT merge objects.
248
235
  * The operation is added to the current patch, ready to be commited by `commit()`
@@ -396,8 +383,8 @@ class BasePatch {
396
383
  const _ObservablePatch = class extends BasePatch {
397
384
  constructor(selection, operations, client) {
398
385
  super(selection, operations);
399
- __privateAdd$7(this, _client$6, void 0);
400
- __privateSet$7(this, _client$6, client);
386
+ __privateAdd$6(this, _client$5, void 0);
387
+ __privateSet$6(this, _client$5, client);
401
388
  }
402
389
  /**
403
390
  * Clones the patch
@@ -405,10 +392,10 @@ const _ObservablePatch = class extends BasePatch {
405
392
  clone() {
406
393
  return new _ObservablePatch(this.selection, {
407
394
  ...this.operations
408
- }, __privateGet$7(this, _client$6));
395
+ }, __privateGet$6(this, _client$5));
409
396
  }
410
397
  commit(options) {
411
- if (!__privateGet$7(this, _client$6)) {
398
+ if (!__privateGet$6(this, _client$5)) {
412
399
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
413
400
  }
414
401
  const returnFirst = typeof this.selection === "string";
@@ -416,18 +403,18 @@ const _ObservablePatch = class extends BasePatch {
416
403
  returnFirst,
417
404
  returnDocuments: true
418
405
  }, options);
419
- return __privateGet$7(this, _client$6).mutate({
406
+ return __privateGet$6(this, _client$5).mutate({
420
407
  patch: this.serialize()
421
408
  }, opts);
422
409
  }
423
410
  };
424
411
  let ObservablePatch = _ObservablePatch;
425
- _client$6 = new WeakMap();
412
+ _client$5 = new WeakMap();
426
413
  const _Patch = class extends BasePatch {
427
414
  constructor(selection, operations, client) {
428
415
  super(selection, operations);
429
- __privateAdd$7(this, _client2$6, void 0);
430
- __privateSet$7(this, _client2$6, client);
416
+ __privateAdd$6(this, _client2$5, void 0);
417
+ __privateSet$6(this, _client2$5, client);
431
418
  }
432
419
  /**
433
420
  * Clones the patch
@@ -435,10 +422,10 @@ const _Patch = class extends BasePatch {
435
422
  clone() {
436
423
  return new _Patch(this.selection, {
437
424
  ...this.operations
438
- }, __privateGet$7(this, _client2$6));
425
+ }, __privateGet$6(this, _client2$5));
439
426
  }
440
427
  commit(options) {
441
- if (!__privateGet$7(this, _client2$6)) {
428
+ if (!__privateGet$6(this, _client2$5)) {
442
429
  throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
443
430
  }
444
431
  const returnFirst = typeof this.selection === "string";
@@ -446,30 +433,30 @@ const _Patch = class extends BasePatch {
446
433
  returnFirst,
447
434
  returnDocuments: true
448
435
  }, options);
449
- return __privateGet$7(this, _client2$6).mutate({
436
+ return __privateGet$6(this, _client2$5).mutate({
450
437
  patch: this.serialize()
451
438
  }, opts);
452
439
  }
453
440
  };
454
441
  let Patch = _Patch;
455
- _client2$6 = new WeakMap();
456
- var __accessCheck$6 = (obj, member, msg) => {
442
+ _client2$5 = new WeakMap();
443
+ var __accessCheck$5 = (obj, member, msg) => {
457
444
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
458
445
  };
459
- var __privateGet$6 = (obj, member, getter) => {
460
- __accessCheck$6(obj, member, "read from private field");
446
+ var __privateGet$5 = (obj, member, getter) => {
447
+ __accessCheck$5(obj, member, "read from private field");
461
448
  return getter ? getter.call(obj) : member.get(obj);
462
449
  };
463
- var __privateAdd$6 = (obj, member, value) => {
450
+ var __privateAdd$5 = (obj, member, value) => {
464
451
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
465
452
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
466
453
  };
467
- var __privateSet$6 = (obj, member, value, setter) => {
468
- __accessCheck$6(obj, member, "write to private field");
454
+ var __privateSet$5 = (obj, member, value, setter) => {
455
+ __accessCheck$5(obj, member, "write to private field");
469
456
  setter ? setter.call(obj, value) : member.set(obj, value);
470
457
  return value;
471
458
  };
472
- var _client$5, _client2$5;
459
+ var _client$4, _client2$4;
473
460
  const defaultMutateOptions = {
474
461
  returnDocuments: false
475
462
  };
@@ -568,20 +555,20 @@ class BaseTransaction {
568
555
  const _Transaction = class extends BaseTransaction {
569
556
  constructor(operations, client, transactionId) {
570
557
  super(operations, transactionId);
571
- __privateAdd$6(this, _client$5, void 0);
572
- __privateSet$6(this, _client$5, client);
558
+ __privateAdd$5(this, _client$4, void 0);
559
+ __privateSet$5(this, _client$4, client);
573
560
  }
574
561
  /**
575
562
  * Clones the transaction
576
563
  */
577
564
  clone() {
578
- return new _Transaction([...this.operations], __privateGet$6(this, _client$5), this.trxId);
565
+ return new _Transaction([...this.operations], __privateGet$5(this, _client$4), this.trxId);
579
566
  }
580
567
  commit(options) {
581
- if (!__privateGet$6(this, _client$5)) {
568
+ if (!__privateGet$5(this, _client$4)) {
582
569
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
583
570
  }
584
- return __privateGet$6(this, _client$5).mutate(this.serialize(), Object.assign({
571
+ return __privateGet$5(this, _client$4).mutate(this.serialize(), Object.assign({
585
572
  transactionId: this.trxId
586
573
  }, defaultMutateOptions, options || {}));
587
574
  }
@@ -594,7 +581,7 @@ const _Transaction = class extends BaseTransaction {
594
581
  });
595
582
  }
596
583
  if (isBuilder) {
597
- const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$6(this, _client$5)));
584
+ const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$5(this, _client$4)));
598
585
  if (!(patch instanceof Patch)) {
599
586
  throw new Error("function passed to `patch()` must return the patch");
600
587
  }
@@ -611,24 +598,24 @@ const _Transaction = class extends BaseTransaction {
611
598
  }
612
599
  };
613
600
  let Transaction = _Transaction;
614
- _client$5 = new WeakMap();
601
+ _client$4 = new WeakMap();
615
602
  const _ObservableTransaction = class extends BaseTransaction {
616
603
  constructor(operations, client, transactionId) {
617
604
  super(operations, transactionId);
618
- __privateAdd$6(this, _client2$5, void 0);
619
- __privateSet$6(this, _client2$5, client);
605
+ __privateAdd$5(this, _client2$4, void 0);
606
+ __privateSet$5(this, _client2$4, client);
620
607
  }
621
608
  /**
622
609
  * Clones the transaction
623
610
  */
624
611
  clone() {
625
- return new _ObservableTransaction([...this.operations], __privateGet$6(this, _client2$5), this.trxId);
612
+ return new _ObservableTransaction([...this.operations], __privateGet$5(this, _client2$4), this.trxId);
626
613
  }
627
614
  commit(options) {
628
- if (!__privateGet$6(this, _client2$5)) {
615
+ if (!__privateGet$5(this, _client2$4)) {
629
616
  throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
630
617
  }
631
- return __privateGet$6(this, _client2$5).mutate(this.serialize(), Object.assign({
618
+ return __privateGet$5(this, _client2$4).mutate(this.serialize(), Object.assign({
632
619
  transactionId: this.trxId
633
620
  }, defaultMutateOptions, options || {}));
634
621
  }
@@ -641,7 +628,7 @@ const _ObservableTransaction = class extends BaseTransaction {
641
628
  });
642
629
  }
643
630
  if (isBuilder) {
644
- const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$6(this, _client2$5)));
631
+ const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$5(this, _client2$4)));
645
632
  if (!(patch instanceof ObservablePatch)) {
646
633
  throw new Error("function passed to `patch()` must return the patch");
647
634
  }
@@ -658,7 +645,7 @@ const _ObservableTransaction = class extends BaseTransaction {
658
645
  }
659
646
  };
660
647
  let ObservableTransaction = _ObservableTransaction;
661
- _client2$5 = new WeakMap();
648
+ _client2$4 = new WeakMap();
662
649
  const excludeFalsey = (param, defValue) => {
663
650
  const value = typeof param === "undefined" ? defValue : param;
664
651
  return param === false ? void 0 : value;
@@ -830,50 +817,50 @@ function _getUrl(client, uri) {
830
817
  const base = canUseCdn ? cdnUrl : url;
831
818
  return "".concat(base, "/").concat(uri.replace(/^\//, ""));
832
819
  }
833
- var __accessCheck$5 = (obj, member, msg) => {
820
+ var __accessCheck$4 = (obj, member, msg) => {
834
821
  if (!member.has(obj)) throw TypeError("Cannot " + msg);
835
822
  };
836
- var __privateGet$5 = (obj, member, getter) => {
837
- __accessCheck$5(obj, member, "read from private field");
823
+ var __privateGet$4 = (obj, member, getter) => {
824
+ __accessCheck$4(obj, member, "read from private field");
838
825
  return getter ? getter.call(obj) : member.get(obj);
839
826
  };
840
- var __privateAdd$5 = (obj, member, value) => {
827
+ var __privateAdd$4 = (obj, member, value) => {
841
828
  if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
842
829
  member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
843
830
  };
844
- var __privateSet$5 = (obj, member, value, setter) => {
845
- __accessCheck$5(obj, member, "write to private field");
831
+ var __privateSet$4 = (obj, member, value, setter) => {
832
+ __accessCheck$4(obj, member, "write to private field");
846
833
  setter ? setter.call(obj, value) : member.set(obj, value);
847
834
  return value;
848
835
  };
849
- var _client$4, _httpRequest$5, _client2$4, _httpRequest2$5;
836
+ var _client$3, _httpRequest$4, _client2$3, _httpRequest2$4;
850
837
  class ObservableAssetsClient {
851
838
  constructor(client, httpRequest) {
852
- __privateAdd$5(this, _client$4, void 0);
853
- __privateAdd$5(this, _httpRequest$5, void 0);
854
- __privateSet$5(this, _client$4, client);
855
- __privateSet$5(this, _httpRequest$5, httpRequest);
839
+ __privateAdd$4(this, _client$3, void 0);
840
+ __privateAdd$4(this, _httpRequest$4, void 0);
841
+ __privateSet$4(this, _client$3, client);
842
+ __privateSet$4(this, _httpRequest$4, httpRequest);
856
843
  }
857
844
  upload(assetType, body, options) {
858
- return _upload(__privateGet$5(this, _client$4), __privateGet$5(this, _httpRequest$5), assetType, body, options);
845
+ return _upload(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), assetType, body, options);
859
846
  }
860
847
  }
861
- _client$4 = new WeakMap();
862
- _httpRequest$5 = new WeakMap();
848
+ _client$3 = new WeakMap();
849
+ _httpRequest$4 = new WeakMap();
863
850
  class AssetsClient {
864
851
  constructor(client, httpRequest) {
865
- __privateAdd$5(this, _client2$4, void 0);
866
- __privateAdd$5(this, _httpRequest2$5, void 0);
867
- __privateSet$5(this, _client2$4, client);
868
- __privateSet$5(this, _httpRequest2$5, httpRequest);
852
+ __privateAdd$4(this, _client2$3, void 0);
853
+ __privateAdd$4(this, _httpRequest2$4, void 0);
854
+ __privateSet$4(this, _client2$3, client);
855
+ __privateSet$4(this, _httpRequest2$4, httpRequest);
869
856
  }
870
857
  upload(assetType, body, options) {
871
- const observable = _upload(__privateGet$5(this, _client2$4), __privateGet$5(this, _httpRequest2$5), assetType, body, options);
858
+ const observable = _upload(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), assetType, body, options);
872
859
  return rxjs.lastValueFrom(observable.pipe(operators.filter(event => event.type === "response"), operators.map(event => event.body.document)));
873
860
  }
874
861
  }
875
- _client2$4 = new WeakMap();
876
- _httpRequest2$5 = new WeakMap();
862
+ _client2$3 = new WeakMap();
863
+ _httpRequest2$4 = new WeakMap();
877
864
  function _upload(client, httpRequest, assetType, body) {
878
865
  let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
879
866
  validateAssetType(assetType);
@@ -927,77 +914,6 @@ function optionsFromFile(opts, file) {
927
914
  contentType: file.type
928
915
  }, opts);
929
916
  }
930
- var __accessCheck$4 = (obj, member, msg) => {
931
- if (!member.has(obj)) throw TypeError("Cannot " + msg);
932
- };
933
- var __privateGet$4 = (obj, member, getter) => {
934
- __accessCheck$4(obj, member, "read from private field");
935
- return getter ? getter.call(obj) : member.get(obj);
936
- };
937
- var __privateAdd$4 = (obj, member, value) => {
938
- if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
939
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
940
- };
941
- var __privateSet$4 = (obj, member, value, setter) => {
942
- __accessCheck$4(obj, member, "write to private field");
943
- setter ? setter.call(obj, value) : member.set(obj, value);
944
- return value;
945
- };
946
- var _client$3, _httpRequest$4, _client2$3, _httpRequest2$4;
947
- class ObservableAuthClient {
948
- constructor(client, httpRequest) {
949
- __privateAdd$4(this, _client$3, void 0);
950
- __privateAdd$4(this, _httpRequest$4, void 0);
951
- __privateSet$4(this, _client$3, client);
952
- __privateSet$4(this, _httpRequest$4, httpRequest);
953
- }
954
- /**
955
- * Fetch available login providers
956
- */
957
- getLoginProviders() {
958
- return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
959
- uri: "/auth/providers"
960
- });
961
- }
962
- /**
963
- * Revoke the configured session/token
964
- */
965
- logout() {
966
- return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
967
- uri: "/auth/logout",
968
- method: "POST"
969
- });
970
- }
971
- }
972
- _client$3 = new WeakMap();
973
- _httpRequest$4 = new WeakMap();
974
- class AuthClient {
975
- constructor(client, httpRequest) {
976
- __privateAdd$4(this, _client2$3, void 0);
977
- __privateAdd$4(this, _httpRequest2$4, void 0);
978
- __privateSet$4(this, _client2$3, client);
979
- __privateSet$4(this, _httpRequest2$4, httpRequest);
980
- }
981
- /**
982
- * Fetch available login providers
983
- */
984
- getLoginProviders() {
985
- return rxjs.lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
986
- uri: "/auth/providers"
987
- }));
988
- }
989
- /**
990
- * Revoke the configured session/token
991
- */
992
- logout() {
993
- return rxjs.lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
994
- uri: "/auth/logout",
995
- method: "POST"
996
- }));
997
- }
998
- }
999
- _client2$3 = new WeakMap();
1000
- _httpRequest2$4 = new WeakMap();
1001
917
  const BASE_URL = "https://www.sanity.io/help/";
1002
918
  function generateHelpUrl(slug) {
1003
919
  return BASE_URL + slug;
@@ -1503,7 +1419,6 @@ const _ObservableSanityClient = class {
1503
1419
  this.config(config);
1504
1420
  __privateSet(this, _httpRequest, httpRequest);
1505
1421
  this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
1506
- this.auth = new ObservableAuthClient(this, __privateGet(this, _httpRequest));
1507
1422
  this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest));
1508
1423
  this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest));
1509
1424
  this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
@@ -1622,7 +1537,6 @@ const _SanityClient = class {
1622
1537
  this.config(config);
1623
1538
  __privateSet(this, _httpRequest2, httpRequest);
1624
1539
  this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
1625
- this.auth = new AuthClient(this, __privateGet(this, _httpRequest2));
1626
1540
  this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2));
1627
1541
  this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2));
1628
1542
  this.users = new UsersClient(this, __privateGet(this, _httpRequest2));