74 lines
1.5 KiB
JavaScript
74 lines
1.5 KiB
JavaScript
/**
|
|
* Universal Cookie Consent
|
|
* jurisdiction/jurisdiction.js
|
|
*
|
|
* Declarative jurisdiction catalog. This file maps jurisdiction identifiers
|
|
* to policy identifiers. It does not detect visitors or enforce consent.
|
|
*/
|
|
|
|
import { hasPolicy } from "./policies.js";
|
|
|
|
const JURISDICTIONS = {
|
|
global: {
|
|
id: "global",
|
|
country: null,
|
|
region: null,
|
|
policy: "global-baseline"
|
|
},
|
|
|
|
us: {
|
|
id: "us",
|
|
country: "US",
|
|
region: null,
|
|
policy: "us-state-privacy"
|
|
},
|
|
|
|
"us-ma": {
|
|
id: "us-ma",
|
|
country: "US",
|
|
region: "MA",
|
|
policy: "us-state-privacy"
|
|
},
|
|
|
|
"us-ca": {
|
|
id: "us-ca",
|
|
country: "US",
|
|
region: "CA",
|
|
policy: "us-california-privacy"
|
|
},
|
|
|
|
eu: {
|
|
id: "eu",
|
|
country: "EU",
|
|
region: null,
|
|
policy: "eu-privacy"
|
|
}
|
|
};
|
|
|
|
for (const entry of Object.values(JURISDICTIONS)) {
|
|
if (!hasPolicy(entry.policy)) {
|
|
throw new Error(`Jurisdiction references unknown policy: ${entry.policy}`);
|
|
}
|
|
}
|
|
|
|
export const JURISDICTION_CATALOG = Object.freeze(
|
|
Object.fromEntries(
|
|
Object.entries(JURISDICTIONS).map(([id, value]) => [
|
|
id,
|
|
Object.freeze({ ...value })
|
|
])
|
|
)
|
|
);
|
|
|
|
export function getJurisdiction(id) {
|
|
if (typeof id !== "string") {
|
|
return null;
|
|
}
|
|
|
|
return JURISDICTION_CATALOG[id] || null;
|
|
}
|
|
|
|
export function hasJurisdiction(id) {
|
|
return Boolean(getJurisdiction(id));
|
|
}
|