@replohq/canopy-sdk 0.16.2 → 0.16.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/env.d.ts CHANGED
@@ -11,10 +11,5 @@ type Env = {
11
11
  /** Shared secret sent in X-Replo-Resolver-Auth for server-to-server cart calls. */
12
12
  CART_AUTH_SECRET?: string;
13
13
  };
14
- declare const fetchCloudflareContext: () => Promise<import("@opennextjs/cloudflare").CloudflareContext<IncomingRequestCfProperties, ExecutionContext>>;
15
- type CloudflareContextPromise = ReturnType<typeof fetchCloudflareContext>;
16
- declare global {
17
- var canopyCloudflareContextPromise: CloudflareContextPromise | undefined;
18
- }
19
14
  export declare const getEnv: () => Promise<Env>;
20
15
  export {};
package/env.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { getCloudflareContext } from "@opennextjs/cloudflare";
2
+ import JSONC from "tiny-jsonc";
2
3
  import { z } from "zod";
3
4
  const envSchema = z.object({
4
5
  CANOPY_API_HOST: z.string().min(1),
@@ -12,17 +13,18 @@ const envSchema = z.object({
12
13
  REPLO_INTERNAL_REVALIDATE_SECRET: z.string().optional(),
13
14
  CART_AUTH_SECRET: z.string().optional()
14
15
  });
15
- const fetchCloudflareContext = () => getCloudflareContext({ async: true });
16
- const getSharedCloudflareContext = () => {
17
- if (process.env.NODE_ENV !== "development") return fetchCloudflareContext();
18
- return globalThis.canopyCloudflareContextPromise ??= fetchCloudflareContext().catch((error) => {
19
- globalThis.canopyCloudflareContextPromise = void 0;
20
- throw error;
21
- });
16
+ const wranglerConfigSchema = z.object({ vars: envSchema });
17
+ const isDeployedWorker = () => {
18
+ return process.env.NODE_ENV === "production" && process.env.BUILD_ENV !== "build" && process.env.NEXT_PHASE !== "phase-production-build";
22
19
  };
23
20
  const getEnv = async () => {
24
- const { env } = await getSharedCloudflareContext();
25
- return envSchema.parse(env);
21
+ if (isDeployedWorker()) {
22
+ const { env } = await getCloudflareContext({ async: true });
23
+ return envSchema.parse(env);
24
+ }
25
+ const { promises: fs } = await import(`${"__node:fs".replaceAll("__", "")}`);
26
+ const raw = await fs.readFile(`${process.cwd()}/wrangler.jsonc`, "utf8");
27
+ return wranglerConfigSchema.parse(JSONC.parse(raw)).vars;
26
28
  };
27
29
  export {
28
30
  getEnv
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 // 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.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().nullish(),\n STRIPE_CONNECT_ACCOUNT_ID: z.string().nullish(),\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\nconst fetchCloudflareContext = () => getCloudflareContext({ async: true });\ntype CloudflareContextPromise = ReturnType<typeof fetchCloudflareContext>;\n\ndeclare global {\n var canopyCloudflareContextPromise: CloudflareContextPromise | undefined;\n}\n\n// (Andrew, 2026-07-08, REPL-29048): memoize the in-flight dev init so concurrent cold-start renders share one workerd, not separate ones racing on the same SQLite lock (SQLITE_BUSY).\nconst getSharedCloudflareContext = (): CloudflareContextPromise => {\n if (process.env.NODE_ENV !== \"development\") return fetchCloudflareContext();\n return (globalThis.canopyCloudflareContextPromise ??=\n fetchCloudflareContext().catch((error: unknown) => {\n globalThis.canopyCloudflareContextPromise = undefined; // let the next request retry instead of caching a rejection\n throw error;\n }));\n};\n\nexport const getEnv = async (): Promise<Env> => {\n const { env } = await getSharedCloudflareContext();\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,KAAK;AAAA,EACnB,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,QAAQ;AAAA,EACpD,2BAA2B,EAAE,OAAO,EAAE,QAAQ;AAAA,EAC9C,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;AAED,MAAM,yBAAyB,MAAM,qBAAqB,EAAE,OAAO,KAAK,CAAC;AAQzE,MAAM,6BAA6B,MAAgC;AACjE,MAAI,QAAQ,IAAI,aAAa,cAAe,QAAO,uBAAuB;AAC1E,SAAQ,WAAW,mCACjB,uBAAuB,EAAE,MAAM,CAAC,UAAmB;AACjD,eAAW,iCAAiC;AAC5C,UAAM;AAAA,EACR,CAAC;AACL;AAEO,MAAM,SAAS,YAA0B;AAC9C,QAAM,EAAE,IAAI,IAAI,MAAM,2BAA2B;AACjD,SAAO,UAAU,MAAM,GAAG;AAC5B;",
4
+ "sourcesContent": ["import { getCloudflareContext } from \"@opennextjs/cloudflare\";\nimport JSONC from \"tiny-jsonc\";\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.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().nullish(),\n STRIPE_CONNECT_ACCOUNT_ID: z.string().nullish(),\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\nconst wranglerConfigSchema = z.object({ vars: envSchema });\n\n// NOTE (Cole, 2026-07-28, REPL-29501): outside the deployed worker, read wrangler.jsonc directly \u2014 concurrent workerd boots race on the shared .wrangler/state SQLite (SQLITE_BUSY).\nconst isDeployedWorker = () => {\n return (\n process.env.NODE_ENV === \"production\" &&\n process.env.BUILD_ENV !== \"build\" &&\n process.env.NEXT_PHASE !== \"phase-production-build\"\n );\n};\n\nexport const getEnv = async (): Promise<Env> => {\n if (isDeployedWorker()) {\n const { env } = await getCloudflareContext({ async: true });\n return envSchema.parse(env);\n }\n // NOTE (Cole, 2026-07-29, REPL-29501): client chunks bundle this module (integration-utils has client consumers), so Node builtins must stay out of the static import graph \u2014 a static node:fs broke those chunks in 0.16.3; the computed specifier mirrors @opennextjs/cloudflare's wrangler import.\n const { promises: fs }: typeof import(\"node:fs\") = await import(\n `${\"__node:fs\".replaceAll(\"__\", \"\")}`\n );\n const raw = await fs.readFile(`${process.cwd()}/wrangler.jsonc`, \"utf8\");\n return wranglerConfigSchema.parse(JSONC.parse(raw)).vars;\n};\n"],
5
+ "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3
- "version": "0.16.2",
3
+ "version": "0.16.4",
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,