@coframe/sdk 1.1.27 → 1.1.30

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.
@@ -4032,16 +4032,22 @@ async function resolveConfig(Coframe, revealPage) {
4032
4032
  };
4033
4033
  }
4034
4034
 
4035
- async function resolveIdentity(config, Coframe, timeoutMs, gracefulExit) {
4035
+ async function resolveIdentity(config, Coframe, timeoutMs, gracefulExit, previewVariantId) {
4036
4036
  const logger = Coframe.logger;
4037
4037
  let userToken;
4038
4038
  if (config.waitForUserToken) {
4039
4039
  const tokenCmd = await waitForCmd((cmd) => !!cmd.setUserToken && typeof cmd.setUserToken === 'string', Coframe, timeoutMs);
4040
- if (!tokenCmd || !tokenCmd.setUserToken) {
4040
+ if (tokenCmd === null || tokenCmd === void 0 ? void 0 : tokenCmd.setUserToken) {
4041
+ userToken = tokenCmd.setUserToken;
4042
+ }
4043
+ else if (previewVariantId) {
4044
+ console.warn('[Coframe] User token was not provided after timeout, using an internal token for the preview');
4045
+ userToken = getOrGenerateUserToken();
4046
+ }
4047
+ else {
4041
4048
  gracefulExit('User token was not provided after timeout, graceful exit');
4042
4049
  return null;
4043
4050
  }
4044
- userToken = tokenCmd.setUserToken;
4045
4051
  }
4046
4052
  else {
4047
4053
  userToken = getOrGenerateUserToken();
@@ -4257,7 +4263,7 @@ async function init(options) {
4257
4263
  return;
4258
4264
  Coframe.orgId = projectResult.project.org_id || '';
4259
4265
  Coframe.personalizationHeaders = projectResult.personalizationHeaders;
4260
- const identity = await resolveIdentity(configResult.config, Coframe, configResult.timeoutMs, gracefulExit);
4266
+ const identity = await resolveIdentity(configResult.config, Coframe, configResult.timeoutMs, gracefulExit, configResult.previewVariantId);
4261
4267
  if (!identity)
4262
4268
  return;
4263
4269
  const analytics = setupTracking(Coframe, projectResult, configResult.previewVariantId, configResult.executionStartTime, configResult.config.nonce, configResult.config.waitForCookiesEnabled, identity.onConsentChange);
@@ -4030,16 +4030,22 @@ async function resolveConfig(Coframe, revealPage) {
4030
4030
  };
4031
4031
  }
4032
4032
 
4033
- async function resolveIdentity(config, Coframe, timeoutMs, gracefulExit) {
4033
+ async function resolveIdentity(config, Coframe, timeoutMs, gracefulExit, previewVariantId) {
4034
4034
  const logger = Coframe.logger;
4035
4035
  let userToken;
4036
4036
  if (config.waitForUserToken) {
4037
4037
  const tokenCmd = await waitForCmd((cmd) => !!cmd.setUserToken && typeof cmd.setUserToken === 'string', Coframe, timeoutMs);
4038
- if (!tokenCmd || !tokenCmd.setUserToken) {
4038
+ if (tokenCmd === null || tokenCmd === void 0 ? void 0 : tokenCmd.setUserToken) {
4039
+ userToken = tokenCmd.setUserToken;
4040
+ }
4041
+ else if (previewVariantId) {
4042
+ console.warn('[Coframe] User token was not provided after timeout, using an internal token for the preview');
4043
+ userToken = getOrGenerateUserToken();
4044
+ }
4045
+ else {
4039
4046
  gracefulExit('User token was not provided after timeout, graceful exit');
4040
4047
  return null;
4041
4048
  }
4042
- userToken = tokenCmd.setUserToken;
4043
4049
  }
4044
4050
  else {
4045
4051
  userToken = getOrGenerateUserToken();
@@ -4255,7 +4261,7 @@ async function init(options) {
4255
4261
  return;
4256
4262
  Coframe.orgId = projectResult.project.org_id || '';
4257
4263
  Coframe.personalizationHeaders = projectResult.personalizationHeaders;
4258
- const identity = await resolveIdentity(configResult.config, Coframe, configResult.timeoutMs, gracefulExit);
4264
+ const identity = await resolveIdentity(configResult.config, Coframe, configResult.timeoutMs, gracefulExit, configResult.previewVariantId);
4259
4265
  if (!identity)
4260
4266
  return;
4261
4267
  const analytics = setupTracking(Coframe, projectResult, configResult.previewVariantId, configResult.executionStartTime, configResult.config.nonce, configResult.config.waitForCookiesEnabled, identity.onConsentChange);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coframe/sdk",
3
- "version": "1.1.27",
3
+ "version": "1.1.30",
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",