@botpress/webchat-client 0.7.1 → 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.1 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.93 kB │ gzip: 1.68 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 6171ms.
27
+ [vite:dts] Declaration files built in 6001ms.
28
28
 
29
- ✓ built in 6.50s
29
+ ✓ built in 6.31s
@@ -1,149 +1,149 @@
1
- import { createUser as k, generateUserKey as C, sendPerfMetrics as F, removeMessageFeedback as I, addMessageFeedback as S, getEvent as T, createEvent as R, deleteUser as w, 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
4
  import { throwErrorInterceptor as b } from "./webchat-client6.js";
5
5
  import { createEventEmitter as $ } from "./webchat-client7.js";
6
- const n = (a) => a.data, M = 10, P = 3e3, W = "60000", m = {
6
+ const r = (a) => a.data, M = 10, P = 3e3, W = "60000", U = {
7
7
  throwOnError: !0
8
- }, re = async ({
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}`;
15
+ const t = `${h || l.getConfig().baseUrl}/${a}`;
16
16
  l.interceptors.response._fns.length === 0 && l.interceptors.response.use(b);
17
17
  const i = {
18
- ...m,
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
28
- }).then(n);
27
+ body: d
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
37
  const s = $();
38
- let f = a;
39
- const e = () => {
38
+ let f = a, e = h;
39
+ const n = () => {
40
40
  i && i.close();
41
- const g = `${`${o || l.getConfig().baseUrl}/${d}`}/initialize${f ? `?conversationId=${f}` : ""}`, v = {
42
- ...h ? { "x-admin-secret": h } : {},
43
- ...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 } : {}
44
44
  };
45
- i = L(g, v), i.addEventListener("open", () => s.emit("open")), i.addEventListener("error", (u) => {
46
- t < M ? (t++, setTimeout(() => e(), P)) : s.emit("error", u);
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
47
  }), i.addEventListener("message", (u) => {
48
- const p = x(u.data);
49
- p.type === "init" && (f = p.data.conversation.id ?? f), s.emit(p.type, p.data);
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);
50
50
  });
51
51
  };
52
- return e(), s.on;
52
+ return n(), s.on;
53
53
  }, oe = async ({
54
54
  adminSecret: a,
55
- expiresAt: c,
56
- userId: d,
55
+ expiresAt: h,
56
+ userId: c,
57
57
  apiUrl: o,
58
- clientId: h
58
+ clientId: d
59
59
  }) => {
60
- const t = { "x-admin-secret": a }, i = `${o || l.getConfig().baseUrl}/${h}`, s = {
61
- ...m,
60
+ const t = { "x-admin-secret": a }, i = `${o || l.getConfig().baseUrl}/${d}`, s = {
61
+ ...U,
62
62
  baseUrl: i
63
63
  };
64
- return C({ ...s, headers: t, body: { id: d, expiresAt: c } }).then(n);
65
- }, ie = async (a, c, d, o) => {
66
- const h = `${d || l.getConfig().baseUrl}/${a}`, t = {
67
- ...m,
68
- 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
69
69
  };
70
- return F({ ...t, body: c, headers: o }).then(n);
70
+ return L({ ...t, body: h, headers: o }).then(r);
71
71
  }, ce = ({
72
72
  userKey: a,
73
- clientId: c,
74
- apiUrl: d,
73
+ clientId: h,
74
+ apiUrl: c,
75
75
  customHeaders: o,
76
- advancedOptions: h
76
+ advancedOptions: d
77
77
  }) => {
78
78
  const t = {
79
79
  "x-user-key": a,
80
80
  ...o
81
- }, i = `${d || l.getConfig().baseUrl}/${c}`, s = {
82
- ...m,
81
+ }, i = `${c || l.getConfig().baseUrl}/${h}`, s = {
82
+ ...U,
83
83
  baseUrl: i
84
84
  };
85
85
  return l.interceptors.response._fns.length === 0 && l.interceptors.response.use(b), {
86
- createConversation: () => O({ ...s, headers: t, body: {} }).then(n),
87
- getConversation: ({ conversationId: e }) => H({ ...s, headers: t, path: { id: e } }).then(n),
88
- deleteConversation: ({ conversationId: e }) => G({ ...s, headers: t, path: { id: e } }).then(n),
89
- listConversations: ({ nextToken: e }) => B({ ...s, headers: t, query: { nextToken: e } }).then(n),
90
- listConversationMessages: ({ conversationId: e, nextToken: r }) => Y({
86
+ createConversation: () => O({ ...s, headers: t, body: {} }).then(r),
87
+ getConversation: ({ conversationId: e }) => H({ ...s, headers: t, path: { id: e } }).then(r),
88
+ deleteConversation: ({ conversationId: e }) => G({ ...s, headers: t, path: { id: e } }).then(r),
89
+ listConversations: ({ nextToken: e }) => B({ ...s, headers: t, query: { nextToken: e } }).then(r),
90
+ listConversationMessages: ({ conversationId: e, nextToken: n }) => Y({
91
91
  ...s,
92
92
  headers: t,
93
93
  path: { id: e },
94
- query: { nextToken: r }
95
- }).then(n),
96
- addParticipant: ({ conversationId: e, userId: r }) => X({ ...s, headers: t, path: { id: e }, body: { userId: r } }).then(n),
97
- removeParticipant: ({ conversationId: e, userId: r }) => V({ ...s, headers: t, path: { id: e, userId: r } }).then(n),
98
- getParticipant: ({ conversationId: e, userId: r }) => D({ ...s, headers: t, path: { id: e, userId: r } }).then(n),
99
- listParticipants: ({ conversationId: e, nextToken: r }) => j({ ...s, headers: t, path: { id: e }, query: { nextToken: r } }).then(n),
100
- createMessage: (e) => J({ ...s, headers: t, body: e }).then(n),
101
- updateMessage: ({ messageId: e, ...r }) => A({ ...s, headers: t, path: { id: e }, body: r }).then(n),
102
- getMessage: ({ messageId: e }) => z({ ...s, headers: t, path: { id: e } }).then(n),
103
- deleteMessage: ({ messageId: e }) => N({ ...s, headers: t, path: { id: e } }).then(n),
104
- createFile: (e) => q({ ...s, headers: t, body: e }).then(n),
105
- getUser: () => _({ ...s, headers: t }).then(n),
106
- updateUser: (e) => K({ ...s, headers: t, body: e }).then(n),
107
- deleteUser: () => w({ ...s, headers: t }).then(n),
108
- createEvent: (e) => R({ ...s, headers: t, body: e }).then(n),
109
- getEvent: ({ eventId: e }) => T({ ...s, headers: t, path: { id: e } }).then(n),
110
- addMessageFeedback: ({ messageId: e, ...r }) => S({ ...s, headers: t, path: { id: e }, body: r }).then(n),
111
- removeMessageFeedback: ({ messageId: e }) => I({ ...s, headers: t, path: { id: e } }).then(n),
112
- generateUserKey: ({ adminSecret: e, ...r }) => C({ ...s, headers: { "x-admin-secret": e }, body: r }).then(n),
94
+ query: { nextToken: n }
95
+ }).then(r),
96
+ addParticipant: ({ conversationId: e, userId: n }) => X({ ...s, headers: t, path: { id: e }, body: { userId: n } }).then(r),
97
+ removeParticipant: ({ conversationId: e, userId: n }) => V({ ...s, headers: t, path: { id: e, userId: n } }).then(r),
98
+ getParticipant: ({ conversationId: e, userId: n }) => D({ ...s, headers: t, path: { id: e, userId: n } }).then(r),
99
+ listParticipants: ({ conversationId: e, nextToken: n }) => j({ ...s, headers: t, path: { id: e }, query: { nextToken: n } }).then(r),
100
+ createMessage: (e) => J({ ...s, headers: t, body: e }).then(r),
101
+ updateMessage: ({ messageId: e, ...n }) => A({ ...s, headers: t, path: { id: e }, body: n }).then(r),
102
+ getMessage: ({ messageId: e }) => z({ ...s, headers: t, path: { id: e } }).then(r),
103
+ deleteMessage: ({ messageId: e }) => N({ ...s, headers: t, path: { id: e } }).then(r),
104
+ createFile: (e) => q({ ...s, headers: t, body: e }).then(r),
105
+ getUser: () => _({ ...s, headers: t }).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),
113
113
  listenConversation: ({ conversationId: e }) => {
114
- let r = 0, g = null;
115
- const v = $(), u = () => {
116
- g && g.close();
117
- const p = `${i}/conversations/${e}/listen`, E = h == null ? void 0 : h.eventSource;
118
- g = E ? E({ url: p, headers: t }) : L(p, t), g.addEventListener("open", () => v.emit("open")), g.addEventListener("error", (U) => {
119
- r < M ? (r++, setTimeout(() => u(), P)) : v.emit("error", U);
120
- }), g.addEventListener("message", (U) => {
121
- const y = x(U.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
122
  v.emit(y.type, y.data);
123
123
  });
124
124
  };
125
- return u(), v.on;
125
+ return m(), v.on;
126
126
  }
127
127
  };
128
- }, x = (a) => {
128
+ }, k = (a) => {
129
129
  try {
130
130
  return JSON.parse(a);
131
131
  } catch {
132
132
  return a;
133
133
  }
134
- }, L = (a, c) => new Q(a, {
135
- fetch: (d, o) => fetch(d, {
134
+ }, x = (a, h) => new Q(a, {
135
+ fetch: (c, o) => fetch(c, {
136
136
  ...o,
137
137
  headers: {
138
138
  ...o == null ? void 0 : o.headers,
139
- ...c,
139
+ ...h,
140
140
  timeout: W
141
141
  }
142
142
  })
143
143
  });
144
144
  export {
145
145
  ce as createClient,
146
- re as createUser,
146
+ ne as createUser,
147
147
  oe as generateUserKey,
148
148
  ae as initialize,
149
149
  ie as sendPerfMetrics
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/webchat-client",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -143,6 +143,7 @@ export const initialize = ({
143
143
  let eventSource: EventSourceLike | null = null
144
144
  const eventEmitter = createEventEmitter<EventMap>()
145
145
  let resolvedConversationId = conversationId
146
+ let resolvedUserToken = userToken
146
147
 
147
148
  const connect = () => {
148
149
  if (eventSource) {
@@ -154,7 +155,7 @@ export const initialize = ({
154
155
 
155
156
  const headers = {
156
157
  ...(adminSecret ? { 'x-admin-secret': adminSecret } : {}),
157
- ...(userToken ? { 'x-user-key': userToken } : {}),
158
+ ...(resolvedUserToken ? { 'x-user-key': resolvedUserToken } : {}),
158
159
  }
159
160
 
160
161
  eventSource = createNewEventSource(url, headers)
@@ -171,9 +172,11 @@ export const initialize = ({
171
172
  eventSource.addEventListener('message', (ev) => {
172
173
  const event = safeJsonParse(ev.data) as Signal
173
174
 
174
- // Save this conversationId for future reconnections in case of a connection error retry
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.
175
177
  if (event.type === 'init') {
176
178
  resolvedConversationId = event.data.conversation.id ?? resolvedConversationId
179
+ resolvedUserToken = event.data.user.userKey ?? resolvedUserToken
177
180
  }
178
181
 
179
182
  eventEmitter.emit(event.type, event.data)