@botpress/webchat-client 0.6.1 → 0.7.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.6.1 build /home/runner/work/genisys/genisys/packages/webchat-client
2
+ > @botpress/webchat-client@0.7.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
@@ -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.93 kB │ gzip: 1.68 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 6133ms.
27
+ [vite:dts] Declaration files built in 6171ms.
28
28
 
29
- ✓ built in 6.44s
29
+ ✓ built in 6.50s
package/dist/index.d.ts CHANGED
@@ -1117,6 +1117,12 @@ export declare type CreateUserBody = {
1117
1117
  * User data. An object or a signed JWT token
1118
1118
  */
1119
1119
  userData?: {} | string;
1120
+ /**
1121
+ * Custom attributes for the user as key-value pairs. Can be an object or a signed JWT token.
1122
+ */
1123
+ attributes?: {
1124
+ [key: string]: string;
1125
+ } | string;
1120
1126
  };
1121
1127
 
1122
1128
  export declare type CreateUserData = {
@@ -4003,6 +4009,12 @@ export declare type UpdateUserBody = {
4003
4009
  * User data. An object or a signed JWT token
4004
4010
  */
4005
4011
  userData?: {} | string | null;
4012
+ /**
4013
+ * Custom attributes for the user as key-value pairs. Can be an object or a signed JWT token. Set a key to null to delete it.
4014
+ */
4015
+ attributes?: {
4016
+ [key: string]: string | null;
4017
+ } | string;
4006
4018
  };
4007
4019
 
4008
4020
  export declare type UpdateUserData = {
@@ -4059,6 +4071,12 @@ export declare type User = {
4059
4071
  * User data
4060
4072
  */
4061
4073
  data?: {};
4074
+ /**
4075
+ * Custom attributes of the user
4076
+ */
4077
+ attributes?: {
4078
+ [key: string]: string;
4079
+ };
4062
4080
  /**
4063
4081
  * Id of the [User](#schema_user)
4064
4082
  */
@@ -1,11 +1,11 @@
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 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";
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 n = (a) => a.data, M = 10, P = 3e3, W = "60000", m = {
7
7
  throwOnError: !0
8
- }, ne = async ({
8
+ }, re = async ({
9
9
  clientId: a,
10
10
  apiUrl: c,
11
11
  adminSecret: d,
@@ -13,9 +13,9 @@ const r = (a) => a.data, M = 10, P = 3e3, W = "60000", v = {
13
13
  ...h
14
14
  }) => {
15
15
  const t = `${c || l.getConfig().baseUrl}/${a}`;
16
- l.interceptors.response._fns.length === 0 && l.interceptors.response.use(C);
16
+ l.interceptors.response._fns.length === 0 && l.interceptors.response.use(b);
17
17
  const i = {
18
- ...v,
18
+ ...m,
19
19
  baseUrl: t
20
20
  }, s = {
21
21
  ...d ? { "x-admin-secret": d } : {},
@@ -25,7 +25,7 @@ const r = (a) => a.data, M = 10, P = 3e3, W = "60000", v = {
25
25
  ...i,
26
26
  headers: Object.keys(s).length > 0 ? s : void 0,
27
27
  body: h
28
- }).then(r);
28
+ }).then(n);
29
29
  }, ae = ({
30
30
  conversationId: a,
31
31
  userToken: c,
@@ -34,20 +34,22 @@ const r = (a) => a.data, M = 10, P = 3e3, W = "60000", v = {
34
34
  adminSecret: h
35
35
  }) => {
36
36
  let t = 0, i = null;
37
- const s = $(), m = () => {
37
+ const s = $();
38
+ let f = a;
39
+ const e = () => {
38
40
  i && i.close();
39
- const n = `${`${o || l.getConfig().baseUrl}/${d}`}/initialize${a ? `?conversationId=${a}` : ""}`, g = {
41
+ const g = `${`${o || l.getConfig().baseUrl}/${d}`}/initialize${f ? `?conversationId=${f}` : ""}`, v = {
40
42
  ...h ? { "x-admin-secret": h } : {},
41
43
  ...c ? { "x-user-key": c } : {}
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 = L(g, v), i.addEventListener("open", () => s.emit("open")), i.addEventListener("error", (u) => {
46
+ t < M ? (t++, setTimeout(() => e(), P)) : s.emit("error", u);
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
50
  });
49
51
  };
50
- return m(), s.on;
52
+ return e(), s.on;
51
53
  }, oe = async ({
52
54
  adminSecret: a,
53
55
  expiresAt: c,
@@ -56,16 +58,16 @@ const r = (a) => a.data, M = 10, P = 3e3, W = "60000", v = {
56
58
  clientId: h
57
59
  }) => {
58
60
  const t = { "x-admin-secret": a }, i = `${o || l.getConfig().baseUrl}/${h}`, s = {
59
- ...v,
61
+ ...m,
60
62
  baseUrl: i
61
63
  };
62
- return b({ ...s, headers: t, body: { id: d, expiresAt: c } }).then(r);
64
+ return C({ ...s, headers: t, body: { id: d, expiresAt: c } }).then(n);
63
65
  }, ie = async (a, c, d, o) => {
64
66
  const h = `${d || l.getConfig().baseUrl}/${a}`, t = {
65
- ...v,
67
+ ...m,
66
68
  baseUrl: h
67
69
  };
68
- return F({ ...t, body: c, headers: o }).then(r);
70
+ return F({ ...t, body: c, headers: o }).then(n);
69
71
  }, ce = ({
70
72
  userKey: a,
71
73
  clientId: c,
@@ -77,50 +79,50 @@ const r = (a) => a.data, M = 10, P = 3e3, W = "60000", v = {
77
79
  "x-user-key": a,
78
80
  ...o
79
81
  }, i = `${d || l.getConfig().baseUrl}/${c}`, s = {
80
- ...v,
82
+ ...m,
81
83
  baseUrl: i
82
84
  };
83
- return l.interceptors.response._fns.length === 0 && l.interceptors.response.use(C), {
84
- createConversation: () => O({ ...s, headers: t, body: {} }).then(r),
85
- getConversation: ({ conversationId: e }) => H({ ...s, headers: t, path: { id: e } }).then(r),
86
- deleteConversation: ({ conversationId: e }) => G({ ...s, headers: t, path: { id: e } }).then(r),
87
- listConversations: ({ nextToken: e }) => B({ ...s, headers: t, query: { nextToken: e } }).then(r),
88
- listConversationMessages: ({ conversationId: e, nextToken: n }) => Y({
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({
89
91
  ...s,
90
92
  headers: t,
91
93
  path: { id: e },
92
- query: { nextToken: n }
93
- }).then(r),
94
- addParticipant: ({ conversationId: e, userId: n }) => X({ ...s, headers: t, path: { id: e }, body: { userId: n } }).then(r),
95
- removeParticipant: ({ conversationId: e, userId: n }) => V({ ...s, headers: t, path: { id: e, userId: n } }).then(r),
96
- getParticipant: ({ conversationId: e, userId: n }) => D({ ...s, headers: t, path: { id: e, userId: n } }).then(r),
97
- listParticipants: ({ conversationId: e, nextToken: n }) => j({ ...s, headers: t, path: { id: e }, query: { nextToken: n } }).then(r),
98
- createMessage: (e) => J({ ...s, headers: t, body: e }).then(r),
99
- updateMessage: ({ messageId: e, ...n }) => A({ ...s, headers: t, path: { id: e }, body: n }).then(r),
100
- getMessage: ({ messageId: e }) => z({ ...s, headers: t, path: { id: e } }).then(r),
101
- deleteMessage: ({ messageId: e }) => N({ ...s, headers: t, path: { id: e } }).then(r),
102
- createFile: (e) => q({ ...s, headers: t, body: e }).then(r),
103
- 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),
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),
111
113
  listenConversation: ({ conversationId: e }) => {
112
- let n = 0, g = null;
113
- const p = $(), u = () => {
114
+ let r = 0, g = null;
115
+ const v = $(), u = () => {
114
116
  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);
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);
122
+ v.emit(y.type, y.data);
121
123
  });
122
124
  };
123
- return u(), p.on;
125
+ return u(), v.on;
124
126
  }
125
127
  };
126
128
  }, x = (a) => {
@@ -141,7 +143,7 @@ const r = (a) => a.data, M = 10, P = 3e3, W = "60000", v = {
141
143
  });
142
144
  export {
143
145
  ce as createClient,
144
- ne as createUser,
146
+ re as createUser,
145
147
  oe as generateUserKey,
146
148
  ae as initialize,
147
149
  ie as sendPerfMetrics
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/webchat-client",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
@@ -30,7 +30,7 @@
30
30
  "eventsource": "^3.0.6"
31
31
  },
32
32
  "devDependencies": {
33
- "@bpinternal/webchat-http-client": "0.10.0",
33
+ "@bpinternal/webchat-http-client": "0.11.0",
34
34
  "@hey-api/client-fetch": "^0.10.0",
35
35
  "@hey-api/openapi-ts": "^0.66.4",
36
36
  "@repo/eslint-config": "workspace:*",
@@ -142,6 +142,7 @@ 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
145
146
 
146
147
  const connect = () => {
147
148
  if (eventSource) {
@@ -149,7 +150,7 @@ export const initialize = ({
149
150
  }
150
151
 
151
152
  const baseUrl = `${apiUrl || baseClient.getConfig().baseUrl}/${clientId}`
152
- const url = `${baseUrl}/initialize${conversationId ? `?conversationId=${conversationId}` : ''}`
153
+ const url = `${baseUrl}/initialize${resolvedConversationId ? `?conversationId=${resolvedConversationId}` : ''}`
153
154
 
154
155
  const headers = {
155
156
  ...(adminSecret ? { 'x-admin-secret': adminSecret } : {}),
@@ -169,9 +170,16 @@ export const initialize = ({
169
170
  })
170
171
  eventSource.addEventListener('message', (ev) => {
171
172
  const event = safeJsonParse(ev.data) as Signal
173
+
174
+ // Save this conversationId for future reconnections in case of a connection error retry
175
+ if (event.type === 'init') {
176
+ resolvedConversationId = event.data.conversation.id ?? resolvedConversationId
177
+ }
178
+
172
179
  eventEmitter.emit(event.type, event.data)
173
180
  })
174
181
  }
182
+
175
183
  connect()
176
184
  return eventEmitter.on
177
185
  }