mock-config-server 1.0.4 → 2.0.0
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/README.md +277 -213
- package/dist/bin/mock-config-server.d.ts +2 -2
- package/dist/bin/mock-config-server.js +67 -65
- package/dist/bin/resolveExportsFromSourceCode.d.ts +1 -1
- package/dist/bin/resolveExportsFromSourceCode.js +11 -11
- package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateBaseUrl/validateBaseUrl.js +12 -0
- package/dist/bin/validateMockServerConfig/validateCors/validateCors.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateCors/validateCors.js +82 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateGraphqlConfig.js +48 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +71 -0
- package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateInterceptors/validateInterceptors.js +21 -0
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateMockServerConfig.js +34 -0
- package/dist/bin/validateMockServerConfig/validatePort/validatePort.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validatePort/validatePort.js +9 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRestConfig.js +52 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.d.ts +2 -0
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +104 -0
- package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.d.ts +1 -0
- package/dist/bin/validateMockServerConfig/validateStaticPath/validateStaticPath.js +44 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -17
- package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.d.ts +1 -2
- package/dist/src/configs/isEntitiesEqual/isEntityValuesEqual.js +29 -29
- package/dist/src/cors/corsMiddleware/corsMiddleware.d.ts +3 -3
- package/dist/src/cors/corsMiddleware/corsMiddleware.js +44 -32
- package/dist/src/cors/getOrigins/getAllowedOrigins.d.ts +2 -2
- package/dist/src/cors/getOrigins/getAllowedOrigins.js +13 -16
- package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.d.ts +2 -2
- package/dist/src/cors/noCorsMiddleware/noCorsMiddleware.js +20 -15
- package/dist/src/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +3 -0
- package/dist/src/graphql/createGraphQLRoutes/createGraphQLRoutes.js +73 -0
- package/dist/src/graphql/getGraphQLInput/getGraphQLInput.d.ts +3 -0
- package/dist/src/graphql/getGraphQLInput/getGraphQLInput.js +21 -0
- package/dist/src/graphql/parseGraphQLRequest/parseGraphQLRequest.d.ts +3 -0
- package/dist/src/graphql/parseGraphQLRequest/parseGraphQLRequest.js +12 -0
- package/dist/src/graphql/parseQuery/parseQuery.d.ts +7 -0
- package/dist/src/graphql/parseQuery/parseQuery.js +21 -0
- package/dist/src/graphql/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.d.ts +2 -0
- package/dist/src/graphql/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +28 -0
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +19 -19
- package/dist/src/notFound/notFoundMiddleware.d.ts +8 -0
- package/dist/src/notFound/notFoundMiddleware.js +47 -0
- package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.d.ts +6 -0
- package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +18 -0
- package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/index.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getGraphqlUrlSuggestions/index.js +17 -0
- package/dist/src/notFound/urlSuggestions/getLevenshteinDistance/getLevenshteinDistance.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getLevenshteinDistance/getLevenshteinDistance.js +80 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/getRestUrlSuggestions.d.ts +6 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/getRestUrlSuggestions.js +34 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString.js +7 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString.js +5 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/index.d.ts +2 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/helpers/index.js +18 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/index.d.ts +1 -0
- package/dist/src/notFound/urlSuggestions/getRestUrlSuggestions/index.js +17 -0
- package/dist/src/notFound/urlSuggestions/index.d.ts +2 -0
- package/dist/src/notFound/urlSuggestions/index.js +18 -0
- package/dist/src/rest/createRestRoutes/createRestRoutes.d.ts +3 -0
- package/dist/src/{routes/createRoutes/createRoutes.js → rest/createRestRoutes/createRestRoutes.js} +41 -43
- package/dist/src/rest/prepareRestRequestConfigs/prepareRestRequestConfigs.d.ts +2 -0
- package/dist/src/{configs/prepareRequestConfigs/prepareRequestConfigs.js → rest/prepareRestRequestConfigs/prepareRestRequestConfigs.js} +30 -30
- package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.d.ts +12 -12
- package/dist/src/routes/callRequestInterceptors/callRequestInterceptors.js +13 -13
- package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.d.ts +14 -14
- package/dist/src/routes/callResponseInterceptors/callResponseInterceptors.js +31 -31
- package/dist/src/server/createMockServer/createMockServer.d.ts +3 -3
- package/dist/src/server/createMockServer/createMockServer.js +48 -35
- package/dist/src/server/startMockServer/startMockServer.d.ts +2 -2
- package/dist/src/server/startMockServer/startMockServer.js +17 -13
- package/dist/src/static/staticMiddleware/staticMiddleware.d.ts +3 -3
- package/dist/src/static/staticMiddleware/staticMiddleware.js +30 -29
- package/dist/src/utils/constants/appPath.d.ts +1 -1
- package/dist/src/utils/constants/appPath.js +4 -4
- package/dist/src/utils/constants/default.d.ts +11 -10
- package/dist/src/utils/constants/default.js +14 -13
- package/dist/src/utils/constants/index.d.ts +2 -2
- package/dist/src/utils/constants/index.js +18 -18
- package/dist/src/utils/helpers/index.d.ts +3 -2
- package/dist/src/utils/helpers/index.js +19 -18
- package/dist/src/utils/helpers/isPlainObject.d.ts +1 -1
- package/dist/src/utils/helpers/isPlainObject.js +5 -5
- package/dist/src/utils/helpers/sleep.d.ts +1 -1
- package/dist/src/utils/helpers/sleep.js +7 -7
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.d.ts +1 -0
- package/dist/src/utils/helpers/url/getUrlParts/getUrlParts.js +6 -0
- package/dist/src/utils/helpers/url/index.d.ts +2 -0
- package/dist/src/utils/helpers/url/index.js +18 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.d.ts +1 -0
- package/dist/src/utils/helpers/url/removeLeadingAndTrailingSlashes/removeLeadingAndTrailingSlashes.js +5 -0
- package/dist/src/utils/types/configs.d.ts +63 -34
- package/dist/src/utils/types/configs.js +2 -2
- package/dist/src/utils/types/graphql.d.ts +5 -0
- package/dist/src/utils/types/graphql.js +2 -0
- package/dist/src/utils/types/index.d.ts +4 -3
- package/dist/src/utils/types/index.js +20 -19
- package/dist/src/utils/types/interceptors.d.ts +15 -15
- package/dist/src/utils/types/interceptors.js +2 -2
- package/dist/src/utils/types/server.d.ts +32 -24
- package/dist/src/utils/types/server.js +2 -2
- package/package.json +102 -99
- package/dist/src/configs/prepareRequestConfigs/prepareRequestConfigs.d.ts +0 -2
- package/dist/src/routes/createRoutes/createRoutes.d.ts +0 -3
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getActualRestUrlMeaningfulString = void 0;
|
|
4
|
+
const getActualRestUrlMeaningfulString = (actualUrlParts, patternUrlParts) => actualUrlParts
|
|
5
|
+
.filter((_actualUrlPart, index) => !patternUrlParts[index].startsWith(':'))
|
|
6
|
+
.join('');
|
|
7
|
+
exports.getActualRestUrlMeaningfulString = getActualRestUrlMeaningfulString;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPatternRestUrlMeaningfulString: (patternUrlParts: string[]) => string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getPatternRestUrlMeaningfulString = void 0;
|
|
4
|
+
const getPatternRestUrlMeaningfulString = (patternUrlParts) => patternUrlParts.filter((urlPatternPart) => !urlPatternPart.startsWith(':')).join('');
|
|
5
|
+
exports.getPatternRestUrlMeaningfulString = getPatternRestUrlMeaningfulString;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getActualRestUrlMeaningfulString/getActualRestUrlMeaningfulString"), exports);
|
|
18
|
+
__exportStar(require("./getPatternRestUrlMeaningfulString/getPatternRestUrlMeaningfulString"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getRestUrlSuggestions';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getRestUrlSuggestions"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./getGraphqlUrlSuggestions"), exports);
|
|
18
|
+
__exportStar(require("./getRestUrlSuggestions"), exports);
|
package/dist/src/{routes/createRoutes/createRoutes.js → rest/createRestRoutes/createRestRoutes.js}
RENAMED
|
@@ -1,43 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const isEntityValuesEqual_1 = require("../../configs/isEntitiesEqual/isEntityValuesEqual");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
(0,
|
|
10
|
-
router.route(requestConfig.path)[requestConfig.method]((request, response) => {
|
|
11
|
-
(0, callRequestInterceptors_1.callRequestInterceptors)({
|
|
12
|
-
request,
|
|
13
|
-
interceptors: {
|
|
14
|
-
requestInterceptor: requestConfig.interceptors?.request,
|
|
15
|
-
serverInterceptor:
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
const matchedRouteConfig = requestConfig.routes.find(({ entities }) => {
|
|
19
|
-
if (!entities)
|
|
20
|
-
return true;
|
|
21
|
-
return Object.entries(entities).every(([entity, entityValue]) => (0, isEntityValuesEqual_1.isEntityValuesEqual)(entityValue, request[entity]));
|
|
22
|
-
});
|
|
23
|
-
if (!matchedRouteConfig) {
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
};
|
|
43
|
-
exports.createRoutes = createRoutes;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRestRoutes = void 0;
|
|
4
|
+
const isEntityValuesEqual_1 = require("../../configs/isEntitiesEqual/isEntityValuesEqual");
|
|
5
|
+
const callRequestInterceptors_1 = require("../../routes/callRequestInterceptors/callRequestInterceptors");
|
|
6
|
+
const callResponseInterceptors_1 = require("../../routes/callResponseInterceptors/callResponseInterceptors");
|
|
7
|
+
const prepareRestRequestConfigs_1 = require("../prepareRestRequestConfigs/prepareRestRequestConfigs");
|
|
8
|
+
const createRestRoutes = (router, configs, interceptors) => {
|
|
9
|
+
(0, prepareRestRequestConfigs_1.prepareRestRequestConfigs)(configs).forEach((requestConfig) => {
|
|
10
|
+
router.route(requestConfig.path)[requestConfig.method]((request, response, next) => {
|
|
11
|
+
(0, callRequestInterceptors_1.callRequestInterceptors)({
|
|
12
|
+
request,
|
|
13
|
+
interceptors: {
|
|
14
|
+
requestInterceptor: requestConfig.interceptors?.request,
|
|
15
|
+
serverInterceptor: interceptors?.request
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const matchedRouteConfig = requestConfig.routes.find(({ entities }) => {
|
|
19
|
+
if (!entities)
|
|
20
|
+
return true;
|
|
21
|
+
return Object.entries(entities).every(([entity, entityValue]) => (0, isEntityValuesEqual_1.isEntityValuesEqual)(entityValue, request[entity]));
|
|
22
|
+
});
|
|
23
|
+
if (!matchedRouteConfig) {
|
|
24
|
+
return next();
|
|
25
|
+
}
|
|
26
|
+
const data = (0, callResponseInterceptors_1.callResponseInterceptors)({
|
|
27
|
+
data: matchedRouteConfig.data,
|
|
28
|
+
request,
|
|
29
|
+
response,
|
|
30
|
+
interceptors: {
|
|
31
|
+
routeInterceptor: matchedRouteConfig.interceptors?.response,
|
|
32
|
+
requestInterceptor: requestConfig.interceptors?.response,
|
|
33
|
+
serverInterceptor: interceptors?.response
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return response.status(response.statusCode).json(data);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
return router;
|
|
40
|
+
};
|
|
41
|
+
exports.createRestRoutes = createRestRoutes;
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const helpers_1 = require("../../utils/helpers");
|
|
5
|
-
const calculateRouteConfigWeight = (
|
|
6
|
-
const { entities } =
|
|
7
|
-
if (!entities)
|
|
8
|
-
return 0;
|
|
9
|
-
let routeConfigWeight = 0;
|
|
10
|
-
const { headers, query, params, body } = entities;
|
|
11
|
-
if (headers)
|
|
12
|
-
routeConfigWeight += Object.keys(headers).length;
|
|
13
|
-
if (query)
|
|
14
|
-
routeConfigWeight += Object.keys(query).length;
|
|
15
|
-
if (params)
|
|
16
|
-
routeConfigWeight += Object.keys(params).length;
|
|
17
|
-
if (body)
|
|
18
|
-
routeConfigWeight += (0, helpers_1.isPlainObject)(body) ? Object.keys(body).length : 1;
|
|
19
|
-
return routeConfigWeight;
|
|
20
|
-
};
|
|
21
|
-
const
|
|
22
|
-
requestConfigs.forEach((requestConfig) => {
|
|
23
|
-
requestConfig.routes.sort((first, second) =>
|
|
24
|
-
// ✅ important:
|
|
25
|
-
// Lift more specific configs for correct working of routes
|
|
26
|
-
calculateRouteConfigWeight(second) - calculateRouteConfigWeight(first));
|
|
27
|
-
});
|
|
28
|
-
return requestConfigs;
|
|
29
|
-
};
|
|
30
|
-
exports.
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareRestRequestConfigs = void 0;
|
|
4
|
+
const helpers_1 = require("../../utils/helpers");
|
|
5
|
+
const calculateRouteConfigWeight = (restRouteConfig) => {
|
|
6
|
+
const { entities } = restRouteConfig;
|
|
7
|
+
if (!entities)
|
|
8
|
+
return 0;
|
|
9
|
+
let routeConfigWeight = 0;
|
|
10
|
+
const { headers, query, params, body } = entities;
|
|
11
|
+
if (headers)
|
|
12
|
+
routeConfigWeight += Object.keys(headers).length;
|
|
13
|
+
if (query)
|
|
14
|
+
routeConfigWeight += Object.keys(query).length;
|
|
15
|
+
if (params)
|
|
16
|
+
routeConfigWeight += Object.keys(params).length;
|
|
17
|
+
if (body)
|
|
18
|
+
routeConfigWeight += (0, helpers_1.isPlainObject)(body) ? Object.keys(body).length : 1;
|
|
19
|
+
return routeConfigWeight;
|
|
20
|
+
};
|
|
21
|
+
const prepareRestRequestConfigs = (requestConfigs) => {
|
|
22
|
+
requestConfigs.forEach((requestConfig) => {
|
|
23
|
+
requestConfig.routes.sort((first, second) =>
|
|
24
|
+
// ✅ important:
|
|
25
|
+
// Lift more specific configs for correct working of routes
|
|
26
|
+
calculateRouteConfigWeight(second) - calculateRouteConfigWeight(first));
|
|
27
|
+
});
|
|
28
|
+
return requestConfigs;
|
|
29
|
+
};
|
|
30
|
+
exports.prepareRestRequestConfigs = prepareRestRequestConfigs;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { Request } from 'express';
|
|
2
|
-
import { InterceptorRequest } from '../../utils/types';
|
|
3
|
-
interface CallRequestInterceptorsParams {
|
|
4
|
-
request: Request;
|
|
5
|
-
interceptors?: {
|
|
6
|
-
routeInterceptor?: InterceptorRequest | undefined;
|
|
7
|
-
requestInterceptor?: InterceptorRequest | undefined;
|
|
8
|
-
serverInterceptor?: InterceptorRequest | undefined;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
export declare const callRequestInterceptors: (params: CallRequestInterceptorsParams) => void;
|
|
12
|
-
export {};
|
|
1
|
+
import type { Request } from 'express';
|
|
2
|
+
import { InterceptorRequest } from '../../utils/types';
|
|
3
|
+
interface CallRequestInterceptorsParams {
|
|
4
|
+
request: Request;
|
|
5
|
+
interceptors?: {
|
|
6
|
+
routeInterceptor?: InterceptorRequest | undefined;
|
|
7
|
+
requestInterceptor?: InterceptorRequest | undefined;
|
|
8
|
+
serverInterceptor?: InterceptorRequest | undefined;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare const callRequestInterceptors: (params: CallRequestInterceptorsParams) => void;
|
|
12
|
+
export {};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callRequestInterceptors = void 0;
|
|
4
|
-
const callRequestInterceptors = (params) => {
|
|
5
|
-
const { request, interceptors } = params;
|
|
6
|
-
if (interceptors?.routeInterceptor)
|
|
7
|
-
interceptors.routeInterceptor({ request });
|
|
8
|
-
if (interceptors?.requestInterceptor)
|
|
9
|
-
interceptors.requestInterceptor({ request });
|
|
10
|
-
if (interceptors?.serverInterceptor)
|
|
11
|
-
interceptors.serverInterceptor({ request });
|
|
12
|
-
};
|
|
13
|
-
exports.callRequestInterceptors = callRequestInterceptors;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callRequestInterceptors = void 0;
|
|
4
|
+
const callRequestInterceptors = (params) => {
|
|
5
|
+
const { request, interceptors } = params;
|
|
6
|
+
if (interceptors?.routeInterceptor)
|
|
7
|
+
interceptors.routeInterceptor({ request });
|
|
8
|
+
if (interceptors?.requestInterceptor)
|
|
9
|
+
interceptors.requestInterceptor({ request });
|
|
10
|
+
if (interceptors?.serverInterceptor)
|
|
11
|
+
interceptors.serverInterceptor({ request });
|
|
12
|
+
};
|
|
13
|
+
exports.callRequestInterceptors = callRequestInterceptors;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { Request, Response } from 'express';
|
|
2
|
-
import type { InterceptorResponse } from '../../utils/types';
|
|
3
|
-
interface CallResponseInterceptorsParams<T> {
|
|
4
|
-
data: T;
|
|
5
|
-
request: Request;
|
|
6
|
-
response: Response;
|
|
7
|
-
interceptors?: {
|
|
8
|
-
routeInterceptor?: InterceptorResponse | undefined;
|
|
9
|
-
requestInterceptor?: InterceptorResponse | undefined;
|
|
10
|
-
serverInterceptor?: InterceptorResponse | undefined;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export declare const callResponseInterceptors: <T =
|
|
14
|
-
export {};
|
|
1
|
+
import type { Request, Response } from 'express';
|
|
2
|
+
import type { InterceptorResponse } from '../../utils/types';
|
|
3
|
+
interface CallResponseInterceptorsParams<T> {
|
|
4
|
+
data: T;
|
|
5
|
+
request: Request;
|
|
6
|
+
response: Response;
|
|
7
|
+
interceptors?: {
|
|
8
|
+
routeInterceptor?: InterceptorResponse | undefined;
|
|
9
|
+
requestInterceptor?: InterceptorResponse | undefined;
|
|
10
|
+
serverInterceptor?: InterceptorResponse | undefined;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare const callResponseInterceptors: <T = unknown>(params: CallResponseInterceptorsParams<T>) => T;
|
|
14
|
+
export {};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callResponseInterceptors = void 0;
|
|
4
|
-
const helpers_1 = require("../../utils/helpers");
|
|
5
|
-
const callResponseInterceptors = (params) => {
|
|
6
|
-
const { data, request, response, interceptors } = params;
|
|
7
|
-
const setDelay = async (delay) => {
|
|
8
|
-
await (0, helpers_1.sleep)(delay === Infinity ? 100000 : delay);
|
|
9
|
-
};
|
|
10
|
-
const setStatusCode = (statusCode) => {
|
|
11
|
-
response.statusCode = statusCode;
|
|
12
|
-
};
|
|
13
|
-
const interceptorResponseParams = {
|
|
14
|
-
request,
|
|
15
|
-
response,
|
|
16
|
-
setDelay,
|
|
17
|
-
setStatusCode
|
|
18
|
-
};
|
|
19
|
-
let updatedData = data;
|
|
20
|
-
if (interceptors?.routeInterceptor) {
|
|
21
|
-
updatedData = interceptors.routeInterceptor(updatedData, interceptorResponseParams);
|
|
22
|
-
}
|
|
23
|
-
if (interceptors?.requestInterceptor) {
|
|
24
|
-
updatedData = interceptors.requestInterceptor(updatedData, interceptorResponseParams);
|
|
25
|
-
}
|
|
26
|
-
if (interceptors?.serverInterceptor) {
|
|
27
|
-
updatedData = interceptors.serverInterceptor(updatedData, interceptorResponseParams);
|
|
28
|
-
}
|
|
29
|
-
return updatedData;
|
|
30
|
-
};
|
|
31
|
-
exports.callResponseInterceptors = callResponseInterceptors;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callResponseInterceptors = void 0;
|
|
4
|
+
const helpers_1 = require("../../utils/helpers");
|
|
5
|
+
const callResponseInterceptors = (params) => {
|
|
6
|
+
const { data, request, response, interceptors } = params;
|
|
7
|
+
const setDelay = async (delay) => {
|
|
8
|
+
await (0, helpers_1.sleep)(delay === Infinity ? 100000 : delay);
|
|
9
|
+
};
|
|
10
|
+
const setStatusCode = (statusCode) => {
|
|
11
|
+
response.statusCode = statusCode;
|
|
12
|
+
};
|
|
13
|
+
const interceptorResponseParams = {
|
|
14
|
+
request,
|
|
15
|
+
response,
|
|
16
|
+
setDelay,
|
|
17
|
+
setStatusCode
|
|
18
|
+
};
|
|
19
|
+
let updatedData = data;
|
|
20
|
+
if (interceptors?.routeInterceptor) {
|
|
21
|
+
updatedData = interceptors.routeInterceptor(updatedData, interceptorResponseParams);
|
|
22
|
+
}
|
|
23
|
+
if (interceptors?.requestInterceptor) {
|
|
24
|
+
updatedData = interceptors.requestInterceptor(updatedData, interceptorResponseParams);
|
|
25
|
+
}
|
|
26
|
+
if (interceptors?.serverInterceptor) {
|
|
27
|
+
updatedData = interceptors.serverInterceptor(updatedData, interceptorResponseParams);
|
|
28
|
+
}
|
|
29
|
+
return updatedData;
|
|
30
|
+
};
|
|
31
|
+
exports.callResponseInterceptors = callResponseInterceptors;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Express } from 'express';
|
|
2
|
-
import type { MockServerConfig } from '../../utils/types';
|
|
3
|
-
export declare const createMockServer: (
|
|
1
|
+
import type { Express } from 'express';
|
|
2
|
+
import type { MockServerConfig } from '../../utils/types';
|
|
3
|
+
export declare const createMockServer: (mockServerConfig: Omit<MockServerConfig, 'port'>) => Express;
|
|
@@ -1,35 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createMockServer = void 0;
|
|
7
|
-
const body_parser_1 = __importDefault(require("body-parser"));
|
|
8
|
-
const express_1 = __importDefault(require("express"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createMockServer = void 0;
|
|
7
|
+
const body_parser_1 = __importDefault(require("body-parser"));
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const corsMiddleware_1 = require("../../cors/corsMiddleware/corsMiddleware");
|
|
11
|
+
const noCorsMiddleware_1 = require("../../cors/noCorsMiddleware/noCorsMiddleware");
|
|
12
|
+
const createGraphQLRoutes_1 = require("../../graphql/createGraphQLRoutes/createGraphQLRoutes");
|
|
13
|
+
const notFoundMiddleware_1 = require("../../notFound/notFoundMiddleware");
|
|
14
|
+
const createRestRoutes_1 = require("../../rest/createRestRoutes/createRestRoutes");
|
|
15
|
+
const staticMiddleware_1 = require("../../static/staticMiddleware/staticMiddleware");
|
|
16
|
+
const createMockServer = (mockServerConfig) => {
|
|
17
|
+
const { cors, staticPath, rest, graphql, interceptors } = mockServerConfig;
|
|
18
|
+
const server = (0, express_1.default)();
|
|
19
|
+
server.set('view engine', 'ejs');
|
|
20
|
+
server.use(body_parser_1.default.urlencoded({ extended: false }));
|
|
21
|
+
server.use(body_parser_1.default.json({ limit: '10mb' }));
|
|
22
|
+
const baseUrl = mockServerConfig.baseUrl ?? '/';
|
|
23
|
+
if (cors) {
|
|
24
|
+
(0, corsMiddleware_1.corsMiddleware)(server, cors);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
(0, noCorsMiddleware_1.noCorsMiddleware)(server);
|
|
28
|
+
}
|
|
29
|
+
if (staticPath) {
|
|
30
|
+
(0, staticMiddleware_1.staticMiddleware)(server, baseUrl, staticPath);
|
|
31
|
+
}
|
|
32
|
+
if (rest) {
|
|
33
|
+
const routerWithRestRoutes = (0, createRestRoutes_1.createRestRoutes)(express_1.default.Router(), rest.configs, interceptors);
|
|
34
|
+
const restBaseUrl = path_1.default.join(baseUrl, rest.baseUrl ?? '/');
|
|
35
|
+
server.use(restBaseUrl, routerWithRestRoutes);
|
|
36
|
+
}
|
|
37
|
+
if (graphql) {
|
|
38
|
+
const routerWithGraphQLRoutes = (0, createGraphQLRoutes_1.createGraphQLRoutes)(express_1.default.Router(), graphql.configs, interceptors);
|
|
39
|
+
const graphqlBaseUrl = path_1.default.join(baseUrl, graphql.baseUrl ?? '/');
|
|
40
|
+
server.use(graphqlBaseUrl, routerWithGraphQLRoutes);
|
|
41
|
+
}
|
|
42
|
+
(0, notFoundMiddleware_1.notFoundMiddleware)({
|
|
43
|
+
server,
|
|
44
|
+
mockServerConfig
|
|
45
|
+
});
|
|
46
|
+
return server;
|
|
47
|
+
};
|
|
48
|
+
exports.createMockServer = createMockServer;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MockServerConfig } from '../../utils/types';
|
|
2
|
-
export declare const startMockServer: (mockServerConfig: MockServerConfig) => void;
|
|
1
|
+
import type { MockServerConfig } from '../../utils/types';
|
|
2
|
+
export declare const startMockServer: (mockServerConfig: MockServerConfig) => void;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.startMockServer = void 0;
|
|
7
|
+
const ansi_colors_1 = __importDefault(require("ansi-colors"));
|
|
8
|
+
const constants_1 = require("../../utils/constants");
|
|
9
|
+
const createMockServer_1 = require("../createMockServer/createMockServer");
|
|
10
|
+
const startMockServer = (mockServerConfig) => {
|
|
11
|
+
const mockServer = (0, createMockServer_1.createMockServer)(mockServerConfig);
|
|
12
|
+
const port = mockServerConfig.port ?? constants_1.DEFAULT.PORT;
|
|
13
|
+
mockServer.listen(port, () => {
|
|
14
|
+
console.log(ansi_colors_1.default.green(`🎉 Mock Server is running at http://localhost:${port}`));
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
exports.startMockServer = startMockServer;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Express } from 'express';
|
|
2
|
-
import type { BaseUrl, StaticPath } from '../../utils/types';
|
|
3
|
-
export declare const staticMiddleware: (server: Express, baseUrl: BaseUrl, staticPath: StaticPath) => void;
|
|
1
|
+
import type { Express } from 'express';
|
|
2
|
+
import type { BaseUrl, StaticPath } from '../../utils/types';
|
|
3
|
+
export declare const staticMiddleware: (server: Express, baseUrl: BaseUrl, staticPath: StaticPath) => void;
|
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.staticMiddleware = void 0;
|
|
7
|
-
const express_1 = __importDefault(require("express"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const constants_1 = require("../../utils/constants");
|
|
10
|
-
const staticMiddleware = (server, baseUrl, staticPath) => {
|
|
11
|
-
const isStaticPathArray = Array.isArray(staticPath);
|
|
12
|
-
if (isStaticPathArray) {
|
|
13
|
-
staticPath.forEach((staticPath) => {
|
|
14
|
-
const isPathObject = typeof staticPath === 'object';
|
|
15
|
-
if (isPathObject) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.staticMiddleware = void 0;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const constants_1 = require("../../utils/constants");
|
|
10
|
+
const staticMiddleware = (server, baseUrl, staticPath) => {
|
|
11
|
+
const isStaticPathArray = Array.isArray(staticPath);
|
|
12
|
+
if (isStaticPathArray) {
|
|
13
|
+
staticPath.forEach((staticPath) => {
|
|
14
|
+
const isPathObject = typeof staticPath === 'object';
|
|
15
|
+
if (isPathObject) {
|
|
16
|
+
server.use(path_1.default.join(baseUrl, staticPath.prefix), express_1.default.static(path_1.default.join(constants_1.APP_PATH, staticPath.path)));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
server.use(baseUrl, express_1.default.static(path_1.default.join(constants_1.APP_PATH, staticPath)));
|
|
20
|
+
});
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const isStaticPathObject = typeof staticPath === 'object';
|
|
24
|
+
if (isStaticPathObject) {
|
|
25
|
+
server.use(path_1.default.join(baseUrl, staticPath.prefix), express_1.default.static(path_1.default.join(constants_1.APP_PATH, staticPath.path)));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
server.use(baseUrl, express_1.default.static(path_1.default.join(constants_1.APP_PATH, staticPath)));
|
|
29
|
+
};
|
|
30
|
+
exports.staticMiddleware = staticMiddleware;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const APP_PATH: string;
|
|
1
|
+
export declare const APP_PATH: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.APP_PATH = void 0;
|
|
4
|
-
exports.APP_PATH = process.cwd();
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.APP_PATH = void 0;
|
|
4
|
+
exports.APP_PATH = process.cwd();
|