@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.
@@ -0,0 +1,224 @@
1
+ # API Reference
2
+
3
+ BCP Framework exposes a small set of supported package entrypoints. Import application APIs through these entrypoints instead of private files under `packages/`.
4
+
5
+ The machine-readable source for this page is `docs/api-manifest.json`.
6
+
7
+ ## `bcp`
8
+
9
+ Universal React application APIs.
10
+
11
+ Common exports include:
12
+
13
+ ```ts
14
+ import {
15
+ Form,
16
+ Link,
17
+ createIsland,
18
+ navigate,
19
+ notFound,
20
+ useActionData,
21
+ useActionError,
22
+ useFormStatus,
23
+ useGuardData,
24
+ useLoaderData,
25
+ useNavigation,
26
+ useRouter,
27
+ } from "bcp";
28
+ ```
29
+
30
+ Use this entrypoint for page/client-facing framework APIs, routing, forms, loader/guard data, islands and metadata types.
31
+
32
+ Related guides: [Routing](routing.md), [Server Data Loaders](server-data-loaders.md), [Route Guards](route-guards.md), [Form Actions](form-actions.md).
33
+
34
+ ## `bcp/island`
35
+
36
+ Partial-hydration island APIs.
37
+
38
+ ```ts
39
+ import {
40
+ createIsland,
41
+ } from "bcp/island";
42
+ ```
43
+
44
+ Related guide: [Hydration](hydration.md).
45
+
46
+ ## `bcp/cache`
47
+
48
+ Caching and revalidation APIs.
49
+
50
+ ```ts
51
+ import {
52
+ cache,
53
+ clearCache,
54
+ dedupe,
55
+ getCacheStats,
56
+ revalidatePath,
57
+ revalidateTag,
58
+ } from "bcp/cache";
59
+ ```
60
+
61
+ Related guide: [Caching](caching.md).
62
+
63
+ ## `bcp/config`
64
+
65
+ Typed framework configuration, application environment-schema validation and diagnostics APIs.
66
+
67
+ ```ts
68
+ import {
69
+ applyEnvironmentDefaults,
70
+ defineConfig,
71
+ defineEnvironment,
72
+ diagnoseBcpConfiguration,
73
+ getEnvironmentSchemaFileNames,
74
+ loadBcpEnvironmentSchema,
75
+ readResolvedBcpConfig,
76
+ resolveBcpConfig,
77
+ validateEnvironment,
78
+ } from "bcp/config";
79
+ ```
80
+
81
+ Use `defineConfig()` for framework runtime/build settings and `defineEnvironment()` for the optional `bcp.environment.*` application-variable schema.
82
+
83
+ `validateEnvironment()` returns parsed declared values and structured issues. `applyEnvironmentDefaults()` fills only missing environment keys and does not overwrite values already supplied by the environment/runtime.
84
+
85
+ Related guides: [Configuration](configuration.md), [Environment Validation](environment-validation.md).
86
+
87
+ ## `bcp/validation`
88
+
89
+ Typed validation primitives and `ValidationError`.
90
+
91
+ ```ts
92
+ import {
93
+ array,
94
+ boolean,
95
+ literal,
96
+ nullable,
97
+ number,
98
+ object,
99
+ optional,
100
+ parse,
101
+ safeParse,
102
+ string,
103
+ union,
104
+ } from "bcp/validation";
105
+ ```
106
+
107
+ Related guide: [Validation](validation.md).
108
+
109
+ ## `bcp/error`
110
+
111
+ Structured HTTP error helpers.
112
+
113
+ ```ts
114
+ import {
115
+ HttpError,
116
+ badRequest,
117
+ conflict,
118
+ forbidden,
119
+ internalServerError,
120
+ isHttpError,
121
+ serviceUnavailable,
122
+ throwHttpError,
123
+ tooManyRequests,
124
+ unauthorized,
125
+ unprocessableEntity,
126
+ } from "bcp/error";
127
+ ```
128
+
129
+ Related guide: [Error Handling](error-handling.md).
130
+
131
+ ## `bcp/database`
132
+
133
+ Server-only database primitives.
134
+
135
+ ```ts
136
+ import {
137
+ createDatabase,
138
+ db,
139
+ } from "bcp/database";
140
+ ```
141
+
142
+ Use the public database helpers instead of importing framework-internal pool/runtime modules.
143
+
144
+ Related guides: [Database](database.md), [Database Migrations](database-migrations.md).
145
+
146
+ ## `bcp/auth`
147
+
148
+ Authentication and authorization APIs.
149
+
150
+ ```ts
151
+ import {
152
+ auth,
153
+ createAuth,
154
+ createAuthGuard,
155
+ createRoleGuard,
156
+ getGuardAuth,
157
+ getSession,
158
+ login,
159
+ logout,
160
+ requireAuth,
161
+ requireRole,
162
+ rotateSession,
163
+ } from "bcp/auth";
164
+ ```
165
+
166
+ Related guides: [Authentication](authentication.md), [Auth Route Guards](auth-route-guards.md), [JWT Sessions](session-auth.md).
167
+
168
+ ## `bcp/server`
169
+
170
+ Server request/runtime APIs.
171
+
172
+ This entrypoint includes request context, cookies, logging, graceful shutdown hooks, multipart upload helpers, storage adapters, file delivery, response helpers and low-level session primitives.
173
+
174
+ ```ts
175
+ import {
176
+ clientIp,
177
+ cookies,
178
+ createLocalStorage,
179
+ createLogger,
180
+ createS3Storage,
181
+ createStorageResponse,
182
+ getProductionHardeningConfig,
183
+ headers,
184
+ json,
185
+ redirect,
186
+ registerShutdownHook,
187
+ requestId,
188
+ requestMethod,
189
+ requestUrl,
190
+ storeMultipartFile,
191
+ } from "bcp/server";
192
+ ```
193
+
194
+ Related guides: [Server Request APIs](server-request-apis.md), [File Upload](file-upload.md), [Storage](storage.md), [Storage Ecosystem](storage-ecosystem.md), [Production Hardening](production-hardening.md).
195
+
196
+ ## `bcp/server-only`
197
+
198
+ Server-only module boundary marker.
199
+
200
+ ```ts
201
+ import "bcp/server-only";
202
+ ```
203
+
204
+ Place this import in application modules that must never enter a browser bundle.
205
+
206
+ Related guide: [Application Modules](application-modules.md).
207
+
208
+ ## `bcp/middleware`
209
+
210
+ Middleware System v2 APIs and types.
211
+
212
+ ```ts
213
+ import type {
214
+ MiddlewarePipelineHandler,
215
+ } from "bcp/middleware";
216
+ ```
217
+
218
+ Related guide: [Middleware](middleware.md).
219
+
220
+ ## Stability
221
+
222
+ Only package entrypoints listed in both `docs/platform-manifest.json` and `docs/api-manifest.json` are part of the documented platform surface.
223
+
224
+ Files under internal `packages/*` paths are framework implementation details unless re-exported through a documented public package entrypoint.
@@ -92,6 +92,101 @@ BCP_EXPERIMENTAL_ISLANDS
92
92
 
93
93
  Application environment variables prefixed with `BCP_PUBLIC_` may be embedded into browser bundles. Other application variables remain server-side.
94
94
 
95
+ ## Configuration & Environment v2
96
+
97
+ BCP `0.2.2` adds an optional application environment schema in one of:
98
+
99
+ ```text
100
+ bcp.environment.ts
101
+ bcp.environment.mts
102
+ bcp.environment.js
103
+ bcp.environment.mjs
104
+ ```
105
+
106
+ The schema validates application-specific values after `.env` files are loaded.
107
+
108
+ Example:
109
+
110
+ ```ts
111
+ import {
112
+ defineEnvironment,
113
+ } from "bcp/config";
114
+
115
+ export default defineEnvironment({
116
+ DATABASE_URL: {
117
+ type: "string",
118
+ required: true,
119
+ },
120
+ SESSION_SECRET: {
121
+ type: "string",
122
+ required: true,
123
+ secret: true,
124
+ minLength: 32,
125
+ },
126
+ BCP_PUBLIC_API_URL: {
127
+ type: "url",
128
+ required: true,
129
+ },
130
+ });
131
+ ```
132
+
133
+ This schema is additive. Projects without `bcp.environment.*` continue to use the existing environment behavior.
134
+
135
+ Read more: [Environment Validation](environment-validation.md)
136
+
137
+ ## Configuration check
138
+
139
+ Validate the current project without starting the application:
140
+
141
+ ```bash
142
+ bcp config check
143
+ ```
144
+
145
+ JSON diagnostics:
146
+
147
+ ```bash
148
+ bcp config check --json
149
+ ```
150
+
151
+ Windows project-local form:
152
+
153
+ ```powershell
154
+ npm exec -- bcp-framework config check
155
+ ```
156
+
157
+ The check reports the selected config file, environment files, environment schema, resolved server/build settings and diagnostics. Raw environment values are not printed.
158
+
159
+ For production-mode warnings in PowerShell:
160
+
161
+ ```powershell
162
+ $env:NODE_ENV = "production"
163
+ npm exec -- bcp-framework config check
164
+ Remove-Item Env:NODE_ENV
165
+ ```
166
+
167
+ ## Startup diagnostics
168
+
169
+ `bcp dev` and `bcp build` run the environment-schema diagnostics before the application starts/builds.
170
+
171
+ Schema errors stop startup/build early. Production safety warnings do not fail the build by themselves.
172
+
173
+ Examples of production warnings include:
174
+
175
+ - source maps enabled,
176
+ - powered-by header enabled,
177
+ - Content-Security-Policy disabled,
178
+ - trusted proxy mode enabled.
179
+
180
+ Trusted proxy mode should only be enabled when untrusted clients cannot bypass the trusted proxy/load balancer.
181
+
95
182
  ## Config reload in development
96
183
 
97
- Changes to supported `.env*` files or `bcp.config.*` restart the development worker so the new resolved configuration is applied without restarting the parent CLI manually.
184
+ Changes to these configuration sources restart the development worker automatically:
185
+
186
+ ```text
187
+ .env*
188
+ bcp.config.*
189
+ bcp.environment.*
190
+ ```
191
+
192
+ The parent development supervisor stays running while the worker reloads the new configuration/environment state.
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
3
  "framework": "bcp",
4
- "versionTarget": "0.2.0",
4
+ "versionTarget": "0.2.2",
5
5
  "releaseState": "unreleased",
6
6
  "sections": [
7
7
  {
8
8
  "id": "getting-started",
9
9
  "title": "Getting Started",
10
+ "description": "Create, configure, deploy and update BCP applications.",
10
11
  "pages": [
11
12
  { "route": "/docs/getting-started", "source": "getting-started.md", "title": "Getting Started" },
12
13
  { "route": "/docs/configuration", "source": "configuration.md", "title": "Configuration" },
14
+ { "route": "/docs/environment-validation", "source": "environment-validation.md", "title": "Environment Validation" },
13
15
  { "route": "/docs/application-modules", "source": "application-modules.md", "title": "Application Modules" },
14
16
  { "route": "/docs/project-metadata", "source": "project-metadata.md", "title": "Project Metadata" },
15
17
  { "route": "/docs/deployment", "source": "deployment.md", "title": "Deployment" },
@@ -19,6 +21,7 @@
19
21
  {
20
22
  "id": "routing-data",
21
23
  "title": "Routing & Data",
24
+ "description": "Routing, server data, mutations, validation and structured errors.",
22
25
  "pages": [
23
26
  { "route": "/docs/routing", "source": "routing.md", "title": "Routing" },
24
27
  { "route": "/docs/server-data-loaders", "source": "server-data-loaders.md", "title": "Server Data Loaders" },
@@ -32,6 +35,7 @@
32
35
  {
33
36
  "id": "authentication",
34
37
  "title": "Authentication",
38
+ "description": "Authentication core, auth-aware route guards and JWT cookie sessions.",
35
39
  "pages": [
36
40
  { "route": "/docs/authentication", "source": "authentication.md", "title": "Authentication" },
37
41
  { "route": "/docs/auth-route-guards", "source": "auth-route-guards.md", "title": "Auth Route Guards" },
@@ -41,6 +45,7 @@
41
45
  {
42
46
  "id": "database",
43
47
  "title": "Database",
48
+ "description": "Database primitives, transactions and migration workflows.",
44
49
  "pages": [
45
50
  { "route": "/docs/database", "source": "database.md", "title": "Database" },
46
51
  { "route": "/docs/database-migrations", "source": "database-migrations.md", "title": "Database Migrations" }
@@ -49,6 +54,7 @@
49
54
  {
50
55
  "id": "runtime",
51
56
  "title": "Runtime & Infrastructure",
57
+ "description": "Middleware, hydration, logging, caching, security and production hardening.",
52
58
  "pages": [
53
59
  { "route": "/docs/middleware", "source": "middleware.md", "title": "Middleware" },
54
60
  { "route": "/docs/hydration", "source": "hydration.md", "title": "Hydration" },
@@ -61,6 +67,7 @@
61
67
  {
62
68
  "id": "storage",
63
69
  "title": "Storage & Uploads",
70
+ "description": "Multipart uploads, storage adapters, file delivery and object-storage features.",
64
71
  "pages": [
65
72
  { "route": "/docs/file-upload", "source": "file-upload.md", "title": "File Upload" },
66
73
  { "route": "/docs/storage", "source": "storage.md", "title": "Storage & File Delivery" },
@@ -71,6 +78,7 @@
71
78
  {
72
79
  "id": "developer-experience",
73
80
  "title": "Developer Experience",
81
+ "description": "Project generators, diagnostics, project metadata and framework maintenance tooling.",
74
82
  "pages": [
75
83
  { "route": "/docs/generators", "source": "generators.md", "title": "Project Generators" },
76
84
  { "route": "/docs/developer-tools", "source": "developer-tools.md", "title": "Doctor & Inspect" }
@@ -79,14 +87,26 @@
79
87
  {
80
88
  "id": "platform-compatibility",
81
89
  "title": "Platform & Compatibility",
90
+ "description": "Supported platform contracts, documentation integration and migration guidance.",
82
91
  "pages": [
83
92
  { "route": "/docs/platform-contract", "source": "platform-contract.md", "title": "Framework Platform Contract" },
84
- { "route": "/docs/migration-0.2", "source": "migration-0.2.md", "title": "Migrating to 0.2.0" }
93
+ { "route": "/docs/documentation-platform", "source": "documentation-platform.md", "title": "Documentation Platform" },
94
+ { "route": "/docs/migration-0.2", "source": "migration-0.2.md", "title": "Migrating to 0.2.x" }
95
+ ]
96
+ },
97
+ {
98
+ "id": "api-reference",
99
+ "title": "API Reference",
100
+ "description": "Supported BCP package entrypoints and their guide ownership.",
101
+ "pages": [
102
+ { "route": "/docs/api-reference", "source": "api-reference.md", "title": "API Reference" }
85
103
  ]
86
104
  }
87
105
  ],
88
106
  "releases": [
89
- { "route": "/releases/0.2.0", "source": "releases/0.2.0.md", "version": "0.2.0", "state": "unreleased" },
107
+ { "route": "/releases/0.2.2", "source": "releases/0.2.2.md", "version": "0.2.2", "state": "unreleased" },
108
+ { "route": "/releases/0.2.1", "source": "releases/0.2.1.md", "version": "0.2.1" },
109
+ { "route": "/releases/0.2.0", "source": "releases/0.2.0.md", "version": "0.2.0" },
90
110
  { "route": "/releases/0.1.29", "source": "releases/0.1.29.md", "version": "0.1.29" },
91
111
  { "route": "/releases/0.1.28", "source": "releases/0.1.28.md", "version": "0.1.28" },
92
112
  { "route": "/releases/0.1.27", "source": "releases/0.1.27.md", "version": "0.1.27" },
@@ -0,0 +1,136 @@
1
+ # Documentation Platform
2
+
3
+ BCP Framework `0.2.1` defines a machine-readable documentation platform so the framework repository remains the source of truth while `bcp-docs-web` acts as the presentation, search and navigation layer.
4
+
5
+ ## Source contracts
6
+
7
+ The documentation platform uses three manifests:
8
+
9
+ ```text
10
+ docs/docs-web-manifest.json
11
+ Navigation, routes, page titles and release routes.
12
+
13
+ docs/platform-manifest.json
14
+ Framework runtime, public entrypoints, capabilities and compatibility baseline.
15
+
16
+ docs/api-manifest.json
17
+ Public package entrypoints, source ownership, environment boundary and guide mapping.
18
+ ```
19
+
20
+ Markdown files under `docs/` remain the authored documentation content.
21
+
22
+ ## Docs-web synchronization
23
+
24
+ `bcp-docs-web` should read the manifests first and then load the Markdown sources they reference.
25
+
26
+ Recommended flow:
27
+
28
+ ```text
29
+ Framework repository / selected ref
30
+
31
+ docs-web-manifest.json
32
+ platform-manifest.json
33
+ api-manifest.json
34
+
35
+ validate matching framework/version
36
+
37
+ load Markdown sources
38
+
39
+ synchronize CMS/search/navigation
40
+
41
+ render docs website
42
+ ```
43
+
44
+ The website must not maintain a competing hard-coded list of framework pages when a page exists in `docs-web-manifest.json`.
45
+
46
+ ## Version and release state
47
+
48
+ The current documentation target and release state come from the framework manifests.
49
+
50
+ For an unreleased development target:
51
+
52
+ ```json
53
+ {
54
+ "version": "0.2.1",
55
+ "releaseState": "unreleased"
56
+ }
57
+ ```
58
+
59
+ A release note existing in the repository does not mean that version has been published to npm. Release state should only move to a published value after the release workflow succeeds.
60
+
61
+ ## API reference contract
62
+
63
+ `docs/api-manifest.json` describes supported public package entrypoints.
64
+
65
+ Each entry records:
66
+
67
+ ```text
68
+ package name
69
+ source file
70
+ environment boundary
71
+ API-reference route
72
+ summary
73
+ related guide routes
74
+ ```
75
+
76
+ The manifest intentionally documents public package boundaries instead of private framework implementation modules.
77
+
78
+ Public entrypoints are also checked against `docs/platform-manifest.json` and the prepared npm package during release validation.
79
+
80
+ ## Historical versions
81
+
82
+ The synchronization workflow accepts a Git ref. This allows documentation to be synchronized from a release tag instead of only from `main`.
83
+
84
+ Example:
85
+
86
+ ```powershell
87
+ npm run docs:sync -- --ref=v0.2.0
88
+ ```
89
+
90
+ A docs website may use this foundation for version snapshots without copying current documentation into a second manually maintained source tree.
91
+
92
+ ## Search
93
+
94
+ Search should index the synchronized Markdown documents, not the manifest JSON itself. Manifest titles, categories and API entrypoint summaries may be added to the search index as metadata.
95
+
96
+ ## Previous / next navigation
97
+
98
+ Previous and next document ordering should follow the order in `docs-web-manifest.json`.
99
+
100
+ This keeps sidebar order and previous/next navigation consistent.
101
+
102
+ ## Security boundary
103
+
104
+ Documentation synchronization must only read files explicitly referenced by validated manifests.
105
+
106
+ Source paths must:
107
+
108
+ - be relative to `docs/`,
109
+ - reject `..` traversal,
110
+ - reject absolute paths,
111
+ - use expected Markdown or JSON source types,
112
+ - never ingest `.env`, credentials or application project secrets.
113
+
114
+ `bcp.project.json` is intentionally non-secret, but a documentation site should still avoid reading arbitrary application project files.
115
+
116
+ ## Release validation
117
+
118
+ Before a Documentation Platform release:
119
+
120
+ ```bash
121
+ npm run typecheck
122
+ npm run test:unit
123
+ npm run test:integration
124
+ npm run test:e2e
125
+ npm run test:package
126
+ npm run rc:check
127
+ ```
128
+
129
+ Validation should ensure:
130
+
131
+ - all docs-web page sources exist,
132
+ - all docs routes are unique,
133
+ - API entrypoints are unique,
134
+ - API entrypoints match the platform public-entrypoint baseline,
135
+ - manifest versions match the framework version,
136
+ - prepared npm artifacts contain the documentation contracts.