@jss-rule-engine/edge
Version:
94 lines (93 loc) • 3.02 kB
TypeScript
import { GraphQLClient } from '@sitecore-jss/sitecore-jss/graphql';
import { CacheClient, CacheOptions } from './cache-client';
export type GraphQLPersonalizeServiceConfig = CacheOptions & {
/**
* Your Graphql endpoint
*/
endpoint: string;
/**
* The API key to use for authentication
*/
apiKey: string;
/**
* Timeout (ms) for the Personalize request. Default is 400.
*/
timeout?: number;
/**
* Optional Sitecore Personalize scope identifier allowing you to isolate your personalization data between XM Cloud environments
*/
scope?: string;
/**
* Override fetch method. Uses 'GraphQLRequestClient' default otherwise.
*/
fetch?: typeof fetch;
};
/**
* Object model of personlize info
*/
export type PersonalizeInfo = {
/**
* The (CDP-friendly) content id
*/
contentId: string;
/**
* The configured variant ids
*/
variantIds: string[];
activeVariantid: string;
};
export type PersonalizeContext = {
url: string;
hostname: string | null;
};
type PersonalizeQueryResult = {
layout: {
item: {
id: string;
version: string;
personalizationRule: {
value: string;
};
personalizeOnEdge: {
value: string;
};
};
};
};
export declare class GraphQLSCPersonalizeService {
protected config: GraphQLPersonalizeServiceConfig;
private graphQLClient;
private cache;
private personalizeContext?;
protected get query(): string;
/**
* Fetch personalize data using the Sitecore GraphQL endpoint.
* @param {GraphQLPersonalizeServiceConfig} config
*/
constructor(config: GraphQLPersonalizeServiceConfig);
setPersonalizeContext(context: PersonalizeContext): void;
/**
* Get personalize information for a route
* @param {string} itemPath page route
* @param {string} language language
* @param {string} siteName site name
* @returns {Promise<PersonalizeInfo | undefined>} the personalize information or undefined (if itemPath / language not found)
*/
getPersonalizeInfo(itemPath: string, language: string, siteName: string): Promise<PersonalizeInfo | undefined>;
protected getActiveVariantId(ruleExecutionResults: any): any;
/**
* Gets cache client implementation
* Override this method if custom cache needs to be used
* @returns CacheClient instance
*/
protected getCacheClient(): CacheClient<PersonalizeQueryResult>;
protected getCacheKey(itemPath: string, language: string, siteName: string): string;
/**
* 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;
}
export {};