@protobase/cli 0.49.0 → 0.49.2

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 (59) hide show
  1. package/dist/cli/package.js +1 -1
  2. package/dist/config/build-project.js +18 -8
  3. package/dist/config/config-defaults.js +3 -0
  4. package/dist/config/read-config.js +5 -1
  5. package/dist/db/read-only-db.js +1 -1
  6. package/dist/dev/dev-jobs.js +5 -3
  7. package/dist/dev/entry.js +3 -3
  8. package/dist/migration/load-project.js +1 -1
  9. package/dist/project/load-bundle-project.js +1 -1
  10. package/dist/project-auth.d.ts +2 -0
  11. package/dist/project-auth.js +2 -0
  12. package/dist/serve/app.js +1 -1
  13. package/dist/serve/create-admin.js +1 -1
  14. package/dist/serve/host-modules.js +3 -3
  15. package/dist/serve/lifecycle.js +4 -3
  16. package/dist/supabase/load-phase.js +1 -1
  17. package/dist/users/load-auth.d.ts +10 -0
  18. package/dist/users/load-auth.js +1 -1
  19. package/dist/worker/start-worker.js +3 -2
  20. package/package.json +8 -7
  21. package/skills/protobase/SKILL.md +7 -1
  22. package/skills/protobase/references/features/events-webhooks-and-jobs.md +1 -0
  23. package/skills/protobase/references/features/files-and-images.md +1 -0
  24. package/skills/protobase/references/features/sign-in-and-accounts.md +3 -0
  25. package/skills/protobase/references/features/start-a-project.md +7 -1
  26. package/skills/protobase/references/getting-started.md +13 -13
  27. package/skills/protobase/references/guides/deploy.md +2 -2
  28. package/skills/protobase/references/guides/export-a-list.md +1 -1
  29. package/skills/protobase/references/guides/field-type.md +1 -1
  30. package/skills/protobase/references/guides/first-composed-page.md +1 -1
  31. package/skills/protobase/references/guides/first-plugin.md +1 -1
  32. package/skills/protobase/references/guides/import-records.md +1 -1
  33. package/skills/protobase/references/guides/personal-setting.md +1 -1
  34. package/skills/protobase/references/guides/push-notifications.md +1 -1
  35. package/skills/protobase/references/guides/record-card.md +1 -1
  36. package/skills/protobase/references/guides/remote-resources.md +1 -1
  37. package/skills/protobase/references/guides/theme-an-app.md +1 -1
  38. package/skills/protobase/references/reference/api.md +1 -1
  39. package/skills/protobase/references/reference/architecture.md +4 -4
  40. package/skills/protobase/references/reference/auth.md +36 -4
  41. package/skills/protobase/references/reference/blocks.md +1 -1
  42. package/skills/protobase/references/reference/bottom-bar.md +1 -1
  43. package/skills/protobase/references/reference/cli.md +10 -10
  44. package/skills/protobase/references/reference/client.md +2 -2
  45. package/skills/protobase/references/reference/config/admin-app.md +62 -0
  46. package/skills/protobase/references/reference/config/api.md +164 -0
  47. package/skills/protobase/references/reference/config/app.md +112 -0
  48. package/skills/protobase/references/reference/config/files.md +99 -0
  49. package/skills/protobase/references/reference/config/jobs-and-events.md +267 -0
  50. package/skills/protobase/references/reference/config/sign-in.md +396 -0
  51. package/skills/protobase/references/reference/config.md +89 -70
  52. package/skills/protobase/references/reference/custom-components.md +2 -2
  53. package/skills/protobase/references/reference/data-config.md +2 -2
  54. package/skills/protobase/references/reference/email.md +2 -2
  55. package/skills/protobase/references/reference/files.md +6 -3
  56. package/skills/protobase/references/reference/jobs.md +15 -6
  57. package/skills/protobase/references/reference/sidebar.md +2 -2
  58. package/skills/protobase/references/reference/ui-config.md +5 -5
  59. package/skills/protobase/references/reference/user-menu.md +1 -1
@@ -0,0 +1,396 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/config/sign-in.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Sign-in options
4
+
5
+ The config keys of sign-in, auth and authenticate, each with its type, default and environment variable, and the files where sign-in's hooks, mailer, mail templates and an authenticator of the project's own go.
6
+
7
+ The keys of sign-in and of how the API verifies tokens, in [`protobase.config.ts`](../config.md). The app's URL, secrets and name, which sign-in uses, are the top-level [`url`, `secret`, `previousSecrets` and `name`](app.md). How sign-in works is in [Login with Better Auth](../auth.md).
8
+
9
+ ## auth
10
+
11
+ - **Type:** `AuthConfig | false`
12
+ - **Default:** on, with the defaults below; off when [`authenticate.jwksUrl`](#authenticatejwksurl) trusts an auth server elsewhere
13
+
14
+ Sign-in, with its store in the app's own database. `false` turns it off; an app without sign-in then verifies tokens with [`authenticate`](#authenticate) or `auth/authenticate.ts`.
15
+
16
+ ```ts
17
+ export default defineConfig({ auth: { roles: ['admin', 'sales'], signInFirst: 'emailCode' } })
18
+ ```
19
+
20
+ Sign-in runs the project's own code from these files, each loaded when Protobase builds sign-in:
21
+
22
+ - `auth/hooks.ts`: the hooks, as named exports typed with `AuthHooks` from `@protobase/server`: `generateUserId`, `onUserCreated`, `generateOrganizationId`, `onOrganizationCreated`, `beforeOrganizationDeleted` and `organizationHooks`. Each gets the app's database, `{ db }`, as its last argument. See [Hooks](../auth.md#hooks).
23
+ - `auth/mailer.ts`: a mailer of the project's own, as its default export, in place of the SMTP mailer: sign-in's mail and the jobs' `mail` both go through it. See [Email](../email.md).
24
+ - `emails/`: the templates of sign-in's mail. See [Templates](../email.md#templates).
25
+
26
+ With [extensions](../config.md#extensions), the hooks and the mailer are those of the last folder whose config sets `auth`.
27
+
28
+ ## auth.roles
29
+
30
+ - **Type:** `string[] | Record<string, string | { label: string; grants?: string[] }>`
31
+ - **Default:** `['admin', 'user']`
32
+
33
+ The roles users can hold. `admin` is always included. With [`organizations`](#authorganizations), give each a label, and optionally the other roles its holders may also give members. The capabilities each role has are `config/roles.ts`'s (see [Access](../access.md)). See [Roles](../auth.md#roles).
34
+
35
+ ```ts
36
+ export default defineConfig({
37
+ auth: { roles: { manager: { label: 'Manager', grants: ['sales'] }, sales: 'Sales' }, organizations: true },
38
+ })
39
+ ```
40
+
41
+ ## auth.defaultRole
42
+
43
+ - **Type:** `string`
44
+ - **Default:** none; with exactly one role besides `admin`, that role
45
+
46
+ The role of a user created without one. Without a default, and with more than one role besides `admin`, creating a user without a role is an error that asks for one.
47
+
48
+ ```ts
49
+ export default defineConfig({ auth: { roles: ['admin', 'sales', 'warehouse'], defaultRole: 'sales' } })
50
+ ```
51
+
52
+ ## auth.organizations
53
+
54
+ - **Type:** `true | { create?: 'admins' | 'everyone'; creatorAppRoles?: 'all' | string[]; invitationDays?: number; membershipLimit?: number; deleteRecords?: 'refuse' | 'cascade'; invitationUrl?: string }`
55
+ - **Default:** off: the app works as one organization
56
+
57
+ Turns on organizations: people work in one at a time, records of `.tenant` resources are scoped to it, and roles are held globally or per membership. `create` is who may create one (default `admins`), `creatorAppRoles` the roles its creator holds there (default `all`), `invitationDays` how long an invitation works (default 7), `membershipLimit` the most members (default 1000), `deleteRecords` whether deleting one is refused while it has records (`refuse`, the default) or left to the foreign keys (`cascade`), and `invitationUrl` the page an invitation opens (default `<url>/-/invitation`). Its hooks are in `auth/hooks.ts`. See [Organizations](../auth.md#organizations).
58
+
59
+ ```ts
60
+ export default defineConfig({ auth: { organizations: { create: 'everyone', invitationDays: 14 } } })
61
+ ```
62
+
63
+ ## auth.signUp
64
+
65
+ - **Type:** `{ role: string }`
66
+ - **Default:** off
67
+
68
+ Open sign-up: anyone makes their own account from the sign-in page, with `role`, after proving their address with an emailed code. Needs a mailer. `role` is one of [`roles`](#authroles) and never `admin`. Not with organizations. See [Open sign-up](../auth.md#open-sign-up).
69
+
70
+ ```ts
71
+ export default defineConfig({ auth: { roles: ['admin', 'customer'], signUp: { role: 'customer' } } })
72
+ ```
73
+
74
+ ## auth.signInPolicy
75
+
76
+ - **Type:** `Partial<{ password: 'allowed' | 'forbidden'; emailCode: 'allowed' | 'forbidden'; passkey: 'allowed' | 'required' | 'forbidden'; twoFactor: 'allowed' | 'required' | 'forbidden'; staffAccess: 'allowed' | 'notify' | 'forbidden'; platformSignIn: 'allowed' | 'forbidden' }>`
77
+ - **Default:** everything allowed
78
+
79
+ The sign-in policy that applies until an admin saves one on the Sign-in policy page, and when the saved one no longer reads. Checked at startup as an admin's save is. See [Sign-in policy](../auth.md#sign-in-policy).
80
+
81
+ ```ts
82
+ export default defineConfig({ auth: { signInPolicy: { password: 'forbidden', twoFactor: 'required' } } })
83
+ ```
84
+
85
+ ## auth.signInFirst
86
+
87
+ - **Type:** `'password' | 'emailCode'`
88
+ - **Default:** `password`
89
+
90
+ What the sign-in page leads with: the address and a password, with emailing a code below it; or the address and "Email me a sign-in code", with the password behind "Use a password". Only while the policy leaves both on. See [Emailed sign-in codes](../auth.md#emailed-sign-in-codes).
91
+
92
+ ```ts
93
+ export default defineConfig({ auth: { signInFirst: 'emailCode' } })
94
+ ```
95
+
96
+ ## auth.signInPerMinute
97
+
98
+ - **Type:** `number`
99
+ - **Default:** `5`
100
+
101
+ Sign-in attempts allowed per minute and client, and the sign-up requests allowed. See [Client addresses](../auth.md#client-addresses) for how a client is known.
102
+
103
+ ```ts
104
+ export default defineConfig({ auth: { signInPerMinute: 10 } })
105
+ ```
106
+
107
+ ## auth.mailer
108
+
109
+ - **Type:** `false`
110
+ - **Default:** SMTP with `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM`, when set
111
+ - **Environment variables:** `PROTOBASE_SMTP_URL`, `PROTOBASE_MAIL_FROM`
112
+
113
+ `false` turns sign-in's mail off whatever the environment says: password reset, emailed codes, sign-up, staff sign-in and invitations are then not offered. A mailer of the project's own is `auth/mailer.ts`. See [Email](../email.md#configuration).
114
+
115
+ ```ts
116
+ export default defineConfig({ auth: { mailer: false } })
117
+ ```
118
+
119
+ ## auth.socialProviders
120
+
121
+ - **Type:** Better Auth's `socialProviders`
122
+ - **Default:** none
123
+
124
+ Sign-in providers, such as `{ github: { clientId, clientSecret } }`; the callback is `<url>/api/auth/callback/<provider>`. A provider also signs up people without an account, with the default role. See [Sign-in with GitHub](../auth.md#sign-in-with-github).
125
+
126
+ ```ts
127
+ export default defineConfig(({ env }) => ({
128
+ auth: { socialProviders: { github: { clientId: env.GITHUB_CLIENT_ID!, clientSecret: env.GITHUB_CLIENT_SECRET! } } },
129
+ }))
130
+ ```
131
+
132
+ ## auth.encryptOAuthTokens
133
+
134
+ - **Type:** `boolean`
135
+ - **Default:** `false`
136
+
137
+ Encrypts the OAuth access, refresh and ID tokens kept for social sign-ins, with the app's secret.
138
+
139
+ ```ts
140
+ export default defineConfig({ auth: { encryptOAuthTokens: true } })
141
+ ```
142
+
143
+ ## auth.sso
144
+
145
+ - **Type:** `{ saml: { id: string; name?: string; domains: string[]; idp: { metadata: string } | { entityId: string; ssoUrl: string; certificate: string | string[] }; attributes?: { email?: string; name?: string; firstName?: string; lastName?: string } }[] }`
146
+ - **Default:** none
147
+
148
+ Single sign-on with SAML 2.0 identity providers. A provider signs up people without an account, with the default role, but only at its `domains`, where it also links to the account with the same address. `name` defaults to `SSO`. See [Sign-in with SAML](../auth.md#sign-in-with-saml).
149
+
150
+ ```ts
151
+ export default defineConfig(({ env }) => ({
152
+ auth: { sso: { saml: [{ id: 'okta', name: 'Okta', domains: ['example.com'], idp: { metadata: env.OKTA_METADATA! } }] } },
153
+ }))
154
+ ```
155
+
156
+ ## auth.signInProvider
157
+
158
+ - **Type:** `{ issuer: string; clientId: string; clientSecret: string; provider?: string; name?: string; scopes?: string[] } | false`
159
+ - **Default:** the provider of the environment variables below, when set
160
+ - **Environment variables:** `PROTOBASE_SIGN_IN_ISSUER`, `PROTOBASE_SIGN_IN_CLIENT_ID`, `PROTOBASE_SIGN_IN_CLIENT_SECRET`, and optionally `PROTOBASE_SIGN_IN_PROVIDER` and `PROTOBASE_SIGN_IN_NAME`
161
+
162
+ An OpenID Connect provider the platform adds for people who already have an account; it never signs anyone up. `provider` is its id (default `oidc`), `name` its button's name. `false` turns it off whatever the environment says. Left out when `socialProviders` has a provider with the same id. See [Platform sign-in provider](../auth.md#platform-sign-in-provider).
163
+
164
+ ```ts
165
+ export default defineConfig({ auth: { signInProvider: false } })
166
+ ```
167
+
168
+ ## auth.operator
169
+
170
+ - **Type:** `{ issuer: string; clientId: string; clientSecret: string; name?: string; group?: string; scopes?: string[]; acrValues?: string[]; sessionMinutes?: number } | false`
171
+ - **Default:** the provider of the environment variables below, when set
172
+ - **Environment variables:** `PROTOBASE_OPERATOR_ISSUER`, `PROTOBASE_OPERATOR_CLIENT_ID`, `PROTOBASE_OPERATOR_CLIENT_SECRET`, and optionally `PROTOBASE_OPERATOR_NAME` and `PROTOBASE_OPERATOR_GROUP`
173
+
174
+ The identity provider the operator's staff sign in with to sign in as people of this app, for support. `group` is the ID token's group that allows it (default `protobase-staff-access`), and `sessionMinutes` how long a staff session lasts (default 30, at most 240). `false` turns staff sign-in off whatever the environment says. See [Staff sign-in](../auth.md#staff-sign-in).
175
+
176
+ ```ts
177
+ export default defineConfig({ auth: { operator: false } })
178
+ ```
179
+
180
+ ## auth.passwordHashes
181
+
182
+ - **Type:** `'bcrypt'[]`
183
+ - **Default:** none
184
+
185
+ Password hashes another system wrote that sign-in accepts besides Better Auth's own, such as Supabase Auth's bcrypt. The first sign-in with one stores the password again as Better Auth hashes it. See [An existing users table](../auth.md#an-existing-users-table).
186
+
187
+ ```ts
188
+ export default defineConfig({ auth: { passwordHashes: ['bcrypt'] } })
189
+ ```
190
+
191
+ ## auth.leakedPasswords
192
+
193
+ - **Type:** `boolean`
194
+ - **Default:** `false`
195
+
196
+ Refuses a new password that appears in a known data breach, by Have I Been Pwned's list. Only the first five characters of the password's SHA-1 hash leave the server. See [Leaked passwords](../auth.md#leaked-passwords).
197
+
198
+ ```ts
199
+ export default defineConfig({ auth: { leakedPasswords: true } })
200
+ ```
201
+
202
+ ## auth.users
203
+
204
+ - **Type:** `{ table?: string; columns?: Record<string, string>; metadata?: string }`
205
+ - **Default:** the table `protobase auth migration` makes
206
+
207
+ The user table, when another system made it, such as Supabase's `auth.users`: its name, the columns named otherwise than Protobase names them, and a JSON column for each user's metadata. See [An existing users table](../auth.md#an-existing-users-table).
208
+
209
+ ```ts
210
+ export default defineConfig({
211
+ auth: { schema: 'auth', users: { table: 'users', columns: { role: 'app_role' }, metadata: 'raw_user_meta_data' } },
212
+ })
213
+ ```
214
+
215
+ ## auth.schema
216
+
217
+ - **Type:** `string`
218
+ - **Default:** `auth`
219
+
220
+ The schema of the auth store in the app's database. See [Admin store](../auth.md#admin-store).
221
+
222
+ ```ts
223
+ export default defineConfig({ auth: { schema: 'accounts' } })
224
+ ```
225
+
226
+ ## auth.generateUserId
227
+
228
+ - **Type:** `'uuid'`
229
+ - **Default:** Better Auth's random 32-character text
230
+
231
+ `'uuid'` gives new users a random UUID, and makes every id column of the store a `uuid`. To take ids from the app instead, such as its own users sequence, export `generateUserId` from `auth/hooks.ts`.
232
+
233
+ ```ts
234
+ export default defineConfig({ auth: { generateUserId: 'uuid' } })
235
+ ```
236
+
237
+ ## auth.origins
238
+
239
+ - **Type:** `string[]`
240
+ - **Default:** `PROTOBASE_ORIGINS`, comma separated; none otherwise
241
+ - **Environment variable:** `PROTOBASE_ORIGINS`
242
+
243
+ The other origins the app is served on, besides `url`. A request to one is answered for that host: its sign-in callbacks and the links it mails stay there, and passkeys work on every origin. Tokens keep `url` as issuer. See [Several origins](../auth.md#several-origins).
244
+
245
+ ```ts
246
+ export default defineConfig({ auth: { origins: ['https://admin.shop.com'] } })
247
+ ```
248
+
249
+ ## auth.passkeyDomain
250
+
251
+ - **Type:** `string`
252
+ - **Default:** `PROTOBASE_PASSKEY_DOMAIN`, else the host of `url`
253
+ - **Environment variable:** `PROTOBASE_PASSKEY_DOMAIN`
254
+
255
+ The host new passkeys are made for: the host of `url` or of one of `origins`. Each passkey keeps the one it was made for, so changing it breaks none. See [Passkeys](../auth.md#passkeys).
256
+
257
+ ```ts
258
+ export default defineConfig({ auth: { origins: ['https://admin.shop.com'], passkeyDomain: 'admin.shop.com' } })
259
+ ```
260
+
261
+ ## auth.trustedOrigins
262
+
263
+ - **Type:** `string[]`
264
+ - **Default:** `PROTOBASE_TRUSTED_ORIGINS`, comma separated
265
+ - **Environment variable:** `PROTOBASE_TRUSTED_ORIGINS`
266
+
267
+ Extra origins that may call the auth endpoints, such as the exact host of a dev tunnel; no wildcard is trusted. `url` and `origins` always are. Set in the config, it replaces the variable's list.
268
+
269
+ ```ts
270
+ export default defineConfig(({ env }) => ({
271
+ auth: { trustedOrigins: env.TUNNEL_URL ? [env.TUNNEL_URL] : undefined },
272
+ }))
273
+ ```
274
+
275
+ ## auth.mcp
276
+
277
+ - **Type:** `true | { path?: string; connectPage?: string }`
278
+ - **Default:** off
279
+
280
+ Turns on the OAuth provider for MCP clients, and with it the MCP endpoint: a client registers itself, the person signs in and allows it on the connect page, and the client gets tokens for the MCP endpoint only. `path` is the endpoint's (default `/api/mcp`), `connectPage` the page's (default `/-/connect`). Needs an https `url`, or localhost, and the OAuth tables from `protobase auth migration`. The endpoint's tools are [`mcpEndpoint`](api.md#mcpendpoint). See [MCP](../mcp.md#turning-it-on).
281
+
282
+ ```ts
283
+ export default defineConfig({ auth: { mcp: true } })
284
+ ```
285
+
286
+ ## authenticate
287
+
288
+ - **Type:** `AuthenticateSettings`
289
+ - **Default:** the tokens of `auth`
290
+
291
+ How the API verifies tokens: the app's own, those of an auth server elsewhere, and those of other Protobase apps it admits. An authenticator of the project's own, such as `jwtAuthenticator(...)` for tokens of another system, is the default export of `auth/authenticate.ts`, which replaces this key. See [Tokens and roles](../auth.md#tokens-and-roles).
292
+
293
+ ```ts
294
+ export default defineConfig({ authenticate: { tenant: 'acme' } })
295
+ ```
296
+
297
+ ## authenticate.tenant
298
+
299
+ - **Type:** `string | number`
300
+
301
+ The one tenant everyone works in, for an app without organizations; never read from the token.
302
+
303
+ ```ts
304
+ export default defineConfig({ authenticate: { tenant: 1 } })
305
+ ```
306
+
307
+ ## authenticate.jwksUrl
308
+
309
+ - **Type:** `string`
310
+
311
+ The key set of an auth server elsewhere, for an API that runs apart from it. Needs `issuer`. Set without `auth`, it turns the app's own sign-in off.
312
+
313
+ ```ts
314
+ export default defineConfig({
315
+ authenticate: { jwksUrl: 'https://auth.example.com/api/auth/jwks', issuer: 'https://auth.example.com' },
316
+ })
317
+ ```
318
+
319
+ ## authenticate.issuer
320
+
321
+ - **Type:** `string`
322
+ - **Default:** the app's `url`
323
+
324
+ The issuer the tokens must name; it is also their audience unless `audience` names another.
325
+
326
+ ```ts
327
+ export default defineConfig({ authenticate: { jwksUrl: 'https://auth.example.com/api/auth/jwks', issuer: 'https://auth.example.com' } })
328
+ ```
329
+
330
+ ## authenticate.audience
331
+
332
+ - **Type:** `string`
333
+ - **Default:** `issuer`
334
+
335
+ The audience the tokens must name.
336
+
337
+ ```ts
338
+ export default defineConfig({ authenticate: { jwksUrl: 'https://auth.example.com/api/auth/jwks', issuer: 'https://auth.example.com', audience: 'https://api.example.com' } })
339
+ ```
340
+
341
+ ## authenticate.organizations
342
+
343
+ - **Type:** `boolean`
344
+ - **Default:** read from `auth`
345
+
346
+ Whether the tokens carry organizations. Needed with `jwksUrl` only.
347
+
348
+ ```ts
349
+ export default defineConfig({ authenticate: { jwksUrl: 'https://auth.example.com/api/auth/jwks', issuer: 'https://auth.example.com', organizations: true } })
350
+ ```
351
+
352
+ ## authenticate.cache
353
+
354
+ - **Type:** `{ refreshMs?: number; minReloadMs?: number }`
355
+ - **Default:** `{ refreshMs: 600000, minReloadMs: 30000 }`
356
+
357
+ How long the key set is kept: reloaded whole every `refreshMs`, so removed keys stop working, and when a token names an unknown key, at most every `minReloadMs`.
358
+
359
+ ```ts
360
+ export default defineConfig({ authenticate: { cache: { refreshMs: 60_000 } } })
361
+ ```
362
+
363
+ ## authenticate.apps
364
+
365
+ - **Type:** `{ issuer: string; roles: Record<string, string | string[]>; tenant?: string | number }[]`
366
+ - **Default:** none
367
+
368
+ Other Protobase apps whose signed-in users this API admits with their own tokens, so their admin apps can draw its resources. `issuer` is that app's `url`, `roles` maps its global roles to this app's (a role it does not list is dropped, and a user left with none is refused), and `tenant` is where its users work. See [Users of another app](../auth.md#users-of-another-app).
369
+
370
+ ```ts
371
+ export default defineConfig({
372
+ authenticate: { apps: [{ issuer: 'https://admin.shop.com', roles: { admin: 'shop' } }] },
373
+ })
374
+ ```
375
+
376
+ ## signingKeyDays
377
+
378
+ - **Type:** `number`
379
+ - **Default:** `30`
380
+
381
+ Days a token signing key signs; the first token after that makes a new key. A month bounds how long a leaked key could sign, and keeps the key set to a few keys. A top-level key, beside `auth`. See [Signing keys](../auth.md#signing-keys).
382
+
383
+ ```ts
384
+ export default defineConfig({ signingKeyDays: 90 })
385
+ ```
386
+
387
+ ## signingKeyGraceDays
388
+
389
+ - **Type:** `number`, at least `1`
390
+ - **Default:** `7`
391
+
392
+ Days a replaced signing key stays in the key set, so the tokens it signed keep verifying until they expire; it is deleted after that. A week is far longer than any token lasts, a day at most, so an API that caches the key set never refuses a token signed just before a rotation. A top-level key, beside `auth`.
393
+
394
+ ```ts
395
+ export default defineConfig({ signingKeyGraceDays: 14 })
396
+ ```
@@ -1,10 +1,10 @@
1
1
  <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/config.md: run `bun run docs:skill`, do not edit. -->
2
2
 
3
- # protobase.config.ts
3
+ # Configuring Protobase
4
4
 
5
- The project's config as one object of data, the files where Protobase finds the project's code, the defaults, the JSON form and every key.
5
+ The project's config file, protobase.config.ts or protobase.config.json, as one object of data; defineConfig and its function form, $env values, where the project's code is found and how extensions merge.
6
6
 
7
- `protobase.config.ts`, in the project's root, describes the whole app as one object of data: its address and secret, sign-in, the jobs, the file providers and the API's settings. It default-exports `defineConfig(...)` from `@protobase/config`, which types every key and returns its argument as it is. Every key is optional; Protobase has a default for each.
7
+ Protobase reads its config from one file in the project's root: `protobase.config.ts`, or `protobase.config.json` for the same object as JSON. The file describes the whole app as one flat object of data: its address and secret, sign-in, the jobs, the file providers and the API's settings. Every key is optional; Protobase has a default for each, and a project without a config file is a config of defaults.
8
8
 
9
9
  ```ts
10
10
  // protobase.config.ts
@@ -20,75 +20,84 @@ export default defineConfig({
20
20
  })
21
21
  ```
22
22
 
23
- The config names things; it never holds or imports their code. Protobase finds the code by its path, so the job above runs `jobs/send-invoice.ts` and the write hook is `hooks/queue-sent-invoice.ts`. A project without a config file is a config of defaults.
23
+ The config names things; it never holds or imports their code. Protobase finds the code by its path, so the job above runs `jobs/send-invoice.ts` and the write hook is `hooks/queue-sent-invoice.ts`.
24
24
 
25
- ## Where the code is
26
-
27
- Each file below is loaded only when the app needs it, never while the config is read.
25
+ Each key is described with its type and default in the option pages:
28
26
 
29
- | File | What it holds | Used for |
30
- | --- | --- | --- |
31
- | `config/index.ts`, `config/<dir>/ui.ts` | the resources, views and pages, as exports | [Data config](data-config.md) |
32
- | `config/roles.ts` | the `roles` export, made with `defineRoles` | [Access](access.md) |
33
- | `functions/<name>.ts` | an API function, as its default export | [API functions](../guides/api-functions.md) |
34
- | `jobs/<name>.ts` | what the job `<name>` of `jobs` does, as its default export (`JobRun`) | [Jobs](jobs.md) |
35
- | `hooks/<name>.ts` | a write hook named in `writeHooks`, as its default export | [Jobs](jobs.md#enqueueing) |
36
- | `hooks/error.ts` | called with every error the API answers `500` for, and the request (`onUnhandledError`) | [REST API](api.md#errors) |
37
- | `auth/hooks.ts` | sign-in's hooks, as named exports: `generateUserId`, `onUserCreated`, the organization hooks | [Login](auth.md#hooks) |
38
- | `auth/mailer.ts` | a mailer of the app's own for sign-in mail, as its default export | [Email](email.md) |
39
- | `auth/authenticate.ts` | an `Authenticator` of the app's own, such as `jwtAuthenticator(...)`, in place of `authenticate` | [Tokens and roles](auth.md#tokens-and-roles) |
40
- | `assistant/tools.ts` | the assistant's own tools, an array of `defineTool(...)` | [Assistant](assistant.md) |
41
- | `audit/queue.ts` | the `AuditQueue` reveals of sensitive fields publish to | [REST API](api.md#sensitive-fields-and-audit) |
42
- | `files/<name>.ts` | the file provider `<name>`, declared `{ kind: 'custom' }` in `files.providers` | [Files](files.md) |
43
- | `webhooks/owner-roles.ts` | the roles a webhook subscription's owner holds, when the app signs people in another way | [Webhooks](webhooks.md) |
44
- | `notifications/store.ts`, `notifications/history-store.ts`, `notifications/senders.ts` | a device store, a history store and push senders in place of the built-in ones | [Notifications](notifications.md) |
45
- | `emails/` | the templates of sign-in's mail | [Email](email.md#templates) |
46
-
47
- Hooks of the project's own get the app's database, `{ db }` (Kysely, as jobs get it), as their last argument. A job named in the config without its `jobs/<name>.ts`, or a write hook without its `hooks/<name>.ts`, stops the app at start with an error that names the file.
48
-
49
- ## Defaults
50
-
51
- | Key | Default |
27
+ | Page | Keys |
52
28
  | --- | --- |
53
- | `url` | `PROTOBASE_URL`; in `protobase dev`, the dev server's own address |
54
- | `secret` | `PROTOBASE_SECRET` |
55
- | `name` | `Protobase`; `PROTOBASE_APP_NAME` overrides it |
56
- | `auth` | on, with its own defaults; `false` turns it off, as does an `authenticate.jwksUrl` that trusts an auth server elsewhere |
57
- | `auth.trustedOrigins` | `PROTOBASE_TRUSTED_ORIGINS`, comma separated |
58
- | `timezone` | `UTC` |
59
- | `apiPath` | `/api/v1` |
29
+ | [App options](config/app.md) | `name`, `url`, `secret`, `previousSecrets`, `locale`, `timezone`, `themeColor`, `backgroundColor`, `mobile` |
30
+ | [Sign-in options](config/sign-in.md) | `auth`, `authenticate`, `signingKeyDays`, `signingKeyGraceDays` |
31
+ | [API options](config/api.md) | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting`, `writeHooks`, `mcpEndpoint`, `remoteResources`, `runtimeUpdates` |
32
+ | [Admin app options](config/admin-app.md) | `assistant`, `maps`, `plugins` |
33
+ | [Jobs and events options](config/jobs-and-events.md) | `jobs`, `events`, `history`, `webhooks`, `notifications` |
34
+ | [Files options](config/files.md) | `files` |
60
35
 
61
- The app's database is `DATABASE_URL`'s, with the pool size of `PROTOBASE_DB_CONNECTIONS`. With sign-in on, `protobase dev`, `serve` and the commands that sign people in stop with a clear message when the URL or the secret is missing.
36
+ ## Config types
62
37
 
63
- ## A config, or a function
38
+ `defineConfig` from `@protobase/config` types every key and returns its argument as it is, so the editor completes and checks the config without anything running. The package exports the types too: `ProtobaseConfig` is the object, and `AuthConfig` and `FilesConfig` are its `auth` and `files`.
64
39
 
65
- `defineConfig` takes a config, or a function, plain or async, that returns one. The function gets:
40
+ ```ts
41
+ import type { ProtobaseConfig } from '@protobase/config'
42
+
43
+ const config: ProtobaseConfig = { timezone: 'Europe/Amsterdam' }
44
+ export default config
45
+ ```
46
+
47
+ ## Conditional config
48
+
49
+ `defineConfig` also takes a function, which gets the command that reads the config, the environment and the project's folder, and returns a config:
50
+
51
+ ```ts
52
+ export default defineConfig(({ command, env }) => ({
53
+ auth: { trustedOrigins: env.TUNNEL_URL ? [env.TUNNEL_URL] : undefined },
54
+ errorReporting: command === 'dev' ? false : undefined,
55
+ }))
56
+ ```
66
57
 
67
58
  | | |
68
59
  | --- | --- |
69
- | `command` | `dev`, `build`, `serve` (also `protobase worker` and the serve runtime's `migrate` and `create-admin`), or `tool`, any other command over the project, such as `migration`, `users` or `encryption` |
60
+ | `command` | `dev`, `build`, `serve` (also `protobase worker` and the serve runtime's `migrate` and `create-admin`), or `tool`, any other command over the project, such as `migration`, `users` or `doctor` |
70
61
  | `env` | `process.env`, with the project's `.env` loaded |
71
62
  | `root` | the project's folder |
72
63
 
64
+ `protobase serve` reads a bundle's config again where it runs, with that environment, so a bundle built once serves with each host's own variables. The types are `ConfigEnv`, `ConfigCommand` and `ConfigFunction`.
65
+
66
+ ## Async config
67
+
68
+ The function may be async, and return its config as a promise:
69
+
73
70
  ```ts
74
- export default defineConfig(({ command, env }) => ({
75
- auth: { trustedOrigins: env.TUNNEL_URL ? [env.TUNNEL_URL] : undefined },
76
- errorReporting: command === 'dev' ? false : undefined,
71
+ import { readFile } from 'node:fs/promises'
72
+
73
+ export default defineConfig(async ({ root }) => ({
74
+ maps: JSON.parse(await readFile(`${root}/maps.json`, 'utf8')),
77
75
  }))
78
76
  ```
79
77
 
80
- A config may branch on them, read files of its own with Node's `fs`, and import values from other files, such as a list of map layers, as any module can. Secrets are values like any other, read from the environment. `protobase serve` reads a bundle's config again where it runs, with that environment, so a bundle built once serves with each host's own variables.
78
+ A config may read files of its own with Node's `fs`, and import values from other files, such as a list of map layers, as any module can.
81
79
 
82
- ## Reading it
80
+ ## Environment variables
83
81
 
84
- Every command reads the config, in a few milliseconds: reading it runs the config's file and what that file imports, and none of the files above. A config may not load part of itself later: an `import()` in `protobase.config.ts` stops every command with an error that names it. Code belongs in the files above.
82
+ Secrets are values like any other, read from the environment. Several keys fall back to a variable of their own when the config leaves them out, such as `url` to `PROTOBASE_URL`; each option names its variable. A TypeScript config reads any other variable from `env` (or `process.env`, which holds the same):
83
+
84
+ ```ts
85
+ export default defineConfig(({ env }) => ({
86
+ auth: { trustedOrigins: env.TUNNEL_URLS?.split(',') },
87
+ }))
88
+ ```
89
+
90
+ A JSON config reads one with an `$env` value: `{ "$env": "NAME" }`, with `"default"` for when the variable is unset or empty, and `"split": ","` for a list of its non-empty parts, each trimmed. A value whose variable is unset and has no default is left out, as if the key were not written. A TypeScript config may write `$env` values too, but its types do not know them; `env` is the typed way.
91
+
92
+ The app's database is `DATABASE_URL`'s, with the pool size of `PROTOBASE_DB_CONNECTIONS`; neither is a key of the config.
85
93
 
86
94
  ## The same config as JSON
87
95
 
88
- `protobase.config.json` holds the same object as JSON. A value read from the environment is written `{ "$env": "NAME" }`, with `"default"` for when the variable is unset or empty, and `"split": ","` for a list of its non-empty parts:
96
+ `protobase.config.json` holds the same object as JSON, with [`$env` values](#environment-variables) for what the environment gives:
89
97
 
90
98
  ```json
91
99
  {
100
+ "$schema": "./node_modules/@protobase/config/schema.json",
92
101
  "url": { "$env": "PROTOBASE_URL", "default": "http://localhost:5173" },
93
102
  "timezone": "Europe/Amsterdam",
94
103
  "auth": { "roles": ["admin", "sales"], "trustedOrigins": { "$env": "TUNNEL_URLS", "split": "," } },
@@ -97,35 +106,45 @@ Every command reads the config, in a few milliseconds: reading it runs the confi
97
106
  }
98
107
  ```
99
108
 
100
- A TypeScript config may use `$env` values too. A project has one config file: one with both `protobase.config.ts` and `protobase.config.json` stops every command with an error that names both.
109
+ JSON cannot branch on the command or compute a value; a config that needs to is written in TypeScript. `$schema` points the editor at the file's JSON Schema, which `@protobase/config` ships as `schema.json`, made from the same types as a TypeScript config: it completes and checks every key and value as it is typed, and takes an `$env` value wherever a value goes. Protobase itself leaves `$schema` out. Where a key holds the settings of a library underneath, such as `auth.socialProviders`, the schema takes any object, and the app checks it when it starts.
110
+
111
+ ## One config per project
112
+
113
+ A project has one config file: one with both `protobase.config.ts` and `protobase.config.json` stops every command with an error that names both. A config cannot extend another itself; [extensions](#extensions) merge folders instead.
101
114
 
102
- JSON cannot branch on the command or compute a value; a config that needs to is written in TypeScript. There is no JSON Schema for the file yet, so a JSON config is checked when the app starts rather than in the editor.
115
+ ## Reading it
116
+
117
+ Every command reads the config, in a few milliseconds: reading it runs the config's file and what that file imports, and none of the project's code. A config may not load part of itself later: an `import()` in `protobase.config.ts` stops every command with an error that names it. Code belongs in the files below.
118
+
119
+ ## Where the code is
120
+
121
+ Protobase loads each file below only when the app needs it, never while the config is read. Hooks of the project's own get the app's database, `{ db }` (Kysely, as jobs get it), as their last argument. A job named in the config without its `jobs/<name>.ts`, or a write hook without its `hooks/<name>.ts`, stops the app at start with an error that names the file.
103
122
 
104
- ## Keys
123
+ The resources and roles have no key of their own:
105
124
 
106
- | Key | What | See |
125
+ | File | What it holds | See |
107
126
  | --- | --- | --- |
108
- | `name`, `url`, `secret` | the app's name, public URL and secret, which sign-in, mail and signed links use | [Login](auth.md#configuration) |
109
- | `locale`, `timezone` | the admin app's language for every user, and the time zone of the jobs' schedules | [Languages](languages.md), [Jobs](jobs.md#recurring-jobs) |
110
- | `themeColor`, `backgroundColor` | the installed app's colours | [App identity](app-identity.md) |
111
- | `auth` | sign-in: roles, organizations, sign-up, providers, passkeys, MCP clients; `false` turns it off | [Login](auth.md#configuration) |
112
- | `authenticate` | how the API verifies tokens: `{ tenant }`, `{ jwksUrl, issuer }` for an auth server elsewhere, or `apps` whose tokens it admits; default the tokens of `auth` | [Tokens and roles](auth.md#tokens-and-roles) |
113
- | `jobs` | the jobs by name: `description`, `arguments`, `schedule` and the run options | [Jobs](jobs.md) |
114
- | `writeHooks` | the write hooks by name, run in this order in each write's transaction | [Jobs](jobs.md#enqueueing) |
115
- | `files` | providers by name (`{ kind: 'local', dir }`, `{ kind: 's3', bucket }` or `{ kind: 'custom' }`), `retention`, `trustedHosts` and `images: 'sharp'` | [Files](files.md) |
116
- | `events`, `history` | where changes are captured, and how long history is kept | [Events](events.md), [History](history.md) |
117
- | `webhooks` | webhook subscriptions made in the app; `{}` turns them on | [Webhooks](webhooks.md) |
118
- | `notifications` | each user's devices and inbox; `{}` turns them on | [Notifications](notifications.md) |
119
- | `mobile` | the iOS and Android build | [Mobile app](../guides/mobile-app.md) |
120
- | `apiPath`, `apiKeys`, `cors`, `defaultAccess`, `rowPermissions`, `statementTimeoutMs`, `scanGuard`, `errorReporting` | the REST API's settings | [REST API](api.md) |
121
- | `assistant` | the assistant's model and limits; `false` turns it off | [Assistant](assistant.md) |
122
- | `mcpEndpoint` | the MCP endpoint's tools, or `false` | [MCP](mcp.md) |
123
- | `maps`, `plugins` | the maps' layers, and the admin app's plugins | [UI config](ui-config.md), [Plugins](plugins.md) |
124
- | `remoteResources`, `runtimeUpdates` | other Protobase APIs whose resources the app draws, and the runtime's update endpoint | [Remote resources](remote-resources.md), [Versioning](versioning.md) |
127
+ | `config/index.ts`, `config/<dir>/ui.ts` | the resources, views and pages, as exports | [Data config](data-config.md) |
128
+ | `config/roles.ts` | the `roles` export, made with `defineRoles` | [Access](access.md) |
129
+ | `functions/<name>.ts` | an API function, as its default export | [API functions](../guides/api-functions.md) |
130
+
131
+ The other files belong to an option, and are described with it:
132
+
133
+ | File | Option |
134
+ | --- | --- |
135
+ | `auth/hooks.ts`, `auth/mailer.ts`, `emails/` | [`auth`](config/sign-in.md#auth) |
136
+ | `auth/authenticate.ts` | [`authenticate`](config/sign-in.md#authenticate) |
137
+ | `hooks/<name>.ts` | [`writeHooks`](config/api.md#writehooks) |
138
+ | `hooks/error.ts`, `audit/queue.ts` | [Code of the API](config/api.md#code-of-the-api) |
139
+ | `assistant/tools.ts` | [`assistant`](config/admin-app.md#assistant) |
140
+ | `jobs/<name>.ts` | [`jobs`](config/jobs-and-events.md#jobs) |
141
+ | `webhooks/owner-roles.ts` | [`webhooks`](config/jobs-and-events.md#webhooks) |
142
+ | `notifications/store.ts`, `notifications/history-store.ts`, `notifications/senders.ts` | [`notifications`](config/jobs-and-events.md#notifications) |
143
+ | `files/<name>.ts` | [`files.providers`](config/files.md#filesproviders) |
125
144
 
126
145
  ## Extensions
127
146
 
128
- `protobase dev --extend <dir>` and `protobase build --extend <dir>` merge an extension's folder into the app, before the project. The extension's folder has a config and code of its own, found by the same paths in that folder. A config cannot extend another itself.
147
+ `protobase dev --extend <dir>` and `protobase build --extend <dir>` merge an extension's folder into the app, before the project. The extension's folder has a config and code of its own, found by the same paths in that folder.
129
148
 
130
149
  ```tsx
131
150
  // protobase.ui.tsx
@@ -6,7 +6,7 @@ React components and action handlers of your own in protobase.ui.tsx, used by na
6
6
 
7
7
  Layouts are data; a project's React code lives in one module: `protobase.ui.tsx` at the project root, beside `protobase.config.ts`. It exports each custom component under the name its layouts declare, each from a file of its own, and default-exports `defineUi({ actions })` from `@protobase/ui` for the rest, so the project depends on `@protobase/ui`, and on `react` for its JSX. This is the ERP example's:
8
8
 
9
- ```tsx title="examples/erp/protobase.ui.tsx"
9
+ ```tsx title="tests/apps/erp/protobase.ui.tsx"
10
10
  import { defineUi, type ActionContext } from '@protobase/ui'
11
11
 
12
12
  // The custom components, each in a file of its own, exported by the name their layouts declare.
@@ -23,7 +23,7 @@ const send = async ({ record, recordKey, etag, client }: ActionContext) => {
23
23
  export default defineUi({ actions: { send } })
24
24
  ```
25
25
 
26
- ```tsx title="examples/erp/components/orders-per-day.tsx"
26
+ ```tsx title="tests/apps/erp/components/orders-per-day.tsx"
27
27
  import { useSeries } from '@protobase/ui'
28
28
 
29
29
  /** Bars for orders per day; the custom component behind `<OrdersPerDay>` in config/overview/page.tsx. */