@furystack/rest-service 6.0.7 → 6.1.1

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.
Files changed (38) hide show
  1. package/dist/helpers.js +15 -1
  2. package/dist/helpers.js.map +1 -1
  3. package/dist/helpers.spec.js +18 -2
  4. package/dist/helpers.spec.js.map +1 -1
  5. package/dist/index.js +2 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/mime-types.js +339 -0
  8. package/dist/mime-types.js.map +1 -0
  9. package/dist/mime-types.spec.js +15 -0
  10. package/dist/mime-types.spec.js.map +1 -0
  11. package/dist/server-manager.js.map +1 -1
  12. package/dist/static-server-manager.js +66 -0
  13. package/dist/static-server-manager.js.map +1 -0
  14. package/dist/static-server-manager.spec.js +186 -0
  15. package/dist/static-server-manager.spec.js.map +1 -0
  16. package/package.json +11 -11
  17. package/src/helpers.spec.ts +20 -9
  18. package/src/helpers.ts +14 -0
  19. package/src/index.ts +2 -0
  20. package/src/mime-types.spec.ts +14 -0
  21. package/src/mime-types.ts +336 -0
  22. package/src/server-manager.ts +6 -1
  23. package/src/static-server-manager.spec.ts +226 -0
  24. package/src/static-server-manager.ts +89 -0
  25. package/types/helpers.d.ts +12 -0
  26. package/types/helpers.d.ts.map +1 -1
  27. package/types/index.d.ts +2 -0
  28. package/types/index.d.ts.map +1 -1
  29. package/types/mime-types.d.ts +305 -0
  30. package/types/mime-types.d.ts.map +1 -0
  31. package/types/mime-types.spec.d.ts +2 -0
  32. package/types/mime-types.spec.d.ts.map +1 -0
  33. package/types/server-manager.d.ts +5 -4
  34. package/types/server-manager.d.ts.map +1 -1
  35. package/types/static-server-manager.d.ts +20 -0
  36. package/types/static-server-manager.d.ts.map +1 -0
  37. package/types/static-server-manager.spec.d.ts +2 -0
  38. package/types/static-server-manager.spec.d.ts.map +1 -0
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const inject_1 = require("@furystack/inject");
5
+ const utils_1 = require("@furystack/utils");
6
+ const got_1 = tslib_1.__importStar(require("got"));
7
+ const server_manager_1 = require("./server-manager");
8
+ const static_server_manager_1 = require("./static-server-manager");
9
+ describe('StaticServerManager', () => {
10
+ describe('Top level routing', () => {
11
+ it('Should return a 404 without fallback', async () => {
12
+ await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
13
+ var _a, _b, _c;
14
+ const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
15
+ await staticServerManager.addStaticSite({
16
+ baseUrl: '/',
17
+ path: '.',
18
+ port: 1234,
19
+ });
20
+ try {
21
+ await got_1.default.get('http://localhost:1234/not-found.html');
22
+ }
23
+ catch (error) {
24
+ expect(error).toBeInstanceOf(got_1.RequestError);
25
+ const requestError = error;
26
+ expect((_a = requestError.response) === null || _a === void 0 ? void 0 : _a.statusCode).toBe(404);
27
+ expect((_b = requestError.response) === null || _b === void 0 ? void 0 : _b.headers['content-type']).toBe('text/plain');
28
+ expect((_c = requestError.response) === null || _c === void 0 ? void 0 : _c.body).toBe('Not found');
29
+ }
30
+ });
31
+ });
32
+ it('Should return a fallback', async () => {
33
+ await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
34
+ const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
35
+ await staticServerManager.addStaticSite({
36
+ baseUrl: '/',
37
+ path: '.',
38
+ fallback: 'package.json',
39
+ port: 1234,
40
+ headers: {
41
+ 'custom-header': 'custom-value',
42
+ },
43
+ });
44
+ const result = await got_1.default.get('http://localhost:1234/not-found.html');
45
+ expect(result.headers['content-type']).toBe('application/json');
46
+ expect(result.headers['custom-header']).toBe('custom-value');
47
+ });
48
+ });
49
+ it('Should return a defined file from a root directory', async () => {
50
+ await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
51
+ const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
52
+ await staticServerManager.addStaticSite({
53
+ baseUrl: '/',
54
+ path: '.',
55
+ port: 1234,
56
+ headers: {
57
+ 'custom-header': 'custom-value',
58
+ },
59
+ });
60
+ const result = await got_1.default.get('http://localhost:1234/README.md');
61
+ expect(result.headers['content-type']).toBe('text/markdown');
62
+ expect(result.headers['custom-header']).toBe('custom-value');
63
+ });
64
+ });
65
+ it('Should return a defined file from a subdirectory', async () => {
66
+ await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
67
+ const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
68
+ await staticServerManager.addStaticSite({
69
+ baseUrl: '/',
70
+ path: '.',
71
+ port: 1234,
72
+ });
73
+ const result = await got_1.default.get('http://localhost:1234/packages/utils/README.md');
74
+ expect(result.headers['content-type']).toBe('text/markdown');
75
+ });
76
+ });
77
+ });
78
+ describe('Non-top level routing', () => {
79
+ it('Should not handle a request when the path is not matching', async () => {
80
+ await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
81
+ const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
82
+ await staticServerManager.addStaticSite({
83
+ baseUrl: '/bundle',
84
+ path: '.',
85
+ port: 1234,
86
+ });
87
+ const server = [...injector.getInstance(server_manager_1.ServerManager).servers.values()][0];
88
+ server.apis[0].onRequest = jest.fn();
89
+ got_1.default.get('http://localhost:1234/bundleToAnotherFolder/not-found.html');
90
+ await (0, utils_1.sleepAsync)(100);
91
+ expect(server.apis[0].onRequest).not.toHaveBeenCalled();
92
+ });
93
+ });
94
+ it('Should return a 404 without fallback', async () => {
95
+ await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
96
+ var _a, _b, _c;
97
+ const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
98
+ await staticServerManager.addStaticSite({
99
+ baseUrl: '/bundle',
100
+ path: '.',
101
+ port: 1234,
102
+ });
103
+ try {
104
+ await got_1.default.get('http://localhost:1234/bundle/not-found.html');
105
+ }
106
+ catch (error) {
107
+ expect(error).toBeInstanceOf(got_1.RequestError);
108
+ const requestError = error;
109
+ expect((_a = requestError.response) === null || _a === void 0 ? void 0 : _a.statusCode).toBe(404);
110
+ expect((_b = requestError.response) === null || _b === void 0 ? void 0 : _b.headers['content-type']).toBe('text/plain');
111
+ expect((_c = requestError.response) === null || _c === void 0 ? void 0 : _c.body).toBe('Not found');
112
+ }
113
+ });
114
+ });
115
+ it('Should return a 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
+ fallback: 'package.json',
122
+ port: 1234,
123
+ });
124
+ const result = await got_1.default.get('http://localhost:1234/bundle/not-found.html');
125
+ expect(result.headers['content-type']).toBe('application/json');
126
+ });
127
+ });
128
+ it('Should return a defined file from a root directory', async () => {
129
+ await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
130
+ const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
131
+ await staticServerManager.addStaticSite({
132
+ baseUrl: '/',
133
+ path: '.',
134
+ port: 1234,
135
+ });
136
+ const result = await got_1.default.get('http://localhost:1234/README.md');
137
+ expect(result.headers['content-type']).toBe('text/markdown');
138
+ });
139
+ });
140
+ it('Should return a defined file from a subdirectory', async () => {
141
+ await (0, utils_1.usingAsync)(new inject_1.Injector(), async (injector) => {
142
+ const staticServerManager = injector.getInstance(static_server_manager_1.StaticServerManager);
143
+ await staticServerManager.addStaticSite({
144
+ baseUrl: '/',
145
+ path: '.',
146
+ port: 1234,
147
+ });
148
+ const result = await got_1.default.get('http://localhost:1234/packages/utils/README.md');
149
+ expect(result.headers['content-type']).toBe('text/markdown');
150
+ });
151
+ });
152
+ });
153
+ describe('shouldExec', () => {
154
+ it('Should NOT match for requests with not defined method', () => {
155
+ const staticServerManager = new static_server_manager_1.StaticServerManager();
156
+ expect(staticServerManager.shouldExec('/')({ req: { url: '/' } })).toBe(false);
157
+ });
158
+ it('Should NOT match for non-GET requests', () => {
159
+ const staticServerManager = new static_server_manager_1.StaticServerManager();
160
+ expect(staticServerManager.shouldExec('/')({ req: { method: 'POST', url: '/' } })).toBe(false);
161
+ });
162
+ [
163
+ ['/', '/'],
164
+ ['/', '/index.html'],
165
+ ['/', '/subdir'],
166
+ ['/', '/subdir/'],
167
+ ['/', '/subdir/file.js'],
168
+ ['/subdir', '/subdir'],
169
+ ['/subdir', '/subdir/'],
170
+ ['/subdir', '/subdir/file.js'],
171
+ ['/subdir', '/subdir/s2/file.js'],
172
+ ].forEach(([root, url]) => it(`Should match for '${root}' root and '${url}' url`, () => {
173
+ const staticServerManager = new static_server_manager_1.StaticServerManager();
174
+ const shouldExec = staticServerManager.shouldExec(root)({ req: { method: 'GET', url } });
175
+ expect(shouldExec).toBe(true);
176
+ }));
177
+ it('Should not exec different paths for non-top level root directory', () => {
178
+ const staticServerManager = new static_server_manager_1.StaticServerManager();
179
+ expect(staticServerManager.shouldExec('/subdir')({ req: { method: 'GET', url: '/' } })).toBe(false);
180
+ expect(staticServerManager.shouldExec('/subdir')({ req: { method: 'GET', url: '/other/index.html' } })).toBe(false);
181
+ expect(staticServerManager.shouldExec('/subdir')({ req: { method: 'GET', url: '/subdir2' } })).toBe(false);
182
+ expect(staticServerManager.shouldExec('/subdir')({ req: { method: 'GET', url: '/subdir2/index.html' } })).toBe(false);
183
+ });
184
+ });
185
+ });
186
+ //# 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,mDAAuC;AACvC,qDAAgD;AAChD,mEAA6D;AAE7D,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACnC,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;QACjC,EAAE,CAAC,sCAAsC,EAAE,KAA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BAAmB,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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@furystack/rest-service",
3
- "version": "6.0.7",
3
+ "version": "6.1.1",
4
4
  "description": "Repository implementation for FuryStack",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -29,13 +29,13 @@
29
29
  },
30
30
  "homepage": "https://github.com/furystack/furystack",
31
31
  "dependencies": {
32
- "@furystack/core": "^11.0.6",
33
- "@furystack/inject": "^7.0.1",
34
- "@furystack/logging": "^3.0.5",
35
- "@furystack/repository": "^6.0.6",
36
- "@furystack/rest": "^4.0.5",
37
- "@furystack/security": "^2.0.6",
38
- "@furystack/utils": "^3.0.5",
32
+ "@furystack/core": "^11.0.9",
33
+ "@furystack/inject": "^7.0.3",
34
+ "@furystack/logging": "^3.0.7",
35
+ "@furystack/repository": "^6.0.9",
36
+ "@furystack/rest": "^4.0.8",
37
+ "@furystack/security": "^2.0.9",
38
+ "@furystack/utils": "^3.0.7",
39
39
  "ajv": "^8.11.0",
40
40
  "ajv-formats": "^2.1.1",
41
41
  "path-to-regexp": "^6.2.1",
@@ -43,9 +43,9 @@
43
43
  "tslib": "^2.4.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@furystack/rest-client-got": "^2.0.7",
47
- "@types/jest": "^28.1.4",
48
- "@types/node": "^18.0.3",
46
+ "@furystack/rest-client-got": "^2.0.10",
47
+ "@types/jest": "^28.1.8",
48
+ "@types/node": "^18.7.13",
49
49
  "got": "^11.8.5"
50
50
  },
51
51
  "typings": "./types/index.d.ts",
@@ -1,24 +1,35 @@
1
1
  import { Injector } from '@furystack/inject'
2
2
  import { usingAsync } from '@furystack/utils'
3
- import { useHttpAuthentication } from './helpers'
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
- // TODO: Check if HTTP Auth has been set up
13
+ expect(i.cachedSingletons.get(HttpAuthenticationSettings)).toBeDefined()
11
14
  })
12
15
  })
13
16
  })
14
17
 
15
18
  describe('useRestService()', () => {
16
- it.todo(
17
- 'Should set up a REST service',
18
- // await usingAsync(new Injector(), async (i) => {
19
- // useRestService({ injector: i, api: {}, })
20
- // TODO: Assert if REST service has been set up
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
  })
package/src/helpers.ts CHANGED
@@ -4,6 +4,7 @@ import { HttpAuthenticationSettings } from './http-authentication-settings'
4
4
  import { RestApi } from '@furystack/rest'
5
5
  import { ApiManager, ImplementApiOptions } from './api-manager'
6
6
  import { DefaultSession } from './models/default-session'
7
+ import { StaticServerManager, StaticServerOptions } from './static-server-manager'
7
8
 
8
9
  /**
9
10
  * Sets up the @furystack/rest-service with the provided settings
@@ -26,3 +27,16 @@ export const useHttpAuthentication = <TUser extends User, TSession extends Defau
26
27
  injector: Injector,
27
28
  settings?: Partial<HttpAuthenticationSettings<TUser, TSession>>,
28
29
  ) => injector.setExplicitInstance({ ...new HttpAuthenticationSettings(), ...settings }, HttpAuthenticationSettings)
30
+
31
+ /**
32
+ * Sets up a static file server
33
+ *
34
+ * @param options The settings for the static file server
35
+ * @param options.injector The Injector instance
36
+ * @param options.settings Settings for the static file server
37
+ * @returns a promise that resolves when the server is ready
38
+ */
39
+ export const useStaticFiles = (options: { injector: Injector } & StaticServerOptions) => {
40
+ const { injector, ...settings } = options
41
+ return injector.getInstance(StaticServerManager).addStaticSite(settings)
42
+ }
package/src/index.ts CHANGED
@@ -14,3 +14,5 @@ export * from './endpoint-generators'
14
14
  export * from './schema-validator'
15
15
  export * from './request-action-implementation'
16
16
  export * from './validate'
17
+ export * from './mime-types'
18
+ export * from './static-server-manager'
@@ -0,0 +1,14 @@
1
+ import { getMimeForFile } from './mime-types'
2
+ describe('MIME Types', () => {
3
+ it('Should return a default fallback', () => {
4
+ expect(getMimeForFile('test.alma')).toBe('application/octet-stream')
5
+ })
6
+
7
+ it('Should return a value from a supported list', () => {
8
+ expect(getMimeForFile('asd/123/test.mp4')).toBe('video/mp4')
9
+ })
10
+
11
+ it('Should return a value from a wildcarded entry list', () => {
12
+ expect(getMimeForFile('asd/123/test.asdxml')).toBe('text/xml')
13
+ })
14
+ })