@usertour/helpers 0.0.26 → 0.0.27
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 +19 -19
- package/dist/__tests__/condition.test.js +1 -1
- package/dist/chunk-5C3J4DM2.js +58 -0
- package/dist/{chunk-CCL2GU2M.js → chunk-KQRO6BRK.js} +19 -19
- package/dist/conditions/condition.cjs +19 -19
- package/dist/conditions/condition.d.cts +1 -1
- package/dist/conditions/condition.d.ts +1 -1
- package/dist/conditions/condition.js +1 -1
- package/dist/conditions/index.cjs +19 -19
- package/dist/conditions/index.js +1 -1
- package/dist/index.cjs +66 -19
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +7 -3
- 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 +1 -1
- package/dist/chunk-2AEGAICC.js +0 -13
|
@@ -351,50 +351,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
351
351
|
return condition;
|
|
352
352
|
});
|
|
353
353
|
};
|
|
354
|
-
var evaluateRule = async (
|
|
354
|
+
var evaluateRule = async (condition, options) => {
|
|
355
355
|
var _a;
|
|
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, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
373
373
|
case import_types2.RulesType.TIME:
|
|
374
|
-
return evaluateTimeCondition(
|
|
374
|
+
return evaluateTimeCondition(condition);
|
|
375
375
|
case import_types2.RulesType.USER_ATTR:
|
|
376
376
|
case import_types2.RulesType.COMPANY_ATTR:
|
|
377
377
|
return evaluateAttributeCondition(
|
|
378
|
-
|
|
378
|
+
condition,
|
|
379
379
|
options.attributes || [],
|
|
380
380
|
options.userAttributes || {}
|
|
381
381
|
);
|
|
382
382
|
default:
|
|
383
|
-
return
|
|
383
|
+
return condition.actived || false;
|
|
384
384
|
}
|
|
385
385
|
};
|
|
386
386
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
387
387
|
const results = [];
|
|
388
|
-
for (const
|
|
389
|
-
if (
|
|
388
|
+
for (const condition of conditions) {
|
|
389
|
+
if (condition.type === "group" && condition.conditions) {
|
|
390
390
|
results.push({
|
|
391
|
-
...
|
|
392
|
-
conditions: await evaluateRulesConditions(
|
|
391
|
+
...condition,
|
|
392
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
393
393
|
});
|
|
394
394
|
} else {
|
|
395
395
|
results.push({
|
|
396
|
-
...
|
|
397
|
-
actived: await evaluateRule(
|
|
396
|
+
...condition,
|
|
397
|
+
actived: await evaluateRule(condition, options)
|
|
398
398
|
});
|
|
399
399
|
}
|
|
400
400
|
}
|
|
@@ -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
|
+
};
|
|
@@ -44,50 +44,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
44
44
|
return condition;
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
|
-
var evaluateRule = async (
|
|
47
|
+
var evaluateRule = async (condition, options) => {
|
|
48
48
|
var _a;
|
|
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, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
66
66
|
case RulesType.TIME:
|
|
67
|
-
return evaluateTimeCondition(
|
|
67
|
+
return evaluateTimeCondition(condition);
|
|
68
68
|
case RulesType.USER_ATTR:
|
|
69
69
|
case RulesType.COMPANY_ATTR:
|
|
70
70
|
return evaluateAttributeCondition(
|
|
71
|
-
|
|
71
|
+
condition,
|
|
72
72
|
options.attributes || [],
|
|
73
73
|
options.userAttributes || {}
|
|
74
74
|
);
|
|
75
75
|
default:
|
|
76
|
-
return
|
|
76
|
+
return condition.actived || false;
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
80
80
|
const results = [];
|
|
81
|
-
for (const
|
|
82
|
-
if (
|
|
81
|
+
for (const condition of conditions) {
|
|
82
|
+
if (condition.type === "group" && condition.conditions) {
|
|
83
83
|
results.push({
|
|
84
|
-
...
|
|
85
|
-
conditions: await evaluateRulesConditions(
|
|
84
|
+
...condition,
|
|
85
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
86
86
|
});
|
|
87
87
|
} else {
|
|
88
88
|
results.push({
|
|
89
|
-
...
|
|
90
|
-
actived: await evaluateRule(
|
|
89
|
+
...condition,
|
|
90
|
+
actived: await evaluateRule(condition, options)
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -366,50 +366,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
366
366
|
return condition;
|
|
367
367
|
});
|
|
368
368
|
};
|
|
369
|
-
var evaluateRule = async (
|
|
369
|
+
var evaluateRule = async (condition, options) => {
|
|
370
370
|
var _a;
|
|
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, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
388
388
|
case import_types2.RulesType.TIME:
|
|
389
|
-
return evaluateTimeCondition(
|
|
389
|
+
return evaluateTimeCondition(condition);
|
|
390
390
|
case import_types2.RulesType.USER_ATTR:
|
|
391
391
|
case import_types2.RulesType.COMPANY_ATTR:
|
|
392
392
|
return evaluateAttributeCondition(
|
|
393
|
-
|
|
393
|
+
condition,
|
|
394
394
|
options.attributes || [],
|
|
395
395
|
options.userAttributes || {}
|
|
396
396
|
);
|
|
397
397
|
default:
|
|
398
|
-
return
|
|
398
|
+
return condition.actived || false;
|
|
399
399
|
}
|
|
400
400
|
};
|
|
401
401
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
402
402
|
const results = [];
|
|
403
|
-
for (const
|
|
404
|
-
if (
|
|
403
|
+
for (const condition of conditions) {
|
|
404
|
+
if (condition.type === "group" && condition.conditions) {
|
|
405
405
|
results.push({
|
|
406
|
-
...
|
|
407
|
-
conditions: await evaluateRulesConditions(
|
|
406
|
+
...condition,
|
|
407
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
408
408
|
});
|
|
409
409
|
} else {
|
|
410
410
|
results.push({
|
|
411
|
-
...
|
|
412
|
-
actived: await evaluateRule(
|
|
411
|
+
...condition,
|
|
412
|
+
actived: await evaluateRule(condition, options)
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
415
|
}
|
|
@@ -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 };
|
|
@@ -372,50 +372,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
372
372
|
return condition;
|
|
373
373
|
});
|
|
374
374
|
};
|
|
375
|
-
var evaluateRule = async (
|
|
375
|
+
var evaluateRule = async (condition, options) => {
|
|
376
376
|
var _a;
|
|
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, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
394
394
|
case import_types2.RulesType.TIME:
|
|
395
|
-
return evaluateTimeCondition(
|
|
395
|
+
return evaluateTimeCondition(condition);
|
|
396
396
|
case import_types2.RulesType.USER_ATTR:
|
|
397
397
|
case import_types2.RulesType.COMPANY_ATTR:
|
|
398
398
|
return evaluateAttributeCondition(
|
|
399
|
-
|
|
399
|
+
condition,
|
|
400
400
|
options.attributes || [],
|
|
401
401
|
options.userAttributes || {}
|
|
402
402
|
);
|
|
403
403
|
default:
|
|
404
|
-
return
|
|
404
|
+
return condition.actived || false;
|
|
405
405
|
}
|
|
406
406
|
};
|
|
407
407
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
408
408
|
const results = [];
|
|
409
|
-
for (const
|
|
410
|
-
if (
|
|
409
|
+
for (const condition of conditions) {
|
|
410
|
+
if (condition.type === "group" && condition.conditions) {
|
|
411
411
|
results.push({
|
|
412
|
-
...
|
|
413
|
-
conditions: await evaluateRulesConditions(
|
|
412
|
+
...condition,
|
|
413
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
414
414
|
});
|
|
415
415
|
} else {
|
|
416
416
|
results.push({
|
|
417
|
-
...
|
|
418
|
-
actived: await evaluateRule(
|
|
417
|
+
...condition,
|
|
418
|
+
actived: await evaluateRule(condition, options)
|
|
419
419
|
});
|
|
420
420
|
}
|
|
421
421
|
}
|
package/dist/conditions/index.js
CHANGED
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,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
1293
1338
|
return condition;
|
|
1294
1339
|
});
|
|
1295
1340
|
};
|
|
1296
|
-
var evaluateRule = async (
|
|
1341
|
+
var evaluateRule = async (condition, options) => {
|
|
1297
1342
|
var _a;
|
|
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, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
1315
1360
|
case import_types5.RulesType.TIME:
|
|
1316
|
-
return evaluateTimeCondition(
|
|
1361
|
+
return evaluateTimeCondition(condition);
|
|
1317
1362
|
case import_types5.RulesType.USER_ATTR:
|
|
1318
1363
|
case import_types5.RulesType.COMPANY_ATTR:
|
|
1319
1364
|
return evaluateAttributeCondition(
|
|
1320
|
-
|
|
1365
|
+
condition,
|
|
1321
1366
|
options.attributes || [],
|
|
1322
1367
|
options.userAttributes || {}
|
|
1323
1368
|
);
|
|
1324
1369
|
default:
|
|
1325
|
-
return
|
|
1370
|
+
return condition.actived || false;
|
|
1326
1371
|
}
|
|
1327
1372
|
};
|
|
1328
1373
|
var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
1329
1374
|
const results = [];
|
|
1330
|
-
for (const
|
|
1331
|
-
if (
|
|
1375
|
+
for (const condition of conditions) {
|
|
1376
|
+
if (condition.type === "group" && condition.conditions) {
|
|
1332
1377
|
results.push({
|
|
1333
|
-
...
|
|
1334
|
-
conditions: await evaluateRulesConditions(
|
|
1378
|
+
...condition,
|
|
1379
|
+
conditions: await evaluateRulesConditions(condition.conditions, options)
|
|
1335
1380
|
});
|
|
1336
1381
|
} else {
|
|
1337
1382
|
results.push({
|
|
1338
|
-
...
|
|
1339
|
-
actived: await evaluateRule(
|
|
1383
|
+
...condition,
|
|
1384
|
+
actived: await evaluateRule(condition, options)
|
|
1340
1385
|
});
|
|
1341
1386
|
}
|
|
1342
1387
|
}
|
|
@@ -1418,10 +1463,12 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
1418
1463
|
nativeForEach,
|
|
1419
1464
|
nativeIndexOf,
|
|
1420
1465
|
navigator,
|
|
1466
|
+
parseUrlParams,
|
|
1421
1467
|
removeAuthToken,
|
|
1422
1468
|
setAuthToken,
|
|
1423
1469
|
storage,
|
|
1424
1470
|
userAgent,
|
|
1425
1471
|
uuidV4,
|
|
1472
|
+
wait,
|
|
1426
1473
|
window
|
|
1427
1474
|
});
|
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
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
defaultStep
|
|
7
7
|
} from "./chunk-FW54TSA3.js";
|
|
8
8
|
import {
|
|
9
|
-
deepClone
|
|
10
|
-
|
|
9
|
+
deepClone,
|
|
10
|
+
parseUrlParams,
|
|
11
|
+
wait
|
|
12
|
+
} from "./chunk-5C3J4DM2.js";
|
|
11
13
|
import {
|
|
12
14
|
conditionsIsSame,
|
|
13
15
|
evaluateRule,
|
|
@@ -15,7 +17,7 @@ import {
|
|
|
15
17
|
filterConditionsByType,
|
|
16
18
|
isConditionsActived,
|
|
17
19
|
isEqual
|
|
18
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-KQRO6BRK.js";
|
|
19
21
|
import {
|
|
20
22
|
evaluateUrlCondition,
|
|
21
23
|
isMatchUrlPattern
|
|
@@ -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
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
|
-
};
|