tsledge 0.1.16 → 0.1.18

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/README.md CHANGED
@@ -20,7 +20,7 @@ npm install mongoose@9.2.1
20
20
  import mongoose from "mongoose";
21
21
 
22
22
  export interface User {
23
- ofUserGroup: mongoose.Schema.Types.ObjectId;
23
+ ofUserGroup: mongoose.Types.ObjectId;
24
24
  username: string;
25
25
  email: string;
26
26
  secretHash: string;
@@ -97,4 +97,4 @@ Search in all fields marked with `filter: true` option.
97
97
  GET /?username=john_doe&limit=10&offset=5
98
98
  ```
99
99
 
100
- Search only in the `username` field.
100
+ Search only in the `username` field.
package/dist/index.js CHANGED
@@ -341,12 +341,14 @@ async function generateCredentials(auth) {
341
341
  async function authRegister(req, res, next) {
342
342
  let { identifier = void 0, secret = void 0 } = req.body || {};
343
343
  if (!identifier || !secret) {
344
- return res.sendStatus(FORBIDDEN2);
344
+ res.sendStatus(FORBIDDEN2);
345
+ return;
345
346
  }
346
347
  identifier = identifier.toLowerCase();
347
348
  let user = await AuthUserModel.findOne({ identifier });
348
349
  if (user) {
349
- return res.sendStatus(BAD_REQUEST);
350
+ res.sendStatus(BAD_REQUEST);
351
+ return;
350
352
  }
351
353
  res.locals.authUser = new AuthUserModel({
352
354
  identifier,
@@ -357,23 +359,28 @@ async function authRegister(req, res, next) {
357
359
  async function authLogin(req, res, next) {
358
360
  let { identifier = void 0, secret = void 0 } = req.body || {};
359
361
  if (!identifier || !secret) {
360
- return res.sendStatus(FORBIDDEN2);
362
+ res.sendStatus(FORBIDDEN2);
363
+ return;
361
364
  }
362
365
  identifier = identifier.toLowerCase();
363
366
  let user = await AuthUserModel.findOne({ identifier }).select("+secretHash");
364
367
  if (!user || !user.secretHash) {
365
- return res.sendStatus(BAD_REQUEST);
368
+ res.sendStatus(BAD_REQUEST);
369
+ return;
366
370
  }
367
371
  if (user.blockedSince) {
368
- return res.sendStatus(FORBIDDEN2);
372
+ res.sendStatus(FORBIDDEN2);
373
+ return;
369
374
  }
370
375
  let isMatch = await bcrypt.compare(secret, user.secretHash);
371
376
  if (!isMatch) {
372
- return res.sendStatus(BAD_REQUEST);
377
+ res.sendStatus(BAD_REQUEST);
378
+ return;
373
379
  }
374
380
  let credentials = await generateCredentials(user);
375
381
  if (!credentials) {
376
- return res.sendStatus(BAD_REQUEST);
382
+ res.sendStatus(BAD_REQUEST);
383
+ return;
377
384
  }
378
385
  res.locals.credentials = credentials;
379
386
  next();
@@ -382,7 +389,8 @@ async function authLogout(req, res, next) {
382
389
  await jwtRefreshRequired(req, res, async () => {
383
390
  const refreshToken = res.locals.token;
384
391
  if (!refreshToken) {
385
- return res.sendStatus(BAD_REQUEST);
392
+ res.sendStatus(BAD_REQUEST);
393
+ return;
386
394
  }
387
395
  const decoded = jwt2.decode(refreshToken);
388
396
  const jti = decoded?.jti;
@@ -411,7 +419,8 @@ async function authRefresh(req, res, next) {
411
419
  });
412
420
  const refreshToken = res.locals.token;
413
421
  if (!refreshToken) {
414
- return res.sendStatus(BAD_REQUEST);
422
+ res.sendStatus(BAD_REQUEST);
423
+ return;
415
424
  }
416
425
  try {
417
426
  const decoded = jwt2.decode(refreshToken);
@@ -438,13 +447,15 @@ async function authRefresh(req, res, next) {
438
447
  const payload = jwt2.verify(refreshToken, JwtRefreshSecret);
439
448
  let credentials = await generateCredentials(payload);
440
449
  if (!credentials) {
441
- return res.sendStatus(BAD_REQUEST);
450
+ res.sendStatus(BAD_REQUEST);
451
+ return;
442
452
  }
443
453
  res.locals.credentials = credentials;
444
454
  next();
445
455
  } catch (err) {
446
456
  console.log("[WARN] refreshing JWT:", err);
447
- return res.sendStatus(BAD_REQUEST);
457
+ res.sendStatus(BAD_REQUEST);
458
+ return;
448
459
  }
449
460
  }
450
461
 
@@ -1,4 +1,4 @@
1
- import express, { Request, Response } from 'express';
1
+ import { Request, Response } from 'express';
2
2
  import { JWTCredentials, AuthUserPayload } from './types';
3
3
  import { AuthUserDocument } from '../../models';
4
4
  declare const router: import("express-serve-static-core").Router;
@@ -14,11 +14,7 @@ export declare function authRegister(req: Request, res: Response & {
14
14
  locals: {
15
15
  authUser: AuthUserDocument;
16
16
  };
17
- }, next: any): Promise<(express.Response<any, Record<string, any>> & {
18
- locals: {
19
- authUser: AuthUserDocument;
20
- };
21
- }) | undefined>;
17
+ }, next: any): Promise<void>;
22
18
  /**
23
19
  * Handles user login by validating credentials and generating JWT tokens.
24
20
  * Passes data in ``res.locals.credentials`` for the next middleware to use.
@@ -31,11 +27,7 @@ export declare function authLogin(req: Request, res: Response & {
31
27
  locals: {
32
28
  credentials: JWTCredentials;
33
29
  };
34
- }, next: any): Promise<(express.Response<any, Record<string, any>> & {
35
- locals: {
36
- credentials: JWTCredentials;
37
- };
38
- }) | undefined>;
30
+ }, next: any): Promise<void>;
39
31
  /**
40
32
  * Handles user logout by invalidating the provided refresh token and optionally the access token.
41
33
  * JWTRefresh Token is required
@@ -63,12 +55,6 @@ export declare function authRefresh(req: Request, res: Response & {
63
55
  token: string;
64
56
  credentials: JWTCredentials;
65
57
  };
66
- }, next: any): Promise<(express.Response<any, Record<string, any>> & {
67
- locals: {
68
- user: AuthUserPayload;
69
- token: string;
70
- credentials: JWTCredentials;
71
- };
72
- }) | undefined>;
58
+ }, next: any): Promise<void>;
73
59
  export default router;
74
60
  //# sourceMappingURL=session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/middleware/authentication/session.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI1D,OAAO,EAAE,gBAAgB,EAA0C,MAAM,cAAc,CAAC;AAExF,QAAA,MAAM,MAAM,4CAAmB,CAAC;AA2ChC;;;;;;;GAOG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,O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 * JWT expires, is set by express in sign()
12
+ */
4
13
  exp?: number;
14
+ /**
15
+ * JWT issued at, is set by express in sign()
16
+ */
5
17
  iat?: number;
6
18
  }
7
19
  export interface JWTCredentials {
20
+ /**
21
+ * JWT Access Token, expires in 15 minutes, signed with JwtSecret
22
+ */
8
23
  accessToken: string;
24
+ /**
25
+ * JWT Refresh Token, expires in 7 days, signed with JwtRefreshSecret
26
+ */
9
27
  refreshToken: string;
10
- appUser: any;
28
+ /**
29
+ * Encoded string of AuthUserModel in base64 format
30
+ */
31
+ appUser: string;
11
32
  }
12
33
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/middleware/authentication/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,GAAG,CAAC;CACd"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/middleware/authentication/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB"}
@@ -1,9 +1,21 @@
1
1
  import { Request, Response } from 'express';
2
2
  import { AuthUserPayload } from './types';
3
3
  export interface TokenVerificationResult {
4
+ /**
5
+ * Indicates if the token is valid (signature is correct, not blocked, and user is not blocked).
6
+ */
4
7
  isTokenValid: boolean;
8
+ /**
9
+ * Indicates if the token is expired.
10
+ */
5
11
  isTokenExpired: boolean;
12
+ /**
13
+ * Indicates if the user associated with the token is blocked.
14
+ */
6
15
  isUserBlocked: boolean;
16
+ /**
17
+ * The decoded payload from the JWT token, which should contain user information.
18
+ */
7
19
  payload: AuthUserPayload | any;
8
20
  }
9
21
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/middleware/authentication/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI1C,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,OAAO,CAAC;IACtB,cAAc,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;IACvB,OAAO,EAAE,eAAe,GAAG,GAAG,CAAC;CAChC;AAKD;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,GAAG;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACpE,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,GAAG;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACpE,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,uBAAuB,CAAC,CAgDlC;AAqDD,wBAAsB,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAsBzD"}
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/middleware/authentication/validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAI1C,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB;;OAEG;IACH,cAAc,EAAE,OAAO,CAAC;IACxB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IACvB;;OAEG;IACH,OAAO,EAAE,eAAe,GAAG,GAAG,CAAC;CAChC;AAKD;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,GAAG;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACpE,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,GAAG;IAAE,MAAM,EAAE;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,EACpE,IAAI,EAAE,GAAG,GACR,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,uBAAuB,CAAC,CAgDlC;AAqDD,wB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