@botfabrik/engine-webclient 4.101.1 → 4.101.3-alpha.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.
@@ -1,107 +1,97 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const globals_1 = require("@jest/globals");
7
- const requestSessionData_1 = __importDefault(require("./requestSessionData"));
8
- globals_1.jest.mock('crypto', () => {
9
- const original = globals_1.jest.requireActual('crypto');
10
- return {
11
- v4: globals_1.jest.fn(() => 'uuid'),
12
- ...original,
13
- randomUUID: globals_1.jest.fn(() => 'some-uuid'),
14
- };
15
- });
16
- (0, globals_1.describe)('request session id', () => {
17
- (0, globals_1.beforeEach)(() => {
18
- globals_1.jest.clearAllMocks();
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import requestSessionData from './requestSessionData.js';
3
+ vi.mock('node:crypto', () => ({
4
+ randomUUID: vi.fn(() => 'some-uuid'),
5
+ }));
6
+ describe('request session id', () => {
7
+ beforeEach(() => {
8
+ vi.clearAllMocks();
19
9
  });
20
10
  const querystrings = {
21
11
  accessToken: 'access-token',
22
12
  };
23
- (0, globals_1.it)('when sessionId has been passed by query param but does not exists in db', async () => {
24
- const findOne = globals_1.jest.fn();
13
+ it('when sessionId has been passed by query param but does not exists in db', async () => {
14
+ const findOne = vi.fn();
25
15
  findOne.mockReturnValueOnce(undefined);
26
16
  const sessionsCollection = {
27
17
  findOne,
28
18
  };
29
- const { sessionId, isNew } = await (0, requestSessionData_1.default)('session-id', querystrings, sessionsCollection, 'test-bot', {});
30
- (0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
31
- (0, globals_1.expect)(findOne).toHaveBeenCalledWith({
19
+ const { sessionId, isNew } = await requestSessionData('session-id', querystrings, sessionsCollection, 'test-bot', {});
20
+ expect(findOne).toHaveBeenCalledTimes(1);
21
+ expect(findOne).toHaveBeenCalledWith({
32
22
  _id: 'session-id',
33
23
  'sessionInfo.client.name': 'test-bot',
34
24
  'sessionInfo.client.type': 'webclient',
35
25
  }, { _id: 1, sessionInfo: 1 });
36
- (0, globals_1.expect)(sessionId).toBe('some-uuid');
37
- (0, globals_1.expect)(isNew).toBe(true);
26
+ expect(sessionId).toBe('some-uuid');
27
+ expect(isNew).toBe(true);
38
28
  });
39
- (0, globals_1.it)('when sessionId has been passed by query param and exists in db', async () => {
40
- const findOne = globals_1.jest.fn();
29
+ it('when sessionId has been passed by query param and exists in db', async () => {
30
+ const findOne = vi.fn();
41
31
  findOne.mockReturnValueOnce({ _id: 'session-id' });
42
32
  const sessionsCollection = {
43
33
  findOne,
44
34
  };
45
- const { sessionId, isNew } = await (0, requestSessionData_1.default)('session-id', querystrings, sessionsCollection, 'test-bot', {});
46
- (0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
47
- (0, globals_1.expect)(findOne).toHaveBeenCalledWith({
35
+ const { sessionId, isNew } = await requestSessionData('session-id', querystrings, sessionsCollection, 'test-bot', {});
36
+ expect(findOne).toHaveBeenCalledTimes(1);
37
+ expect(findOne).toHaveBeenCalledWith({
48
38
  _id: 'session-id',
49
39
  'sessionInfo.client.name': 'test-bot',
50
40
  'sessionInfo.client.type': 'webclient',
51
41
  }, { _id: 1, sessionInfo: 1 });
52
- (0, globals_1.expect)(sessionId).toBe('session-id');
53
- (0, globals_1.expect)(isNew).toBe(false);
42
+ expect(sessionId).toBe('session-id');
43
+ expect(isNew).toBe(false);
54
44
  });
55
- (0, globals_1.it)('when requestSessionRecordQuery has been passed as webclient property but no such session exists in db', async () => {
56
- const findOne = globals_1.jest.fn();
45
+ it('when requestSessionRecordQuery has been passed as webclient property but no such session exists in db', async () => {
46
+ const findOne = vi.fn();
57
47
  findOne.mockReturnValueOnce(undefined);
58
48
  const sessionsCollection = {
59
49
  findOne,
60
50
  };
61
- const requestSessionRecordQuery = globals_1.jest.fn();
51
+ const requestSessionRecordQuery = vi.fn();
62
52
  const props = {
63
53
  requestSessionRecordQuery,
64
54
  };
65
55
  requestSessionRecordQuery.mockReturnValueOnce(Promise.resolve({ 'sessionInfo.user.id': 'hans@apptiva.ch' }));
66
- const { sessionId, isNew } = await (0, requestSessionData_1.default)('session-id', querystrings, sessionsCollection, 'test-bot', props);
67
- (0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
68
- (0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledWith({
56
+ const { sessionId, isNew } = await requestSessionData('session-id', querystrings, sessionsCollection, 'test-bot', props);
57
+ expect(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
58
+ expect(requestSessionRecordQuery).toHaveBeenCalledWith({
69
59
  querystrings,
70
60
  sessionId: 'session-id',
71
61
  });
72
- (0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
73
- (0, globals_1.expect)(findOne).toHaveBeenCalledWith({
62
+ expect(findOne).toHaveBeenCalledTimes(1);
63
+ expect(findOne).toHaveBeenCalledWith({
74
64
  'sessionInfo.client.name': 'test-bot',
75
65
  'sessionInfo.client.type': 'webclient',
76
66
  'sessionInfo.user.id': 'hans@apptiva.ch',
77
67
  }, { _id: 1, sessionInfo: 1 });
78
- (0, globals_1.expect)(sessionId).toBe('some-uuid');
79
- (0, globals_1.expect)(isNew).toBe(true);
68
+ expect(sessionId).toBe('some-uuid');
69
+ expect(isNew).toBe(true);
80
70
  });
81
- (0, globals_1.it)('when requestSessionRecordQuery has been passed as webclient property and session exists in db', async () => {
82
- const findOne = globals_1.jest.fn();
71
+ it('when requestSessionRecordQuery has been passed as webclient property and session exists in db', async () => {
72
+ const findOne = vi.fn();
83
73
  findOne.mockReturnValueOnce({ _id: 'session-id' });
84
74
  const sessionsCollection = {
85
75
  findOne,
86
76
  };
87
- const requestSessionRecordQuery = globals_1.jest.fn();
77
+ const requestSessionRecordQuery = vi.fn();
88
78
  const props = {
89
79
  requestSessionRecordQuery,
90
80
  };
91
81
  requestSessionRecordQuery.mockReturnValueOnce(Promise.resolve({ 'sessionInfo.user.id': 'hans@apptiva.ch' }));
92
- const { sessionId, isNew } = await (0, requestSessionData_1.default)('session-id', querystrings, sessionsCollection, 'test-bot', props);
93
- (0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
94
- (0, globals_1.expect)(requestSessionRecordQuery).toHaveBeenCalledWith({
82
+ const { sessionId, isNew } = await requestSessionData('session-id', querystrings, sessionsCollection, 'test-bot', props);
83
+ expect(requestSessionRecordQuery).toHaveBeenCalledTimes(1);
84
+ expect(requestSessionRecordQuery).toHaveBeenCalledWith({
95
85
  querystrings,
96
86
  sessionId: 'session-id',
97
87
  });
98
- (0, globals_1.expect)(findOne).toHaveBeenCalledTimes(1);
99
- (0, globals_1.expect)(findOne).toHaveBeenCalledWith({
88
+ expect(findOne).toHaveBeenCalledTimes(1);
89
+ expect(findOne).toHaveBeenCalledWith({
100
90
  'sessionInfo.client.name': 'test-bot',
101
91
  'sessionInfo.client.type': 'webclient',
102
92
  'sessionInfo.user.id': 'hans@apptiva.ch',
103
93
  }, { _id: 1, sessionInfo: 1 });
104
- (0, globals_1.expect)(sessionId).toBe('session-id');
105
- (0, globals_1.expect)(isNew).toBe(false);
94
+ expect(sessionId).toBe('session-id');
95
+ expect(isNew).toBe(false);
106
96
  });
107
97
  });
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const flat_1 = require("flat");
1
+ import { flatten } from 'flat';
4
2
  const TRANSLATION_KEY = 'website-messenger';
5
3
  const setTranslations = (socket, bot, clientLocale, clientName) => {
6
4
  socket.emit('set-translations', clientLocale, getTranslationsByClient(bot, clientLocale, clientName));
@@ -9,9 +7,9 @@ const getTranslationsByClient = (bot, clientLocale, clientName) => {
9
7
  const webMessengerTranslations = bot.translation.getResourceBundle(clientLocale)[TRANSLATION_KEY] || {};
10
8
  const defaults = webMessengerTranslations['defaults'] || {};
11
9
  const overrides = webMessengerTranslations['overrides']?.[clientName] || {};
12
- const defaultFlat = (0, flat_1.flatten)(defaults);
13
- const overrideFlat = (0, flat_1.flatten)(overrides);
10
+ const defaultFlat = flatten(defaults);
11
+ const overrideFlat = flatten(overrides);
14
12
  const mergedTranslations = { ...defaultFlat, ...overrideFlat };
15
13
  return mergedTranslations;
16
14
  };
17
- exports.default = setTranslations;
15
+ export default setTranslations;
@@ -1,3 +1,3 @@
1
- import type { SpeechToTextProps } from './types';
1
+ import type { SpeechToTextProps } from './types.js';
2
2
  declare const speechToText: (speechProps: SpeechToTextProps, locale: string, speechBytes: any) => Promise<string>;
3
3
  export default speechToText;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const speech_1 = require("@google-cloud/speech");
1
+ import { SpeechClient } from '@google-cloud/speech';
4
2
  const speechToText = (speechProps, locale, speechBytes) => {
5
3
  return new Promise((resolve, reject) => {
6
4
  const speechConfig = {
@@ -9,7 +7,7 @@ const speechToText = (speechProps, locale, speechBytes) => {
9
7
  client_email: speechProps.clientEmail,
10
8
  },
11
9
  };
12
- const client = new speech_1.SpeechClient(speechConfig);
10
+ const client = new SpeechClient(speechConfig);
13
11
  // The audio file's encoding, sample rate in hertz, and BCP-47 language code
14
12
  const audio = {
15
13
  content: speechBytes,
@@ -45,4 +43,4 @@ const speechToText = (speechProps, locale, speechBytes) => {
45
43
  .catch(reject);
46
44
  });
47
45
  };
48
- exports.default = speechToText;
46
+ export default speechToText;
package/dist/types.js CHANGED
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Devices = void 0;
4
- var Devices;
1
+ export var Devices;
5
2
  (function (Devices) {
6
3
  Devices["All"] = "all";
7
4
  Devices["Mobile"] = "mobile";
8
5
  Devices["Desktop"] = "desktop";
9
6
  Devices["None"] = "none";
10
- })(Devices || (exports.Devices = Devices = {}));
7
+ })(Devices || (Devices = {}));
@@ -0,0 +1 @@
1
+ export declare const version: string;
@@ -0,0 +1,2 @@
1
+ import pkg from '../package.json' with { type: 'json' };
2
+ export const version = pkg.version;
@@ -1,5 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  const index = (server, scriptUrl) => `<!DOCTYPE html>
4
2
  <html lang="de">
5
3
  <head>
@@ -166,4 +164,4 @@ const index = (server, scriptUrl) => `<!DOCTYPE html>
166
164
  </body>
167
165
  </html>
168
166
  `;
169
- exports.default = index;
167
+ export default index;
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "@botfabrik/engine-webclient",
3
- "version": "4.101.1",
3
+ "version": "4.101.3-alpha.0",
4
4
  "description": "Webclient for Botfabriks Bot Engine",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "dist"
16
+ ],
7
17
  "scripts": {
8
18
  "build": "npm run clean && npm run build:client && npm run build:server && npm run build:script-tag && npm run copy:client && npm run copy:script-tag",
9
19
  "build:script-tag": "(cd ./script-tag && npm run build && cd ..)",
@@ -12,17 +22,18 @@
12
22
  "copy:script-tag": "copyfiles -u 2 ./script-tag/dist/bundle.js ./dist/embed",
13
23
  "copy:client": "copyfiles -u 2 ./client/dist/** ./dist/client && copyfiles -u 2 ./client/dist/**/*.* ./dist/client",
14
24
  "clean": "rimraf ./dist",
15
- "test": "jest --verbose",
16
- "test:watch": "jest --watch",
25
+ "test": "vitest run --reporter=verbose",
26
+ "test:ci": "vitest run --reporter=verbose",
27
+ "test:watch": "vitest --watch --reporter=verbose",
17
28
  "prepare": "(cd client && npm install); (cd script-tag && npm install)",
18
29
  "prepublishOnly": "npm run build",
19
30
  "update": "npx npm-check-updates -i",
20
31
  "dev:embed": "tsx --watch ./run-embed-local.ts"
21
32
  },
22
33
  "dependencies": {
23
- "@botfabrik/engine-domain": "^4.101.1",
24
- "@botfabrik/engine-transcript-export": "^4.101.1",
25
- "@botfabrik/engine-utils": "^4.101.1",
34
+ "@botfabrik/engine-domain": "^4.101.3-alpha.0",
35
+ "@botfabrik/engine-transcript-export": "^4.101.3-alpha.0",
36
+ "@botfabrik/engine-utils": "^4.101.3-alpha.0",
26
37
  "@google-cloud/speech": "^7.2.1",
27
38
  "@node-saml/passport-saml": "^5.1.0",
28
39
  "accept-language-parser": "^1.5.0",
@@ -43,5 +54,5 @@
43
54
  "tsx": "^4.20.6",
44
55
  "typescript": "5.9.3"
45
56
  },
46
- "gitHead": "2a1effa02dfda6b6949d93ad7489b7a1155833ea"
57
+ "gitHead": "668bb5e26c514e7d091febc092c784db0dd65210"
47
58
  }