UNPKG

@jss-rule-engine/nextjs

Version:

157 lines (156 loc) 5.83 kB
import { GraphQLClient, PageInfo } from '@sitecore-jss/sitecore-jss/graphql'; /** @private */ export declare const languageError = "The list of languages cannot be empty"; export declare const siteError = "The service needs a site name"; /** * @param {string} siteName to inject into error text * @private */ export declare function getSiteEmptyError(siteName: string): string; /** * type for input variables for the site routes query */ interface SiteRouteQueryVariables { /** * Required. The name of the site being queried. */ siteName: string; /** * Required. The language to return routes/pages for. */ language: string; /** * Optional. Only paths starting with these provided prefixes will be returned. */ includedPaths?: string[]; /** * Optional. Paths starting with these provided prefixes will be excluded from returned results. */ excludedPaths?: string[]; /** common variable for all GraphQL queries * it will be used for every type of query to regulate result batch size * Optional. How many result items to fetch in each GraphQL call. This is needed for pagination. * @default 100 */ pageSize?: number; } /** * Schema of data returned in response to a "site" query request * @template T The type of objects being requested. */ export interface SiteRouteQueryResult<T> { site: { siteInfo: { routes: { /** * Data needed to paginate the site results */ pageInfo: PageInfo; results: T[]; }; }; }; } /** * The schema of data returned in response to a routes list query request */ export type RouteListQueryResult = { path: string; route?: { personalizationRule: { value: string; }; personalizeOnEdge: { value: string; }; isStaticRender: { value: string; }; }; }; /** * Configuration options for @see GraphQLSitemapService instances */ export interface BaseGraphQLSitemapServiceConfig extends Omit<SiteRouteQueryVariables, 'language' | 'siteName'> { /** * Your Graphql endpoint */ endpoint: string; /** * The API key to use for authentication. */ apiKey: string; /** * A flag for whether to include personalized routes in service output - only works on XM Cloud * turned off by default */ includePersonalizedRoutes?: boolean; } /** * Object model of a site page item. */ export type StaticPath = { params: { path: string[]; isStaticRender: boolean; }; locale?: string; }; /** * Service that fetches the list of site pages using Sitecore's GraphQL API. * Used to handle a single site * This list is used for SSG and Export functionality. * @mixes SearchQueryService<PageListQueryResult> */ export declare abstract class BasePersonalizeGraphQLSitemapService { options: BaseGraphQLSitemapServiceConfig; private _graphQLClient; /** * GraphQL client accessible by descendant classes when needed */ protected get graphQLClient(): GraphQLClient; /** * Gets the default query used for fetching the list of site pages */ protected get query(): string; /** * Creates an instance of graphQL sitemap service with the provided options * @param {GraphQLSitemapServiceConfig} options instance */ constructor(options: BaseGraphQLSitemapServiceConfig); /** * Fetch sitemap which could be used for generation of static pages during `next export`. * The `locale` parameter will be used in the item query, but since i18n is not supported, * the output paths will not include a `language` property. * @param {string} locale which application supports * @returns an array of @see StaticPath objects */ fetchExportSitemap(locale: string): Promise<StaticPath[]>; /** * Fetch sitemap which could be used for generation of static pages using SSG mode * @param {string[]} locales locales which application supports * @returns an array of @see StaticPath objects */ fetchSSGSitemap(locales: string[]): Promise<StaticPath[]>; protected getTranformedPaths(siteName: string, languages: string[], formatStaticPath: (path: string[], language: string, isStaticRender: boolean) => StaticPath): Promise<StaticPath[]>; protected transformLanguageSitePaths(sitePaths: RouteListQueryResult[], formatStaticPath: (path: string[], language: string, isStaticRender: boolean) => StaticPath, language: string): Promise<StaticPath[]>; protected fetchLanguageSitePaths(language: string, siteName: string): Promise<RouteListQueryResult[]>; /** * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you * want to use something else. * @returns {GraphQLClient} implementation */ protected getGraphQLClient(): GraphQLClient; /** * Fetch a flat list of all pages that belong to the specificed site and have a * version in the specified language(s). * @param {string[]} languages Fetch pages that have versions in this language(s). * @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types. * @returns list of pages * @throws {RangeError} if the list of languages is empty. * @throws {RangeError} if the any of the languages is an empty string. */ protected abstract fetchSitemap(languages: string[], formatStaticPath: (path: string[], language: string, isStaticRender: boolean) => StaticPath): Promise<StaticPath[]>; } export {};