@coframe/sdk 1.1.9 → 1.1.11
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/README.md +25 -0
- package/dist/pkg/cf.cjs.js +209 -272
- package/dist/pkg/cf.esm.mjs +209 -272
- package/dist/pkg/react.cjs.js +9 -1
- package/dist/pkg/react.esm.mjs +10 -2
- package/dist/pkg/server.cjs.js +11 -4
- package/dist/pkg/server.esm.mjs +11 -4
- package/dist/pkg/types/index.d.ts +4 -1
- package/dist/pkg/types/react.d.ts +5 -2
- package/dist/pkg/types/server.d.ts +2 -1
- package/package.json +4 -3
package/dist/pkg/server.esm.mjs
CHANGED
|
@@ -43,14 +43,14 @@ async function fetchProjectFromEdge(projectId, currentUrl, signal, userContext,
|
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
async function fetchAntiflickerFromEdge(projectId, currentUrl, userContext,
|
|
46
|
+
async function fetchAntiflickerFromEdge(projectId, currentUrl, userContext, antiflickerMode, headers) {
|
|
47
47
|
try {
|
|
48
48
|
const payload = { projectId, currentUrl };
|
|
49
49
|
if (userContext) {
|
|
50
50
|
payload.userContext = userContext;
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
53
|
-
payload.
|
|
52
|
+
if (antiflickerMode) {
|
|
53
|
+
payload.antiflickerMode = antiflickerMode;
|
|
54
54
|
}
|
|
55
55
|
const config = encodeURIComponent(JSON.stringify(payload));
|
|
56
56
|
const edgeUrl = new URL(`${"https://edge.cofra.me"}/cf.css`);
|
|
@@ -67,6 +67,13 @@ async function fetchAntiflickerFromEdge(projectId, currentUrl, userContext, enab
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
async function getProjectData(options) {
|
|
70
|
+
try {
|
|
71
|
+
if (/cf_disable/.test(new URL(options.currentUrl).search)) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (_a) {
|
|
76
|
+
}
|
|
70
77
|
const includeProject = options.includeProject !== false;
|
|
71
78
|
const includeCSS = options.includeCSS !== false;
|
|
72
79
|
const [projectResult, antiflickerCSS] = await Promise.all([
|
|
@@ -74,7 +81,7 @@ async function getProjectData(options) {
|
|
|
74
81
|
? fetchProjectFromEdge(options.projectId, options.currentUrl, undefined, options.userContext, undefined, options.headers)
|
|
75
82
|
: Promise.resolve(null),
|
|
76
83
|
includeCSS
|
|
77
|
-
? fetchAntiflickerFromEdge(options.projectId, options.currentUrl, options.userContext, options.
|
|
84
|
+
? fetchAntiflickerFromEdge(options.projectId, options.currentUrl, options.userContext, options.antiflickerMode, options.headers)
|
|
78
85
|
: Promise.resolve(null),
|
|
79
86
|
]);
|
|
80
87
|
const config = {};
|
|
@@ -230,12 +230,13 @@ type ActivationCondition = {
|
|
|
230
230
|
allocation?: ActivationConditionAllocation;
|
|
231
231
|
js_function?: string;
|
|
232
232
|
};
|
|
233
|
+
type AntiflickerMode = 'body' | 'include' | 'exclude';
|
|
233
234
|
type CoframeConfig = {
|
|
234
235
|
projectId: string;
|
|
235
236
|
previewVariantId?: string;
|
|
236
237
|
trackingOnly?: boolean;
|
|
237
238
|
enableAntiFlickering?: boolean;
|
|
238
|
-
|
|
239
|
+
antiflickerMode?: AntiflickerMode;
|
|
239
240
|
waitForHydration?: boolean;
|
|
240
241
|
waitForCookiesEnabled?: boolean;
|
|
241
242
|
waitForFeatureFlag?: boolean;
|
|
@@ -247,6 +248,7 @@ type CoframeConfig = {
|
|
|
247
248
|
currentUrl?: string;
|
|
248
249
|
userContext?: Record<string, unknown>;
|
|
249
250
|
nonce?: string;
|
|
251
|
+
enableDebug?: boolean;
|
|
250
252
|
};
|
|
251
253
|
type ConversionEventPayload = {
|
|
252
254
|
metricId?: string;
|
|
@@ -295,6 +297,7 @@ interface TreatmentAppliedHandlers {
|
|
|
295
297
|
callback?: (data: TreatmentData) => void;
|
|
296
298
|
bulkCallback?: (data: TreatmentData[]) => void;
|
|
297
299
|
bulkCallbackV2?: (data: TreatmentDataV2[], rawIds: ExperimentInfo[]) => void;
|
|
300
|
+
bulkCallbackV2WithoutConsent?: (data: TreatmentDataV2[], rawIds: ExperimentInfo[]) => void;
|
|
298
301
|
}
|
|
299
302
|
declare function setConsent(enabled: boolean): void;
|
|
300
303
|
declare function setUserToken(token: string): void;
|
|
@@ -233,12 +233,13 @@ type ActivationCondition = {
|
|
|
233
233
|
allocation?: ActivationConditionAllocation;
|
|
234
234
|
js_function?: string;
|
|
235
235
|
};
|
|
236
|
+
type AntiflickerMode = 'body' | 'include' | 'exclude';
|
|
236
237
|
type CoframeConfig = {
|
|
237
238
|
projectId: string;
|
|
238
239
|
previewVariantId?: string;
|
|
239
240
|
trackingOnly?: boolean;
|
|
240
241
|
enableAntiFlickering?: boolean;
|
|
241
|
-
|
|
242
|
+
antiflickerMode?: AntiflickerMode;
|
|
242
243
|
waitForHydration?: boolean;
|
|
243
244
|
waitForCookiesEnabled?: boolean;
|
|
244
245
|
waitForFeatureFlag?: boolean;
|
|
@@ -250,6 +251,7 @@ type CoframeConfig = {
|
|
|
250
251
|
currentUrl?: string;
|
|
251
252
|
userContext?: Record<string, unknown>;
|
|
252
253
|
nonce?: string;
|
|
254
|
+
enableDebug?: boolean;
|
|
253
255
|
};
|
|
254
256
|
type BotReason = 'none' | 'cf_bot_score' | 'cf_verified_bot' | 'force_bot_param';
|
|
255
257
|
type PersonalizationHeaders = {
|
|
@@ -290,13 +292,14 @@ interface CoframeProviderProps {
|
|
|
290
292
|
onTreatmentApplied?: (data: TreatmentData) => void;
|
|
291
293
|
onTreatmentAppliedBulk?: (data: TreatmentData[]) => void;
|
|
292
294
|
onTreatmentAppliedBulkV2?: (data: TreatmentDataV2[], rawIds: ExperimentInfo[]) => void;
|
|
295
|
+
onTreatmentAppliedBulkV2WithoutConsent?: (data: TreatmentDataV2[], rawIds: ExperimentInfo[]) => void;
|
|
293
296
|
onLog?: (payload: LogPayload) => void;
|
|
294
297
|
children: ReactNode;
|
|
295
298
|
}
|
|
296
299
|
interface CoframeContextValue {
|
|
297
300
|
treatments: TreatmentData[] | null;
|
|
298
301
|
}
|
|
299
|
-
declare function CoframeProvider({ projectConfig, projectData, onTreatmentApplied: onTreatmentAppliedProp, onTreatmentAppliedBulk: onTreatmentAppliedBulkProp, onTreatmentAppliedBulkV2, onLog: onLogProp, children, }: CoframeProviderProps): React.FunctionComponentElement<React.ProviderProps<CoframeContextValue>>;
|
|
302
|
+
declare function CoframeProvider({ projectConfig, projectData, onTreatmentApplied: onTreatmentAppliedProp, onTreatmentAppliedBulk: onTreatmentAppliedBulkProp, onTreatmentAppliedBulkV2, onTreatmentAppliedBulkV2WithoutConsent, onLog: onLogProp, children, }: CoframeProviderProps): React.FunctionComponentElement<React.ProviderProps<CoframeContextValue>>;
|
|
300
303
|
declare function useCoframeTreatments(): TreatmentData[] | null;
|
|
301
304
|
declare function useCoframeTreatment(experimentId: string): TreatmentData | undefined;
|
|
302
305
|
declare function useCoframeVariant(experimentId: string): string | undefined;
|
|
@@ -196,6 +196,7 @@ type ActivationCondition = {
|
|
|
196
196
|
allocation?: ActivationConditionAllocation;
|
|
197
197
|
js_function?: string;
|
|
198
198
|
};
|
|
199
|
+
type AntiflickerMode = 'body' | 'include' | 'exclude';
|
|
199
200
|
type BotReason = 'none' | 'cf_bot_score' | 'cf_verified_bot' | 'force_bot_param';
|
|
200
201
|
type PersonalizationHeaders = {
|
|
201
202
|
'x-device-type': string;
|
|
@@ -215,7 +216,7 @@ interface GetProjectDataOptions {
|
|
|
215
216
|
currentUrl: string;
|
|
216
217
|
userContext?: Record<string, unknown>;
|
|
217
218
|
headers: Headers | Record<string, string>;
|
|
218
|
-
|
|
219
|
+
antiflickerMode?: AntiflickerMode;
|
|
219
220
|
includeProject?: boolean;
|
|
220
221
|
includeCSS?: boolean;
|
|
221
222
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coframe/sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
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
5
|
"main": "dist/pkg/cf.cjs.js",
|
|
6
6
|
"module": "dist/pkg/cf.esm.mjs",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"lint:fix!": "biome check --write --unsafe .",
|
|
43
43
|
"deploy:cdn": "./bin/publish.sh",
|
|
44
44
|
"deploy:cdn:prod": "SDK_ENV=prod ./bin/publish.sh",
|
|
45
|
-
"dev": "NODE_ENV=production EXTERNAL_PORT=3004 rollup -c -w"
|
|
45
|
+
"dev": "NODE_ENV=production EXTERNAL_PORT=3004 rollup -c -w",
|
|
46
|
+
"dev:local-edge": "COFRAME_EDGE_URL=http://localhost:8787 NODE_ENV=production EXTERNAL_PORT=3004 rollup -c -w"
|
|
46
47
|
},
|
|
47
48
|
"author": "Coframe",
|
|
48
49
|
"keywords": [
|
|
@@ -130,4 +131,4 @@
|
|
|
130
131
|
"ua-parser-js": "^2.0.10"
|
|
131
132
|
},
|
|
132
133
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
133
|
-
}
|
|
134
|
+
}
|