/** * Types for `window.Nodbar`, the API of the Nodbar consent banner script. * Documentation: https://nodbar.com/developers * * Add this file to your project (for example `src/nodbar.d.ts`, inside the `include` of your * tsconfig.json): `window.Nodbar` and the `nodbar:consent` event are then typed. * `window.Nodbar` is undefined until the banner script has run, unless the page defines the * waiting line given in the documentation first. */ export {} declare global { /** Purposes offered to the visitor. `necessary` is always granted. */ type NodbarCategory = 'necessary' | 'analytics' | 'marketing' | 'functional' interface NodbarApi { /** Opens the preferences panel, for the site's own "Manage cookies" button. */ open(): void /** Categories the visitor granted, `necessary` included. */ getConsent(): NodbarCategory[] /** ID of the visitor's consent proof, once they have made a choice. */ getConsentId(): string | undefined /** * Called with the granted categories after every choice, and once on page load when a * choice is already stored (if registered before the script has finished starting). * Returns a function that removes the listener (for a component's cleanup). */ onChange(listener: (granted: NodbarCategory[]) => void): () => void /** * Runs `fn` once: at once if `category` is granted, otherwise when the visitor grants it. * Returns a function that cancels `fn` if it has not run yet. */ when(category: NodbarCategory, fn: () => void): () => void } interface NodbarConsentDetail { granted: NodbarCategory[] } interface Window { Nodbar?: NodbarApi } interface WindowEventMap { 'nodbar:consent': CustomEvent } }