@botpress/webchat-client 0.1.0 → 0.1.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @botpress/webchat-client@0.1.0 build /home/runner/work/genisys/genisys/packages/webchat-client
2
+ > @botpress/webchat-client@0.1.1 build /home/runner/work/genisys/genisys/packages/webchat-client
3
3
  > openapi-ts && vite build
4
4
 
5
5
  ⏳ Generating from raw OpenAPI specification
@@ -17,12 +17,12 @@ computing gzip size...
17
17
  dist/webchat-client6.js  0.53 kB │ gzip: 0.26 kB
18
18
  dist/webchat-client8.js  2.63 kB │ gzip: 1.15 kB
19
19
  dist/webchat-client3.js  2.78 kB │ gzip: 0.52 kB
20
- dist/webchat-client2.js  3.68 kB │ gzip: 1.03 kB
20
+ dist/webchat-client2.js  3.74 kB │ gzip: 1.06 kB
21
21
  dist/webchat-client9.js  8.58 kB │ gzip: 2.91 kB
22
22
  dist/webchat-client5.js 10.93 kB │ gzip: 3.47 kB
23
23
  [vite:dts] Start rollup declaration files...
24
24
  Analysis will use the bundled TypeScript version 5.4.2
25
25
  *** The target project appears to use TypeScript 5.6.2 which is newer than the bundled compiler engine; consider upgrading API Extractor.
26
- [vite:dts] Declaration files built in 5689ms.
26
+ [vite:dts] Declaration files built in 5765ms.
27
27
 
28
- ✓ built in 6.02s
28
+ ✓ built in 6.16s
@@ -1,60 +1,59 @@
1
- import { createUser as g, getEvent as m, createEvent as C, deleteUser as U, updateUser as f, getUser as M, createFile as b, deleteMessage as y, getMessage as E, updateMessage as P, createMessage as $, listParticipants as q, getParticipant as w, removeParticipant as x, addParticipant as S, listConversationMessages as F, listConversations as J, deleteConversation as O, getConversation as k, createConversation as D } from "./webchat-client3.js";
2
- import { client as l } from "./webchat-client4.js";
3
- import { EventSource as N } from "./webchat-client5.js";
4
- import { EventEmitter as _ } from "./webchat-client6.js";
5
- const n = (a) => a.data, v = {
1
+ import { createUser as u, getEvent as f, createEvent as U, deleteUser as M, updateUser as y, getUser as R, createFile as b, deleteMessage as P, getMessage as T, updateMessage as $, createMessage as S, listParticipants as _, getParticipant as A, removeParticipant as I, addParticipant as q, listConversationMessages as w, listConversations as x, deleteConversation as N, getConversation as F, createConversation as J } from "./webchat-client3.js";
2
+ import { client as m } from "./webchat-client4.js";
3
+ import { EventSource as L } from "./webchat-client5.js";
4
+ import { EventEmitter as O } from "./webchat-client6.js";
5
+ const n = (a) => a.data, E = {
6
6
  throwOnError: !0
7
- }, I = ({ clientId: a, apiUrl: h }) => {
8
- const d = `${h || l.getConfig().baseUrl}/${a}`, t = {
9
- ...v,
10
- baseUrl: d
7
+ }, z = ({ clientId: a, apiUrl: d }) => {
8
+ const p = `${d || m.getConfig().baseUrl}/${a}`, t = {
9
+ ...E,
10
+ baseUrl: p
11
11
  };
12
- return g({ ...t, body: {} }).then(n);
13
- }, K = ({
12
+ return u({ ...t, body: {} }).then(n);
13
+ }, B = ({
14
14
  userKey: a,
15
- clientId: h,
16
- apiUrl: d
15
+ clientId: d,
16
+ apiUrl: p
17
17
  }) => {
18
18
  const t = {
19
19
  "x-user-key": a
20
- }, p = `${d || l.getConfig().baseUrl}/${h}`, r = {
21
- ...v,
22
- baseUrl: p
20
+ }, g = `${p || m.getConfig().baseUrl}/${d}`, r = {
21
+ ...E,
22
+ baseUrl: g
23
23
  };
24
24
  return {
25
- createConversation: () => D({ ...r, headers: t, body: {} }).then(n),
26
- getConversation: ({ conversationId: e }) => k({ ...r, headers: t, path: { id: e } }).then(n),
27
- deleteConversation: ({ conversationId: e }) => O({ ...r, headers: t, path: { id: e } }).then(n),
28
- listConversations: ({ nextToken: e }) => J({ ...r, headers: t, query: { nextToken: e } }).then(n),
29
- listConversationMessages: ({ conversationId: e, nextToken: s }) => F({
25
+ createConversation: () => J({ ...r, headers: t, body: {} }).then(n),
26
+ getConversation: ({ conversationId: e }) => F({ ...r, headers: t, path: { id: e } }).then(n),
27
+ deleteConversation: ({ conversationId: e }) => N({ ...r, headers: t, path: { id: e } }).then(n),
28
+ listConversations: ({ nextToken: e }) => x({ ...r, headers: t, query: { nextToken: e } }).then(n),
29
+ listConversationMessages: ({ conversationId: e, nextToken: s }) => w({
30
30
  ...r,
31
31
  headers: t,
32
32
  path: { id: e },
33
33
  query: { nextToken: s }
34
34
  }).then(n),
35
- addParticipant: ({ conversationId: e, userId: s }) => S({ ...r, headers: t, path: { id: e }, body: { userId: s } }).then(n),
36
- removeParticipant: ({ conversationId: e, userId: s }) => x({ ...r, headers: t, path: { id: e, userId: s } }).then(n),
37
- getParticipant: ({ conversationId: e, userId: s }) => w({ ...r, headers: t, path: { id: e, userId: s } }).then(n),
38
- listParticipants: ({ conversationId: e, nextToken: s }) => q({ ...r, headers: t, path: { id: e }, query: { nextToken: s } }).then(n),
39
- createMessage: (e) => $({ ...r, headers: t, body: e }).then(n),
40
- updateMessage: ({ messageId: e, ...s }) => P({ ...r, headers: t, path: { id: e }, body: s }).then(n),
41
- getMessage: ({ messageId: e }) => E({ ...r, headers: t, path: { id: e } }).then(n),
42
- deleteMessage: ({ messageId: e }) => y({ ...r, headers: t, path: { id: e } }).then(n),
35
+ addParticipant: ({ conversationId: e, userId: s }) => q({ ...r, headers: t, path: { id: e }, body: { userId: s } }).then(n),
36
+ removeParticipant: ({ conversationId: e, userId: s }) => I({ ...r, headers: t, path: { id: e, userId: s } }).then(n),
37
+ getParticipant: ({ conversationId: e, userId: s }) => A({ ...r, headers: t, path: { id: e, userId: s } }).then(n),
38
+ listParticipants: ({ conversationId: e, nextToken: s }) => _({ ...r, headers: t, path: { id: e }, query: { nextToken: s } }).then(n),
39
+ createMessage: (e) => S({ ...r, headers: t, body: e }).then(n),
40
+ updateMessage: ({ messageId: e, ...s }) => $({ ...r, headers: t, path: { id: e }, body: s }).then(n),
41
+ getMessage: ({ messageId: e }) => T({ ...r, headers: t, path: { id: e } }).then(n),
42
+ deleteMessage: ({ messageId: e }) => P({ ...r, headers: t, path: { id: e } }).then(n),
43
43
  createFile: (e) => b({ ...r, headers: t, body: e }).then(n),
44
- createUser: (e) => g({ ...r, headers: t, body: e }).then(n),
45
- getUser: () => M({ ...r, headers: t }).then(n),
46
- updateUser: (e) => f({ ...r, headers: t, body: e }).then(n),
47
- deleteUser: () => U({ ...r, headers: t }).then(n),
48
- createEvent: (e) => C({ ...r, headers: t, body: e }).then(n),
49
- getEvent: ({ eventId: e }) => m({ ...r, headers: t, path: { id: e } }).then(n),
44
+ createUser: (e) => u({ ...r, headers: t, body: e }).then(n),
45
+ getUser: () => R({ ...r, headers: t }).then(n),
46
+ updateUser: (e) => y({ ...r, headers: t, body: e }).then(n),
47
+ deleteUser: () => M({ ...r, headers: t }).then(n),
48
+ createEvent: (e) => U({ ...r, headers: t, body: e }).then(n),
49
+ getEvent: ({ eventId: e }) => f({ ...r, headers: t, path: { id: e } }).then(n),
50
50
  listenConversation: ({ conversationId: e }) => {
51
- let s = null;
52
- const i = new _();
53
- return (() => {
54
- s && s.close();
55
- const u = `${p}/conversations/${e}/listen`;
56
- s = new N(u, {
57
- fetch: (c, o) => fetch(c, {
51
+ let l = 0, i = null;
52
+ const c = new O(), v = () => {
53
+ i && i.close();
54
+ const C = `${g}/conversations/${e}/listen`;
55
+ i = new L(C, {
56
+ fetch: (h, o) => fetch(h, {
58
57
  ...o,
59
58
  headers: {
60
59
  ...o == null ? void 0 : o.headers,
@@ -62,16 +61,17 @@ const n = (a) => a.data, v = {
62
61
  timeout: "60_000"
63
62
  }
64
63
  })
65
- }), s.onopen = () => i.emit("open"), s.onerror = (c) => {
66
- i.emit("error", c);
67
- }, s.onmessage = (c) => {
68
- const o = j(c.data);
69
- i.emit(o.type, o.data);
64
+ }), i.onopen = () => c.emit("open"), i.onerror = (h) => {
65
+ c.emit("error", h), l < 10 && (l++, setTimeout(() => v(), 3e3));
66
+ }, i.onmessage = (h) => {
67
+ const o = V(h.data);
68
+ c.emit(o.type, o.data);
70
69
  };
71
- })(), i.on.bind(i);
70
+ };
71
+ return v(), c.on.bind(c);
72
72
  }
73
73
  };
74
- }, j = (a) => {
74
+ }, V = (a) => {
75
75
  try {
76
76
  return JSON.parse(a);
77
77
  } catch {
@@ -79,6 +79,6 @@ const n = (a) => a.data, v = {
79
79
  }
80
80
  };
81
81
  export {
82
- K as createClient,
83
- I as createUser
82
+ B as createClient,
83
+ z as createUser
84
84
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/webchat-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -137,7 +137,7 @@ export const createClient = ({
137
137
  createEvent: (body) => sdk.createEvent({ ...configs, headers, body }).then(extractData),
138
138
  getEvent: ({ eventId }) => sdk.getEvent({ ...configs, headers, path: { id: eventId } }).then(extractData),
139
139
  listenConversation: ({ conversationId }) => {
140
- const MAX_RETRIES = 5
140
+ const MAX_RETRIES = 10
141
141
  const RETRY_INTERVAL = 3000 // ms
142
142
  let retryCount = 0
143
143
  let eventSource: EventSource | null = null
@@ -166,11 +166,9 @@ export const createClient = ({
166
166
  eventSource.onerror = (err) => {
167
167
  eventEmitter.emit('error', err)
168
168
 
169
- // Attempt reconnect with limit
170
169
  if (retryCount < MAX_RETRIES) {
171
170
  retryCount++
172
- // todo: fix this
173
- // setTimeout(() => connect(), RETRY_INTERVAL)
171
+ setTimeout(() => connect(), RETRY_INTERVAL)
174
172
  }
175
173
  }
176
174
  eventSource.onmessage = (ev) => {
package/vite.config.ts CHANGED
@@ -4,7 +4,7 @@ import treeShakeable from 'rollup-plugin-tree-shakeable'
4
4
  import dts from 'vite-plugin-dts'
5
5
 
6
6
  export default defineConfig({
7
- plugins: [treeShakeable(), dts({ rollupTypes: true })],
7
+ plugins: [treeShakeable() as any, dts({ rollupTypes: true })],
8
8
  build: {
9
9
  lib: {
10
10
  entry: resolve(__dirname, 'src/index.ts'),