@chidchanun/bcp 0.1.27 → 0.1.29

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.
@@ -0,0 +1,152 @@
1
+ # Production Hardening
2
+
3
+ BCP Framework `0.1.28` adds a production hardening gateway around the standalone runtime.
4
+
5
+ The gateway is the public HTTP listener. Existing security, cache, critical CSS, page/API and SSR runtimes remain bound to internal loopback ports behind it.
6
+
7
+ ## Default production behavior
8
+
9
+ The hardening gateway configures Node HTTP timeouts and graceful shutdown defaults:
10
+
11
+ ```text
12
+ Request timeout: 120000 ms
13
+ Headers timeout: 66000 ms
14
+ Keep-alive timeout: 65000 ms
15
+ Shutdown timeout: 10000 ms
16
+ Trust proxy: false
17
+ ```
18
+
19
+ Override them with server-only environment variables:
20
+
21
+ ```dotenv
22
+ BCP_REQUEST_TIMEOUT_MS=120000
23
+ BCP_HEADERS_TIMEOUT_MS=66000
24
+ BCP_KEEP_ALIVE_TIMEOUT_MS=65000
25
+ BCP_SHUTDOWN_TIMEOUT_MS=10000
26
+ BCP_TRUST_PROXY=false
27
+ ```
28
+
29
+ `BCP_HEADERS_TIMEOUT_MS` must be greater than `BCP_KEEP_ALIVE_TIMEOUT_MS`.
30
+
31
+ ## Graceful shutdown
32
+
33
+ Standalone production now handles `SIGTERM` and `SIGINT`.
34
+
35
+ This is especially important for Docker, Kubernetes and process managers that send `SIGTERM` before stopping a process.
36
+
37
+ Shutdown order:
38
+
39
+ ```text
40
+ stop accepting public traffic
41
+
42
+ drain/close public HTTP connections
43
+
44
+ run application shutdown hooks
45
+
46
+ stop internal BCP runtime layers
47
+
48
+ process exits naturally
49
+ ```
50
+
51
+ If the public server does not close before `BCP_SHUTDOWN_TIMEOUT_MS`, BCP force-closes remaining connections.
52
+
53
+ ## Application shutdown hooks
54
+
55
+ Register cleanup work through `bcp/server`:
56
+
57
+ ```ts
58
+ import {
59
+ registerShutdownHook,
60
+ } from "bcp/server";
61
+
62
+ const unregister =
63
+ registerShutdownHook(
64
+ async () => {
65
+ await closeApplicationResources();
66
+ },
67
+ {
68
+ name: "application-resources",
69
+ }
70
+ );
71
+ ```
72
+
73
+ Hooks run in reverse registration order. Calling the returned function unregisters the hook.
74
+
75
+ For S3-compatible storage, an application can register the adapter client cleanup when it owns the adapter for the lifetime of the process:
76
+
77
+ ```ts
78
+ registerShutdownHook(
79
+ () => {
80
+ storage.destroy();
81
+ },
82
+ {
83
+ name: "s3-storage",
84
+ }
85
+ );
86
+ ```
87
+
88
+ Do not register request-scoped resources as process shutdown hooks.
89
+
90
+ ## Trusted proxy mode
91
+
92
+ The hardening gateway sanitizes forwarding headers by default.
93
+
94
+ ```dotenv
95
+ BCP_TRUST_PROXY=false
96
+ ```
97
+
98
+ This prevents a direct client from spoofing headers such as:
99
+
100
+ ```text
101
+ Forwarded
102
+ X-Forwarded-For
103
+ X-Forwarded-Host
104
+ X-Forwarded-Proto
105
+ X-Real-IP
106
+ ```
107
+
108
+ When BCP is deployed only behind a trusted reverse proxy such as Nginx, Cloudflare Tunnel or a trusted load balancer, enable:
109
+
110
+ ```dotenv
111
+ BCP_TRUST_PROXY=true
112
+ ```
113
+
114
+ BCP then preserves the trusted proxy forwarding chain and appends the immediate peer address where appropriate.
115
+
116
+ Only enable trusted proxy mode when direct untrusted traffic cannot bypass the trusted proxy.
117
+
118
+ ## Docker
119
+
120
+ A production compose service can use:
121
+
122
+ ```yaml
123
+ services:
124
+ app:
125
+ init: true
126
+ restart: unless-stopped
127
+ environment:
128
+ NODE_ENV: production
129
+ BCP_HOSTNAME: 0.0.0.0
130
+ BCP_PORT: 3000
131
+ BCP_SHUTDOWN_TIMEOUT_MS: 10000
132
+ BCP_TRUST_PROXY: "true"
133
+ ```
134
+
135
+ Set `BCP_TRUST_PROXY=true` only when the container receives requests exclusively from a trusted reverse proxy/network path.
136
+
137
+ Docker's stop grace period should be longer than `BCP_SHUTDOWN_TIMEOUT_MS` so BCP gets time to drain connections and cleanup resources.
138
+
139
+ ## Local Server storage scaffold
140
+
141
+ `create-bcp-app --storage local` now creates:
142
+
143
+ ```text
144
+ lib/storage.ts
145
+ storage/
146
+ ├─ .gitkeep
147
+ └─ README.md
148
+ ```
149
+
150
+ Runtime objects inside `storage/` are ignored while the scaffold files remain tracked. The generated README explains that BCP writes objects and `.bcp-storage-meta` metadata there at runtime.
151
+
152
+ The directory therefore no longer appears as an unexplained empty folder before the first upload.
@@ -0,0 +1,112 @@
1
+ # Project Metadata
2
+
3
+ BCP Framework `0.1.29` makes generated project presets explicit through `bcp.project.json`.
4
+
5
+ `create-bcp-app` writes this file after applying the selected project options.
6
+
7
+ Example:
8
+
9
+ ```json
10
+ {
11
+ "schemaVersion": 1,
12
+ "framework": "bcp",
13
+ "projectName": "my-app",
14
+ "frameworkPackage": "npm:@chidchanun/bcp@0.1.29",
15
+ "createdWith": {
16
+ "package": "create-bcp-app",
17
+ "version": "0.1.29"
18
+ },
19
+ "packageManager": "npm",
20
+ "presets": {
21
+ "tailwind": true,
22
+ "database": "mysql",
23
+ "auth": "jwt-cookie",
24
+ "storage": "cloudflare-r2"
25
+ }
26
+ }
27
+ ```
28
+
29
+ ## Purpose
30
+
31
+ The metadata file records scaffold choices without requiring later tools to infer them from source code.
32
+
33
+ It is intended for:
34
+
35
+ - `bcp doctor`,
36
+ - `bcp inspect`,
37
+ - project migration/update tooling,
38
+ - documentation tooling,
39
+ - `bcp-docs-web` examples and project-aware guidance,
40
+ - future framework upgrade diagnostics.
41
+
42
+ ## Security boundary
43
+
44
+ `bcp.project.json` must not contain credentials or runtime secrets.
45
+
46
+ It records only non-secret configuration identities such as:
47
+
48
+ ```text
49
+ Tailwind enabled/disabled
50
+ Database preset name
51
+ Auth preset name
52
+ Storage provider name
53
+ Package manager
54
+ Framework package specifier
55
+ create-bcp-app version
56
+ ```
57
+
58
+ Do not add values such as:
59
+
60
+ ```text
61
+ AWS_ACCESS_KEY_ID
62
+ AWS_SECRET_ACCESS_KEY
63
+ R2_ACCESS_KEY_ID
64
+ R2_SECRET_ACCESS_KEY
65
+ DATABASE_URL
66
+ passwords
67
+ JWT secrets
68
+ session tokens
69
+ ```
70
+
71
+ Runtime configuration stays in environment variables and server-only configuration.
72
+
73
+ ## Schema version
74
+
75
+ The initial format uses:
76
+
77
+ ```json
78
+ {
79
+ "schemaVersion": 1
80
+ }
81
+ ```
82
+
83
+ Consumers should check `schemaVersion` before relying on optional metadata fields.
84
+
85
+ Unknown future fields should normally be ignored so newer `create-bcp-app` versions remain compatible with older tooling where practical.
86
+
87
+ ## Storage provider metadata
88
+
89
+ Storage choices currently include:
90
+
91
+ ```text
92
+ none
93
+ local
94
+ amazon-s3
95
+ cloudflare-r2
96
+ ```
97
+
98
+ `bcp inspect` can use the metadata first and fall back to inspecting `lib/storage.ts` for older projects without `bcp.project.json`.
99
+
100
+ ## Existing projects
101
+
102
+ Projects created before `0.1.29` do not need this file to keep running.
103
+
104
+ The metadata file is additive. Doctor/inspect can still infer core project information from `package.json`, lockfiles, routes and generated source where possible.
105
+
106
+ If an older project wants to adopt the file manually, keep the schema minimal and do not invent preset values that are not actually in use.
107
+
108
+ ## Source control
109
+
110
+ `bcp.project.json` should normally be committed to source control because it contains project structure metadata, not secrets.
111
+
112
+ This allows CI and documentation tooling to read the same preset identity as local developer tooling.
@@ -0,0 +1,134 @@
1
+ # BCP Framework 0.1.28
2
+
3
+ BCP Framework `0.1.28` is the **Production Hardening** milestone.
4
+
5
+ > Release state: unreleased development target until local validation, RC checks, tagging and npm publication complete.
6
+
7
+ ## Highlights
8
+
9
+ - Added a public production hardening gateway around the existing standalone runtime.
10
+ - Added configurable request, header, keep-alive and shutdown timeouts.
11
+ - Added graceful `SIGTERM` / `SIGINT` handling for Docker and process managers.
12
+ - Added application shutdown hooks through `registerShutdownHook()`.
13
+ - Added trusted-proxy forwarding-header sanitization with secure default `BCP_TRUST_PROXY=false`.
14
+ - Added force-close fallback after the configured graceful shutdown timeout.
15
+ - Fixed `create-bcp-app --storage local` so generated projects no longer contain an unexplained empty storage directory.
16
+ - Added `storage/README.md` and `storage/.gitkeep` while continuing to ignore runtime storage objects.
17
+ - Added regression coverage for production hardening primitives and Local Server scaffolding.
18
+
19
+ ## Production environment controls
20
+
21
+ ```dotenv
22
+ BCP_REQUEST_TIMEOUT_MS=120000
23
+ BCP_HEADERS_TIMEOUT_MS=66000
24
+ BCP_KEEP_ALIVE_TIMEOUT_MS=65000
25
+ BCP_SHUTDOWN_TIMEOUT_MS=10000
26
+ BCP_TRUST_PROXY=false
27
+ ```
28
+
29
+ Defaults are production-safe and require no configuration for ordinary direct HTTP deployments.
30
+
31
+ `BCP_HEADERS_TIMEOUT_MS` must be greater than `BCP_KEEP_ALIVE_TIMEOUT_MS`.
32
+
33
+ ## Graceful shutdown
34
+
35
+ The standalone production runtime now handles:
36
+
37
+ ```text
38
+ SIGTERM
39
+ SIGINT
40
+ ```
41
+
42
+ The runtime first stops/drains the public hardening gateway, then runs application shutdown hooks, then stops internal BCP runtime layers.
43
+
44
+ After `BCP_SHUTDOWN_TIMEOUT_MS`, remaining public connections are force-closed.
45
+
46
+ ## Public API addition
47
+
48
+ ```ts
49
+ import {
50
+ getProductionHardeningConfig,
51
+ registerShutdownHook,
52
+ } from "bcp/server";
53
+ ```
54
+
55
+ Example:
56
+
57
+ ```ts
58
+ registerShutdownHook(
59
+ () => {
60
+ storage.destroy();
61
+ },
62
+ {
63
+ name: "storage",
64
+ }
65
+ );
66
+ ```
67
+
68
+ Hooks run in reverse registration order and can be unregistered with the cleanup function returned by `registerShutdownHook()`.
69
+
70
+ ## Trusted proxy behavior
71
+
72
+ Trusted proxy mode is disabled by default.
73
+
74
+ When disabled, BCP strips spoofable incoming forwarding headers at the public hardening gateway and writes forwarding information from the actual connection.
75
+
76
+ When the application is intentionally deployed behind a trusted reverse proxy/load balancer, enable:
77
+
78
+ ```dotenv
79
+ BCP_TRUST_PROXY=true
80
+ ```
81
+
82
+ Only enable it when direct untrusted traffic cannot bypass the trusted proxy.
83
+
84
+ ## Local Server storage fix
85
+
86
+ Before `0.1.28`, selecting Local Server generated `lib/storage.ts` and configured `./storage`, but the runtime directory had no explanatory scaffold before the first upload.
87
+
88
+ `0.1.28` generates:
89
+
90
+ ```text
91
+ storage/
92
+ ├─ .gitkeep
93
+ └─ README.md
94
+ ```
95
+
96
+ and uses Git ignore rules:
97
+
98
+ ```gitignore
99
+ storage/*
100
+ !storage/.gitkeep
101
+ !storage/README.md
102
+ ```
103
+
104
+ Runtime uploads and `.bcp-storage-meta` remain untracked while the directory structure is visible in a fresh project.
105
+
106
+ ## Testing
107
+
108
+ `0.1.28` adds coverage for:
109
+
110
+ - production timeout parsing,
111
+ - invalid timeout relationships,
112
+ - applying Node HTTP server timeout settings,
113
+ - graceful HTTP server close,
114
+ - shutdown hook ordering/unregistration,
115
+ - generated Local Server storage directory scaffold,
116
+ - generated Local Server Git ignore behavior.
117
+
118
+ ## Remaining release work
119
+
120
+ Before publication:
121
+
122
+ 1. sync `package-lock.json` to `0.1.28`,
123
+ 2. run `npm run typecheck`,
124
+ 3. run unit/integration/E2E/package tests,
125
+ 4. run `npm run rc:check`,
126
+ 5. build a representative BCP application,
127
+ 6. run the standalone artifact in Docker,
128
+ 7. verify `docker stop` produces graceful shutdown logs,
129
+ 8. create the `v0.1.28` tag only after the final release commit is known,
130
+ 9. publish and verify npm visibility.
131
+
132
+ ## Next milestone
133
+
134
+ The planned next milestone is `0.1.29 — Developer Experience`, focused on generators, richer `doctor` / `inspect`, improved diagnostics and create-app workflow improvements.
@@ -0,0 +1,170 @@
1
+ # BCP Framework 0.1.29
2
+
3
+ > **Milestone:** Developer Experience
4
+ >
5
+ > **Release state:** unreleased development target. Do not mark this version as published until local validation, RC checks, tagging and npm publication complete.
6
+
7
+ BCP Framework `0.1.29` focuses on reducing repetitive project setup and making project diagnostics easier to consume locally, in CI and in `bcp-docs-web`.
8
+
9
+ ## Highlights
10
+
11
+ ### Project generators
12
+
13
+ New CLI command:
14
+
15
+ ```bash
16
+ bcp generate <kind>
17
+ ```
18
+
19
+ Supported generators:
20
+
21
+ ```bash
22
+ bcp generate page dashboard/users
23
+ bcp generate api users
24
+ bcp generate middleware
25
+ bcp generate migration create_users
26
+ ```
27
+
28
+ Page, API and middleware generators refuse to replace existing files unless `--force` is explicitly supplied.
29
+
30
+ Migration generation reuses the existing database migration implementation so timestamp/file naming has a single source of truth.
31
+
32
+ ### Doctor / Inspect v2
33
+
34
+ `bcp doctor` now adds project/runtime checks for:
35
+
36
+ - supported dependency lockfiles,
37
+ - duplicate `bcp` / `@chidchanun/bcp` dependency declarations,
38
+ - production hardening environment validity,
39
+ - standalone production build presence,
40
+ - Docker + lockfile reproducibility guidance,
41
+ - configured storage provider detection.
42
+
43
+ `bcp inspect` keeps its previous report fields and adds a `project` section with:
44
+
45
+ ```text
46
+ package manager
47
+ lockfile
48
+ bcp.project.json metadata
49
+ selected create-bcp-app presets
50
+ production build presence
51
+ Dockerfile presence
52
+ framework dependency declarations
53
+ storage provider
54
+ production hardening state
55
+ ```
56
+
57
+ The new fields are additive so existing consumers of the previous JSON fields can continue reading them.
58
+
59
+ ### `bcp.project.json`
60
+
61
+ New projects created by `create-bcp-app` receive a non-secret metadata manifest:
62
+
63
+ ```json
64
+ {
65
+ "schemaVersion": 1,
66
+ "framework": "bcp",
67
+ "projectName": "my-app",
68
+ "createdWith": {
69
+ "package": "create-bcp-app",
70
+ "version": "0.1.29"
71
+ },
72
+ "packageManager": "npm",
73
+ "presets": {
74
+ "tailwind": true,
75
+ "database": "mysql",
76
+ "auth": "jwt-cookie",
77
+ "storage": "local"
78
+ }
79
+ }
80
+ ```
81
+
82
+ The manifest records scaffold identity only. Credentials, passwords, access keys, session secrets and tokens must remain outside this file.
83
+
84
+ Older projects without `bcp.project.json` continue to work. Doctor/inspect fall back to project files where practical.
85
+
86
+ ### Docs-web manifest
87
+
88
+ `docs/docs-web-manifest.json` is now the explicit navigation contract for `bcp-docs-web`.
89
+
90
+ It maps:
91
+
92
+ ```text
93
+ section
94
+ website route
95
+ Markdown source
96
+ title
97
+ release routes
98
+ version target
99
+ release state
100
+ ```
101
+
102
+ The Markdown files under `docs/` remain the authored documentation source of truth. The JSON manifest is navigation/routing metadata, not a competing content source.
103
+
104
+ New authored guides include:
105
+
106
+ - `docs/generators.md`
107
+ - `docs/project-metadata.md`
108
+
109
+ ## Compatibility
110
+
111
+ `0.1.29` is intended to be additive.
112
+
113
+ - Existing page/API routing remains unchanged.
114
+ - Existing database migration commands remain supported.
115
+ - `bcp doctor` retains its existing report structure and adds checks.
116
+ - `bcp inspect` retains its existing fields and adds `project`.
117
+ - Existing projects do not require `bcp.project.json`.
118
+ - `--force` is opt-in and never silently overwrites existing generated files.
119
+
120
+ ## Out of scope
121
+
122
+ The following are not guarantees of `0.1.29`:
123
+
124
+ - generated symbol/API reference documentation,
125
+ - interactive documentation playgrounds,
126
+ - source-code merge behavior for generators,
127
+ - automatic conversion of old projects into `bcp.project.json`,
128
+ - the `0.2.0` API/platform stability baseline.
129
+
130
+ ## Documentation sources
131
+
132
+ Primary documentation for this milestone:
133
+
134
+ ```text
135
+ docs/generators.md
136
+ docs/developer-tools.md
137
+ docs/project-metadata.md
138
+ docs/docs-web-manifest.json
139
+ docs/README.md
140
+ ```
141
+
142
+ ## Validation
143
+
144
+ Before tagging or publishing `0.1.29`, run:
145
+
146
+ ```powershell
147
+ npm run typecheck
148
+ npm run test:unit
149
+ npm run test:integration
150
+ npm run test:package
151
+ npm run test:e2e
152
+ npm run rc:check
153
+ ```
154
+
155
+ The release lockfile must also be synchronized to `0.1.29` before the final tag.
156
+
157
+ Recommended generator smoke checks:
158
+
159
+ ```powershell
160
+ npm exec -- bcp-framework generate page dx-test --root examples/basic-app
161
+ npm exec -- bcp-framework routes --root examples/basic-app
162
+ ```
163
+
164
+ Use a disposable project for destructive `--force` testing.
165
+
166
+ ## Next direction
167
+
168
+ After `0.1.29`, the planned major milestone is **`0.2.0 — Framework Platform`**.
169
+
170
+ The `0.2.0` work should focus on consolidating the existing `0.1.x` surface into a documented platform baseline: API consistency, production stabilization, documentation completeness, migration guidance and compatibility expectations rather than adding unrelated large feature areas.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chidchanun/bcp",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "BCP Framework - a React full-stack framework with file-based routing, SSR, APIs, middleware, islands, caching and standalone production builds.",
5
5
  "type": "module",
6
6
  "license": "MIT",