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