@prismicio/client 7.21.0-pr.420.7e9c320 → 7.21.0-pr.420.a67a5d5

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/Client.cjs CHANGED
@@ -1,6 +1,5 @@
1
1
  const require_filter = require('./filter.cjs');
2
2
  const require_appendFilters = require('./lib/appendFilters.cjs');
3
- const require_castThunk = require('./lib/castThunk.cjs');
4
3
  const require_devMsg = require('./lib/devMsg.cjs');
5
4
  const require_everyTagFilter = require('./lib/everyTagFilter.cjs');
6
5
  const require_PrismicError = require('./errors/PrismicError.cjs');
@@ -54,28 +53,6 @@ const GET_ALL_QUERY_DELAY = 500;
54
53
  */
55
54
  const MAX_INVALID_REF_RETRY_ATTEMPTS = 3;
56
55
  /**
57
- * Modes for client ref management.
58
- */
59
- var RefStateMode = /* @__PURE__ */ function(RefStateMode$1) {
60
- /**
61
- * Use the repository's master ref.
62
- */
63
- RefStateMode$1["Master"] = "Master";
64
- /**
65
- * Use a given Release identified by its ID.
66
- */
67
- RefStateMode$1["ReleaseID"] = "ReleaseID";
68
- /**
69
- * Use a given Release identified by its label.
70
- */
71
- RefStateMode$1["ReleaseLabel"] = "ReleaseLabel";
72
- /**
73
- * Use a given ref.
74
- */
75
- RefStateMode$1["Manual"] = "Manual";
76
- return RefStateMode$1;
77
- }(RefStateMode || {});
78
- /**
79
56
  * A client that allows querying content from a Prismic repository.
80
57
  *
81
58
  * If used in an environment where a global `fetch` function is unavailable,
@@ -158,14 +135,9 @@ var Client = class {
158
135
  * be overridden on each query if needed.
159
136
  */
160
137
  defaultParams;
161
- /**
162
- * The client's ref mode state. This determines which ref is used during
163
- * queries.
164
- */
165
- refState = {
166
- mode: RefStateMode.Master,
167
- autoPreviewsEnabled: true
168
- };
138
+ #getRef;
139
+ #autoPreviews = true;
140
+ #autoPreviewsRequest;
169
141
  #cachedRepository;
170
142
  #cachedRepositoryExpiration = 0;
171
143
  /**
@@ -183,7 +155,8 @@ var Client = class {
183
155
  * @returns A client that can query content from the repository.
184
156
  */
185
157
  constructor(repositoryNameOrEndpoint, options = {}) {
186
- const { documentAPIEndpoint, accessToken, ref, routes, brokenRoute, defaultParams, fetchOptions = {}, fetch = globalThis.fetch } = options;
158
+ var _globalThis$fetch;
159
+ const { documentAPIEndpoint, accessToken, ref, routes, brokenRoute, defaultParams, fetchOptions = {}, fetch = (_globalThis$fetch = globalThis.fetch) === null || _globalThis$fetch === void 0 ? void 0 : _globalThis$fetch.bind(globalThis) } = options;
187
160
  if (require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint)) {
188
161
  try {
189
162
  this.repositoryName = require_getRepositoryName.getRepositoryName(repositoryNameOrEndpoint);
@@ -195,9 +168,10 @@ var Client = class {
195
168
  this.repositoryName = repositoryNameOrEndpoint;
196
169
  this.documentAPIEndpoint = documentAPIEndpoint || require_getRepositoryEndpoint.getRepositoryEndpoint(repositoryNameOrEndpoint);
197
170
  }
198
- if (!fetch) throw new require_PrismicError.PrismicError("A valid fetch implementation was not provided. In environments where fetch is not available (including Node.js), a fetch implementation must be provided via a polyfill or the `fetch` option.", void 0, void 0);
171
+ if (!fetch) throw new require_PrismicError.PrismicError("A valid fetch implementation was not provided. In environments where fetch is not available, a fetch implementation must be provided via a polyfill or the `fetch` option.", void 0, void 0);
199
172
  if (typeof fetch !== "function") throw new require_PrismicError.PrismicError(`fetch must be a function, but received: ${typeof fetch}`, void 0, void 0);
200
173
  if (!require_isRepositoryEndpoint.isRepositoryEndpoint(this.documentAPIEndpoint)) throw new require_PrismicError.PrismicError(`documentAPIEndpoint is not a valid URL: ${documentAPIEndpoint}`, void 0, void 0);
174
+ if (require_isRepositoryEndpoint.isRepositoryEndpoint(repositoryNameOrEndpoint) && documentAPIEndpoint && repositoryNameOrEndpoint !== options.documentAPIEndpoint) console.warn(`[@prismicio/client] Multiple incompatible endpoints were provided. Create the client using a repository name to prevent this error. For more details, see ${require_devMsg.devMsg("prefer-repository-name")}`);
201
175
  if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(this.documentAPIEndpoint) && process.env.NODE_ENV === "development") throw new require_PrismicError.PrismicError("@prismicio/client only supports Prismic Rest API V2. Please provide only the repository name to the first createClient() parameter or use the getRepositoryEndpoint() helper to generate a valid Rest API V2 endpoint URL.", void 0, void 0);
202
176
  if (/(?<!\.cdn)\.prismic\.io$/i.test(new URL(this.documentAPIEndpoint).hostname) && process.env.NODE_ENV === "development") console.warn(`[@prismicio/client] The client was created with a non-CDN endpoint. Convert it to the CDN endpoint for better performance. For more details, see ${require_devMsg.devMsg("endpoint-must-use-cdn")}`);
203
177
  this.accessToken = accessToken;
@@ -206,9 +180,8 @@ var Client = class {
206
180
  this.defaultParams = defaultParams;
207
181
  this.fetchOptions = fetchOptions;
208
182
  this.fetchFn = fetch;
209
- if (this.fetchFn === globalThis.fetch) this.fetchFn = this.fetchFn.bind(globalThis);
210
- if (ref) this.queryContentFromRef(ref);
211
183
  this.graphQLFetch = this.graphQLFetch.bind(this);
184
+ if (ref) this.queryContentFromRef(ref);
212
185
  }
213
186
  /**
214
187
  * Enables the client to automatically query content from a preview session.
@@ -222,7 +195,7 @@ var Client = class {
222
195
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviews}
223
196
  */
224
197
  enableAutoPreviews() {
225
- this.refState.autoPreviewsEnabled = true;
198
+ this.#autoPreviews = true;
226
199
  }
227
200
  /**
228
201
  * Enables the client to automatically query content from a preview session
@@ -236,9 +209,9 @@ var Client = class {
236
209
  *
237
210
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#enableautopreviewsfromreq}
238
211
  */
239
- enableAutoPreviewsFromReq(req) {
240
- this.refState.httpRequest = req;
241
- this.refState.autoPreviewsEnabled = true;
212
+ enableAutoPreviewsFromReq(request$1) {
213
+ this.enableAutoPreviews();
214
+ this.#autoPreviewsRequest = request$1;
242
215
  }
243
216
  /**
244
217
  * Disables the client from automatically querying content from a preview
@@ -253,7 +226,8 @@ var Client = class {
253
226
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#disableautopreviews}
254
227
  */
255
228
  disableAutoPreviews() {
256
- this.refState.autoPreviewsEnabled = false;
229
+ this.#autoPreviews = false;
230
+ this.#autoPreviewsRequest = void 0;
257
231
  }
258
232
  /**
259
233
  * Fetches pages based on the `params` argument. Results are paginated.
@@ -267,8 +241,7 @@ var Client = class {
267
241
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#get}
268
242
  */
269
243
  async get(params) {
270
- const { data } = await this._get(params);
271
- return data;
244
+ return await (await this.#internalGet(params)).json();
272
245
  }
273
246
  /**
274
247
  * Fetches the first page returned based on the `params` argument.
@@ -282,15 +255,14 @@ var Client = class {
282
255
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#getfirst}
283
256
  */
284
257
  async getFirst(params) {
285
- const actualParams = { ...params };
286
- if (!(params && params.page) && !(params === null || params === void 0 ? void 0 : params.pageSize)) {
287
- var _this$defaultParams;
288
- actualParams.pageSize = ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) ?? 1;
289
- }
290
- const { data, url } = await this._get(actualParams);
291
- const firstResult = data.results[0];
292
- if (firstResult) return firstResult;
293
- throw new require_NotFoundError.NotFoundError("No documents were returned", url, void 0);
258
+ const actualParams = (params === null || params === void 0 ? void 0 : params.page) || (params === null || params === void 0 ? void 0 : params.pageSize) ? params : {
259
+ ...params,
260
+ pageSize: 1
261
+ };
262
+ const response = await this.#internalGet(actualParams);
263
+ const { results } = await response.clone().json();
264
+ if (results[0]) return results[0];
265
+ throw new require_NotFoundError.NotFoundError("No documents were returned", response.url, void 0);
294
266
  }
295
267
  /**
296
268
  * Fetches all pages based on the `params` argument. This method may make
@@ -305,11 +277,11 @@ var Client = class {
305
277
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#dangerouslygetall}
306
278
  */
307
279
  async dangerouslyGetAll(params = {}) {
308
- var _this$defaultParams2;
280
+ var _this$defaultParams;
309
281
  const { limit = Infinity,...actualParams } = params;
310
282
  const resolvedParams = {
311
283
  ...actualParams,
312
- pageSize: Math.min(limit, actualParams.pageSize || ((_this$defaultParams2 = this.defaultParams) === null || _this$defaultParams2 === void 0 ? void 0 : _this$defaultParams2.pageSize) || MAX_PAGE_SIZE)
284
+ pageSize: Math.min(limit, actualParams.pageSize || ((_this$defaultParams = this.defaultParams) === null || _this$defaultParams === void 0 ? void 0 : _this$defaultParams.pageSize) || MAX_PAGE_SIZE)
313
285
  };
314
286
  const documents = [];
315
287
  let latestResult;
@@ -571,18 +543,13 @@ var Client = class {
571
543
  const accessToken = (params === null || params === void 0 ? void 0 : params.accessToken) || this.accessToken;
572
544
  if (accessToken) url.searchParams.set("access_token", accessToken);
573
545
  const response = await this.#request(url, params);
574
- switch (response.status) {
575
- case 200:
576
- this.#cachedRepository = await response.json();
577
- this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
578
- return this.#cachedRepository;
579
- case 401: {
580
- const json = await response.json();
581
- throw new require_ForbiddenError.ForbiddenError(json.error, url.toString(), json);
582
- }
583
- case 404: throw new require_RepositoryNotFoundError.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
584
- default: throw new require_PrismicError.PrismicError(void 0, url.toString(), await response.text());
546
+ if (response.ok) {
547
+ this.#cachedRepository = await response.json();
548
+ this.#cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
549
+ return this.#cachedRepository;
585
550
  }
551
+ if (response.status === 404) throw new require_RepositoryNotFoundError.RepositoryNotFoundError(`Prismic repository not found. Check that "${this.documentAPIEndpoint}" is pointing to the correct repository.`, url.toString(), void 0);
552
+ return await this.#throwContentAPIError(response, url.toString());
586
553
  }
587
554
  /**
588
555
  * Fetches the repository's active refs.
@@ -720,7 +687,7 @@ var Client = class {
720
687
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#buildqueryurl}
721
688
  */
722
689
  async buildQueryURL({ signal, fetchOptions,...params } = {}) {
723
- const ref = params.ref || await this.getResolvedRefString({
690
+ const ref = params.ref || await this.#getResolvedRef({
724
691
  accessToken: params.accessToken,
725
692
  signal,
726
693
  fetchOptions
@@ -761,13 +728,13 @@ var Client = class {
761
728
  const searchParams = new URLSearchParams(globalThis.location.search);
762
729
  documentID = documentID || searchParams.get("documentId");
763
730
  previewToken = previewToken || searchParams.get("token");
764
- } else if (this.refState.httpRequest) {
765
- if ("query" in this.refState.httpRequest) {
766
- var _this$refState$httpRe, _this$refState$httpRe2;
767
- documentID = documentID || ((_this$refState$httpRe = this.refState.httpRequest.query) === null || _this$refState$httpRe === void 0 ? void 0 : _this$refState$httpRe.documentId);
768
- previewToken = previewToken || ((_this$refState$httpRe2 = this.refState.httpRequest.query) === null || _this$refState$httpRe2 === void 0 ? void 0 : _this$refState$httpRe2.token);
769
- } else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
770
- const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
731
+ } else if (this.#autoPreviewsRequest) {
732
+ if ("query" in this.#autoPreviewsRequest) {
733
+ var _this$autoPreviewsReq, _this$autoPreviewsReq2;
734
+ documentID = documentID || ((_this$autoPreviewsReq = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq === void 0 ? void 0 : _this$autoPreviewsReq.documentId);
735
+ previewToken = previewToken || ((_this$autoPreviewsReq2 = this.#autoPreviewsRequest.query) === null || _this$autoPreviewsReq2 === void 0 ? void 0 : _this$autoPreviewsReq2.token);
736
+ } else if ("url" in this.#autoPreviewsRequest && this.#autoPreviewsRequest.url) {
737
+ const searchParams = new URL(this.#autoPreviewsRequest.url, "missing-host://").searchParams;
771
738
  documentID = documentID || searchParams.get("documentId");
772
739
  previewToken = previewToken || searchParams.get("token");
773
740
  }
@@ -796,7 +763,7 @@ var Client = class {
796
763
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querylatestcontent}
797
764
  */
798
765
  queryLatestContent() {
799
- this.refState.mode = RefStateMode.Master;
766
+ this.#getRef = void 0;
800
767
  }
801
768
  /**
802
769
  * Configures the client to query content from a release with a specific ID.
@@ -809,11 +776,9 @@ var Client = class {
809
776
  *
810
777
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebyid}
811
778
  */
812
- queryContentFromReleaseByID(releaseID) {
813
- this.refState = {
814
- ...this.refState,
815
- mode: RefStateMode.ReleaseID,
816
- releaseID
779
+ queryContentFromReleaseByID(id) {
780
+ this.#getRef = async (params) => {
781
+ return (await this.getReleaseByID(id, params)).ref;
817
782
  };
818
783
  }
819
784
  /**
@@ -828,11 +793,9 @@ var Client = class {
828
793
  *
829
794
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromreleasebylabel}
830
795
  */
831
- queryContentFromReleaseByLabel(releaseLabel) {
832
- this.refState = {
833
- ...this.refState,
834
- mode: RefStateMode.ReleaseLabel,
835
- releaseLabel
796
+ queryContentFromReleaseByLabel(label) {
797
+ this.#getRef = async (params) => {
798
+ return (await this.getReleaseByLabel(label, params)).ref;
836
799
  };
837
800
  }
838
801
  /**
@@ -847,11 +810,7 @@ var Client = class {
847
810
  * @see {@link https://prismic.io/docs/technical-reference/prismicio-client/v7#querycontentfromref}
848
811
  */
849
812
  queryContentFromRef(ref) {
850
- this.refState = {
851
- ...this.refState,
852
- mode: RefStateMode.Manual,
853
- ref
854
- };
813
+ this.#getRef = typeof ref === "string" ? () => ref : ref;
855
814
  }
856
815
  /**
857
816
  * A preconfigured `fetch()` function for Prismic's GraphQL API that can be
@@ -879,7 +838,7 @@ var Client = class {
879
838
  */
880
839
  async graphQLFetch(input, init) {
881
840
  const repository = await this.getRepository();
882
- const ref = await this.getResolvedRefString();
841
+ const ref = await this.#getResolvedRef();
883
842
  const unsanitizedHeaders = {
884
843
  "Prismic-ref": ref,
885
844
  Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
@@ -920,90 +879,61 @@ var Client = class {
920
879
  *
921
880
  * @returns The ref to use during a query.
922
881
  */
923
- async getResolvedRefString(params) {
924
- if (this.refState.autoPreviewsEnabled) {
925
- var _this$refState$httpRe3, _globalThis$document;
926
- let previewRef;
927
- let cookieJar;
928
- if ((_this$refState$httpRe3 = this.refState.httpRequest) === null || _this$refState$httpRe3 === void 0 ? void 0 : _this$refState$httpRe3.headers) {
929
- if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") cookieJar = this.refState.httpRequest.headers.get("cookie");
930
- else if ("cookie" in this.refState.httpRequest.headers) cookieJar = this.refState.httpRequest.headers.cookie;
931
- } else if ((_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.cookie) cookieJar = globalThis.document.cookie;
932
- if (cookieJar) previewRef = require_getPreviewCookie.getPreviewCookie(cookieJar);
882
+ async #getResolvedRef(params) {
883
+ var _this$getRef;
884
+ if (this.#autoPreviews) {
885
+ var _this$autoPreviewsReq3, _globalThis$document;
886
+ const previewRef = require_getPreviewCookie.getPreviewCookie((((_this$autoPreviewsReq3 = this.#autoPreviewsRequest) === null || _this$autoPreviewsReq3 === void 0 ? void 0 : _this$autoPreviewsReq3.headers) ? "get" in this.#autoPreviewsRequest.headers ? this.#autoPreviewsRequest.headers.get("cookie") : this.#autoPreviewsRequest.headers.cookie : (_globalThis$document = globalThis.document) === null || _globalThis$document === void 0 ? void 0 : _globalThis$document.cookie) ?? "");
933
887
  if (previewRef) return previewRef;
934
888
  }
935
- const repository = await this.getRepository(params);
936
- const refModeType = this.refState.mode;
937
- if (refModeType === RefStateMode.ReleaseID) return require_findRefByID.findRefByID(repository.refs, this.refState.releaseID).ref;
938
- else if (refModeType === RefStateMode.ReleaseLabel) return require_findRefByLabel.findRefByLabel(repository.refs, this.refState.releaseLabel).ref;
939
- else if (refModeType === RefStateMode.Manual) {
940
- const res = await require_castThunk.castThunk(this.refState.ref)();
941
- if (typeof res === "string") return res;
942
- }
943
- return require_findMasterRef.findMasterRef(repository.refs).ref;
889
+ const ref = await ((_this$getRef = this.#getRef) === null || _this$getRef === void 0 ? void 0 : _this$getRef.call(this, params));
890
+ if (ref) return ref;
891
+ return (await this.getMasterRef(params)).ref;
944
892
  }
945
- /**
946
- * The private implementation of `this.get`. It returns the API response and
947
- * the URL used to make the request. The URL is sometimes used in the public
948
- * method to include in thrown errors.
949
- *
950
- * This method retries requests that throw `RefNotFoundError` or
951
- * `RefExpiredError`. It contains special logic to retry with the latest
952
- * master ref, provided in the API's error message.
953
- *
954
- * @typeParam TDocument - Type of Prismic documents returned.
955
- *
956
- * @param params - Parameters to filter, sort, and paginate results.
957
- *
958
- * @returns An object containing the paginated response containing the result
959
- * of the query and the URL used to make the API request.
960
- */
961
- async _get(params, attemptCount = 0) {
893
+ async #internalGet(params, attempt = 1) {
962
894
  const url = await this.buildQueryURL(params);
895
+ const response = await this.#request(new URL(url), params);
896
+ if (response.ok) return response;
963
897
  try {
964
- const response = await this.#request(new URL(url), params);
965
- switch (response.status) {
966
- case 200: try {
967
- return {
968
- data: await response.clone().json(),
969
- url
970
- };
971
- } catch {
972
- throw new require_PrismicError.PrismicError(void 0, url, await response.text());
973
- }
974
- case 400: {
975
- const json = await response.json();
976
- throw new require_ParsingError.ParsingError(json.message, url, json);
977
- }
978
- case 401: {
979
- const json = await response.json();
980
- throw new require_ForbiddenError.ForbiddenError(json.message, url, json);
981
- }
982
- case 404: {
983
- const json = await response.json();
984
- switch (json.type) {
985
- case "api_notfound_error": throw new require_RefNotFoundError.RefNotFoundError(json.message, url, json);
986
- case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_PreviewTokenExpired.PreviewTokenExpiredError(json.message, url, json);
987
- default: throw new require_NotFoundError.NotFoundError(json.message, url, json);
988
- }
989
- }
990
- case 410: {
991
- const json = await response.json();
992
- throw new require_RefExpiredError.RefExpiredError(json.message, url, json);
898
+ return await this.#throwContentAPIError(response, url);
899
+ } catch (error) {
900
+ if ((error instanceof require_RefNotFoundError.RefNotFoundError || error instanceof require_RefExpiredError.RefExpiredError) && attempt < MAX_INVALID_REF_RETRY_ATTEMPTS) {
901
+ var _error$message$match;
902
+ if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
903
+ const masterRef = (_error$message$match = error.message.match(/master ref is: (?<ref>.*)$/i)) === null || _error$message$match === void 0 || (_error$message$match = _error$message$match.groups) === null || _error$message$match === void 0 ? void 0 : _error$message$match.ref;
904
+ if (!masterRef) throw error;
905
+ require_throttledLog.throttledLog(`[@prismicio/client] The ref (${new URL(url).searchParams.get("ref")}) was ${error instanceof require_RefNotFoundError.RefNotFoundError ? "invalid" : "expired"}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`, { level: "warn" });
906
+ return await this.#internalGet({
907
+ ...params,
908
+ ref: masterRef
909
+ }, attempt + 1);
910
+ }
911
+ throw error;
912
+ }
913
+ }
914
+ async #throwContentAPIError(response, url) {
915
+ switch (response.status) {
916
+ case 400: {
917
+ const json = await response.clone().json();
918
+ throw new require_ParsingError.ParsingError(json.message, url, json);
919
+ }
920
+ case 401: {
921
+ const json = await response.clone().json();
922
+ throw new require_ForbiddenError.ForbiddenError(json.message, url, json);
923
+ }
924
+ case 404: {
925
+ const json = await response.clone().json();
926
+ switch (json.type) {
927
+ case "api_notfound_error": throw new require_RefNotFoundError.RefNotFoundError(json.message, url, json);
928
+ case "api_security_error": if (/preview token.*expired/i.test(json.message)) throw new require_PreviewTokenExpired.PreviewTokenExpiredError(json.message, url, json);
929
+ default: throw new require_NotFoundError.NotFoundError(json.message, url, json);
993
930
  }
994
- default: throw new require_PrismicError.PrismicError(void 0, url, await response.text());
995
931
  }
996
- } catch (error) {
997
- var _error$message$match;
998
- if (!(error instanceof require_RefNotFoundError.RefNotFoundError || error instanceof require_RefExpiredError.RefExpiredError) || attemptCount >= MAX_INVALID_REF_RETRY_ATTEMPTS - 1) throw error;
999
- if (!(params === null || params === void 0 ? void 0 : params.ref)) this.#cachedRepository = void 0;
1000
- const masterRef = (_error$message$match = error.message.match(/master ref is: (?<ref>.*)$/i)) === null || _error$message$match === void 0 || (_error$message$match = _error$message$match.groups) === null || _error$message$match === void 0 ? void 0 : _error$message$match.ref;
1001
- if (!masterRef) throw error;
1002
- require_throttledLog.throttledLog(`[@prismicio/client] The ref (${new URL(url).searchParams.get("ref")}) was ${error instanceof require_RefNotFoundError.RefNotFoundError ? "invalid" : "expired"}. Now retrying with the latest master ref (${masterRef}). If you were previewing content, the response will not include draft content.`, { level: "warn" });
1003
- return await this._get({
1004
- ...params,
1005
- ref: masterRef
1006
- }, attemptCount + 1);
932
+ case 410: {
933
+ const json = await response.clone().json();
934
+ throw new require_RefExpiredError.RefExpiredError(json.message, url, json);
935
+ }
936
+ default: throw new require_PrismicError.PrismicError(void 0, url, await response.text());
1007
937
  }
1008
938
  }
1009
939
  /**
@@ -1016,11 +946,8 @@ var Client = class {
1016
946
  * @returns The response from the fetch request.
1017
947
  */
1018
948
  async #request(url, params) {
1019
- return await require_request.request(url, this._buildRequestInit(params), this.fetchFn);
1020
- }
1021
- _buildRequestInit(params) {
1022
949
  var _this$fetchOptions, _params$fetchOptions, _params$fetchOptions2, _this$fetchOptions2;
1023
- return {
950
+ return await require_request.request(url, {
1024
951
  ...this.fetchOptions,
1025
952
  ...params === null || params === void 0 ? void 0 : params.fetchOptions,
1026
953
  headers: {
@@ -1028,7 +955,7 @@ var Client = class {
1028
955
  ...params === null || params === void 0 || (_params$fetchOptions = params.fetchOptions) === null || _params$fetchOptions === void 0 ? void 0 : _params$fetchOptions.headers
1029
956
  },
1030
957
  signal: (params === null || params === void 0 || (_params$fetchOptions2 = params.fetchOptions) === null || _params$fetchOptions2 === void 0 ? void 0 : _params$fetchOptions2.signal) || (params === null || params === void 0 ? void 0 : params.signal) || ((_this$fetchOptions2 = this.fetchOptions) === null || _this$fetchOptions2 === void 0 ? void 0 : _this$fetchOptions2.signal)
1031
- };
958
+ }, this.fetchFn);
1032
959
  }
1033
960
  };
1034
961