@chidchanun/bcp 0.2.16 → 0.2.17

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.
@@ -1,14 +1,14 @@
1
1
  # API Reference
2
2
 
3
- BCP Framework exposes a small set of supported package entrypoints. Import application APIs through these entrypoints instead of private files under `packages/`.
3
+ BCP Framework exposes supported package entrypoints through the `bcp` package. Application code should import these public entrypoints instead of private implementation files under `packages/`.
4
4
 
5
5
  The machine-readable source for this page is `docs/api-manifest.json`.
6
6
 
7
7
  ## `bcp`
8
8
 
9
- Universal React application APIs.
9
+ Universal React application APIs for routing, navigation, layouts, metadata, loaders, route guards, form actions and islands.
10
10
 
11
- Common exports include `Form`, `Link`, `createIsland`, `navigate`, `notFound`, loader/action/guard hooks and router/navigation APIs.
11
+ Common exports include `Form`, `Link`, `createIsland`, `navigate`, `notFound` and loader/action/guard hooks.
12
12
 
13
13
  Related guides: [Routing](routing.md), [Server Data Loaders](server-data-loaders.md), [Route Guards](route-guards.md), [Form Actions](form-actions.md), [Testing Platform](testing-platform.md).
14
14
 
@@ -26,70 +26,37 @@ Related guide: [Hydration](hydration.md).
26
26
 
27
27
  ## `bcp/cache`
28
28
 
29
- Caching APIs include the original process-local request/data cache plus Cache Platform v2 provider contracts for shared production caches.
29
+ Backward-compatible request/data caching plus Cache Platform v2 shared-store APIs.
30
30
 
31
- Legacy-compatible exports remain:
31
+ Legacy APIs:
32
32
 
33
- ```ts
34
- import {
35
- cache,
36
- clearCache,
37
- dedupe,
38
- getCacheStats,
39
- revalidatePath,
40
- revalidateTag,
41
- } from "bcp/cache";
33
+ ```text
34
+ cache
35
+ dedupe
36
+ clearCache
37
+ getCacheStats
38
+ revalidateTag
39
+ revalidatePath
42
40
  ```
43
41
 
44
- Cache Platform v2 adds:
42
+ Cache Platform v2 APIs:
45
43
 
46
- ```ts
47
- import {
48
- createCacheMetrics,
49
- createCacheStore,
50
- createMemoryCacheAdapter,
51
- createMemoryCacheLockAdapter,
52
- createRedisCacheAdapter,
53
- createRedisCacheLockAdapter,
54
- type CacheAdapter,
55
- type CacheAdapterEntry,
56
- type CacheAdapterSetOptions,
57
- type CacheGetOrSetOptions,
58
- type CacheLockAdapter,
59
- type CacheMetricsRegistryLike,
60
- type CacheMetricsSink,
61
- type CacheStore,
62
- type CacheStoreEvent,
63
- type CacheStoreOptions,
64
- type CacheStoreSetOptions,
65
- type CacheStoreStats,
66
- type MemoryCacheAdapter,
67
- type MemoryCacheLockAdapter,
68
- type RedisCacheAdapter,
69
- type RedisCacheAdapterOptions,
70
- type RedisCacheCommandClient,
71
- type RedisCacheLockAdapter,
72
- type RedisCacheLockAdapterOptions,
73
- } from "bcp/cache";
44
+ ```text
45
+ createCacheStore
46
+ createMemoryCacheAdapter
47
+ createMemoryCacheLockAdapter
48
+ createRedisCacheAdapter
49
+ createRedisCacheLockAdapter
50
+ createCacheMetrics
74
51
  ```
75
52
 
76
- `createCacheStore()` exposes async `get()`, `set()`, `delete()`, `clear()`, `revalidateTag()`, `revalidatePath()`, `getOrSet()`, `stats()` and `close()` operations.
77
-
78
- `getOrSet()` always provides local singleflight deduplication. When a `CacheLockAdapter` is supplied, cache fills can also coordinate across multiple application instances with owner-scoped leases, optional renewal and configurable contention timeout behavior.
79
-
80
- `createRedisCacheAdapter()` and `createRedisCacheLockAdapter()` use a minimal `sendCommand()` client contract. BCP does not install or own a Redis library/connection. The default namespace is `bcp:{cache}` for Redis Cluster hash-slot locality.
81
-
82
- Cache Store v2 uses millisecond TTL (`ttlMs`), while the original `cache()` API keeps its existing `revalidate`-seconds contract.
53
+ Public contracts include `CacheAdapter`, `CacheLockAdapter`, `CacheStore`, cache statistics/options and Redis command-client adapter types.
83
54
 
84
- `createCacheMetrics()` adapts cache events to the existing BCP `MetricsRegistry` shape without coupling the cache package directly to a specific exporter.
85
-
86
- Prepared npm packages compile the runtime entrypoint to `packages/client/src/cache.mjs`.
87
-
88
- Related guides: [Caching](caching.md), [Cache Platform v2](cache-platform-v2.md), [Observability Platform v2](observability.md).
55
+ Related guides: [Caching](caching.md), [Cache Platform v2](cache-platform-v2.md), [Observability Platform v3](observability-v3.md).
89
56
 
90
57
  ## `bcp/config`
91
58
 
92
- Typed framework configuration, application environment-schema validation and diagnostics APIs.
59
+ Typed BCP configuration, environment-schema validation and diagnostics APIs.
93
60
 
94
61
  Related guides: [Configuration](configuration.md), [Environment Validation](environment-validation.md).
95
62
 
@@ -107,323 +74,300 @@ Related guide: [Error Handling](error-handling.md).
107
74
 
108
75
  ## `bcp/database`
109
76
 
110
- Server-only Database Platform v2 APIs.
77
+ Server-only provider-neutral SQL APIs for MySQL, PostgreSQL and SQLite.
111
78
 
112
- Built-in SQL providers are MySQL, PostgreSQL and SQLite. `BcpDatabase` instances expose lazy query/execute/transaction operations plus explicit `connect()`, `disconnect()` and backward-compatible `close()` lifecycle methods.
79
+ Core capabilities include query/execute, transactions, lifecycle, migration stores and migration execution.
113
80
 
114
- Related guides: [Database](database.md), [Database Migrations](database-migrations.md), [Transactional Outbox & Events](transactional-outbox-events.md), [Testing Platform](testing-platform.md).
81
+ Related guides: [Database](database.md), [Database Migrations](database-migrations.md), [Transactional Outbox & Events](transactional-outbox-events.md), [Testing Platform](testing-platform.md), [Observability Platform v3](observability-v3.md).
115
82
 
116
83
  ## `bcp/auth`
117
84
 
118
- Server-only authentication and authorization APIs.
85
+ Server-only Authentication Platform v2 and Authorization & Security v2 APIs.
119
86
 
120
- The default authentication mode remains stateless signed JWT-cookie authentication. Applications may opt into server-side session stores, revocation, logout-all, idle timeout, role/permission guards and resource-aware authorization policies.
87
+ Capabilities include JWT-cookie sessions, optional server-side session stores, revocation, logout-all, idle timeout, role/permission guards, policies, same-origin protection and auth/guest guards.
121
88
 
122
- Related guides: [Authentication](authentication.md), [Auth Session Stores](auth-session-store.md), [Auth Route Guards](auth-route-guards.md), [Authorization & Security v2](authorization-security.md), [JWT Sessions](session-auth.md), [Testing Platform](testing-platform.md).
89
+ Related guides: [Authentication](authentication.md), [Auth Session Stores](auth-session-store.md), [Auth Route Guards](auth-route-guards.md), [Authorization & Security v2](authorization-security.md), [JWT Sessions](session-auth.md).
123
90
 
124
91
  ## `bcp/jobs`
125
92
 
126
- Server-only Background Jobs, Job Scheduling and Durable Jobs APIs.
127
-
128
- Core queue APIs include `createJobQueue()`, `createMemoryJobQueueAdapter()`, queue/worker records, retry/backoff, visibility leases, heartbeat renewal, stale recovery, DLQ operations, retention cleanup and queue statistics.
93
+ Server-only background jobs, scheduling and durable job APIs.
129
94
 
130
- Scheduling APIs include `createJobScheduler()`, `createMemoryJobScheduleStore()`, `nextCronTime()` and `nextScheduleTime()`.
95
+ Core queue APIs include:
131
96
 
132
- Durable Redis-compatible APIs added in `0.2.10` include `createRedisJobQueueAdapter()` and `createRedisJobScheduleStore()`.
97
+ ```text
98
+ createJobQueue
99
+ createMemoryJobQueueAdapter
100
+ createRedisJobQueueAdapter
101
+ createJobScheduler
102
+ createMemoryJobScheduleStore
103
+ createRedisJobScheduleStore
104
+ nextCronTime
105
+ nextScheduleTime
106
+ ```
133
107
 
134
- BCP does not install a Redis library and does not create the connection. Applications own authentication, TLS, Cluster/Sentinel configuration and connection shutdown.
108
+ Capabilities include delay, retry/backoff, worker concurrency, cancellation, visibility leases, heartbeat renewal, stale recovery, DLQ/requeue, retention cleanup, queue statistics and recurring interval/UTC cron schedules.
135
109
 
136
- The processing model is at-least-once. Handlers that perform non-idempotent external side effects should use application-level idempotency protection.
110
+ Processing remains at-least-once; non-repeatable external side effects should use application-level idempotency.
137
111
 
138
- Related guides: [Background Jobs Platform](background-jobs.md), [Job Scheduling Platform](job-scheduling.md), [Durable Jobs Platform](durable-jobs.md), [Transactional Outbox & Events](transactional-outbox-events.md), [Realtime Platform](realtime-platform.md), [Testing Platform](testing-platform.md), [Observability Platform v2](observability.md).
112
+ Related guides: [Background Jobs](background-jobs.md), [Job Scheduling](job-scheduling.md), [Durable Jobs](durable-jobs.md), [Observability Platform v3](observability-v3.md).
139
113
 
140
114
  ## `bcp/workflow`
141
115
 
142
- Server-only Workflow Orchestration APIs added in `0.2.11`.
143
-
144
- ```ts
145
- import {
146
- createMemoryWorkflowStore,
147
- createWorkflow,
148
- } from "bcp/workflow";
149
- ```
150
-
151
- `createWorkflow()` defines persistent server-side workflows with sequential steps, parallel groups, per-step retry policies, persisted delays and compensation handlers.
152
-
153
- Workflow controls include:
116
+ Server-only Workflow Orchestration APIs.
154
117
 
155
118
  ```text
156
- start()
157
- run()
158
- get()
159
- list()
160
- resume()
161
- retry()
162
- cancel()
163
- compensate()
164
- close()
119
+ createWorkflow
120
+ createMemoryWorkflowStore
165
121
  ```
166
122
 
167
- When an existing `BackgroundJobQueue` is supplied, workflow execution and delay continuation can run through `bcp/jobs`.
123
+ Workflow controls include `start`, `run`, `get`, `list`, `resume`, `retry`, `cancel`, `compensate` and `close`.
168
124
 
169
- `WorkflowStore.claim()` / `release()` form the run-level lease boundary for multi-instance stores.
125
+ Capabilities include sequential/parallel steps, per-step retry, persisted delays, compensation, run leases and optional execution through `bcp/jobs`.
170
126
 
171
- Related guides: [Workflow Orchestration](workflow-orchestration.md), [Durable Jobs Platform](durable-jobs.md), [Realtime Platform](realtime-platform.md), [Testing Platform](testing-platform.md), [Observability Platform v2](observability.md).
127
+ Related guides: [Workflow Orchestration](workflow-orchestration.md), [Durable Jobs](durable-jobs.md), [Observability Platform v3](observability-v3.md).
172
128
 
173
129
  ## `bcp/events`
174
130
 
175
- Server-only Transactional Outbox & Events APIs added in `0.2.12`.
131
+ Server-only Transactional Outbox & Events APIs.
176
132
 
177
- ```ts
178
- import {
179
- createEventBus,
180
- createMemoryOutboxStore,
181
- createOutboxDispatcher,
182
- createOutboxMigrationSql,
183
- createSqlOutboxStore,
184
- createTransactionalOutbox,
185
- } from "bcp/events";
133
+ ```text
134
+ createTransactionalOutbox
135
+ createMemoryOutboxStore
136
+ createSqlOutboxStore
137
+ createOutboxMigrationSql
138
+ createOutboxDispatcher
139
+ createEventBus
186
140
  ```
187
141
 
188
- `createTransactionalOutbox()` writes an event through the same `TransactionDatabase` used by `db.transaction()`, allowing business rows and outbox rows to commit or roll back together.
142
+ SQL outbox storage supports MySQL, PostgreSQL and SQLite. Dispatch supports batched claims, leases, stale recovery, retry/backoff, terminal failure, durable-job handoff and custom publishing.
189
143
 
190
- `createSqlOutboxStore()` supports MySQL, PostgreSQL and SQLite. `createOutboxMigrationSql()` generates the outbox table/index DDL.
191
-
192
- `createOutboxDispatcher()` supports batched claims, leases, stale recovery, retry/backoff, terminal failure, job-queue handoff, custom publishing, local event-bus delivery and runner lifecycle.
193
-
194
- Delivery is at-least-once; consumers should use idempotency controls for non-repeatable side effects.
195
-
196
- Related guides: [Transactional Outbox & Events](transactional-outbox-events.md), [Database](database.md), [Durable Jobs Platform](durable-jobs.md), [Realtime Platform](realtime-platform.md), [Testing Platform](testing-platform.md), [Observability Platform v2](observability.md).
144
+ Related guides: [Transactional Outbox & Events](transactional-outbox-events.md), [Database](database.md), [Durable Jobs](durable-jobs.md), [Observability Platform v3](observability-v3.md).
197
145
 
198
146
  ## `bcp/realtime`
199
147
 
200
- Server-only Realtime Platform APIs added in `0.2.13`.
148
+ Server-only realtime APIs for channels/rooms, broker delivery, presence, channel authorization, socket adapters, heartbeat and Server-Sent Events.
201
149
 
202
- ```ts
203
- import {
204
- createMemoryRealtimeBroker,
205
- createMemoryRealtimePresenceStore,
206
- createRealtime,
207
- createRealtimeSseResponse,
208
- type RealtimeAuthenticate,
209
- type RealtimeAuthorizeChannel,
210
- type RealtimeBroker,
211
- type RealtimeBroadcastOptions,
212
- type RealtimeConnection,
213
- type RealtimeEnvelope,
214
- type RealtimeEventContext,
215
- type RealtimeEventHandler,
216
- type RealtimeHeartbeatOptions,
217
- type RealtimeHeartbeatRunner,
218
- type RealtimeHub,
219
- type RealtimeJoinOptions,
220
- type RealtimeOptions,
221
- type RealtimePresenceMember,
222
- type RealtimePresenceStore,
223
- type RealtimeSocket,
224
- type RealtimeSseOptions,
225
- } from "bcp/realtime";
150
+ ```text
151
+ createRealtime
152
+ createMemoryRealtimeBroker
153
+ createMemoryRealtimePresenceStore
154
+ createRealtimeSseResponse
226
155
  ```
227
156
 
228
- `createRealtime()` creates a server-side hub. Connections can `join()`, `leave()`, `emit()`, `send()`, `touch()` and `disconnect()`.
229
-
230
- `RealtimeBroker` is the cross-hub pub/sub boundary and `RealtimePresenceStore` is the channel-presence boundary. Built-in memory implementations are intended for tests/single-process use; shared deployments can supply provider adapters.
231
-
232
- `RealtimeOptions.authenticate` can resolve identity from a Request/connection payload, while `authorizeChannel` runs before channel membership is accepted.
157
+ BCP intentionally does not install a WebSocket server library. Applications adapt the selected provider through `RealtimeSocket`.
233
158
 
234
- BCP does not install a WebSocket provider. `RealtimeSocket` defines the minimal transport surface consumed by `hub.attachSocket()`.
235
-
236
- `hub.sse()` and `createRealtimeSseResponse()` expose Web-standard Server-Sent Events responses with abort, filtering, retry hint and keep-alive options.
237
-
238
- Realtime delivery is transient. Use database/outbox/jobs/workflows for durable state and refetch durable state/history after reconnect when catch-up is required.
239
-
240
- Related guides: [Realtime Platform](realtime-platform.md), [Authentication](authentication.md), [Testing Platform](testing-platform.md), [Observability Platform v2](observability.md).
159
+ Related guides: [Realtime Platform](realtime-platform.md), [Testing Platform](testing-platform.md), [Observability Platform v3](observability-v3.md).
241
160
 
242
161
  ## `bcp/testing`
243
162
 
244
- Server-only Testing Platform APIs added in `0.2.14`.
245
-
246
- ```ts
247
- import {
248
- createFakeClock,
249
- createJobTestHarness,
250
- createOutboxTestHarness,
251
- createRealtimeTestHarness,
252
- createRealtimeTestSocket,
253
- createRouteTestHandler,
254
- createSequenceIdFactory,
255
- createTestApp,
256
- createTestAuthSession,
257
- createTestFormData,
258
- createWorkflowTestHarness,
259
- expectResponse,
260
- readSseEvents,
261
- runTestMiddleware,
262
- runTestPageAction,
263
- runTestPageGuards,
264
- runTestPageLoader,
265
- withTestTransaction,
266
- type CreateTestAuthSessionOptions,
267
- type FakeClock,
268
- type JobTestHarness,
269
- type OutboxTestHarness,
270
- type ParsedSseEvent,
271
- type RealtimeTestConnection,
272
- type RealtimeTestHarness,
273
- type RealtimeTestSocket,
274
- type TestApp,
275
- type TestAppOptions,
276
- type TestAuthSession,
277
- type TestPageActionOptions,
278
- type TestPageContextOptions,
279
- type TestPageGuardOptions,
280
- type TestRequestHandler,
281
- type TestRequestOptions,
282
- type TestResponseExpectation,
283
- type TestRouteFunction,
284
- type TestRouteHandlerOptions,
285
- type TestRouteMethod,
286
- type TestRouteModule,
287
- type TestTransactionDatabase,
288
- type WorkflowTestHarness,
289
- } from "bcp/testing";
290
- ```
163
+ Server-only framework-native testing utilities. BCP does not require Jest or Vitest.
291
164
 
292
- ### Request application harness
165
+ Important APIs include:
293
166
 
294
- `createTestApp()` runs a Web-standard `Request -> Response` handler with convenience methods for GET/POST/PUT/PATCH/DELETE, JSON bodies, mutable default headers and an in-memory cookie jar that consumes `Set-Cookie` responses.
167
+ ```text
168
+ createTestApp
169
+ createRouteTestHandler
170
+ expectResponse
171
+ createTestAuthSession
172
+ withTestTransaction
173
+ runTestMiddleware
174
+ runTestPageLoader
175
+ runTestPageGuards
176
+ runTestPageAction
177
+ createFakeClock
178
+ createSequenceIdFactory
179
+ createJobTestHarness
180
+ createWorkflowTestHarness
181
+ createOutboxTestHarness
182
+ createRealtimeTestSocket
183
+ createRealtimeTestHarness
184
+ readSseEvents
185
+ ```
295
186
 
296
- ### API route module testing
187
+ Related guide: [Testing Platform](testing-platform.md).
297
188
 
298
- `createRouteTestHandler()` adapts BCP-style method exports (`GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS`) to a Request handler. Missing methods return 405 with an `Allow` header.
189
+ ## `bcp/plugins`
299
190
 
300
- Return values are normalized for tests: Response is preserved, strings become text Responses, null/undefined become 204, and other values become JSON.
191
+ Server-only Plugin & Module Platform APIs.
301
192
 
302
- ### Page loader, guard and form action testing
193
+ ```text
194
+ definePlugin
195
+ defineModule
196
+ createPluginHost
197
+ createPluginServiceRegistry
198
+ createPluginHookBus
199
+ ```
303
200
 
304
- `runTestPageGuards()` executes one or more guards through the production `executePageGuardFunctions()` path. Guard data is chained in order and redirect/other Response short-circuits are preserved.
201
+ Capabilities include required/optional dependency ordering, setup/start/stop/dispose lifecycle, startup rollback, typed configuration parsing, shared services and awaited in-process hooks.
305
202
 
306
- `runTestPageLoader()` invokes the production `executePageLoaderFunction()` path with test params, URL/search params and optional guard data. The returned value is the normal `PageLoaderExecution` contract.
203
+ Related guides: [Plugin & Module Platform](plugin-module-platform.md), [Configuration](configuration.md), [Observability Platform v3](observability-v3.md).
307
204
 
308
- `runTestPageAction()` invokes the production `executePageActionFunction()` path, including action-name/method validation, guard data, FormData and Response/data handling.
205
+ ## `bcp/observability`
309
206
 
310
- `createTestFormData()` creates a FormData object from string/Blob fields and supports repeated values.
207
+ Server-only metrics, health and tracing APIs.
311
208
 
312
- ### Response assertions
209
+ ### Observability Platform v2
313
210
 
314
- `expectResponse()` exposes lightweight runner-neutral assertions:
211
+ Existing APIs remain supported:
315
212
 
316
213
  ```text
317
- status()
318
- header()
319
- text()
320
- json()
321
- jsonMatches()
214
+ createMetricsRegistry
215
+ createMetricsResponse
216
+ createRequestMetricsMiddleware
217
+ createHealthRegistry
322
218
  ```
323
219
 
324
- BCP does not require Jest/Vitest assertion APIs.
220
+ The metrics registry provides counters, gauges, histograms and Prometheus exposition. Health checks provide readiness/liveness-style reports with timeout support.
325
221
 
326
- ### Auth testing
222
+ ### Observability Platform v3 — 0.2.17
327
223
 
328
- `createTestAuthSession()` uses the production `createSessionToken()` implementation, including HS256 signature, issuer/audience and expiration semantics. It can also register the matching server-side record in an `AuthSessionStore`.
224
+ Tracing APIs:
329
225
 
330
- This allows route/auth tests to use a real BCP session cookie instead of introducing a test-only identity header.
331
-
332
- ### Database rollback testing
333
-
334
- `withTestTransaction()` executes a callback in a real BCP database transaction and deliberately rejects the transaction with an internal rollback sentinel after the test callback succeeds. The callback result is returned to the test while the transaction is rolled back.
226
+ ```ts
227
+ import {
228
+ createCompositeTraceSpanExporter,
229
+ createMemoryTraceSpanExporter,
230
+ createRequestTracingMiddleware,
231
+ createTraceCarrier,
232
+ createTraceMetricsExporter,
233
+ createTracer,
234
+ currentTraceContext,
235
+ extractTraceCarrier,
236
+ extractTraceHeaders,
237
+ formatTraceparent,
238
+ getTraceLogFields,
239
+ injectTraceHeaders,
240
+ parseTraceparent,
241
+ runWithTraceCarrier,
242
+ runWithTraceContext,
243
+ } from "bcp/observability";
244
+ ```
335
245
 
336
- Application callback errors remain unchanged and are not swallowed.
246
+ Important public types:
337
247
 
338
- ### Middleware testing
248
+ ```text
249
+ Tracer
250
+ TracerOptions
251
+ TraceContext
252
+ TraceCarrier
253
+ TraceSpan
254
+ TraceSpanRecord
255
+ TraceSpanEvent
256
+ TraceSpanExporter
257
+ TraceSpanKind
258
+ TraceSpanStatus
259
+ TraceAttributes
260
+ TraceIdFactory
261
+ StartTraceSpanOptions
262
+ RequestTracingOptions
263
+ TraceMetricsOptions
264
+ ```
339
265
 
340
- `runTestMiddleware()` invokes the actual Middleware System v2 onion pipeline through `executeMiddlewarePipeline()` and supports a custom downstream Request handler.
266
+ `createTracer()` creates root/child spans. Active context is stored with Node `AsyncLocalStorage`, allowing nested awaited operations to inherit the current `traceId`, `correlationId` and parent span.
341
267
 
342
- ### Deterministic utilities
268
+ ```ts
269
+ await tracer.withSpan(
270
+ "order.checkout",
271
+ async () => {
272
+ await tracer.withSpan(
273
+ "database.insert",
274
+ createOrder,
275
+ {
276
+ kind: "client",
277
+ }
278
+ );
279
+ }
280
+ );
281
+ ```
343
282
 
344
- `createFakeClock()` exposes `now()`, `set()`, `advance()` and `reset()` for time-sensitive queues/workflows/schedulers.
283
+ Supported span kinds:
345
284
 
346
- `createSequenceIdFactory()` creates deterministic IDs for stable assertions.
285
+ ```text
286
+ internal
287
+ server
288
+ client
289
+ producer
290
+ consumer
291
+ ```
347
292
 
348
- ### Infrastructure harnesses
293
+ Failed `withSpan()` callbacks are marked `error`, receive an `exception` event and rethrow the original application error.
349
294
 
350
- `createJobTestHarness()` drains currently eligible work through the real `BackgroundJobQueue.processNext()` API and exposes record/count assertions.
295
+ ### W3C propagation
351
296
 
352
- `createWorkflowTestHarness()` can start/run workflows until terminal or waiting state and optionally force persisted delays to resume.
297
+ `formatTraceparent()` / `parseTraceparent()` support W3C version `00` trace headers.
353
298
 
354
- `createOutboxTestHarness()` dispatches through the actual `OutboxDispatcher` and exposes event/state/statistics helpers.
299
+ ```ts
300
+ const headers =
301
+ new Headers();
355
302
 
356
- `createRealtimeTestSocket()` implements the `RealtimeSocket` adapter contract entirely in memory. `createRealtimeTestHarness()` connects that socket to a real `RealtimeHub` and can assert server-sent channel events.
303
+ injectTraceHeaders(
304
+ headers
305
+ );
306
+ ```
357
307
 
358
- `readSseEvents()` reads event-stream Responses, ignores comment/retry frames and JSON-decodes `data:` payloads when possible.
308
+ `extractTraceHeaders()` reads `traceparent`, optional `tracestate` and `x-correlation-id`.
359
309
 
360
- ### Runner neutrality and boundary
310
+ ### Middleware tracing
361
311
 
362
- `bcp/testing` has no dependency on Jest or Vitest. BCP's own suite uses Node `node:test`, but the helpers can be called from another runner.
312
+ ```ts
313
+ export const middleware =
314
+ createRequestTracingMiddleware(
315
+ tracer
316
+ );
317
+ ```
363
318
 
364
- The package is server-only; the client boundary validator rejects `bcp/testing` from pages/client islands.
319
+ The middleware continues a valid incoming trace and adds active trace/correlation headers to the response.
365
320
 
366
- Related guides: [Testing Platform](testing-platform.md), [Authentication](authentication.md), [Database](database.md), [Durable Jobs](durable-jobs.md), [Workflow Orchestration](workflow-orchestration.md), [Transactional Outbox & Events](transactional-outbox-events.md), [Realtime Platform](realtime-platform.md).
321
+ ### Non-HTTP propagation
367
322
 
368
- ## `bcp/plugins`
323
+ ```ts
324
+ const trace =
325
+ createTraceCarrier();
326
+ ```
369
327
 
370
- Server-only Plugin & Module Platform APIs added in `0.2.15`.
328
+ Transport that carrier through job payloads, workflow input, event metadata or realtime payloads, then restore it with:
371
329
 
372
330
  ```ts
373
- import {
374
- createPluginHookBus,
375
- createPluginHost,
376
- createPluginServiceRegistry,
377
- defineModule,
378
- definePlugin,
379
- PluginDependencyError,
380
- PluginLifecycleError,
381
- type PluginConfigParser,
382
- type PluginConfigSchema,
383
- type PluginContext,
384
- type PluginDefinition,
385
- type PluginHookBus,
386
- type PluginHookHandler,
387
- type PluginHost,
388
- type PluginHostOptions,
389
- type PluginHostView,
390
- type PluginModule,
391
- type PluginRecord,
392
- type PluginServiceKey,
393
- type PluginServiceRegistry,
394
- type PluginState,
395
- } from "bcp/plugins";
331
+ runWithTraceCarrier(
332
+ payload.trace,
333
+ handler
334
+ );
396
335
  ```
397
336
 
398
- `createPluginHost()` resolves required and optional plugin dependencies and starts plugins in topological order. `stop()` and `close()` shut them down/dispose them in reverse dependency order.
399
-
400
- `defineModule()` groups reusable plugin definitions while preserving one global host dependency graph.
337
+ BCP does not automatically mutate persisted job/workflow/event schemas in `0.2.17`.
401
338
 
402
- Plugin configuration can be parsed with a schema/parser during setup. Values from `PluginHostOptions.configs` override plugin-local defaults before parsing.
339
+ ### Exporters and metrics
403
340
 
404
- `PluginServiceRegistry` provides shared string/Symbol-keyed services. `PluginHookBus` provides awaited, in-process extension hooks in registration order.
341
+ `TraceSpanExporter` is provider-neutral. BCP supplies an in-memory exporter and a composite exporter.
405
342
 
406
- Missing dependencies and dependency cycles throw `PluginDependencyError`. Setup/start failures surface `PluginLifecycleError`; startup failures roll back plugins that already started in the current transition.
343
+ `createTraceMetricsExporter()` converts completed spans into the existing metrics registry:
407
344
 
408
- `host.plugin()` and `host.plugins()` expose inspectable lifecycle records.
345
+ ```text
346
+ bcp_trace_spans_total
347
+ bcp_trace_span_duration_seconds
348
+ ```
409
349
 
410
- `bcp/plugins` is server-only and is rejected from page/client bundles.
350
+ Default labels are `kind` and `status`. Span names are opt-in to reduce accidental high cardinality.
411
351
 
412
- Related guides: [Plugin & Module Platform](plugin-module-platform.md), [Configuration](configuration.md), [Testing Platform](testing-platform.md), [Observability Platform v2](observability.md).
352
+ `getTraceLogFields()` returns:
413
353
 
414
- ## `bcp/observability`
354
+ ```text
355
+ traceId
356
+ spanId
357
+ correlationId
358
+ ```
415
359
 
416
- Server-only Observability Platform v2 APIs for process-local counters, gauges, histograms, Prometheus exposition, request metrics middleware and health/readiness checks.
360
+ for structured log enrichment.
417
361
 
418
- `Cache Platform v2` can connect to this registry through `createCacheMetrics()` from `bcp/cache`.
362
+ Prepared npm packages expose compiled `observability.mjs` as the runtime default for `bcp/observability`.
419
363
 
420
- Related guides: [Observability Platform v2](observability.md), [Logging](development-logging.md), [Cache Platform v2](cache-platform-v2.md).
364
+ Related guides: [Observability Platform v2](observability.md), [Observability Platform v3](observability-v3.md), [Logging](development-logging.md), [Cache Platform v2](cache-platform-v2.md).
421
365
 
422
366
  ## `bcp/server`
423
367
 
424
- Server request/runtime APIs including request context, cookies, CSRF and same-origin protection, logging, graceful shutdown hooks, multipart upload helpers, storage adapters, file delivery, response helpers and low-level session primitives.
368
+ Server request/runtime APIs including request context, cookies, CSRF/same-origin protection, logging, graceful shutdown hooks, multipart upload helpers, storage adapters, file delivery, response helpers and low-level session primitives.
425
369
 
426
- Related guides: [Server Request APIs](server-request-apis.md), [Authorization & Security v2](authorization-security.md), [File Upload](file-upload.md), [Storage](storage.md), [Storage Ecosystem](storage-ecosystem.md), [Production Hardening](production-hardening.md), [Testing Platform](testing-platform.md).
370
+ Related guides: [Server Request APIs](server-request-apis.md), [Authorization & Security v2](authorization-security.md), [File Upload](file-upload.md), [Storage](storage.md), [Production Hardening](production-hardening.md), [Observability Platform v3](observability-v3.md).
427
371
 
428
372
  ## `bcp/server-only`
429
373
 
@@ -433,16 +377,14 @@ Server-only module boundary marker.
433
377
  import "bcp/server-only";
434
378
  ```
435
379
 
436
- Related guide: [Application Modules](application-modules.md).
437
-
438
380
  ## `bcp/middleware`
439
381
 
440
- Middleware System v2 APIs and types.
382
+ Middleware System v2 request/response pipeline types and helpers.
441
383
 
442
- Related guides: [Middleware](middleware.md), [Testing Platform](testing-platform.md).
384
+ Related guides: [Middleware](middleware.md), [Testing Platform](testing-platform.md), [Observability Platform v3](observability-v3.md).
443
385
 
444
386
  ## Stability
445
387
 
446
- Only package entrypoints listed in both `docs/platform-manifest.json` and `docs/api-manifest.json` are part of the documented platform surface.
388
+ Only entrypoints listed in both `docs/platform-manifest.json` and `docs/api-manifest.json` are part of the documented platform surface.
447
389
 
448
- Files under internal `packages/*` paths are framework implementation details unless re-exported through a documented public package entrypoint.
390
+ Files under internal `packages/*` paths are implementation details unless re-exported through a documented public package entrypoint.