alemonjs 2.1.42 → 2.1.43
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/app/message-api.js +0 -2
- package/lib/cbp/connects/platform.js +3 -3
- package/lib/cbp/processor/actions.js +5 -4
- package/lib/cbp/processor/api.js +5 -4
- package/lib/core/index.js +1 -1
- package/lib/core/utils.d.ts +1 -0
- package/lib/core/utils.js +5 -1
- package/lib/index.js +1 -1
- package/lib/process/direct-channel.js +3 -1
- package/lib/process/ipc-bridge.js +10 -4
- package/package.json +1 -1
package/lib/app/message-api.js
CHANGED
|
@@ -45,7 +45,6 @@ class MessageDirect {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
;
|
|
49
48
|
async sendToUser(params) {
|
|
50
49
|
if (!params.OpenID || typeof params.OpenID !== 'string') {
|
|
51
50
|
logger.error({
|
|
@@ -65,7 +64,6 @@ class MessageDirect {
|
|
|
65
64
|
}
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
|
-
;
|
|
69
67
|
}
|
|
70
68
|
const sendToChannel = async (SpaceId, data) => {
|
|
71
69
|
if (!SpaceId || typeof SpaceId !== 'string') {
|
|
@@ -5,7 +5,7 @@ import { ResultCode } from '../../core/variable.js';
|
|
|
5
5
|
import 'fs';
|
|
6
6
|
import 'path';
|
|
7
7
|
import 'yaml';
|
|
8
|
-
import '../../core/utils.js';
|
|
8
|
+
import { sanitizeForSerialization } from '../../core/utils.js';
|
|
9
9
|
import { createWSConnector } from './base.js';
|
|
10
10
|
import { createDirectClient } from '../../process/direct-channel.js';
|
|
11
11
|
|
|
@@ -88,7 +88,7 @@ const cbpPlatformIPC = (open, existingActionReplys, existingApiReplys) => {
|
|
|
88
88
|
if (typeof process.send === 'function') {
|
|
89
89
|
data.DeviceId = deviceId;
|
|
90
90
|
data.CreateAt = Date.now();
|
|
91
|
-
process.send({ type: 'ipc:data', data });
|
|
91
|
+
process.send({ type: 'ipc:data', data: sanitizeForSerialization(data) });
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
const replyAction = (data, payload) => {
|
|
@@ -188,7 +188,7 @@ const cbpPlatform = (url, options = {
|
|
|
188
188
|
if (global.chatbotPlatform && global.chatbotPlatform.readyState === WebSocket.OPEN) {
|
|
189
189
|
data.DeviceId = deviceId;
|
|
190
190
|
data.CreateAt = Date.now();
|
|
191
|
-
global.chatbotPlatform.send(flattedJSON.stringify(data));
|
|
191
|
+
global.chatbotPlatform.send(flattedJSON.stringify(sanitizeForSerialization(data)));
|
|
192
192
|
}
|
|
193
193
|
};
|
|
194
194
|
const actionReplys = [];
|
|
@@ -3,7 +3,7 @@ import { ResultCode } from '../../core/variable.js';
|
|
|
3
3
|
import 'fs';
|
|
4
4
|
import 'path';
|
|
5
5
|
import 'yaml';
|
|
6
|
-
import { createResult } from '../../core/utils.js';
|
|
6
|
+
import { sanitizeForSerialization, createResult } from '../../core/utils.js';
|
|
7
7
|
import { generateUniqueId, deviceId, actionResolves, actionTimeouts, timeoutTime } from './config.js';
|
|
8
8
|
import { getDirectSend } from './transport.js';
|
|
9
9
|
|
|
@@ -24,14 +24,15 @@ const sendAction = (data) => {
|
|
|
24
24
|
return new Promise(resolve => {
|
|
25
25
|
data.actionId = actionId;
|
|
26
26
|
data.DeviceId = deviceId;
|
|
27
|
+
const safeData = sanitizeForSerialization(data);
|
|
27
28
|
const directSend = getDirectSend();
|
|
28
29
|
if (directSend) {
|
|
29
|
-
directSend(
|
|
30
|
+
directSend(safeData);
|
|
30
31
|
setupActionResolve(actionId, resolve);
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
34
|
if (process.env.__ALEMON_IPC === '1' && typeof process.send === 'function') {
|
|
34
|
-
process.send({ type: 'ipc:data', data });
|
|
35
|
+
process.send({ type: 'ipc:data', data: safeData });
|
|
35
36
|
setupActionResolve(actionId, resolve);
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
@@ -39,7 +40,7 @@ const sendAction = (data) => {
|
|
|
39
40
|
resolve([createResult(ResultCode.Fail, 'Chatbot client is not available', null)]);
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
global.chatbotClient?.send(flattedJSON.stringify(
|
|
43
|
+
global.chatbotClient?.send(flattedJSON.stringify(safeData));
|
|
43
44
|
setupActionResolve(actionId, resolve);
|
|
44
45
|
});
|
|
45
46
|
};
|
package/lib/cbp/processor/api.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ResultCode } from '../../core/variable.js';
|
|
|
2
2
|
import 'fs';
|
|
3
3
|
import 'path';
|
|
4
4
|
import 'yaml';
|
|
5
|
-
import { createResult } from '../../core/utils.js';
|
|
5
|
+
import { sanitizeForSerialization, createResult } from '../../core/utils.js';
|
|
6
6
|
import { generateUniqueId, deviceId, apiResolves, apiTimeouts, timeoutTime } from './config.js';
|
|
7
7
|
import * as flattedJSON from 'flatted';
|
|
8
8
|
import { getDirectSend } from './transport.js';
|
|
@@ -24,14 +24,15 @@ const sendAPI = (data) => {
|
|
|
24
24
|
return new Promise(resolve => {
|
|
25
25
|
data.apiId = ApiId;
|
|
26
26
|
data.DeviceId = deviceId;
|
|
27
|
+
const safeData = sanitizeForSerialization(data);
|
|
27
28
|
const directSend = getDirectSend();
|
|
28
29
|
if (directSend) {
|
|
29
|
-
directSend(
|
|
30
|
+
directSend(safeData);
|
|
30
31
|
setupApiResolve(ApiId, resolve);
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
33
34
|
if (process.env.__ALEMON_IPC === '1' && typeof process.send === 'function') {
|
|
34
|
-
process.send({ type: 'ipc:data', data });
|
|
35
|
+
process.send({ type: 'ipc:data', data: safeData });
|
|
35
36
|
setupApiResolve(ApiId, resolve);
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
@@ -39,7 +40,7 @@ const sendAPI = (data) => {
|
|
|
39
40
|
resolve([createResult(ResultCode.Fail, 'Chatbot client is not available', null)]);
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
global.chatbotClient?.send(flattedJSON.stringify(
|
|
43
|
+
global.chatbotClient?.send(flattedJSON.stringify(safeData));
|
|
43
44
|
setupApiResolve(ApiId, resolve);
|
|
44
45
|
});
|
|
45
46
|
};
|
package/lib/core/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ResultCode } from './variable.js';
|
|
2
2
|
export { getConfig, getConfigValue, onWatchConfigValue } from './config.js';
|
|
3
|
-
export { createEventName, createHash, createResult, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './utils.js';
|
|
3
|
+
export { createEventName, createHash, createResult, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey } from './utils.js';
|
package/lib/core/utils.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const getRecursiveDirFiles: (dir: string, condition?: (func: Dire
|
|
|
17
17
|
name: string;
|
|
18
18
|
}[];
|
|
19
19
|
export declare const showErrorModule: (e: Error) => void;
|
|
20
|
+
export declare const sanitizeForSerialization: (data: any) => any;
|
|
20
21
|
export declare const getInputExportPath: (input?: string) => any;
|
|
21
22
|
export type Result<T = any> = {
|
|
22
23
|
code: ResultCode;
|
package/lib/core/utils.js
CHANGED
|
@@ -96,6 +96,10 @@ const showErrorModule = (e) => {
|
|
|
96
96
|
data: e
|
|
97
97
|
});
|
|
98
98
|
};
|
|
99
|
+
const sanitizeForSerialization = (data) => {
|
|
100
|
+
const flatted = require('flatted');
|
|
101
|
+
return flatted.parse(flatted.stringify(data));
|
|
102
|
+
};
|
|
99
103
|
const createExports = (packageJson) => {
|
|
100
104
|
if (packageJson?.exports) {
|
|
101
105
|
if (typeof packageJson.exports === 'string') {
|
|
@@ -131,4 +135,4 @@ const createResult = (code, message, data) => {
|
|
|
131
135
|
};
|
|
132
136
|
};
|
|
133
137
|
|
|
134
|
-
export { createEventName, createHash, createResult, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey };
|
|
138
|
+
export { createEventName, createHash, createResult, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey };
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { ActionsEventEnum } from './types/event/actions.js';
|
|
2
2
|
export { ResultCode } from './core/variable.js';
|
|
3
3
|
export { getConfig, getConfigValue, onWatchConfigValue } from './core/config.js';
|
|
4
|
-
export { createEventName, createHash, createResult, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
|
|
4
|
+
export { createEventName, createHash, createResult, fastHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, sanitizeForSerialization, showErrorModule, stringToNumber, useUserHashKey } from './core/utils.js';
|
|
5
5
|
export { cbpClient } from './cbp/connects/client.js';
|
|
6
6
|
export { cbpPlatform } from './cbp/connects/platform.js';
|
|
7
7
|
export { cbpServer } from './cbp/server/main.js';
|
|
@@ -3,6 +3,7 @@ import * as v8 from 'v8';
|
|
|
3
3
|
import * as os from 'os';
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import * as fs from 'fs';
|
|
6
|
+
import * as flattedJSON from 'flatted';
|
|
6
7
|
|
|
7
8
|
const generateSocketPath = () => {
|
|
8
9
|
if (process.platform === 'win32') {
|
|
@@ -11,7 +12,8 @@ const generateSocketPath = () => {
|
|
|
11
12
|
return path.join(os.tmpdir(), `alemon-direct-${process.pid}-${Date.now()}.sock`);
|
|
12
13
|
};
|
|
13
14
|
const encodeMessage = (data) => {
|
|
14
|
-
const
|
|
15
|
+
const safeData = flattedJSON.parse(flattedJSON.stringify(data));
|
|
16
|
+
const serialized = v8.serialize(safeData);
|
|
15
17
|
const buf = Buffer.allocUnsafe(4 + serialized.length);
|
|
16
18
|
buf.writeUInt32BE(serialized.length, 0);
|
|
17
19
|
serialized.copy(buf, 4);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { WebSocket } from 'ws';
|
|
2
2
|
import { fullClient } from '../cbp/processor/config.js';
|
|
3
3
|
import * as flattedJSON from 'flatted';
|
|
4
|
+
import 'fs';
|
|
5
|
+
import 'path';
|
|
6
|
+
import 'yaml';
|
|
7
|
+
import { sanitizeForSerialization } from '../core/utils.js';
|
|
4
8
|
|
|
5
9
|
let platformChild = null;
|
|
6
10
|
let clientChild = null;
|
|
@@ -13,12 +17,13 @@ const setClientChild = (child) => {
|
|
|
13
17
|
const getPlatformChild = () => platformChild;
|
|
14
18
|
const getClientChild = () => clientChild;
|
|
15
19
|
const forwardFromPlatform = (data) => {
|
|
20
|
+
const safeData = sanitizeForSerialization(data);
|
|
16
21
|
if (clientChild?.connected) {
|
|
17
|
-
clientChild.send({ type: 'ipc:data', data });
|
|
22
|
+
clientChild.send({ type: 'ipc:data', data: safeData });
|
|
18
23
|
}
|
|
19
24
|
if (fullClient.size > 0) {
|
|
20
25
|
try {
|
|
21
|
-
const messageStr = flattedJSON.stringify(
|
|
26
|
+
const messageStr = flattedJSON.stringify(safeData);
|
|
22
27
|
fullClient.forEach((ws, id) => {
|
|
23
28
|
if (ws.readyState === WebSocket.OPEN) {
|
|
24
29
|
ws.send(messageStr);
|
|
@@ -33,12 +38,13 @@ const forwardFromPlatform = (data) => {
|
|
|
33
38
|
}
|
|
34
39
|
};
|
|
35
40
|
const forwardFromClient = (data) => {
|
|
41
|
+
const safeData = sanitizeForSerialization(data);
|
|
36
42
|
if (platformChild?.connected) {
|
|
37
|
-
platformChild.send({ type: 'ipc:data', data });
|
|
43
|
+
platformChild.send({ type: 'ipc:data', data: safeData });
|
|
38
44
|
}
|
|
39
45
|
if (global.__sandbox && global.testoneClient) {
|
|
40
46
|
try {
|
|
41
|
-
const messageStr = typeof
|
|
47
|
+
const messageStr = typeof safeData === 'string' ? safeData : flattedJSON.stringify(safeData);
|
|
42
48
|
if (global.testoneClient.readyState === WebSocket.OPEN) {
|
|
43
49
|
global.testoneClient.send(messageStr);
|
|
44
50
|
}
|