@replohq/canopy-sdk 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_vendor/replo-utils/lib/google-fonts.d.ts +34 -0
- package/_vendor/replo-utils/lib/google-fonts.mjs +28 -0
- package/_vendor/schemas/designLibrary.d.ts +9 -0
- package/_vendor/schemas/designLibrary.mjs +8 -2
- package/_vendor/schemas/generated/consent.d.ts +26 -0
- package/consent/consent-action.d.ts +9 -0
- package/consent/consent-action.js +25 -0
- package/consent/consent-action.js.map +7 -0
- package/consent/consent-actions.d.ts +22 -0
- package/consent/consent-actions.js +37 -0
- package/consent/consent-actions.js.map +7 -0
- package/consent/consent-store.d.ts +10 -8
- package/consent/consent-store.js +34 -20
- package/consent/consent-store.js.map +2 -2
- package/consent/cookie.d.ts +7 -9
- package/consent/cookie.js +6 -2
- package/consent/cookie.js.map +2 -2
- package/editor/design-library-preview/DesignLibraryPreview.js +39 -4
- package/editor/design-library-preview/DesignLibraryPreview.js.map +2 -2
- package/env.d.ts +1 -0
- package/env.js +1 -0
- package/env.js.map +2 -2
- package/package.json +1 -1
- package/consent/server.d.ts +0 -12
- package/consent/server.js +0 -29
- package/consent/server.js.map +0 -7
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slugified family name, matching how `fontNameToCssVariable` derives a CSS var
|
|
3
|
+
* (e.g. "DM Sans" → "dm-sans"), so a `--font-<slug>` var round-trips back to a
|
|
4
|
+
* catalog family.
|
|
5
|
+
*/
|
|
6
|
+
export declare function slugifyFontFamily(family: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* "DM Sans" → "--font-dm-sans". The CSS variable a `next/font` import exposes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function fontNameToCssVariable(fontName: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Wrap a family in single quotes for `font-family` when it contains whitespace
|
|
13
|
+
* (e.g. `Open Sans` → `'Open Sans'`); single-word families pass through.
|
|
14
|
+
*/
|
|
15
|
+
export declare function quoteFontFamily(family: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* "DM Sans" → "dmSans". The JS const name for a `next/font` declaration.
|
|
18
|
+
*/
|
|
19
|
+
export declare function fontNameToVariableName(fontName: string): string;
|
|
20
|
+
export interface NextFontDeclaration {
|
|
21
|
+
/** Import name for `next/font/google`, e.g. "DM_Sans". */
|
|
22
|
+
importName: string;
|
|
23
|
+
/** JS const name, e.g. "dmSans". */
|
|
24
|
+
variableName: string;
|
|
25
|
+
/** CSS variable the import exposes, e.g. "--font-dm-sans". */
|
|
26
|
+
cssVar: string;
|
|
27
|
+
/** The full `const … = …({ … })` declaration. */
|
|
28
|
+
declaration: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Google Fonts CSS2 stylesheet URL for a family at the given weights (defaulting
|
|
32
|
+
* to 400), with `display=swap`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildGoogleFontsCssUrl(family: string, weights?: number[]): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// ../replo-utils/lib/google-fonts.ts
|
|
2
|
+
function slugifyFontFamily(family) {
|
|
3
|
+
return family.replace(/([a-z])([A-Z])/g, "$1-$2").split(/[\s_-]+/u).map((word) => word.toLowerCase()).join("-");
|
|
4
|
+
}
|
|
5
|
+
function fontNameToCssVariable(fontName) {
|
|
6
|
+
return `--font-${slugifyFontFamily(fontName)}`;
|
|
7
|
+
}
|
|
8
|
+
function quoteFontFamily(family) {
|
|
9
|
+
return /\s/u.test(family) ? `'${family}'` : family;
|
|
10
|
+
}
|
|
11
|
+
function fontNameToVariableName(fontName) {
|
|
12
|
+
const words = fontName.replace(/([a-z])([A-Z])/g, "$1 $2").split(/[\s_-]+/u);
|
|
13
|
+
return words.map((word, index) => {
|
|
14
|
+
return index === 0 ? word.toLowerCase() : word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
15
|
+
}).join("");
|
|
16
|
+
}
|
|
17
|
+
function buildGoogleFontsCssUrl(family, weights) {
|
|
18
|
+
const requested = weights && weights.length > 0 ? Array.from(new Set(weights)) : [400];
|
|
19
|
+
const sortedWeights = requested.sort(
|
|
20
|
+
(leftWeight, rightWeight) => leftWeight - rightWeight
|
|
21
|
+
);
|
|
22
|
+
const familyParam = family.trim().replace(/\s+/gu, "+");
|
|
23
|
+
return `https://fonts.googleapis.com/css2?family=${familyParam}:wght@${sortedWeights.join(
|
|
24
|
+
";"
|
|
25
|
+
)}&display=swap`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { buildGoogleFontsCssUrl, fontNameToCssVariable, fontNameToVariableName, quoteFontFamily, slugifyFontFamily };
|
|
@@ -327,7 +327,16 @@ export declare const globalsCssSnapshotSchema: z.ZodObject<{
|
|
|
327
327
|
}, z.core.$strip>>;
|
|
328
328
|
}, z.core.$strip>;
|
|
329
329
|
export declare const DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE = "replo:design-library:applyOverrides";
|
|
330
|
+
export declare const designLibraryPreviewFontSchema: z.ZodObject<{
|
|
331
|
+
family: z.ZodString;
|
|
332
|
+
cssVar: z.ZodString;
|
|
333
|
+
}, z.core.$strip>;
|
|
330
334
|
export declare const designLibraryPreviewMessageSchema: z.ZodObject<{
|
|
331
335
|
type: z.ZodLiteral<"replo:design-library:applyOverrides">;
|
|
332
336
|
cssVars: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
337
|
+
fonts: z.ZodArray<z.ZodObject<{
|
|
338
|
+
family: z.ZodString;
|
|
339
|
+
cssVar: z.ZodString;
|
|
340
|
+
}, z.core.$strip>>;
|
|
341
|
+
defaultFontCssVar: z.ZodNullable<z.ZodString>;
|
|
333
342
|
}, z.core.$strip>;
|
|
@@ -100,9 +100,15 @@ var globalsCssSnapshotSchema = z.object({
|
|
|
100
100
|
scopes: z.array(globalsCssScopeSchema)
|
|
101
101
|
}).describe("GlobalsCssSnapshot");
|
|
102
102
|
var DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE = "replo:design-library:applyOverrides";
|
|
103
|
+
var designLibraryPreviewFontSchema = z.object({
|
|
104
|
+
family: z.string(),
|
|
105
|
+
cssVar: z.string()
|
|
106
|
+
}).describe("DesignLibraryPreviewFont");
|
|
103
107
|
var designLibraryPreviewMessageSchema = z.object({
|
|
104
108
|
type: z.literal(DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE),
|
|
105
|
-
cssVars: z.record(z.string(), z.string())
|
|
109
|
+
cssVars: z.record(z.string(), z.string()),
|
|
110
|
+
fonts: z.array(designLibraryPreviewFontSchema),
|
|
111
|
+
defaultFontCssVar: z.string().nullable()
|
|
106
112
|
}).describe("DesignLibraryPreviewMessage");
|
|
107
113
|
|
|
108
|
-
export { DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE, designLibraryPreviewMessageSchema, designLibrarySavedStyleMetadataSchema, designLibrarySavedStylesSchema, designLibrarySchema, globalsCssScopeSchema, globalsCssSnapshotSchema, globalsCssTokenSchema, savedColorStyleSchema, savedTextStyleSchema };
|
|
114
|
+
export { DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE, designLibraryPreviewFontSchema, designLibraryPreviewMessageSchema, designLibrarySavedStyleMetadataSchema, designLibrarySavedStylesSchema, designLibrarySchema, globalsCssScopeSchema, globalsCssSnapshotSchema, globalsCssTokenSchema, savedColorStyleSchema, savedTextStyleSchema };
|
|
@@ -22,3 +22,29 @@ export type ReploScriptEntry = {
|
|
|
22
22
|
src?: string;
|
|
23
23
|
body?: string;
|
|
24
24
|
};
|
|
25
|
+
export type ConsentAction = "accept" | "reject" | "update" | "withdraw";
|
|
26
|
+
export type ConsentRecordRequest = {
|
|
27
|
+
consentId: string;
|
|
28
|
+
projectId: string;
|
|
29
|
+
decidedAt: number;
|
|
30
|
+
action: ConsentAction;
|
|
31
|
+
categories: {
|
|
32
|
+
[x: string]: boolean;
|
|
33
|
+
};
|
|
34
|
+
consentMode: ConsentMode;
|
|
35
|
+
policyVersion: number;
|
|
36
|
+
};
|
|
37
|
+
export type ConsentEventMessage = {
|
|
38
|
+
consentId: string;
|
|
39
|
+
projectId: string;
|
|
40
|
+
decidedAt: number;
|
|
41
|
+
action: ConsentAction;
|
|
42
|
+
categories: {
|
|
43
|
+
[x: string]: boolean;
|
|
44
|
+
};
|
|
45
|
+
consentMode: ConsentMode;
|
|
46
|
+
policyVersion: number;
|
|
47
|
+
useragent: string;
|
|
48
|
+
referrer: string;
|
|
49
|
+
ipCountry: string;
|
|
50
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ConsentAction } from "../_vendor/schemas/generated/consent";
|
|
2
|
+
import type { ConsentCategories } from "./cookie";
|
|
3
|
+
export declare function deriveConsentAction({ previous, next, }: {
|
|
4
|
+
previous: {
|
|
5
|
+
decidedAt: number | null;
|
|
6
|
+
categories: ConsentCategories;
|
|
7
|
+
};
|
|
8
|
+
next: ConsentCategories;
|
|
9
|
+
}): ConsentAction;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const NON_NECESSARY_CATEGORIES = [
|
|
2
|
+
"analytics",
|
|
3
|
+
"marketing",
|
|
4
|
+
"preferences",
|
|
5
|
+
"sale_of_data"
|
|
6
|
+
];
|
|
7
|
+
function deriveConsentAction({
|
|
8
|
+
previous,
|
|
9
|
+
next
|
|
10
|
+
}) {
|
|
11
|
+
const anyGranted = NON_NECESSARY_CATEGORIES.some(
|
|
12
|
+
(category) => next[category]
|
|
13
|
+
);
|
|
14
|
+
if (previous.decidedAt === null) {
|
|
15
|
+
return anyGranted ? "accept" : "reject";
|
|
16
|
+
}
|
|
17
|
+
if (!anyGranted) {
|
|
18
|
+
return "withdraw";
|
|
19
|
+
}
|
|
20
|
+
return "update";
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
deriveConsentAction
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=consent-action.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../consent/consent-action.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ConsentAction, ConsentCategory } from \"schemas/generated/consent\";\nimport type { ConsentCategories } from \"./cookie\";\n\n/**\n * Pure mapping from a consent decision (previous state vs the resulting state)\n * to the legal-record `action` written to the proof-of-consent audit log.\n *\n * Only non-necessary categories matter (`necessary` is always granted). The\n * mapping is:\n * - first decision (`decidedAt === null`), some category granted -> \"accept\"\n * - first decision, nothing granted -> \"reject\"\n * - later decision that leaves nothing granted -> \"withdraw\"\n * - any other later change -> \"update\"\n *\n * `withdraw` is reserved for going from some consent to none (the GDPR\n * withdrawal right); a partial reduction that still leaves something granted is\n * an `update`.\n */\nconst NON_NECESSARY_CATEGORIES: Exclude<ConsentCategory, \"necessary\">[] = [\n \"analytics\",\n \"marketing\",\n \"preferences\",\n \"sale_of_data\",\n];\n\nexport function deriveConsentAction({\n previous,\n next,\n}: {\n previous: { decidedAt: number | null; categories: ConsentCategories };\n next: ConsentCategories;\n}): ConsentAction {\n const anyGranted = NON_NECESSARY_CATEGORIES.some(\n (category) => next[category],\n );\n\n if (previous.decidedAt === null) {\n return anyGranted ? \"accept\" : \"reject\";\n }\n if (!anyGranted) {\n return \"withdraw\";\n }\n return \"update\";\n}\n"],
|
|
5
|
+
"mappings": "AAkBA,MAAM,2BAAoE;AAAA,EACxE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,oBAAoB;AAAA,EAClC;AAAA,EACA;AACF,GAGkB;AAChB,QAAM,aAAa,yBAAyB;AAAA,IAC1C,CAAC,aAAa,KAAK,QAAQ;AAAA,EAC7B;AAEA,MAAI,SAAS,cAAc,MAAM;AAC/B,WAAO,aAAa,WAAW;AAAA,EACjC;AACA,MAAI,CAAC,YAAY;AACf,WAAO;AAAA,EACT;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ConsentAction, ConsentMode } from "../_vendor/schemas/generated/consent";
|
|
2
|
+
import type { ConsentCategories } from "./cookie";
|
|
3
|
+
/**
|
|
4
|
+
* Records a proof-of-consent decision by forwarding it to analytics-fire.
|
|
5
|
+
*
|
|
6
|
+
* Runs server-side — exactly like the cart's actions — so the browser never needs
|
|
7
|
+
* the project id or the analytics-fire URL: both are read from the worker env
|
|
8
|
+
* here via `getEnv()`. The visitor's user-agent / referrer / coarse geo come from
|
|
9
|
+
* the incoming request headers and are forwarded so analytics-fire derives them
|
|
10
|
+
* the same way it does for the legacy pixel.
|
|
11
|
+
*
|
|
12
|
+
* Best-effort and self-disabling: no-ops when analytics-fire isn't configured
|
|
13
|
+
* (e.g. lean local dev) and never throws into the page.
|
|
14
|
+
*/
|
|
15
|
+
export declare function recordConsentAction(decision: {
|
|
16
|
+
consentId: string;
|
|
17
|
+
action: ConsentAction;
|
|
18
|
+
/** Full resulting consent state (all categories), not a diff. */
|
|
19
|
+
categories: ConsentCategories;
|
|
20
|
+
consentMode: ConsentMode;
|
|
21
|
+
decidedAt: number;
|
|
22
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
import { headers } from "next/headers";
|
|
3
|
+
import { getEnv } from "../env";
|
|
4
|
+
const CONSENT_POLICY_VERSION = 1;
|
|
5
|
+
async function recordConsentAction(decision) {
|
|
6
|
+
try {
|
|
7
|
+
const { PROJECT_ID, ANALYTICS_FIRE_API_URL } = await getEnv();
|
|
8
|
+
if (!ANALYTICS_FIRE_API_URL) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const incoming = await headers();
|
|
12
|
+
const body = {
|
|
13
|
+
consentId: decision.consentId,
|
|
14
|
+
projectId: PROJECT_ID,
|
|
15
|
+
decidedAt: decision.decidedAt,
|
|
16
|
+
action: decision.action,
|
|
17
|
+
categories: decision.categories,
|
|
18
|
+
consentMode: decision.consentMode,
|
|
19
|
+
policyVersion: CONSENT_POLICY_VERSION
|
|
20
|
+
};
|
|
21
|
+
await fetch(`${ANALYTICS_FIRE_API_URL}/api/v1/consent`, {
|
|
22
|
+
method: "POST",
|
|
23
|
+
headers: {
|
|
24
|
+
"content-type": "application/json",
|
|
25
|
+
"user-agent": incoming.get("user-agent") ?? "",
|
|
26
|
+
referer: incoming.get("referer") ?? "",
|
|
27
|
+
"cf-ipcountry": incoming.get("cf-ipcountry") ?? ""
|
|
28
|
+
},
|
|
29
|
+
body: JSON.stringify(body)
|
|
30
|
+
});
|
|
31
|
+
} catch {
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
recordConsentAction
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=consent-actions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../consent/consent-actions.ts"],
|
|
4
|
+
"sourcesContent": ["\"use server\";\n\nimport type {\n ConsentAction,\n ConsentMode,\n ConsentRecordRequest,\n} from \"schemas/generated/consent\";\nimport type { ConsentCategories } from \"./cookie\";\n\nimport { headers } from \"next/headers\";\n\nimport { getEnv } from \"../env\";\n\n// Bumped when the banner copy or category set changes. Lives here (server-side)\n// so the site layout never has to carry a policy version.\nconst CONSENT_POLICY_VERSION = 1;\n\n/**\n * Records a proof-of-consent decision by forwarding it to analytics-fire.\n *\n * Runs server-side \u2014 exactly like the cart's actions \u2014 so the browser never needs\n * the project id or the analytics-fire URL: both are read from the worker env\n * here via `getEnv()`. The visitor's user-agent / referrer / coarse geo come from\n * the incoming request headers and are forwarded so analytics-fire derives them\n * the same way it does for the legacy pixel.\n *\n * Best-effort and self-disabling: no-ops when analytics-fire isn't configured\n * (e.g. lean local dev) and never throws into the page.\n */\nexport async function recordConsentAction(decision: {\n consentId: string;\n action: ConsentAction;\n /** Full resulting consent state (all categories), not a diff. */\n categories: ConsentCategories;\n consentMode: ConsentMode;\n decidedAt: number;\n}) {\n // Best-effort and total: never reject (the caller fire-and-forgets it), even if\n // the Cloudflare env / request context is unavailable.\n try {\n const { PROJECT_ID, ANALYTICS_FIRE_API_URL } = await getEnv();\n if (!ANALYTICS_FIRE_API_URL) {\n return;\n }\n\n const incoming = await headers();\n const body: ConsentRecordRequest = {\n consentId: decision.consentId,\n projectId: PROJECT_ID,\n decidedAt: decision.decidedAt,\n action: decision.action,\n categories: decision.categories,\n consentMode: decision.consentMode,\n policyVersion: CONSENT_POLICY_VERSION,\n };\n\n await fetch(`${ANALYTICS_FIRE_API_URL}/api/v1/consent`, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n \"user-agent\": incoming.get(\"user-agent\") ?? \"\",\n referer: incoming.get(\"referer\") ?? \"\",\n \"cf-ipcountry\": incoming.get(\"cf-ipcountry\") ?? \"\",\n },\n body: JSON.stringify(body),\n });\n } catch {\n // Consent logging must never surface an error in the page.\n }\n}\n"],
|
|
5
|
+
"mappings": ";AASA,SAAS,eAAe;AAExB,SAAS,cAAc;AAIvB,MAAM,yBAAyB;AAc/B,eAAsB,oBAAoB,UAOvC;AAGD,MAAI;AACF,UAAM,EAAE,YAAY,uBAAuB,IAAI,MAAM,OAAO;AAC5D,QAAI,CAAC,wBAAwB;AAC3B;AAAA,IACF;AAEA,UAAM,WAAW,MAAM,QAAQ;AAC/B,UAAM,OAA6B;AAAA,MACjC,WAAW,SAAS;AAAA,MACpB,WAAW;AAAA,MACX,WAAW,SAAS;AAAA,MACpB,QAAQ,SAAS;AAAA,MACjB,YAAY,SAAS;AAAA,MACrB,aAAa,SAAS;AAAA,MACtB,eAAe;AAAA,IACjB;AAEA,UAAM,MAAM,GAAG,sBAAsB,mBAAmB;AAAA,MACtD,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,cAAc,SAAS,IAAI,YAAY,KAAK;AAAA,QAC5C,SAAS,SAAS,IAAI,SAAS,KAAK;AAAA,QACpC,gBAAgB,SAAS,IAAI,cAAc,KAAK;AAAA,MAClD;AAAA,MACA,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B,CAAC;AAAA,EACH,QAAQ;AAAA,EAER;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ConsentCategory, ConsentMode } from "../_vendor/schemas/generated/consent";
|
|
2
|
-
import type { ConsentCategories
|
|
2
|
+
import type { ConsentCategories } from "./cookie";
|
|
3
3
|
/**
|
|
4
4
|
* Framework-agnostic, cookie-backed consent store. Lives as a single module
|
|
5
5
|
* singleton so `ReploScripts`, the site's consent banner, and `AnalyticsProvider`
|
|
@@ -8,19 +8,21 @@ import type { ConsentCategories, ConsentSeed } from "./cookie";
|
|
|
8
8
|
*
|
|
9
9
|
* Consent-dependent work (script injection, banner visibility) happens on the
|
|
10
10
|
* client (effects / post-mount), so there is no SSR/hydration mismatch. The
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* client reads the (non-httpOnly) consent cookie directly, so no server seed is
|
|
12
|
+
* needed. The whole-site `mode` comes from the `data-replo-consent-mode`
|
|
13
|
+
* attribute on `<html>`.
|
|
13
14
|
*/
|
|
14
15
|
export interface ConsentState {
|
|
15
16
|
mode: ConsentMode;
|
|
16
17
|
categories: ConsentCategories;
|
|
17
18
|
/** Epoch ms when the visitor last made a choice, or null if undecided. */
|
|
18
19
|
decidedAt: number | null;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Persistent pseudonymous per-browser id linking a visitor's consent history.
|
|
22
|
+
* Absent until the first `commit()` (and on legacy pre-id cookies, until the
|
|
23
|
+
* next interaction lazily backfills it).
|
|
24
|
+
*/
|
|
25
|
+
consentId?: string;
|
|
24
26
|
}
|
|
25
27
|
export declare const consentStore: {
|
|
26
28
|
getSnapshot(): ConsentState;
|
package/consent/consent-store.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useSyncExternalStore } from "react";
|
|
3
|
+
import { deriveConsentAction } from "./consent-action";
|
|
4
|
+
import { recordConsentAction } from "./consent-actions";
|
|
3
5
|
import {
|
|
4
6
|
CONSENT_COOKIE_MAX_AGE_SECONDS,
|
|
5
7
|
CONSENT_COOKIE_NAME,
|
|
@@ -28,10 +30,6 @@ function resolveMode() {
|
|
|
28
30
|
if (typeof window === "undefined") {
|
|
29
31
|
return "off";
|
|
30
32
|
}
|
|
31
|
-
const seedMode = window.__REPLO_CONSENT__?.mode;
|
|
32
|
-
if (isConsentMode(seedMode)) {
|
|
33
|
-
return seedMode;
|
|
34
|
-
}
|
|
35
33
|
const attribute = document.documentElement.dataset.reploConsentMode;
|
|
36
34
|
return isConsentMode(attribute) ? attribute : "off";
|
|
37
35
|
}
|
|
@@ -51,24 +49,21 @@ function computeSnapshot() {
|
|
|
51
49
|
preferences: fromCookie.categories.preferences,
|
|
52
50
|
sale_of_data: fromCookie.categories.sale_of_data
|
|
53
51
|
},
|
|
54
|
-
decidedAt: fromCookie.decidedAt
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
const seed = window.__REPLO_CONSENT__;
|
|
58
|
-
if (seed) {
|
|
59
|
-
return {
|
|
60
|
-
mode,
|
|
61
|
-
categories: { ...DENIED_CATEGORIES, ...seed.categories, necessary: true },
|
|
62
|
-
decidedAt: seed.decidedAt
|
|
52
|
+
decidedAt: fromCookie.decidedAt,
|
|
53
|
+
consentId: fromCookie.consentId
|
|
63
54
|
};
|
|
64
55
|
}
|
|
65
56
|
return { mode, categories: DENIED_CATEGORIES, decidedAt: null };
|
|
66
57
|
}
|
|
67
|
-
function writeCookie(categories, decidedAt) {
|
|
58
|
+
function writeCookie(categories, decidedAt, consentId) {
|
|
68
59
|
if (typeof document === "undefined") {
|
|
69
60
|
return;
|
|
70
61
|
}
|
|
71
|
-
const value = serializeConsentCookieValue({
|
|
62
|
+
const value = serializeConsentCookieValue({
|
|
63
|
+
categories,
|
|
64
|
+
decidedAt,
|
|
65
|
+
consentId
|
|
66
|
+
});
|
|
72
67
|
document.cookie = `${CONSENT_COOKIE_NAME}=${value}; path=/; max-age=${CONSENT_COOKIE_MAX_AGE_SECONDS}; SameSite=Lax`;
|
|
73
68
|
}
|
|
74
69
|
function notify() {
|
|
@@ -79,18 +74,37 @@ function notify() {
|
|
|
79
74
|
function commit(categories) {
|
|
80
75
|
const previous = consentStore.getSnapshot();
|
|
81
76
|
const decidedAt = Date.now();
|
|
82
|
-
|
|
77
|
+
const consentId = previous.consentId ?? crypto.randomUUID();
|
|
78
|
+
const resultingCategories = {
|
|
79
|
+
...categories,
|
|
80
|
+
necessary: true
|
|
81
|
+
};
|
|
82
|
+
writeCookie(categories, decidedAt, consentId);
|
|
83
83
|
snapshot = {
|
|
84
84
|
mode: previous.mode,
|
|
85
|
-
categories:
|
|
86
|
-
decidedAt
|
|
85
|
+
categories: resultingCategories,
|
|
86
|
+
decidedAt,
|
|
87
|
+
consentId
|
|
87
88
|
};
|
|
88
89
|
notify();
|
|
89
90
|
const wasDowngrade = previous.decidedAt !== null && TOGGLEABLE_CATEGORIES.some((category) => {
|
|
90
91
|
return previous.categories[category] && !categories[category];
|
|
91
92
|
});
|
|
92
|
-
|
|
93
|
-
window
|
|
93
|
+
const reloadIfDowngraded = () => {
|
|
94
|
+
if (wasDowngrade && typeof window !== "undefined") {
|
|
95
|
+
window.location.reload();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
if (previous.mode !== "off") {
|
|
99
|
+
void recordConsentAction({
|
|
100
|
+
consentId,
|
|
101
|
+
action: deriveConsentAction({ previous, next: resultingCategories }),
|
|
102
|
+
categories: resultingCategories,
|
|
103
|
+
consentMode: previous.mode,
|
|
104
|
+
decidedAt
|
|
105
|
+
}).finally(reloadIfDowngraded);
|
|
106
|
+
} else {
|
|
107
|
+
reloadIfDowngraded();
|
|
94
108
|
}
|
|
95
109
|
}
|
|
96
110
|
const consentStore = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../consent/consent-store.ts"],
|
|
4
|
-
"sourcesContent": ["\"use client\";\n\nimport type { ConsentCategory, ConsentMode } from \"schemas/generated/consent\";\nimport type { ConsentCategories
|
|
5
|
-
"mappings": ";AAKA,SAAS,4BAA4B;AAErC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { ConsentCategory, ConsentMode } from \"schemas/generated/consent\";\nimport type { ConsentCategories } from \"./cookie\";\n\nimport { useSyncExternalStore } from \"react\";\n\nimport { deriveConsentAction } from \"./consent-action\";\nimport { recordConsentAction } from \"./consent-actions\";\nimport {\n CONSENT_COOKIE_MAX_AGE_SECONDS,\n CONSENT_COOKIE_NAME,\n DENIED_CATEGORIES,\n GRANTED_CATEGORIES,\n parseConsentCookie,\n serializeConsentCookieValue,\n} from \"./cookie\";\n\n/**\n * Framework-agnostic, cookie-backed consent store. Lives as a single module\n * singleton so `ReploScripts`, the site's consent banner, and `AnalyticsProvider`\n * all share the same state regardless of where they sit in the React tree \u2014 no\n * provider-ancestor relationship is required.\n *\n * Consent-dependent work (script injection, banner visibility) happens on the\n * client (effects / post-mount), so there is no SSR/hydration mismatch. The\n * client reads the (non-httpOnly) consent cookie directly, so no server seed is\n * needed. The whole-site `mode` comes from the `data-replo-consent-mode`\n * attribute on `<html>`.\n */\n\nexport interface ConsentState {\n mode: ConsentMode;\n categories: ConsentCategories;\n /** Epoch ms when the visitor last made a choice, or null if undecided. */\n decidedAt: number | null;\n /**\n * Persistent pseudonymous per-browser id linking a visitor's consent history.\n * Absent until the first `commit()` (and on legacy pre-id cookies, until the\n * next interaction lazily backfills it).\n */\n consentId?: string;\n}\n\n// The non-necessary categories a visitor can grant or revoke. `necessary` is\n// always granted and never toggled.\nconst TOGGLEABLE_CATEGORIES: Exclude<ConsentCategory, \"necessary\">[] = [\n \"analytics\",\n \"marketing\",\n \"preferences\",\n \"sale_of_data\",\n];\n\n// A stable reference for SSR / first hydration render. Consent-dependent DOM is\n// only produced on the client, so this constant never causes a mismatch.\nconst SERVER_SNAPSHOT: ConsentState = Object.freeze({\n mode: \"off\",\n categories: DENIED_CATEGORIES,\n decidedAt: null,\n});\n\nconst listeners = new Set<() => void>();\nlet snapshot: ConsentState | null = null;\n\nfunction isConsentMode(value: string | null | undefined): value is ConsentMode {\n return value === \"off\" || value === \"simple\" || value === \"per-category\";\n}\n\nfunction resolveMode(): ConsentMode {\n if (typeof window === \"undefined\") {\n return \"off\";\n }\n const attribute = document.documentElement.dataset.reploConsentMode;\n return isConsentMode(attribute) ? attribute : \"off\";\n}\n\nfunction computeSnapshot(): ConsentState {\n if (typeof window === \"undefined\") {\n return SERVER_SNAPSHOT;\n }\n\n const mode = resolveMode();\n\n const fromCookie = parseConsentCookie(document.cookie);\n if (fromCookie) {\n return {\n mode,\n categories: {\n necessary: true,\n analytics: fromCookie.categories.analytics,\n marketing: fromCookie.categories.marketing,\n preferences: fromCookie.categories.preferences,\n sale_of_data: fromCookie.categories.sale_of_data,\n },\n decidedAt: fromCookie.decidedAt,\n consentId: fromCookie.consentId,\n };\n }\n\n return { mode, categories: DENIED_CATEGORIES, decidedAt: null };\n}\n\nfunction writeCookie(\n categories: ConsentCategories,\n decidedAt: number,\n consentId: string,\n) {\n if (typeof document === \"undefined\") {\n return;\n }\n const value = serializeConsentCookieValue({\n categories,\n decidedAt,\n consentId,\n });\n document.cookie = `${CONSENT_COOKIE_NAME}=${value}; path=/; max-age=${CONSENT_COOKIE_MAX_AGE_SECONDS}; SameSite=Lax`;\n}\n\nfunction notify() {\n for (const listener of listeners) {\n listener();\n }\n}\n\nfunction commit(categories: ConsentCategories) {\n const previous = consentStore.getSnapshot();\n const decidedAt = Date.now();\n // Reuse the visitor's existing id, or mint one on the first decision (also\n // lazily backfills legacy pre-id cookies). `crypto.randomUUID` is available in\n // every browser we target and on the server (where commit() never runs).\n const consentId = previous.consentId ?? crypto.randomUUID();\n const resultingCategories: ConsentCategories = {\n ...categories,\n necessary: true,\n };\n writeCookie(categories, decidedAt, consentId);\n snapshot = {\n mode: previous.mode,\n categories: resultingCategories,\n decidedAt,\n consentId,\n };\n notify();\n\n // Revocation cannot unload an already-loaded vendor. If the visitor had\n // previously decided and is now turning a granted category off, reload so the\n // page renders without those scripts. Deferred until after the audit record is\n // sent so the reload doesn't cancel the in-flight server action.\n const wasDowngrade =\n previous.decidedAt !== null &&\n TOGGLEABLE_CATEGORIES.some((category) => {\n return previous.categories[category] && !categories[category];\n });\n const reloadIfDowngraded = () => {\n if (wasDowngrade && typeof window !== \"undefined\") {\n window.location.reload();\n }\n };\n\n // Proof-of-consent audit record (ungated by consent, but only on managed\n // sites). On `mode === \"off\"` there is no banner/consent UX, so a\n // `setTrackingConsent()` call from a third-party script would only produce\n // meaningless `consent_mode: \"off\"` noise \u2014 skip it. Egress runs through a\n // server action (like the cart) so the client never needs the project id or\n // analytics-fire URL.\n if (previous.mode !== \"off\") {\n void recordConsentAction({\n consentId,\n action: deriveConsentAction({ previous, next: resultingCategories }),\n categories: resultingCategories,\n consentMode: previous.mode,\n decidedAt,\n }).finally(reloadIfDowngraded);\n } else {\n reloadIfDowngraded();\n }\n}\n\nexport const consentStore = {\n getSnapshot(): ConsentState {\n if (!snapshot) {\n snapshot = computeSnapshot();\n }\n return snapshot;\n },\n getServerSnapshot(): ConsentState {\n return SERVER_SNAPSHOT;\n },\n subscribe(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n /** Grant every consent category. */\n accept() {\n commit(GRANTED_CATEGORIES);\n },\n /** Deny every non-necessary category. */\n reject() {\n commit(DENIED_CATEGORIES);\n },\n /** Set a subset of categories, leaving the rest at their current value. */\n updateCategories(next: Partial<ConsentCategories>) {\n const current = consentStore.getSnapshot().categories;\n commit({ ...current, ...next, necessary: true });\n },\n /** Test-only: reset cached state so the next read recomputes. */\n reset() {\n snapshot = null;\n },\n};\n\nexport interface UseConsentResult extends ConsentState {\n accept(): void;\n reject(): void;\n updateCategories(next: Partial<ConsentCategories>): void;\n}\n\nexport function useConsent(): UseConsentResult {\n const state = useSyncExternalStore(\n consentStore.subscribe,\n consentStore.getSnapshot,\n consentStore.getServerSnapshot,\n );\n return {\n ...state,\n accept: consentStore.accept,\n reject: consentStore.reject,\n updateCategories: consentStore.updateCategories,\n };\n}\n\n/**\n * Whether a script requiring `requiredConsent` is allowed to load right now.\n * `mode === \"off\"` always allows; otherwise every required category must be\n * granted. An empty requirement list is always allowed.\n */\nexport function isConsentAllowed({\n state,\n requiredConsent,\n}: {\n state: ConsentState;\n requiredConsent: ConsentCategory[];\n}): boolean {\n if (state.mode === \"off\") {\n return true;\n }\n if (requiredConsent.length === 0) {\n return true;\n }\n return requiredConsent.every((category) => state.categories[category]);\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/consent/cookie.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ConsentCategory
|
|
1
|
+
import type { ConsentCategory } from "../_vendor/schemas/generated/consent";
|
|
2
2
|
/**
|
|
3
|
-
* Pure (non-React, framework-agnostic) consent cookie helpers
|
|
4
|
-
*
|
|
3
|
+
* Pure (non-React, framework-agnostic) consent cookie helpers used by the client
|
|
4
|
+
* store (`consent-store.ts`).
|
|
5
5
|
*/
|
|
6
6
|
export declare const CONSENT_COOKIE_NAME = "replo_consent";
|
|
7
7
|
export declare const CONSENT_COOKIE_VERSION = 1;
|
|
@@ -11,6 +11,8 @@ export type ConsentCategories = Record<ConsentCategory, boolean>;
|
|
|
11
11
|
export interface ConsentCookiePayload {
|
|
12
12
|
version: number;
|
|
13
13
|
decidedAt: number;
|
|
14
|
+
/** Persistent pseudonymous per-browser id; absent on pre-id (legacy) cookies. */
|
|
15
|
+
consentId?: string;
|
|
14
16
|
categories: {
|
|
15
17
|
analytics: boolean;
|
|
16
18
|
marketing: boolean;
|
|
@@ -18,11 +20,6 @@ export interface ConsentCookiePayload {
|
|
|
18
20
|
sale_of_data: boolean;
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
|
-
export interface ConsentSeed {
|
|
22
|
-
mode: ConsentMode;
|
|
23
|
-
categories: ConsentCategories;
|
|
24
|
-
decidedAt: number | null;
|
|
25
|
-
}
|
|
26
23
|
export declare const DENIED_CATEGORIES: ConsentCategories;
|
|
27
24
|
export declare const GRANTED_CATEGORIES: ConsentCategories;
|
|
28
25
|
/**
|
|
@@ -32,7 +29,8 @@ export declare const GRANTED_CATEGORIES: ConsentCategories;
|
|
|
32
29
|
*/
|
|
33
30
|
export declare function parseConsentCookie(rawCookie: string | undefined): ConsentCookiePayload | null;
|
|
34
31
|
/** Serialize categories into the JSON-encoded cookie value (not the full Set-Cookie line). */
|
|
35
|
-
export declare function serializeConsentCookieValue({ categories, decidedAt, }: {
|
|
32
|
+
export declare function serializeConsentCookieValue({ categories, decidedAt, consentId, }: {
|
|
36
33
|
categories: ConsentCategories;
|
|
37
34
|
decidedAt: number;
|
|
35
|
+
consentId?: string;
|
|
38
36
|
}): string;
|
package/consent/cookie.js
CHANGED
|
@@ -6,6 +6,7 @@ const CONSENT_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 180;
|
|
|
6
6
|
const persistedCookieSchema = z.object({
|
|
7
7
|
version: z.literal(CONSENT_COOKIE_VERSION),
|
|
8
8
|
decidedAt: z.number().optional(),
|
|
9
|
+
consentId: z.string().optional(),
|
|
9
10
|
categories: z.object({
|
|
10
11
|
analytics: z.unknown().optional(),
|
|
11
12
|
marketing: z.unknown().optional(),
|
|
@@ -43,10 +44,11 @@ function parseConsentCookie(rawCookie) {
|
|
|
43
44
|
if (!result.success) {
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
|
-
const { decidedAt, categories } = result.data;
|
|
47
|
+
const { decidedAt, categories, consentId } = result.data;
|
|
47
48
|
return {
|
|
48
49
|
version: CONSENT_COOKIE_VERSION,
|
|
49
50
|
decidedAt: decidedAt ?? Date.now(),
|
|
51
|
+
consentId,
|
|
50
52
|
categories: {
|
|
51
53
|
analytics: Boolean(categories.analytics),
|
|
52
54
|
marketing: Boolean(categories.marketing),
|
|
@@ -57,11 +59,13 @@ function parseConsentCookie(rawCookie) {
|
|
|
57
59
|
}
|
|
58
60
|
function serializeConsentCookieValue({
|
|
59
61
|
categories,
|
|
60
|
-
decidedAt
|
|
62
|
+
decidedAt,
|
|
63
|
+
consentId
|
|
61
64
|
}) {
|
|
62
65
|
const payload = {
|
|
63
66
|
version: CONSENT_COOKIE_VERSION,
|
|
64
67
|
decidedAt,
|
|
68
|
+
consentId,
|
|
65
69
|
categories: {
|
|
66
70
|
analytics: categories.analytics,
|
|
67
71
|
marketing: categories.marketing,
|
package/consent/cookie.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../consent/cookie.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ConsentCategory
|
|
5
|
-
"mappings": "AAEA,SAAS,uBAAuB;AAChC,SAAS,SAAS;AAOX,MAAM,sBAAsB;AAC5B,MAAM,yBAAyB;AAC/B,MAAM,iCAAiC,KAAK,KAAK,KAAK;
|
|
4
|
+
"sourcesContent": ["import type { ConsentCategory } from \"schemas/generated/consent\";\n\nimport { parseJsonOrNull } from \"replo-utils/lib/json\";\nimport { z } from \"zod\";\n\n/**\n * Pure (non-React, framework-agnostic) consent cookie helpers used by the client\n * store (`consent-store.ts`).\n */\n\nexport const CONSENT_COOKIE_NAME = \"replo_consent\";\nexport const CONSENT_COOKIE_VERSION = 1;\nexport const CONSENT_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 180; // 180 days\n\n// Validates the untrusted JSON cookie payload at the parse boundary. A stale\n// version (or any shape mismatch) fails `safeParse`, so the caller treats the\n// visitor as undecided and re-prompts.\n//\n// `consentId` is OPTIONAL on purpose: it was added after v1 shipped, and we must\n// NOT bump `CONSENT_COOKIE_VERSION` to introduce it. Bumping would fail this\n// `safeParse` for every existing cookie, re-showing the banner and dropping the\n// visitor's prior decision. Optional keeps v1 cookies valid; `commit()` lazily\n// backfills the id on the next interaction.\nconst persistedCookieSchema = z.object({\n version: z.literal(CONSENT_COOKIE_VERSION),\n decidedAt: z.number().optional(),\n consentId: z.string().optional(),\n categories: z.object({\n analytics: z.unknown().optional(),\n marketing: z.unknown().optional(),\n preferences: z.unknown().optional(),\n sale_of_data: z.unknown().optional(),\n }),\n});\n\nexport type ConsentCategories = Record<ConsentCategory, boolean>;\n\n/** Persisted cookie payload. `necessary` is always granted and never stored. */\nexport interface ConsentCookiePayload {\n version: number;\n decidedAt: number;\n /** Persistent pseudonymous per-browser id; absent on pre-id (legacy) cookies. */\n consentId?: string;\n categories: {\n analytics: boolean;\n marketing: boolean;\n preferences: boolean;\n sale_of_data: boolean;\n };\n}\n\nexport const DENIED_CATEGORIES: ConsentCategories = {\n necessary: true,\n analytics: false,\n marketing: false,\n preferences: false,\n sale_of_data: false,\n};\n\nexport const GRANTED_CATEGORIES: ConsentCategories = {\n necessary: true,\n analytics: true,\n marketing: true,\n preferences: true,\n sale_of_data: true,\n};\n\n/**\n * Parse a raw `document.cookie` (or a single cookie value) into a payload.\n * Returns null for missing, malformed, or stale-version cookies so callers\n * treat the visitor as undecided and re-prompt.\n */\nexport function parseConsentCookie(\n rawCookie: string | undefined,\n): ConsentCookiePayload | null {\n if (!rawCookie) {\n return null;\n }\n const match = rawCookie\n .split(\"; \")\n .find((entry) => entry.startsWith(`${CONSENT_COOKIE_NAME}=`));\n const encoded = match\n ? match.slice(CONSENT_COOKIE_NAME.length + 1)\n : rawCookie;\n\n // A tampered/corrupted cookie (bad percent-encoding) must not throw \u2014 that\n // would crash the client snapshot or the server seed read. Treat as undecided.\n let decoded: string;\n try {\n decoded = decodeURIComponent(encoded);\n } catch {\n return null;\n }\n\n const result = persistedCookieSchema.safeParse(parseJsonOrNull(decoded));\n if (!result.success) {\n return null;\n }\n const { decidedAt, categories, consentId } = result.data;\n\n return {\n version: CONSENT_COOKIE_VERSION,\n decidedAt: decidedAt ?? Date.now(),\n consentId,\n categories: {\n analytics: Boolean(categories.analytics),\n marketing: Boolean(categories.marketing),\n preferences: Boolean(categories.preferences),\n sale_of_data: Boolean(categories.sale_of_data),\n },\n };\n}\n\n/** Serialize categories into the JSON-encoded cookie value (not the full Set-Cookie line). */\nexport function serializeConsentCookieValue({\n categories,\n decidedAt,\n consentId,\n}: {\n categories: ConsentCategories;\n decidedAt: number;\n consentId?: string;\n}): string {\n const payload: ConsentCookiePayload = {\n version: CONSENT_COOKIE_VERSION,\n decidedAt,\n consentId,\n categories: {\n analytics: categories.analytics,\n marketing: categories.marketing,\n preferences: categories.preferences,\n sale_of_data: categories.sale_of_data,\n },\n };\n return encodeURIComponent(JSON.stringify(payload));\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,uBAAuB;AAChC,SAAS,SAAS;AAOX,MAAM,sBAAsB;AAC5B,MAAM,yBAAyB;AAC/B,MAAM,iCAAiC,KAAK,KAAK,KAAK;AAW7D,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,SAAS,EAAE,QAAQ,sBAAsB;AAAA,EACzC,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,YAAY,EAAE,OAAO;AAAA,IACnB,WAAW,EAAE,QAAQ,EAAE,SAAS;AAAA,IAChC,WAAW,EAAE,QAAQ,EAAE,SAAS;AAAA,IAChC,aAAa,EAAE,QAAQ,EAAE,SAAS;AAAA,IAClC,cAAc,EAAE,QAAQ,EAAE,SAAS;AAAA,EACrC,CAAC;AACH,CAAC;AAkBM,MAAM,oBAAuC;AAAA,EAClD,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAChB;AAEO,MAAM,qBAAwC;AAAA,EACnD,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAChB;AAOO,SAAS,mBACd,WAC6B;AAC7B,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,UACX,MAAM,IAAI,EACV,KAAK,CAAC,UAAU,MAAM,WAAW,GAAG,mBAAmB,GAAG,CAAC;AAC9D,QAAM,UAAU,QACZ,MAAM,MAAM,oBAAoB,SAAS,CAAC,IAC1C;AAIJ,MAAI;AACJ,MAAI;AACF,cAAU,mBAAmB,OAAO;AAAA,EACtC,QAAQ;AACN,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,sBAAsB,UAAU,gBAAgB,OAAO,CAAC;AACvE,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO;AAAA,EACT;AACA,QAAM,EAAE,WAAW,YAAY,UAAU,IAAI,OAAO;AAEpD,SAAO;AAAA,IACL,SAAS;AAAA,IACT,WAAW,aAAa,KAAK,IAAI;AAAA,IACjC;AAAA,IACA,YAAY;AAAA,MACV,WAAW,QAAQ,WAAW,SAAS;AAAA,MACvC,WAAW,QAAQ,WAAW,SAAS;AAAA,MACvC,aAAa,QAAQ,WAAW,WAAW;AAAA,MAC3C,cAAc,QAAQ,WAAW,YAAY;AAAA,IAC/C;AAAA,EACF;AACF;AAGO,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AACF,GAIW;AACT,QAAM,UAAgC;AAAA,IACpC,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,YAAY;AAAA,MACV,WAAW,WAAW;AAAA,MACtB,WAAW,WAAW;AAAA,MACtB,aAAa,WAAW;AAAA,MACxB,cAAc,WAAW;AAAA,IAC3B;AAAA,EACF;AACA,SAAO,mBAAmB,KAAK,UAAU,OAAO,CAAC;AACnD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,22 +1,57 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
+
import { buildGoogleFontsCssUrl } from "../../_vendor/replo-utils/lib/google-fonts.mjs";
|
|
3
4
|
import { designLibraryPreviewMessageSchema } from "../../_vendor/schemas/designLibrary.mjs";
|
|
5
|
+
const FONT_LINK_DATA_KEY = "reploDesignLibraryFont";
|
|
4
6
|
function DesignLibraryPreview() {
|
|
5
7
|
const ownedKeys = useRef(null);
|
|
8
|
+
const ownedFontLinks = useRef(null);
|
|
9
|
+
const ownsDefaultFont = useRef(false);
|
|
6
10
|
useEffect(() => {
|
|
7
11
|
const handleMessage = (event) => {
|
|
8
12
|
const parsed = designLibraryPreviewMessageSchema.safeParse(event.data);
|
|
9
13
|
if (!parsed.success) return;
|
|
10
|
-
const
|
|
14
|
+
const { cssVars, fonts, defaultFontCssVar } = parsed.data;
|
|
11
15
|
const root = document.documentElement;
|
|
16
|
+
const nextVars = { ...cssVars };
|
|
17
|
+
for (const font of fonts) {
|
|
18
|
+
nextVars[font.cssVar] = `'${font.family}'`;
|
|
19
|
+
}
|
|
12
20
|
const owned = ownedKeys.current ?? /* @__PURE__ */ new Set();
|
|
13
21
|
for (const key of owned) {
|
|
14
|
-
if (!(key in
|
|
22
|
+
if (!(key in nextVars)) root.style.removeProperty(key);
|
|
15
23
|
}
|
|
16
|
-
ownedKeys.current = new Set(Object.keys(
|
|
17
|
-
for (const [key, value] of Object.entries(
|
|
24
|
+
ownedKeys.current = new Set(Object.keys(nextVars));
|
|
25
|
+
for (const [key, value] of Object.entries(nextVars)) {
|
|
18
26
|
root.style.setProperty(key, value);
|
|
19
27
|
}
|
|
28
|
+
const links = ownedFontLinks.current ?? /* @__PURE__ */ new Map();
|
|
29
|
+
const nextHrefs = new Set(
|
|
30
|
+
fonts.map((font) => buildGoogleFontsCssUrl(font.family))
|
|
31
|
+
);
|
|
32
|
+
for (const [href, link] of links) {
|
|
33
|
+
if (!nextHrefs.has(href)) {
|
|
34
|
+
link.remove();
|
|
35
|
+
links.delete(href);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
for (const href of nextHrefs) {
|
|
39
|
+
if (links.has(href)) continue;
|
|
40
|
+
const link = document.createElement("link");
|
|
41
|
+
link.rel = "stylesheet";
|
|
42
|
+
link.href = href;
|
|
43
|
+
link.dataset[FONT_LINK_DATA_KEY] = "";
|
|
44
|
+
document.head.append(link);
|
|
45
|
+
links.set(href, link);
|
|
46
|
+
}
|
|
47
|
+
ownedFontLinks.current = links;
|
|
48
|
+
if (defaultFontCssVar) {
|
|
49
|
+
root.style.setProperty("font-family", `var(${defaultFontCssVar})`);
|
|
50
|
+
ownsDefaultFont.current = true;
|
|
51
|
+
} else if (ownsDefaultFont.current) {
|
|
52
|
+
root.style.removeProperty("font-family");
|
|
53
|
+
ownsDefaultFont.current = false;
|
|
54
|
+
}
|
|
20
55
|
};
|
|
21
56
|
window.addEventListener("message", handleMessage);
|
|
22
57
|
return () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../editor/design-library-preview/DesignLibraryPreview.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nimport { designLibraryPreviewMessageSchema } from \"schemas/designLibrary\";\n\nexport function DesignLibraryPreview() {\n // NOTE (Ben, 2026-06-03): The custom-property keys we set last time, so on the\n // next message we remove only the ones we own that the new override set drops.\n const ownedKeys = useRef<Set<string> | null>(null);\n\n // eslint-disable-next-line replo/no-use-effect -- Subscribes to window message events from the parent editor.\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n const parsed = designLibraryPreviewMessageSchema.safeParse(event.data);\n if (!parsed.success) return;\n const
|
|
5
|
-
"mappings": ";AAEA,SAAS,WAAW,cAAc;AAElC,SAAS,yCAAyC;
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nimport { buildGoogleFontsCssUrl } from \"replo-utils/lib/google-fonts\";\nimport { designLibraryPreviewMessageSchema } from \"schemas/designLibrary\";\n\nconst FONT_LINK_DATA_KEY = \"reploDesignLibraryFont\";\n\nexport function DesignLibraryPreview() {\n // NOTE (Ben, 2026-06-03): The custom-property keys we set last time, so on the\n // next message we remove only the ones we own that the new override set drops.\n const ownedKeys = useRef<Set<string> | null>(null);\n // NOTE (Ben, 2026-06-05): The Google Font <link> hrefs we injected, keyed by\n // href so we de-dupe and remove only our own when the override set changes.\n const ownedFontLinks = useRef<Map<string, HTMLLinkElement> | null>(null);\n // NOTE (Ben, 2026-06-05): Whether we set the document default font-family, so\n // we can clear just that.\n const ownsDefaultFont = useRef(false);\n\n // eslint-disable-next-line replo/no-use-effect -- Subscribes to window message events from the parent editor.\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n const parsed = designLibraryPreviewMessageSchema.safeParse(event.data);\n if (!parsed.success) return;\n const { cssVars, fonts, defaultFontCssVar } = parsed.data;\n const root = document.documentElement;\n\n // --- CSS variable overrides (colors + font role vars) ---\n const nextVars: Record<string, string> = { ...cssVars };\n for (const font of fonts) {\n nextVars[font.cssVar] = `'${font.family}'`;\n }\n const owned = ownedKeys.current ?? new Set();\n for (const key of owned) {\n if (!(key in nextVars)) root.style.removeProperty(key);\n }\n ownedKeys.current = new Set(Object.keys(nextVars));\n for (const [key, value] of Object.entries(nextVars)) {\n root.style.setProperty(key, value);\n }\n\n // --- Google Font stylesheets ---\n const links = ownedFontLinks.current ?? new Map();\n const nextHrefs = new Set(\n fonts.map((font) => buildGoogleFontsCssUrl(font.family)),\n );\n for (const [href, link] of links) {\n if (!nextHrefs.has(href)) {\n link.remove();\n links.delete(href);\n }\n }\n for (const href of nextHrefs) {\n if (links.has(href)) continue;\n const link = document.createElement(\"link\");\n link.rel = \"stylesheet\";\n link.href = href;\n link.dataset[FONT_LINK_DATA_KEY] = \"\";\n document.head.append(link);\n links.set(href, link);\n }\n ownedFontLinks.current = links;\n\n // --- Document default font ---\n if (defaultFontCssVar) {\n root.style.setProperty(\"font-family\", `var(${defaultFontCssVar})`);\n ownsDefaultFont.current = true;\n } else if (ownsDefaultFont.current) {\n root.style.removeProperty(\"font-family\");\n ownsDefaultFont.current = false;\n }\n };\n window.addEventListener(\"message\", handleMessage);\n return () => {\n window.removeEventListener(\"message\", handleMessage);\n };\n }, []);\n\n return null;\n}\n"],
|
|
5
|
+
"mappings": ";AAEA,SAAS,WAAW,cAAc;AAElC,SAAS,8BAA8B;AACvC,SAAS,yCAAyC;AAElD,MAAM,qBAAqB;AAEpB,SAAS,uBAAuB;AAGrC,QAAM,YAAY,OAA2B,IAAI;AAGjD,QAAM,iBAAiB,OAA4C,IAAI;AAGvE,QAAM,kBAAkB,OAAO,KAAK;AAGpC,YAAU,MAAM;AACd,UAAM,gBAAgB,CAAC,UAAwB;AAC7C,YAAM,SAAS,kCAAkC,UAAU,MAAM,IAAI;AACrE,UAAI,CAAC,OAAO,QAAS;AACrB,YAAM,EAAE,SAAS,OAAO,kBAAkB,IAAI,OAAO;AACrD,YAAM,OAAO,SAAS;AAGtB,YAAM,WAAmC,EAAE,GAAG,QAAQ;AACtD,iBAAW,QAAQ,OAAO;AACxB,iBAAS,KAAK,MAAM,IAAI,IAAI,KAAK,MAAM;AAAA,MACzC;AACA,YAAM,QAAQ,UAAU,WAAW,oBAAI,IAAI;AAC3C,iBAAW,OAAO,OAAO;AACvB,YAAI,EAAE,OAAO,UAAW,MAAK,MAAM,eAAe,GAAG;AAAA,MACvD;AACA,gBAAU,UAAU,IAAI,IAAI,OAAO,KAAK,QAAQ,CAAC;AACjD,iBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,QAAQ,GAAG;AACnD,aAAK,MAAM,YAAY,KAAK,KAAK;AAAA,MACnC;AAGA,YAAM,QAAQ,eAAe,WAAW,oBAAI,IAAI;AAChD,YAAM,YAAY,IAAI;AAAA,QACpB,MAAM,IAAI,CAAC,SAAS,uBAAuB,KAAK,MAAM,CAAC;AAAA,MACzD;AACA,iBAAW,CAAC,MAAM,IAAI,KAAK,OAAO;AAChC,YAAI,CAAC,UAAU,IAAI,IAAI,GAAG;AACxB,eAAK,OAAO;AACZ,gBAAM,OAAO,IAAI;AAAA,QACnB;AAAA,MACF;AACA,iBAAW,QAAQ,WAAW;AAC5B,YAAI,MAAM,IAAI,IAAI,EAAG;AACrB,cAAM,OAAO,SAAS,cAAc,MAAM;AAC1C,aAAK,MAAM;AACX,aAAK,OAAO;AACZ,aAAK,QAAQ,kBAAkB,IAAI;AACnC,iBAAS,KAAK,OAAO,IAAI;AACzB,cAAM,IAAI,MAAM,IAAI;AAAA,MACtB;AACA,qBAAe,UAAU;AAGzB,UAAI,mBAAmB;AACrB,aAAK,MAAM,YAAY,eAAe,OAAO,iBAAiB,GAAG;AACjE,wBAAgB,UAAU;AAAA,MAC5B,WAAW,gBAAgB,SAAS;AAClC,aAAK,MAAM,eAAe,aAAa;AACvC,wBAAgB,UAAU;AAAA,MAC5B;AAAA,IACF;AACA,WAAO,iBAAiB,WAAW,aAAa;AAChD,WAAO,MAAM;AACX,aAAO,oBAAoB,WAAW,aAAa;AAAA,IACrD;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/env.d.ts
CHANGED
package/env.js
CHANGED
|
@@ -3,6 +3,7 @@ import { z } from "zod";
|
|
|
3
3
|
const envSchema = z.object({
|
|
4
4
|
CANOPY_API_HOST: z.string().min(1),
|
|
5
5
|
PROJECT_ID: z.string().uuid(),
|
|
6
|
+
ANALYTICS_FIRE_API_URL: z.string().optional(),
|
|
6
7
|
SHOPIFY_URL: z.string().optional(),
|
|
7
8
|
SHOPIFY_STOREFRONT_ACCESS_TOKEN: z.string().nullable().optional(),
|
|
8
9
|
STRIPE_CONNECT_ACCOUNT_ID: z.string().nullable().optional(),
|
package/env.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../env.ts"],
|
|
4
|
-
"sourcesContent": ["import { getCloudflareContext } from \"@opennextjs/cloudflare\";\nimport { z } from \"zod\";\n\ntype Env = {\n CANOPY_API_HOST: string;\n PROJECT_ID: string;\n\n // NOTE (Gabe 2025-06-26): If there's no Shopify integration these will be\n // undefined.\n SHOPIFY_URL?: string;\n // NOTE (Gabe 2025-06-26): Even if there's an integration, if we haven't been\n // given elevated scope this may be null.\n SHOPIFY_STOREFRONT_ACCESS_TOKEN?: string | null;\n STRIPE_CONNECT_ACCOUNT_ID?: string | null;\n CHECKOUT_PROVIDER?: \"shopify\" | \"stripe\" | \"none\";\n\n REPLO_INTERNAL_REVALIDATE_SECRET?: string;\n /** Shared secret sent in X-Replo-Resolver-Auth for server-to-server cart calls. */\n CART_AUTH_SECRET?: string;\n};\n\nconst envSchema = z.object({\n CANOPY_API_HOST: z.string().min(1),\n PROJECT_ID: z.string().uuid(),\n SHOPIFY_URL: z.string().optional(),\n SHOPIFY_STOREFRONT_ACCESS_TOKEN: z.string().nullable().optional(),\n STRIPE_CONNECT_ACCOUNT_ID: z.string().nullable().optional(),\n CHECKOUT_PROVIDER: z.enum([\"shopify\", \"stripe\", \"none\"]).optional(),\n REPLO_INTERNAL_REVALIDATE_SECRET: z.string().optional(),\n CART_AUTH_SECRET: z.string().optional(),\n});\n\nexport const getEnv = async (): Promise<Env> => {\n const { env } = await getCloudflareContext({ async: true });\n return envSchema.parse(env);\n};\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,4BAA4B;AACrC,SAAS,SAAS;
|
|
4
|
+
"sourcesContent": ["import { getCloudflareContext } from \"@opennextjs/cloudflare\";\nimport { z } from \"zod\";\n\ntype Env = {\n CANOPY_API_HOST: string;\n PROJECT_ID: string;\n\n // Base URL of analytics-fire (e.g. https://data.replo.app). Read server-side by\n // the consent action (`consent/consent-actions.ts`) to forward proof-of-consent\n // records. Optional: absent in environments where the audit pipeline isn't\n // wired (e.g. local dev), where consent recording simply no-ops.\n ANALYTICS_FIRE_API_URL?: string;\n\n // NOTE (Gabe 2025-06-26): If there's no Shopify integration these will be\n // undefined.\n SHOPIFY_URL?: string;\n // NOTE (Gabe 2025-06-26): Even if there's an integration, if we haven't been\n // given elevated scope this may be null.\n SHOPIFY_STOREFRONT_ACCESS_TOKEN?: string | null;\n STRIPE_CONNECT_ACCOUNT_ID?: string | null;\n CHECKOUT_PROVIDER?: \"shopify\" | \"stripe\" | \"none\";\n\n REPLO_INTERNAL_REVALIDATE_SECRET?: string;\n /** Shared secret sent in X-Replo-Resolver-Auth for server-to-server cart calls. */\n CART_AUTH_SECRET?: string;\n};\n\nconst envSchema = z.object({\n CANOPY_API_HOST: z.string().min(1),\n PROJECT_ID: z.string().uuid(),\n ANALYTICS_FIRE_API_URL: z.string().optional(),\n SHOPIFY_URL: z.string().optional(),\n SHOPIFY_STOREFRONT_ACCESS_TOKEN: z.string().nullable().optional(),\n STRIPE_CONNECT_ACCOUNT_ID: z.string().nullable().optional(),\n CHECKOUT_PROVIDER: z.enum([\"shopify\", \"stripe\", \"none\"]).optional(),\n REPLO_INTERNAL_REVALIDATE_SECRET: z.string().optional(),\n CART_AUTH_SECRET: z.string().optional(),\n});\n\nexport const getEnv = async (): Promise<Env> => {\n const { env } = await getCloudflareContext({ async: true });\n return envSchema.parse(env);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,4BAA4B;AACrC,SAAS,SAAS;AA0BlB,MAAM,YAAY,EAAE,OAAO;AAAA,EACzB,iBAAiB,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACjC,YAAY,EAAE,OAAO,EAAE,KAAK;AAAA,EAC5B,wBAAwB,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5C,aAAa,EAAE,OAAO,EAAE,SAAS;AAAA,EACjC,iCAAiC,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAChE,2BAA2B,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC1D,mBAAmB,EAAE,KAAK,CAAC,WAAW,UAAU,MAAM,CAAC,EAAE,SAAS;AAAA,EAClE,kCAAkC,EAAE,OAAO,EAAE,SAAS;AAAA,EACtD,kBAAkB,EAAE,OAAO,EAAE,SAAS;AACxC,CAAC;AAEM,MAAM,SAAS,YAA0B;AAC9C,QAAM,EAAE,IAAI,IAAI,MAAM,qBAAqB,EAAE,OAAO,KAAK,CAAC;AAC1D,SAAO,UAAU,MAAM,GAAG;AAC5B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
package/consent/server.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ConsentMode } from "../_vendor/schemas/generated/consent";
|
|
2
|
-
import type { ConsentSeed } from "./cookie";
|
|
3
|
-
/**
|
|
4
|
-
* Server-only: reads the `replo_consent` cookie via `next/headers` so the layout
|
|
5
|
-
* can serialize it into `window.__REPLO_CONSENT__`, letting the client consent
|
|
6
|
-
* store hydrate without a banner flash. `cookies()` is async in Next 15+, so this
|
|
7
|
-
* helper (and the layout that awaits it) must be async.
|
|
8
|
-
*
|
|
9
|
-
* Importing `next/headers` makes this module server-only; do not re-export it from
|
|
10
|
-
* the client `consent` barrel.
|
|
11
|
-
*/
|
|
12
|
-
export declare function readConsentSeed(mode?: ConsentMode): Promise<ConsentSeed>;
|
package/consent/server.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { cookies } from "next/headers";
|
|
2
|
-
import {
|
|
3
|
-
CONSENT_COOKIE_NAME,
|
|
4
|
-
DENIED_CATEGORIES,
|
|
5
|
-
parseConsentCookie
|
|
6
|
-
} from "./cookie";
|
|
7
|
-
async function readConsentSeed(mode = "off") {
|
|
8
|
-
const cookieStore = await cookies();
|
|
9
|
-
const raw = cookieStore.get(CONSENT_COOKIE_NAME)?.value;
|
|
10
|
-
const parsed = parseConsentCookie(raw);
|
|
11
|
-
if (!parsed) {
|
|
12
|
-
return { mode, categories: DENIED_CATEGORIES, decidedAt: null };
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
mode,
|
|
16
|
-
categories: {
|
|
17
|
-
necessary: true,
|
|
18
|
-
analytics: parsed.categories.analytics,
|
|
19
|
-
marketing: parsed.categories.marketing,
|
|
20
|
-
preferences: parsed.categories.preferences,
|
|
21
|
-
sale_of_data: parsed.categories.sale_of_data
|
|
22
|
-
},
|
|
23
|
-
decidedAt: parsed.decidedAt
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
readConsentSeed
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=server.js.map
|
package/consent/server.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../consent/server.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ConsentMode } from \"schemas/generated/consent\";\nimport type { ConsentSeed } from \"./cookie\";\n\nimport { cookies } from \"next/headers\";\n\nimport {\n CONSENT_COOKIE_NAME,\n DENIED_CATEGORIES,\n parseConsentCookie,\n} from \"./cookie\";\n\n/**\n * Server-only: reads the `replo_consent` cookie via `next/headers` so the layout\n * can serialize it into `window.__REPLO_CONSENT__`, letting the client consent\n * store hydrate without a banner flash. `cookies()` is async in Next 15+, so this\n * helper (and the layout that awaits it) must be async.\n *\n * Importing `next/headers` makes this module server-only; do not re-export it from\n * the client `consent` barrel.\n */\nexport async function readConsentSeed(\n mode: ConsentMode = \"off\",\n): Promise<ConsentSeed> {\n const cookieStore = await cookies();\n const raw = cookieStore.get(CONSENT_COOKIE_NAME)?.value;\n const parsed = parseConsentCookie(raw);\n\n if (!parsed) {\n return { mode, categories: DENIED_CATEGORIES, decidedAt: null };\n }\n\n return {\n mode,\n categories: {\n necessary: true,\n analytics: parsed.categories.analytics,\n marketing: parsed.categories.marketing,\n preferences: parsed.categories.preferences,\n sale_of_data: parsed.categories.sale_of_data,\n },\n decidedAt: parsed.decidedAt,\n };\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,eAAe;AAExB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAWP,eAAsB,gBACpB,OAAoB,OACE;AACtB,QAAM,cAAc,MAAM,QAAQ;AAClC,QAAM,MAAM,YAAY,IAAI,mBAAmB,GAAG;AAClD,QAAM,SAAS,mBAAmB,GAAG;AAErC,MAAI,CAAC,QAAQ;AACX,WAAO,EAAE,MAAM,YAAY,mBAAmB,WAAW,KAAK;AAAA,EAChE;AAEA,SAAO;AAAA,IACL;AAAA,IACA,YAAY;AAAA,MACV,WAAW;AAAA,MACX,WAAW,OAAO,WAAW;AAAA,MAC7B,WAAW,OAAO,WAAW;AAAA,MAC7B,aAAa,OAAO,WAAW;AAAA,MAC/B,cAAc,OAAO,WAAW;AAAA,IAClC;AAAA,IACA,WAAW,OAAO;AAAA,EACpB;AACF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|