Initial reliable release of consent engine
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Universal Cookie Consent
|
||||
* integration/context.js
|
||||
*
|
||||
* Thin integration boundary between the pure Jurisdiction Engine and
|
||||
* the independent Consent Core.
|
||||
*
|
||||
* The jurisdiction result is context only. It never grants or denies
|
||||
* consent categories.
|
||||
*/
|
||||
|
||||
import {
|
||||
resolveJurisdiction,
|
||||
isValidResolution
|
||||
} from "../jurisdiction/index.js";
|
||||
|
||||
function freezeResolution(resolution) {
|
||||
return Object.freeze({
|
||||
status: resolution.status,
|
||||
jurisdiction: Object.freeze({ ...resolution.jurisdiction }),
|
||||
policy: Object.freeze({ ...resolution.policy }),
|
||||
source: resolution.source,
|
||||
confidence: resolution.confidence
|
||||
});
|
||||
}
|
||||
|
||||
export function resolveConsentContext(input = {}) {
|
||||
const resolution = resolveJurisdiction(input);
|
||||
|
||||
if (!isValidResolution(resolution)) {
|
||||
throw new Error("Jurisdiction Engine returned an invalid resolution.");
|
||||
}
|
||||
|
||||
return Object.freeze({
|
||||
resolution: freezeResolution(resolution)
|
||||
});
|
||||
}
|
||||
|
||||
export function getConsentJurisdiction(input = {}) {
|
||||
return resolveConsentContext(input).resolution.jurisdiction.id;
|
||||
}
|
||||
|
||||
export function getConsentPolicy(input = {}) {
|
||||
return resolveConsentContext(input).resolution.policy.id;
|
||||
}
|
||||
Reference in New Issue
Block a user