@chidchanun/bcp 0.2.3 → 0.2.5

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
@@ -2,13 +2,13 @@
2
2
 
3
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.
4
4
 
5
- > **Development target:** `0.2.3Database Platform v2`
5
+ > **Development target:** `0.2.5Authentication Platform v2`
6
6
  >
7
- > `0.2.3` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
7
+ > `0.2.5` 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, and `0.2.3` adds a provider-neutral SQL database platform with MySQL, PostgreSQL and SQLite support without intentionally removing public application entrypoints.
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.
12
12
 
13
13
  Machine-readable platform contracts:
14
14
 
@@ -31,8 +31,8 @@ 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()`, `requireRole()` |
35
- | Authentication | JWT cookie sessions and auth helpers |
34
+ | Authorization | `guard.ts`, `requireAuth()`, `requireGuest()`, `requireRole()` |
35
+ | Authentication | JWT cookie sessions, optional server-side session stores, revocation, logout-all, idle timeout and rotation |
36
36
  | Middleware | Middleware System v2 with onion execution |
37
37
  | Validation | Typed validators and structured validation errors |
38
38
  | Error handling | HTTP error helpers and consistent error responses |
@@ -43,7 +43,7 @@ docs/api-manifest.json
43
43
  | Caching | Response cache and revalidation primitives |
44
44
  | Configuration | Typed `bcp.config.*`, optional `bcp.environment.*`, startup diagnostics and `bcp config check` |
45
45
  | Developer tools | Generators, Doctor/Inspect v2, updater, route inspection and project metadata |
46
- | Production | Standalone Node.js build, hardening gateway, graceful shutdown, trusted proxy controls and HTTP timeouts |
46
+ | Production | Standalone Node.js build, application packaging, production dependency pruning, deployment manifests, Docker starter, hardening and graceful shutdown |
47
47
  | Documentation | Manifest-driven docs navigation, platform metadata and public API reference |
48
48
 
49
49
  ## Requirements
@@ -80,7 +80,7 @@ Generated projects normally keep one framework dependency key:
80
80
 
81
81
  Do not install both `bcp` and a second direct `@chidchanun/bcp` dependency in the same application.
82
82
 
83
- ## Configuration
83
+ ## Configuration & environment
84
84
 
85
85
  Framework configuration stays in one of:
86
86
 
@@ -91,29 +91,16 @@ bcp.config.js
91
91
  bcp.config.mjs
92
92
  ```
93
93
 
94
- Example:
94
+ Application environment validation can be declared in:
95
95
 
96
- ```ts
97
- import {
98
- defineConfig,
99
- } from "bcp/config";
100
-
101
- export default defineConfig({
102
- server: {
103
- port: 3000,
104
- hostname: "0.0.0.0",
105
- },
106
- build: {
107
- minify: true,
108
- sourceMaps: false,
109
- },
110
- security: {
111
- poweredByHeader: false,
112
- },
113
- });
96
+ ```text
97
+ bcp.environment.ts
98
+ bcp.environment.mts
99
+ bcp.environment.js
100
+ bcp.environment.mjs
114
101
  ```
115
102
 
116
- Configuration precedence remains:
103
+ Configuration precedence is:
117
104
 
118
105
  ```text
119
106
  CLI override
@@ -125,157 +112,169 @@ bcp.config.*
125
112
  framework defaults
126
113
  ```
127
114
 
128
- Read more: [Configuration](docs/configuration.md)
115
+ Validate configuration and declared environment values with:
129
116
 
130
- ## Environment Validation — 0.2.2
117
+ ```bash
118
+ bcp config check
119
+ bcp config check --json
120
+ ```
131
121
 
132
- Application-specific variables can be declared in an optional environment schema:
122
+ Variables beginning with `BCP_PUBLIC_` may be embedded in browser output. Never expose application secrets through public-prefixed variables.
133
123
 
134
- ```text
135
- bcp.environment.ts
136
- ```
124
+ Read more:
137
125
 
138
- Example:
126
+ - [Configuration](docs/configuration.md)
127
+ - [Environment Validation](docs/environment-validation.md)
128
+
129
+ ## Database Platform v2 — 0.2.3
130
+
131
+ Application code uses one server-only database entrypoint across supported SQL providers:
139
132
 
140
133
  ```ts
141
134
  import {
142
- defineEnvironment,
143
- } from "bcp/config";
144
-
145
- export default defineEnvironment({
146
- DB_HOST: {
147
- type: "string",
148
- required: true,
149
- },
150
-
151
- DB_PORT: {
152
- type: "number",
153
- default: 3306,
154
- min: 1,
155
- max: 65535,
156
- },
157
-
158
- SESSION_SECRET: {
159
- type: "string",
160
- required: true,
161
- secret: true,
162
- minLength: 32,
163
- },
164
-
165
- FEATURE_ENABLED: {
166
- type: "boolean",
167
- default: false,
168
- },
169
-
170
- BCP_PUBLIC_API_URL: {
171
- type: "url",
172
- required: true,
173
- },
174
- });
135
+ db,
136
+ createDatabase,
137
+ } from "bcp/database";
175
138
  ```
176
139
 
177
- Supported types:
140
+ Built-in SQL providers:
178
141
 
179
142
  ```text
180
- string
181
- number
182
- boolean
183
- url
143
+ mysql
144
+ postgresql
145
+ sqlite
184
146
  ```
185
147
 
186
- Validate the current project:
148
+ Lifecycle control:
187
149
 
188
- ```bash
189
- bcp config check
190
- ```
150
+ ```ts
151
+ await db.connect();
191
152
 
192
- JSON diagnostics:
153
+ // application work
193
154
 
194
- ```bash
195
- bcp config check --json
155
+ await db.disconnect();
196
156
  ```
197
157
 
198
- On Windows, where Microsoft SQL Server may provide another `bcp.exe`, prefer:
158
+ `db.close()` remains available for backward-compatible shutdown handling.
199
159
 
200
- ```powershell
201
- npm exec -- bcp-framework config check
202
- npm exec -- bcp-framework config check --json
160
+ Migration CLI:
161
+
162
+ ```bash
163
+ bcp db create create_users
164
+ bcp db migrate
165
+ bcp db status
166
+ bcp db rollback
203
167
  ```
204
168
 
205
- `bcp dev` and `bcp build` also validate `bcp.environment.*` before startup/build. Invalid required values fail early.
169
+ BCP makes framework migration bookkeeping provider-aware. Application migration SQL itself is not automatically translated between SQL dialects.
206
170
 
207
- The development supervisor watches:
171
+ Read more:
208
172
 
209
- ```text
210
- .env*
211
- bcp.config.*
212
- bcp.environment.*
213
- ```
173
+ - [Database](docs/database.md)
174
+ - [Database Migrations](docs/database-migrations.md)
214
175
 
215
- and restarts the worker when one of those files changes.
176
+ ## Application Packaging 0.2.4
216
177
 
217
- ### Secret safety
178
+ Create a fresh production build and convert it into a deployment-oriented package:
218
179
 
219
- Variables beginning with `BCP_PUBLIC_` can be embedded into browser bundles.
180
+ ```bash
181
+ bcp package
182
+ ```
220
183
 
221
- A variable marked:
184
+ Output:
222
185
 
223
- ```ts
224
- secret: true
186
+ ```text
187
+ .bcp-framework/package/
188
+ ├─ client/
189
+ ├─ server/
190
+ │ └─ server.mjs
191
+ ├─ public/ # when present
192
+ ├─ manifest.json
193
+ ├─ package.json
194
+ ├─ package-lock.json # when a safe npm v3 production lock can be derived
195
+ ├─ bcp.package.json
196
+ ├─ bcp.deployment.json
197
+ ├─ bcp.env.json
198
+ ├─ Dockerfile
199
+ ├─ .dockerignore
200
+ └─ README.md
225
201
  ```
226
202
 
227
- must not use `BCP_PUBLIC_`. BCP reports this as a configuration error.
203
+ The package layer creates production-only dependency metadata, deployment/environment manifests, SHA-256 file integrity metadata and a Node 24 Alpine Docker starter.
228
204
 
229
- `secret: true` is tooling metadata; it does not encrypt environment values.
205
+ Read more:
230
206
 
231
- Read more: [Environment Validation](docs/environment-validation.md)
207
+ - [Application Packaging](docs/application-packaging.md)
208
+ - [Deployment](docs/deployment.md)
232
209
 
233
- ## Database Platform v2 — 0.2.3
210
+ ## Authentication Platform v2 — 0.2.5
234
211
 
235
- Application code uses the same server-only entrypoint across supported SQL providers:
212
+ The existing stateless JWT-cookie mode remains available:
236
213
 
237
214
  ```ts
238
215
  import {
239
- db,
240
- createDatabase,
241
- } from "bcp/database";
216
+ auth,
217
+ login,
218
+ logout,
219
+ } from "bcp/auth";
242
220
  ```
243
221
 
244
- Built-in providers:
222
+ Applications that need centralized revocation can add a server-side session store:
245
223
 
246
- ```text
247
- mysql
248
- postgresql
249
- sqlite
224
+ ```ts
225
+ import {
226
+ createAuth,
227
+ createMemoryAuthSessionStore,
228
+ } from "bcp/auth";
229
+
230
+ const sessionStore =
231
+ createMemoryAuthSessionStore();
232
+
233
+ export const appAuth =
234
+ createAuth({
235
+ store:
236
+ sessionStore,
237
+ idleTimeout:
238
+ 60 * 30,
239
+ });
250
240
  ```
251
241
 
252
- Connections remain lazy, while explicit lifecycle control is available when needed:
242
+ With a store configured, authentication requires both a valid signed JWT cookie and an active `sid` record.
253
243
 
254
- ```ts
255
- await db.connect();
244
+ New lifecycle APIs:
256
245
 
257
- // application work
258
-
259
- await db.disconnect();
246
+ ```ts
247
+ await appAuth.logout();
248
+ await appAuth.logoutAll();
249
+ await appAuth.revokeSession(sid);
250
+ await appAuth.revokeUserSessions(userId);
251
+ await appAuth.rotateSession();
260
252
  ```
261
253
 
262
- `db.close()` remains available for backward-compatible shutdown handling.
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.
263
255
 
264
- Database migrations use the same CLI across providers:
256
+ Guest-only login/register routes can use:
265
257
 
266
- ```bash
267
- bcp db create create_users
268
- bcp db migrate
269
- bcp db status
270
- bcp db rollback
258
+ ```ts
259
+ import {
260
+ createGuestGuard,
261
+ } from "bcp/auth";
262
+
263
+ export const guard =
264
+ createGuestGuard({
265
+ redirectTo:
266
+ "/dashboard",
267
+ });
271
268
  ```
272
269
 
273
- BCP makes its internal migration bookkeeping provider-aware. Application SQL itself is not automatically translated between SQL dialects.
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.
274
271
 
275
272
  Read more:
276
273
 
277
- - [Database](docs/database.md)
278
- - [Database Migrations](docs/database-migrations.md)
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)
279
278
 
280
279
  ## Public entrypoints
281
280
 
@@ -310,6 +309,7 @@ Core commands:
310
309
  ```bash
311
310
  bcp dev
312
311
  bcp build
312
+ bcp package
313
313
  bcp start
314
314
  bcp routes
315
315
  bcp update
@@ -375,32 +375,20 @@ app/
375
375
 
376
376
  ## Production build
377
377
 
378
+ Raw standalone build:
379
+
378
380
  ```bash
379
381
  npm run build
380
382
  npm run start
381
383
  ```
382
384
 
383
- Standalone output:
384
-
385
- ```text
386
- .bcp-framework/build/
387
- ├─ client/
388
- ├─ public/
389
- └─ server/
390
- └─ server.mjs
391
- ```
392
-
393
- The current production target remains:
385
+ Deployment package:
394
386
 
395
- ```text
396
- standalone-node
387
+ ```bash
388
+ bcp package
397
389
  ```
398
390
 
399
- Native `.exe`, desktop and mobile compilation remain later roadmap work.
400
-
401
- Production hardening includes configurable request/header/keep-alive/shutdown timeouts, trusted-proxy handling and graceful `SIGTERM` / `SIGINT` shutdown.
402
-
403
- Read more: [Production Hardening](docs/production-hardening.md)
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.
404
392
 
405
393
  ## Documentation Platform
406
394
 
@@ -416,12 +404,6 @@ docs/api-manifest.json
416
404
 
417
405
  The manifests provide navigation order, routes, Markdown sources, version/release state, public entrypoints and API guide ownership.
418
406
 
419
- Read more:
420
-
421
- - [Documentation Source Map](docs/README.md)
422
- - [Documentation Platform](docs/documentation-platform.md)
423
- - [Environment Validation](docs/environment-validation.md)
424
-
425
407
  ## Release validation
426
408
 
427
409
  Framework releases must pass:
@@ -436,7 +418,7 @@ npm run test:e2e
436
418
  npm run rc:check
437
419
  ```
438
420
 
439
- `0.2.3` adds Database Platform v2 unit/package checks covering the adapter contract, MySQL/PostgreSQL/SQLite provider resolution, explicit connection lifecycle, failed-initialization retry behavior and provider-specific migration bookkeeping.
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.
440
422
 
441
423
  Do not tag or publish until the final release commit passes the complete RC sequence.
442
424
 
@@ -454,12 +436,14 @@ Do not tag or publish until the final release commit passes the complete RC sequ
454
436
  | `0.2.1` | Documentation Platform |
455
437
  | `0.2.2` | Configuration & Environment v2 |
456
438
  | `0.2.3` | Database Platform v2 |
439
+ | `0.2.4` | Application Packaging |
440
+ | `0.2.5` | Authentication Platform v2 |
457
441
 
458
442
  ## Roadmap
459
443
 
460
- `0.2.3Database Platform v2` completes the planned database adapter contract, PostgreSQL support, SQLite support, connection lifecycle improvements and migration consistency across the built-in SQL providers.
444
+ `0.2.5Authentication Platform v2` establishes optional revocable server-side auth state while preserving the original stateless JWT-cookie path.
461
445
 
462
- The next planned `0.2.x` focus is application packaging. Native `.exe`, desktop and mobile compilation remain later roadmap work.
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.
463
447
 
464
448
  ## License
465
449