@clairejs/server 3.2.8 → 3.3.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.
Files changed (87) hide show
  1. package/.prettierrc +8 -0
  2. package/README.md +608 -602
  3. package/dist/common/FileOperation.d.ts +5 -5
  4. package/dist/common/ServerModelMetadata.d.ts +10 -10
  5. package/dist/common/auth/AbstractPrincipalResolver.d.ts +4 -0
  6. package/dist/{http → common}/auth/IPrincipal.d.ts +4 -4
  7. package/dist/common/constants.d.ts +1 -1
  8. package/dist/{http/controller → common/request}/EndpointMetadata.d.ts +40 -40
  9. package/dist/common/request/HttpData.d.ts +1 -0
  10. package/dist/common/request/HttpEndpoint.d.ts +8 -0
  11. package/dist/common/request/JobData.d.ts +1 -0
  12. package/dist/{http/controller → common/request}/MountedEndpointInfo.d.ts +6 -6
  13. package/dist/common/request/RequestOptions.d.ts +6 -0
  14. package/dist/common/request/SocketData.d.ts +1 -0
  15. package/dist/{http/common → common/request}/types.d.ts +1 -1
  16. package/dist/database/adapter/AbstractDatabaseAdapter.d.ts +20 -20
  17. package/dist/database/adapter/AbstractQuery.d.ts +52 -52
  18. package/dist/database/adapter/DefaultSqlDatabaseAdapter.d.ts +18 -18
  19. package/dist/database/adapter/IQuery.d.ts +75 -75
  20. package/dist/database/adapter/IQueryProvider.d.ts +9 -9
  21. package/dist/database/adapter/aggregators.d.ts +21 -21
  22. package/dist/database/adapter/providers.d.ts +8 -8
  23. package/dist/database/decorators.d.ts +2 -2
  24. package/dist/database/migrator/AbstractDatabaseMigrator.d.ts +4 -4
  25. package/dist/database/migrator/DefaultSqlDatabaseMigrator.d.ts +30 -30
  26. package/dist/database/transaction/ITransaction.d.ts +10 -10
  27. package/dist/database/transaction/ITransactionFactory.d.ts +4 -4
  28. package/dist/database/transaction/ITransactionProvider.d.ts +4 -4
  29. package/dist/database/transaction/TransactionLink.d.ts +14 -14
  30. package/dist/database/transaction/TransactionObjectMetadata.d.ts +4 -4
  31. package/dist/database/transaction/TransactionState.d.ts +5 -5
  32. package/dist/database/util/transaction-provider.d.ts +1 -1
  33. package/dist/http/auth/AbstractHttpAuthorizationProvider.d.ts +9 -7
  34. package/dist/http/auth/AbstractRbacAuthProvider.d.ts +18 -18
  35. package/dist/http/auth/RedisRbacAuthProvider.d.ts +23 -23
  36. package/dist/http/auth/SocketRbacAuthProvider.d.ts +25 -25
  37. package/dist/http/auth/rbac.d.ts +34 -33
  38. package/dist/http/common/HttpRequest.d.ts +37 -39
  39. package/dist/http/common/HttpResponse.d.ts +25 -25
  40. package/dist/http/controller/AbstractHttpController.d.ts +10 -11
  41. package/dist/http/controller/AbstractHttpMiddleware.d.ts +5 -5
  42. package/dist/http/controller/AbstractHttpRequestHandler.d.ts +16 -10
  43. package/dist/http/controller/ControllerMetadata.d.ts +6 -6
  44. package/dist/http/controller/CrudHttpController.d.ts +56 -56
  45. package/dist/http/controller/DefaultHttpRequestHandler.d.ts +19 -25
  46. package/dist/http/decorators.d.ts +32 -33
  47. package/dist/http/file-upload/AbstractFileUploadHandler.d.ts +6 -6
  48. package/dist/http/file-upload/FileUploadHandler.d.ts +10 -10
  49. package/dist/http/file-upload/types.d.ts +3 -3
  50. package/dist/http/repository/AbstractRepository.d.ts +10 -10
  51. package/dist/http/repository/DtoRepository.d.ts +56 -56
  52. package/dist/http/repository/ICrudRepository.d.ts +25 -25
  53. package/dist/http/repository/ModelRepository.d.ts +35 -35
  54. package/dist/http/security/AbstractAccessCondition.d.ts +7 -7
  55. package/dist/http/security/access-conditions/DtoFieldValidation.d.ts +4 -4
  56. package/dist/http/security/access-conditions/FilterModelFieldAccessCondition.d.ts +4 -4
  57. package/dist/http/security/access-conditions/MaximumQueryLimit.d.ts +8 -8
  58. package/dist/index.d.ts +57 -57
  59. package/dist/index.js +1 -1
  60. package/dist/job/AbstractJobController.d.ts +2 -0
  61. package/dist/job/AbstractJobManager.d.ts +5 -0
  62. package/dist/job/Job.d.ts +4 -0
  63. package/dist/job/RedisJobManager.d.ts +6 -0
  64. package/dist/job/SnsJobManager.d.ts +6 -0
  65. package/dist/job/decorators.d.ts +0 -0
  66. package/dist/logging/FileLogMedium.d.ts +13 -13
  67. package/dist/service/AbstractCacheService.d.ts +22 -22
  68. package/dist/service/AbstractFileService.d.ts +8 -8
  69. package/dist/service/AbstractService.d.ts +8 -8
  70. package/dist/socket/AbstractServerSocket.d.ts +19 -39
  71. package/dist/socket/AbstractServerSocketManager.d.ts +42 -19
  72. package/dist/socket/AbstractSocketConnectionHandler.d.ts +6 -0
  73. package/dist/socket/AbstractSocketController.d.ts +14 -0
  74. package/dist/socket/AwsSocketManager.d.ts +33 -46
  75. package/dist/socket/IServerSocket.d.ts +16 -8
  76. package/dist/socket/LocalSocketManager.d.ts +38 -23
  77. package/dist/system/ClaireServer.d.ts +13 -10
  78. package/dist/system/ExpressWrapper.d.ts +17 -17
  79. package/dist/system/LambdaWrapper.d.ts +17 -17
  80. package/dist/system/ServerGlobalStore.d.ts +5 -5
  81. package/dist/system/errors.d.ts +14 -14
  82. package/package.json +60 -59
  83. package/dist/http/auth/AbstractPrincipalResolver.d.ts +0 -5
  84. package/dist/http/common/RequestOptions.d.ts +0 -9
  85. package/dist/http/common/ResponseValues.d.ts +0 -10
  86. package/dist/http/controller/HttpEndpoint.d.ts +0 -9
  87. package/dist/system/IRequestHandler.d.ts +0 -5
@@ -0,0 +1,6 @@
1
+ import { AbstractJobManager } from "./AbstractJobManager";
2
+ import { Job } from "./Job";
3
+ export declare class RedisJobManager extends AbstractJobManager {
4
+ publishJobs(jobs: Job[]): Promise<void>;
5
+ retrieveJob(): Promise<Job | undefined>;
6
+ }
@@ -0,0 +1,6 @@
1
+ import { AbstractJobManager } from "./AbstractJobManager";
2
+ import { Job } from "./Job";
3
+ export declare class SnsJobManager extends AbstractJobManager {
4
+ publishJobs(jobs: Job[]): Promise<void>;
5
+ retrieveJob(): Promise<Job | undefined>;
6
+ }
File without changes
@@ -1,13 +1,13 @@
1
- import { LogLevel, ILogMedium } from "@clairejs/core";
2
- export declare class FileLogMedium implements ILogMedium {
3
- private static readonly levels;
4
- private readonly destination;
5
- private readonly separated;
6
- constructor(config: {
7
- destination: string;
8
- separated?: boolean;
9
- });
10
- init(): Promise<void>;
11
- exit(): void;
12
- write(level: LogLevel, content: string): void;
13
- }
1
+ import { LogLevel, ILogMedium } from "@clairejs/core";
2
+ export declare class FileLogMedium implements ILogMedium {
3
+ private static readonly levels;
4
+ private readonly destination;
5
+ private readonly separated;
6
+ constructor(config: {
7
+ destination: string;
8
+ separated?: boolean;
9
+ });
10
+ init(): Promise<void>;
11
+ exit(): void;
12
+ write(level: LogLevel, content: string): void;
13
+ }
@@ -1,22 +1,22 @@
1
- export interface MutexLock {
2
- unlock(): Promise<void>;
3
- }
4
- export interface ICacheTransaction {
5
- hset(hash: string, key: string, value: any): void;
6
- set(key: string, value: any): void;
7
- del(key: string): void;
8
- hdel(hash: string, key: string): void;
9
- exec(): Promise<any[]>;
10
- }
11
- export declare abstract class AbstractCacheService {
12
- abstract hget<T>(hash: string, key: string): Promise<T | undefined>;
13
- abstract hset<T>(hash: string, key: string, value: T): Promise<void>;
14
- abstract hkeys(hash: string): Promise<string[]>;
15
- abstract get<T>(key: string): Promise<T | undefined>;
16
- abstract set<T>(key: string, value: T): Promise<void>;
17
- abstract del(key: string): Promise<void>;
18
- abstract hdel(hash: string, key: string): Promise<void>;
19
- abstract flush(): Promise<void>;
20
- abstract lock(key: string, durationMs: number, timeoutMs?: number): Promise<MutexLock>;
21
- abstract createTransaction(): ICacheTransaction;
22
- }
1
+ export interface MutexLock {
2
+ unlock(): Promise<void>;
3
+ }
4
+ export interface ICacheTransaction {
5
+ hset(hash: string, key: string, value: any): void;
6
+ set(key: string, value: any): void;
7
+ del(key: string): void;
8
+ hdel(hash: string, key: string): void;
9
+ exec(): Promise<any[]>;
10
+ }
11
+ export declare abstract class AbstractCacheService {
12
+ abstract hget<T>(hash: string, key: string): Promise<T | undefined>;
13
+ abstract hset<T>(hash: string, key: string, value: T): Promise<void>;
14
+ abstract hkeys(hash: string): Promise<string[]>;
15
+ abstract get<T>(key: string): Promise<T | undefined>;
16
+ abstract set<T>(key: string, value: T): Promise<void>;
17
+ abstract del(key: string): Promise<void>;
18
+ abstract hdel(hash: string, key: string): Promise<void>;
19
+ abstract flush(): Promise<void>;
20
+ abstract lock(key: string, durationMs: number, timeoutMs?: number): Promise<MutexLock>;
21
+ abstract createTransaction(): ICacheTransaction;
22
+ }
@@ -1,8 +1,8 @@
1
- import { FileOperation } from "../common/FileOperation";
2
- export declare abstract class AbstractFileService {
3
- abstract getFileSize(objectKey: string): Promise<number>;
4
- abstract getAccessUrl(objectKey: string, isPublic: boolean): string;
5
- abstract getPresignedUrl(operation: FileOperation, objectKey: string): string;
6
- abstract moveObject(fromObjectKey: string, toObjectKey: string): Promise<void>;
7
- abstract removeObject(objectKey: string): Promise<void>;
8
- }
1
+ import { FileOperation } from "../common/FileOperation";
2
+ export declare abstract class AbstractFileService {
3
+ abstract getFileSize(objectKey: string): Promise<number>;
4
+ abstract getAccessUrl(objectKey: string, isPublic: boolean): string;
5
+ abstract getPresignedUrl(operation: FileOperation, objectKey: string): string;
6
+ abstract moveObject(fromObjectKey: string, toObjectKey: string): Promise<void>;
7
+ abstract removeObject(objectKey: string): Promise<void>;
8
+ }
@@ -1,8 +1,8 @@
1
- import { ITransactionFactory } from "../database/transaction/ITransactionFactory";
2
- import { ITransactionProvider } from "../database/transaction/ITransactionProvider";
3
- export declare abstract class AbstractService implements ITransactionProvider, ITransactionFactory {
4
- protected readonly databaseAdapter: ITransactionFactory;
5
- constructor(databaseAdapter: ITransactionFactory);
6
- createTransaction(): Promise<import("..").ITransaction>;
7
- getCurrentTransaction(): Promise<import("..").ITransaction>;
8
- }
1
+ import { ITransactionFactory } from "../database/transaction/ITransactionFactory";
2
+ import { ITransactionProvider } from "../database/transaction/ITransactionProvider";
3
+ export declare abstract class AbstractService implements ITransactionProvider, ITransactionFactory {
4
+ protected readonly databaseAdapter: ITransactionFactory;
5
+ constructor(databaseAdapter: ITransactionFactory);
6
+ createTransaction(): Promise<import("..").ITransaction>;
7
+ getCurrentTransaction(): Promise<import("..").ITransaction>;
8
+ }
@@ -1,39 +1,19 @@
1
- import { SocketPlainMessage, AbstractLogger } from "@clairejs/core";
2
- import { AbstractHttpRequestHandler } from "../http/controller/AbstractHttpRequestHandler";
3
- import { AbstractHttpAuthorizationProvider } from "../http/auth/AbstractHttpAuthorizationProvider";
4
- import { IPrincipal } from "../http/auth/IPrincipal";
5
- import { IServerSocket } from "./IServerSocket";
6
- export interface ServerSocketInfo {
7
- id?: string;
8
- isOpen?: boolean;
9
- authorized?: boolean;
10
- channels?: string[];
11
- authInfo?: IPrincipal;
12
- createdAt?: number;
13
- }
14
- export declare abstract class AbstractServerSocket implements IServerSocket {
15
- readonly logger: AbstractLogger;
16
- readonly requestHandler: AbstractHttpRequestHandler;
17
- readonly authorizationProvider: AbstractHttpAuthorizationProvider<any>;
18
- constructor(logger: AbstractLogger, requestHandler: AbstractHttpRequestHandler, authorizationProvider: AbstractHttpAuthorizationProvider<any>);
19
- connect(): void;
20
- onMessage(_handler: (message: SocketPlainMessage) => void): void;
21
- protected socketInfo: ServerSocketInfo;
22
- abstract setOpen(isOpen: boolean): Promise<void>;
23
- addChannels(channels: string[]): Promise<void>;
24
- removeChannels(channels: string[]): Promise<void>;
25
- isOpen(): boolean;
26
- createdTime(): number;
27
- isAuthorized(): boolean;
28
- getAuthInfo(): IPrincipal | undefined;
29
- getId(): string;
30
- getChannels(): string[];
31
- send(message: SocketPlainMessage): void;
32
- disconnect(disconnectError?: any): void;
33
- authorize(authInfo?: IPrincipal): Promise<void>;
34
- protected sendToSocket(channel: string, message?: any): Promise<void>;
35
- protected abstract physicDisconnect(): Promise<void>;
36
- protected abstract physicSend(message: string): Promise<void>;
37
- handleDisconnect(): Promise<void>;
38
- handleMessage(channel: string, message?: any): Promise<void>;
39
- }
1
+ import { SocketMessage } from "@clairejs/core";
2
+ import { IPrincipal } from "../common/auth/IPrincipal";
3
+ import { IServerSocket } from "./IServerSocket";
4
+ import { ChannelInfo, ServerSocketInfo } from "./AbstractServerSocketManager";
5
+ export declare abstract class AbstractServerSocket implements IServerSocket {
6
+ readonly socketInfo: ServerSocketInfo;
7
+ constructor(socketInfo: ServerSocketInfo);
8
+ getId(): string;
9
+ getAuthInfo(): IPrincipal | undefined;
10
+ send(data: any, channel?: string): void;
11
+ sendRaw(data: SocketMessage): void;
12
+ disconnect(): void;
13
+ removeChannels(channels: string[]): void;
14
+ addChannels(channelInfos: ChannelInfo[]): void;
15
+ getChannelsInfo(): ChannelInfo[];
16
+ abstract physicSend(data: any): void;
17
+ abstract physicClose(): void;
18
+ abstract saveSocketInfo(): Promise<void>;
19
+ }
@@ -1,19 +1,42 @@
1
- /// <reference types="node" />
2
- import { Server } from "http";
3
- import { AbstractLogger } from "@clairejs/core";
4
- import { RequestOptions } from "../http/common/RequestOptions";
5
- import { ResponseValues } from "../http/common/ResponseValues";
6
- import { AbstractServerSocket } from "./AbstractServerSocket";
7
- import { IServerSocket } from "./IServerSocket";
8
- export declare abstract class AbstractServerSocketManager {
9
- protected readonly logger: AbstractLogger;
10
- protected constructor(logger: AbstractLogger);
11
- abstract configure(httpServer?: Server): void;
12
- abstract intercept(options: RequestOptions): Promise<ResponseValues | undefined>;
13
- abstract add(socket: AbstractServerSocket): Promise<void>;
14
- abstract removeById(id: string): Promise<void>;
15
- abstract getById(id: string): Promise<AbstractServerSocket | undefined>;
16
- protected abstract getAllSockets(): Promise<AbstractServerSocket[]>;
17
- protected getAllAliveSockets(): Promise<AbstractServerSocket[]>;
18
- getSocketsByChannel(channel: string): Promise<IServerSocket[]>;
19
- }
1
+ import { AbstractLogger, SocketMessage } from "@clairejs/core";
2
+ import { SocketData } from "../common/request/SocketData";
3
+ import { AbstractSocketConnectionHandler } from "./AbstractSocketConnectionHandler";
4
+ import { IPrincipal } from "../common/auth/IPrincipal";
5
+ import { AbstractServerSocket } from "./AbstractServerSocket";
6
+ import { MountedEndpointInfo } from "../common/request/MountedEndpointInfo";
7
+ import { AbstractHttpAuthorizationProvider } from "../http/auth/AbstractHttpAuthorizationProvider";
8
+ import { IServerSocket } from "./IServerSocket";
9
+ import { RedisClient } from "redis";
10
+ export interface ChannelInfo {
11
+ name: string;
12
+ clientToServerAllowed: boolean;
13
+ serverToClientAllowed: boolean;
14
+ }
15
+ export interface ServerSocketInfo {
16
+ id: string;
17
+ createdAt: number;
18
+ channels: ChannelInfo[];
19
+ authInfo?: IPrincipal;
20
+ }
21
+ export declare abstract class AbstractServerSocketManager {
22
+ protected readonly requireAuthentication: boolean;
23
+ protected readonly logger: AbstractLogger;
24
+ protected readonly redisClient: RedisClient;
25
+ protected readonly connectionHandler: AbstractSocketConnectionHandler;
26
+ protected readonly authProvider: AbstractHttpAuthorizationProvider;
27
+ private mountedEndpointInfo?;
28
+ protected constructor(requireAuthentication: boolean, logger: AbstractLogger, redisClient: RedisClient, connectionHandler: AbstractSocketConnectionHandler, authProvider: AbstractHttpAuthorizationProvider);
29
+ abstract configure(data?: any): void;
30
+ protected getUniqueChannelPrefix(): string;
31
+ protected formatBroadcastData(channel: string, data: any): SocketMessage;
32
+ protected getUniqueChannelName(channel: string): string;
33
+ protected getSocketIdsOfChannel(channel: string): Promise<string[]>;
34
+ abstract createCustomChannel(channel: string): Promise<void>;
35
+ addSocketToChannel(socketId: string, channelInfos: ChannelInfo[]): Promise<void>;
36
+ removeSocketFromChannel(socketId: string, channels: string[]): Promise<void>;
37
+ abstract getSocketsByChannel(channel: string): Promise<IServerSocket[]>;
38
+ abstract broadcastToChannel(channel: string, data: any): Promise<void>;
39
+ abstract getById(socketId: string): Promise<AbstractServerSocket | undefined>;
40
+ handle(socketData: SocketData): Promise<void>;
41
+ getMountedEndpointInfo(): Promise<MountedEndpointInfo[]>;
42
+ }
@@ -0,0 +1,6 @@
1
+ import { IServerSocket } from "./IServerSocket";
2
+ export declare abstract class AbstractSocketConnectionHandler {
3
+ abstract onSocketConnect(socket: IServerSocket): void;
4
+ abstract onSocketDisconnect(socket: IServerSocket): void;
5
+ abstract onMessage(socket: IServerSocket, data: any): void;
6
+ }
@@ -0,0 +1,14 @@
1
+ import { IServerSocket } from "./IServerSocket";
2
+ export declare abstract class AbstractSocketController {
3
+ readonly channel: string;
4
+ constructor(channel: string);
5
+ onChannelJoin(socket: IServerSocket): void;
6
+ onChannelLeave(socket: IServerSocket): void;
7
+ /**
8
+ * Handle the message sent to this channel
9
+ * @param socket the socket sending message
10
+ * @param data the data payload being sent
11
+ * @returns return false to prevent message broadcast
12
+ */
13
+ onMessage(socket: IServerSocket, data: any): boolean | void;
14
+ }
@@ -1,46 +1,33 @@
1
- import { AbstractLogger, IInit } from "@clairejs/core";
2
- import { RedisClient } from "redis";
3
- import { ApiGatewayManagementApi } from "aws-sdk";
4
- import { AbstractHttpRequestHandler } from "../http/controller/AbstractHttpRequestHandler";
5
- import { AbstractServerSocketManager } from "./AbstractServerSocketManager";
6
- import { AbstractServerSocket, ServerSocketInfo } from "./AbstractServerSocket";
7
- import { AbstractHttpAuthorizationProvider } from "../http/auth/AbstractHttpAuthorizationProvider";
8
- import { RequestOptions } from "../http/common/RequestOptions";
9
- import { ResponseValues } from "../http/common/ResponseValues";
10
- declare class ApiGatewaySocket extends AbstractServerSocket {
11
- protected socketManager: AbstractServerSocketManager;
12
- private readonly apiGateway;
13
- private readonly redisClient;
14
- private readonly socketNamespace;
15
- constructor(socketManager: AbstractServerSocketManager, logger: AbstractLogger, httpRequestHandler: AbstractHttpRequestHandler, authorizationProvider: AbstractHttpAuthorizationProvider<any>, socketInfo: ServerSocketInfo, apiGateway: ApiGatewayManagementApi, socketNamespace: string, redisClient: RedisClient);
16
- protected physicSend(message: string): Promise<void>;
17
- private updateSocketInfo;
18
- physicDisconnect(): Promise<void>;
19
- setOpen(isOpen: boolean): Promise<void>;
20
- addChannels(channels: string[]): Promise<void>;
21
- removeChannels(channels: string[]): Promise<void>;
22
- authorize(authInfo: any): Promise<void>;
23
- serialize(): string;
24
- }
25
- export declare class AwsSocketManager extends AbstractServerSocketManager implements IInit {
26
- protected readonly region: string;
27
- protected readonly socketDomainUrl: string;
28
- protected readonly redisServerUrl: string;
29
- protected readonly socketNamespace: string;
30
- protected readonly httpRequestHandler: AbstractHttpRequestHandler;
31
- protected readonly authorizationProvider: AbstractHttpAuthorizationProvider<any>;
32
- protected readonly logger: AbstractLogger;
33
- private readonly redisClient;
34
- private readonly apiGatewayManagement;
35
- constructor(region: string, socketDomainUrl: string, redisServerUrl: string, socketNamespace: string, httpRequestHandler: AbstractHttpRequestHandler, authorizationProvider: AbstractHttpAuthorizationProvider<any>, logger: AbstractLogger);
36
- configure(): void;
37
- intercept(options: RequestOptions): Promise<ResponseValues | undefined>;
38
- init(): Promise<void>;
39
- exit(): void;
40
- create(socketInfo: ServerSocketInfo): ApiGatewaySocket;
41
- add(socket: ApiGatewaySocket): Promise<void>;
42
- removeById(id: string): Promise<void>;
43
- getById(id: string): Promise<AbstractServerSocket | undefined>;
44
- protected getAllSockets(): Promise<AbstractServerSocket[]>;
45
- }
46
- export {};
1
+ import { AbstractLogger, IInit } from "@clairejs/core";
2
+ import { RedisClient } from "redis";
3
+ import { AbstractHttpRequestHandler } from "../http/controller/AbstractHttpRequestHandler";
4
+ import { AbstractServerSocketManager, ServerSocketInfo } from "./AbstractServerSocketManager";
5
+ import { AbstractServerSocket } from "./AbstractServerSocket";
6
+ import { AbstractHttpAuthorizationProvider } from "../http/auth/AbstractHttpAuthorizationProvider";
7
+ import { IPrincipal } from "../common/auth/IPrincipal";
8
+ import { AbstractSocketConnectionHandler } from "./AbstractSocketConnectionHandler";
9
+ import { IServerSocket } from "./IServerSocket";
10
+ export declare class AwsSocketManager extends AbstractServerSocketManager implements IInit {
11
+ protected readonly authenticationRequired: boolean;
12
+ protected readonly region: string;
13
+ protected readonly socketDomainUrl: string;
14
+ protected readonly redisClient: RedisClient;
15
+ protected readonly connectionHandler: AbstractSocketConnectionHandler;
16
+ protected readonly httpRequestHandler: AbstractHttpRequestHandler;
17
+ protected readonly authorizationProvider: AbstractHttpAuthorizationProvider<IPrincipal>;
18
+ protected readonly logger: AbstractLogger;
19
+ private readonly apiGatewayManagement;
20
+ constructor(authenticationRequired: boolean, region: string, socketDomainUrl: string, redisClient: RedisClient, connectionHandler: AbstractSocketConnectionHandler, httpRequestHandler: AbstractHttpRequestHandler, authorizationProvider: AbstractHttpAuthorizationProvider<IPrincipal>, logger: AbstractLogger);
21
+ init(): Promise<void>;
22
+ exit(): void;
23
+ protected getSocketInfoHashKey(): string;
24
+ physicSend(socketId: string, data: any): Promise<void>;
25
+ configure(data?: any): void;
26
+ createCustomChannel(channel: string): Promise<void>;
27
+ getSocketsByChannel(channel: string): Promise<IServerSocket[]>;
28
+ broadcastToChannel(channel: string, data: any): Promise<void>;
29
+ addSocket(socketInfo: ServerSocketInfo, data: any): Promise<AbstractServerSocket>;
30
+ removeSocket(socketId: string): Promise<void>;
31
+ private getSocketBySerialized;
32
+ getById(socketId: string): Promise<AbstractServerSocket | undefined>;
33
+ }
@@ -1,8 +1,16 @@
1
- import { ISocket } from "@clairejs/core";
2
- import { IPrincipal } from "../http/auth/IPrincipal";
3
- export interface IServerSocket extends ISocket {
4
- getId(): string;
5
- getAuthInfo(): IPrincipal | undefined;
6
- isOpen(): boolean;
7
- isAuthorized(): boolean;
8
- }
1
+ import { IPrincipal } from "../common/auth/IPrincipal";
2
+ export interface IServerSocket {
3
+ getId(): string;
4
+ getAuthInfo(): IPrincipal | undefined;
5
+ /**
6
+ * Send back data to client
7
+ * @param data The data to send, will be serialized using JSON.stringify
8
+ */
9
+ send(data: any, channel?: string): void;
10
+ /**
11
+ * Disconnect the socket and optionally provide the error which cause the disconnection.
12
+ * The client socket will treat this error as intended reason for socket termination.
13
+ * @param err The error which cause the disconnection
14
+ */
15
+ disconnect(err?: any): void;
16
+ }
@@ -1,23 +1,38 @@
1
- /// <reference types="node" />
2
- import { AbstractLogger } from "@clairejs/core";
3
- import WebSocket from "ws";
4
- import { Server } from "http";
5
- import { AbstractHttpRequestHandler } from "../http/controller/AbstractHttpRequestHandler";
6
- import { AbstractHttpAuthorizationProvider } from "../http/auth/AbstractHttpAuthorizationProvider";
7
- import { ResponseValues } from "../http/common/ResponseValues";
8
- import { AbstractServerSocketManager } from "./AbstractServerSocketManager";
9
- import { AbstractServerSocket } from "./AbstractServerSocket";
10
- export declare class LocalSocketManager extends AbstractServerSocketManager {
11
- protected readonly logger: AbstractLogger;
12
- protected readonly httpRequestHandler: AbstractHttpRequestHandler;
13
- protected readonly authorizationProvider: AbstractHttpAuthorizationProvider<any>;
14
- private readonly allSockets;
15
- constructor(logger: AbstractLogger, httpRequestHandler: AbstractHttpRequestHandler, authorizationProvider: AbstractHttpAuthorizationProvider<any>);
16
- configure(httpServer?: Server): void;
17
- intercept(): Promise<ResponseValues | undefined>;
18
- create(socket: WebSocket): AbstractServerSocket;
19
- protected getAllSockets(): Promise<AbstractServerSocket[]>;
20
- add(socket: AbstractServerSocket): Promise<void>;
21
- removeById(id: string): Promise<void>;
22
- getById(id: string): Promise<AbstractServerSocket | undefined>;
23
- }
1
+ /// <reference types="node" />
2
+ import { AbstractLogger, IInit } from "@clairejs/core";
3
+ import WebSocket from "ws";
4
+ import { Server } from "http";
5
+ import { RedisClient } from "redis";
6
+ import { AbstractServerSocketManager, ChannelInfo, ServerSocketInfo } from "./AbstractServerSocketManager";
7
+ import { AbstractSocketConnectionHandler } from "./AbstractSocketConnectionHandler";
8
+ import { AbstractServerSocket } from "./AbstractServerSocket";
9
+ import { AbstractHttpAuthorizationProvider } from "../http/auth/AbstractHttpAuthorizationProvider";
10
+ import { IServerSocket } from "./IServerSocket";
11
+ export declare class LocalSocketManager extends AbstractServerSocketManager implements IInit {
12
+ protected readonly authenticationRequired: boolean;
13
+ protected readonly redisClient: RedisClient;
14
+ protected readonly logger: AbstractLogger;
15
+ protected readonly authProvider: AbstractHttpAuthorizationProvider;
16
+ protected readonly connectionHandler: AbstractSocketConnectionHandler;
17
+ private readonly subClient;
18
+ private readonly channelSubClient;
19
+ private readonly sendClient;
20
+ private allSockets;
21
+ constructor(authenticationRequired: boolean, redisClient: RedisClient, logger: AbstractLogger, authProvider: AbstractHttpAuthorizationProvider, connectionHandler: AbstractSocketConnectionHandler);
22
+ init(): Promise<void>;
23
+ exit(): void;
24
+ protected getSocketChannelKeyPrefix(): string;
25
+ protected getSocketInfoHashKey(): string;
26
+ protected getSocketChannelKey(socketId: string): string;
27
+ createCustomChannel(channel: string): Promise<void>;
28
+ broadcastToChannel(channel: string, data: any): Promise<void>;
29
+ addSocketToChannel(socketId: string, channelInfos: ChannelInfo[]): Promise<void>;
30
+ removeSocketFromChannel(socketId: string, channels: string[]): Promise<void>;
31
+ addSocket(socketInfo: ServerSocketInfo, { socket }: {
32
+ socket: WebSocket;
33
+ }): Promise<AbstractServerSocket>;
34
+ removeSocket(socketId: string): Promise<void>;
35
+ getById(socketId: string): Promise<AbstractServerSocket | undefined>;
36
+ getSocketsByChannel(channel: string): Promise<IServerSocket[]>;
37
+ configure(httpServer?: Server): void;
38
+ }
@@ -1,10 +1,13 @@
1
- import { AbstractLogger, ClaireApp } from "@clairejs/core";
2
- export declare class ClaireServer extends ClaireApp {
3
- private readonly injector;
4
- protected readonly logger: AbstractLogger;
5
- private booted;
6
- constructor();
7
- init(): Promise<void>;
8
- exit(): void;
9
- private stop;
10
- }
1
+ import { AbstractLogger, ClaireApp } from "@clairejs/core";
2
+ import { AbstractHttpRequestHandler } from "../http/controller/AbstractHttpRequestHandler";
3
+ import { AbstractServerSocketManager } from "../socket/AbstractServerSocketManager";
4
+ export declare class ClaireServer extends ClaireApp {
5
+ readonly logger: AbstractLogger;
6
+ readonly httpRequestHandler: AbstractHttpRequestHandler | undefined;
7
+ readonly socketManager: AbstractServerSocketManager | undefined;
8
+ private booted;
9
+ constructor(logger: AbstractLogger, httpRequestHandler: AbstractHttpRequestHandler | undefined, socketManager: AbstractServerSocketManager | undefined);
10
+ init(): Promise<void>;
11
+ exit(): void;
12
+ private stop;
13
+ }
@@ -1,17 +1,17 @@
1
- import { ClaireServer } from "./ClaireServer";
2
- interface ExpressWrapperConfig {
3
- maxBodySizeKB?: number;
4
- }
5
- export declare class ExpressWrapper {
6
- private readonly injector;
7
- private readonly socketManager?;
8
- private readonly logger;
9
- private readonly server;
10
- private readonly config?;
11
- private readonly httpRequestHandler;
12
- private httpServer?;
13
- constructor(server: ClaireServer, config?: ExpressWrapperConfig);
14
- close(): void;
15
- listen(listenPort: number): Promise<void>;
16
- }
17
- export {};
1
+ import { ClaireServer } from "./ClaireServer";
2
+ interface ExpressWrapperConfig {
3
+ maxBodySizeKB?: number;
4
+ }
5
+ export declare class ExpressWrapper {
6
+ private readonly injector;
7
+ private readonly socketManager?;
8
+ private readonly logger;
9
+ private readonly server;
10
+ private readonly config?;
11
+ private readonly httpRequestHandler?;
12
+ private httpServer?;
13
+ constructor(server: ClaireServer, config?: ExpressWrapperConfig);
14
+ close(): void;
15
+ listen(listenPort: number): Promise<void>;
16
+ }
17
+ export {};
@@ -1,17 +1,17 @@
1
- import { RequestOptions } from "../http/common/RequestOptions";
2
- import { ClaireServer } from "./ClaireServer";
3
- interface LambdaResponse {
4
- statusCode: number;
5
- body: string;
6
- headers: any;
7
- }
8
- export declare class LambdaWrapper {
9
- private readonly injector;
10
- private readonly httpRequestHandler;
11
- private readonly socketManager?;
12
- private readonly server;
13
- private readonly requestMapper;
14
- constructor(server: ClaireServer, requestMapper: (event: any) => RequestOptions | undefined);
15
- handler(event: any): Promise<LambdaResponse>;
16
- }
17
- export {};
1
+ import { RequestOptions } from "../common/request/RequestOptions";
2
+ import { ClaireServer } from "./ClaireServer";
3
+ interface LambdaResponse {
4
+ statusCode: number;
5
+ body: string;
6
+ headers: any;
7
+ }
8
+ export declare class LambdaWrapper {
9
+ private readonly injector;
10
+ private readonly httpRequestHandler?;
11
+ private readonly socketManager?;
12
+ private readonly server;
13
+ private readonly requestMapper;
14
+ constructor(server: ClaireServer, requestMapper: (event: any) => RequestOptions | undefined);
15
+ handler(event: any): Promise<LambdaResponse>;
16
+ }
17
+ export {};
@@ -1,5 +1,5 @@
1
- import { CoreGlobalStore } from "@clairejs/core";
2
- import { MountedEndpointInfo } from "../http/controller/MountedEndpointInfo";
3
- export interface ServerGlobalStore extends CoreGlobalStore {
4
- mountedEndpointInfo?: MountedEndpointInfo[];
5
- }
1
+ import { CoreGlobalStore } from "@clairejs/core";
2
+ import { MountedEndpointInfo } from "../common/request/MountedEndpointInfo";
3
+ export interface ServerGlobalStore extends CoreGlobalStore {
4
+ mountedEndpointInfo?: MountedEndpointInfo[];
5
+ }
@@ -1,14 +1,14 @@
1
- export declare const Errors: {
2
- TFA_REQUIRED: string;
3
- SYSTEM_ERROR: string;
4
- HTTP_REQUEST_ERROR: string;
5
- SESSION_EXPIRED: string;
6
- ACCESS_DENIED: string;
7
- AUTHENTICATION_ERROR: string;
8
- NOT_FOUND: string;
9
- VALIDATION_ERROR: string;
10
- BAD_STATE: string;
11
- QUERY_ERROR: string;
12
- REQUEST_RATE_LIMIT: string;
13
- CANNOT_LOCK: string;
14
- };
1
+ export declare const Errors: {
2
+ TFA_REQUIRED: string;
3
+ SYSTEM_ERROR: string;
4
+ HTTP_REQUEST_ERROR: string;
5
+ SESSION_EXPIRED: string;
6
+ ACCESS_DENIED: string;
7
+ AUTHENTICATION_ERROR: string;
8
+ NOT_FOUND: string;
9
+ VALIDATION_ERROR: string;
10
+ BAD_STATE: string;
11
+ QUERY_ERROR: string;
12
+ REQUEST_RATE_LIMIT: string;
13
+ CANNOT_LOCK: string;
14
+ };