@sanity/client 3.4.0-beta.esm.2 → 3.4.0-beta.esm.3
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.
|
@@ -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,149 @@ 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.3",
|
|
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
|
+
module: "./dist/sanityClient.browser.mjs",
|
|
838
|
+
exports: {
|
|
839
|
+
".": {
|
|
840
|
+
source: "./src/sanityClient.js",
|
|
841
|
+
browser: "./dist/sanityClient.browser.mjs",
|
|
842
|
+
default: "./dist/sanityClient.node.cjs"
|
|
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:get-it --external:@sanity/eventsource --external:@sanity/generate-help-url --external:make-error --external:rxjs",
|
|
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
|
+
posttest: "npm run lint && package-check"
|
|
865
|
+
},
|
|
866
|
+
browser: {
|
|
867
|
+
"./src/http/nodeMiddleware.js": "./src/http/browserMiddleware.js",
|
|
868
|
+
"./lib/http/nodeMiddleware.js": "./lib/http/browserMiddleware.js"
|
|
869
|
+
},
|
|
870
|
+
engines: {
|
|
871
|
+
node: ">=12"
|
|
872
|
+
},
|
|
873
|
+
dependencies: {
|
|
874
|
+
"@sanity/eventsource": "^4.0.0",
|
|
875
|
+
"@sanity/generate-help-url": "^3.0.0",
|
|
876
|
+
"get-it": "^6.0.1",
|
|
877
|
+
"make-error": "^1.3.0",
|
|
878
|
+
"object-assign": "^4.1.1",
|
|
879
|
+
rxjs: "^6.0.0"
|
|
880
|
+
},
|
|
881
|
+
devDependencies: {
|
|
882
|
+
"@babel/cli": "^7.17.6",
|
|
883
|
+
"@babel/core": "^7.17.7",
|
|
884
|
+
"@babel/preset-env": "^7.11.5",
|
|
885
|
+
"@skypack/package-check": "^0.2.2",
|
|
886
|
+
browserify: "^17.0.0",
|
|
887
|
+
envify: "^4.0.0",
|
|
888
|
+
esbuild: "^0.14.43",
|
|
889
|
+
eslint: "^8.11.0",
|
|
890
|
+
"eslint-config-prettier": "^8.5.0",
|
|
891
|
+
"eslint-config-sanity": "^5.1.0",
|
|
892
|
+
nock: "^13.2.4",
|
|
893
|
+
nyc: "^15.1.0",
|
|
894
|
+
prettier: "^2.6.0",
|
|
895
|
+
rimraf: "^3.0.2",
|
|
896
|
+
"sse-channel": "^4.0.0",
|
|
897
|
+
tape: "^5.5.2",
|
|
898
|
+
terser: "^5.12.1",
|
|
899
|
+
uglifyify: "^5.0.1",
|
|
900
|
+
xtend: "4.0.2"
|
|
901
|
+
},
|
|
902
|
+
repository: {
|
|
903
|
+
type: "git",
|
|
904
|
+
url: "git+https://github.com/sanity-io/client.git"
|
|
905
|
+
},
|
|
906
|
+
keywords: [
|
|
907
|
+
"sanity",
|
|
908
|
+
"cms",
|
|
909
|
+
"headless",
|
|
910
|
+
"realtime",
|
|
911
|
+
"content",
|
|
912
|
+
"client",
|
|
913
|
+
"fetch",
|
|
914
|
+
"api"
|
|
915
|
+
],
|
|
916
|
+
author: "Sanity.io <hello@sanity.io>",
|
|
917
|
+
license: "MIT",
|
|
918
|
+
bugs: {
|
|
919
|
+
url: "https://github.com/sanity-io/client/issues"
|
|
920
|
+
},
|
|
921
|
+
homepage: "https://www.sanity.io/",
|
|
922
|
+
nyc: {
|
|
923
|
+
include: [
|
|
924
|
+
"src/**/*.js"
|
|
925
|
+
],
|
|
926
|
+
sourceMap: false
|
|
927
|
+
},
|
|
928
|
+
prettier: {
|
|
929
|
+
semi: false,
|
|
930
|
+
printWidth: 100,
|
|
931
|
+
bracketSpacing: false,
|
|
932
|
+
singleQuote: true
|
|
933
|
+
}
|
|
934
|
+
};
|
|
830
935
|
}
|
|
831
936
|
});
|
|
832
937
|
|
|
833
938
|
// src/http/nodeMiddleware.js
|
|
834
939
|
var require_nodeMiddleware = __commonJS({
|
|
835
|
-
"src/http/nodeMiddleware.js"(
|
|
836
|
-
var retry =
|
|
837
|
-
var debug =
|
|
838
|
-
var headers =
|
|
839
|
-
var pkg =
|
|
940
|
+
"src/http/nodeMiddleware.js"(exports2, module2) {
|
|
941
|
+
var retry = require("get-it/lib-node/middleware/retry");
|
|
942
|
+
var debug = require("get-it/lib-node/middleware/debug");
|
|
943
|
+
var headers = require("get-it/lib-node/middleware/headers");
|
|
944
|
+
var pkg = require_package();
|
|
840
945
|
var middleware = [
|
|
841
946
|
debug({ verbose: true, namespace: "sanity:client" }),
|
|
842
947
|
headers({ "User-Agent": `${pkg.name} ${pkg.version}` }),
|
|
843
948
|
retry({ maxRetries: 3 })
|
|
844
949
|
];
|
|
845
|
-
|
|
950
|
+
module2.exports = middleware;
|
|
846
951
|
}
|
|
847
952
|
});
|
|
848
953
|
|
|
849
954
|
// src/http/request.js
|
|
850
955
|
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();
|
|
956
|
+
"src/http/request.js"(exports2, module2) {
|
|
957
|
+
var getIt = require("get-it");
|
|
958
|
+
var assign2 = require("object-assign");
|
|
959
|
+
var observable = require("get-it/lib/middleware/observable");
|
|
960
|
+
var jsonRequest = require("get-it/lib/middleware/jsonRequest");
|
|
961
|
+
var jsonResponse = require("get-it/lib/middleware/jsonResponse");
|
|
962
|
+
var progress = require("get-it/lib/middleware/progress");
|
|
963
|
+
var { Observable: Observable2 } = require_observable();
|
|
859
964
|
var { ClientError, ServerError } = require_errors();
|
|
860
965
|
var httpError = {
|
|
861
966
|
onResponse: (res) => {
|
|
@@ -882,25 +987,25 @@ var require_request = __commonJS({
|
|
|
882
987
|
jsonResponse(),
|
|
883
988
|
progress(),
|
|
884
989
|
httpError,
|
|
885
|
-
observable({ implementation:
|
|
990
|
+
observable({ implementation: Observable2 })
|
|
886
991
|
]);
|
|
887
992
|
var request = getIt(middleware);
|
|
888
|
-
function
|
|
889
|
-
return requester(
|
|
993
|
+
function httpRequest2(options, requester = request) {
|
|
994
|
+
return requester(assign2({ maxRedirects: 0 }, options));
|
|
890
995
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
996
|
+
httpRequest2.defaultRequester = request;
|
|
997
|
+
httpRequest2.ClientError = ClientError;
|
|
998
|
+
httpRequest2.ServerError = ServerError;
|
|
999
|
+
module2.exports = httpRequest2;
|
|
895
1000
|
}
|
|
896
1001
|
});
|
|
897
1002
|
|
|
898
1003
|
// src/http/requestOptions.js
|
|
899
1004
|
var require_requestOptions = __commonJS({
|
|
900
|
-
"src/http/requestOptions.js"(
|
|
901
|
-
var
|
|
1005
|
+
"src/http/requestOptions.js"(exports2, module2) {
|
|
1006
|
+
var assign2 = require("object-assign");
|
|
902
1007
|
var projectHeader = "X-Sanity-Project-ID";
|
|
903
|
-
|
|
1008
|
+
module2.exports = (config, overrides = {}) => {
|
|
904
1009
|
const headers = {};
|
|
905
1010
|
const token = overrides.token || config.token;
|
|
906
1011
|
if (token) {
|
|
@@ -911,8 +1016,8 @@ var require_requestOptions = __commonJS({
|
|
|
911
1016
|
}
|
|
912
1017
|
const withCredentials = Boolean(typeof overrides.withCredentials === "undefined" ? config.token || config.withCredentials : overrides.withCredentials);
|
|
913
1018
|
const timeout = typeof overrides.timeout === "undefined" ? config.timeout : overrides.timeout;
|
|
914
|
-
return
|
|
915
|
-
headers:
|
|
1019
|
+
return assign2({}, overrides, {
|
|
1020
|
+
headers: assign2({}, headers, overrides.headers || {}),
|
|
916
1021
|
timeout: typeof timeout === "undefined" ? 5 * 60 * 1e3 : timeout,
|
|
917
1022
|
proxy: overrides.proxy || config.proxy,
|
|
918
1023
|
json: true,
|
|
@@ -924,8 +1029,8 @@ var require_requestOptions = __commonJS({
|
|
|
924
1029
|
|
|
925
1030
|
// src/util/once.js
|
|
926
1031
|
var require_once = __commonJS({
|
|
927
|
-
"src/util/once.js"(
|
|
928
|
-
|
|
1032
|
+
"src/util/once.js"(exports2, module2) {
|
|
1033
|
+
module2.exports = (fn) => {
|
|
929
1034
|
let didCall = false;
|
|
930
1035
|
let returnValue;
|
|
931
1036
|
return (...args) => {
|
|
@@ -942,21 +1047,21 @@ var require_once = __commonJS({
|
|
|
942
1047
|
|
|
943
1048
|
// src/warnings.js
|
|
944
1049
|
var require_warnings = __commonJS({
|
|
945
|
-
"src/warnings.js"(
|
|
946
|
-
var generateHelpUrl =
|
|
1050
|
+
"src/warnings.js"(exports2) {
|
|
1051
|
+
var generateHelpUrl = require("@sanity/generate-help-url").generateHelpUrl;
|
|
947
1052
|
var once = require_once();
|
|
948
1053
|
var createWarningPrinter = (message) => once((...args) => console.warn(message.join(" "), ...args));
|
|
949
|
-
|
|
1054
|
+
exports2.printCdnWarning = createWarningPrinter([
|
|
950
1055
|
"You are not using the Sanity CDN. That means your data is always fresh, but the CDN is faster and",
|
|
951
1056
|
`cheaper. Think about it! For more info, see ${generateHelpUrl("js-client-cdn-configuration")}.`,
|
|
952
1057
|
"To hide this warning, please set the `useCdn` option to either `true` or `false` when creating",
|
|
953
1058
|
"the client."
|
|
954
1059
|
]);
|
|
955
|
-
|
|
1060
|
+
exports2.printBrowserTokenWarning = createWarningPrinter([
|
|
956
1061
|
"You have configured Sanity client to use a token in the browser. This may cause unintentional security issues.",
|
|
957
1062
|
`See ${generateHelpUrl("js-client-browser-token")} for more information and how to hide this warning.`
|
|
958
1063
|
]);
|
|
959
|
-
|
|
1064
|
+
exports2.printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
960
1065
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
961
1066
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
962
1067
|
]);
|
|
@@ -965,13 +1070,13 @@ var require_warnings = __commonJS({
|
|
|
965
1070
|
|
|
966
1071
|
// src/config.js
|
|
967
1072
|
var require_config = __commonJS({
|
|
968
|
-
"src/config.js"(
|
|
969
|
-
var generateHelpUrl =
|
|
970
|
-
var
|
|
971
|
-
var
|
|
1073
|
+
"src/config.js"(exports2) {
|
|
1074
|
+
var generateHelpUrl = require("@sanity/generate-help-url").generateHelpUrl;
|
|
1075
|
+
var assign2 = require("object-assign");
|
|
1076
|
+
var validate2 = require_validators();
|
|
972
1077
|
var warnings = require_warnings();
|
|
973
1078
|
var defaultCdnHost = "apicdn.sanity.io";
|
|
974
|
-
var
|
|
1079
|
+
var defaultConfig2 = {
|
|
975
1080
|
apiHost: "https://api.sanity.io",
|
|
976
1081
|
apiVersion: "1",
|
|
977
1082
|
useProjectHostname: true,
|
|
@@ -979,13 +1084,13 @@ var require_config = __commonJS({
|
|
|
979
1084
|
};
|
|
980
1085
|
var LOCALHOSTS = ["localhost", "127.0.0.1", "0.0.0.0"];
|
|
981
1086
|
var isLocal = (host) => LOCALHOSTS.indexOf(host) !== -1;
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
const specifiedConfig =
|
|
1087
|
+
exports2.defaultConfig = defaultConfig2;
|
|
1088
|
+
exports2.initConfig = (config, prevConfig) => {
|
|
1089
|
+
const specifiedConfig = assign2({}, prevConfig, config);
|
|
985
1090
|
if (!specifiedConfig.apiVersion) {
|
|
986
1091
|
warnings.printNoApiVersionSpecifiedWarning();
|
|
987
1092
|
}
|
|
988
|
-
const newConfig =
|
|
1093
|
+
const newConfig = assign2({}, defaultConfig2, specifiedConfig);
|
|
989
1094
|
const projectBased = newConfig.useProjectHostname;
|
|
990
1095
|
if (typeof Promise === "undefined") {
|
|
991
1096
|
const helpUrl = generateHelpUrl("js-client-promise-polyfill");
|
|
@@ -1002,18 +1107,18 @@ var require_config = __commonJS({
|
|
|
1002
1107
|
warnings.printCdnWarning();
|
|
1003
1108
|
}
|
|
1004
1109
|
if (projectBased) {
|
|
1005
|
-
|
|
1110
|
+
validate2.projectId(newConfig.projectId);
|
|
1006
1111
|
}
|
|
1007
1112
|
if (newConfig.dataset) {
|
|
1008
|
-
|
|
1113
|
+
validate2.dataset(newConfig.dataset);
|
|
1009
1114
|
}
|
|
1010
1115
|
if ("requestTagPrefix" in newConfig) {
|
|
1011
|
-
newConfig.requestTagPrefix = newConfig.requestTagPrefix ?
|
|
1116
|
+
newConfig.requestTagPrefix = newConfig.requestTagPrefix ? validate2.requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0;
|
|
1012
1117
|
}
|
|
1013
1118
|
newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, "");
|
|
1014
|
-
newConfig.isDefaultApi = newConfig.apiHost ===
|
|
1119
|
+
newConfig.isDefaultApi = newConfig.apiHost === defaultConfig2.apiHost;
|
|
1015
1120
|
newConfig.useCdn = Boolean(newConfig.useCdn) && !newConfig.withCredentials;
|
|
1016
|
-
|
|
1121
|
+
exports2.validateApiVersion(newConfig.apiVersion);
|
|
1017
1122
|
const hostParts = newConfig.apiHost.split("://", 2);
|
|
1018
1123
|
const protocol = hostParts[0];
|
|
1019
1124
|
const host = hostParts[1];
|
|
@@ -1027,7 +1132,7 @@ var require_config = __commonJS({
|
|
|
1027
1132
|
}
|
|
1028
1133
|
return newConfig;
|
|
1029
1134
|
};
|
|
1030
|
-
|
|
1135
|
+
exports2.validateApiVersion = function validateApiVersion(apiVersion) {
|
|
1031
1136
|
if (apiVersion === "1" || apiVersion === "X") {
|
|
1032
1137
|
return;
|
|
1033
1138
|
}
|
|
@@ -1041,89 +1146,84 @@ var require_config = __commonJS({
|
|
|
1041
1146
|
});
|
|
1042
1147
|
|
|
1043
1148
|
// 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
|
-
|
|
1149
|
+
var assign = require("object-assign");
|
|
1150
|
+
var { Observable, map, filter } = require_observable();
|
|
1151
|
+
var Patch = require_patch();
|
|
1152
|
+
var Transaction = require_transaction();
|
|
1153
|
+
var dataMethods = require_dataMethods();
|
|
1154
|
+
var DatasetsClient = require_datasetsClient();
|
|
1155
|
+
var ProjectsClient = require_projectsClient();
|
|
1156
|
+
var AssetsClient = require_assetsClient();
|
|
1157
|
+
var UsersClient = require_usersClient();
|
|
1158
|
+
var AuthClient = require_authClient();
|
|
1159
|
+
var httpRequest = require_request();
|
|
1160
|
+
var getRequestOptions = require_requestOptions();
|
|
1161
|
+
var { defaultConfig, initConfig } = require_config();
|
|
1162
|
+
var validate = require_validators();
|
|
1163
|
+
var toPromise = (observable) => observable.toPromise();
|
|
1164
|
+
function SanityClient(config = defaultConfig) {
|
|
1165
|
+
if (!(this instanceof SanityClient)) {
|
|
1166
|
+
return new SanityClient(config);
|
|
1167
|
+
}
|
|
1168
|
+
this.config(config);
|
|
1169
|
+
this.assets = new AssetsClient(this);
|
|
1170
|
+
this.datasets = new DatasetsClient(this);
|
|
1171
|
+
this.projects = new ProjectsClient(this);
|
|
1172
|
+
this.users = new UsersClient(this);
|
|
1173
|
+
this.auth = new AuthClient(this);
|
|
1174
|
+
if (this.clientConfig.isPromiseAPI) {
|
|
1175
|
+
const observableConfig = assign({}, this.clientConfig, { isPromiseAPI: false });
|
|
1176
|
+
this.observable = new SanityClient(observableConfig);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
assign(SanityClient.prototype, dataMethods);
|
|
1180
|
+
assign(SanityClient.prototype, {
|
|
1181
|
+
clone() {
|
|
1182
|
+
return new SanityClient(this.config());
|
|
1183
|
+
},
|
|
1184
|
+
config(newConfig) {
|
|
1185
|
+
if (typeof newConfig === "undefined") {
|
|
1186
|
+
return assign({}, this.clientConfig);
|
|
1075
1187
|
}
|
|
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;
|
|
1188
|
+
if (this.observable) {
|
|
1189
|
+
const observableConfig = assign({}, newConfig, { isPromiseAPI: false });
|
|
1190
|
+
this.observable.config(observableConfig);
|
|
1191
|
+
}
|
|
1192
|
+
this.clientConfig = initConfig(newConfig, this.clientConfig || {});
|
|
1193
|
+
return this;
|
|
1194
|
+
},
|
|
1195
|
+
withConfig(newConfig) {
|
|
1196
|
+
return this.clone().config(newConfig);
|
|
1197
|
+
},
|
|
1198
|
+
getUrl(uri, useCdn = false) {
|
|
1199
|
+
const base = useCdn ? this.clientConfig.cdnUrl : this.clientConfig.url;
|
|
1200
|
+
return `${base}/${uri.replace(/^\//, "")}`;
|
|
1201
|
+
},
|
|
1202
|
+
isPromiseAPI() {
|
|
1203
|
+
return this.clientConfig.isPromiseAPI;
|
|
1204
|
+
},
|
|
1205
|
+
_requestObservable(options) {
|
|
1206
|
+
const uri = options.url || options.uri;
|
|
1207
|
+
const canUseCdn = typeof options.canUseCdn === "undefined" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
|
|
1208
|
+
const useCdn = this.clientConfig.useCdn && canUseCdn;
|
|
1209
|
+
const tag = options.tag && this.clientConfig.requestTagPrefix ? [this.clientConfig.requestTagPrefix, options.tag].join(".") : options.tag || this.clientConfig.requestTagPrefix;
|
|
1210
|
+
if (tag) {
|
|
1211
|
+
options.query = { tag: validate.requestTag(tag), ...options.query };
|
|
1212
|
+
}
|
|
1213
|
+
const reqOptions = getRequestOptions(this.clientConfig, assign({}, options, {
|
|
1214
|
+
url: this.getUrl(uri, useCdn)
|
|
1215
|
+
}));
|
|
1216
|
+
return new Observable((subscriber) => httpRequest(reqOptions, this.clientConfig.requester).subscribe(subscriber));
|
|
1217
|
+
},
|
|
1218
|
+
request(options) {
|
|
1219
|
+
const observable = this._requestObservable(options).pipe(filter((event) => event.type === "response"), map((event) => event.body));
|
|
1220
|
+
return this.isPromiseAPI() ? toPromise(observable) : observable;
|
|
1126
1221
|
}
|
|
1127
1222
|
});
|
|
1128
|
-
|
|
1129
|
-
|
|
1223
|
+
SanityClient.Patch = Patch;
|
|
1224
|
+
SanityClient.Transaction = Transaction;
|
|
1225
|
+
SanityClient.ClientError = httpRequest.ClientError;
|
|
1226
|
+
SanityClient.ServerError = httpRequest.ServerError;
|
|
1227
|
+
SanityClient.requester = httpRequest.defaultRequester;
|
|
1228
|
+
module.exports = SanityClient;
|
|
1229
|
+
//# sourceMappingURL=sanityClient.node.cjs.map
|