@usertour/helpers 0.0.45 → 0.0.47

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.
@@ -521,9 +521,9 @@ var evaluateRule = async (condition, options) => {
521
521
  var _a, _b;
522
522
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
523
523
  const conditionId = condition.id;
524
- if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
524
+ if (conditionId && (activatedIds == null ? void 0 : activatedIds.includes(conditionId)))
525
525
  return true;
526
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
526
+ if (conditionId && (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId)))
527
527
  return false;
528
528
  const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
529
529
  if (customEvaluator) {
@@ -2,7 +2,7 @@ import {
2
2
  evaluateRulesConditions,
3
3
  filterConditionsByType,
4
4
  isConditionsActived
5
- } from "../chunk-SLM6E7HG.js";
5
+ } from "../chunk-SIG4WTEF.js";
6
6
  import "../chunk-YYIGUZNZ.js";
7
7
  import "../chunk-PAESAL23.js";
8
8
  import "../chunk-3KG2HTZ3.js";
@@ -59,6 +59,14 @@ var buildConfig = (config) => {
59
59
  hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
60
60
  };
61
61
  };
62
+ var extractUserAttributeValue = (element, userAttributes) => {
63
+ if (!userAttributes || !("attrCode" in element) || typeof element.attrCode !== "string") {
64
+ return "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
65
+ }
66
+ const attrValue = userAttributes[element.attrCode];
67
+ const fallback = "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
68
+ return attrValue != null ? attrValue : fallback;
69
+ };
62
70
  var extractLinkUrl = (value, userAttributes) => {
63
71
  let url = "";
64
72
  try {
@@ -66,13 +74,7 @@ var extractLinkUrl = (value, userAttributes) => {
66
74
  if ("children" in v && Array.isArray(v.children)) {
67
75
  for (const vc of v.children) {
68
76
  if ("type" in vc && vc.type === "user-attribute") {
69
- if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
70
- const attrValue = userAttributes[vc.attrCode];
71
- const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
72
- url += attrValue != null ? attrValue : fallback;
73
- } else if ("fallback" in vc && typeof vc.fallback === "string") {
74
- url += vc.fallback;
75
- }
77
+ url += String(extractUserAttributeValue(vc, userAttributes));
76
78
  } else if ("text" in vc && typeof vc.text === "string") {
77
79
  url += vc.text;
78
80
  }
@@ -89,7 +91,7 @@ var replaceUserAttrForElement = (data, userAttributes) => {
89
91
  v.children = replaceUserAttrForElement(v.children, userAttributes);
90
92
  }
91
93
  if (v.type === "user-attribute" && userAttributes) {
92
- const value = userAttributes[v.attrCode] || v.fallback;
94
+ const value = extractUserAttributeValue(v, userAttributes);
93
95
  if (!isUndefined(value)) {
94
96
  v.value = String(value);
95
97
  }
@@ -51,9 +51,9 @@ var evaluateRule = async (condition, options) => {
51
51
  var _a, _b;
52
52
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
53
53
  const conditionId = condition.id;
54
- if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
54
+ if (conditionId && (activatedIds == null ? void 0 : activatedIds.includes(conditionId)))
55
55
  return true;
56
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
56
+ if (conditionId && (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId)))
57
57
  return false;
58
58
  const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
59
59
  if (customEvaluator) {
@@ -539,9 +539,9 @@ var evaluateRule = async (condition, options) => {
539
539
  var _a, _b;
540
540
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
541
541
  const conditionId = condition.id;
542
- if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
542
+ if (conditionId && (activatedIds == null ? void 0 : activatedIds.includes(conditionId)))
543
543
  return true;
544
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
544
+ if (conditionId && (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId)))
545
545
  return false;
546
546
  const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
547
547
  if (customEvaluator) {
@@ -8,7 +8,7 @@ import {
8
8
  isConditionsActived,
9
9
  isEqual,
10
10
  regenerateConditionIds
11
- } from "../chunk-SLM6E7HG.js";
11
+ } from "../chunk-SIG4WTEF.js";
12
12
  import "../chunk-YYIGUZNZ.js";
13
13
  import "../chunk-PAESAL23.js";
14
14
  import "../chunk-3KG2HTZ3.js";
@@ -584,9 +584,9 @@ var evaluateRule = async (condition, options) => {
584
584
  var _a, _b;
585
585
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
586
586
  const conditionId = condition.id;
587
- if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
587
+ if (conditionId && (activatedIds == null ? void 0 : activatedIds.includes(conditionId)))
588
588
  return true;
589
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
589
+ if (conditionId && (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId)))
590
590
  return false;
591
591
  const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
592
592
  if (customEvaluator) {
@@ -9,7 +9,7 @@ import {
9
9
  isConditionsActived,
10
10
  isEqual,
11
11
  regenerateConditionIds
12
- } from "../chunk-SLM6E7HG.js";
12
+ } from "../chunk-SIG4WTEF.js";
13
13
  import {
14
14
  evaluateUrlCondition,
15
15
  isMatchUrlPattern
@@ -1,7 +1,7 @@
1
1
  import "./chunk-7ODE2AIC.js";
2
2
  import {
3
3
  regenerateConditionIds
4
- } from "./chunk-SLM6E7HG.js";
4
+ } from "./chunk-SIG4WTEF.js";
5
5
  import "./chunk-YYIGUZNZ.js";
6
6
  import "./chunk-PAESAL23.js";
7
7
  import {
package/dist/content.cjs CHANGED
@@ -90,6 +90,14 @@ var buildConfig = (config) => {
90
90
  hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
91
91
  };
92
92
  };
93
+ var extractUserAttributeValue = (element, userAttributes) => {
94
+ if (!userAttributes || !("attrCode" in element) || typeof element.attrCode !== "string") {
95
+ return "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
96
+ }
97
+ const attrValue = userAttributes[element.attrCode];
98
+ const fallback = "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
99
+ return attrValue != null ? attrValue : fallback;
100
+ };
93
101
  var extractLinkUrl = (value, userAttributes) => {
94
102
  let url = "";
95
103
  try {
@@ -97,13 +105,7 @@ var extractLinkUrl = (value, userAttributes) => {
97
105
  if ("children" in v && Array.isArray(v.children)) {
98
106
  for (const vc of v.children) {
99
107
  if ("type" in vc && vc.type === "user-attribute") {
100
- if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
101
- const attrValue = userAttributes[vc.attrCode];
102
- const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
103
- url += attrValue != null ? attrValue : fallback;
104
- } else if ("fallback" in vc && typeof vc.fallback === "string") {
105
- url += vc.fallback;
106
- }
108
+ url += String(extractUserAttributeValue(vc, userAttributes));
107
109
  } else if ("text" in vc && typeof vc.text === "string") {
108
110
  url += vc.text;
109
111
  }
@@ -120,7 +122,7 @@ var replaceUserAttrForElement = (data, userAttributes) => {
120
122
  v.children = replaceUserAttrForElement(v.children, userAttributes);
121
123
  }
122
124
  if (v.type === "user-attribute" && userAttributes) {
123
- const value = userAttributes[v.attrCode] || v.fallback;
125
+ const value = extractUserAttributeValue(v, userAttributes);
124
126
  if (!isUndefined(value)) {
125
127
  v.value = String(value);
126
128
  }
package/dist/content.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  isPublishedAtLeastOneEnvironment,
6
6
  isPublishedInAllEnvironments,
7
7
  replaceUserAttr
8
- } from "./chunk-MU3AHQEC.js";
8
+ } from "./chunk-GK5DM6EN.js";
9
9
  import "./chunk-GFH3VWOC.js";
10
10
  import "./chunk-XEO3YXBM.js";
11
11
  export {
package/dist/index.cjs CHANGED
@@ -1053,6 +1053,14 @@ var buildConfig = (config) => {
1053
1053
  hideRulesSetting: (config == null ? void 0 : config.hideRulesSetting) || {}
1054
1054
  };
1055
1055
  };
1056
+ var extractUserAttributeValue = (element, userAttributes) => {
1057
+ if (!userAttributes || !("attrCode" in element) || typeof element.attrCode !== "string") {
1058
+ return "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
1059
+ }
1060
+ const attrValue = userAttributes[element.attrCode];
1061
+ const fallback = "fallback" in element && typeof element.fallback === "string" ? element.fallback : "";
1062
+ return attrValue != null ? attrValue : fallback;
1063
+ };
1056
1064
  var extractLinkUrl = (value, userAttributes) => {
1057
1065
  let url = "";
1058
1066
  try {
@@ -1060,13 +1068,7 @@ var extractLinkUrl = (value, userAttributes) => {
1060
1068
  if ("children" in v && Array.isArray(v.children)) {
1061
1069
  for (const vc of v.children) {
1062
1070
  if ("type" in vc && vc.type === "user-attribute") {
1063
- if (userAttributes && "attrCode" in vc && typeof vc.attrCode === "string") {
1064
- const attrValue = userAttributes[vc.attrCode];
1065
- const fallback = "fallback" in vc && typeof vc.fallback === "string" ? vc.fallback : "";
1066
- url += attrValue != null ? attrValue : fallback;
1067
- } else if ("fallback" in vc && typeof vc.fallback === "string") {
1068
- url += vc.fallback;
1069
- }
1071
+ url += String(extractUserAttributeValue(vc, userAttributes));
1070
1072
  } else if ("text" in vc && typeof vc.text === "string") {
1071
1073
  url += vc.text;
1072
1074
  }
@@ -1083,7 +1085,7 @@ var replaceUserAttrForElement = (data, userAttributes) => {
1083
1085
  v.children = replaceUserAttrForElement(v.children, userAttributes);
1084
1086
  }
1085
1087
  if (v.type === "user-attribute" && userAttributes) {
1086
- const value = userAttributes[v.attrCode] || v.fallback;
1088
+ const value = extractUserAttributeValue(v, userAttributes);
1087
1089
  if (!isUndefined(value)) {
1088
1090
  v.value = String(value);
1089
1091
  }
@@ -1559,9 +1561,9 @@ var evaluateRule = async (condition, options) => {
1559
1561
  var _a, _b;
1560
1562
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
1561
1563
  const conditionId = condition.id;
1562
- if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
1564
+ if (conditionId && (activatedIds == null ? void 0 : activatedIds.includes(conditionId)))
1563
1565
  return true;
1564
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
1566
+ if (conditionId && (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId)))
1565
1567
  return false;
1566
1568
  const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
1567
1569
  if (customEvaluator) {
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ import {
33
33
  isConditionsActived,
34
34
  isEqual,
35
35
  regenerateConditionIds
36
- } from "./chunk-SLM6E7HG.js";
36
+ } from "./chunk-SIG4WTEF.js";
37
37
  import {
38
38
  evaluateUrlCondition,
39
39
  isMatchUrlPattern
@@ -60,7 +60,7 @@ import {
60
60
  isPublishedAtLeastOneEnvironment,
61
61
  isPublishedInAllEnvironments,
62
62
  replaceUserAttr
63
- } from "./chunk-MU3AHQEC.js";
63
+ } from "./chunk-GK5DM6EN.js";
64
64
  import {
65
65
  convertSettings,
66
66
  convertToCssVars,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
4
4
  "type": "module",
5
5
  "description": "Utility functions and helpers shared across the UserTour project",
6
6
  "homepage": "https://www.usertour.io",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@paralleldrive/cuid2": "^2.2.2",
32
- "@usertour/types": "^0.0.31",
32
+ "@usertour/types": "^0.0.33",
33
33
  "chroma-js": "^3.1.2",
34
34
  "class-variance-authority": "^0.4.0",
35
35
  "clsx": "^1.2.1",