@sanity/client 7.13.1 → 7.14.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 +67 -5
- package/dist/_chunks-cjs/config.cjs +21 -8
- package/dist/_chunks-cjs/config.cjs.map +1 -1
- package/dist/_chunks-cjs/resolveEditInfo.cjs +1 -1
- package/dist/_chunks-cjs/resolveEditInfo.cjs.map +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs +1 -1
- package/dist/_chunks-cjs/stegaEncodeSourceMap.cjs.map +1 -1
- package/dist/_chunks-es/config.js +21 -8
- package/dist/_chunks-es/config.js.map +1 -1
- package/dist/_chunks-es/resolveEditInfo.js +1 -1
- package/dist/_chunks-es/resolveEditInfo.js.map +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js +1 -1
- package/dist/_chunks-es/stegaEncodeSourceMap.js.map +1 -1
- package/dist/index.browser.cjs +40 -18
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.d.cts +22 -1
- package/dist/index.browser.d.ts +22 -1
- package/dist/index.browser.js +40 -18
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +20 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.js +20 -11
- package/dist/index.js.map +1 -1
- package/dist/stega.browser.d.cts +22 -1
- package/dist/stega.browser.d.ts +22 -1
- package/dist/stega.d.cts +22 -1
- package/dist/stega.d.ts +22 -1
- package/package.json +3 -3
- package/src/assets/AssetsClient.ts +25 -11
- package/src/config.ts +10 -2
- package/src/csm/resolveMapping.ts +1 -1
- package/src/data/dataMethods.ts +12 -6
- package/src/mediaLibrary/MediaLibraryVideoClient.ts +3 -1
- package/src/types.ts +23 -1
- package/src/validators.ts +22 -6
- package/src/warnings.ts +5 -0
- package/umd/sanityClient.js +43 -21
- package/umd/sanityClient.min.js +2 -2
package/dist/index.cjs
CHANGED
|
@@ -919,7 +919,10 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
919
919
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
|
|
920
920
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
921
921
|
}
|
|
922
|
-
const hasDataConfig = (client) =>
|
|
922
|
+
const hasDataConfig = (client) => {
|
|
923
|
+
const config2 = client.config();
|
|
924
|
+
return config2.dataset !== void 0 && config2.projectId !== void 0 || config2.resource !== void 0;
|
|
925
|
+
}, isQuery = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "query")), isMutate = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "mutate")), isDoc = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "doc", "")), isListener = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "listen")), isHistory = (client, uri) => hasDataConfig(client) && uri.startsWith(_getDataUrl(client, "history", "")), isData = (client, uri) => uri.startsWith("/data/") || isQuery(client, uri) || isMutate(client, uri) || isDoc(client, uri) || isListener(client, uri) || isHistory(client, uri);
|
|
923
926
|
function _requestObservable(client, httpRequest, options) {
|
|
924
927
|
const uri = options.url || options.uri, config$1 = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
|
|
925
928
|
let useCdn = (options.useCdn ?? config$1.useCdn) && canUseCdn;
|
|
@@ -952,7 +955,7 @@ function _request(client, httpRequest, options) {
|
|
|
952
955
|
}
|
|
953
956
|
function _getDataUrl(client, operation, path) {
|
|
954
957
|
const config$1 = client.config();
|
|
955
|
-
if (config$1
|
|
958
|
+
if (config$1.resource) {
|
|
956
959
|
config.resourceConfig(config$1);
|
|
957
960
|
const resourceBase = resourceDataBase(config$1), uri2 = path !== void 0 ? `${operation}/${path}` : operation;
|
|
958
961
|
return `${resourceBase}/${uri2}`.replace(/\/($|\?)/, "$1");
|
|
@@ -985,9 +988,10 @@ function _createAbortError(signal) {
|
|
|
985
988
|
return error.name = "AbortError", error;
|
|
986
989
|
}
|
|
987
990
|
const resourceDataBase = (config2) => {
|
|
988
|
-
|
|
991
|
+
const resource = config2.resource;
|
|
992
|
+
if (!resource)
|
|
989
993
|
throw new Error("`resource` must be provided to perform resource queries");
|
|
990
|
-
const { type, id } =
|
|
994
|
+
const { type, id } = resource;
|
|
991
995
|
switch (type) {
|
|
992
996
|
case "dataset": {
|
|
993
997
|
const segments = id.split(".");
|
|
@@ -1148,7 +1152,12 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
1148
1152
|
config.validateAssetType(assetType);
|
|
1149
1153
|
let meta = opts.extract || void 0;
|
|
1150
1154
|
meta && !meta.length && (meta = ["none"]);
|
|
1151
|
-
const config$1 = client.config(), options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
|
|
1155
|
+
const config$1 = client.config(), options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, isMediaLibrary = config$1.resource?.type === "media-library", query = isMediaLibrary ? {
|
|
1156
|
+
// Media Library only supports basic parameters
|
|
1157
|
+
title,
|
|
1158
|
+
filename
|
|
1159
|
+
} : {
|
|
1160
|
+
// Content Lake supports full set of parameters
|
|
1152
1161
|
label,
|
|
1153
1162
|
title,
|
|
1154
1163
|
description,
|
|
@@ -1156,7 +1165,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
1156
1165
|
meta,
|
|
1157
1166
|
creditLine
|
|
1158
1167
|
};
|
|
1159
|
-
return source && (query.sourceId = source.id, query.sourceName = source.name, query.sourceUrl = source.url), _requestObservable(client, httpRequest, {
|
|
1168
|
+
return source && !isMediaLibrary && (query.sourceId = source.id, query.sourceName = source.name, query.sourceUrl = source.url), _requestObservable(client, httpRequest, {
|
|
1160
1169
|
tag,
|
|
1161
1170
|
method: "POST",
|
|
1162
1171
|
timeout: options.timeout || 0,
|
|
@@ -1167,9 +1176,9 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
1167
1176
|
});
|
|
1168
1177
|
}
|
|
1169
1178
|
function buildAssetUploadUrl(config$1, assetType) {
|
|
1170
|
-
const assetTypeEndpoint = assetType === "image" ? "images" : "files";
|
|
1171
|
-
if (
|
|
1172
|
-
const { type, id } =
|
|
1179
|
+
const assetTypeEndpoint = assetType === "image" ? "images" : "files", resource = config$1.resource;
|
|
1180
|
+
if (resource) {
|
|
1181
|
+
const { type, id } = resource;
|
|
1173
1182
|
switch (type) {
|
|
1174
1183
|
case "dataset":
|
|
1175
1184
|
throw new Error(
|
|
@@ -1469,7 +1478,7 @@ class ObservableMediaLibraryVideoClient {
|
|
|
1469
1478
|
* @param options - Options for transformations and expiration
|
|
1470
1479
|
*/
|
|
1471
1480
|
getPlaybackInfo(assetIdentifier, options = {}) {
|
|
1472
|
-
const
|
|
1481
|
+
const config2 = this.#client.config(), configMediaLibraryId = (config2.resource || config2["~experimental_resource"])?.id, { instanceId, libraryId } = parseAssetInstanceId(assetIdentifier), effectiveLibraryId = libraryId || configMediaLibraryId;
|
|
1473
1482
|
if (!effectiveLibraryId)
|
|
1474
1483
|
throw new Error(
|
|
1475
1484
|
"Could not determine Media Library ID - you need to provide a valid Media Library ID in the client config or a Media Library GDR"
|
|
@@ -2682,7 +2691,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2682
2691
|
return config.printNoDefaultExport(), createClient2(config$1);
|
|
2683
2692
|
};
|
|
2684
2693
|
}
|
|
2685
|
-
var name = "@sanity/client", version = "7.
|
|
2694
|
+
var name = "@sanity/client", version = "7.14.0";
|
|
2686
2695
|
const middleware = [
|
|
2687
2696
|
middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2688
2697
|
middleware$1.headers({ "User-Agent": `${name} ${version}` }),
|