@usertour/helpers 0.0.15 → 0.0.18
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__/attribute.test.cjs +1036 -0
- package/dist/__tests__/attribute.test.d.cts +2 -0
- package/dist/__tests__/attribute.test.d.ts +2 -0
- package/dist/__tests__/attribute.test.js +802 -0
- package/dist/__tests__/condition.test.cjs +257 -0
- package/dist/__tests__/condition.test.d.cts +2 -0
- package/dist/__tests__/condition.test.d.ts +2 -0
- package/dist/__tests__/condition.test.js +204 -0
- package/dist/__tests__/time.test.cjs +73 -0
- package/dist/__tests__/time.test.d.cts +2 -0
- package/dist/__tests__/time.test.d.ts +2 -0
- package/dist/__tests__/time.test.js +48 -0
- package/dist/__tests__/url.test.cjs +259 -0
- package/dist/__tests__/url.test.d.cts +2 -0
- package/dist/__tests__/url.test.d.ts +2 -0
- package/dist/__tests__/url.test.js +197 -0
- package/dist/{chunk-B4DTY6GN.js → chunk-4LLDSAHJ.js} +0 -12
- package/dist/chunk-7ODE2AIC.js +0 -0
- package/dist/{chunk-IZFZYGPU.js → chunk-BC7KXBMF.js} +5 -56
- package/dist/chunk-CEK3SCQO.js +31 -0
- package/dist/chunk-PBZSPV5R.js +239 -0
- package/dist/chunk-YOFQHQ7D.js +92 -0
- package/dist/conditions/attribute.cjs +264 -0
- package/dist/conditions/attribute.d.cts +28 -0
- package/dist/conditions/attribute.d.ts +28 -0
- package/dist/conditions/attribute.js +9 -0
- package/dist/conditions/condition.cjs +129 -0
- package/dist/conditions/condition.d.cts +14 -0
- package/dist/conditions/condition.d.ts +14 -0
- package/dist/conditions/condition.js +13 -0
- package/dist/conditions/index.cjs +379 -0
- package/dist/conditions/index.d.cts +6 -0
- package/dist/conditions/index.d.ts +6 -0
- package/dist/conditions/index.js +24 -0
- package/dist/conditions/time.cjs +55 -0
- package/dist/conditions/time.d.cts +10 -0
- package/dist/conditions/time.d.ts +10 -0
- package/dist/conditions/time.js +7 -0
- package/dist/{conditions.cjs → conditions/url.cjs} +9 -71
- package/dist/conditions/url.d.cts +6 -0
- package/dist/conditions/url.d.ts +6 -0
- package/dist/conditions/url.js +9 -0
- package/dist/content.cjs +0 -13
- package/dist/content.d.cts +1 -2
- package/dist/content.d.ts +1 -2
- package/dist/content.js +1 -3
- package/dist/index.cjs +261 -54
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +19 -8
- package/package.json +15 -9
- package/dist/conditions.d.cts +0 -7
- package/dist/conditions.d.ts +0 -7
- package/dist/conditions.js +0 -11
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,25 +15,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
|
-
// src/conditions.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
33
|
-
|
|
34
|
-
isEqual: () => import_fast_deep_equal.default,
|
|
20
|
+
// src/conditions/url.ts
|
|
21
|
+
var url_exports = {};
|
|
22
|
+
__export(url_exports, {
|
|
23
|
+
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
35
24
|
isMatchUrlPattern: () => isMatchUrlPattern
|
|
36
25
|
});
|
|
37
|
-
module.exports = __toCommonJS(
|
|
38
|
-
var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
|
|
26
|
+
module.exports = __toCommonJS(url_exports);
|
|
39
27
|
var parseUrl = (url) => {
|
|
40
28
|
const urlPatterns = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
|
|
41
29
|
if (!urlPatterns) {
|
|
@@ -96,62 +84,12 @@ var isMatchUrlPattern = (_url, includes, excludes) => {
|
|
|
96
84
|
}) : false;
|
|
97
85
|
return isMatchIncludesConditions && !isMatchExcludesConditions;
|
|
98
86
|
};
|
|
99
|
-
var
|
|
100
|
-
const {
|
|
101
|
-
|
|
102
|
-
if (!(0, import_fast_deep_equal.default)(others2, others1)) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
for (const key in data) {
|
|
106
|
-
if (!(0, import_fast_deep_equal.default)(data[key], data2[key])) {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return true;
|
|
111
|
-
};
|
|
112
|
-
var conditionsIsSame = (rr1, rr2) => {
|
|
113
|
-
const r1 = [...rr1];
|
|
114
|
-
const r2 = [...rr2];
|
|
115
|
-
if (r1.length === 0 && r2.length === 0) {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
if (r1.length !== r2.length) {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
121
|
-
const group1 = r1.filter((item) => item.type === "group");
|
|
122
|
-
const group2 = r2.filter((item) => item.type === "group");
|
|
123
|
-
if (group1.length !== group2.length) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
for (let index = 0; index < r1.length; index++) {
|
|
127
|
-
const item1 = r1[index];
|
|
128
|
-
const item2 = r2[index];
|
|
129
|
-
if (!item1 || !item2) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
if (item1.type === "group") {
|
|
133
|
-
if (!item2.conditions) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
const c1 = item1.conditions;
|
|
137
|
-
const c2 = item2.conditions;
|
|
138
|
-
if (item1.operators !== item2.operators) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
if (!conditionsIsSame(c1, c2)) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
} else {
|
|
145
|
-
if (!compareConditionsItem(item1, item2)) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return true;
|
|
87
|
+
var evaluateUrlCondition = (rules, url) => {
|
|
88
|
+
const { excludes, includes } = rules.data;
|
|
89
|
+
return isMatchUrlPattern(url, includes, excludes);
|
|
151
90
|
};
|
|
152
91
|
// Annotate the CommonJS export names for ESM import in node:
|
|
153
92
|
0 && (module.exports = {
|
|
154
|
-
|
|
155
|
-
isEqual,
|
|
93
|
+
evaluateUrlCondition,
|
|
156
94
|
isMatchUrlPattern
|
|
157
95
|
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RulesCondition } from '@usertour/types';
|
|
2
|
+
|
|
3
|
+
declare const isMatchUrlPattern: (_url: string, includes: string[], excludes: string[]) => boolean;
|
|
4
|
+
declare const evaluateUrlCondition: (rules: RulesCondition, url: string) => boolean;
|
|
5
|
+
|
|
6
|
+
export { evaluateUrlCondition, isMatchUrlPattern };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RulesCondition } from '@usertour/types';
|
|
2
|
+
|
|
3
|
+
declare const isMatchUrlPattern: (_url: string, includes: string[], excludes: string[]) => boolean;
|
|
4
|
+
declare const evaluateUrlCondition: (rules: RulesCondition, url: string) => boolean;
|
|
5
|
+
|
|
6
|
+
export { evaluateUrlCondition, isMatchUrlPattern };
|
package/dist/content.cjs
CHANGED
|
@@ -20,7 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/content.ts
|
|
21
21
|
var content_exports = {};
|
|
22
22
|
__export(content_exports, {
|
|
23
|
-
autoStartConditions: () => autoStartConditions,
|
|
24
23
|
buildConfig: () => buildConfig,
|
|
25
24
|
defaultContentConfig: () => defaultContentConfig,
|
|
26
25
|
isPublishedAtLeastOneEnvironment: () => isPublishedAtLeastOneEnvironment,
|
|
@@ -70,17 +69,6 @@ var defaultContentConfig = {
|
|
|
70
69
|
autoStartRulesSetting: rulesSetting,
|
|
71
70
|
hideRulesSetting
|
|
72
71
|
};
|
|
73
|
-
var autoStartConditions = {
|
|
74
|
-
...defaultContentConfig,
|
|
75
|
-
enabledAutoStartRules: true,
|
|
76
|
-
autoStartRules: [
|
|
77
|
-
{
|
|
78
|
-
data: { excludes: [], includes: ["/*"] },
|
|
79
|
-
type: "current-page",
|
|
80
|
-
operators: "and"
|
|
81
|
-
}
|
|
82
|
-
]
|
|
83
|
-
};
|
|
84
72
|
var buildConfig = (config) => {
|
|
85
73
|
return {
|
|
86
74
|
...defaultContentConfig,
|
|
@@ -94,7 +82,6 @@ var buildConfig = (config) => {
|
|
|
94
82
|
};
|
|
95
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
96
84
|
0 && (module.exports = {
|
|
97
|
-
autoStartConditions,
|
|
98
85
|
buildConfig,
|
|
99
86
|
defaultContentConfig,
|
|
100
87
|
isPublishedAtLeastOneEnvironment,
|
package/dist/content.d.cts
CHANGED
|
@@ -3,7 +3,6 @@ import { Content, Environment, ContentVersion, ContentConfigObject } from '@user
|
|
|
3
3
|
declare const isPublishedInAllEnvironments: (content: Content | null, environmentList: Environment[] | null, version: ContentVersion | null) => boolean;
|
|
4
4
|
declare const isPublishedAtLeastOneEnvironment: (content: Content | null) => boolean;
|
|
5
5
|
declare const defaultContentConfig: ContentConfigObject;
|
|
6
|
-
declare const autoStartConditions: ContentConfigObject;
|
|
7
6
|
declare const buildConfig: (config: ContentConfigObject | undefined) => ContentConfigObject;
|
|
8
7
|
|
|
9
|
-
export {
|
|
8
|
+
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments };
|
package/dist/content.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { Content, Environment, ContentVersion, ContentConfigObject } from '@user
|
|
|
3
3
|
declare const isPublishedInAllEnvironments: (content: Content | null, environmentList: Environment[] | null, version: ContentVersion | null) => boolean;
|
|
4
4
|
declare const isPublishedAtLeastOneEnvironment: (content: Content | null) => boolean;
|
|
5
5
|
declare const defaultContentConfig: ContentConfigObject;
|
|
6
|
-
declare const autoStartConditions: ContentConfigObject;
|
|
7
6
|
declare const buildConfig: (config: ContentConfigObject | undefined) => ContentConfigObject;
|
|
8
7
|
|
|
9
|
-
export {
|
|
8
|
+
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments };
|
package/dist/content.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
autoStartConditions,
|
|
3
2
|
buildConfig,
|
|
4
3
|
defaultContentConfig,
|
|
5
4
|
isPublishedAtLeastOneEnvironment,
|
|
6
5
|
isPublishedInAllEnvironments
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-4LLDSAHJ.js";
|
|
8
7
|
import "./chunk-XEO3YXBM.js";
|
|
9
8
|
export {
|
|
10
|
-
autoStartConditions,
|
|
11
9
|
buildConfig,
|
|
12
10
|
defaultContentConfig,
|
|
13
11
|
isPublishedAtLeastOneEnvironment,
|
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,6 @@ __export(src_exports, {
|
|
|
40
40
|
XMLHttpRequest: () => XMLHttpRequest,
|
|
41
41
|
absoluteUrl: () => absoluteUrl,
|
|
42
42
|
assignableWindow: () => assignableWindow,
|
|
43
|
-
autoStartConditions: () => autoStartConditions,
|
|
44
43
|
buildConfig: () => buildConfig,
|
|
45
44
|
cn: () => cn,
|
|
46
45
|
conditionsIsSame: () => conditionsIsSame,
|
|
@@ -52,6 +51,9 @@ __export(src_exports, {
|
|
|
52
51
|
defaultStep: () => defaultStep,
|
|
53
52
|
document: () => document,
|
|
54
53
|
evalCode: () => evalCode,
|
|
54
|
+
evaluateAttributeCondition: () => evaluateAttributeCondition,
|
|
55
|
+
evaluateTimeCondition: () => evaluateTimeCondition,
|
|
56
|
+
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
55
57
|
fetch: () => fetch,
|
|
56
58
|
formatDate: () => formatDate,
|
|
57
59
|
generateAutoStateColors: () => generateAutoStateColors,
|
|
@@ -868,17 +870,6 @@ var defaultContentConfig = {
|
|
|
868
870
|
autoStartRulesSetting: rulesSetting,
|
|
869
871
|
hideRulesSetting
|
|
870
872
|
};
|
|
871
|
-
var autoStartConditions = {
|
|
872
|
-
...defaultContentConfig,
|
|
873
|
-
enabledAutoStartRules: true,
|
|
874
|
-
autoStartRules: [
|
|
875
|
-
{
|
|
876
|
-
data: { excludes: [], includes: ["/*"] },
|
|
877
|
-
type: "current-page",
|
|
878
|
-
operators: "and"
|
|
879
|
-
}
|
|
880
|
-
]
|
|
881
|
-
};
|
|
882
873
|
var buildConfig = (config) => {
|
|
883
874
|
return {
|
|
884
875
|
...defaultContentConfig,
|
|
@@ -969,8 +960,63 @@ var getRandomColor = () => {
|
|
|
969
960
|
return colors[Math.floor(Math.random() * colors.length)];
|
|
970
961
|
};
|
|
971
962
|
|
|
972
|
-
// src/conditions.ts
|
|
963
|
+
// src/conditions/condition.ts
|
|
973
964
|
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
|
+
|
|
1019
|
+
// src/conditions/url.ts
|
|
974
1020
|
var parseUrl = (url) => {
|
|
975
1021
|
const urlPatterns = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
|
|
976
1022
|
if (!urlPatterns) {
|
|
@@ -1031,59 +1077,218 @@ var isMatchUrlPattern = (_url, includes, excludes) => {
|
|
|
1031
1077
|
}) : false;
|
|
1032
1078
|
return isMatchIncludesConditions && !isMatchExcludesConditions;
|
|
1033
1079
|
};
|
|
1034
|
-
var
|
|
1035
|
-
const {
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1080
|
+
var evaluateUrlCondition = (rules, url) => {
|
|
1081
|
+
const { excludes, includes } = rules.data;
|
|
1082
|
+
return isMatchUrlPattern(url, includes, excludes);
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
// src/conditions/time.ts
|
|
1086
|
+
var import_date_fns = require("date-fns");
|
|
1087
|
+
var evaluateTimeCondition = (rules) => {
|
|
1088
|
+
try {
|
|
1089
|
+
const { endDate, endDateHour, endDateMinute, startDate, startDateHour, startDateMinute } = rules.data || {};
|
|
1090
|
+
if (!startDate || !startDateHour || !startDateMinute) {
|
|
1091
|
+
return false;
|
|
1092
|
+
}
|
|
1093
|
+
const startTimeString = `${startDate}T${startDateHour.padStart(2, "0")}:${startDateMinute.padStart(2, "0")}:00`;
|
|
1094
|
+
const startTime = (0, import_date_fns.parseISO)(startTimeString);
|
|
1095
|
+
if (!(0, import_date_fns.isValid)(startTime)) {
|
|
1096
|
+
return false;
|
|
1097
|
+
}
|
|
1098
|
+
const now = /* @__PURE__ */ new Date();
|
|
1099
|
+
if (!endDate || !endDateHour || !endDateMinute) {
|
|
1100
|
+
return (0, import_date_fns.isAfter)(now, startTime);
|
|
1101
|
+
}
|
|
1102
|
+
const endTimeString = `${endDate}T${endDateHour.padStart(2, "0")}:${endDateMinute.padStart(2, "0")}:00`;
|
|
1103
|
+
const endTime = (0, import_date_fns.parseISO)(endTimeString);
|
|
1104
|
+
if (!(0, import_date_fns.isValid)(endTime)) {
|
|
1042
1105
|
return false;
|
|
1043
1106
|
}
|
|
1107
|
+
return (0, import_date_fns.isAfter)(now, startTime) && (0, import_date_fns.isBefore)(now, endTime);
|
|
1108
|
+
} catch {
|
|
1109
|
+
return false;
|
|
1044
1110
|
}
|
|
1045
|
-
return true;
|
|
1046
1111
|
};
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1112
|
+
|
|
1113
|
+
// src/conditions/attribute.ts
|
|
1114
|
+
var import_types4 = require("@usertour/types");
|
|
1115
|
+
var import_date_fns2 = require("date-fns");
|
|
1116
|
+
function evaluateAttributeCondition(condition, attributes, userAttributes) {
|
|
1117
|
+
const { data } = condition;
|
|
1118
|
+
if (!data) {
|
|
1119
|
+
return false;
|
|
1052
1120
|
}
|
|
1053
|
-
|
|
1121
|
+
const { logic, value, attrId, value2, listValues = [] } = data;
|
|
1122
|
+
if (!attrId) {
|
|
1054
1123
|
return false;
|
|
1055
1124
|
}
|
|
1056
|
-
const
|
|
1057
|
-
|
|
1058
|
-
if (group1.length !== group2.length) {
|
|
1125
|
+
const attr = attributes.find((attr2) => attr2.id === attrId);
|
|
1126
|
+
if (!attr) {
|
|
1059
1127
|
return false;
|
|
1060
1128
|
}
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1129
|
+
const actualValue = getAttributeValue(attr.codeName, userAttributes);
|
|
1130
|
+
if (attr.dataType === import_types4.BizAttributeTypes.String) {
|
|
1131
|
+
return evaluateStringCondition(logic, actualValue, value);
|
|
1132
|
+
}
|
|
1133
|
+
if (attr.dataType === import_types4.BizAttributeTypes.Number) {
|
|
1134
|
+
return evaluateNumberCondition(logic, actualValue, value, value2);
|
|
1135
|
+
}
|
|
1136
|
+
if (attr.dataType === import_types4.BizAttributeTypes.Boolean) {
|
|
1137
|
+
return evaluateBooleanCondition(logic, actualValue);
|
|
1138
|
+
}
|
|
1139
|
+
if (attr.dataType === import_types4.BizAttributeTypes.List) {
|
|
1140
|
+
return evaluateListCondition(logic, actualValue, listValues);
|
|
1141
|
+
}
|
|
1142
|
+
if (attr.dataType === import_types4.BizAttributeTypes.DateTime) {
|
|
1143
|
+
return evaluateDateTimeCondition(logic, actualValue, value);
|
|
1144
|
+
}
|
|
1145
|
+
return false;
|
|
1146
|
+
}
|
|
1147
|
+
function getAttributeValue(codeName, userAttributes) {
|
|
1148
|
+
return userAttributes == null ? void 0 : userAttributes[codeName];
|
|
1149
|
+
}
|
|
1150
|
+
function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
1151
|
+
const stringValue = actualValue === null || actualValue === void 0 ? "" : String(actualValue);
|
|
1152
|
+
switch (logic) {
|
|
1153
|
+
case "is":
|
|
1154
|
+
return stringValue === expectedValue;
|
|
1155
|
+
case "not":
|
|
1156
|
+
return stringValue !== expectedValue;
|
|
1157
|
+
case "contains":
|
|
1158
|
+
return stringValue.includes(expectedValue);
|
|
1159
|
+
case "notContain":
|
|
1160
|
+
return !stringValue.includes(expectedValue);
|
|
1161
|
+
case "startsWith":
|
|
1162
|
+
return stringValue.startsWith(expectedValue);
|
|
1163
|
+
case "endsWith":
|
|
1164
|
+
return stringValue.endsWith(expectedValue);
|
|
1165
|
+
case "empty": {
|
|
1166
|
+
const isEmpty = !stringValue || stringValue === "";
|
|
1167
|
+
return isEmpty;
|
|
1066
1168
|
}
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1169
|
+
case "any":
|
|
1170
|
+
return Boolean(stringValue && stringValue !== "");
|
|
1171
|
+
default:
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
|
|
1176
|
+
const numValue = Number(actualValue);
|
|
1177
|
+
const numValue2 = Number(expectedValue2);
|
|
1178
|
+
if (Number.isNaN(numValue)) {
|
|
1179
|
+
return false;
|
|
1180
|
+
}
|
|
1181
|
+
switch (logic) {
|
|
1182
|
+
case "is":
|
|
1183
|
+
return numValue === expectedValue;
|
|
1184
|
+
case "not":
|
|
1185
|
+
return numValue !== expectedValue;
|
|
1186
|
+
case "isLessThan":
|
|
1187
|
+
return numValue < expectedValue;
|
|
1188
|
+
case "isLessThanOrEqualTo":
|
|
1189
|
+
return numValue <= expectedValue;
|
|
1190
|
+
case "isGreaterThan":
|
|
1191
|
+
return numValue > expectedValue;
|
|
1192
|
+
case "isGreaterThanOrEqualTo":
|
|
1193
|
+
return numValue >= expectedValue;
|
|
1194
|
+
case "between":
|
|
1195
|
+
return numValue >= expectedValue && numValue <= numValue2;
|
|
1196
|
+
case "empty":
|
|
1197
|
+
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
1198
|
+
case "any":
|
|
1199
|
+
return actualValue !== null && actualValue !== void 0 && actualValue !== "";
|
|
1200
|
+
default:
|
|
1201
|
+
return false;
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
function evaluateBooleanCondition(logic, actualValue) {
|
|
1205
|
+
switch (logic) {
|
|
1206
|
+
case "true":
|
|
1207
|
+
return actualValue === true;
|
|
1208
|
+
case "false":
|
|
1209
|
+
return actualValue === false;
|
|
1210
|
+
case "empty":
|
|
1211
|
+
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
1212
|
+
case "any":
|
|
1213
|
+
return actualValue !== null && actualValue !== void 0 && actualValue !== "";
|
|
1214
|
+
default:
|
|
1215
|
+
return false;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
function evaluateListCondition(logic, actualValue, expectedValues) {
|
|
1219
|
+
const arrayValue = Array.isArray(actualValue) ? actualValue : [];
|
|
1220
|
+
if (logic === "empty" || logic === "any") {
|
|
1221
|
+
switch (logic) {
|
|
1222
|
+
case "empty":
|
|
1223
|
+
return !arrayValue || arrayValue.length === 0;
|
|
1224
|
+
case "any":
|
|
1225
|
+
return arrayValue && arrayValue.length > 0;
|
|
1226
|
+
default:
|
|
1081
1227
|
return false;
|
|
1082
|
-
}
|
|
1083
1228
|
}
|
|
1084
1229
|
}
|
|
1085
|
-
|
|
1086
|
-
|
|
1230
|
+
const filteredValues = expectedValues.filter(
|
|
1231
|
+
(value) => value !== null && value !== void 0 && value !== ""
|
|
1232
|
+
);
|
|
1233
|
+
if (!filteredValues.length) {
|
|
1234
|
+
return false;
|
|
1235
|
+
}
|
|
1236
|
+
switch (logic) {
|
|
1237
|
+
case "includesAtLeastOne":
|
|
1238
|
+
return filteredValues.some((value) => arrayValue.includes(value));
|
|
1239
|
+
case "includesAll":
|
|
1240
|
+
return filteredValues.every((value) => arrayValue.includes(value));
|
|
1241
|
+
case "notIncludesAtLeastOne":
|
|
1242
|
+
return !filteredValues.some((value) => arrayValue.includes(value));
|
|
1243
|
+
case "notIncludesAll":
|
|
1244
|
+
return !filteredValues.every((value) => arrayValue.includes(value));
|
|
1245
|
+
default:
|
|
1246
|
+
return false;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
1250
|
+
const actualDate = actualValue ? new Date(actualValue) : null;
|
|
1251
|
+
const now = /* @__PURE__ */ new Date();
|
|
1252
|
+
if (!actualDate || Number.isNaN(actualDate.getTime())) {
|
|
1253
|
+
return false;
|
|
1254
|
+
}
|
|
1255
|
+
switch (logic) {
|
|
1256
|
+
case "lessThan": {
|
|
1257
|
+
const targetDate = (0, import_date_fns2.subDays)(now, Number(expectedValue));
|
|
1258
|
+
return actualDate >= targetDate;
|
|
1259
|
+
}
|
|
1260
|
+
case "exactly": {
|
|
1261
|
+
const targetDate = (0, import_date_fns2.subDays)(now, Number(expectedValue));
|
|
1262
|
+
const start = (0, import_date_fns2.startOfDay)(targetDate);
|
|
1263
|
+
const end = (0, import_date_fns2.endOfDay)(targetDate);
|
|
1264
|
+
return actualDate >= start && actualDate <= end;
|
|
1265
|
+
}
|
|
1266
|
+
case "moreThan": {
|
|
1267
|
+
const targetDate = (0, import_date_fns2.subDays)(now, Number(expectedValue));
|
|
1268
|
+
return actualDate <= targetDate;
|
|
1269
|
+
}
|
|
1270
|
+
case "before": {
|
|
1271
|
+
const expectedDate = new Date(expectedValue);
|
|
1272
|
+
return actualDate <= expectedDate;
|
|
1273
|
+
}
|
|
1274
|
+
case "on": {
|
|
1275
|
+
const expectedDateOn = new Date(expectedValue);
|
|
1276
|
+
const start = (0, import_date_fns2.startOfDay)(expectedDateOn);
|
|
1277
|
+
const end = (0, import_date_fns2.endOfDay)(expectedDateOn);
|
|
1278
|
+
return actualDate >= start && actualDate <= end;
|
|
1279
|
+
}
|
|
1280
|
+
case "after": {
|
|
1281
|
+
const expectedDateAfter = new Date(expectedValue);
|
|
1282
|
+
return actualDate >= expectedDateAfter;
|
|
1283
|
+
}
|
|
1284
|
+
case "empty":
|
|
1285
|
+
return !actualValue || actualValue === "";
|
|
1286
|
+
case "any":
|
|
1287
|
+
return actualValue && actualValue !== "";
|
|
1288
|
+
default:
|
|
1289
|
+
return false;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1087
1292
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1088
1293
|
0 && (module.exports = {
|
|
1089
1294
|
AbortController,
|
|
@@ -1091,7 +1296,6 @@ var conditionsIsSame = (rr1, rr2) => {
|
|
|
1091
1296
|
XMLHttpRequest,
|
|
1092
1297
|
absoluteUrl,
|
|
1093
1298
|
assignableWindow,
|
|
1094
|
-
autoStartConditions,
|
|
1095
1299
|
buildConfig,
|
|
1096
1300
|
cn,
|
|
1097
1301
|
conditionsIsSame,
|
|
@@ -1103,6 +1307,9 @@ var conditionsIsSame = (rr1, rr2) => {
|
|
|
1103
1307
|
defaultStep,
|
|
1104
1308
|
document,
|
|
1105
1309
|
evalCode,
|
|
1310
|
+
evaluateAttributeCondition,
|
|
1311
|
+
evaluateTimeCondition,
|
|
1312
|
+
evaluateUrlCondition,
|
|
1106
1313
|
fetch,
|
|
1107
1314
|
formatDate,
|
|
1108
1315
|
generateAutoStateColors,
|
package/dist/index.d.cts
CHANGED
|
@@ -5,11 +5,14 @@ export { getAuthToken, removeAuthToken, setAuthToken, storage } from './auth.cjs
|
|
|
5
5
|
export { defaultStep } from './settings.cjs';
|
|
6
6
|
export { isUrl } from './is-url.cjs';
|
|
7
7
|
export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.cjs';
|
|
8
|
-
export {
|
|
8
|
+
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.cjs';
|
|
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
|
|
12
|
+
export { conditionsIsSame } from './conditions/condition.cjs';
|
|
13
|
+
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.cjs';
|
|
14
|
+
export { evaluateTimeCondition } from './conditions/time.cjs';
|
|
15
|
+
export { evaluateAttributeCondition } from './conditions/attribute.cjs';
|
|
13
16
|
export { default as isEqual } from 'fast-deep-equal';
|
|
14
17
|
import '@usertour/types';
|
|
15
18
|
import './storage.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,11 +5,14 @@ export { getAuthToken, removeAuthToken, setAuthToken, storage } from './auth.js'
|
|
|
5
5
|
export { defaultStep } from './settings.js';
|
|
6
6
|
export { isUrl } from './is-url.js';
|
|
7
7
|
export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.js';
|
|
8
|
-
export {
|
|
8
|
+
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.js';
|
|
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
|
|
12
|
+
export { conditionsIsSame } from './conditions/condition.js';
|
|
13
|
+
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.js';
|
|
14
|
+
export { evaluateTimeCondition } from './conditions/time.js';
|
|
15
|
+
export { evaluateAttributeCondition } from './conditions/attribute.js';
|
|
13
16
|
export { default as isEqual } from 'fast-deep-equal';
|
|
14
17
|
import '@usertour/types';
|
|
15
18
|
import './storage.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import "./chunk-7ODE2AIC.js";
|
|
2
|
+
import {
|
|
3
|
+
evaluateUrlCondition,
|
|
4
|
+
isMatchUrlPattern
|
|
5
|
+
} from "./chunk-BC7KXBMF.js";
|
|
1
6
|
import {
|
|
2
7
|
isUrl
|
|
3
8
|
} from "./chunk-ZNFXGN3M.js";
|
|
@@ -7,6 +12,16 @@ import {
|
|
|
7
12
|
import {
|
|
8
13
|
deepClone
|
|
9
14
|
} from "./chunk-2AEGAICC.js";
|
|
15
|
+
import {
|
|
16
|
+
evaluateAttributeCondition
|
|
17
|
+
} from "./chunk-PBZSPV5R.js";
|
|
18
|
+
import {
|
|
19
|
+
conditionsIsSame,
|
|
20
|
+
isEqual
|
|
21
|
+
} from "./chunk-YOFQHQ7D.js";
|
|
22
|
+
import {
|
|
23
|
+
evaluateTimeCondition
|
|
24
|
+
} from "./chunk-CEK3SCQO.js";
|
|
10
25
|
import {
|
|
11
26
|
getAuthToken,
|
|
12
27
|
removeAuthToken,
|
|
@@ -15,17 +30,11 @@ import {
|
|
|
15
30
|
} from "./chunk-FGFMTWFT.js";
|
|
16
31
|
import "./chunk-3ZGH3NRU.js";
|
|
17
32
|
import {
|
|
18
|
-
conditionsIsSame,
|
|
19
|
-
isEqual,
|
|
20
|
-
isMatchUrlPattern
|
|
21
|
-
} from "./chunk-IZFZYGPU.js";
|
|
22
|
-
import {
|
|
23
|
-
autoStartConditions,
|
|
24
33
|
buildConfig,
|
|
25
34
|
defaultContentConfig,
|
|
26
35
|
isPublishedAtLeastOneEnvironment,
|
|
27
36
|
isPublishedInAllEnvironments
|
|
28
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-4LLDSAHJ.js";
|
|
29
38
|
import {
|
|
30
39
|
convertSettings,
|
|
31
40
|
convertToCssVars,
|
|
@@ -104,7 +113,6 @@ export {
|
|
|
104
113
|
XMLHttpRequest,
|
|
105
114
|
absoluteUrl,
|
|
106
115
|
assignableWindow,
|
|
107
|
-
autoStartConditions,
|
|
108
116
|
buildConfig,
|
|
109
117
|
cn,
|
|
110
118
|
conditionsIsSame,
|
|
@@ -116,6 +124,9 @@ export {
|
|
|
116
124
|
defaultStep,
|
|
117
125
|
document,
|
|
118
126
|
evalCode,
|
|
127
|
+
evaluateAttributeCondition,
|
|
128
|
+
evaluateTimeCondition,
|
|
129
|
+
evaluateUrlCondition,
|
|
119
130
|
fetch,
|
|
120
131
|
formatDate,
|
|
121
132
|
generateAutoStateColors,
|