@sanity/client 8.2.0 → 8.4.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 +2 -2
- package/dist/{browserUpload-2tz6Sdqp.js → browserUpload-C7PwCs-C.js} +6 -9
- package/dist/browserUpload-C7PwCs-C.js.map +1 -0
- package/dist/{browserUpload-CwpNx7Vl.js → browserUpload-D-2Rmfjo.js} +6 -9
- package/dist/browserUpload-D-2Rmfjo.js.map +1 -0
- package/dist/{config-3wiPP-sZ.js → config-CgJ16jET.js} +4 -2
- package/dist/config-CgJ16jET.js.map +1 -0
- package/dist/csm.js +1 -1
- package/dist/{dist-C9ExSk2R.js → dist-C5K_YcEU.js} +3 -2
- package/dist/{dist-C9ExSk2R.js.map → dist-C5K_YcEU.js.map} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +942 -115
- package/dist/index.js.map +1 -1
- package/dist/index.node.d.ts +3345 -16
- package/dist/index.node.js +865 -59
- package/dist/index.node.js.map +1 -1
- package/dist/media-library.d.ts +1 -1
- package/dist/rolldown-runtime-4YWMqDIC.js +9 -0
- package/dist/{stegaEncodeSourceMap-DbM2fTN4.js → stegaEncodeSourceMap-CO1HKnm2.js} +2 -2
- package/dist/{stegaEncodeSourceMap-DbM2fTN4.js.map → stegaEncodeSourceMap-CO1HKnm2.js.map} +1 -1
- package/dist/{types-nJhm5Nyq.d.ts → types-DiPF0ENT.d.ts} +3346 -17
- package/package.json +3 -3
- package/src/SanityClient.ts +7 -0
- package/src/assets/AssetsClient.ts +5 -0
- package/src/collaboration/types.ts +59 -8
- package/src/config.ts +1 -0
- package/src/context/ContextClient.ts +1006 -0
- package/src/context/openapi.json +5345 -0
- package/src/context/reads.ts +206 -0
- package/src/context/store.ts +100 -0
- package/src/context/types.gen.ts +2428 -0
- package/src/context/types.ts +228 -0
- package/src/data/dataMethods.ts +4 -1
- package/src/defineCreateClient.ts +1 -0
- package/src/functions/FunctionsClient.ts +52 -9
- package/src/functions/invoke.ts +47 -6
- package/src/http/browserUpload.ts +0 -12
- package/src/types.ts +29 -3
- package/src/util/createVersionId.ts +15 -5
- package/src/validators.ts +1 -0
- package/dist/browserUpload-2tz6Sdqp.js.map +0 -1
- package/dist/browserUpload-CwpNx7Vl.js.map +0 -1
- package/dist/config-3wiPP-sZ.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-vyAXikos.js";
|
|
1
2
|
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
3
|
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-
|
|
4
|
+
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-CgJ16jET.js";
|
|
4
5
|
import { t as stegaClean } from "./stegaClean-C18wLWau.js";
|
|
5
6
|
import { isTimeoutError } from "get-it";
|
|
6
7
|
import { Observable, catchError, concat, defer, finalize, isObservable, lastValueFrom, map, merge, mergeMap, of, share, tap, throwError, timer } from "rxjs";
|
|
7
8
|
import { getDraftId, getPublishedId, getVersionFromId, getVersionId, isDraftId, isVersionId } from "@sanity/client/csm";
|
|
8
9
|
import { filter, finalize as finalize$1, map as map$1, mergeAll } from "rxjs/operators";
|
|
9
10
|
import { EventSource } from "eventsource";
|
|
10
|
-
import { customAlphabet } from "nanoid";
|
|
11
11
|
/**
|
|
12
12
|
* A string constant containing the experimental API version warning message.
|
|
13
13
|
* Use this with the `ignoreWarnings` option to suppress warnings when using experimental API versions.
|
|
@@ -338,41 +338,41 @@ var BasePatch = class {
|
|
|
338
338
|
_set(op, props) {
|
|
339
339
|
return this._assign(op, props, !1);
|
|
340
340
|
}
|
|
341
|
-
}, _client$
|
|
341
|
+
}, _client$12 = /* @__PURE__ */ new WeakMap(), ObservablePatch = class ObservablePatch extends BasePatch {
|
|
342
342
|
constructor(selection, operations, client) {
|
|
343
|
-
super(selection, operations), _classPrivateFieldInitSpec(this, _client$
|
|
343
|
+
super(selection, operations), _classPrivateFieldInitSpec(this, _client$12, void 0), _classPrivateFieldSet2(_client$12, this, client);
|
|
344
344
|
}
|
|
345
345
|
/**
|
|
346
346
|
* Clones the patch
|
|
347
347
|
*/
|
|
348
348
|
clone() {
|
|
349
|
-
return new ObservablePatch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client$
|
|
349
|
+
return new ObservablePatch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client$12, this));
|
|
350
350
|
}
|
|
351
351
|
commit(options) {
|
|
352
|
-
if (!_classPrivateFieldGet2(_client$
|
|
352
|
+
if (!_classPrivateFieldGet2(_client$12, this)) throw Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
353
353
|
let returnFirst = typeof this.selection == "string", opts = Object.assign({
|
|
354
354
|
returnFirst,
|
|
355
355
|
returnDocuments: !0
|
|
356
356
|
}, options);
|
|
357
|
-
return _classPrivateFieldGet2(_client$
|
|
357
|
+
return _classPrivateFieldGet2(_client$12, this).mutate({ patch: this.serialize() }, opts);
|
|
358
358
|
}
|
|
359
|
-
}, _client2$
|
|
359
|
+
}, _client2$11 = /* @__PURE__ */ new WeakMap(), Patch = class Patch extends BasePatch {
|
|
360
360
|
constructor(selection, operations, client) {
|
|
361
|
-
super(selection, operations), _classPrivateFieldInitSpec(this, _client2$
|
|
361
|
+
super(selection, operations), _classPrivateFieldInitSpec(this, _client2$11, void 0), _classPrivateFieldSet2(_client2$11, this, client);
|
|
362
362
|
}
|
|
363
363
|
/**
|
|
364
364
|
* Clones the patch
|
|
365
365
|
*/
|
|
366
366
|
clone() {
|
|
367
|
-
return new Patch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client2$
|
|
367
|
+
return new Patch(this.selection, { ...this.operations }, _classPrivateFieldGet2(_client2$11, this));
|
|
368
368
|
}
|
|
369
369
|
commit(options) {
|
|
370
|
-
if (!_classPrivateFieldGet2(_client2$
|
|
370
|
+
if (!_classPrivateFieldGet2(_client2$11, this)) throw Error("No `client` passed to patch, either provide one or pass the patch to a clients `mutate()` method");
|
|
371
371
|
let returnFirst = typeof this.selection == "string", opts = Object.assign({
|
|
372
372
|
returnFirst,
|
|
373
373
|
returnDocuments: !0
|
|
374
374
|
}, options);
|
|
375
|
-
return _classPrivateFieldGet2(_client2$
|
|
375
|
+
return _classPrivateFieldGet2(_client2$11, this).mutate({ patch: this.serialize() }, opts);
|
|
376
376
|
}
|
|
377
377
|
};
|
|
378
378
|
const defaultMutateOptions = { returnDocuments: !1 };
|
|
@@ -443,30 +443,30 @@ var BaseTransaction = class {
|
|
|
443
443
|
_add(mut) {
|
|
444
444
|
return this.operations.push(mut), this;
|
|
445
445
|
}
|
|
446
|
-
}, _client$
|
|
446
|
+
}, _client$11 = /* @__PURE__ */ new WeakMap(), Transaction = class Transaction extends BaseTransaction {
|
|
447
447
|
constructor(operations, client, transactionId) {
|
|
448
|
-
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client$
|
|
448
|
+
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client$11, void 0), _classPrivateFieldSet2(_client$11, this, client);
|
|
449
449
|
}
|
|
450
450
|
/**
|
|
451
451
|
* Clones the transaction
|
|
452
452
|
*/
|
|
453
453
|
clone() {
|
|
454
|
-
return new Transaction([...this.operations], _classPrivateFieldGet2(_client$
|
|
454
|
+
return new Transaction([...this.operations], _classPrivateFieldGet2(_client$11, this), this.trxId);
|
|
455
455
|
}
|
|
456
456
|
commit(options) {
|
|
457
|
-
if (!_classPrivateFieldGet2(_client$
|
|
458
|
-
return _classPrivateFieldGet2(_client$
|
|
457
|
+
if (!_classPrivateFieldGet2(_client$11, this)) throw Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
458
|
+
return _classPrivateFieldGet2(_client$11, this).mutate(this.serialize(), Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {}));
|
|
459
459
|
}
|
|
460
460
|
patch(patchOrDocumentId, patchOps) {
|
|
461
461
|
let isBuilder = typeof patchOps == "function", isPatch = typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof Patch, isMutationSelection = typeof patchOrDocumentId == "object" && ("query" in patchOrDocumentId || "id" in patchOrDocumentId);
|
|
462
462
|
if (isPatch) return this._add({ patch: patchOrDocumentId.serialize() });
|
|
463
463
|
if (isBuilder) {
|
|
464
|
-
let patch = patchOps(new Patch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client$
|
|
464
|
+
let patch = patchOps(new Patch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client$11, this)));
|
|
465
465
|
if (!(patch instanceof Patch)) throw Error("function passed to `patch()` must return the patch");
|
|
466
466
|
return this._add({ patch: patch.serialize() });
|
|
467
467
|
}
|
|
468
468
|
if (isMutationSelection) {
|
|
469
|
-
let patch = new Patch(patchOrDocumentId, patchOps || {}, _classPrivateFieldGet2(_client$
|
|
469
|
+
let patch = new Patch(patchOrDocumentId, patchOps || {}, _classPrivateFieldGet2(_client$11, this));
|
|
470
470
|
return this._add({ patch: patch.serialize() });
|
|
471
471
|
}
|
|
472
472
|
return this._add({ patch: {
|
|
@@ -474,25 +474,25 @@ var BaseTransaction = class {
|
|
|
474
474
|
...patchOps
|
|
475
475
|
} });
|
|
476
476
|
}
|
|
477
|
-
}, _client2$
|
|
477
|
+
}, _client2$10 = /* @__PURE__ */ new WeakMap(), ObservableTransaction = class ObservableTransaction extends BaseTransaction {
|
|
478
478
|
constructor(operations, client, transactionId) {
|
|
479
|
-
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client2$
|
|
479
|
+
super(operations, transactionId), _classPrivateFieldInitSpec(this, _client2$10, void 0), _classPrivateFieldSet2(_client2$10, this, client);
|
|
480
480
|
}
|
|
481
481
|
/**
|
|
482
482
|
* Clones the transaction
|
|
483
483
|
*/
|
|
484
484
|
clone() {
|
|
485
|
-
return new ObservableTransaction([...this.operations], _classPrivateFieldGet2(_client2$
|
|
485
|
+
return new ObservableTransaction([...this.operations], _classPrivateFieldGet2(_client2$10, this), this.trxId);
|
|
486
486
|
}
|
|
487
487
|
commit(options) {
|
|
488
|
-
if (!_classPrivateFieldGet2(_client2$
|
|
489
|
-
return _classPrivateFieldGet2(_client2$
|
|
488
|
+
if (!_classPrivateFieldGet2(_client2$10, this)) throw Error("No `client` passed to transaction, either provide one or pass the transaction to a clients `mutate()` method");
|
|
489
|
+
return _classPrivateFieldGet2(_client2$10, this).mutate(this.serialize(), Object.assign({ transactionId: this.trxId }, defaultMutateOptions, options || {}));
|
|
490
490
|
}
|
|
491
491
|
patch(patchOrDocumentId, patchOps) {
|
|
492
492
|
let isBuilder = typeof patchOps == "function";
|
|
493
493
|
if (typeof patchOrDocumentId != "string" && patchOrDocumentId instanceof ObservablePatch) return this._add({ patch: patchOrDocumentId.serialize() });
|
|
494
494
|
if (isBuilder) {
|
|
495
|
-
let patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client2$
|
|
495
|
+
let patch = patchOps(new ObservablePatch(patchOrDocumentId, {}, _classPrivateFieldGet2(_client2$10, this)));
|
|
496
496
|
if (!(patch instanceof ObservablePatch)) throw Error("function passed to `patch()` must return the patch");
|
|
497
497
|
return this._add({ patch: patch.serialize() });
|
|
498
498
|
}
|
|
@@ -501,7 +501,15 @@ var BaseTransaction = class {
|
|
|
501
501
|
...patchOps
|
|
502
502
|
} });
|
|
503
503
|
}
|
|
504
|
-
};
|
|
504
|
+
}, types_exports = /* @__PURE__ */ __exportAll({ possibleStoreRequestOptions: () => possibleStoreRequestOptions });
|
|
505
|
+
/** @internal */
|
|
506
|
+
const possibleStoreRequestOptions = [
|
|
507
|
+
"headers",
|
|
508
|
+
"signal",
|
|
509
|
+
"tag",
|
|
510
|
+
"timeout",
|
|
511
|
+
"token"
|
|
512
|
+
];
|
|
505
513
|
/**
|
|
506
514
|
* Project the public request options (`timeout: 0` to disable,
|
|
507
515
|
* `withCredentials`, `maxRedirects`, the function/object-form `fetch`, ...)
|
|
@@ -604,7 +612,7 @@ function _fetchRequest(_stega, _params, options) {
|
|
|
604
612
|
}
|
|
605
613
|
/** @internal */
|
|
606
614
|
function _fetchObservable(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
607
|
-
return _observe(options.signal, (signal) => _fetch$
|
|
615
|
+
return _observe(options.signal, (signal) => _fetch$2(client, httpRequest, _stega, query, _params, {
|
|
608
616
|
...options,
|
|
609
617
|
signal
|
|
610
618
|
}));
|
|
@@ -614,7 +622,7 @@ function _fetchObservable(client, httpRequest, _stega, query, _params = {}, opti
|
|
|
614
622
|
*
|
|
615
623
|
* @internal
|
|
616
624
|
*/
|
|
617
|
-
function _fetch$
|
|
625
|
+
function _fetch$2(client, httpRequest, _stega, query, _params = {}, options = {}) {
|
|
618
626
|
let { stega, params, mapResponse, reqOpts } = _fetchRequest(_stega, _params, options), request = _dataRequest(client, httpRequest, "query", {
|
|
619
627
|
query,
|
|
620
628
|
params
|
|
@@ -1176,6 +1184,7 @@ const resourceDataBase = (config) => {
|
|
|
1176
1184
|
return `/projects/${segments[0]}/datasets/${segments[1]}`;
|
|
1177
1185
|
}
|
|
1178
1186
|
case "canvas": return `/canvases/${id}`;
|
|
1187
|
+
case "knowledge-base": return `/knowledge-bases/${id}`;
|
|
1179
1188
|
case "media-library": return `/media-libraries/${id}`;
|
|
1180
1189
|
case "dashboard": return `/dashboards/${id}`;
|
|
1181
1190
|
default: throw Error(`Unsupported resource type: ${type.toString()}`);
|
|
@@ -1240,62 +1249,62 @@ function _translate(client, httpRequest, request) {
|
|
|
1240
1249
|
body: request
|
|
1241
1250
|
});
|
|
1242
1251
|
}
|
|
1243
|
-
var _client$
|
|
1252
|
+
var _client$10 = /* @__PURE__ */ new WeakMap(), _httpRequest$9 = /* @__PURE__ */ new WeakMap(), ObservableAgentsActionClient = class {
|
|
1244
1253
|
constructor(client, httpRequest) {
|
|
1245
|
-
_classPrivateFieldInitSpec(this, _client$
|
|
1254
|
+
_classPrivateFieldInitSpec(this, _client$10, void 0), _classPrivateFieldInitSpec(this, _httpRequest$9, void 0), _classPrivateFieldSet2(_client$10, this, client), _classPrivateFieldSet2(_httpRequest$9, this, httpRequest);
|
|
1246
1255
|
}
|
|
1247
1256
|
/**
|
|
1248
1257
|
* Run an instruction to generate content in a target document.
|
|
1249
1258
|
* @param request - instruction request
|
|
1250
1259
|
*/
|
|
1251
1260
|
generate(request) {
|
|
1252
|
-
return _generateObservable(_classPrivateFieldGet2(_client$
|
|
1261
|
+
return _generateObservable(_classPrivateFieldGet2(_client$10, this), _classPrivateFieldGet2(_httpRequest$9, this), request);
|
|
1253
1262
|
}
|
|
1254
1263
|
/**
|
|
1255
1264
|
* Transform a target document based on a source.
|
|
1256
1265
|
* @param request - translation request
|
|
1257
1266
|
*/
|
|
1258
1267
|
transform(request) {
|
|
1259
|
-
return _transformObservable(_classPrivateFieldGet2(_client$
|
|
1268
|
+
return _transformObservable(_classPrivateFieldGet2(_client$10, this), _classPrivateFieldGet2(_httpRequest$9, this), request);
|
|
1260
1269
|
}
|
|
1261
1270
|
/**
|
|
1262
1271
|
* Translate a target document based on a source.
|
|
1263
1272
|
* @param request - translation request
|
|
1264
1273
|
*/
|
|
1265
1274
|
translate(request) {
|
|
1266
|
-
return _translateObservable(_classPrivateFieldGet2(_client$
|
|
1275
|
+
return _translateObservable(_classPrivateFieldGet2(_client$10, this), _classPrivateFieldGet2(_httpRequest$9, this), request);
|
|
1267
1276
|
}
|
|
1268
|
-
}, _client2$
|
|
1277
|
+
}, _client2$9 = /* @__PURE__ */ new WeakMap(), _httpRequest2$10 = /* @__PURE__ */ new WeakMap(), AgentActionsClient = class {
|
|
1269
1278
|
constructor(client, httpRequest) {
|
|
1270
|
-
_classPrivateFieldInitSpec(this, _client2$
|
|
1279
|
+
_classPrivateFieldInitSpec(this, _client2$9, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$10, void 0), _classPrivateFieldSet2(_client2$9, this, client), _classPrivateFieldSet2(_httpRequest2$10, this, httpRequest);
|
|
1271
1280
|
}
|
|
1272
1281
|
/**
|
|
1273
1282
|
* Run an instruction to generate content in a target document.
|
|
1274
1283
|
* @param request - instruction request
|
|
1275
1284
|
*/
|
|
1276
1285
|
generate(request) {
|
|
1277
|
-
return _generate(_classPrivateFieldGet2(_client2$
|
|
1286
|
+
return _generate(_classPrivateFieldGet2(_client2$9, this), _classPrivateFieldGet2(_httpRequest2$10, this), request);
|
|
1278
1287
|
}
|
|
1279
1288
|
/**
|
|
1280
1289
|
* Transform a target document based on a source.
|
|
1281
1290
|
* @param request - translation request
|
|
1282
1291
|
*/
|
|
1283
1292
|
transform(request) {
|
|
1284
|
-
return _transform(_classPrivateFieldGet2(_client2$
|
|
1293
|
+
return _transform(_classPrivateFieldGet2(_client2$9, this), _classPrivateFieldGet2(_httpRequest2$10, this), request);
|
|
1285
1294
|
}
|
|
1286
1295
|
/**
|
|
1287
1296
|
* Translate a target document based on a source.
|
|
1288
1297
|
* @param request - translation request
|
|
1289
1298
|
*/
|
|
1290
1299
|
translate(request) {
|
|
1291
|
-
return _translate(_classPrivateFieldGet2(_client2$
|
|
1300
|
+
return _translate(_classPrivateFieldGet2(_client2$9, this), _classPrivateFieldGet2(_httpRequest2$10, this), request);
|
|
1292
1301
|
}
|
|
1293
1302
|
/**
|
|
1294
1303
|
* Run a raw instruction and return the result either as text or json
|
|
1295
1304
|
* @param request - prompt request
|
|
1296
1305
|
*/
|
|
1297
1306
|
prompt(request) {
|
|
1298
|
-
return _prompt(_classPrivateFieldGet2(_client2$
|
|
1307
|
+
return _prompt(_classPrivateFieldGet2(_client2$9, this), _classPrivateFieldGet2(_httpRequest2$10, this), request);
|
|
1299
1308
|
}
|
|
1300
1309
|
/**
|
|
1301
1310
|
* Patch a document using a schema aware API.
|
|
@@ -1303,21 +1312,21 @@ var _client$9 = /* @__PURE__ */ new WeakMap(), _httpRequest$8 = /* @__PURE__ */
|
|
|
1303
1312
|
* @param request - instruction request
|
|
1304
1313
|
*/
|
|
1305
1314
|
patch(request) {
|
|
1306
|
-
return _patch(_classPrivateFieldGet2(_client2$
|
|
1315
|
+
return _patch(_classPrivateFieldGet2(_client2$9, this), _classPrivateFieldGet2(_httpRequest2$10, this), request);
|
|
1307
1316
|
}
|
|
1308
|
-
}, _client$
|
|
1317
|
+
}, _client$9 = /* @__PURE__ */ new WeakMap(), _httpRequest2$9 = /* @__PURE__ */ new WeakMap(), ObservableAssetsClient = class {
|
|
1309
1318
|
constructor(client, httpRequest) {
|
|
1310
|
-
_classPrivateFieldInitSpec(this, _client$
|
|
1319
|
+
_classPrivateFieldInitSpec(this, _client$9, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$9, void 0), _classPrivateFieldSet2(_client$9, this, client), _classPrivateFieldSet2(_httpRequest2$9, this, httpRequest);
|
|
1311
1320
|
}
|
|
1312
1321
|
upload(assetType, body, options) {
|
|
1313
|
-
return _upload(_classPrivateFieldGet2(_client$
|
|
1322
|
+
return _upload(_classPrivateFieldGet2(_client$9, this), _classPrivateFieldGet2(_httpRequest2$9, this), assetType, body, options);
|
|
1314
1323
|
}
|
|
1315
|
-
}, _client2$
|
|
1324
|
+
}, _client2$8 = /* @__PURE__ */ new WeakMap(), _httpRequest3 = /* @__PURE__ */ new WeakMap(), AssetsClient = class {
|
|
1316
1325
|
constructor(client, httpRequest) {
|
|
1317
|
-
_classPrivateFieldInitSpec(this, _client2$
|
|
1326
|
+
_classPrivateFieldInitSpec(this, _client2$8, void 0), _classPrivateFieldInitSpec(this, _httpRequest3, void 0), _classPrivateFieldSet2(_client2$8, this, client), _classPrivateFieldSet2(_httpRequest3, this, httpRequest);
|
|
1318
1327
|
}
|
|
1319
1328
|
upload(assetType, body, options) {
|
|
1320
|
-
let observable = _upload(_classPrivateFieldGet2(_client2$
|
|
1329
|
+
let observable = _upload(_classPrivateFieldGet2(_client2$8, this), _classPrivateFieldGet2(_httpRequest3, this), assetType, body, options);
|
|
1321
1330
|
return lastValueFrom(observable.pipe(filter((event) => event.type === "response"), map$1((event) => pluckUploadedAsset(event.body))));
|
|
1322
1331
|
}
|
|
1323
1332
|
};
|
|
@@ -1360,7 +1369,7 @@ function _upload(client, _httpRequest, assetType, body, opts = {}) {
|
|
|
1360
1369
|
body
|
|
1361
1370
|
};
|
|
1362
1371
|
return typeof XMLHttpRequest < "u" ? defer(async () => {
|
|
1363
|
-
let { uploadWithProgress } = await import("./browserUpload-
|
|
1372
|
+
let { uploadWithProgress } = await import("./browserUpload-D-2Rmfjo.js"), req = _prepareRequest(client, { ...baseRequest });
|
|
1364
1373
|
return uploadWithProgress({
|
|
1365
1374
|
url: appendQuery(req.url, req.query),
|
|
1366
1375
|
method: req.method ?? "POST",
|
|
@@ -1384,6 +1393,7 @@ function buildAssetUploadUrl(config, assetType) {
|
|
|
1384
1393
|
switch (type) {
|
|
1385
1394
|
case "dataset": throw Error("Assets are not supported for dataset resources, yet. Configure the client with `{projectId: <projectId>, dataset: <datasetId>}` instead.");
|
|
1386
1395
|
case "canvas": return `/canvases/${id}/assets/${assetTypeEndpoint}`;
|
|
1396
|
+
case "knowledge-base": throw Error("Assets are not supported for knowledge-base resources. Use `client.context.imports` to add content instead.");
|
|
1387
1397
|
case "media-library": return `/media-libraries/${id}/upload`;
|
|
1388
1398
|
case "dashboard": return `/dashboards/${id}/assets/${assetTypeEndpoint}`;
|
|
1389
1399
|
default: throw Error(`Unsupported resource type: ${type.toString()}`);
|
|
@@ -1470,7 +1480,7 @@ const possibleOptions = [
|
|
|
1470
1480
|
"tag"
|
|
1471
1481
|
], defaultOptions = { includeResult: !0 };
|
|
1472
1482
|
/** @public */
|
|
1473
|
-
function _listen$
|
|
1483
|
+
function _listen$2(query, params, opts = {}) {
|
|
1474
1484
|
let { url, requestTagPrefix } = this.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, options = {
|
|
1475
1485
|
...defaults_default(opts, defaultOptions),
|
|
1476
1486
|
tag
|
|
@@ -1589,7 +1599,7 @@ function _removeReaction(client, httpRequest, id, shortName, options) {
|
|
|
1589
1599
|
return writeDocument(id, client, httpRequest, "DELETE", `${commentUrl(id)}/reactions/${encodeURIComponent(shortName)}`, void 0, options);
|
|
1590
1600
|
}
|
|
1591
1601
|
/** @internal */
|
|
1592
|
-
function _fetch(client, httpRequest, query, params, options) {
|
|
1602
|
+
function _fetch$1(client, httpRequest, query, params, options) {
|
|
1593
1603
|
let search = resourceQuery(client);
|
|
1594
1604
|
return _requestObservable(client, httpRequest, {
|
|
1595
1605
|
...encodeQueryString({
|
|
@@ -1615,7 +1625,7 @@ function _fetch(client, httpRequest, query, params, options) {
|
|
|
1615
1625
|
}).pipe(map$1((response) => response.result));
|
|
1616
1626
|
}
|
|
1617
1627
|
/** @internal */
|
|
1618
|
-
function _listen(client, query, params, options) {
|
|
1628
|
+
function _listen$1(client, query, params, options) {
|
|
1619
1629
|
let opts = options ?? {}, { requestTagPrefix } = client.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, listenOpts = pick({
|
|
1620
1630
|
...defaults_default(opts, defaultOptions),
|
|
1621
1631
|
tag
|
|
@@ -1629,9 +1639,9 @@ function _listen(client, query, params, options) {
|
|
|
1629
1639
|
}), uri = `${client.getUrl("/collaboration/comments/listen")}${qs}`;
|
|
1630
1640
|
return uri.length > 14800 ? throwError(() => /* @__PURE__ */ Error("Query too large for listener")) : _connectListenEventSource(client, uri, opts.events ? opts.events : ["mutation"]);
|
|
1631
1641
|
}
|
|
1632
|
-
var _client$
|
|
1642
|
+
var _client$8 = /* @__PURE__ */ new WeakMap(), _httpRequest$8 = /* @__PURE__ */ new WeakMap(), ObservableCollaborationCommentsClient = class {
|
|
1633
1643
|
constructor(client, httpRequest) {
|
|
1634
|
-
_classPrivateFieldInitSpec(this, _client$
|
|
1644
|
+
_classPrivateFieldInitSpec(this, _client$8, void 0), _classPrivateFieldInitSpec(this, _httpRequest$8, void 0), _classPrivateFieldSet2(_client$8, this, client), _classPrivateFieldSet2(_httpRequest$8, this, httpRequest);
|
|
1635
1645
|
}
|
|
1636
1646
|
/**
|
|
1637
1647
|
* Create a comment or reply on the configured resource.
|
|
@@ -1644,7 +1654,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1644
1654
|
* @returns The created comment
|
|
1645
1655
|
*/
|
|
1646
1656
|
create(body, options) {
|
|
1647
|
-
return _create(_classPrivateFieldGet2(_client$
|
|
1657
|
+
return _create(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest$8, this), body, options);
|
|
1648
1658
|
}
|
|
1649
1659
|
/**
|
|
1650
1660
|
* Update an existing comment.
|
|
@@ -1657,7 +1667,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1657
1667
|
* @returns The updated comment
|
|
1658
1668
|
*/
|
|
1659
1669
|
update(id, body, options) {
|
|
1660
|
-
return _update(_classPrivateFieldGet2(_client$
|
|
1670
|
+
return _update(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest$8, this), id, body, options);
|
|
1661
1671
|
}
|
|
1662
1672
|
/**
|
|
1663
1673
|
* Delete a comment and its replies.
|
|
@@ -1667,7 +1677,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1667
1677
|
* @returns Mutation result, where `documentIds` covers the comment and every deleted reply
|
|
1668
1678
|
*/
|
|
1669
1679
|
delete(id, options) {
|
|
1670
|
-
return _delete(_classPrivateFieldGet2(_client$
|
|
1680
|
+
return _delete(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest$8, this), id, options);
|
|
1671
1681
|
}
|
|
1672
1682
|
/**
|
|
1673
1683
|
* Add the current user's reaction to a comment.
|
|
@@ -1678,7 +1688,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1678
1688
|
* @returns The comment, with the reaction applied
|
|
1679
1689
|
*/
|
|
1680
1690
|
addReaction(id, shortName, options) {
|
|
1681
|
-
return _addReaction(_classPrivateFieldGet2(_client$
|
|
1691
|
+
return _addReaction(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest$8, this), id, shortName, options);
|
|
1682
1692
|
}
|
|
1683
1693
|
/**
|
|
1684
1694
|
* Remove the current user's reaction from a comment.
|
|
@@ -1689,7 +1699,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1689
1699
|
* @returns The comment, with the reaction removed
|
|
1690
1700
|
*/
|
|
1691
1701
|
removeReaction(id, shortName, options) {
|
|
1692
|
-
return _removeReaction(_classPrivateFieldGet2(_client$
|
|
1702
|
+
return _removeReaction(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest$8, this), id, shortName, options);
|
|
1693
1703
|
}
|
|
1694
1704
|
/**
|
|
1695
1705
|
* Build the global document reference used by `target.document._ref`, for use in
|
|
@@ -1710,7 +1720,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1710
1720
|
* @returns Global document reference, of the form `resourceType:resourceId:documentId`
|
|
1711
1721
|
*/
|
|
1712
1722
|
getTargetDocumentRef(documentId) {
|
|
1713
|
-
return _getTargetDocumentRef(_classPrivateFieldGet2(_client$
|
|
1723
|
+
return _getTargetDocumentRef(_classPrivateFieldGet2(_client$8, this), documentId);
|
|
1714
1724
|
}
|
|
1715
1725
|
/**
|
|
1716
1726
|
* Fetch comments on the configured resource.
|
|
@@ -1729,14 +1739,14 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1729
1739
|
* @param options - Optional request options
|
|
1730
1740
|
*/
|
|
1731
1741
|
fetch(query, params, options) {
|
|
1732
|
-
return _fetch(_classPrivateFieldGet2(_client$
|
|
1742
|
+
return _fetch$1(_classPrivateFieldGet2(_client$8, this), _classPrivateFieldGet2(_httpRequest$8, this), query, params, options);
|
|
1733
1743
|
}
|
|
1734
1744
|
listen(query, params, options) {
|
|
1735
|
-
return _listen(_classPrivateFieldGet2(_client$
|
|
1745
|
+
return _listen$1(_classPrivateFieldGet2(_client$8, this), query, params, options);
|
|
1736
1746
|
}
|
|
1737
|
-
}, _client2$
|
|
1747
|
+
}, _client2$7 = /* @__PURE__ */ new WeakMap(), _httpRequest2$8 = /* @__PURE__ */ new WeakMap(), CollaborationCommentsClient = class {
|
|
1738
1748
|
constructor(client, httpRequest) {
|
|
1739
|
-
_classPrivateFieldInitSpec(this, _client2$
|
|
1749
|
+
_classPrivateFieldInitSpec(this, _client2$7, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$8, void 0), _classPrivateFieldSet2(_client2$7, this, client), _classPrivateFieldSet2(_httpRequest2$8, this, httpRequest);
|
|
1740
1750
|
}
|
|
1741
1751
|
/**
|
|
1742
1752
|
* Create a comment or reply on the configured resource.
|
|
@@ -1749,7 +1759,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1749
1759
|
* @returns The created comment
|
|
1750
1760
|
*/
|
|
1751
1761
|
create(body, options) {
|
|
1752
|
-
return lastValueFrom(_create(_classPrivateFieldGet2(_client2$
|
|
1762
|
+
return lastValueFrom(_create(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), body, options));
|
|
1753
1763
|
}
|
|
1754
1764
|
/**
|
|
1755
1765
|
* Update an existing comment.
|
|
@@ -1762,7 +1772,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1762
1772
|
* @returns The updated comment
|
|
1763
1773
|
*/
|
|
1764
1774
|
update(id, body, options) {
|
|
1765
|
-
return lastValueFrom(_update(_classPrivateFieldGet2(_client2$
|
|
1775
|
+
return lastValueFrom(_update(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), id, body, options));
|
|
1766
1776
|
}
|
|
1767
1777
|
/**
|
|
1768
1778
|
* Delete a comment and its replies.
|
|
@@ -1772,7 +1782,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1772
1782
|
* @returns Mutation result, where `documentIds` covers the comment and every deleted reply
|
|
1773
1783
|
*/
|
|
1774
1784
|
delete(id, options) {
|
|
1775
|
-
return lastValueFrom(_delete(_classPrivateFieldGet2(_client2$
|
|
1785
|
+
return lastValueFrom(_delete(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), id, options));
|
|
1776
1786
|
}
|
|
1777
1787
|
/**
|
|
1778
1788
|
* Add the current user's reaction to a comment.
|
|
@@ -1783,7 +1793,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1783
1793
|
* @returns The comment, with the reaction applied
|
|
1784
1794
|
*/
|
|
1785
1795
|
addReaction(id, shortName, options) {
|
|
1786
|
-
return lastValueFrom(_addReaction(_classPrivateFieldGet2(_client2$
|
|
1796
|
+
return lastValueFrom(_addReaction(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), id, shortName, options));
|
|
1787
1797
|
}
|
|
1788
1798
|
/**
|
|
1789
1799
|
* Remove the current user's reaction from a comment.
|
|
@@ -1794,7 +1804,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1794
1804
|
* @returns The comment, with the reaction removed
|
|
1795
1805
|
*/
|
|
1796
1806
|
removeReaction(id, shortName, options) {
|
|
1797
|
-
return lastValueFrom(_removeReaction(_classPrivateFieldGet2(_client2$
|
|
1807
|
+
return lastValueFrom(_removeReaction(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), id, shortName, options));
|
|
1798
1808
|
}
|
|
1799
1809
|
/**
|
|
1800
1810
|
* Build the global document reference used by `target.document._ref`, for use in
|
|
@@ -1815,7 +1825,7 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1815
1825
|
* @returns Global document reference, of the form `resourceType:resourceId:documentId`
|
|
1816
1826
|
*/
|
|
1817
1827
|
getTargetDocumentRef(documentId) {
|
|
1818
|
-
return _getTargetDocumentRef(_classPrivateFieldGet2(_client2$
|
|
1828
|
+
return _getTargetDocumentRef(_classPrivateFieldGet2(_client2$7, this), documentId);
|
|
1819
1829
|
}
|
|
1820
1830
|
/**
|
|
1821
1831
|
* Fetch comments on the configured resource.
|
|
@@ -1834,8 +1844,824 @@ var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */
|
|
|
1834
1844
|
* @param options - Optional request options
|
|
1835
1845
|
*/
|
|
1836
1846
|
fetch(query, params, options) {
|
|
1837
|
-
return lastValueFrom(_fetch(_classPrivateFieldGet2(_client2$
|
|
1847
|
+
return lastValueFrom(_fetch$1(_classPrivateFieldGet2(_client2$7, this), _classPrivateFieldGet2(_httpRequest2$8, this), query, params, options));
|
|
1848
|
+
}
|
|
1849
|
+
listen(query, params, options) {
|
|
1850
|
+
return _listen$1(_classPrivateFieldGet2(_client2$7, this), query, params, options);
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
/** @internal */
|
|
1854
|
+
function _organizationId(client) {
|
|
1855
|
+
let organizationId = client.config().context?.organizationId;
|
|
1856
|
+
if (!organizationId) throw Error("`context.organizationId` must be configured to query Context documents");
|
|
1857
|
+
return organizationId;
|
|
1858
|
+
}
|
|
1859
|
+
function storeUrl(client, suffix) {
|
|
1860
|
+
return `/context/organizations/${encodeURIComponent(_organizationId(client))}/${suffix}`;
|
|
1861
|
+
}
|
|
1862
|
+
/** @internal */
|
|
1863
|
+
function _fetch(client, httpRequest, query, params, options) {
|
|
1864
|
+
let url = storeUrl(client, "query");
|
|
1865
|
+
return _requestObservable(client, httpRequest, {
|
|
1866
|
+
...encodeQueryString({
|
|
1867
|
+
query,
|
|
1868
|
+
params
|
|
1869
|
+
}).length < 11264 ? {
|
|
1870
|
+
method: "GET",
|
|
1871
|
+
url: `${url}${encodeQueryString({
|
|
1872
|
+
query,
|
|
1873
|
+
params
|
|
1874
|
+
})}`
|
|
1875
|
+
} : {
|
|
1876
|
+
method: "POST",
|
|
1877
|
+
url,
|
|
1878
|
+
body: {
|
|
1879
|
+
query,
|
|
1880
|
+
params: params ?? {}
|
|
1881
|
+
}
|
|
1882
|
+
},
|
|
1883
|
+
...pick(options || {}, possibleStoreRequestOptions)
|
|
1884
|
+
}).pipe(map$1((response) => response.result));
|
|
1885
|
+
}
|
|
1886
|
+
/** @internal */
|
|
1887
|
+
function _listen(client, query, params, options) {
|
|
1888
|
+
let opts = options ?? {}, { requestTagPrefix } = client.config(), tag = opts.tag && requestTagPrefix ? [requestTagPrefix, opts.tag].join(".") : opts.tag, listenOpts = pick({
|
|
1889
|
+
...defaults_default(opts, defaultOptions),
|
|
1890
|
+
tag
|
|
1891
|
+
}, possibleOptions), qs = encodeQueryString({
|
|
1892
|
+
query,
|
|
1893
|
+
params,
|
|
1894
|
+
options: listenOpts
|
|
1895
|
+
}), uri = `${client.getUrl(storeUrl(client, "listen"))}${qs}`;
|
|
1896
|
+
return uri.length > 14800 ? throwError(() => /* @__PURE__ */ Error("Query too large for listener")) : _connectListenEventSource(client, uri, opts.events ? opts.events : ["mutation"]);
|
|
1897
|
+
}
|
|
1898
|
+
const ENTRY_TYPE = "sanity.context.entry", ISSUE_TYPE = "sanity.context.issue", MCP_TYPE = "sanity.context.mcp";
|
|
1899
|
+
function _one(client, httpRequest, query, params, options) {
|
|
1900
|
+
return lastValueFrom(_fetch(client, httpRequest, query, params, options));
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* Drain every page of a `(_createdAt, _id)`-keyset read. Termination keys on
|
|
1904
|
+
* the raw page length before anything looks at the rows: a short page means
|
|
1905
|
+
* the store had nothing more to give, and filtering must never shorten a
|
|
1906
|
+
* full page into a false stop.
|
|
1907
|
+
*/
|
|
1908
|
+
async function _drainByCreatedAt(client, httpRequest, filter, params, options) {
|
|
1909
|
+
let all = [], cursor;
|
|
1910
|
+
for (;;) {
|
|
1911
|
+
let query = `*[${cursor ? `${filter} && (_createdAt > \$c || (_createdAt == \$c && _id > \$i))` : filter}] | order(_createdAt asc, _id asc) [0...200]`, page = await lastValueFrom(_fetch(client, httpRequest, query, cursor ? {
|
|
1912
|
+
...params,
|
|
1913
|
+
...cursor
|
|
1914
|
+
} : params, options));
|
|
1915
|
+
if (all.push(...page), page.length < 200) return all;
|
|
1916
|
+
let last = page[page.length - 1];
|
|
1917
|
+
cursor = {
|
|
1918
|
+
c: last._createdAt,
|
|
1919
|
+
i: last._id
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
/** @internal */
|
|
1924
|
+
function _readEntry(client, httpRequest, knowledgeBaseId, path, options) {
|
|
1925
|
+
return _one(client, httpRequest, `*[_type == "${ENTRY_TYPE}" && knowledgeBaseId == $kb && path == $path][0]`, {
|
|
1926
|
+
kb: knowledgeBaseId,
|
|
1927
|
+
path
|
|
1928
|
+
}, options);
|
|
1929
|
+
}
|
|
1930
|
+
/** @internal */
|
|
1931
|
+
async function _listEntries(client, httpRequest, knowledgeBaseId, options) {
|
|
1932
|
+
let all = [], after = "";
|
|
1933
|
+
for (;;) {
|
|
1934
|
+
let page = await lastValueFrom(_fetch(client, httpRequest, `*[_type == "${ENTRY_TYPE}" && knowledgeBaseId == $kb && path > $after] | order(path asc) [0...200] {_id, path, title, tldr, status}`, {
|
|
1935
|
+
kb: knowledgeBaseId,
|
|
1936
|
+
after
|
|
1937
|
+
}, options));
|
|
1938
|
+
if (all.push(...page), page.length < 200) return all;
|
|
1939
|
+
after = page[page.length - 1].path;
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
/** @internal */
|
|
1943
|
+
function _listIssues(client, httpRequest, knowledgeBaseId, status, options) {
|
|
1944
|
+
return _drainByCreatedAt(client, httpRequest, `_type == "${ISSUE_TYPE}" && knowledgeBaseId == $kb${status === void 0 ? "" : " && status == $status"}`, status === void 0 ? { kb: knowledgeBaseId } : {
|
|
1945
|
+
kb: knowledgeBaseId,
|
|
1946
|
+
status
|
|
1947
|
+
}, options);
|
|
1948
|
+
}
|
|
1949
|
+
/** @internal */
|
|
1950
|
+
function _readIssue(client, httpRequest, knowledgeBaseId, issueId, options) {
|
|
1951
|
+
return _one(client, httpRequest, `*[_type == "${ISSUE_TYPE}" && knowledgeBaseId == $kb && _id == $id][0]`, {
|
|
1952
|
+
kb: knowledgeBaseId,
|
|
1953
|
+
id: issueId
|
|
1954
|
+
}, options);
|
|
1955
|
+
}
|
|
1956
|
+
/** @internal */
|
|
1957
|
+
function _listInstructions(client, httpRequest, knowledgeBaseId, options) {
|
|
1958
|
+
return _drainByCreatedAt(client, httpRequest, "_type == \"sanity.context.instruction\" && knowledgeBaseId == $kb && schemaVersion == 1", { kb: knowledgeBaseId }, options);
|
|
1959
|
+
}
|
|
1960
|
+
/** @internal */
|
|
1961
|
+
function _listMcpEndpoints(client, httpRequest, options) {
|
|
1962
|
+
return lastValueFrom(_fetch(client, httpRequest, `*[_type == "${MCP_TYPE}" && organizationId == $org] | order(_createdAt asc, _id asc) [0...500]`, { org: _organizationId(client) }, options));
|
|
1963
|
+
}
|
|
1964
|
+
/** @internal */
|
|
1965
|
+
function _readMcpEndpoint(client, httpRequest, name, options) {
|
|
1966
|
+
return _one(client, httpRequest, `*[_type == "${MCP_TYPE}" && organizationId == $org && name == $name][0]`, {
|
|
1967
|
+
org: _organizationId(client),
|
|
1968
|
+
name
|
|
1969
|
+
}, options);
|
|
1970
|
+
}
|
|
1971
|
+
/** @internal */
|
|
1972
|
+
function _readConversation(client, httpRequest, threadId, options) {
|
|
1973
|
+
return _one(client, httpRequest, "*[_type == \"sanity.context.conversation\" && organizationId == $org && threadId == $threadId][0]", {
|
|
1974
|
+
org: _organizationId(client),
|
|
1975
|
+
threadId
|
|
1976
|
+
}, options);
|
|
1977
|
+
}
|
|
1978
|
+
function _classPrivateMethodInitSpec(e, a) {
|
|
1979
|
+
_checkPrivateRedeclaration(e, a), a.add(e);
|
|
1980
|
+
}
|
|
1981
|
+
const COLLECTION_URL = "/context/knowledge-bases";
|
|
1982
|
+
/**
|
|
1983
|
+
* The knowledge base every scoped method operates on comes from the client's
|
|
1984
|
+
* `resource` configuration, matching how media libraries and canvases are
|
|
1985
|
+
* addressed. Resolved per call so `withConfig` clones behave.
|
|
1986
|
+
*/
|
|
1987
|
+
function _resolveKnowledgeBaseId(client) {
|
|
1988
|
+
let resource = client.config().resource;
|
|
1989
|
+
if (resource?.type !== "knowledge-base") throw Error("`resource` of type `knowledge-base` must be configured to use knowledge-base methods");
|
|
1990
|
+
return resource.id;
|
|
1991
|
+
}
|
|
1992
|
+
function _knowledgeBaseUrl(knowledgeBaseId, suffix = "") {
|
|
1993
|
+
return `${COLLECTION_URL}/${encodeURIComponent(knowledgeBaseId)}${suffix}`;
|
|
1994
|
+
}
|
|
1995
|
+
/** Serialize defined values into query params, dropping the undefined ones. */
|
|
1996
|
+
function _conversationUrl(client, threadId) {
|
|
1997
|
+
let organizationId = client.config().context?.organizationId;
|
|
1998
|
+
if (!organizationId) throw Error("`context.organizationId` must be configured to record conversations");
|
|
1999
|
+
if (!threadId) throw Error("`threadId` must be provided");
|
|
2000
|
+
return `/context/organizations/${encodeURIComponent(organizationId)}/conversations/${encodeURIComponent(threadId)}`;
|
|
2001
|
+
}
|
|
2002
|
+
function _query(entries) {
|
|
2003
|
+
return Object.fromEntries(Object.entries(entries).flatMap(([key, value]) => value === void 0 ? [] : [[key, `${value}`]]));
|
|
2004
|
+
}
|
|
2005
|
+
function _fetchBody(file) {
|
|
2006
|
+
return ArrayBuffer.isView(file) ? file.buffer instanceof ArrayBuffer ? new Uint8Array(file.buffer, file.byteOffset, file.byteLength) : Uint8Array.from(file) : file;
|
|
2007
|
+
}
|
|
2008
|
+
var _client$7 = /* @__PURE__ */ new WeakMap(), _httpRequest$7 = /* @__PURE__ */ new WeakMap(), _ContextClient_brand = /* @__PURE__ */ new WeakSet(), ContextClient = class {
|
|
2009
|
+
constructor(client, httpRequest) {
|
|
2010
|
+
_classPrivateMethodInitSpec(this, _ContextClient_brand), _classPrivateFieldInitSpec(this, _client$7, void 0), _classPrivateFieldInitSpec(this, _httpRequest$7, void 0), _defineProperty(
|
|
2011
|
+
this,
|
|
2012
|
+
/** The knowledge base collection: management addressed per call. */
|
|
2013
|
+
"knowledgeBases",
|
|
2014
|
+
{
|
|
2015
|
+
/** Create a knowledge base. Requires the org-level knowledge-base create grant. */
|
|
2016
|
+
create: (params, options) => _request(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), {
|
|
2017
|
+
url: COLLECTION_URL,
|
|
2018
|
+
method: "POST",
|
|
2019
|
+
body: params,
|
|
2020
|
+
...options
|
|
2021
|
+
}),
|
|
2022
|
+
/** List the organization's knowledge bases. */
|
|
2023
|
+
list: (params) => _request(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), {
|
|
2024
|
+
url: COLLECTION_URL,
|
|
2025
|
+
query: _query({
|
|
2026
|
+
organizationId: params.organizationId,
|
|
2027
|
+
cursor: params.cursor,
|
|
2028
|
+
limit: params.limit
|
|
2029
|
+
}),
|
|
2030
|
+
signal: params.signal,
|
|
2031
|
+
tag: params.tag
|
|
2032
|
+
}),
|
|
2033
|
+
/** Fetch a knowledge base by its id. */
|
|
2034
|
+
get: (knowledgeBaseId, options) => _request(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), {
|
|
2035
|
+
url: _knowledgeBaseUrl(knowledgeBaseId),
|
|
2036
|
+
...options
|
|
2037
|
+
}),
|
|
2038
|
+
/** Edit a knowledge base's configuration. */
|
|
2039
|
+
edit: (knowledgeBaseId, params, options) => _request(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), {
|
|
2040
|
+
url: _knowledgeBaseUrl(knowledgeBaseId),
|
|
2041
|
+
method: "PATCH",
|
|
2042
|
+
body: params,
|
|
2043
|
+
...options
|
|
2044
|
+
}),
|
|
2045
|
+
/** Delete a knowledge base and its generated content. */
|
|
2046
|
+
delete: async (knowledgeBaseId, options) => {
|
|
2047
|
+
await _request(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), {
|
|
2048
|
+
url: _knowledgeBaseUrl(knowledgeBaseId),
|
|
2049
|
+
method: "DELETE",
|
|
2050
|
+
...options
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
), _defineProperty(
|
|
2055
|
+
this,
|
|
2056
|
+
/**
|
|
2057
|
+
* Conversation telemetry. `threadId` identifies the conversation within
|
|
2058
|
+
* the organization — reuse means the same conversation. Beyond the canned
|
|
2059
|
+
* `get`, reads go through {@link fetch} and {@link listen} with GROQ
|
|
2060
|
+
* (`_type == "sanity.context.conversation"`).
|
|
2061
|
+
*
|
|
2062
|
+
* Requires `context.organizationId` in the client configuration.
|
|
2063
|
+
*/
|
|
2064
|
+
"conversations",
|
|
2065
|
+
{
|
|
2066
|
+
/**
|
|
2067
|
+
* Record a conversation. Messages replace the stored transcript
|
|
2068
|
+
* wholesale; `metadata` and model fields only overwrite when present.
|
|
2069
|
+
* Last write per thread wins — retries are safe.
|
|
2070
|
+
*/
|
|
2071
|
+
save: (params, options) => {
|
|
2072
|
+
let { threadId, ...body } = params;
|
|
2073
|
+
return _request(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), {
|
|
2074
|
+
url: _conversationUrl(_classPrivateFieldGet2(_client$7, this), threadId),
|
|
2075
|
+
method: "PUT",
|
|
2076
|
+
body,
|
|
2077
|
+
...options
|
|
2078
|
+
});
|
|
2079
|
+
},
|
|
2080
|
+
/**
|
|
2081
|
+
* Record the classification your own model produced for one thread:
|
|
2082
|
+
* exactly one of `coreMetrics` (a verdict) or `classificationError`
|
|
2083
|
+
* (why classification failed).
|
|
2084
|
+
*/
|
|
2085
|
+
classify: (params, options) => {
|
|
2086
|
+
let { threadId, ...body } = params;
|
|
2087
|
+
return _request(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), {
|
|
2088
|
+
url: _conversationUrl(_classPrivateFieldGet2(_client$7, this), threadId),
|
|
2089
|
+
method: "PATCH",
|
|
2090
|
+
body,
|
|
2091
|
+
...options
|
|
2092
|
+
});
|
|
2093
|
+
},
|
|
2094
|
+
/**
|
|
2095
|
+
* One recorded conversation by its thread id, or `null` when the thread
|
|
2096
|
+
* was never recorded. Runs:
|
|
2097
|
+
*
|
|
2098
|
+
* `*[_type == "sanity.context.conversation" && organizationId == $org && threadId == $threadId][0]`
|
|
2099
|
+
*
|
|
2100
|
+
* For anything more, use {@link fetch}.
|
|
2101
|
+
*/
|
|
2102
|
+
get: (params, options) => _readConversation(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), params.threadId, options)
|
|
2103
|
+
}
|
|
2104
|
+
), _defineProperty(
|
|
2105
|
+
this,
|
|
2106
|
+
/** Imports: feed content into the configured knowledge base. */
|
|
2107
|
+
"imports",
|
|
2108
|
+
{
|
|
2109
|
+
/**
|
|
2110
|
+
* Import content. One entry point, discriminated on `type`: inline
|
|
2111
|
+
* `text`, a website `crawl`, a Sanity `dataset` bind, or a `file`
|
|
2112
|
+
* upload. Processing queues automatically. The file variant stages the
|
|
2113
|
+
* upload, PUTs the bytes to a signed storage URL, and confirms; the
|
|
2114
|
+
* bytes never pass through the Context API.
|
|
2115
|
+
*/
|
|
2116
|
+
create: (params, options) => params.type === "file" ? _assertClassBrand(_ContextClient_brand, this, _uploadFile).call(this, params, options) : _assertClassBrand(_ContextClient_brand, this, _request2).call(this, "/imports", {
|
|
2117
|
+
method: "POST",
|
|
2118
|
+
body: params,
|
|
2119
|
+
...options
|
|
2120
|
+
}),
|
|
2121
|
+
list: (params) => _assertClassBrand(_ContextClient_brand, this, _list).call(this, "/imports", params),
|
|
2122
|
+
get: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/imports/${encodeURIComponent(params.importId)}`, options),
|
|
2123
|
+
/** A short-lived signed URL for the original uploaded bytes. */
|
|
2124
|
+
download: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/imports/${encodeURIComponent(params.importId)}/download`, options),
|
|
2125
|
+
delete: async (params, options) => {
|
|
2126
|
+
await _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/imports/${encodeURIComponent(params.importId)}`, {
|
|
2127
|
+
method: "DELETE",
|
|
2128
|
+
...options
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
), _defineProperty(
|
|
2133
|
+
this,
|
|
2134
|
+
/** Jobs: poll async work (builds, imports) to a terminal state. */
|
|
2135
|
+
"jobs",
|
|
2136
|
+
{ get: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/jobs/${encodeURIComponent(params.jobId)}`, options) }
|
|
2137
|
+
), _defineProperty(
|
|
2138
|
+
this,
|
|
2139
|
+
/**
|
|
2140
|
+
* Issues: findings from builds awaiting triage. Reads are canned GROQ
|
|
2141
|
+
* queries against the organization's document store; for anything more,
|
|
2142
|
+
* use {@link fetch}. Reads require `context.organizationId` alongside the
|
|
2143
|
+
* knowledge-base `resource` in the client configuration.
|
|
2144
|
+
*/
|
|
2145
|
+
"issues",
|
|
2146
|
+
{
|
|
2147
|
+
/**
|
|
2148
|
+
* Every issue on the knowledge base, oldest first, optionally narrowed
|
|
2149
|
+
* to one status. Drains keyset pages internally and resolves with the
|
|
2150
|
+
* complete set. Runs:
|
|
2151
|
+
*
|
|
2152
|
+
* `*[_type == "sanity.context.issue" && knowledgeBaseId == $kb && status == $status] | order(_createdAt asc, _id asc)`
|
|
2153
|
+
*
|
|
2154
|
+
* (the status clause only when given). For anything more, use {@link fetch}.
|
|
2155
|
+
*/
|
|
2156
|
+
list: (params, options) => _listIssues(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client$7, this)), params?.status, options),
|
|
2157
|
+
/**
|
|
2158
|
+
* One issue by its document id, or `null` when it does not exist. Runs:
|
|
2159
|
+
*
|
|
2160
|
+
* `*[_type == "sanity.context.issue" && knowledgeBaseId == $kb && _id == $id][0]`
|
|
2161
|
+
*
|
|
2162
|
+
* For anything more, use {@link fetch}.
|
|
2163
|
+
*/
|
|
2164
|
+
get: (params, options) => _readIssue(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client$7, this)), params.issueId, options),
|
|
2165
|
+
/** Resolve a conflict issue. Mints the standing instruction, same as the dashboard. */
|
|
2166
|
+
resolve: (params, options) => {
|
|
2167
|
+
let { issueId, ...body } = params;
|
|
2168
|
+
return _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/issues/${encodeURIComponent(issueId)}/resolve`, {
|
|
2169
|
+
method: "POST",
|
|
2170
|
+
body,
|
|
2171
|
+
...options
|
|
2172
|
+
});
|
|
2173
|
+
},
|
|
2174
|
+
dismiss: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/issues/${encodeURIComponent(params.issueId)}/dismiss`, {
|
|
2175
|
+
method: "POST",
|
|
2176
|
+
...options
|
|
2177
|
+
}),
|
|
2178
|
+
reopen: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/issues/${encodeURIComponent(params.issueId)}/reopen`, {
|
|
2179
|
+
method: "POST",
|
|
2180
|
+
...options
|
|
2181
|
+
}),
|
|
2182
|
+
/** Apply already-accepted issues to the knowledge base in one batch. */
|
|
2183
|
+
apply: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, "/issues/apply", {
|
|
2184
|
+
method: "POST",
|
|
2185
|
+
body: params,
|
|
2186
|
+
...options
|
|
2187
|
+
})
|
|
2188
|
+
}
|
|
2189
|
+
), _defineProperty(
|
|
2190
|
+
this,
|
|
2191
|
+
/** Instructions: standing decisions that steer every build. */
|
|
2192
|
+
"instructions",
|
|
2193
|
+
{
|
|
2194
|
+
create: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, "/instructions", {
|
|
2195
|
+
method: "POST",
|
|
2196
|
+
body: params,
|
|
2197
|
+
...options
|
|
2198
|
+
}),
|
|
2199
|
+
/**
|
|
2200
|
+
* Every current-schema instruction on the knowledge base, oldest first.
|
|
2201
|
+
* Drains keyset pages internally and resolves with the complete set.
|
|
2202
|
+
* Runs:
|
|
2203
|
+
*
|
|
2204
|
+
* `*[_type == "sanity.context.instruction" && knowledgeBaseId == $kb && schemaVersion == 1] | order(_createdAt asc, _id asc)`
|
|
2205
|
+
*
|
|
2206
|
+
* For anything more, use {@link fetch}. Requires `context.organizationId`
|
|
2207
|
+
* alongside the knowledge-base `resource` in the client configuration.
|
|
2208
|
+
*/
|
|
2209
|
+
list: (options) => _listInstructions(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client$7, this)), options),
|
|
2210
|
+
edit: (params, options) => {
|
|
2211
|
+
let { instructionId, ...body } = params;
|
|
2212
|
+
return _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/instructions/${encodeURIComponent(instructionId)}`, {
|
|
2213
|
+
method: "PATCH",
|
|
2214
|
+
body,
|
|
2215
|
+
...options
|
|
2216
|
+
});
|
|
2217
|
+
},
|
|
2218
|
+
delete: async (params, options) => {
|
|
2219
|
+
await _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/instructions/${encodeURIComponent(params.instructionId)}`, {
|
|
2220
|
+
method: "DELETE",
|
|
2221
|
+
...options
|
|
2222
|
+
});
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
), _defineProperty(
|
|
2226
|
+
this,
|
|
2227
|
+
/**
|
|
2228
|
+
* Entries: the built outline, one entry per node. Reads are canned GROQ
|
|
2229
|
+
* queries against the organization's document store; for anything more,
|
|
2230
|
+
* use {@link fetch}. Requires `context.organizationId` alongside the
|
|
2231
|
+
* knowledge-base `resource` in the client configuration.
|
|
2232
|
+
*/
|
|
2233
|
+
"entries",
|
|
2234
|
+
{
|
|
2235
|
+
/**
|
|
2236
|
+
* Every entry, path-ordered, as a metadata view (`_id`, `path`,
|
|
2237
|
+
* `title`, `tldr`, `status`) with bodies excluded. Drains keyset pages
|
|
2238
|
+
* internally and resolves with the complete set. Runs:
|
|
2239
|
+
*
|
|
2240
|
+
* `*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path > $after] | order(path asc) [0...200] {_id, path, title, tldr, status}`
|
|
2241
|
+
*
|
|
2242
|
+
* For bodies, use `entries.get` or {@link fetch}.
|
|
2243
|
+
*/
|
|
2244
|
+
list: (options) => _listEntries(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client$7, this)), options),
|
|
2245
|
+
/**
|
|
2246
|
+
* One entry with its full body and citations, by outline path (e.g.
|
|
2247
|
+
* `billing/refunds`), or `null` when no entry sits at that path. Runs:
|
|
2248
|
+
*
|
|
2249
|
+
* `*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path == $path][0]`
|
|
2250
|
+
*
|
|
2251
|
+
* For anything more, use {@link fetch}.
|
|
2252
|
+
*/
|
|
2253
|
+
get: (params, options) => _readEntry(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client$7, this)), params.path, options),
|
|
2254
|
+
/**
|
|
2255
|
+
* Rebuild one entry from its already-placed sources, by outline path.
|
|
2256
|
+
* Poll the returned job with {@link jobs}; `affectedEntries` lists every
|
|
2257
|
+
* entry the rebuild touches.
|
|
2258
|
+
*/
|
|
2259
|
+
rebuild: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/entries/${encodeURIComponent(params.path)}/rebuild`, {
|
|
2260
|
+
method: "POST",
|
|
2261
|
+
...options
|
|
2262
|
+
})
|
|
2263
|
+
}
|
|
2264
|
+
), _defineProperty(
|
|
2265
|
+
this,
|
|
2266
|
+
/**
|
|
2267
|
+
* MCP endpoint configurations, org-owned documents read with canned GROQ
|
|
2268
|
+
* queries. Requires `context.organizationId` in the client configuration.
|
|
2269
|
+
*/
|
|
2270
|
+
"mcpEndpoints",
|
|
2271
|
+
{
|
|
2272
|
+
/**
|
|
2273
|
+
* The organization's MCP endpoint configurations, oldest first. Runs:
|
|
2274
|
+
*
|
|
2275
|
+
* `*[_type == "sanity.context.mcp" && organizationId == $org] | order(_createdAt asc, _id asc) [0...500]`
|
|
2276
|
+
*
|
|
2277
|
+
* For anything more, use {@link fetch}.
|
|
2278
|
+
*/
|
|
2279
|
+
list: (options) => _listMcpEndpoints(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), options),
|
|
2280
|
+
/**
|
|
2281
|
+
* One MCP endpoint configuration by its URL name, or `null` when none
|
|
2282
|
+
* carries that name. Runs:
|
|
2283
|
+
*
|
|
2284
|
+
* `*[_type == "sanity.context.mcp" && organizationId == $org && name == $name][0]`
|
|
2285
|
+
*
|
|
2286
|
+
* For anything more, use {@link fetch}.
|
|
2287
|
+
*/
|
|
2288
|
+
get: (params, options) => _readMcpEndpoint(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), params.name, options)
|
|
2289
|
+
}
|
|
2290
|
+
), _defineProperty(
|
|
2291
|
+
this,
|
|
2292
|
+
/** Sources: the distilled units builds cite. */
|
|
2293
|
+
"sources",
|
|
2294
|
+
{
|
|
2295
|
+
/**
|
|
2296
|
+
* List sources, optionally filtered by `status` or the `importId` they
|
|
2297
|
+
* came from. `ids` is a lookup mode: it resolves those exact sources
|
|
2298
|
+
* (e.g. from an entry's citations) and overrides `status` and `cursor`.
|
|
2299
|
+
*/
|
|
2300
|
+
list: (params) => _assertClassBrand(_ContextClient_brand, this, _list).call(this, "/sources", params, {
|
|
2301
|
+
status: params?.status,
|
|
2302
|
+
importId: params?.importId,
|
|
2303
|
+
ids: params?.ids?.join(",")
|
|
2304
|
+
}),
|
|
2305
|
+
get: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/sources/${encodeURIComponent(params.sourceId)}`, options),
|
|
2306
|
+
/**
|
|
2307
|
+
* Distilled source content, optionally a line range: the evidence behind
|
|
2308
|
+
* a citation or an issue.
|
|
2309
|
+
*/
|
|
2310
|
+
content: (params, options) => _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/sources/${encodeURIComponent(params.sourceId)}/content`, {
|
|
2311
|
+
query: _query({
|
|
2312
|
+
startLine: params.startLine,
|
|
2313
|
+
endLine: params.endLine
|
|
2314
|
+
}),
|
|
2315
|
+
...options
|
|
2316
|
+
}),
|
|
2317
|
+
delete: async (params, options) => {
|
|
2318
|
+
await _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/sources/${encodeURIComponent(params.sourceId)}`, {
|
|
2319
|
+
method: "DELETE",
|
|
2320
|
+
...options
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
), _classPrivateFieldSet2(_client$7, this, client), _classPrivateFieldSet2(_httpRequest$7, this, httpRequest);
|
|
2325
|
+
}
|
|
2326
|
+
/**
|
|
2327
|
+
* GROQ over the organization's Context documents (conversation telemetry
|
|
2328
|
+
* today; the store holds every Context family and the caller's access
|
|
2329
|
+
* decides what a query returns, so filter on `_type`).
|
|
2330
|
+
*
|
|
2331
|
+
* Requires `context.organizationId` in the client configuration.
|
|
2332
|
+
*/
|
|
2333
|
+
fetch(query, params, options) {
|
|
2334
|
+
return lastValueFrom(_fetch(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), query, params, options));
|
|
2335
|
+
}
|
|
2336
|
+
/**
|
|
2337
|
+
* Listen for changes to the organization's Context documents. Mirrors
|
|
2338
|
+
* `client.listen(query, params, options)` and emits mutation events by
|
|
2339
|
+
* default.
|
|
2340
|
+
*/
|
|
2341
|
+
listen(query, params, options) {
|
|
2342
|
+
return _listen(_classPrivateFieldGet2(_client$7, this), query, params, options);
|
|
2343
|
+
}
|
|
2344
|
+
/**
|
|
2345
|
+
* Build the configured knowledge base. The server waits for pending import
|
|
2346
|
+
* processing before assembling, so importing and building back to back is
|
|
2347
|
+
* safe. Track the returned job with {@link jobs}.
|
|
2348
|
+
*/
|
|
2349
|
+
build(options) {
|
|
2350
|
+
return _assertClassBrand(_ContextClient_brand, this, _request2).call(this, "/build", {
|
|
2351
|
+
method: "POST",
|
|
2352
|
+
...options
|
|
2353
|
+
});
|
|
2354
|
+
}
|
|
2355
|
+
/** Cancel the running build, if any. */
|
|
2356
|
+
cancelBuild(options) {
|
|
2357
|
+
return _assertClassBrand(_ContextClient_brand, this, _request2).call(this, "/build/cancel", {
|
|
2358
|
+
method: "POST",
|
|
2359
|
+
...options
|
|
2360
|
+
});
|
|
2361
|
+
}
|
|
2362
|
+
/** Run an incremental refresh: re-check sources and apply what changed. */
|
|
2363
|
+
refresh(options) {
|
|
2364
|
+
return _assertClassBrand(_ContextClient_brand, this, _request2).call(this, "/refresh", {
|
|
2365
|
+
method: "POST",
|
|
2366
|
+
...options
|
|
2367
|
+
});
|
|
2368
|
+
}
|
|
2369
|
+
};
|
|
2370
|
+
/** Request against the configured knowledge base. */
|
|
2371
|
+
function _request2(suffix, reqOptions = {}) {
|
|
2372
|
+
return _request(_classPrivateFieldGet2(_client$7, this), _classPrivateFieldGet2(_httpRequest$7, this), {
|
|
2373
|
+
url: _knowledgeBaseUrl(_resolveKnowledgeBaseId(_classPrivateFieldGet2(_client$7, this)), suffix),
|
|
2374
|
+
...reqOptions
|
|
2375
|
+
});
|
|
2376
|
+
}
|
|
2377
|
+
/** Shared shape of every paginated list endpoint scoped to the knowledge base. */
|
|
2378
|
+
function _list(suffix, params, extraQuery) {
|
|
2379
|
+
return _assertClassBrand(_ContextClient_brand, this, _request2).call(this, suffix, {
|
|
2380
|
+
query: _query({
|
|
2381
|
+
cursor: params?.cursor,
|
|
2382
|
+
limit: params?.limit,
|
|
2383
|
+
...extraQuery
|
|
2384
|
+
}),
|
|
2385
|
+
signal: params?.signal,
|
|
2386
|
+
tag: params?.tag
|
|
2387
|
+
});
|
|
2388
|
+
}
|
|
2389
|
+
async function _uploadFile(params, options) {
|
|
2390
|
+
let staged = await _assertClassBrand(_ContextClient_brand, this, _request2).call(this, "/imports/uploads", {
|
|
2391
|
+
method: "POST",
|
|
2392
|
+
body: {
|
|
2393
|
+
filename: params.filename,
|
|
2394
|
+
...params.contentType && { contentType: params.contentType }
|
|
2395
|
+
},
|
|
2396
|
+
...options
|
|
2397
|
+
}), config = _classPrivateFieldGet2(_client$7, this).config(), putResponse = await (config.resolveFetch?.(config.proxy) ?? globalThis.fetch)(staged.uploadUrl, {
|
|
2398
|
+
method: "PUT",
|
|
2399
|
+
body: _fetchBody(params.file),
|
|
2400
|
+
...params.contentType && { headers: { "content-type": params.contentType } },
|
|
2401
|
+
signal: options?.signal
|
|
2402
|
+
});
|
|
2403
|
+
if (!putResponse.ok) throw Error(`File upload failed: ${putResponse.status} ${putResponse.statusText}`);
|
|
2404
|
+
return _assertClassBrand(_ContextClient_brand, this, _request2).call(this, `/imports/uploads/${encodeURIComponent(staged.importId)}/complete`, {
|
|
2405
|
+
method: "POST",
|
|
2406
|
+
body: {},
|
|
2407
|
+
...options
|
|
2408
|
+
});
|
|
2409
|
+
}
|
|
2410
|
+
var _client2$6 = /* @__PURE__ */ new WeakMap(), _httpRequest2$7 = /* @__PURE__ */ new WeakMap(), ObservableContextClient = class {
|
|
2411
|
+
constructor(client, httpRequest) {
|
|
2412
|
+
_classPrivateFieldInitSpec(this, _client2$6, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$7, void 0), _defineProperty(
|
|
2413
|
+
this,
|
|
2414
|
+
/** The knowledge base collection: management addressed per call. */
|
|
2415
|
+
"knowledgeBases",
|
|
2416
|
+
{
|
|
2417
|
+
/** Create a knowledge base. Requires the org-level knowledge-base create grant. */
|
|
2418
|
+
create: (params, options) => _observe(options?.signal, (signal) => _request(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), {
|
|
2419
|
+
url: COLLECTION_URL,
|
|
2420
|
+
method: "POST",
|
|
2421
|
+
body: params,
|
|
2422
|
+
tag: options?.tag,
|
|
2423
|
+
signal
|
|
2424
|
+
})),
|
|
2425
|
+
/** List the organization's knowledge bases. */
|
|
2426
|
+
list: (params) => _observe(params.signal, (signal) => _request(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), {
|
|
2427
|
+
url: COLLECTION_URL,
|
|
2428
|
+
query: _query({
|
|
2429
|
+
organizationId: params.organizationId,
|
|
2430
|
+
cursor: params.cursor,
|
|
2431
|
+
limit: params.limit
|
|
2432
|
+
}),
|
|
2433
|
+
tag: params.tag,
|
|
2434
|
+
signal
|
|
2435
|
+
})),
|
|
2436
|
+
/** Fetch a knowledge base by its id. */
|
|
2437
|
+
get: (knowledgeBaseId, options) => _observe(options?.signal, (signal) => _request(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), {
|
|
2438
|
+
url: _knowledgeBaseUrl(knowledgeBaseId),
|
|
2439
|
+
tag: options?.tag,
|
|
2440
|
+
signal
|
|
2441
|
+
})),
|
|
2442
|
+
/** Edit a knowledge base's configuration. */
|
|
2443
|
+
edit: (knowledgeBaseId, params, options) => _observe(options?.signal, (signal) => _request(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), {
|
|
2444
|
+
url: _knowledgeBaseUrl(knowledgeBaseId),
|
|
2445
|
+
method: "PATCH",
|
|
2446
|
+
body: params,
|
|
2447
|
+
tag: options?.tag,
|
|
2448
|
+
signal
|
|
2449
|
+
})),
|
|
2450
|
+
/** Delete a knowledge base and its generated content. */
|
|
2451
|
+
delete: (knowledgeBaseId, options) => _observe(options?.signal, (signal) => _request(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), {
|
|
2452
|
+
url: _knowledgeBaseUrl(knowledgeBaseId),
|
|
2453
|
+
method: "DELETE",
|
|
2454
|
+
tag: options?.tag,
|
|
2455
|
+
signal
|
|
2456
|
+
}))
|
|
2457
|
+
}
|
|
2458
|
+
), _defineProperty(
|
|
2459
|
+
this,
|
|
2460
|
+
/**
|
|
2461
|
+
* Conversation telemetry. `threadId` identifies the conversation within
|
|
2462
|
+
* the organization — reuse means the same conversation. Beyond the canned
|
|
2463
|
+
* `get`, reads go through {@link fetch} and {@link listen} with GROQ
|
|
2464
|
+
* (`_type == "sanity.context.conversation"`).
|
|
2465
|
+
*
|
|
2466
|
+
* Requires `context.organizationId` in the client configuration.
|
|
2467
|
+
*/
|
|
2468
|
+
"conversations",
|
|
2469
|
+
{
|
|
2470
|
+
/**
|
|
2471
|
+
* Record a conversation. Messages replace the stored transcript
|
|
2472
|
+
* wholesale; `metadata` and model fields only overwrite when present.
|
|
2473
|
+
* Last write per thread wins — retries are safe.
|
|
2474
|
+
*/
|
|
2475
|
+
save: (params, options) => {
|
|
2476
|
+
let { threadId, ...body } = params;
|
|
2477
|
+
return _observe(options?.signal, (signal) => _request(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), {
|
|
2478
|
+
url: _conversationUrl(_classPrivateFieldGet2(_client2$6, this), threadId),
|
|
2479
|
+
method: "PUT",
|
|
2480
|
+
body,
|
|
2481
|
+
tag: options?.tag,
|
|
2482
|
+
signal
|
|
2483
|
+
}));
|
|
2484
|
+
},
|
|
2485
|
+
/**
|
|
2486
|
+
* Record the classification your own model produced for one thread:
|
|
2487
|
+
* exactly one of `coreMetrics` (a verdict) or `classificationError`
|
|
2488
|
+
* (why classification failed).
|
|
2489
|
+
*/
|
|
2490
|
+
classify: (params, options) => {
|
|
2491
|
+
let { threadId, ...body } = params;
|
|
2492
|
+
return _observe(options?.signal, (signal) => _request(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), {
|
|
2493
|
+
url: _conversationUrl(_classPrivateFieldGet2(_client2$6, this), threadId),
|
|
2494
|
+
method: "PATCH",
|
|
2495
|
+
body,
|
|
2496
|
+
tag: options?.tag,
|
|
2497
|
+
signal
|
|
2498
|
+
}));
|
|
2499
|
+
},
|
|
2500
|
+
/**
|
|
2501
|
+
* One recorded conversation by its thread id, or `null` when the thread
|
|
2502
|
+
* was never recorded. Runs:
|
|
2503
|
+
*
|
|
2504
|
+
* `*[_type == "sanity.context.conversation" && organizationId == $org && threadId == $threadId][0]`
|
|
2505
|
+
*
|
|
2506
|
+
* For anything more, use {@link fetch}.
|
|
2507
|
+
*/
|
|
2508
|
+
get: (params, options) => _observe(options?.signal, (signal) => _readConversation(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), params.threadId, {
|
|
2509
|
+
...options,
|
|
2510
|
+
signal
|
|
2511
|
+
}))
|
|
2512
|
+
}
|
|
2513
|
+
), _defineProperty(
|
|
2514
|
+
this,
|
|
2515
|
+
/**
|
|
2516
|
+
* Entries: the built outline, one entry per node. Reads are canned GROQ
|
|
2517
|
+
* queries against the organization's document store; for anything more,
|
|
2518
|
+
* use {@link fetch}. Requires `context.organizationId` alongside the
|
|
2519
|
+
* knowledge-base `resource` in the client configuration.
|
|
2520
|
+
*/
|
|
2521
|
+
"entries",
|
|
2522
|
+
{
|
|
2523
|
+
/**
|
|
2524
|
+
* Every entry, path-ordered, as a metadata view (`_id`, `path`,
|
|
2525
|
+
* `title`, `tldr`, `status`) with bodies excluded. Drains keyset pages
|
|
2526
|
+
* internally and emits the complete set. Runs:
|
|
2527
|
+
*
|
|
2528
|
+
* `*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path > $after] | order(path asc) [0...200] {_id, path, title, tldr, status}`
|
|
2529
|
+
*
|
|
2530
|
+
* For bodies, use `entries.get` or {@link fetch}.
|
|
2531
|
+
*/
|
|
2532
|
+
list: (options) => _observe(options?.signal, (signal) => _listEntries(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client2$6, this)), {
|
|
2533
|
+
...options,
|
|
2534
|
+
signal
|
|
2535
|
+
})),
|
|
2536
|
+
/**
|
|
2537
|
+
* One entry with its full body and citations, by outline path (e.g.
|
|
2538
|
+
* `billing/refunds`), or `null` when no entry sits at that path. Runs:
|
|
2539
|
+
*
|
|
2540
|
+
* `*[_type == "sanity.context.entry" && knowledgeBaseId == $kb && path == $path][0]`
|
|
2541
|
+
*
|
|
2542
|
+
* For anything more, use {@link fetch}.
|
|
2543
|
+
*/
|
|
2544
|
+
get: (params, options) => _observe(options?.signal, (signal) => _readEntry(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client2$6, this)), params.path, {
|
|
2545
|
+
...options,
|
|
2546
|
+
signal
|
|
2547
|
+
})),
|
|
2548
|
+
/**
|
|
2549
|
+
* Rebuild one entry from its already-placed sources, by outline path.
|
|
2550
|
+
* Poll the returned job with the promise client's `jobs`;
|
|
2551
|
+
* `affectedEntries` lists every entry the rebuild touches.
|
|
2552
|
+
*/
|
|
2553
|
+
rebuild: (params, options) => _observe(options?.signal, (signal) => _request(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), {
|
|
2554
|
+
url: _knowledgeBaseUrl(_resolveKnowledgeBaseId(_classPrivateFieldGet2(_client2$6, this)), `/entries/${encodeURIComponent(params.path)}/rebuild`),
|
|
2555
|
+
method: "POST",
|
|
2556
|
+
tag: options?.tag,
|
|
2557
|
+
signal
|
|
2558
|
+
}))
|
|
2559
|
+
}
|
|
2560
|
+
), _defineProperty(
|
|
2561
|
+
this,
|
|
2562
|
+
/**
|
|
2563
|
+
* Issues: findings from builds awaiting triage. Reads are canned GROQ
|
|
2564
|
+
* queries against the organization's document store; for anything more,
|
|
2565
|
+
* use {@link fetch}. Requires `context.organizationId` alongside the
|
|
2566
|
+
* knowledge-base `resource` in the client configuration.
|
|
2567
|
+
*/
|
|
2568
|
+
"issues",
|
|
2569
|
+
{
|
|
2570
|
+
/**
|
|
2571
|
+
* Every issue on the knowledge base, oldest first, optionally narrowed
|
|
2572
|
+
* to one status. Drains keyset pages internally and emits the complete
|
|
2573
|
+
* set. Runs:
|
|
2574
|
+
*
|
|
2575
|
+
* `*[_type == "sanity.context.issue" && knowledgeBaseId == $kb && status == $status] | order(_createdAt asc, _id asc)`
|
|
2576
|
+
*
|
|
2577
|
+
* (the status clause only when given). For anything more, use {@link fetch}.
|
|
2578
|
+
*/
|
|
2579
|
+
list: (params, options) => _observe(options?.signal, (signal) => _listIssues(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client2$6, this)), params?.status, {
|
|
2580
|
+
...options,
|
|
2581
|
+
signal
|
|
2582
|
+
})),
|
|
2583
|
+
/**
|
|
2584
|
+
* One issue by its document id, or `null` when it does not exist. Runs:
|
|
2585
|
+
*
|
|
2586
|
+
* `*[_type == "sanity.context.issue" && knowledgeBaseId == $kb && _id == $id][0]`
|
|
2587
|
+
*
|
|
2588
|
+
* For anything more, use {@link fetch}.
|
|
2589
|
+
*/
|
|
2590
|
+
get: (params, options) => _observe(options?.signal, (signal) => _readIssue(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client2$6, this)), params.issueId, {
|
|
2591
|
+
...options,
|
|
2592
|
+
signal
|
|
2593
|
+
}))
|
|
2594
|
+
}
|
|
2595
|
+
), _defineProperty(
|
|
2596
|
+
this,
|
|
2597
|
+
/**
|
|
2598
|
+
* Instructions: standing decisions that steer every build. The canned
|
|
2599
|
+
* GROQ read; writes are promise-based on `client.context`.
|
|
2600
|
+
*/
|
|
2601
|
+
"instructions",
|
|
2602
|
+
{
|
|
2603
|
+
/**
|
|
2604
|
+
* Every current-schema instruction on the knowledge base, oldest first.
|
|
2605
|
+
* Drains keyset pages internally and emits the complete set. Runs:
|
|
2606
|
+
*
|
|
2607
|
+
* `*[_type == "sanity.context.instruction" && knowledgeBaseId == $kb && schemaVersion == 1] | order(_createdAt asc, _id asc)`
|
|
2608
|
+
*
|
|
2609
|
+
* For anything more, use {@link fetch}. Requires `context.organizationId`
|
|
2610
|
+
* alongside the knowledge-base `resource` in the client configuration.
|
|
2611
|
+
*/
|
|
2612
|
+
list: (options) => _observe(options?.signal, (signal) => _listInstructions(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), _resolveKnowledgeBaseId(_classPrivateFieldGet2(_client2$6, this)), {
|
|
2613
|
+
...options,
|
|
2614
|
+
signal
|
|
2615
|
+
})) }
|
|
2616
|
+
), _defineProperty(
|
|
2617
|
+
this,
|
|
2618
|
+
/**
|
|
2619
|
+
* MCP endpoint configurations, org-owned documents read with canned GROQ
|
|
2620
|
+
* queries. Requires `context.organizationId` in the client configuration.
|
|
2621
|
+
*/
|
|
2622
|
+
"mcpEndpoints",
|
|
2623
|
+
{
|
|
2624
|
+
/**
|
|
2625
|
+
* The organization's MCP endpoint configurations, oldest first. Runs:
|
|
2626
|
+
*
|
|
2627
|
+
* `*[_type == "sanity.context.mcp" && organizationId == $org] | order(_createdAt asc, _id asc) [0...500]`
|
|
2628
|
+
*
|
|
2629
|
+
* For anything more, use {@link fetch}.
|
|
2630
|
+
*/
|
|
2631
|
+
list: (options) => _observe(options?.signal, (signal) => _listMcpEndpoints(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), {
|
|
2632
|
+
...options,
|
|
2633
|
+
signal
|
|
2634
|
+
})),
|
|
2635
|
+
/**
|
|
2636
|
+
* One MCP endpoint configuration by its URL name, or `null` when none
|
|
2637
|
+
* carries that name. Runs:
|
|
2638
|
+
*
|
|
2639
|
+
* `*[_type == "sanity.context.mcp" && organizationId == $org && name == $name][0]`
|
|
2640
|
+
*
|
|
2641
|
+
* For anything more, use {@link fetch}.
|
|
2642
|
+
*/
|
|
2643
|
+
get: (params, options) => _observe(options?.signal, (signal) => _readMcpEndpoint(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), params.name, {
|
|
2644
|
+
...options,
|
|
2645
|
+
signal
|
|
2646
|
+
}))
|
|
2647
|
+
}
|
|
2648
|
+
), _classPrivateFieldSet2(_client2$6, this, client), _classPrivateFieldSet2(_httpRequest2$7, this, httpRequest);
|
|
2649
|
+
}
|
|
2650
|
+
/**
|
|
2651
|
+
* GROQ over the organization's Context documents (conversation telemetry
|
|
2652
|
+
* today; the store holds every Context family and the caller's access
|
|
2653
|
+
* decides what a query returns, so filter on `_type`).
|
|
2654
|
+
*
|
|
2655
|
+
* Requires `context.organizationId` in the client configuration.
|
|
2656
|
+
*/
|
|
2657
|
+
fetch(query, params, options) {
|
|
2658
|
+
return _fetch(_classPrivateFieldGet2(_client2$6, this), _classPrivateFieldGet2(_httpRequest2$7, this), query, params, options);
|
|
1838
2659
|
}
|
|
2660
|
+
/**
|
|
2661
|
+
* Listen for changes to the organization's Context documents. Mirrors
|
|
2662
|
+
* `client.listen(query, params, options)` and emits mutation events by
|
|
2663
|
+
* default.
|
|
2664
|
+
*/
|
|
1839
2665
|
listen(query, params, options) {
|
|
1840
2666
|
return _listen(_classPrivateFieldGet2(_client2$6, this), query, params, options);
|
|
1841
2667
|
}
|
|
@@ -2142,7 +2968,11 @@ function _modify(client, httpRequest, method, name, options) {
|
|
|
2142
2968
|
});
|
|
2143
2969
|
}
|
|
2144
2970
|
/** Function resource types in a blueprint are namespaced under this prefix. */
|
|
2145
|
-
const
|
|
2971
|
+
const SYNC_INVOCABLE_FUNCTION_TYPES = ["sanity.function.pubsub"], ASYNC_INVOCABLE_FUNCTION_TYPES = [
|
|
2972
|
+
"sanity.function.durable",
|
|
2973
|
+
"sanity.function.pubsub",
|
|
2974
|
+
"sanity.function.queue"
|
|
2975
|
+
], INVOCABLE_FUNCTION_TYPES = [.../* @__PURE__ */ new Set([...SYNC_INVOCABLE_FUNCTION_TYPES, ...ASYNC_INVOCABLE_FUNCTION_TYPES])], scopeHeaders = (config, request) => {
|
|
2146
2976
|
let organizationId = request?.organizationId || config.organizationId;
|
|
2147
2977
|
if (organizationId) return {
|
|
2148
2978
|
"X-Sanity-Scope-Type": "organization",
|
|
@@ -2166,7 +2996,7 @@ const scopeHeaders = (config, request) => {
|
|
|
2166
2996
|
*
|
|
2167
2997
|
* @internal
|
|
2168
2998
|
*/
|
|
2169
|
-
function _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request) {
|
|
2999
|
+
function _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request, sync) {
|
|
2170
3000
|
return _requestObservable(client, httpRequest, {
|
|
2171
3001
|
method: "GET",
|
|
2172
3002
|
url: `/blueprints/stacks/${stackId}`,
|
|
@@ -2176,17 +3006,19 @@ function _resolveFunctionId(client, httpRequest, functionName, stackId, headers,
|
|
|
2176
3006
|
let match = (stack?.resources || []).find((resource) => resource.type?.startsWith("sanity.function.") && resource.name === functionName);
|
|
2177
3007
|
if (!match) throw Error(`Function "${functionName}" not found in stack "${stackId}"`);
|
|
2178
3008
|
if (!match.externalId) throw Error(`Function "${functionName}" is declared in stack "${stackId}" but is not deployed`);
|
|
2179
|
-
if (match.type
|
|
3009
|
+
if (!INVOCABLE_FUNCTION_TYPES.includes(match.type)) throw Error(`Function invocation is not supported for ${match.type}`);
|
|
3010
|
+
if (sync && !SYNC_INVOCABLE_FUNCTION_TYPES.includes(match.type)) throw Error(`Synchronous function invocation is not supported for ${match.type}`);
|
|
3011
|
+
if (!sync && !ASYNC_INVOCABLE_FUNCTION_TYPES.includes(match.type)) throw Error(`Asynchronous function invocation is not supported for ${match.type}`);
|
|
2180
3012
|
return match.externalId;
|
|
2181
3013
|
}));
|
|
2182
3014
|
}
|
|
2183
3015
|
/** @internal */
|
|
2184
|
-
function _invoke(client, httpRequest, functionName, request) {
|
|
3016
|
+
function _invoke(client, httpRequest, functionName, request, options) {
|
|
2185
3017
|
return defer(() => {
|
|
2186
|
-
let config = client.config(), headers = scopeHeaders(config, request);
|
|
2187
|
-
return _resolveFunctionId(client, httpRequest, functionName,
|
|
3018
|
+
let config = client.config(), headers = scopeHeaders(config, request), stackId = resolveStackId(config, request), sync = options?.sync ?? !1;
|
|
3019
|
+
return _resolveFunctionId(client, httpRequest, functionName, stackId, headers, request, sync).pipe(mergeMap((functionId) => _requestObservable(client, httpRequest, {
|
|
2188
3020
|
method: "POST",
|
|
2189
|
-
url: `/functions/${functionId}/invoke`,
|
|
3021
|
+
url: `/functions/${functionId}/invoke${sync ? "?sync=true" : ""}`,
|
|
2190
3022
|
headers,
|
|
2191
3023
|
body: { event: { data: request?.event?.data ?? {} } },
|
|
2192
3024
|
timeout: request?.timeout,
|
|
@@ -2198,42 +3030,15 @@ var _client$4 = /* @__PURE__ */ new WeakMap(), _httpRequest$5 = /* @__PURE__ */
|
|
|
2198
3030
|
constructor(client, httpRequest) {
|
|
2199
3031
|
_classPrivateFieldInitSpec(this, _client$4, void 0), _classPrivateFieldInitSpec(this, _httpRequest$5, void 0), _classPrivateFieldSet2(_client$4, this, client), _classPrivateFieldSet2(_httpRequest$5, this, httpRequest);
|
|
2200
3032
|
}
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
*
|
|
2204
|
-
* The name is resolved within the stack given by `stackId` on the request or
|
|
2205
|
-
* the client config. Passes the function's return value once it finishes.
|
|
2206
|
-
*
|
|
2207
|
-
* @param functionName - name of the function, as declared in the blueprint
|
|
2208
|
-
* @param request - payload and request options
|
|
2209
|
-
*/
|
|
2210
|
-
invoke(functionName, request) {
|
|
2211
|
-
return _invoke(_classPrivateFieldGet2(_client$4, this), _classPrivateFieldGet2(_httpRequest$5, this), functionName, request);
|
|
3033
|
+
invoke(functionName, request, options) {
|
|
3034
|
+
return _invoke(_classPrivateFieldGet2(_client$4, this), _classPrivateFieldGet2(_httpRequest$5, this), functionName, request, options);
|
|
2212
3035
|
}
|
|
2213
3036
|
}, _client2$4 = /* @__PURE__ */ new WeakMap(), _httpRequest2$5 = /* @__PURE__ */ new WeakMap(), FunctionsClient = class {
|
|
2214
3037
|
constructor(client, httpRequest) {
|
|
2215
3038
|
_classPrivateFieldInitSpec(this, _client2$4, void 0), _classPrivateFieldInitSpec(this, _httpRequest2$5, void 0), _classPrivateFieldSet2(_client2$4, this, client), _classPrivateFieldSet2(_httpRequest2$5, this, httpRequest);
|
|
2216
3039
|
}
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
*
|
|
2220
|
-
* The name is resolved within the stack given by `stackId` on the request or
|
|
2221
|
-
* the client config, which costs one extra request per call. Rejects if the
|
|
2222
|
-
* stack has no function by that name, or if the name resolves to anything
|
|
2223
|
-
* other than a `sanity.function.pubsub` function.
|
|
2224
|
-
*
|
|
2225
|
-
* The lookup is scoped to `projectId`, or to `organizationId` when one is set
|
|
2226
|
-
* for a stack deployed at organization scope.
|
|
2227
|
-
*
|
|
2228
|
-
* The request stays open until the function finishes, and resolves with its
|
|
2229
|
-
* return value, or `undefined` if it returns nothing. Long-running functions
|
|
2230
|
-
* may need an explicit `timeout`.
|
|
2231
|
-
*
|
|
2232
|
-
* @param functionName - name of the function, as declared in the blueprint
|
|
2233
|
-
* @param request - payload and request options
|
|
2234
|
-
*/
|
|
2235
|
-
invoke(functionName, request) {
|
|
2236
|
-
return lastValueFrom(_invoke(_classPrivateFieldGet2(_client2$4, this), _classPrivateFieldGet2(_httpRequest2$5, this), functionName, request));
|
|
3040
|
+
invoke(functionName, request, options) {
|
|
3041
|
+
return lastValueFrom(_invoke(_classPrivateFieldGet2(_client2$4, this), _classPrivateFieldGet2(_httpRequest2$5, this), functionName, request, options));
|
|
2237
3042
|
}
|
|
2238
3043
|
}, _client$3 = /* @__PURE__ */ new WeakMap(), _httpRequest$4 = /* @__PURE__ */ new WeakMap(), ObservableMediaLibraryVideoClient = class {
|
|
2239
3044
|
constructor(client, httpRequest) {
|
|
@@ -2372,7 +3177,19 @@ var _client$2 = /* @__PURE__ */ new WeakMap(), _httpRequest$3 = /* @__PURE__ */
|
|
|
2372
3177
|
*
|
|
2373
3178
|
* ~24 years (or 7.54e+8 seconds) needed, in order to have a 1% probability of at least one collision if 10 ID's are generated every hour.
|
|
2374
3179
|
*/
|
|
2375
|
-
|
|
3180
|
+
function generateReleaseId() {
|
|
3181
|
+
let id = "";
|
|
3182
|
+
for (; id.length < 8;) {
|
|
3183
|
+
let bytes = crypto.getRandomValues(new Uint8Array(8 - id.length));
|
|
3184
|
+
for (let byte of bytes) {
|
|
3185
|
+
let index = byte & 63;
|
|
3186
|
+
index < 62 && (id += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[index]);
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
return id;
|
|
3190
|
+
}
|
|
3191
|
+
/** @internal */
|
|
3192
|
+
const getDocumentVersionId = (publishedId, releaseId) => releaseId ? getVersionId(publishedId, releaseId) : getDraftId(publishedId);
|
|
2376
3193
|
/** @internal */
|
|
2377
3194
|
function deriveDocumentVersionId(op, { releaseId, publishedId, document }) {
|
|
2378
3195
|
if (publishedId && document._id) {
|
|
@@ -2867,14 +3684,19 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
2867
3684
|
}
|
|
2868
3685
|
}, _clientConfig = /* @__PURE__ */ new WeakMap(), _httpRequest = /* @__PURE__ */ new WeakMap(), ObservableSanityClient = class ObservableSanityClient {
|
|
2869
3686
|
constructor(httpRequest, config = defaultConfig) {
|
|
2870
|
-
_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, "collaboration", void 0), _defineProperty(this, "functions", void 0), _defineProperty(this, "releases", void 0),
|
|
3687
|
+
_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, "collaboration", void 0), _defineProperty(this, "functions", void 0), _defineProperty(this, "releases", void 0), _defineProperty(
|
|
3688
|
+
this,
|
|
3689
|
+
/** @beta */
|
|
3690
|
+
"context",
|
|
3691
|
+
void 0
|
|
3692
|
+
), _classPrivateFieldInitSpec(this, _clientConfig, void 0), _classPrivateFieldInitSpec(this, _httpRequest, void 0), _defineProperty(
|
|
2871
3693
|
this,
|
|
2872
3694
|
/**
|
|
2873
3695
|
* Instance properties
|
|
2874
3696
|
*/
|
|
2875
3697
|
"listen",
|
|
2876
|
-
_listen$
|
|
2877
|
-
), 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.collaboration = { comments: new ObservableCollaborationCommentsClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.functions = new ObservableFunctionsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.releases = new ObservableReleasesClient(this, _classPrivateFieldGet2(_httpRequest, this));
|
|
3698
|
+
_listen$2
|
|
3699
|
+
), 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.collaboration = { comments: new ObservableCollaborationCommentsClient(this, _classPrivateFieldGet2(_httpRequest, this)) }, this.functions = new ObservableFunctionsClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.releases = new ObservableReleasesClient(this, _classPrivateFieldGet2(_httpRequest, this)), this.context = new ObservableContextClient(this, _classPrivateFieldGet2(_httpRequest, this));
|
|
2878
3700
|
}
|
|
2879
3701
|
/**
|
|
2880
3702
|
* Clone the client - returns a new instance
|
|
@@ -3092,6 +3914,11 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
3092
3914
|
}, _clientConfig2 = /* @__PURE__ */ new WeakMap(), _httpRequest2 = /* @__PURE__ */ new WeakMap(), SanityClient = class SanityClient {
|
|
3093
3915
|
constructor(httpRequest, config = defaultConfig) {
|
|
3094
3916
|
_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, "collaboration", void 0), _defineProperty(this, "functions", void 0), _defineProperty(this, "releases", void 0), _defineProperty(
|
|
3917
|
+
this,
|
|
3918
|
+
/** @beta */
|
|
3919
|
+
"context",
|
|
3920
|
+
void 0
|
|
3921
|
+
), _defineProperty(
|
|
3095
3922
|
this,
|
|
3096
3923
|
/**
|
|
3097
3924
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
@@ -3104,8 +3931,8 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
3104
3931
|
* Instance properties
|
|
3105
3932
|
*/
|
|
3106
3933
|
"listen",
|
|
3107
|
-
_listen$
|
|
3108
|
-
), 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.collaboration = { comments: new CollaborationCommentsClient(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);
|
|
3934
|
+
_listen$2
|
|
3935
|
+
), 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.collaboration = { comments: new CollaborationCommentsClient(this, _classPrivateFieldGet2(_httpRequest2, this)) }, this.functions = new FunctionsClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.releases = new ReleasesClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.context = new ContextClient(this, _classPrivateFieldGet2(_httpRequest2, this)), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
3109
3936
|
}
|
|
3110
3937
|
/**
|
|
3111
3938
|
* Clone the client - returns a new instance
|
|
@@ -3135,7 +3962,7 @@ var _client$1 = /* @__PURE__ */ new WeakMap(), _httpRequest$2 = /* @__PURE__ */
|
|
|
3135
3962
|
});
|
|
3136
3963
|
}
|
|
3137
3964
|
fetch(query, params, options) {
|
|
3138
|
-
return _fetch$
|
|
3965
|
+
return _fetch$2(this, _classPrivateFieldGet2(_httpRequest2, this), _classPrivateFieldGet2(_clientConfig2, this).stega, query, params, options);
|
|
3139
3966
|
}
|
|
3140
3967
|
getDocument(id, options) {
|
|
3141
3968
|
if (options?.includeAllVersions === !0) return _getDocument(this, _classPrivateFieldGet2(_httpRequest2, this), id, {
|
|
@@ -3368,6 +4195,6 @@ function defineDeprecatedCreateClient(createClient) {
|
|
|
3368
4195
|
};
|
|
3369
4196
|
}
|
|
3370
4197
|
const exp = defineCreateClientExports({ middleware: [] }, SanityClient), requester = exp.requester, createClient = exp.createClient, deprecatedCreateClient = defineDeprecatedCreateClient(createClient);
|
|
3371
|
-
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 };
|
|
4198
|
+
export { BasePatch, BaseTransaction, ChannelError, ClientError, ConnectionFailedError, types_exports as Context, 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 };
|
|
3372
4199
|
|
|
3373
4200
|
//# sourceMappingURL=index.js.map
|