@botpress/webchat-client 0.2.0-beta.1 → 0.2.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 +3 -1
- package/dist/webchat-client2.js +67 -72
- package/package.json +2 -2
- package/src/client/client.ts +12 -17
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/webchat-client@0.2.0
|
|
2
|
+
> @botpress/webchat-client@0.2.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.63 kB[22m[1m[22m[2m │ gzip: 1.15 kB[22m
|
|
20
20
|
[2mdist/[22m[36mwebchat-client3.js [39m[1m[2m 3.30 kB[22m[1m[22m[2m │ gzip: 0.58 kB[22m
|
|
21
|
-
[2mdist/[22m[36mwebchat-client2.js [39m[1m[2m 4.
|
|
21
|
+
[2mdist/[22m[36mwebchat-client2.js [39m[1m[2m 4.75 kB[22m[1m[22m[2m │ gzip: 1.31 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.4.2
|
|
26
26
|
*** The target project appears to use TypeScript 5.6.2 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 5323ms.
|
|
28
28
|
|
|
29
|
-
[32m✓ built in
|
|
29
|
+
[32m✓ built in 5.65s[39m
|
package/dist/index.d.ts
CHANGED
|
@@ -195,7 +195,9 @@ export declare type Client = {
|
|
|
195
195
|
listenConversation: (params: ConversationIdParam) => EventEmitter<Record<Event_3['type'], Event_3['data']>>['on'];
|
|
196
196
|
addMessageFeedback: (params: MessageIdParam & ClientTypes_2.AddMessageFeedbackBody) => Promise<ClientTypes_2.AddMessageFeedbackResponse>;
|
|
197
197
|
removeMessageFeedback: (params: MessageIdParam) => Promise<ClientTypes_2.RemoveMessageFeedbackResponse>;
|
|
198
|
-
generateUserKey: (params: ClientTypes_2.GenerateUserKeyBody
|
|
198
|
+
generateUserKey: (params: ClientTypes_2.GenerateUserKeyBody & {
|
|
199
|
+
adminKey: string;
|
|
200
|
+
}) => Promise<ClientTypes_2.GenerateUserKeyResponse>;
|
|
199
201
|
};
|
|
200
202
|
|
|
201
203
|
declare type Client_2 = Client$1<RequestFn, Config, MethodFn, BuildUrlFn> & {
|
package/dist/webchat-client2.js
CHANGED
|
@@ -1,108 +1,103 @@
|
|
|
1
|
-
import { createUser as
|
|
1
|
+
import { createUser as U, generateUserKey as y, removeMessageFeedback as M, addMessageFeedback as b, getEvent as $, createEvent as R, deleteUser as P, updateUser as k, getUser as T, createFile as _, deleteMessage as x, getMessage as F, updateMessage as I, createMessage as S, listParticipants as A, getParticipant as q, removeParticipant as w, addParticipant as K, listConversationMessages as N, listConversations as J, deleteConversation as L, getConversation as O, createConversation as V } from "./webchat-client3.js";
|
|
2
2
|
import { client as i } from "./webchat-client4.js";
|
|
3
|
-
import { EventSource as
|
|
4
|
-
import { throwErrorInterceptor as
|
|
5
|
-
import { createEventEmitter as
|
|
6
|
-
const n = (a) => a.data,
|
|
3
|
+
import { EventSource as X } from "./webchat-client5.js";
|
|
4
|
+
import { throwErrorInterceptor as E } from "./webchat-client6.js";
|
|
5
|
+
import { createEventEmitter as Y } from "./webchat-client7.js";
|
|
6
|
+
const n = (a) => a.data, v = {
|
|
7
7
|
throwOnError: !0
|
|
8
8
|
}, W = async ({
|
|
9
9
|
clientId: a,
|
|
10
|
-
apiUrl:
|
|
11
|
-
adminKey:
|
|
10
|
+
apiUrl: p,
|
|
11
|
+
adminKey: c
|
|
12
12
|
}) => {
|
|
13
|
-
const
|
|
14
|
-
i.interceptors.response._fns.length === 0 && i.interceptors.response.use(
|
|
13
|
+
const t = `${p || i.getConfig().baseUrl}/${a}`;
|
|
14
|
+
i.interceptors.response._fns.length === 0 && i.interceptors.response.use(E);
|
|
15
15
|
const d = {
|
|
16
|
-
...
|
|
17
|
-
baseUrl:
|
|
18
|
-
}
|
|
16
|
+
...v,
|
|
17
|
+
baseUrl: t
|
|
18
|
+
};
|
|
19
|
+
return U({
|
|
19
20
|
...d,
|
|
20
21
|
body: {},
|
|
21
|
-
headers:
|
|
22
|
-
});
|
|
23
|
-
return n(t);
|
|
22
|
+
headers: c ? { "x-admin-key": c } : void 0
|
|
23
|
+
}).then(n);
|
|
24
24
|
}, Z = async ({
|
|
25
25
|
adminKey: a,
|
|
26
|
-
expiresAt:
|
|
27
|
-
userId:
|
|
28
|
-
apiUrl:
|
|
26
|
+
expiresAt: p,
|
|
27
|
+
userId: c,
|
|
28
|
+
apiUrl: t,
|
|
29
29
|
clientId: d
|
|
30
30
|
}) => {
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const m = `${s || i.getConfig().baseUrl}/${d}`, e = {
|
|
34
|
-
...u,
|
|
31
|
+
const s = { "x-admin-key": a }, m = `${t || i.getConfig().baseUrl}/${d}`, e = {
|
|
32
|
+
...v,
|
|
35
33
|
baseUrl: m
|
|
36
34
|
};
|
|
37
|
-
return
|
|
35
|
+
return y({ ...e, headers: s, body: { id: c, expiresAt: p } }).then(n);
|
|
38
36
|
}, ee = ({
|
|
39
37
|
userKey: a,
|
|
40
|
-
clientId:
|
|
41
|
-
apiUrl:
|
|
38
|
+
clientId: p,
|
|
39
|
+
apiUrl: c
|
|
42
40
|
}) => {
|
|
43
|
-
const
|
|
41
|
+
const t = {
|
|
44
42
|
"x-user-key": a
|
|
45
|
-
}, d = `${
|
|
46
|
-
...
|
|
43
|
+
}, d = `${c || i.getConfig().baseUrl}/${p}`, s = {
|
|
44
|
+
...v,
|
|
47
45
|
baseUrl: d
|
|
48
46
|
};
|
|
49
|
-
return i.interceptors.response._fns.length === 0 && i.interceptors.response.use(
|
|
50
|
-
createConversation: () =>
|
|
51
|
-
getConversation: ({ conversationId: e }) =>
|
|
52
|
-
deleteConversation: ({ conversationId: e }) =>
|
|
53
|
-
listConversations: ({ nextToken: e }) =>
|
|
54
|
-
listConversationMessages: ({ conversationId: e, nextToken: r }) =>
|
|
55
|
-
...
|
|
56
|
-
headers:
|
|
47
|
+
return i.interceptors.response._fns.length === 0 && i.interceptors.response.use(E), {
|
|
48
|
+
createConversation: () => V({ ...s, headers: t, body: {} }).then(n),
|
|
49
|
+
getConversation: ({ conversationId: e }) => O({ ...s, headers: t, path: { id: e } }).then(n),
|
|
50
|
+
deleteConversation: ({ conversationId: e }) => L({ ...s, headers: t, path: { id: e } }).then(n),
|
|
51
|
+
listConversations: ({ nextToken: e }) => J({ ...s, headers: t, query: { nextToken: e } }).then(n),
|
|
52
|
+
listConversationMessages: ({ conversationId: e, nextToken: r }) => N({
|
|
53
|
+
...s,
|
|
54
|
+
headers: t,
|
|
57
55
|
path: { id: e },
|
|
58
56
|
query: { nextToken: r }
|
|
59
57
|
}).then(n),
|
|
60
|
-
addParticipant: ({ conversationId: e, userId: r }) =>
|
|
61
|
-
removeParticipant: ({ conversationId: e, userId: r }) =>
|
|
62
|
-
getParticipant: ({ conversationId: e, userId: r }) => q({ ...
|
|
63
|
-
listParticipants: ({ conversationId: e, nextToken: r }) =>
|
|
64
|
-
createMessage: (e) =>
|
|
65
|
-
updateMessage: ({ messageId: e, ...r }) =>
|
|
66
|
-
getMessage: ({ messageId: e }) =>
|
|
67
|
-
deleteMessage: ({ messageId: e }) => x({ ...
|
|
68
|
-
createFile: (e) =>
|
|
69
|
-
createUser: (e) =>
|
|
70
|
-
getUser: () =>
|
|
71
|
-
updateUser: (e) =>
|
|
72
|
-
deleteUser: () =>
|
|
73
|
-
createEvent: (e) =>
|
|
74
|
-
getEvent: ({ eventId: e }) =>
|
|
75
|
-
addMessageFeedback: ({ messageId: e, ...r }) =>
|
|
76
|
-
removeMessageFeedback: ({ messageId: e }) =>
|
|
77
|
-
generateUserKey:
|
|
78
|
-
const v = r ? { "x-admin-key": r } : void 0;
|
|
79
|
-
return console.log("generateUserKey", e, v), E({ ...t, headers: v, body: e }).then(n);
|
|
80
|
-
},
|
|
58
|
+
addParticipant: ({ conversationId: e, userId: r }) => K({ ...s, headers: t, path: { id: e }, body: { userId: r } }).then(n),
|
|
59
|
+
removeParticipant: ({ conversationId: e, userId: r }) => w({ ...s, headers: t, path: { id: e, userId: r } }).then(n),
|
|
60
|
+
getParticipant: ({ conversationId: e, userId: r }) => q({ ...s, headers: t, path: { id: e, userId: r } }).then(n),
|
|
61
|
+
listParticipants: ({ conversationId: e, nextToken: r }) => A({ ...s, headers: t, path: { id: e }, query: { nextToken: r } }).then(n),
|
|
62
|
+
createMessage: (e) => S({ ...s, headers: t, body: e }).then(n),
|
|
63
|
+
updateMessage: ({ messageId: e, ...r }) => I({ ...s, headers: t, path: { id: e }, body: r }).then(n),
|
|
64
|
+
getMessage: ({ messageId: e }) => F({ ...s, headers: t, path: { id: e } }).then(n),
|
|
65
|
+
deleteMessage: ({ messageId: e }) => x({ ...s, headers: t, path: { id: e } }).then(n),
|
|
66
|
+
createFile: (e) => _({ ...s, headers: t, body: e }).then(n),
|
|
67
|
+
createUser: (e) => U({ ...s, headers: t, body: e }).then(n),
|
|
68
|
+
getUser: () => T({ ...s, headers: t }).then(n),
|
|
69
|
+
updateUser: (e) => k({ ...s, headers: t, body: e }).then(n),
|
|
70
|
+
deleteUser: () => P({ ...s, headers: t }).then(n),
|
|
71
|
+
createEvent: (e) => R({ ...s, headers: t, body: e }).then(n),
|
|
72
|
+
getEvent: ({ eventId: e }) => $({ ...s, headers: t, path: { id: e } }).then(n),
|
|
73
|
+
addMessageFeedback: ({ messageId: e, ...r }) => b({ ...s, headers: t, path: { id: e }, body: r }).then(n),
|
|
74
|
+
removeMessageFeedback: ({ messageId: e }) => M({ ...s, headers: t, path: { id: e } }).then(n),
|
|
75
|
+
generateUserKey: ({ adminKey: e, ...r }) => y({ ...s, headers: { "x-admin-key": e }, body: r }).then(n),
|
|
81
76
|
listenConversation: ({ conversationId: e }) => {
|
|
82
|
-
let
|
|
83
|
-
const l =
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
fetch: (
|
|
88
|
-
...
|
|
77
|
+
let u = 0, h = null;
|
|
78
|
+
const l = Y(), f = () => {
|
|
79
|
+
h && h.close();
|
|
80
|
+
const C = `${d}/conversations/${e}/listen`;
|
|
81
|
+
h = new X(C, {
|
|
82
|
+
fetch: (g, o) => fetch(g, {
|
|
83
|
+
...o,
|
|
89
84
|
headers: {
|
|
90
|
-
...
|
|
91
|
-
...
|
|
85
|
+
...o == null ? void 0 : o.headers,
|
|
86
|
+
...t,
|
|
92
87
|
timeout: "60_000"
|
|
93
88
|
}
|
|
94
89
|
})
|
|
95
|
-
}),
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
const
|
|
99
|
-
l.emit(
|
|
90
|
+
}), h.onopen = () => l.emit("open"), h.onerror = (g) => {
|
|
91
|
+
u < 10 ? (u++, setTimeout(() => f(), 3e3)) : l.emit("error", g);
|
|
92
|
+
}, h.onmessage = (g) => {
|
|
93
|
+
const o = D(g.data);
|
|
94
|
+
l.emit(o.type, o.data);
|
|
100
95
|
};
|
|
101
96
|
};
|
|
102
97
|
return f(), l.on;
|
|
103
98
|
}
|
|
104
99
|
};
|
|
105
|
-
},
|
|
100
|
+
}, D = (a) => {
|
|
106
101
|
try {
|
|
107
102
|
return JSON.parse(a);
|
|
108
103
|
} catch {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/webchat-client",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"eventsource": "^3.0.6"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@bpinternal/webchat-http-client": "0.4.
|
|
29
|
+
"@bpinternal/webchat-http-client": "0.4.1",
|
|
30
30
|
"@hey-api/client-fetch": "^0.10.0",
|
|
31
31
|
"@hey-api/openapi-ts": "^0.66.4",
|
|
32
32
|
"@repo/eslint-config": "workspace:*",
|
package/src/client/client.ts
CHANGED
|
@@ -68,8 +68,7 @@ export type Client = {
|
|
|
68
68
|
) => Promise<ClientTypes.AddMessageFeedbackResponse>
|
|
69
69
|
removeMessageFeedback: (params: MessageIdParam) => Promise<ClientTypes.RemoveMessageFeedbackResponse>
|
|
70
70
|
generateUserKey: (
|
|
71
|
-
params: ClientTypes.GenerateUserKeyBody
|
|
72
|
-
adminKey?: string
|
|
71
|
+
params: ClientTypes.GenerateUserKeyBody & { adminKey: string }
|
|
73
72
|
) => Promise<ClientTypes.GenerateUserKeyResponse>
|
|
74
73
|
}
|
|
75
74
|
|
|
@@ -98,13 +97,13 @@ export const createUser = async ({
|
|
|
98
97
|
baseUrl,
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
100
|
+
return sdk
|
|
101
|
+
.createUser({
|
|
102
|
+
...configs,
|
|
103
|
+
body: {},
|
|
104
|
+
headers: adminKey ? { 'x-admin-key': adminKey } : undefined,
|
|
105
|
+
})
|
|
106
|
+
.then(extractData)
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
export const generateUserKey = async ({
|
|
@@ -121,7 +120,6 @@ export const generateUserKey = async ({
|
|
|
121
120
|
clientId: string
|
|
122
121
|
}) => {
|
|
123
122
|
const headers = { 'x-admin-key': adminKey }
|
|
124
|
-
console.log('generateUserKey', userId, expiresAt, headers)
|
|
125
123
|
|
|
126
124
|
const baseUrl = `${apiUrl || baseClient.getConfig().baseUrl}/${clientId}`
|
|
127
125
|
const configs = {
|
|
@@ -199,11 +197,8 @@ export const createClient = ({
|
|
|
199
197
|
sdk.addMessageFeedback({ ...configs, headers, path: { id: messageId }, body }).then(extractData),
|
|
200
198
|
removeMessageFeedback: ({ messageId }) =>
|
|
201
199
|
sdk.removeMessageFeedback({ ...configs, headers, path: { id: messageId } }).then(extractData),
|
|
202
|
-
generateUserKey:
|
|
203
|
-
|
|
204
|
-
console.log('generateUserKey', body, headers)
|
|
205
|
-
return sdk.generateUserKey({ ...configs, headers, body }).then(extractData)
|
|
206
|
-
},
|
|
200
|
+
generateUserKey: ({ adminKey, ...body }) =>
|
|
201
|
+
sdk.generateUserKey({ ...configs, headers: { 'x-admin-key': adminKey }, body }).then(extractData),
|
|
207
202
|
listenConversation: ({ conversationId }) => {
|
|
208
203
|
const MAX_RETRIES = 10
|
|
209
204
|
const RETRY_INTERVAL = 3000 // ms
|
|
@@ -232,11 +227,11 @@ export const createClient = ({
|
|
|
232
227
|
|
|
233
228
|
eventSource.onopen = () => eventEmitter.emit('open')
|
|
234
229
|
eventSource.onerror = (err) => {
|
|
235
|
-
eventEmitter.emit('error', err)
|
|
236
|
-
|
|
237
230
|
if (retryCount < MAX_RETRIES) {
|
|
238
231
|
retryCount++
|
|
239
232
|
setTimeout(() => connect(), RETRY_INTERVAL)
|
|
233
|
+
} else {
|
|
234
|
+
eventEmitter.emit('error', err)
|
|
240
235
|
}
|
|
241
236
|
}
|
|
242
237
|
eventSource.onmessage = (ev) => {
|