@usertour/helpers 0.0.17 → 0.0.20
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 +928 -0
- package/dist/__tests__/condition.test.d.cts +2 -0
- package/dist/__tests__/condition.test.d.ts +2 -0
- package/dist/__tests__/condition.test.js +545 -0
- package/dist/__tests__/url.test.cjs +314 -54
- package/dist/__tests__/url.test.js +248 -4
- package/dist/chunk-PAESAL23.js +77 -0
- package/dist/chunk-TB7JGI2Q.js +97 -0
- package/dist/chunk-YYIGUZNZ.js +17 -0
- package/dist/conditions/attribute.d.cts +2 -10
- package/dist/conditions/attribute.d.ts +2 -10
- package/dist/conditions/condition.cjs +358 -37
- package/dist/conditions/condition.d.cts +11 -2
- package/dist/conditions/condition.d.ts +11 -2
- package/dist/conditions/condition.js +11 -1
- package/dist/conditions/index.cjs +108 -104
- package/dist/conditions/index.d.cts +1 -1
- package/dist/conditions/index.d.ts +1 -1
- package/dist/conditions/index.js +10 -5
- package/dist/conditions/url-v1.cjs +89 -0
- package/dist/conditions/url-v1.d.cts +3 -0
- package/dist/conditions/url-v1.d.ts +3 -0
- package/dist/{chunk-BC7KXBMF.js → conditions/url-v1.js} +4 -8
- package/dist/conditions/url-v2.cjs +101 -0
- package/dist/conditions/url-v2.d.cts +16 -0
- package/dist/conditions/url-v2.d.ts +16 -0
- package/dist/conditions/url-v2.js +7 -0
- package/dist/conditions/url.cjs +69 -50
- package/dist/conditions/url.js +2 -1
- package/dist/index.cjs +108 -104
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -8
- package/package.json +2 -2
- package/dist/chunk-7CC4WXB3.js +0 -60
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
evaluateUrlCondition,
|
|
3
3
|
isMatchUrlPattern
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-YYIGUZNZ.js";
|
|
5
|
+
import "../chunk-PAESAL23.js";
|
|
5
6
|
import "../chunk-XEO3YXBM.js";
|
|
6
7
|
|
|
7
8
|
// src/__tests__/url.test.ts
|
|
@@ -59,7 +60,7 @@ describe("URL Condition Evaluation", () => {
|
|
|
59
60
|
const url = "https://example.com/dashboard";
|
|
60
61
|
expect(evaluateUrlCondition(rules, url)).toBe(true);
|
|
61
62
|
});
|
|
62
|
-
test("should return
|
|
63
|
+
test("should return false when no includes and no excludes specified", () => {
|
|
63
64
|
const rules = {
|
|
64
65
|
id: "condition-5",
|
|
65
66
|
type: "condition",
|
|
@@ -70,7 +71,7 @@ describe("URL Condition Evaluation", () => {
|
|
|
70
71
|
}
|
|
71
72
|
};
|
|
72
73
|
const url = "https://example.com/dashboard";
|
|
73
|
-
expect(evaluateUrlCondition(rules, url)).toBe(
|
|
74
|
+
expect(evaluateUrlCondition(rules, url)).toBe(false);
|
|
74
75
|
});
|
|
75
76
|
test("should return false when URL matches exclude even with no includes", () => {
|
|
76
77
|
const rules = {
|
|
@@ -85,6 +86,97 @@ describe("URL Condition Evaluation", () => {
|
|
|
85
86
|
const url = "https://example.com/admin";
|
|
86
87
|
expect(evaluateUrlCondition(rules, url)).toBe(false);
|
|
87
88
|
});
|
|
89
|
+
test("should handle URLs with ports", () => {
|
|
90
|
+
const rules = {
|
|
91
|
+
id: "condition-7",
|
|
92
|
+
type: "condition",
|
|
93
|
+
operators: "and",
|
|
94
|
+
data: {
|
|
95
|
+
includes: ["https://example.com:8080/dashboard"],
|
|
96
|
+
excludes: []
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const url = "https://example.com:8080/dashboard";
|
|
100
|
+
expect(evaluateUrlCondition(rules, url)).toBe(true);
|
|
101
|
+
});
|
|
102
|
+
test("should handle URLs with complex query parameters", () => {
|
|
103
|
+
const rules = {
|
|
104
|
+
id: "condition-8",
|
|
105
|
+
type: "condition",
|
|
106
|
+
operators: "and",
|
|
107
|
+
data: {
|
|
108
|
+
includes: ["https://example.com/dashboard?tab=overview&user=123"],
|
|
109
|
+
excludes: []
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const url = "https://example.com/dashboard?tab=overview&user=123";
|
|
113
|
+
expect(evaluateUrlCondition(rules, url)).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
test("should handle URLs with special characters in query parameters", () => {
|
|
116
|
+
const rules = {
|
|
117
|
+
id: "condition-9",
|
|
118
|
+
type: "condition",
|
|
119
|
+
operators: "and",
|
|
120
|
+
data: {
|
|
121
|
+
includes: ["https://example.com/search?q=hello+world"],
|
|
122
|
+
excludes: []
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
const url = "https://example.com/search?q=hello+world";
|
|
126
|
+
expect(evaluateUrlCondition(rules, url)).toBe(false);
|
|
127
|
+
});
|
|
128
|
+
test("should handle URLs with fragments", () => {
|
|
129
|
+
const rules = {
|
|
130
|
+
id: "condition-10",
|
|
131
|
+
type: "condition",
|
|
132
|
+
operators: "and",
|
|
133
|
+
data: {
|
|
134
|
+
includes: ["https://example.com/dashboard#overview"],
|
|
135
|
+
excludes: []
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const url = "https://example.com/dashboard#overview";
|
|
139
|
+
expect(evaluateUrlCondition(rules, url)).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
test("should handle wildcard patterns in query parameters", () => {
|
|
142
|
+
const rules = {
|
|
143
|
+
id: "condition-11",
|
|
144
|
+
type: "condition",
|
|
145
|
+
operators: "and",
|
|
146
|
+
data: {
|
|
147
|
+
includes: ["https://example.com/dashboard?tab=*"],
|
|
148
|
+
excludes: []
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const url = "https://example.com/dashboard?tab=overview";
|
|
152
|
+
expect(evaluateUrlCondition(rules, url)).toBe(true);
|
|
153
|
+
});
|
|
154
|
+
test("should handle empty query parameter values", () => {
|
|
155
|
+
const rules = {
|
|
156
|
+
id: "condition-12",
|
|
157
|
+
type: "condition",
|
|
158
|
+
operators: "and",
|
|
159
|
+
data: {
|
|
160
|
+
includes: ["https://example.com/dashboard?tab="],
|
|
161
|
+
excludes: []
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const url = "https://example.com/dashboard?tab=";
|
|
165
|
+
expect(evaluateUrlCondition(rules, url)).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
test("should handle multiple query parameters with wildcards", () => {
|
|
168
|
+
const rules = {
|
|
169
|
+
id: "condition-13",
|
|
170
|
+
type: "condition",
|
|
171
|
+
operators: "and",
|
|
172
|
+
data: {
|
|
173
|
+
includes: ["https://example.com/dashboard?tab=*&user=*"],
|
|
174
|
+
excludes: []
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const url = "https://example.com/dashboard?tab=overview&user=123";
|
|
178
|
+
expect(evaluateUrlCondition(rules, url)).toBe(true);
|
|
179
|
+
});
|
|
88
180
|
});
|
|
89
181
|
describe("isMatchUrlPattern", () => {
|
|
90
182
|
test("should match exact URL", () => {
|
|
@@ -131,7 +223,7 @@ describe("URL Condition Evaluation", () => {
|
|
|
131
223
|
const url = "https://example.com/dashboard";
|
|
132
224
|
const includes = [];
|
|
133
225
|
const excludes = [];
|
|
134
|
-
expect(isMatchUrlPattern(url, includes, excludes)).toBe(
|
|
226
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(false);
|
|
135
227
|
});
|
|
136
228
|
test("should handle empty excludes", () => {
|
|
137
229
|
const url = "https://example.com/dashboard";
|
|
@@ -193,5 +285,157 @@ describe("URL Condition Evaluation", () => {
|
|
|
193
285
|
const excludes = ["https://example.com/admin", "https://example.com/settings"];
|
|
194
286
|
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
195
287
|
});
|
|
288
|
+
test("should handle URLs with special regex characters", () => {
|
|
289
|
+
const url = "https://example.com/dashboard?param=value+with+spaces";
|
|
290
|
+
const includes = ["https://example.com/dashboard?param=value+with+spaces"];
|
|
291
|
+
const excludes = [];
|
|
292
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(false);
|
|
293
|
+
});
|
|
294
|
+
test("should handle URLs with encoded characters", () => {
|
|
295
|
+
const url = "https://example.com/search?q=hello%20world";
|
|
296
|
+
const includes = ["https://example.com/search?q=hello%20world"];
|
|
297
|
+
const excludes = [];
|
|
298
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
299
|
+
});
|
|
300
|
+
test("should handle URLs with multiple query parameters in different order", () => {
|
|
301
|
+
const url = "https://example.com/dashboard?tab=overview&user=123&theme=dark";
|
|
302
|
+
const includes = ["https://example.com/dashboard?user=123&tab=overview"];
|
|
303
|
+
const excludes = [];
|
|
304
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
305
|
+
});
|
|
306
|
+
test("should handle URLs with empty path", () => {
|
|
307
|
+
const url = "https://example.com/";
|
|
308
|
+
const includes = ["https://example.com/"];
|
|
309
|
+
const excludes = [];
|
|
310
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
311
|
+
});
|
|
312
|
+
test("should handle URLs with root path wildcard", () => {
|
|
313
|
+
const url = "https://example.com/";
|
|
314
|
+
const includes = ["https://example.com/*"];
|
|
315
|
+
const excludes = [];
|
|
316
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
317
|
+
});
|
|
318
|
+
test("should handle URLs with subdomain wildcards", () => {
|
|
319
|
+
const url = "https://app.example.com/dashboard";
|
|
320
|
+
const includes = ["https://*.example.com/dashboard"];
|
|
321
|
+
const excludes = [];
|
|
322
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
323
|
+
});
|
|
324
|
+
test("should handle URLs with port numbers", () => {
|
|
325
|
+
const url = "https://example.com:3000/dashboard";
|
|
326
|
+
const includes = ["https://example.com:3000/dashboard"];
|
|
327
|
+
const excludes = [];
|
|
328
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
329
|
+
});
|
|
330
|
+
test("should handle URLs with port wildcards", () => {
|
|
331
|
+
const url = "https://example.com:8080/dashboard";
|
|
332
|
+
const includes = ["https://example.com:*/dashboard"];
|
|
333
|
+
const excludes = [];
|
|
334
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
335
|
+
});
|
|
336
|
+
test("should handle complex fragment patterns", () => {
|
|
337
|
+
const url = "https://example.com/dashboard#section-1";
|
|
338
|
+
const includes = ["https://example.com/dashboard#section-*"];
|
|
339
|
+
const excludes = [];
|
|
340
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
341
|
+
});
|
|
342
|
+
test("should handle URLs with special characters in path", () => {
|
|
343
|
+
const url = "https://example.com/user/123/profile";
|
|
344
|
+
const includes = ["https://example.com/user/*/profile"];
|
|
345
|
+
const excludes = [];
|
|
346
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
347
|
+
});
|
|
348
|
+
test("should handle URLs with query parameters containing special characters", () => {
|
|
349
|
+
const url = "https://example.com/search?q=hello&filter=active";
|
|
350
|
+
const includes = ["https://example.com/search?q=*&filter=active"];
|
|
351
|
+
const excludes = [];
|
|
352
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
353
|
+
});
|
|
354
|
+
test("should handle URLs with empty query parameter values", () => {
|
|
355
|
+
const url = "https://example.com/dashboard?tab=";
|
|
356
|
+
const includes = ["https://example.com/dashboard?tab="];
|
|
357
|
+
const excludes = [];
|
|
358
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
359
|
+
});
|
|
360
|
+
test("should handle URLs with query parameters that have no value", () => {
|
|
361
|
+
const url = "https://example.com/dashboard?tab";
|
|
362
|
+
const includes = ["https://example.com/dashboard?tab"];
|
|
363
|
+
const excludes = [];
|
|
364
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
365
|
+
});
|
|
366
|
+
test("should handle URLs with multiple fragments", () => {
|
|
367
|
+
const url = "https://example.com/dashboard#section-1#subsection-a";
|
|
368
|
+
const includes = ["https://example.com/dashboard#section-1#*"];
|
|
369
|
+
const excludes = [];
|
|
370
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
371
|
+
});
|
|
372
|
+
test("should handle URLs with IPv4 addresses", () => {
|
|
373
|
+
const url = "https://192.168.1.1/dashboard";
|
|
374
|
+
const includes = ["https://192.168.1.1/dashboard"];
|
|
375
|
+
const excludes = [];
|
|
376
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
377
|
+
});
|
|
378
|
+
test("should handle URLs with IPv6 addresses", () => {
|
|
379
|
+
const url = "https://[2001:db8::1]/dashboard";
|
|
380
|
+
const includes = ["https://[2001:db8::1]/dashboard"];
|
|
381
|
+
const excludes = [];
|
|
382
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
383
|
+
});
|
|
384
|
+
test("should handle URLs with mixed case in domain", () => {
|
|
385
|
+
const url = "https://Example.COM/dashboard";
|
|
386
|
+
const includes = ["https://example.com/dashboard"];
|
|
387
|
+
const excludes = [];
|
|
388
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(false);
|
|
389
|
+
});
|
|
390
|
+
test("should handle URLs with mixed case in path", () => {
|
|
391
|
+
const url = "https://example.com/Dashboard";
|
|
392
|
+
const includes = ["https://example.com/dashboard"];
|
|
393
|
+
const excludes = [];
|
|
394
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(false);
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
describe("Implementation Compatibility Tests", () => {
|
|
398
|
+
test("should handle query parameters with special characters consistently", () => {
|
|
399
|
+
const url = "https://example.com/search?q=hello+world&filter=active";
|
|
400
|
+
const includes = ["https://example.com/search?q=hello+world"];
|
|
401
|
+
const excludes = [];
|
|
402
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(false);
|
|
403
|
+
});
|
|
404
|
+
test("should handle query parameters with encoded characters consistently", () => {
|
|
405
|
+
const url = "https://example.com/search?q=hello%20world";
|
|
406
|
+
const includes = ["https://example.com/search?q=hello%20world"];
|
|
407
|
+
const excludes = [];
|
|
408
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
409
|
+
});
|
|
410
|
+
test("should handle query parameters with wildcards consistently", () => {
|
|
411
|
+
const url = "https://example.com/search?q=hello&filter=*";
|
|
412
|
+
const includes = ["https://example.com/search?q=*&filter=active"];
|
|
413
|
+
const excludes = [];
|
|
414
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(false);
|
|
415
|
+
});
|
|
416
|
+
test("should handle empty includes and excludes consistently", () => {
|
|
417
|
+
const url = "https://example.com/dashboard";
|
|
418
|
+
const includes = [];
|
|
419
|
+
const excludes = [];
|
|
420
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(false);
|
|
421
|
+
});
|
|
422
|
+
test("should handle only excludes consistently", () => {
|
|
423
|
+
const url = "https://example.com/dashboard";
|
|
424
|
+
const includes = [];
|
|
425
|
+
const excludes = ["https://example.com/admin"];
|
|
426
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
427
|
+
});
|
|
428
|
+
test("should handle complex nested paths consistently", () => {
|
|
429
|
+
const url = "https://example.com/app/dashboard/user/123/settings";
|
|
430
|
+
const includes = ["https://example.com/app/*/user/*/settings"];
|
|
431
|
+
const excludes = [];
|
|
432
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
433
|
+
});
|
|
434
|
+
test("should handle URLs with multiple query parameters consistently", () => {
|
|
435
|
+
const url = "https://example.com/dashboard?tab=overview&user=123&theme=dark&lang=en";
|
|
436
|
+
const includes = ["https://example.com/dashboard?tab=overview&user=*&theme=dark"];
|
|
437
|
+
const excludes = [];
|
|
438
|
+
expect(isMatchUrlPattern(url, includes, excludes)).toBe(true);
|
|
439
|
+
});
|
|
196
440
|
});
|
|
197
441
|
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// src/conditions/url-v2.ts
|
|
2
|
+
function parseUrl(url) {
|
|
3
|
+
const match = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
|
|
4
|
+
if (!match)
|
|
5
|
+
return null;
|
|
6
|
+
const [, , scheme, domain, path, , query, fragment] = match;
|
|
7
|
+
return {
|
|
8
|
+
scheme: scheme || "",
|
|
9
|
+
domain: domain || "",
|
|
10
|
+
path: path || "",
|
|
11
|
+
query: query || "",
|
|
12
|
+
fragment: fragment || ""
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function escapeRegex(str) {
|
|
16
|
+
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
17
|
+
}
|
|
18
|
+
function processUrlPattern(pattern, wildcardReplacement, paramReplacement) {
|
|
19
|
+
let processed = escapeRegex(pattern);
|
|
20
|
+
processed = processed.replace(/\\\*/g, `${wildcardReplacement}*`);
|
|
21
|
+
if (paramReplacement) {
|
|
22
|
+
processed = processed.replace(/:[a-zA-Z0-9_]+/g, `[^${paramReplacement}]+`);
|
|
23
|
+
}
|
|
24
|
+
return processed;
|
|
25
|
+
}
|
|
26
|
+
function urlPatternToRegex(pattern) {
|
|
27
|
+
const parsed = parseUrl(pattern);
|
|
28
|
+
if (!parsed) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const { scheme, domain, path, query, fragment } = parsed;
|
|
32
|
+
const schemePattern = scheme ? escapeRegex(scheme) : "[a-z\\d]+";
|
|
33
|
+
const domainPattern = domain ? processUrlPattern(domain, "[^/]", ".") : "[^/]*";
|
|
34
|
+
const portPattern = "(:\\d+)?";
|
|
35
|
+
const pathPattern = path ? processUrlPattern(path, "[^?#]", "/") : "/[^?#]*";
|
|
36
|
+
let queryPattern;
|
|
37
|
+
if (query) {
|
|
38
|
+
queryPattern = "";
|
|
39
|
+
new URLSearchParams(query).forEach((value, key) => {
|
|
40
|
+
let valuePattern;
|
|
41
|
+
if (value === "") {
|
|
42
|
+
valuePattern = "=?";
|
|
43
|
+
} else if (value === "*") {
|
|
44
|
+
valuePattern = "(=[^&#]*)?";
|
|
45
|
+
} else {
|
|
46
|
+
const encodedValue = value.split(/\*/g).map((part) => encodeURI(part)).join("*");
|
|
47
|
+
valuePattern = `=${processUrlPattern(encodedValue, "[^#]")}`;
|
|
48
|
+
}
|
|
49
|
+
queryPattern += `(?=.*[?&]${escapeRegex(key)}${valuePattern}([&#]|$))`;
|
|
50
|
+
});
|
|
51
|
+
queryPattern += "\\?[^#]*";
|
|
52
|
+
} else {
|
|
53
|
+
queryPattern = "(\\?[^#]*)?";
|
|
54
|
+
}
|
|
55
|
+
const fragmentPattern = fragment ? processUrlPattern(fragment, ".", "/") : "(#.*)?";
|
|
56
|
+
return new RegExp(
|
|
57
|
+
`^${schemePattern}://${domainPattern}${portPattern}${pathPattern}${queryPattern}${fragmentPattern}$`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
function matchUrlPattern(urlPattern, url) {
|
|
61
|
+
if (urlPattern.includes.length === 0 && urlPattern.excludes.length === 0) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const matchesInclude = urlPattern.includes.length === 0 || urlPattern.includes.some((includePattern) => {
|
|
65
|
+
const regex = urlPatternToRegex(includePattern);
|
|
66
|
+
return regex && url.match(regex);
|
|
67
|
+
});
|
|
68
|
+
const matchesExclude = urlPattern.excludes.some((excludePattern) => {
|
|
69
|
+
const regex = urlPatternToRegex(excludePattern);
|
|
70
|
+
return regex && url.match(regex);
|
|
71
|
+
});
|
|
72
|
+
return matchesInclude && !matchesExclude;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
matchUrlPattern
|
|
77
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
evaluateUrlCondition
|
|
3
|
+
} from "./chunk-YYIGUZNZ.js";
|
|
4
|
+
import {
|
|
5
|
+
evaluateAttributeCondition
|
|
6
|
+
} from "./chunk-PBZSPV5R.js";
|
|
7
|
+
import {
|
|
8
|
+
evaluateTimeCondition
|
|
9
|
+
} from "./chunk-CEK3SCQO.js";
|
|
10
|
+
|
|
11
|
+
// src/conditions/condition.ts
|
|
12
|
+
import {
|
|
13
|
+
RulesType
|
|
14
|
+
} from "@usertour/types";
|
|
15
|
+
import isEqual from "fast-deep-equal";
|
|
16
|
+
var conditionsIsSame = (rr1, rr2) => {
|
|
17
|
+
return isEqual(rr1, rr2);
|
|
18
|
+
};
|
|
19
|
+
var isConditionsActived = (conditions) => {
|
|
20
|
+
if (!conditions || conditions.length === 0) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const operator = conditions[0].operators;
|
|
24
|
+
const actives = conditions.filter((rule) => {
|
|
25
|
+
if (!rule.conditions) {
|
|
26
|
+
return rule.actived;
|
|
27
|
+
}
|
|
28
|
+
return isConditionsActived(rule.conditions);
|
|
29
|
+
});
|
|
30
|
+
return operator === "and" ? actives.length === conditions.length : actives.length > 0;
|
|
31
|
+
};
|
|
32
|
+
var filterConditionsByType = (conditions, allowedTypes) => {
|
|
33
|
+
return conditions.filter((condition) => {
|
|
34
|
+
if (condition.type === "group" && condition.conditions) {
|
|
35
|
+
const filteredGroupConditions = filterConditionsByType(condition.conditions, allowedTypes);
|
|
36
|
+
return filteredGroupConditions.length > 0;
|
|
37
|
+
}
|
|
38
|
+
return allowedTypes.includes(condition.type);
|
|
39
|
+
}).map((condition) => {
|
|
40
|
+
if (condition.type === "group" && condition.conditions) {
|
|
41
|
+
return {
|
|
42
|
+
...condition,
|
|
43
|
+
conditions: filterConditionsByType(condition.conditions, allowedTypes)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return condition;
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var evaluateRule = (rule, options) => {
|
|
50
|
+
var _a;
|
|
51
|
+
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
52
|
+
const ruleId = rule.id;
|
|
53
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
54
|
+
return true;
|
|
55
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
56
|
+
return false;
|
|
57
|
+
if (typeControl[rule.type] === false) {
|
|
58
|
+
return rule.actived || false;
|
|
59
|
+
}
|
|
60
|
+
switch (rule.type) {
|
|
61
|
+
case RulesType.CURRENT_PAGE:
|
|
62
|
+
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
63
|
+
case RulesType.TIME:
|
|
64
|
+
return evaluateTimeCondition(rule);
|
|
65
|
+
case RulesType.USER_ATTR:
|
|
66
|
+
case RulesType.COMPANY_ATTR:
|
|
67
|
+
return evaluateAttributeCondition(
|
|
68
|
+
rule,
|
|
69
|
+
options.attributes || [],
|
|
70
|
+
options.userAttributes || {}
|
|
71
|
+
);
|
|
72
|
+
default:
|
|
73
|
+
return rule.actived || false;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var activedRulesConditions = (conditions, options = {}) => {
|
|
77
|
+
return conditions.map((rule) => {
|
|
78
|
+
if (rule.type === "group" && rule.conditions) {
|
|
79
|
+
return {
|
|
80
|
+
...rule,
|
|
81
|
+
conditions: activedRulesConditions(rule.conditions, options)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
...rule,
|
|
86
|
+
actived: evaluateRule(rule, options)
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
isEqual,
|
|
93
|
+
conditionsIsSame,
|
|
94
|
+
isConditionsActived,
|
|
95
|
+
filterConditionsByType,
|
|
96
|
+
activedRulesConditions
|
|
97
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
matchUrlPattern
|
|
3
|
+
} from "./chunk-PAESAL23.js";
|
|
4
|
+
|
|
5
|
+
// src/conditions/url.ts
|
|
6
|
+
var isMatchUrlPattern = (_url, includes, excludes) => {
|
|
7
|
+
return matchUrlPattern({ includes, excludes }, _url);
|
|
8
|
+
};
|
|
9
|
+
var evaluateUrlCondition = (rules, url) => {
|
|
10
|
+
const { excludes = [], includes = [] } = rules.data || {};
|
|
11
|
+
return isMatchUrlPattern(url, includes, excludes);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
isMatchUrlPattern,
|
|
16
|
+
evaluateUrlCondition
|
|
17
|
+
};
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import { RulesCondition, UserTourTypes } from '@usertour/types';
|
|
1
|
+
import { RulesCondition, SimpleAttribute, UserTourTypes } from '@usertour/types';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Simplified attribute type with only required fields
|
|
5
|
-
*/
|
|
6
|
-
interface SimpleAttribute {
|
|
7
|
-
id: string;
|
|
8
|
-
codeName: string;
|
|
9
|
-
dataType: number;
|
|
10
|
-
}
|
|
11
3
|
/**
|
|
12
4
|
* Evaluate filter conditions and return boolean result
|
|
13
5
|
* @param conditions - Filter conditions to evaluate
|
|
@@ -25,4 +17,4 @@ declare function evaluateFilterConditions(conditions: RulesCondition[], attribut
|
|
|
25
17
|
*/
|
|
26
18
|
declare function evaluateAttributeCondition(condition: RulesCondition, attributes: SimpleAttribute[], userAttributes: UserTourTypes.Attributes): any;
|
|
27
19
|
|
|
28
|
-
export {
|
|
20
|
+
export { evaluateAttributeCondition, evaluateFilterConditions };
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import { RulesCondition, UserTourTypes } from '@usertour/types';
|
|
1
|
+
import { RulesCondition, SimpleAttribute, UserTourTypes } from '@usertour/types';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Simplified attribute type with only required fields
|
|
5
|
-
*/
|
|
6
|
-
interface SimpleAttribute {
|
|
7
|
-
id: string;
|
|
8
|
-
codeName: string;
|
|
9
|
-
dataType: number;
|
|
10
|
-
}
|
|
11
3
|
/**
|
|
12
4
|
* Evaluate filter conditions and return boolean result
|
|
13
5
|
* @param conditions - Filter conditions to evaluate
|
|
@@ -25,4 +17,4 @@ declare function evaluateFilterConditions(conditions: RulesCondition[], attribut
|
|
|
25
17
|
*/
|
|
26
18
|
declare function evaluateAttributeCondition(condition: RulesCondition, attributes: SimpleAttribute[], userAttributes: UserTourTypes.Attributes): any;
|
|
27
19
|
|
|
28
|
-
export {
|
|
20
|
+
export { evaluateAttributeCondition, evaluateFilterConditions };
|