tsledge 0.1.9 → 0.1.11
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 +97 -2
- package/dist/fluent-interface/fluent-pattern-handler.d.ts +13 -8
- package/dist/fluent-interface/fluent-pattern-handler.d.ts.map +1 -1
- package/dist/fluent-interface/types.d.ts +1 -9
- package/dist/fluent-interface/types.d.ts.map +1 -1
- package/dist/index.js +50 -46
- package/dist/middleware/authentication/session.d.ts +1 -1
- package/dist/middleware/authentication/session.d.ts.map +1 -1
- package/dist/middleware/authentication/validation.d.ts.map +1 -1
- package/dist/models/auth-token-blocklist.d.ts +13 -0
- package/dist/models/auth-token-blocklist.d.ts.map +1 -0
- package/dist/models/auth-user.d.ts +4 -3
- package/dist/models/auth-user.d.ts.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/package.json +9 -6
- package/dist/models/token-blocklist.d.ts +0 -12
- package/dist/models/token-blocklist.d.ts.map +0 -1
- package/dist/src/index.js +0 -1024
- package/dist/tests/main.js +0 -965
package/README.md
CHANGED
|
@@ -1,5 +1,100 @@
|
|
|
1
1
|
# TSledge
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A TypeScript playground and toolkit for web development.
|
|
4
4
|
|
|
5
|
-

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
This project requires the following dependencies:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install mongoose@9.2.1
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Tutorials
|
|
16
|
+
|
|
17
|
+
### Create Mongoose Collection
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import mongoose from "mongoose";
|
|
21
|
+
|
|
22
|
+
export interface User {
|
|
23
|
+
ofUserGroup: mongoose.Schema.Types.ObjectId;
|
|
24
|
+
username: string;
|
|
25
|
+
email: string;
|
|
26
|
+
secretHash: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type UserDocument = User & mongoose.Document;
|
|
30
|
+
|
|
31
|
+
const UserSchema = new mongoose.Schema<UserDocument>(
|
|
32
|
+
{
|
|
33
|
+
ofUserGroup: {
|
|
34
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
35
|
+
ref: 'UserGroup',
|
|
36
|
+
alias: 'userGroup',
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
username: { type: String, unique: true, required: true, filter: true }, // 'filter' is a fluent-pattern-handler feature
|
|
40
|
+
email: { type: String, unique: true, required: true, select: false },
|
|
41
|
+
secretHash: { type: String, select: false },
|
|
42
|
+
},
|
|
43
|
+
{ collection: 'users', timestamps: true }
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
UserSchema.set('toJSON', {
|
|
47
|
+
transform: (_doc, ret: any) => {
|
|
48
|
+
delete ret.secretHash;
|
|
49
|
+
return ret;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
export const UserModel = mongoose.model<UserDocument>('User', UserSchema);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Using FluentInterface
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
router.get(
|
|
60
|
+
'/',
|
|
61
|
+
async (
|
|
62
|
+
req: FluentExpressRequest,
|
|
63
|
+
res: FluentExpressResponse
|
|
64
|
+
) => {
|
|
65
|
+
try {
|
|
66
|
+
let queryBuilder = new QueryBuilder({
|
|
67
|
+
model: UserModel
|
|
68
|
+
});
|
|
69
|
+
let codec = await FluentPatternHandler.getInstance().exec({
|
|
70
|
+
req,
|
|
71
|
+
res,
|
|
72
|
+
queryBuilder
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
codec.sendToClient(res);
|
|
76
|
+
} catch (e) {
|
|
77
|
+
console.log(e);
|
|
78
|
+
res.status(500).json();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### API Examples
|
|
85
|
+
|
|
86
|
+
#### Search across all filter fields
|
|
87
|
+
|
|
88
|
+
```http
|
|
89
|
+
GET /?filter=john_doe&limit=10&offset=5
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Search in all fields marked with `filter: true` option.
|
|
93
|
+
|
|
94
|
+
#### Search in a specific field
|
|
95
|
+
|
|
96
|
+
```http
|
|
97
|
+
GET /?username=john_doe&limit=10&offset=5
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Search only in the `username` field.
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FluentMiddleware, FluentExecParams } from './types';
|
|
2
2
|
import { PromiseDefaultCodec } from '../core/index';
|
|
3
3
|
export declare class FluentPatternHandler {
|
|
4
|
+
/**
|
|
5
|
+
* Singleton instance of FluentPatternHandler. The class is designed
|
|
6
|
+
*/
|
|
4
7
|
private static _singleton;
|
|
5
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Array of middleware functions to be executed before the main query execution in the exec method. Each function receives the execution parameters and can modify them as needed.
|
|
10
|
+
*/
|
|
6
11
|
private _execMiddlewareFunctions;
|
|
7
12
|
/**
|
|
8
|
-
* Constructor for
|
|
9
|
-
* @param
|
|
13
|
+
* Constructor for FluentPatternHandler.
|
|
14
|
+
* @param execMiddleware - Optional array of middleware functions to be executed before the main query execution in the exec method.
|
|
10
15
|
*/
|
|
11
|
-
constructor(
|
|
16
|
+
constructor(execMiddleware?: FluentMiddleware[]);
|
|
12
17
|
/**
|
|
13
18
|
* Initializes the singleton instance of FluentPatternHandler with the provided options.
|
|
14
|
-
* @param
|
|
19
|
+
* @param execMiddleware - Optional array of middleware functions to be executed before the main query execution in the exec method.
|
|
15
20
|
* @returns Singleton instance of FluentPatternHandler.
|
|
16
21
|
*/
|
|
17
|
-
static init(
|
|
22
|
+
static init(execMiddleware?: FluentMiddleware[]): FluentPatternHandler;
|
|
18
23
|
/**
|
|
19
24
|
* Returns the singleton instance of FluentPatternHandler.
|
|
20
25
|
* @returns Singleton instance of FluentPatternHandler.
|
|
@@ -34,7 +39,7 @@ export declare class FluentPatternHandler {
|
|
|
34
39
|
*/
|
|
35
40
|
private _applyParameters;
|
|
36
41
|
/**
|
|
37
|
-
*
|
|
42
|
+
* Generates filter fields for the given Mongoose model based on schema options.
|
|
38
43
|
* @param model - The Mongoose model.
|
|
39
44
|
* @returns Array of filter fields.
|
|
40
45
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fluent-pattern-handler.d.ts","sourceRoot":"","sources":["../../src/fluent-interface/fluent-pattern-handler.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"fluent-pattern-handler.d.ts","sourceRoot":"","sources":["../../src/fluent-interface/fluent-pattern-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAA8B,mBAAmB,EAAgB,MAAM,eAAe,CAAC;AAY9F,qBAAa,oBAAoB;IAC/B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU,CAAuB;IAChD;;OAEG;IACH,OAAO,CAAC,wBAAwB,CAA0B;IAE1D;;;OAGG;gBACS,cAAc,GAAE,gBAAgB,EAAO;IAUnD;;;;OAIG;WACW,IAAI,CAAC,cAAc,GAAE,gBAAgB,EAAO,GAAG,oBAAoB;IAQjF;;;OAGG;WACW,WAAW,IAAI,oBAAoB;IASjD;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAsChC;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAoCxB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAWhC;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IAa7B;;;;OAIG;IACU,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,MAAM,EAAE,gBAAgB,GAAG,mBAAmB;CAgB1E"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import mongoose from 'mongoose';
|
|
2
1
|
import { Request, Response } from 'express';
|
|
3
2
|
import { DefaultResponseBody, KeysEnum, QueryBuilder } from '../core/index';
|
|
4
|
-
export interface FluentRequestParams extends Record<string, string> {
|
|
5
|
-
collection: string;
|
|
6
|
-
}
|
|
7
3
|
export interface FluentRequestBody {
|
|
8
4
|
}
|
|
9
5
|
export interface FluentRequestQuery {
|
|
@@ -19,11 +15,7 @@ export interface FluentRequestQuery {
|
|
|
19
15
|
* Attributes of FluentRequestQuery used for validation and parsing.
|
|
20
16
|
*/
|
|
21
17
|
export declare const fluentRequestQueryAttributes: KeysEnum<FluentRequestQuery>;
|
|
22
|
-
export
|
|
23
|
-
model: mongoose.Model<T>;
|
|
24
|
-
filters?: string[];
|
|
25
|
-
}
|
|
26
|
-
export type FluentExpressRequest = Request<FluentRequestParams, DefaultResponseBody, FluentRequestBody, FluentRequestQuery>;
|
|
18
|
+
export type FluentExpressRequest = Request<any, DefaultResponseBody, FluentRequestBody, FluentRequestQuery>;
|
|
27
19
|
export type FluentExpressResponse = Response<DefaultResponseBody>;
|
|
28
20
|
export type FluentExecParams = {
|
|
29
21
|
req: FluentExpressRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fluent-interface/types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/fluent-interface/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,WAAW,iBAAiB;CAAG;AAErC,MAAM,WAAW,kBAAkB;IACjC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,EAAE,QAAQ,CAAC,kBAAkB,CAQrE,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,OAAO,CACxC,GAAG,EACH,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,CACnB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAAC,mBAAmB,CAAC,CAAC;AAElE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,oBAAoB,CAAC;IAC1B,GAAG,EAAE,qBAAqB,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -165,6 +165,11 @@ function errorLogger(err, req, res, next) {
|
|
|
165
165
|
|
|
166
166
|
// src/middleware/authentication/session.ts
|
|
167
167
|
import express from "express";
|
|
168
|
+
import bcrypt from "bcrypt";
|
|
169
|
+
import jwt2 from "jsonwebtoken";
|
|
170
|
+
|
|
171
|
+
// src/middleware/authentication/validation.ts
|
|
172
|
+
import jwt from "jsonwebtoken";
|
|
168
173
|
|
|
169
174
|
// src/models/auth-user.ts
|
|
170
175
|
import mongoose2 from "mongoose";
|
|
@@ -176,24 +181,22 @@ var AuthUserSchema = new mongoose2.Schema(
|
|
|
176
181
|
},
|
|
177
182
|
{ collection: "auth_users", timestamps: true }
|
|
178
183
|
);
|
|
179
|
-
var
|
|
184
|
+
var AuthUserModel = mongoose2.model("AuthUser", AuthUserSchema);
|
|
180
185
|
|
|
181
|
-
// src/models/token-blocklist.ts
|
|
186
|
+
// src/models/auth-token-blocklist.ts
|
|
182
187
|
import mongoose3 from "mongoose";
|
|
183
|
-
var
|
|
188
|
+
var AuthTokenBlocklistSchema = new mongoose3.Schema(
|
|
184
189
|
{
|
|
185
190
|
jti: { type: String, required: true }
|
|
186
191
|
},
|
|
187
192
|
{ collection: "token_blocklist", timestamps: true }
|
|
188
193
|
);
|
|
189
|
-
var
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
import jwt2 from "jsonwebtoken";
|
|
194
|
+
var AuthTokenBlocklistModel = mongoose3.model(
|
|
195
|
+
"AuthTokenBlocklist",
|
|
196
|
+
AuthTokenBlocklistSchema
|
|
197
|
+
);
|
|
194
198
|
|
|
195
199
|
// src/middleware/authentication/validation.ts
|
|
196
|
-
import jwt from "jsonwebtoken";
|
|
197
200
|
var FORBIDDEN = 403;
|
|
198
201
|
var UNAUTHORIZED = 401;
|
|
199
202
|
async function jwtRequired(req, res, next) {
|
|
@@ -210,14 +213,14 @@ async function verifyToken(token, jwtSecret) {
|
|
|
210
213
|
console.log("[WARN] JWT token without jti");
|
|
211
214
|
return { isTokenValid: false, isTokenExpired: false, isUserBlocked: false, payload };
|
|
212
215
|
}
|
|
213
|
-
const existingBlock = await
|
|
216
|
+
const existingBlock = await AuthTokenBlocklistModel.findOne({ jti });
|
|
214
217
|
if (existingBlock) {
|
|
215
218
|
console.log("[WARN] JWT token is blocked");
|
|
216
219
|
return { isTokenValid: false, isTokenExpired: false, isUserBlocked: false, payload };
|
|
217
220
|
}
|
|
218
221
|
const identifier = payload.identifier;
|
|
219
222
|
if (identifier) {
|
|
220
|
-
const user = await
|
|
223
|
+
const user = await AuthUserModel.findOne({ identifier });
|
|
221
224
|
if (!user) {
|
|
222
225
|
console.log("[WARN] JWT token for non-existing user");
|
|
223
226
|
return { isTokenValid: false, isTokenExpired: false, isUserBlocked: false, payload };
|
|
@@ -309,9 +312,9 @@ async function generateCredentials(auth) {
|
|
|
309
312
|
let blocked = void 0;
|
|
310
313
|
do {
|
|
311
314
|
jti = crypto.randomUUID();
|
|
312
|
-
blocked = await
|
|
315
|
+
blocked = await AuthTokenBlocklistModel.findOne({ jti });
|
|
313
316
|
} while (blocked != void 0);
|
|
314
|
-
const user = await
|
|
317
|
+
const user = await AuthUserModel.findOne({ identifier: auth.identifier }).lean();
|
|
315
318
|
if (!user) {
|
|
316
319
|
return void 0;
|
|
317
320
|
}
|
|
@@ -341,11 +344,11 @@ async function authRegister(req, res, next) {
|
|
|
341
344
|
return res.sendStatus(FORBIDDEN2);
|
|
342
345
|
}
|
|
343
346
|
identifier = identifier.toLowerCase();
|
|
344
|
-
let user = await
|
|
347
|
+
let user = await AuthUserModel.findOne({ identifier });
|
|
345
348
|
if (user) {
|
|
346
349
|
return res.sendStatus(BAD_REQUEST);
|
|
347
350
|
}
|
|
348
|
-
res.locals.authUser = new
|
|
351
|
+
res.locals.authUser = new AuthUserModel({
|
|
349
352
|
identifier,
|
|
350
353
|
secretHash: await bcrypt.hash(secret, 10)
|
|
351
354
|
});
|
|
@@ -357,7 +360,7 @@ async function authLogin(req, res, next) {
|
|
|
357
360
|
return res.sendStatus(FORBIDDEN2);
|
|
358
361
|
}
|
|
359
362
|
identifier = identifier.toLowerCase();
|
|
360
|
-
let user = await
|
|
363
|
+
let user = await AuthUserModel.findOne({ identifier }).select("+secretHash");
|
|
361
364
|
if (!user || !user.secretHash) {
|
|
362
365
|
return res.sendStatus(BAD_REQUEST);
|
|
363
366
|
}
|
|
@@ -384,9 +387,9 @@ async function authLogout(req, res, next) {
|
|
|
384
387
|
const decoded = jwt2.decode(refreshToken);
|
|
385
388
|
const jti = decoded?.jti;
|
|
386
389
|
if (jti) {
|
|
387
|
-
const existingBlock = await
|
|
390
|
+
const existingBlock = await AuthTokenBlocklistModel.findOne({ jti });
|
|
388
391
|
if (!existingBlock) {
|
|
389
|
-
await new
|
|
392
|
+
await new AuthTokenBlocklistModel({ jti }).save();
|
|
390
393
|
}
|
|
391
394
|
}
|
|
392
395
|
let accessToken = validateString(req.body?.access_token);
|
|
@@ -394,9 +397,9 @@ async function authLogout(req, res, next) {
|
|
|
394
397
|
const accessTokenDecoded = jwt2.decode(accessToken);
|
|
395
398
|
let accessTokenJti = accessTokenDecoded?.jti;
|
|
396
399
|
if (accessTokenJti) {
|
|
397
|
-
const existing = await
|
|
400
|
+
const existing = await AuthTokenBlocklistModel.findOne({ jti: accessTokenJti });
|
|
398
401
|
if (!existing) {
|
|
399
|
-
await new
|
|
402
|
+
await new AuthTokenBlocklistModel({ jti: accessTokenJti }).save();
|
|
400
403
|
}
|
|
401
404
|
}
|
|
402
405
|
}
|
|
@@ -414,9 +417,9 @@ async function authRefresh(req, res, next) {
|
|
|
414
417
|
const decoded = jwt2.decode(refreshToken);
|
|
415
418
|
const jti = decoded?.jti;
|
|
416
419
|
if (jti) {
|
|
417
|
-
const existingBlock = await
|
|
420
|
+
const existingBlock = await AuthTokenBlocklistModel.findOne({ jti });
|
|
418
421
|
if (!existingBlock) {
|
|
419
|
-
await new
|
|
422
|
+
await new AuthTokenBlocklistModel({ jti }).save();
|
|
420
423
|
}
|
|
421
424
|
}
|
|
422
425
|
let accessToken = validateString(req.body?.access_token);
|
|
@@ -424,11 +427,11 @@ async function authRefresh(req, res, next) {
|
|
|
424
427
|
const accessTokenDecoded = jwt2.decode(accessToken);
|
|
425
428
|
let accessTokenJti = accessTokenDecoded?.jti;
|
|
426
429
|
if (accessTokenJti) {
|
|
427
|
-
const existing = await
|
|
430
|
+
const existing = await AuthTokenBlocklistModel.findOne({
|
|
428
431
|
jti: accessTokenJti
|
|
429
432
|
});
|
|
430
433
|
if (!existing) {
|
|
431
|
-
await new
|
|
434
|
+
await new AuthTokenBlocklistModel({ jti: accessTokenJti }).save();
|
|
432
435
|
}
|
|
433
436
|
}
|
|
434
437
|
}
|
|
@@ -807,30 +810,32 @@ async function httpRequest(config) {
|
|
|
807
810
|
// src/fluent-interface/fluent-pattern-handler.ts
|
|
808
811
|
var FluentPatternHandler = class _FluentPatternHandler {
|
|
809
812
|
/**
|
|
810
|
-
* Constructor for
|
|
811
|
-
* @param
|
|
813
|
+
* Constructor for FluentPatternHandler.
|
|
814
|
+
* @param execMiddleware - Optional array of middleware functions to be executed before the main query execution in the exec method.
|
|
812
815
|
*/
|
|
813
|
-
constructor(
|
|
816
|
+
constructor(execMiddleware = []) {
|
|
817
|
+
/**
|
|
818
|
+
* Array of middleware functions to be executed before the main query execution in the exec method. Each function receives the execution parameters and can modify them as needed.
|
|
819
|
+
*/
|
|
814
820
|
this._execMiddlewareFunctions = [];
|
|
815
821
|
if (_FluentPatternHandler._singleton) {
|
|
816
822
|
throw new Error(
|
|
817
823
|
"FluentPatternHandler is a singleton class. Use FluentPatternHandler.getInstance() to access the instance."
|
|
818
824
|
);
|
|
819
825
|
}
|
|
820
|
-
this._options = options;
|
|
821
826
|
this._execMiddlewareFunctions = execMiddleware;
|
|
822
827
|
_FluentPatternHandler._singleton = this;
|
|
823
828
|
}
|
|
824
829
|
/**
|
|
825
830
|
* Initializes the singleton instance of FluentPatternHandler with the provided options.
|
|
826
|
-
* @param
|
|
831
|
+
* @param execMiddleware - Optional array of middleware functions to be executed before the main query execution in the exec method.
|
|
827
832
|
* @returns Singleton instance of FluentPatternHandler.
|
|
828
833
|
*/
|
|
829
|
-
static init(
|
|
834
|
+
static init(execMiddleware = []) {
|
|
830
835
|
if (_FluentPatternHandler._singleton != void 0) {
|
|
831
836
|
throw new Error("FluentPatternHandler is already initialized");
|
|
832
837
|
}
|
|
833
|
-
_FluentPatternHandler._singleton = new _FluentPatternHandler(
|
|
838
|
+
_FluentPatternHandler._singleton = new _FluentPatternHandler(execMiddleware);
|
|
834
839
|
return _FluentPatternHandler._singleton;
|
|
835
840
|
}
|
|
836
841
|
/**
|
|
@@ -869,7 +874,7 @@ var FluentPatternHandler = class _FluentPatternHandler {
|
|
|
869
874
|
excluded = JSON.parse(excludedJSON);
|
|
870
875
|
if (!Array.isArray(excluded)) throw new Error("Excluded must be an array");
|
|
871
876
|
} catch (error) {
|
|
872
|
-
console.warn("[
|
|
877
|
+
console.warn("[FluentPatternHandler] Invalid excluded parameter:", error);
|
|
873
878
|
}
|
|
874
879
|
}
|
|
875
880
|
let ids;
|
|
@@ -878,7 +883,7 @@ var FluentPatternHandler = class _FluentPatternHandler {
|
|
|
878
883
|
ids = JSON.parse(idsJSON);
|
|
879
884
|
if (!Array.isArray(ids)) throw new Error("Ids must be an array");
|
|
880
885
|
} catch (error) {
|
|
881
|
-
console.warn("[
|
|
886
|
+
console.warn("[FluentPatternHandler] Invalid ids parameter:", error);
|
|
882
887
|
}
|
|
883
888
|
}
|
|
884
889
|
return { filter, limit, offset, id, excluded, ids, filterFields };
|
|
@@ -921,20 +926,19 @@ var FluentPatternHandler = class _FluentPatternHandler {
|
|
|
921
926
|
}
|
|
922
927
|
}
|
|
923
928
|
/**
|
|
924
|
-
*
|
|
929
|
+
* Generates filter fields for the given Mongoose model based on schema options.
|
|
925
930
|
* @param model - The Mongoose model.
|
|
926
931
|
* @returns Array of filter fields.
|
|
927
932
|
*/
|
|
928
933
|
_getFilterFieldsForModel(model) {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
return [];
|
|
934
|
+
let filterFields = [];
|
|
935
|
+
let schema = model.schema;
|
|
936
|
+
schema.eachPath((path2, type) => {
|
|
937
|
+
if (type?.options?.filter == true) {
|
|
938
|
+
filterFields.push(path2);
|
|
935
939
|
}
|
|
936
|
-
}
|
|
937
|
-
return
|
|
940
|
+
});
|
|
941
|
+
return filterFields;
|
|
938
942
|
}
|
|
939
943
|
/**
|
|
940
944
|
* Builds execution parameters for the query builder.
|
|
@@ -952,7 +956,7 @@ var FluentPatternHandler = class _FluentPatternHandler {
|
|
|
952
956
|
/**
|
|
953
957
|
* Executes the query builder with applied filters and returns the result.
|
|
954
958
|
* @param params Execution parameters including the query builder and request query.
|
|
955
|
-
* @returns
|
|
959
|
+
* @returns
|
|
956
960
|
*/
|
|
957
961
|
async exec(params) {
|
|
958
962
|
try {
|
|
@@ -966,7 +970,7 @@ var FluentPatternHandler = class _FluentPatternHandler {
|
|
|
966
970
|
const execConfig = this._buildExecutionConfig(queryParams);
|
|
967
971
|
return await params.queryBuilder.exec(execConfig);
|
|
968
972
|
} catch (err) {
|
|
969
|
-
console.error("[ERROR -
|
|
973
|
+
console.error("[ERROR - FluentPatternHandler]", err);
|
|
970
974
|
return new Codec({ data: [], meta: { total: 0 } }, 500);
|
|
971
975
|
}
|
|
972
976
|
}
|
|
@@ -985,7 +989,8 @@ function createApp() {
|
|
|
985
989
|
return app;
|
|
986
990
|
}
|
|
987
991
|
export {
|
|
988
|
-
|
|
992
|
+
AuthTokenBlocklistModel,
|
|
993
|
+
AuthUserModel,
|
|
989
994
|
Codec,
|
|
990
995
|
EXIT_CODE_GENERAL_ERROR,
|
|
991
996
|
EXIT_CODE_INVALID_CONFIG,
|
|
@@ -996,7 +1001,6 @@ export {
|
|
|
996
1001
|
JwtRefreshSecret,
|
|
997
1002
|
JwtSecret,
|
|
998
1003
|
QueryBuilder,
|
|
999
|
-
TokenBlocklist,
|
|
1000
1004
|
authLogin,
|
|
1001
1005
|
authLogout,
|
|
1002
1006
|
authRefresh,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express, { Request, Response } from 'express';
|
|
2
|
-
import { AuthUserDocument } from '../../models';
|
|
3
2
|
import { JWTCredentials, AuthUserPayload } from './types';
|
|
3
|
+
import { AuthUserDocument } from '../../models';
|
|
4
4
|
declare const router: import("express-serve-static-core").Router;
|
|
5
5
|
/**
|
|
6
6
|
* Handles user registration by validating input and creating a new user with a hashed password.
|
|
@@ -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;
|
|
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,OAAO,EACZ,GAAG,EAAE,QAAQ,GAAG;IAAE,MAAM,EAAE;QAAE,QAAQ,EAAE,gBAAgB,CAAA;KAAE,CAAA;CAAE,EAC1D,IAAI,EAAE,GAAG;YADiB;QAAE,QAAQ,EAAE,gBAAgB,CAAA;KAAE;gBAkBzD;AAED;;;;;;;GAOG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG;IAAE,MAAM,EAAE;QAAE,WAAW,EAAE,cAAc,CAAA;KAAE,CAAA;CAAE,EAAE,IAAI,EAAE,GAAG;YAA5C;QAAE,WAAW,EAAE,cAAc,CAAA;KAAE;gBAuBtG;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,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,iBA4BV;AAED;;;;;;;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,CAAC;QAAC,WAAW,EAAE,cAAc,CAAA;KAAE,CAAA;CAAE,EACjG,IAAI,EAAE,GAAG;YADiB;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,cAAc,CAAA;KAAE;gBAyChG;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -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;
|
|
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;YAuFwD;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;gBApF1G;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;YAuEwD;QAAE,IAAI,EAAE,eAAe,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE;gBApE1G;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAgDpG;AAwCD,wBAAsB,WAAW,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,gBAqBzD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
export interface AuthTokenBlocklist {
|
|
3
|
+
jti: string;
|
|
4
|
+
}
|
|
5
|
+
export type AuthTokenBlocklistDocument = AuthTokenBlocklist & mongoose.Document;
|
|
6
|
+
export declare const AuthTokenBlocklistModel: mongoose.Model<AuthTokenBlocklistDocument, {}, {}, {}, mongoose.Document<unknown, {}, AuthTokenBlocklistDocument, {}, mongoose.DefaultSchemaOptions> & AuthTokenBlocklist & mongoose.Document<mongoose.Types.ObjectId, any, any, Record<string, any>, {}> & Required<{
|
|
7
|
+
_id: mongoose.Types.ObjectId;
|
|
8
|
+
}> & {
|
|
9
|
+
__v: number;
|
|
10
|
+
} & {
|
|
11
|
+
id: string;
|
|
12
|
+
}, any, AuthTokenBlocklistDocument>;
|
|
13
|
+
//# sourceMappingURL=auth-token-blocklist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-token-blocklist.d.ts","sourceRoot":"","sources":["../../src/models/auth-token-blocklist.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,0BAA0B,GAAG,kBAAkB,GAAG,QAAQ,CAAC,QAAQ,CAAC;AAShF,eAAO,MAAM,uBAAuB;;;;;;mCAGnC,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import mongoose
|
|
2
|
-
export interface
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
export interface AuthUser {
|
|
3
3
|
identifier: string;
|
|
4
4
|
secretHash: string;
|
|
5
5
|
blockedSince: Date;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
7
|
+
export type AuthUserDocument = AuthUser & mongoose.Document;
|
|
8
|
+
export declare const AuthUserModel: mongoose.Model<AuthUserDocument, {}, {}, {}, mongoose.Document<unknown, {}, AuthUserDocument, {}, mongoose.DefaultSchemaOptions> & AuthUser & mongoose.Document<mongoose.Types.ObjectId, any, any, Record<string, any>, {}> & Required<{
|
|
8
9
|
_id: mongoose.Types.ObjectId;
|
|
9
10
|
}> & {
|
|
10
11
|
__v: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-user.d.ts","sourceRoot":"","sources":["../../src/models/auth-user.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"auth-user.d.ts","sourceRoot":"","sources":["../../src/models/auth-user.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,IAAI,CAAC;CACpB;AAED,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;AAW5D,eAAO,MAAM,aAAa;;;;;;yBAA+D,CAAC"}
|
package/dist/models/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Niklas Wockenfuß",
|
|
3
3
|
"homepage": "https://niklaswockenfuss.de/",
|
|
4
4
|
"name": "tsledge",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.11",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "My playground and some helpful tools for web development ",
|
|
8
8
|
"main": "dist/index.js",
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
"node": ">=23.0.0"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"esbuild:build:watch": "node esbuild.js --watch",
|
|
21
|
-
"esbuild:dev:watch": "node --watch dist/tests/main.js",
|
|
22
|
-
"build": "node esbuild.js && tsc --emitDeclarationOnly",
|
|
20
|
+
"esbuild:build:watch": "node ./esbuild.js --watch",
|
|
21
|
+
"esbuild:dev:watch": "node --watch ./dist/tests/main.js",
|
|
22
|
+
"build": "npm i && node esbuild.js && tsc --emitDeclarationOnly",
|
|
23
23
|
"dev": "concurrently \"npm run esbuild:build:watch\" \"npm run esbuild:dev:watch\"",
|
|
24
24
|
"repl": "tsx ./scripts/repl.ts",
|
|
25
|
-
"npmjs": "npm run build && npm publish"
|
|
25
|
+
"npmjs": "npm run build && npm publish",
|
|
26
|
+
"package": "npm run build && npm pack"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"bcrypt": "^6.0.0",
|
|
@@ -30,9 +31,11 @@
|
|
|
30
31
|
"dotenv": "^17.2.3",
|
|
31
32
|
"express": "^5.2.1",
|
|
32
33
|
"jsonwebtoken": "^9.0.3",
|
|
33
|
-
"mongoose": "^9.1.5",
|
|
34
34
|
"multer": "^2.0.2"
|
|
35
35
|
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"mongoose": "9.2.1"
|
|
38
|
+
},
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"@types/bcrypt": "^6.0.0",
|
|
38
41
|
"@types/cors": "^2.8.19",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
export interface TokenBlocklistDocument extends Document {
|
|
3
|
-
jti: string;
|
|
4
|
-
}
|
|
5
|
-
export declare const TokenBlocklist: mongoose.Model<TokenBlocklistDocument, {}, {}, {}, mongoose.Document<unknown, {}, TokenBlocklistDocument, {}, mongoose.DefaultSchemaOptions> & TokenBlocklistDocument & {
|
|
6
|
-
_id: mongoose.Types.ObjectId;
|
|
7
|
-
} & {
|
|
8
|
-
__v: number;
|
|
9
|
-
} & {
|
|
10
|
-
id: string;
|
|
11
|
-
}, any, TokenBlocklistDocument>;
|
|
12
|
-
//# sourceMappingURL=token-blocklist.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"token-blocklist.d.ts","sourceRoot":"","sources":["../../src/models/token-blocklist.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAEhC,MAAM,WAAW,sBAAuB,SAAQ,QAAQ;IACtD,GAAG,EAAE,MAAM,CAAC;CACb;AASD,eAAO,MAAM,cAAc;;;;;;+BAAiF,CAAC"}
|