@usertour/helpers 0.0.30 → 0.0.32
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/__tests__/condition.test.cjs +68 -0
- package/dist/__tests__/condition.test.js +2 -1
- package/dist/{chunk-RVCKVUQF.js → chunk-VBHUPKP7.js} +39 -1
- package/dist/{chunk-4LLDSAHJ.js → chunk-VWNWWZCH.js} +8 -9
- package/dist/conditions/condition.cjs +108 -2
- package/dist/conditions/condition.d.cts +19 -1
- package/dist/conditions/condition.d.ts +19 -1
- package/dist/conditions/condition.js +10 -3
- package/dist/conditions/index.cjs +108 -2
- package/dist/conditions/index.d.cts +1 -1
- package/dist/conditions/index.d.ts +1 -1
- package/dist/conditions/index.js +10 -3
- package/dist/content.cjs +8 -9
- package/dist/content.js +1 -1
- package/dist/index.cjs +46 -9
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -3
- package/package.json +1 -1
|
@@ -327,6 +327,74 @@ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
+
// src/helper.ts
|
|
331
|
+
var import_clsx = require("clsx");
|
|
332
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
333
|
+
var import_uuid = require("uuid");
|
|
334
|
+
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
335
|
+
function cn(...inputs) {
|
|
336
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
337
|
+
}
|
|
338
|
+
var cuid = () => {
|
|
339
|
+
return (0, import_cuid2.createId)();
|
|
340
|
+
};
|
|
341
|
+
function formatDate(input) {
|
|
342
|
+
const date = new Date(input);
|
|
343
|
+
return date.toLocaleDateString("en-US", {
|
|
344
|
+
month: "long",
|
|
345
|
+
day: "numeric",
|
|
346
|
+
year: "numeric"
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function absoluteUrl(path) {
|
|
350
|
+
return `${path}`;
|
|
351
|
+
}
|
|
352
|
+
var uuidV4 = () => {
|
|
353
|
+
return (0, import_uuid.v4)();
|
|
354
|
+
};
|
|
355
|
+
function hexToRgb(hex) {
|
|
356
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
357
|
+
return result ? {
|
|
358
|
+
r: Number.parseInt(result[1], 16),
|
|
359
|
+
g: Number.parseInt(result[2], 16),
|
|
360
|
+
b: Number.parseInt(result[3], 16)
|
|
361
|
+
} : null;
|
|
362
|
+
}
|
|
363
|
+
var isDark = (hex) => {
|
|
364
|
+
const rgb = hexToRgb(hex);
|
|
365
|
+
if (!rgb) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
const { r, g, b } = rgb;
|
|
369
|
+
if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
|
|
370
|
+
return true;
|
|
371
|
+
}
|
|
372
|
+
return false;
|
|
373
|
+
};
|
|
374
|
+
var evalCode = (code) => {
|
|
375
|
+
try {
|
|
376
|
+
return eval(code);
|
|
377
|
+
} catch (error) {
|
|
378
|
+
console.error("Usertour.js: Error evaluating code:", error);
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
var getRandomColor = () => {
|
|
383
|
+
const colors = [
|
|
384
|
+
"bg-red-500",
|
|
385
|
+
"bg-orange-500",
|
|
386
|
+
"bg-yellow-500",
|
|
387
|
+
"bg-green-500",
|
|
388
|
+
"bg-teal-500",
|
|
389
|
+
"bg-blue-500",
|
|
390
|
+
"bg-indigo-500",
|
|
391
|
+
"bg-purple-500",
|
|
392
|
+
"bg-pink-500",
|
|
393
|
+
"bg-rose-500"
|
|
394
|
+
];
|
|
395
|
+
return colors[Math.floor(Math.random() * colors.length)];
|
|
396
|
+
};
|
|
397
|
+
|
|
330
398
|
// src/conditions/condition.ts
|
|
331
399
|
var isConditionsActived = (conditions) => {
|
|
332
400
|
if (!conditions || conditions.length === 0) {
|
|
@@ -2,11 +2,12 @@ import {
|
|
|
2
2
|
evaluateRulesConditions,
|
|
3
3
|
filterConditionsByType,
|
|
4
4
|
isConditionsActived
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-VBHUPKP7.js";
|
|
6
6
|
import "../chunk-YYIGUZNZ.js";
|
|
7
7
|
import "../chunk-PAESAL23.js";
|
|
8
8
|
import "../chunk-P46FJFKP.js";
|
|
9
9
|
import "../chunk-CEK3SCQO.js";
|
|
10
|
+
import "../chunk-3KG2HTZ3.js";
|
|
10
11
|
import "../chunk-XEO3YXBM.js";
|
|
11
12
|
|
|
12
13
|
// src/__tests__/condition.test.ts
|
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
evaluateTimeCondition
|
|
9
9
|
} from "./chunk-CEK3SCQO.js";
|
|
10
|
+
import {
|
|
11
|
+
cuid
|
|
12
|
+
} from "./chunk-3KG2HTZ3.js";
|
|
10
13
|
|
|
11
14
|
// src/conditions/condition.ts
|
|
12
15
|
import { RulesType } from "@usertour/types";
|
|
@@ -88,6 +91,38 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
88
91
|
}
|
|
89
92
|
return results;
|
|
90
93
|
};
|
|
94
|
+
var regenerateConditionIds = (conditions) => {
|
|
95
|
+
return conditions.map((condition) => ({
|
|
96
|
+
...condition,
|
|
97
|
+
id: cuid(),
|
|
98
|
+
conditions: condition.conditions ? regenerateConditionIds(condition.conditions) : void 0
|
|
99
|
+
}));
|
|
100
|
+
};
|
|
101
|
+
var assignConditionIds = (conditions) => {
|
|
102
|
+
return conditions.map((condition) => {
|
|
103
|
+
var _a;
|
|
104
|
+
return {
|
|
105
|
+
...condition,
|
|
106
|
+
id: (_a = condition.id) != null ? _a : cuid(),
|
|
107
|
+
conditions: condition.conditions ? assignConditionIds(condition.conditions) : void 0
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
var allConditionsHaveIds = (conditions) => {
|
|
112
|
+
if (!conditions || conditions.length === 0)
|
|
113
|
+
return true;
|
|
114
|
+
for (const condition of conditions) {
|
|
115
|
+
if (!condition.id) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (condition.type === "group" && condition.conditions) {
|
|
119
|
+
if (!allConditionsHaveIds(condition.conditions)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
};
|
|
91
126
|
|
|
92
127
|
export {
|
|
93
128
|
isEqual,
|
|
@@ -95,5 +130,8 @@ export {
|
|
|
95
130
|
isConditionsActived,
|
|
96
131
|
filterConditionsByType,
|
|
97
132
|
evaluateRule,
|
|
98
|
-
evaluateRulesConditions
|
|
133
|
+
evaluateRulesConditions,
|
|
134
|
+
regenerateConditionIds,
|
|
135
|
+
assignConditionIds,
|
|
136
|
+
allConditionsHaveIds
|
|
99
137
|
};
|
|
@@ -4,25 +4,24 @@ import {
|
|
|
4
4
|
} from "@usertour/types";
|
|
5
5
|
import { deepmerge } from "deepmerge-ts";
|
|
6
6
|
var isPublishedInAllEnvironments = (content, environmentList, version) => {
|
|
7
|
-
|
|
7
|
+
var _a;
|
|
8
|
+
if (!((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) || !(environmentList == null ? void 0 : environmentList.length) || !(version == null ? void 0 : version.id)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return environmentList.every(
|
|
8
12
|
(env) => {
|
|
9
|
-
var
|
|
10
|
-
return (
|
|
11
|
-
(item) => item.published && item.publishedVersionId ===
|
|
13
|
+
var _a2;
|
|
14
|
+
return (_a2 = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a2.some(
|
|
15
|
+
(item) => item.published && item.publishedVersionId === version.id && item.environment.id === env.id
|
|
12
16
|
);
|
|
13
17
|
}
|
|
14
18
|
);
|
|
15
|
-
const isPublishedInOneEnvironment = (content == null ? void 0 : content.published) && (content == null ? void 0 : content.publishedVersionId) === (version == null ? void 0 : version.id) && environmentList && (environmentList == null ? void 0 : environmentList.length) === 1;
|
|
16
|
-
return (content == null ? void 0 : content.contentOnEnvironments) && (content == null ? void 0 : content.contentOnEnvironments.length) > 0 ? Boolean(isPublishedInAllEnvironments2) : Boolean(isPublishedInOneEnvironment);
|
|
17
19
|
};
|
|
18
20
|
var isPublishedAtLeastOneEnvironment = (content) => {
|
|
19
21
|
var _a;
|
|
20
22
|
if ((content == null ? void 0 : content.contentOnEnvironments) && ((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) > 0) {
|
|
21
23
|
return true;
|
|
22
24
|
}
|
|
23
|
-
if ((content == null ? void 0 : content.published) && (content == null ? void 0 : content.publishedVersionId)) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
25
|
return false;
|
|
27
26
|
};
|
|
28
27
|
var rulesSetting = {
|
|
@@ -30,12 +30,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/conditions/condition.ts
|
|
31
31
|
var condition_exports = {};
|
|
32
32
|
__export(condition_exports, {
|
|
33
|
+
allConditionsHaveIds: () => allConditionsHaveIds,
|
|
34
|
+
assignConditionIds: () => assignConditionIds,
|
|
33
35
|
conditionsIsSame: () => conditionsIsSame,
|
|
34
36
|
evaluateRule: () => evaluateRule,
|
|
35
37
|
evaluateRulesConditions: () => evaluateRulesConditions,
|
|
36
38
|
filterConditionsByType: () => filterConditionsByType,
|
|
37
39
|
isConditionsActived: () => isConditionsActived,
|
|
38
|
-
isEqual: () => import_fast_deep_equal.default
|
|
40
|
+
isEqual: () => import_fast_deep_equal.default,
|
|
41
|
+
regenerateConditionIds: () => regenerateConditionIds
|
|
39
42
|
});
|
|
40
43
|
module.exports = __toCommonJS(condition_exports);
|
|
41
44
|
var import_types2 = require("@usertour/types");
|
|
@@ -339,6 +342,74 @@ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
|
339
342
|
}
|
|
340
343
|
}
|
|
341
344
|
|
|
345
|
+
// src/helper.ts
|
|
346
|
+
var import_clsx = require("clsx");
|
|
347
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
348
|
+
var import_uuid = require("uuid");
|
|
349
|
+
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
350
|
+
function cn(...inputs) {
|
|
351
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
352
|
+
}
|
|
353
|
+
var cuid = () => {
|
|
354
|
+
return (0, import_cuid2.createId)();
|
|
355
|
+
};
|
|
356
|
+
function formatDate(input) {
|
|
357
|
+
const date = new Date(input);
|
|
358
|
+
return date.toLocaleDateString("en-US", {
|
|
359
|
+
month: "long",
|
|
360
|
+
day: "numeric",
|
|
361
|
+
year: "numeric"
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
function absoluteUrl(path) {
|
|
365
|
+
return `${path}`;
|
|
366
|
+
}
|
|
367
|
+
var uuidV4 = () => {
|
|
368
|
+
return (0, import_uuid.v4)();
|
|
369
|
+
};
|
|
370
|
+
function hexToRgb(hex) {
|
|
371
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
372
|
+
return result ? {
|
|
373
|
+
r: Number.parseInt(result[1], 16),
|
|
374
|
+
g: Number.parseInt(result[2], 16),
|
|
375
|
+
b: Number.parseInt(result[3], 16)
|
|
376
|
+
} : null;
|
|
377
|
+
}
|
|
378
|
+
var isDark = (hex) => {
|
|
379
|
+
const rgb = hexToRgb(hex);
|
|
380
|
+
if (!rgb) {
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
const { r, g, b } = rgb;
|
|
384
|
+
if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
387
|
+
return false;
|
|
388
|
+
};
|
|
389
|
+
var evalCode = (code) => {
|
|
390
|
+
try {
|
|
391
|
+
return eval(code);
|
|
392
|
+
} catch (error) {
|
|
393
|
+
console.error("Usertour.js: Error evaluating code:", error);
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
var getRandomColor = () => {
|
|
398
|
+
const colors = [
|
|
399
|
+
"bg-red-500",
|
|
400
|
+
"bg-orange-500",
|
|
401
|
+
"bg-yellow-500",
|
|
402
|
+
"bg-green-500",
|
|
403
|
+
"bg-teal-500",
|
|
404
|
+
"bg-blue-500",
|
|
405
|
+
"bg-indigo-500",
|
|
406
|
+
"bg-purple-500",
|
|
407
|
+
"bg-pink-500",
|
|
408
|
+
"bg-rose-500"
|
|
409
|
+
];
|
|
410
|
+
return colors[Math.floor(Math.random() * colors.length)];
|
|
411
|
+
};
|
|
412
|
+
|
|
342
413
|
// src/conditions/condition.ts
|
|
343
414
|
var conditionsIsSame = (rr1, rr2) => {
|
|
344
415
|
return (0, import_fast_deep_equal.default)(rr1, rr2);
|
|
@@ -417,12 +488,47 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
417
488
|
}
|
|
418
489
|
return results;
|
|
419
490
|
};
|
|
491
|
+
var regenerateConditionIds = (conditions) => {
|
|
492
|
+
return conditions.map((condition) => ({
|
|
493
|
+
...condition,
|
|
494
|
+
id: cuid(),
|
|
495
|
+
conditions: condition.conditions ? regenerateConditionIds(condition.conditions) : void 0
|
|
496
|
+
}));
|
|
497
|
+
};
|
|
498
|
+
var assignConditionIds = (conditions) => {
|
|
499
|
+
return conditions.map((condition) => {
|
|
500
|
+
var _a;
|
|
501
|
+
return {
|
|
502
|
+
...condition,
|
|
503
|
+
id: (_a = condition.id) != null ? _a : cuid(),
|
|
504
|
+
conditions: condition.conditions ? assignConditionIds(condition.conditions) : void 0
|
|
505
|
+
};
|
|
506
|
+
});
|
|
507
|
+
};
|
|
508
|
+
var allConditionsHaveIds = (conditions) => {
|
|
509
|
+
if (!conditions || conditions.length === 0)
|
|
510
|
+
return true;
|
|
511
|
+
for (const condition of conditions) {
|
|
512
|
+
if (!condition.id) {
|
|
513
|
+
return false;
|
|
514
|
+
}
|
|
515
|
+
if (condition.type === "group" && condition.conditions) {
|
|
516
|
+
if (!allConditionsHaveIds(condition.conditions)) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return true;
|
|
522
|
+
};
|
|
420
523
|
// Annotate the CommonJS export names for ESM import in node:
|
|
421
524
|
0 && (module.exports = {
|
|
525
|
+
allConditionsHaveIds,
|
|
526
|
+
assignConditionIds,
|
|
422
527
|
conditionsIsSame,
|
|
423
528
|
evaluateRule,
|
|
424
529
|
evaluateRulesConditions,
|
|
425
530
|
filterConditionsByType,
|
|
426
531
|
isConditionsActived,
|
|
427
|
-
isEqual
|
|
532
|
+
isEqual,
|
|
533
|
+
regenerateConditionIds
|
|
428
534
|
});
|
|
@@ -36,5 +36,23 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
|
|
|
36
36
|
*/
|
|
37
37
|
declare const evaluateRule: (condition: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
|
|
38
38
|
declare const evaluateRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => Promise<RulesCondition[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Regenerates IDs for each item in RulesCondition array using cuid
|
|
41
|
+
* @param conditions - Array of rules conditions to process
|
|
42
|
+
* @returns Array of rules conditions with new IDs
|
|
43
|
+
*/
|
|
44
|
+
declare const regenerateConditionIds: (conditions: RulesCondition[]) => RulesCondition[];
|
|
45
|
+
/**
|
|
46
|
+
* Assign unique IDs to rules that don't have them
|
|
47
|
+
* @param conditions - Array of rules conditions to process
|
|
48
|
+
* @returns Array of rules conditions with IDs assigned (only for those missing IDs)
|
|
49
|
+
*/
|
|
50
|
+
declare const assignConditionIds: (conditions: RulesCondition[]) => RulesCondition[];
|
|
51
|
+
/**
|
|
52
|
+
* Check if all conditions have IDs (including nested conditions)
|
|
53
|
+
* @param conditions - Array of rules conditions to check
|
|
54
|
+
* @returns true if all conditions have IDs, false otherwise
|
|
55
|
+
*/
|
|
56
|
+
declare const allConditionsHaveIds: (conditions: RulesCondition[]) => boolean;
|
|
39
57
|
|
|
40
|
-
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived };
|
|
58
|
+
export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived, regenerateConditionIds };
|
|
@@ -36,5 +36,23 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
|
|
|
36
36
|
*/
|
|
37
37
|
declare const evaluateRule: (condition: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
|
|
38
38
|
declare const evaluateRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => Promise<RulesCondition[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Regenerates IDs for each item in RulesCondition array using cuid
|
|
41
|
+
* @param conditions - Array of rules conditions to process
|
|
42
|
+
* @returns Array of rules conditions with new IDs
|
|
43
|
+
*/
|
|
44
|
+
declare const regenerateConditionIds: (conditions: RulesCondition[]) => RulesCondition[];
|
|
45
|
+
/**
|
|
46
|
+
* Assign unique IDs to rules that don't have them
|
|
47
|
+
* @param conditions - Array of rules conditions to process
|
|
48
|
+
* @returns Array of rules conditions with IDs assigned (only for those missing IDs)
|
|
49
|
+
*/
|
|
50
|
+
declare const assignConditionIds: (conditions: RulesCondition[]) => RulesCondition[];
|
|
51
|
+
/**
|
|
52
|
+
* Check if all conditions have IDs (including nested conditions)
|
|
53
|
+
* @param conditions - Array of rules conditions to check
|
|
54
|
+
* @returns true if all conditions have IDs, false otherwise
|
|
55
|
+
*/
|
|
56
|
+
declare const allConditionsHaveIds: (conditions: RulesCondition[]) => boolean;
|
|
39
57
|
|
|
40
|
-
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived };
|
|
58
|
+
export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived, regenerateConditionIds };
|
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import {
|
|
2
|
+
allConditionsHaveIds,
|
|
3
|
+
assignConditionIds,
|
|
2
4
|
conditionsIsSame,
|
|
3
5
|
evaluateRule,
|
|
4
6
|
evaluateRulesConditions,
|
|
5
7
|
filterConditionsByType,
|
|
6
8
|
isConditionsActived,
|
|
7
|
-
isEqual
|
|
8
|
-
|
|
9
|
+
isEqual,
|
|
10
|
+
regenerateConditionIds
|
|
11
|
+
} from "../chunk-VBHUPKP7.js";
|
|
9
12
|
import "../chunk-YYIGUZNZ.js";
|
|
10
13
|
import "../chunk-PAESAL23.js";
|
|
11
14
|
import "../chunk-P46FJFKP.js";
|
|
12
15
|
import "../chunk-CEK3SCQO.js";
|
|
16
|
+
import "../chunk-3KG2HTZ3.js";
|
|
13
17
|
import "../chunk-XEO3YXBM.js";
|
|
14
18
|
export {
|
|
19
|
+
allConditionsHaveIds,
|
|
20
|
+
assignConditionIds,
|
|
15
21
|
conditionsIsSame,
|
|
16
22
|
evaluateRule,
|
|
17
23
|
evaluateRulesConditions,
|
|
18
24
|
filterConditionsByType,
|
|
19
25
|
isConditionsActived,
|
|
20
|
-
isEqual
|
|
26
|
+
isEqual,
|
|
27
|
+
regenerateConditionIds
|
|
21
28
|
};
|
|
@@ -30,6 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/conditions/index.ts
|
|
31
31
|
var conditions_exports = {};
|
|
32
32
|
__export(conditions_exports, {
|
|
33
|
+
allConditionsHaveIds: () => allConditionsHaveIds,
|
|
34
|
+
assignConditionIds: () => assignConditionIds,
|
|
33
35
|
conditionsIsSame: () => conditionsIsSame,
|
|
34
36
|
evaluateAttributeCondition: () => evaluateAttributeCondition,
|
|
35
37
|
evaluateRule: () => evaluateRule,
|
|
@@ -39,7 +41,8 @@ __export(conditions_exports, {
|
|
|
39
41
|
filterConditionsByType: () => filterConditionsByType,
|
|
40
42
|
isConditionsActived: () => isConditionsActived,
|
|
41
43
|
isEqual: () => import_fast_deep_equal.default,
|
|
42
|
-
isMatchUrlPattern: () => isMatchUrlPattern
|
|
44
|
+
isMatchUrlPattern: () => isMatchUrlPattern,
|
|
45
|
+
regenerateConditionIds: () => regenerateConditionIds
|
|
43
46
|
});
|
|
44
47
|
module.exports = __toCommonJS(conditions_exports);
|
|
45
48
|
|
|
@@ -345,6 +348,74 @@ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
|
345
348
|
}
|
|
346
349
|
}
|
|
347
350
|
|
|
351
|
+
// src/helper.ts
|
|
352
|
+
var import_clsx = require("clsx");
|
|
353
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
354
|
+
var import_uuid = require("uuid");
|
|
355
|
+
var import_cuid2 = require("@paralleldrive/cuid2");
|
|
356
|
+
function cn(...inputs) {
|
|
357
|
+
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
358
|
+
}
|
|
359
|
+
var cuid = () => {
|
|
360
|
+
return (0, import_cuid2.createId)();
|
|
361
|
+
};
|
|
362
|
+
function formatDate(input) {
|
|
363
|
+
const date = new Date(input);
|
|
364
|
+
return date.toLocaleDateString("en-US", {
|
|
365
|
+
month: "long",
|
|
366
|
+
day: "numeric",
|
|
367
|
+
year: "numeric"
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
function absoluteUrl(path) {
|
|
371
|
+
return `${path}`;
|
|
372
|
+
}
|
|
373
|
+
var uuidV4 = () => {
|
|
374
|
+
return (0, import_uuid.v4)();
|
|
375
|
+
};
|
|
376
|
+
function hexToRgb(hex) {
|
|
377
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
378
|
+
return result ? {
|
|
379
|
+
r: Number.parseInt(result[1], 16),
|
|
380
|
+
g: Number.parseInt(result[2], 16),
|
|
381
|
+
b: Number.parseInt(result[3], 16)
|
|
382
|
+
} : null;
|
|
383
|
+
}
|
|
384
|
+
var isDark = (hex) => {
|
|
385
|
+
const rgb = hexToRgb(hex);
|
|
386
|
+
if (!rgb) {
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
const { r, g, b } = rgb;
|
|
390
|
+
if (r * 0.299 + g * 0.587 + b * 0.114 > 186) {
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
return false;
|
|
394
|
+
};
|
|
395
|
+
var evalCode = (code) => {
|
|
396
|
+
try {
|
|
397
|
+
return eval(code);
|
|
398
|
+
} catch (error) {
|
|
399
|
+
console.error("Usertour.js: Error evaluating code:", error);
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
var getRandomColor = () => {
|
|
404
|
+
const colors = [
|
|
405
|
+
"bg-red-500",
|
|
406
|
+
"bg-orange-500",
|
|
407
|
+
"bg-yellow-500",
|
|
408
|
+
"bg-green-500",
|
|
409
|
+
"bg-teal-500",
|
|
410
|
+
"bg-blue-500",
|
|
411
|
+
"bg-indigo-500",
|
|
412
|
+
"bg-purple-500",
|
|
413
|
+
"bg-pink-500",
|
|
414
|
+
"bg-rose-500"
|
|
415
|
+
];
|
|
416
|
+
return colors[Math.floor(Math.random() * colors.length)];
|
|
417
|
+
};
|
|
418
|
+
|
|
348
419
|
// src/conditions/condition.ts
|
|
349
420
|
var conditionsIsSame = (rr1, rr2) => {
|
|
350
421
|
return (0, import_fast_deep_equal.default)(rr1, rr2);
|
|
@@ -423,8 +494,42 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
423
494
|
}
|
|
424
495
|
return results;
|
|
425
496
|
};
|
|
497
|
+
var regenerateConditionIds = (conditions) => {
|
|
498
|
+
return conditions.map((condition) => ({
|
|
499
|
+
...condition,
|
|
500
|
+
id: cuid(),
|
|
501
|
+
conditions: condition.conditions ? regenerateConditionIds(condition.conditions) : void 0
|
|
502
|
+
}));
|
|
503
|
+
};
|
|
504
|
+
var assignConditionIds = (conditions) => {
|
|
505
|
+
return conditions.map((condition) => {
|
|
506
|
+
var _a;
|
|
507
|
+
return {
|
|
508
|
+
...condition,
|
|
509
|
+
id: (_a = condition.id) != null ? _a : cuid(),
|
|
510
|
+
conditions: condition.conditions ? assignConditionIds(condition.conditions) : void 0
|
|
511
|
+
};
|
|
512
|
+
});
|
|
513
|
+
};
|
|
514
|
+
var allConditionsHaveIds = (conditions) => {
|
|
515
|
+
if (!conditions || conditions.length === 0)
|
|
516
|
+
return true;
|
|
517
|
+
for (const condition of conditions) {
|
|
518
|
+
if (!condition.id) {
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
if (condition.type === "group" && condition.conditions) {
|
|
522
|
+
if (!allConditionsHaveIds(condition.conditions)) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return true;
|
|
528
|
+
};
|
|
426
529
|
// Annotate the CommonJS export names for ESM import in node:
|
|
427
530
|
0 && (module.exports = {
|
|
531
|
+
allConditionsHaveIds,
|
|
532
|
+
assignConditionIds,
|
|
428
533
|
conditionsIsSame,
|
|
429
534
|
evaluateAttributeCondition,
|
|
430
535
|
evaluateRule,
|
|
@@ -434,5 +539,6 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
434
539
|
filterConditionsByType,
|
|
435
540
|
isConditionsActived,
|
|
436
541
|
isEqual,
|
|
437
|
-
isMatchUrlPattern
|
|
542
|
+
isMatchUrlPattern,
|
|
543
|
+
regenerateConditionIds
|
|
438
544
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './condition.cjs';
|
|
1
|
+
export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived, regenerateConditionIds } from './condition.cjs';
|
|
2
2
|
export { evaluateUrlCondition, isMatchUrlPattern } from './url.cjs';
|
|
3
3
|
export { evaluateTimeCondition } from './time.cjs';
|
|
4
4
|
export { evaluateAttributeCondition } from './attribute.cjs';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './condition.js';
|
|
1
|
+
export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived, regenerateConditionIds } from './condition.js';
|
|
2
2
|
export { evaluateUrlCondition, isMatchUrlPattern } from './url.js';
|
|
3
3
|
export { evaluateTimeCondition } from './time.js';
|
|
4
4
|
export { evaluateAttributeCondition } from './attribute.js';
|
package/dist/conditions/index.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import "../chunk-7ODE2AIC.js";
|
|
2
2
|
import {
|
|
3
|
+
allConditionsHaveIds,
|
|
4
|
+
assignConditionIds,
|
|
3
5
|
conditionsIsSame,
|
|
4
6
|
evaluateRule,
|
|
5
7
|
evaluateRulesConditions,
|
|
6
8
|
filterConditionsByType,
|
|
7
9
|
isConditionsActived,
|
|
8
|
-
isEqual
|
|
9
|
-
|
|
10
|
+
isEqual,
|
|
11
|
+
regenerateConditionIds
|
|
12
|
+
} from "../chunk-VBHUPKP7.js";
|
|
10
13
|
import {
|
|
11
14
|
evaluateUrlCondition,
|
|
12
15
|
isMatchUrlPattern
|
|
@@ -18,8 +21,11 @@ import {
|
|
|
18
21
|
import {
|
|
19
22
|
evaluateTimeCondition
|
|
20
23
|
} from "../chunk-CEK3SCQO.js";
|
|
24
|
+
import "../chunk-3KG2HTZ3.js";
|
|
21
25
|
import "../chunk-XEO3YXBM.js";
|
|
22
26
|
export {
|
|
27
|
+
allConditionsHaveIds,
|
|
28
|
+
assignConditionIds,
|
|
23
29
|
conditionsIsSame,
|
|
24
30
|
evaluateAttributeCondition,
|
|
25
31
|
evaluateRule,
|
|
@@ -29,5 +35,6 @@ export {
|
|
|
29
35
|
filterConditionsByType,
|
|
30
36
|
isConditionsActived,
|
|
31
37
|
isEqual,
|
|
32
|
-
isMatchUrlPattern
|
|
38
|
+
isMatchUrlPattern,
|
|
39
|
+
regenerateConditionIds
|
|
33
40
|
};
|
package/dist/content.cjs
CHANGED
|
@@ -29,25 +29,24 @@ module.exports = __toCommonJS(content_exports);
|
|
|
29
29
|
var import_types = require("@usertour/types");
|
|
30
30
|
var import_deepmerge_ts = require("deepmerge-ts");
|
|
31
31
|
var isPublishedInAllEnvironments = (content, environmentList, version) => {
|
|
32
|
-
|
|
32
|
+
var _a;
|
|
33
|
+
if (!((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) || !(environmentList == null ? void 0 : environmentList.length) || !(version == null ? void 0 : version.id)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
return environmentList.every(
|
|
33
37
|
(env) => {
|
|
34
|
-
var
|
|
35
|
-
return (
|
|
36
|
-
(item) => item.published && item.publishedVersionId ===
|
|
38
|
+
var _a2;
|
|
39
|
+
return (_a2 = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a2.some(
|
|
40
|
+
(item) => item.published && item.publishedVersionId === version.id && item.environment.id === env.id
|
|
37
41
|
);
|
|
38
42
|
}
|
|
39
43
|
);
|
|
40
|
-
const isPublishedInOneEnvironment = (content == null ? void 0 : content.published) && (content == null ? void 0 : content.publishedVersionId) === (version == null ? void 0 : version.id) && environmentList && (environmentList == null ? void 0 : environmentList.length) === 1;
|
|
41
|
-
return (content == null ? void 0 : content.contentOnEnvironments) && (content == null ? void 0 : content.contentOnEnvironments.length) > 0 ? Boolean(isPublishedInAllEnvironments2) : Boolean(isPublishedInOneEnvironment);
|
|
42
44
|
};
|
|
43
45
|
var isPublishedAtLeastOneEnvironment = (content) => {
|
|
44
46
|
var _a;
|
|
45
47
|
if ((content == null ? void 0 : content.contentOnEnvironments) && ((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) > 0) {
|
|
46
48
|
return true;
|
|
47
49
|
}
|
|
48
|
-
if ((content == null ? void 0 : content.published) && (content == null ? void 0 : content.publishedVersionId)) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
50
|
return false;
|
|
52
51
|
};
|
|
53
52
|
var rulesSetting = {
|
package/dist/content.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,8 @@ __export(src_exports, {
|
|
|
39
39
|
ArrayProto: () => ArrayProto,
|
|
40
40
|
XMLHttpRequest: () => XMLHttpRequest,
|
|
41
41
|
absoluteUrl: () => absoluteUrl,
|
|
42
|
+
allConditionsHaveIds: () => allConditionsHaveIds,
|
|
43
|
+
assignConditionIds: () => assignConditionIds,
|
|
42
44
|
assignableWindow: () => assignableWindow,
|
|
43
45
|
buildConfig: () => buildConfig,
|
|
44
46
|
cn: () => cn,
|
|
@@ -110,6 +112,7 @@ __export(src_exports, {
|
|
|
110
112
|
nativeIndexOf: () => nativeIndexOf,
|
|
111
113
|
navigator: () => navigator,
|
|
112
114
|
parseUrlParams: () => parseUrlParams,
|
|
115
|
+
regenerateConditionIds: () => regenerateConditionIds,
|
|
113
116
|
removeAuthToken: () => removeAuthToken,
|
|
114
117
|
setAuthToken: () => setAuthToken,
|
|
115
118
|
storage: () => storage,
|
|
@@ -836,25 +839,24 @@ function isUrl(string) {
|
|
|
836
839
|
var import_types3 = require("@usertour/types");
|
|
837
840
|
var import_deepmerge_ts2 = require("deepmerge-ts");
|
|
838
841
|
var isPublishedInAllEnvironments = (content, environmentList, version) => {
|
|
839
|
-
|
|
842
|
+
var _a;
|
|
843
|
+
if (!((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) || !(environmentList == null ? void 0 : environmentList.length) || !(version == null ? void 0 : version.id)) {
|
|
844
|
+
return false;
|
|
845
|
+
}
|
|
846
|
+
return environmentList.every(
|
|
840
847
|
(env) => {
|
|
841
|
-
var
|
|
842
|
-
return (
|
|
843
|
-
(item) => item.published && item.publishedVersionId ===
|
|
848
|
+
var _a2;
|
|
849
|
+
return (_a2 = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a2.some(
|
|
850
|
+
(item) => item.published && item.publishedVersionId === version.id && item.environment.id === env.id
|
|
844
851
|
);
|
|
845
852
|
}
|
|
846
853
|
);
|
|
847
|
-
const isPublishedInOneEnvironment = (content == null ? void 0 : content.published) && (content == null ? void 0 : content.publishedVersionId) === (version == null ? void 0 : version.id) && environmentList && (environmentList == null ? void 0 : environmentList.length) === 1;
|
|
848
|
-
return (content == null ? void 0 : content.contentOnEnvironments) && (content == null ? void 0 : content.contentOnEnvironments.length) > 0 ? Boolean(isPublishedInAllEnvironments2) : Boolean(isPublishedInOneEnvironment);
|
|
849
854
|
};
|
|
850
855
|
var isPublishedAtLeastOneEnvironment = (content) => {
|
|
851
856
|
var _a;
|
|
852
857
|
if ((content == null ? void 0 : content.contentOnEnvironments) && ((_a = content == null ? void 0 : content.contentOnEnvironments) == null ? void 0 : _a.length) > 0) {
|
|
853
858
|
return true;
|
|
854
859
|
}
|
|
855
|
-
if ((content == null ? void 0 : content.published) && (content == null ? void 0 : content.publishedVersionId)) {
|
|
856
|
-
return true;
|
|
857
|
-
}
|
|
858
860
|
return false;
|
|
859
861
|
};
|
|
860
862
|
var rulesSetting = {
|
|
@@ -1389,12 +1391,46 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
1389
1391
|
}
|
|
1390
1392
|
return results;
|
|
1391
1393
|
};
|
|
1394
|
+
var regenerateConditionIds = (conditions) => {
|
|
1395
|
+
return conditions.map((condition) => ({
|
|
1396
|
+
...condition,
|
|
1397
|
+
id: cuid(),
|
|
1398
|
+
conditions: condition.conditions ? regenerateConditionIds(condition.conditions) : void 0
|
|
1399
|
+
}));
|
|
1400
|
+
};
|
|
1401
|
+
var assignConditionIds = (conditions) => {
|
|
1402
|
+
return conditions.map((condition) => {
|
|
1403
|
+
var _a;
|
|
1404
|
+
return {
|
|
1405
|
+
...condition,
|
|
1406
|
+
id: (_a = condition.id) != null ? _a : cuid(),
|
|
1407
|
+
conditions: condition.conditions ? assignConditionIds(condition.conditions) : void 0
|
|
1408
|
+
};
|
|
1409
|
+
});
|
|
1410
|
+
};
|
|
1411
|
+
var allConditionsHaveIds = (conditions) => {
|
|
1412
|
+
if (!conditions || conditions.length === 0)
|
|
1413
|
+
return true;
|
|
1414
|
+
for (const condition of conditions) {
|
|
1415
|
+
if (!condition.id) {
|
|
1416
|
+
return false;
|
|
1417
|
+
}
|
|
1418
|
+
if (condition.type === "group" && condition.conditions) {
|
|
1419
|
+
if (!allConditionsHaveIds(condition.conditions)) {
|
|
1420
|
+
return false;
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
return true;
|
|
1425
|
+
};
|
|
1392
1426
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1393
1427
|
0 && (module.exports = {
|
|
1394
1428
|
AbortController,
|
|
1395
1429
|
ArrayProto,
|
|
1396
1430
|
XMLHttpRequest,
|
|
1397
1431
|
absoluteUrl,
|
|
1432
|
+
allConditionsHaveIds,
|
|
1433
|
+
assignConditionIds,
|
|
1398
1434
|
assignableWindow,
|
|
1399
1435
|
buildConfig,
|
|
1400
1436
|
cn,
|
|
@@ -1466,6 +1502,7 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
1466
1502
|
nativeIndexOf,
|
|
1467
1503
|
navigator,
|
|
1468
1504
|
parseUrlParams,
|
|
1505
|
+
regenerateConditionIds,
|
|
1469
1506
|
removeAuthToken,
|
|
1470
1507
|
setAuthToken,
|
|
1471
1508
|
storage,
|
package/dist/index.d.cts
CHANGED
|
@@ -9,7 +9,7 @@ export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, is
|
|
|
9
9
|
export { deepClone, parseUrlParams, wait } from './utils.cjs';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
|
|
12
|
-
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './conditions/condition.cjs';
|
|
12
|
+
export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived, regenerateConditionIds } from './conditions/condition.cjs';
|
|
13
13
|
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.cjs';
|
|
14
14
|
export { evaluateTimeCondition } from './conditions/time.cjs';
|
|
15
15
|
export { evaluateAttributeCondition } from './conditions/attribute.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, is
|
|
|
9
9
|
export { deepClone, parseUrlParams, wait } from './utils.js';
|
|
10
10
|
export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.js';
|
|
11
11
|
export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
|
|
12
|
-
export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './conditions/condition.js';
|
|
12
|
+
export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived, regenerateConditionIds } from './conditions/condition.js';
|
|
13
13
|
export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.js';
|
|
14
14
|
export { evaluateTimeCondition } from './conditions/time.js';
|
|
15
15
|
export { evaluateAttributeCondition } from './conditions/attribute.js';
|
package/dist/index.js
CHANGED
|
@@ -11,13 +11,16 @@ import {
|
|
|
11
11
|
wait
|
|
12
12
|
} from "./chunk-5C3J4DM2.js";
|
|
13
13
|
import {
|
|
14
|
+
allConditionsHaveIds,
|
|
15
|
+
assignConditionIds,
|
|
14
16
|
conditionsIsSame,
|
|
15
17
|
evaluateRule,
|
|
16
18
|
evaluateRulesConditions,
|
|
17
19
|
filterConditionsByType,
|
|
18
20
|
isConditionsActived,
|
|
19
|
-
isEqual
|
|
20
|
-
|
|
21
|
+
isEqual,
|
|
22
|
+
regenerateConditionIds
|
|
23
|
+
} from "./chunk-VBHUPKP7.js";
|
|
21
24
|
import {
|
|
22
25
|
evaluateUrlCondition,
|
|
23
26
|
isMatchUrlPattern
|
|
@@ -41,7 +44,7 @@ import {
|
|
|
41
44
|
defaultContentConfig,
|
|
42
45
|
isPublishedAtLeastOneEnvironment,
|
|
43
46
|
isPublishedInAllEnvironments
|
|
44
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-VWNWWZCH.js";
|
|
45
48
|
import {
|
|
46
49
|
convertSettings,
|
|
47
50
|
convertToCssVars,
|
|
@@ -119,6 +122,8 @@ export {
|
|
|
119
122
|
ArrayProto,
|
|
120
123
|
XMLHttpRequest,
|
|
121
124
|
absoluteUrl,
|
|
125
|
+
allConditionsHaveIds,
|
|
126
|
+
assignConditionIds,
|
|
122
127
|
assignableWindow,
|
|
123
128
|
buildConfig,
|
|
124
129
|
cn,
|
|
@@ -190,6 +195,7 @@ export {
|
|
|
190
195
|
nativeIndexOf,
|
|
191
196
|
navigator,
|
|
192
197
|
parseUrlParams,
|
|
198
|
+
regenerateConditionIds,
|
|
193
199
|
removeAuthToken,
|
|
194
200
|
setAuthToken,
|
|
195
201
|
storage,
|