@usertour/helpers 0.0.20 → 0.0.22
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 +81 -22
- package/dist/__tests__/condition.test.js +81 -22
- package/dist/{chunk-TB7JGI2Q.js → chunk-BJ42SRQ6.js} +2 -1
- package/dist/conditions/condition.cjs +3 -1
- package/dist/conditions/condition.d.cts +26 -1
- package/dist/conditions/condition.d.ts +26 -1
- package/dist/conditions/condition.js +3 -1
- package/dist/conditions/index.cjs +45 -0
- package/dist/conditions/index.d.cts +1 -1
- package/dist/conditions/index.d.ts +1 -1
- package/dist/conditions/index.js +5 -1
- package/dist/index.cjs +45 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -1
- package/package.json +1 -1
|
@@ -359,7 +359,7 @@ var evaluateRule = (rule, options) => {
|
|
|
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
365
|
switch (rule.type) {
|
|
@@ -672,6 +672,16 @@ describe("activedRulesConditions", () => {
|
|
|
672
672
|
expect(result[0].actived).toBe(true);
|
|
673
673
|
expect(result[1].actived).toBe(false);
|
|
674
674
|
});
|
|
675
|
+
test("should disable all rule types by default when typeControl is empty", () => {
|
|
676
|
+
const result = activedRulesConditions(mockConditions, {
|
|
677
|
+
...mockOptions,
|
|
678
|
+
typeControl: {}
|
|
679
|
+
});
|
|
680
|
+
expect(result[0].actived).toBe(false);
|
|
681
|
+
expect(result[1].actived).toBe(false);
|
|
682
|
+
expect(result[2].actived).toBe(false);
|
|
683
|
+
expect(result[3].actived).toBe(true);
|
|
684
|
+
});
|
|
675
685
|
test("should force activate rules by ID", () => {
|
|
676
686
|
const result = activedRulesConditions(mockConditions, {
|
|
677
687
|
...mockOptions,
|
|
@@ -679,7 +689,7 @@ describe("activedRulesConditions", () => {
|
|
|
679
689
|
});
|
|
680
690
|
expect(result[0].actived).toBe(true);
|
|
681
691
|
expect(result[1].actived).toBe(true);
|
|
682
|
-
expect(result[2].actived).toBe(
|
|
692
|
+
expect(result[2].actived).toBe(false);
|
|
683
693
|
expect(result[3].actived).toBe(true);
|
|
684
694
|
});
|
|
685
695
|
test("should force deactivate rules by ID", () => {
|
|
@@ -688,8 +698,8 @@ describe("activedRulesConditions", () => {
|
|
|
688
698
|
deactivatedIds: ["rule-1", "rule-4"]
|
|
689
699
|
});
|
|
690
700
|
expect(result[0].actived).toBe(false);
|
|
691
|
-
expect(result[1].actived).toBe(
|
|
692
|
-
expect(result[2].actived).toBe(
|
|
701
|
+
expect(result[1].actived).toBe(false);
|
|
702
|
+
expect(result[2].actived).toBe(false);
|
|
693
703
|
expect(result[3].actived).toBe(false);
|
|
694
704
|
});
|
|
695
705
|
test("should prioritize activatedIds over deactivatedIds", () => {
|
|
@@ -700,7 +710,7 @@ describe("activedRulesConditions", () => {
|
|
|
700
710
|
});
|
|
701
711
|
expect(result[0].actived).toBe(true);
|
|
702
712
|
});
|
|
703
|
-
test("should disable evaluation for specific rule types", () => {
|
|
713
|
+
test("should disable evaluation for specific rule types by default", () => {
|
|
704
714
|
const result = activedRulesConditions(mockConditions, {
|
|
705
715
|
...mockOptions,
|
|
706
716
|
typeControl: {
|
|
@@ -710,19 +720,34 @@ describe("activedRulesConditions", () => {
|
|
|
710
720
|
});
|
|
711
721
|
expect(result[0].actived).toBe(false);
|
|
712
722
|
expect(result[1].actived).toBe(false);
|
|
713
|
-
expect(result[2].actived).toBe(
|
|
723
|
+
expect(result[2].actived).toBe(false);
|
|
714
724
|
expect(result[3].actived).toBe(true);
|
|
715
725
|
});
|
|
716
|
-
test("should evaluate URL conditions correctly", () => {
|
|
717
|
-
const result = activedRulesConditions(mockConditions,
|
|
726
|
+
test("should evaluate URL conditions correctly when enabled", () => {
|
|
727
|
+
const result = activedRulesConditions(mockConditions, {
|
|
728
|
+
...mockOptions,
|
|
729
|
+
typeControl: {
|
|
730
|
+
[import_types3.RulesType.CURRENT_PAGE]: true
|
|
731
|
+
}
|
|
732
|
+
});
|
|
718
733
|
expect(result[0].actived).toBe(false);
|
|
719
734
|
});
|
|
720
|
-
test("should evaluate time conditions correctly", () => {
|
|
721
|
-
const result = activedRulesConditions(mockConditions,
|
|
735
|
+
test("should evaluate time conditions correctly when enabled", () => {
|
|
736
|
+
const result = activedRulesConditions(mockConditions, {
|
|
737
|
+
...mockOptions,
|
|
738
|
+
typeControl: {
|
|
739
|
+
[import_types3.RulesType.TIME]: true
|
|
740
|
+
}
|
|
741
|
+
});
|
|
722
742
|
expect(typeof result[1].actived).toBe("boolean");
|
|
723
743
|
});
|
|
724
|
-
test("should evaluate attribute conditions correctly", () => {
|
|
725
|
-
const result = activedRulesConditions(mockConditions,
|
|
744
|
+
test("should evaluate attribute conditions correctly when enabled", () => {
|
|
745
|
+
const result = activedRulesConditions(mockConditions, {
|
|
746
|
+
...mockOptions,
|
|
747
|
+
typeControl: {
|
|
748
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
749
|
+
}
|
|
750
|
+
});
|
|
726
751
|
expect(result[2].actived).toBe(true);
|
|
727
752
|
});
|
|
728
753
|
test("should handle rules without ID", () => {
|
|
@@ -833,7 +858,7 @@ describe("activedRulesConditions", () => {
|
|
|
833
858
|
const result = activedRulesConditions(conditions, mockOptions);
|
|
834
859
|
expect(result[0].actived).toBe(false);
|
|
835
860
|
});
|
|
836
|
-
test("should handle mixed rule types with different evaluation results", () => {
|
|
861
|
+
test("should handle mixed rule types with different evaluation results when enabled", () => {
|
|
837
862
|
const mixedConditions = [
|
|
838
863
|
{
|
|
839
864
|
id: "url-rule",
|
|
@@ -864,7 +889,13 @@ describe("activedRulesConditions", () => {
|
|
|
864
889
|
data: {}
|
|
865
890
|
}
|
|
866
891
|
];
|
|
867
|
-
const result = activedRulesConditions(mixedConditions,
|
|
892
|
+
const result = activedRulesConditions(mixedConditions, {
|
|
893
|
+
...mockOptions,
|
|
894
|
+
typeControl: {
|
|
895
|
+
[import_types3.RulesType.CURRENT_PAGE]: true,
|
|
896
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
897
|
+
}
|
|
898
|
+
});
|
|
868
899
|
expect(result[0].actived).toBe(false);
|
|
869
900
|
expect(result[1].actived).toBe(true);
|
|
870
901
|
expect(result[2].actived).toBe(false);
|
|
@@ -874,7 +905,21 @@ describe("activedRulesConditions", () => {
|
|
|
874
905
|
...mockOptions,
|
|
875
906
|
typeControl: {
|
|
876
907
|
[import_types3.RulesType.CURRENT_PAGE]: false
|
|
877
|
-
// Other types not specified, should
|
|
908
|
+
// Other types not specified, should be disabled by default
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
expect(result[0].actived).toBe(false);
|
|
912
|
+
expect(result[1].actived).toBe(false);
|
|
913
|
+
expect(result[2].actived).toBe(false);
|
|
914
|
+
expect(result[3].actived).toBe(true);
|
|
915
|
+
});
|
|
916
|
+
test("should enable evaluation for explicitly enabled rule types", () => {
|
|
917
|
+
const result = activedRulesConditions(mockConditions, {
|
|
918
|
+
...mockOptions,
|
|
919
|
+
typeControl: {
|
|
920
|
+
[import_types3.RulesType.CURRENT_PAGE]: true,
|
|
921
|
+
[import_types3.RulesType.TIME]: true,
|
|
922
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
878
923
|
}
|
|
879
924
|
});
|
|
880
925
|
expect(result[0].actived).toBe(false);
|
|
@@ -882,29 +927,40 @@ describe("activedRulesConditions", () => {
|
|
|
882
927
|
expect(result[2].actived).toBe(true);
|
|
883
928
|
expect(result[3].actived).toBe(true);
|
|
884
929
|
});
|
|
885
|
-
test("should handle missing clientContext gracefully", () => {
|
|
930
|
+
test("should handle missing clientContext gracefully when enabled", () => {
|
|
886
931
|
const result = activedRulesConditions(mockConditions, {
|
|
887
932
|
attributes: mockOptions.attributes,
|
|
888
|
-
userAttributes: mockOptions.userAttributes
|
|
933
|
+
userAttributes: mockOptions.userAttributes,
|
|
934
|
+
typeControl: {
|
|
935
|
+
[import_types3.RulesType.CURRENT_PAGE]: true,
|
|
936
|
+
[import_types3.RulesType.TIME]: true,
|
|
937
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
938
|
+
}
|
|
889
939
|
});
|
|
890
940
|
expect(result).toHaveLength(4);
|
|
891
941
|
expect(typeof result[0].actived).toBe("boolean");
|
|
892
942
|
});
|
|
893
|
-
test("should handle missing attributes gracefully", () => {
|
|
943
|
+
test("should handle missing attributes gracefully when enabled", () => {
|
|
894
944
|
const result = activedRulesConditions(mockConditions, {
|
|
895
945
|
clientContext: mockOptions.clientContext,
|
|
896
|
-
userAttributes: mockOptions.userAttributes
|
|
946
|
+
userAttributes: mockOptions.userAttributes,
|
|
947
|
+
typeControl: {
|
|
948
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
949
|
+
}
|
|
897
950
|
});
|
|
898
951
|
expect(result[2].actived).toBe(false);
|
|
899
952
|
});
|
|
900
|
-
test("should handle missing userAttributes gracefully", () => {
|
|
953
|
+
test("should handle missing userAttributes gracefully when enabled", () => {
|
|
901
954
|
const result = activedRulesConditions(mockConditions, {
|
|
902
955
|
clientContext: mockOptions.clientContext,
|
|
903
|
-
attributes: mockOptions.attributes
|
|
956
|
+
attributes: mockOptions.attributes,
|
|
957
|
+
typeControl: {
|
|
958
|
+
[import_types3.RulesType.USER_ATTR]: true
|
|
959
|
+
}
|
|
904
960
|
});
|
|
905
961
|
expect(result[2].actived).toBe(false);
|
|
906
962
|
});
|
|
907
|
-
test("debug: should test URL evaluation directly", () => {
|
|
963
|
+
test("debug: should test URL evaluation directly when enabled", () => {
|
|
908
964
|
const urlCondition = {
|
|
909
965
|
id: "debug-rule",
|
|
910
966
|
type: "current-page",
|
|
@@ -920,6 +976,9 @@ describe("activedRulesConditions", () => {
|
|
|
920
976
|
page_url: "https://example.com",
|
|
921
977
|
viewport_width: 1920,
|
|
922
978
|
viewport_height: 1080
|
|
979
|
+
},
|
|
980
|
+
typeControl: {
|
|
981
|
+
[import_types3.RulesType.CURRENT_PAGE]: true
|
|
923
982
|
}
|
|
924
983
|
};
|
|
925
984
|
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-BJ42SRQ6.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);
|
|
@@ -54,7 +54,7 @@ var evaluateRule = (rule, options) => {
|
|
|
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
60
|
switch (rule.type) {
|
|
@@ -93,5 +93,6 @@ export {
|
|
|
93
93
|
conditionsIsSame,
|
|
94
94
|
isConditionsActived,
|
|
95
95
|
filterConditionsByType,
|
|
96
|
+
evaluateRule,
|
|
96
97
|
activedRulesConditions
|
|
97
98
|
};
|
|
@@ -32,6 +32,7 @@ var condition_exports = {};
|
|
|
32
32
|
__export(condition_exports, {
|
|
33
33
|
activedRulesConditions: () => activedRulesConditions,
|
|
34
34
|
conditionsIsSame: () => conditionsIsSame,
|
|
35
|
+
evaluateRule: () => evaluateRule,
|
|
35
36
|
filterConditionsByType: () => filterConditionsByType,
|
|
36
37
|
isConditionsActived: () => isConditionsActived,
|
|
37
38
|
isEqual: () => import_fast_deep_equal.default
|
|
@@ -373,7 +374,7 @@ var evaluateRule = (rule, options) => {
|
|
|
373
374
|
return true;
|
|
374
375
|
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
375
376
|
return false;
|
|
376
|
-
if (typeControl[rule.type]
|
|
377
|
+
if (typeControl[rule.type] !== true) {
|
|
377
378
|
return rule.actived || false;
|
|
378
379
|
}
|
|
379
380
|
switch (rule.type) {
|
|
@@ -410,6 +411,7 @@ var activedRulesConditions = (conditions, options = {}) => {
|
|
|
410
411
|
0 && (module.exports = {
|
|
411
412
|
activedRulesConditions,
|
|
412
413
|
conditionsIsSame,
|
|
414
|
+
evaluateRule,
|
|
413
415
|
filterConditionsByType,
|
|
414
416
|
isConditionsActived,
|
|
415
417
|
isEqual
|
|
@@ -10,6 +10,31 @@ declare const isConditionsActived: (conditions: RulesCondition[]) => boolean;
|
|
|
10
10
|
* @returns Filtered conditions array
|
|
11
11
|
*/
|
|
12
12
|
declare const filterConditionsByType: (conditions: RulesCondition[], allowedTypes: RulesType[]) => RulesCondition[];
|
|
13
|
+
/**
|
|
14
|
+
* Evaluate and activate rules conditions with enhanced context and type control
|
|
15
|
+
*
|
|
16
|
+
* @param conditions - Array of rules conditions to evaluate
|
|
17
|
+
* @param options - Evaluation options including context, type control, and ID overrides
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const result = await activedRulesConditions(conditions, {
|
|
21
|
+
* clientContext: {
|
|
22
|
+
* page_url: 'https://example.com',
|
|
23
|
+
* viewport_width: 1920,
|
|
24
|
+
* viewport_height: 1080
|
|
25
|
+
* },
|
|
26
|
+
* attributes: userAttributes,
|
|
27
|
+
* userAttributes: userData,
|
|
28
|
+
* typeControl: {
|
|
29
|
+
* [RulesType.CURRENT_PAGE]: true,
|
|
30
|
+
* [RulesType.TIME]: false,
|
|
31
|
+
* [RulesType.USER_ATTR]: true
|
|
32
|
+
* },
|
|
33
|
+
* activatedIds: ['rule-1', 'rule-2'],
|
|
34
|
+
* deactivatedIds: ['rule-3']
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
declare const evaluateRule: (rule: RulesCondition, options: RulesEvaluationOptions) => boolean;
|
|
13
38
|
declare const activedRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => RulesCondition[];
|
|
14
39
|
|
|
15
|
-
export { activedRulesConditions, conditionsIsSame, filterConditionsByType, isConditionsActived };
|
|
40
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, filterConditionsByType, isConditionsActived };
|
|
@@ -10,6 +10,31 @@ declare const isConditionsActived: (conditions: RulesCondition[]) => boolean;
|
|
|
10
10
|
* @returns Filtered conditions array
|
|
11
11
|
*/
|
|
12
12
|
declare const filterConditionsByType: (conditions: RulesCondition[], allowedTypes: RulesType[]) => RulesCondition[];
|
|
13
|
+
/**
|
|
14
|
+
* Evaluate and activate rules conditions with enhanced context and type control
|
|
15
|
+
*
|
|
16
|
+
* @param conditions - Array of rules conditions to evaluate
|
|
17
|
+
* @param options - Evaluation options including context, type control, and ID overrides
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const result = await activedRulesConditions(conditions, {
|
|
21
|
+
* clientContext: {
|
|
22
|
+
* page_url: 'https://example.com',
|
|
23
|
+
* viewport_width: 1920,
|
|
24
|
+
* viewport_height: 1080
|
|
25
|
+
* },
|
|
26
|
+
* attributes: userAttributes,
|
|
27
|
+
* userAttributes: userData,
|
|
28
|
+
* typeControl: {
|
|
29
|
+
* [RulesType.CURRENT_PAGE]: true,
|
|
30
|
+
* [RulesType.TIME]: false,
|
|
31
|
+
* [RulesType.USER_ATTR]: true
|
|
32
|
+
* },
|
|
33
|
+
* activatedIds: ['rule-1', 'rule-2'],
|
|
34
|
+
* deactivatedIds: ['rule-3']
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
declare const evaluateRule: (rule: RulesCondition, options: RulesEvaluationOptions) => boolean;
|
|
13
38
|
declare const activedRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => RulesCondition[];
|
|
14
39
|
|
|
15
|
-
export { activedRulesConditions, conditionsIsSame, filterConditionsByType, isConditionsActived };
|
|
40
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, filterConditionsByType, isConditionsActived };
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
activedRulesConditions,
|
|
3
3
|
conditionsIsSame,
|
|
4
|
+
evaluateRule,
|
|
4
5
|
filterConditionsByType,
|
|
5
6
|
isConditionsActived,
|
|
6
7
|
isEqual
|
|
7
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-BJ42SRQ6.js";
|
|
8
9
|
import "../chunk-YYIGUZNZ.js";
|
|
9
10
|
import "../chunk-PAESAL23.js";
|
|
10
11
|
import "../chunk-PBZSPV5R.js";
|
|
@@ -13,6 +14,7 @@ import "../chunk-XEO3YXBM.js";
|
|
|
13
14
|
export {
|
|
14
15
|
activedRulesConditions,
|
|
15
16
|
conditionsIsSame,
|
|
17
|
+
evaluateRule,
|
|
16
18
|
filterConditionsByType,
|
|
17
19
|
isConditionsActived,
|
|
18
20
|
isEqual
|
|
@@ -30,8 +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,
|
|
33
34
|
conditionsIsSame: () => conditionsIsSame,
|
|
34
35
|
evaluateAttributeCondition: () => evaluateAttributeCondition,
|
|
36
|
+
evaluateRule: () => evaluateRule,
|
|
35
37
|
evaluateTimeCondition: () => evaluateTimeCondition,
|
|
36
38
|
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
37
39
|
filterConditionsByType: () => filterConditionsByType,
|
|
@@ -370,10 +372,53 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
370
372
|
return condition;
|
|
371
373
|
});
|
|
372
374
|
};
|
|
375
|
+
var evaluateRule = (rule, options) => {
|
|
376
|
+
var _a;
|
|
377
|
+
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
378
|
+
const ruleId = rule.id;
|
|
379
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
380
|
+
return true;
|
|
381
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
382
|
+
return false;
|
|
383
|
+
if (typeControl[rule.type] !== true) {
|
|
384
|
+
return rule.actived || false;
|
|
385
|
+
}
|
|
386
|
+
switch (rule.type) {
|
|
387
|
+
case import_types2.RulesType.CURRENT_PAGE:
|
|
388
|
+
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
389
|
+
case import_types2.RulesType.TIME:
|
|
390
|
+
return evaluateTimeCondition(rule);
|
|
391
|
+
case import_types2.RulesType.USER_ATTR:
|
|
392
|
+
case import_types2.RulesType.COMPANY_ATTR:
|
|
393
|
+
return evaluateAttributeCondition(
|
|
394
|
+
rule,
|
|
395
|
+
options.attributes || [],
|
|
396
|
+
options.userAttributes || {}
|
|
397
|
+
);
|
|
398
|
+
default:
|
|
399
|
+
return rule.actived || false;
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
var activedRulesConditions = (conditions, options = {}) => {
|
|
403
|
+
return conditions.map((rule) => {
|
|
404
|
+
if (rule.type === "group" && rule.conditions) {
|
|
405
|
+
return {
|
|
406
|
+
...rule,
|
|
407
|
+
conditions: activedRulesConditions(rule.conditions, options)
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
return {
|
|
411
|
+
...rule,
|
|
412
|
+
actived: evaluateRule(rule, options)
|
|
413
|
+
};
|
|
414
|
+
});
|
|
415
|
+
};
|
|
373
416
|
// Annotate the CommonJS export names for ESM import in node:
|
|
374
417
|
0 && (module.exports = {
|
|
418
|
+
activedRulesConditions,
|
|
375
419
|
conditionsIsSame,
|
|
376
420
|
evaluateAttributeCondition,
|
|
421
|
+
evaluateRule,
|
|
377
422
|
evaluateTimeCondition,
|
|
378
423
|
evaluateUrlCondition,
|
|
379
424
|
filterConditionsByType,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { conditionsIsSame, filterConditionsByType, isConditionsActived } from './condition.cjs';
|
|
1
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, 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 { conditionsIsSame, filterConditionsByType, isConditionsActived } from './condition.js';
|
|
1
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, 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,10 +1,12 @@
|
|
|
1
1
|
import "../chunk-7ODE2AIC.js";
|
|
2
2
|
import {
|
|
3
|
+
activedRulesConditions,
|
|
3
4
|
conditionsIsSame,
|
|
5
|
+
evaluateRule,
|
|
4
6
|
filterConditionsByType,
|
|
5
7
|
isConditionsActived,
|
|
6
8
|
isEqual
|
|
7
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-BJ42SRQ6.js";
|
|
8
10
|
import {
|
|
9
11
|
evaluateUrlCondition,
|
|
10
12
|
isMatchUrlPattern
|
|
@@ -18,8 +20,10 @@ import {
|
|
|
18
20
|
} from "../chunk-CEK3SCQO.js";
|
|
19
21
|
import "../chunk-XEO3YXBM.js";
|
|
20
22
|
export {
|
|
23
|
+
activedRulesConditions,
|
|
21
24
|
conditionsIsSame,
|
|
22
25
|
evaluateAttributeCondition,
|
|
26
|
+
evaluateRule,
|
|
23
27
|
evaluateTimeCondition,
|
|
24
28
|
evaluateUrlCondition,
|
|
25
29
|
filterConditionsByType,
|
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
ArrayProto: () => ArrayProto,
|
|
40
40
|
XMLHttpRequest: () => XMLHttpRequest,
|
|
41
41
|
absoluteUrl: () => absoluteUrl,
|
|
42
|
+
activedRulesConditions: () => activedRulesConditions,
|
|
42
43
|
assignableWindow: () => assignableWindow,
|
|
43
44
|
buildConfig: () => buildConfig,
|
|
44
45
|
cn: () => cn,
|
|
@@ -52,6 +53,7 @@ __export(src_exports, {
|
|
|
52
53
|
document: () => document,
|
|
53
54
|
evalCode: () => evalCode,
|
|
54
55
|
evaluateAttributeCondition: () => evaluateAttributeCondition,
|
|
56
|
+
evaluateRule: () => evaluateRule,
|
|
55
57
|
evaluateTimeCondition: () => evaluateTimeCondition,
|
|
56
58
|
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
57
59
|
fetch: () => fetch,
|
|
@@ -1291,12 +1293,54 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
1291
1293
|
return condition;
|
|
1292
1294
|
});
|
|
1293
1295
|
};
|
|
1296
|
+
var evaluateRule = (rule, options) => {
|
|
1297
|
+
var _a;
|
|
1298
|
+
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
1299
|
+
const ruleId = rule.id;
|
|
1300
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
1301
|
+
return true;
|
|
1302
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
1303
|
+
return false;
|
|
1304
|
+
if (typeControl[rule.type] !== true) {
|
|
1305
|
+
return rule.actived || false;
|
|
1306
|
+
}
|
|
1307
|
+
switch (rule.type) {
|
|
1308
|
+
case import_types5.RulesType.CURRENT_PAGE:
|
|
1309
|
+
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
1310
|
+
case import_types5.RulesType.TIME:
|
|
1311
|
+
return evaluateTimeCondition(rule);
|
|
1312
|
+
case import_types5.RulesType.USER_ATTR:
|
|
1313
|
+
case import_types5.RulesType.COMPANY_ATTR:
|
|
1314
|
+
return evaluateAttributeCondition(
|
|
1315
|
+
rule,
|
|
1316
|
+
options.attributes || [],
|
|
1317
|
+
options.userAttributes || {}
|
|
1318
|
+
);
|
|
1319
|
+
default:
|
|
1320
|
+
return rule.actived || false;
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
var activedRulesConditions = (conditions, options = {}) => {
|
|
1324
|
+
return conditions.map((rule) => {
|
|
1325
|
+
if (rule.type === "group" && rule.conditions) {
|
|
1326
|
+
return {
|
|
1327
|
+
...rule,
|
|
1328
|
+
conditions: activedRulesConditions(rule.conditions, options)
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
return {
|
|
1332
|
+
...rule,
|
|
1333
|
+
actived: evaluateRule(rule, options)
|
|
1334
|
+
};
|
|
1335
|
+
});
|
|
1336
|
+
};
|
|
1294
1337
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1295
1338
|
0 && (module.exports = {
|
|
1296
1339
|
AbortController,
|
|
1297
1340
|
ArrayProto,
|
|
1298
1341
|
XMLHttpRequest,
|
|
1299
1342
|
absoluteUrl,
|
|
1343
|
+
activedRulesConditions,
|
|
1300
1344
|
assignableWindow,
|
|
1301
1345
|
buildConfig,
|
|
1302
1346
|
cn,
|
|
@@ -1310,6 +1354,7 @@ var filterConditionsByType = (conditions, allowedTypes) => {
|
|
|
1310
1354
|
document,
|
|
1311
1355
|
evalCode,
|
|
1312
1356
|
evaluateAttributeCondition,
|
|
1357
|
+
evaluateRule,
|
|
1313
1358
|
evaluateTimeCondition,
|
|
1314
1359
|
evaluateUrlCondition,
|
|
1315
1360
|
fetch,
|
package/dist/index.d.cts
CHANGED
|
@@ -9,7 +9,7 @@ export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, is
|
|
|
9
9
|
export { deepClone } from './utils.cjs';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
|
|
12
|
-
export { conditionsIsSame, filterConditionsByType, isConditionsActived } from './conditions/condition.cjs';
|
|
12
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, 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
|
@@ -9,7 +9,7 @@ export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, is
|
|
|
9
9
|
export { deepClone } from './utils.js';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.js';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
|
|
12
|
-
export { conditionsIsSame, filterConditionsByType, isConditionsActived } from './conditions/condition.js';
|
|
12
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, 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
|
@@ -9,11 +9,13 @@ import {
|
|
|
9
9
|
deepClone
|
|
10
10
|
} from "./chunk-2AEGAICC.js";
|
|
11
11
|
import {
|
|
12
|
+
activedRulesConditions,
|
|
12
13
|
conditionsIsSame,
|
|
14
|
+
evaluateRule,
|
|
13
15
|
filterConditionsByType,
|
|
14
16
|
isConditionsActived,
|
|
15
17
|
isEqual
|
|
16
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-BJ42SRQ6.js";
|
|
17
19
|
import {
|
|
18
20
|
evaluateUrlCondition,
|
|
19
21
|
isMatchUrlPattern
|
|
@@ -115,6 +117,7 @@ export {
|
|
|
115
117
|
ArrayProto,
|
|
116
118
|
XMLHttpRequest,
|
|
117
119
|
absoluteUrl,
|
|
120
|
+
activedRulesConditions,
|
|
118
121
|
assignableWindow,
|
|
119
122
|
buildConfig,
|
|
120
123
|
cn,
|
|
@@ -128,6 +131,7 @@ export {
|
|
|
128
131
|
document,
|
|
129
132
|
evalCode,
|
|
130
133
|
evaluateAttributeCondition,
|
|
134
|
+
evaluateRule,
|
|
131
135
|
evaluateTimeCondition,
|
|
132
136
|
evaluateUrlCondition,
|
|
133
137
|
fetch,
|