@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/umd/sanityClient.js
CHANGED
|
@@ -1465,11 +1465,13 @@
|
|
|
1465
1465
|
return !!obj && (obj instanceof Observable || (isFunction(obj.lift) && isFunction(obj.subscribe)));
|
|
1466
1466
|
}
|
|
1467
1467
|
|
|
1468
|
-
var EmptyError = createErrorClass(function (_super) {
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1468
|
+
var EmptyError = createErrorClass(function (_super) {
|
|
1469
|
+
return function EmptyErrorImpl() {
|
|
1470
|
+
_super(this);
|
|
1471
|
+
this.name = 'EmptyError';
|
|
1472
|
+
this.message = 'no elements in sequence';
|
|
1473
|
+
};
|
|
1474
|
+
});
|
|
1473
1475
|
|
|
1474
1476
|
function lastValueFrom(source, config) {
|
|
1475
1477
|
return new Promise(function (resolve, reject) {
|
|
@@ -2086,6 +2088,9 @@
|
|
|
2086
2088
|
`See ${generateHelpUrl(
|
|
2087
2089
|
"js-client-browser-token"
|
|
2088
2090
|
)} for more information and how to hide this warning.`
|
|
2091
|
+
]), printCredentialedTokenWarning = createWarningPrinter([
|
|
2092
|
+
"You have configured Sanity client to use a token, but also provided `withCredentials: true`.",
|
|
2093
|
+
"This is no longer supported - only token will be used - remove `withCredentials: true`."
|
|
2089
2094
|
]), printNoApiVersionSpecifiedWarning = createWarningPrinter([
|
|
2090
2095
|
"Using the Sanity client without specifying an API version is deprecated.",
|
|
2091
2096
|
`See ${generateHelpUrl("js-client-api-version")}`
|
|
@@ -2104,21 +2109,11 @@
|
|
|
2104
2109
|
if (!(/^\d{4}-\d{2}-\d{2}$/.test(apiVersion) && apiDate instanceof Date && apiDate.getTime() > 0))
|
|
2105
2110
|
throw new Error("Invalid API version string, expected `1` or date in format `YYYY-MM-DD`");
|
|
2106
2111
|
}
|
|
2107
|
-
const VALID_PERSPECTIVE = /^[a-z0-9_]+$/i;
|
|
2108
2112
|
function validateApiPerspective(perspective) {
|
|
2109
|
-
if (Array.isArray(perspective) && perspective.includes("raw"))
|
|
2113
|
+
if (Array.isArray(perspective) && perspective.length > 1 && perspective.includes("raw"))
|
|
2110
2114
|
throw new TypeError(
|
|
2111
2115
|
'Invalid API perspective value: "raw". The raw-perspective can not be combined with other perspectives'
|
|
2112
2116
|
);
|
|
2113
|
-
const invalid = (Array.isArray(perspective) ? perspective : [perspective]).filter(
|
|
2114
|
-
(perspectiveName) => typeof perspectiveName != "string" || !VALID_PERSPECTIVE.test(perspectiveName)
|
|
2115
|
-
);
|
|
2116
|
-
if (invalid.length > 0) {
|
|
2117
|
-
const formatted = invalid.map((v) => JSON.stringify(v));
|
|
2118
|
-
throw new TypeError(
|
|
2119
|
-
`Invalid API perspective value${invalid.length === 1 ? "" : "s"}: ${formatted.join(", ")}, expected \`published\`, \`drafts\`, \`raw\` or a release identifier string`
|
|
2120
|
-
);
|
|
2121
|
-
}
|
|
2122
2117
|
}
|
|
2123
2118
|
const initConfig = (config, prevConfig) => {
|
|
2124
2119
|
const specifiedConfig = {
|
|
@@ -2156,8 +2151,8 @@
|
|
|
2156
2151
|
throw new Error(
|
|
2157
2152
|
`stega.studioUrl must be a string or a function, received ${newConfig.stega.studioUrl}`
|
|
2158
2153
|
);
|
|
2159
|
-
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
|
|
2160
|
-
|
|
2154
|
+
const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname), hasToken = !!newConfig.token;
|
|
2155
|
+
newConfig.withCredentials && hasToken && (printCredentialedTokenWarning(), newConfig.withCredentials = false), isBrowser && isLocalhost && hasToken && newConfig.ignoreBrowserTokenWarning !== true ? 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 === true && newConfig.withCredentials && printCdnAndWithCredentialsWarning(), newConfig.useCdn = newConfig.useCdn !== false && !newConfig.withCredentials, validateApiVersion(newConfig.apiVersion);
|
|
2161
2156
|
const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
|
|
2162
2157
|
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;
|
|
2163
2158
|
};
|
|
@@ -2605,7 +2600,7 @@ ${selectionOpts}`);
|
|
|
2605
2600
|
function requestOptions(config, overrides = {}) {
|
|
2606
2601
|
const headers = {}, token = overrides.token || config.token;
|
|
2607
2602
|
token && (headers.Authorization = `Bearer ${token}`), !overrides.useGlobalApi && !config.useProjectHostname && config.projectId && (headers[projectHeader] = config.projectId);
|
|
2608
|
-
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.
|
|
2603
|
+
const withCredentials = !!(typeof overrides.withCredentials > "u" ? config.withCredentials : overrides.withCredentials), timeout = typeof overrides.timeout > "u" ? config.timeout : overrides.timeout;
|
|
2609
2604
|
return Object.assign({}, overrides, {
|
|
2610
2605
|
headers: Object.assign({}, headers, overrides.headers || {}),
|
|
2611
2606
|
timeout: typeof timeout > "u" ? 5 * 60 * 1e3 : timeout,
|
|
@@ -2828,6 +2823,42 @@ ${selectionOpts}`);
|
|
|
2828
2823
|
const error = new Error(signal?.reason ?? "The operation was aborted.");
|
|
2829
2824
|
return error.name = "AbortError", error;
|
|
2830
2825
|
}
|
|
2826
|
+
function _instruct(client, httpRequest, request) {
|
|
2827
|
+
const dataset2 = hasDataset(client.config());
|
|
2828
|
+
return _request(client, httpRequest, {
|
|
2829
|
+
method: "POST",
|
|
2830
|
+
uri: `/assist/tasks/instruct/${dataset2}`,
|
|
2831
|
+
body: request
|
|
2832
|
+
});
|
|
2833
|
+
}
|
|
2834
|
+
class ObservableAiClient {
|
|
2835
|
+
#client;
|
|
2836
|
+
#httpRequest;
|
|
2837
|
+
constructor(client, httpRequest) {
|
|
2838
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
2839
|
+
}
|
|
2840
|
+
/**
|
|
2841
|
+
* Run an ad-hoc instruction for a target document.
|
|
2842
|
+
* @param request instruction request
|
|
2843
|
+
*/
|
|
2844
|
+
instruct(request) {
|
|
2845
|
+
return _instruct(this.#client, this.#httpRequest, request);
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
class AiClient {
|
|
2849
|
+
#client;
|
|
2850
|
+
#httpRequest;
|
|
2851
|
+
constructor(client, httpRequest) {
|
|
2852
|
+
this.#client = client, this.#httpRequest = httpRequest;
|
|
2853
|
+
}
|
|
2854
|
+
/**
|
|
2855
|
+
* Run an ad-hoc instruction for a target document.
|
|
2856
|
+
* @param request instruction request
|
|
2857
|
+
*/
|
|
2858
|
+
instruct(request) {
|
|
2859
|
+
return lastValueFrom(_instruct(this.#client, this.#httpRequest, request));
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2831
2862
|
class ObservableAssetsClient {
|
|
2832
2863
|
#client;
|
|
2833
2864
|
#httpRequest;
|
|
@@ -2915,7 +2946,7 @@ ${selectionOpts}`);
|
|
|
2915
2946
|
if (uri.length > MAX_URL_LENGTH)
|
|
2916
2947
|
return throwError(() => new Error("Query too large for listener"));
|
|
2917
2948
|
const listenFor = options.events ? options.events : ["mutation"], esOptions = {};
|
|
2918
|
-
return
|
|
2949
|
+
return withCredentials && (esOptions.withCredentials = true), token && (esOptions.headers = {
|
|
2919
2950
|
Authorization: `Bearer ${token}`
|
|
2920
2951
|
}), connectEventSource(() => (
|
|
2921
2952
|
// use polyfill if there is no global EventSource or if we need to set headers
|
|
@@ -2948,7 +2979,10 @@ ${selectionOpts}`);
|
|
|
2948
2979
|
}),
|
|
2949
2980
|
share(shareConfig)
|
|
2950
2981
|
), emitLatest = new Observable((subscriber) => {
|
|
2951
|
-
emitted && subscriber.next(
|
|
2982
|
+
emitted && subscriber.next(
|
|
2983
|
+
// this cast is safe because of the emitted check which asserts that we got T from the source
|
|
2984
|
+
latest
|
|
2985
|
+
), subscriber.complete();
|
|
2952
2986
|
});
|
|
2953
2987
|
return merge(wrapped, emitLatest);
|
|
2954
2988
|
};
|
|
@@ -3219,6 +3253,7 @@ ${selectionOpts}`);
|
|
|
3219
3253
|
live;
|
|
3220
3254
|
projects;
|
|
3221
3255
|
users;
|
|
3256
|
+
ai;
|
|
3222
3257
|
/**
|
|
3223
3258
|
* Private properties
|
|
3224
3259
|
*/
|
|
@@ -3229,7 +3264,7 @@ ${selectionOpts}`);
|
|
|
3229
3264
|
*/
|
|
3230
3265
|
listen = _listen;
|
|
3231
3266
|
constructor(httpRequest, config = defaultConfig) {
|
|
3232
|
-
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);
|
|
3267
|
+
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);
|
|
3233
3268
|
}
|
|
3234
3269
|
/**
|
|
3235
3270
|
* Clone the client - returns a new instance
|
|
@@ -3368,6 +3403,7 @@ ${selectionOpts}`);
|
|
|
3368
3403
|
live;
|
|
3369
3404
|
projects;
|
|
3370
3405
|
users;
|
|
3406
|
+
ai;
|
|
3371
3407
|
/**
|
|
3372
3408
|
* Observable version of the Sanity client, with the same configuration as the promise-based one
|
|
3373
3409
|
*/
|
|
@@ -3382,7 +3418,7 @@ ${selectionOpts}`);
|
|
|
3382
3418
|
*/
|
|
3383
3419
|
listen = _listen;
|
|
3384
3420
|
constructor(httpRequest, config = defaultConfig) {
|
|
3385
|
-
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);
|
|
3421
|
+
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);
|
|
3386
3422
|
}
|
|
3387
3423
|
/**
|
|
3388
3424
|
* Clone the client - returns a new instance
|