@chidchanun/bcp 0.1.22 → 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,310 +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.22`
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/caching` | `caching.md` | Cache and revalidation |
69
- | `/docs/security` | `security.md` | Framework security defaults |
70
- | `/docs/development-logging` | `development-logging.md` | Development request logging |
71
-
72
- ### Releases
73
-
74
- Use the files under `docs/releases/` for release pages.
75
-
76
- Recommended route format:
77
-
78
- ```text
79
- /releases/0.1.20
80
- /releases/0.1.21
81
- /releases/0.1.22
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.
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 |
89
59
 
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
69
+ - loaders, guards and form actions
70
+ - client islands / partial hydration
71
+ - Fast Refresh and deterministic development hydration
117
72
 
118
- ### Database
119
-
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 package-root diagnostics
159
- - Standalone production builds
160
- - Critical CSS
161
- - Cache/revalidation
162
- - Security defaults
163
- - Unit/integration/E2E/package smoke testing in the framework repository
164
-
165
- ## Suggested homepage hero
166
-
167
- Suggested content, not a required exact copy:
168
-
169
- ```text
170
- BCP Framework
171
- A React full-stack framework for building server-rendered applications with routing,
172
- data loading, server mutations, authentication, databases, validation, structured errors,
173
- middleware and production tooling.
174
- ```
175
-
176
- Primary actions:
177
-
178
- ```text
179
- Get Started
180
- Read the Docs
181
- View on GitHub
182
- ```
183
-
184
- The website may display the current release version from project metadata instead of hard-coding it in multiple UI files.
185
-
186
- ## Suggested documentation sidebar
187
-
188
- ```text
189
- Getting Started
190
- Introduction
191
- Installation
192
- Project Structure
193
- Configuration
194
- Updating
195
-
196
- Core
197
- Routing
198
- Application Modules
199
- Server Request APIs
200
- Server Data Loaders
201
- Route Guards
202
- Form Actions
203
- Validation
204
- Error Handling
205
-
206
- Authentication
207
- Authentication Core
208
- Auth Route Guards
209
- JWT Sessions
210
-
211
- Database
212
- Database
213
- Migrations
214
-
215
- Runtime
216
- Middleware
217
- Hydration
218
- Developer Tools
219
- Caching
220
- Security
221
-
222
- Production
223
- Deployment
224
- Development Logging
225
-
226
- Releases
227
- 0.1.22
228
- 0.1.21
229
- 0.1.20
230
- ```
231
-
232
- ## Suggested documentation page layout
233
-
234
- Each documentation page should support:
235
-
236
- - title
237
- - short summary
238
- - previous/next page navigation
239
- - table of contents generated from headings
240
- - syntax-highlighted code blocks
241
- - copy-code button
242
- - deep links to headings
243
- - responsive sidebar
244
- - mobile navigation
245
- - light/dark appearance
246
- - framework version label
247
- - link to the corresponding source Markdown file in GitHub
248
-
249
- Optional later additions:
94
+ - `bcp doctor`
95
+ - `bcp inspect`
96
+ - `bcp-framework` Windows-safe CLI alias
97
+ - standalone production build
98
+ - release/package smoke checks
250
99
 
251
- - documentation search
252
- - version selector
253
- - API symbol index
254
- - interactive examples
255
- - edit-on-GitHub links
100
+ ## BCP 0.1.24 documentation priorities
256
101
 
257
- ## Code examples
102
+ ### File Upload
258
103
 
259
- Examples should use the public package entrypoints that application developers actually install.
260
-
261
- Preferred:
104
+ BCP 0.1.24 exposes upload helpers through the server-only `bcp/server` entrypoint:
262
105
 
263
106
  ```ts
264
107
  import {
265
- auth,
266
- requireAuth,
267
- } from "bcp/auth";
108
+ parseMultipartFormData,
109
+ getUploadedFile,
110
+ requireUploadedFile,
111
+ validateUploadedFile,
112
+ saveUploadedFile,
113
+ sanitizeUploadFileName,
114
+ UploadError,
115
+ } from "bcp/server";
116
+ ```
268
117
 
269
- import {
270
- db,
271
- } from "bcp/database";
118
+ Documentation must make the following boundaries clear:
272
119
 
273
- import {
274
- v,
275
- validateFormData,
276
- } from "bcp/validation";
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.
277
127
 
278
- import {
279
- badRequest,
280
- unauthorized,
281
- } from "bcp/error";
128
+ See `file-upload.md`.
282
129
 
283
- import {
284
- type MiddlewarePipelineHandler,
285
- } from "bcp/middleware";
286
- ```
130
+ ### Dev route/client bundle synchronization
287
131
 
288
- Avoid documenting internal monorepo imports such as:
132
+ 0.1.24 also fixes a development-only graph drift that could produce:
289
133
 
290
134
  ```text
291
- packages/server/src/...
292
- packages/client/src/...
135
+ Client bundle was not found for route "/docs/[...slug]".
293
136
  ```
294
137
 
295
- 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
141
+
142
+ 0.1.23 introduced:
296
143
 
297
- ## Version labels
144
+ - `logger` / `createLogger()`
145
+ - request-scoped `requestLogger()`
146
+ - log levels and JSON format
147
+ - `X-Request-Id` helpers
148
+ - structured development request/SSR timing
298
149
 
299
- The website should distinguish:
150
+ See `development-logging.md`.
300
151
 
301
- - current stable npm version
302
- - documentation target version
303
- - unreleased/main documentation if it is shown
152
+ ### Developer Tools
304
153
 
305
- Do not label unreleased `main` behavior as already available from npm until the corresponding package has been published.
154
+ 0.1.22 introduced `bcp doctor` and `bcp inspect`, JSON reports, duplicate React diagnostics and duplicate BCP-install protection.
306
155
 
307
- ## Framework commands to document
156
+ See `developer-tools.md`.
157
+
158
+ ## Commands
308
159
 
309
160
  ```bash
310
161
  bcp dev
@@ -324,107 +175,31 @@ bcp db status
324
175
  bcp db rollback
325
176
  ```
326
177
 
327
- Project creation:
328
-
329
- ```bash
330
- npx create-bcp-app@latest my-app
331
- ```
332
-
333
- ## Middleware v2 documentation priority
178
+ On Windows systems where SQL Server owns `bcp.exe`, direct shell commands can use:
334
179
 
335
- BCP 0.1.18 introduced a meaningful middleware architecture change, so the `bcp-docs` website should make the distinction between v1 and v2 clear.
336
-
337
- The middleware page should prominently explain:
338
-
339
- ```text
340
- v1 next() = return a pass-through instruction
341
- v2 await next() = execute downstream middleware/application and receive Response
180
+ ```powershell
181
+ bcp-framework doctor
182
+ bcp-framework inspect
183
+ bcp-framework dev
342
184
  ```
343
185
 
344
- Existing v1 code remains supported, so migration documentation should describe v2 as an additive upgrade rather than a mandatory rewrite.
345
-
346
- See `middleware.md` for the full API and examples.
347
-
348
- ## Validation documentation priority
349
-
350
- BCP 0.1.19 introduced the public `bcp/validation` entrypoint. The docs website should show validation in both form-action and API-route examples.
351
-
352
- Important concepts to surface:
353
-
354
- - `v.object`, `v.string`, `v.number`, `v.boolean`, `v.array`
355
- - FormData coercion with `validateFormData()`
356
- - `success/data` versus `issues/fieldErrors/formErrors`
357
- - object fields are stripped unless `allowUnknown: true`
358
- - `refine()` for custom application rules
359
- - no external validation dependency is required
186
+ ## Releases
360
187
 
361
- See `validation.md` for the complete API and examples.
362
-
363
- ## Error Handling documentation priority
364
-
365
- BCP 0.1.20 introduced the public `bcp/error` entrypoint and a standard HTTP error envelope.
366
-
367
- The docs website should clearly distinguish:
188
+ Recommended release routes:
368
189
 
369
190
  ```text
370
- notFound() = activate page 404 UI behavior
371
- 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
372
196
  ```
373
197
 
374
- Important concepts to surface:
375
-
376
- - `HttpError` and `createHttpError()`
377
- - `errorResponse()` for any 4xx/5xx status
378
- - `toErrorResponse()` for safe catch boundaries
379
- - `badRequest()`, `unauthorized()`, `forbidden()`, `conflict()` and other convenience helpers
380
- - standard `{ error: { status, code, message, details? } }` payload
381
- - error responses default to `Cache-Control: no-store`
382
- - unknown exceptions become a generic 500 response without exposing the original exception message
383
- - normal field validation still belongs to `bcp/validation`
384
-
385
- See `error-handling.md` for the complete API and examples.
386
-
387
- ## Hydration documentation priority
388
-
389
- 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.
390
-
391
- 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.
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.
392
199
 
393
- The docs website should make these points clear:
200
+ ## Release workflow
394
201
 
395
- - multiline quoted JSX attributes are supported,
396
- - multiline template-literal JSX expressions are supported,
397
- - developers should not need to rewrite multiline `className` values as one-line strings to avoid framework hydration warnings,
398
- - `CRLF` and standalone `CR` source line endings are normalized to `LF` before development instrumentation,
399
- - React Refresh instrumentation must not change the semantic value of JSX attributes,
400
- - 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,
401
- - `suppressHydrationWarning` is not a general-purpose solution.
402
-
403
- See `hydration.md` for the full explanation, transform pipeline and troubleshooting steps.
404
-
405
- ## Developer Tools documentation priority
406
-
407
- BCP 0.1.22 adds `bcp doctor` and `bcp inspect` as the first dedicated developer-diagnostics commands.
408
-
409
- The docs website should surface:
410
-
411
- - PASS/WARN/FAIL health checks,
412
- - non-zero exit codes for blocking doctor failures,
413
- - React / React DOM version and package-root parity,
414
- - config and development environment inspection,
415
- - page/API route summaries,
416
- - `--json` output for CI and automation,
417
- - the recommendation to verify local releases from packed `.tgz` artifacts rather than linked staging directories.
418
-
419
- See `developer-tools.md` for the full command reference.
420
-
421
- ## Release roadmap
422
-
423
- `0.1.22` is the Developer Tools milestone. The next planned milestone is `0.1.23` — Logging & Observability, followed by File Upload and the remaining pre-0.2 foundation milestones unless they are regrouped.
424
-
425
- ## Release workflow for documentation
426
-
427
- Before publishing a new BCP release:
202
+ Before publishing a BCP release:
428
203
 
429
204
  ```bash
430
205
  npm run typecheck
@@ -432,6 +207,8 @@ npm run test:unit
432
207
  npm run rc:check
433
208
  ```
434
209
 
435
- 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
436
213
 
437
- 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.