46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
/**
|
|
* 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;
|
|
}
|