@usertour/helpers 0.0.21 → 0.0.23
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 +86 -23
- package/dist/__tests__/condition.test.js +81 -22
- package/dist/{chunk-UNXDVBM3.js → chunk-U3EE75KX.js} +6 -2
- package/dist/conditions/condition.cjs +6 -2
- package/dist/conditions/condition.js +1 -1
- package/dist/conditions/index.cjs +6 -2
- package/dist/conditions/index.js +1 -1
- package/dist/index.cjs +6 -2
- package/dist/index.js +1 -1
- package/package.json +2 -2
|
@@ -353,15 +353,19 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
353
353
|
};
|
|
354
354
|
var evaluateRule = (rule, options) => {
|
|
355
355
|
var _a;
|
|
356
|
-
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
356
|
+
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
357
357
|
const ruleId = rule.id;
|
|
358
358
|
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
359
359
|
return true;
|
|
360
360
|
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
361
361
|
return false;
|
|
362
|
-
if (typeControl[rule.type]
|
|
362
|
+
if (typeControl[rule.type] !== true) {
|
|
363
363
|
return rule.actived || false;
|
|
364
364
|
}
|
|
365
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
|
|
366
|
+
if (customEvaluator) {
|
|
367
|
+
return customEvaluator(rule, options);
|
|
368
|
+
}
|
|
365
369
|
switch (rule.type) {
|
|
366
370
|
case import_types2.RulesType.CURRENT_PAGE:
|
|
367
371
|
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
@@ -672,6 +676,16 @@ describe("activedRulesConditions", () => {
|
|
|
672
676
|
expect(result[0].actived).toBe(true);
|
|
673
677
|
expect(result[1].actived).toBe(false);
|
|
674
678
|
});
|
|
679
|
+
test("should disable all rule types by default when typeControl is empty", () => {
|
|
680
|
+
const result = activedRulesConditions(mockConditions, {
|
|
681
|
+
...mockOptions,
|
|
682
|
+
typeControl: {}
|
|
683
|
+
});
|
|
684
|
+
expect(result[0].actived).toBe(false);
|
|
685
|
+
expect(result[1].actived).toBe(false);
|
|
686
|
+
expect(result[2].actived).toBe(false);
|
|
687
|
+
expect(result[3].actived).toBe(true);
|
|
688
|
+
});
|
|
675
689
|
test("should force activate rules by ID", () => {
|
|
676
690
|
const result = activedRulesConditions(mockConditions, {
|
|
677
691
|
...mockOptions,
|
|
@@ -679,7 +693,7 @@ describe("activedRulesConditions", () => {
|
|
|
679
693
|
});
|
|
680
694
|
expect(result[0].actived).toBe(true);
|
|
681
695
|
expect(result[1].actived).toBe(true);
|
|
682
|
-
expect(result[2].actived).toBe(
|
|
696
|
+
expect(result[2].actived).toBe(false);
|
|
683
697
|
expect(result[3].actived).toBe(true);
|
|
684
698
|
});
|
|
685
699
|
test("should force deactivate rules by ID", () => {
|
|
@@ -688,8 +702,8 @@ describe("activedRulesConditions", () => {
|
|
|
688
702
|
deactivatedIds: ["rule-1", "rule-4"]
|
|
689
703
|
});
|
|
690
704
|
expect(result[0].actived).toBe(false);
|
|
691
|
-
expect(result[1].actived).toBe(
|
|
692
|
-
expect(result[2].actived).toBe(
|
|
705
|
+
expect(result[1].actived).toBe(false);
|
|
706
|
+
expect(result[2].actived).toBe(false);
|
|
693
707
|
expect(result[3].actived).toBe(false);
|
|
694
708
|
});
|
|
695
709
|
test("should prioritize activatedIds over deactivatedIds", () => {
|
|
@@ -700,7 +714,7 @@ describe("activedRulesConditions", () => {
|
|
|
700
714
|
});
|
|
701
715
|
expect(result[0].actived).toBe(true);
|
|
702
716
|
});
|
|
703
|
-
test("should disable evaluation for specific rule types", () => {
|
|
717
|
+
test("should disable evaluation for specific rule types by default", () => {
|
|
704
718
|
const result = activedRulesConditions(mockConditions, {
|
|
705
719
|
...mockOptions,
|
|
706
720
|
typeControl: {
|
|
@@ -710,19 +724,34 @@ describe("activedRulesConditions", () => {
|
|
|
710
724
|
});
|
|
711
725
|
expect(result[0].actived).toBe(false);
|
|
712
726
|
expect(result[1].actived).toBe(false);
|
|
713
|
-
expect(result[2].actived).toBe(
|
|
727
|
+
expect(result[2].actived).toBe(false);
|
|
714
728
|
expect(result[3].actived).toBe(true);
|
|
715
729
|
});
|
|
716
|
-
test("should evaluate URL conditions correctly", () => {
|
|
717
|
-
const result = activedRulesConditions(mockConditions,
|
|
730
|
+
test("should evaluate URL conditions correctly when enabled", () => {
|
|
731
|
+
const result = activedRulesConditions(mockConditions, {
|
|
732
|
+
...mockOptions,
|
|
733
|
+
typeControl: {
|
|
734
|
+
[import_types3.RulesType.CURRENT_PAGE]: true
|
|
735
|
+
}
|
|
736
|
+
});
|
|
718
737
|
expect(result[0].actived).toBe(false);
|
|
719
738
|
});
|
|
720
|
-
test("should evaluate time conditions correctly", () => {
|
|
721
|
-
const result = activedRulesConditions(mockConditions,
|
|
739
|
+
test("should evaluate time conditions correctly when enabled", () => {
|
|
740
|
+
const result = activedRulesConditions(mockConditions, {
|
|
741
|
+
...mockOptions,
|
|
742
|
+
typeControl: {
|
|
743
|
+
[import_types3.RulesType.TIME]: true
|
|
744
|
+
}
|
|
745
|
+
});
|
|
722
746
|
expect(typeof result[1].actived).toBe("boolean");
|
|
723
747
|
});
|
|
724
|
-
test("should evaluate attribute conditions correctly", () => {
|
|
725
|
-
const result = activedRulesConditions(mockConditions,
|
|
748
|
+
test("should evaluate attribute conditions correctly when enabled", () => {
|
|
749
|
+
const result = activedRulesConditions(mockConditions, {
|
|
750
|
+
...mockOptions,
|
|
751
|
+
typeControl: {
|
|
752
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
753
|
+
}
|
|
754
|
+
});
|
|
726
755
|
expect(result[2].actived).toBe(true);
|
|
727
756
|
});
|
|
728
757
|
test("should handle rules without ID", () => {
|
|
@@ -833,7 +862,7 @@ describe("activedRulesConditions", () => {
|
|
|
833
862
|
const result = activedRulesConditions(conditions, mockOptions);
|
|
834
863
|
expect(result[0].actived).toBe(false);
|
|
835
864
|
});
|
|
836
|
-
test("should handle mixed rule types with different evaluation results", () => {
|
|
865
|
+
test("should handle mixed rule types with different evaluation results when enabled", () => {
|
|
837
866
|
const mixedConditions = [
|
|
838
867
|
{
|
|
839
868
|
id: "url-rule",
|
|
@@ -864,7 +893,13 @@ describe("activedRulesConditions", () => {
|
|
|
864
893
|
data: {}
|
|
865
894
|
}
|
|
866
895
|
];
|
|
867
|
-
const result = activedRulesConditions(mixedConditions,
|
|
896
|
+
const result = activedRulesConditions(mixedConditions, {
|
|
897
|
+
...mockOptions,
|
|
898
|
+
typeControl: {
|
|
899
|
+
[import_types3.RulesType.CURRENT_PAGE]: true,
|
|
900
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
901
|
+
}
|
|
902
|
+
});
|
|
868
903
|
expect(result[0].actived).toBe(false);
|
|
869
904
|
expect(result[1].actived).toBe(true);
|
|
870
905
|
expect(result[2].actived).toBe(false);
|
|
@@ -874,7 +909,21 @@ describe("activedRulesConditions", () => {
|
|
|
874
909
|
...mockOptions,
|
|
875
910
|
typeControl: {
|
|
876
911
|
[import_types3.RulesType.CURRENT_PAGE]: false
|
|
877
|
-
// Other types not specified, should
|
|
912
|
+
// Other types not specified, should be disabled by default
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
expect(result[0].actived).toBe(false);
|
|
916
|
+
expect(result[1].actived).toBe(false);
|
|
917
|
+
expect(result[2].actived).toBe(false);
|
|
918
|
+
expect(result[3].actived).toBe(true);
|
|
919
|
+
});
|
|
920
|
+
test("should enable evaluation for explicitly enabled rule types", () => {
|
|
921
|
+
const result = activedRulesConditions(mockConditions, {
|
|
922
|
+
...mockOptions,
|
|
923
|
+
typeControl: {
|
|
924
|
+
[import_types3.RulesType.CURRENT_PAGE]: true,
|
|
925
|
+
[import_types3.RulesType.TIME]: true,
|
|
926
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
878
927
|
}
|
|
879
928
|
});
|
|
880
929
|
expect(result[0].actived).toBe(false);
|
|
@@ -882,29 +931,40 @@ describe("activedRulesConditions", () => {
|
|
|
882
931
|
expect(result[2].actived).toBe(true);
|
|
883
932
|
expect(result[3].actived).toBe(true);
|
|
884
933
|
});
|
|
885
|
-
test("should handle missing clientContext gracefully", () => {
|
|
934
|
+
test("should handle missing clientContext gracefully when enabled", () => {
|
|
886
935
|
const result = activedRulesConditions(mockConditions, {
|
|
887
936
|
attributes: mockOptions.attributes,
|
|
888
|
-
userAttributes: mockOptions.userAttributes
|
|
937
|
+
userAttributes: mockOptions.userAttributes,
|
|
938
|
+
typeControl: {
|
|
939
|
+
[import_types3.RulesType.CURRENT_PAGE]: true,
|
|
940
|
+
[import_types3.RulesType.TIME]: true,
|
|
941
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
942
|
+
}
|
|
889
943
|
});
|
|
890
944
|
expect(result).toHaveLength(4);
|
|
891
945
|
expect(typeof result[0].actived).toBe("boolean");
|
|
892
946
|
});
|
|
893
|
-
test("should handle missing attributes gracefully", () => {
|
|
947
|
+
test("should handle missing attributes gracefully when enabled", () => {
|
|
894
948
|
const result = activedRulesConditions(mockConditions, {
|
|
895
949
|
clientContext: mockOptions.clientContext,
|
|
896
|
-
userAttributes: mockOptions.userAttributes
|
|
950
|
+
userAttributes: mockOptions.userAttributes,
|
|
951
|
+
typeControl: {
|
|
952
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
953
|
+
}
|
|
897
954
|
});
|
|
898
955
|
expect(result[2].actived).toBe(false);
|
|
899
956
|
});
|
|
900
|
-
test("should handle missing userAttributes gracefully", () => {
|
|
957
|
+
test("should handle missing userAttributes gracefully when enabled", () => {
|
|
901
958
|
const result = activedRulesConditions(mockConditions, {
|
|
902
959
|
clientContext: mockOptions.clientContext,
|
|
903
|
-
attributes: mockOptions.attributes
|
|
960
|
+
attributes: mockOptions.attributes,
|
|
961
|
+
typeControl: {
|
|
962
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
963
|
+
}
|
|
904
964
|
});
|
|
905
965
|
expect(result[2].actived).toBe(false);
|
|
906
966
|
});
|
|
907
|
-
test("debug: should test URL evaluation directly", () => {
|
|
967
|
+
test("debug: should test URL evaluation directly when enabled", () => {
|
|
908
968
|
const urlCondition = {
|
|
909
969
|
id: "debug-rule",
|
|
910
970
|
type: "current-page",
|
|
@@ -920,6 +980,9 @@ describe("activedRulesConditions", () => {
|
|
|
920
980
|
page_url: "https://example.com",
|
|
921
981
|
viewport_width: 1920,
|
|
922
982
|
viewport_height: 1080
|
|
983
|
+
},
|
|
984
|
+
typeControl: {
|
|
985
|
+
[import_types3.RulesType.CURRENT_PAGE]: true
|
|
923
986
|
}
|
|
924
987
|
};
|
|
925
988
|
const result = activedRulesConditions([urlCondition], options);
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
activedRulesConditions,
|
|
3
3
|
filterConditionsByType,
|
|
4
4
|
isConditionsActived
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-U3EE75KX.js";
|
|
6
6
|
import "../chunk-YYIGUZNZ.js";
|
|
7
7
|
import "../chunk-PAESAL23.js";
|
|
8
8
|
import "../chunk-PBZSPV5R.js";
|
|
@@ -289,6 +289,16 @@ describe("activedRulesConditions", () => {
|
|
|
289
289
|
expect(result[0].actived).toBe(true);
|
|
290
290
|
expect(result[1].actived).toBe(false);
|
|
291
291
|
});
|
|
292
|
+
test("should disable all rule types by default when typeControl is empty", () => {
|
|
293
|
+
const result = activedRulesConditions(mockConditions, {
|
|
294
|
+
...mockOptions,
|
|
295
|
+
typeControl: {}
|
|
296
|
+
});
|
|
297
|
+
expect(result[0].actived).toBe(false);
|
|
298
|
+
expect(result[1].actived).toBe(false);
|
|
299
|
+
expect(result[2].actived).toBe(false);
|
|
300
|
+
expect(result[3].actived).toBe(true);
|
|
301
|
+
});
|
|
292
302
|
test("should force activate rules by ID", () => {
|
|
293
303
|
const result = activedRulesConditions(mockConditions, {
|
|
294
304
|
...mockOptions,
|
|
@@ -296,7 +306,7 @@ describe("activedRulesConditions", () => {
|
|
|
296
306
|
});
|
|
297
307
|
expect(result[0].actived).toBe(true);
|
|
298
308
|
expect(result[1].actived).toBe(true);
|
|
299
|
-
expect(result[2].actived).toBe(
|
|
309
|
+
expect(result[2].actived).toBe(false);
|
|
300
310
|
expect(result[3].actived).toBe(true);
|
|
301
311
|
});
|
|
302
312
|
test("should force deactivate rules by ID", () => {
|
|
@@ -305,8 +315,8 @@ describe("activedRulesConditions", () => {
|
|
|
305
315
|
deactivatedIds: ["rule-1", "rule-4"]
|
|
306
316
|
});
|
|
307
317
|
expect(result[0].actived).toBe(false);
|
|
308
|
-
expect(result[1].actived).toBe(
|
|
309
|
-
expect(result[2].actived).toBe(
|
|
318
|
+
expect(result[1].actived).toBe(false);
|
|
319
|
+
expect(result[2].actived).toBe(false);
|
|
310
320
|
expect(result[3].actived).toBe(false);
|
|
311
321
|
});
|
|
312
322
|
test("should prioritize activatedIds over deactivatedIds", () => {
|
|
@@ -317,7 +327,7 @@ describe("activedRulesConditions", () => {
|
|
|
317
327
|
});
|
|
318
328
|
expect(result[0].actived).toBe(true);
|
|
319
329
|
});
|
|
320
|
-
test("should disable evaluation for specific rule types", () => {
|
|
330
|
+
test("should disable evaluation for specific rule types by default", () => {
|
|
321
331
|
const result = activedRulesConditions(mockConditions, {
|
|
322
332
|
...mockOptions,
|
|
323
333
|
typeControl: {
|
|
@@ -327,19 +337,34 @@ describe("activedRulesConditions", () => {
|
|
|
327
337
|
});
|
|
328
338
|
expect(result[0].actived).toBe(false);
|
|
329
339
|
expect(result[1].actived).toBe(false);
|
|
330
|
-
expect(result[2].actived).toBe(
|
|
340
|
+
expect(result[2].actived).toBe(false);
|
|
331
341
|
expect(result[3].actived).toBe(true);
|
|
332
342
|
});
|
|
333
|
-
test("should evaluate URL conditions correctly", () => {
|
|
334
|
-
const result = activedRulesConditions(mockConditions,
|
|
343
|
+
test("should evaluate URL conditions correctly when enabled", () => {
|
|
344
|
+
const result = activedRulesConditions(mockConditions, {
|
|
345
|
+
...mockOptions,
|
|
346
|
+
typeControl: {
|
|
347
|
+
[RulesType.CURRENT_PAGE]: true
|
|
348
|
+
}
|
|
349
|
+
});
|
|
335
350
|
expect(result[0].actived).toBe(false);
|
|
336
351
|
});
|
|
337
|
-
test("should evaluate time conditions correctly", () => {
|
|
338
|
-
const result = activedRulesConditions(mockConditions,
|
|
352
|
+
test("should evaluate time conditions correctly when enabled", () => {
|
|
353
|
+
const result = activedRulesConditions(mockConditions, {
|
|
354
|
+
...mockOptions,
|
|
355
|
+
typeControl: {
|
|
356
|
+
[RulesType.TIME]: true
|
|
357
|
+
}
|
|
358
|
+
});
|
|
339
359
|
expect(typeof result[1].actived).toBe("boolean");
|
|
340
360
|
});
|
|
341
|
-
test("should evaluate attribute conditions correctly", () => {
|
|
342
|
-
const result = activedRulesConditions(mockConditions,
|
|
361
|
+
test("should evaluate attribute conditions correctly when enabled", () => {
|
|
362
|
+
const result = activedRulesConditions(mockConditions, {
|
|
363
|
+
...mockOptions,
|
|
364
|
+
typeControl: {
|
|
365
|
+
[RulesType.USER_ATTR]: true
|
|
366
|
+
}
|
|
367
|
+
});
|
|
343
368
|
expect(result[2].actived).toBe(true);
|
|
344
369
|
});
|
|
345
370
|
test("should handle rules without ID", () => {
|
|
@@ -450,7 +475,7 @@ describe("activedRulesConditions", () => {
|
|
|
450
475
|
const result = activedRulesConditions(conditions, mockOptions);
|
|
451
476
|
expect(result[0].actived).toBe(false);
|
|
452
477
|
});
|
|
453
|
-
test("should handle mixed rule types with different evaluation results", () => {
|
|
478
|
+
test("should handle mixed rule types with different evaluation results when enabled", () => {
|
|
454
479
|
const mixedConditions = [
|
|
455
480
|
{
|
|
456
481
|
id: "url-rule",
|
|
@@ -481,7 +506,13 @@ describe("activedRulesConditions", () => {
|
|
|
481
506
|
data: {}
|
|
482
507
|
}
|
|
483
508
|
];
|
|
484
|
-
const result = activedRulesConditions(mixedConditions,
|
|
509
|
+
const result = activedRulesConditions(mixedConditions, {
|
|
510
|
+
...mockOptions,
|
|
511
|
+
typeControl: {
|
|
512
|
+
[RulesType.CURRENT_PAGE]: true,
|
|
513
|
+
[RulesType.USER_ATTR]: true
|
|
514
|
+
}
|
|
515
|
+
});
|
|
485
516
|
expect(result[0].actived).toBe(false);
|
|
486
517
|
expect(result[1].actived).toBe(true);
|
|
487
518
|
expect(result[2].actived).toBe(false);
|
|
@@ -491,7 +522,21 @@ describe("activedRulesConditions", () => {
|
|
|
491
522
|
...mockOptions,
|
|
492
523
|
typeControl: {
|
|
493
524
|
[RulesType.CURRENT_PAGE]: false
|
|
494
|
-
// Other types not specified, should
|
|
525
|
+
// Other types not specified, should be disabled by default
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
expect(result[0].actived).toBe(false);
|
|
529
|
+
expect(result[1].actived).toBe(false);
|
|
530
|
+
expect(result[2].actived).toBe(false);
|
|
531
|
+
expect(result[3].actived).toBe(true);
|
|
532
|
+
});
|
|
533
|
+
test("should enable evaluation for explicitly enabled rule types", () => {
|
|
534
|
+
const result = activedRulesConditions(mockConditions, {
|
|
535
|
+
...mockOptions,
|
|
536
|
+
typeControl: {
|
|
537
|
+
[RulesType.CURRENT_PAGE]: true,
|
|
538
|
+
[RulesType.TIME]: true,
|
|
539
|
+
[RulesType.USER_ATTR]: true
|
|
495
540
|
}
|
|
496
541
|
});
|
|
497
542
|
expect(result[0].actived).toBe(false);
|
|
@@ -499,29 +544,40 @@ describe("activedRulesConditions", () => {
|
|
|
499
544
|
expect(result[2].actived).toBe(true);
|
|
500
545
|
expect(result[3].actived).toBe(true);
|
|
501
546
|
});
|
|
502
|
-
test("should handle missing clientContext gracefully", () => {
|
|
547
|
+
test("should handle missing clientContext gracefully when enabled", () => {
|
|
503
548
|
const result = activedRulesConditions(mockConditions, {
|
|
504
549
|
attributes: mockOptions.attributes,
|
|
505
|
-
userAttributes: mockOptions.userAttributes
|
|
550
|
+
userAttributes: mockOptions.userAttributes,
|
|
551
|
+
typeControl: {
|
|
552
|
+
[RulesType.CURRENT_PAGE]: true,
|
|
553
|
+
[RulesType.TIME]: true,
|
|
554
|
+
[RulesType.USER_ATTR]: true
|
|
555
|
+
}
|
|
506
556
|
});
|
|
507
557
|
expect(result).toHaveLength(4);
|
|
508
558
|
expect(typeof result[0].actived).toBe("boolean");
|
|
509
559
|
});
|
|
510
|
-
test("should handle missing attributes gracefully", () => {
|
|
560
|
+
test("should handle missing attributes gracefully when enabled", () => {
|
|
511
561
|
const result = activedRulesConditions(mockConditions, {
|
|
512
562
|
clientContext: mockOptions.clientContext,
|
|
513
|
-
userAttributes: mockOptions.userAttributes
|
|
563
|
+
userAttributes: mockOptions.userAttributes,
|
|
564
|
+
typeControl: {
|
|
565
|
+
[RulesType.USER_ATTR]: true
|
|
566
|
+
}
|
|
514
567
|
});
|
|
515
568
|
expect(result[2].actived).toBe(false);
|
|
516
569
|
});
|
|
517
|
-
test("should handle missing userAttributes gracefully", () => {
|
|
570
|
+
test("should handle missing userAttributes gracefully when enabled", () => {
|
|
518
571
|
const result = activedRulesConditions(mockConditions, {
|
|
519
572
|
clientContext: mockOptions.clientContext,
|
|
520
|
-
attributes: mockOptions.attributes
|
|
573
|
+
attributes: mockOptions.attributes,
|
|
574
|
+
typeControl: {
|
|
575
|
+
[RulesType.USER_ATTR]: true
|
|
576
|
+
}
|
|
521
577
|
});
|
|
522
578
|
expect(result[2].actived).toBe(false);
|
|
523
579
|
});
|
|
524
|
-
test("debug: should test URL evaluation directly", () => {
|
|
580
|
+
test("debug: should test URL evaluation directly when enabled", () => {
|
|
525
581
|
const urlCondition = {
|
|
526
582
|
id: "debug-rule",
|
|
527
583
|
type: "current-page",
|
|
@@ -537,6 +593,9 @@ describe("activedRulesConditions", () => {
|
|
|
537
593
|
page_url: "https://example.com",
|
|
538
594
|
viewport_width: 1920,
|
|
539
595
|
viewport_height: 1080
|
|
596
|
+
},
|
|
597
|
+
typeControl: {
|
|
598
|
+
[RulesType.CURRENT_PAGE]: true
|
|
540
599
|
}
|
|
541
600
|
};
|
|
542
601
|
const result = activedRulesConditions([urlCondition], options);
|
|
@@ -48,15 +48,19 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
48
48
|
};
|
|
49
49
|
var evaluateRule = (rule, options) => {
|
|
50
50
|
var _a;
|
|
51
|
-
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
51
|
+
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
52
52
|
const ruleId = rule.id;
|
|
53
53
|
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
54
54
|
return true;
|
|
55
55
|
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
56
56
|
return false;
|
|
57
|
-
if (typeControl[rule.type]
|
|
57
|
+
if (typeControl[rule.type] !== true) {
|
|
58
58
|
return rule.actived || false;
|
|
59
59
|
}
|
|
60
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
|
|
61
|
+
if (customEvaluator) {
|
|
62
|
+
return customEvaluator(rule, options);
|
|
63
|
+
}
|
|
60
64
|
switch (rule.type) {
|
|
61
65
|
case RulesType.CURRENT_PAGE:
|
|
62
66
|
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
@@ -368,15 +368,19 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
368
368
|
};
|
|
369
369
|
var evaluateRule = (rule, options) => {
|
|
370
370
|
var _a;
|
|
371
|
-
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
371
|
+
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
372
372
|
const ruleId = rule.id;
|
|
373
373
|
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
374
374
|
return true;
|
|
375
375
|
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
376
376
|
return false;
|
|
377
|
-
if (typeControl[rule.type]
|
|
377
|
+
if (typeControl[rule.type] !== true) {
|
|
378
378
|
return rule.actived || false;
|
|
379
379
|
}
|
|
380
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
|
|
381
|
+
if (customEvaluator) {
|
|
382
|
+
return customEvaluator(rule, options);
|
|
383
|
+
}
|
|
380
384
|
switch (rule.type) {
|
|
381
385
|
case import_types2.RulesType.CURRENT_PAGE:
|
|
382
386
|
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
@@ -374,15 +374,19 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
374
374
|
};
|
|
375
375
|
var evaluateRule = (rule, options) => {
|
|
376
376
|
var _a;
|
|
377
|
-
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
377
|
+
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
378
378
|
const ruleId = rule.id;
|
|
379
379
|
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
380
380
|
return true;
|
|
381
381
|
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
382
382
|
return false;
|
|
383
|
-
if (typeControl[rule.type]
|
|
383
|
+
if (typeControl[rule.type] !== true) {
|
|
384
384
|
return rule.actived || false;
|
|
385
385
|
}
|
|
386
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
|
|
387
|
+
if (customEvaluator) {
|
|
388
|
+
return customEvaluator(rule, options);
|
|
389
|
+
}
|
|
386
390
|
switch (rule.type) {
|
|
387
391
|
case import_types2.RulesType.CURRENT_PAGE:
|
|
388
392
|
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
package/dist/conditions/index.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1295,15 +1295,19 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
1295
1295
|
};
|
|
1296
1296
|
var evaluateRule = (rule, options) => {
|
|
1297
1297
|
var _a;
|
|
1298
|
-
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
1298
|
+
const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
|
|
1299
1299
|
const ruleId = rule.id;
|
|
1300
1300
|
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
1301
1301
|
return true;
|
|
1302
1302
|
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
1303
1303
|
return false;
|
|
1304
|
-
if (typeControl[rule.type]
|
|
1304
|
+
if (typeControl[rule.type] !== true) {
|
|
1305
1305
|
return rule.actived || false;
|
|
1306
1306
|
}
|
|
1307
|
+
const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
|
|
1308
|
+
if (customEvaluator) {
|
|
1309
|
+
return customEvaluator(rule, options);
|
|
1310
|
+
}
|
|
1307
1311
|
switch (rule.type) {
|
|
1308
1312
|
case import_types5.RulesType.CURRENT_PAGE:
|
|
1309
1313
|
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
package/dist/index.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.23",
|
|
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.13",
|
|
33
33
|
"chroma-js": "^3.1.2",
|
|
34
34
|
"class-variance-authority": "^0.4.0",
|
|
35
35
|
"clsx": "^1.2.1",
|