@sanity/client 8.0.0 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -0
- package/dist/{browserUpload-CQgx9YYo.js → browserUpload-2tz6Sdqp.js} +4 -3
- package/dist/browserUpload-2tz6Sdqp.js.map +1 -0
- package/dist/{browserUpload-icWlVP15.js → browserUpload-CwpNx7Vl.js} +4 -3
- package/dist/browserUpload-CwpNx7Vl.js.map +1 -0
- package/dist/{config-a8VajuEY.js → config-3wiPP-sZ.js} +2 -2
- package/dist/config-3wiPP-sZ.js.map +1 -0
- package/dist/csm.js +2 -2
- package/dist/csm.js.map +1 -1
- package/dist/index.d.ts +17 -11
- package/dist/index.js +247 -120
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +270 -26
- package/dist/index.node.js +183 -50
- package/dist/index.node.js.map +1 -1
- package/dist/media-library.d.ts +1 -1
- package/dist/{request-CJxcN16k.js → request-BhMuKj0D.js} +10 -9
- package/dist/request-BhMuKj0D.js.map +1 -0
- package/dist/{request-k7VS_NnC.js → request-SnMg7nUX.js} +10 -9
- package/dist/request-SnMg7nUX.js.map +1 -0
- package/dist/{resolveEditInfo-sq7yF78q.js → resolveEditInfo-Cz-smq3a.js} +17 -3
- package/dist/resolveEditInfo-Cz-smq3a.js.map +1 -0
- package/dist/stega.js +1 -1
- package/dist/{stegaEncodeSourceMap-DkoIlutY.js → stegaEncodeSourceMap-DbM2fTN4.js} +8 -2
- package/dist/stegaEncodeSourceMap-DbM2fTN4.js.map +1 -0
- package/dist/{stegaEncodeSourceMap-B2fGArSf.js → stegaEncodeSourceMap-YR3NQ3iz.js} +2 -2
- package/dist/{stegaEncodeSourceMap-B2fGArSf.js.map → stegaEncodeSourceMap-YR3NQ3iz.js.map} +1 -1
- package/dist/{types-CUxZSgB2.d.ts → types-BODIEY7F.d.ts} +262 -24
- package/package.json +26 -11
- package/src/SanityClient.ts +19 -20
- package/src/assets/AssetsClient.ts +54 -5
- package/src/csm/applySourceDocuments.ts +2 -4
- package/src/csm/draftUtils.ts +23 -4
- package/src/data/dataMethods.ts +2 -19
- package/src/data/eventsource.ts +71 -41
- package/src/data/live.ts +17 -9
- package/src/data/resolveEventSourceFetch.ts +9 -1
- package/src/defineCreateClient.ts +5 -1
- package/src/functions/FunctionsClient.ts +66 -0
- package/src/functions/invoke.ts +176 -0
- package/src/http/browserUpload.ts +1 -0
- package/src/http/errors.ts +2 -1
- package/src/http/request.ts +8 -14
- package/src/mediaLibrary/MediaLibraryVideoClient.ts +1 -1
- package/src/types.ts +186 -4
- package/src/validators.ts +1 -1
- package/src/warnings.ts +7 -1
- package/dist/browserUpload-CQgx9YYo.js.map +0 -1
- package/dist/browserUpload-icWlVP15.js.map +0 -1
- package/dist/config-a8VajuEY.js.map +0 -1
- package/dist/request-CJxcN16k.js.map +0 -1
- package/dist/request-k7VS_NnC.js.map +0 -1
- package/dist/resolveEditInfo-sq7yF78q.js.map +0 -1
- package/dist/stegaEncodeSourceMap-DkoIlutY.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { a as ServerError, c as isHttpError, i as CorsOriginError, l as isQueryParseError, o as formatQueryParseError, r as ClientError, t as defineRequester, u as _defineProperty } from "./request-
|
|
2
|
-
import {
|
|
1
|
+
import { a as ServerError, c as isHttpError, i as CorsOriginError, l as isQueryParseError, o as formatQueryParseError, r as ClientError, t as defineRequester, u as _defineProperty } from "./request-BhMuKj0D.js";
|
|
2
|
+
import { t as isRecord } from "./isRecord-Kfmt-nk-.js";
|
|
3
|
+
import { _ as validateDocumentId, a as printCreateVersionWithBaseIdWarning, b as validateVersionIdMatch, c as printPreviewDraftsDeprecationWarning, d as requestTag, f as requireDocumentId, g as validateAssetType, h as resourceGuard, i as printCdnPreviewDraftsWarning, l as dataset, m as resourceConfig, n as initConfig, o as printDeprecatedUriOptionWarning, p as requireDocumentType, r as validateApiPerspective, s as printNoDefaultExport, t as defaultConfig, u as hasDataset, v as validateInsert, y as validateObject } from "./config-3wiPP-sZ.js";
|
|
3
4
|
import { t as stegaClean } from "./stegaClean-C18wLWau.js";
|
|
5
|
+
import { isTimeoutError } from "get-it";
|
|
4
6
|
import { Observable, catchError, concat, defer, finalize, isObservable, lastValueFrom, map, merge, mergeMap, of, share, tap, throwError, timer } from "rxjs";
|
|
5
7
|
import { getDraftId, getPublishedId, getVersionFromId, getVersionId, isDraftId, isVersionId } from "@sanity/client/csm";
|
|
6
8
|
import { filter, finalize as finalize$1, map as map$1, mergeAll } from "rxjs/operators";
|
|
@@ -26,11 +28,12 @@ import { customAlphabet } from "nanoid";
|
|
|
26
28
|
*/
|
|
27
29
|
const EXPERIMENTAL_API_WARNING = "This is an experimental API version";
|
|
28
30
|
/**
|
|
29
|
-
* @public
|
|
30
31
|
* Thrown when the EventSource connection could not be established, or was rejected by the server.
|
|
31
32
|
* Transient failures (network drops, 5xx, 408, 429) are reconnected internally and emitted as
|
|
32
33
|
* `reconnect` events; a permanent rejection (any other 4xx, eg an expired token) errors the
|
|
33
34
|
* stream with this class so consumers can react — check `status` for the rejection code.
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
34
37
|
*/
|
|
35
38
|
var ConnectionFailedError = class extends Error {
|
|
36
39
|
constructor(message, options = {}) {
|
|
@@ -89,26 +92,30 @@ function connectEventSource(initEventSource, events) {
|
|
|
89
92
|
*/
|
|
90
93
|
function connectWithESInstance(es, events) {
|
|
91
94
|
return new Observable((observer) => {
|
|
92
|
-
let
|
|
95
|
+
let requestedEvents = new Set(events), isRequestedEvent = (type) => requestedEvents.has(type), emitOpen = isRequestedEvent("open");
|
|
93
96
|
function onError(evt) {
|
|
94
97
|
if ("data" in evt) {
|
|
95
98
|
let [parseError, event] = parseEvent(evt);
|
|
96
|
-
observer.error(parseError ? new MessageParseError("Unable to parse EventSource error message", { cause: parseError }) : new MessageError(event.data.message, event));
|
|
99
|
+
observer.error(parseError || !event ? new MessageParseError("Unable to parse EventSource error message", { cause: parseError }) : new MessageError(isRecord(event.data) && typeof event.data.message == "string" ? event.data.message : "", event));
|
|
97
100
|
return;
|
|
98
101
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
observer.error(new ConnectionFailedError("EventSource connection failed", { status }));
|
|
102
|
+
if (evt.code !== void 0) {
|
|
103
|
+
observer.error(new ConnectionFailedError("EventSource connection failed", { status: evt.code }));
|
|
102
104
|
return;
|
|
103
105
|
}
|
|
104
|
-
es.readyState === es.CLOSED
|
|
106
|
+
if (es.readyState === es.CLOSED) observer.error(new ConnectionFailedError("EventSource connection failed"));
|
|
107
|
+
else {
|
|
108
|
+
let type = "reconnect";
|
|
109
|
+
isRequestedEvent(type) && observer.next({ type });
|
|
110
|
+
}
|
|
105
111
|
}
|
|
106
112
|
function onOpen() {
|
|
107
|
-
|
|
113
|
+
let type = "open";
|
|
114
|
+
isRequestedEvent(type) && observer.next({ type });
|
|
108
115
|
}
|
|
109
116
|
function onMessage(message) {
|
|
110
117
|
let [parseError, event] = parseEvent(message);
|
|
111
|
-
if (parseError) {
|
|
118
|
+
if (parseError || !event) {
|
|
112
119
|
observer.error(new MessageParseError("Unable to parse EventSource message", { cause: parseError }));
|
|
113
120
|
return;
|
|
114
121
|
}
|
|
@@ -118,10 +125,10 @@ function connectWithESInstance(es, events) {
|
|
|
118
125
|
return;
|
|
119
126
|
}
|
|
120
127
|
if (message.type === "disconnect") {
|
|
121
|
-
observer.error(new DisconnectError(`Server disconnected client: ${event.data
|
|
128
|
+
observer.error(new DisconnectError(`Server disconnected client: ${isRecord(event.data) && typeof event.data.reason == "string" && event.data.reason || "unknown error"}`));
|
|
122
129
|
return;
|
|
123
130
|
}
|
|
124
|
-
observer.next({
|
|
131
|
+
isRequestedEvent(message.type) && observer.next({
|
|
125
132
|
type: message.type,
|
|
126
133
|
id: message.lastEventId,
|
|
127
134
|
...event.data ? { data: event.data } : {}
|
|
@@ -147,8 +154,16 @@ function parseEvent(message) {
|
|
|
147
154
|
}
|
|
148
155
|
}
|
|
149
156
|
function extractErrorMessage(err, tag) {
|
|
150
|
-
let error = err.error;
|
|
151
|
-
|
|
157
|
+
let error = isRecord(err) ? err.error : void 0;
|
|
158
|
+
if (!error) {
|
|
159
|
+
let message = isRecord(err) ? err.message : void 0;
|
|
160
|
+
return typeof message == "string" && message || "Unknown listener error";
|
|
161
|
+
}
|
|
162
|
+
if (isRecord(error)) {
|
|
163
|
+
if (isQueryParseError(error)) return formatQueryParseError(error, tag);
|
|
164
|
+
if (typeof error.description == "string") return error.description;
|
|
165
|
+
}
|
|
166
|
+
return typeof error == "string" ? error : JSON.stringify(error, null, 2);
|
|
152
167
|
}
|
|
153
168
|
function isEmptyObject(data) {
|
|
154
169
|
for (let _ in data) return !1;
|
|
@@ -323,41 +338,41 @@ var BasePatch = class {
|
|
|
323
338
|
_set(op, props) {
|
|
324
339
|
return this._assign(op, props, !1);
|
|
325
340
|
}
|
|
326
|
-
}, _client$
|
|
341
|
+
}, _client$10 = /* @__PURE__ */ new WeakMap(), ObservablePatch = class ObservablePatch extends BasePatch {
|
|
327
342
|
constructor(selection, operations, client) {
|
|
328
|
-
super(selection, operations), _classPrivateFieldInitSpec(this, _client$
|
|
343
|
+
super(selection, operations), _classPrivateFieldInitSpec(this, _client$10, void 0), _classPrivateFieldSet2(_client$10, this, client);
|
|
329
344
|
}
|
|
330
345
|
/**
|
|
331
346
|
* Clones the patch
|
|
332
347
|
*/
|
|
333
348
|
clone() {
|
|
334
|
-
return new ObservablePatch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client$
|
|
349
|
+
return new ObservablePatch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client$10, this));
|
|
335
350
|
}
|
|
336
351
|
commit(options) {
|
|
337
|
-
if (!_classPrivateFieldGet2(_client$
|
|
352
|
+
if (!_classPrivateFieldGet2(_client$10, this)) throw Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
338
353
|
let returnFirst = typeof this.selection == "string", opts = Object.assign({
|
|
339
354
|
returnFirst,
|
|
340
355
|
returnDocuments: !0
|
|
341
356
|
}, options);
|
|
342
|
-
return _classPrivateFieldGet2(_client$
|
|
357
|
+
return _classPrivateFieldGet2(_client$10, this).mutate({ patch: this.serialize() }, opts);
|
|
343
358
|
}
|
|
344
|
-
}, _client2$
|
|
359
|
+
}, _client2$9 = /* @__PURE__ */ new WeakMap(), Patch = class Patch extends BasePatch {
|
|
345
360
|
constructor(selection, operations, client) {
|
|
346
|
-
super(selection, operations), _classPrivateFieldInitSpec(this, _client2$
|
|
361
|
+
super(selection, operations), _classPrivateFieldInitSpec(this, _client2$9, void 0), _classPrivateFieldSet2(_client2$9, this, client);
|
|
347
362
|
}
|
|
348
363
|
/**
|
|
349
364
|
* Clones the patch
|
|
350
365
|
*/
|
|
351
366
|
clone() {
|
|
352
|
-
return new Patch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client2$
|
|
367
|
+
return new Patch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client2$9, this));
|
|
353
368
|
}
|
|
354
369
|
commit(options) {
|
|
355
|
-
if (!_classPrivateFieldGet2(_client2$
|
|
370
|
+
if (!_classPrivateFieldGet2(_client2$9, this)) throw Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
356
371
|
let returnFirst = typeof this.selection == "string", opts = Object.assign({
|
|
357
372
|
returnFirst,
|
|
358
373
|
returnDocuments: !0
|
|
359
374
|
}, options);
|
|
360
|
-
return _classPrivateFieldGet2(_client2$
|
|
375
|
+
return _classPrivateFieldGet2(_client2$9, this).mutate({ patch: this.serialize() }, opts);
|
|
361
376
|
}
|
|
362
377
|
};
|
|
363
378
|
const defaultMutateOptions = { returnDocuments: !1 };
|
|
@@ -428,30 +443,30 @@ var BaseTransaction = class {
|
|
|
428
443
|
_add(mut) {
|
|
429
444
|
return this.operations.push(mut), this;
|
|
430
445
|
}
|
|
431
|
-
}, _client$
|
|
446
|
+
}, _client$9 = /* @__PURE__ */ new WeakMap(), Transaction = class Transaction extends BaseTransaction {
|
|
432
447
|
constructor(operations, client, transactionId) {
|
|
433
|
-
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client$
|
|
448
|
+
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client$9, void 0), _classPrivateFieldSet2(_client$9, this, client);
|
|
434
449
|
}
|
|
435
450
|
/**
|
|
436
451
|
* Clones the transaction
|
|
437
452
|
*/
|
|
438
453
|
clone() {
|
|
439
|
-
return new Transaction([...this.operations], _classPrivateFieldGet2(_client$
|
|
454
|
+
return new Transaction([...this.operations], _classPrivateFieldGet2(_client$9, this), this.trxId);
|
|
440
455
|
}
|
|
441
456
|
commit(options) {
|
|
442
|
-
if (!_classPrivateFieldGet2(_client$
|
|
443
|
-
return _classPrivateFieldGet2(_client$
|
|
457
|
+
if (!_classPrivateFieldGet2(_client$9, this)) throw Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
458
|
+
return _classPrivateFieldGet2(_client$9, this).mutate(this.serialize(), Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {}));
|
|
444
459
|
}
|
|
445
460
|
patch(patchOrDocumentId, patchOps) {
|
|
446
461
|
let isBuilder = typeof patchOps == "function", isPatch = typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch, isMutationSelection = typeof patchOrDocumentId == "object" && ("query" in patchOrDocumentId || "id" in patchOrDocumentId);
|
|
447
462
|
if (isPatch) return this._add({ patch: patchOrDocumentId.serialize() });
|
|
448
463
|
if (isBuilder) {
|
|
449
|
-
let patch = patchOps(new Patch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client$
|
|
464
|
+
let patch = patchOps(new Patch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client$9, this)));
|
|
450
465
|
if (!(patch instanceof Patch)) throw Error("function passed to `patch()` must return the patch");
|
|
451
466
|
return this._add({ patch: patch.serialize() });
|
|
452
467
|
}
|
|
453
468
|
if (isMutationSelection) {
|
|
454
|
-
let patch = new Patch(patchOrDocumentId, patchOps || {}, _classPrivateFieldGet2(_client$
|
|
469
|
+
let patch = new Patch(patchOrDocumentId, patchOps || {}, _classPrivateFieldGet2(_client$9, this));
|
|
455
470
|
return this._add({ patch: patch.serialize() });
|
|
456
471
|
}
|
|
457
472
|
return this._add({ patch: {
|
|
@@ -459,25 +474,25 @@ var BaseTransaction = class {
|
|
|
459
474
|
...patchOps
|
|
460
475
|
} });
|
|
461
476
|
}
|
|
462
|
-
}, _client2$
|
|
477
|
+
}, _client2$8 = /* @__PURE__ */ new WeakMap(), ObservableTransaction = class ObservableTransaction extends BaseTransaction {
|
|
463
478
|
constructor(operations, client, transactionId) {
|
|
464
|
-
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client2$
|
|
479
|
+
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client2$8, void 0), _classPrivateFieldSet2(_client2$8, this, client);
|
|
465
480
|
}
|
|
466
481
|
/**
|
|
467
482
|
* Clones the transaction
|
|
468
483
|
*/
|
|
469
484
|
clone() {
|
|
470
|
-
return new ObservableTransaction([...this.operations], _classPrivateFieldGet2(_client2$
|
|
485
|
+
return new ObservableTransaction([...this.operations], _classPrivateFieldGet2(_client2$8, this), this.trxId);
|
|
471
486
|
}
|
|
472
487
|
commit(options) {
|
|
473
|
-
if (!_classPrivateFieldGet2(_client2$
|
|
474
|
-
return _classPrivateFieldGet2(_client2$
|
|
488
|
+
if (!_classPrivateFieldGet2(_client2$8, this)) throw Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
489
|
+
return _classPrivateFieldGet2(_client2$8, this).mutate(this.serialize(), Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {}));
|
|
475
490
|
}
|
|
476
491
|
patch(patchOrDocumentId, patchOps) {
|
|
477
492
|
let isBuilder = typeof patchOps == "function";
|
|
478
493
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof ObservablePatch) return this._add({ patch: patchOrDocumentId.serialize() });
|
|
479
494
|
if (isBuilder) {
|
|
480
|
-
let patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client2$
|
|
495
|
+
let patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client2$8, this)));
|
|
481
496
|
if (!(patch instanceof ObservablePatch)) throw Error("function passed to `patch()` must return the patch");
|
|
482
497
|
return this._add({ patch: patch.serialize() });
|
|
483
498
|
}
|
|
@@ -604,7 +619,7 @@ function _fetch(client, httpRequest, _stega, query, _params = {}, options = {})
|
|
|
604
619
|
query,
|
|
605
620
|
params
|
|
606
621
|
}, reqOpts);
|
|
607
|
-
return stega.enabled ? Promise.all([request, import("./stegaEncodeSourceMap-
|
|
622
|
+
return stega.enabled ? Promise.all([request, import("./stegaEncodeSourceMap-YR3NQ3iz.js").then((n) => n.n)]).then(([res, { stegaEncodeSourceMap }]) => {
|
|
608
623
|
let result = stegaEncodeSourceMap(res.result, res.resultSourceMap, stega);
|
|
609
624
|
return mapResponse({
|
|
610
625
|
...res,
|
|
@@ -847,8 +862,6 @@ function _mapDataResponse(res, isMutation, returnFirst, returnDocuments) {
|
|
|
847
862
|
};
|
|
848
863
|
}
|
|
849
864
|
/**
|
|
850
|
-
* Promise-based sibling of {@link _dataRequestObservable}.
|
|
851
|
-
*
|
|
852
865
|
* @internal
|
|
853
866
|
*/
|
|
854
867
|
function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
|
|
@@ -1073,7 +1086,7 @@ function _observe(userSignal, run) {
|
|
|
1073
1086
|
* @internal
|
|
1074
1087
|
*/
|
|
1075
1088
|
function _request(client, httpRequest, options) {
|
|
1076
|
-
return httpRequest(_prepareRequest(client, options)).then((body) => body);
|
|
1089
|
+
return httpRequest(_prepareRequest(client, options), client.config().requestHandler).then((body) => body);
|
|
1077
1090
|
}
|
|
1078
1091
|
/**
|
|
1079
1092
|
* Execute an HTTP request through the regular pipeline and resolve to the
|
|
@@ -1227,62 +1240,62 @@ function _translate(client, httpRequest, request) {
|
|
|
1227
1240
|
body: request
|
|
1228
1241
|
});
|
|
1229
1242
|
}
|
|
1230
|
-
var _client$
|
|
1243
|
+
var _client$8 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */ new WeakMap(), ObservableAgentsActionClient = class {
|
|
1231
1244
|
constructor(client, httpRequest) {
|
|
1232
|
-
_classPrivateFieldInitSpec(this, _client$
|
|
1245
|
+
_classPrivateFieldInitSpec(this, _client$8, void 0), _classPrivateFieldInitSpec(this, _httpRequest$7, void 0), _classPrivateFieldSet2(_client$8, this, client), _classPrivateFieldSet2(_httpRequest$7, this, httpRequest);
|
|
1233
1246
|
}
|
|
1234
1247
|
/**
|
|
1235
1248
|
* Run an instruction to generate content in a target document.
|
|
1236
1249
|
* @param request - instruction request
|
|
1237
1250
|
*/
|
|
1238
1251
|
generate(request) {
|
|
1239
|
-
return _generateObservable(_classPrivateFieldGet2(_client$
|
|
1252
|
+
return _generateObservable(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest$7, this), request);
|
|
1240
1253
|
}
|
|
1241
1254
|
/**
|
|
1242
1255
|
* Transform a target document based on a source.
|
|
1243
1256
|
* @param request - translation request
|
|
1244
1257
|
*/
|
|
1245
1258
|
transform(request) {
|
|
1246
|
-
return _transformObservable(_classPrivateFieldGet2(_client$
|
|
1259
|
+
return _transformObservable(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest$7, this), request);
|
|
1247
1260
|
}
|
|
1248
1261
|
/**
|
|
1249
1262
|
* Translate a target document based on a source.
|
|
1250
1263
|
* @param request - translation request
|
|
1251
1264
|
*/
|
|
1252
1265
|
translate(request) {
|
|
1253
|
-
return _translateObservable(_classPrivateFieldGet2(_client$
|
|
1266
|
+
return _translateObservable(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest$7, this), request);
|
|
1254
1267
|
}
|
|
1255
|
-
}, _client2$
|
|
1268
|
+
}, _client2$7 = /* @__PURE__ */ new WeakMap(), _httpRequest2$8 = /* @__PURE__ */ new WeakMap(), AgentActionsClient = class {
|
|
1256
1269
|
constructor(client, httpRequest) {
|
|
1257
|
-
_classPrivateFieldInitSpec(this, _client2$
|
|
1270
|
+
_classPrivateFieldInitSpec(this, _client2$7, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$8, void 0), _classPrivateFieldSet2(_client2$7, this, client), _classPrivateFieldSet2(_httpRequest2$8, this, httpRequest);
|
|
1258
1271
|
}
|
|
1259
1272
|
/**
|
|
1260
1273
|
* Run an instruction to generate content in a target document.
|
|
1261
1274
|
* @param request - instruction request
|
|
1262
1275
|
*/
|
|
1263
1276
|
generate(request) {
|
|
1264
|
-
return _generate(_classPrivateFieldGet2(_client2$
|
|
1277
|
+
return _generate(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), request);
|
|
1265
1278
|
}
|
|
1266
1279
|
/**
|
|
1267
1280
|
* Transform a target document based on a source.
|
|
1268
1281
|
* @param request - translation request
|
|
1269
1282
|
*/
|
|
1270
1283
|
transform(request) {
|
|
1271
|
-
return _transform(_classPrivateFieldGet2(_client2$
|
|
1284
|
+
return _transform(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), request);
|
|
1272
1285
|
}
|
|
1273
1286
|
/**
|
|
1274
1287
|
* Translate a target document based on a source.
|
|
1275
1288
|
* @param request - translation request
|
|
1276
1289
|
*/
|
|
1277
1290
|
translate(request) {
|
|
1278
|
-
return _translate(_classPrivateFieldGet2(_client2$
|
|
1291
|
+
return _translate(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), request);
|
|
1279
1292
|
}
|
|
1280
1293
|
/**
|
|
1281
1294
|
* Run a raw instruction and return the result either as text or json
|
|
1282
1295
|
* @param request - prompt request
|
|
1283
1296
|
*/
|
|
1284
1297
|
prompt(request) {
|
|
1285
|
-
return _prompt(_classPrivateFieldGet2(_client2$
|
|
1298
|
+
return _prompt(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), request);
|
|
1286
1299
|
}
|
|
1287
1300
|
/**
|
|
1288
1301
|
* Patch a document using a schema aware API.
|
|
@@ -1290,24 +1303,37 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$6 = /* @__PURE__ */
|
|
|
1290
1303
|
* @param request - instruction request
|
|
1291
1304
|
*/
|
|
1292
1305
|
patch(request) {
|
|
1293
|
-
return _patch(_classPrivateFieldGet2(_client2$
|
|
1306
|
+
return _patch(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), request);
|
|
1294
1307
|
}
|
|
1295
|
-
}, _client$
|
|
1308
|
+
}, _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest2$7 = /* @__PURE__ */ new WeakMap(), ObservableAssetsClient = class {
|
|
1296
1309
|
constructor(client, httpRequest) {
|
|
1297
|
-
_classPrivateFieldInitSpec(this, _client$
|
|
1310
|
+
_classPrivateFieldInitSpec(this, _client$7, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$7, void 0), _classPrivateFieldSet2(_client$7, this, client), _classPrivateFieldSet2(_httpRequest2$7, this, httpRequest);
|
|
1298
1311
|
}
|
|
1299
1312
|
upload(assetType, body, options) {
|
|
1300
|
-
return _upload(_classPrivateFieldGet2(_client$
|
|
1313
|
+
return _upload(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest2$7, this), assetType, body, options);
|
|
1301
1314
|
}
|
|
1302
|
-
}, _client2$
|
|
1315
|
+
}, _client2$6 = /* @__PURE__ */ new WeakMap(), _httpRequest3 = /* @__PURE__ */ new WeakMap(), AssetsClient = class {
|
|
1303
1316
|
constructor(client, httpRequest) {
|
|
1304
|
-
_classPrivateFieldInitSpec(this, _client2$
|
|
1317
|
+
_classPrivateFieldInitSpec(this, _client2$6, void 0), _classPrivateFieldInitSpec(this, _httpRequest3, void 0), _classPrivateFieldSet2(_client2$6, this, client), _classPrivateFieldSet2(_httpRequest3, this, httpRequest);
|
|
1305
1318
|
}
|
|
1306
1319
|
upload(assetType, body, options) {
|
|
1307
|
-
let observable = _upload(_classPrivateFieldGet2(_client2$
|
|
1308
|
-
return lastValueFrom(observable.pipe(filter((event) => event.type === "response"), map$1((event) => event.body
|
|
1320
|
+
let observable = _upload(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest3, this), assetType, body, options);
|
|
1321
|
+
return lastValueFrom(observable.pipe(filter((event) => event.type === "response"), map$1((event) => pluckUploadedAsset(event.body))));
|
|
1309
1322
|
}
|
|
1310
1323
|
};
|
|
1324
|
+
/**
|
|
1325
|
+
* Content Lake's upload endpoint responds with `{document: ...}`; the Media
|
|
1326
|
+
* Library upload endpoint responds with `{asset: ...}` instead (a
|
|
1327
|
+
* `sanity.asset` document, not a Content Lake asset document). Narrowing on
|
|
1328
|
+
* the response body itself - rather than on the client's `resource` config -
|
|
1329
|
+
* keeps this correct regardless of how the two are ever wired together.
|
|
1330
|
+
*/
|
|
1331
|
+
function isMediaLibraryUploadBody(body) {
|
|
1332
|
+
return "asset" in body;
|
|
1333
|
+
}
|
|
1334
|
+
function pluckUploadedAsset(body) {
|
|
1335
|
+
return isMediaLibraryUploadBody(body) ? body.asset : body.document;
|
|
1336
|
+
}
|
|
1311
1337
|
function _upload(client, _httpRequest, assetType, body, opts = {}) {
|
|
1312
1338
|
validateAssetType(assetType);
|
|
1313
1339
|
let meta = opts.extract || void 0;
|
|
@@ -1334,7 +1360,7 @@ function _upload(client, _httpRequest, assetType, body, opts = {}) {
|
|
|
1334
1360
|
body
|
|
1335
1361
|
};
|
|
1336
1362
|
return typeof XMLHttpRequest < "u" ? defer(async () => {
|
|
1337
|
-
let { uploadWithProgress } = await import("./browserUpload-
|
|
1363
|
+
let { uploadWithProgress } = await import("./browserUpload-CwpNx7Vl.js"), req = _prepareRequest(client, { ...baseRequest });
|
|
1338
1364
|
return uploadWithProgress({
|
|
1339
1365
|
url: appendQuery(req.url, req.query),
|
|
1340
1366
|
method: req.method ?? "POST",
|
|
@@ -1421,6 +1447,14 @@ function resolveEventSourceFetch(config, options = {}) {
|
|
|
1421
1447
|
return credentials !== void 0 && (mergedInit.credentials = credentials), baseFetch(typeof url == "string" ? url : url.href, mergedInit);
|
|
1422
1448
|
};
|
|
1423
1449
|
}
|
|
1450
|
+
/**
|
|
1451
|
+
* The fetch the client's own transport resolves for this config: the
|
|
1452
|
+
* configured `resolveFetch` (honouring an explicit `proxy`) if present,
|
|
1453
|
+
* otherwise the global fetch. Shared by the EventSource connection and the
|
|
1454
|
+
* `/check/cors` probe so both resolve identically.
|
|
1455
|
+
*
|
|
1456
|
+
* @internal
|
|
1457
|
+
*/
|
|
1424
1458
|
function pickBaseFetch(config) {
|
|
1425
1459
|
return config.resolveFetch ? config.resolveFetch(typeof config.proxy == "string" ? config.proxy : void 0) : globalThis.fetch.bind(globalThis);
|
|
1426
1460
|
}
|
|
@@ -1483,18 +1517,18 @@ function _shareReplayLatest(config) {
|
|
|
1483
1517
|
};
|
|
1484
1518
|
}
|
|
1485
1519
|
const requiredApiVersion = "2021-03-25";
|
|
1486
|
-
var _client$
|
|
1520
|
+
var _client$6 = /* @__PURE__ */ new WeakMap(), LiveClient = class {
|
|
1487
1521
|
constructor(client) {
|
|
1488
|
-
_classPrivateFieldInitSpec(this, _client$
|
|
1522
|
+
_classPrivateFieldInitSpec(this, _client$6, void 0), _classPrivateFieldSet2(_client$6, this, client);
|
|
1489
1523
|
}
|
|
1490
1524
|
/**
|
|
1491
1525
|
* Requires `apiVersion` to be `2021-03-25` or later.
|
|
1492
1526
|
*/
|
|
1493
1527
|
events({ includeDrafts = !1, tag: _tag, waitFor } = {}) {
|
|
1494
|
-
let config = _classPrivateFieldGet2(_client$
|
|
1528
|
+
let config = _classPrivateFieldGet2(_client$6, this).config(), { projectId, apiVersion: _apiVersion, token, withCredentials, requestTagPrefix, headers: configHeaders } = config, apiVersion = _apiVersion.replace(/^v/, "");
|
|
1495
1529
|
if (apiVersion !== "X" && apiVersion < requiredApiVersion) throw Error(`The live events API requires API version ${requiredApiVersion} or later. The current API version is ${apiVersion}. Please update your API version to use this feature.`);
|
|
1496
1530
|
if (includeDrafts && !token && !withCredentials) throw Error("The live events API requires a token or withCredentials when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role.");
|
|
1497
|
-
let path = _getDataUrl(_classPrivateFieldGet2(_client$
|
|
1531
|
+
let path = _getDataUrl(_classPrivateFieldGet2(_client$6, this), "live/events"), url = new URL(_classPrivateFieldGet2(_client$6, this).getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
|
|
1498
1532
|
tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true"), waitFor && url.searchParams.set("waitFor", waitFor);
|
|
1499
1533
|
let eventSourceHeaders = {};
|
|
1500
1534
|
includeDrafts && token && (eventSourceHeaders.Authorization = `Bearer ${token}`), configHeaders && Object.assign(eventSourceHeaders, configHeaders);
|
|
@@ -1516,7 +1550,7 @@ var _client$5 = /* @__PURE__ */ new WeakMap(), LiveClient = class {
|
|
|
1516
1550
|
"welcome",
|
|
1517
1551
|
"reconnect",
|
|
1518
1552
|
"goaway"
|
|
1519
|
-
]), checkCors = checkCorsObservable(new URL(_classPrivateFieldGet2(_client$
|
|
1553
|
+
]), checkCors = checkCorsObservable(new URL(_classPrivateFieldGet2(_client$6, this).getUrl("/check/cors", !1)), projectId, eventSourceWithCredentials, pickBaseFetch(config)), observable = events.pipe(reconnectOnConnectionFailure(), mergeMap((event) => event.type === "reconnect" ? checkCors.pipe(mergeMap(() => of(event))) : of(event)), catchError((err) => err instanceof CorsOriginError ? throwError(() => err) : checkCors.pipe(mergeMap(() => {
|
|
1520
1554
|
throw err;
|
|
1521
1555
|
}))), map$1((event) => {
|
|
1522
1556
|
if (event.type === "message") {
|
|
@@ -1569,34 +1603,33 @@ var _client$5 = /* @__PURE__ */ new WeakMap(), LiveClient = class {
|
|
|
1569
1603
|
* In all of those cases the caller's original underlying error from the
|
|
1570
1604
|
* EventSource is allowed to propagate unchanged.
|
|
1571
1605
|
*/
|
|
1572
|
-
function checkCorsObservable(url, projectId, requireCredentials) {
|
|
1606
|
+
function checkCorsObservable(url, projectId, requireCredentials, fetcher) {
|
|
1573
1607
|
return new Observable((observer) => {
|
|
1574
1608
|
let controller = new AbortController(), { signal } = controller;
|
|
1575
|
-
return
|
|
1609
|
+
return fetcher(url.href, {
|
|
1576
1610
|
method: "GET",
|
|
1577
|
-
mode: "cors",
|
|
1578
1611
|
credentials: "omit",
|
|
1579
1612
|
signal
|
|
1580
1613
|
}).then((response) => {
|
|
1581
|
-
if (!(signal.aborted || !response.ok)) return response.
|
|
1582
|
-
}).then((
|
|
1583
|
-
if (
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
observer.next(), observer.complete();
|
|
1614
|
+
if (!(signal.aborted || !response.ok)) return response.text();
|
|
1615
|
+
}).then((text) => {
|
|
1616
|
+
if (signal.aborted) return;
|
|
1617
|
+
let parsed = text === void 0 ? void 0 : JSON.parse(text), result = isRecord(parsed) ? parsed.result : void 0;
|
|
1618
|
+
if (requireCredentials && isRecord(result) && result.withCredentials === !1) {
|
|
1619
|
+
observer.error(new CorsOriginError({
|
|
1620
|
+
projectId,
|
|
1621
|
+
credentials: !0
|
|
1622
|
+
}));
|
|
1623
|
+
return;
|
|
1624
|
+
}
|
|
1625
|
+
if (isRecord(result) && result.allowed === !1) {
|
|
1626
|
+
observer.error(new CorsOriginError({
|
|
1627
|
+
projectId,
|
|
1628
|
+
credentials: requireCredentials
|
|
1629
|
+
}));
|
|
1630
|
+
return;
|
|
1599
1631
|
}
|
|
1632
|
+
observer.next(), observer.complete();
|
|
1600
1633
|
}).catch(() => {
|
|
1601
1634
|
signal.aborted || observer.closed || (observer.next(), observer.complete());
|
|
1602
1635
|
}), () => controller.abort();
|
|
@@ -1608,9 +1641,9 @@ function checkCorsObservable(url, projectId, requireCredentials) {
|
|
|
1608
1641
|
* resolver — `undefined` covers the `globalThis.fetch` fallback.
|
|
1609
1642
|
*/
|
|
1610
1643
|
const eventsCache = /* @__PURE__ */ new Map();
|
|
1611
|
-
var _client$
|
|
1644
|
+
var _client$5 = /* @__PURE__ */ new WeakMap(), _httpRequest$6 = /* @__PURE__ */ new WeakMap(), ObservableDatasetsClient = class {
|
|
1612
1645
|
constructor(client, httpRequest) {
|
|
1613
|
-
_classPrivateFieldInitSpec(this, _client$
|
|
1646
|
+
_classPrivateFieldInitSpec(this, _client$5, void 0), _classPrivateFieldInitSpec(this, _httpRequest$6, void 0), _classPrivateFieldSet2(_client$5, this, client), _classPrivateFieldSet2(_httpRequest$6, this, httpRequest);
|
|
1614
1647
|
}
|
|
1615
1648
|
/**
|
|
1616
1649
|
* Create a new dataset with the given name
|
|
@@ -1619,7 +1652,7 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1619
1652
|
* @param options - Options for the dataset, including optional embeddings configuration
|
|
1620
1653
|
*/
|
|
1621
1654
|
create(name, options) {
|
|
1622
|
-
return _modifyObservable(_classPrivateFieldGet2(_client$
|
|
1655
|
+
return _modifyObservable(_classPrivateFieldGet2(_client$5, this), _classPrivateFieldGet2(_httpRequest$6, this), "PUT", name, options);
|
|
1623
1656
|
}
|
|
1624
1657
|
/**
|
|
1625
1658
|
* Edit a dataset with the given name
|
|
@@ -1628,7 +1661,7 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1628
1661
|
* @param options - New options for the dataset
|
|
1629
1662
|
*/
|
|
1630
1663
|
edit(name, options) {
|
|
1631
|
-
return _modifyObservable(_classPrivateFieldGet2(_client$
|
|
1664
|
+
return _modifyObservable(_classPrivateFieldGet2(_client$5, this), _classPrivateFieldGet2(_httpRequest$6, this), "PATCH", name, options);
|
|
1632
1665
|
}
|
|
1633
1666
|
/**
|
|
1634
1667
|
* Delete a dataset with the given name
|
|
@@ -1636,15 +1669,15 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1636
1669
|
* @param name - Name of the dataset to delete
|
|
1637
1670
|
*/
|
|
1638
1671
|
delete(name) {
|
|
1639
|
-
return _modifyObservable(_classPrivateFieldGet2(_client$
|
|
1672
|
+
return _modifyObservable(_classPrivateFieldGet2(_client$5, this), _classPrivateFieldGet2(_httpRequest$6, this), "DELETE", name);
|
|
1640
1673
|
}
|
|
1641
1674
|
/**
|
|
1642
1675
|
* Fetch a list of datasets for the configured project
|
|
1643
1676
|
*/
|
|
1644
1677
|
list() {
|
|
1645
|
-
resourceGuard("dataset", _classPrivateFieldGet2(_client$
|
|
1646
|
-
let config = _classPrivateFieldGet2(_client$
|
|
1647
|
-
return config.useProjectHostname === !1 && (url = `/projects/${projectId}/datasets`), _requestObservable(_classPrivateFieldGet2(_client$
|
|
1678
|
+
resourceGuard("dataset", _classPrivateFieldGet2(_client$5, this).config());
|
|
1679
|
+
let config = _classPrivateFieldGet2(_client$5, this).config(), projectId = config.projectId, url = "/datasets";
|
|
1680
|
+
return config.useProjectHostname === !1 && (url = `/projects/${projectId}/datasets`), _requestObservable(_classPrivateFieldGet2(_client$5, this), _classPrivateFieldGet2(_httpRequest$6, this), {
|
|
1648
1681
|
url,
|
|
1649
1682
|
tag: null
|
|
1650
1683
|
});
|
|
@@ -1655,8 +1688,8 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1655
1688
|
* @param name - Name of the dataset
|
|
1656
1689
|
*/
|
|
1657
1690
|
getEmbeddingsSettings(name) {
|
|
1658
|
-
return resourceGuard("dataset", _classPrivateFieldGet2(_client$
|
|
1659
|
-
url: _embeddingsSettingsUri(_classPrivateFieldGet2(_client$
|
|
1691
|
+
return resourceGuard("dataset", _classPrivateFieldGet2(_client$5, this).config()), dataset(name), _requestObservable(_classPrivateFieldGet2(_client$5, this), _classPrivateFieldGet2(_httpRequest$6, this), {
|
|
1692
|
+
url: _embeddingsSettingsUri(_classPrivateFieldGet2(_client$5, this), name),
|
|
1660
1693
|
tag: null
|
|
1661
1694
|
});
|
|
1662
1695
|
}
|
|
@@ -1667,16 +1700,16 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1667
1700
|
* @param settings - Embeddings settings to apply
|
|
1668
1701
|
*/
|
|
1669
1702
|
editEmbeddingsSettings(name, settings) {
|
|
1670
|
-
return resourceGuard("dataset", _classPrivateFieldGet2(_client$
|
|
1703
|
+
return resourceGuard("dataset", _classPrivateFieldGet2(_client$5, this).config()), dataset(name), _requestObservable(_classPrivateFieldGet2(_client$5, this), _classPrivateFieldGet2(_httpRequest$6, this), {
|
|
1671
1704
|
method: "PUT",
|
|
1672
|
-
url: _embeddingsSettingsUri(_classPrivateFieldGet2(_client$
|
|
1705
|
+
url: _embeddingsSettingsUri(_classPrivateFieldGet2(_client$5, this), name),
|
|
1673
1706
|
body: settings,
|
|
1674
1707
|
tag: null
|
|
1675
1708
|
});
|
|
1676
1709
|
}
|
|
1677
|
-
}, _client2$
|
|
1710
|
+
}, _client2$5 = /* @__PURE__ */ new WeakMap(), _httpRequest2$6 = /* @__PURE__ */ new WeakMap(), DatasetsClient = class {
|
|
1678
1711
|
constructor(client, httpRequest) {
|
|
1679
|
-
_classPrivateFieldInitSpec(this, _client2$
|
|
1712
|
+
_classPrivateFieldInitSpec(this, _client2$5, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$6, void 0), _classPrivateFieldSet2(_client2$5, this, client), _classPrivateFieldSet2(_httpRequest2$6, this, httpRequest);
|
|
1680
1713
|
}
|
|
1681
1714
|
/**
|
|
1682
1715
|
* Create a new dataset with the given name
|
|
@@ -1685,7 +1718,7 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1685
1718
|
* @param options - Options for the dataset, including optional embeddings configuration
|
|
1686
1719
|
*/
|
|
1687
1720
|
create(name, options) {
|
|
1688
|
-
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$
|
|
1721
|
+
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$5, this).config()), _modify(_classPrivateFieldGet2(_client2$5, this), _classPrivateFieldGet2(_httpRequest2$6, this), "PUT", name, options);
|
|
1689
1722
|
}
|
|
1690
1723
|
/**
|
|
1691
1724
|
* Edit a dataset with the given name
|
|
@@ -1694,7 +1727,7 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1694
1727
|
* @param options - New options for the dataset
|
|
1695
1728
|
*/
|
|
1696
1729
|
edit(name, options) {
|
|
1697
|
-
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$
|
|
1730
|
+
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$5, this).config()), _modify(_classPrivateFieldGet2(_client2$5, this), _classPrivateFieldGet2(_httpRequest2$6, this), "PATCH", name, options);
|
|
1698
1731
|
}
|
|
1699
1732
|
/**
|
|
1700
1733
|
* Delete a dataset with the given name
|
|
@@ -1702,15 +1735,15 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1702
1735
|
* @param name - Name of the dataset to delete
|
|
1703
1736
|
*/
|
|
1704
1737
|
delete(name) {
|
|
1705
|
-
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$
|
|
1738
|
+
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$5, this).config()), _modify(_classPrivateFieldGet2(_client2$5, this), _classPrivateFieldGet2(_httpRequest2$6, this), "DELETE", name);
|
|
1706
1739
|
}
|
|
1707
1740
|
/**
|
|
1708
1741
|
* Fetch a list of datasets for the configured project
|
|
1709
1742
|
*/
|
|
1710
1743
|
list() {
|
|
1711
|
-
resourceGuard("dataset", _classPrivateFieldGet2(_client2$
|
|
1712
|
-
let config = _classPrivateFieldGet2(_client2$
|
|
1713
|
-
return config.useProjectHostname === !1 && (url = `/projects/${projectId}/datasets`), _request(_classPrivateFieldGet2(_client2$
|
|
1744
|
+
resourceGuard("dataset", _classPrivateFieldGet2(_client2$5, this).config());
|
|
1745
|
+
let config = _classPrivateFieldGet2(_client2$5, this).config(), projectId = config.projectId, url = "/datasets";
|
|
1746
|
+
return config.useProjectHostname === !1 && (url = `/projects/${projectId}/datasets`), _request(_classPrivateFieldGet2(_client2$5, this), _classPrivateFieldGet2(_httpRequest2$6, this), {
|
|
1714
1747
|
url,
|
|
1715
1748
|
tag: null
|
|
1716
1749
|
});
|
|
@@ -1721,8 +1754,8 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1721
1754
|
* @param name - Name of the dataset
|
|
1722
1755
|
*/
|
|
1723
1756
|
getEmbeddingsSettings(name) {
|
|
1724
|
-
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$
|
|
1725
|
-
url: _embeddingsSettingsUri(_classPrivateFieldGet2(_client2$
|
|
1757
|
+
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$5, this).config()), dataset(name), _request(_classPrivateFieldGet2(_client2$5, this), _classPrivateFieldGet2(_httpRequest2$6, this), {
|
|
1758
|
+
url: _embeddingsSettingsUri(_classPrivateFieldGet2(_client2$5, this), name),
|
|
1726
1759
|
tag: null
|
|
1727
1760
|
});
|
|
1728
1761
|
}
|
|
@@ -1733,9 +1766,9 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
1733
1766
|
* @param settings - Embeddings settings to apply
|
|
1734
1767
|
*/
|
|
1735
1768
|
editEmbeddingsSettings(name, settings) {
|
|
1736
|
-
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$
|
|
1769
|
+
return resourceGuard("dataset", _classPrivateFieldGet2(_client2$5, this).config()), dataset(name), _request(_classPrivateFieldGet2(_client2$5, this), _classPrivateFieldGet2(_httpRequest2$6, this), {
|
|
1737
1770
|
method: "PUT",
|
|
1738
|
-
url: _embeddingsSettingsUri(_classPrivateFieldGet2(_client2$
|
|
1771
|
+
url: _embeddingsSettingsUri(_classPrivateFieldGet2(_client2$5, this), name),
|
|
1739
1772
|
body: settings,
|
|
1740
1773
|
tag: null
|
|
1741
1774
|
});
|
|
@@ -1761,7 +1794,101 @@ function _modify(client, httpRequest, method, name, options) {
|
|
|
1761
1794
|
tag: null
|
|
1762
1795
|
});
|
|
1763
1796
|
}
|
|
1764
|
-
|
|
1797
|
+
/** Function resource types in a blueprint are namespaced under this prefix. */
|
|
1798
|
+
const scopeHeaders = (config, request) => {
|
|
1799
|
+
let organizationId = request?.organizationId || config.organizationId;
|
|
1800
|
+
if (organizationId) return {
|
|
1801
|
+
"X-Sanity-Scope-Type": "organization",
|
|
1802
|
+
"X-Sanity-Scope-Id": organizationId
|
|
1803
|
+
};
|
|
1804
|
+
let { projectId } = config;
|
|
1805
|
+
if (!projectId) throw Error("`functions.invoke()` requires a `projectId` to be set in the client config, or an `organizationId` for a stack deployed at organization scope");
|
|
1806
|
+
return {
|
|
1807
|
+
"X-Sanity-Scope-Type": "project",
|
|
1808
|
+
"X-Sanity-Scope-Id": projectId
|
|
1809
|
+
};
|
|
1810
|
+
}, resolveStackId = (config, request) => {
|
|
1811
|
+
let stackId = request?.stackId || config.stackId;
|
|
1812
|
+
if (!stackId) throw Error("`functions.invoke()` requires a `stackId`, either in the client config or on the request. Function names are only unique within a stack.");
|
|
1813
|
+
return stackId;
|
|
1814
|
+
};
|
|
1815
|
+
/**
|
|
1816
|
+
* The invoke route is keyed by function id, but callers know functions by the
|
|
1817
|
+
* name declared in the blueprint. Names are unique within a stack, so the stack
|
|
1818
|
+
* both makes the name resolvable and confines the call to its own functions.
|
|
1819
|
+
*
|
|
1820
|
+
* @internal
|
|
1821
|
+
*/
|
|
1822
|
+
function _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request) {
|
|
1823
|
+
return _requestObservable(client, httpRequest, {
|
|
1824
|
+
method: "GET",
|
|
1825
|
+
url: `/blueprints/stacks/${stackId}`,
|
|
1826
|
+
headers,
|
|
1827
|
+
signal: request?.signal
|
|
1828
|
+
}).pipe(map((stack) => {
|
|
1829
|
+
let match = (stack?.resources || []).find((resource) => resource.type?.startsWith("sanity.function.") && resource.name === functionName);
|
|
1830
|
+
if (!match) throw Error(`Function "${functionName}" not found in stack "${stackId}"`);
|
|
1831
|
+
if (!match.externalId) throw Error(`Function "${functionName}" is declared in stack "${stackId}" but is not deployed`);
|
|
1832
|
+
if (match.type !== "sanity.function.pubsub") throw Error(`Function invocation is not supported for ${match.type}`);
|
|
1833
|
+
return match.externalId;
|
|
1834
|
+
}));
|
|
1835
|
+
}
|
|
1836
|
+
/** @internal */
|
|
1837
|
+
function _invoke(client, httpRequest, functionName, request) {
|
|
1838
|
+
return defer(() => {
|
|
1839
|
+
let config = client.config(), headers = scopeHeaders(config, request);
|
|
1840
|
+
return _resolveFunctionId(client, httpRequest, functionName, resolveStackId(config, request), headers, request).pipe(mergeMap((functionId) => _requestObservable(client, httpRequest, {
|
|
1841
|
+
method: "POST",
|
|
1842
|
+
url: `/functions/${functionId}/invoke`,
|
|
1843
|
+
headers,
|
|
1844
|
+
body: { event: { data: request?.event?.data ?? {} } },
|
|
1845
|
+
timeout: request?.timeout,
|
|
1846
|
+
signal: request?.signal
|
|
1847
|
+
})));
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */ new WeakMap(), ObservableFunctionsClient = class {
|
|
1851
|
+
constructor(client, httpRequest) {
|
|
1852
|
+
_classPrivateFieldInitSpec(this, _client$4, void 0), _classPrivateFieldInitSpec(this, _httpRequest$5, void 0), _classPrivateFieldSet2(_client$4, this, client), _classPrivateFieldSet2(_httpRequest$5, this, httpRequest);
|
|
1853
|
+
}
|
|
1854
|
+
/**
|
|
1855
|
+
* Invoke a deployed function by its blueprint name.
|
|
1856
|
+
*
|
|
1857
|
+
* The name is resolved within the stack given by `stackId` on the request or
|
|
1858
|
+
* the client config. Passes the function's return value once it finishes.
|
|
1859
|
+
*
|
|
1860
|
+
* @param functionName - name of the function, as declared in the blueprint
|
|
1861
|
+
* @param request - payload and request options
|
|
1862
|
+
*/
|
|
1863
|
+
invoke(functionName, request) {
|
|
1864
|
+
return _invoke(_classPrivateFieldGet2(_client$4, this), _classPrivateFieldGet2(_httpRequest$5, this), functionName, request);
|
|
1865
|
+
}
|
|
1866
|
+
}, _client2$4 = /* @__PURE__ */ new WeakMap(), _httpRequest2$5 = /* @__PURE__ */ new WeakMap(), FunctionsClient = class {
|
|
1867
|
+
constructor(client, httpRequest) {
|
|
1868
|
+
_classPrivateFieldInitSpec(this, _client2$4, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$5, void 0), _classPrivateFieldSet2(_client2$4, this, client), _classPrivateFieldSet2(_httpRequest2$5, this, httpRequest);
|
|
1869
|
+
}
|
|
1870
|
+
/**
|
|
1871
|
+
* Invoke a deployed function by its blueprint name.
|
|
1872
|
+
*
|
|
1873
|
+
* The name is resolved within the stack given by `stackId` on the request or
|
|
1874
|
+
* the client config, which costs one extra request per call. Rejects if the
|
|
1875
|
+
* stack has no function by that name, or if the name resolves to anything
|
|
1876
|
+
* other than a `sanity.function.pubsub` function.
|
|
1877
|
+
*
|
|
1878
|
+
* The lookup is scoped to `projectId`, or to `organizationId` when one is set
|
|
1879
|
+
* for a stack deployed at organization scope.
|
|
1880
|
+
*
|
|
1881
|
+
* The request stays open until the function finishes, and resolves with its
|
|
1882
|
+
* return value, or `undefined` if it returns nothing. Long-running functions
|
|
1883
|
+
* may need an explicit `timeout`.
|
|
1884
|
+
*
|
|
1885
|
+
* @param functionName - name of the function, as declared in the blueprint
|
|
1886
|
+
* @param request - payload and request options
|
|
1887
|
+
*/
|
|
1888
|
+
invoke(functionName, request) {
|
|
1889
|
+
return lastValueFrom(_invoke(_classPrivateFieldGet2(_client2$4, this), _classPrivateFieldGet2(_httpRequest2$5, this), functionName, request));
|
|
1890
|
+
}
|
|
1891
|
+
}, _client$3 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap(), ObservableMediaLibraryVideoClient = class {
|
|
1765
1892
|
constructor(client, httpRequest) {
|
|
1766
1893
|
_classPrivateFieldInitSpec(this, _client$3, void 0), _classPrivateFieldInitSpec(this, _httpRequest$4, void 0), _classPrivateFieldSet2(_client$3, this, client), _classPrivateFieldSet2(_httpRequest$4, this, httpRequest);
|
|
1767
1894
|
}
|
|
@@ -2393,14 +2520,14 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2393
2520
|
}
|
|
2394
2521
|
}, _clientConfig = /* @__PURE__ */ new WeakMap(), _httpRequest = /* @__PURE__ */ new WeakMap(), ObservableSanityClient = class ObservableSanityClient {
|
|
2395
2522
|
constructor(httpRequest, config = defaultConfig) {
|
|
2396
|
-
_defineProperty(this, "assets", void 0), _defineProperty(this, "datasets", void 0), _defineProperty(this, "live", void 0), _defineProperty(this, "mediaLibrary", void 0), _defineProperty(this, "projects", void 0), _defineProperty(this, "users", void 0), _defineProperty(this, "agent", void 0), _defineProperty(this, "releases", void 0), _classPrivateFieldInitSpec(this, _clientConfig, void 0), _classPrivateFieldInitSpec(this, _httpRequest, void 0), _defineProperty(
|
|
2523
|
+
_defineProperty(this, "assets", void 0), _defineProperty(this, "datasets", void 0), _defineProperty(this, "live", void 0), _defineProperty(this, "mediaLibrary", void 0), _defineProperty(this, "projects", void 0), _defineProperty(this, "users", void 0), _defineProperty(this, "agent", void 0), _defineProperty(this, "functions", void 0), _defineProperty(this, "releases", void 0), _classPrivateFieldInitSpec(this, _clientConfig, void 0), _classPrivateFieldInitSpec(this, _httpRequest, void 0), _defineProperty(
|
|
2397
2524
|
this,
|
|
2398
2525
|
/**
|
|
2399
2526
|
* Instance properties
|
|
2400
2527
|
*/
|
|
2401
2528
|
"listen",
|
|
2402
2529
|
_listen
|
|
2403
|
-
), this.config(config), _classPrivateFieldSet2(_httpRequest, this, httpRequest), this.assets = new ObservableAssetsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.datasets = new ObservableDatasetsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.live = new LiveClient(this), this.mediaLibrary = { video: new ObservableMediaLibraryVideoClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.projects = new ObservableProjectsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.users = new ObservableUsersClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.agent = { action: new ObservableAgentsActionClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.releases = new ObservableReleasesClient(this, _classPrivateFieldGet2(_httpRequest, this));
|
|
2530
|
+
), this.config(config), _classPrivateFieldSet2(_httpRequest, this, httpRequest), this.assets = new ObservableAssetsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.datasets = new ObservableDatasetsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.live = new LiveClient(this), this.mediaLibrary = { video: new ObservableMediaLibraryVideoClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.projects = new ObservableProjectsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.users = new ObservableUsersClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.agent = { action: new ObservableAgentsActionClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.functions = new ObservableFunctionsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.releases = new ObservableReleasesClient(this, _classPrivateFieldGet2(_httpRequest, this));
|
|
2404
2531
|
}
|
|
2405
2532
|
/**
|
|
2406
2533
|
* Clone the client - returns a new instance
|
|
@@ -2617,7 +2744,7 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2617
2744
|
}
|
|
2618
2745
|
}, _clientConfig2 = /* @__PURE__ */ new WeakMap(), _httpRequest2 = /* @__PURE__ */ new WeakMap(), SanityClient = class SanityClient {
|
|
2619
2746
|
constructor(httpRequest, config = defaultConfig) {
|
|
2620
|
-
_defineProperty(this, "assets", void 0), _defineProperty(this, "datasets", void 0), _defineProperty(this, "live", void 0), _defineProperty(this, "mediaLibrary", void 0), _defineProperty(this, "projects", void 0), _defineProperty(this, "users", void 0), _defineProperty(this, "agent", void 0), _defineProperty(this, "releases", void 0), _defineProperty(
|
|
2747
|
+
_defineProperty(this, "assets", void 0), _defineProperty(this, "datasets", void 0), _defineProperty(this, "live", void 0), _defineProperty(this, "mediaLibrary", void 0), _defineProperty(this, "projects", void 0), _defineProperty(this, "users", void 0), _defineProperty(this, "agent", void 0), _defineProperty(this, "functions", void 0), _defineProperty(this, "releases", void 0), _defineProperty(
|
|
2621
2748
|
this,
|
|
2622
2749
|
/**
|
|
2623
2750
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
@@ -2631,7 +2758,7 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2631
2758
|
*/
|
|
2632
2759
|
"listen",
|
|
2633
2760
|
_listen
|
|
2634
|
-
), this.config(config), _classPrivateFieldSet2(_httpRequest2, this, httpRequest), this.assets = new AssetsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.datasets = new DatasetsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.live = new LiveClient(this), this.mediaLibrary = { video: new MediaLibraryVideoClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.projects = new ProjectsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.users = new UsersClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.agent = { action: new AgentActionsClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.releases = new ReleasesClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
2761
|
+
), this.config(config), _classPrivateFieldSet2(_httpRequest2, this, httpRequest), this.assets = new AssetsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.datasets = new DatasetsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.live = new LiveClient(this), this.mediaLibrary = { video: new MediaLibraryVideoClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.projects = new ProjectsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.users = new UsersClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.agent = { action: new AgentActionsClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.functions = new FunctionsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.releases = new ReleasesClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
2635
2762
|
}
|
|
2636
2763
|
/**
|
|
2637
2764
|
* Clone the client - returns a new instance
|
|
@@ -2873,10 +3000,10 @@ function defineCreateClientExports(envOptions, ClassConstructor) {
|
|
|
2873
3000
|
ignoreWarnings: config.ignoreWarnings,
|
|
2874
3001
|
maxRetries: config.maxRetries,
|
|
2875
3002
|
retryDelay: config.retryDelay
|
|
2876
|
-
}),
|
|
3003
|
+
}), performRequest = async (options) => (await clientRequesterPromise({
|
|
2877
3004
|
redirect: "manual",
|
|
2878
3005
|
...options
|
|
2879
|
-
})).body;
|
|
3006
|
+
})).body, httpRequest = (options, requestHandler) => requestHandler ? requestHandler(options, performRequest) : performRequest(options);
|
|
2880
3007
|
return new ClassConstructor(httpRequest, {
|
|
2881
3008
|
...config,
|
|
2882
3009
|
requester: clientRequester,
|
|
@@ -2894,6 +3021,6 @@ function defineDeprecatedCreateClient(createClient) {
|
|
|
2894
3021
|
};
|
|
2895
3022
|
}
|
|
2896
3023
|
const exp = defineCreateClientExports({ middleware: [] }, SanityClient), requester = exp.requester, createClient = exp.createClient, deprecatedCreateClient = defineDeprecatedCreateClient(createClient);
|
|
2897
|
-
export { BasePatch, BaseTransaction, ChannelError, ClientError, ConnectionFailedError, CorsOriginError, DisconnectError, EXPERIMENTAL_API_WARNING, MessageError, MessageParseError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, connectEventSource, createClient, deprecatedCreateClient as default, formatQueryParseError, isHttpError, isQueryParseError, requester, validateApiPerspective };
|
|
3024
|
+
export { BasePatch, BaseTransaction, ChannelError, ClientError, ConnectionFailedError, CorsOriginError, DisconnectError, EXPERIMENTAL_API_WARNING, MessageError, MessageParseError, ObservablePatch, ObservableSanityClient, ObservableTransaction, Patch, SanityClient, ServerError, Transaction, connectEventSource, createClient, deprecatedCreateClient as default, formatQueryParseError, isHttpError, isQueryParseError, isTimeoutError, requester, validateApiPerspective };
|
|
2898
3025
|
|
|
2899
3026
|
//# sourceMappingURL=index.js.map
|