create-bcp-app 0.2.5 → 0.2.7
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 +62 -18
- package/package.json +1 -1
- package/template/README.md +63 -5
package/README.md
CHANGED
|
@@ -92,10 +92,10 @@ Example:
|
|
|
92
92
|
"schemaVersion": 1,
|
|
93
93
|
"framework": "bcp",
|
|
94
94
|
"projectName": "my-app",
|
|
95
|
-
"frameworkPackage": "npm:@chidchanun/bcp@0.2.
|
|
95
|
+
"frameworkPackage": "npm:@chidchanun/bcp@0.2.7",
|
|
96
96
|
"createdWith": {
|
|
97
97
|
"package": "create-bcp-app",
|
|
98
|
-
"version": "0.2.
|
|
98
|
+
"version": "0.2.7"
|
|
99
99
|
},
|
|
100
100
|
"packageManager": "npm",
|
|
101
101
|
"presets": {
|
|
@@ -292,16 +292,70 @@ const sessionStore =
|
|
|
292
292
|
|
|
293
293
|
const frameworkAuth =
|
|
294
294
|
createAuth<AuthenticatedUser>({
|
|
295
|
-
store:
|
|
296
|
-
|
|
297
|
-
idleTimeout:
|
|
298
|
-
60 * 30,
|
|
295
|
+
store: sessionStore,
|
|
296
|
+
idleTimeout: 60 * 30,
|
|
299
297
|
});
|
|
300
298
|
```
|
|
301
299
|
|
|
302
300
|
The memory store is intended for development/tests. Multi-process production deployments should implement `AuthSessionStore` using shared durable storage.
|
|
303
301
|
|
|
304
|
-
|
|
302
|
+
## Authorization & request security — 0.2.6+
|
|
303
|
+
|
|
304
|
+
Generated applications can add permissions to their application user shape and use server-side permission guards without changing the auth preset routes:
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
import {
|
|
308
|
+
createPermissionGuard,
|
|
309
|
+
hasPermission,
|
|
310
|
+
} from "bcp/auth";
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
For resource-specific decisions, use `defineAuthorizationPolicy()`, `can()` or `authorize()`.
|
|
314
|
+
|
|
315
|
+
Cookie-authenticated mutation routes can opt into same-origin and CSRF protection through `bcp/server`:
|
|
316
|
+
|
|
317
|
+
```ts
|
|
318
|
+
import {
|
|
319
|
+
createCsrfToken,
|
|
320
|
+
requireCsrfRequest,
|
|
321
|
+
requireSameOriginRequest,
|
|
322
|
+
} from "bcp/server";
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
`createCsrfToken()` uses `BCP_CSRF_SECRET` when configured and otherwise falls back to `BCP_SESSION_SECRET`, so the generated JWT auth preset does not require another environment variable to get started. Production applications may define a separate `BCP_CSRF_SECRET` for independent key rotation.
|
|
326
|
+
|
|
327
|
+
Authorization and CSRF checks must remain on the server; hiding UI controls in client code is not an authorization boundary.
|
|
328
|
+
|
|
329
|
+
## Observability — 0.2.7+
|
|
330
|
+
|
|
331
|
+
Generated projects can opt into process-local metrics and health/readiness without adding another dependency:
|
|
332
|
+
|
|
333
|
+
```ts
|
|
334
|
+
import {
|
|
335
|
+
createHealthRegistry,
|
|
336
|
+
createMetricsRegistry,
|
|
337
|
+
createRequestMetricsMiddleware,
|
|
338
|
+
} from "bcp/observability";
|
|
339
|
+
|
|
340
|
+
export const metrics =
|
|
341
|
+
createMetricsRegistry();
|
|
342
|
+
|
|
343
|
+
export const health =
|
|
344
|
+
createHealthRegistry();
|
|
345
|
+
|
|
346
|
+
export const requestMetrics =
|
|
347
|
+
createRequestMetricsMiddleware(
|
|
348
|
+
metrics
|
|
349
|
+
);
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Expose metrics from an application API route with `createMetricsResponse(metrics)`. The response uses Prometheus-compatible text format.
|
|
353
|
+
|
|
354
|
+
Health endpoints can return `health.response()`, which uses HTTP `200` when all checks pass and `503` when any dependency check fails or times out.
|
|
355
|
+
|
|
356
|
+
The default HTTP request metrics use `method` and `status` labels only. Raw paths are intentionally excluded to avoid high-cardinality metric series.
|
|
357
|
+
|
|
358
|
+
`bcp/observability` is server-only. Protect metrics and operational health detail with an appropriate network or authorization boundary when needed.
|
|
305
359
|
|
|
306
360
|
## Application Packaging — 0.2.4+
|
|
307
361
|
|
|
@@ -337,8 +391,6 @@ npm ci --omit=dev
|
|
|
337
391
|
npm start
|
|
338
392
|
```
|
|
339
393
|
|
|
340
|
-
If the package manifest reports that no lockfile was included, use the install command recorded in `bcp.package.json`.
|
|
341
|
-
|
|
342
394
|
## Project generators after creation
|
|
343
395
|
|
|
344
396
|
```bash
|
|
@@ -357,14 +409,6 @@ bcp generate middleware
|
|
|
357
409
|
bcp generate migration create_users
|
|
358
410
|
```
|
|
359
411
|
|
|
360
|
-
From PowerShell:
|
|
361
|
-
|
|
362
|
-
```powershell
|
|
363
|
-
npm exec -- bcp-framework generate page dashboard/users
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
Use `--force` only when intentionally replacing an existing page/API/middleware scaffold.
|
|
367
|
-
|
|
368
412
|
## Options
|
|
369
413
|
|
|
370
414
|
```text
|
|
@@ -394,5 +438,5 @@ npx create-bcp-app my-app --yes
|
|
|
394
438
|
The `--bcp` option is mainly for prerelease/local package verification:
|
|
395
439
|
|
|
396
440
|
```bash
|
|
397
|
-
npx create-bcp-app my-app --bcp file:../chidchanun-bcp-0.2.
|
|
441
|
+
npx create-bcp-app my-app --bcp file:../chidchanun-bcp-0.2.7.tgz
|
|
398
442
|
```
|
package/package.json
CHANGED
package/template/README.md
CHANGED
|
@@ -56,16 +56,74 @@ const sessionStore =
|
|
|
56
56
|
|
|
57
57
|
export const appAuth =
|
|
58
58
|
createAuth({
|
|
59
|
-
store:
|
|
60
|
-
|
|
61
|
-
idleTimeout:
|
|
62
|
-
60 * 30,
|
|
59
|
+
store: sessionStore,
|
|
60
|
+
idleTimeout: 60 * 30,
|
|
63
61
|
});
|
|
64
62
|
```
|
|
65
63
|
|
|
66
64
|
The memory store is intended for local development/tests. Use a shared durable `AuthSessionStore` implementation for multi-process or multi-container production deployments.
|
|
67
65
|
|
|
68
|
-
|
|
66
|
+
## Authorization & request security — BCP 0.2.6+
|
|
67
|
+
|
|
68
|
+
Server-side permission guards:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import {
|
|
72
|
+
createPermissionGuard,
|
|
73
|
+
} from "bcp/auth";
|
|
74
|
+
|
|
75
|
+
export const guard =
|
|
76
|
+
createPermissionGuard(
|
|
77
|
+
"dashboard.read"
|
|
78
|
+
);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For ownership or resource-specific rules, use `defineAuthorizationPolicy()`, `can()` and `authorize()` from `bcp/auth`.
|
|
82
|
+
|
|
83
|
+
Cookie-authenticated mutation routes can validate browser origin and CSRF state:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import {
|
|
87
|
+
createCsrfToken,
|
|
88
|
+
requireCsrfRequest,
|
|
89
|
+
requireSameOriginRequest,
|
|
90
|
+
} from "bcp/server";
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`createCsrfToken()` uses `BCP_CSRF_SECRET` when configured and otherwise falls back to `BCP_SESSION_SECRET`.
|
|
94
|
+
|
|
95
|
+
Authorization must always be enforced server-side. Client UI visibility is not a security boundary.
|
|
96
|
+
|
|
97
|
+
## Observability — BCP 0.2.7+
|
|
98
|
+
|
|
99
|
+
Create process-local metrics and health/readiness registries:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import {
|
|
103
|
+
createHealthRegistry,
|
|
104
|
+
createMetricsRegistry,
|
|
105
|
+
createRequestMetricsMiddleware,
|
|
106
|
+
} from "bcp/observability";
|
|
107
|
+
|
|
108
|
+
export const metrics =
|
|
109
|
+
createMetricsRegistry();
|
|
110
|
+
|
|
111
|
+
export const health =
|
|
112
|
+
createHealthRegistry();
|
|
113
|
+
|
|
114
|
+
export const requestMetrics =
|
|
115
|
+
createRequestMetricsMiddleware(
|
|
116
|
+
metrics
|
|
117
|
+
);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Expose Prometheus-compatible metrics with `createMetricsResponse(metrics)` from a server API route.
|
|
121
|
+
|
|
122
|
+
Use `health.response()` for readiness endpoints. It returns HTTP `200` when all checks pass and `503` when a check fails or times out.
|
|
123
|
+
|
|
124
|
+
The default request metrics use bounded `method` and `status` labels and do not include raw paths.
|
|
125
|
+
|
|
126
|
+
Protect operational endpoints when their contents should not be public.
|
|
69
127
|
|
|
70
128
|
## Generate framework files
|
|
71
129
|
|