@forklaunch/express 0.3.5 → 0.3.7

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.
package/lib/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { AnySchemaValidator, LiteralSchema, IdiomaticSchema, SchemaResolve } from '@forklaunch/validator';
2
1
  import * as _forklaunch_core_http from '@forklaunch/core/http';
3
- import { ForklaunchExpressLikeApplication, OpenTelemetryCollector, MetricsDefinition, ForklaunchExpressLikeRouter, TypedMiddlewareDefinition, ParamsObject, ResponsesObject, Body, QueryObject, HeadersObject, ContractDetails, ExpressLikeSchemaHandler } from '@forklaunch/core/http';
2
+ import { ForklaunchExpressLikeApplication, OpenTelemetryCollector, MetricsDefinition, DocsConfiguration, ForklaunchExpressLikeRouter, TypedMiddlewareDefinition, ParamsObject, ResponsesObject, Body, QueryObject, HeadersObject, ContractDetails, ExpressLikeSchemaHandler } from '@forklaunch/core/http';
3
+ import { AnySchemaValidator, LiteralSchema, IdiomaticSchema, SchemaResolve } from '@forklaunch/validator';
4
4
  import { Express, RequestHandler, Request, Response, NextFunction, Router as Router$1 } from 'express';
5
5
  export { NextFunction, Request, Response } from 'express';
6
6
  import { Server } from 'http';
@@ -14,12 +14,13 @@ import * as express_serve_static_core from 'express-serve-static-core';
14
14
  * @template SV - A type that extends AnySchemaValidator.
15
15
  */
16
16
  declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Express, RequestHandler, Request, Response, NextFunction> {
17
+ private readonly docsConfiguration?;
17
18
  /**
18
19
  * Creates an instance of Application.
19
20
  *
20
21
  * @param {SV} schemaValidator - The schema validator.
21
22
  */
22
- constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
23
+ constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, docsConfiguration?: DocsConfiguration | undefined);
23
24
  /**
24
25
  * Starts the server and sets up Swagger documentation.
25
26
  *
@@ -240,7 +241,7 @@ declare const unsubscribe: <SV extends AnySchemaValidator, Path extends `/${stri
240
241
  * @param {SV} schemaValidator - The schema validator.
241
242
  * @returns {Application<SV>} - The new application instance.
242
243
  */
243
- declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>): Application<SV>;
244
+ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, docsConfiguration?: DocsConfiguration): Application<SV>;
244
245
  /**
245
246
  * Creates a new instance of Router with the given base path and schema validator.
246
247
  *
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { AnySchemaValidator, LiteralSchema, IdiomaticSchema, SchemaResolve } from '@forklaunch/validator';
2
1
  import * as _forklaunch_core_http from '@forklaunch/core/http';
3
- import { ForklaunchExpressLikeApplication, OpenTelemetryCollector, MetricsDefinition, ForklaunchExpressLikeRouter, TypedMiddlewareDefinition, ParamsObject, ResponsesObject, Body, QueryObject, HeadersObject, ContractDetails, ExpressLikeSchemaHandler } from '@forklaunch/core/http';
2
+ import { ForklaunchExpressLikeApplication, OpenTelemetryCollector, MetricsDefinition, DocsConfiguration, ForklaunchExpressLikeRouter, TypedMiddlewareDefinition, ParamsObject, ResponsesObject, Body, QueryObject, HeadersObject, ContractDetails, ExpressLikeSchemaHandler } from '@forklaunch/core/http';
3
+ import { AnySchemaValidator, LiteralSchema, IdiomaticSchema, SchemaResolve } from '@forklaunch/validator';
4
4
  import { Express, RequestHandler, Request, Response, NextFunction, Router as Router$1 } from 'express';
5
5
  export { NextFunction, Request, Response } from 'express';
6
6
  import { Server } from 'http';
@@ -14,12 +14,13 @@ import * as express_serve_static_core from 'express-serve-static-core';
14
14
  * @template SV - A type that extends AnySchemaValidator.
15
15
  */
16
16
  declare class Application<SV extends AnySchemaValidator> extends ForklaunchExpressLikeApplication<SV, Express, RequestHandler, Request, Response, NextFunction> {
17
+ private readonly docsConfiguration?;
17
18
  /**
18
19
  * Creates an instance of Application.
19
20
  *
20
21
  * @param {SV} schemaValidator - The schema validator.
21
22
  */
22
- constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
23
+ constructor(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, docsConfiguration?: DocsConfiguration | undefined);
23
24
  /**
24
25
  * Starts the server and sets up Swagger documentation.
25
26
  *
@@ -240,7 +241,7 @@ declare const unsubscribe: <SV extends AnySchemaValidator, Path extends `/${stri
240
241
  * @param {SV} schemaValidator - The schema validator.
241
242
  * @returns {Application<SV>} - The new application instance.
242
243
  */
243
- declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>): Application<SV>;
244
+ declare function forklaunchExpress<SV extends AnySchemaValidator>(schemaValidator: SV, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, docsConfiguration?: DocsConfiguration): Application<SV>;
244
245
  /**
245
246
  * Creates a new instance of Router with the given base path and schema validator.
246
247
  *
package/lib/index.js CHANGED
@@ -47,37 +47,42 @@ var Application = class extends import_http.ForklaunchExpressLikeApplication {
47
47
  *
48
48
  * @param {SV} schemaValidator - The schema validator.
49
49
  */
50
- constructor(schemaValidator, openTelemetryCollector) {
50
+ constructor(schemaValidator, openTelemetryCollector, docsConfiguration) {
51
51
  super(schemaValidator, (0, import_express.default)(), openTelemetryCollector);
52
+ this.docsConfiguration = docsConfiguration;
52
53
  }
53
54
  listen(...args) {
54
55
  const port = typeof args[0] === "number" ? args[0] : Number(process.env.PORT);
55
- this.internal.use(
56
- `/api/${process.env.VERSION ?? "v1"}/swagger`,
57
- import_swagger_ui_express.default.serve,
58
- import_swagger_ui_express.default.setup(
59
- (0, import_http.generateSwaggerDocument)(this.schemaValidator, port, this.routers)
60
- )
61
- );
62
- this.internal.use(
63
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
64
- (0, import_express_api_reference.apiReference)({
65
- spec: {
66
- content: (0, import_http.generateSwaggerDocument)(
67
- this.schemaValidator,
68
- port,
69
- this.routers
70
- )
71
- }
72
- })
73
- );
56
+ if (this.docsConfiguration == null || this.docsConfiguration.type === "scalar") {
57
+ this.internal.use(
58
+ `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
59
+ (0, import_express_api_reference.apiReference)({
60
+ spec: {
61
+ content: (0, import_http.generateSwaggerDocument)(
62
+ this.schemaValidator,
63
+ port,
64
+ this.routers
65
+ )
66
+ },
67
+ ...this.docsConfiguration
68
+ })
69
+ );
70
+ } else if (this.docsConfiguration.type === "swagger") {
71
+ this.internal.use(
72
+ `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
73
+ import_swagger_ui_express.default.serve,
74
+ import_swagger_ui_express.default.setup(
75
+ (0, import_http.generateSwaggerDocument)(this.schemaValidator, port, this.routers)
76
+ )
77
+ );
78
+ }
74
79
  const errorHandler = (err, req, res, _next) => {
75
80
  res.locals.errorMessage = err.message;
76
81
  res.type("text/plain");
77
82
  res.status(res.statusCode && res.statusCode >= 400 ? res.statusCode : 500).send(
78
83
  `Internal server error:
79
84
 
80
- ${(0, import_http.isForklaunchRequest)(req) ? req.context.correlationId : "No correlation ID"}`
85
+ Correlation id: ${(0, import_http.isForklaunchRequest)(req) ? req.context.correlationId : "No correlation ID"}`
81
86
  );
82
87
  (0, import_http.logger)("error").error(
83
88
  err.stack ?? err.message,
@@ -480,8 +485,12 @@ var unsubscribe = (schemaValidator, path, contractDetails, ...handlers2) => {
480
485
  };
481
486
 
482
487
  // index.ts
483
- function forklaunchExpress(schemaValidator, openTelemetryCollector) {
484
- return new Application(schemaValidator, openTelemetryCollector);
488
+ function forklaunchExpress(schemaValidator, openTelemetryCollector, docsConfiguration) {
489
+ return new Application(
490
+ schemaValidator,
491
+ openTelemetryCollector,
492
+ docsConfiguration
493
+ );
485
494
  }
486
495
  function forklaunchRouter(basePath, schemaValidator, openTelemetryCollector) {
487
496
  const router = new Router(basePath, schemaValidator, openTelemetryCollector);
package/lib/index.mjs CHANGED
@@ -16,37 +16,42 @@ var Application = class extends ForklaunchExpressLikeApplication {
16
16
  *
17
17
  * @param {SV} schemaValidator - The schema validator.
18
18
  */
19
- constructor(schemaValidator, openTelemetryCollector) {
19
+ constructor(schemaValidator, openTelemetryCollector, docsConfiguration) {
20
20
  super(schemaValidator, express(), openTelemetryCollector);
21
+ this.docsConfiguration = docsConfiguration;
21
22
  }
22
23
  listen(...args) {
23
24
  const port = typeof args[0] === "number" ? args[0] : Number(process.env.PORT);
24
- this.internal.use(
25
- `/api/${process.env.VERSION ?? "v1"}/swagger`,
26
- swaggerUi.serve,
27
- swaggerUi.setup(
28
- generateSwaggerDocument(this.schemaValidator, port, this.routers)
29
- )
30
- );
31
- this.internal.use(
32
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
33
- apiReference({
34
- spec: {
35
- content: generateSwaggerDocument(
36
- this.schemaValidator,
37
- port,
38
- this.routers
39
- )
40
- }
41
- })
42
- );
25
+ if (this.docsConfiguration == null || this.docsConfiguration.type === "scalar") {
26
+ this.internal.use(
27
+ `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
28
+ apiReference({
29
+ spec: {
30
+ content: generateSwaggerDocument(
31
+ this.schemaValidator,
32
+ port,
33
+ this.routers
34
+ )
35
+ },
36
+ ...this.docsConfiguration
37
+ })
38
+ );
39
+ } else if (this.docsConfiguration.type === "swagger") {
40
+ this.internal.use(
41
+ `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
42
+ swaggerUi.serve,
43
+ swaggerUi.setup(
44
+ generateSwaggerDocument(this.schemaValidator, port, this.routers)
45
+ )
46
+ );
47
+ }
43
48
  const errorHandler = (err, req, res, _next) => {
44
49
  res.locals.errorMessage = err.message;
45
50
  res.type("text/plain");
46
51
  res.status(res.statusCode && res.statusCode >= 400 ? res.statusCode : 500).send(
47
52
  `Internal server error:
48
53
 
49
- ${isForklaunchRequest(req) ? req.context.correlationId : "No correlation ID"}`
54
+ Correlation id: ${isForklaunchRequest(req) ? req.context.correlationId : "No correlation ID"}`
50
55
  );
51
56
  logger("error").error(
52
57
  err.stack ?? err.message,
@@ -507,8 +512,12 @@ var unsubscribe = (schemaValidator, path, contractDetails, ...handlers2) => {
507
512
  };
508
513
 
509
514
  // index.ts
510
- function forklaunchExpress(schemaValidator, openTelemetryCollector) {
511
- return new Application(schemaValidator, openTelemetryCollector);
515
+ function forklaunchExpress(schemaValidator, openTelemetryCollector, docsConfiguration) {
516
+ return new Application(
517
+ schemaValidator,
518
+ openTelemetryCollector,
519
+ docsConfiguration
520
+ );
512
521
  }
513
522
  function forklaunchRouter(basePath, schemaValidator, openTelemetryCollector) {
514
523
  const router = new Router(basePath, schemaValidator, openTelemetryCollector);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/express",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "Forklaunch framework for express.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -25,14 +25,14 @@
25
25
  "lib/**"
26
26
  ],
27
27
  "dependencies": {
28
- "@scalar/express-api-reference": "^0.4.192",
28
+ "@scalar/express-api-reference": "^0.4.193",
29
29
  "cors": "^2.8.5",
30
30
  "express": "^4.21.2",
31
31
  "qs": "^6.14.0",
32
32
  "swagger-ui-express": "^5.0.1",
33
- "@forklaunch/common": "0.2.3",
34
- "@forklaunch/core": "0.5.4",
35
- "@forklaunch/validator": "0.4.6"
33
+ "@forklaunch/common": "0.2.4",
34
+ "@forklaunch/validator": "0.4.7",
35
+ "@forklaunch/core": "0.5.6"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@eslint/js": "^9.22.0",
@@ -49,7 +49,7 @@
49
49
  "ts-node": "^10.9.2",
50
50
  "tsup": "^8.4.0",
51
51
  "typescript": "^5.8.2",
52
- "typescript-eslint": "^8.26.0"
52
+ "typescript-eslint": "^8.26.1"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsc --noEmit && tsup index.ts --format cjs,esm --no-splitting --tsconfig tsconfig.json --outDir lib --dts --clean",