@sanity/client 3.3.3-esm.3 → 3.3.3-esm.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sanityClient.browser.mjs +348 -276
- 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 -23
- package/lib/data/dataMethods.js +3 -4
- package/lib/data/encodeQueryString.js +9 -2
- 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/browserMiddleware.js +7 -1
- package/lib/http/errors.js +13 -7
- package/lib/http/nodeMiddleware.js +8 -1
- package/lib/http/queryString.js +10 -2
- package/lib/http/request.js +20 -24
- package/lib/http/requestOptions.js +12 -6
- package/lib/projects/projectsClient.js +10 -4
- package/lib/sanityClient.js +12 -10
- package/lib/users/usersClient.js +10 -4
- package/lib/util/defaults.js +10 -2
- package/lib/util/getSelection.js +9 -2
- package/lib/util/observable-modern.js +29 -0
- package/lib/util/observable.js +23 -9
- package/lib/util/once.js +10 -2
- package/lib/util/pick.js +10 -2
- package/lib/validators.js +38 -15
- package/lib/warnings.js +16 -6
- package/package.json +13 -7
- package/umd/sanityClient.js +168 -100
- package/umd/sanityClient.min.js +1 -1
|
@@ -1,83 +1,120 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
1
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __esm = (fn, res) => function __init() {
|
|
6
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
7
|
+
};
|
|
2
8
|
var __commonJS = (cb, mod) => function __require() {
|
|
3
9
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
10
|
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
5
24
|
|
|
6
|
-
// src/util/observable.js
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
// src/util/observable-modern.js
|
|
26
|
+
var observable_modern_exports = {};
|
|
27
|
+
__export(observable_modern_exports, {
|
|
28
|
+
Observable: () => Observable,
|
|
29
|
+
filter: () => filter,
|
|
30
|
+
map: () => map
|
|
31
|
+
});
|
|
32
|
+
import { Observable } from "rxjs-v7/internal/Observable";
|
|
33
|
+
import { filter } from "rxjs-v7/internal/operators/filter";
|
|
34
|
+
import { map } from "rxjs-v7/internal/operators/map";
|
|
35
|
+
var init_observable_modern = __esm({
|
|
36
|
+
"src/util/observable-modern.js"() {
|
|
17
37
|
}
|
|
18
38
|
});
|
|
19
39
|
|
|
20
40
|
// src/util/getSelection.js
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
var getSelection_exports = {};
|
|
42
|
+
__export(getSelection_exports, {
|
|
43
|
+
default: () => getSelection
|
|
44
|
+
});
|
|
45
|
+
function getSelection(sel) {
|
|
46
|
+
if (typeof sel === "string" || Array.isArray(sel)) {
|
|
47
|
+
return { id: sel };
|
|
48
|
+
}
|
|
49
|
+
if (sel && sel.query) {
|
|
50
|
+
return "params" in sel ? { query: sel.query, params: sel.params } : { query: sel.query };
|
|
51
|
+
}
|
|
52
|
+
const selectionOpts = [
|
|
53
|
+
"* Document ID (<docId>)",
|
|
54
|
+
"* Array of document IDs",
|
|
55
|
+
"* Object containing `query`"
|
|
56
|
+
].join("\n");
|
|
57
|
+
throw new Error(`Unknown selection - must be one of:
|
|
36
58
|
|
|
37
59
|
${selectionOpts}`);
|
|
38
|
-
|
|
60
|
+
}
|
|
61
|
+
var init_getSelection = __esm({
|
|
62
|
+
"src/util/getSelection.js"() {
|
|
39
63
|
}
|
|
40
64
|
});
|
|
41
65
|
|
|
42
66
|
// src/validators.js
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
67
|
+
var validators_exports = {};
|
|
68
|
+
__export(validators_exports, {
|
|
69
|
+
dataset: () => dataset,
|
|
70
|
+
hasDataset: () => hasDataset,
|
|
71
|
+
projectId: () => projectId,
|
|
72
|
+
requestTag: () => requestTag,
|
|
73
|
+
requireDocumentId: () => requireDocumentId,
|
|
74
|
+
validateAssetType: () => validateAssetType,
|
|
75
|
+
validateDocumentId: () => validateDocumentId,
|
|
76
|
+
validateInsert: () => validateInsert,
|
|
77
|
+
validateObject: () => validateObject
|
|
78
|
+
});
|
|
79
|
+
var VALID_ASSET_TYPES, VALID_INSERT_LOCATIONS, dataset, projectId, validateAssetType, validateObject, validateDocumentId, requireDocumentId, validateInsert, hasDataset, requestTag;
|
|
80
|
+
var init_validators = __esm({
|
|
81
|
+
"src/validators.js"() {
|
|
82
|
+
VALID_ASSET_TYPES = ["image", "file"];
|
|
83
|
+
VALID_INSERT_LOCATIONS = ["before", "after", "replace"];
|
|
84
|
+
dataset = (name) => {
|
|
48
85
|
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
|
|
49
86
|
throw new Error(
|
|
50
87
|
"Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters"
|
|
51
88
|
);
|
|
52
89
|
}
|
|
53
90
|
};
|
|
54
|
-
|
|
91
|
+
projectId = (id) => {
|
|
55
92
|
if (!/^[-a-z0-9]+$/i.test(id)) {
|
|
56
93
|
throw new Error("`projectId` can only contain only a-z, 0-9 and dashes");
|
|
57
94
|
}
|
|
58
95
|
};
|
|
59
|
-
|
|
96
|
+
validateAssetType = (type) => {
|
|
60
97
|
if (VALID_ASSET_TYPES.indexOf(type) === -1) {
|
|
61
98
|
throw new Error(`Invalid asset type: ${type}. Must be one of ${VALID_ASSET_TYPES.join(", ")}`);
|
|
62
99
|
}
|
|
63
100
|
};
|
|
64
|
-
|
|
101
|
+
validateObject = (op, val) => {
|
|
65
102
|
if (val === null || typeof val !== "object" || Array.isArray(val)) {
|
|
66
103
|
throw new Error(`${op}() takes an object of properties`);
|
|
67
104
|
}
|
|
68
105
|
};
|
|
69
|
-
|
|
70
|
-
if (!doc._id) {
|
|
71
|
-
throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
|
|
72
|
-
}
|
|
73
|
-
exports.validateDocumentId(op, doc._id);
|
|
74
|
-
};
|
|
75
|
-
exports.validateDocumentId = (op, id) => {
|
|
106
|
+
validateDocumentId = (op, id) => {
|
|
76
107
|
if (typeof id !== "string" || !/^[a-z0-9_.-]+$/i.test(id)) {
|
|
77
108
|
throw new Error(`${op}(): "${id}" is not a valid document ID`);
|
|
78
109
|
}
|
|
79
110
|
};
|
|
80
|
-
|
|
111
|
+
requireDocumentId = (op, doc) => {
|
|
112
|
+
if (!doc._id) {
|
|
113
|
+
throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
|
|
114
|
+
}
|
|
115
|
+
validateDocumentId(op, doc._id);
|
|
116
|
+
};
|
|
117
|
+
validateInsert = (at, selector, items) => {
|
|
81
118
|
const signature = "insert(at, selector, items)";
|
|
82
119
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
83
120
|
const valid = VALID_INSERT_LOCATIONS.map((loc) => `"${loc}"`).join(", ");
|
|
@@ -90,13 +127,13 @@ var require_validators = __commonJS({
|
|
|
90
127
|
throw new Error(`${signature} takes an "items"-argument which must be an array`);
|
|
91
128
|
}
|
|
92
129
|
};
|
|
93
|
-
|
|
130
|
+
hasDataset = (config) => {
|
|
94
131
|
if (!config.dataset) {
|
|
95
132
|
throw new Error("`dataset` must be provided to perform queries");
|
|
96
133
|
}
|
|
97
134
|
return config.dataset || "";
|
|
98
135
|
};
|
|
99
|
-
|
|
136
|
+
requestTag = (tag) => {
|
|
100
137
|
if (typeof tag !== "string" || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
|
|
101
138
|
throw new Error(
|
|
102
139
|
`Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.`
|
|
@@ -108,52 +145,51 @@ var require_validators = __commonJS({
|
|
|
108
145
|
});
|
|
109
146
|
|
|
110
147
|
// src/data/patch.js
|
|
111
|
-
import assign from "object-assign";
|
|
112
148
|
var require_patch = __commonJS({
|
|
113
149
|
"src/data/patch.js"(exports, module) {
|
|
114
|
-
var
|
|
115
|
-
var validate =
|
|
116
|
-
var
|
|
117
|
-
var
|
|
150
|
+
var getSelection2 = (init_getSelection(), __toCommonJS(getSelection_exports));
|
|
151
|
+
var validate = (init_validators(), __toCommonJS(validators_exports));
|
|
152
|
+
var validateObject2 = validate.validateObject;
|
|
153
|
+
var validateInsert2 = validate.validateInsert;
|
|
118
154
|
function Patch(selection, operations = {}, client = null) {
|
|
119
155
|
this.selection = selection;
|
|
120
|
-
this.operations = assign({}, operations);
|
|
156
|
+
this.operations = Object.assign({}, operations);
|
|
121
157
|
this.client = client;
|
|
122
158
|
}
|
|
123
|
-
assign(Patch.prototype, {
|
|
159
|
+
Object.assign(Patch.prototype, {
|
|
124
160
|
clone() {
|
|
125
|
-
return new Patch(this.selection, assign({}, this.operations), this.client);
|
|
161
|
+
return new Patch(this.selection, Object.assign({}, this.operations), this.client);
|
|
126
162
|
},
|
|
127
163
|
set(props) {
|
|
128
|
-
return this.
|
|
164
|
+
return this.assign("set", props);
|
|
129
165
|
},
|
|
130
166
|
diffMatchPatch(props) {
|
|
131
|
-
|
|
132
|
-
return this.
|
|
167
|
+
validateObject2("diffMatchPatch", props);
|
|
168
|
+
return this.assign("diffMatchPatch", props);
|
|
133
169
|
},
|
|
134
170
|
unset(attrs) {
|
|
135
171
|
if (!Array.isArray(attrs)) {
|
|
136
172
|
throw new Error("unset(attrs) takes an array of attributes to unset, non-array given");
|
|
137
173
|
}
|
|
138
|
-
this.operations = assign({}, this.operations, { unset: attrs });
|
|
174
|
+
this.operations = Object.assign({}, this.operations, { unset: attrs });
|
|
139
175
|
return this;
|
|
140
176
|
},
|
|
141
177
|
setIfMissing(props) {
|
|
142
|
-
return this.
|
|
178
|
+
return this.assign("setIfMissing", props);
|
|
143
179
|
},
|
|
144
180
|
replace(props) {
|
|
145
|
-
|
|
181
|
+
validateObject2("replace", props);
|
|
146
182
|
return this._set("set", { $: props });
|
|
147
183
|
},
|
|
148
184
|
inc(props) {
|
|
149
|
-
return this.
|
|
185
|
+
return this.assign("inc", props);
|
|
150
186
|
},
|
|
151
187
|
dec(props) {
|
|
152
|
-
return this.
|
|
188
|
+
return this.assign("dec", props);
|
|
153
189
|
},
|
|
154
190
|
insert(at, selector, items) {
|
|
155
|
-
|
|
156
|
-
return this.
|
|
191
|
+
validateInsert2(at, selector, items);
|
|
192
|
+
return this.assign("insert", { [at]: selector, items });
|
|
157
193
|
},
|
|
158
194
|
append(selector, items) {
|
|
159
195
|
return this.insert("after", `${selector}[-1]`, items);
|
|
@@ -174,7 +210,7 @@ var require_patch = __commonJS({
|
|
|
174
210
|
return this;
|
|
175
211
|
},
|
|
176
212
|
serialize() {
|
|
177
|
-
return assign(
|
|
213
|
+
return Object.assign(getSelection2(this.selection), this.operations);
|
|
178
214
|
},
|
|
179
215
|
toJSON() {
|
|
180
216
|
return this.serialize();
|
|
@@ -186,7 +222,7 @@ var require_patch = __commonJS({
|
|
|
186
222
|
);
|
|
187
223
|
}
|
|
188
224
|
const returnFirst = typeof this.selection === "string";
|
|
189
|
-
const opts = assign({ returnFirst, returnDocuments: true }, options);
|
|
225
|
+
const opts = Object.assign({ returnFirst, returnDocuments: true }, options);
|
|
190
226
|
return this.client.mutate({ patch: this.serialize() }, opts);
|
|
191
227
|
},
|
|
192
228
|
reset() {
|
|
@@ -194,12 +230,12 @@ var require_patch = __commonJS({
|
|
|
194
230
|
return this;
|
|
195
231
|
},
|
|
196
232
|
_set(op, props) {
|
|
197
|
-
return this.
|
|
233
|
+
return this.assign(op, props, false);
|
|
198
234
|
},
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.operations = assign({}, this.operations, {
|
|
202
|
-
[op]: assign({}, merge && this.operations[op] || {}, props)
|
|
235
|
+
assign(op, props, merge = true) {
|
|
236
|
+
validateObject2(op, props);
|
|
237
|
+
this.operations = Object.assign({}, this.operations, {
|
|
238
|
+
[op]: Object.assign({}, merge && this.operations[op] || {}, props)
|
|
203
239
|
});
|
|
204
240
|
return this;
|
|
205
241
|
}
|
|
@@ -209,10 +245,9 @@ var require_patch = __commonJS({
|
|
|
209
245
|
});
|
|
210
246
|
|
|
211
247
|
// src/data/transaction.js
|
|
212
|
-
import assign2 from "object-assign";
|
|
213
248
|
var require_transaction = __commonJS({
|
|
214
249
|
"src/data/transaction.js"(exports, module) {
|
|
215
|
-
var validators =
|
|
250
|
+
var validators = (init_validators(), __toCommonJS(validators_exports));
|
|
216
251
|
var Patch = require_patch();
|
|
217
252
|
var defaultMutateOptions = { returnDocuments: false };
|
|
218
253
|
function Transaction(operations = [], client, transactionId) {
|
|
@@ -220,7 +255,7 @@ var require_transaction = __commonJS({
|
|
|
220
255
|
this.operations = operations;
|
|
221
256
|
this.client = client;
|
|
222
257
|
}
|
|
223
|
-
|
|
258
|
+
Object.assign(Transaction.prototype, {
|
|
224
259
|
clone() {
|
|
225
260
|
return new Transaction(this.operations.slice(0), this.client, this.trxId);
|
|
226
261
|
},
|
|
@@ -257,7 +292,7 @@ var require_transaction = __commonJS({
|
|
|
257
292
|
}
|
|
258
293
|
return this._add({ patch: patch.serialize() });
|
|
259
294
|
}
|
|
260
|
-
return this._add({ patch:
|
|
295
|
+
return this._add({ patch: Object.assign({ id: documentId }, patchOps) });
|
|
261
296
|
},
|
|
262
297
|
transactionId(id) {
|
|
263
298
|
if (!id) {
|
|
@@ -280,7 +315,7 @@ var require_transaction = __commonJS({
|
|
|
280
315
|
}
|
|
281
316
|
return this.client.mutate(
|
|
282
317
|
this.serialize(),
|
|
283
|
-
|
|
318
|
+
Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {})
|
|
284
319
|
);
|
|
285
320
|
},
|
|
286
321
|
reset() {
|
|
@@ -297,10 +332,15 @@ var require_transaction = __commonJS({
|
|
|
297
332
|
});
|
|
298
333
|
|
|
299
334
|
// src/data/encodeQueryString.js
|
|
300
|
-
var
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
335
|
+
var encodeQueryString_exports = {};
|
|
336
|
+
__export(encodeQueryString_exports, {
|
|
337
|
+
default: () => encodeQueryString_default
|
|
338
|
+
});
|
|
339
|
+
var enc, encodeQueryString_default;
|
|
340
|
+
var init_encodeQueryString = __esm({
|
|
341
|
+
"src/data/encodeQueryString.js"() {
|
|
342
|
+
enc = encodeURIComponent;
|
|
343
|
+
encodeQueryString_default = ({ query, params = {}, options = {} }) => {
|
|
304
344
|
const { tag, ...opts } = options;
|
|
305
345
|
const q = `query=${enc(query)}`;
|
|
306
346
|
const base = tag ? `?tag=${enc(tag)}&${q}` : `?${q}`;
|
|
@@ -316,9 +356,14 @@ var require_encodeQueryString = __commonJS({
|
|
|
316
356
|
});
|
|
317
357
|
|
|
318
358
|
// src/util/pick.js
|
|
319
|
-
var
|
|
320
|
-
|
|
321
|
-
|
|
359
|
+
var pick_exports = {};
|
|
360
|
+
__export(pick_exports, {
|
|
361
|
+
default: () => pick_default
|
|
362
|
+
});
|
|
363
|
+
var pick_default;
|
|
364
|
+
var init_pick = __esm({
|
|
365
|
+
"src/util/pick.js"() {
|
|
366
|
+
pick_default = (obj, props) => props.reduce((selection, prop) => {
|
|
322
367
|
if (typeof obj[prop] === "undefined") {
|
|
323
368
|
return selection;
|
|
324
369
|
}
|
|
@@ -329,9 +374,14 @@ var require_pick = __commonJS({
|
|
|
329
374
|
});
|
|
330
375
|
|
|
331
376
|
// src/util/defaults.js
|
|
332
|
-
var
|
|
333
|
-
|
|
334
|
-
|
|
377
|
+
var defaults_exports = {};
|
|
378
|
+
__export(defaults_exports, {
|
|
379
|
+
default: () => defaults_default
|
|
380
|
+
});
|
|
381
|
+
var defaults_default;
|
|
382
|
+
var init_defaults = __esm({
|
|
383
|
+
"src/util/defaults.js"() {
|
|
384
|
+
defaults_default = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj)).reduce((target, prop) => {
|
|
335
385
|
target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
|
|
336
386
|
return target;
|
|
337
387
|
}, {});
|
|
@@ -339,14 +389,13 @@ var require_defaults = __commonJS({
|
|
|
339
389
|
});
|
|
340
390
|
|
|
341
391
|
// src/data/listen.js
|
|
342
|
-
import assign3 from "object-assign";
|
|
343
392
|
import polyfilledEventSource from "@sanity/eventsource";
|
|
344
393
|
var require_listen = __commonJS({
|
|
345
394
|
"src/data/listen.js"(exports, module) {
|
|
346
|
-
var { Observable: Observable2 } =
|
|
347
|
-
var pick =
|
|
348
|
-
var defaults =
|
|
349
|
-
var encodeQueryString =
|
|
395
|
+
var { Observable: Observable2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
|
|
396
|
+
var pick = (init_pick(), __toCommonJS(pick_exports));
|
|
397
|
+
var defaults = (init_defaults(), __toCommonJS(defaults_exports));
|
|
398
|
+
var encodeQueryString = (init_encodeQueryString(), __toCommonJS(encodeQueryString_exports));
|
|
350
399
|
var MAX_URL_LENGTH = 16e3 - 1200;
|
|
351
400
|
var EventSource = polyfilledEventSource;
|
|
352
401
|
var possibleOptions = [
|
|
@@ -443,7 +492,7 @@ var require_listen = __commonJS({
|
|
|
443
492
|
function parseEvent(event) {
|
|
444
493
|
try {
|
|
445
494
|
const data = event.data && JSON.parse(event.data) || {};
|
|
446
|
-
return
|
|
495
|
+
return Object.assign({ type: event.type }, data);
|
|
447
496
|
} catch (err) {
|
|
448
497
|
return err;
|
|
449
498
|
}
|
|
@@ -468,13 +517,12 @@ var require_listen = __commonJS({
|
|
|
468
517
|
});
|
|
469
518
|
|
|
470
519
|
// src/data/dataMethods.js
|
|
471
|
-
import assign4 from "object-assign";
|
|
472
520
|
var require_dataMethods = __commonJS({
|
|
473
521
|
"src/data/dataMethods.js"(exports, module) {
|
|
474
|
-
var { map: map2, filter: filter2 } =
|
|
475
|
-
var validators =
|
|
476
|
-
var
|
|
477
|
-
var encodeQueryString =
|
|
522
|
+
var { map: map2, filter: filter2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
|
|
523
|
+
var validators = (init_validators(), __toCommonJS(validators_exports));
|
|
524
|
+
var getSelection2 = (init_getSelection(), __toCommonJS(getSelection_exports));
|
|
525
|
+
var encodeQueryString = (init_encodeQueryString(), __toCommonJS(encodeQueryString_exports));
|
|
478
526
|
var Transaction = require_transaction();
|
|
479
527
|
var Patch = require_patch();
|
|
480
528
|
var listen = require_listen();
|
|
@@ -548,7 +596,7 @@ var require_dataMethods = __commonJS({
|
|
|
548
596
|
return new Patch(selector, operations, this);
|
|
549
597
|
},
|
|
550
598
|
delete(selection, options) {
|
|
551
|
-
return this.dataRequest("mutate", { mutations: [{ delete:
|
|
599
|
+
return this.dataRequest("mutate", { mutations: [{ delete: getSelection2(selection) }] }, options);
|
|
552
600
|
},
|
|
553
601
|
mutate(mutations, options) {
|
|
554
602
|
const mut = mutations instanceof Patch || mutations instanceof Transaction ? mutations.serialize() : mutations;
|
|
@@ -560,8 +608,8 @@ var require_dataMethods = __commonJS({
|
|
|
560
608
|
return new Transaction(operations, this);
|
|
561
609
|
},
|
|
562
610
|
dataRequest(endpoint, body, options = {}) {
|
|
563
|
-
const
|
|
564
|
-
return this.isPromiseAPI() ? toPromise(
|
|
611
|
+
const request2 = this._dataRequest(endpoint, body, options);
|
|
612
|
+
return this.isPromiseAPI() ? toPromise(request2) : request2;
|
|
565
613
|
},
|
|
566
614
|
_dataRequest(endpoint, body, options = {}) {
|
|
567
615
|
const isMutation = endpoint === "mutate";
|
|
@@ -607,7 +655,7 @@ var require_dataMethods = __commonJS({
|
|
|
607
655
|
},
|
|
608
656
|
_create(doc, op, options = {}) {
|
|
609
657
|
const mutation = { [op]: doc };
|
|
610
|
-
const opts =
|
|
658
|
+
const opts = Object.assign({ returnFirst: true, returnDocuments: true }, options);
|
|
611
659
|
return this.dataRequest("mutate", { mutations: [mutation] }, opts);
|
|
612
660
|
}
|
|
613
661
|
};
|
|
@@ -615,14 +663,13 @@ var require_dataMethods = __commonJS({
|
|
|
615
663
|
});
|
|
616
664
|
|
|
617
665
|
// src/datasets/datasetsClient.js
|
|
618
|
-
import assign5 from "object-assign";
|
|
619
666
|
var require_datasetsClient = __commonJS({
|
|
620
667
|
"src/datasets/datasetsClient.js"(exports, module) {
|
|
621
|
-
var validate =
|
|
668
|
+
var validate = (init_validators(), __toCommonJS(validators_exports));
|
|
622
669
|
function DatasetsClient(client) {
|
|
623
670
|
this.request = client.request.bind(client);
|
|
624
671
|
}
|
|
625
|
-
|
|
672
|
+
Object.assign(DatasetsClient.prototype, {
|
|
626
673
|
create(name, options) {
|
|
627
674
|
return this._modify("PUT", name, options);
|
|
628
675
|
},
|
|
@@ -645,13 +692,17 @@ var require_datasetsClient = __commonJS({
|
|
|
645
692
|
});
|
|
646
693
|
|
|
647
694
|
// src/projects/projectsClient.js
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
695
|
+
var projectsClient_exports = {};
|
|
696
|
+
__export(projectsClient_exports, {
|
|
697
|
+
default: () => projectsClient_default
|
|
698
|
+
});
|
|
699
|
+
function ProjectsClient(client) {
|
|
700
|
+
this.client = client;
|
|
701
|
+
}
|
|
702
|
+
var projectsClient_default;
|
|
703
|
+
var init_projectsClient = __esm({
|
|
704
|
+
"src/projects/projectsClient.js"() {
|
|
705
|
+
Object.assign(ProjectsClient.prototype, {
|
|
655
706
|
list() {
|
|
656
707
|
return this.client.request({ uri: "/projects" });
|
|
657
708
|
},
|
|
@@ -659,14 +710,19 @@ var require_projectsClient = __commonJS({
|
|
|
659
710
|
return this.client.request({ uri: `/projects/${id}` });
|
|
660
711
|
}
|
|
661
712
|
});
|
|
662
|
-
|
|
713
|
+
projectsClient_default = ProjectsClient;
|
|
663
714
|
}
|
|
664
715
|
});
|
|
665
716
|
|
|
666
717
|
// src/http/queryString.js
|
|
667
|
-
var
|
|
668
|
-
|
|
669
|
-
|
|
718
|
+
var queryString_exports = {};
|
|
719
|
+
__export(queryString_exports, {
|
|
720
|
+
default: () => queryString_default
|
|
721
|
+
});
|
|
722
|
+
var queryString_default;
|
|
723
|
+
var init_queryString = __esm({
|
|
724
|
+
"src/http/queryString.js"() {
|
|
725
|
+
queryString_default = (params) => {
|
|
670
726
|
const qs = [];
|
|
671
727
|
for (const key in params) {
|
|
672
728
|
if (params.hasOwnProperty(key)) {
|
|
@@ -679,12 +735,11 @@ var require_queryString = __commonJS({
|
|
|
679
735
|
});
|
|
680
736
|
|
|
681
737
|
// src/assets/assetsClient.js
|
|
682
|
-
import assign7 from "object-assign";
|
|
683
738
|
var require_assetsClient = __commonJS({
|
|
684
739
|
"src/assets/assetsClient.js"(exports, module) {
|
|
685
|
-
var { map: map2, filter: filter2 } =
|
|
686
|
-
var queryString =
|
|
687
|
-
var validators =
|
|
740
|
+
var { map: map2, filter: filter2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
|
|
741
|
+
var queryString = (init_queryString(), __toCommonJS(queryString_exports));
|
|
742
|
+
var validators = (init_validators(), __toCommonJS(validators_exports));
|
|
688
743
|
function AssetsClient(client) {
|
|
689
744
|
this.client = client;
|
|
690
745
|
}
|
|
@@ -692,7 +747,7 @@ var require_assetsClient = __commonJS({
|
|
|
692
747
|
if (typeof window === "undefined" || !(file instanceof window.File)) {
|
|
693
748
|
return opts;
|
|
694
749
|
}
|
|
695
|
-
return
|
|
750
|
+
return Object.assign(
|
|
696
751
|
{
|
|
697
752
|
filename: opts.preserveFilename === false ? void 0 : file.name,
|
|
698
753
|
contentType: file.type
|
|
@@ -700,14 +755,14 @@ var require_assetsClient = __commonJS({
|
|
|
700
755
|
opts
|
|
701
756
|
);
|
|
702
757
|
}
|
|
703
|
-
|
|
758
|
+
Object.assign(AssetsClient.prototype, {
|
|
704
759
|
upload(assetType, body, opts = {}) {
|
|
705
760
|
validators.validateAssetType(assetType);
|
|
706
761
|
let meta = opts.extract || void 0;
|
|
707
762
|
if (meta && !meta.length) {
|
|
708
763
|
meta = ["none"];
|
|
709
764
|
}
|
|
710
|
-
const
|
|
765
|
+
const dataset2 = validators.hasDataset(this.client.clientConfig);
|
|
711
766
|
const assetEndpoint = assetType === "image" ? "images" : "files";
|
|
712
767
|
const options = optionsFromFile(opts, body);
|
|
713
768
|
const { tag, label, title, description, creditLine, filename, source } = options;
|
|
@@ -728,7 +783,7 @@ var require_assetsClient = __commonJS({
|
|
|
728
783
|
tag,
|
|
729
784
|
method: "POST",
|
|
730
785
|
timeout: options.timeout || 0,
|
|
731
|
-
uri: `/assets/${assetEndpoint}/${
|
|
786
|
+
uri: `/assets/${assetEndpoint}/${dataset2}`,
|
|
732
787
|
headers: options.contentType ? { "Content-Type": options.contentType } : {},
|
|
733
788
|
query,
|
|
734
789
|
body
|
|
@@ -763,9 +818,9 @@ var require_assetsClient = __commonJS({
|
|
|
763
818
|
}
|
|
764
819
|
const [, assetId, size, format] = id.split("-");
|
|
765
820
|
validators.hasDataset(this.client.clientConfig);
|
|
766
|
-
const { projectId, dataset } = this.client.clientConfig;
|
|
821
|
+
const { projectId: projectId2, dataset: dataset2 } = this.client.clientConfig;
|
|
767
822
|
const qs = query ? queryString(query) : "";
|
|
768
|
-
return `https://cdn.sanity.io/images/${
|
|
823
|
+
return `https://cdn.sanity.io/images/${projectId2}/${dataset2}/${assetId}-${size}.${format}${qs}`;
|
|
769
824
|
}
|
|
770
825
|
});
|
|
771
826
|
module.exports = AssetsClient;
|
|
@@ -773,29 +828,32 @@ var require_assetsClient = __commonJS({
|
|
|
773
828
|
});
|
|
774
829
|
|
|
775
830
|
// src/users/usersClient.js
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
831
|
+
var usersClient_exports = {};
|
|
832
|
+
__export(usersClient_exports, {
|
|
833
|
+
default: () => usersClient_default
|
|
834
|
+
});
|
|
835
|
+
function UsersClient(client) {
|
|
836
|
+
this.client = client;
|
|
837
|
+
}
|
|
838
|
+
var usersClient_default;
|
|
839
|
+
var init_usersClient = __esm({
|
|
840
|
+
"src/users/usersClient.js"() {
|
|
841
|
+
Object.assign(UsersClient.prototype, {
|
|
783
842
|
getById(id) {
|
|
784
843
|
return this.client.request({ uri: `/users/${id}` });
|
|
785
844
|
}
|
|
786
845
|
});
|
|
787
|
-
|
|
846
|
+
usersClient_default = UsersClient;
|
|
788
847
|
}
|
|
789
848
|
});
|
|
790
849
|
|
|
791
850
|
// src/auth/authClient.js
|
|
792
|
-
import assign9 from "object-assign";
|
|
793
851
|
var require_authClient = __commonJS({
|
|
794
852
|
"src/auth/authClient.js"(exports, module) {
|
|
795
853
|
function AuthClient(client) {
|
|
796
854
|
this.client = client;
|
|
797
855
|
}
|
|
798
|
-
|
|
856
|
+
Object.assign(AuthClient.prototype, {
|
|
799
857
|
getLoginProviders() {
|
|
800
858
|
return this.client.request({ uri: "/auth/providers" });
|
|
801
859
|
},
|
|
@@ -809,73 +867,79 @@ var require_authClient = __commonJS({
|
|
|
809
867
|
|
|
810
868
|
// src/http/errors.js
|
|
811
869
|
import makeError from "make-error";
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
}
|
|
870
|
+
function ClientError(res) {
|
|
871
|
+
const props = extractErrorProps(res);
|
|
872
|
+
ClientError.super.call(this, props.message);
|
|
873
|
+
Object.assign(this, props);
|
|
874
|
+
}
|
|
875
|
+
function ServerError(res) {
|
|
876
|
+
const props = extractErrorProps(res);
|
|
877
|
+
ServerError.super.call(this, props.message);
|
|
878
|
+
Object.assign(this, props);
|
|
879
|
+
}
|
|
880
|
+
function extractErrorProps(res) {
|
|
881
|
+
const body = res.body;
|
|
882
|
+
const props = {
|
|
883
|
+
response: res,
|
|
884
|
+
statusCode: res.statusCode,
|
|
885
|
+
responseBody: stringifyBody(body, res)
|
|
886
|
+
};
|
|
887
|
+
if (body.error && body.message) {
|
|
888
|
+
props.message = `${body.error} - ${body.message}`;
|
|
889
|
+
return props;
|
|
890
|
+
}
|
|
891
|
+
if (body.error && body.error.description) {
|
|
892
|
+
props.message = body.error.description;
|
|
893
|
+
props.details = body.error;
|
|
894
|
+
return props;
|
|
895
|
+
}
|
|
896
|
+
props.message = body.error || body.message || httpErrorMessage(res);
|
|
897
|
+
return props;
|
|
898
|
+
}
|
|
899
|
+
function httpErrorMessage(res) {
|
|
900
|
+
const statusMessage = res.statusMessage ? ` ${res.statusMessage}` : "";
|
|
901
|
+
return `${res.method}-request to ${res.url} resulted in HTTP ${res.statusCode}${statusMessage}`;
|
|
902
|
+
}
|
|
903
|
+
function stringifyBody(body, res) {
|
|
904
|
+
const contentType = (res.headers["content-type"] || "").toLowerCase();
|
|
905
|
+
const isJson = contentType.indexOf("application/json") !== -1;
|
|
906
|
+
return isJson ? JSON.stringify(body, null, 2) : body;
|
|
907
|
+
}
|
|
908
|
+
var init_errors = __esm({
|
|
909
|
+
"src/http/errors.js"() {
|
|
853
910
|
makeError(ClientError);
|
|
854
911
|
makeError(ServerError);
|
|
855
|
-
exports.ClientError = ClientError;
|
|
856
|
-
exports.ServerError = ServerError;
|
|
857
912
|
}
|
|
858
913
|
});
|
|
859
914
|
|
|
860
915
|
// src/http/browserMiddleware.js
|
|
861
|
-
var
|
|
862
|
-
|
|
863
|
-
|
|
916
|
+
var browserMiddleware_exports = {};
|
|
917
|
+
__export(browserMiddleware_exports, {
|
|
918
|
+
default: () => browserMiddleware_default
|
|
919
|
+
});
|
|
920
|
+
var browserMiddleware_default;
|
|
921
|
+
var init_browserMiddleware = __esm({
|
|
922
|
+
"src/http/browserMiddleware.js"() {
|
|
923
|
+
browserMiddleware_default = [];
|
|
864
924
|
}
|
|
865
925
|
});
|
|
866
926
|
|
|
867
927
|
// src/http/request.js
|
|
928
|
+
var request_exports = {};
|
|
929
|
+
__export(request_exports, {
|
|
930
|
+
default: () => request_default
|
|
931
|
+
});
|
|
868
932
|
import getIt from "get-it";
|
|
869
|
-
import
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
var
|
|
875
|
-
"src/http/request.js"(
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
933
|
+
import { observable, jsonRequest, jsonResponse, progress } from "get-it/middleware";
|
|
934
|
+
function httpRequest(options, requester = request) {
|
|
935
|
+
return requester(Object.assign({ maxRedirects: 0 }, options));
|
|
936
|
+
}
|
|
937
|
+
var httpError, printWarnings, envSpecific, middleware, request, request_default;
|
|
938
|
+
var init_request = __esm({
|
|
939
|
+
"src/http/request.js"() {
|
|
940
|
+
init_observable_modern();
|
|
941
|
+
init_errors();
|
|
942
|
+
httpError = {
|
|
879
943
|
onResponse: (res) => {
|
|
880
944
|
if (res.statusCode >= 500) {
|
|
881
945
|
throw new ServerError(res);
|
|
@@ -885,7 +949,7 @@ var require_request = __commonJS({
|
|
|
885
949
|
return res;
|
|
886
950
|
}
|
|
887
951
|
};
|
|
888
|
-
|
|
952
|
+
printWarnings = {
|
|
889
953
|
onResponse: (res) => {
|
|
890
954
|
const warn = res.headers["x-sanity-warning"];
|
|
891
955
|
const warnings = Array.isArray(warn) ? warn : [warn];
|
|
@@ -893,32 +957,33 @@ var require_request = __commonJS({
|
|
|
893
957
|
return res;
|
|
894
958
|
}
|
|
895
959
|
};
|
|
896
|
-
|
|
897
|
-
|
|
960
|
+
envSpecific = typeof EdgeRuntime === "string" ? (init_browserMiddleware(), __toCommonJS(browserMiddleware_exports)) : (init_browserMiddleware(), __toCommonJS(browserMiddleware_exports));
|
|
961
|
+
middleware = envSpecific.concat([
|
|
898
962
|
printWarnings,
|
|
899
963
|
jsonRequest(),
|
|
900
964
|
jsonResponse(),
|
|
901
965
|
progress(),
|
|
902
966
|
httpError,
|
|
903
|
-
observable({ implementation:
|
|
967
|
+
observable({ implementation: Observable })
|
|
904
968
|
]);
|
|
905
|
-
|
|
906
|
-
function httpRequest(options, requester = request) {
|
|
907
|
-
return requester(assign11({ maxRedirects: 0 }, options));
|
|
908
|
-
}
|
|
969
|
+
request = getIt(middleware);
|
|
909
970
|
httpRequest.defaultRequester = request;
|
|
910
971
|
httpRequest.ClientError = ClientError;
|
|
911
972
|
httpRequest.ServerError = ServerError;
|
|
912
|
-
|
|
973
|
+
request_default = httpRequest;
|
|
913
974
|
}
|
|
914
975
|
});
|
|
915
976
|
|
|
916
977
|
// src/http/requestOptions.js
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
978
|
+
var requestOptions_exports = {};
|
|
979
|
+
__export(requestOptions_exports, {
|
|
980
|
+
default: () => requestOptions_default
|
|
981
|
+
});
|
|
982
|
+
var projectHeader, requestOptions_default;
|
|
983
|
+
var init_requestOptions = __esm({
|
|
984
|
+
"src/http/requestOptions.js"() {
|
|
985
|
+
projectHeader = "X-Sanity-Project-ID";
|
|
986
|
+
requestOptions_default = (config, overrides = {}) => {
|
|
922
987
|
const headers = {};
|
|
923
988
|
const token = overrides.token || config.token;
|
|
924
989
|
if (token) {
|
|
@@ -931,8 +996,8 @@ var require_requestOptions = __commonJS({
|
|
|
931
996
|
typeof overrides.withCredentials === "undefined" ? config.token || config.withCredentials : overrides.withCredentials
|
|
932
997
|
);
|
|
933
998
|
const timeout = typeof overrides.timeout === "undefined" ? config.timeout : overrides.timeout;
|
|
934
|
-
return
|
|
935
|
-
headers:
|
|
999
|
+
return Object.assign({}, overrides, {
|
|
1000
|
+
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
936
1001
|
timeout: typeof timeout === "undefined" ? 5 * 60 * 1e3 : timeout,
|
|
937
1002
|
proxy: overrides.proxy || config.proxy,
|
|
938
1003
|
json: true,
|
|
@@ -943,19 +1008,21 @@ var require_requestOptions = __commonJS({
|
|
|
943
1008
|
});
|
|
944
1009
|
|
|
945
1010
|
// src/generateHelpUrl.js
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
1011
|
+
function generateHelpUrl(slug) {
|
|
1012
|
+
return BASE_URL + slug;
|
|
1013
|
+
}
|
|
1014
|
+
var BASE_URL;
|
|
1015
|
+
var init_generateHelpUrl = __esm({
|
|
1016
|
+
"src/generateHelpUrl.js"() {
|
|
1017
|
+
BASE_URL = "https://docs.sanity.io/help/";
|
|
952
1018
|
}
|
|
953
1019
|
});
|
|
954
1020
|
|
|
955
1021
|
// src/util/once.js
|
|
956
|
-
var
|
|
957
|
-
|
|
958
|
-
|
|
1022
|
+
var once_default;
|
|
1023
|
+
var init_once = __esm({
|
|
1024
|
+
"src/util/once.js"() {
|
|
1025
|
+
once_default = (fn) => {
|
|
959
1026
|
let didCall = false;
|
|
960
1027
|
let returnValue;
|
|
961
1028
|
return (...args) => {
|
|
@@ -971,24 +1038,25 @@ var require_once = __commonJS({
|
|
|
971
1038
|
});
|
|
972
1039
|
|
|
973
1040
|
// src/warnings.js
|
|
974
|
-
var
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
1041
|
+
var createWarningPrinter, printCdnWarning, printBrowserTokenWarning, printNoApiVersionSpecifiedWarning;
|
|
1042
|
+
var init_warnings = __esm({
|
|
1043
|
+
"src/warnings.js"() {
|
|
1044
|
+
init_generateHelpUrl();
|
|
1045
|
+
init_once();
|
|
1046
|
+
createWarningPrinter = (message) => once_default((...args) => console.warn(message.join(" "), ...args));
|
|
1047
|
+
printCdnWarning = createWarningPrinter([
|
|
980
1048
|
"You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and",
|
|
981
1049
|
`cheaper. Think about it! For more info, see ${generateHelpUrl("js-client-cdn-configuration")}.`,
|
|
982
1050
|
"To hide this warning, please set the `useCdn` option to either `true` or `false` when creating",
|
|
983
1051
|
"the client."
|
|
984
1052
|
]);
|
|
985
|
-
|
|
1053
|
+
printBrowserTokenWarning = createWarningPrinter([
|
|
986
1054
|
"You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
|
|
987
1055
|
`See ${generateHelpUrl(
|
|
988
1056
|
"js-client-browser-token"
|
|
989
1057
|
)} for more information and how to hide this warning.`
|
|
990
1058
|
]);
|
|
991
|
-
|
|
1059
|
+
printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
992
1060
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
993
1061
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
994
1062
|
]);
|
|
@@ -996,28 +1064,43 @@ var require_warnings = __commonJS({
|
|
|
996
1064
|
});
|
|
997
1065
|
|
|
998
1066
|
// src/config.js
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1067
|
+
var config_exports = {};
|
|
1068
|
+
__export(config_exports, {
|
|
1069
|
+
defaultConfig: () => defaultConfig,
|
|
1070
|
+
initConfig: () => initConfig,
|
|
1071
|
+
validateApiVersion: () => validateApiVersion
|
|
1072
|
+
});
|
|
1073
|
+
var defaultCdnHost, defaultConfig, LOCALHOSTS, isLocal, validateApiVersion, initConfig;
|
|
1074
|
+
var init_config = __esm({
|
|
1075
|
+
"src/config.js"() {
|
|
1076
|
+
init_generateHelpUrl();
|
|
1077
|
+
init_validators();
|
|
1078
|
+
init_warnings();
|
|
1079
|
+
defaultCdnHost = "apicdn.sanity.io";
|
|
1080
|
+
defaultConfig = {
|
|
1007
1081
|
apiHost: "https://api.sanity.io",
|
|
1008
1082
|
apiVersion: "1",
|
|
1009
1083
|
useProjectHostname: true,
|
|
1010
1084
|
isPromiseAPI: true
|
|
1011
1085
|
};
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1086
|
+
LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
|
|
1087
|
+
isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
1088
|
+
validateApiVersion = function validateApiVersion2(apiVersion) {
|
|
1089
|
+
if (apiVersion === "1" || apiVersion === "X") {
|
|
1090
|
+
return;
|
|
1091
|
+
}
|
|
1092
|
+
const apiDate = new Date(apiVersion);
|
|
1093
|
+
const apiVersionValid = /^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0;
|
|
1094
|
+
if (!apiVersionValid) {
|
|
1095
|
+
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
initConfig = (config, prevConfig) => {
|
|
1099
|
+
const specifiedConfig = Object.assign({}, prevConfig, config);
|
|
1017
1100
|
if (!specifiedConfig.apiVersion) {
|
|
1018
|
-
|
|
1101
|
+
printNoApiVersionSpecifiedWarning();
|
|
1019
1102
|
}
|
|
1020
|
-
const newConfig =
|
|
1103
|
+
const newConfig = Object.assign({}, defaultConfig, specifiedConfig);
|
|
1021
1104
|
const projectBased = newConfig.useProjectHostname;
|
|
1022
1105
|
if (typeof Promise === "undefined") {
|
|
1023
1106
|
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
@@ -1029,23 +1112,23 @@ var require_config = __commonJS({
|
|
|
1029
1112
|
const isBrowser = typeof window !== "undefined" && window.location && window.location.hostname;
|
|
1030
1113
|
const isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
1031
1114
|
if (isBrowser && isLocalhost && newConfig.token && newConfig.ignoreBrowserTokenWarning !== true) {
|
|
1032
|
-
|
|
1115
|
+
printBrowserTokenWarning();
|
|
1033
1116
|
} else if (typeof newConfig.useCdn === "undefined") {
|
|
1034
|
-
|
|
1117
|
+
printCdnWarning();
|
|
1035
1118
|
}
|
|
1036
1119
|
if (projectBased) {
|
|
1037
|
-
|
|
1120
|
+
projectId(newConfig.projectId);
|
|
1038
1121
|
}
|
|
1039
1122
|
if (newConfig.dataset) {
|
|
1040
|
-
|
|
1123
|
+
dataset(newConfig.dataset);
|
|
1041
1124
|
}
|
|
1042
1125
|
if ("requestTagPrefix" in newConfig) {
|
|
1043
|
-
newConfig.requestTagPrefix = newConfig.requestTagPrefix ?
|
|
1126
|
+
newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0;
|
|
1044
1127
|
}
|
|
1045
1128
|
newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, "");
|
|
1046
1129
|
newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost;
|
|
1047
1130
|
newConfig.useCdn = Boolean(newConfig.useCdn) && !newConfig.withCredentials;
|
|
1048
|
-
|
|
1131
|
+
validateApiVersion(newConfig.apiVersion);
|
|
1049
1132
|
const hostParts = newConfig.apiHost.split("://", 2);
|
|
1050
1133
|
const protocol = hostParts[0];
|
|
1051
1134
|
const host = hostParts[1];
|
|
@@ -1059,66 +1142,55 @@ var require_config = __commonJS({
|
|
|
1059
1142
|
}
|
|
1060
1143
|
return newConfig;
|
|
1061
1144
|
};
|
|
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
1145
|
}
|
|
1073
1146
|
});
|
|
1074
1147
|
|
|
1075
1148
|
// src/sanityClient.js
|
|
1076
|
-
import assign14 from "object-assign";
|
|
1077
1149
|
var require_sanityClient = __commonJS({
|
|
1078
1150
|
"src/sanityClient.js"(exports, module) {
|
|
1079
|
-
var { Observable: Observable2, map: map2, filter: filter2 } =
|
|
1151
|
+
var { Observable: Observable2, map: map2, filter: filter2 } = (init_observable_modern(), __toCommonJS(observable_modern_exports));
|
|
1080
1152
|
var Patch = require_patch();
|
|
1081
1153
|
var Transaction = require_transaction();
|
|
1082
1154
|
var dataMethods = require_dataMethods();
|
|
1083
1155
|
var DatasetsClient = require_datasetsClient();
|
|
1084
|
-
var
|
|
1156
|
+
var ProjectsClient2 = (init_projectsClient(), __toCommonJS(projectsClient_exports));
|
|
1085
1157
|
var AssetsClient = require_assetsClient();
|
|
1086
|
-
var
|
|
1158
|
+
var UsersClient2 = (init_usersClient(), __toCommonJS(usersClient_exports));
|
|
1087
1159
|
var AuthClient = require_authClient();
|
|
1088
|
-
var
|
|
1089
|
-
var getRequestOptions =
|
|
1090
|
-
var { defaultConfig, initConfig } =
|
|
1091
|
-
var validate =
|
|
1160
|
+
var httpRequest2 = (init_request(), __toCommonJS(request_exports));
|
|
1161
|
+
var getRequestOptions = (init_requestOptions(), __toCommonJS(requestOptions_exports));
|
|
1162
|
+
var { defaultConfig: defaultConfig2, initConfig: initConfig2 } = (init_config(), __toCommonJS(config_exports));
|
|
1163
|
+
var validate = (init_validators(), __toCommonJS(validators_exports));
|
|
1092
1164
|
var toPromise = (observable2) => observable2.toPromise();
|
|
1093
|
-
function SanityClient(config =
|
|
1165
|
+
function SanityClient(config = defaultConfig2) {
|
|
1094
1166
|
if (!(this instanceof SanityClient)) {
|
|
1095
1167
|
return new SanityClient(config);
|
|
1096
1168
|
}
|
|
1097
1169
|
this.config(config);
|
|
1098
1170
|
this.assets = new AssetsClient(this);
|
|
1099
1171
|
this.datasets = new DatasetsClient(this);
|
|
1100
|
-
this.projects = new
|
|
1101
|
-
this.users = new
|
|
1172
|
+
this.projects = new ProjectsClient2(this);
|
|
1173
|
+
this.users = new UsersClient2(this);
|
|
1102
1174
|
this.auth = new AuthClient(this);
|
|
1103
1175
|
if (this.clientConfig.isPromiseAPI) {
|
|
1104
|
-
const observableConfig =
|
|
1176
|
+
const observableConfig = Object.assign({}, this.clientConfig, { isPromiseAPI: false });
|
|
1105
1177
|
this.observable = new SanityClient(observableConfig);
|
|
1106
1178
|
}
|
|
1107
1179
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1180
|
+
Object.assign(SanityClient.prototype, dataMethods);
|
|
1181
|
+
Object.assign(SanityClient.prototype, {
|
|
1110
1182
|
clone() {
|
|
1111
1183
|
return new SanityClient(this.config());
|
|
1112
1184
|
},
|
|
1113
1185
|
config(newConfig) {
|
|
1114
1186
|
if (typeof newConfig === "undefined") {
|
|
1115
|
-
return
|
|
1187
|
+
return Object.assign({}, this.clientConfig);
|
|
1116
1188
|
}
|
|
1117
1189
|
if (this.observable) {
|
|
1118
|
-
const observableConfig =
|
|
1190
|
+
const observableConfig = Object.assign({}, newConfig, { isPromiseAPI: false });
|
|
1119
1191
|
this.observable.config(observableConfig);
|
|
1120
1192
|
}
|
|
1121
|
-
this.clientConfig =
|
|
1193
|
+
this.clientConfig = initConfig2(newConfig, this.clientConfig || {});
|
|
1122
1194
|
return this;
|
|
1123
1195
|
},
|
|
1124
1196
|
withConfig(newConfig) {
|
|
@@ -1141,12 +1213,12 @@ var require_sanityClient = __commonJS({
|
|
|
1141
1213
|
}
|
|
1142
1214
|
const reqOptions = getRequestOptions(
|
|
1143
1215
|
this.clientConfig,
|
|
1144
|
-
|
|
1216
|
+
Object.assign({}, options, {
|
|
1145
1217
|
url: this.getUrl(uri, useCdn)
|
|
1146
1218
|
})
|
|
1147
1219
|
);
|
|
1148
1220
|
return new Observable2(
|
|
1149
|
-
(subscriber) =>
|
|
1221
|
+
(subscriber) => httpRequest2(reqOptions, this.clientConfig.requester).subscribe(subscriber)
|
|
1150
1222
|
);
|
|
1151
1223
|
},
|
|
1152
1224
|
request(options) {
|
|
@@ -1159,9 +1231,9 @@ var require_sanityClient = __commonJS({
|
|
|
1159
1231
|
});
|
|
1160
1232
|
SanityClient.Patch = Patch;
|
|
1161
1233
|
SanityClient.Transaction = Transaction;
|
|
1162
|
-
SanityClient.ClientError =
|
|
1163
|
-
SanityClient.ServerError =
|
|
1164
|
-
SanityClient.requester =
|
|
1234
|
+
SanityClient.ClientError = httpRequest2.ClientError;
|
|
1235
|
+
SanityClient.ServerError = httpRequest2.ServerError;
|
|
1236
|
+
SanityClient.requester = httpRequest2.defaultRequester;
|
|
1165
1237
|
module.exports = SanityClient;
|
|
1166
1238
|
}
|
|
1167
1239
|
});
|