@lucaapp/service-utils 1.62.2 → 1.62.3
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/dist/lib/api/api.js +5 -2
- package/dist/lib/api/endpoint.js +39 -41
- package/package.json +7 -6
package/dist/lib/api/api.js
CHANGED
|
@@ -72,14 +72,17 @@ class Api {
|
|
|
72
72
|
return spec;
|
|
73
73
|
}
|
|
74
74
|
mountSwaggerMiddlewares() {
|
|
75
|
+
// Serve the Swagger UI documentation at '/swagger'
|
|
75
76
|
this.router.use('/swagger', swagger_ui_express_1.default.serve);
|
|
77
|
+
// Setup the Swagger UI documentation at '/swagger'
|
|
76
78
|
this.router.get('/swagger', (request, response, next) => {
|
|
77
79
|
const spec = this.generateOpenAPISpec();
|
|
78
|
-
swagger_ui_express_1.default.setup(spec)(request, response, next);
|
|
80
|
+
return swagger_ui_express_1.default.setup(spec)(request, response, next);
|
|
79
81
|
});
|
|
82
|
+
// Serve the Swagger specification JSON at '/swagger.json'
|
|
80
83
|
this.router.get('/swagger.json', (request, response) => {
|
|
81
84
|
const spec = this.generateOpenAPISpec();
|
|
82
|
-
response.
|
|
85
|
+
response.json(spec); // Ensuring a proper JSON response
|
|
83
86
|
});
|
|
84
87
|
}
|
|
85
88
|
}
|
package/dist/lib/api/endpoint.js
CHANGED
|
@@ -321,52 +321,50 @@ new Promise(async (resolve) => {
|
|
|
321
321
|
});
|
|
322
322
|
const mountEndpoint = (router, method, path, options, handler, debug) => {
|
|
323
323
|
(0, assert_1.default)(options.responses.length > 0, 'You need to specify at least one response');
|
|
324
|
-
router[method](path, (request, response) => {
|
|
325
|
-
|
|
324
|
+
router[method](path, async (request, response) => {
|
|
325
|
+
try {
|
|
326
|
+
let handlerRequestBody;
|
|
327
|
+
let handlerRequestParams;
|
|
328
|
+
let handlerRequestQuery;
|
|
329
|
+
let handlerRequestHeaders;
|
|
326
330
|
try {
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
handlerRequestHeaders = ((await options.schemas?.headers?.parseAsync(request.headers)) || undefined);
|
|
337
|
-
}
|
|
338
|
-
catch (error) {
|
|
339
|
-
if (error instanceof zod_1.ZodError) {
|
|
340
|
-
return sendBadRequestZodError(response, error);
|
|
341
|
-
}
|
|
342
|
-
if (error instanceof libphonenumber_js_1.ParseError) {
|
|
343
|
-
const newError = new Error(error.message);
|
|
344
|
-
return sendBadRequestError(response, newError);
|
|
345
|
-
}
|
|
346
|
-
throw error;
|
|
331
|
+
// parse request schemas
|
|
332
|
+
handlerRequestBody = ((await options.schemas?.body?.parseAsync(request.body)) || undefined);
|
|
333
|
+
handlerRequestParams = ((await options.schemas?.params?.parseAsync(request.params)) || undefined);
|
|
334
|
+
handlerRequestQuery = ((await options.schemas?.query?.parseAsync(request.query)) || undefined);
|
|
335
|
+
handlerRequestHeaders = ((await options.schemas?.headers?.parseAsync(request.headers)) || undefined);
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
if (error instanceof zod_1.ZodError) {
|
|
339
|
+
return sendBadRequestZodError(response, error);
|
|
347
340
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
query: handlerRequestQuery,
|
|
352
|
-
headers: handlerRequestHeaders,
|
|
353
|
-
};
|
|
354
|
-
const ctx = {};
|
|
355
|
-
if (options.middlewares instanceof Array) {
|
|
356
|
-
for (const middleware of options.middlewares) {
|
|
357
|
-
const shouldContinue = await handleMiddleware(middleware, ctx, request, response, debug);
|
|
358
|
-
if (!shouldContinue)
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
341
|
+
if (error instanceof libphonenumber_js_1.ParseError) {
|
|
342
|
+
const newError = new Error(error.message);
|
|
343
|
+
return sendBadRequestError(response, newError);
|
|
361
344
|
}
|
|
362
|
-
|
|
363
|
-
await validateAndSendResponse(response, controllerResponse, options.responses, debug);
|
|
364
|
-
}, response);
|
|
345
|
+
throw error;
|
|
365
346
|
}
|
|
366
|
-
|
|
367
|
-
|
|
347
|
+
const handlerRequest = {
|
|
348
|
+
body: handlerRequestBody,
|
|
349
|
+
params: handlerRequestParams,
|
|
350
|
+
query: handlerRequestQuery,
|
|
351
|
+
headers: handlerRequestHeaders,
|
|
352
|
+
};
|
|
353
|
+
const ctx = {};
|
|
354
|
+
if (options.middlewares instanceof Array) {
|
|
355
|
+
for (const middleware of options.middlewares) {
|
|
356
|
+
const shouldContinue = await handleMiddleware(middleware, ctx, request, response, debug);
|
|
357
|
+
if (!shouldContinue)
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
368
360
|
}
|
|
369
|
-
|
|
361
|
+
await handler(handlerRequest, ctx, async (controllerResponse) => {
|
|
362
|
+
await validateAndSendResponse(response, controllerResponse, options.responses, debug);
|
|
363
|
+
}, response);
|
|
364
|
+
}
|
|
365
|
+
catch (error) {
|
|
366
|
+
sendErrorResponse(response, error, options.errors, debug);
|
|
367
|
+
}
|
|
370
368
|
});
|
|
371
369
|
};
|
|
372
370
|
exports.mountEndpoint = mountEndpoint;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucaapp/service-utils",
|
|
3
|
-
"version": "1.62.
|
|
3
|
+
"version": "1.62.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"@asteasolutions/zod-to-openapi": "6.1.0",
|
|
22
22
|
"@hapi/boom": "^10.0.0",
|
|
23
23
|
"@tsconfig/node18": "1.0.1",
|
|
24
|
-
"@types/express": "
|
|
25
|
-
"@types/express-serve-static-core": "
|
|
24
|
+
"@types/express": "4.17.15",
|
|
25
|
+
"@types/express-serve-static-core": "^4.17.43",
|
|
26
26
|
"@types/node": "18.18.2",
|
|
27
|
-
"@types/response-time": "^2.3.
|
|
27
|
+
"@types/response-time": "^2.3.8",
|
|
28
28
|
"@types/swagger-ui-express": "4.1.3",
|
|
29
29
|
"axios": "^1.7.4",
|
|
30
30
|
"busboy": "^1.6.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"negotiator": "^0.6.3",
|
|
40
40
|
"pino-http": "9.0.0",
|
|
41
41
|
"prom-client": "14.1.0",
|
|
42
|
-
"response-time": "
|
|
42
|
+
"response-time": "2.3.3",
|
|
43
43
|
"sequelize": "6.32.0",
|
|
44
44
|
"sqlite3": "5.1.1",
|
|
45
45
|
"swagger-ui-express": "5.0.1",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"send": "0.19.0",
|
|
79
79
|
"rollup": "4.22.4",
|
|
80
80
|
"cookie": ">= 0.7.0",
|
|
81
|
-
"string-width": "4.2.3"
|
|
81
|
+
"string-width": "4.2.3",
|
|
82
|
+
"@types/express": "4.17.15"
|
|
82
83
|
}
|
|
83
84
|
}
|