@furystack/rest-service 9.0.6 → 10.0.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.
- package/esm/actions/login-action.spec.js +2 -2
- package/esm/actions/login-action.spec.js.map +1 -1
- package/esm/actions/logout-action.spec.js +1 -1
- package/esm/actions/logout-action.spec.js.map +1 -1
- package/esm/add-cors-header.d.ts +0 -3
- package/esm/add-cors-header.d.ts.map +1 -1
- package/esm/api-manager.d.ts +6 -7
- package/esm/api-manager.d.ts.map +1 -1
- package/esm/api-manager.js +8 -8
- package/esm/api-manager.js.map +1 -1
- package/esm/authenticate.d.ts.map +1 -1
- package/esm/authenticate.js.map +1 -1
- package/esm/authorize.d.ts.map +1 -1
- package/esm/endpoint-generators/create-delete-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-get-collection-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-get-entity-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-patch-endpoint.d.ts.map +1 -1
- package/esm/endpoint-generators/create-post-endpoint.d.ts.map +1 -1
- package/esm/helpers.d.ts.map +1 -1
- package/esm/http-user-context.d.ts +0 -3
- package/esm/http-user-context.d.ts.map +1 -1
- package/esm/http-user-context.spec.js.map +1 -1
- package/esm/read-post-body.d.ts +0 -2
- package/esm/read-post-body.d.ts.map +1 -1
- package/esm/read-post-body.js.map +1 -1
- package/esm/request-action-implementation.d.ts +1 -5
- package/esm/request-action-implementation.d.ts.map +1 -1
- package/esm/request-action-implementation.js.map +1 -1
- package/esm/rest-service.integration.spec.d.ts.map +1 -1
- package/esm/rest-service.integration.spec.js +8 -8
- package/esm/rest-service.integration.spec.js.map +1 -1
- package/esm/rest.integration.test.d.ts +1 -1
- package/esm/rest.integration.test.d.ts.map +1 -1
- package/esm/rest.integration.test.js +7 -7
- package/esm/rest.integration.test.js.map +1 -1
- package/esm/server-manager.d.ts +4 -10
- package/esm/server-manager.d.ts.map +1 -1
- package/esm/server-manager.js +1 -1
- package/esm/server-manager.js.map +1 -1
- package/esm/static-server-manager.d.ts +1 -5
- package/esm/static-server-manager.d.ts.map +1 -1
- package/esm/validate.d.ts +1 -1
- package/esm/validate.d.ts.map +1 -1
- package/esm/validate.integration.spec.js +7 -7
- package/esm/validate.integration.spec.js.map +1 -1
- package/package.json +13 -13
- package/src/actions/login-action.spec.ts +4 -4
- package/src/actions/logout-action.spec.ts +3 -3
- package/src/api-manager.ts +19 -21
- package/src/authenticate.ts +1 -1
- package/src/http-user-context.spec.ts +2 -2
- package/src/read-post-body.ts +1 -1
- package/src/request-action-implementation.ts +1 -2
- package/src/rest-service.integration.spec.ts +9 -9
- package/src/rest.integration.test.ts +8 -8
- package/src/server-manager.ts +5 -7
- package/src/validate.integration.spec.ts +8 -8
package/esm/server-manager.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference path="incoming-message-extensions.d.ts" />
|
|
3
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
-
/// <reference types="node/http.js" />
|
|
5
|
-
import type { Disposable } from '@furystack/utils';
|
|
6
|
-
import type { Server } from 'http';
|
|
7
|
-
import type { IncomingMessage, ServerResponse } from 'http';
|
|
1
|
+
import type { IncomingMessage, Server, ServerResponse } from 'http';
|
|
8
2
|
export interface ServerOptions {
|
|
9
3
|
hostName?: string;
|
|
10
4
|
port: number;
|
|
@@ -15,20 +9,20 @@ export interface OnRequest {
|
|
|
15
9
|
}
|
|
16
10
|
export interface ServerApi {
|
|
17
11
|
shouldExec: (options: OnRequest) => boolean;
|
|
18
|
-
onRequest: (options: OnRequest) => void
|
|
12
|
+
onRequest: (options: OnRequest) => Promise<void>;
|
|
19
13
|
}
|
|
20
14
|
export interface ServerRecord {
|
|
21
15
|
server: Server;
|
|
22
16
|
apis: ServerApi[];
|
|
23
17
|
}
|
|
24
|
-
export declare class ServerManager implements
|
|
18
|
+
export declare class ServerManager implements AsyncDisposable {
|
|
25
19
|
static DEFAULT_HOST: string;
|
|
26
20
|
servers: Map<string, ServerRecord>;
|
|
27
21
|
private openedSockets;
|
|
28
22
|
private readonly listenLock;
|
|
29
23
|
private getHostUrl;
|
|
30
24
|
private onConnection;
|
|
31
|
-
|
|
25
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
32
26
|
getOrCreate(options: ServerOptions): Promise<ServerRecord>;
|
|
33
27
|
}
|
|
34
28
|
//# sourceMappingURL=server-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-manager.d.ts","sourceRoot":"","sources":["../src/server-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-manager.d.ts","sourceRoot":"","sources":["../src/server-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,MAAM,CAAA;AAKnE,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,eAAe,CAAA;IACpB,GAAG,EAAE,cAAc,CAAA;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,OAAO,CAAA;IAC3C,SAAS,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACjD;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,SAAS,EAAE,CAAA;CAClB;AAED,qBACa,aAAc,YAAW,eAAe;IACnD,OAAc,YAAY,SAAc;IAEjC,OAAO,4BAAkC;IAChD,OAAO,CAAC,aAAa,CAAoB;IAEzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IAExC,OAAO,CAAC,UAAU,CAC0D;IAE5E,OAAO,CAAC,YAAY,CAGnB;IAEY,CAAC,MAAM,CAAC,YAAY,CAAC;IAmBrB,WAAW,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;CA6BxE"}
|
package/esm/server-manager.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-manager.js","sourceRoot":"","sources":["../src/server-manager.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"server-manager.js","sourceRoot":"","sources":["../src/server-manager.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAEnC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAuBrC,IAAM,aAAa,GAAnB,MAAM,aAAa;;IACjB,MAAM,CAAC,YAAY,GAAG,WAAW,CAAA;IAEjC,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAA;IACxC,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;IAExB,UAAU,GAAG,IAAI,IAAI,EAAE,CAAA;IAEhC,UAAU,GAAG,CAAC,OAAsB,EAAE,EAAE,CAC9C,UAAU,OAAO,CAAC,QAAQ,IAAI,eAAa,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,EAAE,CAAA;IAEpE,YAAY,GAAG,CAAC,MAAc,EAAE,EAAE;QACxC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAC9B,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;IAC/D,CAAC,CAAA;IAEM,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QAChC,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,C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ference path="incoming-message-extensions.d.ts" />
|
|
3
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
4
|
-
/// <reference types="node/http.js" />
|
|
5
1
|
import type { IncomingMessage, OutgoingHttpHeaders } from 'http';
|
|
6
2
|
export interface StaticServerOptions {
|
|
7
3
|
baseUrl: string;
|
|
@@ -15,7 +11,7 @@ export declare class StaticServerManager {
|
|
|
15
11
|
private readonly serverManager;
|
|
16
12
|
private sendFile;
|
|
17
13
|
shouldExec: (baseUrl: string) => ({ req }: {
|
|
18
|
-
req: Pick<IncomingMessage,
|
|
14
|
+
req: Pick<IncomingMessage, "url" | "method">;
|
|
19
15
|
}) => boolean;
|
|
20
16
|
private onRequest;
|
|
21
17
|
addStaticSite(options: StaticServerOptions): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-server-manager.d.ts","sourceRoot":"","sources":["../src/static-server-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"static-server-manager.d.ts","sourceRoot":"","sources":["../src/static-server-manager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAkB,MAAM,MAAM,CAAA;AAKhF,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,mBAAmB,CAAA;CAC9B;AAED,qBACa,mBAAmB;IAC9B,iBACyB,aAAa,CAAe;YAEvC,QAAQ;IAwBf,UAAU,YACL,MAAM,eACN;QAAE,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,KAAK,GAAG,QAAQ,CAAC,CAAA;KAAE,aAK/C;IAEb,OAAO,CAAC,SAAS,CA0BhB;IAEY,aAAa,CAAC,OAAO,EAAE,mBAAmB;CAQxD"}
|
package/esm/validate.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare const Validate: <TSchema extends {
|
|
|
13
13
|
/**
|
|
14
14
|
* Entity key from the JSON Schema object
|
|
15
15
|
*/
|
|
16
|
-
schemaName: keyof TSchema[
|
|
16
|
+
schemaName: keyof TSchema["definitions"];
|
|
17
17
|
}) => <T extends {
|
|
18
18
|
result: any;
|
|
19
19
|
}>(action: RequestAction<T>) => RequestAction<T>;
|
package/esm/validate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,oCAAoC,CAAA;AAG3G,eAAO,MAAM,QAAQ;
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,aAAa,EAAwB,MAAM,oCAAoC,CAAA;AAG3G,eAAO,MAAM,QAAQ,GAClB,OAAO,SAAS;IAAE,WAAW,EAAE;QAAE,CAAC,CAAC,EAAE,MAAM,GAAG;YAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;SAAE,GAAG,GAAG,CAAA;KAAE,CAAA;CAAE,qBAAqB;IACnG;;OAEG;IACH,MAAM,EAAE,OAAO,CAAA;IACf;;OAEG;IACH,UAAU,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,CAAA;CACzC,MACA,CAAC,SAAS;IAAE,MAAM,EAAE,GAAG,CAAA;CAAE,UAAU,aAAa,CAAC,CAAC,CAAC,KAAG,aAAa,CAAC,CAAC,CA6CrE,CAAA"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import { getStoreManager, InMemoryStore, User } from '@furystack/core';
|
|
2
|
+
import { getPort } from '@furystack/core/port-generator';
|
|
1
3
|
import { Injector } from '@furystack/inject';
|
|
2
4
|
import { createClient, ResponseError } from '@furystack/rest-client-fetch';
|
|
3
5
|
import { usingAsync } from '@furystack/utils';
|
|
4
|
-
import {
|
|
5
|
-
import { Validate } from './validate.js';
|
|
6
|
-
import schema from './validate.integration.spec.schema.json' with { type: 'json' };
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
7
|
import { useRestService } from './helpers.js';
|
|
8
|
-
import { describe, it, expect } from 'vitest';
|
|
9
|
-
import { getPort } from '@furystack/core/port-generator';
|
|
10
|
-
import { getStoreManager, InMemoryStore, User } from '@furystack/core';
|
|
11
8
|
import { DefaultSession } from './models/default-session.js';
|
|
9
|
+
import { JsonResult } from './request-action-implementation.js';
|
|
10
|
+
import schema from './validate.integration.spec.schema.json' with { type: 'json' };
|
|
11
|
+
import { Validate } from './validate.js';
|
|
12
12
|
// 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
|
|
13
13
|
const createValidateApi = async () => {
|
|
14
14
|
const injector = new Injector();
|
|
@@ -58,7 +58,7 @@ const createValidateApi = async () => {
|
|
|
58
58
|
endpointUrl: `http://127.0.0.1:${port}/api`,
|
|
59
59
|
});
|
|
60
60
|
return {
|
|
61
|
-
|
|
61
|
+
[Symbol.asyncDispose]: injector[Symbol.asyncDispose].bind(injector),
|
|
62
62
|
client,
|
|
63
63
|
};
|
|
64
64
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.integration.spec.js","sourceRoot":"","sources":["../src/validate.integration.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"validate.integration.spec.js","sourceRoot":"","sources":["../src/validate.integration.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAm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AC,MAAM,iBAAiB,EAAE,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC/D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC;oBAC1B,MAAM,EAAE,MAAM;oBACd,MAAM,EAAE,gBAAgB;oBACxB,IAAI,EAAE;wBACJ,GAAG,EAAE,KAAK;wBACV,GAAG,EAAE,EAAE;wBACP,GAAG,EAAE,IAAI;qBACV;iBACF,CAAC,CAAA;gBAEF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;gBACxC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACrC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAClC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACtC,CAAC,CAAC,CAAA;QACJ,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": "
|
|
3
|
+
"version": "10.0.1",
|
|
4
4
|
"description": "Repository implementation for FuryStack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -37,22 +37,22 @@
|
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/furystack/furystack",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@furystack/core": "^
|
|
41
|
-
"@furystack/inject": "^
|
|
42
|
-
"@furystack/repository": "^
|
|
43
|
-
"@furystack/rest": "^
|
|
44
|
-
"@furystack/security": "^
|
|
45
|
-
"@furystack/utils": "^
|
|
46
|
-
"ajv": "^8.
|
|
40
|
+
"@furystack/core": "^15.0.1",
|
|
41
|
+
"@furystack/inject": "^12.0.1",
|
|
42
|
+
"@furystack/repository": "^10.0.1",
|
|
43
|
+
"@furystack/rest": "^8.0.1",
|
|
44
|
+
"@furystack/security": "^6.0.1",
|
|
45
|
+
"@furystack/utils": "^8.0.1",
|
|
46
|
+
"ajv": "^8.17.1",
|
|
47
47
|
"ajv-formats": "^3.0.1",
|
|
48
|
-
"path-to-regexp": "^
|
|
48
|
+
"path-to-regexp": "^7.1.0",
|
|
49
49
|
"semaphore-async-await": "^1.5.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@furystack/rest-client-fetch": "^
|
|
53
|
-
"@types/node": "^20.14.
|
|
54
|
-
"typescript": "^5.
|
|
55
|
-
"vitest": "^
|
|
52
|
+
"@furystack/rest-client-fetch": "^8.0.1",
|
|
53
|
+
"@types/node": "^20.14.11",
|
|
54
|
+
"typescript": "^5.5.3",
|
|
55
|
+
"vitest": "^2.0.3"
|
|
56
56
|
},
|
|
57
57
|
"gitHead": "1045d854bfd8c475b7035471d130d401417a2321"
|
|
58
58
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { IncomingMessage, ServerResponse } from 'http'
|
|
2
1
|
import { Injector } from '@furystack/inject'
|
|
3
2
|
import { usingAsync } from '@furystack/utils'
|
|
4
|
-
import {
|
|
3
|
+
import type { IncomingMessage, ServerResponse } from 'http'
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
5
5
|
import { HttpUserContext } from '../http-user-context.js'
|
|
6
|
-
import {
|
|
6
|
+
import { LoginAction } from './login.js'
|
|
7
7
|
|
|
8
8
|
describe('LoginAction', () => {
|
|
9
9
|
const request = { url: 'https://google.com' } as IncomingMessage
|
|
@@ -25,7 +25,7 @@ describe('LoginAction', () => {
|
|
|
25
25
|
response,
|
|
26
26
|
injector: i,
|
|
27
27
|
getBody: async () => ({ username: 'testuser', password: 'alma' }),
|
|
28
|
-
}
|
|
28
|
+
})
|
|
29
29
|
expect(result.chunk).toEqual(testUser)
|
|
30
30
|
expect(result.statusCode).toBe(200)
|
|
31
31
|
})
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Injector } from '@furystack/inject'
|
|
2
2
|
import { usingAsync } from '@furystack/utils'
|
|
3
|
+
import type { IncomingMessage, ServerResponse } from 'http'
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
5
|
import { HttpUserContext } from '../http-user-context.js'
|
|
4
6
|
import { LogoutAction } from './logout.js'
|
|
5
|
-
import type { IncomingMessage, ServerResponse } from 'http'
|
|
6
|
-
import { describe, it, expect, vi } from 'vitest'
|
|
7
7
|
|
|
8
8
|
describe('LogoutAction', () => {
|
|
9
9
|
const request = { url: 'https://google.com' } as IncomingMessage
|
|
@@ -19,7 +19,7 @@ describe('LogoutAction', () => {
|
|
|
19
19
|
HttpUserContext,
|
|
20
20
|
)
|
|
21
21
|
|
|
22
|
-
const result = await LogoutAction({ request, response, injector: i }
|
|
22
|
+
const result = await LogoutAction({ request, response, injector: i })
|
|
23
23
|
expect(result.statusCode).toBe(200)
|
|
24
24
|
expect(result.chunk).toBe(undefined)
|
|
25
25
|
expect(cookieLogout).toBeCalled()
|
package/src/api-manager.ts
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type { Method, RestApi } from '@furystack/rest'
|
|
4
|
-
import { deserializeQueryString } from '@furystack/rest'
|
|
1
|
+
import type { User } from '@furystack/core'
|
|
2
|
+
import { IdentityContext } from '@furystack/core'
|
|
5
3
|
import type { Injector } from '@furystack/inject'
|
|
6
4
|
import { Injectable, Injected } from '@furystack/inject'
|
|
5
|
+
import type { Method, RestApi } from '@furystack/rest'
|
|
6
|
+
import { deserializeQueryString } from '@furystack/rest'
|
|
7
|
+
import { PathHelper, usingAsync } from '@furystack/utils'
|
|
7
8
|
import type { MatchFunction } from 'path-to-regexp'
|
|
8
9
|
import { match } from 'path-to-regexp'
|
|
9
|
-
import type { User } from '@furystack/core'
|
|
10
|
-
import { IdentityContext } from '@furystack/core'
|
|
11
|
-
|
|
12
|
-
import type { OnRequest } from './server-manager.js'
|
|
13
|
-
import { ServerManager } from './server-manager.js'
|
|
14
|
-
import { NotFoundAction } from './actions/not-found-action.js'
|
|
15
|
-
import type { CorsOptions } from './models/cors-options.js'
|
|
16
10
|
import { ErrorAction } from './actions/error-action.js'
|
|
17
|
-
import './
|
|
18
|
-
import { HttpUserContext } from './http-user-context.js'
|
|
19
|
-
import type { RequestAction } from './request-action-implementation.js'
|
|
11
|
+
import { NotFoundAction } from './actions/not-found-action.js'
|
|
20
12
|
import { addCorsHeaders } from './add-cors-header.js'
|
|
13
|
+
import { HttpUserContext } from './http-user-context.js'
|
|
14
|
+
import type { CorsOptions } from './models/cors-options.js'
|
|
21
15
|
import { readPostBody } from './read-post-body.js'
|
|
16
|
+
import type { RequestAction } from './request-action-implementation.js'
|
|
17
|
+
import type { OnRequest } from './server-manager.js'
|
|
18
|
+
import { ServerManager } from './server-manager.js'
|
|
19
|
+
import './server-response-extensions.js'
|
|
22
20
|
|
|
23
21
|
export type RestApiImplementation<T extends RestApi> = {
|
|
24
22
|
[TMethod in keyof T]: {
|
|
@@ -39,7 +37,7 @@ export interface ImplementApiOptions<T extends RestApi> {
|
|
|
39
37
|
export type NewCompiledApiEntry = {
|
|
40
38
|
method: Method
|
|
41
39
|
fullPath: string
|
|
42
|
-
matcher: MatchFunction
|
|
40
|
+
matcher: MatchFunction<Partial<Record<string, string | string[]>>>
|
|
43
41
|
action: RequestAction<any>
|
|
44
42
|
}
|
|
45
43
|
|
|
@@ -55,18 +53,18 @@ export type OnRequestOptions = OnRequest & {
|
|
|
55
53
|
injector: Injector
|
|
56
54
|
cors?: CorsOptions
|
|
57
55
|
supportedMethods: string[]
|
|
58
|
-
deserializeQueryParams?: (param: string) =>
|
|
56
|
+
deserializeQueryParams?: (param: string) => Record<string, unknown>
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
@Injectable({ lifetime: 'singleton' })
|
|
62
60
|
export class ApiManager implements Disposable {
|
|
63
61
|
private readonly apis = new Map<string, NewCompiledApi>()
|
|
64
62
|
|
|
65
|
-
public dispose() {
|
|
63
|
+
public [Symbol.dispose]() {
|
|
66
64
|
this.apis.clear()
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
private getSuportedMethods(api: RestApiImplementation<
|
|
67
|
+
private getSuportedMethods(api: RestApiImplementation<RestApi>): Method[] {
|
|
70
68
|
return Object.keys(api) as Method[]
|
|
71
69
|
}
|
|
72
70
|
|
|
@@ -138,7 +136,7 @@ export class ApiManager implements Disposable {
|
|
|
138
136
|
}
|
|
139
137
|
|
|
140
138
|
private getActionFromEndpoint(compiledEndpoint: NewCompiledApi, fullUrl: URL, method: Method) {
|
|
141
|
-
let resolvedParams:
|
|
139
|
+
let resolvedParams: unknown
|
|
142
140
|
const action = compiledEndpoint[method]?.find((route) => {
|
|
143
141
|
const result = route.matcher(fullUrl.pathname)
|
|
144
142
|
if (result) {
|
|
@@ -165,7 +163,7 @@ export class ApiManager implements Disposable {
|
|
|
165
163
|
}: OnRequestOptions & {
|
|
166
164
|
fullUrl: URL
|
|
167
165
|
action: RequestAction<{ body: {}; result: {}; query: {}; url: {}; headers: {} }>
|
|
168
|
-
params:
|
|
166
|
+
params: unknown
|
|
169
167
|
}) {
|
|
170
168
|
await usingAsync(injector.createChild(), async (i) => {
|
|
171
169
|
const httpUserContext = i.getInstance(HttpUserContext)
|
|
@@ -187,7 +185,7 @@ export class ApiManager implements Disposable {
|
|
|
187
185
|
getQuery: () =>
|
|
188
186
|
deserializeQueryParams ? deserializeQueryParams(fullUrl.search) : deserializeQueryString(fullUrl.search),
|
|
189
187
|
getUrlParams: () => {
|
|
190
|
-
return params
|
|
188
|
+
return params as {}
|
|
191
189
|
},
|
|
192
190
|
})
|
|
193
191
|
res.sendActionResult(actionResult)
|
package/src/authenticate.ts
CHANGED
|
@@ -18,6 +18,6 @@ export const Authenticate =
|
|
|
18
18
|
injector.getInstance(HttpUserContext).authentication.enableBasicAuth ? { 'WWW-Authenticate': 'Basic' } : {},
|
|
19
19
|
) as unknown as ActionResult<T>
|
|
20
20
|
}
|
|
21
|
-
return (await action(args)) as
|
|
21
|
+
return (await action(args)) as ActionResult<T>
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -373,7 +373,7 @@ describe('HttpUserContext', () => {
|
|
|
373
373
|
|
|
374
374
|
await ctx.cookieLogin(testUser, {
|
|
375
375
|
setHeader: (_headerName, headerValue) => {
|
|
376
|
-
sessionId = headerValue
|
|
376
|
+
sessionId = headerValue
|
|
377
377
|
return {} as ServerResponse
|
|
378
378
|
},
|
|
379
379
|
})
|
|
@@ -382,7 +382,7 @@ describe('HttpUserContext', () => {
|
|
|
382
382
|
expect(originalUser).toEqual(testUser)
|
|
383
383
|
|
|
384
384
|
const sessionStore = ctx.getSessionStore()
|
|
385
|
-
await sessionStore.remove(sessionId
|
|
385
|
+
await sessionStore.remove(sessionId)
|
|
386
386
|
|
|
387
387
|
await expect(() => ctx.getCurrentUser(request)).rejects.toThrowError(UnauthenticatedError)
|
|
388
388
|
})
|
package/src/read-post-body.ts
CHANGED
|
@@ -30,7 +30,7 @@ export const readPostBodyRaw = async (incomingMessage: IncomingMessage) => {
|
|
|
30
30
|
* @returns the parsed object from the post body
|
|
31
31
|
*/
|
|
32
32
|
export const readPostBody = async <T>(incomingMessage: IncomingMessage): Promise<T> => {
|
|
33
|
-
const body = incomingMessage.postBody || JSON.parse(await readPostBodyRaw(incomingMessage))
|
|
33
|
+
const body = (incomingMessage.postBody as T) || (JSON.parse(await readPostBodyRaw(incomingMessage)) as T)
|
|
34
34
|
incomingMessage.postBody = body
|
|
35
35
|
return body
|
|
36
36
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { InMemoryStore, User, addStore } from '@furystack/core'
|
|
2
|
+
import { getPort } from '@furystack/core/port-generator'
|
|
1
3
|
import { Injector } from '@furystack/inject'
|
|
2
|
-
import './helpers'
|
|
3
|
-
import { usingAsync, PathHelper } from '@furystack/utils'
|
|
4
|
-
import { GetCurrentUser, IsAuthenticated, LoginAction, LogoutAction } from './actions/index.js'
|
|
5
4
|
import type { RestApi } from '@furystack/rest'
|
|
6
|
-
import {
|
|
5
|
+
import { serializeValue } from '@furystack/rest'
|
|
6
|
+
import { PathHelper, usingAsync } from '@furystack/utils'
|
|
7
|
+
import { describe, expect, it } from 'vitest'
|
|
8
|
+
import { GetCurrentUser, IsAuthenticated, LoginAction, LogoutAction } from './actions/index.js'
|
|
9
|
+
import './helpers'
|
|
10
|
+
import { useHttpAuthentication, useRestService } from './helpers.js'
|
|
7
11
|
import { DefaultSession } from './models/default-session.js'
|
|
8
12
|
import { JsonResult } from './request-action-implementation.js'
|
|
9
|
-
import { useHttpAuthentication, useRestService } from './helpers.js'
|
|
10
|
-
import { describe, it, expect } from 'vitest'
|
|
11
|
-
import { serializeValue } from '@furystack/rest'
|
|
12
|
-
import { getPort } from '@furystack/core/port-generator'
|
|
13
13
|
|
|
14
14
|
interface IntegrationTestApi extends RestApi {
|
|
15
15
|
GET: {
|
|
@@ -68,7 +68,7 @@ const createIntegrationApi = async () => {
|
|
|
68
68
|
return {
|
|
69
69
|
apiUrl: `http://127.0.0.1:${port}/${root}`,
|
|
70
70
|
port,
|
|
71
|
-
|
|
71
|
+
[Symbol.asyncDispose]: i[Symbol.asyncDispose].bind(i),
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { getPort } from '@furystack/core/port-generator'
|
|
1
2
|
import { Injector } from '@furystack/inject'
|
|
2
3
|
import type { RestApi } from '@furystack/rest'
|
|
3
4
|
import { createClient } from '@furystack/rest-client-fetch'
|
|
4
5
|
import { usingAsync } from '@furystack/utils'
|
|
5
|
-
import {
|
|
6
|
+
import { describe, expect, it } from 'vitest'
|
|
6
7
|
import { useRestService } from './helpers.js'
|
|
7
|
-
import {
|
|
8
|
-
import { getPort } from '@furystack/core/port-generator'
|
|
8
|
+
import { JsonResult } from './request-action-implementation.js'
|
|
9
9
|
|
|
10
10
|
export interface EchoApi extends RestApi {
|
|
11
11
|
GET: {
|
|
@@ -19,7 +19,7 @@ export interface EchoApi extends RestApi {
|
|
|
19
19
|
'/segment': { result: { name: 'segment' } }
|
|
20
20
|
'/segment/subsegment': { result: { name: 'segment-subsegment' } }
|
|
21
21
|
'/segment/:id/subsegment': { url: { id: string }; result: { url: { id: string; name: 'segment-subsegment' } } }
|
|
22
|
-
'/segment/:optionalId?/optionalSubsegment/': {
|
|
22
|
+
'/segment{/:optionalId}?/optionalSubsegment/': {
|
|
23
23
|
url: { optionalId?: string }
|
|
24
24
|
result: { url: { optionalId?: string }; name: 'optional-id' }
|
|
25
25
|
}
|
|
@@ -47,7 +47,7 @@ const createEchoApiServer = async () => {
|
|
|
47
47
|
'/segment/subsegment': async () => JsonResult({ name: 'segment-subsegment' }),
|
|
48
48
|
'/segment/:id/subsegment': async ({ getUrlParams }) =>
|
|
49
49
|
JsonResult({ url: { ...getUrlParams(), name: 'segment-subsegment' } }),
|
|
50
|
-
'/segment/:optionalId?/optionalSubsegment/': async ({ getUrlParams }) =>
|
|
50
|
+
'/segment{/:optionalId}?/optionalSubsegment/': async ({ getUrlParams }) =>
|
|
51
51
|
JsonResult({ url: getUrlParams(), name: 'optional-id' }),
|
|
52
52
|
},
|
|
53
53
|
POST: {
|
|
@@ -59,7 +59,7 @@ const createEchoApiServer = async () => {
|
|
|
59
59
|
endpointUrl: `http://127.0.0.1:${port}/api`,
|
|
60
60
|
})
|
|
61
61
|
return {
|
|
62
|
-
|
|
62
|
+
[Symbol.asyncDispose]: injector[Symbol.asyncDispose].bind(injector),
|
|
63
63
|
root,
|
|
64
64
|
port,
|
|
65
65
|
client,
|
|
@@ -166,7 +166,7 @@ describe('REST Integration tests with FETCH client', () => {
|
|
|
166
166
|
await usingAsync(await createEchoApiServer(), async ({ client }) => {
|
|
167
167
|
const result = await client({
|
|
168
168
|
method: 'GET',
|
|
169
|
-
action: '/segment/:optionalId?/optionalSubsegment/',
|
|
169
|
+
action: '/segment{/:optionalId}?/optionalSubsegment/',
|
|
170
170
|
url: {},
|
|
171
171
|
})
|
|
172
172
|
expect(result.response.status).toBe(200)
|
|
@@ -175,7 +175,7 @@ describe('REST Integration tests with FETCH client', () => {
|
|
|
175
175
|
|
|
176
176
|
const result2 = await client({
|
|
177
177
|
method: 'GET',
|
|
178
|
-
action: '/segment/:optionalId?/optionalSubsegment/',
|
|
178
|
+
action: '/segment{/:optionalId}?/optionalSubsegment/',
|
|
179
179
|
url: {
|
|
180
180
|
optionalId: 'value',
|
|
181
181
|
},
|
package/src/server-manager.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Injectable } from '@furystack/inject'
|
|
2
|
-
import type {
|
|
3
|
-
import type { Server } from 'http'
|
|
2
|
+
import type { IncomingMessage, Server, ServerResponse } from 'http'
|
|
4
3
|
import { createServer } from 'http'
|
|
5
|
-
import { Lock } from 'semaphore-async-await'
|
|
6
|
-
import type { IncomingMessage, ServerResponse } from 'http'
|
|
7
4
|
import type { Socket } from 'net'
|
|
5
|
+
import { Lock } from 'semaphore-async-await'
|
|
8
6
|
|
|
9
7
|
export interface ServerOptions {
|
|
10
8
|
hostName?: string
|
|
@@ -18,7 +16,7 @@ export interface OnRequest {
|
|
|
18
16
|
|
|
19
17
|
export interface ServerApi {
|
|
20
18
|
shouldExec: (options: OnRequest) => boolean
|
|
21
|
-
onRequest: (options: OnRequest) => void
|
|
19
|
+
onRequest: (options: OnRequest) => Promise<void>
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
export interface ServerRecord {
|
|
@@ -27,7 +25,7 @@ export interface ServerRecord {
|
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
@Injectable({ lifetime: 'singleton' })
|
|
30
|
-
export class ServerManager implements
|
|
28
|
+
export class ServerManager implements AsyncDisposable {
|
|
31
29
|
public static DEFAULT_HOST = 'localhost'
|
|
32
30
|
|
|
33
31
|
public servers = new Map<string, ServerRecord>()
|
|
@@ -43,7 +41,7 @@ export class ServerManager implements Disposable {
|
|
|
43
41
|
socket.once('close', () => this.openedSockets.delete(socket))
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
public async
|
|
44
|
+
public async [Symbol.asyncDispose]() {
|
|
47
45
|
try {
|
|
48
46
|
await this.listenLock.waitFor(5000)
|
|
49
47
|
} finally {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { getStoreManager, InMemoryStore, User } from '@furystack/core'
|
|
2
|
+
import { getPort } from '@furystack/core/port-generator'
|
|
1
3
|
import { Injector } from '@furystack/inject'
|
|
2
4
|
import { createClient, ResponseError } from '@furystack/rest-client-fetch'
|
|
3
5
|
import { usingAsync } from '@furystack/utils'
|
|
4
|
-
import {
|
|
5
|
-
import { Validate } from './validate.js'
|
|
6
|
-
import schema from './validate.integration.spec.schema.json' with { type: 'json' }
|
|
7
|
-
import type { ValidationApi } from './validate.integration.schema.js'
|
|
6
|
+
import { describe, expect, it } from 'vitest'
|
|
8
7
|
import { useRestService } from './helpers.js'
|
|
9
|
-
import { describe, it, expect } from 'vitest'
|
|
10
|
-
import { getPort } from '@furystack/core/port-generator'
|
|
11
|
-
import { getStoreManager, InMemoryStore, User } from '@furystack/core'
|
|
12
8
|
import { DefaultSession } from './models/default-session.js'
|
|
9
|
+
import { JsonResult } from './request-action-implementation.js'
|
|
10
|
+
import type { ValidationApi } from './validate.integration.schema.js'
|
|
11
|
+
import schema from './validate.integration.spec.schema.json' with { type: 'json' }
|
|
12
|
+
import { Validate } from './validate.js'
|
|
13
13
|
|
|
14
14
|
// 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
|
|
15
15
|
|
|
@@ -64,7 +64,7 @@ const createValidateApi = async () => {
|
|
|
64
64
|
})
|
|
65
65
|
|
|
66
66
|
return {
|
|
67
|
-
|
|
67
|
+
[Symbol.asyncDispose]: injector[Symbol.asyncDispose].bind(injector),
|
|
68
68
|
client,
|
|
69
69
|
}
|
|
70
70
|
}
|