@supacloud/cli 0.14.6 → 0.16.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.
Files changed (3) hide show
  1. package/README.md +164 -5
  2. package/dist/index.js +1606 -174
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -36,16 +36,102 @@ grants, extensions, and reference-data changes in migrations; use read-only SQL
36
36
  for ordinary inspection; dry-run remote migrations; and reconcile existing
37
37
  remote drift before touching migration history.
38
38
 
39
- `supacloud-cli` defaults to the current workspace's project context. If you do not pass explicit flags, it tries to auto-link from `.env`:
39
+ ## Environment profiles and production safety
40
+
41
+ Use named environment files to keep test and production configuration separate.
42
+ `--env test` reads `.env.supacloud.test` from the current working directory;
43
+ `--env prod` reads `.env.supacloud.prod` and treats the profile as production.
44
+ For example:
45
+
46
+ ```dotenv
47
+ # .env.supacloud.test
48
+ SUPACLOUD_ENV=test
49
+ SUPACLOUD_API_URL=https://management.test.example.com
50
+ SUPACLOUD_API_TOKEN=<test-management-api-token>
51
+ SUPACLOUD_PROJECT_REF=test-ref
52
+ ```
53
+
54
+ ```dotenv
55
+ # .env.supacloud.prod
56
+ SUPACLOUD_ENV=production
57
+ SUPACLOUD_API_URL=https://management.example.com
58
+ SUPACLOUD_API_TOKEN=<production-management-api-token>
59
+ SUPACLOUD_PROJECT_REF=production-ref
60
+ ```
61
+
62
+ Run commands with the selected profile:
63
+
64
+ ```bash
65
+ supacloud-cli --env test status
66
+ supacloud-cli project get --env test
67
+ supacloud-cli status --env-file ./config/supacloud.staging.env
68
+ ```
69
+
70
+ Global flags may appear before or after the command. Both `--key value` and
71
+ `--key=value` syntax are accepted. `--env` and `--env-file` are mutually
72
+ exclusive. An explicit `--env-file` must declare `SUPACLOUD_ENV`.
73
+
74
+ Environment files contain credentials. The repository root `.gitignore`
75
+ already ignores `.env` and `.env.*`; do not force-add or commit these files.
76
+ Restrict locally created files to the current user:
77
+
78
+ ```bash
79
+ chmod 600 .env.supacloud.test .env.supacloud.prod
80
+ ```
81
+
82
+ CI can provide one complete context through process environment variables
83
+ instead of writing a file:
84
+
85
+ ```bash
86
+ SUPACLOUD_ENV=test \
87
+ SUPACLOUD_API_URL=https://management.test.example.com \
88
+ SUPACLOUD_API_TOKEN="$CI_SUPACLOUD_API_TOKEN" \
89
+ SUPACLOUD_PROJECT_REF=test-ref \
90
+ supacloud-cli status
91
+ ```
92
+
93
+ Project context is resolved from one atomic source: a named profile selected by
94
+ `--env`, an explicit `--env-file`, a complete process environment, or the
95
+ legacy `.env` fallback. Core URL, token, and project-ref values are not filled
96
+ by mixing sources. If `SUPACLOUD_ENV` is set without a complete process context,
97
+ it strictly selects `.env.supacloud.<value>`. For backward compatibility, when
98
+ no selector and no core process variables are present, `supacloud-cli` still
99
+ tries to auto-link from `.env` using:
40
100
 
41
101
  - `SUPABASE_URL` or `SUPACLOUD_API_URL`
42
102
  - `SUPABASE_SERVICE_ROLE_KEY` or `SUPACLOUD_API_TOKEN`
43
103
  - `SUPACLOUD_PROJECT_REF` when the project ref cannot be inferred from a managed `<ref>.api.*` hostname
44
104
 
45
- Both `--key value` and `--key=value` flag syntax are accepted. `--ref` can
46
- override the auto-linked project for an individual command. `status` checks
47
- configuration, Management API connectivity, and authentication; it exits
48
- non-zero when any required check fails.
105
+ The legacy `.env` fallback is unclassified and therefore does not enable the
106
+ production confirmation gate. Production automation must select a `prod` or
107
+ `production` profile, or set `SUPACLOUD_ENV=production` together with a complete
108
+ process context. Use `SUPACLOUD_READ_ONLY=true` when legacy workflows must be
109
+ restricted to inspection only.
110
+
111
+ `SUPACLOUD_READ_ONLY=true` is a safety override that blocks remote writes.
112
+ Production writes require an explicit confirmation equal to the selected
113
+ profile's project ref:
114
+
115
+ ```bash
116
+ supacloud-cli database push_migrations --env prod \
117
+ --ref production-ref --dir supabase/migrations \
118
+ --confirm-production production-ref
119
+ ```
120
+
121
+ Dry runs remain read operations. Production `diagnostics repair` is always
122
+ forbidden, and unclassified actions fail closed in production or read-only
123
+ contexts.
124
+
125
+ For supported command groups, `--ref` overrides the profile's default project
126
+ for one command. A production profile cannot target a different project with
127
+ `--ref`; the requested ref and `--confirm-production` must both exactly match
128
+ the profile's project ref.
129
+
130
+ `status` checks configuration, Management API connectivity, and authentication;
131
+ it exits non-zero when any required check fails. Its output includes
132
+ `environment`, `source` (`kind` and `path`), `apiUrl`, `projectRef`, `readOnly`,
133
+ `production`, and `hasApiToken`. It never prints the API token or service-role
134
+ key.
49
135
 
50
136
  Examples:
51
137
 
@@ -60,6 +146,7 @@ supacloud-cli queue dlq --queue emails --limit 20
60
146
  supacloud-cli task_events inspect_webhook --ref abc123
61
147
  supacloud-cli database query --sql "select now()"
62
148
  supacloud-cli database query --ref abc123 --file ./queries/vector-search.sql
149
+ supacloud-cli database migration_inventory --ref abc123
63
150
  supacloud-cli database push_migrations --ref abc123 --dir supabase/migrations --dry_run
64
151
  supacloud-cli supabase migration_new --name add_accounts
65
152
  supacloud-cli supabase db_diff --schema public --name add_accounts
@@ -71,8 +158,26 @@ supacloud-cli branch promote --branch_ref preview123 --plan_checksum <sha256>
71
158
  supacloud-cli edge_functions deploy --ref abc123 --slug hello --path ./supabase/functions/hello
72
159
  supacloud-cli edge_functions deploy_bundle --ref abc123 --slug hello --files '{"index.ts":"export default { fetch: () => new Response(\"ok\") }"}'
73
160
  supacloud-cli edge_functions source --ref abc123 --slug hello --output ./hello.ts
161
+ supacloud-cli edge_functions activate --ref abc123 --slug hello --version 3
162
+ supacloud-cli scheduled_functions list --ref abc123
163
+ supacloud-cli secrets upsert --ref abc123 --from-env API_KEY,WEBHOOK_SECRET
164
+ supacloud-cli storage list_buckets --ref abc123
165
+ supacloud-cli storage get_bucket --ref abc123 --bucket reports
166
+ supacloud-cli storage create_bucket --ref abc123 --bucket reports --public false \
167
+ --file_size_limit 10485760 --allowed_mime_types "application/pdf,image/png"
168
+ supacloud-cli storage update_bucket --ref abc123 --bucket reports \
169
+ --allowed_mime_types '["application/pdf"]'
170
+ supacloud-cli storage delete_bucket --ref abc123 --bucket reports
74
171
  ```
75
172
 
173
+ `database migration_inventory` reads the canonical migration ledger through the
174
+ project-scoped Management API and prints only a validated JSON array. It rejects
175
+ non-2xx responses, malformed entries, unsafe project refs, duplicate canonical
176
+ migration versions, checksum
177
+ drift, and statement-count mismatches instead of treating them as an empty
178
+ ledger. `database list_migrations` remains available with its legacy SQL-backed,
179
+ human-readable behavior.
180
+
76
181
  `edge_functions deploy --path` bundles local TypeScript and dependencies with
77
182
  Bun and runs a local syntax check before upload. The Management API validates and
78
183
  normalizes the final server-side artifact against the multi-tenant Edge Runtime
@@ -82,6 +187,44 @@ Use `source --output <file>` for large Functions so terminal or automation outpu
82
187
  limits cannot truncate the original TS/JS source code. The destination must not
83
188
  already exist.
84
189
 
190
+ `edge_functions activate` restores an existing immutable Function version and
191
+ returns a machine-readable receipt containing the activated version and JWT
192
+ policy. HTTP and malformed-response failures exit non-zero without echoing the
193
+ server response body.
194
+
195
+ Mutation receipts use schema `supacloud.cli.release-control.v1`. An
196
+ `OUTCOME_UNKNOWN` error means the server may have committed the mutation before
197
+ the response was lost or failed validation; read back current state before any
198
+ retry.
199
+
200
+ Scheduled Function lifecycle operations are also project-scoped:
201
+
202
+ ```bash
203
+ supacloud-cli scheduled_functions create --ref abc123 --name nightly \
204
+ --slug cleanup --cron "0 2 * * *" --method POST
205
+ supacloud-cli scheduled_functions update --ref abc123 --schedule_id <id> \
206
+ --cron "0 3 * * *"
207
+ supacloud-cli scheduled_functions delete --ref abc123 --schedule_id <id>
208
+ ```
209
+
210
+ Schedule IDs are canonical UUIDv4 values returned by create/list. Cron values
211
+ use bounded numeric five-field syntax with wildcards, lists, ranges, and steps;
212
+ out-of-range endpoints and steps are rejected before HTTP dispatch.
213
+
214
+ Use `--body_file ./payload.json` for a JSON-object request body. Header values
215
+ must come from environment variables: pass a JSON name mapping such as
216
+ `--header_env '{"x-schedule-token":"SCHEDULE_TOKEN"}'`. Platform-owned
217
+ `authorization`, `apikey`, and `x-project-ref` headers cannot be overridden. Receipts never
218
+ include header values or body content; list and mutation receipts report only
219
+ whether the body is empty and the configured header names.
220
+
221
+ For secret writes, `--from-env` accepts a comma-separated list of environment
222
+ variable names. The CLI reads each non-empty value from its own process
223
+ environment, so command arguments contain names only and values are never
224
+ printed. Names must be unique shell-style identifiers (`[A-Za-z_][A-Za-z0-9_]*`,
225
+ up to 256 characters). Missing or empty values fail before any HTTP request.
226
+ Do not combine `--from-env` with the compatibility `--secrets` input.
227
+
85
228
  Branch promotion is migration-first. `branch promotion_plan` prints pending
86
229
  versions, names, statement counts, and checksums without echoing SQL into terminal
87
230
  logs; review the migration files or the Web Console SQL view before approval.
@@ -174,6 +317,22 @@ USING hnsw (embedding vector_cosine_ops);
174
317
 
175
318
  Transaction boundary: SupaCloud supports transaction blocks inside one SQL request and transactional migrations. It does not expose long-lived HTTP transaction sessions; use a direct Postgres DSN for application-side long transactions.
176
319
 
320
+ Auth configuration commands accept a JSON object from the CLI:
321
+
322
+ ```bash
323
+ supacloud-cli auth update_settings --ref abc123 \
324
+ --config '{"disable_signup":true,"enable_signup":false}'
325
+ supacloud-cli auth update_config --ref abc123 \
326
+ --config '{"third_party_auth":{"enabled":true}}'
327
+ ```
328
+
329
+ Failed Auth mutations exit non-zero and print a JSON object containing the HTTP
330
+ status plus an allowlisted subset of runtime-apply state. If Management API
331
+ returns `503` with `persisted: true`, the desired configuration was saved but
332
+ runtime propagation was incomplete; automation must read the affected settings
333
+ back exactly before deciding whether it is safe to continue. Free-form server
334
+ messages and request configuration are not echoed.
335
+
177
336
  Project commands owned by this CLI:
178
337
 
179
338
  - `project get`