@dsh-plus/notify-email 0.1.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/LICENSE +21 -0
- package/lib/client.js +624 -0
- package/lib/index.d.ts +149 -0
- package/lib/index.js +579 -0
- package/package.json +62 -0
- package/src/audit.ts +48 -0
- package/src/client/api.ts +83 -0
- package/src/client/card.tsx +239 -0
- package/src/client/client.ts +63 -0
- package/src/client/fields.tsx +75 -0
- package/src/client/i18n.ts +104 -0
- package/src/client/styles.ts +64 -0
- package/src/config-api.ts +116 -0
- package/src/config.ts +131 -0
- package/src/index.ts +24 -0
- package/src/mailer.ts +103 -0
- package/src/service.ts +122 -0
- package/src/triggers/builtin.ts +47 -0
- package/src/triggers/render.ts +93 -0
- package/src/triggers/types.ts +40 -0
- package/src/watchers/decision.ts +33 -0
- package/src/watchers/turn-end.ts +135 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 agguy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "@dsh-plus/notify-email",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
|
|
7
|
+
//#region rolldown:runtime
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
16
|
+
key = keys[i];
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: ((k) => from[k]).bind(null, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
25
|
+
value: mod,
|
|
26
|
+
enumerable: true
|
|
27
|
+
}) : target, mod));
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
let react = require("react");
|
|
31
|
+
react = __toESM(react);
|
|
32
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
react_jsx_runtime = __toESM(react_jsx_runtime);
|
|
34
|
+
|
|
35
|
+
//#region src/client/api.ts
|
|
36
|
+
const ROUTE_CONFIG = "/dsh-plus/notify-email/config";
|
|
37
|
+
const ROUTE_TEST = "/dsh-plus/notify-email/test";
|
|
38
|
+
async function parse(res) {
|
|
39
|
+
const body = await res.json();
|
|
40
|
+
if (!res.ok) throw new Error(body.error ?? `HTTP ${res.status}`);
|
|
41
|
+
return body;
|
|
42
|
+
}
|
|
43
|
+
async function fetchConfig() {
|
|
44
|
+
return parse(await fetch(ROUTE_CONFIG, { credentials: "same-origin" }));
|
|
45
|
+
}
|
|
46
|
+
async function saveConfig(patch) {
|
|
47
|
+
return parse(await fetch(ROUTE_CONFIG, {
|
|
48
|
+
method: "PUT",
|
|
49
|
+
credentials: "same-origin",
|
|
50
|
+
headers: { "content-type": "application/json" },
|
|
51
|
+
body: JSON.stringify(patch)
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
async function sendTest() {
|
|
55
|
+
return parse(await fetch(ROUTE_TEST, {
|
|
56
|
+
method: "POST",
|
|
57
|
+
credentials: "same-origin"
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/client/fields.tsx
|
|
63
|
+
function TextField(props) {
|
|
64
|
+
const invalid = props.invalid === true;
|
|
65
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
66
|
+
className: "dne-field",
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
69
|
+
className: "dne-head",
|
|
70
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
71
|
+
className: "dne-label",
|
|
72
|
+
htmlFor: props.id,
|
|
73
|
+
children: props.label
|
|
74
|
+
}), props.badge !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
75
|
+
className: `dne-badge ${props.badge.set ? "dne-badgeSet" : "dne-badgeUnset"}`,
|
|
76
|
+
children: props.badge.text
|
|
77
|
+
}) : null]
|
|
78
|
+
}),
|
|
79
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
80
|
+
id: props.id,
|
|
81
|
+
className: `dne-input${invalid ? " dne-inputInvalid" : ""}`,
|
|
82
|
+
type: props.password === true ? "password" : "text",
|
|
83
|
+
inputMode: props.numeric === true ? "numeric" : void 0,
|
|
84
|
+
autoComplete: props.password === true ? "off" : void 0,
|
|
85
|
+
"aria-invalid": invalid || void 0,
|
|
86
|
+
value: props.value,
|
|
87
|
+
disabled: props.disabled === true,
|
|
88
|
+
onChange: (event) => props.onEdit(event.target.value)
|
|
89
|
+
}),
|
|
90
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
91
|
+
className: invalid ? "dne-invalid" : "dne-hint",
|
|
92
|
+
children: invalid ? props.invalidLabel ?? "" : props.hint ?? ""
|
|
93
|
+
})
|
|
94
|
+
]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function CheckRow(props) {
|
|
98
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
99
|
+
className: "dne-checkRow",
|
|
100
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
101
|
+
id: props.id,
|
|
102
|
+
type: "checkbox",
|
|
103
|
+
checked: props.checked,
|
|
104
|
+
disabled: props.disabled === true,
|
|
105
|
+
onChange: (event) => props.onEdit(event.target.checked)
|
|
106
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
|
|
107
|
+
htmlFor: props.id,
|
|
108
|
+
children: props.label
|
|
109
|
+
})]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/client/card.tsx
|
|
115
|
+
const IDLE_STATUS = {
|
|
116
|
+
kind: "idle",
|
|
117
|
+
text: ""
|
|
118
|
+
};
|
|
119
|
+
function draftFromWire(wire) {
|
|
120
|
+
return {
|
|
121
|
+
enabled: wire.enabled,
|
|
122
|
+
host: wire.smtp.host,
|
|
123
|
+
port: String(wire.smtp.port),
|
|
124
|
+
secure: wire.smtp.secure,
|
|
125
|
+
user: wire.smtp.user,
|
|
126
|
+
pass: "",
|
|
127
|
+
from: wire.smtp.from,
|
|
128
|
+
toText: wire.to.join(", "),
|
|
129
|
+
triggers: { ...wire.triggers },
|
|
130
|
+
idleDebounceMs: String(wire.idleDebounceMs),
|
|
131
|
+
maxBodyChars: String(wire.maxBodyChars),
|
|
132
|
+
dryRun: wire.dryRun
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function isPositiveInt(text) {
|
|
136
|
+
return /^[0-9]+$/.test(text) && Number(text) > 0;
|
|
137
|
+
}
|
|
138
|
+
function toPatch(draft) {
|
|
139
|
+
return {
|
|
140
|
+
enabled: draft.enabled,
|
|
141
|
+
smtp: {
|
|
142
|
+
host: draft.host.trim(),
|
|
143
|
+
port: Number(draft.port),
|
|
144
|
+
secure: draft.secure,
|
|
145
|
+
user: draft.user.trim(),
|
|
146
|
+
pass: draft.pass,
|
|
147
|
+
from: draft.from.trim()
|
|
148
|
+
},
|
|
149
|
+
to: draft.toText.split(",").map((s) => s.trim()).filter((s) => s.length > 0),
|
|
150
|
+
triggers: { ...draft.triggers },
|
|
151
|
+
idleDebounceMs: Number(draft.idleDebounceMs),
|
|
152
|
+
maxBodyChars: Number(draft.maxBodyChars),
|
|
153
|
+
dryRun: draft.dryRun
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const TRIGGER_KEYS = [
|
|
157
|
+
"onComplete",
|
|
158
|
+
"onError",
|
|
159
|
+
"onAborted",
|
|
160
|
+
"onQuestion",
|
|
161
|
+
"onPlanReview"
|
|
162
|
+
];
|
|
163
|
+
function NotifyEmailCard(props) {
|
|
164
|
+
const { t } = props;
|
|
165
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
166
|
+
const [wire, setWire] = (0, react.useState)(null);
|
|
167
|
+
const [draft, setDraft] = (0, react.useState)(null);
|
|
168
|
+
const [failed, setFailed] = (0, react.useState)(false);
|
|
169
|
+
const [saving, setSaving] = (0, react.useState)(false);
|
|
170
|
+
const [testing, setTesting] = (0, react.useState)(false);
|
|
171
|
+
const [status, setStatus] = (0, react.useState)(IDLE_STATUS);
|
|
172
|
+
(0, react.useEffect)(() => {
|
|
173
|
+
let alive = true;
|
|
174
|
+
fetchConfig().then((loaded) => {
|
|
175
|
+
if (!alive) return;
|
|
176
|
+
setWire(loaded);
|
|
177
|
+
setDraft(draftFromWire(loaded));
|
|
178
|
+
}).catch(() => {
|
|
179
|
+
if (alive) setFailed(true);
|
|
180
|
+
});
|
|
181
|
+
return () => {
|
|
182
|
+
alive = false;
|
|
183
|
+
};
|
|
184
|
+
}, []);
|
|
185
|
+
const dirty = (0, react.useMemo)(() => wire !== null && draft !== null && JSON.stringify(toPatch(draft)) !== JSON.stringify(toPatch(draftFromWire(wire))), [wire, draft]);
|
|
186
|
+
const invalid = (0, react.useMemo)(() => draft !== null && (!isPositiveInt(draft.port) || !isPositiveInt(draft.idleDebounceMs) || !isPositiveInt(draft.maxBodyChars) || Number(draft.maxBodyChars) < 200), [draft]);
|
|
187
|
+
if (failed) return null;
|
|
188
|
+
if (wire === null || draft === null) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
|
|
189
|
+
className: "dne-card",
|
|
190
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
191
|
+
className: "dne-readOnly",
|
|
192
|
+
children: t("loading")
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
const edit = (key, value) => {
|
|
196
|
+
setDraft({
|
|
197
|
+
...draft,
|
|
198
|
+
[key]: value
|
|
199
|
+
});
|
|
200
|
+
setStatus(IDLE_STATUS);
|
|
201
|
+
};
|
|
202
|
+
const editTrigger = (key, checked) => {
|
|
203
|
+
edit("triggers", {
|
|
204
|
+
...draft.triggers,
|
|
205
|
+
[key]: checked
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
const onSave = () => {
|
|
209
|
+
setSaving(true);
|
|
210
|
+
saveConfig(toPatch(draft)).then((saved) => {
|
|
211
|
+
setWire(saved);
|
|
212
|
+
setDraft(draftFromWire(saved));
|
|
213
|
+
setStatus(IDLE_STATUS);
|
|
214
|
+
}).catch((error) => {
|
|
215
|
+
setStatus({
|
|
216
|
+
kind: "error",
|
|
217
|
+
text: `${t("saveFailed")} ${error instanceof Error ? error.message : ""}`
|
|
218
|
+
});
|
|
219
|
+
}).finally(() => setSaving(false));
|
|
220
|
+
};
|
|
221
|
+
const onTest = () => {
|
|
222
|
+
setTesting(true);
|
|
223
|
+
sendTest().then((result) => {
|
|
224
|
+
if (result.ok) setStatus({
|
|
225
|
+
kind: "ok",
|
|
226
|
+
text: result.detail === "dry-run" ? t("testDryRun") : t("testOk")
|
|
227
|
+
});
|
|
228
|
+
else {
|
|
229
|
+
const why = result.detail === "incomplete" ? t("incomplete") : result.detail;
|
|
230
|
+
setStatus({
|
|
231
|
+
kind: "error",
|
|
232
|
+
text: `${t("testFailed")}${why}`
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}).catch((error) => {
|
|
236
|
+
setStatus({
|
|
237
|
+
kind: "error",
|
|
238
|
+
text: `${t("testFailed")}${error instanceof Error ? error.message : ""}`
|
|
239
|
+
});
|
|
240
|
+
}).finally(() => setTesting(false));
|
|
241
|
+
};
|
|
242
|
+
const disabled = !wire.writable;
|
|
243
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
|
|
244
|
+
className: `dne-card${open ? " dne-cardOpen" : ""}`,
|
|
245
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
246
|
+
type: "button",
|
|
247
|
+
className: "dne-header",
|
|
248
|
+
"aria-expanded": open,
|
|
249
|
+
"aria-label": `${t(open ? "collapse" : "expand")}: ${t("title")}`,
|
|
250
|
+
onClick: () => setOpen(!open),
|
|
251
|
+
children: [
|
|
252
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
253
|
+
className: "dne-headText",
|
|
254
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
255
|
+
className: "dne-name",
|
|
256
|
+
children: t("title")
|
|
257
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
258
|
+
className: "dne-description",
|
|
259
|
+
children: t("description")
|
|
260
|
+
})]
|
|
261
|
+
}),
|
|
262
|
+
dirty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
263
|
+
className: "dne-pending",
|
|
264
|
+
children: t("unsaved")
|
|
265
|
+
}) : null,
|
|
266
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
267
|
+
className: `dne-chevron${open ? " dne-chevronOpen" : ""}`,
|
|
268
|
+
children: "▾"
|
|
269
|
+
})
|
|
270
|
+
]
|
|
271
|
+
}), open ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
272
|
+
className: "dne-body",
|
|
273
|
+
children: [
|
|
274
|
+
disabled ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
275
|
+
className: "dne-readOnly",
|
|
276
|
+
role: "status",
|
|
277
|
+
children: t("readOnly")
|
|
278
|
+
}) : null,
|
|
279
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
280
|
+
id: "dne-enabled",
|
|
281
|
+
label: t("enabled"),
|
|
282
|
+
checked: draft.enabled,
|
|
283
|
+
disabled,
|
|
284
|
+
onEdit: (v) => edit("enabled", v)
|
|
285
|
+
}),
|
|
286
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
287
|
+
id: "dne-host",
|
|
288
|
+
label: t("host"),
|
|
289
|
+
hint: t("hostHint"),
|
|
290
|
+
value: draft.host,
|
|
291
|
+
disabled,
|
|
292
|
+
onEdit: (v) => edit("host", v)
|
|
293
|
+
}),
|
|
294
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
295
|
+
id: "dne-port",
|
|
296
|
+
label: t("port"),
|
|
297
|
+
hint: t("portHint"),
|
|
298
|
+
value: draft.port,
|
|
299
|
+
numeric: true,
|
|
300
|
+
disabled,
|
|
301
|
+
invalid: !isPositiveInt(draft.port),
|
|
302
|
+
invalidLabel: t("invalidNumber"),
|
|
303
|
+
onEdit: (v) => edit("port", v)
|
|
304
|
+
}),
|
|
305
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
306
|
+
id: "dne-secure",
|
|
307
|
+
label: t("secure"),
|
|
308
|
+
checked: draft.secure,
|
|
309
|
+
disabled,
|
|
310
|
+
onEdit: (v) => edit("secure", v)
|
|
311
|
+
}),
|
|
312
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
313
|
+
id: "dne-user",
|
|
314
|
+
label: t("user"),
|
|
315
|
+
hint: t("userHint"),
|
|
316
|
+
value: draft.user,
|
|
317
|
+
disabled,
|
|
318
|
+
onEdit: (v) => edit("user", v)
|
|
319
|
+
}),
|
|
320
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
321
|
+
id: "dne-pass",
|
|
322
|
+
label: t("pass"),
|
|
323
|
+
hint: t("passHint"),
|
|
324
|
+
value: draft.pass,
|
|
325
|
+
password: true,
|
|
326
|
+
disabled,
|
|
327
|
+
badge: {
|
|
328
|
+
text: wire.smtp.passConfigured ? t("passSet") : t("passUnset"),
|
|
329
|
+
set: wire.smtp.passConfigured
|
|
330
|
+
},
|
|
331
|
+
onEdit: (v) => edit("pass", v)
|
|
332
|
+
}),
|
|
333
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
334
|
+
id: "dne-from",
|
|
335
|
+
label: t("from"),
|
|
336
|
+
hint: t("fromHint"),
|
|
337
|
+
value: draft.from,
|
|
338
|
+
disabled,
|
|
339
|
+
onEdit: (v) => edit("from", v)
|
|
340
|
+
}),
|
|
341
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
342
|
+
id: "dne-to",
|
|
343
|
+
label: t("to"),
|
|
344
|
+
hint: t("toHint"),
|
|
345
|
+
value: draft.toText,
|
|
346
|
+
disabled,
|
|
347
|
+
onEdit: (v) => edit("toText", v)
|
|
348
|
+
}),
|
|
349
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
350
|
+
className: "dne-groupLabel",
|
|
351
|
+
children: t("triggerGroup")
|
|
352
|
+
}),
|
|
353
|
+
TRIGGER_KEYS.map((key) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
354
|
+
id: `dne-${key}`,
|
|
355
|
+
label: t(key),
|
|
356
|
+
checked: draft.triggers[key],
|
|
357
|
+
disabled,
|
|
358
|
+
onEdit: (v) => editTrigger(key, v)
|
|
359
|
+
}, key)),
|
|
360
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
361
|
+
id: "dne-debounce",
|
|
362
|
+
label: t("idleDebounceMs"),
|
|
363
|
+
hint: t("idleDebounceMsHint"),
|
|
364
|
+
value: draft.idleDebounceMs,
|
|
365
|
+
numeric: true,
|
|
366
|
+
disabled,
|
|
367
|
+
invalid: !isPositiveInt(draft.idleDebounceMs),
|
|
368
|
+
invalidLabel: t("invalidNumber"),
|
|
369
|
+
onEdit: (v) => edit("idleDebounceMs", v)
|
|
370
|
+
}),
|
|
371
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, {
|
|
372
|
+
id: "dne-maxchars",
|
|
373
|
+
label: t("maxBodyChars"),
|
|
374
|
+
hint: t("maxBodyCharsHint"),
|
|
375
|
+
value: draft.maxBodyChars,
|
|
376
|
+
numeric: true,
|
|
377
|
+
disabled,
|
|
378
|
+
invalid: !isPositiveInt(draft.maxBodyChars) || Number(draft.maxBodyChars) < 200,
|
|
379
|
+
invalidLabel: t("invalidNumber"),
|
|
380
|
+
onEdit: (v) => edit("maxBodyChars", v)
|
|
381
|
+
}),
|
|
382
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckRow, {
|
|
383
|
+
id: "dne-dryrun",
|
|
384
|
+
label: t("dryRun"),
|
|
385
|
+
checked: draft.dryRun,
|
|
386
|
+
disabled,
|
|
387
|
+
onEdit: (v) => edit("dryRun", v)
|
|
388
|
+
}),
|
|
389
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
390
|
+
className: "dne-footer",
|
|
391
|
+
children: [
|
|
392
|
+
status.kind !== "idle" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
393
|
+
className: `dne-status${status.kind === "error" ? " dne-statusError" : ""}`,
|
|
394
|
+
role: "status",
|
|
395
|
+
children: status.text
|
|
396
|
+
}) : null,
|
|
397
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
398
|
+
type: "button",
|
|
399
|
+
className: "dne-btn dne-btnGhost",
|
|
400
|
+
disabled: testing,
|
|
401
|
+
onClick: onTest,
|
|
402
|
+
children: t(testing ? "testing" : "test")
|
|
403
|
+
}),
|
|
404
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
405
|
+
type: "button",
|
|
406
|
+
className: "dne-btn dne-btnGhost",
|
|
407
|
+
disabled: !dirty || saving,
|
|
408
|
+
onClick: () => {
|
|
409
|
+
setDraft(draftFromWire(wire));
|
|
410
|
+
setStatus(IDLE_STATUS);
|
|
411
|
+
},
|
|
412
|
+
children: t("discard")
|
|
413
|
+
}),
|
|
414
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
415
|
+
type: "button",
|
|
416
|
+
className: "dne-btn dne-btnPrimary",
|
|
417
|
+
disabled: !dirty || invalid || saving || disabled,
|
|
418
|
+
onClick: onSave,
|
|
419
|
+
children: t(saving ? "saving" : "save")
|
|
420
|
+
})
|
|
421
|
+
]
|
|
422
|
+
})
|
|
423
|
+
]
|
|
424
|
+
}) : null]
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/client/i18n.ts
|
|
430
|
+
/**
|
|
431
|
+
* 配置卡片文案(zh/en)。经 ctx.locale.register 注册、bind 取用,与官方卡片同机制。
|
|
432
|
+
* @module notify-email/client/i18n
|
|
433
|
+
*/
|
|
434
|
+
const NS = "dsh-plus-notify-email";
|
|
435
|
+
const zh = {
|
|
436
|
+
title: "邮件通知",
|
|
437
|
+
description: "任务结束、等待决策或出错时向指定邮箱发送邮件。",
|
|
438
|
+
enabled: "启用通知",
|
|
439
|
+
host: "SMTP 服务器",
|
|
440
|
+
hostHint: "如 smtp.qq.com、smtp.163.com。",
|
|
441
|
+
port: "端口",
|
|
442
|
+
portHint: "465(TLS)或 587(STARTTLS)。",
|
|
443
|
+
secure: "TLS 直连",
|
|
444
|
+
user: "登录用户名",
|
|
445
|
+
userHint: "通常为发件邮箱地址;免认证服务器可留空。",
|
|
446
|
+
pass: "密码 / 授权码",
|
|
447
|
+
passHint: "留空表示保持已存密码不变。",
|
|
448
|
+
passSet: "已配置",
|
|
449
|
+
passUnset: "未配置",
|
|
450
|
+
from: "发件地址",
|
|
451
|
+
fromHint: "邮件 From 头,通常与登录用户名一致。",
|
|
452
|
+
to: "收件邮箱",
|
|
453
|
+
toHint: "多个收件人用英文逗号分隔。",
|
|
454
|
+
triggerGroup: "通知时机",
|
|
455
|
+
onComplete: "任务执行完毕",
|
|
456
|
+
onError: "报错 / 失败停止",
|
|
457
|
+
onAborted: "被用户取消",
|
|
458
|
+
onQuestion: "提问等待回答",
|
|
459
|
+
onPlanReview: "Plan 待审批",
|
|
460
|
+
idleDebounceMs: "空闲确认(毫秒)",
|
|
461
|
+
idleDebounceMsHint: "任务结束后等待该时长确认无后续工作再发信。",
|
|
462
|
+
maxBodyChars: "正文截断长度",
|
|
463
|
+
maxBodyCharsHint: "邮件正文内容超过该长度时截断。",
|
|
464
|
+
dryRun: "仅记录日志(不真实发送)",
|
|
465
|
+
save: "保存",
|
|
466
|
+
saving: "保存中…",
|
|
467
|
+
discard: "放弃",
|
|
468
|
+
unsaved: "未保存",
|
|
469
|
+
test: "发送测试邮件",
|
|
470
|
+
testing: "发送中…",
|
|
471
|
+
testOk: "测试邮件已发送。",
|
|
472
|
+
testDryRun: "已按 dry-run 记录日志(未真实发送)。",
|
|
473
|
+
testFailed: "测试发送失败:",
|
|
474
|
+
saveFailed: "保存失败,请检查填写内容。",
|
|
475
|
+
loading: "加载中…",
|
|
476
|
+
unavailable: "配置服务不可用。",
|
|
477
|
+
readOnly: "当前部署无 settings provider,配置为只读;请编辑 settings.yaml。",
|
|
478
|
+
expand: "展开",
|
|
479
|
+
collapse: "收起",
|
|
480
|
+
invalidNumber: "请输入有效数字",
|
|
481
|
+
incomplete: "SMTP 配置不完整(服务器/发件地址/收件人必填)。"
|
|
482
|
+
};
|
|
483
|
+
const en = {
|
|
484
|
+
title: "Email notifications",
|
|
485
|
+
description: "Email a mailbox when a task finishes, awaits a decision, or fails.",
|
|
486
|
+
enabled: "Enable notifications",
|
|
487
|
+
host: "SMTP host",
|
|
488
|
+
hostHint: "e.g. smtp.qq.com, smtp.gmail.com.",
|
|
489
|
+
port: "Port",
|
|
490
|
+
portHint: "465 (TLS) or 587 (STARTTLS).",
|
|
491
|
+
secure: "Direct TLS",
|
|
492
|
+
user: "Username",
|
|
493
|
+
userHint: "Usually the sender address; leave empty for auth-less servers.",
|
|
494
|
+
pass: "Password / app token",
|
|
495
|
+
passHint: "Leave blank to keep the stored password.",
|
|
496
|
+
passSet: "Configured",
|
|
497
|
+
passUnset: "Not configured",
|
|
498
|
+
from: "From address",
|
|
499
|
+
fromHint: "The From header, usually same as the username.",
|
|
500
|
+
to: "Recipients",
|
|
501
|
+
toHint: "Separate multiple recipients with commas.",
|
|
502
|
+
triggerGroup: "Notify when",
|
|
503
|
+
onComplete: "Task completed",
|
|
504
|
+
onError: "Task failed",
|
|
505
|
+
onAborted: "Cancelled by user",
|
|
506
|
+
onQuestion: "Waiting for an answer",
|
|
507
|
+
onPlanReview: "Plan pending approval",
|
|
508
|
+
idleDebounceMs: "Idle confirmation (ms)",
|
|
509
|
+
idleDebounceMsHint: "Wait this long after completion to confirm no follow-up work.",
|
|
510
|
+
maxBodyChars: "Body truncation",
|
|
511
|
+
maxBodyCharsHint: "Truncate mail body content beyond this length.",
|
|
512
|
+
dryRun: "Log only (do not send)",
|
|
513
|
+
save: "Save",
|
|
514
|
+
saving: "Saving…",
|
|
515
|
+
discard: "Discard",
|
|
516
|
+
unsaved: "Unsaved",
|
|
517
|
+
test: "Send test email",
|
|
518
|
+
testing: "Sending…",
|
|
519
|
+
testOk: "Test email sent.",
|
|
520
|
+
testDryRun: "Recorded as dry-run (not actually sent).",
|
|
521
|
+
testFailed: "Test failed: ",
|
|
522
|
+
saveFailed: "Save failed; please check the fields.",
|
|
523
|
+
loading: "Loading…",
|
|
524
|
+
unavailable: "Configuration service unavailable.",
|
|
525
|
+
readOnly: "No settings provider in this deployment; edit settings.yaml instead.",
|
|
526
|
+
expand: "Expand",
|
|
527
|
+
collapse: "Collapse",
|
|
528
|
+
invalidNumber: "Enter a valid number",
|
|
529
|
+
incomplete: "SMTP config incomplete (host/from/recipients required)."
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region src/client/styles.ts
|
|
534
|
+
/**
|
|
535
|
+
* 配置卡片样式:沿用官方 data-plugin / data-plugin-css 约定(HMR 据此卸载),
|
|
536
|
+
* 视觉对齐官方卡片(--dsw-alias-* 变量),不覆盖上游任何选择器。
|
|
537
|
+
* @module notify-email/client/styles
|
|
538
|
+
*/
|
|
539
|
+
const PLUGIN_ID = "@dsh-plus/notify-email";
|
|
540
|
+
const STYLE_TAG_ID = `${PLUGIN_ID}/card.css`;
|
|
541
|
+
const cardCss = `
|
|
542
|
+
.dne-card{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:12px;list-style:none;transition:border-color .16s,background .16s}
|
|
543
|
+
.dne-card:hover{border-color:var(--dsw-alias-label-dimmed)}
|
|
544
|
+
.dne-cardOpen{background:var(--dsw-alias-bg-layer-2);border-color:var(--dsw-alias-label-dimmed)}
|
|
545
|
+
.dne-header{appearance:none;width:100%;font:inherit;color:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:12px;align-items:center;gap:12px;padding:14px 16px;display:flex}
|
|
546
|
+
.dne-header:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:-2px}
|
|
547
|
+
.dne-headText{flex-direction:column;flex:1;gap:4px;min-width:0;display:flex}
|
|
548
|
+
.dne-name{color:var(--dsw-alias-label-primary);font-size:15px;font-weight:600;line-height:1.4}
|
|
549
|
+
.dne-description{color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1.5}
|
|
550
|
+
.dne-chevron{color:var(--dsw-alias-label-tertiary);flex:none;transition:transform .16s;font-size:12px}
|
|
551
|
+
.dne-chevronOpen{transform:rotate(180deg)}
|
|
552
|
+
.dne-pending{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;flex:none;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
553
|
+
.dne-body{border-top:1px solid var(--dsw-alias-border-l2);margin:0 16px;padding-bottom:8px}
|
|
554
|
+
.dne-field{flex-direction:column;gap:6px;padding:12px 0;display:flex}
|
|
555
|
+
.dne-field+.dne-field{border-top:1px solid var(--dsw-alias-border-l2)}
|
|
556
|
+
.dne-head{align-items:center;gap:8px;display:flex}
|
|
557
|
+
.dne-label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}
|
|
558
|
+
.dne-badge{white-space:nowrap;border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}
|
|
559
|
+
.dne-badgeSet{background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary)}
|
|
560
|
+
.dne-badgeUnset{color:var(--dsw-alias-label-tertiary)}
|
|
561
|
+
.dne-input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px}
|
|
562
|
+
.dne-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}
|
|
563
|
+
.dne-input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}
|
|
564
|
+
.dne-inputInvalid{border-color:var(--dsw-alias-label-error)}
|
|
565
|
+
.dne-hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}
|
|
566
|
+
.dne-invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}
|
|
567
|
+
.dne-checkRow{align-items:center;gap:8px;display:flex;padding:6px 0}
|
|
568
|
+
.dne-checkRow input{accent-color:var(--dsw-alias-brand-primary)}
|
|
569
|
+
.dne-checkRow label{color:var(--dsw-alias-label-primary);font-size:13px;line-height:1.5;cursor:pointer}
|
|
570
|
+
.dne-groupLabel{color:var(--dsw-alias-label-secondary);font-size:12px;font-weight:600;padding:12px 0 2px;margin:0}
|
|
571
|
+
.dne-readOnly{color:var(--dsw-alias-label-tertiary);margin:12px 0 0;font-size:12px;line-height:1.5}
|
|
572
|
+
.dne-footer{border-top:1px solid var(--dsw-alias-border-l2);justify-content:flex-end;align-items:center;gap:8px;padding:12px 0 4px;display:flex;flex-wrap:wrap}
|
|
573
|
+
.dne-status{min-width:0;color:var(--dsw-alias-label-secondary);flex:1;margin:0;font-size:12px;line-height:1.5}
|
|
574
|
+
.dne-statusError{color:var(--dsw-alias-label-error)}
|
|
575
|
+
.dne-btn{appearance:none;font:inherit;cursor:pointer;border:1px solid #0000;border-radius:8px;padding:5px 14px;font-size:13px;line-height:1.5}
|
|
576
|
+
.dne-btnGhost{border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-secondary);background:0 0}
|
|
577
|
+
.dne-btnGhost:hover:not(:disabled){color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-label-dimmed)}
|
|
578
|
+
.dne-btnPrimary{background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-layer-3)}
|
|
579
|
+
.dne-btn:disabled{opacity:.4;cursor:default}
|
|
580
|
+
.dne-btn:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}
|
|
581
|
+
`;
|
|
582
|
+
/** 幂等注入样式标签;返回标签(已存在或环境无 document 时为 null)。 */
|
|
583
|
+
function injectStyle() {
|
|
584
|
+
if (typeof document === "undefined") return null;
|
|
585
|
+
if (document.querySelector(`style[data-plugin-css=${JSON.stringify(STYLE_TAG_ID)}]`) !== null) return null;
|
|
586
|
+
const tag = document.createElement("style");
|
|
587
|
+
tag.dataset.plugin = PLUGIN_ID;
|
|
588
|
+
tag.dataset.pluginCss = STYLE_TAG_ID;
|
|
589
|
+
tag.textContent = cardCss;
|
|
590
|
+
document.head.appendChild(tag);
|
|
591
|
+
return tag;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
//#endregion
|
|
595
|
+
//#region src/client/client.ts
|
|
596
|
+
const name = "dsh-plus-notify-email";
|
|
597
|
+
/** 浏览器半需要的 cordis 服务 key(loader 据此注入;package.json 的 dsh.client.inject 管包加载顺序)。 */
|
|
598
|
+
const inject = ["slots", "locale"];
|
|
599
|
+
function apply(ctx) {
|
|
600
|
+
const c = ctx;
|
|
601
|
+
const tag = injectStyle();
|
|
602
|
+
c.effect(() => () => {
|
|
603
|
+
tag?.remove();
|
|
604
|
+
}, "notify-email: style");
|
|
605
|
+
c.effect(() => c.locale.register(NS, {
|
|
606
|
+
zh,
|
|
607
|
+
en
|
|
608
|
+
}), "notify-email: locale");
|
|
609
|
+
c.slots.inject("settings.plugin.item", () => c.slots.register({
|
|
610
|
+
name: "settings.plugin.item",
|
|
611
|
+
id: "notify-email",
|
|
612
|
+
order: 100,
|
|
613
|
+
locale: NS,
|
|
614
|
+
inject: () => ({ t: c.locale.bind(NS) })
|
|
615
|
+
}, NotifyEmailCard));
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
//#endregion
|
|
619
|
+
exports.apply = apply;
|
|
620
|
+
exports.inject = inject;
|
|
621
|
+
exports.name = name;
|
|
622
|
+
return module.exports;
|
|
623
|
+
}
|
|
624
|
+
});
|