@prismicio/client
Version:
The official JavaScript + TypeScript client library for Prismic
943 lines (942 loc) • 35.9 kB
TypeScript
import type { Query } from "./types/api/query";
import type { Ref } from "./types/api/ref";
import type { Repository } from "./types/api/repository";
import type { PrismicDocument } from "./types/value/document";
import type { LinkResolverFunction } from "./helpers/asLink";
import { type AbortSignalLike, BaseClient, type BaseClientConfig, type FetchParams, type HttpRequestLike } from "./BaseClient";
import type { BuildQueryURLArgs } from "./buildQueryURL";
/**
* The number of milliseconds in which repository metadata is considered valid.
* A ref can be invalidated quickly depending on how frequently content is
* updated in the Prismic repository. As such, repository's metadata can only be
* considered valid for a short amount of time.
*/
export declare const REPOSITORY_CACHE_TTL = 5000;
/**
* The number of milliseconds in which a multi-page `getAll` (e.g. `getAll`,
* `getAllByType`, `getAllByTag`) will wait between individual page requests.
*
* This is done to ensure API performance is sustainable and reduces the chance
* of a failed API request due to overloading.
*/
export declare const GET_ALL_QUERY_DELAY = 500;
/**
* Extracts one or more Prismic document types that match a given Prismic
* document type. If no matches are found, no extraction is performed and the
* union of all provided Prismic document types are returned.
*
* @typeParam TDocuments - Prismic document types from which to extract.
* @typeParam TDocumentType - Type(s) to match `TDocuments` against.
*/
type ExtractDocumentType<TDocuments extends PrismicDocument, TDocumentType extends TDocuments["type"]> = Extract<TDocuments, {
type: TDocumentType;
}> extends never ? TDocuments : Extract<TDocuments, {
type: TDocumentType;
}>;
/**
* A ref or a function that returns a ref. If a static ref is known, one can be
* given. If the ref must be fetched on-demand, a function can be provided. This
* function can optionally be asynchronous.
*/
type RefStringOrThunk = string | (() => string | undefined | Promise<string | undefined>);
/**
* Configuration for clients that determine how content is queried.
*/
export type ClientConfig = {
/**
* The full Rest API V2 endpoint for the repository. This is only helpful if
* you're using Prismic behind a proxy which we do not recommend.
*
* @defaultValue `getRepositoryEndpoint(repositoryNameOrEndpoint)`
*/
documentAPIEndpoint?: string;
/**
* The secure token for accessing the Prismic repository. This is only
* required if the repository is set to private.
*/
accessToken?: string;
/**
* A string representing a version of the Prismic repository's content. This
* may point to the latest version (called the "master ref"), or a preview
* with draft content.
*/
ref?: RefStringOrThunk;
/**
* A list of route resolver objects that define how a document's `url`
* property is resolved.
*
* {@link https://prismic.io/docs/route-resolver}
*/
routes?: NonNullable<BuildQueryURLArgs["routes"]>;
/**
* The `brokenRoute` option allows you to define the route populated in the
* `url` property for broken link or content relationship fields. A broken
* link is a link or content relationship field whose linked document has been
* unpublished or deleted.
*
* {@link https://prismic.io/docs/route-resolver}
*/
brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>;
/**
* Default parameters that will be sent with each query. These parameters can
* be overridden on each query if needed.
*/
defaultParams?: Omit<BuildQueryURLArgs, "ref" | "integrationFieldsRef" | "accessToken" | "routes" | "brokenRoute">;
} & BaseClientConfig;
/**
* Parameters specific to client methods that fetch all documents. These methods
* start with `getAll` (for example, `getAllByType`).
*/
type GetAllParams = {
/**
* Limit the number of documents queried. If a number is not provided, there
* will be no limit and all matching documents will be returned.
*/
limit?: number;
};
/**
* Arguments to determine how the URL for a preview session is resolved.
*/
type ResolvePreviewArgs<LinkResolverReturnType> = {
/**
* A function that maps a Prismic document to a URL within your app.
*/
linkResolver?: LinkResolverFunction<LinkResolverReturnType>;
/**
* A fallback URL if the link resolver does not return a value.
*/
defaultURL: string;
/**
* The preview token (also known as a ref) that will be used to query preview
* content from the Prismic repository.
*/
previewToken?: string;
/**
* The previewed document that will be used to determine the destination URL.
*/
documentID?: string;
};
/**
* A client that allows querying content from a Prismic repository.
*
* If used in an environment where a global `fetch` function is unavailable,
* such as Node.js, the `fetch` option must be provided as part of the `options`
* parameter.
*
* @typeParam TDocuments - Document types that are registered for the Prismic
* repository. Query methods will automatically be typed based on this type.
*/
export declare class Client<TDocuments extends PrismicDocument = PrismicDocument> extends BaseClient {
#private;
/**
* The Prismic repository's name.
*/
set repositoryName(value: string);
/**
* The Prismic repository's name.
*/
get repositoryName(): string;
/**
* The Prismic REST API V2 endpoint for the repository (use
* `prismic.getRepositoryEndpoint` for the default endpoint).
*/
documentAPIEndpoint: string;
/**
* The Prismic REST API V2 endpoint for the repository (use
* `prismic.getRepositoryEndpoint` for the default endpoint).
*
* @deprecated Use `documentAPIEndpoint` instead.
*/
set endpoint(value: string);
/**
* The Prismic REST API V2 endpoint for the repository (use
* `prismic.getRepositoryEndpoint` for the default endpoint).
*
* @deprecated Use `documentAPIEndpoint` instead.
*/
get endpoint(): string;
/**
* The secure token for accessing the API (only needed if your repository is
* set to private).
*
* {@link https://user-guides.prismic.io/en/articles/1036153-generating-an-access-token}
*/
accessToken?: string;
/**
* A list of route resolver objects that define how a document's `url` field
* is resolved.
*
* {@link https://prismic.io/docs/route-resolver}
*/
routes?: NonNullable<BuildQueryURLArgs["routes"]>;
/**
* The `brokenRoute` option allows you to define the route populated in the
* `url` property for broken link or content relationship fields. A broken
* link is a link or content relationship field whose linked document has been
* unpublished or deleted.
*
* {@link https://prismic.io/docs/route-resolver}
*/
brokenRoute?: NonNullable<BuildQueryURLArgs["brokenRoute"]>;
/**
* Default parameters that will be sent with each query. These parameters can
* be overridden on each query if needed.
*/
defaultParams?: Omit<BuildQueryURLArgs, "ref" | "integrationFieldsRef" | "accessToken" | "routes">;
/**
* The client's ref mode state. This determines which ref is used during
* queries.
*/
private refState;
/**
* Cached repository value.
*/
private cachedRepository;
/**
* Timestamp at which the cached repository data is considered stale.
*/
private cachedRepositoryExpiration;
/**
* Creates a Prismic client that can be used to query a repository.
*
* If used in an environment where a global `fetch` function is unavailable,
* such as in some Node.js versions, the `fetch` option must be provided as
* part of the `options` parameter.
*
* @param repositoryNameOrEndpoint - The Prismic repository name or full Rest
* API V2 endpoint for the repository.
* @param options - Configuration that determines how content will be queried
* from the Prismic repository.
*
* @returns A client that can query content from the repository.
*/
constructor(repositoryNameOrEndpoint: string, options?: ClientConfig);
/**
* Enables the client to automatically query content from a preview session if
* one is active in browser environments. This is enabled by default in the
* browser.
*
* For server environments, use `enableAutoPreviewsFromReq`.
*
* @example
*
* ```ts
* client.enableAutoPreviews()
* ```
*
* @see enableAutoPreviewsFromReq
*/
enableAutoPreviews(): void;
/**
* Enables the client to automatically query content from a preview session if
* one is active in server environments. This is disabled by default on the
* server.
*
* For browser environments, use `enableAutoPreviews`.
*
* @example
*
* ```ts
* // In an express app
* app.get("/", function (req, res) {
* client.enableAutoPreviewsFromReq(req)
* })
* ```
*
* @param req - An HTTP server request object containing the request's
* cookies.
*/
enableAutoPreviewsFromReq<R extends HttpRequestLike>(req: R): void;
/**
* Disables the client from automatically querying content from a preview
* session if one is active.
*
* Automatic preview content querying is enabled by default unless this method
* is called.
*
* @example
*
* ```ts
* client.disableAutoPreviews()
* ```
*/
disableAutoPreviews(): void;
/**
* Queries content from the Prismic repository.
*
* @example
*
* ```ts
* const response = await client.get()
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param params - Parameters to filter, sort, and paginate results.
*
* @returns A paginated response containing the result of the query.
*/
get<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
/**
* Queries content from the Prismic repository and returns only the first
* result, if any.
*
* @example
*
* ```ts
* const document = await client.getFirst()
* ```
*
* @typeParam TDocument - Type of the Prismic document returned.
*
* @param params - Parameters to filter, sort, and paginate results.
*
* @returns The first result of the query, if any.
*/
getFirst<TDocument extends TDocuments>(params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
/**
* **IMPORTANT**: Avoid using `dangerouslyGetAll` as it may be slower and
* require more resources than other methods. Prefer using other methods that
* filter by filters such as `getAllByType`.
*
* Queries content from the Prismic repository and returns all matching
* content. If no filters are provided, all documents will be fetched.
*
* This method may make multiple network requests to query all matching
* content.
*
* @example
*
* ```ts
* const response = await client.dangerouslyGetAll()
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param params - Parameters to filter, sort, and paginate results.
*
* @returns A list of documents matching the query.
*/
dangerouslyGetAll<TDocument extends TDocuments>(params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
/**
* Queries a document from the Prismic repository with a specific ID.
*
* @remarks
* A document's UID is different from its ID. An ID is automatically generated
* for all documents and is made available on its `id` property. A UID is
* provided in the Prismic editor and is unique among all documents of its
* custom type.
*
* @example
*
* ```ts
* const document = await client.getByID("WW4bKScAAMAqmluX")
* ```
*
* @typeParam TDocument- Type of the Prismic document returned.
*
* @param id - ID of the document.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns The document with an ID matching the `id` parameter, if a matching
* document exists.
*/
getByID<TDocument extends TDocuments>(id: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<TDocument>;
/**
* Queries documents from the Prismic repository with specific IDs.
*
* @remarks
* A document's UID is different from its ID. An ID is automatically generated
* for all documents and is made available on its `id` property. A UID is
* provided in the Prismic editor and is unique among all documents of its
* custom type.
*
* @example
*
* ```ts
* const response = await client.getByIDs([
* "WW4bKScAAMAqmluX",
* "U1kTRgEAAC8A5ldS",
* ])
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param ids - A list of document IDs.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A paginated response containing documents with IDs matching the
* `ids` parameter.
*/
getByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
/**
* Queries all documents from the Prismic repository with specific IDs.
*
* This method may make multiple network requests to query all matching
* content.
*
* @remarks
* A document's UID is different from its ID. An ID is automatically generated
* for all documents and is made available on its `id` property. A UID is
* provided in the Prismic editor and is unique among all documents of its
* custom type.
*
* @example
*
* ```ts
* const response = await client.getAllByIDs([
* "WW4bKScAAMAqmluX",
* "U1kTRgEAAC8A5ldS",
* ])
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param ids - A list of document IDs.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A list of documents with IDs matching the `ids` parameter.
*/
getAllByIDs<TDocument extends TDocuments>(ids: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
/**
* Queries a document from the Prismic repository with a specific UID and
* custom type.
*
* @remarks
* A document's UID is different from its ID. An ID is automatically generated
* for all documents and is made available on its `id` property. A UID is
* provided in the Prismic editor and is unique among all documents of its
* custom type.
*
* @example
*
* ```ts
* const document = await client.getByUID("blog_post", "my-first-post")
* ```
*
* @typeParam TDocument - Type of the Prismic document returned.
*
* @param documentType - The API ID of the document's custom type.
* @param uid - UID of the document.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns The document with a UID matching the `uid` parameter, if a
* matching document exists.
*/
getByUID<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uid: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
/**
* Queries document from the Prismic repository with specific UIDs and Custom
* Type.
*
* @remarks
* A document's UID is different from its ID. An ID is automatically generated
* for all documents and is made available on its `id` property. A UID is
* provided in the Prismic editor and is unique among all documents of its
* custom type.
*
* @example
*
* ```ts
* const document = await client.getByUIDs("blog_post", [
* "my-first-post",
* "my-second-post",
* ])
* ```
*
* @typeParam TDocument - Type of the Prismic document returned.
*
* @param documentType - The API ID of the document's custom type.
* @param uids - A list of document UIDs.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A paginated response containing documents with UIDs matching the
* `uids` parameter.
*/
getByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
/**
* Queries all documents from the Prismic repository with specific UIDs and
* custom type.
*
* This method may make multiple network requests to query all matching
* content.
*
* @remarks
* A document's UID is different from its ID. An ID is automatically generated
* for all documents and is made available on its `id` property. A UID is
* provided in the Prismic editor and is unique among all documents of its
* custom type.
*
* @example
*
* ```ts
* const response = await client.getAllByUIDs([
* "my-first-post",
* "my-second-post",
* ])
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param documentType - The API ID of the document's custom type.
* @param uids - A list of document UIDs.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A list of documents with UIDs matching the `uids` parameter.
*/
getAllByUIDs<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, uids: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
/**
* Queries a singleton document from the Prismic repository for a specific
* custom type.
*
* @remarks
* A singleton document is one that is configured in Prismic to only allow one
* instance. For example, a repository may be configured to contain just one
* Settings document. This is in contrast to a repeatable custom type which
* allows multiple instances of itself.
*
* @example
*
* ```ts
* const document = await client.getSingle("settings")
* ```
*
* @typeParam TDocument - Type of the Prismic document returned.
*
* @param documentType - The API ID of the singleton custom type.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns The singleton document for the custom type, if a matching document
* exists.
*/
getSingle<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>>;
/**
* Queries documents from the Prismic repository for a specific custom type.
*
* Use `getAllByType` instead if you need to query all documents for a
* specific custom type.
*
* @example
*
* ```ts
* const response = await client.getByType("blog_post")
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param documentType - The API ID of the custom type.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A paginated response containing documents of the custom type.
*/
getByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<ExtractDocumentType<TDocument, TDocumentType>>>;
/**
* Queries all documents from the Prismic repository for a specific Custom
* Type.
*
* This method may make multiple network requests to query all matching
* content.
*
* @example
*
* ```ts
* const response = await client.getByType("blog_post")
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param documentType - The API ID of the custom type.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A list of all documents of the custom type.
*/
getAllByType<TDocument extends TDocuments, TDocumentType extends TDocument["type"] = TDocument["type"]>(documentType: TDocumentType, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<ExtractDocumentType<TDocument, TDocumentType>[]>;
/**
* Queries documents from the Prismic repository with a specific tag.
*
* Use `getAllByTag` instead if you need to query all documents with a
* specific tag.
*
* @example
*
* ```ts
* const response = await client.getByTag("food")
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param tag - The tag that must be included on a document.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A paginated response containing documents with the tag.
*/
getByTag<TDocument extends TDocuments>(tag: string, params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
/**
* Queries all documents from the Prismic repository with a specific tag.
*
* This method may make multiple network requests to query all matching
* content.
*
* @example
*
* ```ts
* const response = await client.getAllByTag("food")
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param tag - The tag that must be included on a document.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A list of all documents with the tag.
*/
getAllByTag<TDocument extends TDocuments>(tag: string, params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
/**
* Queries documents from the Prismic repository with specific tags. A
* document must be tagged with all of the queried tags to be included.
*
* @example
*
* ```ts
* const response = await client.getByEveryTag(["food", "fruit"])
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param tags - A list of tags that must be included on a document.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A paginated response containing documents with the tags.
*/
getByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
/**
* Queries documents from the Prismic repository with specific tags. A
* document must be tagged with all of the queried tags to be included.
*
* This method may make multiple network requests to query all matching
* content.
*
* @example
*
* ```ts
* const response = await client.getAllByEveryTag(["food", "fruit"])
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param tags - A list of tags that must be included on a document.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A list of all documents with the tags.
*/
getAllByEveryTag<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
/**
* Queries documents from the Prismic repository with specific tags. A
* document must be tagged with at least one of the queried tags to be
* included.
*
* @example
*
* ```ts
* const response = await client.getByEveryTag(["food", "fruit"])
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param tags - A list of tags that must be included on a document.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A paginated response containing documents with at least one of the
* tags.
*/
getBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<BuildQueryURLArgs> & FetchParams): Promise<Query<TDocument>>;
/**
* Queries documents from the Prismic repository with specific tags. A
* document must be tagged with at least one of the queried tags to be
* included.
*
* This method may make multiple network requests to query all matching
* content.
*
* @example
*
* ```ts
* const response = await client.getAllBySomeTags(["food", "fruit"])
* ```
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param tags - A list of tags that must be included on a document.
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A list of all documents with at least one of the tags.
*/
getAllBySomeTags<TDocument extends TDocuments>(tags: string[], params?: Partial<Omit<BuildQueryURLArgs, "page">> & GetAllParams & FetchParams): Promise<TDocument[]>;
/**
* Returns metadata about the Prismic repository, such as its refs, releases,
* and custom types.
*
* @returns Repository metadata.
*/
getRepository(params?: FetchParams): Promise<Repository>;
/**
* Returns a list of all refs for the Prismic repository.
*
* Refs are used to identify which version of the repository's content should
* be queried. All repositories will have at least one ref pointing to the
* latest published content called the "master ref".
*
* @returns A list of all refs for the Prismic repository.
*/
getRefs(params?: FetchParams): Promise<Ref[]>;
/**
* Returns a ref for the Prismic repository with a matching ID.
*
* @param id - ID of the ref.
*
* @returns The ref with a matching ID, if it exists.
*/
getRefByID(id: string, params?: FetchParams): Promise<Ref>;
/**
* Returns a ref for the Prismic repository with a matching label.
*
* @param label - Label of the ref.
*
* @returns The ref with a matching label, if it exists.
*/
getRefByLabel(label: string, params?: FetchParams): Promise<Ref>;
/**
* Returns the master ref for the Prismic repository. The master ref points to
* the repository's latest published content.
*
* @returns The repository's master ref.
*/
getMasterRef(params?: FetchParams): Promise<Ref>;
/**
* Returns a list of all Releases for the Prismic repository. Releases are
* used to group content changes before publishing.
*
* @returns A list of all Releases for the Prismic repository.
*/
getReleases(params?: FetchParams): Promise<Ref[]>;
/**
* Returns a Release for the Prismic repository with a matching ID.
*
* @param id - ID of the Release.
*
* @returns The Release with a matching ID, if it exists.
*/
getReleaseByID(id: string, params?: FetchParams): Promise<Ref>;
/**
* Returns a Release for the Prismic repository with a matching label.
*
* @param label - Label of the ref.
*
* @returns The ref with a matching label, if it exists.
*/
getReleaseByLabel(label: string, params?: FetchParams): Promise<Ref>;
/**
* Returns a list of all tags used in the Prismic repository.
*
* @returns A list of all tags used in the repository.
*/
getTags(params?: FetchParams): Promise<string[]>;
/**
* Builds a URL used to query content from the Prismic repository.
*
* @param params - Parameters to filter, sort, and paginate the results.
*
* @returns A URL string that can be requested to query content.
*/
buildQueryURL({ signal, fetchOptions, ...params }?: Partial<BuildQueryURLArgs> & FetchParams): Promise<string>;
/**
* Determines the URL for a previewed document during an active preview
* session. The result of this method should be used to redirect the user to
* the document's URL.
*
* @example
*
* ```ts
* const url = client.resolvePreviewURL({
* linkResolver: (document) => `/${document.uid}`
* defaultURL: '/'
* })
* ```
*
* @param args - Arguments to configure the URL resolving.
*
* @returns The URL for the previewed document during an active preview
* session. The user should be redirected to this URL.
*/
resolvePreviewURL<LinkResolverReturnType>(args: ResolvePreviewArgs<LinkResolverReturnType> & FetchParams): Promise<string>;
/**
* Configures the client to query the latest published content for all future
* queries.
*
* If the `ref` parameter is provided during a query, it takes priority for
* that query.
*
* @example
*
* ```ts
* await client.queryLatestContent()
* const document = await client.getByID("WW4bKScAAMAqmluX")
* ```
*/
queryLatestContent(): void;
/**
* Configures the client to query content from a specific Release identified
* by its ID for all future queries.
*
* If the `ref` parameter is provided during a query, it takes priority for
* that query.
*
* @example
*
* ```ts
* await client.queryContentFromReleaseByID("YLB7OBAAACMA7Cpa")
* const document = await client.getByID("WW4bKScAAMAqmluX")
* ```
*
* @param releaseID - The ID of the Release.
*/
queryContentFromReleaseByID(releaseID: string): void;
/**
* Configures the client to query content from a specific Release identified
* by its label for all future queries.
*
* If the `ref` parameter is provided during a query, it takes priority for
* that query.
*
* @example
*
* ```ts
* await client.queryContentFromReleaseByLabel("My Release")
* const document = await client.getByID("WW4bKScAAMAqmluX")
* ```
*
* @param releaseLabel - The label of the Release.
*/
queryContentFromReleaseByLabel(releaseLabel: string): void;
/**
* Configures the client to query content from a specific ref. The ref can be
* provided as a string or a function.
*
* If a function is provided, the ref is fetched lazily before each query. The
* function may also be asynchronous.
*
* @example
*
* ```ts
* await client.queryContentFromRef("my-ref")
* const document = await client.getByID("WW4bKScAAMAqmluX")
* ```
*
* @param ref - The ref or a function that returns the ref from which to query
* content.
*/
queryContentFromRef(ref: RefStringOrThunk): void;
/**
* A `fetch()` function to be used with GraphQL clients configured for
* Prismic's GraphQL API. It automatically applies the necessary `prismic-ref`
* and Authorization headers. Queries will automatically be minified by
* removing whitespace where possible.
*
* @example
*
* ```ts
* const graphQLClient = new ApolloClient({
* link: new HttpLink({
* uri: prismic.getGraphQLEndpoint(repositoryName),
* // Provide `client.graphQLFetch` as the fetch implementation.
* fetch: client.graphQLFetch,
* // Using GET is required.
* useGETForQueries: true,
* }),
* cache: new InMemoryCache(),
* })
* ```
*
* @param input - The `fetch()` `input` parameter. Only strings are supported.
* @param init - The `fetch()` `init` parameter. Only plain objects are
* supported.
*
* @returns The `fetch()` Response for the request.
*
* @experimental
*/
graphQLFetch(input: RequestInfo, init?: Omit<RequestInit, "signal"> & {
signal?: AbortSignalLike;
}): Promise<Response>;
/**
* Returns a cached version of `getRepository` with a TTL.
*
* @returns Cached repository metadata.
*/
private getCachedRepository;
/**
* Returns a cached Prismic repository form. Forms are used to determine API
* endpoints for types of repository data.
*
* @param name - Name of the form.
*
* @returns The repository form.
*
* @throws If a matching form cannot be found.
*/
private getCachedRepositoryForm;
/**
* Returns the ref needed to query based on the client's current state. This
* method may make a network request to fetch a ref or resolve the user's ref
* thunk.
*
* If auto previews are enabled, the preview ref takes priority if available.
*
* The following strategies are used depending on the client's state:
*
* - If the user called `queryLatestContent`: Use the repository's master ref.
* The ref is cached for 5 seconds. After 5 seconds, a new master ref is
* fetched.
* - If the user called `queryContentFromReleaseByID`: Use the release's ref.
* The ref is cached for 5 seconds. After 5 seconds, a new ref for the
* release is fetched.
* - If the user called `queryContentFromReleaseByLabel`: Use the release's ref.
* The ref is cached for 5 seconds. After 5 seconds, a new ref for the
* release is fetched.
* - If the user called `queryContentFromRef`: Use the provided ref. Fall back
* to the master ref if the ref is not a string.
*
* @returns The ref to use during a query.
*/
private getResolvedRefString;
/**
* The private implementation of `this.get`. It returns the API response and
* the URL used to make the request. The URL is sometimes used in the public
* method to include in thrown errors.
*
* This method retries requests that throw `RefNotFoundError` or
* `RefExpiredError`. It contains special logic to retry with the latest
* master ref, provided in the API's error message.
*
* @typeParam TDocument - Type of Prismic documents returned.
*
* @param params - Parameters to filter, sort, and paginate results.
*
* @returns An object containing the paginated response containing the result
* of the query and the URL used to make the API request.
*/
private _get;
/**
* Performs a network request using the configured `fetch` function. It
* assumes all successful responses will have a JSON content type. It also
* normalizes unsuccessful network requests.
*
* @typeParam T - The JSON response.
*
* @param url - URL to the resource to fetch.
* @param params - Prismic REST API parameters for the network request.
*
* @returns The JSON response from the network request.
*/
protected fetch<T = unknown>(url: string, params?: FetchParams): Promise<T>;
}
export {};