@botpress/webchat-client 0.5.0 → 0.6.0
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 +12 -1
- package/dist/webchat-client2.js +96 -95
- package/package.json +1 -1
- package/src/client/client.ts +24 -14
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/webchat-client@0.
|
|
2
|
+
> @botpress/webchat-client@0.6.0 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.86 kB[22m[1m[22m[2m │ gzip: 1.64 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 5892ms.
|
|
28
28
|
|
|
29
|
-
[32m✓ built in 6.
|
|
29
|
+
[32m✓ built in 6.19s[39m
|
package/dist/index.d.ts
CHANGED
|
@@ -666,11 +666,17 @@ declare type ConversationIdParam = {
|
|
|
666
666
|
conversationId: string;
|
|
667
667
|
};
|
|
668
668
|
|
|
669
|
-
export declare const createClient: ({ userKey, clientId, apiUrl, customHeaders, }: {
|
|
669
|
+
export declare const createClient: ({ userKey, clientId, apiUrl, customHeaders, advancedOptions, }: {
|
|
670
670
|
userKey: string;
|
|
671
671
|
clientId: string;
|
|
672
672
|
apiUrl?: string;
|
|
673
673
|
customHeaders?: Record<string, string>;
|
|
674
|
+
advancedOptions?: {
|
|
675
|
+
eventSource?: (params: {
|
|
676
|
+
url: string;
|
|
677
|
+
headers: Record<string, string>;
|
|
678
|
+
}) => EventSourceLike;
|
|
679
|
+
};
|
|
674
680
|
}) => Client;
|
|
675
681
|
|
|
676
682
|
/**
|
|
@@ -1357,6 +1363,11 @@ declare type EventMap = {
|
|
|
1357
1363
|
[E in Event_3 as E['type']]: E['data'];
|
|
1358
1364
|
};
|
|
1359
1365
|
|
|
1366
|
+
declare interface EventSourceLike {
|
|
1367
|
+
close(): void;
|
|
1368
|
+
addEventListener(event: string, handler: (event: any) => void): void;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1360
1371
|
declare type File_2 = {
|
|
1361
1372
|
id: string;
|
|
1362
1373
|
botId: string;
|
package/dist/webchat-client2.js
CHANGED
|
@@ -1,147 +1,148 @@
|
|
|
1
|
-
import { createUser as
|
|
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";
|
|
2
2
|
import { client as l } from "./webchat-client4.js";
|
|
3
|
-
import { EventSource as
|
|
4
|
-
import { throwErrorInterceptor as
|
|
5
|
-
import { createEventEmitter as
|
|
6
|
-
const
|
|
3
|
+
import { EventSource as Q } from "./webchat-client5.js";
|
|
4
|
+
import { throwErrorInterceptor as C } from "./webchat-client6.js";
|
|
5
|
+
import { createEventEmitter as $ } from "./webchat-client7.js";
|
|
6
|
+
const r = (a) => a.data, M = 10, P = 3e3, W = "60000", v = {
|
|
7
7
|
throwOnError: !0
|
|
8
|
-
},
|
|
8
|
+
}, ne = async ({
|
|
9
9
|
clientId: a,
|
|
10
10
|
apiUrl: c,
|
|
11
|
-
adminSecret:
|
|
11
|
+
adminSecret: d,
|
|
12
12
|
customHeaders: o,
|
|
13
|
-
...
|
|
13
|
+
...h
|
|
14
14
|
}) => {
|
|
15
|
-
const
|
|
16
|
-
l.interceptors.response._fns.length === 0 && l.interceptors.response.use(
|
|
17
|
-
const
|
|
15
|
+
const t = `${c || l.getConfig().baseUrl}/${a}`;
|
|
16
|
+
l.interceptors.response._fns.length === 0 && l.interceptors.response.use(C);
|
|
17
|
+
const i = {
|
|
18
18
|
...v,
|
|
19
|
-
baseUrl:
|
|
20
|
-
},
|
|
21
|
-
...
|
|
19
|
+
baseUrl: t
|
|
20
|
+
}, s = {
|
|
21
|
+
...d ? { "x-admin-secret": d } : {},
|
|
22
22
|
...o
|
|
23
23
|
};
|
|
24
|
-
return
|
|
25
|
-
...
|
|
26
|
-
headers: Object.keys(
|
|
27
|
-
body:
|
|
28
|
-
}).then(
|
|
29
|
-
},
|
|
24
|
+
return k({
|
|
25
|
+
...i,
|
|
26
|
+
headers: Object.keys(s).length > 0 ? s : void 0,
|
|
27
|
+
body: h
|
|
28
|
+
}).then(r);
|
|
29
|
+
}, ae = ({
|
|
30
30
|
conversationId: a,
|
|
31
31
|
userToken: c,
|
|
32
|
-
clientId:
|
|
32
|
+
clientId: d,
|
|
33
33
|
apiUrl: o,
|
|
34
|
-
adminSecret:
|
|
34
|
+
adminSecret: h
|
|
35
35
|
}) => {
|
|
36
|
-
let
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
...
|
|
36
|
+
let t = 0, i = null;
|
|
37
|
+
const s = $(), m = () => {
|
|
38
|
+
i && i.close();
|
|
39
|
+
const n = `${`${o || l.getConfig().baseUrl}/${d}`}/initialize${a ? `?conversationId=${a}` : ""}`, g = {
|
|
40
|
+
...h ? { "x-admin-secret": h } : {},
|
|
41
41
|
...c ? { "x-user-key": c } : {}
|
|
42
42
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
};
|
|
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);
|
|
48
|
+
});
|
|
49
49
|
};
|
|
50
|
-
return
|
|
51
|
-
},
|
|
50
|
+
return m(), s.on;
|
|
51
|
+
}, oe = async ({
|
|
52
52
|
adminSecret: a,
|
|
53
53
|
expiresAt: c,
|
|
54
|
-
userId:
|
|
54
|
+
userId: d,
|
|
55
55
|
apiUrl: o,
|
|
56
|
-
clientId:
|
|
56
|
+
clientId: h
|
|
57
57
|
}) => {
|
|
58
|
-
const
|
|
58
|
+
const t = { "x-admin-secret": a }, i = `${o || l.getConfig().baseUrl}/${h}`, s = {
|
|
59
59
|
...v,
|
|
60
|
-
baseUrl:
|
|
60
|
+
baseUrl: i
|
|
61
61
|
};
|
|
62
|
-
return
|
|
63
|
-
},
|
|
64
|
-
const
|
|
62
|
+
return b({ ...s, headers: t, body: { id: d, expiresAt: c } }).then(r);
|
|
63
|
+
}, ie = async (a, c, d, o) => {
|
|
64
|
+
const h = `${d || l.getConfig().baseUrl}/${a}`, t = {
|
|
65
65
|
...v,
|
|
66
|
-
baseUrl:
|
|
66
|
+
baseUrl: h
|
|
67
67
|
};
|
|
68
|
-
return
|
|
69
|
-
},
|
|
68
|
+
return F({ ...t, body: c, headers: o }).then(r);
|
|
69
|
+
}, ce = ({
|
|
70
70
|
userKey: a,
|
|
71
71
|
clientId: c,
|
|
72
|
-
apiUrl:
|
|
73
|
-
customHeaders: o
|
|
72
|
+
apiUrl: d,
|
|
73
|
+
customHeaders: o,
|
|
74
|
+
advancedOptions: h
|
|
74
75
|
}) => {
|
|
75
|
-
const
|
|
76
|
+
const t = {
|
|
76
77
|
"x-user-key": a,
|
|
77
78
|
...o
|
|
78
|
-
},
|
|
79
|
+
}, i = `${d || l.getConfig().baseUrl}/${c}`, s = {
|
|
79
80
|
...v,
|
|
80
|
-
baseUrl:
|
|
81
|
+
baseUrl: i
|
|
81
82
|
};
|
|
82
|
-
return l.interceptors.response._fns.length === 0 && l.interceptors.response.use(
|
|
83
|
-
createConversation: () =>
|
|
84
|
-
getConversation: ({ conversationId: e }) =>
|
|
85
|
-
deleteConversation: ({ conversationId: e }) =>
|
|
86
|
-
listConversations: ({ nextToken: e }) =>
|
|
87
|
-
listConversationMessages: ({ conversationId: e, nextToken:
|
|
88
|
-
...
|
|
89
|
-
headers:
|
|
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({
|
|
89
|
+
...s,
|
|
90
|
+
headers: t,
|
|
90
91
|
path: { id: e },
|
|
91
|
-
query: { nextToken:
|
|
92
|
-
}).then(
|
|
93
|
-
addParticipant: ({ conversationId: e, userId:
|
|
94
|
-
removeParticipant: ({ conversationId: e, userId:
|
|
95
|
-
getParticipant: ({ conversationId: e, userId:
|
|
96
|
-
listParticipants: ({ conversationId: e, nextToken:
|
|
97
|
-
createMessage: (e) =>
|
|
98
|
-
updateMessage: ({ messageId: e, ...
|
|
99
|
-
getMessage: ({ messageId: e }) =>
|
|
100
|
-
deleteMessage: ({ messageId: e }) =>
|
|
101
|
-
createFile: (e) =>
|
|
102
|
-
getUser: () =>
|
|
103
|
-
updateUser: (e) => K({ ...
|
|
104
|
-
deleteUser: () => I({ ...
|
|
105
|
-
createEvent: (e) => w({ ...
|
|
106
|
-
getEvent: ({ eventId: e }) => R({ ...
|
|
107
|
-
addMessageFeedback: ({ messageId: e, ...
|
|
108
|
-
removeMessageFeedback: ({ messageId: e }) =>
|
|
109
|
-
generateUserKey: ({ adminSecret: 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),
|
|
110
111
|
listenConversation: ({ conversationId: e }) => {
|
|
111
|
-
let
|
|
112
|
-
const p =
|
|
112
|
+
let n = 0, g = null;
|
|
113
|
+
const p = $(), u = () => {
|
|
113
114
|
g && g.close();
|
|
114
|
-
const
|
|
115
|
-
g =
|
|
116
|
-
|
|
117
|
-
}, g.
|
|
118
|
-
const
|
|
119
|
-
p.emit(
|
|
120
|
-
};
|
|
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);
|
|
121
|
+
});
|
|
121
122
|
};
|
|
122
123
|
return u(), p.on;
|
|
123
124
|
}
|
|
124
125
|
};
|
|
125
|
-
},
|
|
126
|
+
}, x = (a) => {
|
|
126
127
|
try {
|
|
127
128
|
return JSON.parse(a);
|
|
128
129
|
} catch {
|
|
129
130
|
return a;
|
|
130
131
|
}
|
|
131
|
-
},
|
|
132
|
-
fetch: (
|
|
132
|
+
}, L = (a, c) => new Q(a, {
|
|
133
|
+
fetch: (d, o) => fetch(d, {
|
|
133
134
|
...o,
|
|
134
135
|
headers: {
|
|
135
136
|
...o == null ? void 0 : o.headers,
|
|
136
137
|
...c,
|
|
137
|
-
timeout:
|
|
138
|
+
timeout: W
|
|
138
139
|
}
|
|
139
140
|
})
|
|
140
141
|
});
|
|
141
142
|
export {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
ce as createClient,
|
|
144
|
+
ne as createUser,
|
|
145
|
+
oe as generateUserKey,
|
|
146
|
+
ae as initialize,
|
|
147
|
+
ie as sendPerfMetrics
|
|
147
148
|
};
|
package/package.json
CHANGED
package/src/client/client.ts
CHANGED
|
@@ -6,6 +6,11 @@ import type { Signal } from './types/signals'
|
|
|
6
6
|
import { throwErrorInterceptor } from './interceptor'
|
|
7
7
|
import { createEventEmitter, EventEmitter } from './emitter'
|
|
8
8
|
|
|
9
|
+
interface EventSourceLike {
|
|
10
|
+
close(): void
|
|
11
|
+
addEventListener(event: string, handler: (event: any) => void): void
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
type ConversationIdParam = {
|
|
10
15
|
conversationId: string
|
|
11
16
|
}
|
|
@@ -135,7 +140,7 @@ export const initialize = ({
|
|
|
135
140
|
adminSecret?: string
|
|
136
141
|
}) => {
|
|
137
142
|
let retryCount = 0
|
|
138
|
-
let eventSource:
|
|
143
|
+
let eventSource: EventSourceLike | null = null
|
|
139
144
|
const eventEmitter = createEventEmitter<EventMap>()
|
|
140
145
|
|
|
141
146
|
const connect = () => {
|
|
@@ -153,19 +158,19 @@ export const initialize = ({
|
|
|
153
158
|
|
|
154
159
|
eventSource = createNewEventSource(url, headers)
|
|
155
160
|
|
|
156
|
-
eventSource.
|
|
157
|
-
eventSource.
|
|
161
|
+
eventSource.addEventListener('open', () => eventEmitter.emit('open'))
|
|
162
|
+
eventSource.addEventListener('error', (err) => {
|
|
158
163
|
if (retryCount < MAX_RETRIES) {
|
|
159
164
|
retryCount++
|
|
160
165
|
setTimeout(() => connect(), RETRY_INTERVAL)
|
|
161
166
|
} else {
|
|
162
167
|
eventEmitter.emit('error', err)
|
|
163
168
|
}
|
|
164
|
-
}
|
|
165
|
-
eventSource.
|
|
169
|
+
})
|
|
170
|
+
eventSource.addEventListener('message', (ev) => {
|
|
166
171
|
const event = safeJsonParse(ev.data) as Signal
|
|
167
172
|
eventEmitter.emit(event.type, event.data)
|
|
168
|
-
}
|
|
173
|
+
})
|
|
169
174
|
}
|
|
170
175
|
connect()
|
|
171
176
|
return eventEmitter.on
|
|
@@ -213,11 +218,15 @@ export const createClient = ({
|
|
|
213
218
|
clientId,
|
|
214
219
|
apiUrl,
|
|
215
220
|
customHeaders,
|
|
221
|
+
advancedOptions,
|
|
216
222
|
}: {
|
|
217
223
|
userKey: string
|
|
218
224
|
clientId: string
|
|
219
225
|
apiUrl?: string
|
|
220
226
|
customHeaders?: Record<string, string>
|
|
227
|
+
advancedOptions?: {
|
|
228
|
+
eventSource?: (params: { url: string; headers: Record<string, string> }) => EventSourceLike
|
|
229
|
+
}
|
|
221
230
|
}): Client => {
|
|
222
231
|
const headers = {
|
|
223
232
|
'x-user-key': userKey,
|
|
@@ -282,7 +291,7 @@ export const createClient = ({
|
|
|
282
291
|
sdk.generateUserKey({ ...configs, headers: { 'x-admin-secret': adminSecret }, body }).then(extractData),
|
|
283
292
|
listenConversation: ({ conversationId }) => {
|
|
284
293
|
let retryCount = 0
|
|
285
|
-
let eventSource:
|
|
294
|
+
let eventSource: EventSourceLike | null = null
|
|
286
295
|
const eventEmitter = createEventEmitter<EventMap>()
|
|
287
296
|
|
|
288
297
|
const connect = () => {
|
|
@@ -292,21 +301,22 @@ export const createClient = ({
|
|
|
292
301
|
|
|
293
302
|
const url = `${baseUrl}/conversations/${conversationId}/listen`
|
|
294
303
|
|
|
295
|
-
|
|
304
|
+
const providedEventSource = advancedOptions?.eventSource
|
|
305
|
+
eventSource = providedEventSource ? providedEventSource({ url, headers }) : createNewEventSource(url, headers)
|
|
296
306
|
|
|
297
|
-
eventSource.
|
|
298
|
-
eventSource.
|
|
307
|
+
eventSource.addEventListener('open', () => eventEmitter.emit('open'))
|
|
308
|
+
eventSource.addEventListener('error', (err) => {
|
|
299
309
|
if (retryCount < MAX_RETRIES) {
|
|
300
310
|
retryCount++
|
|
301
311
|
setTimeout(() => connect(), RETRY_INTERVAL)
|
|
302
312
|
} else {
|
|
303
313
|
eventEmitter.emit('error', err)
|
|
304
314
|
}
|
|
305
|
-
}
|
|
306
|
-
eventSource.
|
|
315
|
+
})
|
|
316
|
+
eventSource.addEventListener('message', (ev) => {
|
|
307
317
|
const event = safeJsonParse(ev.data) as Signal
|
|
308
318
|
eventEmitter.emit(event.type, event.data)
|
|
309
|
-
}
|
|
319
|
+
})
|
|
310
320
|
}
|
|
311
321
|
connect()
|
|
312
322
|
return eventEmitter.on
|
|
@@ -324,7 +334,7 @@ const safeJsonParse = (data: any) => {
|
|
|
324
334
|
}
|
|
325
335
|
}
|
|
326
336
|
|
|
327
|
-
const createNewEventSource = (url: string, headers: Record<string, string>) => {
|
|
337
|
+
const createNewEventSource = (url: string, headers: Record<string, string>): EventSourceLike => {
|
|
328
338
|
return new EventSource(url, {
|
|
329
339
|
fetch: (input, init) =>
|
|
330
340
|
fetch(input, {
|