@sanity/client 5.0.0-esm.2 → 5.0.0-esm.4
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 +442 -17
- package/dist/index.browser.cjs +252 -176
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +252 -176
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +253 -177
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +425 -367
- package/dist/index.js +253 -177
- package/dist/index.js.map +1 -1
- package/package.json +32 -29
- package/src/SanityClient.ts +181 -242
- package/src/assets/AssetsClient.ts +14 -12
- package/src/auth/AuthClient.ts +15 -9
- package/src/config.ts +2 -2
- package/src/data/dataMethods.ts +32 -4
- package/src/data/listen.ts +10 -9
- package/src/data/patch.ts +34 -31
- package/src/data/transaction.ts +5 -0
- package/src/datasets/DatasetsClient.ts +75 -57
- package/src/http/errors.ts +2 -0
- package/src/http/request.ts +1 -3
- package/src/index.browser.ts +3 -3
- package/src/index.ts +3 -42
- package/src/projects/ProjectsClient.ts +39 -23
- package/src/types.ts +60 -0
- package/src/users/UsersClient.ts +37 -28
- package/src/validators.ts +4 -2
- package/umd/sanityClient.js +5449 -5396
- package/umd/sanityClient.min.js +12 -12
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { BaseError } from 'make-error';
|
|
|
5
5
|
import { map, filter } from 'rxjs/operators';
|
|
6
6
|
import polyfilledEventSource from '@sanity/eventsource';
|
|
7
7
|
var name = "@sanity/client";
|
|
8
|
-
var version = "5.0.0-esm.
|
|
8
|
+
var version = "5.0.0-esm.4";
|
|
9
9
|
const middleware = [debug({
|
|
10
10
|
verbose: true,
|
|
11
11
|
namespace: "sanity:client"
|
|
@@ -206,23 +206,23 @@ var encodeQueryString = _ref => {
|
|
|
206
206
|
return options[option] ? "".concat(qs, "&").concat(enc(option), "=").concat(enc(options[option])) : qs;
|
|
207
207
|
}, qString);
|
|
208
208
|
};
|
|
209
|
-
var __accessCheck$
|
|
209
|
+
var __accessCheck$7 = (obj, member, msg) => {
|
|
210
210
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
211
211
|
};
|
|
212
|
-
var __privateGet$
|
|
213
|
-
__accessCheck$
|
|
212
|
+
var __privateGet$7 = (obj, member, getter) => {
|
|
213
|
+
__accessCheck$7(obj, member, "read from private field");
|
|
214
214
|
return getter ? getter.call(obj) : member.get(obj);
|
|
215
215
|
};
|
|
216
|
-
var __privateAdd$
|
|
216
|
+
var __privateAdd$7 = (obj, member, value) => {
|
|
217
217
|
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
218
218
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
219
219
|
};
|
|
220
|
-
var __privateSet$
|
|
221
|
-
__accessCheck$
|
|
220
|
+
var __privateSet$7 = (obj, member, value, setter) => {
|
|
221
|
+
__accessCheck$7(obj, member, "write to private field");
|
|
222
222
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
223
223
|
return value;
|
|
224
224
|
};
|
|
225
|
-
var _client$
|
|
225
|
+
var _client$6, _client2$6;
|
|
226
226
|
class BasePatch {
|
|
227
227
|
constructor(selection) {
|
|
228
228
|
let operations = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
@@ -313,16 +313,16 @@ class BasePatch {
|
|
|
313
313
|
const _ObservablePatch = class extends BasePatch {
|
|
314
314
|
constructor(selection, operations, client) {
|
|
315
315
|
super(selection, operations);
|
|
316
|
-
__privateAdd$
|
|
317
|
-
__privateSet$
|
|
316
|
+
__privateAdd$7(this, _client$6, void 0);
|
|
317
|
+
__privateSet$7(this, _client$6, client);
|
|
318
318
|
}
|
|
319
319
|
clone() {
|
|
320
320
|
return new _ObservablePatch(this.selection, {
|
|
321
321
|
...this.operations
|
|
322
|
-
}, __privateGet$
|
|
322
|
+
}, __privateGet$7(this, _client$6));
|
|
323
323
|
}
|
|
324
324
|
commit(options) {
|
|
325
|
-
if (!__privateGet$
|
|
325
|
+
if (!__privateGet$7(this, _client$6)) {
|
|
326
326
|
throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
327
327
|
}
|
|
328
328
|
const returnFirst = typeof this.selection === "string";
|
|
@@ -330,26 +330,26 @@ const _ObservablePatch = class extends BasePatch {
|
|
|
330
330
|
returnFirst,
|
|
331
331
|
returnDocuments: true
|
|
332
332
|
}, options);
|
|
333
|
-
return __privateGet$
|
|
333
|
+
return __privateGet$7(this, _client$6).mutate({
|
|
334
334
|
patch: this.serialize()
|
|
335
335
|
}, opts);
|
|
336
336
|
}
|
|
337
337
|
};
|
|
338
338
|
let ObservablePatch = _ObservablePatch;
|
|
339
|
-
_client$
|
|
339
|
+
_client$6 = new WeakMap();
|
|
340
340
|
const _Patch = class extends BasePatch {
|
|
341
341
|
constructor(selection, operations, client) {
|
|
342
342
|
super(selection, operations);
|
|
343
|
-
__privateAdd$
|
|
344
|
-
__privateSet$
|
|
343
|
+
__privateAdd$7(this, _client2$6, void 0);
|
|
344
|
+
__privateSet$7(this, _client2$6, client);
|
|
345
345
|
}
|
|
346
346
|
clone() {
|
|
347
347
|
return new _Patch(this.selection, {
|
|
348
348
|
...this.operations
|
|
349
|
-
}, __privateGet$
|
|
349
|
+
}, __privateGet$7(this, _client2$6));
|
|
350
350
|
}
|
|
351
351
|
commit(options) {
|
|
352
|
-
if (!__privateGet$
|
|
352
|
+
if (!__privateGet$7(this, _client2$6)) {
|
|
353
353
|
throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
354
354
|
}
|
|
355
355
|
const returnFirst = typeof this.selection === "string";
|
|
@@ -357,30 +357,30 @@ const _Patch = class extends BasePatch {
|
|
|
357
357
|
returnFirst,
|
|
358
358
|
returnDocuments: true
|
|
359
359
|
}, options);
|
|
360
|
-
return __privateGet$
|
|
360
|
+
return __privateGet$7(this, _client2$6).mutate({
|
|
361
361
|
patch: this.serialize()
|
|
362
362
|
}, opts);
|
|
363
363
|
}
|
|
364
364
|
};
|
|
365
365
|
let Patch = _Patch;
|
|
366
|
-
_client2$
|
|
367
|
-
var __accessCheck$
|
|
366
|
+
_client2$6 = new WeakMap();
|
|
367
|
+
var __accessCheck$6 = (obj, member, msg) => {
|
|
368
368
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
369
369
|
};
|
|
370
|
-
var __privateGet$
|
|
371
|
-
__accessCheck$
|
|
370
|
+
var __privateGet$6 = (obj, member, getter) => {
|
|
371
|
+
__accessCheck$6(obj, member, "read from private field");
|
|
372
372
|
return getter ? getter.call(obj) : member.get(obj);
|
|
373
373
|
};
|
|
374
|
-
var __privateAdd$
|
|
374
|
+
var __privateAdd$6 = (obj, member, value) => {
|
|
375
375
|
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
376
376
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
377
377
|
};
|
|
378
|
-
var __privateSet$
|
|
379
|
-
__accessCheck$
|
|
378
|
+
var __privateSet$6 = (obj, member, value, setter) => {
|
|
379
|
+
__accessCheck$6(obj, member, "write to private field");
|
|
380
380
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
381
381
|
return value;
|
|
382
382
|
};
|
|
383
|
-
var _client$
|
|
383
|
+
var _client$5, _client2$5;
|
|
384
384
|
const defaultMutateOptions = {
|
|
385
385
|
returnDocuments: false
|
|
386
386
|
};
|
|
@@ -446,17 +446,17 @@ class BaseTransaction {
|
|
|
446
446
|
const _Transaction = class extends BaseTransaction {
|
|
447
447
|
constructor(operations, client, transactionId) {
|
|
448
448
|
super(operations, transactionId);
|
|
449
|
-
__privateAdd$
|
|
450
|
-
__privateSet$
|
|
449
|
+
__privateAdd$6(this, _client$5, void 0);
|
|
450
|
+
__privateSet$6(this, _client$5, client);
|
|
451
451
|
}
|
|
452
452
|
clone() {
|
|
453
|
-
return new _Transaction([...this.operations], __privateGet$
|
|
453
|
+
return new _Transaction([...this.operations], __privateGet$6(this, _client$5), this.trxId);
|
|
454
454
|
}
|
|
455
455
|
commit(options) {
|
|
456
|
-
if (!__privateGet$
|
|
456
|
+
if (!__privateGet$6(this, _client$5)) {
|
|
457
457
|
throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
458
458
|
}
|
|
459
|
-
return __privateGet$
|
|
459
|
+
return __privateGet$6(this, _client$5).mutate(this.serialize(), Object.assign({
|
|
460
460
|
transactionId: this.trxId
|
|
461
461
|
}, defaultMutateOptions, options || {}));
|
|
462
462
|
}
|
|
@@ -469,7 +469,7 @@ const _Transaction = class extends BaseTransaction {
|
|
|
469
469
|
});
|
|
470
470
|
}
|
|
471
471
|
if (isBuilder) {
|
|
472
|
-
const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$
|
|
472
|
+
const patch = patchOps(new Patch(patchOrDocumentId, {}, __privateGet$6(this, _client$5)));
|
|
473
473
|
if (!(patch instanceof Patch)) {
|
|
474
474
|
throw new Error("function passed to `patch()` must return the patch");
|
|
475
475
|
}
|
|
@@ -486,21 +486,21 @@ const _Transaction = class extends BaseTransaction {
|
|
|
486
486
|
}
|
|
487
487
|
};
|
|
488
488
|
let Transaction = _Transaction;
|
|
489
|
-
_client$
|
|
489
|
+
_client$5 = new WeakMap();
|
|
490
490
|
const _ObservableTransaction = class extends BaseTransaction {
|
|
491
491
|
constructor(operations, client, transactionId) {
|
|
492
492
|
super(operations, transactionId);
|
|
493
|
-
__privateAdd$
|
|
494
|
-
__privateSet$
|
|
493
|
+
__privateAdd$6(this, _client2$5, void 0);
|
|
494
|
+
__privateSet$6(this, _client2$5, client);
|
|
495
495
|
}
|
|
496
496
|
clone() {
|
|
497
|
-
return new _ObservableTransaction([...this.operations], __privateGet$
|
|
497
|
+
return new _ObservableTransaction([...this.operations], __privateGet$6(this, _client2$5), this.trxId);
|
|
498
498
|
}
|
|
499
499
|
commit(options) {
|
|
500
|
-
if (!__privateGet$
|
|
500
|
+
if (!__privateGet$6(this, _client2$5)) {
|
|
501
501
|
throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
502
502
|
}
|
|
503
|
-
return __privateGet$
|
|
503
|
+
return __privateGet$6(this, _client2$5).mutate(this.serialize(), Object.assign({
|
|
504
504
|
transactionId: this.trxId
|
|
505
505
|
}, defaultMutateOptions, options || {}));
|
|
506
506
|
}
|
|
@@ -513,7 +513,7 @@ const _ObservableTransaction = class extends BaseTransaction {
|
|
|
513
513
|
});
|
|
514
514
|
}
|
|
515
515
|
if (isBuilder) {
|
|
516
|
-
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$
|
|
516
|
+
const patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, __privateGet$6(this, _client2$5)));
|
|
517
517
|
if (!(patch instanceof ObservablePatch)) {
|
|
518
518
|
throw new Error("function passed to `patch()` must return the patch");
|
|
519
519
|
}
|
|
@@ -530,7 +530,7 @@ const _ObservableTransaction = class extends BaseTransaction {
|
|
|
530
530
|
}
|
|
531
531
|
};
|
|
532
532
|
let ObservableTransaction = _ObservableTransaction;
|
|
533
|
-
_client2$
|
|
533
|
+
_client2$5 = new WeakMap();
|
|
534
534
|
const excludeFalsey = (param, defValue) => {
|
|
535
535
|
const value = typeof param === "undefined" ? defValue : param;
|
|
536
536
|
return param === false ? void 0 : value;
|
|
@@ -564,7 +564,7 @@ function _fetch(client, httpRequest, query, params) {
|
|
|
564
564
|
function _getDocument(client, httpRequest, id) {
|
|
565
565
|
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
566
566
|
const options = {
|
|
567
|
-
uri: client
|
|
567
|
+
uri: _getDataUrl(client, "doc", id),
|
|
568
568
|
json: true,
|
|
569
569
|
tag: opts.tag
|
|
570
570
|
};
|
|
@@ -573,7 +573,7 @@ function _getDocument(client, httpRequest, id) {
|
|
|
573
573
|
function _getDocuments(client, httpRequest, ids) {
|
|
574
574
|
let opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
575
575
|
const options = {
|
|
576
|
-
uri: client
|
|
576
|
+
uri: _getDataUrl(client, "doc", ids.join(",")),
|
|
577
577
|
json: true,
|
|
578
578
|
tag: opts.tag
|
|
579
579
|
};
|
|
@@ -620,7 +620,7 @@ function _dataRequest(client, httpRequest, endpoint, body) {
|
|
|
620
620
|
tag,
|
|
621
621
|
headers
|
|
622
622
|
} = options;
|
|
623
|
-
const uri = client
|
|
623
|
+
const uri = _getDataUrl(client, endpoint, stringQuery);
|
|
624
624
|
const reqOptions = {
|
|
625
625
|
method: useGet ? "GET" : "POST",
|
|
626
626
|
uri,
|
|
@@ -676,7 +676,7 @@ function _requestObservable(client, httpRequest, options) {
|
|
|
676
676
|
};
|
|
677
677
|
}
|
|
678
678
|
const reqOptions = getRequestOptions(config, Object.assign({}, options, {
|
|
679
|
-
url: client
|
|
679
|
+
url: _getUrl(client, uri, useCdn)
|
|
680
680
|
}));
|
|
681
681
|
return new Observable(subscriber => httpRequest(reqOptions, config.requester).subscribe(subscriber));
|
|
682
682
|
}
|
|
@@ -684,50 +684,66 @@ function _request(client, httpRequest, options) {
|
|
|
684
684
|
const observable = _requestObservable(client, httpRequest, options).pipe(filter(event => event.type === "response"), map(event => event.body));
|
|
685
685
|
return observable;
|
|
686
686
|
}
|
|
687
|
-
|
|
687
|
+
function _getDataUrl(client, operation, path) {
|
|
688
|
+
const config = client.config();
|
|
689
|
+
const catalog = hasDataset(config);
|
|
690
|
+
const baseUri = "/".concat(operation, "/").concat(catalog);
|
|
691
|
+
const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
|
|
692
|
+
return "/data".concat(uri).replace(/\/($|\?)/, "$1");
|
|
693
|
+
}
|
|
694
|
+
function _getUrl(client, uri) {
|
|
695
|
+
let canUseCdn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
696
|
+
const {
|
|
697
|
+
url,
|
|
698
|
+
cdnUrl
|
|
699
|
+
} = client.config();
|
|
700
|
+
const base = canUseCdn ? cdnUrl : url;
|
|
701
|
+
return "".concat(base, "/").concat(uri.replace(/^\//, ""));
|
|
702
|
+
}
|
|
703
|
+
var __accessCheck$5 = (obj, member, msg) => {
|
|
688
704
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
689
705
|
};
|
|
690
|
-
var __privateGet$
|
|
691
|
-
__accessCheck$
|
|
706
|
+
var __privateGet$5 = (obj, member, getter) => {
|
|
707
|
+
__accessCheck$5(obj, member, "read from private field");
|
|
692
708
|
return getter ? getter.call(obj) : member.get(obj);
|
|
693
709
|
};
|
|
694
|
-
var __privateAdd$
|
|
710
|
+
var __privateAdd$5 = (obj, member, value) => {
|
|
695
711
|
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
696
712
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
697
713
|
};
|
|
698
|
-
var __privateSet$
|
|
699
|
-
__accessCheck$
|
|
714
|
+
var __privateSet$5 = (obj, member, value, setter) => {
|
|
715
|
+
__accessCheck$5(obj, member, "write to private field");
|
|
700
716
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
701
717
|
return value;
|
|
702
718
|
};
|
|
703
|
-
var _client$
|
|
719
|
+
var _client$4, _httpRequest$5, _client2$4, _httpRequest2$5;
|
|
704
720
|
class ObservableAssetsClient {
|
|
705
721
|
constructor(client, httpRequest) {
|
|
706
|
-
__privateAdd$
|
|
707
|
-
__privateAdd$
|
|
708
|
-
__privateSet$
|
|
709
|
-
__privateSet$
|
|
722
|
+
__privateAdd$5(this, _client$4, void 0);
|
|
723
|
+
__privateAdd$5(this, _httpRequest$5, void 0);
|
|
724
|
+
__privateSet$5(this, _client$4, client);
|
|
725
|
+
__privateSet$5(this, _httpRequest$5, httpRequest);
|
|
710
726
|
}
|
|
711
727
|
upload(assetType, body, options) {
|
|
712
|
-
return _upload(__privateGet$
|
|
728
|
+
return _upload(__privateGet$5(this, _client$4), __privateGet$5(this, _httpRequest$5), assetType, body, options);
|
|
713
729
|
}
|
|
714
730
|
}
|
|
715
|
-
_client$
|
|
716
|
-
_httpRequest$
|
|
731
|
+
_client$4 = new WeakMap();
|
|
732
|
+
_httpRequest$5 = new WeakMap();
|
|
717
733
|
class AssetsClient {
|
|
718
734
|
constructor(client, httpRequest) {
|
|
719
|
-
__privateAdd$
|
|
720
|
-
__privateAdd$
|
|
721
|
-
__privateSet$
|
|
722
|
-
__privateSet$
|
|
735
|
+
__privateAdd$5(this, _client2$4, void 0);
|
|
736
|
+
__privateAdd$5(this, _httpRequest2$5, void 0);
|
|
737
|
+
__privateSet$5(this, _client2$4, client);
|
|
738
|
+
__privateSet$5(this, _httpRequest2$5, httpRequest);
|
|
723
739
|
}
|
|
724
740
|
upload(assetType, body, options) {
|
|
725
|
-
const observable = _upload(__privateGet$
|
|
741
|
+
const observable = _upload(__privateGet$5(this, _client2$4), __privateGet$5(this, _httpRequest2$5), assetType, body, options);
|
|
726
742
|
return lastValueFrom(observable.pipe(filter(event => event.type === "response"), map(event => event.body.document)));
|
|
727
743
|
}
|
|
728
744
|
}
|
|
729
|
-
_client2$
|
|
730
|
-
_httpRequest2$
|
|
745
|
+
_client2$4 = new WeakMap();
|
|
746
|
+
_httpRequest2$5 = new WeakMap();
|
|
731
747
|
function _upload(client, httpRequest, assetType, body) {
|
|
732
748
|
let opts = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
733
749
|
validateAssetType(assetType);
|
|
@@ -781,65 +797,65 @@ function optionsFromFile(opts, file) {
|
|
|
781
797
|
contentType: file.type
|
|
782
798
|
}, opts);
|
|
783
799
|
}
|
|
784
|
-
var __accessCheck$
|
|
800
|
+
var __accessCheck$4 = (obj, member, msg) => {
|
|
785
801
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
786
802
|
};
|
|
787
|
-
var __privateGet$
|
|
788
|
-
__accessCheck$
|
|
803
|
+
var __privateGet$4 = (obj, member, getter) => {
|
|
804
|
+
__accessCheck$4(obj, member, "read from private field");
|
|
789
805
|
return getter ? getter.call(obj) : member.get(obj);
|
|
790
806
|
};
|
|
791
|
-
var __privateAdd$
|
|
807
|
+
var __privateAdd$4 = (obj, member, value) => {
|
|
792
808
|
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
793
809
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
794
810
|
};
|
|
795
|
-
var __privateSet$
|
|
796
|
-
__accessCheck$
|
|
811
|
+
var __privateSet$4 = (obj, member, value, setter) => {
|
|
812
|
+
__accessCheck$4(obj, member, "write to private field");
|
|
797
813
|
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
798
814
|
return value;
|
|
799
815
|
};
|
|
800
|
-
var _client, _httpRequest$
|
|
816
|
+
var _client$3, _httpRequest$4, _client2$3, _httpRequest2$4;
|
|
801
817
|
class ObservableAuthClient {
|
|
802
818
|
constructor(client, httpRequest) {
|
|
803
|
-
__privateAdd$
|
|
804
|
-
__privateAdd$
|
|
805
|
-
__privateSet$
|
|
806
|
-
__privateSet$
|
|
819
|
+
__privateAdd$4(this, _client$3, void 0);
|
|
820
|
+
__privateAdd$4(this, _httpRequest$4, void 0);
|
|
821
|
+
__privateSet$4(this, _client$3, client);
|
|
822
|
+
__privateSet$4(this, _httpRequest$4, httpRequest);
|
|
807
823
|
}
|
|
808
824
|
getLoginProviders() {
|
|
809
|
-
return _request(__privateGet$
|
|
825
|
+
return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
|
|
810
826
|
uri: "/auth/providers"
|
|
811
827
|
});
|
|
812
828
|
}
|
|
813
829
|
logout() {
|
|
814
|
-
return _request(__privateGet$
|
|
830
|
+
return _request(__privateGet$4(this, _client$3), __privateGet$4(this, _httpRequest$4), {
|
|
815
831
|
uri: "/auth/logout",
|
|
816
832
|
method: "POST"
|
|
817
833
|
});
|
|
818
834
|
}
|
|
819
835
|
}
|
|
820
|
-
_client = new WeakMap();
|
|
821
|
-
_httpRequest$
|
|
836
|
+
_client$3 = new WeakMap();
|
|
837
|
+
_httpRequest$4 = new WeakMap();
|
|
822
838
|
class AuthClient {
|
|
823
839
|
constructor(client, httpRequest) {
|
|
824
|
-
__privateAdd$
|
|
825
|
-
__privateAdd$
|
|
826
|
-
__privateSet$
|
|
827
|
-
__privateSet$
|
|
840
|
+
__privateAdd$4(this, _client2$3, void 0);
|
|
841
|
+
__privateAdd$4(this, _httpRequest2$4, void 0);
|
|
842
|
+
__privateSet$4(this, _client2$3, client);
|
|
843
|
+
__privateSet$4(this, _httpRequest2$4, httpRequest);
|
|
828
844
|
}
|
|
829
845
|
getLoginProviders() {
|
|
830
|
-
return lastValueFrom(_request(__privateGet$
|
|
846
|
+
return lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
|
|
831
847
|
uri: "/auth/providers"
|
|
832
848
|
}));
|
|
833
849
|
}
|
|
834
850
|
logout() {
|
|
835
|
-
return lastValueFrom(_request(__privateGet$
|
|
851
|
+
return lastValueFrom(_request(__privateGet$4(this, _client2$3), __privateGet$4(this, _httpRequest2$4), {
|
|
836
852
|
uri: "/auth/logout",
|
|
837
853
|
method: "POST"
|
|
838
854
|
}));
|
|
839
855
|
}
|
|
840
856
|
}
|
|
841
|
-
_client2 = new WeakMap();
|
|
842
|
-
_httpRequest2$
|
|
857
|
+
_client2$3 = new WeakMap();
|
|
858
|
+
_httpRequest2$4 = new WeakMap();
|
|
843
859
|
const BASE_URL = "https://docs.sanity.io/help/";
|
|
844
860
|
function generateHelpUrl(slug) {
|
|
845
861
|
return BASE_URL + slug;
|
|
@@ -969,7 +985,7 @@ function _listen(query, params) {
|
|
|
969
985
|
...listenOpts
|
|
970
986
|
}
|
|
971
987
|
});
|
|
972
|
-
const uri = "".concat(url).concat(this
|
|
988
|
+
const uri = "".concat(url).concat(_getDataUrl(this, "listen", qs));
|
|
973
989
|
if (uri.length > MAX_URL_LENGTH) {
|
|
974
990
|
return new Observable(observer => observer.error(new Error("Query too large for listener")));
|
|
975
991
|
}
|
|
@@ -1072,101 +1088,183 @@ function extractErrorMessage(err) {
|
|
|
1072
1088
|
}
|
|
1073
1089
|
return typeof err.error === "string" ? err.error : JSON.stringify(err.error, null, 2);
|
|
1074
1090
|
}
|
|
1075
|
-
var __accessCheck$
|
|
1091
|
+
var __accessCheck$3 = (obj, member, msg) => {
|
|
1076
1092
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
1077
1093
|
};
|
|
1078
|
-
var
|
|
1094
|
+
var __privateGet$3 = (obj, member, getter) => {
|
|
1095
|
+
__accessCheck$3(obj, member, "read from private field");
|
|
1096
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
1097
|
+
};
|
|
1098
|
+
var __privateAdd$3 = (obj, member, value) => {
|
|
1079
1099
|
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
1080
1100
|
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1081
1101
|
};
|
|
1082
|
-
var
|
|
1083
|
-
__accessCheck$
|
|
1084
|
-
|
|
1102
|
+
var __privateSet$3 = (obj, member, value, setter) => {
|
|
1103
|
+
__accessCheck$3(obj, member, "write to private field");
|
|
1104
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1105
|
+
return value;
|
|
1085
1106
|
};
|
|
1086
|
-
var
|
|
1087
|
-
class
|
|
1088
|
-
constructor() {
|
|
1089
|
-
__privateAdd$
|
|
1107
|
+
var _client$2, _httpRequest$3, _client2$2, _httpRequest2$3;
|
|
1108
|
+
class ObservableDatasetsClient {
|
|
1109
|
+
constructor(client, httpRequest) {
|
|
1110
|
+
__privateAdd$3(this, _client$2, void 0);
|
|
1111
|
+
__privateAdd$3(this, _httpRequest$3, void 0);
|
|
1112
|
+
__privateSet$3(this, _client$2, client);
|
|
1113
|
+
__privateSet$3(this, _httpRequest$3, httpRequest);
|
|
1090
1114
|
}
|
|
1091
1115
|
create(name, options) {
|
|
1092
|
-
return
|
|
1116
|
+
return _modify(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), "PUT", name, options);
|
|
1093
1117
|
}
|
|
1094
1118
|
edit(name, options) {
|
|
1095
|
-
return
|
|
1119
|
+
return _modify(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), "PATCH", name, options);
|
|
1096
1120
|
}
|
|
1097
1121
|
delete(name) {
|
|
1098
|
-
return
|
|
1122
|
+
return _modify(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), "DELETE", name);
|
|
1099
1123
|
}
|
|
1100
1124
|
list() {
|
|
1101
|
-
return this
|
|
1125
|
+
return _request(__privateGet$3(this, _client$2), __privateGet$3(this, _httpRequest$3), {
|
|
1102
1126
|
uri: "/datasets"
|
|
1103
1127
|
});
|
|
1104
1128
|
}
|
|
1105
1129
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1130
|
+
_client$2 = new WeakMap();
|
|
1131
|
+
_httpRequest$3 = new WeakMap();
|
|
1132
|
+
class DatasetsClient {
|
|
1133
|
+
constructor(client, httpRequest) {
|
|
1134
|
+
__privateAdd$3(this, _client2$2, void 0);
|
|
1135
|
+
__privateAdd$3(this, _httpRequest2$3, void 0);
|
|
1136
|
+
__privateSet$3(this, _client2$2, client);
|
|
1137
|
+
__privateSet$3(this, _httpRequest2$3, httpRequest);
|
|
1138
|
+
}
|
|
1139
|
+
create(name, options) {
|
|
1140
|
+
return lastValueFrom(_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "PUT", name, options));
|
|
1141
|
+
}
|
|
1142
|
+
edit(name, options) {
|
|
1143
|
+
return lastValueFrom(_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "PATCH", name, options));
|
|
1144
|
+
}
|
|
1145
|
+
delete(name) {
|
|
1146
|
+
return lastValueFrom(_modify(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), "DELETE", name));
|
|
1147
|
+
}
|
|
1148
|
+
list() {
|
|
1149
|
+
return lastValueFrom(_request(__privateGet$3(this, _client2$2), __privateGet$3(this, _httpRequest2$3), {
|
|
1150
|
+
uri: "/datasets"
|
|
1151
|
+
}));
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
_client2$2 = new WeakMap();
|
|
1155
|
+
_httpRequest2$3 = new WeakMap();
|
|
1156
|
+
function _modify(client, httpRequest, method, name, options) {
|
|
1108
1157
|
dataset(name);
|
|
1109
|
-
return
|
|
1158
|
+
return _request(client, httpRequest, {
|
|
1110
1159
|
method,
|
|
1111
1160
|
uri: "/datasets/".concat(name),
|
|
1112
1161
|
body: options
|
|
1113
1162
|
});
|
|
1114
|
-
};
|
|
1115
|
-
class ObservableDatasetsClient extends BaseDatasetsClient {
|
|
1116
|
-
constructor(client) {
|
|
1117
|
-
super();
|
|
1118
|
-
this.client = client;
|
|
1119
|
-
}
|
|
1120
1163
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1164
|
+
var __accessCheck$2 = (obj, member, msg) => {
|
|
1165
|
+
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
1166
|
+
};
|
|
1167
|
+
var __privateGet$2 = (obj, member, getter) => {
|
|
1168
|
+
__accessCheck$2(obj, member, "read from private field");
|
|
1169
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
1170
|
+
};
|
|
1171
|
+
var __privateAdd$2 = (obj, member, value) => {
|
|
1172
|
+
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
1173
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1174
|
+
};
|
|
1175
|
+
var __privateSet$2 = (obj, member, value, setter) => {
|
|
1176
|
+
__accessCheck$2(obj, member, "write to private field");
|
|
1177
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1178
|
+
return value;
|
|
1179
|
+
};
|
|
1180
|
+
var _client$1, _httpRequest$2, _client2$1, _httpRequest2$2;
|
|
1181
|
+
class ObservableProjectsClient {
|
|
1182
|
+
constructor(client, httpRequest) {
|
|
1183
|
+
__privateAdd$2(this, _client$1, void 0);
|
|
1184
|
+
__privateAdd$2(this, _httpRequest$2, void 0);
|
|
1185
|
+
__privateSet$2(this, _client$1, client);
|
|
1186
|
+
__privateSet$2(this, _httpRequest$2, httpRequest);
|
|
1125
1187
|
}
|
|
1126
|
-
}
|
|
1127
|
-
class BaseProjectsClient {
|
|
1128
1188
|
list() {
|
|
1129
|
-
return this
|
|
1189
|
+
return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), {
|
|
1130
1190
|
uri: "/projects"
|
|
1131
1191
|
});
|
|
1132
1192
|
}
|
|
1133
1193
|
getById(projectId) {
|
|
1134
|
-
return this
|
|
1194
|
+
return _request(__privateGet$2(this, _client$1), __privateGet$2(this, _httpRequest$2), {
|
|
1135
1195
|
uri: "/projects/".concat(projectId)
|
|
1136
1196
|
});
|
|
1137
1197
|
}
|
|
1138
1198
|
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1199
|
+
_client$1 = new WeakMap();
|
|
1200
|
+
_httpRequest$2 = new WeakMap();
|
|
1201
|
+
class ProjectsClient {
|
|
1202
|
+
constructor(client, httpRequest) {
|
|
1203
|
+
__privateAdd$2(this, _client2$1, void 0);
|
|
1204
|
+
__privateAdd$2(this, _httpRequest2$2, void 0);
|
|
1205
|
+
__privateSet$2(this, _client2$1, client);
|
|
1206
|
+
__privateSet$2(this, _httpRequest2$2, httpRequest);
|
|
1143
1207
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1208
|
+
list() {
|
|
1209
|
+
return lastValueFrom(_request(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), {
|
|
1210
|
+
uri: "/projects"
|
|
1211
|
+
}));
|
|
1212
|
+
}
|
|
1213
|
+
getById(projectId) {
|
|
1214
|
+
return lastValueFrom(_request(__privateGet$2(this, _client2$1), __privateGet$2(this, _httpRequest2$2), {
|
|
1215
|
+
uri: "/projects/".concat(projectId)
|
|
1216
|
+
}));
|
|
1149
1217
|
}
|
|
1150
1218
|
}
|
|
1151
|
-
|
|
1219
|
+
_client2$1 = new WeakMap();
|
|
1220
|
+
_httpRequest2$2 = new WeakMap();
|
|
1221
|
+
var __accessCheck$1 = (obj, member, msg) => {
|
|
1222
|
+
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
1223
|
+
};
|
|
1224
|
+
var __privateGet$1 = (obj, member, getter) => {
|
|
1225
|
+
__accessCheck$1(obj, member, "read from private field");
|
|
1226
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
1227
|
+
};
|
|
1228
|
+
var __privateAdd$1 = (obj, member, value) => {
|
|
1229
|
+
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
|
|
1230
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1231
|
+
};
|
|
1232
|
+
var __privateSet$1 = (obj, member, value, setter) => {
|
|
1233
|
+
__accessCheck$1(obj, member, "write to private field");
|
|
1234
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
1235
|
+
return value;
|
|
1236
|
+
};
|
|
1237
|
+
var _client, _httpRequest$1, _client2, _httpRequest2$1;
|
|
1238
|
+
class ObservableUsersClient {
|
|
1239
|
+
constructor(client, httpRequest) {
|
|
1240
|
+
__privateAdd$1(this, _client, void 0);
|
|
1241
|
+
__privateAdd$1(this, _httpRequest$1, void 0);
|
|
1242
|
+
__privateSet$1(this, _client, client);
|
|
1243
|
+
__privateSet$1(this, _httpRequest$1, httpRequest);
|
|
1244
|
+
}
|
|
1152
1245
|
getById(id) {
|
|
1153
|
-
return this
|
|
1246
|
+
return _request(__privateGet$1(this, _client), __privateGet$1(this, _httpRequest$1), {
|
|
1154
1247
|
uri: "/users/".concat(id)
|
|
1155
1248
|
});
|
|
1156
1249
|
}
|
|
1157
1250
|
}
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1251
|
+
_client = new WeakMap();
|
|
1252
|
+
_httpRequest$1 = new WeakMap();
|
|
1253
|
+
class UsersClient {
|
|
1254
|
+
constructor(client, httpRequest) {
|
|
1255
|
+
__privateAdd$1(this, _client2, void 0);
|
|
1256
|
+
__privateAdd$1(this, _httpRequest2$1, void 0);
|
|
1257
|
+
__privateSet$1(this, _client2, client);
|
|
1258
|
+
__privateSet$1(this, _httpRequest2$1, httpRequest);
|
|
1162
1259
|
}
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
this.client = client;
|
|
1260
|
+
getById(id) {
|
|
1261
|
+
return lastValueFrom(_request(__privateGet$1(this, _client2), __privateGet$1(this, _httpRequest2$1), {
|
|
1262
|
+
uri: "/users/".concat(id)
|
|
1263
|
+
}));
|
|
1168
1264
|
}
|
|
1169
1265
|
}
|
|
1266
|
+
_client2 = new WeakMap();
|
|
1267
|
+
_httpRequest2$1 = new WeakMap();
|
|
1170
1268
|
var __accessCheck = (obj, member, msg) => {
|
|
1171
1269
|
if (!member.has(obj)) throw TypeError("Cannot " + msg);
|
|
1172
1270
|
};
|
|
@@ -1185,16 +1283,17 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
1185
1283
|
};
|
|
1186
1284
|
var _clientConfig, _httpRequest, _clientConfig2, _httpRequest2;
|
|
1187
1285
|
const _ObservableSanityClient = class {
|
|
1188
|
-
constructor(httpRequest
|
|
1286
|
+
constructor(httpRequest) {
|
|
1287
|
+
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1189
1288
|
__privateAdd(this, _clientConfig, void 0);
|
|
1190
1289
|
__privateAdd(this, _httpRequest, void 0);
|
|
1191
1290
|
this.config(config);
|
|
1192
1291
|
__privateSet(this, _httpRequest, httpRequest);
|
|
1193
1292
|
this.assets = new ObservableAssetsClient(this, __privateGet(this, _httpRequest));
|
|
1194
1293
|
this.auth = new ObservableAuthClient(this, __privateGet(this, _httpRequest));
|
|
1195
|
-
this.datasets = new ObservableDatasetsClient(this);
|
|
1196
|
-
this.projects = new ObservableProjectsClient(this);
|
|
1197
|
-
this.users = new ObservableUsersClient(this);
|
|
1294
|
+
this.datasets = new ObservableDatasetsClient(this, __privateGet(this, _httpRequest));
|
|
1295
|
+
this.projects = new ObservableProjectsClient(this, __privateGet(this, _httpRequest));
|
|
1296
|
+
this.users = new ObservableUsersClient(this, __privateGet(this, _httpRequest));
|
|
1198
1297
|
}
|
|
1199
1298
|
clone() {
|
|
1200
1299
|
return new _ObservableSanityClient(__privateGet(this, _httpRequest), this.config());
|
|
@@ -1251,35 +1350,24 @@ const _ObservableSanityClient = class {
|
|
|
1251
1350
|
request(options) {
|
|
1252
1351
|
return _request(this, __privateGet(this, _httpRequest), options);
|
|
1253
1352
|
}
|
|
1254
|
-
getUrl(uri) {
|
|
1255
|
-
let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1256
|
-
const base = canUseCdn ? __privateGet(this, _clientConfig).cdnUrl : __privateGet(this, _clientConfig).url;
|
|
1257
|
-
return "".concat(base, "/").concat(uri.replace(/^\//, ""));
|
|
1258
|
-
}
|
|
1259
|
-
getDataUrl(operation, path) {
|
|
1260
|
-
const config = this.config();
|
|
1261
|
-
const catalog = hasDataset(config);
|
|
1262
|
-
const baseUri = "/".concat(operation, "/").concat(catalog);
|
|
1263
|
-
const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
|
|
1264
|
-
return "/data".concat(uri).replace(/\/($|\?)/, "$1");
|
|
1265
|
-
}
|
|
1266
1353
|
};
|
|
1267
1354
|
let ObservableSanityClient = _ObservableSanityClient;
|
|
1268
1355
|
_clientConfig = new WeakMap();
|
|
1269
1356
|
_httpRequest = new WeakMap();
|
|
1270
1357
|
const _SanityClient = class {
|
|
1271
|
-
constructor(httpRequest
|
|
1358
|
+
constructor(httpRequest) {
|
|
1359
|
+
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultConfig;
|
|
1272
1360
|
__privateAdd(this, _clientConfig2, void 0);
|
|
1273
1361
|
__privateAdd(this, _httpRequest2, void 0);
|
|
1274
1362
|
this.listen = _listen;
|
|
1275
|
-
this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1276
1363
|
this.config(config);
|
|
1277
1364
|
__privateSet(this, _httpRequest2, httpRequest);
|
|
1278
1365
|
this.assets = new AssetsClient(this, __privateGet(this, _httpRequest2));
|
|
1279
1366
|
this.auth = new AuthClient(this, __privateGet(this, _httpRequest2));
|
|
1280
|
-
this.datasets = new DatasetsClient(this);
|
|
1281
|
-
this.projects = new ProjectsClient(this);
|
|
1282
|
-
this.users = new UsersClient(this);
|
|
1367
|
+
this.datasets = new DatasetsClient(this, __privateGet(this, _httpRequest2));
|
|
1368
|
+
this.projects = new ProjectsClient(this, __privateGet(this, _httpRequest2));
|
|
1369
|
+
this.users = new UsersClient(this, __privateGet(this, _httpRequest2));
|
|
1370
|
+
this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1283
1371
|
}
|
|
1284
1372
|
clone() {
|
|
1285
1373
|
return new _SanityClient(__privateGet(this, _httpRequest2), this.config());
|
|
@@ -1293,7 +1381,9 @@ const _SanityClient = class {
|
|
|
1293
1381
|
if (__privateGet(this, _clientConfig2) && __privateGet(this, _clientConfig2).allowReconfigure === false) {
|
|
1294
1382
|
throw new Error("Existing client instance cannot be reconfigured - use `withConfig(newConfig)` to return a new client");
|
|
1295
1383
|
}
|
|
1296
|
-
this.observable
|
|
1384
|
+
if (this.observable) {
|
|
1385
|
+
this.observable.config(newConfig);
|
|
1386
|
+
}
|
|
1297
1387
|
__privateSet(this, _clientConfig2, initConfig(newConfig, __privateGet(this, _clientConfig2) || {}));
|
|
1298
1388
|
return this;
|
|
1299
1389
|
}
|
|
@@ -1340,26 +1430,12 @@ const _SanityClient = class {
|
|
|
1340
1430
|
dataRequest(endpoint, body, options) {
|
|
1341
1431
|
return lastValueFrom(_dataRequest(this, __privateGet(this, _httpRequest2), endpoint, body, options));
|
|
1342
1432
|
}
|
|
1343
|
-
getUrl(uri) {
|
|
1344
|
-
let canUseCdn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1345
|
-
const base = canUseCdn ? __privateGet(this, _clientConfig2).cdnUrl : __privateGet(this, _clientConfig2).url;
|
|
1346
|
-
return "".concat(base, "/").concat(uri.replace(/^\//, ""));
|
|
1347
|
-
}
|
|
1348
|
-
getDataUrl(operation, path) {
|
|
1349
|
-
const config = this.config();
|
|
1350
|
-
const catalog = hasDataset(config);
|
|
1351
|
-
const baseUri = "/".concat(operation, "/").concat(catalog);
|
|
1352
|
-
const uri = path ? "".concat(baseUri, "/").concat(path) : baseUri;
|
|
1353
|
-
return "/data".concat(uri).replace(/\/($|\?)/, "$1");
|
|
1354
|
-
}
|
|
1355
1433
|
};
|
|
1356
1434
|
let SanityClient = _SanityClient;
|
|
1357
1435
|
_clientConfig2 = new WeakMap();
|
|
1358
1436
|
_httpRequest2 = new WeakMap();
|
|
1359
1437
|
const httpRequest = defineHttpRequest(middleware);
|
|
1360
1438
|
const requester = httpRequest.defaultRequester;
|
|
1361
|
-
|
|
1362
|
-
return new SanityClient(httpRequest, config);
|
|
1363
|
-
}
|
|
1439
|
+
const createClient = config => new SanityClient(httpRequest, config);
|
|
1364
1440
|
export { BasePatch, BaseTransaction, ClientError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, createClient, requester };
|
|
1365
1441
|
//# sourceMappingURL=index.js.map
|