mock-config-server 2.2.0 → 2.4.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 +10 -5
- package/dist/bin/build.d.ts +2 -0
- package/dist/bin/build.js +49 -0
- package/dist/bin/cli.js +14 -2
- package/dist/bin/helpers/index.d.ts +3 -0
- package/dist/bin/helpers/index.js +19 -0
- package/dist/bin/helpers/resolveConfigFile.d.ts +2 -0
- package/dist/bin/helpers/resolveConfigFile.js +20 -0
- package/dist/bin/helpers/resolveConfigFilePath.d.ts +1 -0
- package/dist/bin/helpers/resolveConfigFilePath.js +39 -0
- package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.d.ts +1 -0
- package/dist/bin/resolveConfigFilePath/resolveConfigFilePath.js +39 -0
- package/dist/bin/run.d.ts +6 -0
- package/dist/bin/run.js +17 -0
- package/dist/bin/validateMockServerConfig/validateGraphqlConfig/validateRoutes/validateRoutes.js +11 -11
- package/dist/bin/validateMockServerConfig/validateRestConfig/validateRoutes/validateRoutes.js +15 -15
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.d.ts +2 -2
- package/dist/src/core/graphql/createGraphQLRoutes/createGraphQLRoutes.js +18 -16
- package/dist/src/core/graphql/createGraphQLRoutes/helpers/prepareGraphQLRequestConfigs/prepareGraphQLRequestConfigs.js +3 -1
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.d.ts +2 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/cookieParseMiddleware.js +16 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.d.ts +1 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/index.js +17 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.d.ts +3 -0
- package/dist/src/core/middlewares/cookieParseMiddleware/helpers/parseCookie/parseCookie.js +17 -0
- package/dist/src/core/middlewares/corsMiddleware/corsMiddleware.js +12 -12
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.d.ts +7 -0
- package/dist/src/core/middlewares/destroyerMiddleware/destroyerMiddleware.js +23 -0
- package/dist/src/core/middlewares/index.d.ts +3 -0
- package/dist/src/core/middlewares/index.js +3 -0
- package/dist/src/core/middlewares/noCorsMiddleware/noCorsMiddleware.js +13 -13
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.d.ts +7 -2
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getGraphqlUrlSuggestions/getGraphqlUrlSuggestions.js +8 -7
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.d.ts +7 -2
- package/dist/src/core/middlewares/notFoundMiddleware/helpers/getRestUrlSuggestions/getRestUrlSuggestions.js +4 -4
- package/dist/src/core/middlewares/notFoundMiddleware/notFoundMiddleware.js +36 -30
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.d.ts +3 -0
- package/dist/src/core/middlewares/requestInterceptorMiddleware/requestInterceptorMiddleware.js +11 -0
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.d.ts +2 -2
- package/dist/src/core/rest/createRestRoutes/createRestRoutes.js +9 -11
- package/dist/src/core/rest/createRestRoutes/helpers/prepareRestRequestConfigs/prepareRestRequestConfigs.js +3 -1
- package/dist/src/server/createMockServer/createMockServer.js +17 -3
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/server/index.js +1 -1
- package/dist/src/server/startMockServer/startMockServer.d.ts +4 -1
- package/dist/src/server/startMockServer/startMockServer.js +4 -1
- package/dist/src/static/views/assets/icons/scheme-dark.svg +3 -0
- package/dist/src/static/views/assets/icons/scheme-light.svg +3 -0
- package/dist/src/static/views/assets/images/404.png +0 -0
- package/dist/src/static/views/assets/images/logo.png +0 -0
- package/dist/src/static/views/assets/images/success.png +0 -0
- package/dist/src/static/views/assets/styles/global.css +88 -0
- package/dist/src/static/views/components/header/index.css +55 -0
- package/dist/src/static/views/components/header/index.ejs +40 -0
- package/dist/src/static/views/components/header/index.js +1 -0
- package/dist/src/static/views/features/scheme/dark.css +12 -0
- package/dist/src/static/views/features/scheme/index.ejs +3 -0
- package/dist/src/static/views/features/scheme/index.js +31 -0
- package/dist/src/static/views/features/scheme/light.css +12 -0
- package/dist/src/static/views/features/tab/index.css +30 -0
- package/dist/src/static/views/features/tab/index.ejs +2 -0
- package/dist/src/static/views/features/tab/index.js +12 -0
- package/dist/src/static/views/pages/404/index.css +10 -0
- package/dist/src/static/views/pages/404/index.ejs +85 -0
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.d.ts +8 -0
- package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.js +19 -0
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.d.ts +6 -5
- package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js +20 -23
- package/dist/src/utils/helpers/interceptors/helpers/setDelay.d.ts +1 -0
- package/dist/src/utils/helpers/interceptors/helpers/setDelay.js +8 -0
- package/dist/src/utils/helpers/interceptors/index.d.ts +1 -1
- package/dist/src/utils/helpers/interceptors/index.js +1 -1
- package/dist/src/utils/helpers/sleep.d.ts +1 -1
- package/dist/src/utils/helpers/sleep.js +2 -2
- package/dist/src/utils/types/graphql.d.ts +1 -1
- package/dist/src/utils/types/interceptors.d.ts +15 -6
- package/dist/src/utils/types/rest.d.ts +9 -8
- package/dist/src/utils/types/server.d.ts +19 -9
- package/dist/src/utils/types/values.d.ts +1 -0
- package/package.json +9 -2
- package/dist/bin/start.d.ts +0 -3
- package/dist/bin/start.js +0 -73
- package/dist/src/static/views/notFound.ejs +0 -42
- package/dist/src/utils/helpers/interceptors/callRequestInterceptors/callRequestInterceptors.d.ts +0 -12
- package/dist/src/utils/helpers/interceptors/callRequestInterceptors/callRequestInterceptors.js +0 -13
- /package/dist/bin/{resolveExportsFromSourceCode → helpers}/resolveExportsFromSourceCode.d.ts +0 -0
- /package/dist/bin/{resolveExportsFromSourceCode → helpers}/resolveExportsFromSourceCode.js +0 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const lightStyles = document.querySelector(
|
|
2
|
+
'link[rel=stylesheet][media*=prefers-color-scheme][media*=light]'
|
|
3
|
+
);
|
|
4
|
+
const darkStyles = document.querySelector(
|
|
5
|
+
'link[rel=stylesheet][media*=prefers-color-scheme][media*=dark]'
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
function getSavedScheme() {
|
|
9
|
+
return localStorage.getItem('color-scheme');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function setScheme(scheme) {
|
|
13
|
+
const lightMedia = scheme === 'light' ? 'all' : 'not all';
|
|
14
|
+
const darkMedia = scheme === 'dark' ? 'all' : 'not all';
|
|
15
|
+
|
|
16
|
+
lightStyles.media = lightMedia;
|
|
17
|
+
darkStyles.media = darkMedia;
|
|
18
|
+
|
|
19
|
+
localStorage.setItem('color-scheme', scheme);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
23
|
+
function switchScheme() {
|
|
24
|
+
setScheme(getSavedScheme() === 'light' ? 'dark' : 'light');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function initScheme() {
|
|
28
|
+
setScheme(getSavedScheme() ?? 'dark');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
initScheme();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
color-scheme: light;
|
|
3
|
+
--accent: rgb(149 155 255);
|
|
4
|
+
--accent-glass: rgb(149 155 255 / 50%);
|
|
5
|
+
--primary: #343434;
|
|
6
|
+
--primary-glass: rgba(52 52 52 / 70%);
|
|
7
|
+
--shadow: 0px 4px 10px rgba(0 0 0 / 15%);
|
|
8
|
+
--background-body: #e4e5ef;
|
|
9
|
+
--background-container: rgba(255 255 255 / 75%);
|
|
10
|
+
--background-card: rgba(255 255 255 / 75%);
|
|
11
|
+
--image-scheme: url('/assets/icons/scheme-light.svg');
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.tab-items {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: row;
|
|
4
|
+
align-items: center;
|
|
5
|
+
padding: 3px;
|
|
6
|
+
border-radius: 20px;
|
|
7
|
+
background: var(--background-container);
|
|
8
|
+
font-size: 14px;
|
|
9
|
+
font-weight: 300;
|
|
10
|
+
gap: 4px;
|
|
11
|
+
line-height: 17px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.tab-item {
|
|
15
|
+
display: flex;
|
|
16
|
+
width: 120px;
|
|
17
|
+
height: 30px;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
border-radius: 20px;
|
|
21
|
+
cursor: pointer;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.tab-item:not(.tab-item-active):hover {
|
|
25
|
+
background-color: var(--accent-glass);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.tab-content {
|
|
29
|
+
display: none;
|
|
30
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function switchTab(activeTabId) {
|
|
2
|
+
document.querySelector('body').className = activeTabId;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function initTab() {
|
|
6
|
+
const tabItems = document.getElementsByClassName('tab-item');
|
|
7
|
+
for (let i = 0; i < tabItems.length; i += 1) {
|
|
8
|
+
tabItems[i].addEventListener('click', () => switchTab(tabItems[i].id));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
initTab();
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
|
|
8
|
+
<title>404 - 🎉 Mock Config Server</title>
|
|
9
|
+
|
|
10
|
+
<link rel="stylesheet" href="/assets/styles/global.css" />
|
|
11
|
+
<link rel="stylesheet" href="/pages/404/index.css" />
|
|
12
|
+
|
|
13
|
+
<% const api = { rest: "REST", graphql: "GraphQL" } %>
|
|
14
|
+
|
|
15
|
+
<% const rootPath = (path) => `../../${path}` %>
|
|
16
|
+
<%- include(rootPath('features/scheme/index')) -%>
|
|
17
|
+
<%- include(rootPath('features/tab/index')) -%>
|
|
18
|
+
</head>
|
|
19
|
+
|
|
20
|
+
<body class="tab-item-<%= graphqlRequestSuggestions.length ? api.graphql : api.rest %>">
|
|
21
|
+
<%- include(rootPath('components/header/index')) -%>
|
|
22
|
+
<div class="margin-container">
|
|
23
|
+
<div class="hero">
|
|
24
|
+
<div class="title">
|
|
25
|
+
<img src="/assets/images/404.png" />
|
|
26
|
+
404
|
|
27
|
+
</div>
|
|
28
|
+
<div class="description">
|
|
29
|
+
Such request or page not found ☹️
|
|
30
|
+
<a class="link" href="/">
|
|
31
|
+
Return on main page
|
|
32
|
+
</a>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="margin-container">
|
|
37
|
+
<div class="content">
|
|
38
|
+
<div class="content-head">
|
|
39
|
+
<div class="tab-items">
|
|
40
|
+
<% Object.values(api).forEach((variant)=> { %>
|
|
41
|
+
<div id="tab-item-<%=variant%>" class="tab-item">
|
|
42
|
+
<%=variant%>
|
|
43
|
+
</div>
|
|
44
|
+
<% }) %>
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
<div id="tab-content-<%=api.rest%>" class="tab-content">
|
|
48
|
+
<div class="description">
|
|
49
|
+
<% if (restRequestSuggestions.length) { %>
|
|
50
|
+
<span>We searched a bit, maybe this will help you:</span>
|
|
51
|
+
<% restRequestSuggestions.forEach((requestSuggestion) => { %>
|
|
52
|
+
<span><%= requestSuggestion.method.toUpperCase() %> <%=
|
|
53
|
+
requestSuggestion.path %></span>
|
|
54
|
+
<% })} else { %>
|
|
55
|
+
<span>We searched, but found nothing.</span>
|
|
56
|
+
<span>Maybe you don't have <%=api.rest%> configs? 👀</span>
|
|
57
|
+
<a class="link" href="https://github.com/siberiacancode/mock-config-server#configs" rel="noopener noreferrer" target="_blank">
|
|
58
|
+
Read documentation 📘 for more information
|
|
59
|
+
</a>
|
|
60
|
+
<% } %>
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<div id="tab-content-<%=api.graphql%>" class="tab-content">
|
|
65
|
+
<div class="description">
|
|
66
|
+
<% if (graphqlRequestSuggestions.length) { %>
|
|
67
|
+
<span>We searched a bit, maybe this will help you:</span>
|
|
68
|
+
<% graphqlRequestSuggestions.forEach((requestSuggestion) => { %>
|
|
69
|
+
<span><%= requestSuggestion.operationType %> <%=
|
|
70
|
+
requestSuggestion.operationName %></span>
|
|
71
|
+
<% })} else { %>
|
|
72
|
+
<span>We searched, but found nothing.</span>
|
|
73
|
+
<span>Maybe you don't have <%=api.graphql%> configs? 👀</span>
|
|
74
|
+
<a class="link" href="https://github.com/siberiacancode/mock-config-server#configs" rel="noopener noreferrer" target="_blank">
|
|
75
|
+
Read documentation 📘 for more information
|
|
76
|
+
</a>
|
|
77
|
+
<% } %>
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
</body>
|
|
84
|
+
|
|
85
|
+
</html>
|
package/dist/src/utils/helpers/interceptors/callRequestInterceptor/callRequestInterceptor.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Request } from 'express';
|
|
2
|
+
import type { RequestInterceptor } from '../../../types';
|
|
3
|
+
interface CallRequestInterceptorParams {
|
|
4
|
+
request: Request;
|
|
5
|
+
interceptor: RequestInterceptor;
|
|
6
|
+
}
|
|
7
|
+
export declare const callRequestInterceptor: (params: CallRequestInterceptorParams) => Promise<void>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.callRequestInterceptor = void 0;
|
|
4
|
+
const setDelay_1 = require("../helpers/setDelay");
|
|
5
|
+
const callRequestInterceptor = async (params) => {
|
|
6
|
+
const { request, interceptor } = params;
|
|
7
|
+
const getHeader = (field) => request.headers[field];
|
|
8
|
+
const getHeaders = () => request.headers;
|
|
9
|
+
const getCookie = (name) => request.cookies[name];
|
|
10
|
+
const requestInterceptorParams = {
|
|
11
|
+
request,
|
|
12
|
+
setDelay: setDelay_1.setDelay,
|
|
13
|
+
getHeader,
|
|
14
|
+
getHeaders,
|
|
15
|
+
getCookie
|
|
16
|
+
};
|
|
17
|
+
await interceptor(requestInterceptorParams);
|
|
18
|
+
};
|
|
19
|
+
exports.callRequestInterceptor = callRequestInterceptor;
|
package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { Request, Response } from 'express';
|
|
2
|
-
import type { Data,
|
|
2
|
+
import type { Data, ResponseInterceptor } from '../../../types';
|
|
3
3
|
interface CallResponseInterceptorsParams {
|
|
4
4
|
data: Data;
|
|
5
5
|
request: Request;
|
|
6
6
|
response: Response;
|
|
7
7
|
interceptors?: {
|
|
8
|
-
routeInterceptor?:
|
|
9
|
-
requestInterceptor?:
|
|
10
|
-
|
|
8
|
+
routeInterceptor?: ResponseInterceptor;
|
|
9
|
+
requestInterceptor?: ResponseInterceptor;
|
|
10
|
+
apiInterceptor?: ResponseInterceptor;
|
|
11
|
+
serverInterceptor?: ResponseInterceptor;
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
|
-
export declare const callResponseInterceptors: (params: CallResponseInterceptorsParams) => Data
|
|
14
|
+
export declare const callResponseInterceptors: (params: CallResponseInterceptorsParams) => Promise<Data>;
|
|
14
15
|
export {};
|
package/dist/src/utils/helpers/interceptors/callResponseInterceptors/callResponseInterceptors.js
CHANGED
|
@@ -1,54 +1,51 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.callResponseInterceptors = void 0;
|
|
4
|
-
const
|
|
5
|
-
const callResponseInterceptors = (params) => {
|
|
4
|
+
const setDelay_1 = require("../helpers/setDelay");
|
|
5
|
+
const callResponseInterceptors = async (params) => {
|
|
6
6
|
const { data, request, response, interceptors } = params;
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const getHeader = (field) => response.getHeader(field);
|
|
8
|
+
const getHeaders = () => response.getHeaders();
|
|
9
|
+
const getCookie = (name) => request.cookies[name];
|
|
10
10
|
const setStatusCode = (statusCode) => {
|
|
11
11
|
response.statusCode = statusCode;
|
|
12
12
|
};
|
|
13
|
-
const setHeader = (field, value) =>
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
const appendHeader = (field, value) => {
|
|
17
|
-
response.append(field, value);
|
|
18
|
-
};
|
|
13
|
+
const setHeader = (field, value) => response.set(field, value);
|
|
14
|
+
const appendHeader = (field, value) => response.append(field, value);
|
|
19
15
|
const setCookie = (name, value, options) => {
|
|
20
16
|
if (options) {
|
|
21
17
|
response.cookie(name, value, options);
|
|
22
|
-
return;
|
|
23
18
|
}
|
|
24
19
|
response.cookie(name, value);
|
|
25
20
|
};
|
|
26
|
-
const clearCookie = (name, options) =>
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const attachment = (filename) => {
|
|
30
|
-
response.attachment(filename);
|
|
31
|
-
};
|
|
32
|
-
const interceptorResponseParams = {
|
|
21
|
+
const clearCookie = (name, options) => response.clearCookie(name, options);
|
|
22
|
+
const attachment = (filename) => response.attachment(filename);
|
|
23
|
+
const ResponseInterceptorParams = {
|
|
33
24
|
request,
|
|
34
25
|
response,
|
|
35
|
-
setDelay,
|
|
26
|
+
setDelay: setDelay_1.setDelay,
|
|
36
27
|
setStatusCode,
|
|
37
28
|
setHeader,
|
|
38
29
|
appendHeader,
|
|
30
|
+
getHeader,
|
|
31
|
+
getHeaders,
|
|
39
32
|
setCookie,
|
|
33
|
+
getCookie,
|
|
40
34
|
clearCookie,
|
|
41
35
|
attachment
|
|
42
36
|
};
|
|
43
37
|
let updatedData = data;
|
|
44
38
|
if (interceptors?.routeInterceptor) {
|
|
45
|
-
updatedData = interceptors.routeInterceptor(updatedData,
|
|
39
|
+
updatedData = await interceptors.routeInterceptor(updatedData, ResponseInterceptorParams);
|
|
46
40
|
}
|
|
47
41
|
if (interceptors?.requestInterceptor) {
|
|
48
|
-
updatedData = interceptors.requestInterceptor(updatedData,
|
|
42
|
+
updatedData = await interceptors.requestInterceptor(updatedData, ResponseInterceptorParams);
|
|
43
|
+
}
|
|
44
|
+
if (interceptors?.apiInterceptor) {
|
|
45
|
+
updatedData = await interceptors.apiInterceptor(updatedData, ResponseInterceptorParams);
|
|
49
46
|
}
|
|
50
47
|
if (interceptors?.serverInterceptor) {
|
|
51
|
-
updatedData = interceptors.serverInterceptor(updatedData,
|
|
48
|
+
updatedData = await interceptors.serverInterceptor(updatedData, ResponseInterceptorParams);
|
|
52
49
|
}
|
|
53
50
|
return updatedData;
|
|
54
51
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const setDelay: (delay: number) => Promise<void>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setDelay = void 0;
|
|
4
|
+
const sleep_1 = require("../../sleep");
|
|
5
|
+
const setDelay = async (delay) => {
|
|
6
|
+
await (0, sleep_1.sleep)(delay === Infinity ? 99999999 : delay);
|
|
7
|
+
};
|
|
8
|
+
exports.setDelay = setDelay;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './callRequestInterceptor/callRequestInterceptor';
|
|
2
2
|
export * from './callResponseInterceptors/callResponseInterceptors';
|
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./callRequestInterceptor/callRequestInterceptor"), exports);
|
|
18
18
|
__exportStar(require("./callResponseInterceptors/callResponseInterceptors"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const sleep: (
|
|
1
|
+
export declare const sleep: (milliseconds: number) => Promise<unknown>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sleep = void 0;
|
|
4
|
-
const sleep = (
|
|
5
|
-
setTimeout(resolve,
|
|
4
|
+
const sleep = (milliseconds) => new Promise((resolve) => {
|
|
5
|
+
setTimeout(resolve, milliseconds);
|
|
6
6
|
});
|
|
7
7
|
exports.sleep = sleep;
|
|
@@ -6,7 +6,7 @@ export interface GraphQLInput {
|
|
|
6
6
|
query?: string;
|
|
7
7
|
variables: GraphQLVariables;
|
|
8
8
|
}
|
|
9
|
-
export type GraphQLEntities = 'headers' | 'query' | 'variables';
|
|
9
|
+
export type GraphQLEntities = 'headers' | 'cookies' | 'query' | 'variables';
|
|
10
10
|
export type GraphQLEntitiesValues = {
|
|
11
11
|
[Key in GraphQLEntities]: Key extends 'variables' ? VariablesValue : PlainObject;
|
|
12
12
|
};
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import type { CookieOptions, Request, Response } from 'express';
|
|
2
|
-
export
|
|
2
|
+
export type RequestInterceptorCookieValue = string | undefined;
|
|
3
|
+
export type RequestInterceptorHeaderValue = string | number | string[] | undefined;
|
|
4
|
+
export interface RequestInterceptorParams {
|
|
3
5
|
request: Request;
|
|
6
|
+
setDelay: (delay: number) => Promise<void>;
|
|
7
|
+
getCookie: (name: string) => RequestInterceptorCookieValue;
|
|
8
|
+
getHeader: (field: string) => RequestInterceptorHeaderValue;
|
|
9
|
+
getHeaders: () => Record<string, RequestInterceptorHeaderValue>;
|
|
4
10
|
}
|
|
5
|
-
export type
|
|
6
|
-
export interface
|
|
11
|
+
export type RequestInterceptor = (params: RequestInterceptorParams) => void;
|
|
12
|
+
export interface ResponseInterceptorParams {
|
|
7
13
|
request: Request;
|
|
8
14
|
response: Response;
|
|
9
15
|
setDelay: (delay: number) => Promise<void>;
|
|
10
16
|
setStatusCode: (statusCode: number) => void;
|
|
11
17
|
setHeader: (field: string, value?: string | string[]) => void;
|
|
12
18
|
appendHeader: (field: string, value?: string[] | string) => void;
|
|
19
|
+
getHeader: (field: string) => RequestInterceptorHeaderValue;
|
|
20
|
+
getHeaders: () => Record<string, RequestInterceptorHeaderValue>;
|
|
13
21
|
setCookie: (name: string, value: string, options?: CookieOptions) => void;
|
|
22
|
+
getCookie: (name: string) => RequestInterceptorCookieValue;
|
|
14
23
|
clearCookie: (name: string, options?: CookieOptions) => void;
|
|
15
24
|
attachment: (filename: string) => void;
|
|
16
25
|
}
|
|
17
|
-
export type
|
|
26
|
+
export type ResponseInterceptor<Data extends any = any> = (data: Data, params: ResponseInterceptorParams) => any;
|
|
18
27
|
export interface Interceptors {
|
|
19
|
-
request?:
|
|
20
|
-
response?:
|
|
28
|
+
request?: RequestInterceptor;
|
|
29
|
+
response?: ResponseInterceptor;
|
|
21
30
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import type { Request } from 'express';
|
|
2
2
|
import type { Interceptors } from './interceptors';
|
|
3
|
-
import type { BodyValue, Data, HeadersValue, ParamsValue, QueryValue } from './values';
|
|
4
|
-
export type RestEntities = 'headers' | 'query' | 'params' | 'body';
|
|
5
|
-
export type RestEntitiesValue = BodyValue | QueryValue | HeadersValue | ParamsValue;
|
|
3
|
+
import type { BodyValue, CookiesValue, Data, HeadersValue, ParamsValue, QueryValue } from './values';
|
|
4
|
+
export type RestEntities = 'headers' | 'cookies' | 'query' | 'params' | 'body';
|
|
5
|
+
export type RestEntitiesValue = BodyValue | QueryValue | HeadersValue | CookiesValue | ParamsValue;
|
|
6
6
|
export type RestEntitiesValues = {
|
|
7
|
-
[Key in RestEntities]: Key extends 'body' ? BodyValue : Key extends 'query' ? QueryValue : Key extends 'headers' ? HeadersValue : Key extends 'params' ? ParamsValue : never;
|
|
7
|
+
[Key in RestEntities]: Key extends 'body' ? BodyValue : Key extends 'query' ? QueryValue : Key extends 'headers' ? HeadersValue : Key extends 'cookies' ? CookiesValue : Key extends 'params' ? ParamsValue : never;
|
|
8
8
|
};
|
|
9
9
|
export interface RestMethodsEntities {
|
|
10
|
-
get:
|
|
11
|
-
delete:
|
|
10
|
+
get: Exclude<RestEntities, 'body'>;
|
|
11
|
+
delete: Exclude<RestEntities, 'body'>;
|
|
12
12
|
post: RestEntities;
|
|
13
13
|
put: RestEntities;
|
|
14
14
|
patch: RestEntities;
|
|
15
|
-
options:
|
|
15
|
+
options: Exclude<RestEntities, 'body'>;
|
|
16
16
|
}
|
|
17
17
|
export type RestRouteConfigEntities<Method extends RestMethod> = {
|
|
18
18
|
[Key in RestMethodsEntities[Method]]?: RestEntitiesValues[Key];
|
|
@@ -23,8 +23,9 @@ export interface RestRouteConfig<Method extends RestMethod, Entities extends Res
|
|
|
23
23
|
interceptors?: Pick<Interceptors, 'response'>;
|
|
24
24
|
}
|
|
25
25
|
export type RestMethod = 'get' | 'post' | 'delete' | 'put' | 'patch' | 'options';
|
|
26
|
+
export type RestPathString = `/${string}`;
|
|
26
27
|
export interface BaseRestRequestConfig<Method extends RestMethod> {
|
|
27
|
-
path:
|
|
28
|
+
path: RestPathString | RegExp;
|
|
28
29
|
method: Method;
|
|
29
30
|
routes: RestRouteConfig<Method>[];
|
|
30
31
|
interceptors?: Interceptors;
|
|
@@ -19,19 +19,29 @@ export type Cors = {
|
|
|
19
19
|
};
|
|
20
20
|
export type Port = number;
|
|
21
21
|
export type BaseUrl = `/${string}`;
|
|
22
|
+
export interface RestConfig {
|
|
23
|
+
baseUrl?: BaseUrl;
|
|
24
|
+
configs: RestRequestConfig[];
|
|
25
|
+
interceptors?: Interceptors;
|
|
26
|
+
}
|
|
27
|
+
export interface GraphqlConfig {
|
|
28
|
+
baseUrl?: BaseUrl;
|
|
29
|
+
configs: GraphQLRequestConfig[];
|
|
30
|
+
interceptors?: Interceptors;
|
|
31
|
+
}
|
|
22
32
|
export interface MockServerConfig {
|
|
23
33
|
baseUrl?: BaseUrl;
|
|
24
|
-
rest?:
|
|
25
|
-
|
|
26
|
-
configs: RestRequestConfig[];
|
|
27
|
-
};
|
|
28
|
-
graphql?: {
|
|
29
|
-
baseUrl?: BaseUrl;
|
|
30
|
-
configs: GraphQLRequestConfig[];
|
|
31
|
-
};
|
|
34
|
+
rest?: RestConfig;
|
|
35
|
+
graphql?: GraphqlConfig;
|
|
32
36
|
port?: Port;
|
|
33
37
|
staticPath?: StaticPath;
|
|
34
38
|
interceptors?: Interceptors;
|
|
35
39
|
cors?: Cors;
|
|
36
40
|
}
|
|
37
|
-
export
|
|
41
|
+
export interface MockServerConfigArgv {
|
|
42
|
+
baseUrl?: string;
|
|
43
|
+
port?: number;
|
|
44
|
+
staticPath?: string;
|
|
45
|
+
config?: string;
|
|
46
|
+
watch?: boolean;
|
|
47
|
+
}
|
|
@@ -5,5 +5,6 @@ export type BodyValue = any;
|
|
|
5
5
|
export type VariablesValue = any;
|
|
6
6
|
export type QueryValue = ParsedQs;
|
|
7
7
|
export type HeadersValue = Record<string, string>;
|
|
8
|
+
export type CookiesValue = Record<string, string>;
|
|
8
9
|
export type ParamsValue = Record<string, string>;
|
|
9
10
|
export type Data = boolean | number | string | any[] | Record<any, any> | null | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mock-config-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "Tool that easily and quickly imitates server operation, create full fake api in few steps",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SIBERIA CAN CODE 🧊",
|
|
@@ -41,10 +41,12 @@
|
|
|
41
41
|
"test": "jest",
|
|
42
42
|
"type": "tsc --noEmit",
|
|
43
43
|
"lint": "eslint . --ext ts --no-error-on-unmatched-pattern",
|
|
44
|
+
"stylelint": "stylelint \"src/static/**/*.css\"",
|
|
44
45
|
"format": "prettier --write {src,bin}/**/*.ts",
|
|
45
46
|
"pretty": "yarn type && yarn format && yarn lint --fix"
|
|
46
47
|
},
|
|
47
48
|
"lint-staged": {
|
|
49
|
+
"*.css": "yarn stylelint",
|
|
48
50
|
"*.js": "yarn format",
|
|
49
51
|
"*.ts": "yarn pretty"
|
|
50
52
|
},
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
"@types/yargs": "^17.0.24",
|
|
56
58
|
"ansi-colors": "^4.1.3",
|
|
57
59
|
"body-parser": "^1.20.0",
|
|
58
|
-
"ejs": "^3.1.
|
|
60
|
+
"ejs": "^3.1.9",
|
|
59
61
|
"esbuild": "^0.17.8",
|
|
60
62
|
"express": "^4.18.1",
|
|
61
63
|
"flat": "^5.0.2",
|
|
@@ -76,6 +78,11 @@
|
|
|
76
78
|
"eslint-import-resolver-typescript": "^3.4.1",
|
|
77
79
|
"eslint-plugin-import": "^2.27.5",
|
|
78
80
|
"eslint-plugin-prettier": "^4.2.1",
|
|
81
|
+
"style-loader": "^3.3.2",
|
|
82
|
+
"stylelint": "^15.6.1",
|
|
83
|
+
"stylelint-config-prettier": "^9.0.5",
|
|
84
|
+
"stylelint-config-standard": "^32.0.0",
|
|
85
|
+
"stylelint-order": "^6.0.3",
|
|
79
86
|
"husky": "^8.0.1",
|
|
80
87
|
"jest": "^29.4.2",
|
|
81
88
|
"lint-staged": "^13.1.1",
|
package/dist/bin/start.d.ts
DELETED
package/dist/bin/start.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.start = void 0;
|
|
28
|
-
const fs = __importStar(require("fs"));
|
|
29
|
-
const esbuild_1 = require("esbuild");
|
|
30
|
-
const server_1 = require("../src/server");
|
|
31
|
-
const helpers_1 = require("../src/utils/helpers");
|
|
32
|
-
const resolveExportsFromSourceCode_1 = require("./resolveExportsFromSourceCode/resolveExportsFromSourceCode");
|
|
33
|
-
const validateMockServerConfig_1 = require("./validateMockServerConfig/validateMockServerConfig");
|
|
34
|
-
const start = async (argv) => {
|
|
35
|
-
try {
|
|
36
|
-
const appPath = process.cwd();
|
|
37
|
-
const mockServerConfigFileRegex = /mock-server.config.(?:ts|js)/;
|
|
38
|
-
const mockServerConfigFile = fs
|
|
39
|
-
.readdirSync(appPath)
|
|
40
|
-
.find((file) => mockServerConfigFileRegex.test(file));
|
|
41
|
-
if (!mockServerConfigFile) {
|
|
42
|
-
throw new Error('Cannot find config file mock-server.config.(ts|js)');
|
|
43
|
-
}
|
|
44
|
-
const { outputFiles } = await (0, esbuild_1.build)({
|
|
45
|
-
entryPoints: [mockServerConfigFile],
|
|
46
|
-
bundle: true,
|
|
47
|
-
platform: 'node',
|
|
48
|
-
target: 'esnext',
|
|
49
|
-
minifySyntax: true,
|
|
50
|
-
minify: true,
|
|
51
|
-
write: false,
|
|
52
|
-
metafile: false
|
|
53
|
-
});
|
|
54
|
-
const mockServerConfigSourceCode = outputFiles[0]?.text;
|
|
55
|
-
if (!mockServerConfigSourceCode) {
|
|
56
|
-
throw new Error('Cannot handle source code of mock-server.config.(ts|js)');
|
|
57
|
-
}
|
|
58
|
-
const mockServerConfigExports = (0, resolveExportsFromSourceCode_1.resolveExportsFromSourceCode)(mockServerConfigSourceCode);
|
|
59
|
-
if (!mockServerConfigExports?.default) {
|
|
60
|
-
throw new Error('Cannot handle exports of mock-server.config.(ts|js)');
|
|
61
|
-
}
|
|
62
|
-
if (!(0, helpers_1.isPlainObject)(mockServerConfigExports.default)) {
|
|
63
|
-
throw new Error('configuration should be plain object; see our doc (https://www.npmjs.com/package/mock-config-server) for more information');
|
|
64
|
-
}
|
|
65
|
-
const mergedMockServerConfig = { ...mockServerConfigExports.default, ...argv };
|
|
66
|
-
(0, validateMockServerConfig_1.validateMockServerConfig)(mergedMockServerConfig);
|
|
67
|
-
(0, server_1.startMockServer)(mergedMockServerConfig);
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
console.error(error.message);
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
exports.start = start;
|