@roomi-fields/grillhouse 0.54.1 → 0.55.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/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +69 -0
- package/cadre/templates/projet/.github/workflows/ci.yml +4 -2
- package/cadre/templates/projet/.github/workflows/machine-vierge.yml +5 -42
- package/cadre/templates/projet/CONTRIBUTING.md +0 -5
- package/cadre/templates/projet/README.md +0 -126
- package/cadre/templates/projet/_npmignore +1 -6
- package/cadre/templates/projet/package.json +5 -32
- package/cadre/templates/projet/tsconfig.json +4 -4
- package/cadre/templates/projet/vitest.config.cjs +3 -2
- package/charte/tests.md +14 -0
- package/dist/machine/part-par-sorte.d.ts +9 -9
- package/dist/machine/part-par-sorte.js +20 -24
- package/dist/machine/part-par-sorte.js.map +1 -1
- package/dist/machine/table-des-consommations.d.ts +65 -0
- package/dist/machine/table-des-consommations.js +94 -0
- package/dist/machine/table-des-consommations.js.map +1 -0
- package/dist/temporal/circuit/activites.d.ts +2 -0
- package/dist/temporal/circuit/activites.js +87 -3
- package/dist/temporal/circuit/activites.js.map +1 -1
- package/dist/temporal/circuit/client.js +9 -4
- package/dist/temporal/circuit/client.js.map +1 -1
- package/dist/temporal/circuit/contrat.d.ts +32 -4
- package/dist/temporal/circuit/deroule.js +54 -4
- package/dist/temporal/circuit/deroule.js.map +1 -1
- package/dist/temporal/circuit/versions.d.ts +12 -0
- package/dist/temporal/circuit/versions.js +22 -0
- package/dist/temporal/circuit/versions.js.map +1 -0
- package/dist/temporal/consommation/activites.d.ts +2 -0
- package/dist/temporal/consommation/activites.js +9 -0
- package/dist/temporal/consommation/activites.js.map +1 -0
- package/dist/temporal/consommation/actualisation.d.ts +2 -0
- package/dist/temporal/consommation/actualisation.js +71 -0
- package/dist/temporal/consommation/actualisation.js.map +1 -0
- package/dist/temporal/consommation/client.d.ts +12 -0
- package/dist/temporal/consommation/client.js +28 -0
- package/dist/temporal/consommation/client.js.map +1 -0
- package/dist/temporal/consommation/commande.d.ts +5 -0
- package/dist/temporal/consommation/commande.js +32 -0
- package/dist/temporal/consommation/commande.js.map +1 -0
- package/dist/temporal/consommation/contrat.d.ts +15 -0
- package/dist/temporal/consommation/contrat.js +13 -0
- package/dist/temporal/consommation/contrat.js.map +1 -0
- package/dist/temporal/consommation/deroule.d.ts +2 -0
- package/dist/temporal/consommation/deroule.js +14 -0
- package/dist/temporal/consommation/deroule.js.map +1 -0
- package/dist/temporal/deroules.d.ts +2 -1
- package/dist/temporal/deroules.js +3 -2
- package/dist/temporal/deroules.js.map +1 -1
- package/dist/temporal/file/contrat.d.ts +2 -0
- package/dist/temporal/file/deroule.js +14 -4
- package/dist/temporal/file/deroule.js.map +1 -1
- package/dist/temporal/installation.d.ts +6 -0
- package/dist/temporal/installation.js +15 -0
- package/dist/temporal/installation.js.map +1 -1
- package/dist/temporal/nuits/activites.d.ts +2 -1
- package/dist/temporal/nuits/activites.js +127 -3
- package/dist/temporal/nuits/activites.js.map +1 -1
- package/dist/temporal/nuits/client.d.ts +19 -5
- package/dist/temporal/nuits/client.js +33 -23
- package/dist/temporal/nuits/client.js.map +1 -1
- package/dist/temporal/nuits/commande.js +16 -11
- package/dist/temporal/nuits/commande.js.map +1 -1
- package/dist/temporal/nuits/contrat.d.ts +29 -0
- package/dist/temporal/nuits/contrat.js +10 -0
- package/dist/temporal/nuits/contrat.js.map +1 -1
- package/dist/temporal/nuits/deroule.d.ts +5 -0
- package/dist/temporal/nuits/deroule.js +18 -1
- package/dist/temporal/nuits/deroule.js.map +1 -1
- package/dist/temporal/nuits/pc2.d.ts +72 -0
- package/dist/temporal/nuits/pc2.js +206 -0
- package/dist/temporal/nuits/pc2.js.map +1 -0
- package/dist/temporal/places/activites.d.ts +23 -1
- package/dist/temporal/places/activites.js +38 -2
- package/dist/temporal/places/activites.js.map +1 -1
- package/dist/temporal/places/client.d.ts +16 -0
- package/dist/temporal/places/client.js +25 -1
- package/dist/temporal/places/client.js.map +1 -1
- package/dist/temporal/places/contrat.d.ts +79 -14
- package/dist/temporal/places/contrat.js +7 -0
- package/dist/temporal/places/contrat.js.map +1 -1
- package/dist/temporal/places/deroule.js +159 -23
- package/dist/temporal/places/deroule.js.map +1 -1
- package/dist/temporal/places/reservation.d.ts +54 -0
- package/dist/temporal/places/reservation.js +69 -0
- package/dist/temporal/places/reservation.js.map +1 -0
- package/dist/temporal/planification.d.ts +6 -0
- package/dist/temporal/planification.js +26 -0
- package/dist/temporal/planification.js.map +1 -0
- package/dist/temporal/tickets/activites.d.ts +0 -2
- package/dist/temporal/tickets/activites.js +2 -52
- package/dist/temporal/tickets/activites.js.map +1 -1
- package/dist/temporal/tickets/contrat.d.ts +7 -26
- package/dist/temporal/tickets/deroule.js +35 -23
- package/dist/temporal/tickets/deroule.js.map +1 -1
- package/dist/temporal/travailleur.js +2 -0
- package/dist/temporal/travailleur.js.map +1 -1
- package/docs/ARCHITECTURE.md +2 -2
- package/docs/CADRE.md +1 -1
- package/docs/INTERFACE.md +16 -11
- package/docs/architecture/circuit.md +62 -58
- package/docs/architecture/entree.md +87 -63
- package/docs/architecture/greffon.md +24 -21
- package/docs/architecture/installation.md +35 -30
- package/docs/architecture/machine.md +48 -40
- package/docs/architecture/tests.md +37 -33
- package/docs/lexique.md +4 -3
- package/package.json +1 -1
- package/scripts/activites.mjs +351 -180
- package/scripts/aiguillage.mjs +1 -0
- package/scripts/attente-de-la-machine.mjs +3 -22
- package/scripts/avancement.mjs +21 -30
- package/scripts/bilan.mjs +22 -2
- package/scripts/branche-de-nuit.mjs +1 -1
- package/scripts/circuit.mjs +75 -39
- package/scripts/codes-de-sortie.mjs +0 -6
- package/scripts/consommation-des-passes.mjs +67 -31
- package/scripts/consommation.mjs +152 -24
- package/scripts/copies-finies.mjs +15 -35
- package/scripts/dernier-vert.mjs +4 -5
- package/scripts/dette.mjs +5 -3
- package/scripts/droits.mjs +2 -2
- package/scripts/echantillonneur-de-la-passe.mjs +7 -31
- package/scripts/engendres.mjs +5 -61
- package/scripts/enveloppe/enveloppe.mjs +30 -34
- package/scripts/enveloppe/travail-de-la-copie.mjs +5 -0
- package/scripts/etapes.mjs +21 -7
- package/scripts/etat-du-depot.mjs +61 -0
- package/scripts/faits-du-circuit.mjs +7 -4
- package/scripts/fermeture-de-la-machine.d.mts +6 -4
- package/scripts/fermeture-de-la-machine.mjs +12 -16
- package/scripts/fichier-du-poste.d.mts +9 -0
- package/scripts/file-des-tickets.d.mts +0 -18
- package/scripts/file-des-tickets.mjs +0 -42
- package/scripts/fusion-du-changelog.mjs +1 -1
- package/scripts/grillhouse-maj.mjs +1 -1
- package/scripts/index-des-rouges.d.mts +40 -0
- package/scripts/index-des-rouges.mjs +104 -0
- package/scripts/integration/file.mjs +13 -63
- package/scripts/integration/integrer.mjs +157 -424
- package/scripts/integration/jugement.mjs +109 -0
- package/scripts/integration/rejeu.mjs +94 -71
- package/scripts/jointure.d.ts +34 -27
- package/scripts/journal-des-etats.d.mts +1 -1
- package/scripts/langages/c/commandes.mjs +27 -12
- package/scripts/langages/cargo/commandes.mjs +148 -94
- package/scripts/langages/cargo/index.mjs +2 -1
- package/scripts/langages/cargo/lectures-des-tests.mjs +132 -0
- package/scripts/langages/cargo/migrations/lectures-des-tests.mjs +31 -0
- package/scripts/langages/python/commandes.mjs +31 -15
- package/scripts/langages/python/index.mjs +2 -1
- package/scripts/langages/python/lectures-des-tests.mjs +148 -0
- package/scripts/langages/python/migrations/lectures-des-tests.mjs +31 -0
- package/scripts/langages/typescript/consommateurs-arbitres.mjs +2 -2
- package/scripts/langages/typescript/index.mjs +4 -0
- package/scripts/langages/typescript/lectures-des-tests.mjs +95 -0
- package/scripts/langages/typescript/migrations/lectures-des-tests.mjs +31 -0
- package/scripts/langages/typescript/tests-de-nuit.mjs +9 -15
- package/scripts/langages/typescript/tests.mjs +11 -37
- package/scripts/langages/typescript/titres-de-tests.mjs +5 -4
- package/scripts/langages/typescript/verifier.mjs +74 -44
- package/scripts/langages/typescript/vitest-config/base.mjs +3 -3
- package/scripts/langages/typescript/vitest-config/machine.setup.mjs +6 -25
- package/scripts/lectures-communes.mjs +234 -0
- package/scripts/machine.mjs +11 -18
- package/scripts/mesure/base-de-passe.mjs +1 -2
- package/scripts/mesure-de-la-machine.d.mts +40 -3
- package/scripts/mesure-de-la-machine.mjs +201 -11
- package/scripts/migrations/0.33.0-ci-du-cadre.mjs +3 -3
- package/scripts/migrations/nuit-yml-retire.mjs +25 -0
- package/scripts/migrations/part-retiree.mjs +31 -0
- package/scripts/migrations.mjs +4 -0
- package/scripts/montee.mjs +9 -0
- package/scripts/nuit-de-pc2.mjs +628 -0
- package/scripts/nuit.sh +8 -131
- package/scripts/paquets.mjs +1 -1
- package/scripts/passe-de-la-machine.mjs +340 -103
- package/scripts/place-du-circuit.d.mts +15 -0
- package/scripts/place-du-circuit.mjs +32 -0
- package/scripts/places-de-la-machine.mjs +148 -626
- package/scripts/places-du-serveur.mjs +26 -13
- package/scripts/plafond-de-la-machine.d.mts +8 -13
- package/scripts/plafond-de-la-machine.mjs +26 -56
- package/scripts/registre-des-entrees.mjs +57 -0
- package/scripts/regles-des-places.d.mts +82 -50
- package/scripts/regles-des-places.mjs +192 -156
- package/scripts/retirer-copie.sh +2 -2
- package/scripts/seances.mjs +181 -63
- package/scripts/secours.mjs +95 -0
- package/scripts/services-du-noyau.mjs +11 -19
- package/scripts/sous-commandes.mjs +1 -0
- package/scripts/sous-modules.sh +1 -1
- package/scripts/superviseur.mjs +16 -7
- package/scripts/table-des-consommations.d.mts +9 -0
- package/scripts/table-des-consommations.mjs +35 -0
- package/scripts/tableau.mjs +33 -19
- package/scripts/taches-du-graphe.mjs +124 -2
- package/scripts/transitions.d.mts +27 -5
- package/scripts/transitions.mjs +122 -104
- package/scripts/verdict-de-la-nuit.d.mts +13 -0
- package/scripts/verdict-de-la-nuit.mjs +34 -7
- package/scripts/verrou-de-fichier.mjs +1 -2
- package/scripts/workflows-du-cadre.mjs +2 -2
- package/skills/developpeur/SKILL.md +8 -2
- package/skills/direct/SKILL.md +5 -0
- package/skills/explorateur/SKILL.md +10 -1
- package/skills/grill/SKILL.md +2 -4
- package/skills/pitmaster/SKILL.md +7 -5
- package/skills/pitmaster/references/consigne-agent.md +1 -1
- package/skills/relecteur/SKILL.md +4 -1
- package/skills/testwriter/SKILL.md +15 -2
- package/cadre/templates/projet/.env.example +0 -57
- package/cadre/templates/projet/.github/workflows/nuit.yml +0 -139
- package/cadre/templates/projet/deployment/README.md +0 -98
- package/cadre/templates/projet/deployment/docs/01-INSTALL.md +0 -145
- package/cadre/templates/projet/deployment/docs/02-CONFIGURATION.md +0 -117
- package/cadre/templates/projet/deployment/docs/03-API.md +0 -264
- package/cadre/templates/projet/deployment/docs/04-TROUBLESHOOTING.md +0 -262
- package/cadre/templates/projet/deployment/scripts/install.ps1 +0 -100
- package/cadre/templates/projet/deployment/scripts/start.ps1 +0 -61
- package/cadre/templates/projet/deployment/scripts/stop.ps1 +0 -37
- package/cadre/templates/projet/deployment/scripts/test.ps1 +0 -118
- package/cadre/templates/projet/ecosystem.config.cjs +0 -73
- package/cadre/templates/projet/src/config.ts +0 -68
- package/cadre/templates/projet/src/errors.ts +0 -102
- package/cadre/templates/projet/src/index.ts +0 -46
- package/cadre/templates/projet/src/services/.gitkeep +0 -8
- package/cadre/templates/projet/src/types/index.ts +0 -24
- package/cadre/templates/projet/src/utils/logger.ts +0 -106
- package/cadre/templates/projet/tests/unit/config.spec.ts +0 -68
- package/cadre/templates/projet/tests/unit/errors.spec.ts +0 -132
- package/cadre/templates/projet/tests/unit/types.spec.ts +0 -73
- package/cadre/templates/projet/tsconfig.build.json +0 -14
- package/scripts/flux-de-la-nuit.mjs +0 -39
- package/scripts/garde-de-la-memoire.mjs +0 -231
- package/scripts/repli-de-la-nuit.mjs +0 -184
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
<#
|
|
2
|
-
.SYNOPSIS
|
|
3
|
-
Test the application endpoints.
|
|
4
|
-
|
|
5
|
-
.DESCRIPTION
|
|
6
|
-
Runs basic tests against the running application.
|
|
7
|
-
|
|
8
|
-
.PARAMETER BaseUrl
|
|
9
|
-
Base URL of the application. Default: http://localhost:3000
|
|
10
|
-
|
|
11
|
-
.EXAMPLE
|
|
12
|
-
.\test.ps1
|
|
13
|
-
.\test.ps1 -BaseUrl "http://localhost:8080"
|
|
14
|
-
#>
|
|
15
|
-
|
|
16
|
-
param(
|
|
17
|
-
[string]$BaseUrl = "http://localhost:3000"
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
$ErrorActionPreference = "Continue"
|
|
21
|
-
|
|
22
|
-
function Write-Step {
|
|
23
|
-
param([string]$Message)
|
|
24
|
-
Write-Host "`n==> $Message" -ForegroundColor Cyan
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function Write-Success {
|
|
28
|
-
param([string]$Message)
|
|
29
|
-
Write-Host "[PASS] $Message" -ForegroundColor Green
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function Write-Fail {
|
|
33
|
-
param([string]$Message)
|
|
34
|
-
Write-Host "[FAIL] $Message" -ForegroundColor Red
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function Test-Endpoint {
|
|
38
|
-
param(
|
|
39
|
-
[string]$Name,
|
|
40
|
-
[string]$Method,
|
|
41
|
-
[string]$Url,
|
|
42
|
-
[string]$Body = $null,
|
|
43
|
-
[int]$ExpectedStatus = 200
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
Write-Host " Testing: $Name... " -NoNewline
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
$params = @{
|
|
50
|
-
Uri = $Url
|
|
51
|
-
Method = $Method
|
|
52
|
-
ContentType = "application/json"
|
|
53
|
-
UseBasicParsing = $true
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if ($Body) {
|
|
57
|
-
$params.Body = $Body
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
$response = Invoke-WebRequest @params
|
|
61
|
-
$status = $response.StatusCode
|
|
62
|
-
|
|
63
|
-
if ($status -eq $ExpectedStatus) {
|
|
64
|
-
Write-Host "[PASS]" -ForegroundColor Green
|
|
65
|
-
return $true
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
Write-Host "[FAIL] Expected $ExpectedStatus, got $status" -ForegroundColor Red
|
|
69
|
-
return $false
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch {
|
|
73
|
-
$status = $_.Exception.Response.StatusCode.value__
|
|
74
|
-
if ($status -eq $ExpectedStatus) {
|
|
75
|
-
Write-Host "[PASS]" -ForegroundColor Green
|
|
76
|
-
return $true
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
Write-Host "[FAIL] $($_.Exception.Message)" -ForegroundColor Red
|
|
80
|
-
return $false
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
Write-Host "API Endpoint Tests" -ForegroundColor Magenta
|
|
86
|
-
Write-Host "==================" -ForegroundColor Magenta
|
|
87
|
-
Write-Host "Base URL: $BaseUrl"
|
|
88
|
-
|
|
89
|
-
$passed = 0
|
|
90
|
-
$failed = 0
|
|
91
|
-
|
|
92
|
-
# Health Check
|
|
93
|
-
Write-Step "Health Check"
|
|
94
|
-
if (Test-Endpoint -Name "GET /health" -Method "GET" -Url "$BaseUrl/health") {
|
|
95
|
-
$passed++
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
$failed++
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
# Add more tests as needed
|
|
102
|
-
# Write-Step "API Endpoints"
|
|
103
|
-
# if (Test-Endpoint -Name "GET /api/resources" -Method "GET" -Url "$BaseUrl/api/resources") {
|
|
104
|
-
# $passed++
|
|
105
|
-
# } else {
|
|
106
|
-
# $failed++
|
|
107
|
-
# }
|
|
108
|
-
|
|
109
|
-
# Summary
|
|
110
|
-
Write-Host "`n" -NoNewline
|
|
111
|
-
Write-Host "Results" -ForegroundColor Magenta
|
|
112
|
-
Write-Host "=======" -ForegroundColor Magenta
|
|
113
|
-
Write-Host "Passed: $passed" -ForegroundColor Green
|
|
114
|
-
Write-Host "Failed: $failed" -ForegroundColor $(if ($failed -gt 0) { "Red" } else { "Green" })
|
|
115
|
-
|
|
116
|
-
if ($failed -gt 0) {
|
|
117
|
-
exit 1
|
|
118
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PM2 Ecosystem Configuration
|
|
3
|
-
*
|
|
4
|
-
* This file configures PM2 for running the application as a background daemon.
|
|
5
|
-
*
|
|
6
|
-
* Usage:
|
|
7
|
-
* npm run daemon:start - Start the daemon
|
|
8
|
-
* npm run daemon:stop - Stop the daemon
|
|
9
|
-
* npm run daemon:restart - Restart the daemon
|
|
10
|
-
* npm run daemon:logs - View logs
|
|
11
|
-
* npm run daemon:status - Check status
|
|
12
|
-
* npm run daemon:delete - Remove from PM2
|
|
13
|
-
*
|
|
14
|
-
* @see https://pm2.keymetrics.io/docs/usage/application-declaration/
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
module.exports = {
|
|
18
|
-
apps: [
|
|
19
|
-
{
|
|
20
|
-
// Application name (used in PM2 commands)
|
|
21
|
-
name: 'project-name',
|
|
22
|
-
|
|
23
|
-
// Entry point script
|
|
24
|
-
script: 'dist/index.js',
|
|
25
|
-
|
|
26
|
-
// Working directory
|
|
27
|
-
cwd: __dirname,
|
|
28
|
-
|
|
29
|
-
// Process mode: 'fork' for single instance, 'cluster' for multiple
|
|
30
|
-
exec_mode: 'fork',
|
|
31
|
-
instances: 1,
|
|
32
|
-
|
|
33
|
-
// Auto-restart configuration
|
|
34
|
-
autorestart: true,
|
|
35
|
-
watch: false,
|
|
36
|
-
max_memory_restart: '1G',
|
|
37
|
-
|
|
38
|
-
// Restart delay strategy
|
|
39
|
-
exp_backoff_restart_delay: 100,
|
|
40
|
-
max_restarts: 10,
|
|
41
|
-
restart_delay: 3000,
|
|
42
|
-
|
|
43
|
-
// Environment variables
|
|
44
|
-
env: {
|
|
45
|
-
NODE_ENV: 'production',
|
|
46
|
-
PORT: 3000
|
|
47
|
-
},
|
|
48
|
-
env_development: {
|
|
49
|
-
NODE_ENV: 'development',
|
|
50
|
-
PORT: 3000
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
// Logging configuration
|
|
54
|
-
log_date_format: 'YYYY-MM-DD HH:mm:ss',
|
|
55
|
-
error_file: 'logs/pm2-error.log',
|
|
56
|
-
out_file: 'logs/pm2-out.log',
|
|
57
|
-
merge_logs: true,
|
|
58
|
-
|
|
59
|
-
// Process identification
|
|
60
|
-
pid_file: 'logs/pm2.pid',
|
|
61
|
-
|
|
62
|
-
// Graceful shutdown
|
|
63
|
-
kill_timeout: 5000,
|
|
64
|
-
listen_timeout: 10000,
|
|
65
|
-
|
|
66
|
-
// Health monitoring
|
|
67
|
-
min_uptime: '10s',
|
|
68
|
-
|
|
69
|
-
// Node.js specific
|
|
70
|
-
node_args: '--enable-source-maps'
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Application configuration
|
|
3
|
-
*
|
|
4
|
-
* Centralizes all configuration from environment variables
|
|
5
|
-
* with sensible defaults for development.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { config as dotenvConfig } from 'dotenv';
|
|
9
|
-
import { z } from 'zod';
|
|
10
|
-
|
|
11
|
-
// Load environment variables
|
|
12
|
-
dotenvConfig();
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Environment configuration schema
|
|
16
|
-
*/
|
|
17
|
-
const envSchema = z.object({
|
|
18
|
-
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
|
19
|
-
PORT: z.string().transform(Number).default('3000'),
|
|
20
|
-
LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Parse and validate environment variables
|
|
25
|
-
*/
|
|
26
|
-
function parseEnv() {
|
|
27
|
-
const result = envSchema.safeParse(process.env);
|
|
28
|
-
|
|
29
|
-
if (!result.success) {
|
|
30
|
-
console.error('Invalid environment configuration:');
|
|
31
|
-
console.error(result.error.format());
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return result.data;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const env = parseEnv();
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Application configuration object
|
|
42
|
-
*/
|
|
43
|
-
export const config = {
|
|
44
|
-
/** Application version from package.json */
|
|
45
|
-
version: '1.0.0',
|
|
46
|
-
|
|
47
|
-
/** Current environment */
|
|
48
|
-
env: env.NODE_ENV,
|
|
49
|
-
|
|
50
|
-
/** Is development mode */
|
|
51
|
-
isDev: env.NODE_ENV === 'development',
|
|
52
|
-
|
|
53
|
-
/** Is production mode */
|
|
54
|
-
isProd: env.NODE_ENV === 'production',
|
|
55
|
-
|
|
56
|
-
/** Is test mode */
|
|
57
|
-
isTest: env.NODE_ENV === 'test',
|
|
58
|
-
|
|
59
|
-
/** Server configuration */
|
|
60
|
-
server: {
|
|
61
|
-
port: env.PORT,
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
/** Logging configuration */
|
|
65
|
-
logging: {
|
|
66
|
-
level: env.LOG_LEVEL,
|
|
67
|
-
},
|
|
68
|
-
} as const;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom error classes
|
|
3
|
-
*
|
|
4
|
-
* Define application-specific errors for better error handling.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Base application error
|
|
9
|
-
*/
|
|
10
|
-
export class AppError extends Error {
|
|
11
|
-
public readonly code: string;
|
|
12
|
-
public readonly statusCode: number;
|
|
13
|
-
public readonly isOperational: boolean;
|
|
14
|
-
|
|
15
|
-
constructor(message: string, code = 'INTERNAL_ERROR', statusCode = 500, isOperational = true) {
|
|
16
|
-
super(message);
|
|
17
|
-
this.name = this.constructor.name;
|
|
18
|
-
this.code = code;
|
|
19
|
-
this.statusCode = statusCode;
|
|
20
|
-
this.isOperational = isOperational;
|
|
21
|
-
|
|
22
|
-
// Maintains proper stack trace
|
|
23
|
-
Error.captureStackTrace(this, this.constructor);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Validation error (400)
|
|
29
|
-
*/
|
|
30
|
-
export class ValidationError extends AppError {
|
|
31
|
-
constructor(message: string) {
|
|
32
|
-
super(message, 'VALIDATION_ERROR', 400);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Not found error (404)
|
|
38
|
-
*/
|
|
39
|
-
export class NotFoundError extends AppError {
|
|
40
|
-
constructor(resource: string) {
|
|
41
|
-
super(`${resource} not found`, 'NOT_FOUND', 404);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Authentication error (401)
|
|
47
|
-
*/
|
|
48
|
-
export class AuthenticationError extends AppError {
|
|
49
|
-
constructor(message = 'Authentication required') {
|
|
50
|
-
super(message, 'AUTHENTICATION_ERROR', 401);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Authorization error (403)
|
|
56
|
-
*/
|
|
57
|
-
export class AuthorizationError extends AppError {
|
|
58
|
-
constructor(message = 'Permission denied') {
|
|
59
|
-
super(message, 'AUTHORIZATION_ERROR', 403);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Conflict error (409)
|
|
65
|
-
*/
|
|
66
|
-
export class ConflictError extends AppError {
|
|
67
|
-
constructor(message: string) {
|
|
68
|
-
super(message, 'CONFLICT_ERROR', 409);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Rate limit error (429)
|
|
74
|
-
*/
|
|
75
|
-
export class RateLimitError extends AppError {
|
|
76
|
-
constructor(message = 'Too many requests') {
|
|
77
|
-
super(message, 'RATE_LIMIT_ERROR', 429);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* External service error (502)
|
|
83
|
-
*/
|
|
84
|
-
export class ExternalServiceError extends AppError {
|
|
85
|
-
constructor(service: string, originalError?: Error) {
|
|
86
|
-
super(
|
|
87
|
-
`External service error: ${service}${originalError ? ` - ${originalError.message}` : ''}`,
|
|
88
|
-
'EXTERNAL_SERVICE_ERROR',
|
|
89
|
-
502
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Check if error is operational (expected) vs programming error
|
|
96
|
-
*/
|
|
97
|
-
export function isOperationalError(error: unknown): boolean {
|
|
98
|
-
if (error instanceof AppError) {
|
|
99
|
-
return error.isOperational;
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Main entry point
|
|
4
|
-
*
|
|
5
|
-
* @packageDocumentation
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { config } from './config.js';
|
|
9
|
-
import { logger } from './utils/logger.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Main application function
|
|
13
|
-
*/
|
|
14
|
-
function main(): void {
|
|
15
|
-
logger.info('Application starting...', { version: config.version });
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
// Initialize your application here
|
|
19
|
-
logger.info('Application started successfully');
|
|
20
|
-
|
|
21
|
-
// Keep the process running (remove if not needed)
|
|
22
|
-
// await new Promise(() => {});
|
|
23
|
-
} catch (error) {
|
|
24
|
-
logger.error('Application failed to start', { error });
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Handle graceful shutdown
|
|
30
|
-
process.on('SIGINT', () => {
|
|
31
|
-
logger.info('Received SIGINT, shutting down...');
|
|
32
|
-
process.exit(0);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
process.on('SIGTERM', () => {
|
|
36
|
-
logger.info('Received SIGTERM, shutting down...');
|
|
37
|
-
process.exit(0);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Handle unhandled rejections
|
|
41
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
42
|
-
logger.error('Unhandled Rejection', { reason, promise });
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Run main
|
|
46
|
-
main();
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions
|
|
3
|
-
*
|
|
4
|
-
* Export all shared types from this module.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Generic result type for operations that can fail
|
|
9
|
-
*/
|
|
10
|
-
export type Result<T, E = Error> = { success: true; data: T } | { success: false; error: E };
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Create a success result
|
|
14
|
-
*/
|
|
15
|
-
export function success<T>(data: T): Result<T, never> {
|
|
16
|
-
return { success: true, data };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Create a failure result
|
|
21
|
-
*/
|
|
22
|
-
export function failure<E>(error: E): Result<never, E> {
|
|
23
|
-
return { success: false, error };
|
|
24
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Logger utility
|
|
3
|
-
*
|
|
4
|
-
* Simple structured logging with levels and context.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
8
|
-
|
|
9
|
-
interface LogContext {
|
|
10
|
-
[key: string]: unknown;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const LOG_LEVELS: Record<LogLevel, number> = {
|
|
14
|
-
debug: 0,
|
|
15
|
-
info: 1,
|
|
16
|
-
warn: 2,
|
|
17
|
-
error: 3,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get current log level from environment
|
|
22
|
-
*/
|
|
23
|
-
function getCurrentLevel(): LogLevel {
|
|
24
|
-
const level = process.env.LOG_LEVEL?.toLowerCase() as LogLevel;
|
|
25
|
-
return LOG_LEVELS[level] !== undefined ? level : 'info';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Format log message with timestamp and context
|
|
30
|
-
*/
|
|
31
|
-
function formatMessage(level: LogLevel, message: string, context?: LogContext): string {
|
|
32
|
-
const timestamp = new Date().toISOString();
|
|
33
|
-
const levelStr = level.toUpperCase().padEnd(5);
|
|
34
|
-
|
|
35
|
-
let output = `[${timestamp}] ${levelStr} ${message}`;
|
|
36
|
-
|
|
37
|
-
if (context && Object.keys(context).length > 0) {
|
|
38
|
-
output += ` ${JSON.stringify(context)}`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return output;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Check if log level should be output
|
|
46
|
-
*/
|
|
47
|
-
function shouldLog(level: LogLevel): boolean {
|
|
48
|
-
return LOG_LEVELS[level] >= LOG_LEVELS[getCurrentLevel()];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Logger instance
|
|
53
|
-
*/
|
|
54
|
-
export const logger = {
|
|
55
|
-
/**
|
|
56
|
-
* Log debug message
|
|
57
|
-
*/
|
|
58
|
-
debug(message: string, context?: LogContext): void {
|
|
59
|
-
if (shouldLog('debug')) {
|
|
60
|
-
console.debug(formatMessage('debug', message, context));
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Log info message
|
|
66
|
-
*/
|
|
67
|
-
info(message: string, context?: LogContext): void {
|
|
68
|
-
if (shouldLog('info')) {
|
|
69
|
-
console.info(formatMessage('info', message, context));
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Log warning message
|
|
75
|
-
*/
|
|
76
|
-
warn(message: string, context?: LogContext): void {
|
|
77
|
-
if (shouldLog('warn')) {
|
|
78
|
-
console.warn(formatMessage('warn', message, context));
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Log error message
|
|
84
|
-
*/
|
|
85
|
-
error(message: string, context?: LogContext): void {
|
|
86
|
-
if (shouldLog('error')) {
|
|
87
|
-
console.error(formatMessage('error', message, context));
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Create a child logger with preset context
|
|
93
|
-
*/
|
|
94
|
-
child(baseContext: LogContext) {
|
|
95
|
-
return {
|
|
96
|
-
debug: (message: string, context?: LogContext) =>
|
|
97
|
-
logger.debug(message, { ...baseContext, ...context }),
|
|
98
|
-
info: (message: string, context?: LogContext) =>
|
|
99
|
-
logger.info(message, { ...baseContext, ...context }),
|
|
100
|
-
warn: (message: string, context?: LogContext) =>
|
|
101
|
-
logger.warn(message, { ...baseContext, ...context }),
|
|
102
|
-
error: (message: string, context?: LogContext) =>
|
|
103
|
-
logger.error(message, { ...baseContext, ...context }),
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Config module tests
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
describe('Config', () => {
|
|
8
|
-
const originalEnv = process.env;
|
|
9
|
-
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
// Reset modules to get fresh config
|
|
12
|
-
vi.resetModules();
|
|
13
|
-
process.env = { ...originalEnv };
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
process.env = originalEnv;
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe('environment detection', () => {
|
|
21
|
-
it('should default to development', async () => {
|
|
22
|
-
delete process.env.NODE_ENV;
|
|
23
|
-
const { config } = await import('../../src/config.js');
|
|
24
|
-
expect(config.isDev).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('should detect production environment', async () => {
|
|
28
|
-
process.env.NODE_ENV = 'production';
|
|
29
|
-
const { config } = await import('../../src/config.js');
|
|
30
|
-
expect(config.isProd).toBe(true);
|
|
31
|
-
expect(config.isDev).toBe(false);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should detect test environment', async () => {
|
|
35
|
-
process.env.NODE_ENV = 'test';
|
|
36
|
-
const { config } = await import('../../src/config.js');
|
|
37
|
-
expect(config.isTest).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('server configuration', () => {
|
|
42
|
-
it('should use default port', async () => {
|
|
43
|
-
delete process.env.PORT;
|
|
44
|
-
const { config } = await import('../../src/config.js');
|
|
45
|
-
expect(config.server.port).toBe(3000);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should use custom port from environment', async () => {
|
|
49
|
-
process.env.PORT = '8080';
|
|
50
|
-
const { config } = await import('../../src/config.js');
|
|
51
|
-
expect(config.server.port).toBe(8080);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('logging configuration', () => {
|
|
56
|
-
it('should default to info log level', async () => {
|
|
57
|
-
delete process.env.LOG_LEVEL;
|
|
58
|
-
const { config } = await import('../../src/config.js');
|
|
59
|
-
expect(config.logging.level).toBe('info');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should use custom log level', async () => {
|
|
63
|
-
process.env.LOG_LEVEL = 'debug';
|
|
64
|
-
const { config } = await import('../../src/config.js');
|
|
65
|
-
expect(config.logging.level).toBe('debug');
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|