@prismicio/client 6.7.0 → 7.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ForbiddenError.cjs +7 -0
- package/dist/ForbiddenError.cjs.map +1 -0
- package/dist/ForbiddenError.d.ts +11 -0
- package/dist/ForbiddenError.js +7 -0
- package/dist/ForbiddenError.js.map +1 -0
- package/dist/NotFoundError.cjs +7 -0
- package/dist/NotFoundError.cjs.map +1 -0
- package/dist/NotFoundError.d.ts +3 -0
- package/dist/NotFoundError.js +7 -0
- package/dist/NotFoundError.js.map +1 -0
- package/dist/ParsingError.cjs +7 -0
- package/dist/ParsingError.cjs.map +1 -0
- package/dist/ParsingError.d.ts +12 -0
- package/dist/ParsingError.js +7 -0
- package/dist/ParsingError.js.map +1 -0
- package/dist/PrismicError.cjs +19 -0
- package/dist/PrismicError.cjs.map +1 -0
- package/dist/PrismicError.d.ts +5 -0
- package/dist/PrismicError.js +19 -0
- package/dist/PrismicError.js.map +1 -0
- package/dist/buildQueryURL.cjs +41 -0
- package/dist/buildQueryURL.cjs.map +1 -0
- package/dist/buildQueryURL.d.ts +130 -0
- package/dist/buildQueryURL.js +41 -0
- package/dist/buildQueryURL.js.map +1 -0
- package/dist/client.cjs +414 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.ts +908 -0
- package/dist/client.js +414 -0
- package/dist/client.js.map +1 -0
- package/dist/cookie.cjs +5 -0
- package/dist/cookie.cjs.map +1 -0
- package/dist/cookie.d.ts +5 -0
- package/dist/cookie.js +5 -0
- package/dist/cookie.js.map +1 -0
- package/dist/getGraphQLEndpoint.cjs +13 -0
- package/dist/getGraphQLEndpoint.cjs.map +1 -0
- package/dist/getGraphQLEndpoint.d.ts +9 -0
- package/dist/getGraphQLEndpoint.js +13 -0
- package/dist/getGraphQLEndpoint.js.map +1 -0
- package/dist/getRepositoryEndpoint.cjs +13 -0
- package/dist/getRepositoryEndpoint.cjs.map +1 -0
- package/dist/getRepositoryEndpoint.d.ts +10 -0
- package/dist/getRepositoryEndpoint.js +13 -0
- package/dist/getRepositoryEndpoint.js.map +1 -0
- package/dist/getRepositoryName.cjs +12 -0
- package/dist/getRepositoryName.cjs.map +1 -0
- package/dist/getRepositoryName.d.ts +13 -0
- package/dist/getRepositoryName.js +12 -0
- package/dist/getRepositoryName.js.map +1 -0
- package/dist/helpers/asDate.cjs +14 -0
- package/dist/helpers/asDate.cjs.map +1 -0
- package/dist/helpers/asDate.d.ts +16 -0
- package/dist/helpers/asDate.js +14 -0
- package/dist/helpers/asDate.js.map +1 -0
- package/dist/helpers/asHTML.cjs +79 -0
- package/dist/helpers/asHTML.cjs.map +1 -0
- package/dist/helpers/asHTML.d.ts +20 -0
- package/dist/helpers/asHTML.js +79 -0
- package/dist/helpers/asHTML.js.map +1 -0
- package/dist/helpers/asImagePixelDensitySrcSet.cjs +21 -0
- package/dist/helpers/asImagePixelDensitySrcSet.cjs.map +1 -0
- package/dist/helpers/asImagePixelDensitySrcSet.d.ts +52 -0
- package/dist/helpers/asImagePixelDensitySrcSet.js +21 -0
- package/dist/helpers/asImagePixelDensitySrcSet.js.map +1 -0
- package/dist/helpers/asImageSrc.cjs +13 -0
- package/dist/helpers/asImageSrc.cjs.map +1 -0
- package/dist/helpers/asImageSrc.d.ts +27 -0
- package/dist/helpers/asImageSrc.js +13 -0
- package/dist/helpers/asImageSrc.js.map +1 -0
- package/dist/helpers/asImageWidthSrcSet.cjs +40 -0
- package/dist/helpers/asImageWidthSrcSet.cjs.map +1 -0
- package/dist/helpers/asImageWidthSrcSet.d.ts +60 -0
- package/dist/helpers/asImageWidthSrcSet.js +40 -0
- package/dist/helpers/asImageWidthSrcSet.js.map +1 -0
- package/dist/helpers/asLink.cjs +32 -0
- package/dist/helpers/asLink.cjs.map +1 -0
- package/dist/helpers/asLink.d.ts +24 -0
- package/dist/helpers/asLink.js +32 -0
- package/dist/helpers/asLink.js.map +1 -0
- package/dist/helpers/asText.cjs +12 -0
- package/dist/helpers/asText.cjs.map +1 -0
- package/dist/helpers/asText.d.ts +16 -0
- package/dist/helpers/asText.js +12 -0
- package/dist/helpers/asText.js.map +1 -0
- package/dist/helpers/documentToLinkField.cjs +19 -0
- package/dist/helpers/documentToLinkField.cjs.map +1 -0
- package/dist/helpers/documentToLinkField.d.ts +15 -0
- package/dist/helpers/documentToLinkField.js +19 -0
- package/dist/helpers/documentToLinkField.js.map +1 -0
- package/dist/helpers/isFilled.cjs +67 -0
- package/dist/helpers/isFilled.cjs.map +1 -0
- package/dist/helpers/isFilled.d.ts +175 -0
- package/dist/helpers/isFilled.js +67 -0
- package/dist/helpers/isFilled.js.map +1 -0
- package/dist/index.cjs +67 -721
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +92 -1526
- package/dist/index.js +64 -681
- package/dist/index.js.map +1 -1
- package/dist/isRepositoryEndpoint.cjs +12 -0
- package/dist/isRepositoryEndpoint.cjs.map +1 -0
- package/dist/isRepositoryEndpoint.d.ts +10 -0
- package/dist/isRepositoryEndpoint.js +12 -0
- package/dist/isRepositoryEndpoint.js.map +1 -0
- package/dist/isRepositoryName.cjs +7 -0
- package/dist/isRepositoryName.cjs.map +1 -0
- package/dist/isRepositoryName.d.ts +9 -0
- package/dist/isRepositoryName.js +7 -0
- package/dist/isRepositoryName.js.map +1 -0
- package/dist/lib/appendPredicates.cjs +14 -0
- package/dist/lib/appendPredicates.cjs.map +1 -0
- package/dist/lib/appendPredicates.d.ts +18 -0
- package/dist/lib/appendPredicates.js +14 -0
- package/dist/lib/appendPredicates.js.map +1 -0
- package/dist/lib/castArray.cjs +5 -0
- package/dist/lib/castArray.cjs.map +1 -0
- package/dist/lib/castArray.d.ts +11 -0
- package/dist/lib/castArray.js +5 -0
- package/dist/lib/castArray.js.map +1 -0
- package/dist/lib/castThunk.cjs +5 -0
- package/dist/lib/castThunk.cjs.map +1 -0
- package/dist/lib/castThunk.d.ts +10 -0
- package/dist/lib/castThunk.js +5 -0
- package/dist/lib/castThunk.js.map +1 -0
- package/dist/lib/findMasterRef.cjs +8 -0
- package/dist/lib/findMasterRef.cjs.map +1 -0
- package/dist/lib/findMasterRef.d.ts +10 -0
- package/dist/lib/findMasterRef.js +8 -0
- package/dist/lib/findMasterRef.js.map +1 -0
- package/dist/lib/findRef.cjs +12 -0
- package/dist/lib/findRef.cjs.map +1 -0
- package/dist/lib/findRef.d.ts +13 -0
- package/dist/lib/findRef.js +12 -0
- package/dist/lib/findRef.js.map +1 -0
- package/dist/lib/findRefByID.cjs +8 -0
- package/dist/lib/findRefByID.cjs.map +1 -0
- package/dist/lib/findRefByID.d.ts +11 -0
- package/dist/lib/findRefByID.js +8 -0
- package/dist/lib/findRefByID.js.map +1 -0
- package/dist/lib/findRefByLabel.cjs +8 -0
- package/dist/lib/findRefByLabel.cjs.map +1 -0
- package/dist/lib/findRefByLabel.d.ts +11 -0
- package/dist/lib/findRefByLabel.js +8 -0
- package/dist/lib/findRefByLabel.js.map +1 -0
- package/dist/lib/getPreviewCookie.cjs +21 -0
- package/dist/lib/getPreviewCookie.cjs.map +1 -0
- package/dist/lib/getPreviewCookie.d.ts +9 -0
- package/dist/lib/getPreviewCookie.js +21 -0
- package/dist/lib/getPreviewCookie.js.map +1 -0
- package/dist/lib/minifyGraphQLQuery.cjs +7 -0
- package/dist/lib/minifyGraphQLQuery.cjs.map +1 -0
- package/dist/lib/minifyGraphQLQuery.d.ts +8 -0
- package/dist/lib/minifyGraphQLQuery.js +7 -0
- package/dist/lib/minifyGraphQLQuery.js.map +1 -0
- package/dist/lib/serializerHelpers.cjs +56 -0
- package/dist/lib/serializerHelpers.cjs.map +1 -0
- package/dist/lib/serializerHelpers.d.ts +9 -0
- package/dist/lib/serializerHelpers.js +54 -0
- package/dist/lib/serializerHelpers.js.map +1 -0
- package/dist/predicate.cjs +68 -0
- package/dist/predicate.cjs.map +1 -0
- package/dist/predicate.d.ts +209 -0
- package/dist/predicate.js +68 -0
- package/dist/predicate.js.map +1 -0
- package/dist/types/api/query.d.ts +42 -0
- package/dist/types/api/ref.d.ts +32 -0
- package/dist/types/api/release.d.ts +10 -0
- package/dist/types/api/repository.d.ts +100 -0
- package/dist/types/api/tags.d.ts +8 -0
- package/dist/types/client.d.ts +128 -0
- package/dist/types/helpers.d.ts +63 -0
- package/dist/types/model/boolean.d.ts +15 -0
- package/dist/types/model/color.d.ts +13 -0
- package/dist/types/model/contentRelationship.d.ts +18 -0
- package/dist/types/model/customType.d.ts +42 -0
- package/dist/types/model/date.d.ts +14 -0
- package/dist/types/model/embed.d.ts +13 -0
- package/dist/types/model/geoPoint.d.ts +12 -0
- package/dist/types/model/group.d.ts +15 -0
- package/dist/types/model/image.d.ts +31 -0
- package/dist/types/model/integrationFields.d.ts +14 -0
- package/dist/types/model/keyText.d.ts +13 -0
- package/dist/types/model/link.cjs +9 -0
- package/dist/types/model/link.cjs.map +1 -0
- package/dist/types/model/link.d.ts +27 -0
- package/dist/types/model/link.js +9 -0
- package/dist/types/model/link.js.map +1 -0
- package/dist/types/model/linkToMedia.d.ts +16 -0
- package/dist/types/model/number.d.ts +15 -0
- package/dist/types/model/range.d.ts +14 -0
- package/dist/types/model/richText.d.ts +35 -0
- package/dist/types/model/select.d.ts +18 -0
- package/dist/types/model/separator.d.ts +10 -0
- package/dist/types/model/sharedSlice.d.ts +19 -0
- package/dist/types/model/sharedSliceVariation.d.ts +22 -0
- package/dist/types/model/slice.cjs +8 -0
- package/dist/types/model/slice.cjs.map +1 -0
- package/dist/types/model/slice.d.ts +33 -0
- package/dist/types/model/slice.js +8 -0
- package/dist/types/model/slice.js.map +1 -0
- package/dist/types/model/sliceZone.cjs +8 -0
- package/dist/types/model/sliceZone.cjs.map +1 -0
- package/dist/types/model/sliceZone.d.ts +44 -0
- package/dist/types/model/sliceZone.js +8 -0
- package/dist/types/model/sliceZone.js.map +1 -0
- package/dist/types/model/timestamp.d.ts +14 -0
- package/dist/types/model/title.d.ts +7 -0
- package/dist/types/model/types.cjs +25 -0
- package/dist/types/model/types.cjs.map +1 -0
- package/dist/types/model/types.d.ts +62 -0
- package/dist/types/model/types.js +25 -0
- package/dist/types/model/types.js.map +1 -0
- package/dist/types/model/uid.d.ts +13 -0
- package/dist/types/utils.d.ts +28 -0
- package/dist/types/value/boolean.d.ts +6 -0
- package/dist/types/value/color.d.ts +8 -0
- package/dist/types/value/contentRelationship.d.ts +29 -0
- package/dist/types/value/date.d.ts +8 -0
- package/dist/types/value/document.d.ts +113 -0
- package/dist/types/value/embed.cjs +10 -0
- package/dist/types/value/embed.cjs.map +1 -0
- package/dist/types/value/embed.d.ts +167 -0
- package/dist/types/value/embed.js +10 -0
- package/dist/types/value/embed.js.map +1 -0
- package/dist/types/value/geoPoint.d.ts +11 -0
- package/dist/types/value/group.d.ts +7 -0
- package/dist/types/value/image.d.ts +36 -0
- package/dist/types/value/integrationFields.d.ts +9 -0
- package/dist/types/value/keyText.d.ts +8 -0
- package/dist/types/value/link.cjs +10 -0
- package/dist/types/value/link.cjs.map +1 -0
- package/dist/types/value/link.d.ts +40 -0
- package/dist/types/value/link.js +10 -0
- package/dist/types/value/link.js.map +1 -0
- package/dist/types/value/linkToMedia.d.ts +20 -0
- package/dist/types/value/number.d.ts +8 -0
- package/dist/types/value/richText.cjs +25 -0
- package/dist/types/value/richText.cjs.map +1 -0
- package/dist/types/value/richText.d.ts +203 -0
- package/dist/types/value/richText.js +25 -0
- package/dist/types/value/richText.js.map +1 -0
- package/dist/types/value/select.d.ts +9 -0
- package/dist/types/value/sharedSlice.d.ts +11 -0
- package/dist/types/value/sharedSliceVariation.d.ts +7 -0
- package/dist/types/value/slice.d.ts +13 -0
- package/dist/types/value/sliceZone.d.ts +12 -0
- package/dist/types/value/timestamp.d.ts +8 -0
- package/dist/types/value/title.d.ts +12 -0
- package/dist/types/value/types.d.ts +40 -0
- package/dist/types/webhook/apiUpdate.d.ts +52 -0
- package/dist/types/webhook/testTrigger.d.ts +9 -0
- package/dist/types/webhook/types.cjs +8 -0
- package/dist/types/webhook/types.cjs.map +1 -0
- package/dist/types/webhook/types.d.ts +18 -0
- package/dist/types/webhook/types.js +8 -0
- package/dist/types/webhook/types.js.map +1 -0
- package/package.json +40 -33
- package/src/buildQueryURL.ts +8 -4
- package/src/client.ts +111 -118
- package/src/cookie.ts +2 -1
- package/src/getRepositoryName.ts +4 -2
- package/src/helpers/asDate.ts +48 -0
- package/src/helpers/asHTML.ts +154 -0
- package/src/helpers/asImagePixelDensitySrcSet.ts +96 -0
- package/src/helpers/asImageSrc.ts +41 -0
- package/src/helpers/asImageWidthSrcSet.ts +139 -0
- package/src/helpers/asLink.ts +99 -0
- package/src/helpers/asText.ts +29 -0
- package/src/helpers/documentToLinkField.ts +47 -0
- package/src/helpers/isFilled.ts +290 -0
- package/src/index.ts +237 -21
- package/src/isRepositoryEndpoint.ts +2 -1
- package/src/isRepositoryName.ts +2 -1
- package/src/lib/appendPredicates.ts +2 -1
- package/src/lib/findMasterRef.ts +2 -2
- package/src/lib/findRef.ts +2 -5
- package/src/lib/findRefByID.ts +2 -2
- package/src/lib/findRefByLabel.ts +2 -5
- package/src/lib/getPreviewCookie.ts +3 -2
- package/src/lib/serializerHelpers.ts +96 -0
- package/src/predicate.ts +4 -2
- package/src/types/api/query.ts +50 -0
- package/src/types/api/ref.ts +36 -0
- package/src/types/api/release.ts +11 -0
- package/src/types/api/repository.ts +117 -0
- package/src/types/api/tags.ts +8 -0
- package/src/{types.ts → types/client.ts} +16 -52
- package/src/types/helpers.ts +103 -0
- package/src/types/model/boolean.ts +16 -0
- package/src/types/model/color.ts +14 -0
- package/src/types/model/contentRelationship.ts +22 -0
- package/src/types/model/customType.ts +61 -0
- package/src/types/model/date.ts +15 -0
- package/src/types/model/embed.ts +14 -0
- package/src/types/model/geoPoint.ts +13 -0
- package/src/types/model/group.ts +24 -0
- package/src/types/model/image.ts +37 -0
- package/src/types/model/integrationFields.ts +15 -0
- package/src/types/model/keyText.ts +14 -0
- package/src/types/model/link.ts +31 -0
- package/src/types/model/linkToMedia.ts +17 -0
- package/src/types/model/number.ts +16 -0
- package/src/types/model/range.ts +15 -0
- package/src/types/model/richText.ts +40 -0
- package/src/types/model/select.ts +22 -0
- package/src/types/model/separator.ts +11 -0
- package/src/types/model/sharedSlice.ts +23 -0
- package/src/types/model/sharedSliceVariation.ts +33 -0
- package/src/types/model/slice.ts +49 -0
- package/src/types/model/sliceZone.ts +62 -0
- package/src/types/model/timestamp.ts +15 -0
- package/src/types/model/title.ts +8 -0
- package/src/types/model/types.ts +91 -0
- package/src/types/model/uid.ts +14 -0
- package/src/types/utils.ts +34 -0
- package/src/types/value/boolean.ts +6 -0
- package/src/types/value/color.ts +10 -0
- package/src/types/value/contentRelationship.ts +48 -0
- package/src/types/value/date.ts +10 -0
- package/src/types/value/document.ts +142 -0
- package/src/types/value/embed.ts +196 -0
- package/src/types/value/geoPoint.ts +15 -0
- package/src/types/value/group.ts +14 -0
- package/src/types/value/image.ts +67 -0
- package/src/types/value/integrationFields.ts +13 -0
- package/src/types/value/keyText.ts +10 -0
- package/src/types/value/link.ts +59 -0
- package/src/types/value/linkToMedia.ts +25 -0
- package/src/types/value/number.ts +10 -0
- package/src/types/value/richText.ts +286 -0
- package/src/types/value/select.ts +13 -0
- package/src/types/value/sharedSlice.ts +15 -0
- package/src/types/value/sharedSliceVariation.ts +18 -0
- package/src/types/value/slice.ts +24 -0
- package/src/types/value/sliceZone.ts +16 -0
- package/src/types/value/timestamp.ts +12 -0
- package/src/types/value/title.ts +31 -0
- package/src/types/value/types.ts +60 -0
- package/src/types/webhook/apiUpdate.ts +56 -0
- package/src/types/webhook/testTrigger.ts +10 -0
- package/src/types/webhook/types.ts +21 -0
- package/src/lib/orElseThrow.ts +0 -17
package/src/client.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as prismicT from "@prismicio/types";
|
|
2
|
-
import * as prismicH from "@prismicio/helpers";
|
|
3
|
-
|
|
4
1
|
import { appendPredicates } from "./lib/appendPredicates";
|
|
5
2
|
import { castArray } from "./lib/castArray";
|
|
6
3
|
import { castThunk } from "./lib/castThunk";
|
|
@@ -10,12 +7,20 @@ import { findRefByLabel } from "./lib/findRefByLabel";
|
|
|
10
7
|
import { getPreviewCookie } from "./lib/getPreviewCookie";
|
|
11
8
|
import { minifyGraphQLQuery } from "./lib/minifyGraphQLQuery";
|
|
12
9
|
|
|
13
|
-
import {
|
|
10
|
+
import type {
|
|
14
11
|
AbortSignalLike,
|
|
15
12
|
FetchLike,
|
|
16
13
|
HttpRequestLike,
|
|
17
14
|
ExtractDocumentType,
|
|
18
|
-
} from "./types";
|
|
15
|
+
} from "./types/client";
|
|
16
|
+
import type { LinkResolverFunction } from "./types/helpers";
|
|
17
|
+
import type { PrismicDocument } from "./types/value/document";
|
|
18
|
+
import type { Form, Repository } from "./types/api/repository";
|
|
19
|
+
import type { Query } from "./types/api/query";
|
|
20
|
+
import type { Ref } from "./types/api/ref";
|
|
21
|
+
|
|
22
|
+
import { asLink } from "./helpers/asLink";
|
|
23
|
+
|
|
19
24
|
import { ForbiddenError } from "./ForbiddenError";
|
|
20
25
|
import { NotFoundError } from "./NotFoundError";
|
|
21
26
|
import { ParsingError } from "./ParsingError";
|
|
@@ -199,7 +204,7 @@ type ResolvePreviewArgs<LinkResolverReturnType> = {
|
|
|
199
204
|
/**
|
|
200
205
|
* A function that maps a Prismic document to a URL within your app.
|
|
201
206
|
*/
|
|
202
|
-
linkResolver?:
|
|
207
|
+
linkResolver?: LinkResolverFunction<LinkResolverReturnType>;
|
|
203
208
|
|
|
204
209
|
/**
|
|
205
210
|
* A fallback URL if the Link Resolver does not return a value.
|
|
@@ -255,7 +260,7 @@ const someTagsPredicate = (tags: string | string[]): string =>
|
|
|
255
260
|
* third-party libraries.
|
|
256
261
|
*/
|
|
257
262
|
export interface CreateClient {
|
|
258
|
-
<TDocuments extends
|
|
263
|
+
<TDocuments extends PrismicDocument>(
|
|
259
264
|
...args: ConstructorParameters<typeof Client>
|
|
260
265
|
): Client<TDocuments>;
|
|
261
266
|
}
|
|
@@ -282,9 +287,7 @@ export interface CreateClient {
|
|
|
282
287
|
*
|
|
283
288
|
* @returns A client that can query content from the repository.
|
|
284
289
|
*/
|
|
285
|
-
export const createClient: CreateClient = <
|
|
286
|
-
TDocuments extends prismicT.PrismicDocument,
|
|
287
|
-
>(
|
|
290
|
+
export const createClient: CreateClient = <TDocuments extends PrismicDocument>(
|
|
288
291
|
repositoryNameOrEndpoint: string,
|
|
289
292
|
options?: ClientConfig,
|
|
290
293
|
) => new Client<TDocuments>(repositoryNameOrEndpoint, options);
|
|
@@ -299,9 +302,7 @@ export const createClient: CreateClient = <
|
|
|
299
302
|
* @typeParam TDocuments - Document types that are registered for the Prismic
|
|
300
303
|
* repository. Query methods will automatically be typed based on this type.
|
|
301
304
|
*/
|
|
302
|
-
export class Client<
|
|
303
|
-
TDocuments extends prismicT.PrismicDocument = prismicT.PrismicDocument,
|
|
304
|
-
> {
|
|
305
|
+
export class Client<TDocuments extends PrismicDocument = PrismicDocument> {
|
|
305
306
|
/**
|
|
306
307
|
* The Prismic REST API V2 endpoint for the repository (use
|
|
307
308
|
* `prismic.getRepositoryEndpoint` for the default endpoint).
|
|
@@ -351,7 +352,8 @@ export class Client<
|
|
|
351
352
|
>;
|
|
352
353
|
|
|
353
354
|
/**
|
|
354
|
-
* The client's ref mode state. This determines which ref is used during
|
|
355
|
+
* The client's ref mode state. This determines which ref is used during
|
|
356
|
+
* queries.
|
|
355
357
|
*/
|
|
356
358
|
private refState: RefState = {
|
|
357
359
|
mode: RefStateMode.Master,
|
|
@@ -361,7 +363,7 @@ export class Client<
|
|
|
361
363
|
/**
|
|
362
364
|
* Cached repository value.
|
|
363
365
|
*/
|
|
364
|
-
private cachedRepository:
|
|
366
|
+
private cachedRepository: Repository | undefined;
|
|
365
367
|
|
|
366
368
|
/**
|
|
367
369
|
* Timestamp at which the cached repository data is considered stale.
|
|
@@ -431,7 +433,8 @@ export class Client<
|
|
|
431
433
|
|
|
432
434
|
/**
|
|
433
435
|
* Enables the client to automatically query content from a preview session if
|
|
434
|
-
* one is active in browser environments. This is enabled by default in the
|
|
436
|
+
* one is active in browser environments. This is enabled by default in the
|
|
437
|
+
* browser.
|
|
435
438
|
*
|
|
436
439
|
* For server environments, use `enableAutoPreviewsFromReq`.
|
|
437
440
|
*
|
|
@@ -449,7 +452,8 @@ export class Client<
|
|
|
449
452
|
|
|
450
453
|
/**
|
|
451
454
|
* Enables the client to automatically query content from a preview session if
|
|
452
|
-
* one is active in server environments. This is disabled by default on the
|
|
455
|
+
* one is active in server environments. This is disabled by default on the
|
|
456
|
+
* server.
|
|
453
457
|
*
|
|
454
458
|
* For browser environments, use `enableAutoPreviews`.
|
|
455
459
|
*
|
|
@@ -462,7 +466,8 @@ export class Client<
|
|
|
462
466
|
* });
|
|
463
467
|
* ```
|
|
464
468
|
*
|
|
465
|
-
* @param req - An HTTP server request object containing the request's
|
|
469
|
+
* @param req - An HTTP server request object containing the request's
|
|
470
|
+
* cookies.
|
|
466
471
|
*/
|
|
467
472
|
enableAutoPreviewsFromReq<R extends HttpRequestLike>(req: R): void {
|
|
468
473
|
this.refState.httpRequest = req;
|
|
@@ -486,32 +491,6 @@ export class Client<
|
|
|
486
491
|
this.refState.autoPreviewsEnabled = false;
|
|
487
492
|
}
|
|
488
493
|
|
|
489
|
-
/**
|
|
490
|
-
* Queries content from the Prismic repository.
|
|
491
|
-
*
|
|
492
|
-
* @deprecated Use `get` instead.
|
|
493
|
-
* @example
|
|
494
|
-
*
|
|
495
|
-
* ```ts
|
|
496
|
-
* const response = await client.query(
|
|
497
|
-
* prismic.predicate.at("document.type", "page"),
|
|
498
|
-
* );
|
|
499
|
-
* ```
|
|
500
|
-
*
|
|
501
|
-
* @typeParam TDocument - Type of Prismic documents returned.
|
|
502
|
-
* @param params - Parameters to filter, sort, and paginate results.
|
|
503
|
-
*
|
|
504
|
-
* @returns A paginated response containing the result of the query.
|
|
505
|
-
*/
|
|
506
|
-
async query<TDocument extends TDocuments>(
|
|
507
|
-
predicates: NonNullable<BuildQueryURLArgs["predicates"]>,
|
|
508
|
-
params?: Partial<Omit<BuildQueryURLArgs, "predicates">> & FetchParams,
|
|
509
|
-
): Promise<prismicT.Query<TDocument>> {
|
|
510
|
-
const url = await this.buildQueryURL({ ...params, predicates });
|
|
511
|
-
|
|
512
|
-
return await this.fetch<prismicT.Query<TDocument>>(url, params);
|
|
513
|
-
}
|
|
514
|
-
|
|
515
494
|
/**
|
|
516
495
|
* Queries content from the Prismic repository.
|
|
517
496
|
*
|
|
@@ -528,10 +507,10 @@ export class Client<
|
|
|
528
507
|
*/
|
|
529
508
|
async get<TDocument extends TDocuments>(
|
|
530
509
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
531
|
-
): Promise<
|
|
510
|
+
): Promise<Query<TDocument>> {
|
|
532
511
|
const url = await this.buildQueryURL(params);
|
|
533
512
|
|
|
534
|
-
return await this.fetch<
|
|
513
|
+
return await this.fetch<Query<TDocument>>(url, params);
|
|
535
514
|
}
|
|
536
515
|
|
|
537
516
|
/**
|
|
@@ -556,7 +535,7 @@ export class Client<
|
|
|
556
535
|
actualParams.pageSize = this.defaultParams?.pageSize ?? 1;
|
|
557
536
|
}
|
|
558
537
|
const url = await this.buildQueryURL(actualParams);
|
|
559
|
-
const result = await this.fetch<
|
|
538
|
+
const result = await this.fetch<Query<TDocument>>(url, params);
|
|
560
539
|
|
|
561
540
|
const firstResult = result.results[0];
|
|
562
541
|
|
|
@@ -575,7 +554,8 @@ export class Client<
|
|
|
575
554
|
* Queries content from the Prismic repository and returns all matching
|
|
576
555
|
* content. If no predicates are provided, all documents will be fetched.
|
|
577
556
|
*
|
|
578
|
-
* This method may make multiple network requests to query all matching
|
|
557
|
+
* This method may make multiple network requests to query all matching
|
|
558
|
+
* content.
|
|
579
559
|
*
|
|
580
560
|
* @example
|
|
581
561
|
*
|
|
@@ -603,7 +583,7 @@ export class Client<
|
|
|
603
583
|
};
|
|
604
584
|
|
|
605
585
|
const documents: TDocument[] = [];
|
|
606
|
-
let latestResult:
|
|
586
|
+
let latestResult: Query<TDocument> | undefined;
|
|
607
587
|
|
|
608
588
|
while (
|
|
609
589
|
(!latestResult || latestResult.next_page) &&
|
|
@@ -628,7 +608,8 @@ export class Client<
|
|
|
628
608
|
* @remarks
|
|
629
609
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
630
610
|
* for all documents and is made available on its `id` property. A UID is
|
|
631
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
611
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
612
|
+
* Custom Type.
|
|
632
613
|
* @example
|
|
633
614
|
*
|
|
634
615
|
* ```ts
|
|
@@ -657,7 +638,8 @@ export class Client<
|
|
|
657
638
|
* @remarks
|
|
658
639
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
659
640
|
* for all documents and is made available on its `id` property. A UID is
|
|
660
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
641
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
642
|
+
* Custom Type.
|
|
661
643
|
* @example
|
|
662
644
|
*
|
|
663
645
|
* ```ts
|
|
@@ -677,7 +659,7 @@ export class Client<
|
|
|
677
659
|
async getByIDs<TDocument extends TDocuments>(
|
|
678
660
|
ids: string[],
|
|
679
661
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
680
|
-
): Promise<
|
|
662
|
+
): Promise<Query<TDocument>> {
|
|
681
663
|
return await this.get<TDocument>(
|
|
682
664
|
appendPredicates(params, predicate.in("document.id", ids)),
|
|
683
665
|
);
|
|
@@ -686,12 +668,14 @@ export class Client<
|
|
|
686
668
|
/**
|
|
687
669
|
* Queries all documents from the Prismic repository with specific IDs.
|
|
688
670
|
*
|
|
689
|
-
* This method may make multiple network requests to query all matching
|
|
671
|
+
* This method may make multiple network requests to query all matching
|
|
672
|
+
* content.
|
|
690
673
|
*
|
|
691
674
|
* @remarks
|
|
692
675
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
693
676
|
* for all documents and is made available on its `id` property. A UID is
|
|
694
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
677
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
678
|
+
* Custom Type.
|
|
695
679
|
* @example
|
|
696
680
|
*
|
|
697
681
|
* ```ts
|
|
@@ -717,12 +701,14 @@ export class Client<
|
|
|
717
701
|
}
|
|
718
702
|
|
|
719
703
|
/**
|
|
720
|
-
* Queries a document from the Prismic repository with a specific UID and
|
|
704
|
+
* Queries a document from the Prismic repository with a specific UID and
|
|
705
|
+
* Custom Type.
|
|
721
706
|
*
|
|
722
707
|
* @remarks
|
|
723
708
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
724
709
|
* for all documents and is made available on its `id` property. A UID is
|
|
725
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
710
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
711
|
+
* Custom Type.
|
|
726
712
|
* @example
|
|
727
713
|
*
|
|
728
714
|
* ```ts
|
|
@@ -754,12 +740,14 @@ export class Client<
|
|
|
754
740
|
}
|
|
755
741
|
|
|
756
742
|
/**
|
|
757
|
-
* Queries document from the Prismic repository with specific UIDs and Custom
|
|
743
|
+
* Queries document from the Prismic repository with specific UIDs and Custom
|
|
744
|
+
* Type.
|
|
758
745
|
*
|
|
759
746
|
* @remarks
|
|
760
747
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
761
748
|
* for all documents and is made available on its `id` property. A UID is
|
|
762
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
749
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
750
|
+
* Custom Type.
|
|
763
751
|
* @example
|
|
764
752
|
*
|
|
765
753
|
* ```ts
|
|
@@ -784,7 +772,7 @@ export class Client<
|
|
|
784
772
|
documentType: TDocumentType,
|
|
785
773
|
uids: string[],
|
|
786
774
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
787
|
-
): Promise<
|
|
775
|
+
): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>> {
|
|
788
776
|
return await this.get<ExtractDocumentType<TDocument, TDocumentType>>(
|
|
789
777
|
appendPredicates(params, [
|
|
790
778
|
typePredicate(documentType),
|
|
@@ -794,14 +782,17 @@ export class Client<
|
|
|
794
782
|
}
|
|
795
783
|
|
|
796
784
|
/**
|
|
797
|
-
* Queries all documents from the Prismic repository with specific UIDs and
|
|
785
|
+
* Queries all documents from the Prismic repository with specific UIDs and
|
|
786
|
+
* Custom Type.
|
|
798
787
|
*
|
|
799
|
-
* This method may make multiple network requests to query all matching
|
|
788
|
+
* This method may make multiple network requests to query all matching
|
|
789
|
+
* content.
|
|
800
790
|
*
|
|
801
791
|
* @remarks
|
|
802
792
|
* A document's UID is different from its ID. An ID is automatically generated
|
|
803
793
|
* for all documents and is made available on its `id` property. A UID is
|
|
804
|
-
* provided in the Prismic editor and is unique among all documents of its
|
|
794
|
+
* provided in the Prismic editor and is unique among all documents of its
|
|
795
|
+
* Custom Type.
|
|
805
796
|
* @example
|
|
806
797
|
*
|
|
807
798
|
* ```ts
|
|
@@ -837,7 +828,8 @@ export class Client<
|
|
|
837
828
|
}
|
|
838
829
|
|
|
839
830
|
/**
|
|
840
|
-
* Queries a singleton document from the Prismic repository for a specific
|
|
831
|
+
* Queries a singleton document from the Prismic repository for a specific
|
|
832
|
+
* Custom Type.
|
|
841
833
|
*
|
|
842
834
|
* @remarks
|
|
843
835
|
* A singleton document is one that is configured in Prismic to only allow one
|
|
@@ -854,7 +846,8 @@ export class Client<
|
|
|
854
846
|
* @param documentType - The API ID of the singleton Custom Type.
|
|
855
847
|
* @param params - Parameters to filter, sort, and paginate the results.
|
|
856
848
|
*
|
|
857
|
-
* @returns The singleton document for the Custom Type, if a matching document
|
|
849
|
+
* @returns The singleton document for the Custom Type, if a matching document
|
|
850
|
+
* exists.
|
|
858
851
|
*/
|
|
859
852
|
async getSingle<
|
|
860
853
|
TDocument extends TDocuments,
|
|
@@ -892,16 +885,18 @@ export class Client<
|
|
|
892
885
|
>(
|
|
893
886
|
documentType: TDocumentType,
|
|
894
887
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
895
|
-
): Promise<
|
|
888
|
+
): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>> {
|
|
896
889
|
return await this.get<ExtractDocumentType<TDocument, TDocumentType>>(
|
|
897
890
|
appendPredicates(params, typePredicate(documentType)),
|
|
898
891
|
);
|
|
899
892
|
}
|
|
900
893
|
|
|
901
894
|
/**
|
|
902
|
-
* Queries all documents from the Prismic repository for a specific Custom
|
|
895
|
+
* Queries all documents from the Prismic repository for a specific Custom
|
|
896
|
+
* Type.
|
|
903
897
|
*
|
|
904
|
-
* This method may make multiple network requests to query all matching
|
|
898
|
+
* This method may make multiple network requests to query all matching
|
|
899
|
+
* content.
|
|
905
900
|
*
|
|
906
901
|
* @example
|
|
907
902
|
*
|
|
@@ -932,7 +927,8 @@ export class Client<
|
|
|
932
927
|
/**
|
|
933
928
|
* Queries documents from the Prismic repository with a specific tag.
|
|
934
929
|
*
|
|
935
|
-
* Use `getAllByTag` instead if you need to query all documents with a
|
|
930
|
+
* Use `getAllByTag` instead if you need to query all documents with a
|
|
931
|
+
* specific tag.
|
|
936
932
|
*
|
|
937
933
|
* @example
|
|
938
934
|
*
|
|
@@ -949,7 +945,7 @@ export class Client<
|
|
|
949
945
|
async getByTag<TDocument extends TDocuments>(
|
|
950
946
|
tag: string,
|
|
951
947
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
952
|
-
): Promise<
|
|
948
|
+
): Promise<Query<TDocument>> {
|
|
953
949
|
return await this.get<TDocument>(
|
|
954
950
|
appendPredicates(params, someTagsPredicate(tag)),
|
|
955
951
|
);
|
|
@@ -958,7 +954,8 @@ export class Client<
|
|
|
958
954
|
/**
|
|
959
955
|
* Queries all documents from the Prismic repository with a specific tag.
|
|
960
956
|
*
|
|
961
|
-
* This method may make multiple network requests to query all matching
|
|
957
|
+
* This method may make multiple network requests to query all matching
|
|
958
|
+
* content.
|
|
962
959
|
*
|
|
963
960
|
* @example
|
|
964
961
|
*
|
|
@@ -1002,7 +999,7 @@ export class Client<
|
|
|
1002
999
|
async getByEveryTag<TDocument extends TDocuments>(
|
|
1003
1000
|
tags: string[],
|
|
1004
1001
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
1005
|
-
): Promise<
|
|
1002
|
+
): Promise<Query<TDocument>> {
|
|
1006
1003
|
return await this.get<TDocument>(
|
|
1007
1004
|
appendPredicates(params, everyTagPredicate(tags)),
|
|
1008
1005
|
);
|
|
@@ -1012,7 +1009,8 @@ export class Client<
|
|
|
1012
1009
|
* Queries documents from the Prismic repository with specific tags. A
|
|
1013
1010
|
* document must be tagged with all of the queried tags to be included.
|
|
1014
1011
|
*
|
|
1015
|
-
* This method may make multiple network requests to query all matching
|
|
1012
|
+
* This method may make multiple network requests to query all matching
|
|
1013
|
+
* content.
|
|
1016
1014
|
*
|
|
1017
1015
|
* @example
|
|
1018
1016
|
*
|
|
@@ -1039,7 +1037,8 @@ export class Client<
|
|
|
1039
1037
|
|
|
1040
1038
|
/**
|
|
1041
1039
|
* Queries documents from the Prismic repository with specific tags. A
|
|
1042
|
-
* document must be tagged with at least one of the queried tags to be
|
|
1040
|
+
* document must be tagged with at least one of the queried tags to be
|
|
1041
|
+
* included.
|
|
1043
1042
|
*
|
|
1044
1043
|
* @example
|
|
1045
1044
|
*
|
|
@@ -1051,12 +1050,13 @@ export class Client<
|
|
|
1051
1050
|
* @param tags - A list of tags that must be included on a document.
|
|
1052
1051
|
* @param params - Parameters to filter, sort, and paginate the results.
|
|
1053
1052
|
*
|
|
1054
|
-
* @returns A paginated response containing documents with at least one of the
|
|
1053
|
+
* @returns A paginated response containing documents with at least one of the
|
|
1054
|
+
* tags.
|
|
1055
1055
|
*/
|
|
1056
1056
|
async getBySomeTags<TDocument extends TDocuments>(
|
|
1057
1057
|
tags: string[],
|
|
1058
1058
|
params?: Partial<BuildQueryURLArgs> & FetchParams,
|
|
1059
|
-
): Promise<
|
|
1059
|
+
): Promise<Query<TDocument>> {
|
|
1060
1060
|
return await this.get<TDocument>(
|
|
1061
1061
|
appendPredicates(params, someTagsPredicate(tags)),
|
|
1062
1062
|
);
|
|
@@ -1064,9 +1064,11 @@ export class Client<
|
|
|
1064
1064
|
|
|
1065
1065
|
/**
|
|
1066
1066
|
* Queries documents from the Prismic repository with specific tags. A
|
|
1067
|
-
* document must be tagged with at least one of the queried tags to be
|
|
1067
|
+
* document must be tagged with at least one of the queried tags to be
|
|
1068
|
+
* included.
|
|
1068
1069
|
*
|
|
1069
|
-
* This method may make multiple network requests to query all matching
|
|
1070
|
+
* This method may make multiple network requests to query all matching
|
|
1071
|
+
* content.
|
|
1070
1072
|
*
|
|
1071
1073
|
* @example
|
|
1072
1074
|
*
|
|
@@ -1097,9 +1099,9 @@ export class Client<
|
|
|
1097
1099
|
*
|
|
1098
1100
|
* @returns Repository metadata.
|
|
1099
1101
|
*/
|
|
1100
|
-
async getRepository(params?: FetchParams): Promise<
|
|
1102
|
+
async getRepository(params?: FetchParams): Promise<Repository> {
|
|
1101
1103
|
// TODO: Restore when Authorization header support works in browsers with CORS.
|
|
1102
|
-
// return await this.fetch<
|
|
1104
|
+
// return await this.fetch<Repository>(this.endpoint);
|
|
1103
1105
|
|
|
1104
1106
|
const url = new URL(this.endpoint);
|
|
1105
1107
|
|
|
@@ -1107,7 +1109,7 @@ export class Client<
|
|
|
1107
1109
|
url.searchParams.set("access_token", this.accessToken);
|
|
1108
1110
|
}
|
|
1109
1111
|
|
|
1110
|
-
return await this.fetch<
|
|
1112
|
+
return await this.fetch<Repository>(url.toString(), params);
|
|
1111
1113
|
}
|
|
1112
1114
|
|
|
1113
1115
|
/**
|
|
@@ -1119,7 +1121,7 @@ export class Client<
|
|
|
1119
1121
|
*
|
|
1120
1122
|
* @returns A list of all refs for the Prismic repository.
|
|
1121
1123
|
*/
|
|
1122
|
-
async getRefs(params?: FetchParams): Promise<
|
|
1124
|
+
async getRefs(params?: FetchParams): Promise<Ref[]> {
|
|
1123
1125
|
const repository = await this.getRepository(params);
|
|
1124
1126
|
|
|
1125
1127
|
return repository.refs;
|
|
@@ -1132,7 +1134,7 @@ export class Client<
|
|
|
1132
1134
|
*
|
|
1133
1135
|
* @returns The ref with a matching ID, if it exists.
|
|
1134
1136
|
*/
|
|
1135
|
-
async getRefByID(id: string, params?: FetchParams): Promise<
|
|
1137
|
+
async getRefByID(id: string, params?: FetchParams): Promise<Ref> {
|
|
1136
1138
|
const refs = await this.getRefs(params);
|
|
1137
1139
|
|
|
1138
1140
|
return findRefByID(refs, id);
|
|
@@ -1145,10 +1147,7 @@ export class Client<
|
|
|
1145
1147
|
*
|
|
1146
1148
|
* @returns The ref with a matching label, if it exists.
|
|
1147
1149
|
*/
|
|
1148
|
-
async getRefByLabel(
|
|
1149
|
-
label: string,
|
|
1150
|
-
params?: FetchParams,
|
|
1151
|
-
): Promise<prismicT.Ref> {
|
|
1150
|
+
async getRefByLabel(label: string, params?: FetchParams): Promise<Ref> {
|
|
1152
1151
|
const refs = await this.getRefs(params);
|
|
1153
1152
|
|
|
1154
1153
|
return findRefByLabel(refs, label);
|
|
@@ -1160,7 +1159,7 @@ export class Client<
|
|
|
1160
1159
|
*
|
|
1161
1160
|
* @returns The repository's master ref.
|
|
1162
1161
|
*/
|
|
1163
|
-
async getMasterRef(params?: FetchParams): Promise<
|
|
1162
|
+
async getMasterRef(params?: FetchParams): Promise<Ref> {
|
|
1164
1163
|
const refs = await this.getRefs(params);
|
|
1165
1164
|
|
|
1166
1165
|
return findMasterRef(refs);
|
|
@@ -1172,7 +1171,7 @@ export class Client<
|
|
|
1172
1171
|
*
|
|
1173
1172
|
* @returns A list of all Releases for the Prismic repository.
|
|
1174
1173
|
*/
|
|
1175
|
-
async getReleases(params?: FetchParams): Promise<
|
|
1174
|
+
async getReleases(params?: FetchParams): Promise<Ref[]> {
|
|
1176
1175
|
const refs = await this.getRefs(params);
|
|
1177
1176
|
|
|
1178
1177
|
return refs.filter((ref) => !ref.isMasterRef);
|
|
@@ -1185,10 +1184,7 @@ export class Client<
|
|
|
1185
1184
|
*
|
|
1186
1185
|
* @returns The Release with a matching ID, if it exists.
|
|
1187
1186
|
*/
|
|
1188
|
-
async getReleaseByID(
|
|
1189
|
-
id: string,
|
|
1190
|
-
params?: FetchParams,
|
|
1191
|
-
): Promise<prismicT.Ref> {
|
|
1187
|
+
async getReleaseByID(id: string, params?: FetchParams): Promise<Ref> {
|
|
1192
1188
|
const releases = await this.getReleases(params);
|
|
1193
1189
|
|
|
1194
1190
|
return findRefByID(releases, id);
|
|
@@ -1201,10 +1197,7 @@ export class Client<
|
|
|
1201
1197
|
*
|
|
1202
1198
|
* @returns The ref with a matching label, if it exists.
|
|
1203
1199
|
*/
|
|
1204
|
-
async getReleaseByLabel(
|
|
1205
|
-
label: string,
|
|
1206
|
-
params?: FetchParams,
|
|
1207
|
-
): Promise<prismicT.Ref> {
|
|
1200
|
+
async getReleaseByLabel(label: string, params?: FetchParams): Promise<Ref> {
|
|
1208
1201
|
const releases = await this.getReleases(params);
|
|
1209
1202
|
|
|
1210
1203
|
return findRefByLabel(releases, label);
|
|
@@ -1316,7 +1309,7 @@ export class Client<
|
|
|
1316
1309
|
lang: "*",
|
|
1317
1310
|
});
|
|
1318
1311
|
|
|
1319
|
-
const url =
|
|
1312
|
+
const url = asLink(document, args.linkResolver);
|
|
1320
1313
|
|
|
1321
1314
|
if (typeof url === "string") {
|
|
1322
1315
|
return url;
|
|
@@ -1327,9 +1320,11 @@ export class Client<
|
|
|
1327
1320
|
}
|
|
1328
1321
|
|
|
1329
1322
|
/**
|
|
1330
|
-
* Configures the client to query the latest published content for all future
|
|
1323
|
+
* Configures the client to query the latest published content for all future
|
|
1324
|
+
* queries.
|
|
1331
1325
|
*
|
|
1332
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
1326
|
+
* If the `ref` parameter is provided during a query, it takes priority for
|
|
1327
|
+
* that query.
|
|
1333
1328
|
*
|
|
1334
1329
|
* @example
|
|
1335
1330
|
*
|
|
@@ -1346,7 +1341,8 @@ export class Client<
|
|
|
1346
1341
|
* Configures the client to query content from a specific Release identified
|
|
1347
1342
|
* by its ID for all future queries.
|
|
1348
1343
|
*
|
|
1349
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
1344
|
+
* If the `ref` parameter is provided during a query, it takes priority for
|
|
1345
|
+
* that query.
|
|
1350
1346
|
*
|
|
1351
1347
|
* @example
|
|
1352
1348
|
*
|
|
@@ -1369,7 +1365,8 @@ export class Client<
|
|
|
1369
1365
|
* Configures the client to query content from a specific Release identified
|
|
1370
1366
|
* by its label for all future queries.
|
|
1371
1367
|
*
|
|
1372
|
-
* If the `ref` parameter is provided during a query, it takes priority for
|
|
1368
|
+
* If the `ref` parameter is provided during a query, it takes priority for
|
|
1369
|
+
* that query.
|
|
1373
1370
|
*
|
|
1374
1371
|
* @example
|
|
1375
1372
|
*
|
|
@@ -1402,7 +1399,8 @@ export class Client<
|
|
|
1402
1399
|
* const document = await client.getByID("WW4bKScAAMAqmluX");
|
|
1403
1400
|
* ```
|
|
1404
1401
|
*
|
|
1405
|
-
* @param ref - The ref or a function that returns the ref from which to query
|
|
1402
|
+
* @param ref - The ref or a function that returns the ref from which to query
|
|
1403
|
+
* content.
|
|
1406
1404
|
*/
|
|
1407
1405
|
queryContentFromRef(ref: RefStringOrThunk): void {
|
|
1408
1406
|
this.refState = {
|
|
@@ -1412,12 +1410,6 @@ export class Client<
|
|
|
1412
1410
|
};
|
|
1413
1411
|
}
|
|
1414
1412
|
|
|
1415
|
-
/**
|
|
1416
|
-
* @deprecated Renamed to `graphQLFetch()` (note the capitalization of "QL").
|
|
1417
|
-
*/
|
|
1418
|
-
// TODO: Remove in v7
|
|
1419
|
-
graphqlFetch = this.graphQLFetch.bind(this);
|
|
1420
|
-
|
|
1421
1413
|
/**
|
|
1422
1414
|
* A `fetch()` function to be used with GraphQL clients configured for
|
|
1423
1415
|
* Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
|
|
@@ -1427,11 +1419,11 @@ export class Client<
|
|
|
1427
1419
|
* @example
|
|
1428
1420
|
*
|
|
1429
1421
|
* ```ts
|
|
1430
|
-
* const
|
|
1422
|
+
* const graphQLClient = new ApolloClient({
|
|
1431
1423
|
* link: new HttpLink({
|
|
1432
1424
|
* uri: prismic.getGraphQLEndpoint(repositoryName),
|
|
1433
|
-
* // Provide `client.
|
|
1434
|
-
* fetch: client.
|
|
1425
|
+
* // Provide `client.graphQLFetch` as the fetch implementation.
|
|
1426
|
+
* fetch: client.graphQLFetch,
|
|
1435
1427
|
* // Using GET is required.
|
|
1436
1428
|
* useGETForQueries: true,
|
|
1437
1429
|
* }),
|
|
@@ -1440,7 +1432,8 @@ export class Client<
|
|
|
1440
1432
|
* ```
|
|
1441
1433
|
*
|
|
1442
1434
|
* @param input - The `fetch()` `input` parameter. Only strings are supported.
|
|
1443
|
-
* @param init - The `fetch()` `init` parameter. Only plain objects are
|
|
1435
|
+
* @param init - The `fetch()` `init` parameter. Only plain objects are
|
|
1436
|
+
* supported.
|
|
1444
1437
|
*
|
|
1445
1438
|
* @returns The `fetch()` Response for the request.
|
|
1446
1439
|
* @experimental
|
|
@@ -1518,9 +1511,7 @@ export class Client<
|
|
|
1518
1511
|
*
|
|
1519
1512
|
* @returns Cached repository metadata.
|
|
1520
1513
|
*/
|
|
1521
|
-
private async getCachedRepository(
|
|
1522
|
-
params?: FetchParams,
|
|
1523
|
-
): Promise<prismicT.Repository> {
|
|
1514
|
+
private async getCachedRepository(params?: FetchParams): Promise<Repository> {
|
|
1524
1515
|
if (
|
|
1525
1516
|
!this.cachedRepository ||
|
|
1526
1517
|
Date.now() >= this.cachedRepositoryExpiration
|
|
@@ -1544,7 +1535,7 @@ export class Client<
|
|
|
1544
1535
|
private async getCachedRepositoryForm(
|
|
1545
1536
|
name: string,
|
|
1546
1537
|
params?: FetchParams,
|
|
1547
|
-
): Promise<
|
|
1538
|
+
): Promise<Form> {
|
|
1548
1539
|
const cachedRepository = await this.getCachedRepository(params);
|
|
1549
1540
|
const form = cachedRepository.forms[name];
|
|
1550
1541
|
|
|
@@ -1561,14 +1552,16 @@ export class Client<
|
|
|
1561
1552
|
|
|
1562
1553
|
/**
|
|
1563
1554
|
* Returns the ref needed to query based on the client's current state. This
|
|
1564
|
-
* method may make a network request to fetch a ref or resolve the user's ref
|
|
1555
|
+
* method may make a network request to fetch a ref or resolve the user's ref
|
|
1556
|
+
* thunk.
|
|
1565
1557
|
*
|
|
1566
1558
|
* If auto previews are enabled, the preview ref takes priority if available.
|
|
1567
1559
|
*
|
|
1568
1560
|
* The following strategies are used depending on the client's state:
|
|
1569
1561
|
*
|
|
1570
1562
|
* - If the user called `queryLatestContent`: Use the repository's master ref.
|
|
1571
|
-
* The ref is cached for 5 seconds. After 5 seconds, a new master ref is
|
|
1563
|
+
* The ref is cached for 5 seconds. After 5 seconds, a new master ref is
|
|
1564
|
+
* fetched.
|
|
1572
1565
|
* - If the user called `queryContentFromReleaseByID`: Use the release's ref.
|
|
1573
1566
|
* The ref is cached for 5 seconds. After 5 seconds, a new ref for the
|
|
1574
1567
|
* release is fetched.
|
package/src/cookie.ts
CHANGED
package/src/getRepositoryName.ts
CHANGED
|
@@ -4,11 +4,13 @@ import { PrismicError } from "./PrismicError";
|
|
|
4
4
|
* Get a Prismic repository's name from its standard Prismic Rest API V2 or
|
|
5
5
|
* GraphQL endpoint.
|
|
6
6
|
*
|
|
7
|
-
* @typeParam RepositoryEndpoint - Prismic Rest API V2 endpoint for the
|
|
7
|
+
* @typeParam RepositoryEndpoint - Prismic Rest API V2 endpoint for the
|
|
8
|
+
* repository.
|
|
8
9
|
* @param repositoryEndpoint - Prismic Rest API V2 endpoint for the repository.
|
|
9
10
|
*
|
|
10
11
|
* @returns The Prismic repository's name.
|
|
11
|
-
* @throws {@link Error} Thrown if an invalid Prismic Rest API V2 endpoint is
|
|
12
|
+
* @throws {@link Error} Thrown if an invalid Prismic Rest API V2 endpoint is
|
|
13
|
+
* provided.
|
|
12
14
|
*/
|
|
13
15
|
export const getRepositoryName = (repositoryEndpoint: string): string => {
|
|
14
16
|
try {
|