@almacareer/cookie-consent-manager
Version:
Cookie Consent Manager mainly for Alma Career products
88 lines (87 loc) • 3.36 kB
TypeScript
import CookieConsent, { CookieConsentConfig, CookieValue } from 'vanilla-cookieconsent';
import { CookieConsentCategory, DisplayMode, KnownCookieName } from '../constants';
export type Values<T> = T[keyof T];
export type CookieConsentCategoryValues = Values<typeof CookieConsentCategory>;
export type CategoriesChangeset = {
accepted: CookieConsentCategoryValues[];
rejected: CookieConsentCategoryValues[];
changed: CookieConsentCategoryValues[];
};
export type OnFirstConsentCallback = (param: {
cookieConsent: typeof CookieConsent;
cookie: CookieValue;
}) => void;
export type OnConsentCallback = (param: {
cookieConsent: typeof CookieConsent;
cookie: CookieValue;
}) => void;
export type OnChangeCallback = (param: {
cookieConsent: typeof CookieConsent;
cookie: CookieValue;
categories: CategoriesChangeset;
}) => void;
declare const SUPPORTED_LANGUAGES: readonly ["bs", "cs", "de", "en", "es", "et", "fr", "hr", "hu", "lt", "lv", "mk", "pl", "pt", "ro", "ru", "sk", "sl", "sr", "uk"];
export type SupportedLanguage = (typeof SUPPORTED_LANGUAGES)[number];
export declare const isSupportedLanguage: (lang: string) => lang is SupportedLanguage;
export type TranslationOverride = {
consentTitle?: string;
descriptionIntro?: string;
preferencesModalMoreInfo?: string;
};
export type CookieTableCategories = {
[category in CookieConsentCategoryValues]: {
[p: string]: string;
}[];
};
export type CookieTable = {
[language: string]: CookieTableCategories;
};
export type Expiration = {
years: number;
} | {
months: number;
} | {
days: number;
} | {
hours: number;
} | 'Session';
/**
* A cookie from the predefined dictionary. Only `name` (one of the known glob patterns)
* and `expire` are required — descriptions are resolved internally.
*/
export type PredefinedCookie = {
name: KnownCookieName;
expire: Expiration;
};
/**
* A cookie not in the predefined dictionary. Requires full metadata.
*/
export type CustomCookie = {
name: Exclude<string, KnownCookieName>;
/** Regex pattern used to match the cookie. Defaults to `name` if not specified. */
pattern?: string;
provider: string;
suggestedCategory: CookieConsentCategoryValues;
expire: Expiration;
description: Partial<Record<SupportedLanguage, string>>;
};
export type CookieTableItem = PredefinedCookie | CustomCookie;
/** Builds the internal CookieTable structure from a flat list of cookie items, fetching descriptions for predefined cookies from the API. */
export type CreateCookieTable = (items: CookieTableItem[]) => Promise<CookieTable>;
export type CookieConsentManagerOptions = {
defaultLang: string;
autodetectLang: boolean;
consentCollectorApiUrl: string;
onFirstConsent: OnFirstConsentCallback;
onConsent: OnConsentCallback;
onChange: OnChangeCallback;
companyNames: string[];
displayMode: Values<typeof DisplayMode>;
translationOverrides: Record<string, TranslationOverride>;
/** @deprecated Use `cookieTableItems` instead. Will be removed in the next major version. */
cookieTable: CookieTable;
cookieTableItems: CookieTableItem[];
config?: Partial<CookieConsentConfig>;
};
export type CookieConsentManager = (serviceName: string, args?: Partial<CookieConsentManagerOptions>) => typeof CookieConsent;
export {};