@forklaunch/express 0.7.5 → 0.7.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.js CHANGED
@@ -61,9 +61,15 @@ function contentParse(options2) {
61
61
  return async (req, res, next) => {
62
62
  try {
63
63
  const coercedRequest = req;
64
+ let contractBody;
65
+ if (coercedRequest.contractDetails.versions) {
66
+ contractBody = Object.values(coercedRequest.contractDetails.versions)[0]?.body;
67
+ } else {
68
+ contractBody = coercedRequest.contractDetails.body;
69
+ }
64
70
  const discriminatedBody = (0, import_http.discriminateBody)(
65
71
  coercedRequest.schemaValidator,
66
- coercedRequest.contractDetails.body
72
+ contractBody
67
73
  );
68
74
  if (!discriminatedBody) {
69
75
  return next();
@@ -116,6 +122,9 @@ function contentParse(options2) {
116
122
  }
117
123
  default:
118
124
  (0, import_common.isNever)(discriminatedBody.parserType);
125
+ throw new Error(
126
+ "Unsupported parser type for body: " + discriminatedBody.parserType
127
+ );
119
128
  }
120
129
  } catch (error) {
121
130
  next(error);
@@ -186,7 +195,7 @@ var Application = class extends import_http3.ForklaunchExpressLikeApplication {
186
195
  const port = typeof args[0] === "number" ? args[0] : Number(process.env.PORT);
187
196
  const host = typeof args[1] === "string" ? args[1] : process.env.HOST ?? "localhost";
188
197
  const protocol = process.env.PROTOCOL ?? "http";
189
- const openApi = (0, import_http3.generateSwaggerDocument)(
198
+ const openApi = (0, import_http3.generateOpenApiSpecs)(
190
199
  this.schemaValidator,
191
200
  protocol,
192
201
  host,
@@ -214,30 +223,42 @@ var Application = class extends import_http3.ForklaunchExpressLikeApplication {
214
223
  }
215
224
  if (this.docsConfiguration == null || this.docsConfiguration.type === "scalar") {
216
225
  this.internal.use(
217
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
226
+ `/api${process.env.VERSION ? `/${process.env.VERSION}` : ""}${process.env.DOCS_PATH ?? "/docs"}`,
218
227
  (0, import_express_api_reference.apiReference)({
219
228
  ...this.docsConfiguration,
220
229
  sources: [
221
230
  {
222
- content: openApi,
231
+ content: openApi[import_http3.OPENAPI_DEFAULT_VERSION],
223
232
  title: "API Reference"
224
233
  },
234
+ ...Object.entries(openApi).map(([version, spec]) => ({
235
+ content: spec,
236
+ title: `API Reference - ${version}`
237
+ })),
225
238
  ...this.docsConfiguration?.sources ?? []
226
239
  ]
227
240
  })
228
241
  );
229
242
  } else if (this.docsConfiguration.type === "swagger") {
230
243
  this.internal.use(
231
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
232
- import_swagger_ui_express.default.serve,
244
+ `/api${process.env.VERSION ? `/${process.env.VERSION}` : ""}${process.env.DOCS_PATH ?? "/docs"}`,
245
+ import_swagger_ui_express.default.serveFiles(openApi),
233
246
  import_swagger_ui_express.default.setup(openApi)
234
247
  );
235
248
  }
236
249
  this.internal.get(
237
- `/api/${process.env.VERSION ?? "v1"}/openapi`,
250
+ `/api${process.env.VERSION ? `/${process.env.VERSION}` : ""}/openapi`,
238
251
  (_, res) => {
239
252
  res.type("application/json");
240
- res.json(openApi);
253
+ res.json({
254
+ latest: openApi[import_http3.OPENAPI_DEFAULT_VERSION],
255
+ ...Object.fromEntries(
256
+ Object.entries(openApi).map(([version, spec]) => [
257
+ `v${version}`,
258
+ spec
259
+ ])
260
+ )
261
+ });
241
262
  }
242
263
  );
243
264
  this.internal.get(
package/lib/index.mjs CHANGED
@@ -4,9 +4,10 @@ import {
4
4
  ATTR_HTTP_RESPONSE_STATUS_CODE,
5
5
  ForklaunchExpressLikeApplication,
6
6
  generateMcpServer,
7
- generateSwaggerDocument,
7
+ generateOpenApiSpecs,
8
8
  isForklaunchRequest,
9
- meta
9
+ meta,
10
+ OPENAPI_DEFAULT_VERSION
10
11
  } from "@forklaunch/core/http";
11
12
  import { ZodSchemaValidator } from "@forklaunch/validator/zod";
12
13
  import { apiReference } from "@scalar/express-api-reference";
@@ -30,9 +31,15 @@ function contentParse(options2) {
30
31
  return async (req, res, next) => {
31
32
  try {
32
33
  const coercedRequest = req;
34
+ let contractBody;
35
+ if (coercedRequest.contractDetails.versions) {
36
+ contractBody = Object.values(coercedRequest.contractDetails.versions)[0]?.body;
37
+ } else {
38
+ contractBody = coercedRequest.contractDetails.body;
39
+ }
33
40
  const discriminatedBody = discriminateBody(
34
41
  coercedRequest.schemaValidator,
35
- coercedRequest.contractDetails.body
42
+ contractBody
36
43
  );
37
44
  if (!discriminatedBody) {
38
45
  return next();
@@ -85,6 +92,9 @@ function contentParse(options2) {
85
92
  }
86
93
  default:
87
94
  isNever(discriminatedBody.parserType);
95
+ throw new Error(
96
+ "Unsupported parser type for body: " + discriminatedBody.parserType
97
+ );
88
98
  }
89
99
  } catch (error) {
90
100
  next(error);
@@ -157,7 +167,7 @@ var Application = class extends ForklaunchExpressLikeApplication {
157
167
  const port = typeof args[0] === "number" ? args[0] : Number(process.env.PORT);
158
168
  const host = typeof args[1] === "string" ? args[1] : process.env.HOST ?? "localhost";
159
169
  const protocol = process.env.PROTOCOL ?? "http";
160
- const openApi = generateSwaggerDocument(
170
+ const openApi = generateOpenApiSpecs(
161
171
  this.schemaValidator,
162
172
  protocol,
163
173
  host,
@@ -185,30 +195,42 @@ var Application = class extends ForklaunchExpressLikeApplication {
185
195
  }
186
196
  if (this.docsConfiguration == null || this.docsConfiguration.type === "scalar") {
187
197
  this.internal.use(
188
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
198
+ `/api${process.env.VERSION ? `/${process.env.VERSION}` : ""}${process.env.DOCS_PATH ?? "/docs"}`,
189
199
  apiReference({
190
200
  ...this.docsConfiguration,
191
201
  sources: [
192
202
  {
193
- content: openApi,
203
+ content: openApi[OPENAPI_DEFAULT_VERSION],
194
204
  title: "API Reference"
195
205
  },
206
+ ...Object.entries(openApi).map(([version, spec]) => ({
207
+ content: spec,
208
+ title: `API Reference - ${version}`
209
+ })),
196
210
  ...this.docsConfiguration?.sources ?? []
197
211
  ]
198
212
  })
199
213
  );
200
214
  } else if (this.docsConfiguration.type === "swagger") {
201
215
  this.internal.use(
202
- `/api/${process.env.VERSION ?? "v1"}${process.env.DOCS_PATH ?? "/docs"}`,
203
- swaggerUi.serve,
216
+ `/api${process.env.VERSION ? `/${process.env.VERSION}` : ""}${process.env.DOCS_PATH ?? "/docs"}`,
217
+ swaggerUi.serveFiles(openApi),
204
218
  swaggerUi.setup(openApi)
205
219
  );
206
220
  }
207
221
  this.internal.get(
208
- `/api/${process.env.VERSION ?? "v1"}/openapi`,
222
+ `/api${process.env.VERSION ? `/${process.env.VERSION}` : ""}/openapi`,
209
223
  (_, res) => {
210
224
  res.type("application/json");
211
- res.json(openApi);
225
+ res.json({
226
+ latest: openApi[OPENAPI_DEFAULT_VERSION],
227
+ ...Object.fromEntries(
228
+ Object.entries(openApi).map(([version, spec]) => [
229
+ `v${version}`,
230
+ spec
231
+ ])
232
+ )
233
+ });
212
234
  }
213
235
  );
214
236
  this.internal.get(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/express",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "description": "Forklaunch framework for express.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -25,23 +25,23 @@
25
25
  "lib/**"
26
26
  ],
27
27
  "dependencies": {
28
- "@modelcontextprotocol/sdk": "^1.15.1",
29
- "@scalar/express-api-reference": "^0.8.10",
28
+ "@modelcontextprotocol/sdk": "^1.17.1",
29
+ "@scalar/express-api-reference": "^0.8.13",
30
30
  "@types/multer": "^2.0.0",
31
31
  "body-parser": "^2.2.0",
32
32
  "busboy": "^1.6.0",
33
33
  "cors": "^2.8.5",
34
34
  "express": "^5.1.0",
35
- "fastmcp": "^3.8.5",
36
- "multer": "2.0.1",
35
+ "fastmcp": "^3.13.0",
36
+ "multer": "2.0.2",
37
37
  "qs": "^6.14.0",
38
38
  "swagger-ui-express": "^5.0.1",
39
- "@forklaunch/common": "0.4.5",
40
- "@forklaunch/validator": "0.7.7",
41
- "@forklaunch/core": "0.11.5"
39
+ "@forklaunch/common": "0.4.6",
40
+ "@forklaunch/core": "0.11.7",
41
+ "@forklaunch/validator": "0.7.8"
42
42
  },
43
43
  "devDependencies": {
44
- "@eslint/js": "^9.31.0",
44
+ "@eslint/js": "^9.32.0",
45
45
  "@types/body-parser": "^1.19.6",
46
46
  "@types/busboy": "^1.5.4",
47
47
  "@types/cors": "^2.8.19",
@@ -51,16 +51,16 @@
51
51
  "@types/qs": "^6.14.0",
52
52
  "@types/range-parser": "^1.2.7",
53
53
  "@types/swagger-ui-express": "^4.1.8",
54
- "@typescript/native-preview": "7.0.0-dev.20250712.1",
55
- "jest": "^30.0.4",
54
+ "@typescript/native-preview": "7.0.0-dev.20250802.1",
55
+ "jest": "^30.0.5",
56
56
  "kill-port-process": "^3.2.1",
57
57
  "prettier": "^3.6.2",
58
58
  "ts-jest": "^29.4.0",
59
59
  "ts-node": "^10.9.2",
60
60
  "tsup": "^8.5.0",
61
- "typedoc": "^0.28.7",
62
- "typescript": "^5.8.3",
63
- "typescript-eslint": "^8.36.0"
61
+ "typedoc": "^0.28.9",
62
+ "typescript": "^5.9.2",
63
+ "typescript-eslint": "^8.38.0"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "tsgo --noEmit && tsup index.ts --format cjs,esm --no-splitting --tsconfig tsconfig.json --outDir lib --dts --clean",