@jeffusion/bungee-core 6.17.0 → 6.18.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.
- package/dist/main.js +58 -58
- package/dist/observability-worker.js +17 -1
- package/dist/plugins/request-body-redaction/control.js +58 -0
- package/dist/plugins/request-body-redaction/control.js.map +10 -0
- package/dist/plugins/request-body-redaction/index.js +7049 -0
- package/dist/plugins/request-body-redaction/index.js.map +28 -0
- package/dist/plugins/request-body-redaction/manifest.json +83 -0
- package/dist/plugins/request-body-redaction/ui/RedactionRulesEditor.svelte +475 -0
- package/dist/plugins/request-body-redaction/ui/RequestBodyRedactionPage.svelte +674 -0
- package/dist/plugins/request-body-redaction/ui/RequestBodyRedactionStats.svelte +218 -0
- package/dist/plugins/request-body-redaction/ui/route-bindings.ts +69 -0
- package/package.json +2 -2
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "request-body-redaction",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"schemaVersion": 3,
|
|
5
|
+
"artifactKind": "runtime-plugin",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"capabilities": [
|
|
8
|
+
"hooks",
|
|
9
|
+
"api",
|
|
10
|
+
"nativeWidgetsStatic",
|
|
11
|
+
"dynamicRuntimeLoad",
|
|
12
|
+
"controlPlane"
|
|
13
|
+
],
|
|
14
|
+
"uiExtensionMode": "native-static",
|
|
15
|
+
"engines": {
|
|
16
|
+
"bungee": "^6.0.0"
|
|
17
|
+
},
|
|
18
|
+
"runtimeScope": "scoped",
|
|
19
|
+
"control": {
|
|
20
|
+
"entry": "control.js",
|
|
21
|
+
"rpc": []
|
|
22
|
+
},
|
|
23
|
+
"builtin": true,
|
|
24
|
+
"ui": {
|
|
25
|
+
"components": [
|
|
26
|
+
{
|
|
27
|
+
"name": "RequestBodyRedactionPage",
|
|
28
|
+
"entry": "ui/RequestBodyRedactionPage.svelte"
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"contributes": {
|
|
33
|
+
"api": [
|
|
34
|
+
{
|
|
35
|
+
"path": "/stats",
|
|
36
|
+
"methods": [
|
|
37
|
+
"GET"
|
|
38
|
+
],
|
|
39
|
+
"handler": "getStats",
|
|
40
|
+
"execution": "control",
|
|
41
|
+
"capability": "logs.read"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"navigation": [
|
|
45
|
+
{
|
|
46
|
+
"label": "metadata.name",
|
|
47
|
+
"path": "/settings",
|
|
48
|
+
"component": "RequestBodyRedactionPage",
|
|
49
|
+
"layout": "standalone",
|
|
50
|
+
"icon": "shield",
|
|
51
|
+
"target": "header"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
"metadata": {
|
|
56
|
+
"name": "metadata.name",
|
|
57
|
+
"description": "plugin.description",
|
|
58
|
+
"icon": "shield"
|
|
59
|
+
},
|
|
60
|
+
"configSchema": [
|
|
61
|
+
{
|
|
62
|
+
"name": "rules",
|
|
63
|
+
"type": "json",
|
|
64
|
+
"label": "config.rules.label",
|
|
65
|
+
"default": [],
|
|
66
|
+
"description": "config.rules.description"
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"translations": {
|
|
70
|
+
"en": {
|
|
71
|
+
"metadata.name": "Request Redaction",
|
|
72
|
+
"plugin.description": "Redact JSON request bodies before forwarding",
|
|
73
|
+
"config.rules.label": "Redaction rules",
|
|
74
|
+
"config.rules.description": "Ordered JSON array of rules: type (literal or regex), pattern, and optional replacement (default: [REDACTED])."
|
|
75
|
+
},
|
|
76
|
+
"zh-CN": {
|
|
77
|
+
"metadata.name": "请求脱敏",
|
|
78
|
+
"plugin.description": "转发前脱敏 JSON 请求正文",
|
|
79
|
+
"config.rules.label": "脱敏规则",
|
|
80
|
+
"config.rules.description": "按序执行的 JSON 规则数组:type(literal 或 regex)、pattern、可选 replacement(默认 [REDACTED])。"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick, untrack } from 'svelte';
|
|
3
|
+
import { locale } from 'svelte-i18n';
|
|
4
|
+
import AlertCircle from 'lucide-svelte/icons/alert-circle';
|
|
5
|
+
import ArrowDown from 'lucide-svelte/icons/arrow-down';
|
|
6
|
+
import ArrowRight from 'lucide-svelte/icons/arrow-right';
|
|
7
|
+
import ArrowUp from 'lucide-svelte/icons/arrow-up';
|
|
8
|
+
import Plus from 'lucide-svelte/icons/plus';
|
|
9
|
+
import ShieldAlert from 'lucide-svelte/icons/shield-alert';
|
|
10
|
+
import ShieldPlus from 'lucide-svelte/icons/shield-plus';
|
|
11
|
+
import Trash2 from 'lucide-svelte/icons/trash-2';
|
|
12
|
+
import { IndustrialToggle, PanelCard, SegmentedControl, StatusBadge } from '$components/industrial';
|
|
13
|
+
import { Button } from '$components/ui/button';
|
|
14
|
+
import { Textarea } from '$components/ui/textarea';
|
|
15
|
+
import { DEFAULT_REDACTION_REPLACEMENT, MAX_REDACTION_FIELD_LENGTH, MAX_REDACTION_RULES, validateRedactionRule } from '../rules';
|
|
16
|
+
|
|
17
|
+
let { value, label, onchange, onvalidate }: {
|
|
18
|
+
value: unknown;
|
|
19
|
+
label: string;
|
|
20
|
+
onchange: (rules: unknown[]) => void;
|
|
21
|
+
onvalidate: (invalid: boolean) => void;
|
|
22
|
+
} = $props();
|
|
23
|
+
|
|
24
|
+
const copy = $derived($locale?.startsWith('zh') ? {
|
|
25
|
+
sequence: '按序号自上而下依次执行,后续规则作用于前一条规则替换后的文本。',
|
|
26
|
+
singleHint: '匹配解析后 JSON 字符串值中的所有命中片段,不改写键名与非字符串字段。',
|
|
27
|
+
add: '添加规则',
|
|
28
|
+
addFirst: '添加第一条规则',
|
|
29
|
+
reset: '清空无效规则',
|
|
30
|
+
rule: '规则',
|
|
31
|
+
kind: '匹配方式',
|
|
32
|
+
literal: '字面文本',
|
|
33
|
+
regex: '正则表达式',
|
|
34
|
+
pattern: '匹配内容',
|
|
35
|
+
patternPlaceholderLiteral: '输入需要脱敏的敏感词或固定子串…',
|
|
36
|
+
patternPlaceholderRegex: '例如:(?i)acct-[0-9]{4,8}',
|
|
37
|
+
replacement: '替换输出',
|
|
38
|
+
replacementPlaceholder: '留空则直接删除匹配到的文本',
|
|
39
|
+
custom: '自定义替换',
|
|
40
|
+
emptyModeHint: '当前留空:命中内容将被直接删除。',
|
|
41
|
+
customHint: '按字面文本替换($1 等不展开捕获组),留空则删除匹配内容。',
|
|
42
|
+
defaultCaption: '使用系统默认脱敏占位符,开启右侧开关可自定义或清空删除。',
|
|
43
|
+
modeDefault: `默认 ${DEFAULT_REDACTION_REPLACEMENT}`,
|
|
44
|
+
modeDelete: '删除匹配',
|
|
45
|
+
modeCustom: '自定义替换',
|
|
46
|
+
ruleError: '规则有误',
|
|
47
|
+
literalHint: '区分大小写 · 按字面子串匹配',
|
|
48
|
+
re2: 'RE2 语法(不带 /…/)· (?i) 忽略大小写',
|
|
49
|
+
up: '上移',
|
|
50
|
+
down: '下移',
|
|
51
|
+
remove: '删除',
|
|
52
|
+
limit: `已达上限:每条路由最多配置 ${MAX_REDACTION_RULES} 条规则。`,
|
|
53
|
+
overLimit: `规则数量超出上限(最多 ${MAX_REDACTION_RULES} 条),请删除多余规则。`,
|
|
54
|
+
emptyTitle: '尚未配置脱敏规则',
|
|
55
|
+
emptyDesc: '添加至少 1 条字面文本或 RE2 正则规则并保存,即可对经过此路由的出站 JSON 请求正文生效。',
|
|
56
|
+
invalidRule: '此条规则结构无效,请删除后重新创建。',
|
|
57
|
+
invalidType: '请选择有效的匹配方式。',
|
|
58
|
+
invalidPattern: '无效的 RE2 正则表达式(不支持反向引用和环视)。',
|
|
59
|
+
required: '请输入匹配内容。',
|
|
60
|
+
tooLong: `不得超过 ${MAX_REDACTION_FIELD_LENGTH} 个 UTF-16 代码单元。`,
|
|
61
|
+
invalidReplacement: '请输入有效的替换文本,或关闭自定义替换。',
|
|
62
|
+
invalidListTitle: '已保存的规则格式损坏',
|
|
63
|
+
invalidList: '当前路由保存的规则不是有效列表,请清空后重新创建规则。',
|
|
64
|
+
} : {
|
|
65
|
+
sequence: 'Rules execute top to bottom; each rule runs on the text produced by earlier rules.',
|
|
66
|
+
singleHint: 'Matches all occurrences inside JSON string values; keys and non-string primitives are untouched.',
|
|
67
|
+
add: 'Add rule',
|
|
68
|
+
addFirst: 'Add first rule',
|
|
69
|
+
reset: 'Clear invalid rules',
|
|
70
|
+
rule: 'Rule',
|
|
71
|
+
kind: 'Match type',
|
|
72
|
+
literal: 'Literal',
|
|
73
|
+
regex: 'Regex',
|
|
74
|
+
pattern: 'Match pattern',
|
|
75
|
+
patternPlaceholderLiteral: 'Enter exact text or sensitive substring…',
|
|
76
|
+
patternPlaceholderRegex: 'e.g. (?i)acct-[0-9]{4,8}',
|
|
77
|
+
replacement: 'Replacement',
|
|
78
|
+
replacementPlaceholder: 'Leave empty to strip matched text',
|
|
79
|
+
custom: 'Custom',
|
|
80
|
+
emptyModeHint: 'Empty custom value: matched text will be deleted.',
|
|
81
|
+
customHint: 'Inserted literally ($1 is not expanded); leave empty to delete matches.',
|
|
82
|
+
defaultCaption: 'Uses the default redaction token. Toggle Custom to override or strip.',
|
|
83
|
+
modeDefault: `Default ${DEFAULT_REDACTION_REPLACEMENT}`,
|
|
84
|
+
modeDelete: 'Strip match',
|
|
85
|
+
modeCustom: 'Custom text',
|
|
86
|
+
ruleError: 'Invalid',
|
|
87
|
+
literalHint: 'Case-sensitive exact substring',
|
|
88
|
+
re2: 'RE2 syntax without /…/ · (?i) ignores case',
|
|
89
|
+
up: 'Move up',
|
|
90
|
+
down: 'Move down',
|
|
91
|
+
remove: 'Delete',
|
|
92
|
+
limit: `Limit reached: up to ${MAX_REDACTION_RULES} rules per route.`,
|
|
93
|
+
overLimit: `Too many rules (max ${MAX_REDACTION_RULES}). Remove extra rules to save.`,
|
|
94
|
+
emptyTitle: 'No redaction rules yet',
|
|
95
|
+
emptyDesc: 'Add at least one literal or RE2 regex rule and save to redact outbound JSON request bodies on this route.',
|
|
96
|
+
invalidRule: 'Invalid rule structure. Delete and recreate it.',
|
|
97
|
+
invalidType: 'Select a valid match type.',
|
|
98
|
+
invalidPattern: 'Invalid RE2 expression (backreferences and lookarounds are not supported).',
|
|
99
|
+
required: 'Enter a pattern.',
|
|
100
|
+
tooLong: `Use no more than ${MAX_REDACTION_FIELD_LENGTH} UTF-16 code units.`,
|
|
101
|
+
invalidReplacement: 'Enter valid replacement text, or turn off Custom.',
|
|
102
|
+
invalidListTitle: 'Saved rules format is invalid',
|
|
103
|
+
invalidList: 'The saved rules list for this route is malformed. Clear and recreate it.',
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const uid = $props.id();
|
|
107
|
+
const rules = $derived(Array.isArray(value) ? value : []);
|
|
108
|
+
const invalidList = $derived(value !== undefined && !Array.isArray(value));
|
|
109
|
+
const rowErrors = $derived(rules.map(validateRedactionRule));
|
|
110
|
+
const invalid = $derived(invalidList || !rules.length || rules.length > MAX_REDACTION_RULES || rowErrors.some(Boolean));
|
|
111
|
+
let nextKey = 0;
|
|
112
|
+
let keys = $state(untrack(() => rules.map(() => nextKey++)));
|
|
113
|
+
const types = $derived([{ value: 'literal', label: copy.literal }, { value: 'regex', label: copy.regex }]);
|
|
114
|
+
|
|
115
|
+
$effect(() => {
|
|
116
|
+
const currentInvalid = invalid;
|
|
117
|
+
untrack(() => onvalidate(currentInvalid));
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
function update(index: number, fields: Record<string, unknown>) {
|
|
121
|
+
onchange(rules.map((rule, i) => i === index ? { ...rule, ...fields } : rule));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function setCustom(index: number, enabled: boolean) {
|
|
125
|
+
const { replacement: _, ...rule } = rules[index];
|
|
126
|
+
onchange(rules.map((item, i) => i !== index ? item : enabled ? { ...rule, replacement: '' } : rule));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function focusPattern(key: number | undefined) {
|
|
130
|
+
void tick().then(() => (key === undefined ? document.getElementById(`${uid}-add`) :
|
|
131
|
+
document.getElementById(`${uid}-${key}-pattern`) ?? document.getElementById(`${uid}-${key}-position`))?.focus());
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function add() {
|
|
135
|
+
const key = nextKey++;
|
|
136
|
+
keys = [...keys, key];
|
|
137
|
+
onchange([...rules, { type: 'literal', pattern: '' }]);
|
|
138
|
+
focusPattern(key);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function remove(index: number) {
|
|
142
|
+
keys = keys.filter((_, i) => i !== index);
|
|
143
|
+
onchange(rules.filter((_, i) => i !== index));
|
|
144
|
+
focusPattern(keys[index] ?? keys[index - 1]);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function move(index: number, direction: number) {
|
|
148
|
+
const target = index + direction;
|
|
149
|
+
const next = [...rules];
|
|
150
|
+
const order = [...keys];
|
|
151
|
+
[next[index], next[target]] = [next[target], next[index]];
|
|
152
|
+
[order[index], order[target]] = [order[target], order[index]];
|
|
153
|
+
keys = order;
|
|
154
|
+
onchange(next);
|
|
155
|
+
void tick().then(() => document.getElementById(`${uid}-${order[target]}-position`)?.focus());
|
|
156
|
+
}
|
|
157
|
+
</script>
|
|
158
|
+
|
|
159
|
+
<section aria-labelledby={`${uid}-title`} class="space-y-3">
|
|
160
|
+
<!-- Rules toolbar -->
|
|
161
|
+
<div class="flex flex-wrap items-start justify-between gap-3">
|
|
162
|
+
<div class="min-w-0 flex-1 space-y-1">
|
|
163
|
+
<div class="flex flex-wrap items-center gap-2.5">
|
|
164
|
+
<h3 id={`${uid}-title`} class="nx-field-label">// {label}</h3>
|
|
165
|
+
<span class="border border-carbon-600 bg-carbon-900 px-2 py-0.5 font-mono text-[10px] tracking-command {rules.length > MAX_REDACTION_RULES ? 'border-red-500/60 text-red-300' : 'text-zinc-400'}">
|
|
166
|
+
{rules.length} / {MAX_REDACTION_RULES}
|
|
167
|
+
</span>
|
|
168
|
+
</div>
|
|
169
|
+
<p class="text-xs text-zinc-400">
|
|
170
|
+
{rules.length > 1 ? copy.sequence : copy.singleHint}
|
|
171
|
+
</p>
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
{#if !invalidList && rules.length > 0}
|
|
175
|
+
<Button
|
|
176
|
+
id={`${uid}-add`}
|
|
177
|
+
variant="outline"
|
|
178
|
+
size="sm"
|
|
179
|
+
class="min-h-[44px] shrink-0 sm:min-h-0"
|
|
180
|
+
disabled={rules.length >= MAX_REDACTION_RULES}
|
|
181
|
+
onclick={add}
|
|
182
|
+
>
|
|
183
|
+
<Plus class="mr-1.5 h-3.5 w-3.5" aria-hidden="true" />
|
|
184
|
+
{copy.add}
|
|
185
|
+
</Button>
|
|
186
|
+
{/if}
|
|
187
|
+
</div>
|
|
188
|
+
|
|
189
|
+
{#if invalidList}
|
|
190
|
+
<div role="alert" class="flex flex-wrap items-center justify-between gap-4 border border-red-500/50 bg-red-500/5 p-4">
|
|
191
|
+
<div class="flex items-start gap-3">
|
|
192
|
+
<ShieldAlert class="mt-0.5 h-5 w-5 shrink-0 text-red-400" aria-hidden="true" />
|
|
193
|
+
<div class="space-y-1">
|
|
194
|
+
<p class="font-mono text-xs font-bold uppercase tracking-command text-red-300">{copy.invalidListTitle}</p>
|
|
195
|
+
<p class="text-sm text-zinc-300">{copy.invalidList}</p>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
<Button
|
|
199
|
+
variant="destructive"
|
|
200
|
+
size="sm"
|
|
201
|
+
class="min-h-[44px] sm:min-h-0"
|
|
202
|
+
onclick={() => { onchange([]); focusPattern(undefined); }}
|
|
203
|
+
>
|
|
204
|
+
{copy.reset}
|
|
205
|
+
</Button>
|
|
206
|
+
</div>
|
|
207
|
+
{:else if rules.length === 0}
|
|
208
|
+
<div class="flex flex-col items-center justify-center gap-3 border border-dashed border-carbon-500 bg-carbon-950/60 px-6 py-10 text-center">
|
|
209
|
+
<span class="flex h-11 w-11 items-center justify-center border border-carbon-500 bg-carbon-900 text-nexus-400">
|
|
210
|
+
<ShieldPlus class="h-5 w-5" aria-hidden="true" />
|
|
211
|
+
</span>
|
|
212
|
+
<div class="max-w-md space-y-1">
|
|
213
|
+
<p class="font-mono text-xs font-bold uppercase tracking-command text-zinc-200">{copy.emptyTitle}</p>
|
|
214
|
+
<p class="text-sm text-zinc-400">{copy.emptyDesc}</p>
|
|
215
|
+
</div>
|
|
216
|
+
<Button
|
|
217
|
+
id={`${uid}-add`}
|
|
218
|
+
variant="outline"
|
|
219
|
+
size="sm"
|
|
220
|
+
class="mt-1 min-h-[44px] sm:min-h-0"
|
|
221
|
+
onclick={add}
|
|
222
|
+
>
|
|
223
|
+
<Plus class="mr-1.5 h-3.5 w-3.5" aria-hidden="true" />
|
|
224
|
+
{copy.addFirst}
|
|
225
|
+
</Button>
|
|
226
|
+
</div>
|
|
227
|
+
{:else}
|
|
228
|
+
<div class="space-y-3">
|
|
229
|
+
{#each rules as rule, index (keys[index])}
|
|
230
|
+
{@const id = `${uid}-${keys[index]}`}
|
|
231
|
+
{@const issue = rowErrors[index]}
|
|
232
|
+
{@const pattern = typeof rule?.pattern === 'string' ? rule.pattern : ''}
|
|
233
|
+
{@const replacement = rule?.replacement}
|
|
234
|
+
{@const custom = replacement !== undefined}
|
|
235
|
+
{@const isDeleteMode = custom && replacement === ''}
|
|
236
|
+
{@const stepNumber = String(index + 1).padStart(2, '0')}
|
|
237
|
+
|
|
238
|
+
<PanelCard
|
|
239
|
+
corners={false}
|
|
240
|
+
headless
|
|
241
|
+
variant="flat"
|
|
242
|
+
flush
|
|
243
|
+
class="rule-card {issue ? 'border-red-500/60' : ''}"
|
|
244
|
+
>
|
|
245
|
+
<!-- Rule Step Header Bar -->
|
|
246
|
+
<div class="flex flex-wrap items-center justify-between gap-2 border-b border-carbon-600/80 bg-carbon-900/70 px-3.5 py-2">
|
|
247
|
+
<div class="flex flex-wrap items-center gap-2.5">
|
|
248
|
+
<h4
|
|
249
|
+
id={`${id}-position`}
|
|
250
|
+
tabindex="-1"
|
|
251
|
+
class="inline-flex items-center gap-1.5 font-mono text-xs font-bold uppercase tracking-command text-zinc-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-nexus-500"
|
|
252
|
+
>
|
|
253
|
+
<span class="inline-flex h-5 min-w-[26px] items-center justify-center border {issue ? 'border-red-500/70 bg-red-500/15 text-red-300' : 'border-nexus-500/50 bg-nexus-500/15 text-nexus-300'} px-1 text-[10px]">
|
|
254
|
+
#{stepNumber}
|
|
255
|
+
</span>
|
|
256
|
+
<span class="sr-only">{copy.rule} {index + 1}</span>
|
|
257
|
+
</h4>
|
|
258
|
+
|
|
259
|
+
{#if issue !== 'invalidRule'}
|
|
260
|
+
<SegmentedControl
|
|
261
|
+
options={types}
|
|
262
|
+
value={rule?.type}
|
|
263
|
+
ariaLabel={copy.kind}
|
|
264
|
+
class="min-h-[36px] sm:min-h-0"
|
|
265
|
+
onchange={type => update(index, { type })}
|
|
266
|
+
/>
|
|
267
|
+
{/if}
|
|
268
|
+
</div>
|
|
269
|
+
|
|
270
|
+
<div class="flex w-full items-center justify-between gap-2 sm:w-auto sm:justify-end">
|
|
271
|
+
<div class="flex items-center gap-1.5">
|
|
272
|
+
{#if issue}
|
|
273
|
+
<StatusBadge variant="fault">{copy.ruleError}</StatusBadge>
|
|
274
|
+
{/if}
|
|
275
|
+
{#if issue !== 'invalidRule'}
|
|
276
|
+
<StatusBadge variant={!custom ? 'muted' : isDeleteMode ? 'standby' : 'info'}>
|
|
277
|
+
{!custom ? copy.modeDefault : isDeleteMode ? copy.modeDelete : copy.modeCustom}
|
|
278
|
+
</StatusBadge>
|
|
279
|
+
{/if}
|
|
280
|
+
</div>
|
|
281
|
+
|
|
282
|
+
<div class="flex items-center gap-1">
|
|
283
|
+
{#each [{ key: 'up', icon: ArrowUp, direction: -1 }, { key: 'down', icon: ArrowDown, direction: 1 }] as action (action.key)}
|
|
284
|
+
{@const text = `${action.direction < 0 ? copy.up : copy.down} · ${copy.rule} ${index + 1}`}
|
|
285
|
+
<Button
|
|
286
|
+
variant="ghost"
|
|
287
|
+
size="icon"
|
|
288
|
+
class="h-[36px] w-[36px] sm:h-[30px] sm:w-[30px]"
|
|
289
|
+
aria-label={text}
|
|
290
|
+
title={text}
|
|
291
|
+
disabled={index + action.direction < 0 || index + action.direction >= rules.length}
|
|
292
|
+
onclick={() => move(index, action.direction)}
|
|
293
|
+
>
|
|
294
|
+
<action.icon class="h-3.5 w-3.5" aria-hidden="true" />
|
|
295
|
+
</Button>
|
|
296
|
+
{/each}
|
|
297
|
+
<Button
|
|
298
|
+
variant="ghost"
|
|
299
|
+
size="icon"
|
|
300
|
+
class="h-[36px] w-[36px] text-zinc-400 hover:border-red-500 hover:bg-red-500/10 hover:text-red-300 sm:h-[30px] sm:w-[30px]"
|
|
301
|
+
aria-label={`${copy.remove} · ${copy.rule} ${index + 1}`}
|
|
302
|
+
title={copy.remove}
|
|
303
|
+
onclick={() => remove(index)}
|
|
304
|
+
>
|
|
305
|
+
<Trash2 class="h-3.5 w-3.5" aria-hidden="true" />
|
|
306
|
+
</Button>
|
|
307
|
+
</div>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
|
|
311
|
+
<!-- Rule Body: Match -> Replacement Flow -->
|
|
312
|
+
<div class="p-3.5">
|
|
313
|
+
{#if issue === 'invalidRule'}
|
|
314
|
+
<div class="flex items-center gap-2 text-sm text-red-300">
|
|
315
|
+
<AlertCircle class="h-4 w-4 shrink-0" aria-hidden="true" />
|
|
316
|
+
<span>{copy.invalidRule}</span>
|
|
317
|
+
</div>
|
|
318
|
+
{:else}
|
|
319
|
+
{#if issue === 'invalidType'}
|
|
320
|
+
<p class="mb-2 text-sm text-red-300">{copy.invalidType}</p>
|
|
321
|
+
{/if}
|
|
322
|
+
|
|
323
|
+
<div class="rule-flow">
|
|
324
|
+
<!-- Left column: Match Pattern -->
|
|
325
|
+
<div class="min-w-0 space-y-1.5">
|
|
326
|
+
<div class="flex min-h-[36px] flex-wrap items-center justify-between gap-2">
|
|
327
|
+
<label id={`${id}-pattern-label`} class="nx-field-label" for={`${id}-pattern`}>
|
|
328
|
+
{copy.pattern}
|
|
329
|
+
</label>
|
|
330
|
+
<span class="font-mono text-[10px] text-zinc-500">
|
|
331
|
+
{rule?.type === 'regex' ? copy.re2 : copy.literalHint}
|
|
332
|
+
</span>
|
|
333
|
+
</div>
|
|
334
|
+
<Textarea
|
|
335
|
+
id={`${id}-pattern`}
|
|
336
|
+
rows={2}
|
|
337
|
+
class="min-h-[66px] resize-y {issue === 'invalidPattern' ? 'border-red-500 focus-visible:border-red-400 focus-visible:ring-red-500/40' : ''}"
|
|
338
|
+
value={pattern}
|
|
339
|
+
placeholder={rule?.type === 'regex' ? copy.patternPlaceholderRegex : copy.patternPlaceholderLiteral}
|
|
340
|
+
spellcheck={false}
|
|
341
|
+
aria-required="true"
|
|
342
|
+
aria-invalid={issue === 'invalidPattern'}
|
|
343
|
+
aria-labelledby={`${id}-position ${id}-pattern-label`}
|
|
344
|
+
aria-describedby={issue === 'invalidPattern' ? `${id}-pattern-help` : undefined}
|
|
345
|
+
oninput={event => update(index, { pattern: (event.target as HTMLTextAreaElement).value })}
|
|
346
|
+
/>
|
|
347
|
+
{#if issue === 'invalidPattern'}
|
|
348
|
+
<p id={`${id}-pattern-help`} class="flex items-center gap-1.5 text-xs text-red-300">
|
|
349
|
+
<AlertCircle class="h-3.5 w-3.5 shrink-0" aria-hidden="true" />
|
|
350
|
+
<span>
|
|
351
|
+
{!pattern.length ? copy.required : pattern.length > MAX_REDACTION_FIELD_LENGTH ? copy.tooLong : copy.invalidPattern}
|
|
352
|
+
</span>
|
|
353
|
+
</p>
|
|
354
|
+
{/if}
|
|
355
|
+
</div>
|
|
356
|
+
|
|
357
|
+
<!-- Center connector arrow -->
|
|
358
|
+
<div class="rule-arrow" aria-hidden="true">
|
|
359
|
+
<span class="rule-arrow-badge flex h-7 w-7 items-center justify-center border border-carbon-600 bg-carbon-900 text-nexus-400">
|
|
360
|
+
<ArrowRight class="h-3.5 w-3.5" />
|
|
361
|
+
</span>
|
|
362
|
+
</div>
|
|
363
|
+
|
|
364
|
+
<!-- Right column: Replacement Output -->
|
|
365
|
+
<div class="min-w-0 space-y-1.5">
|
|
366
|
+
<div class="flex min-h-[36px] items-center justify-between gap-2">
|
|
367
|
+
<label
|
|
368
|
+
id={`${id}-replacement-label`}
|
|
369
|
+
class="nx-field-label"
|
|
370
|
+
for={custom ? `${id}-replacement` : `${id}-custom`}
|
|
371
|
+
>
|
|
372
|
+
{copy.replacement}
|
|
373
|
+
</label>
|
|
374
|
+
<div class="-mr-2 flex items-center gap-1">
|
|
375
|
+
<label for={`${id}-custom`} class="cursor-pointer font-mono text-[10px] uppercase tracking-command text-zinc-400">
|
|
376
|
+
{copy.custom}
|
|
377
|
+
</label>
|
|
378
|
+
<IndustrialToggle
|
|
379
|
+
id={`${id}-custom`}
|
|
380
|
+
label={copy.custom}
|
|
381
|
+
checked={custom}
|
|
382
|
+
onchange={enabled => setCustom(index, enabled)}
|
|
383
|
+
/>
|
|
384
|
+
</div>
|
|
385
|
+
</div>
|
|
386
|
+
|
|
387
|
+
{#if custom}
|
|
388
|
+
<Textarea
|
|
389
|
+
id={`${id}-replacement`}
|
|
390
|
+
rows={2}
|
|
391
|
+
class="min-h-[66px] resize-y {issue === 'invalidReplacement' ? 'border-red-500 focus-visible:border-red-400 focus-visible:ring-red-500/40' : isDeleteMode ? 'border-amber-500/50' : ''}"
|
|
392
|
+
spellcheck={false}
|
|
393
|
+
placeholder={copy.replacementPlaceholder}
|
|
394
|
+
value={typeof replacement === 'string' ? replacement : ''}
|
|
395
|
+
aria-labelledby={`${id}-position ${id}-replacement-label`}
|
|
396
|
+
aria-invalid={issue === 'invalidReplacement'}
|
|
397
|
+
aria-describedby={`${id}-replacement-help`}
|
|
398
|
+
oninput={event => update(index, { replacement: (event.target as HTMLTextAreaElement).value })}
|
|
399
|
+
/>
|
|
400
|
+
<p
|
|
401
|
+
id={`${id}-replacement-help`}
|
|
402
|
+
class="text-xs {issue === 'invalidReplacement' ? 'text-red-300' : isDeleteMode ? 'text-amber-300' : 'text-zinc-400'}"
|
|
403
|
+
>
|
|
404
|
+
{issue === 'invalidReplacement'
|
|
405
|
+
? typeof replacement === 'string' && replacement.length > MAX_REDACTION_FIELD_LENGTH ? copy.tooLong : copy.invalidReplacement
|
|
406
|
+
: isDeleteMode ? copy.emptyModeHint : copy.customHint}
|
|
407
|
+
</p>
|
|
408
|
+
{:else}
|
|
409
|
+
<div class="flex min-h-[66px] flex-col justify-center gap-1 border border-dashed border-carbon-500 bg-carbon-950/70 px-3 py-2">
|
|
410
|
+
<div class="flex items-center gap-2">
|
|
411
|
+
<span class="border border-nexus-500/40 bg-nexus-500/10 px-2 py-0.5 font-mono text-xs font-medium text-nexus-300">
|
|
412
|
+
{DEFAULT_REDACTION_REPLACEMENT}
|
|
413
|
+
</span>
|
|
414
|
+
</div>
|
|
415
|
+
<p class="text-xs text-zinc-500">{copy.defaultCaption}</p>
|
|
416
|
+
</div>
|
|
417
|
+
{/if}
|
|
418
|
+
</div>
|
|
419
|
+
</div>
|
|
420
|
+
{/if}
|
|
421
|
+
</div>
|
|
422
|
+
</PanelCard>
|
|
423
|
+
{/each}
|
|
424
|
+
</div>
|
|
425
|
+
|
|
426
|
+
{#if rules.length >= MAX_REDACTION_RULES}
|
|
427
|
+
<p class="text-xs {rules.length > MAX_REDACTION_RULES ? 'text-red-300' : 'text-zinc-400'}">
|
|
428
|
+
{rules.length > MAX_REDACTION_RULES ? copy.overLimit : copy.limit}
|
|
429
|
+
</p>
|
|
430
|
+
{:else if rules.length >= 2}
|
|
431
|
+
<button
|
|
432
|
+
type="button"
|
|
433
|
+
class="flex w-full items-center justify-center gap-2 border border-dashed border-carbon-500 bg-carbon-900/40 px-3 py-2.5 font-mono text-[11px] font-semibold uppercase tracking-command text-zinc-400 transition-colors hover:border-nexus-500 hover:bg-nexus-500/5 hover:text-nexus-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-nexus-500"
|
|
434
|
+
onclick={add}
|
|
435
|
+
>
|
|
436
|
+
<Plus class="h-3.5 w-3.5" aria-hidden="true" />
|
|
437
|
+
{copy.add} ({rules.length} / {MAX_REDACTION_RULES})
|
|
438
|
+
</button>
|
|
439
|
+
{/if}
|
|
440
|
+
{/if}
|
|
441
|
+
</section>
|
|
442
|
+
|
|
443
|
+
<style>
|
|
444
|
+
.rule-flow {
|
|
445
|
+
display: grid;
|
|
446
|
+
min-width: 0;
|
|
447
|
+
gap: 10px;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.rule-arrow {
|
|
451
|
+
display: flex;
|
|
452
|
+
align-items: center;
|
|
453
|
+
justify-content: center;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
.rule-arrow-badge {
|
|
457
|
+
transform: rotate(90deg);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
@media (min-width: 768px) {
|
|
461
|
+
.rule-flow {
|
|
462
|
+
grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr);
|
|
463
|
+
gap: 12px;
|
|
464
|
+
align-items: start;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
.rule-arrow {
|
|
468
|
+
padding-top: 60px;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
.rule-arrow-badge {
|
|
472
|
+
transform: none;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
</style>
|