@sectester/core 0.16.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 (114) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -0
  3. package/package.json +49 -0
  4. package/src/bus/Command.d.ts +14 -0
  5. package/src/bus/Command.js +23 -0
  6. package/src/bus/Command.js.map +1 -0
  7. package/src/bus/CommandDispatcher.d.ts +5 -0
  8. package/src/bus/CommandDispatcher.js +5 -0
  9. package/src/bus/CommandDispatcher.js.map +1 -0
  10. package/src/bus/Event.d.ts +7 -0
  11. package/src/bus/Event.js +14 -0
  12. package/src/bus/Event.js.map +1 -0
  13. package/src/bus/EventBus.d.ts +10 -0
  14. package/src/bus/EventBus.js +5 -0
  15. package/src/bus/EventBus.js.map +1 -0
  16. package/src/bus/EventDispatcher.d.ts +5 -0
  17. package/src/bus/EventDispatcher.js +5 -0
  18. package/src/bus/EventDispatcher.js.map +1 -0
  19. package/src/bus/EventHandler.d.ts +4 -0
  20. package/src/bus/EventHandler.js +3 -0
  21. package/src/bus/EventHandler.js.map +1 -0
  22. package/src/bus/Message.d.ts +7 -0
  23. package/src/bus/Message.js +15 -0
  24. package/src/bus/Message.js.map +1 -0
  25. package/src/bus/RetryStartegy.d.ts +4 -0
  26. package/src/bus/RetryStartegy.js +5 -0
  27. package/src/bus/RetryStartegy.js.map +1 -0
  28. package/src/bus/decorators/bind.d.ts +3 -0
  29. package/src/bus/decorators/bind.js +22 -0
  30. package/src/bus/decorators/bind.js.map +1 -0
  31. package/src/bus/decorators/index.d.ts +1 -0
  32. package/src/bus/decorators/index.js +5 -0
  33. package/src/bus/decorators/index.js.map +1 -0
  34. package/src/bus/exceptions/EventHandlerNotFound.d.ts +4 -0
  35. package/src/bus/exceptions/EventHandlerNotFound.js +11 -0
  36. package/src/bus/exceptions/EventHandlerNotFound.js.map +1 -0
  37. package/src/bus/exceptions/IllegalOperation.d.ts +6 -0
  38. package/src/bus/exceptions/IllegalOperation.js +12 -0
  39. package/src/bus/exceptions/IllegalOperation.js.map +1 -0
  40. package/src/bus/exceptions/NoResponse.d.ts +4 -0
  41. package/src/bus/exceptions/NoResponse.js +11 -0
  42. package/src/bus/exceptions/NoResponse.js.map +1 -0
  43. package/src/bus/exceptions/NoSubscriptionsFound.d.ts +5 -0
  44. package/src/bus/exceptions/NoSubscriptionsFound.js +12 -0
  45. package/src/bus/exceptions/NoSubscriptionsFound.js.map +1 -0
  46. package/src/bus/exceptions/UnsupportedEventType.d.ts +4 -0
  47. package/src/bus/exceptions/UnsupportedEventType.js +12 -0
  48. package/src/bus/exceptions/UnsupportedEventType.js.map +1 -0
  49. package/src/bus/exceptions/index.d.ts +5 -0
  50. package/src/bus/exceptions/index.js +9 -0
  51. package/src/bus/exceptions/index.js.map +1 -0
  52. package/src/bus/index.d.ts +10 -0
  53. package/src/bus/index.js +14 -0
  54. package/src/bus/index.js.map +1 -0
  55. package/src/configuration/Configuration.d.ts +33 -0
  56. package/src/configuration/Configuration.js +96 -0
  57. package/src/configuration/Configuration.js.map +1 -0
  58. package/src/configuration/index.d.ts +1 -0
  59. package/src/configuration/index.js +5 -0
  60. package/src/configuration/index.js.map +1 -0
  61. package/src/credentials-provider/Credentials.d.ts +9 -0
  62. package/src/credentials-provider/Credentials.js +20 -0
  63. package/src/credentials-provider/Credentials.js.map +1 -0
  64. package/src/credentials-provider/CredentialsProvider.d.ts +5 -0
  65. package/src/credentials-provider/CredentialsProvider.js +5 -0
  66. package/src/credentials-provider/CredentialsProvider.js.map +1 -0
  67. package/src/credentials-provider/EnvCredentialProvider.d.ts +5 -0
  68. package/src/credentials-provider/EnvCredentialProvider.js +12 -0
  69. package/src/credentials-provider/EnvCredentialProvider.js.map +1 -0
  70. package/src/credentials-provider/index.d.ts +3 -0
  71. package/src/credentials-provider/index.js +7 -0
  72. package/src/credentials-provider/index.js.map +1 -0
  73. package/src/exceptions/SecTesterError.d.ts +3 -0
  74. package/src/exceptions/SecTesterError.js +11 -0
  75. package/src/exceptions/SecTesterError.js.map +1 -0
  76. package/src/exceptions/index.d.ts +1 -0
  77. package/src/exceptions/index.js +5 -0
  78. package/src/exceptions/index.js.map +1 -0
  79. package/src/index.d.ts +8 -0
  80. package/src/index.js +26 -0
  81. package/src/index.js.map +1 -0
  82. package/src/logger/Logger.d.ts +21 -0
  83. package/src/logger/Logger.js +70 -0
  84. package/src/logger/Logger.js.map +1 -0
  85. package/src/logger/index.d.ts +1 -0
  86. package/src/logger/index.js +5 -0
  87. package/src/logger/index.js.map +1 -0
  88. package/src/register.d.ts +1 -0
  89. package/src/register.js +13 -0
  90. package/src/register.js.map +1 -0
  91. package/src/utils/check-boundaries.d.ts +7 -0
  92. package/src/utils/check-boundaries.js +24 -0
  93. package/src/utils/check-boundaries.js.map +1 -0
  94. package/src/utils/contains.d.ts +1 -0
  95. package/src/utils/contains.js +6 -0
  96. package/src/utils/contains.js.map +1 -0
  97. package/src/utils/delay.d.ts +1 -0
  98. package/src/utils/delay.js +7 -0
  99. package/src/utils/delay.js.map +1 -0
  100. package/src/utils/first.d.ts +1 -0
  101. package/src/utils/first.js +10 -0
  102. package/src/utils/first.js.map +1 -0
  103. package/src/utils/get-type-name.d.ts +6 -0
  104. package/src/utils/get-type-name.js +11 -0
  105. package/src/utils/get-type-name.js.map +1 -0
  106. package/src/utils/index.d.ts +7 -0
  107. package/src/utils/index.js +11 -0
  108. package/src/utils/index.js.map +1 -0
  109. package/src/utils/truncate.d.ts +1 -0
  110. package/src/utils/truncate.js +6 -0
  111. package/src/utils/truncate.js.map +1 -0
  112. package/src/utils/types.d.ts +11 -0
  113. package/src/utils/types.js +26 -0
  114. package/src/utils/types.js.map +1 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Bright Security
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,281 @@
1
+ # @sectester/core
2
+
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a5f72ececc9b0f402802/maintainability)](https://codeclimate.com/github/NeuraLegion/sectester-js/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/a5f72ececc9b0f402802/test_coverage)](https://codeclimate.com/github/NeuraLegion/sectester-js/test_coverage)
5
+ ![Build Status](https://github.com/NeuraLegion/sectester-js/actions/workflows/coverage.yml/badge.svg?branch=master&event=push)
6
+ ![NPM Downloads](https://img.shields.io/npm/dw/@sectester/core)
7
+
8
+ The core package can be used to obtain a config including credentials from different sources, and provide a simplified abstraction to handle events and commands.
9
+
10
+ ## Setup
11
+
12
+ ```bash
13
+ npm i -s @sectester/core
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### Configuration
19
+
20
+ First, you need to generate a new instance of `Configuration`.
21
+
22
+ ```ts
23
+ import { Configuration } from '@sectester/core';
24
+
25
+ const config = new Configuration({
26
+ hostname: 'app.neuralegion.com',
27
+ credentials: {
28
+ token: 'your API key'
29
+ }
30
+ });
31
+ ```
32
+
33
+ After that, you can resolve the configuration using the IoC container.
34
+
35
+ ```ts
36
+ const config = config.container.resolve(Configuration);
37
+ ```
38
+
39
+ #### Options
40
+
41
+ Configuration can be customized using the following options:
42
+
43
+ ```ts
44
+ export interface ConfigurationOptions {
45
+ hostname: string;
46
+ credentials?: Credentials;
47
+ logLevel?: LogLevel;
48
+ credentialProviders?: CredentialProvider[];
49
+ }
50
+ ```
51
+
52
+ The default configuration is as follows:
53
+
54
+ ```js
55
+ {
56
+ logLevel: LogLevel.ERROR,
57
+ credentialProviders: [new EnvCredentialProvider()];
58
+ }
59
+ ```
60
+
61
+ #### hostname
62
+
63
+ - type: `string`
64
+
65
+ Set the application name (domain name), that is used to establish connection with.
66
+
67
+ ```ts
68
+ import { Configuration } from '@sectester/core';
69
+
70
+ const config = new Configuration({
71
+ hostname: 'app.neuralegion.com'
72
+ });
73
+ ```
74
+
75
+ #### logLevel
76
+
77
+ - type: `LogLevel`
78
+
79
+ What level of logs to report. Any logs of a higher level than the setting are shown.
80
+
81
+ ```ts
82
+ import { Configuration, LogLevel } from '@sectester/core';
83
+
84
+ const config = new Configuration({
85
+ // ...
86
+ logLevel: LogLevel.ERROR
87
+ });
88
+ ```
89
+
90
+ #### credentials
91
+
92
+ - type: `Credentials`
93
+
94
+ Set credentials to access the application.
95
+
96
+ ```ts
97
+ import { Configuration } from '@sectester/core';
98
+
99
+ const config = new Configuration({
100
+ // ...
101
+ credentials: {
102
+ token: 'your API key'
103
+ }
104
+ });
105
+ ```
106
+
107
+ More info about [setting up an API key](https://docs.brightsec.com/docs/manage-your-personal-account#manage-your-personal-api-keys-authentication-tokens)
108
+
109
+ #### credentialProviders
110
+
111
+ - type: `CredentialProvider[]`
112
+
113
+ Allows you to provide credentials and load it in runtime. The configuration will invoke one provider at a time and only continue to the next if no credentials have been located. For example, if the process finds values defined via the `BRIGHT_TOKEN` environment variables, the file at `.sectesterrc` will not be read.
114
+
115
+ #### EnvCredentialProvider
116
+
117
+ Use this provider to read credentials from the following environment variable: `BRIGHT_TOKEN`
118
+
119
+ If the `BRIGHT_TOKEN` environment variable is not set or contains a falsy value, it will return undefined.
120
+
121
+ ```ts
122
+ import { Configuration, EnvCredentialProvider } from '@sectester/core';
123
+
124
+ const credentialsProvider = new EnvCredentialProvider();
125
+ const config = new Configuration({
126
+ // ...
127
+ credentialProviders: [credentialsProvider]
128
+ });
129
+ ```
130
+
131
+ ### Messages
132
+
133
+ Message is used for syncing state between SDK, application and/or external services.
134
+ This functionality is done by sending messages outside using a concrete implementation of `Dispatcher`.
135
+
136
+ Depending on the type of derived class from the `Message`, it might be addressed to only one consumer or have typically multiple consumers as well.
137
+ When a message is sent to multiple consumers, the appropriate event handler in each consumer handles the message.
138
+
139
+ The `Message` is a data-holding class, but it implements a [Visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern#:~:text=In%20object%2Doriented%20programming%20and,structures%20without%20modifying%20the%20structures.)
140
+ to allow clients to perform operations on it using a visitor class (see `Dispatcher`) without modifying the source.
141
+
142
+ For instance, you can dispatch a message in a way that is more approach you or convenient from the client's perspective.
143
+
144
+ ```ts
145
+ import { CommandDispatcher, Command } from '@sectester/core';
146
+ import { container } from 'tsyringe';
147
+
148
+ const dispatcher = container.resolve(CommandDispatcher);
149
+
150
+ interface Payload {
151
+ status: 'connected' | 'disconnected';
152
+ }
153
+
154
+ class Ping extends Command<Payload, undefined> {
155
+ constructor(payload: Payload) {
156
+ super(payload);
157
+ }
158
+ }
159
+
160
+ // using a visitor pattern
161
+ await new Ping({ status: 'connected' }).execute(dispatcher);
162
+
163
+ // or directly
164
+ await dispatcher.execute(new Ping({ status: 'disconnected' }));
165
+ ```
166
+
167
+ The same is applicable for the `Event`. You just need to use the `EventDispatcher` instead of `CommandDispatcher`.
168
+
169
+ Each message have a correlation ID to ensure atomicity. The regular UUID is used, but you might also want to consider other options.
170
+
171
+ ### Request-response
172
+
173
+ The request-response message (aka `Command`) style is useful when you need to exchange messages between various external services.
174
+ Using `Command` you can easily ensure that the service has actually received the message and sent a response back.
175
+
176
+ To create an instance of `Command` use the abstract class as follows:
177
+
178
+ ```ts
179
+ import { Command } from '@sectester/core';
180
+
181
+ interface RequestOptions {
182
+ url: string;
183
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
184
+ headers?: Record<string, string>;
185
+ body?: string;
186
+ }
187
+
188
+ class Request<R = unknown> extends Command<RequestOptions, R> {
189
+ constructor(options: RequestOptions) {
190
+ super(options);
191
+ }
192
+ }
193
+ ```
194
+
195
+ To adjust its behavior you can use next options:
196
+
197
+ | Option | Description |
198
+ | :------------- | -------------------------------------------------------------------------------------------- |
199
+ | `payload` | Message that we want to transmit to the remote service. |
200
+ | `expectReply` | Indicates whether to wait for a reply. By default `true`. |
201
+ | `ttl` | Period of time that command should be handled before being discarded. By default `10000` ms. |
202
+ | `type` | The name of a command. By default, it is the name of specific class. |
203
+ | `corelationId` | Used to ensure atomicity while working with EventBus. By default, random UUID. |
204
+ | `createdAt` | The exact date and time the command was created. |
205
+
206
+ ### Publish-subscribe
207
+
208
+ When you just want to publish events without waiting for a response, it is better to use the `Event`.
209
+ The ideal use case for the publish-subscribe model is when you want to simply notify another service that a certain condition has occurred.
210
+
211
+ To create an instance of `Event` use the abstract class as follows:
212
+
213
+ ```ts
214
+ import { Event } from '@sectester/core';
215
+
216
+ interface Issue {
217
+ name: string;
218
+ details: string;
219
+ type: string;
220
+ cvss?: string;
221
+ cwe?: string;
222
+ }
223
+
224
+ class IssueDetected extends Event<Issue> {
225
+ constructor(payload: Issue) {
226
+ super(payload);
227
+ }
228
+ }
229
+ ```
230
+
231
+ To adjust its behavior you can use next options:
232
+
233
+ | Option | Description |
234
+ | :------------- | ------------------------------------------------------------------------------ |
235
+ | `payload` | Message that we want to transmit to the remote service. |
236
+ | `type` | The name of a command. By default, it is the name of specific class. |
237
+ | `corelationId` | Used to ensure atomicity while working with EventBus. By default, random UUID. |
238
+ | `createdAt` | The exact date and time the event was created. |
239
+
240
+ To create an event handler, you should implement the `Handler` interface and use the `@bind()` decorator to subscribe a handler to an event:
241
+
242
+ ```ts
243
+ @bind(IssueDetected)
244
+ class IssueDetectedHandler implements EventHandler<Issue> {
245
+ public handle(payload: Issue): Promise<void> {
246
+ // implementation
247
+ }
248
+ }
249
+ ```
250
+
251
+ You can register multiple event handlers for a single event pattern and all of them will be automatically triggered in parallel.
252
+
253
+ ```ts
254
+ @bind(IssueDetected, IssueReopened)
255
+ class IssueDetectedHandler implements EventHandler<Issue> {
256
+ public handle(payload: Issue): Promise<void> {
257
+ // implementation
258
+ }
259
+ }
260
+ ```
261
+
262
+ You can also use a string and symbol to subscribe a handler to events:
263
+
264
+ ```ts
265
+ const IssueReopened = Symbol('IssueReopened');
266
+
267
+ @bind('IssueDetected', IssueReopened)
268
+ class IssueDetectedHandler implements EventHandler<Issue> {
269
+ public handle(payload: Issue): Promise<void> {
270
+ // implementation
271
+ }
272
+ }
273
+ ```
274
+
275
+ As soon as the `IssueDetected` event appears, the event handler takes a single argument, the data passed from the client (in this case, an event payload which has been sent over the network).
276
+
277
+ ## License
278
+
279
+ Copyright © 2022 [Bright Security](https://brightsec.com/).
280
+
281
+ This project is licensed under the MIT License - see the [LICENSE file](LICENSE) for details.
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@sectester/core",
3
+ "version": "0.16.1",
4
+ "description": "The core package can be used to obtain a config including credentials from different sources, and provide a simplified abstraction to handle events and commands.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/NeuraLegion/sectester-js.git"
8
+ },
9
+ "engines": {
10
+ "node": ">=16",
11
+ "npm": "^8.1.0"
12
+ },
13
+ "author": {
14
+ "name": "Artem Derevnjuk",
15
+ "email": "artem.derevnjuk@brightsec.com"
16
+ },
17
+ "license": "MIT",
18
+ "bugs": {
19
+ "url": "https://github.com/NeuraLegion/sectester-js/issues"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "keywords": [
25
+ "security",
26
+ "testing",
27
+ "e2e",
28
+ "test",
29
+ "typescript",
30
+ "appsec",
31
+ "pentesting",
32
+ "qa",
33
+ "brightsec"
34
+ ],
35
+ "secTester": {
36
+ "name": "sectester-js",
37
+ "repeaterVersion": "8.8.0"
38
+ },
39
+ "main": "./src/index.js",
40
+ "typings": "./src/index.d.ts",
41
+ "dependencies": {
42
+ "reflect-metadata": "^0.1.13",
43
+ "uuid": "^8.3.2",
44
+ "tsyringe": "^4.6.0",
45
+ "chalk": "^4.1.2",
46
+ "form-data": "^4.0.0"
47
+ },
48
+ "peerDependencies": {}
49
+ }
@@ -0,0 +1,14 @@
1
+ import { CommandDispatcher } from './CommandDispatcher';
2
+ import { Message } from './Message';
3
+ export declare abstract class Command<T, R> extends Message<T> {
4
+ readonly expectReply: boolean;
5
+ readonly ttl: number;
6
+ protected constructor(payload: T, options?: {
7
+ expectReply?: boolean;
8
+ ttl?: number;
9
+ type?: string;
10
+ correlationId?: string;
11
+ createdAt?: Date;
12
+ });
13
+ execute(dispatcher: CommandDispatcher): Promise<R | undefined>;
14
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Command = void 0;
4
+ const Message_1 = require("./Message");
5
+ class Command extends Message_1.Message {
6
+ constructor(payload, options = {}) {
7
+ super(payload, options.type, options.correlationId, options.createdAt);
8
+ this.expectReply = true;
9
+ this.ttl = 10000;
10
+ const { expectReply, ttl } = options;
11
+ if (typeof expectReply === 'boolean') {
12
+ this.expectReply = expectReply;
13
+ }
14
+ if (typeof ttl === 'number' && ttl > 0) {
15
+ this.ttl = ttl;
16
+ }
17
+ }
18
+ execute(dispatcher) {
19
+ return dispatcher.execute(this);
20
+ }
21
+ }
22
+ exports.Command = Command;
23
+ //# sourceMappingURL=Command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../../../packages/core/src/bus/Command.ts"],"names":[],"mappings":";;;AACA,uCAAoC;AAEpC,MAAsB,OAAc,SAAQ,iBAAU;IAIpD,YACE,OAAU,EACV,UAMI,EAAE;QAEN,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;QAbzD,gBAAW,GAAY,IAAI,CAAC;QAC5B,QAAG,GAAW,KAAK,CAAC;QAclC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QACrC,IAAI,OAAO,WAAW,KAAK,SAAS,EAAE;YACpC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;SAChC;QAED,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,GAAG,CAAC,EAAE;YACtC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;SAChB;IACH,CAAC;IAEM,OAAO,CAAC,UAA6B;QAC1C,OAAO,UAAU,CAAC,OAAO,CAAO,IAAI,CAAC,CAAC;IACxC,CAAC;CACF;AA7BD,0BA6BC"}
@@ -0,0 +1,5 @@
1
+ import { Command } from './Command';
2
+ export interface CommandDispatcher {
3
+ execute<T, R>(command: Command<T, R>): Promise<R | undefined>;
4
+ }
5
+ export declare const CommandDispatcher: unique symbol;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandDispatcher = void 0;
4
+ exports.CommandDispatcher = Symbol('CommandDispatcher');
5
+ //# sourceMappingURL=CommandDispatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandDispatcher.js","sourceRoot":"","sources":["../../../../../packages/core/src/bus/CommandDispatcher.ts"],"names":[],"mappings":";;;AAMa,QAAA,iBAAiB,GAAkB,MAAM,CAAC,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { EventDispatcher } from './EventDispatcher';
2
+ import { Message } from './Message';
3
+ export declare abstract class Event<T> extends Message<T> {
4
+ protected constructor(payload: T, type?: string, correlationId?: string, createdAt?: Date);
5
+ publish(dispatcher: EventDispatcher): Promise<void>;
6
+ }
7
+ export declare type EventConstructor<T = unknown> = abstract new (...args: any[]) => Event<T>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Event = void 0;
4
+ const Message_1 = require("./Message");
5
+ class Event extends Message_1.Message {
6
+ constructor(payload, type, correlationId, createdAt) {
7
+ super(payload, type, correlationId, createdAt);
8
+ }
9
+ publish(dispatcher) {
10
+ return dispatcher.publish(this);
11
+ }
12
+ }
13
+ exports.Event = Event;
14
+ //# sourceMappingURL=Event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Event.js","sourceRoot":"","sources":["../../../../../packages/core/src/bus/Event.ts"],"names":[],"mappings":";;;AACA,uCAAoC;AAEpC,MAAsB,KAAS,SAAQ,iBAAU;IAC/C,YACE,OAAU,EACV,IAAa,EACb,aAAsB,EACtB,SAAgB;QAEhB,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;IAEM,OAAO,CAAC,UAA2B;QACxC,OAAO,UAAU,CAAC,OAAO,CAAI,IAAI,CAAC,CAAC;IACrC,CAAC;CACF;AAbD,sBAaC"}
@@ -0,0 +1,10 @@
1
+ import { CommandDispatcher } from './CommandDispatcher';
2
+ import { EventDispatcher } from './EventDispatcher';
3
+ import { EventHandlerConstructor } from './EventHandler';
4
+ export interface EventBus extends EventDispatcher, CommandDispatcher {
5
+ register(type: EventHandlerConstructor): Promise<void>;
6
+ unregister(type: EventHandlerConstructor): Promise<void>;
7
+ init?(): Promise<void>;
8
+ destroy?(): Promise<void>;
9
+ }
10
+ export declare const EventBus: unique symbol;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventBus = void 0;
4
+ exports.EventBus = Symbol('EventBus');
5
+ //# sourceMappingURL=EventBus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventBus.js","sourceRoot":"","sources":["../../../../../packages/core/src/bus/EventBus.ts"],"names":[],"mappings":";;;AAca,QAAA,QAAQ,GAAkB,MAAM,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Event } from './Event';
2
+ export interface EventDispatcher {
3
+ publish<T>(event: Event<T>): Promise<void>;
4
+ }
5
+ export declare const EventDispatcher: unique symbol;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventDispatcher = void 0;
4
+ exports.EventDispatcher = Symbol('EventDispatcher');
5
+ //# sourceMappingURL=EventDispatcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventDispatcher.js","sourceRoot":"","sources":["../../../../../packages/core/src/bus/EventDispatcher.ts"],"names":[],"mappings":";;;AAMa,QAAA,eAAe,GAAkB,MAAM,CAAC,iBAAiB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export interface EventHandler<T, R = void> {
2
+ handle(payload: T): Promise<R | undefined>;
3
+ }
4
+ export declare type EventHandlerConstructor<T = unknown, R = unknown> = new (...args: any) => EventHandler<T, R>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=EventHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventHandler.js","sourceRoot":"","sources":["../../../../../packages/core/src/bus/EventHandler.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ export declare abstract class Message<T> {
2
+ readonly payload: T;
3
+ readonly type: string;
4
+ readonly correlationId: string;
5
+ readonly createdAt: Date;
6
+ protected constructor(payload: T, type?: string, correlationId?: string, createdAt?: Date);
7
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Message = void 0;
4
+ const utils_1 = require("../utils");
5
+ const uuid_1 = require("uuid");
6
+ class Message {
7
+ constructor(payload, type, correlationId, createdAt) {
8
+ this.payload = payload;
9
+ this.type = type || (0, utils_1.getTypeName)(this);
10
+ this.correlationId = correlationId || (0, uuid_1.v4)();
11
+ this.createdAt = createdAt || new Date();
12
+ }
13
+ }
14
+ exports.Message = Message;
15
+ //# sourceMappingURL=Message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Message.js","sourceRoot":"","sources":["../../../../../packages/core/src/bus/Message.ts"],"names":[],"mappings":";;;AAAA,oCAAuC;AACvC,+BAA0B;AAE1B,MAAsB,OAAO;IAK3B,YACkB,OAAU,EAC1B,IAAa,EACb,aAAsB,EACtB,SAAgB;QAHA,YAAO,GAAP,OAAO,CAAG;QAK1B,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAA,mBAAW,EAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,IAAA,SAAE,GAAE,CAAC;QAC3C,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,IAAI,IAAI,EAAE,CAAC;IAC3C,CAAC;CACF;AAfD,0BAeC"}
@@ -0,0 +1,4 @@
1
+ export interface RetryStrategy {
2
+ acquire<T extends (...args: unknown[]) => unknown>(task: T): Promise<ReturnType<T>>;
3
+ }
4
+ export declare const RetryStrategy: unique symbol;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RetryStrategy = void 0;
4
+ exports.RetryStrategy = Symbol('RetryStrategy');
5
+ //# sourceMappingURL=RetryStartegy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RetryStartegy.js","sourceRoot":"","sources":["../../../../../packages/core/src/bus/RetryStartegy.ts"],"names":[],"mappings":";;;AAMa,QAAA,aAAa,GAAkB,MAAM,CAAC,eAAe,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { EventConstructor } from '../Event';
2
+ export declare type EventName = EventConstructor | string | symbol;
3
+ export declare const bind: (...events: EventName[]) => ClassDecorator;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bind = void 0;
4
+ const Event_1 = require("../Event");
5
+ const exceptions_1 = require("../exceptions");
6
+ const bind = (...events) => target => {
7
+ const eventNames = events.map(event => {
8
+ switch (typeof event) {
9
+ case 'string':
10
+ return event;
11
+ case 'function':
12
+ return event.name;
13
+ case 'symbol':
14
+ return event.description;
15
+ default:
16
+ throw new exceptions_1.UnsupportedEventType(event);
17
+ }
18
+ });
19
+ Reflect.defineMetadata(Event_1.Event, eventNames, target);
20
+ };
21
+ exports.bind = bind;
22
+ //# sourceMappingURL=bind.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bind.js","sourceRoot":"","sources":["../../../../../../packages/core/src/bus/decorators/bind.ts"],"names":[],"mappings":";;;AAAA,oCAAmD;AACnD,8CAAqD;AAI9C,MAAM,IAAI,GACf,CAAC,GAAG,MAAmB,EAAkB,EAAE,CAC3C,MAAM,CAAC,EAAE;IACP,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QACpC,QAAQ,OAAO,KAAK,EAAE;YACpB,KAAK,QAAQ;gBACX,OAAO,KAAK,CAAC;YACf,KAAK,UAAU;gBACb,OAAO,KAAK,CAAC,IAAI,CAAC;YACpB,KAAK,QAAQ;gBACX,OAAO,KAAK,CAAC,WAAW,CAAC;YAC3B;gBACE,MAAM,IAAI,iCAAoB,CAAC,KAAK,CAAC,CAAC;SACzC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,cAAc,CAAC,aAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;AACpD,CAAC,CAAC;AAjBS,QAAA,IAAI,QAiBb"}
@@ -0,0 +1 @@
1
+ export * from './bind';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./bind"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/bus/decorators/index.ts"],"names":[],"mappings":";;;AAAA,sDAAuB"}
@@ -0,0 +1,4 @@
1
+ import { SecTesterError } from '../../exceptions';
2
+ export declare class EventHandlerNotFound extends SecTesterError {
3
+ constructor(...eventNames: string[]);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EventHandlerNotFound = void 0;
4
+ const exceptions_1 = require("../../exceptions");
5
+ class EventHandlerNotFound extends exceptions_1.SecTesterError {
6
+ constructor(...eventNames) {
7
+ super(`Event handler not found. Please register a handler for the following events: ${eventNames.join(', ')}`);
8
+ }
9
+ }
10
+ exports.EventHandlerNotFound = EventHandlerNotFound;
11
+ //# sourceMappingURL=EventHandlerNotFound.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EventHandlerNotFound.js","sourceRoot":"","sources":["../../../../../../packages/core/src/bus/exceptions/EventHandlerNotFound.ts"],"names":[],"mappings":";;;AAAA,iDAAkD;AAElD,MAAa,oBAAqB,SAAQ,2BAAc;IACtD,YAAY,GAAG,UAAoB;QACjC,KAAK,CACH,gFAAgF,UAAU,CAAC,IAAI,CAC7F,IAAI,CACL,EAAE,CACJ,CAAC;IACJ,CAAC;CACF;AARD,oDAQC"}
@@ -0,0 +1,6 @@
1
+ import { CommandDispatcher } from '../CommandDispatcher';
2
+ import { EventDispatcher } from '../EventDispatcher';
3
+ import { SecTesterError } from '../../exceptions';
4
+ export declare class IllegalOperation extends SecTesterError {
5
+ constructor(instance: EventDispatcher | CommandDispatcher);
6
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IllegalOperation = void 0;
4
+ const exceptions_1 = require("../../exceptions");
5
+ const utils_1 = require("../../utils");
6
+ class IllegalOperation extends exceptions_1.SecTesterError {
7
+ constructor(instance) {
8
+ super(`Please make sure that ${(0, utils_1.getTypeName)(instance)} established a connection with host.`);
9
+ }
10
+ }
11
+ exports.IllegalOperation = IllegalOperation;
12
+ //# sourceMappingURL=IllegalOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IllegalOperation.js","sourceRoot":"","sources":["../../../../../../packages/core/src/bus/exceptions/IllegalOperation.ts"],"names":[],"mappings":";;;AAEA,iDAAkD;AAClD,uCAA0C;AAE1C,MAAa,gBAAiB,SAAQ,2BAAc;IAClD,YAAY,QAA6C;QACvD,KAAK,CACH,yBAAyB,IAAA,mBAAW,EAClC,QAAQ,CACT,sCAAsC,CACxC,CAAC;IACJ,CAAC;CACF;AARD,4CAQC"}
@@ -0,0 +1,4 @@
1
+ import { SecTesterError } from '../../exceptions';
2
+ export declare class NoResponse extends SecTesterError {
3
+ constructor(duration: number);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NoResponse = void 0;
4
+ const exceptions_1 = require("../../exceptions");
5
+ class NoResponse extends exceptions_1.SecTesterError {
6
+ constructor(duration) {
7
+ super(`No response for ${duration} seconds.`);
8
+ }
9
+ }
10
+ exports.NoResponse = NoResponse;
11
+ //# sourceMappingURL=NoResponse.js.map