@coframe/sdk 1.1.14 → 1.1.21

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.
@@ -22,8 +22,11 @@ function sanitizeUserContext(userContext) {
22
22
  return userContext;
23
23
  }
24
24
 
25
- async function fetchProjectFromEdge(projectId, currentUrl, signal, userContext, previewVariantId, headers) {
25
+ async function fetchProjectFromEdge(projectId, currentUrl, signal, userContext, previewVariantId, headers, referrer) {
26
26
  const payload = { projectId, currentUrl };
27
+ if (referrer !== undefined) {
28
+ payload.referrer = referrer;
29
+ }
27
30
  const safe = sanitizeUserContext(userContext);
28
31
  if (safe) {
29
32
  payload.userContext = safe;
@@ -45,9 +48,25 @@ async function fetchProjectFromEdge(projectId, currentUrl, signal, userContext,
45
48
  }
46
49
  }
47
50
 
48
- async function fetchAntiflickerFromEdge(projectId, currentUrl, userContext, antiflickerMode, headers) {
51
+ function getRequestReferrer(headers) {
52
+ const get = headers.get;
53
+ if (typeof get === 'function') {
54
+ const value = get.call(headers, 'referer');
55
+ return typeof value === 'string' ? value : undefined;
56
+ }
57
+ for (const [key, value] of Object.entries(headers)) {
58
+ if (key.toLowerCase() === 'referer') {
59
+ return typeof value === 'string' ? value : undefined;
60
+ }
61
+ }
62
+ return undefined;
63
+ }
64
+ async function fetchAntiflickerFromEdge(projectId, currentUrl, referrer, userContext, antiflickerMode, headers) {
49
65
  try {
50
66
  const payload = { projectId, currentUrl };
67
+ if (referrer !== undefined) {
68
+ payload.referrer = referrer;
69
+ }
51
70
  if (userContext) {
52
71
  payload.userContext = userContext;
53
72
  }
@@ -69,21 +88,23 @@ async function fetchAntiflickerFromEdge(projectId, currentUrl, userContext, anti
69
88
  }
70
89
  }
71
90
  async function getProjectData(options) {
91
+ var _a;
72
92
  try {
73
93
  if (/cf_disable/.test(new URL(options.currentUrl).search)) {
74
94
  return null;
75
95
  }
76
96
  }
77
- catch (_a) {
97
+ catch (_b) {
78
98
  }
79
99
  const includeProject = options.includeProject !== false;
80
100
  const includeCSS = options.includeCSS !== false;
101
+ const referrer = (_a = options.referrer) !== null && _a !== void 0 ? _a : getRequestReferrer(options.headers);
81
102
  const [projectResult, antiflickerCSS] = await Promise.all([
82
103
  includeProject
83
- ? fetchProjectFromEdge(options.projectId, options.currentUrl, undefined, options.userContext, undefined, options.headers)
104
+ ? fetchProjectFromEdge(options.projectId, options.currentUrl, undefined, options.userContext, undefined, options.headers, referrer)
84
105
  : Promise.resolve(null),
85
106
  includeCSS
86
- ? fetchAntiflickerFromEdge(options.projectId, options.currentUrl, options.userContext, options.antiflickerMode, options.headers)
107
+ ? fetchAntiflickerFromEdge(options.projectId, options.currentUrl, referrer, options.userContext, options.antiflickerMode, options.headers)
87
108
  : Promise.resolve(null),
88
109
  ]);
89
110
  const config = {};
@@ -20,8 +20,11 @@ function sanitizeUserContext(userContext) {
20
20
  return userContext;
21
21
  }
22
22
 
23
- async function fetchProjectFromEdge(projectId, currentUrl, signal, userContext, previewVariantId, headers) {
23
+ async function fetchProjectFromEdge(projectId, currentUrl, signal, userContext, previewVariantId, headers, referrer) {
24
24
  const payload = { projectId, currentUrl };
25
+ if (referrer !== undefined) {
26
+ payload.referrer = referrer;
27
+ }
25
28
  const safe = sanitizeUserContext(userContext);
26
29
  if (safe) {
27
30
  payload.userContext = safe;
@@ -43,9 +46,25 @@ async function fetchProjectFromEdge(projectId, currentUrl, signal, userContext,
43
46
  }
44
47
  }
45
48
 
46
- async function fetchAntiflickerFromEdge(projectId, currentUrl, userContext, antiflickerMode, headers) {
49
+ function getRequestReferrer(headers) {
50
+ const get = headers.get;
51
+ if (typeof get === 'function') {
52
+ const value = get.call(headers, 'referer');
53
+ return typeof value === 'string' ? value : undefined;
54
+ }
55
+ for (const [key, value] of Object.entries(headers)) {
56
+ if (key.toLowerCase() === 'referer') {
57
+ return typeof value === 'string' ? value : undefined;
58
+ }
59
+ }
60
+ return undefined;
61
+ }
62
+ async function fetchAntiflickerFromEdge(projectId, currentUrl, referrer, userContext, antiflickerMode, headers) {
47
63
  try {
48
64
  const payload = { projectId, currentUrl };
65
+ if (referrer !== undefined) {
66
+ payload.referrer = referrer;
67
+ }
49
68
  if (userContext) {
50
69
  payload.userContext = userContext;
51
70
  }
@@ -67,21 +86,23 @@ async function fetchAntiflickerFromEdge(projectId, currentUrl, userContext, anti
67
86
  }
68
87
  }
69
88
  async function getProjectData(options) {
89
+ var _a;
70
90
  try {
71
91
  if (/cf_disable/.test(new URL(options.currentUrl).search)) {
72
92
  return null;
73
93
  }
74
94
  }
75
- catch (_a) {
95
+ catch (_b) {
76
96
  }
77
97
  const includeProject = options.includeProject !== false;
78
98
  const includeCSS = options.includeCSS !== false;
99
+ const referrer = (_a = options.referrer) !== null && _a !== void 0 ? _a : getRequestReferrer(options.headers);
79
100
  const [projectResult, antiflickerCSS] = await Promise.all([
80
101
  includeProject
81
- ? fetchProjectFromEdge(options.projectId, options.currentUrl, undefined, options.userContext, undefined, options.headers)
102
+ ? fetchProjectFromEdge(options.projectId, options.currentUrl, undefined, options.userContext, undefined, options.headers, referrer)
82
103
  : Promise.resolve(null),
83
104
  includeCSS
84
- ? fetchAntiflickerFromEdge(options.projectId, options.currentUrl, options.userContext, options.antiflickerMode, options.headers)
105
+ ? fetchAntiflickerFromEdge(options.projectId, options.currentUrl, referrer, options.userContext, options.antiflickerMode, options.headers)
85
106
  : Promise.resolve(null),
86
107
  ]);
87
108
  const config = {};
@@ -172,7 +172,9 @@ interface ExperimentMetadata {
172
172
  audience_ids?: string[];
173
173
  };
174
174
  lane_ids?: string[];
175
+ serving_mode?: ServingMode;
175
176
  }
177
+ type ServingMode = 'off' | 'split' | 'winner';
176
178
  interface Allocation {
177
179
  [variantId: string]: number[][];
178
180
  }
@@ -246,6 +248,9 @@ type CoframeConfig = {
246
248
  timeoutMs?: number;
247
249
  timeoutBehavior?: 'exclude';
248
250
  currentUrl?: string;
251
+ projectUrl?: string;
252
+ ingestUrl?: string;
253
+ referrer?: string;
249
254
  userContext?: Record<string, unknown>;
250
255
  nonce?: string;
251
256
  enableDebug?: boolean;
@@ -258,6 +263,8 @@ type ConversionEventPayload = {
258
263
  };
259
264
  type BotReason = 'none' | 'cf_bot_score' | 'cf_verified_bot' | 'force_bot_param';
260
265
  type PersonalizationHeaders = {
266
+ 'x-visit-url'?: string;
267
+ 'x-visit-referrer'?: string;
261
268
  'x-device-type': string;
262
269
  'x-is-mobile-viewer': string;
263
270
  'x-viewer-city': string;
@@ -175,7 +175,9 @@ interface ExperimentMetadata {
175
175
  audience_ids?: string[];
176
176
  };
177
177
  lane_ids?: string[];
178
+ serving_mode?: ServingMode;
178
179
  }
180
+ type ServingMode = 'off' | 'split' | 'winner';
179
181
  interface Allocation {
180
182
  [variantId: string]: number[][];
181
183
  }
@@ -249,12 +251,17 @@ type CoframeConfig = {
249
251
  timeoutMs?: number;
250
252
  timeoutBehavior?: 'exclude';
251
253
  currentUrl?: string;
254
+ projectUrl?: string;
255
+ ingestUrl?: string;
256
+ referrer?: string;
252
257
  userContext?: Record<string, unknown>;
253
258
  nonce?: string;
254
259
  enableDebug?: boolean;
255
260
  };
256
261
  type BotReason = 'none' | 'cf_bot_score' | 'cf_verified_bot' | 'force_bot_param';
257
262
  type PersonalizationHeaders = {
263
+ 'x-visit-url'?: string;
264
+ 'x-visit-referrer'?: string;
258
265
  'x-device-type': string;
259
266
  'x-is-mobile-viewer': string;
260
267
  'x-viewer-city': string;
@@ -138,7 +138,9 @@ interface ExperimentMetadata {
138
138
  audience_ids?: string[];
139
139
  };
140
140
  lane_ids?: string[];
141
+ serving_mode?: ServingMode;
141
142
  }
143
+ type ServingMode = 'off' | 'split' | 'winner';
142
144
  interface Allocation {
143
145
  [variantId: string]: number[][];
144
146
  }
@@ -199,6 +201,8 @@ type ActivationCondition = {
199
201
  type AntiflickerMode = 'body' | 'include' | 'exclude';
200
202
  type BotReason = 'none' | 'cf_bot_score' | 'cf_verified_bot' | 'force_bot_param';
201
203
  type PersonalizationHeaders = {
204
+ 'x-visit-url'?: string;
205
+ 'x-visit-referrer'?: string;
202
206
  'x-device-type': string;
203
207
  'x-is-mobile-viewer': string;
204
208
  'x-viewer-city': string;
@@ -214,6 +218,7 @@ type PersonalizationHeaders = {
214
218
  interface GetProjectDataOptions {
215
219
  projectId: string;
216
220
  currentUrl: string;
221
+ referrer?: string;
217
222
  userContext?: Record<string, unknown>;
218
223
  headers: Headers | Record<string, string>;
219
224
  antiflickerMode?: AntiflickerMode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coframe/sdk",
3
- "version": "1.1.14",
3
+ "version": "1.1.21",
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",