@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.
- package/dist/cli/package.js +1 -1
- package/dist/config/build-project.js +18 -8
- package/dist/config/config-defaults.js +3 -0
- package/dist/config/read-config.js +5 -1
- package/dist/db/read-only-db.js +1 -1
- package/dist/dev/dev-jobs.js +5 -3
- package/dist/dev/entry.js +3 -3
- package/dist/migration/load-project.js +1 -1
- package/dist/project/load-bundle-project.js +1 -1
- package/dist/project-auth.d.ts +2 -0
- package/dist/project-auth.js +2 -0
- package/dist/serve/app.js +1 -1
- package/dist/serve/create-admin.js +1 -1
- package/dist/serve/host-modules.js +3 -3
- package/dist/serve/lifecycle.js +4 -3
- package/dist/supabase/load-phase.js +1 -1
- package/dist/users/load-auth.d.ts +10 -0
- package/dist/users/load-auth.js +1 -1
- package/dist/worker/start-worker.js +3 -2
- package/package.json +8 -7
- package/skills/protobase/SKILL.md +7 -1
- package/skills/protobase/references/features/events-webhooks-and-jobs.md +1 -0
- package/skills/protobase/references/features/files-and-images.md +1 -0
- package/skills/protobase/references/features/sign-in-and-accounts.md +3 -0
- package/skills/protobase/references/features/start-a-project.md +7 -1
- package/skills/protobase/references/getting-started.md +13 -13
- package/skills/protobase/references/guides/deploy.md +2 -2
- package/skills/protobase/references/guides/export-a-list.md +1 -1
- package/skills/protobase/references/guides/field-type.md +1 -1
- package/skills/protobase/references/guides/first-composed-page.md +1 -1
- package/skills/protobase/references/guides/first-plugin.md +1 -1
- package/skills/protobase/references/guides/import-records.md +1 -1
- package/skills/protobase/references/guides/personal-setting.md +1 -1
- package/skills/protobase/references/guides/push-notifications.md +1 -1
- package/skills/protobase/references/guides/record-card.md +1 -1
- package/skills/protobase/references/guides/remote-resources.md +1 -1
- package/skills/protobase/references/guides/theme-an-app.md +1 -1
- package/skills/protobase/references/reference/api.md +1 -1
- package/skills/protobase/references/reference/architecture.md +4 -4
- package/skills/protobase/references/reference/auth.md +36 -4
- package/skills/protobase/references/reference/blocks.md +1 -1
- package/skills/protobase/references/reference/bottom-bar.md +1 -1
- package/skills/protobase/references/reference/cli.md +10 -10
- package/skills/protobase/references/reference/client.md +2 -2
- package/skills/protobase/references/reference/config/admin-app.md +62 -0
- package/skills/protobase/references/reference/config/api.md +164 -0
- package/skills/protobase/references/reference/config/app.md +112 -0
- package/skills/protobase/references/reference/config/files.md +99 -0
- package/skills/protobase/references/reference/config/jobs-and-events.md +267 -0
- package/skills/protobase/references/reference/config/sign-in.md +396 -0
- package/skills/protobase/references/reference/config.md +89 -70
- package/skills/protobase/references/reference/custom-components.md +2 -2
- package/skills/protobase/references/reference/data-config.md +2 -2
- package/skills/protobase/references/reference/email.md +2 -2
- package/skills/protobase/references/reference/files.md +6 -3
- package/skills/protobase/references/reference/jobs.md +15 -6
- package/skills/protobase/references/reference/sidebar.md +2 -2
- package/skills/protobase/references/reference/ui-config.md +5 -5
- package/skills/protobase/references/reference/user-menu.md +1 -1
|
@@ -117,7 +117,7 @@ Every option returns a new [field](https://docs.protobase.net/api/schema/interfa
|
|
|
117
117
|
|
|
118
118
|
The ERP's products show most of them, together with soft delete and a tenant:
|
|
119
119
|
|
|
120
|
-
```ts title="
|
|
120
|
+
```ts title="tests/apps/erp/config/products/data.ts"
|
|
121
121
|
import { f, resource } from '@protobase/schema'
|
|
122
122
|
import { erpAccess } from '../roles'
|
|
123
123
|
|
|
@@ -398,7 +398,7 @@ export const workOrders = resource('work_orders')
|
|
|
398
398
|
|
|
399
399
|
Export the roles as `roles` from `config/roles.ts`, where the server finds them, and every operation without a rule needs its capability (`<resource>.<action>`). The ERP's orders use `.owner` and `.search` with the ERP's roles:
|
|
400
400
|
|
|
401
|
-
```ts title="
|
|
401
|
+
```ts title="tests/apps/erp/config/orders/data.ts"
|
|
402
402
|
import { f, resource } from '@protobase/schema'
|
|
403
403
|
import { erpAccess } from '../roles'
|
|
404
404
|
|
|
@@ -12,7 +12,7 @@ An app sends mail through one SMTP server: Protobase's own mail ([password reset
|
|
|
12
12
|
| --- | --- |
|
|
13
13
|
| `PROTOBASE_SMTP_URL` | The SMTP server, credential included: `smtp://user:password@host:587` (STARTTLS when the server offers it) or `smtps://user:password@host:465` (TLS from the start). |
|
|
14
14
|
| `PROTOBASE_MAIL_FROM` | The sender, a plain address such as `noreply@shop.example.com`. The client greets the server with its domain; a `?name=` on the URL overrides that. |
|
|
15
|
-
| `PROTOBASE_APP_NAME` | Optional: the app's name, such as `Shop`, which mail clients show as the sender's name (`Shop <noreply@shop.example.com>`). It overrides the config's [`name`](config.md#
|
|
15
|
+
| `PROTOBASE_APP_NAME` | Optional: the app's name, such as `Shop`, which mail clients show as the sender's name (`Shop <noreply@shop.example.com>`). It overrides the config's [`name`](config/app.md#name). Without either the sender has no name. |
|
|
16
16
|
|
|
17
17
|
Set both or neither. One without the other, a URL that is not `smtp://` or `smtps://`, or a sender that is not a plain address stops the app at startup. Without them mail is off: password reset and emailed codes are not offered, a job's `mail` is `undefined`, and sending an app's email rejects.
|
|
18
18
|
|
|
@@ -26,7 +26,7 @@ PROTOBASE_SMTP_URL=smtp://localhost:1025
|
|
|
26
26
|
PROTOBASE_MAIL_FROM=noreply@shop.example.com
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
A project that delivers
|
|
29
|
+
A project that delivers its mail another way exports a mailer, `{ send({ to, subject, text, html, headers }) }`, as the default of `auth/mailer.ts`: sign-in and the jobs (`mail` in their context) both send with it. `auth: { mailer: false }` turns sign-in's mail off whatever the environment says. A host that runs jobs itself passes a mailer to `startJobs`. A template's `send` takes one too, see [Templates](#templates).
|
|
30
30
|
|
|
31
31
|
## Protobase's own mail
|
|
32
32
|
|
|
@@ -112,15 +112,18 @@ A bucket has no quota of its own, so the provider counts what it holds with `lis
|
|
|
112
112
|
|
|
113
113
|
### Writing files from a seed
|
|
114
114
|
|
|
115
|
-
A seed, an import or another script that writes files outside a request uses `storeFile` from `@protobase/server`, so the same script fills the folder locally and the bucket where the app has one. It finds the provider as the server does, from `env`, and from `files`
|
|
115
|
+
A seed, an import or another script that writes files outside a request uses `storeFile` from `@protobase/server`, so the same script fills the folder locally and the bucket where the app has one. It finds the provider as the server does, from `env`, and from `files` when the script passes the config's, as it is:
|
|
116
116
|
|
|
117
|
-
```ts
|
|
117
|
+
```ts title="docs-examples/files/seed.ts"
|
|
118
118
|
import { storeFile } from '@protobase/server'
|
|
119
|
+
import config from './protobase.config'
|
|
119
120
|
|
|
120
121
|
// A row then holds public:images/test.png
|
|
121
|
-
|
|
122
|
+
export const seedImage = (bytes: Uint8Array) => storeFile({ provider: 'public', path: 'images/test.png', body: bytes, files: config.files, env: process.env })
|
|
122
123
|
```
|
|
123
124
|
|
|
125
|
+
A `custom` provider is the project's own code, so the script imports the default export of `files/<name>.ts` and passes it in `files.providers` in place of `{ kind: 'custom' }`.
|
|
126
|
+
|
|
124
127
|
`body` is bytes or a stream. A relative folder, such as the default `data/files/public`, is taken from the working directory, so run the script where the server runs. A script that makes [variants](#image-variants-and-placeholders) stores each at `variantPath(path, name, extension)` the same way.
|
|
125
128
|
|
|
126
129
|
### S3-compatible buckets
|
|
@@ -37,14 +37,15 @@ export default defineConfig({
|
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
```ts title="jobs/send-invoice.ts"
|
|
40
|
-
import { FatalJobError, type JobRun } from '@protobase/server'
|
|
40
|
+
import { FatalJobError, type JobPayload, type JobRun } from '@protobase/server'
|
|
41
|
+
import type config from '../protobase.config'
|
|
41
42
|
|
|
42
43
|
export default (async ({ invoiceId }, { db }) => {
|
|
43
44
|
const invoice = await db.selectFrom('sales.invoices').select(['id', 'status']).where('id', '=', invoiceId).executeTakeFirst()
|
|
44
45
|
// Retrying will not bring it back: fail for good.
|
|
45
46
|
if (!invoice) throw new FatalJobError(`Invoice ${invoiceId} is gone`)
|
|
46
47
|
// ... render the PDF and mail it
|
|
47
|
-
}) satisfies JobRun<
|
|
48
|
+
}) satisfies JobRun<JobPayload<typeof config, 'send-invoice'>>
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
| Key of a job | |
|
|
@@ -52,7 +53,7 @@ export default (async ({ invoiceId }, { db }) => {
|
|
|
52
53
|
| its name | Letters, digits, `_`, `-`, `.` and `/`; the file `jobs/<name>.ts` holds what it does. |
|
|
53
54
|
| `description` | What the job does, for the people who read the config. |
|
|
54
55
|
| `arguments` | Its arguments by name, each a [field type](data-config.md#field-types) such as `'integer'` or `'bigint'`, or the type with options: `{ type: 'enum', values: ['day', 'week'] }`, `{ type: 'text', min: 1 }`, `{ type: 'integer', optional: true }`, `{ type: 'decimal', precision: 8, scale: 2 }`. Each value is checked as a field of that type checks it, when the job is enqueued and again before it runs, and no other argument is taken. A payload refused at run time fails the job for good. The same is JSON in a `protobase.config.json`. |
|
|
55
|
-
| the default export of `jobs/<name>.ts` | `(payload, { db, job, signal, mail, sendNotification })`, typed with `JobRun<Payload>` from `@protobase/server
|
|
56
|
+
| the default export of `jobs/<name>.ts` | `(payload, { db, job, signal, mail, sendNotification })`, typed with `JobRun<Payload>` from `@protobase/server`, its payload `JobPayload<typeof config, '<name>'>` (see [Typed names and payloads](#typed-names-and-payloads)): the work. `db` is the app's pool: the enqueuer's transaction has committed by then. `job` holds its `id`, `name`, `attempt`, `maxAttempts` and `startedOn`, when this try took it. `signal` aborts when the try times out or the worker shuts down. `mail` sends mail, see [Mail](#mail). `sendNotification` sends a notification, see [Sending](notifications.md#sending); inside a transaction of `db`, a try that throws in it queues nothing. |
|
|
56
57
|
| `maxAttempts` | Tries before the job is kept as failed; default 10. |
|
|
57
58
|
| `retryDelay`, `maxRetryDelay` | The wait before the first retry, doubling with each one (with some jitter), and its ceiling; default `2s` and `1 hour`. Milliseconds or text such as `30 seconds`. |
|
|
58
59
|
| `timeout` | How long one try may run before it counts as failed; default `15 minutes`. |
|
|
@@ -74,16 +75,24 @@ await enqueueJob(db, 'send-invoice', { invoiceId: 7 }, { delay: '5 minutes', key
|
|
|
74
75
|
`db` is the app's database, or the transaction of a write hook or an [API function](../guides/api-functions.md): there, the job commits with the caller's writes, or not at all. It returns the job's id. A write hook is named in the config's `writeHooks` and is the default export of `hooks/<name>.ts`:
|
|
75
76
|
|
|
76
77
|
```ts title="hooks/queue-sent-invoice.ts"
|
|
77
|
-
import { enqueueJob, type PipelineHook } from '@protobase/server'
|
|
78
|
+
import { enqueueJob, type EnqueueJob, type PipelineHook } from '@protobase/server'
|
|
79
|
+
import type config from '../protobase.config'
|
|
80
|
+
|
|
81
|
+
// enqueueJob, typed with the config's jobs: a name it does not declare, or a payload that does not fit, fails to compile.
|
|
82
|
+
const enqueue: EnqueueJob<typeof config> = enqueueJob
|
|
78
83
|
|
|
79
84
|
// In the write's own transaction: the invoice and its job commit together or not at all.
|
|
80
85
|
export default (async (event, trx) => {
|
|
81
86
|
if (event.resource.name !== 'invoices' || event.after?.status !== 'sent' || event.before?.status === 'sent') return
|
|
82
87
|
const invoiceId = Number(event.after.id)
|
|
83
|
-
await
|
|
88
|
+
await enqueue(trx, 'send-invoice', { invoiceId }, { key: `invoice:${invoiceId}` })
|
|
84
89
|
}) satisfies PipelineHook
|
|
85
90
|
```
|
|
86
91
|
|
|
92
|
+
### Typed names and payloads
|
|
93
|
+
|
|
94
|
+
`enqueueJob` takes any name and payload, and checks them when it runs. `EnqueueJob<typeof config>` of `@protobase/server`, with `config` the default export of `protobase.config.ts` imported as a type, checks them as the code compiles, as the hook above does: a name the config does not declare, a required argument left out, one it does not take, or a value of the wrong type is an error. The payload follows each argument's type: a number for `integer`, a boolean for `boolean`, any JSON value for `json`, one of an enum's `values`, and a string for the others, `bigint` and `decimal` too, which JSON numbers cannot hold exactly. `JobPayload<typeof config, '<name>'>` is the same payload, for the job's `JobRun`. A job without `arguments` takes any payload. A `protobase.config.json` gives the names only, since JSON keeps no argument's type.
|
|
95
|
+
|
|
87
96
|
| Option | |
|
|
88
97
|
| --- | --- |
|
|
89
98
|
| `runAt` or `delay` | When the job may run first: a `Date`, or milliseconds or text from now. Default now. |
|
|
@@ -109,7 +118,7 @@ select jobs.enqueue('sync-customer', '{"customerId": 3, "fields": ["email"]}', g
|
|
|
109
118
|
|
|
110
119
|
## Mail
|
|
111
120
|
|
|
112
|
-
`mail.send({ to, subject, text, html })` sends one message, with an optional HTML part beside the plain text, through the app's
|
|
121
|
+
`mail.send({ to, subject, text, html })` sends one message, with an optional HTML part beside the plain text, through the app's mail, the one that also sends password resets and sign-in codes: the mailer of `auth/mailer.ts` when the app has one, else the SMTP server of `PROTOBASE_SMTP_URL` and `PROTOBASE_MAIL_FROM` (see [Email](email.md#configuration)). An [email template](email.md#templates) sends through it with `template.send(to, data, mail)`. It rejects when the server refuses the message, so the try fails and is retried. Without either, `mail` is `undefined`: a job that must send fails for good with `FatalJobError`, and one that may skip mail leaves it out.
|
|
113
122
|
|
|
114
123
|
```ts
|
|
115
124
|
run: async ({ invoiceId }, { db, mail }) => {
|
|
@@ -24,7 +24,7 @@ view<typeof apps>('apps')
|
|
|
24
24
|
An entry can list a few of its records under it, each with a status dot, so the ones that need attention are one click away:
|
|
25
25
|
|
|
26
26
|
```ts
|
|
27
|
-
//
|
|
27
|
+
// tests/apps/erp/config/orders/ui.ts
|
|
28
28
|
export const ordersView = view<typeof orders>('orders')
|
|
29
29
|
.nav({
|
|
30
30
|
recent: {
|
|
@@ -61,4 +61,4 @@ The records come from the list API with the caller's token, so they follow the s
|
|
|
61
61
|
|
|
62
62
|
`/meta` drops the group, and keeps the rest of `nav`, for a caller who cannot read a field it uses (its status, or a field in its filter or order), so it never names a hidden field.
|
|
63
63
|
|
|
64
|
-
`EMAIL=... PASSWORD=... bun scripts/e2e-shell.mjs` checks the groups and the user menu in a browser against a running `bun run --cwd
|
|
64
|
+
`EMAIL=... PASSWORD=... bun scripts/e2e-shell.mjs` checks the groups and the user menu in a browser against a running `bun run --cwd tests/apps/erp dev` (`BASE` for another address), comparing them with what the API gives that user.
|
|
@@ -505,7 +505,7 @@ view<typeof savedSearches>('saved_searches').searchesOf((r) => ({
|
|
|
505
505
|
|
|
506
506
|
The view checks its own fields when the config loads: `filter` and `name` are text fields, `seenAt` a timestamp and each control an enum or boolean. The server checks the rest when it starts: `resource` has an [owner](data-config.md#access), the fields a save or a control writes are writable, `unseen.field` is a filterable timestamp or date of the searched resource, and a view of the resource a list saves to has `searchesOf` for that list. In `/api/meta`, a user who cannot list the searched resource or read `filter` gets the view without `searchesOf`, and its controls and `unseen` narrow to what they can write. A search's filter is checked like any list's when its records load; checking it on a write, against the searched resource, is the data config's: a `.validate` rule with `parseFilter` and `checkFilter`.
|
|
507
507
|
|
|
508
|
-
To tell users of new records, a job matches each new record against the saved filters with `evaluateFilter`, given the searched resource as `search` so that a search text in the filter looks in its search fields too, and sends an [email](email.md). The [property portal example](https://github.com/PrototeamHQ/protobase/tree/main/
|
|
508
|
+
To tell users of new records, a job matches each new record against the saved filters with `evaluateFilter`, given the searched resource as `search` so that a search text in the filter looks in its search fields too, and sends an [email](email.md). The [property portal example](https://github.com/PrototeamHQ/protobase/tree/main/tests/apps/property-portal#alerts) mails at once or in a daily digest.
|
|
509
509
|
|
|
510
510
|
### Exports
|
|
511
511
|
|
|
@@ -763,7 +763,7 @@ d.map(
|
|
|
763
763
|
|
|
764
764
|
`radius`, `area` and `defaultRadius` need `approximate` or `exact`, and the server refuses to start when a field is of another type. A user who may not read the field that marks the positions sees them as exact.
|
|
765
765
|
|
|
766
|
-
<gap>A map does not edit the position.</gap> List the fields in a section as well when users should change them. The [property portal example](https://github.com/PrototeamHQ/protobase/tree/main/
|
|
766
|
+
<gap>A map does not edit the position.</gap> List the fields in a section as well when users should change them. The [property portal example](https://github.com/PrototeamHQ/protobase/tree/main/tests/apps/property-portal) shows a listing on a map, and its listings on one.
|
|
767
767
|
|
|
768
768
|
#### Map layers
|
|
769
769
|
|
|
@@ -796,7 +796,7 @@ export default defineConfig({
|
|
|
796
796
|
| `bounds` | Optional `[west, south, east, north]` in degrees, where the tiles are. The layer is offered everywhere; outside its bounds no tiles are asked for and the style's map shows through. |
|
|
797
797
|
| `maxzoom` | Optional deepest zoom of the tiles, from 0 to 24 (default 22); closer in, the map enlarges them. |
|
|
798
798
|
|
|
799
|
-
The browser fetches the tiles, so their host must answer the app's origins with CORS. Layers need a style: without one there is no map to switch. A layer that is not as above stops the server at startup. Use only tiles whose terms allow it: open aerial photos are published per country, such as the Netherlands' [PDOK Luchtfoto](https://www.pdok.nl/-/open-data-hr-luchtfoto) and Spain's [PNOA](https://pnoa.ign.es/) from the IGN, both CC BY 4.0, free and without a key; the [property portal example](https://github.com/PrototeamHQ/protobase/tree/main/
|
|
799
|
+
The browser fetches the tiles, so their host must answer the app's origins with CORS. Layers need a style: without one there is no map to switch. A layer that is not as above stops the server at startup. Use only tiles whose terms allow it: open aerial photos are published per country, such as the Netherlands' [PDOK Luchtfoto](https://www.pdok.nl/-/open-data-hr-luchtfoto) and Spain's [PNOA](https://pnoa.ign.es/) from the IGN, both CC BY 4.0, free and without a key; the [property portal example](https://github.com/PrototeamHQ/protobase/tree/main/tests/apps/property-portal) offers both.
|
|
800
800
|
|
|
801
801
|
### Related records
|
|
802
802
|
|
|
@@ -822,7 +822,7 @@ Without any configuration, the record page's rail has a **Related records** card
|
|
|
822
822
|
|
|
823
823
|
The real estate example lists who a unit is let to (the primary tenant and co-signers of the lease that runs today) and that lease:
|
|
824
824
|
|
|
825
|
-
```ts title="
|
|
825
|
+
```ts title="tests/apps/real-estate/config/units/ui.ts"
|
|
826
826
|
import { l, view } from '@protobase/schema'
|
|
827
827
|
import type { units } from './data'
|
|
828
828
|
|
|
@@ -942,7 +942,7 @@ export const workshopRepairsView = laidOut
|
|
|
942
942
|
|
|
943
943
|
The ERP's orders view uses most of this page at once, with a recent-record group in the sidebar:
|
|
944
944
|
|
|
945
|
-
```ts title="
|
|
945
|
+
```ts title="tests/apps/erp/config/orders/ui.ts"
|
|
946
946
|
import { view } from '@protobase/schema'
|
|
947
947
|
import type { orders } from './data'
|
|
948
948
|
|
|
@@ -9,7 +9,7 @@ The signed-in user sits at the bottom of the sidebar. Clicking them opens a menu
|
|
|
9
9
|
Export one [`userMenu(...)`](https://docs.protobase.net/api/schema/functions/usermenu/) from the config module:
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
|
-
//
|
|
12
|
+
// tests/apps/erp/config/user-menu.ts, re-exported from config/index.ts
|
|
13
13
|
import { userMenu } from '@protobase/schema'
|
|
14
14
|
|
|
15
15
|
export const accountMenu = userMenu((m) => [
|