@replohq/canopy-sdk 0.4.1 → 0.5.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/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.mjs +1 -1
- package/_vendor/schemas/objectType.d.ts +2 -0
- package/_vendor/schemas/objectType.mjs +1 -1
- package/_vendor/schemas/registry.d.ts +96 -0
- package/_vendor/schemas/selectMode.mjs +1 -1
- package/{chunk-7WEM5FUJ.mjs → chunk-77XUQJHY.mjs} +22 -2
- package/{chunk-XK2K3263.mjs → chunk-MSIQX4QA.mjs} +9 -7
- 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/LinkInterceptor.js +5 -5
- package/editor/LinkInterceptor.js.map +2 -2
- package/package.json +1 -1
|
@@ -65,22 +65,22 @@ export declare function exhaustiveSwitch<UnionType extends {
|
|
|
65
65
|
type: string;
|
|
66
66
|
}>(value: UnionType): <ResultType>(cases: StructureRecord<UnionType, ResultType>) => ResultType;
|
|
67
67
|
export declare function exhaustiveSwitch<UnionType extends Record<KeyType, string>, KeyType extends keyof UnionType>(value: UnionType, key: KeyType): <ResultType>(cases: StructureRecordGeneric<UnionType, ResultType, KeyType>) => ResultType;
|
|
68
|
-
type EmptyObject<
|
|
69
|
-
[KeyType in keyof
|
|
68
|
+
type EmptyObject<ValueType> = {
|
|
69
|
+
[KeyType in keyof ValueType]?: never;
|
|
70
70
|
};
|
|
71
|
-
type EmptyObjectOf<
|
|
71
|
+
type EmptyObjectOf<ValueType> = EmptyObject<ValueType> extends ValueType ? EmptyObject<ValueType> : never;
|
|
72
72
|
/**
|
|
73
73
|
* The same as `isEmpty` from lodash, but with a few additional overloads for
|
|
74
74
|
* stronger type-checking on empty arrays.
|
|
75
75
|
*/
|
|
76
76
|
export declare function isEmpty(value: string): value is "";
|
|
77
|
-
export declare function isEmpty<
|
|
78
|
-
export declare function isEmpty<
|
|
77
|
+
export declare function isEmpty<ValueType extends any[]>(value: ValueType | null | undefined): value is (ValueType & []) | null | undefined;
|
|
78
|
+
export declare function isEmpty<ValueType extends ArrayLike<any>>(value: ValueType | null | undefined): value is (ValueType & {
|
|
79
79
|
length: 0;
|
|
80
80
|
}) | null | undefined;
|
|
81
81
|
export declare function isEmpty(value: Map<any, any> | Set<any> | ArrayLike<any> | null | undefined): boolean;
|
|
82
82
|
export declare function isEmpty(value: object): boolean;
|
|
83
|
-
export declare function isEmpty<
|
|
83
|
+
export declare function isEmpty<ValueType extends object>(value: ValueType | null | undefined): value is EmptyObjectOf<ValueType> | null | undefined;
|
|
84
84
|
export declare function isEmpty(value?: any): boolean;
|
|
85
85
|
export declare function noop(): void;
|
|
86
86
|
export declare function preventDefault(event: {
|
|
@@ -103,13 +103,13 @@ export declare function invariant(condition: unknown, message: string | (() => s
|
|
|
103
103
|
}): asserts condition;
|
|
104
104
|
export declare const mergeReplacingObjects: (first: Object, second: Object) => void;
|
|
105
105
|
export declare const mergeReplacingArrays: (first: Object, second: Object) => void;
|
|
106
|
-
export declare const deepCloneAndMergeReplacingArrays: <
|
|
106
|
+
export declare const deepCloneAndMergeReplacingArrays: <ValueType>(source: ValueType, ...toMerge: Object[]) => ValueType;
|
|
107
107
|
/**
|
|
108
108
|
* hasOwnProperty with a type assertion. If this returns true, typescript knows that `obj`
|
|
109
109
|
* has a property called `prop` from that point forward
|
|
110
110
|
* https://fettblog.eu/typescript-hasownproperty/
|
|
111
111
|
*/
|
|
112
|
-
export declare function hasOwnProperty<ObjectType extends {} | null | undefined,
|
|
112
|
+
export declare function hasOwnProperty<ObjectType extends {} | null | undefined, KeyType extends PropertyKey>(obj: ObjectType, prop: KeyType): obj is ObjectType & Record<KeyType, unknown>;
|
|
113
113
|
/**
|
|
114
114
|
* Given a string | number param, converts it to a string, unless it's nullish
|
|
115
115
|
* in which case it just returns it. Useful for times when you have string | number
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty, invariant, isEmpty, isFunction_default as isFunction, isNotNullish, isNullish, isPrimitive, isRecord, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, stringValue, warning } from '../../../chunk-
|
|
1
|
+
export { coerceNumberToString, deepCloneAndMergeReplacingArrays, errorMessage, exhaustiveSwitch, formatFileSize, getFromRecordOrNull, hasOwnProperty, invariant, isEmpty, isFunction_default as isFunction, isNotNullish, isNullish, isPrimitive, isRecord, mergeReplacingArrays, mergeReplacingObjects, noop, preventDefault, sleep, stringValue, warning } from '../../../chunk-MSIQX4QA.mjs';
|
|
2
2
|
export { isNumber_default as isNumber, isString_default as isString } from '../../../chunk-GV5FY7ZZ.mjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { priceSchema, metafieldSchema, imageSchema, selectedOptionSchema, mediaSchema, productOptionSchema, productSchema } from '../../../../../chunk-
|
|
1
|
+
import { priceSchema, metafieldSchema, imageSchema, selectedOptionSchema, mediaSchema, productOptionSchema, productSchema } from '../../../../../chunk-77XUQJHY.mjs';
|
|
2
2
|
import { sellingPlanGroupSchema } from '../../../../../chunk-4TZVNC3W.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MapCache_default, exhaustiveSwitch, hasOwnProperty, identity_default, baseFor_default, keys_default, Stack_default, isLength_default, isIndex_default, isArguments_default, getTag_default, isBuffer_default, isTypedArray_default, eq_default, Uint8Array_default, getAllKeys_default, baseAssignValue_default } from '../../chunk-
|
|
1
|
+
import { MapCache_default, exhaustiveSwitch, hasOwnProperty, identity_default, baseFor_default, keys_default, Stack_default, isLength_default, isIndex_default, isArguments_default, getTag_default, isBuffer_default, isTypedArray_default, eq_default, Uint8Array_default, getAllKeys_default, baseAssignValue_default } from '../../chunk-MSIQX4QA.mjs';
|
|
2
2
|
import { Symbol_default, isArray_default, isObject_default, isObjectLike_default, baseGetTag_default } from '../../chunk-GV5FY7ZZ.mjs';
|
|
3
3
|
import { z, ZodError } from 'zod';
|
|
4
4
|
|
|
@@ -332,6 +332,7 @@ export declare const registryItemSchema: z.ZodObject<{
|
|
|
332
332
|
slug: z.ZodOptional<z.ZodString>;
|
|
333
333
|
title: z.ZodOptional<z.ZodString>;
|
|
334
334
|
type: z.ZodOptional<z.ZodEnum<{
|
|
335
|
+
product: "product";
|
|
335
336
|
plan: "plan";
|
|
336
337
|
site: "site";
|
|
337
338
|
page: "page";
|
|
@@ -745,6 +746,7 @@ declare const OBJECT_TYPE_REGISTRY: {
|
|
|
745
746
|
slug: z.ZodOptional<z.ZodString>;
|
|
746
747
|
title: z.ZodOptional<z.ZodString>;
|
|
747
748
|
type: z.ZodOptional<z.ZodEnum<{
|
|
749
|
+
product: "product";
|
|
748
750
|
plan: "plan";
|
|
749
751
|
site: "site";
|
|
750
752
|
page: "page";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { assetSchema, collectionSchema, customerIoBroadcastSchema, customerIoCampaignSchema, customerIoSegmentSchema, externalVideoSchema, getObjectTypeDefinition, imageSchema, integrationSchema, intelligemsExperienceSchema, levantaAffiliateLinkSchema, levantaProductSchema, looxReviewSchema, mediaImageSchema, mediaSchema, metafieldSchema, okendoReviewSchema, optionValueSchema, optionValueSwatchSchema, opusClipSchema, opusCollectionSchema, opusProjectSchema, pageSchema, planSchema, previewImageSchema, priceSchema, productOptionSchema, productSchema, registryItemSchema, segmentSourceSchema, selectedOptionSchema, transformReploProductToCanonical, variantSchema, videoSchema, videoSourceSchema, vwoCampaignSchema } from '../../chunk-
|
|
1
|
+
export { assetSchema, collectionSchema, customerIoBroadcastSchema, customerIoCampaignSchema, customerIoSegmentSchema, externalVideoSchema, getObjectTypeDefinition, imageSchema, integrationSchema, intelligemsExperienceSchema, levantaAffiliateLinkSchema, levantaProductSchema, looxReviewSchema, mediaImageSchema, mediaSchema, metafieldSchema, okendoReviewSchema, optionValueSchema, optionValueSwatchSchema, opusClipSchema, opusCollectionSchema, opusProjectSchema, pageSchema, planSchema, previewImageSchema, priceSchema, productOptionSchema, productSchema, registryItemSchema, segmentSourceSchema, selectedOptionSchema, transformReploProductToCanonical, variantSchema, videoSchema, videoSourceSchema, vwoCampaignSchema } from '../../chunk-77XUQJHY.mjs';
|
|
2
2
|
import '../../chunk-4TZVNC3W.mjs';
|
|
@@ -18,6 +18,7 @@ import { z } from "zod";
|
|
|
18
18
|
* registry Worker does not host preview blobs anymore.
|
|
19
19
|
*/
|
|
20
20
|
export declare const registryItemTypeSchema: z.ZodEnum<{
|
|
21
|
+
product: "product";
|
|
21
22
|
plan: "plan";
|
|
22
23
|
site: "site";
|
|
23
24
|
page: "page";
|
|
@@ -54,6 +55,25 @@ export declare const skillRegistryItemMetadataSchema: z.ZodObject<{
|
|
|
54
55
|
command: z.ZodOptional<z.ZodString>;
|
|
55
56
|
tagline: z.ZodOptional<z.ZodString>;
|
|
56
57
|
}, z.core.$strict>;
|
|
58
|
+
export declare const productRegistryItemMetadataSchema: z.ZodObject<{
|
|
59
|
+
provider: z.ZodString;
|
|
60
|
+
providerDisplayName: z.ZodString;
|
|
61
|
+
providerProductId: z.ZodString;
|
|
62
|
+
productType: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
63
|
+
productTypeName: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
64
|
+
categoryIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
65
|
+
defaultVariantId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
66
|
+
capabilities: z.ZodObject<{
|
|
67
|
+
mockupGeneration: z.ZodBoolean;
|
|
68
|
+
fileUpload: z.ZodBoolean;
|
|
69
|
+
productCreation: z.ZodBoolean;
|
|
70
|
+
orderFulfillment: z.ZodBoolean;
|
|
71
|
+
variantEditing: z.ZodBoolean;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
techniques: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
74
|
+
colors: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
75
|
+
sizes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
76
|
+
}, z.core.$strict>;
|
|
57
77
|
export declare const genericRegistryItemMetadataSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
58
78
|
brandName: z.ZodOptional<z.ZodString>;
|
|
59
79
|
brandDomain: z.ZodOptional<z.ZodString>;
|
|
@@ -74,12 +94,31 @@ export declare const genericRegistryItemMetadataSchema: z.ZodUnion<readonly [z.Z
|
|
|
74
94
|
logoUrl: z.ZodOptional<z.ZodString>;
|
|
75
95
|
faviconUrl: z.ZodOptional<z.ZodString>;
|
|
76
96
|
tagline: z.ZodOptional<z.ZodString>;
|
|
97
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
98
|
+
provider: z.ZodString;
|
|
99
|
+
providerDisplayName: z.ZodString;
|
|
100
|
+
providerProductId: z.ZodString;
|
|
101
|
+
productType: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
102
|
+
productTypeName: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
103
|
+
categoryIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
104
|
+
defaultVariantId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
105
|
+
capabilities: z.ZodObject<{
|
|
106
|
+
mockupGeneration: z.ZodBoolean;
|
|
107
|
+
fileUpload: z.ZodBoolean;
|
|
108
|
+
productCreation: z.ZodBoolean;
|
|
109
|
+
orderFulfillment: z.ZodBoolean;
|
|
110
|
+
variantEditing: z.ZodBoolean;
|
|
111
|
+
}, z.core.$strict>;
|
|
112
|
+
techniques: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
113
|
+
colors: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
114
|
+
sizes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
77
115
|
}, z.core.$strict>]>;
|
|
78
116
|
export declare const registryItemMetadataSchema: z.ZodObject<{
|
|
79
117
|
id: z.ZodString;
|
|
80
118
|
slug: z.ZodString;
|
|
81
119
|
name: z.ZodString;
|
|
82
120
|
type: z.ZodEnum<{
|
|
121
|
+
product: "product";
|
|
83
122
|
plan: "plan";
|
|
84
123
|
site: "site";
|
|
85
124
|
page: "page";
|
|
@@ -107,6 +146,24 @@ export declare const registryItemMetadataSchema: z.ZodObject<{
|
|
|
107
146
|
logoUrl: z.ZodOptional<z.ZodString>;
|
|
108
147
|
faviconUrl: z.ZodOptional<z.ZodString>;
|
|
109
148
|
tagline: z.ZodOptional<z.ZodString>;
|
|
149
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
150
|
+
provider: z.ZodString;
|
|
151
|
+
providerDisplayName: z.ZodString;
|
|
152
|
+
providerProductId: z.ZodString;
|
|
153
|
+
productType: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
154
|
+
productTypeName: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
155
|
+
categoryIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
156
|
+
defaultVariantId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
157
|
+
capabilities: z.ZodObject<{
|
|
158
|
+
mockupGeneration: z.ZodBoolean;
|
|
159
|
+
fileUpload: z.ZodBoolean;
|
|
160
|
+
productCreation: z.ZodBoolean;
|
|
161
|
+
orderFulfillment: z.ZodBoolean;
|
|
162
|
+
variantEditing: z.ZodBoolean;
|
|
163
|
+
}, z.core.$strict>;
|
|
164
|
+
techniques: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
165
|
+
colors: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
166
|
+
sizes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
110
167
|
}, z.core.$strict>]>>;
|
|
111
168
|
projectId: z.ZodNullable<z.ZodString>;
|
|
112
169
|
createdBy: z.ZodNullable<z.ZodString>;
|
|
@@ -127,6 +184,7 @@ export declare const registryListItemsResultSchema: z.ZodObject<{
|
|
|
127
184
|
slug: z.ZodString;
|
|
128
185
|
name: z.ZodString;
|
|
129
186
|
type: z.ZodEnum<{
|
|
187
|
+
product: "product";
|
|
130
188
|
plan: "plan";
|
|
131
189
|
site: "site";
|
|
132
190
|
page: "page";
|
|
@@ -154,6 +212,24 @@ export declare const registryListItemsResultSchema: z.ZodObject<{
|
|
|
154
212
|
logoUrl: z.ZodOptional<z.ZodString>;
|
|
155
213
|
faviconUrl: z.ZodOptional<z.ZodString>;
|
|
156
214
|
tagline: z.ZodOptional<z.ZodString>;
|
|
215
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
216
|
+
provider: z.ZodString;
|
|
217
|
+
providerDisplayName: z.ZodString;
|
|
218
|
+
providerProductId: z.ZodString;
|
|
219
|
+
productType: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
220
|
+
productTypeName: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
221
|
+
categoryIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
222
|
+
defaultVariantId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
223
|
+
capabilities: z.ZodObject<{
|
|
224
|
+
mockupGeneration: z.ZodBoolean;
|
|
225
|
+
fileUpload: z.ZodBoolean;
|
|
226
|
+
productCreation: z.ZodBoolean;
|
|
227
|
+
orderFulfillment: z.ZodBoolean;
|
|
228
|
+
variantEditing: z.ZodBoolean;
|
|
229
|
+
}, z.core.$strict>;
|
|
230
|
+
techniques: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
231
|
+
colors: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
232
|
+
sizes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
157
233
|
}, z.core.$strict>]>>;
|
|
158
234
|
projectId: z.ZodNullable<z.ZodString>;
|
|
159
235
|
createdBy: z.ZodNullable<z.ZodString>;
|
|
@@ -181,6 +257,7 @@ export declare const registryItemDetailSchema: z.ZodObject<{
|
|
|
181
257
|
slug: z.ZodString;
|
|
182
258
|
name: z.ZodString;
|
|
183
259
|
type: z.ZodEnum<{
|
|
260
|
+
product: "product";
|
|
184
261
|
plan: "plan";
|
|
185
262
|
site: "site";
|
|
186
263
|
page: "page";
|
|
@@ -208,6 +285,24 @@ export declare const registryItemDetailSchema: z.ZodObject<{
|
|
|
208
285
|
logoUrl: z.ZodOptional<z.ZodString>;
|
|
209
286
|
faviconUrl: z.ZodOptional<z.ZodString>;
|
|
210
287
|
tagline: z.ZodOptional<z.ZodString>;
|
|
288
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
289
|
+
provider: z.ZodString;
|
|
290
|
+
providerDisplayName: z.ZodString;
|
|
291
|
+
providerProductId: z.ZodString;
|
|
292
|
+
productType: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
293
|
+
productTypeName: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
294
|
+
categoryIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
295
|
+
defaultVariantId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
296
|
+
capabilities: z.ZodObject<{
|
|
297
|
+
mockupGeneration: z.ZodBoolean;
|
|
298
|
+
fileUpload: z.ZodBoolean;
|
|
299
|
+
productCreation: z.ZodBoolean;
|
|
300
|
+
orderFulfillment: z.ZodBoolean;
|
|
301
|
+
variantEditing: z.ZodBoolean;
|
|
302
|
+
}, z.core.$strict>;
|
|
303
|
+
techniques: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
304
|
+
colors: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
305
|
+
sizes: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
211
306
|
}, z.core.$strict>]>>;
|
|
212
307
|
projectId: z.ZodNullable<z.ZodString>;
|
|
213
308
|
createdBy: z.ZodNullable<z.ZodString>;
|
|
@@ -228,6 +323,7 @@ export declare const registryItemContentSchema: z.ZodObject<{
|
|
|
228
323
|
id: z.ZodString;
|
|
229
324
|
slug: z.ZodString;
|
|
230
325
|
type: z.ZodEnum<{
|
|
326
|
+
product: "product";
|
|
231
327
|
plan: "plan";
|
|
232
328
|
site: "site";
|
|
233
329
|
page: "page";
|
|
@@ -1,7 +1,7 @@
|
|
|
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
5
|
z.object({
|
|
6
6
|
sourceType: z.string().min(1).max(80),
|
|
7
7
|
sourceKey: z.string().min(1).max(512)
|
|
@@ -24,12 +24,32 @@ var skillRegistryItemMetadataSchema = z.object({
|
|
|
24
24
|
command: z.string().optional(),
|
|
25
25
|
tagline: z.string().optional()
|
|
26
26
|
}).strict().describe("SkillRegistryItemMetadata");
|
|
27
|
+
var productRegistryItemMetadataSchema = z.object({
|
|
28
|
+
provider: z.string(),
|
|
29
|
+
providerDisplayName: z.string(),
|
|
30
|
+
providerProductId: z.string(),
|
|
31
|
+
productType: z.string().nullable().default(null),
|
|
32
|
+
productTypeName: z.string().nullable().default(null),
|
|
33
|
+
categoryIds: z.array(z.string()).default([]),
|
|
34
|
+
defaultVariantId: z.string().nullable().optional(),
|
|
35
|
+
capabilities: z.object({
|
|
36
|
+
mockupGeneration: z.boolean(),
|
|
37
|
+
fileUpload: z.boolean(),
|
|
38
|
+
productCreation: z.boolean(),
|
|
39
|
+
orderFulfillment: z.boolean(),
|
|
40
|
+
variantEditing: z.boolean()
|
|
41
|
+
}).strict(),
|
|
42
|
+
techniques: z.array(z.string()).default([]),
|
|
43
|
+
colors: z.array(z.string()).default([]),
|
|
44
|
+
sizes: z.array(z.string()).default([])
|
|
45
|
+
}).strict().describe("ProductRegistryItemMetadata");
|
|
27
46
|
var genericRegistryItemMetadataSchema = z.union([
|
|
28
47
|
siteRegistryItemMetadataSchema,
|
|
29
48
|
pageRegistryItemMetadataSchema,
|
|
30
49
|
sectionRegistryItemMetadataSchema,
|
|
31
50
|
skillRegistryItemMetadataSchema,
|
|
32
|
-
brandingRegistryItemMetadataSchema
|
|
51
|
+
brandingRegistryItemMetadataSchema,
|
|
52
|
+
productRegistryItemMetadataSchema
|
|
33
53
|
]).describe("GenericRegistryItemMetadata");
|
|
34
54
|
var registryItemMetadataSchema = z.object({
|
|
35
55
|
id: z.string(),
|
|
@@ -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);
|
|
@@ -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": ";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;AAIA,MA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S,WAAW,UAA6B,CAAC,GAAqB;AAC5E,QAAM,gBAAgB,QAAQ;AAC9B,QAAM,QAAQ;AAAA,IACZ,aAAa;AAAA,IACb,aAAa;AAAA,IACb,aAAa;AAAA,EACf;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ,MAAM,aAAa,OAAO,EAAE,cAAc,CAAC;AAAA,IACnD,QAAQ,MAAM,aAAa,OAAO,EAAE,cAAc,CAAC;AAAA,IACnD,kBAAkB,CAAC,SAAS;AAC1B,mBAAa,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAAA,IACvD;AAAA,EACF;AACF;AAOO,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AACF,GAGY;AACV,MAAI,MAAM,SAAS,OAAO;AACxB,WAAO;AAAA,EACT;AACA,MAAI,gBAAgB,WAAW,GAAG;AAChC,WAAO;AAAA,EACT;AACA,SAAO,gBAAgB,MAAM,CAAC,aAAa,MAAM,WAAW,QAAQ,CAAC;AACvE;",
|
|
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,QA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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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AM,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
|
}
|
|
@@ -66,8 +66,8 @@ function LinkInterceptor() {
|
|
|
66
66
|
}
|
|
67
67
|
event.preventDefault?.();
|
|
68
68
|
};
|
|
69
|
-
const handleClick = (
|
|
70
|
-
const target =
|
|
69
|
+
const handleClick = (event) => {
|
|
70
|
+
const target = event.target;
|
|
71
71
|
if (!(target instanceof Element)) {
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
@@ -84,14 +84,14 @@ function LinkInterceptor() {
|
|
|
84
84
|
}
|
|
85
85
|
const linkTarget = link.getAttribute("target");
|
|
86
86
|
if (linkTarget && linkTarget !== "_self") {
|
|
87
|
-
blockNavigation(
|
|
87
|
+
blockNavigation(event);
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
if (urlLeavesSandbox(href) === true) {
|
|
91
|
-
blockNavigation(
|
|
91
|
+
blockNavigation(event);
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
event.preventDefault();
|
|
95
95
|
let route;
|
|
96
96
|
try {
|
|
97
97
|
route = new URL(href, window.location.href).pathname;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../editor/LinkInterceptor.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\";\n\nimport { useEffect } from \"react\";\n\ntype NavigationNavigateEvent = {\n destination?: { url?: string };\n preventDefault?: () => void;\n};\n\ntype NavigationLike = {\n addEventListener: (\n type: \"navigate\",\n listener: (event: NavigationNavigateEvent) => void,\n ) => void;\n removeEventListener: (\n type: \"navigate\",\n listener: (event: NavigationNavigateEvent) => void,\n ) => void;\n};\n\nfunction blockNavigation(event: MouseEvent) {\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n}\n\nfunction isNavigationLike(value: unknown): value is NavigationLike {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n return (\n typeof Reflect.get(value, \"addEventListener\") === \"function\" &&\n typeof Reflect.get(value, \"removeEventListener\") === \"function\"\n );\n}\n\nfunction getWindowNavigation() {\n const navigation = Reflect.get(window, \"navigation\");\n return isNavigationLike(navigation) ? navigation : null;\n}\n\nfunction shouldInterceptNavigationForAgentPreview() {\n if (typeof window === \"undefined\") {\n return false;\n }\n\n if (window.parent === window) {\n return false;\n }\n\n return (\n new URLSearchParams(window.location.search).get(\"__reploAgentPreview\") ===\n \"1\"\n );\n}\n\nfunction urlLeavesSandbox(rawUrl: string | URL): boolean | null {\n try {\n const resolved =\n typeof rawUrl === \"string\"\n ? new URL(rawUrl, window.location.href)\n : new URL(rawUrl.href, window.location.href);\n return resolved.origin !== window.location.origin;\n } catch {\n return null;\n }\n}\n\nexport default function LinkInterceptor() {\n // eslint-disable-next-line replo/no-use-effect -- Browser navigation APIs must be patched at client runtime and restored when the interceptor unmounts.\n useEffect(() => {\n if (!shouldInterceptNavigationForAgentPreview()) {\n return;\n }\n\n const originalWindowOpen = window.open;\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n const navigation = getWindowNavigation();\n\n window.open = function (\n url?: string | URL,\n target?: string,\n features?: string,\n ) {\n if (url !== undefined && url !== \"\" && urlLeavesSandbox(url) === true) {\n return null;\n }\n\n return originalWindowOpen.call(window, url, target, features);\n };\n\n history.pushState = function (\n state: Parameters<History[\"pushState\"]>[0],\n unused: string,\n url?: string | URL | null,\n ) {\n if (url != null && url !== \"\" && urlLeavesSandbox(url) === true) {\n return;\n }\n\n return originalPushState.call(history, state, unused, url);\n };\n\n history.replaceState = function (\n state: Parameters<History[\"replaceState\"]>[0],\n unused: string,\n url?: string | URL | null,\n ) {\n if (url != null && url !== \"\" && urlLeavesSandbox(url) === true) {\n return;\n }\n\n return originalReplaceState.call(history, state, unused, url);\n };\n\n const handleNavigate = (event: NavigationNavigateEvent) => {\n const destinationUrl = event.destination?.url;\n if (\n destinationUrl === undefined ||\n destinationUrl === \"\" ||\n urlLeavesSandbox(destinationUrl) !== true\n ) {\n return;\n }\n\n event.preventDefault?.();\n };\n\n const handleClick = (
|
|
5
|
-
"mappings": ";AAEA,SAAS,iBAAiB;AAkB1B,SAAS,gBAAgB,OAAmB;AAC1C,QAAM,eAAe;AACrB,QAAM,gBAAgB;AACtB,QAAM,yBAAyB;AACjC;AAEA,SAAS,iBAAiB,OAAyC;AACjE,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,SACE,OAAO,QAAQ,IAAI,OAAO,kBAAkB,MAAM,cAClD,OAAO,QAAQ,IAAI,OAAO,qBAAqB,MAAM;AAEzD;AAEA,SAAS,sBAAsB;AAC7B,QAAM,aAAa,QAAQ,IAAI,QAAQ,YAAY;AACnD,SAAO,iBAAiB,UAAU,IAAI,aAAa;AACrD;AAEA,SAAS,2CAA2C;AAClD,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,WAAW,QAAQ;AAC5B,WAAO;AAAA,EACT;AAEA,SACE,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAAE,IAAI,qBAAqB,MACrE;AAEJ;AAEA,SAAS,iBAAiB,QAAsC;AAC9D,MAAI;AACF,UAAM,WACJ,OAAO,WAAW,WACd,IAAI,IAAI,QAAQ,OAAO,SAAS,IAAI,IACpC,IAAI,IAAI,OAAO,MAAM,OAAO,SAAS,IAAI;AAC/C,WAAO,SAAS,WAAW,OAAO,SAAS;AAAA,EAC7C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEe,SAAR,kBAAmC;AAExC,YAAU,MAAM;AACd,QAAI,CAAC,yCAAyC,GAAG;AAC/C;AAAA,IACF;AAEA,UAAM,qBAAqB,OAAO;AAClC,UAAM,oBAAoB,QAAQ;AAClC,UAAM,uBAAuB,QAAQ;AACrC,UAAM,aAAa,oBAAoB;AAEvC,WAAO,OAAO,SACZ,KACA,QACA,UACA;AACA,UAAI,QAAQ,UAAa,QAAQ,MAAM,iBAAiB,GAAG,MAAM,MAAM;AACrE,eAAO;AAAA,MACT;AAEA,aAAO,mBAAmB,KAAK,QAAQ,KAAK,QAAQ,QAAQ;AAAA,IAC9D;AAEA,YAAQ,YAAY,SAClB,OACA,QACA,KACA;AACA,UAAI,OAAO,QAAQ,QAAQ,MAAM,iBAAiB,GAAG,MAAM,MAAM;AAC/D;AAAA,MACF;AAEA,aAAO,kBAAkB,KAAK,SAAS,OAAO,QAAQ,GAAG;AAAA,IAC3D;AAEA,YAAQ,eAAe,SACrB,OACA,QACA,KACA;AACA,UAAI,OAAO,QAAQ,QAAQ,MAAM,iBAAiB,GAAG,MAAM,MAAM;AAC/D;AAAA,MACF;AAEA,aAAO,qBAAqB,KAAK,SAAS,OAAO,QAAQ,GAAG;AAAA,IAC9D;AAEA,UAAM,iBAAiB,CAAC,UAAmC;AACzD,YAAM,iBAAiB,MAAM,aAAa;AAC1C,UACE,mBAAmB,UACnB,mBAAmB,MACnB,iBAAiB,cAAc,MAAM,MACrC;AACA;AAAA,MACF;AAEA,YAAM,iBAAiB;AAAA,IACzB;AAEA,UAAM,cAAc,CAAC,
|
|
4
|
+
"sourcesContent": ["\"use client\";\n\nimport { useEffect } from \"react\";\n\ntype NavigationNavigateEvent = {\n destination?: { url?: string };\n preventDefault?: () => void;\n};\n\ntype NavigationLike = {\n addEventListener: (\n type: \"navigate\",\n listener: (event: NavigationNavigateEvent) => void,\n ) => void;\n removeEventListener: (\n type: \"navigate\",\n listener: (event: NavigationNavigateEvent) => void,\n ) => void;\n};\n\nfunction blockNavigation(event: MouseEvent) {\n event.preventDefault();\n event.stopPropagation();\n event.stopImmediatePropagation();\n}\n\nfunction isNavigationLike(value: unknown): value is NavigationLike {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n\n return (\n typeof Reflect.get(value, \"addEventListener\") === \"function\" &&\n typeof Reflect.get(value, \"removeEventListener\") === \"function\"\n );\n}\n\nfunction getWindowNavigation() {\n const navigation = Reflect.get(window, \"navigation\");\n return isNavigationLike(navigation) ? navigation : null;\n}\n\nfunction shouldInterceptNavigationForAgentPreview() {\n if (typeof window === \"undefined\") {\n return false;\n }\n\n if (window.parent === window) {\n return false;\n }\n\n return (\n new URLSearchParams(window.location.search).get(\"__reploAgentPreview\") ===\n \"1\"\n );\n}\n\nfunction urlLeavesSandbox(rawUrl: string | URL): boolean | null {\n try {\n const resolved =\n typeof rawUrl === \"string\"\n ? new URL(rawUrl, window.location.href)\n : new URL(rawUrl.href, window.location.href);\n return resolved.origin !== window.location.origin;\n } catch {\n return null;\n }\n}\n\nexport default function LinkInterceptor() {\n // eslint-disable-next-line replo/no-use-effect -- Browser navigation APIs must be patched at client runtime and restored when the interceptor unmounts.\n useEffect(() => {\n if (!shouldInterceptNavigationForAgentPreview()) {\n return;\n }\n\n const originalWindowOpen = window.open;\n const originalPushState = history.pushState;\n const originalReplaceState = history.replaceState;\n const navigation = getWindowNavigation();\n\n window.open = function (\n url?: string | URL,\n target?: string,\n features?: string,\n ) {\n if (url !== undefined && url !== \"\" && urlLeavesSandbox(url) === true) {\n return null;\n }\n\n return originalWindowOpen.call(window, url, target, features);\n };\n\n history.pushState = function (\n state: Parameters<History[\"pushState\"]>[0],\n unused: string,\n url?: string | URL | null,\n ) {\n if (url != null && url !== \"\" && urlLeavesSandbox(url) === true) {\n return;\n }\n\n return originalPushState.call(history, state, unused, url);\n };\n\n history.replaceState = function (\n state: Parameters<History[\"replaceState\"]>[0],\n unused: string,\n url?: string | URL | null,\n ) {\n if (url != null && url !== \"\" && urlLeavesSandbox(url) === true) {\n return;\n }\n\n return originalReplaceState.call(history, state, unused, url);\n };\n\n const handleNavigate = (event: NavigationNavigateEvent) => {\n const destinationUrl = event.destination?.url;\n if (\n destinationUrl === undefined ||\n destinationUrl === \"\" ||\n urlLeavesSandbox(destinationUrl) !== true\n ) {\n return;\n }\n\n event.preventDefault?.();\n };\n\n const handleClick = (event: MouseEvent) => {\n const target = event.target;\n\n if (!(target instanceof Element)) {\n return;\n }\n\n const link = target.closest(\"a[href]\");\n\n if (!(link instanceof HTMLAnchorElement)) {\n return;\n }\n\n const href = link.getAttribute(\"href\");\n if (!href) {\n return;\n }\n\n if (href.startsWith(\"#\")) {\n return;\n }\n\n const linkTarget = link.getAttribute(\"target\");\n if (linkTarget && linkTarget !== \"_self\") {\n blockNavigation(event);\n return;\n }\n\n if (urlLeavesSandbox(href) === true) {\n blockNavigation(event);\n return;\n }\n\n event.preventDefault();\n\n let route: string;\n try {\n route = new URL(href, window.location.href).pathname;\n } catch {\n route = href;\n }\n\n window.parent.postMessage(\n {\n type: \"replo:navigate\",\n route,\n },\n \"*\",\n );\n };\n\n navigation?.addEventListener(\"navigate\", handleNavigate);\n document.addEventListener(\"click\", handleClick, true);\n\n return () => {\n window.open = originalWindowOpen;\n history.pushState = originalPushState;\n history.replaceState = originalReplaceState;\n navigation?.removeEventListener(\"navigate\", handleNavigate);\n document.removeEventListener(\"click\", handleClick, true);\n };\n }, []);\n\n return null;\n}\n"],
|
|
5
|
+
"mappings": ";AAEA,SAAS,iBAAiB;AAkB1B,SAAS,gBAAgB,OAAmB;AAC1C,QAAM,eAAe;AACrB,QAAM,gBAAgB;AACtB,QAAM,yBAAyB;AACjC;AAEA,SAAS,iBAAiB,OAAyC;AACjE,MAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,WAAO;AAAA,EACT;AAEA,SACE,OAAO,QAAQ,IAAI,OAAO,kBAAkB,MAAM,cAClD,OAAO,QAAQ,IAAI,OAAO,qBAAqB,MAAM;AAEzD;AAEA,SAAS,sBAAsB;AAC7B,QAAM,aAAa,QAAQ,IAAI,QAAQ,YAAY;AACnD,SAAO,iBAAiB,UAAU,I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