@sanity/client 6.22.1-bundle-perspective → 6.22.2-bundle-perspective

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
@@ -103,7 +103,8 @@ function defineHttpRequest(envMiddleware) {
103
103
  ]);
104
104
  }
105
105
  function shouldRetry(err, attempt, options) {
106
- if (options.maxRetries === 0) return !1;
106
+ if (options.maxRetries === 0)
107
+ return !1;
107
108
  const isSafe = options.method === "GET" || options.method === "HEAD", isQuery = (options.uri || options.url).startsWith("/data/query"), isRetriableResponse = err.response && (err.response.statusCode === 429 || err.response.statusCode === 502 || err.response.statusCode === 503);
108
109
  return (isSafe || isQuery) && isRetriableResponse ? !0 : middleware$1.retry.shouldRetry(err, attempt, options);
109
110
  }
@@ -534,6 +535,11 @@ const validateApiPerspective = function(perspective) {
534
535
  "Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
535
536
  );
536
537
  }
538
+ }, validateApiBundlePerspective = function(perspective, bundlePerspective) {
539
+ if (perspective !== "raw" && bundlePerspective)
540
+ throw new TypeError(
541
+ "Invalid, perspective and bundlePerspective parameters are mutually exclusive"
542
+ );
537
543
  }, initConfig = (config, prevConfig) => {
538
544
  const specifiedConfig = {
539
545
  ...prevConfig,
@@ -752,8 +758,10 @@ function _requestObservable(client, httpRequest, options) {
752
758
  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) {
753
759
  const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
754
760
  resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
755
- const perspective = options.perspective || config.perspective, bundlePerspective = options.bundlePerspective || config.bundlePerspective;
756
- typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), typeof bundlePerspective == "string" && (options.query = { perspective: void 0, bundlePerspective, ...options.query }), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
761
+ const perspective = options.perspective || config.perspective;
762
+ typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning()));
763
+ const bundlePerspective = options.bundlePerspective || config.bundlePerspective;
764
+ Array.isArray(bundlePerspective) && bundlePerspective.length > 0 && (validateApiBundlePerspective(perspective, bundlePerspective), options.query = { perspective: void 0, bundlePerspective, ...options.query }), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
757
765
  }
758
766
  const reqOptions = requestOptions(
759
767
  config,
@@ -945,27 +953,33 @@ class LiveClient {
945
953
  * Requires `apiVersion` to be `2021-03-26` or later.
946
954
  */
947
955
  events({
948
- includeDrafts = !1
956
+ includeDrafts = !1,
957
+ tag: _tag
949
958
  } = {}) {
950
- const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
959
+ const {
960
+ apiVersion: _apiVersion,
961
+ token,
962
+ withCredentials,
963
+ requestTagPrefix
964
+ } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
951
965
  if (apiVersion !== "X" && apiVersion < requiredApiVersion)
952
966
  throw new Error(
953
967
  `The live events API requires API version ${requiredApiVersion} or later. The current API version is ${apiVersion}. Please update your API version to use this feature.`
954
968
  );
955
- if (includeDrafts && !token)
969
+ if (includeDrafts && !token && !withCredentials)
956
970
  throw new Error(
957
- "The live events API requires a token when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role."
971
+ "The live events API requires a token or withCredentials when 'includeDrafts: true'. Please update your client configuration. The token should have the lowest possible access role."
958
972
  );
959
973
  if (includeDrafts && apiVersion !== "X")
960
974
  throw new Error(
961
975
  "The live events API requires API version X when 'includeDrafts: true'. This API is experimental and may change or even be removed."
962
976
  );
963
- const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1));
964
- includeDrafts && url.searchParams.set("includeDrafts", "true");
965
- const listenFor = ["restart", "message"], esOptions = {};
977
+ const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
978
+ tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
979
+ const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {};
966
980
  return includeDrafts && token && (esOptions.headers = {
967
981
  Authorization: `Bearer ${token}`
968
- }), new rxjs.Observable((observer) => {
982
+ }), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new rxjs.Observable((observer) => {
969
983
  let es, reconnectTimer, stopped = !1, unsubscribed = !1;
970
984
  open();
971
985
  function onError(evt) {
@@ -990,7 +1004,7 @@ class LiveClient {
990
1004
  }
991
1005
  }
992
1006
  async function getEventSource() {
993
- const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
1007
+ const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
994
1008
  if (unsubscribed)
995
1009
  return;
996
1010
  const evs = new EventSourceImplementation(url.toString(), esOptions);
@@ -1537,7 +1551,7 @@ function defineDeprecatedCreateClient(createClient2) {
1537
1551
  return printNoDefaultExport(), createClient2(config);
1538
1552
  };
1539
1553
  }
1540
- var name = "@sanity/client", version = "6.22.1-bundle-perspective";
1554
+ var name = "@sanity/client", version = "6.22.2-bundle-perspective";
1541
1555
  const middleware = [
1542
1556
  middleware$1.debug({ verbose: !0, namespace: "sanity:client" }),
1543
1557
  middleware$1.headers({ "User-Agent": `${name} ${version}` }),