Documentation menuCore API
Core API
Functions exported by @permitojs/core.
createConsentManager(config)
| Member | Description |
|---|---|
getSnapshot(), subscribe(fn) | External store contract. Snapshot reference stays stable between changes. |
ready | Promise, resolves once async storage has been read. |
hasConsent(id), hasServiceConsent(id) | |
acceptAll(source?), rejectAll(source?) | |
update(categories, { services, source }) | Unknown ids are ignored, required categories stay granted. |
setServiceConsent(id, granted, source?) | |
reset() | Clears storage and emits consent_revoked. |
exportState(), importState(state) | Import is validated against the current config. |
on(type, fn) | Events: consent_loaded, consent_updated, consent_revoked, service_allowed, service_blocked. |
Helpers
| Function | Description |
|---|---|
readConsentFromCookieHeader(header, name?) | Parse the decision from a Cookie header on the server. |
parseConsentState(raw), serializeConsentState(state), isConsentState(value) | Validate untrusted data. |
getConsentModeDefaultScript(options) | Inline Consent Mode default snippet. |
connectGoogleConsentMode(manager, options) | Push Consent Mode updates. |
toGoogleConsent(categories, mapping) | Map categories to Consent Mode values. |
loadScript(options) | Load an external script once. |
activateBlockedElements(manager, options) | Activate blocked markup. |
isUrlAllowed(src, allowlist) | |
getTranslations(language, overrides), localize(text, language) |