@everystack/auth 0.4.2 → 0.4.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.
- package/package.json +20 -3
- package/src/models/functions.ts +15 -0
- package/src/models/user.ts +13 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@everystack/auth",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "JWT authentication handlers, password hashing, and React auth context",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"author": "Scalable Technology, Inc. <licensing@scalable.technology>",
|
|
@@ -22,42 +22,52 @@
|
|
|
22
22
|
],
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
|
+
"source": "./src/index.ts",
|
|
25
26
|
"types": "./src/index.ts",
|
|
26
27
|
"default": "./src/index.ts"
|
|
27
28
|
},
|
|
28
29
|
"./client": {
|
|
30
|
+
"source": "./src/client/index.tsx",
|
|
29
31
|
"types": "./src/client/index.tsx",
|
|
30
32
|
"default": "./src/client/index.tsx"
|
|
31
33
|
},
|
|
32
34
|
"./api": {
|
|
35
|
+
"source": "./src/api.ts",
|
|
33
36
|
"types": "./src/api.ts",
|
|
34
37
|
"default": "./src/api.ts"
|
|
35
38
|
},
|
|
36
39
|
"./schema": {
|
|
40
|
+
"source": "./src/schema.ts",
|
|
37
41
|
"types": "./src/schema.ts",
|
|
38
42
|
"default": "./src/schema.ts"
|
|
39
43
|
},
|
|
40
44
|
"./models": {
|
|
45
|
+
"source": "./src/models/index.ts",
|
|
41
46
|
"types": "./src/models/index.ts",
|
|
42
47
|
"default": "./src/models/index.ts"
|
|
43
48
|
},
|
|
44
49
|
"./sql": {
|
|
50
|
+
"source": "./src/sql.ts",
|
|
45
51
|
"types": "./src/sql.ts",
|
|
46
52
|
"default": "./src/sql.ts"
|
|
47
53
|
},
|
|
48
54
|
"./postgres": {
|
|
55
|
+
"source": "./src/postgres.ts",
|
|
49
56
|
"types": "./src/postgres.ts",
|
|
50
57
|
"default": "./src/postgres.ts"
|
|
51
58
|
},
|
|
52
59
|
"./jwt": {
|
|
60
|
+
"source": "./src/jwt/index.ts",
|
|
53
61
|
"types": "./src/jwt/index.ts",
|
|
54
62
|
"default": "./src/jwt/index.ts"
|
|
55
63
|
},
|
|
56
64
|
"./jwt/node": {
|
|
65
|
+
"source": "./src/jwt/hmac-node.ts",
|
|
57
66
|
"types": "./src/jwt/hmac-node.ts",
|
|
58
67
|
"default": "./src/jwt/hmac-node.ts"
|
|
59
68
|
},
|
|
60
69
|
"./jwt/web": {
|
|
70
|
+
"source": "./src/jwt/hmac-web.ts",
|
|
61
71
|
"types": "./src/jwt/hmac-web.ts",
|
|
62
72
|
"default": "./src/jwt/hmac-web.ts"
|
|
63
73
|
},
|
|
@@ -65,33 +75,39 @@
|
|
|
65
75
|
"default": "./src/jwt/jwt.sql"
|
|
66
76
|
},
|
|
67
77
|
"./oauth": {
|
|
78
|
+
"source": "./src/oauth/index.ts",
|
|
68
79
|
"types": "./src/oauth/index.ts",
|
|
69
80
|
"default": "./src/oauth/index.ts"
|
|
70
81
|
},
|
|
71
82
|
"./cookies": {
|
|
83
|
+
"source": "./src/cookies.ts",
|
|
72
84
|
"types": "./src/cookies.ts",
|
|
73
85
|
"default": "./src/cookies.ts"
|
|
74
86
|
},
|
|
75
87
|
"./context": {
|
|
88
|
+
"source": "./src/context.ts",
|
|
76
89
|
"types": "./src/context.ts",
|
|
77
90
|
"default": "./src/context.ts"
|
|
78
91
|
},
|
|
79
92
|
"./cff": {
|
|
93
|
+
"source": "./src/cff/index.ts",
|
|
80
94
|
"types": "./src/cff/index.ts",
|
|
81
95
|
"default": "./src/cff/index.ts"
|
|
82
96
|
},
|
|
83
97
|
"./plugin": {
|
|
98
|
+
"source": "./src/plugin.ts",
|
|
84
99
|
"types": "./src/plugin.ts",
|
|
85
100
|
"default": "./src/plugin.ts"
|
|
86
101
|
},
|
|
87
102
|
"./testing": {
|
|
103
|
+
"source": "./src/testing.ts",
|
|
88
104
|
"types": "./src/testing.ts",
|
|
89
105
|
"default": "./src/testing.ts"
|
|
90
106
|
}
|
|
91
107
|
},
|
|
92
108
|
"dependencies": {
|
|
93
109
|
"bcryptjs": "3.0.3",
|
|
94
|
-
"@everystack/model": "0.4.
|
|
110
|
+
"@everystack/model": "0.4.17"
|
|
95
111
|
},
|
|
96
112
|
"peerDependencies": {
|
|
97
113
|
"@everystack/api": ">=0.1.0",
|
|
@@ -120,7 +136,8 @@
|
|
|
120
136
|
"postgres": "3.4.9",
|
|
121
137
|
"ts-jest": "29.4.9",
|
|
122
138
|
"typescript": "5.9.3",
|
|
123
|
-
"@everystack/api": "0.4.0"
|
|
139
|
+
"@everystack/api": "0.4.0",
|
|
140
|
+
"@everystack/server": "0.4.26"
|
|
124
141
|
},
|
|
125
142
|
"scripts": {
|
|
126
143
|
"test": "jest",
|
package/src/models/functions.ts
CHANGED
|
@@ -89,6 +89,7 @@ export const cleanupRefreshTokensFn = defineFunction('auth.cleanup_refresh_token
|
|
|
89
89
|
language: 'plpgsql',
|
|
90
90
|
security: 'definer',
|
|
91
91
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
92
|
+
internal: true,
|
|
92
93
|
body: sql`
|
|
93
94
|
DECLARE
|
|
94
95
|
v_count INTEGER;
|
|
@@ -134,6 +135,7 @@ export const createOneTimeTokenFn = defineFunction('auth.create_one_time_token',
|
|
|
134
135
|
language: 'plpgsql',
|
|
135
136
|
security: 'definer',
|
|
136
137
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
138
|
+
internal: true,
|
|
137
139
|
body: sql`
|
|
138
140
|
DECLARE
|
|
139
141
|
v_raw_token TEXT;
|
|
@@ -165,6 +167,7 @@ export const hashPasswordFn = defineFunction('auth.hash_password', {
|
|
|
165
167
|
language: 'plpgsql',
|
|
166
168
|
security: 'definer',
|
|
167
169
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
170
|
+
internal: true,
|
|
168
171
|
body: sql`
|
|
169
172
|
BEGIN
|
|
170
173
|
RETURN crypt(p_password, gen_salt('bf', 10));
|
|
@@ -178,6 +181,7 @@ export const issueRefreshTokenFn = defineFunction('auth.issue_refresh_token', {
|
|
|
178
181
|
language: 'plpgsql',
|
|
179
182
|
security: 'definer',
|
|
180
183
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
184
|
+
internal: true,
|
|
181
185
|
body: sql`
|
|
182
186
|
DECLARE
|
|
183
187
|
v_raw_token TEXT;
|
|
@@ -265,6 +269,7 @@ export const oauthSignInFn = defineFunction('auth.oauth_sign_in', {
|
|
|
265
269
|
language: 'plpgsql',
|
|
266
270
|
security: 'definer',
|
|
267
271
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
272
|
+
internal: true,
|
|
268
273
|
body: sql`
|
|
269
274
|
DECLARE
|
|
270
275
|
v_identity RECORD;
|
|
@@ -358,6 +363,7 @@ export const oauthSignInJwtFn = defineFunction('auth.oauth_sign_in_jwt', {
|
|
|
358
363
|
language: 'plpgsql',
|
|
359
364
|
security: 'definer',
|
|
360
365
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
366
|
+
internal: true,
|
|
361
367
|
body: sql`
|
|
362
368
|
DECLARE
|
|
363
369
|
v_payload JSONB;
|
|
@@ -418,6 +424,7 @@ export const revokeRefreshTokensFn = defineFunction('auth.revoke_refresh_tokens'
|
|
|
418
424
|
language: 'plpgsql',
|
|
419
425
|
security: 'definer',
|
|
420
426
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
427
|
+
internal: true,
|
|
421
428
|
body: sql`
|
|
422
429
|
DECLARE
|
|
423
430
|
v_count INTEGER;
|
|
@@ -458,6 +465,7 @@ export const signInFn = defineFunction('auth.sign_in', {
|
|
|
458
465
|
language: 'plpgsql',
|
|
459
466
|
security: 'definer',
|
|
460
467
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
468
|
+
internal: true,
|
|
461
469
|
body: sql`
|
|
462
470
|
DECLARE
|
|
463
471
|
v_user RECORD;
|
|
@@ -502,6 +510,7 @@ export const signInJwtFn = defineFunction('auth.sign_in_jwt', {
|
|
|
502
510
|
language: 'plpgsql',
|
|
503
511
|
security: 'definer',
|
|
504
512
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
513
|
+
internal: true,
|
|
505
514
|
body: sql`
|
|
506
515
|
DECLARE
|
|
507
516
|
v_payload JSONB;
|
|
@@ -556,6 +565,7 @@ export const signJwtFn = defineFunction('auth.sign_jwt', {
|
|
|
556
565
|
language: 'plpgsql',
|
|
557
566
|
security: 'definer',
|
|
558
567
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
568
|
+
internal: true,
|
|
559
569
|
body: sql`
|
|
560
570
|
DECLARE
|
|
561
571
|
v_header TEXT;
|
|
@@ -601,6 +611,7 @@ export const signUpFn = defineFunction('auth.sign_up', {
|
|
|
601
611
|
language: 'plpgsql',
|
|
602
612
|
security: 'definer',
|
|
603
613
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
614
|
+
internal: true,
|
|
604
615
|
body: sql`
|
|
605
616
|
DECLARE
|
|
606
617
|
v_user RECORD;
|
|
@@ -645,6 +656,7 @@ export const signUpJwtFn = defineFunction('auth.sign_up_jwt', {
|
|
|
645
656
|
language: 'plpgsql',
|
|
646
657
|
security: 'definer',
|
|
647
658
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
659
|
+
internal: true,
|
|
648
660
|
body: sql`
|
|
649
661
|
DECLARE
|
|
650
662
|
v_payload JSONB;
|
|
@@ -794,6 +806,7 @@ export const verifyJwtFn = defineFunction('auth.verify_jwt', {
|
|
|
794
806
|
language: 'plpgsql',
|
|
795
807
|
security: 'definer',
|
|
796
808
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
809
|
+
internal: true,
|
|
797
810
|
body: sql`
|
|
798
811
|
DECLARE
|
|
799
812
|
v_parts TEXT[];
|
|
@@ -853,6 +866,7 @@ export const verifyOneTimeTokenFn = defineFunction('auth.verify_one_time_token',
|
|
|
853
866
|
language: 'plpgsql',
|
|
854
867
|
security: 'definer',
|
|
855
868
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
869
|
+
internal: true,
|
|
856
870
|
body: sql`
|
|
857
871
|
DECLARE
|
|
858
872
|
v_token_hash TEXT;
|
|
@@ -888,6 +902,7 @@ export const verifyPasswordFn = defineFunction('auth.verify_password', {
|
|
|
888
902
|
language: 'plpgsql',
|
|
889
903
|
security: 'definer',
|
|
890
904
|
searchPath: ['auth', 'public', 'pg_temp'],
|
|
905
|
+
internal: true,
|
|
891
906
|
body: sql`
|
|
892
907
|
DECLARE
|
|
893
908
|
v_normalized TEXT;
|
package/src/models/user.ts
CHANGED
|
@@ -51,6 +51,19 @@ export const User = defineModel('users', {
|
|
|
51
51
|
updatedAt: field.timestamptz().defaultNow().notNull(),
|
|
52
52
|
},
|
|
53
53
|
constraints: [index('instanceId')],
|
|
54
|
+
// `deletedAt` on a user means a soft delete: the row stays, because auth rows are referenced
|
|
55
|
+
// by half the schema and destroying one breaks those references rather than cleaning them up.
|
|
56
|
+
// Every reader in this package already assumes that shape — the sign-in path and the auth
|
|
57
|
+
// SQL functions gate on `deleted_at IS NULL` rather than on the row's absence.
|
|
58
|
+
//
|
|
59
|
+
// Declared rather than defaulted because the admin `manage` ability below grants DELETE
|
|
60
|
+
// ("all actions"), which is the axis that matters here. It is INERT in both directions today,
|
|
61
|
+
// which is what makes it safe to add to a published package: no public read, so the compiled
|
|
62
|
+
// contract is unchanged (no fingerprint movement for any consumer); and `private: true` keeps
|
|
63
|
+
// this model out of the generic data API, so none of the handler's soft-delete behaviour
|
|
64
|
+
// applies either. It states the intent that the readers already depend on, and it stops the
|
|
65
|
+
// model from silently acquiring the opposite one.
|
|
66
|
+
softDelete: true,
|
|
54
67
|
abilities: [
|
|
55
68
|
can('manage', { role: 'admin' }),
|
|
56
69
|
// Self-read, column-scoped: id/email/role of your own row, never the hash.
|