run402 1.20.0 → 1.21.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/lib/email.mjs +34 -10
- package/lib/projects.mjs +13 -2
- package/package.json +1 -1
package/lib/email.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { findProject, resolveProjectId, API, updateProject, loadKeyStore, saveKeyStore } from "./config.mjs";
|
|
2
2
|
|
|
3
|
-
const HELP = `run402 email — Send
|
|
3
|
+
const HELP = `run402 email — Send emails from your project
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
6
6
|
run402 email <subcommand> [args...]
|
|
@@ -8,11 +8,15 @@ Usage:
|
|
|
8
8
|
Subcommands:
|
|
9
9
|
create <slug> [--project <id>] Create a mailbox (<slug>@mail.run402.com)
|
|
10
10
|
status [--project <id>] Show mailbox info (ID, address, slug)
|
|
11
|
-
send --
|
|
12
|
-
Send a template email
|
|
11
|
+
send --to <email> [mode flags] Send an email (template or raw HTML)
|
|
13
12
|
list [--project <id>] List sent emails
|
|
14
13
|
get <message_id> [--project <id>] Get a message with replies
|
|
15
14
|
|
|
15
|
+
Send modes:
|
|
16
|
+
Template: --template <name> --var key=value [--var ...]
|
|
17
|
+
Raw HTML: --subject "..." --html "..." [--text "..."]
|
|
18
|
+
Both modes support: --from-name "Display Name" --project <id>
|
|
19
|
+
|
|
16
20
|
Templates:
|
|
17
21
|
project_invite — requires --var project_name=... --var invite_url=...
|
|
18
22
|
magic_link — requires --var project_name=... --var link_url=... --var expires_in=...
|
|
@@ -22,6 +26,8 @@ Examples:
|
|
|
22
26
|
run402 email create my-app
|
|
23
27
|
run402 email send --template project_invite --to user@example.com \\
|
|
24
28
|
--var project_name="My App" --var invite_url="https://example.com/invite/abc"
|
|
29
|
+
run402 email send --to user@example.com --subject "Welcome!" \\
|
|
30
|
+
--html "<h1>Hello</h1><p>Welcome aboard.</p>" --from-name "My App"
|
|
25
31
|
run402 email send --template notification --to admin@example.com \\
|
|
26
32
|
--var project_name="My App" --var message="Deploy complete"
|
|
27
33
|
run402 email list
|
|
@@ -31,7 +37,7 @@ Notes:
|
|
|
31
37
|
- One mailbox per project
|
|
32
38
|
- Single recipient per send (no CC/BCC)
|
|
33
39
|
- Slug: 3-63 chars, lowercase alphanumeric + hyphens, no consecutive hyphens
|
|
34
|
-
- Rate limits vary by tier (prototype: 10/day, hobby: 50/day, team:
|
|
40
|
+
- Rate limits vary by tier (prototype: 10/day, hobby: 50/day, team: 500/day)
|
|
35
41
|
- --project defaults to the active project
|
|
36
42
|
`;
|
|
37
43
|
|
|
@@ -147,25 +153,43 @@ async function create(args) {
|
|
|
147
153
|
async function send(args) {
|
|
148
154
|
const template = parseFlag(args, "--template");
|
|
149
155
|
const to = parseFlag(args, "--to");
|
|
156
|
+
const subject = parseFlag(args, "--subject");
|
|
157
|
+
const html = parseFlag(args, "--html");
|
|
158
|
+
const text = parseFlag(args, "--text");
|
|
159
|
+
const fromName = parseFlag(args, "--from-name");
|
|
150
160
|
const projectId = resolveProjectId(parseFlag(args, "--project"));
|
|
151
161
|
const p = findProject(projectId);
|
|
152
162
|
const variables = parseVars(args);
|
|
153
163
|
|
|
154
|
-
if (!template) {
|
|
155
|
-
console.error(JSON.stringify({ status: "error", message: "Missing --template. Options: project_invite, magic_link, notification" }));
|
|
156
|
-
process.exit(1);
|
|
157
|
-
}
|
|
158
164
|
if (!to) {
|
|
159
165
|
console.error(JSON.stringify({ status: "error", message: "Missing --to <email>" }));
|
|
160
166
|
process.exit(1);
|
|
161
167
|
}
|
|
162
168
|
|
|
169
|
+
const isRaw = !!(subject || html);
|
|
170
|
+
const isTemplate = !!template;
|
|
171
|
+
if (!isRaw && !isTemplate) {
|
|
172
|
+
console.error(JSON.stringify({ status: "error", message: "Provide --template (template mode) or --subject + --html (raw HTML mode)" }));
|
|
173
|
+
process.exit(1);
|
|
174
|
+
}
|
|
175
|
+
|
|
163
176
|
const mailboxId = await requireMailboxId(projectId, p.service_key);
|
|
164
177
|
|
|
178
|
+
const body = { to };
|
|
179
|
+
if (isTemplate) {
|
|
180
|
+
body.template = template;
|
|
181
|
+
body.variables = variables;
|
|
182
|
+
} else {
|
|
183
|
+
body.subject = subject;
|
|
184
|
+
body.html = html;
|
|
185
|
+
if (text) body.text = text;
|
|
186
|
+
}
|
|
187
|
+
if (fromName) body.from_name = fromName;
|
|
188
|
+
|
|
165
189
|
const res = await fetch(`${API}/mailboxes/v1/${mailboxId}/messages`, {
|
|
166
190
|
method: "POST",
|
|
167
191
|
headers: { "Authorization": `Bearer ${p.service_key}`, "Content-Type": "application/json" },
|
|
168
|
-
body: JSON.stringify(
|
|
192
|
+
body: JSON.stringify(body),
|
|
169
193
|
});
|
|
170
194
|
const data = await res.json();
|
|
171
195
|
if (!res.ok) {
|
|
@@ -173,7 +197,7 @@ async function send(args) {
|
|
|
173
197
|
process.exit(1);
|
|
174
198
|
}
|
|
175
199
|
|
|
176
|
-
console.log(JSON.stringify({ status: "ok", message_id: data.id, to: data.to, template: data.template }));
|
|
200
|
+
console.log(JSON.stringify({ status: "ok", message_id: data.id, to: data.to, template: data.template || null, subject: data.subject || null }));
|
|
177
201
|
}
|
|
178
202
|
|
|
179
203
|
async function list(args) {
|
package/lib/projects.mjs
CHANGED
|
@@ -13,7 +13,7 @@ Subcommands:
|
|
|
13
13
|
list List all your projects (IDs, URLs, active marker)
|
|
14
14
|
info <id> Show project details: REST URL, keys
|
|
15
15
|
keys <id> Print anon_key and service_key as JSON
|
|
16
|
-
sql <id> "<query>" [--file <path>]
|
|
16
|
+
sql <id> "<query>" [--file <path>] [--params '<json>'] Run a SQL query (supports parameterized queries)
|
|
17
17
|
rest <id> <table> [params] Query a table via the REST API (PostgREST)
|
|
18
18
|
usage <id> Show compute/storage usage for a project
|
|
19
19
|
schema <id> Inspect the database schema
|
|
@@ -29,6 +29,7 @@ Examples:
|
|
|
29
29
|
run402 projects list
|
|
30
30
|
run402 projects info abc123
|
|
31
31
|
run402 projects sql abc123 "SELECT * FROM users LIMIT 5"
|
|
32
|
+
run402 projects sql abc123 "SELECT * FROM users WHERE id = $1" --params '[42]'
|
|
32
33
|
run402 projects sql abc123 --file setup.sql
|
|
33
34
|
run402 projects rest abc123 users "limit=10&select=id,name"
|
|
34
35
|
run402 projects usage abc123
|
|
@@ -121,13 +122,23 @@ async function sqlCmd(projectId, args = []) {
|
|
|
121
122
|
const p = findProject(projectId);
|
|
122
123
|
let file = null;
|
|
123
124
|
let query = null;
|
|
125
|
+
let paramsRaw = null;
|
|
124
126
|
for (let i = 0; i < args.length; i++) {
|
|
125
127
|
if (args[i] === "--file" && args[i + 1]) { file = args[++i]; }
|
|
128
|
+
else if (args[i] === "--params" && args[i + 1]) { paramsRaw = args[++i]; }
|
|
126
129
|
else if (!query && !args[i].startsWith("--")) { query = args[i]; }
|
|
127
130
|
}
|
|
128
131
|
const sql = file ? readFileSync(file, "utf-8") : query;
|
|
129
132
|
if (!sql) { console.error(JSON.stringify({ status: "error", message: "Missing SQL query. Provide inline or use --file <path>" })); process.exit(1); }
|
|
130
|
-
|
|
133
|
+
let params;
|
|
134
|
+
if (paramsRaw) {
|
|
135
|
+
try { params = JSON.parse(paramsRaw); } catch { console.error(JSON.stringify({ status: "error", message: "Invalid JSON for --params. Expected a JSON array, e.g. '[42, \"hello\"]'" })); process.exit(1); }
|
|
136
|
+
if (!Array.isArray(params)) { console.error(JSON.stringify({ status: "error", message: "--params must be a JSON array, e.g. '[42, \"hello\"]'" })); process.exit(1); }
|
|
137
|
+
}
|
|
138
|
+
const useParams = params && params.length > 0;
|
|
139
|
+
const headers = { "Authorization": `Bearer ${p.service_key}`, "Content-Type": useParams ? "application/json" : "text/plain" };
|
|
140
|
+
const body = useParams ? JSON.stringify({ sql, params }) : sql;
|
|
141
|
+
const res = await fetch(`${API}/projects/v1/admin/${projectId}/sql`, { method: "POST", headers, body });
|
|
131
142
|
console.log(JSON.stringify(await res.json(), null, 2));
|
|
132
143
|
}
|
|
133
144
|
|
package/package.json
CHANGED