@sanity/client 6.27.2-resources.2 → 6.27.2

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.
@@ -388,13 +388,6 @@ export declare interface ClientConfig {
388
388
  * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
389
389
  */
390
390
  stega?: StegaConfig | boolean
391
- /**
392
- * @deprecated Don't use
393
- */
394
- experimental_resource?: {
395
- id: string
396
- type: string
397
- }
398
391
  }
399
392
 
400
393
  /** @public */
@@ -388,13 +388,6 @@ export declare interface ClientConfig {
388
388
  * Options for how, if enabled, Content Source Maps are encoded into query results using steganography
389
389
  */
390
390
  stega?: StegaConfig | boolean
391
- /**
392
- * @deprecated Don't use
393
- */
394
- experimental_resource?: {
395
- id: string
396
- type: string
397
- }
398
391
  }
399
392
 
400
393
  /** @public */
@@ -230,17 +230,7 @@ const initConfig = (config, prevConfig) => {
230
230
  const newConfig = {
231
231
  ...defaultConfig,
232
232
  ...specifiedConfig
233
- }, projectId$1 = newConfig.projectId;
234
- if (projectId$1?.startsWith("resource.")) {
235
- const [, resourceType, resourceId] = projectId$1.split(".");
236
- resourceType && resourceId && (newConfig.experimental_resource = {
237
- type: resourceType,
238
- id: resourceId
239
- });
240
- }
241
- const experimentalResource = newConfig.experimental_resource;
242
- experimentalResource && (newConfig.useProjectHostname = !1);
243
- const projectBased = newConfig.useProjectHostname;
233
+ }, projectBased = newConfig.useProjectHostname;
244
234
  if (typeof Promise > "u") {
245
235
  const helpUrl = generateHelpUrl("js-client-promise-polyfill");
246
236
  throw new Error(`No native Promise-implementation found, polyfill needed - see ${helpUrl}`);
@@ -266,11 +256,7 @@ const initConfig = (config, prevConfig) => {
266
256
  const isBrowser = typeof window < "u" && window.location && window.location.hostname, isLocalhost = isBrowser && isLocal(window.location.hostname);
267
257
  isBrowser && isLocalhost && newConfig.token && 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);
268
258
  const hostParts = newConfig.apiHost.split("://", 2), protocol = hostParts[0], host = hostParts[1], cdnHost = newConfig.isDefaultApi ? defaultCdnHost : host;
269
- if (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), experimentalResource) {
270
- const resourceSuffix = `${experimentalResource.type}/${experimentalResource.id}`;
271
- newConfig.url = `${newConfig.url}/${resourceSuffix}`, newConfig.cdnUrl = `${newConfig.cdnUrl}/${resourceSuffix}`;
272
- }
273
- return newConfig;
259
+ 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;
274
260
  };
275
261
  class ConnectionFailedError extends Error {
276
262
  name = "ConnectionFailedError";
@@ -310,7 +296,7 @@ function connectWithESInstance(es, events) {
310
296
  return new Observable((observer) => {
311
297
  const emitOpen = events.includes("open"), emitReconnect = events.includes("reconnect");
312
298
  function onError(evt) {
313
- if (console.log("Eventsource onError", evt, es.url), "data" in evt) {
299
+ if ("data" in evt) {
314
300
  const [parseError, event] = parseEvent(evt);
315
301
  observer.error(
316
302
  parseError ? new MessageParseError("Unable to parse EventSource error message", { cause: event }) : new MessageError((event?.data).message, event)
@@ -881,20 +867,11 @@ function _create(client, httpRequest, doc, op, options = {}) {
881
867
  const mutation = { [op]: doc }, opts = Object.assign({ returnFirst: !0, returnDocuments: !0 }, options);
882
868
  return _dataRequest(client, httpRequest, "mutate", { mutations: [mutation] }, opts);
883
869
  }
884
- function _resourceBase(resource) {
885
- return `/${resource.type}/${resource.id}`;
886
- }
887
- function isDataRequestUri(uri, resource) {
888
- return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/`) === 0 : uri.indexOf("/data/") === 0;
889
- }
890
- function isDataQueryRequestUri(uri, resource) {
891
- return resource ? uri.indexOf(`/${_resourceBase(resource)}/data/query`) === 0 : uri.indexOf("/data/query") === 0;
892
- }
893
870
  function _requestObservable(client, httpRequest, options) {
894
- const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && isDataRequestUri(uri, config.experimental_resource) : options.canUseCdn;
871
+ const uri = options.url || options.uri, config = client.config(), canUseCdn = typeof options.canUseCdn > "u" ? ["GET", "HEAD"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/") === 0 : options.canUseCdn;
895
872
  let useCdn = (options.useCdn ?? config.useCdn) && canUseCdn;
896
873
  const tag = options.tag && config.requestTagPrefix ? [config.requestTagPrefix, options.tag].join(".") : options.tag || config.requestTagPrefix;
897
- if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && isDataQueryRequestUri(uri, config.experimental_resource)) {
874
+ if (tag && options.tag !== null && (options.query = { tag: requestTag(tag), ...options.query }), ["GET", "HEAD", "POST"].indexOf(options.method || "GET") >= 0 && uri.indexOf("/data/query/") === 0) {
898
875
  const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
899
876
  resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
900
877
  const perspectiveOption = options.perspective || config.perspective;
@@ -920,18 +897,12 @@ function _request(client, httpRequest, options) {
920
897
  );
921
898
  }
922
899
  function _getDataUrl(client, operation, path) {
923
- const config = client.config();
924
- if (config.experimental_resource) {
925
- const baseUri2 = `/${operation}`;
926
- return (path ? `${baseUri2}/${path}` : baseUri2).replace(/\/($|\?)/, "$1");
927
- }
928
- const catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
900
+ const config = client.config(), catalog = hasDataset(config), baseUri = `/${operation}/${catalog}`;
929
901
  return `/data${path ? `${baseUri}/${path}` : baseUri}`.replace(/\/($|\?)/, "$1");
930
902
  }
931
903
  function _getUrl(client, uri, canUseCdn = !1) {
932
- const { url, cdnUrl, experimental_resource } = client.config();
933
- let base = canUseCdn ? cdnUrl : url;
934
- return experimental_resource && uri.indexOf("/users") !== -1 && (base = base.replace(_resourceBase(experimental_resource), "")), `${base}/${uri.replace(/^\//, "")}`;
904
+ const { url, cdnUrl } = client.config();
905
+ return `${canUseCdn ? cdnUrl : url}/${uri.replace(/^\//, "")}`;
935
906
  }
936
907
  function _withAbortSignal(signal) {
937
908
  return (input) => new Observable((observer) => {
@@ -985,7 +956,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
985
956
  validateAssetType(assetType);
986
957
  let meta = opts.extract || void 0;
987
958
  meta && !meta.length && (meta = ["none"]);
988
- const config = client.config(), dataset2 = config.experimental_resource ? void 0 : hasDataset(config), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
959
+ const dataset2 = hasDataset(client.config()), assetEndpoint = assetType === "image" ? "images" : "files", options = optionsFromFile(opts, body), { tag, label, title, description, creditLine, filename, source } = options, query = {
989
960
  label,
990
961
  title,
991
962
  description,
@@ -997,7 +968,7 @@ function _upload(client, httpRequest, assetType, body, opts = {}) {
997
968
  tag,
998
969
  method: "POST",
999
970
  timeout: options.timeout || 0,
1000
- uri: dataset2 ? `/assets/${assetEndpoint}/${dataset2}` : `/assets/${assetEndpoint}`,
971
+ uri: `/assets/${assetEndpoint}/${dataset2}`,
1001
972
  headers: options.contentType ? { "Content-Type": options.contentType } : {},
1002
973
  query,
1003
974
  body
@@ -1220,23 +1191,6 @@ class DatasetsClient {
1220
1191
  );
1221
1192
  }
1222
1193
  }
1223
- class ThrowingDatasetsClient extends DatasetsClient {
1224
- constructor(client, httpRequest) {
1225
- super(client, httpRequest);
1226
- }
1227
- create() {
1228
- throw new Error("cannot create dataset with the current client configuration");
1229
- }
1230
- edit() {
1231
- throw new Error("cannot edit dataset with the current client configuration");
1232
- }
1233
- delete() {
1234
- throw new Error("cannot delete dataset with the current client configuration");
1235
- }
1236
- list() {
1237
- throw new Error("cannot list dataset with the current client configuration");
1238
- }
1239
- }
1240
1194
  function _modify(client, httpRequest, method, name, options) {
1241
1195
  return dataset(name), _request(client, httpRequest, {
1242
1196
  method,
@@ -1492,7 +1446,7 @@ class SanityClient {
1492
1446
  */
1493
1447
  listen = _listen;
1494
1448
  constructor(httpRequest, config = defaultConfig) {
1495
- this.config(config), this.#httpRequest = httpRequest, this.assets = new AssetsClient(this, this.#httpRequest), this.datasets = this.#clientConfig.experimental_resource ? new ThrowingDatasetsClient(this, this.#httpRequest) : 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);
1449
+ 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);
1496
1450
  }
1497
1451
  /**
1498
1452
  * Clone the client - returns a new instance