run402 1.25.0 → 1.27.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/cli.mjs CHANGED
@@ -37,6 +37,8 @@ Commands:
37
37
  image Generate AI images via x402 or MPP micropayments
38
38
  email Send template-based emails from your project
39
39
  message Send messages to Run402 developers
40
+ auth Manage project user authentication (magic link, passwords, settings)
41
+ sender-domain Manage custom email sender domain (register, status, remove)
40
42
  agent Manage agent identity (contact info)
41
43
 
42
44
  Run 'run402 <command> --help' for detailed usage of each command.
@@ -159,6 +161,16 @@ switch (cmd) {
159
161
  await run(sub, rest);
160
162
  break;
161
163
  }
164
+ case "auth": {
165
+ const { run } = await import("./lib/auth.mjs");
166
+ await run(sub, rest);
167
+ break;
168
+ }
169
+ case "sender-domain": {
170
+ const { run } = await import("./lib/sender-domain.mjs");
171
+ await run(sub, rest);
172
+ break;
173
+ }
162
174
  default:
163
175
  console.error(`Unknown command: ${cmd}\n`);
164
176
  console.log(HELP);
package/lib/auth.mjs ADDED
@@ -0,0 +1,153 @@
1
+ import { findProject, resolveProjectId, API } from "./config.mjs";
2
+
3
+ const HELP = `run402 auth — Manage project user authentication
4
+
5
+ Usage:
6
+ run402 auth <subcommand> [args...]
7
+
8
+ Subcommands:
9
+ magic-link --email <addr> --redirect <url> [--project <id>]
10
+ Send a passwordless login link to the given email. Auto-creates user on first use.
11
+
12
+ verify --token <token> [--project <id>]
13
+ Exchange a magic link token for access_token + refresh_token.
14
+
15
+ set-password --token <bearer> --new <password> [--current <password>] [--project <id>]
16
+ Change, reset, or set a user's password. Requires the user's access_token.
17
+
18
+ settings --allow-password-set <true|false> [--project <id>]
19
+ Update project auth settings (requires service_key).
20
+
21
+ providers [--project <id>]
22
+ List available auth providers for the project.
23
+
24
+ Examples:
25
+ run402 auth magic-link --email user@example.com --redirect https://myapp.run402.com/cb
26
+ run402 auth verify --token abc123def456
27
+ run402 auth set-password --token eyJ... --new "new-pass" --current "old-pass"
28
+ run402 auth settings --allow-password-set true
29
+ run402 auth providers
30
+ `;
31
+
32
+ function parseFlag(args, flag) {
33
+ for (let i = 0; i < args.length; i++) {
34
+ if (args[i] === flag && args[i + 1]) return args[i + 1];
35
+ }
36
+ return null;
37
+ }
38
+
39
+ async function magicLink(args) {
40
+ const email = parseFlag(args, "--email");
41
+ const redirect = parseFlag(args, "--redirect");
42
+ const projectId = resolveProjectId(parseFlag(args, "--project"));
43
+ const p = findProject(projectId);
44
+
45
+ if (!email) { console.error(JSON.stringify({ status: "error", message: "Missing --email" })); process.exit(1); }
46
+ if (!redirect) { console.error(JSON.stringify({ status: "error", message: "Missing --redirect <url>" })); process.exit(1); }
47
+
48
+ const res = await fetch(`${API}/auth/v1/magic-link`, {
49
+ method: "POST",
50
+ headers: { "Authorization": `Bearer ${p.anon_key}`, "Content-Type": "application/json" },
51
+ body: JSON.stringify({ email, redirect_url: redirect }),
52
+ });
53
+ const data = await res.json();
54
+ if (!res.ok) {
55
+ console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
56
+ process.exit(1);
57
+ }
58
+ console.log(JSON.stringify({ status: "ok", ...data }));
59
+ }
60
+
61
+ async function verify(args) {
62
+ const token = parseFlag(args, "--token");
63
+ const projectId = resolveProjectId(parseFlag(args, "--project"));
64
+ const p = findProject(projectId);
65
+
66
+ if (!token) { console.error(JSON.stringify({ status: "error", message: "Missing --token" })); process.exit(1); }
67
+
68
+ const res = await fetch(`${API}/auth/v1/token?grant_type=magic_link`, {
69
+ method: "POST",
70
+ headers: { "Authorization": `Bearer ${p.anon_key}`, "Content-Type": "application/json" },
71
+ body: JSON.stringify({ token }),
72
+ });
73
+ const data = await res.json();
74
+ if (!res.ok) {
75
+ console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
76
+ process.exit(1);
77
+ }
78
+ console.log(JSON.stringify({ status: "ok", ...data }));
79
+ }
80
+
81
+ async function setPassword(args) {
82
+ const accessToken = parseFlag(args, "--token");
83
+ const newPassword = parseFlag(args, "--new");
84
+ const currentPassword = parseFlag(args, "--current");
85
+
86
+ if (!accessToken) { console.error(JSON.stringify({ status: "error", message: "Missing --token <bearer_token>" })); process.exit(1); }
87
+ if (!newPassword) { console.error(JSON.stringify({ status: "error", message: "Missing --new <password>" })); process.exit(1); }
88
+
89
+ const body = { new_password: newPassword };
90
+ if (currentPassword) body.current_password = currentPassword;
91
+
92
+ const res = await fetch(`${API}/auth/v1/user/password`, {
93
+ method: "PUT",
94
+ headers: { "Authorization": `Bearer ${accessToken}`, "Content-Type": "application/json" },
95
+ body: JSON.stringify(body),
96
+ });
97
+ const data = await res.json();
98
+ if (!res.ok) {
99
+ console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
100
+ process.exit(1);
101
+ }
102
+ console.log(JSON.stringify({ status: "ok", ...data }));
103
+ }
104
+
105
+ async function settings(args) {
106
+ const allowPasswordSet = parseFlag(args, "--allow-password-set");
107
+ const projectId = resolveProjectId(parseFlag(args, "--project"));
108
+ const p = findProject(projectId);
109
+
110
+ if (allowPasswordSet === null) { console.error(JSON.stringify({ status: "error", message: "Missing --allow-password-set <true|false>" })); process.exit(1); }
111
+
112
+ const res = await fetch(`${API}/auth/v1/settings`, {
113
+ method: "PATCH",
114
+ headers: { "Authorization": `Bearer ${p.service_key}`, "Content-Type": "application/json" },
115
+ body: JSON.stringify({ allow_password_set: allowPasswordSet === "true" }),
116
+ });
117
+ const data = await res.json();
118
+ if (!res.ok) {
119
+ console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
120
+ process.exit(1);
121
+ }
122
+ console.log(JSON.stringify({ status: "ok", ...data }));
123
+ }
124
+
125
+ async function providers(args) {
126
+ const projectId = resolveProjectId(parseFlag(args, "--project"));
127
+ const p = findProject(projectId);
128
+
129
+ const res = await fetch(`${API}/auth/v1/providers`, {
130
+ headers: { "Authorization": `Bearer ${p.anon_key}` },
131
+ });
132
+ const data = await res.json();
133
+ if (!res.ok) {
134
+ console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
135
+ process.exit(1);
136
+ }
137
+ console.log(JSON.stringify(data, null, 2));
138
+ }
139
+
140
+ export async function run(sub, args) {
141
+ if (!sub || sub === "--help" || sub === "-h") { console.log(HELP); process.exit(0); }
142
+ switch (sub) {
143
+ case "magic-link": await magicLink(args); break;
144
+ case "verify": await verify(args); break;
145
+ case "set-password": await setPassword(args); break;
146
+ case "settings": await settings(args); break;
147
+ case "providers": await providers(args); break;
148
+ default:
149
+ console.error(`Unknown subcommand: ${sub}\n`);
150
+ console.log(HELP);
151
+ process.exit(1);
152
+ }
153
+ }
package/lib/deploy.mjs CHANGED
@@ -32,11 +32,13 @@ Manifest format (JSON):
32
32
  { "file": "index.html", "data": "<html>...</html>" },
33
33
  { "file": "style.css", "path": "./dist/style.css" }
34
34
  ],
35
- "subdomain": "my-app"
35
+ "subdomain": "my-app",
36
+ "inherit": true
36
37
  }
37
38
 
38
39
  project_id is required (provision first with 'run402 provision').
39
40
  All other fields are optional.
41
+ inherit: copy unchanged site files from previous deployment (only upload changed files).
40
42
 
41
43
  Migrations can be inline or read from a file:
42
44
  "migrations": "CREATE TABLE ..." ← inline SQL
@@ -0,0 +1,96 @@
1
+ import { findProject, resolveProjectId, API } from "./config.mjs";
2
+
3
+ const HELP = `run402 sender-domain — Manage custom email sender domain
4
+
5
+ Usage:
6
+ run402 sender-domain <subcommand> [args...]
7
+
8
+ Subcommands:
9
+ register <domain> [--project <id>] Register a custom sender domain (returns DNS records)
10
+ status [--project <id>] Check domain verification status
11
+ remove [--project <id>] Remove custom sender domain
12
+
13
+ Examples:
14
+ run402 sender-domain register kysigned.com
15
+ run402 sender-domain status
16
+ run402 sender-domain remove
17
+ `;
18
+
19
+ function parseFlag(args, flag) {
20
+ for (let i = 0; i < args.length; i++) {
21
+ if (args[i] === flag && args[i + 1]) return args[i + 1];
22
+ }
23
+ return null;
24
+ }
25
+
26
+ async function register(args) {
27
+ let domain = null;
28
+ let projectOpt = null;
29
+ for (let i = 0; i < args.length; i++) {
30
+ if (args[i] === "--project" && args[i + 1]) { projectOpt = args[++i]; }
31
+ else if (!args[i].startsWith("--") && !domain) { domain = args[i]; }
32
+ }
33
+ const projectId = resolveProjectId(projectOpt);
34
+ const p = findProject(projectId);
35
+
36
+ if (!domain) {
37
+ console.error(JSON.stringify({ status: "error", message: "Missing domain. Usage: run402 sender-domain register <domain>" }));
38
+ process.exit(1);
39
+ }
40
+
41
+ const res = await fetch(`${API}/email/v1/domains`, {
42
+ method: "POST",
43
+ headers: { apikey: p.service_key, "Content-Type": "application/json" },
44
+ body: JSON.stringify({ domain }),
45
+ });
46
+ const data = await res.json();
47
+ if (!res.ok) {
48
+ console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
49
+ process.exit(1);
50
+ }
51
+ console.log(JSON.stringify(data, null, 2));
52
+ }
53
+
54
+ async function status(args) {
55
+ const projectId = resolveProjectId(parseFlag(args, "--project"));
56
+ const p = findProject(projectId);
57
+
58
+ const res = await fetch(`${API}/email/v1/domains`, {
59
+ headers: { apikey: p.service_key },
60
+ });
61
+ const data = await res.json();
62
+ if (!res.ok) {
63
+ console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
64
+ process.exit(1);
65
+ }
66
+ console.log(JSON.stringify(data, null, 2));
67
+ }
68
+
69
+ async function remove(args) {
70
+ const projectId = resolveProjectId(parseFlag(args, "--project"));
71
+ const p = findProject(projectId);
72
+
73
+ const res = await fetch(`${API}/email/v1/domains`, {
74
+ method: "DELETE",
75
+ headers: { apikey: p.service_key },
76
+ });
77
+ const data = await res.json();
78
+ if (!res.ok) {
79
+ console.error(JSON.stringify({ status: "error", http: res.status, ...data }));
80
+ process.exit(1);
81
+ }
82
+ console.log(JSON.stringify(data));
83
+ }
84
+
85
+ export async function run(sub, args) {
86
+ if (!sub || sub === "--help" || sub === "-h") { console.log(HELP); process.exit(0); }
87
+ switch (sub) {
88
+ case "register": await register(args); break;
89
+ case "status": await status(args); break;
90
+ case "remove": await remove(args); break;
91
+ default:
92
+ console.error(`Unknown subcommand: ${sub}\n`);
93
+ console.log(HELP);
94
+ process.exit(1);
95
+ }
96
+ }
package/lib/sites.mjs CHANGED
@@ -18,6 +18,7 @@ Options (deploy):
18
18
  --manifest <file> Path to manifest JSON file (or read from stdin)
19
19
  --project <id> Project ID (defaults to active project)
20
20
  --target <target> Deployment target (e.g. 'production')
21
+ --inherit Copy unchanged files from the previous deployment (only upload changed files)
21
22
  --help, -h Show this help message
22
23
 
23
24
  Manifest format (JSON):
@@ -51,12 +52,13 @@ async function readStdin() {
51
52
  }
52
53
 
53
54
  async function deploy(args) {
54
- const opts = { manifest: null, project: undefined, target: undefined };
55
+ const opts = { manifest: null, project: undefined, target: undefined, inherit: false };
55
56
  for (let i = 0; i < args.length; i++) {
56
57
  if (args[i] === "--help" || args[i] === "-h") { console.log(HELP); process.exit(0); }
57
58
  if (args[i] === "--manifest" && args[i + 1]) opts.manifest = args[++i];
58
59
  if (args[i] === "--project" && args[i + 1]) opts.project = args[++i];
59
60
  if (args[i] === "--target" && args[i + 1]) opts.target = args[++i];
61
+ if (args[i] === "--inherit") opts.inherit = true;
60
62
  }
61
63
  const projectId = resolveProjectId(opts.project);
62
64
  const raw = opts.manifest ? readFileSync(opts.manifest, "utf-8") : await readStdin();
@@ -64,6 +66,7 @@ async function deploy(args) {
64
66
  if (opts.manifest) resolveFilePathsInManifest(manifest, dirname(resolve(opts.manifest)));
65
67
  const body = { files: manifest.files, project: projectId };
66
68
  if (opts.target) body.target = opts.target;
69
+ if (opts.inherit) body.inherit = true;
67
70
 
68
71
  const authHeaders = allowanceAuthHeaders("/deployments/v1");
69
72
  const res = await fetch(`${API}/deployments/v1`, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "run402",
3
- "version": "1.25.0",
3
+ "version": "1.27.0",
4
4
  "description": "CLI for Run402 — provision Postgres databases, deploy static sites, generate images, and manage wallets via x402 and MPP micropayments.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,62 +0,0 @@
1
- /**
2
- * Wallet auth helper — generates EIP-191 signature headers for Run402 API.
3
- * Uses @noble/curves (lighter than viem) for signing.
4
- */
5
- import { secp256k1 } from "@noble/curves/secp256k1.js";
6
- import { keccak_256 } from "@noble/hashes/sha3.js";
7
- import { bytesToHex } from "@noble/hashes/utils.js";
8
- import { readWallet } from "./wallet.js";
9
- /**
10
- * EIP-191 personal_sign: sign a message with the wallet's private key.
11
- */
12
- function personalSign(privateKeyHex, address, message) {
13
- const msgBytes = new TextEncoder().encode(message);
14
- const prefix = new TextEncoder().encode(`\x19Ethereum Signed Message:\n${msgBytes.length}`);
15
- const prefixed = new Uint8Array(prefix.length + msgBytes.length);
16
- prefixed.set(prefix);
17
- prefixed.set(msgBytes, prefix.length);
18
- const hash = keccak_256(prefixed);
19
- const pkHex = privateKeyHex.startsWith("0x")
20
- ? privateKeyHex.slice(2)
21
- : privateKeyHex;
22
- const pkBytes = Uint8Array.from(Buffer.from(pkHex, "hex"));
23
- const rawSig = secp256k1.sign(hash, pkBytes);
24
- const sig = secp256k1.Signature.fromBytes(rawSig);
25
- // Determine recovery bit by trying both and matching the address
26
- let recovery = 0;
27
- for (const v of [0, 1]) {
28
- try {
29
- const recovered = sig.addRecoveryBit(v).recoverPublicKey(hash);
30
- const pubBytes = recovered.toBytes(false).slice(1); // uncompressed, drop 04 prefix
31
- const addrBytes = keccak_256(pubBytes).slice(-20);
32
- if ("0x" + bytesToHex(addrBytes) === address.toLowerCase()) {
33
- recovery = v;
34
- break;
35
- }
36
- }
37
- catch {
38
- continue;
39
- }
40
- }
41
- const r = sig.r.toString(16).padStart(64, "0");
42
- const s = sig.s.toString(16).padStart(64, "0");
43
- const vHex = (recovery + 27).toString(16).padStart(2, "0");
44
- return "0x" + r + s + vHex;
45
- }
46
- /**
47
- * Get wallet auth headers for the Run402 API.
48
- * Returns null if no wallet is configured.
49
- */
50
- export function getWalletAuthHeaders(walletPath) {
51
- const wallet = readWallet(walletPath);
52
- if (!wallet || !wallet.address || !wallet.privateKey)
53
- return null;
54
- const timestamp = Math.floor(Date.now() / 1000).toString();
55
- const signature = personalSign(wallet.privateKey, wallet.address, `run402:${timestamp}`);
56
- return {
57
- "X-Run402-Wallet": wallet.address,
58
- "X-Run402-Signature": signature,
59
- "X-Run402-Timestamp": timestamp,
60
- };
61
- }
62
- //# sourceMappingURL=wallet-auth.js.map
@@ -1,25 +0,0 @@
1
- import { readFileSync, writeFileSync, mkdirSync, existsSync, chmodSync, renameSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
- import { randomBytes } from "node:crypto";
4
- import { getWalletPath } from "./config.js";
5
- export function readWallet(path) {
6
- const p = path ?? getWalletPath();
7
- if (!existsSync(p))
8
- return null;
9
- try {
10
- return JSON.parse(readFileSync(p, "utf-8"));
11
- }
12
- catch {
13
- return null;
14
- }
15
- }
16
- export function saveWallet(data, path) {
17
- const p = path ?? getWalletPath();
18
- const dir = dirname(p);
19
- mkdirSync(dir, { recursive: true });
20
- const tmp = join(dir, `.wallet.${randomBytes(4).toString("hex")}.tmp`);
21
- writeFileSync(tmp, JSON.stringify(data, null, 2), { mode: 0o600 });
22
- renameSync(tmp, p);
23
- chmodSync(p, 0o600);
24
- }
25
- //# sourceMappingURL=wallet.js.map