@usertour/helpers 0.0.5 → 0.0.7
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-7IK5Q5N2.js +591 -0
- package/dist/chunk-DEG6MTU7.js +318 -0
- package/dist/chunk-Y6FPPOKF.js +28 -0
- package/dist/conditions.cjs +1001 -0
- package/dist/conditions.d.cts +23 -0
- package/dist/conditions.d.ts +23 -0
- package/dist/conditions.js +45 -0
- package/dist/finderx.cjs +346 -0
- package/dist/finderx.d.cts +47 -0
- package/dist/finderx.d.ts +47 -0
- package/dist/finderx.js +15 -0
- package/dist/index.cjs +913 -2
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +68 -17
- 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 +14 -9
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
import {
|
|
2
|
+
finderV2
|
|
3
|
+
} from "./chunk-DEG6MTU7.js";
|
|
4
|
+
import {
|
|
5
|
+
off,
|
|
6
|
+
on
|
|
7
|
+
} from "./chunk-Y6FPPOKF.js";
|
|
8
|
+
import {
|
|
9
|
+
document,
|
|
10
|
+
location
|
|
11
|
+
} from "./chunk-H7VA3ML2.js";
|
|
12
|
+
import {
|
|
13
|
+
conditionsIsSame,
|
|
14
|
+
isMatchUrlPattern
|
|
15
|
+
} from "./chunk-FNQIIEWK.js";
|
|
16
|
+
|
|
17
|
+
// src/conditions.ts
|
|
18
|
+
import { computePosition, hide } from "@floating-ui/dom";
|
|
19
|
+
import {
|
|
20
|
+
BizEvents,
|
|
21
|
+
ContentDataType,
|
|
22
|
+
ContentConditionLogic,
|
|
23
|
+
Frequency,
|
|
24
|
+
FrequencyUnits,
|
|
25
|
+
ElementConditionLogic,
|
|
26
|
+
StringConditionLogic,
|
|
27
|
+
ContentPriority,
|
|
28
|
+
RulesType
|
|
29
|
+
} from "@usertour/types";
|
|
30
|
+
import {
|
|
31
|
+
differenceInDays,
|
|
32
|
+
differenceInHours,
|
|
33
|
+
differenceInMinutes,
|
|
34
|
+
differenceInSeconds,
|
|
35
|
+
isAfter,
|
|
36
|
+
isBefore
|
|
37
|
+
} from "date-fns";
|
|
38
|
+
var rulesTypes = Object.values(RulesType);
|
|
39
|
+
var PRIORITIES = [
|
|
40
|
+
ContentPriority.HIGHEST,
|
|
41
|
+
ContentPriority.HIGH,
|
|
42
|
+
ContentPriority.MEDIUM,
|
|
43
|
+
ContentPriority.LOW,
|
|
44
|
+
ContentPriority.LOWEST
|
|
45
|
+
];
|
|
46
|
+
var isActiveRulesByCurrentPage = (rules) => {
|
|
47
|
+
const { excludes, includes } = rules.data;
|
|
48
|
+
if (location) {
|
|
49
|
+
const href = location.href;
|
|
50
|
+
return isMatchUrlPattern(href, includes, excludes);
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
};
|
|
54
|
+
var isActiveRulesByCurrentTime = (rules) => {
|
|
55
|
+
const { endDate, endDateHour, endDateMinute, startDate, startDateHour, startDateMinute } = rules.data;
|
|
56
|
+
const startTime = /* @__PURE__ */ new Date(`${startDate} ${startDateHour}:${startDateMinute}:00`);
|
|
57
|
+
const endTime = /* @__PURE__ */ new Date(`${endDate} ${endDateHour}:${endDateMinute}:00`);
|
|
58
|
+
const now = /* @__PURE__ */ new Date();
|
|
59
|
+
if (!endDate) {
|
|
60
|
+
return isAfter(now, startTime);
|
|
61
|
+
}
|
|
62
|
+
return isAfter(now, startTime) && isBefore(now, endTime);
|
|
63
|
+
};
|
|
64
|
+
var isActivedContentRulesCondition = (rules, contentSession) => {
|
|
65
|
+
const { contentId, logic } = rules.data;
|
|
66
|
+
const { latestSession, seenSessions, completedSessions } = contentSession;
|
|
67
|
+
if (!contentId || !logic || contentId !== contentSession.contentId) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
if (logic === ContentConditionLogic.ACTIVED || logic === ContentConditionLogic.UNACTIVED) {
|
|
71
|
+
if (!latestSession) {
|
|
72
|
+
return logic === ContentConditionLogic.UNACTIVED;
|
|
73
|
+
}
|
|
74
|
+
const isActived = !(flowIsDismissed(latestSession) || checklistIsDimissed(latestSession));
|
|
75
|
+
return logic === ContentConditionLogic.ACTIVED ? isActived : !isActived;
|
|
76
|
+
}
|
|
77
|
+
const isSeen = seenSessions > 0;
|
|
78
|
+
const isCompleted = completedSessions > 0;
|
|
79
|
+
if (logic === ContentConditionLogic.SEEN || logic === ContentConditionLogic.UNSEEN) {
|
|
80
|
+
return logic === ContentConditionLogic.SEEN ? isSeen : !isSeen;
|
|
81
|
+
}
|
|
82
|
+
if (logic === ContentConditionLogic.COMPLETED || logic === ContentConditionLogic.UNCOMPLETED) {
|
|
83
|
+
return logic === ContentConditionLogic.COMPLETED ? isCompleted : !isCompleted;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
87
|
+
var isVisible = async (el) => {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
if (!((_a = document) == null ? void 0 : _a.body)) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
const { middlewareData } = await computePosition(el, document.body, {
|
|
93
|
+
strategy: "fixed",
|
|
94
|
+
middleware: [hide()]
|
|
95
|
+
});
|
|
96
|
+
if ((_b = middlewareData == null ? void 0 : middlewareData.hide) == null ? void 0 : _b.referenceHidden) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
};
|
|
101
|
+
var cache = /* @__PURE__ */ new Map();
|
|
102
|
+
var isClicked = (el) => {
|
|
103
|
+
if (cache.has(el)) {
|
|
104
|
+
return cache.get(el);
|
|
105
|
+
}
|
|
106
|
+
const onClick = () => {
|
|
107
|
+
cache.set(el, true);
|
|
108
|
+
off(el, "click", onClick);
|
|
109
|
+
};
|
|
110
|
+
on(el, "click", onClick);
|
|
111
|
+
cache.set(el, false);
|
|
112
|
+
return false;
|
|
113
|
+
};
|
|
114
|
+
var isActiveRulesByElement = async (rules) => {
|
|
115
|
+
const { data } = rules;
|
|
116
|
+
if (!document) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const el = finderV2(data.elementData, document);
|
|
120
|
+
const isPresent = el ? await isVisible(el) : false;
|
|
121
|
+
const isDisabled = el ? el.disabled : false;
|
|
122
|
+
switch (data.logic) {
|
|
123
|
+
case ElementConditionLogic.PRESENT:
|
|
124
|
+
return isPresent;
|
|
125
|
+
case ElementConditionLogic.UNPRESENT:
|
|
126
|
+
return !isPresent;
|
|
127
|
+
case ElementConditionLogic.DISABLED:
|
|
128
|
+
return el && isDisabled;
|
|
129
|
+
case ElementConditionLogic.UNDISABLED:
|
|
130
|
+
return el && !isDisabled;
|
|
131
|
+
case ElementConditionLogic.CLICKED:
|
|
132
|
+
return el && isClicked(el);
|
|
133
|
+
case ElementConditionLogic.UNCLICKED:
|
|
134
|
+
return el && !isClicked(el);
|
|
135
|
+
default:
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
var isActiveRulesByTextInput = async (rules) => {
|
|
140
|
+
const {
|
|
141
|
+
data: { elementData, logic, value }
|
|
142
|
+
} = rules;
|
|
143
|
+
if (!document) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const el = finderV2(elementData, document);
|
|
147
|
+
if (!el) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const elValue = el.value;
|
|
151
|
+
switch (logic) {
|
|
152
|
+
case StringConditionLogic.IS:
|
|
153
|
+
return elValue === value;
|
|
154
|
+
case StringConditionLogic.NOT:
|
|
155
|
+
return elValue !== value;
|
|
156
|
+
case StringConditionLogic.CONTAINS:
|
|
157
|
+
return elValue.includes(value);
|
|
158
|
+
case StringConditionLogic.NOT_CONTAIN:
|
|
159
|
+
return !elValue.includes(value);
|
|
160
|
+
case StringConditionLogic.STARTS_WITH:
|
|
161
|
+
return elValue.startsWith(value);
|
|
162
|
+
case StringConditionLogic.ENDS_WITH:
|
|
163
|
+
return elValue.endsWith(value);
|
|
164
|
+
case StringConditionLogic.MATCH:
|
|
165
|
+
return elValue.search(value) !== -1;
|
|
166
|
+
case StringConditionLogic.UNMATCH:
|
|
167
|
+
return elValue.search(value) === -1;
|
|
168
|
+
case StringConditionLogic.ANY:
|
|
169
|
+
return true;
|
|
170
|
+
case StringConditionLogic.EMPTY:
|
|
171
|
+
return !elValue;
|
|
172
|
+
default:
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
var fillCache = /* @__PURE__ */ new Map();
|
|
177
|
+
var isActiveRulesByTextFill = async (rules) => {
|
|
178
|
+
const {
|
|
179
|
+
data: { elementData }
|
|
180
|
+
} = rules;
|
|
181
|
+
if (!document) {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
const el = finderV2(elementData, document);
|
|
185
|
+
if (!el) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
189
|
+
const onKeyup = () => {
|
|
190
|
+
const cacheData = fillCache.get(el);
|
|
191
|
+
const data = { ...cacheData, timestamp: (/* @__PURE__ */ new Date()).getTime() };
|
|
192
|
+
fillCache.set(el, data);
|
|
193
|
+
};
|
|
194
|
+
if (fillCache.has(el)) {
|
|
195
|
+
const { timestamp, value, isActive: isActive2 } = fillCache.get(el);
|
|
196
|
+
if (isActive2) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (timestamp !== -1 && now - timestamp > 1e3 && value !== el.value) {
|
|
200
|
+
off(document, "click", onKeyup);
|
|
201
|
+
fillCache.set(el, { timestamp, value, isActive: true });
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
on(document, "keyup", onKeyup);
|
|
207
|
+
fillCache.set(el, { timestamp: -1, value: el.value, isActive: false });
|
|
208
|
+
return false;
|
|
209
|
+
};
|
|
210
|
+
var isValidRulesType = (type) => {
|
|
211
|
+
return rulesTypes.includes(type);
|
|
212
|
+
};
|
|
213
|
+
var isActiveRules = async (rules) => {
|
|
214
|
+
if (!isValidRulesType(rules.type)) {
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
switch (rules.type) {
|
|
218
|
+
case RulesType.CURRENT_PAGE:
|
|
219
|
+
return isActiveRulesByCurrentPage(rules);
|
|
220
|
+
case RulesType.TIME:
|
|
221
|
+
return isActiveRulesByCurrentTime(rules);
|
|
222
|
+
case RulesType.ELEMENT:
|
|
223
|
+
return await isActiveRulesByElement(rules);
|
|
224
|
+
case RulesType.TEXT_INPUT:
|
|
225
|
+
return await isActiveRulesByTextInput(rules);
|
|
226
|
+
case RulesType.TEXT_FILL:
|
|
227
|
+
return await isActiveRulesByTextFill(rules);
|
|
228
|
+
default:
|
|
229
|
+
return rules.actived;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
var activedRulesConditions = async (conditions, rewrite) => {
|
|
233
|
+
const rulesCondition = [...conditions];
|
|
234
|
+
for (let j = 0; j < rulesCondition.length; j++) {
|
|
235
|
+
const rules = rulesCondition[j];
|
|
236
|
+
if (rules.type !== "group") {
|
|
237
|
+
if (rewrite == null ? void 0 : rewrite[rules.type]) {
|
|
238
|
+
rulesCondition[j].actived = true;
|
|
239
|
+
} else {
|
|
240
|
+
rulesCondition[j].actived = await isActiveRules(rules);
|
|
241
|
+
}
|
|
242
|
+
} else if (rules.conditions) {
|
|
243
|
+
rulesCondition[j].conditions = await activedRulesConditions(rules.conditions);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return rulesCondition;
|
|
247
|
+
};
|
|
248
|
+
var activedContentRulesConditions = async (conditions, contents) => {
|
|
249
|
+
const rulesCondition = [...conditions];
|
|
250
|
+
for (let j = 0; j < rulesCondition.length; j++) {
|
|
251
|
+
const rules = rulesCondition[j];
|
|
252
|
+
if (rules.type !== "group") {
|
|
253
|
+
if (rules.type === RulesType.CONTENT) {
|
|
254
|
+
const content = contents.find((c) => c.contentId === rules.data.contentId);
|
|
255
|
+
if (content) {
|
|
256
|
+
const contentSession = {
|
|
257
|
+
contentId: content.contentId,
|
|
258
|
+
latestSession: content.latestSession,
|
|
259
|
+
totalSessions: content.totalSessions,
|
|
260
|
+
dismissedSessions: content.dismissedSessions,
|
|
261
|
+
completedSessions: content.completedSessions,
|
|
262
|
+
seenSessions: content.seenSessions
|
|
263
|
+
};
|
|
264
|
+
rulesCondition[j].actived = isActivedContentRulesCondition(rules, contentSession);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
} else if (rules.conditions) {
|
|
268
|
+
rulesCondition[j].conditions = await activedContentRulesConditions(
|
|
269
|
+
rules.conditions,
|
|
270
|
+
contents
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return rulesCondition;
|
|
275
|
+
};
|
|
276
|
+
var activedContentCondition = async (contents) => {
|
|
277
|
+
const _contents = JSON.parse(JSON.stringify(contents));
|
|
278
|
+
for (let index = 0; index < _contents.length; index++) {
|
|
279
|
+
const content = _contents[index];
|
|
280
|
+
const { enabledAutoStartRules, autoStartRules, hideRules, enabledHideRules } = content.config;
|
|
281
|
+
if (enabledAutoStartRules && autoStartRules && autoStartRules.length > 0) {
|
|
282
|
+
content.config.autoStartRules = await activedRulesConditions(autoStartRules);
|
|
283
|
+
}
|
|
284
|
+
if (enabledHideRules && hideRules && hideRules.length > 0) {
|
|
285
|
+
content.config.hideRules = await activedRulesConditions(hideRules);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return _contents;
|
|
289
|
+
};
|
|
290
|
+
var isActive = (autoStartRules) => {
|
|
291
|
+
if (!autoStartRules || autoStartRules.length === 0) {
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
const operator = autoStartRules[0].operators;
|
|
295
|
+
const actives = autoStartRules.filter((rule) => {
|
|
296
|
+
if (!rule.conditions) {
|
|
297
|
+
return rule.actived;
|
|
298
|
+
}
|
|
299
|
+
return isActive(rule.conditions);
|
|
300
|
+
});
|
|
301
|
+
return operator === "and" ? actives.length === autoStartRules.length : actives.length > 0;
|
|
302
|
+
};
|
|
303
|
+
var isActiveContent = (content) => {
|
|
304
|
+
const { enabledAutoStartRules, autoStartRules } = content.config;
|
|
305
|
+
if (!enabledAutoStartRules || !isActive(autoStartRules)) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
return true;
|
|
309
|
+
};
|
|
310
|
+
var priorityCompare = (a, b) => {
|
|
311
|
+
var _a, _b, _c, _d;
|
|
312
|
+
const a1 = (_b = (_a = a == null ? void 0 : a.config) == null ? void 0 : _a.autoStartRulesSetting) == null ? void 0 : _b.priority;
|
|
313
|
+
const a2 = (_d = (_c = b == null ? void 0 : b.config) == null ? void 0 : _c.autoStartRulesSetting) == null ? void 0 : _d.priority;
|
|
314
|
+
if (!a1 || !a2) {
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
const index1 = PRIORITIES.indexOf(a1);
|
|
318
|
+
const index2 = PRIORITIES.indexOf(a2);
|
|
319
|
+
if (index1 > index2) {
|
|
320
|
+
return 1;
|
|
321
|
+
}
|
|
322
|
+
if (index1 < index2) {
|
|
323
|
+
return -1;
|
|
324
|
+
}
|
|
325
|
+
return 0;
|
|
326
|
+
};
|
|
327
|
+
var filterAutoStartContent = (contents, type) => {
|
|
328
|
+
return contents.filter((content) => {
|
|
329
|
+
const isActive2 = isActiveContent(content);
|
|
330
|
+
const isValid = isValidContent(content, contents);
|
|
331
|
+
return content.type === type && isActive2 && isValid;
|
|
332
|
+
}).sort(priorityCompare);
|
|
333
|
+
};
|
|
334
|
+
var isHasActivedContents = (source, dest) => {
|
|
335
|
+
for (let index = 0; index < source.length; index++) {
|
|
336
|
+
const content1 = source[index];
|
|
337
|
+
const content2 = dest.find((c) => c.id === content1.id);
|
|
338
|
+
if (!content2) {
|
|
339
|
+
return true;
|
|
340
|
+
}
|
|
341
|
+
if (isActiveContent(content1) !== isActiveContent(content2)) {
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
};
|
|
347
|
+
var isSameContents = (source, dest) => {
|
|
348
|
+
if (!source || !dest || source.length !== dest.length) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
for (let index = 0; index < source.length; index++) {
|
|
352
|
+
const content1 = source[index];
|
|
353
|
+
const content2 = dest.find((c) => c.id === content1.id);
|
|
354
|
+
if (!content2) {
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
if (!conditionsIsSame(content1.config.autoStartRules, content2.config.autoStartRules)) {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return true;
|
|
362
|
+
};
|
|
363
|
+
var getLatestEvent = (currentContent, contents, eventCodeName) => {
|
|
364
|
+
var _a;
|
|
365
|
+
const bizEvents = [];
|
|
366
|
+
const contentId = currentContent.id;
|
|
367
|
+
const contentType = currentContent.type;
|
|
368
|
+
for (let index = 0; index < contents.length; index++) {
|
|
369
|
+
const content = contents[index];
|
|
370
|
+
if (content.id === contentId || content.type !== contentType) {
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
const sessionBizEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
|
|
374
|
+
if (sessionBizEvents && sessionBizEvents.length > 0) {
|
|
375
|
+
bizEvents.push(...sessionBizEvents.filter((e) => {
|
|
376
|
+
var _a2;
|
|
377
|
+
return ((_a2 = e == null ? void 0 : e.event) == null ? void 0 : _a2.codeName) === eventCodeName;
|
|
378
|
+
}));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return findLatestEvent(bizEvents);
|
|
382
|
+
};
|
|
383
|
+
var findLatestEvent = (bizEvents) => {
|
|
384
|
+
const initialValue = bizEvents[0];
|
|
385
|
+
const lastEvent = bizEvents.reduce(
|
|
386
|
+
(accumulator, currentValue) => {
|
|
387
|
+
if (isAfter(new Date(currentValue.createdAt), new Date(accumulator.createdAt))) {
|
|
388
|
+
return currentValue;
|
|
389
|
+
}
|
|
390
|
+
return accumulator;
|
|
391
|
+
},
|
|
392
|
+
initialValue
|
|
393
|
+
);
|
|
394
|
+
return lastEvent;
|
|
395
|
+
};
|
|
396
|
+
var showEventMapping = {
|
|
397
|
+
[ContentDataType.FLOW]: BizEvents.FLOW_STEP_SEEN,
|
|
398
|
+
[ContentDataType.LAUNCHER]: BizEvents.LAUNCHER_SEEN,
|
|
399
|
+
[ContentDataType.CHECKLIST]: BizEvents.CHECKLIST_SEEN
|
|
400
|
+
};
|
|
401
|
+
var isGreaterThenDuration = (dateLeft, dateRight, unit, duration) => {
|
|
402
|
+
switch (unit) {
|
|
403
|
+
case FrequencyUnits.SECONDS: {
|
|
404
|
+
if (differenceInSeconds(dateLeft, dateRight) >= duration) {
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
case FrequencyUnits.MINUTES:
|
|
410
|
+
if (differenceInMinutes(dateLeft, dateRight) >= duration) {
|
|
411
|
+
return true;
|
|
412
|
+
}
|
|
413
|
+
return false;
|
|
414
|
+
case FrequencyUnits.HOURS:
|
|
415
|
+
if (differenceInHours(dateLeft, dateRight) >= duration) {
|
|
416
|
+
return true;
|
|
417
|
+
}
|
|
418
|
+
return false;
|
|
419
|
+
case FrequencyUnits.DAYES:
|
|
420
|
+
if (differenceInDays(dateLeft, dateRight) >= duration) {
|
|
421
|
+
return true;
|
|
422
|
+
}
|
|
423
|
+
return false;
|
|
424
|
+
default:
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
var checklistIsDimissed = (latestSession) => {
|
|
429
|
+
var _a;
|
|
430
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
|
|
431
|
+
(event) => {
|
|
432
|
+
var _a2;
|
|
433
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === BizEvents.CHECKLIST_DISMISSED;
|
|
434
|
+
}
|
|
435
|
+
);
|
|
436
|
+
};
|
|
437
|
+
var flowIsDismissed = (latestSession) => {
|
|
438
|
+
var _a;
|
|
439
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find((event) => {
|
|
440
|
+
var _a2;
|
|
441
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === BizEvents.FLOW_ENDED;
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
var flowIsSeen = (latestSession) => {
|
|
445
|
+
var _a;
|
|
446
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
|
|
447
|
+
(event) => {
|
|
448
|
+
var _a2;
|
|
449
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === BizEvents.FLOW_STEP_SEEN;
|
|
450
|
+
}
|
|
451
|
+
);
|
|
452
|
+
};
|
|
453
|
+
var checklistIsSeen = (latestSession) => {
|
|
454
|
+
var _a;
|
|
455
|
+
return (_a = latestSession == null ? void 0 : latestSession.bizEvent) == null ? void 0 : _a.find(
|
|
456
|
+
(event) => {
|
|
457
|
+
var _a2;
|
|
458
|
+
return ((_a2 = event == null ? void 0 : event.event) == null ? void 0 : _a2.codeName) === BizEvents.CHECKLIST_SEEN;
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
};
|
|
462
|
+
var isValidContent = (content, contents) => {
|
|
463
|
+
var _a;
|
|
464
|
+
const now = /* @__PURE__ */ new Date();
|
|
465
|
+
if (content.type === ContentDataType.FLOW) {
|
|
466
|
+
if (!content.steps || content.steps.length === 0) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
} else {
|
|
470
|
+
if (!content.data) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (!content.config.autoStartRulesSetting) {
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
const { frequency, startIfNotComplete } = content.config.autoStartRulesSetting;
|
|
478
|
+
const completedSessions = content.completedSessions;
|
|
479
|
+
const dismissedSessions = content.dismissedSessions;
|
|
480
|
+
if (startIfNotComplete && completedSessions > 0) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
483
|
+
if (!frequency) {
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
const contentType = content.type;
|
|
487
|
+
const lastEventName = showEventMapping[contentType];
|
|
488
|
+
const lastEvent = getLatestEvent(content, contents, lastEventName);
|
|
489
|
+
const contentEvents = (_a = content.latestSession) == null ? void 0 : _a.bizEvent;
|
|
490
|
+
if (lastEvent && frequency && frequency.atLeast && !isGreaterThenDuration(
|
|
491
|
+
now,
|
|
492
|
+
new Date(lastEvent.createdAt),
|
|
493
|
+
frequency.atLeast.unit,
|
|
494
|
+
frequency.atLeast.duration
|
|
495
|
+
)) {
|
|
496
|
+
return false;
|
|
497
|
+
}
|
|
498
|
+
if (frequency.frequency === Frequency.ONCE) {
|
|
499
|
+
if (dismissedSessions > 0) {
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
const showEventName = showEventMapping[contentType];
|
|
505
|
+
const showEvents = contentEvents == null ? void 0 : contentEvents.filter(
|
|
506
|
+
(e) => {
|
|
507
|
+
var _a2, _b;
|
|
508
|
+
return ((_a2 = e == null ? void 0 : e.event) == null ? void 0 : _a2.codeName) === showEventName && (contentType === ContentDataType.FLOW ? ((_b = e == null ? void 0 : e.data) == null ? void 0 : _b.flow_step_number) === 0 : true);
|
|
509
|
+
}
|
|
510
|
+
);
|
|
511
|
+
if (!showEvents || showEvents.length === 0) {
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
const lastShowEvent = findLatestEvent(showEvents);
|
|
515
|
+
const lastShowEventDate = new Date(lastShowEvent.createdAt);
|
|
516
|
+
if (frequency.frequency === Frequency.MULTIPLE) {
|
|
517
|
+
if (frequency.every.times && dismissedSessions >= frequency.every.times) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (frequency.frequency === Frequency.MULTIPLE || frequency.frequency === Frequency.UNLIMITED) {
|
|
522
|
+
if (!isGreaterThenDuration(now, lastShowEventDate, frequency.every.unit, frequency.every.duration)) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return true;
|
|
527
|
+
};
|
|
528
|
+
var parseUrlParams = (url, paramName) => {
|
|
529
|
+
if (!url || !paramName) {
|
|
530
|
+
return null;
|
|
531
|
+
}
|
|
532
|
+
try {
|
|
533
|
+
const urlObj = new URL(url);
|
|
534
|
+
const searchParams = new URLSearchParams(urlObj.search);
|
|
535
|
+
if (searchParams.has(paramName)) {
|
|
536
|
+
return searchParams.get(paramName);
|
|
537
|
+
}
|
|
538
|
+
if (urlObj.hash) {
|
|
539
|
+
const hashSearch = urlObj.hash.split("?")[1];
|
|
540
|
+
if (hashSearch) {
|
|
541
|
+
const hashParams = new URLSearchParams(hashSearch);
|
|
542
|
+
if (hashParams.has(paramName)) {
|
|
543
|
+
return hashParams.get(paramName);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return null;
|
|
548
|
+
} catch (error) {
|
|
549
|
+
console.error("Error parsing URL:", error);
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
var wait = (seconds) => {
|
|
554
|
+
if (typeof seconds !== "number" || Number.isNaN(seconds)) {
|
|
555
|
+
return Promise.reject(new Error("Invalid wait time: must be a number"));
|
|
556
|
+
}
|
|
557
|
+
if (seconds < 0) {
|
|
558
|
+
return Promise.reject(new Error("Invalid wait time: cannot be negative"));
|
|
559
|
+
}
|
|
560
|
+
if (seconds === 0) {
|
|
561
|
+
return Promise.resolve();
|
|
562
|
+
}
|
|
563
|
+
return new Promise((resolve, reject) => {
|
|
564
|
+
try {
|
|
565
|
+
setTimeout(resolve, seconds * 1e3);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
reject(error);
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
export {
|
|
573
|
+
PRIORITIES,
|
|
574
|
+
isVisible,
|
|
575
|
+
activedRulesConditions,
|
|
576
|
+
activedContentRulesConditions,
|
|
577
|
+
activedContentCondition,
|
|
578
|
+
isActive,
|
|
579
|
+
isActiveContent,
|
|
580
|
+
filterAutoStartContent,
|
|
581
|
+
isHasActivedContents,
|
|
582
|
+
isSameContents,
|
|
583
|
+
findLatestEvent,
|
|
584
|
+
checklistIsDimissed,
|
|
585
|
+
flowIsDismissed,
|
|
586
|
+
flowIsSeen,
|
|
587
|
+
checklistIsSeen,
|
|
588
|
+
isValidContent,
|
|
589
|
+
parseUrlParams,
|
|
590
|
+
wait
|
|
591
|
+
};
|