@usertour/helpers 0.0.11 → 0.0.12
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-UT6OPCUX.js +460 -0
- package/dist/conditions.cjs +611 -0
- package/dist/conditions.d.cts +33 -0
- package/dist/conditions.d.ts +33 -0
- package/dist/conditions.js +46 -0
- package/dist/index.cjs +460 -2
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +56 -14
- package/package.json +3 -2
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PRIORITIES,
|
|
3
|
+
activedContentCondition,
|
|
4
|
+
activedContentRulesConditions,
|
|
5
|
+
activedRulesConditions,
|
|
6
|
+
checklistIsDimissed,
|
|
7
|
+
checklistIsSeen,
|
|
8
|
+
completeEventMapping,
|
|
9
|
+
filterAutoStartContent,
|
|
10
|
+
findLatestEvent,
|
|
11
|
+
flowIsDismissed,
|
|
12
|
+
flowIsSeen,
|
|
13
|
+
isActive,
|
|
14
|
+
isActiveContent,
|
|
15
|
+
isDismissedEventMapping,
|
|
16
|
+
isHasActivedContents,
|
|
17
|
+
isSameContents,
|
|
18
|
+
isValidContent,
|
|
19
|
+
parseUrlParams,
|
|
20
|
+
rulesTypes,
|
|
21
|
+
wait
|
|
22
|
+
} from "./chunk-UT6OPCUX.js";
|
|
23
|
+
import "./chunk-FNQIIEWK.js";
|
|
24
|
+
import "./chunk-XEO3YXBM.js";
|
|
25
|
+
export {
|
|
26
|
+
PRIORITIES,
|
|
27
|
+
activedContentCondition,
|
|
28
|
+
activedContentRulesConditions,
|
|
29
|
+
activedRulesConditions,
|
|
30
|
+
checklistIsDimissed,
|
|
31
|
+
checklistIsSeen,
|
|
32
|
+
completeEventMapping,
|
|
33
|
+
filterAutoStartContent,
|
|
34
|
+
findLatestEvent,
|
|
35
|
+
flowIsDismissed,
|
|
36
|
+
flowIsSeen,
|
|
37
|
+
isActive,
|
|
38
|
+
isActiveContent,
|
|
39
|
+
isDismissedEventMapping,
|
|
40
|
+
isHasActivedContents,
|
|
41
|
+
isSameContents,
|
|
42
|
+
isValidContent,
|
|
43
|
+
parseUrlParams,
|
|
44
|
+
rulesTypes,
|
|
45
|
+
wait
|
|
46
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -37,12 +37,19 @@ var src_exports = {};
|
|
|
37
37
|
__export(src_exports, {
|
|
38
38
|
AbortController: () => AbortController,
|
|
39
39
|
ArrayProto: () => ArrayProto,
|
|
40
|
+
PRIORITIES: () => PRIORITIES,
|
|
40
41
|
XMLHttpRequest: () => XMLHttpRequest,
|
|
41
42
|
absoluteUrl: () => absoluteUrl,
|
|
43
|
+
activedContentCondition: () => activedContentCondition,
|
|
44
|
+
activedContentRulesConditions: () => activedContentRulesConditions,
|
|
45
|
+
activedRulesConditions: () => activedRulesConditions,
|
|
42
46
|
assignableWindow: () => assignableWindow,
|
|
43
47
|
autoStartConditions: () => autoStartConditions,
|
|
44
48
|
buildConfig: () => buildConfig,
|
|
49
|
+
checklistIsDimissed: () => checklistIsDimissed,
|
|
50
|
+
checklistIsSeen: () => checklistIsSeen,
|
|
45
51
|
cn: () => cn,
|
|
52
|
+
completeEventMapping: () => completeEventMapping,
|
|
46
53
|
conditionsIsSame: () => conditionsIsSame,
|
|
47
54
|
convertSettings: () => convertSettings,
|
|
48
55
|
convertToCssVars: () => convertToCssVars,
|
|
@@ -53,6 +60,10 @@ __export(src_exports, {
|
|
|
53
60
|
document: () => document,
|
|
54
61
|
evalCode: () => evalCode,
|
|
55
62
|
fetch: () => fetch,
|
|
63
|
+
filterAutoStartContent: () => filterAutoStartContent,
|
|
64
|
+
findLatestEvent: () => findLatestEvent,
|
|
65
|
+
flowIsDismissed: () => flowIsDismissed,
|
|
66
|
+
flowIsSeen: () => flowIsSeen,
|
|
56
67
|
formatDate: () => formatDate,
|
|
57
68
|
generateAutoStateColors: () => generateAutoStateColors,
|
|
58
69
|
getAuthToken: () => getAuthToken,
|
|
@@ -75,10 +86,13 @@ __export(src_exports, {
|
|
|
75
86
|
hexToHSLString: () => hexToHSLString,
|
|
76
87
|
hexToRGBStr: () => hexToRGBStr,
|
|
77
88
|
hexToRgb: () => hexToRgb,
|
|
89
|
+
isActive: () => isActive,
|
|
90
|
+
isActiveContent: () => isActiveContent,
|
|
78
91
|
isArray: () => isArray,
|
|
79
92
|
isBoolean: () => isBoolean,
|
|
80
93
|
isDark: () => isDark,
|
|
81
94
|
isDate: () => isDate,
|
|
95
|
+
isDismissedEventMapping: () => isDismissedEventMapping,
|
|
82
96
|
isDocument: () => isDocument,
|
|
83
97
|
isEmptyObject: () => isEmptyObject,
|
|
84
98
|
isEmptyString: () => isEmptyString,
|
|
@@ -86,6 +100,7 @@ __export(src_exports, {
|
|
|
86
100
|
isFile: () => isFile,
|
|
87
101
|
isFormData: () => isFormData,
|
|
88
102
|
isFunction: () => isFunction,
|
|
103
|
+
isHasActivedContents: () => isHasActivedContents,
|
|
89
104
|
isMatchUrlPattern: () => isMatchUrlPattern,
|
|
90
105
|
isNull: () => isNull,
|
|
91
106
|
isNullish: () => isNullish,
|
|
@@ -93,21 +108,26 @@ __export(src_exports, {
|
|
|
93
108
|
isObject: () => isObject,
|
|
94
109
|
isPublishedAtLeastOneEnvironment: () => isPublishedAtLeastOneEnvironment,
|
|
95
110
|
isPublishedInAllEnvironments: () => isPublishedInAllEnvironments,
|
|
111
|
+
isSameContents: () => isSameContents,
|
|
96
112
|
isString: () => isString,
|
|
97
113
|
isUint8Array: () => isUint8Array,
|
|
98
114
|
isUndefined: () => isUndefined,
|
|
99
115
|
isUrl: () => isUrl,
|
|
116
|
+
isValidContent: () => isValidContent,
|
|
100
117
|
isValidSelector: () => isValidSelector,
|
|
101
|
-
location: () =>
|
|
118
|
+
location: () => location2,
|
|
102
119
|
mergeThemeDefaultSettings: () => mergeThemeDefaultSettings,
|
|
103
120
|
nativeForEach: () => nativeForEach,
|
|
104
121
|
nativeIndexOf: () => nativeIndexOf,
|
|
105
122
|
navigator: () => navigator,
|
|
123
|
+
parseUrlParams: () => parseUrlParams,
|
|
106
124
|
removeAuthToken: () => removeAuthToken,
|
|
125
|
+
rulesTypes: () => rulesTypes,
|
|
107
126
|
setAuthToken: () => setAuthToken,
|
|
108
127
|
storage: () => storage,
|
|
109
128
|
userAgent: () => userAgent,
|
|
110
129
|
uuidV4: () => uuidV4,
|
|
130
|
+
wait: () => wait,
|
|
111
131
|
window: () => win
|
|
112
132
|
});
|
|
113
133
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -812,7 +832,7 @@ var nativeForEach = ArrayProto.forEach;
|
|
|
812
832
|
var nativeIndexOf = ArrayProto.indexOf;
|
|
813
833
|
var navigator = global == null ? void 0 : global.navigator;
|
|
814
834
|
var document = global == null ? void 0 : global.document;
|
|
815
|
-
var
|
|
835
|
+
var location2 = global == null ? void 0 : global.location;
|
|
816
836
|
var fetch = global == null ? void 0 : global.fetch;
|
|
817
837
|
var XMLHttpRequest = (global == null ? void 0 : global.XMLHttpRequest) && "withCredentials" in new global.XMLHttpRequest() ? global.XMLHttpRequest : void 0;
|
|
818
838
|
var AbortController = global == null ? void 0 : global.AbortController;
|
|
@@ -1086,16 +1106,441 @@ var getRandomColor = () => {
|
|
|
1086
1106
|
];
|
|
1087
1107
|
return colors[Math.floor(Math.random() * colors.length)];
|
|
1088
1108
|
};
|
|
1109
|
+
|
|
1110
|
+
// src/conditions.ts
|
|
1111
|
+
var import_types4 = require("@usertour/types");
|
|
1112
|
+
var import_date_fns = require("date-fns");
|
|
1113
|
+
var PRIORITIES = [
|
|
1114
|
+
import_types4.ContentPriority.HIGHEST,
|
|
1115
|
+
import_types4.ContentPriority.HIGH,
|
|
1116
|
+
import_types4.ContentPriority.MEDIUM,
|
|
1117
|
+
import_types4.ContentPriority.LOW,
|
|
1118
|
+
import_types4.ContentPriority.LOWEST
|
|
1119
|
+
];
|
|
1120
|
+
var rulesTypes = Object.values(import_types4.RulesType);
|
|
1121
|
+
var isActiveRulesByCurrentPage = (rules) => {
|
|
1122
|
+
const { excludes, includes } = rules.data;
|
|
1123
|
+
if (location) {
|
|
1124
|
+
const href = location.href;
|
|
1125
|
+
return isMatchUrlPattern(href, includes, excludes);
|
|
1126
|
+
}
|
|
1127
|
+
return false;
|
|
1128
|
+
};
|
|
1129
|
+
var isActiveRulesByCurrentTime = (rules) => {
|
|
1130
|
+
const { endDate, endDateHour, endDateMinute, startDate, startDateHour, startDateMinute } = rules.data;
|
|
1131
|
+
const startTime = /* @__PURE__ */ new Date(`${startDate} ${startDateHour}:${startDateMinute}:00`);
|
|
1132
|
+
const endTime = /* @__PURE__ */ new Date(`${endDate} ${endDateHour}:${endDateMinute}:00`);
|
|
1133
|
+
const now = /* @__PURE__ */ new Date();
|
|
1134
|
+
if (!endDate) {
|
|
1135
|
+
return (0, import_date_fns.isAfter)(now, startTime);
|
|
1136
|
+
}
|
|
1137
|
+
return (0, import_date_fns.isAfter)(now, startTime) && (0, import_date_fns.isBefore)(now, endTime);
|
|
1138
|
+
};
|
|
1139
|
+
var isActivedContentRulesCondition = (rules, contentSession) => {
|
|
1140
|
+
const { contentId, logic } = rules.data;
|
|
1141
|
+
const { latestSession, seenSessions, completedSessions } = contentSession;
|
|
1142
|
+
if (!contentId || !logic || contentId !== contentSession.contentId) {
|
|
1143
|
+
return false;
|
|
1144
|
+
}
|
|
1145
|
+
if (logic === import_types4.ContentConditionLogic.ACTIVED || logic === import_types4.ContentConditionLogic.UNACTIVED) {
|
|
1146
|
+
if (!latestSession) {
|
|
1147
|
+
return logic === import_types4.ContentConditionLogic.UNACTIVED;
|
|
1148
|
+
}
|
|
1149
|
+
const isActived = !(flowIsDismissed(latestSession) || checklistIsDimissed(latestSession));
|
|
1150
|
+
return logic === import_types4.ContentConditionLogic.ACTIVED ? isActived : !isActived;
|
|
1151
|
+
}
|
|
1152
|
+
const isSeen = seenSessions > 0;
|
|
1153
|
+
const isCompleted = completedSessions > 0;
|
|
1154
|
+
if (logic === import_types4.ContentConditionLogic.SEEN || logic === import_types4.ContentConditionLogic.UNSEEN) {
|
|
1155
|
+
return logic === import_types4.ContentConditionLogic.SEEN ? isSeen : !isSeen;
|
|
1156
|
+
}
|
|
1157
|
+
if (logic === import_types4.ContentConditionLogic.COMPLETED || logic === import_types4.ContentConditionLogic.UNCOMPLETED) {
|
|
1158
|
+
return logic === import_types4.ContentConditionLogic.COMPLETED ? isCompleted : !isCompleted;
|
|
1159
|
+
}
|
|
1160
|
+
return false;
|
|
1161
|
+
};
|
|
1162
|
+
var isValidRulesType = (type) => {
|
|
1163
|
+
return rulesTypes.includes(type);
|
|
1164
|
+
};
|
|
1165
|
+
var isActiveRules = async (rules) => {
|
|
1166
|
+
if (!isValidRulesType(rules.type)) {
|
|
1167
|
+
return true;
|
|
1168
|
+
}
|
|
1169
|
+
switch (rules.type) {
|
|
1170
|
+
case import_types4.RulesType.CURRENT_PAGE:
|
|
1171
|
+
return isActiveRulesByCurrentPage(rules);
|
|
1172
|
+
case import_types4.RulesType.TIME:
|
|
1173
|
+
return isActiveRulesByCurrentTime(rules);
|
|
1174
|
+
default:
|
|
1175
|
+
return rules.actived;
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
var activedRulesConditions = async (conditions, rewrite) => {
|
|
1179
|
+
const rulesCondition = [...conditions];
|
|
1180
|
+
for (let j = 0; j < rulesCondition.length; j++) {
|
|
1181
|
+
const rules = rulesCondition[j];
|
|
1182
|
+
if (rules.type !== "group") {
|
|
1183
|
+
if (rewrite == null ? void 0 : rewrite[rules.type]) {
|
|
1184
|
+
rulesCondition[j].actived = true;
|
|
1185
|
+
} else {
|
|
1186
|
+
rulesCondition[j].actived = await isActiveRules(rules);
|
|
1187
|
+
}
|
|
1188
|
+
} else if (rules.conditions) {
|
|
1189
|
+
rulesCondition[j].conditions = await activedRulesConditions(rules.conditions);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
return rulesCondition;
|
|
1193
|
+
};
|
|
1194
|
+
var activedContentRulesConditions = async (conditions, contents) => {
|
|
1195
|
+
const rulesCondition = [...conditions];
|
|
1196
|
+
for (let j = 0; j < rulesCondition.length; j++) {
|
|
1197
|
+
const rules = rulesCondition[j];
|
|
1198
|
+
if (rules.type !== "group") {
|
|
1199
|
+
if (rules.type === import_types4.RulesType.CONTENT) {
|
|
1200
|
+
const content = contents.find((c) => c.contentId === rules.data.contentId);
|
|
1201
|
+
if (content) {
|
|
1202
|
+
const contentSession = {
|
|
1203
|
+
contentId: content.contentId,
|
|
1204
|
+
latestSession: content.latestSession,
|
|
1205
|
+
totalSessions: content.totalSessions,
|
|
1206
|
+
dismissedSessions: content.dismissedSessions,
|
|
1207
|
+
completedSessions: content.completedSessions,
|
|
1208
|
+
seenSessions: content.seenSessions
|
|
1209
|
+
};
|
|
1210
|
+
rulesCondition[j].actived = isActivedContentRulesCondition(rules, contentSession);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
} else if (rules.conditions) {
|
|
1214
|
+
rulesCondition[j].conditions = await activedContentRulesConditions(
|
|
1215
|
+
rules.conditions,
|
|
1216
|
+
contents
|
|
1217
|
+
);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
return rulesCondition;
|
|
1221
|
+
};
|
|
1222
|
+
var activedContentCondition = async (contents) => {
|
|
1223
|
+
const _contents = JSON.parse(JSON.stringify(contents));
|
|
1224
|
+
for (let index = 0; index < _contents.length; index++) {
|
|
1225
|
+
const content = _contents[index];
|
|
1226
|
+
const { enabledAutoStartRules, autoStartRules, hideRules, enabledHideRules } = content.config;
|
|
1227
|
+
if (enabledAutoStartRules && autoStartRules && autoStartRules.length > 0) {
|
|
1228
|
+
content.config.autoStartRules = await activedRulesConditions(autoStartRules);
|
|
1229
|
+
}
|
|
1230
|
+
if (enabledHideRules && hideRules && hideRules.length > 0) {
|
|
1231
|
+
content.config.hideRules = await activedRulesConditions(hideRules);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
return _contents;
|
|
1235
|
+
};
|
|
1236
|
+
var isActive = (autoStartRules) => {
|
|
1237
|
+
if (!autoStartRules || autoStartRules.length === 0) {
|
|
1238
|
+
return false;
|
|
1239
|
+
}
|
|
1240
|
+
const operator = autoStartRules[0].operators;
|
|
1241
|
+
const actives = autoStartRules.filter((rule) => {
|
|
1242
|
+
if (!rule.conditions) {
|
|
1243
|
+
return rule.actived;
|
|
1244
|
+
}
|
|
1245
|
+
return isActive(rule.conditions);
|
|
1246
|
+
});
|
|
1247
|
+
return operator === "and" ? actives.length === autoStartRules.length : actives.length > 0;
|
|
1248
|
+
};
|
|
1249
|
+
var isActiveContent = (content) => {
|
|
1250
|
+
const { enabledAutoStartRules, autoStartRules } = content.config;
|
|
1251
|
+
if (!enabledAutoStartRules || !isActive(autoStartRules)) {
|
|
1252
|
+
return false;
|
|
1253
|
+
}
|
|
1254
|
+
return true;
|
|
1255
|
+
};
|
|
1256
|
+
var priorityCompare = (a, b) => {
|
|
1257
|
+
var _a, _b, _c, _d;
|
|
1258
|
+
const a1 = (_b = (_a = a == null ? void 0 : a.config) == null ? void 0 : _a.autoStartRulesSetting) == null ? void 0 : _b.priority;
|
|
1259
|
+
const a2 = (_d = (_c = b == null ? void 0 : b.config) == null ? void 0 : _c.autoStartRulesSetting) == null ? void 0 : _d.priority;
|
|
1260
|
+
if (!a1 || !a2) {
|
|
1261
|
+
return 0;
|
|
1262
|
+
}
|
|
1263
|
+
const index1 = PRIORITIES.indexOf(a1);
|
|
1264
|
+
const index2 = PRIORITIES.indexOf(a2);
|
|
1265
|
+
if (index1 > index2) {
|
|
1266
|
+
return 1;
|
|
1267
|
+
}
|
|
1268
|
+
if (index1 < index2) {
|
|
1269
|
+
return -1;
|
|
1270
|
+
}
|
|
1271
|
+
return 0;
|
|
1272
|
+
};
|
|
1273
|
+
var filterAutoStartContent = (contents, type) => {
|
|
1274
|
+
return contents.filter((content) => {
|
|
1275
|
+
const isActive2 = isActiveContent(content);
|
|
1276
|
+
const isValid = isValidContent(content, contents);
|
|
1277
|
+
return content.type === type && isActive2 && isValid;
|
|
1278
|
+
}).sort(priorityCompare);
|
|
1279
|
+
};
|
|
1280
|
+
var isHasActivedContents = (source, dest) => {
|
|
1281
|
+
for (let index = 0; index < source.length; index++) {
|
|
1282
|
+
const content1 = source[index];
|
|
1283
|
+
const content2 = dest.find((c) => c.id === content1.id);
|
|
1284
|
+
if (!content2) {
|
|
1285
|
+
return true;
|
|
1286
|
+
}
|
|
1287
|
+
if (isActiveContent(content1) !== isActiveContent(content2)) {
|
|
1288
|
+
return true;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
return false;
|
|
1292
|
+
};
|
|
1293
|
+
var isSameContents = (source, dest) => {
|
|
1294
|
+
if (!source || !dest || source.length !== dest.length) {
|
|
1295
|
+
return false;
|
|
1296
|
+
}
|
|
1297
|
+
for (let index = 0; index < source.length; index++) {
|
|
1298
|
+
const content1 = source[index];
|
|
1299
|
+
const content2 = dest.find((c) => c.id === content1.id);
|
|
1300
|
+
if (!content2) {
|
|
1301
|
+
return false;
|
|
1302
|
+
}
|
|
1303
|
+
if (!conditionsIsSame(content1.config.autoStartRules, content2.config.autoStartRules)) {
|
|
1304
|
+
return false;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
return true;
|
|
1308
|
+
};
|
|
1309
|
+
var getLatestEvent = (currentContent, contents, eventCodeName) => {
|
|
1310
|
+
var _a;
|
|
1311
|
+
const bizEvents = [];
|
|
1312
|
+
const contentId = currentContent.id;
|
|
1313
|
+
const contentType = currentContent.type;
|
|
1314
|
+
for (let index = 0; index < contents.length; index++) {
|
|
1315
|
+
const content = contents[index];
|
|
1316
|
+
if (content.id === contentId || content.type !== contentType) {
|
|
1317
|
+
continue;
|
|
1318
|
+
}
|
|
1319
|
+
const sessionBizEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
|
|
1320
|
+
if (sessionBizEvents && sessionBizEvents.length > 0) {
|
|
1321
|
+
bizEvents.push(...sessionBizEvents.filter((e) => {
|
|
1322
|
+
var _a2;
|
|
1323
|
+
return ((_a2 = e == null ? void 0 : e.event) == null ? void 0 : _a2.codeName) === eventCodeName;
|
|
1324
|
+
}));
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
return findLatestEvent(bizEvents);
|
|
1328
|
+
};
|
|
1329
|
+
var findLatestEvent = (bizEvents) => {
|
|
1330
|
+
const initialValue = bizEvents[0];
|
|
1331
|
+
const lastEvent = bizEvents.reduce(
|
|
1332
|
+
(accumulator, currentValue) => {
|
|
1333
|
+
if ((0, import_date_fns.isAfter)(new Date(currentValue.createdAt), new Date(accumulator.createdAt))) {
|
|
1334
|
+
return currentValue;
|
|
1335
|
+
}
|
|
1336
|
+
return accumulator;
|
|
1337
|
+
},
|
|
1338
|
+
initialValue
|
|
1339
|
+
);
|
|
1340
|
+
return lastEvent;
|
|
1341
|
+
};
|
|
1342
|
+
var completeEventMapping = {
|
|
1343
|
+
[import_types4.ContentDataType.FLOW]: import_types4.BizEvents.FLOW_COMPLETED,
|
|
1344
|
+
[import_types4.ContentDataType.LAUNCHER]: import_types4.BizEvents.LAUNCHER_ACTIVATED,
|
|
1345
|
+
[import_types4.ContentDataType.CHECKLIST]: import_types4.BizEvents.CHECKLIST_COMPLETED
|
|
1346
|
+
};
|
|
1347
|
+
var showEventMapping = {
|
|
1348
|
+
[import_types4.ContentDataType.FLOW]: import_types4.BizEvents.FLOW_STEP_SEEN,
|
|
1349
|
+
[import_types4.ContentDataType.LAUNCHER]: import_types4.BizEvents.LAUNCHER_SEEN,
|
|
1350
|
+
[import_types4.ContentDataType.CHECKLIST]: import_types4.BizEvents.CHECKLIST_SEEN
|
|
1351
|
+
};
|
|
1352
|
+
var isDismissedEventMapping = {
|
|
1353
|
+
[import_types4.ContentDataType.FLOW]: import_types4.BizEvents.FLOW_ENDED,
|
|
1354
|
+
[import_types4.ContentDataType.LAUNCHER]: import_types4.BizEvents.LAUNCHER_DISMISSED,
|
|
1355
|
+
[import_types4.ContentDataType.CHECKLIST]: import_types4.BizEvents.CHECKLIST_DISMISSED
|
|
1356
|
+
};
|
|
1357
|
+
var isGreaterThenDuration = (dateLeft, dateRight, unit, duration) => {
|
|
1358
|
+
switch (unit) {
|
|
1359
|
+
case import_types4.FrequencyUnits.SECONDS: {
|
|
1360
|
+
if ((0, import_date_fns.differenceInSeconds)(dateLeft, dateRight) >= duration) {
|
|
1361
|
+
return true;
|
|
1362
|
+
}
|
|
1363
|
+
return false;
|
|
1364
|
+
}
|
|
1365
|
+
case import_types4.FrequencyUnits.MINUTES:
|
|
1366
|
+
if ((0, import_date_fns.differenceInMinutes)(dateLeft, dateRight) >= duration) {
|
|
1367
|
+
return true;
|
|
1368
|
+
}
|
|
1369
|
+
return false;
|
|
1370
|
+
case import_types4.FrequencyUnits.HOURS:
|
|
1371
|
+
if ((0, import_date_fns.differenceInHours)(dateLeft, dateRight) >= duration) {
|
|
1372
|
+
return true;
|
|
1373
|
+
}
|
|
1374
|
+
return false;
|
|
1375
|
+
case import_types4.FrequencyUnits.DAYES:
|
|
1376
|
+
if ((0, import_date_fns.differenceInDays)(dateLeft, dateRight) >= duration) {
|
|
1377
|
+
return true;
|
|
1378
|
+
}
|
|
1379
|
+
return false;
|
|
1380
|
+
default:
|
|
1381
|
+
return false;
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
var checklistIsDimissed = (latestSession) => {
|
|
1385
|
+
var _a;
|
|
1386
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
|
|
1387
|
+
(event) => {
|
|
1388
|
+
var _a2;
|
|
1389
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.CHECKLIST_DISMISSED;
|
|
1390
|
+
}
|
|
1391
|
+
);
|
|
1392
|
+
};
|
|
1393
|
+
var flowIsDismissed = (latestSession) => {
|
|
1394
|
+
var _a;
|
|
1395
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find((event) => {
|
|
1396
|
+
var _a2;
|
|
1397
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.FLOW_ENDED;
|
|
1398
|
+
});
|
|
1399
|
+
};
|
|
1400
|
+
var flowIsSeen = (latestSession) => {
|
|
1401
|
+
var _a;
|
|
1402
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
|
|
1403
|
+
(event) => {
|
|
1404
|
+
var _a2;
|
|
1405
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.FLOW_STEP_SEEN;
|
|
1406
|
+
}
|
|
1407
|
+
);
|
|
1408
|
+
};
|
|
1409
|
+
var checklistIsSeen = (latestSession) => {
|
|
1410
|
+
var _a;
|
|
1411
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
|
|
1412
|
+
(event) => {
|
|
1413
|
+
var _a2;
|
|
1414
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === import_types4.BizEvents.CHECKLIST_SEEN;
|
|
1415
|
+
}
|
|
1416
|
+
);
|
|
1417
|
+
};
|
|
1418
|
+
var isValidContent = (content, contents) => {
|
|
1419
|
+
var _a;
|
|
1420
|
+
const now = /* @__PURE__ */ new Date();
|
|
1421
|
+
if (content.type === import_types4.ContentDataType.FLOW) {
|
|
1422
|
+
if (!content.steps || content.steps.length === 0) {
|
|
1423
|
+
return false;
|
|
1424
|
+
}
|
|
1425
|
+
} else {
|
|
1426
|
+
if (!content.data) {
|
|
1427
|
+
return false;
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
if (!content.config.autoStartRulesSetting) {
|
|
1431
|
+
return true;
|
|
1432
|
+
}
|
|
1433
|
+
const { frequency, startIfNotComplete } = content.config.autoStartRulesSetting;
|
|
1434
|
+
const completedSessions = content.completedSessions;
|
|
1435
|
+
const dismissedSessions = content.dismissedSessions;
|
|
1436
|
+
if (startIfNotComplete && completedSessions > 0) {
|
|
1437
|
+
return false;
|
|
1438
|
+
}
|
|
1439
|
+
if (!frequency) {
|
|
1440
|
+
return true;
|
|
1441
|
+
}
|
|
1442
|
+
const contentType = content.type;
|
|
1443
|
+
const lastEventName = showEventMapping[contentType];
|
|
1444
|
+
const lastEvent = getLatestEvent(content, contents, lastEventName);
|
|
1445
|
+
const contentEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
|
|
1446
|
+
if (lastEvent && frequency && frequency.atLeast && !isGreaterThenDuration(
|
|
1447
|
+
now,
|
|
1448
|
+
new Date(lastEvent.createdAt),
|
|
1449
|
+
frequency.atLeast.unit,
|
|
1450
|
+
frequency.atLeast.duration
|
|
1451
|
+
)) {
|
|
1452
|
+
return false;
|
|
1453
|
+
}
|
|
1454
|
+
if (frequency.frequency === import_types4.Frequency.ONCE) {
|
|
1455
|
+
if (dismissedSessions > 0) {
|
|
1456
|
+
return false;
|
|
1457
|
+
}
|
|
1458
|
+
return true;
|
|
1459
|
+
}
|
|
1460
|
+
const showEventName = showEventMapping[contentType];
|
|
1461
|
+
const showEvents = contentEvents == null ? void 0 : contentEvents.filter(
|
|
1462
|
+
(e) => {
|
|
1463
|
+
var _a2, _b;
|
|
1464
|
+
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);
|
|
1465
|
+
}
|
|
1466
|
+
);
|
|
1467
|
+
if (!showEvents || showEvents.length === 0) {
|
|
1468
|
+
return true;
|
|
1469
|
+
}
|
|
1470
|
+
const lastShowEvent = findLatestEvent(showEvents);
|
|
1471
|
+
const lastShowEventDate = new Date(lastShowEvent.createdAt);
|
|
1472
|
+
if (frequency.frequency === import_types4.Frequency.MULTIPLE) {
|
|
1473
|
+
if (frequency.every.times && dismissedSessions >= frequency.every.times) {
|
|
1474
|
+
return false;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
if (frequency.frequency === import_types4.Frequency.MULTIPLE || frequency.frequency === import_types4.Frequency.UNLIMITED) {
|
|
1478
|
+
if (!isGreaterThenDuration(now, lastShowEventDate, frequency.every.unit, frequency.every.duration)) {
|
|
1479
|
+
return false;
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
return true;
|
|
1483
|
+
};
|
|
1484
|
+
var parseUrlParams = (url, paramName) => {
|
|
1485
|
+
if (!url || !paramName) {
|
|
1486
|
+
return null;
|
|
1487
|
+
}
|
|
1488
|
+
try {
|
|
1489
|
+
const urlObj = new URL(url);
|
|
1490
|
+
const searchParams = new URLSearchParams(urlObj.search);
|
|
1491
|
+
if (searchParams.has(paramName)) {
|
|
1492
|
+
return searchParams.get(paramName);
|
|
1493
|
+
}
|
|
1494
|
+
if (urlObj.hash) {
|
|
1495
|
+
const hashSearch = urlObj.hash.split("?")[1];
|
|
1496
|
+
if (hashSearch) {
|
|
1497
|
+
const hashParams = new URLSearchParams(hashSearch);
|
|
1498
|
+
if (hashParams.has(paramName)) {
|
|
1499
|
+
return hashParams.get(paramName);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
return null;
|
|
1504
|
+
} catch (error) {
|
|
1505
|
+
console.error("Error parsing URL:", error);
|
|
1506
|
+
return null;
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
var wait = (seconds) => {
|
|
1510
|
+
if (typeof seconds !== "number" || Number.isNaN(seconds)) {
|
|
1511
|
+
return Promise.reject(new Error("Invalid wait time: must be a number"));
|
|
1512
|
+
}
|
|
1513
|
+
if (seconds < 0) {
|
|
1514
|
+
return Promise.reject(new Error("Invalid wait time: cannot be negative"));
|
|
1515
|
+
}
|
|
1516
|
+
if (seconds === 0) {
|
|
1517
|
+
return Promise.resolve();
|
|
1518
|
+
}
|
|
1519
|
+
return new Promise((resolve, reject) => {
|
|
1520
|
+
try {
|
|
1521
|
+
setTimeout(resolve, seconds * 1e3);
|
|
1522
|
+
} catch (error) {
|
|
1523
|
+
reject(error);
|
|
1524
|
+
}
|
|
1525
|
+
});
|
|
1526
|
+
};
|
|
1089
1527
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1090
1528
|
0 && (module.exports = {
|
|
1091
1529
|
AbortController,
|
|
1092
1530
|
ArrayProto,
|
|
1531
|
+
PRIORITIES,
|
|
1093
1532
|
XMLHttpRequest,
|
|
1094
1533
|
absoluteUrl,
|
|
1534
|
+
activedContentCondition,
|
|
1535
|
+
activedContentRulesConditions,
|
|
1536
|
+
activedRulesConditions,
|
|
1095
1537
|
assignableWindow,
|
|
1096
1538
|
autoStartConditions,
|
|
1097
1539
|
buildConfig,
|
|
1540
|
+
checklistIsDimissed,
|
|
1541
|
+
checklistIsSeen,
|
|
1098
1542
|
cn,
|
|
1543
|
+
completeEventMapping,
|
|
1099
1544
|
conditionsIsSame,
|
|
1100
1545
|
convertSettings,
|
|
1101
1546
|
convertToCssVars,
|
|
@@ -1106,6 +1551,10 @@ var getRandomColor = () => {
|
|
|
1106
1551
|
document,
|
|
1107
1552
|
evalCode,
|
|
1108
1553
|
fetch,
|
|
1554
|
+
filterAutoStartContent,
|
|
1555
|
+
findLatestEvent,
|
|
1556
|
+
flowIsDismissed,
|
|
1557
|
+
flowIsSeen,
|
|
1109
1558
|
formatDate,
|
|
1110
1559
|
generateAutoStateColors,
|
|
1111
1560
|
getAuthToken,
|
|
@@ -1128,10 +1577,13 @@ var getRandomColor = () => {
|
|
|
1128
1577
|
hexToHSLString,
|
|
1129
1578
|
hexToRGBStr,
|
|
1130
1579
|
hexToRgb,
|
|
1580
|
+
isActive,
|
|
1581
|
+
isActiveContent,
|
|
1131
1582
|
isArray,
|
|
1132
1583
|
isBoolean,
|
|
1133
1584
|
isDark,
|
|
1134
1585
|
isDate,
|
|
1586
|
+
isDismissedEventMapping,
|
|
1135
1587
|
isDocument,
|
|
1136
1588
|
isEmptyObject,
|
|
1137
1589
|
isEmptyString,
|
|
@@ -1139,6 +1591,7 @@ var getRandomColor = () => {
|
|
|
1139
1591
|
isFile,
|
|
1140
1592
|
isFormData,
|
|
1141
1593
|
isFunction,
|
|
1594
|
+
isHasActivedContents,
|
|
1142
1595
|
isMatchUrlPattern,
|
|
1143
1596
|
isNull,
|
|
1144
1597
|
isNullish,
|
|
@@ -1146,20 +1599,25 @@ var getRandomColor = () => {
|
|
|
1146
1599
|
isObject,
|
|
1147
1600
|
isPublishedAtLeastOneEnvironment,
|
|
1148
1601
|
isPublishedInAllEnvironments,
|
|
1602
|
+
isSameContents,
|
|
1149
1603
|
isString,
|
|
1150
1604
|
isUint8Array,
|
|
1151
1605
|
isUndefined,
|
|
1152
1606
|
isUrl,
|
|
1607
|
+
isValidContent,
|
|
1153
1608
|
isValidSelector,
|
|
1154
1609
|
location,
|
|
1155
1610
|
mergeThemeDefaultSettings,
|
|
1156
1611
|
nativeForEach,
|
|
1157
1612
|
nativeIndexOf,
|
|
1158
1613
|
navigator,
|
|
1614
|
+
parseUrlParams,
|
|
1159
1615
|
removeAuthToken,
|
|
1616
|
+
rulesTypes,
|
|
1160
1617
|
setAuthToken,
|
|
1161
1618
|
storage,
|
|
1162
1619
|
userAgent,
|
|
1163
1620
|
uuidV4,
|
|
1621
|
+
wait,
|
|
1164
1622
|
window
|
|
1165
1623
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,7 @@ export { isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from '
|
|
|
11
11
|
export { deepClone } from './utils.cjs';
|
|
12
12
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
|
|
13
13
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
|
|
14
|
+
export { PRIORITIES, activedContentCondition, activedContentRulesConditions, activedRulesConditions, checklistIsDimissed, checklistIsSeen, completeEventMapping, filterAutoStartContent, findLatestEvent, flowIsDismissed, flowIsSeen, isActive, isActiveContent, isDismissedEventMapping, isHasActivedContents, isSameContents, isValidContent, parseUrlParams, rulesTypes, wait } from './conditions.cjs';
|
|
14
15
|
export { default as isEqual } from 'fast-deep-equal';
|
|
15
16
|
import '@usertour/types';
|
|
16
17
|
import './storage.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from '
|
|
|
11
11
|
export { deepClone } from './utils.js';
|
|
12
12
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.js';
|
|
13
13
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
|
|
14
|
+
export { PRIORITIES, activedContentCondition, activedContentRulesConditions, activedRulesConditions, checklistIsDimissed, checklistIsSeen, completeEventMapping, filterAutoStartContent, findLatestEvent, flowIsDismissed, flowIsSeen, isActive, isActiveContent, isDismissedEventMapping, isHasActivedContents, isSameContents, isValidContent, parseUrlParams, rulesTypes, wait } from './conditions.js';
|
|
14
15
|
export { default as isEqual } from 'fast-deep-equal';
|
|
15
16
|
import '@usertour/types';
|
|
16
17
|
import './storage.js';
|