Types
All types are exported from @uabcodus/consent/core.
Configuration types
Section titled “Configuration types”ConsentConfig<TCategories>
Section titled “ConsentConfig<TCategories>”The main configuration object passed to createConsent().
interface ConsentConfig<TCategories extends Record<string, CategoryConfig>> { preset?: Partial<ConsentConfig<Record<string, CategoryConfig>>>; mode?: ConsentMode; revision?: number; hideFromBots?: boolean; manageScripts?: boolean; scriptType?: string; autoClearCookies?: boolean; categories: TCategories; storage?: StorageAdapter; initialCookie?: CookieValue | string | null; callbacks?: ConsentCallbacks;}ConsentMode
Section titled “ConsentMode”type ConsentMode = "opt-in" | "opt-out";CategoryConfig
Section titled “CategoryConfig”interface CategoryConfig { enabled?: boolean; readOnly?: boolean; autoClear?: { reloadPage?: boolean; cookies?: CookieItem[]; }; services?: Record<string, ServiceConfig>;}ServiceConfig
Section titled “ServiceConfig”interface ServiceConfig { onAccept?: () => void; onReject?: () => void; cookies?: CookieItem[];}CookieConfig
Section titled “CookieConfig”interface CookieConfig { name: string; expiresAfterDays: number | ((acceptType: AcceptType) => number); domain: string; path: string; secure: boolean; sameSite: "Lax" | "Strict" | "None";}StorageAdapter
Section titled “StorageAdapter”interface StorageAdapter { get(): CookieValue; set(value: CookieValue): void; remove(): void;}Factory functions:
function cookieStorage(config: CookieConfig): StorageAdapter;function localStorageStorage(name: string, expiresAfterMs?: number): StorageAdapter;CookieItem
Section titled “CookieItem”interface CookieItem { name: string | RegExp; path?: string; domain?: string;}State types
Section titled “State types”ConsentState
Section titled “ConsentState”interface ConsentState { valid: boolean; skipped: boolean; categories: Record<string, { accepted: boolean; readOnly: boolean }>; services: Record<string, Record<string, boolean>>; cookie: CookieValue | null; mode: ConsentMode; acceptType: AcceptType;}AcceptType
Section titled “AcceptType”type AcceptType = "all" | "custom" | "necessary";CookieValue
Section titled “CookieValue”interface CookieValue { categories: string[]; services: Record<string, string[]>; revision: number; data: unknown; consentId: string; consentTimestamp: string; lastConsentTimestamp?: string; expirationTime?: number; languageCode?: string;}Callback types
Section titled “Callback types”ConsentCallbacks
Section titled “ConsentCallbacks”interface ConsentCallbacks { onFirstConsent?: (payload: { cookie: CookieValue }) => void; onConsent?: (payload: { cookie: CookieValue }) => void; onChange?: (payload: CookieChange) => void;}CookieChange
Section titled “CookieChange”interface CookieChange { cookie: CookieValue; changedCategories: string[]; changedServices: Record<string, string[]>;}Instance type
Section titled “Instance type”ConsentInstance<TCategories>
Section titled “ConsentInstance<TCategories>”The main API object returned by createConsent().
interface ConsentInstance<TCategories extends Record<string, CategoryConfig>> { readonly state: Readonly<ConsentState>;
accept: (categories: CategoryAcceptArg<TCategories>, excludedCategories?: string[]) => void; reject: (categories: CategoryAcceptArg<TCategories>) => void; acceptedCategory: (category: CategoryNames<TCategories>) => boolean;
acceptService: ( service: ServiceAcceptArg<TCategories, CategoryNames<TCategories>>, category: CategoryNames<TCategories> ) => void; rejectService: ( service: ServiceAcceptArg<TCategories, CategoryNames<TCategories>>, category: CategoryNames<TCategories> ) => void; acceptedService: ( service: ServiceNames<TCategories, CategoryNames<TCategories>>, category: CategoryNames<TCategories> ) => boolean;
eraseCookies: ( cookies: string | RegExp | Array<string | RegExp>, path?: string, domain?: string ) => void; getCookie: (field?: string) => unknown; setCookieData: (props: { value: unknown; mode: "set" | "update" }) => boolean; getConfig: <K extends string>(field?: K) => unknown; validConsent: () => boolean; loadScript: (src: string, attrs?: Record<string, string>) => Promise<boolean>; reset: (deleteCookie?: boolean) => void;
subscribe: (listener: (state: Readonly<ConsentState>) => void) => () => void; on: (event: string, listener: (...args: unknown[]) => void) => () => void; off: (event: string, listener: (...args: unknown[]) => void) => void; destroy: () => void;}Generic helpers
Section titled “Generic helpers”These are utility types that help with type inference. You typically don’t need to import them
directly — they power the generic type parameter on ConsentInstance.
CategoryNames<TCategories>
Section titled “CategoryNames<TCategories>”type CategoryNames<TCategories> = keyof TCategories & string;Extracts category name strings from your config.
CategoryAcceptArg<TCategories>
Section titled “CategoryAcceptArg<TCategories>”type CategoryAcceptArg<TCategories> = | "all" | "necessary" | CategoryNames<TCategories> | Array<CategoryNames<TCategories>>;The union of all valid arguments to accept() and reject().
ServiceNames<TCategories, TCategory>
Section titled “ServiceNames<TCategories, TCategory>”type ServiceNames< TCategories extends Record<string, CategoryConfig>, TCategory extends CategoryNames<TCategories>> = NonNullable<TCategories[TCategory]["services"]> extends Record<infer K, ServiceConfig> ? K & string : never;Extracts service name strings from a category’s services config.
ServiceAcceptArg<TCategories, TCategory>
Section titled “ServiceAcceptArg<TCategories, TCategory>”type ServiceAcceptArg<TCategories, TCategory> = | "all" | ServiceNames<TCategories, TCategory> | Array<ServiceNames<TCategories, TCategory>>;The union of all valid arguments to acceptService() and rejectService().