@furystack/rest-service 6.0.8 → 6.1.2
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/dist/actions/index.js +20 -7
- package/dist/actions/index.js.map +1 -1
- package/dist/api-manager.js +20 -16
- package/dist/api-manager.js.map +1 -1
- package/dist/endpoint-generators/create-delete-endpoint.spec.js +4 -2
- package/dist/endpoint-generators/create-delete-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.js +1 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.js.map +1 -1
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js +4 -2
- package/dist/endpoint-generators/create-get-collection-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js +4 -2
- package/dist/endpoint-generators/create-get-entity-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-patch-endpoint.spec.js +5 -3
- package/dist/endpoint-generators/create-patch-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/create-post-endpoint.spec.js +5 -3
- package/dist/endpoint-generators/create-post-endpoint.spec.js.map +1 -1
- package/dist/endpoint-generators/index.js +19 -6
- package/dist/endpoint-generators/index.js.map +1 -1
- package/dist/helpers.js +15 -1
- package/dist/helpers.js.map +1 -1
- package/dist/helpers.spec.js +18 -2
- package/dist/helpers.spec.js.map +1 -1
- package/dist/http-authentication-settings.js +7 -2
- package/dist/http-authentication-settings.js.map +1 -1
- package/dist/http-user-context.js +16 -8
- package/dist/http-user-context.js.map +1 -1
- package/dist/incoming-message-extensions.js +4 -2
- package/dist/incoming-message-extensions.js.map +1 -1
- package/dist/index.js +32 -17
- package/dist/index.js.map +1 -1
- package/dist/mime-types.js +340 -0
- package/dist/mime-types.js.map +1 -0
- package/dist/mime-types.spec.js +15 -0
- package/dist/mime-types.spec.js.map +1 -0
- package/dist/models/index.js +16 -3
- package/dist/models/index.js.map +1 -1
- package/dist/rest-service.integration.spec.js +4 -2
- package/dist/rest-service.integration.spec.js.map +1 -1
- package/dist/schema-validator/index.js +16 -3
- package/dist/schema-validator/index.js.map +1 -1
- package/dist/schema-validator/schema-validator.js +5 -3
- package/dist/schema-validator/schema-validator.js.map +1 -1
- package/dist/server-manager.js +11 -3
- package/dist/server-manager.js.map +1 -1
- package/dist/server-response-extensions.js +4 -2
- package/dist/server-response-extensions.js.map +1 -1
- package/dist/static-server-manager.js +71 -0
- package/dist/static-server-manager.js.map +1 -0
- package/dist/static-server-manager.spec.js +206 -0
- package/dist/static-server-manager.spec.js.map +1 -0
- package/dist/utils.js +7 -2
- package/dist/utils.js.map +1 -1
- package/dist/validate.integration.spec.js +12 -14
- package/dist/validate.integration.spec.js.map +1 -1
- package/dist/validate.js +4 -6
- package/dist/validate.js.map +1 -1
- package/package.json +12 -13
- package/src/helpers.spec.ts +20 -9
- package/src/helpers.ts +14 -0
- package/src/index.ts +2 -0
- package/src/mime-types.spec.ts +14 -0
- package/src/mime-types.ts +336 -0
- package/src/server-manager.ts +6 -1
- package/src/static-server-manager.spec.ts +226 -0
- package/src/static-server-manager.ts +89 -0
- package/types/helpers.d.ts +12 -0
- package/types/helpers.d.ts.map +1 -1
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -1
- package/types/mime-types.d.ts +305 -0
- package/types/mime-types.d.ts.map +1 -0
- package/types/mime-types.spec.d.ts +2 -0
- package/types/mime-types.spec.d.ts.map +1 -0
- package/types/server-manager.d.ts +5 -4
- package/types/server-manager.d.ts.map +1 -1
- package/types/static-server-manager.d.ts +20 -0
- package/types/static-server-manager.d.ts.map +1 -0
- package/types/static-server-manager.spec.d.ts +2 -0
- package/types/static-server-manager.spec.d.ts.map +1 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
const http_1 = tslib_1.__importDefault(require("http"));
|
|
6
|
+
const http_1 = __importDefault(require("http"));
|
|
5
7
|
http_1.default.ServerResponse.prototype.sendActionResult = function (options) {
|
|
6
8
|
if (typeof options.chunk === 'object') {
|
|
7
9
|
options.chunk = JSON.stringify(options.chunk);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-response-extensions.js","sourceRoot":"","sources":["../src/server-response-extensions.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.StaticServerManager = void 0;
|
|
13
|
+
const inject_1 = require("@furystack/inject");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const promises_1 = require("fs/promises");
|
|
16
|
+
const mime_types_1 = require("./mime-types");
|
|
17
|
+
const path_1 = require("path");
|
|
18
|
+
const server_manager_1 = require("./server-manager");
|
|
19
|
+
let StaticServerManager = class StaticServerManager {
|
|
20
|
+
constructor() {
|
|
21
|
+
this.shouldExec = (baseUrl) => ({ req }) => req.url &&
|
|
22
|
+
req.method?.toUpperCase() === 'GET' &&
|
|
23
|
+
(req.url === baseUrl || req.url.startsWith(baseUrl[baseUrl.length - 1] === '/' ? baseUrl : `${baseUrl}/`))
|
|
24
|
+
? true
|
|
25
|
+
: false;
|
|
26
|
+
this.onRequest = ({ path, baseUrl, fallback, headers, }) => {
|
|
27
|
+
return async ({ req, res }) => {
|
|
28
|
+
const filePath = req.url.substring(baseUrl.length - 1).replaceAll('/', path_1.sep);
|
|
29
|
+
const fullPath = (0, path_1.normalize)((0, path_1.join)(path, filePath));
|
|
30
|
+
try {
|
|
31
|
+
await this.sendFile({ fullPath, res, headers });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (fallback) {
|
|
35
|
+
await this.sendFile({ fullPath: (0, path_1.join)(path, fallback), res, headers });
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
res.writeHead(404, { 'Content-Type': 'text/plain' });
|
|
39
|
+
res.end('Not found');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async sendFile({ fullPath, headers, res, }) {
|
|
46
|
+
const { size } = await (0, promises_1.stat)(fullPath);
|
|
47
|
+
const head = {
|
|
48
|
+
...headers,
|
|
49
|
+
'Content-Length': size,
|
|
50
|
+
'Content-Type': (0, mime_types_1.getMimeForFile)(fullPath),
|
|
51
|
+
};
|
|
52
|
+
res.writeHead(200, head);
|
|
53
|
+
(0, fs_1.createReadStream)(fullPath, { autoClose: true }).pipe(res);
|
|
54
|
+
}
|
|
55
|
+
async addStaticSite(options) {
|
|
56
|
+
const server = await this.serverManager.getOrCreate({ hostName: options.hostName, port: options.port });
|
|
57
|
+
server.apis.push({
|
|
58
|
+
shouldExec: this.shouldExec(options.baseUrl),
|
|
59
|
+
onRequest: this.onRequest({ ...options }),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
__decorate([
|
|
64
|
+
(0, inject_1.Injected)(server_manager_1.ServerManager),
|
|
65
|
+
__metadata("design:type", server_manager_1.ServerManager)
|
|
66
|
+
], StaticServerManager.prototype, "serverManager", void 0);
|
|
67
|
+
StaticServerManager = __decorate([
|
|
68
|
+
(0, inject_1.Injectable)({ lifetime: 'singleton' })
|
|
69
|
+
], StaticServerManager);
|
|
70
|
+
exports.StaticServerManager = StaticServerManager;
|
|
71
|
+
//# sourceMappingURL=static-server-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-server-manager.js","sourceRoot":"","sources":["../src/static-server-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAwD;AACxD,2BAAqC;AACrC,0CAAkC;AAElC,6CAA6C;AAC7C,+BAA2C;AAC3C,qDAAgD;AAYzC,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAAzB;QAyBE,eAAU,GACf,CAAC,OAAe,EAAE,EAAE,CACpB,CAAC,EAAE,GAAG,EAAoD,EAAE,EAAE,CAC5D,GAAG,CAAC,GAAG;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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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const inject_1 = require("@furystack/inject");
|
|
27
|
+
const utils_1 = require("@furystack/utils");
|
|
28
|
+
const got_1 = __importStar(require("got"));
|
|
29
|
+
const server_manager_1 = require("./server-manager");
|
|
30
|
+
const static_server_manager_1 = require("./static-server-manager");
|
|
31
|
+
describe('StaticServerManager', () => {
|
|
32
|
+
describe('Top level routing', () => {
|
|
33
|
+
it('Should return a 404 without fallback', async () => {
|
|
34
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
35
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
36
|
+
await staticServerManager.addStaticSite({
|
|
37
|
+
baseUrl: '/',
|
|
38
|
+
path: '.',
|
|
39
|
+
port: 1234,
|
|
40
|
+
});
|
|
41
|
+
try {
|
|
42
|
+
await got_1.default.get('http://localhost:1234/not-found.html');
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
expect(error).toBeInstanceOf(got_1.RequestError);
|
|
46
|
+
const requestError = error;
|
|
47
|
+
expect(requestError.response?.statusCode).toBe(404);
|
|
48
|
+
expect(requestError.response?.headers['content-type']).toBe('text/plain');
|
|
49
|
+
expect(requestError.response?.body).toBe('Not found');
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
it('Should return a fallback', async () => {
|
|
54
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
55
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
56
|
+
await staticServerManager.addStaticSite({
|
|
57
|
+
baseUrl: '/',
|
|
58
|
+
path: '.',
|
|
59
|
+
fallback: 'package.json',
|
|
60
|
+
port: 1234,
|
|
61
|
+
headers: {
|
|
62
|
+
'custom-header': 'custom-value',
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
const result = await got_1.default.get('http://localhost:1234/not-found.html');
|
|
66
|
+
expect(result.headers['content-type']).toBe('application/json');
|
|
67
|
+
expect(result.headers['custom-header']).toBe('custom-value');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
it('Should return a defined file from a root directory', async () => {
|
|
71
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
72
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
73
|
+
await staticServerManager.addStaticSite({
|
|
74
|
+
baseUrl: '/',
|
|
75
|
+
path: '.',
|
|
76
|
+
port: 1234,
|
|
77
|
+
headers: {
|
|
78
|
+
'custom-header': 'custom-value',
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const result = await got_1.default.get('http://localhost:1234/README.md');
|
|
82
|
+
expect(result.headers['content-type']).toBe('text/markdown');
|
|
83
|
+
expect(result.headers['custom-header']).toBe('custom-value');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
it('Should return a defined file from a subdirectory', async () => {
|
|
87
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
88
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
89
|
+
await staticServerManager.addStaticSite({
|
|
90
|
+
baseUrl: '/',
|
|
91
|
+
path: '.',
|
|
92
|
+
port: 1234,
|
|
93
|
+
});
|
|
94
|
+
const result = await got_1.default.get('http://localhost:1234/packages/utils/README.md');
|
|
95
|
+
expect(result.headers['content-type']).toBe('text/markdown');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe('Non-top level routing', () => {
|
|
100
|
+
it('Should not handle a request when the path is not matching', async () => {
|
|
101
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
102
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
103
|
+
await staticServerManager.addStaticSite({
|
|
104
|
+
baseUrl: '/bundle',
|
|
105
|
+
path: '.',
|
|
106
|
+
port: 1234,
|
|
107
|
+
});
|
|
108
|
+
const server = [...injector.getInstance(server_manager_1.ServerManager).servers.values()][0];
|
|
109
|
+
server.apis[0].onRequest = jest.fn();
|
|
110
|
+
got_1.default.get('http://localhost:1234/bundleToAnotherFolder/not-found.html');
|
|
111
|
+
await (0, utils_1.sleepAsync)(100);
|
|
112
|
+
expect(server.apis[0].onRequest).not.toHaveBeenCalled();
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
it('Should return a 404 without fallback', async () => {
|
|
116
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
117
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
118
|
+
await staticServerManager.addStaticSite({
|
|
119
|
+
baseUrl: '/bundle',
|
|
120
|
+
path: '.',
|
|
121
|
+
port: 1234,
|
|
122
|
+
});
|
|
123
|
+
try {
|
|
124
|
+
await got_1.default.get('http://localhost:1234/bundle/not-found.html');
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
expect(error).toBeInstanceOf(got_1.RequestError);
|
|
128
|
+
const requestError = error;
|
|
129
|
+
expect(requestError.response?.statusCode).toBe(404);
|
|
130
|
+
expect(requestError.response?.headers['content-type']).toBe('text/plain');
|
|
131
|
+
expect(requestError.response?.body).toBe('Not found');
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
it('Should return a fallback', async () => {
|
|
136
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
137
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
138
|
+
await staticServerManager.addStaticSite({
|
|
139
|
+
baseUrl: '/bundle',
|
|
140
|
+
path: '.',
|
|
141
|
+
fallback: 'package.json',
|
|
142
|
+
port: 1234,
|
|
143
|
+
});
|
|
144
|
+
const result = await got_1.default.get('http://localhost:1234/bundle/not-found.html');
|
|
145
|
+
expect(result.headers['content-type']).toBe('application/json');
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
it('Should return a defined file from a root directory', async () => {
|
|
149
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
150
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
151
|
+
await staticServerManager.addStaticSite({
|
|
152
|
+
baseUrl: '/',
|
|
153
|
+
path: '.',
|
|
154
|
+
port: 1234,
|
|
155
|
+
});
|
|
156
|
+
const result = await got_1.default.get('http://localhost:1234/README.md');
|
|
157
|
+
expect(result.headers['content-type']).toBe('text/markdown');
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
it('Should return a defined file from a subdirectory', async () => {
|
|
161
|
+
await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
|
|
162
|
+
const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
|
|
163
|
+
await staticServerManager.addStaticSite({
|
|
164
|
+
baseUrl: '/',
|
|
165
|
+
path: '.',
|
|
166
|
+
port: 1234,
|
|
167
|
+
});
|
|
168
|
+
const result = await got_1.default.get('http://localhost:1234/packages/utils/README.md');
|
|
169
|
+
expect(result.headers['content-type']).toBe('text/markdown');
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe('shouldExec', () => {
|
|
174
|
+
it('Should NOT match for requests with not defined method', () => {
|
|
175
|
+
const staticServerManager = new static_server_manager_1.StaticServerManager();
|
|
176
|
+
expect(staticServerManager.shouldExec('/')({ req: { url: '/' } })).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
it('Should NOT match for non-GET requests', () => {
|
|
179
|
+
const staticServerManager = new static_server_manager_1.StaticServerManager();
|
|
180
|
+
expect(staticServerManager.shouldExec('/')({ req: { method: 'POST', url: '/' } })).toBe(false);
|
|
181
|
+
});
|
|
182
|
+
[
|
|
183
|
+
['/', '/'],
|
|
184
|
+
['/', '/index.html'],
|
|
185
|
+
['/', '/subdir'],
|
|
186
|
+
['/', '/subdir/'],
|
|
187
|
+
['/', '/subdir/file.js'],
|
|
188
|
+
['/subdir', '/subdir'],
|
|
189
|
+
['/subdir', '/subdir/'],
|
|
190
|
+
['/subdir', '/subdir/file.js'],
|
|
191
|
+
['/subdir', '/subdir/s2/file.js'],
|
|
192
|
+
].forEach(([root, url]) => it(`Should match for '${root}' root and '${url}' url`, () => {
|
|
193
|
+
const staticServerManager = new static_server_manager_1.StaticServerManager();
|
|
194
|
+
const shouldExec = staticServerManager.shouldExec(root)({ req: { method: 'GET', url } });
|
|
195
|
+
expect(shouldExec).toBe(true);
|
|
196
|
+
}));
|
|
197
|
+
it('Should not exec different paths for non-top level root directory', () => {
|
|
198
|
+
const staticServerManager = new static_server_manager_1.StaticServerManager();
|
|
199
|
+
expect(staticServerManager.shouldExec('/subdir')({ req: { method: 'GET', url: '/' } })).toBe(false);
|
|
200
|
+
expect(staticServerManager.shouldExec('/subdir')({ req: { method: 'GET', url: '/other/index.html' } })).toBe(false);
|
|
201
|
+
expect(staticServerManager.shouldExec('/subdir')({ req: { method: 'GET', url: '/subdir2' } })).toBe(false);
|
|
202
|
+
expect(staticServerManager.shouldExec('/subdir')({ req: { method: 'GET', url: '/subdir2/index.html' } })).toBe(false);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
//# sourceMappingURL=static-server-manager.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static-server-manager.spec.js","sourceRoot":"","sources":["../src/static-server-manager.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAA4C;AAC5C,4CAAyD;AACzD,2CAAuC;AACvC,qDAAgD;AAChD,mEAA6D;AAE7D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;YACpD,MAAM,IAAA,kBAAU,EAAC,IAAI,iBAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE;gBAClD,MAAM,mBAAmB,GAAG,QAAQ,CAAC,WAAW,CAAC,2CAAmB,CAAC,CAAA;gBAErE,MAAM,mBAAmB,CAAC,aAAa,CAAC;oBACtC,OAAO,EAAE,GAAG;oBACZ,IAAI,EAAE,GAAG;oBACT,IAAI,EAAE,IAAI;iBACX,CAAC,CAAA;gBAEF,IAAI;oBACF,MAAM,aAAG,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAA;iBACtD;gBAAC,OAAO,KAAK,EAAE;oBACd,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,kBAAY,CAAC,CAAA;oBAC1C,MAAM,YAAY,GAAiB,KAAqB,CAAA;oBAExD,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,GA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;YACrD,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACnG,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,mBAAmB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC1G,KAAK,CACN,CAAA;YACD,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAC1G,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,qBAAqB,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAC5G,KAAK,CACN,CAAA;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/utils.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
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
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.Utils = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
10
|
const inject_1 = require("@furystack/inject");
|
|
6
11
|
/**
|
|
7
12
|
* A collection of various HTTP API related utilities
|
|
@@ -59,7 +64,7 @@ let Utils = class Utils {
|
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
};
|
|
62
|
-
Utils =
|
|
67
|
+
Utils = __decorate([
|
|
63
68
|
(0, inject_1.Injectable)({ lifetime: 'transient' })
|
|
64
69
|
], Utils);
|
|
65
70
|
exports.Utils = Utils;
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;AACA,8CAA8C;AAG9C;;GAEG;AAEI,IAAM,KAAK,GAAX,MAAM,KAAK;IACT,KAAK,CAAC,eAAe,CAAC,eAAgC;QAC3D,IAAI,IAAI,GAAG,EAAE,CAAA;QACb,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC1C,eAAe,CAAC,EAAE,CAAC,UAAU,EAAE,GAAG,EAAE;gBAClC,MAAM,IAAI,GAAG,eAAe,CAAC,IAAI,EAAE,CAAA;gBACnC,IAAI,IAAI,EAAE;oBACR,IAAI,IAAI,IAAI,CAAA;iBACb;YACH,CAAC,CAAC,CAAA;YACF,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBAC7B,OAAO,EAAE,CAAA;YACX,CAAC,CAAC,CAAA;YACF,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBAClC,MAAM,CAAC,GAAG,CAAC,CAAA;YACb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ACzB,KAAK,CAwDjB;AAxDY,sBAAK"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
6
|
const inject_1 = require("@furystack/inject");
|
|
5
7
|
const rest_client_got_1 = require("@furystack/rest-client-got");
|
|
6
8
|
const utils_1 = require("@furystack/utils");
|
|
@@ -8,7 +10,7 @@ const source_1 = require("got/dist/source");
|
|
|
8
10
|
const request_action_implementation_1 = require("./request-action-implementation");
|
|
9
11
|
const validate_1 = require("./validate");
|
|
10
12
|
require("./helpers");
|
|
11
|
-
const validate_integration_spec_schema_json_1 =
|
|
13
|
+
const validate_integration_spec_schema_json_1 = __importDefault(require("./validate.integration.spec.schema.json"));
|
|
12
14
|
const helpers_1 = require("./helpers");
|
|
13
15
|
// To recreate: yarn ts-json-schema-generator -f tsconfig.json --no-type-check -p packages/rest-service/src/validate.integration.schema.ts -o packages/rest-service/src/validate.integration.spec.schema.json
|
|
14
16
|
const createValidateApi = async () => {
|
|
@@ -65,7 +67,6 @@ describe('Validation integration tests', () => {
|
|
|
65
67
|
describe('Validation errors', () => {
|
|
66
68
|
it('Should validate query', async () => {
|
|
67
69
|
await (0, utils_1.usingAsync)(await createValidateApi(), async ({ client }) => {
|
|
68
|
-
var _a, _b;
|
|
69
70
|
expect.assertions(5);
|
|
70
71
|
try {
|
|
71
72
|
await client({
|
|
@@ -77,8 +78,8 @@ describe('Validation integration tests', () => {
|
|
|
77
78
|
catch (error) {
|
|
78
79
|
if (error instanceof source_1.RequestError) {
|
|
79
80
|
expect(error.message).toBe('Response code 400 (Bad Request)');
|
|
80
|
-
expect(
|
|
81
|
-
const responseJson = JSON.parse(
|
|
81
|
+
expect(error.response?.statusCode).toBe(400);
|
|
82
|
+
const responseJson = JSON.parse(error.response?.body);
|
|
82
83
|
expect(responseJson.errors[0].params.missingProperty).toEqual('foo');
|
|
83
84
|
expect(responseJson.errors[1].params.missingProperty).toEqual('bar');
|
|
84
85
|
expect(responseJson.errors[2].params.missingProperty).toEqual('baz');
|
|
@@ -88,7 +89,6 @@ describe('Validation integration tests', () => {
|
|
|
88
89
|
});
|
|
89
90
|
it('Should validate url', async () => {
|
|
90
91
|
await (0, utils_1.usingAsync)(await createValidateApi(), async ({ client }) => {
|
|
91
|
-
var _a, _b;
|
|
92
92
|
expect.assertions(4);
|
|
93
93
|
try {
|
|
94
94
|
await client({
|
|
@@ -100,8 +100,8 @@ describe('Validation integration tests', () => {
|
|
|
100
100
|
catch (error) {
|
|
101
101
|
if (error instanceof source_1.RequestError) {
|
|
102
102
|
expect(error.message).toBe('Response code 400 (Bad Request)');
|
|
103
|
-
expect(
|
|
104
|
-
const responseJson = JSON.parse(
|
|
103
|
+
expect(error.response?.statusCode).toBe(400);
|
|
104
|
+
const responseJson = JSON.parse(error.response?.body);
|
|
105
105
|
expect(responseJson.errors[0].params.type).toEqual('number');
|
|
106
106
|
expect(responseJson.errors[0].instancePath).toEqual('/url/id');
|
|
107
107
|
}
|
|
@@ -110,7 +110,6 @@ describe('Validation integration tests', () => {
|
|
|
110
110
|
});
|
|
111
111
|
it('Should validate headers', async () => {
|
|
112
112
|
await (0, utils_1.usingAsync)(await createValidateApi(), async ({ client }) => {
|
|
113
|
-
var _a, _b;
|
|
114
113
|
expect.assertions(3);
|
|
115
114
|
try {
|
|
116
115
|
await client({
|
|
@@ -122,8 +121,8 @@ describe('Validation integration tests', () => {
|
|
|
122
121
|
catch (error) {
|
|
123
122
|
if (error instanceof source_1.RequestError) {
|
|
124
123
|
expect(error.message).toBe('Response code 400 (Bad Request)');
|
|
125
|
-
expect(
|
|
126
|
-
const responseJson = JSON.parse(
|
|
124
|
+
expect(error.response?.statusCode).toBe(400);
|
|
125
|
+
const responseJson = JSON.parse(error.response?.body);
|
|
127
126
|
expect(responseJson.errors.find((e) => e.keyword === 'required' && e.message.includes('foo'))).toBeDefined();
|
|
128
127
|
}
|
|
129
128
|
}
|
|
@@ -131,7 +130,6 @@ describe('Validation integration tests', () => {
|
|
|
131
130
|
});
|
|
132
131
|
it('Should validate body', async () => {
|
|
133
132
|
await (0, utils_1.usingAsync)(await createValidateApi(), async ({ client }) => {
|
|
134
|
-
var _a, _b;
|
|
135
133
|
expect.assertions(3);
|
|
136
134
|
try {
|
|
137
135
|
await client({
|
|
@@ -143,8 +141,8 @@ describe('Validation integration tests', () => {
|
|
|
143
141
|
catch (error) {
|
|
144
142
|
if (error instanceof source_1.RequestError) {
|
|
145
143
|
expect(error.message).toBe('Response code 400 (Bad Request)');
|
|
146
|
-
expect(
|
|
147
|
-
const responseJson = JSON.parse(
|
|
144
|
+
expect(error.response?.statusCode).toBe(400);
|
|
145
|
+
const responseJson = JSON.parse(error.response?.body);
|
|
148
146
|
expect(responseJson.errors[0].params.missingProperty).toEqual('body');
|
|
149
147
|
}
|
|
150
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.integration.spec.js","sourceRoot":"","sources":["../src/validate.integration.spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.integration.spec.js","sourceRoot":"","sources":["../src/validate.integration.spec.ts"],"names":[],"mappings":";;;;;AAAA,8CAA4C;AAC5C,gEAAyD;AACzD,4CAA6C;AAC7C,4CAA8C;AAC9C,mFAA4D;AAC5D,yCAAqC;AACrC,qBAAkB;AAElB,oHAA4D;AAE5D,uCAA0C;AAE1C,6MAA6M;AAE7M,MAAM,iBAAiB,GAAG,KAAK,IAAI,EAAE;IACnC,MAAM,QAAQ,GAAG,IAAI,iBAAQ,EAAE,CAAA;IAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,KAAK,CAAA;IACrD,IAAA,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}
|
package/dist/validate.js
CHANGED
|
@@ -5,25 +5,23 @@ const schema_validator_1 = require("./schema-validator");
|
|
|
5
5
|
const Validate = (validationOptions) => (action) => {
|
|
6
6
|
const schema = { ...validationOptions.schema };
|
|
7
7
|
Object.values(schema.definitions).forEach((definition) => {
|
|
8
|
-
var _a;
|
|
9
8
|
if (definition.required && definition.required.includes('result')) {
|
|
10
9
|
definition.required = definition.required.filter((value) => value !== 'result');
|
|
11
10
|
}
|
|
12
11
|
definition.additionalProperties = true;
|
|
13
|
-
if (
|
|
12
|
+
if (definition.properties?.headers) {
|
|
14
13
|
definition.properties.headers.additionalProperties = true;
|
|
15
14
|
}
|
|
16
15
|
});
|
|
17
16
|
const validator = new schema_validator_1.SchemaValidator(schema, { coerceTypes: true, strict: false });
|
|
18
17
|
return async (args) => {
|
|
19
|
-
var _a, _b, _c;
|
|
20
18
|
const anyArgs = args;
|
|
21
19
|
let body;
|
|
22
20
|
const { headers } = anyArgs;
|
|
23
|
-
const query =
|
|
24
|
-
const url =
|
|
21
|
+
const query = anyArgs.getQuery?.();
|
|
22
|
+
const url = anyArgs.getUrlParams?.();
|
|
25
23
|
try {
|
|
26
|
-
body = await
|
|
24
|
+
body = await anyArgs.getBody?.();
|
|
27
25
|
}
|
|
28
26
|
catch (error) {
|
|
29
27
|
// ignore
|
package/dist/validate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":";;;AACA,yDAAoD;AAE7C,MAAM,QAAQ,GACnB,CAAkF,iBASjF,EAAE,EAAE,CACL,CAA4B,MAAwB,EAAoB,EAAE;IACxE,MAAM,MAAM,GAAG,EAAE,GAAG,iBAAiB,CAAC,MAAM,EAAE,CAAA;IAE9C,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE
|
|
1
|
+
{"version":3,"file":"validate.js","source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AS;SACV;QACD,SAAS,CAAC,OAAO,CACf;YACE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3B,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzB,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACvB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,EACD,EAAE,UAAU,EAAE,iBAAiB,CAAC,UAAU,EAAE,CAC7C,CAAA;QACD,OAAO,MAAM,MAAM,CAAC;YAClB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO;YACP,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK;YACrB,YAAY,EAAE,GAAG,EAAE,CAAC,GAAG;YACvB,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC;SAC9B,CAAC,CAAA;IACX,CAAC,CAAA;AACH,CAAC,CAAA;AAxDU,QAAA,QAAQ,YAwDlB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@furystack/rest-service",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.2",
|
|
4
4
|
"description": "Repository implementation for FuryStack",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -29,23 +29,22 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/furystack/furystack",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@furystack/core": "^11.0.
|
|
33
|
-
"@furystack/inject": "^7.0.
|
|
34
|
-
"@furystack/logging": "^3.0.
|
|
35
|
-
"@furystack/repository": "^6.0.
|
|
36
|
-
"@furystack/rest": "^4.0.
|
|
37
|
-
"@furystack/security": "^2.0.
|
|
38
|
-
"@furystack/utils": "^3.0.
|
|
32
|
+
"@furystack/core": "^11.0.10",
|
|
33
|
+
"@furystack/inject": "^7.0.4",
|
|
34
|
+
"@furystack/logging": "^3.0.8",
|
|
35
|
+
"@furystack/repository": "^6.0.10",
|
|
36
|
+
"@furystack/rest": "^4.0.9",
|
|
37
|
+
"@furystack/security": "^2.0.10",
|
|
38
|
+
"@furystack/utils": "^3.0.8",
|
|
39
39
|
"ajv": "^8.11.0",
|
|
40
40
|
"ajv-formats": "^2.1.1",
|
|
41
41
|
"path-to-regexp": "^6.2.1",
|
|
42
|
-
"semaphore-async-await": "^1.5.1"
|
|
43
|
-
"tslib": "^2.4.0"
|
|
42
|
+
"semaphore-async-await": "^1.5.1"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
|
-
"@furystack/rest-client-got": "^2.0.
|
|
47
|
-
"@types/jest": "^
|
|
48
|
-
"@types/node": "^18.
|
|
45
|
+
"@furystack/rest-client-got": "^2.0.11",
|
|
46
|
+
"@types/jest": "^29.0.0",
|
|
47
|
+
"@types/node": "^18.7.14",
|
|
49
48
|
"got": "^11.8.5"
|
|
50
49
|
},
|
|
51
50
|
"typings": "./types/index.d.ts",
|
package/src/helpers.spec.ts
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import { Injector } from '@furystack/inject'
|
|
2
2
|
import { usingAsync } from '@furystack/utils'
|
|
3
|
-
import {
|
|
3
|
+
import { ApiManager } from './api-manager'
|
|
4
|
+
import { HttpAuthenticationSettings } from './http-authentication-settings'
|
|
5
|
+
import { useHttpAuthentication, useRestService, useStaticFiles } from './helpers'
|
|
6
|
+
import { StaticServerManager } from './static-server-manager'
|
|
4
7
|
|
|
5
8
|
describe('Injector extensions', () => {
|
|
6
9
|
describe('useHttpAuthentication', () => {
|
|
7
10
|
it('Should set up HTTP Authentication', async () => {
|
|
8
11
|
await usingAsync(new Injector(), async (i) => {
|
|
9
12
|
useHttpAuthentication(i)
|
|
10
|
-
|
|
13
|
+
expect(i.cachedSingletons.get(HttpAuthenticationSettings)).toBeDefined()
|
|
11
14
|
})
|
|
12
15
|
})
|
|
13
16
|
})
|
|
14
17
|
|
|
15
18
|
describe('useRestService()', () => {
|
|
16
|
-
it
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
it('Should set up a REST service', async () => {
|
|
20
|
+
await usingAsync(new Injector(), async (i) => {
|
|
21
|
+
await useRestService({ injector: i, api: {}, root: '/', port: 1234 })
|
|
22
|
+
expect(i.cachedSingletons.get(ApiManager)).toBeDefined()
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('useRestService()', () => {
|
|
28
|
+
it('Should set up a REST service', async () => {
|
|
29
|
+
await usingAsync(new Injector(), async (i) => {
|
|
30
|
+
await useStaticFiles({ injector: i, baseUrl: '/', path: '.', port: 1234 })
|
|
31
|
+
expect(i.cachedSingletons.get(StaticServerManager)).toBeDefined()
|
|
32
|
+
})
|
|
33
|
+
})
|
|
23
34
|
})
|
|
24
35
|
})
|