@wallarm-org/design-system 4.10.0-rc-feat-parser.1 → 4.10.0

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 (146) hide show
  1. package/README.md +1 -1
  2. package/dist/components/Badge/generateBadgeVariants.js +9 -28
  3. package/dist/components/CodeSnippet/internal/FoldToggle.js +1 -1
  4. package/dist/components/DropdownMenu/DropdownMenu.d.ts +0 -2
  5. package/dist/components/DropdownMenu/DropdownMenu.js +71 -84
  6. package/dist/components/DropdownMenu/DropdownMenuItemDescription.js +1 -1
  7. package/dist/components/FilterInput/hooks/useFilterInputAutocomplete/useFilterInputAutocomplete.js +1 -1
  8. package/dist/components/SimpleCharts/Chart/classes.js +1 -1
  9. package/dist/components/SimpleCharts/HorizontalBarStack/classes.js +1 -1
  10. package/dist/components/SimpleCharts/Metric/classes.d.ts +2 -2
  11. package/dist/components/SimpleCharts/Metric/classes.js +2 -2
  12. package/dist/components/Table/TableBody/TableBodyCell.js +4 -1
  13. package/dist/guidelines/patterns/complex-drawer.md +1084 -0
  14. package/dist/guidelines/patterns/confirmation-dialogs.md +3 -11
  15. package/dist/guidelines/patterns/detail-drawer.md +31 -13
  16. package/dist/guidelines/patterns/empty-states.md +6 -5
  17. package/dist/guidelines/patterns/entity-table.md +25 -29
  18. package/dist/guidelines/patterns/feedback-toasts.md +3 -11
  19. package/dist/guidelines/patterns/resource-list-page.md +14 -16
  20. package/dist/guidelines/rules.md +6 -5
  21. package/dist/guidelines/templates/ai-assistant.md +1133 -0
  22. package/dist/guidelines/templates/api-inventory.md +905 -0
  23. package/dist/guidelines/templates/attack-events.md +2722 -0
  24. package/dist/guidelines/templates/incident-detail.md +2085 -0
  25. package/dist/guidelines/templates/integrations-settings.md +836 -0
  26. package/dist/guidelines/templates/page-states.md +798 -0
  27. package/dist/guidelines/templates/rule-editor.md +886 -0
  28. package/dist/guidelines/templates/security-dashboard.md +681 -0
  29. package/dist/index.d.ts +0 -2
  30. package/dist/index.js +0 -2
  31. package/dist/metadata/components.json +9 -107
  32. package/dist/metadata/guidelines.json +1203 -36
  33. package/dist/theme/tokens.test.ts +52 -0
  34. package/package.json +1 -4
  35. package/dist/components/Rules/PointSelector/KeyboardShortcutsDialog.d.ts +0 -14
  36. package/dist/components/Rules/PointSelector/KeyboardShortcutsDialog.js +0 -209
  37. package/dist/components/Rules/PointSelector/MatchStep.d.ts +0 -15
  38. package/dist/components/Rules/PointSelector/MatchStep.js +0 -186
  39. package/dist/components/Rules/PointSelector/MenuFooterHints.d.ts +0 -16
  40. package/dist/components/Rules/PointSelector/MenuFooterHints.js +0 -177
  41. package/dist/components/Rules/PointSelector/PointPreview.d.ts +0 -10
  42. package/dist/components/Rules/PointSelector/PointPreview.js +0 -88
  43. package/dist/components/Rules/PointSelector/PointSelector.d.ts +0 -17
  44. package/dist/components/Rules/PointSelector/PointSelector.js +0 -937
  45. package/dist/components/Rules/PointSelector/PointSelectorEmptyState.d.ts +0 -12
  46. package/dist/components/Rules/PointSelector/PointSelectorEmptyState.js +0 -173
  47. package/dist/components/Rules/PointSelector/PointSelectorError.d.ts +0 -31
  48. package/dist/components/Rules/PointSelector/PointSelectorError.js +0 -275
  49. package/dist/components/Rules/PointSelector/PointSelectorInput.d.ts +0 -20
  50. package/dist/components/Rules/PointSelector/PointSelectorInput.js +0 -130
  51. package/dist/components/Rules/PointSelector/PointSelectorMenu.d.ts +0 -31
  52. package/dist/components/Rules/PointSelector/PointSelectorMenu.js +0 -317
  53. package/dist/components/Rules/PointSelector/PointSelectorSkeleton.d.ts +0 -8
  54. package/dist/components/Rules/PointSelector/PointSelectorSkeleton.js +0 -73
  55. package/dist/components/Rules/PointSelector/SampleRequest.d.ts +0 -14
  56. package/dist/components/Rules/PointSelector/SampleRequest.js +0 -116
  57. package/dist/components/Rules/PointSelector/StepMenu.d.ts +0 -40
  58. package/dist/components/Rules/PointSelector/StepMenu.js +0 -210
  59. package/dist/components/Rules/PointSelector/VersionWarning.d.ts +0 -26
  60. package/dist/components/Rules/PointSelector/VersionWarning.js +0 -231
  61. package/dist/components/Rules/PointSelector/WhereBar.d.ts +0 -48
  62. package/dist/components/Rules/PointSelector/WhereBar.js +0 -263
  63. package/dist/components/Rules/PointSelector/classes.d.ts +0 -28
  64. package/dist/components/Rules/PointSelector/classes.js +0 -22
  65. package/dist/components/Rules/PointSelector/index.d.ts +0 -20
  66. package/dist/components/Rules/PointSelector/index.js +0 -18
  67. package/dist/components/Rules/PointSelector/liftLayer.d.ts +0 -8
  68. package/dist/components/Rules/PointSelector/liftLayer.js +0 -4
  69. package/dist/components/Rules/PointSelector/sampleValue.d.ts +0 -6
  70. package/dist/components/Rules/PointSelector/sampleValue.js +0 -51
  71. package/dist/components/Rules/PointSelector/sdkBridge.d.ts +0 -508
  72. package/dist/components/Rules/PointSelector/sdkBridge.js +0 -339
  73. package/dist/components/Rules/PointSelector/types.d.ts +0 -304
  74. package/dist/components/Rules/PointSelector/types.js +0 -0
  75. package/dist/components/Rules/PointSelector/usePointSelector.d.ts +0 -161
  76. package/dist/components/Rules/PointSelector/usePointSelector.js +0 -1088
  77. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionEditor.d.ts +0 -28
  78. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionEditor.js +0 -208
  79. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionFields.d.ts +0 -23
  80. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionFields.js +0 -950
  81. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTargetPicker.d.ts +0 -21
  82. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTargetPicker.js +0 -110
  83. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTypeSelect.d.ts +0 -20
  84. package/dist/components/Rules/RuleBuilder/ActionEditor/ActionTypeSelect.js +0 -31
  85. package/dist/components/Rules/RuleBuilder/ActionEditor/AttackTypeField.d.ts +0 -23
  86. package/dist/components/Rules/RuleBuilder/ActionEditor/AttackTypeField.js +0 -131
  87. package/dist/components/Rules/RuleBuilder/ActionEditor/classes.d.ts +0 -17
  88. package/dist/components/Rules/RuleBuilder/ActionEditor/classes.js +0 -14
  89. package/dist/components/Rules/RuleBuilder/ActionEditor/index.d.ts +0 -6
  90. package/dist/components/Rules/RuleBuilder/ActionEditor/index.js +0 -6
  91. package/dist/components/Rules/RuleBuilder/ConditionTree/AddConditionMenu.d.ts +0 -24
  92. package/dist/components/Rules/RuleBuilder/ConditionTree/AddConditionMenu.js +0 -245
  93. package/dist/components/Rules/RuleBuilder/ConditionTree/AttackCondition.d.ts +0 -15
  94. package/dist/components/Rules/RuleBuilder/ConditionTree/AttackCondition.js +0 -691
  95. package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionCard.d.ts +0 -19
  96. package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionCard.js +0 -72
  97. package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionTree.d.ts +0 -27
  98. package/dist/components/Rules/RuleBuilder/ConditionTree/ConditionTree.js +0 -407
  99. package/dist/components/Rules/RuleBuilder/ConditionTree/FieldCondition.d.ts +0 -14
  100. package/dist/components/Rules/RuleBuilder/ConditionTree/FieldCondition.js +0 -269
  101. package/dist/components/Rules/RuleBuilder/ConditionTree/GroupCondition.d.ts +0 -25
  102. package/dist/components/Rules/RuleBuilder/ConditionTree/GroupCondition.js +0 -99
  103. package/dist/components/Rules/RuleBuilder/ConditionTree/SampleCondition.d.ts +0 -14
  104. package/dist/components/Rules/RuleBuilder/ConditionTree/SampleCondition.js +0 -118
  105. package/dist/components/Rules/RuleBuilder/ConditionTree/SignalCondition.d.ts +0 -14
  106. package/dist/components/Rules/RuleBuilder/ConditionTree/SignalCondition.js +0 -446
  107. package/dist/components/Rules/RuleBuilder/ConditionTree/TagCondition.d.ts +0 -14
  108. package/dist/components/Rules/RuleBuilder/ConditionTree/TagCondition.js +0 -266
  109. package/dist/components/Rules/RuleBuilder/ConditionTree/classes.d.ts +0 -35
  110. package/dist/components/Rules/RuleBuilder/ConditionTree/classes.js +0 -57
  111. package/dist/components/Rules/RuleBuilder/ConditionTree/index.d.ts +0 -15
  112. package/dist/components/Rules/RuleBuilder/ConditionTree/index.js +0 -10
  113. package/dist/components/Rules/RuleBuilder/RuleBuilder.d.ts +0 -67
  114. package/dist/components/Rules/RuleBuilder/RuleBuilder.js +0 -366
  115. package/dist/components/Rules/RuleBuilder/Summary/ActionSummary.d.ts +0 -32
  116. package/dist/components/Rules/RuleBuilder/Summary/ActionSummary.js +0 -420
  117. package/dist/components/Rules/RuleBuilder/Summary/ConditionSummary.d.ts +0 -27
  118. package/dist/components/Rules/RuleBuilder/Summary/ConditionSummary.js +0 -446
  119. package/dist/components/Rules/RuleBuilder/Summary/index.d.ts +0 -7
  120. package/dist/components/Rules/RuleBuilder/Summary/index.js +0 -2
  121. package/dist/components/Rules/RuleBuilder/classes.d.ts +0 -19
  122. package/dist/components/Rules/RuleBuilder/classes.js +0 -18
  123. package/dist/components/Rules/RuleBuilder/index.d.ts +0 -55
  124. package/dist/components/Rules/RuleBuilder/index.js +0 -11
  125. package/dist/components/Rules/RuleBuilder/models/actionModel.d.ts +0 -31
  126. package/dist/components/Rules/RuleBuilder/models/actionModel.js +0 -276
  127. package/dist/components/Rules/RuleBuilder/models/conditionModel.d.ts +0 -95
  128. package/dist/components/Rules/RuleBuilder/models/conditionModel.js +0 -418
  129. package/dist/components/Rules/RuleBuilder/models/index.d.ts +0 -3
  130. package/dist/components/Rules/RuleBuilder/models/index.js +0 -3
  131. package/dist/components/Rules/RuleBuilder/models/validation.d.ts +0 -176
  132. package/dist/components/Rules/RuleBuilder/models/validation.js +0 -242
  133. package/dist/components/Rules/RuleBuilder/shared/ChoiceSelect.d.ts +0 -27
  134. package/dist/components/Rules/RuleBuilder/shared/ChoiceSelect.js +0 -92
  135. package/dist/components/Rules/RuleBuilder/shared/index.d.ts +0 -1
  136. package/dist/components/Rules/RuleBuilder/shared/index.js +0 -1
  137. package/dist/components/Rules/RuleBuilder/types.d.ts +0 -384
  138. package/dist/components/Rules/RuleBuilder/types.js +0 -0
  139. package/dist/components/Rules/RuleBuilder/utils/constants.d.ts +0 -65
  140. package/dist/components/Rules/RuleBuilder/utils/constants.js +0 -356
  141. package/dist/components/Rules/RuleBuilder/utils/extractBindings.d.ts +0 -48
  142. package/dist/components/Rules/RuleBuilder/utils/extractBindings.js +0 -42
  143. package/dist/components/Rules/RuleBuilder/utils/helpers.d.ts +0 -92
  144. package/dist/components/Rules/RuleBuilder/utils/helpers.js +0 -54
  145. package/dist/components/Rules/RuleBuilder/utils/index.d.ts +0 -2
  146. package/dist/components/Rules/RuleBuilder/utils/index.js +0 -2
@@ -1,418 +0,0 @@
1
- import { pointOf } from "../../PointSelector/sdkBridge.js";
2
- let conditionSequence = 0;
3
- function nodeId() {
4
- return `c${++conditionSequence}`;
5
- }
6
- const EMPTY_FIELD_VALUE = {
7
- segments: [],
8
- condition: null,
9
- value: '',
10
- ignoreCase: false,
11
- canonical: null,
12
- canonicalVersion: null
13
- };
14
- function newField(context = 'http_request') {
15
- return {
16
- kind: 'field',
17
- id: nodeId(),
18
- context,
19
- value: EMPTY_FIELD_VALUE
20
- };
21
- }
22
- function newAttack(attackType = '', point = 'flow') {
23
- return {
24
- kind: 'attack',
25
- id: nodeId(),
26
- attackType,
27
- point
28
- };
29
- }
30
- function newSignal(signalType = '', point = '[http:header]') {
31
- return {
32
- kind: 'signal',
33
- id: nodeId(),
34
- signalType,
35
- point,
36
- limit: ''
37
- };
38
- }
39
- function newTag(tagKey = '', tagValue = '', point = 'flow') {
40
- return {
41
- kind: 'tag',
42
- id: nodeId(),
43
- tagKey,
44
- tagValue,
45
- point
46
- };
47
- }
48
- function newSample(percent = 10) {
49
- return {
50
- kind: 'sample',
51
- id: nodeId(),
52
- percent
53
- };
54
- }
55
- function newGroup(operator = 'and') {
56
- return {
57
- kind: 'group',
58
- id: nodeId(),
59
- operator,
60
- children: [
61
- newField()
62
- ]
63
- };
64
- }
65
- function fieldComplete(condition) {
66
- const { segments, condition: conditionType, value } = condition.value;
67
- if (0 === segments.length) return false;
68
- if (null === conditionType) return false;
69
- const requiresValue = ![
70
- 'exists',
71
- 'absent'
72
- ].includes(conditionType);
73
- if (requiresValue && '' === value) return false;
74
- return true;
75
- }
76
- function fieldToCheck(condition, proton) {
77
- if (!fieldComplete(condition) || !condition.value.condition) return null;
78
- const { segments, condition: conditionType, value, ignoreCase, canonical } = condition.value;
79
- const check = {
80
- type: conditionType,
81
- context: condition.context,
82
- point: canonical || pointOf(segments, proton)
83
- };
84
- const requiresValue = ![
85
- 'exists',
86
- 'absent'
87
- ].includes(conditionType);
88
- if (requiresValue) check.value = value;
89
- if (ignoreCase) check.case_sensitive = false;
90
- if (condition.bindPoint) check.bind_point = condition.bindPoint;
91
- if (condition.pointRef) check.point_ref = condition.pointRef;
92
- if (condition.pointRole) check.point_role = condition.pointRole;
93
- return check;
94
- }
95
- function nodeToProton(node, proton) {
96
- switch(node.kind){
97
- case 'field':
98
- return fieldToCheck(node, proton);
99
- case 'raw':
100
- return node.check;
101
- case 'attack':
102
- {
103
- const check = {
104
- type: node.absent ? 'attack_absent' : 'attack_present',
105
- context: 'http_request',
106
- point: node.point || 'flow'
107
- };
108
- const attack = {};
109
- if (node.attackType) attack.attack_type = node.attackType;
110
- if (node.source) attack.source = node.source;
111
- if (node.stampIds && node.stampIds.length > 0) attack.stamp_ids = node.stampIds.map((id)=>Number(id));
112
- if (node.ruleIds) attack.rule_ids = node.ruleIds;
113
- if (node.property) attack.property = node.property;
114
- if (node.reference) attack.reference = node.reference;
115
- if (node.known) attack.known = node.known;
116
- if (node.knownFalse) attack.known_false = node.knownFalse;
117
- if (Object.keys(attack).length > 0) check.attack = attack;
118
- if (node.bindAttack) check.bind_attack = node.bindAttack;
119
- return check;
120
- }
121
- case 'signal':
122
- if (!node.signalType) return null;
123
- if ('key_duplicate' === node.signalType) {
124
- const signal = {
125
- signal_type: 'key_duplicate'
126
- };
127
- if (node.key) signal.key = node.key;
128
- const check = {
129
- type: node.absent ? 'signal_absent' : 'signal_present',
130
- context: 'http_request',
131
- point: node.point || '[http:header]',
132
- signal
133
- };
134
- if (node.bindPoint) check.bind_point = node.bindPoint;
135
- return check;
136
- }
137
- if ('resource_overlimit' === node.signalType) {
138
- const isEntryLimit = 'entry_size_soft_limit' === node.limit || 'entry_size_hard_limit' === node.limit;
139
- const point = isEntryLimit ? node.point || '[**]' : 'flow';
140
- const check = {
141
- type: node.absent ? 'signal_absent' : 'signal_present',
142
- context: 'http_request',
143
- point,
144
- signal: {
145
- signal_type: 'resource_overlimit'
146
- }
147
- };
148
- if (node.limit) check.signal.limit = node.limit;
149
- if (node.bindPoint) check.bind_point = node.bindPoint;
150
- return check;
151
- }
152
- return null;
153
- case 'tag':
154
- {
155
- if (!node.tagKey) return null;
156
- const check = {
157
- type: node.absent ? 'tag_absent' : 'tag_present',
158
- context: 'http_request',
159
- point: node.point || 'flow',
160
- tag: {
161
- key: node.tagKey
162
- }
163
- };
164
- if (node.tagValue) check.tag.value = node.tagValue;
165
- return check;
166
- }
167
- case 'sample':
168
- return {
169
- type: 'sample',
170
- percent: node.percent
171
- };
172
- case 'group':
173
- {
174
- const checks = node.children.map((child)=>nodeToProton(child, proton)).filter((c)=>null !== c);
175
- if (0 === checks.length) return null;
176
- if ('not' === node.operator && checks.length > 1) return {
177
- operator: 'not',
178
- checks: [
179
- {
180
- operator: 'or',
181
- checks
182
- }
183
- ]
184
- };
185
- return {
186
- operator: node.operator,
187
- checks
188
- };
189
- }
190
- default:
191
- return null;
192
- }
193
- }
194
- function toProtonCondition(root, proton) {
195
- return nodeToProton(root, proton);
196
- }
197
- function segmentsOfPoint(point, context, proton) {
198
- if (!point) return [];
199
- if (!proton) return [];
200
- try {
201
- const result = proton.point.parse(point);
202
- return result;
203
- } catch (error) {
204
- console.warn('Failed to parse canonical point string with SDK', {
205
- point,
206
- error: error instanceof Error ? error.message : String(error)
207
- });
208
- return [];
209
- }
210
- }
211
- function isGroup(obj) {
212
- return 'object' == typeof obj && null !== obj && 'operator' in obj && 'checks' in obj;
213
- }
214
- function onlyKeys(obj, allowed) {
215
- return 'object' == typeof obj && null !== obj && Object.keys(obj).every((k)=>allowed.includes(k));
216
- }
217
- const CONDITIONS = [
218
- 'equal',
219
- 'nequal',
220
- 'contains',
221
- 'startswith',
222
- 'endswith',
223
- 'regexp',
224
- 'nregexp',
225
- 'exists',
226
- 'absent'
227
- ];
228
- function checkToNode(check, proton) {
229
- const type = String(check.type ?? '');
230
- if (('attack_present' === type || 'attack_absent' === type) && onlyKeys(check, [
231
- 'type',
232
- 'context',
233
- 'point',
234
- 'attack',
235
- 'bind_attack'
236
- ]) && 'string' == typeof check.point) {
237
- const attack = check.attack ?? {};
238
- const node = {
239
- kind: 'attack',
240
- id: nodeId(),
241
- attackType: 'string' == typeof attack.attack_type ? attack.attack_type : '',
242
- point: check.point,
243
- absent: 'attack_absent' === type ? true : void 0
244
- };
245
- if ('string' == typeof attack.source) node.source = attack.source;
246
- if (Array.isArray(attack.stamp_ids)) node.stampIds = attack.stamp_ids.map((id)=>String(id));
247
- if (void 0 !== attack.rule_ids) node.ruleIds = attack.rule_ids;
248
- if (void 0 !== attack.property) node.property = attack.property;
249
- if (attack.reference && 'object' == typeof attack.reference) {
250
- const ref = attack.reference;
251
- if ('string' == typeof ref.operator && [
252
- 'equal',
253
- 'startswith',
254
- 'regex'
255
- ].includes(ref.operator) && ('string' == typeof ref.value || Array.isArray(ref.value))) node.reference = {
256
- operator: ref.operator,
257
- value: ref.value
258
- };
259
- }
260
- if (attack.known && 'object' == typeof attack.known) node.known = attack.known;
261
- if (void 0 !== attack.known_false) node.knownFalse = attack.known_false;
262
- if ('string' == typeof check.bind_attack) node.bindAttack = check.bind_attack;
263
- return node;
264
- }
265
- if (('signal_present' === type || 'signal_absent' === type) && onlyKeys(check, [
266
- 'type',
267
- 'context',
268
- 'point',
269
- 'signal',
270
- 'bind_point'
271
- ]) && 'string' == typeof check.point) {
272
- const signal = check.signal ?? {};
273
- const absent = 'signal_absent' === type ? true : void 0;
274
- if ('key_duplicate' === signal.signal_type && void 0 === signal.limit) {
275
- const node = {
276
- kind: 'signal',
277
- id: nodeId(),
278
- signalType: 'key_duplicate',
279
- point: check.point,
280
- limit: '',
281
- absent
282
- };
283
- if ('string' == typeof signal.key) node.key = signal.key;
284
- if ('string' == typeof check.bind_point) node.bindPoint = check.bind_point;
285
- return node;
286
- }
287
- if ('resource_overlimit' === signal.signal_type && (void 0 === signal.limit || 'string' == typeof signal.limit)) {
288
- const point = 'string' == typeof check.point ? check.point : 'flow';
289
- const node = {
290
- kind: 'signal',
291
- id: nodeId(),
292
- signalType: 'resource_overlimit',
293
- point,
294
- limit: signal.limit ?? '',
295
- absent
296
- };
297
- if ('string' == typeof check.bind_point) node.bindPoint = check.bind_point;
298
- return node;
299
- }
300
- }
301
- if (('tag_present' === type || 'tag_absent' === type) && onlyKeys(check, [
302
- 'type',
303
- 'context',
304
- 'point',
305
- 'tag'
306
- ]) && 'string' == typeof check.point && onlyKeys(check.tag, [
307
- 'key',
308
- 'value'
309
- ])) {
310
- const tag = check.tag;
311
- if (tag.key && (void 0 === tag.value || 'string' == typeof tag.value)) return {
312
- kind: 'tag',
313
- id: nodeId(),
314
- tagKey: tag.key,
315
- tagValue: tag.value ?? '',
316
- point: check.point,
317
- absent: 'tag_absent' === type ? true : void 0
318
- };
319
- }
320
- if ('sample' === type && onlyKeys(check, [
321
- 'type',
322
- 'percent'
323
- ]) && 'number' == typeof check.percent) return {
324
- kind: 'sample',
325
- id: nodeId(),
326
- percent: check.percent
327
- };
328
- const point = check.point;
329
- const value = check.value;
330
- const isValueCheck = CONDITIONS.some((t)=>t === type);
331
- const context = check.context ?? 'http_request';
332
- const literalStar = ('equal' === type || 'nequal' === type) && 'string' == typeof value && value.includes('*');
333
- if (isValueCheck && !literalStar && 'string' == typeof point && (void 0 === value || 'string' == typeof value) && onlyKeys(check, [
334
- 'type',
335
- 'context',
336
- 'point',
337
- 'value',
338
- 'case_sensitive'
339
- ])) {
340
- const segments = segmentsOfPoint(point, context, proton);
341
- const currentVersion = proton ? proton.version().canonical : void 0;
342
- return {
343
- kind: 'field',
344
- id: nodeId(),
345
- context,
346
- value: {
347
- segments,
348
- canonical: point,
349
- canonicalVersion: currentVersion ?? null,
350
- condition: type,
351
- value: value ?? '',
352
- ignoreCase: false === check.case_sensitive
353
- }
354
- };
355
- }
356
- return {
357
- kind: 'raw',
358
- id: nodeId(),
359
- check
360
- };
361
- }
362
- function protonToNode(obj, proton) {
363
- if (!isGroup(obj)) return checkToNode(obj, proton);
364
- const operator = obj.operator ?? 'and';
365
- const only = obj.checks[0];
366
- if ('not' === operator && 1 === obj.checks.length && only && isGroup(only) && 'or' === only.operator) return {
367
- kind: 'group',
368
- id: nodeId(),
369
- operator: 'not',
370
- children: only.checks.map((c)=>protonToNode(c, proton))
371
- };
372
- return {
373
- kind: 'group',
374
- id: nodeId(),
375
- operator,
376
- children: obj.checks.map((c)=>protonToNode(c, proton))
377
- };
378
- }
379
- function fromProtonCondition(condition, proton = null) {
380
- if (!condition || 'object' != typeof condition) return {
381
- ...newGroup('and'),
382
- children: []
383
- };
384
- const node = protonToNode(condition, proton);
385
- return 'group' === node.kind ? node : {
386
- kind: 'group',
387
- id: nodeId(),
388
- operator: 'and',
389
- children: [
390
- node
391
- ]
392
- };
393
- }
394
- function hasSignalChecks(node) {
395
- return 'attack' === node.kind || 'signal' === node.kind || 'tag' === node.kind || 'sample' === node.kind || 'group' === node.kind && node.children.some(hasSignalChecks);
396
- }
397
- function conditionProblems(root) {
398
- const problems = new Set();
399
- function walk(node, underNone) {
400
- if ('field' === node.kind && !fieldComplete(node)) problems.add('Finish every condition: say where the value is, the condition and the value.');
401
- if ('signal' === node.kind && !node.signalType) problems.add('Choose which request anomaly.');
402
- if ('tag' === node.kind && !node.tagKey) problems.add('Specify the tag key.');
403
- if ('sample' === node.kind) {
404
- if (node.percent <= 0 || node.percent > 100) problems.add('Sample percent must be between 0 and 100.');
405
- }
406
- if ('group' === node.kind) {
407
- if (node !== root && 0 === node.children.length) problems.add('Remove empty groups.');
408
- const none = underNone || 'not' === node.operator;
409
- if (none && node.children.some(hasSignalChecks)) problems.add('"None of" cannot contain attack, anomaly, tag, or sample conditions.');
410
- for (const child of node.children)walk(child, none);
411
- }
412
- }
413
- walk(root, false);
414
- return [
415
- ...problems
416
- ];
417
- }
418
- export { EMPTY_FIELD_VALUE, conditionProblems, fieldComplete, fromProtonCondition, newAttack, newField, newGroup, newSample, newSignal, newTag, nodeId, toProtonCondition };
@@ -1,3 +0,0 @@
1
- export * from './actionModel.js';
2
- export * from './conditionModel.js';
3
- export * from './validation.js';
@@ -1,3 +0,0 @@
1
- export * from "./actionModel.js";
2
- export * from "./conditionModel.js";
3
- export * from "./validation.js";
@@ -1,176 +0,0 @@
1
- /**
2
- * Validation
3
- *
4
- * Validation rules for conditions and actions.
5
- * Mirrors Proton's load-time checks so the UI can show errors before API submission.
6
- */
7
- import type { Proton } from '@wallarm-org/rules-lib';
8
- import type { ActionDraft, GroupCondition } from '../types.js';
9
- /**
10
- * Check if a string is a valid Go duration.
11
- *
12
- * @param value - Value to check
13
- * @returns True if valid Go duration
14
- *
15
- * @example
16
- * ```typescript
17
- * isValidDuration('10ms') // true
18
- * isValidDuration('1.5s') // true
19
- * isValidDuration('invalid') // false
20
- * ```
21
- */
22
- export declare function isValidDuration(value: string): boolean;
23
- /**
24
- * Check if a string is a valid quantity.
25
- *
26
- * @param value - Value to check
27
- * @returns True if valid quantity
28
- *
29
- * @example
30
- * ```typescript
31
- * isValidQuantity('512') // true
32
- * isValidQuantity('1.5Ki') // true
33
- * isValidQuantity('2Mi') // true
34
- * isValidQuantity('invalid') // false
35
- * ```
36
- */
37
- export declare function isValidQuantity(value: string): boolean;
38
- /**
39
- * Check if a string is a valid integer.
40
- *
41
- * @param value - Value to check
42
- * @returns True if valid integer
43
- */
44
- export declare function isValidInteger(value: string): boolean;
45
- /**
46
- * Validate rule metadata (ID and description).
47
- *
48
- * @param ruleId - Rule ID to validate
49
- * @returns Array of problem descriptions (empty if valid)
50
- *
51
- * @example
52
- * ```typescript
53
- * const problems = ruleMetaProblems('');
54
- * // ['Rule ID is required']
55
- *
56
- * const problems = ruleMetaProblems(' ');
57
- * // ['Rule ID is required']
58
- *
59
- * const problems = ruleMetaProblems('my-rule-1');
60
- * // []
61
- * ```
62
- */
63
- export declare function ruleMetaProblems(ruleId: string): string[];
64
- /**
65
- * Validate action target against action type requirements.
66
- *
67
- * @param draft - Action draft to validate
68
- * @returns Array of problem descriptions (empty if valid)
69
- *
70
- * @example
71
- * ```typescript
72
- * // combine action requires point pattern, not flow
73
- * const problems = validateActionTarget({ kind: 'combine', target: { whole: true, ... } });
74
- * // ['The "Join repeated keys" action needs a specific point, not the whole request.']
75
- *
76
- * // processing_time_limit requires flow, not point pattern
77
- * const problems = validateActionTarget({ kind: 'processing_time_limit', target: { whole: false, segments: [...] } });
78
- * // ['The "Limit processing time" action applies to the whole request, not a specific point.']
79
- * ```
80
- */
81
- export declare function validateActionTarget(draft: ActionDraft): string[];
82
- /**
83
- * Validate action priority field based on action type.
84
- * Spec reference: rules-framework-actions.md §10
85
- *
86
- * @param draft - Action draft to validate
87
- * @returns Array of problem descriptions (empty if valid)
88
- *
89
- * @example
90
- * ```typescript
91
- * validateActionPriority({ kind: 'add_attack', priority: '10' })
92
- * // ['Priority is not allowed for add_attack actions.']
93
- *
94
- * validateActionPriority({ kind: 'processing_time_limit', priority: '50' })
95
- * // []
96
- *
97
- * validateActionPriority({ kind: 'entry_limits', priority: 'abc' })
98
- * // ['Priority must be a whole number.']
99
- * ```
100
- */
101
- export declare function validateActionPriority(draft: ActionDraft): string[];
102
- /**
103
- * Validate action draft and return problems.
104
- *
105
- * @param draft - Action draft to validate
106
- * @returns Array of problem descriptions (empty if valid)
107
- */
108
- export declare function actionProblems(draft: ActionDraft): string[];
109
- /**
110
- * Check if an action draft has any validation problems.
111
- *
112
- * @param draft - Action draft to check
113
- * @returns True if action is valid
114
- */
115
- export declare function isActionValid(draft: ActionDraft): boolean;
116
- /**
117
- * Common validation helpers for UI components.
118
- */
119
- export declare const validators: {
120
- /**
121
- * Validate duration input.
122
- */
123
- duration: (value: string) => string | null;
124
- /**
125
- * Validate quantity input.
126
- */
127
- quantity: (value: string) => string | null;
128
- /**
129
- * Validate integer input.
130
- */
131
- integer: (value: string) => string | null;
132
- /**
133
- * Validate non-empty string.
134
- */
135
- required: (value: string) => string | null;
136
- };
137
- /**
138
- * Validate binding references in action.
139
- *
140
- * Checks that attack_ref and target_ref refer to existing bindings in the condition tree,
141
- * AND that the binding is on the correct check type (rules-framework.md §4b):
142
- *
143
- * - bind_attack MUST be on attack_present or attack_absent check
144
- * - bind_point MUST be on data checks (exists, equal, contains, etc.)
145
- * - bind_point CANNOT be on signal checks or attack checks
146
- * - bind_point requires exact point (no wildcards, alternations, caseless keys)
147
- *
148
- * @param draft - Action draft to validate
149
- * @param condition - Root condition tree
150
- * @param proton - Proton SDK instance for point exactness validation (optional)
151
- * @returns Array of problem descriptions (empty if valid)
152
- *
153
- * @example
154
- * ```typescript
155
- * const problems = validateBindingRefs(action, condition, proton);
156
- * // ['bind_attack "my_attack" must reference an attack_present or attack_absent check, not exists']
157
- * // ['bind_point "my_target" cannot reference signal check tag_present']
158
- * // ['bind_point "my_target" requires exact point, but [key:*] contains wildcards']
159
- * ```
160
- */
161
- export declare function validateBindingRefs(draft: ActionDraft, condition: GroupCondition, proton?: Proton | null): string[];
162
- /**
163
- * Validate binding uniqueness in condition tree.
164
- *
165
- * Checks that all bind_attack and bind_point IDs are unique within the tree.
166
- *
167
- * @param condition - Root condition tree
168
- * @returns Array of problem descriptions (empty if valid)
169
- *
170
- * @example
171
- * ```typescript
172
- * const problems = validateBindingUniqueness(condition);
173
- * // ['Binding name "a" is used more than once']
174
- * ```
175
- */
176
- export declare function validateBindingUniqueness(condition: GroupCondition): string[];