@pgpm/jwt-claims 0.13.0 → 0.15.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/LICENSE +1 -1
- package/Makefile +2 -2
- package/README.md +13 -13
- package/package.json +9 -9
- package/pgpm-jwt-claims.control +8 -0
- package/pgpm.plan +2 -2
- package/sql/{launchql-jwt-claims--0.9.0.sql → pgpm-jwt-claims--0.14.0.sql} +39 -38
- package/launchql-jwt-claims.control +0 -8
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
3
|
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
|
-
Copyright (c) 2025
|
|
4
|
+
Copyright (c) 2025 Constructive
|
|
5
5
|
|
|
6
6
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
of this software and associated documentation files (the "Software"), to deal
|
package/Makefile
CHANGED
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# @pgpm/jwt-claims
|
|
2
2
|
|
|
3
3
|
<p align="center" width="100%">
|
|
4
|
-
<img height="250" src="https://raw.githubusercontent.com/
|
|
4
|
+
<img height="250" src="https://raw.githubusercontent.com/constructive-io/constructive/refs/heads/main/assets/outline-logo.svg" />
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
7
|
<p align="center" width="100%">
|
|
8
|
-
<a href="https://github.com/
|
|
9
|
-
<img height="20" src="https://github.com/
|
|
8
|
+
<a href="https://github.com/constructive-io/pgpm-modules/actions/workflows/ci.yml">
|
|
9
|
+
<img height="20" src="https://github.com/constructive-io/pgpm-modules/actions/workflows/ci.yml/badge.svg" />
|
|
10
10
|
</a>
|
|
11
|
-
<a href="https://github.com/
|
|
12
|
-
<a href="https://www.npmjs.com/package/@pgpm/jwt-claims"><img height="20" src="https://img.shields.io/github/package-json/v/
|
|
11
|
+
<a href="https://github.com/constructive-io/pgpm-modules/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@pgpm/jwt-claims"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/pgpm-modules?filename=packages%2Fsecurity%2Fjwt-claims%2Fpackage.json"/></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
15
|
JWT claim handling and validation functions.
|
|
@@ -65,7 +65,7 @@ pgpm deploy
|
|
|
65
65
|
|
|
66
66
|
```bash
|
|
67
67
|
# 1. Create a workspace
|
|
68
|
-
pgpm init
|
|
68
|
+
pgpm init workspace
|
|
69
69
|
|
|
70
70
|
# 2. Create your first module
|
|
71
71
|
cd my-workspace
|
|
@@ -338,13 +338,13 @@ pnpm test
|
|
|
338
338
|
|
|
339
339
|
## Related Tooling
|
|
340
340
|
|
|
341
|
-
* [pgpm](https://github.com/
|
|
342
|
-
* [pgsql-test](https://github.com/
|
|
343
|
-
* [supabase-test](https://github.com/
|
|
344
|
-
* [graphile-test](https://github.com/
|
|
345
|
-
* [pgsql-parser](https://github.com/
|
|
346
|
-
* [libpg-query-node](https://github.com/
|
|
347
|
-
* [pg-proto-parser](https://github.com/
|
|
341
|
+
* [pgpm](https://github.com/constructive-io/constructive/tree/main/packages/pgpm): **🖥️ PostgreSQL Package Manager** for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
|
|
342
|
+
* [pgsql-test](https://github.com/constructive-io/constructive/tree/main/packages/pgsql-test): **📊 Isolated testing environments** with per-test transaction rollbacks—ideal for integration tests, complex migrations, and RLS simulation.
|
|
343
|
+
* [supabase-test](https://github.com/constructive-io/constructive/tree/main/packages/supabase-test): **🧪 Supabase-native test harness** preconfigured for the local Supabase stack—per-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
|
|
344
|
+
* [graphile-test](https://github.com/constructive-io/constructive/tree/main/packages/graphile-test): **🔐 Authentication mocking** for Graphile-focused test helpers and emulating row-level security contexts.
|
|
345
|
+
* [pgsql-parser](https://github.com/constructive-io/pgsql-parser): **🔄 SQL conversion engine** that interprets and converts PostgreSQL syntax.
|
|
346
|
+
* [libpg-query-node](https://github.com/constructive-io/libpg-query-node): **🌉 Node.js bindings** for `libpg_query`, converting SQL into parse trees.
|
|
347
|
+
* [pg-proto-parser](https://github.com/constructive-io/pg-proto-parser): **📦 Protobuf parser** for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
|
|
348
348
|
|
|
349
349
|
## Disclaimer
|
|
350
350
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgpm/jwt-claims",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "JWT claim handling and validation functions",
|
|
5
5
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
7
|
-
"
|
|
7
|
+
"Constructive <developers@constructive.io>"
|
|
8
8
|
],
|
|
9
9
|
"keywords": [
|
|
10
10
|
"postgresql",
|
|
@@ -21,19 +21,19 @@
|
|
|
21
21
|
"test:watch": "jest --watch"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"pgpm": "^0.
|
|
24
|
+
"pgpm": "^1.0.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@pgpm/types": "0.
|
|
28
|
-
"@pgpm/verify": "0.
|
|
27
|
+
"@pgpm/types": "0.15.0",
|
|
28
|
+
"@pgpm/verify": "0.15.0"
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
32
|
-
"url": "https://github.com/
|
|
32
|
+
"url": "https://github.com/constructive-io/pgpm-modules"
|
|
33
33
|
},
|
|
34
|
-
"homepage": "https://github.com/
|
|
34
|
+
"homepage": "https://github.com/constructive-io/pgpm-modules",
|
|
35
35
|
"bugs": {
|
|
36
|
-
"url": "https://github.com/
|
|
36
|
+
"url": "https://github.com/constructive-io/pgpm-modules/issues"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "118ac6f810720378fa954e9620abf2516293c148"
|
|
39
39
|
}
|
package/pgpm.plan
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
%syntax-version=1.0.0
|
|
2
|
-
%project=
|
|
3
|
-
%uri=
|
|
2
|
+
%project=pgpm-jwt-claims
|
|
3
|
+
%uri=pgpm-jwt-claims
|
|
4
4
|
|
|
5
5
|
schemas/ctx/schema 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/schema
|
|
6
6
|
schemas/ctx/procedures/ip_address [schemas/ctx/schema] 2017-08-11T08:11:51Z skitch <skitch@5b0c196eeb62> # add schemas/ctx/procedures/ip_address
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
\echo Use "CREATE EXTENSION
|
|
1
|
+
\echo Use "CREATE EXTENSION pgpm-jwt-claims" to load this file. \quit
|
|
2
2
|
CREATE SCHEMA ctx;
|
|
3
3
|
|
|
4
4
|
GRANT USAGE ON SCHEMA ctx TO authenticated, anonymous;
|
|
@@ -6,20 +6,6 @@ GRANT USAGE ON SCHEMA ctx TO authenticated, anonymous;
|
|
|
6
6
|
ALTER DEFAULT PRIVILEGES IN SCHEMA ctx
|
|
7
7
|
GRANT EXECUTE ON FUNCTIONS TO authenticated;
|
|
8
8
|
|
|
9
|
-
CREATE SCHEMA jwt_public;
|
|
10
|
-
|
|
11
|
-
GRANT USAGE ON SCHEMA jwt_public TO authenticated, anonymous;
|
|
12
|
-
|
|
13
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA jwt_public
|
|
14
|
-
GRANT EXECUTE ON FUNCTIONS TO authenticated;
|
|
15
|
-
|
|
16
|
-
CREATE SCHEMA jwt_private;
|
|
17
|
-
|
|
18
|
-
GRANT USAGE ON SCHEMA jwt_private TO authenticated, anonymous;
|
|
19
|
-
|
|
20
|
-
ALTER DEFAULT PRIVILEGES IN SCHEMA jwt_private
|
|
21
|
-
GRANT EXECUTE ON FUNCTIONS TO authenticated;
|
|
22
|
-
|
|
23
9
|
CREATE FUNCTION ctx.ip_address() RETURNS inet AS $EOFCODE$
|
|
24
10
|
SELECT nullif(current_setting('jwt.claims.ip_address', true), '')::inet;
|
|
25
11
|
$EOFCODE$ LANGUAGE sql STABLE;
|
|
@@ -36,7 +22,7 @@ CREATE FUNCTION ctx.user_id() RETURNS uuid AS $EOFCODE$
|
|
|
36
22
|
SELECT nullif(current_setting('jwt.claims.user_id', true), '')::uuid;
|
|
37
23
|
$EOFCODE$ LANGUAGE sql STABLE;
|
|
38
24
|
|
|
39
|
-
DO $
|
|
25
|
+
DO $EOFCODE$
|
|
40
26
|
DECLARE
|
|
41
27
|
BEGIN
|
|
42
28
|
EXECUTE format('CREATE FUNCTION ctx.security_definer() returns text as $FUNC$
|
|
@@ -48,11 +34,19 @@ LANGUAGE ''sql'';', current_user);
|
|
|
48
34
|
$FUNC$
|
|
49
35
|
LANGUAGE ''sql'';', current_user);
|
|
50
36
|
END;
|
|
51
|
-
$
|
|
37
|
+
$EOFCODE$;
|
|
52
38
|
|
|
53
39
|
GRANT EXECUTE ON FUNCTION ctx.security_definer() TO PUBLIC;
|
|
40
|
+
|
|
54
41
|
GRANT EXECUTE ON FUNCTION ctx.is_security_definer() TO PUBLIC;
|
|
55
42
|
|
|
43
|
+
CREATE SCHEMA jwt_public;
|
|
44
|
+
|
|
45
|
+
GRANT USAGE ON SCHEMA jwt_public TO authenticated, anonymous;
|
|
46
|
+
|
|
47
|
+
ALTER DEFAULT PRIVILEGES IN SCHEMA jwt_public
|
|
48
|
+
GRANT EXECUTE ON FUNCTIONS TO authenticated;
|
|
49
|
+
|
|
56
50
|
CREATE FUNCTION jwt_public.current_user_id() RETURNS uuid AS $EOFCODE$
|
|
57
51
|
DECLARE
|
|
58
52
|
v_identifier_id uuid;
|
|
@@ -93,10 +87,6 @@ BEGIN
|
|
|
93
87
|
END;
|
|
94
88
|
$EOFCODE$ LANGUAGE plpgsql STABLE;
|
|
95
89
|
|
|
96
|
-
CREATE FUNCTION jwt_public.current_origin() RETURNS origin AS $EOFCODE$
|
|
97
|
-
SELECT nullif(current_setting('jwt.claims.origin', TRUE), '')::origin;
|
|
98
|
-
$EOFCODE$ LANGUAGE sql STABLE;
|
|
99
|
-
|
|
100
90
|
CREATE FUNCTION jwt_public.current_user_agent() RETURNS text AS $EOFCODE$
|
|
101
91
|
DECLARE
|
|
102
92
|
v_uagent text;
|
|
@@ -117,46 +107,57 @@ BEGIN
|
|
|
117
107
|
END;
|
|
118
108
|
$EOFCODE$ LANGUAGE plpgsql STABLE;
|
|
119
109
|
|
|
120
|
-
CREATE FUNCTION
|
|
110
|
+
CREATE FUNCTION jwt_public.current_origin() RETURNS origin AS $EOFCODE$
|
|
111
|
+
SELECT nullif(current_setting('jwt.claims.origin', true), '')::origin;
|
|
112
|
+
$EOFCODE$ LANGUAGE sql STABLE;
|
|
113
|
+
|
|
114
|
+
CREATE FUNCTION jwt_public.current_group_ids() RETURNS uuid[] AS $EOFCODE$
|
|
121
115
|
DECLARE
|
|
122
|
-
|
|
116
|
+
v_identifier_ids uuid[];
|
|
123
117
|
BEGIN
|
|
124
|
-
IF current_setting('jwt.claims.
|
|
118
|
+
IF current_setting('jwt.claims.group_ids', TRUE)
|
|
125
119
|
IS NOT NULL THEN
|
|
126
120
|
BEGIN
|
|
127
|
-
|
|
121
|
+
v_identifier_ids = current_setting('jwt.claims.group_ids', TRUE)::uuid[];
|
|
128
122
|
EXCEPTION
|
|
129
123
|
WHEN OTHERS THEN
|
|
130
124
|
RAISE NOTICE 'Invalid UUID value';
|
|
131
|
-
RETURN
|
|
125
|
+
RETURN ARRAY[]::uuid[];
|
|
132
126
|
END;
|
|
133
|
-
RETURN
|
|
127
|
+
RETURN v_identifier_ids;
|
|
134
128
|
ELSE
|
|
135
|
-
RETURN
|
|
129
|
+
RETURN ARRAY[]::uuid[];
|
|
136
130
|
END IF;
|
|
137
131
|
END;
|
|
138
132
|
$EOFCODE$ LANGUAGE plpgsql STABLE;
|
|
139
133
|
|
|
140
|
-
CREATE
|
|
141
|
-
SELECT nullif(current_setting('jwt.claims.token_id', TRUE), '')::uuid;
|
|
142
|
-
$EOFCODE$ LANGUAGE sql STABLE;
|
|
134
|
+
CREATE SCHEMA jwt_private;
|
|
143
135
|
|
|
144
|
-
|
|
136
|
+
GRANT USAGE ON SCHEMA jwt_private TO authenticated, anonymous;
|
|
137
|
+
|
|
138
|
+
ALTER DEFAULT PRIVILEGES IN SCHEMA jwt_private
|
|
139
|
+
GRANT EXECUTE ON FUNCTIONS TO authenticated;
|
|
140
|
+
|
|
141
|
+
CREATE FUNCTION jwt_private.current_database_id() RETURNS uuid AS $EOFCODE$
|
|
145
142
|
DECLARE
|
|
146
|
-
|
|
143
|
+
v_identifier_id uuid;
|
|
147
144
|
BEGIN
|
|
148
|
-
IF current_setting('jwt.claims.
|
|
145
|
+
IF current_setting('jwt.claims.database_id', TRUE)
|
|
149
146
|
IS NOT NULL THEN
|
|
150
147
|
BEGIN
|
|
151
|
-
|
|
148
|
+
v_identifier_id = current_setting('jwt.claims.database_id', TRUE)::uuid;
|
|
152
149
|
EXCEPTION
|
|
153
150
|
WHEN OTHERS THEN
|
|
154
151
|
RAISE NOTICE 'Invalid UUID value';
|
|
155
|
-
RETURN
|
|
152
|
+
RETURN NULL;
|
|
156
153
|
END;
|
|
157
|
-
RETURN
|
|
154
|
+
RETURN v_identifier_id;
|
|
158
155
|
ELSE
|
|
159
|
-
RETURN
|
|
156
|
+
RETURN NULL;
|
|
160
157
|
END IF;
|
|
161
158
|
END;
|
|
162
159
|
$EOFCODE$ LANGUAGE plpgsql STABLE;
|
|
160
|
+
|
|
161
|
+
CREATE FUNCTION jwt_private.current_token_id() RETURNS uuid AS $EOFCODE$
|
|
162
|
+
SELECT nullif(current_setting('jwt.claims.token_id', true), '')::uuid;
|
|
163
|
+
$EOFCODE$ LANGUAGE sql STABLE;
|