@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.
Files changed (41) hide show
  1. package/build/backend/commands/subscription-settings/get-subscription-settings.command.d.ts +3 -25
  2. package/build/backend/commands/subscription-settings/get-subscription-settings.command.d.ts.map +1 -1
  3. package/build/backend/commands/subscription-settings/update-subscription-settings.command.d.ts +6 -50
  4. package/build/backend/commands/subscription-settings/update-subscription-settings.command.d.ts.map +1 -1
  5. package/build/backend/commands/system/testers/test-srr-matcher.command.d.ts +5 -47
  6. package/build/backend/commands/system/testers/test-srr-matcher.command.d.ts.map +1 -1
  7. package/build/backend/constants/response-rules/response-rules.contants.d.ts +23 -3
  8. package/build/backend/constants/response-rules/response-rules.contants.d.ts.map +1 -1
  9. package/build/backend/constants/response-rules/response-rules.contants.js +22 -3
  10. package/build/backend/models/response-rules/index.d.ts +2 -0
  11. package/build/backend/models/response-rules/index.d.ts.map +1 -1
  12. package/build/backend/models/response-rules/index.js +2 -0
  13. package/build/backend/models/response-rules/response-rule-condition.schema.d.ts +40 -3
  14. package/build/backend/models/response-rules/response-rule-condition.schema.d.ts.map +1 -1
  15. package/build/backend/models/response-rules/response-rule-condition.schema.js +156 -6
  16. package/build/backend/models/response-rules/response-rule.schema.d.ts +4 -44
  17. package/build/backend/models/response-rules/response-rule.schema.d.ts.map +1 -1
  18. package/build/backend/models/response-rules/response-rule.schema.js +26 -10
  19. package/build/backend/models/response-rules/response-rules-config.schema.d.ts +3 -25
  20. package/build/backend/models/response-rules/response-rules-config.schema.d.ts.map +1 -1
  21. package/build/backend/models/response-rules/response-rules-config.schema.js +9 -4
  22. package/build/backend/models/response-rules/response-rules-examples.d.ts +2 -2
  23. package/build/backend/models/response-rules/response-rules-examples.d.ts.map +1 -1
  24. package/build/backend/models/response-rules/response-rules-examples.js +30 -22
  25. package/build/backend/models/response-rules/response-rules-legacy.schema.d.ts +157 -0
  26. package/build/backend/models/response-rules/response-rules-legacy.schema.d.ts.map +1 -0
  27. package/build/backend/models/response-rules/response-rules-legacy.schema.js +33 -0
  28. package/build/backend/models/response-rules/response-rules-migration.d.ts +10 -0
  29. package/build/backend/models/response-rules/response-rules-migration.d.ts.map +1 -0
  30. package/build/backend/models/response-rules/response-rules-migration.js +45 -0
  31. package/build/backend/models/subscription-settings.schema.d.ts +3 -25
  32. package/build/backend/models/subscription-settings.schema.d.ts.map +1 -1
  33. package/build/frontend/constants/response-rules/response-rules.contants.js +22 -3
  34. package/build/frontend/models/response-rules/index.js +2 -0
  35. package/build/frontend/models/response-rules/response-rule-condition.schema.js +156 -6
  36. package/build/frontend/models/response-rules/response-rule.schema.js +26 -10
  37. package/build/frontend/models/response-rules/response-rules-config.schema.js +9 -4
  38. package/build/frontend/models/response-rules/response-rules-examples.js +30 -22
  39. package/build/frontend/models/response-rules/response-rules-legacy.schema.js +33 -0
  40. package/build/frontend/models/response-rules/response-rules-migration.js +45 -0
  41. package/package.json +1 -1
@@ -3,27 +3,7 @@ export declare const ResponseRuleSchemaBase: z.ZodObject<{
3
3
  name: z.ZodString;
4
4
  description: z.ZodOptional<z.ZodString>;
5
5
  enabled: z.ZodBoolean;
6
- operator: z.ZodEnum<{
7
- readonly AND: "AND";
8
- readonly OR: "OR";
9
- }>;
10
- conditions: z.ZodArray<z.ZodObject<{
11
- headerName: z.ZodString;
12
- operator: z.ZodEnum<{
13
- readonly EQUALS: "EQUALS";
14
- readonly NOT_EQUALS: "NOT_EQUALS";
15
- readonly CONTAINS: "CONTAINS";
16
- readonly NOT_CONTAINS: "NOT_CONTAINS";
17
- readonly STARTS_WITH: "STARTS_WITH";
18
- readonly NOT_STARTS_WITH: "NOT_STARTS_WITH";
19
- readonly ENDS_WITH: "ENDS_WITH";
20
- readonly NOT_ENDS_WITH: "NOT_ENDS_WITH";
21
- readonly REGEX: "REGEX";
22
- readonly NOT_REGEX: "NOT_REGEX";
23
- }>;
24
- value: z.ZodString;
25
- caseSensitive: z.ZodBoolean;
26
- }, z.core.$strip>>;
6
+ when: z.ZodOptional<z.ZodType<import("./response-rule-condition.schema").TResponseRuleConditionNode, unknown, z.core.$ZodTypeInternals<import("./response-rule-condition.schema").TResponseRuleConditionNode, unknown>>>;
27
7
  responseType: z.ZodEnum<{
28
8
  readonly BROWSER: "BROWSER";
29
9
  readonly BLOCK: "BLOCK";
@@ -57,32 +37,12 @@ export declare const ResponseRuleSchemaBase: z.ZodObject<{
57
37
  }, z.core.$strip>>;
58
38
  excludeHostsByTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
59
39
  }, z.core.$strip>>;
60
- }, z.core.$strip>;
40
+ }, z.core.$strict>;
61
41
  export declare const ResponseRuleSchema: z.ZodObject<{
62
42
  name: z.ZodString;
63
43
  description: z.ZodOptional<z.ZodString>;
64
44
  enabled: z.ZodBoolean;
65
- operator: z.ZodEnum<{
66
- readonly AND: "AND";
67
- readonly OR: "OR";
68
- }>;
69
- conditions: z.ZodArray<z.ZodObject<{
70
- headerName: z.ZodString;
71
- operator: z.ZodEnum<{
72
- readonly EQUALS: "EQUALS";
73
- readonly NOT_EQUALS: "NOT_EQUALS";
74
- readonly CONTAINS: "CONTAINS";
75
- readonly NOT_CONTAINS: "NOT_CONTAINS";
76
- readonly STARTS_WITH: "STARTS_WITH";
77
- readonly NOT_STARTS_WITH: "NOT_STARTS_WITH";
78
- readonly ENDS_WITH: "ENDS_WITH";
79
- readonly NOT_ENDS_WITH: "NOT_ENDS_WITH";
80
- readonly REGEX: "REGEX";
81
- readonly NOT_REGEX: "NOT_REGEX";
82
- }>;
83
- value: z.ZodString;
84
- caseSensitive: z.ZodBoolean;
85
- }, z.core.$strip>>;
45
+ when: z.ZodOptional<z.ZodType<import("./response-rule-condition.schema").TResponseRuleConditionNode, unknown, z.core.$ZodTypeInternals<import("./response-rule-condition.schema").TResponseRuleConditionNode, unknown>>>;
86
46
  responseType: z.ZodEnum<{
87
47
  readonly BROWSER: "BROWSER";
88
48
  readonly BLOCK: "BLOCK";
@@ -116,5 +76,5 @@ export declare const ResponseRuleSchema: z.ZodObject<{
116
76
  }, z.core.$strip>>;
117
77
  excludeHostsByTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
118
78
  }, z.core.$strip>>;
119
- }, z.core.$strip>;
79
+ }, z.core.$strict>;
120
80
  //# sourceMappingURL=response-rule.schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response-rule.schema.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rule.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAexB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuCjC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmB7B,CAAC"}
1
+ {"version":3,"file":"response-rule.schema.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rule.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAmBxB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA0DjC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAmB7B,CAAC"}
@@ -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.object({
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
- operator: zod_1.z.enum(constants_1.RESPONSE_RULES_OPERATORS).meta({
32
- markdownDescription: 'Operator to use for combining conditions in the rule.',
33
- }),
34
- conditions: zod_1.z.array(response_rule_condition_schema_1.ResponseRuleConditionSchema).meta({
35
- title: 'Conditions',
36
- markdownDescription: 'Array of conditions to check against the request headers. Conditions are applied with **operator**. If conditions are empty, the rule will be matched.',
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: Block Legacy Clients',
58
- markdownDescription: `Block requests from legacy clients\n\`\`\`json\n${JSON.stringify(response_rules_examples_1.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE, null, 2)}\n\`\`\``,
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.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE,
76
+ ...response_rules_examples_1.EXAMPLES_SRR_NESTED_CONDITIONS_RULE,
61
77
  },
62
78
  },
63
79
  ],
@@ -1,8 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  export declare const ResponseRulesConfigSchema: z.ZodObject<{
3
- version: z.ZodEnum<{
4
- readonly 1: "1";
5
- }>;
3
+ version: z.ZodLiteral<"2">;
6
4
  settings: z.ZodOptional<z.ZodObject<{
7
5
  disableSubscriptionAccessByPath: z.ZodOptional<z.ZodBoolean>;
8
6
  }, z.core.$strip>>;
@@ -10,27 +8,7 @@ export declare const ResponseRulesConfigSchema: z.ZodObject<{
10
8
  name: z.ZodString;
11
9
  description: z.ZodOptional<z.ZodString>;
12
10
  enabled: z.ZodBoolean;
13
- operator: z.ZodEnum<{
14
- readonly AND: "AND";
15
- readonly OR: "OR";
16
- }>;
17
- conditions: z.ZodArray<z.ZodObject<{
18
- headerName: z.ZodString;
19
- operator: z.ZodEnum<{
20
- readonly EQUALS: "EQUALS";
21
- readonly NOT_EQUALS: "NOT_EQUALS";
22
- readonly CONTAINS: "CONTAINS";
23
- readonly NOT_CONTAINS: "NOT_CONTAINS";
24
- readonly STARTS_WITH: "STARTS_WITH";
25
- readonly NOT_STARTS_WITH: "NOT_STARTS_WITH";
26
- readonly ENDS_WITH: "ENDS_WITH";
27
- readonly NOT_ENDS_WITH: "NOT_ENDS_WITH";
28
- readonly REGEX: "REGEX";
29
- readonly NOT_REGEX: "NOT_REGEX";
30
- }>;
31
- value: z.ZodString;
32
- caseSensitive: z.ZodBoolean;
33
- }, z.core.$strip>>;
11
+ when: z.ZodOptional<z.ZodType<import("./response-rule-condition.schema").TResponseRuleConditionNode, unknown, z.core.$ZodTypeInternals<import("./response-rule-condition.schema").TResponseRuleConditionNode, unknown>>>;
34
12
  responseType: z.ZodEnum<{
35
13
  readonly BROWSER: "BROWSER";
36
14
  readonly BLOCK: "BLOCK";
@@ -64,6 +42,6 @@ export declare const ResponseRulesConfigSchema: z.ZodObject<{
64
42
  }, z.core.$strip>>;
65
43
  excludeHostsByTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
66
44
  }, z.core.$strip>>;
67
- }, z.core.$strip>>;
45
+ }, z.core.$strict>>;
68
46
  }, z.core.$strip>;
69
47
  //# sourceMappingURL=response-rules-config.schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response-rules-config.schema.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rules-config.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAYpC,CAAC"}
1
+ {"version":3,"file":"response-rules-config.schema.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rules-config.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiBhC,CAAC"}
@@ -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.object({
10
- version: zod_1.z.enum(constants_1.RESPONSE_RULES_CONFIG_VERSION).meta({
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.EXAMPLES_SRR_BLANK_RULE], null, 2)}\n\`\`\``,
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,6 +1,6 @@
1
- import z from 'zod';
2
1
  import type { ResponseRuleSchemaBase } from './response-rule.schema';
2
+ import z from 'zod';
3
3
  export declare const EXAMPLES_SRR_BLANK_RULE: z.infer<typeof ResponseRuleSchemaBase>;
4
- export declare const EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE: z.infer<typeof ResponseRuleSchemaBase>;
4
+ export declare const EXAMPLES_SRR_NESTED_CONDITIONS_RULE: z.infer<typeof ResponseRuleSchemaBase>;
5
5
  export declare function generateResponseRuleDescription(schema: typeof ResponseRuleSchemaBase): string;
6
6
  //# sourceMappingURL=response-rules-examples.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response-rules-examples.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rules-examples.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAOpB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAErE,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAU1E,CAAC;AAEF,eAAO,MAAM,sCAAsC,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAoBzF,CAAC;AAEF,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,OAAO,sBAAsB,UAcpF"}
1
+ {"version":3,"file":"response-rules-examples.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rules-examples.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,CAAC,MAAM,KAAK,CAAC;AAQpB,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAQ1E,CAAC;AAEF,eAAO,MAAM,mCAAmC,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CA8BtF,CAAC;AAEF,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,OAAO,sBAAsB,UAcpF"}
@@ -1,38 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE = exports.EXAMPLES_SRR_BLANK_RULE = void 0;
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.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE = {
18
- name: 'Block Legacy Clients',
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
- operator: constants_1.RESPONSE_RULES_OPERATORS.OR,
22
- conditions: [
23
- {
24
- headerName: 'user-agent',
25
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
26
- value: 'Hiddify',
27
- caseSensitive: true,
28
- },
29
- {
30
- headerName: 'user-agent',
31
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
32
- value: 'FoxRay',
33
- caseSensitive: true,
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.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE, null, 2)}\n\`\`\``;
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,157 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * Frozen legacy (version 1) response rules config.
4
+ *
5
+ * Kept only to accept old configs and migrate them to version 2
6
+ * via `migrateResponseRulesConfig`. Do not extend.
7
+ */
8
+ export declare const ResponseRuleLegacyConditionSchema: z.ZodObject<{
9
+ headerName: z.ZodString;
10
+ operator: z.ZodEnum<{
11
+ readonly EQUALS: "EQUALS";
12
+ readonly NOT_EQUALS: "NOT_EQUALS";
13
+ readonly CONTAINS: "CONTAINS";
14
+ readonly NOT_CONTAINS: "NOT_CONTAINS";
15
+ readonly STARTS_WITH: "STARTS_WITH";
16
+ readonly NOT_STARTS_WITH: "NOT_STARTS_WITH";
17
+ readonly ENDS_WITH: "ENDS_WITH";
18
+ readonly NOT_ENDS_WITH: "NOT_ENDS_WITH";
19
+ readonly REGEX: "REGEX";
20
+ readonly NOT_REGEX: "NOT_REGEX";
21
+ readonly EXISTS: "EXISTS";
22
+ readonly NOT_EXISTS: "NOT_EXISTS";
23
+ }>;
24
+ value: z.ZodString;
25
+ caseSensitive: z.ZodBoolean;
26
+ }, z.core.$strip>;
27
+ export declare const ResponseRuleLegacySchema: z.ZodObject<{
28
+ name: z.ZodString;
29
+ description: z.ZodOptional<z.ZodString>;
30
+ enabled: z.ZodBoolean;
31
+ operator: z.ZodEnum<{
32
+ readonly AND: "AND";
33
+ readonly OR: "OR";
34
+ }>;
35
+ conditions: z.ZodArray<z.ZodObject<{
36
+ headerName: z.ZodString;
37
+ operator: z.ZodEnum<{
38
+ readonly EQUALS: "EQUALS";
39
+ readonly NOT_EQUALS: "NOT_EQUALS";
40
+ readonly CONTAINS: "CONTAINS";
41
+ readonly NOT_CONTAINS: "NOT_CONTAINS";
42
+ readonly STARTS_WITH: "STARTS_WITH";
43
+ readonly NOT_STARTS_WITH: "NOT_STARTS_WITH";
44
+ readonly ENDS_WITH: "ENDS_WITH";
45
+ readonly NOT_ENDS_WITH: "NOT_ENDS_WITH";
46
+ readonly REGEX: "REGEX";
47
+ readonly NOT_REGEX: "NOT_REGEX";
48
+ readonly EXISTS: "EXISTS";
49
+ readonly NOT_EXISTS: "NOT_EXISTS";
50
+ }>;
51
+ value: z.ZodString;
52
+ caseSensitive: z.ZodBoolean;
53
+ }, z.core.$strip>>;
54
+ responseType: z.ZodEnum<{
55
+ readonly BROWSER: "BROWSER";
56
+ readonly BLOCK: "BLOCK";
57
+ readonly STATUS_CODE_404: "STATUS_CODE_404";
58
+ readonly STATUS_CODE_451: "STATUS_CODE_451";
59
+ readonly SOCKET_DROP: "SOCKET_DROP";
60
+ readonly XRAY_JSON: "XRAY_JSON";
61
+ readonly XRAY_BASE64: "XRAY_BASE64";
62
+ readonly MIHOMO: "MIHOMO";
63
+ readonly STASH: "STASH";
64
+ readonly CLASH: "CLASH";
65
+ readonly SINGBOX: "SINGBOX";
66
+ }>;
67
+ responseModifications: z.ZodOptional<z.ZodObject<{
68
+ headers: z.ZodOptional<z.ZodArray<z.ZodObject<{
69
+ key: z.ZodString;
70
+ value: z.ZodString;
71
+ }, z.core.$strip>>>;
72
+ applyHeadersToEnd: z.ZodOptional<z.ZodBoolean>;
73
+ subscriptionTemplate: z.ZodOptional<z.ZodString>;
74
+ ignoreHostXrayJsonTemplate: z.ZodOptional<z.ZodBoolean>;
75
+ ignoreServeJsonAtBaseSubscription: z.ZodOptional<z.ZodBoolean>;
76
+ additionalExtendedClientsRegex: z.ZodOptional<z.ZodArray<z.ZodString>>;
77
+ disableHwidCheck: z.ZodOptional<z.ZodBoolean>;
78
+ encryption: z.ZodOptional<z.ZodObject<{
79
+ method: z.ZodEnum<{
80
+ age1: "age1";
81
+ age1pq1: "age1pq1";
82
+ }>;
83
+ key: z.ZodString;
84
+ }, z.core.$strip>>;
85
+ excludeHostsByTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
86
+ }, z.core.$strip>>;
87
+ }, z.core.$strip>;
88
+ export declare const ResponseRulesLegacyConfigSchema: z.ZodObject<{
89
+ version: z.ZodLiteral<"1">;
90
+ settings: z.ZodOptional<z.ZodObject<{
91
+ disableSubscriptionAccessByPath: z.ZodOptional<z.ZodBoolean>;
92
+ }, z.core.$strip>>;
93
+ rules: z.ZodArray<z.ZodObject<{
94
+ name: z.ZodString;
95
+ description: z.ZodOptional<z.ZodString>;
96
+ enabled: z.ZodBoolean;
97
+ operator: z.ZodEnum<{
98
+ readonly AND: "AND";
99
+ readonly OR: "OR";
100
+ }>;
101
+ conditions: z.ZodArray<z.ZodObject<{
102
+ headerName: z.ZodString;
103
+ operator: z.ZodEnum<{
104
+ readonly EQUALS: "EQUALS";
105
+ readonly NOT_EQUALS: "NOT_EQUALS";
106
+ readonly CONTAINS: "CONTAINS";
107
+ readonly NOT_CONTAINS: "NOT_CONTAINS";
108
+ readonly STARTS_WITH: "STARTS_WITH";
109
+ readonly NOT_STARTS_WITH: "NOT_STARTS_WITH";
110
+ readonly ENDS_WITH: "ENDS_WITH";
111
+ readonly NOT_ENDS_WITH: "NOT_ENDS_WITH";
112
+ readonly REGEX: "REGEX";
113
+ readonly NOT_REGEX: "NOT_REGEX";
114
+ readonly EXISTS: "EXISTS";
115
+ readonly NOT_EXISTS: "NOT_EXISTS";
116
+ }>;
117
+ value: z.ZodString;
118
+ caseSensitive: z.ZodBoolean;
119
+ }, z.core.$strip>>;
120
+ responseType: z.ZodEnum<{
121
+ readonly BROWSER: "BROWSER";
122
+ readonly BLOCK: "BLOCK";
123
+ readonly STATUS_CODE_404: "STATUS_CODE_404";
124
+ readonly STATUS_CODE_451: "STATUS_CODE_451";
125
+ readonly SOCKET_DROP: "SOCKET_DROP";
126
+ readonly XRAY_JSON: "XRAY_JSON";
127
+ readonly XRAY_BASE64: "XRAY_BASE64";
128
+ readonly MIHOMO: "MIHOMO";
129
+ readonly STASH: "STASH";
130
+ readonly CLASH: "CLASH";
131
+ readonly SINGBOX: "SINGBOX";
132
+ }>;
133
+ responseModifications: z.ZodOptional<z.ZodObject<{
134
+ headers: z.ZodOptional<z.ZodArray<z.ZodObject<{
135
+ key: z.ZodString;
136
+ value: z.ZodString;
137
+ }, z.core.$strip>>>;
138
+ applyHeadersToEnd: z.ZodOptional<z.ZodBoolean>;
139
+ subscriptionTemplate: z.ZodOptional<z.ZodString>;
140
+ ignoreHostXrayJsonTemplate: z.ZodOptional<z.ZodBoolean>;
141
+ ignoreServeJsonAtBaseSubscription: z.ZodOptional<z.ZodBoolean>;
142
+ additionalExtendedClientsRegex: z.ZodOptional<z.ZodArray<z.ZodString>>;
143
+ disableHwidCheck: z.ZodOptional<z.ZodBoolean>;
144
+ encryption: z.ZodOptional<z.ZodObject<{
145
+ method: z.ZodEnum<{
146
+ age1: "age1";
147
+ age1pq1: "age1pq1";
148
+ }>;
149
+ key: z.ZodString;
150
+ }, z.core.$strip>>;
151
+ excludeHostsByTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
152
+ }, z.core.$strip>>;
153
+ }, z.core.$strip>>;
154
+ }, z.core.$strip>;
155
+ export type TResponseRuleLegacy = z.infer<typeof ResponseRuleLegacySchema>;
156
+ export type TResponseRulesLegacyConfig = z.infer<typeof ResponseRulesLegacyConfigSchema>;
157
+ //# sourceMappingURL=response-rules-legacy.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-rules-legacy.schema.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rules-legacy.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB;;;;;GAKG;AAEH,eAAO,MAAM,iCAAiC;;;;;;;;;;;;;;;;;;iBAK5C,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAQnC,CAAC;AAEH,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAI1C,CAAC;AAEH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC3E,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,+BAA+B,CAAC,CAAC"}
@@ -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,10 @@
1
+ import type { ResponseRulesConfigSchema } from './response-rules-config.schema';
2
+ import type { TResponseRulesLegacyConfig } from './response-rules-legacy.schema';
3
+ import type { z } from 'zod';
4
+ type TResponseRulesConfig = z.infer<typeof ResponseRulesConfigSchema>;
5
+ /**
6
+ * Migrates a legacy (version 1) response rules config to version 2.
7
+ */
8
+ export declare function migrateResponseRulesConfig(config: TResponseRulesConfig | TResponseRulesLegacyConfig): TResponseRulesConfig;
9
+ export {};
10
+ //# sourceMappingURL=response-rules-migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response-rules-migration.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rules-migration.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,KAAK,EAGR,0BAA0B,EAC7B,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAK7B,KAAK,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAGtE;;GAEG;AACH,wBAAgB,0BAA0B,CACtC,MAAM,EAAE,oBAAoB,GAAG,0BAA0B,GAC1D,oBAAoB,CAUtB"}
@@ -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
+ }
@@ -14,9 +14,7 @@ export declare const SubscriptionSettingsSchema: z.ZodObject<{
14
14
  customResponseHeaders: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodString>>;
15
15
  randomizeHosts: z.ZodBoolean;
16
16
  responseRules: z.ZodNullable<z.ZodObject<{
17
- version: z.ZodEnum<{
18
- readonly 1: "1";
19
- }>;
17
+ version: z.ZodLiteral<"2">;
20
18
  settings: z.ZodOptional<z.ZodObject<{
21
19
  disableSubscriptionAccessByPath: z.ZodOptional<z.ZodBoolean>;
22
20
  }, z.core.$strip>>;
@@ -24,27 +22,7 @@ export declare const SubscriptionSettingsSchema: z.ZodObject<{
24
22
  name: z.ZodString;
25
23
  description: z.ZodOptional<z.ZodString>;
26
24
  enabled: z.ZodBoolean;
27
- operator: z.ZodEnum<{
28
- readonly AND: "AND";
29
- readonly OR: "OR";
30
- }>;
31
- conditions: z.ZodArray<z.ZodObject<{
32
- headerName: z.ZodString;
33
- operator: z.ZodEnum<{
34
- readonly EQUALS: "EQUALS";
35
- readonly NOT_EQUALS: "NOT_EQUALS";
36
- readonly CONTAINS: "CONTAINS";
37
- readonly NOT_CONTAINS: "NOT_CONTAINS";
38
- readonly STARTS_WITH: "STARTS_WITH";
39
- readonly NOT_STARTS_WITH: "NOT_STARTS_WITH";
40
- readonly ENDS_WITH: "ENDS_WITH";
41
- readonly NOT_ENDS_WITH: "NOT_ENDS_WITH";
42
- readonly REGEX: "REGEX";
43
- readonly NOT_REGEX: "NOT_REGEX";
44
- }>;
45
- value: z.ZodString;
46
- caseSensitive: z.ZodBoolean;
47
- }, z.core.$strip>>;
25
+ when: z.ZodOptional<z.ZodType<import("./response-rules").TResponseRuleConditionNode, unknown, z.core.$ZodTypeInternals<import("./response-rules").TResponseRuleConditionNode, unknown>>>;
48
26
  responseType: z.ZodEnum<{
49
27
  readonly BROWSER: "BROWSER";
50
28
  readonly BLOCK: "BLOCK";
@@ -78,7 +56,7 @@ export declare const SubscriptionSettingsSchema: z.ZodObject<{
78
56
  }, z.core.$strip>>;
79
57
  excludeHostsByTags: z.ZodOptional<z.ZodArray<z.ZodString>>;
80
58
  }, z.core.$strip>>;
81
- }, z.core.$strip>>;
59
+ }, z.core.$strict>>;
82
60
  }, z.core.$strip>>;
83
61
  hwidSettings: z.ZodNullable<z.ZodObject<{
84
62
  enabled: z.ZodBoolean;
@@ -1 +1 @@
1
- {"version":3,"file":"subscription-settings.schema.d.ts","sourceRoot":"","sources":["../../../models/subscription-settings.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiBrC,CAAC"}
1
+ {"version":3,"file":"subscription-settings.schema.d.ts","sourceRoot":"","sources":["../../../models/subscription-settings.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAiBrC,CAAC"}