@usertour/helpers 0.0.18 → 0.0.21
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 +679 -8
- package/dist/__tests__/condition.test.js +342 -1
- 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-UNXDVBM3.js +98 -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 +328 -39
- package/dist/conditions/condition.d.cts +29 -3
- package/dist/conditions/condition.d.ts +29 -3
- package/dist/conditions/condition.js +9 -1
- package/dist/conditions/index.cjs +153 -104
- package/dist/conditions/index.d.cts +1 -1
- package/dist/conditions/index.d.ts +1 -1
- package/dist/conditions/index.js +14 -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 +153 -104
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -8
- package/package.json +2 -2
- package/dist/chunk-YOFQHQ7D.js +0 -92
|
@@ -30,134 +30,103 @@ 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
|
+
activedRulesConditions: () => activedRulesConditions,
|
|
33
34
|
conditionsIsSame: () => conditionsIsSame,
|
|
34
35
|
evaluateAttributeCondition: () => evaluateAttributeCondition,
|
|
36
|
+
evaluateRule: () => evaluateRule,
|
|
35
37
|
evaluateTimeCondition: () => evaluateTimeCondition,
|
|
36
38
|
evaluateUrlCondition: () => evaluateUrlCondition,
|
|
39
|
+
filterConditionsByType: () => filterConditionsByType,
|
|
40
|
+
isConditionsActived: () => isConditionsActived,
|
|
37
41
|
isEqual: () => import_fast_deep_equal.default,
|
|
38
42
|
isMatchUrlPattern: () => isMatchUrlPattern
|
|
39
43
|
});
|
|
40
44
|
module.exports = __toCommonJS(conditions_exports);
|
|
41
45
|
|
|
42
46
|
// src/conditions/condition.ts
|
|
47
|
+
var import_types2 = require("@usertour/types");
|
|
43
48
|
var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
|
|
44
|
-
var compareConditionsItem = (item1, item2) => {
|
|
45
|
-
const { data = {}, ...others1 } = item1;
|
|
46
|
-
const { data: data2 = {}, ...others2 } = item2;
|
|
47
|
-
if (!(0, import_fast_deep_equal.default)(others2, others1)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
for (const key in data) {
|
|
51
|
-
if (!(0, import_fast_deep_equal.default)(data[key], data2[key])) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return true;
|
|
56
|
-
};
|
|
57
|
-
var conditionsIsSame = (rr1, rr2) => {
|
|
58
|
-
const r1 = [...rr1];
|
|
59
|
-
const r2 = [...rr2];
|
|
60
|
-
if (r1.length === 0 && r2.length === 0) {
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
if (r1.length !== r2.length) {
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
const group1 = r1.filter((item) => item.type === "group");
|
|
67
|
-
const group2 = r2.filter((item) => item.type === "group");
|
|
68
|
-
if (group1.length !== group2.length) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
for (let index = 0; index < r1.length; index++) {
|
|
72
|
-
const item1 = r1[index];
|
|
73
|
-
const item2 = r2[index];
|
|
74
|
-
if (!item1 || !item2) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
if (item1.type === "group") {
|
|
78
|
-
if (!item2.conditions) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
const c1 = item1.conditions;
|
|
82
|
-
const c2 = item2.conditions;
|
|
83
|
-
if (item1.operators !== item2.operators) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
if (!conditionsIsSame(c1, c2)) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
if (!compareConditionsItem(item1, item2)) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return true;
|
|
96
|
-
};
|
|
97
49
|
|
|
98
|
-
// src/conditions/url.ts
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
if (!
|
|
50
|
+
// src/conditions/url-v2.ts
|
|
51
|
+
function parseUrl(url) {
|
|
52
|
+
const match = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
|
|
53
|
+
if (!match)
|
|
102
54
|
return null;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return withWildcard.replace(/:[a-z0-9_]+/g, `[^${s2}]+`);
|
|
114
|
-
};
|
|
115
|
-
var replaceSpecialWords = (str) => {
|
|
55
|
+
const [, , scheme, domain, path, , query, fragment] = match;
|
|
56
|
+
return {
|
|
57
|
+
scheme: scheme || "",
|
|
58
|
+
domain: domain || "",
|
|
59
|
+
path: path || "",
|
|
60
|
+
query: query || "",
|
|
61
|
+
fragment: fragment || ""
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function escapeRegex(str) {
|
|
116
65
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
66
|
+
}
|
|
67
|
+
function processUrlPattern(pattern, wildcardReplacement, paramReplacement) {
|
|
68
|
+
let processed = escapeRegex(pattern);
|
|
69
|
+
processed = processed.replace(/\\\*/g, `${wildcardReplacement}*`);
|
|
70
|
+
if (paramReplacement) {
|
|
71
|
+
processed = processed.replace(/:[a-zA-Z0-9_]+/g, `[^${paramReplacement}]+`);
|
|
121
72
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
73
|
+
return processed;
|
|
74
|
+
}
|
|
75
|
+
function urlPatternToRegex(pattern) {
|
|
76
|
+
const parsed = parseUrl(pattern);
|
|
77
|
+
if (!parsed) {
|
|
125
78
|
return null;
|
|
126
79
|
}
|
|
127
|
-
const { scheme, domain, path, query, fragment } =
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
const
|
|
132
|
-
let
|
|
80
|
+
const { scheme, domain, path, query, fragment } = parsed;
|
|
81
|
+
const schemePattern = scheme ? escapeRegex(scheme) : "[a-z\\d]+";
|
|
82
|
+
const domainPattern = domain ? processUrlPattern(domain, "[^/]", ".") : "[^/]*";
|
|
83
|
+
const portPattern = "(:\\d+)?";
|
|
84
|
+
const pathPattern = path ? processUrlPattern(path, "[^?#]", "/") : "/[^?#]*";
|
|
85
|
+
let queryPattern;
|
|
133
86
|
if (query) {
|
|
87
|
+
queryPattern = "";
|
|
134
88
|
new URLSearchParams(query).forEach((value, key) => {
|
|
135
|
-
|
|
136
|
-
|
|
89
|
+
let valuePattern;
|
|
90
|
+
if (value === "") {
|
|
91
|
+
valuePattern = "=?";
|
|
92
|
+
} else if (value === "*") {
|
|
93
|
+
valuePattern = "(=[^&#]*)?";
|
|
94
|
+
} else {
|
|
95
|
+
const encodedValue = value.split(/\*/g).map((part) => encodeURI(part)).join("*");
|
|
96
|
+
valuePattern = `=${processUrlPattern(encodedValue, "[^#]")}`;
|
|
97
|
+
}
|
|
98
|
+
queryPattern += `(?=.*[?&]${escapeRegex(key)}${valuePattern}([&#]|$))`;
|
|
137
99
|
});
|
|
138
|
-
|
|
100
|
+
queryPattern += "\\?[^#]*";
|
|
101
|
+
} else {
|
|
102
|
+
queryPattern = "(\\?[^#]*)?";
|
|
139
103
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
return false;
|
|
149
|
-
}) : true;
|
|
150
|
-
const isMatchExcludesConditions = excludes.length > 0 ? excludes.some((_exclude) => {
|
|
151
|
-
const reg = parsePattern(_exclude);
|
|
152
|
-
if (reg) {
|
|
153
|
-
return reg.test(_url);
|
|
154
|
-
}
|
|
104
|
+
const fragmentPattern = fragment ? processUrlPattern(fragment, ".", "/") : "(#.*)?";
|
|
105
|
+
return new RegExp(
|
|
106
|
+
`^${schemePattern}://${domainPattern}${portPattern}${pathPattern}${queryPattern}${fragmentPattern}$`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
function matchUrlPattern(urlPattern, url) {
|
|
110
|
+
if (urlPattern.includes.length === 0 && urlPattern.excludes.length === 0) {
|
|
155
111
|
return false;
|
|
156
|
-
}
|
|
157
|
-
|
|
112
|
+
}
|
|
113
|
+
const matchesInclude = urlPattern.includes.length === 0 || urlPattern.includes.some((includePattern) => {
|
|
114
|
+
const regex = urlPatternToRegex(includePattern);
|
|
115
|
+
return regex && url.match(regex);
|
|
116
|
+
});
|
|
117
|
+
const matchesExclude = urlPattern.excludes.some((excludePattern) => {
|
|
118
|
+
const regex = urlPatternToRegex(excludePattern);
|
|
119
|
+
return regex && url.match(regex);
|
|
120
|
+
});
|
|
121
|
+
return matchesInclude && !matchesExclude;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/conditions/url.ts
|
|
125
|
+
var isMatchUrlPattern = (_url, includes, excludes) => {
|
|
126
|
+
return matchUrlPattern({ includes, excludes }, _url);
|
|
158
127
|
};
|
|
159
128
|
var evaluateUrlCondition = (rules, url) => {
|
|
160
|
-
const { excludes, includes } = rules.data;
|
|
129
|
+
const { excludes = [], includes = [] } = rules.data || {};
|
|
161
130
|
return isMatchUrlPattern(url, includes, excludes);
|
|
162
131
|
};
|
|
163
132
|
|
|
@@ -368,12 +337,92 @@ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
|
|
|
368
337
|
return false;
|
|
369
338
|
}
|
|
370
339
|
}
|
|
340
|
+
|
|
341
|
+
// src/conditions/condition.ts
|
|
342
|
+
var conditionsIsSame = (rr1, rr2) => {
|
|
343
|
+
return (0, import_fast_deep_equal.default)(rr1, rr2);
|
|
344
|
+
};
|
|
345
|
+
var isConditionsActived = (conditions) => {
|
|
346
|
+
if (!conditions || conditions.length === 0) {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
const operator = conditions[0].operators;
|
|
350
|
+
const actives = conditions.filter((rule) => {
|
|
351
|
+
if (!rule.conditions) {
|
|
352
|
+
return rule.actived;
|
|
353
|
+
}
|
|
354
|
+
return isConditionsActived(rule.conditions);
|
|
355
|
+
});
|
|
356
|
+
return operator === "and" ? actives.length === conditions.length : actives.length > 0;
|
|
357
|
+
};
|
|
358
|
+
var filterConditionsByType = (conditions, allowedTypes) => {
|
|
359
|
+
return conditions.filter((condition) => {
|
|
360
|
+
if (condition.type === "group" && condition.conditions) {
|
|
361
|
+
const filteredGroupConditions = filterConditionsByType(condition.conditions, allowedTypes);
|
|
362
|
+
return filteredGroupConditions.length > 0;
|
|
363
|
+
}
|
|
364
|
+
return allowedTypes.includes(condition.type);
|
|
365
|
+
}).map((condition) => {
|
|
366
|
+
if (condition.type === "group" && condition.conditions) {
|
|
367
|
+
return {
|
|
368
|
+
...condition,
|
|
369
|
+
conditions: filterConditionsByType(condition.conditions, allowedTypes)
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
return condition;
|
|
373
|
+
});
|
|
374
|
+
};
|
|
375
|
+
var evaluateRule = (rule, options) => {
|
|
376
|
+
var _a;
|
|
377
|
+
const { typeControl = {}, activatedIds, deactivatedIds } = options;
|
|
378
|
+
const ruleId = rule.id;
|
|
379
|
+
if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
|
|
380
|
+
return true;
|
|
381
|
+
if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
|
|
382
|
+
return false;
|
|
383
|
+
if (typeControl[rule.type] === false) {
|
|
384
|
+
return rule.actived || false;
|
|
385
|
+
}
|
|
386
|
+
switch (rule.type) {
|
|
387
|
+
case import_types2.RulesType.CURRENT_PAGE:
|
|
388
|
+
return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
|
|
389
|
+
case import_types2.RulesType.TIME:
|
|
390
|
+
return evaluateTimeCondition(rule);
|
|
391
|
+
case import_types2.RulesType.USER_ATTR:
|
|
392
|
+
case import_types2.RulesType.COMPANY_ATTR:
|
|
393
|
+
return evaluateAttributeCondition(
|
|
394
|
+
rule,
|
|
395
|
+
options.attributes || [],
|
|
396
|
+
options.userAttributes || {}
|
|
397
|
+
);
|
|
398
|
+
default:
|
|
399
|
+
return rule.actived || false;
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
var activedRulesConditions = (conditions, options = {}) => {
|
|
403
|
+
return conditions.map((rule) => {
|
|
404
|
+
if (rule.type === "group" && rule.conditions) {
|
|
405
|
+
return {
|
|
406
|
+
...rule,
|
|
407
|
+
conditions: activedRulesConditions(rule.conditions, options)
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
return {
|
|
411
|
+
...rule,
|
|
412
|
+
actived: evaluateRule(rule, options)
|
|
413
|
+
};
|
|
414
|
+
});
|
|
415
|
+
};
|
|
371
416
|
// Annotate the CommonJS export names for ESM import in node:
|
|
372
417
|
0 && (module.exports = {
|
|
418
|
+
activedRulesConditions,
|
|
373
419
|
conditionsIsSame,
|
|
374
420
|
evaluateAttributeCondition,
|
|
421
|
+
evaluateRule,
|
|
375
422
|
evaluateTimeCondition,
|
|
376
423
|
evaluateUrlCondition,
|
|
424
|
+
filterConditionsByType,
|
|
425
|
+
isConditionsActived,
|
|
377
426
|
isEqual,
|
|
378
427
|
isMatchUrlPattern
|
|
379
428
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { conditionsIsSame } from './condition.cjs';
|
|
1
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, filterConditionsByType, isConditionsActived } 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 } from './condition.js';
|
|
1
|
+
export { activedRulesConditions, conditionsIsSame, evaluateRule, filterConditionsByType, isConditionsActived } 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,24 +1,33 @@
|
|
|
1
1
|
import "../chunk-7ODE2AIC.js";
|
|
2
|
+
import {
|
|
3
|
+
activedRulesConditions,
|
|
4
|
+
conditionsIsSame,
|
|
5
|
+
evaluateRule,
|
|
6
|
+
filterConditionsByType,
|
|
7
|
+
isConditionsActived,
|
|
8
|
+
isEqual
|
|
9
|
+
} from "../chunk-UNXDVBM3.js";
|
|
2
10
|
import {
|
|
3
11
|
evaluateUrlCondition,
|
|
4
12
|
isMatchUrlPattern
|
|
5
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-YYIGUZNZ.js";
|
|
14
|
+
import "../chunk-PAESAL23.js";
|
|
6
15
|
import {
|
|
7
16
|
evaluateAttributeCondition
|
|
8
17
|
} from "../chunk-PBZSPV5R.js";
|
|
9
|
-
import {
|
|
10
|
-
conditionsIsSame,
|
|
11
|
-
isEqual
|
|
12
|
-
} from "../chunk-YOFQHQ7D.js";
|
|
13
18
|
import {
|
|
14
19
|
evaluateTimeCondition
|
|
15
20
|
} from "../chunk-CEK3SCQO.js";
|
|
16
21
|
import "../chunk-XEO3YXBM.js";
|
|
17
22
|
export {
|
|
23
|
+
activedRulesConditions,
|
|
18
24
|
conditionsIsSame,
|
|
19
25
|
evaluateAttributeCondition,
|
|
26
|
+
evaluateRule,
|
|
20
27
|
evaluateTimeCondition,
|
|
21
28
|
evaluateUrlCondition,
|
|
29
|
+
filterConditionsByType,
|
|
30
|
+
isConditionsActived,
|
|
22
31
|
isEqual,
|
|
23
32
|
isMatchUrlPattern
|
|
24
33
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/conditions/url-v1.ts
|
|
21
|
+
var url_v1_exports = {};
|
|
22
|
+
__export(url_v1_exports, {
|
|
23
|
+
isMatchUrlPattern: () => isMatchUrlPattern
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(url_v1_exports);
|
|
26
|
+
var parseUrl = (url) => {
|
|
27
|
+
const urlPatterns = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
|
|
28
|
+
if (!urlPatterns) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const [, , scheme = "", domain = "", path = "", , query = "", fragment = ""] = urlPatterns;
|
|
32
|
+
return { scheme, domain, path, query, fragment };
|
|
33
|
+
};
|
|
34
|
+
var replaceWildcard = (input, s1, s2) => {
|
|
35
|
+
const withSpecialWords = replaceSpecialWords(input);
|
|
36
|
+
const withWildcard = withSpecialWords.replace(/\\\*/g, `${s1}*`);
|
|
37
|
+
if (!s2) {
|
|
38
|
+
return withWildcard;
|
|
39
|
+
}
|
|
40
|
+
return withWildcard.replace(/:[a-z0-9_]+/g, `[^${s2}]+`);
|
|
41
|
+
};
|
|
42
|
+
var replaceSpecialWords = (str) => {
|
|
43
|
+
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
44
|
+
};
|
|
45
|
+
var parsePattern = (pattern) => {
|
|
46
|
+
if (!pattern || !pattern.trim()) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const _pattern = parseUrl(pattern);
|
|
50
|
+
if (!_pattern) {
|
|
51
|
+
console.error("Invalid URL pattern:", pattern);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const { scheme, domain, path, query, fragment } = _pattern;
|
|
55
|
+
const _scheme = scheme ? replaceSpecialWords(scheme) : "[a-z\\d]+";
|
|
56
|
+
const _domain = domain ? replaceWildcard(domain, "[^/]", ".") : "[^/]*";
|
|
57
|
+
const _fragment = fragment ? replaceWildcard(fragment, ".", "/") : "(#.*)?";
|
|
58
|
+
const _path = path ? replaceWildcard(path, "[^?#]", "/") : "/[^?#]*";
|
|
59
|
+
let _query = "(\\?[^#]*)?";
|
|
60
|
+
if (query) {
|
|
61
|
+
new URLSearchParams(query).forEach((value, key) => {
|
|
62
|
+
const _str = value === "" ? "=?" : value === "*" ? "(=[^&#]*)?" : `=${replaceWildcard(value, "[^#]")}`;
|
|
63
|
+
_query += `(?=.*[?&]${replaceSpecialWords(key)}${_str}([&#]|$))`;
|
|
64
|
+
});
|
|
65
|
+
_query += "\\?[^#]*";
|
|
66
|
+
}
|
|
67
|
+
return new RegExp(`^${_scheme}://${_domain}(:\\d+)?${_path}${_query}${_fragment}$`);
|
|
68
|
+
};
|
|
69
|
+
var isMatchUrlPattern = (_url, includes, excludes) => {
|
|
70
|
+
const isMatchIncludesConditions = includes.length > 0 ? includes.some((_include) => {
|
|
71
|
+
const reg = parsePattern(_include);
|
|
72
|
+
if (reg) {
|
|
73
|
+
return reg.test(_url);
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}) : true;
|
|
77
|
+
const isMatchExcludesConditions = excludes.length > 0 ? excludes.some((_exclude) => {
|
|
78
|
+
const reg = parsePattern(_exclude);
|
|
79
|
+
if (reg) {
|
|
80
|
+
return reg.test(_url);
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}) : false;
|
|
84
|
+
return isMatchIncludesConditions && !isMatchExcludesConditions;
|
|
85
|
+
};
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
isMatchUrlPattern
|
|
89
|
+
});
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import "../chunk-XEO3YXBM.js";
|
|
2
|
+
|
|
3
|
+
// src/conditions/url-v1.ts
|
|
2
4
|
var parseUrl = (url) => {
|
|
3
5
|
const urlPatterns = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
|
|
4
6
|
if (!urlPatterns) {
|
|
@@ -59,12 +61,6 @@ var isMatchUrlPattern = (_url, includes, excludes) => {
|
|
|
59
61
|
}) : false;
|
|
60
62
|
return isMatchIncludesConditions && !isMatchExcludesConditions;
|
|
61
63
|
};
|
|
62
|
-
var evaluateUrlCondition = (rules, url) => {
|
|
63
|
-
const { excludes, includes } = rules.data;
|
|
64
|
-
return isMatchUrlPattern(url, includes, excludes);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
64
|
export {
|
|
68
|
-
isMatchUrlPattern
|
|
69
|
-
evaluateUrlCondition
|
|
65
|
+
isMatchUrlPattern
|
|
70
66
|
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/conditions/url-v2.ts
|
|
21
|
+
var url_v2_exports = {};
|
|
22
|
+
__export(url_v2_exports, {
|
|
23
|
+
matchUrlPattern: () => matchUrlPattern
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(url_v2_exports);
|
|
26
|
+
function parseUrl(url) {
|
|
27
|
+
const match = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
|
|
28
|
+
if (!match)
|
|
29
|
+
return null;
|
|
30
|
+
const [, , scheme, domain, path, , query, fragment] = match;
|
|
31
|
+
return {
|
|
32
|
+
scheme: scheme || "",
|
|
33
|
+
domain: domain || "",
|
|
34
|
+
path: path || "",
|
|
35
|
+
query: query || "",
|
|
36
|
+
fragment: fragment || ""
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function escapeRegex(str) {
|
|
40
|
+
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
41
|
+
}
|
|
42
|
+
function processUrlPattern(pattern, wildcardReplacement, paramReplacement) {
|
|
43
|
+
let processed = escapeRegex(pattern);
|
|
44
|
+
processed = processed.replace(/\\\*/g, `${wildcardReplacement}*`);
|
|
45
|
+
if (paramReplacement) {
|
|
46
|
+
processed = processed.replace(/:[a-zA-Z0-9_]+/g, `[^${paramReplacement}]+`);
|
|
47
|
+
}
|
|
48
|
+
return processed;
|
|
49
|
+
}
|
|
50
|
+
function urlPatternToRegex(pattern) {
|
|
51
|
+
const parsed = parseUrl(pattern);
|
|
52
|
+
if (!parsed) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const { scheme, domain, path, query, fragment } = parsed;
|
|
56
|
+
const schemePattern = scheme ? escapeRegex(scheme) : "[a-z\\d]+";
|
|
57
|
+
const domainPattern = domain ? processUrlPattern(domain, "[^/]", ".") : "[^/]*";
|
|
58
|
+
const portPattern = "(:\\d+)?";
|
|
59
|
+
const pathPattern = path ? processUrlPattern(path, "[^?#]", "/") : "/[^?#]*";
|
|
60
|
+
let queryPattern;
|
|
61
|
+
if (query) {
|
|
62
|
+
queryPattern = "";
|
|
63
|
+
new URLSearchParams(query).forEach((value, key) => {
|
|
64
|
+
let valuePattern;
|
|
65
|
+
if (value === "") {
|
|
66
|
+
valuePattern = "=?";
|
|
67
|
+
} else if (value === "*") {
|
|
68
|
+
valuePattern = "(=[^&#]*)?";
|
|
69
|
+
} else {
|
|
70
|
+
const encodedValue = value.split(/\*/g).map((part) => encodeURI(part)).join("*");
|
|
71
|
+
valuePattern = `=${processUrlPattern(encodedValue, "[^#]")}`;
|
|
72
|
+
}
|
|
73
|
+
queryPattern += `(?=.*[?&]${escapeRegex(key)}${valuePattern}([&#]|$))`;
|
|
74
|
+
});
|
|
75
|
+
queryPattern += "\\?[^#]*";
|
|
76
|
+
} else {
|
|
77
|
+
queryPattern = "(\\?[^#]*)?";
|
|
78
|
+
}
|
|
79
|
+
const fragmentPattern = fragment ? processUrlPattern(fragment, ".", "/") : "(#.*)?";
|
|
80
|
+
return new RegExp(
|
|
81
|
+
`^${schemePattern}://${domainPattern}${portPattern}${pathPattern}${queryPattern}${fragmentPattern}$`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
function matchUrlPattern(urlPattern, url) {
|
|
85
|
+
if (urlPattern.includes.length === 0 && urlPattern.excludes.length === 0) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const matchesInclude = urlPattern.includes.length === 0 || urlPattern.includes.some((includePattern) => {
|
|
89
|
+
const regex = urlPatternToRegex(includePattern);
|
|
90
|
+
return regex && url.match(regex);
|
|
91
|
+
});
|
|
92
|
+
const matchesExclude = urlPattern.excludes.some((excludePattern) => {
|
|
93
|
+
const regex = urlPatternToRegex(excludePattern);
|
|
94
|
+
return regex && url.match(regex);
|
|
95
|
+
});
|
|
96
|
+
return matchesInclude && !matchesExclude;
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
matchUrlPattern
|
|
101
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL pattern object interface
|
|
3
|
+
*/
|
|
4
|
+
interface UrlPattern {
|
|
5
|
+
includes: string[];
|
|
6
|
+
excludes: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Check if URL matches URL pattern with includes/excludes
|
|
10
|
+
* @param urlPattern - URL pattern object with includes and excludes arrays
|
|
11
|
+
* @param url - URL to check
|
|
12
|
+
* @returns True if URL matches pattern
|
|
13
|
+
*/
|
|
14
|
+
declare function matchUrlPattern(urlPattern: UrlPattern, url: string): boolean;
|
|
15
|
+
|
|
16
|
+
export { matchUrlPattern };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL pattern object interface
|
|
3
|
+
*/
|
|
4
|
+
interface UrlPattern {
|
|
5
|
+
includes: string[];
|
|
6
|
+
excludes: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Check if URL matches URL pattern with includes/excludes
|
|
10
|
+
* @param urlPattern - URL pattern object with includes and excludes arrays
|
|
11
|
+
* @param url - URL to check
|
|
12
|
+
* @returns True if URL matches pattern
|
|
13
|
+
*/
|
|
14
|
+
declare function matchUrlPattern(urlPattern: UrlPattern, url: string): boolean;
|
|
15
|
+
|
|
16
|
+
export { matchUrlPattern };
|