@chidchanun/bcp 0.1.23 → 0.1.24

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/docs/README.md CHANGED
@@ -1,321 +1,161 @@
1
1
  # BCP Framework Documentation Source
2
2
 
3
- This directory is the documentation source of truth for the BCP Framework documentation website.
3
+ This directory is the documentation source of truth for the BCP Framework documentation website (`bcp-docs`).
4
4
 
5
- The recommended documentation website project name is `bcp-docs`.
5
+ > Documentation target: BCP Framework `0.1.24`
6
6
 
7
- > Documentation target: BCP Framework `0.1.23`
8
-
9
- ## Purpose
10
-
11
- The `bcp-docs` website should turn the Markdown files in this directory into a structured developer documentation experience without duplicating framework behavior in a separate source of truth.
12
-
13
- When framework behavior changes:
14
-
15
- 1. update the framework source and tests,
16
- 2. update the relevant file in `docs/`,
17
- 3. update the release note in `docs/releases/`,
18
- 4. then publish or synchronize the content to `bcp-docs`.
19
-
20
- The website should not invent API behavior that is not documented or tested in the framework repository.
7
+ When framework behavior changes, update framework source/tests first, then the matching file under `docs/`, then the release note under `docs/releases/`.
21
8
 
22
9
  ## Recommended website navigation
23
10
 
24
11
  ### Getting Started
25
12
 
26
- | Website route | Source file | Description |
13
+ | Route | Source | Purpose |
27
14
  | --- | --- | --- |
28
15
  | `/docs/getting-started` | `getting-started.md` | Create and run a BCP application |
29
16
  | `/docs/configuration` | `configuration.md` | Framework configuration |
30
- | `/docs/application-modules` | `application-modules.md` | Client/server module boundaries |
31
- | `/docs/deployment` | `deployment.md` | Production and deployment guidance |
32
- | `/docs/updating` | `updating.md` | Upgrade an existing BCP project |
17
+ | `/docs/application-modules` | `application-modules.md` | Client/server boundaries |
18
+ | `/docs/deployment` | `deployment.md` | Production deployment |
19
+ | `/docs/updating` | `updating.md` | Framework upgrades |
33
20
 
34
21
  ### Routing and Data
35
22
 
36
- | Website route | Source file | Description |
23
+ | Route | Source | Purpose |
37
24
  | --- | --- | --- |
38
25
  | `/docs/routing` | `routing.md` | File-based routing |
39
26
  | `/docs/server-data-loaders` | `server-data-loaders.md` | Server-side page data |
40
- | `/docs/route-guards` | `route-guards.md` | Scoped page authorization |
41
- | `/docs/form-actions` | `form-actions.md` | Server mutations and forms |
42
- | `/docs/server-request-apis` | `server-request-apis.md` | Request, cookie, redirect and response APIs |
43
- | `/docs/validation` | `validation.md` | Typed form/API validation and field errors |
44
- | `/docs/error-handling` | `error-handling.md` | Structured HTTP errors and standard error responses |
27
+ | `/docs/route-guards` | `route-guards.md` | Scoped route authorization |
28
+ | `/docs/form-actions` | `form-actions.md` | Server mutations/forms |
29
+ | `/docs/server-request-apis` | `server-request-apis.md` | Request/cookie/response APIs |
30
+ | `/docs/validation` | `validation.md` | Typed validation |
31
+ | `/docs/error-handling` | `error-handling.md` | Structured HTTP errors |
32
+ | `/docs/file-upload` | `file-upload.md` | Multipart parsing, validation and local file storage |
45
33
 
46
34
  ### Authentication
47
35
 
48
- | Website route | Source file | Description |
36
+ | Route | Source | Purpose |
49
37
  | --- | --- | --- |
50
- | `/docs/authentication` | `authentication.md` | Authentication Core and `bcp/auth` |
51
- | `/docs/auth-route-guards` | `auth-route-guards.md` | `requireAuth`, `requireRole` and guard integration |
52
- | `/docs/session-auth` | `session-auth.md` | Low-level JWT cookie sessions |
38
+ | `/docs/authentication` | `authentication.md` | Authentication Core |
39
+ | `/docs/auth-route-guards` | `auth-route-guards.md` | Auth-aware guards |
40
+ | `/docs/session-auth` | `session-auth.md` | JWT cookie sessions |
53
41
 
54
42
  ### Database
55
43
 
56
- | Website route | Source file | Description |
44
+ | Route | Source | Purpose |
57
45
  | --- | --- | --- |
58
- | `/docs/database` | `database.md` | `bcp/database`, MySQL and transactions |
59
- | `/docs/database-migrations` | `database-migrations.md` | Migration CLI and migration files |
46
+ | `/docs/database` | `database.md` | MySQL database primitives |
47
+ | `/docs/database-migrations` | `database-migrations.md` | Migration CLI and files |
60
48
 
61
49
  ### Runtime and Infrastructure
62
50
 
63
- | Website route | Source file | Description |
51
+ | Route | Source | Purpose |
64
52
  | --- | --- | --- |
65
- | `/docs/middleware` | `middleware.md` | Middleware System v2 and v1 compatibility |
66
- | `/docs/hydration` | `hydration.md` | SSR/client transform parity, deterministic rendering and Windows line endings |
67
- | `/docs/developer-tools` | `developer-tools.md` | `bcp doctor`, `bcp inspect` and JSON diagnostics |
68
- | `/docs/development-logging` | `development-logging.md` | Structured logging, request identity and development observability |
69
- | `/docs/caching` | `caching.md` | Cache and revalidation |
70
- | `/docs/security` | `security.md` | Framework security defaults |
71
-
72
- ### Releases
73
-
74
- Use the files under `docs/releases/` for release pages.
53
+ | `/docs/middleware` | `middleware.md` | Middleware System v2 |
54
+ | `/docs/hydration` | `hydration.md` | SSR/client hydration parity |
55
+ | `/docs/developer-tools` | `developer-tools.md` | `doctor` / `inspect` diagnostics |
56
+ | `/docs/development-logging` | `development-logging.md` | Structured logging and observability |
57
+ | `/docs/caching` | `caching.md` | Cache/revalidation |
58
+ | `/docs/security` | `security.md` | Security defaults and body limits |
75
59
 
76
- Recommended route format:
77
-
78
- ```text
79
- /releases/0.1.21
80
- /releases/0.1.22
81
- /releases/0.1.23
82
- ```
83
-
84
- The newest release should also be available from `/releases`.
85
-
86
- ## Homepage content for bcp-docs
87
-
88
- The documentation homepage should describe BCP as a React full-stack framework and highlight the currently implemented capabilities.
89
-
90
- Recommended feature groups:
60
+ ## Current capability groups
91
61
 
92
62
  ### Application
93
63
 
94
- - File-based routing
95
- - React SSR
64
+ - React SSR and hydration
65
+ - file-based page/API routing
66
+ - dynamic/catch-all routes
67
+ - layouts and metadata
96
68
  - SPA navigation
97
- - Persistent layouts
98
- - Loading and error UI
99
- - API routes
100
- - Client islands / partial hydration
101
- - Deterministic development hydration across server/client transform pipelines
102
- - LF/CRLF-safe development source handling
103
-
104
- ### Server data and mutations
105
-
106
- - Server data loaders
107
- - Route guards
108
- - Form actions
109
- - Request-scoped server APIs
110
- - Cookies and redirects
111
- - `bcp/validation`
112
- - Typed form/API validation
113
- - Field and form error output
114
- - `bcp/error`
115
- - Structured HTTP error responses
116
- - Safe unknown-error fallback responses
117
-
118
- ### Database
69
+ - loaders, guards and form actions
70
+ - client islands / partial hydration
71
+ - Fast Refresh and deterministic development hydration
119
72
 
120
- - `bcp/database`
121
- - Lazy MySQL connection pool
122
- - Queries and prepared execution
123
- - Transactions
124
- - Database migrations
125
- - Migration status and rollback
126
-
127
- ### Authentication
73
+ ### Server
128
74
 
129
- - `bcp/auth`
130
- - JWT cookie sessions
131
- - Typed users and session data
132
- - Session rotation
133
- - `requireAuth()`
134
- - `requireRole()`
135
- - Auth-aware route guards
75
+ - request-scoped server APIs
76
+ - cookies and redirects
77
+ - JWT sessions and authentication
78
+ - Middleware System v2
79
+ - typed validation and structured errors
80
+ - structured logging with request identity
81
+ - multipart file uploads and local filesystem persistence
136
82
 
137
- ### Middleware
83
+ ### Database
138
84
 
139
- - Middleware System v2
140
- - Middleware chains
141
- - Real `await next()` downstream execution
142
- - Before/after response interception
143
- - Shared request context state
144
- - Matchers
145
- - Rewrite and redirect
146
- - Backward-compatible Middleware v1 handlers
85
+ - `bcp/database`
86
+ - MySQL pool/query helpers
87
+ - transactions
88
+ - migrations/status/rollback
147
89
 
148
- ### Production and DX
90
+ ### Developer Experience
149
91
 
150
92
  - `create-bcp-app`
151
- - Interactive project setup
152
- - Tailwind preset
153
- - Database/auth presets
154
93
  - `bcp update`
155
- - `bcp doctor` project/runtime diagnostics
156
- - `bcp inspect` environment/config/route inspection
157
- - JSON developer-tool output for CI/automation
158
- - Duplicate React and duplicate BCP installation diagnostics
94
+ - `bcp doctor`
95
+ - `bcp inspect`
159
96
  - `bcp-framework` Windows-safe CLI alias
160
- - Structured server logger
161
- - Request-scoped loggers with request identity
162
- - Pretty and JSON log formats
163
- - Configurable log levels
164
- - Structured development HTTP/SSR timing events
165
- - Standalone production builds
166
- - Critical CSS
167
- - Cache/revalidation
168
- - Security defaults
169
- - Unit/integration/E2E/package smoke testing in the framework repository
170
-
171
- ## Suggested homepage hero
172
-
173
- Suggested content, not a required exact copy:
174
-
175
- ```text
176
- BCP Framework
177
- A React full-stack framework for building server-rendered applications with routing,
178
- data loading, server mutations, authentication, databases, validation, structured errors,
179
- middleware, observability and production tooling.
180
- ```
181
-
182
- Primary actions:
183
-
184
- ```text
185
- Get Started
186
- Read the Docs
187
- View on GitHub
188
- ```
189
-
190
- The website may display the current release version from project metadata instead of hard-coding it in multiple UI files.
191
-
192
- ## Suggested documentation sidebar
97
+ - standalone production build
98
+ - release/package smoke checks
193
99
 
194
- ```text
195
- Getting Started
196
- Introduction
197
- Installation
198
- Project Structure
199
- Configuration
200
- Updating
201
-
202
- Core
203
- Routing
204
- Application Modules
205
- Server Request APIs
206
- Server Data Loaders
207
- Route Guards
208
- Form Actions
209
- Validation
210
- Error Handling
211
-
212
- Authentication
213
- Authentication Core
214
- Auth Route Guards
215
- JWT Sessions
216
-
217
- Database
218
- Database
219
- Migrations
220
-
221
- Runtime
222
- Middleware
223
- Hydration
224
- Developer Tools
225
- Logging & Observability
226
- Caching
227
- Security
228
-
229
- Production
230
- Deployment
231
-
232
- Releases
233
- 0.1.23
234
- 0.1.22
235
- 0.1.21
236
- ```
237
-
238
- ## Suggested documentation page layout
239
-
240
- Each documentation page should support:
241
-
242
- - title
243
- - short summary
244
- - previous/next page navigation
245
- - table of contents generated from headings
246
- - syntax-highlighted code blocks
247
- - copy-code button
248
- - deep links to headings
249
- - responsive sidebar
250
- - mobile navigation
251
- - light/dark appearance
252
- - framework version label
253
- - link to the corresponding source Markdown file in GitHub
254
-
255
- Optional later additions:
100
+ ## BCP 0.1.24 documentation priorities
256
101
 
257
- - documentation search
258
- - version selector
259
- - API symbol index
260
- - interactive examples
261
- - edit-on-GitHub links
102
+ ### File Upload
262
103
 
263
- ## Code examples
264
-
265
- Examples should use the public package entrypoints that application developers actually install.
266
-
267
- Preferred:
104
+ BCP 0.1.24 exposes upload helpers through the server-only `bcp/server` entrypoint:
268
105
 
269
106
  ```ts
270
107
  import {
271
- auth,
272
- requireAuth,
273
- } from "bcp/auth";
274
-
275
- import {
276
- db,
277
- } from "bcp/database";
108
+ parseMultipartFormData,
109
+ getUploadedFile,
110
+ requireUploadedFile,
111
+ validateUploadedFile,
112
+ saveUploadedFile,
113
+ sanitizeUploadFileName,
114
+ UploadError,
115
+ } from "bcp/server";
116
+ ```
278
117
 
279
- import {
280
- v,
281
- validateFormData,
282
- } from "bcp/validation";
118
+ Documentation must make the following boundaries clear:
283
119
 
284
- import {
285
- badRequest,
286
- unauthorized,
287
- } from "bcp/error";
120
+ - `server.bodyLimit` / `BCP_BODY_LIMIT` is the outer request-size limit enforced by the security gateway.
121
+ - multipart and individual file limits can be stricter than the global body limit.
122
+ - MIME type and extension are metadata checks, not file-signature verification.
123
+ - default storage names are UUID based.
124
+ - existing files are not overwritten unless explicitly requested.
125
+ - saved metadata includes SHA-256 checksum.
126
+ - local filesystem storage is the initial foundation; distributed/object storage requires a later adapter layer.
288
127
 
289
- import {
290
- logger,
291
- requestLogger,
292
- } from "bcp/server";
128
+ See `file-upload.md`.
293
129
 
294
- import {
295
- type MiddlewarePipelineHandler,
296
- } from "bcp/middleware";
297
- ```
130
+ ### Dev route/client bundle synchronization
298
131
 
299
- Avoid documenting internal monorepo imports such as:
132
+ 0.1.24 also fixes a development-only graph drift that could produce:
300
133
 
301
134
  ```text
302
- packages/server/src/...
303
- packages/client/src/...
135
+ Client bundle was not found for route "/docs/[...slug]".
304
136
  ```
305
137
 
306
- unless a page is explicitly explaining framework internals.
138
+ The dev gateway now compares the actual page route topology and refreshes the internal client bundler when pathname/page/layout structure changes. Users should no longer need to manually delete `.bcp-framework` to recover a missing route bundle.
139
+
140
+ ### Logging & Observability
307
141
 
308
- ## Version labels
142
+ 0.1.23 introduced:
309
143
 
310
- The website should distinguish:
144
+ - `logger` / `createLogger()`
145
+ - request-scoped `requestLogger()`
146
+ - log levels and JSON format
147
+ - `X-Request-Id` helpers
148
+ - structured development request/SSR timing
311
149
 
312
- - current stable npm version
313
- - documentation target version
314
- - unreleased/main documentation if it is shown
150
+ See `development-logging.md`.
315
151
 
316
- Do not label unreleased `main` behavior as already available from npm until the corresponding package has been published.
152
+ ### Developer Tools
317
153
 
318
- ## Framework commands to document
154
+ 0.1.22 introduced `bcp doctor` and `bcp inspect`, JSON reports, duplicate React diagnostics and duplicate BCP-install protection.
155
+
156
+ See `developer-tools.md`.
157
+
158
+ ## Commands
319
159
 
320
160
  ```bash
321
161
  bcp dev
@@ -335,128 +175,31 @@ bcp db status
335
175
  bcp db rollback
336
176
  ```
337
177
 
338
- On Windows systems where Microsoft SQL Server owns the `bcp` executable name, document the equivalent collision-free commands with `bcp-framework`.
339
-
340
- Project creation:
178
+ On Windows systems where SQL Server owns `bcp.exe`, direct shell commands can use:
341
179
 
342
- ```bash
343
- npx create-bcp-app@latest my-app
180
+ ```powershell
181
+ bcp-framework doctor
182
+ bcp-framework inspect
183
+ bcp-framework dev
344
184
  ```
345
185
 
346
- ## Middleware v2 documentation priority
347
-
348
- BCP 0.1.18 introduced a meaningful middleware architecture change, so the `bcp-docs` website should make the distinction between v1 and v2 clear.
349
-
350
- The middleware page should prominently explain:
351
-
352
- ```text
353
- v1 next() = return a pass-through instruction
354
- v2 await next() = execute downstream middleware/application and receive Response
355
- ```
356
-
357
- Existing v1 code remains supported, so migration documentation should describe v2 as an additive upgrade rather than a mandatory rewrite.
358
-
359
- See `middleware.md` for the full API and examples.
360
-
361
- ## Validation documentation priority
362
-
363
- BCP 0.1.19 introduced the public `bcp/validation` entrypoint. The docs website should show validation in both form-action and API-route examples.
364
-
365
- Important concepts to surface:
366
-
367
- - `v.object`, `v.string`, `v.number`, `v.boolean`, `v.array`
368
- - FormData coercion with `validateFormData()`
369
- - `success/data` versus `issues/fieldErrors/formErrors`
370
- - object fields are stripped unless `allowUnknown: true`
371
- - `refine()` for custom application rules
372
- - no external validation dependency is required
373
-
374
- See `validation.md` for the complete API and examples.
375
-
376
- ## Error Handling documentation priority
377
-
378
- BCP 0.1.20 introduced the public `bcp/error` entrypoint and a standard HTTP error envelope.
186
+ ## Releases
379
187
 
380
- The docs website should clearly distinguish:
188
+ Recommended release routes:
381
189
 
382
190
  ```text
383
- notFound() = activate page 404 UI behavior
384
- notFoundResponse() = return a JSON 404 HTTP response
191
+ /releases/0.1.24
192
+ /releases/0.1.23
193
+ /releases/0.1.22
194
+ /releases/0.1.21
195
+ /releases/0.1.20
385
196
  ```
386
197
 
387
- Important concepts to surface:
388
-
389
- - `HttpError` and `createHttpError()`
390
- - `errorResponse()` for any 4xx/5xx status
391
- - `toErrorResponse()` for safe catch boundaries
392
- - `badRequest()`, `unauthorized()`, `forbidden()`, `conflict()` and other convenience helpers
393
- - standard `{ error: { status, code, message, details? } }` payload
394
- - error responses default to `Cache-Control: no-store`
395
- - unknown exceptions become a generic 500 response without exposing the original exception message
396
- - normal field validation still belongs to `bcp/validation`
397
-
398
- See `error-handling.md` for the complete API and examples.
399
-
400
- ## Hydration documentation priority
401
-
402
- BCP 0.1.20 added line-ending normalization for the development React Refresh path. That removed the Windows `CRLF` versus `LF` mismatch, but a second issue remained when Babel compiled multiline quoted JSX attributes and collapsed their whitespace differently from SSR.
403
-
404
- BCP 0.1.21 completes this fix by keeping Babel responsible for TypeScript removal and React Refresh instrumentation while leaving JSX untransformed. esbuild then performs the development JSX transform with the development JSX runtime enabled.
405
-
406
- The docs website should make these points clear:
407
-
408
- - multiline quoted JSX attributes are supported,
409
- - multiline template-literal JSX expressions are supported,
410
- - developers should not need to rewrite multiline `className` values as one-line strings to avoid framework hydration warnings,
411
- - `CRLF` and standalone `CR` source line endings are normalized to `LF` before development instrumentation,
412
- - React Refresh instrumentation must not change the semantic value of JSX attributes,
413
- - the framework fix does not suppress genuine hydration mismatches caused by random values, locale differences, browser-only initial branches, changing external data or invalid HTML,
414
- - `suppressHydrationWarning` is not a general-purpose solution.
415
-
416
- See `hydration.md` for the full explanation, transform pipeline and troubleshooting steps.
417
-
418
- ## Developer Tools documentation priority
198
+ Do not present unreleased `main` behavior as already available from npm. The website should distinguish the stable npm version from the documentation target when they differ.
419
199
 
420
- BCP 0.1.22 adds `bcp doctor` and `bcp inspect` as the first dedicated developer-diagnostics commands.
200
+ ## Release workflow
421
201
 
422
- The docs website should surface:
423
-
424
- - PASS/WARN/FAIL health checks,
425
- - non-zero exit codes for blocking doctor failures,
426
- - React / React DOM version and package-root parity,
427
- - duplicate `bcp` / `@chidchanun/bcp` installation detection,
428
- - config and development environment inspection,
429
- - page/API route summaries,
430
- - `--json` output for CI and automation,
431
- - the recommendation to verify local releases from packed `.tgz` artifacts installed under the existing `bcp` dependency key rather than linked staging directories.
432
-
433
- See `developer-tools.md` for the full command reference.
434
-
435
- ## Logging and observability documentation priority
436
-
437
- BCP 0.1.23 adds the structured logging foundation through `bcp/server`.
438
-
439
- The docs website should surface:
440
-
441
- - `logger.debug/info/warn/error`,
442
- - `createLogger()` and child loggers,
443
- - `requestLogger()` and its request ID/method/path bindings,
444
- - `attachRequestId()` for `X-Request-Id` response propagation,
445
- - `BCP_LOG_LEVEL`,
446
- - `BCP_LOG_FORMAT=pretty|json`,
447
- - JSON-safe `Error`, `bigint` and circular value handling,
448
- - structured `http.request`, `module.import` and `ssr.render` development events,
449
- - the existing dev noise filter for framework-internal requests.
450
-
451
- See `development-logging.md` for the complete API and examples.
452
-
453
- ## Release roadmap
454
-
455
- `0.1.23` is the Logging & Observability milestone. The next planned milestone is `0.1.24` — File Upload foundation, followed by Background Jobs, Testing Utilities, Production Build Hardening and Plugin Architecture unless milestones are regrouped.
456
-
457
- ## Release workflow for documentation
458
-
459
- Before publishing a new BCP release:
202
+ Before publishing a BCP release:
460
203
 
461
204
  ```bash
462
205
  npm run typecheck
@@ -464,6 +207,8 @@ npm run test:unit
464
207
  npm run rc:check
465
208
  ```
466
209
 
467
- After npm publication, the docs website can update its displayed stable version.
210
+ The framework repository remains authoritative for API behavior. `bcp-docs` is the presentation layer for this source content.
211
+
212
+ ## Next milestone
468
213
 
469
- The framework repository remains authoritative for API correctness; `bcp-docs` is the presentation layer for that content.
214
+ After 0.1.24, the planned follow-up is `0.1.25` for upload/storage adapters and production file-delivery hardening unless roadmap priorities are regrouped.
@@ -211,6 +211,20 @@ export function guard() {
211
211
  }
212
212
  ```
213
213
 
214
+ ## Standalone production behavior
215
+
216
+ BCP 0.1.24 keeps `bcp/auth` inside the same production guard runtime graph as `runWithRequestContext()`. This guarantees that `requireAuth()`, `requireRole()`, `auth()`, `getSession()` and `cookies()` observe the active request after `bcp build`, rather than resolving through a second framework request-context instance.
217
+
218
+ This fixes the production-only failure:
219
+
220
+ ```text
221
+ BCP Framework: server request APIs can only be used while handling a request.
222
+ ```
223
+
224
+ No application guard changes are required. Continue importing authentication helpers from `bcp/auth` normally.
225
+
226
+ The production form-action bundle applies the same runtime unification because route guards may execute before an action.
227
+
214
228
  ## Security boundary
215
229
 
216
230
  `bcp/auth` is server-only. BCP blocks it from page/client graphs and maps its browser export to the server-only runtime guard. Authentication and authorization checks should stay in guards, loaders, actions, API routes, or other server modules.