@lucaapp/service-utils 1.32.0 → 1.32.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.
|
@@ -41,6 +41,16 @@ declare const notFoundErrorSchema: z.ZodObject<{
|
|
|
41
41
|
message: string;
|
|
42
42
|
error: HTTPStatus.NOT_FOUND;
|
|
43
43
|
}>;
|
|
44
|
+
declare const tooManyRequestsErrorSchema: z.ZodObject<{
|
|
45
|
+
error: z.ZodLiteral<HTTPStatus.TOO_MANY_REQUESTS>;
|
|
46
|
+
message: z.ZodString;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
message: string;
|
|
49
|
+
error: HTTPStatus.TOO_MANY_REQUESTS;
|
|
50
|
+
}, {
|
|
51
|
+
message: string;
|
|
52
|
+
error: HTTPStatus.TOO_MANY_REQUESTS;
|
|
53
|
+
}>;
|
|
44
54
|
export declare const okResponse: <T>(schema: z.ZodType<T, z.ZodTypeDef, T>) => {
|
|
45
55
|
status: 200;
|
|
46
56
|
description: string;
|
|
@@ -71,4 +81,9 @@ export declare const notFoundResponse: () => {
|
|
|
71
81
|
description: string;
|
|
72
82
|
schema: typeof notFoundErrorSchema;
|
|
73
83
|
};
|
|
84
|
+
export declare const tooManyRequestsResponse: () => {
|
|
85
|
+
status: 429;
|
|
86
|
+
description: string;
|
|
87
|
+
schema: typeof tooManyRequestsErrorSchema;
|
|
88
|
+
};
|
|
74
89
|
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.notFoundResponse = exports.forbiddenResponse = exports.unauthorizedResponse = exports.badRequestResponse = exports.noContentResponse = exports.okResponse = void 0;
|
|
3
|
+
exports.tooManyRequestsResponse = exports.notFoundResponse = exports.forbiddenResponse = exports.unauthorizedResponse = exports.badRequestResponse = exports.noContentResponse = 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
|
const http_1 = require("./types/http");
|
|
@@ -23,6 +23,10 @@ const notFoundErrorSchema = zod_1.z.object({
|
|
|
23
23
|
error: zod_1.z.literal(http_1.HTTPStatus.NOT_FOUND),
|
|
24
24
|
message: zod_1.z.string(),
|
|
25
25
|
});
|
|
26
|
+
const tooManyRequestsErrorSchema = zod_1.z.object({
|
|
27
|
+
error: zod_1.z.literal(http_1.HTTPStatus.TOO_MANY_REQUESTS),
|
|
28
|
+
message: zod_1.z.string(),
|
|
29
|
+
});
|
|
26
30
|
// response functions
|
|
27
31
|
const okResponse = (schema) => ({
|
|
28
32
|
status: 200,
|
|
@@ -60,3 +64,9 @@ const notFoundResponse = () => ({
|
|
|
60
64
|
schema: notFoundErrorSchema,
|
|
61
65
|
});
|
|
62
66
|
exports.notFoundResponse = notFoundResponse;
|
|
67
|
+
const tooManyRequestsResponse = () => ({
|
|
68
|
+
status: 429,
|
|
69
|
+
description: 'Too Many Requests',
|
|
70
|
+
schema: tooManyRequestsErrorSchema,
|
|
71
|
+
});
|
|
72
|
+
exports.tooManyRequestsResponse = tooManyRequestsResponse;
|
|
@@ -2,4 +2,7 @@ import { Request } from 'express';
|
|
|
2
2
|
export type InternalLanguages = 'de' | 'en';
|
|
3
3
|
export declare const DEFAULT_LANGUAGE = "de";
|
|
4
4
|
export declare const AVAILABLE_LANGUAGES: string[];
|
|
5
|
+
type LanguageOptions = typeof AVAILABLE_LANGUAGES[number];
|
|
6
|
+
export declare const parseAcceptLanguageHeader: (header?: string) => LanguageOptions;
|
|
5
7
|
export declare const getPreferredLanguageFromRequest: (request: Request) => string;
|
|
8
|
+
export {};
|
|
@@ -3,10 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPreferredLanguageFromRequest = exports.AVAILABLE_LANGUAGES = exports.DEFAULT_LANGUAGE = void 0;
|
|
6
|
+
exports.getPreferredLanguageFromRequest = exports.parseAcceptLanguageHeader = exports.AVAILABLE_LANGUAGES = exports.DEFAULT_LANGUAGE = void 0;
|
|
7
7
|
const negotiator_1 = __importDefault(require("negotiator"));
|
|
8
8
|
exports.DEFAULT_LANGUAGE = 'de';
|
|
9
9
|
exports.AVAILABLE_LANGUAGES = ['en', 'de'];
|
|
10
|
+
const parseAcceptLanguageHeader = (header) => {
|
|
11
|
+
if (!header) {
|
|
12
|
+
return exports.DEFAULT_LANGUAGE;
|
|
13
|
+
}
|
|
14
|
+
const negotiator = new negotiator_1.default({
|
|
15
|
+
headers: {
|
|
16
|
+
'accept-language': header,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
return (negotiator.language(exports.AVAILABLE_LANGUAGES) ?? 'en');
|
|
20
|
+
};
|
|
21
|
+
exports.parseAcceptLanguageHeader = parseAcceptLanguageHeader;
|
|
10
22
|
const getPreferredLanguageFromRequest = (request) => {
|
|
11
23
|
const acceptLanguageHeader = request.headers['accept-language'];
|
|
12
24
|
if (!acceptLanguageHeader) {
|