@replohq/sdk 2.13.0 → 2.14.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.
@@ -1,7 +1,7 @@
1
1
  export const BUILD_METADATA = {
2
2
  "packageName": "@replohq/sdk",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "branch": "HEAD",
5
- "commit": "7431b844d8aaadcf980cdeb6b63ecaa33fb70a49",
6
- "builtAt": "2026-10-30T05:21:51.639Z"
5
+ "commit": "06e25b3341d1e79f6171365410c49bee41b1f3e0",
6
+ "builtAt": "2026-10-30T20:22:53.823Z"
7
7
  };
package/next/config.js CHANGED
@@ -1,4 +1,6 @@
1
- import { existsSync } from "fs";
1
+ import { createHash } from "crypto";
2
+ import { existsSync, readFileSync } from "fs";
3
+ import { createRequire } from "module";
2
4
  import os from "os";
3
5
  import path from "path";
4
6
  const PLATFORM_DEV_ORIGINS = [
@@ -20,6 +22,33 @@ const PLATFORM_SERVER_ACTION_ORIGINS = [
20
22
  ];
21
23
  const PLATFORM_DEVICE_SIZES = [640, 828, 1080, 1200, 1920, 2048, 3840];
22
24
  const PLATFORM_IMAGE_SIZES = [32, 48, 96, 128, 256, 384];
25
+ const PLATFORM_RESOLVE_ALIAS = {
26
+ "../build/polyfills/polyfill-module": {
27
+ browser: "@replohq/sdk/next/polyfill-module"
28
+ }
29
+ };
30
+ const VETTED_NEXT_POLYFILL_MODULE_SHA256 = "94c8008b70e41ac5b0360fd6f35ea7a59c20c6927aca7731ef8c6a3c26b9cddf";
31
+ function resolvePolyfillAlias() {
32
+ try {
33
+ const requireFromSite = createRequire(
34
+ path.join(process.cwd(), "package.json")
35
+ );
36
+ const source = readFileSync(
37
+ path.join(
38
+ path.dirname(requireFromSite.resolve("next/package.json")),
39
+ "dist/build/polyfills/polyfill-module.js"
40
+ )
41
+ );
42
+ if (createHash("sha256").update(source).digest("hex") === VETTED_NEXT_POLYFILL_MODULE_SHA256) {
43
+ return PLATFORM_RESOLVE_ALIAS;
44
+ }
45
+ } catch {
46
+ }
47
+ console.warn(
48
+ "[@replohq/sdk] Skipped the Next.js polyfill alias because next/dist/build/polyfills/polyfill-module.js is missing or differs from the vetted version, so Next's own polyfills ship. Re-vet the polyfill list and update VETTED_NEXT_POLYFILL_MODULE_SHA256 in @replohq/sdk/next/config."
49
+ );
50
+ return {};
51
+ }
23
52
  const DEFAULT_PAGE_EXTENSIONS = ["tsx", "ts", "jsx", "js"];
24
53
  const DEVELOPMENT_ONLY_PAGE_EXTENSIONS = ["dev.jsx", "dev.tsx"];
25
54
  const BUILD_ONLY_PAGE_EXTENSIONS = ["published.tsx"];
@@ -61,7 +90,11 @@ function siteConfig(overrides = {}) {
61
90
  outputFileTracingRoot: isBuild ? "/" : void 0,
62
91
  turbopack: {
63
92
  ...overrideTurbopack,
64
- root: isBuild ? "/" : devRoot
93
+ root: isBuild ? "/" : devRoot,
94
+ resolveAlias: {
95
+ ...resolvePolyfillAlias(),
96
+ ...overrideTurbopack?.resolveAlias
97
+ }
65
98
  },
66
99
  allowedDevOrigins: Array.from(
67
100
  /* @__PURE__ */ new Set([...overrideDevOrigins ?? [], ...PLATFORM_DEV_ORIGINS])
@@ -1,62 +1,87 @@
1
+ import { exhaustiveSwitch } from "../_vendor/replo-utils/lib/misc.mjs";
1
2
  const REPLO_IMAGE_CDN = "https://assets.replocdn.com";
2
3
  function isContentfulImagesCdn(hostname) {
3
4
  return /^images(?:\.[a-z]+)?\.ctfassets\.net$/i.test(hostname);
4
5
  }
5
- function isPassthroughSource(src) {
6
+ const MAX_PARSED_SOURCES = 1e3;
7
+ const parsedSources = /* @__PURE__ */ new Map();
8
+ function parseSource(src) {
9
+ const isAbsolute = /^https:\/\//i.test(src);
10
+ let url;
6
11
  try {
7
- return /\.(avif|svg)$/i.test(new URL(src, REPLO_IMAGE_CDN).pathname);
12
+ url = new URL(src, REPLO_IMAGE_CDN);
8
13
  } catch {
9
- return false;
14
+ url = null;
10
15
  }
11
- }
12
- function contentfulImagesApiUrl({
13
- src,
14
- width,
15
- quality
16
- }) {
17
- const url = new URL(src);
18
- url.searchParams.set("w", String(width));
19
- url.searchParams.set("q", String(quality ?? 75));
20
- if (!url.searchParams.has("fm")) {
21
- url.searchParams.set("fm", "webp");
16
+ if (url !== null && /\.(avif|svg)$/i.test(url.pathname)) {
17
+ return { kind: "unchanged" };
18
+ }
19
+ if (!isAbsolute) {
20
+ return { kind: "relative" };
22
21
  }
23
- return url.toString();
22
+ if (url === null) {
23
+ return { kind: "unchanged" };
24
+ }
25
+ if (/(^|\.)ctfassets\.net$/i.test(url.hostname)) {
26
+ if (!isContentfulImagesCdn(url.hostname)) {
27
+ return { kind: "unchanged" };
28
+ }
29
+ const [, hrefBeforeSearch = "", , hash = ""] = /^([^?#]*)(\?[^#]*)?(#.*)?$/.exec(url.href) ?? [];
30
+ return {
31
+ kind: "contentfulImagesApi",
32
+ hrefBeforeSearch,
33
+ searchParams: url.searchParams,
34
+ hash
35
+ };
36
+ }
37
+ if (/(^|\.)replocdn\.com$/i.test(url.hostname)) {
38
+ return { kind: "replocdn" };
39
+ }
40
+ return {
41
+ kind: "external",
42
+ passthroughUrl: `${REPLO_IMAGE_CDN}/images/external?url=${encodeURIComponent(src)}`
43
+ };
24
44
  }
25
45
  function cloudflareLoader({
26
46
  src,
27
47
  width,
28
48
  quality
29
49
  }) {
30
- if (isPassthroughSource(src)) {
31
- return src;
50
+ let source = parsedSources.get(src);
51
+ if (!source) {
52
+ if (parsedSources.size >= MAX_PARSED_SOURCES) {
53
+ parsedSources.clear();
54
+ }
55
+ source = parseSource(src);
56
+ parsedSources.set(src, source);
32
57
  }
33
58
  const isDevelopment = process.env.NODE_ENV === "development";
34
- const params = [`width=${width}`, `quality=${quality ?? 75}`, "format=auto"];
35
- if (/^https:\/\//i.test(src)) {
36
- let hostname;
37
- try {
38
- hostname = new URL(src).hostname;
39
- } catch {
40
- return src;
41
- }
42
- if (/(^|\.)ctfassets\.net$/i.test(hostname)) {
43
- if (isContentfulImagesCdn(hostname)) {
44
- return contentfulImagesApiUrl({ src, width, quality });
59
+ const params = `width=${width},quality=${quality ?? 75},format=auto`;
60
+ return exhaustiveSwitch(
61
+ source,
62
+ "kind"
63
+ )({
64
+ unchanged: src,
65
+ contentfulImagesApi: (contentfulSource) => {
66
+ const searchParams = new URLSearchParams(contentfulSource.searchParams);
67
+ searchParams.set("w", String(width));
68
+ searchParams.set("q", String(quality ?? 75));
69
+ if (!searchParams.has("fm")) {
70
+ searchParams.set("fm", "webp");
45
71
  }
46
- return src;
47
- }
48
- if (/(^|\.)replocdn\.com$/i.test(hostname)) {
72
+ return `${contentfulSource.hrefBeforeSearch}?${searchParams.toString()}${contentfulSource.hash}`;
73
+ },
74
+ replocdn: () => {
49
75
  const resizerOrigin = isDevelopment ? REPLO_IMAGE_CDN : "";
50
- return `${resizerOrigin}/cdn-cgi/image/${params.join(",")}/${src}`;
76
+ return `${resizerOrigin}/cdn-cgi/image/${params}/${src}`;
77
+ },
78
+ external: (externalSource) => {
79
+ return `${REPLO_IMAGE_CDN}/cdn-cgi/image/${params},onerror=redirect/${externalSource.passthroughUrl}`;
80
+ },
81
+ relative: () => {
82
+ return isDevelopment ? src : `/cdn-cgi/image/${params}/${src.startsWith("/") ? src.slice(1) : src}`;
51
83
  }
52
- const passthroughUrl = `${REPLO_IMAGE_CDN}/images/external?url=${encodeURIComponent(src)}`;
53
- return `${REPLO_IMAGE_CDN}/cdn-cgi/image/${[...params, "onerror=redirect"].join(",")}/${passthroughUrl}`;
54
- }
55
- if (isDevelopment) {
56
- return src;
57
- }
58
- const normalizedSrc = src.startsWith("/") ? src.slice(1) : src;
59
- return `/cdn-cgi/image/${params.join(",")}/${normalizedSrc}`;
84
+ });
60
85
  }
61
86
  export {
62
87
  cloudflareLoader as default
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ if (typeof URL.canParse !== "function") {
2
+ URL.canParse = (url, base) => {
3
+ try {
4
+ new URL(url, base);
5
+ return true;
6
+ } catch {
7
+ return false;
8
+ }
9
+ };
10
+ }
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@replohq/sdk",
3
- "version": "2.13.0",
3
+ "version": "2.14.0",
4
4
  "reploBuild": {
5
5
  "packageName": "@replohq/sdk",
6
- "version": "2.13.0",
6
+ "version": "2.14.0",
7
7
  "branch": "HEAD",
8
- "commit": "7431b844d8aaadcf980cdeb6b63ecaa33fb70a49",
9
- "builtAt": "2026-10-30T05:21:51.639Z"
8
+ "commit": "06e25b3341d1e79f6171365410c49bee41b1f3e0",
9
+ "builtAt": "2026-10-30T20:22:53.823Z"
10
10
  },
11
11
  "description": "Replo SDK — cart, analytics, and data loaders for agent-built Next.js sites.",
12
12
  "license": "SEE LICENSE IN LICENSE",
13
13
  "type": "module",
14
- "sideEffects": false,
14
+ "sideEffects": [
15
+ "./next/polyfill-module.js"
16
+ ],
15
17
  "exports": {
16
18
  "./providers/replo-provider": {
17
19
  "types": "./providers/replo-provider.d.ts",
@@ -297,6 +299,10 @@
297
299
  "types": "./next/open-next.d.ts",
298
300
  "default": "./next/open-next.js"
299
301
  },
302
+ "./next/polyfill-module": {
303
+ "types": "./next/polyfill-module.d.ts",
304
+ "default": "./next/polyfill-module.js"
305
+ },
300
306
  "./routing/evaluate": {
301
307
  "types": "./routing/evaluate.d.ts",
302
308
  "default": "./routing/evaluate.js"