@sanity/client 3.3.3-esm.1 → 3.3.3-esm.6
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/sanityClient.browser.mjs +220 -124
- package/dist/sanityClient.browser.mjs.map +4 -4
- package/lib/assets/assetsClient.js +5 -6
- package/lib/auth/authClient.js +3 -4
- package/lib/config.js +39 -29
- package/lib/data/dataMethods.js +3 -4
- package/lib/data/listen.js +3 -3
- package/lib/data/patch.js +21 -20
- package/lib/data/transaction.js +6 -7
- package/lib/datasets/datasetsClient.js +3 -4
- package/lib/generateHelpUrl.js +8 -2
- package/lib/http/errors.js +6 -4
- package/lib/http/request.js +6 -14
- package/lib/http/requestOptions.js +3 -5
- package/lib/projects/projectsClient.js +3 -4
- package/lib/sanityClient.js +12 -6
- package/lib/users/usersClient.js +3 -4
- package/lib/util/observable-modern.js +29 -0
- package/lib/util/observable.js +23 -9
- package/package.json +11 -6
- package/umd/sanityClient.js +161 -90
- package/umd/sanityClient.min.js +1 -1
|
@@ -1,22 +1,118 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
1
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
2
10
|
var __commonJS = (cb, mod) => function __require() {
|
|
3
11
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
12
|
};
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
5
30
|
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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;
|
|
16
97
|
};
|
|
17
98
|
}
|
|
18
99
|
});
|
|
19
100
|
|
|
101
|
+
// src/util/observable-modern.js
|
|
102
|
+
var observable_modern_exports = {};
|
|
103
|
+
__export(observable_modern_exports, {
|
|
104
|
+
Observable: () => Observable,
|
|
105
|
+
filter: () => filter,
|
|
106
|
+
map: () => map
|
|
107
|
+
});
|
|
108
|
+
import { Observable } from "rxjs-v7/internal/Observable";
|
|
109
|
+
import { filter } from "rxjs-v7/internal/operators/filter";
|
|
110
|
+
import { map } from "rxjs-v7/internal/operators/map";
|
|
111
|
+
var init_observable_modern = __esm({
|
|
112
|
+
"src/util/observable-modern.js"() {
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
20
116
|
// src/util/getSelection.js
|
|
21
117
|
var require_getSelection = __commonJS({
|
|
22
118
|
"src/util/getSelection.js"(exports, module) {
|
|
@@ -108,52 +204,51 @@ var require_validators = __commonJS({
|
|
|
108
204
|
});
|
|
109
205
|
|
|
110
206
|
// src/data/patch.js
|
|
111
|
-
import assign from "object-assign";
|
|
112
207
|
var require_patch = __commonJS({
|
|
113
208
|
"src/data/patch.js"(exports, module) {
|
|
114
209
|
var getSelection = require_getSelection();
|
|
115
|
-
var
|
|
116
|
-
var validateObject =
|
|
117
|
-
var validateInsert =
|
|
210
|
+
var validate2 = require_validators();
|
|
211
|
+
var validateObject = validate2.validateObject;
|
|
212
|
+
var validateInsert = validate2.validateInsert;
|
|
118
213
|
function Patch(selection, operations = {}, client = null) {
|
|
119
214
|
this.selection = selection;
|
|
120
|
-
this.operations = assign({}, operations);
|
|
215
|
+
this.operations = Object.assign({}, operations);
|
|
121
216
|
this.client = client;
|
|
122
217
|
}
|
|
123
|
-
assign(Patch.prototype, {
|
|
218
|
+
Object.assign(Patch.prototype, {
|
|
124
219
|
clone() {
|
|
125
|
-
return new Patch(this.selection, assign({}, this.operations), this.client);
|
|
220
|
+
return new Patch(this.selection, Object.assign({}, this.operations), this.client);
|
|
126
221
|
},
|
|
127
222
|
set(props) {
|
|
128
|
-
return this.
|
|
223
|
+
return this.assign("set", props);
|
|
129
224
|
},
|
|
130
225
|
diffMatchPatch(props) {
|
|
131
226
|
validateObject("diffMatchPatch", props);
|
|
132
|
-
return this.
|
|
227
|
+
return this.assign("diffMatchPatch", props);
|
|
133
228
|
},
|
|
134
229
|
unset(attrs) {
|
|
135
230
|
if (!Array.isArray(attrs)) {
|
|
136
231
|
throw new Error("unset(attrs) takes an array of attributes to unset, non-array given");
|
|
137
232
|
}
|
|
138
|
-
this.operations = assign({}, this.operations, { unset: attrs });
|
|
233
|
+
this.operations = Object.assign({}, this.operations, { unset: attrs });
|
|
139
234
|
return this;
|
|
140
235
|
},
|
|
141
236
|
setIfMissing(props) {
|
|
142
|
-
return this.
|
|
237
|
+
return this.assign("setIfMissing", props);
|
|
143
238
|
},
|
|
144
239
|
replace(props) {
|
|
145
240
|
validateObject("replace", props);
|
|
146
241
|
return this._set("set", { $: props });
|
|
147
242
|
},
|
|
148
243
|
inc(props) {
|
|
149
|
-
return this.
|
|
244
|
+
return this.assign("inc", props);
|
|
150
245
|
},
|
|
151
246
|
dec(props) {
|
|
152
|
-
return this.
|
|
247
|
+
return this.assign("dec", props);
|
|
153
248
|
},
|
|
154
249
|
insert(at, selector, items) {
|
|
155
250
|
validateInsert(at, selector, items);
|
|
156
|
-
return this.
|
|
251
|
+
return this.assign("insert", { [at]: selector, items });
|
|
157
252
|
},
|
|
158
253
|
append(selector, items) {
|
|
159
254
|
return this.insert("after", `${selector}[-1]`, items);
|
|
@@ -174,7 +269,7 @@ var require_patch = __commonJS({
|
|
|
174
269
|
return this;
|
|
175
270
|
},
|
|
176
271
|
serialize() {
|
|
177
|
-
return assign(getSelection(this.selection), this.operations);
|
|
272
|
+
return Object.assign(getSelection(this.selection), this.operations);
|
|
178
273
|
},
|
|
179
274
|
toJSON() {
|
|
180
275
|
return this.serialize();
|
|
@@ -186,7 +281,7 @@ var require_patch = __commonJS({
|
|
|
186
281
|
);
|
|
187
282
|
}
|
|
188
283
|
const returnFirst = typeof this.selection === "string";
|
|
189
|
-
const opts = assign({ returnFirst, returnDocuments: true }, options);
|
|
284
|
+
const opts = Object.assign({ returnFirst, returnDocuments: true }, options);
|
|
190
285
|
return this.client.mutate({ patch: this.serialize() }, opts);
|
|
191
286
|
},
|
|
192
287
|
reset() {
|
|
@@ -194,12 +289,12 @@ var require_patch = __commonJS({
|
|
|
194
289
|
return this;
|
|
195
290
|
},
|
|
196
291
|
_set(op, props) {
|
|
197
|
-
return this.
|
|
292
|
+
return this.assign(op, props, false);
|
|
198
293
|
},
|
|
199
|
-
|
|
294
|
+
assign(op, props, merge = true) {
|
|
200
295
|
validateObject(op, props);
|
|
201
|
-
this.operations = assign({}, this.operations, {
|
|
202
|
-
[op]: assign({}, merge && this.operations[op] || {}, props)
|
|
296
|
+
this.operations = Object.assign({}, this.operations, {
|
|
297
|
+
[op]: Object.assign({}, merge && this.operations[op] || {}, props)
|
|
203
298
|
});
|
|
204
299
|
return this;
|
|
205
300
|
}
|
|
@@ -209,7 +304,6 @@ var require_patch = __commonJS({
|
|
|
209
304
|
});
|
|
210
305
|
|
|
211
306
|
// src/data/transaction.js
|
|
212
|
-
import assign2 from "object-assign";
|
|
213
307
|
var require_transaction = __commonJS({
|
|
214
308
|
"src/data/transaction.js"(exports, module) {
|
|
215
309
|
var validators = require_validators();
|
|
@@ -220,7 +314,7 @@ var require_transaction = __commonJS({
|
|
|
220
314
|
this.operations = operations;
|
|
221
315
|
this.client = client;
|
|
222
316
|
}
|
|
223
|
-
|
|
317
|
+
Object.assign(Transaction.prototype, {
|
|
224
318
|
clone() {
|
|
225
319
|
return new Transaction(this.operations.slice(0), this.client, this.trxId);
|
|
226
320
|
},
|
|
@@ -257,7 +351,7 @@ var require_transaction = __commonJS({
|
|
|
257
351
|
}
|
|
258
352
|
return this._add({ patch: patch.serialize() });
|
|
259
353
|
}
|
|
260
|
-
return this._add({ patch:
|
|
354
|
+
return this._add({ patch: Object.assign({ id: documentId }, patchOps) });
|
|
261
355
|
},
|
|
262
356
|
transactionId(id) {
|
|
263
357
|
if (!id) {
|
|
@@ -280,7 +374,7 @@ var require_transaction = __commonJS({
|
|
|
280
374
|
}
|
|
281
375
|
return this.client.mutate(
|
|
282
376
|
this.serialize(),
|
|
283
|
-
|
|
377
|
+
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
284
378
|
);
|
|
285
379
|
},
|
|
286
380
|
reset() {
|
|
@@ -339,11 +433,10 @@ var require_defaults = __commonJS({
|
|
|
339
433
|
});
|
|
340
434
|
|
|
341
435
|
// src/data/listen.js
|
|
342
|
-
import assign3 from "object-assign";
|
|
343
436
|
import polyfilledEventSource from "@sanity/eventsource";
|
|
344
437
|
var require_listen = __commonJS({
|
|
345
438
|
"src/data/listen.js"(exports, module) {
|
|
346
|
-
var { Observable: Observable2 } =
|
|
439
|
+
var { Observable: Observable2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
|
|
347
440
|
var pick = require_pick();
|
|
348
441
|
var defaults = require_defaults();
|
|
349
442
|
var encodeQueryString = require_encodeQueryString();
|
|
@@ -443,7 +536,7 @@ var require_listen = __commonJS({
|
|
|
443
536
|
function parseEvent(event) {
|
|
444
537
|
try {
|
|
445
538
|
const data = event.data && JSON.parse(event.data) || {};
|
|
446
|
-
return
|
|
539
|
+
return Object.assign({ type: event.type }, data);
|
|
447
540
|
} catch (err) {
|
|
448
541
|
return err;
|
|
449
542
|
}
|
|
@@ -468,10 +561,9 @@ var require_listen = __commonJS({
|
|
|
468
561
|
});
|
|
469
562
|
|
|
470
563
|
// src/data/dataMethods.js
|
|
471
|
-
import assign4 from "object-assign";
|
|
472
564
|
var require_dataMethods = __commonJS({
|
|
473
565
|
"src/data/dataMethods.js"(exports, module) {
|
|
474
|
-
var { map: map2, filter: filter2 } =
|
|
566
|
+
var { map: map2, filter: filter2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
|
|
475
567
|
var validators = require_validators();
|
|
476
568
|
var getSelection = require_getSelection();
|
|
477
569
|
var encodeQueryString = require_encodeQueryString();
|
|
@@ -607,7 +699,7 @@ var require_dataMethods = __commonJS({
|
|
|
607
699
|
},
|
|
608
700
|
_create(doc, op, options = {}) {
|
|
609
701
|
const mutation = { [op]: doc };
|
|
610
|
-
const opts =
|
|
702
|
+
const opts = Object.assign({ returnFirst: true, returnDocuments: true }, options);
|
|
611
703
|
return this.dataRequest("mutate", { mutations: [mutation] }, opts);
|
|
612
704
|
}
|
|
613
705
|
};
|
|
@@ -615,14 +707,13 @@ var require_dataMethods = __commonJS({
|
|
|
615
707
|
});
|
|
616
708
|
|
|
617
709
|
// src/datasets/datasetsClient.js
|
|
618
|
-
import assign5 from "object-assign";
|
|
619
710
|
var require_datasetsClient = __commonJS({
|
|
620
711
|
"src/datasets/datasetsClient.js"(exports, module) {
|
|
621
|
-
var
|
|
712
|
+
var validate2 = require_validators();
|
|
622
713
|
function DatasetsClient(client) {
|
|
623
714
|
this.request = client.request.bind(client);
|
|
624
715
|
}
|
|
625
|
-
|
|
716
|
+
Object.assign(DatasetsClient.prototype, {
|
|
626
717
|
create(name, options) {
|
|
627
718
|
return this._modify("PUT", name, options);
|
|
628
719
|
},
|
|
@@ -636,7 +727,7 @@ var require_datasetsClient = __commonJS({
|
|
|
636
727
|
return this.request({ uri: "/datasets" });
|
|
637
728
|
},
|
|
638
729
|
_modify(method, name, body) {
|
|
639
|
-
|
|
730
|
+
validate2.dataset(name);
|
|
640
731
|
return this.request({ method, uri: `/datasets/${name}`, body });
|
|
641
732
|
}
|
|
642
733
|
});
|
|
@@ -645,13 +736,12 @@ var require_datasetsClient = __commonJS({
|
|
|
645
736
|
});
|
|
646
737
|
|
|
647
738
|
// src/projects/projectsClient.js
|
|
648
|
-
import assign6 from "object-assign";
|
|
649
739
|
var require_projectsClient = __commonJS({
|
|
650
740
|
"src/projects/projectsClient.js"(exports, module) {
|
|
651
741
|
function ProjectsClient(client) {
|
|
652
742
|
this.client = client;
|
|
653
743
|
}
|
|
654
|
-
|
|
744
|
+
Object.assign(ProjectsClient.prototype, {
|
|
655
745
|
list() {
|
|
656
746
|
return this.client.request({ uri: "/projects" });
|
|
657
747
|
},
|
|
@@ -679,10 +769,9 @@ var require_queryString = __commonJS({
|
|
|
679
769
|
});
|
|
680
770
|
|
|
681
771
|
// src/assets/assetsClient.js
|
|
682
|
-
import assign7 from "object-assign";
|
|
683
772
|
var require_assetsClient = __commonJS({
|
|
684
773
|
"src/assets/assetsClient.js"(exports, module) {
|
|
685
|
-
var { map: map2, filter: filter2 } =
|
|
774
|
+
var { map: map2, filter: filter2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
|
|
686
775
|
var queryString = require_queryString();
|
|
687
776
|
var validators = require_validators();
|
|
688
777
|
function AssetsClient(client) {
|
|
@@ -692,7 +781,7 @@ var require_assetsClient = __commonJS({
|
|
|
692
781
|
if (typeof window === "undefined" || !(file instanceof window.File)) {
|
|
693
782
|
return opts;
|
|
694
783
|
}
|
|
695
|
-
return
|
|
784
|
+
return Object.assign(
|
|
696
785
|
{
|
|
697
786
|
filename: opts.preserveFilename === false ? void 0 : file.name,
|
|
698
787
|
contentType: file.type
|
|
@@ -700,7 +789,7 @@ var require_assetsClient = __commonJS({
|
|
|
700
789
|
opts
|
|
701
790
|
);
|
|
702
791
|
}
|
|
703
|
-
|
|
792
|
+
Object.assign(AssetsClient.prototype, {
|
|
704
793
|
upload(assetType, body, opts = {}) {
|
|
705
794
|
validators.validateAssetType(assetType);
|
|
706
795
|
let meta = opts.extract || void 0;
|
|
@@ -773,13 +862,12 @@ var require_assetsClient = __commonJS({
|
|
|
773
862
|
});
|
|
774
863
|
|
|
775
864
|
// src/users/usersClient.js
|
|
776
|
-
import assign8 from "object-assign";
|
|
777
865
|
var require_usersClient = __commonJS({
|
|
778
866
|
"src/users/usersClient.js"(exports, module) {
|
|
779
867
|
function UsersClient(client) {
|
|
780
868
|
this.client = client;
|
|
781
869
|
}
|
|
782
|
-
|
|
870
|
+
Object.assign(UsersClient.prototype, {
|
|
783
871
|
getById(id) {
|
|
784
872
|
return this.client.request({ uri: `/users/${id}` });
|
|
785
873
|
}
|
|
@@ -789,13 +877,12 @@ var require_usersClient = __commonJS({
|
|
|
789
877
|
});
|
|
790
878
|
|
|
791
879
|
// src/auth/authClient.js
|
|
792
|
-
import assign9 from "object-assign";
|
|
793
880
|
var require_authClient = __commonJS({
|
|
794
881
|
"src/auth/authClient.js"(exports, module) {
|
|
795
882
|
function AuthClient(client) {
|
|
796
883
|
this.client = client;
|
|
797
884
|
}
|
|
798
|
-
|
|
885
|
+
Object.assign(AuthClient.prototype, {
|
|
799
886
|
getLoginProviders() {
|
|
800
887
|
return this.client.request({ uri: "/auth/providers" });
|
|
801
888
|
},
|
|
@@ -809,18 +896,17 @@ var require_authClient = __commonJS({
|
|
|
809
896
|
|
|
810
897
|
// src/http/errors.js
|
|
811
898
|
import makeError from "make-error";
|
|
812
|
-
import assign10 from "object-assign";
|
|
813
899
|
var require_errors = __commonJS({
|
|
814
900
|
"src/http/errors.js"(exports) {
|
|
815
901
|
function ClientError(res) {
|
|
816
902
|
const props = extractErrorProps(res);
|
|
817
903
|
ClientError.super.call(this, props.message);
|
|
818
|
-
|
|
904
|
+
Object.assign(this, props);
|
|
819
905
|
}
|
|
820
906
|
function ServerError(res) {
|
|
821
907
|
const props = extractErrorProps(res);
|
|
822
908
|
ServerError.super.call(this, props.message);
|
|
823
|
-
|
|
909
|
+
Object.assign(this, props);
|
|
824
910
|
}
|
|
825
911
|
function extractErrorProps(res) {
|
|
826
912
|
const body = res.body;
|
|
@@ -866,14 +952,10 @@ var require_browserMiddleware = __commonJS({
|
|
|
866
952
|
|
|
867
953
|
// src/http/request.js
|
|
868
954
|
import getIt from "get-it";
|
|
869
|
-
import
|
|
870
|
-
import observable from "get-it/lib/middleware/observable";
|
|
871
|
-
import jsonRequest from "get-it/lib/middleware/jsonRequest";
|
|
872
|
-
import jsonResponse from "get-it/lib/middleware/jsonResponse";
|
|
873
|
-
import progress from "get-it/lib/middleware/progress";
|
|
955
|
+
import { observable, jsonRequest, jsonResponse, progress } from "get-it/middleware";
|
|
874
956
|
var require_request = __commonJS({
|
|
875
957
|
"src/http/request.js"(exports, module) {
|
|
876
|
-
var { Observable: Observable2 } =
|
|
958
|
+
var { Observable: Observable2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
|
|
877
959
|
var { ClientError, ServerError } = require_errors();
|
|
878
960
|
var httpError = {
|
|
879
961
|
onResponse: (res) => {
|
|
@@ -888,12 +970,12 @@ var require_request = __commonJS({
|
|
|
888
970
|
var printWarnings = {
|
|
889
971
|
onResponse: (res) => {
|
|
890
972
|
const warn = res.headers["x-sanity-warning"];
|
|
891
|
-
const
|
|
892
|
-
|
|
973
|
+
const warnings2 = Array.isArray(warn) ? warn : [warn];
|
|
974
|
+
warnings2.filter(Boolean).forEach((msg) => console.warn(msg));
|
|
893
975
|
return res;
|
|
894
976
|
}
|
|
895
977
|
};
|
|
896
|
-
var envSpecific = require_browserMiddleware();
|
|
978
|
+
var envSpecific = typeof EdgeRuntime === "string" ? require_browserMiddleware() : require_browserMiddleware();
|
|
897
979
|
var middleware = envSpecific.concat([
|
|
898
980
|
printWarnings,
|
|
899
981
|
jsonRequest(),
|
|
@@ -904,7 +986,7 @@ var require_request = __commonJS({
|
|
|
904
986
|
]);
|
|
905
987
|
var request = getIt(middleware);
|
|
906
988
|
function httpRequest(options, requester = request) {
|
|
907
|
-
return requester(
|
|
989
|
+
return requester(Object.assign({ maxRedirects: 0 }, options));
|
|
908
990
|
}
|
|
909
991
|
httpRequest.defaultRequester = request;
|
|
910
992
|
httpRequest.ClientError = ClientError;
|
|
@@ -914,7 +996,6 @@ var require_request = __commonJS({
|
|
|
914
996
|
});
|
|
915
997
|
|
|
916
998
|
// src/http/requestOptions.js
|
|
917
|
-
import assign12 from "object-assign";
|
|
918
999
|
var require_requestOptions = __commonJS({
|
|
919
1000
|
"src/http/requestOptions.js"(exports, module) {
|
|
920
1001
|
var projectHeader = "X-Sanity-Project-ID";
|
|
@@ -931,8 +1012,8 @@ var require_requestOptions = __commonJS({
|
|
|
931
1012
|
typeof overrides.withCredentials === "undefined" ? config.token || config.withCredentials : overrides.withCredentials
|
|
932
1013
|
);
|
|
933
1014
|
const timeout = typeof overrides.timeout === "undefined" ? config.timeout : overrides.timeout;
|
|
934
|
-
return
|
|
935
|
-
headers:
|
|
1015
|
+
return Object.assign({}, overrides, {
|
|
1016
|
+
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
936
1017
|
timeout: typeof timeout === "undefined" ? 5 * 60 * 1e3 : timeout,
|
|
937
1018
|
proxy: overrides.proxy || config.proxy,
|
|
938
1019
|
json: true,
|
|
@@ -943,12 +1024,17 @@ var require_requestOptions = __commonJS({
|
|
|
943
1024
|
});
|
|
944
1025
|
|
|
945
1026
|
// src/generateHelpUrl.js
|
|
946
|
-
var
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1027
|
+
var generateHelpUrl_exports = {};
|
|
1028
|
+
__export(generateHelpUrl_exports, {
|
|
1029
|
+
default: () => generateHelpUrl
|
|
1030
|
+
});
|
|
1031
|
+
function generateHelpUrl(slug) {
|
|
1032
|
+
return BASE_URL + slug;
|
|
1033
|
+
}
|
|
1034
|
+
var BASE_URL;
|
|
1035
|
+
var init_generateHelpUrl = __esm({
|
|
1036
|
+
"src/generateHelpUrl.js"() {
|
|
1037
|
+
BASE_URL = "https://docs.sanity.io/help/";
|
|
952
1038
|
}
|
|
953
1039
|
});
|
|
954
1040
|
|
|
@@ -973,51 +1059,66 @@ var require_once = __commonJS({
|
|
|
973
1059
|
// src/warnings.js
|
|
974
1060
|
var require_warnings = __commonJS({
|
|
975
1061
|
"src/warnings.js"(exports) {
|
|
976
|
-
var
|
|
1062
|
+
var generateHelpUrl2 = (init_generateHelpUrl(), __toCommonJS(generateHelpUrl_exports));
|
|
977
1063
|
var once = require_once();
|
|
978
1064
|
var createWarningPrinter = (message) => once((...args) => console.warn(message.join(" "), ...args));
|
|
979
1065
|
exports.printCdnWarning = createWarningPrinter([
|
|
980
1066
|
"You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and",
|
|
981
|
-
`cheaper. Think about it! For more info, see ${
|
|
1067
|
+
`cheaper. Think about it! For more info, see ${generateHelpUrl2("js-client-cdn-configuration")}.`,
|
|
982
1068
|
"To hide this warning, please set the `useCdn` option to either `true` or `false` when creating",
|
|
983
1069
|
"the client."
|
|
984
1070
|
]);
|
|
985
1071
|
exports.printBrowserTokenWarning = createWarningPrinter([
|
|
986
1072
|
"You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
|
|
987
|
-
`See ${
|
|
1073
|
+
`See ${generateHelpUrl2(
|
|
988
1074
|
"js-client-browser-token"
|
|
989
1075
|
)} for more information and how to hide this warning.`
|
|
990
1076
|
]);
|
|
991
1077
|
exports.printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
992
1078
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
993
|
-
`See ${
|
|
1079
|
+
`See ${generateHelpUrl2("js-client-api-version")}`
|
|
994
1080
|
]);
|
|
995
1081
|
}
|
|
996
1082
|
});
|
|
997
1083
|
|
|
998
1084
|
// src/config.js
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1085
|
+
var config_exports = {};
|
|
1086
|
+
__export(config_exports, {
|
|
1087
|
+
defaultConfig: () => defaultConfig,
|
|
1088
|
+
initConfig: () => initConfig,
|
|
1089
|
+
validateApiVersion: () => validateApiVersion
|
|
1090
|
+
});
|
|
1091
|
+
var import_validators, import_warnings, defaultCdnHost, defaultConfig, LOCALHOSTS, isLocal, validateApiVersion, initConfig;
|
|
1092
|
+
var init_config = __esm({
|
|
1093
|
+
"src/config.js"() {
|
|
1094
|
+
init_generateHelpUrl();
|
|
1095
|
+
import_validators = __toESM(require_validators());
|
|
1096
|
+
import_warnings = __toESM(require_warnings());
|
|
1097
|
+
defaultCdnHost = "apicdn.sanity.io";
|
|
1098
|
+
defaultConfig = {
|
|
1007
1099
|
apiHost: "https://api.sanity.io",
|
|
1008
1100
|
apiVersion: "1",
|
|
1009
1101
|
useProjectHostname: true,
|
|
1010
1102
|
isPromiseAPI: true
|
|
1011
1103
|
};
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1104
|
+
LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
|
|
1105
|
+
isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
1106
|
+
validateApiVersion = function validateApiVersion2(apiVersion) {
|
|
1107
|
+
if (apiVersion === "1" || apiVersion === "X") {
|
|
1108
|
+
return;
|
|
1109
|
+
}
|
|
1110
|
+
const apiDate = new Date(apiVersion);
|
|
1111
|
+
const apiVersionValid = /^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0;
|
|
1112
|
+
if (!apiVersionValid) {
|
|
1113
|
+
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
initConfig = (config, prevConfig) => {
|
|
1117
|
+
const specifiedConfig = Object.assign({}, prevConfig, config);
|
|
1017
1118
|
if (!specifiedConfig.apiVersion) {
|
|
1018
|
-
|
|
1119
|
+
import_warnings.default.printNoApiVersionSpecifiedWarning();
|
|
1019
1120
|
}
|
|
1020
|
-
const newConfig =
|
|
1121
|
+
const newConfig = Object.assign({}, defaultConfig, specifiedConfig);
|
|
1021
1122
|
const projectBased = newConfig.useProjectHostname;
|
|
1022
1123
|
if (typeof Promise === "undefined") {
|
|
1023
1124
|
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
@@ -1029,23 +1130,23 @@ var require_config = __commonJS({
|
|
|
1029
1130
|
const isBrowser = typeof window !== "undefined" && window.location && window.location.hostname;
|
|
1030
1131
|
const isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
1031
1132
|
if (isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true) {
|
|
1032
|
-
|
|
1133
|
+
import_warnings.default.printBrowserTokenWarning();
|
|
1033
1134
|
} else if (typeof newConfig.useCdn === "undefined") {
|
|
1034
|
-
|
|
1135
|
+
import_warnings.default.printCdnWarning();
|
|
1035
1136
|
}
|
|
1036
1137
|
if (projectBased) {
|
|
1037
|
-
|
|
1138
|
+
import_validators.default.projectId(newConfig.projectId);
|
|
1038
1139
|
}
|
|
1039
1140
|
if (newConfig.dataset) {
|
|
1040
|
-
|
|
1141
|
+
import_validators.default.dataset(newConfig.dataset);
|
|
1041
1142
|
}
|
|
1042
1143
|
if ("requestTagPrefix" in newConfig) {
|
|
1043
|
-
newConfig.requestTagPrefix = newConfig.requestTagPrefix ?
|
|
1144
|
+
newConfig.requestTagPrefix = newConfig.requestTagPrefix ? import_validators.default.requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0;
|
|
1044
1145
|
}
|
|
1045
1146
|
newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, "");
|
|
1046
1147
|
newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
|
|
1047
1148
|
newConfig.useCdn = Boolean(newConfig.useCdn) && !newConfig.withCredentials;
|
|
1048
|
-
|
|
1149
|
+
validateApiVersion(newConfig.apiVersion);
|
|
1049
1150
|
const hostParts = newConfig.apiHost.split("://", 2);
|
|
1050
1151
|
const protocol = hostParts[0];
|
|
1051
1152
|
const host = hostParts[1];
|
|
@@ -1059,24 +1160,14 @@ var require_config = __commonJS({
|
|
|
1059
1160
|
}
|
|
1060
1161
|
return newConfig;
|
|
1061
1162
|
};
|
|
1062
|
-
exports.validateApiVersion = function validateApiVersion(apiVersion) {
|
|
1063
|
-
if (apiVersion === "1" || apiVersion === "X") {
|
|
1064
|
-
return;
|
|
1065
|
-
}
|
|
1066
|
-
const apiDate = new Date(apiVersion);
|
|
1067
|
-
const apiVersionValid = /^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0;
|
|
1068
|
-
if (!apiVersionValid) {
|
|
1069
|
-
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
1070
|
-
}
|
|
1071
|
-
};
|
|
1072
1163
|
}
|
|
1073
1164
|
});
|
|
1074
1165
|
|
|
1075
1166
|
// src/sanityClient.js
|
|
1076
|
-
import assign14 from "object-assign";
|
|
1077
1167
|
var require_sanityClient = __commonJS({
|
|
1078
1168
|
"src/sanityClient.js"(exports, module) {
|
|
1079
|
-
var
|
|
1169
|
+
var import_object_assign = __toESM(require_object_assign());
|
|
1170
|
+
var { Observable: Observable2, map: map2, filter: filter2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
|
|
1080
1171
|
var Patch = require_patch();
|
|
1081
1172
|
var Transaction = require_transaction();
|
|
1082
1173
|
var dataMethods = require_dataMethods();
|
|
@@ -1087,10 +1178,10 @@ var require_sanityClient = __commonJS({
|
|
|
1087
1178
|
var AuthClient = require_authClient();
|
|
1088
1179
|
var httpRequest = require_request();
|
|
1089
1180
|
var getRequestOptions = require_requestOptions();
|
|
1090
|
-
var { defaultConfig, initConfig } =
|
|
1091
|
-
var
|
|
1181
|
+
var { defaultConfig: defaultConfig2, initConfig: initConfig2 } = (init_config(), __toCommonJS(config_exports));
|
|
1182
|
+
var validate2 = require_validators();
|
|
1092
1183
|
var toPromise = (observable2) => observable2.toPromise();
|
|
1093
|
-
function SanityClient(config =
|
|
1184
|
+
function SanityClient(config = defaultConfig2) {
|
|
1094
1185
|
if (!(this instanceof SanityClient)) {
|
|
1095
1186
|
return new SanityClient(config);
|
|
1096
1187
|
}
|
|
@@ -1101,24 +1192,24 @@ var require_sanityClient = __commonJS({
|
|
|
1101
1192
|
this.users = new UsersClient(this);
|
|
1102
1193
|
this.auth = new AuthClient(this);
|
|
1103
1194
|
if (this.clientConfig.isPromiseAPI) {
|
|
1104
|
-
const observableConfig =
|
|
1195
|
+
const observableConfig = Object.assign({}, this.clientConfig, { isPromiseAPI: false });
|
|
1105
1196
|
this.observable = new SanityClient(observableConfig);
|
|
1106
1197
|
}
|
|
1107
1198
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1199
|
+
Object.assign(SanityClient.prototype, dataMethods);
|
|
1200
|
+
Object.assign(SanityClient.prototype, {
|
|
1110
1201
|
clone() {
|
|
1111
1202
|
return new SanityClient(this.config());
|
|
1112
1203
|
},
|
|
1113
1204
|
config(newConfig) {
|
|
1114
1205
|
if (typeof newConfig === "undefined") {
|
|
1115
|
-
return
|
|
1206
|
+
return Object.assign({}, this.clientConfig);
|
|
1116
1207
|
}
|
|
1117
1208
|
if (this.observable) {
|
|
1118
|
-
const observableConfig =
|
|
1209
|
+
const observableConfig = Object.assign({}, newConfig, { isPromiseAPI: false });
|
|
1119
1210
|
this.observable.config(observableConfig);
|
|
1120
1211
|
}
|
|
1121
|
-
this.clientConfig =
|
|
1212
|
+
this.clientConfig = initConfig2(newConfig, this.clientConfig || {});
|
|
1122
1213
|
return this;
|
|
1123
1214
|
},
|
|
1124
1215
|
withConfig(newConfig) {
|
|
@@ -1137,11 +1228,11 @@ var require_sanityClient = __commonJS({
|
|
|
1137
1228
|
const useCdn = this.clientConfig.useCdn && canUseCdn;
|
|
1138
1229
|
const tag = options.tag && this.clientConfig.requestTagPrefix ? [this.clientConfig.requestTagPrefix, options.tag].join(".") : options.tag || this.clientConfig.requestTagPrefix;
|
|
1139
1230
|
if (tag) {
|
|
1140
|
-
options.query = { tag:
|
|
1231
|
+
options.query = { tag: validate2.requestTag(tag), ...options.query };
|
|
1141
1232
|
}
|
|
1142
1233
|
const reqOptions = getRequestOptions(
|
|
1143
1234
|
this.clientConfig,
|
|
1144
|
-
|
|
1235
|
+
Object.assign({}, options, {
|
|
1145
1236
|
url: this.getUrl(uri, useCdn)
|
|
1146
1237
|
})
|
|
1147
1238
|
);
|
|
@@ -1166,4 +1257,9 @@ var require_sanityClient = __commonJS({
|
|
|
1166
1257
|
}
|
|
1167
1258
|
});
|
|
1168
1259
|
export default require_sanityClient();
|
|
1260
|
+
/*
|
|
1261
|
+
object-assign
|
|
1262
|
+
(c) Sindre Sorhus
|
|
1263
|
+
@license MIT
|
|
1264
|
+
*/
|
|
1169
1265
|
//# sourceMappingURL=sanityClient.browser.mjs.map
|