@furystack/rest-service 6.2.23 → 7.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/package.json +29 -12
- package/src/actions/error-action.spec.ts +1 -0
- package/src/actions/get-current-user.spec.ts +1 -0
- package/src/actions/get-current-user.ts +0 -1
- package/src/actions/is-authenticated.spec.ts +1 -0
- package/src/actions/is-authenticated.ts +0 -1
- package/src/actions/login-action.spec.ts +3 -2
- package/src/actions/logout-action.spec.ts +2 -1
- package/src/actions/logout.ts +0 -1
- package/src/actions/not-found-action.spec.ts +1 -0
- package/src/add-cors-header.spec.ts +7 -6
- package/src/authenticate.spec.ts +7 -6
- package/src/authorize.spec.ts +7 -6
- package/src/endpoint-generators/create-delete-endpoint.spec.ts +1 -0
- package/src/endpoint-generators/create-delete-endpoint.ts +0 -1
- package/src/endpoint-generators/create-get-collection-endpoint.spec.ts +1 -0
- package/src/endpoint-generators/create-get-collection-endpoint.ts +0 -1
- package/src/endpoint-generators/create-get-entity-endpoint.spec.ts +1 -0
- package/src/endpoint-generators/create-get-entity-endpoint.ts +0 -1
- package/src/endpoint-generators/create-patch-endpoint.spec.ts +1 -0
- package/src/endpoint-generators/create-patch-endpoint.ts +0 -1
- package/src/endpoint-generators/create-post-endpoint.spec.ts +1 -0
- package/src/endpoint-generators/create-post-endpoint.ts +0 -1
- package/src/helpers.spec.ts +1 -0
- package/src/helpers.ts +2 -6
- package/src/http-user-context.spec.ts +15 -14
- package/src/http-user-context.ts +0 -3
- package/src/incoming-message-extensions.spec.ts +1 -0
- package/src/mime-types.spec.ts +1 -0
- package/src/rest-service.integration.spec.ts +1 -0
- package/src/rest.integration.test.ts +1 -0
- package/src/schema-validator/schema-validator.test.ts +1 -0
- package/src/server-manager.ts +2 -2
- package/src/server-response-extensions.spec.ts +23 -18
- package/src/static-server-manager.spec.ts +2 -2
- package/src/utils.ts +0 -2
- package/src/validate.integration.spec.ts +1 -0
- package/types/actions/get-current-user.d.ts +0 -1
- package/types/actions/get-current-user.d.ts.map +1 -1
- package/types/actions/is-authenticated.d.ts +0 -1
- package/types/actions/is-authenticated.d.ts.map +1 -1
- package/types/actions/logout.d.ts +0 -1
- package/types/actions/logout.d.ts.map +1 -1
- package/types/endpoint-generators/create-delete-endpoint.d.ts +0 -1
- package/types/endpoint-generators/create-delete-endpoint.d.ts.map +1 -1
- package/types/endpoint-generators/create-get-collection-endpoint.d.ts +0 -1
- package/types/endpoint-generators/create-get-collection-endpoint.d.ts.map +1 -1
- package/types/endpoint-generators/create-get-entity-endpoint.d.ts +0 -1
- package/types/endpoint-generators/create-get-entity-endpoint.d.ts.map +1 -1
- package/types/endpoint-generators/create-patch-endpoint.d.ts +0 -1
- package/types/endpoint-generators/create-patch-endpoint.d.ts.map +1 -1
- package/types/endpoint-generators/create-post-endpoint.d.ts +0 -1
- package/types/endpoint-generators/create-post-endpoint.d.ts.map +1 -1
- package/types/helpers.d.ts +2 -4
- package/types/helpers.d.ts.map +1 -1
- package/types/http-user-context.d.ts +0 -3
- package/types/http-user-context.d.ts.map +1 -1
- package/types/server-manager.d.ts.map +1 -1
- package/types/utils.d.ts +0 -2
- package/types/utils.d.ts.map +1 -1
- package/dist/actions/error-action.js +0 -29
- package/dist/actions/error-action.js.map +0 -1
- package/dist/actions/error-action.spec.js +0 -48
- package/dist/actions/error-action.spec.js.map +0 -1
- package/dist/actions/get-current-user.js +0 -16
- package/dist/actions/get-current-user.js.map +0 -1
- package/dist/actions/get-current-user.spec.js +0 -20
- package/dist/actions/get-current-user.spec.js.map +0 -1
- package/dist/actions/index.js +0 -23
- package/dist/actions/index.js.map +0 -1
- package/dist/actions/is-authenticated.js +0 -18
- package/dist/actions/is-authenticated.js.map +0 -1
- package/dist/actions/is-authenticated.spec.js +0 -19
- package/dist/actions/is-authenticated.spec.js.map +0 -1
- package/dist/actions/login-action.spec.js +0 -35
- package/dist/actions/login-action.spec.js.map +0 -1
- package/dist/actions/login.js +0 -26
- package/dist/actions/login.js.map +0 -1
- package/dist/actions/logout-action.spec.js +0 -23
- package/dist/actions/logout-action.spec.js.map +0 -1
- package/dist/actions/logout.js +0 -20
- package/dist/actions/logout.js.map +0 -1
- package/dist/actions/not-found-action.js +0 -14
- package/dist/actions/not-found-action.js.map +0 -1
- package/dist/actions/not-found-action.spec.js +0 -17
- package/dist/actions/not-found-action.spec.js.map +0 -1
- package/dist/add-cors-header.spec.js +0 -99
- package/dist/add-cors-header.spec.js.map +0 -1
- package/dist/api-manager.js +0 -156
- package/dist/api-manager.js.map +0 -1
- package/dist/authenticate.js +0 -20
- package/dist/authenticate.js.map +0 -1
- package/dist/authenticate.spec.js +0 -59
- package/dist/authenticate.spec.js.map +0 -1
- package/dist/authorize.js +0 -23
- package/dist/authorize.js.map +0 -1
- package/dist/authorize.spec.js +0 -55
- package/dist/authorize.spec.js.map +0 -1
- package/dist/endpoint-generators/create-delete-endpoint.js +0 -25
- package/dist/endpoint-generators/create-delete-endpoint.js.map +0 -1
- package/dist/endpoint-generators/create-delete-endpoint.spec.js +0 -35
- package/dist/endpoint-generators/create-delete-endpoint.spec.js.map +0 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.js +0 -27
- package/dist/endpoint-generators/create-get-collection-endpoint.js.map +0 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js +0 -157
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js.map +0 -1
- package/dist/endpoint-generators/create-get-entity-endpoint.js +0 -30
- package/dist/endpoint-generators/create-get-entity-endpoint.js.map +0 -1
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js +0 -75
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js.map +0 -1
- package/dist/endpoint-generators/create-patch-endpoint.js +0 -27
- package/dist/endpoint-generators/create-patch-endpoint.js.map +0 -1
- package/dist/endpoint-generators/create-patch-endpoint.spec.js +0 -38
- package/dist/endpoint-generators/create-patch-endpoint.spec.js.map +0 -1
- package/dist/endpoint-generators/create-post-endpoint.js +0 -30
- package/dist/endpoint-generators/create-post-endpoint.js.map +0 -1
- package/dist/endpoint-generators/create-post-endpoint.spec.js +0 -36
- package/dist/endpoint-generators/create-post-endpoint.spec.js.map +0 -1
- package/dist/endpoint-generators/index.js +0 -22
- package/dist/endpoint-generators/index.js.map +0 -1
- package/dist/endpoint-generators/utils.js +0 -28
- package/dist/endpoint-generators/utils.js.map +0 -1
- package/dist/helpers.js +0 -39
- package/dist/helpers.js.map +0 -1
- package/dist/helpers.spec.js +0 -35
- package/dist/helpers.spec.js.map +0 -1
- package/dist/http-authentication-settings.js +0 -29
- package/dist/http-authentication-settings.js.map +0 -1
- package/dist/http-user-context.js +0 -174
- package/dist/http-user-context.js.map +0 -1
- package/dist/http-user-context.spec.js +0 -272
- package/dist/http-user-context.spec.js.map +0 -1
- package/dist/incoming-message-extensions.js +0 -16
- package/dist/incoming-message-extensions.js.map +0 -1
- package/dist/incoming-message-extensions.spec.js +0 -39
- package/dist/incoming-message-extensions.spec.js.map +0 -1
- package/dist/index.js +0 -35
- package/dist/index.js.map +0 -1
- package/dist/mime-types.js +0 -340
- package/dist/mime-types.js.map +0 -1
- package/dist/mime-types.spec.js +0 -15
- package/dist/mime-types.spec.js.map +0 -1
- package/dist/models/cors-options.js +0 -3
- package/dist/models/cors-options.js.map +0 -1
- package/dist/models/default-session.js +0 -10
- package/dist/models/default-session.js.map +0 -1
- package/dist/models/index.js +0 -19
- package/dist/models/index.js.map +0 -1
- package/dist/request-action-implementation.js +0 -42
- package/dist/request-action-implementation.js.map +0 -1
- package/dist/rest-service.integration.spec.js +0 -143
- package/dist/rest-service.integration.spec.js.map +0 -1
- package/dist/rest.integration.test.js +0 -156
- package/dist/rest.integration.test.js.map +0 -1
- package/dist/schema-validator/index.js +0 -19
- package/dist/schema-validator/index.js.map +0 -1
- package/dist/schema-validator/schema-validation-error.js +0 -15
- package/dist/schema-validator/schema-validation-error.js.map +0 -1
- package/dist/schema-validator/schema-validator.js +0 -38
- package/dist/schema-validator/schema-validator.js.map +0 -1
- package/dist/schema-validator/schema-validator.test.js +0 -62
- package/dist/schema-validator/schema-validator.test.js.map +0 -1
- package/dist/schema-validator/validate-examples.js +0 -29
- package/dist/schema-validator/validate-examples.js.map +0 -1
- package/dist/server-manager.js +0 -79
- package/dist/server-manager.js.map +0 -1
- package/dist/server-response-extensions.js +0 -17
- package/dist/server-response-extensions.js.map +0 -1
- package/dist/server-response-extensions.spec.js +0 -49
- package/dist/server-response-extensions.spec.js.map +0 -1
- package/dist/static-server-manager.js +0 -71
- package/dist/static-server-manager.js.map +0 -1
- package/dist/static-server-manager.spec.js +0 -218
- package/dist/static-server-manager.spec.js.map +0 -1
- package/dist/utils.js +0 -75
- package/dist/utils.js.map +0 -1
- package/dist/validate.integration.schema.js +0 -3
- package/dist/validate.integration.schema.js.map +0 -1
- package/dist/validate.integration.spec.js +0 -216
- package/dist/validate.integration.spec.js.map +0 -1
- package/dist/validate.integration.spec.schema.json +0 -903
- package/dist/validate.js +0 -47
- package/dist/validate.js.map +0 -1
- package/types/actions/error-action.spec.d.ts +0 -2
- package/types/actions/error-action.spec.d.ts.map +0 -1
- package/types/actions/get-current-user.spec.d.ts +0 -2
- package/types/actions/get-current-user.spec.d.ts.map +0 -1
- package/types/actions/is-authenticated.spec.d.ts +0 -2
- package/types/actions/is-authenticated.spec.d.ts.map +0 -1
- package/types/actions/login-action.spec.d.ts +0 -2
- package/types/actions/login-action.spec.d.ts.map +0 -1
- package/types/actions/logout-action.spec.d.ts +0 -2
- package/types/actions/logout-action.spec.d.ts.map +0 -1
- package/types/actions/not-found-action.spec.d.ts +0 -2
- package/types/actions/not-found-action.spec.d.ts.map +0 -1
- package/types/add-cors-header.spec.d.ts +0 -2
- package/types/add-cors-header.spec.d.ts.map +0 -1
- package/types/authenticate.spec.d.ts +0 -2
- package/types/authenticate.spec.d.ts.map +0 -1
- package/types/authorize.spec.d.ts +0 -2
- package/types/authorize.spec.d.ts.map +0 -1
- package/types/endpoint-generators/create-delete-endpoint.spec.d.ts +0 -2
- package/types/endpoint-generators/create-delete-endpoint.spec.d.ts.map +0 -1
- package/types/endpoint-generators/create-get-collection-endpoint.spec.d.ts +0 -2
- package/types/endpoint-generators/create-get-collection-endpoint.spec.d.ts.map +0 -1
- package/types/endpoint-generators/create-get-entity-endpoint.spec.d.ts +0 -2
- package/types/endpoint-generators/create-get-entity-endpoint.spec.d.ts.map +0 -1
- package/types/endpoint-generators/create-patch-endpoint.spec.d.ts +0 -2
- package/types/endpoint-generators/create-patch-endpoint.spec.d.ts.map +0 -1
- package/types/endpoint-generators/create-post-endpoint.spec.d.ts +0 -2
- package/types/endpoint-generators/create-post-endpoint.spec.d.ts.map +0 -1
- package/types/helpers.spec.d.ts +0 -2
- package/types/helpers.spec.d.ts.map +0 -1
- package/types/http-user-context.spec.d.ts +0 -3
- package/types/http-user-context.spec.d.ts.map +0 -1
- package/types/incoming-message-extensions.spec.d.ts +0 -2
- package/types/incoming-message-extensions.spec.d.ts.map +0 -1
- package/types/mime-types.spec.d.ts +0 -2
- package/types/mime-types.spec.d.ts.map +0 -1
- package/types/rest-service.integration.spec.d.ts +0 -2
- package/types/rest-service.integration.spec.d.ts.map +0 -1
- package/types/rest.integration.test.d.ts +0 -90
- package/types/rest.integration.test.d.ts.map +0 -1
- package/types/schema-validator/schema-validator.test.d.ts +0 -2
- package/types/schema-validator/schema-validator.test.d.ts.map +0 -1
- package/types/server-response-extensions.spec.d.ts +0 -2
- package/types/server-response-extensions.spec.d.ts.map +0 -1
- package/types/static-server-manager.spec.d.ts +0 -2
- package/types/static-server-manager.spec.d.ts.map +0 -1
- package/types/validate.integration.spec.d.ts +0 -2
- package/types/validate.integration.spec.d.ts.map +0 -1
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const inject_1 = require("@furystack/inject");
|
|
4
|
-
require("./helpers");
|
|
5
|
-
const utils_1 = require("@furystack/utils");
|
|
6
|
-
const actions_1 = require("./actions");
|
|
7
|
-
const core_1 = require("@furystack/core");
|
|
8
|
-
const default_session_1 = require("./models/default-session");
|
|
9
|
-
const request_action_implementation_1 = require("./request-action-implementation");
|
|
10
|
-
const helpers_1 = require("./helpers");
|
|
11
|
-
class UserWithPassword extends core_1.User {
|
|
12
|
-
}
|
|
13
|
-
const port = 19090;
|
|
14
|
-
const hostName = 'localhost';
|
|
15
|
-
const root = 'test-api';
|
|
16
|
-
const prepareInjector = async (i) => {
|
|
17
|
-
(0, core_1.addStore)(i, new core_1.InMemoryStore({ model: core_1.User, primaryKey: 'username' })).addStore(new core_1.InMemoryStore({ model: default_session_1.DefaultSession, primaryKey: 'sessionId' }));
|
|
18
|
-
(0, helpers_1.useHttpAuthentication)(i, {
|
|
19
|
-
getUserStore: (sm) => sm.getStoreFor(UserWithPassword, 'username'),
|
|
20
|
-
getSessionStore: (sm) => sm.getStoreFor(default_session_1.DefaultSession, 'sessionId'),
|
|
21
|
-
});
|
|
22
|
-
await (0, helpers_1.useRestService)({
|
|
23
|
-
injector: i,
|
|
24
|
-
root,
|
|
25
|
-
port,
|
|
26
|
-
hostName,
|
|
27
|
-
cors: {
|
|
28
|
-
credentials: true,
|
|
29
|
-
origins: ['http://localhost:8080'],
|
|
30
|
-
headers: ['cache', 'content-type'],
|
|
31
|
-
},
|
|
32
|
-
api: {
|
|
33
|
-
GET: {
|
|
34
|
-
'/currentUser': actions_1.GetCurrentUser,
|
|
35
|
-
'/isAuthenticated': actions_1.IsAuthenticated,
|
|
36
|
-
'/testQuery': async (options) => (0, request_action_implementation_1.JsonResult)({ param1Value: options.getQuery().param1 }),
|
|
37
|
-
'/testUrlParams/:urlParam': async (options) => (0, request_action_implementation_1.JsonResult)({ urlParamValue: options.getUrlParams().urlParam }),
|
|
38
|
-
},
|
|
39
|
-
POST: {
|
|
40
|
-
'/login': actions_1.LoginAction,
|
|
41
|
-
'/logout': actions_1.LogoutAction,
|
|
42
|
-
'/testPostBody': async (options) => {
|
|
43
|
-
const body = await options.getBody();
|
|
44
|
-
const body2 = await options.getBody();
|
|
45
|
-
return (0, request_action_implementation_1.JsonResult)({ bodyValue: body.value, body2Value: body2.value });
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
const apiUrl = utils_1.PathHelper.joinPaths(`http://${hostName}:${port}`, root);
|
|
52
|
-
describe('@furystack/rest-service inregration tests', () => {
|
|
53
|
-
it('Should be started and disposed', async () => {
|
|
54
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
55
|
-
await prepareInjector(i);
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
it('Should respond with 404 when a route is not found', async () => {
|
|
59
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
60
|
-
await prepareInjector(i);
|
|
61
|
-
const result = await fetch(utils_1.PathHelper.joinPaths(apiUrl, 'some-route-that-does-not-exists'));
|
|
62
|
-
expect(result.ok).toBe(false);
|
|
63
|
-
expect(result.status).toBe(404);
|
|
64
|
-
const responseText = await result.json();
|
|
65
|
-
expect(responseText).toEqual({ error: 'Content not found' });
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
it('Should respond with 401 for unauthorized request errors', async () => {
|
|
69
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
70
|
-
await prepareInjector(i);
|
|
71
|
-
const result = await fetch(utils_1.PathHelper.joinPaths(apiUrl, 'currentUser'));
|
|
72
|
-
expect(result.ok).toBe(false);
|
|
73
|
-
expect(result.status).toBe(401);
|
|
74
|
-
const responseText = await result.json();
|
|
75
|
-
expect(responseText).toEqual({ error: 'unauthorized' });
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
it('Should respond with 401 for unauthorized request errors', async () => {
|
|
79
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
80
|
-
await prepareInjector(i);
|
|
81
|
-
const result = await fetch(utils_1.PathHelper.joinPaths(apiUrl, 'currentUser'));
|
|
82
|
-
expect(result.ok).toBe(false);
|
|
83
|
-
expect(result.status).toBe(401);
|
|
84
|
-
const responseText = await result.json();
|
|
85
|
-
expect(responseText).toEqual({ error: 'unauthorized' });
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
it('Should respond with the correct result body', async () => {
|
|
89
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
90
|
-
await prepareInjector(i);
|
|
91
|
-
const response = await fetch(utils_1.PathHelper.joinPaths(apiUrl, 'isAuthenticated'));
|
|
92
|
-
expect(response.status).toBe(200);
|
|
93
|
-
const result = await response.json();
|
|
94
|
-
expect(result).toEqual({ isAuthenticated: false });
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
it('Should be able to read query parameters', async () => {
|
|
98
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
99
|
-
await prepareInjector(i);
|
|
100
|
-
const response = await fetch(utils_1.PathHelper.joinPaths(apiUrl, 'testQuery?param1=foo'));
|
|
101
|
-
expect(response.status).toBe(200);
|
|
102
|
-
const result = await response.json();
|
|
103
|
-
expect(result).toEqual({ param1Value: 'foo' });
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
it('Should be able to read url parameters', async () => {
|
|
107
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
108
|
-
await prepareInjector(i);
|
|
109
|
-
const response = await fetch(utils_1.PathHelper.joinPaths(apiUrl, 'testUrlParams/bar'));
|
|
110
|
-
expect(response.status).toBe(200);
|
|
111
|
-
const result = await response.json();
|
|
112
|
-
expect(result).toEqual({ urlParamValue: 'bar' });
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
it('Should be able to read post body', async () => {
|
|
116
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
117
|
-
await prepareInjector(i);
|
|
118
|
-
const response = await fetch(utils_1.PathHelper.joinPaths(apiUrl, 'testPostBody'), {
|
|
119
|
-
method: 'POST',
|
|
120
|
-
body: JSON.stringify({ value: 'baz' }),
|
|
121
|
-
});
|
|
122
|
-
expect(response.status).toBe(200);
|
|
123
|
-
const result = await response.json();
|
|
124
|
-
expect(result).toEqual({ bodyValue: 'baz', body2Value: 'baz' });
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
it('Should respond with OK to OPTIONS requests', async () => {
|
|
128
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
129
|
-
await prepareInjector(i);
|
|
130
|
-
const response = await fetch(utils_1.PathHelper.joinPaths(apiUrl, 'testPostBody'), {
|
|
131
|
-
method: 'OPTIONS',
|
|
132
|
-
});
|
|
133
|
-
expect(response.status).toBe(200);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
it('Should reject requests outside of the API Root', async () => {
|
|
137
|
-
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (i) => {
|
|
138
|
-
await prepareInjector(i);
|
|
139
|
-
await expect(fetch(utils_1.PathHelper.joinPaths(`http://${hostName}:${port}`, 'not-my-api-root'))).rejects.toThrowError('fetch failed');
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
//# sourceMappingURL=rest-service.integration.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rest-service.integration.spec.js","sourceRoot":"","sources":["../src/rest-service.integration.spec.ts"],"names":[],"mappings":";;AAAA,8CAA4C;AAC5C,qBAAkB;AAClB,4CAAyD;AACzD,uCAAsF;AAEtF,0CAA+D;AAC/D,8DAAyD;AACzD,mFAA4D;AAC5D,uCAAiE;AAEjE,MAAM,gBAAiB,SAAQ,WAAI;CAElC;AAgBD,MAAM,IAAI,GAAG,KAAK,CAAA;AAClB,MAAM,QAAQ,GAAG,WAAW,CAAA;AAC5B,MAAM,IAAI,GAAG,UAAU,CAAA;AAEvB,MAAM,eAAe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OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAA;QACjE,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;QAC1D,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,MAAM,eAAe,CAAC,CAAC,CAAC,CAAA;YACxB,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,kBAAU,CAAC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE;gBACzE,MAAM,EAAE,SAAS;aAClB,CAAC,CAAA;YACF,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACnC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,gDAAgD,EAAE,KAAK,IAAI,EAAE;QAC9D,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;YAC3C,MAAM,eAAe,CAAC,CAAC,CAAC,CAAA;YACxB,MAAM,MAAM,CAAC,KAAK,CAAC,kBAAU,CAAC,SAAS,CAAC,UAAU,QAAQ,IAAI,IAAI,EAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAC7G,cAAc,CACf,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const inject_1 = require("@furystack/inject");
|
|
4
|
-
const rest_client_fetch_1 = require("@furystack/rest-client-fetch");
|
|
5
|
-
const utils_1 = require("@furystack/utils");
|
|
6
|
-
const request_action_implementation_1 = require("./request-action-implementation");
|
|
7
|
-
require("./helpers");
|
|
8
|
-
const helpers_1 = require("./helpers");
|
|
9
|
-
const createEchoApiServer = async () => {
|
|
10
|
-
const port = Math.round(Math.random() * 1000) + 10000;
|
|
11
|
-
const root = '/api';
|
|
12
|
-
const injector = new inject_1.Injector();
|
|
13
|
-
await (0, helpers_1.useRestService)({
|
|
14
|
-
injector,
|
|
15
|
-
port,
|
|
16
|
-
root,
|
|
17
|
-
api: {
|
|
18
|
-
GET: {
|
|
19
|
-
'/plain': async () => (0, request_action_implementation_1.JsonResult)({}),
|
|
20
|
-
'/headers': async ({ headers }) => (0, request_action_implementation_1.JsonResult)({ headers }),
|
|
21
|
-
'/query': async ({ getQuery }) => (0, request_action_implementation_1.JsonResult)({ query: getQuery() }),
|
|
22
|
-
'/urlParams/:id': async ({ getUrlParams }) => (0, request_action_implementation_1.JsonResult)({ url: getUrlParams() }),
|
|
23
|
-
'/segment': async () => (0, request_action_implementation_1.JsonResult)({ name: 'segment' }),
|
|
24
|
-
'/segment/subsegment': async () => (0, request_action_implementation_1.JsonResult)({ name: 'segment-subsegment' }),
|
|
25
|
-
'/segment/:id/subsegment': async ({ getUrlParams }) => (0, request_action_implementation_1.JsonResult)({ url: { ...getUrlParams(), name: 'segment-subsegment' } }),
|
|
26
|
-
'/segment/:optionalId?/optionalSubsegment/': async ({ getUrlParams }) => (0, request_action_implementation_1.JsonResult)({ url: getUrlParams(), name: 'optional-id' }),
|
|
27
|
-
},
|
|
28
|
-
POST: {
|
|
29
|
-
'/body': async ({ getBody }) => (0, request_action_implementation_1.JsonResult)({ body: await getBody() }),
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
const client = (0, rest_client_fetch_1.createClient)({
|
|
34
|
-
endpointUrl: `http://localhost:${port}/api`,
|
|
35
|
-
});
|
|
36
|
-
return {
|
|
37
|
-
dispose: injector.dispose.bind(injector),
|
|
38
|
-
root,
|
|
39
|
-
port,
|
|
40
|
-
client,
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
describe('REST Integration tests with FETCH client', () => {
|
|
44
|
-
it('Should execute a single parameterless GET query', async () => {
|
|
45
|
-
await (0, utils_1.usingAsync)(await createEchoApiServer(), async ({ client }) => {
|
|
46
|
-
const result = await client({
|
|
47
|
-
method: 'GET',
|
|
48
|
-
action: '/plain',
|
|
49
|
-
});
|
|
50
|
-
expect(result.response.status).toBe(200);
|
|
51
|
-
expect(result.result).toEqual({});
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
it('Should execute a request with headers', async () => {
|
|
55
|
-
await (0, utils_1.usingAsync)(await createEchoApiServer(), async ({ client }) => {
|
|
56
|
-
const value = 'value';
|
|
57
|
-
const result = await client({
|
|
58
|
-
method: 'GET',
|
|
59
|
-
action: '/headers',
|
|
60
|
-
headers: {
|
|
61
|
-
value,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
expect(result.response.status).toBe(200);
|
|
65
|
-
expect(result.result.headers.value).toEqual(value);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
it('Should execute a request with query', async () => {
|
|
69
|
-
await (0, utils_1.usingAsync)(await createEchoApiServer(), async ({ client }) => {
|
|
70
|
-
const value = 'value2';
|
|
71
|
-
const result = await client({
|
|
72
|
-
method: 'GET',
|
|
73
|
-
action: '/query',
|
|
74
|
-
query: {
|
|
75
|
-
someObject: {
|
|
76
|
-
foo: value,
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
expect(result.response.status).toBe(200);
|
|
81
|
-
expect(result.result.query.someObject.foo).toEqual(value);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
it('Should execute a request with URL parameters', async () => {
|
|
85
|
-
await (0, utils_1.usingAsync)(await createEchoApiServer(), async ({ client }) => {
|
|
86
|
-
const value = 'value3';
|
|
87
|
-
const result = await client({
|
|
88
|
-
method: 'GET',
|
|
89
|
-
action: '/urlParams/:id',
|
|
90
|
-
url: {
|
|
91
|
-
id: value,
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
expect(result.response.status).toBe(200);
|
|
95
|
-
expect(result.result.url.id).toEqual(value);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
it('should execute a request for a segment', async () => {
|
|
99
|
-
await (0, utils_1.usingAsync)(await createEchoApiServer(), async ({ client }) => {
|
|
100
|
-
const result = await client({
|
|
101
|
-
method: 'GET',
|
|
102
|
-
action: '/segment',
|
|
103
|
-
});
|
|
104
|
-
expect(result.response.status).toBe(200);
|
|
105
|
-
expect(result.result.name).toEqual('segment');
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
it('should execute a request for a subsegment', async () => {
|
|
109
|
-
await (0, utils_1.usingAsync)(await createEchoApiServer(), async ({ client }) => {
|
|
110
|
-
const result = await client({
|
|
111
|
-
method: 'GET',
|
|
112
|
-
action: '/segment/subsegment',
|
|
113
|
-
});
|
|
114
|
-
expect(result.response.status).toBe(200);
|
|
115
|
-
expect(result.result.name).toEqual('segment-subsegment');
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
it('should execute a request for a subsegment with URL parameters', async () => {
|
|
119
|
-
await (0, utils_1.usingAsync)(await createEchoApiServer(), async ({ client }) => {
|
|
120
|
-
const value = 'value4';
|
|
121
|
-
const result = await client({
|
|
122
|
-
method: 'GET',
|
|
123
|
-
action: '/segment/:id/subsegment',
|
|
124
|
-
url: {
|
|
125
|
-
id: value,
|
|
126
|
-
},
|
|
127
|
-
});
|
|
128
|
-
expect(result.response.status).toBe(200);
|
|
129
|
-
expect(result.result.url.id).toEqual(value);
|
|
130
|
-
expect(result.result.url.name).toEqual('segment-subsegment');
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
it('should evaluate optional parameters in the URL', async () => {
|
|
134
|
-
await (0, utils_1.usingAsync)(await createEchoApiServer(), async ({ client }) => {
|
|
135
|
-
const result = await client({
|
|
136
|
-
method: 'GET',
|
|
137
|
-
action: '/segment/:optionalId?/optionalSubsegment/',
|
|
138
|
-
url: {},
|
|
139
|
-
});
|
|
140
|
-
expect(result.response.status).toBe(200);
|
|
141
|
-
expect(result.result.url.optionalId).toBeUndefined();
|
|
142
|
-
expect(result.result.name).toEqual('optional-id');
|
|
143
|
-
const result2 = await client({
|
|
144
|
-
method: 'GET',
|
|
145
|
-
action: '/segment/:optionalId?/optionalSubsegment/',
|
|
146
|
-
url: {
|
|
147
|
-
optionalId: 'value',
|
|
148
|
-
},
|
|
149
|
-
});
|
|
150
|
-
expect(result2.response.status).toBe(200);
|
|
151
|
-
expect(result2.result.url.optionalId).toEqual('value');
|
|
152
|
-
expect(result2.result.name).toEqual('optional-id');
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
//# sourceMappingURL=rest.integration.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rest.integration.test.js","sourceRoot":"","sources":["../src/rest.integration.test.ts"],"names":[],"mappings":";;AAAA,8CAA4C;AAE5C,oEAA2D;AAC3D,4CAA6C;AAC7C,mFAA4D;AAC5D,qBAAkB;AAClB,uCAA0C;AAwB1C,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,KAAK,CAAA;IACrD,MAAM,IAAI,GAAG,MAAM,CAAA;IACnB,MAAM,QAAQ,GAAG,IAAI,iBAAQ,EAAE,CAAA;IAC/B,MAAM,IAAA,wBAAc,EAAU;QAC5B,QAAQ;QACR,IAAI;QACJ,IAAI;QACJ,GAAG,EAAE;YACH,GAAG,EAAE;gBACH,QAAQ,EAAE,KAAK,IAAI,EAAE,CAAC,IAAA,0CAAU,EAAC,EAAE,CAAC;gBACpC,UAAU,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,IAAA,0CAAU,EAAC,EAAE,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;YACtD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,19 +0,0 @@
|
|
|
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("./schema-validator"), exports);
|
|
18
|
-
__exportStar(require("./schema-validation-error"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schema-validator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAkC;AAClC,4DAAyC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SchemaValidationError = void 0;
|
|
4
|
-
const rest_1 = require("@furystack/rest");
|
|
5
|
-
/**
|
|
6
|
-
* Custom Error class for Schema Validation Errors
|
|
7
|
-
*/
|
|
8
|
-
class SchemaValidationError extends rest_1.RequestError {
|
|
9
|
-
constructor(errors) {
|
|
10
|
-
super('Schema Validation failed', 400);
|
|
11
|
-
this.errors = errors;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
exports.SchemaValidationError = SchemaValidationError;
|
|
15
|
-
//# sourceMappingURL=schema-validation-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-validation-error.js","sourceRoot":"","sources":["../../src/schema-validator/schema-validation-error.ts"],"names":[],"mappings":";;;AAAA,0CAA8C;AAG9C;;GAEG;AACH,MAAa,qBAAsB,SAAQ,mBAAY;IACrD,YAA4B,MAAqB;QAC/C,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAA;QADZ,WAAM,GAAN,MAAM,CAAe;IAEjD,CAAC;CACF;AAJD,sDAIC"}
|
|
@@ -1,38 +0,0 @@
|
|
|
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.SchemaValidator = void 0;
|
|
7
|
-
const ajv_1 = __importDefault(require("ajv"));
|
|
8
|
-
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
9
|
-
const schema_validation_error_1 = require("./schema-validation-error");
|
|
10
|
-
class SchemaValidator {
|
|
11
|
-
constructor(schema, ajvOptions) {
|
|
12
|
-
this.schema = schema;
|
|
13
|
-
this.ajvOptions = ajvOptions;
|
|
14
|
-
this.ajv = new ajv_1.default({
|
|
15
|
-
allErrors: true,
|
|
16
|
-
...this.ajvOptions,
|
|
17
|
-
});
|
|
18
|
-
(0, ajv_formats_1.default)(this.ajv);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* @param data The object to validate
|
|
22
|
-
* @param options Options for the schema validation
|
|
23
|
-
* @param options.schemaName The name of the type in the Schema Definitions
|
|
24
|
-
* @throws SchemaValidationError when the validation has been failed
|
|
25
|
-
* @returns true in case of validation success
|
|
26
|
-
*/
|
|
27
|
-
isValid(data, options) {
|
|
28
|
-
const schema = { ...this.schema, $ref: `#/definitions/${options.schemaName}` };
|
|
29
|
-
const validatorFn = this.ajv.compile(schema);
|
|
30
|
-
const isValid = validatorFn(data);
|
|
31
|
-
if (!isValid) {
|
|
32
|
-
throw new schema_validation_error_1.SchemaValidationError(validatorFn.errors);
|
|
33
|
-
}
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
exports.SchemaValidator = SchemaValidator;
|
|
38
|
-
//# sourceMappingURL=schema-validator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-validator.js","sourceRoot":"","sources":["../../src/schema-validator/schema-validator.ts"],"names":[],"mappings":";;;;;;AACA,8CAAqB;AACrB,8DAAoC;AACpC,uEAAiE;AAEjE,MAAa,eAAe;IAK1B,YAA6B,MAAe,EAAmB,UAAoB;QAAtD,WAAM,GAAN,MAAM,CAAS;QAAmB,eAAU,GAAV,UAAU,CAAU;QAJlE,QAAG,GAAG,IAAI,aAAG,CAAC;YAC7B,SAAS,EAAE,IAAI;YACf,GAAG,IAAI,CAAC,UAAU;SACnB,CAAC,CAAA;QAEA,IAAA,qBAAU,EAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACtB,CAAC;IAED;;;;;;OAMG;IACI,OAAO,CAAI,IAAS,EAAE,OAAqD;QAChF,MAAM,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,iBAAiB,OAAO,CAAC,UAAoB,EAAE,EAAE,CAAA;QACxF,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAC5C,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,CAAA;QACjC,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,+CAAqB,CAAC,WAAW,CAAC,MAAuB,CAAC,CAAA;SACrE;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF;AA1BD,0CA0BC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const schema_validator_1 = require("./schema-validator");
|
|
4
|
-
const validate_examples_1 = require("./validate-examples");
|
|
5
|
-
const schema_validation_error_1 = require("./schema-validation-error");
|
|
6
|
-
describe('ValidateSchema', () => {
|
|
7
|
-
describe('String Literal checks', () => {
|
|
8
|
-
it('Should pass on valid string literal parameters', () => {
|
|
9
|
-
expect(new schema_validator_1.SchemaValidator(validate_examples_1.exampleSchema).isValid('en', { schemaName: 'Language' })).toBeTruthy();
|
|
10
|
-
});
|
|
11
|
-
it('Should throw a ValidationError on Age parameters', () => {
|
|
12
|
-
try {
|
|
13
|
-
const result = new schema_validator_1.SchemaValidator(validate_examples_1.exampleSchema).isValid('foo', { schemaName: 'Language' });
|
|
14
|
-
expect(result).toBeFalsy(); // should not hit
|
|
15
|
-
}
|
|
16
|
-
catch (error) {
|
|
17
|
-
expect(error).toBeInstanceOf(schema_validation_error_1.SchemaValidationError);
|
|
18
|
-
const { errors } = error;
|
|
19
|
-
expect(errors).toHaveLength(1);
|
|
20
|
-
expect(errors[0].message).toEqual('must be equal to one of the allowed values');
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
describe('Object checks', () => {
|
|
25
|
-
it('Should fail when string is passed instead of object', () => {
|
|
26
|
-
try {
|
|
27
|
-
new schema_validator_1.SchemaValidator(validate_examples_1.exampleSchema).isValid('foo', { schemaName: 'BodyParameters' });
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
expect(error).toBeInstanceOf(schema_validation_error_1.SchemaValidationError);
|
|
31
|
-
const { errors } = error;
|
|
32
|
-
expect(errors).toHaveLength(1);
|
|
33
|
-
expect(errors[0].message).toEqual('must be object');
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
it('Should fail when an additional property is present', () => {
|
|
37
|
-
try {
|
|
38
|
-
new schema_validator_1.SchemaValidator(validate_examples_1.exampleSchema).isValid({ age: '3', foo: 2 }, { schemaName: 'BodyParameters' });
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
expect(error).toBeInstanceOf(schema_validation_error_1.SchemaValidationError);
|
|
42
|
-
const { errors } = error;
|
|
43
|
-
expect(errors).toHaveLength(1);
|
|
44
|
-
expect(errors[0].message).toEqual('must NOT have additional properties');
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
it('Should pass with empty objects', () => {
|
|
48
|
-
expect(new schema_validator_1.SchemaValidator(validate_examples_1.exampleSchema).isValid({}, { schemaName: 'BodyParameters' })).toBeTruthy();
|
|
49
|
-
});
|
|
50
|
-
it('Should pass with valid partial objects', () => {
|
|
51
|
-
expect(new schema_validator_1.SchemaValidator(validate_examples_1.exampleSchema).isValid({ age: '3' }, { schemaName: 'BodyParameters' })).toBeTruthy();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('Multiple checks per validator instance', () => {
|
|
55
|
-
it('Should pass with multiple types from schema per validator instance', () => {
|
|
56
|
-
const validator = new schema_validator_1.SchemaValidator(validate_examples_1.exampleSchema);
|
|
57
|
-
expect(validator.isValid('en', { schemaName: 'Language' })).toBeTruthy();
|
|
58
|
-
expect(new schema_validator_1.SchemaValidator(validate_examples_1.exampleSchema).isValid({}, { schemaName: 'BodyParameters' })).toBeTruthy();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
//# sourceMappingURL=schema-validator.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-validator.test.js","sourceRoot":"","sources":["../../src/schema-validator/schema-validator.test.ts"],"names":[],"mappings":";;AAAA,yDAAoD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E,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC,CAC3G,CAAC,UAAU,EAAE,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,wCAAwC,EAAE,GAAG,EAAE;QACtD,EAAE,CAAC,oEAAoE,EAAE,GAAG,EAAE;YAC5E,MAAM,SAAS,GAAG,IAAI,kCAAe,CAAC,iCAAa,CAAC,CAAA;YACpD,MAAM,CAAC,SAAS,CAAC,OAAO,CAAW,IAAI,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,UAAU,EAAE,CAAA;YAClF,MAAM,CACJ,IAAI,kCAAe,CAAC,iCAAa,CAAC,CAAC,OAAO,CAAiB,EAAE,EAAE,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC,CACjG,CAAC,UAAU,EAAE,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exampleSchema = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Example Schema Definition - can be generated from the example types above with ts-json-schema-generator
|
|
6
|
-
*/
|
|
7
|
-
exports.exampleSchema = {
|
|
8
|
-
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
9
|
-
definitions: {
|
|
10
|
-
BodyParameters: {
|
|
11
|
-
additionalProperties: false,
|
|
12
|
-
properties: {
|
|
13
|
-
age: {
|
|
14
|
-
type: 'string',
|
|
15
|
-
},
|
|
16
|
-
gender: {
|
|
17
|
-
enum: ['MALE', 'FEMALE'],
|
|
18
|
-
type: 'string',
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
type: 'object',
|
|
22
|
-
},
|
|
23
|
-
Language: {
|
|
24
|
-
enum: ['en', 'hu', 'de', 'all'],
|
|
25
|
-
type: 'string',
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=validate-examples.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate-examples.js","sourceRoot":"","sources":["../../src/schema-validator/validate-examples.ts"],"names":[],"mappings":";;;AAaA;;GAEG;AACU,QAAA,aAAa,GAAG;IAC3B,OAAO,EAAE,yCAAyC;IAClD,WAAW,EAAE;QACX,cAAc,EAAE;YACd,oBAAoB,EAAE,KAAK;YAC3B,UAAU,EAAE;gBACV,GAAG,EAAE;oBACH,IAAI,EAAE,QAAQ;iBACf;gBACD,MAAM,EAAE;oBACN,IAAI,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC;oBACxB,IAAI,EAAE,QAAQ;iBACf;aACF;YACD,IAAI,EAAE,QAAQ;SACf;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC;YAC/B,IAAI,EAAE,QAAQ;SACf;KACF;CACF,CAAA"}
|
package/dist/server-manager.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
var ServerManager_1;
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.ServerManager = void 0;
|
|
14
|
-
const inject_1 = require("@furystack/inject");
|
|
15
|
-
const http_1 = require("http");
|
|
16
|
-
const semaphore_async_await_1 = __importDefault(require("semaphore-async-await"));
|
|
17
|
-
let ServerManager = ServerManager_1 = class ServerManager {
|
|
18
|
-
constructor() {
|
|
19
|
-
this.servers = new Map();
|
|
20
|
-
this.openedSockets = new Set();
|
|
21
|
-
this.listenLock = new semaphore_async_await_1.default(1);
|
|
22
|
-
this.getHostUrl = (options) => `http://${options.hostName || ServerManager_1.DEFAULT_HOST}:${options.port}`;
|
|
23
|
-
this.onConnection = (socket) => {
|
|
24
|
-
this.openedSockets.add(socket);
|
|
25
|
-
socket.once('close', () => this.openedSockets.delete(socket));
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
async dispose() {
|
|
29
|
-
try {
|
|
30
|
-
await this.listenLock.waitFor(5000);
|
|
31
|
-
}
|
|
32
|
-
finally {
|
|
33
|
-
this.openedSockets.forEach((s) => s.destroy());
|
|
34
|
-
await Promise.allSettled([...this.servers.values()].map((s) => new Promise((resolve, reject) => {
|
|
35
|
-
s.server.close((err) => (err ? reject(err) : resolve()));
|
|
36
|
-
s.server.off('connection', this.onConnection);
|
|
37
|
-
})));
|
|
38
|
-
this.servers.clear();
|
|
39
|
-
this.listenLock.release();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
async getOrCreate(options) {
|
|
43
|
-
const url = this.getHostUrl(options);
|
|
44
|
-
if (!this.servers.has(url)) {
|
|
45
|
-
await this.listenLock.acquire();
|
|
46
|
-
try {
|
|
47
|
-
if (!this.servers.has(url)) {
|
|
48
|
-
await new Promise((resolve, reject) => {
|
|
49
|
-
const apis = [];
|
|
50
|
-
const server = (0, http_1.createServer)((req, res) => {
|
|
51
|
-
const apiMatch = apis.find((api) => api.shouldExec({ req, res }));
|
|
52
|
-
if (apiMatch) {
|
|
53
|
-
apiMatch.onRequest({ req, res });
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
res.destroy();
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
server.on('connection', this.onConnection);
|
|
60
|
-
server.on('listening', () => resolve());
|
|
61
|
-
server.on('error', (err) => reject(err));
|
|
62
|
-
server.listen(options.port, options.hostName);
|
|
63
|
-
this.servers.set(url, { server, apis });
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
finally {
|
|
68
|
-
this.listenLock.release();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return this.servers.get(url);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
ServerManager.DEFAULT_HOST = 'localhost';
|
|
75
|
-
ServerManager = ServerManager_1 = __decorate([
|
|
76
|
-
(0, inject_1.Injectable)({ lifetime: 'singleton' })
|
|
77
|
-
], ServerManager);
|
|
78
|
-
exports.ServerManager = ServerManager;
|
|
79
|
-
//# sourceMappingURL=server-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server-manager.js","sourceRoot":"","sources":["../src/server-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,8CAA8C;AAG9C,+BAAmC;AACnC,kFAA6C;AAyB7C,IAAa,aAAa,qBAA1B,MAAa,aAAa;IAA1B;QAGS,YAAO,GAAG,IAAI,GAAG,EAAwB,CAAA;QACxC,kBAAa,GAAG,IAAI,GAAG,EAAU,CAAA;QAExB,eAAU,GAAG,IAAI,+BAAS,CAAC,CAAC,CAAC,CAAA;QAEtC,eAAU,GAAG,CAAC,OAAsB,EAAE,EAAE,CAC9C,UAAU,OAAO,CAAC,QAAQ,IAAI,eAAa,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,EAAE,CAAA;QAEpE,iBAAY,GAAG,CAAC,MAAc,EAAE,EAAE;YACxC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YAC9B,MAAM,CAAC,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AW,AAAd,CAAc;AAD7B,aAAa;IADzB,IAAA,mBAAU,EAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,aAAa,CAgEzB;AAhEY,sCAAa"}
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
const http_1 = __importDefault(require("http"));
|
|
7
|
-
http_1.default.ServerResponse.prototype.sendActionResult = function (options) {
|
|
8
|
-
if (typeof options.chunk === 'object') {
|
|
9
|
-
options.chunk = JSON.stringify(options.chunk);
|
|
10
|
-
}
|
|
11
|
-
if (typeof options.chunk === 'string' && options.chunk === 'BypassResult') {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
this.writeHead(options.statusCode, options.headers);
|
|
15
|
-
this.end(options.chunk);
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=server-response-extensions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server-response-extensions.js","sourceRoot":"","sources":["../src/server-response-extensions.ts"],"names":[],"mappings":";;;;;AAAA,gDAAuB;AAoBvB,cAAI,CAAC,cAAc,CAAC,SAAS,CAAC,gBAAgB,GAAG,UAAa,OAAwB;IACpF,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;QACrC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAQ,CAAA;KACrD;IACD,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,KAAK,KAAK,cAAc,EAAE;QACzE,OAAM;KACP;IACD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AACzB,CAAC,CAAA"}
|