@remnawave/backend-contract 2.2.0 → 2.2.2

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 (25) hide show
  1. package/build/backend/commands/subscription/get-subscription-by-short-uuid-by-client-type.command.d.ts.map +1 -1
  2. package/build/backend/commands/subscription/get-subscription-by-short-uuid-by-client-type.command.js +3 -1
  3. package/build/backend/constants/response-rules/response-rules.contants.d.ts +21 -21
  4. package/build/backend/constants/response-rules/response-rules.contants.d.ts.map +1 -1
  5. package/build/backend/constants/response-rules/response-rules.contants.js +21 -21
  6. package/build/backend/models/response-rules/response-rule-condition.schema.d.ts.map +1 -1
  7. package/build/backend/models/response-rules/response-rule-condition.schema.js +24 -9
  8. package/build/backend/models/response-rules/response-rule-modifications.schema.d.ts.map +1 -1
  9. package/build/backend/models/response-rules/response-rule-modifications.schema.js +30 -20
  10. package/build/backend/models/response-rules/response-rule.schema.d.ts +107 -0
  11. package/build/backend/models/response-rules/response-rule.schema.d.ts.map +1 -1
  12. package/build/backend/models/response-rules/response-rule.schema.js +26 -56
  13. package/build/backend/models/response-rules/response-rules-config.schema.d.ts.map +1 -1
  14. package/build/backend/models/response-rules/response-rules-config.schema.js +4 -41
  15. package/build/backend/models/response-rules/response-rules-examples.d.ts +6 -0
  16. package/build/backend/models/response-rules/response-rules-examples.d.ts.map +1 -0
  17. package/build/backend/models/response-rules/response-rules-examples.js +50 -0
  18. package/build/frontend/commands/subscription/get-subscription-by-short-uuid-by-client-type.command.js +3 -1
  19. package/build/frontend/constants/response-rules/response-rules.contants.js +21 -21
  20. package/build/frontend/models/response-rules/response-rule-condition.schema.js +24 -9
  21. package/build/frontend/models/response-rules/response-rule-modifications.schema.js +30 -20
  22. package/build/frontend/models/response-rules/response-rule.schema.js +22 -56
  23. package/build/frontend/models/response-rules/response-rules-config.schema.js +4 -41
  24. package/build/frontend/models/response-rules/response-rules-examples.js +50 -0
  25. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"get-subscription-by-short-uuid-by-client-type.command.d.ts","sourceRoot":"","sources":["../../../../commands/subscription/get-subscription-by-short-uuid-by-client-type.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,yBAAiB,6CAA6C,CAAC;IACpD,MAAM,GAAG,+BAA4B,CAAC;IACtC,MAAM,OAAO,QAAoB,CAAC;IAElC,MAAM,aAAa;;;;;;;;;;;;;;;;MAGxB,CAAC;IAEH,KAAY,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;CACvD"}
1
+ {"version":3,"file":"get-subscription-by-short-uuid-by-client-type.command.d.ts","sourceRoot":"","sources":["../../../../commands/subscription/get-subscription-by-short-uuid-by-client-type.command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,yBAAiB,6CAA6C,CAAC;IACpD,MAAM,GAAG,+BAA4B,CAAC;IACtC,MAAM,OAAO,QAAoB,CAAC;IAElC,MAAM,aAAa;;;;;;;;;;;;;;;;MAKxB,CAAC;IAEH,KAAY,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;CACvD"}
@@ -10,6 +10,8 @@ var GetSubscriptionByShortUuidByClientTypeCommand;
10
10
  GetSubscriptionByShortUuidByClientTypeCommand.TSQ_url = GetSubscriptionByShortUuidByClientTypeCommand.url(':shortUuid');
11
11
  GetSubscriptionByShortUuidByClientTypeCommand.RequestSchema = zod_1.z.object({
12
12
  shortUuid: zod_1.z.string(),
13
- clientType: zod_1.z.nativeEnum(constants_1.REQUEST_TEMPLATE_TYPE),
13
+ clientType: zod_1.z.nativeEnum(constants_1.REQUEST_TEMPLATE_TYPE, {
14
+ message: 'Invalid client type.',
15
+ }),
14
16
  });
15
17
  })(GetSubscriptionByShortUuidByClientTypeCommand || (exports.GetSubscriptionByShortUuidByClientTypeCommand = GetSubscriptionByShortUuidByClientTypeCommand = {}));
@@ -42,28 +42,28 @@ export type TResponseRulesConditionOperator = [
42
42
  export declare const RESPONSE_RULES_CONDITION_OPERATORS_VALUES: ("EQUALS" | "NOT_EQUALS" | "CONTAINS" | "NOT_CONTAINS" | "STARTS_WITH" | "NOT_STARTS_WITH" | "ENDS_WITH" | "NOT_ENDS_WITH" | "REGEX" | "NOT_REGEX")[];
43
43
  export type TResponseRulesConditionOperatorKeys = (typeof RESPONSE_RULES_CONDITION_OPERATORS)[keyof typeof RESPONSE_RULES_CONDITION_OPERATORS];
44
44
  export declare const RESPONSE_RULES_RESPONSE_TYPES_DESCRIPTION: {
45
- readonly BLOCK: "Block response type blocks the request and returns a 403 status code.";
46
- readonly XRAY_BASE64: "Previously used as fallback response type. It return subscription as base64 encoded string. Compatible with most client application with Xray core.";
47
- readonly STATUS_CODE_404: "Status code 404 response type returns a 404 status code. This response type is used to return a 404 status code.";
48
- readonly STATUS_CODE_451: "Status code 451 response type returns a 451 status code. This response type is used to return a 451 status code.";
49
- readonly SOCKET_DROP: "Socket drop response type drops the socket connection. This response type is used to drop the socket connection.";
50
- readonly CLASH: "Useful for client application that use Legacy Clash core. It return subscription as Clash YAML format.";
51
- readonly STASH: "Format which is used by Stash client application.";
52
- readonly SINGBOX: "Format which is used by Singbox client application.";
53
- readonly MIHOMO: "Return subscription as Mihomo Core YAML format.";
54
- readonly XRAY_JSON: "Return subscription as Xray JSON format.";
55
- readonly BROWSER: "Return subscription as browser format.";
45
+ readonly XRAY_JSON: "Return **subscription** in XRAY-JSON format. (Using `Xray Json` template)";
46
+ readonly XRAY_BASE64: "Return **subscription** in BASE64 encoded string. Compatible with most client application with Xray core.";
47
+ readonly MIHOMO: "Return **subscription** in Mihomo format. (Using `Mihomo` template)";
48
+ readonly STASH: "Return **subscription** in Stash format. (Using `Stash` template)";
49
+ readonly CLASH: "Return **subscription** in Clash format. (Using `Clash` template) Useful for client application that use Legacy Clash core.";
50
+ readonly SINGBOX: "Return **subscription** in Singbox format. (Using `Singbox` template) Format which is used by Singbox client application.";
51
+ readonly BROWSER: "Return **subscription** as browser format. The same as on `/info` route.";
52
+ readonly BLOCK: "**Drop** request and return `403` status code.";
53
+ readonly STATUS_CODE_404: "**Drop** request and return `404` status code.";
54
+ readonly STATUS_CODE_451: "**Drop** request and return `451` status code.";
55
+ readonly SOCKET_DROP: "**Drop** the socket connection.";
56
56
  };
57
57
  export declare const RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION: {
58
- readonly EQUALS: "Equals operator checks if the header value exactly matches the specified string, case sensitive. Underlying implementation uses strict string comparison – ===.";
59
- readonly NOT_EQUALS: "Not equals operator checks if the header value does not match the specified string, case sensitive. Underlying implementation uses strict string comparison – !==.";
60
- readonly CONTAINS: "Contains operator checks if the header value contains the specified string, case sensitive. Underlying implementation uses string.includes().";
61
- readonly NOT_CONTAINS: "Not contains operator checks if the header value does not contain the specified string, case sensitive. Underlying implementation uses string.includes().";
62
- readonly STARTS_WITH: "Starts with operator checks if the header value starts with the specified string, case sensitive. Underlying implementation uses string.startsWith().";
63
- readonly NOT_STARTS_WITH: "Not starts with operator checks if the header value does not start with the specified string, case sensitive. Underlying implementation uses string.startsWith().";
64
- readonly ENDS_WITH: "Ends with operator checks if the header value ends with the specified string, case sensitive. Underlying implementation uses string.endsWith().";
65
- readonly NOT_ENDS_WITH: "Not ends with operator checks if the header value does not end with the specified string, case sensitive. Underlying implementation uses string.endsWith().";
66
- readonly REGEX: "Regex operator checks if the header value matches the specified regex. Underlying implementation uses regex.test().";
67
- readonly NOT_REGEX: "Inverse regex operator checks if the header value does not match the specified regex. Underlying implementation uses regex.test().";
58
+ readonly EQUALS: "Performs an exact, comparison between the header value and specified string. `string === value`";
59
+ readonly NOT_EQUALS: "Ensures the header value does not exactly match the specified string. `string !== value`";
60
+ readonly CONTAINS: "Checks if the header value contains the specified string as a substring. `string.includes()`";
61
+ readonly NOT_CONTAINS: "Verifies the header value does not contain the specified string as a substring. `!string.includes()`";
62
+ readonly STARTS_WITH: "Validates that the header value begins with the specified string. `string.startsWith()`";
63
+ readonly NOT_STARTS_WITH: "Validates that the header value does not begin with the specified string. `!string.startsWith()`";
64
+ readonly ENDS_WITH: "Confirms the header value ends with the specified string. `string.endsWith()`";
65
+ readonly NOT_ENDS_WITH: "Confirms the header value does not end with the specified string. `!string.endsWith()`";
66
+ readonly REGEX: "Evaluates if the header value matches the specified regular expression pattern. `regex.test()`";
67
+ readonly NOT_REGEX: "Evaluates if the header value does not match the specified regular expression pattern. `!regex.test()`";
68
68
  };
69
69
  //# sourceMappingURL=response-rules.contants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"response-rules.contants.d.ts","sourceRoot":"","sources":["../../../../constants/response-rules/response-rules.contants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,6BAA6B;;CAEhC,CAAC;AAEX,eAAO,MAAM,wBAAwB;;;CAG3B,CAAC;AAEX,eAAO,MAAM,6BAA6B;;CAEhC,CAAC;AAEX,eAAO,MAAM,kCAAkC;;;;;;;;;;;CAWrC,CAAC;AAEX,eAAO,MAAM,6BAA6B;;;;;;;;;;;;CAOhC,CAAC;AAEX,MAAM,MAAM,0BAA0B,GAAG,CAAC,MAAM,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9F,eAAO,MAAM,oCAAoC,0JAA+C,CAAC;AACjG,MAAM,MAAM,8BAA8B,GACtC,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,OAAO,6BAA6B,CAAC,CAAC;AAEvF,MAAM,MAAM,+BAA+B,GAAG;IAC1C,MAAM,OAAO,kCAAkC;CAClD,CAAC,MAAM,CAAC,CAAC;AACV,eAAO,MAAM,yCAAyC,uJAErD,CAAC;AACF,MAAM,MAAM,mCAAmC,GAC3C,CAAC,OAAO,kCAAkC,CAAC,CAAC,MAAM,OAAO,kCAAkC,CAAC,CAAC;AAEjG,eAAO,MAAM,yCAAyC;;;;;;;;;;;;CAkB5C,CAAC;AAEX,eAAO,MAAM,8CAA8C;;;;;;;;;;;CAqBjD,CAAC"}
1
+ {"version":3,"file":"response-rules.contants.d.ts","sourceRoot":"","sources":["../../../../constants/response-rules/response-rules.contants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,6BAA6B;;CAEhC,CAAC;AAEX,eAAO,MAAM,wBAAwB;;;CAG3B,CAAC;AAEX,eAAO,MAAM,6BAA6B;;CAEhC,CAAC;AAEX,eAAO,MAAM,kCAAkC;;;;;;;;;;;CAWrC,CAAC;AAEX,eAAO,MAAM,6BAA6B;;;;;;;;;;;;CAOhC,CAAC;AAEX,MAAM,MAAM,0BAA0B,GAAG,CAAC,MAAM,OAAO,6BAA6B,CAAC,CAAC,MAAM,CAAC,CAAC;AAC9F,eAAO,MAAM,oCAAoC,0JAA+C,CAAC;AACjG,MAAM,MAAM,8BAA8B,GACtC,CAAC,OAAO,6BAA6B,CAAC,CAAC,MAAM,OAAO,6BAA6B,CAAC,CAAC;AAEvF,MAAM,MAAM,+BAA+B,GAAG;IAC1C,MAAM,OAAO,kCAAkC;CAClD,CAAC,MAAM,CAAC,CAAC;AACV,eAAO,MAAM,yCAAyC,uJAErD,CAAC;AACF,MAAM,MAAM,mCAAmC,GAC3C,CAAC,OAAO,kCAAkC,CAAC,CAAC,MAAM,OAAO,kCAAkC,CAAC,CAAC;AAEjG,eAAO,MAAM,yCAAyC;;;;;;;;;;;;CAqB5C,CAAC;AAEX,eAAO,MAAM,8CAA8C;;;;;;;;;;;CAqBjD,CAAC"}
@@ -35,27 +35,27 @@ exports.RESPONSE_RULES_RESPONSE_TYPES = {
35
35
  exports.RESPONSE_RULES_RESPONSE_TYPES_VALUES = Object.values(exports.RESPONSE_RULES_RESPONSE_TYPES);
36
36
  exports.RESPONSE_RULES_CONDITION_OPERATORS_VALUES = Object.values(exports.RESPONSE_RULES_CONDITION_OPERATORS);
37
37
  exports.RESPONSE_RULES_RESPONSE_TYPES_DESCRIPTION = {
38
- [exports.RESPONSE_RULES_RESPONSE_TYPES.BLOCK]: 'Block response type blocks the request and returns a 403 status code.',
39
- [exports.RESPONSE_RULES_RESPONSE_TYPES.XRAY_BASE64]: 'Previously used as fallback response type. It return subscription as base64 encoded string. Compatible with most client application with Xray core.',
40
- [exports.RESPONSE_RULES_RESPONSE_TYPES.STATUS_CODE_404]: 'Status code 404 response type returns a 404 status code. This response type is used to return a 404 status code.',
41
- [exports.RESPONSE_RULES_RESPONSE_TYPES.STATUS_CODE_451]: 'Status code 451 response type returns a 451 status code. This response type is used to return a 451 status code.',
42
- [exports.RESPONSE_RULES_RESPONSE_TYPES.SOCKET_DROP]: 'Socket drop response type drops the socket connection. This response type is used to drop the socket connection.',
43
- [exports.RESPONSE_RULES_RESPONSE_TYPES.CLASH]: 'Useful for client application that use Legacy Clash core. It return subscription as Clash YAML format.',
44
- [exports.RESPONSE_RULES_RESPONSE_TYPES.STASH]: 'Format which is used by Stash client application.',
45
- [exports.RESPONSE_RULES_RESPONSE_TYPES.SINGBOX]: 'Format which is used by Singbox client application.',
46
- [exports.RESPONSE_RULES_RESPONSE_TYPES.MIHOMO]: 'Return subscription as Mihomo Core YAML format.',
47
- [exports.RESPONSE_RULES_RESPONSE_TYPES.XRAY_JSON]: 'Return subscription as Xray JSON format.',
48
- [exports.RESPONSE_RULES_RESPONSE_TYPES.BROWSER]: 'Return subscription as browser format.',
38
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.XRAY_JSON]: 'Return **subscription** in XRAY-JSON format. (Using `Xray Json` template)',
39
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.XRAY_BASE64]: 'Return **subscription** in BASE64 encoded string. Compatible with most client application with Xray core.',
40
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.MIHOMO]: 'Return **subscription** in Mihomo format. (Using `Mihomo` template)',
41
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.STASH]: 'Return **subscription** in Stash format. (Using `Stash` template)',
42
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.CLASH]: 'Return **subscription** in Clash format. (Using `Clash` template) Useful for client application that use Legacy Clash core.',
43
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.SINGBOX]: 'Return **subscription** in Singbox format. (Using `Singbox` template) Format which is used by Singbox client application.',
44
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.BROWSER]: 'Return **subscription** as browser format. The same as on `/info` route.',
45
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.BLOCK]: '**Drop** request and return `403` status code.',
46
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.STATUS_CODE_404]: '**Drop** request and return `404` status code.',
47
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.STATUS_CODE_451]: '**Drop** request and return `451` status code.',
48
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.SOCKET_DROP]: '**Drop** the socket connection.',
49
49
  };
50
50
  exports.RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION = {
51
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.EQUALS]: 'Equals operator checks if the header value exactly matches the specified string, case sensitive. Underlying implementation uses strict string comparison – ===.',
52
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_EQUALS]: 'Not equals operator checks if the header value does not match the specified string, case sensitive. Underlying implementation uses strict string comparison – !==.',
53
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS]: 'Contains operator checks if the header value contains the specified string, case sensitive. Underlying implementation uses string.includes().',
54
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_CONTAINS]: 'Not contains operator checks if the header value does not contain the specified string, case sensitive. Underlying implementation uses string.includes().',
55
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.STARTS_WITH]: 'Starts with operator checks if the header value starts with the specified string, case sensitive. Underlying implementation uses string.startsWith().',
56
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_STARTS_WITH]: 'Not starts with operator checks if the header value does not start with the specified string, case sensitive. Underlying implementation uses string.startsWith().',
57
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.ENDS_WITH]: 'Ends with operator checks if the header value ends with the specified string, case sensitive. Underlying implementation uses string.endsWith().',
58
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_ENDS_WITH]: 'Not ends with operator checks if the header value does not end with the specified string, case sensitive. Underlying implementation uses string.endsWith().',
59
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.REGEX]: 'Regex operator checks if the header value matches the specified regex. Underlying implementation uses regex.test().',
60
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_REGEX]: 'Inverse regex operator checks if the header value does not match the specified regex. Underlying implementation uses regex.test().',
51
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.EQUALS]: 'Performs an exact, comparison between the header value and specified string. `string === value`',
52
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_EQUALS]: 'Ensures the header value does not exactly match the specified string. `string !== value`',
53
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS]: 'Checks if the header value contains the specified string as a substring. `string.includes()`',
54
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_CONTAINS]: 'Verifies the header value does not contain the specified string as a substring. `!string.includes()`',
55
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.STARTS_WITH]: 'Validates that the header value begins with the specified string. `string.startsWith()`',
56
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_STARTS_WITH]: 'Validates that the header value does not begin with the specified string. `!string.startsWith()`',
57
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.ENDS_WITH]: 'Confirms the header value ends with the specified string. `string.endsWith()`',
58
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_ENDS_WITH]: 'Confirms the header value does not end with the specified string. `!string.endsWith()`',
59
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.REGEX]: 'Evaluates if the header value matches the specified regular expression pattern. `regex.test()`',
60
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_REGEX]: 'Evaluates if the header value does not match the specified regular expression pattern. `!regex.test()`',
61
61
  };
@@ -1 +1 @@
1
- {"version":3,"file":"response-rule-condition.schema.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rule-condition.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;EAsCtC,CAAC"}
1
+ {"version":3,"file":"response-rule-condition.schema.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rule-condition.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;EAyDnC,CAAC"}
@@ -3,27 +3,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResponseRuleConditionSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const constants_1 = require("../../constants");
6
- exports.ResponseRuleConditionSchema = zod_1.z.object({
6
+ exports.ResponseRuleConditionSchema = zod_1.z
7
+ .object({
7
8
  headerName: zod_1.z
8
9
  .string()
9
10
  .regex(/^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$/, 'Invalid header name. Only letters(a-z, A-Z), numbers(0-9), underscores(_) and hyphens(-) are allowed.')
10
11
  .describe(JSON.stringify({
11
- title: 'Header Name',
12
- markdownDescription: 'Name of the HTTP header to check, case insensitive, must comply with RFC 7230.',
12
+ markdownDescription: '**Name** of the HTTP header to check. Must comply with RFC 7230.',
13
13
  })),
14
14
  operator: zod_1.z.nativeEnum(constants_1.RESPONSE_RULES_CONDITION_OPERATORS).describe(JSON.stringify({
15
- markdownDescription: `Comparison operator to compare the header value against.\n\n${Object.entries(constants_1.RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION)
16
- .map(([key, description]) => `- **${key}**: ${description}\n`)
17
- .join('\n')}`,
15
+ errorMessage: 'Invalid operator. Please select a valid operator.',
16
+ markdownDescription: 'Operator to use for comparing the `headerName` with `value`.',
17
+ markdownEnumDescriptions: Object.entries(constants_1.RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION).map(([_key, description]) => description),
18
18
  })),
19
19
  value: zod_1.z
20
20
  .string()
21
21
  .min(1, 'Value is required')
22
22
  .max(255, 'Value must be less than 255 characters')
23
23
  .describe(JSON.stringify({
24
- markdownDescription: `Value to check against the header, case sensitive (excluding regex/not_regex operator). Maximum length is 255 characters.`,
24
+ markdownDescription: `**Value** to check against the **headerName**.`,
25
25
  })),
26
26
  caseSensitive: zod_1.z.boolean().describe(JSON.stringify({
27
- markdownDescription: 'Whether the value is case sensitive. If true, the value will be compared case sensitive. If false, the value will be lowercased before comparison.',
27
+ markdownDescription: 'Whether the value is **case sensitive**. \n\n - `true`: the value will be compared as is. \n\n - `false`: the value will be lowercased **before** comparison.',
28
28
  })),
29
- });
29
+ })
30
+ .describe(JSON.stringify({
31
+ markdownDescription: 'Condition to check against the **headerName**.',
32
+ defaultSnippets: [
33
+ {
34
+ label: 'Examples: Check if header contains "text/html"',
35
+ markdownDescription: 'Condition to check if **headerName** contains "text/html"',
36
+ body: {
37
+ headerName: 'accept',
38
+ operator: 'CONTAINS',
39
+ value: 'text/html',
40
+ caseSensitive: true,
41
+ },
42
+ },
43
+ ],
44
+ }));
@@ -1 +1 @@
1
- {"version":3,"file":"response-rule-modifications.schema.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rule-modifications.schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AA0BpB,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;GAyCvC,CAAC"}
1
+ {"version":3,"file":"response-rule-modifications.schema.d.ts","sourceRoot":"","sources":["../../../../models/response-rules/response-rule-modifications.schema.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,KAAK,CAAC;AAEpB,eAAO,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;GAoEvC,CAAC"}
@@ -5,44 +5,54 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ResponseRuleModificationsSchema = void 0;
7
7
  const zod_1 = __importDefault(require("zod"));
8
- const exampleJson = JSON.stringify({
9
- headers: [
10
- {
11
- key: 'X-Custom-Header',
12
- value: 'Custom Value',
13
- },
14
- ],
15
- }, null, 2);
16
- const exampleHeaderJson = JSON.stringify([
17
- {
18
- key: 'X-Custom-Header',
19
- value: 'Custom Value',
20
- },
21
- ], null, 2);
22
8
  exports.ResponseRuleModificationsSchema = zod_1.default
23
9
  .object({
24
10
  headers: zod_1.default
25
- .array(zod_1.default.object({
11
+ .array(zod_1.default
12
+ .object({
26
13
  key: zod_1.default
27
14
  .string()
28
15
  .regex(/^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$/, 'Invalid header name. Only letters(a-z, A-Z), numbers(0-9), underscores(_) and hyphens(-) are allowed.')
29
16
  .describe(JSON.stringify({
30
- title: 'Key',
31
17
  markdownDescription: 'Key of the response header. Must comply with RFC 7230.',
32
18
  })),
33
19
  value: zod_1.default
34
20
  .string()
35
21
  .min(1, 'Value is required')
36
22
  .describe(JSON.stringify({
37
- title: 'Value',
38
23
  markdownDescription: 'Value of the response header. ',
39
24
  })),
40
- }))
25
+ })
26
+ .describe(JSON.stringify({
27
+ markdownDescription: '**Key** and **value** of the response header will be added to the response.',
28
+ })))
41
29
  .describe(JSON.stringify({
42
- markdownDescription: `Array of headers to be added when the rule is matched.\n\nExample:\n\`\`\`json\n${exampleHeaderJson}\n\`\`\``,
30
+ defaultSnippets: [
31
+ {
32
+ label: 'Examples: Add custom header',
33
+ markdownDescription: 'Add a custom header to the response',
34
+ body: [
35
+ {
36
+ key: 'X-Custom-Header',
37
+ value: 'CustomValue',
38
+ },
39
+ ],
40
+ },
41
+ ],
42
+ markdownDescription: 'Array of headers to be added when the rule is matched.',
43
43
  })),
44
44
  })
45
45
  .optional()
46
46
  .describe(JSON.stringify({
47
- markdownDescription: `Response modifications to be applied when the rule is matched.\n\nExample:\n\`\`\`json\n${exampleJson}\n\`\`\``,
47
+ examples: [
48
+ {
49
+ headers: [
50
+ {
51
+ key: 'X-Custom-Header',
52
+ value: 'CustomValue',
53
+ },
54
+ ],
55
+ },
56
+ ],
57
+ markdownDescription: 'Response modifications to be applied when the rule is matched. Optional.',
48
58
  }));
@@ -1,4 +1,111 @@
1
1
  import { z } from 'zod';
2
+ export declare const ResponseRuleSchemaBase: z.ZodObject<{
3
+ name: z.ZodString;
4
+ description: z.ZodOptional<z.ZodString>;
5
+ enabled: z.ZodBoolean;
6
+ operator: z.ZodNativeEnum<{
7
+ readonly AND: "AND";
8
+ readonly OR: "OR";
9
+ }>;
10
+ conditions: z.ZodArray<z.ZodObject<{
11
+ headerName: z.ZodString;
12
+ operator: z.ZodNativeEnum<{
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
+ }, "strip", z.ZodTypeAny, {
27
+ value: string;
28
+ headerName: string;
29
+ operator: "EQUALS" | "NOT_EQUALS" | "CONTAINS" | "NOT_CONTAINS" | "STARTS_WITH" | "NOT_STARTS_WITH" | "ENDS_WITH" | "NOT_ENDS_WITH" | "REGEX" | "NOT_REGEX";
30
+ caseSensitive: boolean;
31
+ }, {
32
+ value: string;
33
+ headerName: string;
34
+ operator: "EQUALS" | "NOT_EQUALS" | "CONTAINS" | "NOT_CONTAINS" | "STARTS_WITH" | "NOT_STARTS_WITH" | "ENDS_WITH" | "NOT_ENDS_WITH" | "REGEX" | "NOT_REGEX";
35
+ caseSensitive: boolean;
36
+ }>, "many">;
37
+ responseType: z.ZodNativeEnum<{
38
+ readonly BROWSER: "BROWSER";
39
+ readonly BLOCK: "BLOCK";
40
+ readonly STATUS_CODE_404: "STATUS_CODE_404";
41
+ readonly STATUS_CODE_451: "STATUS_CODE_451";
42
+ readonly SOCKET_DROP: "SOCKET_DROP";
43
+ readonly XRAY_JSON: "XRAY_JSON";
44
+ readonly XRAY_BASE64: "XRAY_BASE64";
45
+ readonly MIHOMO: "MIHOMO";
46
+ readonly STASH: "STASH";
47
+ readonly CLASH: "CLASH";
48
+ readonly SINGBOX: "SINGBOX";
49
+ }>;
50
+ responseModifications: z.ZodOptional<z.ZodObject<{
51
+ headers: z.ZodArray<z.ZodObject<{
52
+ key: z.ZodString;
53
+ value: z.ZodString;
54
+ }, "strip", z.ZodTypeAny, {
55
+ value: string;
56
+ key: string;
57
+ }, {
58
+ value: string;
59
+ key: string;
60
+ }>, "many">;
61
+ }, "strip", z.ZodTypeAny, {
62
+ headers: {
63
+ value: string;
64
+ key: string;
65
+ }[];
66
+ }, {
67
+ headers: {
68
+ value: string;
69
+ key: string;
70
+ }[];
71
+ }>>;
72
+ }, "strip", z.ZodTypeAny, {
73
+ name: string;
74
+ operator: "AND" | "OR";
75
+ enabled: boolean;
76
+ conditions: {
77
+ value: string;
78
+ headerName: string;
79
+ operator: "EQUALS" | "NOT_EQUALS" | "CONTAINS" | "NOT_CONTAINS" | "STARTS_WITH" | "NOT_STARTS_WITH" | "ENDS_WITH" | "NOT_ENDS_WITH" | "REGEX" | "NOT_REGEX";
80
+ caseSensitive: boolean;
81
+ }[];
82
+ responseType: "STASH" | "SINGBOX" | "MIHOMO" | "XRAY_JSON" | "CLASH" | "XRAY_BASE64" | "BROWSER" | "BLOCK" | "STATUS_CODE_404" | "STATUS_CODE_451" | "SOCKET_DROP";
83
+ description?: string | undefined;
84
+ responseModifications?: {
85
+ headers: {
86
+ value: string;
87
+ key: string;
88
+ }[];
89
+ } | undefined;
90
+ }, {
91
+ name: string;
92
+ operator: "AND" | "OR";
93
+ enabled: boolean;
94
+ conditions: {
95
+ value: string;
96
+ headerName: string;
97
+ operator: "EQUALS" | "NOT_EQUALS" | "CONTAINS" | "NOT_CONTAINS" | "STARTS_WITH" | "NOT_STARTS_WITH" | "ENDS_WITH" | "NOT_ENDS_WITH" | "REGEX" | "NOT_REGEX";
98
+ caseSensitive: boolean;
99
+ }[];
100
+ responseType: "STASH" | "SINGBOX" | "MIHOMO" | "XRAY_JSON" | "CLASH" | "XRAY_BASE64" | "BROWSER" | "BLOCK" | "STATUS_CODE_404" | "STATUS_CODE_451" | "SOCKET_DROP";
101
+ description?: string | undefined;
102
+ responseModifications?: {
103
+ headers: {
104
+ value: string;
105
+ key: string;
106
+ }[];
107
+ } | undefined;
108
+ }>;
2
109
  export declare const ResponseRuleSchema: z.ZodObject<{
3
110
  name: z.ZodString;
4
111
  description: z.ZodOptional<z.ZodString>;
@@ -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;AAqCxB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6E1B,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;AAexB,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgDjC,CAAC;AAEH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqB9B,CAAC"}
@@ -1,39 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResponseRuleSchema = void 0;
3
+ exports.ResponseRuleSchema = exports.ResponseRuleSchemaBase = void 0;
4
4
  const zod_1 = require("zod");
5
+ const response_rules_examples_1 = require("./response-rules-examples");
5
6
  const constants_1 = require("../../constants");
6
7
  const response_rule_modifications_schema_1 = require("./response-rule-modifications.schema");
7
8
  const response_rule_condition_schema_1 = require("./response-rule-condition.schema");
8
- const RuleExampleJson = JSON.stringify({
9
- name: 'Block Legacy Clients',
10
- description: 'Block requests from legacy clients',
11
- enabled: true,
12
- operator: constants_1.RESPONSE_RULES_OPERATORS.OR,
13
- conditions: [
14
- {
15
- headerName: 'user-agent',
16
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
17
- value: 'Hiddify',
18
- caseSensitive: true,
19
- },
20
- {
21
- headerName: 'user-agent',
22
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
23
- value: 'FoxRay',
24
- caseSensitive: true,
25
- },
26
- ],
27
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
28
- }, null, 2);
29
- exports.ResponseRuleSchema = zod_1.z
30
- .object({
9
+ exports.ResponseRuleSchemaBase = zod_1.z.object({
31
10
  name: zod_1.z
32
11
  .string()
33
12
  .min(1, 'Name is required')
34
13
  .max(50, 'Name must be less than 50 characters')
35
14
  .describe(JSON.stringify({
36
- title: 'Name',
37
15
  markdownDescription: 'Name of the response rule.',
38
16
  })),
39
17
  description: zod_1.z
@@ -42,49 +20,41 @@ exports.ResponseRuleSchema = zod_1.z
42
20
  .max(250, 'Description must be less than 250 characters')
43
21
  .optional()
44
22
  .describe(JSON.stringify({
45
- title: 'Description',
46
- markdownDescription: 'Description of the response rule. Maximum length is 250 characters.',
23
+ markdownDescription: 'Description of the response rule. Optional.',
47
24
  })),
48
25
  enabled: zod_1.z.boolean().describe(JSON.stringify({
49
- markdownDescription: 'Whether the response rule is enabled. If disabled, the rule will not be applied.',
26
+ 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.',
50
27
  })),
51
28
  operator: zod_1.z.nativeEnum(constants_1.RESPONSE_RULES_OPERATORS).describe(JSON.stringify({
52
- title: 'Operator',
53
29
  markdownDescription: 'Operator to use for combining conditions in the rule.',
54
30
  })),
55
- conditions: zod_1.z.array(response_rule_condition_schema_1.ResponseRuleConditionSchema),
31
+ conditions: zod_1.z.array(response_rule_condition_schema_1.ResponseRuleConditionSchema).describe(JSON.stringify({
32
+ markdownDescription: 'Array of conditions to check against the request headers. Conditions are applied with **operator**. If conditions are empty, the rule will be matched.',
33
+ })),
56
34
  responseType: zod_1.z.nativeEnum(constants_1.RESPONSE_RULES_RESPONSE_TYPES).describe(JSON.stringify({
57
- markdownDescription: `Type of the response. Determines the type of **response** to be returned when the rule is matched.\n\n${Object.entries(constants_1.RESPONSE_RULES_RESPONSE_TYPES_DESCRIPTION)
58
- .map(([key, description]) => `- **${key}**: ${description}\n`)
59
- .join('\n')}`,
35
+ errorMessage: 'Invalid response type. Please select a valid response type.',
36
+ markdownDescription: `Type of the response. Determines the type of **response** to be returned when the rule is matched.`,
37
+ markdownEnumDescriptions: Object.entries(constants_1.RESPONSE_RULES_RESPONSE_TYPES_DESCRIPTION).map(([_key, description]) => description),
60
38
  })),
61
39
  responseModifications: response_rule_modifications_schema_1.ResponseRuleModificationsSchema,
62
- })
63
- .describe(JSON.stringify({
64
- title: 'Response Rule',
65
- markdownDescription: `\n\nFields:\n- **name**: Name of the response rule (required)\n- **description**: Description of the response rule (optional)\n- **enabled**: Whether the response rule is enabled. If disabled, the rule will not be applied.\n- **operator**: Operator to combine conditions (AND/OR)\n- **conditions**: Array of conditions to match against HTTP headers\n - **headerName**: Name of the HTTP header to check (case insensitive)\n - **operator**: Comparison operator (CONTAINS, EQUALS, etc)\n - **value**: Value to compare against (case sensitive, max 255 chars)\n- **responseType**: Type of response when rule matches (e.g. BLOCK)\n\nExample:\n\`\`\`json\n${RuleExampleJson}\n\`\`\``,
66
- examples: [
40
+ });
41
+ exports.ResponseRuleSchema = exports.ResponseRuleSchemaBase.describe(JSON.stringify({
42
+ defaultSnippets: [
67
43
  {
68
- name: 'This is example rule name',
69
- description: 'This is example rule description (optional)',
70
- enabled: true,
71
- operator: constants_1.RESPONSE_RULES_OPERATORS.AND,
72
- conditions: [
73
- {
74
- headerName: 'user-agent',
75
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
76
- value: 'Example Rule Value, replace with your own value',
77
- caseSensitive: true,
78
- },
79
- ],
80
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
44
+ label: 'Examples: Blank rule',
45
+ markdownDescription: `Simple blank rule with no conditions or modifications.\n\`\`\`json\n${JSON.stringify(response_rules_examples_1.EXAMPLES_SRR_BLANK_RULE, null, 2)}\n\`\`\``,
46
+ body: {
47
+ ...response_rules_examples_1.EXAMPLES_SRR_BLANK_RULE,
48
+ },
81
49
  },
82
50
  {
83
- name: 'Empty rule',
84
- enabled: true,
85
- operator: constants_1.RESPONSE_RULES_OPERATORS.AND,
86
- conditions: [],
87
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
51
+ label: 'Examples: Block Legacy Clients',
52
+ markdownDescription: `Block requests from legacy clients\n\`\`\`json\n${JSON.stringify(response_rules_examples_1.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE, null, 2)}\n\`\`\``,
53
+ body: {
54
+ ...response_rules_examples_1.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE,
55
+ },
88
56
  },
89
57
  ],
58
+ title: 'Response Rule',
59
+ markdownDescription: (0, response_rules_examples_1.generateResponseRuleDescription)(exports.ResponseRuleSchemaBase),
90
60
  }));
@@ -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;AAoCxB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCpC,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;AAMxB,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAepC,CAAC"}
@@ -2,54 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResponseRulesConfigSchema = void 0;
4
4
  const zod_1 = require("zod");
5
+ const response_rules_examples_1 = require("./response-rules-examples");
5
6
  const constants_1 = require("../../constants");
6
7
  const response_rule_schema_1 = require("./response-rule.schema");
7
- const RuleExampleJson = JSON.stringify({
8
- name: 'Block Legacy Clients',
9
- description: 'Block requests from legacy clients',
10
- operator: constants_1.RESPONSE_RULES_OPERATORS.OR,
11
- enabled: true,
12
- conditions: [
13
- {
14
- headerName: 'user-agent',
15
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
16
- value: 'Hiddify',
17
- caseSensitive: true,
18
- },
19
- {
20
- headerName: 'user-agent',
21
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
22
- value: 'FoxRay',
23
- caseSensitive: true,
24
- },
25
- ],
26
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
27
- }, null, 2);
28
8
  exports.ResponseRulesConfigSchema = zod_1.z.object({
29
9
  version: zod_1.z.nativeEnum(constants_1.RESPONSE_RULES_CONFIG_VERSION).describe(JSON.stringify({
30
10
  title: 'Response Rules Config Version',
31
11
  markdownDescription: 'Version of the **response rules** config. Currently supported version is **1**.',
32
12
  })),
33
13
  rules: zod_1.z.array(response_rule_schema_1.ResponseRuleSchema).describe(JSON.stringify({
34
- examples: [
35
- [
36
- {
37
- name: 'This is example rule name',
38
- description: 'This is example rule description (optional)',
39
- operator: constants_1.RESPONSE_RULES_OPERATORS.AND,
40
- enabled: true,
41
- conditions: [
42
- {
43
- headerName: 'user-agent',
44
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
45
- value: 'Example Rule Value, replace with your own value',
46
- caseSensitive: true,
47
- },
48
- ],
49
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
50
- },
51
- ],
52
- ],
53
- markdownDescription: `Array of **response rules**.\n\nRules served from top to bottom – first matched rule is applied. Each rule is an object with the following properties:\n\n- **name**: Name of the response rule.\n- **description**: Description of the response rule.(Optional) \n- **enabled**: Whether the response rule is enabled. If disabled, the rule will not be applied.\n- **operator**: Operator to use for the rule.\n- **conditions**: Array of conditions to use for the rule.\n- **responseType**: Type of the response.\n\nExamples:\n\n1. Block legacy clients:\n\n\`\`\`json\n${RuleExampleJson}\n\`\`\`\n\nThis example shows how to block requests from legacy clients by checking if the User-Agent header contains "Hiddify" or "FoxRay".`,
14
+ title: 'Response Rules',
15
+ 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\`\`\``,
16
+ defaultSnippets: [],
54
17
  })),
55
18
  });
@@ -0,0 +1,6 @@
1
+ import z from 'zod';
2
+ import { ResponseRuleSchema, ResponseRuleSchemaBase } from './response-rule.schema';
3
+ export declare const EXAMPLES_SRR_BLANK_RULE: z.infer<typeof ResponseRuleSchema>;
4
+ export declare const EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE: z.infer<typeof ResponseRuleSchema>;
5
+ export declare function generateResponseRuleDescription(schema: typeof ResponseRuleSchemaBase): string;
6
+ //# sourceMappingURL=response-rules-examples.d.ts.map
@@ -0,0 +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,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAEpF,eAAO,MAAM,uBAAuB,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAUtE,CAAC;AAEF,eAAO,MAAM,sCAAsC,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAoBrF,CAAC;AAEF,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,OAAO,sBAAsB,UAcpF"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE = exports.EXAMPLES_SRR_BLANK_RULE = void 0;
4
+ exports.generateResponseRuleDescription = generateResponseRuleDescription;
5
+ const constants_1 = require("../../constants");
6
+ exports.EXAMPLES_SRR_BLANK_RULE = {
7
+ name: 'Blank rule',
8
+ description: 'Blank rule',
9
+ operator: 'AND',
10
+ enabled: true,
11
+ conditions: [],
12
+ responseType: 'BLOCK',
13
+ responseModifications: {
14
+ headers: [],
15
+ },
16
+ };
17
+ exports.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE = {
18
+ name: 'Block Legacy Clients',
19
+ description: 'Block requests from legacy clients',
20
+ 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
+ ],
36
+ responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
37
+ };
38
+ function generateResponseRuleDescription(schema) {
39
+ const fields = Object.entries(schema.shape).map(([key, value]) => {
40
+ const desc = value.description ? JSON.parse(value.description) : {};
41
+ return {
42
+ name: key,
43
+ description: desc.markdownDescription || desc.title || 'No description',
44
+ };
45
+ });
46
+ const fieldsText = fields
47
+ .map((field) => `- **${field.name}**: ${field.description}`)
48
+ .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\`\`\``;
50
+ }
@@ -10,6 +10,8 @@ var GetSubscriptionByShortUuidByClientTypeCommand;
10
10
  GetSubscriptionByShortUuidByClientTypeCommand.TSQ_url = GetSubscriptionByShortUuidByClientTypeCommand.url(':shortUuid');
11
11
  GetSubscriptionByShortUuidByClientTypeCommand.RequestSchema = zod_1.z.object({
12
12
  shortUuid: zod_1.z.string(),
13
- clientType: zod_1.z.nativeEnum(constants_1.REQUEST_TEMPLATE_TYPE),
13
+ clientType: zod_1.z.nativeEnum(constants_1.REQUEST_TEMPLATE_TYPE, {
14
+ message: 'Invalid client type.',
15
+ }),
14
16
  });
15
17
  })(GetSubscriptionByShortUuidByClientTypeCommand || (exports.GetSubscriptionByShortUuidByClientTypeCommand = GetSubscriptionByShortUuidByClientTypeCommand = {}));
@@ -28,27 +28,27 @@ exports.RESPONSE_RULES_RESPONSE_TYPES = Object.assign(Object.assign({}, subscrip
28
28
  exports.RESPONSE_RULES_RESPONSE_TYPES_VALUES = Object.values(exports.RESPONSE_RULES_RESPONSE_TYPES);
29
29
  exports.RESPONSE_RULES_CONDITION_OPERATORS_VALUES = Object.values(exports.RESPONSE_RULES_CONDITION_OPERATORS);
30
30
  exports.RESPONSE_RULES_RESPONSE_TYPES_DESCRIPTION = {
31
- [exports.RESPONSE_RULES_RESPONSE_TYPES.BLOCK]: 'Block response type blocks the request and returns a 403 status code.',
32
- [exports.RESPONSE_RULES_RESPONSE_TYPES.XRAY_BASE64]: 'Previously used as fallback response type. It return subscription as base64 encoded string. Compatible with most client application with Xray core.',
33
- [exports.RESPONSE_RULES_RESPONSE_TYPES.STATUS_CODE_404]: 'Status code 404 response type returns a 404 status code. This response type is used to return a 404 status code.',
34
- [exports.RESPONSE_RULES_RESPONSE_TYPES.STATUS_CODE_451]: 'Status code 451 response type returns a 451 status code. This response type is used to return a 451 status code.',
35
- [exports.RESPONSE_RULES_RESPONSE_TYPES.SOCKET_DROP]: 'Socket drop response type drops the socket connection. This response type is used to drop the socket connection.',
36
- [exports.RESPONSE_RULES_RESPONSE_TYPES.CLASH]: 'Useful for client application that use Legacy Clash core. It return subscription as Clash YAML format.',
37
- [exports.RESPONSE_RULES_RESPONSE_TYPES.STASH]: 'Format which is used by Stash client application.',
38
- [exports.RESPONSE_RULES_RESPONSE_TYPES.SINGBOX]: 'Format which is used by Singbox client application.',
39
- [exports.RESPONSE_RULES_RESPONSE_TYPES.MIHOMO]: 'Return subscription as Mihomo Core YAML format.',
40
- [exports.RESPONSE_RULES_RESPONSE_TYPES.XRAY_JSON]: 'Return subscription as Xray JSON format.',
41
- [exports.RESPONSE_RULES_RESPONSE_TYPES.BROWSER]: 'Return subscription as browser format.',
31
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.XRAY_JSON]: 'Return **subscription** in XRAY-JSON format. (Using `Xray Json` template)',
32
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.XRAY_BASE64]: 'Return **subscription** in BASE64 encoded string. Compatible with most client application with Xray core.',
33
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.MIHOMO]: 'Return **subscription** in Mihomo format. (Using `Mihomo` template)',
34
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.STASH]: 'Return **subscription** in Stash format. (Using `Stash` template)',
35
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.CLASH]: 'Return **subscription** in Clash format. (Using `Clash` template) Useful for client application that use Legacy Clash core.',
36
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.SINGBOX]: 'Return **subscription** in Singbox format. (Using `Singbox` template) Format which is used by Singbox client application.',
37
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.BROWSER]: 'Return **subscription** as browser format. The same as on `/info` route.',
38
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.BLOCK]: '**Drop** request and return `403` status code.',
39
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.STATUS_CODE_404]: '**Drop** request and return `404` status code.',
40
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.STATUS_CODE_451]: '**Drop** request and return `451` status code.',
41
+ [exports.RESPONSE_RULES_RESPONSE_TYPES.SOCKET_DROP]: '**Drop** the socket connection.',
42
42
  };
43
43
  exports.RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION = {
44
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.EQUALS]: 'Equals operator checks if the header value exactly matches the specified string, case sensitive. Underlying implementation uses strict string comparison – ===.',
45
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_EQUALS]: 'Not equals operator checks if the header value does not match the specified string, case sensitive. Underlying implementation uses strict string comparison – !==.',
46
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS]: 'Contains operator checks if the header value contains the specified string, case sensitive. Underlying implementation uses string.includes().',
47
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_CONTAINS]: 'Not contains operator checks if the header value does not contain the specified string, case sensitive. Underlying implementation uses string.includes().',
48
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.STARTS_WITH]: 'Starts with operator checks if the header value starts with the specified string, case sensitive. Underlying implementation uses string.startsWith().',
49
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_STARTS_WITH]: 'Not starts with operator checks if the header value does not start with the specified string, case sensitive. Underlying implementation uses string.startsWith().',
50
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.ENDS_WITH]: 'Ends with operator checks if the header value ends with the specified string, case sensitive. Underlying implementation uses string.endsWith().',
51
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_ENDS_WITH]: 'Not ends with operator checks if the header value does not end with the specified string, case sensitive. Underlying implementation uses string.endsWith().',
52
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.REGEX]: 'Regex operator checks if the header value matches the specified regex. Underlying implementation uses regex.test().',
53
- [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_REGEX]: 'Inverse regex operator checks if the header value does not match the specified regex. Underlying implementation uses regex.test().',
44
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.EQUALS]: 'Performs an exact, comparison between the header value and specified string. `string === value`',
45
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_EQUALS]: 'Ensures the header value does not exactly match the specified string. `string !== value`',
46
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS]: 'Checks if the header value contains the specified string as a substring. `string.includes()`',
47
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_CONTAINS]: 'Verifies the header value does not contain the specified string as a substring. `!string.includes()`',
48
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.STARTS_WITH]: 'Validates that the header value begins with the specified string. `string.startsWith()`',
49
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_STARTS_WITH]: 'Validates that the header value does not begin with the specified string. `!string.startsWith()`',
50
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.ENDS_WITH]: 'Confirms the header value ends with the specified string. `string.endsWith()`',
51
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_ENDS_WITH]: 'Confirms the header value does not end with the specified string. `!string.endsWith()`',
52
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.REGEX]: 'Evaluates if the header value matches the specified regular expression pattern. `regex.test()`',
53
+ [exports.RESPONSE_RULES_CONDITION_OPERATORS.NOT_REGEX]: 'Evaluates if the header value does not match the specified regular expression pattern. `!regex.test()`',
54
54
  };
@@ -3,27 +3,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResponseRuleConditionSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const constants_1 = require("../../constants");
6
- exports.ResponseRuleConditionSchema = zod_1.z.object({
6
+ exports.ResponseRuleConditionSchema = zod_1.z
7
+ .object({
7
8
  headerName: zod_1.z
8
9
  .string()
9
10
  .regex(/^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$/, 'Invalid header name. Only letters(a-z, A-Z), numbers(0-9), underscores(_) and hyphens(-) are allowed.')
10
11
  .describe(JSON.stringify({
11
- title: 'Header Name',
12
- markdownDescription: 'Name of the HTTP header to check, case insensitive, must comply with RFC 7230.',
12
+ markdownDescription: '**Name** of the HTTP header to check. Must comply with RFC 7230.',
13
13
  })),
14
14
  operator: zod_1.z.nativeEnum(constants_1.RESPONSE_RULES_CONDITION_OPERATORS).describe(JSON.stringify({
15
- markdownDescription: `Comparison operator to compare the header value against.\n\n${Object.entries(constants_1.RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION)
16
- .map(([key, description]) => `- **${key}**: ${description}\n`)
17
- .join('\n')}`,
15
+ errorMessage: 'Invalid operator. Please select a valid operator.',
16
+ markdownDescription: 'Operator to use for comparing the `headerName` with `value`.',
17
+ markdownEnumDescriptions: Object.entries(constants_1.RESPONSE_RULES_CONDITION_OPERATORS_DESCRIPTION).map(([_key, description]) => description),
18
18
  })),
19
19
  value: zod_1.z
20
20
  .string()
21
21
  .min(1, 'Value is required')
22
22
  .max(255, 'Value must be less than 255 characters')
23
23
  .describe(JSON.stringify({
24
- markdownDescription: `Value to check against the header, case sensitive (excluding regex/not_regex operator). Maximum length is 255 characters.`,
24
+ markdownDescription: `**Value** to check against the **headerName**.`,
25
25
  })),
26
26
  caseSensitive: zod_1.z.boolean().describe(JSON.stringify({
27
- markdownDescription: 'Whether the value is case sensitive. If true, the value will be compared case sensitive. If false, the value will be lowercased before comparison.',
27
+ markdownDescription: 'Whether the value is **case sensitive**. \n\n - `true`: the value will be compared as is. \n\n - `false`: the value will be lowercased **before** comparison.',
28
28
  })),
29
- });
29
+ })
30
+ .describe(JSON.stringify({
31
+ markdownDescription: 'Condition to check against the **headerName**.',
32
+ defaultSnippets: [
33
+ {
34
+ label: 'Examples: Check if header contains "text/html"',
35
+ markdownDescription: 'Condition to check if **headerName** contains "text/html"',
36
+ body: {
37
+ headerName: 'accept',
38
+ operator: 'CONTAINS',
39
+ value: 'text/html',
40
+ caseSensitive: true,
41
+ },
42
+ },
43
+ ],
44
+ }));
@@ -5,44 +5,54 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ResponseRuleModificationsSchema = void 0;
7
7
  const zod_1 = __importDefault(require("zod"));
8
- const exampleJson = JSON.stringify({
9
- headers: [
10
- {
11
- key: 'X-Custom-Header',
12
- value: 'Custom Value',
13
- },
14
- ],
15
- }, null, 2);
16
- const exampleHeaderJson = JSON.stringify([
17
- {
18
- key: 'X-Custom-Header',
19
- value: 'Custom Value',
20
- },
21
- ], null, 2);
22
8
  exports.ResponseRuleModificationsSchema = zod_1.default
23
9
  .object({
24
10
  headers: zod_1.default
25
- .array(zod_1.default.object({
11
+ .array(zod_1.default
12
+ .object({
26
13
  key: zod_1.default
27
14
  .string()
28
15
  .regex(/^[!#$%&'*+\-.0-9A-Z^_`a-z|~]+$/, 'Invalid header name. Only letters(a-z, A-Z), numbers(0-9), underscores(_) and hyphens(-) are allowed.')
29
16
  .describe(JSON.stringify({
30
- title: 'Key',
31
17
  markdownDescription: 'Key of the response header. Must comply with RFC 7230.',
32
18
  })),
33
19
  value: zod_1.default
34
20
  .string()
35
21
  .min(1, 'Value is required')
36
22
  .describe(JSON.stringify({
37
- title: 'Value',
38
23
  markdownDescription: 'Value of the response header. ',
39
24
  })),
40
- }))
25
+ })
26
+ .describe(JSON.stringify({
27
+ markdownDescription: '**Key** and **value** of the response header will be added to the response.',
28
+ })))
41
29
  .describe(JSON.stringify({
42
- markdownDescription: `Array of headers to be added when the rule is matched.\n\nExample:\n\`\`\`json\n${exampleHeaderJson}\n\`\`\``,
30
+ defaultSnippets: [
31
+ {
32
+ label: 'Examples: Add custom header',
33
+ markdownDescription: 'Add a custom header to the response',
34
+ body: [
35
+ {
36
+ key: 'X-Custom-Header',
37
+ value: 'CustomValue',
38
+ },
39
+ ],
40
+ },
41
+ ],
42
+ markdownDescription: 'Array of headers to be added when the rule is matched.',
43
43
  })),
44
44
  })
45
45
  .optional()
46
46
  .describe(JSON.stringify({
47
- markdownDescription: `Response modifications to be applied when the rule is matched.\n\nExample:\n\`\`\`json\n${exampleJson}\n\`\`\``,
47
+ examples: [
48
+ {
49
+ headers: [
50
+ {
51
+ key: 'X-Custom-Header',
52
+ value: 'CustomValue',
53
+ },
54
+ ],
55
+ },
56
+ ],
57
+ markdownDescription: 'Response modifications to be applied when the rule is matched. Optional.',
48
58
  }));
@@ -1,39 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResponseRuleSchema = void 0;
3
+ exports.ResponseRuleSchema = exports.ResponseRuleSchemaBase = void 0;
4
4
  const zod_1 = require("zod");
5
+ const response_rules_examples_1 = require("./response-rules-examples");
5
6
  const constants_1 = require("../../constants");
6
7
  const response_rule_modifications_schema_1 = require("./response-rule-modifications.schema");
7
8
  const response_rule_condition_schema_1 = require("./response-rule-condition.schema");
8
- const RuleExampleJson = JSON.stringify({
9
- name: 'Block Legacy Clients',
10
- description: 'Block requests from legacy clients',
11
- enabled: true,
12
- operator: constants_1.RESPONSE_RULES_OPERATORS.OR,
13
- conditions: [
14
- {
15
- headerName: 'user-agent',
16
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
17
- value: 'Hiddify',
18
- caseSensitive: true,
19
- },
20
- {
21
- headerName: 'user-agent',
22
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
23
- value: 'FoxRay',
24
- caseSensitive: true,
25
- },
26
- ],
27
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
28
- }, null, 2);
29
- exports.ResponseRuleSchema = zod_1.z
30
- .object({
9
+ exports.ResponseRuleSchemaBase = zod_1.z.object({
31
10
  name: zod_1.z
32
11
  .string()
33
12
  .min(1, 'Name is required')
34
13
  .max(50, 'Name must be less than 50 characters')
35
14
  .describe(JSON.stringify({
36
- title: 'Name',
37
15
  markdownDescription: 'Name of the response rule.',
38
16
  })),
39
17
  description: zod_1.z
@@ -42,49 +20,37 @@ exports.ResponseRuleSchema = zod_1.z
42
20
  .max(250, 'Description must be less than 250 characters')
43
21
  .optional()
44
22
  .describe(JSON.stringify({
45
- title: 'Description',
46
- markdownDescription: 'Description of the response rule. Maximum length is 250 characters.',
23
+ markdownDescription: 'Description of the response rule. Optional.',
47
24
  })),
48
25
  enabled: zod_1.z.boolean().describe(JSON.stringify({
49
- markdownDescription: 'Whether the response rule is enabled. If disabled, the rule will not be applied.',
26
+ 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.',
50
27
  })),
51
28
  operator: zod_1.z.nativeEnum(constants_1.RESPONSE_RULES_OPERATORS).describe(JSON.stringify({
52
- title: 'Operator',
53
29
  markdownDescription: 'Operator to use for combining conditions in the rule.',
54
30
  })),
55
- conditions: zod_1.z.array(response_rule_condition_schema_1.ResponseRuleConditionSchema),
31
+ conditions: zod_1.z.array(response_rule_condition_schema_1.ResponseRuleConditionSchema).describe(JSON.stringify({
32
+ markdownDescription: 'Array of conditions to check against the request headers. Conditions are applied with **operator**. If conditions are empty, the rule will be matched.',
33
+ })),
56
34
  responseType: zod_1.z.nativeEnum(constants_1.RESPONSE_RULES_RESPONSE_TYPES).describe(JSON.stringify({
57
- markdownDescription: `Type of the response. Determines the type of **response** to be returned when the rule is matched.\n\n${Object.entries(constants_1.RESPONSE_RULES_RESPONSE_TYPES_DESCRIPTION)
58
- .map(([key, description]) => `- **${key}**: ${description}\n`)
59
- .join('\n')}`,
35
+ errorMessage: 'Invalid response type. Please select a valid response type.',
36
+ markdownDescription: `Type of the response. Determines the type of **response** to be returned when the rule is matched.`,
37
+ markdownEnumDescriptions: Object.entries(constants_1.RESPONSE_RULES_RESPONSE_TYPES_DESCRIPTION).map(([_key, description]) => description),
60
38
  })),
61
39
  responseModifications: response_rule_modifications_schema_1.ResponseRuleModificationsSchema,
62
- })
63
- .describe(JSON.stringify({
64
- title: 'Response Rule',
65
- markdownDescription: `\n\nFields:\n- **name**: Name of the response rule (required)\n- **description**: Description of the response rule (optional)\n- **enabled**: Whether the response rule is enabled. If disabled, the rule will not be applied.\n- **operator**: Operator to combine conditions (AND/OR)\n- **conditions**: Array of conditions to match against HTTP headers\n - **headerName**: Name of the HTTP header to check (case insensitive)\n - **operator**: Comparison operator (CONTAINS, EQUALS, etc)\n - **value**: Value to compare against (case sensitive, max 255 chars)\n- **responseType**: Type of response when rule matches (e.g. BLOCK)\n\nExample:\n\`\`\`json\n${RuleExampleJson}\n\`\`\``,
66
- examples: [
40
+ });
41
+ exports.ResponseRuleSchema = exports.ResponseRuleSchemaBase.describe(JSON.stringify({
42
+ defaultSnippets: [
67
43
  {
68
- name: 'This is example rule name',
69
- description: 'This is example rule description (optional)',
70
- enabled: true,
71
- operator: constants_1.RESPONSE_RULES_OPERATORS.AND,
72
- conditions: [
73
- {
74
- headerName: 'user-agent',
75
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
76
- value: 'Example Rule Value, replace with your own value',
77
- caseSensitive: true,
78
- },
79
- ],
80
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
44
+ label: 'Examples: Blank rule',
45
+ markdownDescription: `Simple blank rule with no conditions or modifications.\n\`\`\`json\n${JSON.stringify(response_rules_examples_1.EXAMPLES_SRR_BLANK_RULE, null, 2)}\n\`\`\``,
46
+ body: Object.assign({}, response_rules_examples_1.EXAMPLES_SRR_BLANK_RULE),
81
47
  },
82
48
  {
83
- name: 'Empty rule',
84
- enabled: true,
85
- operator: constants_1.RESPONSE_RULES_OPERATORS.AND,
86
- conditions: [],
87
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
49
+ label: 'Examples: Block Legacy Clients',
50
+ markdownDescription: `Block requests from legacy clients\n\`\`\`json\n${JSON.stringify(response_rules_examples_1.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE, null, 2)}\n\`\`\``,
51
+ body: Object.assign({}, response_rules_examples_1.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE),
88
52
  },
89
53
  ],
54
+ title: 'Response Rule',
55
+ markdownDescription: (0, response_rules_examples_1.generateResponseRuleDescription)(exports.ResponseRuleSchemaBase),
90
56
  }));
@@ -2,54 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ResponseRulesConfigSchema = void 0;
4
4
  const zod_1 = require("zod");
5
+ const response_rules_examples_1 = require("./response-rules-examples");
5
6
  const constants_1 = require("../../constants");
6
7
  const response_rule_schema_1 = require("./response-rule.schema");
7
- const RuleExampleJson = JSON.stringify({
8
- name: 'Block Legacy Clients',
9
- description: 'Block requests from legacy clients',
10
- operator: constants_1.RESPONSE_RULES_OPERATORS.OR,
11
- enabled: true,
12
- conditions: [
13
- {
14
- headerName: 'user-agent',
15
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
16
- value: 'Hiddify',
17
- caseSensitive: true,
18
- },
19
- {
20
- headerName: 'user-agent',
21
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
22
- value: 'FoxRay',
23
- caseSensitive: true,
24
- },
25
- ],
26
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
27
- }, null, 2);
28
8
  exports.ResponseRulesConfigSchema = zod_1.z.object({
29
9
  version: zod_1.z.nativeEnum(constants_1.RESPONSE_RULES_CONFIG_VERSION).describe(JSON.stringify({
30
10
  title: 'Response Rules Config Version',
31
11
  markdownDescription: 'Version of the **response rules** config. Currently supported version is **1**.',
32
12
  })),
33
13
  rules: zod_1.z.array(response_rule_schema_1.ResponseRuleSchema).describe(JSON.stringify({
34
- examples: [
35
- [
36
- {
37
- name: 'This is example rule name',
38
- description: 'This is example rule description (optional)',
39
- operator: constants_1.RESPONSE_RULES_OPERATORS.AND,
40
- enabled: true,
41
- conditions: [
42
- {
43
- headerName: 'user-agent',
44
- operator: constants_1.RESPONSE_RULES_CONDITION_OPERATORS.CONTAINS,
45
- value: 'Example Rule Value, replace with your own value',
46
- caseSensitive: true,
47
- },
48
- ],
49
- responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
50
- },
51
- ],
52
- ],
53
- markdownDescription: `Array of **response rules**.\n\nRules served from top to bottom – first matched rule is applied. Each rule is an object with the following properties:\n\n- **name**: Name of the response rule.\n- **description**: Description of the response rule.(Optional) \n- **enabled**: Whether the response rule is enabled. If disabled, the rule will not be applied.\n- **operator**: Operator to use for the rule.\n- **conditions**: Array of conditions to use for the rule.\n- **responseType**: Type of the response.\n\nExamples:\n\n1. Block legacy clients:\n\n\`\`\`json\n${RuleExampleJson}\n\`\`\`\n\nThis example shows how to block requests from legacy clients by checking if the User-Agent header contains "Hiddify" or "FoxRay".`,
14
+ title: 'Response Rules',
15
+ 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\`\`\``,
16
+ defaultSnippets: [],
54
17
  })),
55
18
  });
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE = exports.EXAMPLES_SRR_BLANK_RULE = void 0;
4
+ exports.generateResponseRuleDescription = generateResponseRuleDescription;
5
+ const constants_1 = require("../../constants");
6
+ exports.EXAMPLES_SRR_BLANK_RULE = {
7
+ name: 'Blank rule',
8
+ description: 'Blank rule',
9
+ operator: 'AND',
10
+ enabled: true,
11
+ conditions: [],
12
+ responseType: 'BLOCK',
13
+ responseModifications: {
14
+ headers: [],
15
+ },
16
+ };
17
+ exports.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE = {
18
+ name: 'Block Legacy Clients',
19
+ description: 'Block requests from legacy clients',
20
+ 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
+ ],
36
+ responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
37
+ };
38
+ function generateResponseRuleDescription(schema) {
39
+ const fields = Object.entries(schema.shape).map(([key, value]) => {
40
+ const desc = value.description ? JSON.parse(value.description) : {};
41
+ return {
42
+ name: key,
43
+ description: desc.markdownDescription || desc.title || 'No description',
44
+ };
45
+ });
46
+ const fieldsText = fields
47
+ .map((field) => `- **${field.name}**: ${field.description}`)
48
+ .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\`\`\``;
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnawave/backend-contract",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "public": true,
5
5
  "license": "AGPL-3.0-only",
6
6
  "description": "A contract library for Remnawave Backend. It can be used in backend and frontend.",