alemonjs 2.1.83-alpha.3 → 2.1.83-alpha.4

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.
@@ -14,11 +14,29 @@ import 'v8';
14
14
  import 'os';
15
15
  import { USER_AGENT_HEADER, USER_AGENT_HEADER_VALUE_MAP, DEVICE_ID_HEADER, FULL_RECEIVE_HEADER } from '../../../common/cbp/constants.js';
16
16
  import '../../../common/cbp/runtime.js';
17
- import { normalizeInboundMessage, getNormalizedDeviceId, getNormalizedEventRouteId } from '../../../common/cbp/normalize.js';
17
+ import { normalizeInboundMessage, getNormalizedDeviceId, getNormalizedEventRouteId, isNormalizedActionRequest, toLegacyActionData, isNormalizedApiRequest, toLegacyApiData } from '../../../common/cbp/normalize.js';
18
18
  import { platformClient, childrenClient, fullClient, childrenBind, clientBindCount, unbindClient, bindChannelToClient } from '../processor/config.js';
19
19
  import { createTestOneController } from './testone.js';
20
20
  import { getClientChild } from '../../process/ipc-bridge.js';
21
21
 
22
+ const stringifyForSocket = (payload) => {
23
+ return flattedJSON.stringify(payload);
24
+ };
25
+ const normalizeTestOneOutboundMessage = (message) => {
26
+ try {
27
+ const inbound = flattedJSON.parse(String(message));
28
+ const normalized = normalizeInboundMessage(inbound);
29
+ if (isNormalizedActionRequest(normalized)) {
30
+ return stringifyForSocket(toLegacyActionData(normalized));
31
+ }
32
+ if (isNormalizedApiRequest(normalized)) {
33
+ return stringifyForSocket(toLegacyApiData(normalized));
34
+ }
35
+ }
36
+ catch {
37
+ }
38
+ return message.toString();
39
+ };
22
40
  const routeNormalizedMessage = (message, input) => {
23
41
  const normalized = normalizeInboundMessage(input);
24
42
  if (!normalized) {
@@ -156,7 +174,7 @@ const setChildrenClient = (originId, ws) => {
156
174
  ws.on('message', (message) => {
157
175
  if (global.__sandbox) {
158
176
  if (global.testoneClient?.readyState === WebSocket.OPEN) {
159
- global.testoneClient.send(message.toString());
177
+ global.testoneClient.send(normalizeTestOneOutboundMessage(message.toString()));
160
178
  }
161
179
  return;
162
180
  }
@@ -193,7 +211,7 @@ const setFullClient = (originId, ws) => {
193
211
  ws.on('message', (message) => {
194
212
  if (global.__sandbox) {
195
213
  if (global.testoneClient?.readyState === WebSocket.OPEN) {
196
- global.testoneClient.send(message.toString());
214
+ global.testoneClient.send(normalizeTestOneOutboundMessage(message.toString()));
197
215
  }
198
216
  return;
199
217
  }
@@ -10,6 +10,7 @@ import 'net';
10
10
  import 'v8';
11
11
  import 'os';
12
12
  import '../../common/cbp/runtime.js';
13
+ import { normalizeInboundMessage, isNormalizedActionRequest, toLegacyActionData, isNormalizedApiRequest, toLegacyApiData } from '../../common/cbp/normalize.js';
13
14
 
14
15
  let platformChild = null;
15
16
  let clientChild = null;
@@ -49,7 +50,15 @@ const forwardFromClient = (data) => {
49
50
  }
50
51
  if (global.__sandbox && global.testoneClient) {
51
52
  try {
52
- const messageStr = typeof safeData === 'string' ? safeData : flattedJSON.stringify(safeData);
53
+ const normalized = normalizeInboundMessage(safeData);
54
+ let outbound = safeData;
55
+ if (isNormalizedActionRequest(normalized)) {
56
+ outbound = toLegacyActionData(normalized);
57
+ }
58
+ else if (isNormalizedApiRequest(normalized)) {
59
+ outbound = toLegacyApiData(normalized);
60
+ }
61
+ const messageStr = typeof outbound === 'string' ? outbound : flattedJSON.stringify(outbound);
53
62
  if (global.testoneClient.readyState === WebSocket.OPEN) {
54
63
  global.testoneClient.send(messageStr);
55
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.83-alpha.3",
3
+ "version": "2.1.83-alpha.4",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",