@replohq/canopy-sdk 0.3.1 → 0.4.1

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.
@@ -1,4 +1,4 @@
1
- type ValueOfType<T> = T[keyof T];
1
+ type ValueOfType<ObjectType> = ObjectType[keyof ObjectType];
2
2
  /**
3
3
  * Mostly taken from
4
4
  * https://gist.githubusercontent.com/scokmen/f813c904ef79022e84ab2409574d1b45/raw/cd8709a2fccb005bb53e9bfb2461e07d40b4e8d8/HttpStatusCode.ts
@@ -17,18 +17,33 @@ export declare function quoteFontFamily(family: string): string;
17
17
  * "DM Sans" → "dmSans". The JS const name for a `next/font` declaration.
18
18
  */
19
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
20
  /**
31
21
  * Google Fonts CSS2 stylesheet URL for a family at the given weights (defaulting
32
22
  * to 400), with `display=swap`.
33
23
  */
34
24
  export declare function buildGoogleFontsCssUrl(family: string, weights?: number[]): string;
25
+ /**
26
+ * "Brand Sans-Bold.woff2" → { family: "Brand Sans Bold", mimeType: "font/woff2" }.
27
+ * The family is derived from the filename since Bedrock assets don't store one.
28
+ */
29
+ export declare function describeFontFile(fileName: string): {
30
+ family: string;
31
+ mimeType: string;
32
+ };
33
+ /**
34
+ * The `format(...)` keyword for an @font-face src, from a font file extension
35
+ * (Bedrock's `find` returns `fileExtension`, not a MIME type).
36
+ */
37
+ export declare function fontFormatFromExtension(extension: string): string;
38
+ /** The `format(...)` keyword for an @font-face src, from a font MIME type. */
39
+ export declare function fontFormatFromMimeType(mimeType: string): string;
40
+ /**
41
+ * The @font-face rule that makes a custom family renderable from its asset URL.
42
+ */
43
+ export declare function buildFontFaceCss({ family, faceUrl, format, weight, }: {
44
+ family: string;
45
+ faceUrl: string;
46
+ format: string;
47
+ weight?: number;
48
+ }): string;
49
+ export declare const escapeFontFamilyName: (fontFamily: string) => string;
@@ -0,0 +1,78 @@
1
+ // ../replo-utils/lib/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
+ var FONT_MIME_BY_EXTENSION = {
28
+ woff2: "font/woff2",
29
+ woff: "font/woff",
30
+ ttf: "font/ttf",
31
+ otf: "font/otf"
32
+ };
33
+ function describeFontFile(fileName) {
34
+ const lastDot = fileName.lastIndexOf(".");
35
+ const base = lastDot > 0 ? fileName.slice(0, lastDot) : fileName;
36
+ const extension = lastDot > 0 ? fileName.slice(lastDot + 1).toLowerCase() : "";
37
+ const family = base.replace(/[_-]+/gu, " ").replace(/\s+/gu, " ").trim() || "Custom font";
38
+ return {
39
+ family,
40
+ mimeType: FONT_MIME_BY_EXTENSION[extension] ?? "font/woff2"
41
+ };
42
+ }
43
+ function fontFormatFromExtension(extension) {
44
+ const normalized = extension.toLowerCase().replace(/^\./u, "");
45
+ if (normalized === "woff2") return "woff2";
46
+ if (normalized === "woff") return "woff";
47
+ if (normalized === "otf") return "opentype";
48
+ if (normalized === "ttf") return "truetype";
49
+ return "woff2";
50
+ }
51
+ function fontFormatFromMimeType(mimeType) {
52
+ const normalized = mimeType.toLowerCase();
53
+ if (normalized.includes("woff2")) return "woff2";
54
+ if (normalized.includes("woff")) return "woff";
55
+ if (normalized.includes("otf") || normalized.includes("opentype")) {
56
+ return "opentype";
57
+ }
58
+ if (normalized.includes("ttf") || normalized.includes("truetype")) {
59
+ return "truetype";
60
+ }
61
+ return "woff2";
62
+ }
63
+ function escapeCssString(value) {
64
+ return value.replace(/\\/gu, "\\\\").replace(/"/gu, '\\"');
65
+ }
66
+ function buildFontFaceCss({
67
+ family,
68
+ faceUrl,
69
+ format,
70
+ weight = 400
71
+ }) {
72
+ return `@font-face{font-family:"${escapeCssString(family)}";font-weight:${weight};font-style:normal;src:url("${escapeCssString(faceUrl)}") format("${escapeCssString(format)}");font-display:swap;}`;
73
+ }
74
+ var escapeFontFamilyName = (fontFamily) => {
75
+ return fontFamily.replace(/"/g, '\\"').replace(/'/g, "\\'");
76
+ };
77
+
78
+ export { buildFontFaceCss, buildGoogleFontsCssUrl, describeFontFile, escapeFontFamilyName, fontFormatFromExtension, fontFormatFromMimeType, fontNameToCssVariable, fontNameToVariableName, quoteFontFamily, slugifyFontFamily };
@@ -5,7 +5,7 @@ export { isFunction, isNumber, isString };
5
5
  /**
6
6
  * Checks if a value is neither `null` nor `undefined`.
7
7
  */
8
- export declare function isNotNullish<T>(value: T): value is Exclude<T, null | undefined>;
8
+ export declare function isNotNullish<ValueType>(value: ValueType): value is Exclude<ValueType, null | undefined>;
9
9
  /**
10
10
  * Checks if a value is either `null` or `undefined`.
11
11
  */
@@ -14,13 +14,13 @@ export declare function isRecord(value: unknown): value is Record<string, unknow
14
14
  export declare function stringValue(value: unknown): string | null;
15
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;
16
16
  export declare function isPrimitive(value: unknown): value is string | number | boolean;
17
- type StructureRecord<A extends {
17
+ type StructureRecord<UnionType extends {
18
18
  type: string;
19
- }, R> = {
20
- [T in A as T["type"]]: R | ((value: T) => R);
19
+ }, ResultType> = {
20
+ [MemberType in UnionType as MemberType["type"]]: ResultType | ((value: MemberType) => ResultType);
21
21
  };
22
- type StructureRecordGeneric<A extends Record<K, string>, R, K extends keyof A> = {
23
- [T in A as T[K]]: R | ((value: T) => R);
22
+ type StructureRecordGeneric<UnionType extends Record<KeyType, string>, ResultType, KeyType extends keyof UnionType> = {
23
+ [MemberType in UnionType as MemberType[KeyType]]: ResultType | ((value: MemberType) => ResultType);
24
24
  };
25
25
  /**
26
26
  * @returns A function which can be used to create an exhaustive switch over all
@@ -61,26 +61,26 @@ type StructureRecordGeneric<A extends Record<K, string>, R, K extends keyof A> =
61
61
  *
62
62
  * Works well for many of our types, like ComponentActionType, Action, etc
63
63
  */
64
- export declare function exhaustiveSwitch<A extends {
64
+ export declare function exhaustiveSwitch<UnionType extends {
65
65
  type: string;
66
- }>(value: A): <R>(cases: StructureRecord<A, R>) => R;
67
- export declare function exhaustiveSwitch<A extends Record<K, string>, K extends keyof A>(value: A, key: K): <R>(cases: StructureRecordGeneric<A, R, K>) => R;
68
- type EmptyObject<T> = {
69
- [K in keyof T]?: never;
66
+ }>(value: UnionType): <ResultType>(cases: StructureRecord<UnionType, ResultType>) => ResultType;
67
+ export declare function exhaustiveSwitch<UnionType extends Record<KeyType, string>, KeyType extends keyof UnionType>(value: UnionType, key: KeyType): <ResultType>(cases: StructureRecordGeneric<UnionType, ResultType, KeyType>) => ResultType;
68
+ type EmptyObject<ObjectType> = {
69
+ [KeyType in keyof ObjectType]?: never;
70
70
  };
71
- type EmptyObjectOf<T> = EmptyObject<T> extends T ? EmptyObject<T> : never;
71
+ type EmptyObjectOf<ObjectType> = EmptyObject<ObjectType> extends ObjectType ? EmptyObject<ObjectType> : never;
72
72
  /**
73
73
  * The same as `isEmpty` from lodash, but with a few additional overloads for
74
74
  * stronger type-checking on empty arrays.
75
75
  */
76
76
  export declare function isEmpty(value: string): value is "";
77
- export declare function isEmpty<T extends any[]>(value: T | null | undefined): value is (T & []) | null | undefined;
78
- export declare function isEmpty<T extends ArrayLike<any>>(value: T | null | undefined): value is (T & {
77
+ export declare function isEmpty<ArrayType extends any[]>(value: ArrayType | null | undefined): value is (ArrayType & []) | null | undefined;
78
+ export declare function isEmpty<ArrayLikeType extends ArrayLike<any>>(value: ArrayLikeType | null | undefined): value is (ArrayLikeType & {
79
79
  length: 0;
80
80
  }) | null | undefined;
81
81
  export declare function isEmpty(value: Map<any, any> | Set<any> | ArrayLike<any> | null | undefined): boolean;
82
82
  export declare function isEmpty(value: object): boolean;
83
- export declare function isEmpty<T extends object>(value: T | null | undefined): value is EmptyObjectOf<T> | null | undefined;
83
+ export declare function isEmpty<ObjectType extends object>(value: ObjectType | null | undefined): value is EmptyObjectOf<ObjectType> | null | undefined;
84
84
  export declare function isEmpty(value?: any): boolean;
85
85
  export declare function noop(): void;
86
86
  export declare function preventDefault(event: {
@@ -103,13 +103,13 @@ export declare function invariant(condition: unknown, message: string | (() => s
103
103
  }): asserts condition;
104
104
  export declare const mergeReplacingObjects: (first: Object, second: Object) => void;
105
105
  export declare const mergeReplacingArrays: (first: Object, second: Object) => void;
106
- export declare const deepCloneAndMergeReplacingArrays: <T>(source: T, ...toMerge: Object[]) => T;
106
+ export declare const deepCloneAndMergeReplacingArrays: <SourceType>(source: SourceType, ...toMerge: Object[]) => SourceType;
107
107
  /**
108
108
  * hasOwnProperty with a type assertion. If this returns true, typescript knows that `obj`
109
109
  * has a property called `prop` from that point forward
110
110
  * https://fettblog.eu/typescript-hasownproperty/
111
111
  */
112
- export declare function hasOwnProperty<X extends {} | null | undefined, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>;
112
+ export declare function hasOwnProperty<ObjectType extends {} | null | undefined, PropType extends PropertyKey>(obj: ObjectType, prop: PropType): obj is ObjectType & Record<PropType, unknown>;
113
113
  /**
114
114
  * Given a string | number param, converts it to a string, unless it's nullish
115
115
  * in which case it just returns it. Useful for times when you have string | number
@@ -25,7 +25,7 @@ export declare const deepEqual: typeof dequalLite;
25
25
  * @param keysToOmit - Array of keys to omit from the result
26
26
  * @returns A new object without the specified keys
27
27
  */
28
- export declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keysToOmit: K[]): Omit<T, K>;
29
- export declare function filterUndefined<T extends Record<string, unknown>>(data: T): Partial<T>;
30
- export declare function toNullableIfDefined<T>(value: T | undefined): T | null | undefined;
28
+ export declare function omit<ObjectType extends Record<string, any>, KeyType extends keyof ObjectType>(obj: ObjectType, keysToOmit: KeyType[]): Omit<ObjectType, KeyType>;
29
+ export declare function filterUndefined<ObjectType extends Record<string, unknown>>(data: ObjectType): Partial<ObjectType>;
30
+ export declare function toNullableIfDefined<ValueType>(value: ValueType | undefined): ValueType | null | undefined;
31
31
  export {};
@@ -4,7 +4,7 @@ import type { z } from "zod";
4
4
  * environmental variables that need to be access via the full object path, like
5
5
  * `process.env.COMMIT`.
6
6
  */
7
- export declare function parseOrDefault<T extends z.ZodType<any, any>>(value: string | undefined, schema: T, defaultValue: z.infer<T>): z.infer<T>;
7
+ export declare function parseOrDefault<SchemaType extends z.ZodType<any, any>>(value: string | undefined, schema: SchemaType, defaultValue: z.infer<SchemaType>): z.infer<SchemaType>;
8
8
  /**
9
9
  * Parse an arbitrary value using the zod schema, returning `null` on
10
10
  * failure. Use this for the common pattern of validating untrusted
@@ -326,6 +326,21 @@ export declare const globalsCssSnapshotSchema: z.ZodObject<{
326
326
  }, z.core.$strip>>;
327
327
  }, z.core.$strip>>;
328
328
  }, z.core.$strip>;
329
+ export declare const siteFontRoleSchema: z.ZodObject<{
330
+ role: z.ZodString;
331
+ family: z.ZodNullable<z.ZodString>;
332
+ cssVar: z.ZodNullable<z.ZodString>;
333
+ rawValue: z.ZodString;
334
+ }, z.core.$strip>;
335
+ export declare const siteFontsSnapshotSchema: z.ZodObject<{
336
+ roles: z.ZodArray<z.ZodObject<{
337
+ role: z.ZodString;
338
+ family: z.ZodNullable<z.ZodString>;
339
+ cssVar: z.ZodNullable<z.ZodString>;
340
+ rawValue: z.ZodString;
341
+ }, z.core.$strip>>;
342
+ defaultRole: z.ZodNullable<z.ZodString>;
343
+ }, z.core.$strip>;
329
344
  export declare const DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE = "replo:design-library:applyOverrides";
330
345
  export declare const designLibraryPreviewFontSchema: z.ZodObject<{
331
346
  family: z.ZodString;
@@ -99,6 +99,16 @@ var globalsCssScopeSchema = z.object({
99
99
  var globalsCssSnapshotSchema = z.object({
100
100
  scopes: z.array(globalsCssScopeSchema)
101
101
  }).describe("GlobalsCssSnapshot");
102
+ var siteFontRoleSchema = z.object({
103
+ role: z.string(),
104
+ family: z.string().nullable(),
105
+ cssVar: z.string().nullable(),
106
+ rawValue: z.string()
107
+ }).describe("SiteFontRole");
108
+ var siteFontsSnapshotSchema = z.object({
109
+ roles: z.array(siteFontRoleSchema),
110
+ defaultRole: z.string().nullable()
111
+ }).describe("SiteFontsSnapshot");
102
112
  var DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE = "replo:design-library:applyOverrides";
103
113
  var designLibraryPreviewFontSchema = z.object({
104
114
  family: z.string(),
@@ -113,4 +123,4 @@ var designLibraryPreviewMessageSchema = z.object({
113
123
  defaultFontCssVar: z.string().nullable()
114
124
  }).describe("DesignLibraryPreviewMessage");
115
125
 
116
- export { DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE, designLibraryPreviewFontSchema, designLibraryPreviewMessageSchema, designLibrarySavedStyleMetadataSchema, designLibrarySavedStylesSchema, designLibrarySchema, globalsCssScopeSchema, globalsCssSnapshotSchema, globalsCssTokenSchema, savedColorStyleSchema, savedTextStyleSchema };
126
+ export { DESIGN_LIBRARY_PREVIEW_MESSAGE_TYPE, designLibraryPreviewFontSchema, designLibraryPreviewMessageSchema, designLibrarySavedStyleMetadataSchema, designLibrarySavedStylesSchema, designLibrarySchema, globalsCssScopeSchema, globalsCssSnapshotSchema, globalsCssTokenSchema, savedColorStyleSchema, savedTextStyleSchema, siteFontRoleSchema, siteFontsSnapshotSchema };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Resolves the Replo first-party pixel's config from the worker env and hands it
3
+ * to the consent-gated client injector. This lives inside `ReploProvider` (not
4
+ * the site's `app/layout.tsx`) so every agent site ships the implicit
5
+ * first-party pixel automatically — mirroring how `ReploSink` is an always-on
6
+ * sink that is never authored in the layout or editable in the miniapp.
7
+ *
8
+ * Renders nothing when the analytics pipeline isn't wired (e.g. lean local dev,
9
+ * where `REPLO_ANALYTICS_PIXEL_URL` / `ANALYTICS_FIRE_API_URL` are unset),
10
+ * mirroring the self-disabling consent action.
11
+ */
12
+ export declare function ReploFirstPartyPixel(): Promise<import("react/jsx-runtime").JSX.Element | null>;
@@ -0,0 +1,31 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { getEnv } from "../env";
3
+ import { ReploPixelScript } from "./replo-pixel-script";
4
+ async function ReploFirstPartyPixel() {
5
+ let pixelUrl;
6
+ let apiUrl;
7
+ let projectId;
8
+ try {
9
+ const env = await getEnv();
10
+ pixelUrl = env.REPLO_ANALYTICS_PIXEL_URL;
11
+ apiUrl = env.ANALYTICS_FIRE_API_URL;
12
+ projectId = env.PROJECT_ID;
13
+ } catch {
14
+ return null;
15
+ }
16
+ if (!pixelUrl || !apiUrl || !projectId) {
17
+ return null;
18
+ }
19
+ return /* @__PURE__ */ jsx(
20
+ ReploPixelScript,
21
+ {
22
+ pixelUrl,
23
+ apiUrl,
24
+ projectId
25
+ }
26
+ );
27
+ }
28
+ export {
29
+ ReploFirstPartyPixel
30
+ };
31
+ //# sourceMappingURL=replo-first-party-pixel.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../analytics/replo-first-party-pixel.tsx"],
4
+ "sourcesContent": ["import { getEnv } from \"../env\";\nimport { ReploPixelScript } from \"./replo-pixel-script\";\n\n/**\n * Resolves the Replo first-party pixel's config from the worker env and hands it\n * to the consent-gated client injector. This lives inside `ReploProvider` (not\n * the site's `app/layout.tsx`) so every agent site ships the implicit\n * first-party pixel automatically \u2014 mirroring how `ReploSink` is an always-on\n * sink that is never authored in the layout or editable in the miniapp.\n *\n * Renders nothing when the analytics pipeline isn't wired (e.g. lean local dev,\n * where `REPLO_ANALYTICS_PIXEL_URL` / `ANALYTICS_FIRE_API_URL` are unset),\n * mirroring the self-disabling consent action.\n */\nexport async function ReploFirstPartyPixel() {\n let pixelUrl: string | undefined;\n let apiUrl: string | undefined;\n let projectId: string | undefined;\n try {\n const env = await getEnv();\n pixelUrl = env.REPLO_ANALYTICS_PIXEL_URL;\n apiUrl = env.ANALYTICS_FIRE_API_URL;\n projectId = env.PROJECT_ID;\n } catch {\n // No Cloudflare env (e.g. running the site outside the worker): no pixel.\n return null;\n }\n\n if (!pixelUrl || !apiUrl || !projectId) {\n return null;\n }\n\n return (\n <ReploPixelScript\n pixelUrl={pixelUrl}\n apiUrl={apiUrl}\n projectId={projectId}\n />\n );\n}\n"],
5
+ "mappings": "AAiCI;AAjCJ,SAAS,cAAc;AACvB,SAAS,wBAAwB;AAajC,eAAsB,uBAAuB;AAC3C,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACF,UAAM,MAAM,MAAM,OAAO;AACzB,eAAW,IAAI;AACf,aAAS,IAAI;AACb,gBAAY,IAAI;AAAA,EAClB,QAAQ;AAEN,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,YAAY,CAAC,UAAU,CAAC,WAAW;AACtC,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Consent-gated injector for Replo's first-party analytics pixel. The loaded
3
+ * script sets `window.ReploPixel`, which the always-on `ReploSink` forwards
4
+ * events into, so gating it on `analytics` consent keeps the first-party sink
5
+ * consent-correct without the pixel loading unconditionally in `<head>` the way
6
+ * the legacy scaffold does. `analytics` consent here matches the
7
+ * `firstPartyAllowed` gate that controls whether `ReploSink` is created at all.
8
+ */
9
+ export declare function ReploPixelScript({ pixelUrl, apiUrl, projectId, }: {
10
+ pixelUrl: string;
11
+ apiUrl: string;
12
+ projectId: string;
13
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { isConsentAllowed, useConsent } from "../consent/consent-store";
4
+ import { InjectedScript } from "../consent/replo-scripts";
5
+ const PIXEL_SCRIPT_ID = "replo:first-party-pixel";
6
+ function ReploPixelScript({
7
+ pixelUrl,
8
+ apiUrl,
9
+ projectId
10
+ }) {
11
+ const consent = useConsent();
12
+ if (!isConsentAllowed({ state: consent, requiredConsent: ["analytics"] })) {
13
+ return null;
14
+ }
15
+ const descriptors = [
16
+ {
17
+ kind: "external",
18
+ src: `${pixelUrl}/latest.js`,
19
+ attributes: {
20
+ "data-api-url": apiUrl,
21
+ "data-project-id": projectId
22
+ }
23
+ }
24
+ ];
25
+ return /* @__PURE__ */ jsx(InjectedScript, { baseId: PIXEL_SCRIPT_ID, descriptors });
26
+ }
27
+ export {
28
+ ReploPixelScript
29
+ };
30
+ //# sourceMappingURL=replo-pixel-script.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../analytics/replo-pixel-script.tsx"],
4
+ "sourcesContent": ["\"use client\";\n\nimport type { ScriptTagDescriptor } from \"schemas/generated/consent\";\n\nimport { isConsentAllowed, useConsent } from \"../consent/consent-store\";\nimport { InjectedScript } from \"../consent/replo-scripts\";\n\n// Stable injection id so re-renders and React Strict Mode double-invokes never\n// inject the pixel twice (the loader itself also guards via `__reploPixelLoaded`).\nconst PIXEL_SCRIPT_ID = \"replo:first-party-pixel\";\n\n/**\n * Consent-gated injector for Replo's first-party analytics pixel. The loaded\n * script sets `window.ReploPixel`, which the always-on `ReploSink` forwards\n * events into, so gating it on `analytics` consent keeps the first-party sink\n * consent-correct without the pixel loading unconditionally in `<head>` the way\n * the legacy scaffold does. `analytics` consent here matches the\n * `firstPartyAllowed` gate that controls whether `ReploSink` is created at all.\n */\nexport function ReploPixelScript({\n pixelUrl,\n apiUrl,\n projectId,\n}: {\n pixelUrl: string;\n apiUrl: string;\n projectId: string;\n}) {\n const consent = useConsent();\n if (!isConsentAllowed({ state: consent, requiredConsent: [\"analytics\"] })) {\n return null;\n }\n\n const descriptors: ScriptTagDescriptor[] = [\n {\n kind: \"external\",\n src: `${pixelUrl}/latest.js`,\n attributes: {\n \"data-api-url\": apiUrl,\n \"data-project-id\": projectId,\n },\n },\n ];\n\n return <InjectedScript baseId={PIXEL_SCRIPT_ID} descriptors={descriptors} />;\n}\n"],
5
+ "mappings": ";AA4CS;AAxCT,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,sBAAsB;AAI/B,MAAM,kBAAkB;AAUjB,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACD,QAAM,UAAU,WAAW;AAC3B,MAAI,CAAC,iBAAiB,EAAE,OAAO,SAAS,iBAAiB,CAAC,WAAW,EAAE,CAAC,GAAG;AACzE,WAAO;AAAA,EACT;AAEA,QAAM,cAAqC;AAAA,IACzC;AAAA,MACE,MAAM;AAAA,MACN,KAAK,GAAG,QAAQ;AAAA,MAChB,YAAY;AAAA,QACV,gBAAgB;AAAA,QAChB,mBAAmB;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEA,SAAO,oBAAC,kBAAe,QAAQ,iBAAiB,aAA0B;AAC5E;",
6
+ "names": []
7
+ }
@@ -3,5 +3,5 @@ type MethodQueueOptions = {
3
3
  queueName?: string;
4
4
  onTimeout?: () => void;
5
5
  };
6
- export declare function createMethodQueue<T extends Record<string, (...args: any[]) => any>>(checkInstanceReady: () => T | null, options?: MethodQueueOptions): (method: keyof T, ...args: any[]) => void;
6
+ export declare function createMethodQueue<InstanceType extends Record<string, (...args: any[]) => any>>(checkInstanceReady: () => InstanceType | null, options?: MethodQueueOptions): (method: keyof InstanceType, ...args: any[]) => void;
7
7
  export {};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../analytics/utils/analytics-utils.ts"],
4
- "sourcesContent": ["// oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\ntype QueuedEvent = { event: string; params: Record<string, any> };\n\nexport function createEventQueue(\n checkPixelReady: () => boolean,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n sendEvent: (event: string, params: Record<string, any>) => void,\n pixelName: string,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n): (event: string, params?: Record<string, any>) => void {\n const queue: QueuedEvent[] = [];\n let flushTimer: number | null = null;\n let timeoutTimer: number | null = null;\n let permanentlyDisabled = false;\n\n const cleanup = () => {\n if (flushTimer !== null) {\n window.clearInterval(flushTimer);\n flushTimer = null;\n }\n if (timeoutTimer !== null) {\n window.clearTimeout(timeoutTimer);\n timeoutTimer = null;\n }\n };\n\n const flush = () => {\n if (!checkPixelReady()) {\n return;\n }\n console.debug(\n `[analytics] flushing ${queue.length} queued events for ${pixelName}`,\n );\n try {\n queue.forEach(({ event, params }) => sendEvent(event, params));\n } finally {\n queue.length = 0;\n cleanup();\n }\n };\n\n const scheduleFlush = () => {\n if (typeof window === \"undefined\" || flushTimer !== null) {\n return;\n }\n\n flushTimer = window.setInterval(flush, 500);\n timeoutTimer = window.setTimeout(() => {\n queue.length = 0;\n permanentlyDisabled = true;\n console.debug(\n `Analytics queue timed out after 30 seconds for ${pixelName}`,\n );\n cleanup();\n }, 30_000);\n };\n\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n return (event: string, params: Record<string, any> = {}) => {\n if (permanentlyDisabled) {\n console.debug(\n `[analytics] ${pixelName} queue is disabled, dropping event`,\n event,\n );\n return;\n }\n\n if (checkPixelReady()) {\n sendEvent(event, params);\n } else {\n queue.push({ event, params });\n scheduleFlush();\n }\n };\n}\n\ntype MethodQueueOptions = {\n queueName?: string;\n onTimeout?: () => void;\n};\n\nexport function createMethodQueue<\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n T extends Record<string, (...args: any[]) => any>,\n>(\n checkInstanceReady: () => T | null,\n options?: MethodQueueOptions,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n): (method: keyof T, ...args: any[]) => void {\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n const queue: { method: keyof T; args: any[] }[] = [];\n let flushTimer: number | null = null;\n let timeoutTimer: number | null = null;\n let permanentlyDisabled = false;\n const queueName = options?.queueName ?? \"method queue\";\n\n const cleanup = () => {\n if (flushTimer !== null) {\n window.clearInterval(flushTimer);\n flushTimer = null;\n }\n if (timeoutTimer !== null) {\n window.clearTimeout(timeoutTimer);\n timeoutTimer = null;\n }\n };\n\n const flush = () => {\n const instance = checkInstanceReady();\n if (!instance) {\n return;\n }\n try {\n queue.forEach(({ method, args }) => {\n const methodFunction = instance[method];\n if (typeof methodFunction === \"function\") {\n void methodFunction.apply(instance, args);\n }\n });\n } finally {\n queue.length = 0;\n cleanup();\n }\n };\n\n const scheduleFlush = () => {\n if (typeof window === \"undefined\" || flushTimer !== null) {\n return;\n }\n\n flushTimer = window.setInterval(flush, 500);\n timeoutTimer = window.setTimeout(() => {\n queue.length = 0;\n permanentlyDisabled = true;\n if (typeof window !== \"undefined\") {\n console.debug(\n `[analytics] ${queueName} timed out after 30 seconds and has been disabled`,\n );\n }\n options?.onTimeout?.();\n cleanup();\n }, 30_000);\n };\n\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n return (method: keyof T, ...args: any[]) => {\n if (permanentlyDisabled) {\n return;\n }\n\n const instance = checkInstanceReady();\n if (instance) {\n const methodFunction = instance[method];\n if (typeof methodFunction === \"function\") {\n void methodFunction.apply(instance, args);\n }\n } else {\n queue.push({ method, args });\n scheduleFlush();\n }\n };\n}\n"],
5
- "mappings": "AAGO,SAAS,iBACd,iBAEA,WACA,WAEuD;AACvD,QAAM,QAAuB,CAAC;AAC9B,MAAI,aAA4B;AAChC,MAAI,eAA8B;AAClC,MAAI,sBAAsB;AAE1B,QAAM,UAAU,MAAM;AACpB,QAAI,eAAe,MAAM;AACvB,aAAO,cAAc,UAAU;AAC/B,mBAAa;AAAA,IACf;AACA,QAAI,iBAAiB,MAAM;AACzB,aAAO,aAAa,YAAY;AAChC,qBAAe;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,QAAQ,MAAM;AAClB,QAAI,CAAC,gBAAgB,GAAG;AACtB;AAAA,IACF;AACA,YAAQ;AAAA,MACN,wBAAwB,MAAM,MAAM,sBAAsB,SAAS;AAAA,IACrE;AACA,QAAI;AACF,YAAM,QAAQ,CAAC,EAAE,OAAO,OAAO,MAAM,UAAU,OAAO,MAAM,CAAC;AAAA,IAC/D,UAAE;AACA,YAAM,SAAS;AACf,cAAQ;AAAA,IACV;AAAA,EACF;AAEA,QAAM,gBAAgB,MAAM;AAC1B,QAAI,OAAO,WAAW,eAAe,eAAe,MAAM;AACxD;AAAA,IACF;AAEA,iBAAa,OAAO,YAAY,OAAO,GAAG;AAC1C,mBAAe,OAAO,WAAW,MAAM;AACrC,YAAM,SAAS;AACf,4BAAsB;AACtB,cAAQ;AAAA,QACN,kDAAkD,SAAS;AAAA,MAC7D;AACA,cAAQ;AAAA,IACV,GAAG,GAAM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e,SAAS;AAAA,QAC1B;AAAA,MACF;AACA,eAAS,YAAY;AACrB,cAAQ;AAAA,IACV,GAAG,GAAM;AAAA,EACX;AAGA,SAAO,CAAC,WAAoB,SAAgB;AAC1C,QAAI,qBAAqB;AACvB;AAAA,IACF;AAEA,UAAM,WAAW,mBAAmB;AACpC,QAAI,UAAU;AACZ,YAAM,iBAAiB,SAAS,MAAM;AACtC,UAAI,OAAO,mBAAmB,YAAY;AACxC,aAAK,eAAe,MAAM,UAAU,IAAI;AAAA,MAC1C;AAAA,IACF,OAAO;AACL,YAAM,KAAK,EAAE,QAAQ,KAAK,CAAC;AAC3B,oBAAc;AAAA,IAChB;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["// oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\ntype QueuedEvent = { event: string; params: Record<string, any> };\n\nexport function createEventQueue(\n checkPixelReady: () => boolean,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n sendEvent: (event: string, params: Record<string, any>) => void,\n pixelName: string,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n): (event: string, params?: Record<string, any>) => void {\n const queue: QueuedEvent[] = [];\n let flushTimer: number | null = null;\n let timeoutTimer: number | null = null;\n let permanentlyDisabled = false;\n\n const cleanup = () => {\n if (flushTimer !== null) {\n window.clearInterval(flushTimer);\n flushTimer = null;\n }\n if (timeoutTimer !== null) {\n window.clearTimeout(timeoutTimer);\n timeoutTimer = null;\n }\n };\n\n const flush = () => {\n if (!checkPixelReady()) {\n return;\n }\n console.debug(\n `[analytics] flushing ${queue.length} queued events for ${pixelName}`,\n );\n try {\n queue.forEach(({ event, params }) => sendEvent(event, params));\n } finally {\n queue.length = 0;\n cleanup();\n }\n };\n\n const scheduleFlush = () => {\n if (typeof window === \"undefined\" || flushTimer !== null) {\n return;\n }\n\n flushTimer = window.setInterval(flush, 500);\n timeoutTimer = window.setTimeout(() => {\n queue.length = 0;\n permanentlyDisabled = true;\n console.debug(\n `Analytics queue timed out after 30 seconds for ${pixelName}`,\n );\n cleanup();\n }, 30_000);\n };\n\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n return (event: string, params: Record<string, any> = {}) => {\n if (permanentlyDisabled) {\n console.debug(\n `[analytics] ${pixelName} queue is disabled, dropping event`,\n event,\n );\n return;\n }\n\n if (checkPixelReady()) {\n sendEvent(event, params);\n } else {\n queue.push({ event, params });\n scheduleFlush();\n }\n };\n}\n\ntype MethodQueueOptions = {\n queueName?: string;\n onTimeout?: () => void;\n};\n\nexport function createMethodQueue<\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n InstanceType extends Record<string, (...args: any[]) => any>,\n>(\n checkInstanceReady: () => InstanceType | null,\n options?: MethodQueueOptions,\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n): (method: keyof InstanceType, ...args: any[]) => void {\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n const queue: { method: keyof InstanceType; args: any[] }[] = [];\n let flushTimer: number | null = null;\n let timeoutTimer: number | null = null;\n let permanentlyDisabled = false;\n const queueName = options?.queueName ?? \"method queue\";\n\n const cleanup = () => {\n if (flushTimer !== null) {\n window.clearInterval(flushTimer);\n flushTimer = null;\n }\n if (timeoutTimer !== null) {\n window.clearTimeout(timeoutTimer);\n timeoutTimer = null;\n }\n };\n\n const flush = () => {\n const instance = checkInstanceReady();\n if (!instance) {\n return;\n }\n try {\n queue.forEach(({ method, args }) => {\n const methodFunction = instance[method];\n if (typeof methodFunction === \"function\") {\n void methodFunction.apply(instance, args);\n }\n });\n } finally {\n queue.length = 0;\n cleanup();\n }\n };\n\n const scheduleFlush = () => {\n if (typeof window === \"undefined\" || flushTimer !== null) {\n return;\n }\n\n flushTimer = window.setInterval(flush, 500);\n timeoutTimer = window.setTimeout(() => {\n queue.length = 0;\n permanentlyDisabled = true;\n if (typeof window !== \"undefined\") {\n console.debug(\n `[analytics] ${queueName} timed out after 30 seconds and has been disabled`,\n );\n }\n options?.onTimeout?.();\n cleanup();\n }, 30_000);\n };\n\n // oxlint-disable-next-line typescript/no-explicit-any -- legacy any, may or may not be needed\n return (method: keyof InstanceType, ...args: any[]) => {\n if (permanentlyDisabled) {\n return;\n }\n\n const instance = checkInstanceReady();\n if (instance) {\n const methodFunction = instance[method];\n if (typeof methodFunction === \"function\") {\n void methodFunction.apply(instance, args);\n }\n } else {\n queue.push({ method, args });\n scheduleFlush();\n }\n };\n}\n"],
5
+ "mappings": "AAGO,SAAS,iBACd,iBAEA,WACA,WAEuD;AACvD,QAAM,QAAuB,CAAC;AAC9B,MAAI,aAA4B;AAChC,MAAI,eAA8B;AAClC,MAAI,sBAAsB;AAE1B,QAAM,UAAU,MAAM;AACpB,QAAI,eAAe,MAAM;AACvB,aAAO,cAAc,UAAU;AAC/B,mBAAa;AAAA,IACf;AACA,QAAI,iBAAiB,MAAM;AACzB,aAAO,aAAa,YAAY;AAChC,qBAAe;AAAA,IACjB;AAAA,EACF;AAEA,QAAM,QAAQ,MAAM;AAClB,QAAI,CAAC,gBAAgB,GAAG;AACtB;AAAA,IACF;AACA,YAAQ;AAAA,MACN,wBAAwB,MAAM,MAAM,sBAAsB,SAAS;AAAA,IACrE;AACA,QAAI;AACF,YAAM,QAAQ,CAAC,EAAE,OAAO,OAAO,MAAM,UAAU,OAAO,MAAM,CAAC;AAAA,IAC/D,UAAE;AACA,YAAM,SAAS;AACf,cAAQ;AAAA,IACV;AAAA,EACF;AAEA,QAAM,gBAAgB,MAAM;AAC1B,QAAI,OAAO,WAAW,eAAe,eAAe,MAAM;AACxD;AAAA,IACF;AAEA,iBAAa,OAAO,YAAY,OAAO,GAAG;AAC1C,mBAAe,OAAO,WAAW,MAAM;AACrC,YAAM,SAAS;AACf,4BAAsB;AACtB,cAAQ;AAAA,QACN,kDAAkD,SAAS;AAAA,MAC7D;AACA,cAAQ;AAAA,IACV,GAAG,GAAM;AAAA,EACX;AAGA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AC1B;AAAA,MACF;AACA,eAAS,YAAY;AACrB,cAAQ;AAAA,IACV,GAAG,GAAM;AAAA,EACX;AAGA,SAAO,CAAC,WAA+B,SAAgB;AACrD,QAAI,qBAAqB;AACvB;AAAA,IACF;AAEA,UAAM,WAAW,mBAAmB;AACpC,QAAI,UAAU;AACZ,YAAM,iBAAiB,SAAS,MAAM;AACtC,UAAI,OAAO,mBAAmB,YAAY;AACxC,aAAK,eAAe,MAAM,UAAU,IAAI;AAAA,MAC1C;AAAA,IACF,OAAO;AACL,YAAM,KAAK,EAAE,QAAQ,KAAK,CAAC;AAC3B,oBAAc;AAAA,IAChB;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,18 @@
1
- import type { ReploScriptEntry } from "../_vendor/schemas/generated/consent";
1
+ import type { ReploScriptEntry, ScriptTagDescriptor } from "../_vendor/schemas/generated/consent";
2
+ /**
3
+ * Injects the resolved tags into `document.head` once a caller has decided
4
+ * consent allows it. Reused both for author-managed `ReploScripts` entries and
5
+ * for the implicit Replo first-party pixel.
6
+ *
7
+ * DOM insertion (not JSX) is required because inline `<script>` bodies set via
8
+ * React's `dangerouslySetInnerHTML` never execute. Each node is tagged with
9
+ * `data-replo-script-id` (plus a per-tag index) so re-renders and React Strict
10
+ * Mode double-invokes do not double-inject.
11
+ */
12
+ export declare function InjectedScript({ baseId, descriptors, }: {
13
+ baseId: string;
14
+ descriptors: ScriptTagDescriptor[];
15
+ }): null;
2
16
  /**
3
17
  * The single registry component for all managed tracking scripts on the site.
4
18
  * Authored once in `app/layout.tsx`; the agent/miniapp only edit the `scripts`
@@ -26,9 +26,10 @@ function descriptorsFor(entry) {
26
26
  }
27
27
  return buildScriptTags({ type: entry.type, identifier: entry.identifier });
28
28
  }
29
- function InjectedScript({ entry }) {
30
- const descriptors = descriptorsFor(entry);
31
- const baseId = scriptId(entry);
29
+ function InjectedScript({
30
+ baseId,
31
+ descriptors
32
+ }) {
32
33
  const injectionKey = `${baseId}|${JSON.stringify(descriptors)}`;
33
34
  useEffect(() => {
34
35
  if (typeof document === "undefined") {
@@ -79,13 +80,14 @@ function ManagedScript({ entry }) {
79
80
  if (!isConsentAllowed({ state: consent, requiredConsent })) {
80
81
  return null;
81
82
  }
82
- return /* @__PURE__ */ jsx(InjectedScript, { entry });
83
+ return /* @__PURE__ */ jsx(InjectedScript, { baseId: id, descriptors: descriptorsFor(entry) });
83
84
  }
84
85
  function ReploScripts({ scripts }) {
85
86
  useEffect(() => installConsentWindowApi(), []);
86
87
  return /* @__PURE__ */ jsx(Fragment, { children: scripts.map((entry) => /* @__PURE__ */ jsx(ManagedScript, { entry }, scriptId(entry))) });
87
88
  }
88
89
  export {
90
+ InjectedScript,
89
91
  ReploScripts
90
92
  };
91
93
  //# sourceMappingURL=replo-scripts.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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": ";AAwHS,SAaL,UAbK;AAhHT,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,gBAAgB,wBAAwB;AACjD,SAAS,iBAAiB,yBAAyB;AACnD,SAAS,+BAA+B;AAGxC,SAAS,SAAS,OAAiC;AACjD,SAAO,MAAM,SAAS,WAClB,UAAU,MAAM,EAAE,KAClB,GAAG,MAAM,IAAI,IAAI,MAAM,UAAU;AACvC;AAEA,SAAS,mBAAmB,OAA4C;AACtE,MAAI,MAAM,SAAS,UAAU;AAC3B,WAAO,MAAM;AAAA,EACf;AACA,SAAO,MAAM,mBAAmB,kBAAkB,MAAM,IAAI;AAC9D;AAOA,SAAS,eAAe,OAAgD;AACtE,MAAI,MAAM,SAAS,UAAU;AAC3B,QAAI,MAAM,KAAK;AACb,aAAO,CAAC,EAAE,MAAM,YAAY,KAAK,MAAM,IAAI,CAAC;AAAA,IAC9C;AACA,QAAI,MAAM,MAAM;AACd,aAAO,CAAC,EAAE,MA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AK,SAAS,KAAK;AACzB,QAAM,aAAa,gBAAgB,KAAK,GAAG;AAG3C,YAAU,MAAM;AACd,mBAAe,EAAE,IAAI,MAAM,MAAM,MAAM,gBAAgB,CAAC;AACxD,WAAO,MAAM,iBAAiB,EAAE;AAAA,EAClC,GAAG,CAAC,IAAI,MAAM,MAAM,UAAU,CAAC;AAE/B,MAAI,CAAC,iBAAiB,EAAE,OAAO,SAAS,gBAAgB,CAAC,GAAG;AAC1D,WAAO;AAAA,EACT;AACA,SAAO,oBAAC,kBAAe,OAAc;AACvC;AAOO,SAAS,aAAa,EAAE,QAAQ,GAAoC;AAEzE,YAAU,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE7C,SACE,gCACG,kBAAQ,IAAI,CAAC,UACZ,oBAAC,iBAAoC,SAAjB,SAAS,KAAK,CAAiB,CACpD,GACH;AAEJ;",
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 a caller has decided\n * consent allows it. Reused both for author-managed `ReploScripts` entries and\n * for the implicit Replo first-party pixel.\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 */\nexport function InjectedScript({\n baseId,\n descriptors,\n}: {\n baseId: string;\n descriptors: ScriptTagDescriptor[];\n}) {\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 baseId={id} descriptors={descriptorsFor(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": ";AA8HS,SAaL,UAbK;AAtHT,SAAS,iBAAiB;AAE1B,SAAS,kBAAkB,kBAAkB;AAC7C,SAAS,gBAAgB,wBAAwB;AACjD,SAAS,iBAAiB,yBAAyB;AACnD,SAAS,+BAA+B;AAGxC,SAAS,SAAS,OAAiC;AACjD,SAAO,MAAM,SAAS,WAClB,UAAU,MAAM,EAAE,KAClB,GAAG,MAAM,IAAI,IAAI,MAAM,UAAU;AACvC;AAEA,SAAS,mBAAmB,OAA4C;AACtE,MAAI,MAAM,SAAS,UAAU;AAC3B,WAAO,MAAM;AAAA,EACf;AACA,SAAO,MAAM,mBAAmB,kBAAkB,MAAM,IAAI;AAC9D;AAOA,SAAS,eAAe,OAAgD;AACtE,MAAI,MAAM,SAAS,UAAU;AAC3B,QAAI,MAAM,KAAK;AACb,aAAO,CAAC,EAAE,MAAM,YAAY,KAAK,MAAM,IAAI,CAAC;AAAA,IAC9C;AACA,QAAI,MAAM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AACzB,QAAM,aAAa,gBAAgB,KAAK,GAAG;AAG3C,YAAU,MAAM;AACd,mBAAe,EAAE,IAAI,MAAM,MAAM,MAAM,gBAAgB,CAAC;AACxD,WAAO,MAAM,iBAAiB,EAAE;AAAA,EAClC,GAAG,CAAC,IAAI,MAAM,MAAM,UAAU,CAAC;AAE/B,MAAI,CAAC,iBAAiB,EAAE,OAAO,SAAS,gBAAgB,CAAC,GAAG;AAC1D,WAAO;AAAA,EACT;AACA,SAAO,oBAAC,kBAAe,QAAQ,IAAI,aAAa,eAAe,KAAK,GAAG;AACzE;AAOO,SAAS,aAAa,EAAE,QAAQ,GAAoC;AAEzE,YAAU,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE7C,SACE,gCACG,kBAAQ,IAAI,CAAC,UACZ,oBAAC,iBAAoC,SAAjB,SAAS,KAAK,CAAiB,CACpD,GACH;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { useEffect, useRef } from "react";
3
- import { buildGoogleFontsCssUrl } from "../../_vendor/replo-utils/lib/google-fonts.mjs";
3
+ import { buildGoogleFontsCssUrl } from "../../_vendor/replo-utils/lib/fonts.mjs";
4
4
  import { designLibraryPreviewMessageSchema } from "../../_vendor/schemas/designLibrary.mjs";
5
5
  const FONT_LINK_DATA_KEY = "reploDesignLibraryFont";
6
6
  function escapeCssString(value) {
@@ -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 { buildGoogleFontsCssUrl } from \"replo-utils/lib/google-fonts\";\nimport { designLibraryPreviewMessageSchema } from \"schemas/designLibrary\";\n\nconst FONT_LINK_DATA_KEY = \"reploDesignLibraryFont\";\n\nfunction escapeCssString(value: string): string {\n return value.replace(/\\\\/gu, \"\\\\\\\\\").replace(/'/gu, \"\\\\'\");\n}\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): The @font-face <style> nodes for uploaded custom\n // fonts, keyed by family with the URL we injected, so we de-dupe, re-inject\n // when a family's asset URL changes (re-upload), and remove only our own when\n // the override set changes.\n const ownedFontFaces = useRef<Map<\n string,\n { url: string; style: HTMLStyleElement }\n > | 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] = `'${escapeCssString(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 // Custom uploaded fonts carry a faceUrl; Google fonts don't.\n const customFonts = fonts.filter((font) => Boolean(font.faceUrl));\n const googleFonts = fonts.filter((font) => !font.faceUrl);\n\n // --- Google Font stylesheets (<link> to the CDN) ---\n const links = ownedFontLinks.current ?? new Map();\n const nextHrefs = new Set(\n googleFonts.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 // --- Custom uploaded fonts (@font-face from the asset URL) ---\n const faces = ownedFontFaces.current ?? new Map();\n const nextFamilies = new Set(customFonts.map((font) => font.family));\n for (const [family, entry] of faces) {\n if (!nextFamilies.has(family)) {\n entry.style.remove();\n faces.delete(family);\n }\n }\n for (const font of customFonts) {\n if (!font.faceUrl) continue;\n const existing = faces.get(font.family);\n // Re-upload reuses the family but changes the asset URL; replace the\n // stale node rather than skipping it.\n if (existing?.url === font.faceUrl) continue;\n existing?.style.remove();\n const style = document.createElement(\"style\");\n style.dataset[FONT_LINK_DATA_KEY] = \"\";\n const format = font.format\n ? ` format('${escapeCssString(font.format)}')`\n : \"\";\n style.textContent = `@font-face{font-family:'${escapeCssString(font.family)}';font-weight:400;font-style:normal;src:url('${escapeCssString(font.faceUrl)}')${format};font-display:swap;}`;\n document.head.append(style);\n faces.set(font.family, { url: font.faceUrl, style });\n }\n ownedFontFaces.current = faces;\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"],
4
+ "sourcesContent": ["\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nimport { buildGoogleFontsCssUrl } from \"replo-utils/lib/fonts\";\nimport { designLibraryPreviewMessageSchema } from \"schemas/designLibrary\";\n\nconst FONT_LINK_DATA_KEY = \"reploDesignLibraryFont\";\n\nfunction escapeCssString(value: string): string {\n return value.replace(/\\\\/gu, \"\\\\\\\\\").replace(/'/gu, \"\\\\'\");\n}\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): The @font-face <style> nodes for uploaded custom\n // fonts, keyed by family with the URL we injected, so we de-dupe, re-inject\n // when a family's asset URL changes (re-upload), and remove only our own when\n // the override set changes.\n const ownedFontFaces = useRef<Map<\n string,\n { url: string; style: HTMLStyleElement }\n > | 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] = `'${escapeCssString(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 // Custom uploaded fonts carry a faceUrl; Google fonts don't.\n const customFonts = fonts.filter((font) => Boolean(font.faceUrl));\n const googleFonts = fonts.filter((font) => !font.faceUrl);\n\n // --- Google Font stylesheets (<link> to the CDN) ---\n const links = ownedFontLinks.current ?? new Map();\n const nextHrefs = new Set(\n googleFonts.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 // --- Custom uploaded fonts (@font-face from the asset URL) ---\n const faces = ownedFontFaces.current ?? new Map();\n const nextFamilies = new Set(customFonts.map((font) => font.family));\n for (const [family, entry] of faces) {\n if (!nextFamilies.has(family)) {\n entry.style.remove();\n faces.delete(family);\n }\n }\n for (const font of customFonts) {\n if (!font.faceUrl) continue;\n const existing = faces.get(font.family);\n // Re-upload reuses the family but changes the asset URL; replace the\n // stale node rather than skipping it.\n if (existing?.url === font.faceUrl) continue;\n existing?.style.remove();\n const style = document.createElement(\"style\");\n style.dataset[FONT_LINK_DATA_KEY] = \"\";\n const format = font.format\n ? ` format('${escapeCssString(font.format)}')`\n : \"\";\n style.textContent = `@font-face{font-family:'${escapeCssString(font.family)}';font-weight:400;font-style:normal;src:url('${escapeCssString(font.faceUrl)}')${format};font-display:swap;}`;\n document.head.append(style);\n faces.set(font.family, { url: font.faceUrl, style });\n }\n ownedFontFaces.current = faces;\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
5
  "mappings": ";AAEA,SAAS,WAAW,cAAc;AAElC,SAAS,8BAA8B;AACvC,SAAS,yCAAyC;AAElD,MAAM,qBAAqB;AAE3B,SAAS,gBAAgB,OAAuB;AAC9C,SAAO,MAAM,QAAQ,Q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AAS;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
@@ -2,6 +2,7 @@ type Env = {
2
2
  CANOPY_API_HOST: string;
3
3
  PROJECT_ID: string;
4
4
  ANALYTICS_FIRE_API_URL?: string;
5
+ REPLO_ANALYTICS_PIXEL_URL?: string;
5
6
  SHOPIFY_URL?: string;
6
7
  SHOPIFY_STOREFRONT_ACCESS_TOKEN?: string | null;
7
8
  STRIPE_CONNECT_ACCOUNT_ID?: string | null;
package/env.js CHANGED
@@ -4,6 +4,7 @@ const envSchema = z.object({
4
4
  CANOPY_API_HOST: z.string().min(1),
5
5
  PROJECT_ID: z.string().uuid(),
6
6
  ANALYTICS_FIRE_API_URL: z.string().optional(),
7
+ REPLO_ANALYTICS_PIXEL_URL: z.string().optional(),
7
8
  SHOPIFY_URL: z.string().optional(),
8
9
  SHOPIFY_STOREFRONT_ACCESS_TOKEN: z.string().nullable().optional(),
9
10
  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 // 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;",
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 // Base URL of the Replo first-party analytics pixel CDN (e.g.\n // https://pixel.replo.app). `<ReploFirstPartyPixel>` loads\n // `${REPLO_ANALYTICS_PIXEL_URL}/latest.js` into the page once analytics consent\n // is granted; the browser fetches it directly. Optional: absent when the pixel\n // isn't configured (e.g. lean local dev), where the pixel simply isn't injected.\n REPLO_ANALYTICS_PIXEL_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 REPLO_ANALYTICS_PIXEL_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;AAiClB,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,2BAA2B,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/C,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
  }
@@ -7,4 +7,4 @@
7
7
  * The useEffect doesn't have any dependencies - it's designed to only run once. So if you expect your read() function to return
8
8
  * different values through the lifecycle of the component, you should not use this hook.
9
9
  */
10
- export declare function useClientValue<T>(readValue: () => T, initialValue: T): T;
10
+ export declare function useClientValue<ValueType>(readValue: () => ValueType, initialValue: ValueType): ValueType;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../hooks/use-client-value.ts"],
4
- "sourcesContent": ["import * as React from \"react\";\n\n/**\n * NOTE (Max, 2025-09-15): This hook is to be used for values that aren't available on the server (such as window.location).\n *\n * This hook will use a dummy value both on the server & on hydration. Then,\n * after hydration, this useEffect will update the value to the actual value.\n *\n * The useEffect doesn't have any dependencies - it's designed to only run once. So if you expect your read() function to return\n * different values through the lifecycle of the component, you should not use this hook.\n */\n\nexport function useClientValue<T>(readValue: () => T, initialValue: T) {\n const [value, setValue] = React.useState<T>(initialValue);\n\n /* eslint-disable replo/no-use-effect -- Legacy effect - may or may not be necessary */\n React.useEffect(() => {\n setValue(readValue());\n }, []);\n /* eslint-enable replo/no-use-effect */\n return value;\n}\n"],
5
- "mappings": "AAAA,YAAY,WAAW;AAYhB,SAAS,eAAkB,WAAoB,cAAiB;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAY,YAAY;AAGxD,QAAM,UAAU,MAAM;AACpB,aAAS,UAAU,CAAC;AAAA,EACtB,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
4
+ "sourcesContent": ["import * as React from \"react\";\n\n/**\n * NOTE (Max, 2025-09-15): This hook is to be used for values that aren't available on the server (such as window.location).\n *\n * This hook will use a dummy value both on the server & on hydration. Then,\n * after hydration, this useEffect will update the value to the actual value.\n *\n * The useEffect doesn't have any dependencies - it's designed to only run once. So if you expect your read() function to return\n * different values through the lifecycle of the component, you should not use this hook.\n */\n\nexport function useClientValue<ValueType>(\n readValue: () => ValueType,\n initialValue: ValueType,\n) {\n const [value, setValue] = React.useState<ValueType>(initialValue);\n\n /* eslint-disable replo/no-use-effect -- Legacy effect - may or may not be necessary */\n React.useEffect(() => {\n setValue(readValue());\n }, []);\n /* eslint-enable replo/no-use-effect */\n return value;\n}\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;AAYhB,SAAS,eACd,WACA,cACA;AACA,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAoB,YAAY;AAGhE,QAAM,UAAU,MAAM;AACpB,aAAS,UAAU,CAAC;AAAA,EACtB,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replohq/canopy-sdk",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "Replo Canopy SDK — cart, analytics, data loaders, and editor runtime for agent-built Next.js sites.",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -1,5 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { AnalyticsProvider } from "../analytics/analytics-provider";
3
+ import { ReploFirstPartyPixel } from "../analytics/replo-first-party-pixel";
3
4
  import { CartLoader } from "../cart/cart-loader";
4
5
  import { ClientErrorBoundary } from "../editor/ClientErrorBoundary";
5
6
  import { DesignLibraryPreview } from "../editor/design-library-preview/DesignLibraryPreview";
@@ -8,13 +9,16 @@ import PostHogRelay from "../editor/posthog-relay";
8
9
  import { EditorSelection } from "../editor/select-mode/EditorSelection";
9
10
  import { QueryProvider } from "./query-provider";
10
11
  function ReploProvider({ children }) {
11
- return /* @__PURE__ */ jsx(QueryProvider, { children: /* @__PURE__ */ jsx(AnalyticsProvider, { children: /* @__PURE__ */ jsx(CartLoader, { children: /* @__PURE__ */ jsxs(ClientErrorBoundary, { children: [
12
- /* @__PURE__ */ jsx(LinkInterceptor, {}),
13
- /* @__PURE__ */ jsx(PostHogRelay, {}),
14
- /* @__PURE__ */ jsx(EditorSelection, {}),
15
- /* @__PURE__ */ jsx(DesignLibraryPreview, {}),
16
- children
17
- ] }) }) }) });
12
+ return /* @__PURE__ */ jsx(QueryProvider, { children: /* @__PURE__ */ jsxs(AnalyticsProvider, { children: [
13
+ /* @__PURE__ */ jsx(ReploFirstPartyPixel, {}),
14
+ /* @__PURE__ */ jsx(CartLoader, { children: /* @__PURE__ */ jsxs(ClientErrorBoundary, { children: [
15
+ /* @__PURE__ */ jsx(LinkInterceptor, {}),
16
+ /* @__PURE__ */ jsx(PostHogRelay, {}),
17
+ /* @__PURE__ */ jsx(EditorSelection, {}),
18
+ /* @__PURE__ */ jsx(DesignLibraryPreview, {}),
19
+ children
20
+ ] }) })
21
+ ] }) });
18
22
  }
19
23
  export {
20
24
  ReploProvider
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../providers/replo-provider.tsx"],
4
- "sourcesContent": ["import { AnalyticsProvider } from \"../analytics/analytics-provider\";\nimport { CartLoader } from \"../cart/cart-loader\";\nimport { ClientErrorBoundary } from \"../editor/ClientErrorBoundary\";\nimport { DesignLibraryPreview } from \"../editor/design-library-preview/DesignLibraryPreview\";\nimport LinkInterceptor from \"../editor/LinkInterceptor\";\nimport PostHogRelay from \"../editor/posthog-relay\";\nimport { EditorSelection } from \"../editor/select-mode/EditorSelection\";\nimport { QueryProvider } from \"./query-provider\";\n\nexport function ReploProvider({ children }: React.PropsWithChildren) {\n return (\n <QueryProvider>\n <AnalyticsProvider>\n <CartLoader>\n <ClientErrorBoundary>\n <LinkInterceptor />\n <PostHogRelay />\n <EditorSelection />\n <DesignLibraryPreview />\n {children}\n </ClientErrorBoundary>\n </CartLoader>\n </AnalyticsProvider>\n </QueryProvider>\n );\n}\n"],
5
- "mappings": "AAcU,SACE,KADF;AAdV,SAAS,yBAAyB;AAClC,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,OAAO,qBAAqB;AAC5B,OAAO,kBAAkB;AACzB,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAEvB,SAAS,cAAc,EAAE,SAAS,GAA4B;AACnE,SACE,oBAAC,iBACC,8BAAC,qBACC,8BAAC,cACC,+BAAC,uBACC;AAAA,wBAAC,mBAAgB;AAAA,IACjB,oBAAC,gBAAa;AAAA,IACd,oBAAC,mBAAgB;AAAA,IACjB,oBAAC,wBAAqB;AAAA,IACrB;AAAA,KACH,GACF,GACF,GACF;AAEJ;",
4
+ "sourcesContent": ["import { AnalyticsProvider } from \"../analytics/analytics-provider\";\nimport { ReploFirstPartyPixel } from \"../analytics/replo-first-party-pixel\";\nimport { CartLoader } from \"../cart/cart-loader\";\nimport { ClientErrorBoundary } from \"../editor/ClientErrorBoundary\";\nimport { DesignLibraryPreview } from \"../editor/design-library-preview/DesignLibraryPreview\";\nimport LinkInterceptor from \"../editor/LinkInterceptor\";\nimport PostHogRelay from \"../editor/posthog-relay\";\nimport { EditorSelection } from \"../editor/select-mode/EditorSelection\";\nimport { QueryProvider } from \"./query-provider\";\n\nexport function ReploProvider({ children }: React.PropsWithChildren) {\n return (\n <QueryProvider>\n <AnalyticsProvider>\n <ReploFirstPartyPixel />\n <CartLoader>\n <ClientErrorBoundary>\n <LinkInterceptor />\n <PostHogRelay />\n <EditorSelection />\n <DesignLibraryPreview />\n {children}\n </ClientErrorBoundary>\n </CartLoader>\n </AnalyticsProvider>\n </QueryProvider>\n );\n}\n"],
5
+ "mappings": "AAcQ,cAEE,YAFF;AAdR,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAC3B,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,OAAO,qBAAqB;AAC5B,OAAO,kBAAkB;AACzB,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAEvB,SAAS,cAAc,EAAE,SAAS,GAA4B;AACnE,SACE,oBAAC,iBACC,+BAAC,qBACC;AAAA,wBAAC,wBAAqB;AAAA,IACtB,oBAAC,cACC,+BAAC,uBACC;AAAA,0BAAC,mBAAgB;AAAA,MACjB,oBAAC,gBAAa;AAAA,MACd,oBAAC,mBAAgB;AAAA,MACjB,oBAAC,wBAAqB;AAAA,MACrB;AAAA,OACH,GACF;AAAA,KACF,GACF;AAEJ;",
6
6
  "names": []
7
7
  }
@@ -1,28 +0,0 @@
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 };