@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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @botpress/webchat-client@0.2.0-beta.1 build /home/runner/work/genisys/genisys/packages/webchat-client
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
  dist/webchat-client7.js  0.45 kB │ gzip: 0.26 kB
19
19
  dist/webchat-client9.js  2.63 kB │ gzip: 1.15 kB
20
20
  dist/webchat-client3.js  3.30 kB │ gzip: 0.58 kB
21
- dist/webchat-client2.js  4.89 kB │ gzip: 1.36 kB
21
+ dist/webchat-client2.js  4.75 kB │ gzip: 1.31 kB
22
22
  dist/webchat-client10.js  8.58 kB │ gzip: 2.91 kB
23
23
  dist/webchat-client5.js 10.93 kB │ gzip: 3.47 kB
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 5685ms.
27
+ [vite:dts] Declaration files built in 5323ms.
28
28
 
29
- ✓ built in 6.04s
29
+ ✓ built in 5.65s
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, adminKey?: string) => Promise<ClientTypes_2.GenerateUserKeyResponse>;
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> & {
@@ -1,108 +1,103 @@
1
- import { createUser as y, generateUserKey as E, removeMessageFeedback as b, addMessageFeedback as $, getEvent as R, createEvent as P, deleteUser as k, updateUser as T, getUser as _, createFile as F, deleteMessage as x, getMessage as S, updateMessage as w, createMessage as I, listParticipants as K, getParticipant as q, removeParticipant as A, addParticipant as N, listConversationMessages as J, listConversations as L, deleteConversation as O, getConversation as V, createConversation as X } from "./webchat-client3.js";
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 Y } from "./webchat-client5.js";
4
- import { throwErrorInterceptor as C } from "./webchat-client6.js";
5
- import { createEventEmitter as D } from "./webchat-client7.js";
6
- const n = (a) => a.data, u = {
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: h,
11
- adminKey: o
10
+ apiUrl: p,
11
+ adminKey: c
12
12
  }) => {
13
- const s = `${h || i.getConfig().baseUrl}/${a}`;
14
- i.interceptors.response._fns.length === 0 && i.interceptors.response.use(C);
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
- ...u,
17
- baseUrl: s
18
- }, t = await y({
16
+ ...v,
17
+ baseUrl: t
18
+ };
19
+ return U({
19
20
  ...d,
20
21
  body: {},
21
- headers: o ? { "x-admin-key": o } : void 0
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: h,
27
- userId: o,
28
- apiUrl: s,
26
+ expiresAt: p,
27
+ userId: c,
28
+ apiUrl: t,
29
29
  clientId: d
30
30
  }) => {
31
- const t = { "x-admin-key": a };
32
- console.log("generateUserKey", o, h, t);
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 E({ ...e, headers: t, body: { id: o, expiresAt: h } }).then(n);
35
+ return y({ ...e, headers: s, body: { id: c, expiresAt: p } }).then(n);
38
36
  }, ee = ({
39
37
  userKey: a,
40
- clientId: h,
41
- apiUrl: o
38
+ clientId: p,
39
+ apiUrl: c
42
40
  }) => {
43
- const s = {
41
+ const t = {
44
42
  "x-user-key": a
45
- }, d = `${o || i.getConfig().baseUrl}/${h}`, t = {
46
- ...u,
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(C), {
50
- createConversation: () => X({ ...t, headers: s, body: {} }).then(n),
51
- getConversation: ({ conversationId: e }) => V({ ...t, headers: s, path: { id: e } }).then(n),
52
- deleteConversation: ({ conversationId: e }) => O({ ...t, headers: s, path: { id: e } }).then(n),
53
- listConversations: ({ nextToken: e }) => L({ ...t, headers: s, query: { nextToken: e } }).then(n),
54
- listConversationMessages: ({ conversationId: e, nextToken: r }) => J({
55
- ...t,
56
- headers: s,
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 }) => N({ ...t, headers: s, path: { id: e }, body: { userId: r } }).then(n),
61
- removeParticipant: ({ conversationId: e, userId: r }) => A({ ...t, headers: s, path: { id: e, userId: r } }).then(n),
62
- getParticipant: ({ conversationId: e, userId: r }) => q({ ...t, headers: s, path: { id: e, userId: r } }).then(n),
63
- listParticipants: ({ conversationId: e, nextToken: r }) => K({ ...t, headers: s, path: { id: e }, query: { nextToken: r } }).then(n),
64
- createMessage: (e) => I({ ...t, headers: s, body: e }).then(n),
65
- updateMessage: ({ messageId: e, ...r }) => w({ ...t, headers: s, path: { id: e }, body: r }).then(n),
66
- getMessage: ({ messageId: e }) => S({ ...t, headers: s, path: { id: e } }).then(n),
67
- deleteMessage: ({ messageId: e }) => x({ ...t, headers: s, path: { id: e } }).then(n),
68
- createFile: (e) => F({ ...t, headers: s, body: e }).then(n),
69
- createUser: (e) => y({ ...t, headers: s, body: e }).then(n),
70
- getUser: () => _({ ...t, headers: s }).then(n),
71
- updateUser: (e) => T({ ...t, headers: s, body: e }).then(n),
72
- deleteUser: () => k({ ...t, headers: s }).then(n),
73
- createEvent: (e) => P({ ...t, headers: s, body: e }).then(n),
74
- getEvent: ({ eventId: e }) => R({ ...t, headers: s, path: { id: e } }).then(n),
75
- addMessageFeedback: ({ messageId: e, ...r }) => $({ ...t, headers: s, path: { id: e }, body: r }).then(n),
76
- removeMessageFeedback: ({ messageId: e }) => b({ ...t, headers: s, path: { id: e } }).then(n),
77
- generateUserKey: async (e, r) => {
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 U = 0, g = null;
83
- const l = D(), f = () => {
84
- g && g.close();
85
- const M = `${d}/conversations/${e}/listen`;
86
- g = new Y(M, {
87
- fetch: (p, c) => fetch(p, {
88
- ...c,
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
- ...c == null ? void 0 : c.headers,
91
- ...s,
85
+ ...o == null ? void 0 : o.headers,
86
+ ...t,
92
87
  timeout: "60_000"
93
88
  }
94
89
  })
95
- }), g.onopen = () => l.emit("open"), g.onerror = (p) => {
96
- l.emit("error", p), U < 10 && (U++, setTimeout(() => f(), 3e3));
97
- }, g.onmessage = (p) => {
98
- const c = j(p.data);
99
- l.emit(c.type, c.data);
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
- }, j = (a) => {
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-beta.1",
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.0",
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:*",
@@ -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
- const res = await sdk.createUser({
102
- ...configs,
103
- body: {},
104
- headers: adminKey ? { 'x-admin-key': adminKey } : undefined,
105
- })
106
-
107
- return extractData(res)
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: async (body, adminKey) => {
203
- const headers = adminKey ? { 'x-admin-key': adminKey } : undefined
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) => {