@replohq/sdk 1.9.2 → 1.9.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.
@@ -1,16 +1,18 @@
1
1
  "use client";
2
2
  import { jsx } from "react/jsx-runtime";
3
- import { findDelegatedPlatform } from "../consent/consent-platform";
4
- import { isConsentAllowed, useConsent } from "../consent/consent-store";
5
3
  import { InjectedScript } from "../consent/replo-scripts";
4
+ import { useIsBlockedByNativeConsent } from "../consent/use-is-blocked-by-native-consent";
6
5
  const PIXEL_SCRIPT_ID = "replo:first-party-pixel";
6
+ const PIXEL_REQUIRED_CONSENT = ["analytics"];
7
7
  function ReploPixelScript({
8
8
  pixelUrl,
9
9
  apiUrl,
10
10
  projectId
11
11
  }) {
12
- const consent = useConsent();
13
- if (!findDelegatedPlatform() && !isConsentAllowed({ state: consent, requiredConsent: ["analytics"] })) {
12
+ const isBlockedByNativeConsent = useIsBlockedByNativeConsent(
13
+ PIXEL_REQUIRED_CONSENT
14
+ );
15
+ if (isBlockedByNativeConsent) {
14
16
  return null;
15
17
  }
16
18
  const descriptors = [
@@ -28,7 +30,7 @@ function ReploPixelScript({
28
30
  {
29
31
  baseId: PIXEL_SCRIPT_ID,
30
32
  descriptors,
31
- requiredConsent: ["analytics"]
33
+ requiredConsent: PIXEL_REQUIRED_CONSENT
32
34
  }
33
35
  );
34
36
  }
@@ -6,11 +6,10 @@ import type { ConsentCategories } from "./cookie";
6
6
  * all share the same state regardless of where they sit in the React tree — no
7
7
  * provider-ancestor relationship is required.
8
8
  *
9
- * Consent-dependent work (script injection, banner visibility) happens on the
10
- * client (effects / post-mount), so there is no SSR/hydration mismatch. The
11
- * client reads the (non-httpOnly) consent cookie directly, so no server seed is
12
- * needed. The whole-site `mode` comes from the `data-replo-consent-mode`
13
- * attribute on `<html>`.
9
+ * SSR and the first hydration render use a `mode: "off"` snapshot, which allows
10
+ * every category under native consent. Irreversible consent work must wait for
11
+ * client hydration, when the cookie-backed snapshot is available. The
12
+ * whole-site `mode` comes from `data-replo-consent-mode` on `<html>`.
14
13
  */
15
14
  export interface ConsentState {
16
15
  /** Which platform owns consent. Absent means Replo's native banner; "external" is a generic `consentPlatform` entry. */
@@ -11,7 +11,6 @@ import {
11
11
  isConsentPlatformEntry,
12
12
  OPTIONAL_CONSENT_CATEGORIES
13
13
  } from "./consent-platform";
14
- import { isConsentAllowed, useConsent } from "./consent-store";
15
14
  import { injectScriptDescriptors } from "./inject-script-descriptors";
16
15
  import {
17
16
  registerScript,
@@ -19,6 +18,7 @@ import {
19
18
  unregisterScript
20
19
  } from "./script-registration-store";
21
20
  import { buildScriptTags, defaultConsentFor } from "./script-snippets";
21
+ import { useIsBlockedByNativeConsent } from "./use-is-blocked-by-native-consent";
22
22
  import { installConsentWindowApi } from "./window-api";
23
23
  function scriptId(entry) {
24
24
  if (entry.type === "custom") {
@@ -90,10 +90,9 @@ class ScriptRegistration extends Component {
90
90
  }
91
91
  }
92
92
  function ManagedScript({ entry }) {
93
- const consent = useConsent();
94
93
  const requiredConsent = requiredConsentFor(entry);
95
94
  const id = scriptId(entry);
96
- const isBlockedByNativeConsent = !findDelegatedPlatform() && !isConsentAllowed({ state: consent, requiredConsent });
95
+ const isBlockedByNativeConsent = useIsBlockedByNativeConsent(requiredConsent);
97
96
  return /* @__PURE__ */ jsxs(Fragment, { children: [
98
97
  /* @__PURE__ */ jsx(
99
98
  ScriptRegistration,
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from "react";
2
+ import type { ConsentCategories } from "./cookie";
3
+ export declare function clearConsentCookie(): void;
4
+ export declare function writeConsentCookie({ categories, consentId, }: {
5
+ categories: ConsentCategories;
6
+ consentId: string;
7
+ }): void;
8
+ export declare function hydrateFromServer(element: ReactNode): {
9
+ root: import("react-dom/client").Root;
10
+ serverHtml: string;
11
+ };
@@ -0,0 +1,29 @@
1
+ import { flushSync } from "react-dom";
2
+ import { hydrateRoot } from "react-dom/client";
3
+ import { renderToString } from "react-dom/server";
4
+ import { CONSENT_COOKIE_NAME, serializeConsentCookieValue } from "./cookie";
5
+ function clearConsentCookie() {
6
+ document.cookie = `${CONSENT_COOKIE_NAME}=; path=/; max-age=0`;
7
+ }
8
+ function writeConsentCookie({
9
+ categories,
10
+ consentId
11
+ }) {
12
+ document.cookie = `${CONSENT_COOKIE_NAME}=${serializeConsentCookieValue({
13
+ categories,
14
+ decidedAt: 1e3,
15
+ consentId
16
+ })}; path=/`;
17
+ }
18
+ function hydrateFromServer(element) {
19
+ const serverHtml = renderToString(element);
20
+ const container = document.createElement("div");
21
+ container.innerHTML = serverHtml;
22
+ const root = flushSync(() => hydrateRoot(container, element));
23
+ return { root, serverHtml };
24
+ }
25
+ export {
26
+ clearConsentCookie,
27
+ hydrateFromServer,
28
+ writeConsentCookie
29
+ };
@@ -0,0 +1,2 @@
1
+ import type { ConsentCategory } from "../_vendor/schemas/generated/consent";
2
+ export declare function useIsBlockedByNativeConsent(requiredConsent: ConsentCategory[]): boolean;
@@ -0,0 +1,11 @@
1
+ import { useIsHydrated } from "../hooks/use-is-hydrated";
2
+ import { findDelegatedPlatform } from "./consent-platform";
3
+ import { isConsentAllowed, useConsent } from "./consent-store";
4
+ function useIsBlockedByNativeConsent(requiredConsent) {
5
+ const isHydrated = useIsHydrated();
6
+ const consent = useConsent();
7
+ return !findDelegatedPlatform() && (!isHydrated || !isConsentAllowed({ state: consent, requiredConsent }));
8
+ }
9
+ export {
10
+ useIsBlockedByNativeConsent
11
+ };
@@ -0,0 +1,2 @@
1
+ /** False during SSR and hydration, then true for client renders. */
2
+ export declare function useIsHydrated(): boolean;
@@ -0,0 +1,11 @@
1
+ import { useSyncExternalStore } from "react";
2
+ const subscribe = () => () => {
3
+ };
4
+ const getClientSnapshot = () => true;
5
+ const getServerSnapshot = () => false;
6
+ function useIsHydrated() {
7
+ return useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);
8
+ }
9
+ export {
10
+ useIsHydrated
11
+ };
@@ -1,7 +1,7 @@
1
1
  export const BUILD_METADATA = {
2
2
  "packageName": "@replohq/sdk",
3
- "version": "1.9.2",
3
+ "version": "1.9.4",
4
4
  "branch": "HEAD",
5
- "commit": "b00423087f2b01a9cc8fb4700d453161b9ec846c",
6
- "builtAt": "2026-09-17T18:32:43.736Z"
5
+ "commit": "aa07173168356fbdc7ade4a24770a38f85a887f6",
6
+ "builtAt": "2026-09-18T16:24:49.114Z"
7
7
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@replohq/sdk",
3
- "version": "1.9.2",
3
+ "version": "1.9.4",
4
4
  "reploBuild": {
5
5
  "packageName": "@replohq/sdk",
6
- "version": "1.9.2",
6
+ "version": "1.9.4",
7
7
  "branch": "HEAD",
8
- "commit": "b00423087f2b01a9cc8fb4700d453161b9ec846c",
9
- "builtAt": "2026-09-17T18:32:43.736Z"
8
+ "commit": "aa07173168356fbdc7ade4a24770a38f85a887f6",
9
+ "builtAt": "2026-09-18T16:24:49.114Z"
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",
@@ -123,7 +123,7 @@ function evaluateLocalePhase({
123
123
  if (isLocaleExemptPath(pathname)) {
124
124
  return NextResponse.next();
125
125
  }
126
- const { urlMode, pathLocale, negotiated, scope } = localeContext;
126
+ const { urlMode, pathLocale, negotiated, scope, config } = localeContext;
127
127
  if (urlMode === "prefixed") {
128
128
  if (!pathLocale) {
129
129
  const url2 = request.nextUrl.clone();
@@ -133,12 +133,13 @@ function evaluateLocalePhase({
133
133
  });
134
134
  return NextResponse.redirect(url2, 307);
135
135
  }
136
- if (pathLocale.pathSegment !== pathLocale.locale) {
136
+ const canonicalPath = canonicalPrefixedPathname({
137
+ pathLocale,
138
+ locales: config.locales
139
+ });
140
+ if (canonicalPath !== pathname) {
137
141
  const url2 = request.nextUrl.clone();
138
- url2.pathname = withLocalePrefix({
139
- locale: pathLocale.locale,
140
- path: pathLocale.logicalPath
141
- });
142
+ url2.pathname = canonicalPath;
142
143
  return NextResponse.redirect(url2, 308);
143
144
  }
144
145
  const response = NextResponse.next();
@@ -163,6 +164,20 @@ function evaluateLocalePhase({
163
164
  });
164
165
  return NextResponse.rewrite(url);
165
166
  }
167
+ function canonicalPrefixedPathname({
168
+ pathLocale,
169
+ locales
170
+ }) {
171
+ const nestedLocale = getLocaleFromPath({
172
+ pathname: pathLocale.logicalPath,
173
+ locales
174
+ });
175
+ const chosen = nestedLocale ?? pathLocale;
176
+ return withLocalePrefix({
177
+ locale: chosen.locale,
178
+ path: chosen.logicalPath
179
+ });
180
+ }
166
181
  function isLocaleExemptPath(pathname) {
167
182
  if (pathname === "/api" || pathname.startsWith("/api/")) {
168
183
  return true;
@@ -10,4 +10,4 @@
10
10
  */
11
11
  export type { LocaleDetection, LocaleRoutingConfig, LocaleRoutingConfigInput, LocaleUrlMode, } from "../_vendor/schemas/routing/locale";
12
12
  export { REPLO_COUNTRY_OVERRIDE_COOKIE, REPLO_LOCALE_COOKIE, reploLocaleRouting, } from "../_vendor/schemas/routing/locale";
13
- export { localeUrl } from "../_vendor/schemas/routing/localeNegotiation";
13
+ export { getLocaleFromPath, localeUrl, } from "../_vendor/schemas/routing/localeNegotiation";
package/routing/locale.js CHANGED
@@ -3,10 +3,14 @@ import {
3
3
  REPLO_LOCALE_COOKIE,
4
4
  reploLocaleRouting
5
5
  } from "../_vendor/schemas/routing/locale.mjs";
6
- import { localeUrl } from "../_vendor/schemas/routing/localeNegotiation.mjs";
6
+ import {
7
+ getLocaleFromPath,
8
+ localeUrl
9
+ } from "../_vendor/schemas/routing/localeNegotiation.mjs";
7
10
  export {
8
11
  REPLO_COUNTRY_OVERRIDE_COOKIE,
9
12
  REPLO_LOCALE_COOKIE,
13
+ getLocaleFromPath,
10
14
  localeUrl,
11
15
  reploLocaleRouting
12
16
  };