@protobase/server 0.47.1 → 0.48.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.
Files changed (51) hide show
  1. package/dist/auth-store.d.ts +3 -0
  2. package/dist/auth-store.js +3 -0
  3. package/dist/better-auth/auth-schema.d.ts +7 -8
  4. package/dist/better-auth/auth-schema.js +40 -42
  5. package/dist/better-auth/auth-tables.d.ts +1 -1
  6. package/dist/better-auth/auth-tables.js +11 -9
  7. package/dist/better-auth/authenticator.d.ts +1 -1
  8. package/dist/better-auth/create-auth.d.ts +20 -12
  9. package/dist/better-auth/create-auth.js +6 -1
  10. package/dist/better-auth/mcp/mcp-plugins.d.ts +1 -1
  11. package/dist/better-auth/store/adoption.js +87 -0
  12. package/dist/better-auth/store/ddl.js +18 -0
  13. package/dist/better-auth/store/drift.d.ts +9 -0
  14. package/dist/better-auth/store/drift.js +18 -0
  15. package/dist/better-auth/store/migration-sql.js +15 -0
  16. package/dist/better-auth/store/migrations/001-core.js +80 -0
  17. package/dist/better-auth/store/migrations/002-two-factor.js +25 -0
  18. package/dist/better-auth/store/migrations/003-passkeys.js +29 -0
  19. package/dist/better-auth/store/migrations/004-sign-in-policy.js +22 -0
  20. package/dist/better-auth/store/migrations/005-staff-sign-in.js +25 -0
  21. package/dist/better-auth/store/migrations/006-organizations.js +50 -0
  22. package/dist/better-auth/store/migrations/007-mcp.js +150 -0
  23. package/dist/better-auth/store/migrations/index.js +22 -0
  24. package/dist/better-auth/store/migrations/migration.d.ts +3 -0
  25. package/dist/better-auth/store/migrations/migration.js +14 -0
  26. package/dist/better-auth/store/migrations-table.d.ts +7 -0
  27. package/dist/better-auth/store/migrations-table.js +23 -0
  28. package/dist/better-auth/store/resources-outside.d.ts +7 -0
  29. package/dist/better-auth/store/resources-outside.js +20 -0
  30. package/dist/better-auth/store/store-db.js +13 -0
  31. package/dist/better-auth/store/store-names.d.ts +2 -0
  32. package/dist/better-auth/store/store-names.js +14 -0
  33. package/dist/better-auth/store/table-names.d.ts +7 -0
  34. package/dist/better-auth/store/table-names.js +10 -0
  35. package/dist/better-auth/users.d.ts +1 -1
  36. package/dist/comments/comment-users.d.ts +1 -1
  37. package/dist/config-exports.d.ts +2 -0
  38. package/dist/config-exports.js +2 -0
  39. package/dist/create-admin.d.ts +1 -1
  40. package/dist/index.d.ts +13 -11
  41. package/dist/index.js +4 -2
  42. package/dist/jobs/job-types.d.ts +1 -1
  43. package/dist/notifications/device-store-of.d.ts +1 -1
  44. package/dist/notifications/history-store-of.d.ts +1 -1
  45. package/dist/notifications/schema.d.ts +1 -1
  46. package/dist/notifications/schema.js +1 -1
  47. package/dist/package.js +1 -1
  48. package/dist/project-config.d.ts +1 -1
  49. package/package.json +6 -4
  50. package/dist/better-auth/mcp/mcp-tables.js +0 -32
  51. package/dist/better-auth/snake-case-migration.js +0 -122
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/server",
3
- "version": "0.47.1",
3
+ "version": "0.48.0",
4
4
  "description": "The Protobase REST API as a Hono app, with Better Auth sign-in.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -16,6 +16,8 @@
16
16
  },
17
17
  "exports": {
18
18
  ".": "./dist/index.js",
19
+ "./auth-store": "./dist/auth-store.js",
20
+ "./config-exports": "./dist/config-exports.js",
19
21
  "./email": "./dist/email.js",
20
22
  "./vapid": "./dist/vapid.js"
21
23
  },
@@ -37,9 +39,9 @@
37
39
  "@better-auth/passkey": "^1.7.12",
38
40
  "@better-auth/sso": "^1.7.12",
39
41
  "@modelcontextprotocol/server": "^2.3.1",
40
- "@protobase/layout": "0.47.1",
41
- "@protobase/query": "0.47.1",
42
- "@protobase/schema": "0.47.1",
42
+ "@protobase/layout": "0.48.0",
43
+ "@protobase/query": "0.48.0",
44
+ "@protobase/schema": "0.48.0",
43
45
  "@react-email/render": "^2.1.0",
44
46
  "@scalar/hono-api-reference": "^0.12.10",
45
47
  "@sentry/core": "^11.7.0",
@@ -1,32 +0,0 @@
1
- import { pluginNames } from "../snake-case-names.js";
2
- //#region src/better-auth/mcp/mcp-tables.ts
3
- /** The database names of MCP's tables. */
4
- const mcpTableNames = Object.values(pluginNames.mcp).map(({ modelName }) => modelName);
5
- const mcpTablesPlugin = {
6
- id: "protobase-mcp-tables",
7
- schema: Object.fromEntries(Object.entries(pluginNames.mcp).map(([model, { modelName }]) => [model, {
8
- modelName,
9
- fields: {}
10
- }]))
11
- };
12
- /** The auth's options, which with MCP off also name MCP's tables, for a plan that tells whether they are left over. */
13
- const withMcpTables = (auth) => auth.mcp ? auth.options : {
14
- ...auth.options,
15
- plugins: [...auth.options.plugins ?? [], mcpTablesPlugin]
16
- };
17
- /** The MCP tables the store still has while MCP is off, from a plan made with `withMcpTables`; none with MCP on. */
18
- const leftoverMcpTables = (auth, { toBeCreated }) => {
19
- if (auth.mcp) return [];
20
- const missing = new Set(toBeCreated.map(({ table }) => table));
21
- return mcpTableNames.filter((table) => !missing.has(table));
22
- };
23
- const schemaName = /^[a-z_][a-z0-9_]*$/;
24
- /** The statement that drops MCP's tables, in `schema` or the connection's current one. */
25
- const dropMcpTables = (schema) => {
26
- if (schema !== void 0 && !schemaName.test(schema)) throw new Error(`Invalid auth schema name "${schema}"`);
27
- const s = schema === void 0 ? "" : `"${schema}".`;
28
- return `-- MCP is off: dropping the tables of its OAuth provider disconnects every MCP client and forgets every grant.
29
- drop table if exists ${mcpTableNames.map((table) => `${s}"${table}"`).join(", ")};`;
30
- };
31
- //#endregion
32
- export { dropMcpTables, leftoverMcpTables, mcpTableNames, withMcpTables };
@@ -1,122 +0,0 @@
1
- //#region src/better-auth/snake-case-migration.ts
2
- const schemaName = /^[a-z_][a-z0-9_]*$/;
3
- /**
4
- * The migration that renames the auth store of Protobase 0.6 in place, from Better Auth's camelCase names to the
5
- * snake_case ones of `snake-case-names.ts`: tables, columns, and the indexes and constraints named after them. Data,
6
- * defaults, keys and indexes stay as they are. On a store that has the snake_case names already it does nothing, so a
7
- * project's migrations can carry it after an auth migration written with them. `schema` is the store's schema, the
8
- * connection's current one when left out.
9
- */
10
- const snakeCaseMigration = (schema) => {
11
- if (schema !== void 0 && !schemaName.test(schema)) throw new Error(`Invalid auth schema name "${schema}"`);
12
- const s = schema === void 0 ? "" : `"${schema}".`;
13
- const current = schema === void 0 ? "current_schema()" : `'${schema}'`;
14
- return `-- Renames the auth store of Protobase 0.6 to snake_case. A store set up with the snake_case names has no "emailVerified"
15
- -- and is left as it is.
16
- do $$
17
- declare
18
- constraint_row record;
19
- begin
20
- if not exists (select from information_schema.columns where table_schema = ${current} and table_name = 'user' and column_name = 'emailVerified') then
21
- return;
22
- end if;
23
-
24
- alter table ${s}"twoFactor" rename to two_factor;
25
- alter table ${s}"signInPolicy" rename to sign_in_policy;
26
- alter table ${s}"staffSignIn" rename to staff_sign_in;
27
-
28
- alter table ${s}"user" rename column "emailVerified" to email_verified;
29
- alter table ${s}"user" rename column "createdAt" to created_at;
30
- alter table ${s}"user" rename column "updatedAt" to updated_at;
31
- alter table ${s}"user" rename column "banReason" to ban_reason;
32
- alter table ${s}"user" rename column "banExpires" to ban_expires;
33
- alter table ${s}"user" rename column "twoFactorEnabled" to two_factor_enabled;
34
-
35
- alter table ${s}session rename column "expiresAt" to expires_at;
36
- alter table ${s}session rename column "createdAt" to created_at;
37
- alter table ${s}session rename column "updatedAt" to updated_at;
38
- alter table ${s}session rename column "ipAddress" to ip_address;
39
- alter table ${s}session rename column "userAgent" to user_agent;
40
- alter table ${s}session rename column "userId" to user_id;
41
- alter table ${s}session rename column "impersonatedBy" to impersonated_by;
42
-
43
- alter table ${s}account rename column "accountId" to account_id;
44
- alter table ${s}account rename column "providerId" to provider_id;
45
- alter table ${s}account rename column "userId" to user_id;
46
- alter table ${s}account rename column "accessToken" to access_token;
47
- alter table ${s}account rename column "refreshToken" to refresh_token;
48
- alter table ${s}account rename column "idToken" to id_token;
49
- alter table ${s}account rename column "accessTokenExpiresAt" to access_token_expires_at;
50
- alter table ${s}account rename column "refreshTokenExpiresAt" to refresh_token_expires_at;
51
- alter table ${s}account rename column "createdAt" to created_at;
52
- alter table ${s}account rename column "updatedAt" to updated_at;
53
-
54
- alter table ${s}verification rename column "expiresAt" to expires_at;
55
- alter table ${s}verification rename column "createdAt" to created_at;
56
- alter table ${s}verification rename column "updatedAt" to updated_at;
57
-
58
- alter table ${s}jwks rename column "publicKey" to public_key;
59
- alter table ${s}jwks rename column "privateKey" to private_key;
60
- alter table ${s}jwks rename column "createdAt" to created_at;
61
- alter table ${s}jwks rename column "expiresAt" to expires_at;
62
-
63
- alter table ${s}two_factor rename column "backupCodes" to backup_codes;
64
- alter table ${s}two_factor rename column "userId" to user_id;
65
- alter table ${s}two_factor rename column "failedVerificationCount" to failed_verification_count;
66
- alter table ${s}two_factor rename column "lockedUntil" to locked_until;
67
-
68
- alter table ${s}passkey rename column "publicKey" to public_key;
69
- alter table ${s}passkey rename column "userId" to user_id;
70
- alter table ${s}passkey rename column "credentialID" to credential_id;
71
- alter table ${s}passkey rename column "deviceType" to device_type;
72
- alter table ${s}passkey rename column "backedUp" to backed_up;
73
- alter table ${s}passkey rename column "createdAt" to created_at;
74
-
75
- alter table ${s}sign_in_policy rename column "emailCode" to email_code;
76
- alter table ${s}sign_in_policy rename column "twoFactor" to two_factor;
77
- alter table ${s}sign_in_policy rename column "staffAccess" to staff_access;
78
- alter table ${s}sign_in_policy rename column "platformSignIn" to platform_sign_in;
79
- alter table ${s}sign_in_policy rename column "createdAt" to created_at;
80
- alter table ${s}sign_in_policy rename column "createdBy" to created_by;
81
-
82
- alter table ${s}staff_sign_in rename column "userId" to user_id;
83
- alter table ${s}staff_sign_in rename column "userEmail" to user_email;
84
- alter table ${s}staff_sign_in rename column "staffName" to staff_name;
85
- alter table ${s}staff_sign_in rename column "staffSubject" to staff_subject;
86
- alter table ${s}staff_sign_in rename column "sessionId" to session_id;
87
- alter table ${s}staff_sign_in rename column "startedAt" to started_at;
88
- alter table ${s}staff_sign_in rename column "expiresAt" to expires_at;
89
- alter table ${s}staff_sign_in rename column "endedAt" to ended_at;
90
-
91
- -- A primary key's index takes the new name with it.
92
- alter table ${s}two_factor rename constraint "twoFactor_pkey" to two_factor_pkey;
93
- alter table ${s}sign_in_policy rename constraint "signInPolicy_pkey" to sign_in_policy_pkey;
94
- alter table ${s}staff_sign_in rename constraint "staffSignIn_pkey" to staff_sign_in_pkey;
95
- alter table ${s}session rename constraint "session_userId_fkey" to session_user_id_fkey;
96
- alter table ${s}account rename constraint "account_userId_fkey" to account_user_id_fkey;
97
- alter table ${s}two_factor rename constraint "twoFactor_userId_fkey" to two_factor_user_id_fkey;
98
- alter table ${s}passkey rename constraint "passkey_userId_fkey" to passkey_user_id_fkey;
99
-
100
- alter index ${s}"session_userId_idx" rename to session_user_id_idx;
101
- alter index ${s}"account_userId_idx" rename to account_user_id_idx;
102
- alter index ${s}"twoFactor_secret_idx" rename to two_factor_secret_idx;
103
- alter index ${s}"twoFactor_userId_idx" rename to two_factor_user_id_idx;
104
- alter index ${s}"passkey_userId_idx" rename to passkey_user_id_idx;
105
- alter index ${s}"passkey_credentialID_idx" rename to passkey_credential_id_idx;
106
-
107
- -- Postgres 18 names each not-null constraint after its table and column, as "user_emailVerified_not_null"; earlier
108
- -- versions keep no such constraints, so there is nothing to rename there.
109
- for constraint_row in
110
- select c.conrelid::regclass as table_name, c.conname as old_name, t.relname || '_' || a.attname || '_not_null' as new_name
111
- from pg_constraint c
112
- join pg_class t on t.oid = c.conrelid
113
- join pg_attribute a on a.attrelid = c.conrelid and a.attnum = c.conkey[1]
114
- where c.contype = 'n' and t.relnamespace = (select oid from pg_namespace where nspname = ${current}) and c.conname ~ '[A-Z]'
115
- loop
116
- execute format('alter table %s rename constraint %I to %I', constraint_row.table_name, constraint_row.old_name, constraint_row.new_name);
117
- end loop;
118
- end
119
- $$;`;
120
- };
121
- //#endregion
122
- export { snakeCaseMigration };