@kilichat/react 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +79 -2
- package/dist/index.cjs +969 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +273 -0
- package/dist/index.d.ts +273 -0
- package/dist/index.js +900 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +2 -0
- package/package.json +78 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default, { ReactNode } from 'react';
|
|
3
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
4
|
+
import { VariantProps } from 'class-variance-authority';
|
|
5
|
+
import * as _socket_io_component_emitter from '@socket.io/component-emitter';
|
|
6
|
+
import { Socket } from 'socket.io-client';
|
|
7
|
+
import * as axios from 'axios';
|
|
8
|
+
import { ClassValue } from 'clsx';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Runtime configuration for the SDK.
|
|
12
|
+
*
|
|
13
|
+
* In the original web app these values came from VITE_* environment variables
|
|
14
|
+
* (VITE_API_BASE_URL, VITE_SOCKET_BASE_URL, VITE_API_KEY, VITE_API_SECRET).
|
|
15
|
+
* As a library they are supplied by the host app, either through the
|
|
16
|
+
* <KiliChat config={...} /> prop or by calling configureKili() directly.
|
|
17
|
+
*/
|
|
18
|
+
type KiliConfig = {
|
|
19
|
+
/** Base URL of the Kili REST API, e.g. "https://api.kili.africa" */
|
|
20
|
+
apiBaseUrl: string;
|
|
21
|
+
/** Base URL of the Kili socket server. Defaults to apiBaseUrl. */
|
|
22
|
+
socketBaseUrl?: string;
|
|
23
|
+
/** Organisation API key */
|
|
24
|
+
apiKey: string;
|
|
25
|
+
/** Organisation API secret */
|
|
26
|
+
apiSecret: string;
|
|
27
|
+
};
|
|
28
|
+
declare function configureKili(config: KiliConfig): void;
|
|
29
|
+
declare function getKiliConfig(): KiliConfig;
|
|
30
|
+
|
|
31
|
+
type KiliChatProps = {
|
|
32
|
+
config: KiliConfig;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Drop-in Kili support chat. This is the library equivalent of the
|
|
36
|
+
* kili-customer-fe "/" route: it wraps the widget in the app state provider
|
|
37
|
+
* and bootstraps the customer session on mount.
|
|
38
|
+
*/
|
|
39
|
+
declare function KiliChat({ config }: KiliChatProps): React.JSX.Element;
|
|
40
|
+
|
|
41
|
+
declare function ChatWidget(): React.JSX.Element;
|
|
42
|
+
|
|
43
|
+
type Chat = {
|
|
44
|
+
id: number;
|
|
45
|
+
createdAt: Date;
|
|
46
|
+
updatedAt: string;
|
|
47
|
+
assignedStaffEmail?: string;
|
|
48
|
+
assignedStaffFullName?: string;
|
|
49
|
+
assignedStaffId?: number;
|
|
50
|
+
assignmentStatus: string;
|
|
51
|
+
closedAt?: Date;
|
|
52
|
+
customerEmail?: string;
|
|
53
|
+
customerFullName?: string;
|
|
54
|
+
customerId?: number;
|
|
55
|
+
initiationChannel?: string;
|
|
56
|
+
lastMessageSentAt?: string;
|
|
57
|
+
lastMessagePreview?: string;
|
|
58
|
+
lastMessageSenderAccountType?: 'customer' | 'staff';
|
|
59
|
+
priority: string;
|
|
60
|
+
snoozedAt?: string;
|
|
61
|
+
snoozedByStaffEmail?: string;
|
|
62
|
+
snoozedUntil?: string;
|
|
63
|
+
staffMemberEmailsMentioned?: string;
|
|
64
|
+
status: string;
|
|
65
|
+
summary?: string;
|
|
66
|
+
tags: string;
|
|
67
|
+
title?: string;
|
|
68
|
+
};
|
|
69
|
+
type ChatAction = 'typing.started' | 'typing.stopped' | 'uploading_file.started' | 'uploading_file.stopped';
|
|
70
|
+
type Customer = {
|
|
71
|
+
id: number;
|
|
72
|
+
createdAt: Date;
|
|
73
|
+
updatedAt: Date;
|
|
74
|
+
city?: string;
|
|
75
|
+
country?: string;
|
|
76
|
+
device?: string;
|
|
77
|
+
email?: string;
|
|
78
|
+
firstName?: string;
|
|
79
|
+
identifier?: string;
|
|
80
|
+
lastName?: string;
|
|
81
|
+
middleName?: string;
|
|
82
|
+
orgId?: number;
|
|
83
|
+
phoneCountryCode?: string;
|
|
84
|
+
phoneNumberSuffix?: string;
|
|
85
|
+
state?: string;
|
|
86
|
+
username?: string;
|
|
87
|
+
};
|
|
88
|
+
type Message = {
|
|
89
|
+
id: number;
|
|
90
|
+
createdAt: Date;
|
|
91
|
+
updatedAt: Date;
|
|
92
|
+
attachmentPath?: string;
|
|
93
|
+
attachmentType?: string;
|
|
94
|
+
attachmentUrl?: string;
|
|
95
|
+
deliveredAt?: Date;
|
|
96
|
+
chatId?: number;
|
|
97
|
+
content?: string;
|
|
98
|
+
extraData?: string;
|
|
99
|
+
openedByReceiverAt?: Date;
|
|
100
|
+
orgId?: number;
|
|
101
|
+
senderEmail?: string;
|
|
102
|
+
senderId?: number;
|
|
103
|
+
sentAt?: string;
|
|
104
|
+
senderAccountType?: string;
|
|
105
|
+
senderFirstName?: string;
|
|
106
|
+
senderLastName?: string;
|
|
107
|
+
mentionedStaffEmails?: string;
|
|
108
|
+
type: string;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
declare function ChatHome({ chats, onOpen, onStartNew, }: {
|
|
112
|
+
chats: Chat[];
|
|
113
|
+
onOpen: (c: Chat) => void;
|
|
114
|
+
onStartNew: () => void;
|
|
115
|
+
}): React.JSX.Element;
|
|
116
|
+
|
|
117
|
+
declare function ChatThread({ chat: conversation, draft, typing, onDraftChange, onSend, onBack, onTextFieldBlur, onTextfieldFocus, }: {
|
|
118
|
+
chat: Chat;
|
|
119
|
+
draft: string;
|
|
120
|
+
typing: boolean;
|
|
121
|
+
onDraftChange: (value: string) => void;
|
|
122
|
+
onSend: () => void;
|
|
123
|
+
onBack: () => void;
|
|
124
|
+
onTextfieldFocus: () => void;
|
|
125
|
+
onTextFieldBlur: () => void;
|
|
126
|
+
}): React.JSX.Element;
|
|
127
|
+
|
|
128
|
+
declare function InitialsAvatar({ initials, size, tone, className, }: {
|
|
129
|
+
initials: string;
|
|
130
|
+
size?: "sm" | "md" | "lg";
|
|
131
|
+
tone?: "brand" | "muted" | "sage";
|
|
132
|
+
className?: string;
|
|
133
|
+
}): React.JSX.Element;
|
|
134
|
+
|
|
135
|
+
declare const buttonVariants: (props?: ({
|
|
136
|
+
variant?: "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
|
|
137
|
+
size?: "sm" | "lg" | "default" | "icon" | null | undefined;
|
|
138
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
139
|
+
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
|
140
|
+
asChild?: boolean;
|
|
141
|
+
}
|
|
142
|
+
declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
143
|
+
|
|
144
|
+
declare const Textarea: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>, "ref"> & React.RefAttributes<HTMLTextAreaElement>>;
|
|
145
|
+
|
|
146
|
+
type AppState = {
|
|
147
|
+
accessToken: string | null;
|
|
148
|
+
setAccessToken: (at: string) => void;
|
|
149
|
+
chats: Chat[];
|
|
150
|
+
setChats: (chats: Chat[]) => void;
|
|
151
|
+
updateChat: (chat: Chat) => void;
|
|
152
|
+
messages: Message[];
|
|
153
|
+
setMessages: (msgs: Message[]) => void;
|
|
154
|
+
appendMessage: (msg: Message) => void;
|
|
155
|
+
refreshToken: string | null;
|
|
156
|
+
setRefreshToken: (rt: string) => void;
|
|
157
|
+
user: any | null;
|
|
158
|
+
setUser: (usr: object) => void;
|
|
159
|
+
};
|
|
160
|
+
declare const AppStateContext: React.Context<AppState | null>;
|
|
161
|
+
declare const AppStateProvider: ({ children }: {
|
|
162
|
+
children: ReactNode;
|
|
163
|
+
}) => React.JSX.Element;
|
|
164
|
+
declare const useApp: () => AppState;
|
|
165
|
+
|
|
166
|
+
declare const SocketContext: React__default.Context<Socket<_socket_io_component_emitter.DefaultEventsMap, _socket_io_component_emitter.DefaultEventsMap> | null>;
|
|
167
|
+
declare function SocketProvider({ children }: {
|
|
168
|
+
children: React__default.ReactNode;
|
|
169
|
+
}): React__default.JSX.Element;
|
|
170
|
+
|
|
171
|
+
declare function useIsMobile(): boolean;
|
|
172
|
+
|
|
173
|
+
declare const chatService: {
|
|
174
|
+
getAllChats(userId: number): Promise<any>;
|
|
175
|
+
getChatMessages(chatId: number): Promise<any>;
|
|
176
|
+
startChat(): Promise<any>;
|
|
177
|
+
sendMessage(): Promise<void>;
|
|
178
|
+
markMessageAsRead(): Promise<void>;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
declare const coreService: {
|
|
182
|
+
createCustomer(): Promise<any>;
|
|
183
|
+
registerCustomer(): Promise<any>;
|
|
184
|
+
setCustomerHmac(): Promise<void>;
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
declare const http: axios.AxiosInstance;
|
|
188
|
+
|
|
189
|
+
declare const SocketEvent: Readonly<{
|
|
190
|
+
Connection: "connection";
|
|
191
|
+
Disconnect: "disconnect";
|
|
192
|
+
Error: "error";
|
|
193
|
+
AssignChat: "assign_chat";
|
|
194
|
+
ChatAction: "chat_action";
|
|
195
|
+
ChatAssigned: "chat_assigned";
|
|
196
|
+
ChatDeassigned: "chat_deassigned";
|
|
197
|
+
ChatStarted: "chat_started";
|
|
198
|
+
ChatUpdated: "chat_updated";
|
|
199
|
+
ChatWindowClosed: "chat_window_closed";
|
|
200
|
+
ChatWindowOpened: "chat_window_opened";
|
|
201
|
+
CloseChat: "close_chat";
|
|
202
|
+
InternalNote: "internal_note";
|
|
203
|
+
JoinAllUnclosedChatRooms: "join_all_unclosed_chat_rooms";
|
|
204
|
+
JoinChatRoom: "join_chat_room";
|
|
205
|
+
JoinedChatRoom: "joined_chat_room";
|
|
206
|
+
LeaveRoom: "leave_room";
|
|
207
|
+
MarkMsgAsRead: "mark_msg_as_read";
|
|
208
|
+
Message: "message";
|
|
209
|
+
MessageDelivered: "message_delivered";
|
|
210
|
+
NewMention: "new_mention";
|
|
211
|
+
PrioritizeChat: "prioritize_chat";
|
|
212
|
+
RefetchChats: "refetch_chats";
|
|
213
|
+
ReopenChat: "reopen_chat";
|
|
214
|
+
RefetchChatCounts: "refetch_chat_counts";
|
|
215
|
+
SnoozeChat: "snooze_chat";
|
|
216
|
+
StartChat: "start_chat";
|
|
217
|
+
}>;
|
|
218
|
+
|
|
219
|
+
declare const LocalStorageKeys: {
|
|
220
|
+
AccessTokenExp: string;
|
|
221
|
+
JwtAccessToken: string;
|
|
222
|
+
JwtRefreshToken: string;
|
|
223
|
+
User: string;
|
|
224
|
+
};
|
|
225
|
+
declare const SessionStorageKeys: {
|
|
226
|
+
ActiveChat: string;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
230
|
+
declare function getInitialsFromFullName(fullname?: string): string;
|
|
231
|
+
declare function getInitialsFromNames(fname?: string, lname?: string): string;
|
|
232
|
+
|
|
233
|
+
declare function clockTime(iso?: string): string;
|
|
234
|
+
declare function dayLabel(iso?: string): string;
|
|
235
|
+
declare function relativeTime(iso: string): string;
|
|
236
|
+
|
|
237
|
+
type MessageKind = "customer" | "agent";
|
|
238
|
+
type WidgetMessage = {
|
|
239
|
+
id: string;
|
|
240
|
+
kind: MessageKind;
|
|
241
|
+
body: string;
|
|
242
|
+
at: string;
|
|
243
|
+
authorId?: string;
|
|
244
|
+
};
|
|
245
|
+
type Agent = {
|
|
246
|
+
id: string;
|
|
247
|
+
name: string;
|
|
248
|
+
initials: string;
|
|
249
|
+
role: string;
|
|
250
|
+
};
|
|
251
|
+
type WidgetConversation = {
|
|
252
|
+
id: string;
|
|
253
|
+
subject: string;
|
|
254
|
+
agentId: string;
|
|
255
|
+
messages: WidgetMessage[];
|
|
256
|
+
closed?: boolean;
|
|
257
|
+
};
|
|
258
|
+
declare const brand: {
|
|
259
|
+
name: string;
|
|
260
|
+
greeting: string;
|
|
261
|
+
subline: string;
|
|
262
|
+
replyTime: string;
|
|
263
|
+
};
|
|
264
|
+
declare const customer: {
|
|
265
|
+
name: string;
|
|
266
|
+
initials: string;
|
|
267
|
+
};
|
|
268
|
+
declare const agents: Agent[];
|
|
269
|
+
declare const seedConversations: WidgetConversation[];
|
|
270
|
+
declare function nextCannedReply(): string;
|
|
271
|
+
declare function agentById(id: string): Agent;
|
|
272
|
+
|
|
273
|
+
export { type Agent, type AppState, AppStateContext, AppStateProvider, Button, type ButtonProps, type Chat, type ChatAction, ChatHome, ChatThread, ChatWidget, type Customer, InitialsAvatar, KiliChat, type KiliChatProps, type KiliConfig, LocalStorageKeys, type Message, type MessageKind, SessionStorageKeys, SocketContext, SocketEvent, SocketProvider, Textarea, type WidgetConversation, type WidgetMessage, agentById, agents, brand, buttonVariants, chatService, clockTime, cn, configureKili, coreService, customer, dayLabel, getInitialsFromFullName, getInitialsFromNames, getKiliConfig, http, nextCannedReply, relativeTime, seedConversations, useApp, useIsMobile };
|