rivia 0.0.76 → 0.0.78

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 +235 -29
  2. package/index.d.ts +1 -1
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -146,10 +146,37 @@ function Onboarding(topTitle = "Get Started", subtitle, completion = 0, checklis
146
146
  end_date: userData?.end_date || userData?.end_data || ""
147
147
  };
148
148
  } catch (err) {
149
+ let uploadVisitedPagesInBackground2 = function(completed2, touched = false) {
150
+ let activeStepId2 = sessionStorage.getItem("activeStepId") || null;
151
+ let user_var22 = user_var;
152
+ const backendUrl22 = `https://demoapi.rivia.ai/clients/${checklist_id}`;
153
+ try {
154
+ const payload = {
155
+ name: user_var22,
156
+ completed_items: completed2,
157
+ touched
158
+ };
159
+ fetch(backendUrl22, {
160
+ method: "POST",
161
+ headers: { "Content-Type": "application/json" },
162
+ credentials: "include",
163
+ body: JSON.stringify(payload),
164
+ keepalive: true
165
+ }).then((res) => {
166
+ if (!res.ok) console.warn(`Upload failed: ${res.status}`);
167
+ }).catch((err2) => {
168
+ console.warn("\u26A0\uFE0F Background PUT upload failed:", err2);
169
+ });
170
+ } catch (err2) {
171
+ console.warn("\u274C Error preparing background upload:", err2);
172
+ }
173
+ };
174
+ var uploadVisitedPagesInBackground = uploadVisitedPagesInBackground2;
149
175
  console.warn(
150
176
  "\u26A0\uFE0F Invalid checklist Id",
151
177
  err
152
178
  );
179
+ uploadVisitedPagesInBackground2([], false);
153
180
  return {
154
181
  completedPages: [],
155
182
  progress: 0,
@@ -304,6 +331,14 @@ async function fetchWithTimeout(topTitle = "Get Started", subtitle, completion =
304
331
  color: var(--text-color);
305
332
  }
306
333
 
334
+ .checklist-title {
335
+ max-width: 500px;
336
+ margin: auto;
337
+ position: relative;
338
+ font-family: var(--font-family);
339
+ font-size: var(--font-size);
340
+ color: var(--text-color);
341
+ }
307
342
  /* Close button */
308
343
  .checklist-close {
309
344
  position: absolute;
@@ -357,7 +392,7 @@ async function fetchWithTimeout(topTitle = "Get Started", subtitle, completion =
357
392
  padding: 8px;
358
393
  border-radius: 6px;
359
394
  background: var(--step-bg);
360
- margin-bottom: 16px;
395
+ margin-bottom: 2px;
361
396
  }
362
397
 
363
398
  .start-select {
@@ -921,6 +956,7 @@ transform: translateY(-20%);
921
956
  "\u26A0\uFE0F Invalid checklist Id",
922
957
  err
923
958
  );
959
+ uploadVisitedPagesInBackground([], false);
924
960
  const storedVisited22 = [];
925
961
  return {
926
962
  completedPages: [],
@@ -3614,7 +3650,7 @@ function injectBanner(banner = {}, opts = {}, userId, bannerId) {
3614
3650
  let uploadVisitedPagesInBackground2 = function(bannerId2) {
3615
3651
  console.log("Uploading visited pages in background for banner ID: and user_var:", userId);
3616
3652
  let user_var2 = userId;
3617
- const backendUrl22 = `https://demoapi.rivia.ai/banners_clients/${bannerId2}`;
3653
+ const backendUrl22 = `https://staging-demoapi.rivia.ai/banners_clients/${bannerId2}`;
3618
3654
  try {
3619
3655
  const payload = {
3620
3656
  name: user_var2,
@@ -3628,14 +3664,14 @@ function injectBanner(banner = {}, opts = {}, userId, bannerId) {
3628
3664
  keepalive: true
3629
3665
  }).then((res) => {
3630
3666
  if (res.status === 404) {
3631
- console.warn("Invalid banner id");
3667
+ throw new Error("Invalid banner id");
3632
3668
  }
3633
- console.warn(`Upload failed: ${res.status}`);
3669
+ throw new Error(`Upload failed: ${res.status}`);
3634
3670
  }).catch((err) => {
3635
- console.warn("\u26A0\uFE0F Background PUT upload failed:", err);
3671
+ console.error("\u26A0\uFE0F Background PUT upload failed:", err);
3636
3672
  });
3637
3673
  } catch (err) {
3638
- console.warn("\u274C Error preparing background upload:", err);
3674
+ console.error("\u274C Error preparing background upload:", err);
3639
3675
  }
3640
3676
  };
3641
3677
  var uploadVisitedPagesInBackground = uploadVisitedPagesInBackground2;
@@ -3714,6 +3750,7 @@ function injectBanner(banner = {}, opts = {}, userId, bannerId) {
3714
3750
  textEl.style.color = banner.background?.text_color || banner.text_color || "#fff";
3715
3751
  textWrap.appendChild(textEl);
3716
3752
  }
3753
+ window.container = container;
3717
3754
  const btnArea = document.createElement("div");
3718
3755
  btnArea.style.display = "flex";
3719
3756
  btnArea.style.alignItems = "center";
@@ -3818,33 +3855,202 @@ function injectBanner(banner = {}, opts = {}, userId, bannerId) {
3818
3855
  remove: () => container.remove()
3819
3856
  };
3820
3857
  } catch (err) {
3821
- console.warn("injectBanner error:", err);
3858
+ console.error("injectBanner error:", err);
3822
3859
  }
3823
3860
  }
3824
- async function Banner(bannerId, userId) {
3825
- if (!userId)
3826
- return;
3827
- try {
3828
- const response = await fetch(`https://demoapi.rivia.ai/banners2/${bannerId}`);
3829
- if (!response.ok) {
3830
- if (response.status === 404) {
3831
- console.warn("Invalid Banner id");
3832
- }
3833
- }
3834
- const data = await response.json();
3835
- if (data && data.banner && data.banner.user_data && data.banner.user_data[userId] && data.banner.user_data[userId].is_completed) {
3836
- return;
3861
+ function evaluateRule2(rule, context) {
3862
+ const leftValue = context[rule.name];
3863
+ const operator = rule.operator;
3864
+ const rightValue = rule.values;
3865
+ console.log("leftValue", leftValue);
3866
+ console.log("operator", operator);
3867
+ console.log("rightValue", rightValue);
3868
+ if (leftValue === void 0) return false;
3869
+ switch (operator) {
3870
+ case "in":
3871
+ return Array.isArray(rightValue) && rightValue.includes(leftValue);
3872
+ case "not_in":
3873
+ return Array.isArray(rightValue) && !rightValue.includes(leftValue);
3874
+ case "equals":
3875
+ return leftValue === rightValue;
3876
+ case "not_equals":
3877
+ return leftValue != rightValue;
3878
+ case "greater_than":
3879
+ if (rule.name == "sign_up_at")
3880
+ return new Date(leftValue).getTime() > new Date(rightValue).getTime();
3881
+ else
3882
+ return leftValue > rightValue;
3883
+ case "less_than":
3884
+ if (rule.name == "sign_up_at")
3885
+ return new Date(leftValue).getTime() < new Date(rightValue).getTime();
3886
+ else
3887
+ return leftValue < rightValue;
3888
+ case "greater_or_equals":
3889
+ if (rule.name == "sign_up_at")
3890
+ return new Date(leftValue).getTime() >= new Date(rightValue).getTime();
3891
+ else
3892
+ return leftValue >= rightValue;
3893
+ case "less_or_equals":
3894
+ if (rule.name == "sign_up_at")
3895
+ return new Date(leftValue).getTime() <= new Date(rightValue).getTime();
3896
+ else
3897
+ return leftValue <= rightValue;
3898
+ case "is_empty":
3899
+ if (leftValue == "")
3900
+ return true;
3901
+ else
3902
+ return false;
3903
+ case "is_not_empty":
3904
+ if (leftValue != "")
3905
+ return true;
3906
+ else
3907
+ return false;
3908
+ default:
3909
+ return false;
3910
+ }
3911
+ }
3912
+ function evaluateRules2(rules, context) {
3913
+ if (!Array.isArray(rules) || rules.length === 0) return true;
3914
+ let finalResult = evaluateRule2(rules[0], context);
3915
+ for (let i = 1; i < rules.length; i++) {
3916
+ console.log(finalResult);
3917
+ const previousRule = rules[i - 1];
3918
+ const currentResult = evaluateRule2(rules[i], context);
3919
+ switch (previousRule.next) {
3920
+ case "and":
3921
+ finalResult = finalResult && currentResult;
3922
+ break;
3923
+ case "or":
3924
+ finalResult = finalResult || currentResult;
3925
+ break;
3926
+ default:
3927
+ finalResult = currentResult;
3837
3928
  }
3838
- var bannerFromBackend = null;
3839
- bannerFromBackend = data.banner;
3840
- if (!bannerFromBackend.publish)
3841
- return;
3842
- injectBanner(bannerFromBackend, {}, userId, bannerId);
3843
- console.log("Fetched banner:", bannerFromBackend);
3844
- return bannerFromBackend;
3845
- } catch (error) {
3846
- console.warn("Invalid banner id:", error);
3847
3929
  }
3930
+ return finalResult;
3931
+ }
3932
+ async function Banner(workspace_id, obj) {
3933
+ window.addEventListener("locationchange", async () => {
3934
+ window.workspace_id = workspace_id;
3935
+ window.userid = obj.userid;
3936
+ let user_var = obj.userid;
3937
+ window.sign_up_at = obj.sign_up_at;
3938
+ window.role = obj.role;
3939
+ window.email = obj.email;
3940
+ console.log("");
3941
+ try {
3942
+ let doesRouteMatch2 = function(routes) {
3943
+ if (!Array.isArray(routes)) return true;
3944
+ const currentPath2 = window.location.pathname.toLowerCase();
3945
+ console.log("Current Path:", currentPath2);
3946
+ return routes.some((route) => {
3947
+ if (!route) return false;
3948
+ let pattern;
3949
+ const normalizedRoute = route.toLowerCase().replace(/\/$/, "");
3950
+ if (normalizedRoute.includes("[dynamic]")) {
3951
+ const base = normalizedRoute.split("[dynamic]")[0].replace(/\/$/, "");
3952
+ console.log("Base:", base);
3953
+ pattern = new RegExp(`^${escapeRegex2(base)}(/.*)?$`);
3954
+ } else {
3955
+ pattern = new RegExp(`^${escapeRegex2(normalizedRoute)}$`);
3956
+ }
3957
+ return pattern.test(currentPath2);
3958
+ });
3959
+ }, escapeRegex2 = function(str) {
3960
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3961
+ }, buildContext2 = function(obj2) {
3962
+ return {
3963
+ userid: obj2.userid,
3964
+ role: obj2.role,
3965
+ sign_up_at: obj2.sign_up_at,
3966
+ email: obj2.email,
3967
+ first_name: obj2.first_name,
3968
+ last_name: obj2.last_name
3969
+ };
3970
+ };
3971
+ var doesRouteMatch = doesRouteMatch2, escapeRegex = escapeRegex2, buildContext = buildContext2;
3972
+ const res = await fetch(
3973
+ `https://staging-demoapi.rivia.ai/banner_by_workspace2/${workspace_id}`,
3974
+ {
3975
+ method: "GET",
3976
+ headers: { "Content-Type": "application/json" }
3977
+ }
3978
+ );
3979
+ if (!res.ok) {
3980
+ console.warn("\u274C Failed to fetch banner");
3981
+ return;
3982
+ }
3983
+ const data = await res.json();
3984
+ const banners = data.banner || [];
3985
+ if (!Array.isArray(banners) || banners.length === 0) return;
3986
+ const currentPath = window.location.pathname;
3987
+ const matchedbanner = banners.find((chk) => {
3988
+ const routes = chk?.targeting_data?.routes;
3989
+ if (!chk?.publish)
3990
+ return false;
3991
+ if (!chk?.targeting_data?.display)
3992
+ return !doesRouteMatch2(routes, currentPath);
3993
+ else
3994
+ return doesRouteMatch2(routes, currentPath);
3995
+ });
3996
+ if (!matchedbanner) {
3997
+ if (window.container && window.container.parentNode) {
3998
+ window.container.remove();
3999
+ }
4000
+ console.log("No banner applicable for this route");
4001
+ return;
4002
+ }
4003
+ console.log("userid", obj.userid);
4004
+ console.log("matched ch", matchedbanner);
4005
+ const rules = matchedbanner?.targeting_data?.custom_rules || [];
4006
+ console.log("rules", rules);
4007
+ const context = buildContext2(obj);
4008
+ const shouldShow = evaluateRules2(rules, context);
4009
+ if (!shouldShow) {
4010
+ console.log("Banner rules not satisfied, not showing banner");
4011
+ return;
4012
+ }
4013
+ const {
4014
+ banner_id,
4015
+ title = "Untitled banner",
4016
+ subtitle = "Describe the purpose of this banner...",
4017
+ items = [],
4018
+ completion = 0,
4019
+ branding_data: cssConfig = {},
4020
+ targeting_data: targetingData = {},
4021
+ customCSS = ""
4022
+ } = matchedbanner;
4023
+ console.log("Banner rules satisfied, showing banner", banner_id);
4024
+ const fullData = {
4025
+ banner: matchedbanner,
4026
+ cssConfig,
4027
+ targetingData,
4028
+ customCSS
4029
+ };
4030
+ sessionStorage.removeItem("onboardingVisited");
4031
+ injectBanner(matchedbanner, {}, obj.userid, banner_id);
4032
+ return matchedbanner;
4033
+ } catch (err) {
4034
+ console.warn("banner error:", err.message);
4035
+ throw err;
4036
+ }
4037
+ });
4038
+ (function() {
4039
+ const pushState = history.pushState;
4040
+ const replaceState = history.replaceState;
4041
+ history.pushState = function() {
4042
+ pushState.apply(history, arguments);
4043
+ window.dispatchEvent(new Event("locationchange"));
4044
+ };
4045
+ history.replaceState = function() {
4046
+ replaceState.apply(history, arguments);
4047
+ window.dispatchEvent(new Event("locationchange"));
4048
+ };
4049
+ window.addEventListener("popstate", () => {
4050
+ window.dispatchEvent(new Event("locationchange"));
4051
+ });
4052
+ window.dispatchEvent(new Event("locationchange"));
4053
+ })();
3848
4054
  }
3849
4055
  var banner_default = Banner;
3850
4056
 
package/index.d.ts CHANGED
@@ -4,7 +4,7 @@ declare function Checklist(
4
4
  ): void ;
5
5
  declare function Banner(
6
6
  banner_id: string,
7
- userId: string
7
+ userId: object
8
8
  ): void ;
9
9
 
10
10
  export function triggerEvent(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rivia",
3
- "version": "0.0.76",
3
+ "version": "0.0.78",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",