@engjts/nexus 0.1.8 → 0.1.10
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/dist/advanced/playground/playground.js.map +1 -1
- package/dist/advanced/static/generateDirectoryListing.d.ts +1 -1
- package/dist/advanced/static/generateDirectoryListing.d.ts.map +1 -1
- package/dist/advanced/static/generateDirectoryListing.js +12 -6
- package/dist/advanced/static/generateDirectoryListing.js.map +1 -1
- package/dist/advanced/static/index.d.ts +2 -0
- package/dist/advanced/static/index.d.ts.map +1 -1
- package/dist/advanced/static/index.js +4 -1
- package/dist/advanced/static/index.js.map +1 -1
- package/dist/advanced/static/serveStatic.d.ts.map +1 -1
- package/dist/advanced/static/serveStatic.js +7 -1
- package/dist/advanced/static/serveStatic.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/BENCHMARK_REPORT.md +0 -343
- package/documentation/01-getting-started.md +0 -240
- package/documentation/02-context.md +0 -335
- package/documentation/03-routing.md +0 -397
- package/documentation/04-middleware.md +0 -483
- package/documentation/05-validation.md +0 -514
- package/documentation/06-error-handling.md +0 -465
- package/documentation/07-performance.md +0 -364
- package/documentation/08-adapters.md +0 -470
- package/documentation/09-api-reference.md +0 -548
- package/documentation/10-examples.md +0 -582
- package/documentation/11-deployment.md +0 -477
- package/documentation/12-sentry.md +0 -620
- package/documentation/13-sentry-data-storage.md +0 -996
- package/documentation/14-sentry-data-reference.md +0 -457
- package/documentation/15-sentry-summary.md +0 -409
- package/documentation/16-alerts-system.md +0 -745
- package/documentation/17-alert-adapters.md +0 -696
- package/documentation/18-alerts-implementation-summary.md +0 -385
- package/documentation/19-class-based-routing.md +0 -840
- package/documentation/20-websocket-realtime.md +0 -813
- package/documentation/21-cache-system.md +0 -510
- package/documentation/22-job-queue.md +0 -772
- package/documentation/23-sentry-plugin.md +0 -551
- package/documentation/24-testing-utilities.md +0 -1287
- package/documentation/25-api-versioning.md +0 -533
- package/documentation/26-context-store.md +0 -607
- package/documentation/27-dependency-injection.md +0 -329
- package/documentation/28-lifecycle-hooks.md +0 -521
- package/documentation/29-package-structure.md +0 -196
- package/documentation/30-plugin-system.md +0 -414
- package/documentation/31-jwt-authentication.md +0 -597
- package/documentation/32-cli.md +0 -268
- package/documentation/ALERTS-COMPLETE-SUMMARY.md +0 -429
- package/documentation/ALERTS-INDEX.md +0 -330
- package/documentation/ALERTS-QUICK-REFERENCE.md +0 -286
- package/documentation/README.md +0 -178
- package/documentation/index.html +0 -34
- package/modern_framework_paper.md +0 -1870
- package/public/css/style.css +0 -87
- package/public/index.html +0 -34
- package/public/js/app.js +0 -27
- package/src/advanced/cache/InMemoryCacheStore.ts +0 -68
- package/src/advanced/cache/MultiTierCache.ts +0 -194
- package/src/advanced/cache/RedisCacheStore.ts +0 -341
- package/src/advanced/cache/index.ts +0 -5
- package/src/advanced/cache/types.ts +0 -40
- package/src/advanced/graphql/SimpleDataLoader.ts +0 -42
- package/src/advanced/graphql/index.ts +0 -22
- package/src/advanced/graphql/server.ts +0 -252
- package/src/advanced/graphql/types.ts +0 -42
- package/src/advanced/jobs/InMemoryQueueStore.ts +0 -68
- package/src/advanced/jobs/JobQueue.ts +0 -556
- package/src/advanced/jobs/RedisQueueStore.ts +0 -367
- package/src/advanced/jobs/index.ts +0 -5
- package/src/advanced/jobs/types.ts +0 -70
- package/src/advanced/observability/APMManager.ts +0 -163
- package/src/advanced/observability/AlertManager.ts +0 -109
- package/src/advanced/observability/MetricRegistry.ts +0 -151
- package/src/advanced/observability/ObservabilityCenter.ts +0 -304
- package/src/advanced/observability/StructuredLogger.ts +0 -154
- package/src/advanced/observability/TracingManager.ts +0 -117
- package/src/advanced/observability/adapters.ts +0 -304
- package/src/advanced/observability/createObservabilityMiddleware.ts +0 -63
- package/src/advanced/observability/index.ts +0 -11
- package/src/advanced/observability/types.ts +0 -174
- package/src/advanced/playground/extractPathParams.ts +0 -6
- package/src/advanced/playground/generateFieldExample.ts +0 -31
- package/src/advanced/playground/generatePlaygroundHTML.ts +0 -1956
- package/src/advanced/playground/generateSummary.ts +0 -19
- package/src/advanced/playground/getTagFromPath.ts +0 -9
- package/src/advanced/playground/index.ts +0 -8
- package/src/advanced/playground/playground.ts +0 -250
- package/src/advanced/playground/types.ts +0 -49
- package/src/advanced/playground/zodToExample.ts +0 -16
- package/src/advanced/playground/zodToParams.ts +0 -15
- package/src/advanced/postman/buildAuth.ts +0 -31
- package/src/advanced/postman/buildBody.ts +0 -15
- package/src/advanced/postman/buildQueryParams.ts +0 -27
- package/src/advanced/postman/buildRequestItem.ts +0 -36
- package/src/advanced/postman/buildResponses.ts +0 -11
- package/src/advanced/postman/buildUrl.ts +0 -33
- package/src/advanced/postman/capitalize.ts +0 -4
- package/src/advanced/postman/generateCollection.ts +0 -59
- package/src/advanced/postman/generateEnvironment.ts +0 -34
- package/src/advanced/postman/generateExampleFromZod.ts +0 -21
- package/src/advanced/postman/generateFieldExample.ts +0 -45
- package/src/advanced/postman/generateName.ts +0 -20
- package/src/advanced/postman/generateUUID.ts +0 -11
- package/src/advanced/postman/getTagFromPath.ts +0 -10
- package/src/advanced/postman/index.ts +0 -28
- package/src/advanced/postman/postman.ts +0 -156
- package/src/advanced/postman/slugify.ts +0 -7
- package/src/advanced/postman/types.ts +0 -140
- package/src/advanced/realtime/index.ts +0 -18
- package/src/advanced/realtime/websocket.ts +0 -231
- package/src/advanced/sentry/index.ts +0 -1236
- package/src/advanced/sentry/types.ts +0 -355
- package/src/advanced/static/generateDirectoryListing.ts +0 -47
- package/src/advanced/static/generateETag.ts +0 -7
- package/src/advanced/static/getMimeType.ts +0 -9
- package/src/advanced/static/index.ts +0 -32
- package/src/advanced/static/isSafePath.ts +0 -13
- package/src/advanced/static/publicDir.ts +0 -21
- package/src/advanced/static/serveStatic.ts +0 -225
- package/src/advanced/static/spa.ts +0 -24
- package/src/advanced/static/types.ts +0 -159
- package/src/advanced/swagger/SwaggerGenerator.ts +0 -66
- package/src/advanced/swagger/buildOperation.ts +0 -61
- package/src/advanced/swagger/buildParameters.ts +0 -61
- package/src/advanced/swagger/buildRequestBody.ts +0 -21
- package/src/advanced/swagger/buildResponses.ts +0 -54
- package/src/advanced/swagger/capitalize.ts +0 -5
- package/src/advanced/swagger/convertPath.ts +0 -9
- package/src/advanced/swagger/createSwagger.ts +0 -12
- package/src/advanced/swagger/generateOperationId.ts +0 -21
- package/src/advanced/swagger/generateSpec.ts +0 -105
- package/src/advanced/swagger/generateSummary.ts +0 -24
- package/src/advanced/swagger/generateSwaggerUI.ts +0 -70
- package/src/advanced/swagger/generateThemeCss.ts +0 -53
- package/src/advanced/swagger/index.ts +0 -25
- package/src/advanced/swagger/swagger.ts +0 -237
- package/src/advanced/swagger/types.ts +0 -206
- package/src/advanced/swagger/zodFieldToOpenAPI.ts +0 -94
- package/src/advanced/swagger/zodSchemaToOpenAPI.ts +0 -50
- package/src/advanced/swagger/zodToOpenAPI.ts +0 -22
- package/src/advanced/testing/factory.ts +0 -509
- package/src/advanced/testing/harness.ts +0 -612
- package/src/advanced/testing/index.ts +0 -430
- package/src/advanced/testing/load-test.ts +0 -618
- package/src/advanced/testing/mock-server.ts +0 -498
- package/src/advanced/testing/mock.ts +0 -670
- package/src/cli/bin.ts +0 -9
- package/src/cli/cli.ts +0 -158
- package/src/cli/commands/add.ts +0 -178
- package/src/cli/commands/build.ts +0 -73
- package/src/cli/commands/create.ts +0 -166
- package/src/cli/commands/dev.ts +0 -85
- package/src/cli/commands/generate.ts +0 -99
- package/src/cli/commands/help.ts +0 -95
- package/src/cli/commands/init.ts +0 -91
- package/src/cli/commands/version.ts +0 -38
- package/src/cli/index.ts +0 -6
- package/src/cli/templates/generators.ts +0 -359
- package/src/cli/templates/index.ts +0 -680
- package/src/cli/utils/exec.ts +0 -52
- package/src/cli/utils/file-system.ts +0 -78
- package/src/cli/utils/logger.ts +0 -111
- package/src/core/adapter.ts +0 -88
- package/src/core/application.ts +0 -1453
- package/src/core/context-pool.ts +0 -79
- package/src/core/context.ts +0 -856
- package/src/core/index.ts +0 -94
- package/src/core/middleware.ts +0 -272
- package/src/core/performance/buffer-pool.ts +0 -108
- package/src/core/performance/middleware-optimizer.ts +0 -162
- package/src/core/plugin/PluginManager.ts +0 -435
- package/src/core/plugin/builder.ts +0 -358
- package/src/core/plugin/index.ts +0 -50
- package/src/core/plugin/types.ts +0 -214
- package/src/core/router/file-router.ts +0 -623
- package/src/core/router/index.ts +0 -260
- package/src/core/router/radix-tree.ts +0 -242
- package/src/core/serializer.ts +0 -397
- package/src/core/store/index.ts +0 -30
- package/src/core/store/registry.ts +0 -178
- package/src/core/store/request-store.ts +0 -240
- package/src/core/store/types.ts +0 -233
- package/src/core/types.ts +0 -616
- package/src/database/adapter.ts +0 -35
- package/src/database/adapters/index.ts +0 -1
- package/src/database/adapters/mysql.ts +0 -669
- package/src/database/database.ts +0 -70
- package/src/database/dialect.ts +0 -388
- package/src/database/index.ts +0 -12
- package/src/database/migrations.ts +0 -86
- package/src/database/optimizer.ts +0 -125
- package/src/database/query-builder.ts +0 -404
- package/src/database/realtime.ts +0 -53
- package/src/database/schema.ts +0 -71
- package/src/database/transactions.ts +0 -56
- package/src/database/types.ts +0 -87
- package/src/deployment/cluster.ts +0 -471
- package/src/deployment/config.ts +0 -454
- package/src/deployment/docker.ts +0 -599
- package/src/deployment/graceful-shutdown.ts +0 -373
- package/src/deployment/index.ts +0 -56
- package/src/index.ts +0 -281
- package/src/security/adapter.ts +0 -318
- package/src/security/auth/JWTPlugin.ts +0 -234
- package/src/security/auth/JWTProvider.ts +0 -316
- package/src/security/auth/adapter.ts +0 -12
- package/src/security/auth/jwt.ts +0 -234
- package/src/security/auth/middleware.ts +0 -188
- package/src/security/csrf.ts +0 -220
- package/src/security/headers.ts +0 -108
- package/src/security/index.ts +0 -60
- package/src/security/rate-limit/adapter.ts +0 -7
- package/src/security/rate-limit/memory.ts +0 -108
- package/src/security/rate-limit/middleware.ts +0 -181
- package/src/security/sanitization.ts +0 -75
- package/src/security/types.ts +0 -240
- package/src/security/utils.ts +0 -52
- package/tsconfig.json +0 -39
package/documentation/32-cli.md
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
# Nexus CLI
|
|
2
|
-
|
|
3
|
-
Command-line interface untuk Nexus Framework.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Setelah install `@engjts/nexus`, command `nexus` akan tersedia secara global:
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install -g @engjts/nexus
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Atau gunakan via npx:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npx @engjts/nexus create my-app
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Commands
|
|
20
|
-
|
|
21
|
-
### `nexus create <name>`
|
|
22
|
-
|
|
23
|
-
Buat project Nexus baru.
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
nexus create my-app
|
|
27
|
-
nexus create my-api --template api
|
|
28
|
-
nexus create my-fullstack --template fullstack
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
**Options:**
|
|
32
|
-
|
|
33
|
-
| Option | Alias | Description | Default |
|
|
34
|
-
|--------|-------|-------------|---------|
|
|
35
|
-
| `--template` | `-t` | Template project (basic, api, fullstack) | `basic` |
|
|
36
|
-
| `--package-manager` | `-pm` | Package manager (npm, yarn, pnpm, bun) | `npm` |
|
|
37
|
-
| `--skip-install` | | Skip dependency installation | `false` |
|
|
38
|
-
| `--skip-git` | | Skip git initialization | `false` |
|
|
39
|
-
|
|
40
|
-
**Templates:**
|
|
41
|
-
|
|
42
|
-
- **basic**: Simple starter dengan routing dasar
|
|
43
|
-
- **api**: REST API dengan structure lengkap (routes, middleware, services, validators)
|
|
44
|
-
- **fullstack**: API + static files untuk frontend
|
|
45
|
-
|
|
46
|
-
### `nexus init`
|
|
47
|
-
|
|
48
|
-
Initialize Nexus di directory yang sudah ada.
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
nexus init
|
|
52
|
-
nexus init --template api
|
|
53
|
-
nexus init --force
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
**Options:**
|
|
57
|
-
|
|
58
|
-
| Option | Alias | Description | Default |
|
|
59
|
-
|--------|-------|-------------|---------|
|
|
60
|
-
| `--template` | `-t` | Template project | `basic` |
|
|
61
|
-
| `--force` | `-f` | Force init meskipun directory tidak kosong | `false` |
|
|
62
|
-
|
|
63
|
-
### `nexus generate <type> <name>`
|
|
64
|
-
|
|
65
|
-
Generate komponen baru.
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
nexus generate route users
|
|
69
|
-
nexus generate controller UserController
|
|
70
|
-
nexus generate middleware auth
|
|
71
|
-
nexus generate service user
|
|
72
|
-
nexus generate model Product
|
|
73
|
-
nexus generate validator user
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
**Types:**
|
|
77
|
-
|
|
78
|
-
| Type | Description | Output Path |
|
|
79
|
-
|------|-------------|-------------|
|
|
80
|
-
| `route` | Route handler | `src/routes/<name>.ts` |
|
|
81
|
-
| `middleware` | Middleware function | `src/middleware/<name>.ts` |
|
|
82
|
-
| `controller` | Controller class dengan decorators | `src/controllers/<name>.ts` |
|
|
83
|
-
| `service` | Service class dengan CRUD methods | `src/services/<name>.ts` |
|
|
84
|
-
| `model` | Model/entity definition | `src/models/<name>.ts` |
|
|
85
|
-
| `validator` | Zod validation schemas | `src/validators/<name>.ts` |
|
|
86
|
-
|
|
87
|
-
**Options:**
|
|
88
|
-
|
|
89
|
-
| Option | Alias | Description |
|
|
90
|
-
|--------|-------|-------------|
|
|
91
|
-
| `--path` | `-p` | Custom output path |
|
|
92
|
-
| `--methods` | `-m` | HTTP methods untuk route (comma-separated) |
|
|
93
|
-
|
|
94
|
-
**Examples:**
|
|
95
|
-
|
|
96
|
-
```bash
|
|
97
|
-
# Generate route dengan multiple methods
|
|
98
|
-
nexus generate route products --methods get,post,put,delete
|
|
99
|
-
|
|
100
|
-
# Generate ke custom path
|
|
101
|
-
nexus generate middleware auth --path src/api/middleware
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### `nexus dev`
|
|
105
|
-
|
|
106
|
-
Start development server dengan hot reload.
|
|
107
|
-
|
|
108
|
-
```bash
|
|
109
|
-
nexus dev
|
|
110
|
-
nexus dev --port 8080
|
|
111
|
-
nexus dev --host 0.0.0.0
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
**Options:**
|
|
115
|
-
|
|
116
|
-
| Option | Alias | Description | Default |
|
|
117
|
-
|--------|-------|-------------|---------|
|
|
118
|
-
| `--port` | `-p` | Port untuk server | `3000` |
|
|
119
|
-
| `--host` | `-H` | Host untuk bind server | `localhost` |
|
|
120
|
-
|
|
121
|
-
### `nexus build`
|
|
122
|
-
|
|
123
|
-
Build project untuk production.
|
|
124
|
-
|
|
125
|
-
```bash
|
|
126
|
-
nexus build
|
|
127
|
-
nexus build --outDir build
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
**Options:**
|
|
131
|
-
|
|
132
|
-
| Option | Alias | Description | Default |
|
|
133
|
-
|--------|-------|-------------|---------|
|
|
134
|
-
| `--outDir` | `-o` | Output directory | `dist` |
|
|
135
|
-
| `--minify` | | Minify output | `false` |
|
|
136
|
-
|
|
137
|
-
### `nexus help [command]`
|
|
138
|
-
|
|
139
|
-
Tampilkan help.
|
|
140
|
-
|
|
141
|
-
```bash
|
|
142
|
-
nexus help
|
|
143
|
-
nexus help create
|
|
144
|
-
nexus help generate
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
### `nexus version`
|
|
148
|
-
|
|
149
|
-
Tampilkan versi CLI.
|
|
150
|
-
|
|
151
|
-
```bash
|
|
152
|
-
nexus version
|
|
153
|
-
nexus --version
|
|
154
|
-
nexus -v
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
## Project Structure
|
|
158
|
-
|
|
159
|
-
Saat membuat project baru dengan template `api`, struktur folder akan seperti ini:
|
|
160
|
-
|
|
161
|
-
```
|
|
162
|
-
my-app/
|
|
163
|
-
├── src/
|
|
164
|
-
│ ├── index.ts # Entry point
|
|
165
|
-
│ ├── routes/
|
|
166
|
-
│ │ ├── index.ts # Route registry
|
|
167
|
-
│ │ └── users.ts # User routes
|
|
168
|
-
│ ├── middleware/
|
|
169
|
-
│ │ ├── auth.ts # Auth middleware
|
|
170
|
-
│ │ └── logger.ts # Logger middleware
|
|
171
|
-
│ ├── services/
|
|
172
|
-
│ │ └── user.service.ts # Business logic
|
|
173
|
-
│ ├── validators/
|
|
174
|
-
│ │ └── user.validator.ts # Zod schemas
|
|
175
|
-
│ └── types/
|
|
176
|
-
│ └── index.ts # TypeScript types
|
|
177
|
-
├── package.json
|
|
178
|
-
├── tsconfig.json
|
|
179
|
-
├── .env.example
|
|
180
|
-
├── .gitignore
|
|
181
|
-
└── README.md
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
## Environment Variables
|
|
185
|
-
|
|
186
|
-
File `.env.example` berisi template environment variables:
|
|
187
|
-
|
|
188
|
-
```env
|
|
189
|
-
# Server
|
|
190
|
-
PORT=3000
|
|
191
|
-
HOST=localhost
|
|
192
|
-
NODE_ENV=development
|
|
193
|
-
|
|
194
|
-
# Database
|
|
195
|
-
DATABASE_URL=mysql://user:password@localhost:3306/dbname
|
|
196
|
-
|
|
197
|
-
# JWT
|
|
198
|
-
JWT_SECRET=your-super-secret-jwt-key
|
|
199
|
-
JWT_EXPIRES_IN=7d
|
|
200
|
-
|
|
201
|
-
# Rate Limiting
|
|
202
|
-
RATE_LIMIT_MAX=100
|
|
203
|
-
RATE_LIMIT_WINDOW_MS=60000
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
Copy ke `.env` dan sesuaikan nilai-nilainya:
|
|
207
|
-
|
|
208
|
-
```bash
|
|
209
|
-
cp .env.example .env
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
## Quick Start
|
|
213
|
-
|
|
214
|
-
```bash
|
|
215
|
-
# Create new project
|
|
216
|
-
nexus create my-api --template api
|
|
217
|
-
|
|
218
|
-
# Navigate to project
|
|
219
|
-
cd my-api
|
|
220
|
-
|
|
221
|
-
# Install dependencies (if skipped)
|
|
222
|
-
npm install
|
|
223
|
-
|
|
224
|
-
# Start development server
|
|
225
|
-
npm run dev
|
|
226
|
-
# atau
|
|
227
|
-
nexus dev
|
|
228
|
-
|
|
229
|
-
# Build for production
|
|
230
|
-
npm run build
|
|
231
|
-
# atau
|
|
232
|
-
nexus build
|
|
233
|
-
|
|
234
|
-
# Start production server
|
|
235
|
-
npm start
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
## Tips
|
|
239
|
-
|
|
240
|
-
### Using with Different Package Managers
|
|
241
|
-
|
|
242
|
-
```bash
|
|
243
|
-
# Using Yarn
|
|
244
|
-
nexus create my-app --pm yarn
|
|
245
|
-
|
|
246
|
-
# Using pnpm
|
|
247
|
-
nexus create my-app --pm pnpm
|
|
248
|
-
|
|
249
|
-
# Using Bun
|
|
250
|
-
nexus create my-app --pm bun
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
### Generate Multiple Components
|
|
254
|
-
|
|
255
|
-
```bash
|
|
256
|
-
# Generate complete feature
|
|
257
|
-
nexus generate route products
|
|
258
|
-
nexus generate service product
|
|
259
|
-
nexus generate validator product
|
|
260
|
-
nexus generate model Product
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
### Custom Paths
|
|
264
|
-
|
|
265
|
-
```bash
|
|
266
|
-
# Generate ke subfolder
|
|
267
|
-
nexus generate route v2/users --path src/api/v2/routes
|
|
268
|
-
```
|
|
@@ -1,429 +0,0 @@
|
|
|
1
|
-
# 🎉 Alert System - Implementation Complete
|
|
2
|
-
|
|
3
|
-
## Status: ✅ READY FOR PRODUCTION
|
|
4
|
-
|
|
5
|
-
Sistem Alert dengan Adapter Pattern telah selesai di-implement dengan dokumentasi lengkap dan contoh penggunaan.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## What's Been Done
|
|
10
|
-
|
|
11
|
-
### ✅ Code Implementation
|
|
12
|
-
|
|
13
|
-
1. **Alert Channel Adapter Pattern**
|
|
14
|
-
- File: `src/advanced/observability/adapters.ts`
|
|
15
|
-
- Interface: `AlertChannelAdapter`
|
|
16
|
-
- Registry: `AlertChannelAdapterRegistry`
|
|
17
|
-
|
|
18
|
-
2. **Built-in Adapters (7 total)**
|
|
19
|
-
- ✨ **Telegram** - NEW
|
|
20
|
-
- ✨ **Discord** - NEW
|
|
21
|
-
- Slack
|
|
22
|
-
- Webhook (Custom HTTP)
|
|
23
|
-
- Email (template)
|
|
24
|
-
- PagerDuty (template)
|
|
25
|
-
- Console (testing)
|
|
26
|
-
|
|
27
|
-
3. **Refactored AlertManager**
|
|
28
|
-
- File: `src/advanced/observability/index.ts`
|
|
29
|
-
- Removed hardcoded switch-case
|
|
30
|
-
- Uses adapter registry
|
|
31
|
-
- Better error handling
|
|
32
|
-
- Config validation
|
|
33
|
-
|
|
34
|
-
4. **Type Safety**
|
|
35
|
-
- Updated `AlertingOptions` interface
|
|
36
|
-
- Support for all 7 channels
|
|
37
|
-
- TypeScript compilation ✅
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
### ✅ Documentation
|
|
42
|
-
|
|
43
|
-
| File | Purpose |
|
|
44
|
-
|------|---------|
|
|
45
|
-
| `16-alerts-system.md` | Complete alert system guide |
|
|
46
|
-
| `17-alert-adapters.md` | Adapter pattern & custom adapters |
|
|
47
|
-
| `18-alerts-implementation-summary.md` | Implementation details & architecture |
|
|
48
|
-
| `ALERTS-QUICK-REFERENCE.md` | Quick reference card |
|
|
49
|
-
|
|
50
|
-
---
|
|
51
|
-
|
|
52
|
-
### ✅ Examples & Configuration
|
|
53
|
-
|
|
54
|
-
| File | Purpose |
|
|
55
|
-
|------|---------|
|
|
56
|
-
| `example-alerts.ts` | 6 real-world examples |
|
|
57
|
-
| `.env.example.alerts` | Environment variable template |
|
|
58
|
-
|
|
59
|
-
---
|
|
60
|
-
|
|
61
|
-
## Features Implemented
|
|
62
|
-
|
|
63
|
-
### Alert Channels
|
|
64
|
-
|
|
65
|
-
```
|
|
66
|
-
Telegram ✅ Production-ready
|
|
67
|
-
Discord ✅ Production-ready
|
|
68
|
-
Slack ✅ Production-ready
|
|
69
|
-
Webhook ✅ Production-ready (Generic HTTP)
|
|
70
|
-
Email ⚠️ Template (needs SendGrid/Mailgun integration)
|
|
71
|
-
PagerDuty ⚠️ Template (needs Events API v2 integration)
|
|
72
|
-
Console ✅ Testing & debugging
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Adapter Pattern Benefits
|
|
76
|
-
|
|
77
|
-
- ✅ **Extensible** - Add new channels easily
|
|
78
|
-
- ✅ **Maintainable** - Each adapter isolated
|
|
79
|
-
- ✅ **Testable** - Mock adapters easily
|
|
80
|
-
- ✅ **Type-safe** - Full TypeScript support
|
|
81
|
-
- ✅ **Flexible** - Mix & match channels
|
|
82
|
-
- ✅ **Dynamic** - Register adapters at runtime
|
|
83
|
-
|
|
84
|
-
### Core Features
|
|
85
|
-
|
|
86
|
-
- ✅ Multiple notification channels
|
|
87
|
-
- ✅ Alert condition evaluation (>, <, >=, <=)
|
|
88
|
-
- ✅ Cooldown to prevent spam (60 seconds)
|
|
89
|
-
- ✅ Alert history tracking
|
|
90
|
-
- ✅ Config validation per adapter
|
|
91
|
-
- ✅ Error handling & logging
|
|
92
|
-
- ✅ Custom adapter support
|
|
93
|
-
- ✅ Environment-aware setup
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
## Quick Start
|
|
98
|
-
|
|
99
|
-
### 1. Setup Telegram Alerts
|
|
100
|
-
|
|
101
|
-
```bash
|
|
102
|
-
# Get bot token from @BotFather on Telegram
|
|
103
|
-
# Get chat ID from api.telegram.org/bot{TOKEN}/getUpdates
|
|
104
|
-
|
|
105
|
-
export TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklmnoPQRstUVwxyz
|
|
106
|
-
export TELEGRAM_CHAT_ID=987654321
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
```typescript
|
|
110
|
-
import { ObservabilityCenter } from './nexus/advanced/observability';
|
|
111
|
-
|
|
112
|
-
const obs = new ObservabilityCenter({
|
|
113
|
-
alerting: {
|
|
114
|
-
enabled: true,
|
|
115
|
-
channels: {
|
|
116
|
-
telegram: {
|
|
117
|
-
botToken: process.env.TELEGRAM_BOT_TOKEN!,
|
|
118
|
-
chatId: process.env.TELEGRAM_CHAT_ID!
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
alerts: [
|
|
122
|
-
{
|
|
123
|
-
name: 'High Error Rate',
|
|
124
|
-
condition: 'error_rate > 0.05',
|
|
125
|
-
window: '5m',
|
|
126
|
-
threshold: 0.05,
|
|
127
|
-
channels: ['telegram']
|
|
128
|
-
}
|
|
129
|
-
]
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
### 2. Multi-Channel Setup
|
|
135
|
-
|
|
136
|
-
```typescript
|
|
137
|
-
channels: {
|
|
138
|
-
slack: { webhookUrl: process.env.SLACK_WEBHOOK_URL! },
|
|
139
|
-
telegram: {
|
|
140
|
-
botToken: process.env.TELEGRAM_BOT_TOKEN!,
|
|
141
|
-
chatId: process.env.TELEGRAM_CHAT_ID!
|
|
142
|
-
},
|
|
143
|
-
discord: { webhookUrl: process.env.DISCORD_WEBHOOK_URL! }
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Use all 3 channels in one alert
|
|
147
|
-
channels: ['slack', 'telegram', 'discord']
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
### 3. Custom Adapter
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
import { AlertChannelAdapter } from './nexus/advanced/observability';
|
|
154
|
-
|
|
155
|
-
class MyAdapter implements AlertChannelAdapter {
|
|
156
|
-
async send(alert, value, config) {
|
|
157
|
-
// Your implementation
|
|
158
|
-
}
|
|
159
|
-
validate(config) {
|
|
160
|
-
return !!config.required;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
registry?.register('my-adapter', new MyAdapter());
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
---
|
|
168
|
-
|
|
169
|
-
## File Structure
|
|
170
|
-
|
|
171
|
-
```
|
|
172
|
-
nexus/
|
|
173
|
-
├── src/
|
|
174
|
-
│ └── advanced/
|
|
175
|
-
│ └── observability/
|
|
176
|
-
│ ├── index.ts (MODIFIED)
|
|
177
|
-
│ ├── adapters.ts (NEW ✨)
|
|
178
|
-
│ ├── cache/
|
|
179
|
-
│ ├── graphql/
|
|
180
|
-
│ ├── jobs/
|
|
181
|
-
│ ├── realtime/
|
|
182
|
-
│ ├── sentry/
|
|
183
|
-
│ ├── testing/
|
|
184
|
-
│ └── versioning/
|
|
185
|
-
│
|
|
186
|
-
├── documentation/
|
|
187
|
-
│ ├── 16-alerts-system.md (NEW ✨)
|
|
188
|
-
│ ├── 17-alert-adapters.md (NEW ✨)
|
|
189
|
-
│ ├── 18-alerts-implementation-summary.md (NEW ✨)
|
|
190
|
-
│ ├── ALERTS-QUICK-REFERENCE.md (NEW ✨)
|
|
191
|
-
│ ├── 01-15-*.md (existing)
|
|
192
|
-
│ └── README.md
|
|
193
|
-
│
|
|
194
|
-
├── example-alerts.ts (NEW ✨)
|
|
195
|
-
├── .env.example.alerts (NEW ✨)
|
|
196
|
-
└── ... (other files)
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
## Key Design Decisions
|
|
202
|
-
|
|
203
|
-
### Why Adapter Pattern?
|
|
204
|
-
|
|
205
|
-
**Before (Hardcoded):**
|
|
206
|
-
```typescript
|
|
207
|
-
switch (channel) {
|
|
208
|
-
case 'slack': await sendSlack(...); break;
|
|
209
|
-
case 'email': await sendEmail(...); break;
|
|
210
|
-
// Adding new channel = modify AlertManager
|
|
211
|
-
}
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
**After (Adapter Pattern):**
|
|
215
|
-
```typescript
|
|
216
|
-
const adapter = registry.get(channel);
|
|
217
|
-
await adapter.send(alert, value, config);
|
|
218
|
-
// Adding new channel = create new adapter class
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
### Why Interface-based?
|
|
222
|
-
|
|
223
|
-
- ✅ Type safety at compile-time
|
|
224
|
-
- ✅ IDE auto-completion
|
|
225
|
-
- ✅ Clear contract for adapters
|
|
226
|
-
- ✅ Easy testing with mocks
|
|
227
|
-
|
|
228
|
-
### Why Registry Pattern?
|
|
229
|
-
|
|
230
|
-
- ✅ Dynamic adapter registration
|
|
231
|
-
- ✅ Runtime channel discovery
|
|
232
|
-
- ✅ Support custom adapters
|
|
233
|
-
- ✅ No hardcoding needed
|
|
234
|
-
|
|
235
|
-
---
|
|
236
|
-
|
|
237
|
-
## Documentation Breakdown
|
|
238
|
-
|
|
239
|
-
### 16-alerts-system.md
|
|
240
|
-
- Alert System overview
|
|
241
|
-
- Quick start guide
|
|
242
|
-
- Configuration & API
|
|
243
|
-
- Common patterns
|
|
244
|
-
- Troubleshooting
|
|
245
|
-
- **Best for:** Understanding the system
|
|
246
|
-
|
|
247
|
-
### 17-alert-adapters.md
|
|
248
|
-
- Adapter pattern explanation
|
|
249
|
-
- All 7 built-in adapters documented
|
|
250
|
-
- Custom adapter creation
|
|
251
|
-
- Multi-severity patterns
|
|
252
|
-
- Registry API
|
|
253
|
-
- Real-world examples
|
|
254
|
-
- **Best for:** Creating custom adapters & advanced usage
|
|
255
|
-
|
|
256
|
-
### 18-alerts-implementation-summary.md
|
|
257
|
-
- What's implemented
|
|
258
|
-
- Architecture overview
|
|
259
|
-
- File modifications
|
|
260
|
-
- Design decisions
|
|
261
|
-
- Production checklist
|
|
262
|
-
- **Best for:** Technical overview & deployment
|
|
263
|
-
|
|
264
|
-
### ALERTS-QUICK-REFERENCE.md
|
|
265
|
-
- Setup channels (copy-paste ready)
|
|
266
|
-
- Define alerts
|
|
267
|
-
- Usage patterns
|
|
268
|
-
- API methods
|
|
269
|
-
- Environment variables
|
|
270
|
-
- Debugging tips
|
|
271
|
-
- **Best for:** Quick lookup & reference
|
|
272
|
-
|
|
273
|
-
### example-alerts.ts
|
|
274
|
-
- 6 complete examples:
|
|
275
|
-
1. Basic Telegram alerts
|
|
276
|
-
2. Multi-channel (Slack+Discord+Telegram)
|
|
277
|
-
3. Custom adapter
|
|
278
|
-
4. Environment-aware setup
|
|
279
|
-
5. Local testing
|
|
280
|
-
6. Dynamic configuration
|
|
281
|
-
- **Best for:** Copy-paste starting point
|
|
282
|
-
|
|
283
|
-
---
|
|
284
|
-
|
|
285
|
-
## Testing
|
|
286
|
-
|
|
287
|
-
### Local Testing
|
|
288
|
-
```bash
|
|
289
|
-
npx ts-node example-alerts.ts
|
|
290
|
-
```
|
|
291
|
-
|
|
292
|
-
### Manual Trigger
|
|
293
|
-
```typescript
|
|
294
|
-
await observability.alertManager?.checkAndTrigger('Alert Name', value);
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### Check History
|
|
298
|
-
```typescript
|
|
299
|
-
const history = observability.getAlertHistory();
|
|
300
|
-
console.log(history);
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
---
|
|
304
|
-
|
|
305
|
-
## Production Checklist
|
|
306
|
-
|
|
307
|
-
- ✅ Adapters implemented (7 total)
|
|
308
|
-
- ✅ Type safety verified
|
|
309
|
-
- ✅ Error handling in place
|
|
310
|
-
- ✅ Config validation per adapter
|
|
311
|
-
- ✅ Alert cooldown (60s)
|
|
312
|
-
- ✅ Alert history tracking
|
|
313
|
-
- ✅ Multiple channels support
|
|
314
|
-
- ✅ Documentation complete (4 files)
|
|
315
|
-
- ✅ Examples provided (6 patterns)
|
|
316
|
-
- ✅ Environment variables template
|
|
317
|
-
- ⚠️ Email/PagerDuty need service integration
|
|
318
|
-
- ⚠️ Rate limiting per channel (optional)
|
|
319
|
-
- ⚠️ Retry logic (optional)
|
|
320
|
-
|
|
321
|
-
---
|
|
322
|
-
|
|
323
|
-
## Next Steps (Optional Enhancements)
|
|
324
|
-
|
|
325
|
-
1. **System Metrics Monitoring**
|
|
326
|
-
- Auto-detect memory spike
|
|
327
|
-
- Auto-detect CPU spike
|
|
328
|
-
- Auto-detect server crash
|
|
329
|
-
- Auto-trigger alerts
|
|
330
|
-
|
|
331
|
-
2. **Email Implementation**
|
|
332
|
-
- Integrate SendGrid/Mailgun
|
|
333
|
-
- Email templates
|
|
334
|
-
|
|
335
|
-
3. **PagerDuty Implementation**
|
|
336
|
-
- Events API v2 integration
|
|
337
|
-
- Incident escalation
|
|
338
|
-
|
|
339
|
-
4. **Alert Dashboard**
|
|
340
|
-
- View active alerts
|
|
341
|
-
- Alert history UI
|
|
342
|
-
- Configure alerts via UI
|
|
343
|
-
|
|
344
|
-
5. **Advanced Features**
|
|
345
|
-
- Conditional retry logic
|
|
346
|
-
- Alert aggregation
|
|
347
|
-
- Rate limiting per channel
|
|
348
|
-
- Dead letter queue
|
|
349
|
-
|
|
350
|
-
---
|
|
351
|
-
|
|
352
|
-
## How to Extend
|
|
353
|
-
|
|
354
|
-
### Add New Adapter
|
|
355
|
-
|
|
356
|
-
1. Implement `AlertChannelAdapter` interface
|
|
357
|
-
2. Add validation logic
|
|
358
|
-
3. Implement `send()` method
|
|
359
|
-
4. Register with registry
|
|
360
|
-
5. Update documentation
|
|
361
|
-
|
|
362
|
-
```typescript
|
|
363
|
-
class MyAdapter implements AlertChannelAdapter {
|
|
364
|
-
async send(alert, value, config) { /* ... */ }
|
|
365
|
-
validate(config) { /* ... */ }
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
registry?.register('my-adapter', new MyAdapter());
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
---
|
|
372
|
-
|
|
373
|
-
## Support & Questions
|
|
374
|
-
|
|
375
|
-
- Read `16-alerts-system.md` for system overview
|
|
376
|
-
- Read `17-alert-adapters.md` for adapter details
|
|
377
|
-
- Check `example-alerts.ts` for usage examples
|
|
378
|
-
- See `ALERTS-QUICK-REFERENCE.md` for quick lookup
|
|
379
|
-
|
|
380
|
-
---
|
|
381
|
-
|
|
382
|
-
## Files Changed
|
|
383
|
-
|
|
384
|
-
### New Files Created
|
|
385
|
-
- ✨ `src/advanced/observability/adapters.ts`
|
|
386
|
-
- ✨ `documentation/16-alerts-system.md`
|
|
387
|
-
- ✨ `documentation/17-alert-adapters.md`
|
|
388
|
-
- ✨ `documentation/18-alerts-implementation-summary.md`
|
|
389
|
-
- ✨ `documentation/ALERTS-QUICK-REFERENCE.md`
|
|
390
|
-
- ✨ `example-alerts.ts`
|
|
391
|
-
- ✨ `.env.example.alerts`
|
|
392
|
-
|
|
393
|
-
### Modified Files
|
|
394
|
-
- 📝 `src/advanced/observability/index.ts`
|
|
395
|
-
- Import adapters
|
|
396
|
-
- Update AlertingOptions interface
|
|
397
|
-
- Refactor AlertManager
|
|
398
|
-
- Export adapter types
|
|
399
|
-
|
|
400
|
-
---
|
|
401
|
-
|
|
402
|
-
## Verification
|
|
403
|
-
|
|
404
|
-
```bash
|
|
405
|
-
# TypeScript compilation ✅
|
|
406
|
-
npx tsc --noEmit
|
|
407
|
-
|
|
408
|
-
# All files present ✅
|
|
409
|
-
ls -la src/advanced/observability/adapters.ts
|
|
410
|
-
ls -la documentation/16-*.md
|
|
411
|
-
ls -la documentation/17-*.md
|
|
412
|
-
ls -la documentation/18-*.md
|
|
413
|
-
ls -la documentation/ALERTS-QUICK-REFERENCE.md
|
|
414
|
-
ls -la example-alerts.ts
|
|
415
|
-
ls -la .env.example.alerts
|
|
416
|
-
```
|
|
417
|
-
|
|
418
|
-
---
|
|
419
|
-
|
|
420
|
-
**Status: PRODUCTION READY** 🚀
|
|
421
|
-
|
|
422
|
-
Siap untuk di-deploy ke production!
|
|
423
|
-
|
|
424
|
-
---
|
|
425
|
-
|
|
426
|
-
**Created:** December 3, 2025
|
|
427
|
-
**Version:** 1.0
|
|
428
|
-
**Author:** AI Assistant
|
|
429
|
-
|