@chidchanun/bcp 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # BCP Framework
2
2
 
3
- BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, guarded application flows, API routes, authentication, database access, validation, uploads, storage and standalone Node.js production deployment.
3
+ BCP Framework is a React full-stack framework for file-based routing, SSR, SPA navigation, server data loading, guarded application flows, API routes, authentication, authorization, database access, observability, validation, uploads, storage and standalone Node.js production deployment.
4
4
 
5
- > **Development target:** `0.2.5Authentication Platform v2`
5
+ > **Development target:** `0.2.7Observability Platform v2`
6
6
  >
7
- > `0.2.5` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
7
+ > `0.2.7` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
8
8
 
9
9
  ## 0.2 platform
10
10
 
11
- `0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, `0.2.2` added Configuration & Environment v2, `0.2.3` added Database Platform v2, `0.2.4` added Application Packaging, and `0.2.5` adds optional revocable authentication sessions and guest-aware route guards without intentionally removing the existing stateless JWT-cookie model.
11
+ `0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, `0.2.2` added Configuration & Environment v2, `0.2.3` added Database Platform v2, `0.2.4` added Application Packaging, `0.2.5` added Authentication Platform v2, `0.2.6` added Authorization & Security v2, and `0.2.7` adds dependency-free metrics, Prometheus exposition, request metrics and health/readiness checks without intentionally changing the existing application model.
12
12
 
13
13
  Machine-readable platform contracts:
14
14
 
@@ -31,13 +31,14 @@ docs/api-manifest.json
31
31
  | Routing | Static, dynamic, catch-all, optional catch-all and route groups |
32
32
  | Server data | Route `loader.ts`, request-scoped server APIs |
33
33
  | Mutations | Route-owned `actions.ts` and `<Form>` |
34
- | Authorization | `guard.ts`, `requireAuth()`, `requireGuest()`, `requireRole()` |
35
34
  | Authentication | JWT cookie sessions, optional server-side session stores, revocation, logout-all, idle timeout and rotation |
35
+ | Authorization | Auth/guest/role/permission route guards, flat permissions and resource-aware policies |
36
+ | Request security | Same-origin validation and signed CSRF tokens for unsafe mutations |
36
37
  | Middleware | Middleware System v2 with onion execution |
38
+ | Observability | Structured logs, counters/gauges/histograms, Prometheus output, request metrics and health/readiness checks |
37
39
  | Validation | Typed validators and structured validation errors |
38
40
  | Error handling | HTTP error helpers and consistent error responses |
39
41
  | Database | Provider-neutral MySQL, PostgreSQL and SQLite adapters, transactions, lifecycle and migrations |
40
- | Logging | Structured logger, request logger and request IDs |
41
42
  | Uploads | Buffered multipart helpers and production multipart streaming |
42
43
  | Storage | Local + S3-compatible storage, streaming, list/copy/move, metadata, bulk delete and signed URLs |
43
44
  | Caching | Response cache and revalidation primitives |
@@ -155,8 +156,6 @@ await db.connect();
155
156
  await db.disconnect();
156
157
  ```
157
158
 
158
- `db.close()` remains available for backward-compatible shutdown handling.
159
-
160
159
  Migration CLI:
161
160
 
162
161
  ```bash
@@ -166,8 +165,6 @@ bcp db status
166
165
  bcp db rollback
167
166
  ```
168
167
 
169
- BCP makes framework migration bookkeeping provider-aware. Application migration SQL itself is not automatically translated between SQL dialects.
170
-
171
168
  Read more:
172
169
 
173
170
  - [Database](docs/database.md)
@@ -175,7 +172,7 @@ Read more:
175
172
 
176
173
  ## Application Packaging — 0.2.4
177
174
 
178
- Create a fresh production build and convert it into a deployment-oriented package:
175
+ Create a fresh production build and deployment package:
179
176
 
180
177
  ```bash
181
178
  bcp package
@@ -200,8 +197,6 @@ Output:
200
197
  └─ README.md
201
198
  ```
202
199
 
203
- The package layer creates production-only dependency metadata, deployment/environment manifests, SHA-256 file integrity metadata and a Node 24 Alpine Docker starter.
204
-
205
200
  Read more:
206
201
 
207
202
  - [Application Packaging](docs/application-packaging.md)
@@ -209,7 +204,7 @@ Read more:
209
204
 
210
205
  ## Authentication Platform v2 — 0.2.5
211
206
 
212
- The existing stateless JWT-cookie mode remains available:
207
+ Stateless signed JWT-cookie authentication remains supported:
213
208
 
214
209
  ```ts
215
210
  import {
@@ -232,49 +227,169 @@ const sessionStore =
232
227
 
233
228
  export const appAuth =
234
229
  createAuth({
235
- store:
236
- sessionStore,
237
- idleTimeout:
238
- 60 * 30,
230
+ store: sessionStore,
231
+ idleTimeout: 60 * 30,
239
232
  });
240
233
  ```
241
234
 
242
- With a store configured, authentication requires both a valid signed JWT cookie and an active `sid` record.
235
+ With a store configured, authentication requires both a valid signed JWT cookie and an active `sid` record. The built-in memory store is intended for development/tests; production multi-instance deployments should implement `AuthSessionStore` with shared storage.
236
+
237
+ Read more:
238
+
239
+ - [Authentication](docs/authentication.md)
240
+ - [Auth Session Stores](docs/auth-session-store.md)
241
+ - [Auth Route Guards](docs/auth-route-guards.md)
243
242
 
244
- New lifecycle APIs:
243
+ ## Authorization & Security v2 — 0.2.6
244
+
245
+ Use flat permissions directly from `bcp/auth`:
245
246
 
246
247
  ```ts
247
- await appAuth.logout();
248
- await appAuth.logoutAll();
249
- await appAuth.revokeSession(sid);
250
- await appAuth.revokeUserSessions(userId);
251
- await appAuth.rotateSession();
252
- ```
248
+ import {
249
+ hasPermission,
250
+ requirePermission,
251
+ } from "bcp/auth";
253
252
 
254
- `idleTimeout` is enforced only when a server-side store is configured. BCP rejects the option in stateless-only mode rather than silently pretending to enforce inactivity expiration.
253
+ hasPermission(
254
+ user,
255
+ "users.read"
256
+ );
257
+
258
+ await requirePermission(
259
+ [
260
+ "users.read",
261
+ "users.write",
262
+ ],
263
+ {
264
+ match: "all",
265
+ }
266
+ );
267
+ ```
255
268
 
256
- Guest-only login/register routes can use:
269
+ Resource-aware policies:
257
270
 
258
271
  ```ts
259
272
  import {
260
- createGuestGuard,
273
+ authorize,
274
+ defineAuthorizationPolicy,
261
275
  } from "bcp/auth";
262
276
 
263
- export const guard =
264
- createGuestGuard({
265
- redirectTo:
266
- "/dashboard",
267
- });
277
+ const updateProject =
278
+ defineAuthorizationPolicy(
279
+ ({
280
+ user,
281
+ resource,
282
+ }) =>
283
+ resource.ownerId ===
284
+ user.id
285
+ );
286
+
287
+ await authorize(
288
+ updateProject,
289
+ {
290
+ user,
291
+ resource: project,
292
+ }
293
+ );
268
294
  ```
269
295
 
270
- The built-in memory session store is intended for development/tests and process-local prototypes. Production applications running multiple processes or containers should implement `AuthSessionStore` with shared durable storage such as Redis or a database.
296
+ Request-security helpers are exposed from `bcp/server`:
271
297
 
272
- Read more:
298
+ ```ts
299
+ import {
300
+ createCsrfToken,
301
+ requireCsrfRequest,
302
+ requireSameOriginRequest,
303
+ } from "bcp/server";
304
+ ```
273
305
 
274
- - [Authentication](docs/authentication.md)
275
- - [Auth Session Stores](docs/auth-session-store.md)
276
- - [Auth Route Guards](docs/auth-route-guards.md)
277
- - [JWT Sessions](docs/session-auth.md)
306
+ Read more: [Authorization & Security v2](docs/authorization-security.md)
307
+
308
+ ## Observability Platform v2 — 0.2.7
309
+
310
+ Create one application metrics registry:
311
+
312
+ ```ts
313
+ import {
314
+ createMetricsRegistry,
315
+ } from "bcp/observability";
316
+
317
+ export const metrics =
318
+ createMetricsRegistry();
319
+ ```
320
+
321
+ Supported metric types:
322
+
323
+ ```text
324
+ counter
325
+ gauge
326
+ histogram
327
+ ```
328
+
329
+ Expose Prometheus-compatible text:
330
+
331
+ ```ts
332
+ import {
333
+ createMetricsResponse,
334
+ } from "bcp/observability";
335
+
336
+ export function GET() {
337
+ return createMetricsResponse(
338
+ metrics
339
+ );
340
+ }
341
+ ```
342
+
343
+ Instrument HTTP requests through Middleware System v2:
344
+
345
+ ```ts
346
+ import {
347
+ createRequestMetricsMiddleware,
348
+ } from "bcp/observability";
349
+
350
+ export const requestMetrics =
351
+ createRequestMetricsMiddleware(
352
+ metrics
353
+ );
354
+ ```
355
+
356
+ Default request metrics use only bounded labels:
357
+
358
+ ```text
359
+ bcp_http_requests_total{method,status}
360
+ bcp_http_request_duration_seconds{method,status}
361
+ ```
362
+
363
+ Raw paths are not attached by default.
364
+
365
+ Health/readiness registry:
366
+
367
+ ```ts
368
+ import {
369
+ createHealthRegistry,
370
+ } from "bcp/observability";
371
+
372
+ export const health =
373
+ createHealthRegistry();
374
+
375
+ health.register(
376
+ "database",
377
+ async () => {
378
+ await db.query("SELECT 1");
379
+ return true;
380
+ }
381
+ );
382
+ ```
383
+
384
+ Use:
385
+
386
+ ```ts
387
+ return health.response();
388
+ ```
389
+
390
+ Health responses return `200` when every check passes and `503` when any registered dependency is unhealthy or times out.
391
+
392
+ Read more: [Observability Platform v2](docs/observability.md)
278
393
 
279
394
  ## Public entrypoints
280
395
 
@@ -289,6 +404,7 @@ bcp/validation
289
404
  bcp/error
290
405
  bcp/database
291
406
  bcp/auth
407
+ bcp/observability
292
408
  bcp/server
293
409
  bcp/server-only
294
410
  bcp/middleware
@@ -337,40 +453,23 @@ bcp generate middleware
337
453
  bcp generate migration create_users
338
454
  ```
339
455
 
340
- Page/API/middleware generators require `--force` before replacing an existing scaffold target.
341
-
342
456
  ## Application model
343
457
 
344
458
  ```text
345
459
  Browser
346
460
 
347
- Security / middleware / cache
461
+ Origin / CSRF / middleware / cache
348
462
 
349
- Route guard
463
+ Authentication + authorization guard
350
464
 
351
465
  Loader / action / API route
352
466
 
353
467
  React SSR
354
468
 
355
469
  Hydration / SPA navigation
356
- ```
357
-
358
- Typical route structure:
359
470
 
360
- ```text
361
- app/
362
- ├─ layout.tsx
363
- ├─ page.tsx
364
- ├─ dashboard/
365
- │ ├─ guard.ts
366
- │ └─ users/
367
- │ └─ [id]/
368
- │ ├─ loader.ts
369
- │ ├─ actions.ts
370
- │ └─ page.tsx
371
- └─ api/
372
- └─ upload/
373
- └─ route.ts
471
+ Operational side channels:
472
+ structured logs + metrics + health/readiness
374
473
  ```
375
474
 
376
475
  ## Production build
@@ -388,7 +487,7 @@ Deployment package:
388
487
  bcp package
389
488
  ```
390
489
 
391
- Both current targets remain Node.js `standalone-node` applications. Production hardening includes configurable request/header/keep-alive/shutdown timeouts, trusted-proxy handling and graceful `SIGTERM` / `SIGINT` shutdown.
490
+ Both current targets remain Node.js `standalone-node` applications.
392
491
 
393
492
  ## Documentation Platform
394
493
 
@@ -402,8 +501,6 @@ docs/platform-manifest.json
402
501
  docs/api-manifest.json
403
502
  ```
404
503
 
405
- The manifests provide navigation order, routes, Markdown sources, version/release state, public entrypoints and API guide ownership.
406
-
407
504
  ## Release validation
408
505
 
409
506
  Framework releases must pass:
@@ -418,7 +515,7 @@ npm run test:e2e
418
515
  npm run rc:check
419
516
  ```
420
517
 
421
- `0.2.5` adds Authentication Platform v2 unit and prepared-package smoke checks covering session-store registration, revocation, logout-all, idle timeout, rotation and guest guards.
518
+ `0.2.7` adds Observability Platform v2 unit and prepared-package smoke checks covering metrics, Prometheus exposition, request timing, cardinality-safe default labels, health/readiness responses and timeout handling.
422
519
 
423
520
  Do not tag or publish until the final release commit passes the complete RC sequence.
424
521
 
@@ -438,12 +535,14 @@ Do not tag or publish until the final release commit passes the complete RC sequ
438
535
  | `0.2.3` | Database Platform v2 |
439
536
  | `0.2.4` | Application Packaging |
440
537
  | `0.2.5` | Authentication Platform v2 |
538
+ | `0.2.6` | Authorization & Security v2 |
539
+ | `0.2.7` | Observability Platform v2 |
441
540
 
442
541
  ## Roadmap
443
542
 
444
- `0.2.5Authentication Platform v2` establishes optional revocable server-side auth state while preserving the original stateless JWT-cookie path.
543
+ `0.2.7Observability Platform v2` establishes process-level metrics and health/readiness contracts on top of the existing structured logging and Middleware System v2 runtime.
445
544
 
446
- A later security/authorization milestone can build on this session contract for broader permission and security policy features. Native `.exe`, desktop and mobile compilation remain later roadmap work.
545
+ Future `0.2.x` work can add distributed tracing or exporter integrations without changing the application metrics/health contract introduced here. Native `.exe`, desktop and mobile compilation remain later roadmap work.
447
546
 
448
547
  ## License
449
548
 
package/docs/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The `docs/` directory is the documentation source of truth for BCP Framework and is organized for **`bcp-docs-web`**.
4
4
 
5
- > **Documentation target:** BCP Framework `0.2.5Authentication Platform v2`
5
+ > **Documentation target:** BCP Framework `0.2.7Observability Platform v2`
6
6
  >
7
7
  > **Release state:** unreleased development target until RC validation, tagging and npm publication complete.
8
8
 
@@ -51,62 +51,50 @@ Framework source and tests remain authoritative for runtime behavior.
51
51
  | `0.2.3` | Database Platform v2 |
52
52
  | `0.2.4` | Application Packaging |
53
53
  | `0.2.5` | Authentication Platform v2 |
54
+ | `0.2.6` | Authorization & Security v2 |
55
+ | `0.2.7` | Observability Platform v2 |
54
56
 
55
- ## 0.2.5Authentication Platform v2
57
+ ## 0.2.7Observability Platform v2
56
58
 
57
- `0.2.5` keeps stateless signed JWT-cookie authentication as the default and adds optional server-side session state for revocation and inactivity policy.
59
+ `0.2.7` adds a server-only observability layer without adding third-party runtime dependencies.
58
60
 
59
61
  New/updated documentation sources:
60
62
 
61
63
  | Source | Purpose |
62
64
  | --- | --- |
63
- | `authentication.md` | Auth core, revocation, logout-all, rotation and idle timeout |
64
- | `auth-session-store.md` | `AuthSessionStore`, memory adapter and production-store guidance |
65
- | `auth-route-guards.md` | Auth, guest and role route guards |
66
- | `api-reference.md` | Public Authentication Platform v2 exports |
67
- | `platform-manifest.json` | Authentication v2 capability flags |
68
- | `api-manifest.json` | `bcp/auth` guide ownership |
69
- | `releases/0.2.5.md` | Authentication Platform v2 release notes |
65
+ | `observability.md` | Metrics registry, Prometheus output, request metrics and health/readiness checks |
66
+ | `api-reference.md` | Public `bcp/observability` exports |
67
+ | `platform-manifest.json` | Observability capability flags and new public entrypoint |
68
+ | `api-manifest.json` | `bcp/observability` guide ownership |
69
+ | `docs-web-manifest.json` | Observability navigation and `0.2.7` release route |
70
+ | `releases/0.2.7.md` | Observability Platform v2 release notes |
70
71
 
71
- Primary public entrypoint:
72
+ Primary APIs:
72
73
 
73
74
  ```ts
74
75
  import {
75
- auth,
76
- createAuth,
77
- createMemoryAuthSessionStore,
78
- login,
79
- logout,
80
- logoutAll,
81
- requireAuth,
82
- requireGuest,
83
- requireRole,
84
- } from "bcp/auth";
76
+ createHealthRegistry,
77
+ createMetricsRegistry,
78
+ createMetricsResponse,
79
+ createRequestMetricsMiddleware,
80
+ } from "bcp/observability";
85
81
  ```
86
82
 
87
- ## Authentication security model
88
-
89
- Default mode:
83
+ Runtime model:
90
84
 
91
85
  ```text
92
- signed HttpOnly JWT cookie
93
-
94
- signature + expiry validation
95
-
96
- authenticated session
86
+ structured logs
87
+ +
88
+ process-local metrics
89
+ +
90
+ Prometheus exposition
91
+ +
92
+ health/readiness checks
97
93
  ```
98
94
 
99
- Optional revocable mode:
100
-
101
- ```text
102
- signed HttpOnly JWT cookie
103
- +
104
- server-side sid store
105
-
106
- revocable authenticated session
107
- ```
95
+ The request metrics middleware intentionally uses bounded `method` and `status` labels by default rather than raw paths.
108
96
 
109
- The built-in memory store is intended for development/tests. Multi-process production systems should implement `AuthSessionStore` using shared durable storage.
97
+ The built-in metrics registry is process-local; distributed aggregation remains deployment infrastructure or future exporter work.
110
98
 
111
99
  ## Update rule
112
100
 
@@ -130,7 +118,7 @@ Current sections:
130
118
  ```text
131
119
  Getting Started
132
120
  Routing & Data
133
- Authentication
121
+ Authentication & Authorization
134
122
  Database
135
123
  Runtime & Infrastructure
136
124
  Storage & Uploads
@@ -145,12 +133,13 @@ Important current routes:
145
133
  | Website route | Markdown source |
146
134
  | --- | --- |
147
135
  | `/docs/authentication` | `authentication.md` |
148
- | `/docs/auth-session-store` | `auth-session-store.md` |
149
- | `/docs/auth-route-guards` | `auth-route-guards.md` |
136
+ | `/docs/authorization-security` | `authorization-security.md` |
137
+ | `/docs/observability` | `observability.md` |
138
+ | `/docs/development-logging` | `development-logging.md` |
150
139
  | `/docs/application-packaging` | `application-packaging.md` |
151
140
  | `/docs/database` | `database.md` |
152
141
  | `/docs/api-reference` | `api-reference.md` |
153
- | `/releases/0.2.5` | `releases/0.2.5.md` |
142
+ | `/releases/0.2.7` | `releases/0.2.7.md` |
154
143
 
155
144
  Every route/source pair is validated by unit tests.
156
145
 
@@ -190,6 +179,7 @@ bcp/validation
190
179
  bcp/error
191
180
  bcp/database
192
181
  bcp/auth
182
+ bcp/observability
193
183
  bcp/server
194
184
  bcp/server-only
195
185
  bcp/middleware
@@ -229,7 +219,7 @@ synchronize CMS/search/navigation
229
219
 
230
220
  ## Release validation
231
221
 
232
- Before publishing `0.2.5`:
222
+ Before publishing `0.2.7`:
233
223
 
234
224
  ```bash
235
225
  npm run typecheck
@@ -240,16 +230,16 @@ npm run test:e2e
240
230
  npm run rc:check
241
231
  ```
242
232
 
243
- Authentication Platform v2 validation covers:
233
+ Observability Platform v2 validation covers:
244
234
 
245
- - stateless JWT backward compatibility,
246
- - session-store registration and lookup,
247
- - session revocation,
248
- - logout-all,
249
- - idle timeout,
250
- - rotation with old-session revocation,
251
- - guest route guards,
252
- - public `bcp/auth` exports,
235
+ - counter/gauge/histogram behavior,
236
+ - Prometheus exposition,
237
+ - metric definition validation,
238
+ - request count and duration middleware,
239
+ - cardinality-safe default request labels,
240
+ - health/readiness response semantics,
241
+ - health check timeout handling,
242
+ - public `bcp/observability` exports,
253
243
  - prepared npm package contents,
254
244
  - docs/platform/API version parity.
255
245
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "framework": "bcp",
4
- "version": "0.2.5",
4
+ "version": "0.2.7",
5
5
  "releaseState": "unreleased",
6
6
  "coverage": "public-entrypoints",
7
7
  "entrypoints": [
@@ -85,22 +85,35 @@
85
85
  "source": "packages/client/src/auth.ts",
86
86
  "environment": "server",
87
87
  "route": "/docs/api-reference#bcp-auth",
88
- "summary": "Authentication Platform v2 with JWT cookies, optional revocable session stores, idle timeout, logout-all and auth/guest/role route guards.",
88
+ "summary": "Authentication Platform v2 plus permission checks, authorization policies and auth/guest/role/permission route guards.",
89
89
  "guides": [
90
90
  "/docs/authentication",
91
91
  "/docs/auth-session-store",
92
92
  "/docs/auth-route-guards",
93
+ "/docs/authorization-security",
93
94
  "/docs/session-auth"
94
95
  ]
95
96
  },
97
+ {
98
+ "package": "bcp/observability",
99
+ "source": "packages/client/src/observability.ts",
100
+ "environment": "server",
101
+ "route": "/docs/api-reference#bcp-observability",
102
+ "summary": "In-process metrics, Prometheus exposition, request metrics middleware and health/readiness checks.",
103
+ "guides": [
104
+ "/docs/observability",
105
+ "/docs/development-logging"
106
+ ]
107
+ },
96
108
  {
97
109
  "package": "bcp/server",
98
110
  "source": "packages/client/src/server.ts",
99
111
  "environment": "server",
100
112
  "route": "/docs/api-reference#bcp-server",
101
- "summary": "Request context, cookies, logging, production hardening, upload, storage, response and session APIs.",
113
+ "summary": "Request context, cookies, CSRF/same-origin protection, logging, production hardening, upload, storage, response and session APIs.",
102
114
  "guides": [
103
115
  "/docs/server-request-apis",
116
+ "/docs/authorization-security",
104
117
  "/docs/file-upload",
105
118
  "/docs/storage",
106
119
  "/docs/storage-ecosystem",