@usertour/helpers 0.0.18 → 0.0.21
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/dist/__tests__/condition.test.cjs +679 -8
- package/dist/__tests__/condition.test.js +342 -1
- package/dist/__tests__/url.test.cjs +314 -54
- package/dist/__tests__/url.test.js +248 -4
- package/dist/chunk-PAESAL23.js +77 -0
- package/dist/chunk-UNXDVBM3.js +98 -0
- package/dist/chunk-YYIGUZNZ.js +17 -0
- package/dist/conditions/attribute.d.cts +2 -10
- package/dist/conditions/attribute.d.ts +2 -10
- package/dist/conditions/condition.cjs +328 -39
- package/dist/conditions/condition.d.cts +29 -3
- package/dist/conditions/condition.d.ts +29 -3
- package/dist/conditions/condition.js +9 -1
- package/dist/conditions/index.cjs +153 -104
- package/dist/conditions/index.d.cts +1 -1
- package/dist/conditions/index.d.ts +1 -1
- package/dist/conditions/index.js +14 -5
- package/dist/conditions/url-v1.cjs +89 -0
- package/dist/conditions/url-v1.d.cts +3 -0
- package/dist/conditions/url-v1.d.ts +3 -0
- package/dist/{chunk-BC7KXBMF.js → conditions/url-v1.js} +4 -8
- package/dist/conditions/url-v2.cjs +101 -0
- package/dist/conditions/url-v2.d.cts +16 -0
- package/dist/conditions/url-v2.d.ts +16 -0
- package/dist/conditions/url-v2.js +7 -0
- package/dist/conditions/url.cjs +69 -50
- package/dist/conditions/url.js +2 -1
- package/dist/index.cjs +153 -104
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -8
- package/package.json +2 -2
- package/dist/chunk-YOFQHQ7D.js +0 -92
package/dist/conditions/url.cjs
CHANGED
|
@@ -24,68 +24,87 @@ __export(url_exports, {
|
|
|
24
24
|
isMatchUrlPattern: () => isMatchUrlPattern
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(url_exports);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
|
|
28
|
+
// src/conditions/url-v2.ts
|
|
29
|
+
function parseUrl(url) {
|
|
30
|
+
const match = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
|
|
31
|
+
if (!match)
|
|
30
32
|
return null;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return withWildcard.replace(/:[a-z0-9_]+/g, `[^${s2}]+`);
|
|
42
|
-
};
|
|
43
|
-
var replaceSpecialWords = (str) => {
|
|
33
|
+
const [, , scheme, domain, path, , query, fragment] = match;
|
|
34
|
+
return {
|
|
35
|
+
scheme: scheme || "",
|
|
36
|
+
domain: domain || "",
|
|
37
|
+
path: path || "",
|
|
38
|
+
query: query || "",
|
|
39
|
+
fragment: fragment || ""
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function escapeRegex(str) {
|
|
44
43
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
}
|
|
45
|
+
function processUrlPattern(pattern, wildcardReplacement, paramReplacement) {
|
|
46
|
+
let processed = escapeRegex(pattern);
|
|
47
|
+
processed = processed.replace(/\\\*/g, `${wildcardReplacement}*`);
|
|
48
|
+
if (paramReplacement) {
|
|
49
|
+
processed = processed.replace(/:[a-zA-Z0-9_]+/g, `[^${paramReplacement}]+`);
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
return processed;
|
|
52
|
+
}
|
|
53
|
+
function urlPatternToRegex(pattern) {
|
|
54
|
+
const parsed = parseUrl(pattern);
|
|
55
|
+
if (!parsed) {
|
|
53
56
|
return null;
|
|
54
57
|
}
|
|
55
|
-
const { scheme, domain, path, query, fragment } =
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
let
|
|
58
|
+
const { scheme, domain, path, query, fragment } = parsed;
|
|
59
|
+
const schemePattern = scheme ? escapeRegex(scheme) : "[a-z\\d]+";
|
|
60
|
+
const domainPattern = domain ? processUrlPattern(domain, "[^/]", ".") : "[^/]*";
|
|
61
|
+
const portPattern = "(:\\d+)?";
|
|
62
|
+
const pathPattern = path ? processUrlPattern(path, "[^?#]", "/") : "/[^?#]*";
|
|
63
|
+
let queryPattern;
|
|
61
64
|
if (query) {
|
|
65
|
+
queryPattern = "";
|
|
62
66
|
new URLSearchParams(query).forEach((value, key) => {
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
let valuePattern;
|
|
68
|
+
if (value === "") {
|
|
69
|
+
valuePattern = "=?";
|
|
70
|
+
} else if (value === "*") {
|
|
71
|
+
valuePattern = "(=[^&#]*)?";
|
|
72
|
+
} else {
|
|
73
|
+
const encodedValue = value.split(/\*/g).map((part) => encodeURI(part)).join("*");
|
|
74
|
+
valuePattern = `=${processUrlPattern(encodedValue, "[^#]")}`;
|
|
75
|
+
}
|
|
76
|
+
queryPattern += `(?=.*[?&]${escapeRegex(key)}${valuePattern}([&#]|$))`;
|
|
65
77
|
});
|
|
66
|
-
|
|
78
|
+
queryPattern += "\\?[^#]*";
|
|
79
|
+
} else {
|
|
80
|
+
queryPattern = "(\\?[^#]*)?";
|
|
67
81
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
82
|
+
const fragmentPattern = fragment ? processUrlPattern(fragment, ".", "/") : "(#.*)?";
|
|
83
|
+
return new RegExp(
|
|
84
|
+
`^${schemePattern}://${domainPattern}${portPattern}${pathPattern}${queryPattern}${fragmentPattern}$`
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
function matchUrlPattern(urlPattern, url) {
|
|
88
|
+
if (urlPattern.includes.length === 0 && urlPattern.excludes.length === 0) {
|
|
76
89
|
return false;
|
|
77
|
-
}
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
}
|
|
91
|
+
const matchesInclude = urlPattern.includes.length === 0 || urlPattern.includes.some((includePattern) => {
|
|
92
|
+
const regex = urlPatternToRegex(includePattern);
|
|
93
|
+
return regex && url.match(regex);
|
|
94
|
+
});
|
|
95
|
+
const matchesExclude = urlPattern.excludes.some((excludePattern) => {
|
|
96
|
+
const regex = urlPatternToRegex(excludePattern);
|
|
97
|
+
return regex && url.match(regex);
|
|
98
|
+
});
|
|
99
|
+
return matchesInclude && !matchesExclude;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/conditions/url.ts
|
|
103
|
+
var isMatchUrlPattern = (_url, includes, excludes) => {
|
|
104
|
+
return matchUrlPattern({ includes, excludes }, _url);
|
|
86
105
|
};
|
|
87
106
|
var evaluateUrlCondition = (rules, url) => {
|
|
88
|
-
const { excludes, includes } = rules.data;
|
|
107
|
+
const { excludes = [], includes = [] } = rules.data || {};
|
|
89
108
|
return isMatchUrlPattern(url, includes, excludes);
|
|
90
109
|
};
|
|
91
110
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/conditions/url.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
ArrayProto: () => ArrayProto,
|
|
40
40
|
XMLHttpRequest: () => XMLHttpRequest,
|
|
41
41
|
absoluteUrl: () => absoluteUrl,
|
|
42
|
+
activedRulesConditions: () => activedRulesConditions,
|
|
42
43
|
assignableWindow: () => assignableWindow,
|
|
43
44
|
buildConfig: () => buildConfig,
|
|
44
45
|
cn: () => cn,
|
|
@@ -52,9 +53,11 @@ __export(src_exports, {
|
|
|
52
53
|
document: () => document,
|
|
53
54
|
evalCode: () => evalCode,
|
|
54
55
|
evaluateAttributeCondition: () => evaluateAttributeCondition,
|
|
56
|
+
evaluateRule: () => evaluateRule,
|
|
55
57
|
evaluateTimeCondition: () => evaluateTimeCondition,
|
|
56
58
|
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
57
59
|
fetch: () => fetch,
|
|
60
|
+
filterConditionsByType: () => filterConditionsByType,
|
|
58
61
|
formatDate: () => formatDate,
|
|
59
62
|
generateAutoStateColors: () => generateAutoStateColors,
|
|
60
63
|
getAuthToken: () => getAuthToken,
|
|
@@ -79,6 +82,7 @@ __export(src_exports, {
|
|
|
79
82
|
hexToRgb: () => hexToRgb,
|
|
80
83
|
isArray: () => isArray,
|
|
81
84
|
isBoolean: () => isBoolean,
|
|
85
|
+
isConditionsActived: () => isConditionsActived,
|
|
82
86
|
isDark: () => isDark,
|
|
83
87
|
isDate: () => isDate,
|
|
84
88
|
isDocument: () => isDocument,
|
|
@@ -961,124 +965,89 @@ var getRandomColor = () => {
|
|
|
961
965
|
};
|
|
962
966
|
|
|
963
967
|
// src/conditions/condition.ts
|
|
968
|
+
var import_types5 = require("@usertour/types");
|
|
964
969
|
var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
|
|
965
|
-
var compareConditionsItem = (item1, item2) => {
|
|
966
|
-
const { data = {}, ...others1 } = item1;
|
|
967
|
-
const { data: data2 = {}, ...others2 } = item2;
|
|
968
|
-
if (!(0, import_fast_deep_equal.default)(others2, others1)) {
|
|
969
|
-
return false;
|
|
970
|
-
}
|
|
971
|
-
for (const key in data) {
|
|
972
|
-
if (!(0, import_fast_deep_equal.default)(data[key], data2[key])) {
|
|
973
|
-
return false;
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
return true;
|
|
977
|
-
};
|
|
978
|
-
var conditionsIsSame = (rr1, rr2) => {
|
|
979
|
-
const r1 = [...rr1];
|
|
980
|
-
const r2 = [...rr2];
|
|
981
|
-
if (r1.length === 0 && r2.length === 0) {
|
|
982
|
-
return true;
|
|
983
|
-
}
|
|
984
|
-
if (r1.length !== r2.length) {
|
|
985
|
-
return false;
|
|
986
|
-
}
|
|
987
|
-
const group1 = r1.filter((item) => item.type === "group");
|
|
988
|
-
const group2 = r2.filter((item) => item.type === "group");
|
|
989
|
-
if (group1.length !== group2.length) {
|
|
990
|
-
return false;
|
|
991
|
-
}
|
|
992
|
-
for (let index = 0; index < r1.length; index++) {
|
|
993
|
-
const item1 = r1[index];
|
|
994
|
-
const item2 = r2[index];
|
|
995
|
-
if (!item1 || !item2) {
|
|
996
|
-
return false;
|
|
997
|
-
}
|
|
998
|
-
if (item1.type === "group") {
|
|
999
|
-
if (!item2.conditions) {
|
|
1000
|
-
return false;
|
|
1001
|
-
}
|
|
1002
|
-
const c1 = item1.conditions;
|
|
1003
|
-
const c2 = item2.conditions;
|
|
1004
|
-
if (item1.operators !== item2.operators) {
|
|
1005
|
-
return false;
|
|
1006
|
-
}
|
|
1007
|
-
if (!conditionsIsSame(c1, c2)) {
|
|
1008
|
-
return false;
|
|
1009
|
-
}
|
|
1010
|
-
} else {
|
|
1011
|
-
if (!compareConditionsItem(item1, item2)) {
|
|
1012
|
-
return false;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
return true;
|
|
1017
|
-
};
|
|
1018
970
|
|
|
1019
|
-
// src/conditions/url.ts
|
|
1020
|
-
|
|
1021
|
-
const
|
|
1022
|
-
if (!
|
|
971
|
+
// src/conditions/url-v2.ts
|
|
972
|
+
function parseUrl(url) {
|
|
973
|
+
const match = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
|
|
974
|
+
if (!match)
|
|
1023
975
|
return null;
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
return withWildcard.replace(/:[a-z0-9_]+/g, `[^${s2}]+`);
|
|
1035
|
-
};
|
|
1036
|
-
var replaceSpecialWords = (str) => {
|
|
976
|
+
const [, , scheme, domain, path, , query, fragment] = match;
|
|
977
|
+
return {
|
|
978
|
+
scheme: scheme || "",
|
|
979
|
+
domain: domain || "",
|
|
980
|
+
path: path || "",
|
|
981
|
+
query: query || "",
|
|
982
|
+
fragment: fragment || ""
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
function escapeRegex(str) {
|
|
1037
986
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
987
|
+
}
|
|
988
|
+
function processUrlPattern(pattern, wildcardReplacement, paramReplacement) {
|
|
989
|
+
let processed = escapeRegex(pattern);
|
|
990
|
+
processed = processed.replace(/\\\*/g, `${wildcardReplacement}*`);
|
|
991
|
+
if (paramReplacement) {
|
|
992
|
+
processed = processed.replace(/:[a-zA-Z0-9_]+/g, `[^${paramReplacement}]+`);
|
|
1042
993
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
994
|
+
return processed;
|
|
995
|
+
}
|
|
996
|
+
function urlPatternToRegex(pattern) {
|
|
997
|
+
const parsed = parseUrl(pattern);
|
|
998
|
+
if (!parsed) {
|
|
1046
999
|
return null;
|
|
1047
1000
|
}
|
|
1048
|
-
const { scheme, domain, path, query, fragment } =
|
|
1049
|
-
const
|
|
1050
|
-
const
|
|
1051
|
-
const
|
|
1052
|
-
const
|
|
1053
|
-
let
|
|
1001
|
+
const { scheme, domain, path, query, fragment } = parsed;
|
|
1002
|
+
const schemePattern = scheme ? escapeRegex(scheme) : "[a-z\\d]+";
|
|
1003
|
+
const domainPattern = domain ? processUrlPattern(domain, "[^/]", ".") : "[^/]*";
|
|
1004
|
+
const portPattern = "(:\\d+)?";
|
|
1005
|
+
const pathPattern = path ? processUrlPattern(path, "[^?#]", "/") : "/[^?#]*";
|
|
1006
|
+
let queryPattern;
|
|
1054
1007
|
if (query) {
|
|
1008
|
+
queryPattern = "";
|
|
1055
1009
|
new URLSearchParams(query).forEach((value, key) => {
|
|
1056
|
-
|
|
1057
|
-
|
|
1010
|
+
let valuePattern;
|
|
1011
|
+
if (value === "") {
|
|
1012
|
+
valuePattern = "=?";
|
|
1013
|
+
} else if (value === "*") {
|
|
1014
|
+
valuePattern = "(=[^&#]*)?";
|
|
1015
|
+
} else {
|
|
1016
|
+
const encodedValue = value.split(/\*/g).map((part) => encodeURI(part)).join("*");
|
|
1017
|
+
valuePattern = `=${processUrlPattern(encodedValue, "[^#]")}`;
|
|
1018
|
+
}
|
|
1019
|
+
queryPattern += `(?=.*[?&]${escapeRegex(key)}${valuePattern}([&#]|$))`;
|
|
1058
1020
|
});
|
|
1059
|
-
|
|
1021
|
+
queryPattern += "\\?[^#]*";
|
|
1022
|
+
} else {
|
|
1023
|
+
queryPattern = "(\\?[^#]*)?";
|
|
1060
1024
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
}
|
|
1069
|
-
return false;
|
|
1070
|
-
}) : true;
|
|
1071
|
-
const isMatchExcludesConditions = excludes.length > 0 ? excludes.some((_exclude) => {
|
|
1072
|
-
const reg = parsePattern(_exclude);
|
|
1073
|
-
if (reg) {
|
|
1074
|
-
return reg.test(_url);
|
|
1075
|
-
}
|
|
1025
|
+
const fragmentPattern = fragment ? processUrlPattern(fragment, ".", "/") : "(#.*)?";
|
|
1026
|
+
return new RegExp(
|
|
1027
|
+
`^${schemePattern}://${domainPattern}${portPattern}${pathPattern}${queryPattern}${fragmentPattern}$`
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
function matchUrlPattern(urlPattern, url) {
|
|
1031
|
+
if (urlPattern.includes.length === 0 && urlPattern.excludes.length === 0) {
|
|
1076
1032
|
return false;
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1033
|
+
}
|
|
1034
|
+
const matchesInclude = urlPattern.includes.length === 0 || urlPattern.includes.some((includePattern) => {
|
|
1035
|
+
const regex = urlPatternToRegex(includePattern);
|
|
1036
|
+
return regex && url.match(regex);
|
|
1037
|
+
});
|
|
1038
|
+
const matchesExclude = urlPattern.excludes.some((excludePattern) => {
|
|
1039
|
+
const regex = urlPatternToRegex(excludePattern);
|
|
1040
|
+
return regex && url.match(regex);
|
|
1041
|
+
});
|
|
1042
|
+
return matchesInclude && !matchesExclude;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
// src/conditions/url.ts
|
|
1046
|
+
var isMatchUrlPattern = (_url, includes, excludes) => {
|
|
1047
|
+
return matchUrlPattern({ includes, excludes }, _url);
|
|
1079
1048
|
};
|
|
1080
1049
|
var evaluateUrlCondition = (rules, url) => {
|
|
1081
|
-
const { excludes, includes } = rules.data;
|
|
1050
|
+
const { excludes = [], includes = [] } = rules.data || {};
|
|
1082
1051
|
return isMatchUrlPattern(url, includes, excludes);
|
|
1083
1052
|
};
|
|
1084
1053
|
|
|
@@ -1289,12 +1258,89 @@ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
|
1289
1258
|
return false;
|
|
1290
1259
|
}
|
|
1291
1260
|
}
|
|
1261
|
+
|
|
1262
|
+
// src/conditions/condition.ts
|
|
1263
|
+
var conditionsIsSame = (rr1, rr2) => {
|
|
1264
|
+
return (0, import_fast_deep_equal.default)(rr1, rr2);
|
|
1265
|
+
};
|
|
1266
|
+
var isConditionsActived = (conditions) => {
|
|
1267
|
+
if (!conditions || conditions.length === 0) {
|
|
1268
|
+
return false;
|
|
1269
|
+
}
|
|
1270
|
+
const operator = conditions[0].operators;
|
|
1271
|
+
const actives = conditions.filter((rule) => {
|
|
1272
|
+
if (!rule.conditions) {
|
|
1273
|
+
return rule.actived;
|
|
1274
|
+
}
|
|
1275
|
+
return isConditionsActived(rule.conditions);
|
|
1276
|
+
});
|
|
1277
|
+
return operator === "and" ? actives.length === conditions.length : actives.length > 0;
|
|
1278
|
+
};
|
|
1279
|
+
var filterConditionsByType = (conditions, allowedTypes) => {
|
|
1280
|
+
return conditions.filter((condition) => {
|
|
1281
|
+
if (condition.type === "group" && condition.conditions) {
|
|
1282
|
+
const filteredGroupConditions = filterConditionsByType(condition.conditions, allowedTypes);
|
|
1283
|
+
return filteredGroupConditions.length > 0;
|
|
1284
|
+
}
|
|
1285
|
+
return allowedTypes.includes(condition.type);
|
|
1286
|
+
}).map((condition) => {
|
|
1287
|
+
if (condition.type === "group" && condition.conditions) {
|
|
1288
|
+
return {
|
|
1289
|
+
...condition,
|
|
1290
|
+
conditions: filterConditionsByType(condition.conditions, allowedTypes)
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
return condition;
|
|
1294
|
+
});
|
|
1295
|
+
};
|
|
1296
|
+
var evaluateRule = (rule, options) => {
|
|
1297
|
+
var _a;
|
|
1298
|
+
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
1299
|
+
const ruleId = rule.id;
|
|
1300
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
1301
|
+
return true;
|
|
1302
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
1303
|
+
return false;
|
|
1304
|
+
if (typeControl[rule.type] === false) {
|
|
1305
|
+
return rule.actived || false;
|
|
1306
|
+
}
|
|
1307
|
+
switch (rule.type) {
|
|
1308
|
+
case import_types5.RulesType.CURRENT_PAGE:
|
|
1309
|
+
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
1310
|
+
case import_types5.RulesType.TIME:
|
|
1311
|
+
return evaluateTimeCondition(rule);
|
|
1312
|
+
case import_types5.RulesType.USER_ATTR:
|
|
1313
|
+
case import_types5.RulesType.COMPANY_ATTR:
|
|
1314
|
+
return evaluateAttributeCondition(
|
|
1315
|
+
rule,
|
|
1316
|
+
options.attributes || [],
|
|
1317
|
+
options.userAttributes || {}
|
|
1318
|
+
);
|
|
1319
|
+
default:
|
|
1320
|
+
return rule.actived || false;
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
var activedRulesConditions = (conditions, options = {}) => {
|
|
1324
|
+
return conditions.map((rule) => {
|
|
1325
|
+
if (rule.type === "group" && rule.conditions) {
|
|
1326
|
+
return {
|
|
1327
|
+
...rule,
|
|
1328
|
+
conditions: activedRulesConditions(rule.conditions, options)
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
return {
|
|
1332
|
+
...rule,
|
|
1333
|
+
actived: evaluateRule(rule, options)
|
|
1334
|
+
};
|
|
1335
|
+
});
|
|
1336
|
+
};
|
|
1292
1337
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1293
1338
|
0 && (module.exports = {
|
|
1294
1339
|
AbortController,
|
|
1295
1340
|
ArrayProto,
|
|
1296
1341
|
XMLHttpRequest,
|
|
1297
1342
|
absoluteUrl,
|
|
1343
|
+
activedRulesConditions,
|
|
1298
1344
|
assignableWindow,
|
|
1299
1345
|
buildConfig,
|
|
1300
1346
|
cn,
|
|
@@ -1308,9 +1354,11 @@ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
|
1308
1354
|
document,
|
|
1309
1355
|
evalCode,
|
|
1310
1356
|
evaluateAttributeCondition,
|
|
1357
|
+
evaluateRule,
|
|
1311
1358
|
evaluateTimeCondition,
|
|
1312
1359
|
evaluateUrlCondition,
|
|
1313
1360
|
fetch,
|
|
1361
|
+
filterConditionsByType,
|
|
1314
1362
|
formatDate,
|
|
1315
1363
|
generateAutoStateColors,
|
|
1316
1364
|
getAuthToken,
|
|
@@ -1335,6 +1383,7 @@ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
|
1335
1383
|
hexToRgb,
|
|
1336
1384
|
isArray,
|
|
1337
1385
|
isBoolean,
|
|
1386
|
+
isConditionsActived,
|
|
1338
1387
|
isDark,
|
|
1339
1388
|
isDate,
|
|
1340
1389
|
isDocument,
|
package/dist/index.d.cts
CHANGED
|
@@ -9,7 +9,7 @@ export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, is
|
|
|
9
9
|
export { deepClone } from './utils.cjs';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
|
|
12
|
-
export { conditionsIsSame } from './conditions/condition.cjs';
|
|
12
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, filterConditionsByType, isConditionsActived } from './conditions/condition.cjs';
|
|
13
13
|
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.cjs';
|
|
14
14
|
export { evaluateTimeCondition } from './conditions/time.cjs';
|
|
15
15
|
export { evaluateAttributeCondition } from './conditions/attribute.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, is
|
|
|
9
9
|
export { deepClone } from './utils.js';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.js';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
|
|
12
|
-
export { conditionsIsSame } from './conditions/condition.js';
|
|
12
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, filterConditionsByType, isConditionsActived } from './conditions/condition.js';
|
|
13
13
|
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.js';
|
|
14
14
|
export { evaluateTimeCondition } from './conditions/time.js';
|
|
15
15
|
export { evaluateAttributeCondition } from './conditions/attribute.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import "./chunk-7ODE2AIC.js";
|
|
2
|
-
import {
|
|
3
|
-
evaluateUrlCondition,
|
|
4
|
-
isMatchUrlPattern
|
|
5
|
-
} from "./chunk-BC7KXBMF.js";
|
|
6
2
|
import {
|
|
7
3
|
isUrl
|
|
8
4
|
} from "./chunk-ZNFXGN3M.js";
|
|
@@ -13,12 +9,21 @@ import {
|
|
|
13
9
|
deepClone
|
|
14
10
|
} from "./chunk-2AEGAICC.js";
|
|
15
11
|
import {
|
|
16
|
-
|
|
17
|
-
} from "./chunk-PBZSPV5R.js";
|
|
18
|
-
import {
|
|
12
|
+
activedRulesConditions,
|
|
19
13
|
conditionsIsSame,
|
|
14
|
+
evaluateRule,
|
|
15
|
+
filterConditionsByType,
|
|
16
|
+
isConditionsActived,
|
|
20
17
|
isEqual
|
|
21
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-UNXDVBM3.js";
|
|
19
|
+
import {
|
|
20
|
+
evaluateUrlCondition,
|
|
21
|
+
isMatchUrlPattern
|
|
22
|
+
} from "./chunk-YYIGUZNZ.js";
|
|
23
|
+
import "./chunk-PAESAL23.js";
|
|
24
|
+
import {
|
|
25
|
+
evaluateAttributeCondition
|
|
26
|
+
} from "./chunk-PBZSPV5R.js";
|
|
22
27
|
import {
|
|
23
28
|
evaluateTimeCondition
|
|
24
29
|
} from "./chunk-CEK3SCQO.js";
|
|
@@ -112,6 +117,7 @@ export {
|
|
|
112
117
|
ArrayProto,
|
|
113
118
|
XMLHttpRequest,
|
|
114
119
|
absoluteUrl,
|
|
120
|
+
activedRulesConditions,
|
|
115
121
|
assignableWindow,
|
|
116
122
|
buildConfig,
|
|
117
123
|
cn,
|
|
@@ -125,9 +131,11 @@ export {
|
|
|
125
131
|
document,
|
|
126
132
|
evalCode,
|
|
127
133
|
evaluateAttributeCondition,
|
|
134
|
+
evaluateRule,
|
|
128
135
|
evaluateTimeCondition,
|
|
129
136
|
evaluateUrlCondition,
|
|
130
137
|
fetch,
|
|
138
|
+
filterConditionsByType,
|
|
131
139
|
formatDate,
|
|
132
140
|
generateAutoStateColors,
|
|
133
141
|
getAuthToken,
|
|
@@ -152,6 +160,7 @@ export {
|
|
|
152
160
|
hexToRgb,
|
|
153
161
|
isArray,
|
|
154
162
|
isBoolean,
|
|
163
|
+
isConditionsActived,
|
|
155
164
|
isDark,
|
|
156
165
|
isDate,
|
|
157
166
|
isDocument,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usertour/helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
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.
|
|
32
|
+
"@usertour/types": "^0.0.11",
|
|
33
33
|
"chroma-js": "^3.1.2",
|
|
34
34
|
"class-variance-authority": "^0.4.0",
|
|
35
35
|
"clsx": "^1.2.1",
|
package/dist/chunk-YOFQHQ7D.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// src/conditions/condition.ts
|
|
2
|
-
import isEqual from "fast-deep-equal";
|
|
3
|
-
var compareConditionsItem = (item1, item2) => {
|
|
4
|
-
const { data = {}, ...others1 } = item1;
|
|
5
|
-
const { data: data2 = {}, ...others2 } = item2;
|
|
6
|
-
if (!isEqual(others2, others1)) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
for (const key in data) {
|
|
10
|
-
if (!isEqual(data[key], data2[key])) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return true;
|
|
15
|
-
};
|
|
16
|
-
var conditionsIsSame = (rr1, rr2) => {
|
|
17
|
-
const r1 = [...rr1];
|
|
18
|
-
const r2 = [...rr2];
|
|
19
|
-
if (r1.length === 0 && r2.length === 0) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
if (r1.length !== r2.length) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
const group1 = r1.filter((item) => item.type === "group");
|
|
26
|
-
const group2 = r2.filter((item) => item.type === "group");
|
|
27
|
-
if (group1.length !== group2.length) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
for (let index = 0; index < r1.length; index++) {
|
|
31
|
-
const item1 = r1[index];
|
|
32
|
-
const item2 = r2[index];
|
|
33
|
-
if (!item1 || !item2) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
if (item1.type === "group") {
|
|
37
|
-
if (!item2.conditions) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
const c1 = item1.conditions;
|
|
41
|
-
const c2 = item2.conditions;
|
|
42
|
-
if (item1.operators !== item2.operators) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
if (!conditionsIsSame(c1, c2)) {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
if (!compareConditionsItem(item1, item2)) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
};
|
|
56
|
-
var isConditionsActived = (conditions) => {
|
|
57
|
-
if (!conditions || conditions.length === 0) {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
const operator = conditions[0].operators;
|
|
61
|
-
const actives = conditions.filter((rule) => {
|
|
62
|
-
if (!rule.conditions) {
|
|
63
|
-
return rule.actived;
|
|
64
|
-
}
|
|
65
|
-
return isConditionsActived(rule.conditions);
|
|
66
|
-
});
|
|
67
|
-
return operator === "and" ? actives.length === conditions.length : actives.length > 0;
|
|
68
|
-
};
|
|
69
|
-
function filterConditionsByType(conditions, allowedTypes) {
|
|
70
|
-
return conditions.filter((condition) => {
|
|
71
|
-
if (condition.type === "group" && condition.conditions) {
|
|
72
|
-
const filteredGroupConditions = filterConditionsByType(condition.conditions, allowedTypes);
|
|
73
|
-
return filteredGroupConditions.length > 0;
|
|
74
|
-
}
|
|
75
|
-
return allowedTypes.includes(condition.type);
|
|
76
|
-
}).map((condition) => {
|
|
77
|
-
if (condition.type === "group" && condition.conditions) {
|
|
78
|
-
return {
|
|
79
|
-
...condition,
|
|
80
|
-
conditions: filterConditionsByType(condition.conditions, allowedTypes)
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
return condition;
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export {
|
|
88
|
-
isEqual,
|
|
89
|
-
conditionsIsSame,
|
|
90
|
-
isConditionsActived,
|
|
91
|
-
filterConditionsByType
|
|
92
|
-
};
|