@replohq/sdk 2.2.0 → 2.2.2

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.
@@ -3,9 +3,18 @@ export declare class InvalidAmountError extends ReploError {
3
3
  }
4
4
  export declare class UnsupportedCurrencyError extends ReploError {
5
5
  }
6
+ /**
7
+ * True for currencies where Stripe deliberately differs from ISO — e.g. ISO
8
+ * calls IQD/LYD 3-decimal and ISK/UGX 0-decimal, but Stripe treats all four as
9
+ * 2-decimal (and MGA/MRU are ÷5, not decimal at all). Check it before sending
10
+ * minor units to Stripe, so a wrong-exponent amount can never be charged. When
11
+ * we launch one of these for Replo checkout, add a Stripe-verified override.
12
+ */
13
+ export declare function stripeExponentDiffersFromIso(currencyCode: string): boolean;
14
+ export declare function assertStripeExponentMatchesIso(currencyCode: string): void;
6
15
  /**
7
16
  * Converts a decimal major-unit amount (e.g. "19.99", 19.99) into integer
8
- * minor units (1999) using the currency's Stripe exponent. Half-away-from-zero
17
+ * minor units (1999) using the currency's ISO-4217 exponent. Half-away-from-zero
9
18
  * rounding for the non-negative amounts this domain uses (prices, totals),
10
19
  * matching Stripe. Throws on non-numeric input.
11
20
  */
@@ -1856,7 +1856,7 @@ var InvalidAmountError = class extends ReploError {
1856
1856
  };
1857
1857
  var UnsupportedCurrencyError = class extends ReploError {
1858
1858
  };
1859
- var STRIPE_UNSUPPORTED_CURRENCIES = /* @__PURE__ */ new Set([
1859
+ var STRIPE_EXPONENT_MISMATCH_CURRENCIES = /* @__PURE__ */ new Set([
1860
1860
  "ISK",
1861
1861
  "UGX",
1862
1862
  "IQD",
@@ -1864,15 +1864,19 @@ var STRIPE_UNSUPPORTED_CURRENCIES = /* @__PURE__ */ new Set([
1864
1864
  "MGA",
1865
1865
  "MRU"
1866
1866
  ]);
1867
- function currencyMinorUnitExponent(currencyCode) {
1868
- const normalizedCode = currencyCode.toUpperCase();
1869
- if (STRIPE_UNSUPPORTED_CURRENCIES.has(normalizedCode)) {
1867
+ function stripeExponentDiffersFromIso(currencyCode) {
1868
+ return STRIPE_EXPONENT_MISMATCH_CURRENCIES.has(currencyCode.toUpperCase());
1869
+ }
1870
+ function assertStripeExponentMatchesIso(currencyCode) {
1871
+ if (stripeExponentDiffersFromIso(currencyCode)) {
1870
1872
  throw new UnsupportedCurrencyError({
1871
1873
  message: "Currency's ISO minor-unit exponent differs from Stripe's; not supported",
1872
- additionalData: { currencyCode: normalizedCode }
1874
+ additionalData: { currencyCode: currencyCode.toUpperCase() }
1873
1875
  });
1874
1876
  }
1875
- return (0, import_currency_codes.code)(normalizedCode)?.digits ?? 2;
1877
+ }
1878
+ function currencyMinorUnitExponent(currencyCode) {
1879
+ return (0, import_currency_codes.code)(currencyCode.toUpperCase())?.digits ?? 2;
1876
1880
  }
1877
1881
  function fromMajorUnitsToMinorUnits({
1878
1882
  amount,
@@ -1923,4 +1927,4 @@ function formatAmount({
1923
1927
  }).format(fromMinorUnitsToMajorUnits({ amount, currencyCode }));
1924
1928
  }
1925
1929
 
1926
- export { InvalidAmountError, UnsupportedCurrencyError, formatAmount, fromMajorUnitsToMinorUnits, fromMinorUnitsToMajorUnits, fromMinorUnitsToMajorUnitsString, parseDecimalToMinorUnits };
1930
+ export { InvalidAmountError, UnsupportedCurrencyError, assertStripeExponentMatchesIso, formatAmount, fromMajorUnitsToMinorUnits, fromMinorUnitsToMajorUnits, fromMinorUnitsToMajorUnitsString, parseDecimalToMinorUnits, stripeExponentDiffersFromIso };
@@ -1,4 +1,4 @@
1
- import * as z from "zod";
1
+ import * as v from "valibot";
2
2
  import { DENIED_CATEGORIES } from "./cookie";
3
3
  const COOKIEBOT_CATEGORY_BY_CONSENT = {
4
4
  analytics: "statistics",
@@ -75,7 +75,7 @@ const OPTIONAL_CONSENT_CATEGORIES = [
75
75
  "preferences",
76
76
  "sale_of_data"
77
77
  ];
78
- const genericConsentCategorySchema = z.enum(OPTIONAL_CONSENT_CATEGORIES);
78
+ const genericConsentCategorySchema = v.picklist(OPTIONAL_CONSENT_CATEGORIES);
79
79
  const GENERIC_CONSENT_GRANTED_EVENT = "reploConsentCategoryGranted";
80
80
  let delegatedPlatform = null;
81
81
  let listeningToCookiebot = false;
@@ -134,11 +134,11 @@ function handleGenericConsentActivation(event) {
134
134
  if (!(event instanceof CustomEvent)) {
135
135
  return;
136
136
  }
137
- const result = genericConsentCategorySchema.safeParse(event.detail);
138
- if (!result.success || categories[result.data]) {
137
+ const result = v.safeParse(genericConsentCategorySchema, event.detail);
138
+ if (!result.success || categories[result.output]) {
139
139
  return;
140
140
  }
141
- categories = { ...categories, [result.data]: true };
141
+ categories = { ...categories, [result.output]: true };
142
142
  decidedAt = Date.now();
143
143
  notifyConsentListeners();
144
144
  }
@@ -1,4 +1,5 @@
1
1
  import type { ConsentCategory } from "../_vendor/schemas/generated/consent";
2
+ import * as v from "valibot";
2
3
  /**
3
4
  * Pure (non-React, framework-agnostic) consent cookie helpers used by the client
4
5
  * store (`consent-store.ts`).
@@ -6,20 +7,21 @@ import type { ConsentCategory } from "../_vendor/schemas/generated/consent";
6
7
  export declare const CONSENT_COOKIE_NAME = "replo_consent";
7
8
  export declare const CONSENT_COOKIE_VERSION = 1;
8
9
  export declare const CONSENT_COOKIE_MAX_AGE_SECONDS: number;
10
+ declare const persistedCookieSchema: v.ObjectSchema<{
11
+ readonly version: v.LiteralSchema<1, undefined>;
12
+ readonly decidedAt: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>]>, () => number>;
13
+ /** Persistent pseudonymous per-browser id; absent on pre-id (legacy) cookies. */
14
+ readonly consentId: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
15
+ readonly categories: v.ObjectSchema<{
16
+ readonly analytics: v.BooleanSchema<undefined>;
17
+ readonly marketing: v.BooleanSchema<undefined>;
18
+ readonly preferences: v.BooleanSchema<undefined>;
19
+ readonly sale_of_data: v.BooleanSchema<undefined>;
20
+ }, undefined>;
21
+ }, undefined>;
9
22
  export type ConsentCategories = Record<ConsentCategory, boolean>;
10
23
  /** Persisted cookie payload. `necessary` is always granted and never stored. */
11
- export interface ConsentCookiePayload {
12
- version: number;
13
- decidedAt: number;
14
- /** Persistent pseudonymous per-browser id; absent on pre-id (legacy) cookies. */
15
- consentId?: string;
16
- categories: {
17
- analytics: boolean;
18
- marketing: boolean;
19
- preferences: boolean;
20
- sale_of_data: boolean;
21
- };
22
- }
24
+ export type ConsentCookiePayload = v.InferOutput<typeof persistedCookieSchema>;
23
25
  export declare const DENIED_CATEGORIES: ConsentCategories;
24
26
  export declare const GRANTED_CATEGORIES: ConsentCategories;
25
27
  /**
@@ -34,3 +36,4 @@ export declare function serializeConsentCookieValue({ categories, decidedAt, con
34
36
  decidedAt: number;
35
37
  consentId?: string;
36
38
  }): string;
39
+ export {};
package/consent/cookie.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import { parseJsonOrNull } from "../_vendor/replo-utils/lib/json.mjs";
2
- import * as z from "zod";
2
+ import * as v from "valibot";
3
3
  const CONSENT_COOKIE_NAME = "replo_consent";
4
4
  const CONSENT_COOKIE_VERSION = 1;
5
5
  const CONSENT_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 180;
6
- const persistedCookieSchema = z.object({
7
- version: z.literal(CONSENT_COOKIE_VERSION),
8
- decidedAt: z.number().optional(),
9
- consentId: z.string().optional(),
10
- categories: z.object({
11
- analytics: z.boolean(),
12
- marketing: z.boolean(),
13
- preferences: z.boolean(),
14
- sale_of_data: z.boolean()
6
+ const persistedCookieSchema = v.object({
7
+ version: v.literal(CONSENT_COOKIE_VERSION),
8
+ decidedAt: v.optional(v.pipe(v.number(), v.finite()), () => Date.now()),
9
+ consentId: v.optional(v.string()),
10
+ categories: v.object({
11
+ analytics: v.boolean(),
12
+ marketing: v.boolean(),
13
+ preferences: v.boolean(),
14
+ sale_of_data: v.boolean()
15
15
  })
16
16
  });
17
17
  const DENIED_CATEGORIES = {
@@ -40,14 +40,14 @@ function parseConsentCookie(rawCookie) {
40
40
  } catch {
41
41
  return null;
42
42
  }
43
- const result = persistedCookieSchema.safeParse(parseJsonOrNull(decoded));
43
+ const result = v.safeParse(persistedCookieSchema, parseJsonOrNull(decoded));
44
44
  if (!result.success) {
45
45
  return null;
46
46
  }
47
- const { decidedAt, categories, consentId } = result.data;
47
+ const { decidedAt, categories, consentId } = result.output;
48
48
  return {
49
49
  version: CONSENT_COOKIE_VERSION,
50
- decidedAt: decidedAt ?? Date.now(),
50
+ decidedAt,
51
51
  consentId,
52
52
  categories
53
53
  };
@@ -1,19 +1,10 @@
1
1
  import React from "react";
2
- import * as z from "zod";
2
+ import * as v from "valibot";
3
3
  import { CanopyError } from "../lib/canopy-error";
4
- declare const mailchimpSubscribeErrorCodeSchema: z.ZodEnum<{
5
- notConnected: "notConnected";
6
- listNotFound: "listNotFound";
7
- invalidEmail: "invalidEmail";
8
- invalidRequest: "invalidRequest";
9
- emailNotSubscribable: "emailNotSubscribable";
10
- mergeFieldsInvalid: "mergeFieldsInvalid";
11
- rateLimited: "rateLimited";
12
- upstreamError: "upstreamError";
13
- }>;
4
+ declare const mailchimpSubscribeErrorCodeSchema: v.PicklistSchema<["notConnected", "listNotFound", "invalidEmail", "invalidRequest", "emailNotSubscribable", "mergeFieldsInvalid", "rateLimited", "upstreamError"], undefined>;
14
5
  /** `pending` means Mailchimp emailed a confirmation link the visitor must click. */
15
6
  export type MailchimpSubscribeStatus = "subscribed" | "pending";
16
- export type MailchimpSubscribeErrorCode = z.infer<typeof mailchimpSubscribeErrorCodeSchema>;
7
+ export type MailchimpSubscribeErrorCode = v.InferOutput<typeof mailchimpSubscribeErrorCodeSchema>;
17
8
  export declare class MailchimpSubscribeError extends CanopyError {
18
9
  readonly code: MailchimpSubscribeErrorCode;
19
10
  constructor({ code, message, cause, }: {
@@ -2,10 +2,10 @@
2
2
  import React from "react";
3
3
  import { useMutation } from "@tanstack/react-query";
4
4
  import { parseJsonOrNull } from "../_vendor/replo-utils/lib/json.mjs";
5
- import * as z from "zod";
5
+ import * as v from "valibot";
6
6
  import { CanopyError } from "../lib/canopy-error";
7
7
  import { useCanopyClientConfig } from "../providers/canopy-client-config";
8
- const mailchimpSubscribeErrorCodeSchema = z.enum([
8
+ const mailchimpSubscribeErrorCodeSchema = v.picklist([
9
9
  "notConnected",
10
10
  "listNotFound",
11
11
  "invalidEmail",
@@ -15,12 +15,12 @@ const mailchimpSubscribeErrorCodeSchema = z.enum([
15
15
  "rateLimited",
16
16
  "upstreamError"
17
17
  ]);
18
- const mailchimpSubscribeSuccessSchema = z.object({
19
- status: z.enum(["subscribed", "pending"])
18
+ const mailchimpSubscribeSuccessSchema = v.object({
19
+ status: v.picklist(["subscribed", "pending"])
20
20
  });
21
- const mailchimpSubscribeFailureSchema = z.object({
21
+ const mailchimpSubscribeFailureSchema = v.object({
22
22
  key: mailchimpSubscribeErrorCodeSchema,
23
- message: z.string()
23
+ message: v.string()
24
24
  });
25
25
  class MailchimpSubscribeError extends CanopyError {
26
26
  code;
@@ -65,24 +65,28 @@ async function postSubscribe({
65
65
  }
66
66
  const body = parseJsonOrNull(responseText);
67
67
  if (!response.ok) {
68
- const failure = mailchimpSubscribeFailureSchema.safeParse(body);
68
+ const failure = v.safeParse(mailchimpSubscribeFailureSchema, body);
69
69
  throw new MailchimpSubscribeError(
70
- failure.success ? { code: failure.data.key, message: failure.data.message, cause: null } : {
70
+ failure.success ? {
71
+ code: failure.output.key,
72
+ message: failure.output.message,
73
+ cause: null
74
+ } : {
71
75
  code: "upstreamError",
72
76
  message: `The Mailchimp subscribe endpoint failed with status ${response.status}`,
73
- cause: failure.error
77
+ cause: new v.ValiError(failure.issues)
74
78
  }
75
79
  );
76
80
  }
77
- const success = mailchimpSubscribeSuccessSchema.safeParse(body);
81
+ const success = v.safeParse(mailchimpSubscribeSuccessSchema, body);
78
82
  if (!success.success) {
79
83
  throw new MailchimpSubscribeError({
80
84
  code: "upstreamError",
81
85
  message: "The Mailchimp subscribe endpoint returned an unexpected response",
82
- cause: success.error
86
+ cause: new v.ValiError(success.issues)
83
87
  });
84
88
  }
85
- return success.data.status;
89
+ return success.output.status;
86
90
  }
87
91
  function useMailchimpSubscribe({
88
92
  listId,
@@ -1,7 +1,7 @@
1
1
  export const BUILD_METADATA = {
2
2
  "packageName": "@replohq/sdk",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "branch": "HEAD",
5
- "commit": "425a057ac5f569a875e63976fa5a936dc651e292",
6
- "builtAt": "2026-10-20T23:04:33.045Z"
5
+ "commit": "10eafe148d1a068d735ebb31d3b9ad7cc63f7056",
6
+ "builtAt": "2026-10-21T00:01:06.096Z"
7
7
  };
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Sample-data substitution for previewing dynamic routes inside the editor.
3
+ *
4
+ * When the editor previews an unfilled Next.js dynamic route (the literal
5
+ * `/products/[handle]` URL), the page receives the bracket token itself as its
6
+ * param, every lookup misses, and the preview 404s. Loader invocations detect
7
+ * that exact case — editor iframe + a bracket-token arg — and substitute a
8
+ * type-correct sample fixture so the page renders its real layout with sample
9
+ * data. A `replo:preview:placeholder-render` message tells the embedding
10
+ * editor the preview is showing sample data (mirrors `replo:preview:status`
11
+ * from NextErrorReporter).
12
+ *
13
+ * Substitution is gated to editor iframes only: production traffic to a
14
+ * bracket URL still misses lookups and 404s, so this can never soft-404 a
15
+ * published site.
16
+ */
17
+ import type { FullCollection, FullProduct, PaginatedProducts } from "./loader-schemas";
1
18
  export declare function hasUnfilledRouteParam(args: Record<string, unknown>): boolean;
2
19
  /**
3
20
  * Sample data for a loader invoked with an unfilled dynamic-route param, or
@@ -13,8 +30,9 @@ export declare function resolvePreviewPlaceholderData({ loaderKey, args, }: {
13
30
  loaderKey: string;
14
31
  args: Record<string, unknown>;
15
32
  }): unknown;
33
+ type PreviewableLoaderData = FullProduct | FullCollection | PaginatedProducts;
16
34
  /** Whether loader output is one of this module's sample fixtures. */
17
- export declare function isPreviewPlaceholderData(data: unknown): boolean;
35
+ export declare function isPreviewPlaceholderData(data: PreviewableLoaderData): boolean;
18
36
  /**
19
37
  * Notify the embedding editor when a loader component rendered sample data.
20
38
  * The single reporting path: inspecting rendered data (rather than hooking
@@ -22,4 +40,5 @@ export declare function isPreviewPlaceholderData(data: unknown): boolean;
22
40
  * hydration never re-invokes the loader on the client. Receivers treat the
23
41
  * message as idempotent, so no dedupe is needed.
24
42
  */
25
- export declare function useReportPreviewPlaceholderRender(data: unknown): void;
43
+ export declare function useReportPreviewPlaceholderRender(data: PreviewableLoaderData): void;
44
+ export {};
@@ -1,5 +1,4 @@
1
1
  import { useEffect } from "react";
2
- import * as z from "zod";
3
2
  import { DATA_LOADER_KEYS } from "./loader-keys";
4
3
  const PLACEHOLDER_RENDER_MESSAGE_TYPE = "replo:preview:placeholder-render";
5
4
  const UNFILLED_ROUTE_PARAM_RE = /^\[{1,2}(?:\.\.\.)?[^\]]+\]{1,2}$/;
@@ -184,17 +183,9 @@ function resolvePreviewPlaceholderData({
184
183
  }
185
184
  return window.parent === window ? null : placeholderData;
186
185
  }
187
- const placeholderIdSchema = z.object({ id: z.string() });
188
- const placeholderProductsSchema = z.object({
189
- products: z.array(z.object({ id: z.string() })).min(1)
190
- });
191
186
  function isPreviewPlaceholderData(data) {
192
- const withId = placeholderIdSchema.safeParse(data);
193
- if (withId.success) {
194
- return withId.data.id.startsWith(SAMPLE_ID_PREFIX);
195
- }
196
- const withProducts = placeholderProductsSchema.safeParse(data);
197
- return withProducts.success && (withProducts.data.products[0]?.id.startsWith(SAMPLE_ID_PREFIX) ?? false);
187
+ const id = "products" in data ? data.products[0]?.id : data.id;
188
+ return id?.startsWith(SAMPLE_ID_PREFIX) ?? false;
198
189
  }
199
190
  function useReportPreviewPlaceholderRender(data) {
200
191
  useEffect(() => {
package/money.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Money helpers for storefronts. All commerce amounts in the SDK (variant
3
- * prices, cart costs) are integer minor units, Stripe convention: 1999 =
3
+ * prices, cart costs) are integer ISO 4217 minor units: 1999 =
4
4
  * $19.99 USD, 1999 = ¥1999 JPY. Use formatAmount/useFormattedPrice for
5
5
  * display and fromMinorUnitsToMajorUnits when handing amounts to analytics or third-party
6
6
  * APIs that speak decimal money.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@replohq/sdk",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "reploBuild": {
5
5
  "packageName": "@replohq/sdk",
6
- "version": "2.2.0",
6
+ "version": "2.2.2",
7
7
  "branch": "HEAD",
8
- "commit": "425a057ac5f569a875e63976fa5a936dc651e292",
9
- "builtAt": "2026-10-20T23:04:33.045Z"
8
+ "commit": "10eafe148d1a068d735ebb31d3b9ad7cc63f7056",
9
+ "builtAt": "2026-10-21T00:01:06.096Z"
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",
@@ -300,6 +300,7 @@
300
300
  "server-only": "^0.0.1",
301
301
  "tiny-jsonc": "^1.0.2",
302
302
  "uuid": "^11.1.0",
303
+ "valibot": "^1.5.0",
303
304
  "yaml": "^2.8.3",
304
305
  "zod": "^4.3.6"
305
306
  },
@@ -0,0 +1 @@
1
+ export declare function BuyBox(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export default function FixtureProductPage(): import("react/jsx-runtime").JSX.Element;