alemonjs 2.1.83-alpha.2 → 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.
@@ -10,3 +10,7 @@ export * from './format/message-api.js';
10
10
  export * from './format/message-format.js';
11
11
  export * from './format/message-format-old.js';
12
12
  export * from './router/main.js';
13
+ export * from './runtime/event-response.js';
14
+ export * from './runtime/event-middleware.js';
15
+ export { createSelects, onSelects, onState, unChildren, unState, useState } from './runtime/event-utils.js';
16
+ export { onGroup } from './runtime/event-group.js';
@@ -30,3 +30,7 @@ export { Router } from './router/dsl.js';
30
30
  export { checkFallbackHint } from './router/fallback.js';
31
31
  export { normalizeRoutePath, parseMessageText } from './router/parser.js';
32
32
  export { validateRouteArgs } from './router/validator.js';
33
+ export { OnResponse, onResponse } from './runtime/event-response.js';
34
+ export { OnMiddleware, onMiddleware } from './runtime/event-middleware.js';
35
+ export { createSelects, onSelects, onState, unChildren, unState, useState } from './runtime/event-utils.js';
36
+ export { onGroup } from './runtime/event-group.js';
@@ -17,8 +17,9 @@ async function collectMiddlewares(routeFile) {
17
17
  }
18
18
  }
19
19
  const parent = dirname(dir);
20
- if (parent === dir)
20
+ if (parent === dir) {
21
21
  break;
22
+ }
22
23
  dir = parent;
23
24
  }
24
25
  return middlewares;
@@ -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/lib/index.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  export * from './types/index.js';
2
2
  export * from './global.js';
3
+ export * from './common/index.js';
4
+ export * from './core/index.js';
5
+ export * from './platform/index.js';
6
+ export * from './application/index.js';
3
7
  export { start } from './main.js';
8
+ export * from './main.js';
4
9
  export * as common from './common/index.js';
5
10
  export * as core from './core/index.js';
6
11
  export * as platform from './platform/index.js';
package/lib/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export { ActionsEventEnum } from './types/event/actions.js';
2
- export { start } from './core/start.js';
3
2
  import * as index$1 from './common/index.js';
4
3
  export { index$1 as common };
5
4
  import * as index$2 from './core/index.js';
@@ -8,3 +7,57 @@ import * as index$3 from './platform/index.js';
8
7
  export { index$3 as platform };
9
8
  import * as index from './application/index.js';
10
9
  export { index as application };
10
+ export { start } from './core/start.js';
11
+ export { A, Body, Component, DOCTYPE, Div, H1, Head, Html, P, Style, Title, createElement, renderToString } from './common/react.js';
12
+ export { Attachment, Audio, BT, Button, Image, ImageFile, ImageURL, Link, MD, Markdown, MarkdownOriginal, Mention, Text, Video } from './application/format/message-format-old.js';
13
+ export { DEVICE_ID_HEADER, FULL_RECEIVE_HEADER, HEARTBEAT_INTERVAL, USER_AGENT_HEADER, USER_AGENT_HEADER_VALUE_MAP, reconnectInterval, timeoutTime } from './common/cbp/constants.js';
14
+ export { EventMessageText, Fail, FailAuth, FailInternal, FailParams, Ok, ResultCode, Warn, defaultLogin, defaultPlatformCommonPrefix, defaultPlatformPrefix, defaultPort, filePrefixCommon, fileSuffixMiddleware, fileSuffixResponse, processorMaxMapSize, processorRepeatedClearSize, processorRepeatedClearTimeMax, processorRepeatedClearTimeMin, processorRepeatedEventTime, processorRepeatedUserTime } from './common/variable.js';
15
+ export { Expose, clearAllExpose, disposeExpose, registerExpose } from './application/expose.js';
16
+ export { Format, FormatButtonGroup, FormatMarkDown, FormatSelect } from './application/format/message-format.js';
17
+ export { FormatEvent, wrapEvent } from './platform/event-format.js';
18
+ export { Logger, logger } from './common/logger.js';
19
+ export { MessageDirect, createDataFormat, format, getMessageIntent, sendToChannel, sendToUser } from './application/format/message-api.js';
20
+ export { OnMiddleware, onMiddleware } from './application/runtime/event-middleware.js';
21
+ export { OnResponse, onResponse } from './application/runtime/event-response.js';
22
+ export { Router } from './application/router/dsl.js';
23
+ export { SinglyLinkedList } from './common/SinglyLinkedList.js';
24
+ export { cbpPlatform } from './platform/cbp-platform.js';
25
+ export { checkFallbackHint } from './application/router/fallback.js';
26
+ export { clearInterval, clearTimeout, listSchedule, pauseSchedule, resumeSchedule, setCron, setInterval, setTimeout } from './application/schedule.js';
27
+ export { createActionRequestEnvelope, createActionResponseEnvelope, createApiRequestEnvelope, createApiResponseEnvelope, createEventEnvelope, getNormalizedDeviceId, getNormalizedEventRouteId, isCBPEnvelope, isNormalizedActionRequest, isNormalizedApiRequest, normalizeInboundMessage, toLegacyActionData, toLegacyApiData } from './common/cbp/normalize.js';
28
+ export { createDirectClient, createDirectServer, generateSocketPath } from './common/direct-channel.js';
29
+ export { createEvent, useEvent } from './application/hooks/event.js';
30
+ export { createEventName, createHash, getCachedRegExp, getInputExportPath, getRecursiveDirFiles, sanitizeForSerialization, showErrorModule, stringToNumber } from './common/utils.js';
31
+ export { createEventValue } from './platform/event-value.js';
32
+ export { createResult } from './common/result.js';
33
+ export { createSelects, onSelects, onState, unChildren, unState, useState } from './application/runtime/event-utils.js';
34
+ export { createUserHashKey, fastHash, isMaster, matchIn, useUserHashKey } from './common/identity.js';
35
+ export { createWSConnector } from './common/cbp/ws-connector.js';
36
+ export { defineChildren } from './application/define-children.js';
37
+ export { defineMiddleware } from './application/define-middleware.js';
38
+ export { definePlatform } from './platform/define-platform.js';
39
+ export { defineResponse } from './application/define-response.js';
40
+ export { defineRouter } from './application/define-router.js';
41
+ export { deviceId, generateUniqueId } from './common/cbp/runtime.js';
42
+ export { getConfig, getConfigValue, onWatchConfigValue } from './common/config.js';
43
+ export { normalizeRoutePath, parseMessageText } from './application/router/parser.js';
44
+ export { onGroup } from './application/runtime/event-group.js';
45
+ export { useAnnounce } from './application/hooks/announce.js';
46
+ export { useChannel } from './application/hooks/channel.js';
47
+ export { useClient } from './application/hooks/client.js';
48
+ export { useGuild } from './application/hooks/guild.js';
49
+ export { useHeartbeat } from './common/cbp/heartbeat.js';
50
+ export { useHistory } from './application/hooks/history.js';
51
+ export { useMe } from './application/hooks/me.js';
52
+ export { useMedia } from './application/hooks/media.js';
53
+ export { useMember } from './application/hooks/member.js';
54
+ export { useMention } from './application/hooks/mention.js';
55
+ export { useMessage, useSend, useSends } from './application/hooks/message.js';
56
+ export { useObserver, useSubscribe } from './application/hooks/subscribe.js';
57
+ export { usePermission } from './application/hooks/permission.js';
58
+ export { useReaction } from './application/hooks/reaction.js';
59
+ export { useRequest } from './application/hooks/request.js';
60
+ export { useRole } from './application/hooks/role.js';
61
+ export { useRoute } from './application/hooks/route.js';
62
+ export { useUser } from './application/hooks/user.js';
63
+ export { validateRouteArgs } from './application/router/validator.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs",
3
- "version": "2.1.83-alpha.2",
3
+ "version": "2.1.83-alpha.4",
4
4
  "description": "bot script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",