create-protobase 0.47.1 → 0.49.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/env-file.js +3 -3
- package/dist/templates/erp/.env.example +3 -3
- package/dist/templates/erp/auth/hooks.ts +26 -0
- package/dist/templates/erp/db/migrations/022_auth.sql +297 -0
- package/dist/templates/erp/{config/jobs.test.ts → hooks/schedule-overdue-check.test.ts} +1 -1
- package/dist/templates/erp/hooks/schedule-overdue-check.ts +16 -0
- package/dist/templates/erp/jobs/mark-invoice-overdue.ts +7 -0
- package/dist/templates/erp/jobs/mark-overdue-invoices.ts +8 -0
- package/dist/templates/erp/package.json +6 -5
- package/dist/templates/erp/protobase.config.ts +33 -18
- package/dist/templates/real-estate/.env.example +3 -3
- package/dist/templates/real-estate/auth/hooks.ts +9 -0
- package/dist/templates/real-estate/db/migrations/015_auth.sql +319 -0
- package/dist/templates/real-estate/package.json +6 -5
- package/dist/templates/real-estate/protobase.config.ts +13 -4
- package/dist/templates/scratch/.env.example +3 -3
- package/dist/templates/scratch/db/migrations/006_auth.sql +319 -0
- package/dist/templates/scratch/package.json +6 -5
- package/dist/templates/scratch/protobase.config.ts +11 -3
- package/package.json +1 -1
- package/dist/templates/erp/auth/auth.ts +0 -65
- package/dist/templates/erp/config/jobs.ts +0 -29
- package/dist/templates/real-estate/auth/auth.ts +0 -33
- package/dist/templates/scratch/auth/auth.ts +0 -25
|
@@ -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,12 @@
|
|
|
16
16
|
"dev": "protobase dev"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@protobase/cli": "^0.
|
|
20
|
-
"@protobase/
|
|
21
|
-
"@protobase/
|
|
22
|
-
"@protobase/
|
|
23
|
-
"@protobase/
|
|
19
|
+
"@protobase/cli": "^0.49.0",
|
|
20
|
+
"@protobase/config": "^0.49.0",
|
|
21
|
+
"@protobase/layout": "^0.49.0",
|
|
22
|
+
"@protobase/schema": "^0.49.0",
|
|
23
|
+
"@protobase/server": "^0.49.0",
|
|
24
|
+
"@protobase/ui": "^0.49.0",
|
|
24
25
|
"better-auth": "^1.7.12",
|
|
25
26
|
"jose": "^6.2.12",
|
|
26
27
|
"kysely": "^0.29.6",
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { roles } from './config/roles'
|
|
3
|
-
import { auth, authenticate } from './auth/auth'
|
|
1
|
+
import { defineConfig } from '@protobase/config'
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
// The whole app, as one object. Its code is found by its path: resources in config/, roles in config/roles.ts and the
|
|
4
|
+
// auth hooks in auth/hooks.ts. Its address and secret are Protobase's defaults, PROTOBASE_URL and PROTOBASE_SECRET (see
|
|
5
|
+
// .env.example).
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
auth: {
|
|
8
|
+
// No defaultRole on purpose: every account is created with an explicit role (`protobase users create --role`).
|
|
9
|
+
// New users take their ids from the app's own users sequence (auth/hooks.ts).
|
|
10
|
+
roles: ['admin', 'manager', 'finance', 'maintenance'],
|
|
11
|
+
},
|
|
12
|
+
// Organizations are not used yet: everyone works in organization 1.
|
|
13
|
+
authenticate: { tenant: 1 },
|
|
14
|
+
})
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
DATABASE_URL=postgres://protobase:protobase@localhost:55432/scratch
|
|
3
3
|
|
|
4
4
|
# Admin store (Better Auth users, sessions, signing keys): the `auth` schema of DATABASE_URL, created by `db:migrate`.
|
|
5
|
-
|
|
5
|
+
PROTOBASE_URL=http://localhost:5173
|
|
6
6
|
# Signs cookies and encrypts the token keys. Generate your own: openssl rand -base64 32
|
|
7
|
-
|
|
8
|
-
#
|
|
7
|
+
PROTOBASE_SECRET=change-me-generate-with-openssl-rand-base64-32
|
|
8
|
+
# PROTOBASE_TRUSTED_ORIGINS=
|