@botfabrik/engine-webclient 4.68.0 → 4.69.0

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.
@@ -7,8 +7,8 @@
7
7
  <meta name="theme-color" content="#000000" />
8
8
  <meta name="google" content="notranslate" />
9
9
  <title>Bubble Chat Client</title>
10
- <script type="module" crossorigin src="./assets/index-Cg7Yy2hZ.js"></script>
11
- <link rel="stylesheet" crossorigin href="./assets/index-DfppAcaS.css">
10
+ <script type="module" crossorigin src="./assets/index-DMj7jWAL.js"></script>
11
+ <link rel="stylesheet" crossorigin href="./assets/index-C1QXALqF.css">
12
12
  </head>
13
13
 
14
14
  <body>
@@ -1,7 +1,8 @@
1
1
  import type { SessionInfo } from '@botfabrik/engine-core';
2
2
  import type { Environment } from '@botfabrik/engine-domain';
3
+ import { ParsedUrlQuery } from 'node:querystring';
3
4
  import type { Socket } from 'socket.io';
4
5
  import { WebClientProps } from './index';
5
6
  import type { SessionInfoClientPayload, SessionInfoUserPayload } from './types';
6
- declare const createSessionInfo: (socket: Socket, clientName: string, environment: Environment, sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>, userId: string, locale: string | undefined, props: WebClientProps) => () => Promise<SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>>;
7
+ declare const createSessionInfo: (socket: Socket, clientName: string, environment: Environment, sessionInfo: SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>, userId: string, locale: string | undefined, querystrings: ParsedUrlQuery, props: WebClientProps) => () => Promise<SessionInfo<SessionInfoClientPayload, SessionInfoUserPayload>>;
7
8
  export default createSessionInfo;
@@ -14,16 +14,16 @@ const createSessionInfoBase = async (userId, querystrings, headers, ip, clientNa
14
14
  type: index_1.CLIENT_TYPE,
15
15
  payload: {
16
16
  ...sessionInfo.client.payload,
17
- referrer: decodeURIComponent(querystrings['referrer'] || 'unknown'),
17
+ referrer: decodeURIComponent(querystrings['referrer'] || headers['referer'] || 'unknown'),
18
18
  headers: { ...headers, cookie: undefined },
19
19
  querystrings,
20
20
  ip,
21
21
  userAgent,
22
22
  },
23
23
  };
24
- const firstName = querystrings.userFirstName;
25
- const lastName = querystrings.userLastName;
26
- const email = querystrings.userEmail;
24
+ const firstName = querystrings['userFirstName'];
25
+ const lastName = querystrings['userLastName'];
26
+ const email = querystrings['userEmail'];
27
27
  const displayName = firstName && lastName ? `${firstName} ${lastName}` : 'Webseiten Besucher';
28
28
  let user = {
29
29
  ...sessionInfo.user,
@@ -42,9 +42,8 @@ const createSessionInfoBase = async (userId, querystrings, headers, ip, clientNa
42
42
  }
43
43
  return { client, user, contexts, environment };
44
44
  };
45
- const createSessionInfo = (socket, clientName, environment, sessionInfo, userId, locale, props) => async () => {
45
+ const createSessionInfo = (socket, clientName, environment, sessionInfo, userId, locale, querystrings, props) => async () => {
46
46
  const request = socket.request;
47
- const querystrings = socket.handshake.query;
48
47
  const ip = (0, extractIP_1.default)(request);
49
48
  return await createSessionInfoBase(userId, querystrings, request.headers, ip, clientName, environment, sessionInfo, locale, props);
50
49
  };
@@ -55,7 +55,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
55
55
  environment: 'PROD',
56
56
  };
57
57
  (0, globals_1.it)('without user payload', async () => {
58
- const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', {})();
58
+ const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', { email: 'hans@example.com' }, {})();
59
59
  // client
60
60
  (0, globals_1.expect)(sessionInfo.client.name).toBe('my-client');
61
61
  (0, globals_1.expect)(sessionInfo.client.type).toBe('webclient');
@@ -63,7 +63,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
63
63
  ...headers,
64
64
  cookie: undefined,
65
65
  }); // cookies sollen nicht gespeichert werden
66
- (0, globals_1.expect)(sessionInfo.client.payload.querystrings).toEqual(querystrings);
66
+ (0, globals_1.expect)(sessionInfo.client.payload.querystrings.email).toBe('hans@example.com');
67
67
  (0, globals_1.expect)(sessionInfo.client.payload.ip).toBe('151.248.213.117');
68
68
  // user
69
69
  (0, globals_1.expect)(sessionInfo.user.id).toBe('my-user-id');
@@ -88,7 +88,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
88
88
  const props = {
89
89
  requestUserInfos,
90
90
  };
91
- const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', props)();
91
+ const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', {}, props)();
92
92
  (0, globals_1.expect)(sessionInfo.user.id).toBe('hans.muster@PRIMARY');
93
93
  (0, globals_1.expect)(sessionInfo.user.displayName).toBe('Hans Muster');
94
94
  (0, globals_1.expect)(sessionInfo.user.payload.username).toBe('hans.muster');
@@ -102,7 +102,7 @@ const createSessionInfo_1 = __importDefault(require("./createSessionInfo"));
102
102
  const props = {
103
103
  requestUserInfos,
104
104
  };
105
- const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', props)();
105
+ const sessionInfo = await (0, createSessionInfo_1.default)(socket, 'my-client', 'TEST', defaultSessionInfo, 'my-user-id', 'de_DE', {}, props)();
106
106
  (0, globals_1.expect)(sessionInfo.user.id).toBe('my-user-id');
107
107
  (0, globals_1.expect)(sessionInfo.user.displayName).toBe('Webseiten Besucher');
108
108
  (0, globals_1.expect)(sessionInfo.user.locale).toBe('de_DE');
package/dist/index.d.ts CHANGED
@@ -22,7 +22,7 @@ export interface WebClientProps {
22
22
  fabVisible?: boolean;
23
23
  /**
24
24
  * Displays a start screen before a new chat begins, useful for user opt-in (e.g., terms acceptance).
25
- * Contains a text (`start-screen.body` in Markdown) and a start button (`start-screen.start-chat`).
25
+ * Contains a text (`start-screen.intro` in Markdown), form fields, and a start button (`start-screen.start-chat`).
26
26
  * No user data is collected until the user clicks the start button.
27
27
  * @default false
28
28
  */
package/dist/index.js CHANGED
@@ -101,6 +101,7 @@ exports.default = (clientName, environment, props) => async (bot) => {
101
101
  try {
102
102
  sendConfigurationToClient(socket, props, bot, clientName);
103
103
  socket.on('start-chat', onStartChat(socket, props, bot, clientName, environment, logger));
104
+ socket.on('terminate-session', onTerminateSession(socket, bot));
104
105
  }
105
106
  catch (error) {
106
107
  logger.error('Error while connecting webclient with backend.');
@@ -132,19 +133,20 @@ const serveStaticOptions = {
132
133
  },
133
134
  };
134
135
  const isFabVisible = ({ fabVisible = true }) => fabVisible;
135
- const onStartChat = (socket, props, bot, clientName, environment, logger) => async ({ sessionId: sessionIdFromClient, sessionIdToTerminate, // passed if the user wants to restart the chat
136
- userId: defaultUserId, }) => {
137
- const locale = (0, extractLocale_1.default)(socket.handshake.query, socket.request.headers['accept-language']);
136
+ const onTerminateSession = (socket, bot) => async ({ sessionId, // passed if the user wants to restart the chat
137
+ }) => {
138
+ const session = await bot.createSession(sessionId);
139
+ socket.leave(sessionId);
140
+ await session.dispatch((0, engine_domain_1.guestDisconnected)(sessionId));
141
+ };
142
+ const onStartChat = (socket, props, bot, clientName, environment, logger) => async ({ sessionId: sessionIdFromClient, userId: defaultUserId, querystrings, }) => {
143
+ const locale = (0, extractLocale_1.default)(querystrings, socket.request.headers['accept-language']);
138
144
  const sessionsCollection = bot.store.db.collection('sessions');
139
- const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(sessionIdFromClient, socket.handshake.query, sessionsCollection, clientName, locale, props);
145
+ const { sessionId, sessionInfo: defaultSessionInfo, isNew, } = await (0, requestSessionData_1.default)(sessionIdFromClient, querystrings, sessionsCollection, clientName, locale, props);
140
146
  // create a channel for each session
141
147
  socket.join(sessionId);
142
- const sessionInfo = await (0, createSessionInfo_1.default)(socket, clientName, environment, defaultSessionInfo, defaultUserId, locale, props)();
148
+ const sessionInfo = await (0, createSessionInfo_1.default)(socket, clientName, environment, defaultSessionInfo, defaultUserId, locale, querystrings, props)();
143
149
  const session = await bot.createSession(sessionId, sessionInfo);
144
- if (sessionIdToTerminate) {
145
- socket.leave(sessionIdToTerminate);
146
- await session.dispatch((0, engine_domain_1.guestDisconnected)(sessionIdToTerminate));
147
- }
148
150
  // sending persisted state to client
149
151
  const previousConversations = await (0, loadPreviousConversation_1.default)(bot.store, sessionId);
150
152
  socket.emit('restore-client-state', {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botfabrik/engine-webclient",
3
- "version": "4.68.0",
3
+ "version": "4.69.0",
4
4
  "description": "Webclient for Botfabriks Bot Engine",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -40,5 +40,5 @@
40
40
  "tsx": "^4.16.3",
41
41
  "typescript": "5.1.6"
42
42
  },
43
- "gitHead": "e64f95bd095221855680a9d0c895b5622179afe3"
43
+ "gitHead": "9560b9553e1db53d1a6f812788a32b9169701ca3"
44
44
  }