@usertour/helpers 0.0.25 → 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 +43 -43
- package/dist/__tests__/condition.test.js +25 -25
- package/dist/chunk-5C3J4DM2.js +58 -0
- package/dist/{chunk-4UMEUZN5.js → chunk-KQRO6BRK.js} +21 -21
- package/dist/conditions/condition.cjs +22 -22
- package/dist/conditions/condition.d.cts +4 -4
- package/dist/conditions/condition.d.ts +4 -4
- package/dist/conditions/condition.js +3 -3
- package/dist/conditions/index.cjs +22 -22
- package/dist/conditions/index.d.cts +1 -1
- package/dist/conditions/index.d.ts +1 -1
- package/dist/conditions/index.js +3 -3
- package/dist/index.cjs +69 -22
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -5
- 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
|
-
var
|
|
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
|
|
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
|
}
|
|
@@ -598,7 +598,7 @@ describe("isConditionsActived", () => {
|
|
|
598
598
|
expect(result).toBe(true);
|
|
599
599
|
});
|
|
600
600
|
});
|
|
601
|
-
describe("
|
|
601
|
+
describe("evaluateRulesConditions", () => {
|
|
602
602
|
const mockConditions = [
|
|
603
603
|
{
|
|
604
604
|
id: "rule-1",
|
|
@@ -675,13 +675,13 @@ describe("activedRulesConditions", () => {
|
|
|
675
675
|
data: {}
|
|
676
676
|
}
|
|
677
677
|
];
|
|
678
|
-
const result = await
|
|
678
|
+
const result = await evaluateRulesConditions(conditions);
|
|
679
679
|
expect(result).toHaveLength(2);
|
|
680
680
|
expect(result[0].actived).toBe(true);
|
|
681
681
|
expect(result[1].actived).toBe(false);
|
|
682
682
|
});
|
|
683
683
|
test("should disable all rule types by default when typeControl is empty", async () => {
|
|
684
|
-
const result = await
|
|
684
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
685
685
|
...mockOptions,
|
|
686
686
|
typeControl: {}
|
|
687
687
|
});
|
|
@@ -691,7 +691,7 @@ describe("activedRulesConditions", () => {
|
|
|
691
691
|
expect(result[3].actived).toBe(true);
|
|
692
692
|
});
|
|
693
693
|
test("should force activate rules by ID", async () => {
|
|
694
|
-
const result = await
|
|
694
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
695
695
|
...mockOptions,
|
|
696
696
|
activatedIds: ["rule-1", "rule-2"]
|
|
697
697
|
});
|
|
@@ -701,7 +701,7 @@ describe("activedRulesConditions", () => {
|
|
|
701
701
|
expect(result[3].actived).toBe(true);
|
|
702
702
|
});
|
|
703
703
|
test("should force deactivate rules by ID", async () => {
|
|
704
|
-
const result = await
|
|
704
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
705
705
|
...mockOptions,
|
|
706
706
|
deactivatedIds: ["rule-1", "rule-4"]
|
|
707
707
|
});
|
|
@@ -711,7 +711,7 @@ describe("activedRulesConditions", () => {
|
|
|
711
711
|
expect(result[3].actived).toBe(false);
|
|
712
712
|
});
|
|
713
713
|
test("should prioritize activatedIds over deactivatedIds", async () => {
|
|
714
|
-
const result = await
|
|
714
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
715
715
|
...mockOptions,
|
|
716
716
|
activatedIds: ["rule-1"],
|
|
717
717
|
deactivatedIds: ["rule-1"]
|
|
@@ -719,7 +719,7 @@ describe("activedRulesConditions", () => {
|
|
|
719
719
|
expect(result[0].actived).toBe(true);
|
|
720
720
|
});
|
|
721
721
|
test("should disable evaluation for specific rule types by default", async () => {
|
|
722
|
-
const result = await
|
|
722
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
723
723
|
...mockOptions,
|
|
724
724
|
typeControl: {
|
|
725
725
|
[import_types3.RulesType.CURRENT_PAGE]: false,
|
|
@@ -732,7 +732,7 @@ describe("activedRulesConditions", () => {
|
|
|
732
732
|
expect(result[3].actived).toBe(true);
|
|
733
733
|
});
|
|
734
734
|
test("should evaluate URL conditions correctly when enabled", async () => {
|
|
735
|
-
const result = await
|
|
735
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
736
736
|
...mockOptions,
|
|
737
737
|
typeControl: {
|
|
738
738
|
[import_types3.RulesType.CURRENT_PAGE]: true
|
|
@@ -741,7 +741,7 @@ describe("activedRulesConditions", () => {
|
|
|
741
741
|
expect(result[0].actived).toBe(false);
|
|
742
742
|
});
|
|
743
743
|
test("should evaluate time conditions correctly when enabled", async () => {
|
|
744
|
-
const result = await
|
|
744
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
745
745
|
...mockOptions,
|
|
746
746
|
typeControl: {
|
|
747
747
|
[import_types3.RulesType.TIME]: true
|
|
@@ -750,7 +750,7 @@ describe("activedRulesConditions", () => {
|
|
|
750
750
|
expect(typeof result[1].actived).toBe("boolean");
|
|
751
751
|
});
|
|
752
752
|
test("should evaluate attribute conditions correctly when enabled", async () => {
|
|
753
|
-
const result = await
|
|
753
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
754
754
|
...mockOptions,
|
|
755
755
|
typeControl: {
|
|
756
756
|
[import_types3.RulesType.USER_ATTR]: true
|
|
@@ -768,7 +768,7 @@ describe("activedRulesConditions", () => {
|
|
|
768
768
|
data: {}
|
|
769
769
|
}
|
|
770
770
|
];
|
|
771
|
-
const result = await
|
|
771
|
+
const result = await evaluateRulesConditions(conditions, {
|
|
772
772
|
activatedIds: ["non-existent"],
|
|
773
773
|
deactivatedIds: ["non-existent"]
|
|
774
774
|
});
|
|
@@ -803,7 +803,7 @@ describe("activedRulesConditions", () => {
|
|
|
803
803
|
]
|
|
804
804
|
}
|
|
805
805
|
];
|
|
806
|
-
const result = await
|
|
806
|
+
const result = await evaluateRulesConditions(nestedConditions, {
|
|
807
807
|
...mockOptions,
|
|
808
808
|
activatedIds: ["rule-1"]
|
|
809
809
|
});
|
|
@@ -843,14 +843,14 @@ describe("activedRulesConditions", () => {
|
|
|
843
843
|
]
|
|
844
844
|
}
|
|
845
845
|
];
|
|
846
|
-
const result = await
|
|
846
|
+
const result = await evaluateRulesConditions(deepNestedConditions, {
|
|
847
847
|
...mockOptions,
|
|
848
848
|
activatedIds: ["rule-1"]
|
|
849
849
|
});
|
|
850
850
|
expect(result[0].conditions[0].conditions[0].actived).toBe(true);
|
|
851
851
|
});
|
|
852
852
|
test("should handle empty conditions array", async () => {
|
|
853
|
-
const result = await
|
|
853
|
+
const result = await evaluateRulesConditions([]);
|
|
854
854
|
expect(result).toEqual([]);
|
|
855
855
|
});
|
|
856
856
|
test("should handle conditions with missing data", async () => {
|
|
@@ -863,7 +863,7 @@ describe("activedRulesConditions", () => {
|
|
|
863
863
|
data: void 0
|
|
864
864
|
}
|
|
865
865
|
];
|
|
866
|
-
const result = await
|
|
866
|
+
const result = await evaluateRulesConditions(conditions, mockOptions);
|
|
867
867
|
expect(result[0].actived).toBe(false);
|
|
868
868
|
});
|
|
869
869
|
test("should handle mixed rule types with different evaluation results when enabled", async () => {
|
|
@@ -897,7 +897,7 @@ describe("activedRulesConditions", () => {
|
|
|
897
897
|
data: {}
|
|
898
898
|
}
|
|
899
899
|
];
|
|
900
|
-
const result = await
|
|
900
|
+
const result = await evaluateRulesConditions(mixedConditions, {
|
|
901
901
|
...mockOptions,
|
|
902
902
|
typeControl: {
|
|
903
903
|
[import_types3.RulesType.CURRENT_PAGE]: true,
|
|
@@ -909,7 +909,7 @@ describe("activedRulesConditions", () => {
|
|
|
909
909
|
expect(result[2].actived).toBe(false);
|
|
910
910
|
});
|
|
911
911
|
test("should handle type control with partial configuration", async () => {
|
|
912
|
-
const result = await
|
|
912
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
913
913
|
...mockOptions,
|
|
914
914
|
typeControl: {
|
|
915
915
|
[import_types3.RulesType.CURRENT_PAGE]: false
|
|
@@ -922,7 +922,7 @@ describe("activedRulesConditions", () => {
|
|
|
922
922
|
expect(result[3].actived).toBe(true);
|
|
923
923
|
});
|
|
924
924
|
test("should enable evaluation for explicitly enabled rule types", async () => {
|
|
925
|
-
const result = await
|
|
925
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
926
926
|
...mockOptions,
|
|
927
927
|
typeControl: {
|
|
928
928
|
[import_types3.RulesType.CURRENT_PAGE]: true,
|
|
@@ -945,7 +945,7 @@ describe("activedRulesConditions", () => {
|
|
|
945
945
|
return false;
|
|
946
946
|
}
|
|
947
947
|
};
|
|
948
|
-
const result = await
|
|
948
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
949
949
|
...mockOptions,
|
|
950
950
|
typeControl: {
|
|
951
951
|
[import_types3.RulesType.CURRENT_PAGE]: true,
|
|
@@ -959,7 +959,7 @@ describe("activedRulesConditions", () => {
|
|
|
959
959
|
expect(result[3].actived).toBe(true);
|
|
960
960
|
});
|
|
961
961
|
test("should handle missing clientContext gracefully when enabled", async () => {
|
|
962
|
-
const result = await
|
|
962
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
963
963
|
attributes: mockOptions.attributes,
|
|
964
964
|
userAttributes: mockOptions.userAttributes,
|
|
965
965
|
typeControl: {
|
|
@@ -972,7 +972,7 @@ describe("activedRulesConditions", () => {
|
|
|
972
972
|
expect(typeof result[0].actived).toBe("boolean");
|
|
973
973
|
});
|
|
974
974
|
test("should handle missing attributes gracefully when enabled", async () => {
|
|
975
|
-
const result = await
|
|
975
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
976
976
|
clientContext: mockOptions.clientContext,
|
|
977
977
|
userAttributes: mockOptions.userAttributes,
|
|
978
978
|
typeControl: {
|
|
@@ -982,7 +982,7 @@ describe("activedRulesConditions", () => {
|
|
|
982
982
|
expect(result[2].actived).toBe(false);
|
|
983
983
|
});
|
|
984
984
|
test("should handle missing userAttributes gracefully when enabled", async () => {
|
|
985
|
-
const result = await
|
|
985
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
986
986
|
clientContext: mockOptions.clientContext,
|
|
987
987
|
attributes: mockOptions.attributes,
|
|
988
988
|
typeControl: {
|
|
@@ -1012,7 +1012,7 @@ describe("activedRulesConditions", () => {
|
|
|
1012
1012
|
[import_types3.RulesType.CURRENT_PAGE]: true
|
|
1013
1013
|
}
|
|
1014
1014
|
};
|
|
1015
|
-
const result = await
|
|
1015
|
+
const result = await evaluateRulesConditions([urlCondition], options);
|
|
1016
1016
|
expect(result[0].actived).toBe(false);
|
|
1017
1017
|
});
|
|
1018
1018
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
evaluateRulesConditions,
|
|
3
3
|
filterConditionsByType,
|
|
4
4
|
isConditionsActived
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-KQRO6BRK.js";
|
|
6
6
|
import "../chunk-YYIGUZNZ.js";
|
|
7
7
|
import "../chunk-PAESAL23.js";
|
|
8
8
|
import "../chunk-PBZSPV5R.js";
|
|
@@ -207,7 +207,7 @@ describe("isConditionsActived", () => {
|
|
|
207
207
|
expect(result).toBe(true);
|
|
208
208
|
});
|
|
209
209
|
});
|
|
210
|
-
describe("
|
|
210
|
+
describe("evaluateRulesConditions", () => {
|
|
211
211
|
const mockConditions = [
|
|
212
212
|
{
|
|
213
213
|
id: "rule-1",
|
|
@@ -284,13 +284,13 @@ describe("activedRulesConditions", () => {
|
|
|
284
284
|
data: {}
|
|
285
285
|
}
|
|
286
286
|
];
|
|
287
|
-
const result = await
|
|
287
|
+
const result = await evaluateRulesConditions(conditions);
|
|
288
288
|
expect(result).toHaveLength(2);
|
|
289
289
|
expect(result[0].actived).toBe(true);
|
|
290
290
|
expect(result[1].actived).toBe(false);
|
|
291
291
|
});
|
|
292
292
|
test("should disable all rule types by default when typeControl is empty", async () => {
|
|
293
|
-
const result = await
|
|
293
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
294
294
|
...mockOptions,
|
|
295
295
|
typeControl: {}
|
|
296
296
|
});
|
|
@@ -300,7 +300,7 @@ describe("activedRulesConditions", () => {
|
|
|
300
300
|
expect(result[3].actived).toBe(true);
|
|
301
301
|
});
|
|
302
302
|
test("should force activate rules by ID", async () => {
|
|
303
|
-
const result = await
|
|
303
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
304
304
|
...mockOptions,
|
|
305
305
|
activatedIds: ["rule-1", "rule-2"]
|
|
306
306
|
});
|
|
@@ -310,7 +310,7 @@ describe("activedRulesConditions", () => {
|
|
|
310
310
|
expect(result[3].actived).toBe(true);
|
|
311
311
|
});
|
|
312
312
|
test("should force deactivate rules by ID", async () => {
|
|
313
|
-
const result = await
|
|
313
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
314
314
|
...mockOptions,
|
|
315
315
|
deactivatedIds: ["rule-1", "rule-4"]
|
|
316
316
|
});
|
|
@@ -320,7 +320,7 @@ describe("activedRulesConditions", () => {
|
|
|
320
320
|
expect(result[3].actived).toBe(false);
|
|
321
321
|
});
|
|
322
322
|
test("should prioritize activatedIds over deactivatedIds", async () => {
|
|
323
|
-
const result = await
|
|
323
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
324
324
|
...mockOptions,
|
|
325
325
|
activatedIds: ["rule-1"],
|
|
326
326
|
deactivatedIds: ["rule-1"]
|
|
@@ -328,7 +328,7 @@ describe("activedRulesConditions", () => {
|
|
|
328
328
|
expect(result[0].actived).toBe(true);
|
|
329
329
|
});
|
|
330
330
|
test("should disable evaluation for specific rule types by default", async () => {
|
|
331
|
-
const result = await
|
|
331
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
332
332
|
...mockOptions,
|
|
333
333
|
typeControl: {
|
|
334
334
|
[RulesType.CURRENT_PAGE]: false,
|
|
@@ -341,7 +341,7 @@ describe("activedRulesConditions", () => {
|
|
|
341
341
|
expect(result[3].actived).toBe(true);
|
|
342
342
|
});
|
|
343
343
|
test("should evaluate URL conditions correctly when enabled", async () => {
|
|
344
|
-
const result = await
|
|
344
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
345
345
|
...mockOptions,
|
|
346
346
|
typeControl: {
|
|
347
347
|
[RulesType.CURRENT_PAGE]: true
|
|
@@ -350,7 +350,7 @@ describe("activedRulesConditions", () => {
|
|
|
350
350
|
expect(result[0].actived).toBe(false);
|
|
351
351
|
});
|
|
352
352
|
test("should evaluate time conditions correctly when enabled", async () => {
|
|
353
|
-
const result = await
|
|
353
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
354
354
|
...mockOptions,
|
|
355
355
|
typeControl: {
|
|
356
356
|
[RulesType.TIME]: true
|
|
@@ -359,7 +359,7 @@ describe("activedRulesConditions", () => {
|
|
|
359
359
|
expect(typeof result[1].actived).toBe("boolean");
|
|
360
360
|
});
|
|
361
361
|
test("should evaluate attribute conditions correctly when enabled", async () => {
|
|
362
|
-
const result = await
|
|
362
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
363
363
|
...mockOptions,
|
|
364
364
|
typeControl: {
|
|
365
365
|
[RulesType.USER_ATTR]: true
|
|
@@ -377,7 +377,7 @@ describe("activedRulesConditions", () => {
|
|
|
377
377
|
data: {}
|
|
378
378
|
}
|
|
379
379
|
];
|
|
380
|
-
const result = await
|
|
380
|
+
const result = await evaluateRulesConditions(conditions, {
|
|
381
381
|
activatedIds: ["non-existent"],
|
|
382
382
|
deactivatedIds: ["non-existent"]
|
|
383
383
|
});
|
|
@@ -412,7 +412,7 @@ describe("activedRulesConditions", () => {
|
|
|
412
412
|
]
|
|
413
413
|
}
|
|
414
414
|
];
|
|
415
|
-
const result = await
|
|
415
|
+
const result = await evaluateRulesConditions(nestedConditions, {
|
|
416
416
|
...mockOptions,
|
|
417
417
|
activatedIds: ["rule-1"]
|
|
418
418
|
});
|
|
@@ -452,14 +452,14 @@ describe("activedRulesConditions", () => {
|
|
|
452
452
|
]
|
|
453
453
|
}
|
|
454
454
|
];
|
|
455
|
-
const result = await
|
|
455
|
+
const result = await evaluateRulesConditions(deepNestedConditions, {
|
|
456
456
|
...mockOptions,
|
|
457
457
|
activatedIds: ["rule-1"]
|
|
458
458
|
});
|
|
459
459
|
expect(result[0].conditions[0].conditions[0].actived).toBe(true);
|
|
460
460
|
});
|
|
461
461
|
test("should handle empty conditions array", async () => {
|
|
462
|
-
const result = await
|
|
462
|
+
const result = await evaluateRulesConditions([]);
|
|
463
463
|
expect(result).toEqual([]);
|
|
464
464
|
});
|
|
465
465
|
test("should handle conditions with missing data", async () => {
|
|
@@ -472,7 +472,7 @@ describe("activedRulesConditions", () => {
|
|
|
472
472
|
data: void 0
|
|
473
473
|
}
|
|
474
474
|
];
|
|
475
|
-
const result = await
|
|
475
|
+
const result = await evaluateRulesConditions(conditions, mockOptions);
|
|
476
476
|
expect(result[0].actived).toBe(false);
|
|
477
477
|
});
|
|
478
478
|
test("should handle mixed rule types with different evaluation results when enabled", async () => {
|
|
@@ -506,7 +506,7 @@ describe("activedRulesConditions", () => {
|
|
|
506
506
|
data: {}
|
|
507
507
|
}
|
|
508
508
|
];
|
|
509
|
-
const result = await
|
|
509
|
+
const result = await evaluateRulesConditions(mixedConditions, {
|
|
510
510
|
...mockOptions,
|
|
511
511
|
typeControl: {
|
|
512
512
|
[RulesType.CURRENT_PAGE]: true,
|
|
@@ -518,7 +518,7 @@ describe("activedRulesConditions", () => {
|
|
|
518
518
|
expect(result[2].actived).toBe(false);
|
|
519
519
|
});
|
|
520
520
|
test("should handle type control with partial configuration", async () => {
|
|
521
|
-
const result = await
|
|
521
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
522
522
|
...mockOptions,
|
|
523
523
|
typeControl: {
|
|
524
524
|
[RulesType.CURRENT_PAGE]: false
|
|
@@ -531,7 +531,7 @@ describe("activedRulesConditions", () => {
|
|
|
531
531
|
expect(result[3].actived).toBe(true);
|
|
532
532
|
});
|
|
533
533
|
test("should enable evaluation for explicitly enabled rule types", async () => {
|
|
534
|
-
const result = await
|
|
534
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
535
535
|
...mockOptions,
|
|
536
536
|
typeControl: {
|
|
537
537
|
[RulesType.CURRENT_PAGE]: true,
|
|
@@ -554,7 +554,7 @@ describe("activedRulesConditions", () => {
|
|
|
554
554
|
return false;
|
|
555
555
|
}
|
|
556
556
|
};
|
|
557
|
-
const result = await
|
|
557
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
558
558
|
...mockOptions,
|
|
559
559
|
typeControl: {
|
|
560
560
|
[RulesType.CURRENT_PAGE]: true,
|
|
@@ -568,7 +568,7 @@ describe("activedRulesConditions", () => {
|
|
|
568
568
|
expect(result[3].actived).toBe(true);
|
|
569
569
|
});
|
|
570
570
|
test("should handle missing clientContext gracefully when enabled", async () => {
|
|
571
|
-
const result = await
|
|
571
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
572
572
|
attributes: mockOptions.attributes,
|
|
573
573
|
userAttributes: mockOptions.userAttributes,
|
|
574
574
|
typeControl: {
|
|
@@ -581,7 +581,7 @@ describe("activedRulesConditions", () => {
|
|
|
581
581
|
expect(typeof result[0].actived).toBe("boolean");
|
|
582
582
|
});
|
|
583
583
|
test("should handle missing attributes gracefully when enabled", async () => {
|
|
584
|
-
const result = await
|
|
584
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
585
585
|
clientContext: mockOptions.clientContext,
|
|
586
586
|
userAttributes: mockOptions.userAttributes,
|
|
587
587
|
typeControl: {
|
|
@@ -591,7 +591,7 @@ describe("activedRulesConditions", () => {
|
|
|
591
591
|
expect(result[2].actived).toBe(false);
|
|
592
592
|
});
|
|
593
593
|
test("should handle missing userAttributes gracefully when enabled", async () => {
|
|
594
|
-
const result = await
|
|
594
|
+
const result = await evaluateRulesConditions(mockConditions, {
|
|
595
595
|
clientContext: mockOptions.clientContext,
|
|
596
596
|
attributes: mockOptions.attributes,
|
|
597
597
|
typeControl: {
|
|
@@ -621,7 +621,7 @@ describe("activedRulesConditions", () => {
|
|
|
621
621
|
[RulesType.CURRENT_PAGE]: true
|
|
622
622
|
}
|
|
623
623
|
};
|
|
624
|
-
const result = await
|
|
624
|
+
const result = await evaluateRulesConditions([urlCondition], options);
|
|
625
625
|
expect(result[0].actived).toBe(false);
|
|
626
626
|
});
|
|
627
627
|
});
|
|
@@ -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
|
-
var
|
|
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
|
|
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
|
}
|
|
@@ -100,5 +100,5 @@ export {
|
|
|
100
100
|
isConditionsActived,
|
|
101
101
|
filterConditionsByType,
|
|
102
102
|
evaluateRule,
|
|
103
|
-
|
|
103
|
+
evaluateRulesConditions
|
|
104
104
|
};
|
|
@@ -30,9 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/conditions/condition.ts
|
|
31
31
|
var condition_exports = {};
|
|
32
32
|
__export(condition_exports, {
|
|
33
|
-
activedRulesConditions: () => activedRulesConditions,
|
|
34
33
|
conditionsIsSame: () => conditionsIsSame,
|
|
35
34
|
evaluateRule: () => evaluateRule,
|
|
35
|
+
evaluateRulesConditions: () => evaluateRulesConditions,
|
|
36
36
|
filterConditionsByType: () => filterConditionsByType,
|
|
37
37
|
isConditionsActived: () => isConditionsActived,
|
|
38
38
|
isEqual: () => import_fast_deep_equal.default
|
|
@@ -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
|
-
var
|
|
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
|
|
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
|
}
|
|
@@ -417,9 +417,9 @@ var activedRulesConditions = async (conditions, options = {}) => {
|
|
|
417
417
|
};
|
|
418
418
|
// Annotate the CommonJS export names for ESM import in node:
|
|
419
419
|
0 && (module.exports = {
|
|
420
|
-
activedRulesConditions,
|
|
421
420
|
conditionsIsSame,
|
|
422
421
|
evaluateRule,
|
|
422
|
+
evaluateRulesConditions,
|
|
423
423
|
filterConditionsByType,
|
|
424
424
|
isConditionsActived,
|
|
425
425
|
isEqual
|
|
@@ -17,7 +17,7 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
|
|
|
17
17
|
* @param options - Evaluation options including context, type control, and ID overrides
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* const result = await
|
|
20
|
+
* const result = await evaluateRulesConditions(conditions, {
|
|
21
21
|
* clientContext: {
|
|
22
22
|
* page_url: 'https://example.com',
|
|
23
23
|
* viewport_width: 1920,
|
|
@@ -34,7 +34,7 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
|
|
|
34
34
|
* deactivatedIds: ['rule-3']
|
|
35
35
|
* });
|
|
36
36
|
*/
|
|
37
|
-
declare const evaluateRule: (
|
|
38
|
-
declare const
|
|
37
|
+
declare const evaluateRule: (condition: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
|
|
38
|
+
declare const evaluateRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => Promise<RulesCondition[]>;
|
|
39
39
|
|
|
40
|
-
export {
|
|
40
|
+
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived };
|
|
@@ -17,7 +17,7 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
|
|
|
17
17
|
* @param options - Evaluation options including context, type control, and ID overrides
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
|
-
* const result = await
|
|
20
|
+
* const result = await evaluateRulesConditions(conditions, {
|
|
21
21
|
* clientContext: {
|
|
22
22
|
* page_url: 'https://example.com',
|
|
23
23
|
* viewport_width: 1920,
|
|
@@ -34,7 +34,7 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
|
|
|
34
34
|
* deactivatedIds: ['rule-3']
|
|
35
35
|
* });
|
|
36
36
|
*/
|
|
37
|
-
declare const evaluateRule: (
|
|
38
|
-
declare const
|
|
37
|
+
declare const evaluateRule: (condition: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
|
|
38
|
+
declare const evaluateRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => Promise<RulesCondition[]>;
|
|
39
39
|
|
|
40
|
-
export {
|
|
40
|
+
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived };
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
|
-
activedRulesConditions,
|
|
3
2
|
conditionsIsSame,
|
|
4
3
|
evaluateRule,
|
|
4
|
+
evaluateRulesConditions,
|
|
5
5
|
filterConditionsByType,
|
|
6
6
|
isConditionsActived,
|
|
7
7
|
isEqual
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-KQRO6BRK.js";
|
|
9
9
|
import "../chunk-YYIGUZNZ.js";
|
|
10
10
|
import "../chunk-PAESAL23.js";
|
|
11
11
|
import "../chunk-PBZSPV5R.js";
|
|
12
12
|
import "../chunk-CEK3SCQO.js";
|
|
13
13
|
import "../chunk-XEO3YXBM.js";
|
|
14
14
|
export {
|
|
15
|
-
activedRulesConditions,
|
|
16
15
|
conditionsIsSame,
|
|
17
16
|
evaluateRule,
|
|
17
|
+
evaluateRulesConditions,
|
|
18
18
|
filterConditionsByType,
|
|
19
19
|
isConditionsActived,
|
|
20
20
|
isEqual
|
|
@@ -30,10 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/conditions/index.ts
|
|
31
31
|
var conditions_exports = {};
|
|
32
32
|
__export(conditions_exports, {
|
|
33
|
-
activedRulesConditions: () => activedRulesConditions,
|
|
34
33
|
conditionsIsSame: () => conditionsIsSame,
|
|
35
34
|
evaluateAttributeCondition: () => evaluateAttributeCondition,
|
|
36
35
|
evaluateRule: () => evaluateRule,
|
|
36
|
+
evaluateRulesConditions: () => evaluateRulesConditions,
|
|
37
37
|
evaluateTimeCondition: () => evaluateTimeCondition,
|
|
38
38
|
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
39
39
|
filterConditionsByType: () => filterConditionsByType,
|
|
@@ -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
|
-
var
|
|
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
|
|
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
|
}
|
|
@@ -423,10 +423,10 @@ var activedRulesConditions = async (conditions, options = {}) => {
|
|
|
423
423
|
};
|
|
424
424
|
// Annotate the CommonJS export names for ESM import in node:
|
|
425
425
|
0 && (module.exports = {
|
|
426
|
-
activedRulesConditions,
|
|
427
426
|
conditionsIsSame,
|
|
428
427
|
evaluateAttributeCondition,
|
|
429
428
|
evaluateRule,
|
|
429
|
+
evaluateRulesConditions,
|
|
430
430
|
evaluateTimeCondition,
|
|
431
431
|
evaluateUrlCondition,
|
|
432
432
|
filterConditionsByType,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './condition.cjs';
|
|
2
2
|
export { evaluateUrlCondition, isMatchUrlPattern } from './url.cjs';
|
|
3
3
|
export { evaluateTimeCondition } from './time.cjs';
|
|
4
4
|
export { evaluateAttributeCondition } from './attribute.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './condition.js';
|
|
2
2
|
export { evaluateUrlCondition, isMatchUrlPattern } from './url.js';
|
|
3
3
|
export { evaluateTimeCondition } from './time.js';
|
|
4
4
|
export { evaluateAttributeCondition } from './attribute.js';
|
package/dist/conditions/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import "../chunk-7ODE2AIC.js";
|
|
2
2
|
import {
|
|
3
|
-
activedRulesConditions,
|
|
4
3
|
conditionsIsSame,
|
|
5
4
|
evaluateRule,
|
|
5
|
+
evaluateRulesConditions,
|
|
6
6
|
filterConditionsByType,
|
|
7
7
|
isConditionsActived,
|
|
8
8
|
isEqual
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-KQRO6BRK.js";
|
|
10
10
|
import {
|
|
11
11
|
evaluateUrlCondition,
|
|
12
12
|
isMatchUrlPattern
|
|
@@ -20,10 +20,10 @@ import {
|
|
|
20
20
|
} from "../chunk-CEK3SCQO.js";
|
|
21
21
|
import "../chunk-XEO3YXBM.js";
|
|
22
22
|
export {
|
|
23
|
-
activedRulesConditions,
|
|
24
23
|
conditionsIsSame,
|
|
25
24
|
evaluateAttributeCondition,
|
|
26
25
|
evaluateRule,
|
|
26
|
+
evaluateRulesConditions,
|
|
27
27
|
evaluateTimeCondition,
|
|
28
28
|
evaluateUrlCondition,
|
|
29
29
|
filterConditionsByType,
|
package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,6 @@ __export(src_exports, {
|
|
|
39
39
|
ArrayProto: () => ArrayProto,
|
|
40
40
|
XMLHttpRequest: () => XMLHttpRequest,
|
|
41
41
|
absoluteUrl: () => absoluteUrl,
|
|
42
|
-
activedRulesConditions: () => activedRulesConditions,
|
|
43
42
|
assignableWindow: () => assignableWindow,
|
|
44
43
|
buildConfig: () => buildConfig,
|
|
45
44
|
cn: () => cn,
|
|
@@ -54,6 +53,7 @@ __export(src_exports, {
|
|
|
54
53
|
evalCode: () => evalCode,
|
|
55
54
|
evaluateAttributeCondition: () => evaluateAttributeCondition,
|
|
56
55
|
evaluateRule: () => evaluateRule,
|
|
56
|
+
evaluateRulesConditions: () => evaluateRulesConditions,
|
|
57
57
|
evaluateTimeCondition: () => evaluateTimeCondition,
|
|
58
58
|
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
59
59
|
fetch: () => fetch,
|
|
@@ -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
|
-
var
|
|
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
|
|
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
|
}
|
|
@@ -1348,7 +1393,6 @@ var activedRulesConditions = async (conditions, options = {}) => {
|
|
|
1348
1393
|
ArrayProto,
|
|
1349
1394
|
XMLHttpRequest,
|
|
1350
1395
|
absoluteUrl,
|
|
1351
|
-
activedRulesConditions,
|
|
1352
1396
|
assignableWindow,
|
|
1353
1397
|
buildConfig,
|
|
1354
1398
|
cn,
|
|
@@ -1363,6 +1407,7 @@ var activedRulesConditions = async (conditions, options = {}) => {
|
|
|
1363
1407
|
evalCode,
|
|
1364
1408
|
evaluateAttributeCondition,
|
|
1365
1409
|
evaluateRule,
|
|
1410
|
+
evaluateRulesConditions,
|
|
1366
1411
|
evaluateTimeCondition,
|
|
1367
1412
|
evaluateUrlCondition,
|
|
1368
1413
|
fetch,
|
|
@@ -1418,10 +1463,12 @@ var activedRulesConditions = 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,10 +6,10 @@ 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
|
-
export {
|
|
12
|
+
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './conditions/condition.cjs';
|
|
13
13
|
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.cjs';
|
|
14
14
|
export { evaluateTimeCondition } from './conditions/time.cjs';
|
|
15
15
|
export { evaluateAttributeCondition } from './conditions/attribute.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,10 @@ 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
|
-
export {
|
|
12
|
+
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './conditions/condition.js';
|
|
13
13
|
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.js';
|
|
14
14
|
export { evaluateTimeCondition } from './conditions/time.js';
|
|
15
15
|
export { evaluateAttributeCondition } from './conditions/attribute.js';
|
package/dist/index.js
CHANGED
|
@@ -6,16 +6,18 @@ 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
|
-
activedRulesConditions,
|
|
13
14
|
conditionsIsSame,
|
|
14
15
|
evaluateRule,
|
|
16
|
+
evaluateRulesConditions,
|
|
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
|
|
@@ -117,7 +119,6 @@ export {
|
|
|
117
119
|
ArrayProto,
|
|
118
120
|
XMLHttpRequest,
|
|
119
121
|
absoluteUrl,
|
|
120
|
-
activedRulesConditions,
|
|
121
122
|
assignableWindow,
|
|
122
123
|
buildConfig,
|
|
123
124
|
cn,
|
|
@@ -132,6 +133,7 @@ export {
|
|
|
132
133
|
evalCode,
|
|
133
134
|
evaluateAttributeCondition,
|
|
134
135
|
evaluateRule,
|
|
136
|
+
evaluateRulesConditions,
|
|
135
137
|
evaluateTimeCondition,
|
|
136
138
|
evaluateUrlCondition,
|
|
137
139
|
fetch,
|
|
@@ -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
|
-
};
|