rivia 0.0.58 → 0.0.59
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/index.js +119 -32
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
function slugify(text) {
|
|
3
3
|
return "/" + String(text || "").trim().toLowerCase().replace(/[^a-z0-9\-_\s]/g, "").replace(/\s+/g, "-");
|
|
4
4
|
}
|
|
5
|
-
function Onboarding(topTitle = "Get Started", subtitle, completion = 0, checklistItems = [], cssText = [], targetingData = {}, customCSS = "",
|
|
5
|
+
function Onboarding(topTitle = "Get Started", subtitle, completion = 0, checklistItems = [], cssText = [], targetingData = {}, customCSS = "", user_var, checklist_id) {
|
|
6
6
|
let usrn = targetingData?.targeting_data?.usernames ?? "Not Set";
|
|
7
7
|
let inc = targetingData?.targeting_data?.inclusion ?? "Not Set";
|
|
8
8
|
const mymap = /* @__PURE__ */ new Map();
|
|
@@ -77,14 +77,14 @@ function Onboarding(topTitle = "Get Started", subtitle, completion = 0, checklis
|
|
|
77
77
|
sessionStorage.getItem("onboardingVisited") || "[]"
|
|
78
78
|
);
|
|
79
79
|
if (!Array.isArray(storedVisited2)) storedVisited2 = [];
|
|
80
|
-
let user_var1 =
|
|
80
|
+
let user_var1 = user_var;
|
|
81
81
|
if (!user_var1) {
|
|
82
82
|
user_var1 = "User_" + Math.random().toString(36).substring(2, 8);
|
|
83
|
-
sessionStorage.setItem(
|
|
83
|
+
sessionStorage.setItem(user_var, user_var1);
|
|
84
84
|
}
|
|
85
|
-
const backendUrl = `
|
|
85
|
+
const backendUrl = `http://localhost:5000/clients/${checklist_id}/${user_var1}`;
|
|
86
86
|
async function getUserProgress22() {
|
|
87
|
-
const backendUrl2 = `
|
|
87
|
+
const backendUrl2 = `http://localhost:5000/clients/${checklist_id}/${user_var1}`;
|
|
88
88
|
try {
|
|
89
89
|
const res = await fetch(backendUrl2, { credentials: "include" });
|
|
90
90
|
if (!res.ok) console.warn(`GET failed: ${res.status}`);
|
|
@@ -122,7 +122,7 @@ function Onboarding(topTitle = "Get Started", subtitle, completion = 0, checklis
|
|
|
122
122
|
}
|
|
123
123
|
storedVisited2 = sessionStorage.getItem("onboardingVisited");
|
|
124
124
|
async function getUserProgress22() {
|
|
125
|
-
const backendUrl2 = `
|
|
125
|
+
const backendUrl2 = `http://localhost:5000/clients/${checklist_id}/${user_var1}`;
|
|
126
126
|
try {
|
|
127
127
|
const res = await fetch(backendUrl2, { credentials: "include" });
|
|
128
128
|
if (!res.ok) console.warn(`GET failed: ${res.status}`);
|
|
@@ -173,7 +173,7 @@ function Onboarding(topTitle = "Get Started", subtitle, completion = 0, checklis
|
|
|
173
173
|
checklistItems,
|
|
174
174
|
cssText,
|
|
175
175
|
targetingData,
|
|
176
|
-
|
|
176
|
+
user_var,
|
|
177
177
|
checklist_id,
|
|
178
178
|
cssConfig,
|
|
179
179
|
items,
|
|
@@ -233,7 +233,7 @@ function Onboarding(topTitle = "Get Started", subtitle, completion = 0, checklis
|
|
|
233
233
|
checklistItems,
|
|
234
234
|
cssText,
|
|
235
235
|
targetingData,
|
|
236
|
-
|
|
236
|
+
user_var,
|
|
237
237
|
checklist_id,
|
|
238
238
|
cssConfig,
|
|
239
239
|
items,
|
|
@@ -246,9 +246,9 @@ function Onboarding(topTitle = "Get Started", subtitle, completion = 0, checklis
|
|
|
246
246
|
);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
|
-
async function fetchWithTimeout(topTitle = "Get Started", subtitle, completion = 0, checklistItems = [], cssText = [], targetingData = {},
|
|
250
|
-
console.log("inside fetchWithTimeout",
|
|
251
|
-
if (!
|
|
249
|
+
async function fetchWithTimeout(topTitle = "Get Started", subtitle, completion = 0, checklistItems = [], cssText = [], targetingData = {}, user_var, checklist_id, cssConfig = {}, items = [], storedVisited2 = [], backendUrl = "", progressData = {}, visitedPages = {}, cleanUrlItems = [], custom_css = "") {
|
|
250
|
+
console.log("inside fetchWithTimeout", user_var);
|
|
251
|
+
if (!user_var)
|
|
252
252
|
return;
|
|
253
253
|
let i = 0;
|
|
254
254
|
const stepsHTML = items.map((it) => {
|
|
@@ -858,14 +858,14 @@ transform: translateY(-20%);
|
|
|
858
858
|
updateProgress2(visitedSet.size);
|
|
859
859
|
}
|
|
860
860
|
});
|
|
861
|
-
let
|
|
861
|
+
let user_var2 = user_var;
|
|
862
862
|
function uploadVisitedPagesInBackground(completed2, touched = false) {
|
|
863
863
|
let activeStepId2 = sessionStorage.getItem("activeStepId") || null;
|
|
864
|
-
let
|
|
865
|
-
const backendUrl22 = `
|
|
864
|
+
let user_var22 = user_var;
|
|
865
|
+
const backendUrl22 = `http://localhost:5000/clients/${checklist_id}`;
|
|
866
866
|
try {
|
|
867
867
|
const payload = {
|
|
868
|
-
name:
|
|
868
|
+
name: user_var22,
|
|
869
869
|
completed_items: completed2,
|
|
870
870
|
touched
|
|
871
871
|
};
|
|
@@ -893,12 +893,12 @@ transform: translateY(-20%);
|
|
|
893
893
|
storedVisited2 = sessionStorage.getItem("onboardingVisited");
|
|
894
894
|
if (!storedVisited2 || storedVisited2 == "[]") {
|
|
895
895
|
async function getUserProgress22() {
|
|
896
|
-
const backendUrl2 = `
|
|
896
|
+
const backendUrl2 = `http://localhost:5000/clients/${checklist_id}/${user_var}`;
|
|
897
897
|
try {
|
|
898
898
|
const res = await fetch(backendUrl2, { credentials: "include" });
|
|
899
899
|
if (!res.ok) console.warn(`GET failed: ${res.status}`);
|
|
900
900
|
const data2 = await res.json();
|
|
901
|
-
let userData = data2[
|
|
901
|
+
let userData = data2[user_var];
|
|
902
902
|
if (Array.isArray(userData)) {
|
|
903
903
|
storedVisited2 = userData;
|
|
904
904
|
} else if (typeof userData === "object" && userData !== null && Array.isArray(userData.completed_items)) {
|
|
@@ -1209,9 +1209,78 @@ transform: translateY(-20%);
|
|
|
1209
1209
|
if (label.style.display !== "none") positionCloseBtn();
|
|
1210
1210
|
});
|
|
1211
1211
|
}
|
|
1212
|
+
function evaluateRule(rule, context) {
|
|
1213
|
+
const leftValue = context[rule.name];
|
|
1214
|
+
const operator = rule.operator;
|
|
1215
|
+
const rightValue = rule.values;
|
|
1216
|
+
console.log("leftValue", leftValue);
|
|
1217
|
+
console.log("operator", operator);
|
|
1218
|
+
console.log("rightValue", rightValue);
|
|
1219
|
+
if (leftValue === void 0) return false;
|
|
1220
|
+
switch (operator) {
|
|
1221
|
+
case "in":
|
|
1222
|
+
return Array.isArray(rightValue) && rightValue.includes(leftValue);
|
|
1223
|
+
case "not_in":
|
|
1224
|
+
return Array.isArray(rightValue) && !rightValue.includes(leftValue);
|
|
1225
|
+
case "equals":
|
|
1226
|
+
if (rightValue == "sign_up_at")
|
|
1227
|
+
return new Date(leftValue).getTime() === new Date(rightValue).getTime();
|
|
1228
|
+
else
|
|
1229
|
+
return leftValue === rightValue;
|
|
1230
|
+
case "not_equals":
|
|
1231
|
+
return leftValue != rightValue;
|
|
1232
|
+
case "greater_than":
|
|
1233
|
+
if (rightValue == "sign_up_at")
|
|
1234
|
+
return new Date(leftValue).getTime() > new Date(rightValue).getTime();
|
|
1235
|
+
else
|
|
1236
|
+
return leftValue > rightValue;
|
|
1237
|
+
case "less_than":
|
|
1238
|
+
if (rightValue == "sign_up_at")
|
|
1239
|
+
return new Date(leftValue).getTime() < new Date(rightValue).getTime();
|
|
1240
|
+
else
|
|
1241
|
+
return leftValue < rightValue;
|
|
1242
|
+
case "greater_or_equals":
|
|
1243
|
+
if (rightValue == "sign_up_at")
|
|
1244
|
+
return new Date(leftValue).getTime() >= new Date(rightValue).getTime();
|
|
1245
|
+
else
|
|
1246
|
+
return leftValue >= rightValue;
|
|
1247
|
+
case "less_or_equals":
|
|
1248
|
+
if (rightValue == "sign_up_at")
|
|
1249
|
+
return new Date(leftValue).getTime() <= new Date(rightValue).getTime();
|
|
1250
|
+
else
|
|
1251
|
+
return leftValue <= rightValue;
|
|
1252
|
+
default:
|
|
1253
|
+
return false;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
function evaluateRules(rules, context) {
|
|
1257
|
+
if (!Array.isArray(rules) || rules.length === 0) return true;
|
|
1258
|
+
let finalResult = evaluateRule(rules[0], context);
|
|
1259
|
+
for (let i = 1; i < rules.length; i++) {
|
|
1260
|
+
console.log(finalResult);
|
|
1261
|
+
const previousRule = rules[i - 1];
|
|
1262
|
+
const currentResult = evaluateRule(rules[i], context);
|
|
1263
|
+
switch (previousRule.next) {
|
|
1264
|
+
case "and":
|
|
1265
|
+
finalResult = finalResult && currentResult;
|
|
1266
|
+
break;
|
|
1267
|
+
case "or":
|
|
1268
|
+
finalResult = finalResult || currentResult;
|
|
1269
|
+
break;
|
|
1270
|
+
default:
|
|
1271
|
+
finalResult = currentResult;
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
return finalResult;
|
|
1275
|
+
}
|
|
1212
1276
|
async function Checklist(workspace_id, obj) {
|
|
1213
1277
|
window.workspace_id = workspace_id;
|
|
1214
|
-
window.
|
|
1278
|
+
window.userid = obj.userid;
|
|
1279
|
+
let user_var = obj.userid;
|
|
1280
|
+
window.sign_up_at = obj.sign_up_at;
|
|
1281
|
+
window.role = obj.role;
|
|
1282
|
+
window.email = obj.email;
|
|
1283
|
+
console.log("");
|
|
1215
1284
|
try {
|
|
1216
1285
|
let doesRouteMatch2 = function(routes) {
|
|
1217
1286
|
if (!Array.isArray(routes)) return false;
|
|
@@ -1230,10 +1299,19 @@ async function Checklist(workspace_id, obj) {
|
|
|
1230
1299
|
});
|
|
1231
1300
|
}, escapeRegex2 = function(str) {
|
|
1232
1301
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1302
|
+
}, buildContext2 = function(obj2) {
|
|
1303
|
+
return {
|
|
1304
|
+
userid: obj2.userid,
|
|
1305
|
+
role: obj2.role,
|
|
1306
|
+
sign_up_at: obj2.sign_up_at,
|
|
1307
|
+
email: obj2.email,
|
|
1308
|
+
first_name: obj2.first_name,
|
|
1309
|
+
last_name: obj2.last_name
|
|
1310
|
+
};
|
|
1233
1311
|
};
|
|
1234
|
-
var doesRouteMatch = doesRouteMatch2, escapeRegex = escapeRegex2;
|
|
1312
|
+
var doesRouteMatch = doesRouteMatch2, escapeRegex = escapeRegex2, buildContext = buildContext2;
|
|
1235
1313
|
const res = await fetch(
|
|
1236
|
-
`
|
|
1314
|
+
`http://localhost:5000/checklist_by_workspace2/${workspace_id}`,
|
|
1237
1315
|
{
|
|
1238
1316
|
method: "GET",
|
|
1239
1317
|
headers: { "Content-Type": "application/json" }
|
|
@@ -1260,6 +1338,15 @@ async function Checklist(workspace_id, obj) {
|
|
|
1260
1338
|
console.log("No checklist applicable for this route");
|
|
1261
1339
|
return;
|
|
1262
1340
|
}
|
|
1341
|
+
console.log("userid", obj.userid);
|
|
1342
|
+
console.log("matched ch", matchedChecklist);
|
|
1343
|
+
const rules = matchedChecklist?.targeting_data?.custom_rules || [];
|
|
1344
|
+
console.log("rules", rules);
|
|
1345
|
+
const context = buildContext2(obj);
|
|
1346
|
+
const shouldShow = evaluateRules(rules, context);
|
|
1347
|
+
if (!shouldShow) {
|
|
1348
|
+
return;
|
|
1349
|
+
}
|
|
1263
1350
|
const {
|
|
1264
1351
|
checklist_id,
|
|
1265
1352
|
title = "Untitled Checklist",
|
|
@@ -1556,13 +1643,13 @@ var RIVIA_TOUR = function() {
|
|
|
1556
1643
|
tip.style.left = left + window.scrollX + "px";
|
|
1557
1644
|
tip.style.top = top + window.scrollY + "px";
|
|
1558
1645
|
}
|
|
1559
|
-
function uploadVisitedPagesInBackground(tourId,
|
|
1646
|
+
function uploadVisitedPagesInBackground(tourId, user_var, tourIndex) {
|
|
1560
1647
|
console.log("Uploading visited pages in background for tour ID:", tourIndex, "and user_var:", user_var1);
|
|
1561
|
-
let
|
|
1648
|
+
let user_var2 = user_var1;
|
|
1562
1649
|
const backendUrl22 = `https://demoapi.rivia.ai/tours_clients/${tourId}`;
|
|
1563
1650
|
try {
|
|
1564
1651
|
const payload = {
|
|
1565
|
-
name:
|
|
1652
|
+
name: user_var2,
|
|
1566
1653
|
tourIndex
|
|
1567
1654
|
};
|
|
1568
1655
|
fetch(backendUrl22, {
|
|
@@ -1580,11 +1667,11 @@ var RIVIA_TOUR = function() {
|
|
|
1580
1667
|
} catch (err) {
|
|
1581
1668
|
}
|
|
1582
1669
|
}
|
|
1583
|
-
async function loadTips(tourId,
|
|
1584
|
-
if (!
|
|
1670
|
+
async function loadTips(tourId, user_var) {
|
|
1671
|
+
if (!user_var) {
|
|
1585
1672
|
return;
|
|
1586
1673
|
}
|
|
1587
|
-
user_var1 =
|
|
1674
|
+
user_var1 = user_var;
|
|
1588
1675
|
STATE.tour_id = tourId;
|
|
1589
1676
|
if (sessionStorage.getItem("rivia_tour_state"))
|
|
1590
1677
|
return;
|
|
@@ -1608,15 +1695,15 @@ var RIVIA_TOUR = function() {
|
|
|
1608
1695
|
const stripTrailing = (p) => p.replace(/\/+$/, "");
|
|
1609
1696
|
console.log("STATE.url", STATE.url);
|
|
1610
1697
|
console.log("window.location.pathname", window.location.href);
|
|
1611
|
-
console.log("user_var",
|
|
1612
|
-
console.log("data.tour?.user_data?.[user_var],", data.tour?.user_data?.[
|
|
1613
|
-
if (!data.tour?.user_data?.[
|
|
1614
|
-
uploadVisitedPagesInBackground(tourId,
|
|
1698
|
+
console.log("user_var", user_var);
|
|
1699
|
+
console.log("data.tour?.user_data?.[user_var],", data.tour?.user_data?.[user_var]);
|
|
1700
|
+
if (!data.tour?.user_data?.[user_var]) {
|
|
1701
|
+
uploadVisitedPagesInBackground(tourId, user_var, 0);
|
|
1615
1702
|
} else {
|
|
1616
|
-
STATE.tourIndex = data.tour.user_data[
|
|
1703
|
+
STATE.tourIndex = data.tour.user_data[user_var].tourIndex || 0;
|
|
1617
1704
|
console.log("STATE.tourIndex ", STATE.tourIndex);
|
|
1618
1705
|
}
|
|
1619
|
-
STATE.is_completed = data.tour.user_data && data.tour.user_data[
|
|
1706
|
+
STATE.is_completed = data.tour.user_data && data.tour.user_data[user_var] && data.tour.user_data[user_var].is_completed ? data.tour.user_data[user_var].is_completed : false;
|
|
1620
1707
|
if (STATE.is_completed) {
|
|
1621
1708
|
return;
|
|
1622
1709
|
}
|