@sanity/client 7.13.2 → 7.14.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/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) => client.config().dataset !== void 0 && client.config().projectId !== void 0 || client.config()["~experimental_resource"] !== void 0, 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);
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["~experimental_resource"]) {
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
- if (!config2["~experimental_resource"])
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 } = config2["~experimental_resource"];
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 (config$1["~experimental_resource"]) {
1172
- const { type, id } = config$1["~experimental_resource"];
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(
@@ -1275,7 +1284,6 @@ class LiveClient {
1275
1284
  includeDrafts = !1,
1276
1285
  tag: _tag
1277
1286
  } = {}) {
1278
- config.resourceGuard("live", this.#client.config());
1279
1287
  const {
1280
1288
  projectId,
1281
1289
  apiVersion: _apiVersion,
@@ -1469,7 +1477,7 @@ class ObservableMediaLibraryVideoClient {
1469
1477
  * @param options - Options for transformations and expiration
1470
1478
  */
1471
1479
  getPlaybackInfo(assetIdentifier, options = {}) {
1472
- const configMediaLibraryId = this.#client.config()["~experimental_resource"]?.id, { instanceId, libraryId } = parseAssetInstanceId(assetIdentifier), effectiveLibraryId = libraryId || configMediaLibraryId;
1480
+ const config2 = this.#client.config(), configMediaLibraryId = (config2.resource || config2["~experimental_resource"])?.id, { instanceId, libraryId } = parseAssetInstanceId(assetIdentifier), effectiveLibraryId = libraryId || configMediaLibraryId;
1473
1481
  if (!effectiveLibraryId)
1474
1482
  throw new Error(
1475
1483
  "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 +2690,7 @@ function defineDeprecatedCreateClient(createClient2) {
2682
2690
  return config.printNoDefaultExport(), createClient2(config$1);
2683
2691
  };
2684
2692
  }
2685
- var name = "@sanity/client", version = "7.13.2";
2693
+ var name = "@sanity/client", version = "7.14.1";
2686
2694
  const middleware = [
2687
2695
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
2688
2696
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),