import { type TelemetryOptions } from '../telemetry/settings.js'; import { type GraphAuth, type GraphGetContentOptions, type GraphGetItemOptions, type GraphGetLinksOptions, type GraphGetPreviewOptions, type GraphOptions, type GraphReference, type GraphSecrets, type GraphSlot, type PreviewParams, type ResolvedFragmentOptions, type ResolvedQueryOptions } from './options.js'; import { type PlatformAdapter } from './platform.js'; export { GraphVariationInput } from './filters.js'; export { GraphGetContentOptions, GraphGetItemOptions, GraphGetLinksOptions, GraphGetPreviewOptions, GraphOptions, GraphQueryOptions, GraphReference, GraphSlot, PreviewParams, } from './options.js'; export type { DamMode, GraphActingUser, GraphAuth, GraphAuthContext, GraphAuthHeaders, GraphAuthMode, GraphAuthResolver, GraphFragmentOptions, GraphPlatform, GraphSecrets, TaxonomyTerm, TaxonomyMode, } from './options.js'; export declare class GraphClient { apiKey: string; graphUrl: string; userAgent: string; /** Which credential each request carries. Unset means the single key is used. */ readonly auth?: GraphAuth; /** The app key and secret the `hmac` mode signs with. */ readonly secrets?: GraphSecrets; /** * Every setting the query builders read that comes from configuration, * assembled once so a call site cannot forget one. */ readonly fragmentDefaults: ResolvedFragmentOptions; /** The resolved `query` group: what every request uses unless it overrides it. */ readonly queryDefaults: ResolvedQueryOptions; /** How requests are built and responses read for the configured CMS product. */ readonly platform: PlatformAdapter; constructor(apiKey: string, options?: Omit); /** Perform a GraphQL query with variables */ request(query: string, variables: any, previewToken?: string, cache?: boolean, slot?: GraphSlot, stored?: boolean): Promise; /** * 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; getPreviewContent(params: PreviewParams, options?: GraphGetPreviewOptions): Promise; /** * Unified content fetching method using GraphReference. * Fetches content by key with optional locale and version parameters. * * Supports both object and string formats: * - Object: `{ key: '880777d5a2824399b07e93e3ca70668e', locale: 'en', version: '123' }` * - String: `graph://source/type/key?loc=en&ver=123` * * **Priority rules:** * - If `version` is specified, it takes priority (ignores locale-based filtering) * - If only `locale` is specified, fetches latest published version in that locale * - If neither specified, fetches latest published version * * **Note:** This method always returns published content. To fetch draft content, * use `getPreviewContent()` with a preview token instead. * @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: '880777d5a2824399b07e93e3ca70668e' }); * * // Fetch latest published content in specific locale * const content = await client.getContent({ key: '880777d5a2824399b07e93e3ca70668e', locale: 'en' }); * * // Fetch specific version (version has priority over locale) * const content = await client.getContent({ * key: '880777d5a2824399b07e93e3ca70668e', * version: '123', * locale: 'en' // This will be ignored when version is specified * }); * * // Using string format * const content = await client.getContent('graph://cms/Page/880777d5a2824399b07e93e3ca70668e?loc=en&ver=123'); * * // With preview token * const content = await client.getContent({ key: '880777d5a2824399b07e93e3ca70668e', version: '123' }, { previewToken: 'token' }); * ``` */ getContent(reference: string | GraphReference, options?: GraphGetItemOptions): 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: '880777d5a2824399b07e93e3ca70668e', locale: 'en' }` * - String format: `graph://cms/Page/880777d5a2824399b07e93e3ca70668e?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: '880777d5a2824399b07e93e3ca70668e', locale: 'en' }); * * // Using string format * const path = await client.getPath('graph://Page/880777d5a2824399b07e93e3ca70668e?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: '880777d5a2824399b07e93e3ca70668e', locale: 'en' }` * - String format: `graph://Page/880777d5a2824399b07e93e3ca70668e?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: '880777d5a2824399b07e93e3ca70668e', locale: 'en' }); * * // Using string format * const items = await client.getItems('graph://Page/880777d5a2824399b07e93e3ca70668e?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>; } /** * 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 * fragment: { richTextFormat: 'json' }, // optional * query: { cache: true, host: 'example.com' }, // optional * telemetry: { componentMetrics: false }, // optional * }); * * export default function RootLayout({ children }) { * return {children}; * } * ``` */ export declare function config({ telemetry, ...options }: GraphOptions & { telemetry?: TelemetryOptions; }): 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 * query: { 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({ query: { host: 'custom.example.com' } }); * const jsonOnly = getClient({ fragment: { richTextFormat: 'json' } }); * ``` */ export declare function getClient(overrideOptions?: Partial): GraphClient;