@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.d.cts
CHANGED
|
@@ -430,6 +430,7 @@ export declare type AssetMetadataType =
|
|
|
430
430
|
| 'palette'
|
|
431
431
|
| 'lqip'
|
|
432
432
|
| 'blurhash'
|
|
433
|
+
| 'thumbhash'
|
|
433
434
|
| 'none'
|
|
434
435
|
|
|
435
436
|
/** @internal */
|
|
@@ -697,7 +698,26 @@ export declare interface ClientConfig {
|
|
|
697
698
|
/** @defaultValue true */
|
|
698
699
|
useCdn?: boolean
|
|
699
700
|
token?: string
|
|
700
|
-
/**
|
|
701
|
+
/**
|
|
702
|
+
* Configure the client to work with a specific Sanity resource (Media Library, Canvas, etc.)
|
|
703
|
+
* @remarks
|
|
704
|
+
* This allows the client to interact with resources beyond traditional project datasets.
|
|
705
|
+
* When configured, methods like `fetch()`, `assets.upload()`, and mutations will operate on the specified resource.
|
|
706
|
+
* @example
|
|
707
|
+
* ```ts
|
|
708
|
+
* createClient({
|
|
709
|
+
* resource: {
|
|
710
|
+
* type: 'media-library',
|
|
711
|
+
* id: 'your-media-library-id'
|
|
712
|
+
* }
|
|
713
|
+
* })
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
716
|
+
resource?: ClientConfigResource
|
|
717
|
+
/**
|
|
718
|
+
* @deprecated Use `resource` instead
|
|
719
|
+
* @internal
|
|
720
|
+
*/
|
|
701
721
|
'~experimental_resource'?: ClientConfigResource
|
|
702
722
|
/**
|
|
703
723
|
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
@@ -5565,6 +5585,7 @@ export declare interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
|
5565
5585
|
isOpaque: boolean
|
|
5566
5586
|
lqip?: string
|
|
5567
5587
|
blurHash?: string
|
|
5588
|
+
thumbHash?: string
|
|
5568
5589
|
dimensions: {
|
|
5569
5590
|
_type: 'sanity.imageDimensions'
|
|
5570
5591
|
aspectRatio: number
|
package/dist/index.d.ts
CHANGED
|
@@ -430,6 +430,7 @@ export declare type AssetMetadataType =
|
|
|
430
430
|
| 'palette'
|
|
431
431
|
| 'lqip'
|
|
432
432
|
| 'blurhash'
|
|
433
|
+
| 'thumbhash'
|
|
433
434
|
| 'none'
|
|
434
435
|
|
|
435
436
|
/** @internal */
|
|
@@ -697,7 +698,26 @@ export declare interface ClientConfig {
|
|
|
697
698
|
/** @defaultValue true */
|
|
698
699
|
useCdn?: boolean
|
|
699
700
|
token?: string
|
|
700
|
-
/**
|
|
701
|
+
/**
|
|
702
|
+
* Configure the client to work with a specific Sanity resource (Media Library, Canvas, etc.)
|
|
703
|
+
* @remarks
|
|
704
|
+
* This allows the client to interact with resources beyond traditional project datasets.
|
|
705
|
+
* When configured, methods like `fetch()`, `assets.upload()`, and mutations will operate on the specified resource.
|
|
706
|
+
* @example
|
|
707
|
+
* ```ts
|
|
708
|
+
* createClient({
|
|
709
|
+
* resource: {
|
|
710
|
+
* type: 'media-library',
|
|
711
|
+
* id: 'your-media-library-id'
|
|
712
|
+
* }
|
|
713
|
+
* })
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
716
|
+
resource?: ClientConfigResource
|
|
717
|
+
/**
|
|
718
|
+
* @deprecated Use `resource` instead
|
|
719
|
+
* @internal
|
|
720
|
+
*/
|
|
701
721
|
'~experimental_resource'?: ClientConfigResource
|
|
702
722
|
/**
|
|
703
723
|
* What perspective to use for the client. See {@link https://www.sanity.io/docs/perspectives|perspective documentation}
|
|
@@ -5565,6 +5585,7 @@ export declare interface SanityImageAssetDocument extends SanityAssetDocument {
|
|
|
5565
5585
|
isOpaque: boolean
|
|
5566
5586
|
lqip?: string
|
|
5567
5587
|
blurHash?: string
|
|
5588
|
+
thumbHash?: string
|
|
5568
5589
|
dimensions: {
|
|
5569
5590
|
_type: 'sanity.imageDimensions'
|
|
5570
5591
|
aspectRatio: number
|
package/dist/index.js
CHANGED
|
@@ -905,7 +905,10 @@ function _create(client, httpRequest, doc, op, options = {}) {
|
|
|
905
905
|
const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
|
|
906
906
|
return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
|
|
907
907
|
}
|
|
908
|
-
const hasDataConfig = (client) =>
|
|
908
|
+
const hasDataConfig = (client) => {
|
|
909
|
+
const config = client.config();
|
|
910
|
+
return config.dataset !== void 0 && config.projectId !== void 0 || config.resource !== void 0;
|
|
911
|
+
}, 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);
|
|
909
912
|
function _requestObservable(client, httpRequest, options) {
|
|
910
913
|
const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isData(client, uri) : options.canUseCdn;
|
|
911
914
|
let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
|
|
@@ -938,7 +941,7 @@ function _request(client, httpRequest, options) {
|
|
|
938
941
|
}
|
|
939
942
|
function _getDataUrl(client, operation, path) {
|
|
940
943
|
const config = client.config();
|
|
941
|
-
if (config
|
|
944
|
+
if (config.resource) {
|
|
942
945
|
resourceConfig(config);
|
|
943
946
|
const resourceBase = resourceDataBase(config), uri2 = path !== void 0 ? `${operation}/${path}` : operation;
|
|
944
947
|
return `${resourceBase}/${uri2}`.replace(/\/($|\?)/, "$1");
|
|
@@ -971,9 +974,10 @@ function _createAbortError(signal) {
|
|
|
971
974
|
return error.name = "AbortError", error;
|
|
972
975
|
}
|
|
973
976
|
const resourceDataBase = (config) => {
|
|
974
|
-
|
|
977
|
+
const resource = config.resource;
|
|
978
|
+
if (!resource)
|
|
975
979
|
throw new Error("`resource` must be provided to perform resource queries");
|
|
976
|
-
const { type, id } =
|
|
980
|
+
const { type, id } = resource;
|
|
977
981
|
switch (type) {
|
|
978
982
|
case "dataset": {
|
|
979
983
|
const segments = id.split(".");
|
|
@@ -1134,7 +1138,12 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
1134
1138
|
validateAssetType(assetType);
|
|
1135
1139
|
let meta = opts.extract || void 0;
|
|
1136
1140
|
meta && !meta.length && (meta = ["none"]);
|
|
1137
|
-
const config = client.config(), options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
|
|
1141
|
+
const config = client.config(), options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, isMediaLibrary = config.resource?.type === "media-library", query = isMediaLibrary ? {
|
|
1142
|
+
// Media Library only supports basic parameters
|
|
1143
|
+
title,
|
|
1144
|
+
filename
|
|
1145
|
+
} : {
|
|
1146
|
+
// Content Lake supports full set of parameters
|
|
1138
1147
|
label,
|
|
1139
1148
|
title,
|
|
1140
1149
|
description,
|
|
@@ -1142,7 +1151,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
1142
1151
|
meta,
|
|
1143
1152
|
creditLine
|
|
1144
1153
|
};
|
|
1145
|
-
return source && (query.sourceId = source.id, query.sourceName = source.name, query.sourceUrl = source.url), _requestObservable(client, httpRequest, {
|
|
1154
|
+
return source && !isMediaLibrary && (query.sourceId = source.id, query.sourceName = source.name, query.sourceUrl = source.url), _requestObservable(client, httpRequest, {
|
|
1146
1155
|
tag,
|
|
1147
1156
|
method: "POST",
|
|
1148
1157
|
timeout: options.timeout || 0,
|
|
@@ -1153,9 +1162,9 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
|
|
|
1153
1162
|
});
|
|
1154
1163
|
}
|
|
1155
1164
|
function buildAssetUploadUrl(config, assetType) {
|
|
1156
|
-
const assetTypeEndpoint = assetType === "image" ? "images" : "files";
|
|
1157
|
-
if (
|
|
1158
|
-
const { type, id } =
|
|
1165
|
+
const assetTypeEndpoint = assetType === "image" ? "images" : "files", resource = config.resource;
|
|
1166
|
+
if (resource) {
|
|
1167
|
+
const { type, id } = resource;
|
|
1159
1168
|
switch (type) {
|
|
1160
1169
|
case "dataset":
|
|
1161
1170
|
throw new Error(
|
|
@@ -1455,7 +1464,7 @@ class ObservableMediaLibraryVideoClient {
|
|
|
1455
1464
|
* @param options - Options for transformations and expiration
|
|
1456
1465
|
*/
|
|
1457
1466
|
getPlaybackInfo(assetIdentifier, options = {}) {
|
|
1458
|
-
const
|
|
1467
|
+
const config = this.#client.config(), configMediaLibraryId = (config.resource || config["~experimental_resource"])?.id, { instanceId, libraryId } = parseAssetInstanceId(assetIdentifier), effectiveLibraryId = libraryId || configMediaLibraryId;
|
|
1459
1468
|
if (!effectiveLibraryId)
|
|
1460
1469
|
throw new Error(
|
|
1461
1470
|
"Could not determine Media Library ID - you need to provide a valid Media Library ID in the client config or a Media Library GDR"
|
|
@@ -2668,7 +2677,7 @@ function defineDeprecatedCreateClient(createClient2) {
|
|
|
2668
2677
|
return printNoDefaultExport(), createClient2(config);
|
|
2669
2678
|
};
|
|
2670
2679
|
}
|
|
2671
|
-
var name = "@sanity/client", version = "7.
|
|
2680
|
+
var name = "@sanity/client", version = "7.14.0";
|
|
2672
2681
|
const middleware = [
|
|
2673
2682
|
debug({ verbose: !0, namespace: "sanity:client" }),
|
|
2674
2683
|
headers({ "User-Agent": `${name} ${version}` }),
|