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