learning_ai_common_plat/services/cowork-service/src/lib/auth.ts
saravanakumardb1 19674c7ef7 feat(cowork-service): ecosystem alignment + IPC bridge to Rust runtime
ECOSYSTEM GAPS CLOSED — cowork-service now matches the pattern used by
all other product backends (FlowMonk, ActionTrail, NoteLett, etc.):

New lib files (6):
- lib/product-config.ts — canonical product identity (PRODUCT_ID, productConfig)
- lib/auth.ts — @bytelyst/fastify-auth createAuthMiddleware
- lib/request-context.ts — getUserId(), getRequestProductId()
- lib/telemetry.ts — @bytelyst/backend-telemetry buffer
- lib/feature-flags.ts — @bytelyst/backend-flags with 12 cowork flags
- lib/ipc-bridge.ts — IpcBridge class: spawn Rust child, JSON-RPC, 13 methods

Updated files:
- lib/config.ts — extends @bytelyst/backend-config baseBackendConfigSchema
- server.ts — JWT context, bootstrap endpoint, IPC startup, graceful shutdown
- modules/tasks/routes.ts — IPC bridge forwarding with in-memory fallback
- modules/health/routes.ts — productId from product-config, IPC status
- package.json — 7 new @bytelyst/* workspace deps

IPC bridge features:
- Spawns cowork-orchestrator --ipc-bridge as child process
- JSON-RPC 2.0 over stdin/stdout (line-delimited)
- 13 convenience methods matching Rust IpcHandler
- Timeout + pending request tracking
- Graceful shutdown with SIGTERM
- Singleton pattern with setIpcBridge() for testing

24 tests passing (was 8), typecheck clean.
2026-04-02 22:14:24 -07:00

18 lines
577 B
TypeScript

/**
* JWT auth middleware — delegates to @bytelyst/fastify-auth.
* RS256 JWKS verification with HS256 fallback, configured from local config.
*
* Uses getter functions so config is read on each call (supports test mocks).
*/
import { createAuthMiddleware } from '@bytelyst/fastify-auth';
import { config } from './config.js';
export type { AuthPayload } from '@bytelyst/fastify-auth';
const { extractAuth, requireRole } = createAuthMiddleware({
jwtSecret: () => config.JWT_SECRET,
jwksUrl: () => config.PLATFORM_JWKS_URL,
});
export { extractAuth, requireRole };