run402 1.19.3 → 1.19.5
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 +30 -11
- package/lib/secrets.mjs +1 -1
- package/package.json +1 -1
package/lib/email.mjs
CHANGED
|
@@ -69,23 +69,37 @@ async function resolveMailboxId(projectId, serviceKey) {
|
|
|
69
69
|
});
|
|
70
70
|
if (!res.ok) {
|
|
71
71
|
const data = await res.json().catch(() => ({}));
|
|
72
|
-
|
|
73
|
-
process.exit(1);
|
|
72
|
+
throw Object.assign(new Error("Failed to resolve mailbox"), { http: res.status, ...data });
|
|
74
73
|
}
|
|
75
74
|
const body = await res.json();
|
|
76
75
|
const mailboxes = body.mailboxes || body;
|
|
77
76
|
if (!Array.isArray(mailboxes) || mailboxes.length === 0) {
|
|
78
|
-
|
|
79
|
-
process.exit(1);
|
|
77
|
+
throw new Error("No mailbox found. Run: run402 email create <slug>");
|
|
80
78
|
}
|
|
81
79
|
const mb = mailboxes[0];
|
|
82
80
|
updateProject(projectId, { mailbox_id: mb.mailbox_id, mailbox_address: mb.address });
|
|
83
81
|
return mb.mailbox_id;
|
|
84
82
|
}
|
|
85
83
|
|
|
84
|
+
async function requireMailboxId(projectId, serviceKey) {
|
|
85
|
+
try {
|
|
86
|
+
return await resolveMailboxId(projectId, serviceKey);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
const out = { status: "error", message: err.message };
|
|
89
|
+
if (err.http) out.http = err.http;
|
|
90
|
+
console.error(JSON.stringify(out));
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
86
95
|
async function create(args) {
|
|
87
|
-
|
|
88
|
-
|
|
96
|
+
let slug = null;
|
|
97
|
+
let projectOpt = null;
|
|
98
|
+
for (let i = 0; i < args.length; i++) {
|
|
99
|
+
if (args[i] === "--project" && args[i + 1]) { projectOpt = args[++i]; }
|
|
100
|
+
else if (!args[i].startsWith("--") && !slug) { slug = args[i]; }
|
|
101
|
+
}
|
|
102
|
+
const projectId = resolveProjectId(projectOpt);
|
|
89
103
|
const p = findProject(projectId);
|
|
90
104
|
|
|
91
105
|
if (!slug) {
|
|
@@ -146,7 +160,7 @@ async function send(args) {
|
|
|
146
160
|
process.exit(1);
|
|
147
161
|
}
|
|
148
162
|
|
|
149
|
-
const mailboxId = await
|
|
163
|
+
const mailboxId = await requireMailboxId(projectId, p.service_key);
|
|
150
164
|
|
|
151
165
|
const res = await fetch(`${API}/mailboxes/v1/${mailboxId}/messages`, {
|
|
152
166
|
method: "POST",
|
|
@@ -165,7 +179,7 @@ async function send(args) {
|
|
|
165
179
|
async function list(args) {
|
|
166
180
|
const projectId = resolveProjectId(parseFlag(args, "--project"));
|
|
167
181
|
const p = findProject(projectId);
|
|
168
|
-
const mailboxId = await
|
|
182
|
+
const mailboxId = await requireMailboxId(projectId, p.service_key);
|
|
169
183
|
|
|
170
184
|
const res = await fetch(`${API}/mailboxes/v1/${mailboxId}/messages`, {
|
|
171
185
|
headers: { "Authorization": `Bearer ${p.service_key}` },
|
|
@@ -180,8 +194,13 @@ async function list(args) {
|
|
|
180
194
|
}
|
|
181
195
|
|
|
182
196
|
async function get(args) {
|
|
183
|
-
|
|
184
|
-
|
|
197
|
+
let messageId = null;
|
|
198
|
+
let projectOpt = null;
|
|
199
|
+
for (let i = 0; i < args.length; i++) {
|
|
200
|
+
if (args[i] === "--project" && args[i + 1]) { projectOpt = args[++i]; }
|
|
201
|
+
else if (!args[i].startsWith("--") && !messageId) { messageId = args[i]; }
|
|
202
|
+
}
|
|
203
|
+
const projectId = resolveProjectId(projectOpt);
|
|
185
204
|
const p = findProject(projectId);
|
|
186
205
|
|
|
187
206
|
if (!messageId) {
|
|
@@ -189,7 +208,7 @@ async function get(args) {
|
|
|
189
208
|
process.exit(1);
|
|
190
209
|
}
|
|
191
210
|
|
|
192
|
-
const mailboxId = await
|
|
211
|
+
const mailboxId = await requireMailboxId(projectId, p.service_key);
|
|
193
212
|
|
|
194
213
|
const res = await fetch(`${API}/mailboxes/v1/${mailboxId}/messages/${messageId}`, {
|
|
195
214
|
headers: { "Authorization": `Bearer ${p.service_key}` },
|
package/lib/secrets.mjs
CHANGED
|
@@ -19,7 +19,7 @@ Examples:
|
|
|
19
19
|
|
|
20
20
|
Notes:
|
|
21
21
|
- Secrets are injected as process.env in serverless functions
|
|
22
|
-
- Values are
|
|
22
|
+
- Values are write-only — list returns keys with a value_hash (first 8 hex chars of SHA-256) for verifying the correct value was set
|
|
23
23
|
`;
|
|
24
24
|
|
|
25
25
|
async function set(projectId, key, args = []) {
|
package/package.json
CHANGED