Extract shared types and add Regulation type with parsing methods
Move cookie banner types (CookieItem, Category, Regulation, BannerConfig, etc.) into a dedicated types.ts file. Add a coredata.Regulation type with parsing, JSON marshaling, and database scanning methods. Hardcode the geoloc-import data directory since the submodule path is fixed. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -20,82 +20,30 @@ import { COOKIE_NAME, getConsentCookie, setConsentCookie } from "./cookie";
|
||||
import { CookieDetector } from "./detector";
|
||||
import { NotFoundError } from "./errors";
|
||||
import { fetchJSON } from "./http";
|
||||
import type { BannerTexts } from "./i18n";
|
||||
import { detectLanguage } from "./i18n";
|
||||
import type { ConsentIntegration } from "./integrations";
|
||||
import { createDefaultIntegrations } from "./integrations";
|
||||
import { enqueue, flush } from "./queue";
|
||||
import type {
|
||||
BannerConfig,
|
||||
ConsentAction,
|
||||
ConsentRecord,
|
||||
CookieBannerClientOptions,
|
||||
Regulation,
|
||||
VisitorConsent,
|
||||
} from "./types";
|
||||
import { getOrCreateVisitorId } from "./visitor";
|
||||
|
||||
export interface CookieItem {
|
||||
name: string;
|
||||
max_age_seconds: number | null;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface Category {
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string;
|
||||
kind: string;
|
||||
cookies: CookieItem[];
|
||||
gcm_consent_types: string[];
|
||||
posthog_consent: boolean;
|
||||
}
|
||||
|
||||
export type Regulation =
|
||||
| "GDPR"
|
||||
| "UK_GDPR"
|
||||
| "FADP"
|
||||
| "CCPA"
|
||||
| "PIPEDA"
|
||||
| "LGPD"
|
||||
| "LFPDPPP"
|
||||
| "POPIA"
|
||||
| "PDPA"
|
||||
| "PIPL"
|
||||
| "PIPA"
|
||||
| "APPI"
|
||||
| "DPDP"
|
||||
| "PDPL";
|
||||
|
||||
export interface BannerConfig {
|
||||
banner_id: string;
|
||||
version: number;
|
||||
language: string;
|
||||
default_language: string;
|
||||
privacy_policy_url?: string;
|
||||
cookie_policy_url: string;
|
||||
consent_expiry_days: number;
|
||||
consent_mode: "OPT_IN" | "OPT_OUT";
|
||||
regulation: Regulation | null;
|
||||
show_branding: boolean;
|
||||
categories: Category[];
|
||||
texts: BannerTexts;
|
||||
}
|
||||
|
||||
export type ConsentAction = "ACCEPT_ALL" | "REJECT_ALL" | "CUSTOMIZE" | "GPC";
|
||||
|
||||
export interface VisitorConsent {
|
||||
visitor_id: string;
|
||||
version: number;
|
||||
action: ConsentAction;
|
||||
consent_data: Record<string, boolean>;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface ConsentRecord {
|
||||
id: string;
|
||||
visitor_id: string;
|
||||
action: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface CookieBannerClientOptions {
|
||||
bannerId: string;
|
||||
baseUrl: string;
|
||||
lang?: string;
|
||||
}
|
||||
export type {
|
||||
BannerConfig,
|
||||
Category,
|
||||
ConsentAction,
|
||||
ConsentRecord,
|
||||
CookieBannerClientOptions,
|
||||
CookieItem,
|
||||
Regulation,
|
||||
VisitorConsent,
|
||||
} from "./types";
|
||||
|
||||
export class CookieBannerClient {
|
||||
private readonly baseUrl: URL;
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { CookieBannerClient, BannerConfig } from "../client";
|
||||
import type { CookieBannerClient } from "../client";
|
||||
import type { BannerConfig } from "../types";
|
||||
|
||||
export type ProboState = "loading" | "banner" | "panel" | "hidden";
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { Category } from "../client";
|
||||
import type { Category } from "../types";
|
||||
import { ProboElement } from "./base";
|
||||
import type { ProboRootElement } from "./base";
|
||||
import type { ProboCookieBannerRoot } from "./cookie-banner-root";
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { CookieItem } from "../client";
|
||||
import type { CookieItem } from "../types";
|
||||
import { ProboElement } from "./base";
|
||||
|
||||
export class ProboCategory extends ProboElement {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import { CookieBannerClient } from "../client";
|
||||
import type { BannerConfig } from "../client";
|
||||
import type { BannerConfig } from "../types";
|
||||
import { ProboElement } from "./base";
|
||||
import type { ProboState, ProboRootElement, ConsentDraft } from "./base";
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { CookieItem } from "../client";
|
||||
import type { CookieItem } from "../types";
|
||||
import { humanizeDuration } from "../cookie-utils";
|
||||
import { getCookieDetailLabels } from "../i18n";
|
||||
import { ProboElement } from "./base";
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { ConsentAction } from "./client";
|
||||
import type { ConsentAction } from "./types";
|
||||
|
||||
export const COOKIE_NAME = "probo_consent";
|
||||
const SECONDS_PER_DAY = 86400;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { Category } from "../client";
|
||||
import type { Category } from "../types";
|
||||
import type { ConsentIntegration } from "./integration";
|
||||
|
||||
export class GoogleConsentModeIntegration implements ConsentIntegration {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { Category } from "../client";
|
||||
import type { Category } from "../types";
|
||||
|
||||
export interface ConsentIntegration {
|
||||
/** Called once after config is loaded, before any consent is applied. */
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { Category } from "../client";
|
||||
import type { Category } from "../types";
|
||||
import type { ConsentIntegration } from "./integration";
|
||||
|
||||
interface PostHogInstance {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
import { registerHeadlessComponents } from "../components";
|
||||
import type { ProboCookieBannerRoot } from "../components/cookie-banner-root";
|
||||
import type { BannerConfig } from "../client";
|
||||
import type { BannerConfig } from "../types";
|
||||
import { getGpcLabel, interpolate } from "../i18n";
|
||||
import { BRANDING, CHEVRON_DOWN, CLOSE_ICON } from "../html";
|
||||
import { THEMED_STYLES } from "./styles";
|
||||
|
||||
85
packages/cookie-banner/src/types.ts
Normal file
85
packages/cookie-banner/src/types.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import type { BannerTexts } from "./i18n";
|
||||
|
||||
export interface CookieItem {
|
||||
name: string;
|
||||
max_age_seconds: number | null;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface Category {
|
||||
name: string;
|
||||
slug: string;
|
||||
description: string;
|
||||
kind: string;
|
||||
cookies: CookieItem[];
|
||||
gcm_consent_types: string[];
|
||||
posthog_consent: boolean;
|
||||
}
|
||||
|
||||
export type Regulation =
|
||||
| "GDPR"
|
||||
| "UK_GDPR"
|
||||
| "FADP"
|
||||
| "CCPA"
|
||||
| "PIPEDA"
|
||||
| "LGPD"
|
||||
| "LFPDPPP"
|
||||
| "POPIA"
|
||||
| "PDPA"
|
||||
| "PIPL"
|
||||
| "PIPA"
|
||||
| "APPI"
|
||||
| "DPDP"
|
||||
| "PDPL";
|
||||
|
||||
export interface BannerConfig {
|
||||
banner_id: string;
|
||||
version: number;
|
||||
language: string;
|
||||
default_language: string;
|
||||
privacy_policy_url?: string;
|
||||
cookie_policy_url: string;
|
||||
consent_expiry_days: number;
|
||||
consent_mode: "OPT_IN" | "OPT_OUT";
|
||||
regulation: Regulation | null;
|
||||
show_branding: boolean;
|
||||
categories: Category[];
|
||||
texts: BannerTexts;
|
||||
}
|
||||
|
||||
export type ConsentAction = "ACCEPT_ALL" | "REJECT_ALL" | "CUSTOMIZE" | "GPC";
|
||||
|
||||
export interface VisitorConsent {
|
||||
visitor_id: string;
|
||||
version: number;
|
||||
action: ConsentAction;
|
||||
consent_data: Record<string, boolean>;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface ConsentRecord {
|
||||
id: string;
|
||||
visitor_id: string;
|
||||
action: string;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface CookieBannerClientOptions {
|
||||
bannerId: string;
|
||||
baseUrl: string;
|
||||
lang?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user