@coframe/sdk 1.1.12 → 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,7 +49,7 @@ 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
- Debug tools are allowed by default. Open the Launcher with `cf_debug=true` and
52
+ Debug tools are allowed by default. Open the Launcher with `cf_preview=true` and
53
53
  use **Keep across navigation** in the Preview Session tool to keep the selected
54
54
  variants active for the current tab. Set `enableDebug: false` to prevent URL or
55
55
  saved session state from loading the Launcher.
@@ -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();
@@ -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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coframe/sdk",
3
- "version": "1.1.12",
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",