@replohq/canopy-sdk 0.1.0 → 0.1.2
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/json.mjs +2 -0
- package/_vendor/replo-utils/lib/misc.d.ts +2 -0
- package/_vendor/replo-utils/lib/misc.mjs +2 -1
- package/_vendor/schemas/errors.mjs +2 -1
- package/_vendor/schemas/generated/consent.d.ts +24 -0
- package/_vendor/schemas/loaderKeys.mjs +1 -5
- package/_vendor/schemas/selectMode.mjs +3 -10
- package/analytics/analytics-provider.js +28 -29
- package/analytics/analytics-provider.js.map +2 -2
- package/analytics/get-analytics-sinks.d.ts +25 -0
- package/analytics/get-analytics-sinks.js +46 -0
- package/analytics/get-analytics-sinks.js.map +7 -0
- package/chunk-GV5FY7ZZ.mjs +89 -0
- package/chunk-VKO7P3ED.mjs +41 -0
- package/{chunk-INHK6MYI.mjs → chunk-XK2K3263.mjs} +48 -128
- package/consent/consent-store.d.ts +52 -0
- package/consent/consent-store.js +160 -0
- package/consent/consent-store.js.map +7 -0
- package/consent/cookie.d.ts +38 -0
- package/consent/cookie.js +83 -0
- package/consent/cookie.js.map +7 -0
- package/consent/replo-scripts.d.ts +9 -0
- package/consent/replo-scripts.js +91 -0
- package/consent/replo-scripts.js.map +7 -0
- package/consent/script-registration-store.d.ts +25 -0
- package/consent/script-registration-store.js +61 -0
- package/consent/script-registration-store.js.map +7 -0
- package/consent/script-snippets.d.ts +19 -0
- package/consent/script-snippets.js +125 -0
- package/consent/script-snippets.js.map +7 -0
- package/consent/server.d.ts +12 -0
- package/consent/server.js +29 -0
- package/consent/server.js.map +7 -0
- package/consent/window-api.d.ts +41 -0
- package/consent/window-api.js +73 -0
- package/consent/window-api.js.map +7 -0
- package/loaders/prefetch-loaders.d.ts +1 -1
- package/loaders/prefetch-loaders.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { parseJsonOrNull } from "../_vendor/replo-utils/lib/json.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
const CONSENT_COOKIE_NAME = "replo_consent";
|
|
4
|
+
const CONSENT_COOKIE_VERSION = 1;
|
|
5
|
+
const CONSENT_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 180;
|
|
6
|
+
const persistedCookieSchema = z.object({
|
|
7
|
+
version: z.literal(CONSENT_COOKIE_VERSION),
|
|
8
|
+
decidedAt: z.number().optional(),
|
|
9
|
+
categories: z.object({
|
|
10
|
+
analytics: z.unknown().optional(),
|
|
11
|
+
marketing: z.unknown().optional(),
|
|
12
|
+
preferences: z.unknown().optional(),
|
|
13
|
+
sale_of_data: z.unknown().optional()
|
|
14
|
+
})
|
|
15
|
+
});
|
|
16
|
+
const DENIED_CATEGORIES = {
|
|
17
|
+
necessary: true,
|
|
18
|
+
analytics: false,
|
|
19
|
+
marketing: false,
|
|
20
|
+
preferences: false,
|
|
21
|
+
sale_of_data: false
|
|
22
|
+
};
|
|
23
|
+
const GRANTED_CATEGORIES = {
|
|
24
|
+
necessary: true,
|
|
25
|
+
analytics: true,
|
|
26
|
+
marketing: true,
|
|
27
|
+
preferences: true,
|
|
28
|
+
sale_of_data: true
|
|
29
|
+
};
|
|
30
|
+
function parseConsentCookie(rawCookie) {
|
|
31
|
+
if (!rawCookie) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const match = rawCookie.split("; ").find((entry) => entry.startsWith(`${CONSENT_COOKIE_NAME}=`));
|
|
35
|
+
const encoded = match ? match.slice(CONSENT_COOKIE_NAME.length + 1) : rawCookie;
|
|
36
|
+
let decoded;
|
|
37
|
+
try {
|
|
38
|
+
decoded = decodeURIComponent(encoded);
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const result = persistedCookieSchema.safeParse(parseJsonOrNull(decoded));
|
|
43
|
+
if (!result.success) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const { decidedAt, categories } = result.data;
|
|
47
|
+
return {
|
|
48
|
+
version: CONSENT_COOKIE_VERSION,
|
|
49
|
+
decidedAt: decidedAt ?? Date.now(),
|
|
50
|
+
categories: {
|
|
51
|
+
analytics: Boolean(categories.analytics),
|
|
52
|
+
marketing: Boolean(categories.marketing),
|
|
53
|
+
preferences: Boolean(categories.preferences),
|
|
54
|
+
sale_of_data: Boolean(categories.sale_of_data)
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function serializeConsentCookieValue({
|
|
59
|
+
categories,
|
|
60
|
+
decidedAt
|
|
61
|
+
}) {
|
|
62
|
+
const payload = {
|
|
63
|
+
version: CONSENT_COOKIE_VERSION,
|
|
64
|
+
decidedAt,
|
|
65
|
+
categories: {
|
|
66
|
+
analytics: categories.analytics,
|
|
67
|
+
marketing: categories.marketing,
|
|
68
|
+
preferences: categories.preferences,
|
|
69
|
+
sale_of_data: categories.sale_of_data
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return encodeURIComponent(JSON.stringify(payload));
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
CONSENT_COOKIE_MAX_AGE_SECONDS,
|
|
76
|
+
CONSENT_COOKIE_NAME,
|
|
77
|
+
CONSENT_COOKIE_VERSION,
|
|
78
|
+
DENIED_CATEGORIES,
|
|
79
|
+
GRANTED_CATEGORIES,
|
|
80
|
+
parseConsentCookie,
|
|
81
|
+
serializeConsentCookieValue
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=cookie.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../consent/cookie.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ConsentCategory, ConsentMode } 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, shared by the\n * client store (`consent-store.ts`) and the server seed reader (`server.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.\nconst persistedCookieSchema = z.object({\n version: z.literal(CONSENT_COOKIE_VERSION),\n decidedAt: z.number().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 categories: {\n analytics: boolean;\n marketing: boolean;\n preferences: boolean;\n sale_of_data: boolean;\n };\n}\n\nexport interface ConsentSeed {\n mode: ConsentMode;\n categories: ConsentCategories;\n decidedAt: number | null;\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 } = result.data;\n\n return {\n version: CONSENT_COOKIE_VERSION,\n decidedAt: decidedAt ?? Date.now(),\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}: {\n categories: ConsentCategories;\n decidedAt: number;\n}): string {\n const payload: ConsentCookiePayload = {\n version: CONSENT_COOKIE_VERSION,\n decidedAt,\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;AAK7D,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,SAAS,EAAE,QAAQ,sBAAsB;AAAA,EACzC,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;AAsBM,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,WAAW,IAAI,OAAO;AAEzC,SAAO;AAAA,IACL,SAAS;AAAA,IACT,WAAW,aAAa,KAAK,IAAI;AAAA,IACjC,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;AACF,GAGW;AACT,QAAM,UAAgC;AAAA,IACpC,SAAS;AAAA,IACT;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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReploScriptEntry } from "../_vendor/schemas/generated/consent";
|
|
2
|
+
/**
|
|
3
|
+
* The single registry component for all managed tracking scripts on the site.
|
|
4
|
+
* Authored once in `app/layout.tsx`; the agent/miniapp only edit the `scripts`
|
|
5
|
+
* array. Each entry registers itself and is gated + injected per consent.
|
|
6
|
+
*/
|
|
7
|
+
export declare function ReploScripts({ scripts }: {
|
|
8
|
+
scripts: ReploScriptEntry[];
|
|
9
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import { isConsentAllowed, useConsent } from "./consent-store";
|
|
5
|
+
import { registerScript, unregisterScript } from "./script-registration-store";
|
|
6
|
+
import { buildScriptTags, defaultConsentFor } from "./script-snippets";
|
|
7
|
+
import { installConsentWindowApi } from "./window-api";
|
|
8
|
+
function scriptId(entry) {
|
|
9
|
+
return entry.type === "custom" ? `custom:${entry.id}` : `${entry.type}:${entry.identifier}`;
|
|
10
|
+
}
|
|
11
|
+
function requiredConsentFor(entry) {
|
|
12
|
+
if (entry.type === "custom") {
|
|
13
|
+
return entry.requiredConsent;
|
|
14
|
+
}
|
|
15
|
+
return entry.requiredConsent ?? defaultConsentFor(entry.type);
|
|
16
|
+
}
|
|
17
|
+
function descriptorsFor(entry) {
|
|
18
|
+
if (entry.type === "custom") {
|
|
19
|
+
if (entry.src) {
|
|
20
|
+
return [{ kind: "external", src: entry.src }];
|
|
21
|
+
}
|
|
22
|
+
if (entry.body) {
|
|
23
|
+
return [{ kind: "inline", body: entry.body }];
|
|
24
|
+
}
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
return buildScriptTags({ type: entry.type, identifier: entry.identifier });
|
|
28
|
+
}
|
|
29
|
+
function InjectedScript({ entry }) {
|
|
30
|
+
const descriptors = descriptorsFor(entry);
|
|
31
|
+
const baseId = scriptId(entry);
|
|
32
|
+
const injectionKey = `${baseId}|${JSON.stringify(descriptors)}`;
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (typeof document === "undefined") {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const createdNodes = [];
|
|
38
|
+
descriptors.forEach((descriptor, index) => {
|
|
39
|
+
const nodeId = `${baseId}#${index}`;
|
|
40
|
+
const existing = document.querySelector(
|
|
41
|
+
`script[data-replo-script-id="${nodeId}"]`
|
|
42
|
+
);
|
|
43
|
+
if (existing) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const scriptElement = document.createElement("script");
|
|
47
|
+
scriptElement.dataset.reploScriptId = nodeId;
|
|
48
|
+
if (descriptor.kind === "external") {
|
|
49
|
+
scriptElement.src = descriptor.src;
|
|
50
|
+
scriptElement.async = true;
|
|
51
|
+
for (const [attributeName, attributeValue] of Object.entries(
|
|
52
|
+
descriptor.attributes ?? {}
|
|
53
|
+
)) {
|
|
54
|
+
scriptElement.setAttribute(attributeName, attributeValue);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
scriptElement.textContent = descriptor.body;
|
|
58
|
+
}
|
|
59
|
+
document.head.append(scriptElement);
|
|
60
|
+
createdNodes.push(scriptElement);
|
|
61
|
+
});
|
|
62
|
+
return () => {
|
|
63
|
+
for (const node of createdNodes) {
|
|
64
|
+
node.remove();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}, [injectionKey]);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
function ManagedScript({ entry }) {
|
|
71
|
+
const consent = useConsent();
|
|
72
|
+
const requiredConsent = requiredConsentFor(entry);
|
|
73
|
+
const id = scriptId(entry);
|
|
74
|
+
const consentKey = requiredConsent.join(",");
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
registerScript({ id, type: entry.type, requiredConsent });
|
|
77
|
+
return () => unregisterScript(id);
|
|
78
|
+
}, [id, entry.type, consentKey]);
|
|
79
|
+
if (!isConsentAllowed({ state: consent, requiredConsent })) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
return /* @__PURE__ */ jsx(InjectedScript, { entry });
|
|
83
|
+
}
|
|
84
|
+
function ReploScripts({ scripts }) {
|
|
85
|
+
useEffect(() => installConsentWindowApi(), []);
|
|
86
|
+
return /* @__PURE__ */ jsx(Fragment, { children: scripts.map((entry) => /* @__PURE__ */ jsx(ManagedScript, { entry }, scriptId(entry))) });
|
|
87
|
+
}
|
|
88
|
+
export {
|
|
89
|
+
ReploScripts
|
|
90
|
+
};
|
|
91
|
+
//# sourceMappingURL=replo-scripts.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../consent/replo-scripts.tsx"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type {\n ConsentCategory,\n ReploScriptEntry,\n ScriptTagDescriptor,\n} from \"schemas/generated/consent\";\n\nimport { useEffect } from \"react\";\n\nimport { isConsentAllowed, useConsent } from \"./consent-store\";\nimport { registerScript, unregisterScript } from \"./script-registration-store\";\nimport { buildScriptTags, defaultConsentFor } from \"./script-snippets\";\nimport { installConsentWindowApi } from \"./window-api\";\n\n/** Stable identity for an entry, used as React key and DOM dedupe key. */\nfunction scriptId(entry: ReploScriptEntry): string {\n return entry.type === \"custom\"\n ? `custom:${entry.id}`\n : `${entry.type}:${entry.identifier}`;\n}\n\nfunction requiredConsentFor(entry: ReploScriptEntry): ConsentCategory[] {\n if (entry.type === \"custom\") {\n return entry.requiredConsent;\n }\n return entry.requiredConsent ?? defaultConsentFor(entry.type);\n}\n\n/**\n * Resolves an entry to the concrete tags to inject. A named provider may resolve\n * to multiple tags (GA4 = external loader + inline config); a custom entry is a\n * single external `src` or inline `body`.\n */\nfunction descriptorsFor(entry: ReploScriptEntry): ScriptTagDescriptor[] {\n if (entry.type === \"custom\") {\n if (entry.src) {\n return [{ kind: \"external\", src: entry.src }];\n }\n if (entry.body) {\n return [{ kind: \"inline\", body: entry.body }];\n }\n return [];\n }\n return buildScriptTags({ type: entry.type, identifier: entry.identifier });\n}\n\n/**\n * Injects the resolved tags into `document.head` once consent allows it.\n *\n * DOM insertion (not JSX) is required because inline `<script>` bodies set via\n * React's `dangerouslySetInnerHTML` never execute. Each node is tagged with\n * `data-replo-script-id` (plus a per-tag index) so re-renders and React Strict\n * Mode double-invokes do not double-inject.\n */\nfunction InjectedScript({ entry }: { entry: ReploScriptEntry }) {\n const descriptors = descriptorsFor(entry);\n const baseId = scriptId(entry);\n // Re-inject only when the resolved tags actually change.\n const injectionKey = `${baseId}|${JSON.stringify(descriptors)}`;\n\n // eslint-disable-next-line replo/no-use-effect -- script injection is a DOM side effect that must run after mount and on consent changes\n useEffect(() => {\n if (typeof document === \"undefined\") {\n return;\n }\n const createdNodes: HTMLScriptElement[] = [];\n descriptors.forEach((descriptor, index) => {\n const nodeId = `${baseId}#${index}`;\n const existing = document.querySelector(\n `script[data-replo-script-id=\"${nodeId}\"]`,\n );\n if (existing) {\n return;\n }\n const scriptElement = document.createElement(\"script\");\n scriptElement.dataset.reploScriptId = nodeId;\n if (descriptor.kind === \"external\") {\n scriptElement.src = descriptor.src;\n scriptElement.async = true;\n for (const [attributeName, attributeValue] of Object.entries(\n descriptor.attributes ?? {},\n )) {\n scriptElement.setAttribute(attributeName, attributeValue);\n }\n } else {\n scriptElement.textContent = descriptor.body;\n }\n document.head.append(scriptElement);\n createdNodes.push(scriptElement);\n });\n\n return () => {\n // Removing the node does not unload an already-loaded vendor (see the plan's\n // revocation note); full teardown is a reload triggered by the banner. This\n // cleanup keeps the DOM tidy and prevents duplicates across remounts.\n for (const node of createdNodes) {\n node.remove();\n }\n };\n }, [injectionKey]);\n\n return null;\n}\n\nfunction ManagedScript({ entry }: { entry: ReploScriptEntry }) {\n const consent = useConsent();\n const requiredConsent = requiredConsentFor(entry);\n const id = scriptId(entry);\n const consentKey = requiredConsent.join(\",\");\n\n // eslint-disable-next-line replo/no-use-effect -- register/unregister with the singleton so the analytics provider can gate sinks by what's on the page\n useEffect(() => {\n registerScript({ id, type: entry.type, requiredConsent });\n return () => unregisterScript(id);\n }, [id, entry.type, consentKey]);\n\n if (!isConsentAllowed({ state: consent, requiredConsent })) {\n return null;\n }\n return <InjectedScript entry={entry} />;\n}\n\n/**\n * The single registry component for all managed tracking scripts on the site.\n * Authored once in `app/layout.tsx`; the agent/miniapp only edit the `scripts`\n * array. Each entry registers itself and is gated + injected per consent.\n */\nexport function ReploScripts({ scripts }: { scripts: ReploScriptEntry[] }) {\n // eslint-disable-next-line replo/no-use-effect -- install the window.Replo.customerPrivacy API + change event once the consent runtime mounts\n useEffect(() => installConsentWindowApi(), []);\n\n return (\n <>\n {scripts.map((entry) => (\n <ManagedScript key={scriptId(entry)} entry={entry} />\n ))}\n </>\n );\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ConsentCategory, ReploScriptType } from "../_vendor/schemas/generated/consent";
|
|
2
|
+
/**
|
|
3
|
+
* Tracks which managed scripts are currently mounted on the page. Each
|
|
4
|
+
* `ReploScripts` entry registers itself here on mount, so the analytics provider
|
|
5
|
+
* can create sinks only for providers that are actually present (and consented),
|
|
6
|
+
* without importing a static list. Like the consent store, this is a singleton
|
|
7
|
+
* rather than React context so it works regardless of tree position.
|
|
8
|
+
*/
|
|
9
|
+
export interface RegisteredScript {
|
|
10
|
+
id: string;
|
|
11
|
+
type: ReploScriptType;
|
|
12
|
+
requiredConsent: ConsentCategory[];
|
|
13
|
+
}
|
|
14
|
+
export declare const scriptRegistrationStore: {
|
|
15
|
+
register(script: RegisteredScript): void;
|
|
16
|
+
unregister(id: string): void;
|
|
17
|
+
getSnapshot(): RegisteredScript[];
|
|
18
|
+
getServerSnapshot(): RegisteredScript[];
|
|
19
|
+
subscribe(listener: () => void): () => void;
|
|
20
|
+
/** Test-only: clear the registry between cases. */
|
|
21
|
+
reset(): void;
|
|
22
|
+
};
|
|
23
|
+
export declare function registerScript(script: RegisteredScript): void;
|
|
24
|
+
export declare function unregisterScript(id: string): void;
|
|
25
|
+
export declare function useRegisteredScripts(): RegisteredScript[];
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
const registry = /* @__PURE__ */ new Map();
|
|
4
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
5
|
+
let snapshot = [];
|
|
6
|
+
const SERVER_SNAPSHOT = [];
|
|
7
|
+
function emit() {
|
|
8
|
+
snapshot = [...registry.values()];
|
|
9
|
+
for (const listener of listeners) {
|
|
10
|
+
listener();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const scriptRegistrationStore = {
|
|
14
|
+
register(script) {
|
|
15
|
+
registry.set(script.id, script);
|
|
16
|
+
emit();
|
|
17
|
+
},
|
|
18
|
+
unregister(id) {
|
|
19
|
+
if (registry.delete(id)) {
|
|
20
|
+
emit();
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
getSnapshot() {
|
|
24
|
+
return snapshot;
|
|
25
|
+
},
|
|
26
|
+
getServerSnapshot() {
|
|
27
|
+
return SERVER_SNAPSHOT;
|
|
28
|
+
},
|
|
29
|
+
subscribe(listener) {
|
|
30
|
+
listeners.add(listener);
|
|
31
|
+
return () => {
|
|
32
|
+
listeners.delete(listener);
|
|
33
|
+
};
|
|
34
|
+
},
|
|
35
|
+
/** Test-only: clear the registry between cases. */
|
|
36
|
+
reset() {
|
|
37
|
+
registry.clear();
|
|
38
|
+
listeners.clear();
|
|
39
|
+
snapshot = [];
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
function registerScript(script) {
|
|
43
|
+
scriptRegistrationStore.register(script);
|
|
44
|
+
}
|
|
45
|
+
function unregisterScript(id) {
|
|
46
|
+
scriptRegistrationStore.unregister(id);
|
|
47
|
+
}
|
|
48
|
+
function useRegisteredScripts() {
|
|
49
|
+
return useSyncExternalStore(
|
|
50
|
+
scriptRegistrationStore.subscribe,
|
|
51
|
+
scriptRegistrationStore.getSnapshot,
|
|
52
|
+
scriptRegistrationStore.getServerSnapshot
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
export {
|
|
56
|
+
registerScript,
|
|
57
|
+
scriptRegistrationStore,
|
|
58
|
+
unregisterScript,
|
|
59
|
+
useRegisteredScripts
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=script-registration-store.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../consent/script-registration-store.ts"],
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type {\n ConsentCategory,\n ReploScriptType,\n} from \"schemas/generated/consent\";\n\nimport { useSyncExternalStore } from \"react\";\n\n/**\n * Tracks which managed scripts are currently mounted on the page. Each\n * `ReploScripts` entry registers itself here on mount, so the analytics provider\n * can create sinks only for providers that are actually present (and consented),\n * without importing a static list. Like the consent store, this is a singleton\n * rather than React context so it works regardless of tree position.\n */\n\nexport interface RegisteredScript {\n id: string;\n type: ReploScriptType;\n requiredConsent: ConsentCategory[];\n}\n\nconst registry = new Map<string, RegisteredScript>();\nconst listeners = new Set<() => void>();\n\n// useSyncExternalStore requires a referentially-stable snapshot between emits.\nlet snapshot: RegisteredScript[] = [];\n\nconst SERVER_SNAPSHOT: RegisteredScript[] = [];\n\nfunction emit() {\n snapshot = [...registry.values()];\n for (const listener of listeners) {\n listener();\n }\n}\n\nexport const scriptRegistrationStore = {\n register(script: RegisteredScript) {\n registry.set(script.id, script);\n emit();\n },\n unregister(id: string) {\n if (registry.delete(id)) {\n emit();\n }\n },\n getSnapshot(): RegisteredScript[] {\n return snapshot;\n },\n getServerSnapshot(): RegisteredScript[] {\n return SERVER_SNAPSHOT;\n },\n subscribe(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n /** Test-only: clear the registry between cases. */\n reset() {\n registry.clear();\n listeners.clear();\n snapshot = [];\n },\n};\n\nexport function registerScript(script: RegisteredScript) {\n scriptRegistrationStore.register(script);\n}\n\nexport function unregisterScript(id: string) {\n scriptRegistrationStore.unregister(id);\n}\n\nexport function useRegisteredScripts(): RegisteredScript[] {\n return useSyncExternalStore(\n scriptRegistrationStore.subscribe,\n scriptRegistrationStore.getSnapshot,\n scriptRegistrationStore.getServerSnapshot,\n );\n}\n"],
|
|
5
|
+
"mappings": ";AAOA,SAAS,4BAA4B;AAgBrC,MAAM,WAAW,oBAAI,IAA8B;AACnD,MAAM,YAAY,oBAAI,IAAgB;AAGtC,IAAI,WAA+B,CAAC;AAEpC,MAAM,kBAAsC,CAAC;AAE7C,SAAS,OAAO;AACd,aAAW,CAAC,GAAG,SAAS,OAAO,CAAC;AAChC,aAAW,YAAY,WAAW;AAChC,aAAS;AAAA,EACX;AACF;AAEO,MAAM,0BAA0B;AAAA,EACrC,SAAS,QAA0B;AACjC,aAAS,IAAI,OAAO,IAAI,MAAM;AAC9B,SAAK;AAAA,EACP;AAAA,EACA,WAAW,IAAY;AACrB,QAAI,SAAS,OAAO,EAAE,GAAG;AACvB,WAAK;AAAA,IACP;AAAA,EACF;AAAA,EACA,cAAkC;AAChC,WAAO;AAAA,EACT;AAAA,EACA,oBAAwC;AACtC,WAAO;AAAA,EACT;AAAA,EACA,UAAU,UAAkC;AAC1C,cAAU,IAAI,QAAQ;AACtB,WAAO,MAAM;AACX,gBAAU,OAAO,QAAQ;AAAA,IAC3B;AAAA,EACF;AAAA;AAAA,EAEA,QAAQ;AACN,aAAS,MAAM;AACf,cAAU,MAAM;AAChB,eAAW,CAAC;AAAA,EACd;AACF;AAEO,SAAS,eAAe,QAA0B;AACvD,0BAAwB,SAAS,MAAM;AACzC;AAEO,SAAS,iBAAiB,IAAY;AAC3C,0BAAwB,WAAW,EAAE;AACvC;AAEO,SAAS,uBAA2C;AACzD,SAAO;AAAA,IACL,wBAAwB;AAAA,IACxB,wBAAwB;AAAA,IACxB,wBAAwB;AAAA,EAC1B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ConsentCategory, ReploScriptType, ScriptTagDescriptor } from "../_vendor/schemas/generated/consent";
|
|
2
|
+
type ProviderType = Exclude<ReploScriptType, "custom">;
|
|
3
|
+
/**
|
|
4
|
+
* Returns the structured tag descriptors for a named provider. A single provider
|
|
5
|
+
* can produce multiple tags (e.g. GA4 = external loader + inline config), which
|
|
6
|
+
* the runtime injects in order.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildScriptTags({ type, identifier, }: {
|
|
9
|
+
type: ProviderType;
|
|
10
|
+
identifier: string;
|
|
11
|
+
}): ScriptTagDescriptor[];
|
|
12
|
+
/**
|
|
13
|
+
* The default consent categories that gate a script when an entry does not
|
|
14
|
+
* specify `requiredConsent`. Named providers map to a defensible default;
|
|
15
|
+
* `custom` has no safe default, so the caller must supply `requiredConsent`.
|
|
16
|
+
* Overridable per entry by the customer.
|
|
17
|
+
*/
|
|
18
|
+
export declare function defaultConsentFor(type: ReploScriptType): ConsentCategory[];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
const PROVIDER_SNIPPETS = {
|
|
2
|
+
GA4: {
|
|
3
|
+
defaultConsent: ["analytics"],
|
|
4
|
+
buildTags: (id) => [
|
|
5
|
+
{
|
|
6
|
+
kind: "external",
|
|
7
|
+
src: `https://www.googletagmanager.com/gtag/js?id=${id}`
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
kind: "inline",
|
|
11
|
+
body: `window.dataLayer = window.dataLayer || [];
|
|
12
|
+
function gtag(){dataLayer.push(arguments);}
|
|
13
|
+
gtag('js', new Date());
|
|
14
|
+
gtag('config', '${id}');`
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
GoogleTagManager: {
|
|
19
|
+
defaultConsent: ["analytics", "marketing"],
|
|
20
|
+
buildTags: (id) => [
|
|
21
|
+
{
|
|
22
|
+
kind: "inline",
|
|
23
|
+
body: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${id}');`
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
Meta: {
|
|
28
|
+
defaultConsent: ["marketing"],
|
|
29
|
+
buildTags: (id) => [
|
|
30
|
+
{
|
|
31
|
+
kind: "inline",
|
|
32
|
+
body: `!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,document,'script','https://connect.facebook.net/en_US/fbevents.js');fbq('init','${id}');fbq('track','PageView');`
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
TikTok: {
|
|
37
|
+
defaultConsent: ["marketing"],
|
|
38
|
+
buildTags: (id) => [
|
|
39
|
+
{
|
|
40
|
+
kind: "inline",
|
|
41
|
+
body: `!function(w,d,t){w.TiktokAnalyticsObject=t;var ttq=w[t]=w[t]||[];ttq.methods=["page","track","identify","instances","debug","on","off","once","ready","alias","group","enableCookie","disableCookie","holdConsent","revokeConsent","grantConsent"],ttq.setAndDefer=function(t,e){t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}};for(var i=0;i<ttq.methods.length;i++)ttq.setAndDefer(ttq,ttq.methods[i]);ttq.instance=function(t){for(var e=ttq._i[t]||[],n=0;n<ttq.methods.length;n++)ttq.setAndDefer(e,ttq.methods[n]);return e};ttq.load=function(e,n){var r="https://analytics.tiktok.com/i18n/pixel/events.js",o=n&&n.partner;ttq._i=ttq._i||{},ttq._i[e]=[],ttq._i[e]._u=r,ttq._t=ttq._t||{},ttq._t[e]=+new Date,ttq._o=ttq._o||{},ttq._o[e]=n||{};var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=r+"?sdkid="+e+"&lib="+t;var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(a,s)};ttq.load('${id}');ttq.page();}(window,document,'ttq');`
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
Pinterest: {
|
|
46
|
+
defaultConsent: ["marketing"],
|
|
47
|
+
buildTags: (id) => [
|
|
48
|
+
{
|
|
49
|
+
kind: "inline",
|
|
50
|
+
body: `!function(e){if(!window.pintrk){window.pintrk=function(){window.pintrk.queue.push(Array.prototype.slice.call(arguments))};var n=window.pintrk;n.queue=[],n.version="3.0";var t=document.createElement("script");t.async=!0,t.src=e;var r=document.getElementsByTagName("script")[0];r.parentNode.insertBefore(t,r)}}("https://s.pinimg.com/ct/core.js");pintrk('load','${id}');pintrk('page');`
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
Reddit: {
|
|
55
|
+
defaultConsent: ["marketing"],
|
|
56
|
+
buildTags: (id) => [
|
|
57
|
+
{
|
|
58
|
+
kind: "inline",
|
|
59
|
+
body: `!function(w,d){if(!w.rdt){var p=w.rdt=function(){p.sendEvent?p.sendEvent.apply(p,arguments):p.callQueue.push(arguments)};p.callQueue=[];var t=d.createElement("script");t.src="https://www.redditstatic.com/ads/pixel.js",t.async=!0;var s=d.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}}(window,document);rdt('init','${id}');rdt('track','PageVisit');`
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
Snapchat: {
|
|
64
|
+
defaultConsent: ["marketing"],
|
|
65
|
+
buildTags: (id) => [
|
|
66
|
+
{
|
|
67
|
+
kind: "inline",
|
|
68
|
+
body: `(function(e,t,n){if(e.snaptr)return;var a=e.snaptr=function(){a.handleRequest?a.handleRequest.apply(a,arguments):a.queue.push(arguments)};a.queue=[];var s='script';var r=t.createElement(s);r.async=!0;r.src=n;var u=t.getElementsByTagName(s)[0];u.parentNode.insertBefore(r,u);})(window,document,'https://sc-static.net/scevent.min.js');snaptr('init','${id}',{});snaptr('track','PAGE_VIEW');`
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
Hotjar: {
|
|
73
|
+
defaultConsent: ["analytics"],
|
|
74
|
+
buildTags: (id) => [
|
|
75
|
+
{
|
|
76
|
+
kind: "inline",
|
|
77
|
+
body: `(function(h,o,t,j,a,r){h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};h._hjSettings={hjid:${id},hjsv:6};a=o.getElementsByTagName('head')[0];r=o.createElement('script');r.async=1;r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;a.appendChild(r);})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');`
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
},
|
|
81
|
+
MicrosoftClarity: {
|
|
82
|
+
defaultConsent: ["analytics"],
|
|
83
|
+
buildTags: (id) => [
|
|
84
|
+
{
|
|
85
|
+
kind: "inline",
|
|
86
|
+
body: `(function(c,l,a,r,i,t,y){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);})(window,document,"clarity","script","${id}");`
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
Triplewhale: {
|
|
91
|
+
defaultConsent: ["analytics", "marketing"],
|
|
92
|
+
buildTags: (id) => [
|
|
93
|
+
{
|
|
94
|
+
kind: "external",
|
|
95
|
+
src: `https://api.triplewhale.com/pixel/${id}`
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
},
|
|
99
|
+
Segment: {
|
|
100
|
+
defaultConsent: ["analytics", "marketing"],
|
|
101
|
+
buildTags: (id) => [
|
|
102
|
+
{
|
|
103
|
+
kind: "inline",
|
|
104
|
+
body: `!function(){var i="analytics",analytics=window[i]=window[i]||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","screen","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware","register"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e<analytics.methods.length;e++){var key=analytics.methods[e];analytics[key]=analytics.factory(key)}analytics.load=function(key,e){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.src="https://cdn.segment.com/analytics.js/v1/"+key+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics._writeKey="${id}";analytics.SNIPPET_VERSION="5.2.0";analytics.load("${id}");analytics.page();}}();`
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
function buildScriptTags({
|
|
110
|
+
type,
|
|
111
|
+
identifier
|
|
112
|
+
}) {
|
|
113
|
+
return PROVIDER_SNIPPETS[type].buildTags(identifier);
|
|
114
|
+
}
|
|
115
|
+
function defaultConsentFor(type) {
|
|
116
|
+
if (type === "custom") {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
return PROVIDER_SNIPPETS[type].defaultConsent;
|
|
120
|
+
}
|
|
121
|
+
export {
|
|
122
|
+
buildScriptTags,
|
|
123
|
+
defaultConsentFor
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=script-snippets.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../consent/script-snippets.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n ConsentCategory,\n ReploScriptType,\n ScriptTagDescriptor,\n} from \"schemas/generated/consent\";\n\ntype ProviderType = Exclude<ReploScriptType, \"custom\">;\n\n/**\n * Runtime-safe per-provider data for the consent system. This is the subset of\n * the website-builder miniapp's `scriptConstants.ts` that must ship in the\n * customer site bundle: how to materialize each provider's script tags, and the\n * default consent category that gates it. Miniapp-only concerns (LLM detection\n * schemas, logos, marketing copy) intentionally stay in the miniapp.\n *\n * Unlike the miniapp's `buildSnippet`, which returns a JSX *string* for the\n * agent to paste into `layout.tsx`, this returns structured descriptors so the\n * runtime can inject real DOM nodes (inline `<script>` bodies set via React's\n * `dangerouslySetInnerHTML` never execute).\n */\ntype ProviderSnippet = {\n defaultConsent: ConsentCategory[];\n buildTags: (identifier: string) => ScriptTagDescriptor[];\n};\n\n/**\n * NOTE (Ryan, 2026-05-28, REPL-27515): `defaultConsent` is net-new,\n * legally-sensitive categorization that does not exist elsewhere in the repo.\n * These are conservative defaults a customer can override per entry via\n * `requiredConsent`; container/CDP providers that fan out to multiple vendors\n * (GTM, Segment, Triple Whale) require the union of categories they can serve.\n */\nconst PROVIDER_SNIPPETS: Record<ProviderType, ProviderSnippet> = {\n GA4: {\n defaultConsent: [\"analytics\"],\n buildTags: (id) => [\n {\n kind: \"external\",\n src: `https://www.googletagmanager.com/gtag/js?id=${id}`,\n },\n {\n kind: \"inline\",\n body: `window.dataLayer = window.dataLayer || [];\\nfunction gtag(){dataLayer.push(arguments);}\\ngtag('js', new Date());\\ngtag('config', '${id}');`,\n },\n ],\n },\n GoogleTagManager: {\n defaultConsent: [\"analytics\", \"marketing\"],\n buildTags: (id) => [\n {\n kind: \"inline\",\n body: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${id}');`,\n },\n ],\n },\n Meta: {\n defaultConsent: [\"marketing\"],\n buildTags: (id) => [\n {\n kind: \"inline\",\n body: `!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,document,'script','https://connect.facebook.net/en_US/fbevents.js');fbq('init','${id}');fbq('track','PageView');`,\n },\n ],\n },\n TikTok: {\n defaultConsent: [\"marketing\"],\n buildTags: (id) => [\n {\n kind: \"inline\",\n body: `!function(w,d,t){w.TiktokAnalyticsObject=t;var ttq=w[t]=w[t]||[];ttq.methods=[\"page\",\"track\",\"identify\",\"instances\",\"debug\",\"on\",\"off\",\"once\",\"ready\",\"alias\",\"group\",\"enableCookie\",\"disableCookie\",\"holdConsent\",\"revokeConsent\",\"grantConsent\"],ttq.setAndDefer=function(t,e){t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}};for(var i=0;i<ttq.methods.length;i++)ttq.setAndDefer(ttq,ttq.methods[i]);ttq.instance=function(t){for(var e=ttq._i[t]||[],n=0;n<ttq.methods.length;n++)ttq.setAndDefer(e,ttq.methods[n]);return e};ttq.load=function(e,n){var r=\"https://analytics.tiktok.com/i18n/pixel/events.js\",o=n&&n.partner;ttq._i=ttq._i||{},ttq._i[e]=[],ttq._i[e]._u=r,ttq._t=ttq._t||{},ttq._t[e]=+new Date,ttq._o=ttq._o||{},ttq._o[e]=n||{};var a=document.createElement(\"script\");a.type=\"text/javascript\",a.async=!0,a.src=r+\"?sdkid=\"+e+\"&lib=\"+t;var s=document.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(a,s)};ttq.load('${id}');ttq.page();}(window,document,'ttq');`,\n },\n ],\n },\n Pinterest: {\n defaultConsent: [\"marketing\"],\n buildTags: (id) => [\n {\n kind: \"inline\",\n body: `!function(e){if(!window.pintrk){window.pintrk=function(){window.pintrk.queue.push(Array.prototype.slice.call(arguments))};var n=window.pintrk;n.queue=[],n.version=\"3.0\";var t=document.createElement(\"script\");t.async=!0,t.src=e;var r=document.getElementsByTagName(\"script\")[0];r.parentNode.insertBefore(t,r)}}(\"https://s.pinimg.com/ct/core.js\");pintrk('load','${id}');pintrk('page');`,\n },\n ],\n },\n Reddit: {\n defaultConsent: [\"marketing\"],\n buildTags: (id) => [\n {\n kind: \"inline\",\n body: `!function(w,d){if(!w.rdt){var p=w.rdt=function(){p.sendEvent?p.sendEvent.apply(p,arguments):p.callQueue.push(arguments)};p.callQueue=[];var t=d.createElement(\"script\");t.src=\"https://www.redditstatic.com/ads/pixel.js\",t.async=!0;var s=d.getElementsByTagName(\"script\")[0];s.parentNode.insertBefore(t,s)}}(window,document);rdt('init','${id}');rdt('track','PageVisit');`,\n },\n ],\n },\n Snapchat: {\n defaultConsent: [\"marketing\"],\n buildTags: (id) => [\n {\n kind: \"inline\",\n body: `(function(e,t,n){if(e.snaptr)return;var a=e.snaptr=function(){a.handleRequest?a.handleRequest.apply(a,arguments):a.queue.push(arguments)};a.queue=[];var s='script';var r=t.createElement(s);r.async=!0;r.src=n;var u=t.getElementsByTagName(s)[0];u.parentNode.insertBefore(r,u);})(window,document,'https://sc-static.net/scevent.min.js');snaptr('init','${id}',{});snaptr('track','PAGE_VIEW');`,\n },\n ],\n },\n Hotjar: {\n defaultConsent: [\"analytics\"],\n buildTags: (id) => [\n {\n kind: \"inline\",\n body: `(function(h,o,t,j,a,r){h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};h._hjSettings={hjid:${id},hjsv:6};a=o.getElementsByTagName('head')[0];r=o.createElement('script');r.async=1;r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;a.appendChild(r);})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');`,\n },\n ],\n },\n MicrosoftClarity: {\n defaultConsent: [\"analytics\"],\n buildTags: (id) => [\n {\n kind: \"inline\",\n body: `(function(c,l,a,r,i,t,y){c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};t=l.createElement(r);t.async=1;t.src=\"https://www.clarity.ms/tag/\"+i;y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);})(window,document,\"clarity\",\"script\",\"${id}\");`,\n },\n ],\n },\n Triplewhale: {\n defaultConsent: [\"analytics\", \"marketing\"],\n buildTags: (id) => [\n {\n kind: \"external\",\n src: `https://api.triplewhale.com/pixel/${id}`,\n },\n ],\n },\n Segment: {\n defaultConsent: [\"analytics\", \"marketing\"],\n buildTags: (id) => [\n {\n kind: \"inline\",\n body: `!function(){var i=\"analytics\",analytics=window[i]=window[i]||[];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error(\"Segment snippet included twice.\");else{analytics.invoked=!0;analytics.methods=[\"trackSubmit\",\"trackClick\",\"trackLink\",\"trackForm\",\"pageview\",\"identify\",\"reset\",\"group\",\"track\",\"ready\",\"alias\",\"debug\",\"page\",\"screen\",\"once\",\"off\",\"on\",\"addSourceMiddleware\",\"addIntegrationMiddleware\",\"setAnonymousId\",\"addDestinationMiddleware\",\"register\"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e<analytics.methods.length;e++){var key=analytics.methods[e];analytics[key]=analytics.factory(key)}analytics.load=function(key,e){var t=document.createElement(\"script\");t.type=\"text/javascript\";t.async=!0;t.src=\"https://cdn.segment.com/analytics.js/v1/\"+key+\"/analytics.min.js\";var n=document.getElementsByTagName(\"script\")[0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics._writeKey=\"${id}\";analytics.SNIPPET_VERSION=\"5.2.0\";analytics.load(\"${id}\");analytics.page();}}();`,\n },\n ],\n },\n};\n\n/**\n * Returns the structured tag descriptors for a named provider. A single provider\n * can produce multiple tags (e.g. GA4 = external loader + inline config), which\n * the runtime injects in order.\n */\nexport function buildScriptTags({\n type,\n identifier,\n}: {\n type: ProviderType;\n identifier: string;\n}): ScriptTagDescriptor[] {\n return PROVIDER_SNIPPETS[type].buildTags(identifier);\n}\n\n/**\n * The default consent categories that gate a script when an entry does not\n * specify `requiredConsent`. Named providers map to a defensible default;\n * `custom` has no safe default, so the caller must supply `requiredConsent`.\n * Overridable per entry by the customer.\n */\nexport function defaultConsentFor(type: ReploScriptType): ConsentCategory[] {\n if (type === \"custom\") {\n return [];\n }\n return PROVIDER_SNIPPETS[type].defaultConsent;\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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>;
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ConsentCategory } from "../_vendor/schemas/generated/consent";
|
|
2
|
+
/**
|
|
3
|
+
* Global, framework-agnostic consent API exposed on `window.Replo.customerPrivacy`,
|
|
4
|
+
* mirroring Shopify's Customer Privacy API surface so on-page (third-party)
|
|
5
|
+
* scripts can query consent and react to changes without importing canopy.
|
|
6
|
+
*
|
|
7
|
+
* It deliberately lives under our own `window.Replo` namespace rather than
|
|
8
|
+
* `window.Shopify` to avoid colliding with Shopify's real API on Shopify-backed
|
|
9
|
+
* sites.
|
|
10
|
+
*/
|
|
11
|
+
type ToggleableCategory = Exclude<ConsentCategory, "necessary">;
|
|
12
|
+
/** Shopify-style tri-state: declared-allowed, declared-denied, or undeclared. */
|
|
13
|
+
type ConsentSignal = "yes" | "no" | "";
|
|
14
|
+
export interface ReploCustomerPrivacyApi {
|
|
15
|
+
/** Per-category declaration, or "" when the visitor has not decided. */
|
|
16
|
+
currentVisitorConsent(): Record<ToggleableCategory, ConsentSignal>;
|
|
17
|
+
analyticsProcessingAllowed(): boolean;
|
|
18
|
+
marketingAllowed(): boolean;
|
|
19
|
+
preferencesProcessingAllowed(): boolean;
|
|
20
|
+
saleOfDataAllowed(): boolean;
|
|
21
|
+
/** Whether the consent banner should still be shown (mode on + undecided). */
|
|
22
|
+
shouldShowBanner(): boolean;
|
|
23
|
+
/** Update a subset of categories; runs the optional callback once persisted. */
|
|
24
|
+
setTrackingConsent(consent: Partial<Record<ToggleableCategory, boolean>>, callback?: () => void): void;
|
|
25
|
+
}
|
|
26
|
+
declare global {
|
|
27
|
+
interface Window {
|
|
28
|
+
Replo?: {
|
|
29
|
+
customerPrivacy?: ReploCustomerPrivacyApi;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** DOM event dispatched on `document` whenever consent changes. */
|
|
34
|
+
export declare const CONSENT_CHANGE_EVENT = "visitorConsentCollected";
|
|
35
|
+
/**
|
|
36
|
+
* Installs `window.Replo.customerPrivacy` and dispatches `visitorConsentCollected`
|
|
37
|
+
* on `document` whenever consent changes. Idempotent; returns a teardown that
|
|
38
|
+
* removes the change subscription. Safe to call on the server (no-op).
|
|
39
|
+
*/
|
|
40
|
+
export declare function installConsentWindowApi(): () => void;
|
|
41
|
+
export {};
|