@vserifsaglam/chat-react-client 1.0.2
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/README.md +674 -0
- package/dist/api/chatApi.d.ts +143 -0
- package/dist/connection/ConnectionManager.d.ts +68 -0
- package/dist/connection/ConnectionManager.test.d.ts +1 -0
- package/dist/context/ChatContext.d.ts +20 -0
- package/dist/context/ConnectionContext.d.ts +28 -0
- package/dist/context/ConnectionContext.test.d.ts +1 -0
- package/dist/hooks/useBans.d.ts +14 -0
- package/dist/hooks/useClientProfile.d.ts +10 -0
- package/dist/hooks/useConnection.d.ts +14 -0
- package/dist/hooks/useConversationDetails.d.ts +15 -0
- package/dist/hooks/useConversationManagements.d.ts +12 -0
- package/dist/hooks/useConversations.d.ts +17 -0
- package/dist/hooks/useCustomEvents.d.ts +14 -0
- package/dist/hooks/useFiles.d.ts +10 -0
- package/dist/hooks/useLogging.d.ts +9 -0
- package/dist/hooks/useMessageManagements.d.ts +19 -0
- package/dist/hooks/useMessages.d.ts +23 -0
- package/dist/hooks/useQueue.d.ts +12 -0
- package/dist/hooks/useRealtime.d.ts +56 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +3075 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +3057 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/types.d.ts +248 -0
- package/dist/utils/Logger.d.ts +37 -0
- package/package.json +68 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { AuthConfig, Conversation, ConversationSearchResult, MessagesResponse, SendMessageRequest, SendMessageResponse, MarkConversationReadResponse, UpdateMessageRequest, UpdateMessageResponse, DeleteMessageResponse, FileUploadResponse, ApiResponse, BanClientRequest, UnbanClientRequest, AdminBanClientRequest, AdminUnbanClientRequest, BanStatusResponse, ClientProfileResponse, ClientPreferencesResponse, UpdatePreferencesRequest, UpdatePreferencesResponse } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Chat API client for making requests to the chat backend
|
|
4
|
+
*/
|
|
5
|
+
export declare class ChatApi {
|
|
6
|
+
private client;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new ChatApi instance
|
|
9
|
+
* @param config Authentication configuration
|
|
10
|
+
*/
|
|
11
|
+
constructor(config: AuthConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Check if the API is running
|
|
14
|
+
* @returns A promise that resolves to "OK" if the API is running
|
|
15
|
+
*/
|
|
16
|
+
healthCheck(): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Get a list of conversations
|
|
19
|
+
* @param archived Whether to include archived conversations
|
|
20
|
+
* @param clientId Filter conversations by client ID
|
|
21
|
+
* @returns A promise that resolves to an array of conversations
|
|
22
|
+
*/
|
|
23
|
+
listConversations(archived?: boolean, clientIds?: string): Promise<Conversation[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Delete a conversation
|
|
26
|
+
* @param conversationUid The UID of the conversation to delete
|
|
27
|
+
* @returns A promise that resolves to an API response
|
|
28
|
+
*/
|
|
29
|
+
deleteConversation(conversationUid: string): Promise<ApiResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Archive a conversation
|
|
32
|
+
* @param conversationUid The UID of the conversation to archive
|
|
33
|
+
* @returns A promise that resolves to an API response
|
|
34
|
+
*/
|
|
35
|
+
archiveConversation(conversationUid: string): Promise<ApiResponse>;
|
|
36
|
+
/**
|
|
37
|
+
* Unarchive a conversation
|
|
38
|
+
* @param conversationUid The UID of the conversation to unarchive
|
|
39
|
+
* @returns A promise that resolves to an API response
|
|
40
|
+
*/
|
|
41
|
+
unarchiveConversation(conversationUid: string): Promise<ApiResponse>;
|
|
42
|
+
/**
|
|
43
|
+
* Get details about a conversation
|
|
44
|
+
* @param conversationUid The UID of the conversation
|
|
45
|
+
* @returns A promise that resolves to conversation details
|
|
46
|
+
*/
|
|
47
|
+
getConversationDetails(conversationUid: string): Promise<Conversation>;
|
|
48
|
+
/**
|
|
49
|
+
* Get conversation details with a specific receiver
|
|
50
|
+
* @param receiverId The ID of the receiver
|
|
51
|
+
* @returns A promise that resolves to conversation details
|
|
52
|
+
*/
|
|
53
|
+
getConversationWithReceiver(receiverId: string): Promise<Conversation>;
|
|
54
|
+
/**
|
|
55
|
+
* Search for messages in a conversation
|
|
56
|
+
* @param conversationUid The UID of the conversation
|
|
57
|
+
* @param term The search term
|
|
58
|
+
* @returns A promise that resolves to search results
|
|
59
|
+
*/
|
|
60
|
+
searchConversation(conversationUid: string, term: string): Promise<ConversationSearchResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Get messages for a conversation
|
|
63
|
+
* @param conversationUid The UID of the conversation
|
|
64
|
+
* @param page The page number
|
|
65
|
+
* @param pageSize The number of messages per page
|
|
66
|
+
* @returns A promise that resolves to a messages response
|
|
67
|
+
*/
|
|
68
|
+
getMessages(conversationUid: string, page?: number, pageSize?: number): Promise<MessagesResponse>;
|
|
69
|
+
/**
|
|
70
|
+
* Mark a message as read
|
|
71
|
+
* @param messageId The ID of the message
|
|
72
|
+
* @returns A promise that resolves to an API response
|
|
73
|
+
*/
|
|
74
|
+
markMessageAsRead(messageId: number): Promise<ApiResponse>;
|
|
75
|
+
/**
|
|
76
|
+
* Send a message
|
|
77
|
+
* @param message The message to send
|
|
78
|
+
* @returns A promise that resolves to a send message response
|
|
79
|
+
*/
|
|
80
|
+
sendMessage(message: SendMessageRequest): Promise<SendMessageResponse>;
|
|
81
|
+
/**
|
|
82
|
+
* Mark all messages in a conversation as read
|
|
83
|
+
* @param conversationUid The UID of the conversation
|
|
84
|
+
* @returns A promise that resolves to a mark conversation read response
|
|
85
|
+
*/
|
|
86
|
+
markConversationAsRead(conversationUid: string): Promise<MarkConversationReadResponse>;
|
|
87
|
+
/**
|
|
88
|
+
* Update a message
|
|
89
|
+
* @param messageId The ID of the message
|
|
90
|
+
* @param update The update to apply
|
|
91
|
+
* @returns A promise that resolves to an update message response
|
|
92
|
+
*/
|
|
93
|
+
updateMessage(messageId: number, update: UpdateMessageRequest): Promise<UpdateMessageResponse>;
|
|
94
|
+
/**
|
|
95
|
+
* Delete a message
|
|
96
|
+
* @param messageId The ID of the message
|
|
97
|
+
* @returns A promise that resolves to a delete message response
|
|
98
|
+
*/
|
|
99
|
+
deleteMessage(messageId: number): Promise<DeleteMessageResponse>;
|
|
100
|
+
/**
|
|
101
|
+
* Upload a file
|
|
102
|
+
* @param file The file to upload
|
|
103
|
+
* @returns A promise that resolves to a file upload response
|
|
104
|
+
*/
|
|
105
|
+
uploadFile(file: File): Promise<FileUploadResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Ban a client from communicating with the requesting client
|
|
108
|
+
* @param request The ban client request
|
|
109
|
+
* @returns A promise that resolves to an API response
|
|
110
|
+
*/
|
|
111
|
+
banClient(request: BanClientRequest): Promise<ApiResponse>;
|
|
112
|
+
/**
|
|
113
|
+
* Unban a client that was previously banned by the requesting client
|
|
114
|
+
* @param request The unban client request
|
|
115
|
+
* @returns A promise that resolves to an API response
|
|
116
|
+
*/
|
|
117
|
+
unbanClient(request: UnbanClientRequest): Promise<ApiResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Ban a client as an admin
|
|
120
|
+
* @param request The admin ban client request
|
|
121
|
+
* @returns A promise that resolves to an API response
|
|
122
|
+
*/
|
|
123
|
+
adminBanClient(request: AdminBanClientRequest): Promise<ApiResponse>;
|
|
124
|
+
/**
|
|
125
|
+
* Unban a client that was previously banned by an admin
|
|
126
|
+
* @param request The admin unban client request
|
|
127
|
+
* @returns A promise that resolves to an API response
|
|
128
|
+
*/
|
|
129
|
+
adminUnbanClient(request: AdminUnbanClientRequest): Promise<ApiResponse>;
|
|
130
|
+
/**
|
|
131
|
+
* Check if a client is banned by the requesting client or by an admin
|
|
132
|
+
* @param clientId The client ID to check the ban status for
|
|
133
|
+
* @returns A promise that resolves to a ban status response
|
|
134
|
+
*/
|
|
135
|
+
checkBanStatus(clientId: string): Promise<BanStatusResponse>;
|
|
136
|
+
/**
|
|
137
|
+
* Get the profile information of the authenticated client
|
|
138
|
+
* @returns A promise that resolves to a client profile response
|
|
139
|
+
*/
|
|
140
|
+
getClientProfile(): Promise<ClientProfileResponse>;
|
|
141
|
+
getClientPreferences(): Promise<ClientPreferencesResponse>;
|
|
142
|
+
updateClientPreferences(request: UpdatePreferencesRequest): Promise<UpdatePreferencesResponse>;
|
|
143
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ChatApi } from '../api/chatApi';
|
|
2
|
+
import { AuthConfig, ConnectionConfig, ConnectionStatus, EventType, RealtimeEvent, SendMessageRequest } from '../types';
|
|
3
|
+
import { LoggerConfig } from '../utils/Logger';
|
|
4
|
+
export interface ExtendedConnectionOptions extends Partial<ConnectionConfig> {
|
|
5
|
+
/** Extra HTTP headers – used when the runtime supports them (Node/RN) */
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
/** Extra values to send via auth/query in the browser (simulates headers) */
|
|
8
|
+
extraAuth?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
declare type EventCallback = (e: RealtimeEvent) => void;
|
|
11
|
+
declare type StatusCallback = (s: ConnectionStatus) => void;
|
|
12
|
+
export declare class ConnectionManager {
|
|
13
|
+
private static instance;
|
|
14
|
+
static getInstance(auth: AuthConfig, api: ChatApi, options?: ExtendedConnectionOptions): ConnectionManager;
|
|
15
|
+
static resetInstance(): void;
|
|
16
|
+
private readonly cfg;
|
|
17
|
+
private readonly auth;
|
|
18
|
+
private readonly api;
|
|
19
|
+
private readonly logger;
|
|
20
|
+
private socket;
|
|
21
|
+
private status;
|
|
22
|
+
private eventListeners;
|
|
23
|
+
private statusListeners;
|
|
24
|
+
private errorListeners;
|
|
25
|
+
private readonly queue;
|
|
26
|
+
private processingQueue;
|
|
27
|
+
private connecting;
|
|
28
|
+
private reconnectCount;
|
|
29
|
+
private wsFailCount;
|
|
30
|
+
private isDegraded;
|
|
31
|
+
private constructor();
|
|
32
|
+
connect(): void;
|
|
33
|
+
disconnect(): void;
|
|
34
|
+
getStatus(): ConnectionStatus;
|
|
35
|
+
queueMessage(msg: SendMessageRequest, maxAttempts?: number): string;
|
|
36
|
+
on(evt: EventType, cb: EventCallback): void;
|
|
37
|
+
off(evt: EventType, cb: EventCallback): void;
|
|
38
|
+
emit(evt: any, ...args: any[]): void;
|
|
39
|
+
onStatusChange(cb: StatusCallback): void;
|
|
40
|
+
offStatusChange(cb: StatusCallback): void;
|
|
41
|
+
onError(cb: (err: any) => void): void;
|
|
42
|
+
offError(cb: (err: any) => void): void;
|
|
43
|
+
updateLogging(config: Partial<LoggerConfig>): void;
|
|
44
|
+
getLoggingConfig(): LoggerConfig;
|
|
45
|
+
private connectWS;
|
|
46
|
+
private buildSocketOpts;
|
|
47
|
+
private handleConnError;
|
|
48
|
+
private processQueue;
|
|
49
|
+
private sendMessageHttp;
|
|
50
|
+
private handleEvent;
|
|
51
|
+
private setStatus;
|
|
52
|
+
private scheduleReconnect;
|
|
53
|
+
private clearTimers;
|
|
54
|
+
private saveQueue;
|
|
55
|
+
private add;
|
|
56
|
+
private remove;
|
|
57
|
+
private storageAvailable;
|
|
58
|
+
private failKey;
|
|
59
|
+
private untilKey;
|
|
60
|
+
private getFailCount;
|
|
61
|
+
private setFailCount;
|
|
62
|
+
private resetWsFailures;
|
|
63
|
+
private getDegradeUntil;
|
|
64
|
+
private setDegradeUntil;
|
|
65
|
+
private clearDegradation;
|
|
66
|
+
private onWsFailure;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { ReactNode, Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { ChatApi } from '../api/chatApi';
|
|
3
|
+
import { AuthConfig, Conversation, ConnectionOptions } from '../types';
|
|
4
|
+
interface ChatContextType {
|
|
5
|
+
api: ChatApi | null;
|
|
6
|
+
isInitialized: boolean;
|
|
7
|
+
isAuthenticated: boolean;
|
|
8
|
+
initialize: (config: AuthConfig) => void;
|
|
9
|
+
conversations: Conversation[];
|
|
10
|
+
refreshConversations: (archived?: boolean, clientIds?: string) => Promise<Conversation[]>;
|
|
11
|
+
setConversations: Dispatch<SetStateAction<Conversation[]>>;
|
|
12
|
+
}
|
|
13
|
+
interface ChatProviderProps {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
config?: AuthConfig;
|
|
16
|
+
connectionOptions?: ConnectionOptions;
|
|
17
|
+
}
|
|
18
|
+
export declare const ChatProvider: React.FC<ChatProviderProps>;
|
|
19
|
+
export declare const useChatContext: () => ChatContextType;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import { ConnectionManager } from '../connection/ConnectionManager';
|
|
3
|
+
import { ChatApi } from '../api/chatApi';
|
|
4
|
+
import { AuthConfig, ConnectionOptions, ConnectionStatus, EventType, RealtimeEvent, SendMessageRequest } from '../types';
|
|
5
|
+
import { LoggerConfig } from '../utils/Logger';
|
|
6
|
+
interface ConnectionContextType {
|
|
7
|
+
connection: ConnectionManager | null;
|
|
8
|
+
status: ConnectionStatus;
|
|
9
|
+
connect: () => void;
|
|
10
|
+
disconnect: () => void;
|
|
11
|
+
sendMessage: (message: SendMessageRequest, maxAttempts?: number) => string | null;
|
|
12
|
+
on: (eventType: EventType, callback: (event: RealtimeEvent) => void) => void;
|
|
13
|
+
off: (eventType: EventType, callback: (event: RealtimeEvent) => void) => void;
|
|
14
|
+
onError: (cb: (err: any) => void) => void;
|
|
15
|
+
offError: (cb: (err: any) => void) => void;
|
|
16
|
+
updateLogging: (config: Partial<LoggerConfig>) => void;
|
|
17
|
+
getLoggingConfig: () => LoggerConfig | null;
|
|
18
|
+
}
|
|
19
|
+
interface ConnectionProviderProps {
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
authConfig?: AuthConfig;
|
|
22
|
+
api?: ChatApi;
|
|
23
|
+
connectionOptions?: ConnectionOptions;
|
|
24
|
+
autoConnect?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare const ConnectionProvider: React.FC<ConnectionProviderProps>;
|
|
27
|
+
export declare const useConnectionContext: () => ConnectionContextType;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ApiResponse, BanStatusResponse } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for managing client bans
|
|
4
|
+
*/
|
|
5
|
+
export declare const useBans: () => {
|
|
6
|
+
loading: boolean;
|
|
7
|
+
error: Error | null;
|
|
8
|
+
banStatus: BanStatusResponse | null;
|
|
9
|
+
banClient: (clientId: string) => Promise<ApiResponse | null>;
|
|
10
|
+
unbanClient: (clientId: string) => Promise<ApiResponse | null>;
|
|
11
|
+
adminBanClient: (clientId: string, reason?: string | undefined, durationDays?: number | undefined) => Promise<ApiResponse | null>;
|
|
12
|
+
adminUnbanClient: (clientId: string) => Promise<ApiResponse | null>;
|
|
13
|
+
checkBanStatus: (clientId: string) => Promise<BanStatusResponse | null>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ClientProfileResponse } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for accessing client profile information
|
|
4
|
+
*/
|
|
5
|
+
export declare const useClientProfile: () => {
|
|
6
|
+
loading: boolean;
|
|
7
|
+
error: Error | null;
|
|
8
|
+
profile: ClientProfileResponse | null;
|
|
9
|
+
fetchProfile: () => Promise<ClientProfileResponse | null>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ConnectionStatus, SendMessageRequest } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for managing the realtime connection
|
|
4
|
+
*/
|
|
5
|
+
export declare const useConnection: () => {
|
|
6
|
+
status: ConnectionStatus;
|
|
7
|
+
isConnected: boolean;
|
|
8
|
+
isConnecting: boolean;
|
|
9
|
+
hasError: boolean;
|
|
10
|
+
connect: () => void;
|
|
11
|
+
disconnect: () => void;
|
|
12
|
+
sendMessage: (message: SendMessageRequest, maxAttempts?: any) => string | null;
|
|
13
|
+
connection: import("../connection/ConnectionManager").ConnectionManager | null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Conversation } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook to get conversation details with a specific receiver
|
|
4
|
+
* @returns Functions and state for working with conversation details
|
|
5
|
+
*/
|
|
6
|
+
export declare const useConversationDetails: () => {
|
|
7
|
+
conversationDetails: Conversation | null;
|
|
8
|
+
receiverId: string | null;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
getConversationWithReceiver: (receiverId: string) => Promise<{
|
|
12
|
+
details: Conversation | null;
|
|
13
|
+
receiverId: string;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Conversation } from '../types';
|
|
2
|
+
export declare function useConversationManagement(): {
|
|
3
|
+
conversations: Conversation[];
|
|
4
|
+
conversationsLoading: boolean;
|
|
5
|
+
selectedConversationId: string;
|
|
6
|
+
selectedConversation: Conversation | undefined;
|
|
7
|
+
deleteConversation: (conversationUid: string) => Promise<import("../types").ApiResponse | null>;
|
|
8
|
+
archiveConversation: (conversationUid: string) => Promise<import("../types").ApiResponse | null>;
|
|
9
|
+
unarchiveConversation: (conversationUid: string) => Promise<import("../types").ApiResponse | null>;
|
|
10
|
+
handleSelectConversation: (conversation: Conversation | null) => void;
|
|
11
|
+
getConversations: (archived?: boolean | undefined, clientIds?: string | undefined) => Promise<Conversation[]>;
|
|
12
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ConversationSearchResult, ApiResponse, Conversation } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for managing conversations
|
|
5
|
+
*/
|
|
6
|
+
export declare const useConversations: () => {
|
|
7
|
+
conversations: Conversation[];
|
|
8
|
+
loading: boolean;
|
|
9
|
+
error: Error | null;
|
|
10
|
+
getConversations: (archived?: boolean | undefined, clientIds?: string | undefined) => Promise<Conversation[]>;
|
|
11
|
+
deleteConversation: (conversationUid: string) => Promise<ApiResponse | null>;
|
|
12
|
+
archiveConversation: (conversationUid: string) => Promise<ApiResponse | null>;
|
|
13
|
+
unarchiveConversation: (conversationUid: string) => Promise<ApiResponse | null>;
|
|
14
|
+
getConversationDetails: (conversationUid: string) => Promise<Conversation | null>;
|
|
15
|
+
searchConversation: (conversationUid: string, term: string) => Promise<ConversationSearchResult | null>;
|
|
16
|
+
setConversations: import("react").Dispatch<import("react").SetStateAction<Conversation[]>>;
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventType } from '../types';
|
|
2
|
+
declare type CustomEventListener<T = any> = (data: T) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Hook for managing custom events
|
|
5
|
+
*
|
|
6
|
+
* @returns Object with methods to register, unregister, and emit custom events
|
|
7
|
+
*/
|
|
8
|
+
export declare function useCustomEvents(): {
|
|
9
|
+
registerCustomEventListener: <T = any>(key: string, eventType: EventType, callback: CustomEventListener<T>) => () => void;
|
|
10
|
+
unregisterCustomEventListener: (key: string, callback: CustomEventListener) => void;
|
|
11
|
+
unregisterAllCustomEventListeners: (key: string) => void;
|
|
12
|
+
emitCustomEvent: (eventType: EventType, data: any) => void;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FileUploadResponse } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for managing file uploads
|
|
4
|
+
*/
|
|
5
|
+
export declare const useFiles: () => {
|
|
6
|
+
loading: boolean;
|
|
7
|
+
error: Error | null;
|
|
8
|
+
uploadProgress: number;
|
|
9
|
+
uploadFile: (file: File) => Promise<FileUploadResponse | null>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { LogLevel, LoggerConfig } from '../utils/Logger';
|
|
2
|
+
export interface UseLoggingReturn {
|
|
3
|
+
enableLogging: (level?: LogLevel) => void;
|
|
4
|
+
disableLogging: () => void;
|
|
5
|
+
setLogLevel: (level: LogLevel) => void;
|
|
6
|
+
updateLoggingConfig: (config: Partial<LoggerConfig>) => void;
|
|
7
|
+
getLoggingConfig: () => LoggerConfig | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function useLogging(): UseLoggingReturn;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Message, SenderReceiverUser } from '../index';
|
|
3
|
+
export declare function useMessageManagement(selectedConversationId: string): {
|
|
4
|
+
messages: Message[];
|
|
5
|
+
messagesLoading: boolean;
|
|
6
|
+
fileLoading: boolean;
|
|
7
|
+
uploadProgress: number;
|
|
8
|
+
uploadFile: (file: File) => Promise<import("..").FileUploadResponse | null>;
|
|
9
|
+
handleSendMessage: (content: string, receiver: SenderReceiverUser) => Promise<boolean | undefined>;
|
|
10
|
+
handleSendFileMessage: (content: string, fileId: number, receiver: SenderReceiverUser, filename?: string | undefined, url?: string | undefined) => Promise<boolean | undefined>;
|
|
11
|
+
deleteMessage: (messageId: number) => Promise<import("..").DeleteMessageResponse | null>;
|
|
12
|
+
updateMessage: (messageId: number, update: import("..").UpdateMessageRequest) => Promise<import("..").UpdateMessageResponse | null>;
|
|
13
|
+
getMessages: (conversationId?: any, page?: any, pageSize?: any) => Promise<import("..").MessagesResponse | null>;
|
|
14
|
+
loadMoreMessages: () => Promise<void>;
|
|
15
|
+
hasMore: boolean;
|
|
16
|
+
setMessages: import("react").Dispatch<import("react").SetStateAction<import("..").MessagesResponse | null>>;
|
|
17
|
+
preferences: import("..").ClientPreferences | null;
|
|
18
|
+
updatePreferences: (enableRead: boolean) => Promise<boolean>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MessagesResponse, SendMessageRequest, SendMessageResponse, MarkConversationReadResponse, UpdateMessageRequest, UpdateMessageResponse, DeleteMessageResponse, ApiResponse, Message, ClientPreferences } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for managing messages
|
|
5
|
+
*/
|
|
6
|
+
export declare const useMessages: (conversationUid?: string | undefined) => {
|
|
7
|
+
messages: Message[];
|
|
8
|
+
pagination: import("../types").MessagesPagination | undefined;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
queueLength: number;
|
|
12
|
+
getMessages: (conversationId?: any, page?: any, pageSize?: any) => Promise<MessagesResponse | null>;
|
|
13
|
+
markMessageAsRead: (messageId: number) => Promise<ApiResponse | null>;
|
|
14
|
+
sendMessage: (message: Omit<SendMessageRequest, 'conversation_uid'> & {
|
|
15
|
+
conversation_uid?: string;
|
|
16
|
+
}) => Promise<SendMessageResponse | null>;
|
|
17
|
+
markConversationAsRead: (conversationId?: any) => Promise<MarkConversationReadResponse | null>;
|
|
18
|
+
updateMessage: (messageId: number, update: UpdateMessageRequest) => Promise<UpdateMessageResponse | null>;
|
|
19
|
+
deleteMessage: (messageId: number) => Promise<DeleteMessageResponse | null>;
|
|
20
|
+
setMessages: import("react").Dispatch<import("react").SetStateAction<MessagesResponse | null>>;
|
|
21
|
+
updatePreferences: (enableRead: boolean) => Promise<boolean>;
|
|
22
|
+
preferences: ClientPreferences | null;
|
|
23
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChatApi } from '../api/chatApi';
|
|
2
|
+
import { SendMessageRequest, SendMessageResponse } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for managing a message queue with retry functionality
|
|
5
|
+
* @param api The ChatApi instance
|
|
6
|
+
*/
|
|
7
|
+
export declare const useQueue: (api: ChatApi | null) => {
|
|
8
|
+
enqueueMessage: (message: SendMessageRequest) => string;
|
|
9
|
+
sendMessageWithRetry: (message: SendMessageRequest) => Promise<SendMessageResponse | null>;
|
|
10
|
+
queueLength: number;
|
|
11
|
+
isProcessing: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { EventType, RealtimeEvent, MessageSentEvent, MessageEditedEvent, MessageDeletedEvent, MessageReadEvent, ConversationReadEvent } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for subscribing to realtime events
|
|
4
|
+
* @param eventType The event type to subscribe to
|
|
5
|
+
*/
|
|
6
|
+
export declare function useRealtime<T = any>(eventType: EventType): {
|
|
7
|
+
event: RealtimeEvent<T> | null;
|
|
8
|
+
clearEvent: () => void;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Hook for subscribing to message sent events
|
|
12
|
+
*/
|
|
13
|
+
export declare function useMessageSentEvents(): {
|
|
14
|
+
event: RealtimeEvent<MessageSentEvent> | null;
|
|
15
|
+
clearEvent: () => void;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Hook for subscribing to message edited events
|
|
19
|
+
*/
|
|
20
|
+
export declare function useMessageEditedEvents(): {
|
|
21
|
+
event: RealtimeEvent<MessageEditedEvent> | null;
|
|
22
|
+
clearEvent: () => void;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Hook for subscribing to message deleted events
|
|
26
|
+
*/
|
|
27
|
+
export declare function useMessageDeletedEvents(): {
|
|
28
|
+
event: RealtimeEvent<MessageDeletedEvent> | null;
|
|
29
|
+
clearEvent: () => void;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Hook for subscribing to message read events
|
|
33
|
+
*/
|
|
34
|
+
export declare function useMessageReadEvents(): {
|
|
35
|
+
event: RealtimeEvent<MessageReadEvent> | null;
|
|
36
|
+
clearEvent: () => void;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Hook for subscribing to conversation read events
|
|
40
|
+
*/
|
|
41
|
+
export declare function useConversationReadEvents(): {
|
|
42
|
+
event: RealtimeEvent<ConversationReadEvent> | null;
|
|
43
|
+
clearEvent: () => void;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Hook for subscribing to all message events
|
|
47
|
+
* @param callback Optional callback function that will be called when any message event is received
|
|
48
|
+
*/
|
|
49
|
+
export declare function useAllMessageEvents(callback?: (eventType: EventType, data: any) => void): {
|
|
50
|
+
messageSent: RealtimeEvent<MessageSentEvent> | null;
|
|
51
|
+
messageEdited: RealtimeEvent<MessageEditedEvent> | null;
|
|
52
|
+
messageDeleted: RealtimeEvent<MessageDeletedEvent> | null;
|
|
53
|
+
messageRead: RealtimeEvent<MessageReadEvent> | null;
|
|
54
|
+
conversationRead: RealtimeEvent<ConversationReadEvent> | null;
|
|
55
|
+
clearEvents: () => void;
|
|
56
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ConnectionOptions } from './types';
|
|
3
|
+
import { useAllMessageEvents as useAllMessageEventsHook } from './hooks/useRealtime';
|
|
4
|
+
export * from './types';
|
|
5
|
+
export { LogLevel } from './utils/Logger';
|
|
6
|
+
export type { LoggerConfig } from './utils/Logger';
|
|
7
|
+
export { ChatApi } from './api/chatApi';
|
|
8
|
+
export { ChatProvider, useChatContext } from './context/ChatContext';
|
|
9
|
+
export { useConversations } from './hooks/useConversations';
|
|
10
|
+
export { useMessages } from './hooks/useMessages';
|
|
11
|
+
export { useFiles } from './hooks/useFiles';
|
|
12
|
+
export { useConnection } from './hooks/useConnection';
|
|
13
|
+
export { useClientProfile } from './hooks/useClientProfile';
|
|
14
|
+
export { useConversationDetails } from './hooks/useConversationDetails';
|
|
15
|
+
export type { Message, Conversation, MessagesPagination, MessagesResponse, ConnectionOptions, ClientProfileResponse } from './types';
|
|
16
|
+
export { useRealtime, useMessageSentEvents, useMessageEditedEvents, useMessageDeletedEvents } from './hooks/useRealtime';
|
|
17
|
+
export { useConversationManagement } from './hooks/useConversationManagements';
|
|
18
|
+
export { useBans } from './hooks/useBans';
|
|
19
|
+
export { useMessageManagement } from './hooks/useMessageManagements';
|
|
20
|
+
export { useCustomEvents } from './hooks/useCustomEvents';
|
|
21
|
+
export { useLogging } from './hooks/useLogging';
|
|
22
|
+
export declare const useAllMessageEvents: typeof useAllMessageEventsHook;
|
|
23
|
+
interface ChatClientProps {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
token?: string;
|
|
26
|
+
baseUrl?: string;
|
|
27
|
+
socketBaseUrl?: string;
|
|
28
|
+
connectionOptions?: ConnectionOptions;
|
|
29
|
+
client_id: string;
|
|
30
|
+
}
|
|
31
|
+
export declare const ChatClient: React.FC<ChatClientProps>;
|