run402 1.35.4 → 1.36.1
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/ai.mjs +27 -0
- package/lib/allowance.mjs +31 -0
- package/lib/apps.mjs +73 -0
- package/lib/auth.mjs +89 -2
- package/lib/billing.mjs +64 -0
- package/lib/blob.mjs +84 -1
- package/lib/contracts.mjs +139 -0
- package/lib/deploy.mjs +17 -6
- package/lib/domains.mjs +1 -0
- package/lib/email.mjs +51 -0
- package/lib/functions.mjs +90 -1
- package/lib/init.mjs +16 -6
- package/lib/projects.mjs +117 -30
- package/lib/secrets.mjs +26 -1
- package/lib/sender-domain.mjs +1 -0
- package/lib/service.mjs +4 -4
- package/lib/sites.mjs +36 -0
- package/lib/storage.mjs +24 -0
- package/lib/subdomains.mjs +26 -0
- package/lib/tier.mjs +8 -1
- package/lib/webhooks.mjs +42 -0
- package/package.json +1 -1
package/lib/email.mjs
CHANGED
|
@@ -56,6 +56,56 @@ Notes:
|
|
|
56
56
|
- --project defaults to the active project
|
|
57
57
|
`;
|
|
58
58
|
|
|
59
|
+
const SUB_HELP = {
|
|
60
|
+
send: `run402 email send — Send an email (template or raw HTML)
|
|
61
|
+
|
|
62
|
+
Usage:
|
|
63
|
+
run402 email send --to <email> --template <name> --var key=value [--var ...]
|
|
64
|
+
run402 email send --to <email> --subject "..." --html "..." [--text "..."]
|
|
65
|
+
|
|
66
|
+
Options:
|
|
67
|
+
--to <email> Recipient email address (required; single recipient)
|
|
68
|
+
--template <name> Template name (template mode): project_invite, magic_link,
|
|
69
|
+
notification
|
|
70
|
+
--var key=value Template variable (repeatable; required keys vary by
|
|
71
|
+
template)
|
|
72
|
+
--subject "..." Subject line (raw HTML mode)
|
|
73
|
+
--html "..." HTML body (raw HTML mode)
|
|
74
|
+
--text "..." Plain-text body (raw HTML mode; optional)
|
|
75
|
+
--from-name "..." Display name for the From header
|
|
76
|
+
--project <id> Project ID (defaults to the active project)
|
|
77
|
+
|
|
78
|
+
Templates:
|
|
79
|
+
project_invite --var project_name=... --var invite_url=...
|
|
80
|
+
magic_link --var project_name=... --var link_url=... --var expires_in=...
|
|
81
|
+
notification --var project_name=... --var message=... (max 500 chars)
|
|
82
|
+
|
|
83
|
+
Examples:
|
|
84
|
+
run402 email send --template project_invite --to user@example.com \\
|
|
85
|
+
--var project_name="My App" --var invite_url="https://example.com/invite/abc"
|
|
86
|
+
run402 email send --to user@example.com --subject "Welcome!" \\
|
|
87
|
+
--html "<h1>Hello</h1><p>Welcome aboard.</p>" --from-name "My App"
|
|
88
|
+
run402 email send --template notification --to admin@example.com \\
|
|
89
|
+
--var project_name="My App" --var message="Deploy complete"
|
|
90
|
+
`,
|
|
91
|
+
"get-raw": `run402 email get-raw — Fetch raw RFC-822 bytes for an inbound message
|
|
92
|
+
|
|
93
|
+
Usage:
|
|
94
|
+
run402 email get-raw <message_id> [--output <file>] [--project <id>]
|
|
95
|
+
|
|
96
|
+
Arguments:
|
|
97
|
+
<message_id> Message ID to fetch (inbound messages only)
|
|
98
|
+
|
|
99
|
+
Options:
|
|
100
|
+
--output <file> Write raw bytes to this file; omit to stream to stdout
|
|
101
|
+
--project <id> Project ID (defaults to the active project)
|
|
102
|
+
|
|
103
|
+
Examples:
|
|
104
|
+
run402 email get-raw msg_abc123 --output reply.eml
|
|
105
|
+
run402 email get-raw msg_abc123 > reply.eml
|
|
106
|
+
`,
|
|
107
|
+
};
|
|
108
|
+
|
|
59
109
|
const SLUG_RE = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/;
|
|
60
110
|
|
|
61
111
|
function parseFlag(args, flag) {
|
|
@@ -327,6 +377,7 @@ async function status(args) {
|
|
|
327
377
|
|
|
328
378
|
export async function run(sub, args) {
|
|
329
379
|
if (!sub || sub === '--help' || sub === '-h') { console.log(HELP); process.exit(0); }
|
|
380
|
+
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h")) && sub !== "webhooks") { console.log(SUB_HELP[sub] || HELP); process.exit(0); }
|
|
330
381
|
switch (sub) {
|
|
331
382
|
case "create": await create(args); break;
|
|
332
383
|
case "status": await status(args); break;
|
package/lib/functions.mjs
CHANGED
|
@@ -38,6 +38,95 @@ Notes:
|
|
|
38
38
|
- Deploy may require payment if the project lease has expired
|
|
39
39
|
`;
|
|
40
40
|
|
|
41
|
+
const SUB_HELP = {
|
|
42
|
+
deploy: `run402 functions deploy — Deploy a function to a project
|
|
43
|
+
|
|
44
|
+
Usage:
|
|
45
|
+
run402 functions deploy <project_id> <name> --file <file> [options]
|
|
46
|
+
|
|
47
|
+
Arguments:
|
|
48
|
+
<project_id> Target project ID
|
|
49
|
+
<name> Function name (used in the invoke URL path)
|
|
50
|
+
|
|
51
|
+
Options:
|
|
52
|
+
--file <file> Required: path to the function source file
|
|
53
|
+
--timeout <s> Runtime timeout in seconds
|
|
54
|
+
--memory <mb> Memory in MB
|
|
55
|
+
--deps <pkg,...> Comma-separated npm deps to bundle
|
|
56
|
+
--schedule <cron> Cron schedule; pass '' to clear an existing schedule
|
|
57
|
+
|
|
58
|
+
Notes:
|
|
59
|
+
Code must export a default async function:
|
|
60
|
+
export default async (req: Request) => Response
|
|
61
|
+
Deploy may require payment if the project lease has expired.
|
|
62
|
+
|
|
63
|
+
Examples:
|
|
64
|
+
run402 functions deploy abc123 stripe-webhook --file handler.ts
|
|
65
|
+
run402 functions deploy abc123 send-reminders --file remind.ts \\
|
|
66
|
+
--schedule '*/15 * * * *'
|
|
67
|
+
run402 functions deploy abc123 send-reminders --file remind.ts --schedule ''
|
|
68
|
+
`,
|
|
69
|
+
invoke: `run402 functions invoke — Invoke a deployed function
|
|
70
|
+
|
|
71
|
+
Usage:
|
|
72
|
+
run402 functions invoke <project_id> <name> [options]
|
|
73
|
+
|
|
74
|
+
Arguments:
|
|
75
|
+
<project_id> Target project ID
|
|
76
|
+
<name> Function name
|
|
77
|
+
|
|
78
|
+
Options:
|
|
79
|
+
--method <M> HTTP method (default POST)
|
|
80
|
+
--body <json> Request body (ignored for GET/HEAD)
|
|
81
|
+
|
|
82
|
+
Examples:
|
|
83
|
+
run402 functions invoke abc123 stripe-webhook --body '{"event":"test"}'
|
|
84
|
+
run402 functions invoke abc123 ping --method GET
|
|
85
|
+
`,
|
|
86
|
+
logs: `run402 functions logs — Fetch or tail function logs
|
|
87
|
+
|
|
88
|
+
Usage:
|
|
89
|
+
run402 functions logs <project_id> <name> [options]
|
|
90
|
+
|
|
91
|
+
Arguments:
|
|
92
|
+
<project_id> Target project ID
|
|
93
|
+
<name> Function name
|
|
94
|
+
|
|
95
|
+
Options:
|
|
96
|
+
--tail <n> Number of most-recent entries (default 50)
|
|
97
|
+
--since <ts> ISO timestamp or epoch ms; only entries after this
|
|
98
|
+
--follow Poll every 3s and stream new entries (Ctrl-C to stop)
|
|
99
|
+
|
|
100
|
+
Examples:
|
|
101
|
+
run402 functions logs abc123 stripe-webhook --tail 100
|
|
102
|
+
run402 functions logs abc123 stripe-webhook --since 2026-03-29T14:00:00Z
|
|
103
|
+
run402 functions logs abc123 stripe-webhook --follow
|
|
104
|
+
`,
|
|
105
|
+
update: `run402 functions update — Update function config without re-deploying
|
|
106
|
+
|
|
107
|
+
Usage:
|
|
108
|
+
run402 functions update <project_id> <name> [options]
|
|
109
|
+
|
|
110
|
+
Arguments:
|
|
111
|
+
<project_id> Target project ID
|
|
112
|
+
<name> Function name
|
|
113
|
+
|
|
114
|
+
Options:
|
|
115
|
+
--schedule <cron> New cron schedule (pass '' to clear)
|
|
116
|
+
--schedule-remove Explicitly remove the schedule
|
|
117
|
+
--timeout <s> Runtime timeout in seconds
|
|
118
|
+
--memory <mb> Memory in MB
|
|
119
|
+
|
|
120
|
+
Notes:
|
|
121
|
+
Must provide at least one of the options above.
|
|
122
|
+
|
|
123
|
+
Examples:
|
|
124
|
+
run402 functions update abc123 send-reminders --schedule '0 */4 * * *'
|
|
125
|
+
run402 functions update abc123 send-reminders --schedule-remove
|
|
126
|
+
run402 functions update abc123 my-func --timeout 15 --memory 256
|
|
127
|
+
`,
|
|
128
|
+
};
|
|
129
|
+
|
|
41
130
|
async function deploy(projectId, name, args) {
|
|
42
131
|
const p = findProject(projectId);
|
|
43
132
|
const opts = { file: null, timeout: undefined, memory: undefined, deps: undefined, schedule: undefined };
|
|
@@ -213,7 +302,7 @@ async function deleteFunction(projectId, name) {
|
|
|
213
302
|
export async function run(sub, args) {
|
|
214
303
|
if (!sub || sub === '--help' || sub === '-h') { console.log(HELP); process.exit(0); }
|
|
215
304
|
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) {
|
|
216
|
-
console.log(HELP);
|
|
305
|
+
console.log(SUB_HELP[sub] || HELP);
|
|
217
306
|
process.exit(0);
|
|
218
307
|
}
|
|
219
308
|
switch (sub) {
|
package/lib/init.mjs
CHANGED
|
@@ -112,16 +112,23 @@ export async function run(args = []) {
|
|
|
112
112
|
});
|
|
113
113
|
const data = await res.json();
|
|
114
114
|
if (data.result) {
|
|
115
|
-
// Tempo faucet is instant
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
115
|
+
// Tempo faucet is "instant" on-chain, but the client RPC read can be
|
|
116
|
+
// racy relative to faucet settlement — poll up to 30s (GH-81), mirroring
|
|
117
|
+
// the x402 path below.
|
|
118
|
+
for (let i = 0; i < 30; i++) {
|
|
119
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
120
|
+
try {
|
|
121
|
+
const raw = await client.readContract({ address: PATH_USD, abi: USDC_ABI, functionName: "balanceOf", args: [allowance.address] });
|
|
122
|
+
balance = Number(raw);
|
|
123
|
+
if (balance > 0) break;
|
|
124
|
+
} catch {}
|
|
125
|
+
}
|
|
120
126
|
saveAllowance({ ...allowance, funded: true, lastFaucet: new Date().toISOString() });
|
|
127
|
+
summary.allowance.funded = true;
|
|
121
128
|
if (balance > 0) {
|
|
122
129
|
line("Balance", `${(balance / 1e6).toFixed(2)} pathUSD (funded)`);
|
|
123
130
|
} else {
|
|
124
|
-
line("Balance", "faucet sent —
|
|
131
|
+
line("Balance", "faucet sent — not yet confirmed on-chain");
|
|
125
132
|
}
|
|
126
133
|
} else {
|
|
127
134
|
line("Balance", `faucet failed: ${data.error?.message || "unknown error"}`);
|
|
@@ -131,6 +138,7 @@ export async function run(args = []) {
|
|
|
131
138
|
}
|
|
132
139
|
} else {
|
|
133
140
|
line("Balance", `${(balance / 1e6).toFixed(2)} pathUSD`);
|
|
141
|
+
summary.allowance.funded = balance > 0;
|
|
134
142
|
}
|
|
135
143
|
summary.balance = { symbol: "pathUSD", usd_micros: balance };
|
|
136
144
|
} else {
|
|
@@ -162,6 +170,7 @@ export async function run(args = []) {
|
|
|
162
170
|
} catch {}
|
|
163
171
|
}
|
|
164
172
|
saveAllowance({ ...allowance, funded: true, lastFaucet: new Date().toISOString() });
|
|
173
|
+
summary.allowance.funded = true;
|
|
165
174
|
if (balance > 0) {
|
|
166
175
|
line("Balance", `${(balance / 1e6).toFixed(2)} USDC (funded)`);
|
|
167
176
|
} else {
|
|
@@ -174,6 +183,7 @@ export async function run(args = []) {
|
|
|
174
183
|
}
|
|
175
184
|
} else {
|
|
176
185
|
line("Balance", `${(balance / 1e6).toFixed(2)} USDC`);
|
|
186
|
+
summary.allowance.funded = balance > 0;
|
|
177
187
|
}
|
|
178
188
|
summary.balance = { symbol: "USDC", usd_micros: balance };
|
|
179
189
|
}
|
package/lib/projects.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readFileSync } from "fs";
|
|
2
|
-
import { findProject, loadKeyStore, saveProject, removeProject, API, allowanceAuthHeaders, setActiveProjectId, getActiveProjectId } from "./config.mjs";
|
|
2
|
+
import { findProject, loadKeyStore, saveProject, removeProject, API, allowanceAuthHeaders, setActiveProjectId, getActiveProjectId, resolveProjectId } from "./config.mjs";
|
|
3
3
|
|
|
4
4
|
const HELP = `run402 projects — Manage your deployed Run402 projects
|
|
5
5
|
|
|
@@ -11,17 +11,17 @@ Subcommands:
|
|
|
11
11
|
provision [--tier <tier>] [--name <n>] Provision a new Postgres project (pays via x402)
|
|
12
12
|
use <id> Set the active project (used as default for other commands)
|
|
13
13
|
list List all your projects (IDs, URLs, active marker)
|
|
14
|
-
info
|
|
15
|
-
keys
|
|
16
|
-
sql
|
|
17
|
-
rest
|
|
18
|
-
usage
|
|
19
|
-
schema
|
|
20
|
-
rls
|
|
21
|
-
delete
|
|
22
|
-
pin
|
|
23
|
-
promote-user
|
|
24
|
-
demote-user
|
|
14
|
+
info [id] Show project details: REST URL, keys
|
|
15
|
+
keys [id] Print anon_key and service_key as JSON
|
|
16
|
+
sql [id] "<query>" [--file <path>] [--params '<json>'] Run a SQL query (supports parameterized queries)
|
|
17
|
+
rest [id] <table> [params] Query a table via the REST API (PostgREST)
|
|
18
|
+
usage [id] Show compute/storage usage for a project
|
|
19
|
+
schema [id] Inspect the database schema
|
|
20
|
+
rls [id] <template> <tables_json> Apply Row-Level Security policies
|
|
21
|
+
delete [id] Immediately and irreversibly delete a project (cascade purge) and remove from local state
|
|
22
|
+
pin [id] Pin a project (prevents expiry/GC)
|
|
23
|
+
promote-user [id] <email> Promote a user to project_admin role
|
|
24
|
+
demote-user [id] <email> Demote a user from project_admin role
|
|
25
25
|
|
|
26
26
|
Examples:
|
|
27
27
|
run402 projects quote
|
|
@@ -36,18 +36,66 @@ Examples:
|
|
|
36
36
|
run402 projects rest abc123 users "limit=10&select=id,name"
|
|
37
37
|
run402 projects usage abc123
|
|
38
38
|
run402 projects schema abc123
|
|
39
|
-
run402 projects rls abc123
|
|
39
|
+
run402 projects rls abc123 public_read_authenticated_write '[{"table":"posts"}]'
|
|
40
40
|
run402 projects keys abc123
|
|
41
41
|
run402 projects delete abc123
|
|
42
42
|
|
|
43
43
|
Notes:
|
|
44
|
-
- <id> is the project_id shown in 'run402 projects list'
|
|
45
|
-
- Most commands that take <id> default to the active project
|
|
44
|
+
- <id> is the project_id shown in 'run402 projects list' (prefix: 'prj_')
|
|
45
|
+
- Most commands that take <id> default to the active project when omitted
|
|
46
|
+
(set it with 'run402 projects use <id>'). Project IDs start with 'prj_';
|
|
47
|
+
any first positional that doesn't is treated as the next argument instead.
|
|
46
48
|
- 'rest' uses PostgREST query syntax (table name + optional query string)
|
|
47
49
|
- 'provision' requires a funded allowance — payment is automatic via x402
|
|
48
|
-
- RLS templates
|
|
50
|
+
- RLS templates (prefer user_owns_rows for user-scoped data):
|
|
51
|
+
user_owns_rows users access only their own rows (requires owner_column)
|
|
52
|
+
public_read_authenticated_write anyone reads; any authenticated user writes any row
|
|
53
|
+
public_read_write_UNRESTRICTED fully open (anon_key writes); use 'run402 deploy' with a manifest
|
|
54
|
+
that includes "i_understand_this_is_unrestricted": true
|
|
49
55
|
`;
|
|
50
56
|
|
|
57
|
+
const SUB_HELP = {
|
|
58
|
+
provision: `run402 projects provision — Provision a new Postgres project
|
|
59
|
+
|
|
60
|
+
Usage:
|
|
61
|
+
run402 projects provision [--tier <tier>] [--name <name>]
|
|
62
|
+
|
|
63
|
+
Options:
|
|
64
|
+
--tier <tier> Tier for the new project (default: prototype)
|
|
65
|
+
--name <name> Human-readable name for the project
|
|
66
|
+
|
|
67
|
+
Notes:
|
|
68
|
+
- Payment is automatic via x402; requires a funded allowance
|
|
69
|
+
- The new project becomes the active project after provisioning
|
|
70
|
+
|
|
71
|
+
Examples:
|
|
72
|
+
run402 projects provision
|
|
73
|
+
run402 projects provision --tier prototype
|
|
74
|
+
run402 projects provision --tier hobby --name my-app
|
|
75
|
+
`,
|
|
76
|
+
sql: `run402 projects sql — Run a SQL query against a project's database
|
|
77
|
+
|
|
78
|
+
Usage:
|
|
79
|
+
run402 projects sql [id] "<query>" [options]
|
|
80
|
+
run402 projects sql [id] --file <path> [options]
|
|
81
|
+
|
|
82
|
+
Arguments:
|
|
83
|
+
[id] Project ID (defaults to the active project if omitted;
|
|
84
|
+
must start with 'prj_' — any other first arg is treated
|
|
85
|
+
as the query instead)
|
|
86
|
+
<query> Inline SQL query (quote it to preserve spaces)
|
|
87
|
+
|
|
88
|
+
Options:
|
|
89
|
+
--file <path> Read SQL from a file instead of an inline query
|
|
90
|
+
--params '<json>' JSON array of parameters for a parameterized query
|
|
91
|
+
|
|
92
|
+
Examples:
|
|
93
|
+
run402 projects sql abc123 "SELECT * FROM users LIMIT 5"
|
|
94
|
+
run402 projects sql abc123 "SELECT * FROM users WHERE id = $1" --params '[42]'
|
|
95
|
+
run402 projects sql abc123 --file setup.sql
|
|
96
|
+
`,
|
|
97
|
+
};
|
|
98
|
+
|
|
51
99
|
async function quote() {
|
|
52
100
|
const res = await fetch(`${API}/tiers/v1`);
|
|
53
101
|
const data = await res.json();
|
|
@@ -69,8 +117,34 @@ async function provision(args) {
|
|
|
69
117
|
headers: { "Content-Type": "application/json", ...authHeaders },
|
|
70
118
|
body: JSON.stringify(body),
|
|
71
119
|
});
|
|
72
|
-
|
|
73
|
-
|
|
120
|
+
// Content-type aware parsing: gateways (ALB, CloudFront, etc.) return HTML on
|
|
121
|
+
// 502/504/etc., which would otherwise crash res.json() with SyntaxError (GH-84).
|
|
122
|
+
const contentType = res.headers.get("content-type") || "";
|
|
123
|
+
let data = null;
|
|
124
|
+
let parseError = null;
|
|
125
|
+
let bodyText = null;
|
|
126
|
+
if (contentType.includes("application/json")) {
|
|
127
|
+
try {
|
|
128
|
+
data = await res.json();
|
|
129
|
+
} catch (e) {
|
|
130
|
+
parseError = e;
|
|
131
|
+
try { bodyText = await res.text(); } catch { bodyText = ""; }
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
try { bodyText = await res.text(); } catch { bodyText = ""; }
|
|
135
|
+
}
|
|
136
|
+
if (!res.ok || parseError || data === null) {
|
|
137
|
+
const err = { status: "error", http: res.status, content_type: contentType || null };
|
|
138
|
+
if (data && typeof data === "object") {
|
|
139
|
+
Object.assign(err, data);
|
|
140
|
+
} else {
|
|
141
|
+
const preview = typeof bodyText === "string" ? bodyText.slice(0, 500) : "";
|
|
142
|
+
err.body_preview = preview;
|
|
143
|
+
if (parseError) err.parse_error = "response body was not valid JSON";
|
|
144
|
+
}
|
|
145
|
+
console.error(JSON.stringify(err));
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
74
148
|
// Save project credentials locally and set as active
|
|
75
149
|
if (data.project_id) {
|
|
76
150
|
saveProject(data.project_id, {
|
|
@@ -227,13 +301,26 @@ async function deleteProject(projectId) {
|
|
|
227
301
|
}
|
|
228
302
|
}
|
|
229
303
|
|
|
304
|
+
// Resolve a positional project_id argument with active-project fallback (GH-102).
|
|
305
|
+
// Heuristic: real project IDs start with "prj_". If args[0] is missing OR
|
|
306
|
+
// doesn't start with "prj_", fall back to the active project and return the
|
|
307
|
+
// full args array as remaining positionals. Otherwise consume args[0] as the
|
|
308
|
+
// project_id and return args.slice(1) as remaining positionals.
|
|
309
|
+
function resolvePositionalProject(args) {
|
|
310
|
+
const first = Array.isArray(args) ? args[0] : undefined;
|
|
311
|
+
if (typeof first === "string" && first.startsWith("prj_")) {
|
|
312
|
+
return { projectId: first, rest: args.slice(1) };
|
|
313
|
+
}
|
|
314
|
+
return { projectId: resolveProjectId(null), rest: Array.isArray(args) ? args : [] };
|
|
315
|
+
}
|
|
316
|
+
|
|
230
317
|
export async function run(sub, args) {
|
|
231
318
|
if (!sub || sub === '--help' || sub === '-h') {
|
|
232
319
|
console.log(HELP);
|
|
233
320
|
process.exit(0);
|
|
234
321
|
}
|
|
235
322
|
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) {
|
|
236
|
-
console.log(HELP);
|
|
323
|
+
console.log(SUB_HELP[sub] || HELP);
|
|
237
324
|
process.exit(0);
|
|
238
325
|
}
|
|
239
326
|
switch (sub) {
|
|
@@ -241,17 +328,17 @@ export async function run(sub, args) {
|
|
|
241
328
|
case "provision": await provision(args); break;
|
|
242
329
|
case "use": await use(args[0]); break;
|
|
243
330
|
case "list": await list(); break;
|
|
244
|
-
case "info": await info(
|
|
245
|
-
case "keys": await keys(
|
|
246
|
-
case "sql": await sqlCmd(
|
|
247
|
-
case "rest": await rest(
|
|
248
|
-
case "usage": await usage(
|
|
249
|
-
case "schema": await schema(
|
|
250
|
-
case "rls": await rls(
|
|
251
|
-
case "delete": await deleteProject(
|
|
252
|
-
case "pin":
|
|
253
|
-
case "promote-user": await promoteUser(
|
|
254
|
-
case "demote-user": await demoteUser(
|
|
331
|
+
case "info": { const { projectId } = resolvePositionalProject(args); await info(projectId); break; }
|
|
332
|
+
case "keys": { const { projectId } = resolvePositionalProject(args); await keys(projectId); break; }
|
|
333
|
+
case "sql": { const { projectId, rest } = resolvePositionalProject(args); await sqlCmd(projectId, rest); break; }
|
|
334
|
+
case "rest": { const { projectId, rest: restArgs } = resolvePositionalProject(args); await rest(projectId, restArgs[0], restArgs[1]); break; }
|
|
335
|
+
case "usage": { const { projectId } = resolvePositionalProject(args); await usage(projectId); break; }
|
|
336
|
+
case "schema": { const { projectId } = resolvePositionalProject(args); await schema(projectId); break; }
|
|
337
|
+
case "rls": { const { projectId, rest } = resolvePositionalProject(args); await rls(projectId, rest[0], rest[1]); break; }
|
|
338
|
+
case "delete": { const { projectId } = resolvePositionalProject(args); await deleteProject(projectId); break; }
|
|
339
|
+
case "pin": { const { projectId } = resolvePositionalProject(args); await pin(projectId); break; }
|
|
340
|
+
case "promote-user": { const { projectId, rest } = resolvePositionalProject(args); await promoteUser(projectId, rest[0]); break; }
|
|
341
|
+
case "demote-user": { const { projectId, rest } = resolvePositionalProject(args); await demoteUser(projectId, rest[0]); break; }
|
|
255
342
|
default:
|
|
256
343
|
console.error(`Unknown subcommand: ${sub}\n`);
|
|
257
344
|
console.log(HELP);
|
package/lib/secrets.mjs
CHANGED
|
@@ -22,6 +22,31 @@ Notes:
|
|
|
22
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
|
+
const SUB_HELP = {
|
|
26
|
+
set: `run402 secrets set — Set a secret on a project
|
|
27
|
+
|
|
28
|
+
Usage:
|
|
29
|
+
run402 secrets set <id> <key> <value> [--file <path>]
|
|
30
|
+
run402 secrets set <id> <key> --file <path>
|
|
31
|
+
|
|
32
|
+
Arguments:
|
|
33
|
+
<id> Project ID (from 'run402 projects list')
|
|
34
|
+
<key> Secret key name (exposed as process.env.<key>)
|
|
35
|
+
<value> Inline secret value (omit if using --file)
|
|
36
|
+
|
|
37
|
+
Options:
|
|
38
|
+
--file <path> Read the secret value from a file instead of inline
|
|
39
|
+
|
|
40
|
+
Notes:
|
|
41
|
+
- Secrets are injected as process.env in serverless functions
|
|
42
|
+
- Values are write-only; 'list' returns a value_hash for verification
|
|
43
|
+
|
|
44
|
+
Examples:
|
|
45
|
+
run402 secrets set abc123 STRIPE_KEY sk-1234
|
|
46
|
+
run402 secrets set abc123 TLS_CERT --file cert.pem
|
|
47
|
+
`,
|
|
48
|
+
};
|
|
49
|
+
|
|
25
50
|
async function set(projectId, key, args = []) {
|
|
26
51
|
const p = findProject(projectId);
|
|
27
52
|
let file = null;
|
|
@@ -69,7 +94,7 @@ async function deleteSecret(projectId, key) {
|
|
|
69
94
|
export async function run(sub, args) {
|
|
70
95
|
if (!sub || sub === '--help' || sub === '-h') { console.log(HELP); process.exit(0); }
|
|
71
96
|
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) {
|
|
72
|
-
console.log(HELP);
|
|
97
|
+
console.log(SUB_HELP[sub] || HELP);
|
|
73
98
|
process.exit(0);
|
|
74
99
|
}
|
|
75
100
|
switch (sub) {
|
package/lib/sender-domain.mjs
CHANGED
|
@@ -117,6 +117,7 @@ async function inboundToggle(action, args) {
|
|
|
117
117
|
|
|
118
118
|
export async function run(sub, args) {
|
|
119
119
|
if (!sub || sub === "--help" || sub === "-h") { console.log(HELP); process.exit(0); }
|
|
120
|
+
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) { console.log(HELP); process.exit(0); }
|
|
120
121
|
switch (sub) {
|
|
121
122
|
case "register": await register(args); break;
|
|
122
123
|
case "status": await status(args); break;
|
package/lib/service.mjs
CHANGED
|
@@ -17,15 +17,15 @@ async function fetchAndEmit(path) {
|
|
|
17
17
|
try {
|
|
18
18
|
res = await fetch(`${API}${path}`);
|
|
19
19
|
} catch (err) {
|
|
20
|
-
console.
|
|
21
|
-
|
|
20
|
+
console.error(JSON.stringify({ status: "error", message: err?.message || String(err) }));
|
|
21
|
+
process.exit(1);
|
|
22
22
|
}
|
|
23
23
|
const text = await res.text();
|
|
24
24
|
let body;
|
|
25
25
|
try { body = JSON.parse(text); } catch { body = text; }
|
|
26
26
|
if (!res.ok) {
|
|
27
|
-
console.
|
|
28
|
-
|
|
27
|
+
console.error(JSON.stringify({ status: "error", http: res.status, body }));
|
|
28
|
+
process.exit(1);
|
|
29
29
|
}
|
|
30
30
|
console.log(JSON.stringify(body, null, 2));
|
|
31
31
|
}
|
package/lib/sites.mjs
CHANGED
|
@@ -45,6 +45,41 @@ Notes:
|
|
|
45
45
|
- Free with active tier — requires allowance auth
|
|
46
46
|
`;
|
|
47
47
|
|
|
48
|
+
const SUB_HELP = {
|
|
49
|
+
deploy: `run402 sites deploy — Deploy a static site from a manifest
|
|
50
|
+
|
|
51
|
+
Usage:
|
|
52
|
+
run402 sites deploy --manifest <file> [--project <id>] [--target <target>] [--inherit]
|
|
53
|
+
cat manifest.json | run402 sites deploy [--project <id>] [--target <target>]
|
|
54
|
+
|
|
55
|
+
Options:
|
|
56
|
+
--manifest <file> Path to manifest JSON file (or read from stdin)
|
|
57
|
+
--project <id> Project ID (defaults to the active project)
|
|
58
|
+
--target <target> Deployment target (e.g. 'production')
|
|
59
|
+
--inherit Copy unchanged files from the previous deployment
|
|
60
|
+
(only upload changed files)
|
|
61
|
+
|
|
62
|
+
Manifest format (JSON):
|
|
63
|
+
{
|
|
64
|
+
"files": [
|
|
65
|
+
{ "file": "index.html", "data": "<html>...</html>" },
|
|
66
|
+
{ "file": "style.css", "path": "./dist/style.css" }
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
Paths are resolved relative to the manifest file's directory.
|
|
70
|
+
Binary files are auto-detected and base64-encoded.
|
|
71
|
+
|
|
72
|
+
Notes:
|
|
73
|
+
- Must include at least index.html in the files array
|
|
74
|
+
- Free with active tier — requires allowance auth
|
|
75
|
+
|
|
76
|
+
Examples:
|
|
77
|
+
run402 sites deploy --manifest site.json
|
|
78
|
+
run402 sites deploy --manifest site.json --target production --inherit
|
|
79
|
+
cat site.json | run402 sites deploy
|
|
80
|
+
`,
|
|
81
|
+
};
|
|
82
|
+
|
|
48
83
|
async function readStdin() {
|
|
49
84
|
const chunks = [];
|
|
50
85
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
@@ -96,6 +131,7 @@ async function status(args) {
|
|
|
96
131
|
|
|
97
132
|
export async function run(sub, args) {
|
|
98
133
|
if (!sub || sub === '--help' || sub === '-h') { console.log(HELP); process.exit(0); }
|
|
134
|
+
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) { console.log(SUB_HELP[sub] || HELP); process.exit(0); }
|
|
99
135
|
switch (sub) {
|
|
100
136
|
case "deploy": await deploy(args); break;
|
|
101
137
|
case "status": await status(args); break;
|
package/lib/storage.mjs
CHANGED
|
@@ -25,6 +25,29 @@ Notes:
|
|
|
25
25
|
- Upload reads from --file or stdin if no --file is given
|
|
26
26
|
`;
|
|
27
27
|
|
|
28
|
+
const SUB_HELP = {
|
|
29
|
+
upload: `run402 storage upload — Upload a file to a project's storage bucket
|
|
30
|
+
|
|
31
|
+
Usage:
|
|
32
|
+
run402 storage upload <id> <bucket> <path> [--file <local>] [--content-type <mime>]
|
|
33
|
+
echo "..." | run402 storage upload <id> <bucket> <path> [--content-type <mime>]
|
|
34
|
+
|
|
35
|
+
Arguments:
|
|
36
|
+
<id> Project ID (from 'run402 projects list')
|
|
37
|
+
<bucket> Target bucket name
|
|
38
|
+
<path> Destination path within the bucket
|
|
39
|
+
|
|
40
|
+
Options:
|
|
41
|
+
--file <local> Local file to upload; if omitted, content is read from stdin
|
|
42
|
+
--content-type <mime> MIME type of the upload (default: text/plain)
|
|
43
|
+
|
|
44
|
+
Examples:
|
|
45
|
+
run402 storage upload abc123 assets logo.png --file ./logo.png \\
|
|
46
|
+
--content-type image/png
|
|
47
|
+
echo "hello" | run402 storage upload abc123 data notes.txt
|
|
48
|
+
`,
|
|
49
|
+
};
|
|
50
|
+
|
|
28
51
|
async function readStdin() {
|
|
29
52
|
const chunks = [];
|
|
30
53
|
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
@@ -88,6 +111,7 @@ async function list(projectId, bucket) {
|
|
|
88
111
|
|
|
89
112
|
export async function run(sub, args) {
|
|
90
113
|
if (!sub || sub === '--help' || sub === '-h') { console.log(HELP); process.exit(0); }
|
|
114
|
+
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) { console.log(SUB_HELP[sub] || HELP); process.exit(0); }
|
|
91
115
|
switch (sub) {
|
|
92
116
|
case "upload": await upload(args[0], args[1], args[2], args.slice(3)); break;
|
|
93
117
|
case "download": await download(args[0], args[1], args[2]); break;
|
package/lib/subdomains.mjs
CHANGED
|
@@ -24,6 +24,31 @@ Notes:
|
|
|
24
24
|
- Creates <name>.run402.com pointing to the deployment
|
|
25
25
|
`;
|
|
26
26
|
|
|
27
|
+
const SUB_HELP = {
|
|
28
|
+
claim: `run402 subdomains claim — Claim a custom subdomain for a deployment
|
|
29
|
+
|
|
30
|
+
Usage:
|
|
31
|
+
run402 subdomains claim <name> [--project <id>] [--deployment <id>]
|
|
32
|
+
|
|
33
|
+
Arguments:
|
|
34
|
+
<name> Subdomain name (3-63 chars, lowercase alphanumeric +
|
|
35
|
+
hyphens). Creates <name>.run402.com.
|
|
36
|
+
|
|
37
|
+
Options:
|
|
38
|
+
--project <id> Project ID (defaults to the active project)
|
|
39
|
+
--deployment <id> Deployment ID to point at (defaults to the project's
|
|
40
|
+
last deployment)
|
|
41
|
+
|
|
42
|
+
Notes:
|
|
43
|
+
- Legacy syntax 'claim <deployment_id> <name>' is still supported
|
|
44
|
+
- Deploy a site first (or pass --deployment) so there is a target to claim
|
|
45
|
+
|
|
46
|
+
Examples:
|
|
47
|
+
run402 subdomains claim myapp
|
|
48
|
+
run402 subdomains claim myapp --deployment dpl_abc123 --project proj123
|
|
49
|
+
`,
|
|
50
|
+
};
|
|
51
|
+
|
|
27
52
|
async function claim(positionalArgs, flagArgs) {
|
|
28
53
|
const opts = { project: null, deployment: null };
|
|
29
54
|
for (let i = 0; i < flagArgs.length; i++) {
|
|
@@ -85,6 +110,7 @@ async function list(projectId) {
|
|
|
85
110
|
|
|
86
111
|
export async function run(sub, args) {
|
|
87
112
|
if (!sub || sub === '--help' || sub === '-h') { console.log(HELP); process.exit(0); }
|
|
113
|
+
if (Array.isArray(args) && (args.includes("--help") || args.includes("-h"))) { console.log(SUB_HELP[sub] || HELP); process.exit(0); }
|
|
88
114
|
switch (sub) {
|
|
89
115
|
case "claim": {
|
|
90
116
|
const positional = [];
|
package/lib/tier.mjs
CHANGED
|
@@ -29,7 +29,14 @@ async function status() {
|
|
|
29
29
|
const res = await fetch(`${API}/tiers/v1/status`, {
|
|
30
30
|
headers: { ...authHeaders },
|
|
31
31
|
});
|
|
32
|
-
const
|
|
32
|
+
const text = await res.text();
|
|
33
|
+
let data;
|
|
34
|
+
try {
|
|
35
|
+
data = JSON.parse(text);
|
|
36
|
+
} catch {
|
|
37
|
+
console.error(JSON.stringify({ status: "error", http: res.status, message: "Non-JSON response from server", body: text.slice(0, 500) }));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
33
40
|
if (!res.ok) { console.error(JSON.stringify({ status: "error", http: res.status, ...data })); process.exit(1); }
|
|
34
41
|
console.log(JSON.stringify(data, null, 2));
|
|
35
42
|
}
|