@usertour/helpers 0.0.26 → 0.0.28
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 +26 -27
- package/dist/__tests__/condition.test.js +8 -8
- package/dist/chunk-5C3J4DM2.js +58 -0
- package/dist/{chunk-CCL2GU2M.js → chunk-UGDTOUMM.js} +23 -24
- package/dist/conditions/condition.cjs +20 -21
- package/dist/conditions/condition.d.cts +1 -1
- package/dist/conditions/condition.d.ts +1 -1
- package/dist/conditions/condition.js +2 -2
- package/dist/conditions/index.cjs +20 -21
- package/dist/conditions/index.js +4 -4
- package/dist/index.cjs +67 -21
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +11 -7
- package/dist/utils.cjs +49 -2
- package/dist/utils.d.cts +3 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.js +7 -3
- package/package.json +2 -2
- package/dist/chunk-2AEGAICC.js +0 -13
|
@@ -351,50 +351,49 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
351
351
|
return condition;
|
|
352
352
|
});
|
|
353
353
|
};
|
|
354
|
-
var evaluateRule = async (
|
|
355
|
-
var _a;
|
|
354
|
+
var evaluateRule = async (condition, options) => {
|
|
355
|
+
var _a, _b;
|
|
356
356
|
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
357
|
-
const
|
|
358
|
-
if (activatedIds == null ? void 0 : activatedIds.includes(
|
|
357
|
+
const conditionId = condition.id;
|
|
358
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
|
|
359
359
|
return true;
|
|
360
|
-
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(
|
|
360
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
|
|
361
361
|
return false;
|
|
362
|
-
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[
|
|
362
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
|
|
363
363
|
if (customEvaluator) {
|
|
364
|
-
const result = customEvaluator(
|
|
364
|
+
const result = customEvaluator(condition, options);
|
|
365
365
|
return typeof result === "object" && result !== null && "then" in result ? await result : result;
|
|
366
366
|
}
|
|
367
|
-
if (typeControl[
|
|
368
|
-
return
|
|
367
|
+
if (typeControl[condition.type] !== true) {
|
|
368
|
+
return condition.actived || false;
|
|
369
369
|
}
|
|
370
|
-
switch (
|
|
370
|
+
switch (condition.type) {
|
|
371
371
|
case import_types2.RulesType.CURRENT_PAGE:
|
|
372
|
-
return evaluateUrlCondition(
|
|
372
|
+
return evaluateUrlCondition(condition, (_b = (_a = options.clientContext) == null ? void 0 : _a.pageUrl) != null ? _b : "");
|
|
373
373
|
case import_types2.RulesType.TIME:
|
|
374
|
-
return evaluateTimeCondition(
|
|
374
|
+
return evaluateTimeCondition(condition);
|
|
375
375
|
case import_types2.RulesType.USER_ATTR:
|
|
376
|
-
case import_types2.RulesType.COMPANY_ATTR:
|
|
377
376
|
return evaluateAttributeCondition(
|
|
378
|
-
|
|
377
|
+
condition,
|
|
379
378
|
options.attributes || [],
|
|
380
379
|
options.userAttributes || {}
|
|
381
380
|
);
|
|
382
381
|
default:
|
|
383
|
-
return
|
|
382
|
+
return condition.actived || false;
|
|
384
383
|
}
|
|
385
384
|
};
|
|
386
385
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
387
386
|
const results = [];
|
|
388
|
-
for (const
|
|
389
|
-
if (
|
|
387
|
+
for (const condition of conditions) {
|
|
388
|
+
if (condition.type === "group" && condition.conditions) {
|
|
390
389
|
results.push({
|
|
391
|
-
...
|
|
392
|
-
conditions: await evaluateRulesConditions(
|
|
390
|
+
...condition,
|
|
391
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
393
392
|
});
|
|
394
393
|
} else {
|
|
395
394
|
results.push({
|
|
396
|
-
...
|
|
397
|
-
actived: await evaluateRule(
|
|
395
|
+
...condition,
|
|
396
|
+
actived: await evaluateRule(condition, options)
|
|
398
397
|
});
|
|
399
398
|
}
|
|
400
399
|
}
|
|
@@ -642,9 +641,9 @@ describe("evaluateRulesConditions", () => {
|
|
|
642
641
|
];
|
|
643
642
|
const mockOptions = {
|
|
644
643
|
clientContext: {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
644
|
+
pageUrl: "https://example.com",
|
|
645
|
+
viewportWidth: 1920,
|
|
646
|
+
viewportHeight: 1080
|
|
648
647
|
},
|
|
649
648
|
attributes: [
|
|
650
649
|
{
|
|
@@ -1004,9 +1003,9 @@ describe("evaluateRulesConditions", () => {
|
|
|
1004
1003
|
};
|
|
1005
1004
|
const options = {
|
|
1006
1005
|
clientContext: {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1006
|
+
pageUrl: "https://example.com",
|
|
1007
|
+
viewportWidth: 1920,
|
|
1008
|
+
viewportHeight: 1080
|
|
1010
1009
|
},
|
|
1011
1010
|
typeControl: {
|
|
1012
1011
|
[import_types3.RulesType.CURRENT_PAGE]: true
|
|
@@ -2,11 +2,11 @@ import {
|
|
|
2
2
|
evaluateRulesConditions,
|
|
3
3
|
filterConditionsByType,
|
|
4
4
|
isConditionsActived
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-UGDTOUMM.js";
|
|
6
|
+
import "../chunk-CEK3SCQO.js";
|
|
6
7
|
import "../chunk-YYIGUZNZ.js";
|
|
7
8
|
import "../chunk-PAESAL23.js";
|
|
8
9
|
import "../chunk-PBZSPV5R.js";
|
|
9
|
-
import "../chunk-CEK3SCQO.js";
|
|
10
10
|
import "../chunk-XEO3YXBM.js";
|
|
11
11
|
|
|
12
12
|
// src/__tests__/condition.test.ts
|
|
@@ -251,9 +251,9 @@ describe("evaluateRulesConditions", () => {
|
|
|
251
251
|
];
|
|
252
252
|
const mockOptions = {
|
|
253
253
|
clientContext: {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
pageUrl: "https://example.com",
|
|
255
|
+
viewportWidth: 1920,
|
|
256
|
+
viewportHeight: 1080
|
|
257
257
|
},
|
|
258
258
|
attributes: [
|
|
259
259
|
{
|
|
@@ -613,9 +613,9 @@ describe("evaluateRulesConditions", () => {
|
|
|
613
613
|
};
|
|
614
614
|
const options = {
|
|
615
615
|
clientContext: {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
616
|
+
pageUrl: "https://example.com",
|
|
617
|
+
viewportWidth: 1920,
|
|
618
|
+
viewportHeight: 1080
|
|
619
619
|
},
|
|
620
620
|
typeControl: {
|
|
621
621
|
[RulesType.CURRENT_PAGE]: true
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
var deepClone = (obj) => {
|
|
3
|
+
try {
|
|
4
|
+
return structuredClone(obj);
|
|
5
|
+
} catch (error) {
|
|
6
|
+
console.warn("structuredClone failed, falling back to JSON method:", error);
|
|
7
|
+
return JSON.parse(JSON.stringify(obj));
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var parseUrlParams = (url, paramName) => {
|
|
11
|
+
if (!url || !paramName) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
const urlObj = new URL(url);
|
|
16
|
+
const searchParams = new URLSearchParams(urlObj.search);
|
|
17
|
+
if (searchParams.has(paramName)) {
|
|
18
|
+
return searchParams.get(paramName);
|
|
19
|
+
}
|
|
20
|
+
if (urlObj.hash) {
|
|
21
|
+
const hashSearch = urlObj.hash.split("?")[1];
|
|
22
|
+
if (hashSearch) {
|
|
23
|
+
const hashParams = new URLSearchParams(hashSearch);
|
|
24
|
+
if (hashParams.has(paramName)) {
|
|
25
|
+
return hashParams.get(paramName);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error("Error parsing URL:", error);
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var wait = (seconds) => {
|
|
36
|
+
if (typeof seconds !== "number" || Number.isNaN(seconds)) {
|
|
37
|
+
return Promise.reject(new Error("Invalid wait time: must be a number"));
|
|
38
|
+
}
|
|
39
|
+
if (seconds < 0) {
|
|
40
|
+
return Promise.reject(new Error("Invalid wait time: cannot be negative"));
|
|
41
|
+
}
|
|
42
|
+
if (seconds === 0) {
|
|
43
|
+
return Promise.resolve();
|
|
44
|
+
}
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
try {
|
|
47
|
+
setTimeout(resolve, seconds * 1e3);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
reject(error);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
deepClone,
|
|
56
|
+
parseUrlParams,
|
|
57
|
+
wait
|
|
58
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
evaluateTimeCondition
|
|
3
|
+
} from "./chunk-CEK3SCQO.js";
|
|
1
4
|
import {
|
|
2
5
|
evaluateUrlCondition
|
|
3
6
|
} from "./chunk-YYIGUZNZ.js";
|
|
4
7
|
import {
|
|
5
8
|
evaluateAttributeCondition
|
|
6
9
|
} from "./chunk-PBZSPV5R.js";
|
|
7
|
-
import {
|
|
8
|
-
evaluateTimeCondition
|
|
9
|
-
} from "./chunk-CEK3SCQO.js";
|
|
10
10
|
|
|
11
11
|
// src/conditions/condition.ts
|
|
12
12
|
import { RulesType } from "@usertour/types";
|
|
@@ -44,50 +44,49 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
44
44
|
return condition;
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
|
-
var evaluateRule = async (
|
|
48
|
-
var _a;
|
|
47
|
+
var evaluateRule = async (condition, options) => {
|
|
48
|
+
var _a, _b;
|
|
49
49
|
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
50
|
-
const
|
|
51
|
-
if (activatedIds == null ? void 0 : activatedIds.includes(
|
|
50
|
+
const conditionId = condition.id;
|
|
51
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
|
|
52
52
|
return true;
|
|
53
|
-
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(
|
|
53
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
|
|
54
54
|
return false;
|
|
55
|
-
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[
|
|
55
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
|
|
56
56
|
if (customEvaluator) {
|
|
57
|
-
const result = customEvaluator(
|
|
57
|
+
const result = customEvaluator(condition, options);
|
|
58
58
|
return typeof result === "object" && result !== null && "then" in result ? await result : result;
|
|
59
59
|
}
|
|
60
|
-
if (typeControl[
|
|
61
|
-
return
|
|
60
|
+
if (typeControl[condition.type] !== true) {
|
|
61
|
+
return condition.actived || false;
|
|
62
62
|
}
|
|
63
|
-
switch (
|
|
63
|
+
switch (condition.type) {
|
|
64
64
|
case RulesType.CURRENT_PAGE:
|
|
65
|
-
return evaluateUrlCondition(
|
|
65
|
+
return evaluateUrlCondition(condition, (_b = (_a = options.clientContext) == null ? void 0 : _a.pageUrl) != null ? _b : "");
|
|
66
66
|
case RulesType.TIME:
|
|
67
|
-
return evaluateTimeCondition(
|
|
67
|
+
return evaluateTimeCondition(condition);
|
|
68
68
|
case RulesType.USER_ATTR:
|
|
69
|
-
case RulesType.COMPANY_ATTR:
|
|
70
69
|
return evaluateAttributeCondition(
|
|
71
|
-
|
|
70
|
+
condition,
|
|
72
71
|
options.attributes || [],
|
|
73
72
|
options.userAttributes || {}
|
|
74
73
|
);
|
|
75
74
|
default:
|
|
76
|
-
return
|
|
75
|
+
return condition.actived || false;
|
|
77
76
|
}
|
|
78
77
|
};
|
|
79
78
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
80
79
|
const results = [];
|
|
81
|
-
for (const
|
|
82
|
-
if (
|
|
80
|
+
for (const condition of conditions) {
|
|
81
|
+
if (condition.type === "group" && condition.conditions) {
|
|
83
82
|
results.push({
|
|
84
|
-
...
|
|
85
|
-
conditions: await evaluateRulesConditions(
|
|
83
|
+
...condition,
|
|
84
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
86
85
|
});
|
|
87
86
|
} else {
|
|
88
87
|
results.push({
|
|
89
|
-
...
|
|
90
|
-
actived: await evaluateRule(
|
|
88
|
+
...condition,
|
|
89
|
+
actived: await evaluateRule(condition, options)
|
|
91
90
|
});
|
|
92
91
|
}
|
|
93
92
|
}
|
|
@@ -366,50 +366,49 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
366
366
|
return condition;
|
|
367
367
|
});
|
|
368
368
|
};
|
|
369
|
-
var evaluateRule = async (
|
|
370
|
-
var _a;
|
|
369
|
+
var evaluateRule = async (condition, options) => {
|
|
370
|
+
var _a, _b;
|
|
371
371
|
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
372
|
-
const
|
|
373
|
-
if (activatedIds == null ? void 0 : activatedIds.includes(
|
|
372
|
+
const conditionId = condition.id;
|
|
373
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
|
|
374
374
|
return true;
|
|
375
|
-
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(
|
|
375
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
|
|
376
376
|
return false;
|
|
377
|
-
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[
|
|
377
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
|
|
378
378
|
if (customEvaluator) {
|
|
379
|
-
const result = customEvaluator(
|
|
379
|
+
const result = customEvaluator(condition, options);
|
|
380
380
|
return typeof result === "object" && result !== null && "then" in result ? await result : result;
|
|
381
381
|
}
|
|
382
|
-
if (typeControl[
|
|
383
|
-
return
|
|
382
|
+
if (typeControl[condition.type] !== true) {
|
|
383
|
+
return condition.actived || false;
|
|
384
384
|
}
|
|
385
|
-
switch (
|
|
385
|
+
switch (condition.type) {
|
|
386
386
|
case import_types2.RulesType.CURRENT_PAGE:
|
|
387
|
-
return evaluateUrlCondition(
|
|
387
|
+
return evaluateUrlCondition(condition, (_b = (_a = options.clientContext) == null ? void 0 : _a.pageUrl) != null ? _b : "");
|
|
388
388
|
case import_types2.RulesType.TIME:
|
|
389
|
-
return evaluateTimeCondition(
|
|
389
|
+
return evaluateTimeCondition(condition);
|
|
390
390
|
case import_types2.RulesType.USER_ATTR:
|
|
391
|
-
case import_types2.RulesType.COMPANY_ATTR:
|
|
392
391
|
return evaluateAttributeCondition(
|
|
393
|
-
|
|
392
|
+
condition,
|
|
394
393
|
options.attributes || [],
|
|
395
394
|
options.userAttributes || {}
|
|
396
395
|
);
|
|
397
396
|
default:
|
|
398
|
-
return
|
|
397
|
+
return condition.actived || false;
|
|
399
398
|
}
|
|
400
399
|
};
|
|
401
400
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
402
401
|
const results = [];
|
|
403
|
-
for (const
|
|
404
|
-
if (
|
|
402
|
+
for (const condition of conditions) {
|
|
403
|
+
if (condition.type === "group" && condition.conditions) {
|
|
405
404
|
results.push({
|
|
406
|
-
...
|
|
407
|
-
conditions: await evaluateRulesConditions(
|
|
405
|
+
...condition,
|
|
406
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
408
407
|
});
|
|
409
408
|
} else {
|
|
410
409
|
results.push({
|
|
411
|
-
...
|
|
412
|
-
actived: await evaluateRule(
|
|
410
|
+
...condition,
|
|
411
|
+
actived: await evaluateRule(condition, options)
|
|
413
412
|
});
|
|
414
413
|
}
|
|
415
414
|
}
|
|
@@ -34,7 +34,7 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
|
|
|
34
34
|
* deactivatedIds: ['rule-3']
|
|
35
35
|
* });
|
|
36
36
|
*/
|
|
37
|
-
declare const evaluateRule: (
|
|
37
|
+
declare const evaluateRule: (condition: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
|
|
38
38
|
declare const evaluateRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => Promise<RulesCondition[]>;
|
|
39
39
|
|
|
40
40
|
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived };
|
|
@@ -34,7 +34,7 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
|
|
|
34
34
|
* deactivatedIds: ['rule-3']
|
|
35
35
|
* });
|
|
36
36
|
*/
|
|
37
|
-
declare const evaluateRule: (
|
|
37
|
+
declare const evaluateRule: (condition: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
|
|
38
38
|
declare const evaluateRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => Promise<RulesCondition[]>;
|
|
39
39
|
|
|
40
40
|
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived };
|
|
@@ -5,11 +5,11 @@ import {
|
|
|
5
5
|
filterConditionsByType,
|
|
6
6
|
isConditionsActived,
|
|
7
7
|
isEqual
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-UGDTOUMM.js";
|
|
9
|
+
import "../chunk-CEK3SCQO.js";
|
|
9
10
|
import "../chunk-YYIGUZNZ.js";
|
|
10
11
|
import "../chunk-PAESAL23.js";
|
|
11
12
|
import "../chunk-PBZSPV5R.js";
|
|
12
|
-
import "../chunk-CEK3SCQO.js";
|
|
13
13
|
import "../chunk-XEO3YXBM.js";
|
|
14
14
|
export {
|
|
15
15
|
conditionsIsSame,
|
|
@@ -372,50 +372,49 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
372
372
|
return condition;
|
|
373
373
|
});
|
|
374
374
|
};
|
|
375
|
-
var evaluateRule = async (
|
|
376
|
-
var _a;
|
|
375
|
+
var evaluateRule = async (condition, options) => {
|
|
376
|
+
var _a, _b;
|
|
377
377
|
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
378
|
-
const
|
|
379
|
-
if (activatedIds == null ? void 0 : activatedIds.includes(
|
|
378
|
+
const conditionId = condition.id;
|
|
379
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
|
|
380
380
|
return true;
|
|
381
|
-
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(
|
|
381
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
|
|
382
382
|
return false;
|
|
383
|
-
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[
|
|
383
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
|
|
384
384
|
if (customEvaluator) {
|
|
385
|
-
const result = customEvaluator(
|
|
385
|
+
const result = customEvaluator(condition, options);
|
|
386
386
|
return typeof result === "object" && result !== null && "then" in result ? await result : result;
|
|
387
387
|
}
|
|
388
|
-
if (typeControl[
|
|
389
|
-
return
|
|
388
|
+
if (typeControl[condition.type] !== true) {
|
|
389
|
+
return condition.actived || false;
|
|
390
390
|
}
|
|
391
|
-
switch (
|
|
391
|
+
switch (condition.type) {
|
|
392
392
|
case import_types2.RulesType.CURRENT_PAGE:
|
|
393
|
-
return evaluateUrlCondition(
|
|
393
|
+
return evaluateUrlCondition(condition, (_b = (_a = options.clientContext) == null ? void 0 : _a.pageUrl) != null ? _b : "");
|
|
394
394
|
case import_types2.RulesType.TIME:
|
|
395
|
-
return evaluateTimeCondition(
|
|
395
|
+
return evaluateTimeCondition(condition);
|
|
396
396
|
case import_types2.RulesType.USER_ATTR:
|
|
397
|
-
case import_types2.RulesType.COMPANY_ATTR:
|
|
398
397
|
return evaluateAttributeCondition(
|
|
399
|
-
|
|
398
|
+
condition,
|
|
400
399
|
options.attributes || [],
|
|
401
400
|
options.userAttributes || {}
|
|
402
401
|
);
|
|
403
402
|
default:
|
|
404
|
-
return
|
|
403
|
+
return condition.actived || false;
|
|
405
404
|
}
|
|
406
405
|
};
|
|
407
406
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
408
407
|
const results = [];
|
|
409
|
-
for (const
|
|
410
|
-
if (
|
|
408
|
+
for (const condition of conditions) {
|
|
409
|
+
if (condition.type === "group" && condition.conditions) {
|
|
411
410
|
results.push({
|
|
412
|
-
...
|
|
413
|
-
conditions: await evaluateRulesConditions(
|
|
411
|
+
...condition,
|
|
412
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
414
413
|
});
|
|
415
414
|
} else {
|
|
416
415
|
results.push({
|
|
417
|
-
...
|
|
418
|
-
actived: await evaluateRule(
|
|
416
|
+
...condition,
|
|
417
|
+
actived: await evaluateRule(condition, options)
|
|
419
418
|
});
|
|
420
419
|
}
|
|
421
420
|
}
|
package/dist/conditions/index.js
CHANGED
|
@@ -6,7 +6,10 @@ import {
|
|
|
6
6
|
filterConditionsByType,
|
|
7
7
|
isConditionsActived,
|
|
8
8
|
isEqual
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-UGDTOUMM.js";
|
|
10
|
+
import {
|
|
11
|
+
evaluateTimeCondition
|
|
12
|
+
} from "../chunk-CEK3SCQO.js";
|
|
10
13
|
import {
|
|
11
14
|
evaluateUrlCondition,
|
|
12
15
|
isMatchUrlPattern
|
|
@@ -15,9 +18,6 @@ import "../chunk-PAESAL23.js";
|
|
|
15
18
|
import {
|
|
16
19
|
evaluateAttributeCondition
|
|
17
20
|
} from "../chunk-PBZSPV5R.js";
|
|
18
|
-
import {
|
|
19
|
-
evaluateTimeCondition
|
|
20
|
-
} from "../chunk-CEK3SCQO.js";
|
|
21
21
|
import "../chunk-XEO3YXBM.js";
|
|
22
22
|
export {
|
|
23
23
|
conditionsIsSame,
|
package/dist/index.cjs
CHANGED
|
@@ -109,11 +109,13 @@ __export(src_exports, {
|
|
|
109
109
|
nativeForEach: () => nativeForEach,
|
|
110
110
|
nativeIndexOf: () => nativeIndexOf,
|
|
111
111
|
navigator: () => navigator,
|
|
112
|
+
parseUrlParams: () => parseUrlParams,
|
|
112
113
|
removeAuthToken: () => removeAuthToken,
|
|
113
114
|
setAuthToken: () => setAuthToken,
|
|
114
115
|
storage: () => storage,
|
|
115
116
|
userAgent: () => userAgent,
|
|
116
117
|
uuidV4: () => uuidV4,
|
|
118
|
+
wait: () => wait,
|
|
117
119
|
window: () => win
|
|
118
120
|
});
|
|
119
121
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -895,6 +897,49 @@ var deepClone = (obj) => {
|
|
|
895
897
|
return JSON.parse(JSON.stringify(obj));
|
|
896
898
|
}
|
|
897
899
|
};
|
|
900
|
+
var parseUrlParams = (url, paramName) => {
|
|
901
|
+
if (!url || !paramName) {
|
|
902
|
+
return null;
|
|
903
|
+
}
|
|
904
|
+
try {
|
|
905
|
+
const urlObj = new URL(url);
|
|
906
|
+
const searchParams = new URLSearchParams(urlObj.search);
|
|
907
|
+
if (searchParams.has(paramName)) {
|
|
908
|
+
return searchParams.get(paramName);
|
|
909
|
+
}
|
|
910
|
+
if (urlObj.hash) {
|
|
911
|
+
const hashSearch = urlObj.hash.split("?")[1];
|
|
912
|
+
if (hashSearch) {
|
|
913
|
+
const hashParams = new URLSearchParams(hashSearch);
|
|
914
|
+
if (hashParams.has(paramName)) {
|
|
915
|
+
return hashParams.get(paramName);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
return null;
|
|
920
|
+
} catch (error) {
|
|
921
|
+
console.error("Error parsing URL:", error);
|
|
922
|
+
return null;
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
var wait = (seconds) => {
|
|
926
|
+
if (typeof seconds !== "number" || Number.isNaN(seconds)) {
|
|
927
|
+
return Promise.reject(new Error("Invalid wait time: must be a number"));
|
|
928
|
+
}
|
|
929
|
+
if (seconds < 0) {
|
|
930
|
+
return Promise.reject(new Error("Invalid wait time: cannot be negative"));
|
|
931
|
+
}
|
|
932
|
+
if (seconds === 0) {
|
|
933
|
+
return Promise.resolve();
|
|
934
|
+
}
|
|
935
|
+
return new Promise((resolve, reject) => {
|
|
936
|
+
try {
|
|
937
|
+
setTimeout(resolve, seconds * 1e3);
|
|
938
|
+
} catch (error) {
|
|
939
|
+
reject(error);
|
|
940
|
+
}
|
|
941
|
+
});
|
|
942
|
+
};
|
|
898
943
|
|
|
899
944
|
// src/helper.ts
|
|
900
945
|
var import_clsx = require("clsx");
|
|
@@ -1293,50 +1338,49 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
1293
1338
|
return condition;
|
|
1294
1339
|
});
|
|
1295
1340
|
};
|
|
1296
|
-
var evaluateRule = async (
|
|
1297
|
-
var _a;
|
|
1341
|
+
var evaluateRule = async (condition, options) => {
|
|
1342
|
+
var _a, _b;
|
|
1298
1343
|
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
1299
|
-
const
|
|
1300
|
-
if (activatedIds == null ? void 0 : activatedIds.includes(
|
|
1344
|
+
const conditionId = condition.id;
|
|
1345
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
|
|
1301
1346
|
return true;
|
|
1302
|
-
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(
|
|
1347
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
|
|
1303
1348
|
return false;
|
|
1304
|
-
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[
|
|
1349
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
|
|
1305
1350
|
if (customEvaluator) {
|
|
1306
|
-
const result = customEvaluator(
|
|
1351
|
+
const result = customEvaluator(condition, options);
|
|
1307
1352
|
return typeof result === "object" && result !== null && "then" in result ? await result : result;
|
|
1308
1353
|
}
|
|
1309
|
-
if (typeControl[
|
|
1310
|
-
return
|
|
1354
|
+
if (typeControl[condition.type] !== true) {
|
|
1355
|
+
return condition.actived || false;
|
|
1311
1356
|
}
|
|
1312
|
-
switch (
|
|
1357
|
+
switch (condition.type) {
|
|
1313
1358
|
case import_types5.RulesType.CURRENT_PAGE:
|
|
1314
|
-
return evaluateUrlCondition(
|
|
1359
|
+
return evaluateUrlCondition(condition, (_b = (_a = options.clientContext) == null ? void 0 : _a.pageUrl) != null ? _b : "");
|
|
1315
1360
|
case import_types5.RulesType.TIME:
|
|
1316
|
-
return evaluateTimeCondition(
|
|
1361
|
+
return evaluateTimeCondition(condition);
|
|
1317
1362
|
case import_types5.RulesType.USER_ATTR:
|
|
1318
|
-
case import_types5.RulesType.COMPANY_ATTR:
|
|
1319
1363
|
return evaluateAttributeCondition(
|
|
1320
|
-
|
|
1364
|
+
condition,
|
|
1321
1365
|
options.attributes || [],
|
|
1322
1366
|
options.userAttributes || {}
|
|
1323
1367
|
);
|
|
1324
1368
|
default:
|
|
1325
|
-
return
|
|
1369
|
+
return condition.actived || false;
|
|
1326
1370
|
}
|
|
1327
1371
|
};
|
|
1328
1372
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
1329
1373
|
const results = [];
|
|
1330
|
-
for (const
|
|
1331
|
-
if (
|
|
1374
|
+
for (const condition of conditions) {
|
|
1375
|
+
if (condition.type === "group" && condition.conditions) {
|
|
1332
1376
|
results.push({
|
|
1333
|
-
...
|
|
1334
|
-
conditions: await evaluateRulesConditions(
|
|
1377
|
+
...condition,
|
|
1378
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
1335
1379
|
});
|
|
1336
1380
|
} else {
|
|
1337
1381
|
results.push({
|
|
1338
|
-
...
|
|
1339
|
-
actived: await evaluateRule(
|
|
1382
|
+
...condition,
|
|
1383
|
+
actived: await evaluateRule(condition, options)
|
|
1340
1384
|
});
|
|
1341
1385
|
}
|
|
1342
1386
|
}
|
|
@@ -1418,10 +1462,12 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
1418
1462
|
nativeForEach,
|
|
1419
1463
|
nativeIndexOf,
|
|
1420
1464
|
navigator,
|
|
1465
|
+
parseUrlParams,
|
|
1421
1466
|
removeAuthToken,
|
|
1422
1467
|
setAuthToken,
|
|
1423
1468
|
storage,
|
|
1424
1469
|
userAgent,
|
|
1425
1470
|
uuidV4,
|
|
1471
|
+
wait,
|
|
1426
1472
|
window
|
|
1427
1473
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -6,7 +6,7 @@ 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
8
|
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.cjs';
|
|
9
|
-
export { deepClone } from './utils.cjs';
|
|
9
|
+
export { deepClone, parseUrlParams, wait } 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
12
|
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './conditions/condition.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ 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
8
|
export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.js';
|
|
9
|
-
export { deepClone } from './utils.js';
|
|
9
|
+
export { deepClone, parseUrlParams, wait } 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
12
|
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './conditions/condition.js';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./chunk-7ODE2AIC.js";
|
|
2
1
|
import {
|
|
3
2
|
isUrl
|
|
4
3
|
} from "./chunk-ZNFXGN3M.js";
|
|
@@ -6,8 +5,11 @@ import {
|
|
|
6
5
|
defaultStep
|
|
7
6
|
} from "./chunk-FW54TSA3.js";
|
|
8
7
|
import {
|
|
9
|
-
deepClone
|
|
10
|
-
|
|
8
|
+
deepClone,
|
|
9
|
+
parseUrlParams,
|
|
10
|
+
wait
|
|
11
|
+
} from "./chunk-5C3J4DM2.js";
|
|
12
|
+
import "./chunk-7ODE2AIC.js";
|
|
11
13
|
import {
|
|
12
14
|
conditionsIsSame,
|
|
13
15
|
evaluateRule,
|
|
@@ -15,7 +17,10 @@ import {
|
|
|
15
17
|
filterConditionsByType,
|
|
16
18
|
isConditionsActived,
|
|
17
19
|
isEqual
|
|
18
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-UGDTOUMM.js";
|
|
21
|
+
import {
|
|
22
|
+
evaluateTimeCondition
|
|
23
|
+
} from "./chunk-CEK3SCQO.js";
|
|
19
24
|
import {
|
|
20
25
|
evaluateUrlCondition,
|
|
21
26
|
isMatchUrlPattern
|
|
@@ -24,9 +29,6 @@ import "./chunk-PAESAL23.js";
|
|
|
24
29
|
import {
|
|
25
30
|
evaluateAttributeCondition
|
|
26
31
|
} from "./chunk-PBZSPV5R.js";
|
|
27
|
-
import {
|
|
28
|
-
evaluateTimeCondition
|
|
29
|
-
} from "./chunk-CEK3SCQO.js";
|
|
30
32
|
import {
|
|
31
33
|
getAuthToken,
|
|
32
34
|
removeAuthToken,
|
|
@@ -187,10 +189,12 @@ export {
|
|
|
187
189
|
nativeForEach,
|
|
188
190
|
nativeIndexOf,
|
|
189
191
|
navigator,
|
|
192
|
+
parseUrlParams,
|
|
190
193
|
removeAuthToken,
|
|
191
194
|
setAuthToken,
|
|
192
195
|
storage,
|
|
193
196
|
userAgent,
|
|
194
197
|
uuidV4,
|
|
198
|
+
wait,
|
|
195
199
|
win as window
|
|
196
200
|
};
|
package/dist/utils.cjs
CHANGED
|
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/utils.ts
|
|
21
21
|
var utils_exports = {};
|
|
22
22
|
__export(utils_exports, {
|
|
23
|
-
deepClone: () => deepClone
|
|
23
|
+
deepClone: () => deepClone,
|
|
24
|
+
parseUrlParams: () => parseUrlParams,
|
|
25
|
+
wait: () => wait
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(utils_exports);
|
|
26
28
|
var deepClone = (obj) => {
|
|
@@ -31,7 +33,52 @@ var deepClone = (obj) => {
|
|
|
31
33
|
return JSON.parse(JSON.stringify(obj));
|
|
32
34
|
}
|
|
33
35
|
};
|
|
36
|
+
var parseUrlParams = (url, paramName) => {
|
|
37
|
+
if (!url || !paramName) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const urlObj = new URL(url);
|
|
42
|
+
const searchParams = new URLSearchParams(urlObj.search);
|
|
43
|
+
if (searchParams.has(paramName)) {
|
|
44
|
+
return searchParams.get(paramName);
|
|
45
|
+
}
|
|
46
|
+
if (urlObj.hash) {
|
|
47
|
+
const hashSearch = urlObj.hash.split("?")[1];
|
|
48
|
+
if (hashSearch) {
|
|
49
|
+
const hashParams = new URLSearchParams(hashSearch);
|
|
50
|
+
if (hashParams.has(paramName)) {
|
|
51
|
+
return hashParams.get(paramName);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error("Error parsing URL:", error);
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var wait = (seconds) => {
|
|
62
|
+
if (typeof seconds !== "number" || Number.isNaN(seconds)) {
|
|
63
|
+
return Promise.reject(new Error("Invalid wait time: must be a number"));
|
|
64
|
+
}
|
|
65
|
+
if (seconds < 0) {
|
|
66
|
+
return Promise.reject(new Error("Invalid wait time: cannot be negative"));
|
|
67
|
+
}
|
|
68
|
+
if (seconds === 0) {
|
|
69
|
+
return Promise.resolve();
|
|
70
|
+
}
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
try {
|
|
73
|
+
setTimeout(resolve, seconds * 1e3);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
reject(error);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
};
|
|
34
79
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
80
|
0 && (module.exports = {
|
|
36
|
-
deepClone
|
|
81
|
+
deepClone,
|
|
82
|
+
parseUrlParams,
|
|
83
|
+
wait
|
|
37
84
|
});
|
package/dist/utils.d.cts
CHANGED
|
@@ -4,5 +4,7 @@
|
|
|
4
4
|
* @returns A deep copy of the object
|
|
5
5
|
*/
|
|
6
6
|
declare const deepClone: <T>(obj: T) => T;
|
|
7
|
+
declare const parseUrlParams: (url: string, paramName: string) => string | null;
|
|
8
|
+
declare const wait: (seconds: number) => Promise<void>;
|
|
7
9
|
|
|
8
|
-
export { deepClone };
|
|
10
|
+
export { deepClone, parseUrlParams, wait };
|
package/dist/utils.d.ts
CHANGED
|
@@ -4,5 +4,7 @@
|
|
|
4
4
|
* @returns A deep copy of the object
|
|
5
5
|
*/
|
|
6
6
|
declare const deepClone: <T>(obj: T) => T;
|
|
7
|
+
declare const parseUrlParams: (url: string, paramName: string) => string | null;
|
|
8
|
+
declare const wait: (seconds: number) => Promise<void>;
|
|
7
9
|
|
|
8
|
-
export { deepClone };
|
|
10
|
+
export { deepClone, parseUrlParams, wait };
|
package/dist/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usertour/helpers",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
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.16",
|
|
33
33
|
"chroma-js": "^3.1.2",
|
|
34
34
|
"class-variance-authority": "^0.4.0",
|
|
35
35
|
"clsx": "^1.2.1",
|
package/dist/chunk-2AEGAICC.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
var deepClone = (obj) => {
|
|
3
|
-
try {
|
|
4
|
-
return structuredClone(obj);
|
|
5
|
-
} catch (error) {
|
|
6
|
-
console.warn("structuredClone failed, falling back to JSON method:", error);
|
|
7
|
-
return JSON.parse(JSON.stringify(obj));
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
deepClone
|
|
13
|
-
};
|