@thunderid/express 1.4.0 → 1.6.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.
@@ -1,4 +1,4 @@
1
- import { ThunderIDNodeClient, Storage, TokenResponse, User } from '@thunderid/node';
1
+ import { ThunderIDNodeClient, ThunderIDNodeManagementClient, Storage, TokenResponse, User } from '@thunderid/node';
2
2
  import express from 'express';
3
3
  import { ExpressClientConfig } from './models/config';
4
4
  declare class ThunderIDExpressClient<T extends ExpressClientConfig = ExpressClientConfig> extends ThunderIDNodeClient<T> {
@@ -13,6 +13,21 @@ declare class ThunderIDExpressClient<T extends ExpressClientConfig = ExpressClie
13
13
  */
14
14
  getSessionCookieName(): string;
15
15
  getUserFromRequest(req: express.Request): Promise<User | undefined>;
16
+ /**
17
+ * Returns the management operations bound to the session named by the request's session cookie,
18
+ * so a route handler can administer users, groups, roles, and agents as the signed-in user. The
19
+ * session's access token stays on the server and is read on every call.
20
+ *
21
+ * ```ts
22
+ * app.get('/admin/users', protect(), async (req, res) => {
23
+ * const admin = req.thunderIDAuth.managementFromRequest(req);
24
+ * res.json(await admin.users.list({limit: 20}));
25
+ * });
26
+ * ```
27
+ *
28
+ * @throws {ThunderIDRuntimeError} `EXPRESS-CLIENT-MFR-NF01` when the request carries no session cookie.
29
+ */
30
+ managementFromRequest(req: express.Request): ThunderIDNodeManagementClient;
16
31
  updateUserCredentialsFromRequest(req: express.Request, payload: Record<string, string>): Promise<void>;
17
32
  signIn(req: express.Request, res: express.Response, next?: express.NextFunction, signInConfig?: Record<string, string | boolean>): Promise<TokenResponse>;
18
33
  signOut(userId?: string): Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"ThunderIDExpressClient.d.ts","sourceRoot":"","sources":["../src/ThunderIDExpressClient.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EAEnB,OAAO,EACP,aAAa,EACb,IAAI,EAEL,MAAM,iBAAiB,CAAC;AACzB,OAAO,O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AAC,MAAM,iBAAiB,CAAC;AAGpD,cAAM,sBAAsB,CAAC,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IAC9G,OAAO,CAAC,cAAc,CAAkC;;IAMlC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAKhF,IAAW,aAAa,IAAI,mBAAmB,GAAG,SAAS,CAE1D;IAED;;;;OAIG;IACI,oBAAoB,IAAI,MAAM;IAOxB,kBAAkB,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC;IAMhF;;;;;;;;;;;;;OAaG;IACI,qBAAqB,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,GAAG,6BAA6B;IAWpE,gCAAgC,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAM7F,MAAM,CAC1B,GAAG,EAAE,OAAO,CAAC,OAAO,EACpB,GAAG,EAAE,OAAO,CAAC,QAAQ,EACrB,IAAI,CAAC,EAAE,OAAO,CAAC,YAAY,EAC3B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAC9C,OAAO,CAAC,aAAa,CAAC;IAuDH,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAGhE;AAED,eAAe,sBAAsB,CAAC"}
@@ -75,6 +75,25 @@ var ThunderIDExpressClient = class extends __thunderid_node.ThunderIDNodeClient
75
75
  const sessionId = req.cookies?.[this.getSessionCookieName()];
76
76
  return this.getUser(sessionId);
77
77
  }
78
+ /**
79
+ * Returns the management operations bound to the session named by the request's session cookie,
80
+ * so a route handler can administer users, groups, roles, and agents as the signed-in user. The
81
+ * session's access token stays on the server and is read on every call.
82
+ *
83
+ * ```ts
84
+ * app.get('/admin/users', protect(), async (req, res) => {
85
+ * const admin = req.thunderIDAuth.managementFromRequest(req);
86
+ * res.json(await admin.users.list({limit: 20}));
87
+ * });
88
+ * ```
89
+ *
90
+ * @throws {ThunderIDRuntimeError} `EXPRESS-CLIENT-MFR-NF01` when the request carries no session cookie.
91
+ */
92
+ managementFromRequest(req) {
93
+ const sessionId = req.cookies?.[this.getSessionCookieName()];
94
+ if (!sessionId) throw new __thunderid_node.ThunderIDRuntimeError("No session cookie found in the request.", "EXPRESS-CLIENT-MFR-NF01", "express");
95
+ return this.management(sessionId);
96
+ }
78
97
  async updateUserCredentialsFromRequest(req, payload) {
79
98
  const sessionId = req.cookies?.[this.getSessionCookieName()];
80
99
  return this.updateUserCredentials(payload, sessionId);
@@ -51,6 +51,25 @@ var ThunderIDExpressClient = class extends ThunderIDNodeClient {
51
51
  const sessionId = req.cookies?.[this.getSessionCookieName()];
52
52
  return this.getUser(sessionId);
53
53
  }
54
+ /**
55
+ * Returns the management operations bound to the session named by the request's session cookie,
56
+ * so a route handler can administer users, groups, roles, and agents as the signed-in user. The
57
+ * session's access token stays on the server and is read on every call.
58
+ *
59
+ * ```ts
60
+ * app.get('/admin/users', protect(), async (req, res) => {
61
+ * const admin = req.thunderIDAuth.managementFromRequest(req);
62
+ * res.json(await admin.users.list({limit: 20}));
63
+ * });
64
+ * ```
65
+ *
66
+ * @throws {ThunderIDRuntimeError} `EXPRESS-CLIENT-MFR-NF01` when the request carries no session cookie.
67
+ */
68
+ managementFromRequest(req) {
69
+ const sessionId = req.cookies?.[this.getSessionCookieName()];
70
+ if (!sessionId) throw new ThunderIDRuntimeError("No session cookie found in the request.", "EXPRESS-CLIENT-MFR-NF01", "express");
71
+ return this.management(sessionId);
72
+ }
54
73
  async updateUserCredentialsFromRequest(req, payload) {
55
74
  const sessionId = req.cookies?.[this.getSessionCookieName()];
56
75
  return this.updateUserCredentials(payload, sessionId);
package/dist/index.js CHANGED
@@ -51,6 +51,25 @@ var ThunderIDExpressClient = class extends ThunderIDNodeClient {
51
51
  const sessionId = req.cookies?.[this.getSessionCookieName()];
52
52
  return this.getUser(sessionId);
53
53
  }
54
+ /**
55
+ * Returns the management operations bound to the session named by the request's session cookie,
56
+ * so a route handler can administer users, groups, roles, and agents as the signed-in user. The
57
+ * session's access token stays on the server and is read on every call.
58
+ *
59
+ * ```ts
60
+ * app.get('/admin/users', protect(), async (req, res) => {
61
+ * const admin = req.thunderIDAuth.managementFromRequest(req);
62
+ * res.json(await admin.users.list({limit: 20}));
63
+ * });
64
+ * ```
65
+ *
66
+ * @throws {ThunderIDRuntimeError} `EXPRESS-CLIENT-MFR-NF01` when the request carries no session cookie.
67
+ */
68
+ managementFromRequest(req) {
69
+ const sessionId = req.cookies?.[this.getSessionCookieName()];
70
+ if (!sessionId) throw new ThunderIDRuntimeError("No session cookie found in the request.", "EXPRESS-CLIENT-MFR-NF01", "express");
71
+ return this.management(sessionId);
72
+ }
54
73
  async updateUserCredentialsFromRequest(req, payload) {
55
74
  const sessionId = req.cookies?.[this.getSessionCookieName()];
56
75
  return this.updateUserCredentials(payload, sessionId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thunderid/express",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Express.js SDK for ThunderID",
5
5
  "keywords": [
6
6
  "thunderid",
@@ -47,7 +47,7 @@
47
47
  "vitest": "4.1.11"
48
48
  },
49
49
  "dependencies": {
50
- "@thunderid/node": "^1.4.0",
50
+ "@thunderid/node": "^1.6.0",
51
51
  "uuid": "11.1.1"
52
52
  },
53
53
  "peerDependencies": {