run402 1.19.1 → 1.19.2
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/lib/email.mjs +35 -0
- package/package.json +1 -1
package/lib/email.mjs
CHANGED
|
@@ -7,6 +7,7 @@ Usage:
|
|
|
7
7
|
|
|
8
8
|
Subcommands:
|
|
9
9
|
create <slug> [--project <id>] Create a mailbox (<slug>@mail.run402.com)
|
|
10
|
+
status [--project <id>] Show mailbox info (ID, address, slug)
|
|
10
11
|
send --template <name> --to <email> [--var key=value ...] [--project <id>]
|
|
11
12
|
Send a template email
|
|
12
13
|
list [--project <id>] List sent emails
|
|
@@ -111,6 +112,16 @@ async function create(args) {
|
|
|
111
112
|
});
|
|
112
113
|
const data = await res.json();
|
|
113
114
|
if (!res.ok) {
|
|
115
|
+
// On 409 (mailbox already exists), discover existing mailbox and return it
|
|
116
|
+
if (res.status === 409) {
|
|
117
|
+
const mbId = await resolveMailboxId(projectId, p.service_key).catch(() => null);
|
|
118
|
+
if (mbId) {
|
|
119
|
+
const store = loadKeyStore();
|
|
120
|
+
const proj = store.projects[projectId];
|
|
121
|
+
console.log(JSON.stringify({ status: "ok", mailbox_id: mbId, address: proj?.mailbox_address || mbId, already_existed: true }));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
114
125
|
console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
|
|
115
126
|
process.exit(1);
|
|
116
127
|
}
|
|
@@ -192,10 +203,34 @@ async function get(args) {
|
|
|
192
203
|
console.log(JSON.stringify(data, null, 2));
|
|
193
204
|
}
|
|
194
205
|
|
|
206
|
+
async function status(args) {
|
|
207
|
+
const projectId = resolveProjectId(parseFlag(args, "--project"));
|
|
208
|
+
const p = findProject(projectId);
|
|
209
|
+
|
|
210
|
+
const res = await fetch(`${API}/mailboxes/v1`, {
|
|
211
|
+
headers: { "Authorization": `Bearer ${p.service_key}` },
|
|
212
|
+
});
|
|
213
|
+
if (!res.ok) {
|
|
214
|
+
const data = await res.json().catch(() => ({}));
|
|
215
|
+
console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
|
|
216
|
+
process.exit(1);
|
|
217
|
+
}
|
|
218
|
+
const body = await res.json();
|
|
219
|
+
const mailboxes = body.mailboxes || body;
|
|
220
|
+
if (!Array.isArray(mailboxes) || mailboxes.length === 0) {
|
|
221
|
+
console.error(JSON.stringify({ status: "error", message: "No mailbox found. Run: run402 email create <slug>" }));
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
const mb = mailboxes[0];
|
|
225
|
+
updateProject(projectId, { mailbox_id: mb.mailbox_id, mailbox_address: mb.address });
|
|
226
|
+
console.log(JSON.stringify({ status: "ok", mailbox_id: mb.mailbox_id, address: mb.address, slug: mb.slug }));
|
|
227
|
+
}
|
|
228
|
+
|
|
195
229
|
export async function run(sub, args) {
|
|
196
230
|
if (!sub || sub === '--help' || sub === '-h') { console.log(HELP); process.exit(0); }
|
|
197
231
|
switch (sub) {
|
|
198
232
|
case "create": await create(args); break;
|
|
233
|
+
case "status": await status(args); break;
|
|
199
234
|
case "send": await send(args); break;
|
|
200
235
|
case "list": await list(args); break;
|
|
201
236
|
case "get": await get(args); break;
|
package/package.json
CHANGED