@remnawave/backend-contract 2.9.31 → 2.9.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/build/backend/commands/subscription-settings/get-subscription-settings.command.d.ts +3 -25
- package/build/backend/commands/subscription-settings/get-subscription-settings.command.d.ts.map +1 -1
- package/build/backend/commands/subscription-settings/update-subscription-settings.command.d.ts +6 -50
- package/build/backend/commands/subscription-settings/update-subscription-settings.command.d.ts.map +1 -1
- package/build/backend/commands/system/testers/test-srr-matcher.command.d.ts +5 -47
- package/build/backend/commands/system/testers/test-srr-matcher.command.d.ts.map +1 -1
- package/build/backend/constants/response-rules/response-rules.contants.d.ts +23 -3
- package/build/backend/constants/response-rules/response-rules.contants.d.ts.map +1 -1
- package/build/backend/constants/response-rules/response-rules.contants.js +22 -3
- package/build/backend/models/response-rules/index.d.ts +2 -0
- package/build/backend/models/response-rules/index.d.ts.map +1 -1
- package/build/backend/models/response-rules/index.js +2 -0
- package/build/backend/models/response-rules/response-rule-condition.schema.d.ts +40 -3
- package/build/backend/models/response-rules/response-rule-condition.schema.d.ts.map +1 -1
- package/build/backend/models/response-rules/response-rule-condition.schema.js +156 -6
- package/build/backend/models/response-rules/response-rule.schema.d.ts +4 -44
- package/build/backend/models/response-rules/response-rule.schema.d.ts.map +1 -1
- package/build/backend/models/response-rules/response-rule.schema.js +26 -10
- package/build/backend/models/response-rules/response-rules-config.schema.d.ts +3 -25
- package/build/backend/models/response-rules/response-rules-config.schema.d.ts.map +1 -1
- package/build/backend/models/response-rules/response-rules-config.schema.js +9 -4
- package/build/backend/models/response-rules/response-rules-examples.d.ts +2 -2
- package/build/backend/models/response-rules/response-rules-examples.d.ts.map +1 -1
- package/build/backend/models/response-rules/response-rules-examples.js +30 -22
- package/build/backend/models/response-rules/response-rules-legacy.schema.d.ts +157 -0
- package/build/backend/models/response-rules/response-rules-legacy.schema.d.ts.map +1 -0
- package/build/backend/models/response-rules/response-rules-legacy.schema.js +33 -0
- package/build/backend/models/response-rules/response-rules-migration.d.ts +10 -0
- package/build/backend/models/response-rules/response-rules-migration.d.ts.map +1 -0
- package/build/backend/models/response-rules/response-rules-migration.js +45 -0
- package/build/backend/models/subscription-settings.schema.d.ts +3 -25
- package/build/backend/models/subscription-settings.schema.d.ts.map +1 -1
- package/build/frontend/constants/response-rules/response-rules.contants.js +22 -3
- package/build/frontend/models/response-rules/index.js +2 -0
- package/build/frontend/models/response-rules/response-rule-condition.schema.js +156 -6
- package/build/frontend/models/response-rules/response-rule.schema.js +26 -10
- package/build/frontend/models/response-rules/response-rules-config.schema.js +9 -4
- package/build/frontend/models/response-rules/response-rules-examples.js +30 -22
- package/build/frontend/models/response-rules/response-rules-legacy.schema.js +33 -0
- package/build/frontend/models/response-rules/response-rules-migration.js +45 -0
- package/package.json +1 -1
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION = exports.RESPONSE_RULES_RESPONSE_TYPES_DESCRIPTION = exports.RESPONSE_RULES_CONDITION_OPERATORS_VALUES = exports.RESPONSE_RULES_RESPONSE_TYPES_VALUES = exports.RESPONSE_RULES_RESPONSE_TYPES = exports.RESPONSE_RULES_CONDITION_OPERATORS = exports.
|
|
3
|
+
exports.RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION = exports.RESPONSE_RULES_RESPONSE_TYPES_DESCRIPTION = exports.RESPONSE_RULES_CONDITION_OPERATORS_VALUES = exports.RESPONSE_RULES_RESPONSE_TYPES_VALUES = exports.RESPONSE_RULES_RESPONSE_TYPES = exports.RESPONSE_RULES_CONDITION_OPERATORS = exports.RESPONSE_RULES_GROUP_OPERATORS_DESCRIPTION = exports.RESPONSE_RULES_GROUP_OPERATORS_VALUES = exports.RESPONSE_RULES_GROUP_OPERATORS = exports.RESPONSE_RULES_OPERATORS = exports.RESPONSE_RULES_CONFIG_VERSION = void 0;
|
|
4
4
|
const subscription_template_1 = require("../subscription-template");
|
|
5
5
|
exports.RESPONSE_RULES_CONFIG_VERSION = {
|
|
6
6
|
1: '1',
|
|
7
|
+
2: '2',
|
|
7
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Version 1
|
|
11
|
+
*/
|
|
8
12
|
exports.RESPONSE_RULES_OPERATORS = {
|
|
9
13
|
AND: 'AND',
|
|
10
14
|
OR: 'OR',
|
|
11
15
|
};
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Version 2
|
|
18
|
+
*/
|
|
19
|
+
exports.RESPONSE_RULES_GROUP_OPERATORS = {
|
|
20
|
+
AND: 'AND',
|
|
21
|
+
OR: 'OR',
|
|
22
|
+
NOT: 'NOT',
|
|
23
|
+
};
|
|
24
|
+
exports.RESPONSE_RULES_GROUP_OPERATORS_VALUES = Object.values(exports.RESPONSE_RULES_GROUP_OPERATORS);
|
|
25
|
+
exports.RESPONSE_RULES_GROUP_OPERATORS_DESCRIPTION = {
|
|
26
|
+
[exports.RESPONSE_RULES_GROUP_OPERATORS.AND]: 'Matches only if **all** nested conditions match. `conditions.every()`',
|
|
27
|
+
[exports.RESPONSE_RULES_GROUP_OPERATORS.OR]: 'Matches if **at least one** nested condition matches. `conditions.some()`',
|
|
28
|
+
[exports.RESPONSE_RULES_GROUP_OPERATORS.NOT]: 'Inverts the result of the nested **condition**. `!condition`',
|
|
14
29
|
};
|
|
15
30
|
exports.RESPONSE_RULES_CONDITION_OPERATORS = {
|
|
16
31
|
EQUALS: 'EQUALS',
|
|
@@ -23,6 +38,8 @@ exports.RESPONSE_RULES_CONDITION_OPERATORS = {
|
|
|
23
38
|
NOT_ENDS_WITH: 'NOT_ENDS_WITH',
|
|
24
39
|
REGEX: 'REGEX',
|
|
25
40
|
NOT_REGEX: 'NOT_REGEX',
|
|
41
|
+
EXISTS: 'EXISTS',
|
|
42
|
+
NOT_EXISTS: 'NOT_EXISTS',
|
|
26
43
|
};
|
|
27
44
|
exports.RESPONSE_RULES_RESPONSE_TYPES = {
|
|
28
45
|
...subscription_template_1.SUBSCRIPTION_TEMPLATE_TYPE,
|
|
@@ -58,4 +75,6 @@ exports.RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION = {
|
|
|
58
75
|
[exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_ENDS_WITH]: 'Confirms the header value does not end with the specified string. `!string.endsWith()`',
|
|
59
76
|
[exports.RESPONSE_RULES_CONDITION_OPERATORS.REGEX]: 'Evaluates if the header value matches the specified regular expression pattern. `regex.test()`',
|
|
60
77
|
[exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_REGEX]: 'Evaluates if the header value does not match the specified regular expression pattern. `!regex.test()`',
|
|
78
|
+
[exports.RESPONSE_RULES_CONDITION_OPERATORS.EXISTS]: 'Checks that the header is present in the request, regardless of its value. `value` is not required. `string !== undefined`',
|
|
79
|
+
[exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_EXISTS]: 'Checks that the header is not present in the request. `value` is not required. `string === undefined`',
|
|
61
80
|
};
|
|
@@ -18,3 +18,5 @@ __exportStar(require("./response-rule-condition.schema"), exports);
|
|
|
18
18
|
__exportStar(require("./response-rule-modifications.schema"), exports);
|
|
19
19
|
__exportStar(require("./response-rule.schema"), exports);
|
|
20
20
|
__exportStar(require("./response-rules-config.schema"), exports);
|
|
21
|
+
__exportStar(require("./response-rules-legacy.schema"), exports);
|
|
22
|
+
__exportStar(require("./response-rules-migration"), exports);
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ResponseRuleConditionSchema = void 0;
|
|
3
|
+
exports.ResponseRuleConditionNodeSchema = exports.ResponseRuleConditionNotSchema = exports.ResponseRuleConditionGroupSchema = exports.ResponseRuleConditionSchema = exports.RESPONSE_RULES_MAX_CONDITION_NODES = exports.RESPONSE_RULES_MAX_CONDITION_DEPTH = void 0;
|
|
4
|
+
exports.forEachResponseRuleCondition = forEachResponseRuleCondition;
|
|
5
|
+
exports.measureResponseRuleConditionTree = measureResponseRuleConditionTree;
|
|
4
6
|
const zod_1 = require("zod");
|
|
5
7
|
const constants_1 = require("../../constants");
|
|
8
|
+
exports.RESPONSE_RULES_MAX_CONDITION_DEPTH = 10;
|
|
9
|
+
exports.RESPONSE_RULES_MAX_CONDITION_NODES = 100;
|
|
10
|
+
const OPERATORS_WITHOUT_VALUE = [
|
|
11
|
+
constants_1.RESPONSE_RULES_CONDITION_OPERATORS.EXISTS,
|
|
12
|
+
constants_1.RESPONSE_RULES_CONDITION_OPERATORS.NOT_EXISTS,
|
|
13
|
+
];
|
|
6
14
|
exports.ResponseRuleConditionSchema = zod_1.z
|
|
7
|
-
.
|
|
15
|
+
.strictObject({
|
|
8
16
|
headerName: zod_1.z
|
|
9
17
|
.string()
|
|
10
18
|
.regex(/^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$/, 'Invalid header name. Only letters(a-z, A-Z), numbers(0-9), underscores(_) and hyphens(-) are allowed.')
|
|
@@ -21,14 +29,27 @@ exports.ResponseRuleConditionSchema = zod_1.z
|
|
|
21
29
|
.string()
|
|
22
30
|
.min(1, 'Value is required')
|
|
23
31
|
.max(255, 'Value must be less than 255 characters')
|
|
32
|
+
.optional()
|
|
24
33
|
.meta({
|
|
25
|
-
markdownDescription: '**Value** to check against the **headerName**.',
|
|
34
|
+
markdownDescription: '**Value** to check against the **headerName**. Required for all operators except `EXISTS` and `NOT_EXISTS`.',
|
|
26
35
|
}),
|
|
27
|
-
caseSensitive: zod_1.z.boolean().meta({
|
|
28
|
-
|
|
36
|
+
caseSensitive: zod_1.z.boolean().optional().meta({
|
|
37
|
+
default: false,
|
|
38
|
+
markdownDescription: 'Whether the value is **case sensitive**. Optional, defaults to `false`. \n\n - `true`: the value will be compared as is. \n\n - `false`: the value will be lowercased **before** comparison.',
|
|
29
39
|
}),
|
|
40
|
+
})
|
|
41
|
+
.superRefine((condition, ctx) => {
|
|
42
|
+
if (condition.value === undefined &&
|
|
43
|
+
!OPERATORS_WITHOUT_VALUE.includes(condition.operator)) {
|
|
44
|
+
ctx.addIssue({
|
|
45
|
+
code: 'custom',
|
|
46
|
+
path: ['value'],
|
|
47
|
+
message: `Value is required for operator "${condition.operator}".`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
30
50
|
})
|
|
31
51
|
.meta({
|
|
52
|
+
title: 'Condition',
|
|
32
53
|
markdownDescription: 'Condition to check against the **headerName**.',
|
|
33
54
|
defaultSnippets: [
|
|
34
55
|
{
|
|
@@ -38,8 +59,137 @@ exports.ResponseRuleConditionSchema = zod_1.z
|
|
|
38
59
|
headerName: 'accept',
|
|
39
60
|
operator: 'CONTAINS',
|
|
40
61
|
value: 'text/html',
|
|
41
|
-
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
label: 'Examples: Check if header exists',
|
|
66
|
+
markdownDescription: 'Condition to check if **headerName** is present in the request',
|
|
67
|
+
body: {
|
|
68
|
+
headerName: 'x-hwid',
|
|
69
|
+
operator: 'EXISTS',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
exports.ResponseRuleConditionGroupSchema = zod_1.z
|
|
75
|
+
.strictObject({
|
|
76
|
+
operator: zod_1.z
|
|
77
|
+
.enum([constants_1.RESPONSE_RULES_GROUP_OPERATORS.AND, constants_1.RESPONSE_RULES_GROUP_OPERATORS.OR])
|
|
78
|
+
.meta({
|
|
79
|
+
markdownDescription: 'Logical operator to use for combining nested **conditions**.',
|
|
80
|
+
markdownEnumDescriptions: [
|
|
81
|
+
constants_1.RESPONSE_RULES_GROUP_OPERATORS_DESCRIPTION.AND,
|
|
82
|
+
constants_1.RESPONSE_RULES_GROUP_OPERATORS_DESCRIPTION.OR,
|
|
83
|
+
],
|
|
84
|
+
}),
|
|
85
|
+
get conditions() {
|
|
86
|
+
return zod_1.z
|
|
87
|
+
.array(exports.ResponseRuleConditionNodeSchema)
|
|
88
|
+
.min(1, 'Group must contain at least one condition')
|
|
89
|
+
.meta({
|
|
90
|
+
title: 'Conditions',
|
|
91
|
+
markdownDescription: 'Array of nested conditions. Each item is either a **condition** or another **group** (`AND`/`OR`/`NOT`), so groups can be nested to express complex logic.',
|
|
92
|
+
});
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
.meta({
|
|
96
|
+
title: 'Condition Group',
|
|
97
|
+
markdownDescription: 'Group of nested conditions combined with a logical **operator** (`AND`/`OR`). Groups can be nested inside each other.',
|
|
98
|
+
defaultSnippets: [
|
|
99
|
+
{
|
|
100
|
+
label: 'Examples: OR group',
|
|
101
|
+
markdownDescription: 'Group that matches if **at least one** nested condition matches',
|
|
102
|
+
body: {
|
|
103
|
+
operator: 'OR',
|
|
104
|
+
conditions: [
|
|
105
|
+
{
|
|
106
|
+
headerName: 'user-agent',
|
|
107
|
+
operator: 'CONTAINS',
|
|
108
|
+
value: 'Hiddify',
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
headerName: 'user-agent',
|
|
112
|
+
operator: 'CONTAINS',
|
|
113
|
+
value: 'FoxRay',
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
exports.ResponseRuleConditionNotSchema = zod_1.z
|
|
121
|
+
.strictObject({
|
|
122
|
+
operator: zod_1.z.literal(constants_1.RESPONSE_RULES_GROUP_OPERATORS.NOT).meta({
|
|
123
|
+
markdownDescription: constants_1.RESPONSE_RULES_GROUP_OPERATORS_DESCRIPTION.NOT,
|
|
124
|
+
}),
|
|
125
|
+
get condition() {
|
|
126
|
+
return exports.ResponseRuleConditionNodeSchema.meta({
|
|
127
|
+
title: 'Condition',
|
|
128
|
+
markdownDescription: 'Nested condition to invert. Can be a **condition** or a **group**.',
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
.meta({
|
|
133
|
+
title: 'NOT Group',
|
|
134
|
+
markdownDescription: 'Inverts the result of the nested **condition**. The nested condition can be a single condition or a whole group.',
|
|
135
|
+
defaultSnippets: [
|
|
136
|
+
{
|
|
137
|
+
label: 'Examples: NOT group',
|
|
138
|
+
markdownDescription: 'Matches if the nested condition does **not** match',
|
|
139
|
+
body: {
|
|
140
|
+
operator: 'NOT',
|
|
141
|
+
condition: {
|
|
142
|
+
headerName: 'user-agent',
|
|
143
|
+
operator: 'CONTAINS',
|
|
144
|
+
value: 'Happ',
|
|
145
|
+
},
|
|
42
146
|
},
|
|
43
147
|
},
|
|
44
148
|
],
|
|
45
149
|
});
|
|
150
|
+
exports.ResponseRuleConditionNodeSchema = zod_1.z
|
|
151
|
+
.lazy(() => zod_1.z.discriminatedUnion('operator', [
|
|
152
|
+
exports.ResponseRuleConditionSchema,
|
|
153
|
+
exports.ResponseRuleConditionGroupSchema,
|
|
154
|
+
exports.ResponseRuleConditionNotSchema,
|
|
155
|
+
]))
|
|
156
|
+
.meta({
|
|
157
|
+
title: 'Condition Node',
|
|
158
|
+
markdownDescription: 'Either a single **condition** (header check) or a **group** (`AND`/`OR`/`NOT`) with nested conditions. Groups can be nested to express complex logic, e.g. `A AND (B OR C)`.',
|
|
159
|
+
});
|
|
160
|
+
function forEachResponseRuleCondition(node, callback) {
|
|
161
|
+
switch (node.operator) {
|
|
162
|
+
case constants_1.RESPONSE_RULES_GROUP_OPERATORS.AND:
|
|
163
|
+
case constants_1.RESPONSE_RULES_GROUP_OPERATORS.OR:
|
|
164
|
+
for (const child of node.conditions) {
|
|
165
|
+
forEachResponseRuleCondition(child, callback);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
case constants_1.RESPONSE_RULES_GROUP_OPERATORS.NOT:
|
|
169
|
+
forEachResponseRuleCondition(node.condition, callback);
|
|
170
|
+
return;
|
|
171
|
+
default:
|
|
172
|
+
callback(node);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function measureResponseRuleConditionTree(node) {
|
|
176
|
+
switch (node.operator) {
|
|
177
|
+
case constants_1.RESPONSE_RULES_GROUP_OPERATORS.AND:
|
|
178
|
+
case constants_1.RESPONSE_RULES_GROUP_OPERATORS.OR: {
|
|
179
|
+
let depth = 0;
|
|
180
|
+
let nodes = 1;
|
|
181
|
+
for (const child of node.conditions) {
|
|
182
|
+
const childMetrics = measureResponseRuleConditionTree(child);
|
|
183
|
+
depth = Math.max(depth, childMetrics.depth);
|
|
184
|
+
nodes += childMetrics.nodes;
|
|
185
|
+
}
|
|
186
|
+
return { depth: depth + 1, nodes };
|
|
187
|
+
}
|
|
188
|
+
case constants_1.RESPONSE_RULES_GROUP_OPERATORS.NOT: {
|
|
189
|
+
const childMetrics = measureResponseRuleConditionTree(node.condition);
|
|
190
|
+
return { depth: childMetrics.depth + 1, nodes: childMetrics.nodes + 1 };
|
|
191
|
+
}
|
|
192
|
+
default:
|
|
193
|
+
return { depth: 1, nodes: 1 };
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -6,7 +6,7 @@ const constants_1 = require("../../constants");
|
|
|
6
6
|
const response_rule_condition_schema_1 = require("./response-rule-condition.schema");
|
|
7
7
|
const response_rule_modifications_schema_1 = require("./response-rule-modifications.schema");
|
|
8
8
|
const response_rules_examples_1 = require("./response-rules-examples");
|
|
9
|
-
exports.ResponseRuleSchemaBase = zod_1.z.
|
|
9
|
+
exports.ResponseRuleSchemaBase = zod_1.z.strictObject({
|
|
10
10
|
name: zod_1.z
|
|
11
11
|
.string()
|
|
12
12
|
.min(1, 'Name is required')
|
|
@@ -28,12 +28,28 @@ exports.ResponseRuleSchemaBase = zod_1.z.object({
|
|
|
28
28
|
title: 'Enabled',
|
|
29
29
|
markdownDescription: 'Control whether the response rule is enabled or disabled. \n\n - `true` the rule will be applied. \n\n - `false` the rule will be always ignored.',
|
|
30
30
|
}),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
when: response_rule_condition_schema_1.ResponseRuleConditionNodeSchema.optional()
|
|
32
|
+
.superRefine((node, ctx) => {
|
|
33
|
+
if (!node) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const { depth, nodes } = (0, response_rule_condition_schema_1.measureResponseRuleConditionTree)(node);
|
|
37
|
+
if (depth > response_rule_condition_schema_1.RESPONSE_RULES_MAX_CONDITION_DEPTH) {
|
|
38
|
+
ctx.addIssue({
|
|
39
|
+
code: 'custom',
|
|
40
|
+
message: `Condition tree is too deep. Maximum depth is ${response_rule_condition_schema_1.RESPONSE_RULES_MAX_CONDITION_DEPTH}.`,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (nodes > response_rule_condition_schema_1.RESPONSE_RULES_MAX_CONDITION_NODES) {
|
|
44
|
+
ctx.addIssue({
|
|
45
|
+
code: 'custom',
|
|
46
|
+
message: `Condition tree is too big. Maximum number of nodes is ${response_rule_condition_schema_1.RESPONSE_RULES_MAX_CONDITION_NODES}.`,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
.meta({
|
|
51
|
+
title: 'When',
|
|
52
|
+
markdownDescription: 'Condition tree to check against the request headers. The root is either a single **condition** or a **group** (`AND`/`OR`/`NOT`) with nested conditions — groups can be nested to express complex logic, e.g. `A AND (B OR C)`. If **when** is omitted, the rule will always be matched.',
|
|
37
53
|
}),
|
|
38
54
|
responseType: zod_1.z.enum(constants_1.RESPONSE_RULES_RESPONSE_TYPES).meta({
|
|
39
55
|
errorMessage: 'Invalid response type. Please select a valid response type.',
|
|
@@ -54,10 +70,10 @@ exports.ResponseRuleSchema = exports.ResponseRuleSchemaBase.meta({
|
|
|
54
70
|
},
|
|
55
71
|
},
|
|
56
72
|
{
|
|
57
|
-
label: 'Examples:
|
|
58
|
-
markdownDescription: `Block requests from legacy clients
|
|
73
|
+
label: 'Examples: Nested conditions (AND with OR inside)',
|
|
74
|
+
markdownDescription: `Block browser requests from legacy clients using nested conditions: \`accept AND (user-agent OR user-agent)\`\n\`\`\`json\n${JSON.stringify(response_rules_examples_1.EXAMPLES_SRR_NESTED_CONDITIONS_RULE, null, 2)}\n\`\`\``,
|
|
59
75
|
body: {
|
|
60
|
-
...response_rules_examples_1.
|
|
76
|
+
...response_rules_examples_1.EXAMPLES_SRR_NESTED_CONDITIONS_RULE,
|
|
61
77
|
},
|
|
62
78
|
},
|
|
63
79
|
],
|
|
@@ -6,15 +6,20 @@ const constants_1 = require("../../constants");
|
|
|
6
6
|
const response_rule_settings_schema_1 = require("./response-rule-settings.schema");
|
|
7
7
|
const response_rule_schema_1 = require("./response-rule.schema");
|
|
8
8
|
const response_rules_examples_1 = require("./response-rules-examples");
|
|
9
|
-
exports.ResponseRulesConfigSchema = zod_1.z
|
|
10
|
-
|
|
9
|
+
exports.ResponseRulesConfigSchema = zod_1.z
|
|
10
|
+
.object({
|
|
11
|
+
version: zod_1.z.literal(constants_1.RESPONSE_RULES_CONFIG_VERSION[2]).meta({
|
|
11
12
|
title: 'Response Rules Config Version',
|
|
12
|
-
markdownDescription: 'Version of the **response rules** config. Currently supported version is **1
|
|
13
|
+
markdownDescription: 'Version of the **response rules** config. Currently supported version is **2**. Legacy version **1** configs can be migrated with `migrateResponseRulesConfig`.',
|
|
13
14
|
}),
|
|
14
15
|
settings: response_rule_settings_schema_1.ResponseRuleSettingsSchema,
|
|
15
16
|
rules: zod_1.z.array(response_rule_schema_1.ResponseRuleSchema).meta({
|
|
16
17
|
title: 'Response Rules',
|
|
17
|
-
markdownDescription: `Array of **response rules**. Rules are evaluated in order and the first rule that matches is applied. If no rule matches, request will be blocked by default.\n\n**Example:**\n\`\`\`json\n${JSON.stringify([response_rules_examples_1.
|
|
18
|
+
markdownDescription: `Array of **response rules**. Rules are evaluated in order and the first rule that matches is applied. If no rule matches, request will be blocked by default.\n\n**Example:**\n\`\`\`json\n${JSON.stringify([response_rules_examples_1.EXAMPLES_SRR_NESTED_CONDITIONS_RULE], null, 2)}\n\`\`\``,
|
|
18
19
|
defaultSnippets: [],
|
|
19
20
|
}),
|
|
21
|
+
})
|
|
22
|
+
.meta({
|
|
23
|
+
title: 'Response Rules Config',
|
|
24
|
+
markdownDescription: 'Configuration of the **response rules**.',
|
|
20
25
|
});
|
|
@@ -1,38 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.EXAMPLES_SRR_NESTED_CONDITIONS_RULE = exports.EXAMPLES_SRR_BLANK_RULE = void 0;
|
|
4
4
|
exports.generateResponseRuleDescription = generateResponseRuleDescription;
|
|
5
5
|
const constants_1 = require("../../constants");
|
|
6
6
|
exports.EXAMPLES_SRR_BLANK_RULE = {
|
|
7
7
|
name: 'Blank rule',
|
|
8
8
|
description: 'Blank rule',
|
|
9
|
-
operator: 'AND',
|
|
10
9
|
enabled: true,
|
|
11
|
-
conditions: [],
|
|
12
10
|
responseType: 'BLOCK',
|
|
13
11
|
responseModifications: {
|
|
14
12
|
headers: [],
|
|
15
13
|
},
|
|
16
14
|
};
|
|
17
|
-
exports.
|
|
18
|
-
name: 'Block Legacy
|
|
19
|
-
description: 'Block requests from legacy clients',
|
|
15
|
+
exports.EXAMPLES_SRR_NESTED_CONDITIONS_RULE = {
|
|
16
|
+
name: 'Block Legacy Browsers',
|
|
17
|
+
description: 'Block browser requests from legacy clients',
|
|
20
18
|
enabled: true,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
19
|
+
when: {
|
|
20
|
+
operator: constants_1.RESPONSE_RULES_GROUP_OPERATORS.AND,
|
|
21
|
+
conditions: [
|
|
22
|
+
{
|
|
23
|
+
headerName: 'accept',
|
|
24
|
+
operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
|
|
25
|
+
value: 'text/html',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
operator: constants_1.RESPONSE_RULES_GROUP_OPERATORS.OR,
|
|
29
|
+
conditions: [
|
|
30
|
+
{
|
|
31
|
+
headerName: 'user-agent',
|
|
32
|
+
operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
|
|
33
|
+
value: 'Hiddify',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
headerName: 'user-agent',
|
|
37
|
+
operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
|
|
38
|
+
value: 'FoxRay',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
36
44
|
responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
|
|
37
45
|
};
|
|
38
46
|
function generateResponseRuleDescription(schema) {
|
|
@@ -46,5 +54,5 @@ function generateResponseRuleDescription(schema) {
|
|
|
46
54
|
const fieldsText = fields
|
|
47
55
|
.map((field) => `- **${field.name}**: ${field.description}`)
|
|
48
56
|
.join('\n');
|
|
49
|
-
return `Response rule configuration.\n\n**Fields:**\n${fieldsText}\n\n**Example:**\n\`\`\`json\n${JSON.stringify(exports.
|
|
57
|
+
return `Response rule configuration.\n\n**Fields:**\n${fieldsText}\n\n**Example:**\n\`\`\`json\n${JSON.stringify(exports.EXAMPLES_SRR_NESTED_CONDITIONS_RULE, null, 2)}\n\`\`\``;
|
|
50
58
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResponseRulesLegacyConfigSchema = exports.ResponseRuleLegacySchema = exports.ResponseRuleLegacyConditionSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const response_rule_modifications_schema_1 = require("./response-rule-modifications.schema");
|
|
7
|
+
const response_rule_settings_schema_1 = require("./response-rule-settings.schema");
|
|
8
|
+
/**
|
|
9
|
+
* Frozen legacy (version 1) response rules config.
|
|
10
|
+
*
|
|
11
|
+
* Kept only to accept old configs and migrate them to version 2
|
|
12
|
+
* via `migrateResponseRulesConfig`. Do not extend.
|
|
13
|
+
*/
|
|
14
|
+
exports.ResponseRuleLegacyConditionSchema = zod_1.z.object({
|
|
15
|
+
headerName: zod_1.z.string(),
|
|
16
|
+
operator: zod_1.z.enum(constants_1.RESPONSE_RULES_CONDITION_OPERATORS),
|
|
17
|
+
value: zod_1.z.string(),
|
|
18
|
+
caseSensitive: zod_1.z.boolean(),
|
|
19
|
+
});
|
|
20
|
+
exports.ResponseRuleLegacySchema = zod_1.z.object({
|
|
21
|
+
name: zod_1.z.string(),
|
|
22
|
+
description: zod_1.z.string().optional(),
|
|
23
|
+
enabled: zod_1.z.boolean(),
|
|
24
|
+
operator: zod_1.z.enum(constants_1.RESPONSE_RULES_OPERATORS),
|
|
25
|
+
conditions: zod_1.z.array(exports.ResponseRuleLegacyConditionSchema),
|
|
26
|
+
responseType: zod_1.z.enum(constants_1.RESPONSE_RULES_RESPONSE_TYPES),
|
|
27
|
+
responseModifications: response_rule_modifications_schema_1.ResponseRuleModificationsSchema,
|
|
28
|
+
});
|
|
29
|
+
exports.ResponseRulesLegacyConfigSchema = zod_1.z.object({
|
|
30
|
+
version: zod_1.z.literal(constants_1.RESPONSE_RULES_CONFIG_VERSION[1]),
|
|
31
|
+
settings: response_rule_settings_schema_1.ResponseRuleSettingsSchema,
|
|
32
|
+
rules: zod_1.z.array(exports.ResponseRuleLegacySchema),
|
|
33
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.migrateResponseRulesConfig = migrateResponseRulesConfig;
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
/**
|
|
6
|
+
* Migrates a legacy (version 1) response rules config to version 2.
|
|
7
|
+
*/
|
|
8
|
+
function migrateResponseRulesConfig(config) {
|
|
9
|
+
if (config.version === constants_1.RESPONSE_RULES_CONFIG_VERSION[2]) {
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
version: constants_1.RESPONSE_RULES_CONFIG_VERSION[2],
|
|
14
|
+
...(config.settings !== undefined && { settings: config.settings }),
|
|
15
|
+
rules: config.rules.map(migrateLegacyResponseRule),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function migrateLegacyResponseRule(rule) {
|
|
19
|
+
const { operator, conditions, ...rest } = rule;
|
|
20
|
+
const when = migrateLegacyConditions(operator, conditions);
|
|
21
|
+
return {
|
|
22
|
+
...rest,
|
|
23
|
+
...(when !== undefined && { when }),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function migrateLegacyConditions(operator, conditions) {
|
|
27
|
+
if (conditions.length === 0) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
if (conditions.length === 1) {
|
|
31
|
+
return migrateLegacyCondition(conditions[0]);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
operator,
|
|
35
|
+
conditions: conditions.map(migrateLegacyCondition),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function migrateLegacyCondition(condition) {
|
|
39
|
+
return {
|
|
40
|
+
headerName: condition.headerName,
|
|
41
|
+
operator: condition.operator,
|
|
42
|
+
value: condition.value,
|
|
43
|
+
...(condition.caseSensitive && { caseSensitive: true }),
|
|
44
|
+
};
|
|
45
|
+
}
|
package/package.json
CHANGED