gate-stack-cli 1.0.4

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.
Files changed (3) hide show
  1. package/README.md +114 -0
  2. package/package.json +22 -0
  3. package/scripts/gate +82 -0
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # GateStack
2
+
3
+ Backend agora padronizado em **NestJS + Prisma + PostgreSQL + Zod + BullMQ/Redis**, com observabilidade em **Pino + Prometheus + Grafana** e infra com **Docker + Nginx**.
4
+
5
+ `QUEUE_ENABLED` e `QUEUE_WORKER_ENABLED` ficam desabilitados por padrao em ambiente local (fail-open) para evitar falha da API quando Redis estiver indisponivel ou com credencial incorreta.
6
+
7
+ ## Stack
8
+
9
+ - Backend: NestJS (TypeScript)
10
+ - ORM: Prisma
11
+ - Banco: PostgreSQL
12
+ - Filas: BullMQ + Redis
13
+ - Validação: Zod
14
+ - Logging: Pino (`nestjs-pino`)
15
+ - Métricas: Prometheus (`/metrics`)
16
+ - Dashboard: Grafana
17
+ - Dev tools: `tsx`, ESLint, Prettier
18
+ - Testes: Jest + Playwright
19
+
20
+ ## Backend local
21
+
22
+ ```bash
23
+ npm --prefix backend install
24
+ npm --prefix backend run prisma:generate
25
+ npm --prefix backend run dev
26
+ ```
27
+
28
+ API principal:
29
+
30
+ - `POST /api/auth/login`
31
+ - `GET /health`
32
+ - `GET /api/releases`
33
+ - `POST /api/releases`
34
+ - `POST /api/releases/:releaseId/publish`
35
+ - `POST /api/releases/:releaseId/rollback`
36
+ - `GET /metrics` (protegido por token)
37
+
38
+ ## Infra completa (Docker)
39
+
40
+ ```bash
41
+ docker compose up --build
42
+ ```
43
+
44
+ Serviços:
45
+
46
+ - Backend: `http://localhost:5000`
47
+ - Nginx (reverse proxy): `http://localhost`
48
+ - PostgreSQL: `localhost:5432`
49
+ - Redis: `localhost:6379`
50
+ - Prometheus: `http://localhost:9090`
51
+ - Grafana: `http://localhost:3001`
52
+
53
+ Grafana já sobe com:
54
+
55
+ - datasource Prometheus provisionado automaticamente
56
+ - dashboard `GateStack Overview` provisionado automaticamente
57
+
58
+ ## Segurança aplicada
59
+
60
+ - JWT + RBAC (`admin`, `writer`, `reader`)
61
+ - hardening com `helmet`
62
+ - rate limiting global com `@nestjs/throttler`
63
+ - endpoint `/metrics` protegido por `METRICS_TOKEN`
64
+ - Snyk com bloqueio por severidade alta no CI
65
+ - Prometheus configurado para enviar token bearer em `infra/prometheus/prometheus.yml`
66
+
67
+ ## Prisma
68
+
69
+ ```bash
70
+ npm --prefix backend run prisma:migrate:dev
71
+ npm --prefix backend run prisma:generate
72
+ npm --prefix backend run prisma:migrate:deploy
73
+ npm --prefix backend run prisma:seed
74
+ ```
75
+
76
+ Login inicial:
77
+
78
+ - usa `ADMIN_EMAIL` e `ADMIN_PASSWORD` configurados no ambiente
79
+ - usuário admin é criado/atualizado automaticamente no bootstrap
80
+
81
+ ## Qualidade
82
+
83
+ ```bash
84
+ npm --prefix backend run lint
85
+ npm --prefix backend run type-check
86
+ npm --prefix backend run test
87
+ npm --prefix backend run test:e2e
88
+ ```
89
+
90
+ ## CLI `gate` (alias para git)
91
+
92
+ Use `gate clone` em vez de `git clone` apontando para o Git HTTP do backend.
93
+
94
+ 1. Dê permissão de execução ao wrapper:
95
+ ```bash
96
+ chmod +x scripts/gate
97
+ ```
98
+ 2. Adicione `scripts/` ao PATH ou chame direto:
99
+ ```bash
100
+ scripts/gate clone http://localhost:5000/git/<slug>
101
+ ```
102
+ 3. Você pode usar só o slug; o host vem de `GATE_HOST` (default `http://localhost:5000`):
103
+ ```bash
104
+ GATE_HOST=https://gatestack.local scripts/gate clone meu-projeto
105
+ ```
106
+
107
+ Comandos suportados:
108
+ - `gate clone <slug|url> [dir]` (transforma slug em `<GATE_HOST>/git/<slug>`)
109
+ - `gate init`, `gate pull`, `gate push`, `gate status`
110
+ - qualquer outro comando git funciona: `gate checkout -b feature/x`
111
+
112
+ Variáveis:
113
+ - `GATE_HOST`: base do Git HTTP.
114
+ - `GIT_BIN`: caminho do binário git (default `git`).
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "gate-stack-cli",
3
+ "version": "1.0.4",
4
+ "private": false,
5
+ "description": "Gate CLI wrapper for git (gate clone/init/push/pull/status)",
6
+ "bin": {
7
+ "gate": "scripts/gate"
8
+ },
9
+ "files": [
10
+ "scripts/gate"
11
+ ],
12
+ "scripts": {
13
+ "dev": "make dev",
14
+ "dev:backend": "npm --prefix backend run dev",
15
+ "dev:tauri": "make dev-tauri",
16
+ "build": "make build",
17
+ "build:backend": "npm --prefix backend run build",
18
+ "start:backend": "npm --prefix backend run start",
19
+ "install:all": "make install"
20
+ },
21
+ "dependencies": {}
22
+ }
package/scripts/gate ADDED
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env bash
2
+ # Gate CLI — wrapper sobre git com convenções da GateStack
3
+ # Suporta:
4
+ # gate clone <slug|url> [dir]
5
+ # gate init [dir]
6
+ # gate pull [args...]
7
+ # gate push [args...]
8
+ # gate status [args...]
9
+ # gate <qualquer-comando-git> [...]
10
+
11
+ set -euo pipefail
12
+
13
+ GATE_HOST="${GATE_HOST:-http://localhost:5000}"
14
+ GIT_BIN="${GIT_BIN:-git}"
15
+
16
+ usage() {
17
+ cat <<'EOF'
18
+ Gate CLI (wrapper para git)
19
+ Usage:
20
+ gate clone <slug|url> [dir]
21
+ gate init [dir]
22
+ gate pull [args...]
23
+ gate push [args...]
24
+ gate status [args...]
25
+ gate <comando-git> [...]
26
+
27
+ Env vars:
28
+ GATE_HOST Base URL para o Git HTTP (default: http://localhost:5000)
29
+ GIT_BIN Caminho do binário git (default: git)
30
+ EOF
31
+ }
32
+
33
+ ensure_args() {
34
+ local count=$1
35
+ shift
36
+ if [ $# -lt "$count" ]; then
37
+ usage
38
+ exit 1
39
+ fi
40
+ }
41
+
42
+ normalize_clone_url() {
43
+ local target=$1
44
+ if [[ "$target" =~ ^https?:// ]] || [[ "$target" =~ ^git@ ]] || [[ "$target" =~ ^ssh:// ]]; then
45
+ echo "$target"
46
+ else
47
+ echo "${GATE_HOST%/}/git/${target}"
48
+ fi
49
+ }
50
+
51
+ cmd="${1:-}"
52
+ if [ -z "$cmd" ]; then
53
+ usage
54
+ exit 1
55
+ fi
56
+ shift || true
57
+
58
+ case "$cmd" in
59
+ clone)
60
+ ensure_args 1 "$@"
61
+ url=$(normalize_clone_url "$1"); shift
62
+ exec "$GIT_BIN" clone "$url" "$@"
63
+ ;;
64
+ init)
65
+ exec "$GIT_BIN" init "$@"
66
+ ;;
67
+ pull)
68
+ exec "$GIT_BIN" pull "$@"
69
+ ;;
70
+ push)
71
+ exec "$GIT_BIN" push "$@"
72
+ ;;
73
+ status)
74
+ exec "$GIT_BIN" status "$@"
75
+ ;;
76
+ -h|--help|help)
77
+ usage
78
+ ;;
79
+ *)
80
+ exec "$GIT_BIN" "$cmd" "$@"
81
+ ;;
82
+ esac