@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.
- package/.turbo/turbo-build.log +4 -4
- package/dist/webchat-client2.js +65 -63
- package/package.json +1 -1
- package/src/client/client.ts +13 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/webchat-client@0.7.
|
|
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
|
[2mdist/[22m[36mwebchat-client7.js [39m[1m[2m 0.45 kB[22m[1m[22m[2m │ gzip: 0.26 kB[22m
|
|
19
19
|
[2mdist/[22m[36mwebchat-client9.js [39m[1m[2m 2.66 kB[22m[1m[22m[2m │ gzip: 1.17 kB[22m
|
|
20
20
|
[2mdist/[22m[36mwebchat-client3.js [39m[1m[2m 3.50 kB[22m[1m[22m[2m │ gzip: 0.60 kB[22m
|
|
21
|
-
[2mdist/[22m[36mwebchat-client2.js [39m[1m[2m 5.
|
|
21
|
+
[2mdist/[22m[36mwebchat-client2.js [39m[1m[2m 5.97 kB[22m[1m[22m[2m │ gzip: 1.69 kB[22m
|
|
22
22
|
[2mdist/[22m[36mwebchat-client10.js [39m[1m[2m 8.58 kB[22m[1m[22m[2m │ gzip: 2.91 kB[22m
|
|
23
23
|
[2mdist/[22m[36mwebchat-client5.js [39m[1m[2m10.93 kB[22m[1m[22m[2m │ gzip: 3.47 kB[22m
|
|
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
|
|
27
|
+
[vite:dts] Declaration files built in 6001ms.
|
|
28
28
|
|
|
29
|
-
[32m✓ built in 6.
|
|
29
|
+
[32m✓ built in 6.31s[39m
|
package/dist/webchat-client2.js
CHANGED
|
@@ -1,86 +1,88 @@
|
|
|
1
|
-
import { createUser as
|
|
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
|
|
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",
|
|
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:
|
|
11
|
-
adminSecret:
|
|
10
|
+
apiUrl: h,
|
|
11
|
+
adminSecret: c,
|
|
12
12
|
customHeaders: o,
|
|
13
|
-
...
|
|
13
|
+
...d
|
|
14
14
|
}) => {
|
|
15
|
-
const t = `${
|
|
16
|
-
l.interceptors.response._fns.length === 0 && l.interceptors.response.use(
|
|
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
|
-
...
|
|
18
|
+
...U,
|
|
19
19
|
baseUrl: t
|
|
20
20
|
}, s = {
|
|
21
|
-
...
|
|
21
|
+
...c ? { "x-admin-secret": c } : {},
|
|
22
22
|
...o
|
|
23
23
|
};
|
|
24
|
-
return
|
|
24
|
+
return T({
|
|
25
25
|
...i,
|
|
26
26
|
headers: Object.keys(s).length > 0 ? s : void 0,
|
|
27
|
-
body:
|
|
27
|
+
body: d
|
|
28
28
|
}).then(r);
|
|
29
29
|
}, ae = ({
|
|
30
30
|
conversationId: a,
|
|
31
|
-
userToken:
|
|
32
|
-
clientId:
|
|
31
|
+
userToken: h,
|
|
32
|
+
clientId: c,
|
|
33
33
|
apiUrl: o,
|
|
34
|
-
adminSecret:
|
|
34
|
+
adminSecret: d
|
|
35
35
|
}) => {
|
|
36
36
|
let t = 0, i = null;
|
|
37
|
-
const s = $()
|
|
37
|
+
const s = $();
|
|
38
|
+
let f = a, e = h;
|
|
39
|
+
const n = () => {
|
|
38
40
|
i && i.close();
|
|
39
|
-
const
|
|
40
|
-
...
|
|
41
|
-
...
|
|
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 =
|
|
44
|
-
t < M ? (t++, setTimeout(() =>
|
|
45
|
-
}), i.addEventListener("message", (
|
|
46
|
-
const
|
|
47
|
-
s.emit(
|
|
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
|
|
52
|
+
return n(), s.on;
|
|
51
53
|
}, oe = async ({
|
|
52
54
|
adminSecret: a,
|
|
53
|
-
expiresAt:
|
|
54
|
-
userId:
|
|
55
|
+
expiresAt: h,
|
|
56
|
+
userId: c,
|
|
55
57
|
apiUrl: o,
|
|
56
|
-
clientId:
|
|
58
|
+
clientId: d
|
|
57
59
|
}) => {
|
|
58
|
-
const t = { "x-admin-secret": a }, i = `${o || l.getConfig().baseUrl}/${
|
|
59
|
-
...
|
|
60
|
+
const t = { "x-admin-secret": a }, i = `${o || l.getConfig().baseUrl}/${d}`, s = {
|
|
61
|
+
...U,
|
|
60
62
|
baseUrl: i
|
|
61
63
|
};
|
|
62
|
-
return
|
|
63
|
-
}, ie = async (a,
|
|
64
|
-
const
|
|
65
|
-
...
|
|
66
|
-
baseUrl:
|
|
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
|
|
70
|
+
return L({ ...t, body: h, headers: o }).then(r);
|
|
69
71
|
}, ce = ({
|
|
70
72
|
userKey: a,
|
|
71
|
-
clientId:
|
|
72
|
-
apiUrl:
|
|
73
|
+
clientId: h,
|
|
74
|
+
apiUrl: c,
|
|
73
75
|
customHeaders: o,
|
|
74
|
-
advancedOptions:
|
|
76
|
+
advancedOptions: d
|
|
75
77
|
}) => {
|
|
76
78
|
const t = {
|
|
77
79
|
"x-user-key": a,
|
|
78
80
|
...o
|
|
79
|
-
}, i = `${
|
|
80
|
-
...
|
|
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(
|
|
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) =>
|
|
105
|
-
deleteUser: () =>
|
|
106
|
-
createEvent: (e) =>
|
|
107
|
-
getEvent: ({ eventId: e }) =>
|
|
108
|
-
addMessageFeedback: ({ messageId: e, ...n }) =>
|
|
109
|
-
removeMessageFeedback: ({ messageId: e }) =>
|
|
110
|
-
generateUserKey: ({ adminSecret: e, ...n }) =>
|
|
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,
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
n < M ? (n++, setTimeout(() =>
|
|
118
|
-
}),
|
|
119
|
-
const y =
|
|
120
|
-
|
|
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
|
|
125
|
+
return m(), v.on;
|
|
124
126
|
}
|
|
125
127
|
};
|
|
126
|
-
},
|
|
128
|
+
}, k = (a) => {
|
|
127
129
|
try {
|
|
128
130
|
return JSON.parse(a);
|
|
129
131
|
} catch {
|
|
130
132
|
return a;
|
|
131
133
|
}
|
|
132
|
-
},
|
|
133
|
-
fetch: (
|
|
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
|
-
...
|
|
139
|
+
...h,
|
|
138
140
|
timeout: W
|
|
139
141
|
}
|
|
140
142
|
})
|
package/package.json
CHANGED
package/src/client/client.ts
CHANGED
|
@@ -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${
|
|
154
|
+
const url = `${baseUrl}/initialize${resolvedConversationId ? `?conversationId=${resolvedConversationId}` : ''}`
|
|
153
155
|
|
|
154
156
|
const headers = {
|
|
155
157
|
...(adminSecret ? { 'x-admin-secret': adminSecret } : {}),
|
|
156
|
-
...(
|
|
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
|
}
|