@sanity/client 6.28.2 → 6.28.3-instruct.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks-cjs/config.cjs +6 -13
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-es/config.js +6 -13
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/index.browser.cjs +52 -18
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +247 -3
- package/dist/index.browser.d.ts +247 -3
- package/dist/index.browser.js +52 -18
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +47 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +237 -4
- package/dist/index.d.ts +237 -4
- package/dist/index.js +47 -6
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +236 -3
- package/dist/stega.browser.d.ts +236 -3
- package/dist/stega.d.cts +236 -3
- package/dist/stega.d.ts +236 -3
- package/package.json +20 -20
- package/src/SanityClient.ts +5 -1
- package/src/ai/AiClient.ts +93 -0
- package/src/ai/types.ts +206 -0
- package/src/config.ts +9 -18
- package/src/data/listen.ts +1 -1
- package/src/http/requestOptions.ts +1 -1
- package/src/index.ts +1 -1
- package/src/types.ts +13 -3
- package/src/util/shareReplayLatest.ts +4 -1
- package/src/warnings.ts +5 -0
- package/umd/sanityClient.js +59 -23
- package/umd/sanityClient.min.js +2 -2
package/dist/index.browser.js
CHANGED
|
@@ -180,6 +180,9 @@ const createWarningPrinter = (message) => (
|
|
|
180
180
|
`See ${generateHelpUrl(
|
|
181
181
|
"js-client-browser-token"
|
|
182
182
|
)} for more information and how to hide this warning.`
|
|
183
|
+
]), printCredentialedTokenWarning = createWarningPrinter([
|
|
184
|
+
"You have configured Sanity client to use a token, but also provided `withCredentials: true`.",
|
|
185
|
+
"This is no longer supported - only token will be used - remove `withCredentials: true`."
|
|
183
186
|
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
184
187
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
185
188
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
@@ -198,21 +201,11 @@ function validateApiVersion(apiVersion) {
|
|
|
198
201
|
if (!(/^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0))
|
|
199
202
|
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
200
203
|
}
|
|
201
|
-
const VALID_PERSPECTIVE = /^[a-z0-9_]+$/i;
|
|
202
204
|
function validateApiPerspective(perspective) {
|
|
203
|
-
if (Array.isArray(perspective) && perspective.includes("raw"))
|
|
205
|
+
if (Array.isArray(perspective) && perspective.length > 1 && perspective.includes("raw"))
|
|
204
206
|
throw new TypeError(
|
|
205
207
|
'Invalid API perspective value: "raw". The raw-perspective can not be combined with other perspectives'
|
|
206
208
|
);
|
|
207
|
-
const invalid = (Array.isArray(perspective) ? perspective : [perspective]).filter(
|
|
208
|
-
(perspectiveName) => typeof perspectiveName != "string" || !VALID_PERSPECTIVE.test(perspectiveName)
|
|
209
|
-
);
|
|
210
|
-
if (invalid.length > 0) {
|
|
211
|
-
const formatted = invalid.map((v) => JSON.stringify(v));
|
|
212
|
-
throw new TypeError(
|
|
213
|
-
`Invalid API perspective value${invalid.length === 1 ? "" : "s"}: ${formatted.join(", ")}, expected \`published\`, \`drafts\`, \`raw\` or a release identifier string`
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
209
|
}
|
|
217
210
|
const initConfig = (config, prevConfig) => {
|
|
218
211
|
const specifiedConfig = {
|
|
@@ -250,8 +243,8 @@ const initConfig = (config, prevConfig) => {
|
|
|
250
243
|
throw new Error(
|
|
251
244
|
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
252
245
|
);
|
|
253
|
-
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
254
|
-
|
|
246
|
+
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname), hasToken = !!newConfig.token;
|
|
247
|
+
newConfig.withCredentials && hasToken && (printCredentialedTokenWarning(), newConfig.withCredentials = !1), isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== !0 ? printBrowserTokenWarning() : typeof newConfig.useCdn > "u" && printCdnWarning(), projectBased && projectId(newConfig.projectId), newConfig.dataset && dataset(newConfig.dataset), "requestTagPrefix" in newConfig && (newConfig.requestTagPrefix = newConfig.requestTagPrefix ? requestTag(newConfig.requestTagPrefix).replace(/\.+$/, "") : void 0), newConfig.apiVersion = `${newConfig.apiVersion}`.replace(/^v/, ""), newConfig.isDefaultApi = newConfig.apiHost === defaultConfig.apiHost, newConfig.useCdn === !0 && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== !1 && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
255
248
|
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
256
249
|
return newConfig.useProjectHostname ? (newConfig.url = `${protocol}://${newConfig.projectId}.${host}/v${newConfig.apiVersion}`, newConfig.cdnUrl = `${protocol}://${newConfig.projectId}.${cdnHost}/v${newConfig.apiVersion}`) : (newConfig.url = `${newConfig.apiHost}/v${newConfig.apiVersion}`, newConfig.cdnUrl = newConfig.url), newConfig;
|
|
257
250
|
};
|
|
@@ -699,7 +692,7 @@ const projectHeader = "X-Sanity-Project-ID";
|
|
|
699
692
|
function requestOptions(config, overrides = {}) {
|
|
700
693
|
const headers = {}, token = overrides.token || config.token;
|
|
701
694
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
702
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.
|
|
695
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
703
696
|
return Object.assign({}, overrides, {
|
|
704
697
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
705
698
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
@@ -922,6 +915,42 @@ function _createAbortError(signal) {
|
|
|
922
915
|
const error = new Error(signal?.reason ?? "The operation was aborted.");
|
|
923
916
|
return error.name = "AbortError", error;
|
|
924
917
|
}
|
|
918
|
+
function _instruct(client, httpRequest, request) {
|
|
919
|
+
const dataset2 = hasDataset(client.config());
|
|
920
|
+
return _request(client, httpRequest, {
|
|
921
|
+
method: "POST",
|
|
922
|
+
uri: `/assist/tasks/instruct/${dataset2}`,
|
|
923
|
+
body: request
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
class ObservableAiClient {
|
|
927
|
+
#client;
|
|
928
|
+
#httpRequest;
|
|
929
|
+
constructor(client, httpRequest) {
|
|
930
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Run an ad-hoc instruction for a target document.
|
|
934
|
+
* @param request instruction request
|
|
935
|
+
*/
|
|
936
|
+
instruct(request) {
|
|
937
|
+
return _instruct(this.#client, this.#httpRequest, request);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
class AiClient {
|
|
941
|
+
#client;
|
|
942
|
+
#httpRequest;
|
|
943
|
+
constructor(client, httpRequest) {
|
|
944
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Run an ad-hoc instruction for a target document.
|
|
948
|
+
* @param request instruction request
|
|
949
|
+
*/
|
|
950
|
+
instruct(request) {
|
|
951
|
+
return lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
952
|
+
}
|
|
953
|
+
}
|
|
925
954
|
class ObservableAssetsClient {
|
|
926
955
|
#client;
|
|
927
956
|
#httpRequest;
|
|
@@ -1009,7 +1038,7 @@ function _listen(query, params, opts = {}) {
|
|
|
1009
1038
|
if (uri.length > MAX_URL_LENGTH)
|
|
1010
1039
|
return throwError(() => new Error("Query too large for listener"));
|
|
1011
1040
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
1012
|
-
return
|
|
1041
|
+
return withCredentials && (esOptions.withCredentials = !0), token && (esOptions.headers = {
|
|
1013
1042
|
Authorization: `Bearer ${token}`
|
|
1014
1043
|
}), connectEventSource(() => (
|
|
1015
1044
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
@@ -1042,7 +1071,10 @@ function _shareReplayLatest(config) {
|
|
|
1042
1071
|
}),
|
|
1043
1072
|
share(shareConfig)
|
|
1044
1073
|
), emitLatest = new Observable((subscriber) => {
|
|
1045
|
-
emitted && subscriber.next(
|
|
1074
|
+
emitted && subscriber.next(
|
|
1075
|
+
// this cast is safe because of the emitted check which asserts that we got T from the source
|
|
1076
|
+
latest
|
|
1077
|
+
), subscriber.complete();
|
|
1046
1078
|
});
|
|
1047
1079
|
return merge(wrapped, emitLatest);
|
|
1048
1080
|
};
|
|
@@ -1313,6 +1345,7 @@ class ObservableSanityClient {
|
|
|
1313
1345
|
live;
|
|
1314
1346
|
projects;
|
|
1315
1347
|
users;
|
|
1348
|
+
ai;
|
|
1316
1349
|
/**
|
|
1317
1350
|
* Private properties
|
|
1318
1351
|
*/
|
|
@@ -1323,7 +1356,7 @@ class ObservableSanityClient {
|
|
|
1323
1356
|
*/
|
|
1324
1357
|
listen = _listen;
|
|
1325
1358
|
constructor(httpRequest, config = defaultConfig) {
|
|
1326
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest);
|
|
1359
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new ObservableAssetsClient(this, this.#httpRequest), this.datasets = new ObservableDatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ObservableProjectsClient(this, this.#httpRequest), this.users = new ObservableUsersClient(this, this.#httpRequest), this.ai = new ObservableAiClient(this, this.#httpRequest);
|
|
1327
1360
|
}
|
|
1328
1361
|
/**
|
|
1329
1362
|
* Clone the client - returns a new instance
|
|
@@ -1462,6 +1495,7 @@ class SanityClient {
|
|
|
1462
1495
|
live;
|
|
1463
1496
|
projects;
|
|
1464
1497
|
users;
|
|
1498
|
+
ai;
|
|
1465
1499
|
/**
|
|
1466
1500
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
1467
1501
|
*/
|
|
@@ -1476,7 +1510,7 @@ class SanityClient {
|
|
|
1476
1510
|
*/
|
|
1477
1511
|
listen = _listen;
|
|
1478
1512
|
constructor(httpRequest, config = defaultConfig) {
|
|
1479
|
-
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1513
|
+
this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = new DatasetsClient(this, this.#httpRequest), this.live = new LiveClient(this), this.projects = new ProjectsClient(this, this.#httpRequest), this.users = new UsersClient(this, this.#httpRequest), this.ai = new AiClient(this, this.#httpRequest), this.observable = new ObservableSanityClient(httpRequest, config);
|
|
1480
1514
|
}
|
|
1481
1515
|
/**
|
|
1482
1516
|
* Clone the client - returns a new instance
|