raiton 6.5.0-beta.13 → 6.7.0-beta.15
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 +31 -0
- package/README.md +16 -9
- package/build/bin/index.mjs +10288 -6059
- package/deno.json +4 -1
- package/docs/contributors/framework/README.md +2 -0
- package/docs/contributors/framework/cache/README.md +55 -0
- package/docs/contributors/framework/cache/cache.md +86 -0
- package/docs/contributors/framework/cache/etag.md +82 -0
- package/docs/contributors/framework/decorators/README.md +1 -0
- package/docs/contributors/framework/plugins/csrf.md +277 -0
- package/docs/contributors/framework/plugins/security.md +40 -6
- package/docs/contributors/framework/runtime.md +13 -3
- package/docs/user-guide/README.md +8 -4
- package/docs/user-guide/best-practices.md +1 -0
- package/docs/user-guide/cache.md +79 -0
- package/docs/user-guide/cli.md +35 -3
- package/docs/user-guide/csrf.md +557 -0
- package/docs/user-guide/decorators/README.md +3 -0
- package/docs/user-guide/decorators/cache.md +79 -0
- package/docs/user-guide/decorators/health-check.md +125 -0
- package/docs/user-guide/health-check.md +117 -0
- package/docs/user-guide/runtime.md +2 -1
- package/docs/user-guide/security.md +8 -2
- package/package.json +8 -3
- package/source/bin/bootstrapper.ts +4 -4
- package/source/bin/cli-tools.ts +27 -3
- package/source/bin/cli.ts +2 -2
- package/source/bin/commands.registry.ts +17 -0
- package/source/bin/constants.ts +1 -0
- package/source/bin/index.ts +2 -2
- package/source/commands/artifact.command.ts +2 -2
- package/source/commands/build.command.ts +2 -2
- package/source/commands/develop.command.ts +4 -5
- package/source/commands/grafts.command.ts +1 -1
- package/source/commands/start.command.ts +2 -2
- package/source/core/application.ts +10 -10
- package/source/core/artifacts/artifact.ts +1 -1
- package/source/core/artifacts/index.ts +1 -1
- package/source/core/builder.ts +69 -15
- package/source/core/bytes.util.ts +1 -1
- package/source/core/commands.ts +24 -14
- package/source/core/config/config.ts +2 -2
- package/source/core/config/define.ts +2 -2
- package/source/core/config/index.ts +2 -2
- package/source/core/context.ts +1 -1
- package/source/core/controller/builder.ts +31 -8
- package/source/core/controller/compiler.ts +6 -6
- package/source/core/controller/index.ts +4 -4
- package/source/core/controller/metadata.ts +2 -2
- package/source/core/controller/tracker.ts +1 -1
- package/source/core/directories.ts +3 -2
- package/source/core/guards.ts +1 -1
- package/source/core/helpers/index.ts +1 -1
- package/source/core/hooks.ts +1 -1
- package/source/core/index.ts +16 -16
- package/source/core/injection/index.ts +1 -1
- package/source/core/injection/injection.ts +3 -3
- package/source/core/mcp/builder.ts +8 -8
- package/source/core/mcp/index.ts +3 -3
- package/source/core/mcp/metadata.ts +2 -2
- package/source/core/mcp/tracker.ts +1 -1
- package/source/core/middleware/compose.ts +2 -2
- package/source/core/middleware/index.ts +2 -2
- package/source/core/middleware/pipeline.ts +2 -2
- package/source/core/plugins/index.ts +2 -2
- package/source/core/plugins/plugin.ts +1 -1
- package/source/core/plugins/scope.ts +4 -4
- package/source/core/raiton.ts +1 -1
- package/source/core/router/handler.ts +30 -6
- package/source/core/router/handler.utils.ts +3 -3
- package/source/core/router/index.ts +4 -4
- package/source/core/router/matcher.ts +1 -1
- package/source/core/router/route.ts +1 -1
- package/source/core/router/router.ts +4 -4
- package/source/core/server.ts +1 -1
- package/source/core/socket/builder.ts +2 -2
- package/source/core/socket/index.ts +2 -2
- package/source/core/socket/metadata.ts +2 -2
- package/source/core/thread.ts +53 -20
- package/source/framework/artifacts.ts +8 -5
- package/source/framework/cache/cache.decorator.ts +35 -0
- package/source/framework/cache/cache.ts +197 -0
- package/source/framework/cache/etag.ts +174 -0
- package/source/framework/cache/index.ts +4 -0
- package/source/framework/cache/types.ts +111 -0
- package/source/framework/constants/decorators.constant.ts +4 -0
- package/source/framework/constants/index.ts +2 -2
- package/source/framework/decorators/access-guard.decorator.ts +2 -2
- package/source/framework/decorators/api-response.decorator.ts +1 -1
- package/source/framework/decorators/api.decorator.ts +1 -1
- package/source/framework/decorators/controllable.decorator.ts +3 -3
- package/source/framework/decorators/csrf-guard.decorator.ts +60 -0
- package/source/framework/decorators/csrf-token.decorator.ts +20 -0
- package/source/framework/decorators/guard.decorator.ts +4 -4
- package/source/framework/decorators/health-check.decorator.ts +50 -0
- package/source/framework/decorators/index.ts +14 -11
- package/source/framework/decorators/injection.decorator.ts +3 -3
- package/source/framework/decorators/mcp.decorator.ts +4 -4
- package/source/framework/decorators/middleware.decorator.ts +2 -2
- package/source/framework/decorators/parametrable.decorator.ts +2 -2
- package/source/framework/decorators/routable.decorator.ts +3 -3
- package/source/framework/decorators/route-interaction.decorator.ts +4 -4
- package/source/framework/decorators/socket.decorator.ts +3 -3
- package/source/framework/encryption.ts +2 -2
- package/source/framework/enums/csrf.enum.ts +4 -0
- package/source/framework/enums/index.ts +8 -7
- package/source/framework/enums/runtime.enum.ts +1 -2
- package/source/framework/env.ts +2 -2
- package/source/framework/exceptions/http-exception.ts +3 -3
- package/source/framework/exceptions/index.ts +2 -2
- package/source/framework/health-check.ts +137 -0
- package/source/framework/index.ts +18 -16
- package/source/framework/mcp/handler.ts +3 -3
- package/source/framework/mcp/index.ts +3 -3
- package/source/framework/mcp/protocol.ts +1 -1
- package/source/framework/mcp/streamable-http.ts +3 -3
- package/source/framework/parameter-bag.ts +2 -2
- package/source/framework/plugins/body-parser.plugin.ts +3 -3
- package/source/framework/plugins/index.ts +4 -4
- package/source/framework/plugins/mcp.plugin.ts +5 -5
- package/source/framework/plugins/openapi.plugin.ts +4 -4
- package/source/framework/plugins/security/body-limit.ts +3 -3
- package/source/framework/plugins/security/cors.ts +2 -2
- package/source/framework/plugins/security/csrf.ts +145 -0
- package/source/framework/plugins/security/headers.ts +2 -2
- package/source/framework/plugins/security/index.ts +7 -5
- package/source/framework/plugins/security/method-guard.ts +3 -3
- package/source/framework/plugins/security/rate-limit.ts +3 -3
- package/source/framework/repositories.ts +1 -1
- package/source/framework/responses/error.ts +2 -2
- package/source/framework/responses/helpers.ts +3 -3
- package/source/framework/responses/http-throwable.ts +3 -3
- package/source/framework/responses/http.ts +3 -3
- package/source/framework/responses/index.ts +4 -4
- package/source/framework/runtime/bun/server.ts +5 -5
- package/source/framework/runtime/deno/server.ts +156 -96
- package/source/framework/runtime/index.ts +11 -17
- package/source/framework/runtime/node/reply.ts +1 -1
- package/source/framework/runtime/node/request.ts +2 -2
- package/source/framework/runtime/node/server.ts +3 -3
- package/source/framework/runtime/web/server.ts +2 -2
- package/source/framework/services.ts +1 -1
- package/source/framework/utilities/artifact.util.ts +4 -0
- package/source/framework/utilities/csrf.util.ts +162 -0
- package/source/framework/utilities/index.ts +10 -9
- package/source/framework/utilities/openapi.utils.ts +7 -7
- package/source/framework/utilities/utilities.util.ts +1 -1
- package/source/types/application.ts +2 -2
- package/source/types/builder.ts +1 -1
- package/source/types/config.ts +1 -1
- package/source/types/controller.ts +3 -3
- package/source/types/core.ts +1 -1
- package/source/types/csrf.ts +38 -0
- package/source/types/guard.ts +1 -1
- package/source/types/http-responses.ts +1 -1
- package/source/types/index.ts +26 -25
- package/source/types/injection.ts +1 -1
- package/source/types/middleware.ts +1 -1
- package/source/types/plugin.ts +1 -1
- package/source/types/raiton.ts +1 -1
- package/source/types/responses.ts +2 -2
- package/source/types/router.ts +2 -2
- package/source/types/runtime.ts +3 -5
- package/source/types/thread.ts +4 -4
- /package/source/framework/utilities/{https.ts → https.util.ts} +0 -0
- /package/source/framework/utilities/{url.ts → url.util.ts} +0 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# `@HealthCheck()`
|
|
2
|
+
|
|
3
|
+
> **Navigation :** [← route-interaction](route-interaction.md) | [README →](README.md)
|
|
4
|
+
|
|
5
|
+
`@HealthCheck()` qualifie un endpoint de contrôleur comme **health-check**. Il marque la méthode avec des métadonnées (`path`, `tags`, `summary`, …) et, combiné à un décorateur de route (`@Get`, `@Post`, …), enregistre le endpoint personnalisé.
|
|
6
|
+
|
|
7
|
+
Si vous ne définissez **aucun** health-check, Raiton en fournit un **par défaut** sur `GET /health`.
|
|
8
|
+
|
|
9
|
+
## Pourquoi utilisé
|
|
10
|
+
|
|
11
|
+
- exposer un point de contrôle pour les sondes d'infrastructure (load balancer, orchestrateur, « liveness » / « readiness »)
|
|
12
|
+
- centraliser les vérifications de dépendances (base de données, cache, services externes)
|
|
13
|
+
- qualifier clairement une méthode comme endpoint de santé dans le code
|
|
14
|
+
|
|
15
|
+
## Comment l'utiliser
|
|
16
|
+
|
|
17
|
+
- placez `@HealthCheck()` sur la méthode d'un contrôleur
|
|
18
|
+
- combinez-le avec un décorateur de route pour définir le chemin réel
|
|
19
|
+
- personnalisez la réponse globale avec `HealthCheckManager.configure(...)`
|
|
20
|
+
- ajoutez des vérifications personnalisées avec `checks`
|
|
21
|
+
|
|
22
|
+
## Exemple
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { Controllable, Get, HealthCheck, HttpStatus, RaitonResponses } from "raiton/framework"
|
|
26
|
+
|
|
27
|
+
@Controllable()
|
|
28
|
+
export class HealthController {
|
|
29
|
+
@Get("/health")
|
|
30
|
+
@HealthCheck({ summary: "État de l'application" })
|
|
31
|
+
check() {
|
|
32
|
+
return RaitonResponses(
|
|
33
|
+
"Service is healthy",
|
|
34
|
+
{ status: "healthy" },
|
|
35
|
+
HttpStatus.OK,
|
|
36
|
+
{ error: false }
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Health-check par défaut
|
|
43
|
+
|
|
44
|
+
Si aucun contrôleur ne définit de health-check, Raiton enregistre automatiquement `GET /health` après le scan des contrôleurs. Il renvoie :
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"statusCode": 200,
|
|
49
|
+
"message": "Service is healthy",
|
|
50
|
+
"data": {
|
|
51
|
+
"status": "healthy",
|
|
52
|
+
"timestamp": "2026-09-03T12:00:00.000Z",
|
|
53
|
+
"uptime": 42.1,
|
|
54
|
+
"version": "0.0.0"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Dès que vous définissez votre propre endpoint sur le même chemin, le défaut est remplacé.
|
|
60
|
+
|
|
61
|
+
## Options de `@HealthCheck()`
|
|
62
|
+
|
|
63
|
+
| Option | Type | défaut | Description |
|
|
64
|
+
| ------ | ---- | ------ | ----------- |
|
|
65
|
+
| `path` | `string` | `/health` | chemin du endpoint |
|
|
66
|
+
| `tags` | `string[]` | `['Health']` | tags pour la documentation |
|
|
67
|
+
| `summary` | `string` | – | résumé du endpoint |
|
|
68
|
+
| `description` | `string` | – | description détaillée |
|
|
69
|
+
| `excludeFromDocs` | `boolean` | `false` | exclure de la documentation |
|
|
70
|
+
|
|
71
|
+
## Configuration globale
|
|
72
|
+
|
|
73
|
+
`HealthCheckManager` permet de configurer le comportement par défaut.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
import { HealthCheckManager, HttpStatus } from "raiton/framework"
|
|
77
|
+
|
|
78
|
+
HealthCheckManager.configure({
|
|
79
|
+
path: "/health",
|
|
80
|
+
response: {
|
|
81
|
+
statusCode: HttpStatus.OK,
|
|
82
|
+
message: "All systems operational"
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Vérifications personnalisées
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
HealthCheckManager.configure({
|
|
91
|
+
checks: [
|
|
92
|
+
{
|
|
93
|
+
name: "database",
|
|
94
|
+
check: async () => {
|
|
95
|
+
// testez votre connexion
|
|
96
|
+
return { status: "healthy" as const }
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "cache",
|
|
101
|
+
check: async () => ({ status: "degraded" as const, message: "cache partiellement disponible" })
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Les résultats des vérifications sont agrégés dans `data.checks`. Le statut global est :
|
|
108
|
+
- `unhealthy` si au moins une vérification échoue (code `503 Service Unavailable`)
|
|
109
|
+
- `degraded` sinon
|
|
110
|
+
- `healthy` par défaut (code `200`)
|
|
111
|
+
|
|
112
|
+
## Avantages
|
|
113
|
+
|
|
114
|
+
- aucun code à écrire pour disposer d'un point de contrôle
|
|
115
|
+
- personnalisable par contrôleur ou globalement
|
|
116
|
+
- se combine naturellement avec les routes existantes
|
|
117
|
+
|
|
118
|
+
## Inconvénients
|
|
119
|
+
|
|
120
|
+
- le health-check par défaut reste minimal (uptime/version) tant que vous n'ajoutez pas de `checks`
|
|
121
|
+
- le statut global dépend de la qualité de vos vérifications
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
[← route-interaction](route-interaction.md) | [README →](README.md)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Health-check
|
|
2
|
+
|
|
3
|
+
> **Navigation :** [← security](security.md) | [https →](https.md)
|
|
4
|
+
|
|
5
|
+
Les health-checks permettent d'exposer un endpoint de contrôle pour les sondes d'infrastructure (load balancer, orchestrateur, « liveness » / « readiness »). Raiton fournit un endpoint **par défaut** et vous permet de le **personnaliser** grâce à `@HealthCheck()` et `HealthCheckManager`.
|
|
6
|
+
|
|
7
|
+
## Endpoint par défaut
|
|
8
|
+
|
|
9
|
+
Sans aucune configuration, Raiton enregistre automatiquement `GET /health` **après** le scan des contrôleurs.
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"statusCode": 200,
|
|
14
|
+
"message": "Service is healthy",
|
|
15
|
+
"data": {
|
|
16
|
+
"status": "healthy",
|
|
17
|
+
"timestamp": "2026-09-03T12:00:00.000Z",
|
|
18
|
+
"uptime": 42.1,
|
|
19
|
+
"version": "0.0.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Dès que vous définissez votre propre health-check, le défaut est remplacé.
|
|
25
|
+
|
|
26
|
+
## Définir un health-check personnalisé
|
|
27
|
+
|
|
28
|
+
Utilisez `@HealthCheck()` sur une méthode combinée à un décorateur de route.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Controllable, Get, HealthCheck, HttpStatus, RaitonResponses } from "raiton/framework"
|
|
32
|
+
|
|
33
|
+
@Controllable()
|
|
34
|
+
export class HealthController {
|
|
35
|
+
@Get("/health")
|
|
36
|
+
@HealthCheck({ summary: "État de l'application" })
|
|
37
|
+
check() {
|
|
38
|
+
return RaitonResponses(
|
|
39
|
+
"Service is healthy",
|
|
40
|
+
{ status: "healthy" },
|
|
41
|
+
HttpStatus.OK,
|
|
42
|
+
{ error: false }
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Vous pouvez renvoyer un code `503 Service Unavailable` dans le cas où l'application est en mauvaise santé.
|
|
49
|
+
|
|
50
|
+
## Configurer le comportement par défaut
|
|
51
|
+
|
|
52
|
+
`HealthCheckManager.configure(...)` agit sur le health-check par défaut (et sur les sauts de middleware applicables).
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { HealthCheckManager, HttpStatus } from "raiton/framework"
|
|
56
|
+
|
|
57
|
+
HealthCheckManager.configure({
|
|
58
|
+
path: "/health",
|
|
59
|
+
response: {
|
|
60
|
+
statusCode: HttpStatus.OK,
|
|
61
|
+
message: "All systems operational"
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Vérifications personnalisées
|
|
67
|
+
|
|
68
|
+
Ajoutez des vérifications de dépendances pour enrichir la réponse.
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
HealthCheckManager.configure({
|
|
72
|
+
checks: [
|
|
73
|
+
{
|
|
74
|
+
name: "database",
|
|
75
|
+
check: async () => {
|
|
76
|
+
// testez votre connexion
|
|
77
|
+
return { status: "healthy" as const }
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: "cache",
|
|
82
|
+
check: async () => ({ status: "degraded" as const, message: "cache partiellement disponible" })
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Les résultats sont agrégés dans `data.checks`. Le statut global est :
|
|
89
|
+
- `unhealthy` si au moins une vérification échoue (code `503`)
|
|
90
|
+
- `degraded` sinon
|
|
91
|
+
- `healthy` par défaut (code `200`)
|
|
92
|
+
|
|
93
|
+
### Handler entièrement personnalisé
|
|
94
|
+
|
|
95
|
+
`registerCustomHandler` remplace entièrement la logique de réponse du health-check par défaut.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
HealthCheckManager.registerCustomHandler((ctx) => {
|
|
99
|
+
return { ok: true, memory: process.memoryUsage() }
|
|
100
|
+
})
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Types et options
|
|
104
|
+
|
|
105
|
+
- `HealthCheckManager.configure(config)` : `path`, `response` (`statusCode`, `message`), `checks`.
|
|
106
|
+
- `@HealthCheck(options)` : `path`, `tags`, `summary`, `description`, `excludeFromDocs`.
|
|
107
|
+
- `HealthCheckCheck` : `{ name, check }` où `check` renvoie `{ status, message? }`.
|
|
108
|
+
|
|
109
|
+
## Bon usage
|
|
110
|
+
|
|
111
|
+
- garder le endpoint de santé léger et sans logique métier lourde
|
|
112
|
+
- utiliser `checks` pour les dépendances critiques (base de données, cache)
|
|
113
|
+
- renvoyer `503` quand l'application ne peut plus traiter de requêtes
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
[← security](security.md) | [https →](https.md)
|
|
@@ -21,13 +21,14 @@ return await thread.setup({
|
|
|
21
21
|
## Pourquoi utilisé
|
|
22
22
|
|
|
23
23
|
- choisir explicitement l’environnement d’exécution
|
|
24
|
-
- garder un point d’entrée unique pour Bun et
|
|
24
|
+
- garder un point d’entrée unique pour Bun, Node et Deno
|
|
25
25
|
|
|
26
26
|
## Comment l’utiliser
|
|
27
27
|
|
|
28
28
|
- laissez Raiton détecter le runtime si vous ne souhaitez rien imposer
|
|
29
29
|
- forcez `RuntimeType.Bun` si vous ciblez Bun en priorité
|
|
30
30
|
- utilisez `RuntimeType.Node` si vous visez un exécutable Node
|
|
31
|
+
- utilisez `RuntimeType.Deno` si vous exécutez l’application avec Deno
|
|
31
32
|
|
|
32
33
|
## Avantages
|
|
33
34
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Sécurité
|
|
2
2
|
|
|
3
|
-
> **Navigation :** [← body-parser](body-parser.md) | [
|
|
3
|
+
> **Navigation :** [← body-parser](body-parser.md) | [csrf →](csrf.md)
|
|
4
4
|
|
|
5
5
|
Les plugins de sécurité servent à protéger une API exposée publiquement.
|
|
6
6
|
|
|
@@ -8,6 +8,7 @@ Les plugins de sécurité servent à protéger une API exposée publiquement.
|
|
|
8
8
|
|
|
9
9
|
- `Security.headers()`
|
|
10
10
|
- `Security.cors()`
|
|
11
|
+
- `Security.csrf()` — [Documentation complète](csrf.md)
|
|
11
12
|
- `Security.rateLimit()`
|
|
12
13
|
- `Security.bodyLimit()`
|
|
13
14
|
- `Security.methodGuard()`
|
|
@@ -19,6 +20,7 @@ app.register({
|
|
|
19
20
|
plugins: [
|
|
20
21
|
Security.headers(),
|
|
21
22
|
Security.cors({ origin: "*" }),
|
|
23
|
+
Security.csrf({ mode: CSRFModeEnum.DOUBLE_SUBMIT, secret: process.env.CSRF_SECRET }),
|
|
22
24
|
Security.rateLimit({ max: 100, windowMs: 60000 }),
|
|
23
25
|
Security.bodyLimit(1_000_000)
|
|
24
26
|
]
|
|
@@ -30,17 +32,21 @@ app.register({
|
|
|
30
32
|
- réduire les abus
|
|
31
33
|
- contrôler les origines autorisées
|
|
32
34
|
- limiter la taille des payloads
|
|
35
|
+
- protéger contre les attaques CSRF (Cross-Site Request Forgery)
|
|
33
36
|
|
|
34
37
|
## Avantages
|
|
35
38
|
|
|
36
39
|
- facile à activer
|
|
37
40
|
- couvre plusieurs protections de base
|
|
41
|
+
- CSRF supporte le mode stateless (double-submit) et stateful (synchronizer)
|
|
42
|
+
- détection automatique des clients mobile/desktop
|
|
38
43
|
|
|
39
44
|
## Inconvénients
|
|
40
45
|
|
|
41
46
|
- `rateLimit()` est en mémoire, donc non distribué
|
|
42
47
|
- `cors()` doit être configuré selon le contexte réel
|
|
48
|
+
- `csrf()` nécessite une configuration côté client pour les navigateurs
|
|
43
49
|
|
|
44
50
|
---
|
|
45
51
|
|
|
46
|
-
[← body-parser](body-parser.md) | [
|
|
52
|
+
[← body-parser](body-parser.md) | [csrf →](csrf.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "raiton",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.0-beta.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Modular TypeScript Backend Framework with Dependency Injection, Plugins, Controllers, Middleware and Hot Reloading.",
|
|
@@ -37,9 +37,14 @@
|
|
|
37
37
|
"./types/*": "./source/types/*.ts"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
|
-
"dev": "bun run --hot source/bin/index.ts",
|
|
41
|
-
"
|
|
40
|
+
"dev": "bun run --hot source/bin/index.ts dev",
|
|
41
|
+
"dev:node": "node build/bin/index.mjs dev",
|
|
42
|
+
"dev:deno": "deno task dev",
|
|
42
43
|
"build": "bun build source/bin/index.ts --target=node --format=esm --outfile=build/bin/index.mjs",
|
|
44
|
+
"start": "bun run source/bin/index.ts start",
|
|
45
|
+
"start:node": "node build/bin/index.mjs start",
|
|
46
|
+
"start:deno": "deno task start",
|
|
47
|
+
"compile:deno": "deno task compile",
|
|
43
48
|
"version": "bun run scripts/update-version.ts",
|
|
44
49
|
"postinstall": "bun run scripts/postinstall.js",
|
|
45
50
|
"prepublishOnly": "npm run build"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Command} from 'commander';
|
|
2
|
-
import {RaitonCommands, RaitonConfig} from "../core";
|
|
3
|
-
import {getPackageRoot} from "../framework";
|
|
4
|
-
import {CliTools} from "./cli-tools";
|
|
2
|
+
import {RaitonCommands, RaitonConfig} from "../core/index.ts";
|
|
3
|
+
import {getPackageRoot} from "../framework/index.ts";
|
|
4
|
+
import {CliTools} from "./cli-tools.ts";
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export default async function bootstrapper(cli: Command) {
|
|
@@ -11,5 +11,5 @@ export default async function bootstrapper(cli: Command) {
|
|
|
11
11
|
|
|
12
12
|
await RaitonConfig.sync(workdir);
|
|
13
13
|
await capabilities.harvest();
|
|
14
|
-
return cli.parse(
|
|
14
|
+
return cli.parse(CliTools.argv)
|
|
15
15
|
}
|
package/source/bin/cli-tools.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference types="deno" />
|
|
2
2
|
import {spawn} from 'node:child_process';
|
|
3
|
-
import
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import {isBunUsed, isDenoUsed, isNodeUsed} from "./constants.ts";
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
export class CliTools {
|
|
@@ -8,6 +10,20 @@ export class CliTools {
|
|
|
8
10
|
return `${isDenoUsed ? (globalThis as any).Deno.cwd() : process.cwd()}`;
|
|
9
11
|
}
|
|
10
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Resolve the runtime-appropriate CLI entry point.
|
|
15
|
+
* - Node: `build/bin/index.mjs` (compiled bundle)
|
|
16
|
+
* - Bun / Deno: `bin/index.ts` (native TypeScript execution)
|
|
17
|
+
*/
|
|
18
|
+
static cliEntry(appdir: string): string {
|
|
19
|
+
if (isNodeUsed) {
|
|
20
|
+
const built = path.join(appdir, 'build', 'bin', 'index.mjs');
|
|
21
|
+
if (fs.existsSync(built)) return built;
|
|
22
|
+
return path.join(appdir, 'bin', 'index.mjs');
|
|
23
|
+
}
|
|
24
|
+
return path.join(appdir, 'bin', 'index.ts');
|
|
25
|
+
}
|
|
26
|
+
|
|
11
27
|
static set cwd(value: string) {
|
|
12
28
|
if (isDenoUsed) {
|
|
13
29
|
(globalThis as any).Deno.chdir(value);
|
|
@@ -18,7 +34,7 @@ export class CliTools {
|
|
|
18
34
|
|
|
19
35
|
static get argv() {
|
|
20
36
|
if (isBunUsed) return (globalThis as any).Bun.argv;
|
|
21
|
-
if (isDenoUsed) return (globalThis as any).Deno.args;
|
|
37
|
+
if (isDenoUsed) return [globalThis, 'run', ...(globalThis as any).Deno.args];
|
|
22
38
|
return process.argv;
|
|
23
39
|
}
|
|
24
40
|
|
|
@@ -62,7 +78,15 @@ export class CliTools {
|
|
|
62
78
|
const cmdArgs = typeof command == 'string' ? args : [...command.slice(1), ...args];
|
|
63
79
|
|
|
64
80
|
if (cmd.endsWith('.ts')) {
|
|
65
|
-
|
|
81
|
+
const entry = CliTools.cliEntry(path.resolve(cmd, '..', '..'));
|
|
82
|
+
if (fs.existsSync(entry)) {
|
|
83
|
+
return spawn('node', [entry, ...cmdArgs], options);
|
|
84
|
+
}
|
|
85
|
+
return spawn('node', [cmd, ...cmdArgs], options);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (cmd.endsWith('.mjs') || cmd.endsWith('.js') || cmd.endsWith('.cjs')) {
|
|
89
|
+
return spawn('node', [cmd, ...cmdArgs], options);
|
|
66
90
|
}
|
|
67
91
|
|
|
68
92
|
return spawn(cmd, cmdArgs, options);
|
package/source/bin/cli.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {Command} from "commander";
|
|
2
|
-
import
|
|
2
|
+
import pkg from '../../package.json' with {type: "json"};
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const CLI = new Command();
|
|
@@ -7,6 +7,6 @@ const CLI = new Command();
|
|
|
7
7
|
CLI
|
|
8
8
|
.name('raiton')
|
|
9
9
|
.description('Protorians Raiton framework for backend microservice')
|
|
10
|
-
.version(version);
|
|
10
|
+
.version(pkg.version);
|
|
11
11
|
|
|
12
12
|
export default CLI;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import ArtifactCommand from "../commands/artifact.command.ts";
|
|
2
|
+
import BuildCommand from "../commands/build.command.ts";
|
|
3
|
+
import DevelopCommand from "../commands/develop.command.ts";
|
|
4
|
+
import GraftsCommand from "../commands/grafts.command.ts";
|
|
5
|
+
import StartCommand from "../commands/start.command.ts";
|
|
6
|
+
import type {Command} from "commander";
|
|
7
|
+
import type {RaitonCommand} from "../core/index.ts";
|
|
8
|
+
|
|
9
|
+
export type RaitonCommandConstructor = new (cli: Command, workdir: string, appdir: string) => RaitonCommand;
|
|
10
|
+
|
|
11
|
+
export const RaitonCommandsRegistry: RaitonCommandConstructor[] = [
|
|
12
|
+
ArtifactCommand,
|
|
13
|
+
BuildCommand,
|
|
14
|
+
DevelopCommand,
|
|
15
|
+
GraftsCommand,
|
|
16
|
+
StartCommand,
|
|
17
|
+
];
|
package/source/bin/constants.ts
CHANGED
package/source/bin/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {RaitonCommand, RaitonBuilder} from "../core";
|
|
1
|
+
import {RaitonCommand, RaitonBuilder} from "../core/index.ts";
|
|
2
2
|
import {Logger} from "@protorians/logger";
|
|
3
|
-
import type {BuildCommandOptionsInterface} from "../types";
|
|
3
|
+
import type {BuildCommandOptionsInterface} from "../types/index.ts";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export default class ArtifactCommand extends RaitonCommand {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {RaitonCommand, RaitonBuilder} from "../core";
|
|
1
|
+
import {RaitonCommand, RaitonBuilder} from "../core/index.ts";
|
|
2
2
|
import {LBadge, Logger} from "@protorians/logger";
|
|
3
|
-
import type {BuildCommandOptionsInterface} from "../types";
|
|
3
|
+
import type {BuildCommandOptionsInterface} from "../types/index.ts";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export default class BuildCommand extends RaitonCommand {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/// <reference types="deno" />
|
|
2
|
-
import {Raiton, RaitonCommand} from "../core";
|
|
2
|
+
import {Raiton, RaitonCommand} from "../core/index.ts";
|
|
3
3
|
import {ChildProcess, ChildProcessWithoutNullStreams} from 'node:child_process';
|
|
4
4
|
import {Logger} from "@protorians/logger";
|
|
5
|
-
import {EventMessageEnum} from "../framework";
|
|
6
|
-
import {CliTools} from "../bin/cli-tools";
|
|
7
|
-
import path from "node:path";
|
|
5
|
+
import {EventMessageEnum} from "../framework/index.ts";
|
|
6
|
+
import {CliTools} from "../bin/cli-tools.ts";
|
|
8
7
|
|
|
9
8
|
export default class DevelopCommand extends RaitonCommand {
|
|
10
9
|
public readonly name: string = 'develop';
|
|
@@ -32,7 +31,7 @@ export default class DevelopCommand extends RaitonCommand {
|
|
|
32
31
|
protected async run(): Promise<void> {
|
|
33
32
|
// Logger.info('Workdir', this.workdir);
|
|
34
33
|
|
|
35
|
-
const entryPoint =
|
|
34
|
+
const entryPoint = CliTools.cliEntry(this.appdir);
|
|
36
35
|
this.child = CliTools.spawn(entryPoint, ['build', '-d'], {
|
|
37
36
|
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
|
|
38
37
|
cwd: this.workdir
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="deno" />
|
|
2
|
-
import {RaitonBuilder, RaitonCommand} from "../core";
|
|
2
|
+
import {RaitonBuilder, RaitonCommand} from "../core/index.ts";
|
|
3
3
|
import {ChildProcess} from 'node:child_process';
|
|
4
4
|
import {LBadge, Logger} from "@protorians/logger";
|
|
5
|
-
import {StartCommandOptionsInterface} from "../types";
|
|
5
|
+
import {StartCommandOptionsInterface} from "../types/index.ts";
|
|
6
6
|
|
|
7
7
|
export default class StartCommand extends RaitonCommand {
|
|
8
8
|
public readonly name: string = 'start';
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {Security, bodyParserPlugin} from "../framework/plugins";
|
|
2
|
-
import {PluginScope} from './plugins/scope'
|
|
3
|
-
import {RequestContext} from './context'
|
|
4
|
-
import {ApplicationConfigInterface, ApplicationInterface} from "../types/application";
|
|
5
|
-
import {HttpException, HttpMethod, ThrowableResponse, RaitonResponses, HttpStatus} from "../framework";
|
|
6
|
-
import {RouteHandlerCallable} from "../types";
|
|
1
|
+
import {Security, bodyParserPlugin} from "../framework/plugins/index.ts";
|
|
2
|
+
import {PluginScope} from './plugins/scope.ts'
|
|
3
|
+
import {RequestContext} from './context.ts'
|
|
4
|
+
import {ApplicationConfigInterface, ApplicationInterface} from "../types/application.ts";
|
|
5
|
+
import {HttpException, HttpMethod, ThrowableResponse, RaitonResponses, HttpStatus} from "../framework/index.ts";
|
|
6
|
+
import {RouteHandlerCallable} from "../types/index.ts";
|
|
7
7
|
import {Logger} from "@protorians/logger";
|
|
8
|
-
import {RaitonConfig} from "./config";
|
|
9
|
-
import {Artifacts} from "../framework/artifacts";
|
|
10
|
-
import {Injection} from "./injection";
|
|
11
|
-
import {HttpsConfigInterface, resolveHttpsConfig} from "../framework/utilities/https";
|
|
8
|
+
import {RaitonConfig} from "./config/index.ts";
|
|
9
|
+
import {Artifacts} from "../framework/artifacts.ts";
|
|
10
|
+
import {Injection} from "./injection/index.ts";
|
|
11
|
+
import {HttpsConfigInterface, resolveHttpsConfig} from "../framework/utilities/https.util.ts";
|
|
12
12
|
|
|
13
13
|
export class Application implements ApplicationInterface {
|
|
14
14
|
private root: PluginScope
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./artifact";
|
|
1
|
+
export * from "./artifact.ts";
|