axe-api 1.5.0-rc-2 → 1.5.0-rc-4
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.
|
@@ -227,6 +227,11 @@ const getRelatedData = (version, data, withArray, model, modelList, database, ha
|
|
|
227
227
|
}
|
|
228
228
|
selectColumns = uniqueByMap(selectColumns);
|
|
229
229
|
const foreignModelQuery = database(foreignModel.instance.table).select(selectColumns);
|
|
230
|
+
// Call the onBeforeQuery function if there is a defined one!
|
|
231
|
+
console.log("QUERRRRY", foreignModel.instance.table, definedRelation.options);
|
|
232
|
+
if (definedRelation.options.onBeforeQuery) {
|
|
233
|
+
yield definedRelation.options.onBeforeQuery(request, foreignModelQuery);
|
|
234
|
+
}
|
|
230
235
|
// If the model is supported soft-delete we should check the data.
|
|
231
236
|
if (foreignModel.instance.deletedAtColumn) {
|
|
232
237
|
foreignModelQuery.whereNull(foreignModel.instance.deletedAtColumn);
|
|
@@ -44,15 +44,15 @@ export interface IQueryConfig {
|
|
|
44
44
|
limits: Array<IQueryLimitConfig[]>;
|
|
45
45
|
defaults?: IQueryDefaultConfig;
|
|
46
46
|
}
|
|
47
|
-
export interface IRateLimitMiddleware {
|
|
48
|
-
name: string;
|
|
49
|
-
clientKey: string;
|
|
50
|
-
setResponseHeaders?: boolean;
|
|
51
|
-
}
|
|
52
47
|
export interface IRateLimitOptions {
|
|
53
48
|
maxRequests: number;
|
|
54
49
|
windowInSeconds: number;
|
|
55
50
|
}
|
|
51
|
+
export interface IRateLimitIdentifier extends IRateLimitOptions {
|
|
52
|
+
name: string;
|
|
53
|
+
clientKey: string;
|
|
54
|
+
setResponseHeaders?: boolean;
|
|
55
|
+
}
|
|
56
56
|
export interface IRateLimitConfig extends IRateLimitOptions {
|
|
57
57
|
enabled: boolean;
|
|
58
58
|
adaptor: AdaptorType;
|
|
@@ -402,6 +402,7 @@ export interface IElasticSearchParameters {
|
|
|
402
402
|
}
|
|
403
403
|
export interface IHasManyOptions {
|
|
404
404
|
autoRouting: boolean;
|
|
405
|
+
onBeforeQuery?: (req: AxeRequest, query: Knex.QueryBuilder) => Promise<void>;
|
|
405
406
|
}
|
|
406
407
|
export interface IValidator {
|
|
407
408
|
validate: (req: AxeRequest, model: IModelService, formData: any) => Promise<null | IValidationError>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncomingMessage, ServerResponse } from "http";
|
|
2
|
-
import { AxeConfig, IRateLimitOptions, IContext,
|
|
2
|
+
import { AxeConfig, IRateLimitOptions, IContext, IRateLimitIdentifier } from "../../Interfaces";
|
|
3
3
|
export declare const setupRateLimitAdaptors: (config: AxeConfig) => Promise<void>;
|
|
4
4
|
/**
|
|
5
5
|
* Add a rate limit with the `IRateLimitOptions`
|
|
@@ -30,6 +30,6 @@ export declare const rateLimit: (options?: IRateLimitOptions) => (context: ICont
|
|
|
30
30
|
* @param next NextFunction
|
|
31
31
|
* @returns
|
|
32
32
|
*/
|
|
33
|
-
export declare const createRateLimitter: (
|
|
33
|
+
export declare const createRateLimitter: (identifier: IRateLimitIdentifier, req: IncomingMessage, res: ServerResponse, next: any) => Promise<any>;
|
|
34
34
|
declare const _default: (req: IncomingMessage, res: ServerResponse, next: any) => Promise<any>;
|
|
35
35
|
export default _default;
|
|
@@ -105,7 +105,7 @@ const rateLimit = (options) => {
|
|
|
105
105
|
context.res.original.setHeader("X-RateLimit-Remaining", isAllowed.remaining);
|
|
106
106
|
// Sending an error message if there is an error
|
|
107
107
|
if (isAllowed.success === false) {
|
|
108
|
-
Services_1.LogService.
|
|
108
|
+
Services_1.LogService.info(`Rate limit exceeded: ${context.req.url}`);
|
|
109
109
|
context.res
|
|
110
110
|
.status(Enums_1.StatusCodes.TOO_MANY_REQUESTS)
|
|
111
111
|
.json({ error: "Rate limit exceeded." });
|
|
@@ -124,20 +124,20 @@ exports.rateLimit = rateLimit;
|
|
|
124
124
|
* @param next NextFunction
|
|
125
125
|
* @returns
|
|
126
126
|
*/
|
|
127
|
-
const createRateLimitter = (
|
|
127
|
+
const createRateLimitter = (identifier, req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
128
|
// Checking the rate limits.
|
|
129
|
-
const isAllowed = yield checkRateLimit(
|
|
129
|
+
const isAllowed = yield checkRateLimit(identifier.clientKey, identifier);
|
|
130
130
|
// Setting the HTTP Response headers.
|
|
131
|
-
if (
|
|
132
|
-
res.setHeader(`X-${
|
|
133
|
-
res.setHeader(`X-${
|
|
131
|
+
if (identifier.setResponseHeaders) {
|
|
132
|
+
res.setHeader(`X-${identifier.name}-Limit`, isAllowed.limit);
|
|
133
|
+
res.setHeader(`X-${identifier.name}-Remaining`, isAllowed.remaining);
|
|
134
134
|
}
|
|
135
135
|
// If it is allowed, the next function would be called.
|
|
136
136
|
if (isAllowed.success) {
|
|
137
137
|
return next();
|
|
138
138
|
}
|
|
139
139
|
// Sending an error message.
|
|
140
|
-
Services_1.LogService.
|
|
140
|
+
Services_1.LogService.info(`Rate limit exceeded: ${req.url}`);
|
|
141
141
|
res.writeHead(429, { "Content-Type": "application/json" });
|
|
142
142
|
res.end(JSON.stringify({
|
|
143
143
|
error: "Rate limit exceeded.",
|
|
@@ -161,7 +161,7 @@ exports.default = (req, res, next) => __awaiter(void 0, void 0, void 0, function
|
|
|
161
161
|
return next();
|
|
162
162
|
}
|
|
163
163
|
// Sending an error message.
|
|
164
|
-
Services_1.LogService.
|
|
164
|
+
Services_1.LogService.info(`Rate limit exceeded: ${req.url}`);
|
|
165
165
|
res.writeHead(429, { "Content-Type": "application/json" });
|
|
166
166
|
res.end(JSON.stringify({
|
|
167
167
|
error: "Rate limit exceeded.",
|