@remnawave/backend-contract 2.9.32 → 2.9.33

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 +25 -3
  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 +50 -6
  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 +47 -5
  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 +3 -23
  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 +3 -22
  10. package/build/backend/models/response-rules/index.d.ts +0 -2
  11. package/build/backend/models/response-rules/index.d.ts.map +1 -1
  12. package/build/backend/models/response-rules/index.js +0 -2
  13. package/build/backend/models/response-rules/response-rule-condition.schema.d.ts +3 -40
  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 +6 -156
  16. package/build/backend/models/response-rules/response-rule.schema.d.ts +44 -4
  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 +10 -26
  19. package/build/backend/models/response-rules/response-rules-config.schema.d.ts +25 -3
  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 +4 -9
  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 +22 -30
  25. package/build/backend/models/subscription-settings.schema.d.ts +25 -3
  26. package/build/backend/models/subscription-settings.schema.d.ts.map +1 -1
  27. package/build/frontend/constants/response-rules/response-rules.contants.js +3 -22
  28. package/build/frontend/models/response-rules/index.js +0 -2
  29. package/build/frontend/models/response-rules/response-rule-condition.schema.js +6 -156
  30. package/build/frontend/models/response-rules/response-rule.schema.js +10 -26
  31. package/build/frontend/models/response-rules/response-rules-config.schema.js +4 -9
  32. package/build/frontend/models/response-rules/response-rules-examples.js +22 -30
  33. package/package.json +1 -1
  34. package/build/backend/models/response-rules/response-rules-legacy.schema.d.ts +0 -157
  35. package/build/backend/models/response-rules/response-rules-legacy.schema.d.ts.map +0 -1
  36. package/build/backend/models/response-rules/response-rules-legacy.schema.js +0 -33
  37. package/build/backend/models/response-rules/response-rules-migration.d.ts +0 -10
  38. package/build/backend/models/response-rules/response-rules-migration.d.ts.map +0 -1
  39. package/build/backend/models/response-rules/response-rules-migration.js +0 -45
  40. package/build/frontend/models/response-rules/response-rules-legacy.schema.js +0 -33
  41. package/build/frontend/models/response-rules/response-rules-migration.js +0 -45
@@ -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.strictObject({
9
+ exports.ResponseRuleSchemaBase = zod_1.z.object({
10
10
  name: zod_1.z
11
11
  .string()
12
12
  .min(1, 'Name is required')
@@ -28,28 +28,12 @@ exports.ResponseRuleSchemaBase = zod_1.z.strictObject({
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
- 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.',
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.',
53
37
  }),
54
38
  responseType: zod_1.z.enum(constants_1.RESPONSE_RULES_RESPONSE_TYPES).meta({
55
39
  errorMessage: 'Invalid response type. Please select a valid response type.',
@@ -70,10 +54,10 @@ exports.ResponseRuleSchema = exports.ResponseRuleSchemaBase.meta({
70
54
  },
71
55
  },
72
56
  {
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\`\`\``,
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\`\`\``,
75
59
  body: {
76
- ...response_rules_examples_1.EXAMPLES_SRR_NESTED_CONDITIONS_RULE,
60
+ ...response_rules_examples_1.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE,
77
61
  },
78
62
  },
79
63
  ],
@@ -6,20 +6,15 @@ const constants_1 = require("../../constants");
6
6
  const response_rule_settings_schema_1 = require("./response-rule-settings.schema");
7
7
  const response_rule_schema_1 = require("./response-rule.schema");
8
8
  const response_rules_examples_1 = require("./response-rules-examples");
9
- exports.ResponseRulesConfigSchema = zod_1.z
10
- .object({
11
- version: zod_1.z.literal(constants_1.RESPONSE_RULES_CONFIG_VERSION[2]).meta({
9
+ exports.ResponseRulesConfigSchema = zod_1.z.object({
10
+ version: zod_1.z.enum(constants_1.RESPONSE_RULES_CONFIG_VERSION).meta({
12
11
  title: 'Response Rules Config Version',
13
- markdownDescription: 'Version of the **response rules** config. Currently supported version is **2**. Legacy version **1** configs can be migrated with `migrateResponseRulesConfig`.',
12
+ markdownDescription: 'Version of the **response rules** config. Currently supported version is **1**.',
14
13
  }),
15
14
  settings: response_rule_settings_schema_1.ResponseRuleSettingsSchema,
16
15
  rules: zod_1.z.array(response_rule_schema_1.ResponseRuleSchema).meta({
17
16
  title: 'Response Rules',
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\`\`\``,
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\`\`\``,
19
18
  defaultSnippets: [],
20
19
  }),
21
- })
22
- .meta({
23
- title: 'Response Rules Config',
24
- markdownDescription: 'Configuration of the **response rules**.',
25
20
  });
@@ -1,46 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EXAMPLES_SRR_NESTED_CONDITIONS_RULE = exports.EXAMPLES_SRR_BLANK_RULE = void 0;
3
+ exports.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_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',
9
10
  enabled: true,
11
+ conditions: [],
10
12
  responseType: 'BLOCK',
11
13
  responseModifications: {
12
14
  headers: [],
13
15
  },
14
16
  };
15
- exports.EXAMPLES_SRR_NESTED_CONDITIONS_RULE = {
16
- name: 'Block Legacy Browsers',
17
- description: 'Block browser requests from legacy clients',
17
+ exports.EXAMPLES_SRR_BLOCK_LEGACY_CLIENTS_RULE = {
18
+ name: 'Block Legacy Clients',
19
+ description: 'Block requests from legacy clients',
18
20
  enabled: true,
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
- },
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
+ ],
44
36
  responseType: constants_1.RESPONSE_RULES_RESPONSE_TYPES.BLOCK,
45
37
  };
46
38
  function generateResponseRuleDescription(schema) {
@@ -54,5 +46,5 @@ function generateResponseRuleDescription(schema) {
54
46
  const fieldsText = fields
55
47
  .map((field) => `- **${field.name}**: ${field.description}`)
56
48
  .join('\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\`\`\``;
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\`\`\``;
58
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnawave/backend-contract",
3
- "version": "2.9.32",
3
+ "version": "2.9.33",
4
4
  "description": "A contract library for Remnawave Backend. It can be used in backend and frontend.",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/remnawave",
@@ -1,157 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,33 +0,0 @@
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
- });
@@ -1,10 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,45 +0,0 @@
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
- }
@@ -1,33 +0,0 @@
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
- });
@@ -1,45 +0,0 @@
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
- }