@protobase/cli 0.75.1 → 0.76.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.
@@ -2,16 +2,17 @@ import { checkMobileConfig } from "../mobile/mobile-config.js";
2
2
  //#region src/build/bundle-mobile.ts
3
3
  /**
4
4
  * What the manifest says of the config's `mobile` section, checked as `protobase mobile` checks it: its app id, which a
5
- * host that never runs the config binds in the release's statement, and its plugins, empty when it gives none, which it
6
- * fingerprints the mobile release with. `undefined`
7
- * without a section, so its presence means the app has a mobile build.
5
+ * host that never runs the config binds in the release's statement, and its plugins, empty when it gives none, and
6
+ * `push`, the config's `notifications()`, with which it fingerprints the mobile release. `undefined` without a section,
7
+ * so its presence means the app has a mobile build.
8
8
  */
9
- const bundleMobile = (section) => {
9
+ const bundleMobile = (section, push) => {
10
10
  if (section === void 0) return;
11
11
  const { appId, plugins } = checkMobileConfig(section);
12
12
  return {
13
13
  appId,
14
- plugins: plugins ?? {}
14
+ plugins: plugins ?? {},
15
+ push
15
16
  };
16
17
  };
17
18
  //#endregion
@@ -99,7 +99,8 @@ const buildConfigBundle = async ({ projectDir, outFile, bun, extensions = [], co
99
99
  });
100
100
  return {
101
101
  native: [...native.values()],
102
- mobile: config.mobile
102
+ mobile: config.mobile,
103
+ notifications: Boolean(config.notifications)
103
104
  };
104
105
  };
105
106
  //#endregion
@@ -51,14 +51,14 @@ const buildDeployBundle = async ({ projectDir, outDir, bun, extensions = [], sou
51
51
  await removeOwnFolder(outDir, bundleNodeModules, "nodeModules");
52
52
  await removeOwnFolder(outDir, bundleMigrations, "migrations");
53
53
  const components = /* @__PURE__ */ new Set();
54
- const { native, mobile } = await buildConfigBundle({
54
+ const { native, mobile, notifications } = await buildConfigBundle({
55
55
  projectDir,
56
56
  outFile: path.join(outDir, bundleLayout.server),
57
57
  bun,
58
58
  extensions,
59
59
  components
60
60
  });
61
- const mobileSection = bundleMobile(mobile);
61
+ const mobileSection = bundleMobile(mobile, notifications);
62
62
  await checkViews(projectDir);
63
63
  await checkUi(projectDir, extensions, components);
64
64
  const packages = native.length > 0 ? await copyPackages(native, path.join(outDir, bundleNodeModules)) : [];
@@ -32,7 +32,7 @@ const parseManifest = (value, file) => {
32
32
  if (builtAt !== void 0 && !isTime(builtAt)) throw new Error(`${file} has a builtAt that is no time in ms`);
33
33
  if (icons !== void 0 && !isIcons(icons)) throw new Error(`${file} has icons that are not a favicon flag and a list of PNG icons`);
34
34
  if (native !== void 0 && !isVersions(native)) throw new Error(`${file} has a native that is not a map of package names to versions`);
35
- if (mobile !== void 0 && !(isObject(mobile) && isVersions(mobile.plugins) && (mobile.appId === void 0 || typeof mobile.appId === "string"))) throw new Error(`${file} has a mobile that is not { appId, plugins } with an app id and a map of package names to versions`);
35
+ if (mobile !== void 0 && !(isObject(mobile) && isVersions(mobile.plugins) && (mobile.appId === void 0 || typeof mobile.appId === "string") && (mobile.push === void 0 || typeof mobile.push === "boolean"))) throw new Error(`${file} has a mobile that is not { appId, plugins, push } with an app id, a map of package names to versions and true or false`);
36
36
  if (nodeModules !== void 0 && typeof nodeModules !== "string") throw new Error(`${file} has a nodeModules that is no path`);
37
37
  if (migrations !== void 0 && typeof migrations !== "string") throw new Error(`${file} has a migrations that is no path`);
38
38
  return {
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.75.1";
2
+ var version = "0.76.0";
3
3
  //#endregion
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.75.1",
3
+ "version": "0.76.0",
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.75.1",
47
- "@protobase/layout": "0.75.1",
48
- "@protobase/query": "0.75.1",
49
- "@protobase/schema": "0.75.1",
50
- "@protobase/server": "0.75.1",
51
- "@protobase/ui": "0.75.1",
52
- "@protobase/workflows": "0.75.1",
46
+ "@protobase/config": "0.76.0",
47
+ "@protobase/layout": "0.76.0",
48
+ "@protobase/query": "0.76.0",
49
+ "@protobase/schema": "0.76.0",
50
+ "@protobase/server": "0.76.0",
51
+ "@protobase/ui": "0.76.0",
52
+ "@protobase/workflows": "0.76.0",
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",
@@ -12,6 +12,6 @@ A bell in the top bar and push to browsers and phones, for what your app tells i
12
12
  - [Notification history](../reference/notifications.md#history) (beta): Each user's inbox notifications are kept with when they were read, and the API lists them, counts the unread ones and marks them read.
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
- - Push on iOS (coming soon): Notifications reach the iOS build of the app on a user's iPhones and iPads.
15
+ - [Push on iOS](../reference/notifications.md#ios) (in development): The mobile app receives notifications on iPhone and iPad through the Apple Push Notification service, set up by `protobase mobile`.
16
16
  - [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
17
  - [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.
@@ -254,7 +254,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
254
254
  ],
255
255
  "shell": { "protobase": "0.12.0", "pluginApi": 1, "paths": ["/index.html", "/assets", "/protobase.sw.js"] },
256
256
  "native": { "@capacitor/core": "8.5.3", "@capacitor/ios": "8.5.3" },
257
- "mobile": { "appId": "com.example.shop", "plugins": { "@capacitor/camera": "^8.0.1" } },
257
+ "mobile": { "appId": "com.example.shop", "plugins": { "@capacitor/camera": "^8.0.1" }, "push": true },
258
258
  "nodeModules": "node_modules",
259
259
  "migrations": "migrations"
260
260
  }
@@ -265,7 +265,7 @@ By default the bundle runs on Node and on Bun. `--bun` makes it a bundle for Bun
265
265
  - `plugins` are the bundle's own plugins, in the order the app merges them: the extensions', then the project's (`app`). Each names its `plugin.json`, the plugin API and Protobase versions it is built for, and the [field types](plugins.md#field-types) it registers with the storage types each shows, which the serve runtime checks the views against at startup. `/api/meta` names them to everyone, before any other plugin.
266
266
  - `shell` is the admin app `public/` holds a copy of: its Protobase version and plugin API, and its files as URL paths. A host with a shell of its own may serve its own for those paths instead (see [The UI](#the-ui)), so the app gets that release's fixes without a rebuild.
267
267
  - `native` is the native code, name to version, that `shell` runs on in the [mobile app](../guides/mobile-app.md): the native packages `@protobase/mobile` pins, and `@protobase/mobile` itself at its native contract, such as `native-1`, which Protobase raises when its own native code changes. The fingerprint of the bundle's [mobile release](#mobile-releases) names them. A bundle built before it serves no mobile release.
268
- - `mobile` is present only when the project's config has a `mobile` section, so a host learns that the app has a mobile build without running the config: the section's `appId`, which the statement of a signed mobile release binds, and its `plugins`, name to the spec it gives, `{}` when it gives none, which the fingerprint of the mobile release names besides `native`. A bundle built before it names no `appId`. The build checks the section as `protobase mobile` does.
268
+ - `mobile` is present only when the project's config has a `mobile` section, so a host learns that the app has a mobile build without running the config: the section's `appId`, which the statement of a signed mobile release binds, its `plugins`, name to the spec it gives, `{}` when it gives none, and `push`, whether the config has [`notifications()`](notifications.md), with which the binaries compile native push in; the fingerprint of the mobile release names both besides `native`. A bundle built before it names no `appId`, and one built before `push` none, which counts as `false`. The build checks the section as `protobase mobile` does.
269
269
  - `theme` is the project's [theme](theme.md), which the app links at `/protobase.theme.css`. It is always there, empty when the project has none.
270
270
  - `nodeModules` is present only when the config module imports [native packages](#native-packages). It is always the `node_modules` folder beside `server`, where Bun and Node resolve the module's imports from, and holds plain packages: JavaScript, `package.json` files and native binaries for linux x64 and arm64 (glibc), which the runtime loads with `dlopen`. A host keeps it next to the server module and must not mount it `noexec` (an add-on there then fails with `failed to map segment from shared object`). Its binaries link nothing but glibc, `libstdc++.so.6`, `libgcc_s.so.1` and libraries in the bundle itself, so the run image must have those three. Without `nodeModules`, the server module is the only file the runtime reads.
271
271
  - `migrations` is present only when the project has a `db/migrations` folder: its `.sql` files, which the runtime's `migrate` applies (see [Deploy](../guides/deploy.md)). A host never serves it.
@@ -493,7 +493,7 @@ An Android or iOS app built with `mobile.publicKey` updates itself from the serv
493
493
 
494
494
  A host that serves bundles without running their config, such as a router in front of many apps or a static host, serves the same release from the files it already serves with `@protobase/server/mobile-release`, which loads none of the rest of the server: `protobase serve` composes its own release with the same exports.
495
495
 
496
- - `nativeFingerprint(native, plugins)`: the release's fingerprint, from the manifest's `native` (or that of the shell the host serves) and `mobile.plugins`. It is a contract across versions: a binary one Protobase release built is matched by a host that runs another.
496
+ - `nativeFingerprint(native, plugins, { push })`: the release's fingerprint, from the manifest's `native` (or that of the shell the host serves), `mobile.plugins` and `mobile.push`, `false` when the manifest names none. A host that leaves `push` out matches no binary of an app with `notifications()`. It is a contract across versions: a binary one Protobase release built is matched by a host that runs another.
497
497
  - `releaseOrder({ builtAt, shell })`: the order a release signs, from the manifest's build time and that of the server's own shell the host serves in its place, `[builtAt, 0]` with the bundle's copy; `undefined` when either names no build time.
498
498
  - `withApiOrigin(html, origin)`: the `spa` page naming the API origin, the app's `url`.
499
499
  - `composeRelease(files, signing?)`: the release of `{ href, content }` files, every file the host serves the web with the page above in place of `spa`, with its id and, with `signing`, `{ key, binding: { order, appId, fingerprint, shellVersion } }`, `appId` the manifest's `mobile.appId`, the signed checksums and statement.
@@ -7,7 +7,7 @@ Turn on notifications, send them to users or devices, show each signed-in user t
7
7
  ## Turning them on
8
8
 
9
9
  :::caution[Beta]
10
- Push reaches browsers and the Android app; push on iOS is coming soon.
10
+ Push reaches browsers and the Android app. On iPhone and iPad the server delivers through [APNs](#ios), but the mobile app does not register for push yet.
11
11
  :::
12
12
 
13
13
  Notifications tell a user about something in the app, in a bell in the top bar and as push on their devices. [Send notifications](../guides/push-notifications.md) walks through turning them on and sending the first one. You turn them on in `protobase.config.ts`:
@@ -22,12 +22,12 @@ export default defineConfig({
22
22
 
23
23
  Then run `protobase migration`, which writes the [devices and history tables](#table-names), and the jobs schema that [sending](#sending) runs on, as a migration of the project's own, and apply it with the project's migrations. `protobase dev` and `protobase serve` refuse to start while a table is missing or lacks what notifications need, and name it. Without `notifications` there is none of it: no endpoints, no tables and no migration.
24
24
 
25
- Every signed-in user gets [the bell](#the-bell), browsers receive push through [Web Push](#web-push), and the Android app through [FCM](#android); push on iOS is coming soon. `notifications: { ui: false }` keeps only the backend, [without the bell](#without-the-bell).
25
+ Every signed-in user gets [the bell](#the-bell), browsers receive push through [Web Push](#web-push), the Android app through [FCM](#android) and iOS devices through [APNs](#ios). `notifications: { ui: false }` keeps only the backend, [without the bell](#without-the-bell).
26
26
 
27
27
  ## Devices
28
28
 
29
29
  :::caution[Beta]
30
- Browsers receive push through [Web Push](#web-push), and the Android app through [FCM](#android): push on iOS is coming soon.
30
+ Browsers receive push through [Web Push](#web-push), and the Android app through [FCM](#android). The server delivers to iOS devices through [APNs](#ios), but the mobile app does not register for push on iOS yet.
31
31
  :::
32
32
 
33
33
  A device is where a user receives push: a browser's push subscription, or an Android or iOS app's push token. Each signed-in user registers and removes only their own, through the API:
@@ -67,7 +67,7 @@ The path comes from `devicesPath('/api', id)`, and the name of its id parameter
67
67
  ## Sending
68
68
 
69
69
  :::caution[Beta]
70
- Browsers and the Android app receive push; push on iOS is coming soon. <gap>A send can reach a device twice, or keep an entry twice in a history store of your own, when a worker stops mid-send because saving the send's progress in the same step as the push is not implemented.</gap>
70
+ Browsers and the Android app receive push, and iOS devices through [APNs](#ios) once the mobile app registers them, which is coming soon. <gap>A send can reach a device twice, or keep an entry twice in a history store of your own, when a worker stops mid-send because saving the send's progress in the same step as the push is not implemented.</gap>
71
71
  :::
72
72
 
73
73
  [Send notifications](../guides/push-notifications.md) sends one from a record change, step by step. You send a notification from your server code, such as a job, a hook, an event subscription or an API function, with `sendNotification(db, to, message)` from `@protobase/server`. It is queued as a background job in `db`'s transaction when `db` is one, so it goes out only once your write commits, and nothing goes out when the transaction rolls back. A running job also has it as `sendNotification` in its context, beside `mail`, when the app has `notifications`.
@@ -211,10 +211,30 @@ export const PushButton = () => {
211
211
 
212
212
  `protobase serve` and `protobase dev` both serve the service worker that shows notifications, `protobase dev` only when the app has `notifications`.
213
213
 
214
+ ## iOS
215
+
216
+ :::caution[In development]
217
+ The mobile app does not register for push on iOS yet.
218
+ :::
219
+
220
+ iOS devices receive push through the Apple Push Notification service (APNs), with token authentication. You create an APNs key in your Apple developer account, under Certificates, Identifiers & Profiles, Keys, and set it in three environment variables:
221
+
222
+ | Variable | |
223
+ | --- | --- |
224
+ | `PROTOBASE_APNS_KEY` | the text of the `.p8` file you download, from `-----BEGIN PRIVATE KEY-----` to `-----END PRIVATE KEY-----` |
225
+ | `PROTOBASE_APNS_KEY_ID` | the key's id, ten letters and digits |
226
+ | `PROTOBASE_APNS_TEAM_ID` | your team's id, ten letters and digits |
227
+
228
+ Without them APNs is off and iOS devices are skipped. One or two of them set, a blank one, a key that is no APNs key or an id that is not ten letters and digits stops startup, naming the variable without its value, and so do the three set in an app without a [`mobile`](../guides/mobile-app.md) section. The key is a secret: keep it out of client code, `VITE_` variables and the repository. Anyone holding it can push to every iOS device of your apps.
229
+
230
+ The topic of every notification is the mobile app's `appId`. Each device goes to the environment it was registered with: development builds to the APNs sandbox, App Store and TestFlight builds to production. A device whose token is not lowercase hex, whose environment is neither `sandbox` nor `production`, or that was registered for another app id is `refused`.
231
+
232
+ The notification's title and body are its alert, with its `badge` and `sound`; the JSON also holds `url`, `data` and `user`, the id of the user the device is registered for. `urgency` sets the priority (`very-low` and `low` wait until the device saves power less), `ttl` how long APNs keeps it for a device that is offline, 28 days without one, and `tag` the collapse id. A message's `platform.apns` is merged into the JSON, such as `{ aps: { 'thread-id': 'chat' } }`, never into the request's headers; a `url` in it is checked as the message's is, and the JSON holds at most 4096 bytes. APNs answering that the device is unregistered, or that its token is bad, removes the device; any other refusal, such as a wrong topic or key, is retried and then fails the send, so a mistake in the configuration removes no device.
233
+
214
234
  ## Android
215
235
 
216
236
  :::caution[Beta]
217
- Push on Android is new.
237
+ Push on Android is new, and a message over FCM's size limit is not refused before it is sent (see below).
218
238
  :::
219
239
 
220
240
  Android devices receive push through Firebase Cloud Messaging's HTTP v1 API. You create a service account key in your Firebase project (Project settings, Service accounts, Generate new private key) and set its JSON as `PROTOBASE_FCM_SERVICE_ACCOUNT`. Without it, Android devices are skipped. `protobase mobile` sets the app up from your `google-services.json`: see [Push notifications in the mobile app guide](../guides/mobile-app.md#9-push-notifications).
@@ -288,7 +308,7 @@ A notification is `{ id, userId, title, body, url, data, createdAt, readAt }`, a
288
308
 
289
309
  ### Senders
290
310
 
291
- A sender delivers notifications to the devices of the kinds it names, through their push service. Web Push and FCM 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 Web Push beside them, list it too: `webPushSender(readVapidSettings(process.env)!)` from `@protobase/server` is the built-in sender, and `readVapidSettings` reads the [VAPID variables](#web-push), `undefined` when none is set:
311
+ A sender delivers notifications to the devices of the kinds it names, through their push service. Web Push, APNs and FCM 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:
292
312
 
293
313
  ```ts
294
314
  // notifications/senders.ts