@wabot-dev/framework 0.1.0-beta.62 → 0.1.0-beta.64
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/auth/api-key/ApiKeyConnectionGuardMiddleware.js +4 -7
- package/dist/src/addon/auth/jwt/JwtConnectionGuardMiddleware.js +2 -2
- package/dist/src/addon/chat-bot/wabot/WabotChatAdapter.js +1 -1
- package/dist/src/feature/mindset/MindsetOperator.js +13 -1
- package/dist/src/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -2,7 +2,6 @@ import { __decorate, __metadata } from 'tslib';
|
|
|
2
2
|
import { Auth } from '../../../core/auth/Auth.js';
|
|
3
3
|
import { CustomError } from '../../../core/error/CustomError.js';
|
|
4
4
|
import { injectable } from '../../../core/injection/index.js';
|
|
5
|
-
import { ApiKey } from './ApiKey.js';
|
|
6
5
|
import { ApiKeyRepository } from './ApiKeyRepository.js';
|
|
7
6
|
|
|
8
7
|
let ApiKeyConnectionGuardMiddleware = class ApiKeyConnectionGuardMiddleware {
|
|
@@ -19,8 +18,8 @@ let ApiKeyConnectionGuardMiddleware = class ApiKeyConnectionGuardMiddleware {
|
|
|
19
18
|
authorization = authorization[0];
|
|
20
19
|
}
|
|
21
20
|
if (authorization) {
|
|
22
|
-
const [
|
|
23
|
-
if (
|
|
21
|
+
const [prefix, token] = authorization.split(' ');
|
|
22
|
+
if (prefix.toLowerCase() !== 'api-key' || !token) {
|
|
24
23
|
throw new CustomError({
|
|
25
24
|
httpCode: 401,
|
|
26
25
|
message: 'Authorization should be an Api-Key',
|
|
@@ -34,10 +33,8 @@ let ApiKeyConnectionGuardMiddleware = class ApiKeyConnectionGuardMiddleware {
|
|
|
34
33
|
throw new CustomError({ httpCode: 401, message: 'Token not available' });
|
|
35
34
|
}
|
|
36
35
|
try {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
apiKey.validatePassword(keyData.pass);
|
|
40
|
-
this.auth.assign(apiKey.authInfo);
|
|
36
|
+
const authInfo = await this.apiKeyRepository.findAuthInfo(keySecret);
|
|
37
|
+
this.auth.assign(authInfo);
|
|
41
38
|
}
|
|
42
39
|
catch (err) {
|
|
43
40
|
throw new CustomError({
|
|
@@ -19,8 +19,8 @@ let JwtConnectionGuardMiddleware = class JwtConnectionGuardMiddleware {
|
|
|
19
19
|
authorization = authorization[0];
|
|
20
20
|
}
|
|
21
21
|
if (authorization) {
|
|
22
|
-
const [
|
|
23
|
-
if (
|
|
22
|
+
const [prefix, token] = authorization.split(' ');
|
|
23
|
+
if (prefix.toLowerCase() !== 'bearer' || !token) {
|
|
24
24
|
throw new CustomError({
|
|
25
25
|
httpCode: 401,
|
|
26
26
|
message: 'Authorization should be a bearer token',
|
|
@@ -19,7 +19,7 @@ let WabotChatAdapter = class WabotChatAdapter {
|
|
|
19
19
|
const response = await fetch(this.baseUrl + '/chat-bot/next-item', {
|
|
20
20
|
method: 'post',
|
|
21
21
|
headers: {
|
|
22
|
-
Authorization: `
|
|
22
|
+
Authorization: `Api-Key ${this.apiKey}`,
|
|
23
23
|
'Content-Type': 'application/json',
|
|
24
24
|
},
|
|
25
25
|
body: JSON.stringify(req),
|
|
@@ -111,12 +111,24 @@ let MindsetOperator = class MindsetOperator {
|
|
|
111
111
|
if (!response) {
|
|
112
112
|
return 'success';
|
|
113
113
|
}
|
|
114
|
-
return
|
|
114
|
+
return this.functionResponseToString(response);
|
|
115
115
|
}
|
|
116
116
|
catch (error) {
|
|
117
117
|
return `Error: ${error}`;
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
+
functionResponseToString(response) {
|
|
121
|
+
const type = typeof response;
|
|
122
|
+
if (type === 'string') {
|
|
123
|
+
return response;
|
|
124
|
+
}
|
|
125
|
+
else if (type === 'boolean' || type === 'number') {
|
|
126
|
+
return `${response}`;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return JSON.stringify(response);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
120
132
|
};
|
|
121
133
|
MindsetOperator = __decorate([
|
|
122
134
|
injectable(),
|
package/dist/src/index.d.ts
CHANGED
|
@@ -566,6 +566,7 @@ declare class MindsetOperator implements IMindset {
|
|
|
566
566
|
protected tool(fn: IMindsetFunctionMetadata, module: IMindsetModuleMetadata): IMindsetTool;
|
|
567
567
|
protected toolParameter(param: IMindsetFunctionParamMetadata): IMindsetToolParameter;
|
|
568
568
|
callFunction(name: string, params: string): Promise<string>;
|
|
569
|
+
functionResponseToString(response: any): string;
|
|
569
570
|
}
|
|
570
571
|
|
|
571
572
|
interface IChatMessage extends IStorableData {
|