@opencx/widget-core 4.0.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.
Files changed (40) hide show
  1. package/README.md +5 -0
  2. package/dist/__tests__/api-caller.mock.d.ts +1 -0
  3. package/dist/__tests__/context/contact/auth/auto-create-unverified-anonymous.spec.d.ts +0 -0
  4. package/dist/__tests__/context/contact/auth/auto-create-unverified-with-user-data-provided-by-org.spec.d.ts +0 -0
  5. package/dist/__tests__/context/contact/auth/manually-create-unverified-with-user-data-provided-by-user.spec.d.ts +0 -0
  6. package/dist/__tests__/context/contact/auth/with-secure-token.spec.d.ts +0 -0
  7. package/dist/__tests__/context/contact/should-collect-data.spec.d.ts +0 -0
  8. package/dist/__tests__/test-utils.d.ts +419 -0
  9. package/dist/__tests__/utils/Poller.spec.d.ts +1 -0
  10. package/dist/__tests__/utils/PrimitiveState.spec.d.ts +1 -0
  11. package/dist/api/api-caller.d.ts +437 -0
  12. package/dist/api/client.d.ts +12 -0
  13. package/dist/api/schema.d.ts +928 -0
  14. package/dist/context/active-session-polling.ctx.d.ts +25 -0
  15. package/dist/context/contact.ctx.d.ts +30 -0
  16. package/dist/context/message.ctx.d.ts +38 -0
  17. package/dist/context/router.ctx.d.ts +33 -0
  18. package/dist/context/session.ctx.d.ts +119 -0
  19. package/dist/context/storage.ctx.d.ts +15 -0
  20. package/dist/context/widget.ctx.d.ts +27 -0
  21. package/dist/index.cjs +5 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.ts +15 -0
  24. package/dist/index.js +699 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/types/agent-or-bot.d.ts +6 -0
  27. package/dist/types/component-name.d.ts +1 -0
  28. package/dist/types/dtos.d.ts +12 -0
  29. package/dist/types/external-storage.d.ts +5 -0
  30. package/dist/types/helpers.d.ts +2 -0
  31. package/dist/types/icons.d.ts +3 -0
  32. package/dist/types/json-value.d.ts +7 -0
  33. package/dist/types/messages.d.ts +55 -0
  34. package/dist/types/widget-config.d.ts +400 -0
  35. package/dist/utils/Poller.d.ts +12 -0
  36. package/dist/utils/PrimitiveState.d.ts +13 -0
  37. package/dist/utils/is-exhaustive.d.ts +1 -0
  38. package/dist/utils/run-catching.d.ts +13 -0
  39. package/dist/utils/uuid.d.ts +1 -0
  40. package/package.json +49 -0
@@ -0,0 +1,437 @@
1
+ import { Dto } from './client';
2
+ import { WidgetConfig } from '../types/widget-config';
3
+ import { ResolveSessionDto, SendMessageDto, VoteInputDto } from '../types/dtos';
4
+ export declare class ApiCaller {
5
+ private client;
6
+ private config;
7
+ private userToken;
8
+ constructor({ config }: {
9
+ config: WidgetConfig;
10
+ });
11
+ private constructClientOptions;
12
+ private createOpenAPIClient;
13
+ setAuthToken: (token: string) => void;
14
+ getExternalWidgetConfig: () => Promise<import('openapi-fetch').FetchResponse<{
15
+ parameters: {
16
+ query?: never;
17
+ header: {
18
+ "X-Bot-Token": string;
19
+ };
20
+ path?: never;
21
+ cookie?: never;
22
+ };
23
+ requestBody?: never;
24
+ responses: {
25
+ 200: {
26
+ headers: {
27
+ [name: string]: unknown;
28
+ };
29
+ content: {
30
+ "application/json": import('./schema').components["schemas"]["WidgetConfigDto"];
31
+ };
32
+ };
33
+ 500: {
34
+ headers: {
35
+ [name: string]: unknown;
36
+ };
37
+ content: {
38
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
39
+ };
40
+ };
41
+ };
42
+ }, {
43
+ params: {
44
+ header: {
45
+ 'X-Bot-Token': string;
46
+ };
47
+ };
48
+ }, `${string}/${string}`>>;
49
+ widgetPrelude: () => Promise<import('openapi-fetch').FetchResponse<{
50
+ parameters: {
51
+ query?: never;
52
+ header: {
53
+ "X-Bot-Token": string;
54
+ };
55
+ path?: never;
56
+ cookie?: never;
57
+ };
58
+ requestBody?: never;
59
+ responses: {
60
+ 200: {
61
+ headers: {
62
+ [name: string]: unknown;
63
+ };
64
+ content: {
65
+ "application/json": import('./schema').components["schemas"]["WidgetPreludeDto"];
66
+ };
67
+ };
68
+ 500: {
69
+ headers: {
70
+ [name: string]: unknown;
71
+ };
72
+ content: {
73
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
74
+ };
75
+ };
76
+ };
77
+ }, {
78
+ params: {
79
+ header: {
80
+ 'X-Bot-Token': string;
81
+ };
82
+ };
83
+ }, `${string}/${string}`>>;
84
+ sendMessage: (body: SendMessageDto, abortSignal?: AbortSignal) => Promise<import('openapi-fetch').FetchResponse<{
85
+ parameters: {
86
+ query?: never;
87
+ header?: never;
88
+ path?: never;
89
+ cookie?: never;
90
+ };
91
+ requestBody: {
92
+ content: {
93
+ "application/json": import('./schema').components["schemas"]["WidgetSendMessageInputDto"];
94
+ };
95
+ };
96
+ responses: {
97
+ 200: {
98
+ headers: {
99
+ [name: string]: unknown;
100
+ };
101
+ content: {
102
+ "application/json": import('./schema').components["schemas"]["WidgetSendMessageOutputDto"];
103
+ };
104
+ };
105
+ 500: {
106
+ headers: {
107
+ [name: string]: unknown;
108
+ };
109
+ content: {
110
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
111
+ };
112
+ };
113
+ };
114
+ }, {
115
+ body: {
116
+ uuid: string;
117
+ content: string;
118
+ session_id: string;
119
+ bot_token: string;
120
+ headers?: {
121
+ [key: string]: string;
122
+ } | null;
123
+ query_params?: {
124
+ [key: string]: string;
125
+ } | null;
126
+ body_properties?: {
127
+ [key: string]: unknown;
128
+ } | null;
129
+ language?: string | null;
130
+ attachments?: {
131
+ id: string;
132
+ name: string;
133
+ size: number;
134
+ type: string;
135
+ url: string;
136
+ }[] | null;
137
+ clientContext?: {
138
+ [key: string]: unknown;
139
+ } | null;
140
+ custom_data?: {
141
+ [key: string]: unknown;
142
+ } | null;
143
+ exit_mode_prompt?: string;
144
+ };
145
+ signal: AbortSignal | undefined;
146
+ }, `${string}/${string}`>>;
147
+ createUnverifiedContact: (body: Dto["CreateUnverifiedContactDto"]) => Promise<import('openapi-fetch').FetchResponse<{
148
+ parameters: {
149
+ query?: never;
150
+ header: {
151
+ "x-bot-token": string;
152
+ };
153
+ path?: never;
154
+ cookie?: never;
155
+ };
156
+ requestBody: {
157
+ content: {
158
+ "application/json": import('./schema').components["schemas"]["CreateUnverifiedContactDto"];
159
+ };
160
+ };
161
+ responses: {
162
+ 200: {
163
+ headers: {
164
+ [name: string]: unknown;
165
+ };
166
+ content: {
167
+ "application/json": import('./schema').components["schemas"]["WidgetContactTokenResponseDto"];
168
+ };
169
+ };
170
+ 500: {
171
+ headers: {
172
+ [name: string]: unknown;
173
+ };
174
+ content: {
175
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
176
+ };
177
+ };
178
+ };
179
+ }, {
180
+ params: {
181
+ header: {
182
+ 'x-bot-token': string;
183
+ };
184
+ };
185
+ body: {
186
+ email?: string;
187
+ non_verified_name?: string;
188
+ non_verified_custom_data?: {
189
+ [key: string]: string | number | boolean;
190
+ };
191
+ };
192
+ }, `${string}/${string}`>>;
193
+ createSession: (body: Dto["CreateWidgetSessionDto"]) => Promise<import('openapi-fetch').FetchResponse<{
194
+ parameters: {
195
+ query?: never;
196
+ header?: never;
197
+ path?: never;
198
+ cookie?: never;
199
+ };
200
+ requestBody: {
201
+ content: {
202
+ "application/json": import('./schema').components["schemas"]["CreateWidgetSessionDto"];
203
+ };
204
+ };
205
+ responses: {
206
+ 200: {
207
+ headers: {
208
+ [name: string]: unknown;
209
+ };
210
+ content: {
211
+ "application/json": import('./schema').components["schemas"]["WidgetSessionDto"];
212
+ };
213
+ };
214
+ 500: {
215
+ headers: {
216
+ [name: string]: unknown;
217
+ };
218
+ content: {
219
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
220
+ };
221
+ };
222
+ };
223
+ }, {
224
+ body: {
225
+ customData?: {
226
+ [key: string]: string | number | boolean | unknown | unknown;
227
+ };
228
+ };
229
+ }, `${string}/${string}`>>;
230
+ pollSessionAndHistory: ({ sessionId, lastMessageTimestamp, abortSignal, }: {
231
+ sessionId: string;
232
+ lastMessageTimestamp?: string;
233
+ abortSignal: AbortSignal;
234
+ }) => Promise<import('openapi-fetch').FetchResponse<{
235
+ parameters: {
236
+ query?: {
237
+ lastMessageTimestamp?: string;
238
+ };
239
+ header?: never;
240
+ path: {
241
+ sessionId: string;
242
+ };
243
+ cookie?: never;
244
+ };
245
+ requestBody?: never;
246
+ responses: {
247
+ 200: {
248
+ headers: {
249
+ [name: string]: unknown;
250
+ };
251
+ content: {
252
+ "application/json": import('./schema').components["schemas"]["WidgetSessionAndHistoryDto"];
253
+ };
254
+ };
255
+ 500: {
256
+ headers: {
257
+ [name: string]: unknown;
258
+ };
259
+ content: {
260
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
261
+ };
262
+ };
263
+ };
264
+ }, {
265
+ params: {
266
+ path: {
267
+ sessionId: string;
268
+ };
269
+ query: {
270
+ lastMessageTimestamp: string;
271
+ } | undefined;
272
+ };
273
+ signal: AbortSignal;
274
+ }, `${string}/${string}`>>;
275
+ getSessions: ({ cursor, filters, abortSignal, }: {
276
+ cursor: string | undefined;
277
+ filters: Record<string, string>;
278
+ abortSignal?: AbortSignal;
279
+ }) => Promise<import('openapi-fetch').FetchResponse<{
280
+ parameters: {
281
+ query: {
282
+ filters: string;
283
+ cursor?: string;
284
+ };
285
+ header?: never;
286
+ path?: never;
287
+ cookie?: never;
288
+ };
289
+ requestBody?: never;
290
+ responses: {
291
+ 200: {
292
+ headers: {
293
+ [name: string]: unknown;
294
+ };
295
+ content: {
296
+ "application/json": import('./schema').components["schemas"]["PaginatedWidgetSessionsDto"];
297
+ };
298
+ };
299
+ 500: {
300
+ headers: {
301
+ [name: string]: unknown;
302
+ };
303
+ content: {
304
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
305
+ };
306
+ };
307
+ };
308
+ }, {
309
+ params: {
310
+ query: {
311
+ cursor: string | undefined;
312
+ filters: string;
313
+ };
314
+ };
315
+ signal: AbortSignal | undefined;
316
+ }, `${string}/${string}`>>;
317
+ /**
318
+ * openapi-fetch usually works fine for file uploads, but this time around it parses the payload in a weird way and results in 413 errors (payload too large)
319
+ * Anyway, good old XHR even does it better with progress events
320
+ */
321
+ uploadFile: ({ file, abortSignal, onProgress, }: {
322
+ file: File;
323
+ abortSignal: AbortSignal;
324
+ onProgress?: (percentage: number) => void;
325
+ }) => Promise<Dto["UploadWidgetFileResponseDto"]>;
326
+ vote: (body: VoteInputDto) => Promise<import('openapi-fetch').FetchResponse<{
327
+ parameters: {
328
+ query?: never;
329
+ header?: never;
330
+ path?: never;
331
+ cookie?: never;
332
+ };
333
+ requestBody: {
334
+ content: {
335
+ "application/json": import('./schema').components["schemas"]["WidgetVoteDto"];
336
+ };
337
+ };
338
+ responses: {
339
+ 200: {
340
+ headers: {
341
+ [name: string]: unknown;
342
+ };
343
+ content: {
344
+ "application/json": import('./schema').components["schemas"]["WidgetVoteResponseDto"];
345
+ };
346
+ };
347
+ 500: {
348
+ headers: {
349
+ [name: string]: unknown;
350
+ };
351
+ content: {
352
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
353
+ };
354
+ };
355
+ };
356
+ }, {
357
+ body: {
358
+ action: "upvote" | "downvote";
359
+ sessionId: string;
360
+ messagePublicId: string;
361
+ };
362
+ }, `${string}/${string}`>>;
363
+ resolveSession: (body: ResolveSessionDto, abortSignal?: AbortSignal) => Promise<import('openapi-fetch').FetchResponse<{
364
+ parameters: {
365
+ query?: never;
366
+ header?: never;
367
+ path?: never;
368
+ cookie?: never;
369
+ };
370
+ requestBody: {
371
+ content: {
372
+ "application/json": import('./schema').components["schemas"]["WidgetResolveSessionInputDto"];
373
+ };
374
+ };
375
+ responses: {
376
+ 200: {
377
+ headers: {
378
+ [name: string]: unknown;
379
+ };
380
+ content: {
381
+ "application/json": import('./schema').components["schemas"]["WidgetSessionDto"];
382
+ };
383
+ };
384
+ 500: {
385
+ headers: {
386
+ [name: string]: unknown;
387
+ };
388
+ content: {
389
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
390
+ };
391
+ };
392
+ };
393
+ }, {
394
+ body: {
395
+ session_id: string;
396
+ };
397
+ signal: AbortSignal | undefined;
398
+ }, `${string}/${string}`>>;
399
+ createStateCheckpoint: (body: Dto["WidgetCreateStateCheckpointInputDto"]) => Promise<import('openapi-fetch').FetchResponse<{
400
+ parameters: {
401
+ query?: never;
402
+ header?: never;
403
+ path?: never;
404
+ cookie?: never;
405
+ };
406
+ requestBody: {
407
+ content: {
408
+ "application/json": import('./schema').components["schemas"]["WidgetCreateStateCheckpointInputDto"];
409
+ };
410
+ };
411
+ responses: {
412
+ 200: {
413
+ headers: {
414
+ [name: string]: unknown;
415
+ };
416
+ content: {
417
+ "application/json": import('./schema').components["schemas"]["WidgetCreateStateCheckpointOutputDto"];
418
+ };
419
+ };
420
+ 500: {
421
+ headers: {
422
+ [name: string]: unknown;
423
+ };
424
+ content: {
425
+ "application/json": import('./schema').components["schemas"]["ErrorDto"];
426
+ };
427
+ };
428
+ };
429
+ }, {
430
+ body: {
431
+ session_id: string;
432
+ payload: {
433
+ [key: string]: unknown;
434
+ };
435
+ };
436
+ }, `${string}/${string}`>>;
437
+ }
@@ -0,0 +1,12 @@
1
+ import { Middleware } from 'openapi-fetch';
2
+ import { paths, components } from './schema';
3
+ type Options = {
4
+ baseUrl: string;
5
+ onRequest?: Middleware['onRequest'];
6
+ onResponse?: Middleware['onResponse'];
7
+ onError?: Middleware['onError'];
8
+ };
9
+ export declare const basicClient: (options: Options) => import('openapi-fetch').Client<paths, `${string}/${string}`>;
10
+ export type Endpoint = keyof paths;
11
+ export type Dto = components['schemas'];
12
+ export {};