@protobase/cli 0.25.12 → 0.26.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.
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.25.12";
2
+ var version = "0.26.0";
3
3
  //#endregion
4
4
  export { version };
@@ -4,9 +4,10 @@ import { configExports, createAdmin, jobDefinitions } from "@protobase/server";
4
4
  * The admin API of a project over `db`, as `dev`, `serve` and `worker` build it: its config module's resources, views,
5
5
  * pages and subscriptions, and the rest of its config; served from a bundle, the plugins it carries and their field
6
6
  * types. `jobs` are the project's own and the delivery of its events and history. With a `reporter`, every error the API turns
7
- * into a 500 goes to the error tracker too, besides the project's `onUnhandledError` or the console.
7
+ * into a 500 goes to the error tracker too, besides the project's `onUnhandledError` or the console. With the host's
8
+ * `upgradeWebSocket`, it serves `/realtime/v1` too.
8
9
  */
9
- const projectAdmin = (project, config, db, ui, reporter) => {
10
+ const projectAdmin = (project, config, db, ui, reporter, upgradeWebSocket) => {
10
11
  const { resources, views, pages, userMenu, bottomBars, subscriptions } = configExports(config);
11
12
  const own = jobDefinitions(project.jobs ?? {});
12
13
  const unhandled = project.options?.onUnhandledError ?? ((error) => console.error(error));
@@ -30,6 +31,7 @@ const projectAdmin = (project, config, db, ui, reporter) => {
30
31
  bundlePlugins: ui.plugins,
31
32
  fieldTypes: ui.fieldTypes
32
33
  },
34
+ ...upgradeWebSocket && { upgradeWebSocket },
33
35
  options: {
34
36
  ...project.options,
35
37
  onUnhandledError: (error, request) => {
@@ -4,7 +4,8 @@ import { createServeApp } from "./app.js";
4
4
  import { startCleanupTimer } from "./cleanup-timer.js";
5
5
  import { checkAi, checkAuthSchema, checkChanges, checkComments, checkComputed, checkJobsSchema, checkWebhooksSchema, configExports, createFileCleanup, startJobs } from "@protobase/server";
6
6
  import pg from "pg";
7
- import { createAdaptorServer } from "@hono/node-server";
7
+ import { createAdaptorServer, upgradeWebSocket } from "@hono/node-server";
8
+ import { WebSocketServer } from "ws";
8
9
  //#region src/serve/lifecycle.ts
9
10
  const listen = (server, port) => new Promise((resolve, reject) => {
10
11
  server.once("error", reject);
@@ -31,7 +32,7 @@ const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url
31
32
  env: process.env
32
33
  });
33
34
  if (env.startupChecks && project.webhooks) await checkWebhooksSchema(db, project.webhooks);
34
- const { admin, jobs: definitions } = projectAdmin(project, project.config, db, ui, reporter);
35
+ const { admin, jobs: definitions } = projectAdmin(project, project.config, db, ui, reporter, upgradeWebSocket);
35
36
  if (env.startupChecks && definitions.length > 0) await checkJobsSchema(db);
36
37
  const jobs = definitions.length > 0 ? await startJobs({
37
38
  db,
@@ -48,7 +49,8 @@ const startServe = async ({ project, env, createDb = (url) => createPgDb(pg, url
48
49
  });
49
50
  const server = createAdaptorServer({
50
51
  fetch: app.fetch,
51
- overrideGlobalObjects: false
52
+ overrideGlobalObjects: false,
53
+ websocket: { server: new WebSocketServer({ noServer: true }) }
52
54
  });
53
55
  await listen(server, env.port).catch(async (error) => {
54
56
  await jobs?.stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.25.12",
3
+ "version": "0.26.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": {
@@ -35,11 +35,11 @@
35
35
  "dependencies": {
36
36
  "@hono/node-server": "^2.1.3",
37
37
  "@hono/vite-dev-server": "^0.26.1",
38
- "@protobase/layout": "0.25.12",
39
- "@protobase/query": "0.25.12",
40
- "@protobase/schema": "0.25.12",
41
- "@protobase/server": "0.25.12",
42
- "@protobase/ui": "0.25.12",
38
+ "@protobase/layout": "0.26.0",
39
+ "@protobase/query": "0.26.0",
40
+ "@protobase/schema": "0.26.0",
41
+ "@protobase/server": "0.26.0",
42
+ "@protobase/ui": "0.26.0",
43
43
  "@react-email/render": "^2.1.0",
44
44
  "@scalar/hono-api-reference": "^0.12.10",
45
45
  "@tailwindcss/vite": "^4.3.3",
@@ -58,9 +58,11 @@
58
58
  "react": "^19.3.0",
59
59
  "ts-morph": "^28.0.0",
60
60
  "vite": "^8.3.3",
61
+ "ws": "^8.22.0",
61
62
  "zod": "^4.6.5"
62
63
  },
63
64
  "devDependencies": {
65
+ "@types/ws": "^8.18.2",
64
66
  "tsx": "^4.23.15"
65
67
  }
66
68
  }
@@ -66,6 +66,7 @@ Reference:
66
66
  - When keeping or showing the changes of records → read [Record history](references/reference/history.md)
67
67
  - When adding comments to records → read [Record comments](references/reference/comments.md)
68
68
  - When open pages should refresh as records change → read [Live updates](references/reference/live.md)
69
+ - When an app listens to `postgres_changes` with supabase-js under RLS → read [Supabase Realtime](references/reference/supabase-realtime.md)
69
70
  - When filling fields with a model → read [AI fields and actions](references/reference/ai.md)
70
71
  - When letting people without an account create records → read [Public forms](references/reference/forms.md)
71
72
  - When running background jobs → read [Jobs](references/reference/jobs.md)
@@ -59,7 +59,7 @@ createAuth({
59
59
  })
60
60
  ```
61
61
 
62
- - `users.table` names the table, default `user`. `users.columns` maps a column, by the name Protobase gives it (`name`, `email`, `email_verified`, `image`, `created_at`, `updated_at`, `role`, `banned`, `ban_reason`, `ban_expires`, `two_factor_enabled`, `last_role`, `last_organization_id`), to the table's own; here the app's roles go to `app_role`, since Supabase's `role` holds the Postgres role. The other tables keep their names and point at this one.
62
+ - `users.table` names the table, default `user`. `users.columns` maps a column, by the name Protobase gives it (`name`, `email`, `email_verified`, `email_confirmed_at`, `image`, `created_at`, `updated_at`, `role`, `banned`, `ban_reason`, `ban_expires`, `two_factor_enabled`, `last_role`, `last_organization_id`), to the table's own; here the app's roles go to `app_role`, since Supabase's `role` holds the Postgres role. The other tables keep their names and point at this one.
63
63
  - `users.metadata` names a JSON column for each user's metadata: `createUser(auth, { ..., metadata: { full_name: 'Carol' } })` writes it, so a trigger that reads `raw_user_meta_data->>'full_name'` sees it.
64
64
  - `passwordHashes: ['bcrypt']` also verifies bcrypt hashes (`$2a$`, `$2b$`, `$2y$`), and stores the password again as Better Auth's own scrypt after its first sign-in. The 12-character minimum holds for new passwords only, so a shorter existing one still signs in.
65
65
  - `generateUserId: 'uuid'` makes each new user's id a random UUID in the server, for a table whose `id` is a `uuid` without a default, and makes every id column of the other tables a `uuid` too.
@@ -445,6 +445,17 @@ betterAuthAuthenticator({ auth, apps: [{ issuer: 'https://shop.example.com', rol
445
445
 
446
446
  Their tokens are verified against that app's keys at `<issuer>/api/auth/jwks`; a role it does not map is dropped, a role held in one of its organizations never counts, and a user left with none gets `403`; their id here is `<sub>@<that app's host>`. See [Signing in at the source](remote-resources.md#signing-in-at-the-source)).
447
447
 
448
+ ## supabase-js and @supabase/ssr
449
+
450
+ An app moving from Supabase keeps its `supabase.auth` calls and its `@supabase/ssr` session checks: the app serves GoTrue's endpoints at `/auth/v1`, over the same Better Auth sign-in, so `createClient(<the app's origin>, <publishable key>)` signs in, refreshes, reads the user and signs out as on Supabase.
451
+
452
+ - `signInWithPassword`, `signInWithOtp` then `verifyOtp({ email, token, type: 'email' })`, `signInWithOAuth` with one of the app's [sign-in providers](#sign-in-with-github) (PKCE, as `@supabase/ssr` uses, or the implicit flow), `refreshSession`, `getUser`, `getClaims`, `updateUser({ password, data })` and `signOut` work. Each goes through Better Auth's own endpoint, with its rate limits and the [sign-in policy](#sign-in-policy).
453
+ - Addresses are proved with the emailed 6-digit code, never a link. `signUp({ email, password, options: { data } })` needs [open sign-up](#open-sign-up) and mails a sign-up code; `verifyOtp({ email, token, type: 'signup' })` makes the account, with `data` in the [user metadata column](#an-existing-users-table), and signs in. Until then there is no account and `signUp` answers no user. `resetPasswordForEmail` mails a sign-in code; `verifyOtp` with `type: 'recovery'` signs in, and `updateUser({ password })` sets the new password.
454
+ - The access token is ES256, valid for an hour, with Supabase's claims: `sub`, `role: authenticated`, `aud: authenticated`, `email`, `app_metadata`, `user_metadata`, `aal`, `session_id`, issued by `<baseURL>/auth/v1`. Its keys are at `/auth/v1/.well-known/jwks.json`. It is apart from the EdDSA token of [Tokens and roles](#tokens-and-roles): neither is accepted for the other.
455
+ - The refresh token is the Better Auth session's token. Each refresh gives the session a new one, so a refresh token works once, and signing out, a ban or a revoked session ends it.
456
+ - `email_confirmed_at` is the time the address was confirmed, in the user table's `email_confirmed_at` column. An account verified before that column existed has none.
457
+ - Not offered: MFA, passkeys, SSO, phone sign-in, anonymous sign-in, the admin API and changing the address.
458
+
448
459
  ## Tokens for scripts and curl
449
460
 
450
461
  There is no development login. For scripts, mint a token for an existing user on the host (the CLI exposes it as `protobase token you@example.com`):
@@ -0,0 +1,39 @@
1
+ <!-- Generated by scripts/protobase-skill.ts from website/src/content/docs/reference/supabase-realtime.md: run `bun run docs:skill`, do not edit. -->
2
+
3
+ # Supabase Realtime
4
+
5
+ The Realtime-compatible /realtime/v1 that supabase-js's channel().on('postgres_changes') listens to, each change checked under the subscriber's RLS policies.
6
+
7
+ An app with API keys and [live resources](live.md)) also serves `/realtime/v1/websocket`, the socket that supabase-js's `channel()` joins. An app moved from Supabase keeps its `postgres_changes` listeners: point the client at the app and give it the publishable key.
8
+
9
+ ```ts
10
+ import { createClient } from '@supabase/supabase-js'
11
+
12
+ const supabase = createClient('https://my-app.example.com', 'sb_publishable_...')
13
+ supabase
14
+ .channel('my-todos')
15
+ .on('postgres_changes', { event: 'INSERT', schema: 'public', table: 'todos', filter: 'done=eq.false' }, (payload) => console.log(payload.new))
16
+ .subscribe()
17
+ ```
18
+
19
+ ## Keys, roles and tokens
20
+
21
+ The keys are `options.apiKeys` of `createAdmin`, `{ publishable_key, secret_key }`, or else `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY`. The socket sends the key in its URL and is refused with `401` without a key of the app. Each channel joins with the client's access token: a signed-in user's token makes it `authenticated` with the token's claims, the publishable key alone `anon`, the secret key alone the app's own role. A token the client refreshes on an open socket replaces the channel's; a channel whose token expires is closed with a `Token has expired` system message, as on Supabase.
22
+
23
+ The server serves the socket when the host gives `createAdmin` its WebSocket upgrade: `protobase serve` does, on Bun and Node. `protobase dev` does not serve it yet.
24
+
25
+ ## Which tables
26
+
27
+ A channel may listen to the tables of the resources with [`.live()`](live.md)), by `schema` (`*` for any), `table` (every live table of the schema when left out), `event` (`INSERT`, `UPDATE`, `DELETE` or `*`) and `filter`. A table that is not live is refused when the channel joins, with Supabase's message. A filter is Supabase's: `column=operator.value`, with `eq`, `neq`, `lt`, `lte`, `gt`, `gte`, `in.(a,b)`, `like`, `ilike`, `match`, `imatch`, `is` and `isdistinct`, `not.` before the operator, and several conditions joined by commas, all of which must hold. Postgres compares each value as the column's type. `select` of columns is not supported yet; broadcast, presence and private channels neither.
28
+
29
+ ## What a subscriber receives
30
+
31
+ Each change is checked for each subscriber before it is sent. The database needs the `anon` and `authenticated` roles, and the app's role must be allowed to `SET ROLE` to them. In one transaction per batch of changes, the server sets the subscriber's role with `SET LOCAL ROLE` and its claims in `request.jwt.claims` and `request.jwt.claim.sub`, so Supabase's `auth.uid()` and `auth.jwt()` work, reads the changed rows by key, and sends an insert or update only when the table's RLS policies let the subscriber select the row, with the columns its role may select. Subscribers with the same role and claims, such as one user's tabs, are checked once. The check holds one pooled connection per serving process, and only while it runs, never one per socket.
32
+
33
+ Unlike Supabase, which reads changes from the write-ahead log, the server reads them from the [live updates' notices](live.md#the-table)), which keep record keys only. So:
34
+
35
+ - An insert or update carries the row as it is when it is checked. Several changes of a row between two checks each carry its latest state, and a row deleted or no longer visible by then is not sent. `old_record` holds the primary key alone, as on Supabase without `replica identity full`.
36
+ - A delete carries the primary key alone and is not checked against RLS, as on Supabase. A filter on a column other than the key does not match a delete.
37
+ - `commit_timestamp` is when the change became a notice, within a second or two of the commit.
38
+
39
+ Changes reach subscribers within a second or two, the notices being read once a second.