@forklaunch/core 0.5.4 → 0.5.5

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,13 +1,14 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, IdiomaticSchema, Schema } from '@forklaunch/validator';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../openTelemetryCollector-CWrfzmmW.mjs';
3
+ export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../openTelemetryCollector-CWrfzmmW.mjs';
2
4
  import { Prettify, RemoveTrailingSlash, MakePropertyOptionalIfChildrenOptional } from '@forklaunch/common';
3
5
  import { Span } from '@opentelemetry/api';
4
6
  import { ParsedQs } from 'qs';
5
7
  import { Readable } from 'stream';
6
- import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../openTelemetryCollector-CWrfzmmW.mjs';
7
- export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../openTelemetryCollector-CWrfzmmW.mjs';
8
8
  import { OpenAPIObject } from 'openapi3-ts/oas31';
9
9
  import { AnyValueMap } from '@opentelemetry/api-logs';
10
10
  import { LevelWithSilentOrString, LevelWithSilent, Logger } from 'pino';
11
+ import { ApiReferenceConfiguration } from '@scalar/express-api-reference';
11
12
  export { ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
12
13
 
13
14
  interface PathBasedHandler<RouterHandler> {
@@ -959,4 +960,10 @@ declare function logger(level: LevelWithSilentOrString, meta?: AnyValueMap): Pin
959
960
 
960
961
  declare function recordMetric<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ResBodyMap extends Record<string, unknown>, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>>(req: ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>, res: ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>): void;
961
962
 
962
- export { ATTR_API_NAME, ATTR_CORRELATION_ID, type ApiClient, type AuthMethods, type AuthMethodsBase, type Body, type BodyObject, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type ErrorContainer, type ExpressLikeAuthMapper, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractedParamsObject, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HttpContractDetails, type HttpMethod, type LiveTypeFunction, type LiveTypeRouteDefinition, LogFn, LoggerMeta, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type Method, MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, type NumberOnlyObject, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, type QueryObject, type RequestContext, type ResolvedForklaunchRequest, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type SchemaAuthMethods, type StatusCode, type StringOnlyObject, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, delete_, enrichExpressLikeSend, generateSwaggerDocument, get, getCodeForStatus, head, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedHandler };
963
+ type DocsConfiguration = ({
964
+ type: 'scalar';
965
+ } & Partial<Omit<ApiReferenceConfiguration, 'spec'>>) | {
966
+ type: 'swagger';
967
+ };
968
+
969
+ export { ATTR_API_NAME, ATTR_CORRELATION_ID, type ApiClient, type AuthMethods, type AuthMethodsBase, type Body, type BodyObject, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type DocsConfiguration, type ErrorContainer, type ExpressLikeAuthMapper, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractedParamsObject, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HttpContractDetails, type HttpMethod, type LiveTypeFunction, type LiveTypeRouteDefinition, LogFn, LoggerMeta, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type Method, MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, type NumberOnlyObject, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, type QueryObject, type RequestContext, type ResolvedForklaunchRequest, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type SchemaAuthMethods, type StatusCode, type StringOnlyObject, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, delete_, enrichExpressLikeSend, generateSwaggerDocument, get, getCodeForStatus, head, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedHandler };
@@ -1,13 +1,14 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, IdiomaticSchema, Schema } from '@forklaunch/validator';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../openTelemetryCollector-CWrfzmmW.js';
3
+ export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../openTelemetryCollector-CWrfzmmW.js';
2
4
  import { Prettify, RemoveTrailingSlash, MakePropertyOptionalIfChildrenOptional } from '@forklaunch/common';
3
5
  import { Span } from '@opentelemetry/api';
4
6
  import { ParsedQs } from 'qs';
5
7
  import { Readable } from 'stream';
6
- import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../openTelemetryCollector-CWrfzmmW.js';
7
- export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../openTelemetryCollector-CWrfzmmW.js';
8
8
  import { OpenAPIObject } from 'openapi3-ts/oas31';
9
9
  import { AnyValueMap } from '@opentelemetry/api-logs';
10
10
  import { LevelWithSilentOrString, LevelWithSilent, Logger } from 'pino';
11
+ import { ApiReferenceConfiguration } from '@scalar/express-api-reference';
11
12
  export { ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
12
13
 
13
14
  interface PathBasedHandler<RouterHandler> {
@@ -959,4 +960,10 @@ declare function logger(level: LevelWithSilentOrString, meta?: AnyValueMap): Pin
959
960
 
960
961
  declare function recordMetric<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ResBodyMap extends Record<string, unknown>, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>>(req: ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>, res: ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>): void;
961
962
 
962
- export { ATTR_API_NAME, ATTR_CORRELATION_ID, type ApiClient, type AuthMethods, type AuthMethodsBase, type Body, type BodyObject, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type ErrorContainer, type ExpressLikeAuthMapper, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractedParamsObject, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HttpContractDetails, type HttpMethod, type LiveTypeFunction, type LiveTypeRouteDefinition, LogFn, LoggerMeta, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type Method, MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, type NumberOnlyObject, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, type QueryObject, type RequestContext, type ResolvedForklaunchRequest, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type SchemaAuthMethods, type StatusCode, type StringOnlyObject, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, delete_, enrichExpressLikeSend, generateSwaggerDocument, get, getCodeForStatus, head, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedHandler };
963
+ type DocsConfiguration = ({
964
+ type: 'scalar';
965
+ } & Partial<Omit<ApiReferenceConfiguration, 'spec'>>) | {
966
+ type: 'swagger';
967
+ };
968
+
969
+ export { ATTR_API_NAME, ATTR_CORRELATION_ID, type ApiClient, type AuthMethods, type AuthMethodsBase, type Body, type BodyObject, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type DocsConfiguration, type ErrorContainer, type ExpressLikeAuthMapper, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractedParamsObject, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HttpContractDetails, type HttpMethod, type LiveTypeFunction, type LiveTypeRouteDefinition, LogFn, LoggerMeta, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type Method, MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, type NumberOnlyObject, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, type QueryObject, type RequestContext, type ResolvedForklaunchRequest, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type SchemaAuthMethods, type StatusCode, type StringOnlyObject, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, delete_, enrichExpressLikeSend, generateSwaggerDocument, get, getCodeForStatus, head, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedHandler };
package/lib/http/index.js CHANGED
@@ -552,13 +552,18 @@ function enrichDetails(path, contractDetails, requestSchema, responseSchemas, op
552
552
  // src/http/middleware/request/parse.middleware.ts
553
553
  var import_validator = require("@forklaunch/validator");
554
554
 
555
+ // src/http/guards/hasSend.ts
556
+ function hasSend(res) {
557
+ return typeof res === "object" && res !== null && "send" in res;
558
+ }
559
+
555
560
  // src/http/guards/isResponseShape.ts
556
561
  function isResponseShape(maybeResponseShape) {
557
562
  return maybeResponseShape != null && "body" in maybeResponseShape && "query" in maybeResponseShape && "params" in maybeResponseShape && "headers" in maybeResponseShape;
558
563
  }
559
564
 
560
565
  // src/http/middleware/request/parse.middleware.ts
561
- function parse(req, _res, next) {
566
+ function parse(req, res, next) {
562
567
  const request = {
563
568
  params: req.params,
564
569
  query: req.query,
@@ -579,10 +584,18 @@ function parse(req, _res, next) {
579
584
  switch (req.contractDetails.options?.requestValidation) {
580
585
  default:
581
586
  case "error":
582
- next?.(
583
- new Error((0, import_validator.prettyPrintParseErrors)(parsedRequest.errors, "Request"))
584
- );
585
- break;
587
+ res.type("application/json");
588
+ res.status(400);
589
+ if (hasSend(res)) {
590
+ res.send(
591
+ `${(0, import_validator.prettyPrintParseErrors)(parsedRequest.errors, "Request")}
592
+
593
+ Correlation id: ${req.context.correlationId ?? "No correlation ID"}`
594
+ );
595
+ } else {
596
+ next?.(new Error("Request is not sendable."));
597
+ }
598
+ return;
586
599
  case "warning":
587
600
  req.openTelemetryCollector.warn(
588
601
  (0, import_validator.prettyPrintParseErrors)(parsedRequest.errors, "Request")
@@ -2283,9 +2296,19 @@ function parse2(req, res, next) {
2283
2296
  switch (req.contractDetails.options?.responseValidation) {
2284
2297
  default:
2285
2298
  case "error":
2286
- next?.(new Error(`Invalid response:
2287
- ${parseErrors.join("\n\n")}`));
2288
- break;
2299
+ res.type("text/plain");
2300
+ res.status(400);
2301
+ if (hasSend(res)) {
2302
+ res.send(
2303
+ `Invalid response:
2304
+ ${parseErrors.join("\n\n")}
2305
+
2306
+ Correlation id: ${req.context.correlationId ?? "No correlation ID"}`
2307
+ );
2308
+ } else {
2309
+ next?.(new Error("Response is not sendable."));
2310
+ }
2311
+ return;
2289
2312
  case "warning":
2290
2313
  req.openTelemetryCollector.warn(
2291
2314
  `Invalid response: