@replohq/sdk 2.2.0 → 2.2.1
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/consent/consent-platform.js +5 -5
- package/consent/cookie.d.ts +15 -12
- package/consent/cookie.js +13 -13
- package/integrations/mailchimp.d.ts +3 -12
- package/integrations/mailchimp.js +16 -12
- package/lib/buildMetadata.js +3 -3
- package/loaders/preview-placeholder.d.ts +21 -2
- package/loaders/preview-placeholder.js +2 -11
- package/package.json +5 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
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 =
|
|
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 =
|
|
138
|
-
if (!result.success || categories[result.
|
|
137
|
+
const result = v.safeParse(genericConsentCategorySchema, event.detail);
|
|
138
|
+
if (!result.success || categories[result.output]) {
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
|
-
categories = { ...categories, [result.
|
|
141
|
+
categories = { ...categories, [result.output]: true };
|
|
142
142
|
decidedAt = Date.now();
|
|
143
143
|
notifyConsentListeners();
|
|
144
144
|
}
|
package/consent/cookie.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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 =
|
|
7
|
-
version:
|
|
8
|
-
decidedAt:
|
|
9
|
-
consentId:
|
|
10
|
-
categories:
|
|
11
|
-
analytics:
|
|
12
|
-
marketing:
|
|
13
|
-
preferences:
|
|
14
|
-
sale_of_data:
|
|
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 =
|
|
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.
|
|
47
|
+
const { decidedAt, categories, consentId } = result.output;
|
|
48
48
|
return {
|
|
49
49
|
version: CONSENT_COOKIE_VERSION,
|
|
50
|
-
decidedAt
|
|
50
|
+
decidedAt,
|
|
51
51
|
consentId,
|
|
52
52
|
categories
|
|
53
53
|
};
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import * as
|
|
2
|
+
import * as v from "valibot";
|
|
3
3
|
import { CanopyError } from "../lib/canopy-error";
|
|
4
|
-
declare const mailchimpSubscribeErrorCodeSchema:
|
|
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 =
|
|
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
|
|
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 =
|
|
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 =
|
|
19
|
-
status:
|
|
18
|
+
const mailchimpSubscribeSuccessSchema = v.object({
|
|
19
|
+
status: v.picklist(["subscribed", "pending"])
|
|
20
20
|
});
|
|
21
|
-
const mailchimpSubscribeFailureSchema =
|
|
21
|
+
const mailchimpSubscribeFailureSchema = v.object({
|
|
22
22
|
key: mailchimpSubscribeErrorCodeSchema,
|
|
23
|
-
message:
|
|
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 =
|
|
68
|
+
const failure = v.safeParse(mailchimpSubscribeFailureSchema, body);
|
|
69
69
|
throw new MailchimpSubscribeError(
|
|
70
|
-
failure.success ? {
|
|
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.
|
|
77
|
+
cause: new v.ValiError(failure.issues)
|
|
74
78
|
}
|
|
75
79
|
);
|
|
76
80
|
}
|
|
77
|
-
const success =
|
|
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.
|
|
86
|
+
cause: new v.ValiError(success.issues)
|
|
83
87
|
});
|
|
84
88
|
}
|
|
85
|
-
return success.
|
|
89
|
+
return success.output.status;
|
|
86
90
|
}
|
|
87
91
|
function useMailchimpSubscribe({
|
|
88
92
|
listId,
|
package/lib/buildMetadata.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const BUILD_METADATA = {
|
|
2
2
|
"packageName": "@replohq/sdk",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"branch": "HEAD",
|
|
5
|
-
"commit": "
|
|
6
|
-
"builtAt": "2026-10-20T23:
|
|
5
|
+
"commit": "cb0991cc863d256c3df479ed294f1a2dc48dba29",
|
|
6
|
+
"builtAt": "2026-10-20T23:18:54.483Z"
|
|
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:
|
|
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:
|
|
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
|
|
193
|
-
|
|
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/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@replohq/sdk",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"reploBuild": {
|
|
5
5
|
"packageName": "@replohq/sdk",
|
|
6
|
-
"version": "2.2.
|
|
6
|
+
"version": "2.2.1",
|
|
7
7
|
"branch": "HEAD",
|
|
8
|
-
"commit": "
|
|
9
|
-
"builtAt": "2026-10-20T23:
|
|
8
|
+
"commit": "cb0991cc863d256c3df479ed294f1a2dc48dba29",
|
|
9
|
+
"builtAt": "2026-10-20T23:18:54.483Z"
|
|
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
|
},
|