create-protobase 0.47.0 → 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.
@@ -0,0 +1,297 @@
1
+ -- The auth schema changes this version of Protobase needs, written by `protobase auth migration`.
2
+ -- Applied with the project's other migrations; edit or remove statements the project handles differently.
3
+
4
+ -- The record of the auth store's migrations.
5
+ create schema if not exists "auth";
6
+
7
+ create table "auth"."auth_migrations" (
8
+ version integer primary key,
9
+ name text not null,
10
+ applied_at timestamptz default current_timestamp not null
11
+ );
12
+
13
+ -- The auth store an earlier Protobase made, without a record of its migrations, adopted: 1 core, 2 two_factor, 3 passkeys, 4 sign_in_policy, 5 staff_sign_in, 6 organizations
14
+ -- recorded as applied, once every table and column they make is there.
15
+ do $adopt$
16
+ declare
17
+ missing text;
18
+ begin
19
+ select string_agg(expected.table_name || '.' || expected.column_name, ', ' order by expected.table_name, expected.column_name) into missing
20
+ from (values ('account', 'id', 'text'),
21
+ ('account', 'account_id', 'text'),
22
+ ('account', 'provider_id', 'text'),
23
+ ('account', 'user_id', 'text'),
24
+ ('account', 'access_token', 'text'),
25
+ ('account', 'refresh_token', 'text'),
26
+ ('account', 'id_token', 'text'),
27
+ ('account', 'access_token_expires_at', 'timestamptz'),
28
+ ('account', 'refresh_token_expires_at', 'timestamptz'),
29
+ ('account', 'scope', 'text'),
30
+ ('account', 'password', 'text'),
31
+ ('account', 'created_at', 'timestamptz'),
32
+ ('account', 'updated_at', 'timestamptz'),
33
+ ('jwks', 'id', 'text'),
34
+ ('jwks', 'public_key', 'text'),
35
+ ('jwks', 'private_key', 'text'),
36
+ ('jwks', 'created_at', 'timestamptz'),
37
+ ('jwks', 'expires_at', 'timestamptz'),
38
+ ('jwks', 'alg', 'text'),
39
+ ('jwks', 'crv', 'text'),
40
+ ('session', 'id', 'text'),
41
+ ('session', 'expires_at', 'timestamptz'),
42
+ ('session', 'token', 'text'),
43
+ ('session', 'created_at', 'timestamptz'),
44
+ ('session', 'updated_at', 'timestamptz'),
45
+ ('session', 'ip_address', 'text'),
46
+ ('session', 'user_agent', 'text'),
47
+ ('session', 'user_id', 'text'),
48
+ ('session', 'impersonated_by', 'text'),
49
+ ('session', 'active_role', 'text'),
50
+ ('user', 'id', 'text'),
51
+ ('user', 'name', 'text'),
52
+ ('user', 'email', 'text'),
53
+ ('user', 'email_verified', 'bool'),
54
+ ('user', 'image', 'text'),
55
+ ('user', 'created_at', 'timestamptz'),
56
+ ('user', 'updated_at', 'timestamptz'),
57
+ ('user', 'role', 'text'),
58
+ ('user', 'banned', 'bool'),
59
+ ('user', 'ban_reason', 'text'),
60
+ ('user', 'ban_expires', 'timestamptz'),
61
+ ('user', 'last_role', 'text'),
62
+ ('user', 'email_confirmed_at', 'timestamptz'),
63
+ ('verification', 'id', 'text'),
64
+ ('verification', 'identifier', 'text'),
65
+ ('verification', 'value', 'text'),
66
+ ('verification', 'expires_at', 'timestamptz'),
67
+ ('verification', 'created_at', 'timestamptz'),
68
+ ('verification', 'updated_at', 'timestamptz'),
69
+ ('two_factor', 'id', 'text'),
70
+ ('two_factor', 'secret', 'text'),
71
+ ('two_factor', 'backup_codes', 'text'),
72
+ ('two_factor', 'user_id', 'text'),
73
+ ('two_factor', 'verified', 'bool'),
74
+ ('two_factor', 'failed_verification_count', 'int4'),
75
+ ('two_factor', 'locked_until', 'timestamptz'),
76
+ ('user', 'two_factor_enabled', 'bool'),
77
+ ('passkey', 'id', 'text'),
78
+ ('passkey', 'name', 'text'),
79
+ ('passkey', 'public_key', 'text'),
80
+ ('passkey', 'user_id', 'text'),
81
+ ('passkey', 'credential_id', 'text'),
82
+ ('passkey', 'counter', 'int4'),
83
+ ('passkey', 'device_type', 'text'),
84
+ ('passkey', 'backed_up', 'bool'),
85
+ ('passkey', 'transports', 'text'),
86
+ ('passkey', 'created_at', 'timestamptz'),
87
+ ('passkey', 'aaguid', 'text'),
88
+ ('passkey', 'rp_id', 'text'),
89
+ ('sign_in_policy', 'id', 'text'),
90
+ ('sign_in_policy', 'password', 'text'),
91
+ ('sign_in_policy', 'email_code', 'text'),
92
+ ('sign_in_policy', 'passkey', 'text'),
93
+ ('sign_in_policy', 'two_factor', 'text'),
94
+ ('sign_in_policy', 'staff_access', 'text'),
95
+ ('sign_in_policy', 'platform_sign_in', 'text'),
96
+ ('sign_in_policy', 'created_at', 'timestamptz'),
97
+ ('sign_in_policy', 'created_by', 'text'),
98
+ ('staff_sign_in', 'id', 'text'),
99
+ ('staff_sign_in', 'user_id', 'text'),
100
+ ('staff_sign_in', 'user_email', 'text'),
101
+ ('staff_sign_in', 'staff', 'text'),
102
+ ('staff_sign_in', 'staff_name', 'text'),
103
+ ('staff_sign_in', 'staff_subject', 'text'),
104
+ ('staff_sign_in', 'issuer', 'text'),
105
+ ('staff_sign_in', 'reason', 'text'),
106
+ ('staff_sign_in', 'session_id', 'text'),
107
+ ('staff_sign_in', 'started_at', 'timestamptz'),
108
+ ('staff_sign_in', 'expires_at', 'timestamptz'),
109
+ ('staff_sign_in', 'ended_at', 'timestamptz'),
110
+ ('invitation', 'id', 'text'),
111
+ ('invitation', 'organization_id', 'text'),
112
+ ('invitation', 'email', 'text'),
113
+ ('invitation', 'role', 'text'),
114
+ ('invitation', 'status', 'text'),
115
+ ('invitation', 'expires_at', 'timestamptz'),
116
+ ('invitation', 'created_at', 'timestamptz'),
117
+ ('invitation', 'inviter_id', 'text'),
118
+ ('invitation', 'app_roles', 'jsonb'),
119
+ ('member', 'id', 'text'),
120
+ ('member', 'organization_id', 'text'),
121
+ ('member', 'user_id', 'text'),
122
+ ('member', 'role', 'text'),
123
+ ('member', 'created_at', 'timestamptz'),
124
+ ('member', 'app_roles', 'jsonb'),
125
+ ('organization', 'id', 'text'),
126
+ ('organization', 'name', 'text'),
127
+ ('organization', 'slug', 'text'),
128
+ ('organization', 'logo', 'text'),
129
+ ('organization', 'created_at', 'timestamptz'),
130
+ ('organization', 'metadata', 'text'),
131
+ ('session', 'active_organization_id', 'text'),
132
+ ('user', 'last_organization_id', 'text')) as expected (table_name, column_name, udt_name)
133
+ where not exists (
134
+ select from information_schema.columns found
135
+ where found.table_schema = 'auth' and found.table_name = expected.table_name and found.column_name = expected.column_name and found.udt_name = expected.udt_name
136
+ );
137
+ if missing is not null then
138
+ raise exception 'The auth store does not match the migrations this file adopts: it lacks %, or has them as other types', missing;
139
+ end if;
140
+ end
141
+ $adopt$;
142
+
143
+ insert into "auth"."auth_migrations" (version, name) values (1, 'core'), (2, 'two_factor'), (3, 'passkeys'), (4, 'sign_in_policy'), (5, 'staff_sign_in'), (6, 'organizations');
144
+
145
+ -- 7 mcp: The clients, resources, tokens and consents of the OAuth provider for MCP.
146
+ create table "auth"."oauth_client" (
147
+ id text primary key,
148
+ client_id text not null unique,
149
+ client_secret text,
150
+ client_discovery_id text,
151
+ disabled boolean,
152
+ skip_consent boolean,
153
+ enable_end_session boolean,
154
+ subject_type text,
155
+ scopes jsonb,
156
+ client_credentials_scopes jsonb,
157
+ user_id text references "auth"."user" (id) on delete cascade,
158
+ created_at timestamptz,
159
+ updated_at timestamptz,
160
+ name text,
161
+ uri text,
162
+ icon text,
163
+ contacts jsonb,
164
+ tos text,
165
+ policy text,
166
+ software_id text,
167
+ software_version text,
168
+ software_statement text,
169
+ redirect_uris jsonb not null,
170
+ post_logout_redirect_uris jsonb,
171
+ backchannel_logout_uri text,
172
+ backchannel_logout_session_required boolean,
173
+ token_endpoint_auth_method text,
174
+ application_type text,
175
+ jwks text,
176
+ jwks_uri text,
177
+ grant_types jsonb,
178
+ response_types jsonb,
179
+ require_pkce boolean,
180
+ dpop_bound_access_tokens boolean,
181
+ reference_id text,
182
+ metadata jsonb
183
+ );
184
+
185
+ create index oauth_client_user_id_idx on "auth"."oauth_client" (user_id);
186
+
187
+ create table "auth"."oauth_resource" (
188
+ id text primary key,
189
+ identifier text not null unique,
190
+ name text not null,
191
+ access_token_ttl integer,
192
+ refresh_token_ttl integer,
193
+ signing_algorithm text,
194
+ signing_key_id text,
195
+ allowed_scopes jsonb,
196
+ custom_claims jsonb,
197
+ dpop_bound_access_tokens_required boolean,
198
+ disabled boolean,
199
+ created_at timestamptz,
200
+ updated_at timestamptz,
201
+ policy_version integer,
202
+ metadata jsonb
203
+ );
204
+
205
+ create table "auth"."oauth_client_resource" (
206
+ id text primary key,
207
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
208
+ resource_id text not null references "auth"."oauth_resource" (identifier) on delete cascade,
209
+ metadata jsonb,
210
+ created_at timestamptz
211
+ );
212
+
213
+ create index oauth_client_resource_client_id_idx on "auth"."oauth_client_resource" (client_id);
214
+
215
+ create index oauth_client_resource_resource_id_idx on "auth"."oauth_client_resource" (resource_id);
216
+
217
+ create unique index oauth_client_resource_client_id_resource_id_uidx on "auth"."oauth_client_resource" (client_id, resource_id);
218
+
219
+ create table "auth"."oauth_refresh_token" (
220
+ id text primary key,
221
+ token text not null unique,
222
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
223
+ session_id text references "auth"."session" (id) on delete set null,
224
+ user_id text not null references "auth"."user" (id) on delete cascade,
225
+ reference_id text,
226
+ authorization_code_id text,
227
+ resources jsonb,
228
+ requested_user_info_claims jsonb,
229
+ expires_at timestamptz not null,
230
+ created_at timestamptz not null,
231
+ revoked timestamptz,
232
+ rotated_at timestamptz,
233
+ rotation_replay_response text,
234
+ rotation_replay_expires_at timestamptz,
235
+ auth_time timestamptz,
236
+ confirmation jsonb,
237
+ scopes jsonb not null
238
+ );
239
+
240
+ create index oauth_refresh_token_client_id_idx on "auth"."oauth_refresh_token" (client_id);
241
+
242
+ create index oauth_refresh_token_session_id_idx on "auth"."oauth_refresh_token" (session_id);
243
+
244
+ create index oauth_refresh_token_user_id_idx on "auth"."oauth_refresh_token" (user_id);
245
+
246
+ create index oauth_refresh_token_authorization_code_id_idx on "auth"."oauth_refresh_token" (authorization_code_id);
247
+
248
+ create table "auth"."oauth_access_token" (
249
+ id text primary key,
250
+ token text not null unique,
251
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
252
+ session_id text references "auth"."session" (id) on delete set null,
253
+ user_id text references "auth"."user" (id) on delete cascade,
254
+ reference_id text,
255
+ authorization_code_id text,
256
+ resources jsonb,
257
+ requested_user_info_claims jsonb,
258
+ refresh_id text references "auth"."oauth_refresh_token" (id) on delete cascade,
259
+ expires_at timestamptz not null,
260
+ created_at timestamptz not null,
261
+ revoked timestamptz,
262
+ confirmation jsonb,
263
+ scopes jsonb not null
264
+ );
265
+
266
+ create index oauth_access_token_client_id_idx on "auth"."oauth_access_token" (client_id);
267
+
268
+ create index oauth_access_token_session_id_idx on "auth"."oauth_access_token" (session_id);
269
+
270
+ create index oauth_access_token_user_id_idx on "auth"."oauth_access_token" (user_id);
271
+
272
+ create index oauth_access_token_authorization_code_id_idx on "auth"."oauth_access_token" (authorization_code_id);
273
+
274
+ create index oauth_access_token_refresh_id_idx on "auth"."oauth_access_token" (refresh_id);
275
+
276
+ create table "auth"."oauth_consent" (
277
+ id text primary key,
278
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
279
+ user_id text references "auth"."user" (id) on delete cascade,
280
+ reference_id text,
281
+ resources jsonb,
282
+ requested_user_info_claims jsonb,
283
+ scopes jsonb not null,
284
+ created_at timestamptz not null,
285
+ updated_at timestamptz not null
286
+ );
287
+
288
+ create index oauth_consent_client_id_idx on "auth"."oauth_consent" (client_id);
289
+
290
+ create index oauth_consent_user_id_idx on "auth"."oauth_consent" (user_id);
291
+
292
+ create table "auth"."oauth_client_assertion" (
293
+ id text primary key,
294
+ expires_at timestamptz not null
295
+ );
296
+
297
+ insert into "auth"."auth_migrations" (version, name) values (7, 'mcp');
@@ -16,11 +16,11 @@
16
16
  "dev": "protobase dev"
17
17
  },
18
18
  "dependencies": {
19
- "@protobase/cli": "^0.47.0",
20
- "@protobase/layout": "^0.47.0",
21
- "@protobase/schema": "^0.47.0",
22
- "@protobase/server": "^0.47.0",
23
- "@protobase/ui": "^0.47.0",
19
+ "@protobase/cli": "^0.48.0",
20
+ "@protobase/layout": "^0.48.0",
21
+ "@protobase/schema": "^0.48.0",
22
+ "@protobase/server": "^0.48.0",
23
+ "@protobase/ui": "^0.48.0",
24
24
  "better-auth": "^1.7.12",
25
25
  "jose": "^6.2.12",
26
26
  "kysely": "^0.29.6",
@@ -0,0 +1,319 @@
1
+ -- The auth schema changes this version of Protobase needs, written by `protobase auth migration`.
2
+ -- Applied with the project's other migrations; edit or remove statements the project handles differently.
3
+
4
+ -- The record of the auth store's migrations.
5
+ create schema if not exists "auth";
6
+
7
+ create table "auth"."auth_migrations" (
8
+ version integer primary key,
9
+ name text not null,
10
+ applied_at timestamptz default current_timestamp not null
11
+ );
12
+
13
+ -- The auth store an earlier Protobase made, without a record of its migrations, adopted: 1 core, 2 two_factor, 3 passkeys, 4 sign_in_policy, 5 staff_sign_in
14
+ -- recorded as applied, once every table and column they make is there.
15
+ do $adopt$
16
+ declare
17
+ missing text;
18
+ begin
19
+ select string_agg(expected.table_name || '.' || expected.column_name, ', ' order by expected.table_name, expected.column_name) into missing
20
+ from (values ('account', 'id', 'text'),
21
+ ('account', 'account_id', 'text'),
22
+ ('account', 'provider_id', 'text'),
23
+ ('account', 'user_id', 'text'),
24
+ ('account', 'access_token', 'text'),
25
+ ('account', 'refresh_token', 'text'),
26
+ ('account', 'id_token', 'text'),
27
+ ('account', 'access_token_expires_at', 'timestamptz'),
28
+ ('account', 'refresh_token_expires_at', 'timestamptz'),
29
+ ('account', 'scope', 'text'),
30
+ ('account', 'password', 'text'),
31
+ ('account', 'created_at', 'timestamptz'),
32
+ ('account', 'updated_at', 'timestamptz'),
33
+ ('jwks', 'id', 'text'),
34
+ ('jwks', 'public_key', 'text'),
35
+ ('jwks', 'private_key', 'text'),
36
+ ('jwks', 'created_at', 'timestamptz'),
37
+ ('jwks', 'expires_at', 'timestamptz'),
38
+ ('jwks', 'alg', 'text'),
39
+ ('jwks', 'crv', 'text'),
40
+ ('session', 'id', 'text'),
41
+ ('session', 'expires_at', 'timestamptz'),
42
+ ('session', 'token', 'text'),
43
+ ('session', 'created_at', 'timestamptz'),
44
+ ('session', 'updated_at', 'timestamptz'),
45
+ ('session', 'ip_address', 'text'),
46
+ ('session', 'user_agent', 'text'),
47
+ ('session', 'user_id', 'text'),
48
+ ('session', 'impersonated_by', 'text'),
49
+ ('session', 'active_role', 'text'),
50
+ ('user', 'id', 'text'),
51
+ ('user', 'name', 'text'),
52
+ ('user', 'email', 'text'),
53
+ ('user', 'email_verified', 'bool'),
54
+ ('user', 'image', 'text'),
55
+ ('user', 'created_at', 'timestamptz'),
56
+ ('user', 'updated_at', 'timestamptz'),
57
+ ('user', 'role', 'text'),
58
+ ('user', 'banned', 'bool'),
59
+ ('user', 'ban_reason', 'text'),
60
+ ('user', 'ban_expires', 'timestamptz'),
61
+ ('user', 'last_role', 'text'),
62
+ ('user', 'email_confirmed_at', 'timestamptz'),
63
+ ('verification', 'id', 'text'),
64
+ ('verification', 'identifier', 'text'),
65
+ ('verification', 'value', 'text'),
66
+ ('verification', 'expires_at', 'timestamptz'),
67
+ ('verification', 'created_at', 'timestamptz'),
68
+ ('verification', 'updated_at', 'timestamptz'),
69
+ ('two_factor', 'id', 'text'),
70
+ ('two_factor', 'secret', 'text'),
71
+ ('two_factor', 'backup_codes', 'text'),
72
+ ('two_factor', 'user_id', 'text'),
73
+ ('two_factor', 'verified', 'bool'),
74
+ ('two_factor', 'failed_verification_count', 'int4'),
75
+ ('two_factor', 'locked_until', 'timestamptz'),
76
+ ('user', 'two_factor_enabled', 'bool'),
77
+ ('passkey', 'id', 'text'),
78
+ ('passkey', 'name', 'text'),
79
+ ('passkey', 'public_key', 'text'),
80
+ ('passkey', 'user_id', 'text'),
81
+ ('passkey', 'credential_id', 'text'),
82
+ ('passkey', 'counter', 'int4'),
83
+ ('passkey', 'device_type', 'text'),
84
+ ('passkey', 'backed_up', 'bool'),
85
+ ('passkey', 'transports', 'text'),
86
+ ('passkey', 'created_at', 'timestamptz'),
87
+ ('passkey', 'aaguid', 'text'),
88
+ ('passkey', 'rp_id', 'text'),
89
+ ('sign_in_policy', 'id', 'text'),
90
+ ('sign_in_policy', 'password', 'text'),
91
+ ('sign_in_policy', 'email_code', 'text'),
92
+ ('sign_in_policy', 'passkey', 'text'),
93
+ ('sign_in_policy', 'two_factor', 'text'),
94
+ ('sign_in_policy', 'staff_access', 'text'),
95
+ ('sign_in_policy', 'platform_sign_in', 'text'),
96
+ ('sign_in_policy', 'created_at', 'timestamptz'),
97
+ ('sign_in_policy', 'created_by', 'text'),
98
+ ('staff_sign_in', 'id', 'text'),
99
+ ('staff_sign_in', 'user_id', 'text'),
100
+ ('staff_sign_in', 'user_email', 'text'),
101
+ ('staff_sign_in', 'staff', 'text'),
102
+ ('staff_sign_in', 'staff_name', 'text'),
103
+ ('staff_sign_in', 'staff_subject', 'text'),
104
+ ('staff_sign_in', 'issuer', 'text'),
105
+ ('staff_sign_in', 'reason', 'text'),
106
+ ('staff_sign_in', 'session_id', 'text'),
107
+ ('staff_sign_in', 'started_at', 'timestamptz'),
108
+ ('staff_sign_in', 'expires_at', 'timestamptz'),
109
+ ('staff_sign_in', 'ended_at', 'timestamptz')) as expected (table_name, column_name, udt_name)
110
+ where not exists (
111
+ select from information_schema.columns found
112
+ where found.table_schema = 'auth' and found.table_name = expected.table_name and found.column_name = expected.column_name and found.udt_name = expected.udt_name
113
+ );
114
+ if missing is not null then
115
+ raise exception 'The auth store does not match the migrations this file adopts: it lacks %, or has them as other types', missing;
116
+ end if;
117
+ end
118
+ $adopt$;
119
+
120
+ insert into "auth"."auth_migrations" (version, name) values (1, 'core'), (2, 'two_factor'), (3, 'passkeys'), (4, 'sign_in_policy'), (5, 'staff_sign_in');
121
+
122
+ -- 6 organizations: Organizations, their members and their invitations.
123
+ alter table "auth"."user" add column if not exists "last_organization_id" text;
124
+
125
+ alter table "auth"."session" add column active_organization_id text;
126
+
127
+ create table "auth"."organization" (
128
+ id text primary key,
129
+ name text not null,
130
+ slug text not null unique,
131
+ logo text,
132
+ created_at timestamptz not null,
133
+ metadata text
134
+ );
135
+
136
+ create table "auth"."member" (
137
+ id text primary key,
138
+ organization_id text not null references "auth"."organization" (id) on delete cascade,
139
+ user_id text not null references "auth"."user" (id) on delete cascade,
140
+ role text not null,
141
+ created_at timestamptz not null,
142
+ app_roles jsonb
143
+ );
144
+
145
+ create index member_organization_id_idx on "auth"."member" (organization_id);
146
+
147
+ create index member_user_id_idx on "auth"."member" (user_id);
148
+
149
+ create table "auth"."invitation" (
150
+ id text primary key,
151
+ organization_id text not null references "auth"."organization" (id) on delete cascade,
152
+ email text not null,
153
+ role text,
154
+ status text not null,
155
+ expires_at timestamptz not null,
156
+ created_at timestamptz default current_timestamp not null,
157
+ inviter_id text not null references "auth"."user" (id) on delete cascade,
158
+ app_roles jsonb
159
+ );
160
+
161
+ create index invitation_organization_id_idx on "auth"."invitation" (organization_id);
162
+
163
+ create index invitation_email_idx on "auth"."invitation" (email);
164
+
165
+ insert into "auth"."auth_migrations" (version, name) values (6, 'organizations');
166
+
167
+ -- 7 mcp: The clients, resources, tokens and consents of the OAuth provider for MCP.
168
+ create table "auth"."oauth_client" (
169
+ id text primary key,
170
+ client_id text not null unique,
171
+ client_secret text,
172
+ client_discovery_id text,
173
+ disabled boolean,
174
+ skip_consent boolean,
175
+ enable_end_session boolean,
176
+ subject_type text,
177
+ scopes jsonb,
178
+ client_credentials_scopes jsonb,
179
+ user_id text references "auth"."user" (id) on delete cascade,
180
+ created_at timestamptz,
181
+ updated_at timestamptz,
182
+ name text,
183
+ uri text,
184
+ icon text,
185
+ contacts jsonb,
186
+ tos text,
187
+ policy text,
188
+ software_id text,
189
+ software_version text,
190
+ software_statement text,
191
+ redirect_uris jsonb not null,
192
+ post_logout_redirect_uris jsonb,
193
+ backchannel_logout_uri text,
194
+ backchannel_logout_session_required boolean,
195
+ token_endpoint_auth_method text,
196
+ application_type text,
197
+ jwks text,
198
+ jwks_uri text,
199
+ grant_types jsonb,
200
+ response_types jsonb,
201
+ require_pkce boolean,
202
+ dpop_bound_access_tokens boolean,
203
+ reference_id text,
204
+ metadata jsonb
205
+ );
206
+
207
+ create index oauth_client_user_id_idx on "auth"."oauth_client" (user_id);
208
+
209
+ create table "auth"."oauth_resource" (
210
+ id text primary key,
211
+ identifier text not null unique,
212
+ name text not null,
213
+ access_token_ttl integer,
214
+ refresh_token_ttl integer,
215
+ signing_algorithm text,
216
+ signing_key_id text,
217
+ allowed_scopes jsonb,
218
+ custom_claims jsonb,
219
+ dpop_bound_access_tokens_required boolean,
220
+ disabled boolean,
221
+ created_at timestamptz,
222
+ updated_at timestamptz,
223
+ policy_version integer,
224
+ metadata jsonb
225
+ );
226
+
227
+ create table "auth"."oauth_client_resource" (
228
+ id text primary key,
229
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
230
+ resource_id text not null references "auth"."oauth_resource" (identifier) on delete cascade,
231
+ metadata jsonb,
232
+ created_at timestamptz
233
+ );
234
+
235
+ create index oauth_client_resource_client_id_idx on "auth"."oauth_client_resource" (client_id);
236
+
237
+ create index oauth_client_resource_resource_id_idx on "auth"."oauth_client_resource" (resource_id);
238
+
239
+ create unique index oauth_client_resource_client_id_resource_id_uidx on "auth"."oauth_client_resource" (client_id, resource_id);
240
+
241
+ create table "auth"."oauth_refresh_token" (
242
+ id text primary key,
243
+ token text not null unique,
244
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
245
+ session_id text references "auth"."session" (id) on delete set null,
246
+ user_id text not null references "auth"."user" (id) on delete cascade,
247
+ reference_id text,
248
+ authorization_code_id text,
249
+ resources jsonb,
250
+ requested_user_info_claims jsonb,
251
+ expires_at timestamptz not null,
252
+ created_at timestamptz not null,
253
+ revoked timestamptz,
254
+ rotated_at timestamptz,
255
+ rotation_replay_response text,
256
+ rotation_replay_expires_at timestamptz,
257
+ auth_time timestamptz,
258
+ confirmation jsonb,
259
+ scopes jsonb not null
260
+ );
261
+
262
+ create index oauth_refresh_token_client_id_idx on "auth"."oauth_refresh_token" (client_id);
263
+
264
+ create index oauth_refresh_token_session_id_idx on "auth"."oauth_refresh_token" (session_id);
265
+
266
+ create index oauth_refresh_token_user_id_idx on "auth"."oauth_refresh_token" (user_id);
267
+
268
+ create index oauth_refresh_token_authorization_code_id_idx on "auth"."oauth_refresh_token" (authorization_code_id);
269
+
270
+ create table "auth"."oauth_access_token" (
271
+ id text primary key,
272
+ token text not null unique,
273
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
274
+ session_id text references "auth"."session" (id) on delete set null,
275
+ user_id text references "auth"."user" (id) on delete cascade,
276
+ reference_id text,
277
+ authorization_code_id text,
278
+ resources jsonb,
279
+ requested_user_info_claims jsonb,
280
+ refresh_id text references "auth"."oauth_refresh_token" (id) on delete cascade,
281
+ expires_at timestamptz not null,
282
+ created_at timestamptz not null,
283
+ revoked timestamptz,
284
+ confirmation jsonb,
285
+ scopes jsonb not null
286
+ );
287
+
288
+ create index oauth_access_token_client_id_idx on "auth"."oauth_access_token" (client_id);
289
+
290
+ create index oauth_access_token_session_id_idx on "auth"."oauth_access_token" (session_id);
291
+
292
+ create index oauth_access_token_user_id_idx on "auth"."oauth_access_token" (user_id);
293
+
294
+ create index oauth_access_token_authorization_code_id_idx on "auth"."oauth_access_token" (authorization_code_id);
295
+
296
+ create index oauth_access_token_refresh_id_idx on "auth"."oauth_access_token" (refresh_id);
297
+
298
+ create table "auth"."oauth_consent" (
299
+ id text primary key,
300
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
301
+ user_id text references "auth"."user" (id) on delete cascade,
302
+ reference_id text,
303
+ resources jsonb,
304
+ requested_user_info_claims jsonb,
305
+ scopes jsonb not null,
306
+ created_at timestamptz not null,
307
+ updated_at timestamptz not null
308
+ );
309
+
310
+ create index oauth_consent_client_id_idx on "auth"."oauth_consent" (client_id);
311
+
312
+ create index oauth_consent_user_id_idx on "auth"."oauth_consent" (user_id);
313
+
314
+ create table "auth"."oauth_client_assertion" (
315
+ id text primary key,
316
+ expires_at timestamptz not null
317
+ );
318
+
319
+ insert into "auth"."auth_migrations" (version, name) values (7, 'mcp');
@@ -16,11 +16,11 @@
16
16
  "dev": "protobase dev"
17
17
  },
18
18
  "dependencies": {
19
- "@protobase/cli": "^0.47.0",
20
- "@protobase/layout": "^0.47.0",
21
- "@protobase/schema": "^0.47.0",
22
- "@protobase/server": "^0.47.0",
23
- "@protobase/ui": "^0.47.0",
19
+ "@protobase/cli": "^0.48.0",
20
+ "@protobase/layout": "^0.48.0",
21
+ "@protobase/schema": "^0.48.0",
22
+ "@protobase/server": "^0.48.0",
23
+ "@protobase/ui": "^0.48.0",
24
24
  "better-auth": "^1.7.12",
25
25
  "jose": "^6.2.12",
26
26
  "kysely": "^0.29.6",
@@ -0,0 +1,319 @@
1
+ -- The auth schema changes this version of Protobase needs, written by `protobase auth migration`.
2
+ -- Applied with the project's other migrations; edit or remove statements the project handles differently.
3
+
4
+ -- The record of the auth store's migrations.
5
+ create schema if not exists "auth";
6
+
7
+ create table "auth"."auth_migrations" (
8
+ version integer primary key,
9
+ name text not null,
10
+ applied_at timestamptz default current_timestamp not null
11
+ );
12
+
13
+ -- The auth store an earlier Protobase made, without a record of its migrations, adopted: 1 core, 2 two_factor, 3 passkeys, 4 sign_in_policy, 5 staff_sign_in
14
+ -- recorded as applied, once every table and column they make is there.
15
+ do $adopt$
16
+ declare
17
+ missing text;
18
+ begin
19
+ select string_agg(expected.table_name || '.' || expected.column_name, ', ' order by expected.table_name, expected.column_name) into missing
20
+ from (values ('account', 'id', 'text'),
21
+ ('account', 'account_id', 'text'),
22
+ ('account', 'provider_id', 'text'),
23
+ ('account', 'user_id', 'text'),
24
+ ('account', 'access_token', 'text'),
25
+ ('account', 'refresh_token', 'text'),
26
+ ('account', 'id_token', 'text'),
27
+ ('account', 'access_token_expires_at', 'timestamptz'),
28
+ ('account', 'refresh_token_expires_at', 'timestamptz'),
29
+ ('account', 'scope', 'text'),
30
+ ('account', 'password', 'text'),
31
+ ('account', 'created_at', 'timestamptz'),
32
+ ('account', 'updated_at', 'timestamptz'),
33
+ ('jwks', 'id', 'text'),
34
+ ('jwks', 'public_key', 'text'),
35
+ ('jwks', 'private_key', 'text'),
36
+ ('jwks', 'created_at', 'timestamptz'),
37
+ ('jwks', 'expires_at', 'timestamptz'),
38
+ ('jwks', 'alg', 'text'),
39
+ ('jwks', 'crv', 'text'),
40
+ ('session', 'id', 'text'),
41
+ ('session', 'expires_at', 'timestamptz'),
42
+ ('session', 'token', 'text'),
43
+ ('session', 'created_at', 'timestamptz'),
44
+ ('session', 'updated_at', 'timestamptz'),
45
+ ('session', 'ip_address', 'text'),
46
+ ('session', 'user_agent', 'text'),
47
+ ('session', 'user_id', 'text'),
48
+ ('session', 'impersonated_by', 'text'),
49
+ ('session', 'active_role', 'text'),
50
+ ('user', 'id', 'text'),
51
+ ('user', 'name', 'text'),
52
+ ('user', 'email', 'text'),
53
+ ('user', 'email_verified', 'bool'),
54
+ ('user', 'image', 'text'),
55
+ ('user', 'created_at', 'timestamptz'),
56
+ ('user', 'updated_at', 'timestamptz'),
57
+ ('user', 'role', 'text'),
58
+ ('user', 'banned', 'bool'),
59
+ ('user', 'ban_reason', 'text'),
60
+ ('user', 'ban_expires', 'timestamptz'),
61
+ ('user', 'last_role', 'text'),
62
+ ('user', 'email_confirmed_at', 'timestamptz'),
63
+ ('verification', 'id', 'text'),
64
+ ('verification', 'identifier', 'text'),
65
+ ('verification', 'value', 'text'),
66
+ ('verification', 'expires_at', 'timestamptz'),
67
+ ('verification', 'created_at', 'timestamptz'),
68
+ ('verification', 'updated_at', 'timestamptz'),
69
+ ('two_factor', 'id', 'text'),
70
+ ('two_factor', 'secret', 'text'),
71
+ ('two_factor', 'backup_codes', 'text'),
72
+ ('two_factor', 'user_id', 'text'),
73
+ ('two_factor', 'verified', 'bool'),
74
+ ('two_factor', 'failed_verification_count', 'int4'),
75
+ ('two_factor', 'locked_until', 'timestamptz'),
76
+ ('user', 'two_factor_enabled', 'bool'),
77
+ ('passkey', 'id', 'text'),
78
+ ('passkey', 'name', 'text'),
79
+ ('passkey', 'public_key', 'text'),
80
+ ('passkey', 'user_id', 'text'),
81
+ ('passkey', 'credential_id', 'text'),
82
+ ('passkey', 'counter', 'int4'),
83
+ ('passkey', 'device_type', 'text'),
84
+ ('passkey', 'backed_up', 'bool'),
85
+ ('passkey', 'transports', 'text'),
86
+ ('passkey', 'created_at', 'timestamptz'),
87
+ ('passkey', 'aaguid', 'text'),
88
+ ('passkey', 'rp_id', 'text'),
89
+ ('sign_in_policy', 'id', 'text'),
90
+ ('sign_in_policy', 'password', 'text'),
91
+ ('sign_in_policy', 'email_code', 'text'),
92
+ ('sign_in_policy', 'passkey', 'text'),
93
+ ('sign_in_policy', 'two_factor', 'text'),
94
+ ('sign_in_policy', 'staff_access', 'text'),
95
+ ('sign_in_policy', 'platform_sign_in', 'text'),
96
+ ('sign_in_policy', 'created_at', 'timestamptz'),
97
+ ('sign_in_policy', 'created_by', 'text'),
98
+ ('staff_sign_in', 'id', 'text'),
99
+ ('staff_sign_in', 'user_id', 'text'),
100
+ ('staff_sign_in', 'user_email', 'text'),
101
+ ('staff_sign_in', 'staff', 'text'),
102
+ ('staff_sign_in', 'staff_name', 'text'),
103
+ ('staff_sign_in', 'staff_subject', 'text'),
104
+ ('staff_sign_in', 'issuer', 'text'),
105
+ ('staff_sign_in', 'reason', 'text'),
106
+ ('staff_sign_in', 'session_id', 'text'),
107
+ ('staff_sign_in', 'started_at', 'timestamptz'),
108
+ ('staff_sign_in', 'expires_at', 'timestamptz'),
109
+ ('staff_sign_in', 'ended_at', 'timestamptz')) as expected (table_name, column_name, udt_name)
110
+ where not exists (
111
+ select from information_schema.columns found
112
+ where found.table_schema = 'auth' and found.table_name = expected.table_name and found.column_name = expected.column_name and found.udt_name = expected.udt_name
113
+ );
114
+ if missing is not null then
115
+ raise exception 'The auth store does not match the migrations this file adopts: it lacks %, or has them as other types', missing;
116
+ end if;
117
+ end
118
+ $adopt$;
119
+
120
+ insert into "auth"."auth_migrations" (version, name) values (1, 'core'), (2, 'two_factor'), (3, 'passkeys'), (4, 'sign_in_policy'), (5, 'staff_sign_in');
121
+
122
+ -- 6 organizations: Organizations, their members and their invitations.
123
+ alter table "auth"."user" add column if not exists "last_organization_id" text;
124
+
125
+ alter table "auth"."session" add column active_organization_id text;
126
+
127
+ create table "auth"."organization" (
128
+ id text primary key,
129
+ name text not null,
130
+ slug text not null unique,
131
+ logo text,
132
+ created_at timestamptz not null,
133
+ metadata text
134
+ );
135
+
136
+ create table "auth"."member" (
137
+ id text primary key,
138
+ organization_id text not null references "auth"."organization" (id) on delete cascade,
139
+ user_id text not null references "auth"."user" (id) on delete cascade,
140
+ role text not null,
141
+ created_at timestamptz not null,
142
+ app_roles jsonb
143
+ );
144
+
145
+ create index member_organization_id_idx on "auth"."member" (organization_id);
146
+
147
+ create index member_user_id_idx on "auth"."member" (user_id);
148
+
149
+ create table "auth"."invitation" (
150
+ id text primary key,
151
+ organization_id text not null references "auth"."organization" (id) on delete cascade,
152
+ email text not null,
153
+ role text,
154
+ status text not null,
155
+ expires_at timestamptz not null,
156
+ created_at timestamptz default current_timestamp not null,
157
+ inviter_id text not null references "auth"."user" (id) on delete cascade,
158
+ app_roles jsonb
159
+ );
160
+
161
+ create index invitation_organization_id_idx on "auth"."invitation" (organization_id);
162
+
163
+ create index invitation_email_idx on "auth"."invitation" (email);
164
+
165
+ insert into "auth"."auth_migrations" (version, name) values (6, 'organizations');
166
+
167
+ -- 7 mcp: The clients, resources, tokens and consents of the OAuth provider for MCP.
168
+ create table "auth"."oauth_client" (
169
+ id text primary key,
170
+ client_id text not null unique,
171
+ client_secret text,
172
+ client_discovery_id text,
173
+ disabled boolean,
174
+ skip_consent boolean,
175
+ enable_end_session boolean,
176
+ subject_type text,
177
+ scopes jsonb,
178
+ client_credentials_scopes jsonb,
179
+ user_id text references "auth"."user" (id) on delete cascade,
180
+ created_at timestamptz,
181
+ updated_at timestamptz,
182
+ name text,
183
+ uri text,
184
+ icon text,
185
+ contacts jsonb,
186
+ tos text,
187
+ policy text,
188
+ software_id text,
189
+ software_version text,
190
+ software_statement text,
191
+ redirect_uris jsonb not null,
192
+ post_logout_redirect_uris jsonb,
193
+ backchannel_logout_uri text,
194
+ backchannel_logout_session_required boolean,
195
+ token_endpoint_auth_method text,
196
+ application_type text,
197
+ jwks text,
198
+ jwks_uri text,
199
+ grant_types jsonb,
200
+ response_types jsonb,
201
+ require_pkce boolean,
202
+ dpop_bound_access_tokens boolean,
203
+ reference_id text,
204
+ metadata jsonb
205
+ );
206
+
207
+ create index oauth_client_user_id_idx on "auth"."oauth_client" (user_id);
208
+
209
+ create table "auth"."oauth_resource" (
210
+ id text primary key,
211
+ identifier text not null unique,
212
+ name text not null,
213
+ access_token_ttl integer,
214
+ refresh_token_ttl integer,
215
+ signing_algorithm text,
216
+ signing_key_id text,
217
+ allowed_scopes jsonb,
218
+ custom_claims jsonb,
219
+ dpop_bound_access_tokens_required boolean,
220
+ disabled boolean,
221
+ created_at timestamptz,
222
+ updated_at timestamptz,
223
+ policy_version integer,
224
+ metadata jsonb
225
+ );
226
+
227
+ create table "auth"."oauth_client_resource" (
228
+ id text primary key,
229
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
230
+ resource_id text not null references "auth"."oauth_resource" (identifier) on delete cascade,
231
+ metadata jsonb,
232
+ created_at timestamptz
233
+ );
234
+
235
+ create index oauth_client_resource_client_id_idx on "auth"."oauth_client_resource" (client_id);
236
+
237
+ create index oauth_client_resource_resource_id_idx on "auth"."oauth_client_resource" (resource_id);
238
+
239
+ create unique index oauth_client_resource_client_id_resource_id_uidx on "auth"."oauth_client_resource" (client_id, resource_id);
240
+
241
+ create table "auth"."oauth_refresh_token" (
242
+ id text primary key,
243
+ token text not null unique,
244
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
245
+ session_id text references "auth"."session" (id) on delete set null,
246
+ user_id text not null references "auth"."user" (id) on delete cascade,
247
+ reference_id text,
248
+ authorization_code_id text,
249
+ resources jsonb,
250
+ requested_user_info_claims jsonb,
251
+ expires_at timestamptz not null,
252
+ created_at timestamptz not null,
253
+ revoked timestamptz,
254
+ rotated_at timestamptz,
255
+ rotation_replay_response text,
256
+ rotation_replay_expires_at timestamptz,
257
+ auth_time timestamptz,
258
+ confirmation jsonb,
259
+ scopes jsonb not null
260
+ );
261
+
262
+ create index oauth_refresh_token_client_id_idx on "auth"."oauth_refresh_token" (client_id);
263
+
264
+ create index oauth_refresh_token_session_id_idx on "auth"."oauth_refresh_token" (session_id);
265
+
266
+ create index oauth_refresh_token_user_id_idx on "auth"."oauth_refresh_token" (user_id);
267
+
268
+ create index oauth_refresh_token_authorization_code_id_idx on "auth"."oauth_refresh_token" (authorization_code_id);
269
+
270
+ create table "auth"."oauth_access_token" (
271
+ id text primary key,
272
+ token text not null unique,
273
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
274
+ session_id text references "auth"."session" (id) on delete set null,
275
+ user_id text references "auth"."user" (id) on delete cascade,
276
+ reference_id text,
277
+ authorization_code_id text,
278
+ resources jsonb,
279
+ requested_user_info_claims jsonb,
280
+ refresh_id text references "auth"."oauth_refresh_token" (id) on delete cascade,
281
+ expires_at timestamptz not null,
282
+ created_at timestamptz not null,
283
+ revoked timestamptz,
284
+ confirmation jsonb,
285
+ scopes jsonb not null
286
+ );
287
+
288
+ create index oauth_access_token_client_id_idx on "auth"."oauth_access_token" (client_id);
289
+
290
+ create index oauth_access_token_session_id_idx on "auth"."oauth_access_token" (session_id);
291
+
292
+ create index oauth_access_token_user_id_idx on "auth"."oauth_access_token" (user_id);
293
+
294
+ create index oauth_access_token_authorization_code_id_idx on "auth"."oauth_access_token" (authorization_code_id);
295
+
296
+ create index oauth_access_token_refresh_id_idx on "auth"."oauth_access_token" (refresh_id);
297
+
298
+ create table "auth"."oauth_consent" (
299
+ id text primary key,
300
+ client_id text not null references "auth"."oauth_client" (client_id) on delete cascade,
301
+ user_id text references "auth"."user" (id) on delete cascade,
302
+ reference_id text,
303
+ resources jsonb,
304
+ requested_user_info_claims jsonb,
305
+ scopes jsonb not null,
306
+ created_at timestamptz not null,
307
+ updated_at timestamptz not null
308
+ );
309
+
310
+ create index oauth_consent_client_id_idx on "auth"."oauth_consent" (client_id);
311
+
312
+ create index oauth_consent_user_id_idx on "auth"."oauth_consent" (user_id);
313
+
314
+ create table "auth"."oauth_client_assertion" (
315
+ id text primary key,
316
+ expires_at timestamptz not null
317
+ );
318
+
319
+ insert into "auth"."auth_migrations" (version, name) values (7, 'mcp');
@@ -13,11 +13,11 @@
13
13
  "dev": "protobase dev"
14
14
  },
15
15
  "dependencies": {
16
- "@protobase/cli": "^0.47.0",
17
- "@protobase/layout": "^0.47.0",
18
- "@protobase/schema": "^0.47.0",
19
- "@protobase/server": "^0.47.0",
20
- "@protobase/ui": "^0.47.0",
16
+ "@protobase/cli": "^0.48.0",
17
+ "@protobase/layout": "^0.48.0",
18
+ "@protobase/schema": "^0.48.0",
19
+ "@protobase/server": "^0.48.0",
20
+ "@protobase/ui": "^0.48.0",
21
21
  "better-auth": "^1.7.12",
22
22
  "jose": "^6.2.12",
23
23
  "kysely": "^0.29.6",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-protobase",
3
- "version": "0.47.0",
3
+ "version": "0.48.0",
4
4
  "description": "npm create protobase: starts a new Protobase project from one of its presets.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {