UNPKG

@kameleoon/nodejs-sdk

Version:
104 lines (103 loc) 7.34 kB
import { KameleoonCore } from '@kameleoon/javascript-sdk-core'; import { SDKParameters, GetVisitorCodeParametersType, SetLegalConsentParametersType, SetNextJSLegalConsentParametersType, GetNextJSVisitorCodeParametersType, GetCustomVisitorCodeParametersType, GetDenoVisitorCodeParametersType, SetDenoLegalConsentParametersType, SetCustomLegalConsentParametersType } from './types'; /** * @class * KameleoonClient - a class for creating kameleoon client instance * */ export declare class KameleoonClient extends KameleoonCore { private domain?; private internalVisitorCodeManager; private externalVisitorCodeManager; constructor({ siteCode, credentials, configuration, compatibility, externals, }: SDKParameters); /** * @method initialize - an asynchronous method for KameleoonClient initialization by fetching Kameleoon SDK related data from server or by retrieving data from local source if data is up-to-date or update interval has not been reached * @returns {Promise<boolean>} Promise resolved into boolean field indicating success or fail * @throws `KameleoonError` with one of the following `type` s: * * - `KameleoonException.StorageWrite` Couldn't update storage data * - `KameleoonException.StorageRead` - Couldn't read storage data * - `KameleoonException.ClientConfiguration` Couldn't retrieve client configuration from Kameleoon Api * - `KameleoonException.MaximumRetriesReached` Maximum retries reached, request failed */ initialize(): Promise<boolean>; /** * @method getVisitorCode - obtains visitor code from the request headers cookie, if the visitor code doesn't yet exist generates a random visitor code (or uses a provided default) and sets a new visitor code to response headers cookie * @param {GetVisitorCodeParametersType} params - an object consisting of the following fields: `request`, `response` and `defaultVisitorCode` * @returns {string} result visitor code * @throws `KameleoonError` with one of the following `type` s: * * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty */ getVisitorCode({ request, response, defaultVisitorCode, }: GetVisitorCodeParametersType): string; /** * @method getVisitorCode - retrieves or generates a visitor code using cookies. * @param {GetDenoVisitorCodeParametersType} params - an object consisting of the following fields: `request`, `response` and `defaultVisitorCode` * @returns {string} result visitor code * @throws `KameleoonError` with one of the following `type` s: * * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty */ getVisitorCode({ request, response, defaultVisitorCode, }: GetDenoVisitorCodeParametersType): string; /** * @method getVisitorCode - retrieves or generates a visitor code using cookies. Optimized for Next.js, it works with the state of cookies from `cookies()` in server-side contexts like API Routes or GetServerSideProps * @param {GetNextJSVisitorCodeParametersType} params - an object consisting of the following fields: `cookies` and `defaultVisitorCode` * @returns {string} result visitor code * @throws `KameleoonError` with one of the following `type` s: * * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty */ getVisitorCode({ cookies, defaultVisitorCode, }: GetNextJSVisitorCodeParametersType): string; /** * @method getVisitorCode - retrieves or generates a visitor code using input and output parameters. It's useful for custom implementations where the visitor code is stored in a different way than cookies * @param {GetCustomVisitorCodeParametersType} params - an object consisting of the following fields: `input`, `output` and `defaultVisitorCode` * @returns {string} result visitor code * @throws `KameleoonError` with one of the following `type` s: * * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty */ getVisitorCode({ input, output, }: GetCustomVisitorCodeParametersType): string; /** * @method setLegalConsent - sets or updates the legal consent status for a visitor identified by their unique visitor code, affecting values in the response cookies based on the consent status * @param {SetLegalConsentParametersType} params - an object consisting of the following fields: `visitorCode`, `consent` and `response` * @returns {void} * @throws `KameleoonError` with one of the following `type` s: * * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty */ setLegalConsent({ visitorCode, consent, response, }: SetLegalConsentParametersType): void; /** * @method setLegalConsent - sets or updates the legal consent status for a visitor identified by their unique visitor code, affecting values in the response cookies based on the consent status * @param {SetDenoLegalConsentParametersType} params - an object consisting of the following fields: `visitorCode`, `consent` and `response` * @returns {void} * @throws `KameleoonError` with one of the following `type` s: * * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty */ setLegalConsent({ visitorCode, consent, response, }: SetDenoLegalConsentParametersType): void; /** * @method setLegalConsent - sets or updates the legal consent status for a visitor identified by their unique visitor code, affecting values in the response cookies based on the consent status * @param {SetNextJSLegalConsentParametersType} params - an object consisting of the following fields: `visitorCode`, `consent` and `cookies` * @returns {void} * @throws `KameleoonError` with one of the following `type` s: * * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty */ setLegalConsent({ visitorCode, consent, cookies, }: SetNextJSLegalConsentParametersType): void; /** * @method setLegalConsent - sets or updates the legal consent status for a visitor identified by their unique visitor code, affecting values in the output object based on the consent status * @param {SetCustomLegalConsentParametersType} params - an object consisting of the following fields: `visitorCode`, `consent` and `output` * @returns {void} * @throws `KameleoonError` with one of the following `type` s: * * - `KameleoonException.VisitorCodeMaxLength` - The visitor code length was exceeded * - `KameleoonException.VisitorCodeEmpty` The visitor code is empty */ setLegalConsent({ visitorCode, consent, output, }: SetCustomLegalConsentParametersType): void; }