@forklaunch/core 4.3.0 → 4.6.0

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.
@@ -638,6 +638,73 @@ function createContext(schemaValidator) {
638
638
  };
639
639
  }
640
640
 
641
+ // src/http/telemetry/processErrorPolicy.ts
642
+ var TRANSIENT_NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
643
+ "ERR_HTTP2_SESSION_ERROR",
644
+ "ERR_HTTP2_STREAM_ERROR",
645
+ "ERR_HTTP2_STREAM_CANCEL",
646
+ "ERR_HTTP2_GOAWAY_SESSION",
647
+ "ERR_HTTP2_ERROR",
648
+ "ERR_HTTP2_PING_CANCEL",
649
+ "ECONNRESET",
650
+ "ECONNREFUSED",
651
+ "ECONNABORTED",
652
+ "EPIPE",
653
+ "ETIMEDOUT",
654
+ "EHOSTUNREACH",
655
+ "ENETUNREACH",
656
+ "ENETDOWN",
657
+ "EAI_AGAIN",
658
+ "UND_ERR_SOCKET",
659
+ "UND_ERR_CONNECT_TIMEOUT",
660
+ "UND_ERR_HEADERS_TIMEOUT",
661
+ "UND_ERR_BODY_TIMEOUT"
662
+ ]);
663
+ function isTransientNetworkError(error) {
664
+ if (!(error instanceof Error)) return false;
665
+ const code = error.code;
666
+ return typeof code === "string" && TRANSIENT_NETWORK_ERROR_CODES.has(code);
667
+ }
668
+ function createProcessErrorHandlers(logger2, options2 = {}) {
669
+ const exit = options2.exit ?? ((code) => process.exit(code));
670
+ const now = options2.now ?? Date.now;
671
+ const maxPerWindow = options2.maxPerWindow ?? 20;
672
+ const windowMs = options2.windowMs ?? 6e4;
673
+ const suffix = options2.label ? ` ${options2.label}` : "";
674
+ const recent = [];
675
+ const withinBudget = () => {
676
+ const at = now();
677
+ while (recent.length && at - recent[0] > windowMs) recent.shift();
678
+ recent.push(at);
679
+ return recent.length <= maxPerWindow;
680
+ };
681
+ const handle = (title) => (error) => {
682
+ const detail = error instanceof Error ? [error] : [];
683
+ if (isTransientNetworkError(error)) {
684
+ const code = error.code;
685
+ if (withinBudget()) {
686
+ logger2.error(
687
+ `${title}${suffix} from a network connection (${code}); process kept alive: ${error}`,
688
+ ...detail
689
+ );
690
+ return;
691
+ }
692
+ logger2.error(
693
+ `${title}${suffix}: more than ${maxPerWindow} network connection errors within ${windowMs} ms; exiting: ${error}`,
694
+ ...detail
695
+ );
696
+ exit(1);
697
+ return;
698
+ }
699
+ logger2.error(`${title}${suffix}: ${error}`, ...detail);
700
+ exit(1);
701
+ };
702
+ return {
703
+ uncaughtException: handle("Uncaught exception"),
704
+ unhandledRejection: handle("Unhandled rejection")
705
+ };
706
+ }
707
+
641
708
  // src/http/router/discriminateBody.ts
642
709
  function discriminateBody(schemaValidator, body, inputProjection) {
643
710
  if (body == null) {
@@ -2211,14 +2278,9 @@ function installProcessHandlers(openTelemetryCollector) {
2211
2278
  return;
2212
2279
  }
2213
2280
  processHandlersInstalled = true;
2214
- process.on("uncaughtException", (err) => {
2215
- openTelemetryCollector.error(`Uncaught exception: ${err}`);
2216
- process.exit(1);
2217
- });
2218
- process.on("unhandledRejection", (reason) => {
2219
- openTelemetryCollector.error(`Unhandled rejection: ${reason}`);
2220
- process.exit(1);
2221
- });
2281
+ const handlers = createProcessErrorHandlers(openTelemetryCollector);
2282
+ process.on("uncaughtException", handlers.uncaughtException);
2283
+ process.on("unhandledRejection", handlers.unhandledRejection);
2222
2284
  process.on("exit", () => {
2223
2285
  openTelemetryCollector.info("Shutting down application");
2224
2286
  });
@@ -4075,6 +4137,15 @@ function createStripeClient(options2 = {}) {
4075
4137
  );
4076
4138
  }
4077
4139
 
4140
+ // src/http/outboundHttp1.ts
4141
+ import { Agent, setGlobalDispatcher } from "undici";
4142
+ var HTTP1_ONLY_AGENT_OPTIONS = { allowH2: false };
4143
+ function useHttp1ForOutboundFetch(set = setGlobalDispatcher) {
4144
+ const dispatcher = new Agent(HTTP1_ONLY_AGENT_OPTIONS);
4145
+ set(dispatcher);
4146
+ return dispatcher;
4147
+ }
4148
+
4078
4149
  // src/http/guards/isPath.ts
4079
4150
  function isPath(path) {
4080
4151
  return path.startsWith("/");
@@ -6922,6 +6993,7 @@ export {
6922
6993
  EmailRequestError,
6923
6994
  ForklaunchExpressLikeApplication,
6924
6995
  ForklaunchExpressLikeRouter,
6996
+ HTTP1_ONLY_AGENT_OPTIONS,
6925
6997
  HTTPStatuses,
6926
6998
  INSTANCE_GATEWAY_MOUNT,
6927
6999
  InMemoryHmacNonceStore,
@@ -6942,6 +7014,7 @@ export {
6942
7014
  SmsClient,
6943
7015
  SmsRequestError,
6944
7016
  SmsValidationError,
7017
+ TRANSIENT_NETWORK_ERROR_CODES,
6945
7018
  VOICE_ATTRIBUTE_LIMITS,
6946
7019
  VoiceClient,
6947
7020
  VoiceRequestError,
@@ -6961,6 +7034,7 @@ export {
6961
7034
  createModelGatewayClient,
6962
7035
  createPaymentsClient,
6963
7036
  createPreviewModelGatewayClient,
7037
+ createProcessErrorHandlers,
6964
7038
  createRouteMcpAuthenticate,
6965
7039
  createSmsClient,
6966
7040
  createStripeClient,
@@ -7002,6 +7076,7 @@ export {
7002
7076
  isSeparateMcpListener,
7003
7077
  isServerError,
7004
7078
  isSuccessful,
7079
+ isTransientNetworkError,
7005
7080
  isValidStatusCode,
7006
7081
  jwtAlgorithmsForPublicKey,
7007
7082
  jwtAlgorithmsForSharedSecret,
@@ -7031,6 +7106,7 @@ export {
7031
7106
  ttlCacheHmacNonceStore,
7032
7107
  typedAuthHandler,
7033
7108
  typedHandler,
7109
+ useHttp1ForOutboundFetch,
7034
7110
  validateEmailSendRequest,
7035
7111
  validateListUnsubscribe,
7036
7112
  validateSmsSend,