Skip to main content

Types

Type definitions for the cookies-consent package.

CookieCategory

type CookieCategory = "essential" | "functional" | "statistics" | "marketing";

ConsentState

The state stored in localStorage and managed by the provider.

interface ConsentState {
/** Whether user has made a consent choice */
hasConsented: boolean;
/** Timestamp of when consent was given */
timestamp: number | null;
/** Category-specific consent settings */
categories: {
/** Essential cookies - always true, cannot be disabled */
essential: true;
/** Functional cookies - user preference storage, UI state */
functional: boolean;
/** Statistics cookies - usage tracking, performance monitoring */
statistics: boolean;
/** Marketing cookies - advertising and retargeting */
marketing: boolean;
};
}

ConsentTranslations

Translation strings for the consent banner.

interface ConsentTranslations {
/** Banner title */
title: string;
/** Banner description */
description: string;
/** Accept all button text */
acceptAll: string;
/** Essential only button text */
essentialOnly: string;
/** Learn more link text */
learnMore: string;
/** Customize button text */
customize: string;
/** Save preferences button text */
savePreferences: string;
/** Back button text */
back: string;
/** Floating button tooltip text */
floatingButtonTooltip: string;
/** Footer link labels */
footerLinks: {
privacy: string;
contact: string;
imprint: string;
};
/** Cookie categories with details */
categories: {
essential: CategoryInfo;
functional: CategoryInfo;
statistics: CategoryInfo;
marketing: CategoryInfo;
};
}

CategoryInfo

Information about a cookie category.

interface CategoryInfo {
/** Category title */
title: string;
/** Category description */
description: string;
/** Whether this category can be toggled (essential cannot) */
required: boolean;
/** List of cookies in this category */
cookies: CookieInfo[];
/** List of storage items in this category (localStorage/sessionStorage) */
storage?: StorageInfo[];
}

CookieInfo

Information about a specific cookie.

interface CookieInfo {
/** Cookie name */
name: string;
/** Cookie purpose/description */
purpose: string;
/** Cookie duration (e.g., "30 days", "Session") */
duration: string;
/** Which app(s) use this cookie (e.g., "Console", "ID", "All", or ["Console", "ID"]) */
app?: string | string[];
}

StorageInfo

Information about a browser storage item (localStorage/sessionStorage).

interface StorageInfo {
/** Storage key */
key: string;
/** Storage type */
type: "localStorage" | "sessionStorage";
/** Storage purpose/description */
purpose: string;
/** Which app(s) use this storage (e.g., "Console", "ID", "All", or ["Console", "ID"]) */
app?: string | string[];
}

ConsentProviderProps

Props for the ConsentProvider component.

interface ConsentProviderProps {
/** Child components */
children: React.ReactNode;
/** Custom translations - uses built-in English if not provided */
translations?: ConsentTranslations;
/** URL to cookie policy page */
policyUrl?: string;
/** Footer links for Privacy, Contact, Imprint */
footerLinks?: ConsentFooterLinks;
/** Callback when consent changes */
onConsentChange?: (consent: ConsentState) => void;
/** Whether to show the floating cookie settings button (default: true) */
showFloatingButton?: boolean;
/** Current app name - used to filter storage items (e.g., "Console", "ID", "Policies") */
appName?: string;
}

Footer links configuration.

interface ConsentFooterLinks {
/** Privacy policy URL */
privacyUrl?: string;
/** Contact page URL */
contactUrl?: string;
/** Imprint/Legal page URL */
imprintUrl?: string;
}

ConsentContextValue

Value provided by the consent context.

interface ConsentContextValue {
/** Current consent state */
consent: ConsentState;
/** Whether user has made a consent choice */
hasConsented: boolean;
/** Whether the consent banner is currently open */
isOpen: boolean;
/** Open the consent banner */
openBanner: () => void;
/** Close the consent banner */
closeBanner: () => void;
/** Accept all cookie categories */
acceptAll: () => void;
/** Accept only essential cookies */
acceptEssentialOnly: () => void;
/** Check if a specific category is allowed */
isAllowed: (category: CookieCategory) => boolean;
}

CustomConsentCategories

Used when saving custom preferences.

interface CustomConsentCategories {
functional: boolean;
statistics: boolean;
marketing: boolean;
}

DetectedCookie

Detected cookie information from the browser.

interface DetectedCookie {
name: string;
value: string;
category: "essential" | "functional" | "statistics" | "marketing" | "unknown";
service?: string;
devOnly?: boolean;
}

DetectedStorageItem

Detected storage item from localStorage or sessionStorage.

type StorageType = "localStorage" | "sessionStorage";

interface DetectedStorageItem {
key: string;
value: string;
storageType: StorageType;
category: "essential" | "functional" | "statistics" | "marketing" | "unknown";
service?: string;
app?: string;
}

DetectedBrowserData

Combined type for all browser data (cookies + storage).

type DataType = "cookie" | "localStorage" | "sessionStorage";

interface DetectedBrowserData {
/** Unique identifier for display */
id: string;
/** Name/key of the item */
name: string;
/** Value stored */
value: string;
/** Type of storage */
dataType: DataType;
/** Category (essential, functional, etc.) */
category: "essential" | "functional" | "statistics" | "marketing" | "unknown";
/** Service that uses this item */
service?: string;
/** App that uses this item (for storage items) */
app?: string;
}

Importing Types

All types are exported from the main package:

import type {
CookieCategory,
CookieInfo,
StorageInfo,
CategoryInfo,
ConsentState,
ConsentTranslations,
ConsentProviderProps,
ConsentContextValue,
CustomConsentCategories,
ConsentFooterLinks,
ConsentBannerProps,
// Detection types
DetectedCookie,
DetectedStorageItem,
StorageType,
DetectedBrowserData,
DataType,
} from "@elcto/cookies-consent";