@botpress/webchat-client 0.3.0 → 0.3.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 +6 -6
- package/dist/index.d.ts +83 -9
- package/dist/webchat-client.js +3 -2
- package/dist/webchat-client2.js +112 -95
- package/dist/webchat-client3.js +28 -20
- package/package.json +2 -2
- package/src/client/client.ts +43 -9
- package/src/client/types/signals/initialize.ts +1 -1
- package/src/index.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/webchat-client@0.3.
|
|
2
|
+
> @botpress/webchat-client@0.3.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
|
|
@@ -12,18 +12,18 @@ rendering chunks...
|
|
|
12
12
|
[vite:dts] Start generate declaration files...
|
|
13
13
|
computing gzip size...
|
|
14
14
|
[2mdist/[22m[36mwebchat-client8.js [39m[1m[2m 0.19 kB[22m[1m[22m[2m │ gzip: 0.16 kB[22m
|
|
15
|
-
[2mdist/[22m[36mwebchat-client.js [39m[1m[2m 0.
|
|
15
|
+
[2mdist/[22m[36mwebchat-client.js [39m[1m[2m 0.25 kB[22m[1m[22m[2m │ gzip: 0.16 kB[22m
|
|
16
16
|
[2mdist/[22m[36mwebchat-client4.js [39m[1m[2m 0.29 kB[22m[1m[22m[2m │ gzip: 0.18 kB[22m
|
|
17
17
|
[2mdist/[22m[36mwebchat-client6.js [39m[1m[2m 0.30 kB[22m[1m[22m[2m │ gzip: 0.22 kB[22m
|
|
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
|
-
[2mdist/[22m[36mwebchat-client3.js [39m[1m[2m 3.
|
|
21
|
-
[2mdist/[22m[36mwebchat-client2.js [39m[1m[2m 5.
|
|
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.66 kB[22m[1m[22m[2m │ gzip: 1.60 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 4664ms.
|
|
28
28
|
|
|
29
|
-
[32m✓ built in
|
|
29
|
+
[32m✓ built in 4.95s[39m
|
package/dist/index.d.ts
CHANGED
|
@@ -186,13 +186,12 @@ export declare type Client = {
|
|
|
186
186
|
getMessage: (params: MessageIdParam) => Promise<ClientTypes_2.GetMessageResponse>;
|
|
187
187
|
deleteMessage: (params: MessageIdParam) => Promise<ClientTypes_2.DeleteMessageResponse>;
|
|
188
188
|
createFile: (params: ClientTypes_2.CreateFileBody) => Promise<ClientTypes_2.CreateFileResponse>;
|
|
189
|
-
createUser: (params: ClientTypes_2.CreateUserBody) => Promise<ClientTypes_2.CreateUserResponse>;
|
|
190
189
|
getUser: () => Promise<ClientTypes_2.GetUserResponse>;
|
|
191
190
|
updateUser: (params: ClientTypes_2.CreateUserBody) => Promise<ClientTypes_2.UpdateUserResponse>;
|
|
192
191
|
deleteUser: (params: UserIdParam) => Promise<ClientTypes_2.DeleteUserResponse>;
|
|
193
192
|
createEvent: (params: ClientTypes_2.CreateEventBody) => Promise<ClientTypes_2.CreateEventResponse>;
|
|
194
193
|
getEvent: (params: EventIdParam) => Promise<ClientTypes_2.GetEventResponse>;
|
|
195
|
-
listenConversation: (params: ConversationIdParam) => EventEmitter<
|
|
194
|
+
listenConversation: (params: ConversationIdParam) => EventEmitter<EventMap>['on'];
|
|
196
195
|
addMessageFeedback: (params: MessageIdParam & ClientTypes_2.AddMessageFeedbackBody) => Promise<ClientTypes_2.AddMessageFeedbackResponse>;
|
|
197
196
|
removeMessageFeedback: (params: MessageIdParam) => Promise<ClientTypes_2.RemoveMessageFeedbackResponse>;
|
|
198
197
|
generateUserKey: (params: ClientTypes_2.GenerateUserKeyBody & {
|
|
@@ -220,6 +219,7 @@ declare namespace ClientTypes_2 {
|
|
|
220
219
|
Message,
|
|
221
220
|
Event_2 as Event,
|
|
222
221
|
File_2 as File,
|
|
222
|
+
Perf,
|
|
223
223
|
CreateConversationBody,
|
|
224
224
|
AddParticipantBody,
|
|
225
225
|
CreateMessageBody,
|
|
@@ -231,6 +231,7 @@ declare namespace ClientTypes_2 {
|
|
|
231
231
|
UpdateUserBody,
|
|
232
232
|
CreateEventBody,
|
|
233
233
|
CreateFileBody,
|
|
234
|
+
SendPerfMetricsBody,
|
|
234
235
|
DeleteConversationData,
|
|
235
236
|
DeleteConversationErrors,
|
|
236
237
|
DeleteConversationError,
|
|
@@ -361,6 +362,11 @@ declare namespace ClientTypes_2 {
|
|
|
361
362
|
InitializeConversationError,
|
|
362
363
|
InitializeConversationResponses,
|
|
363
364
|
InitializeConversationResponse,
|
|
365
|
+
SendPerfMetricsData,
|
|
366
|
+
SendPerfMetricsErrors,
|
|
367
|
+
SendPerfMetricsError,
|
|
368
|
+
SendPerfMetricsResponses,
|
|
369
|
+
SendPerfMetricsResponse,
|
|
364
370
|
ClientOptions,
|
|
365
371
|
Options,
|
|
366
372
|
deleteConversation,
|
|
@@ -388,7 +394,8 @@ declare namespace ClientTypes_2 {
|
|
|
388
394
|
getEvent,
|
|
389
395
|
createEvent,
|
|
390
396
|
createFile,
|
|
391
|
-
initializeConversation
|
|
397
|
+
initializeConversation,
|
|
398
|
+
sendPerfMetrics_2 as sendPerfMetrics
|
|
392
399
|
}
|
|
393
400
|
}
|
|
394
401
|
|
|
@@ -495,10 +502,11 @@ declare type ConversationIdParam = {
|
|
|
495
502
|
conversationId: string;
|
|
496
503
|
};
|
|
497
504
|
|
|
498
|
-
export declare const createClient: ({ userKey, clientId, apiUrl, }: {
|
|
505
|
+
export declare const createClient: ({ userKey, clientId, apiUrl, customHeaders, }: {
|
|
499
506
|
userKey: string;
|
|
500
507
|
clientId: string;
|
|
501
508
|
apiUrl?: string;
|
|
509
|
+
customHeaders?: Record<string, string>;
|
|
502
510
|
}) => Client;
|
|
503
511
|
|
|
504
512
|
/**
|
|
@@ -894,11 +902,12 @@ export declare type CreateMessageResponses = {
|
|
|
894
902
|
};
|
|
895
903
|
};
|
|
896
904
|
|
|
897
|
-
export declare const createUser: ({ clientId, apiUrl, adminSecret, }: {
|
|
905
|
+
export declare const createUser: ({ clientId, apiUrl, adminSecret, customHeaders, ...body }: {
|
|
898
906
|
clientId: string;
|
|
899
907
|
apiUrl?: string;
|
|
900
908
|
adminSecret?: string;
|
|
901
|
-
|
|
909
|
+
customHeaders?: Record<string, string>;
|
|
910
|
+
} & ClientTypes_2.CreateUserBody) => Promise<{
|
|
902
911
|
user: ClientTypes_2.User;
|
|
903
912
|
key: string;
|
|
904
913
|
}>;
|
|
@@ -1172,6 +1181,10 @@ declare type EventIdParam = {
|
|
|
1172
1181
|
eventId: string;
|
|
1173
1182
|
};
|
|
1174
1183
|
|
|
1184
|
+
declare type EventMap = {
|
|
1185
|
+
[E in Event_3 as E['type']]: E['data'];
|
|
1186
|
+
};
|
|
1187
|
+
|
|
1175
1188
|
declare type File_2 = {
|
|
1176
1189
|
id: string;
|
|
1177
1190
|
botId: string;
|
|
@@ -1514,17 +1527,18 @@ declare type Initialize = {
|
|
|
1514
1527
|
messages: ListConversationMessagesResponse['messages'];
|
|
1515
1528
|
participants: ListParticipantsResponse['participants'];
|
|
1516
1529
|
user: GetUserResponse['user'] & {
|
|
1517
|
-
userKey
|
|
1530
|
+
userKey: string;
|
|
1518
1531
|
};
|
|
1519
1532
|
};
|
|
1520
1533
|
};
|
|
1521
1534
|
|
|
1522
|
-
export declare const initialize: ({ conversationId, userToken, clientId, apiUrl, }: {
|
|
1535
|
+
export declare const initialize: ({ conversationId, userToken, clientId, apiUrl, adminSecret, }: {
|
|
1523
1536
|
conversationId?: string;
|
|
1524
1537
|
userToken?: string;
|
|
1525
1538
|
apiUrl?: string;
|
|
1526
1539
|
clientId: string;
|
|
1527
|
-
|
|
1540
|
+
adminSecret?: string;
|
|
1541
|
+
}) => <U extends "custom" | "error" | "message_created" | "message_updated" | "typing_started" | "typing_stopped" | "webchat_config" | "webchat_visibility" | "participant_added" | "participant_removed" | "message_status_changed" | "init" | "open">(event: U, callback: (args: EventMap[U]) => void) => () => void;
|
|
1528
1542
|
|
|
1529
1543
|
/**
|
|
1530
1544
|
* Creates a SSE stream to receive messages and events. The first event will be a payload containing the conversation details.
|
|
@@ -2689,6 +2703,12 @@ declare type ParticipantRemoved = {
|
|
|
2689
2703
|
};
|
|
2690
2704
|
};
|
|
2691
2705
|
|
|
2706
|
+
export declare type Perf = {
|
|
2707
|
+
duration: number;
|
|
2708
|
+
event: string;
|
|
2709
|
+
properties: {};
|
|
2710
|
+
};
|
|
2711
|
+
|
|
2692
2712
|
declare type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
2693
2713
|
|
|
2694
2714
|
declare interface QuerySerializerOptions {
|
|
@@ -2897,6 +2917,60 @@ export declare type SelectMessageResponses = {
|
|
|
2897
2917
|
};
|
|
2898
2918
|
};
|
|
2899
2919
|
|
|
2920
|
+
export declare const sendPerfMetrics: (clientId: string, body: ClientTypes_2.SendPerfMetricsBody, apiUrl?: string, customHeaders?: Record<string, string>) => Promise<{
|
|
2921
|
+
[key: string]: never;
|
|
2922
|
+
}>;
|
|
2923
|
+
|
|
2924
|
+
/**
|
|
2925
|
+
* Sends performance metrics to the server.
|
|
2926
|
+
*/
|
|
2927
|
+
declare const sendPerfMetrics_2: <ThrowOnError extends boolean = false>(options?: Options<SendPerfMetricsData, ThrowOnError>) => RequestResult<{
|
|
2928
|
+
[key: string]: never;
|
|
2929
|
+
}, {
|
|
2930
|
+
[key: string]: never;
|
|
2931
|
+
}, ThrowOnError>;
|
|
2932
|
+
|
|
2933
|
+
/**
|
|
2934
|
+
* Performance metrics
|
|
2935
|
+
*/
|
|
2936
|
+
export declare type SendPerfMetricsBody = {
|
|
2937
|
+
duration: number;
|
|
2938
|
+
event: string;
|
|
2939
|
+
properties: {};
|
|
2940
|
+
};
|
|
2941
|
+
|
|
2942
|
+
export declare type SendPerfMetricsData = {
|
|
2943
|
+
/**
|
|
2944
|
+
* Performance metrics
|
|
2945
|
+
*/
|
|
2946
|
+
body?: SendPerfMetricsBody;
|
|
2947
|
+
path?: never;
|
|
2948
|
+
query?: never;
|
|
2949
|
+
url: '/p';
|
|
2950
|
+
};
|
|
2951
|
+
|
|
2952
|
+
export declare type SendPerfMetricsError = SendPerfMetricsErrors[keyof SendPerfMetricsErrors];
|
|
2953
|
+
|
|
2954
|
+
export declare type SendPerfMetricsErrors = {
|
|
2955
|
+
/**
|
|
2956
|
+
* Returns nothing
|
|
2957
|
+
*/
|
|
2958
|
+
default: {
|
|
2959
|
+
[key: string]: never;
|
|
2960
|
+
};
|
|
2961
|
+
};
|
|
2962
|
+
|
|
2963
|
+
export declare type SendPerfMetricsResponse = SendPerfMetricsResponses[keyof SendPerfMetricsResponses];
|
|
2964
|
+
|
|
2965
|
+
export declare type SendPerfMetricsResponses = {
|
|
2966
|
+
/**
|
|
2967
|
+
* Returns nothing
|
|
2968
|
+
*/
|
|
2969
|
+
200: {
|
|
2970
|
+
[key: string]: never;
|
|
2971
|
+
};
|
|
2972
|
+
};
|
|
2973
|
+
|
|
2900
2974
|
declare interface SerializerOptions<T> {
|
|
2901
2975
|
/**
|
|
2902
2976
|
* @default true
|
package/dist/webchat-client.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createClient as t, createUser as i, generateUserKey as a, initialize as n } from "./webchat-client2.js";
|
|
1
|
+
import { createClient as t, createUser as i, generateUserKey as a, initialize as n, sendPerfMetrics as s } from "./webchat-client2.js";
|
|
2
2
|
export {
|
|
3
3
|
t as createClient,
|
|
4
4
|
i as createUser,
|
|
5
5
|
a as generateUserKey,
|
|
6
|
-
n as initialize
|
|
6
|
+
n as initialize,
|
|
7
|
+
s as sendPerfMetrics
|
|
7
8
|
};
|
package/dist/webchat-client2.js
CHANGED
|
@@ -1,130 +1,147 @@
|
|
|
1
|
-
import { createUser as
|
|
1
|
+
import { createUser as x, generateUserKey as y, sendPerfMetrics as k, removeMessageFeedback as F, addMessageFeedback as T, getEvent as R, createEvent as w, deleteUser as I, updateUser as K, getUser as O, createFile as S, deleteMessage as _, getMessage as q, updateMessage as N, createMessage as z, listParticipants as A, getParticipant as J, removeParticipant as j, addParticipant as D, listConversationMessages as L, listConversations as V, deleteConversation as X, getConversation as Y, createConversation as B } from "./webchat-client3.js";
|
|
2
2
|
import { client as l } from "./webchat-client4.js";
|
|
3
|
-
import { EventSource as
|
|
4
|
-
import { throwErrorInterceptor as
|
|
3
|
+
import { EventSource as G } from "./webchat-client5.js";
|
|
4
|
+
import { throwErrorInterceptor as b } from "./webchat-client6.js";
|
|
5
5
|
import { createEventEmitter as C } from "./webchat-client7.js";
|
|
6
|
-
const
|
|
6
|
+
const n = (a) => a.data, $ = 10, M = 3e3, H = "60000", v = {
|
|
7
7
|
throwOnError: !0
|
|
8
|
-
},
|
|
8
|
+
}, se = async ({
|
|
9
9
|
clientId: a,
|
|
10
|
-
apiUrl:
|
|
11
|
-
adminSecret: i
|
|
10
|
+
apiUrl: c,
|
|
11
|
+
adminSecret: i,
|
|
12
|
+
customHeaders: o,
|
|
13
|
+
...s
|
|
12
14
|
}) => {
|
|
13
|
-
const
|
|
14
|
-
l.interceptors.response._fns.length === 0 && l.interceptors.response.use(
|
|
15
|
-
const
|
|
16
|
-
...
|
|
17
|
-
baseUrl:
|
|
15
|
+
const d = `${c || l.getConfig().baseUrl}/${a}`;
|
|
16
|
+
l.interceptors.response._fns.length === 0 && l.interceptors.response.use(b);
|
|
17
|
+
const t = {
|
|
18
|
+
...v,
|
|
19
|
+
baseUrl: d
|
|
20
|
+
}, h = {
|
|
21
|
+
...i ? { "x-admin-secret": i } : {},
|
|
22
|
+
...o
|
|
18
23
|
};
|
|
19
|
-
return
|
|
20
|
-
...
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}).then(
|
|
24
|
-
},
|
|
24
|
+
return x({
|
|
25
|
+
...t,
|
|
26
|
+
headers: Object.keys(h).length > 0 ? h : void 0,
|
|
27
|
+
body: s
|
|
28
|
+
}).then(n);
|
|
29
|
+
}, ne = ({
|
|
25
30
|
conversationId: a,
|
|
26
|
-
userToken:
|
|
31
|
+
userToken: c,
|
|
27
32
|
clientId: i,
|
|
28
|
-
apiUrl:
|
|
33
|
+
apiUrl: o,
|
|
34
|
+
adminSecret: s
|
|
29
35
|
}) => {
|
|
30
|
-
let
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
c
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
let d = 0, t = null;
|
|
37
|
+
const h = C(), e = () => {
|
|
38
|
+
t && t.close();
|
|
39
|
+
const g = `${`${o || l.getConfig().baseUrl}/${i}`}/initialize${a ? `?conversationId=${a}` : ""}`, p = {
|
|
40
|
+
...s ? { "x-admin-secret": s } : {},
|
|
41
|
+
...c ? { "x-user-key": c } : {}
|
|
42
|
+
};
|
|
43
|
+
t = P(g, p), t.onopen = () => h.emit("open"), t.onerror = (u) => {
|
|
44
|
+
d < $ ? (d++, setTimeout(() => e(), M)) : h.emit("error", u);
|
|
45
|
+
}, t.onmessage = (u) => {
|
|
46
|
+
const m = E(u.data);
|
|
47
|
+
h.emit(m.type, m.data);
|
|
39
48
|
};
|
|
40
49
|
};
|
|
41
|
-
return e(),
|
|
42
|
-
},
|
|
50
|
+
return e(), h.on;
|
|
51
|
+
}, re = async ({
|
|
43
52
|
adminSecret: a,
|
|
44
|
-
expiresAt:
|
|
53
|
+
expiresAt: c,
|
|
45
54
|
userId: i,
|
|
46
|
-
apiUrl:
|
|
47
|
-
clientId:
|
|
55
|
+
apiUrl: o,
|
|
56
|
+
clientId: s
|
|
48
57
|
}) => {
|
|
49
|
-
const
|
|
50
|
-
...
|
|
51
|
-
baseUrl:
|
|
58
|
+
const d = { "x-admin-secret": a }, t = `${o || l.getConfig().baseUrl}/${s}`, h = {
|
|
59
|
+
...v,
|
|
60
|
+
baseUrl: t
|
|
61
|
+
};
|
|
62
|
+
return y({ ...h, headers: d, body: { id: i, expiresAt: c } }).then(n);
|
|
63
|
+
}, ae = async (a, c, i, o) => {
|
|
64
|
+
const s = `${i || l.getConfig().baseUrl}/${a}`, d = {
|
|
65
|
+
...v,
|
|
66
|
+
baseUrl: s
|
|
52
67
|
};
|
|
53
|
-
return
|
|
54
|
-
},
|
|
68
|
+
return k({ ...d, body: c, headers: o }).then(n);
|
|
69
|
+
}, oe = ({
|
|
55
70
|
userKey: a,
|
|
56
|
-
clientId:
|
|
57
|
-
apiUrl: i
|
|
71
|
+
clientId: c,
|
|
72
|
+
apiUrl: i,
|
|
73
|
+
customHeaders: o
|
|
58
74
|
}) => {
|
|
59
|
-
const
|
|
60
|
-
"x-user-key": a
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
const s = {
|
|
76
|
+
"x-user-key": a,
|
|
77
|
+
...o
|
|
78
|
+
}, d = `${i || l.getConfig().baseUrl}/${c}`, t = {
|
|
79
|
+
...v,
|
|
80
|
+
baseUrl: d
|
|
64
81
|
};
|
|
65
|
-
return l.interceptors.response._fns.length === 0 && l.interceptors.response.use(
|
|
66
|
-
createConversation: () =>
|
|
67
|
-
getConversation: ({ conversationId: e }) =>
|
|
68
|
-
deleteConversation: ({ conversationId: e }) =>
|
|
69
|
-
listConversations: ({ nextToken: e }) =>
|
|
70
|
-
listConversationMessages: ({ conversationId: e, nextToken:
|
|
71
|
-
...
|
|
72
|
-
headers:
|
|
82
|
+
return l.interceptors.response._fns.length === 0 && l.interceptors.response.use(b), {
|
|
83
|
+
createConversation: () => B({ ...t, headers: s, body: {} }).then(n),
|
|
84
|
+
getConversation: ({ conversationId: e }) => Y({ ...t, headers: s, path: { id: e } }).then(n),
|
|
85
|
+
deleteConversation: ({ conversationId: e }) => X({ ...t, headers: s, path: { id: e } }).then(n),
|
|
86
|
+
listConversations: ({ nextToken: e }) => V({ ...t, headers: s, query: { nextToken: e } }).then(n),
|
|
87
|
+
listConversationMessages: ({ conversationId: e, nextToken: r }) => L({
|
|
88
|
+
...t,
|
|
89
|
+
headers: s,
|
|
73
90
|
path: { id: e },
|
|
74
|
-
query: { nextToken:
|
|
75
|
-
}).then(
|
|
76
|
-
addParticipant: ({ conversationId: e, userId:
|
|
77
|
-
removeParticipant: ({ conversationId: e, userId:
|
|
78
|
-
getParticipant: ({ conversationId: e, userId:
|
|
79
|
-
listParticipants: ({ conversationId: e, nextToken:
|
|
80
|
-
createMessage: (e) =>
|
|
81
|
-
updateMessage: ({ messageId: e, ...
|
|
82
|
-
getMessage: ({ messageId: e }) =>
|
|
83
|
-
deleteMessage: ({ messageId: e }) =>
|
|
84
|
-
createFile: (e) =>
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
generateUserKey: ({ adminSecret: e, ...s }) => U({ ...n, headers: { "x-admin-secret": e }, body: s }).then(r),
|
|
91
|
+
query: { nextToken: r }
|
|
92
|
+
}).then(n),
|
|
93
|
+
addParticipant: ({ conversationId: e, userId: r }) => D({ ...t, headers: s, path: { id: e }, body: { userId: r } }).then(n),
|
|
94
|
+
removeParticipant: ({ conversationId: e, userId: r }) => j({ ...t, headers: s, path: { id: e, userId: r } }).then(n),
|
|
95
|
+
getParticipant: ({ conversationId: e, userId: r }) => J({ ...t, headers: s, path: { id: e, userId: r } }).then(n),
|
|
96
|
+
listParticipants: ({ conversationId: e, nextToken: r }) => A({ ...t, headers: s, path: { id: e }, query: { nextToken: r } }).then(n),
|
|
97
|
+
createMessage: (e) => z({ ...t, headers: s, body: e }).then(n),
|
|
98
|
+
updateMessage: ({ messageId: e, ...r }) => N({ ...t, headers: s, path: { id: e }, body: r }).then(n),
|
|
99
|
+
getMessage: ({ messageId: e }) => q({ ...t, headers: s, path: { id: e } }).then(n),
|
|
100
|
+
deleteMessage: ({ messageId: e }) => _({ ...t, headers: s, path: { id: e } }).then(n),
|
|
101
|
+
createFile: (e) => S({ ...t, headers: s, body: e }).then(n),
|
|
102
|
+
getUser: () => O({ ...t, headers: s }).then(n),
|
|
103
|
+
updateUser: (e) => K({ ...t, headers: s, body: e }).then(n),
|
|
104
|
+
deleteUser: () => I({ ...t, headers: s }).then(n),
|
|
105
|
+
createEvent: (e) => w({ ...t, headers: s, body: e }).then(n),
|
|
106
|
+
getEvent: ({ eventId: e }) => R({ ...t, headers: s, path: { id: e } }).then(n),
|
|
107
|
+
addMessageFeedback: ({ messageId: e, ...r }) => T({ ...t, headers: s, path: { id: e }, body: r }).then(n),
|
|
108
|
+
removeMessageFeedback: ({ messageId: e }) => F({ ...t, headers: s, path: { id: e } }).then(n),
|
|
109
|
+
generateUserKey: ({ adminSecret: e, ...r }) => y({ ...t, headers: { "x-admin-secret": e }, body: r }).then(n),
|
|
94
110
|
listenConversation: ({ conversationId: e }) => {
|
|
95
|
-
let
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
},
|
|
102
|
-
const
|
|
103
|
-
|
|
111
|
+
let r = 0, g = null;
|
|
112
|
+
const p = C(), u = () => {
|
|
113
|
+
g && g.close();
|
|
114
|
+
const m = `${d}/conversations/${e}/listen`;
|
|
115
|
+
g = P(m, s), g.onopen = () => p.emit("open"), g.onerror = (f) => {
|
|
116
|
+
r < $ ? (r++, setTimeout(() => u(), M)) : p.emit("error", f);
|
|
117
|
+
}, g.onmessage = (f) => {
|
|
118
|
+
const U = E(f.data);
|
|
119
|
+
p.emit(U.type, U.data);
|
|
104
120
|
};
|
|
105
121
|
};
|
|
106
|
-
return
|
|
122
|
+
return u(), p.on;
|
|
107
123
|
}
|
|
108
124
|
};
|
|
109
|
-
},
|
|
125
|
+
}, E = (a) => {
|
|
110
126
|
try {
|
|
111
127
|
return JSON.parse(a);
|
|
112
128
|
} catch {
|
|
113
129
|
return a;
|
|
114
130
|
}
|
|
115
|
-
},
|
|
116
|
-
fetch: (i,
|
|
117
|
-
...
|
|
131
|
+
}, P = (a, c) => new G(a, {
|
|
132
|
+
fetch: (i, o) => fetch(i, {
|
|
133
|
+
...o,
|
|
118
134
|
headers: {
|
|
119
|
-
...
|
|
120
|
-
...
|
|
121
|
-
timeout:
|
|
135
|
+
...o == null ? void 0 : o.headers,
|
|
136
|
+
...c,
|
|
137
|
+
timeout: H
|
|
122
138
|
}
|
|
123
139
|
})
|
|
124
140
|
});
|
|
125
141
|
export {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
142
|
+
oe as createClient,
|
|
143
|
+
se as createUser,
|
|
144
|
+
re as generateUserKey,
|
|
145
|
+
ne as initialize,
|
|
146
|
+
ae as sendPerfMetrics
|
|
130
147
|
};
|
package/dist/webchat-client3.js
CHANGED
|
@@ -47,54 +47,54 @@ const t = (e) => (e.client ?? r).delete({
|
|
|
47
47
|
"Content-Type": "application/json",
|
|
48
48
|
...e == null ? void 0 : e.headers
|
|
49
49
|
}
|
|
50
|
-
}),
|
|
50
|
+
}), y = (e) => (e.client ?? r).post({
|
|
51
51
|
url: "/messages",
|
|
52
52
|
...e,
|
|
53
53
|
headers: {
|
|
54
54
|
"Content-Type": "application/json",
|
|
55
55
|
...e == null ? void 0 : e.headers
|
|
56
56
|
}
|
|
57
|
-
}),
|
|
57
|
+
}), j = (e) => (e.client ?? r).delete({
|
|
58
58
|
url: "/messages/{id}/feedback",
|
|
59
59
|
...e
|
|
60
|
-
}),
|
|
60
|
+
}), T = (e) => (e.client ?? r).put({
|
|
61
61
|
url: "/messages/{id}/feedback",
|
|
62
62
|
...e,
|
|
63
63
|
headers: {
|
|
64
64
|
"Content-Type": "application/json",
|
|
65
65
|
...e == null ? void 0 : e.headers
|
|
66
66
|
}
|
|
67
|
-
}),
|
|
67
|
+
}), M = (e) => (e.client ?? r).delete({
|
|
68
68
|
url: "/users/me",
|
|
69
69
|
...e
|
|
70
|
-
}),
|
|
70
|
+
}), i = (e) => (e.client ?? r).get({
|
|
71
71
|
url: "/users/me",
|
|
72
72
|
...e
|
|
73
|
-
}),
|
|
73
|
+
}), f = (e) => (e.client ?? r).put({
|
|
74
74
|
url: "/users/me",
|
|
75
75
|
...e,
|
|
76
76
|
headers: {
|
|
77
77
|
"Content-Type": "application/json",
|
|
78
78
|
...e == null ? void 0 : e.headers
|
|
79
79
|
}
|
|
80
|
-
}),
|
|
80
|
+
}), k = (e) => ((e == null ? void 0 : e.client) ?? r).post({
|
|
81
81
|
url: "/users",
|
|
82
82
|
...e,
|
|
83
83
|
headers: {
|
|
84
84
|
"Content-Type": "application/json",
|
|
85
85
|
...e == null ? void 0 : e.headers
|
|
86
86
|
}
|
|
87
|
-
}),
|
|
87
|
+
}), P = (e) => ((e == null ? void 0 : e.client) ?? r).post({
|
|
88
88
|
url: "/users/key",
|
|
89
89
|
...e,
|
|
90
90
|
headers: {
|
|
91
91
|
"Content-Type": "application/json",
|
|
92
92
|
...e == null ? void 0 : e.headers
|
|
93
93
|
}
|
|
94
|
-
}),
|
|
94
|
+
}), U = (e) => (e.client ?? r).get({
|
|
95
95
|
url: "/events/{id}",
|
|
96
96
|
...e
|
|
97
|
-
}),
|
|
97
|
+
}), b = (e) => (e.client ?? r).post({
|
|
98
98
|
url: "/events",
|
|
99
99
|
...e,
|
|
100
100
|
headers: {
|
|
@@ -108,29 +108,37 @@ const t = (e) => (e.client ?? r).delete({
|
|
|
108
108
|
"Content-Type": "application/json",
|
|
109
109
|
...e == null ? void 0 : e.headers
|
|
110
110
|
}
|
|
111
|
+
}), E = (e) => ((e == null ? void 0 : e.client) ?? r).post({
|
|
112
|
+
url: "/p",
|
|
113
|
+
...e,
|
|
114
|
+
headers: {
|
|
115
|
+
"Content-Type": "application/json",
|
|
116
|
+
...e == null ? void 0 : e.headers
|
|
117
|
+
}
|
|
111
118
|
});
|
|
112
119
|
export {
|
|
113
|
-
|
|
120
|
+
T as addMessageFeedback,
|
|
114
121
|
d as addParticipant,
|
|
115
122
|
n as createConversation,
|
|
116
|
-
|
|
123
|
+
b as createEvent,
|
|
117
124
|
F as createFile,
|
|
118
|
-
|
|
119
|
-
|
|
125
|
+
y as createMessage,
|
|
126
|
+
k as createUser,
|
|
120
127
|
t as deleteConversation,
|
|
121
128
|
v as deleteMessage,
|
|
122
|
-
|
|
123
|
-
|
|
129
|
+
M as deleteUser,
|
|
130
|
+
P as generateUserKey,
|
|
124
131
|
c as getConversation,
|
|
125
|
-
|
|
132
|
+
U as getEvent,
|
|
126
133
|
C as getMessage,
|
|
127
134
|
h as getParticipant,
|
|
128
|
-
|
|
135
|
+
i as getUser,
|
|
129
136
|
s as listConversationMessages,
|
|
130
137
|
l as listConversations,
|
|
131
138
|
u as listParticipants,
|
|
132
|
-
|
|
139
|
+
j as removeMessageFeedback,
|
|
133
140
|
g as removeParticipant,
|
|
141
|
+
E as sendPerfMetrics,
|
|
134
142
|
m as updateMessage,
|
|
135
|
-
|
|
143
|
+
f as updateUser
|
|
136
144
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/webchat-client",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"eventsource": "^3.0.6"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@bpinternal/webchat-http-client": "0.
|
|
32
|
+
"@bpinternal/webchat-http-client": "0.6.0",
|
|
33
33
|
"@hey-api/client-fetch": "^0.10.0",
|
|
34
34
|
"@hey-api/openapi-ts": "^0.66.4",
|
|
35
35
|
"@repo/eslint-config": "workspace:*",
|
package/src/client/client.ts
CHANGED
|
@@ -39,6 +39,10 @@ type Event =
|
|
|
39
39
|
data: any
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
type EventMap = {
|
|
43
|
+
[E in Event as E['type']]: E['data']
|
|
44
|
+
}
|
|
45
|
+
|
|
42
46
|
const MAX_RETRIES = 10
|
|
43
47
|
const RETRY_INTERVAL = 3000 // ms
|
|
44
48
|
const TIMEOUT = '60000' // ms
|
|
@@ -60,13 +64,12 @@ export type Client = {
|
|
|
60
64
|
getMessage: (params: MessageIdParam) => Promise<ClientTypes.GetMessageResponse>
|
|
61
65
|
deleteMessage: (params: MessageIdParam) => Promise<ClientTypes.DeleteMessageResponse>
|
|
62
66
|
createFile: (params: ClientTypes.CreateFileBody) => Promise<ClientTypes.CreateFileResponse>
|
|
63
|
-
createUser: (params: ClientTypes.CreateUserBody) => Promise<ClientTypes.CreateUserResponse>
|
|
64
67
|
getUser: () => Promise<ClientTypes.GetUserResponse>
|
|
65
68
|
updateUser: (params: ClientTypes.CreateUserBody) => Promise<ClientTypes.UpdateUserResponse>
|
|
66
69
|
deleteUser: (params: UserIdParam) => Promise<ClientTypes.DeleteUserResponse>
|
|
67
70
|
createEvent: (params: ClientTypes.CreateEventBody) => Promise<ClientTypes.CreateEventResponse>
|
|
68
71
|
getEvent: (params: EventIdParam) => Promise<ClientTypes.GetEventResponse>
|
|
69
|
-
listenConversation: (params: ConversationIdParam) => EventEmitter<
|
|
72
|
+
listenConversation: (params: ConversationIdParam) => EventEmitter<EventMap>['on']
|
|
70
73
|
addMessageFeedback: (
|
|
71
74
|
params: MessageIdParam & ClientTypes.AddMessageFeedbackBody
|
|
72
75
|
) => Promise<ClientTypes.AddMessageFeedbackResponse>
|
|
@@ -84,11 +87,14 @@ export const createUser = async ({
|
|
|
84
87
|
clientId,
|
|
85
88
|
apiUrl,
|
|
86
89
|
adminSecret,
|
|
90
|
+
customHeaders,
|
|
91
|
+
...body
|
|
87
92
|
}: {
|
|
88
93
|
clientId: string
|
|
89
94
|
apiUrl?: string
|
|
90
95
|
adminSecret?: string
|
|
91
|
-
|
|
96
|
+
customHeaders?: Record<string, string>
|
|
97
|
+
} & ClientTypes.CreateUserBody) => {
|
|
92
98
|
const baseUrl = `${apiUrl || baseClient.getConfig().baseUrl}/${clientId}`
|
|
93
99
|
|
|
94
100
|
// @ts-expect-error - this is a private property
|
|
@@ -101,11 +107,16 @@ export const createUser = async ({
|
|
|
101
107
|
baseUrl,
|
|
102
108
|
}
|
|
103
109
|
|
|
110
|
+
const headers = {
|
|
111
|
+
...(adminSecret ? { 'x-admin-secret': adminSecret } : {}),
|
|
112
|
+
...customHeaders,
|
|
113
|
+
}
|
|
114
|
+
|
|
104
115
|
return sdk
|
|
105
116
|
.createUser({
|
|
106
117
|
...configs,
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
headers: Object.keys(headers).length > 0 ? headers : undefined,
|
|
119
|
+
body,
|
|
109
120
|
})
|
|
110
121
|
.then(extractData)
|
|
111
122
|
}
|
|
@@ -115,15 +126,17 @@ export const initialize = ({
|
|
|
115
126
|
userToken,
|
|
116
127
|
clientId,
|
|
117
128
|
apiUrl,
|
|
129
|
+
adminSecret,
|
|
118
130
|
}: {
|
|
119
131
|
conversationId?: string
|
|
120
132
|
userToken?: string
|
|
121
133
|
apiUrl?: string
|
|
122
134
|
clientId: string
|
|
135
|
+
adminSecret?: string
|
|
123
136
|
}) => {
|
|
124
137
|
let retryCount = 0
|
|
125
138
|
let eventSource: EventSource | null = null
|
|
126
|
-
const eventEmitter = createEventEmitter<
|
|
139
|
+
const eventEmitter = createEventEmitter<EventMap>()
|
|
127
140
|
|
|
128
141
|
const connect = () => {
|
|
129
142
|
if (eventSource) {
|
|
@@ -133,7 +146,12 @@ export const initialize = ({
|
|
|
133
146
|
const baseUrl = `${apiUrl || baseClient.getConfig().baseUrl}/${clientId}`
|
|
134
147
|
const url = `${baseUrl}/initialize${conversationId ? `?conversationId=${conversationId}` : ''}`
|
|
135
148
|
|
|
136
|
-
|
|
149
|
+
const headers = {
|
|
150
|
+
...(adminSecret ? { 'x-admin-secret': adminSecret } : {}),
|
|
151
|
+
...(userToken ? { 'x-user-key': userToken } : {}),
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
eventSource = createNewEventSource(url, headers)
|
|
137
155
|
|
|
138
156
|
eventSource.onopen = () => eventEmitter.emit('open')
|
|
139
157
|
eventSource.onerror = (err) => {
|
|
@@ -176,17 +194,34 @@ export const generateUserKey = async ({
|
|
|
176
194
|
return sdk.generateUserKey({ ...configs, headers, body: { id: userId, expiresAt } }).then(extractData)
|
|
177
195
|
}
|
|
178
196
|
|
|
197
|
+
export const sendPerfMetrics = async (
|
|
198
|
+
clientId: string,
|
|
199
|
+
body: ClientTypes.SendPerfMetricsBody,
|
|
200
|
+
apiUrl?: string,
|
|
201
|
+
customHeaders?: Record<string, string>
|
|
202
|
+
) => {
|
|
203
|
+
const baseUrl = `${apiUrl || baseClient.getConfig().baseUrl}/${clientId}`
|
|
204
|
+
const configs = {
|
|
205
|
+
...baseConfigs,
|
|
206
|
+
baseUrl,
|
|
207
|
+
}
|
|
208
|
+
return sdk.sendPerfMetrics({ ...configs, body, headers: customHeaders }).then(extractData)
|
|
209
|
+
}
|
|
210
|
+
|
|
179
211
|
export const createClient = ({
|
|
180
212
|
userKey,
|
|
181
213
|
clientId,
|
|
182
214
|
apiUrl,
|
|
215
|
+
customHeaders,
|
|
183
216
|
}: {
|
|
184
217
|
userKey: string
|
|
185
218
|
clientId: string
|
|
186
219
|
apiUrl?: string
|
|
220
|
+
customHeaders?: Record<string, string>
|
|
187
221
|
}): Client => {
|
|
188
222
|
const headers = {
|
|
189
223
|
'x-user-key': userKey,
|
|
224
|
+
...customHeaders,
|
|
190
225
|
}
|
|
191
226
|
|
|
192
227
|
const baseUrl = `${apiUrl || baseClient.getConfig().baseUrl}/${clientId}`
|
|
@@ -234,7 +269,6 @@ export const createClient = ({
|
|
|
234
269
|
deleteMessage: ({ messageId }) =>
|
|
235
270
|
sdk.deleteMessage({ ...configs, headers, path: { id: messageId } }).then(extractData),
|
|
236
271
|
createFile: (body) => sdk.createFile({ ...configs, headers, body }).then(extractData),
|
|
237
|
-
createUser: (body) => sdk.createUser({ ...configs, headers, body }).then(extractData),
|
|
238
272
|
getUser: () => sdk.getUser({ ...configs, headers }).then(extractData),
|
|
239
273
|
updateUser: (body) => sdk.updateUser({ ...configs, headers, body }).then(extractData),
|
|
240
274
|
deleteUser: () => sdk.deleteUser({ ...configs, headers }).then(extractData),
|
|
@@ -249,7 +283,7 @@ export const createClient = ({
|
|
|
249
283
|
listenConversation: ({ conversationId }) => {
|
|
250
284
|
let retryCount = 0
|
|
251
285
|
let eventSource: EventSource | null = null
|
|
252
|
-
const eventEmitter = createEventEmitter<
|
|
286
|
+
const eventEmitter = createEventEmitter<EventMap>()
|
|
253
287
|
|
|
254
288
|
const connect = () => {
|
|
255
289
|
if (eventSource) {
|