@usertour/helpers 0.0.21 → 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.
@@ -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] === false) {
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(true);
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(true);
692
- expect(result[2].actived).toBe(true);
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(true);
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, mockOptions);
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, mockOptions);
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, mockOptions);
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, mockOptions);
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 evaluate normally
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-UNXDVBM3.js";
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(true);
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(true);
309
- expect(result[2].actived).toBe(true);
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(true);
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, mockOptions);
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, mockOptions);
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, mockOptions);
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, mockOptions);
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 evaluate normally
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] === false) {
57
+ if (typeControl[rule.type] !== true) {
58
58
  return rule.actived || false;
59
59
  }
60
60
  switch (rule.type) {
@@ -374,7 +374,7 @@ var evaluateRule = (rule, options) => {
374
374
  return true;
375
375
  if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
376
376
  return false;
377
- if (typeControl[rule.type] === false) {
377
+ if (typeControl[rule.type] !== true) {
378
378
  return rule.actived || false;
379
379
  }
380
380
  switch (rule.type) {
@@ -5,7 +5,7 @@ import {
5
5
  filterConditionsByType,
6
6
  isConditionsActived,
7
7
  isEqual
8
- } from "../chunk-UNXDVBM3.js";
8
+ } from "../chunk-BJ42SRQ6.js";
9
9
  import "../chunk-YYIGUZNZ.js";
10
10
  import "../chunk-PAESAL23.js";
11
11
  import "../chunk-PBZSPV5R.js";
@@ -380,7 +380,7 @@ var evaluateRule = (rule, options) => {
380
380
  return true;
381
381
  if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
382
382
  return false;
383
- if (typeControl[rule.type] === false) {
383
+ if (typeControl[rule.type] !== true) {
384
384
  return rule.actived || false;
385
385
  }
386
386
  switch (rule.type) {
@@ -6,7 +6,7 @@ import {
6
6
  filterConditionsByType,
7
7
  isConditionsActived,
8
8
  isEqual
9
- } from "../chunk-UNXDVBM3.js";
9
+ } from "../chunk-BJ42SRQ6.js";
10
10
  import {
11
11
  evaluateUrlCondition,
12
12
  isMatchUrlPattern
package/dist/index.cjs CHANGED
@@ -1301,7 +1301,7 @@ var evaluateRule = (rule, options) => {
1301
1301
  return true;
1302
1302
  if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
1303
1303
  return false;
1304
- if (typeControl[rule.type] === false) {
1304
+ if (typeControl[rule.type] !== true) {
1305
1305
  return rule.actived || false;
1306
1306
  }
1307
1307
  switch (rule.type) {
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  filterConditionsByType,
16
16
  isConditionsActived,
17
17
  isEqual
18
- } from "./chunk-UNXDVBM3.js";
18
+ } from "./chunk-BJ42SRQ6.js";
19
19
  import {
20
20
  evaluateUrlCondition,
21
21
  isMatchUrlPattern
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "type": "module",
5
5
  "description": "Utility functions and helpers shared across the UserTour project",
6
6
  "homepage": "https://www.usertour.io",