@forklaunch/core 4.4.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.
@@ -16,6 +16,7 @@ export * from './paymentsClient';
16
16
  export * from './discriminateAuthMethod';
17
17
  export * from './hmacReplayProtection';
18
18
  export * from './jwtAlgorithms';
19
+ export * from './outboundHttp1';
19
20
  export * from './guards/isForklaunchRequest';
20
21
  export * from './guards/isForklaunchRouter';
21
22
  export * from './handlers/delete';
@@ -47,6 +48,7 @@ export * from './telemetry/evaluateTelemetryOptions';
47
48
  export * from './telemetry/metricsDefinition';
48
49
  export * from './telemetry/openTelemetryCollector';
49
50
  export * from './telemetry/pinoLogger';
51
+ export * from './telemetry/processErrorPolicy';
50
52
  export * from './telemetry/recordMetric';
51
53
  export * from './types/apiDefinition.types';
52
54
  export * from './types/contractDetails.types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACnC,cAAc,sCAAsC,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CA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pB,0BAA0B,EAC1B,kBAAkB,EAClB,yBAAyB,EACzB,4BAA4B,EAC5B,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AACjC,cAAc,+CAA+C,CAAC;AAC9D,cAAc,wDAAwD,CAAC;AACvE,cAAc,yCAAyC,CAAC;AACxD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,sCAAsC,CAAC;AACrD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC;AACnD,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAE3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC"}
package/lib/http/index.js CHANGED
@@ -46,6 +46,7 @@ __export(http_exports, {
46
46
  EmailRequestError: () => EmailRequestError,
47
47
  ForklaunchExpressLikeApplication: () => ForklaunchExpressLikeApplication,
48
48
  ForklaunchExpressLikeRouter: () => ForklaunchExpressLikeRouter,
49
+ HTTP1_ONLY_AGENT_OPTIONS: () => HTTP1_ONLY_AGENT_OPTIONS,
49
50
  HTTPStatuses: () => HTTPStatuses,
50
51
  INSTANCE_GATEWAY_MOUNT: () => INSTANCE_GATEWAY_MOUNT,
51
52
  InMemoryHmacNonceStore: () => InMemoryHmacNonceStore,
@@ -66,6 +67,7 @@ __export(http_exports, {
66
67
  SmsClient: () => SmsClient,
67
68
  SmsRequestError: () => SmsRequestError,
68
69
  SmsValidationError: () => SmsValidationError,
70
+ TRANSIENT_NETWORK_ERROR_CODES: () => TRANSIENT_NETWORK_ERROR_CODES,
69
71
  VOICE_ATTRIBUTE_LIMITS: () => VOICE_ATTRIBUTE_LIMITS,
70
72
  VoiceClient: () => VoiceClient,
71
73
  VoiceRequestError: () => VoiceRequestError,
@@ -85,6 +87,7 @@ __export(http_exports, {
85
87
  createModelGatewayClient: () => createModelGatewayClient,
86
88
  createPaymentsClient: () => createPaymentsClient,
87
89
  createPreviewModelGatewayClient: () => createPreviewModelGatewayClient,
90
+ createProcessErrorHandlers: () => createProcessErrorHandlers,
88
91
  createRouteMcpAuthenticate: () => createRouteMcpAuthenticate,
89
92
  createSmsClient: () => createSmsClient,
90
93
  createStripeClient: () => createStripeClient,
@@ -126,6 +129,7 @@ __export(http_exports, {
126
129
  isSeparateMcpListener: () => isSeparateMcpListener,
127
130
  isServerError: () => isServerError,
128
131
  isSuccessful: () => isSuccessful,
132
+ isTransientNetworkError: () => isTransientNetworkError,
129
133
  isValidStatusCode: () => isValidStatusCode,
130
134
  jwtAlgorithmsForPublicKey: () => jwtAlgorithmsForPublicKey,
131
135
  jwtAlgorithmsForSharedSecret: () => jwtAlgorithmsForSharedSecret,
@@ -155,6 +159,7 @@ __export(http_exports, {
155
159
  ttlCacheHmacNonceStore: () => ttlCacheHmacNonceStore,
156
160
  typedAuthHandler: () => typedAuthHandler,
157
161
  typedHandler: () => typedHandler,
162
+ useHttp1ForOutboundFetch: () => useHttp1ForOutboundFetch,
158
163
  validateEmailSendRequest: () => validateEmailSendRequest,
159
164
  validateListUnsubscribe: () => validateListUnsubscribe,
160
165
  validateSmsSend: () => validateSmsSend,
@@ -788,6 +793,73 @@ function createContext(schemaValidator) {
788
793
  };
789
794
  }
790
795
 
796
+ // src/http/telemetry/processErrorPolicy.ts
797
+ var TRANSIENT_NETWORK_ERROR_CODES = /* @__PURE__ */ new Set([
798
+ "ERR_HTTP2_SESSION_ERROR",
799
+ "ERR_HTTP2_STREAM_ERROR",
800
+ "ERR_HTTP2_STREAM_CANCEL",
801
+ "ERR_HTTP2_GOAWAY_SESSION",
802
+ "ERR_HTTP2_ERROR",
803
+ "ERR_HTTP2_PING_CANCEL",
804
+ "ECONNRESET",
805
+ "ECONNREFUSED",
806
+ "ECONNABORTED",
807
+ "EPIPE",
808
+ "ETIMEDOUT",
809
+ "EHOSTUNREACH",
810
+ "ENETUNREACH",
811
+ "ENETDOWN",
812
+ "EAI_AGAIN",
813
+ "UND_ERR_SOCKET",
814
+ "UND_ERR_CONNECT_TIMEOUT",
815
+ "UND_ERR_HEADERS_TIMEOUT",
816
+ "UND_ERR_BODY_TIMEOUT"
817
+ ]);
818
+ function isTransientNetworkError(error) {
819
+ if (!(error instanceof Error)) return false;
820
+ const code = error.code;
821
+ return typeof code === "string" && TRANSIENT_NETWORK_ERROR_CODES.has(code);
822
+ }
823
+ function createProcessErrorHandlers(logger2, options2 = {}) {
824
+ const exit = options2.exit ?? ((code) => process.exit(code));
825
+ const now = options2.now ?? Date.now;
826
+ const maxPerWindow = options2.maxPerWindow ?? 20;
827
+ const windowMs = options2.windowMs ?? 6e4;
828
+ const suffix = options2.label ? ` ${options2.label}` : "";
829
+ const recent = [];
830
+ const withinBudget = () => {
831
+ const at = now();
832
+ while (recent.length && at - recent[0] > windowMs) recent.shift();
833
+ recent.push(at);
834
+ return recent.length <= maxPerWindow;
835
+ };
836
+ const handle = (title) => (error) => {
837
+ const detail = error instanceof Error ? [error] : [];
838
+ if (isTransientNetworkError(error)) {
839
+ const code = error.code;
840
+ if (withinBudget()) {
841
+ logger2.error(
842
+ `${title}${suffix} from a network connection (${code}); process kept alive: ${error}`,
843
+ ...detail
844
+ );
845
+ return;
846
+ }
847
+ logger2.error(
848
+ `${title}${suffix}: more than ${maxPerWindow} network connection errors within ${windowMs} ms; exiting: ${error}`,
849
+ ...detail
850
+ );
851
+ exit(1);
852
+ return;
853
+ }
854
+ logger2.error(`${title}${suffix}: ${error}`, ...detail);
855
+ exit(1);
856
+ };
857
+ return {
858
+ uncaughtException: handle("Uncaught exception"),
859
+ unhandledRejection: handle("Unhandled rejection")
860
+ };
861
+ }
862
+
791
863
  // src/http/router/discriminateBody.ts
792
864
  function discriminateBody(schemaValidator, body, inputProjection) {
793
865
  if (body == null) {
@@ -2355,14 +2427,9 @@ function installProcessHandlers(openTelemetryCollector) {
2355
2427
  return;
2356
2428
  }
2357
2429
  processHandlersInstalled = true;
2358
- process.on("uncaughtException", (err) => {
2359
- openTelemetryCollector.error(`Uncaught exception: ${err}`);
2360
- process.exit(1);
2361
- });
2362
- process.on("unhandledRejection", (reason) => {
2363
- openTelemetryCollector.error(`Unhandled rejection: ${reason}`);
2364
- process.exit(1);
2365
- });
2430
+ const handlers = createProcessErrorHandlers(openTelemetryCollector);
2431
+ process.on("uncaughtException", handlers.uncaughtException);
2432
+ process.on("unhandledRejection", handlers.unhandledRejection);
2366
2433
  process.on("exit", () => {
2367
2434
  openTelemetryCollector.info("Shutting down application");
2368
2435
  });
@@ -4220,6 +4287,15 @@ function createStripeClient(options2 = {}) {
4220
4287
  );
4221
4288
  }
4222
4289
 
4290
+ // src/http/outboundHttp1.ts
4291
+ var import_undici = require("undici");
4292
+ var HTTP1_ONLY_AGENT_OPTIONS = { allowH2: false };
4293
+ function useHttp1ForOutboundFetch(set = import_undici.setGlobalDispatcher) {
4294
+ const dispatcher = new import_undici.Agent(HTTP1_ONLY_AGENT_OPTIONS);
4295
+ set(dispatcher);
4296
+ return dispatcher;
4297
+ }
4298
+
4223
4299
  // src/http/guards/isPath.ts
4224
4300
  function isPath(path) {
4225
4301
  return path.startsWith("/");
@@ -7046,6 +7122,7 @@ function createLocalModelGatewayClient(options2 = {}) {
7046
7122
  EmailRequestError,
7047
7123
  ForklaunchExpressLikeApplication,
7048
7124
  ForklaunchExpressLikeRouter,
7125
+ HTTP1_ONLY_AGENT_OPTIONS,
7049
7126
  HTTPStatuses,
7050
7127
  INSTANCE_GATEWAY_MOUNT,
7051
7128
  InMemoryHmacNonceStore,
@@ -7066,6 +7143,7 @@ function createLocalModelGatewayClient(options2 = {}) {
7066
7143
  SmsClient,
7067
7144
  SmsRequestError,
7068
7145
  SmsValidationError,
7146
+ TRANSIENT_NETWORK_ERROR_CODES,
7069
7147
  VOICE_ATTRIBUTE_LIMITS,
7070
7148
  VoiceClient,
7071
7149
  VoiceRequestError,
@@ -7085,6 +7163,7 @@ function createLocalModelGatewayClient(options2 = {}) {
7085
7163
  createModelGatewayClient,
7086
7164
  createPaymentsClient,
7087
7165
  createPreviewModelGatewayClient,
7166
+ createProcessErrorHandlers,
7088
7167
  createRouteMcpAuthenticate,
7089
7168
  createSmsClient,
7090
7169
  createStripeClient,
@@ -7126,6 +7205,7 @@ function createLocalModelGatewayClient(options2 = {}) {
7126
7205
  isSeparateMcpListener,
7127
7206
  isServerError,
7128
7207
  isSuccessful,
7208
+ isTransientNetworkError,
7129
7209
  isValidStatusCode,
7130
7210
  jwtAlgorithmsForPublicKey,
7131
7211
  jwtAlgorithmsForSharedSecret,
@@ -7155,6 +7235,7 @@ function createLocalModelGatewayClient(options2 = {}) {
7155
7235
  ttlCacheHmacNonceStore,
7156
7236
  typedAuthHandler,
7157
7237
  typedHandler,
7238
+ useHttp1ForOutboundFetch,
7158
7239
  validateEmailSendRequest,
7159
7240
  validateListUnsubscribe,
7160
7241
  validateSmsSend,