prismic-ts-codegen 0.1.21 → 0.1.23-alpha.0

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.
Files changed (65) hide show
  1. package/dist/_node_modules/@babel/helper-validator-identifier/lib/index.cjs +1 -1
  2. package/dist/_node_modules/@babel/helper-validator-identifier/lib/index.js +1 -1
  3. package/dist/_node_modules/@babel/highlight/lib/index.cjs +2 -2
  4. package/dist/_node_modules/@babel/highlight/lib/index.js +2 -2
  5. package/dist/_node_modules/@prismicio/client/dist/BaseClient.cjs +97 -0
  6. package/dist/_node_modules/@prismicio/client/dist/BaseClient.cjs.map +1 -0
  7. package/dist/_node_modules/@prismicio/client/dist/BaseClient.js +97 -0
  8. package/dist/_node_modules/@prismicio/client/dist/BaseClient.js.map +1 -0
  9. package/dist/_node_modules/@prismicio/client/dist/Client.cjs +1179 -0
  10. package/dist/_node_modules/@prismicio/client/dist/Client.cjs.map +1 -0
  11. package/dist/_node_modules/@prismicio/client/dist/Client.js +1179 -0
  12. package/dist/_node_modules/@prismicio/client/dist/Client.js.map +1 -0
  13. package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.cjs +7 -0
  14. package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.cjs.map +1 -1
  15. package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.js +7 -0
  16. package/dist/_node_modules/@prismicio/client/dist/buildQueryURL.js.map +1 -1
  17. package/dist/_node_modules/@prismicio/client/dist/createClient.cjs +2 -1172
  18. package/dist/_node_modules/@prismicio/client/dist/createClient.cjs.map +1 -1
  19. package/dist/_node_modules/@prismicio/client/dist/createClient.js +1 -1171
  20. package/dist/_node_modules/@prismicio/client/dist/createClient.js.map +1 -1
  21. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +1 -4
  22. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +1 -1
  23. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +1 -4
  24. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +1 -1
  25. package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.cjs +7 -2
  26. package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.cjs.map +1 -1
  27. package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.js +7 -2
  28. package/dist/_node_modules/@prismicio/client/dist/getRepositoryName.js.map +1 -1
  29. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +9 -7
  30. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +1 -1
  31. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +9 -7
  32. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +1 -1
  33. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +1 -0
  34. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +1 -1
  35. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +1 -0
  36. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +1 -1
  37. package/dist/_node_modules/@prismicio/client/dist/lib/pLimit.cjs +49 -0
  38. package/dist/_node_modules/@prismicio/client/dist/lib/pLimit.cjs.map +1 -0
  39. package/dist/_node_modules/@prismicio/client/dist/lib/pLimit.js +49 -0
  40. package/dist/_node_modules/@prismicio/client/dist/lib/pLimit.js.map +1 -0
  41. package/dist/_node_modules/@prismicio/client/dist/package.json.cjs +1 -1
  42. package/dist/_node_modules/@prismicio/client/dist/package.json.cjs.map +1 -1
  43. package/dist/_node_modules/@prismicio/client/dist/package.json.js +1 -1
  44. package/dist/_node_modules/@prismicio/client/dist/package.json.js.map +1 -1
  45. package/dist/_node_modules/js-tokens/index.cjs +1 -1
  46. package/dist/_node_modules/js-tokens/index.js +1 -1
  47. package/dist/_node_modules/read-pkg/_node_modules/hosted-git-info/index.cjs +1 -1
  48. package/dist/_node_modules/read-pkg/_node_modules/hosted-git-info/index.js +1 -1
  49. package/dist/_virtual/index7.cjs +2 -2
  50. package/dist/_virtual/index7.js +2 -2
  51. package/dist/_virtual/index8.cjs +2 -2
  52. package/dist/_virtual/index8.js +2 -2
  53. package/dist/_virtual/index9.cjs +2 -2
  54. package/dist/_virtual/index9.js +2 -2
  55. package/dist/generateTypes.cjs +12 -0
  56. package/dist/generateTypes.cjs.map +1 -1
  57. package/dist/generateTypes.js +12 -0
  58. package/dist/generateTypes.js.map +1 -1
  59. package/dist/lib/buildFieldProperties.cjs +9 -8
  60. package/dist/lib/buildFieldProperties.cjs.map +1 -1
  61. package/dist/lib/buildFieldProperties.js +9 -8
  62. package/dist/lib/buildFieldProperties.js.map +1 -1
  63. package/package.json +6 -3
  64. package/src/generateTypes.ts +24 -0
  65. package/src/lib/buildFieldProperties.ts +9 -2
@@ -1,1176 +1,6 @@
1
- import { appendFilters } from "./lib/appendFilters.js";
2
- import { castThunk } from "./lib/castThunk.js";
3
- import { devMsg } from "./lib/devMsg.js";
4
- import { everyTagFilter } from "./lib/everyTagFilter.js";
5
- import { findMasterRef } from "./lib/findMasterRef.js";
6
- import { findRefByID } from "./lib/findRefByID.js";
7
- import { findRefByLabel } from "./lib/findRefByLabel.js";
8
- import { getPreviewCookie } from "./lib/getPreviewCookie.js";
9
- import { minifyGraphQLQuery } from "./lib/minifyGraphQLQuery.js";
10
- import { someTagsFilter } from "./lib/someTagsFilter.js";
11
- import { typeFilter } from "./lib/typeFilter.js";
12
- import { ForbiddenError } from "./errors/ForbiddenError.js";
13
- import { NotFoundError } from "./errors/NotFoundError.js";
14
- import { ParsingError } from "./errors/ParsingError.js";
15
- import { PreviewTokenExpiredError } from "./errors/PreviewTokenExpired.js";
16
- import { PrismicError } from "./errors/PrismicError.js";
17
- import { RefExpiredError } from "./errors/RefExpiredError.js";
18
- import { RefNotFoundError } from "./errors/RefNotFoundError.js";
19
- import { RepositoryNotFoundError } from "./errors/RepositoryNotFoundError.js";
20
- import { asLink } from "./helpers/asLink.js";
21
- import { buildQueryURL } from "./buildQueryURL.js";
22
- import { filter } from "./filter.js";
23
- import { getRepositoryEndpoint } from "./getRepositoryEndpoint.js";
24
- import { getRepositoryName } from "./getRepositoryName.js";
25
- import { isRepositoryEndpoint } from "./isRepositoryEndpoint.js";
26
- var __defProp = Object.defineProperty;
27
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
28
- var __publicField = (obj, key, value) => {
29
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
30
- return value;
31
- };
32
- const MAX_PAGE_SIZE = 100;
33
- const REPOSITORY_CACHE_TTL = 5e3;
34
- const GET_ALL_QUERY_DELAY = 500;
35
- const DEFUALT_RETRY_AFTER_MS = 1e3;
36
- var RefStateMode;
37
- (function(RefStateMode2) {
38
- RefStateMode2["Master"] = "Master";
39
- RefStateMode2["ReleaseID"] = "ReleaseID";
40
- RefStateMode2["ReleaseLabel"] = "ReleaseLabel";
41
- RefStateMode2["Manual"] = "Manual";
42
- })(RefStateMode || (RefStateMode = {}));
1
+ import { Client } from "./Client.js";
43
2
  const createClient = (repositoryNameOrEndpoint, options) => new Client(repositoryNameOrEndpoint, options);
44
- class Client {
45
- /**
46
- * Creates a Prismic client that can be used to query a repository.
47
- *
48
- * If used in an environment where a global `fetch` function is unavailable,
49
- * such as Node.js, the `fetch` option must be provided as part of the
50
- * `options` parameter.
51
- *
52
- * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
53
- * API V2 endpoint for the repository.
54
- * @param options - Configuration that determines how content will be queried
55
- * from the Prismic repository.
56
- *
57
- * @returns A client that can query content from the repository.
58
- */
59
- constructor(repositoryNameOrEndpoint, options = {}) {
60
- __publicField(this, "endpoint");
61
- __publicField(this, "accessToken");
62
- __publicField(this, "routes");
63
- __publicField(this, "brokenRoute");
64
- __publicField(this, "fetchFn");
65
- __publicField(this, "fetchOptions");
66
- __publicField(this, "defaultParams");
67
- __publicField(this, "refState", {
68
- mode: RefStateMode.Master,
69
- autoPreviewsEnabled: true
70
- });
71
- __publicField(this, "cachedRepository");
72
- __publicField(this, "cachedRepositoryExpiration", 0);
73
- __publicField(this, "fetchJobs", {});
74
- if (isRepositoryEndpoint(repositoryNameOrEndpoint)) {
75
- if (process.env.NODE_ENV === "development") {
76
- if (/\.prismic\.io\/(?!api\/v2\/?)/i.test(repositoryNameOrEndpoint)) {
77
- throw new 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);
78
- }
79
- const hostname = new URL(repositoryNameOrEndpoint).hostname.toLowerCase();
80
- if (hostname.endsWith(".prismic.io") && !hostname.endsWith(".cdn.prismic.io")) {
81
- const repositoryName = getRepositoryName(repositoryNameOrEndpoint);
82
- const dotCDNEndpoint = getRepositoryEndpoint(repositoryName);
83
- console.warn(`[@prismicio/client] A non-.cdn endpoint was provided to create a client with (\`${repositoryNameOrEndpoint}\`). Non-.cdn endpoints can have unexpected side-effects and cause performance issues when querying Prismic. Please convert it to the \`.cdn\` alternative (\`${dotCDNEndpoint}\`) or use the repository name directly instead (\`${repositoryName}\`). For more details, see ${devMsg("endpoint-must-use-cdn")}`);
84
- }
85
- }
86
- this.endpoint = repositoryNameOrEndpoint;
87
- } else {
88
- this.endpoint = getRepositoryEndpoint(repositoryNameOrEndpoint);
89
- }
90
- this.accessToken = options.accessToken;
91
- this.routes = options.routes;
92
- this.brokenRoute = options.brokenRoute;
93
- this.fetchOptions = options.fetchOptions;
94
- this.defaultParams = options.defaultParams;
95
- if (options.ref) {
96
- this.queryContentFromRef(options.ref);
97
- }
98
- if (typeof options.fetch === "function") {
99
- this.fetchFn = options.fetch;
100
- } else if (typeof globalThis.fetch === "function") {
101
- this.fetchFn = globalThis.fetch;
102
- } else {
103
- throw new 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);
104
- }
105
- if (this.fetchFn === globalThis.fetch) {
106
- this.fetchFn = this.fetchFn.bind(globalThis);
107
- }
108
- this.graphQLFetch = this.graphQLFetch.bind(this);
109
- }
110
- /**
111
- * Enables the client to automatically query content from a preview session if
112
- * one is active in browser environments. This is enabled by default in the
113
- * browser.
114
- *
115
- * For server environments, use `enableAutoPreviewsFromReq`.
116
- *
117
- * @example
118
- *
119
- * ```ts
120
- * client.enableAutoPreviews();
121
- * ```
122
- *
123
- * @see enableAutoPreviewsFromReq
124
- */
125
- enableAutoPreviews() {
126
- this.refState.autoPreviewsEnabled = true;
127
- }
128
- /**
129
- * Enables the client to automatically query content from a preview session if
130
- * one is active in server environments. This is disabled by default on the
131
- * server.
132
- *
133
- * For browser environments, use `enableAutoPreviews`.
134
- *
135
- * @example
136
- *
137
- * ```ts
138
- * // In an express app
139
- * app.get("/", function (req, res) {
140
- * client.enableAutoPreviewsFromReq(req);
141
- * });
142
- * ```
143
- *
144
- * @param req - An HTTP server request object containing the request's
145
- * cookies.
146
- */
147
- enableAutoPreviewsFromReq(req) {
148
- this.refState.httpRequest = req;
149
- this.refState.autoPreviewsEnabled = true;
150
- }
151
- /**
152
- * Disables the client from automatically querying content from a preview
153
- * session if one is active.
154
- *
155
- * Automatic preview content querying is enabled by default unless this method
156
- * is called.
157
- *
158
- * @example
159
- *
160
- * ```ts
161
- * client.disableAutoPreviews();
162
- * ```
163
- */
164
- disableAutoPreviews() {
165
- this.refState.autoPreviewsEnabled = false;
166
- }
167
- /**
168
- * Queries content from the Prismic repository.
169
- *
170
- * @example
171
- *
172
- * ```ts
173
- * const response = await client.get();
174
- * ```
175
- *
176
- * @typeParam TDocument - Type of Prismic documents returned.
177
- *
178
- * @param params - Parameters to filter, sort, and paginate results.
179
- *
180
- * @returns A paginated response containing the result of the query.
181
- */
182
- async get(params) {
183
- const url = await this.buildQueryURL(params);
184
- return await this.fetch(url, params);
185
- }
186
- /**
187
- * Queries content from the Prismic repository and returns only the first
188
- * result, if any.
189
- *
190
- * @example
191
- *
192
- * ```ts
193
- * const document = await client.getFirst();
194
- * ```
195
- *
196
- * @typeParam TDocument - Type of the Prismic document returned.
197
- *
198
- * @param params - Parameters to filter, sort, and paginate results. @returns
199
- * The first result of the query, if any.
200
- */
201
- async getFirst(params) {
202
- var _a;
203
- const actualParams = { ...params };
204
- if (!(params && params.page) && !(params == null ? void 0 : params.pageSize)) {
205
- actualParams.pageSize = ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) ?? 1;
206
- }
207
- const url = await this.buildQueryURL(actualParams);
208
- const result = await this.fetch(url, params);
209
- const firstResult = result.results[0];
210
- if (firstResult) {
211
- return firstResult;
212
- }
213
- throw new NotFoundError("No documents were returned", url, void 0);
214
- }
215
- /**
216
- * **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
217
- * require more resources than other methods. Prefer using other methods that
218
- * filter by filters such as `getAllByType`.
219
- *
220
- * Queries content from the Prismic repository and returns all matching
221
- * content. If no filters are provided, all documents will be fetched.
222
- *
223
- * This method may make multiple network requests to query all matching
224
- * content.
225
- *
226
- * @example
227
- *
228
- * ```ts
229
- * const response = await client.dangerouslyGetAll();
230
- * ```
231
- *
232
- * @typeParam TDocument - Type of Prismic documents returned.
233
- *
234
- * @param params - Parameters to filter, sort, and paginate results.
235
- *
236
- * @returns A list of documents matching the query.
237
- */
238
- async dangerouslyGetAll(params = {}) {
239
- var _a;
240
- const { limit = Infinity, ...actualParams } = params;
241
- const resolvedParams = {
242
- ...actualParams,
243
- pageSize: Math.min(limit, actualParams.pageSize || ((_a = this.defaultParams) == null ? void 0 : _a.pageSize) || MAX_PAGE_SIZE)
244
- };
245
- const documents = [];
246
- let latestResult;
247
- while ((!latestResult || latestResult.next_page) && documents.length < limit) {
248
- const page = latestResult ? latestResult.page + 1 : void 0;
249
- latestResult = await this.get({ ...resolvedParams, page });
250
- documents.push(...latestResult.results);
251
- if (latestResult.next_page) {
252
- await new Promise((res) => setTimeout(res, GET_ALL_QUERY_DELAY));
253
- }
254
- }
255
- return documents.slice(0, limit);
256
- }
257
- /**
258
- * Queries a document from the Prismic repository with a specific ID.
259
- *
260
- * @remarks
261
- * A document's UID is different from its ID. An ID is automatically generated
262
- * for all documents and is made available on its `id` property. A UID is
263
- * provided in the Prismic editor and is unique among all documents of its
264
- * custom type.
265
- *
266
- * @example
267
- *
268
- * ```ts
269
- * const document = await client.getByID("WW4bKScAAMAqmluX");
270
- * ```
271
- *
272
- * @typeParam TDocument- Type of the Prismic document returned.
273
- *
274
- * @param id - ID of the document.
275
- * @param params - Parameters to filter, sort, and paginate the results.
276
- *
277
- * @returns The document with an ID matching the `id` parameter, if a matching
278
- * document exists.
279
- */
280
- async getByID(id, params) {
281
- return await this.getFirst(appendFilters(params, filter.at("document.id", id)));
282
- }
283
- /**
284
- * Queries documents from the Prismic repository with specific IDs.
285
- *
286
- * @remarks
287
- * A document's UID is different from its ID. An ID is automatically generated
288
- * for all documents and is made available on its `id` property. A UID is
289
- * provided in the Prismic editor and is unique among all documents of its
290
- * custom type.
291
- *
292
- * @example
293
- *
294
- * ```ts
295
- * const response = await client.getByIDs([
296
- * "WW4bKScAAMAqmluX",
297
- * "U1kTRgEAAC8A5ldS",
298
- * ]);
299
- * ```
300
- *
301
- * @typeParam TDocument - Type of Prismic documents returned.
302
- *
303
- * @param ids - A list of document IDs.
304
- * @param params - Parameters to filter, sort, and paginate the results.
305
- *
306
- * @returns A paginated response containing documents with IDs matching the
307
- * `ids` parameter.
308
- */
309
- async getByIDs(ids, params) {
310
- return await this.get(appendFilters(params, filter.in("document.id", ids)));
311
- }
312
- /**
313
- * Queries all documents from the Prismic repository with specific IDs.
314
- *
315
- * This method may make multiple network requests to query all matching
316
- * content.
317
- *
318
- * @remarks
319
- * A document's UID is different from its ID. An ID is automatically generated
320
- * for all documents and is made available on its `id` property. A UID is
321
- * provided in the Prismic editor and is unique among all documents of its
322
- * custom type.
323
- *
324
- * @example
325
- *
326
- * ```ts
327
- * const response = await client.getAllByIDs([
328
- * "WW4bKScAAMAqmluX",
329
- * "U1kTRgEAAC8A5ldS",
330
- * ]);
331
- * ```
332
- *
333
- * @typeParam TDocument - Type of Prismic documents returned.
334
- *
335
- * @param ids - A list of document IDs.
336
- * @param params - Parameters to filter, sort, and paginate the results.
337
- *
338
- * @returns A list of documents with IDs matching the `ids` parameter.
339
- */
340
- async getAllByIDs(ids, params) {
341
- return await this.dangerouslyGetAll(appendFilters(params, filter.in("document.id", ids)));
342
- }
343
- /**
344
- * Queries a document from the Prismic repository with a specific UID and
345
- * custom type.
346
- *
347
- * @remarks
348
- * A document's UID is different from its ID. An ID is automatically generated
349
- * for all documents and is made available on its `id` property. A UID is
350
- * provided in the Prismic editor and is unique among all documents of its
351
- * custom type.
352
- *
353
- * @example
354
- *
355
- * ```ts
356
- * const document = await client.getByUID("blog_post", "my-first-post");
357
- * ```
358
- *
359
- * @typeParam TDocument - Type of the Prismic document returned.
360
- *
361
- * @param documentType - The API ID of the document's custom type.
362
- * @param uid - UID of the document.
363
- * @param params - Parameters to filter, sort, and paginate the results.
364
- *
365
- * @returns The document with a UID matching the `uid` parameter, if a
366
- * matching document exists.
367
- */
368
- async getByUID(documentType, uid, params) {
369
- return await this.getFirst(appendFilters(params, [
370
- typeFilter(documentType),
371
- filter.at(`my.${documentType}.uid`, uid)
372
- ]));
373
- }
374
- /**
375
- * Queries document from the Prismic repository with specific UIDs and Custom
376
- * Type.
377
- *
378
- * @remarks
379
- * A document's UID is different from its ID. An ID is automatically generated
380
- * for all documents and is made available on its `id` property. A UID is
381
- * provided in the Prismic editor and is unique among all documents of its
382
- * custom type.
383
- *
384
- * @example
385
- *
386
- * ```ts
387
- * const document = await client.getByUIDs("blog_post", [
388
- * "my-first-post",
389
- * "my-second-post",
390
- * ]);
391
- * ```
392
- *
393
- * @typeParam TDocument - Type of the Prismic document returned.
394
- *
395
- * @param documentType - The API ID of the document's custom type.
396
- * @param uids - A list of document UIDs.
397
- * @param params - Parameters to filter, sort, and paginate the results.
398
- *
399
- * @returns A paginated response containing documents with UIDs matching the
400
- * `uids` parameter.
401
- */
402
- async getByUIDs(documentType, uids, params) {
403
- return await this.get(appendFilters(params, [
404
- typeFilter(documentType),
405
- filter.in(`my.${documentType}.uid`, uids)
406
- ]));
407
- }
408
- /**
409
- * Queries all documents from the Prismic repository with specific UIDs and
410
- * custom type.
411
- *
412
- * This method may make multiple network requests to query all matching
413
- * content.
414
- *
415
- * @remarks
416
- * A document's UID is different from its ID. An ID is automatically generated
417
- * for all documents and is made available on its `id` property. A UID is
418
- * provided in the Prismic editor and is unique among all documents of its
419
- * custom type.
420
- *
421
- * @example
422
- *
423
- * ```ts
424
- * const response = await client.getAllByUIDs([
425
- * "my-first-post",
426
- * "my-second-post",
427
- * ]);
428
- * ```
429
- *
430
- * @typeParam TDocument - Type of Prismic documents returned.
431
- *
432
- * @param documentType - The API ID of the document's custom type.
433
- * @param uids - A list of document UIDs.
434
- * @param params - Parameters to filter, sort, and paginate the results.
435
- *
436
- * @returns A list of documents with UIDs matching the `uids` parameter.
437
- */
438
- async getAllByUIDs(documentType, uids, params) {
439
- return await this.dangerouslyGetAll(appendFilters(params, [
440
- typeFilter(documentType),
441
- filter.in(`my.${documentType}.uid`, uids)
442
- ]));
443
- }
444
- /**
445
- * Queries a singleton document from the Prismic repository for a specific
446
- * custom type.
447
- *
448
- * @remarks
449
- * A singleton document is one that is configured in Prismic to only allow one
450
- * instance. For example, a repository may be configured to contain just one
451
- * Settings document. This is in contrast to a repeatable custom type which
452
- * allows multiple instances of itself.
453
- *
454
- * @example
455
- *
456
- * ```ts
457
- * const document = await client.getSingle("settings");
458
- * ```
459
- *
460
- * @typeParam TDocument - Type of the Prismic document returned.
461
- *
462
- * @param documentType - The API ID of the singleton custom type.
463
- * @param params - Parameters to filter, sort, and paginate the results.
464
- *
465
- * @returns The singleton document for the custom type, if a matching document
466
- * exists.
467
- */
468
- async getSingle(documentType, params) {
469
- return await this.getFirst(appendFilters(params, typeFilter(documentType)));
470
- }
471
- /**
472
- * Queries documents from the Prismic repository for a specific custom type.
473
- *
474
- * Use `getAllByType` instead if you need to query all documents for a
475
- * specific custom type.
476
- *
477
- * @example
478
- *
479
- * ```ts
480
- * const response = await client.getByType("blog_post");
481
- * ```
482
- *
483
- * @typeParam TDocument - Type of Prismic documents returned.
484
- *
485
- * @param documentType - The API ID of the custom type.
486
- * @param params - Parameters to filter, sort, and paginate the results.
487
- *
488
- * @returns A paginated response containing documents of the custom type.
489
- */
490
- async getByType(documentType, params) {
491
- return await this.get(appendFilters(params, typeFilter(documentType)));
492
- }
493
- /**
494
- * Queries all documents from the Prismic repository for a specific Custom
495
- * Type.
496
- *
497
- * This method may make multiple network requests to query all matching
498
- * content.
499
- *
500
- * @example
501
- *
502
- * ```ts
503
- * const response = await client.getByType("blog_post");
504
- * ```
505
- *
506
- * @typeParam TDocument - Type of Prismic documents returned.
507
- *
508
- * @param documentType - The API ID of the custom type.
509
- * @param params - Parameters to filter, sort, and paginate the results.
510
- *
511
- * @returns A list of all documents of the custom type.
512
- */
513
- async getAllByType(documentType, params) {
514
- return await this.dangerouslyGetAll(appendFilters(params, typeFilter(documentType)));
515
- }
516
- /**
517
- * Queries documents from the Prismic repository with a specific tag.
518
- *
519
- * Use `getAllByTag` instead if you need to query all documents with a
520
- * specific tag.
521
- *
522
- * @example
523
- *
524
- * ```ts
525
- * const response = await client.getByTag("food");
526
- * ```
527
- *
528
- * @typeParam TDocument - Type of Prismic documents returned.
529
- *
530
- * @param tag - The tag that must be included on a document.
531
- * @param params - Parameters to filter, sort, and paginate the results.
532
- *
533
- * @returns A paginated response containing documents with the tag.
534
- */
535
- async getByTag(tag, params) {
536
- return await this.get(appendFilters(params, someTagsFilter(tag)));
537
- }
538
- /**
539
- * Queries all documents from the Prismic repository with a specific tag.
540
- *
541
- * This method may make multiple network requests to query all matching
542
- * content.
543
- *
544
- * @example
545
- *
546
- * ```ts
547
- * const response = await client.getAllByTag("food");
548
- * ```
549
- *
550
- * @typeParam TDocument - Type of Prismic documents returned.
551
- *
552
- * @param tag - The tag that must be included on a document.
553
- * @param params - Parameters to filter, sort, and paginate the results.
554
- *
555
- * @returns A list of all documents with the tag.
556
- */
557
- async getAllByTag(tag, params) {
558
- return await this.dangerouslyGetAll(appendFilters(params, someTagsFilter(tag)));
559
- }
560
- /**
561
- * Queries documents from the Prismic repository with specific tags. A
562
- * document must be tagged with all of the queried tags to be included.
563
- *
564
- * @example
565
- *
566
- * ```ts
567
- * const response = await client.getByEveryTag(["food", "fruit"]);
568
- * ```
569
- *
570
- * @typeParam TDocument - Type of Prismic documents returned.
571
- *
572
- * @param tags - A list of tags that must be included on a document.
573
- * @param params - Parameters to filter, sort, and paginate the results.
574
- *
575
- * @returns A paginated response containing documents with the tags.
576
- */
577
- async getByEveryTag(tags, params) {
578
- return await this.get(appendFilters(params, everyTagFilter(tags)));
579
- }
580
- /**
581
- * Queries documents from the Prismic repository with specific tags. A
582
- * document must be tagged with all of the queried tags to be included.
583
- *
584
- * This method may make multiple network requests to query all matching
585
- * content.
586
- *
587
- * @example
588
- *
589
- * ```ts
590
- * const response = await client.getAllByEveryTag(["food", "fruit"]);
591
- * ```
592
- *
593
- * @typeParam TDocument - Type of Prismic documents returned.
594
- *
595
- * @param tags - A list of tags that must be included on a document.
596
- * @param params - Parameters to filter, sort, and paginate the results.
597
- *
598
- * @returns A list of all documents with the tags.
599
- */
600
- async getAllByEveryTag(tags, params) {
601
- return await this.dangerouslyGetAll(appendFilters(params, everyTagFilter(tags)));
602
- }
603
- /**
604
- * Queries documents from the Prismic repository with specific tags. A
605
- * document must be tagged with at least one of the queried tags to be
606
- * included.
607
- *
608
- * @example
609
- *
610
- * ```ts
611
- * const response = await client.getByEveryTag(["food", "fruit"]);
612
- * ```
613
- *
614
- * @typeParam TDocument - Type of Prismic documents returned.
615
- *
616
- * @param tags - A list of tags that must be included on a document.
617
- * @param params - Parameters to filter, sort, and paginate the results.
618
- *
619
- * @returns A paginated response containing documents with at least one of the
620
- * tags.
621
- */
622
- async getBySomeTags(tags, params) {
623
- return await this.get(appendFilters(params, someTagsFilter(tags)));
624
- }
625
- /**
626
- * Queries documents from the Prismic repository with specific tags. A
627
- * document must be tagged with at least one of the queried tags to be
628
- * included.
629
- *
630
- * This method may make multiple network requests to query all matching
631
- * content.
632
- *
633
- * @example
634
- *
635
- * ```ts
636
- * const response = await client.getAllBySomeTags(["food", "fruit"]);
637
- * ```
638
- *
639
- * @typeParam TDocument - Type of Prismic documents returned.
640
- *
641
- * @param tags - A list of tags that must be included on a document.
642
- * @param params - Parameters to filter, sort, and paginate the results.
643
- *
644
- * @returns A list of all documents with at least one of the tags.
645
- */
646
- async getAllBySomeTags(tags, params) {
647
- return await this.dangerouslyGetAll(appendFilters(params, someTagsFilter(tags)));
648
- }
649
- /**
650
- * Returns metadata about the Prismic repository, such as its refs, releases,
651
- * and custom types.
652
- *
653
- * @returns Repository metadata.
654
- */
655
- async getRepository(params) {
656
- const url = new URL(this.endpoint);
657
- if (this.accessToken) {
658
- url.searchParams.set("access_token", this.accessToken);
659
- }
660
- return await this.fetch(url.toString(), params);
661
- }
662
- /**
663
- * Returns a list of all refs for the Prismic repository.
664
- *
665
- * Refs are used to identify which version of the repository's content should
666
- * be queried. All repositories will have at least one ref pointing to the
667
- * latest published content called the "master ref".
668
- *
669
- * @returns A list of all refs for the Prismic repository.
670
- */
671
- async getRefs(params) {
672
- const repository = await this.getRepository(params);
673
- return repository.refs;
674
- }
675
- /**
676
- * Returns a ref for the Prismic repository with a matching ID.
677
- *
678
- * @param id - ID of the ref.
679
- *
680
- * @returns The ref with a matching ID, if it exists.
681
- */
682
- async getRefByID(id, params) {
683
- const refs = await this.getRefs(params);
684
- return findRefByID(refs, id);
685
- }
686
- /**
687
- * Returns a ref for the Prismic repository with a matching label.
688
- *
689
- * @param label - Label of the ref.
690
- *
691
- * @returns The ref with a matching label, if it exists.
692
- */
693
- async getRefByLabel(label, params) {
694
- const refs = await this.getRefs(params);
695
- return findRefByLabel(refs, label);
696
- }
697
- /**
698
- * Returns the master ref for the Prismic repository. The master ref points to
699
- * the repository's latest published content.
700
- *
701
- * @returns The repository's master ref.
702
- */
703
- async getMasterRef(params) {
704
- const refs = await this.getRefs(params);
705
- return findMasterRef(refs);
706
- }
707
- /**
708
- * Returns a list of all Releases for the Prismic repository. Releases are
709
- * used to group content changes before publishing.
710
- *
711
- * @returns A list of all Releases for the Prismic repository.
712
- */
713
- async getReleases(params) {
714
- const refs = await this.getRefs(params);
715
- return refs.filter((ref) => !ref.isMasterRef);
716
- }
717
- /**
718
- * Returns a Release for the Prismic repository with a matching ID.
719
- *
720
- * @param id - ID of the Release.
721
- *
722
- * @returns The Release with a matching ID, if it exists.
723
- */
724
- async getReleaseByID(id, params) {
725
- const releases = await this.getReleases(params);
726
- return findRefByID(releases, id);
727
- }
728
- /**
729
- * Returns a Release for the Prismic repository with a matching label.
730
- *
731
- * @param label - Label of the ref.
732
- *
733
- * @returns The ref with a matching label, if it exists.
734
- */
735
- async getReleaseByLabel(label, params) {
736
- const releases = await this.getReleases(params);
737
- return findRefByLabel(releases, label);
738
- }
739
- /**
740
- * Returns a list of all tags used in the Prismic repository.
741
- *
742
- * @returns A list of all tags used in the repository.
743
- */
744
- async getTags(params) {
745
- try {
746
- const tagsForm = await this.getCachedRepositoryForm("tags", params);
747
- const url = new URL(tagsForm.action);
748
- if (this.accessToken) {
749
- url.searchParams.set("access_token", this.accessToken);
750
- }
751
- return await this.fetch(url.toString(), params);
752
- } catch {
753
- const repository = await this.getRepository(params);
754
- return repository.tags;
755
- }
756
- }
757
- /**
758
- * Builds a URL used to query content from the Prismic repository.
759
- *
760
- * @param params - Parameters to filter, sort, and paginate the results.
761
- *
762
- * @returns A URL string that can be requested to query content.
763
- */
764
- async buildQueryURL({ signal, fetchOptions, ...params } = {}) {
765
- const ref = params.ref || await this.getResolvedRefString({ signal, fetchOptions });
766
- const integrationFieldsRef = params.integrationFieldsRef || (await this.getCachedRepository({ signal, fetchOptions })).integrationFieldsRef || void 0;
767
- return buildQueryURL(this.endpoint, {
768
- ...this.defaultParams,
769
- ...params,
770
- ref,
771
- integrationFieldsRef,
772
- routes: params.routes || this.routes,
773
- brokenRoute: params.brokenRoute || this.brokenRoute,
774
- accessToken: params.accessToken || this.accessToken
775
- });
776
- }
777
- /**
778
- * Determines the URL for a previewed document during an active preview
779
- * session. The result of this method should be used to redirect the user to
780
- * the document's URL.
781
- *
782
- * @example
783
- *
784
- * ```ts
785
- * const url = client.resolvePreviewURL({
786
- * linkResolver: (document) => `/${document.uid}`
787
- * defaultURL: '/'
788
- * })
789
- * ```
790
- *
791
- * @param args - Arguments to configure the URL resolving.
792
- *
793
- * @returns The URL for the previewed document during an active preview
794
- * session. The user should be redirected to this URL.
795
- */
796
- async resolvePreviewURL(args) {
797
- var _a, _b;
798
- let documentID = args.documentID;
799
- let previewToken = args.previewToken;
800
- if (typeof globalThis.location !== "undefined") {
801
- const searchParams = new URLSearchParams(globalThis.location.search);
802
- documentID = documentID || searchParams.get("documentId");
803
- previewToken = previewToken || searchParams.get("token");
804
- } else if (this.refState.httpRequest) {
805
- if ("query" in this.refState.httpRequest) {
806
- documentID = documentID || ((_a = this.refState.httpRequest.query) == null ? void 0 : _a.documentId);
807
- previewToken = previewToken || ((_b = this.refState.httpRequest.query) == null ? void 0 : _b.token);
808
- } else if ("url" in this.refState.httpRequest && this.refState.httpRequest.url) {
809
- const searchParams = new URL(this.refState.httpRequest.url, "missing-host://").searchParams;
810
- documentID = documentID || searchParams.get("documentId");
811
- previewToken = previewToken || searchParams.get("token");
812
- }
813
- }
814
- if (documentID != null && previewToken != null) {
815
- const document = await this.getByID(documentID, {
816
- ref: previewToken,
817
- lang: "*",
818
- signal: args.signal,
819
- fetchOptions: args.fetchOptions
820
- });
821
- const url = asLink(document, { linkResolver: args.linkResolver });
822
- if (typeof url === "string") {
823
- return url;
824
- }
825
- }
826
- return args.defaultURL;
827
- }
828
- /**
829
- * Configures the client to query the latest published content for all future
830
- * queries.
831
- *
832
- * If the `ref` parameter is provided during a query, it takes priority for
833
- * that query.
834
- *
835
- * @example
836
- *
837
- * ```ts
838
- * await client.queryLatestContent();
839
- * const document = await client.getByID("WW4bKScAAMAqmluX");
840
- * ```
841
- */
842
- queryLatestContent() {
843
- this.refState.mode = RefStateMode.Master;
844
- }
845
- /**
846
- * Configures the client to query content from a specific Release identified
847
- * by its ID for all future queries.
848
- *
849
- * If the `ref` parameter is provided during a query, it takes priority for
850
- * that query.
851
- *
852
- * @example
853
- *
854
- * ```ts
855
- * await client.queryContentFromReleaseByID("YLB7OBAAACMA7Cpa");
856
- * const document = await client.getByID("WW4bKScAAMAqmluX");
857
- * ```
858
- *
859
- * @param releaseID - The ID of the Release.
860
- */
861
- queryContentFromReleaseByID(releaseID) {
862
- this.refState = {
863
- ...this.refState,
864
- mode: RefStateMode.ReleaseID,
865
- releaseID
866
- };
867
- }
868
- /**
869
- * Configures the client to query content from a specific Release identified
870
- * by its label for all future queries.
871
- *
872
- * If the `ref` parameter is provided during a query, it takes priority for
873
- * that query.
874
- *
875
- * @example
876
- *
877
- * ```ts
878
- * await client.queryContentFromReleaseByLabel("My Release");
879
- * const document = await client.getByID("WW4bKScAAMAqmluX");
880
- * ```
881
- *
882
- * @param releaseLabel - The label of the Release.
883
- */
884
- queryContentFromReleaseByLabel(releaseLabel) {
885
- this.refState = {
886
- ...this.refState,
887
- mode: RefStateMode.ReleaseLabel,
888
- releaseLabel
889
- };
890
- }
891
- /**
892
- * Configures the client to query content from a specific ref. The ref can be
893
- * provided as a string or a function.
894
- *
895
- * If a function is provided, the ref is fetched lazily before each query. The
896
- * function may also be asynchronous.
897
- *
898
- * @example
899
- *
900
- * ```ts
901
- * await client.queryContentFromRef("my-ref");
902
- * const document = await client.getByID("WW4bKScAAMAqmluX");
903
- * ```
904
- *
905
- * @param ref - The ref or a function that returns the ref from which to query
906
- * content.
907
- */
908
- queryContentFromRef(ref) {
909
- this.refState = {
910
- ...this.refState,
911
- mode: RefStateMode.Manual,
912
- ref
913
- };
914
- }
915
- /**
916
- * A `fetch()` function to be used with GraphQL clients configured for
917
- * Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
918
- * and Authorization headers. Queries will automatically be minified by
919
- * removing whitespace where possible.
920
- *
921
- * @example
922
- *
923
- * ```ts
924
- * const graphQLClient = new ApolloClient({
925
- * link: new HttpLink({
926
- * uri: prismic.getGraphQLEndpoint(repositoryName),
927
- * // Provide `client.graphQLFetch` as the fetch implementation.
928
- * fetch: client.graphQLFetch,
929
- * // Using GET is required.
930
- * useGETForQueries: true,
931
- * }),
932
- * cache: new InMemoryCache(),
933
- * });
934
- * ```
935
- *
936
- * @param input - The `fetch()` `input` parameter. Only strings are supported.
937
- * @param init - The `fetch()` `init` parameter. Only plain objects are
938
- * supported.
939
- *
940
- * @returns The `fetch()` Response for the request.
941
- *
942
- * @experimental
943
- */
944
- async graphQLFetch(input, init) {
945
- const cachedRepository = await this.getCachedRepository();
946
- const ref = await this.getResolvedRefString();
947
- const unsanitizedHeaders = {
948
- "Prismic-ref": ref,
949
- Authorization: this.accessToken ? `Token ${this.accessToken}` : "",
950
- // Asserting `init.headers` is a Record since popular GraphQL
951
- // libraries pass this as a Record. Header objects as input
952
- // are unsupported.
953
- ...init ? init.headers : {}
954
- };
955
- if (cachedRepository.integrationFieldsRef) {
956
- unsanitizedHeaders["Prismic-integration-field-ref"] = cachedRepository.integrationFieldsRef;
957
- }
958
- const headers = {};
959
- for (const key in unsanitizedHeaders) {
960
- if (unsanitizedHeaders[key]) {
961
- headers[key.toLowerCase()] = unsanitizedHeaders[key];
962
- }
963
- }
964
- const url = new URL(
965
- // Asserting `input` is a string since popular GraphQL
966
- // libraries pass this as a string. Request objects as
967
- // input are unsupported.
968
- input
969
- );
970
- url.searchParams.set("ref", ref);
971
- const query = url.searchParams.get("query");
972
- if (query) {
973
- url.searchParams.set(
974
- "query",
975
- // Compress the GraphQL query (if it exists) by
976
- // removing whitespace. This is done to
977
- // optimize the query size and avoid
978
- // hitting the upper limit of GET requests
979
- // (2048 characters).
980
- minifyGraphQLQuery(query)
981
- );
982
- }
983
- return await this.fetchFn(url.toString(), {
984
- ...init,
985
- headers
986
- });
987
- }
988
- /**
989
- * Returns a cached version of `getRepository` with a TTL.
990
- *
991
- * @returns Cached repository metadata.
992
- */
993
- async getCachedRepository(params) {
994
- if (!this.cachedRepository || Date.now() >= this.cachedRepositoryExpiration) {
995
- this.cachedRepositoryExpiration = Date.now() + REPOSITORY_CACHE_TTL;
996
- this.cachedRepository = await this.getRepository(params);
997
- }
998
- return this.cachedRepository;
999
- }
1000
- /**
1001
- * Returns a cached Prismic repository form. Forms are used to determine API
1002
- * endpoints for types of repository data.
1003
- *
1004
- * @param name - Name of the form.
1005
- *
1006
- * @returns The repository form.
1007
- *
1008
- * @throws If a matching form cannot be found.
1009
- */
1010
- async getCachedRepositoryForm(name, params) {
1011
- const cachedRepository = await this.getCachedRepository(params);
1012
- const form = cachedRepository.forms[name];
1013
- if (!form) {
1014
- throw new PrismicError(`Form with name "${name}" could not be found`, void 0, void 0);
1015
- }
1016
- return form;
1017
- }
1018
- /**
1019
- * Returns the ref needed to query based on the client's current state. This
1020
- * method may make a network request to fetch a ref or resolve the user's ref
1021
- * thunk.
1022
- *
1023
- * If auto previews are enabled, the preview ref takes priority if available.
1024
- *
1025
- * The following strategies are used depending on the client's state:
1026
- *
1027
- * - If the user called `queryLatestContent`: Use the repository's master ref.
1028
- * The ref is cached for 5 seconds. After 5 seconds, a new master ref is
1029
- * fetched.
1030
- * - If the user called `queryContentFromReleaseByID`: Use the release's ref.
1031
- * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
1032
- * release is fetched.
1033
- * - If the user called `queryContentFromReleaseByLabel`: Use the release's ref.
1034
- * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
1035
- * release is fetched.
1036
- * - If the user called `queryContentFromRef`: Use the provided ref. Fall back
1037
- * to the master ref if the ref is not a string.
1038
- *
1039
- * @returns The ref to use during a query.
1040
- */
1041
- async getResolvedRefString(params) {
1042
- var _a, _b;
1043
- if (this.refState.autoPreviewsEnabled) {
1044
- let previewRef;
1045
- let cookieJar;
1046
- if ((_a = this.refState.httpRequest) == null ? void 0 : _a.headers) {
1047
- if ("get" in this.refState.httpRequest.headers && typeof this.refState.httpRequest.headers.get === "function") {
1048
- cookieJar = this.refState.httpRequest.headers.get("cookie");
1049
- } else if ("cookie" in this.refState.httpRequest.headers) {
1050
- cookieJar = this.refState.httpRequest.headers.cookie;
1051
- }
1052
- } else if ((_b = globalThis.document) == null ? void 0 : _b.cookie) {
1053
- cookieJar = globalThis.document.cookie;
1054
- }
1055
- if (cookieJar) {
1056
- previewRef = getPreviewCookie(cookieJar);
1057
- }
1058
- if (previewRef) {
1059
- return previewRef;
1060
- }
1061
- }
1062
- const cachedRepository = await this.getCachedRepository(params);
1063
- const refModeType = this.refState.mode;
1064
- if (refModeType === RefStateMode.ReleaseID) {
1065
- return findRefByID(cachedRepository.refs, this.refState.releaseID).ref;
1066
- } else if (refModeType === RefStateMode.ReleaseLabel) {
1067
- return findRefByLabel(cachedRepository.refs, this.refState.releaseLabel).ref;
1068
- } else if (refModeType === RefStateMode.Manual) {
1069
- const res = await castThunk(this.refState.ref)();
1070
- if (typeof res === "string") {
1071
- return res;
1072
- }
1073
- }
1074
- return findMasterRef(cachedRepository.refs).ref;
1075
- }
1076
- /**
1077
- * Performs a network request using the configured `fetch` function. It
1078
- * assumes all successful responses will have a JSON content type. It also
1079
- * normalizes unsuccessful network requests.
1080
- *
1081
- * @typeParam T - The JSON response.
1082
- *
1083
- * @param url - URL to the resource to fetch.
1084
- * @param params - Prismic REST API parameters for the network request.
1085
- *
1086
- * @returns The JSON response from the network request.
1087
- */
1088
- async fetch(url, params = {}) {
1089
- var _a, _b, _c, _d;
1090
- const requestInit = {
1091
- ...this.fetchOptions,
1092
- ...params.fetchOptions,
1093
- headers: {
1094
- ...(_a = this.fetchOptions) == null ? void 0 : _a.headers,
1095
- ...(_b = params.fetchOptions) == null ? void 0 : _b.headers
1096
- },
1097
- signal: ((_c = params.fetchOptions) == null ? void 0 : _c.signal) || params.signal || ((_d = this.fetchOptions) == null ? void 0 : _d.signal)
1098
- };
1099
- let job;
1100
- if (this.fetchJobs[url] && this.fetchJobs[url].has(requestInit.signal)) {
1101
- job = this.fetchJobs[url].get(requestInit.signal);
1102
- } else {
1103
- this.fetchJobs[url] = this.fetchJobs[url] || /* @__PURE__ */ new Map();
1104
- job = this.fetchFn(url, requestInit).then(async (res2) => {
1105
- let json = void 0;
1106
- try {
1107
- json = await res2.json();
1108
- } catch {
1109
- }
1110
- return {
1111
- status: res2.status,
1112
- headers: res2.headers,
1113
- json
1114
- };
1115
- }).finally(() => {
1116
- this.fetchJobs[url].delete(requestInit.signal);
1117
- if (this.fetchJobs[url].size === 0) {
1118
- delete this.fetchJobs[url];
1119
- }
1120
- });
1121
- this.fetchJobs[url].set(requestInit.signal, job);
1122
- }
1123
- const res = await job;
1124
- if (res.status !== 404 && res.json == null) {
1125
- throw new PrismicError(void 0, url, res.json);
1126
- }
1127
- switch (res.status) {
1128
- case 200: {
1129
- return res.json;
1130
- }
1131
- case 400: {
1132
- throw new ParsingError(res.json.message, url, res.json);
1133
- }
1134
- case 401:
1135
- case 403: {
1136
- throw new ForbiddenError(res.json.error || res.json.message, url, res.json);
1137
- }
1138
- case 404: {
1139
- if (res.json === void 0) {
1140
- throw new RepositoryNotFoundError(`Prismic repository not found. Check that "${this.endpoint}" is pointing to the correct repository.`, url, void 0);
1141
- }
1142
- if (res.json.type === "api_notfound_error") {
1143
- throw new RefNotFoundError(res.json.message, url, res.json);
1144
- }
1145
- if (res.json.type === "api_security_error" && /preview token.*expired/i.test(res.json.message)) {
1146
- throw new PreviewTokenExpiredError(res.json.message, url, res.json);
1147
- }
1148
- throw new NotFoundError(res.json.message, url, res.json);
1149
- }
1150
- case 410: {
1151
- throw new RefExpiredError(res.json.message, url, res.json);
1152
- }
1153
- case 429: {
1154
- const parsedRetryAfter = Number(res.headers.get("retry-after"));
1155
- const delay = Number.isNaN(parsedRetryAfter) ? DEFUALT_RETRY_AFTER_MS : parsedRetryAfter;
1156
- return await new Promise((resolve, reject) => {
1157
- setTimeout(async () => {
1158
- try {
1159
- resolve(await this.fetch(url, params));
1160
- } catch (error) {
1161
- reject(error);
1162
- }
1163
- }, delay);
1164
- });
1165
- }
1166
- }
1167
- throw new PrismicError(void 0, url, res.json);
1168
- }
1169
- }
1170
3
  export {
1171
- Client,
1172
- GET_ALL_QUERY_DELAY,
1173
- REPOSITORY_CACHE_TTL,
1174
4
  createClient
1175
5
  };
1176
6
  //# sourceMappingURL=createClient.js.map