@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.
- package/.turbo/turbo-build.log +4 -4
- package/dist/index.d.ts +18 -0
- package/dist/webchat-client2.js +57 -55
- package/package.json +2 -2
- package/src/client/client.ts +9 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/webchat-client@0.
|
|
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
|
[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.93 kB[22m[1m[22m[2m │ gzip: 1.68 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 6171ms.
|
|
28
28
|
|
|
29
|
-
[32m✓ built in 6.
|
|
29
|
+
[32m✓ built in 6.50s[39m
|
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
|
*/
|
package/dist/webchat-client2.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createUser as k, generateUserKey as
|
|
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
|
|
4
|
+
import { throwErrorInterceptor as b } from "./webchat-client6.js";
|
|
5
5
|
import { createEventEmitter as $ } from "./webchat-client7.js";
|
|
6
|
-
const
|
|
6
|
+
const n = (a) => a.data, M = 10, P = 3e3, W = "60000", m = {
|
|
7
7
|
throwOnError: !0
|
|
8
|
-
},
|
|
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(
|
|
16
|
+
l.interceptors.response._fns.length === 0 && l.interceptors.response.use(b);
|
|
17
17
|
const i = {
|
|
18
|
-
...
|
|
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(
|
|
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 = $()
|
|
37
|
+
const s = $();
|
|
38
|
+
let f = a;
|
|
39
|
+
const e = () => {
|
|
38
40
|
i && i.close();
|
|
39
|
-
const
|
|
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(
|
|
44
|
-
t < M ? (t++, setTimeout(() =>
|
|
45
|
-
}), i.addEventListener("message", (
|
|
46
|
-
const
|
|
47
|
-
s.emit(
|
|
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
|
|
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
|
-
...
|
|
61
|
+
...m,
|
|
60
62
|
baseUrl: i
|
|
61
63
|
};
|
|
62
|
-
return
|
|
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
|
-
...
|
|
67
|
+
...m,
|
|
66
68
|
baseUrl: h
|
|
67
69
|
};
|
|
68
|
-
return F({ ...t, body: c, headers: o }).then(
|
|
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
|
-
...
|
|
82
|
+
...m,
|
|
81
83
|
baseUrl: i
|
|
82
84
|
};
|
|
83
|
-
return l.interceptors.response._fns.length === 0 && l.interceptors.response.use(
|
|
84
|
-
createConversation: () => O({ ...s, headers: t, body: {} }).then(
|
|
85
|
-
getConversation: ({ conversationId: e }) => H({ ...s, headers: t, path: { id: e } }).then(
|
|
86
|
-
deleteConversation: ({ conversationId: e }) => G({ ...s, headers: t, path: { id: e } }).then(
|
|
87
|
-
listConversations: ({ nextToken: e }) => B({ ...s, headers: t, query: { nextToken: e } }).then(
|
|
88
|
-
listConversationMessages: ({ conversationId: e, nextToken:
|
|
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:
|
|
93
|
-
}).then(
|
|
94
|
-
addParticipant: ({ conversationId: e, userId:
|
|
95
|
-
removeParticipant: ({ conversationId: e, userId:
|
|
96
|
-
getParticipant: ({ conversationId: e, userId:
|
|
97
|
-
listParticipants: ({ conversationId: e, nextToken:
|
|
98
|
-
createMessage: (e) => J({ ...s, headers: t, body: e }).then(
|
|
99
|
-
updateMessage: ({ messageId: e, ...
|
|
100
|
-
getMessage: ({ messageId: e }) => z({ ...s, headers: t, path: { id: e } }).then(
|
|
101
|
-
deleteMessage: ({ messageId: e }) => N({ ...s, headers: t, path: { id: e } }).then(
|
|
102
|
-
createFile: (e) => q({ ...s, headers: t, body: e }).then(
|
|
103
|
-
getUser: () => _({ ...s, headers: t }).then(
|
|
104
|
-
updateUser: (e) => K({ ...s, headers: t, body: e }).then(
|
|
105
|
-
deleteUser: () =>
|
|
106
|
-
createEvent: (e) =>
|
|
107
|
-
getEvent: ({ eventId: e }) =>
|
|
108
|
-
addMessageFeedback: ({ messageId: e, ...
|
|
109
|
-
removeMessageFeedback: ({ messageId: e }) =>
|
|
110
|
-
generateUserKey: ({ adminSecret: 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),
|
|
111
113
|
listenConversation: ({ conversationId: e }) => {
|
|
112
|
-
let
|
|
113
|
-
const
|
|
114
|
+
let r = 0, g = null;
|
|
115
|
+
const v = $(), u = () => {
|
|
114
116
|
g && g.close();
|
|
115
|
-
const
|
|
116
|
-
g = E ? E({ url:
|
|
117
|
-
|
|
118
|
-
}), g.addEventListener("message", (
|
|
119
|
-
const y = x(
|
|
120
|
-
|
|
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(),
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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:*",
|
package/src/client/client.ts
CHANGED
|
@@ -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${
|
|
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
|
}
|