@orion-js/echoes 2.2.7 → 3.0.0-alpha.12
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/lib/config.d.ts +3 -0
- package/lib/config.js +3 -12
- package/lib/echo/deserialize.d.ts +1 -0
- package/lib/echo/deserialize.js +10 -13
- package/lib/echo/index.d.ts +9 -0
- package/lib/echo/index.js +30 -38
- package/lib/echo/types.d.ts +5 -0
- package/lib/echo/types.js +4 -9
- package/lib/index.d.ts +5 -0
- package/lib/index.js +13 -38
- package/lib/publish/index.d.ts +5 -0
- package/lib/publish/index.js +26 -32
- package/lib/publish/serialize.d.ts +1 -0
- package/lib/publish/serialize.js +12 -19
- package/lib/request/getSignature.d.ts +1 -0
- package/lib/request/getSignature.js +17 -19
- package/lib/request/getURL.d.ts +1 -0
- package/lib/request/getURL.js +13 -19
- package/lib/request/index.d.ts +2 -0
- package/lib/request/index.js +40 -58
- package/lib/requestsHandler/checkSignature.d.ts +1 -0
- package/lib/requestsHandler/checkSignature.js +12 -17
- package/lib/requestsHandler/getEcho.d.ts +1 -0
- package/lib/requestsHandler/getEcho.js +17 -25
- package/lib/requestsHandler/index.d.ts +2 -0
- package/lib/requestsHandler/index.js +26 -40
- package/lib/startService/index.d.ts +2 -0
- package/lib/startService/index.js +37 -50
- package/lib/types.d.ts +51 -0
- package/lib/types.js +2 -0
- package/package.json +16 -8
- package/jest.config.js +0 -7
- package/yarn-error.log +0 -2416
|
@@ -1,41 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} = body;
|
|
29
|
-
const echo = (0, _getEcho.default)(method);
|
|
30
|
-
const result = await echo.onRequest(serializedParams);
|
|
31
|
-
return {
|
|
32
|
-
result: (0, _serialize.default)(result)
|
|
33
|
-
};
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error('Error at echo requests handler:');
|
|
36
|
-
console.error(error);
|
|
37
|
-
return {
|
|
38
|
-
error: error.message
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
}
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getEcho_1 = __importDefault(require("./getEcho"));
|
|
7
|
+
const serialize_1 = __importDefault(require("../publish/serialize"));
|
|
8
|
+
const checkSignature_1 = __importDefault(require("./checkSignature"));
|
|
9
|
+
async function default_1({ getBodyJSON }) {
|
|
10
|
+
try {
|
|
11
|
+
const { body, signature } = await getBodyJSON();
|
|
12
|
+
(0, checkSignature_1.default)(body, signature);
|
|
13
|
+
const { method, serializedParams } = body;
|
|
14
|
+
const echo = (0, getEcho_1.default)(method);
|
|
15
|
+
const result = await echo.onRequest(serializedParams);
|
|
16
|
+
return {
|
|
17
|
+
result: (0, serialize_1.default)(result)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error('Error at echo requests handler:', error);
|
|
22
|
+
return {
|
|
23
|
+
error: error.message
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.default = default_1;
|
|
@@ -1,53 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
_config.default.consumer = kafka.consumer(options.consumer);
|
|
22
|
-
|
|
23
|
-
_config.default.producer.connect();
|
|
24
|
-
|
|
25
|
-
_config.default.consumer.connect();
|
|
26
|
-
|
|
27
|
-
for (const topic in options.echoes) {
|
|
28
|
-
const echo = options.echoes[topic];
|
|
29
|
-
if (echo.type !== _types.default.event) continue;
|
|
30
|
-
|
|
31
|
-
_config.default.consumer.subscribe({
|
|
32
|
-
topic
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
_config.default.consumer.run({
|
|
37
|
-
eachMessage: async params => {
|
|
38
|
-
const echo = options.echoes[params.topic];
|
|
39
|
-
if (!echo) return;
|
|
40
|
-
if (echo.type !== _types.default.event) return;
|
|
41
|
-
await echo.onMessage(params);
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const kafkajs_1 = require("kafkajs");
|
|
7
|
+
const config_1 = __importDefault(require("../config"));
|
|
8
|
+
const requestsHandler_1 = __importDefault(require("../requestsHandler"));
|
|
9
|
+
const types_1 = __importDefault(require("../echo/types"));
|
|
10
|
+
function default_1(options) {
|
|
11
|
+
const kafka = new kafkajs_1.Kafka(options.client);
|
|
12
|
+
config_1.default.producer = kafka.producer(options.producer);
|
|
13
|
+
config_1.default.consumer = kafka.consumer(options.consumer);
|
|
14
|
+
config_1.default.producer.connect();
|
|
15
|
+
config_1.default.consumer.connect();
|
|
16
|
+
for (const topic in options.echoes) {
|
|
17
|
+
const echo = options.echoes[topic];
|
|
18
|
+
if (echo.type !== types_1.default.event)
|
|
19
|
+
continue;
|
|
20
|
+
config_1.default.consumer.subscribe({ topic });
|
|
42
21
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
22
|
+
config_1.default.consumer.run({
|
|
23
|
+
eachMessage: async (payload) => {
|
|
24
|
+
const echo = options.echoes[payload.topic];
|
|
25
|
+
if (!echo)
|
|
26
|
+
return;
|
|
27
|
+
if (echo.type !== types_1.default.event)
|
|
28
|
+
return;
|
|
29
|
+
await echo.onMessage(payload);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
if (options.requests) {
|
|
33
|
+
config_1.default.requests = options.requests;
|
|
34
|
+
config_1.default.echoes = options.echoes;
|
|
35
|
+
if (config_1.default.requests.startHandler) {
|
|
36
|
+
config_1.default.requests.startHandler(requestsHandler_1.default);
|
|
37
|
+
}
|
|
51
38
|
}
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
}
|
|
40
|
+
exports.default = default_1;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ConsumerConfig, KafkaConfig, ProducerConfig, Consumer, Producer, EachMessagePayload } from 'kafkajs';
|
|
2
|
+
export interface EchoConfig {
|
|
3
|
+
type: 'event' | 'request';
|
|
4
|
+
resolve(params: any, context?: any): Promise<any>;
|
|
5
|
+
}
|
|
6
|
+
export interface Echo extends EchoConfig {
|
|
7
|
+
onMessage(messageData: EachMessagePayload): Promise<void>;
|
|
8
|
+
onRequest(serializedParams: string): any;
|
|
9
|
+
}
|
|
10
|
+
export interface PublishOptions {
|
|
11
|
+
topic: string;
|
|
12
|
+
params: any;
|
|
13
|
+
acks?: number;
|
|
14
|
+
timeout?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface RequestOptions {
|
|
17
|
+
method: string;
|
|
18
|
+
service: string;
|
|
19
|
+
params: any;
|
|
20
|
+
}
|
|
21
|
+
export interface RequestHandlerResponse {
|
|
22
|
+
result?: any;
|
|
23
|
+
error?: any;
|
|
24
|
+
}
|
|
25
|
+
export interface RequestsHandlerParams {
|
|
26
|
+
getBodyJSON(): Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
export interface RequestsConfig {
|
|
29
|
+
key: string;
|
|
30
|
+
startHandler(handler: (params: RequestsHandlerParams) => Promise<RequestHandlerResponse>): any;
|
|
31
|
+
services: {
|
|
32
|
+
[key: string]: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface EchoesOptions {
|
|
36
|
+
client: KafkaConfig;
|
|
37
|
+
producer: ProducerConfig;
|
|
38
|
+
consumer: ConsumerConfig;
|
|
39
|
+
requests: RequestsConfig;
|
|
40
|
+
echoes: {
|
|
41
|
+
[key: string]: Echo;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface EchoesConfigHandler {
|
|
45
|
+
producer?: Producer;
|
|
46
|
+
consumer?: Consumer;
|
|
47
|
+
requests?: RequestsConfig;
|
|
48
|
+
echoes?: {
|
|
49
|
+
[key: string]: Echo;
|
|
50
|
+
};
|
|
51
|
+
}
|
package/lib/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/echoes",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.12",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
|
+
"types": "lib/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"/lib"
|
|
8
|
+
],
|
|
5
9
|
"author": "nicolaslopezj",
|
|
6
10
|
"license": "MIT",
|
|
7
11
|
"scripts": {
|
|
8
|
-
"
|
|
12
|
+
"test": "exit 0",
|
|
9
13
|
"prepare": "yarn run build",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
14
|
+
"clean": "rm -rf ./lib",
|
|
15
|
+
"build": "yarn run clean && tsc",
|
|
16
|
+
"watch": "yarn run clean && tsc -w"
|
|
13
17
|
},
|
|
14
18
|
"dependencies": {
|
|
15
|
-
"@orion-js/helpers": "^
|
|
19
|
+
"@orion-js/helpers": "^3.0.0-alpha.11",
|
|
20
|
+
"@orion-js/resolvers": "^3.0.0-alpha.12",
|
|
21
|
+
"@orion-js/schema": "^3.0.0-alpha.12",
|
|
16
22
|
"axios": "^0.23.0",
|
|
17
23
|
"jssha": "^3.2.0",
|
|
18
24
|
"kafkajs": "^1.15.0",
|
|
@@ -23,10 +29,12 @@
|
|
|
23
29
|
"@babel/core": "^7.5.5",
|
|
24
30
|
"@babel/plugin-transform-runtime": "^7.5.5",
|
|
25
31
|
"@babel/preset-env": "^7.5.5",
|
|
26
|
-
"@babel/runtime": "^7.5.5"
|
|
32
|
+
"@babel/runtime": "^7.5.5",
|
|
33
|
+
"@shelf/jest-mongodb": "^2.1.0",
|
|
34
|
+
"typescript": "^4.4.4"
|
|
27
35
|
},
|
|
28
36
|
"publishConfig": {
|
|
29
37
|
"access": "public"
|
|
30
38
|
},
|
|
31
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "57034d6f442e89a9c8f5dfc076e1ab366d401110"
|
|
32
40
|
}
|