@lucaapp/service-utils 1.56.7 → 1.56.8
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/endpoint.js +8 -18
- package/dist/lib/api/response.d.ts +0 -6
- package/dist/lib/api/response.js +1 -8
- package/dist/lib/api/send.d.ts +0 -8
- package/dist/lib/api/send.js +1 -10
- package/dist/lib/api/types/endpoint.d.ts +1 -5
- package/dist/lib/api/types/middleware.d.ts +0 -1
- package/dist/lib/kafka/events/location.d.ts +0 -2
- package/dist/types/pino.d.ts +2 -0
- package/dist/types/pino.ded.d.ts +2 -0
- package/dist/types/pino.ded.js +2 -0
- package/dist/types/pino.js +2 -0
- package/package.json +5 -5
package/dist/lib/api/endpoint.js
CHANGED
|
@@ -9,9 +9,6 @@ const assert_1 = __importDefault(require("assert"));
|
|
|
9
9
|
const http_1 = require("./types/http");
|
|
10
10
|
const libphonenumber_js_1 = require("libphonenumber-js");
|
|
11
11
|
const busboy_1 = __importDefault(require("busboy"));
|
|
12
|
-
const isRawResponse = (response) => {
|
|
13
|
-
return response.isRawResponseEnd === true;
|
|
14
|
-
};
|
|
15
12
|
const sendBadContextError = (response, error, debug) => {
|
|
16
13
|
response.err = error;
|
|
17
14
|
return response.status(500).send({
|
|
@@ -123,12 +120,9 @@ const isTypedError = (error) => {
|
|
|
123
120
|
};
|
|
124
121
|
const validateAndSendResponse = async (expressResponse, response, validResponses, debug) => {
|
|
125
122
|
try {
|
|
126
|
-
if (isRawResponse(response)) {
|
|
127
|
-
expressResponse.end();
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
123
|
(0, assert_1.default)(typeof response.status === 'number');
|
|
131
|
-
|
|
124
|
+
// get schema respective to status code
|
|
125
|
+
const responseSchema = validResponses.find(responseSchema => responseSchema.status === response.status);
|
|
132
126
|
const schema = responseSchema?.schema;
|
|
133
127
|
(0, assert_1.default)(schema);
|
|
134
128
|
if (response.headers) {
|
|
@@ -136,16 +130,10 @@ const validateAndSendResponse = async (expressResponse, response, validResponses
|
|
|
136
130
|
expressResponse.set(header, value);
|
|
137
131
|
});
|
|
138
132
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.catch(error => {
|
|
142
|
-
if (debug || process.env.NODE_ENV !== 'production') {
|
|
143
|
-
throw error;
|
|
144
|
-
}
|
|
145
|
-
console.error('Response schema validation failed:', error);
|
|
146
|
-
return response.body; // Return original body in production
|
|
147
|
-
});
|
|
133
|
+
// validate response schema
|
|
134
|
+
const validatedResponseBody = await schema.parseAsync(response.body);
|
|
148
135
|
if (validatedResponseBody === undefined) {
|
|
136
|
+
// No Content Response
|
|
149
137
|
expressResponse.status(response.status).end();
|
|
150
138
|
return;
|
|
151
139
|
}
|
|
@@ -169,6 +157,7 @@ async function stream2buffer(stream) {
|
|
|
169
157
|
}
|
|
170
158
|
function handleFileUpload(request) {
|
|
171
159
|
return new Promise((resolve, reject) => {
|
|
160
|
+
console.log('Handling file upload');
|
|
172
161
|
const bb = (0, busboy_1.default)({
|
|
173
162
|
headers: request.headers,
|
|
174
163
|
defCharset: 'utf8',
|
|
@@ -179,6 +168,7 @@ function handleFileUpload(request) {
|
|
|
179
168
|
});
|
|
180
169
|
let file = undefined;
|
|
181
170
|
bb.once('error', error => {
|
|
171
|
+
console.log('err');
|
|
182
172
|
reject(error);
|
|
183
173
|
});
|
|
184
174
|
bb.on('file', async (fieldname, fileStream, filename) => {
|
|
@@ -312,7 +302,7 @@ const mountEndpoint = (router, method, path, options, handler, debug) => {
|
|
|
312
302
|
}
|
|
313
303
|
await handler(handlerRequest, ctx, async (controllerResponse) => {
|
|
314
304
|
await validateAndSendResponse(response, controllerResponse, options.responses, debug);
|
|
315
|
-
}
|
|
305
|
+
});
|
|
316
306
|
}
|
|
317
307
|
catch (error) {
|
|
318
308
|
sendErrorResponse(response, error, options.errors, debug);
|
|
@@ -15,10 +15,4 @@ export declare const noContentResponse: () => {
|
|
|
15
15
|
description: string;
|
|
16
16
|
schema: typeof noContentSchema;
|
|
17
17
|
};
|
|
18
|
-
export declare const rawResponseEnd: () => {
|
|
19
|
-
status: number;
|
|
20
|
-
isRawResponseEnd: true;
|
|
21
|
-
description: string;
|
|
22
|
-
schema: typeof noContentSchema;
|
|
23
|
-
};
|
|
24
18
|
export {};
|
package/dist/lib/api/response.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.noContentResponse = exports.createdResponse = exports.okResponse = void 0;
|
|
4
4
|
const zod_to_openapi_1 = require("@asteasolutions/zod-to-openapi");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
(0, zod_to_openapi_1.extendZodWithOpenApi)(zod_1.z);
|
|
@@ -25,10 +25,3 @@ const noContentResponse = () => ({
|
|
|
25
25
|
schema: noContentSchema,
|
|
26
26
|
});
|
|
27
27
|
exports.noContentResponse = noContentResponse;
|
|
28
|
-
const rawResponseEnd = () => ({
|
|
29
|
-
status: 0,
|
|
30
|
-
isRawResponseEnd: true,
|
|
31
|
-
description: 'rawEnd',
|
|
32
|
-
schema: noContentSchema,
|
|
33
|
-
});
|
|
34
|
-
exports.rawResponseEnd = rawResponseEnd;
|
package/dist/lib/api/send.d.ts
CHANGED
|
@@ -13,11 +13,3 @@ export declare const noContent: <T>(headers?: T | undefined) => {
|
|
|
13
13
|
body: void;
|
|
14
14
|
headers?: T | undefined;
|
|
15
15
|
};
|
|
16
|
-
/**
|
|
17
|
-
* Specifies that the response is a raw response.
|
|
18
|
-
*
|
|
19
|
-
* `response.end()` is called in the handler function.
|
|
20
|
-
*/
|
|
21
|
-
export declare const rawEnd: () => {
|
|
22
|
-
isRawResponseEnd: true;
|
|
23
|
-
};
|
package/dist/lib/api/send.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.noContent = exports.created = exports.ok = void 0;
|
|
4
4
|
const ok = (body, headers) => ({
|
|
5
5
|
status: 200,
|
|
6
6
|
body: body,
|
|
@@ -19,12 +19,3 @@ const noContent = (headers) => ({
|
|
|
19
19
|
headers: headers,
|
|
20
20
|
});
|
|
21
21
|
exports.noContent = noContent;
|
|
22
|
-
/**
|
|
23
|
-
* Specifies that the response is a raw response.
|
|
24
|
-
*
|
|
25
|
-
* `response.end()` is called in the handler function.
|
|
26
|
-
*/
|
|
27
|
-
const rawEnd = () => ({
|
|
28
|
-
isRawResponseEnd: true,
|
|
29
|
-
});
|
|
30
|
-
exports.rawEnd = rawEnd;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import { Response } from 'express';
|
|
2
1
|
import { Middleware, EndpointResponseSchema } from './middleware';
|
|
3
2
|
import { ArrayToUnion, ExtractZodOutput, ExtractZodOutputFromMiddleware, Always, Merge, ZodSchemaOuput } from './utils';
|
|
4
|
-
export type RawResponseEnd = {
|
|
5
|
-
isRawResponseEnd: boolean;
|
|
6
|
-
};
|
|
7
3
|
export type EndpointHandler<TResponse, TRequestBodySchema, TRequestParamsSchema, TRequestQuerySchema, TRequestHeadersSchema, TMiddlewares> = (request: {
|
|
8
4
|
body: ZodSchemaOuput<TRequestBodySchema>;
|
|
9
5
|
params: ZodSchemaOuput<TRequestParamsSchema>;
|
|
10
6
|
query: ZodSchemaOuput<TRequestQuerySchema>;
|
|
11
7
|
headers: ZodSchemaOuput<TRequestHeadersSchema>;
|
|
12
|
-
}, context: Merge<Always<ExtractZodOutputFromMiddleware<ArrayToUnion<TMiddlewares>>>>, send: (response: ExtractZodOutput<ArrayToUnion<TResponse>>
|
|
8
|
+
}, context: Merge<Always<ExtractZodOutputFromMiddleware<ArrayToUnion<TMiddlewares>>>>, send: (response: ExtractZodOutput<ArrayToUnion<TResponse>>) => void) => Promise<void>;
|
|
13
9
|
export type EndpointOptions<TResponseSchemas extends ReadonlyArray<EndpointResponseSchema>, TRequestBodySchema, TRequestParamsSchema, TRequestQuerySchema, TRequestHeadersSchema, TMiddlewares extends ReadonlyArray<Middleware<any, any, any, any, any, any>> | undefined> = {
|
|
14
10
|
schemas?: {
|
|
15
11
|
body?: TRequestBodySchema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucaapp/service-utils",
|
|
3
|
-
"version": "1.56.
|
|
3
|
+
"version": "1.56.08",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@types/node": "18.18.2",
|
|
27
27
|
"@types/response-time": "^2.3.5",
|
|
28
28
|
"@types/swagger-ui-express": "4.1.3",
|
|
29
|
-
"axios": "^1.
|
|
29
|
+
"axios": "^1.7.4",
|
|
30
30
|
"busboy": "^1.6.0",
|
|
31
31
|
"cls-rtracer": "^2.6.2",
|
|
32
32
|
"express": "4.19.2",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@types/pino-http": "5.8.4",
|
|
56
56
|
"@types/supertest": "2.0.11",
|
|
57
57
|
"@types/uuid": "^8.3.4",
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
59
|
-
"@typescript-eslint/parser": "^7.
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^7.15.0",
|
|
59
|
+
"@typescript-eslint/parser": "^7.15.0",
|
|
60
60
|
"@vitest/coverage-v8": "1.4.0",
|
|
61
61
|
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
62
62
|
"eslint": "8.57.0",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"semantic-release": "^19.0.3",
|
|
68
68
|
"semantic-release-monorepo": "^7.0.5",
|
|
69
69
|
"supertest": "^6.3.3",
|
|
70
|
-
"typescript": "5.
|
|
70
|
+
"typescript": "5.5.3",
|
|
71
71
|
"vite-tsconfig-paths": "4.3.2"
|
|
72
72
|
},
|
|
73
73
|
"resolutions": {
|