@replohq/canopy-sdk 0.1.1 → 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/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
|
@@ -10,6 +10,8 @@ export declare function isNotNullish<T>(value: T): value is Exclude<T, null | un
|
|
|
10
10
|
* Checks if a value is either `null` or `undefined`.
|
|
11
11
|
*/
|
|
12
12
|
export declare function isNullish(value: unknown): value is null | undefined;
|
|
13
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
14
|
+
export declare function stringValue(value: unknown): string | null;
|
|
13
15
|
export declare function getFromRecordOrNull<RecordKey extends PropertyKey, RecordValue>(record: Record<RecordKey, RecordValue> | null | undefined, key: RecordKey | undefined | null): NonNullable<Record<RecordKey, RecordValue>[RecordKey]> | null;
|
|
14
16
|
export declare function isPrimitive(value: unknown): value is string | number | boolean;
|
|
15
17
|
type StructureRecord<A extends {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty, invariant, isEmpty, isFunction_default as isFunction, isNotNullish, isNullish,
|
|
1
|
+
export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty, invariant, isEmpty, isFunction_default as isFunction, isNotNullish, isNullish, isPrimitive, isRecord, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, stringValue, warning } from '../../../chunk-XK2K3263.mjs';
|
|
2
|
+
export { isNumber_default as isNumber, isString_default as isString } from '../../../chunk-GV5FY7ZZ.mjs';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MapCache_default, exhaustiveSwitch, hasOwnProperty, identity_default, baseFor_default, keys_default, Stack_default, isLength_default, isIndex_default, isArguments_default, getTag_default, isBuffer_default, isTypedArray_default, eq_default, Uint8Array_default, getAllKeys_default, baseAssignValue_default } from '../../chunk-XK2K3263.mjs';
|
|
2
|
+
import { Symbol_default, isArray_default, isObject_default, isObjectLike_default, baseGetTag_default } from '../../chunk-GV5FY7ZZ.mjs';
|
|
2
3
|
import { z, ZodError } from 'zod';
|
|
3
4
|
|
|
4
5
|
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseForOwn.js
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type ReploScriptType = "GA4" | "GoogleTagManager" | "Meta" | "TikTok" | "Pinterest" | "Reddit" | "Snapchat" | "Hotjar" | "MicrosoftClarity" | "Triplewhale" | "Segment" | "custom";
|
|
2
|
+
export type ConsentCategory = "necessary" | "analytics" | "marketing" | "preferences" | "sale_of_data";
|
|
3
|
+
export type ConsentMode = "off" | "simple" | "per-category";
|
|
4
|
+
export type ScriptTagDescriptor = {
|
|
5
|
+
kind: "external";
|
|
6
|
+
src: string;
|
|
7
|
+
attributes?: {
|
|
8
|
+
[x: string]: string;
|
|
9
|
+
};
|
|
10
|
+
} | {
|
|
11
|
+
kind: "inline";
|
|
12
|
+
body: string;
|
|
13
|
+
};
|
|
14
|
+
export type ReploScriptEntry = {
|
|
15
|
+
type: "GA4" | "GoogleTagManager" | "Meta" | "TikTok" | "Pinterest" | "Reddit" | "Snapchat" | "Hotjar" | "MicrosoftClarity" | "Triplewhale" | "Segment";
|
|
16
|
+
identifier: string;
|
|
17
|
+
requiredConsent?: ConsentCategory[];
|
|
18
|
+
} | {
|
|
19
|
+
type: "custom";
|
|
20
|
+
id: string;
|
|
21
|
+
requiredConsent: ConsentCategory[];
|
|
22
|
+
src?: string;
|
|
23
|
+
body?: string;
|
|
24
|
+
};
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseJsonOrNull } from '../../chunk-VKO7P3ED.mjs';
|
|
2
|
+
import { exhaustiveSwitch } from '../../chunk-XK2K3263.mjs';
|
|
3
|
+
import '../../chunk-GV5FY7ZZ.mjs';
|
|
2
4
|
import { z } from 'zod';
|
|
3
5
|
|
|
4
|
-
// ../replo-utils/lib/json.ts
|
|
5
|
-
function parseJsonOrNull(json) {
|
|
6
|
-
try {
|
|
7
|
-
return JSON.parse(json);
|
|
8
|
-
} catch {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
6
|
// ../replo-utils/lib/parse.ts
|
|
14
7
|
function parseSchemaOrNull(value, schema) {
|
|
15
8
|
const parseResult = schema.safeParse(value);
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useEffect,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { RedditSink } from "./sinks/reddit-sink";
|
|
8
|
-
import { ReploSink } from "./sinks/replo-sink";
|
|
9
|
-
import { SnapchatSink } from "./sinks/snapchat-sink";
|
|
10
|
-
import { TikTokSink } from "./sinks/tiktok-sink";
|
|
11
|
-
import { WindowSink } from "./sinks/window-sink";
|
|
3
|
+
import { createContext, useContext, useEffect, useMemo, useRef } from "react";
|
|
4
|
+
import { useConsent } from "../consent/consent-store";
|
|
5
|
+
import { useRegisteredScripts } from "../consent/script-registration-store";
|
|
6
|
+
import { getAnalyticsSinks } from "./get-analytics-sinks";
|
|
12
7
|
import { NavigationTracker } from "./utils/navigation-tracker";
|
|
13
8
|
function combineSinks(sinks) {
|
|
14
9
|
const broadcast = async (method, ...args) => {
|
|
@@ -49,29 +44,33 @@ function combineSinks(sinks) {
|
|
|
49
44
|
}
|
|
50
45
|
const AnalyticsContext = createContext(null);
|
|
51
46
|
function AnalyticsProvider({ children }) {
|
|
52
|
-
const
|
|
47
|
+
const consent = useConsent();
|
|
48
|
+
const registeredScripts = useRegisteredScripts();
|
|
49
|
+
const analytics = useMemo(() => {
|
|
50
|
+
return combineSinks(
|
|
51
|
+
getAnalyticsSinks({
|
|
52
|
+
consent: {
|
|
53
|
+
mode: consent.mode,
|
|
54
|
+
categories: consent.categories,
|
|
55
|
+
decidedAt: consent.decidedAt
|
|
56
|
+
},
|
|
57
|
+
registeredScripts
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
}, [consent.mode, consent.categories, consent.decidedAt, registeredScripts]);
|
|
61
|
+
const analyticsRef = useRef(analytics);
|
|
62
|
+
analyticsRef.current = analytics;
|
|
53
63
|
const navigationTracker = useRef(null);
|
|
54
64
|
useEffect(() => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
new GA4Sink(),
|
|
58
|
-
new MetaSink(),
|
|
59
|
-
new TikTokSink(),
|
|
60
|
-
new SnapchatSink(),
|
|
61
|
-
new PinterestSink(),
|
|
62
|
-
new RedditSink(),
|
|
63
|
-
new WindowSink()
|
|
64
|
-
];
|
|
65
|
-
const combinedSink = combineSinks(sinks);
|
|
66
|
-
setAnalytics(combinedSink);
|
|
67
|
-
if (typeof window !== "undefined") {
|
|
68
|
-
navigationTracker.current = new NavigationTracker(
|
|
69
|
-
(metadata) => {
|
|
70
|
-
void combinedSink.pageView(metadata);
|
|
71
|
-
}
|
|
72
|
-
);
|
|
73
|
-
navigationTracker.current.init();
|
|
65
|
+
if (typeof window === "undefined") {
|
|
66
|
+
return;
|
|
74
67
|
}
|
|
68
|
+
navigationTracker.current = new NavigationTracker(
|
|
69
|
+
(metadata) => {
|
|
70
|
+
void analyticsRef.current.pageView(metadata);
|
|
71
|
+
}
|
|
72
|
+
);
|
|
73
|
+
navigationTracker.current.init();
|
|
75
74
|
return () => {
|
|
76
75
|
navigationTracker.current?.cleanup();
|
|
77
76
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../analytics/analytics-provider.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\";\n\nimport type React from \"react\";\nimport type { AnalyticsSink } from \"./analytics-sink\";\nimport type { PageMetadata } from \"./utils/navigation-tracker\";\n\nimport { createContext, useContext, useEffect,
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type React from \"react\";\nimport type { AnalyticsSink } from \"./analytics-sink\";\nimport type { PageMetadata } from \"./utils/navigation-tracker\";\n\nimport { createContext, useContext, useEffect, useMemo, useRef } from \"react\";\n\nimport { useConsent } from \"../consent/consent-store\";\nimport { useRegisteredScripts } from \"../consent/script-registration-store\";\nimport { getAnalyticsSinks } from \"./get-analytics-sinks\";\nimport { NavigationTracker } from \"./utils/navigation-tracker\";\n\nfunction combineSinks(sinks: AnalyticsSink[]): AnalyticsSink {\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n const broadcast = async (method: keyof AnalyticsSink, ...args: any[]) => {\n if (typeof window !== \"undefined\") {\n console.debug(\n \"[analytics] broadcast\",\n method,\n \"to\",\n sinks.length,\n \"sinks\",\n { args },\n );\n }\n\n await Promise.all(\n sinks.map(async (sink) => {\n try {\n // Legacy cast - may or may not be necessary\n // oxlint-disable-next-line replo/no-as-cast, typescript/no-explicit-any -- legacy any/cast, may or may not be needed\n const sinkMethod = sink[method] as (...args: any[]) => Promise<void>;\n await sinkMethod.apply(sink, args);\n } catch {\n if (typeof window !== \"undefined\") {\n console.warn(\"[analytics] sink error\", { method, sink });\n }\n }\n }),\n );\n };\n\n return {\n pageView: (...args) => broadcast(\"pageView\", ...args),\n purchase: (...args) => broadcast(\"purchase\", ...args),\n click: (...args) => broadcast(\"click\", ...args),\n productViewed: (...args) => broadcast(\"productViewed\", ...args),\n addToCart: (...args) => broadcast(\"addToCart\", ...args),\n removeFromCart: (...args) => broadcast(\"removeFromCart\", ...args),\n viewCart: (...args) => broadcast(\"viewCart\", ...args),\n startCheckout: (...args) => broadcast(\"startCheckout\", ...args),\n viewCollection: (...args) => broadcast(\"viewCollection\", ...args),\n };\n}\n\ninterface AnalyticsContextType {\n analytics: AnalyticsSink | null;\n}\n\nconst AnalyticsContext = createContext<AnalyticsContextType | null>(null);\n\nexport function AnalyticsProvider({ children }: React.PropsWithChildren) {\n const consent = useConsent();\n const registeredScripts = useRegisteredScripts();\n\n // Sinks are derived from consent + which managed scripts are on the page, so\n // the set rebuilds whenever the visitor changes consent or a script mounts.\n const analytics = useMemo(() => {\n return combineSinks(\n getAnalyticsSinks({\n consent: {\n mode: consent.mode,\n categories: consent.categories,\n decidedAt: consent.decidedAt,\n },\n registeredScripts,\n }),\n );\n }, [consent.mode, consent.categories, consent.decidedAt, registeredScripts]);\n\n // The navigation tracker is set up once, but always dispatches to the latest\n // combined sink via a ref so consent/registration changes take effect.\n const analyticsRef = useRef(analytics);\n analyticsRef.current = analytics;\n const navigationTracker = useRef<NavigationTracker | null>(null);\n\n // eslint-disable-next-line replo/no-use-effect -- one-time SPA navigation tracking setup; dispatches through analyticsRef to stay current\n useEffect(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n navigationTracker.current = new NavigationTracker(\n (metadata: PageMetadata) => {\n void analyticsRef.current.pageView(metadata);\n },\n );\n navigationTracker.current.init();\n\n return () => {\n navigationTracker.current?.cleanup();\n };\n }, []);\n\n return (\n <AnalyticsContext.Provider value={{ analytics }}>\n {children}\n </AnalyticsContext.Provider>\n );\n}\n\nclass AnalyticsContextError extends Error {\n constructor({ message }: { message: string }) {\n super(message);\n }\n}\n\n/**\n * Returns the AnalyticsSink from the nearest AnalyticsProvider.\n * Throws if used outside of an AnalyticsProvider.\n */\nexport function useAnalytics(): AnalyticsSink | null {\n const context = useContext(AnalyticsContext);\n if (!context) {\n throw new AnalyticsContextError({\n message: \"useAnalytics must be used within <AnalyticsProvider>\",\n });\n }\n return context.analytics;\n}\n\n/**\n * Returns the AnalyticsSink if an AnalyticsProvider is present, or null otherwise.\n * Does not throw -- safe to use in components that may render with or without analytics.\n */\nexport function useAnalyticsOptional(): AnalyticsSink | null {\n const context = useContext(AnalyticsContext);\n return context?.analytics ?? null;\n}\n"],
|
|
5
|
+
"mappings": ";AAyGI;AAnGJ,SAAS,eAAe,YAAY,WAAW,SAAS,cAAc;AAEtE,SAAS,kBAAkB;AAC3B,SAAS,4BAA4B;AACrC,SAAS,yBAAyB;AAClC,SAAS,yBAAyB;AAElC,SAAS,aAAa,OAAuC;AAE3D,QAAM,YAAY,OAAO,WAAgC,SAAgB;AACvE,QAAI,OAAO,WAAW,aAAa;AACjC,cAAQ;AAAA,QACN;AAAA,QACA;AAAA,QACA;AAAA,QACA,MAAM;AAAA,QACN;AAAA,QACA,EAAE,KAAK;AAAA,MACT;AAAA,IACF;AAEA,UAAM,QAAQ;AAAA,MACZ,MAAM,IAAI,OAAO,SAAS;AACxB,YAAI;AAGF,gBAAM,aAAa,KAAK,MAAM;AAC9B,gBAAM,WAAW,MAAM,MAAM,IAAI;AAAA,QACnC,QAAQ;AACN,cAAI,OAAO,WAAW,aAAa;AACjC,oBAAQ,KAAK,0BAA0B,EAAE,QAAQ,KAAK,CAAC;AAAA,UACzD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AAAA,IACL,UAAU,IAAI,SAAS,UAAU,YAAY,GAAG,IAAI;AAAA,IACpD,UAAU,IAAI,SAAS,UAAU,YAAY,GAAG,IAAI;AAAA,IACpD,OAAO,IAAI,SAAS,UAAU,SAAS,GAAG,IAAI;AAAA,IAC9C,eAAe,IAAI,SAAS,UAAU,iBAAiB,GAAG,IAAI;AAAA,IAC9D,WAAW,IAAI,SAAS,UAAU,aAAa,GAAG,IAAI;AAAA,IACtD,gBAAgB,IAAI,SAAS,UAAU,kBAAkB,GAAG,IAAI;AAAA,IAChE,UAAU,IAAI,SAAS,UAAU,YAAY,GAAG,IAAI;AAAA,IACpD,eAAe,IAAI,SAAS,UAAU,iBAAiB,GAAG,IAAI;AAAA,IAC9D,gBAAgB,IAAI,SAAS,UAAU,kBAAkB,GAAG,IAAI;AAAA,EAClE;AACF;AAMA,MAAM,mBAAmB,cAA2C,IAAI;AAEjE,SAAS,kBAAkB,EAAE,SAAS,GAA4B;AACvE,QAAM,UAAU,WAAW;AAC3B,QAAM,oBAAoB,qBAAqB;AAI/C,QAAM,YAAY,QAAQ,MAAM;AAC9B,WAAO;AAAA,MACL,kBAAkB;AAAA,QAChB,SAAS;AAAA,UACP,MAAM,QAAQ;AAAA,UACd,YAAY,QAAQ;AAAA,UACpB,WAAW,QAAQ;AAAA,QACrB;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,QAAQ,MAAM,QAAQ,YAAY,QAAQ,WAAW,iBAAiB,CAAC;AAI3E,QAAM,eAAe,OAAO,SAAS;AACrC,eAAa,UAAU;AACvB,QAAM,oBAAoB,OAAiC,IAAI;AAG/D,YAAU,MAAM;AACd,QAAI,OAAO,WAAW,aAAa;AACjC;AAAA,IACF;AACA,sBAAkB,UAAU,IAAI;AAAA,MAC9B,CAAC,aAA2B;AAC1B,aAAK,aAAa,QAAQ,SAAS,QAAQ;AAAA,MAC7C;AAAA,IACF;AACA,sBAAkB,QAAQ,KAAK;AAE/B,WAAO,MAAM;AACX,wBAAkB,SAAS,QAAQ;AAAA,IACrC;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SACE,oBAAC,iBAAiB,UAAjB,EAA0B,OAAO,EAAE,UAAU,GAC3C,UACH;AAEJ;AAEA,MAAM,8BAA8B,MAAM;AAAA,EACxC,YAAY,EAAE,QAAQ,GAAwB;AAC5C,UAAM,OAAO;AAAA,EACf;AACF;AAMO,SAAS,eAAqC;AACnD,QAAM,UAAU,WAAW,gBAAgB;AAC3C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,sBAAsB;AAAA,MAC9B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AACA,SAAO,QAAQ;AACjB;AAMO,SAAS,uBAA6C;AAC3D,QAAM,UAAU,WAAW,gBAAgB;AAC3C,SAAO,SAAS,aAAa;AAC/B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ConsentState } from "../consent/consent-store";
|
|
2
|
+
import type { RegisteredScript } from "../consent/script-registration-store";
|
|
3
|
+
import type { AnalyticsSink } from "./analytics-sink";
|
|
4
|
+
/**
|
|
5
|
+
* Builds the set of analytics sinks that may fire given the current consent
|
|
6
|
+
* state and which managed scripts are registered on the page.
|
|
7
|
+
*
|
|
8
|
+
* Consent gates data egress, not in-page plumbing:
|
|
9
|
+
* - `WindowSink` is a local `CustomEvent` bus (no data leaves the device), so it
|
|
10
|
+
* always ships regardless of consent. Its consumers self-gate: managed pixels
|
|
11
|
+
* are already gated at the injection layer (they never mount without consent,
|
|
12
|
+
* so they never subscribe), and unmanaged custom scripts are the author's
|
|
13
|
+
* responsibility.
|
|
14
|
+
* - `ReploSink` forwards into Replo's first-party analytics pipeline (real
|
|
15
|
+
* egress / processing), so it counts as `analytics`-category tracking and is
|
|
16
|
+
* gated by that consent. It is an implicit sink this scaffold always ships
|
|
17
|
+
* (not tied to a registered entry) and is never editable in the miniapp.
|
|
18
|
+
*
|
|
19
|
+
* Third-party provider sinks are created only when a matching `<ReploScripts>`
|
|
20
|
+
* entry is registered AND its required consent is granted.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getAnalyticsSinks({ consent, registeredScripts, }: {
|
|
23
|
+
consent: ConsentState;
|
|
24
|
+
registeredScripts: RegisteredScript[];
|
|
25
|
+
}): AnalyticsSink[];
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isConsentAllowed } from "../consent/consent-store";
|
|
2
|
+
import { GA4Sink } from "./sinks/ga4-sink";
|
|
3
|
+
import { MetaSink } from "./sinks/meta-sink";
|
|
4
|
+
import { PinterestSink } from "./sinks/pinterest-sink";
|
|
5
|
+
import { RedditSink } from "./sinks/reddit-sink";
|
|
6
|
+
import { ReploSink } from "./sinks/replo-sink";
|
|
7
|
+
import { SnapchatSink } from "./sinks/snapchat-sink";
|
|
8
|
+
import { TikTokSink } from "./sinks/tiktok-sink";
|
|
9
|
+
import { WindowSink } from "./sinks/window-sink";
|
|
10
|
+
const PROVIDER_SINK_FACTORIES = {
|
|
11
|
+
GA4: () => new GA4Sink(),
|
|
12
|
+
Meta: () => new MetaSink(),
|
|
13
|
+
TikTok: () => new TikTokSink(),
|
|
14
|
+
Snapchat: () => new SnapchatSink(),
|
|
15
|
+
Pinterest: () => new PinterestSink(),
|
|
16
|
+
Reddit: () => new RedditSink()
|
|
17
|
+
};
|
|
18
|
+
function getAnalyticsSinks({
|
|
19
|
+
consent,
|
|
20
|
+
registeredScripts
|
|
21
|
+
}) {
|
|
22
|
+
const sinks = [new WindowSink()];
|
|
23
|
+
const firstPartyAllowed = consent.mode === "off" || consent.categories.analytics;
|
|
24
|
+
if (firstPartyAllowed) {
|
|
25
|
+
sinks.push(new ReploSink());
|
|
26
|
+
}
|
|
27
|
+
const addedTypes = /* @__PURE__ */ new Set();
|
|
28
|
+
for (const script of registeredScripts) {
|
|
29
|
+
const factory = PROVIDER_SINK_FACTORIES[script.type];
|
|
30
|
+
if (!factory || addedTypes.has(script.type)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (isConsentAllowed({
|
|
34
|
+
state: consent,
|
|
35
|
+
requiredConsent: script.requiredConsent
|
|
36
|
+
})) {
|
|
37
|
+
sinks.push(factory());
|
|
38
|
+
addedTypes.add(script.type);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return sinks;
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
getAnalyticsSinks
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=get-analytics-sinks.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../analytics/get-analytics-sinks.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ReploScriptType } from \"schemas/generated/consent\";\nimport type { ConsentState } from \"../consent/consent-store\";\nimport type { RegisteredScript } from \"../consent/script-registration-store\";\nimport type { AnalyticsSink } from \"./analytics-sink\";\n\nimport { isConsentAllowed } from \"../consent/consent-store\";\nimport { GA4Sink } from \"./sinks/ga4-sink\";\nimport { MetaSink } from \"./sinks/meta-sink\";\nimport { PinterestSink } from \"./sinks/pinterest-sink\";\nimport { RedditSink } from \"./sinks/reddit-sink\";\nimport { ReploSink } from \"./sinks/replo-sink\";\nimport { SnapchatSink } from \"./sinks/snapchat-sink\";\nimport { TikTokSink } from \"./sinks/tiktok-sink\";\nimport { WindowSink } from \"./sinks/window-sink\";\n\n/**\n * Named providers that have a corresponding ecommerce-event sink. The other\n * managed providers (GoogleTagManager, Hotjar, MicrosoftClarity, Triplewhale,\n * Segment) load scripts but do not map to `AnalyticsSink` events today, so they\n * never produce a sink here.\n */\nconst PROVIDER_SINK_FACTORIES: Partial<\n Record<ReploScriptType, () => AnalyticsSink>\n> = {\n GA4: () => new GA4Sink(),\n Meta: () => new MetaSink(),\n TikTok: () => new TikTokSink(),\n Snapchat: () => new SnapchatSink(),\n Pinterest: () => new PinterestSink(),\n Reddit: () => new RedditSink(),\n};\n\n/**\n * Builds the set of analytics sinks that may fire given the current consent\n * state and which managed scripts are registered on the page.\n *\n * Consent gates data egress, not in-page plumbing:\n * - `WindowSink` is a local `CustomEvent` bus (no data leaves the device), so it\n * always ships regardless of consent. Its consumers self-gate: managed pixels\n * are already gated at the injection layer (they never mount without consent,\n * so they never subscribe), and unmanaged custom scripts are the author's\n * responsibility.\n * - `ReploSink` forwards into Replo's first-party analytics pipeline (real\n * egress / processing), so it counts as `analytics`-category tracking and is\n * gated by that consent. It is an implicit sink this scaffold always ships\n * (not tied to a registered entry) and is never editable in the miniapp.\n *\n * Third-party provider sinks are created only when a matching `<ReploScripts>`\n * entry is registered AND its required consent is granted.\n */\nexport function getAnalyticsSinks({\n consent,\n registeredScripts,\n}: {\n consent: ConsentState;\n registeredScripts: RegisteredScript[];\n}): AnalyticsSink[] {\n const sinks: AnalyticsSink[] = [new WindowSink()];\n\n const firstPartyAllowed =\n consent.mode === \"off\" || consent.categories.analytics;\n if (firstPartyAllowed) {\n sinks.push(new ReploSink());\n }\n\n const addedTypes = new Set<ReploScriptType>();\n for (const script of registeredScripts) {\n const factory = PROVIDER_SINK_FACTORIES[script.type];\n if (!factory || addedTypes.has(script.type)) {\n continue;\n }\n if (\n isConsentAllowed({\n state: consent,\n requiredConsent: script.requiredConsent,\n })\n ) {\n sinks.push(factory());\n addedTypes.add(script.type);\n }\n }\n\n return sinks;\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,wBAAwB;AACjC,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;AAQ3B,MAAM,0BAEF;AAAA,EACF,KAAK,MAAM,IAAI,QAAQ;AAAA,EACvB,MAAM,MAAM,IAAI,SAAS;AAAA,EACzB,QAAQ,MAAM,IAAI,WAAW;AAAA,EAC7B,UAAU,MAAM,IAAI,aAAa;AAAA,EACjC,WAAW,MAAM,IAAI,cAAc;AAAA,EACnC,QAAQ,MAAM,IAAI,WAAW;AAC/B;AAoBO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAGoB;AAClB,QAAM,QAAyB,CAAC,IAAI,WAAW,CAAC;AAEhD,QAAM,oBACJ,QAAQ,SAAS,SAAS,QAAQ,WAAW;AAC/C,MAAI,mBAAmB;AACrB,UAAM,KAAK,IAAI,UAAU,CAAC;AAAA,EAC5B;AAEA,QAAM,aAAa,oBAAI,IAAqB;AAC5C,aAAW,UAAU,mBAAmB;AACtC,UAAM,UAAU,wBAAwB,OAAO,IAAI;AACnD,QAAI,CAAC,WAAW,WAAW,IAAI,OAAO,IAAI,GAAG;AAC3C;AAAA,IACF;AACA,QACE,iBAAiB;AAAA,MACf,OAAO;AAAA,MACP,iBAAiB,OAAO;AAAA,IAC1B,CAAC,GACD;AACA,YAAM,KAAK,QAAQ,CAAC;AACpB,iBAAW,IAAI,OAAO,IAAI;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObject.js
|
|
2
|
+
function isObject(value) {
|
|
3
|
+
var type = typeof value;
|
|
4
|
+
return value != null && (type == "object" || type == "function");
|
|
5
|
+
}
|
|
6
|
+
var isObject_default = isObject;
|
|
7
|
+
|
|
8
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isArray.js
|
|
9
|
+
var isArray = Array.isArray;
|
|
10
|
+
var isArray_default = isArray;
|
|
11
|
+
|
|
12
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_freeGlobal.js
|
|
13
|
+
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
14
|
+
var freeGlobal_default = freeGlobal;
|
|
15
|
+
|
|
16
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_root.js
|
|
17
|
+
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
|
|
18
|
+
var root = freeGlobal_default || freeSelf || Function("return this")();
|
|
19
|
+
var root_default = root;
|
|
20
|
+
|
|
21
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Symbol.js
|
|
22
|
+
var Symbol = root_default.Symbol;
|
|
23
|
+
var Symbol_default = Symbol;
|
|
24
|
+
|
|
25
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_getRawTag.js
|
|
26
|
+
var objectProto = Object.prototype;
|
|
27
|
+
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
28
|
+
var nativeObjectToString = objectProto.toString;
|
|
29
|
+
var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
30
|
+
function getRawTag(value) {
|
|
31
|
+
var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
32
|
+
try {
|
|
33
|
+
value[symToStringTag] = void 0;
|
|
34
|
+
var unmasked = true;
|
|
35
|
+
} catch (e) {
|
|
36
|
+
}
|
|
37
|
+
var result = nativeObjectToString.call(value);
|
|
38
|
+
if (unmasked) {
|
|
39
|
+
if (isOwn) {
|
|
40
|
+
value[symToStringTag] = tag;
|
|
41
|
+
} else {
|
|
42
|
+
delete value[symToStringTag];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
var getRawTag_default = getRawTag;
|
|
48
|
+
|
|
49
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_objectToString.js
|
|
50
|
+
var objectProto2 = Object.prototype;
|
|
51
|
+
var nativeObjectToString2 = objectProto2.toString;
|
|
52
|
+
function objectToString(value) {
|
|
53
|
+
return nativeObjectToString2.call(value);
|
|
54
|
+
}
|
|
55
|
+
var objectToString_default = objectToString;
|
|
56
|
+
|
|
57
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseGetTag.js
|
|
58
|
+
var nullTag = "[object Null]";
|
|
59
|
+
var undefinedTag = "[object Undefined]";
|
|
60
|
+
var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0;
|
|
61
|
+
function baseGetTag(value) {
|
|
62
|
+
if (value == null) {
|
|
63
|
+
return value === void 0 ? undefinedTag : nullTag;
|
|
64
|
+
}
|
|
65
|
+
return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value);
|
|
66
|
+
}
|
|
67
|
+
var baseGetTag_default = baseGetTag;
|
|
68
|
+
|
|
69
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isObjectLike.js
|
|
70
|
+
function isObjectLike(value) {
|
|
71
|
+
return value != null && typeof value == "object";
|
|
72
|
+
}
|
|
73
|
+
var isObjectLike_default = isObjectLike;
|
|
74
|
+
|
|
75
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNumber.js
|
|
76
|
+
var numberTag = "[object Number]";
|
|
77
|
+
function isNumber(value) {
|
|
78
|
+
return typeof value == "number" || isObjectLike_default(value) && baseGetTag_default(value) == numberTag;
|
|
79
|
+
}
|
|
80
|
+
var isNumber_default = isNumber;
|
|
81
|
+
|
|
82
|
+
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isString.js
|
|
83
|
+
var stringTag = "[object String]";
|
|
84
|
+
function isString(value) {
|
|
85
|
+
return typeof value == "string" || !isArray_default(value) && isObjectLike_default(value) && baseGetTag_default(value) == stringTag;
|
|
86
|
+
}
|
|
87
|
+
var isString_default = isString;
|
|
88
|
+
|
|
89
|
+
export { Symbol_default, baseGetTag_default, freeGlobal_default, isArray_default, isNumber_default, isObjectLike_default, isObject_default, isString_default, root_default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// ../replo-utils/lib/object.ts
|
|
2
|
+
function omit(obj, keysToOmit) {
|
|
3
|
+
const result = { ...obj };
|
|
4
|
+
for (const key of keysToOmit) {
|
|
5
|
+
delete result[key];
|
|
6
|
+
}
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// ../replo-utils/lib/json.ts
|
|
11
|
+
function parseJsonOrNull(json) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(json);
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function omitJsonObjectFieldsOrNull({
|
|
19
|
+
json,
|
|
20
|
+
fields
|
|
21
|
+
}) {
|
|
22
|
+
const parsedJson = parseJsonOrNull(json);
|
|
23
|
+
if (typeof parsedJson !== "object" || parsedJson === null || Array.isArray(parsedJson)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return jsonStringifyOrNull(
|
|
27
|
+
omit(Object.fromEntries(Object.entries(parsedJson)), fields)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function jsonStringifyOrNull(value) {
|
|
31
|
+
if (value === null || value === void 0) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return JSON.stringify(value);
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { jsonStringifyOrNull, omitJsonObjectFieldsOrNull, parseJsonOrNull };
|