@usertour/helpers 0.0.5 → 0.0.6
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/chunk-OASNBRBF.js +589 -0
- package/dist/chunk-Y6FPPOKF.js +28 -0
- package/dist/conditions.cjs +757 -0
- package/dist/conditions.d.cts +23 -0
- package/dist/conditions.d.ts +23 -0
- package/dist/conditions.js +44 -0
- package/dist/index.cjs +589 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +53 -14
- package/dist/listener.cjs +68 -0
- package/dist/listener.d.cts +7 -0
- package/dist/listener.d.ts +7 -0
- package/dist/listener.js +16 -0
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -39,11 +39,17 @@ __export(src_exports, {
|
|
|
39
39
|
ArrayProto: () => ArrayProto,
|
|
40
40
|
JWTLicenseSigner: () => JWTLicenseSigner,
|
|
41
41
|
JWTLicenseValidator: () => JWTLicenseValidator,
|
|
42
|
+
PRIORITIES: () => PRIORITIES,
|
|
42
43
|
XMLHttpRequest: () => XMLHttpRequest,
|
|
43
44
|
absoluteUrl: () => absoluteUrl,
|
|
45
|
+
activedContentCondition: () => activedContentCondition,
|
|
46
|
+
activedContentRulesConditions: () => activedContentRulesConditions,
|
|
47
|
+
activedRulesConditions: () => activedRulesConditions,
|
|
44
48
|
assignableWindow: () => assignableWindow,
|
|
45
49
|
autoStartConditions: () => autoStartConditions,
|
|
46
50
|
buildConfig: () => buildConfig,
|
|
51
|
+
checklistIsDimissed: () => checklistIsDimissed,
|
|
52
|
+
checklistIsSeen: () => checklistIsSeen,
|
|
47
53
|
cn: () => cn,
|
|
48
54
|
conditionsIsSame: () => conditionsIsSame,
|
|
49
55
|
convertSettings: () => convertSettings,
|
|
@@ -55,6 +61,10 @@ __export(src_exports, {
|
|
|
55
61
|
document: () => document,
|
|
56
62
|
evalCode: () => evalCode,
|
|
57
63
|
fetch: () => fetch,
|
|
64
|
+
filterAutoStartContent: () => filterAutoStartContent,
|
|
65
|
+
findLatestEvent: () => findLatestEvent,
|
|
66
|
+
flowIsDismissed: () => flowIsDismissed,
|
|
67
|
+
flowIsSeen: () => flowIsSeen,
|
|
58
68
|
formatDate: () => formatDate,
|
|
59
69
|
generateAutoStateColors: () => generateAutoStateColors,
|
|
60
70
|
getAuthToken: () => getAuthToken,
|
|
@@ -77,6 +87,8 @@ __export(src_exports, {
|
|
|
77
87
|
hexToHSLString: () => hexToHSLString,
|
|
78
88
|
hexToRGBStr: () => hexToRGBStr,
|
|
79
89
|
hexToRgb: () => hexToRgb,
|
|
90
|
+
isActive: () => isActive,
|
|
91
|
+
isActiveContent: () => isActiveContent,
|
|
80
92
|
isArray: () => isArray,
|
|
81
93
|
isBoolean: () => isBoolean,
|
|
82
94
|
isDark: () => isDark,
|
|
@@ -88,6 +100,7 @@ __export(src_exports, {
|
|
|
88
100
|
isFile: () => isFile,
|
|
89
101
|
isFormData: () => isFormData,
|
|
90
102
|
isFunction: () => isFunction,
|
|
103
|
+
isHasActivedContents: () => isHasActivedContents,
|
|
91
104
|
isMatchUrlPattern: () => isMatchUrlPattern,
|
|
92
105
|
isNull: () => isNull,
|
|
93
106
|
isNullish: () => isNullish,
|
|
@@ -95,21 +108,26 @@ __export(src_exports, {
|
|
|
95
108
|
isObject: () => isObject,
|
|
96
109
|
isPublishedAtLeastOneEnvironment: () => isPublishedAtLeastOneEnvironment,
|
|
97
110
|
isPublishedInAllEnvironments: () => isPublishedInAllEnvironments,
|
|
111
|
+
isSameContents: () => isSameContents,
|
|
98
112
|
isString: () => isString,
|
|
99
113
|
isUint8Array: () => isUint8Array,
|
|
100
114
|
isUndefined: () => isUndefined,
|
|
101
115
|
isUrl: () => isUrl,
|
|
116
|
+
isValidContent: () => isValidContent,
|
|
102
117
|
isValidSelector: () => isValidSelector,
|
|
118
|
+
isVisible: () => isVisible,
|
|
103
119
|
location: () => location,
|
|
104
120
|
mergeThemeDefaultSettings: () => mergeThemeDefaultSettings,
|
|
105
121
|
nativeForEach: () => nativeForEach,
|
|
106
122
|
nativeIndexOf: () => nativeIndexOf,
|
|
107
123
|
navigator: () => navigator,
|
|
124
|
+
parseUrlParams: () => parseUrlParams,
|
|
108
125
|
removeAuthToken: () => removeAuthToken,
|
|
109
126
|
setAuthToken: () => setAuthToken,
|
|
110
127
|
storage: () => storage,
|
|
111
128
|
userAgent: () => userAgent,
|
|
112
129
|
uuidV4: () => uuidV4,
|
|
130
|
+
wait: () => wait,
|
|
113
131
|
window: () => win
|
|
114
132
|
});
|
|
115
133
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -1373,17 +1391,576 @@ var JWTLicenseValidator = {
|
|
|
1373
1391
|
}
|
|
1374
1392
|
}
|
|
1375
1393
|
};
|
|
1394
|
+
|
|
1395
|
+
// src/conditions.ts
|
|
1396
|
+
var import_dom = require("@floating-ui/dom");
|
|
1397
|
+
var import_finder = require("@usertour-packages/finder");
|
|
1398
|
+
var import_types4 = require("@usertour/types");
|
|
1399
|
+
var import_date_fns = require("date-fns");
|
|
1400
|
+
|
|
1401
|
+
// src/listener.ts
|
|
1402
|
+
function on(obj, ...args) {
|
|
1403
|
+
if (obj == null ? void 0 : obj.addEventListener) {
|
|
1404
|
+
obj.addEventListener(...args);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
function off(obj, ...args) {
|
|
1408
|
+
if (obj == null ? void 0 : obj.removeEventListener) {
|
|
1409
|
+
obj.removeEventListener(...args);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
// src/conditions.ts
|
|
1414
|
+
var rulesTypes = Object.values(import_types4.RulesType);
|
|
1415
|
+
var PRIORITIES = [
|
|
1416
|
+
import_types4.ContentPriority.HIGHEST,
|
|
1417
|
+
import_types4.ContentPriority.HIGH,
|
|
1418
|
+
import_types4.ContentPriority.MEDIUM,
|
|
1419
|
+
import_types4.ContentPriority.LOW,
|
|
1420
|
+
import_types4.ContentPriority.LOWEST
|
|
1421
|
+
];
|
|
1422
|
+
var isActiveRulesByCurrentPage = (rules) => {
|
|
1423
|
+
const { excludes, includes } = rules.data;
|
|
1424
|
+
if (location) {
|
|
1425
|
+
const href = location.href;
|
|
1426
|
+
return isMatchUrlPattern(href, includes, excludes);
|
|
1427
|
+
}
|
|
1428
|
+
return false;
|
|
1429
|
+
};
|
|
1430
|
+
var isActiveRulesByCurrentTime = (rules) => {
|
|
1431
|
+
const { endDate, endDateHour, endDateMinute, startDate, startDateHour, startDateMinute } = rules.data;
|
|
1432
|
+
const startTime = /* @__PURE__ */ new Date(`${startDate} ${startDateHour}:${startDateMinute}:00`);
|
|
1433
|
+
const endTime = /* @__PURE__ */ new Date(`${endDate} ${endDateHour}:${endDateMinute}:00`);
|
|
1434
|
+
const now = /* @__PURE__ */ new Date();
|
|
1435
|
+
if (!endDate) {
|
|
1436
|
+
return (0, import_date_fns.isAfter)(now, startTime);
|
|
1437
|
+
}
|
|
1438
|
+
return (0, import_date_fns.isAfter)(now, startTime) && (0, import_date_fns.isBefore)(now, endTime);
|
|
1439
|
+
};
|
|
1440
|
+
var isActivedContentRulesCondition = (rules, contentSession) => {
|
|
1441
|
+
const { contentId, logic } = rules.data;
|
|
1442
|
+
const { latestSession, seenSessions, completedSessions } = contentSession;
|
|
1443
|
+
if (!contentId || !logic || contentId !== contentSession.contentId) {
|
|
1444
|
+
return false;
|
|
1445
|
+
}
|
|
1446
|
+
if (logic === import_types4.ContentConditionLogic.ACTIVED || logic === import_types4.ContentConditionLogic.UNACTIVED) {
|
|
1447
|
+
if (!latestSession) {
|
|
1448
|
+
return logic === import_types4.ContentConditionLogic.UNACTIVED;
|
|
1449
|
+
}
|
|
1450
|
+
const isActived = !(flowIsDismissed(latestSession) || checklistIsDimissed(latestSession));
|
|
1451
|
+
return logic === import_types4.ContentConditionLogic.ACTIVED ? isActived : !isActived;
|
|
1452
|
+
}
|
|
1453
|
+
const isSeen = seenSessions > 0;
|
|
1454
|
+
const isCompleted = completedSessions > 0;
|
|
1455
|
+
if (logic === import_types4.ContentConditionLogic.SEEN || logic === import_types4.ContentConditionLogic.UNSEEN) {
|
|
1456
|
+
return logic === import_types4.ContentConditionLogic.SEEN ? isSeen : !isSeen;
|
|
1457
|
+
}
|
|
1458
|
+
if (logic === import_types4.ContentConditionLogic.COMPLETED || logic === import_types4.ContentConditionLogic.UNCOMPLETED) {
|
|
1459
|
+
return logic === import_types4.ContentConditionLogic.COMPLETED ? isCompleted : !isCompleted;
|
|
1460
|
+
}
|
|
1461
|
+
return false;
|
|
1462
|
+
};
|
|
1463
|
+
var isVisible = async (el) => {
|
|
1464
|
+
var _a, _b;
|
|
1465
|
+
if (!((_a = document) == null ? void 0 : _a.body)) {
|
|
1466
|
+
return false;
|
|
1467
|
+
}
|
|
1468
|
+
const { middlewareData } = await (0, import_dom.computePosition)(el, document.body, {
|
|
1469
|
+
strategy: "fixed",
|
|
1470
|
+
middleware: [(0, import_dom.hide)()]
|
|
1471
|
+
});
|
|
1472
|
+
if ((_b = middlewareData == null ? void 0 : middlewareData.hide) == null ? void 0 : _b.referenceHidden) {
|
|
1473
|
+
return false;
|
|
1474
|
+
}
|
|
1475
|
+
return true;
|
|
1476
|
+
};
|
|
1477
|
+
var cache = /* @__PURE__ */ new Map();
|
|
1478
|
+
var isClicked = (el) => {
|
|
1479
|
+
if (cache.has(el)) {
|
|
1480
|
+
return cache.get(el);
|
|
1481
|
+
}
|
|
1482
|
+
const onClick = () => {
|
|
1483
|
+
cache.set(el, true);
|
|
1484
|
+
off(el, "click", onClick);
|
|
1485
|
+
};
|
|
1486
|
+
on(el, "click", onClick);
|
|
1487
|
+
cache.set(el, false);
|
|
1488
|
+
return false;
|
|
1489
|
+
};
|
|
1490
|
+
var isActiveRulesByElement = async (rules) => {
|
|
1491
|
+
const { data } = rules;
|
|
1492
|
+
if (!document) {
|
|
1493
|
+
return false;
|
|
1494
|
+
}
|
|
1495
|
+
const el = (0, import_finder.finderV2)(data.elementData, document);
|
|
1496
|
+
const isPresent = el ? await isVisible(el) : false;
|
|
1497
|
+
const isDisabled = el ? el.disabled : false;
|
|
1498
|
+
switch (data.logic) {
|
|
1499
|
+
case import_types4.ElementConditionLogic.PRESENT:
|
|
1500
|
+
return isPresent;
|
|
1501
|
+
case import_types4.ElementConditionLogic.UNPRESENT:
|
|
1502
|
+
return !isPresent;
|
|
1503
|
+
case import_types4.ElementConditionLogic.DISABLED:
|
|
1504
|
+
return el && isDisabled;
|
|
1505
|
+
case import_types4.ElementConditionLogic.UNDISABLED:
|
|
1506
|
+
return el && !isDisabled;
|
|
1507
|
+
case import_types4.ElementConditionLogic.CLICKED:
|
|
1508
|
+
return el && isClicked(el);
|
|
1509
|
+
case import_types4.ElementConditionLogic.UNCLICKED:
|
|
1510
|
+
return el && !isClicked(el);
|
|
1511
|
+
default:
|
|
1512
|
+
return false;
|
|
1513
|
+
}
|
|
1514
|
+
};
|
|
1515
|
+
var isActiveRulesByTextInput = async (rules) => {
|
|
1516
|
+
const {
|
|
1517
|
+
data: { elementData, logic, value }
|
|
1518
|
+
} = rules;
|
|
1519
|
+
if (!document) {
|
|
1520
|
+
return false;
|
|
1521
|
+
}
|
|
1522
|
+
const el = (0, import_finder.finderV2)(elementData, document);
|
|
1523
|
+
if (!el) {
|
|
1524
|
+
return false;
|
|
1525
|
+
}
|
|
1526
|
+
const elValue = el.value;
|
|
1527
|
+
switch (logic) {
|
|
1528
|
+
case import_types4.StringConditionLogic.IS:
|
|
1529
|
+
return elValue === value;
|
|
1530
|
+
case import_types4.StringConditionLogic.NOT:
|
|
1531
|
+
return elValue !== value;
|
|
1532
|
+
case import_types4.StringConditionLogic.CONTAINS:
|
|
1533
|
+
return elValue.includes(value);
|
|
1534
|
+
case import_types4.StringConditionLogic.NOT_CONTAIN:
|
|
1535
|
+
return !elValue.includes(value);
|
|
1536
|
+
case import_types4.StringConditionLogic.STARTS_WITH:
|
|
1537
|
+
return elValue.startsWith(value);
|
|
1538
|
+
case import_types4.StringConditionLogic.ENDS_WITH:
|
|
1539
|
+
return elValue.endsWith(value);
|
|
1540
|
+
case import_types4.StringConditionLogic.MATCH:
|
|
1541
|
+
return elValue.search(value) !== -1;
|
|
1542
|
+
case import_types4.StringConditionLogic.UNMATCH:
|
|
1543
|
+
return elValue.search(value) === -1;
|
|
1544
|
+
case import_types4.StringConditionLogic.ANY:
|
|
1545
|
+
return true;
|
|
1546
|
+
case import_types4.StringConditionLogic.EMPTY:
|
|
1547
|
+
return !elValue;
|
|
1548
|
+
default:
|
|
1549
|
+
return false;
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
var fillCache = /* @__PURE__ */ new Map();
|
|
1553
|
+
var isActiveRulesByTextFill = async (rules) => {
|
|
1554
|
+
const {
|
|
1555
|
+
data: { elementData }
|
|
1556
|
+
} = rules;
|
|
1557
|
+
if (!document) {
|
|
1558
|
+
return false;
|
|
1559
|
+
}
|
|
1560
|
+
const el = (0, import_finder.finderV2)(elementData, document);
|
|
1561
|
+
if (!el) {
|
|
1562
|
+
return false;
|
|
1563
|
+
}
|
|
1564
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
1565
|
+
const onKeyup = () => {
|
|
1566
|
+
const cacheData = fillCache.get(el);
|
|
1567
|
+
const data = { ...cacheData, timestamp: (/* @__PURE__ */ new Date()).getTime() };
|
|
1568
|
+
fillCache.set(el, data);
|
|
1569
|
+
};
|
|
1570
|
+
if (fillCache.has(el)) {
|
|
1571
|
+
const { timestamp, value, isActive: isActive2 } = fillCache.get(el);
|
|
1572
|
+
if (isActive2) {
|
|
1573
|
+
return true;
|
|
1574
|
+
}
|
|
1575
|
+
if (timestamp !== -1 && now - timestamp > 1e3 && value !== el.value) {
|
|
1576
|
+
off(document, "click", onKeyup);
|
|
1577
|
+
fillCache.set(el, { timestamp, value, isActive: true });
|
|
1578
|
+
return true;
|
|
1579
|
+
}
|
|
1580
|
+
return false;
|
|
1581
|
+
}
|
|
1582
|
+
on(document, "keyup", onKeyup);
|
|
1583
|
+
fillCache.set(el, { timestamp: -1, value: el.value, isActive: false });
|
|
1584
|
+
return false;
|
|
1585
|
+
};
|
|
1586
|
+
var isValidRulesType = (type) => {
|
|
1587
|
+
return rulesTypes.includes(type);
|
|
1588
|
+
};
|
|
1589
|
+
var isActiveRules = async (rules) => {
|
|
1590
|
+
if (!isValidRulesType(rules.type)) {
|
|
1591
|
+
return true;
|
|
1592
|
+
}
|
|
1593
|
+
switch (rules.type) {
|
|
1594
|
+
case import_types4.RulesType.CURRENT_PAGE:
|
|
1595
|
+
return isActiveRulesByCurrentPage(rules);
|
|
1596
|
+
case import_types4.RulesType.TIME:
|
|
1597
|
+
return isActiveRulesByCurrentTime(rules);
|
|
1598
|
+
case import_types4.RulesType.ELEMENT:
|
|
1599
|
+
return await isActiveRulesByElement(rules);
|
|
1600
|
+
case import_types4.RulesType.TEXT_INPUT:
|
|
1601
|
+
return await isActiveRulesByTextInput(rules);
|
|
1602
|
+
case import_types4.RulesType.TEXT_FILL:
|
|
1603
|
+
return await isActiveRulesByTextFill(rules);
|
|
1604
|
+
default:
|
|
1605
|
+
return rules.actived;
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1608
|
+
var activedRulesConditions = async (conditions, rewrite) => {
|
|
1609
|
+
const rulesCondition = [...conditions];
|
|
1610
|
+
for (let j = 0; j < rulesCondition.length; j++) {
|
|
1611
|
+
const rules = rulesCondition[j];
|
|
1612
|
+
if (rules.type !== "group") {
|
|
1613
|
+
if (rewrite == null ? void 0 : rewrite[rules.type]) {
|
|
1614
|
+
rulesCondition[j].actived = true;
|
|
1615
|
+
} else {
|
|
1616
|
+
rulesCondition[j].actived = await isActiveRules(rules);
|
|
1617
|
+
}
|
|
1618
|
+
} else if (rules.conditions) {
|
|
1619
|
+
rulesCondition[j].conditions = await activedRulesConditions(rules.conditions);
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
return rulesCondition;
|
|
1623
|
+
};
|
|
1624
|
+
var activedContentRulesConditions = async (conditions, contents) => {
|
|
1625
|
+
const rulesCondition = [...conditions];
|
|
1626
|
+
for (let j = 0; j < rulesCondition.length; j++) {
|
|
1627
|
+
const rules = rulesCondition[j];
|
|
1628
|
+
if (rules.type !== "group") {
|
|
1629
|
+
if (rules.type === import_types4.RulesType.CONTENT) {
|
|
1630
|
+
const content = contents.find((c) => c.contentId === rules.data.contentId);
|
|
1631
|
+
if (content) {
|
|
1632
|
+
const contentSession = {
|
|
1633
|
+
contentId: content.contentId,
|
|
1634
|
+
latestSession: content.latestSession,
|
|
1635
|
+
totalSessions: content.totalSessions,
|
|
1636
|
+
dismissedSessions: content.dismissedSessions,
|
|
1637
|
+
completedSessions: content.completedSessions,
|
|
1638
|
+
seenSessions: content.seenSessions
|
|
1639
|
+
};
|
|
1640
|
+
rulesCondition[j].actived = isActivedContentRulesCondition(rules, contentSession);
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
} else if (rules.conditions) {
|
|
1644
|
+
rulesCondition[j].conditions = await activedContentRulesConditions(
|
|
1645
|
+
rules.conditions,
|
|
1646
|
+
contents
|
|
1647
|
+
);
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
return rulesCondition;
|
|
1651
|
+
};
|
|
1652
|
+
var activedContentCondition = async (contents) => {
|
|
1653
|
+
const _contents = JSON.parse(JSON.stringify(contents));
|
|
1654
|
+
for (let index = 0; index < _contents.length; index++) {
|
|
1655
|
+
const content = _contents[index];
|
|
1656
|
+
const { enabledAutoStartRules, autoStartRules, hideRules, enabledHideRules } = content.config;
|
|
1657
|
+
if (enabledAutoStartRules && autoStartRules && autoStartRules.length > 0) {
|
|
1658
|
+
content.config.autoStartRules = await activedRulesConditions(autoStartRules);
|
|
1659
|
+
}
|
|
1660
|
+
if (enabledHideRules && hideRules && hideRules.length > 0) {
|
|
1661
|
+
content.config.hideRules = await activedRulesConditions(hideRules);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
return _contents;
|
|
1665
|
+
};
|
|
1666
|
+
var isActive = (autoStartRules) => {
|
|
1667
|
+
if (!autoStartRules || autoStartRules.length === 0) {
|
|
1668
|
+
return false;
|
|
1669
|
+
}
|
|
1670
|
+
const operator = autoStartRules[0].operators;
|
|
1671
|
+
const actives = autoStartRules.filter((rule) => {
|
|
1672
|
+
if (!rule.conditions) {
|
|
1673
|
+
return rule.actived;
|
|
1674
|
+
}
|
|
1675
|
+
return isActive(rule.conditions);
|
|
1676
|
+
});
|
|
1677
|
+
return operator === "and" ? actives.length === autoStartRules.length : actives.length > 0;
|
|
1678
|
+
};
|
|
1679
|
+
var isActiveContent = (content) => {
|
|
1680
|
+
const { enabledAutoStartRules, autoStartRules } = content.config;
|
|
1681
|
+
if (!enabledAutoStartRules || !isActive(autoStartRules)) {
|
|
1682
|
+
return false;
|
|
1683
|
+
}
|
|
1684
|
+
return true;
|
|
1685
|
+
};
|
|
1686
|
+
var priorityCompare = (a, b) => {
|
|
1687
|
+
var _a, _b, _c, _d;
|
|
1688
|
+
const a1 = (_b = (_a = a == null ? void 0 : a.config) == null ? void 0 : _a.autoStartRulesSetting) == null ? void 0 : _b.priority;
|
|
1689
|
+
const a2 = (_d = (_c = b == null ? void 0 : b.config) == null ? void 0 : _c.autoStartRulesSetting) == null ? void 0 : _d.priority;
|
|
1690
|
+
if (!a1 || !a2) {
|
|
1691
|
+
return 0;
|
|
1692
|
+
}
|
|
1693
|
+
const index1 = PRIORITIES.indexOf(a1);
|
|
1694
|
+
const index2 = PRIORITIES.indexOf(a2);
|
|
1695
|
+
if (index1 > index2) {
|
|
1696
|
+
return 1;
|
|
1697
|
+
}
|
|
1698
|
+
if (index1 < index2) {
|
|
1699
|
+
return -1;
|
|
1700
|
+
}
|
|
1701
|
+
return 0;
|
|
1702
|
+
};
|
|
1703
|
+
var filterAutoStartContent = (contents, type) => {
|
|
1704
|
+
return contents.filter((content) => {
|
|
1705
|
+
const isActive2 = isActiveContent(content);
|
|
1706
|
+
const isValid = isValidContent(content, contents);
|
|
1707
|
+
return content.type === type && isActive2 && isValid;
|
|
1708
|
+
}).sort(priorityCompare);
|
|
1709
|
+
};
|
|
1710
|
+
var isHasActivedContents = (source, dest) => {
|
|
1711
|
+
for (let index = 0; index < source.length; index++) {
|
|
1712
|
+
const content1 = source[index];
|
|
1713
|
+
const content2 = dest.find((c) => c.id === content1.id);
|
|
1714
|
+
if (!content2) {
|
|
1715
|
+
return true;
|
|
1716
|
+
}
|
|
1717
|
+
if (isActiveContent(content1) !== isActiveContent(content2)) {
|
|
1718
|
+
return true;
|
|
1719
|
+
}
|
|
1720
|
+
}
|
|
1721
|
+
return false;
|
|
1722
|
+
};
|
|
1723
|
+
var isSameContents = (source, dest) => {
|
|
1724
|
+
if (!source || !dest || source.length !== dest.length) {
|
|
1725
|
+
return false;
|
|
1726
|
+
}
|
|
1727
|
+
for (let index = 0; index < source.length; index++) {
|
|
1728
|
+
const content1 = source[index];
|
|
1729
|
+
const content2 = dest.find((c) => c.id === content1.id);
|
|
1730
|
+
if (!content2) {
|
|
1731
|
+
return false;
|
|
1732
|
+
}
|
|
1733
|
+
if (!conditionsIsSame(content1.config.autoStartRules, content2.config.autoStartRules)) {
|
|
1734
|
+
return false;
|
|
1735
|
+
}
|
|
1736
|
+
}
|
|
1737
|
+
return true;
|
|
1738
|
+
};
|
|
1739
|
+
var getLatestEvent = (currentContent, contents, eventCodeName) => {
|
|
1740
|
+
var _a;
|
|
1741
|
+
const bizEvents = [];
|
|
1742
|
+
const contentId = currentContent.id;
|
|
1743
|
+
const contentType = currentContent.type;
|
|
1744
|
+
for (let index = 0; index < contents.length; index++) {
|
|
1745
|
+
const content = contents[index];
|
|
1746
|
+
if (content.id === contentId || content.type !== contentType) {
|
|
1747
|
+
continue;
|
|
1748
|
+
}
|
|
1749
|
+
const sessionBizEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
|
|
1750
|
+
if (sessionBizEvents && sessionBizEvents.length > 0) {
|
|
1751
|
+
bizEvents.push(...sessionBizEvents.filter((e) => {
|
|
1752
|
+
var _a2;
|
|
1753
|
+
return ((_a2 = e == null ? void 0 : e.event) == null ? void 0 : _a2.codeName) === eventCodeName;
|
|
1754
|
+
}));
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
return findLatestEvent(bizEvents);
|
|
1758
|
+
};
|
|
1759
|
+
var findLatestEvent = (bizEvents) => {
|
|
1760
|
+
const initialValue = bizEvents[0];
|
|
1761
|
+
const lastEvent = bizEvents.reduce(
|
|
1762
|
+
(accumulator, currentValue) => {
|
|
1763
|
+
if ((0, import_date_fns.isAfter)(new Date(currentValue.createdAt), new Date(accumulator.createdAt))) {
|
|
1764
|
+
return currentValue;
|
|
1765
|
+
}
|
|
1766
|
+
return accumulator;
|
|
1767
|
+
},
|
|
1768
|
+
initialValue
|
|
1769
|
+
);
|
|
1770
|
+
return lastEvent;
|
|
1771
|
+
};
|
|
1772
|
+
var showEventMapping = {
|
|
1773
|
+
[import_types4.ContentDataType.FLOW]: import_types4.BizEvents.FLOW_STEP_SEEN,
|
|
1774
|
+
[import_types4.ContentDataType.LAUNCHER]: import_types4.BizEvents.LAUNCHER_SEEN,
|
|
1775
|
+
[import_types4.ContentDataType.CHECKLIST]: import_types4.BizEvents.CHECKLIST_SEEN
|
|
1776
|
+
};
|
|
1777
|
+
var isGreaterThenDuration = (dateLeft, dateRight, unit, duration) => {
|
|
1778
|
+
switch (unit) {
|
|
1779
|
+
case import_types4.FrequencyUnits.SECONDS: {
|
|
1780
|
+
if ((0, import_date_fns.differenceInSeconds)(dateLeft, dateRight) >= duration) {
|
|
1781
|
+
return true;
|
|
1782
|
+
}
|
|
1783
|
+
return false;
|
|
1784
|
+
}
|
|
1785
|
+
case import_types4.FrequencyUnits.MINUTES:
|
|
1786
|
+
if ((0, import_date_fns.differenceInMinutes)(dateLeft, dateRight) >= duration) {
|
|
1787
|
+
return true;
|
|
1788
|
+
}
|
|
1789
|
+
return false;
|
|
1790
|
+
case import_types4.FrequencyUnits.HOURS:
|
|
1791
|
+
if ((0, import_date_fns.differenceInHours)(dateLeft, dateRight) >= duration) {
|
|
1792
|
+
return true;
|
|
1793
|
+
}
|
|
1794
|
+
return false;
|
|
1795
|
+
case import_types4.FrequencyUnits.DAYES:
|
|
1796
|
+
if ((0, import_date_fns.differenceInDays)(dateLeft, dateRight) >= duration) {
|
|
1797
|
+
return true;
|
|
1798
|
+
}
|
|
1799
|
+
return false;
|
|
1800
|
+
default:
|
|
1801
|
+
return false;
|
|
1802
|
+
}
|
|
1803
|
+
};
|
|
1804
|
+
var checklistIsDimissed = (latestSession) => {
|
|
1805
|
+
var _a;
|
|
1806
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
|
|
1807
|
+
(event) => {
|
|
1808
|
+
var _a2;
|
|
1809
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.CHECKLIST_DISMISSED;
|
|
1810
|
+
}
|
|
1811
|
+
);
|
|
1812
|
+
};
|
|
1813
|
+
var flowIsDismissed = (latestSession) => {
|
|
1814
|
+
var _a;
|
|
1815
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find((event) => {
|
|
1816
|
+
var _a2;
|
|
1817
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.FLOW_ENDED;
|
|
1818
|
+
});
|
|
1819
|
+
};
|
|
1820
|
+
var flowIsSeen = (latestSession) => {
|
|
1821
|
+
var _a;
|
|
1822
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
|
|
1823
|
+
(event) => {
|
|
1824
|
+
var _a2;
|
|
1825
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.FLOW_STEP_SEEN;
|
|
1826
|
+
}
|
|
1827
|
+
);
|
|
1828
|
+
};
|
|
1829
|
+
var checklistIsSeen = (latestSession) => {
|
|
1830
|
+
var _a;
|
|
1831
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
|
|
1832
|
+
(event) => {
|
|
1833
|
+
var _a2;
|
|
1834
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.CHECKLIST_SEEN;
|
|
1835
|
+
}
|
|
1836
|
+
);
|
|
1837
|
+
};
|
|
1838
|
+
var isValidContent = (content, contents) => {
|
|
1839
|
+
var _a;
|
|
1840
|
+
const now = /* @__PURE__ */ new Date();
|
|
1841
|
+
if (content.type === import_types4.ContentDataType.FLOW) {
|
|
1842
|
+
if (!content.steps || content.steps.length === 0) {
|
|
1843
|
+
return false;
|
|
1844
|
+
}
|
|
1845
|
+
} else {
|
|
1846
|
+
if (!content.data) {
|
|
1847
|
+
return false;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
if (!content.config.autoStartRulesSetting) {
|
|
1851
|
+
return true;
|
|
1852
|
+
}
|
|
1853
|
+
const { frequency, startIfNotComplete } = content.config.autoStartRulesSetting;
|
|
1854
|
+
const completedSessions = content.completedSessions;
|
|
1855
|
+
const dismissedSessions = content.dismissedSessions;
|
|
1856
|
+
if (startIfNotComplete && completedSessions > 0) {
|
|
1857
|
+
return false;
|
|
1858
|
+
}
|
|
1859
|
+
if (!frequency) {
|
|
1860
|
+
return true;
|
|
1861
|
+
}
|
|
1862
|
+
const contentType = content.type;
|
|
1863
|
+
const lastEventName = showEventMapping[contentType];
|
|
1864
|
+
const lastEvent = getLatestEvent(content, contents, lastEventName);
|
|
1865
|
+
const contentEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
|
|
1866
|
+
if (lastEvent && frequency && frequency.atLeast && !isGreaterThenDuration(
|
|
1867
|
+
now,
|
|
1868
|
+
new Date(lastEvent.createdAt),
|
|
1869
|
+
frequency.atLeast.unit,
|
|
1870
|
+
frequency.atLeast.duration
|
|
1871
|
+
)) {
|
|
1872
|
+
return false;
|
|
1873
|
+
}
|
|
1874
|
+
if (frequency.frequency === import_types4.Frequency.ONCE) {
|
|
1875
|
+
if (dismissedSessions > 0) {
|
|
1876
|
+
return false;
|
|
1877
|
+
}
|
|
1878
|
+
return true;
|
|
1879
|
+
}
|
|
1880
|
+
const showEventName = showEventMapping[contentType];
|
|
1881
|
+
const showEvents = contentEvents == null ? void 0 : contentEvents.filter(
|
|
1882
|
+
(e) => {
|
|
1883
|
+
var _a2, _b;
|
|
1884
|
+
return ((_a2 = e == null ? void 0 : e.event) == null ? void 0 : _a2.codeName) === showEventName && (contentType === import_types4.ContentDataType.FLOW ? ((_b = e == null ? void 0 : e.data) == null ? void 0 : _b.flow_step_number) === 0 : true);
|
|
1885
|
+
}
|
|
1886
|
+
);
|
|
1887
|
+
if (!showEvents || showEvents.length === 0) {
|
|
1888
|
+
return true;
|
|
1889
|
+
}
|
|
1890
|
+
const lastShowEvent = findLatestEvent(showEvents);
|
|
1891
|
+
const lastShowEventDate = new Date(lastShowEvent.createdAt);
|
|
1892
|
+
if (frequency.frequency === import_types4.Frequency.MULTIPLE) {
|
|
1893
|
+
if (frequency.every.times && dismissedSessions >= frequency.every.times) {
|
|
1894
|
+
return false;
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
if (frequency.frequency === import_types4.Frequency.MULTIPLE || frequency.frequency === import_types4.Frequency.UNLIMITED) {
|
|
1898
|
+
if (!isGreaterThenDuration(now, lastShowEventDate, frequency.every.unit, frequency.every.duration)) {
|
|
1899
|
+
return false;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
return true;
|
|
1903
|
+
};
|
|
1904
|
+
var parseUrlParams = (url, paramName) => {
|
|
1905
|
+
if (!url || !paramName) {
|
|
1906
|
+
return null;
|
|
1907
|
+
}
|
|
1908
|
+
try {
|
|
1909
|
+
const urlObj = new URL(url);
|
|
1910
|
+
const searchParams = new URLSearchParams(urlObj.search);
|
|
1911
|
+
if (searchParams.has(paramName)) {
|
|
1912
|
+
return searchParams.get(paramName);
|
|
1913
|
+
}
|
|
1914
|
+
if (urlObj.hash) {
|
|
1915
|
+
const hashSearch = urlObj.hash.split("?")[1];
|
|
1916
|
+
if (hashSearch) {
|
|
1917
|
+
const hashParams = new URLSearchParams(hashSearch);
|
|
1918
|
+
if (hashParams.has(paramName)) {
|
|
1919
|
+
return hashParams.get(paramName);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
return null;
|
|
1924
|
+
} catch (error) {
|
|
1925
|
+
console.error("Error parsing URL:", error);
|
|
1926
|
+
return null;
|
|
1927
|
+
}
|
|
1928
|
+
};
|
|
1929
|
+
var wait = (seconds) => {
|
|
1930
|
+
if (typeof seconds !== "number" || Number.isNaN(seconds)) {
|
|
1931
|
+
return Promise.reject(new Error("Invalid wait time: must be a number"));
|
|
1932
|
+
}
|
|
1933
|
+
if (seconds < 0) {
|
|
1934
|
+
return Promise.reject(new Error("Invalid wait time: cannot be negative"));
|
|
1935
|
+
}
|
|
1936
|
+
if (seconds === 0) {
|
|
1937
|
+
return Promise.resolve();
|
|
1938
|
+
}
|
|
1939
|
+
return new Promise((resolve2, reject) => {
|
|
1940
|
+
try {
|
|
1941
|
+
setTimeout(resolve2, seconds * 1e3);
|
|
1942
|
+
} catch (error) {
|
|
1943
|
+
reject(error);
|
|
1944
|
+
}
|
|
1945
|
+
});
|
|
1946
|
+
};
|
|
1376
1947
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1377
1948
|
0 && (module.exports = {
|
|
1378
1949
|
AbortController,
|
|
1379
1950
|
ArrayProto,
|
|
1380
1951
|
JWTLicenseSigner,
|
|
1381
1952
|
JWTLicenseValidator,
|
|
1953
|
+
PRIORITIES,
|
|
1382
1954
|
XMLHttpRequest,
|
|
1383
1955
|
absoluteUrl,
|
|
1956
|
+
activedContentCondition,
|
|
1957
|
+
activedContentRulesConditions,
|
|
1958
|
+
activedRulesConditions,
|
|
1384
1959
|
assignableWindow,
|
|
1385
1960
|
autoStartConditions,
|
|
1386
1961
|
buildConfig,
|
|
1962
|
+
checklistIsDimissed,
|
|
1963
|
+
checklistIsSeen,
|
|
1387
1964
|
cn,
|
|
1388
1965
|
conditionsIsSame,
|
|
1389
1966
|
convertSettings,
|
|
@@ -1395,6 +1972,10 @@ var JWTLicenseValidator = {
|
|
|
1395
1972
|
document,
|
|
1396
1973
|
evalCode,
|
|
1397
1974
|
fetch,
|
|
1975
|
+
filterAutoStartContent,
|
|
1976
|
+
findLatestEvent,
|
|
1977
|
+
flowIsDismissed,
|
|
1978
|
+
flowIsSeen,
|
|
1398
1979
|
formatDate,
|
|
1399
1980
|
generateAutoStateColors,
|
|
1400
1981
|
getAuthToken,
|
|
@@ -1417,6 +1998,8 @@ var JWTLicenseValidator = {
|
|
|
1417
1998
|
hexToHSLString,
|
|
1418
1999
|
hexToRGBStr,
|
|
1419
2000
|
hexToRgb,
|
|
2001
|
+
isActive,
|
|
2002
|
+
isActiveContent,
|
|
1420
2003
|
isArray,
|
|
1421
2004
|
isBoolean,
|
|
1422
2005
|
isDark,
|
|
@@ -1428,6 +2011,7 @@ var JWTLicenseValidator = {
|
|
|
1428
2011
|
isFile,
|
|
1429
2012
|
isFormData,
|
|
1430
2013
|
isFunction,
|
|
2014
|
+
isHasActivedContents,
|
|
1431
2015
|
isMatchUrlPattern,
|
|
1432
2016
|
isNull,
|
|
1433
2017
|
isNullish,
|
|
@@ -1435,20 +2019,25 @@ var JWTLicenseValidator = {
|
|
|
1435
2019
|
isObject,
|
|
1436
2020
|
isPublishedAtLeastOneEnvironment,
|
|
1437
2021
|
isPublishedInAllEnvironments,
|
|
2022
|
+
isSameContents,
|
|
1438
2023
|
isString,
|
|
1439
2024
|
isUint8Array,
|
|
1440
2025
|
isUndefined,
|
|
1441
2026
|
isUrl,
|
|
2027
|
+
isValidContent,
|
|
1442
2028
|
isValidSelector,
|
|
2029
|
+
isVisible,
|
|
1443
2030
|
location,
|
|
1444
2031
|
mergeThemeDefaultSettings,
|
|
1445
2032
|
nativeForEach,
|
|
1446
2033
|
nativeIndexOf,
|
|
1447
2034
|
navigator,
|
|
2035
|
+
parseUrlParams,
|
|
1448
2036
|
removeAuthToken,
|
|
1449
2037
|
setAuthToken,
|
|
1450
2038
|
storage,
|
|
1451
2039
|
userAgent,
|
|
1452
2040
|
uuidV4,
|
|
2041
|
+
wait,
|
|
1453
2042
|
window
|
|
1454
2043
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -13,6 +13,7 @@ export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cj
|
|
|
13
13
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
|
|
14
14
|
export { GenerateLicenseOptions, JWTLicenseSigner, JWTLicenseSignerOptions } from './jwt-license-signer.cjs';
|
|
15
15
|
export { JWTLicenseValidator } from './jwt-license-validator.cjs';
|
|
16
|
+
export { PRIORITIES, activedContentCondition, activedContentRulesConditions, activedRulesConditions, checklistIsDimissed, checklistIsSeen, filterAutoStartContent, findLatestEvent, flowIsDismissed, flowIsSeen, isActive, isActiveContent, isHasActivedContents, isSameContents, isValidContent, isVisible, parseUrlParams, wait } from './conditions.cjs';
|
|
16
17
|
export { default as isEqual } from 'fast-deep-equal';
|
|
17
18
|
import '@usertour/types';
|
|
18
19
|
import './storage.cjs';
|