@opencx/widget 3.0.8 → 3.0.11

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 (46) hide show
  1. package/dist/{basic.cjs → designs.cjs} +35 -35
  2. package/dist/designs.cjs.map +1 -0
  3. package/dist/designs.d.ts +2 -0
  4. package/dist/{basic.js → designs.js} +1088 -1094
  5. package/dist/designs.js.map +1 -0
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/react.cjs +1 -1
  9. package/dist/react.js +2 -2
  10. package/dist/src/designs/react/index.d.ts +5 -8
  11. package/dist/src/designs/react/{basic/utils → utils}/group-messages-by-type.d.ts +1 -1
  12. package/dist/src/embedded/index.d.ts +11 -0
  13. package/dist/src/headless/core/api.d.ts +42 -16
  14. package/dist/src/headless/core/context/session.d.ts +28 -50
  15. package/dist/src/headless/core/sdk/schema.d.ts +80 -4
  16. package/dist/src/headless/core/types/WidgetConfig.d.ts +22 -9
  17. package/dist/src/headless/react/hooks/useDocumentDir.d.ts +2 -1
  18. package/dist/src/headless/react/hooks/useSession.d.ts +6 -0
  19. package/dist/{useUploadFiles-Cw8s18uG.js → useUploadFiles-B-HZXbPR.js} +3 -3
  20. package/dist/{useUploadFiles-Cw8s18uG.js.map → useUploadFiles-B-HZXbPR.js.map} +1 -1
  21. package/dist/{useUploadFiles-Bp-c5Nf9.cjs → useUploadFiles-WylOvupS.cjs} +2 -2
  22. package/dist/{useUploadFiles-Bp-c5Nf9.cjs.map → useUploadFiles-WylOvupS.cjs.map} +1 -1
  23. package/dist/widget-6i5ISSQC.cjs +2 -0
  24. package/dist/widget-6i5ISSQC.cjs.map +1 -0
  25. package/dist/{widget-BeNOCqB5.js → widget-BOaF1U-p.js} +128 -69
  26. package/dist/widget-BOaF1U-p.js.map +1 -0
  27. package/dist-embed/script.js +115 -115
  28. package/dist-embed/script.js.map +1 -1
  29. package/package.json +5 -5
  30. package/dist/basic.cjs.map +0 -1
  31. package/dist/basic.d.ts +0 -2
  32. package/dist/basic.js.map +0 -1
  33. package/dist/src/designs/react/basic/index.d.ts +0 -10
  34. package/dist/src/designs/react/basic/widget-interaction-tests/widget.test.d.ts +0 -1
  35. package/dist/src/designs/react/render.d.ts +0 -2
  36. package/dist/style.css +0 -1
  37. package/dist/widget-BeNOCqB5.js.map +0 -1
  38. package/dist/widget-DlAUwHzU.cjs +0 -2
  39. package/dist/widget-DlAUwHzU.cjs.map +0 -1
  40. /package/dist/src/designs/react/{basic/WidgetPopoverTrigger.d.ts → WidgetPopoverTrigger.d.ts} +0 -0
  41. /package/dist/src/designs/react/{basic/screens → screens}/chat-screen/ChatFooter.d.ts +0 -0
  42. /package/dist/src/designs/react/{basic/screens → screens}/chat-screen/ChatHeader.d.ts +0 -0
  43. /package/dist/src/designs/react/{basic/screens → screens}/chat-screen/ChatMain.d.ts +0 -0
  44. /package/dist/src/designs/react/{basic/screens → screens}/chat-screen/ChatScreen.d.ts +0 -0
  45. /package/dist/src/designs/react/{basic/screens → screens}/root-screen.d.ts +0 -0
  46. /package/dist/src/designs/react/{basic/screens → screens}/welcome-screen/WelcomeScreen.d.ts +0 -0
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./widget-DlAUwHzU.cjs");exports.PubSub=e.PubSub;exports.WidgetCtx=e.WidgetCtx;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./widget-6i5ISSQC.cjs");exports.PubSub=e.PubSub;exports.WidgetCtx=e.WidgetCtx;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { P as b, W as e } from "./widget-BeNOCqB5.js";
1
+ import { P as b, W as e } from "./widget-BOaF1U-p.js";
2
2
  export {
3
3
  b as PubSub,
4
4
  e as WidgetCtx
package/dist/react.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useUploadFiles-Bp-c5Nf9.cjs");function a(t,s,u){const{widgetCtx:{api:i}}=e.useWidget();return e._default(async o=>o==="up"?i.vote({action:"upvote",messagePublicId:t,sessionId:s}).then(u):i.vote({action:"downvote",messagePublicId:t,sessionId:s}).then(u),[i,t,s,u])}exports.WidgetProvider=e.WidgetProvider;exports.useConfig=e.useConfig;exports.useContact=e.useContact;exports.useIsAwaitingBotReply=e.useIsAwaitingBotReply;exports.useMessages=e.useMessages;exports.usePreludeData=e.usePreludeData;exports.usePubsub=e.usePubsub;exports.useSession=e.useSession;exports.useUploadFiles=e.useUploadFiles;exports.useWidget=e.useWidget;exports.useVote=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useUploadFiles-WylOvupS.cjs");function a(t,s,u){const{widgetCtx:{api:i}}=e.useWidget();return e._default(async o=>o==="up"?i.vote({action:"upvote",messagePublicId:t,sessionId:s}).then(u):i.vote({action:"downvote",messagePublicId:t,sessionId:s}).then(u),[i,t,s,u])}exports.WidgetProvider=e.WidgetProvider;exports.useConfig=e.useConfig;exports.useContact=e.useContact;exports.useIsAwaitingBotReply=e.useIsAwaitingBotReply;exports.useMessages=e.useMessages;exports.usePreludeData=e.usePreludeData;exports.usePubsub=e.usePubsub;exports.useSession=e.useSession;exports.useUploadFiles=e.useUploadFiles;exports.useWidget=e.useWidget;exports.useVote=a;
2
2
  //# sourceMappingURL=react.cjs.map
package/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
- import { u as o, _ as r } from "./useUploadFiles-Cw8s18uG.js";
2
- import { W as p, a as d, b as f, c as b, d as c, e as m, f as v, g as P, h } from "./useUploadFiles-Cw8s18uG.js";
1
+ import { u as o, _ as r } from "./useUploadFiles-B-HZXbPR.js";
2
+ import { W as p, a as d, b as f, c as b, d as c, e as m, f as v, g as P, h } from "./useUploadFiles-B-HZXbPR.js";
3
3
  function n(e, t, s) {
4
4
  const { widgetCtx: { api: a } } = o();
5
5
  return r(
@@ -1,9 +1,6 @@
1
+ import { default as React } from 'react';
1
2
  import { WidgetConfig } from '../../headless/core';
2
- declare global {
3
- interface Window {
4
- initOpenScript: typeof initOpenScript;
5
- openCXWidgetVersion: string;
6
- }
7
- }
8
- declare function initOpenScript(options: WidgetConfig): void;
9
- export {};
3
+ declare function WidgetWrapper({ options }: {
4
+ options: WidgetConfig;
5
+ }): React.JSX.Element;
6
+ export { WidgetWrapper as Widget };
@@ -1,4 +1,4 @@
1
- import { AgentMessageType, BotMessageType, MessageType, UserMessageType } from '../../../../headless/core';
1
+ import { AgentMessageType, BotMessageType, MessageType, UserMessageType } from '../../../headless/core';
2
2
  export declare function groupMessagesByType(messages: MessageType[]): MessageType[][];
3
3
  export declare function isUserMessageGroup(messages: MessageType[]): messages is UserMessageType[];
4
4
  export declare function isBotMessageGroup(messages: MessageType[]): messages is BotMessageType[];
@@ -0,0 +1,11 @@
1
+ import { default as React } from 'react';
2
+ import { WidgetConfig } from '../headless/core';
3
+ declare global {
4
+ interface Window {
5
+ initOpenScript: typeof initOpenScript;
6
+ openCXWidgetVersion: string;
7
+ }
8
+ }
9
+ declare function initOpenScript(options: WidgetConfig): void;
10
+ export declare function render(rootId: string, component: React.JSX.Element): void;
11
+ export {};
@@ -198,14 +198,18 @@ export declare class ApiCaller {
198
198
  name?: string;
199
199
  };
200
200
  }, `${string}/${string}`>>;
201
- createSession: () => Promise<import('openapi-fetch').FetchResponse<{
201
+ createSession: (body: Dto["CreateWidgetChatSessionDto"]) => Promise<import('openapi-fetch').FetchResponse<{
202
202
  parameters: {
203
203
  query?: never;
204
204
  header?: never;
205
205
  path?: never;
206
206
  cookie?: never;
207
207
  };
208
- requestBody?: never;
208
+ requestBody: {
209
+ content: {
210
+ "application/json": import('./sdk/schema').components["schemas"]["CreateWidgetChatSessionDto"];
211
+ };
212
+ };
209
213
  responses: {
210
214
  200: {
211
215
  headers: {
@@ -224,11 +228,23 @@ export declare class ApiCaller {
224
228
  };
225
229
  };
226
230
  };
227
- }, import('openapi-fetch').FetchOptions<{
231
+ }, {
232
+ body: {
233
+ customData?: {
234
+ [key: string]: string | number | boolean | unknown | unknown;
235
+ };
236
+ };
237
+ }, `${string}/${string}`>>;
238
+ getSession: ({ sessionId, abortSignal, }: {
239
+ sessionId: string;
240
+ abortSignal: AbortSignal;
241
+ }) => Promise<import('openapi-fetch').FetchResponse<{
228
242
  parameters: {
229
243
  query?: never;
230
244
  header?: never;
231
- path?: never;
245
+ path: {
246
+ sessionId: string;
247
+ };
232
248
  cookie?: never;
233
249
  };
234
250
  requestBody?: never;
@@ -250,17 +266,26 @@ export declare class ApiCaller {
250
266
  };
251
267
  };
252
268
  };
253
- }> | undefined, `${string}/${string}`>>;
254
- getSession: ({ sessionId, abortSignal, }: {
255
- sessionId: string;
256
- abortSignal: AbortSignal;
257
- }) => Promise<import('openapi-fetch').FetchResponse<{
258
- parameters: {
259
- query?: never;
260
- header?: never;
269
+ }, {
270
+ params: {
261
271
  path: {
262
272
  sessionId: string;
263
273
  };
274
+ };
275
+ signal: AbortSignal;
276
+ }, `${string}/${string}`>>;
277
+ getSessions: ({ cursor, filters, abortSignal, }: {
278
+ cursor: string | undefined;
279
+ filters: Record<string, string>;
280
+ abortSignal?: AbortSignal;
281
+ }) => Promise<import('openapi-fetch').FetchResponse<{
282
+ parameters: {
283
+ query: {
284
+ filters: string;
285
+ cursor?: string;
286
+ };
287
+ header?: never;
288
+ path?: never;
264
289
  cookie?: never;
265
290
  };
266
291
  requestBody?: never;
@@ -270,7 +295,7 @@ export declare class ApiCaller {
270
295
  [name: string]: unknown;
271
296
  };
272
297
  content: {
273
- "application/json": import('./sdk/schema').components["schemas"]["WidgetSessionDto"];
298
+ "application/json": import('./sdk/schema').components["schemas"]["PaginatedWidgetSessionsDto"];
274
299
  };
275
300
  };
276
301
  500: {
@@ -284,11 +309,12 @@ export declare class ApiCaller {
284
309
  };
285
310
  }, {
286
311
  params: {
287
- path: {
288
- sessionId: string;
312
+ query: {
313
+ cursor: string | undefined;
314
+ filters: string;
289
315
  };
290
316
  };
291
- signal: AbortSignal;
317
+ signal: AbortSignal | undefined;
292
318
  }, `${string}/${string}`>>;
293
319
  uploadFile: (file: {
294
320
  id: string;
@@ -1,21 +1,38 @@
1
1
  import { ApiCaller } from '../api';
2
2
  import { SessionDto } from '../types/schemas';
3
+ import { WidgetConfig } from '../types/WidgetConfig';
3
4
  import { PubSub } from '../utils/PubSub';
5
+ import { ContactCtx } from './contact';
6
+ type SessionCtxState = {
7
+ /** The currently selected session */
8
+ session: SessionDto | null;
9
+ sessions: {
10
+ /** List of all user sessions */
11
+ data: SessionDto[];
12
+ /** A cursor to get the next page of sessions */
13
+ cursor: string | undefined;
14
+ /** Indicates if no more pages are left */
15
+ isLastPage: boolean;
16
+ /** Did fetch for the first time */
17
+ didInitialFetch: boolean;
18
+ };
19
+ isCreatingSession: boolean;
20
+ };
4
21
  export declare class SessionCtx {
22
+ private config;
5
23
  private api;
24
+ private contactCtx;
6
25
  private poller;
7
- state: PubSub<{
8
- session: SessionDto | null;
9
- isCreatingSession: boolean;
10
- }>;
11
- constructor(api: ApiCaller);
26
+ state: PubSub<SessionCtxState>;
27
+ constructor({ config, api, contactCtx, }: {
28
+ config: WidgetConfig;
29
+ api: ApiCaller;
30
+ contactCtx: ContactCtx;
31
+ });
12
32
  /** Clears the session and stops polling */
13
33
  reset: () => Promise<void>;
14
34
  registerPolling: () => void;
15
- /**
16
- * Creates a new session
17
- * @returns The session
18
- */
35
+ registerInitialSessionsFetch: () => void;
19
36
  createSession: () => Promise<{
20
37
  id: string;
21
38
  createdAt: string;
@@ -30,45 +47,6 @@ export declare class SessionCtx {
30
47
  channel: string;
31
48
  isVerified: boolean;
32
49
  } | null>;
33
- /**
34
- * Fetches the session from the API
35
- * @param id - The ID of the session to fetch
36
- * @returns The session
37
- */
38
- fetch: (sessionId: string, abortSignal: AbortSignal) => Promise<import('openapi-fetch').FetchResponse<{
39
- parameters: {
40
- query?: never;
41
- header?: never;
42
- path: {
43
- sessionId: string;
44
- };
45
- cookie?: never;
46
- };
47
- requestBody?: never;
48
- responses: {
49
- 200: {
50
- headers: {
51
- [name: string]: unknown;
52
- };
53
- content: {
54
- "application/json": import('../sdk/schema').components["schemas"]["WidgetSessionDto"];
55
- };
56
- };
57
- 500: {
58
- headers: {
59
- [name: string]: unknown;
60
- };
61
- content: {
62
- "application/json": import('../sdk/schema').components["schemas"]["ErrorDto"];
63
- };
64
- };
65
- };
66
- }, {
67
- params: {
68
- path: {
69
- sessionId: string;
70
- };
71
- };
72
- signal: AbortSignal;
73
- }, `${string}/${string}`>>;
50
+ loadMoreSessions: () => Promise<void>;
74
51
  }
52
+ export {};
@@ -10,7 +10,6 @@ export interface paths {
10
10
  path?: never;
11
11
  cookie?: never;
12
12
  };
13
- /** Get the prelude for the widget */
14
13
  get: operations["widgetPrelude"];
15
14
  put?: never;
16
15
  post?: never;
@@ -36,6 +35,22 @@ export interface paths {
36
35
  patch?: never;
37
36
  trace?: never;
38
37
  };
38
+ "/backend/widget/v2/sessions": {
39
+ parameters: {
40
+ query?: never;
41
+ header?: never;
42
+ path?: never;
43
+ cookie?: never;
44
+ };
45
+ get: operations["getSessions"];
46
+ put?: never;
47
+ post?: never;
48
+ delete?: never;
49
+ options?: never;
50
+ head?: never;
51
+ patch?: never;
52
+ trace?: never;
53
+ };
39
54
  "/backend/widget/v2/session/history/{sessionId}": {
40
55
  parameters: {
41
56
  query?: never;
@@ -93,7 +108,6 @@ export interface paths {
93
108
  };
94
109
  get?: never;
95
110
  put?: never;
96
- /** Upload file */
97
111
  post: operations["uploadFile"];
98
112
  delete?: never;
99
113
  options?: never;
@@ -126,7 +140,6 @@ export interface paths {
126
140
  };
127
141
  get?: never;
128
142
  put?: never;
129
- /** Create an unverified contact for the widget */
130
143
  post: operations["createUnverifiedContact"];
131
144
  delete?: never;
132
145
  options?: never;
@@ -142,6 +155,11 @@ export interface components {
142
155
  email?: string;
143
156
  name?: string;
144
157
  };
158
+ CreateWidgetChatSessionDto: {
159
+ customData?: {
160
+ [key: string]: string | number | boolean | unknown | unknown;
161
+ };
162
+ };
145
163
  FileUploadDto: {
146
164
  /** Format: binary */
147
165
  file: string;
@@ -214,6 +232,27 @@ export interface components {
214
232
  url: string;
215
233
  }[] | null;
216
234
  };
235
+ /** @description Paginated response. */
236
+ PaginatedWidgetSessionsDto: {
237
+ items: {
238
+ /** Format: uuid */
239
+ id: string;
240
+ createdAt: string;
241
+ updatedAt: string;
242
+ isHandedOff: boolean;
243
+ isOpened: boolean;
244
+ assignee: {
245
+ /** @enum {string} */
246
+ kind: "human" | "ai" | "none" | "unknown";
247
+ name: string | null;
248
+ avatarUrl: string | null;
249
+ };
250
+ channel: string;
251
+ isVerified: boolean;
252
+ }[];
253
+ /** @description The `cursor` for the request to get the next set of items. Null if there is no more data. */
254
+ next: string | null;
255
+ };
217
256
  UploadWidgetFileResponseDto: {
218
257
  fileName: string;
219
258
  fileUrl: string;
@@ -398,6 +437,39 @@ export interface operations {
398
437
  };
399
438
  };
400
439
  };
440
+ getSessions: {
441
+ parameters: {
442
+ query: {
443
+ /** @description A JSON-stringified Record<string, string>. These filters will be compared against the sessions' custom_data */
444
+ filters: string;
445
+ /** @description Pagination cursor to fetch the next set of results */
446
+ cursor?: string;
447
+ };
448
+ header?: never;
449
+ path?: never;
450
+ cookie?: never;
451
+ };
452
+ requestBody?: never;
453
+ responses: {
454
+ 200: {
455
+ headers: {
456
+ [name: string]: unknown;
457
+ };
458
+ content: {
459
+ "application/json": components["schemas"]["PaginatedWidgetSessionsDto"];
460
+ };
461
+ };
462
+ /** @description Internal Server Error */
463
+ 500: {
464
+ headers: {
465
+ [name: string]: unknown;
466
+ };
467
+ content: {
468
+ "application/json": components["schemas"]["ErrorDto"];
469
+ };
470
+ };
471
+ };
472
+ };
401
473
  getSessionHistory: {
402
474
  parameters: {
403
475
  query?: {
@@ -438,7 +510,11 @@ export interface operations {
438
510
  path?: never;
439
511
  cookie?: never;
440
512
  };
441
- requestBody?: never;
513
+ requestBody: {
514
+ content: {
515
+ "application/json": components["schemas"]["CreateWidgetChatSessionDto"];
516
+ };
517
+ };
442
518
  responses: {
443
519
  200: {
444
520
  headers: {
@@ -1,4 +1,24 @@
1
1
  import { AgentOrBotType } from './agent-or-bot';
2
+ type UserBaseConfig = {
3
+ token: string;
4
+ data?: never;
5
+ } | {
6
+ token?: never;
7
+ data?: {
8
+ name?: string;
9
+ email?: string;
10
+ phone?: string;
11
+ customData?: Record<string, string>;
12
+ avatarUrl?: string;
13
+ };
14
+ };
15
+ export type UserConfig = UserBaseConfig & {
16
+ /**
17
+ * An external ID is useful to scope the sessions of a single user based on workspace.
18
+ * For example, if a user uses one email for multiple accounts (organizations) in your application.
19
+ */
20
+ externalId?: string;
21
+ };
2
22
  export interface WidgetConfig {
3
23
  token: string;
4
24
  apiUrl?: string;
@@ -8,15 +28,7 @@ export interface WidgetConfig {
8
28
  debug?: boolean;
9
29
  initialMessages?: string[];
10
30
  language?: string;
11
- user?: {
12
- external_id?: string;
13
- name?: string;
14
- email?: string;
15
- phone?: string;
16
- customData?: Record<string, string>;
17
- avatarUrl?: string;
18
- };
19
- contactToken?: string;
31
+ user?: UserConfig;
20
32
  bot?: AgentOrBotType;
21
33
  soundEffectsUrls?: {
22
34
  messageArrived?: string;
@@ -32,3 +44,4 @@ export interface WidgetConfig {
32
44
  organizationLogo?: string;
33
45
  };
34
46
  }
47
+ export {};
@@ -1,2 +1,3 @@
1
- declare const useDocumentDir: () => string;
1
+ import { StringOrLiteral } from '../../core';
2
+ declare const useDocumentDir: () => StringOrLiteral<"ltr" | "rtl">;
2
3
  export { useDocumentDir };
@@ -1,6 +1,12 @@
1
1
  export declare function useSession(): {
2
2
  sessionState: {
3
3
  session: import('../../core').SessionDto | null;
4
+ sessions: {
5
+ data: import('../../core').SessionDto[];
6
+ cursor: string | undefined;
7
+ isLastPage: boolean;
8
+ didInitialFetch: boolean;
9
+ };
4
10
  isCreatingSession: boolean;
5
11
  };
6
12
  sessionCtx: import('../../core').SessionCtx;
@@ -3,7 +3,7 @@ var kt = (e, t, n) => t in e ? Kt(e, t, { enumerable: !0, configurable: !0, writ
3
3
  var Ye = (e, t, n) => kt(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import k, { createContext as rt, useContext as ot, useMemo as le, useSyncExternalStore as zt, useEffect as st, useLayoutEffect as Yt, useRef as K, useCallback as Ee, useDebugValue as Jt, useState as Xt } from "react";
5
5
  import { jsx as Qt } from "react/jsx-runtime";
6
- import { W as Zt } from "./widget-BeNOCqB5.js";
6
+ import { W as Zt } from "./widget-BOaF1U-p.js";
7
7
  import { v4 as en } from "uuid";
8
8
  class tn {
9
9
  constructor(t) {
@@ -50,7 +50,7 @@ function nn(e) {
50
50
  return r;
51
51
  }, t.Provider];
52
52
  }
53
- const rn = "3.0.8", [te, on] = nn();
53
+ const rn = "3.0.11", [te, on] = nn();
54
54
  function tr({
55
55
  options: e,
56
56
  children: t,
@@ -1333,4 +1333,4 @@ export {
1333
1333
  ir as m,
1334
1334
  te as u
1335
1335
  };
1336
- //# sourceMappingURL=useUploadFiles-Cw8s18uG.js.map
1336
+ //# sourceMappingURL=useUploadFiles-B-HZXbPR.js.map