///
import { IncomingMessage, ServerResponse } from 'http';
import { Header, HttpMethod, IExternalEventSource, IExternalRequester, IExternalStorage, IExternalLogger, SDKConfigurationType } from '@kameleoon/javascript-sdk-core';
export type RequesterParametersType = {
credentials: CredentialsType;
timeout: number;
};
export type HeadersType = Partial>;
/**
* @param {HttpMethod} method - http method, ex: GET, POST
* @param {HeadersType | undefined} headers - http headers
* @param {string | undefined} body - http body
* */
export type RequestParametersType = {
method: HttpMethod;
headers?: HeadersType;
body?: string;
};
/**
* @param {string} clientId - id of client API credentials
* @param {string} clientSecret - secret of client API credentials
* */
export type CredentialsType = {
clientId: string;
clientSecret: string;
};
/**
* @param {IExternalStorage | undefined} storage - external storage implementation
* @param {IExternalEventSource} eventSource - external event source implementation
* @param {IExternalRequester} requester - external requester implementation
* @param {IExternalVisitorCodeManager | IExternalNextJSVisitorCodeManager | IExternalNextJSVisitorCodeManager | IExternalCustomVisitorCodeManager} visitorCodeManager - external visitor code manager implementation
* @param {IExternalLogger | undefined} logger - external logger implementation
* */
export type ExternalsType = {
storage?: IExternalStorage;
requester: IExternalRequester;
eventSource: IExternalEventSource;
visitorCodeManager: IExternalVisitorCodeManager | IExternalDenoVisitorCodeManager | IExternalNextJSVisitorCodeManager | IExternalCustomVisitorCodeManager;
logger?: IExternalLogger;
};
/**
* @readonly
* @enum {string} an Enum containing all possible variants of compatibility modes
*
* @property `Node16` - Node.js 16.x.x _default_ - All SDK features are available in this compatibility mode
* @property `Node14` - Node.js 14.x.x - Compatibility with this version will make `requestTimeout` parameter in `SDKConfigurationType` unavailable and prevent the SDK from using `AbortController` for request cancellation even within default 10_000 ms timeout
* @property `Node12` - Node.js 12.x.x - Compatibility with this version implies the same limitations as for `Node14` compatibility mode, moreover, it will not allow to provide "@kameleoon/nodejs-requester" as a requester implementation as it uses "node-fetch" library not supporting Node.js 12.x.x version. In that case a developer must provide a custom requester implementation of their own choice, such as older "node-fetch" version or other HTTP based implementation
*
* */
export declare enum Compatibility {
Node16 = 0,
Node14 = 1,
Node12 = 2
}
/**
* @param {string} siteCode - client's siteCode defined on Kameleoon platform
* @param {CredentialsType} credentials - client API credentials to get an access token for requests' Authorization header, such requests are handled with higher request rate limit
* @param {Partial | undefined} configuration - client's configuration
* @param {ExternalsType} externals - external dependencies
* */
export type SDKParameters = {
siteCode: string;
credentials: CredentialsType;
configuration?: Partial;
compatibility?: Compatibility;
externals: ExternalsType;
};
/**
* @param {Request} request - request object to get the cookie from
* @param {Response} response - response object to write the updated cookie to
* @param {string | undefined} defaultVisitorCode - visitor code to be used in case there is no visitor code in cookies *Note*: if not passed visitor code will be randomly generated
* */
export type GetVisitorCodeParametersType = {
request: IncomingMessage;
response: ServerResponse;
defaultVisitorCode?: string;
};
/**
* @param {DenoMessage} request - request object to get the cookie from
* @param {DenoMessage} response - response object to write the updated cookie to
* @param {string | undefined} defaultVisitorCode - visitor code to be used in case there is no visitor code in cookies *Note*: if not passed visitor code will be randomly generated
* */
export type GetDenoVisitorCodeParametersType = {
request: DenoMessage;
response: DenoMessage;
defaultVisitorCode?: string;
};
/**
* @param {typeof cookies} cookies - a function representing cookies in Next.js server-side context, to handle cookie read/write operations
* @param {string | undefined} defaultVisitorCode - visitor code to be used in case there is no visitor code in cookies *Note*: if not passed visitor code will be randomly generated
* */
export type CookieParameters = {
path: string;
domain?: string;
maxAge: number;
};
/**
* @param {string} value - cookie value
* */
export type Cookies = {
value: string;
};
/**
* @type `RequestCookie` mimic NextJS cookies object type can be safely cast to native NextJS `typeof cookies`
* @param {(key: string) => string | undefined} get - function to get cookie value by key
* @param {(key: string, value: string, parameters: CookieParameters) => void} set - function to set cookie value by key
* */
export type RequestCookie = {
get: (key: string) => Cookies | undefined;
set: (key: string, value: string, parameters: CookieParameters) => void;
};
/**
* @param {() => RequestCookie} cookies - a function representing cookies in Next.js server-side context, to handle cookie read/write operations
* @param {string | undefined} defaultVisitorCode - visitor code to be used in case there is no visitor code in cookies *Note*: if not passed visitor code will be randomly generated
* */
export type GetNextJSVisitorCodeParametersType = {
cookies: () => RequestCookie;
defaultVisitorCode?: string;
};
/**
* @param {unknown} input - input parameters for processing visitor code
* @param {unknown} output - output parameters for processing visitor code
* @param {string | undefined} defaultVisitorCode - visitor code to be used in case there is no visitor code in cookies *Note*: if not passed visitor code will be randomly generated
* */
export type GetCustomVisitorCodeParametersType = {
input: unknown;
output: unknown;
defaultVisitorCode?: string;
};
/**
* @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters
* @param {ServerResponse | undefined} response - response object to write the updated cookie to
* @param {boolean} consent - a value representing the legal consent status. - 'true' indicates the
* visitor has given legal consent. - 'false' indicates the visitor has withdrawn or not
* provided legal consent.
* */
export type SetLegalConsentParametersType = {
visitorCode: string;
consent: boolean;
response: ServerResponse;
};
/**
* @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters
* @param {DenoMessage} response - response object to write the updated cookie to
* @param {boolean} consent - a value representing the legal consent status. - 'true' indicates the
* visitor has given legal consent. - 'false' indicates the visitor has withdrawn or not
* provided legal consent.
* */
export type SetDenoLegalConsentParametersType = {
visitorCode: string;
consent: boolean;
response: DenoMessage;
};
/**
* @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters
* @param {unknown} output - output parameters for processing visitor code
* @param {boolean} consent - a value representing the legal consent status. - 'true' indicates the
* visitor has given legal consent. - 'false' indicates the visitor has withdrawn or not
* provided legal consent.
* */
export type SetCustomLegalConsentParametersType = {
visitorCode: string;
consent: boolean;
output: unknown;
};
/**
* @param {string} visitorCode - unique visitor identifier, shouldn't exceed 255 characters
* @param {() => RequestCookie} cookies - a function representing cookies in Next.js server-side context, to handle cookie read/write operations
* @param {boolean} consent - a value representing the legal consent status. - 'true' indicates the
* visitor has given legal consent. - 'false' indicates the visitor has withdrawn or not
* provided legal consent.
* */
export type SetNextJSLegalConsentParametersType = {
visitorCode: string;
consent: boolean;
cookies: () => RequestCookie;
};
/**
* @type `DenoMessage` type representing Deno request/response object
* @param {Map} headers - value representing headers in Deno request/response object
* */
export type DenoMessage = {
headers: Map;
};
export type GetDataRequiredParametersType = {
key: string;
};
export type GetDataParametersType = {
request: IncomingMessage;
} & GetDataRequiredParametersType;
export type GetDenoDataParametersType = {
request: DenoMessage;
} & GetDataRequiredParametersType;
export type GetNextJSDataParametersType = {
cookies: () => RequestCookie;
} & GetDataRequiredParametersType;
export type GetDataCustomParametersType = {
input: unknown;
} & GetDataRequiredParametersType;
export type SetDataRequiredParametersType = {
visitorCode: string;
key: string;
domain?: string;
maxAge: number;
path: string;
};
export type SetDataParametersType = {
response: ServerResponse;
} & SetDataRequiredParametersType;
export type SetDenoDataParametersType = {
response: DenoMessage;
} & SetDataRequiredParametersType;
export type SetNextJSDataParametersType = {
cookies: () => RequestCookie;
} & SetDataRequiredParametersType;
export type SetDataCustomParametersType = {
output: unknown;
} & SetDataRequiredParametersType;
export interface IExternalVisitorCodeManager {
setData(params: SetDataParametersType): void;
getData(params: GetDataParametersType): string | null;
}
export interface IExternalNextJSVisitorCodeManager {
setData(params: SetDataParametersType): void;
setData(params: SetNextJSDataParametersType): void;
getData(params: GetDataParametersType): string | null;
getData(params: GetNextJSDataParametersType): string | null;
}
export interface IExternalDenoVisitorCodeManager {
setData(params: SetDenoDataParametersType): void;
getData(params: GetDenoDataParametersType): string | null;
}
export interface IExternalCustomVisitorCodeManager {
setData(params: SetDataCustomParametersType): void;
getData(params: GetDataCustomParametersType): string | null;
}