@butterbase/cli 0.3.4 → 0.4.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 (70) hide show
  1. package/README.md +407 -407
  2. package/dist/bin/butterbase.js +91 -1
  3. package/dist/bin/butterbase.js.map +1 -1
  4. package/dist/src/commands/clone.d.ts +9 -0
  5. package/dist/src/commands/clone.d.ts.map +1 -0
  6. package/dist/src/commands/clone.js +131 -0
  7. package/dist/src/commands/clone.js.map +1 -0
  8. package/dist/src/commands/init.js +1 -1
  9. package/dist/src/commands/keys.d.ts +1 -0
  10. package/dist/src/commands/keys.d.ts.map +1 -1
  11. package/dist/src/commands/keys.js +1 -1
  12. package/dist/src/commands/keys.js.map +1 -1
  13. package/dist/src/commands/plugin.js +2 -2
  14. package/dist/src/commands/plugin.js.map +1 -1
  15. package/dist/src/commands/repo.d.ts +28 -0
  16. package/dist/src/commands/repo.d.ts.map +1 -0
  17. package/dist/src/commands/repo.js +440 -0
  18. package/dist/src/commands/repo.js.map +1 -0
  19. package/dist/src/commands/substrate.js +1 -1
  20. package/dist/src/commands/substrate.js.map +1 -1
  21. package/dist/src/commands/templates.d.ts +9 -0
  22. package/dist/src/commands/templates.d.ts.map +1 -0
  23. package/dist/src/commands/templates.js +74 -0
  24. package/dist/src/commands/templates.js.map +1 -0
  25. package/dist/src/commands/visibility.d.ts +7 -0
  26. package/dist/src/commands/visibility.d.ts.map +1 -0
  27. package/dist/src/commands/visibility.js +32 -0
  28. package/dist/src/commands/visibility.js.map +1 -0
  29. package/dist/src/lib/api-client.d.ts +5 -1
  30. package/dist/src/lib/api-client.d.ts.map +1 -1
  31. package/dist/src/lib/api-client.js +6 -1
  32. package/dist/src/lib/api-client.js.map +1 -1
  33. package/dist/src/lib/config.d.ts +8 -0
  34. package/dist/src/lib/config.d.ts.map +1 -1
  35. package/dist/src/lib/config.js +21 -0
  36. package/dist/src/lib/config.js.map +1 -1
  37. package/dist/src/lib/repo-api.d.ts +123 -0
  38. package/dist/src/lib/repo-api.d.ts.map +1 -0
  39. package/dist/src/lib/repo-api.js +75 -0
  40. package/dist/src/lib/repo-api.js.map +1 -0
  41. package/dist/src/lib/repo-ignore.d.ts +17 -0
  42. package/dist/src/lib/repo-ignore.d.ts.map +1 -0
  43. package/dist/src/lib/repo-ignore.js +44 -0
  44. package/dist/src/lib/repo-ignore.js.map +1 -0
  45. package/dist/src/lib/repo-manifest.d.ts +12 -0
  46. package/dist/src/lib/repo-manifest.d.ts.map +1 -0
  47. package/dist/src/lib/repo-manifest.js +25 -0
  48. package/dist/src/lib/repo-manifest.js.map +1 -0
  49. package/dist/src/lib/repo-paths.d.ts +14 -0
  50. package/dist/src/lib/repo-paths.d.ts.map +1 -0
  51. package/dist/src/lib/repo-paths.js +41 -0
  52. package/dist/src/lib/repo-paths.js.map +1 -0
  53. package/dist/src/lib/repo-walk.d.ts +14 -0
  54. package/dist/src/lib/repo-walk.d.ts.map +1 -0
  55. package/dist/src/lib/repo-walk.js +36 -0
  56. package/dist/src/lib/repo-walk.js.map +1 -0
  57. package/dist/tsconfig.tsbuildinfo +1 -1
  58. package/package.json +55 -54
  59. package/templates/react-vite/.env.example +2 -2
  60. package/templates/react-vite/.mcp.json +10 -10
  61. package/templates/react-vite/README.md +38 -38
  62. package/templates/react-vite/index.html +13 -13
  63. package/templates/react-vite/package.json +25 -25
  64. package/templates/react-vite/src/App.css +33 -33
  65. package/templates/react-vite/src/App.tsx +77 -77
  66. package/templates/react-vite/src/index.css +8 -8
  67. package/templates/react-vite/src/lib.ts +6 -6
  68. package/templates/react-vite/src/main.tsx +10 -10
  69. package/templates/react-vite/tsconfig.json +21 -21
  70. package/templates/react-vite/vite.config.ts +6 -6
package/README.md CHANGED
@@ -1,407 +1,407 @@
1
- # @butterbase/cli
2
-
3
- Command-line tool for Butterbase project scaffolding and backend management.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install -g @butterbase/cli
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```bash
14
- # Login with your API key
15
- butterbase login
16
-
17
- # Create a new app
18
- butterbase apps create my-app
19
-
20
- # Set as current app
21
- butterbase apps use app_abc123
22
-
23
- # Get current schema
24
- butterbase schema get --output schema.json
25
-
26
- # Apply schema changes
27
- butterbase schema apply schema.json
28
-
29
- # Deploy a function
30
- butterbase functions deploy ./functions/hello.ts
31
-
32
- # Upload a file
33
- butterbase storage upload ./image.png
34
- ```
35
-
36
- ## Commands
37
-
38
- ### Authentication
39
-
40
- ```bash
41
- # Login
42
- butterbase login
43
-
44
- # Logout
45
- butterbase logout
46
- ```
47
-
48
- ### Configuration
49
-
50
- ```bash
51
- # Show current config
52
- butterbase config get
53
-
54
- # Set endpoint
55
- butterbase config set endpoint https://api.butterbase.ai
56
-
57
- # Set API key
58
- butterbase config set apiKey bb_key_...
59
- ```
60
-
61
- Configuration is stored in `~/.butterbase/config.json`.
62
-
63
- ### Apps
64
-
65
- ```bash
66
- # List all apps
67
- butterbase apps list
68
-
69
- # Create new app
70
- butterbase apps create my-app
71
-
72
- # Set current app (used by other commands)
73
- butterbase apps use app_abc123
74
-
75
- # Delete app
76
- butterbase apps delete app_abc123
77
- ```
78
-
79
- ### Schema
80
-
81
- ```bash
82
- # Get current schema
83
- butterbase schema get
84
-
85
- # Save schema to file
86
- butterbase schema get --output schema.json
87
-
88
- # Preview schema changes (dry-run)
89
- butterbase schema apply schema.json --dry-run
90
-
91
- # Apply schema changes
92
- butterbase schema apply schema.json
93
-
94
- # Apply with custom migration name
95
- butterbase schema apply schema.json --name "add_users_table"
96
-
97
- # Use specific app
98
- butterbase schema get --app app_abc123
99
- ```
100
-
101
- ### Functions
102
-
103
- ```bash
104
- # List deployed functions
105
- butterbase functions list
106
-
107
- # Deploy function
108
- butterbase functions deploy ./functions/hello.ts
109
-
110
- # Deploy with custom name
111
- butterbase functions deploy ./functions/hello.ts --name my-function
112
-
113
- # Deploy with description
114
- butterbase functions deploy ./functions/hello.ts --description "Hello world function"
115
-
116
- # Deploy cron function
117
- butterbase functions deploy ./functions/cleanup.ts --trigger cron
118
-
119
- # View function logs
120
- butterbase functions logs my-function
121
-
122
- # View error logs only
123
- butterbase functions logs my-function --level error
124
-
125
- # Limit number of logs
126
- butterbase functions logs my-function --limit 50
127
- ```
128
-
129
- ### Storage
130
-
131
- ```bash
132
- # List storage objects
133
- butterbase storage list
134
-
135
- # Upload file
136
- butterbase storage upload ./image.png
137
-
138
- # Delete object
139
- butterbase storage delete obj_abc123
140
- ```
141
-
142
- ### AI
143
-
144
- ```bash
145
- butterbase ai chat "Summarize this" --model openai/gpt-4o-mini
146
- butterbase ai chat "Explain RAG" --system "You're a concise teacher." --temperature 0.2
147
- butterbase ai embed "hello world" "another doc"
148
- butterbase ai models
149
- butterbase ai config get
150
- butterbase ai config set --default-model openai/gpt-4o-mini --max-tokens-per-request 4000
151
- butterbase ai config set --byok-key sk-or-... # rotate BYOK key; "" to clear
152
- butterbase ai usage --start-date 2026-05-01 --end-date 2026-05-31
153
- ```
154
-
155
- ### OAuth (admin)
156
-
157
- ```bash
158
- butterbase oauth configure google \
159
- --client-id ... --client-secret ... \
160
- --redirect-uri https://app.example/cb \
161
- --scope openid --scope email
162
- butterbase oauth list
163
- butterbase oauth get google
164
- butterbase oauth update google --enabled false
165
- butterbase oauth delete google
166
- ```
167
-
168
- ### Audit logs
169
-
170
- ```bash
171
- butterbase audit query --category auth --event-type login --limit 50
172
- butterbase audit query --from 2026-05-01 --to 2026-05-31 --action create --resource-type user
173
- butterbase audit query --actor-id user_123 --json
174
- ```
175
-
176
- ### App config (server-side)
177
-
178
- ```bash
179
- butterbase apps config get
180
- butterbase apps config cors --allowed-origin https://app.example --allow-credentials true
181
- butterbase apps config jwt --access-token-ttl 15m --refresh-token-ttl-days 30
182
- butterbase apps config storage --public-read true --max-file-size-mb 25 --allowed-content-type image/png --allowed-content-type image/jpeg
183
- butterbase apps config access-mode authenticated
184
- butterbase apps config secure --table posts --table comments --user-column author_id --access-mode authenticated
185
- ```
186
-
187
- ### Regions + multi-region moves
188
-
189
- ```bash
190
- butterbase regions list
191
- butterbase apps move app_abc us-west-2 --follow
192
- butterbase apps migrations active # current app
193
- butterbase apps migrations status app_abc m_xyz
194
- butterbase apps migrations abort app_abc m_xyz # before cutover
195
- butterbase apps migrations reverse app_abc m_xyz # after cutover
196
- butterbase apps replicas list
197
- butterbase apps replicas teardown m_xyz
198
- ```
199
-
200
- ### App-level billing (Stripe Connect)
201
-
202
- ```bash
203
- butterbase app-billing plans list
204
- butterbase app-billing plans create --name pro --price-cents 1999 --interval month
205
- butterbase app-billing plans update plan_abc --price-cents 2499
206
- butterbase app-billing products list
207
- butterbase app-billing products create --name "Lifetime access" --price-cents 9900
208
- butterbase app-billing subscribe plan_abc
209
- butterbase app-billing subscription
210
- butterbase app-billing cancel
211
- butterbase app-billing purchase prod_xyz
212
- butterbase app-billing orders list
213
- butterbase app-billing orders get order_abc
214
- ```
215
-
216
- ### Scoped API keys + integrations
217
-
218
- ```bash
219
- butterbase keys generate ci-key --scope schema:read --scope functions:invoke
220
- butterbase integrations configure github --scope repo --scope read:user
221
- butterbase integrations connect github --redirect-url https://app.example/cb --scope repo
222
- ```
223
-
224
- ### Functions deploy (full options)
225
-
226
- ```bash
227
- butterbase functions deploy fn.ts \
228
- --name my-fn \
229
- --trigger cron --trigger-config '{"schedule":"*/5 * * * *"}' \
230
- --env API_KEY=sk_... --env DEBUG=true \
231
- --timeout-ms 9000 --memory-mb 256
232
- ```
233
-
234
- ### RLS
235
-
236
- ```bash
237
- butterbase rls create --table posts --policy-name posts_own \
238
- --command SELECT --using "author_id = auth.uid()" \
239
- --role user --restrictive
240
- butterbase rls delete posts # delete all policies on table
241
- butterbase rls delete posts --policy posts_own
242
- ```
243
-
244
- ## Global Options
245
-
246
- Most commands support the `--app` flag to specify an app ID:
247
-
248
- ```bash
249
- butterbase schema get --app app_abc123
250
- butterbase functions list --app app_abc123
251
- butterbase storage list --app app_abc123
252
- ```
253
-
254
- If `--app` is not provided, the CLI uses the current app set with `butterbase apps use`.
255
-
256
- ## Configuration
257
-
258
- The CLI stores configuration in two places:
259
-
260
- 1. **Global config**: `~/.butterbase/config.json`
261
- - API key
262
- - Default endpoint
263
- - Current app
264
-
265
- 2. **Project config**: `.butterbase/config.json` (in project directory)
266
- - App ID
267
- - Endpoint override
268
-
269
- Project config takes precedence over global config.
270
-
271
- ## Environment Variables
272
-
273
- You can also configure the CLI using environment variables:
274
-
275
- - `BUTTERBASE_API_KEY` - API key
276
- - `BUTTERBASE_ENDPOINT` - API endpoint URL
277
-
278
- ## Examples
279
-
280
- ### Complete Workflow
281
-
282
- ```bash
283
- # 1. Login
284
- butterbase login
285
-
286
- # 2. Create app
287
- butterbase apps create my-grocery-app
288
-
289
- # 3. Set as current
290
- butterbase apps use app_abc123
291
-
292
- # 4. Create schema file
293
- cat > schema.json <<EOF
294
- {
295
- "tables": {
296
- "grocery_items": {
297
- "columns": {
298
- "id": { "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()" },
299
- "name": { "type": "text" },
300
- "quantity": { "type": "integer", "default": "1" },
301
- "purchased": { "type": "boolean", "default": "false" },
302
- "user_id": { "type": "uuid" },
303
- "created_at": { "type": "timestamptz", "default": "now()" }
304
- }
305
- }
306
- }
307
- }
308
- EOF
309
-
310
- # 5. Apply schema
311
- butterbase schema apply schema.json
312
-
313
- # 6. Deploy function
314
- butterbase functions deploy ./functions/add-item.ts
315
-
316
- # 7. Upload image
317
- butterbase storage upload ./logo.png
318
- ```
319
-
320
- ### Working with Multiple Apps
321
-
322
- ```bash
323
- # Create production app
324
- butterbase apps create my-app-prod
325
- # Returns: app_prod123
326
-
327
- # Create staging app
328
- butterbase apps create my-app-staging
329
- # Returns: app_staging456
330
-
331
- # Deploy to production
332
- butterbase functions deploy ./functions/api.ts --app app_prod123
333
-
334
- # Deploy to staging
335
- butterbase functions deploy ./functions/api.ts --app app_staging456
336
-
337
- # Switch between apps
338
- butterbase apps use app_prod123
339
- butterbase apps use app_staging456
340
- ```
341
-
342
- ## Development
343
-
344
- ```bash
345
- # Install dependencies
346
- npm install
347
-
348
- # Build
349
- npm run build
350
-
351
- # Test locally
352
- node dist/bin/butterbase.js --help
353
- ```
354
-
355
- ### Integrations
356
-
357
- ```bash
358
- # List available integrations (curated)
359
- butterbase integrations list --app app_abc123
360
-
361
- # Search the full catalog
362
- butterbase integrations list --search salesforce --app app_abc123
363
-
364
- # Show configured integrations
365
- butterbase integrations config --app app_abc123
366
-
367
- # Enable a toolkit
368
- butterbase integrations configure gmail --app app_abc123
369
-
370
- # Disable a toolkit
371
- butterbase integrations disable gmail --app app_abc123
372
-
373
- # Generate OAuth URL for an end-user
374
- butterbase integrations connect gmail --redirect-url https://yourapp.com/settings --app app_abc123
375
-
376
- # List connected accounts
377
- butterbase integrations connections --app app_abc123
378
-
379
- # Disconnect an account
380
- butterbase integrations disconnect <connection-id> --app app_abc123
381
-
382
- # List tools for a toolkit
383
- butterbase integrations tools gmail --app app_abc123
384
-
385
- # Execute a tool
386
- butterbase integrations execute GMAIL_SEND_EMAIL --data '{"to":"x@y.com","subject":"Hi","body":"Hello"}' --app app_abc123
387
- ```
388
-
389
- ## Error output
390
-
391
- The CLI throws typed `ButterbaseError`s from `@butterbase/sdk`. The top-level
392
- handler renders the class name, message, and the structured fields the backend
393
- returned (`code`, `status`, `remediation`). Example for an unauthenticated call:
394
-
395
- ```
396
- AuthError: Invalid API key
397
- code: AUTH_INVALID_API_KEY
398
- status: 401
399
- remediation: Rotate the key with `butterbase keys generate` and update ~/.butterbase/config.json.
400
- ```
401
-
402
- The error codes come from `@butterbase/shared`'s `ErrorCodes` namespace — see
403
- the SDK README for the full list.
404
-
405
- ## License
406
-
407
- MIT
1
+ # @butterbase/cli
2
+
3
+ Command-line tool for Butterbase project scaffolding and backend management.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install -g @butterbase/cli
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```bash
14
+ # Login with your API key
15
+ butterbase login
16
+
17
+ # Create a new app
18
+ butterbase apps create my-app
19
+
20
+ # Set as current app
21
+ butterbase apps use app_abc123
22
+
23
+ # Get current schema
24
+ butterbase schema get --output schema.json
25
+
26
+ # Apply schema changes
27
+ butterbase schema apply schema.json
28
+
29
+ # Deploy a function
30
+ butterbase functions deploy ./functions/hello.ts
31
+
32
+ # Upload a file
33
+ butterbase storage upload ./image.png
34
+ ```
35
+
36
+ ## Commands
37
+
38
+ ### Authentication
39
+
40
+ ```bash
41
+ # Login
42
+ butterbase login
43
+
44
+ # Logout
45
+ butterbase logout
46
+ ```
47
+
48
+ ### Configuration
49
+
50
+ ```bash
51
+ # Show current config
52
+ butterbase config get
53
+
54
+ # Set endpoint
55
+ butterbase config set endpoint https://api.butterbase.ai
56
+
57
+ # Set API key
58
+ butterbase config set apiKey bb_key_...
59
+ ```
60
+
61
+ Configuration is stored in `~/.butterbase/config.json`.
62
+
63
+ ### Apps
64
+
65
+ ```bash
66
+ # List all apps
67
+ butterbase apps list
68
+
69
+ # Create new app
70
+ butterbase apps create my-app
71
+
72
+ # Set current app (used by other commands)
73
+ butterbase apps use app_abc123
74
+
75
+ # Delete app
76
+ butterbase apps delete app_abc123
77
+ ```
78
+
79
+ ### Schema
80
+
81
+ ```bash
82
+ # Get current schema
83
+ butterbase schema get
84
+
85
+ # Save schema to file
86
+ butterbase schema get --output schema.json
87
+
88
+ # Preview schema changes (dry-run)
89
+ butterbase schema apply schema.json --dry-run
90
+
91
+ # Apply schema changes
92
+ butterbase schema apply schema.json
93
+
94
+ # Apply with custom migration name
95
+ butterbase schema apply schema.json --name "add_users_table"
96
+
97
+ # Use specific app
98
+ butterbase schema get --app app_abc123
99
+ ```
100
+
101
+ ### Functions
102
+
103
+ ```bash
104
+ # List deployed functions
105
+ butterbase functions list
106
+
107
+ # Deploy function
108
+ butterbase functions deploy ./functions/hello.ts
109
+
110
+ # Deploy with custom name
111
+ butterbase functions deploy ./functions/hello.ts --name my-function
112
+
113
+ # Deploy with description
114
+ butterbase functions deploy ./functions/hello.ts --description "Hello world function"
115
+
116
+ # Deploy cron function
117
+ butterbase functions deploy ./functions/cleanup.ts --trigger cron
118
+
119
+ # View function logs
120
+ butterbase functions logs my-function
121
+
122
+ # View error logs only
123
+ butterbase functions logs my-function --level error
124
+
125
+ # Limit number of logs
126
+ butterbase functions logs my-function --limit 50
127
+ ```
128
+
129
+ ### Storage
130
+
131
+ ```bash
132
+ # List storage objects
133
+ butterbase storage list
134
+
135
+ # Upload file
136
+ butterbase storage upload ./image.png
137
+
138
+ # Delete object
139
+ butterbase storage delete obj_abc123
140
+ ```
141
+
142
+ ### AI
143
+
144
+ ```bash
145
+ butterbase ai chat "Summarize this" --model openai/gpt-4o-mini
146
+ butterbase ai chat "Explain RAG" --system "You're a concise teacher." --temperature 0.2
147
+ butterbase ai embed "hello world" "another doc"
148
+ butterbase ai models
149
+ butterbase ai config get
150
+ butterbase ai config set --default-model openai/gpt-4o-mini --max-tokens-per-request 4000
151
+ butterbase ai config set --byok-key sk-or-... # rotate BYOK key; "" to clear
152
+ butterbase ai usage --start-date 2026-05-01 --end-date 2026-05-31
153
+ ```
154
+
155
+ ### OAuth (admin)
156
+
157
+ ```bash
158
+ butterbase oauth configure google \
159
+ --client-id ... --client-secret ... \
160
+ --redirect-uri https://app.example/cb \
161
+ --scope openid --scope email
162
+ butterbase oauth list
163
+ butterbase oauth get google
164
+ butterbase oauth update google --enabled false
165
+ butterbase oauth delete google
166
+ ```
167
+
168
+ ### Audit logs
169
+
170
+ ```bash
171
+ butterbase audit query --category auth --event-type login --limit 50
172
+ butterbase audit query --from 2026-05-01 --to 2026-05-31 --action create --resource-type user
173
+ butterbase audit query --actor-id user_123 --json
174
+ ```
175
+
176
+ ### App config (server-side)
177
+
178
+ ```bash
179
+ butterbase apps config get
180
+ butterbase apps config cors --allowed-origin https://app.example --allow-credentials true
181
+ butterbase apps config jwt --access-token-ttl 15m --refresh-token-ttl-days 30
182
+ butterbase apps config storage --public-read true --max-file-size-mb 25 --allowed-content-type image/png --allowed-content-type image/jpeg
183
+ butterbase apps config access-mode authenticated
184
+ butterbase apps config secure --table posts --table comments --user-column author_id --access-mode authenticated
185
+ ```
186
+
187
+ ### Regions + multi-region moves
188
+
189
+ ```bash
190
+ butterbase regions list
191
+ butterbase apps move app_abc us-west-2 --follow
192
+ butterbase apps migrations active # current app
193
+ butterbase apps migrations status app_abc m_xyz
194
+ butterbase apps migrations abort app_abc m_xyz # before cutover
195
+ butterbase apps migrations reverse app_abc m_xyz # after cutover
196
+ butterbase apps replicas list
197
+ butterbase apps replicas teardown m_xyz
198
+ ```
199
+
200
+ ### App-level billing (Stripe Connect)
201
+
202
+ ```bash
203
+ butterbase app-billing plans list
204
+ butterbase app-billing plans create --name pro --price-cents 1999 --interval month
205
+ butterbase app-billing plans update plan_abc --price-cents 2499
206
+ butterbase app-billing products list
207
+ butterbase app-billing products create --name "Lifetime access" --price-cents 9900
208
+ butterbase app-billing subscribe plan_abc
209
+ butterbase app-billing subscription
210
+ butterbase app-billing cancel
211
+ butterbase app-billing purchase prod_xyz
212
+ butterbase app-billing orders list
213
+ butterbase app-billing orders get order_abc
214
+ ```
215
+
216
+ ### Scoped API keys + integrations
217
+
218
+ ```bash
219
+ butterbase keys generate ci-key --scope schema:read --scope functions:invoke
220
+ butterbase integrations configure github --scope repo --scope read:user
221
+ butterbase integrations connect github --redirect-url https://app.example/cb --scope repo
222
+ ```
223
+
224
+ ### Functions deploy (full options)
225
+
226
+ ```bash
227
+ butterbase functions deploy fn.ts \
228
+ --name my-fn \
229
+ --trigger cron --trigger-config '{"schedule":"*/5 * * * *"}' \
230
+ --env API_KEY=sk_... --env DEBUG=true \
231
+ --timeout-ms 9000 --memory-mb 256
232
+ ```
233
+
234
+ ### RLS
235
+
236
+ ```bash
237
+ butterbase rls create --table posts --policy-name posts_own \
238
+ --command SELECT --using "author_id = auth.uid()" \
239
+ --role user --restrictive
240
+ butterbase rls delete posts # delete all policies on table
241
+ butterbase rls delete posts --policy posts_own
242
+ ```
243
+
244
+ ## Global Options
245
+
246
+ Most commands support the `--app` flag to specify an app ID:
247
+
248
+ ```bash
249
+ butterbase schema get --app app_abc123
250
+ butterbase functions list --app app_abc123
251
+ butterbase storage list --app app_abc123
252
+ ```
253
+
254
+ If `--app` is not provided, the CLI uses the current app set with `butterbase apps use`.
255
+
256
+ ## Configuration
257
+
258
+ The CLI stores configuration in two places:
259
+
260
+ 1. **Global config**: `~/.butterbase/config.json`
261
+ - API key
262
+ - Default endpoint
263
+ - Current app
264
+
265
+ 2. **Project config**: `.butterbase/config.json` (in project directory)
266
+ - App ID
267
+ - Endpoint override
268
+
269
+ Project config takes precedence over global config.
270
+
271
+ ## Environment Variables
272
+
273
+ You can also configure the CLI using environment variables:
274
+
275
+ - `BUTTERBASE_API_KEY` - API key
276
+ - `BUTTERBASE_ENDPOINT` - API endpoint URL
277
+
278
+ ## Examples
279
+
280
+ ### Complete Workflow
281
+
282
+ ```bash
283
+ # 1. Login
284
+ butterbase login
285
+
286
+ # 2. Create app
287
+ butterbase apps create my-grocery-app
288
+
289
+ # 3. Set as current
290
+ butterbase apps use app_abc123
291
+
292
+ # 4. Create schema file
293
+ cat > schema.json <<EOF
294
+ {
295
+ "tables": {
296
+ "grocery_items": {
297
+ "columns": {
298
+ "id": { "type": "uuid", "primaryKey": true, "default": "gen_random_uuid()" },
299
+ "name": { "type": "text" },
300
+ "quantity": { "type": "integer", "default": "1" },
301
+ "purchased": { "type": "boolean", "default": "false" },
302
+ "user_id": { "type": "uuid" },
303
+ "created_at": { "type": "timestamptz", "default": "now()" }
304
+ }
305
+ }
306
+ }
307
+ }
308
+ EOF
309
+
310
+ # 5. Apply schema
311
+ butterbase schema apply schema.json
312
+
313
+ # 6. Deploy function
314
+ butterbase functions deploy ./functions/add-item.ts
315
+
316
+ # 7. Upload image
317
+ butterbase storage upload ./logo.png
318
+ ```
319
+
320
+ ### Working with Multiple Apps
321
+
322
+ ```bash
323
+ # Create production app
324
+ butterbase apps create my-app-prod
325
+ # Returns: app_prod123
326
+
327
+ # Create staging app
328
+ butterbase apps create my-app-staging
329
+ # Returns: app_staging456
330
+
331
+ # Deploy to production
332
+ butterbase functions deploy ./functions/api.ts --app app_prod123
333
+
334
+ # Deploy to staging
335
+ butterbase functions deploy ./functions/api.ts --app app_staging456
336
+
337
+ # Switch between apps
338
+ butterbase apps use app_prod123
339
+ butterbase apps use app_staging456
340
+ ```
341
+
342
+ ## Development
343
+
344
+ ```bash
345
+ # Install dependencies
346
+ npm install
347
+
348
+ # Build
349
+ npm run build
350
+
351
+ # Test locally
352
+ node dist/bin/butterbase.js --help
353
+ ```
354
+
355
+ ### Integrations
356
+
357
+ ```bash
358
+ # List available integrations (curated)
359
+ butterbase integrations list --app app_abc123
360
+
361
+ # Search the full catalog
362
+ butterbase integrations list --search salesforce --app app_abc123
363
+
364
+ # Show configured integrations
365
+ butterbase integrations config --app app_abc123
366
+
367
+ # Enable a toolkit
368
+ butterbase integrations configure gmail --app app_abc123
369
+
370
+ # Disable a toolkit
371
+ butterbase integrations disable gmail --app app_abc123
372
+
373
+ # Generate OAuth URL for an end-user
374
+ butterbase integrations connect gmail --redirect-url https://yourapp.com/settings --app app_abc123
375
+
376
+ # List connected accounts
377
+ butterbase integrations connections --app app_abc123
378
+
379
+ # Disconnect an account
380
+ butterbase integrations disconnect <connection-id> --app app_abc123
381
+
382
+ # List tools for a toolkit
383
+ butterbase integrations tools gmail --app app_abc123
384
+
385
+ # Execute a tool
386
+ butterbase integrations execute GMAIL_SEND_EMAIL --data '{"to":"x@y.com","subject":"Hi","body":"Hello"}' --app app_abc123
387
+ ```
388
+
389
+ ## Error output
390
+
391
+ The CLI throws typed `ButterbaseError`s from `@butterbase/sdk`. The top-level
392
+ handler renders the class name, message, and the structured fields the backend
393
+ returned (`code`, `status`, `remediation`). Example for an unauthenticated call:
394
+
395
+ ```
396
+ AuthError: Invalid API key
397
+ code: AUTH_INVALID_API_KEY
398
+ status: 401
399
+ remediation: Rotate the key with `butterbase keys generate` and update ~/.butterbase/config.json.
400
+ ```
401
+
402
+ The error codes come from `@butterbase/shared`'s `ErrorCodes` namespace — see
403
+ the SDK README for the full list.
404
+
405
+ ## License
406
+
407
+ MIT