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