@replohq/canopy-sdk 0.4.1 → 0.6.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.
- package/_vendor/replo-utils/lib/geometry.d.ts +18 -0
- package/_vendor/replo-utils/lib/geometry.mjs +9 -0
- package/_vendor/replo-utils/lib/misc.d.ts +8 -8
- package/_vendor/replo-utils/lib/misc.mjs +1 -1
- package/_vendor/schemas/agentTools/customIntegrations/loaders/product.mjs +1 -1
- package/_vendor/schemas/errors.d.ts +1 -1
- package/_vendor/schemas/errors.mjs +7 -3
- package/_vendor/schemas/generated/selectMode.d.ts +8 -2
- package/_vendor/schemas/objectType.d.ts +2 -0
- package/_vendor/schemas/objectType.mjs +1 -1
- package/_vendor/schemas/registry.d.ts +283 -9
- package/_vendor/schemas/selectMode.d.ts +41 -2
- package/_vendor/schemas/selectMode.mjs +13 -4
- package/{chunk-XK2K3263.mjs → chunk-MSIQX4QA.mjs} +9 -7
- package/{chunk-7WEM5FUJ.mjs → chunk-ZLOHRRSZ.mjs} +118 -3
- package/consent/consent-actions.d.ts +6 -0
- package/consent/consent-actions.js +1 -2
- package/consent/consent-actions.js.map +2 -2
- package/consent/consent-store.d.ts +19 -4
- package/consent/consent-store.js +32 -12
- package/consent/consent-store.js.map +2 -2
- package/consent/cookie.js +5 -10
- package/consent/cookie.js.map +2 -2
- package/consent/types.d.ts +5 -0
- package/consent/window-api.js +1 -1
- package/consent/window-api.js.map +2 -2
- package/editor/ClientErrorBoundary.d.ts +6 -3
- package/editor/ClientErrorBoundary.js +18 -5
- package/editor/ClientErrorBoundary.js.map +2 -2
- package/editor/LinkInterceptor.js +5 -5
- package/editor/LinkInterceptor.js.map +2 -2
- package/editor/NextErrorReporter.d.ts +1 -0
- package/editor/NextErrorReporter.js +63 -0
- package/editor/NextErrorReporter.js.map +7 -0
- package/editor/select-mode/hooks/useSelectModeController.js +2 -1
- package/editor/select-mode/hooks/useSelectModeController.js.map +2 -2
- package/editor/select-mode/hooks/useSelectionInteractions.d.ts +3 -3
- package/editor/select-mode/hooks/useSelectionInteractions.js +54 -16
- package/editor/select-mode/hooks/useSelectionInteractions.js.map +2 -2
- package/editor/select-mode/interactions/selectionGeometry.d.ts +37 -12
- package/editor/select-mode/interactions/selectionGeometry.js +52 -24
- package/editor/select-mode/interactions/selectionGeometry.js.map +2 -2
- package/editor/select-mode/selectionFrame.d.ts +26 -7
- package/editor/select-mode/selectionFrame.js +58 -34
- package/editor/select-mode/selectionFrame.js.map +2 -2
- package/editor/select-mode/symbolicate.js +32 -1
- package/editor/select-mode/symbolicate.js.map +2 -2
- package/package.json +1 -1
- package/providers/replo-provider.js +11 -7
- package/providers/replo-provider.js.map +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseJsonOrNull } from '../../chunk-VKO7P3ED.mjs';
|
|
2
|
-
import { exhaustiveSwitch } from '../../chunk-
|
|
2
|
+
import { exhaustiveSwitch } from '../../chunk-MSIQX4QA.mjs';
|
|
3
3
|
import '../../chunk-GV5FY7ZZ.mjs';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
|
|
@@ -36,6 +36,10 @@ var selectModeBoundingRectSchema = z.object({
|
|
|
36
36
|
width: z.number(),
|
|
37
37
|
height: z.number()
|
|
38
38
|
}).describe("SelectModeBoundingRect");
|
|
39
|
+
var selectModeSelectionRectSchema = z.object({
|
|
40
|
+
id: z.string(),
|
|
41
|
+
rect: selectModeBoundingRectSchema
|
|
42
|
+
}).describe("SelectModeSelectionRect");
|
|
39
43
|
function transformRect({
|
|
40
44
|
rect,
|
|
41
45
|
offset
|
|
@@ -134,7 +138,11 @@ var selectModeSelectionSchema = z.discriminatedUnion("type", [
|
|
|
134
138
|
}),
|
|
135
139
|
z.object({
|
|
136
140
|
type: z.literal("drag"),
|
|
137
|
-
|
|
141
|
+
dragRect: selectModeBoundingRectSchema,
|
|
142
|
+
// Bounding boxes of the selectables the drag currently intersects,
|
|
143
|
+
// rendered as lighter highlights so the user can see what the drag
|
|
144
|
+
// will capture before they release.
|
|
145
|
+
selectionRects: z.array(selectModeSelectionRectSchema)
|
|
138
146
|
})
|
|
139
147
|
]).describe("SelectModeSelection");
|
|
140
148
|
var selectModeParentMessageSchema = z.discriminatedUnion("type", [
|
|
@@ -175,7 +183,8 @@ var selectModeIframeMessageSchema = z.discriminatedUnion("type", [
|
|
|
175
183
|
}),
|
|
176
184
|
z.object({
|
|
177
185
|
type: z.literal("replo:select:dragRectUpdated"),
|
|
178
|
-
|
|
186
|
+
dragRect: selectModeBoundingRectSchema.nullable(),
|
|
187
|
+
selectionRects: z.array(selectModeSelectionRectSchema)
|
|
179
188
|
}),
|
|
180
189
|
z.object({
|
|
181
190
|
type: z.literal("replo:select:areaSelected"),
|
|
@@ -184,4 +193,4 @@ var selectModeIframeMessageSchema = z.discriminatedUnion("type", [
|
|
|
184
193
|
})
|
|
185
194
|
]).describe("SelectModeIframeMessage");
|
|
186
195
|
|
|
187
|
-
export { SELECT_MODE_SELECTABLE_ATTRIBUTE, SELECT_MODE_SELECTABLE_PAYLOAD_ATTRIBUTE, displayModeSchema, getIframeOffset, readSelectablePayload, selectModeBoundingRectSchema, selectModeClickPositionSchema, selectModeIframeMessageSchema, selectModeParentMessageSchema, selectModeSelectionSchema, selectModeSelectionTypeSchema, selectModeSourceLocationSchema, selectModeTextMetricsSchema, selectableDataPayloadSchema, selectableDataSchema, selectablePlanDataSchema, selectablePlanPayloadSchema, selectedElementSchema, transformPoint, transformRect, transformSelectableData };
|
|
196
|
+
export { SELECT_MODE_SELECTABLE_ATTRIBUTE, SELECT_MODE_SELECTABLE_PAYLOAD_ATTRIBUTE, displayModeSchema, getIframeOffset, readSelectablePayload, selectModeBoundingRectSchema, selectModeClickPositionSchema, selectModeIframeMessageSchema, selectModeParentMessageSchema, selectModeSelectionRectSchema, selectModeSelectionSchema, selectModeSelectionTypeSchema, selectModeSourceLocationSchema, selectModeTextMetricsSchema, selectableDataPayloadSchema, selectableDataSchema, selectablePlanDataSchema, selectablePlanPayloadSchema, selectedElementSchema, transformPoint, transformRect, transformSelectableData };
|
|
@@ -1424,11 +1424,11 @@ function isPrimitive(value) {
|
|
|
1424
1424
|
function exhaustiveSwitch(value, discriminantKey = "type") {
|
|
1425
1425
|
return (cases) => {
|
|
1426
1426
|
const discriminant = value[discriminantKey];
|
|
1427
|
-
const
|
|
1428
|
-
if (!isFunction_default(
|
|
1429
|
-
return
|
|
1427
|
+
const caseHandler = cases[discriminant];
|
|
1428
|
+
if (!isFunction_default(caseHandler)) {
|
|
1429
|
+
return caseHandler;
|
|
1430
1430
|
}
|
|
1431
|
-
return
|
|
1431
|
+
return caseHandler(value);
|
|
1432
1432
|
};
|
|
1433
1433
|
}
|
|
1434
1434
|
function isEmpty2(value) {
|
|
@@ -1466,12 +1466,14 @@ function invariant(condition, message, opts) {
|
|
|
1466
1466
|
throw new Error(text);
|
|
1467
1467
|
}
|
|
1468
1468
|
var mergeReplacingObjects = (first, second) => {
|
|
1469
|
-
mergeWith_default(first, second, (
|
|
1470
|
-
return isObject_default(
|
|
1469
|
+
mergeWith_default(first, second, (_first, value) => {
|
|
1470
|
+
return isObject_default(value) && isEmpty2(value) ? value : void 0;
|
|
1471
1471
|
});
|
|
1472
1472
|
};
|
|
1473
1473
|
var mergeReplacingArrays = (first, second) => {
|
|
1474
|
-
mergeWith_default(first, second, (
|
|
1474
|
+
mergeWith_default(first, second, (_first, value) => {
|
|
1475
|
+
return isArray_default(value) ? value : void 0;
|
|
1476
|
+
});
|
|
1475
1477
|
};
|
|
1476
1478
|
var deepCloneAndMergeReplacingArrays = (source, ...toMerge) => {
|
|
1477
1479
|
const copy = cloneDeep_default(source);
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { sellingPlanGroupSchema } from './chunk-4TZVNC3W.mjs';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
|
|
4
|
-
var registryItemTypeSchema = z.enum(["site", "page", "section", "skill", "plan", "branding"]).describe("RegistryItemType");
|
|
4
|
+
var registryItemTypeSchema = z.enum(["site", "page", "section", "skill", "plan", "branding", "product"]).describe("RegistryItemType");
|
|
5
|
+
var registryItemVisibilitySchema = z.enum(["public", "unlisted"]).describe("RegistryItemVisibility");
|
|
6
|
+
var registrySlugSchema = z.string().min(1).max(120).regex(/^[\da-z][\d_a-z-]*$/);
|
|
7
|
+
var registryItemIdSchema = z.string().uuid();
|
|
8
|
+
var registryContentFilesSchema = z.record(z.string().min(1), z.string()).refine((files) => Object.keys(files).length > 0, {
|
|
9
|
+
message: "Registry item content must include at least one file"
|
|
10
|
+
});
|
|
5
11
|
z.object({
|
|
6
12
|
sourceType: z.string().min(1).max(80),
|
|
7
13
|
sourceKey: z.string().min(1).max(512)
|
|
@@ -24,12 +30,32 @@ var skillRegistryItemMetadataSchema = z.object({
|
|
|
24
30
|
command: z.string().optional(),
|
|
25
31
|
tagline: z.string().optional()
|
|
26
32
|
}).strict().describe("SkillRegistryItemMetadata");
|
|
33
|
+
var productRegistryItemMetadataSchema = z.object({
|
|
34
|
+
provider: z.string(),
|
|
35
|
+
providerDisplayName: z.string(),
|
|
36
|
+
providerProductId: z.string(),
|
|
37
|
+
productType: z.string().nullable().default(null),
|
|
38
|
+
productTypeName: z.string().nullable().default(null),
|
|
39
|
+
categoryIds: z.array(z.string()).default([]),
|
|
40
|
+
defaultVariantId: z.string().nullable().optional(),
|
|
41
|
+
capabilities: z.object({
|
|
42
|
+
mockupGeneration: z.boolean(),
|
|
43
|
+
fileUpload: z.boolean(),
|
|
44
|
+
productCreation: z.boolean(),
|
|
45
|
+
orderFulfillment: z.boolean(),
|
|
46
|
+
variantEditing: z.boolean()
|
|
47
|
+
}).strict(),
|
|
48
|
+
techniques: z.array(z.string()).default([]),
|
|
49
|
+
colors: z.array(z.string()).default([]),
|
|
50
|
+
sizes: z.array(z.string()).default([])
|
|
51
|
+
}).strict().describe("ProductRegistryItemMetadata");
|
|
27
52
|
var genericRegistryItemMetadataSchema = z.union([
|
|
28
53
|
siteRegistryItemMetadataSchema,
|
|
29
54
|
pageRegistryItemMetadataSchema,
|
|
30
55
|
sectionRegistryItemMetadataSchema,
|
|
31
56
|
skillRegistryItemMetadataSchema,
|
|
32
|
-
brandingRegistryItemMetadataSchema
|
|
57
|
+
brandingRegistryItemMetadataSchema,
|
|
58
|
+
productRegistryItemMetadataSchema
|
|
33
59
|
]).describe("GenericRegistryItemMetadata");
|
|
34
60
|
var registryItemMetadataSchema = z.object({
|
|
35
61
|
id: z.string(),
|
|
@@ -60,9 +86,15 @@ z.object({
|
|
|
60
86
|
z.object({
|
|
61
87
|
tags: z.array(z.string())
|
|
62
88
|
}).describe("RegistryItemTagsResult");
|
|
63
|
-
registryItemMetadataSchema.extend({
|
|
89
|
+
var registryItemDetailSchema = registryItemMetadataSchema.extend({
|
|
64
90
|
previewHtml: z.string().nullable()
|
|
65
91
|
}).describe("RegistryItemDetail");
|
|
92
|
+
z.object({
|
|
93
|
+
item: registryItemDetailSchema.extend({
|
|
94
|
+
projectId: z.null(),
|
|
95
|
+
createdBy: z.null()
|
|
96
|
+
})
|
|
97
|
+
}).describe("RegistryItemPreviewResult");
|
|
66
98
|
z.object({
|
|
67
99
|
meta: z.object({
|
|
68
100
|
id: z.string(),
|
|
@@ -74,6 +106,89 @@ z.object({
|
|
|
74
106
|
files: z.record(z.string(), z.string()),
|
|
75
107
|
dependencies: z.array(z.string())
|
|
76
108
|
}).describe("RegistryItemContent");
|
|
109
|
+
z.object({
|
|
110
|
+
object: z.literal("skill"),
|
|
111
|
+
id: z.string(),
|
|
112
|
+
slug: z.string(),
|
|
113
|
+
name: z.string(),
|
|
114
|
+
description: z.string().nullable(),
|
|
115
|
+
command: z.string().nullable(),
|
|
116
|
+
tagline: z.string().nullable(),
|
|
117
|
+
tags: z.array(z.string()),
|
|
118
|
+
category: z.string().nullable(),
|
|
119
|
+
visibility: z.string(),
|
|
120
|
+
createdAt: z.string(),
|
|
121
|
+
updatedAt: z.string()
|
|
122
|
+
}).describe("PublicSkill");
|
|
123
|
+
z.object({
|
|
124
|
+
name: z.string().min(1),
|
|
125
|
+
description: z.string().nullable().optional(),
|
|
126
|
+
// Spread from the stored metadata schema so the wire input cannot drift
|
|
127
|
+
// from what `RegistryItemMetadata` persists for skills.
|
|
128
|
+
...skillRegistryItemMetadataSchema.shape,
|
|
129
|
+
tags: z.array(z.string()).optional(),
|
|
130
|
+
category: z.string().nullable().optional(),
|
|
131
|
+
files: z.record(z.string().min(1), z.string()),
|
|
132
|
+
dependencies: z.array(z.string()).optional()
|
|
133
|
+
}).describe("PublicSkillUpsertInput");
|
|
134
|
+
z.object({
|
|
135
|
+
id: z.string().uuid(),
|
|
136
|
+
slug: z.string().min(1),
|
|
137
|
+
name: z.string().min(1),
|
|
138
|
+
type: registryItemTypeSchema,
|
|
139
|
+
projectId: z.string().min(1).nullable(),
|
|
140
|
+
createdBy: z.string().min(1).nullable(),
|
|
141
|
+
description: z.string().nullable(),
|
|
142
|
+
visibility: z.string(),
|
|
143
|
+
tags: z.array(z.string()),
|
|
144
|
+
category: z.string().nullable(),
|
|
145
|
+
sourceType: z.string().nullable().default(null),
|
|
146
|
+
sourceKey: z.string().nullable().default(null),
|
|
147
|
+
shortLink: z.string().nullable().default(null),
|
|
148
|
+
previewUrls: z.array(z.string()),
|
|
149
|
+
previewHtml: z.string().nullable(),
|
|
150
|
+
metadata: z.record(z.string(), z.unknown()).nullable(),
|
|
151
|
+
files: registryContentFilesSchema,
|
|
152
|
+
dependencies: z.array(z.string()),
|
|
153
|
+
embeddingText: z.string(),
|
|
154
|
+
embedding: z.array(z.number()),
|
|
155
|
+
createdAt: z.string().min(1),
|
|
156
|
+
updatedAt: z.string().min(1)
|
|
157
|
+
}).describe("RegistryItemDocument");
|
|
158
|
+
z.object({
|
|
159
|
+
item: z.object({
|
|
160
|
+
id: registryItemIdSchema,
|
|
161
|
+
slug: registrySlugSchema,
|
|
162
|
+
name: z.string().min(1),
|
|
163
|
+
type: registryItemTypeSchema,
|
|
164
|
+
projectId: z.string().min(1).nullable().default(null),
|
|
165
|
+
createdBy: z.string().min(1).nullable().default(null),
|
|
166
|
+
sourceType: z.string().min(1).max(80).nullable().default(null),
|
|
167
|
+
sourceKey: z.string().min(1).max(512).nullable().default(null),
|
|
168
|
+
description: z.string().nullable().default(null),
|
|
169
|
+
metadata: z.record(z.string(), z.unknown()).nullable().default(null),
|
|
170
|
+
visibility: registryItemVisibilitySchema.default("public"),
|
|
171
|
+
tags: z.array(z.string()).default([]),
|
|
172
|
+
category: z.string().nullable().default(null),
|
|
173
|
+
previewUrls: z.array(z.string()).default([]),
|
|
174
|
+
previewHtml: z.string().nullable().default(null),
|
|
175
|
+
files: registryContentFilesSchema,
|
|
176
|
+
dependencies: z.array(z.string()).default([])
|
|
177
|
+
})
|
|
178
|
+
}).describe("RegistryCreateItemInput");
|
|
179
|
+
z.object({
|
|
180
|
+
created: z.object({
|
|
181
|
+
id: registryItemIdSchema,
|
|
182
|
+
type: registryItemTypeSchema,
|
|
183
|
+
slug: registrySlugSchema,
|
|
184
|
+
sourceType: z.string().nullable(),
|
|
185
|
+
sourceKey: z.string().nullable(),
|
|
186
|
+
url: z.string().url().describe(
|
|
187
|
+
"Canonical public-facing URL for the new registry item. The skill returns this to the user immediately so they can share / preview without waiting on verification."
|
|
188
|
+
),
|
|
189
|
+
shareUrl: z.string().url().nullable()
|
|
190
|
+
})
|
|
191
|
+
}).describe("RegistryCreateItemOutput");
|
|
77
192
|
z.object({
|
|
78
193
|
appName: z.string(),
|
|
79
194
|
filepath: z.string(),
|
|
@@ -19,4 +19,10 @@ export declare function recordConsentAction(decision: {
|
|
|
19
19
|
categories: ConsentCategories;
|
|
20
20
|
consentMode: ConsentMode;
|
|
21
21
|
decidedAt: number;
|
|
22
|
+
/**
|
|
23
|
+
* Site-owned policy version declared by the consent caller (via
|
|
24
|
+
* `useConsent({ version })`); the site bumps it when the banner copy or
|
|
25
|
+
* category set changes.
|
|
26
|
+
*/
|
|
27
|
+
policyVersion: number;
|
|
22
28
|
}): Promise<void>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import { headers } from "next/headers";
|
|
3
3
|
import { getEnv } from "../env";
|
|
4
|
-
const CONSENT_POLICY_VERSION = 1;
|
|
5
4
|
async function recordConsentAction(decision) {
|
|
6
5
|
try {
|
|
7
6
|
const { PROJECT_ID, ANALYTICS_FIRE_API_URL } = await getEnv();
|
|
@@ -16,7 +15,7 @@ async function recordConsentAction(decision) {
|
|
|
16
15
|
action: decision.action,
|
|
17
16
|
categories: decision.categories,
|
|
18
17
|
consentMode: decision.consentMode,
|
|
19
|
-
policyVersion:
|
|
18
|
+
policyVersion: decision.policyVersion
|
|
20
19
|
};
|
|
21
20
|
await fetch(`${ANALYTICS_FIRE_API_URL}/api/v1/consent`, {
|
|
22
21
|
method: "POST",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../consent/consent-actions.ts"],
|
|
4
|
-
"sourcesContent": ["\"use server\";\n\nimport type {\n ConsentAction,\n ConsentMode,\n ConsentRecordRequest,\n} from \"schemas/generated/consent\";\nimport type { ConsentCategories } from \"./cookie\";\n\nimport { headers } from \"next/headers\";\n\nimport { getEnv } from \"../env\";\n\n
|
|
5
|
-
"mappings": ";AASA,SAAS,eAAe;AAExB,SAAS,cAAc;
|
|
4
|
+
"sourcesContent": ["\"use server\";\n\nimport type {\n ConsentAction,\n ConsentMode,\n ConsentRecordRequest,\n} from \"schemas/generated/consent\";\nimport type { ConsentCategories } from \"./cookie\";\n\nimport { headers } from \"next/headers\";\n\nimport { getEnv } from \"../env\";\n\n/**\n * Records a proof-of-consent decision by forwarding it to analytics-fire.\n *\n * Runs server-side \u2014 exactly like the cart's actions \u2014 so the browser never needs\n * the project id or the analytics-fire URL: both are read from the worker env\n * here via `getEnv()`. The visitor's user-agent / referrer / coarse geo come from\n * the incoming request headers and are forwarded so analytics-fire derives them\n * the same way it does for the legacy pixel.\n *\n * Best-effort and self-disabling: no-ops when analytics-fire isn't configured\n * (e.g. lean local dev) and never throws into the page.\n */\nexport async function recordConsentAction(decision: {\n consentId: string;\n action: ConsentAction;\n /** Full resulting consent state (all categories), not a diff. */\n categories: ConsentCategories;\n consentMode: ConsentMode;\n decidedAt: number;\n /**\n * Site-owned policy version declared by the consent caller (via\n * `useConsent({ version })`); the site bumps it when the banner copy or\n * category set changes.\n */\n policyVersion: number;\n}) {\n // Best-effort and total: never reject (the caller fire-and-forgets it), even if\n // the Cloudflare env / request context is unavailable.\n try {\n const { PROJECT_ID, ANALYTICS_FIRE_API_URL } = await getEnv();\n if (!ANALYTICS_FIRE_API_URL) {\n return;\n }\n\n const incoming = await headers();\n const body: ConsentRecordRequest = {\n consentId: decision.consentId,\n projectId: PROJECT_ID,\n decidedAt: decision.decidedAt,\n action: decision.action,\n categories: decision.categories,\n consentMode: decision.consentMode,\n policyVersion: decision.policyVersion,\n };\n\n await fetch(`${ANALYTICS_FIRE_API_URL}/api/v1/consent`, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n \"user-agent\": incoming.get(\"user-agent\") ?? \"\",\n referer: incoming.get(\"referer\") ?? \"\",\n \"cf-ipcountry\": incoming.get(\"cf-ipcountry\") ?? \"\",\n },\n body: JSON.stringify(body),\n });\n } catch {\n // Consent logging must never surface an error in the page.\n }\n}\n"],
|
|
5
|
+
"mappings": ";AASA,SAAS,eAAe;AAExB,SAAS,cAAc;AAcvB,eAAsB,oBAAoB,UAavC;AAGD,MAAI;AACF,UAAM,EAAE,YAAY,uBAAuB,IAAI,MAAM,OAAO;AAC5D,QAAI,CAAC,wBAAwB;AAC3B;AAAA,IACF;AAEA,UAAM,WAAW,MAAM,QAAQ;AAC/B,UAAM,OAA6B;AAAA,MACjC,WAAW,SAAS;AAAA,MACpB,WAAW;AAAA,MACX,WAAW,SAAS;AAAA,MACpB,QAAQ,SAAS;AAAA,MACjB,YAAY,SAAS;AAAA,MACrB,aAAa,SAAS;AAAA,MACtB,eAAe,SAAS;AAAA,IAC1B;AAEA,UAAM,MAAM,GAAG,sBAAsB,mBAAmB;AAAA,MACtD,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,cAAc,SAAS,IAAI,YAAY,KAAK;AAAA,QAC5C,SAAS,SAAS,IAAI,SAAS,KAAK;AAAA,QACpC,gBAAgB,SAAS,IAAI,cAAc,KAAK;AAAA,MAClD;AAAA,MACA,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B,CAAC;AAAA,EACH,QAAQ;AAAA,EAER;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,20 +29,35 @@ export declare const consentStore: {
|
|
|
29
29
|
getServerSnapshot(): ConsentState;
|
|
30
30
|
subscribe(listener: () => void): () => void;
|
|
31
31
|
/** Grant every consent category. */
|
|
32
|
-
accept(
|
|
32
|
+
accept(options?: {
|
|
33
|
+
policyVersion?: number;
|
|
34
|
+
}): void;
|
|
33
35
|
/** Deny every non-necessary category. */
|
|
34
|
-
reject(
|
|
36
|
+
reject(options?: {
|
|
37
|
+
policyVersion?: number;
|
|
38
|
+
}): void;
|
|
35
39
|
/** Set a subset of categories, leaving the rest at their current value. */
|
|
36
|
-
updateCategories(next
|
|
40
|
+
updateCategories({ next, policyVersion, }: {
|
|
41
|
+
next: Partial<ConsentCategories>;
|
|
42
|
+
policyVersion?: number;
|
|
43
|
+
}): void;
|
|
37
44
|
/** Test-only: reset cached state so the next read recomputes. */
|
|
38
45
|
reset(): void;
|
|
39
46
|
};
|
|
47
|
+
export interface UseConsentOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Site-owned consent policy version, stamped onto each proof-of-consent
|
|
50
|
+
* record so a decision can be tied to the exact banner the visitor saw.
|
|
51
|
+
* Bump it whenever the banner copy or category set changes. Defaults to 1.
|
|
52
|
+
*/
|
|
53
|
+
version?: number;
|
|
54
|
+
}
|
|
40
55
|
export interface UseConsentResult extends ConsentState {
|
|
41
56
|
accept(): void;
|
|
42
57
|
reject(): void;
|
|
43
58
|
updateCategories(next: Partial<ConsentCategories>): void;
|
|
44
59
|
}
|
|
45
|
-
export declare function useConsent(): UseConsentResult;
|
|
60
|
+
export declare function useConsent(options?: UseConsentOptions): UseConsentResult;
|
|
46
61
|
/**
|
|
47
62
|
* Whether a script requiring `requiredConsent` is allowed to load right now.
|
|
48
63
|
* `mode === "off"` always allows; otherwise every required category must be
|
package/consent/consent-store.js
CHANGED
|
@@ -33,6 +33,7 @@ function resolveMode() {
|
|
|
33
33
|
const attribute = document.documentElement.dataset.reploConsentMode;
|
|
34
34
|
return isConsentMode(attribute) ? attribute : "off";
|
|
35
35
|
}
|
|
36
|
+
const DEFAULT_CONSENT_POLICY_VERSION = 1;
|
|
36
37
|
function computeSnapshot() {
|
|
37
38
|
if (typeof window === "undefined") {
|
|
38
39
|
return SERVER_SNAPSHOT;
|
|
@@ -71,7 +72,10 @@ function notify() {
|
|
|
71
72
|
listener();
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
|
-
function commit(
|
|
75
|
+
function commit({
|
|
76
|
+
categories,
|
|
77
|
+
policyVersion = DEFAULT_CONSENT_POLICY_VERSION
|
|
78
|
+
}) {
|
|
75
79
|
const previous = consentStore.getSnapshot();
|
|
76
80
|
const decidedAt = Date.now();
|
|
77
81
|
const consentId = previous.consentId ?? crypto.randomUUID();
|
|
@@ -101,7 +105,8 @@ function commit(categories) {
|
|
|
101
105
|
action: deriveConsentAction({ previous, next: resultingCategories }),
|
|
102
106
|
categories: resultingCategories,
|
|
103
107
|
consentMode: previous.mode,
|
|
104
|
-
decidedAt
|
|
108
|
+
decidedAt,
|
|
109
|
+
policyVersion
|
|
105
110
|
}).finally(reloadIfDowngraded);
|
|
106
111
|
} else {
|
|
107
112
|
reloadIfDowngraded();
|
|
@@ -124,24 +129,37 @@ const consentStore = {
|
|
|
124
129
|
};
|
|
125
130
|
},
|
|
126
131
|
/** Grant every consent category. */
|
|
127
|
-
accept() {
|
|
128
|
-
commit(
|
|
132
|
+
accept(options = {}) {
|
|
133
|
+
commit({
|
|
134
|
+
categories: GRANTED_CATEGORIES,
|
|
135
|
+
policyVersion: options.policyVersion
|
|
136
|
+
});
|
|
129
137
|
},
|
|
130
138
|
/** Deny every non-necessary category. */
|
|
131
|
-
reject() {
|
|
132
|
-
commit(
|
|
139
|
+
reject(options = {}) {
|
|
140
|
+
commit({
|
|
141
|
+
categories: DENIED_CATEGORIES,
|
|
142
|
+
policyVersion: options.policyVersion
|
|
143
|
+
});
|
|
133
144
|
},
|
|
134
145
|
/** Set a subset of categories, leaving the rest at their current value. */
|
|
135
|
-
updateCategories(
|
|
146
|
+
updateCategories({
|
|
147
|
+
next,
|
|
148
|
+
policyVersion
|
|
149
|
+
}) {
|
|
136
150
|
const current = consentStore.getSnapshot().categories;
|
|
137
|
-
commit({
|
|
151
|
+
commit({
|
|
152
|
+
categories: { ...current, ...next, necessary: true },
|
|
153
|
+
policyVersion
|
|
154
|
+
});
|
|
138
155
|
},
|
|
139
156
|
/** Test-only: reset cached state so the next read recomputes. */
|
|
140
157
|
reset() {
|
|
141
158
|
snapshot = null;
|
|
142
159
|
}
|
|
143
160
|
};
|
|
144
|
-
function useConsent() {
|
|
161
|
+
function useConsent(options = {}) {
|
|
162
|
+
const policyVersion = options.version;
|
|
145
163
|
const state = useSyncExternalStore(
|
|
146
164
|
consentStore.subscribe,
|
|
147
165
|
consentStore.getSnapshot,
|
|
@@ -149,9 +167,11 @@ function useConsent() {
|
|
|
149
167
|
);
|
|
150
168
|
return {
|
|
151
169
|
...state,
|
|
152
|
-
accept: consentStore.accept,
|
|
153
|
-
reject: consentStore.reject,
|
|
154
|
-
updateCategories:
|
|
170
|
+
accept: () => consentStore.accept({ policyVersion }),
|
|
171
|
+
reject: () => consentStore.reject({ policyVersion }),
|
|
172
|
+
updateCategories: (next) => {
|
|
173
|
+
consentStore.updateCategories({ next, policyVersion });
|
|
174
|
+
}
|
|
155
175
|
};
|
|
156
176
|
}
|
|
157
177
|
function isConsentAllowed({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../consent/consent-store.ts"],
|
|
4
|
-
"sourcesContent": ["\"use client\";\n\nimport type { ConsentCategory, ConsentMode } from \"schemas/generated/consent\";\nimport type { ConsentCategories } from \"./cookie\";\n\nimport { useSyncExternalStore } from \"react\";\n\nimport { deriveConsentAction } from \"./consent-action\";\nimport { recordConsentAction } from \"./consent-actions\";\nimport {\n CONSENT_COOKIE_MAX_AGE_SECONDS,\n CONSENT_COOKIE_NAME,\n DENIED_CATEGORIES,\n GRANTED_CATEGORIES,\n parseConsentCookie,\n serializeConsentCookieValue,\n} from \"./cookie\";\n\n/**\n * Framework-agnostic, cookie-backed consent store. Lives as a single module\n * singleton so `ReploScripts`, the site's consent banner, and `AnalyticsProvider`\n * all share the same state regardless of where they sit in the React tree \u2014 no\n * provider-ancestor relationship is required.\n *\n * Consent-dependent work (script injection, banner visibility) happens on the\n * client (effects / post-mount), so there is no SSR/hydration mismatch. The\n * client reads the (non-httpOnly) consent cookie directly, so no server seed is\n * needed. The whole-site `mode` comes from the `data-replo-consent-mode`\n * attribute on `<html>`.\n */\n\nexport interface ConsentState {\n mode: ConsentMode;\n categories: ConsentCategories;\n /** Epoch ms when the visitor last made a choice, or null if undecided. */\n decidedAt: number | null;\n /**\n * Persistent pseudonymous per-browser id linking a visitor's consent history.\n * Absent until the first `commit()` (and on legacy pre-id cookies, until the\n * next interaction lazily backfills it).\n */\n consentId?: string;\n}\n\n// The non-necessary categories a visitor can grant or revoke. `necessary` is\n// always granted and never toggled.\nconst TOGGLEABLE_CATEGORIES: Exclude<ConsentCategory, \"necessary\">[] = [\n \"analytics\",\n \"marketing\",\n \"preferences\",\n \"sale_of_data\",\n];\n\n// A stable reference for SSR / first hydration render. Consent-dependent DOM is\n// only produced on the client, so this constant never causes a mismatch.\nconst SERVER_SNAPSHOT: ConsentState = Object.freeze({\n mode: \"off\",\n categories: DENIED_CATEGORIES,\n decidedAt: null,\n});\n\nconst listeners = new Set<() => void>();\nlet snapshot: ConsentState | null = null;\n\nfunction isConsentMode(value: string | null | undefined): value is ConsentMode {\n return value === \"off\" || value === \"simple\" || value === \"per-category\";\n}\n\nfunction resolveMode(): ConsentMode {\n if (typeof window === \"undefined\") {\n return \"off\";\n }\n const attribute = document.documentElement.dataset.reploConsentMode;\n return isConsentMode(attribute) ? attribute : \"off\";\n}\n\nfunction computeSnapshot(): ConsentState {\n if (typeof window === \"undefined\") {\n return SERVER_SNAPSHOT;\n }\n\n const mode = resolveMode();\n\n const fromCookie = parseConsentCookie(document.cookie);\n if (fromCookie) {\n return {\n mode,\n categories: {\n necessary: true,\n analytics: fromCookie.categories.analytics,\n marketing: fromCookie.categories.marketing,\n preferences: fromCookie.categories.preferences,\n sale_of_data: fromCookie.categories.sale_of_data,\n },\n decidedAt: fromCookie.decidedAt,\n consentId: fromCookie.consentId,\n };\n }\n\n return { mode, categories: DENIED_CATEGORIES, decidedAt: null };\n}\n\nfunction writeCookie(\n categories: ConsentCategories,\n decidedAt: number,\n consentId: string,\n) {\n if (typeof document === \"undefined\") {\n return;\n }\n const value = serializeConsentCookieValue({\n categories,\n decidedAt,\n consentId,\n });\n document.cookie = `${CONSENT_COOKIE_NAME}=${value}; path=/; max-age=${CONSENT_COOKIE_MAX_AGE_SECONDS}; SameSite=Lax`;\n}\n\nfunction notify() {\n for (const listener of listeners) {\n listener();\n }\n}\n\nfunction commit(categories: ConsentCategories) {\n const previous = consentStore.getSnapshot();\n const decidedAt = Date.now();\n // Reuse the visitor's existing id, or mint one on the first decision (also\n // lazily backfills legacy pre-id cookies). `crypto.randomUUID` is available in\n // every browser we target and on the server (where commit() never runs).\n const consentId = previous.consentId ?? crypto.randomUUID();\n const resultingCategories: ConsentCategories = {\n ...categories,\n necessary: true,\n };\n writeCookie(categories, decidedAt, consentId);\n snapshot = {\n mode: previous.mode,\n categories: resultingCategories,\n decidedAt,\n consentId,\n };\n notify();\n\n // Revocation cannot unload an already-loaded vendor. If the visitor had\n // previously decided and is now turning a granted category off, reload so the\n // page renders without those scripts. Deferred until after the audit record is\n // sent so the reload doesn't cancel the in-flight server action.\n const wasDowngrade =\n previous.decidedAt !== null &&\n TOGGLEABLE_CATEGORIES.some((category) => {\n return previous.categories[category] && !categories[category];\n });\n const reloadIfDowngraded = () => {\n if (wasDowngrade && typeof window !== \"undefined\") {\n window.location.reload();\n }\n };\n\n // Proof-of-consent audit record (ungated by consent, but only on managed\n // sites). On `mode === \"off\"` there is no banner/consent UX, so a\n // `setTrackingConsent()` call from a third-party script would only produce\n // meaningless `consent_mode: \"off\"` noise \u2014 skip it. Egress runs through a\n // server action (like the cart) so the client never needs the project id or\n // analytics-fire URL.\n if (previous.mode !== \"off\") {\n void recordConsentAction({\n consentId,\n action: deriveConsentAction({ previous, next: resultingCategories }),\n categories: resultingCategories,\n consentMode: previous.mode,\n decidedAt,\n }).finally(reloadIfDowngraded);\n } else {\n reloadIfDowngraded();\n }\n}\n\nexport const consentStore = {\n getSnapshot(): ConsentState {\n if (!snapshot) {\n snapshot = computeSnapshot();\n }\n return snapshot;\n },\n getServerSnapshot(): ConsentState {\n return SERVER_SNAPSHOT;\n },\n subscribe(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n /** Grant every consent category. */\n accept() {\n commit(GRANTED_CATEGORIES);\n },\n /** Deny every non-necessary category. */\n reject() {\n commit(DENIED_CATEGORIES);\n },\n /** Set a subset of categories, leaving the rest at their current value. */\n updateCategories(next: Partial<ConsentCategories
|
|
5
|
-
"mappings": ";AAKA,SAAS,4BAA4B;AAErC,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA8BP,MAAM,wBAAiE;AAAA,EACrE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAIA,MAAM,kBAAgC,OAAO,OAAO;AAAA,EAClD,MAAM;AAAA,EACN,YAAY;AAAA,EACZ,WAAW;AACb,CAAC;AAED,MAAM,YAAY,oBAAI,IAAgB;AACtC,IAAI,WAAgC;AAEpC,SAAS,cAAc,OAAwD;AAC7E,SAAO,UAAU,SAAS,UAAU,YAAY,UAAU;AAC5D;AAEA,SAAS,cAA2B;AAClC,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AACA,QAAM,YAAY,SAAS,gBAAgB,QAAQ;AACnD,SAAO,cAAc,SAAS,IAAI,YAAY;AAChD;
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { ConsentCategory, ConsentMode } from \"schemas/generated/consent\";\nimport type { ConsentCategories } from \"./cookie\";\n\nimport { useSyncExternalStore } from \"react\";\n\nimport { deriveConsentAction } from \"./consent-action\";\nimport { recordConsentAction } from \"./consent-actions\";\nimport {\n CONSENT_COOKIE_MAX_AGE_SECONDS,\n CONSENT_COOKIE_NAME,\n DENIED_CATEGORIES,\n GRANTED_CATEGORIES,\n parseConsentCookie,\n serializeConsentCookieValue,\n} from \"./cookie\";\n\n/**\n * Framework-agnostic, cookie-backed consent store. Lives as a single module\n * singleton so `ReploScripts`, the site's consent banner, and `AnalyticsProvider`\n * all share the same state regardless of where they sit in the React tree \u2014 no\n * provider-ancestor relationship is required.\n *\n * Consent-dependent work (script injection, banner visibility) happens on the\n * client (effects / post-mount), so there is no SSR/hydration mismatch. The\n * client reads the (non-httpOnly) consent cookie directly, so no server seed is\n * needed. The whole-site `mode` comes from the `data-replo-consent-mode`\n * attribute on `<html>`.\n */\n\nexport interface ConsentState {\n mode: ConsentMode;\n categories: ConsentCategories;\n /** Epoch ms when the visitor last made a choice, or null if undecided. */\n decidedAt: number | null;\n /**\n * Persistent pseudonymous per-browser id linking a visitor's consent history.\n * Absent until the first `commit()` (and on legacy pre-id cookies, until the\n * next interaction lazily backfills it).\n */\n consentId?: string;\n}\n\n// The non-necessary categories a visitor can grant or revoke. `necessary` is\n// always granted and never toggled.\nconst TOGGLEABLE_CATEGORIES: Exclude<ConsentCategory, \"necessary\">[] = [\n \"analytics\",\n \"marketing\",\n \"preferences\",\n \"sale_of_data\",\n];\n\n// A stable reference for SSR / first hydration render. Consent-dependent DOM is\n// only produced on the client, so this constant never causes a mismatch.\nconst SERVER_SNAPSHOT: ConsentState = Object.freeze({\n mode: \"off\",\n categories: DENIED_CATEGORIES,\n decidedAt: null,\n});\n\nconst listeners = new Set<() => void>();\nlet snapshot: ConsentState | null = null;\n\nfunction isConsentMode(value: string | null | undefined): value is ConsentMode {\n return value === \"off\" || value === \"simple\" || value === \"per-category\";\n}\n\nfunction resolveMode(): ConsentMode {\n if (typeof window === \"undefined\") {\n return \"off\";\n }\n const attribute = document.documentElement.dataset.reploConsentMode;\n return isConsentMode(attribute) ? attribute : \"off\";\n}\n\n// Used when the consent caller doesn't declare a policy version via\n// `useConsent({ version })` or the store method options.\nconst DEFAULT_CONSENT_POLICY_VERSION = 1;\n\nfunction computeSnapshot(): ConsentState {\n if (typeof window === \"undefined\") {\n return SERVER_SNAPSHOT;\n }\n\n const mode = resolveMode();\n\n const fromCookie = parseConsentCookie(document.cookie);\n if (fromCookie) {\n return {\n mode,\n categories: {\n necessary: true,\n analytics: fromCookie.categories.analytics,\n marketing: fromCookie.categories.marketing,\n preferences: fromCookie.categories.preferences,\n sale_of_data: fromCookie.categories.sale_of_data,\n },\n decidedAt: fromCookie.decidedAt,\n consentId: fromCookie.consentId,\n };\n }\n\n return { mode, categories: DENIED_CATEGORIES, decidedAt: null };\n}\n\nfunction writeCookie(\n categories: ConsentCategories,\n decidedAt: number,\n consentId: string,\n) {\n if (typeof document === \"undefined\") {\n return;\n }\n const value = serializeConsentCookieValue({\n categories,\n decidedAt,\n consentId,\n });\n document.cookie = `${CONSENT_COOKIE_NAME}=${value}; path=/; max-age=${CONSENT_COOKIE_MAX_AGE_SECONDS}; SameSite=Lax`;\n}\n\nfunction notify() {\n for (const listener of listeners) {\n listener();\n }\n}\n\nfunction commit({\n categories,\n policyVersion = DEFAULT_CONSENT_POLICY_VERSION,\n}: {\n categories: ConsentCategories;\n policyVersion?: number;\n}) {\n const previous = consentStore.getSnapshot();\n const decidedAt = Date.now();\n // Reuse the visitor's existing id, or mint one on the first decision (also\n // lazily backfills legacy pre-id cookies). `crypto.randomUUID` is available in\n // every browser we target and on the server (where commit() never runs).\n const consentId = previous.consentId ?? crypto.randomUUID();\n const resultingCategories: ConsentCategories = {\n ...categories,\n necessary: true,\n };\n writeCookie(categories, decidedAt, consentId);\n snapshot = {\n mode: previous.mode,\n categories: resultingCategories,\n decidedAt,\n consentId,\n };\n notify();\n\n // Revocation cannot unload an already-loaded vendor. If the visitor had\n // previously decided and is now turning a granted category off, reload so the\n // page renders without those scripts. Deferred until after the audit record is\n // sent so the reload doesn't cancel the in-flight server action.\n const wasDowngrade =\n previous.decidedAt !== null &&\n TOGGLEABLE_CATEGORIES.some((category) => {\n return previous.categories[category] && !categories[category];\n });\n const reloadIfDowngraded = () => {\n if (wasDowngrade && typeof window !== \"undefined\") {\n window.location.reload();\n }\n };\n\n // Proof-of-consent audit record (ungated by consent, but only on managed\n // sites). On `mode === \"off\"` there is no banner/consent UX, so a\n // `setTrackingConsent()` call from a third-party script would only produce\n // meaningless `consent_mode: \"off\"` noise \u2014 skip it. Egress runs through a\n // server action (like the cart) so the client never needs the project id or\n // analytics-fire URL.\n if (previous.mode !== \"off\") {\n void recordConsentAction({\n consentId,\n action: deriveConsentAction({ previous, next: resultingCategories }),\n categories: resultingCategories,\n consentMode: previous.mode,\n decidedAt,\n policyVersion,\n }).finally(reloadIfDowngraded);\n } else {\n reloadIfDowngraded();\n }\n}\n\nexport const consentStore = {\n getSnapshot(): ConsentState {\n if (!snapshot) {\n snapshot = computeSnapshot();\n }\n return snapshot;\n },\n getServerSnapshot(): ConsentState {\n return SERVER_SNAPSHOT;\n },\n subscribe(listener: () => void): () => void {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n /** Grant every consent category. */\n accept(options: { policyVersion?: number } = {}) {\n commit({\n categories: GRANTED_CATEGORIES,\n policyVersion: options.policyVersion,\n });\n },\n /** Deny every non-necessary category. */\n reject(options: { policyVersion?: number } = {}) {\n commit({\n categories: DENIED_CATEGORIES,\n policyVersion: options.policyVersion,\n });\n },\n /** Set a subset of categories, leaving the rest at their current value. */\n updateCategories({\n next,\n policyVersion,\n }: {\n next: Partial<ConsentCategories>;\n policyVersion?: number;\n }) {\n const current = consentStore.getSnapshot().categories;\n commit({\n categories: { ...current, ...next, necessary: true },\n policyVersion,\n });\n },\n /** Test-only: reset cached state so the next read recomputes. */\n reset() {\n snapshot = null;\n },\n};\n\nexport interface UseConsentOptions {\n /**\n * Site-owned consent policy version, stamped onto each proof-of-consent\n * record so a decision can be tied to the exact banner the visitor saw.\n * Bump it whenever the banner copy or category set changes. Defaults to 1.\n */\n version?: number;\n}\n\nexport interface UseConsentResult extends ConsentState {\n accept(): void;\n reject(): void;\n updateCategories(next: Partial<ConsentCategories>): void;\n}\n\nexport function useConsent(options: UseConsentOptions = {}): UseConsentResult {\n const policyVersion = options.version;\n const state = useSyncExternalStore(\n consentStore.subscribe,\n consentStore.getSnapshot,\n consentStore.getServerSnapshot,\n );\n return {\n ...state,\n accept: () => consentStore.accept({ policyVersion }),\n reject: () => consentStore.reject({ policyVersion }),\n updateCategories: (next) => {\n consentStore.updateCategories({ next, policyVersion });\n },\n };\n}\n\n/**\n * Whether a script requiring `requiredConsent` is allowed to load right now.\n * `mode === \"off\"` always allows; otherwise every required category must be\n * granted. An empty requirement list is always allowed.\n */\nexport function isConsentAllowed({\n state,\n requiredConsent,\n}: {\n state: ConsentState;\n requiredConsent: ConsentCategory[];\n}): boolean {\n if (state.mode === \"off\") {\n return true;\n }\n if (requiredConsent.length === 0) {\n return true;\n }\n return requiredConsent.every((category) => state.categories[category]);\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/consent/cookie.js
CHANGED
|
@@ -8,10 +8,10 @@ const persistedCookieSchema = z.object({
|
|
|
8
8
|
decidedAt: z.number().optional(),
|
|
9
9
|
consentId: z.string().optional(),
|
|
10
10
|
categories: z.object({
|
|
11
|
-
analytics: z.
|
|
12
|
-
marketing: z.
|
|
13
|
-
preferences: z.
|
|
14
|
-
sale_of_data: z.
|
|
11
|
+
analytics: z.boolean(),
|
|
12
|
+
marketing: z.boolean(),
|
|
13
|
+
preferences: z.boolean(),
|
|
14
|
+
sale_of_data: z.boolean()
|
|
15
15
|
})
|
|
16
16
|
});
|
|
17
17
|
const DENIED_CATEGORIES = {
|
|
@@ -49,12 +49,7 @@ function parseConsentCookie(rawCookie) {
|
|
|
49
49
|
version: CONSENT_COOKIE_VERSION,
|
|
50
50
|
decidedAt: decidedAt ?? Date.now(),
|
|
51
51
|
consentId,
|
|
52
|
-
categories
|
|
53
|
-
analytics: Boolean(categories.analytics),
|
|
54
|
-
marketing: Boolean(categories.marketing),
|
|
55
|
-
preferences: Boolean(categories.preferences),
|
|
56
|
-
sale_of_data: Boolean(categories.sale_of_data)
|
|
57
|
-
}
|
|
52
|
+
categories
|
|
58
53
|
};
|
|
59
54
|
}
|
|
60
55
|
function serializeConsentCookieValue({
|
package/consent/cookie.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../consent/cookie.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ConsentCategory } from \"schemas/generated/consent\";\n\nimport { parseJsonOrNull } from \"replo-utils/lib/json\";\nimport { z } from \"zod\";\n\n/**\n * Pure (non-React, framework-agnostic) consent cookie helpers used by the client\n * store (`consent-store.ts`).\n */\n\nexport const CONSENT_COOKIE_NAME = \"replo_consent\";\nexport const CONSENT_COOKIE_VERSION = 1;\nexport const CONSENT_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 180; // 180 days\n\n// Validates the untrusted JSON cookie payload at the parse boundary. A stale\n// version (or any shape mismatch) fails `safeParse`, so the caller treats the\n// visitor as undecided and re-prompts.\n//\n// `consentId` is OPTIONAL on purpose: it was added after v1 shipped, and we must\n// NOT bump `CONSENT_COOKIE_VERSION` to introduce it. Bumping would fail this\n// `safeParse` for every existing cookie, re-showing the banner and dropping the\n// visitor's prior decision. Optional keeps v1 cookies valid; `commit()` lazily\n// backfills the id on the next interaction.\nconst persistedCookieSchema = z.object({\n version: z.literal(CONSENT_COOKIE_VERSION),\n decidedAt: z.number().optional(),\n consentId: z.string().optional(),\n categories: z.object({\n analytics: z.
|
|
5
|
-
"mappings": "AAEA,SAAS,uBAAuB;AAChC,SAAS,SAAS;AAOX,MAAM,sBAAsB;AAC5B,MAAM,yBAAyB;AAC/B,MAAM,iCAAiC,KAAK,KAAK,KAAK;AAW7D,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,SAAS,EAAE,QAAQ,sBAAsB;AAAA,EACzC,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,YAAY,EAAE,OAAO;AAAA,IACnB,WAAW,EAAE,QAAQ
|
|
4
|
+
"sourcesContent": ["import type { ConsentCategory } from \"schemas/generated/consent\";\n\nimport { parseJsonOrNull } from \"replo-utils/lib/json\";\nimport { z } from \"zod\";\n\n/**\n * Pure (non-React, framework-agnostic) consent cookie helpers used by the client\n * store (`consent-store.ts`).\n */\n\nexport const CONSENT_COOKIE_NAME = \"replo_consent\";\nexport const CONSENT_COOKIE_VERSION = 1;\nexport const CONSENT_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 180; // 180 days\n\n// Validates the untrusted JSON cookie payload at the parse boundary. A stale\n// version (or any shape mismatch) fails `safeParse`, so the caller treats the\n// visitor as undecided and re-prompts.\n//\n// `consentId` is OPTIONAL on purpose: it was added after v1 shipped, and we must\n// NOT bump `CONSENT_COOKIE_VERSION` to introduce it. Bumping would fail this\n// `safeParse` for every existing cookie, re-showing the banner and dropping the\n// visitor's prior decision. Optional keeps v1 cookies valid; `commit()` lazily\n// backfills the id on the next interaction.\nconst persistedCookieSchema = z.object({\n version: z.literal(CONSENT_COOKIE_VERSION),\n decidedAt: z.number().optional(),\n consentId: z.string().optional(),\n categories: z.object({\n analytics: z.boolean(),\n marketing: z.boolean(),\n preferences: z.boolean(),\n sale_of_data: z.boolean(),\n }),\n});\n\nexport type ConsentCategories = Record<ConsentCategory, boolean>;\n\n/** Persisted cookie payload. `necessary` is always granted and never stored. */\nexport interface ConsentCookiePayload {\n version: number;\n decidedAt: number;\n /** Persistent pseudonymous per-browser id; absent on pre-id (legacy) cookies. */\n consentId?: string;\n categories: {\n analytics: boolean;\n marketing: boolean;\n preferences: boolean;\n sale_of_data: boolean;\n };\n}\n\nexport const DENIED_CATEGORIES: ConsentCategories = {\n necessary: true,\n analytics: false,\n marketing: false,\n preferences: false,\n sale_of_data: false,\n};\n\nexport const GRANTED_CATEGORIES: ConsentCategories = {\n necessary: true,\n analytics: true,\n marketing: true,\n preferences: true,\n sale_of_data: true,\n};\n\n/**\n * Parse a raw `document.cookie` (or a single cookie value) into a payload.\n * Returns null for missing, malformed, or stale-version cookies so callers\n * treat the visitor as undecided and re-prompt.\n */\nexport function parseConsentCookie(\n rawCookie: string | undefined,\n): ConsentCookiePayload | null {\n if (!rawCookie) {\n return null;\n }\n const match = rawCookie\n .split(\"; \")\n .find((entry) => entry.startsWith(`${CONSENT_COOKIE_NAME}=`));\n const encoded = match\n ? match.slice(CONSENT_COOKIE_NAME.length + 1)\n : rawCookie;\n\n // A tampered/corrupted cookie (bad percent-encoding) must not throw \u2014 that\n // would crash the client snapshot or the server seed read. Treat as undecided.\n let decoded: string;\n try {\n decoded = decodeURIComponent(encoded);\n } catch {\n return null;\n }\n\n const result = persistedCookieSchema.safeParse(parseJsonOrNull(decoded));\n if (!result.success) {\n return null;\n }\n const { decidedAt, categories, consentId } = result.data;\n\n return {\n version: CONSENT_COOKIE_VERSION,\n decidedAt: decidedAt ?? Date.now(),\n consentId,\n categories,\n };\n}\n\n/** Serialize categories into the JSON-encoded cookie value (not the full Set-Cookie line). */\nexport function serializeConsentCookieValue({\n categories,\n decidedAt,\n consentId,\n}: {\n categories: ConsentCategories;\n decidedAt: number;\n consentId?: string;\n}): string {\n const payload: ConsentCookiePayload = {\n version: CONSENT_COOKIE_VERSION,\n decidedAt,\n consentId,\n categories: {\n analytics: categories.analytics,\n marketing: categories.marketing,\n preferences: categories.preferences,\n sale_of_data: categories.sale_of_data,\n },\n };\n return encodeURIComponent(JSON.stringify(payload));\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,uBAAuB;AAChC,SAAS,SAAS;AAOX,MAAM,sBAAsB;AAC5B,MAAM,yBAAyB;AAC/B,MAAM,iCAAiC,KAAK,KAAK,KAAK;AAW7D,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,SAAS,EAAE,QAAQ,sBAAsB;AAAA,EACzC,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,WAAW,EAAE,OAAO,EAAE,SAAS;AAAA,EAC/B,YAAY,EAAE,OAAO;AAAA,IACnB,WAAW,EAAE,QAAQ;AAAA,IACrB,WAAW,EAAE,QAAQ;AAAA,IACrB,aAAa,EAAE,QAAQ;AAAA,IACvB,cAAc,EAAE,QAAQ;AAAA,EAC1B,CAAC;AACH,CAAC;AAkBM,MAAM,oBAAuC;AAAA,EAClD,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAChB;AAEO,MAAM,qBAAwC;AAAA,EACnD,WAAW;AAAA,EACX,WAAW;AAAA,EACX,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAChB;AAOO,SAAS,mBACd,WAC6B;AAC7B,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT;AACA,QAAM,QAAQ,UACX,MAAM,IAAI,EACV,KAAK,CAAC,UAAU,MAAM,WAAW,GAAG,mBAAmB,GAAG,CAAC;AAC9D,QAAM,UAAU,QACZ,MAAM,MAAM,oBAAoB,SAAS,CAAC,IAC1C;AAIJ,MAAI;AACJ,MAAI;AACF,cAAU,mBAAmB,OAAO;AAAA,EACtC,QAAQ;AACN,WAAO;AAAA,EACT;AAEA,QAAM,SAAS,sBAAsB,UAAU,gBAAgB,OAAO,CAAC;AACvE,MAAI,CAAC,OAAO,SAAS;AACnB,WAAO;AAAA,EACT;AACA,QAAM,EAAE,WAAW,YAAY,UAAU,IAAI,OAAO;AAEpD,SAAO;AAAA,IACL,SAAS;AAAA,IACT,WAAW,aAAa,KAAK,IAAI;AAAA,IACjC;AAAA,IACA;AAAA,EACF;AACF;AAGO,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AACF,GAIW;AACT,QAAM,UAAgC;AAAA,IACpC,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA,YAAY;AAAA,MACV,WAAW,WAAW;AAAA,MACtB,WAAW,WAAW;AAAA,MACtB,aAAa,WAAW;AAAA,MACxB,cAAc,WAAW;AAAA,IAC3B;AAAA,EACF;AACA,SAAO,mBAAmB,KAAK,UAAU,OAAO,CAAC;AACnD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/consent/types.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export type ReploScriptType = "GA4" | "GoogleTagManager" | "Meta" | "TikTok" | "Pinterest" | "Reddit" | "Snapchat" | "Hotjar" | "MicrosoftClarity" | "Triplewhale" | "Segment" | "custom";
|
|
2
2
|
export type ConsentCategory = "necessary" | "analytics" | "marketing" | "preferences" | "sale_of_data";
|
|
3
3
|
export type ConsentMode = "off" | "simple" | "per-category";
|
|
4
|
+
declare module "react" {
|
|
5
|
+
interface HtmlHTMLAttributes<T> {
|
|
6
|
+
"data-replo-consent-mode"?: ConsentMode;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
4
9
|
export type ScriptTagDescriptor = {
|
|
5
10
|
kind: "external";
|
|
6
11
|
src: string;
|
package/consent/window-api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../consent/window-api.ts"],
|
|
4
|
-
"sourcesContent": ["\"use client\";\n\nimport type { ConsentCategory } from \"schemas/generated/consent\";\n\nimport { consentStore, isConsentAllowed } from \"./consent-store\";\n\n/**\n * Global, framework-agnostic consent API exposed on `window.Replo.customerPrivacy`,\n * mirroring Shopify's Customer Privacy API surface so on-page (third-party)\n * scripts can query consent and react to changes without importing canopy.\n *\n * It deliberately lives under our own `window.Replo` namespace rather than\n * `window.Shopify` to avoid colliding with Shopify's real API on Shopify-backed\n * sites.\n */\n\ntype ToggleableCategory = Exclude<ConsentCategory, \"necessary\">;\n\n/** Shopify-style tri-state: declared-allowed, declared-denied, or undeclared. */\ntype ConsentSignal = \"yes\" | \"no\" | \"\";\n\nexport interface ReploCustomerPrivacyApi {\n /** Per-category declaration, or \"\" when the visitor has not decided. */\n currentVisitorConsent(): Record<ToggleableCategory, ConsentSignal>;\n analyticsProcessingAllowed(): boolean;\n marketingAllowed(): boolean;\n preferencesProcessingAllowed(): boolean;\n saleOfDataAllowed(): boolean;\n /** Whether the consent banner should still be shown (mode on + undecided). */\n shouldShowBanner(): boolean;\n /** Update a subset of categories; runs the optional callback once persisted. */\n setTrackingConsent(\n consent: Partial<Record<ToggleableCategory, boolean>>,\n callback?: () => void,\n ): void;\n}\n\ndeclare global {\n interface Window {\n Replo?: { customerPrivacy?: ReploCustomerPrivacyApi };\n }\n}\n\n/** DOM event dispatched on `document` whenever consent changes. */\nexport const CONSENT_CHANGE_EVENT = \"visitorConsentCollected\";\n\nfunction isAllowed(category: ConsentCategory): boolean {\n return isConsentAllowed({\n state: consentStore.getSnapshot(),\n requiredConsent: [category],\n });\n}\n\nfunction currentVisitorConsent(): Record<ToggleableCategory, ConsentSignal> {\n const state = consentStore.getSnapshot();\n const signal = (category: ToggleableCategory): ConsentSignal => {\n if (state.decidedAt === null) {\n return \"\";\n }\n return state.categories[category] ? \"yes\" : \"no\";\n };\n return {\n analytics: signal(\"analytics\"),\n marketing: signal(\"marketing\"),\n preferences: signal(\"preferences\"),\n sale_of_data: signal(\"sale_of_data\"),\n };\n}\n\nconst api: ReploCustomerPrivacyApi = {\n currentVisitorConsent,\n analyticsProcessingAllowed: () => isAllowed(\"analytics\"),\n marketingAllowed: () => isAllowed(\"marketing\"),\n preferencesProcessingAllowed: () => isAllowed(\"preferences\"),\n saleOfDataAllowed: () => isAllowed(\"sale_of_data\"),\n shouldShowBanner: () => {\n const state = consentStore.getSnapshot();\n return state.mode !== \"off\" && state.decidedAt === null;\n },\n setTrackingConsent: (consent, callback) => {\n consentStore.updateCategories(consent);\n callback?.();\n },\n};\n\nfunction consentChangeDetail() {\n return {\n analyticsAllowed: isAllowed(\"analytics\"),\n marketingAllowed: isAllowed(\"marketing\"),\n preferencesAllowed: isAllowed(\"preferences\"),\n saleOfDataAllowed: isAllowed(\"sale_of_data\"),\n };\n}\n\nlet teardown: (() => void) | null = null;\n\n/**\n * Installs `window.Replo.customerPrivacy` and dispatches `visitorConsentCollected`\n * on `document` whenever consent changes. Idempotent; returns a teardown that\n * removes the change subscription. Safe to call on the server (no-op).\n */\nexport function installConsentWindowApi(): () => void {\n if (typeof window === \"undefined\") {\n return () => {\n // no-op on the server\n };\n }\n if (teardown) {\n return teardown;\n }\n window.Replo = { ...window.Replo, customerPrivacy: api };\n const unsubscribe = consentStore.subscribe(() => {\n document.dispatchEvent(\n new CustomEvent(CONSENT_CHANGE_EVENT, { detail: consentChangeDetail() }),\n );\n });\n teardown = () => {\n unsubscribe();\n teardown = null;\n };\n return teardown;\n}\n"],
|
|
5
|
-
"mappings": ";AAIA,SAAS,cAAc,wBAAwB;AAwCxC,MAAM,uBAAuB;AAEpC,SAAS,UAAU,UAAoC;AACrD,SAAO,iBAAiB;AAAA,IACtB,OAAO,aAAa,YAAY;AAAA,IAChC,iBAAiB,CAAC,QAAQ;AAAA,EAC5B,CAAC;AACH;AAEA,SAAS,wBAAmE;AAC1E,QAAM,QAAQ,aAAa,YAAY;AACvC,QAAM,SAAS,CAAC,aAAgD;AAC9D,QAAI,MAAM,cAAc,MAAM;AAC5B,aAAO;AAAA,IACT;AACA,WAAO,MAAM,WAAW,QAAQ,IAAI,QAAQ;AAAA,EAC9C;AACA,SAAO;AAAA,IACL,WAAW,OAAO,WAAW;AAAA,IAC7B,WAAW,OAAO,WAAW;AAAA,IAC7B,aAAa,OAAO,aAAa;AAAA,IACjC,cAAc,OAAO,cAAc;AAAA,EACrC;AACF;AAEA,MAAM,MAA+B;AAAA,EACnC;AAAA,EACA,4BAA4B,MAAM,UAAU,WAAW;AAAA,EACvD,kBAAkB,MAAM,UAAU,WAAW;AAAA,EAC7C,8BAA8B,MAAM,UAAU,aAAa;AAAA,EAC3D,mBAAmB,MAAM,UAAU,cAAc;AAAA,EACjD,kBAAkB,MAAM;AACtB,UAAM,QAAQ,aAAa,YAAY;AACvC,WAAO,MAAM,SAAS,SAAS,MAAM,cAAc;AAAA,EACrD;AAAA,EACA,oBAAoB,CAAC,SAAS,aAAa;AACzC,iBAAa,iBAAiB,
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport type { ConsentCategory } from \"schemas/generated/consent\";\n\nimport { consentStore, isConsentAllowed } from \"./consent-store\";\n\n/**\n * Global, framework-agnostic consent API exposed on `window.Replo.customerPrivacy`,\n * mirroring Shopify's Customer Privacy API surface so on-page (third-party)\n * scripts can query consent and react to changes without importing canopy.\n *\n * It deliberately lives under our own `window.Replo` namespace rather than\n * `window.Shopify` to avoid colliding with Shopify's real API on Shopify-backed\n * sites.\n */\n\ntype ToggleableCategory = Exclude<ConsentCategory, \"necessary\">;\n\n/** Shopify-style tri-state: declared-allowed, declared-denied, or undeclared. */\ntype ConsentSignal = \"yes\" | \"no\" | \"\";\n\nexport interface ReploCustomerPrivacyApi {\n /** Per-category declaration, or \"\" when the visitor has not decided. */\n currentVisitorConsent(): Record<ToggleableCategory, ConsentSignal>;\n analyticsProcessingAllowed(): boolean;\n marketingAllowed(): boolean;\n preferencesProcessingAllowed(): boolean;\n saleOfDataAllowed(): boolean;\n /** Whether the consent banner should still be shown (mode on + undecided). */\n shouldShowBanner(): boolean;\n /** Update a subset of categories; runs the optional callback once persisted. */\n setTrackingConsent(\n consent: Partial<Record<ToggleableCategory, boolean>>,\n callback?: () => void,\n ): void;\n}\n\ndeclare global {\n interface Window {\n Replo?: { customerPrivacy?: ReploCustomerPrivacyApi };\n }\n}\n\n/** DOM event dispatched on `document` whenever consent changes. */\nexport const CONSENT_CHANGE_EVENT = \"visitorConsentCollected\";\n\nfunction isAllowed(category: ConsentCategory): boolean {\n return isConsentAllowed({\n state: consentStore.getSnapshot(),\n requiredConsent: [category],\n });\n}\n\nfunction currentVisitorConsent(): Record<ToggleableCategory, ConsentSignal> {\n const state = consentStore.getSnapshot();\n const signal = (category: ToggleableCategory): ConsentSignal => {\n if (state.decidedAt === null) {\n return \"\";\n }\n return state.categories[category] ? \"yes\" : \"no\";\n };\n return {\n analytics: signal(\"analytics\"),\n marketing: signal(\"marketing\"),\n preferences: signal(\"preferences\"),\n sale_of_data: signal(\"sale_of_data\"),\n };\n}\n\nconst api: ReploCustomerPrivacyApi = {\n currentVisitorConsent,\n analyticsProcessingAllowed: () => isAllowed(\"analytics\"),\n marketingAllowed: () => isAllowed(\"marketing\"),\n preferencesProcessingAllowed: () => isAllowed(\"preferences\"),\n saleOfDataAllowed: () => isAllowed(\"sale_of_data\"),\n shouldShowBanner: () => {\n const state = consentStore.getSnapshot();\n return state.mode !== \"off\" && state.decidedAt === null;\n },\n setTrackingConsent: (consent, callback) => {\n consentStore.updateCategories({ next: consent });\n callback?.();\n },\n};\n\nfunction consentChangeDetail() {\n return {\n analyticsAllowed: isAllowed(\"analytics\"),\n marketingAllowed: isAllowed(\"marketing\"),\n preferencesAllowed: isAllowed(\"preferences\"),\n saleOfDataAllowed: isAllowed(\"sale_of_data\"),\n };\n}\n\nlet teardown: (() => void) | null = null;\n\n/**\n * Installs `window.Replo.customerPrivacy` and dispatches `visitorConsentCollected`\n * on `document` whenever consent changes. Idempotent; returns a teardown that\n * removes the change subscription. Safe to call on the server (no-op).\n */\nexport function installConsentWindowApi(): () => void {\n if (typeof window === \"undefined\") {\n return () => {\n // no-op on the server\n };\n }\n if (teardown) {\n return teardown;\n }\n window.Replo = { ...window.Replo, customerPrivacy: api };\n const unsubscribe = consentStore.subscribe(() => {\n document.dispatchEvent(\n new CustomEvent(CONSENT_CHANGE_EVENT, { detail: consentChangeDetail() }),\n );\n });\n teardown = () => {\n unsubscribe();\n teardown = null;\n };\n return teardown;\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAS,cAAc,wBAAwB;AAwCxC,MAAM,uBAAuB;AAEpC,SAAS,UAAU,UAAoC;AACrD,SAAO,iBAAiB;AAAA,IACtB,OAAO,aAAa,YAAY;AAAA,IAChC,iBAAiB,CAAC,QAAQ;AAAA,EAC5B,CAAC;AACH;AAEA,SAAS,wBAAmE;AAC1E,QAAM,QAAQ,aAAa,YAAY;AACvC,QAAM,SAAS,CAAC,aAAgD;AAC9D,QAAI,MAAM,cAAc,MAAM;AAC5B,aAAO;AAAA,IACT;AACA,WAAO,MAAM,WAAW,QAAQ,IAAI,QAAQ;AAAA,EAC9C;AACA,SAAO;AAAA,IACL,WAAW,OAAO,WAAW;AAAA,IAC7B,WAAW,OAAO,WAAW;AAAA,IAC7B,aAAa,OAAO,aAAa;AAAA,IACjC,cAAc,OAAO,cAAc;AAAA,EACrC;AACF;AAEA,MAAM,MAA+B;AAAA,EACnC;AAAA,EACA,4BAA4B,MAAM,UAAU,WAAW;AAAA,EACvD,kBAAkB,MAAM,UAAU,WAAW;AAAA,EAC7C,8BAA8B,MAAM,UAAU,aAAa;AAAA,EAC3D,mBAAmB,MAAM,UAAU,cAAc;AAAA,EACjD,kBAAkB,MAAM;AACtB,UAAM,QAAQ,aAAa,YAAY;AACvC,WAAO,MAAM,SAAS,SAAS,MAAM,cAAc;AAAA,EACrD;AAAA,EACA,oBAAoB,CAAC,SAAS,aAAa;AACzC,iBAAa,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC/C,eAAW;AAAA,EACb;AACF;AAEA,SAAS,sBAAsB;AAC7B,SAAO;AAAA,IACL,kBAAkB,UAAU,WAAW;AAAA,IACvC,kBAAkB,UAAU,WAAW;AAAA,IACvC,oBAAoB,UAAU,aAAa;AAAA,IAC3C,mBAAmB,UAAU,cAAc;AAAA,EAC7C;AACF;AAEA,IAAI,WAAgC;AAO7B,SAAS,0BAAsC;AACpD,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,MAAM;AAAA,IAEb;AAAA,EACF;AACA,MAAI,UAAU;AACZ,WAAO;AAAA,EACT;AACA,SAAO,QAAQ,EAAE,GAAG,OAAO,OAAO,iBAAiB,IAAI;AACvD,QAAM,cAAc,aAAa,UAAU,MAAM;AAC/C,aAAS;AAAA,MACP,IAAI,YAAY,sBAAsB,EAAE,QAAQ,oBAAoB,EAAE,CAAC;AAAA,IACzE;AAAA,EACF,CAAC;AACD,aAAW,MAAM;AACf,gBAAY;AACZ,eAAW;AAAA,EACb;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
/**
|
|
3
|
-
* Client-side error boundary
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* NOTE (Max, 2026-06-10): Client-side error boundary. On a caught render error it
|
|
4
|
+
* (1) reports the error to the parent editor via postMessage (so it can get reported to Sentry)
|
|
5
|
+
* and (2) renders a neutral cover instead of going blank, so the preview never flashes the broken
|
|
6
|
+
* page while the agent fixes it. The editor decides what to show on top (loading
|
|
7
|
+
* vs. an actionable error screen); the embedder reloads the iframe once the error
|
|
8
|
+
* clears.
|
|
6
9
|
*/
|
|
7
10
|
export declare function ClientErrorBoundary({ children }: React.PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|