@coframe/sdk 1.1.35 → 1.1.37

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.
@@ -3332,6 +3332,42 @@ function observeUrlChanges(baseUrlMatch, onUrlChange) {
3332
3332
  patchHistoryMethod('replaceState');
3333
3333
  }
3334
3334
 
3335
+ function mergeClientHeaders(client, server) {
3336
+ if (server)
3337
+ return { ...client, ...server };
3338
+ return client && Object.keys(client).length > 0 ? { ...client } : null;
3339
+ }
3340
+ function getQueuedPersonalizationHeaders() {
3341
+ var _a, _b, _c;
3342
+ const topLevel = (_a = findLastCmd((c) => !!c.personalizationHeaders)) === null || _a === void 0 ? void 0 : _a.personalizationHeaders;
3343
+ const nested = (_c = (_b = findLastCmd((c) => !!c.projectData)) === null || _b === void 0 ? void 0 : _b.projectData) === null || _c === void 0 ? void 0 : _c.personalizationHeaders;
3344
+ return mergeClientHeaders(topLevel, nested);
3345
+ }
3346
+ async function resolveProject(Coframe, previewVariantId, isSessionVariant, config) {
3347
+ var _a, _b;
3348
+ const logger = Coframe.logger;
3349
+ const projectData = (_a = findLastCmd((c) => !!c.projectData)) === null || _a === void 0 ? void 0 : _a.projectData;
3350
+ const queuedHeaders = getQueuedPersonalizationHeaders();
3351
+ let personalizationHeaders = queuedHeaders;
3352
+ let project = isSessionVariant ? undefined : projectData === null || projectData === void 0 ? void 0 : projectData.project;
3353
+ if (!project) {
3354
+ const edgeResult = await fetchProject(config.projectUrl, Coframe.projectId, config.currentUrl || getCurrentPageUrl(), undefined, config.userContext, previewVariantId || undefined, undefined, (_b = config.referrer) !== null && _b !== void 0 ? _b : getBrowserReferrer());
3355
+ personalizationHeaders = mergeClientHeaders(queuedHeaders, edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.personalizationHeaders);
3356
+ project = (edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.project) || undefined;
3357
+ }
3358
+ if (!project) {
3359
+ logger.error('No Coframe Project Config', 'no_project_config', {
3360
+ previewVariantId,
3361
+ });
3362
+ variantRendered();
3363
+ return null;
3364
+ }
3365
+ return {
3366
+ project,
3367
+ personalizationHeaders: personalizationHeaders,
3368
+ };
3369
+ }
3370
+
3335
3371
  const callbacks = [];
3336
3372
  function onEventsFlushed(callback) {
3337
3373
  callbacks.push(callback);
@@ -3764,6 +3800,7 @@ function setupSPANavigation(Coframe, project, config, previewVariantId, isSessio
3764
3800
  if (cached) {
3765
3801
  pageProject = cached.project;
3766
3802
  pagePersonalizationHeaders = {
3803
+ ...getQueuedPersonalizationHeaders(),
3767
3804
  ...cached.personalizationHeaders,
3768
3805
  'x-visit-url': newPageUrl,
3769
3806
  };
@@ -3776,7 +3813,10 @@ function setupSPANavigation(Coframe, project, config, previewVariantId, isSessio
3776
3813
  return;
3777
3814
  if (result) {
3778
3815
  pageProject = result.project;
3779
- pagePersonalizationHeaders = result.personalizationHeaders;
3816
+ pagePersonalizationHeaders = {
3817
+ ...getQueuedPersonalizationHeaders(),
3818
+ ...result.personalizationHeaders,
3819
+ };
3780
3820
  cacheFrames(newPageUrl, result);
3781
3821
  }
3782
3822
  }
@@ -4210,30 +4250,6 @@ async function resolveIdentity(config, Coframe, timeoutMs, gracefulExit, preview
4210
4250
  return { userToken, applyCookieConsent, onConsentChange };
4211
4251
  }
4212
4252
 
4213
- async function resolveProject(Coframe, previewVariantId, isSessionVariant, config) {
4214
- var _a, _b;
4215
- const logger = Coframe.logger;
4216
- const projectData = (_a = findLastCmd((c) => !!c.projectData)) === null || _a === void 0 ? void 0 : _a.projectData;
4217
- let personalizationHeaders = (projectData === null || projectData === void 0 ? void 0 : projectData.personalizationHeaders) || null;
4218
- let project = isSessionVariant ? undefined : projectData === null || projectData === void 0 ? void 0 : projectData.project;
4219
- if (!project) {
4220
- const edgeResult = await fetchProject(config.projectUrl, Coframe.projectId, config.currentUrl || getCurrentPageUrl(), undefined, config.userContext, previewVariantId || undefined, undefined, (_b = config.referrer) !== null && _b !== void 0 ? _b : getBrowserReferrer());
4221
- personalizationHeaders = (edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.personalizationHeaders) || null;
4222
- project = (edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.project) || undefined;
4223
- }
4224
- if (!project) {
4225
- logger.error('No Coframe Project Config', 'no_project_config', {
4226
- previewVariantId,
4227
- });
4228
- variantRendered();
4229
- return null;
4230
- }
4231
- return {
4232
- project,
4233
- personalizationHeaders: personalizationHeaders,
4234
- };
4235
- }
4236
-
4237
4253
  const COFRAME_LAUNCHER_PROTOCOL_VERSION = 1;
4238
4254
 
4239
4255
  const LAUNCHER_SCRIPT_ID = 'coframe-tools-launcher-script';
@@ -4298,6 +4314,10 @@ function injectOptions(options) {
4298
4314
  window.CFQ = window.CFQ || [];
4299
4315
  window.CFQ.push({ config: options.config });
4300
4316
  }
4317
+ if (options.personalizationHeaders) {
4318
+ window.CFQ = window.CFQ || [];
4319
+ window.CFQ.push({ personalizationHeaders: options.personalizationHeaders });
4320
+ }
4301
4321
  if (options.projectData) {
4302
4322
  window.CFQ = window.CFQ || [];
4303
4323
  window.CFQ.push({
@@ -3330,6 +3330,42 @@ function observeUrlChanges(baseUrlMatch, onUrlChange) {
3330
3330
  patchHistoryMethod('replaceState');
3331
3331
  }
3332
3332
 
3333
+ function mergeClientHeaders(client, server) {
3334
+ if (server)
3335
+ return { ...client, ...server };
3336
+ return client && Object.keys(client).length > 0 ? { ...client } : null;
3337
+ }
3338
+ function getQueuedPersonalizationHeaders() {
3339
+ var _a, _b, _c;
3340
+ const topLevel = (_a = findLastCmd((c) => !!c.personalizationHeaders)) === null || _a === void 0 ? void 0 : _a.personalizationHeaders;
3341
+ const nested = (_c = (_b = findLastCmd((c) => !!c.projectData)) === null || _b === void 0 ? void 0 : _b.projectData) === null || _c === void 0 ? void 0 : _c.personalizationHeaders;
3342
+ return mergeClientHeaders(topLevel, nested);
3343
+ }
3344
+ async function resolveProject(Coframe, previewVariantId, isSessionVariant, config) {
3345
+ var _a, _b;
3346
+ const logger = Coframe.logger;
3347
+ const projectData = (_a = findLastCmd((c) => !!c.projectData)) === null || _a === void 0 ? void 0 : _a.projectData;
3348
+ const queuedHeaders = getQueuedPersonalizationHeaders();
3349
+ let personalizationHeaders = queuedHeaders;
3350
+ let project = isSessionVariant ? undefined : projectData === null || projectData === void 0 ? void 0 : projectData.project;
3351
+ if (!project) {
3352
+ const edgeResult = await fetchProject(config.projectUrl, Coframe.projectId, config.currentUrl || getCurrentPageUrl(), undefined, config.userContext, previewVariantId || undefined, undefined, (_b = config.referrer) !== null && _b !== void 0 ? _b : getBrowserReferrer());
3353
+ personalizationHeaders = mergeClientHeaders(queuedHeaders, edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.personalizationHeaders);
3354
+ project = (edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.project) || undefined;
3355
+ }
3356
+ if (!project) {
3357
+ logger.error('No Coframe Project Config', 'no_project_config', {
3358
+ previewVariantId,
3359
+ });
3360
+ variantRendered();
3361
+ return null;
3362
+ }
3363
+ return {
3364
+ project,
3365
+ personalizationHeaders: personalizationHeaders,
3366
+ };
3367
+ }
3368
+
3333
3369
  const callbacks = [];
3334
3370
  function onEventsFlushed(callback) {
3335
3371
  callbacks.push(callback);
@@ -3762,6 +3798,7 @@ function setupSPANavigation(Coframe, project, config, previewVariantId, isSessio
3762
3798
  if (cached) {
3763
3799
  pageProject = cached.project;
3764
3800
  pagePersonalizationHeaders = {
3801
+ ...getQueuedPersonalizationHeaders(),
3765
3802
  ...cached.personalizationHeaders,
3766
3803
  'x-visit-url': newPageUrl,
3767
3804
  };
@@ -3774,7 +3811,10 @@ function setupSPANavigation(Coframe, project, config, previewVariantId, isSessio
3774
3811
  return;
3775
3812
  if (result) {
3776
3813
  pageProject = result.project;
3777
- pagePersonalizationHeaders = result.personalizationHeaders;
3814
+ pagePersonalizationHeaders = {
3815
+ ...getQueuedPersonalizationHeaders(),
3816
+ ...result.personalizationHeaders,
3817
+ };
3778
3818
  cacheFrames(newPageUrl, result);
3779
3819
  }
3780
3820
  }
@@ -4208,30 +4248,6 @@ async function resolveIdentity(config, Coframe, timeoutMs, gracefulExit, preview
4208
4248
  return { userToken, applyCookieConsent, onConsentChange };
4209
4249
  }
4210
4250
 
4211
- async function resolveProject(Coframe, previewVariantId, isSessionVariant, config) {
4212
- var _a, _b;
4213
- const logger = Coframe.logger;
4214
- const projectData = (_a = findLastCmd((c) => !!c.projectData)) === null || _a === void 0 ? void 0 : _a.projectData;
4215
- let personalizationHeaders = (projectData === null || projectData === void 0 ? void 0 : projectData.personalizationHeaders) || null;
4216
- let project = isSessionVariant ? undefined : projectData === null || projectData === void 0 ? void 0 : projectData.project;
4217
- if (!project) {
4218
- const edgeResult = await fetchProject(config.projectUrl, Coframe.projectId, config.currentUrl || getCurrentPageUrl(), undefined, config.userContext, previewVariantId || undefined, undefined, (_b = config.referrer) !== null && _b !== void 0 ? _b : getBrowserReferrer());
4219
- personalizationHeaders = (edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.personalizationHeaders) || null;
4220
- project = (edgeResult === null || edgeResult === void 0 ? void 0 : edgeResult.project) || undefined;
4221
- }
4222
- if (!project) {
4223
- logger.error('No Coframe Project Config', 'no_project_config', {
4224
- previewVariantId,
4225
- });
4226
- variantRendered();
4227
- return null;
4228
- }
4229
- return {
4230
- project,
4231
- personalizationHeaders: personalizationHeaders,
4232
- };
4233
- }
4234
-
4235
4251
  const COFRAME_LAUNCHER_PROTOCOL_VERSION = 1;
4236
4252
 
4237
4253
  const LAUNCHER_SCRIPT_ID = 'coframe-tools-launcher-script';
@@ -4296,6 +4312,10 @@ function injectOptions(options) {
4296
4312
  window.CFQ = window.CFQ || [];
4297
4313
  window.CFQ.push({ config: options.config });
4298
4314
  }
4315
+ if (options.personalizationHeaders) {
4316
+ window.CFQ = window.CFQ || [];
4317
+ window.CFQ.push({ personalizationHeaders: options.personalizationHeaders });
4318
+ }
4299
4319
  if (options.projectData) {
4300
4320
  window.CFQ = window.CFQ || [];
4301
4321
  window.CFQ.push({
@@ -80,6 +80,7 @@ interface SessionReplaySettings {
80
80
  mask_text_selector: string;
81
81
  block_selector: string;
82
82
  url_deny_patterns: string[];
83
+ url_allow_patterns?: string[];
83
84
  max_session_minutes: number;
84
85
  max_session_bytes: number;
85
86
  }
@@ -297,6 +298,7 @@ interface ProjectData {
297
298
  interface CoframeInitOptions {
298
299
  config?: CoframeConfig;
299
300
  projectData?: ProjectData;
301
+ personalizationHeaders?: Partial<PersonalizationHeaders>;
300
302
  }
301
303
  type LogPayload = {
302
304
  kind: 'warn' | 'error' | 'exception';
@@ -100,6 +100,7 @@ interface SessionReplaySettings {
100
100
  mask_text_selector: string;
101
101
  block_selector: string;
102
102
  url_deny_patterns: string[];
103
+ url_allow_patterns?: string[];
103
104
  max_session_minutes: number;
104
105
  max_session_bytes: number;
105
106
  }
@@ -80,6 +80,7 @@ interface SessionReplaySettings {
80
80
  mask_text_selector: string;
81
81
  block_selector: string;
82
82
  url_deny_patterns: string[];
83
+ url_allow_patterns?: string[];
83
84
  max_session_minutes: number;
84
85
  max_session_bytes: number;
85
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coframe/sdk",
3
- "version": "1.1.35",
3
+ "version": "1.1.37",
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",