@wallarm-org/design-system 4.7.0 → 4.8.0-rc-feat-parser.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DropdownMenu/DropdownMenu.d.ts +2 -0
- package/dist/components/DropdownMenu/DropdownMenu.js +84 -71
- package/dist/components/DropdownMenu/DropdownMenuItemDescription.js +1 -1
- package/dist/components/FilterInput/hooks/useFilterInputAutocomplete/useFilterInputAutocomplete.js +1 -1
- package/dist/components/Rules/PointSelector/KeyboardShortcutsDialog.d.ts +14 -0
- package/dist/components/Rules/PointSelector/KeyboardShortcutsDialog.js +209 -0
- package/dist/components/Rules/PointSelector/MatchStep.d.ts +15 -0
- package/dist/components/Rules/PointSelector/MatchStep.js +186 -0
- package/dist/components/Rules/PointSelector/MenuFooterHints.d.ts +16 -0
- package/dist/components/Rules/PointSelector/MenuFooterHints.js +177 -0
- package/dist/components/Rules/PointSelector/PointPreview.d.ts +10 -0
- package/dist/components/Rules/PointSelector/PointPreview.js +88 -0
- package/dist/components/Rules/PointSelector/PointSelector.d.ts +17 -0
- package/dist/components/Rules/PointSelector/PointSelector.js +937 -0
- package/dist/components/Rules/PointSelector/PointSelectorEmptyState.d.ts +12 -0
- package/dist/components/Rules/PointSelector/PointSelectorEmptyState.js +173 -0
- package/dist/components/Rules/PointSelector/PointSelectorError.d.ts +31 -0
- package/dist/components/Rules/PointSelector/PointSelectorError.js +275 -0
- package/dist/components/Rules/PointSelector/PointSelectorInput.d.ts +20 -0
- package/dist/components/Rules/PointSelector/PointSelectorInput.js +130 -0
- package/dist/components/Rules/PointSelector/PointSelectorMenu.d.ts +31 -0
- package/dist/components/Rules/PointSelector/PointSelectorMenu.js +317 -0
- package/dist/components/Rules/PointSelector/PointSelectorSkeleton.d.ts +8 -0
- package/dist/components/Rules/PointSelector/PointSelectorSkeleton.js +73 -0
- package/dist/components/Rules/PointSelector/SampleRequest.d.ts +14 -0
- package/dist/components/Rules/PointSelector/SampleRequest.js +116 -0
- package/dist/components/Rules/PointSelector/StepMenu.d.ts +40 -0
- package/dist/components/Rules/PointSelector/StepMenu.js +210 -0
- package/dist/components/Rules/PointSelector/VersionWarning.d.ts +26 -0
- package/dist/components/Rules/PointSelector/VersionWarning.js +231 -0
- package/dist/components/Rules/PointSelector/WhereBar.d.ts +48 -0
- package/dist/components/Rules/PointSelector/WhereBar.js +263 -0
- package/dist/components/Rules/PointSelector/classes.d.ts +28 -0
- package/dist/components/Rules/PointSelector/classes.js +22 -0
- package/dist/components/Rules/PointSelector/index.d.ts +20 -0
- package/dist/components/Rules/PointSelector/index.js +18 -0
- package/dist/components/Rules/PointSelector/liftLayer.d.ts +8 -0
- package/dist/components/Rules/PointSelector/liftLayer.js +4 -0
- package/dist/components/Rules/PointSelector/sampleValue.d.ts +6 -0
- package/dist/components/Rules/PointSelector/sampleValue.js +51 -0
- package/dist/components/Rules/PointSelector/sdkBridge.d.ts +508 -0
- package/dist/components/Rules/PointSelector/sdkBridge.js +339 -0
- package/dist/components/Rules/PointSelector/types.d.ts +304 -0
- package/dist/components/Rules/PointSelector/types.js +0 -0
- package/dist/components/Rules/PointSelector/usePointSelector.d.ts +161 -0
- package/dist/components/Rules/PointSelector/usePointSelector.js +1088 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/ActionEditor.d.ts +28 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/ActionEditor.js +208 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/ActionFields.d.ts +23 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/ActionFields.js +950 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTargetPicker.d.ts +21 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTargetPicker.js +110 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTypeSelect.d.ts +20 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTypeSelect.js +31 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/AttackTypeField.d.ts +23 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/AttackTypeField.js +131 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/classes.d.ts +17 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/classes.js +14 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/index.d.ts +6 -0
- package/dist/components/Rules/RuleBuilder/ActionEditor/index.js +6 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/AddConditionMenu.d.ts +24 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/AddConditionMenu.js +245 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/AttackCondition.d.ts +15 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/AttackCondition.js +691 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionCard.d.ts +19 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionCard.js +72 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionTree.d.ts +27 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionTree.js +407 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/FieldCondition.d.ts +14 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/FieldCondition.js +269 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/GroupCondition.d.ts +25 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/GroupCondition.js +99 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/SampleCondition.d.ts +14 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/SampleCondition.js +118 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/SignalCondition.d.ts +14 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/SignalCondition.js +446 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/TagCondition.d.ts +14 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/TagCondition.js +266 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/classes.d.ts +35 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/classes.js +57 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/index.d.ts +15 -0
- package/dist/components/Rules/RuleBuilder/ConditionTree/index.js +10 -0
- package/dist/components/Rules/RuleBuilder/RuleBuilder.d.ts +67 -0
- package/dist/components/Rules/RuleBuilder/RuleBuilder.js +366 -0
- package/dist/components/Rules/RuleBuilder/Summary/ActionSummary.d.ts +32 -0
- package/dist/components/Rules/RuleBuilder/Summary/ActionSummary.js +420 -0
- package/dist/components/Rules/RuleBuilder/Summary/ConditionSummary.d.ts +27 -0
- package/dist/components/Rules/RuleBuilder/Summary/ConditionSummary.js +446 -0
- package/dist/components/Rules/RuleBuilder/Summary/index.d.ts +7 -0
- package/dist/components/Rules/RuleBuilder/Summary/index.js +2 -0
- package/dist/components/Rules/RuleBuilder/classes.d.ts +19 -0
- package/dist/components/Rules/RuleBuilder/classes.js +18 -0
- package/dist/components/Rules/RuleBuilder/index.d.ts +55 -0
- package/dist/components/Rules/RuleBuilder/index.js +11 -0
- package/dist/components/Rules/RuleBuilder/models/actionModel.d.ts +31 -0
- package/dist/components/Rules/RuleBuilder/models/actionModel.js +276 -0
- package/dist/components/Rules/RuleBuilder/models/conditionModel.d.ts +95 -0
- package/dist/components/Rules/RuleBuilder/models/conditionModel.js +418 -0
- package/dist/components/Rules/RuleBuilder/models/index.d.ts +3 -0
- package/dist/components/Rules/RuleBuilder/models/index.js +3 -0
- package/dist/components/Rules/RuleBuilder/models/validation.d.ts +176 -0
- package/dist/components/Rules/RuleBuilder/models/validation.js +242 -0
- package/dist/components/Rules/RuleBuilder/shared/ChoiceSelect.d.ts +27 -0
- package/dist/components/Rules/RuleBuilder/shared/ChoiceSelect.js +92 -0
- package/dist/components/Rules/RuleBuilder/shared/index.d.ts +1 -0
- package/dist/components/Rules/RuleBuilder/shared/index.js +1 -0
- package/dist/components/Rules/RuleBuilder/types.d.ts +384 -0
- package/dist/components/Rules/RuleBuilder/types.js +0 -0
- package/dist/components/Rules/RuleBuilder/utils/constants.d.ts +65 -0
- package/dist/components/Rules/RuleBuilder/utils/constants.js +356 -0
- package/dist/components/Rules/RuleBuilder/utils/extractBindings.d.ts +48 -0
- package/dist/components/Rules/RuleBuilder/utils/extractBindings.js +42 -0
- package/dist/components/Rules/RuleBuilder/utils/helpers.d.ts +92 -0
- package/dist/components/Rules/RuleBuilder/utils/helpers.js +54 -0
- package/dist/components/Rules/RuleBuilder/utils/index.d.ts +2 -0
- package/dist/components/Rules/RuleBuilder/utils/index.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/metadata/components.json +100 -2
- package/package.json +4 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { pointOf } from "../../PointSelector/sdkBridge.js";
|
|
2
|
+
import { DEFAULT_SEPARATOR, TARGET_REQUIREMENT } from "../utils/constants.js";
|
|
3
|
+
const WHOLE_REQUEST = {
|
|
4
|
+
whole: true,
|
|
5
|
+
context: 'http_request',
|
|
6
|
+
segments: []
|
|
7
|
+
};
|
|
8
|
+
function newAction(kind = 'add_attack') {
|
|
9
|
+
const targetType = TARGET_REQUIREMENT[kind];
|
|
10
|
+
const needsPoint = 'point' === targetType;
|
|
11
|
+
return {
|
|
12
|
+
kind,
|
|
13
|
+
attackType: '',
|
|
14
|
+
comment: '',
|
|
15
|
+
experimental: false,
|
|
16
|
+
tagKey: '',
|
|
17
|
+
tagValue: '',
|
|
18
|
+
separator: DEFAULT_SEPARATOR,
|
|
19
|
+
limit: '',
|
|
20
|
+
softLimit: '',
|
|
21
|
+
hardLimit: '',
|
|
22
|
+
priority: '',
|
|
23
|
+
parsers: [],
|
|
24
|
+
parser: '',
|
|
25
|
+
ruleIds: [],
|
|
26
|
+
target: needsPoint ? {
|
|
27
|
+
...WHOLE_REQUEST,
|
|
28
|
+
whole: false
|
|
29
|
+
} : WHOLE_REQUEST
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function targetToProton(target, proton) {
|
|
33
|
+
let point;
|
|
34
|
+
point = target.whole ? 'flow' : target.canonical ? target.canonical : pointOf(target.segments, proton);
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
context: target.context,
|
|
38
|
+
point
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
function priorityOf(draft) {
|
|
43
|
+
const trimmed = draft.priority?.trim() ?? '';
|
|
44
|
+
if ('' !== trimmed && Number.isInteger(Number(trimmed))) return {
|
|
45
|
+
priority: Number(trimmed)
|
|
46
|
+
};
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
function bindingFields(draft) {
|
|
50
|
+
const result = {};
|
|
51
|
+
if (draft.attackRef) result.attack_ref = draft.attackRef;
|
|
52
|
+
if (draft.targetRef) result.target_ref = draft.targetRef;
|
|
53
|
+
if (draft.targetRole) result.target_role = draft.targetRole;
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function toProtonAction(draft, proton) {
|
|
57
|
+
const target = targetToProton(draft.target, proton);
|
|
58
|
+
switch(draft.kind){
|
|
59
|
+
case 'raw':
|
|
60
|
+
return draft.raw ?? {};
|
|
61
|
+
case 'add_attack':
|
|
62
|
+
{
|
|
63
|
+
const action = {
|
|
64
|
+
action_type: 'add_attack',
|
|
65
|
+
target,
|
|
66
|
+
attack: {
|
|
67
|
+
attack_type: draft.attackType ?? ''
|
|
68
|
+
},
|
|
69
|
+
...bindingFields(draft)
|
|
70
|
+
};
|
|
71
|
+
if (draft.comment?.trim()) action.attack.comment = draft.comment.trim();
|
|
72
|
+
if (draft.known) action.attack.known = draft.known;
|
|
73
|
+
if (draft.knownFalse) action.attack.known_false = draft.knownFalse;
|
|
74
|
+
if (draft.experimental) action.experimental = true;
|
|
75
|
+
return action;
|
|
76
|
+
}
|
|
77
|
+
case 'add_tag':
|
|
78
|
+
{
|
|
79
|
+
const action = {
|
|
80
|
+
action_type: 'add_tag',
|
|
81
|
+
target,
|
|
82
|
+
tag: {
|
|
83
|
+
key: draft.tagKey ?? '',
|
|
84
|
+
value: draft.tagValue ?? ''
|
|
85
|
+
},
|
|
86
|
+
...bindingFields(draft)
|
|
87
|
+
};
|
|
88
|
+
if (draft.experimental) action.experimental = true;
|
|
89
|
+
return action;
|
|
90
|
+
}
|
|
91
|
+
case 'suppress_attack':
|
|
92
|
+
{
|
|
93
|
+
const action = {
|
|
94
|
+
action_type: 'suppress_attack',
|
|
95
|
+
target,
|
|
96
|
+
...bindingFields(draft)
|
|
97
|
+
};
|
|
98
|
+
if (draft.attackType?.trim()) action.attack = {
|
|
99
|
+
attack_type: draft.attackType.trim()
|
|
100
|
+
};
|
|
101
|
+
return action;
|
|
102
|
+
}
|
|
103
|
+
case 'mark_attack':
|
|
104
|
+
{
|
|
105
|
+
const action = {
|
|
106
|
+
action_type: 'mark_attack',
|
|
107
|
+
target,
|
|
108
|
+
...bindingFields(draft)
|
|
109
|
+
};
|
|
110
|
+
if (void 0 !== draft.experimental) action.experimental = draft.experimental;
|
|
111
|
+
if (draft.attackType?.trim() || draft.known || draft.knownFalse) {
|
|
112
|
+
action.attack = {};
|
|
113
|
+
if (draft.attackType?.trim()) action.attack.attack_type = draft.attackType.trim();
|
|
114
|
+
if (draft.known) action.attack.known = draft.known;
|
|
115
|
+
if (draft.knownFalse) action.attack.known_false = draft.knownFalse;
|
|
116
|
+
}
|
|
117
|
+
return action;
|
|
118
|
+
}
|
|
119
|
+
case 'combine':
|
|
120
|
+
return {
|
|
121
|
+
action_type: 'combine',
|
|
122
|
+
target,
|
|
123
|
+
separator: draft.separator ?? DEFAULT_SEPARATOR,
|
|
124
|
+
...bindingFields(draft)
|
|
125
|
+
};
|
|
126
|
+
case 'processing_time_limit':
|
|
127
|
+
return {
|
|
128
|
+
action_type: 'processing_time_limit',
|
|
129
|
+
target: targetToProton(WHOLE_REQUEST, proton),
|
|
130
|
+
limit: draft.limit?.trim() ?? '',
|
|
131
|
+
...priorityOf(draft)
|
|
132
|
+
};
|
|
133
|
+
case 'processing_space_limit':
|
|
134
|
+
return {
|
|
135
|
+
action_type: 'processing_space_limit',
|
|
136
|
+
target: targetToProton(WHOLE_REQUEST, proton),
|
|
137
|
+
limit: draft.limit?.trim() ?? '',
|
|
138
|
+
...priorityOf(draft)
|
|
139
|
+
};
|
|
140
|
+
case 'entry_limits':
|
|
141
|
+
{
|
|
142
|
+
const action = {
|
|
143
|
+
action_type: 'entry_limits',
|
|
144
|
+
target,
|
|
145
|
+
...priorityOf(draft),
|
|
146
|
+
...bindingFields(draft)
|
|
147
|
+
};
|
|
148
|
+
if (draft.softLimit?.trim()) action.entry_size_soft_limit = draft.softLimit.trim();
|
|
149
|
+
if (draft.hardLimit?.trim()) action.entry_size_hard_limit = draft.hardLimit.trim();
|
|
150
|
+
return action;
|
|
151
|
+
}
|
|
152
|
+
case 'disable_parsers':
|
|
153
|
+
return {
|
|
154
|
+
action_type: 'disable_parsers',
|
|
155
|
+
target,
|
|
156
|
+
parsers: draft.parsers ?? [],
|
|
157
|
+
...priorityOf(draft),
|
|
158
|
+
...bindingFields(draft)
|
|
159
|
+
};
|
|
160
|
+
case 'allow_parsers':
|
|
161
|
+
return {
|
|
162
|
+
action_type: 'allow_parsers',
|
|
163
|
+
target,
|
|
164
|
+
parsers: draft.parsers ?? [],
|
|
165
|
+
...priorityOf(draft),
|
|
166
|
+
...bindingFields(draft)
|
|
167
|
+
};
|
|
168
|
+
case 'force_parser':
|
|
169
|
+
return {
|
|
170
|
+
action_type: 'force_parser',
|
|
171
|
+
target,
|
|
172
|
+
parser: draft.parser ?? '',
|
|
173
|
+
...priorityOf(draft),
|
|
174
|
+
...bindingFields(draft)
|
|
175
|
+
};
|
|
176
|
+
case 'disable_rule':
|
|
177
|
+
return {
|
|
178
|
+
action_type: 'disable_rule',
|
|
179
|
+
rule_ids: draft.ruleIds ?? []
|
|
180
|
+
};
|
|
181
|
+
default:
|
|
182
|
+
return {
|
|
183
|
+
action_type: 'unknown',
|
|
184
|
+
target
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function segmentsOfPoint(point, context, proton) {
|
|
189
|
+
if (!point) return [];
|
|
190
|
+
if (!proton) return [];
|
|
191
|
+
try {
|
|
192
|
+
const result = proton.point.parse(point);
|
|
193
|
+
return result;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
console.warn('Failed to parse canonical point string with SDK', {
|
|
196
|
+
point,
|
|
197
|
+
error: error instanceof Error ? error.message : String(error)
|
|
198
|
+
});
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function parseTarget(target, proton) {
|
|
203
|
+
const context = target?.context ?? 'http_request';
|
|
204
|
+
const point = target?.point ?? 'flow';
|
|
205
|
+
if ('flow' === point) return WHOLE_REQUEST;
|
|
206
|
+
const segments = segmentsOfPoint(point, context, proton);
|
|
207
|
+
const currentVersion = proton ? proton.version().canonical : void 0;
|
|
208
|
+
return {
|
|
209
|
+
whole: false,
|
|
210
|
+
context,
|
|
211
|
+
segments,
|
|
212
|
+
canonical: point,
|
|
213
|
+
canonicalVersion: currentVersion
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const KNOWN_KINDS = [
|
|
217
|
+
'add_attack',
|
|
218
|
+
'add_tag',
|
|
219
|
+
'suppress_attack',
|
|
220
|
+
'mark_attack',
|
|
221
|
+
'combine',
|
|
222
|
+
'processing_time_limit',
|
|
223
|
+
'processing_space_limit',
|
|
224
|
+
'entry_limits',
|
|
225
|
+
'disable_parsers',
|
|
226
|
+
'allow_parsers',
|
|
227
|
+
'force_parser',
|
|
228
|
+
'disable_rule'
|
|
229
|
+
];
|
|
230
|
+
function fromProtonAction(action, proton = null) {
|
|
231
|
+
const obj = Array.isArray(action) ? action[0] : action;
|
|
232
|
+
const raw = ()=>({
|
|
233
|
+
...newAction(),
|
|
234
|
+
kind: 'raw',
|
|
235
|
+
raw: obj ?? {}
|
|
236
|
+
});
|
|
237
|
+
if (!obj || 'object' != typeof obj) return raw();
|
|
238
|
+
const kind = obj.action_type;
|
|
239
|
+
if (!kind || !KNOWN_KINDS.includes(kind)) return raw();
|
|
240
|
+
if ('disable_rule' === kind) {
|
|
241
|
+
const ruleIds = Array.isArray(obj.rule_ids) ? obj.rule_ids : [];
|
|
242
|
+
return {
|
|
243
|
+
...newAction(kind),
|
|
244
|
+
ruleIds: ruleIds.map((id)=>String(id))
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
if (!Array.isArray(obj.target) || 1 !== obj.target.length) return raw();
|
|
248
|
+
const target = parseTarget(obj.target[0], proton);
|
|
249
|
+
const attack = obj.attack ?? {};
|
|
250
|
+
const tag = obj.tag ?? {};
|
|
251
|
+
const draft = {
|
|
252
|
+
...newAction(kind),
|
|
253
|
+
attackType: 'string' == typeof attack.attack_type ? attack.attack_type : '',
|
|
254
|
+
comment: 'string' == typeof attack.comment ? attack.comment : '',
|
|
255
|
+
experimental: true === obj.experimental,
|
|
256
|
+
tagKey: tag.key ?? '',
|
|
257
|
+
tagValue: tag.value ?? '',
|
|
258
|
+
separator: 'string' == typeof obj.separator ? obj.separator : DEFAULT_SEPARATOR,
|
|
259
|
+
limit: 'string' == typeof obj.limit ? obj.limit : '',
|
|
260
|
+
softLimit: 'string' == typeof obj.entry_size_soft_limit ? obj.entry_size_soft_limit : '',
|
|
261
|
+
hardLimit: 'string' == typeof obj.entry_size_hard_limit ? obj.entry_size_hard_limit : '',
|
|
262
|
+
priority: 'number' == typeof obj.priority ? String(obj.priority) : '',
|
|
263
|
+
target
|
|
264
|
+
};
|
|
265
|
+
if (attack.known && 'object' == typeof attack.known) draft.known = attack.known;
|
|
266
|
+
if (void 0 !== attack.known_false) draft.knownFalse = attack.known_false;
|
|
267
|
+
if ('string' == typeof obj.attack_ref) draft.attackRef = obj.attack_ref;
|
|
268
|
+
if ('string' == typeof obj.target_ref) draft.targetRef = obj.target_ref;
|
|
269
|
+
if ('string' == typeof obj.target_role) draft.targetRole = obj.target_role;
|
|
270
|
+
if ('disable_parsers' === kind || 'allow_parsers' === kind) if ('string' == typeof obj.parsers) draft.parsers = obj.parsers;
|
|
271
|
+
else if (Array.isArray(obj.parsers)) draft.parsers = obj.parsers.map((p)=>String(p));
|
|
272
|
+
else draft.parsers = [];
|
|
273
|
+
if ('force_parser' === kind) draft.parser = 'string' == typeof obj.parser ? obj.parser : '';
|
|
274
|
+
return draft;
|
|
275
|
+
}
|
|
276
|
+
export { fromProtonAction, newAction, toProtonAction };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Condition Model
|
|
3
|
+
*
|
|
4
|
+
* Converts between UI tree structure and Proton API format.
|
|
5
|
+
* Handles condition tree transformations, factory functions, and validation.
|
|
6
|
+
*/
|
|
7
|
+
import type { Proton } from '@wallarm-org/rules-lib';
|
|
8
|
+
import type { PointSelectorValue, RuleContext } from '../../PointSelector/types.js';
|
|
9
|
+
import type { AttackCondition, FieldCondition, GroupCondition, GroupOperator, ProtonCondition, SampleCondition, SignalCondition, SignalType, TagCondition } from '../types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Generate a unique ID for a condition node.
|
|
12
|
+
*
|
|
13
|
+
* @returns Unique node ID
|
|
14
|
+
*/
|
|
15
|
+
export declare function nodeId(): string;
|
|
16
|
+
/**
|
|
17
|
+
* Empty PointSelector value for new field conditions.
|
|
18
|
+
*/
|
|
19
|
+
export declare const EMPTY_FIELD_VALUE: PointSelectorValue;
|
|
20
|
+
/**
|
|
21
|
+
* Create a new field condition with default values.
|
|
22
|
+
*
|
|
23
|
+
* @param context - Rule context (default: 'http_request')
|
|
24
|
+
* @returns New FieldCondition
|
|
25
|
+
*/
|
|
26
|
+
export declare function newField(context?: RuleContext): FieldCondition;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new attack condition with default values.
|
|
29
|
+
*
|
|
30
|
+
* @param attackType - Attack type (default: '')
|
|
31
|
+
* @param point - Point where attack is detected (default: 'flow')
|
|
32
|
+
* @returns New AttackCondition
|
|
33
|
+
*/
|
|
34
|
+
export declare function newAttack(attackType?: string, point?: string): AttackCondition;
|
|
35
|
+
/**
|
|
36
|
+
* Create a new signal condition with default values.
|
|
37
|
+
*
|
|
38
|
+
* @param signalType - Signal type (default: '')
|
|
39
|
+
* @param point - Point where signal is detected (default: '[http:header]')
|
|
40
|
+
* @returns New SignalCondition
|
|
41
|
+
*/
|
|
42
|
+
export declare function newSignal(signalType?: SignalType | '', point?: string): SignalCondition;
|
|
43
|
+
/**
|
|
44
|
+
* Create a new tag condition with default values.
|
|
45
|
+
*
|
|
46
|
+
* @param tagKey - Tag key (default: '')
|
|
47
|
+
* @param tagValue - Tag value (default: '')
|
|
48
|
+
* @param point - Point where tag is checked (default: 'flow')
|
|
49
|
+
* @returns New TagCondition
|
|
50
|
+
*/
|
|
51
|
+
export declare function newTag(tagKey?: string, tagValue?: string, point?: string): TagCondition;
|
|
52
|
+
/**
|
|
53
|
+
* Create a new sample condition with default values.
|
|
54
|
+
*
|
|
55
|
+
* @param percent - Percentage of flows to sample (default: 10)
|
|
56
|
+
* @returns New SampleCondition
|
|
57
|
+
*/
|
|
58
|
+
export declare function newSample(percent?: number): SampleCondition;
|
|
59
|
+
/**
|
|
60
|
+
* Create a new group condition with default values.
|
|
61
|
+
*
|
|
62
|
+
* @param operator - Group operator (default: 'and')
|
|
63
|
+
* @returns New GroupCondition with one empty field
|
|
64
|
+
*/
|
|
65
|
+
export declare function newGroup(operator?: GroupOperator): GroupCondition;
|
|
66
|
+
/**
|
|
67
|
+
* Check if a field condition is complete enough to serialize.
|
|
68
|
+
*
|
|
69
|
+
* @param condition - Field condition to check
|
|
70
|
+
* @returns True if condition has segments, a condition type, and value if required
|
|
71
|
+
*/
|
|
72
|
+
export declare function fieldComplete(condition: FieldCondition): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Convert UI condition tree to Proton API format.
|
|
75
|
+
*
|
|
76
|
+
* @param root - Root group condition
|
|
77
|
+
* @param proton - Optional Proton SDK instance for canonical point rendering
|
|
78
|
+
* @returns Proton condition or null if empty/incomplete
|
|
79
|
+
*/
|
|
80
|
+
export declare function toProtonCondition(root: GroupCondition, proton?: Proton | null): ProtonCondition | null;
|
|
81
|
+
/**
|
|
82
|
+
* Convert Proton API format to UI condition tree.
|
|
83
|
+
*
|
|
84
|
+
* @param condition - Proton condition (null/undefined = empty tree)
|
|
85
|
+
* @param proton - SDK instance for parsing point strings (optional)
|
|
86
|
+
* @returns Group condition (always returns a group, even if empty)
|
|
87
|
+
*/
|
|
88
|
+
export declare function fromProtonCondition(condition: unknown, proton?: Proton | null): GroupCondition;
|
|
89
|
+
/**
|
|
90
|
+
* Validate a condition tree and return problems.
|
|
91
|
+
*
|
|
92
|
+
* @param root - Root group condition
|
|
93
|
+
* @returns Array of problem descriptions (empty if valid)
|
|
94
|
+
*/
|
|
95
|
+
export declare function conditionProblems(root: GroupCondition): string[];
|