run402 1.19.6 → 1.20.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/functions.mjs CHANGED
@@ -8,7 +8,7 @@ Usage:
8
8
  run402 functions <subcommand> [args...]
9
9
 
10
10
  Subcommands:
11
- deploy <id> <name> --file <file> [--timeout <s>] [--memory <mb>] [--deps <pkg,...>]
11
+ deploy <id> <name> --file <file> [--timeout <s>] [--memory <mb>] [--deps <pkg,...>] [--schedule <cron>]
12
12
  Deploy a function to a project
13
13
  invoke <id> <name> [--method <M>] [--body <json>]
14
14
  Invoke a deployed function
@@ -18,6 +18,8 @@ Subcommands:
18
18
 
19
19
  Examples:
20
20
  run402 functions deploy abc123 stripe-webhook --file handler.ts
21
+ run402 functions deploy abc123 send-reminders --file remind.ts --schedule '*/15 * * * *'
22
+ run402 functions deploy abc123 send-reminders --file remind.ts --schedule '' # remove schedule
21
23
  run402 functions invoke abc123 stripe-webhook --body '{"event":"test"}'
22
24
  run402 functions logs abc123 stripe-webhook --tail 100
23
25
  run402 functions list abc123
@@ -30,12 +32,13 @@ Notes:
30
32
 
31
33
  async function deploy(projectId, name, args) {
32
34
  const p = findProject(projectId);
33
- const opts = { file: null, timeout: undefined, memory: undefined, deps: undefined };
35
+ const opts = { file: null, timeout: undefined, memory: undefined, deps: undefined, schedule: undefined };
34
36
  for (let i = 0; i < args.length; i++) {
35
37
  if (args[i] === "--file" && args[i + 1]) opts.file = args[++i];
36
38
  if (args[i] === "--timeout" && args[i + 1]) opts.timeout = parseInt(args[++i]);
37
39
  if (args[i] === "--memory" && args[i + 1]) opts.memory = parseInt(args[++i]);
38
40
  if (args[i] === "--deps" && args[i + 1]) opts.deps = args[++i].split(",");
41
+ if (args[i] === "--schedule" && i + 1 < args.length) opts.schedule = args[++i];
39
42
  }
40
43
  if (!opts.file) { console.error(JSON.stringify({ status: "error", message: "Missing --file <file>" })); process.exit(1); }
41
44
  const code = readFileSync(opts.file, "utf-8");
@@ -44,6 +47,7 @@ async function deploy(projectId, name, args) {
44
47
  if (opts.timeout) body.config.timeout = opts.timeout;
45
48
  if (opts.memory) body.config.memory = opts.memory;
46
49
  if (opts.deps) body.deps = opts.deps;
50
+ if (opts.schedule !== undefined) body.schedule = opts.schedule === "" ? null : opts.schedule;
47
51
 
48
52
  const fetchPaid = await setupPaidFetch();
49
53
  const res = await fetchPaid(`${API}/projects/v1/admin/${projectId}/functions`, {
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>] Run a SQL query against a project's Postgres DB
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
- const res = await fetch(`${API}/projects/v1/admin/${projectId}/sql`, { method: "POST", headers: { "Authorization": `Bearer ${p.service_key}`, "Content-Type": "text/plain" }, body: sql });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "run402",
3
- "version": "1.19.6",
3
+ "version": "1.20.1",
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": {