stitchkit 0.28.0 → 0.28.1

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.
@@ -557,15 +557,34 @@ function createHandler(config) {
557
557
  const customLogger = logConfig?.logger ?? null;
558
558
  const useDefaultLog = logConfig !== null && !logConfig.logger;
559
559
  const customTraceId = config.traceId;
560
+ const warn = (line) => {
561
+ try {
562
+ if (customLogger)
563
+ customLogger.warn(line);
564
+ else
565
+ console.warn(line);
566
+ } catch {}
567
+ };
568
+ let traceResolverBroken = false;
569
+ const resolveId = (req) => {
570
+ if (!customTraceId)
571
+ return resolveTraceId(req);
572
+ try {
573
+ return customTraceId(req) ?? resolveTraceId(req);
574
+ } catch (err) {
575
+ if (!traceResolverBroken) {
576
+ traceResolverBroken = true;
577
+ warn("[stitchkit] `traceId` resolver threw — falling back to the framework resolver. " + "Ids will not match your observability context until it is fixed: " + `${err instanceof Error ? err.message : String(err)}`);
578
+ }
579
+ return resolveTraceId(req);
580
+ }
581
+ };
560
582
  const routeMap = buildRouteMap(normalizeGroups(config));
561
583
  validateRoutes(routeMap);
562
584
  for (const shadow of findShadowedRoutes(routeMap, config.rawRoutes)) {
563
585
  const gate = shadow.scope && shadow.scope !== "public" ? ` (scope "${shadow.scope}")` : "";
564
586
  const line = `[stitchkit] raw route ${shadow.rawRoute} shadows contract route ${shadow.pattern}` + ` → ${shadow.endpoint}${gate} will never run, and its hooks never apply`;
565
- if (customLogger)
566
- customLogger.warn(line);
567
- else
568
- console.warn(line);
587
+ warn(line);
569
588
  }
570
589
  async function dispatch(req, url, traceId, server, clientIp) {
571
590
  const shouldLogRequest = logConfig !== null && shouldLog(url.pathname, req.method) && !shouldSkipLog(logConfig, req, url);
@@ -637,13 +656,17 @@ function createHandler(config) {
637
656
  if (cors && req.method === "OPTIONS") {
638
657
  return corsPreflightResponse(cors, req);
639
658
  }
640
- if (hooks?.onRequest) {
641
- const earlyResponse = await hooks.onRequest(req);
642
- if (earlyResponse instanceof Response) {
643
- const withCors = applyCors(earlyResponse, cors, req);
644
- logDone(withCors.status);
645
- return withCors;
659
+ try {
660
+ if (hooks?.onRequest) {
661
+ const earlyResponse = await hooks.onRequest(req);
662
+ if (earlyResponse instanceof Response) {
663
+ const withCors = applyCors(earlyResponse, cors, req);
664
+ logDone(withCors.status);
665
+ return withCors;
666
+ }
646
667
  }
668
+ } catch (err) {
669
+ return respondError(err);
647
670
  }
648
671
  if (config.rawRoutes) {
649
672
  const rawMatch = matchRawRoute(config.rawRoutes, req.method, url.pathname);
@@ -707,13 +730,7 @@ function createHandler(config) {
707
730
  }
708
731
  if (method.outputSchema) {
709
732
  const checked = validateHandlerOutput(method.outputSchema, result, config.warnOnOutputStrip ? (paths) => {
710
- const line = `[stitchkit] output strip ${method.serviceName}.${method.key}: ${paths.join(", ")}`;
711
- try {
712
- if (customLogger)
713
- customLogger.warn(line);
714
- else
715
- console.warn(line);
716
- } catch {}
733
+ warn(`[stitchkit] output strip ${method.serviceName}.${method.key}: ${paths.join(", ")}`);
717
734
  } : undefined);
718
735
  if (!checked.ok) {
719
736
  throw new AppError("INTERNAL_SERVER_ERROR", checked.message, 500);
@@ -734,7 +751,7 @@ function createHandler(config) {
734
751
  }
735
752
  return async (req, server) => {
736
753
  const url = new URL(req.url, "http://localhost");
737
- const traceId = customTraceId?.(req) ?? resolveTraceId(req);
754
+ const traceId = resolveId(req);
738
755
  const clientIp = {
739
756
  trustProxy,
740
757
  socketIp: resolveSocketIp(req, server)
package/dist/node.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  createImplement,
4
4
  createSocketIOServer,
5
5
  implement
6
- } from "./index-17jpjnhd.js";
6
+ } from "./index-xnszhd7g.js";
7
7
  import"./index-czmqks7r.js";
8
8
  import {
9
9
  AppError,
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAEV,eAAe,EACf,YAAY,EACZ,aAAa,EAGd,MAAM,SAAS,CAAC;AAEjB,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,YAAY,CAoVjE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,uBAuBnD"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAEV,eAAe,EACf,YAAY,EACZ,aAAa,EAGd,MAAM,SAAS,CAAC;AAEjB,wBAAgB,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,YAAY,CAwXjE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,uBAuBnD"}
@@ -10,7 +10,7 @@ import {
10
10
  socketIoLane,
11
11
  staticRoute,
12
12
  webSocketLane
13
- } from "../index-17jpjnhd.js";
13
+ } from "../index-xnszhd7g.js";
14
14
  import {
15
15
  createAuthHook,
16
16
  createBearerResolver,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stitchkit",
3
- "version": "0.28.0",
3
+ "version": "0.28.1",
4
4
  "description": "Contract-first backend framework — one defineContract() into an HTTP API, MCP tools, AI-agent tools and a typed client. Bun and Node.",
5
5
  "keywords": [
6
6
  "bun",