@flink-app/flink 2.0.0-alpha.97 → 2.0.0-alpha.98

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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @flink-app/flink
2
2
 
3
+ ## 2.0.0-alpha.98
4
+
5
+ ### Minor Changes
6
+
7
+ - 2f4a132: feat: expose verified token on the request
8
+
9
+ The JWT auth plugin now populates `req.token` (the decoded, signature-verified
10
+ payload) and `req.rawToken` (the original token string) after successful
11
+ authentication. Handlers can read token claims such as `jti` directly instead of
12
+ re-extracting and re-decoding the bearer token with an unverified decode.
13
+
14
+ ```ts
15
+ // Before
16
+ const authHeader = req.headers.authorization;
17
+ const bearer = authHeader?.startsWith("Bearer ") ? authHeader.slice(7) : undefined;
18
+ const decoded = bearer ? (jsonwebtoken.decode(bearer) as { jti?: string }) : null;
19
+ const sessionId = decoded?.jti ?? legacySessionId(req.user._id);
20
+
21
+ // After
22
+ const { jti } = (req.token as { jti?: string }) ?? {};
23
+ const sessionId = jti ?? legacySessionId(req.user._id);
24
+ ```
25
+
26
+ `token` / `rawToken` are added as optional fields on the core `FlinkRequest`
27
+ type, populated by auth plugins that have a token concept.
28
+
3
29
  ## 2.0.0-alpha.97
4
30
 
5
31
  ### Minor Changes
@@ -93,11 +93,18 @@ export interface StreamWriter<T = any> {
93
93
  * userPermissions is populated by auth plugins during authentication and contains
94
94
  * the resolved permissions array based on the plugin's configuration (roles, dynamic
95
95
  * roles, custom permissions, etc.)
96
+ *
97
+ * token / rawToken are populated by auth plugins that have a token concept (e.g. JWT).
98
+ * `token` is the decoded, signature-verified payload; `rawToken` is the original token
99
+ * string that authenticated the request (Bearer header or custom tokenExtractor output).
100
+ * Both are optional and only set once authentication succeeds.
96
101
  */
97
102
  export type FlinkRequest<T = any, P = Params, Q = Query> = Request<P, any, T, Q> & {
98
103
  reqId: string;
99
104
  user?: any;
100
105
  userPermissions?: string[];
106
+ token?: any;
107
+ rawToken?: string;
101
108
  };
102
109
  /**
103
110
  * Route props to control routing.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/flink",
3
- "version": "2.0.0-alpha.97",
3
+ "version": "2.0.0-alpha.98",
4
4
  "description": "Typescript only framework for creating REST-like APIs on top of Express and mongodb",
5
5
  "types": "dist/src/index.d.ts",
6
6
  "main": "dist/src/index.js",
@@ -104,11 +104,18 @@ export interface StreamWriter<T = any> {
104
104
  * userPermissions is populated by auth plugins during authentication and contains
105
105
  * the resolved permissions array based on the plugin's configuration (roles, dynamic
106
106
  * roles, custom permissions, etc.)
107
+ *
108
+ * token / rawToken are populated by auth plugins that have a token concept (e.g. JWT).
109
+ * `token` is the decoded, signature-verified payload; `rawToken` is the original token
110
+ * string that authenticated the request (Bearer header or custom tokenExtractor output).
111
+ * Both are optional and only set once authentication succeeds.
107
112
  */
108
113
  export type FlinkRequest<T = any, P = Params, Q = Query> = Request<P, any, T, Q> & {
109
114
  reqId: string;
110
115
  user?: any;
111
116
  userPermissions?: string[]; // Resolved permissions from auth plugin
117
+ token?: any; // Decoded, verified token payload (set by auth plugin)
118
+ rawToken?: string; // Raw token string that authenticated the request
112
119
  };
113
120
 
114
121
  /**