@protobase/cli 0.79.3 → 0.79.5
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
CHANGED
package/dist/main.js
CHANGED
|
@@ -159,6 +159,8 @@ program.command("serve").description("Serve a bundle written by `protobase build
|
|
|
159
159
|
});
|
|
160
160
|
program.command("worker").description("Run the jobs of a bundle from `protobase build` in a process of their own, until SIGTERM or SIGINT, as `serve` runs them beside the API").argument("<bundle>", "the bundle folder, e.g. dist, or its dist/protobase.config.js").action(async (bundle) => {
|
|
161
161
|
loadNearestEnvFile(process.cwd());
|
|
162
|
+
const { provideHostModules } = await import("./serve/host-modules.js");
|
|
163
|
+
provideHostModules();
|
|
162
164
|
const [{ loadWorkerBundle, startWorker }, { projectErrorReporter }, { reportCrashes }, { closeOnSignals }] = await Promise.all([
|
|
163
165
|
import("./worker/start-worker.js"),
|
|
164
166
|
import("./project/error-reporter.js"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.79.
|
|
3
|
+
"version": "0.79.5",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.79.
|
|
47
|
-
"@protobase/layout": "0.79.
|
|
48
|
-
"@protobase/query": "0.79.
|
|
49
|
-
"@protobase/schema": "0.79.
|
|
50
|
-
"@protobase/server": "0.79.
|
|
51
|
-
"@protobase/ui": "0.79.
|
|
52
|
-
"@protobase/workflows": "0.79.
|
|
46
|
+
"@protobase/config": "0.79.5",
|
|
47
|
+
"@protobase/layout": "0.79.5",
|
|
48
|
+
"@protobase/query": "0.79.5",
|
|
49
|
+
"@protobase/schema": "0.79.5",
|
|
50
|
+
"@protobase/server": "0.79.5",
|
|
51
|
+
"@protobase/ui": "0.79.5",
|
|
52
|
+
"@protobase/workflows": "0.79.5",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -13,5 +13,6 @@ A bell in the top bar and push to browsers and phones, for what your app tells i
|
|
|
13
13
|
- [Web Push](../reference/notifications.md#web-push) (beta): Notifications reach desktop and Android browsers and home-screen web apps on iPhone through Web Push, with keys you generate.
|
|
14
14
|
- [Push on Android](../reference/notifications.md#android) (beta): The server sends notifications to Android devices through Firebase Cloud Messaging with the service account key in `PROTOBASE_FCM_SERVICE_ACCOUNT`, and the mobile app receives them, set up by `protobase mobile` from a `google-services.json` in the project.
|
|
15
15
|
- [Push on iOS](../reference/notifications.md#ios) (in development): The server sends notifications to iPhone and iPad through the Apple Push Notification service with the APNs key in `PROTOBASE_APNS_KEY`, `PROTOBASE_APNS_KEY_ID` and `PROTOBASE_APNS_TEAM_ID`; the mobile app registering for them and receiving them on iOS is coming soon.
|
|
16
|
+
- [Push relay](../reference/notifications.md#push-relay) (beta): Send push notifications through a relay that holds the mobile app's push keys, so your app needs only its own relay credential.
|
|
16
17
|
- [Do not disturb](../reference/status.md#do-not-disturb) (beta): While someone is on do not disturb, sends push nothing to their devices and keep inbox notifications in the bell for later.
|
|
17
18
|
- [Notification bell](../reference/notifications.md#the-bell) (beta): The top bar shows how many inbox notifications are unread; its panel opens each one, marks them read and turns push on or off for this device.
|
|
@@ -466,7 +466,7 @@ The app's address and secret are `PROTOBASE_URL` and `PROTOBASE_SECRET` unless i
|
|
|
466
466
|
- **Startup:** a config module that `protobase build` did not write, a config with an `apiPath` other than `/api/v1`, or one with sign-in on and no secret or URL, stops startup with a one-line error and exit code 1, as does a missing `DATABASE_URL`, an auth store that has not applied every migration of this version, or has a newer one (see [`auth migration`](#auth-migration)), a resource over a table of the auth store, a resource whose [events](events.md) or [history](history.md) lack their triggers or have out-of-date ones, or a missing history or [comments](comments.md#the-table) table, a [rollup or formula field](data-config.md#rollups-and-formulas) whose column or trigger is missing or out of date, a jobs schema that is missing or behind for a config with [jobs](jobs.md#the-jobs-schema) (see [`migration`](#migration)), an [AI field or action](ai.md#the-model) without a model key, [encrypted fields](data-config.md#encrypted-fields) without a key, or another resource over their column, or a taken port; `PROTOBASE_STARTUP_CHECKS=false` skips the checks of those schemas and the key. `protobase serve listening on port <port>` means it is ready.
|
|
467
467
|
- **Jobs:** with [jobs](jobs.md) in the config it runs them beside the API, unless `PROTOBASE_JOBS=false`, and with `PROTOBASE_JOBS_DRAIN_TOKEN` it answers `POST /api/jobs/drain` for the operator.
|
|
468
468
|
- **Shutdown:** the first SIGTERM or SIGINT stops accepting connections, closes open WebSockets with 1001 (dropping any still open after 5 seconds), waits for open requests, gives running jobs 30 seconds to finish, drains the pool `serve` created and exits with 0.
|
|
469
|
-
- **Host modules:** under Bun, the runtime registers [the modules it supplies](#the-config-module) as virtual modules, so the bundle needs no `node_modules` for them. `protobase serve` under Bun
|
|
469
|
+
- **Host modules:** under Bun, the runtime registers [the modules it supplies](#the-config-module) as virtual modules, so the bundle needs no `node_modules` for them. `protobase serve` and `protobase worker` under Bun do the same with the CLI's own copies, whatever the project installed, so a bundle runs on the copies of the CLI that runs it. <gap>`protobase serve` and `protobase worker` on Node cannot give a bundle the CLI's own host modules because a module hook for Node is not implemented.</gap> On Node both resolve them from the `node_modules` next to the bundle, so there keep the bundle inside the project, whose installed versions it then runs on. Native packages load from the bundle's own `node_modules/` under both.
|
|
470
470
|
- **Read-only hosts:** nothing is written: no install (`--no-install`), and for a bundle built with `--bun` no transpiling and so no transpiler cache. A bundle with `node_modules/` needs its folder mounted without `noexec`, since its add-ons are mapped as executable code.
|
|
471
471
|
|
|
472
472
|
### Mobile releases
|
|
@@ -37,7 +37,7 @@ A device is where a user receives push: a browser's push subscription, or an And
|
|
|
37
37
|
| `POST /api/notifications/devices` | registers the device the request comes from, or refreshes it; answers `{ id, kind, createdAt, lastSeenAt }` |
|
|
38
38
|
| `DELETE /api/notifications/devices/<id>` | removes the caller's device with that id; answers `204` whether or not the caller had it |
|
|
39
39
|
|
|
40
|
-
The body of a register is JSON (`Content-Type: application/json`, at most 8 KB), in one of
|
|
40
|
+
The body of a register is JSON (`Content-Type: application/json`, at most 8 KB), in one of four shapes:
|
|
41
41
|
|
|
42
42
|
```jsonc
|
|
43
43
|
// A browser: its PushSubscription as JSON
|
|
@@ -46,6 +46,8 @@ The body of a register is JSON (`Content-Type: application/json`, at most 8 KB),
|
|
|
46
46
|
{ "kind": "apns", "token": "…", "environment": "production", "appId": "net.example.app" }
|
|
47
47
|
// An Android app: its token, and optionally its package name
|
|
48
48
|
{ "kind": "fcm", "token": "…", "appId": "net.example.app" }
|
|
49
|
+
// A mobile app's handle from a push relay
|
|
50
|
+
{ "kind": "relay", "handle": "…" }
|
|
49
51
|
```
|
|
50
52
|
|
|
51
53
|
A field that does not belong to the kind, a missing one, an unknown one such as an owner, or a value out of its format is a `400` that names the field and stores nothing. A browser's `endpoint` must be an https URL on one of the browsers' push services. `environment` is `sandbox` or `production`, and `userAgent`, optional for every kind, is at most 512 characters. The stored device keeps `null` in the fields its kind does not have.
|
|
@@ -58,7 +60,7 @@ Who may call them:
|
|
|
58
60
|
- An app with its own authenticator ([`auth/authenticate.ts`](config/sign-in.md#authenticate)) marks a user's own sign-in on the session it returns, `signIn: { staff: false }`; without that mark, its sessions are refused.
|
|
59
61
|
- With Protobase's auth, every token the endpoints take names its sign-in session; one that names none is refused with a `403`.
|
|
60
62
|
|
|
61
|
-
A device is one token, or one endpoint for a browser. An Android or iOS token someone else had moves to the caller, as a new device with a new id that keeps nothing of the previous user's, so a shared phone notifies whoever signed in on it last. A browser's endpoint never moves: registering one another user holds is a `409` of type `device-held` that stores nothing, and the browser subscribes again for a new endpoint, as [the browser helper](#in-the-browser) does. A user keeps up to 20 devices: registering one more removes their least recently seen. Deleting a user removes their devices.
|
|
63
|
+
A device is one token, or one endpoint for a browser. An Android or iOS token, or a relay handle, someone else had moves to the caller, as a new device with a new id that keeps nothing of the previous user's, so a shared phone notifies whoever signed in on it last. A browser's endpoint never moves: registering one another user holds is a `409` of type `device-held` that stores nothing, and the browser subscribes again for a new endpoint, as [the browser helper](#in-the-browser) does. A user keeps up to 20 devices: registering one more removes their least recently seen. Deleting a user removes their devices.
|
|
62
64
|
|
|
63
65
|
With Protobase's auth, a device belongs to the sign-in session it was registered in. Once that session ends, the device gets no more push and is removed at the next send: when the user signs out, someone signs in on the same browser, the user signs out everywhere, a password change signs out their other devices, an admin ends their sessions or bans them, or the session expires. Registering the device again ties it to the session of that request, which the browser helper does on its own for the same user. With an app's own authenticator, a device stays its user's until it is removed with `DELETE`.
|
|
64
66
|
|
|
@@ -256,6 +258,33 @@ Any other field is refused, such as `token`, `topic`, `webpush` or `click_action
|
|
|
256
258
|
|
|
257
259
|
`fcmSender(readFcmSettings(process.env)!)` from `@protobase/server` is the built-in sender, to list beside [your own senders](#senders).
|
|
258
260
|
|
|
261
|
+
## Push relay
|
|
262
|
+
|
|
263
|
+
:::caution[Beta]
|
|
264
|
+
The relay service, and the mobile app that registers relay handles, are coming soon.
|
|
265
|
+
:::
|
|
266
|
+
|
|
267
|
+
An app can deliver mobile push through a relay instead of holding APNs or FCM keys itself. The relay holds the mobile app's push keys, and your app sends to it with a relay credential of its own. You set the relay's URL and your app's credential in two environment variables:
|
|
268
|
+
|
|
269
|
+
```sh
|
|
270
|
+
PROTOBASE_PUSH_RELAY_URL=https://relay.example.com
|
|
271
|
+
PROTOBASE_PUSH_RELAY_CREDENTIAL=...
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Without them the relay is off and relay devices are skipped. Only one of them set, a URL that is not `https` or that has a user, query or fragment, or a credential that is not 16 to 1024 letters, digits and `-._~+/` stops startup, naming the variable without its value. The credential is a secret: keep it out of client code, `VITE_` variables and the repository.
|
|
275
|
+
|
|
276
|
+
A device registered with a relay handle, `{ "kind": "relay", "handle": "…" }` (see [Devices](#devices)), receives your app's notifications with the usual [inbox](#history), [do not disturb](status.md#do-not-disturb) and sign-in session rules. The handle is what the relay gave the device for your app, never its own push token: 16 to 512 letters, digits, `-` and `_`.
|
|
277
|
+
|
|
278
|
+
Each send is `POST <url>/send`, with the credential as a bearer token, never through a redirect, and JSON with the [message](#senders) as senders get it and up to 100 devices, each with its handle and `user`, the id of the user it is registered for:
|
|
279
|
+
|
|
280
|
+
```json
|
|
281
|
+
{ "message": { "title": "Task assigned", "url": "https://app.example.com/tasks/42" }, "devices": [{ "handle": "…", "user": "user-1" }] }
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
The relay answers a `2xx` with a result for each handle, `ok`, `gone`, `retry` or `refused`, as [senders](#senders) answer: `{ "results": [{ "handle": "…", "result": "ok" }] }`. A handle the relay answers `gone` removes its device. A handle it does not answer, and every handle of any other answer, such as a wrong credential, a `429` or `5xx` (after its `Retry-After`) or no answer within ten seconds, is retried, so a mistake in the configuration removes no device. A device stored with a token that is not a relay handle is `refused`. <gap>A send cannot keep the notification's text from the relay because content-free or encrypted relay payloads are not implemented.</gap>
|
|
285
|
+
|
|
286
|
+
`relaySender(readRelaySettings(process.env)!)` from `@protobase/server` is the built-in sender, to list beside [your own senders](#senders). `relaySendRequest` and `relaySendAnswer` check the request and answer shapes.
|
|
287
|
+
|
|
259
288
|
## Your own parts
|
|
260
289
|
|
|
261
290
|
:::caution[Beta]
|
|
@@ -308,7 +337,7 @@ A notification is `{ id, userId, title, body, url, data, createdAt, readAt }`, a
|
|
|
308
337
|
|
|
309
338
|
### Senders
|
|
310
339
|
|
|
311
|
-
A sender delivers notifications to the devices of the kinds it names, through their push service. Web Push, APNs and
|
|
340
|
+
A sender delivers notifications to the devices of the kinds it names, through their push service. Web Push, APNs, FCM and the [push relay](#push-relay) are built in; your own senders, such as from a package, are the default export of `notifications/senders.ts`, an array, and they replace the built-in ones, at most one for each kind. To keep a built-in one beside them, list it too: `webPushSender(readVapidSettings(process.env)!)` from `@protobase/server` is the built-in Web Push sender, and `readVapidSettings` reads the [VAPID variables](#web-push), `undefined` when none is set; `apnsSender(readApnsSettings(process.env)!, { appId })` is the built-in APNs sender, with the mobile app's `appId`, and `readApnsSettings` reads the [APNs variables](#ios) the same way:
|
|
312
341
|
|
|
313
342
|
```ts
|
|
314
343
|
// notifications/senders.ts
|