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

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,26 @@
1
1
  # @flink-app/flink
2
2
 
3
+ ## 2.0.0-alpha.97
4
+
5
+ ### Minor Changes
6
+
7
+ - eed6bc1: Pass host application context to auth plugins.
8
+
9
+ `FlinkAuthPlugin.authenticateRequest` now receives the host app's context as an optional third argument. Flink core supplies it on every authenticated request, so auth plugins can access repos/services without the caller wiring up a lazy accessor or maintaining a module-level mutable reference.
10
+
11
+ For `@flink-app/jwt-auth-plugin`, this means `getUser` receives the context directly:
12
+
13
+ ```typescript
14
+ jwtAuthPlugin({
15
+ getUser: async (tokenData, req, ctx) => {
16
+ const user = await ctx?.repos.userRepo.getById(tokenData._id);
17
+ return user ? { username: user.username, _id: user._id } : null;
18
+ },
19
+ });
20
+ ```
21
+
22
+ The `getContext` option previously added in alpha.96 is no longer needed and has been removed — remove it from your `jwtAuthPlugin({ … })` call. The third `ctx` parameter on `getUser` is optional, so callbacks that ignore it are unaffected.
23
+
3
24
  ## 2.0.0-alpha.96
4
25
 
5
26
  ### Patch Changes
@@ -1300,7 +1300,7 @@ var FlinkApp = /** @class */ (function () {
1300
1300
  if (!this.auth) {
1301
1301
  throw new Error("Attempting to authenticate request (".concat(req.method, " ").concat(req.path, ") but no authPlugin is set"));
1302
1302
  }
1303
- return [4 /*yield*/, this.auth.authenticateRequest(req, permissions)];
1303
+ return [4 /*yield*/, this.auth.authenticateRequest(req, permissions, this._ctx)];
1304
1304
  case 1: return [2 /*return*/, _a.sent()];
1305
1305
  }
1306
1306
  });
@@ -1,5 +1,5 @@
1
1
  import { FlinkRequest } from "../FlinkHttpHandler";
2
2
  export interface FlinkAuthPlugin {
3
- authenticateRequest: (req: FlinkRequest, permissions: string | string[]) => Promise<boolean>;
3
+ authenticateRequest: (req: FlinkRequest, permissions: string | string[], ctx?: any) => Promise<boolean>;
4
4
  createToken: (payload: any, roles: string[]) => Promise<string>;
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/flink",
3
- "version": "2.0.0-alpha.96",
3
+ "version": "2.0.0-alpha.97",
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",
package/src/FlinkApp.ts CHANGED
@@ -1580,7 +1580,7 @@ export class FlinkApp<C extends FlinkContext> {
1580
1580
  if (!this.auth) {
1581
1581
  throw new Error(`Attempting to authenticate request (${req.method} ${req.path}) but no authPlugin is set`);
1582
1582
  }
1583
- return await this.auth.authenticateRequest(req as FlinkRequest, permissions);
1583
+ return await this.auth.authenticateRequest(req as FlinkRequest, permissions, this._ctx);
1584
1584
  }
1585
1585
 
1586
1586
  public getRegisteredRoutes() {
@@ -3,7 +3,8 @@ import { FlinkRequest } from "../FlinkHttpHandler";
3
3
  export interface FlinkAuthPlugin {
4
4
  authenticateRequest: (
5
5
  req: FlinkRequest,
6
- permissions: string | string[]
6
+ permissions: string | string[],
7
+ ctx?: any
7
8
  ) => Promise<boolean>;
8
9
  createToken: (payload: any, roles: string[]) => Promise<string>;
9
10
  }