@prismicio/client 6.7.0 → 6.7.2

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 (128) hide show
  1. package/dist/ForbiddenError.cjs +7 -0
  2. package/dist/ForbiddenError.cjs.map +1 -0
  3. package/dist/ForbiddenError.d.ts +11 -0
  4. package/dist/ForbiddenError.js +7 -0
  5. package/dist/ForbiddenError.js.map +1 -0
  6. package/dist/NotFoundError.cjs +7 -0
  7. package/dist/NotFoundError.cjs.map +1 -0
  8. package/dist/NotFoundError.d.ts +3 -0
  9. package/dist/NotFoundError.js +7 -0
  10. package/dist/NotFoundError.js.map +1 -0
  11. package/dist/ParsingError.cjs +7 -0
  12. package/dist/ParsingError.cjs.map +1 -0
  13. package/dist/ParsingError.d.ts +12 -0
  14. package/dist/ParsingError.js +7 -0
  15. package/dist/ParsingError.js.map +1 -0
  16. package/dist/PrismicError.cjs +19 -0
  17. package/dist/PrismicError.cjs.map +1 -0
  18. package/dist/PrismicError.d.ts +5 -0
  19. package/dist/PrismicError.js +19 -0
  20. package/dist/PrismicError.js.map +1 -0
  21. package/dist/buildQueryURL.cjs +40 -0
  22. package/dist/buildQueryURL.cjs.map +1 -0
  23. package/dist/buildQueryURL.d.ts +130 -0
  24. package/dist/buildQueryURL.js +40 -0
  25. package/dist/buildQueryURL.js.map +1 -0
  26. package/dist/client.cjs +436 -0
  27. package/dist/client.cjs.map +1 -0
  28. package/dist/client.d.ts +929 -0
  29. package/dist/client.js +419 -0
  30. package/dist/client.js.map +1 -0
  31. package/dist/cookie.cjs +5 -0
  32. package/dist/cookie.cjs.map +1 -0
  33. package/dist/cookie.d.ts +5 -0
  34. package/dist/cookie.js +5 -0
  35. package/dist/cookie.js.map +1 -0
  36. package/dist/getGraphQLEndpoint.cjs +13 -0
  37. package/dist/getGraphQLEndpoint.cjs.map +1 -0
  38. package/dist/getGraphQLEndpoint.d.ts +9 -0
  39. package/dist/getGraphQLEndpoint.js +13 -0
  40. package/dist/getGraphQLEndpoint.js.map +1 -0
  41. package/dist/getRepositoryEndpoint.cjs +13 -0
  42. package/dist/getRepositoryEndpoint.cjs.map +1 -0
  43. package/dist/getRepositoryEndpoint.d.ts +10 -0
  44. package/dist/getRepositoryEndpoint.js +13 -0
  45. package/dist/getRepositoryEndpoint.js.map +1 -0
  46. package/dist/getRepositoryName.cjs +12 -0
  47. package/dist/getRepositoryName.cjs.map +1 -0
  48. package/dist/getRepositoryName.d.ts +13 -0
  49. package/dist/getRepositoryName.js +12 -0
  50. package/dist/getRepositoryName.js.map +1 -0
  51. package/dist/index.cjs +32 -719
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.d.ts +88 -1526
  54. package/dist/index.js +34 -679
  55. package/dist/index.js.map +1 -1
  56. package/dist/isRepositoryEndpoint.cjs +12 -0
  57. package/dist/isRepositoryEndpoint.cjs.map +1 -0
  58. package/dist/isRepositoryEndpoint.d.ts +10 -0
  59. package/dist/isRepositoryEndpoint.js +12 -0
  60. package/dist/isRepositoryEndpoint.js.map +1 -0
  61. package/dist/isRepositoryName.cjs +7 -0
  62. package/dist/isRepositoryName.cjs.map +1 -0
  63. package/dist/isRepositoryName.d.ts +9 -0
  64. package/dist/isRepositoryName.js +7 -0
  65. package/dist/isRepositoryName.js.map +1 -0
  66. package/dist/lib/appendPredicates.cjs +14 -0
  67. package/dist/lib/appendPredicates.cjs.map +1 -0
  68. package/dist/lib/appendPredicates.d.ts +18 -0
  69. package/dist/lib/appendPredicates.js +14 -0
  70. package/dist/lib/appendPredicates.js.map +1 -0
  71. package/dist/lib/castArray.cjs +5 -0
  72. package/dist/lib/castArray.cjs.map +1 -0
  73. package/dist/lib/castArray.d.ts +11 -0
  74. package/dist/lib/castArray.js +5 -0
  75. package/dist/lib/castArray.js.map +1 -0
  76. package/dist/lib/castThunk.cjs +5 -0
  77. package/dist/lib/castThunk.cjs.map +1 -0
  78. package/dist/lib/castThunk.d.ts +10 -0
  79. package/dist/lib/castThunk.js +5 -0
  80. package/dist/lib/castThunk.js.map +1 -0
  81. package/dist/lib/findMasterRef.cjs +8 -0
  82. package/dist/lib/findMasterRef.cjs.map +1 -0
  83. package/dist/lib/findMasterRef.d.ts +10 -0
  84. package/dist/lib/findMasterRef.js +8 -0
  85. package/dist/lib/findMasterRef.js.map +1 -0
  86. package/dist/lib/findRef.cjs +12 -0
  87. package/dist/lib/findRef.cjs.map +1 -0
  88. package/dist/lib/findRef.d.ts +13 -0
  89. package/dist/lib/findRef.js +12 -0
  90. package/dist/lib/findRef.js.map +1 -0
  91. package/dist/lib/findRefByID.cjs +8 -0
  92. package/dist/lib/findRefByID.cjs.map +1 -0
  93. package/dist/lib/findRefByID.d.ts +11 -0
  94. package/dist/lib/findRefByID.js +8 -0
  95. package/dist/lib/findRefByID.js.map +1 -0
  96. package/dist/lib/findRefByLabel.cjs +8 -0
  97. package/dist/lib/findRefByLabel.cjs.map +1 -0
  98. package/dist/lib/findRefByLabel.d.ts +11 -0
  99. package/dist/lib/findRefByLabel.js +8 -0
  100. package/dist/lib/findRefByLabel.js.map +1 -0
  101. package/dist/lib/getPreviewCookie.cjs +21 -0
  102. package/dist/lib/getPreviewCookie.cjs.map +1 -0
  103. package/dist/lib/getPreviewCookie.d.ts +9 -0
  104. package/dist/lib/getPreviewCookie.js +21 -0
  105. package/dist/lib/getPreviewCookie.js.map +1 -0
  106. package/dist/lib/minifyGraphQLQuery.cjs +7 -0
  107. package/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
  108. package/dist/lib/minifyGraphQLQuery.d.ts +8 -0
  109. package/dist/lib/minifyGraphQLQuery.js +7 -0
  110. package/dist/lib/minifyGraphQLQuery.js.map +1 -0
  111. package/dist/lib/orElseThrow.d.ts +11 -0
  112. package/dist/predicate.cjs +68 -0
  113. package/dist/predicate.cjs.map +1 -0
  114. package/dist/predicate.d.ts +209 -0
  115. package/dist/predicate.js +68 -0
  116. package/dist/predicate.js.map +1 -0
  117. package/dist/types.d.ts +156 -0
  118. package/package.json +21 -21
  119. package/src/buildQueryURL.ts +6 -3
  120. package/src/client.ts +71 -36
  121. package/src/cookie.ts +2 -1
  122. package/src/getRepositoryName.ts +4 -2
  123. package/src/isRepositoryEndpoint.ts +2 -1
  124. package/src/isRepositoryName.ts +2 -1
  125. package/src/lib/appendPredicates.ts +2 -1
  126. package/src/lib/getPreviewCookie.ts +2 -1
  127. package/src/predicate.ts +4 -2
  128. package/src/types.ts +16 -18
@@ -0,0 +1,929 @@
1
+ import * as prismicT from "@prismicio/types";
2
+ import * as prismicH from "@prismicio/helpers";
3
+ import { AbortSignalLike, FetchLike, HttpRequestLike, ExtractDocumentType } from "./types";
4
+ import { BuildQueryURLArgs } from "./buildQueryURL";
5
+ /**
6
+ * The number of milliseconds in which repository metadata is considered valid.
7
+ * A ref can be invalidated quickly depending on how frequently content is
8
+ * updated in the Prismic repository. As such, repository's metadata can only be
9
+ * considered valid for a short amount of time.
10
+ */
11
+ export declare const REPOSITORY_CACHE_TTL = 5000;
12
+ /**
13
+ * The number of milliseconds in which a multi-page `getAll` (e.g. `getAll`,
14
+ * `getAllByType`, `getAllByTag`) will wait between individual page requests.
15
+ *
16
+ * This is done to ensure API performance is sustainable and reduces the chance
17
+ * of a failed API request due to overloading.
18
+ */
19
+ export declare const GET_ALL_QUERY_DELAY = 500;
20
+ /**
21
+ * A ref or a function that returns a ref. If a static ref is known, one can be
22
+ * given. If the ref must be fetched on-demand, a function can be provided. This
23
+ * function can optionally be asynchronous.
24
+ */
25
+ type RefStringOrThunk = string | (() => string | undefined | Promise<string | undefined>);
26
+ /**
27
+ * Configuration for clients that determine how content is queried.
28
+ */
29
+ export type ClientConfig = {
30
+ /**
31
+ * The secure token for accessing the Prismic repository. This is only
32
+ * required if the repository is set to private.
33
+ */
34
+ accessToken?: string;
35
+ /**
36
+ * A string representing a version of the Prismic repository's content. This
37
+ * may point to the latest version (called the "master ref"), or a preview
38
+ * with draft content.
39
+ */
40
+ ref?: RefStringOrThunk;
41
+ /**
42
+ * A list of Route Resolver objects that define how a document's `url` field
43
+ * is resolved.
44
+ *
45
+ * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
46
+ */
47
+ routes?: NonNullable<BuildQueryURLArgs["routes"]>;
48
+ /**
49
+ * The `brokenRoute` option allows you to define the route populated in the
50
+ * `url` property for broken Link or Content Relationship fields. A broken
51
+ * link is a Link or Content Relationship field whose linked document has been
52
+ * unpublished or deleted.
53
+ *
54
+ * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
55
+ */
56
+ brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>;
57
+ /**
58
+ * Default parameters that will be sent with each query. These parameters can
59
+ * be overridden on each query if needed.
60
+ */
61
+ defaultParams?: Omit<BuildQueryURLArgs, "ref" | "integrationFieldsRef" | "accessToken" | "routes" | "brokenRoute">;
62
+ /**
63
+ * The function used to make network requests to the Prismic REST API. In
64
+ * environments where a global `fetch` function does not exist, such as
65
+ * Node.js, this function must be provided.
66
+ */
67
+ fetch?: FetchLike;
68
+ };
69
+ /**
70
+ * Parameters for any client method that use `fetch()`. Only a subset of
71
+ * `fetch()` parameters are exposed.
72
+ */
73
+ type FetchParams = {
74
+ /**
75
+ * An `AbortSignal` provided by an `AbortController`. This allows the network
76
+ * request to be cancelled if necessary.
77
+ *
78
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}
79
+ */
80
+ signal?: AbortSignalLike;
81
+ };
82
+ /**
83
+ * Parameters specific to client methods that fetch all documents. These methods
84
+ * start with `getAll` (for example, `getAllByType`).
85
+ */
86
+ type GetAllParams = {
87
+ /**
88
+ * Limit the number of documents queried. If a number is not provided, there
89
+ * will be no limit and all matching documents will be returned.
90
+ */
91
+ limit?: number;
92
+ };
93
+ /**
94
+ * Arguments to determine how the URL for a preview session is resolved.
95
+ */
96
+ type ResolvePreviewArgs<LinkResolverReturnType> = {
97
+ /**
98
+ * A function that maps a Prismic document to a URL within your app.
99
+ */
100
+ linkResolver?: prismicH.LinkResolverFunction<LinkResolverReturnType>;
101
+ /**
102
+ * A fallback URL if the Link Resolver does not return a value.
103
+ */
104
+ defaultURL: string;
105
+ /**
106
+ * The preview token (also known as a ref) that will be used to query preview
107
+ * content from the Prismic repository.
108
+ */
109
+ previewToken?: string;
110
+ /**
111
+ * The previewed document that will be used to determine the destination URL.
112
+ */
113
+ documentID?: string;
114
+ };
115
+ /**
116
+ * Type definitions for the `createClient()` function. May be augmented by
117
+ * third-party libraries.
118
+ */
119
+ export interface CreateClient {
120
+ <TDocuments extends prismicT.PrismicDocument>(...args: ConstructorParameters<typeof Client>): Client<TDocuments>;
121
+ }
122
+ /**
123
+ * Creates a Prismic client that can be used to query a repository.
124
+ *
125
+ * @example
126
+ *
127
+ * ```ts
128
+ * // With a repository name.
129
+ * createClient("qwerty");
130
+ *
131
+ * // Or with a full Prismic Rest API V2 endpoint.
132
+ * createClient("https://qwerty.cdn.prismic.io/api/v2");
133
+ * ```
134
+ *
135
+ * @typeParam TDocuments - A map of Prismic document type IDs mapped to their
136
+ * TypeScript type.
137
+ * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
138
+ * API V2 endpoint for the repository.
139
+ * @param options - Configuration that determines how content will be queried
140
+ * from the Prismic repository.
141
+ *
142
+ * @returns A client that can query content from the repository.
143
+ */
144
+ export declare const createClient: CreateClient;
145
+ /**
146
+ * A client that allows querying content from a Prismic repository.
147
+ *
148
+ * If used in an environment where a global `fetch` function is unavailable,
149
+ * such as Node.js, the `fetch` option must be provided as part of the `options`
150
+ * parameter.
151
+ *
152
+ * @typeParam TDocuments - Document types that are registered for the Prismic
153
+ * repository. Query methods will automatically be typed based on this type.
154
+ */
155
+ export declare class Client<TDocuments extends prismicT.PrismicDocument = prismicT.PrismicDocument> {
156
+ /**
157
+ * The Prismic REST API V2 endpoint for the repository (use
158
+ * `prismic.getRepositoryEndpoint` for the default endpoint).
159
+ */
160
+ endpoint: string;
161
+ /**
162
+ * The secure token for accessing the API (only needed if your repository is
163
+ * set to private).
164
+ *
165
+ * {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
166
+ */
167
+ accessToken?: string;
168
+ /**
169
+ * A list of Route Resolver objects that define how a document's `url` field
170
+ * is resolved.
171
+ *
172
+ * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
173
+ */
174
+ routes?: NonNullable<BuildQueryURLArgs["routes"]>;
175
+ /**
176
+ * The `brokenRoute` option allows you to define the route populated in the
177
+ * `url` property for broken Link or Content Relationship fields. A broken
178
+ * link is a Link or Content Relationship field whose linked document has been
179
+ * unpublished or deleted.
180
+ *
181
+ * {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver#route-resolver}
182
+ */
183
+ brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>;
184
+ /**
185
+ * The function used to make network requests to the Prismic REST API. In
186
+ * environments where a global `fetch` function does not exist, such as
187
+ * Node.js, this function must be provided.
188
+ */
189
+ fetchFn: FetchLike;
190
+ /**
191
+ * Default parameters that will be sent with each query. These parameters can
192
+ * be overridden on each query if needed.
193
+ */
194
+ defaultParams?: Omit<BuildQueryURLArgs, "ref" | "integrationFieldsRef" | "accessToken" | "routes">;
195
+ /**
196
+ * The client's ref mode state. This determines which ref is used during
197
+ * queries.
198
+ */
199
+ private refState;
200
+ /**
201
+ * Cached repository value.
202
+ */
203
+ private cachedRepository;
204
+ /**
205
+ * Timestamp at which the cached repository data is considered stale.
206
+ */
207
+ private cachedRepositoryExpiration;
208
+ /**
209
+ * Creates a Prismic client that can be used to query a repository.
210
+ *
211
+ * If used in an environment where a global `fetch` function is unavailable,
212
+ * such as Node.js, the `fetch` option must be provided as part of the
213
+ * `options` parameter.
214
+ *
215
+ * @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
216
+ * API V2 endpoint for the repository.
217
+ * @param options - Configuration that determines how content will be queried
218
+ * from the Prismic repository.
219
+ *
220
+ * @returns A client that can query content from the repository.
221
+ */
222
+ constructor(repositoryNameOrEndpoint: string, options?: ClientConfig);
223
+ /**
224
+ * Enables the client to automatically query content from a preview session if
225
+ * one is active in browser environments. This is enabled by default in the
226
+ * browser.
227
+ *
228
+ * For server environments, use `enableAutoPreviewsFromReq`.
229
+ *
230
+ * @example
231
+ *
232
+ * ```ts
233
+ * client.enableAutoPreviews();
234
+ * ```
235
+ *
236
+ * @see enableAutoPreviewsFromReq
237
+ */
238
+ enableAutoPreviews(): void;
239
+ /**
240
+ * Enables the client to automatically query content from a preview session if
241
+ * one is active in server environments. This is disabled by default on the
242
+ * server.
243
+ *
244
+ * For browser environments, use `enableAutoPreviews`.
245
+ *
246
+ * @example
247
+ *
248
+ * ```ts
249
+ * // In an express app
250
+ * app.get("/", function (req, res) {
251
+ * client.enableAutoPreviewsFromReq(req);
252
+ * });
253
+ * ```
254
+ *
255
+ * @param req - An HTTP server request object containing the request's
256
+ * cookies.
257
+ */
258
+ enableAutoPreviewsFromReq<R extends HttpRequestLike>(req: R): void;
259
+ /**
260
+ * Disables the client from automatically querying content from a preview
261
+ * session if one is active.
262
+ *
263
+ * Automatic preview content querying is enabled by default unless this method
264
+ * is called.
265
+ *
266
+ * @example
267
+ *
268
+ * ```ts
269
+ * client.disableAutoPreviews();
270
+ * ```
271
+ */
272
+ disableAutoPreviews(): void;
273
+ /**
274
+ * Queries content from the Prismic repository.
275
+ *
276
+ * @deprecated Use `get` instead.
277
+ * @example
278
+ *
279
+ * ```ts
280
+ * const response = await client.query(
281
+ * prismic.predicate.at("document.type", "page"),
282
+ * );
283
+ * ```
284
+ *
285
+ * @typeParam TDocument - Type of Prismic documents returned.
286
+ * @param params - Parameters to filter, sort, and paginate results.
287
+ *
288
+ * @returns A paginated response containing the result of the query.
289
+ */
290
+ query<TDocument extends TDocuments>(predicates: NonNullable<BuildQueryURLArgs["predicates"]>, params?: Partial<Omit<BuildQueryURLArgs, "predicates">> & FetchParams): Promise<prismicT.Query<TDocument>>;
291
+ /**
292
+ * Queries content from the Prismic repository.
293
+ *
294
+ * @example
295
+ *
296
+ * ```ts
297
+ * const response = await client.get();
298
+ * ```
299
+ *
300
+ * @typeParam TDocument - Type of Prismic documents returned.
301
+ * @param params - Parameters to filter, sort, and paginate results.
302
+ *
303
+ * @returns A paginated response containing the result of the query.
304
+ */
305
+ get<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
306
+ /**
307
+ * Queries content from the Prismic repository and returns only the first
308
+ * result, if any.
309
+ *
310
+ * @example
311
+ *
312
+ * ```ts
313
+ * const document = await client.getFirst();
314
+ * ```
315
+ *
316
+ * @typeParam TDocument - Type of the Prismic document returned.
317
+ * @param params - Parameters to filter, sort, and paginate results. @returns
318
+ * The first result of the query, if any.
319
+ */
320
+ getFirst<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
321
+ /**
322
+ * **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
323
+ * require more resources than other methods. Prefer using other methods that
324
+ * filter by predicates such as `getAllByType`.
325
+ *
326
+ * Queries content from the Prismic repository and returns all matching
327
+ * content. If no predicates are provided, all documents will be fetched.
328
+ *
329
+ * This method may make multiple network requests to query all matching
330
+ * content.
331
+ *
332
+ * @example
333
+ *
334
+ * ```ts
335
+ * const response = await client.dangerouslyGetAll();
336
+ * ```
337
+ *
338
+ * @typeParam TDocument - Type of Prismic documents returned.
339
+ * @param params - Parameters to filter, sort, and paginate results.
340
+ *
341
+ * @returns A list of documents matching the query.
342
+ */
343
+ dangerouslyGetAll<TDocument extends TDocuments>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
344
+ /**
345
+ * Queries a document from the Prismic repository with a specific ID.
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
+ * @example
353
+ *
354
+ * ```ts
355
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
356
+ * ```
357
+ *
358
+ * @typeParam TDocument- Type of the Prismic document returned.
359
+ * @param id - ID of the document.
360
+ * @param params - Parameters to filter, sort, and paginate the results.
361
+ *
362
+ * @returns The document with an ID matching the `id` parameter, if a matching
363
+ * document exists.
364
+ */
365
+ getByID<TDocument extends TDocuments>(id: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
366
+ /**
367
+ * Queries documents from the Prismic repository with specific IDs.
368
+ *
369
+ * @remarks
370
+ * A document's UID is different from its ID. An ID is automatically generated
371
+ * for all documents and is made available on its `id` property. A UID is
372
+ * provided in the Prismic editor and is unique among all documents of its
373
+ * Custom Type.
374
+ * @example
375
+ *
376
+ * ```ts
377
+ * const response = await client.getByIDs([
378
+ * "WW4bKScAAMAqmluX",
379
+ * "U1kTRgEAAC8A5ldS",
380
+ * ]);
381
+ * ```
382
+ *
383
+ * @typeParam TDocument - Type of Prismic documents returned.
384
+ * @param ids - A list of document IDs.
385
+ * @param params - Parameters to filter, sort, and paginate the results.
386
+ *
387
+ * @returns A paginated response containing documents with IDs matching the
388
+ * `ids` parameter.
389
+ */
390
+ getByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
391
+ /**
392
+ * Queries all documents from the Prismic repository with specific IDs.
393
+ *
394
+ * This method may make multiple network requests to query all matching
395
+ * content.
396
+ *
397
+ * @remarks
398
+ * A document's UID is different from its ID. An ID is automatically generated
399
+ * for all documents and is made available on its `id` property. A UID is
400
+ * provided in the Prismic editor and is unique among all documents of its
401
+ * Custom Type.
402
+ * @example
403
+ *
404
+ * ```ts
405
+ * const response = await client.getAllByIDs([
406
+ * "WW4bKScAAMAqmluX",
407
+ * "U1kTRgEAAC8A5ldS",
408
+ * ]);
409
+ * ```
410
+ *
411
+ * @typeParam TDocument - Type of Prismic documents returned.
412
+ * @param ids - A list of document IDs.
413
+ * @param params - Parameters to filter, sort, and paginate the results.
414
+ *
415
+ * @returns A list of documents with IDs matching the `ids` parameter.
416
+ */
417
+ getAllByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<TDocument[]>;
418
+ /**
419
+ * Queries a document from the Prismic repository with a specific UID and
420
+ * Custom Type.
421
+ *
422
+ * @remarks
423
+ * A document's UID is different from its ID. An ID is automatically generated
424
+ * for all documents and is made available on its `id` property. A UID is
425
+ * provided in the Prismic editor and is unique among all documents of its
426
+ * Custom Type.
427
+ * @example
428
+ *
429
+ * ```ts
430
+ * const document = await client.getByUID("blog_post", "my-first-post");
431
+ * ```
432
+ *
433
+ * @typeParam TDocument - Type of the Prismic document returned.
434
+ * @param documentType - The API ID of the document's Custom Type.
435
+ * @param uid - UID of the document.
436
+ * @param params - Parameters to filter, sort, and paginate the results.
437
+ *
438
+ * @returns The document with a UID matching the `uid` parameter, if a
439
+ * matching document exists.
440
+ */
441
+ getByUID<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uid: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
442
+ /**
443
+ * Queries document from the Prismic repository with specific UIDs and Custom
444
+ * Type.
445
+ *
446
+ * @remarks
447
+ * A document's UID is different from its ID. An ID is automatically generated
448
+ * for all documents and is made available on its `id` property. A UID is
449
+ * provided in the Prismic editor and is unique among all documents of its
450
+ * Custom Type.
451
+ * @example
452
+ *
453
+ * ```ts
454
+ * const document = await client.getByUIDs("blog_post", [
455
+ * "my-first-post",
456
+ * "my-second-post",
457
+ * ]);
458
+ * ```
459
+ *
460
+ * @typeParam TDocument - Type of the Prismic document returned.
461
+ * @param documentType - The API ID of the document's Custom Type.
462
+ * @param uids - A list of document UIDs.
463
+ * @param params - Parameters to filter, sort, and paginate the results.
464
+ *
465
+ * @returns A paginated response containing documents with UIDs matching the
466
+ * `uids` parameter.
467
+ */
468
+ getByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<ExtractDocumentType<TDocument, TDocumentType>>>;
469
+ /**
470
+ * Queries all documents from the Prismic repository with specific UIDs and
471
+ * Custom Type.
472
+ *
473
+ * This method may make multiple network requests to query all matching
474
+ * content.
475
+ *
476
+ * @remarks
477
+ * A document's UID is different from its ID. An ID is automatically generated
478
+ * for all documents and is made available on its `id` property. A UID is
479
+ * provided in the Prismic editor and is unique among all documents of its
480
+ * Custom Type.
481
+ * @example
482
+ *
483
+ * ```ts
484
+ * const response = await client.getAllByUIDs([
485
+ * "my-first-post",
486
+ * "my-second-post",
487
+ * ]);
488
+ * ```
489
+ *
490
+ * @typeParam TDocument - Type of Prismic documents returned.
491
+ * @param documentType - The API ID of the document's Custom Type.
492
+ * @param uids - A list of document UIDs.
493
+ * @param params - Parameters to filter, sort, and paginate the results.
494
+ *
495
+ * @returns A list of documents with UIDs matching the `uids` parameter.
496
+ */
497
+ getAllByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
498
+ /**
499
+ * Queries a singleton document from the Prismic repository for a specific
500
+ * Custom Type.
501
+ *
502
+ * @remarks
503
+ * A singleton document is one that is configured in Prismic to only allow one
504
+ * instance. For example, a repository may be configured to contain just one
505
+ * Settings document. This is in contrast to a repeatable Custom Type which
506
+ * allows multiple instances of itself.
507
+ * @example
508
+ *
509
+ * ```ts
510
+ * const document = await client.getSingle("settings");
511
+ * ```
512
+ *
513
+ * @typeParam TDocument - Type of the Prismic document returned.
514
+ * @param documentType - The API ID of the singleton Custom Type.
515
+ * @param params - Parameters to filter, sort, and paginate the results.
516
+ *
517
+ * @returns The singleton document for the Custom Type, if a matching document
518
+ * exists.
519
+ */
520
+ getSingle<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
521
+ /**
522
+ * Queries documents from the Prismic repository for a specific Custom Type.
523
+ *
524
+ * Use `getAllByType` instead if you need to query all documents for a
525
+ * specific Custom Type.
526
+ *
527
+ * @example
528
+ *
529
+ * ```ts
530
+ * const response = await client.getByType("blog_post");
531
+ * ```
532
+ *
533
+ * @typeParam TDocument - Type of Prismic documents returned.
534
+ * @param documentType - The API ID of the Custom Type.
535
+ * @param params - Parameters to filter, sort, and paginate the results.
536
+ *
537
+ * @returns A paginated response containing documents of the Custom Type.
538
+ */
539
+ getByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<ExtractDocumentType<TDocument, TDocumentType>>>;
540
+ /**
541
+ * Queries all documents from the Prismic repository for a specific Custom
542
+ * Type.
543
+ *
544
+ * This method may make multiple network requests to query all matching
545
+ * content.
546
+ *
547
+ * @example
548
+ *
549
+ * ```ts
550
+ * const response = await client.getByType("blog_post");
551
+ * ```
552
+ *
553
+ * @typeParam TDocument - Type of Prismic documents returned.
554
+ * @param documentType - The API ID of the Custom Type.
555
+ * @param params - Parameters to filter, sort, and paginate the results.
556
+ *
557
+ * @returns A list of all documents of the Custom Type.
558
+ */
559
+ getAllByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
560
+ /**
561
+ * Queries documents from the Prismic repository with a specific tag.
562
+ *
563
+ * Use `getAllByTag` instead if you need to query all documents with a
564
+ * specific tag.
565
+ *
566
+ * @example
567
+ *
568
+ * ```ts
569
+ * const response = await client.getByTag("food");
570
+ * ```
571
+ *
572
+ * @typeParam TDocument - Type of Prismic documents returned.
573
+ * @param tag - The tag that must be included on a document.
574
+ * @param params - Parameters to filter, sort, and paginate the results.
575
+ *
576
+ * @returns A paginated response containing documents with the tag.
577
+ */
578
+ getByTag<TDocument extends TDocuments>(tag: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
579
+ /**
580
+ * Queries all documents from the Prismic repository with a specific tag.
581
+ *
582
+ * This method may make multiple network requests to query all matching
583
+ * content.
584
+ *
585
+ * @example
586
+ *
587
+ * ```ts
588
+ * const response = await client.getAllByTag("food");
589
+ * ```
590
+ *
591
+ * @typeParam TDocument - Type of Prismic documents returned.
592
+ * @param tag - The tag that must be included on a document.
593
+ * @param params - Parameters to filter, sort, and paginate the results.
594
+ *
595
+ * @returns A list of all documents with the tag.
596
+ */
597
+ getAllByTag<TDocument extends TDocuments>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
598
+ /**
599
+ * Queries documents from the Prismic repository with specific tags. A
600
+ * document must be tagged with all of the queried tags to be included.
601
+ *
602
+ * @example
603
+ *
604
+ * ```ts
605
+ * const response = await client.getByEveryTag(["food", "fruit"]);
606
+ * ```
607
+ *
608
+ * @typeParam TDocument - Type of Prismic documents returned.
609
+ * @param tags - A list of tags that must be included on a document.
610
+ * @param params - Parameters to filter, sort, and paginate the results.
611
+ *
612
+ * @returns A paginated response containing documents with the tags.
613
+ */
614
+ getByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
615
+ /**
616
+ * Queries documents from the Prismic repository with specific tags. A
617
+ * document must be tagged with all of the queried tags to be included.
618
+ *
619
+ * This method may make multiple network requests to query all matching
620
+ * content.
621
+ *
622
+ * @example
623
+ *
624
+ * ```ts
625
+ * const response = await client.getAllByEveryTag(["food", "fruit"]);
626
+ * ```
627
+ *
628
+ * @typeParam TDocument - Type of Prismic documents returned.
629
+ * @param tags - A list of tags that must be included on a document.
630
+ * @param params - Parameters to filter, sort, and paginate the results.
631
+ *
632
+ * @returns A list of all documents with the tags.
633
+ */
634
+ getAllByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
635
+ /**
636
+ * Queries documents from the Prismic repository with specific tags. A
637
+ * document must be tagged with at least one of the queried tags to be
638
+ * included.
639
+ *
640
+ * @example
641
+ *
642
+ * ```ts
643
+ * const response = await client.getByEveryTag(["food", "fruit"]);
644
+ * ```
645
+ *
646
+ * @typeParam TDocument - Type of Prismic documents returned.
647
+ * @param tags - A list of tags that must be included on a document.
648
+ * @param params - Parameters to filter, sort, and paginate the results.
649
+ *
650
+ * @returns A paginated response containing documents with at least one of the
651
+ * tags.
652
+ */
653
+ getBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<prismicT.Query<TDocument>>;
654
+ /**
655
+ * Queries documents from the Prismic repository with specific tags. A
656
+ * document must be tagged with at least one of the queried tags to be
657
+ * included.
658
+ *
659
+ * This method may make multiple network requests to query all matching
660
+ * content.
661
+ *
662
+ * @example
663
+ *
664
+ * ```ts
665
+ * const response = await client.getAllBySomeTags(["food", "fruit"]);
666
+ * ```
667
+ *
668
+ * @typeParam TDocument - Type of Prismic documents returned.
669
+ * @param tags - A list of tags that must be included on a document.
670
+ * @param params - Parameters to filter, sort, and paginate the results.
671
+ *
672
+ * @returns A list of all documents with at least one of the tags.
673
+ */
674
+ getAllBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
675
+ /**
676
+ * Returns metadata about the Prismic repository, such as its refs, releases,
677
+ * and custom types.
678
+ *
679
+ * @returns Repository metadata.
680
+ */
681
+ getRepository(params?: FetchParams): Promise<prismicT.Repository>;
682
+ /**
683
+ * Returns a list of all refs for the Prismic repository.
684
+ *
685
+ * Refs are used to identify which version of the repository's content should
686
+ * be queried. All repositories will have at least one ref pointing to the
687
+ * latest published content called the "master ref".
688
+ *
689
+ * @returns A list of all refs for the Prismic repository.
690
+ */
691
+ getRefs(params?: FetchParams): Promise<prismicT.Ref[]>;
692
+ /**
693
+ * Returns a ref for the Prismic repository with a matching ID.
694
+ *
695
+ * @param id - ID of the ref.
696
+ *
697
+ * @returns The ref with a matching ID, if it exists.
698
+ */
699
+ getRefByID(id: string, params?: FetchParams): Promise<prismicT.Ref>;
700
+ /**
701
+ * Returns a ref for the Prismic repository with a matching label.
702
+ *
703
+ * @param label - Label of the ref.
704
+ *
705
+ * @returns The ref with a matching label, if it exists.
706
+ */
707
+ getRefByLabel(label: string, params?: FetchParams): Promise<prismicT.Ref>;
708
+ /**
709
+ * Returns the master ref for the Prismic repository. The master ref points to
710
+ * the repository's latest published content.
711
+ *
712
+ * @returns The repository's master ref.
713
+ */
714
+ getMasterRef(params?: FetchParams): Promise<prismicT.Ref>;
715
+ /**
716
+ * Returns a list of all Releases for the Prismic repository. Releases are
717
+ * used to group content changes before publishing.
718
+ *
719
+ * @returns A list of all Releases for the Prismic repository.
720
+ */
721
+ getReleases(params?: FetchParams): Promise<prismicT.Ref[]>;
722
+ /**
723
+ * Returns a Release for the Prismic repository with a matching ID.
724
+ *
725
+ * @param id - ID of the Release.
726
+ *
727
+ * @returns The Release with a matching ID, if it exists.
728
+ */
729
+ getReleaseByID(id: string, params?: FetchParams): Promise<prismicT.Ref>;
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
+ getReleaseByLabel(label: string, params?: FetchParams): Promise<prismicT.Ref>;
738
+ /**
739
+ * Returns a list of all tags used in the Prismic repository.
740
+ *
741
+ * @returns A list of all tags used in the repository.
742
+ */
743
+ getTags(params?: FetchParams): Promise<string[]>;
744
+ /**
745
+ * Builds a URL used to query content from the Prismic repository.
746
+ *
747
+ * @param params - Parameters to filter, sort, and paginate the results.
748
+ *
749
+ * @returns A URL string that can be requested to query content.
750
+ */
751
+ buildQueryURL({ signal, ...params }?: Partial<BuildQueryURLArgs> & FetchParams): Promise<string>;
752
+ /**
753
+ * Determines the URL for a previewed document during an active preview
754
+ * session. The result of this method should be used to redirect the user to
755
+ * the document's URL.
756
+ *
757
+ * @example
758
+ *
759
+ * ```ts
760
+ * const url = client.resolvePreviewURL({
761
+ * linkResolver: (document) => `/${document.uid}`
762
+ * defaultURL: '/'
763
+ * })
764
+ * ```
765
+ *
766
+ * @param args - Arguments to configure the URL resolving.
767
+ *
768
+ * @returns The URL for the previewed document during an active preview
769
+ * session. The user should be redirected to this URL.
770
+ */
771
+ resolvePreviewURL<LinkResolverReturnType>(args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams): Promise<string>;
772
+ /**
773
+ * Configures the client to query the latest published content for all future
774
+ * queries.
775
+ *
776
+ * If the `ref` parameter is provided during a query, it takes priority for
777
+ * that query.
778
+ *
779
+ * @example
780
+ *
781
+ * ```ts
782
+ * await client.queryLatestContent();
783
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
784
+ * ```
785
+ */
786
+ queryLatestContent(): void;
787
+ /**
788
+ * Configures the client to query content from a specific Release identified
789
+ * by its ID for all future queries.
790
+ *
791
+ * If the `ref` parameter is provided during a query, it takes priority for
792
+ * that query.
793
+ *
794
+ * @example
795
+ *
796
+ * ```ts
797
+ * await client.queryContentFromReleaseByID("YLB7OBAAACMA7Cpa");
798
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
799
+ * ```
800
+ *
801
+ * @param releaseID - The ID of the Release.
802
+ */
803
+ queryContentFromReleaseByID(releaseID: string): void;
804
+ /**
805
+ * Configures the client to query content from a specific Release identified
806
+ * by its label for all future queries.
807
+ *
808
+ * If the `ref` parameter is provided during a query, it takes priority for
809
+ * that query.
810
+ *
811
+ * @example
812
+ *
813
+ * ```ts
814
+ * await client.queryContentFromReleaseByLabel("My Release");
815
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
816
+ * ```
817
+ *
818
+ * @param releaseLabel - The label of the Release.
819
+ */
820
+ queryContentFromReleaseByLabel(releaseLabel: string): void;
821
+ /**
822
+ * Configures the client to query content from a specific ref. The ref can be
823
+ * provided as a string or a function.
824
+ *
825
+ * If a function is provided, the ref is fetched lazily before each query. The
826
+ * function may also be asynchronous.
827
+ *
828
+ * @example
829
+ *
830
+ * ```ts
831
+ * await client.queryContentFromRef("my-ref");
832
+ * const document = await client.getByID("WW4bKScAAMAqmluX");
833
+ * ```
834
+ *
835
+ * @param ref - The ref or a function that returns the ref from which to query
836
+ * content.
837
+ */
838
+ queryContentFromRef(ref: RefStringOrThunk): void;
839
+ /**
840
+ * @deprecated Renamed to `graphQLFetch()` (note the capitalization of "QL").
841
+ */
842
+ graphqlFetch: (input: RequestInfo, init?: Omit<RequestInit, "signal"> & {
843
+ signal?: AbortSignalLike;
844
+ }) => Promise<Response>;
845
+ /**
846
+ * A `fetch()` function to be used with GraphQL clients configured for
847
+ * Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
848
+ * and Authorization headers. Queries will automatically be minified by
849
+ * removing whitespace where possible.
850
+ *
851
+ * @example
852
+ *
853
+ * ```ts
854
+ * const graphqlClient = new ApolloClient({
855
+ * link: new HttpLink({
856
+ * uri: prismic.getGraphQLEndpoint(repositoryName),
857
+ * // Provide `client.graphqlFetch` as the fetch implementation.
858
+ * fetch: client.graphqlFetch,
859
+ * // Using GET is required.
860
+ * useGETForQueries: true,
861
+ * }),
862
+ * cache: new InMemoryCache(),
863
+ * });
864
+ * ```
865
+ *
866
+ * @param input - The `fetch()` `input` parameter. Only strings are supported.
867
+ * @param init - The `fetch()` `init` parameter. Only plain objects are
868
+ * supported.
869
+ *
870
+ * @returns The `fetch()` Response for the request.
871
+ * @experimental
872
+ */
873
+ graphQLFetch(input: RequestInfo, init?: Omit<RequestInit, "signal"> & {
874
+ signal?: AbortSignalLike;
875
+ }): Promise<Response>;
876
+ /**
877
+ * Returns a cached version of `getRepository` with a TTL.
878
+ *
879
+ * @returns Cached repository metadata.
880
+ */
881
+ private getCachedRepository;
882
+ /**
883
+ * Returns a cached Prismic repository form. Forms are used to determine API
884
+ * endpoints for types of repository data.
885
+ *
886
+ * @param name - Name of the form.
887
+ *
888
+ * @returns The repository form.
889
+ * @throws If a matching form cannot be found.
890
+ */
891
+ private getCachedRepositoryForm;
892
+ /**
893
+ * Returns the ref needed to query based on the client's current state. This
894
+ * method may make a network request to fetch a ref or resolve the user's ref
895
+ * thunk.
896
+ *
897
+ * If auto previews are enabled, the preview ref takes priority if available.
898
+ *
899
+ * The following strategies are used depending on the client's state:
900
+ *
901
+ * - If the user called `queryLatestContent`: Use the repository's master ref.
902
+ * The ref is cached for 5 seconds. After 5 seconds, a new master ref is
903
+ * fetched.
904
+ * - If the user called `queryContentFromReleaseByID`: Use the release's ref.
905
+ * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
906
+ * release is fetched.
907
+ * - If the user called `queryContentFromReleaseByLabel`: Use the release's ref.
908
+ * The ref is cached for 5 seconds. After 5 seconds, a new ref for the
909
+ * release is fetched.
910
+ * - If the user called `queryContentFromRef`: Use the provided ref. Fall back
911
+ * to the master ref if the ref is not a string.
912
+ *
913
+ * @returns The ref to use during a query.
914
+ */
915
+ private getResolvedRefString;
916
+ /**
917
+ * Performs a network request using the configured `fetch` function. It
918
+ * assumes all successful responses will have a JSON content type. It also
919
+ * normalizes unsuccessful network requests.
920
+ *
921
+ * @typeParam T - The JSON response.
922
+ * @param url - URL to the resource to fetch.
923
+ * @param params - Prismic REST API parameters for the network request.
924
+ *
925
+ * @returns The JSON response from the network request.
926
+ */
927
+ private fetch;
928
+ }
929
+ export {};