@botfabrik/engine-webclient 4.35.1 → 4.36.1
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/__mocks__/uuid.js +4 -0
- package/dist/buildUserAgentInfos.d.ts +1 -1
- package/dist/buildUserAgentInfos.js +0 -1
- package/dist/client/asset-manifest.json +6 -13
- package/dist/client/index.html +1 -1
- package/dist/client/static/css/main.72c07115.css +2 -0
- package/dist/client/static/css/main.72c07115.css.map +1 -0
- package/dist/client/static/js/main.f7929ce3.js +3 -0
- package/dist/client/static/js/{2.24f5187f.chunk.js.LICENSE.txt → main.f7929ce3.js.LICENSE.txt} +19 -29
- package/dist/client/static/js/main.f7929ce3.js.map +1 -0
- package/dist/createSessionInfo.d.ts +4 -4
- package/dist/createSessionInfo.js +6 -4
- package/dist/createSessionInfo.test.js +28 -25
- package/dist/extractIP.js +0 -1
- package/dist/extractIP.test.js +18 -15
- package/dist/extractLocale.js +1 -2
- package/dist/extractLocale.test.js +16 -13
- package/dist/getSupportedClientLocale.js +0 -1
- package/dist/getSupportedClientLocale.test.js +18 -15
- package/dist/index.d.ts +6 -5
- package/dist/index.js +47 -32
- package/dist/loadPreviousConversation.d.ts +1 -1
- package/dist/loadPreviousConversation.js +0 -1
- package/dist/middleware/index.d.ts +3 -3
- package/dist/middleware/index.js +1 -3
- package/dist/requestSessionData.d.ts +2 -2
- package/dist/requestSessionData.js +0 -1
- package/dist/requestSessionData.test.js +40 -37
- package/dist/speechToText.js +3 -3
- package/dist/types.js +0 -1
- package/dist/views/index.js +0 -1
- package/package.json +20 -20
- package/dist/buildUserAgentInfos.js.map +0 -1
- package/dist/client/static/css/main.a8d88ddf.chunk.css +0 -2
- package/dist/client/static/css/main.a8d88ddf.chunk.css.map +0 -1
- package/dist/client/static/js/2.24f5187f.chunk.js +0 -3
- package/dist/client/static/js/2.24f5187f.chunk.js.map +0 -1
- package/dist/client/static/js/main.cad44cf0.chunk.js +0 -2
- package/dist/client/static/js/main.cad44cf0.chunk.js.map +0 -1
- package/dist/client/static/js/runtime-main.370aeabc.js +0 -2
- package/dist/client/static/js/runtime-main.370aeabc.js.map +0 -1
- package/dist/createSessionInfo.js.map +0 -1
- package/dist/createSessionInfo.test.js.map +0 -1
- package/dist/extractIP.js.map +0 -1
- package/dist/extractIP.test.js.map +0 -1
- package/dist/extractLocale.js.map +0 -1
- package/dist/extractLocale.test.js.map +0 -1
- package/dist/getSupportedClientLocale.js.map +0 -1
- package/dist/getSupportedClientLocale.test.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.test.js +0 -16
- package/dist/index.test.js.map +0 -1
- package/dist/loadPreviousConversation.js.map +0 -1
- package/dist/middleware/index.js.map +0 -1
- package/dist/requestSessionData.js.map +0 -1
- package/dist/requestSessionData.test.js.map +0 -1
- package/dist/speechToText.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/views/index.js.map +0 -1
- /package/dist/{index.test.d.ts → __mocks__/uuid.d.ts} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SessionInfo, SessionInfoClient, SessionInfoUser } from '@botfabrik/engine-core';
|
|
2
|
-
import express from 'express';
|
|
3
|
-
import { Socket } from 'socket.io';
|
|
1
|
+
import type { SessionInfo, SessionInfoClient, SessionInfoUser } from '@botfabrik/engine-core';
|
|
2
|
+
import type express from 'express';
|
|
3
|
+
import type { Socket } from 'socket.io';
|
|
4
4
|
import { WebClientProps } from './index';
|
|
5
|
-
import { SessionInfoClientPayload, SessionInfoUserPayload } from './types';
|
|
5
|
+
import type { SessionInfoClientPayload, SessionInfoUserPayload } from './types';
|
|
6
6
|
export declare const createSessionInfoFromRequest: (req: express.Request, name: string, sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>, props: WebClientProps) => Promise<{
|
|
7
7
|
client: SessionInfoClient<SessionInfoClientPayload>;
|
|
8
8
|
user: SessionInfoUser<SessionInfoUserPayload>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.createSessionInfoFromRequest = void 0;
|
|
4
|
-
const buildUserAgentInfos_1 = require("./buildUserAgentInfos");
|
|
5
|
-
const extractIP_1 = require("./extractIP");
|
|
6
|
-
const extractLocale_1 = require("./extractLocale");
|
|
7
|
+
const buildUserAgentInfos_1 = __importDefault(require("./buildUserAgentInfos"));
|
|
8
|
+
const extractIP_1 = __importDefault(require("./extractIP"));
|
|
9
|
+
const extractLocale_1 = __importDefault(require("./extractLocale"));
|
|
7
10
|
const index_1 = require("./index");
|
|
8
11
|
const createSessionInfoFromRequest = async (req, name, sessionInfo, props) => {
|
|
9
12
|
const ip = (0, extractIP_1.default)(req);
|
|
@@ -47,4 +50,3 @@ const createSessionInfo = (socket, name, sessionInfo, props) => async () => {
|
|
|
47
50
|
return await createSessionInfoBase(querystrings, request.headers, ip, name, sessionInfo, props);
|
|
48
51
|
};
|
|
49
52
|
exports.default = createSessionInfo;
|
|
50
|
-
//# sourceMappingURL=createSessionInfo.js.map
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
6
|
+
const globals_1 = require("@jest/globals");
|
|
7
|
+
const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
8
|
+
(0, globals_1.describe)('create session info', () => {
|
|
5
9
|
const querystrings = {
|
|
6
10
|
sessionId: 'session-id',
|
|
7
11
|
userId: 'user-id',
|
|
@@ -47,21 +51,21 @@ describe('create session info', () => {
|
|
|
47
51
|
user: { id: 'my-user-id', displayName: 'my user', payload: {} },
|
|
48
52
|
contexts: [],
|
|
49
53
|
};
|
|
50
|
-
it('without user payload', async () => {
|
|
54
|
+
(0, globals_1.it)('without user payload', async () => {
|
|
51
55
|
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', defaultSessionInfo, {})();
|
|
52
56
|
// client
|
|
53
|
-
expect(sessionInfo.client.name).toBe('my-client');
|
|
54
|
-
expect(sessionInfo.client.type).toBe('webclient');
|
|
55
|
-
expect(sessionInfo.client.payload.headers).toEqual({ ...headers, cookie: undefined }); // cookies sollen nicht gespeichert werden
|
|
56
|
-
expect(sessionInfo.client.payload.querystrings).toEqual(querystrings);
|
|
57
|
-
expect(sessionInfo.client.payload.ip).toBe('151.248.213.117');
|
|
57
|
+
(0, globals_1.expect)(sessionInfo.client.name).toBe('my-client');
|
|
58
|
+
(0, globals_1.expect)(sessionInfo.client.type).toBe('webclient');
|
|
59
|
+
(0, globals_1.expect)(sessionInfo.client.payload.headers).toEqual({ ...headers, cookie: undefined }); // cookies sollen nicht gespeichert werden
|
|
60
|
+
(0, globals_1.expect)(sessionInfo.client.payload.querystrings).toEqual(querystrings);
|
|
61
|
+
(0, globals_1.expect)(sessionInfo.client.payload.ip).toBe('151.248.213.117');
|
|
58
62
|
// user
|
|
59
|
-
expect(sessionInfo.user.id).toBe('user-id');
|
|
60
|
-
expect(sessionInfo.user.displayName).toBe('Webseiten Besucher');
|
|
61
|
-
expect(sessionInfo.user.locale).toBe('de_DE');
|
|
62
|
-
expect(sessionInfo.user.payload).toStrictEqual({});
|
|
63
|
+
(0, globals_1.expect)(sessionInfo.user.id).toBe('user-id');
|
|
64
|
+
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Webseiten Besucher');
|
|
65
|
+
(0, globals_1.expect)(sessionInfo.user.locale).toBe('de_DE');
|
|
66
|
+
(0, globals_1.expect)(sessionInfo.user.payload).toStrictEqual({});
|
|
63
67
|
});
|
|
64
|
-
it('with enhanced user data', async () => {
|
|
68
|
+
(0, globals_1.it)('with enhanced user data', async () => {
|
|
65
69
|
const requestUserInfos = async () => {
|
|
66
70
|
const userProfile = {
|
|
67
71
|
username: 'hans.muster',
|
|
@@ -79,24 +83,23 @@ describe('create session info', () => {
|
|
|
79
83
|
requestUserInfos,
|
|
80
84
|
};
|
|
81
85
|
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', defaultSessionInfo, props)();
|
|
82
|
-
expect(sessionInfo.user.id).toBe('hans.muster@PRIMARY');
|
|
83
|
-
expect(sessionInfo.user.displayName).toBe('Hans Muster');
|
|
84
|
-
expect(sessionInfo.user.payload.username).toBe('hans.muster');
|
|
85
|
-
expect(sessionInfo.user.payload.firstName).toBe('Hans');
|
|
86
|
-
expect(sessionInfo.user.payload.lastName).toBe('Muster');
|
|
86
|
+
(0, globals_1.expect)(sessionInfo.user.id).toBe('hans.muster@PRIMARY');
|
|
87
|
+
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Hans Muster');
|
|
88
|
+
(0, globals_1.expect)(sessionInfo.user.payload.username).toBe('hans.muster');
|
|
89
|
+
(0, globals_1.expect)(sessionInfo.user.payload.firstName).toBe('Hans');
|
|
90
|
+
(0, globals_1.expect)(sessionInfo.user.payload.lastName).toBe('Muster');
|
|
87
91
|
});
|
|
88
|
-
it('with undefined enhanced user data', async () => {
|
|
92
|
+
(0, globals_1.it)('with undefined enhanced user data', async () => {
|
|
89
93
|
const requestUserInfos = async () => {
|
|
90
|
-
return
|
|
94
|
+
return {};
|
|
91
95
|
};
|
|
92
96
|
const props = {
|
|
93
97
|
requestUserInfos,
|
|
94
98
|
};
|
|
95
99
|
const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', defaultSessionInfo, props)();
|
|
96
|
-
expect(sessionInfo.user.id).toBe('user-id');
|
|
97
|
-
expect(sessionInfo.user.displayName).toBe('Webseiten Besucher');
|
|
98
|
-
expect(sessionInfo.user.locale).toBe('de_DE');
|
|
99
|
-
expect(sessionInfo.user.payload).toStrictEqual({});
|
|
100
|
+
(0, globals_1.expect)(sessionInfo.user.id).toBe('user-id');
|
|
101
|
+
(0, globals_1.expect)(sessionInfo.user.displayName).toBe('Webseiten Besucher');
|
|
102
|
+
(0, globals_1.expect)(sessionInfo.user.locale).toBe('de_DE');
|
|
103
|
+
(0, globals_1.expect)(sessionInfo.user.payload).toStrictEqual({});
|
|
100
104
|
});
|
|
101
105
|
});
|
|
102
|
-
//# sourceMappingURL=createSessionInfo.test.js.map
|
package/dist/extractIP.js
CHANGED
package/dist/extractIP.test.js
CHANGED
|
@@ -1,38 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
const globals_1 = require("@jest/globals");
|
|
7
|
+
const extractIP_1 = __importDefault(require("./extractIP"));
|
|
8
|
+
(0, globals_1.describe)('extract IP address from websocket request', () => {
|
|
9
|
+
(0, globals_1.it)('takes IP from x-forwarded-for header', () => {
|
|
6
10
|
const request = {
|
|
7
11
|
headers: { 'x-forwarded-for': '192.168.1.1, 192.168.1.1' },
|
|
8
12
|
connection: { remoteAddress: '192.168.1.2', socket: { remoteAddress: '192.168.1.4' } },
|
|
9
|
-
socket: { remoteAddress: '192.168.1.3' }
|
|
13
|
+
socket: { remoteAddress: '192.168.1.3' },
|
|
10
14
|
};
|
|
11
|
-
expect((0, extractIP_1.default)(request)).toBe('192.168.1.1');
|
|
15
|
+
(0, globals_1.expect)((0, extractIP_1.default)(request)).toBe('192.168.1.1');
|
|
12
16
|
});
|
|
13
|
-
it('takes IP from connection remote address', () => {
|
|
17
|
+
(0, globals_1.it)('takes IP from connection remote address', () => {
|
|
14
18
|
const request = {
|
|
15
19
|
headers: {},
|
|
16
20
|
connection: { remoteAddress: '192.168.1.2' },
|
|
17
|
-
socket: { remoteAddress: '192.168.1.3' }
|
|
21
|
+
socket: { remoteAddress: '192.168.1.3' },
|
|
18
22
|
};
|
|
19
|
-
expect((0, extractIP_1.default)(request)).toBe('192.168.1.2');
|
|
23
|
+
(0, globals_1.expect)((0, extractIP_1.default)(request)).toBe('192.168.1.2');
|
|
20
24
|
});
|
|
21
|
-
it('takes IP from socket remote address', () => {
|
|
25
|
+
(0, globals_1.it)('takes IP from socket remote address', () => {
|
|
22
26
|
const request = {
|
|
23
27
|
headers: {},
|
|
24
28
|
connection: {},
|
|
25
|
-
socket: { remoteAddress: '192.168.1.3' }
|
|
29
|
+
socket: { remoteAddress: '192.168.1.3' },
|
|
26
30
|
};
|
|
27
|
-
expect((0, extractIP_1.default)(request)).toBe('192.168.1.3');
|
|
31
|
+
(0, globals_1.expect)((0, extractIP_1.default)(request)).toBe('192.168.1.3');
|
|
28
32
|
});
|
|
29
|
-
it('takes IP from connection ocket remote address', () => {
|
|
33
|
+
(0, globals_1.it)('takes IP from connection ocket remote address', () => {
|
|
30
34
|
const request = {
|
|
31
35
|
headers: {},
|
|
32
36
|
connection: { socket: { remoteAddress: '192.168.1.4' } },
|
|
33
|
-
socket: {}
|
|
37
|
+
socket: {},
|
|
34
38
|
};
|
|
35
|
-
expect((0, extractIP_1.default)(request)).toBe('192.168.1.4');
|
|
39
|
+
(0, globals_1.expect)((0, extractIP_1.default)(request)).toBe('192.168.1.4');
|
|
36
40
|
});
|
|
37
41
|
});
|
|
38
|
-
//# sourceMappingURL=extractIP.test.js.map
|
package/dist/extractLocale.js
CHANGED
|
@@ -8,7 +8,7 @@ const extractLocale = (querystrings, acceptLanguage = '') => {
|
|
|
8
8
|
}
|
|
9
9
|
else {
|
|
10
10
|
const languages = (0, accept_language_parser_1.parse)(acceptLanguage);
|
|
11
|
-
if (languages !== undefined && languages
|
|
11
|
+
if (languages !== undefined && languages[0]) {
|
|
12
12
|
const code = languages[0].code;
|
|
13
13
|
const region = languages[0].region;
|
|
14
14
|
locale = code + (region ? '_' + region : '');
|
|
@@ -17,4 +17,3 @@ const extractLocale = (querystrings, acceptLanguage = '') => {
|
|
|
17
17
|
return locale;
|
|
18
18
|
};
|
|
19
19
|
exports.default = extractLocale;
|
|
20
|
-
//# sourceMappingURL=extractLocale.js.map
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
const globals_1 = require("@jest/globals");
|
|
7
|
+
const extractLocale_1 = __importDefault(require("./extractLocale"));
|
|
8
|
+
(0, globals_1.describe)('should extract locale from accept-language header', () => {
|
|
9
|
+
(0, globals_1.it)('undefined header value', () => {
|
|
10
|
+
(0, globals_1.expect)((0, extractLocale_1.default)({}, undefined)).toBe(undefined);
|
|
7
11
|
});
|
|
8
|
-
it('lang via query parameer', () => {
|
|
9
|
-
expect((0, extractLocale_1.default)({ lang: 'de' }, '')).toBe('de');
|
|
12
|
+
(0, globals_1.it)('lang via query parameer', () => {
|
|
13
|
+
(0, globals_1.expect)((0, extractLocale_1.default)({ lang: 'de' }, '')).toBe('de');
|
|
10
14
|
});
|
|
11
|
-
it('empty header value', () => {
|
|
12
|
-
expect((0, extractLocale_1.default)({}, '')).toBe(undefined);
|
|
15
|
+
(0, globals_1.it)('empty header value', () => {
|
|
16
|
+
(0, globals_1.expect)((0, extractLocale_1.default)({}, '')).toBe(undefined);
|
|
13
17
|
});
|
|
14
|
-
it('header value with one value', () => {
|
|
15
|
-
expect((0, extractLocale_1.default)({}, 'de-CH')).toBe('de_CH');
|
|
18
|
+
(0, globals_1.it)('header value with one value', () => {
|
|
19
|
+
(0, globals_1.expect)((0, extractLocale_1.default)({}, 'de-CH')).toBe('de_CH');
|
|
16
20
|
});
|
|
17
|
-
it('header value with several values', () => {
|
|
21
|
+
(0, globals_1.it)('header value with several values', () => {
|
|
18
22
|
const header = 'de-CH,de;q=0.8,en-US;q=0.6,en;q=0.4';
|
|
19
|
-
expect((0, extractLocale_1.default)({}, header)).toBe('de_CH');
|
|
23
|
+
(0, globals_1.expect)((0, extractLocale_1.default)({}, header)).toBe('de_CH');
|
|
20
24
|
});
|
|
21
25
|
});
|
|
22
|
-
//# sourceMappingURL=extractLocale.test.js.map
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
expect((0, getSupportedClientLocale_1.default)('de
|
|
8
|
-
expect((0, getSupportedClientLocale_1.default)('
|
|
9
|
-
expect((0, getSupportedClientLocale_1.default)('en
|
|
10
|
-
expect((0, getSupportedClientLocale_1.default)('
|
|
11
|
-
expect((0, getSupportedClientLocale_1.default)('fr
|
|
12
|
-
expect((0, getSupportedClientLocale_1.default)('
|
|
6
|
+
const globals_1 = require("@jest/globals");
|
|
7
|
+
const getSupportedClientLocale_1 = __importDefault(require("./getSupportedClientLocale"));
|
|
8
|
+
(0, globals_1.describe)('get client locale', () => {
|
|
9
|
+
(0, globals_1.it)('should return supported client language', () => {
|
|
10
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('de')).toBe('de');
|
|
11
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('de-ch')).toBe('de');
|
|
12
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('en')).toBe('en');
|
|
13
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('en-us')).toBe('en');
|
|
14
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('fr')).toBe('fr');
|
|
15
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('fr-ch')).toBe('fr');
|
|
16
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('it')).toBe('it');
|
|
13
17
|
});
|
|
14
|
-
it('should return "de" as default locale', () => {
|
|
15
|
-
expect((0, getSupportedClientLocale_1.default)('ru')).toBe('de');
|
|
16
|
-
expect((0, getSupportedClientLocale_1.default)('ru-de')).toBe('de');
|
|
17
|
-
expect((0, getSupportedClientLocale_1.default)('sp')).toBe('de');
|
|
18
|
+
(0, globals_1.it)('should return "de" as default locale', () => {
|
|
19
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('ru')).toBe('de');
|
|
20
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('ru-de')).toBe('de');
|
|
21
|
+
(0, globals_1.expect)((0, getSupportedClientLocale_1.default)('sp')).toBe('de');
|
|
18
22
|
});
|
|
19
23
|
});
|
|
20
|
-
//# sourceMappingURL=getSupportedClientLocale.test.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { Client, SessionInfoUser } from '@botfabrik/engine-core';
|
|
1
|
+
import type { Client, SessionInfoUser } from '@botfabrik/engine-core';
|
|
2
2
|
import { Action } from '@botfabrik/engine-domain';
|
|
3
3
|
import { SpeechToTextProps } from './speechToText';
|
|
4
|
-
import { SessionInfoUserPayload, WebclientMiddlewareState } from './types';
|
|
4
|
+
import type { SessionInfoUserPayload, WebclientMiddlewareState } from './types';
|
|
5
|
+
export declare type RequestUserInfos = (querystrings: any) => Promise<Partial<SessionInfoUser<SessionInfoUserPayload>>>;
|
|
6
|
+
export declare type RequestSessionRecordQuery = (querystrings: any) => Promise<Record<string, unknown>>;
|
|
5
7
|
export interface WebClientProps {
|
|
6
8
|
getStartedAction?: Action;
|
|
7
|
-
requestUserInfos?:
|
|
8
|
-
requestSessionRecordQuery?:
|
|
9
|
+
requestUserInfos?: RequestUserInfos;
|
|
10
|
+
requestSessionRecordQuery?: RequestSessionRecordQuery;
|
|
9
11
|
speech?: SpeechToTextProps | undefined;
|
|
10
12
|
expandChatWindowAtStart?: Devices;
|
|
11
13
|
emailExportEnabled?: boolean;
|
|
@@ -23,5 +25,4 @@ export declare enum Devices {
|
|
|
23
25
|
}
|
|
24
26
|
declare const _default: (name: string, props: WebClientProps) => Client<WebclientMiddlewareState>;
|
|
25
27
|
export default _default;
|
|
26
|
-
export declare const splitBlob: (actionObject: any) => any;
|
|
27
28
|
export declare const CLIENT_TYPE = "webclient";
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CLIENT_TYPE = exports.
|
|
29
|
+
exports.CLIENT_TYPE = exports.Devices = void 0;
|
|
4
30
|
const engine_domain_1 = require("@botfabrik/engine-domain");
|
|
5
31
|
const engine_transcript_export_1 = require("@botfabrik/engine-transcript-export");
|
|
6
|
-
const express = require("express");
|
|
7
|
-
const createSessionInfo_1 = require("./createSessionInfo");
|
|
8
|
-
const getSupportedClientLocale_1 = require("./getSupportedClientLocale");
|
|
9
|
-
const loadPreviousConversation_1 = require("./loadPreviousConversation");
|
|
10
|
-
const middleware_1 = require("./middleware");
|
|
11
|
-
const requestSessionData_1 = require("./requestSessionData");
|
|
12
|
-
const speechToText_1 = require("./speechToText");
|
|
13
|
-
const views_1 = require("./views");
|
|
32
|
+
const express = __importStar(require("express"));
|
|
33
|
+
const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
|
|
34
|
+
const getSupportedClientLocale_1 = __importDefault(require("./getSupportedClientLocale"));
|
|
35
|
+
const loadPreviousConversation_1 = __importDefault(require("./loadPreviousConversation"));
|
|
36
|
+
const middleware_1 = __importDefault(require("./middleware"));
|
|
37
|
+
const requestSessionData_1 = __importDefault(require("./requestSessionData"));
|
|
38
|
+
const speechToText_1 = __importDefault(require("./speechToText"));
|
|
39
|
+
const views_1 = __importDefault(require("./views"));
|
|
14
40
|
const version = require('../package.json').version;
|
|
15
41
|
var Devices;
|
|
16
42
|
(function (Devices) {
|
|
@@ -27,12 +53,17 @@ exports.default = (name, props) => async (bot) => {
|
|
|
27
53
|
});
|
|
28
54
|
// serve transcript pdf
|
|
29
55
|
bot.webserver.express.use('/transcript-pdf/:sessionId', async (req, res) => {
|
|
30
|
-
const sessionId = req.params
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
56
|
+
const sessionId = req.params['sessionId'];
|
|
57
|
+
if (sessionId?.length) {
|
|
58
|
+
const session = await bot.createSession(sessionId);
|
|
59
|
+
const pdf = await (0, engine_transcript_export_1.getPdf)(session);
|
|
60
|
+
res.set('Content-Type', 'application/pdf');
|
|
61
|
+
res.set('Content-Disposition', 'attachment; filename="Transcript.pdf"');
|
|
62
|
+
res.end(pdf);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
res.sendStatus(404).send('Invalid request');
|
|
66
|
+
}
|
|
36
67
|
});
|
|
37
68
|
// serve embed resources
|
|
38
69
|
bot.webserver.express.get(`/${name}/embed`, (req, res) => {
|
|
@@ -43,7 +74,7 @@ exports.default = (name, props) => async (bot) => {
|
|
|
43
74
|
});
|
|
44
75
|
if (!isFabVisible(props)) {
|
|
45
76
|
bot.webserver.express.get(`/${name}/embed/bundle.js`, (req, res) => {
|
|
46
|
-
const caller = req.query
|
|
77
|
+
const caller = req.query['caller'];
|
|
47
78
|
if (caller === 'bookmarklet') {
|
|
48
79
|
res.sendFile(`${__dirname}/embed/bundle.js`);
|
|
49
80
|
}
|
|
@@ -111,10 +142,6 @@ exports.default = (name, props) => async (bot) => {
|
|
|
111
142
|
socket.on('action', async (action) => {
|
|
112
143
|
await session.dispatch(JSON.parse(action));
|
|
113
144
|
});
|
|
114
|
-
socket.on('file-from-guest', async (action) => {
|
|
115
|
-
const actionObject = JSON.parse(action);
|
|
116
|
-
await session.dispatch((0, exports.splitBlob)(actionObject));
|
|
117
|
-
});
|
|
118
145
|
socket.on('disconnect', async () => {
|
|
119
146
|
await session.dispatch((0, engine_domain_1.guestDisconnected)(sessionId));
|
|
120
147
|
});
|
|
@@ -150,17 +177,6 @@ exports.default = (name, props) => async (bot) => {
|
|
|
150
177
|
};
|
|
151
178
|
return client;
|
|
152
179
|
};
|
|
153
|
-
const splitBlob = (actionObject) => {
|
|
154
|
-
const regex = /data:(.*);base64,(.*)/i;
|
|
155
|
-
const matches = regex.exec(actionObject.file.blob);
|
|
156
|
-
if (matches !== null && matches.length === 3) {
|
|
157
|
-
actionObject.file.filetype = matches[1];
|
|
158
|
-
actionObject.file.base64 = matches[2];
|
|
159
|
-
delete actionObject.file.blob;
|
|
160
|
-
}
|
|
161
|
-
return actionObject;
|
|
162
|
-
};
|
|
163
|
-
exports.splitBlob = splitBlob;
|
|
164
180
|
// do not cache static files because default implementation uses incorrect last modified date (see https://github.com/npm/npm/issues/20439)
|
|
165
181
|
const serveStaticOptions = {
|
|
166
182
|
etag: false,
|
|
@@ -179,4 +195,3 @@ const serveStaticOptions = {
|
|
|
179
195
|
};
|
|
180
196
|
const isFabVisible = ({ fabVisible = true }) => fabVisible;
|
|
181
197
|
exports.CLIENT_TYPE = 'webclient';
|
|
182
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Middleware } from '@botfabrik/engine-core';
|
|
2
|
-
import { Namespace } from 'socket.io';
|
|
3
|
-
import { WebclientMiddlewareState } from '../types';
|
|
1
|
+
import type { Middleware } from '@botfabrik/engine-core';
|
|
2
|
+
import type { Namespace } from 'socket.io';
|
|
3
|
+
import type { WebclientMiddlewareState } from '../types';
|
|
4
4
|
declare const _default: (clientName: string, nsp: Namespace) => Middleware<WebclientMiddlewareState>;
|
|
5
5
|
export default _default;
|
package/dist/middleware/index.js
CHANGED
|
@@ -16,8 +16,7 @@ exports.default = (clientName, nsp) => async () => {
|
|
|
16
16
|
nsp.to(session.id).emit('action', action);
|
|
17
17
|
};
|
|
18
18
|
const expandChatWindow = (action) => {
|
|
19
|
-
|
|
20
|
-
const devices = (_a = action.payload) === null || _a === void 0 ? void 0 : _a.devices;
|
|
19
|
+
const devices = action.payload?.devices;
|
|
21
20
|
if (!!devices && devices !== __1.Devices.None) {
|
|
22
21
|
nsp.to(session.id).emit('expand-window', { devices: action.payload.devices });
|
|
23
22
|
}
|
|
@@ -42,4 +41,3 @@ exports.default = (clientName, nsp) => async () => {
|
|
|
42
41
|
next(action);
|
|
43
42
|
};
|
|
44
43
|
};
|
|
45
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SessionInfo } from '@botfabrik/engine-core';
|
|
1
|
+
import type { SessionInfo } from '@botfabrik/engine-core';
|
|
2
2
|
import { WebClientProps } from './index';
|
|
3
|
-
import { SessionInfoClientPayload, SessionInfoUserPayload } from './types';
|
|
3
|
+
import type { SessionInfoClientPayload, SessionInfoUserPayload } from './types';
|
|
4
4
|
interface SessionData {
|
|
5
5
|
sessionId: string;
|
|
6
6
|
sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>;
|
|
@@ -1,83 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
const globals_1 = require("@jest/globals");
|
|
7
|
+
const requestSessionData_1 = __importDefault(require("./requestSessionData"));
|
|
8
|
+
(0, globals_1.describe)('request session id', () => {
|
|
9
|
+
(0, globals_1.beforeEach)(() => {
|
|
10
|
+
globals_1.jest.clearAllMocks();
|
|
7
11
|
});
|
|
8
12
|
const querystrings = {
|
|
9
13
|
sessionId: 'session-id',
|
|
10
14
|
accessToken: 'access-token',
|
|
11
15
|
};
|
|
12
|
-
it('when sessionId has been passed by query param but does not exists in db', async () => {
|
|
13
|
-
const findOne = jest.fn();
|
|
16
|
+
(0, globals_1.it)('when sessionId has been passed by query param but does not exists in db', async () => {
|
|
17
|
+
const findOne = globals_1.jest.fn();
|
|
14
18
|
findOne.mockReturnValueOnce(undefined);
|
|
15
19
|
const sessionsCollection = {
|
|
16
20
|
findOne,
|
|
17
21
|
};
|
|
18
22
|
const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', {});
|
|
19
|
-
expect(findOne).toHaveBeenCalledTimes(1);
|
|
20
|
-
expect(findOne).toHaveBeenCalledWith({ _id: 'session-id', 'sessionInfo.client.name': 'test-bot', 'sessionInfo.client.type': 'webclient' }, { _id: 1, sessionInfo: 1 });
|
|
21
|
-
expect(sessionId).toBe('generated-uuid');
|
|
22
|
-
expect(isNew).toBe(true);
|
|
23
|
+
(0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
|
|
24
|
+
(0, globals_1.expect)(findOne).toHaveBeenCalledWith({ _id: 'session-id', 'sessionInfo.client.name': 'test-bot', 'sessionInfo.client.type': 'webclient' }, { _id: 1, sessionInfo: 1 });
|
|
25
|
+
(0, globals_1.expect)(sessionId).toBe('generated-uuid');
|
|
26
|
+
(0, globals_1.expect)(isNew).toBe(true);
|
|
23
27
|
});
|
|
24
|
-
it('when sessionId has been passed by query param and exists in db', async () => {
|
|
25
|
-
const findOne = jest.fn();
|
|
28
|
+
(0, globals_1.it)('when sessionId has been passed by query param and exists in db', async () => {
|
|
29
|
+
const findOne = globals_1.jest.fn();
|
|
26
30
|
findOne.mockReturnValueOnce({ _id: 'session-id' });
|
|
27
31
|
const sessionsCollection = {
|
|
28
32
|
findOne,
|
|
29
33
|
};
|
|
30
34
|
const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', {});
|
|
31
|
-
expect(findOne).toHaveBeenCalledTimes(1);
|
|
32
|
-
expect(findOne).toHaveBeenCalledWith({ _id: 'session-id', 'sessionInfo.client.name': 'test-bot', 'sessionInfo.client.type': 'webclient' }, { _id: 1, sessionInfo: 1 });
|
|
33
|
-
expect(sessionId).toBe('session-id');
|
|
34
|
-
expect(isNew).toBe(false);
|
|
35
|
+
(0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
|
|
36
|
+
(0, globals_1.expect)(findOne).toHaveBeenCalledWith({ _id: 'session-id', 'sessionInfo.client.name': 'test-bot', 'sessionInfo.client.type': 'webclient' }, { _id: 1, sessionInfo: 1 });
|
|
37
|
+
(0, globals_1.expect)(sessionId).toBe('session-id');
|
|
38
|
+
(0, globals_1.expect)(isNew).toBe(false);
|
|
35
39
|
});
|
|
36
|
-
it('when requestSessionRecordQuery has been passed as webclient property but no such session exists in db', async () => {
|
|
37
|
-
const findOne = jest.fn();
|
|
40
|
+
(0, globals_1.it)('when requestSessionRecordQuery has been passed as webclient property but no such session exists in db', async () => {
|
|
41
|
+
const findOne = globals_1.jest.fn();
|
|
38
42
|
findOne.mockReturnValueOnce(undefined);
|
|
39
43
|
const sessionsCollection = {
|
|
40
44
|
findOne,
|
|
41
45
|
};
|
|
42
|
-
const requestSessionRecordQuery = jest.fn();
|
|
46
|
+
const requestSessionRecordQuery = globals_1.jest.fn();
|
|
43
47
|
const props = {
|
|
44
48
|
requestSessionRecordQuery,
|
|
45
49
|
};
|
|
46
|
-
requestSessionRecordQuery.mockReturnValueOnce({ 'sessionInfo.user.id': 'hans@apptiva.ch' });
|
|
50
|
+
requestSessionRecordQuery.mockReturnValueOnce(Promise.resolve({ 'sessionInfo.user.id': 'hans@apptiva.ch' }));
|
|
47
51
|
const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', props);
|
|
48
|
-
expect(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
|
|
49
|
-
expect(requestSessionRecordQuery).toHaveBeenCalledWith(querystrings);
|
|
50
|
-
expect(findOne).toHaveBeenCalledTimes(1);
|
|
51
|
-
expect(findOne).toHaveBeenCalledWith({
|
|
52
|
+
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
|
|
53
|
+
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledWith(querystrings);
|
|
54
|
+
(0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
|
|
55
|
+
(0, globals_1.expect)(findOne).toHaveBeenCalledWith({
|
|
52
56
|
'sessionInfo.client.name': 'test-bot',
|
|
53
57
|
'sessionInfo.client.type': 'webclient',
|
|
54
58
|
'sessionInfo.user.id': 'hans@apptiva.ch',
|
|
55
59
|
}, { _id: 1, sessionInfo: 1 });
|
|
56
|
-
expect(sessionId).toBe('generated-uuid');
|
|
57
|
-
expect(isNew).toBe(true);
|
|
60
|
+
(0, globals_1.expect)(sessionId).toBe('generated-uuid');
|
|
61
|
+
(0, globals_1.expect)(isNew).toBe(true);
|
|
58
62
|
});
|
|
59
|
-
it('when requestSessionRecordQuery has been passed as webclient property and session exists in db', async () => {
|
|
60
|
-
const findOne = jest.fn();
|
|
63
|
+
(0, globals_1.it)('when requestSessionRecordQuery has been passed as webclient property and session exists in db', async () => {
|
|
64
|
+
const findOne = globals_1.jest.fn();
|
|
61
65
|
findOne.mockReturnValueOnce({ _id: 'session-id' });
|
|
62
66
|
const sessionsCollection = {
|
|
63
67
|
findOne,
|
|
64
68
|
};
|
|
65
|
-
const requestSessionRecordQuery = jest.fn();
|
|
69
|
+
const requestSessionRecordQuery = globals_1.jest.fn();
|
|
66
70
|
const props = {
|
|
67
71
|
requestSessionRecordQuery,
|
|
68
72
|
};
|
|
69
|
-
requestSessionRecordQuery.mockReturnValueOnce({ 'sessionInfo.user.id': 'hans@apptiva.ch' });
|
|
73
|
+
requestSessionRecordQuery.mockReturnValueOnce(Promise.resolve({ 'sessionInfo.user.id': 'hans@apptiva.ch' }));
|
|
70
74
|
const { sessionId, isNew } = await (0, requestSessionData_1.default)(querystrings, sessionsCollection, 'test-bot', props);
|
|
71
|
-
expect(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
|
|
72
|
-
expect(requestSessionRecordQuery).toHaveBeenCalledWith(querystrings);
|
|
73
|
-
expect(findOne).toHaveBeenCalledTimes(1);
|
|
74
|
-
expect(findOne).toHaveBeenCalledWith({
|
|
75
|
+
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
|
|
76
|
+
(0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledWith(querystrings);
|
|
77
|
+
(0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
|
|
78
|
+
(0, globals_1.expect)(findOne).toHaveBeenCalledWith({
|
|
75
79
|
'sessionInfo.client.name': 'test-bot',
|
|
76
80
|
'sessionInfo.client.type': 'webclient',
|
|
77
81
|
'sessionInfo.user.id': 'hans@apptiva.ch',
|
|
78
82
|
}, { _id: 1, sessionInfo: 1 });
|
|
79
|
-
expect(sessionId).toBe('session-id');
|
|
80
|
-
expect(isNew).toBe(false);
|
|
83
|
+
(0, globals_1.expect)(sessionId).toBe('session-id');
|
|
84
|
+
(0, globals_1.expect)(isNew).toBe(false);
|
|
81
85
|
});
|
|
82
86
|
});
|
|
83
|
-
//# sourceMappingURL=requestSessionData.test.js.map
|
package/dist/speechToText.js
CHANGED
|
@@ -35,13 +35,13 @@ const speechToText = (speechProps, locale, speechBytes) => {
|
|
|
35
35
|
client
|
|
36
36
|
.recognize(request)
|
|
37
37
|
.then((data) => {
|
|
38
|
-
var _a;
|
|
39
38
|
const response = data[0];
|
|
40
|
-
const transcription =
|
|
39
|
+
const transcription = response?.results
|
|
40
|
+
?.map((result) => (result?.alternatives && result.alternatives[0]?.transcript) || '')
|
|
41
|
+
.join('\n') || '';
|
|
41
42
|
resolve(transcription);
|
|
42
43
|
})
|
|
43
44
|
.catch(reject);
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
exports.default = speechToText;
|
|
47
|
-
//# sourceMappingURL=speechToText.js.map
|