import { GraphVariationInput } from './filters.js'; /** Configuration for initializing the Optimizely Graph Client */ export type GraphOptions = { /** Your Optimizely Graph API key (Single key in CMS) */ apiKey: string; /** Optional custom Graph URL (defaults to production: https://cg.optimizely.com/content/v2) */ graphUrl?: string; /** Optional default host for path filtering */ host?: string; /** Default maximum fragment threshold for GraphQL queries (default: 100) */ maxFragmentThreshold?: number; /** * Enable or disable server-side caching for all queries. * Can be overridden per request. * @default true */ cache?: boolean; /** * Select which Graph index to query against for all requests. * During a smooth rebuild, two indexes exist: the current (active) one and the new one being built. * - `'Current'`: Query the current active index (default) * - `'New'`: Query the new index that is being rebuilt * Can be overridden per request. */ slot?: GraphSlot; }; export type PreviewParams = { preview_token: string; key: string; ctx: string; ver: string; loc: string; }; export type GraphReference = { /** Content key/GUID (required) */ key: string; /** Content locale/language (optional) */ locale?: string; /** Content version for preview mode (optional) */ version?: string; /** Content type name (optional) */ type?: string; /** Source identifier - unused for now (optional) */ source?: string; }; /** Slot values for selecting the Graph engine version */ export type GraphSlot = 'Current' | 'New'; /** Query options shared by all query methods */ export type GraphQueryOptions = { /** * Enable or disable server-side caching for this request. * Overrides the global `cache` setting in `GraphOptions`. */ cache?: boolean; /** * Select which Graph index to query against. * During a smooth rebuild, two indexes exist: the current (active) one and the new one being built. * - `'Current'`: Query the current active index (default) * - `'New'`: Query the new index that is being rebuilt * Overrides the global `slot` setting in `GraphOptions`. */ slot?: GraphSlot; }; export type GraphGetContentOptions = GraphQueryOptions & { variation?: GraphVariationInput; host?: string; }; export type GraphGetLinksOptions = GraphQueryOptions & { host?: string; locales?: string[]; }; export type GraphGetItemOptions = GraphQueryOptions & { previewToken?: string; }; export { GraphVariationInput }; /** * Removes GraphQL alias prefixes from object keys in the response data. * * For objects with a `__typename` property, removes the `{typename}__` prefix * from all field names (e.g., `ContentType__p1` becomes `p1`). * This reverses the aliasing applied in query generation to prevent field * name collisions in GraphQL fragments. * * Traverses all keys in an object recursively, processing arrays and nested objects. * * @param obj - The object to process (typically a GraphQL response) * @returns A new object with prefixes removed, or the original value for primitives * * Note: this function is exported only on this level for testing purposes. * It should not be exported in the user-facing API */ export declare function removeTypePrefix(obj: any): any; export declare class GraphClient { apiKey: string; graphUrl: string; maxFragmentThreshold: number; host?: string; cache: boolean; slot?: GraphSlot; constructor(apiKey: string, options?: Omit); /** Perform a GraphQL query with variables */ request(query: string, variables: any, previewToken?: string, cache?: boolean, slot?: GraphSlot): Promise; /** * Fetches the content type metadata for a given content input. * * @param input - The content input used to query the content type. * @param previewToken - Optional preview token for fetching preview content. * @returns A promise that resolves to the first content type metadata object */ private getContentMetaData; /** * Fetches content from the CMS based on the provided path or options. * * If a string is provided, it is treated as a content path. If an object is provided, * it may include both a path and a variation to filter the content. * * @param path - A string representing the content path * @param options - Options to include or exclude variations * * @param contentType - A string representing the content type. If omitted, the method * will try to get the content type name from the CMS. * * @returns An array of all items matching the path and options. Returns an empty array if no content is found. */ getContentByPath(path: string, options?: GraphGetContentOptions): Promise; /** * Given the path or reference of a page, return its "path" (i.e. a list of ancestor pages). * * Supports both URL path (string) and GraphReference formats: * - String: URL path like `/blog/post-1` * - GraphReference: Object like `{ key: 'abc123', locale: 'en' }` * - String format: `graph://cms/Page/abc123?loc=en` * * @param input - URL path string or GraphReference object/string * @param options - Optional host and locales filters * @returns A list with the metadata information of all ancestors sorted from top-most to current * * @example * ```typescript * // Using path * const path = await client.getPath('/blog/post-1'); * * // Using GraphReference * const path = await client.getPath({ key: 'abc123', locale: 'en' }); * * // Using string format * const path = await client.getPath('graph://Page/abc123?loc=en'); * ``` */ getPath(reference: string | GraphReference, options?: GraphGetLinksOptions): Promise<{ _metadata?: { key: string; sortOrder?: number; displayName?: string; locale?: string; types: string[]; url?: { base?: string; hierarchical?: string; default?: string; }; }; }[] | null>; /** * Given the path or reference of a page, get its "items" (i.e. the children pages) * * Supports both URL path (string) and GraphReference formats: * - String: URL path like `/blog` * - GraphReference: Object like `{ key: 'abc123', locale: 'en' }` * - String format: `graph://Page/abc123?loc=en` * * @param input - URL path string or GraphReference object/string * @param options - Optional host and locales filters * @returns A list with the metadata information of all child/descendant pages * * @example * ```typescript * // Using path * const items = await client.getItems('/blog'); * * // Using GraphReference * const items = await client.getItems({ key: 'abc123', locale: 'en' }); * * // Using string format * const items = await client.getItems('graph://Page/abc123?loc=en'); * ``` */ getItems(reference: string | GraphReference, options?: GraphGetLinksOptions): Promise<{ _metadata?: { key: string; sortOrder?: number; displayName?: string; locale?: string; types: string[]; url?: { base?: string; hierarchical?: string; default?: string; }; }; }[] | null>; /** Fetches a content given the preview parameters (preview_token, ctx, ver, loc, key) */ getPreviewContent(params: PreviewParams, options?: GraphQueryOptions): Promise; /** * Parse GraphReference from string format. * Supports format: `graph://source/type/key?loc=locale&ver=version` * * @param referenceString - String in graph:// format * @returns Parsed GraphReference object * * @example * ```typescript * parseGraphReference('graph://cms/Page/abc123?loc=en&ver=1.0') * // Returns: { source: 'cms', type: 'Page', key: 'abc123', locale: 'en', version: '1.0' } * ``` */ private parseGraphReference; /** * Unified content fetching method using GraphReference. * Fetches content by key with optional locale and version parameters. * * Supports both object and string formats: * - Object: `{ key: 'abc123', locale: 'en', version: '1.0' }` * - String: `graph://source/type/key?loc=en&ver=1.0` * * **Priority rules:** * - If `version` is specified, it takes priority (ignores locale-based filtering) * - If only `locale` is specified, fetches latest draft in that locale * - If neither specified, fetches latest published version * * @param reference - GraphReference object or string in graph:// format * @param previewToken - Optional preview token for preview mode * @returns The requested content item, or null if not found * * @example * ```typescript * // Fetch latest published content by key * const content = await client.getContent({ key: 'abc123' }); * * // Fetch latest draft in specific locale * const content = await client.getContent({ key: 'abc123', locale: 'en' }); * * // Fetch specific version (version has priority over locale) * const content = await client.getContent({ * key: 'abc123', * version: '1.0', * locale: 'en' // This will be ignored when version is specified * }); * * // Using string format * const content = await client.getContent('graph://cms/Page/abc123?loc=en&ver=1.0'); * * // With preview token * const content = await client.getContent({ key: 'abc123', version: '1.0' }, { previewToken: 'token' }); * ``` */ getContent(reference: string | GraphReference, options?: GraphGetItemOptions): Promise; } /** * Gets the global graph configuration * @internal */ export declare function getGraphConfig(): GraphOptions | null; /** * Configure the Optimizely Graph client with your settings. * * Call this function once at the start of your application. * After configuration, you can use getClient() anywhere in your app. * * @param config - The graph configuration object with your API key and optional settings * * @example * ```tsx * // In your root layout or app entry point * import { config } from '@optimizely/cms-sdk'; * * config({ * apiKey: process.env.OPTIMIZELY_GRAPH_SINGLE_KEY!, * graphUrl: process.env.OPTIMIZELY_GRAPH_GATEWAY, // optional * host: 'example.com', // optional * }); * * export default function RootLayout({ children }) { * return {children}; * } * ``` */ export declare function config(options: GraphOptions): void; /** * Creates and returns a GraphClient instance using the global configuration. * * The graph configuration must be set first using config(). * * @param overrideOptions - Optional GraphOptions to override the global configuration * @returns A configured GraphClient instance * @throws Error if graph configuration is not set * * @example * ```ts * // In your root layout (e.g., layout.tsx) * import { config } from '@optimizely/cms-sdk'; * * config({ * apiKey: process.env.OPTIMIZELY_GRAPH_SINGLE_KEY!, * graphUrl: process.env.OPTIMIZELY_GRAPH_GATEWAY, // optional * host: 'example.com', // optional * }); * * // In your components * import { getClient } from '@optimizely/cms-sdk'; * * const client = getClient(); * const content = await client.getContentByPath('/my-page/'); * * // Or override config for specific use cases * const customClient = getClient({ host: 'custom.example.com' }); * ``` */ export declare function getClient(overrideOptions?: Partial): GraphClient;