@replohq/canopy-sdk 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
+ }
@@ -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 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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 <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GED
@@ -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
  }
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.0",
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
  }