rivia 0.0.85 → 0.0.87

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.
Files changed (3) hide show
  1. package/dist/index.js +170 -11
  2. package/index.d.ts +1 -1
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -3640,14 +3640,173 @@ var RIVIA_TOUR = function() {
3640
3640
  }
3641
3641
  return { loadTips, playTour, endTour, STATE };
3642
3642
  }();
3643
- async function Tours(tourId, userId) {
3643
+ function evaluateRule2(rule, context) {
3644
+ const leftValue = context[rule.name];
3645
+ const operator = rule.operator;
3646
+ const rightValue = rule.values;
3647
+ console.log("leftValue", leftValue);
3648
+ console.log("operator", operator);
3649
+ console.log("rightValue", rightValue);
3650
+ if (leftValue === void 0) return false;
3651
+ switch (operator) {
3652
+ case "in":
3653
+ return Array.isArray(rightValue) && rightValue.includes(leftValue);
3654
+ case "not_in":
3655
+ return Array.isArray(rightValue) && !rightValue.includes(leftValue);
3656
+ case "equals":
3657
+ return leftValue === rightValue;
3658
+ case "not_equals":
3659
+ return leftValue != rightValue;
3660
+ case "greater_than":
3661
+ if (rule.name == "sign_up_at")
3662
+ return new Date(leftValue).getTime() > new Date(rightValue).getTime();
3663
+ else
3664
+ return leftValue > rightValue;
3665
+ case "less_than":
3666
+ if (rule.name == "sign_up_at")
3667
+ return new Date(leftValue).getTime() < new Date(rightValue).getTime();
3668
+ else
3669
+ return leftValue < rightValue;
3670
+ case "greater_or_equals":
3671
+ if (rule.name == "sign_up_at")
3672
+ return new Date(leftValue).getTime() >= new Date(rightValue).getTime();
3673
+ else
3674
+ return leftValue >= rightValue;
3675
+ case "less_or_equals":
3676
+ if (rule.name == "sign_up_at")
3677
+ return new Date(leftValue).getTime() <= new Date(rightValue).getTime();
3678
+ else
3679
+ return leftValue <= rightValue;
3680
+ case "is_empty":
3681
+ if (leftValue == "")
3682
+ return true;
3683
+ else
3684
+ return false;
3685
+ case "is_not_empty":
3686
+ if (leftValue != "")
3687
+ return true;
3688
+ else
3689
+ return false;
3690
+ default:
3691
+ return false;
3692
+ }
3693
+ }
3694
+ function evaluateRules2(rules, context) {
3695
+ if (!Array.isArray(rules) || rules.length === 0) return true;
3696
+ let finalResult = evaluateRule2(rules[0], context);
3697
+ for (let i = 1; i < rules.length; i++) {
3698
+ console.log(finalResult);
3699
+ const previousRule = rules[i - 1];
3700
+ const currentResult = evaluateRule2(rules[i], context);
3701
+ switch (previousRule.next) {
3702
+ case "and":
3703
+ finalResult = finalResult && currentResult;
3704
+ break;
3705
+ case "or":
3706
+ finalResult = finalResult || currentResult;
3707
+ break;
3708
+ default:
3709
+ finalResult = currentResult;
3710
+ }
3711
+ }
3712
+ return finalResult;
3713
+ }
3714
+ async function Tours(workspace_id, obj) {
3644
3715
  if (!sessionStorage.getItem("rivia_tour_state")) {
3645
- RIVIA_TOUR.loadTips(tourId, userId).then(() => {
3646
- try {
3647
- RIVIA_TOUR.playTour();
3648
- } catch (err) {
3716
+ window.userId = obj.userid;
3717
+ let userId = obj.userid;
3718
+ window.sign_up_at = obj.sign_up_at;
3719
+ window.role = obj.role;
3720
+ window.email = obj.email;
3721
+ try {
3722
+ let doesRouteMatch2 = function(route) {
3723
+ if (!route) return false;
3724
+ const currentPath2 = window.location.href.toLowerCase().replace(/\/$/, "");
3725
+ const normalizedRoute = route.toLowerCase().replace(/\/$/, "");
3726
+ let pattern;
3727
+ if (normalizedRoute.includes("[dynamic]")) {
3728
+ const base = normalizedRoute.split("[dynamic]")[0].replace(/\/$/, "");
3729
+ pattern = new RegExp(`^${escapeRegex2(base)}(/.*)?$`);
3730
+ } else {
3731
+ pattern = new RegExp(`^${escapeRegex2(normalizedRoute)}$`);
3732
+ }
3733
+ console.log("Matching current path:", currentPath2, "against pattern:", pattern);
3734
+ return pattern.test(currentPath2);
3735
+ }, escapeRegex2 = function(str) {
3736
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3737
+ }, buildContext2 = function(obj2) {
3738
+ return {
3739
+ userid: obj2.userid,
3740
+ role: obj2.role,
3741
+ sign_up_at: obj2.sign_up_at,
3742
+ email: obj2.email,
3743
+ first_name: obj2.first_name,
3744
+ last_name: obj2.last_name
3745
+ };
3746
+ };
3747
+ var doesRouteMatch = doesRouteMatch2, escapeRegex = escapeRegex2, buildContext = buildContext2;
3748
+ const res = await fetch(
3749
+ `https://demoapi.rivia.ai/tour_by_workspace2/${workspace_id}`,
3750
+ {
3751
+ method: "GET",
3752
+ headers: { "Content-Type": "application/json" }
3753
+ }
3754
+ );
3755
+ if (!res.ok) {
3756
+ console.warn("\u274C Failed to fetch tour");
3757
+ return;
3649
3758
  }
3650
- });
3759
+ const data = await res.json();
3760
+ const tours = data.tour || [];
3761
+ if (!Array.isArray(tours) || tours.length === 0) return;
3762
+ const currentPath = window.location.href;
3763
+ const matchedTour = tours.find((chk) => {
3764
+ const routes = chk?.url;
3765
+ console.log("Checking tour:", window.location.href, "with routes:", routes);
3766
+ if (!chk?.publish && !chk?.published)
3767
+ return false;
3768
+ return doesRouteMatch2(routes, currentPath);
3769
+ });
3770
+ if (!matchedTour) {
3771
+ console.log("No tour applicable for this route");
3772
+ return;
3773
+ }
3774
+ console.log("userid", obj.userid);
3775
+ console.log("matched ch", matchedTour);
3776
+ const rules = matchedTour?.targeting_data?.custom_rules || [];
3777
+ console.log("rules", rules);
3778
+ const context = buildContext2(obj);
3779
+ const shouldShow = evaluateRules2(rules, context);
3780
+ if (!shouldShow) {
3781
+ console.log("User does not meet targeting rules for this tour");
3782
+ return;
3783
+ }
3784
+ const {
3785
+ tour_id,
3786
+ title = "Untitled Tour",
3787
+ subtitle = "Describe the purpose of this tour...",
3788
+ items = [],
3789
+ completion = 0,
3790
+ branding_data: cssConfig = {},
3791
+ targeting_data: targetingData = {},
3792
+ customCSS = ""
3793
+ } = matchedTour;
3794
+ const fullData = {
3795
+ tour: matchedTour,
3796
+ cssConfig,
3797
+ targetingData,
3798
+ customCSS
3799
+ };
3800
+ RIVIA_TOUR.loadTips(tour_id, userId).then(() => {
3801
+ try {
3802
+ RIVIA_TOUR.playTour();
3803
+ } catch (err) {
3804
+ }
3805
+ });
3806
+ } catch (err) {
3807
+ console.warn("Tour error:", err.message);
3808
+ throw err;
3809
+ }
3651
3810
  }
3652
3811
  }
3653
3812
  var rivia_tour_default = Tours;
@@ -3866,7 +4025,7 @@ function injectBanner(banner = {}, opts = {}, userId, bannerId) {
3866
4025
  console.error("injectBanner error:", err);
3867
4026
  }
3868
4027
  }
3869
- function evaluateRule2(rule, context) {
4028
+ function evaluateRule3(rule, context) {
3870
4029
  const leftValue = context[rule.name];
3871
4030
  const operator = rule.operator;
3872
4031
  const rightValue = rule.values;
@@ -3917,13 +4076,13 @@ function evaluateRule2(rule, context) {
3917
4076
  return false;
3918
4077
  }
3919
4078
  }
3920
- function evaluateRules2(rules, context) {
4079
+ function evaluateRules3(rules, context) {
3921
4080
  if (!Array.isArray(rules) || rules.length === 0) return true;
3922
- let finalResult = evaluateRule2(rules[0], context);
4081
+ let finalResult = evaluateRule3(rules[0], context);
3923
4082
  for (let i = 1; i < rules.length; i++) {
3924
4083
  console.log(finalResult);
3925
4084
  const previousRule = rules[i - 1];
3926
- const currentResult = evaluateRule2(rules[i], context);
4085
+ const currentResult = evaluateRule3(rules[i], context);
3927
4086
  switch (previousRule.next) {
3928
4087
  case "and":
3929
4088
  finalResult = finalResult && currentResult;
@@ -4013,7 +4172,7 @@ async function Banner(workspace_id, obj) {
4013
4172
  const rules = matchedbanner?.targeting_data?.custom_rules || [];
4014
4173
  console.log("rules", rules);
4015
4174
  const context = buildContext2(obj);
4016
- const shouldShow = evaluateRules2(rules, context);
4175
+ const shouldShow = evaluateRules3(rules, context);
4017
4176
  if (!shouldShow) {
4018
4177
  console.log("Banner rules not satisfied, not showing banner");
4019
4178
  return;
package/index.d.ts CHANGED
@@ -46,7 +46,7 @@ declare function CannyLite(): {
46
46
  destroy(): void;
47
47
  };
48
48
 
49
- declare function Tours(tourId: string, userId: string): void ;
49
+ declare function Tours(tourId: string, userId: object): void ;
50
50
  export { Checklist,Banner, Tours, CannyLite};
51
51
 
52
52
  // declare function Checklist(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rivia",
3
- "version": "0.0.85",
3
+ "version": "0.0.87",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",