@tc-libs/request 3.6.0 → 3.6.1
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 +108 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,11 +1,113 @@
|
|
|
1
|
-
# request
|
|
1
|
+
# @tc-libs/request
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Layer request globale per NestJS.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Centralizza:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- validation pipe globale
|
|
8
|
+
- timeout globale
|
|
9
|
+
- throttling
|
|
10
|
+
- middleware HTTP
|
|
11
|
+
- decorator request-aware
|
|
12
|
+
- custom validators class-validator
|
|
8
13
|
|
|
9
|
-
##
|
|
14
|
+
## Registrazione
|
|
10
15
|
|
|
11
|
-
|
|
16
|
+
```ts
|
|
17
|
+
RequestModule.register(
|
|
18
|
+
{
|
|
19
|
+
request: {
|
|
20
|
+
timeout: 15000,
|
|
21
|
+
timestamp: { toleranceTimeInMs: 30000 },
|
|
22
|
+
userAgent: {
|
|
23
|
+
enabled: true,
|
|
24
|
+
browser: ['Chrome', 'Firefox'],
|
|
25
|
+
os: ['Windows', 'Mac OS', 'Linux'],
|
|
26
|
+
},
|
|
27
|
+
throttle: {
|
|
28
|
+
ttl: 60000,
|
|
29
|
+
limit: 100,
|
|
30
|
+
},
|
|
31
|
+
body: {
|
|
32
|
+
urlencoded: { maxFileSize: 1048576 },
|
|
33
|
+
json: { maxFileSize: 1048576 },
|
|
34
|
+
raw: { maxFileSize: 1048576 },
|
|
35
|
+
text: { maxFileSize: 1048576 },
|
|
36
|
+
},
|
|
37
|
+
cors: {
|
|
38
|
+
allowOrigin: true,
|
|
39
|
+
allowMethod: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
|
|
40
|
+
allowHeader: ['Content-Type', 'Authorization'],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
app: {
|
|
44
|
+
production: false,
|
|
45
|
+
globalPrefix: 'api',
|
|
46
|
+
repoVersion: '1.0.0',
|
|
47
|
+
versioning: {
|
|
48
|
+
enable: true,
|
|
49
|
+
prefix: 'v',
|
|
50
|
+
version: '1',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
file: {
|
|
54
|
+
audio: { maxFileSize: 10485760 },
|
|
55
|
+
excel: { maxFileSize: 10485760 },
|
|
56
|
+
image: { maxFileSize: 10485760 },
|
|
57
|
+
video: { maxFileSize: 10485760 },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
true,
|
|
61
|
+
);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Cosa registra
|
|
65
|
+
|
|
66
|
+
- `ValidationPipe` globale con `Api422ValidationError`
|
|
67
|
+
- `RequestTimeoutInterceptor` globale
|
|
68
|
+
- `ThrottlerGuard` globale
|
|
69
|
+
- middleware per helmet, request id, body parser, cors, version, user-agent, timestamp, timezone
|
|
70
|
+
|
|
71
|
+
## Decorator utili
|
|
72
|
+
|
|
73
|
+
- `RequestId()`
|
|
74
|
+
- `RequestTimestamp()`
|
|
75
|
+
- `RequestXTimestamp()`
|
|
76
|
+
- `RequestCustomLang()`
|
|
77
|
+
- `RequestUserAgent()`
|
|
78
|
+
- `Session()`
|
|
79
|
+
- `RequestParamGuard(...)`
|
|
80
|
+
- `RequestValidateUserAgent()`
|
|
81
|
+
- `RequestValidateTimestamp()`
|
|
82
|
+
- `RequestTimeout('30s')`
|
|
83
|
+
|
|
84
|
+
Esempio:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
@Get()
|
|
88
|
+
@RequestValidateTimestamp()
|
|
89
|
+
list(@RequestId() requestId: string) {}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Validator custom
|
|
93
|
+
|
|
94
|
+
Il package espone validator riusabili come:
|
|
95
|
+
|
|
96
|
+
- password weak/medium/strong
|
|
97
|
+
- only digits
|
|
98
|
+
- safe string
|
|
99
|
+
- max/min date rispetto a oggi
|
|
100
|
+
- max/min greater than
|
|
101
|
+
- max binary file per tipo
|
|
102
|
+
|
|
103
|
+
## Note operative
|
|
104
|
+
|
|
105
|
+
- Gli endpoint SSE vengono esclusi dal timeout globale.
|
|
106
|
+
- I metadati raccolti qui vengono poi usati da `response` ed `error-handler`.
|
|
107
|
+
|
|
108
|
+
## Sviluppo
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
nx build request
|
|
112
|
+
nx test request
|
|
113
|
+
```
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tc-libs/request",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@tc-libs/service": "3.6.
|
|
6
|
-
"@tc-libs/errors": "3.6.
|
|
7
|
-
"@tc-libs/helper": "3.6.
|
|
8
|
-
"@tc-libs/pagination": "3.6.
|
|
9
|
-
"@tc-libs/constant": "3.6.
|
|
5
|
+
"@tc-libs/service": "3.6.1",
|
|
6
|
+
"@tc-libs/errors": "3.6.1",
|
|
7
|
+
"@tc-libs/helper": "3.6.1",
|
|
8
|
+
"@tc-libs/pagination": "3.6.1",
|
|
9
|
+
"@tc-libs/constant": "3.6.1",
|
|
10
10
|
"@nestjs/common": "^11.0.12",
|
|
11
11
|
"mongoose": "^8.13.1",
|
|
12
12
|
"class-transformer": "^0.5.1",
|