@coframe/sdk 1.1.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/dist/pkg/cf.cjs.js +3353 -0
- package/dist/pkg/cf.esm.mjs +3344 -0
- package/dist/pkg/react.cjs.js +89 -0
- package/dist/pkg/react.esm.mjs +53 -0
- package/dist/pkg/server.cjs.js +96 -0
- package/dist/pkg/server.esm.mjs +94 -0
- package/dist/pkg/types/index.d.ts +308 -0
- package/dist/pkg/types/react.d.ts +303 -0
- package/dist/pkg/types/server.d.ts +229 -0
- package/package.json +130 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
export { init, onLog, onTreatmentApplied, setConsent, setFeatureFlag, setPageHydrated, setUserToken, trackConversion } from '@coframe/sdk';
|
|
3
|
+
|
|
4
|
+
interface UniversalSelector {
|
|
5
|
+
t: string;
|
|
6
|
+
fingerprint?: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
dataTestId?: string;
|
|
9
|
+
n?: {
|
|
10
|
+
i: number;
|
|
11
|
+
t: number;
|
|
12
|
+
};
|
|
13
|
+
text?: string;
|
|
14
|
+
href?: string;
|
|
15
|
+
ariaLabel?: string;
|
|
16
|
+
p?: UniversalSelector;
|
|
17
|
+
descendants?: {
|
|
18
|
+
depth: number;
|
|
19
|
+
sel: UniversalSelector;
|
|
20
|
+
}[];
|
|
21
|
+
isShadowRoot?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type ElementStyles = Record<string, string | undefined>;
|
|
25
|
+
type ElementAttributes = {
|
|
26
|
+
src?: string;
|
|
27
|
+
innerHTML?: string;
|
|
28
|
+
styles?: ElementStyles;
|
|
29
|
+
onClick?: string;
|
|
30
|
+
textContent?: string;
|
|
31
|
+
role?: string;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type ProjectTag = {
|
|
35
|
+
js: string | null;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
type Modification = ModificationUpdate | ModificationInsertInto | ModificationInsertBy | ModificationDelete | ModificationAddBanner | ModificationAddModal | ModificationExecuteJs;
|
|
39
|
+
type Modifications = {
|
|
40
|
+
[elementId: string]: Array<Modification>;
|
|
41
|
+
};
|
|
42
|
+
type NewElementAttributes = ElementAttributes & {
|
|
43
|
+
tagName?: 'h1' | 'p' | 'div' | 'span' | 'button' | 'input' | 'img' | 'div';
|
|
44
|
+
};
|
|
45
|
+
type ModificationUpdate = {
|
|
46
|
+
type: 'update';
|
|
47
|
+
attributes: ElementAttributes;
|
|
48
|
+
};
|
|
49
|
+
type ModificationInsertInto = {
|
|
50
|
+
type: 'insert_into';
|
|
51
|
+
child_position: 'first' | 'last';
|
|
52
|
+
new_element: NewElementAttributes;
|
|
53
|
+
};
|
|
54
|
+
type ModificationInsertBy = {
|
|
55
|
+
type: 'insert_by';
|
|
56
|
+
position: 'before' | 'after';
|
|
57
|
+
new_element: NewElementAttributes;
|
|
58
|
+
};
|
|
59
|
+
type ModificationDelete = {
|
|
60
|
+
type: 'delete';
|
|
61
|
+
};
|
|
62
|
+
type ModificationAddModal = {
|
|
63
|
+
type: 'add_modal';
|
|
64
|
+
modal_content: NewElementAttributes;
|
|
65
|
+
trigger: ModalTrigger;
|
|
66
|
+
};
|
|
67
|
+
type ModificationAddBanner = {
|
|
68
|
+
type: 'add_banner';
|
|
69
|
+
banner_content: NewElementAttributes;
|
|
70
|
+
};
|
|
71
|
+
type ModificationExecuteJs = {
|
|
72
|
+
type: 'execute_js';
|
|
73
|
+
js: string;
|
|
74
|
+
};
|
|
75
|
+
type ModalTrigger = 'exit' | 'scroll' | 'enter' | 'timer';
|
|
76
|
+
|
|
77
|
+
interface AnalyticsCallback {
|
|
78
|
+
callback: string;
|
|
79
|
+
}
|
|
80
|
+
interface TreatmentData {
|
|
81
|
+
impressionId: string;
|
|
82
|
+
userToken: string;
|
|
83
|
+
experimentId: string;
|
|
84
|
+
variantId: string;
|
|
85
|
+
inGlobalHoldout: boolean;
|
|
86
|
+
isBaseline: boolean;
|
|
87
|
+
holdoutExperimentId?: string;
|
|
88
|
+
}
|
|
89
|
+
interface TreatmentDataV2 {
|
|
90
|
+
coframe_experiment_id: string;
|
|
91
|
+
coframe_experiment_slug: string;
|
|
92
|
+
coframe_variant_id: string;
|
|
93
|
+
coframe_variant_slug: string;
|
|
94
|
+
coframe_user_token: string;
|
|
95
|
+
coframe_impression_id: string;
|
|
96
|
+
coframe_in_global_holdout: boolean;
|
|
97
|
+
coframe_in_exp_baseline: boolean;
|
|
98
|
+
}
|
|
99
|
+
declare const GLOBAL_HOLDOUT: "global_holdout";
|
|
100
|
+
declare const EXPERIMENT_HOLDOUT: "experiment_holdout";
|
|
101
|
+
declare const EXPERIMENT: "experiment";
|
|
102
|
+
type ExperimentLevel = typeof GLOBAL_HOLDOUT | typeof EXPERIMENT_HOLDOUT | typeof EXPERIMENT;
|
|
103
|
+
interface ExperimentInfo {
|
|
104
|
+
variant_id: string;
|
|
105
|
+
variant_slug: string;
|
|
106
|
+
experiment_id: string;
|
|
107
|
+
experiment_slug: string;
|
|
108
|
+
iteration_id: string;
|
|
109
|
+
level: ExperimentLevel;
|
|
110
|
+
final_state: boolean;
|
|
111
|
+
holdout_experiment_id?: string;
|
|
112
|
+
holdout_experiment_slug?: string;
|
|
113
|
+
}
|
|
114
|
+
interface Audience {
|
|
115
|
+
selector: ActivationCondition;
|
|
116
|
+
}
|
|
117
|
+
interface LaneMember {
|
|
118
|
+
experiment_id: string;
|
|
119
|
+
iteration_id: string;
|
|
120
|
+
}
|
|
121
|
+
interface LaneStatus {
|
|
122
|
+
seed: number;
|
|
123
|
+
members: LaneMember[];
|
|
124
|
+
}
|
|
125
|
+
interface HoldoutInfo {
|
|
126
|
+
holdout_experiment_id: string;
|
|
127
|
+
holdout_experiment_slug: string;
|
|
128
|
+
holdout_variant_id: string;
|
|
129
|
+
holdout_variant_slug: string;
|
|
130
|
+
treatment_variant_id: string;
|
|
131
|
+
treatment_variant_slug: string;
|
|
132
|
+
seed: number;
|
|
133
|
+
variant_bins: Allocation;
|
|
134
|
+
}
|
|
135
|
+
interface Metric {
|
|
136
|
+
id: string;
|
|
137
|
+
selector: SelectorCondition;
|
|
138
|
+
js_binder?: string;
|
|
139
|
+
}
|
|
140
|
+
interface ProjectSettings {
|
|
141
|
+
mutation_observer_active: boolean;
|
|
142
|
+
track_only_activated_frames?: boolean;
|
|
143
|
+
blocklist_ips?: string[];
|
|
144
|
+
bot_cloaking_enabled?: boolean;
|
|
145
|
+
bot_score_threshold?: number;
|
|
146
|
+
analytics_callback?: AnalyticsCallback;
|
|
147
|
+
}
|
|
148
|
+
interface Project {
|
|
149
|
+
org_id: string;
|
|
150
|
+
holdout_info: HoldoutInfo;
|
|
151
|
+
audiences: Record<string, Audience>;
|
|
152
|
+
frames: Frame[];
|
|
153
|
+
metrics?: Metric[];
|
|
154
|
+
settings: ProjectSettings;
|
|
155
|
+
tags?: ProjectTag[];
|
|
156
|
+
lanes?: Record<string, LaneStatus>;
|
|
157
|
+
}
|
|
158
|
+
interface Frame {
|
|
159
|
+
activation_condition: ActivationCondition;
|
|
160
|
+
experiments: Experiment[];
|
|
161
|
+
elements: CoframeElements;
|
|
162
|
+
}
|
|
163
|
+
interface Experiment {
|
|
164
|
+
metadata: ExperimentMetadata;
|
|
165
|
+
variants: Variant[];
|
|
166
|
+
}
|
|
167
|
+
interface ExperimentMetadata {
|
|
168
|
+
experiment_id: string;
|
|
169
|
+
slug: string;
|
|
170
|
+
iteration_id: string;
|
|
171
|
+
seed: number;
|
|
172
|
+
holdout_info: HoldoutInfo;
|
|
173
|
+
allocation: Allocation;
|
|
174
|
+
activation_condition: {
|
|
175
|
+
audience_ids?: string[];
|
|
176
|
+
};
|
|
177
|
+
lane_ids?: string[];
|
|
178
|
+
}
|
|
179
|
+
interface Allocation {
|
|
180
|
+
[variantId: string]: number[][];
|
|
181
|
+
}
|
|
182
|
+
interface Variant {
|
|
183
|
+
id: string;
|
|
184
|
+
slug: string;
|
|
185
|
+
experiment_id: string;
|
|
186
|
+
modifications: Modifications;
|
|
187
|
+
}
|
|
188
|
+
interface CoframeElements {
|
|
189
|
+
[elementId: string]: SelectorCondition[];
|
|
190
|
+
}
|
|
191
|
+
type SelectorCondition = {
|
|
192
|
+
and?: SelectorCondition[];
|
|
193
|
+
or?: SelectorCondition[];
|
|
194
|
+
name?: string;
|
|
195
|
+
url?: string;
|
|
196
|
+
url_starts_with?: string;
|
|
197
|
+
navigate_to_url_starts_with?: string;
|
|
198
|
+
css?: string;
|
|
199
|
+
universal?: UniversalSelector;
|
|
200
|
+
js?: string;
|
|
201
|
+
};
|
|
202
|
+
type Operator = 'equals' | 'contains' | 'not_contains';
|
|
203
|
+
type SegmentCondition = {
|
|
204
|
+
operator: Operator;
|
|
205
|
+
operand: string;
|
|
206
|
+
key?: string;
|
|
207
|
+
};
|
|
208
|
+
type ActivationConditionAllocation = {
|
|
209
|
+
seed: number;
|
|
210
|
+
allocation_bins: number[][];
|
|
211
|
+
allocation_scale: number;
|
|
212
|
+
};
|
|
213
|
+
type ActivationCondition = {
|
|
214
|
+
and?: ActivationCondition[];
|
|
215
|
+
or?: ActivationCondition[];
|
|
216
|
+
device?: string[];
|
|
217
|
+
platform?: string[];
|
|
218
|
+
language?: string[];
|
|
219
|
+
country?: string[];
|
|
220
|
+
region?: string[];
|
|
221
|
+
city?: string[];
|
|
222
|
+
search?: SegmentCondition[];
|
|
223
|
+
user_context?: SegmentCondition[];
|
|
224
|
+
first_time_vs_returning?: string[];
|
|
225
|
+
url?: string;
|
|
226
|
+
base_url_matches?: string;
|
|
227
|
+
url_regex?: string;
|
|
228
|
+
contains?: string;
|
|
229
|
+
time?: {
|
|
230
|
+
before?: Date;
|
|
231
|
+
after?: Date;
|
|
232
|
+
};
|
|
233
|
+
allocation?: ActivationConditionAllocation;
|
|
234
|
+
js_function?: string;
|
|
235
|
+
};
|
|
236
|
+
type CoframeConfig = {
|
|
237
|
+
projectId: string;
|
|
238
|
+
trackingOnly?: boolean;
|
|
239
|
+
enableAntiFlickering?: boolean;
|
|
240
|
+
waitForHydration?: boolean;
|
|
241
|
+
waitForCookiesEnabled?: boolean;
|
|
242
|
+
waitForFeatureFlag?: boolean;
|
|
243
|
+
waitForUserToken?: boolean;
|
|
244
|
+
batchSize?: number;
|
|
245
|
+
startTime?: number;
|
|
246
|
+
timeoutMs?: number;
|
|
247
|
+
timeoutBehavior?: 'exclude';
|
|
248
|
+
currentUrl?: string;
|
|
249
|
+
userContext?: Record<string, unknown>;
|
|
250
|
+
nonce?: string;
|
|
251
|
+
};
|
|
252
|
+
type BotReason = 'none' | 'cf_bot_score' | 'cf_verified_bot' | 'force_bot_param';
|
|
253
|
+
type PersonalizationHeaders = {
|
|
254
|
+
'x-device-type': string;
|
|
255
|
+
'x-is-mobile-viewer': string;
|
|
256
|
+
'x-viewer-city': string;
|
|
257
|
+
'x-viewer-country': string;
|
|
258
|
+
'x-viewer-region': string;
|
|
259
|
+
'x-is-bot': string;
|
|
260
|
+
'x-is-blocklist-ip': string;
|
|
261
|
+
'x-cf-bot-score': string;
|
|
262
|
+
'x-cf-verified-bot-category': string;
|
|
263
|
+
'x-bot-reason': BotReason;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
interface ProjectData {
|
|
267
|
+
project: Project;
|
|
268
|
+
personalizationHeaders?: Partial<PersonalizationHeaders>;
|
|
269
|
+
}
|
|
270
|
+
type LogPayload = {
|
|
271
|
+
kind: 'warn' | 'error' | 'exception';
|
|
272
|
+
org_id: string;
|
|
273
|
+
project_id: string;
|
|
274
|
+
event_id: string;
|
|
275
|
+
variant_id: string;
|
|
276
|
+
experiment_id: string;
|
|
277
|
+
session_id: string;
|
|
278
|
+
url: string;
|
|
279
|
+
monitoring_type: string;
|
|
280
|
+
local_time: string;
|
|
281
|
+
metadata: Record<string, unknown>;
|
|
282
|
+
variant_ids?: string[];
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
interface CoframeProviderProps {
|
|
286
|
+
projectConfig: CoframeConfig;
|
|
287
|
+
projectData?: ProjectData | null;
|
|
288
|
+
onTreatmentApplied?: (data: TreatmentData) => void;
|
|
289
|
+
onTreatmentAppliedBulk?: (data: TreatmentData[]) => void;
|
|
290
|
+
onTreatmentAppliedBulkV2?: (data: TreatmentDataV2[], rawIds: ExperimentInfo[]) => void;
|
|
291
|
+
onLog?: (payload: LogPayload) => void;
|
|
292
|
+
children: ReactNode;
|
|
293
|
+
}
|
|
294
|
+
interface CoframeContextValue {
|
|
295
|
+
treatments: TreatmentData[] | null;
|
|
296
|
+
}
|
|
297
|
+
declare function CoframeProvider({ projectConfig, projectData, onTreatmentApplied: onTreatmentAppliedProp, onTreatmentAppliedBulk: onTreatmentAppliedBulkProp, onTreatmentAppliedBulkV2, onLog: onLogProp, children, }: CoframeProviderProps): React.FunctionComponentElement<React.ProviderProps<CoframeContextValue>>;
|
|
298
|
+
declare function useCoframeTreatments(): TreatmentData[] | null;
|
|
299
|
+
declare function useCoframeTreatment(experimentId: string): TreatmentData | undefined;
|
|
300
|
+
declare function useCoframeVariant(experimentId: string): string | undefined;
|
|
301
|
+
|
|
302
|
+
export { CoframeProvider, useCoframeTreatment, useCoframeTreatments, useCoframeVariant };
|
|
303
|
+
export type { CoframeProviderProps };
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
interface UniversalSelector {
|
|
2
|
+
t: string;
|
|
3
|
+
fingerprint?: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
dataTestId?: string;
|
|
6
|
+
n?: {
|
|
7
|
+
i: number;
|
|
8
|
+
t: number;
|
|
9
|
+
};
|
|
10
|
+
text?: string;
|
|
11
|
+
href?: string;
|
|
12
|
+
ariaLabel?: string;
|
|
13
|
+
p?: UniversalSelector;
|
|
14
|
+
descendants?: {
|
|
15
|
+
depth: number;
|
|
16
|
+
sel: UniversalSelector;
|
|
17
|
+
}[];
|
|
18
|
+
isShadowRoot?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type ElementStyles = Record<string, string | undefined>;
|
|
22
|
+
type ElementAttributes = {
|
|
23
|
+
src?: string;
|
|
24
|
+
innerHTML?: string;
|
|
25
|
+
styles?: ElementStyles;
|
|
26
|
+
onClick?: string;
|
|
27
|
+
textContent?: string;
|
|
28
|
+
role?: string;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
};
|
|
31
|
+
type ProjectTag = {
|
|
32
|
+
js: string | null;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type Modification = ModificationUpdate | ModificationInsertInto | ModificationInsertBy | ModificationDelete | ModificationAddBanner | ModificationAddModal | ModificationExecuteJs;
|
|
36
|
+
type Modifications = {
|
|
37
|
+
[elementId: string]: Array<Modification>;
|
|
38
|
+
};
|
|
39
|
+
type NewElementAttributes = ElementAttributes & {
|
|
40
|
+
tagName?: 'h1' | 'p' | 'div' | 'span' | 'button' | 'input' | 'img' | 'div';
|
|
41
|
+
};
|
|
42
|
+
type ModificationUpdate = {
|
|
43
|
+
type: 'update';
|
|
44
|
+
attributes: ElementAttributes;
|
|
45
|
+
};
|
|
46
|
+
type ModificationInsertInto = {
|
|
47
|
+
type: 'insert_into';
|
|
48
|
+
child_position: 'first' | 'last';
|
|
49
|
+
new_element: NewElementAttributes;
|
|
50
|
+
};
|
|
51
|
+
type ModificationInsertBy = {
|
|
52
|
+
type: 'insert_by';
|
|
53
|
+
position: 'before' | 'after';
|
|
54
|
+
new_element: NewElementAttributes;
|
|
55
|
+
};
|
|
56
|
+
type ModificationDelete = {
|
|
57
|
+
type: 'delete';
|
|
58
|
+
};
|
|
59
|
+
type ModificationAddModal = {
|
|
60
|
+
type: 'add_modal';
|
|
61
|
+
modal_content: NewElementAttributes;
|
|
62
|
+
trigger: ModalTrigger;
|
|
63
|
+
};
|
|
64
|
+
type ModificationAddBanner = {
|
|
65
|
+
type: 'add_banner';
|
|
66
|
+
banner_content: NewElementAttributes;
|
|
67
|
+
};
|
|
68
|
+
type ModificationExecuteJs = {
|
|
69
|
+
type: 'execute_js';
|
|
70
|
+
js: string;
|
|
71
|
+
};
|
|
72
|
+
type ModalTrigger = 'exit' | 'scroll' | 'enter' | 'timer';
|
|
73
|
+
|
|
74
|
+
interface AnalyticsCallback {
|
|
75
|
+
callback: string;
|
|
76
|
+
}
|
|
77
|
+
interface Audience {
|
|
78
|
+
selector: ActivationCondition;
|
|
79
|
+
}
|
|
80
|
+
interface LaneMember {
|
|
81
|
+
experiment_id: string;
|
|
82
|
+
iteration_id: string;
|
|
83
|
+
}
|
|
84
|
+
interface LaneStatus {
|
|
85
|
+
seed: number;
|
|
86
|
+
members: LaneMember[];
|
|
87
|
+
}
|
|
88
|
+
interface HoldoutInfo {
|
|
89
|
+
holdout_experiment_id: string;
|
|
90
|
+
holdout_experiment_slug: string;
|
|
91
|
+
holdout_variant_id: string;
|
|
92
|
+
holdout_variant_slug: string;
|
|
93
|
+
treatment_variant_id: string;
|
|
94
|
+
treatment_variant_slug: string;
|
|
95
|
+
seed: number;
|
|
96
|
+
variant_bins: Allocation;
|
|
97
|
+
}
|
|
98
|
+
interface Metric {
|
|
99
|
+
id: string;
|
|
100
|
+
selector: SelectorCondition;
|
|
101
|
+
js_binder?: string;
|
|
102
|
+
}
|
|
103
|
+
interface ProjectSettings {
|
|
104
|
+
mutation_observer_active: boolean;
|
|
105
|
+
track_only_activated_frames?: boolean;
|
|
106
|
+
blocklist_ips?: string[];
|
|
107
|
+
bot_cloaking_enabled?: boolean;
|
|
108
|
+
bot_score_threshold?: number;
|
|
109
|
+
analytics_callback?: AnalyticsCallback;
|
|
110
|
+
}
|
|
111
|
+
interface Project {
|
|
112
|
+
org_id: string;
|
|
113
|
+
holdout_info: HoldoutInfo;
|
|
114
|
+
audiences: Record<string, Audience>;
|
|
115
|
+
frames: Frame[];
|
|
116
|
+
metrics?: Metric[];
|
|
117
|
+
settings: ProjectSettings;
|
|
118
|
+
tags?: ProjectTag[];
|
|
119
|
+
lanes?: Record<string, LaneStatus>;
|
|
120
|
+
}
|
|
121
|
+
interface Frame {
|
|
122
|
+
activation_condition: ActivationCondition;
|
|
123
|
+
experiments: Experiment[];
|
|
124
|
+
elements: CoframeElements;
|
|
125
|
+
}
|
|
126
|
+
interface Experiment {
|
|
127
|
+
metadata: ExperimentMetadata;
|
|
128
|
+
variants: Variant[];
|
|
129
|
+
}
|
|
130
|
+
interface ExperimentMetadata {
|
|
131
|
+
experiment_id: string;
|
|
132
|
+
slug: string;
|
|
133
|
+
iteration_id: string;
|
|
134
|
+
seed: number;
|
|
135
|
+
holdout_info: HoldoutInfo;
|
|
136
|
+
allocation: Allocation;
|
|
137
|
+
activation_condition: {
|
|
138
|
+
audience_ids?: string[];
|
|
139
|
+
};
|
|
140
|
+
lane_ids?: string[];
|
|
141
|
+
}
|
|
142
|
+
interface Allocation {
|
|
143
|
+
[variantId: string]: number[][];
|
|
144
|
+
}
|
|
145
|
+
interface Variant {
|
|
146
|
+
id: string;
|
|
147
|
+
slug: string;
|
|
148
|
+
experiment_id: string;
|
|
149
|
+
modifications: Modifications;
|
|
150
|
+
}
|
|
151
|
+
interface CoframeElements {
|
|
152
|
+
[elementId: string]: SelectorCondition[];
|
|
153
|
+
}
|
|
154
|
+
type SelectorCondition = {
|
|
155
|
+
and?: SelectorCondition[];
|
|
156
|
+
or?: SelectorCondition[];
|
|
157
|
+
name?: string;
|
|
158
|
+
url?: string;
|
|
159
|
+
url_starts_with?: string;
|
|
160
|
+
navigate_to_url_starts_with?: string;
|
|
161
|
+
css?: string;
|
|
162
|
+
universal?: UniversalSelector;
|
|
163
|
+
js?: string;
|
|
164
|
+
};
|
|
165
|
+
type Operator = 'equals' | 'contains' | 'not_contains';
|
|
166
|
+
type SegmentCondition = {
|
|
167
|
+
operator: Operator;
|
|
168
|
+
operand: string;
|
|
169
|
+
key?: string;
|
|
170
|
+
};
|
|
171
|
+
type ActivationConditionAllocation = {
|
|
172
|
+
seed: number;
|
|
173
|
+
allocation_bins: number[][];
|
|
174
|
+
allocation_scale: number;
|
|
175
|
+
};
|
|
176
|
+
type ActivationCondition = {
|
|
177
|
+
and?: ActivationCondition[];
|
|
178
|
+
or?: ActivationCondition[];
|
|
179
|
+
device?: string[];
|
|
180
|
+
platform?: string[];
|
|
181
|
+
language?: string[];
|
|
182
|
+
country?: string[];
|
|
183
|
+
region?: string[];
|
|
184
|
+
city?: string[];
|
|
185
|
+
search?: SegmentCondition[];
|
|
186
|
+
user_context?: SegmentCondition[];
|
|
187
|
+
first_time_vs_returning?: string[];
|
|
188
|
+
url?: string;
|
|
189
|
+
base_url_matches?: string;
|
|
190
|
+
url_regex?: string;
|
|
191
|
+
contains?: string;
|
|
192
|
+
time?: {
|
|
193
|
+
before?: Date;
|
|
194
|
+
after?: Date;
|
|
195
|
+
};
|
|
196
|
+
allocation?: ActivationConditionAllocation;
|
|
197
|
+
js_function?: string;
|
|
198
|
+
};
|
|
199
|
+
type BotReason = 'none' | 'cf_bot_score' | 'cf_verified_bot' | 'force_bot_param';
|
|
200
|
+
type PersonalizationHeaders = {
|
|
201
|
+
'x-device-type': string;
|
|
202
|
+
'x-is-mobile-viewer': string;
|
|
203
|
+
'x-viewer-city': string;
|
|
204
|
+
'x-viewer-country': string;
|
|
205
|
+
'x-viewer-region': string;
|
|
206
|
+
'x-is-bot': string;
|
|
207
|
+
'x-is-blocklist-ip': string;
|
|
208
|
+
'x-cf-bot-score': string;
|
|
209
|
+
'x-cf-verified-bot-category': string;
|
|
210
|
+
'x-bot-reason': BotReason;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
interface GetProjectDataOptions {
|
|
214
|
+
projectId: string;
|
|
215
|
+
currentUrl: string;
|
|
216
|
+
userContext?: Record<string, unknown>;
|
|
217
|
+
headers: Headers | Record<string, string>;
|
|
218
|
+
includeProject?: boolean;
|
|
219
|
+
includeCSS?: boolean;
|
|
220
|
+
}
|
|
221
|
+
interface CoframeProjectPayload {
|
|
222
|
+
project?: Project;
|
|
223
|
+
personalizationHeaders?: PersonalizationHeaders;
|
|
224
|
+
antiflickerCSS?: string;
|
|
225
|
+
}
|
|
226
|
+
declare function getProjectData(options: GetProjectDataOptions): Promise<CoframeProjectPayload | null>;
|
|
227
|
+
|
|
228
|
+
export { getProjectData };
|
|
229
|
+
export type { CoframeProjectPayload, GetProjectDataOptions };
|
package/package.json
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coframe/sdk",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Coframe optimizes your website using generative AI to deliver maximum impact to your audience and allow your site to improve itself as you sleep. Learn more at coframe.com.",
|
|
5
|
+
"main": "dist/pkg/cf.cjs.js",
|
|
6
|
+
"module": "dist/pkg/cf.esm.mjs",
|
|
7
|
+
"types": "dist/pkg/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/pkg/cf.esm.mjs",
|
|
11
|
+
"require": "./dist/pkg/cf.cjs.js",
|
|
12
|
+
"types": "./dist/pkg/types/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./server": {
|
|
15
|
+
"import": "./dist/pkg/server.esm.mjs",
|
|
16
|
+
"require": "./dist/pkg/server.cjs.js",
|
|
17
|
+
"types": "./dist/pkg/types/server.d.ts"
|
|
18
|
+
},
|
|
19
|
+
"./react": {
|
|
20
|
+
"import": "./dist/pkg/react.esm.mjs",
|
|
21
|
+
"require": "./dist/pkg/react.cjs.js",
|
|
22
|
+
"types": "./dist/pkg/types/react.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/pkg"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test:jest": "jest --maxWorkers=2",
|
|
30
|
+
"test:playwright": "npx playwright test --retries=5 --reporter=list",
|
|
31
|
+
"test:browserstack:full": "jest --config jest.browserstack.config.js --suite=full",
|
|
32
|
+
"test:browserstack:small": "jest --config jest.browserstack.config.js --suite=small",
|
|
33
|
+
"test": "npm run test:jest && npm run test:playwright",
|
|
34
|
+
"build:stage": "SDK_ENV=stage npm run build",
|
|
35
|
+
"build:prod": "SDK_ENV=prod npm run build",
|
|
36
|
+
"build": "NODE_ENV=production rollup -c",
|
|
37
|
+
"prod": "npm run format:fix && npm run build",
|
|
38
|
+
"watch": "NODE_ENV=production rollup -c -w",
|
|
39
|
+
"lint": "biome ci",
|
|
40
|
+
"lint:fix": "biome check --write .",
|
|
41
|
+
"lint:fix!": "biome check --write --unsafe .",
|
|
42
|
+
"deploy:cdn": "./bin/publish.sh",
|
|
43
|
+
"deploy:cdn:prod": "SDK_ENV=prod ./bin/publish.sh",
|
|
44
|
+
"dev": "NODE_ENV=production EXTERNAL_PORT=3004 rollup -c -w"
|
|
45
|
+
},
|
|
46
|
+
"author": "Coframe",
|
|
47
|
+
"keywords": [
|
|
48
|
+
"coframe",
|
|
49
|
+
"optimization",
|
|
50
|
+
"AI",
|
|
51
|
+
"artificial intelligence",
|
|
52
|
+
"generative AI",
|
|
53
|
+
"website optimization",
|
|
54
|
+
"conversion rate",
|
|
55
|
+
"A/B testing",
|
|
56
|
+
"personalization",
|
|
57
|
+
"content optimization",
|
|
58
|
+
"copy optimization"
|
|
59
|
+
],
|
|
60
|
+
"repository": {
|
|
61
|
+
"type": "git",
|
|
62
|
+
"url": "git+https://github.com/Coframe/coframe-js.git"
|
|
63
|
+
},
|
|
64
|
+
"bugs": {
|
|
65
|
+
"url": "https://github.com/Coframe/coframe-js/issues"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://coframe.com",
|
|
68
|
+
"resolutions": {
|
|
69
|
+
"**/test-exclude": "^8.0.0",
|
|
70
|
+
"**/minimatch": "^10.0.0",
|
|
71
|
+
"**/glob": "^11.0.0",
|
|
72
|
+
"**/anymatch/picomatch": "2.3.2",
|
|
73
|
+
"**/micromatch/picomatch": "2.3.2",
|
|
74
|
+
"**/@rollup/plugin-commonjs/picomatch": "4.0.4",
|
|
75
|
+
"**/jest-config/picomatch": "4.0.4",
|
|
76
|
+
"**/jest-haste-map/picomatch": "4.0.4",
|
|
77
|
+
"**/jest-runner/picomatch": "4.0.4",
|
|
78
|
+
"**/jest-runtime/picomatch": "4.0.4",
|
|
79
|
+
"**/jest-util/picomatch": "4.0.4",
|
|
80
|
+
"js-yaml": "3.14.2",
|
|
81
|
+
"**/brace-expansion": "^5.0.6",
|
|
82
|
+
"**/@babel/plugin-transform-modules-systemjs": "^7.29.4"
|
|
83
|
+
},
|
|
84
|
+
"peerDependencies": {
|
|
85
|
+
"react": ">=17.0.0"
|
|
86
|
+
},
|
|
87
|
+
"peerDependenciesMeta": {
|
|
88
|
+
"react": {
|
|
89
|
+
"optional": true
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"typescript": "^6.0.2"
|
|
94
|
+
},
|
|
95
|
+
"devDependencies": {
|
|
96
|
+
"@babel/core": "^7.29.0",
|
|
97
|
+
"@babel/preset-env": "^7.29.2",
|
|
98
|
+
"@biomejs/biome": "^2.4.8",
|
|
99
|
+
"@playwright/test": "1.58.2",
|
|
100
|
+
"@rollup/plugin-babel": "^7.0.0",
|
|
101
|
+
"@rollup/plugin-commonjs": "^29.0.2",
|
|
102
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
103
|
+
"@rollup/plugin-replace": "^6.0.3",
|
|
104
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
105
|
+
"@types/jest": "^30.0.0",
|
|
106
|
+
"@types/react": "^18.0.0",
|
|
107
|
+
"@types/selenium-webdriver": "^4.35.5",
|
|
108
|
+
"dotenv": "^17.3.1",
|
|
109
|
+
"jest": "^30.3.0",
|
|
110
|
+
"jest-environment-jsdom": "^30.3.0",
|
|
111
|
+
"jest-environment-jsdom-global": "^4.0.0",
|
|
112
|
+
"jest-expect-message": "^1.1.3",
|
|
113
|
+
"jest-localstorage-mock": "^2.4.26",
|
|
114
|
+
"jest-raw-loader": "^1.0.1",
|
|
115
|
+
"path-exists-cli": "^2.0.0",
|
|
116
|
+
"playwright": "1.58.2",
|
|
117
|
+
"prettier": "^3.8.1",
|
|
118
|
+
"rollup": "^4.60.0",
|
|
119
|
+
"rollup-plugin-dts": "^6.4.1",
|
|
120
|
+
"rollup-plugin-json": "^4.0.0",
|
|
121
|
+
"rollup-plugin-serve": "^2.0.0",
|
|
122
|
+
"rollup-plugin-string": "^3.0.0",
|
|
123
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
124
|
+
"selenium-webdriver": "^4.41.0",
|
|
125
|
+
"terser": "^5.46.1",
|
|
126
|
+
"ts-jest": "^29.4.6",
|
|
127
|
+
"tslib": "^2.8.1",
|
|
128
|
+
"ua-parser-js": "^2.0.9"
|
|
129
|
+
}
|
|
130
|
+
}
|