@coframe/sdk 1.1.11 → 1.1.13

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 CHANGED
@@ -49,9 +49,10 @@ installations:
49
49
  - `coframe_variant_id` previews one or more comma-separated variant IDs.
50
50
  - `coframe_should_send_events=true` allows events during preview for testing.
51
51
 
52
- When `enableDebug: true` is set for the project, open the Launcher with
53
- `cf_debug=true` and use **Keep across navigation** in the Preview Session
54
- tool to keep the selected variants active for the current tab.
52
+ Debug tools are allowed by default. Open the Launcher with `cf_preview=true` and
53
+ use **Keep across navigation** in the Preview Session tool to keep the selected
54
+ variants active for the current tab. Set `enableDebug: false` to prevent URL or
55
+ saved session state from loading the Launcher.
55
56
 
56
57
  For SSR, pass the complete request URL, including its query string, as
57
58
  `currentUrl`. This is required for query-sensitive targeting and allows
@@ -900,7 +900,16 @@ function getUrlSearchParams(url) {
900
900
  return createURLSearchParams(search);
901
901
  }
902
902
 
903
- const COFRAME_DEBUG_QUERY_PARAM = 'cf_debug';
903
+ const COFRAME_TOOL_QUERY_PARAM = 'cf_tool';
904
+ const COFRAME_DEV_TOOL_QUERY_PARAM = 'cf_devtool';
905
+ const COFRAME_ANNOTATION_QUERY_PARAM = 'cf_annotation';
906
+ const COFRAME_PREVIEW_QUERY_PARAM = 'cf_preview';
907
+ const COFRAME_TOOL_QUERY_PARAMS = [
908
+ COFRAME_TOOL_QUERY_PARAM,
909
+ COFRAME_DEV_TOOL_QUERY_PARAM,
910
+ COFRAME_ANNOTATION_QUERY_PARAM,
911
+ COFRAME_PREVIEW_QUERY_PARAM,
912
+ ];
904
913
  const COFRAME_TOOL_INTERACTION_ATTRIBUTE = 'data-cf-t';
905
914
  const COFRAME_DEBUG_TOOLS_SESSION_STORAGE_KEY = 'cf.tools.enabled';
906
915
  const COFRAME_DEBUG_TOOLS_STATE_STORAGE_KEY = 'cf.tools.session';
@@ -920,13 +929,56 @@ function clearDebugToolsSession() {
920
929
  catch (_a) {
921
930
  }
922
931
  }
932
+ function resolveDebugToolsEntry(url = getCurrentPageUrl()) {
933
+ const params = getUrlSearchParams(url);
934
+ const directTools = [];
935
+ if (params.get(COFRAME_DEV_TOOL_QUERY_PARAM) === ENABLED_VALUE) {
936
+ directTools.push('dev-tool');
937
+ }
938
+ if (params.get(COFRAME_PREVIEW_QUERY_PARAM) === ENABLED_VALUE) {
939
+ directTools.push('preview-ui');
940
+ }
941
+ if (params.get(COFRAME_ANNOTATION_QUERY_PARAM) === ENABLED_VALUE) {
942
+ directTools.push('annotations');
943
+ }
944
+ if (directTools.length > 1) {
945
+ return { kind: 'conflict', toolIds: directTools };
946
+ }
947
+ if (directTools.length === 1) {
948
+ return { kind: 'tool', toolId: directTools[0] };
949
+ }
950
+ if (params.get(COFRAME_TOOL_QUERY_PARAM) === ENABLED_VALUE) {
951
+ return { kind: 'launcher' };
952
+ }
953
+ return { kind: 'none' };
954
+ }
955
+ function removeDebugToolsEntryParams(url) {
956
+ const hashIndex = url.indexOf('#');
957
+ const hash = hashIndex === -1 ? '' : url.slice(hashIndex);
958
+ const withoutHash = hashIndex === -1 ? url : url.slice(0, hashIndex);
959
+ const queryIndex = withoutHash.indexOf('?');
960
+ if (queryIndex === -1)
961
+ return url;
962
+ const base = withoutHash.slice(0, queryIndex);
963
+ const query = withoutHash.slice(queryIndex + 1);
964
+ const filtered = query.split('&').filter((pair) => {
965
+ const rawKey = pair.split('=', 1)[0];
966
+ let key = rawKey;
967
+ try {
968
+ key = decodeURIComponent(rawKey);
969
+ }
970
+ catch (_a) {
971
+ }
972
+ return !COFRAME_TOOL_QUERY_PARAMS.includes(key);
973
+ });
974
+ return `${base}${filtered.length ? `?${filtered.join('&')}` : ''}${hash}`;
975
+ }
923
976
  function isDebugToolsSessionEnabled(allowed) {
924
977
  if (!allowed) {
925
978
  clearDebugToolsSession();
926
979
  return false;
927
980
  }
928
- const enabledByUrl = getUrlSearchParams(getCurrentPageUrl()).get(COFRAME_DEBUG_QUERY_PARAM) ===
929
- ENABLED_VALUE;
981
+ const enabledByUrl = resolveDebugToolsEntry().kind !== 'none';
930
982
  if (enabledByUrl) {
931
983
  enableDebugToolsSession();
932
984
  return true;
@@ -3464,9 +3516,7 @@ function getLauncher() {
3464
3516
  }
3465
3517
  function exitDebugSession() {
3466
3518
  clearDebugToolsSession();
3467
- const url = new URL(window.location.href);
3468
- url.searchParams.delete(COFRAME_DEBUG_QUERY_PARAM);
3469
- window.history.replaceState(window.history.state, '', url);
3519
+ window.history.replaceState(window.history.state, '', removeDebugToolsEntryParams(window.location.href));
3470
3520
  }
3471
3521
  function mountLauncher(nonce) {
3472
3522
  const launcher = getLauncher();
@@ -3475,7 +3525,7 @@ function mountLauncher(nonce) {
3475
3525
  launcher.mount({ nonce, onExitDebugSession: exitDebugSession });
3476
3526
  return true;
3477
3527
  }
3478
- function loadLauncherIfEnabled(enabled, nonce) {
3528
+ function loadLauncherIfEnabled(enabled = true, nonce) {
3479
3529
  if (typeof window === 'undefined')
3480
3530
  return;
3481
3531
  let sessionEnabled = false;
@@ -3592,7 +3642,7 @@ async function init(options) {
3592
3642
  const configResult = await resolveConfig(Coframe, revealPage);
3593
3643
  if (!configResult)
3594
3644
  return;
3595
- loadLauncherIfEnabled(configResult.config.enableDebug === true, configResult.config.nonce);
3645
+ loadLauncherIfEnabled(configResult.config.enableDebug, configResult.config.nonce);
3596
3646
  const projectResult = await resolveProject(Coframe, configResult.previewVariantId, configResult.isSessionVariant, configResult.config);
3597
3647
  if (!projectResult)
3598
3648
  return;
@@ -898,7 +898,16 @@ function getUrlSearchParams(url) {
898
898
  return createURLSearchParams(search);
899
899
  }
900
900
 
901
- const COFRAME_DEBUG_QUERY_PARAM = 'cf_debug';
901
+ const COFRAME_TOOL_QUERY_PARAM = 'cf_tool';
902
+ const COFRAME_DEV_TOOL_QUERY_PARAM = 'cf_devtool';
903
+ const COFRAME_ANNOTATION_QUERY_PARAM = 'cf_annotation';
904
+ const COFRAME_PREVIEW_QUERY_PARAM = 'cf_preview';
905
+ const COFRAME_TOOL_QUERY_PARAMS = [
906
+ COFRAME_TOOL_QUERY_PARAM,
907
+ COFRAME_DEV_TOOL_QUERY_PARAM,
908
+ COFRAME_ANNOTATION_QUERY_PARAM,
909
+ COFRAME_PREVIEW_QUERY_PARAM,
910
+ ];
902
911
  const COFRAME_TOOL_INTERACTION_ATTRIBUTE = 'data-cf-t';
903
912
  const COFRAME_DEBUG_TOOLS_SESSION_STORAGE_KEY = 'cf.tools.enabled';
904
913
  const COFRAME_DEBUG_TOOLS_STATE_STORAGE_KEY = 'cf.tools.session';
@@ -918,13 +927,56 @@ function clearDebugToolsSession() {
918
927
  catch (_a) {
919
928
  }
920
929
  }
930
+ function resolveDebugToolsEntry(url = getCurrentPageUrl()) {
931
+ const params = getUrlSearchParams(url);
932
+ const directTools = [];
933
+ if (params.get(COFRAME_DEV_TOOL_QUERY_PARAM) === ENABLED_VALUE) {
934
+ directTools.push('dev-tool');
935
+ }
936
+ if (params.get(COFRAME_PREVIEW_QUERY_PARAM) === ENABLED_VALUE) {
937
+ directTools.push('preview-ui');
938
+ }
939
+ if (params.get(COFRAME_ANNOTATION_QUERY_PARAM) === ENABLED_VALUE) {
940
+ directTools.push('annotations');
941
+ }
942
+ if (directTools.length > 1) {
943
+ return { kind: 'conflict', toolIds: directTools };
944
+ }
945
+ if (directTools.length === 1) {
946
+ return { kind: 'tool', toolId: directTools[0] };
947
+ }
948
+ if (params.get(COFRAME_TOOL_QUERY_PARAM) === ENABLED_VALUE) {
949
+ return { kind: 'launcher' };
950
+ }
951
+ return { kind: 'none' };
952
+ }
953
+ function removeDebugToolsEntryParams(url) {
954
+ const hashIndex = url.indexOf('#');
955
+ const hash = hashIndex === -1 ? '' : url.slice(hashIndex);
956
+ const withoutHash = hashIndex === -1 ? url : url.slice(0, hashIndex);
957
+ const queryIndex = withoutHash.indexOf('?');
958
+ if (queryIndex === -1)
959
+ return url;
960
+ const base = withoutHash.slice(0, queryIndex);
961
+ const query = withoutHash.slice(queryIndex + 1);
962
+ const filtered = query.split('&').filter((pair) => {
963
+ const rawKey = pair.split('=', 1)[0];
964
+ let key = rawKey;
965
+ try {
966
+ key = decodeURIComponent(rawKey);
967
+ }
968
+ catch (_a) {
969
+ }
970
+ return !COFRAME_TOOL_QUERY_PARAMS.includes(key);
971
+ });
972
+ return `${base}${filtered.length ? `?${filtered.join('&')}` : ''}${hash}`;
973
+ }
921
974
  function isDebugToolsSessionEnabled(allowed) {
922
975
  if (!allowed) {
923
976
  clearDebugToolsSession();
924
977
  return false;
925
978
  }
926
- const enabledByUrl = getUrlSearchParams(getCurrentPageUrl()).get(COFRAME_DEBUG_QUERY_PARAM) ===
927
- ENABLED_VALUE;
979
+ const enabledByUrl = resolveDebugToolsEntry().kind !== 'none';
928
980
  if (enabledByUrl) {
929
981
  enableDebugToolsSession();
930
982
  return true;
@@ -3462,9 +3514,7 @@ function getLauncher() {
3462
3514
  }
3463
3515
  function exitDebugSession() {
3464
3516
  clearDebugToolsSession();
3465
- const url = new URL(window.location.href);
3466
- url.searchParams.delete(COFRAME_DEBUG_QUERY_PARAM);
3467
- window.history.replaceState(window.history.state, '', url);
3517
+ window.history.replaceState(window.history.state, '', removeDebugToolsEntryParams(window.location.href));
3468
3518
  }
3469
3519
  function mountLauncher(nonce) {
3470
3520
  const launcher = getLauncher();
@@ -3473,7 +3523,7 @@ function mountLauncher(nonce) {
3473
3523
  launcher.mount({ nonce, onExitDebugSession: exitDebugSession });
3474
3524
  return true;
3475
3525
  }
3476
- function loadLauncherIfEnabled(enabled, nonce) {
3526
+ function loadLauncherIfEnabled(enabled = true, nonce) {
3477
3527
  if (typeof window === 'undefined')
3478
3528
  return;
3479
3529
  let sessionEnabled = false;
@@ -3590,7 +3640,7 @@ async function init(options) {
3590
3640
  const configResult = await resolveConfig(Coframe, revealPage);
3591
3641
  if (!configResult)
3592
3642
  return;
3593
- loadLauncherIfEnabled(configResult.config.enableDebug === true, configResult.config.nonce);
3643
+ loadLauncherIfEnabled(configResult.config.enableDebug, configResult.config.nonce);
3594
3644
  const projectResult = await resolveProject(Coframe, configResult.previewVariantId, configResult.isSessionVariant, configResult.config);
3595
3645
  if (!projectResult)
3596
3646
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coframe/sdk",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
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",