@wabot-dev/framework 0.2.0-beta.10 → 0.2.0-beta.11
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/dist/src/addon/chat-controller/cmd/CmdChannel.js +12 -7
- package/dist/src/addon/chat-controller/socket/SocketChannel.js +11 -5
- package/dist/src/feature/chat-controller/runChatControllers.js +6 -9
- package/dist/src/feature/socket-controller/runSocketControllers.js +1 -0
- package/dist/src/index.d.ts +3 -2
- package/package.json +1 -1
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { __decorate } from 'tslib';
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
2
|
import { injectable } from '../../../core/injection/index.js';
|
|
3
3
|
import * as readline from 'readline';
|
|
4
4
|
import * as fs from 'fs';
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import { Random } from '../../../core/random/Random.js';
|
|
7
|
+
import { Auth } from '../../../core/auth/Auth.js';
|
|
7
8
|
|
|
8
9
|
var CmdChannel_1;
|
|
9
10
|
const chatIdPath = '.cmd-channel/id.json';
|
|
10
11
|
const authInfoPath = '.cmd-channel/auth-info.json';
|
|
11
12
|
let CmdChannel = CmdChannel_1 = class CmdChannel {
|
|
13
|
+
auth;
|
|
12
14
|
authInfo = undefined;
|
|
13
15
|
chatId = undefined;
|
|
14
16
|
rl = readline.createInterface({
|
|
@@ -16,6 +18,9 @@ let CmdChannel = CmdChannel_1 = class CmdChannel {
|
|
|
16
18
|
output: process.stdout,
|
|
17
19
|
});
|
|
18
20
|
callBack = null;
|
|
21
|
+
constructor(auth) {
|
|
22
|
+
this.auth = auth;
|
|
23
|
+
}
|
|
19
24
|
listen(callback) {
|
|
20
25
|
this.callBack = callback;
|
|
21
26
|
}
|
|
@@ -55,18 +60,18 @@ let CmdChannel = CmdChannel_1 = class CmdChannel {
|
|
|
55
60
|
reply: (message) => {
|
|
56
61
|
console.log(`\n[${message.senderName}]: ${message.text}\n`);
|
|
57
62
|
this.rl.prompt();
|
|
63
|
+
if (this.auth.isAssigned()) {
|
|
64
|
+
writeJsonToFile(authInfoPath, this.auth.require());
|
|
65
|
+
}
|
|
58
66
|
},
|
|
59
|
-
|
|
60
|
-
setAuthInfo: (authInfo) => {
|
|
61
|
-
this.authInfo = authInfo || null;
|
|
62
|
-
writeJsonToFile(authInfoPath, this.authInfo);
|
|
63
|
-
},
|
|
67
|
+
injectInstances: [[Auth, this.auth]],
|
|
64
68
|
});
|
|
65
69
|
});
|
|
66
70
|
}
|
|
67
71
|
};
|
|
68
72
|
CmdChannel = CmdChannel_1 = __decorate([
|
|
69
|
-
injectable()
|
|
73
|
+
injectable(),
|
|
74
|
+
__metadata("design:paramtypes", [Auth])
|
|
70
75
|
], CmdChannel);
|
|
71
76
|
function writeJsonToFile(filename, data) {
|
|
72
77
|
const filePath = path.resolve(process.cwd(), filename);
|
|
@@ -10,6 +10,7 @@ import { SocketChannelConfig } from './SocketChannelConfig.js';
|
|
|
10
10
|
import '../../../core/validation/metadata/ValidationMetadataStore.js';
|
|
11
11
|
import { isNotEmpty } from '../../../core/validation/validators/is-not-empty/@isNotEmpty.js';
|
|
12
12
|
import { isString } from '../../../core/validation/validators/is-string/@isString.js';
|
|
13
|
+
import { Auth } from '../../../core/auth/Auth.js';
|
|
13
14
|
|
|
14
15
|
var SocketChannel_1;
|
|
15
16
|
class SocketChannelReceivedMessage {
|
|
@@ -43,6 +44,10 @@ let SocketChannel = SocketChannel_1 = class SocketChannel {
|
|
|
43
44
|
configController() {
|
|
44
45
|
const channel = this;
|
|
45
46
|
let SocketChannelController = class SocketChannelController {
|
|
47
|
+
auth;
|
|
48
|
+
constructor(auth) {
|
|
49
|
+
this.auth = auth;
|
|
50
|
+
}
|
|
46
51
|
onMessage(message, socket) {
|
|
47
52
|
if (!channel.callBack)
|
|
48
53
|
return;
|
|
@@ -64,10 +69,10 @@ let SocketChannel = SocketChannel_1 = class SocketChannel {
|
|
|
64
69
|
reply: (message) => {
|
|
65
70
|
socket.emit('message', message);
|
|
66
71
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
injectInstances: [
|
|
73
|
+
[Socket, socket],
|
|
74
|
+
[Auth, this.auth],
|
|
75
|
+
],
|
|
71
76
|
});
|
|
72
77
|
}
|
|
73
78
|
};
|
|
@@ -79,7 +84,8 @@ let SocketChannel = SocketChannel_1 = class SocketChannel {
|
|
|
79
84
|
], SocketChannelController.prototype, "onMessage", null);
|
|
80
85
|
SocketChannelController = __decorate([
|
|
81
86
|
socketController(channel.config.namespace),
|
|
82
|
-
handshakeMiddlewares(channel.config.handshakeMidlewares ?? [])
|
|
87
|
+
handshakeMiddlewares(channel.config.handshakeMidlewares ?? []),
|
|
88
|
+
__metadata("design:paramtypes", [Auth])
|
|
83
89
|
], SocketChannelController);
|
|
84
90
|
this.controller = SocketChannelController;
|
|
85
91
|
}
|
|
@@ -62,18 +62,15 @@ function runChatControllers(controllers) {
|
|
|
62
62
|
chat,
|
|
63
63
|
...channelMessage,
|
|
64
64
|
});
|
|
65
|
+
if (channelMessage.injectInstances) {
|
|
66
|
+
for (const [token, instance] of channelMessage.injectInstances) {
|
|
67
|
+
chatContainer.registerInstance(token, instance);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
65
70
|
const chatController = chatContainer.resolve(channelMetadata.controllerConstructor);
|
|
66
71
|
const receivedMessage = {
|
|
67
72
|
message: channelMessage.message,
|
|
68
|
-
reply:
|
|
69
|
-
channelMessage.reply(message);
|
|
70
|
-
if (channelMessage.setAuthInfo) {
|
|
71
|
-
const auth = chatContainer.resolve(Auth);
|
|
72
|
-
if (auth.wasOverrided()) {
|
|
73
|
-
channelMessage.setAuthInfo(auth['authInfo'] || undefined);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
},
|
|
73
|
+
reply: channelMessage.reply,
|
|
77
74
|
};
|
|
78
75
|
chatController[channelMetadata.functionName](receivedMessage);
|
|
79
76
|
});
|
package/dist/src/index.d.ts
CHANGED
|
@@ -709,8 +709,7 @@ interface IReceivedMessage {
|
|
|
709
709
|
|
|
710
710
|
interface IChannelMessage extends IReceivedMessage {
|
|
711
711
|
chatConnection: IChatConnection;
|
|
712
|
-
|
|
713
|
-
setAuthInfo?: (authInfo: IStorableData | undefined) => void;
|
|
712
|
+
injectInstances?: [any, any][];
|
|
714
713
|
}
|
|
715
714
|
|
|
716
715
|
interface IChatChannel {
|
|
@@ -1263,10 +1262,12 @@ declare class WabotChatAdapter implements IChatAdapter {
|
|
|
1263
1262
|
declare function cmd(): (target: object, propertyKey: string | symbol) => void;
|
|
1264
1263
|
|
|
1265
1264
|
declare class CmdChannel implements IChatChannel {
|
|
1265
|
+
private auth;
|
|
1266
1266
|
private authInfo;
|
|
1267
1267
|
private chatId;
|
|
1268
1268
|
private rl;
|
|
1269
1269
|
private callBack;
|
|
1270
|
+
constructor(auth: Auth<any>);
|
|
1270
1271
|
listen(callback: (message: IChannelMessage) => void): void;
|
|
1271
1272
|
connect(): void;
|
|
1272
1273
|
}
|