rivia 0.0.64 → 0.0.65
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 +26 -118
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1281,16 +1281,16 @@ function evaluateRules(rules, context) {
|
|
|
1281
1281
|
return finalResult;
|
|
1282
1282
|
}
|
|
1283
1283
|
async function Checklist(workspace_id, obj) {
|
|
1284
|
-
window.addEventListener("
|
|
1284
|
+
window.addEventListener("locationchange", async () => {
|
|
1285
1285
|
window.workspace_id = workspace_id;
|
|
1286
1286
|
window.userid = obj.userid;
|
|
1287
|
-
let
|
|
1287
|
+
let user_var = obj.userid;
|
|
1288
1288
|
window.sign_up_at = obj.sign_up_at;
|
|
1289
1289
|
window.role = obj.role;
|
|
1290
1290
|
window.email = obj.email;
|
|
1291
1291
|
console.log("");
|
|
1292
1292
|
try {
|
|
1293
|
-
let
|
|
1293
|
+
let doesRouteMatch2 = function(routes) {
|
|
1294
1294
|
if (!Array.isArray(routes)) return true;
|
|
1295
1295
|
const currentPath2 = window.location.pathname.toLowerCase();
|
|
1296
1296
|
console.log("Current Path:", currentPath2);
|
|
@@ -1301,15 +1301,15 @@ async function Checklist(workspace_id, obj) {
|
|
|
1301
1301
|
if (normalizedRoute.includes("[dynamic]")) {
|
|
1302
1302
|
const base = normalizedRoute.split("[dynamic]")[0].replace(/\/$/, "");
|
|
1303
1303
|
console.log("Base:", base);
|
|
1304
|
-
pattern = new RegExp(`^${
|
|
1304
|
+
pattern = new RegExp(`^${escapeRegex2(base)}(/.*)?$`);
|
|
1305
1305
|
} else {
|
|
1306
|
-
pattern = new RegExp(`^${
|
|
1306
|
+
pattern = new RegExp(`^${escapeRegex2(normalizedRoute)}$`);
|
|
1307
1307
|
}
|
|
1308
1308
|
return pattern.test(currentPath2);
|
|
1309
1309
|
});
|
|
1310
|
-
},
|
|
1310
|
+
}, escapeRegex2 = function(str) {
|
|
1311
1311
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1312
|
-
},
|
|
1312
|
+
}, buildContext2 = function(obj2) {
|
|
1313
1313
|
return {
|
|
1314
1314
|
userid: obj2.userid,
|
|
1315
1315
|
role: obj2.role,
|
|
@@ -1319,7 +1319,7 @@ async function Checklist(workspace_id, obj) {
|
|
|
1319
1319
|
last_name: obj2.last_name
|
|
1320
1320
|
};
|
|
1321
1321
|
};
|
|
1322
|
-
var
|
|
1322
|
+
var doesRouteMatch = doesRouteMatch2, escapeRegex = escapeRegex2, buildContext = buildContext2;
|
|
1323
1323
|
const res = await fetch(
|
|
1324
1324
|
`https://demoapi.rivia.ai/checklist_by_workspace2/${workspace_id}`,
|
|
1325
1325
|
{
|
|
@@ -1340,9 +1340,9 @@ async function Checklist(workspace_id, obj) {
|
|
|
1340
1340
|
if (!chk?.publish)
|
|
1341
1341
|
return false;
|
|
1342
1342
|
if (!chk?.targeting_data?.display)
|
|
1343
|
-
return !
|
|
1343
|
+
return !doesRouteMatch2(routes, currentPath);
|
|
1344
1344
|
else
|
|
1345
|
-
return
|
|
1345
|
+
return doesRouteMatch2(routes, currentPath);
|
|
1346
1346
|
});
|
|
1347
1347
|
if (!matchedChecklist) {
|
|
1348
1348
|
console.log("No checklist applicable for this route");
|
|
@@ -1352,7 +1352,7 @@ async function Checklist(workspace_id, obj) {
|
|
|
1352
1352
|
console.log("matched ch", matchedChecklist);
|
|
1353
1353
|
const rules = matchedChecklist?.targeting_data?.custom_rules || [];
|
|
1354
1354
|
console.log("rules", rules);
|
|
1355
|
-
const context =
|
|
1355
|
+
const context = buildContext2(obj);
|
|
1356
1356
|
const shouldShow = evaluateRules(rules, context);
|
|
1357
1357
|
if (!shouldShow) {
|
|
1358
1358
|
return;
|
|
@@ -1382,7 +1382,7 @@ async function Checklist(workspace_id, obj) {
|
|
|
1382
1382
|
cssConfig,
|
|
1383
1383
|
targetingData,
|
|
1384
1384
|
customCSS,
|
|
1385
|
-
|
|
1385
|
+
user_var,
|
|
1386
1386
|
checklist_id
|
|
1387
1387
|
);
|
|
1388
1388
|
return matchedChecklist;
|
|
@@ -1391,114 +1391,22 @@ async function Checklist(workspace_id, obj) {
|
|
|
1391
1391
|
throw err;
|
|
1392
1392
|
}
|
|
1393
1393
|
});
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
console.log("");
|
|
1401
|
-
try {
|
|
1402
|
-
let doesRouteMatch2 = function(routes) {
|
|
1403
|
-
if (!Array.isArray(routes)) return true;
|
|
1404
|
-
const currentPath2 = window.location.pathname.toLowerCase();
|
|
1405
|
-
console.log("Current Path:", currentPath2);
|
|
1406
|
-
return routes.some((route) => {
|
|
1407
|
-
if (!route) return false;
|
|
1408
|
-
let pattern;
|
|
1409
|
-
const normalizedRoute = route.toLowerCase().replace(/\/$/, "");
|
|
1410
|
-
if (normalizedRoute.includes("[dynamic]")) {
|
|
1411
|
-
const base = normalizedRoute.split("[dynamic]")[0].replace(/\/$/, "");
|
|
1412
|
-
console.log("Base:", base);
|
|
1413
|
-
pattern = new RegExp(`^${escapeRegex2(base)}(/.*)?$`);
|
|
1414
|
-
} else {
|
|
1415
|
-
pattern = new RegExp(`^${escapeRegex2(normalizedRoute)}$`);
|
|
1416
|
-
}
|
|
1417
|
-
return pattern.test(currentPath2);
|
|
1418
|
-
});
|
|
1419
|
-
}, escapeRegex2 = function(str) {
|
|
1420
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1421
|
-
}, buildContext2 = function(obj2) {
|
|
1422
|
-
return {
|
|
1423
|
-
userid: obj2.userid,
|
|
1424
|
-
role: obj2.role,
|
|
1425
|
-
sign_up_at: obj2.sign_up_at,
|
|
1426
|
-
email: obj2.email,
|
|
1427
|
-
first_name: obj2.first_name,
|
|
1428
|
-
last_name: obj2.last_name
|
|
1429
|
-
};
|
|
1394
|
+
(function() {
|
|
1395
|
+
const pushState = history.pushState;
|
|
1396
|
+
const replaceState = history.replaceState;
|
|
1397
|
+
history.pushState = function() {
|
|
1398
|
+
pushState.apply(history, arguments);
|
|
1399
|
+
window.dispatchEvent(new Event("locationchange"));
|
|
1430
1400
|
};
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
{
|
|
1435
|
-
method: "GET",
|
|
1436
|
-
headers: { "Content-Type": "application/json" }
|
|
1437
|
-
}
|
|
1438
|
-
);
|
|
1439
|
-
if (!res.ok) {
|
|
1440
|
-
console.warn("\u274C Failed to fetch checklist");
|
|
1441
|
-
return;
|
|
1442
|
-
}
|
|
1443
|
-
const data = await res.json();
|
|
1444
|
-
const checklists = data.checklist || [];
|
|
1445
|
-
if (!Array.isArray(checklists) || checklists.length === 0) return;
|
|
1446
|
-
const currentPath = window.location.pathname;
|
|
1447
|
-
const matchedChecklist = checklists.find((chk) => {
|
|
1448
|
-
const routes = chk?.targeting_data?.routes;
|
|
1449
|
-
if (!chk?.publish)
|
|
1450
|
-
return false;
|
|
1451
|
-
if (!chk?.targeting_data?.display)
|
|
1452
|
-
return !doesRouteMatch2(routes, currentPath);
|
|
1453
|
-
else
|
|
1454
|
-
return doesRouteMatch2(routes, currentPath);
|
|
1455
|
-
});
|
|
1456
|
-
if (!matchedChecklist) {
|
|
1457
|
-
console.log("No checklist applicable for this route");
|
|
1458
|
-
return;
|
|
1459
|
-
}
|
|
1460
|
-
console.log("userid", obj.userid);
|
|
1461
|
-
console.log("matched ch", matchedChecklist);
|
|
1462
|
-
const rules = matchedChecklist?.targeting_data?.custom_rules || [];
|
|
1463
|
-
console.log("rules", rules);
|
|
1464
|
-
const context = buildContext2(obj);
|
|
1465
|
-
const shouldShow = evaluateRules(rules, context);
|
|
1466
|
-
if (!shouldShow) {
|
|
1467
|
-
return;
|
|
1468
|
-
}
|
|
1469
|
-
const {
|
|
1470
|
-
checklist_id,
|
|
1471
|
-
title = "Untitled Checklist",
|
|
1472
|
-
subtitle = "Describe the purpose of this checklist...",
|
|
1473
|
-
items = [],
|
|
1474
|
-
completion = 0,
|
|
1475
|
-
branding_data: cssConfig = {},
|
|
1476
|
-
targeting_data: targetingData = {},
|
|
1477
|
-
customCSS = ""
|
|
1478
|
-
} = matchedChecklist;
|
|
1479
|
-
const fullData = {
|
|
1480
|
-
checklist: matchedChecklist,
|
|
1481
|
-
cssConfig,
|
|
1482
|
-
targetingData,
|
|
1483
|
-
customCSS
|
|
1401
|
+
history.replaceState = function() {
|
|
1402
|
+
replaceState.apply(history, arguments);
|
|
1403
|
+
window.dispatchEvent(new Event("locationchange"));
|
|
1484
1404
|
};
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
items,
|
|
1491
|
-
cssConfig,
|
|
1492
|
-
targetingData,
|
|
1493
|
-
customCSS,
|
|
1494
|
-
user_var,
|
|
1495
|
-
checklist_id
|
|
1496
|
-
);
|
|
1497
|
-
return matchedChecklist;
|
|
1498
|
-
} catch (err) {
|
|
1499
|
-
console.warn("Checklist error:", err.message);
|
|
1500
|
-
throw err;
|
|
1501
|
-
}
|
|
1405
|
+
window.addEventListener("popstate", () => {
|
|
1406
|
+
window.dispatchEvent(new Event("locationchange"));
|
|
1407
|
+
});
|
|
1408
|
+
window.dispatchEvent(new Event("locationchange"));
|
|
1409
|
+
})();
|
|
1502
1410
|
}
|
|
1503
1411
|
var rivia_default = Checklist;
|
|
1504
1412
|
|