@chidchanun/bcp 0.2.0 → 0.2.2

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,38 +2,27 @@
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.0Framework Platform`
5
+ > **Development target:** `0.2.2Configuration & Environment v2`
6
6
  >
7
- > `0.2.0` establishes the first explicit platform baseline for BCP. It remains an unreleased development target until local validation, RC checks, tagging and npm publication complete.
7
+ > `0.2.2` is an unreleased development target until local validation, RC checks, tagging and npm publication complete.
8
8
 
9
- ## Platform baseline — 0.2.0
9
+ ## 0.2 platform
10
10
 
11
- BCP `0.2.0` consolidates the capabilities built across the `0.1.x` series into a documented and testable platform contract.
11
+ `0.2.0` established the Framework Platform baseline, `0.2.1` added the Documentation Platform, and `0.2.2` adds typed application environment validation and configuration diagnostics without intentionally removing public application entrypoints.
12
12
 
13
- New platform sources:
13
+ Machine-readable platform contracts:
14
14
 
15
15
  ```text
16
16
  docs/platform-manifest.json
17
- -> version, runtime target, public entrypoints and capability metadata
17
+ -> runtime target, capabilities and compatibility
18
18
 
19
19
  docs/docs-web-manifest.json
20
- -> docs-web sections, routes, Markdown sources and releases
20
+ -> documentation navigation, routes and releases
21
21
 
22
- docs/platform-contract.md
23
- -> public platform/compatibility contract
24
-
25
- docs/migration-0.2.md
26
- -> application upgrade guide
22
+ docs/api-manifest.json
23
+ -> public package entrypoints and guide ownership
27
24
  ```
28
25
 
29
- The package release pipeline now verifies the platform contract against the prepared npm artifact so accidental public-export/version drift fails package validation.
30
-
31
- Read more:
32
-
33
- - [Framework Platform Contract](docs/platform-contract.md)
34
- - [Migrating to 0.2.0](docs/migration-0.2.md)
35
- - [Platform Manifest](docs/platform-manifest.json)
36
-
37
26
  ## Current capabilities
38
27
 
39
28
  | Area | Capability |
@@ -45,16 +34,17 @@ Read more:
45
34
  | Authorization | `guard.ts`, `requireAuth()`, `requireRole()` |
46
35
  | Authentication | JWT cookie sessions and auth helpers |
47
36
  | Middleware | Middleware System v2 with onion execution |
48
- | Validation | Typed validation helpers and structured validation errors |
37
+ | Validation | Typed validators and structured validation errors |
49
38
  | Error handling | HTTP error helpers and consistent error responses |
50
39
  | Database | MySQL helpers, transactions and migrations |
51
40
  | Logging | Structured logger, request logger and request IDs |
52
41
  | Uploads | Buffered multipart helpers and production multipart streaming |
53
42
  | Storage | Local + S3-compatible storage, streaming, list/copy/move, metadata, bulk delete and signed URLs |
54
43
  | Caching | Response cache and revalidation primitives |
44
+ | Configuration | Typed `bcp.config.*`, optional `bcp.environment.*`, startup diagnostics and `bcp config check` |
55
45
  | Developer tools | Generators, Doctor/Inspect v2, updater, route inspection and project metadata |
56
46
  | Production | Standalone Node.js build, hardening gateway, graceful shutdown, trusted proxy controls and HTTP timeouts |
57
- | Documentation | Markdown source + machine-readable docs-web/platform manifests |
47
+ | Documentation | Manifest-driven docs navigation, platform metadata and public API reference |
58
48
 
59
49
  ## Requirements
60
50
 
@@ -62,7 +52,7 @@ Read more:
62
52
  - React `19`
63
53
  - npm
64
54
 
65
- Database framework primitives currently target MySQL. `create-bcp-app` can also scaffold PostgreSQL, SQLite and MongoDB application helpers.
55
+ Database framework primitives currently target MySQL.
66
56
 
67
57
  ## Quick start
68
58
 
@@ -82,45 +72,161 @@ Generated projects normally keep one framework dependency key:
82
72
  }
83
73
  ```
84
74
 
85
- Do not install both `bcp` and a second direct `@chidchanun/bcp` dependency in the same application; duplicate framework copies can create separate React/framework contexts.
75
+ Do not install both `bcp` and a second direct `@chidchanun/bcp` dependency in the same application.
86
76
 
87
- ## Application model
77
+ ## Configuration
78
+
79
+ Framework configuration stays in one of:
88
80
 
89
81
  ```text
90
- Browser
91
-
92
- Security / middleware / cache
93
-
94
- Route guard
95
-
96
- Loader / action / API route
97
-
98
- React SSR
99
-
100
- Hydration / SPA navigation
82
+ bcp.config.ts
83
+ bcp.config.mts
84
+ bcp.config.js
85
+ bcp.config.mjs
101
86
  ```
102
87
 
103
- Typical route structure:
88
+ Example:
89
+
90
+ ```ts
91
+ import {
92
+ defineConfig,
93
+ } from "bcp/config";
94
+
95
+ export default defineConfig({
96
+ server: {
97
+ port: 3000,
98
+ hostname: "0.0.0.0",
99
+ },
100
+ build: {
101
+ minify: true,
102
+ sourceMaps: false,
103
+ },
104
+ security: {
105
+ poweredByHeader: false,
106
+ },
107
+ });
108
+ ```
109
+
110
+ Configuration precedence remains:
104
111
 
105
112
  ```text
106
- app/
107
- ├─ layout.tsx
108
- ├─ page.tsx
109
- ├─ dashboard/
110
- │ ├─ guard.ts
111
- │ └─ users/
112
- │ └─ [id]/
113
- │ ├─ loader.ts
114
- │ ├─ actions.ts
115
- │ └─ page.tsx
116
- └─ api/
117
- └─ upload/
118
- └─ route.ts
113
+ CLI override
114
+
115
+ BCP_* environment
116
+
117
+ bcp.config.*
118
+
119
+ framework defaults
120
+ ```
121
+
122
+ Read more: [Configuration](docs/configuration.md)
123
+
124
+ ## Environment Validation — 0.2.2
125
+
126
+ Application-specific variables can be declared in an optional environment schema:
127
+
128
+ ```text
129
+ bcp.environment.ts
130
+ ```
131
+
132
+ Example:
133
+
134
+ ```ts
135
+ import {
136
+ defineEnvironment,
137
+ } from "bcp/config";
138
+
139
+ export default defineEnvironment({
140
+ DB_HOST: {
141
+ type: "string",
142
+ required: true,
143
+ },
144
+
145
+ DB_PORT: {
146
+ type: "number",
147
+ default: 3306,
148
+ min: 1,
149
+ max: 65535,
150
+ },
151
+
152
+ SESSION_SECRET: {
153
+ type: "string",
154
+ required: true,
155
+ secret: true,
156
+ minLength: 32,
157
+ },
158
+
159
+ FEATURE_ENABLED: {
160
+ type: "boolean",
161
+ default: false,
162
+ },
163
+
164
+ BCP_PUBLIC_API_URL: {
165
+ type: "url",
166
+ required: true,
167
+ },
168
+ });
169
+ ```
170
+
171
+ Supported types:
172
+
173
+ ```text
174
+ string
175
+ number
176
+ boolean
177
+ url
178
+ ```
179
+
180
+ Validate the current project:
181
+
182
+ ```bash
183
+ bcp config check
184
+ ```
185
+
186
+ JSON diagnostics:
187
+
188
+ ```bash
189
+ bcp config check --json
190
+ ```
191
+
192
+ On Windows, where Microsoft SQL Server may provide another `bcp.exe`, prefer:
193
+
194
+ ```powershell
195
+ npm exec -- bcp-framework config check
196
+ npm exec -- bcp-framework config check --json
119
197
  ```
120
198
 
199
+ `bcp dev` and `bcp build` also validate `bcp.environment.*` before startup/build. Invalid required values fail early.
200
+
201
+ The development supervisor watches:
202
+
203
+ ```text
204
+ .env*
205
+ bcp.config.*
206
+ bcp.environment.*
207
+ ```
208
+
209
+ and restarts the worker when one of those files changes.
210
+
211
+ ### Secret safety
212
+
213
+ Variables beginning with `BCP_PUBLIC_` can be embedded into browser bundles.
214
+
215
+ A variable marked:
216
+
217
+ ```ts
218
+ secret: true
219
+ ```
220
+
221
+ must not use `BCP_PUBLIC_`. BCP reports this as a configuration error.
222
+
223
+ `secret: true` is tooling metadata; it does not encrypt environment values.
224
+
225
+ Read more: [Environment Validation](docs/environment-validation.md)
226
+
121
227
  ## Public entrypoints
122
228
 
123
- The `0.2.0` platform contract recognizes these application entrypoints:
229
+ The current `0.2.x` platform contract recognizes:
124
230
 
125
231
  ```text
126
232
  bcp
@@ -136,9 +242,13 @@ bcp/server-only
136
242
  bcp/middleware
137
243
  ```
138
244
 
139
- Application code should use public entrypoints rather than importing internal framework files under `packages/`.
245
+ Application code should use public entrypoints instead of importing framework internals under `packages/`.
140
246
 
141
- The authoritative machine-readable list is in [docs/platform-manifest.json](docs/platform-manifest.json).
247
+ See:
248
+
249
+ - [API Reference](docs/api-reference.md)
250
+ - [Platform Manifest](docs/platform-manifest.json)
251
+ - [API Manifest](docs/api-manifest.json)
142
252
 
143
253
  ## CLI
144
254
 
@@ -150,6 +260,7 @@ bcp build
150
260
  bcp start
151
261
  bcp routes
152
262
  bcp update
263
+ bcp config check
153
264
  bcp doctor
154
265
  bcp inspect
155
266
  bcp version
@@ -175,124 +286,48 @@ bcp generate migration create_users
175
286
 
176
287
  Page/API/middleware generators require `--force` before replacing an existing scaffold target.
177
288
 
178
- On Windows, Microsoft SQL Server may provide another `bcp.exe`. For direct PowerShell usage prefer the collision-free project-local alias:
179
-
180
- ```powershell
181
- npm exec -- bcp-framework doctor
182
- npm exec -- bcp-framework inspect
183
- npm exec -- bcp-framework routes
184
- npm exec -- bcp-framework generate page dashboard/users
185
- ```
186
-
187
- Inside npm scripts, `bcp` remains safe because npm prepends the project `node_modules/.bin` directory to `PATH`.
188
-
189
- ## Routing, loaders, guards and actions
190
-
191
- BCP discovers pages from `app/**/page.tsx` and API handlers from `app/**/route.ts`.
192
-
193
- ```text
194
- app/page.tsx /
195
- app/users/[id]/page.tsx /users/:id
196
- app/docs/[...slug]/page.tsx /docs/*
197
- app/catalog/[[...slug]]/page.tsx /catalog and /catalog/*
198
- app/(admin)/settings/page.tsx /settings
199
- app/api/users/route.ts /api/users
200
- ```
201
-
202
- Route-owned server features stay colocated:
203
-
204
- ```text
205
- page.tsx
206
- loader.ts
207
- guard.ts
208
- actions.ts
209
- ```
210
-
211
- Guides:
212
-
213
- - [Routing](docs/routing.md)
214
- - [Server Data Loaders](docs/server-data-loaders.md)
215
- - [Route Guards](docs/route-guards.md)
216
- - [Form Actions](docs/form-actions.md)
217
-
218
- ## Authentication and server APIs
219
-
220
- ```ts
221
- import {
222
- auth,
223
- requireAuth,
224
- requireRole,
225
- } from "bcp/auth";
226
-
227
- import {
228
- cookies,
229
- headers,
230
- requestId,
231
- requestMethod,
232
- requestUrl,
233
- } from "bcp/server";
234
- ```
235
-
236
- Guides:
237
-
238
- - [Authentication](docs/authentication.md)
239
- - [JWT Sessions](docs/session-auth.md)
240
- - [Server Request APIs](docs/server-request-apis.md)
241
-
242
- ## Database
243
-
244
- ```ts
245
- import {
246
- db,
247
- } from "bcp/database";
248
- ```
249
-
250
- BCP's database layer includes lazy MySQL pool creation, query/execute helpers, transactions and migrations.
251
-
252
- Guides:
253
-
254
- - [Database](docs/database.md)
255
- - [Database Migrations](docs/database-migrations.md)
256
-
257
- ## Storage and uploads
258
-
259
- `create-bcp-app` can scaffold:
289
+ ## Application model
260
290
 
261
291
  ```text
262
- None
263
- Local Server
264
- Amazon S3
265
- Cloudflare R2
292
+ Browser
293
+
294
+ Security / middleware / cache
295
+
296
+ Route guard
297
+
298
+ Loader / action / API route
299
+
300
+ React SSR
301
+
302
+ Hydration / SPA navigation
266
303
  ```
267
304
 
268
- BCP's storage API supports local and S3-compatible storage, streaming reads/writes, ranges, object listing, copy/move, portable metadata, bulk deletion and S3 signed URLs.
269
-
270
- Local Server projects keep a visible scaffold:
305
+ Typical route structure:
271
306
 
272
307
  ```text
273
- storage/
274
- ├─ .gitkeep
275
- └─ README.md
308
+ app/
309
+ ├─ layout.tsx
310
+ ├─ page.tsx
311
+ ├─ dashboard/
312
+ │ ├─ guard.ts
313
+ │ └─ users/
314
+ │ └─ [id]/
315
+ │ ├─ loader.ts
316
+ │ ├─ actions.ts
317
+ │ └─ page.tsx
318
+ └─ api/
319
+ └─ upload/
320
+ └─ route.ts
276
321
  ```
277
322
 
278
- Runtime objects remain ignored by Git.
279
-
280
- Guides:
281
-
282
- - [File Upload](docs/file-upload.md)
283
- - [Storage & File Delivery](docs/storage.md)
284
- - [Storage Ecosystem](docs/storage-ecosystem.md)
285
- - [S3-Compatible Storage](docs/s3-storage.md)
286
-
287
323
  ## Production build
288
324
 
289
- Build:
290
-
291
325
  ```bash
292
326
  npm run build
327
+ npm run start
293
328
  ```
294
329
 
295
- Output:
330
+ Standalone output:
296
331
 
297
332
  ```text
298
333
  .bcp-framework/build/
@@ -302,99 +337,37 @@ Output:
302
337
  └─ server.mjs
303
338
  ```
304
339
 
305
- Run:
306
-
307
- ```bash
308
- npm run start
309
- ```
310
-
311
- The `0.2.0` platform build target is explicitly:
340
+ The current production target remains:
312
341
 
313
342
  ```text
314
343
  standalone-node
315
344
  ```
316
345
 
317
- Native `.exe`, desktop and mobile compilation are not part of the `0.2.0` platform contract.
346
+ Native `.exe`, desktop and mobile compilation remain later roadmap work.
318
347
 
319
- Production hardening supports:
320
-
321
- ```dotenv
322
- BCP_REQUEST_TIMEOUT_MS=120000
323
- BCP_HEADERS_TIMEOUT_MS=66000
324
- BCP_KEEP_ALIVE_TIMEOUT_MS=65000
325
- BCP_SHUTDOWN_TIMEOUT_MS=10000
326
- BCP_TRUST_PROXY=false
327
- ```
328
-
329
- Enable trusted proxy mode only when untrusted clients cannot bypass the trusted reverse proxy/load balancer.
348
+ Production hardening includes configurable request/header/keep-alive/shutdown timeouts, trusted-proxy handling and graceful `SIGTERM` / `SIGINT` shutdown.
330
349
 
331
350
  Read more: [Production Hardening](docs/production-hardening.md)
332
351
 
333
- ## Doctor / Inspect / project metadata
334
-
335
- Project diagnostics:
336
-
337
- ```powershell
338
- npm exec -- bcp-framework doctor
339
- npm exec -- bcp-framework inspect --json
340
- ```
341
-
342
- Doctor/Inspect v2 can report lockfile/package-manager state, duplicate framework declarations, standalone build presence, Docker/project diagnostics, storage provider and production-hardening configuration.
343
-
344
- Projects created by recent `create-bcp-app` versions include non-secret scaffold metadata:
345
-
346
- ```text
347
- bcp.project.json
348
- ```
349
-
350
- Credentials, database passwords, access keys, JWT/session secrets and tokens must never be stored in that file.
351
-
352
- Guides:
353
-
354
- - [Developer Tools](docs/developer-tools.md)
355
- - [Project Metadata](docs/project-metadata.md)
356
-
357
- ## Updating from 0.1.x
358
-
359
- `0.2.0` does not intentionally remove public entrypoints from the `0.1.29` baseline.
360
-
361
- Recommended upgrade flow after publication:
362
-
363
- ```powershell
364
- npm exec -- bcp-framework doctor
365
- npm exec -- bcp-framework update --check
366
- npm exec -- bcp-framework update 0.2.0
367
- npm run typecheck
368
- npm run build
369
- ```
370
-
371
- Do not reuse a standalone `.bcp-framework/build` produced by an older framework version; rebuild after upgrading.
372
-
373
- Read more: [Migrating to 0.2.0](docs/migration-0.2.md)
374
-
375
- ## Documentation source and bcp-docs-web
352
+ ## Documentation Platform
376
353
 
377
354
  The framework repository is the documentation source of truth.
378
355
 
379
- `bcp-docs-web` should consume:
356
+ `bcp-docs-web` consumes:
380
357
 
381
358
  ```text
382
359
  docs/docs-web-manifest.json
383
- -> navigation, routes, Markdown sources and release routes
384
-
385
360
  docs/platform-manifest.json
386
- -> version, runtime target, public entrypoints and capabilities
361
+ docs/api-manifest.json
387
362
  ```
388
363
 
389
- Markdown under `docs/` remains the authored content source.
364
+ The manifests provide navigation order, routes, Markdown sources, version/release state, public entrypoints and API guide ownership.
390
365
 
391
- Start here:
366
+ Read more:
392
367
 
393
368
  - [Documentation Source Map](docs/README.md)
394
- - [Docs-Web Manifest](docs/docs-web-manifest.json)
395
- - [Platform Manifest](docs/platform-manifest.json)
396
- - [Framework Platform Contract](docs/platform-contract.md)
397
- - [Migration Guide](docs/migration-0.2.md)
369
+ - [Documentation Platform](docs/documentation-platform.md)
370
+ - [Environment Validation](docs/environment-validation.md)
398
371
 
399
372
  ## Release validation
400
373
 
@@ -410,31 +383,41 @@ npm run test:e2e
410
383
  npm run rc:check
411
384
  ```
412
385
 
413
- `0.2.0` adds a platform-contract package smoke check that verifies the prepared npm artifact's public exports, executable aliases, Node baseline, docs metadata and framework/create-app version parity.
386
+ `0.2.2` adds Configuration & Environment v2 unit/package checks covering schema parsing, project schema loading, diagnostics, CLI parsing, public `bcp/config` exports and packed-package files.
414
387
 
415
- Do not tag or publish a release until the final release commit passes the complete RC sequence.
388
+ Do not tag or publish until the final release commit passes the complete RC sequence.
416
389
 
417
390
  ## Release history
418
391
 
419
392
  | Version | Milestone |
420
393
  | --- | --- |
421
- | `0.1.20` | Hydration line-ending stabilization |
422
- | `0.1.21` | Hydration semantic parity |
423
- | `0.1.22` | Developer tools and diagnostics |
424
- | `0.1.23` | Logging and observability |
425
394
  | `0.1.24` | File Upload Foundation |
426
395
  | `0.1.25` | Storage Adapters and File Delivery |
427
396
  | `0.1.26` | S3-Compatible Storage and Production Streaming |
428
397
  | `0.1.27` | Storage Ecosystem |
429
398
  | `0.1.28` | Production Hardening |
430
399
  | `0.1.29` | Developer Experience |
431
- | `0.2.0` | Framework Platform baseline |
400
+ | `0.2.0` | Framework Platform |
401
+ | `0.2.1` | Documentation Platform |
402
+ | `0.2.2` | Configuration & Environment v2 |
403
+
404
+ ## Roadmap
405
+
406
+ Next planned milestone:
407
+
408
+ ```text
409
+ 0.2.3 — Database Platform v2
410
+ ```
432
411
 
433
- ## Next direction
412
+ Planned focus:
434
413
 
435
- After the `0.2.0` platform baseline is validated and released, later `0.2.x` work can add broader build/deployment targets and higher-level platform features without changing the existing standalone Node.js contract by accident.
414
+ - database adapter contract,
415
+ - PostgreSQL support,
416
+ - SQLite support,
417
+ - connection lifecycle improvements,
418
+ - migration consistency across providers.
436
419
 
437
- Native executable/desktop/mobile packaging remains future roadmap work, not a `0.2.0` guarantee.
420
+ Application packaging remains later `0.2.x` roadmap work.
438
421
 
439
422
  ## License
440
423