@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.
- package/.turbo/turbo-build.log +4 -4
- package/dist/webchat-client2.js +79 -79
- package/package.json +1 -1
- package/src/client/client.ts +5 -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,149 +1,149 @@
|
|
|
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
4
|
import { throwErrorInterceptor as b } from "./webchat-client6.js";
|
|
5
5
|
import { createEventEmitter as $ } from "./webchat-client7.js";
|
|
6
|
-
const
|
|
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 = `${
|
|
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
|
-
...
|
|
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:
|
|
28
|
-
}).then(
|
|
27
|
+
body: d
|
|
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
37
|
const s = $();
|
|
38
|
-
let f = a;
|
|
39
|
-
const
|
|
38
|
+
let f = a, e = h;
|
|
39
|
+
const n = () => {
|
|
40
40
|
i && i.close();
|
|
41
|
-
const
|
|
42
|
-
...
|
|
43
|
-
...
|
|
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 =
|
|
46
|
-
t < M ? (t++, setTimeout(() =>
|
|
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
|
|
49
|
-
|
|
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
|
|
52
|
+
return n(), s.on;
|
|
53
53
|
}, oe = async ({
|
|
54
54
|
adminSecret: a,
|
|
55
|
-
expiresAt:
|
|
56
|
-
userId:
|
|
55
|
+
expiresAt: h,
|
|
56
|
+
userId: c,
|
|
57
57
|
apiUrl: o,
|
|
58
|
-
clientId:
|
|
58
|
+
clientId: d
|
|
59
59
|
}) => {
|
|
60
|
-
const t = { "x-admin-secret": a }, i = `${o || l.getConfig().baseUrl}/${
|
|
61
|
-
...
|
|
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:
|
|
65
|
-
}, ie = async (a,
|
|
66
|
-
const
|
|
67
|
-
...
|
|
68
|
-
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
|
|
69
69
|
};
|
|
70
|
-
return
|
|
70
|
+
return L({ ...t, body: h, headers: o }).then(r);
|
|
71
71
|
}, ce = ({
|
|
72
72
|
userKey: a,
|
|
73
|
-
clientId:
|
|
74
|
-
apiUrl:
|
|
73
|
+
clientId: h,
|
|
74
|
+
apiUrl: c,
|
|
75
75
|
customHeaders: o,
|
|
76
|
-
advancedOptions:
|
|
76
|
+
advancedOptions: d
|
|
77
77
|
}) => {
|
|
78
78
|
const t = {
|
|
79
79
|
"x-user-key": a,
|
|
80
80
|
...o
|
|
81
|
-
}, i = `${
|
|
82
|
-
...
|
|
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(
|
|
87
|
-
getConversation: ({ conversationId: e }) => H({ ...s, headers: t, path: { id: e } }).then(
|
|
88
|
-
deleteConversation: ({ conversationId: e }) => G({ ...s, headers: t, path: { id: e } }).then(
|
|
89
|
-
listConversations: ({ nextToken: e }) => B({ ...s, headers: t, query: { nextToken: e } }).then(
|
|
90
|
-
listConversationMessages: ({ conversationId: e, nextToken:
|
|
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:
|
|
95
|
-
}).then(
|
|
96
|
-
addParticipant: ({ conversationId: e, userId:
|
|
97
|
-
removeParticipant: ({ conversationId: e, userId:
|
|
98
|
-
getParticipant: ({ conversationId: e, userId:
|
|
99
|
-
listParticipants: ({ conversationId: e, nextToken:
|
|
100
|
-
createMessage: (e) => J({ ...s, headers: t, body: e }).then(
|
|
101
|
-
updateMessage: ({ messageId: e, ...
|
|
102
|
-
getMessage: ({ messageId: e }) => z({ ...s, headers: t, path: { id: e } }).then(
|
|
103
|
-
deleteMessage: ({ messageId: e }) => N({ ...s, headers: t, path: { id: e } }).then(
|
|
104
|
-
createFile: (e) => q({ ...s, headers: t, body: e }).then(
|
|
105
|
-
getUser: () => _({ ...s, headers: t }).then(
|
|
106
|
-
updateUser: (e) =>
|
|
107
|
-
deleteUser: () =>
|
|
108
|
-
createEvent: (e) =>
|
|
109
|
-
getEvent: ({ eventId: e }) =>
|
|
110
|
-
addMessageFeedback: ({ messageId: e, ...
|
|
111
|
-
removeMessageFeedback: ({ messageId: e }) =>
|
|
112
|
-
generateUserKey: ({ adminSecret: e, ...
|
|
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
|
|
115
|
-
const v = $(),
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}),
|
|
121
|
-
const y =
|
|
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
|
|
125
|
+
return m(), v.on;
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
|
-
},
|
|
128
|
+
}, k = (a) => {
|
|
129
129
|
try {
|
|
130
130
|
return JSON.parse(a);
|
|
131
131
|
} catch {
|
|
132
132
|
return a;
|
|
133
133
|
}
|
|
134
|
-
},
|
|
135
|
-
fetch: (
|
|
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
|
-
...
|
|
139
|
+
...h,
|
|
140
140
|
timeout: W
|
|
141
141
|
}
|
|
142
142
|
})
|
|
143
143
|
});
|
|
144
144
|
export {
|
|
145
145
|
ce as createClient,
|
|
146
|
-
|
|
146
|
+
ne as createUser,
|
|
147
147
|
oe as generateUserKey,
|
|
148
148
|
ae as initialize,
|
|
149
149
|
ie as sendPerfMetrics
|
package/package.json
CHANGED
package/src/client/client.ts
CHANGED
|
@@ -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
|
-
...(
|
|
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
|
|
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)
|