@sanity/client 3.4.0-beta.esm.1 → 3.4.0-beta.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/dist/{sanityClient.node.js → sanityClient.node.cjs} +362 -259
- package/dist/{sanityClient.node.js.map → sanityClient.node.cjs.map} +1 -1
- package/package.json +12 -10
- package/src/assets/assetsClient.js +0 -135
- package/src/auth/authClient.js +0 -17
- package/src/config.js +0 -96
- package/src/data/dataMethods.js +0 -183
- package/src/data/encodeQueryString.js +0 -18
- package/src/data/listen.js +0 -160
- package/src/data/patch.js +0 -124
- package/src/data/transaction.js +0 -106
- package/src/datasets/datasetsClient.js +0 -31
- package/src/http/browserMiddleware.js +0 -1
- package/src/http/errors.js +0 -57
- package/src/http/nodeMiddleware.js +0 -13
- package/src/http/queryString.js +0 -10
- package/src/http/request.js +0 -54
- package/src/http/requestOptions.js +0 -31
- package/src/projects/projectsClient.js +0 -17
- package/src/sanityClient.js +0 -119
- package/src/users/usersClient.js +0 -13
- package/src/util/defaults.js +0 -8
- package/src/util/getSelection.js +0 -17
- package/src/util/observable.js +0 -11
- package/src/util/once.js +0 -12
- package/src/util/pick.js +0 -9
- package/src/validators.js +0 -76
- package/src/warnings.js +0 -25
|
@@ -1,33 +1,26 @@
|
|
|
1
1
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var
|
|
3
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
-
}) : x)(function(x) {
|
|
5
|
-
if (typeof require !== "undefined")
|
|
6
|
-
return require.apply(this, arguments);
|
|
7
|
-
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
-
});
|
|
9
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
10
3
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
4
|
};
|
|
12
5
|
|
|
13
6
|
// src/util/observable.js
|
|
14
7
|
var require_observable = __commonJS({
|
|
15
|
-
"src/util/observable.js"(
|
|
16
|
-
var { Observable } =
|
|
17
|
-
var { filter } =
|
|
18
|
-
var { map } =
|
|
19
|
-
|
|
20
|
-
Observable,
|
|
21
|
-
filter,
|
|
22
|
-
map
|
|
8
|
+
"src/util/observable.js"(exports2, module2) {
|
|
9
|
+
var { Observable: Observable2 } = require("rxjs/internal/Observable");
|
|
10
|
+
var { filter: filter2 } = require("rxjs/internal/operators/filter");
|
|
11
|
+
var { map: map2 } = require("rxjs/internal/operators/map");
|
|
12
|
+
module2.exports = {
|
|
13
|
+
Observable: Observable2,
|
|
14
|
+
filter: filter2,
|
|
15
|
+
map: map2
|
|
23
16
|
};
|
|
24
17
|
}
|
|
25
18
|
});
|
|
26
19
|
|
|
27
20
|
// src/util/getSelection.js
|
|
28
21
|
var require_getSelection = __commonJS({
|
|
29
|
-
"src/util/getSelection.js"(
|
|
30
|
-
|
|
22
|
+
"src/util/getSelection.js"(exports2, module2) {
|
|
23
|
+
module2.exports = function getSelection(sel) {
|
|
31
24
|
if (typeof sel === "string" || Array.isArray(sel)) {
|
|
32
25
|
return { id: sel };
|
|
33
26
|
}
|
|
@@ -48,41 +41,41 @@ ${selectionOpts}`);
|
|
|
48
41
|
|
|
49
42
|
// src/validators.js
|
|
50
43
|
var require_validators = __commonJS({
|
|
51
|
-
"src/validators.js"(
|
|
44
|
+
"src/validators.js"(exports2) {
|
|
52
45
|
var VALID_ASSET_TYPES = ["image", "file"];
|
|
53
46
|
var VALID_INSERT_LOCATIONS = ["before", "after", "replace"];
|
|
54
|
-
|
|
47
|
+
exports2.dataset = (name) => {
|
|
55
48
|
if (!/^(~[a-z0-9]{1}[-\w]{0,63}|[a-z0-9]{1}[-\w]{0,63})$/.test(name)) {
|
|
56
49
|
throw new Error("Datasets can only contain lowercase characters, numbers, underscores and dashes, and start with tilde, and be maximum 64 characters");
|
|
57
50
|
}
|
|
58
51
|
};
|
|
59
|
-
|
|
52
|
+
exports2.projectId = (id) => {
|
|
60
53
|
if (!/^[-a-z0-9]+$/i.test(id)) {
|
|
61
54
|
throw new Error("`projectId` can only contain only a-z, 0-9 and dashes");
|
|
62
55
|
}
|
|
63
56
|
};
|
|
64
|
-
|
|
57
|
+
exports2.validateAssetType = (type) => {
|
|
65
58
|
if (VALID_ASSET_TYPES.indexOf(type) === -1) {
|
|
66
59
|
throw new Error(`Invalid asset type: ${type}. Must be one of ${VALID_ASSET_TYPES.join(", ")}`);
|
|
67
60
|
}
|
|
68
61
|
};
|
|
69
|
-
|
|
62
|
+
exports2.validateObject = (op, val) => {
|
|
70
63
|
if (val === null || typeof val !== "object" || Array.isArray(val)) {
|
|
71
64
|
throw new Error(`${op}() takes an object of properties`);
|
|
72
65
|
}
|
|
73
66
|
};
|
|
74
|
-
|
|
67
|
+
exports2.requireDocumentId = (op, doc) => {
|
|
75
68
|
if (!doc._id) {
|
|
76
69
|
throw new Error(`${op}() requires that the document contains an ID ("_id" property)`);
|
|
77
70
|
}
|
|
78
|
-
|
|
71
|
+
exports2.validateDocumentId(op, doc._id);
|
|
79
72
|
};
|
|
80
|
-
|
|
73
|
+
exports2.validateDocumentId = (op, id) => {
|
|
81
74
|
if (typeof id !== "string" || !/^[a-z0-9_.-]+$/i.test(id)) {
|
|
82
75
|
throw new Error(`${op}(): "${id}" is not a valid document ID`);
|
|
83
76
|
}
|
|
84
77
|
};
|
|
85
|
-
|
|
78
|
+
exports2.validateInsert = (at, selector, items) => {
|
|
86
79
|
const signature = "insert(at, selector, items)";
|
|
87
80
|
if (VALID_INSERT_LOCATIONS.indexOf(at) === -1) {
|
|
88
81
|
const valid = VALID_INSERT_LOCATIONS.map((loc) => `"${loc}"`).join(", ");
|
|
@@ -95,13 +88,13 @@ var require_validators = __commonJS({
|
|
|
95
88
|
throw new Error(`${signature} takes an "items"-argument which must be an array`);
|
|
96
89
|
}
|
|
97
90
|
};
|
|
98
|
-
|
|
91
|
+
exports2.hasDataset = (config) => {
|
|
99
92
|
if (!config.dataset) {
|
|
100
93
|
throw new Error("`dataset` must be provided to perform queries");
|
|
101
94
|
}
|
|
102
95
|
return config.dataset || "";
|
|
103
96
|
};
|
|
104
|
-
|
|
97
|
+
exports2.requestTag = (tag) => {
|
|
105
98
|
if (typeof tag !== "string" || !/^[a-z0-9._-]{1,75}$/i.test(tag)) {
|
|
106
99
|
throw new Error(`Tag can only contain alphanumeric characters, underscores, dashes and dots, and be between one and 75 characters long.`);
|
|
107
100
|
}
|
|
@@ -112,20 +105,20 @@ var require_validators = __commonJS({
|
|
|
112
105
|
|
|
113
106
|
// src/data/patch.js
|
|
114
107
|
var require_patch = __commonJS({
|
|
115
|
-
"src/data/patch.js"(
|
|
116
|
-
var
|
|
108
|
+
"src/data/patch.js"(exports2, module2) {
|
|
109
|
+
var assign2 = require("object-assign");
|
|
117
110
|
var getSelection = require_getSelection();
|
|
118
|
-
var
|
|
119
|
-
var validateObject =
|
|
120
|
-
var validateInsert =
|
|
121
|
-
function
|
|
111
|
+
var validate2 = require_validators();
|
|
112
|
+
var validateObject = validate2.validateObject;
|
|
113
|
+
var validateInsert = validate2.validateInsert;
|
|
114
|
+
function Patch2(selection, operations = {}, client = null) {
|
|
122
115
|
this.selection = selection;
|
|
123
|
-
this.operations =
|
|
116
|
+
this.operations = assign2({}, operations);
|
|
124
117
|
this.client = client;
|
|
125
118
|
}
|
|
126
|
-
|
|
119
|
+
assign2(Patch2.prototype, {
|
|
127
120
|
clone() {
|
|
128
|
-
return new
|
|
121
|
+
return new Patch2(this.selection, assign2({}, this.operations), this.client);
|
|
129
122
|
},
|
|
130
123
|
set(props) {
|
|
131
124
|
return this._assign("set", props);
|
|
@@ -138,7 +131,7 @@ var require_patch = __commonJS({
|
|
|
138
131
|
if (!Array.isArray(attrs)) {
|
|
139
132
|
throw new Error("unset(attrs) takes an array of attributes to unset, non-array given");
|
|
140
133
|
}
|
|
141
|
-
this.operations =
|
|
134
|
+
this.operations = assign2({}, this.operations, { unset: attrs });
|
|
142
135
|
return this;
|
|
143
136
|
},
|
|
144
137
|
setIfMissing(props) {
|
|
@@ -177,7 +170,7 @@ var require_patch = __commonJS({
|
|
|
177
170
|
return this;
|
|
178
171
|
},
|
|
179
172
|
serialize() {
|
|
180
|
-
return
|
|
173
|
+
return assign2(getSelection(this.selection), this.operations);
|
|
181
174
|
},
|
|
182
175
|
toJSON() {
|
|
183
176
|
return this.serialize();
|
|
@@ -187,7 +180,7 @@ var require_patch = __commonJS({
|
|
|
187
180
|
throw new Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
188
181
|
}
|
|
189
182
|
const returnFirst = typeof this.selection === "string";
|
|
190
|
-
const opts =
|
|
183
|
+
const opts = assign2({ returnFirst, returnDocuments: true }, options);
|
|
191
184
|
return this.client.mutate({ patch: this.serialize() }, opts);
|
|
192
185
|
},
|
|
193
186
|
reset() {
|
|
@@ -199,31 +192,31 @@ var require_patch = __commonJS({
|
|
|
199
192
|
},
|
|
200
193
|
_assign(op, props, merge = true) {
|
|
201
194
|
validateObject(op, props);
|
|
202
|
-
this.operations =
|
|
203
|
-
[op]:
|
|
195
|
+
this.operations = assign2({}, this.operations, {
|
|
196
|
+
[op]: assign2({}, merge && this.operations[op] || {}, props)
|
|
204
197
|
});
|
|
205
198
|
return this;
|
|
206
199
|
}
|
|
207
200
|
});
|
|
208
|
-
|
|
201
|
+
module2.exports = Patch2;
|
|
209
202
|
}
|
|
210
203
|
});
|
|
211
204
|
|
|
212
205
|
// src/data/transaction.js
|
|
213
206
|
var require_transaction = __commonJS({
|
|
214
|
-
"src/data/transaction.js"(
|
|
215
|
-
var
|
|
207
|
+
"src/data/transaction.js"(exports2, module2) {
|
|
208
|
+
var assign2 = require("object-assign");
|
|
216
209
|
var validators = require_validators();
|
|
217
|
-
var
|
|
210
|
+
var Patch2 = require_patch();
|
|
218
211
|
var defaultMutateOptions = { returnDocuments: false };
|
|
219
|
-
function
|
|
212
|
+
function Transaction2(operations = [], client, transactionId) {
|
|
220
213
|
this.trxId = transactionId;
|
|
221
214
|
this.operations = operations;
|
|
222
215
|
this.client = client;
|
|
223
216
|
}
|
|
224
|
-
|
|
217
|
+
assign2(Transaction2.prototype, {
|
|
225
218
|
clone() {
|
|
226
|
-
return new
|
|
219
|
+
return new Transaction2(this.operations.slice(0), this.client, this.trxId);
|
|
227
220
|
},
|
|
228
221
|
create(doc) {
|
|
229
222
|
validators.validateObject("create", doc);
|
|
@@ -247,18 +240,18 @@ var require_transaction = __commonJS({
|
|
|
247
240
|
},
|
|
248
241
|
patch(documentId, patchOps) {
|
|
249
242
|
const isBuilder = typeof patchOps === "function";
|
|
250
|
-
const isPatch = documentId instanceof
|
|
243
|
+
const isPatch = documentId instanceof Patch2;
|
|
251
244
|
if (isPatch) {
|
|
252
245
|
return this._add({ patch: documentId.serialize() });
|
|
253
246
|
}
|
|
254
247
|
if (isBuilder) {
|
|
255
|
-
const patch = patchOps(new
|
|
256
|
-
if (!(patch instanceof
|
|
248
|
+
const patch = patchOps(new Patch2(documentId, {}, this.client));
|
|
249
|
+
if (!(patch instanceof Patch2)) {
|
|
257
250
|
throw new Error("function passed to `patch()` must return the patch");
|
|
258
251
|
}
|
|
259
252
|
return this._add({ patch: patch.serialize() });
|
|
260
253
|
}
|
|
261
|
-
return this._add({ patch:
|
|
254
|
+
return this._add({ patch: assign2({ id: documentId }, patchOps) });
|
|
262
255
|
},
|
|
263
256
|
transactionId(id) {
|
|
264
257
|
if (!id) {
|
|
@@ -277,7 +270,7 @@ var require_transaction = __commonJS({
|
|
|
277
270
|
if (!this.client) {
|
|
278
271
|
throw new Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
279
272
|
}
|
|
280
|
-
return this.client.mutate(this.serialize(),
|
|
273
|
+
return this.client.mutate(this.serialize(), assign2({ transactionId: this.trxId }, defaultMutateOptions, options || {}));
|
|
281
274
|
},
|
|
282
275
|
reset() {
|
|
283
276
|
this.operations = [];
|
|
@@ -288,15 +281,15 @@ var require_transaction = __commonJS({
|
|
|
288
281
|
return this;
|
|
289
282
|
}
|
|
290
283
|
});
|
|
291
|
-
|
|
284
|
+
module2.exports = Transaction2;
|
|
292
285
|
}
|
|
293
286
|
});
|
|
294
287
|
|
|
295
288
|
// src/data/encodeQueryString.js
|
|
296
289
|
var require_encodeQueryString = __commonJS({
|
|
297
|
-
"src/data/encodeQueryString.js"(
|
|
290
|
+
"src/data/encodeQueryString.js"(exports2, module2) {
|
|
298
291
|
var enc = encodeURIComponent;
|
|
299
|
-
|
|
292
|
+
module2.exports = ({ query, params = {}, options = {} }) => {
|
|
300
293
|
const { tag, ...opts } = options;
|
|
301
294
|
const q = `query=${enc(query)}`;
|
|
302
295
|
const base = tag ? `?tag=${enc(tag)}&${q}` : `?${q}`;
|
|
@@ -310,8 +303,8 @@ var require_encodeQueryString = __commonJS({
|
|
|
310
303
|
|
|
311
304
|
// src/util/pick.js
|
|
312
305
|
var require_pick = __commonJS({
|
|
313
|
-
"src/util/pick.js"(
|
|
314
|
-
|
|
306
|
+
"src/util/pick.js"(exports2, module2) {
|
|
307
|
+
module2.exports = (obj, props) => props.reduce((selection, prop) => {
|
|
315
308
|
if (typeof obj[prop] === "undefined") {
|
|
316
309
|
return selection;
|
|
317
310
|
}
|
|
@@ -323,8 +316,8 @@ var require_pick = __commonJS({
|
|
|
323
316
|
|
|
324
317
|
// src/util/defaults.js
|
|
325
318
|
var require_defaults = __commonJS({
|
|
326
|
-
"src/util/defaults.js"(
|
|
327
|
-
|
|
319
|
+
"src/util/defaults.js"(exports2, module2) {
|
|
320
|
+
module2.exports = (obj, defaults) => Object.keys(defaults).concat(Object.keys(obj)).reduce((target, prop) => {
|
|
328
321
|
target[prop] = typeof obj[prop] === "undefined" ? defaults[prop] : obj[prop];
|
|
329
322
|
return target;
|
|
330
323
|
}, {});
|
|
@@ -333,10 +326,10 @@ var require_defaults = __commonJS({
|
|
|
333
326
|
|
|
334
327
|
// src/data/listen.js
|
|
335
328
|
var require_listen = __commonJS({
|
|
336
|
-
"src/data/listen.js"(
|
|
337
|
-
var
|
|
338
|
-
var { Observable } = require_observable();
|
|
339
|
-
var polyfilledEventSource =
|
|
329
|
+
"src/data/listen.js"(exports2, module2) {
|
|
330
|
+
var assign2 = require("object-assign");
|
|
331
|
+
var { Observable: Observable2 } = require_observable();
|
|
332
|
+
var polyfilledEventSource = require("@sanity/eventsource");
|
|
340
333
|
var pick = require_pick();
|
|
341
334
|
var defaults = require_defaults();
|
|
342
335
|
var encodeQueryString = require_encodeQueryString();
|
|
@@ -352,7 +345,7 @@ var require_listen = __commonJS({
|
|
|
352
345
|
var defaultOptions = {
|
|
353
346
|
includeResult: true
|
|
354
347
|
};
|
|
355
|
-
|
|
348
|
+
module2.exports = function listen(query, params, opts = {}) {
|
|
356
349
|
const { url, token, withCredentials, requestTagPrefix } = this.clientConfig;
|
|
357
350
|
const tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag;
|
|
358
351
|
const options = { ...defaults(opts, defaultOptions), tag };
|
|
@@ -360,7 +353,7 @@ var require_listen = __commonJS({
|
|
|
360
353
|
const qs = encodeQueryString({ query, params, options: listenOpts, tag });
|
|
361
354
|
const uri = `${url}${this.getDataUrl("listen", qs)}`;
|
|
362
355
|
if (uri.length > MAX_URL_LENGTH) {
|
|
363
|
-
return new
|
|
356
|
+
return new Observable2((observer) => observer.error(new Error("Query too large for listener")));
|
|
364
357
|
}
|
|
365
358
|
const listenFor = options.events ? options.events : ["mutation"];
|
|
366
359
|
const shouldEmitReconnect = listenFor.indexOf("reconnect") !== -1;
|
|
@@ -373,7 +366,7 @@ var require_listen = __commonJS({
|
|
|
373
366
|
Authorization: `Bearer ${token}`
|
|
374
367
|
};
|
|
375
368
|
}
|
|
376
|
-
return new
|
|
369
|
+
return new Observable2((observer) => {
|
|
377
370
|
let es = getEventSource();
|
|
378
371
|
let reconnectTimer;
|
|
379
372
|
let stopped = false;
|
|
@@ -436,7 +429,7 @@ var require_listen = __commonJS({
|
|
|
436
429
|
function parseEvent(event) {
|
|
437
430
|
try {
|
|
438
431
|
const data = event.data && JSON.parse(event.data) || {};
|
|
439
|
-
return
|
|
432
|
+
return assign2({ type: event.type }, data);
|
|
440
433
|
} catch (err) {
|
|
441
434
|
return err;
|
|
442
435
|
}
|
|
@@ -462,14 +455,14 @@ var require_listen = __commonJS({
|
|
|
462
455
|
|
|
463
456
|
// src/data/dataMethods.js
|
|
464
457
|
var require_dataMethods = __commonJS({
|
|
465
|
-
"src/data/dataMethods.js"(
|
|
466
|
-
var
|
|
467
|
-
var { map, filter } = require_observable();
|
|
458
|
+
"src/data/dataMethods.js"(exports2, module2) {
|
|
459
|
+
var assign2 = require("object-assign");
|
|
460
|
+
var { map: map2, filter: filter2 } = require_observable();
|
|
468
461
|
var validators = require_validators();
|
|
469
462
|
var getSelection = require_getSelection();
|
|
470
463
|
var encodeQueryString = require_encodeQueryString();
|
|
471
|
-
var
|
|
472
|
-
var
|
|
464
|
+
var Transaction2 = require_transaction();
|
|
465
|
+
var Patch2 = require_patch();
|
|
473
466
|
var listen = require_listen();
|
|
474
467
|
var excludeFalsey = (param, defValue) => {
|
|
475
468
|
const value = typeof param === "undefined" ? defValue : param;
|
|
@@ -491,9 +484,9 @@ var require_dataMethods = __commonJS({
|
|
|
491
484
|
indexed[attr(doc)] = doc;
|
|
492
485
|
return indexed;
|
|
493
486
|
}, /* @__PURE__ */ Object.create(null));
|
|
494
|
-
var
|
|
487
|
+
var toPromise2 = (observable) => observable.toPromise();
|
|
495
488
|
var getQuerySizeLimit = 11264;
|
|
496
|
-
|
|
489
|
+
module2.exports = {
|
|
497
490
|
listen,
|
|
498
491
|
getDataUrl(operation, path) {
|
|
499
492
|
const config = this.clientConfig;
|
|
@@ -504,21 +497,21 @@ var require_dataMethods = __commonJS({
|
|
|
504
497
|
},
|
|
505
498
|
fetch(query, params, options = {}) {
|
|
506
499
|
const mapResponse = options.filterResponse === false ? (res) => res : (res) => res.result;
|
|
507
|
-
const observable = this._dataRequest("query", { query, params }, options).pipe(
|
|
508
|
-
return this.isPromiseAPI() ?
|
|
500
|
+
const observable = this._dataRequest("query", { query, params }, options).pipe(map2(mapResponse));
|
|
501
|
+
return this.isPromiseAPI() ? toPromise2(observable) : observable;
|
|
509
502
|
},
|
|
510
503
|
getDocument(id, opts = {}) {
|
|
511
504
|
const options = { uri: this.getDataUrl("doc", id), json: true, tag: opts.tag };
|
|
512
|
-
const observable = this._requestObservable(options).pipe(
|
|
513
|
-
return this.isPromiseAPI() ?
|
|
505
|
+
const observable = this._requestObservable(options).pipe(filter2(isResponse), map2((event) => event.body.documents && event.body.documents[0]));
|
|
506
|
+
return this.isPromiseAPI() ? toPromise2(observable) : observable;
|
|
514
507
|
},
|
|
515
508
|
getDocuments(ids, opts = {}) {
|
|
516
509
|
const options = { uri: this.getDataUrl("doc", ids.join(",")), json: true, tag: opts.tag };
|
|
517
|
-
const observable = this._requestObservable(options).pipe(
|
|
510
|
+
const observable = this._requestObservable(options).pipe(filter2(isResponse), map2((event) => {
|
|
518
511
|
const indexed = indexBy(event.body.documents || [], (doc) => doc._id);
|
|
519
512
|
return ids.map((id) => indexed[id] || null);
|
|
520
513
|
}));
|
|
521
|
-
return this.isPromiseAPI() ?
|
|
514
|
+
return this.isPromiseAPI() ? toPromise2(observable) : observable;
|
|
522
515
|
},
|
|
523
516
|
create(doc, options) {
|
|
524
517
|
return this._create(doc, "create", options);
|
|
@@ -532,23 +525,23 @@ var require_dataMethods = __commonJS({
|
|
|
532
525
|
return this._create(doc, "createOrReplace", options);
|
|
533
526
|
},
|
|
534
527
|
patch(selector, operations) {
|
|
535
|
-
return new
|
|
528
|
+
return new Patch2(selector, operations, this);
|
|
536
529
|
},
|
|
537
530
|
delete(selection, options) {
|
|
538
531
|
return this.dataRequest("mutate", { mutations: [{ delete: getSelection(selection) }] }, options);
|
|
539
532
|
},
|
|
540
533
|
mutate(mutations, options) {
|
|
541
|
-
const mut = mutations instanceof
|
|
534
|
+
const mut = mutations instanceof Patch2 || mutations instanceof Transaction2 ? mutations.serialize() : mutations;
|
|
542
535
|
const muts = Array.isArray(mut) ? mut : [mut];
|
|
543
536
|
const transactionId = options && options.transactionId;
|
|
544
537
|
return this.dataRequest("mutate", { mutations: muts, transactionId }, options);
|
|
545
538
|
},
|
|
546
539
|
transaction(operations) {
|
|
547
|
-
return new
|
|
540
|
+
return new Transaction2(operations, this);
|
|
548
541
|
},
|
|
549
542
|
dataRequest(endpoint, body, options = {}) {
|
|
550
543
|
const request = this._dataRequest(endpoint, body, options);
|
|
551
|
-
return this.isPromiseAPI() ?
|
|
544
|
+
return this.isPromiseAPI() ? toPromise2(request) : request;
|
|
552
545
|
},
|
|
553
546
|
_dataRequest(endpoint, body, options = {}) {
|
|
554
547
|
const isMutation = endpoint === "mutate";
|
|
@@ -571,7 +564,7 @@ var require_dataMethods = __commonJS({
|
|
|
571
564
|
tag,
|
|
572
565
|
canUseCdn: isQuery
|
|
573
566
|
};
|
|
574
|
-
return this._requestObservable(reqOptions).pipe(
|
|
567
|
+
return this._requestObservable(reqOptions).pipe(filter2(isResponse), map2(getBody), map2((res) => {
|
|
575
568
|
if (!isMutation) {
|
|
576
569
|
return res;
|
|
577
570
|
}
|
|
@@ -590,7 +583,7 @@ var require_dataMethods = __commonJS({
|
|
|
590
583
|
},
|
|
591
584
|
_create(doc, op, options = {}) {
|
|
592
585
|
const mutation = { [op]: doc };
|
|
593
|
-
const opts =
|
|
586
|
+
const opts = assign2({ returnFirst: true, returnDocuments: true }, options);
|
|
594
587
|
return this.dataRequest("mutate", { mutations: [mutation] }, opts);
|
|
595
588
|
}
|
|
596
589
|
};
|
|
@@ -599,13 +592,13 @@ var require_dataMethods = __commonJS({
|
|
|
599
592
|
|
|
600
593
|
// src/datasets/datasetsClient.js
|
|
601
594
|
var require_datasetsClient = __commonJS({
|
|
602
|
-
"src/datasets/datasetsClient.js"(
|
|
603
|
-
var
|
|
604
|
-
var
|
|
605
|
-
function
|
|
595
|
+
"src/datasets/datasetsClient.js"(exports2, module2) {
|
|
596
|
+
var assign2 = require("object-assign");
|
|
597
|
+
var validate2 = require_validators();
|
|
598
|
+
function DatasetsClient2(client) {
|
|
606
599
|
this.request = client.request.bind(client);
|
|
607
600
|
}
|
|
608
|
-
|
|
601
|
+
assign2(DatasetsClient2.prototype, {
|
|
609
602
|
create(name, options) {
|
|
610
603
|
return this._modify("PUT", name, options);
|
|
611
604
|
},
|
|
@@ -619,22 +612,22 @@ var require_datasetsClient = __commonJS({
|
|
|
619
612
|
return this.request({ uri: "/datasets" });
|
|
620
613
|
},
|
|
621
614
|
_modify(method, name, body) {
|
|
622
|
-
|
|
615
|
+
validate2.dataset(name);
|
|
623
616
|
return this.request({ method, uri: `/datasets/${name}`, body });
|
|
624
617
|
}
|
|
625
618
|
});
|
|
626
|
-
|
|
619
|
+
module2.exports = DatasetsClient2;
|
|
627
620
|
}
|
|
628
621
|
});
|
|
629
622
|
|
|
630
623
|
// src/projects/projectsClient.js
|
|
631
624
|
var require_projectsClient = __commonJS({
|
|
632
|
-
"src/projects/projectsClient.js"(
|
|
633
|
-
var
|
|
634
|
-
function
|
|
625
|
+
"src/projects/projectsClient.js"(exports2, module2) {
|
|
626
|
+
var assign2 = require("object-assign");
|
|
627
|
+
function ProjectsClient2(client) {
|
|
635
628
|
this.client = client;
|
|
636
629
|
}
|
|
637
|
-
|
|
630
|
+
assign2(ProjectsClient2.prototype, {
|
|
638
631
|
list() {
|
|
639
632
|
return this.client.request({ uri: "/projects" });
|
|
640
633
|
},
|
|
@@ -642,14 +635,14 @@ var require_projectsClient = __commonJS({
|
|
|
642
635
|
return this.client.request({ uri: `/projects/${id}` });
|
|
643
636
|
}
|
|
644
637
|
});
|
|
645
|
-
|
|
638
|
+
module2.exports = ProjectsClient2;
|
|
646
639
|
}
|
|
647
640
|
});
|
|
648
641
|
|
|
649
642
|
// src/http/queryString.js
|
|
650
643
|
var require_queryString = __commonJS({
|
|
651
|
-
"src/http/queryString.js"(
|
|
652
|
-
|
|
644
|
+
"src/http/queryString.js"(exports2, module2) {
|
|
645
|
+
module2.exports = (params) => {
|
|
653
646
|
const qs = [];
|
|
654
647
|
for (const key in params) {
|
|
655
648
|
if (params.hasOwnProperty(key)) {
|
|
@@ -663,24 +656,24 @@ var require_queryString = __commonJS({
|
|
|
663
656
|
|
|
664
657
|
// src/assets/assetsClient.js
|
|
665
658
|
var require_assetsClient = __commonJS({
|
|
666
|
-
"src/assets/assetsClient.js"(
|
|
667
|
-
var
|
|
668
|
-
var { map, filter } = require_observable();
|
|
659
|
+
"src/assets/assetsClient.js"(exports2, module2) {
|
|
660
|
+
var assign2 = require("object-assign");
|
|
661
|
+
var { map: map2, filter: filter2 } = require_observable();
|
|
669
662
|
var queryString = require_queryString();
|
|
670
663
|
var validators = require_validators();
|
|
671
|
-
function
|
|
664
|
+
function AssetsClient2(client) {
|
|
672
665
|
this.client = client;
|
|
673
666
|
}
|
|
674
667
|
function optionsFromFile(opts, file) {
|
|
675
668
|
if (typeof window === "undefined" || !(file instanceof window.File)) {
|
|
676
669
|
return opts;
|
|
677
670
|
}
|
|
678
|
-
return
|
|
671
|
+
return assign2({
|
|
679
672
|
filename: opts.preserveFilename === false ? void 0 : file.name,
|
|
680
673
|
contentType: file.type
|
|
681
674
|
}, opts);
|
|
682
675
|
}
|
|
683
|
-
|
|
676
|
+
assign2(AssetsClient2.prototype, {
|
|
684
677
|
upload(assetType, body, opts = {}) {
|
|
685
678
|
validators.validateAssetType(assetType);
|
|
686
679
|
let meta = opts.extract || void 0;
|
|
@@ -713,7 +706,7 @@ var require_assetsClient = __commonJS({
|
|
|
713
706
|
query,
|
|
714
707
|
body
|
|
715
708
|
});
|
|
716
|
-
return this.client.isPromiseAPI() ? observable.pipe(
|
|
709
|
+
return this.client.isPromiseAPI() ? observable.pipe(filter2((event) => event.type === "response"), map2((event) => event.body.document)).toPromise() : observable;
|
|
717
710
|
},
|
|
718
711
|
delete(type, id) {
|
|
719
712
|
console.warn("client.assets.delete() is deprecated, please use client.delete(<document-id>)");
|
|
@@ -741,34 +734,34 @@ var require_assetsClient = __commonJS({
|
|
|
741
734
|
return `https://cdn.sanity.io/images/${projectId}/${dataset}/${assetId}-${size}.${format}${qs}`;
|
|
742
735
|
}
|
|
743
736
|
});
|
|
744
|
-
|
|
737
|
+
module2.exports = AssetsClient2;
|
|
745
738
|
}
|
|
746
739
|
});
|
|
747
740
|
|
|
748
741
|
// src/users/usersClient.js
|
|
749
742
|
var require_usersClient = __commonJS({
|
|
750
|
-
"src/users/usersClient.js"(
|
|
751
|
-
var
|
|
752
|
-
function
|
|
743
|
+
"src/users/usersClient.js"(exports2, module2) {
|
|
744
|
+
var assign2 = require("object-assign");
|
|
745
|
+
function UsersClient2(client) {
|
|
753
746
|
this.client = client;
|
|
754
747
|
}
|
|
755
|
-
|
|
748
|
+
assign2(UsersClient2.prototype, {
|
|
756
749
|
getById(id) {
|
|
757
750
|
return this.client.request({ uri: `/users/${id}` });
|
|
758
751
|
}
|
|
759
752
|
});
|
|
760
|
-
|
|
753
|
+
module2.exports = UsersClient2;
|
|
761
754
|
}
|
|
762
755
|
});
|
|
763
756
|
|
|
764
757
|
// src/auth/authClient.js
|
|
765
758
|
var require_authClient = __commonJS({
|
|
766
|
-
"src/auth/authClient.js"(
|
|
767
|
-
var
|
|
768
|
-
function
|
|
759
|
+
"src/auth/authClient.js"(exports2, module2) {
|
|
760
|
+
var assign2 = require("object-assign");
|
|
761
|
+
function AuthClient2(client) {
|
|
769
762
|
this.client = client;
|
|
770
763
|
}
|
|
771
|
-
|
|
764
|
+
assign2(AuthClient2.prototype, {
|
|
772
765
|
getLoginProviders() {
|
|
773
766
|
return this.client.request({ uri: "/auth/providers" });
|
|
774
767
|
},
|
|
@@ -776,24 +769,24 @@ var require_authClient = __commonJS({
|
|
|
776
769
|
return this.client.request({ uri: "/auth/logout", method: "POST" });
|
|
777
770
|
}
|
|
778
771
|
});
|
|
779
|
-
|
|
772
|
+
module2.exports = AuthClient2;
|
|
780
773
|
}
|
|
781
774
|
});
|
|
782
775
|
|
|
783
776
|
// src/http/errors.js
|
|
784
777
|
var require_errors = __commonJS({
|
|
785
|
-
"src/http/errors.js"(
|
|
786
|
-
var makeError =
|
|
787
|
-
var
|
|
778
|
+
"src/http/errors.js"(exports2) {
|
|
779
|
+
var makeError = require("make-error");
|
|
780
|
+
var assign2 = require("object-assign");
|
|
788
781
|
function ClientError(res) {
|
|
789
782
|
const props = extractErrorProps(res);
|
|
790
783
|
ClientError.super.call(this, props.message);
|
|
791
|
-
|
|
784
|
+
assign2(this, props);
|
|
792
785
|
}
|
|
793
786
|
function ServerError(res) {
|
|
794
787
|
const props = extractErrorProps(res);
|
|
795
788
|
ServerError.super.call(this, props.message);
|
|
796
|
-
|
|
789
|
+
assign2(this, props);
|
|
797
790
|
}
|
|
798
791
|
function extractErrorProps(res) {
|
|
799
792
|
const body = res.body;
|
|
@@ -825,37 +818,152 @@ var require_errors = __commonJS({
|
|
|
825
818
|
}
|
|
826
819
|
makeError(ClientError);
|
|
827
820
|
makeError(ServerError);
|
|
828
|
-
|
|
829
|
-
|
|
821
|
+
exports2.ClientError = ClientError;
|
|
822
|
+
exports2.ServerError = ServerError;
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
|
|
826
|
+
// package.json
|
|
827
|
+
var require_package = __commonJS({
|
|
828
|
+
"package.json"(exports2, module2) {
|
|
829
|
+
module2.exports = {
|
|
830
|
+
name: "@sanity/client",
|
|
831
|
+
version: "3.4.0-beta.esm.4",
|
|
832
|
+
description: "Client for retrieving, creating and patching data from Sanity.io",
|
|
833
|
+
main: "lib/sanityClient.js",
|
|
834
|
+
umd: "umd/sanityClient.min.js",
|
|
835
|
+
unpkg: "umd/sanityClient.min.js",
|
|
836
|
+
types: "./sanityClient.d.ts",
|
|
837
|
+
exports: {
|
|
838
|
+
".": {
|
|
839
|
+
source: "./src/sanityClient.js",
|
|
840
|
+
browser: "./dist/sanityClient.browser.mjs",
|
|
841
|
+
node: "./dist/sanityClient.node.cjs",
|
|
842
|
+
default: "./lib/sanityClient.js"
|
|
843
|
+
}
|
|
844
|
+
},
|
|
845
|
+
files: [
|
|
846
|
+
"dist",
|
|
847
|
+
"lib",
|
|
848
|
+
"umd",
|
|
849
|
+
"sanityClient.d.ts"
|
|
850
|
+
],
|
|
851
|
+
scripts: {
|
|
852
|
+
browserify: "NODE_ENV=production BROWSERIFY_ENV=build DEBUG='' browserify -t envify -g uglifyify lib/sanityClient.js -o umd/sanityClient.js --standalone=SanityClient",
|
|
853
|
+
compile: "babel -d lib src",
|
|
854
|
+
build: "npm run compile && npm run browserify && npm run minify && npm run esbuild:browser && npm run esbuild:node",
|
|
855
|
+
esbuild: "esbuild src/sanityClient.js --bundle --sourcemap",
|
|
856
|
+
"esbuild:browser": "npm run esbuild -- --format=esm --outfile=dist/sanityClient.browser.mjs --platform=browser",
|
|
857
|
+
"esbuild:node": "npm run esbuild -- --format=cjs --outfile=dist/sanityClient.node.cjs --platform=node --external:object-assign --external:rxjs --external:@sanity/eventsource --external:get-it --external:make-error --external:@sanity/generate-help-url",
|
|
858
|
+
lint: "eslint .",
|
|
859
|
+
clean: "rimraf dist lib coverage .nyc_output umd/*.js",
|
|
860
|
+
coverage: "DEBUG=sanity NODE_ENV=test nyc --reporter=html --reporter=lcov --reporter=text npm test",
|
|
861
|
+
minify: "terser -c -m -- umd/sanityClient.js > umd/sanityClient.min.js",
|
|
862
|
+
prepublishOnly: "npm run clean && npm run build",
|
|
863
|
+
test: "NODE_ENV=test tape test/*.test.js",
|
|
864
|
+
"test:node.cjs": "TEST_COND=node NODE_ENV=test tape test/client.test.js",
|
|
865
|
+
"test:browser.mjs": "TEST_COND=browser NODE_ENV=test tape test/client.test.js",
|
|
866
|
+
posttest: "npm run lint"
|
|
867
|
+
},
|
|
868
|
+
browser: {
|
|
869
|
+
"./src/http/nodeMiddleware.js": "./src/http/browserMiddleware.js",
|
|
870
|
+
"./lib/http/nodeMiddleware.js": "./lib/http/browserMiddleware.js"
|
|
871
|
+
},
|
|
872
|
+
engines: {
|
|
873
|
+
node: ">=12"
|
|
874
|
+
},
|
|
875
|
+
dependencies: {
|
|
876
|
+
"@sanity/eventsource": "^4.0.0",
|
|
877
|
+
"@sanity/generate-help-url": "^3.0.0",
|
|
878
|
+
"get-it": "^6.0.1",
|
|
879
|
+
"make-error": "^1.3.0",
|
|
880
|
+
"object-assign": "^4.1.1",
|
|
881
|
+
rxjs: "^6.0.0"
|
|
882
|
+
},
|
|
883
|
+
devDependencies: {
|
|
884
|
+
"@babel/cli": "^7.17.6",
|
|
885
|
+
"@babel/core": "^7.17.7",
|
|
886
|
+
"@babel/preset-env": "^7.11.5",
|
|
887
|
+
browserify: "^17.0.0",
|
|
888
|
+
envify: "^4.0.0",
|
|
889
|
+
esbuild: "^0.14.43",
|
|
890
|
+
eslint: "^8.17.0",
|
|
891
|
+
"eslint-config-prettier": "^8.5.0",
|
|
892
|
+
"eslint-config-sanity": "^5.1.0",
|
|
893
|
+
nock: "^13.2.4",
|
|
894
|
+
"node-abort-controller": "^3.0.1",
|
|
895
|
+
"node-fetch": "^2.0.0",
|
|
896
|
+
nyc: "^15.1.0",
|
|
897
|
+
prettier: "^2.6.0",
|
|
898
|
+
rimraf: "^3.0.2",
|
|
899
|
+
"sse-channel": "^4.0.0",
|
|
900
|
+
tape: "^5.5.2",
|
|
901
|
+
terser: "^5.12.1",
|
|
902
|
+
uglifyify: "^5.0.1",
|
|
903
|
+
xtend: "4.0.2"
|
|
904
|
+
},
|
|
905
|
+
repository: {
|
|
906
|
+
type: "git",
|
|
907
|
+
url: "git+https://github.com/sanity-io/client.git"
|
|
908
|
+
},
|
|
909
|
+
keywords: [
|
|
910
|
+
"sanity",
|
|
911
|
+
"cms",
|
|
912
|
+
"headless",
|
|
913
|
+
"realtime",
|
|
914
|
+
"content",
|
|
915
|
+
"client",
|
|
916
|
+
"fetch",
|
|
917
|
+
"api"
|
|
918
|
+
],
|
|
919
|
+
author: "Sanity.io <hello@sanity.io>",
|
|
920
|
+
license: "MIT",
|
|
921
|
+
bugs: {
|
|
922
|
+
url: "https://github.com/sanity-io/client/issues"
|
|
923
|
+
},
|
|
924
|
+
homepage: "https://www.sanity.io/",
|
|
925
|
+
nyc: {
|
|
926
|
+
include: [
|
|
927
|
+
"src/**/*.js"
|
|
928
|
+
],
|
|
929
|
+
sourceMap: false
|
|
930
|
+
},
|
|
931
|
+
prettier: {
|
|
932
|
+
semi: false,
|
|
933
|
+
printWidth: 100,
|
|
934
|
+
bracketSpacing: false,
|
|
935
|
+
singleQuote: true
|
|
936
|
+
}
|
|
937
|
+
};
|
|
830
938
|
}
|
|
831
939
|
});
|
|
832
940
|
|
|
833
941
|
// src/http/nodeMiddleware.js
|
|
834
942
|
var require_nodeMiddleware = __commonJS({
|
|
835
|
-
"src/http/nodeMiddleware.js"(
|
|
836
|
-
var retry =
|
|
837
|
-
var debug =
|
|
838
|
-
var headers =
|
|
839
|
-
var pkg =
|
|
943
|
+
"src/http/nodeMiddleware.js"(exports2, module2) {
|
|
944
|
+
var retry = require("get-it/lib-node/middleware/retry");
|
|
945
|
+
var debug = require("get-it/lib-node/middleware/debug");
|
|
946
|
+
var headers = require("get-it/lib-node/middleware/headers");
|
|
947
|
+
var pkg = require_package();
|
|
840
948
|
var middleware = [
|
|
841
949
|
debug({ verbose: true, namespace: "sanity:client" }),
|
|
842
950
|
headers({ "User-Agent": `${pkg.name} ${pkg.version}` }),
|
|
843
951
|
retry({ maxRetries: 3 })
|
|
844
952
|
];
|
|
845
|
-
|
|
953
|
+
module2.exports = middleware;
|
|
846
954
|
}
|
|
847
955
|
});
|
|
848
956
|
|
|
849
957
|
// src/http/request.js
|
|
850
958
|
var require_request = __commonJS({
|
|
851
|
-
"src/http/request.js"(
|
|
852
|
-
var getIt =
|
|
853
|
-
var
|
|
854
|
-
var observable =
|
|
855
|
-
var jsonRequest =
|
|
856
|
-
var jsonResponse =
|
|
857
|
-
var progress =
|
|
858
|
-
var { Observable } = require_observable();
|
|
959
|
+
"src/http/request.js"(exports2, module2) {
|
|
960
|
+
var getIt = require("get-it");
|
|
961
|
+
var assign2 = require("object-assign");
|
|
962
|
+
var observable = require("get-it/lib/middleware/observable");
|
|
963
|
+
var jsonRequest = require("get-it/lib/middleware/jsonRequest");
|
|
964
|
+
var jsonResponse = require("get-it/lib/middleware/jsonResponse");
|
|
965
|
+
var progress = require("get-it/lib/middleware/progress");
|
|
966
|
+
var { Observable: Observable2 } = require_observable();
|
|
859
967
|
var { ClientError, ServerError } = require_errors();
|
|
860
968
|
var httpError = {
|
|
861
969
|
onResponse: (res) => {
|
|
@@ -882,25 +990,25 @@ var require_request = __commonJS({
|
|
|
882
990
|
jsonResponse(),
|
|
883
991
|
progress(),
|
|
884
992
|
httpError,
|
|
885
|
-
observable({ implementation:
|
|
993
|
+
observable({ implementation: Observable2 })
|
|
886
994
|
]);
|
|
887
995
|
var request = getIt(middleware);
|
|
888
|
-
function
|
|
889
|
-
return requester(
|
|
996
|
+
function httpRequest2(options, requester = request) {
|
|
997
|
+
return requester(assign2({ maxRedirects: 0 }, options));
|
|
890
998
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
999
|
+
httpRequest2.defaultRequester = request;
|
|
1000
|
+
httpRequest2.ClientError = ClientError;
|
|
1001
|
+
httpRequest2.ServerError = ServerError;
|
|
1002
|
+
module2.exports = httpRequest2;
|
|
895
1003
|
}
|
|
896
1004
|
});
|
|
897
1005
|
|
|
898
1006
|
// src/http/requestOptions.js
|
|
899
1007
|
var require_requestOptions = __commonJS({
|
|
900
|
-
"src/http/requestOptions.js"(
|
|
901
|
-
var
|
|
1008
|
+
"src/http/requestOptions.js"(exports2, module2) {
|
|
1009
|
+
var assign2 = require("object-assign");
|
|
902
1010
|
var projectHeader = "X-Sanity-Project-ID";
|
|
903
|
-
|
|
1011
|
+
module2.exports = (config, overrides = {}) => {
|
|
904
1012
|
const headers = {};
|
|
905
1013
|
const token = overrides.token || config.token;
|
|
906
1014
|
if (token) {
|
|
@@ -911,8 +1019,8 @@ var require_requestOptions = __commonJS({
|
|
|
911
1019
|
}
|
|
912
1020
|
const withCredentials = Boolean(typeof overrides.withCredentials === "undefined" ? config.token || config.withCredentials : overrides.withCredentials);
|
|
913
1021
|
const timeout = typeof overrides.timeout === "undefined" ? config.timeout : overrides.timeout;
|
|
914
|
-
return
|
|
915
|
-
headers:
|
|
1022
|
+
return assign2({}, overrides, {
|
|
1023
|
+
headers: assign2({}, headers, overrides.headers || {}),
|
|
916
1024
|
timeout: typeof timeout === "undefined" ? 5 * 60 * 1e3 : timeout,
|
|
917
1025
|
proxy: overrides.proxy || config.proxy,
|
|
918
1026
|
json: true,
|
|
@@ -924,8 +1032,8 @@ var require_requestOptions = __commonJS({
|
|
|
924
1032
|
|
|
925
1033
|
// src/util/once.js
|
|
926
1034
|
var require_once = __commonJS({
|
|
927
|
-
"src/util/once.js"(
|
|
928
|
-
|
|
1035
|
+
"src/util/once.js"(exports2, module2) {
|
|
1036
|
+
module2.exports = (fn) => {
|
|
929
1037
|
let didCall = false;
|
|
930
1038
|
let returnValue;
|
|
931
1039
|
return (...args) => {
|
|
@@ -942,21 +1050,21 @@ var require_once = __commonJS({
|
|
|
942
1050
|
|
|
943
1051
|
// src/warnings.js
|
|
944
1052
|
var require_warnings = __commonJS({
|
|
945
|
-
"src/warnings.js"(
|
|
946
|
-
var generateHelpUrl =
|
|
1053
|
+
"src/warnings.js"(exports2) {
|
|
1054
|
+
var generateHelpUrl = require("@sanity/generate-help-url").generateHelpUrl;
|
|
947
1055
|
var once = require_once();
|
|
948
1056
|
var createWarningPrinter = (message) => once((...args) => console.warn(message.join(" "), ...args));
|
|
949
|
-
|
|
1057
|
+
exports2.printCdnWarning = createWarningPrinter([
|
|
950
1058
|
"You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and",
|
|
951
1059
|
`cheaper. Think about it! For more info, see ${generateHelpUrl("js-client-cdn-configuration")}.`,
|
|
952
1060
|
"To hide this warning, please set the `useCdn` option to either `true` or `false` when creating",
|
|
953
1061
|
"the client."
|
|
954
1062
|
]);
|
|
955
|
-
|
|
1063
|
+
exports2.printBrowserTokenWarning = createWarningPrinter([
|
|
956
1064
|
"You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
|
|
957
1065
|
`See ${generateHelpUrl("js-client-browser-token")} for more information and how to hide this warning.`
|
|
958
1066
|
]);
|
|
959
|
-
|
|
1067
|
+
exports2.printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
960
1068
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
961
1069
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
962
1070
|
]);
|
|
@@ -965,13 +1073,13 @@ var require_warnings = __commonJS({
|
|
|
965
1073
|
|
|
966
1074
|
// src/config.js
|
|
967
1075
|
var require_config = __commonJS({
|
|
968
|
-
"src/config.js"(
|
|
969
|
-
var generateHelpUrl =
|
|
970
|
-
var
|
|
971
|
-
var
|
|
1076
|
+
"src/config.js"(exports2) {
|
|
1077
|
+
var generateHelpUrl = require("@sanity/generate-help-url").generateHelpUrl;
|
|
1078
|
+
var assign2 = require("object-assign");
|
|
1079
|
+
var validate2 = require_validators();
|
|
972
1080
|
var warnings = require_warnings();
|
|
973
1081
|
var defaultCdnHost = "apicdn.sanity.io";
|
|
974
|
-
var
|
|
1082
|
+
var defaultConfig2 = {
|
|
975
1083
|
apiHost: "https://api.sanity.io",
|
|
976
1084
|
apiVersion: "1",
|
|
977
1085
|
useProjectHostname: true,
|
|
@@ -979,13 +1087,13 @@ var require_config = __commonJS({
|
|
|
979
1087
|
};
|
|
980
1088
|
var LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
|
|
981
1089
|
var isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
const specifiedConfig =
|
|
1090
|
+
exports2.defaultConfig = defaultConfig2;
|
|
1091
|
+
exports2.initConfig = (config, prevConfig) => {
|
|
1092
|
+
const specifiedConfig = assign2({}, prevConfig, config);
|
|
985
1093
|
if (!specifiedConfig.apiVersion) {
|
|
986
1094
|
warnings.printNoApiVersionSpecifiedWarning();
|
|
987
1095
|
}
|
|
988
|
-
const newConfig =
|
|
1096
|
+
const newConfig = assign2({}, defaultConfig2, specifiedConfig);
|
|
989
1097
|
const projectBased = newConfig.useProjectHostname;
|
|
990
1098
|
if (typeof Promise === "undefined") {
|
|
991
1099
|
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
@@ -1002,18 +1110,18 @@ var require_config = __commonJS({
|
|
|
1002
1110
|
warnings.printCdnWarning();
|
|
1003
1111
|
}
|
|
1004
1112
|
if (projectBased) {
|
|
1005
|
-
|
|
1113
|
+
validate2.projectId(newConfig.projectId);
|
|
1006
1114
|
}
|
|
1007
1115
|
if (newConfig.dataset) {
|
|
1008
|
-
|
|
1116
|
+
validate2.dataset(newConfig.dataset);
|
|
1009
1117
|
}
|
|
1010
1118
|
if ("requestTagPrefix" in newConfig) {
|
|
1011
|
-
newConfig.requestTagPrefix = newConfig.requestTagPrefix ?
|
|
1119
|
+
newConfig.requestTagPrefix = newConfig.requestTagPrefix ? validate2.requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0;
|
|
1012
1120
|
}
|
|
1013
1121
|
newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, "");
|
|
1014
|
-
newConfig.isDefaultApi = newConfig.apiHost ===
|
|
1122
|
+
newConfig.isDefaultApi = newConfig.apiHost === defaultConfig2.apiHost;
|
|
1015
1123
|
newConfig.useCdn = Boolean(newConfig.useCdn) && !newConfig.withCredentials;
|
|
1016
|
-
|
|
1124
|
+
exports2.validateApiVersion(newConfig.apiVersion);
|
|
1017
1125
|
const hostParts = newConfig.apiHost.split("://", 2);
|
|
1018
1126
|
const protocol = hostParts[0];
|
|
1019
1127
|
const host = hostParts[1];
|
|
@@ -1027,7 +1135,7 @@ var require_config = __commonJS({
|
|
|
1027
1135
|
}
|
|
1028
1136
|
return newConfig;
|
|
1029
1137
|
};
|
|
1030
|
-
|
|
1138
|
+
exports2.validateApiVersion = function validateApiVersion(apiVersion) {
|
|
1031
1139
|
if (apiVersion === "1" || apiVersion === "X") {
|
|
1032
1140
|
return;
|
|
1033
1141
|
}
|
|
@@ -1041,89 +1149,84 @@ var require_config = __commonJS({
|
|
|
1041
1149
|
});
|
|
1042
1150
|
|
|
1043
1151
|
// src/sanityClient.js
|
|
1044
|
-
var
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1152
|
+
var assign = require("object-assign");
|
|
1153
|
+
var { Observable, map, filter } = require_observable();
|
|
1154
|
+
var Patch = require_patch();
|
|
1155
|
+
var Transaction = require_transaction();
|
|
1156
|
+
var dataMethods = require_dataMethods();
|
|
1157
|
+
var DatasetsClient = require_datasetsClient();
|
|
1158
|
+
var ProjectsClient = require_projectsClient();
|
|
1159
|
+
var AssetsClient = require_assetsClient();
|
|
1160
|
+
var UsersClient = require_usersClient();
|
|
1161
|
+
var AuthClient = require_authClient();
|
|
1162
|
+
var httpRequest = require_request();
|
|
1163
|
+
var getRequestOptions = require_requestOptions();
|
|
1164
|
+
var { defaultConfig, initConfig } = require_config();
|
|
1165
|
+
var validate = require_validators();
|
|
1166
|
+
var toPromise = (observable) => observable.toPromise();
|
|
1167
|
+
function SanityClient(config = defaultConfig) {
|
|
1168
|
+
if (!(this instanceof SanityClient)) {
|
|
1169
|
+
return new SanityClient(config);
|
|
1170
|
+
}
|
|
1171
|
+
this.config(config);
|
|
1172
|
+
this.assets = new AssetsClient(this);
|
|
1173
|
+
this.datasets = new DatasetsClient(this);
|
|
1174
|
+
this.projects = new ProjectsClient(this);
|
|
1175
|
+
this.users = new UsersClient(this);
|
|
1176
|
+
this.auth = new AuthClient(this);
|
|
1177
|
+
if (this.clientConfig.isPromiseAPI) {
|
|
1178
|
+
const observableConfig = assign({}, this.clientConfig, { isPromiseAPI: false });
|
|
1179
|
+
this.observable = new SanityClient(observableConfig);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
assign(SanityClient.prototype, dataMethods);
|
|
1183
|
+
assign(SanityClient.prototype, {
|
|
1184
|
+
clone() {
|
|
1185
|
+
return new SanityClient(this.config());
|
|
1186
|
+
},
|
|
1187
|
+
config(newConfig) {
|
|
1188
|
+
if (typeof newConfig === "undefined") {
|
|
1189
|
+
return assign({}, this.clientConfig);
|
|
1075
1190
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
}
|
|
1110
|
-
const reqOptions = getRequestOptions(this.clientConfig, assign({}, options, {
|
|
1111
|
-
url: this.getUrl(uri, useCdn)
|
|
1112
|
-
}));
|
|
1113
|
-
return new Observable((subscriber) => httpRequest(reqOptions, this.clientConfig.requester).subscribe(subscriber));
|
|
1114
|
-
},
|
|
1115
|
-
request(options) {
|
|
1116
|
-
const observable = this._requestObservable(options).pipe(filter((event) => event.type === "response"), map((event) => event.body));
|
|
1117
|
-
return this.isPromiseAPI() ? toPromise(observable) : observable;
|
|
1118
|
-
}
|
|
1119
|
-
});
|
|
1120
|
-
SanityClient.Patch = Patch;
|
|
1121
|
-
SanityClient.Transaction = Transaction;
|
|
1122
|
-
SanityClient.ClientError = httpRequest.ClientError;
|
|
1123
|
-
SanityClient.ServerError = httpRequest.ServerError;
|
|
1124
|
-
SanityClient.requester = httpRequest.defaultRequester;
|
|
1125
|
-
module.exports = SanityClient;
|
|
1191
|
+
if (this.observable) {
|
|
1192
|
+
const observableConfig = assign({}, newConfig, { isPromiseAPI: false });
|
|
1193
|
+
this.observable.config(observableConfig);
|
|
1194
|
+
}
|
|
1195
|
+
this.clientConfig = initConfig(newConfig, this.clientConfig || {});
|
|
1196
|
+
return this;
|
|
1197
|
+
},
|
|
1198
|
+
withConfig(newConfig) {
|
|
1199
|
+
return this.clone().config(newConfig);
|
|
1200
|
+
},
|
|
1201
|
+
getUrl(uri, useCdn = false) {
|
|
1202
|
+
const base = useCdn ? this.clientConfig.cdnUrl : this.clientConfig.url;
|
|
1203
|
+
return `${base}/${uri.replace(/^\//, "")}`;
|
|
1204
|
+
},
|
|
1205
|
+
isPromiseAPI() {
|
|
1206
|
+
return this.clientConfig.isPromiseAPI;
|
|
1207
|
+
},
|
|
1208
|
+
_requestObservable(options) {
|
|
1209
|
+
const uri = options.url || options.uri;
|
|
1210
|
+
const canUseCdn = typeof options.canUseCdn === "undefined" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
|
|
1211
|
+
const useCdn = this.clientConfig.useCdn && canUseCdn;
|
|
1212
|
+
const tag = options.tag && this.clientConfig.requestTagPrefix ? [this.clientConfig.requestTagPrefix, options.tag].join(".") : options.tag || this.clientConfig.requestTagPrefix;
|
|
1213
|
+
if (tag) {
|
|
1214
|
+
options.query = { tag: validate.requestTag(tag), ...options.query };
|
|
1215
|
+
}
|
|
1216
|
+
const reqOptions = getRequestOptions(this.clientConfig, assign({}, options, {
|
|
1217
|
+
url: this.getUrl(uri, useCdn)
|
|
1218
|
+
}));
|
|
1219
|
+
return new Observable((subscriber) => httpRequest(reqOptions, this.clientConfig.requester).subscribe(subscriber));
|
|
1220
|
+
},
|
|
1221
|
+
request(options) {
|
|
1222
|
+
const observable = this._requestObservable(options).pipe(filter((event) => event.type === "response"), map((event) => event.body));
|
|
1223
|
+
return this.isPromiseAPI() ? toPromise(observable) : observable;
|
|
1126
1224
|
}
|
|
1127
1225
|
});
|
|
1128
|
-
|
|
1129
|
-
|
|
1226
|
+
SanityClient.Patch = Patch;
|
|
1227
|
+
SanityClient.Transaction = Transaction;
|
|
1228
|
+
SanityClient.ClientError = httpRequest.ClientError;
|
|
1229
|
+
SanityClient.ServerError = httpRequest.ServerError;
|
|
1230
|
+
SanityClient.requester = httpRequest.defaultRequester;
|
|
1231
|
+
module.exports = SanityClient;
|
|
1232
|
+
//# sourceMappingURL=sanityClient.node.cjs.map
|