@protobase/cli 0.54.2 → 0.54.4

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.
@@ -1,7 +1,7 @@
1
1
  import { bundleProtobaseVersion } from "../version/project-version.js";
2
2
  import { buildIcons } from "./app-icons.js";
3
- import { bundleLayout, bundleMigrations, bundleNodeModules, manifestFile } from "../bundle/manifest.js";
4
3
  import { protobaseFolder } from "../project/protobase-folder.js";
4
+ import { bundleLayout, bundleMigrations, bundleNodeModules, manifestFile } from "../bundle/manifest.js";
5
5
  import { buildBundlePlugins } from "./bundle-plugins.js";
6
6
  import { copyMigrations } from "./bundle-migrations.js";
7
7
  import { buildConfigBundle } from "./config-bundle.js";
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.54.2";
2
+ var version = "0.54.4";
3
3
  //#endregion
4
4
  export { version };
@@ -1,7 +1,7 @@
1
1
  import { projectPackages } from "../version/project-packages.js";
2
2
  import { uiPackageDir } from "../project/admin-app.js";
3
3
  import { layoutCheck } from "../build/layout-check.js";
4
- import { extensionImports, extensionStyles } from "../project/extensions.js";
4
+ import { extensionImports, projectStyles } from "../project/extensions.js";
5
5
  import { devHost } from "./loopback.js";
6
6
  import { frameHeaders } from "../serve/static-site.js";
7
7
  import { projectUiPlugin } from "../project/project-ui.js";
@@ -67,7 +67,7 @@ const createAppServer = (options, plugins) => {
67
67
  projectUiPlugin(options.projectDir, options.extensions),
68
68
  ...bundled ? [bundledImports(projectDirs)] : [],
69
69
  extensionImports(options.projectDir, options.extensions),
70
- extensionStyles(options.extensions),
70
+ projectStyles(options.projectDir, options.extensions),
71
71
  layoutCheck(),
72
72
  react(),
73
73
  tailwindcss()
@@ -1,4 +1,5 @@
1
1
  import { adminAppDir } from "./admin-app.js";
2
+ import { protobaseFolder } from "./protobase-folder.js";
2
3
  import { existsSync, realpathSync } from "node:fs";
3
4
  import path from "node:path";
4
5
  //#region src/project/extensions.ts
@@ -34,13 +35,19 @@ const extensionImports = (projectDir, extensions) => ({
34
35
  }
35
36
  });
36
37
  const appStyles = path.join(path.dirname(adminAppDir), "styles.css");
37
- const extensionStyles = (extensions) => ({
38
- name: "protobase-extension-styles",
38
+ const projectSources = (projectDir, extensions) => [
39
+ `@source ${JSON.stringify(projectDir)};`,
40
+ `@source not ${JSON.stringify(path.join(projectDir, "dist"))};`,
41
+ `@source not ${JSON.stringify(path.join(projectDir, protobaseFolder))};`,
42
+ ...extensions.map((extension) => `@source ${JSON.stringify(extension.dir)};`)
43
+ ];
44
+ const projectStyles = (projectDir, extensions) => ({
45
+ name: "protobase-project-styles",
39
46
  enforce: "pre",
40
47
  transform: (code, id) => {
41
- if (extensions.length === 0 || id.replace(/\?.*$/, "") !== appStyles) return void 0;
42
- return `${code}\n${extensions.map((extension) => `@source ${JSON.stringify(extension.dir)};`).join("\n")}\n`;
48
+ if (id.replace(/\?.*$/, "") !== appStyles) return void 0;
49
+ return `${code}\n${projectSources(projectDir, extensions).join("\n")}\n`;
43
50
  }
44
51
  });
45
52
  //#endregion
46
- export { extensionConfigFile, extensionImports, extensionStyles, extensionUiFile, resolveExtensions };
53
+ export { extensionConfigFile, extensionImports, extensionUiFile, projectStyles, resolveExtensions };
@@ -0,0 +1,15 @@
1
+ import { apiKeyVariables } from "@protobase/server";
2
+ //#region src/supabase/report-api-keys.ts
3
+ /** What the app needs before supabase-js's clients reach `/api/sb`, in the words of the Supabase client API reference. */
4
+ const apiKeysSection = () => `## API keys
5
+
6
+ The app serves supabase-js's \`/api/sb/rest/v1\`, \`/api/sb/realtime/v1\` and \`/api/sb/storage/v1\` only with API keys, and admits calls to \`/api/sb/functions/v1\` by them. The keys are \`apiKeys\` in \`protobase.config.ts\`, \`{ publishable_key, secret_key }\`, or else \`${apiKeyVariables.publishable_key}\` and \`${apiKeyVariables.secret_key}\` in the app's environment. Without either, or with \`apiKeys: false\`, the app serves none of them. The publishable key takes the place of the Supabase project's anon or publishable key and is safe in a browser; the secret key takes the place of its service_role or secret key and stays on servers.
7
+
8
+ Then point each client at the app's \`/api/sb\` with the publishable key, in place of the project's URL and anon key:
9
+
10
+ \`\`\`ts
11
+ const supabase = createClient('https://<the app's origin>/api/sb', '<the publishable key>')
12
+ \`\`\`
13
+ `;
14
+ //#endregion
15
+ export { apiKeysSection };
@@ -1,5 +1,6 @@
1
1
  import { providerFate } from "./identity-providers.js";
2
2
  import { convertedCronJobs } from "./cron-plan.js";
3
+ import { apiKeysSection } from "./report-api-keys.js";
3
4
  //#region src/supabase/report.ts
4
5
  /** Protobase Cloud's Starter plan holds this much data; the import reports a larger database, it does not refuse it. */
5
6
  const starterBytes = 524288e3;
@@ -72,6 +73,7 @@ const importReport = (manifest, doctor, jobsWired, live, providers) => [
72
73
  `The imported tables take ${megabytes(manifest.bytes)} in the source database${manifest.bytes > starterBytes ? `, more than the ${megabytes(starterBytes)} of the Starter plan: pick a larger plan` : `, within the ${megabytes(starterBytes)} of the Starter plan`}.\n`,
73
74
  `The migration leaves out ${manifest.leftOut} statement${manifest.leftOut === 1 ? "" : "s"} of the dump, as comments: grants to Supabase's own roles and the like.\n`,
74
75
  "## Rows loaded\n\nEach count matched the source before the load committed.\n\n| Table | Rows |\n| --- | --- |\n" + manifest.tables.map((table) => `| ${table.schema}.${table.table} | ${table.rows} |`).join("\n") + "\n",
76
+ apiKeysSection(),
75
77
  signInSection(providers),
76
78
  section("Made again", "A dump cannot carry these. The load made Vault's secrets and pgmq's queues again through each extension's own API, in the same transaction, and scheduled pg_cron's jobs again with `cron.schedule` where the project's database has pg_cron; elsewhere the import made them the app's recurring jobs, on the same schedule. pg_net sends the HTTP triggers' calls from the project's database, Database Webhooks' through the `supabase_functions.http_request` the migration creates.", carried(manifest)),
77
79
  ...recurringJobs(manifest, jobsWired),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/cli",
3
- "version": "0.54.2",
3
+ "version": "0.54.4",
4
4
  "description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -42,12 +42,12 @@
42
42
  "dependencies": {
43
43
  "@better-auth/core": "^1.7.12",
44
44
  "@hono/node-server": "^2.1.3",
45
- "@protobase/config": "0.54.2",
46
- "@protobase/layout": "0.54.2",
47
- "@protobase/query": "0.54.2",
48
- "@protobase/schema": "0.54.2",
49
- "@protobase/server": "0.54.2",
50
- "@protobase/ui": "0.54.2",
45
+ "@protobase/config": "0.54.4",
46
+ "@protobase/layout": "0.54.4",
47
+ "@protobase/query": "0.54.4",
48
+ "@protobase/schema": "0.54.4",
49
+ "@protobase/server": "0.54.4",
50
+ "@protobase/ui": "0.54.4",
51
51
  "@react-email/render": "^2.1.0",
52
52
  "@scalar/hono-api-reference": "^0.12.10",
53
53
  "@tailwindcss/vite": "^4.3.3",
@@ -540,7 +540,7 @@ Turns a Supabase project's database into the project in the current directory, i
540
540
 
541
541
  1. **The first run** takes the Supabase database's connection string, for its `postgres` role (the session pooler's or the direct one; the transaction pooler cannot hold the snapshot the dumps share). It fails unless the database has Supabase's `auth` and `storage` schemas and its `supabase_admin` role, and while `auth.users` has single sign-on (SAML) users, which Supabase opens only through their identity provider and Better Auth would find by email: merge or delete them in Supabase first. It notes the Supabase CLI's `supabase/config.toml`, `supabase/migrations/` and `supabase/functions/` when the checkout has them. It converts `supabase/functions` into the project's `functions/` (see [functions moved from Supabase](../guides/api-functions.md#functions-moved-from-supabase)): `Deno.serve(handler)` and std's `serve(handler)` become `export default defineFunction({ supabase: true }, { fetch: handler })`, an existing default export is wrapped the same way, so each function also answers at `/api/sb/functions/v1/<name>`, `npm:`, `jsr:` and esm.sh imports become bare imports of packages it adds to `package.json`, `Deno.env.get(name)` becomes `process.env[name]`, `EdgeRuntime.waitUntil` becomes `waitUntil` of `@protobase/server`, a function with `verify_jwt = false` in `config.toml` becomes public (`{ public: true, supabase: true }`), and `_shared` and the like are converted beside them. It stops before anything else when `functions/` already has one of their names. It dumps `auth`, `storage` and every schema the app made, schema and data apart, as of one snapshot, leaving out the platform's own migration tables, and writes the schemas as the project's next migration, `NNN_supabase_schema.sql`. It asks the project's database which of the app's extensions its role may create, by trying each in a transaction it rolls back: Postgres alone allows the trusted ones, Supabase's Postgres image all it allowlists, such as pg_net, pgmq and Vault. The migration creates those first, then, where pg_net is among them and the app has Database Webhooks, the `supabase_functions.http_request` function their triggers call, over pg_net; then the dump without what fails there, as comments: grants and default privileges for `dashboard_user`, `supabase_*`, `authenticator` and `postgres`, statements about the `public` schema, Realtime's publication, pgsodium's security labels, the views that decrypt with it and the triggers that encrypt with it, database webhooks without pg_net, functions in plv8, plls or plcoffee where the database has no such language, and a timescaledb hypertable's insert-blocking trigger. It then writes `NNN_supabase_users.sql`, the nullable columns Better Auth needs on `auth.users` (`name`, `email_verified`, `image`, `app_role`, `banned`, `ban_reason`, `ban_expires`) and GoTrue's `'authenticated'` as the default of `role` and `aud`. It writes `NNN_supabase_realtime.sql`, which makes `realtime.messages`, `realtime.topic()`, and Supabase's `realtime.send()` and `realtime.broadcast_changes()`, so the app's triggers and SQL keep [broadcasting from the database](supabase-realtime.md#broadcast-from-the-database), with the source's row security policies on `realtime.messages`, so its [private channels](supabase-realtime.md#private-channels) keep their access; a policy that names only Supabase's own roles is left out as a comment. It points the app at `auth.users`: the `auth` of `protobase.config.ts` gets `users: { table: 'users', columns: { role: 'app_role' }, metadata: 'raw_user_meta_data' }`, `passwordHashes: ['bcrypt']` and `generateUserId: 'uuid'`, or the config gets an `auth` of them when it has none (see [an existing users table](auth.md#an-existing-users-table)). It removes the migrations `protobase auth migration` or `protobase migration` wrote for Protobase's own user table, since `auth.users` replaces it, and stops before writing anything when the project has no `protobase.config.ts`, or one whose `auth` is not an object it can see, or when the project's database has a schema the dump creates already, such as the `auth` schema those migrations made. The project's database needs the roles `anon`, `authenticated` and `service_role` that the dump's grants and policies name; the command makes them when its role may, and otherwise stops, naming them. The data dump goes to `supabase-import/`, which it adds to `.gitignore`, since it holds every row and the users' password hashes. Where the project's database can create Vault, pgmq and pg_cron, `supabase-import/replay.sql` holds what a dump cannot carry: Vault's secrets with their values, read decrypted since only Supabase's key opens their ciphertext, pgmq's queues with their messages, since pgmq owns their tables, and pg_cron's jobs, which live in its own schema.
542
542
  2. **Apply the migration** with the project's other migrations, such as `bun run db:migrate`.
543
- 3. **The second run**, without a connection string, loads the data in one transaction, with the app's triggers off so a sign-up trigger on `auth.users` does not run again for users who already have their rows, and fails the transaction unless every table holds the source's number of rows. In the same transaction it makes Vault's secrets and pgmq's queues again through `vault.create_secret`, `pgmq.create` and `pgmq.send`, each message with its headers and the time it becomes visible. Where the project's database has pg_cron, as Supabase's Postgres image does when it serves that database, it schedules pg_cron's jobs again there with `cron.schedule`, run by the importing role, an inactive one inactive. Elsewhere it writes each job of plain SQL as a [recurring job](jobs.md#recurring-jobs) of its own in `jobs/`, of the same name, schedule and `cron.timezone`, that runs its SQL as the app's database role, tried once each time as pg_cron did, and declares it in the `jobs` of `protobase.config.ts` (or writes one); they run once [`migration`](#migration) has added the jobs schema. Recurring jobs wake an app that sleeps, so they run where a host stops an idle app too. A job that calls what the database lacks, such as pg_net's `net.http_*`, `cron` or Vault, an inactive one and a schedule recurring jobs do not take, such as `30 seconds` or `$`, stay in the report, as does a job of another database. It loads only into empty tables, deletes the data dump and the replay, runs [`scaffold`](#scaffold) on the imported tables of the app's schemas (not `auth` or `storage`), giving the tables of the `supabase_realtime` publication [`.live()`](live.md) so [`/api/sb/realtime/v1`](supabase-realtime.md) keeps sending their `postgres_changes` once [`migration`](#migration) has written their capture triggers, writes Better Auth's other tables next to `auth.users` as [`auth migration`](#auth-migration) does (`NNN_auth.sql`), then `NNN_supabase_accounts.sql`, and writes `supabase-import/report.md`: the rows loaded, the imported tables' size against the Starter plan's 500 MB, each sign-in provider's identities, what it made again, the tables it made live, and what needs a person: the pg_cron jobs it could not carry over, each with why, Realtime tables it made no resource of, Vault secrets by name and pgmq queues where the database has no such extension (and partitioned queues), the columns pgsodium encrypts, still holding Supabase's ciphertext, whose values to export decrypted in Supabase before declaring them [`.encrypted()`](data-config.md#encrypted-fields) and running [`encryption apply`](#encryption-apply), the extensions it cannot create, hypertables and plv8, plls or plcoffee functions to convert, triggers that call out over HTTP without pg_net, the converted Edge Functions with the packages to install and the code the conversion left (`deno.land/x` imports, Deno's file, KV and WebSocket APIs, `Supabase.ai`), and the indexes [`doctor`](#doctor) finds missing. `NNN_supabase_accounts.sql` fills the user columns from what Supabase Auth recorded and leaves them empty where it recorded nothing: the name from `raw_user_meta_data`'s `full_name` or `name`, the picture from its `avatar_url` or `picture`, `email_verified` from `email_confirmed_at`, and a ban from `banned_until`, which Better Auth lifts once it has passed. It gives each password of a confirmed address, as Supabase hashed it, a `credential` account (a user who never confirmed theirs signs in by code or resets the password, since GoTrue refused their password sign-in too), and each identity of a social provider an account under Better Auth's name for it (`azure` is `microsoft`, keyed on the `oid` claim; `linkedin_oidc` is `linkedin`, `slack_oidc` is `slack`, `x` is `twitter`), unless its user has an address they never confirmed, since GoTrue refused that sign-in too. Email, phone, anonymous and single sign-on identities and sessions do not carry over. <gap>The import cannot carry over MFA factors because that is not implemented.</gap> <gap>The import cannot carry over passkeys because that is not implemented.</gap>
543
+ 3. **The second run**, without a connection string, loads the data in one transaction, with the app's triggers off so a sign-up trigger on `auth.users` does not run again for users who already have their rows, and fails the transaction unless every table holds the source's number of rows. In the same transaction it makes Vault's secrets and pgmq's queues again through `vault.create_secret`, `pgmq.create` and `pgmq.send`, each message with its headers and the time it becomes visible. Where the project's database has pg_cron, as Supabase's Postgres image does when it serves that database, it schedules pg_cron's jobs again there with `cron.schedule`, run by the importing role, an inactive one inactive. Elsewhere it writes each job of plain SQL as a [recurring job](jobs.md#recurring-jobs) of its own in `jobs/`, of the same name, schedule and `cron.timezone`, that runs its SQL as the app's database role, tried once each time as pg_cron did, and declares it in the `jobs` of `protobase.config.ts` (or writes one); they run once [`migration`](#migration) has added the jobs schema. Recurring jobs wake an app that sleeps, so they run where a host stops an idle app too. A job that calls what the database lacks, such as pg_net's `net.http_*`, `cron` or Vault, an inactive one and a schedule recurring jobs do not take, such as `30 seconds` or `$`, stay in the report, as does a job of another database. It loads only into empty tables, deletes the data dump and the replay, runs [`scaffold`](#scaffold) on the imported tables of the app's schemas (not `auth` or `storage`), giving the tables of the `supabase_realtime` publication [`.live()`](live.md) so [`/api/sb/realtime/v1`](supabase-realtime.md) keeps sending their `postgres_changes` once [`migration`](#migration) has written their capture triggers, writes Better Auth's other tables next to `auth.users` as [`auth migration`](#auth-migration) does (`NNN_auth.sql`), then `NNN_supabase_accounts.sql`, and writes `supabase-import/report.md`: the rows loaded, the API keys `/api/sb` needs and the `createClient` change to the app's `/api/sb` and its publishable key, the imported tables' size against the Starter plan's 500 MB, each sign-in provider's identities, what it made again, the tables it made live, and what needs a person: the pg_cron jobs it could not carry over, each with why, Realtime tables it made no resource of, Vault secrets by name and pgmq queues where the database has no such extension (and partitioned queues), the columns pgsodium encrypts, still holding Supabase's ciphertext, whose values to export decrypted in Supabase before declaring them [`.encrypted()`](data-config.md#encrypted-fields) and running [`encryption apply`](#encryption-apply), the extensions it cannot create, hypertables and plv8, plls or plcoffee functions to convert, triggers that call out over HTTP without pg_net, the converted Edge Functions with the packages to install and the code the conversion left (`deno.land/x` imports, Deno's file, KV and WebSocket APIs, `Supabase.ai`), and the indexes [`doctor`](#doctor) finds missing. `NNN_supabase_accounts.sql` fills the user columns from what Supabase Auth recorded and leaves them empty where it recorded nothing: the name from `raw_user_meta_data`'s `full_name` or `name`, the picture from its `avatar_url` or `picture`, `email_verified` from `email_confirmed_at`, and a ban from `banned_until`, which Better Auth lifts once it has passed. It gives each password of a confirmed address, as Supabase hashed it, a `credential` account (a user who never confirmed theirs signs in by code or resets the password, since GoTrue refused their password sign-in too), and each identity of a social provider an account under Better Auth's name for it (`azure` is `microsoft`, keyed on the `oid` claim; `linkedin_oidc` is `linkedin`, `slack_oidc` is `slack`, `x` is `twitter`), unless its user has an address they never confirmed, since GoTrue refused that sign-in too. Email, phone, anonymous and single sign-on identities and sessions do not carry over. <gap>The import cannot carry over MFA factors because that is not implemented.</gap> <gap>The import cannot carry over passkeys because that is not implemented.</gap>
544
544
  4. **Apply the migrations** again. Supabase's users then sign in with their own passwords, and with a social provider once it is in the `socialProviders` of the config's `auth`; new users get a UUID in `auth.users`, so the app's triggers there run for them.
545
545
 
546
546
  5. **Storage's files**: with `--storage-url https://<ref>.supabase.co` and the project's secret key in the variable `--storage-key-env` names, `SUPABASE_SERVICE_ROLE_KEY` by default, the second run, or any run after it, copies the bytes of every object in `storage.objects` from the Supabase project's Storage API into the app's [Storage file provider](supabase-storage.md#where-things-are-kept), where [`/api/sb/storage/v1`](supabase-storage.md) serves them, with the type and cache control the rows recorded. It streams each object, checks its byte count against the size Supabase recorded and its MD5 against the ETag where that is one, and deletes a copy that does not match. It first prints each bucket's size and stops when what is left to copy and what the provider holds exceed the provider's `max_bytes`, unless `--yes`. An object that fails does not stop the rest; the run then fails, listing them in `supabase-import/storage.md`, and a rerun copies only what the provider does not hold yet. The key goes only in the requests' headers, never in a file.
@@ -36,6 +36,10 @@ description: Finish a move from Supabase to Protobase after `protobase import su
36
36
 
37
37
  Nothing to do: each table's count matched the source before the load committed.
38
38
 
39
+ ### API keys
40
+
41
+ Unless `protobase.config.ts` sets `apiKeys`, add `PROTOBASE_PUBLISHABLE_KEY` and `PROTOBASE_SECRET_KEY` to `.env.example` with empty values: the user enters the keys, never you. Then point every `createClient` at the app's `/api/sb` with the publishable key, in place of the Supabase project's URL and anon key, reading both from the app's own settings, not the Supabase ones. See [Supabase client API](../protobase/references/reference/supabase-rest.md#keys-and-roles).
42
+
39
43
  ### Sign-in
40
44
 
41
45
  Passwords need nothing: the import's migrations carry them over. For each provider listed with accounts: