@lucaapp/service-utils 1.56.0 → 1.56.1
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
CHANGED
|
@@ -117,15 +117,15 @@ const isTypedError = (error) => {
|
|
|
117
117
|
return false;
|
|
118
118
|
return true;
|
|
119
119
|
};
|
|
120
|
-
const validateAndSendResponse = async (expressResponse, response, validResponses, debug
|
|
120
|
+
const validateAndSendResponse = async (expressResponse, response, validResponses, debug) => {
|
|
121
121
|
try {
|
|
122
122
|
(0, assert_1.default)(typeof response.status === 'number');
|
|
123
123
|
// get schema respective to status code
|
|
124
124
|
const responseSchema = validResponses.find(responseSchema => responseSchema.status === response.status);
|
|
125
125
|
const schema = responseSchema?.schema;
|
|
126
126
|
(0, assert_1.default)(schema);
|
|
127
|
-
if (
|
|
128
|
-
Object.entries(
|
|
127
|
+
if (response.headers) {
|
|
128
|
+
Object.entries(response.headers).forEach(([header, value]) => {
|
|
129
129
|
expressResponse.set(header, value);
|
|
130
130
|
});
|
|
131
131
|
}
|
|
@@ -249,7 +249,7 @@ const mountEndpoint = (router, method, path, options, handler, debug) => {
|
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
await handler(handlerRequest, ctx, async (controllerResponse) => {
|
|
252
|
-
await validateAndSendResponse(response, controllerResponse, options.responses, debug
|
|
252
|
+
await validateAndSendResponse(response, controllerResponse, options.responses, debug);
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
255
|
catch (error) {
|
package/dist/lib/api/send.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
export declare const ok: <T>(body?: T | undefined) => {
|
|
1
|
+
export declare const ok: <T, U>(body?: T | undefined, headers?: U | undefined) => {
|
|
2
2
|
status: 200;
|
|
3
3
|
body: T;
|
|
4
|
+
headers: U;
|
|
4
5
|
};
|
|
5
|
-
export declare const created: <T>(body?: T | undefined) => {
|
|
6
|
+
export declare const created: <T, U>(body?: T | undefined, headers?: U | undefined) => {
|
|
6
7
|
status: 201;
|
|
7
8
|
body: T;
|
|
9
|
+
headers: U;
|
|
8
10
|
};
|
|
9
|
-
export declare const noContent: () => {
|
|
11
|
+
export declare const noContent: <T>(headers?: T | undefined) => {
|
|
10
12
|
status: 204;
|
|
11
13
|
body: void;
|
|
14
|
+
headers?: T | undefined;
|
|
12
15
|
};
|
package/dist/lib/api/send.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.noContent = exports.created = exports.ok = void 0;
|
|
4
|
-
const ok = (body) => ({
|
|
4
|
+
const ok = (body, headers) => ({
|
|
5
5
|
status: 200,
|
|
6
6
|
body: body,
|
|
7
|
+
headers: headers,
|
|
7
8
|
});
|
|
8
9
|
exports.ok = ok;
|
|
9
|
-
const created = (body) => ({
|
|
10
|
+
const created = (body, headers) => ({
|
|
10
11
|
status: 201,
|
|
11
12
|
body: body,
|
|
13
|
+
headers: headers,
|
|
12
14
|
});
|
|
13
15
|
exports.created = created;
|
|
14
|
-
const noContent = () => ({
|
|
16
|
+
const noContent = (headers) => ({
|
|
15
17
|
status: 204,
|
|
16
18
|
body: undefined,
|
|
19
|
+
headers: headers,
|
|
17
20
|
});
|
|
18
21
|
exports.noContent = noContent;
|
|
@@ -4,6 +4,7 @@ export type EndpointResponseSchema = {
|
|
|
4
4
|
status: number;
|
|
5
5
|
description: string;
|
|
6
6
|
schema: z.ZodSchema<any> | z.ZodVoid;
|
|
7
|
+
headers?: Record<string, string>;
|
|
7
8
|
};
|
|
8
9
|
export type MiddlewareHandler<TResponseSchema, TRequestBodySchema, TRequestParamsSchema, TRequestQuerySchema, TRequestHeadersSchema, TContextSchema> = (request: {
|
|
9
10
|
body: ZodSchemaOuput<TRequestBodySchema>;
|