import 'server-only'; import type { Metadata, ResolvingMetadata } from 'next'; import { type IRouteResolver, type Route } from '@remkoj/optimizely-graph-client/router'; import { type ChannelDefinition } from '@remkoj/optimizely-graph-client/channels'; import { type IOptiGraphClient } from '@remkoj/optimizely-graph-client/client'; import { type ComponentFactory } from '@remkoj/optimizely-cms-react/rsc'; import { type GetContentByPathMethod } from './data.js'; import { SystemLocales } from './_base.js'; export { SystemLocales } from './_base.js'; export type DefaultCmsPageParams = { path?: string[]; }; export type DefaultCmsPageSearchParams = {}; export type DefaultCmsPageProps | undefined> = DefaultCmsPageParams, TSearchParams extends Record | undefined> = DefaultCmsPageSearchParams> = { params: TParams; searchParams: TSearchParams; }; export type OptiCmsNextJsPage | undefined> = DefaultCmsPageParams, TSearchParams extends Record | undefined> = DefaultCmsPageSearchParams> = { /** * Default implementation for the `generateStaticParams` export of a * Next.JS Page. * * @returns The list of routes that should be pre-rendered by Next.JS */ generateStaticParams: () => Promise; /** * Default implementation for the `generateMetadata` export, which builds * the metadata for the given route within the Next.JS app. * * @param props The properties of the page * @param resolving The metadata that is currently resolving * @returns Updated metadat */ generateMetadata: (props: DefaultCmsPageProps, resolving: ResolvingMetadata) => Promise; /** * The actual component that performs the page rendering * * @param props The properties of the page * @returns The component to render the page */ CmsPage: (props: DefaultCmsPageProps) => Promise; }; export type CreatePageOptions | undefined> = DefaultCmsPageParams, TSearchParams extends Record | undefined> = DefaultCmsPageSearchParams> = { /** * Main function used to retrieve the content by path */ getContentByPath?: GetContentByPathMethod; /** * The factory that should yield the GraphQL Client to be used within this * page. * * @param token The token retrieved by the CMS Page from the context, always undefined * @param scope The scope in which the client is being created, this allows for checking * draftMode in configuring the client * @returns The client instance */ client: (token?: string, scope?: 'request' | 'metadata') => IOptiGraphClient; /** * The channel information used to resolve locales, domains and more. * * If provided with a string value, this is assumed to be the Application/Website identifier * for the deployment (Base URL ***without trailing slash*** for SaaS CMS; Website GUID for * CMS 12). */ channel?: ChannelDefinition | string; /** * Override the default RouteResolver that is used to discover the routes * provided by the Optimizely CMS and to retrieve the content reference for * each route. * * @param client The Optimizely GraphQL Client to use * @returns The RouteResolver to use */ routerFactory: (client?: IOptiGraphClient) => IRouteResolver; /** * Take the props received by the CmsPage from Next.JS and tranform those * into a path that will be understood by Optimizely CMS. The default * implementation works with both `/[lang]/[[...path]]` as well as * `/[[...path]]` * * @param props The Properties (slugs & search params) received * by Next.JS * @return The path to be retrieved from Router or getContentByPath * function */ propsToCmsPath: (props: DefaultCmsPageProps) => string | null; /** * Take the route from the Routing Service and transform that to the route * params used by Next.JS. The default implementation assumes that the CMS * routes will be handled by `/[[...path]]` * * @param route The Route retrieved from Optimizely Graph * @returns The processed route */ routeToParams: (route: Route) => TParams; /** * Takes the Next.JS route segments and try to transform it into an initial * locale code, the default implementation will try to resolve the `lang` * route segment using the channel definition. * * @param slugs The slugs to resolve * @returns The resolved locale */ paramsToLocale: (params?: TParams, channel?: ChannelDefinition) => string | undefined; }; /** * Generate the React Server Side component and Next.JS functions needed to render an * Optimizely CMS page. This component assumes that the routes are either defined as * /[lang]/[[...path]] or /[[...path]] * * @param factory The component factory to use for this page * @param options The page component generation options * @returns The Optimizely CMS Page */ export declare function createPage | undefined> = DefaultCmsPageParams, TSearchParams extends Record | undefined> = DefaultCmsPageSearchParams>(factory: ComponentFactory, options?: Partial>): OptiCmsNextJsPage;