@sanity/client 6.22.1 → 6.22.2-bundle-perspective-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.
@@ -535,6 +535,11 @@ const validateApiPerspective = function(perspective) {
535
535
  "Invalid API perspective string, expected `published`, `previewDrafts` or `raw`"
536
536
  );
537
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
+ );
538
543
  }, initConfig = (config, prevConfig) => {
539
544
  const specifiedConfig = {
540
545
  ...prevConfig,
@@ -715,6 +720,7 @@ function _dataRequest(client, httpRequest, endpoint, body, options = {}) {
715
720
  tag,
716
721
  returnQuery,
717
722
  perspective: options.perspective,
723
+ bundlePerspective: options.bundlePerspective,
718
724
  resultSourceMap: options.resultSourceMap,
719
725
  lastLiveEventId: Array.isArray(lastLiveEventId) ? lastLiveEventId[0] : lastLiveEventId,
720
726
  canUseCdn: isQuery,
@@ -753,7 +759,13 @@ function _requestObservable(client, httpRequest, options) {
753
759
  const resultSourceMap = options.resultSourceMap ?? config.resultSourceMap;
754
760
  resultSourceMap !== void 0 && resultSourceMap !== !1 && (options.query = { resultSourceMap, ...options.query });
755
761
  const perspective = options.perspective || config.perspective;
756
- typeof perspective == "string" && perspective !== "raw" && (validateApiPerspective(perspective), options.query = { perspective, ...options.query }, perspective === "previewDrafts" && useCdn && (useCdn = !1, printCdnPreviewDraftsWarning())), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
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 = {
765
+ perspective: void 0,
766
+ bundlePerspective: bundlePerspective.join(","),
767
+ ...options.query
768
+ }), options.lastLiveEventId && (options.query = { ...options.query, lastLiveEventId: options.lastLiveEventId }), options.returnQuery === !1 && (options.query = { returnQuery: "false", ...options.query });
757
769
  }
758
770
  const reqOptions = requestOptions(
759
771
  config,
@@ -945,27 +957,33 @@ class LiveClient {
945
957
  * Requires `apiVersion` to be `2021-03-26` or later.
946
958
  */
947
959
  events({
948
- includeDrafts = !1
960
+ includeDrafts = !1,
961
+ tag: _tag
949
962
  } = {}) {
950
- const { apiVersion: _apiVersion, token } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
963
+ const {
964
+ apiVersion: _apiVersion,
965
+ token,
966
+ withCredentials,
967
+ requestTagPrefix
968
+ } = this.#client.config(), apiVersion = _apiVersion.replace(/^v/, "");
951
969
  if (apiVersion !== "X" && apiVersion < requiredApiVersion)
952
970
  throw new Error(
953
971
  `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
972
  );
955
- if (includeDrafts && !token)
973
+ if (includeDrafts && !token && !withCredentials)
956
974
  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."
975
+ "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
976
  );
959
977
  if (includeDrafts && apiVersion !== "X")
960
978
  throw new Error(
961
979
  "The live events API requires API version X when 'includeDrafts: true'. This API is experimental and may change or even be removed."
962
980
  );
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 = {};
981
+ const path = _getDataUrl(this.#client, "live/events"), url = new URL(this.#client.getUrl(path, !1)), tag = _tag && requestTagPrefix ? [requestTagPrefix, _tag].join(".") : _tag;
982
+ tag && url.searchParams.set("tag", tag), includeDrafts && url.searchParams.set("includeDrafts", "true");
983
+ const listenFor = ["restart", "message", "welcome", "reconnect"], esOptions = {};
966
984
  return includeDrafts && token && (esOptions.headers = {
967
985
  Authorization: `Bearer ${token}`
968
- }), new rxjs.Observable((observer) => {
986
+ }), includeDrafts && withCredentials && (esOptions.withCredentials = !0), new rxjs.Observable((observer) => {
969
987
  let es, reconnectTimer, stopped = !1, unsubscribed = !1;
970
988
  open();
971
989
  function onError(evt) {
@@ -990,7 +1008,7 @@ class LiveClient {
990
1008
  }
991
1009
  }
992
1010
  async function getEventSource() {
993
- const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers ? (await import("@sanity/eventsource")).default : EventSource;
1011
+ const EventSourceImplementation = typeof EventSource > "u" || esOptions.headers || esOptions.withCredentials ? (await import("@sanity/eventsource")).default : EventSource;
994
1012
  if (unsubscribed)
995
1013
  return;
996
1014
  const evs = new EventSourceImplementation(url.toString(), esOptions);