@usertour/helpers 0.0.29 → 0.0.31
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__/attribute.test.cjs +505 -67
- package/dist/__tests__/attribute.test.js +495 -60
- package/dist/__tests__/condition.test.cjs +83 -12
- package/dist/__tests__/condition.test.js +10 -5
- package/dist/{chunk-PBZSPV5R.js → chunk-P46FJFKP.js} +20 -10
- package/dist/{chunk-E2IJQFKH.js → chunk-VBHUPKP7.js} +41 -7
- package/dist/{chunk-4LLDSAHJ.js → chunk-VWNWWZCH.js} +8 -9
- package/dist/conditions/attribute.cjs +16 -9
- package/dist/conditions/attribute.d.cts +5 -7
- package/dist/conditions/attribute.d.ts +5 -7
- package/dist/conditions/attribute.js +1 -1
- package/dist/conditions/condition.cjs +121 -12
- package/dist/conditions/condition.d.cts +19 -1
- package/dist/conditions/condition.d.ts +19 -1
- package/dist/conditions/condition.js +11 -4
- package/dist/conditions/index.cjs +121 -12
- package/dist/conditions/index.d.cts +1 -1
- package/dist/conditions/index.d.ts +1 -1
- package/dist/conditions/index.js +11 -4
- package/dist/content.cjs +8 -9
- package/dist/content.js +1 -1
- package/dist/index.cjs +59 -19
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -4
- package/package.json +2 -2
|
@@ -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");
|
|
@@ -155,20 +158,27 @@ var evaluateTimeCondition = (rules) => {
|
|
|
155
158
|
// src/conditions/attribute.ts
|
|
156
159
|
var import_types = require("@usertour/types");
|
|
157
160
|
var import_date_fns2 = require("date-fns");
|
|
158
|
-
function evaluateAttributeCondition(condition,
|
|
161
|
+
function evaluateAttributeCondition(condition, options) {
|
|
159
162
|
const { data } = condition;
|
|
160
163
|
if (!data) {
|
|
161
164
|
return false;
|
|
162
165
|
}
|
|
163
166
|
const { logic, value, attrId, value2, listValues = [] } = data;
|
|
164
|
-
|
|
167
|
+
const {
|
|
168
|
+
attributes,
|
|
169
|
+
userAttributes = {},
|
|
170
|
+
companyAttributes = {},
|
|
171
|
+
membershipAttributes = {}
|
|
172
|
+
} = options;
|
|
173
|
+
if (!attrId || !attributes) {
|
|
165
174
|
return false;
|
|
166
175
|
}
|
|
167
176
|
const attr = attributes.find((attr2) => attr2.id === attrId);
|
|
168
177
|
if (!attr) {
|
|
169
178
|
return false;
|
|
170
179
|
}
|
|
171
|
-
const
|
|
180
|
+
const bizAttributes = attr.bizType === import_types.AttributeBizTypes.Company ? companyAttributes : attr.bizType === import_types.AttributeBizTypes.Membership ? membershipAttributes : userAttributes;
|
|
181
|
+
const actualValue = getAttributeValue(attr.codeName, bizAttributes);
|
|
172
182
|
if (attr.dataType === import_types.BizAttributeTypes.String) {
|
|
173
183
|
return evaluateStringCondition(logic, actualValue, value);
|
|
174
184
|
}
|
|
@@ -186,8 +196,8 @@ function evaluateAttributeCondition(condition, attributes, userAttributes) {
|
|
|
186
196
|
}
|
|
187
197
|
return false;
|
|
188
198
|
}
|
|
189
|
-
function getAttributeValue(codeName,
|
|
190
|
-
return
|
|
199
|
+
function getAttributeValue(codeName, attributes) {
|
|
200
|
+
return attributes == null ? void 0 : attributes[codeName];
|
|
191
201
|
}
|
|
192
202
|
function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
193
203
|
const stringValue = actualValue === null || actualValue === void 0 ? "" : String(actualValue);
|
|
@@ -332,6 +342,74 @@ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
|
332
342
|
}
|
|
333
343
|
}
|
|
334
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
|
+
|
|
335
413
|
// src/conditions/condition.ts
|
|
336
414
|
var conditionsIsSame = (rr1, rr2) => {
|
|
337
415
|
return (0, import_fast_deep_equal.default)(rr1, rr2);
|
|
@@ -388,11 +466,7 @@ var evaluateRule = async (condition, options) => {
|
|
|
388
466
|
case import_types2.RulesType.TIME:
|
|
389
467
|
return evaluateTimeCondition(condition);
|
|
390
468
|
case import_types2.RulesType.USER_ATTR:
|
|
391
|
-
return evaluateAttributeCondition(
|
|
392
|
-
condition,
|
|
393
|
-
options.attributes || [],
|
|
394
|
-
options.userAttributes || {}
|
|
395
|
-
);
|
|
469
|
+
return evaluateAttributeCondition(condition, options);
|
|
396
470
|
default:
|
|
397
471
|
return condition.actived || false;
|
|
398
472
|
}
|
|
@@ -414,12 +488,47 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
414
488
|
}
|
|
415
489
|
return results;
|
|
416
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
|
+
};
|
|
417
523
|
// Annotate the CommonJS export names for ESM import in node:
|
|
418
524
|
0 && (module.exports = {
|
|
525
|
+
allConditionsHaveIds,
|
|
526
|
+
assignConditionIds,
|
|
419
527
|
conditionsIsSame,
|
|
420
528
|
evaluateRule,
|
|
421
529
|
evaluateRulesConditions,
|
|
422
530
|
filterConditionsByType,
|
|
423
531
|
isConditionsActived,
|
|
424
|
-
isEqual
|
|
532
|
+
isEqual,
|
|
533
|
+
regenerateConditionIds
|
|
425
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
|
-
import "../chunk-
|
|
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
|
|
|
@@ -161,20 +164,27 @@ var evaluateTimeCondition = (rules) => {
|
|
|
161
164
|
// src/conditions/attribute.ts
|
|
162
165
|
var import_types = require("@usertour/types");
|
|
163
166
|
var import_date_fns2 = require("date-fns");
|
|
164
|
-
function evaluateAttributeCondition(condition,
|
|
167
|
+
function evaluateAttributeCondition(condition, options) {
|
|
165
168
|
const { data } = condition;
|
|
166
169
|
if (!data) {
|
|
167
170
|
return false;
|
|
168
171
|
}
|
|
169
172
|
const { logic, value, attrId, value2, listValues = [] } = data;
|
|
170
|
-
|
|
173
|
+
const {
|
|
174
|
+
attributes,
|
|
175
|
+
userAttributes = {},
|
|
176
|
+
companyAttributes = {},
|
|
177
|
+
membershipAttributes = {}
|
|
178
|
+
} = options;
|
|
179
|
+
if (!attrId || !attributes) {
|
|
171
180
|
return false;
|
|
172
181
|
}
|
|
173
182
|
const attr = attributes.find((attr2) => attr2.id === attrId);
|
|
174
183
|
if (!attr) {
|
|
175
184
|
return false;
|
|
176
185
|
}
|
|
177
|
-
const
|
|
186
|
+
const bizAttributes = attr.bizType === import_types.AttributeBizTypes.Company ? companyAttributes : attr.bizType === import_types.AttributeBizTypes.Membership ? membershipAttributes : userAttributes;
|
|
187
|
+
const actualValue = getAttributeValue(attr.codeName, bizAttributes);
|
|
178
188
|
if (attr.dataType === import_types.BizAttributeTypes.String) {
|
|
179
189
|
return evaluateStringCondition(logic, actualValue, value);
|
|
180
190
|
}
|
|
@@ -192,8 +202,8 @@ function evaluateAttributeCondition(condition, attributes, userAttributes) {
|
|
|
192
202
|
}
|
|
193
203
|
return false;
|
|
194
204
|
}
|
|
195
|
-
function getAttributeValue(codeName,
|
|
196
|
-
return
|
|
205
|
+
function getAttributeValue(codeName, attributes) {
|
|
206
|
+
return attributes == null ? void 0 : attributes[codeName];
|
|
197
207
|
}
|
|
198
208
|
function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
199
209
|
const stringValue = actualValue === null || actualValue === void 0 ? "" : String(actualValue);
|
|
@@ -338,6 +348,74 @@ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
|
338
348
|
}
|
|
339
349
|
}
|
|
340
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
|
+
|
|
341
419
|
// src/conditions/condition.ts
|
|
342
420
|
var conditionsIsSame = (rr1, rr2) => {
|
|
343
421
|
return (0, import_fast_deep_equal.default)(rr1, rr2);
|
|
@@ -394,11 +472,7 @@ var evaluateRule = async (condition, options) => {
|
|
|
394
472
|
case import_types2.RulesType.TIME:
|
|
395
473
|
return evaluateTimeCondition(condition);
|
|
396
474
|
case import_types2.RulesType.USER_ATTR:
|
|
397
|
-
return evaluateAttributeCondition(
|
|
398
|
-
condition,
|
|
399
|
-
options.attributes || [],
|
|
400
|
-
options.userAttributes || {}
|
|
401
|
-
);
|
|
475
|
+
return evaluateAttributeCondition(condition, options);
|
|
402
476
|
default:
|
|
403
477
|
return condition.actived || false;
|
|
404
478
|
}
|
|
@@ -420,8 +494,42 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
420
494
|
}
|
|
421
495
|
return results;
|
|
422
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
|
+
};
|
|
423
529
|
// Annotate the CommonJS export names for ESM import in node:
|
|
424
530
|
0 && (module.exports = {
|
|
531
|
+
allConditionsHaveIds,
|
|
532
|
+
assignConditionIds,
|
|
425
533
|
conditionsIsSame,
|
|
426
534
|
evaluateAttributeCondition,
|
|
427
535
|
evaluateRule,
|
|
@@ -431,5 +539,6 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
|
|
|
431
539
|
filterConditionsByType,
|
|
432
540
|
isConditionsActived,
|
|
433
541
|
isEqual,
|
|
434
|
-
isMatchUrlPattern
|
|
542
|
+
isMatchUrlPattern,
|
|
543
|
+
regenerateConditionIds
|
|
435
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
|
|
@@ -14,12 +17,15 @@ import {
|
|
|
14
17
|
import "../chunk-PAESAL23.js";
|
|
15
18
|
import {
|
|
16
19
|
evaluateAttributeCondition
|
|
17
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-P46FJFKP.js";
|
|
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 = {
|