@botpress/webchat-client 0.7.0 → 0.7.2

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.7.0 build /home/runner/work/genisys/genisys/packages/webchat-client
2
+ > @botpress/webchat-client@0.7.2 build /home/runner/work/genisys/genisys/packages/webchat-client
3
3
  > openapi-ts && vite build
4
4
 
5
5
  ⏳ Generating from raw OpenAPI specification
@@ -18,12 +18,12 @@ computing gzip size...
18
18
  dist/webchat-client7.js  0.45 kB │ gzip: 0.26 kB
19
19
  dist/webchat-client9.js  2.66 kB │ gzip: 1.17 kB
20
20
  dist/webchat-client3.js  3.50 kB │ gzip: 0.60 kB
21
- dist/webchat-client2.js  5.86 kB │ gzip: 1.64 kB
21
+ dist/webchat-client2.js  5.97 kB │ gzip: 1.69 kB
22
22
  dist/webchat-client10.js  8.58 kB │ gzip: 2.91 kB
23
23
  dist/webchat-client5.js 10.93 kB │ gzip: 3.47 kB
24
24
  [vite:dts] Start rollup declaration files...
25
25
  Analysis will use the bundled TypeScript version 5.8.2
26
26
  *** The target project appears to use TypeScript 5.9.3 which is newer than the bundled compiler engine; consider upgrading API Extractor.
27
- [vite:dts] Declaration files built in 5969ms.
27
+ [vite:dts] Declaration files built in 6001ms.
28
28
 
29
- ✓ built in 6.27s
29
+ ✓ built in 6.31s
@@ -1,86 +1,88 @@
1
- import { createUser as k, generateUserKey as b, sendPerfMetrics as F, removeMessageFeedback as S, addMessageFeedback as T, getEvent as R, createEvent as w, deleteUser as I, updateUser as K, getUser as _, createFile as q, deleteMessage as N, getMessage as z, updateMessage as A, createMessage as J, listParticipants as j, getParticipant as D, removeParticipant as V, addParticipant as X, listConversationMessages as Y, listConversations as B, deleteConversation as G, getConversation as H, createConversation as O } from "./webchat-client3.js";
1
+ import { createUser as T, generateUserKey as C, sendPerfMetrics as L, removeMessageFeedback as F, addMessageFeedback as I, getEvent as S, createEvent as K, deleteUser as R, updateUser as w, getUser as _, createFile as q, deleteMessage as N, getMessage as z, updateMessage as A, createMessage as J, listParticipants as j, getParticipant as D, removeParticipant as V, addParticipant as X, listConversationMessages as Y, listConversations as B, deleteConversation as G, getConversation as H, createConversation as O } from "./webchat-client3.js";
2
2
  import { client as l } from "./webchat-client4.js";
3
3
  import { EventSource as Q } from "./webchat-client5.js";
4
- import { throwErrorInterceptor as C } from "./webchat-client6.js";
4
+ import { throwErrorInterceptor as b } from "./webchat-client6.js";
5
5
  import { createEventEmitter as $ } from "./webchat-client7.js";
6
- const r = (a) => a.data, M = 10, P = 3e3, W = "60000", v = {
6
+ const r = (a) => a.data, M = 10, P = 3e3, W = "60000", U = {
7
7
  throwOnError: !0
8
8
  }, ne = async ({
9
9
  clientId: a,
10
- apiUrl: c,
11
- adminSecret: d,
10
+ apiUrl: h,
11
+ adminSecret: c,
12
12
  customHeaders: o,
13
- ...h
13
+ ...d
14
14
  }) => {
15
- const t = `${c || l.getConfig().baseUrl}/${a}`;
16
- l.interceptors.response._fns.length === 0 && l.interceptors.response.use(C);
15
+ const t = `${h || l.getConfig().baseUrl}/${a}`;
16
+ l.interceptors.response._fns.length === 0 && l.interceptors.response.use(b);
17
17
  const i = {
18
- ...v,
18
+ ...U,
19
19
  baseUrl: t
20
20
  }, s = {
21
- ...d ? { "x-admin-secret": d } : {},
21
+ ...c ? { "x-admin-secret": c } : {},
22
22
  ...o
23
23
  };
24
- return k({
24
+ return T({
25
25
  ...i,
26
26
  headers: Object.keys(s).length > 0 ? s : void 0,
27
- body: h
27
+ body: d
28
28
  }).then(r);
29
29
  }, ae = ({
30
30
  conversationId: a,
31
- userToken: c,
32
- clientId: d,
31
+ userToken: h,
32
+ clientId: c,
33
33
  apiUrl: o,
34
- adminSecret: h
34
+ adminSecret: d
35
35
  }) => {
36
36
  let t = 0, i = null;
37
- const s = $(), m = () => {
37
+ const s = $();
38
+ let f = a, e = h;
39
+ const n = () => {
38
40
  i && i.close();
39
- const n = `${`${o || l.getConfig().baseUrl}/${d}`}/initialize${a ? `?conversationId=${a}` : ""}`, g = {
40
- ...h ? { "x-admin-secret": h } : {},
41
- ...c ? { "x-user-key": c } : {}
41
+ const v = `${`${o || l.getConfig().baseUrl}/${c}`}/initialize${f ? `?conversationId=${f}` : ""}`, m = {
42
+ ...d ? { "x-admin-secret": d } : {},
43
+ ...e ? { "x-user-key": e } : {}
42
44
  };
43
- i = L(n, g), i.addEventListener("open", () => s.emit("open")), i.addEventListener("error", (p) => {
44
- t < M ? (t++, setTimeout(() => m(), P)) : s.emit("error", p);
45
- }), i.addEventListener("message", (p) => {
46
- const u = x(p.data);
47
- s.emit(u.type, u.data);
45
+ i = x(v, m), i.addEventListener("open", () => s.emit("open")), i.addEventListener("error", (u) => {
46
+ t < M ? (t++, setTimeout(() => n(), P)) : s.emit("error", u);
47
+ }), i.addEventListener("message", (u) => {
48
+ const g = k(u.data);
49
+ g.type === "init" && (f = g.data.conversation.id ?? f, e = g.data.user.userKey ?? e), s.emit(g.type, g.data);
48
50
  });
49
51
  };
50
- return m(), s.on;
52
+ return n(), s.on;
51
53
  }, oe = async ({
52
54
  adminSecret: a,
53
- expiresAt: c,
54
- userId: d,
55
+ expiresAt: h,
56
+ userId: c,
55
57
  apiUrl: o,
56
- clientId: h
58
+ clientId: d
57
59
  }) => {
58
- const t = { "x-admin-secret": a }, i = `${o || l.getConfig().baseUrl}/${h}`, s = {
59
- ...v,
60
+ const t = { "x-admin-secret": a }, i = `${o || l.getConfig().baseUrl}/${d}`, s = {
61
+ ...U,
60
62
  baseUrl: i
61
63
  };
62
- return b({ ...s, headers: t, body: { id: d, expiresAt: c } }).then(r);
63
- }, ie = async (a, c, d, o) => {
64
- const h = `${d || l.getConfig().baseUrl}/${a}`, t = {
65
- ...v,
66
- baseUrl: h
64
+ return C({ ...s, headers: t, body: { id: c, expiresAt: h } }).then(r);
65
+ }, ie = async (a, h, c, o) => {
66
+ const d = `${c || l.getConfig().baseUrl}/${a}`, t = {
67
+ ...U,
68
+ baseUrl: d
67
69
  };
68
- return F({ ...t, body: c, headers: o }).then(r);
70
+ return L({ ...t, body: h, headers: o }).then(r);
69
71
  }, ce = ({
70
72
  userKey: a,
71
- clientId: c,
72
- apiUrl: d,
73
+ clientId: h,
74
+ apiUrl: c,
73
75
  customHeaders: o,
74
- advancedOptions: h
76
+ advancedOptions: d
75
77
  }) => {
76
78
  const t = {
77
79
  "x-user-key": a,
78
80
  ...o
79
- }, i = `${d || l.getConfig().baseUrl}/${c}`, s = {
80
- ...v,
81
+ }, i = `${c || l.getConfig().baseUrl}/${h}`, s = {
82
+ ...U,
81
83
  baseUrl: i
82
84
  };
83
- return l.interceptors.response._fns.length === 0 && l.interceptors.response.use(C), {
85
+ return l.interceptors.response._fns.length === 0 && l.interceptors.response.use(b), {
84
86
  createConversation: () => O({ ...s, headers: t, body: {} }).then(r),
85
87
  getConversation: ({ conversationId: e }) => H({ ...s, headers: t, path: { id: e } }).then(r),
86
88
  deleteConversation: ({ conversationId: e }) => G({ ...s, headers: t, path: { id: e } }).then(r),
@@ -101,40 +103,40 @@ const r = (a) => a.data, M = 10, P = 3e3, W = "60000", v = {
101
103
  deleteMessage: ({ messageId: e }) => N({ ...s, headers: t, path: { id: e } }).then(r),
102
104
  createFile: (e) => q({ ...s, headers: t, body: e }).then(r),
103
105
  getUser: () => _({ ...s, headers: t }).then(r),
104
- updateUser: (e) => K({ ...s, headers: t, body: e }).then(r),
105
- deleteUser: () => I({ ...s, headers: t }).then(r),
106
- createEvent: (e) => w({ ...s, headers: t, body: e }).then(r),
107
- getEvent: ({ eventId: e }) => R({ ...s, headers: t, path: { id: e } }).then(r),
108
- addMessageFeedback: ({ messageId: e, ...n }) => T({ ...s, headers: t, path: { id: e }, body: n }).then(r),
109
- removeMessageFeedback: ({ messageId: e }) => S({ ...s, headers: t, path: { id: e } }).then(r),
110
- generateUserKey: ({ adminSecret: e, ...n }) => b({ ...s, headers: { "x-admin-secret": e }, body: n }).then(r),
106
+ updateUser: (e) => w({ ...s, headers: t, body: e }).then(r),
107
+ deleteUser: () => R({ ...s, headers: t }).then(r),
108
+ createEvent: (e) => K({ ...s, headers: t, body: e }).then(r),
109
+ getEvent: ({ eventId: e }) => S({ ...s, headers: t, path: { id: e } }).then(r),
110
+ addMessageFeedback: ({ messageId: e, ...n }) => I({ ...s, headers: t, path: { id: e }, body: n }).then(r),
111
+ removeMessageFeedback: ({ messageId: e }) => F({ ...s, headers: t, path: { id: e } }).then(r),
112
+ generateUserKey: ({ adminSecret: e, ...n }) => C({ ...s, headers: { "x-admin-secret": e }, body: n }).then(r),
111
113
  listenConversation: ({ conversationId: e }) => {
112
- let n = 0, g = null;
113
- const p = $(), u = () => {
114
- g && g.close();
115
- const U = `${i}/conversations/${e}/listen`, E = h == null ? void 0 : h.eventSource;
116
- g = E ? E({ url: U, headers: t }) : L(U, t), g.addEventListener("open", () => p.emit("open")), g.addEventListener("error", (f) => {
117
- n < M ? (n++, setTimeout(() => u(), P)) : p.emit("error", f);
118
- }), g.addEventListener("message", (f) => {
119
- const y = x(f.data);
120
- p.emit(y.type, y.data);
114
+ let n = 0, p = null;
115
+ const v = $(), m = () => {
116
+ p && p.close();
117
+ const u = `${i}/conversations/${e}/listen`, g = d == null ? void 0 : d.eventSource;
118
+ p = g ? g({ url: u, headers: t }) : x(u, t), p.addEventListener("open", () => v.emit("open")), p.addEventListener("error", (E) => {
119
+ n < M ? (n++, setTimeout(() => m(), P)) : v.emit("error", E);
120
+ }), p.addEventListener("message", (E) => {
121
+ const y = k(E.data);
122
+ v.emit(y.type, y.data);
121
123
  });
122
124
  };
123
- return u(), p.on;
125
+ return m(), v.on;
124
126
  }
125
127
  };
126
- }, x = (a) => {
128
+ }, k = (a) => {
127
129
  try {
128
130
  return JSON.parse(a);
129
131
  } catch {
130
132
  return a;
131
133
  }
132
- }, L = (a, c) => new Q(a, {
133
- fetch: (d, o) => fetch(d, {
134
+ }, x = (a, h) => new Q(a, {
135
+ fetch: (c, o) => fetch(c, {
134
136
  ...o,
135
137
  headers: {
136
138
  ...o == null ? void 0 : o.headers,
137
- ...c,
139
+ ...h,
138
140
  timeout: W
139
141
  }
140
142
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/webchat-client",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -142,6 +142,8 @@ export const initialize = ({
142
142
  let retryCount = 0
143
143
  let eventSource: EventSourceLike | null = null
144
144
  const eventEmitter = createEventEmitter<EventMap>()
145
+ let resolvedConversationId = conversationId
146
+ let resolvedUserToken = userToken
145
147
 
146
148
  const connect = () => {
147
149
  if (eventSource) {
@@ -149,11 +151,11 @@ export const initialize = ({
149
151
  }
150
152
 
151
153
  const baseUrl = `${apiUrl || baseClient.getConfig().baseUrl}/${clientId}`
152
- const url = `${baseUrl}/initialize${conversationId ? `?conversationId=${conversationId}` : ''}`
154
+ const url = `${baseUrl}/initialize${resolvedConversationId ? `?conversationId=${resolvedConversationId}` : ''}`
153
155
 
154
156
  const headers = {
155
157
  ...(adminSecret ? { 'x-admin-secret': adminSecret } : {}),
156
- ...(userToken ? { 'x-user-key': userToken } : {}),
158
+ ...(resolvedUserToken ? { 'x-user-key': resolvedUserToken } : {}),
157
159
  }
158
160
 
159
161
  eventSource = createNewEventSource(url, headers)
@@ -169,9 +171,18 @@ export const initialize = ({
169
171
  })
170
172
  eventSource.addEventListener('message', (ev) => {
171
173
  const event = safeJsonParse(ev.data) as Signal
174
+
175
+ // Save the Conversation ID and User Token from the init event so that internal
176
+ // retries reconnect as the same user to the same conversation.
177
+ if (event.type === 'init') {
178
+ resolvedConversationId = event.data.conversation.id ?? resolvedConversationId
179
+ resolvedUserToken = event.data.user.userKey ?? resolvedUserToken
180
+ }
181
+
172
182
  eventEmitter.emit(event.type, event.data)
173
183
  })
174
184
  }
185
+
175
186
  connect()
176
187
  return eventEmitter.on
177
188
  }