@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.
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Type definitions for the Chat API
3
+ */
4
+ import { LoggerConfig } from './utils/Logger';
5
+ export declare enum ConnectionType {
6
+ WebSocket = "websocket",
7
+ LongPolling = "longpolling"
8
+ }
9
+ export declare enum ConnectionStatus {
10
+ Connected = "connected",
11
+ Connecting = "connecting",
12
+ Disconnected = "disconnected",
13
+ Error = "error"
14
+ }
15
+ export interface ConnectionConfig {
16
+ type: ConnectionType;
17
+ autoReconnect: boolean;
18
+ reconnectAttempts: number;
19
+ reconnectDelay: number;
20
+ logging?: Partial<LoggerConfig>;
21
+ onlyLongpolling?: boolean;
22
+ degradeWsOnFailure?: boolean;
23
+ wsFailureThreshold?: number;
24
+ wsDegradeTTLms?: number;
25
+ forceWebSocket?: boolean;
26
+ }
27
+ export interface ConnectionOptions {
28
+ connectionType?: ConnectionType;
29
+ autoReconnect?: boolean;
30
+ reconnectAttempts?: number;
31
+ reconnectDelay?: number;
32
+ logging?: Partial<LoggerConfig>;
33
+ onlyLongpolling?: boolean;
34
+ degradeWsOnFailure?: boolean;
35
+ wsFailureThreshold?: number;
36
+ wsDegradeTTLms?: number;
37
+ forceWebSocket?: boolean;
38
+ }
39
+ export declare enum EventType {
40
+ MessageSent = "message_sent",
41
+ MessageEdited = "message_edited",
42
+ MessageDeleted = "message_deleted",
43
+ MessageReceived = "message_received",
44
+ MessageRead = "message_read",
45
+ ConversationRead = "conversation_read"
46
+ }
47
+ export interface RealtimeEvent<T = any> {
48
+ type: EventType;
49
+ data: T;
50
+ }
51
+ export interface MessageSentEvent {
52
+ id: number;
53
+ content: string;
54
+ sender_client_id: string;
55
+ receiver_client_id: string;
56
+ sent_at: string;
57
+ is_read: boolean;
58
+ attachments?: Attachment[];
59
+ conversation_uid?: string;
60
+ }
61
+ export interface MessageEditedEvent {
62
+ msg_id: number;
63
+ new_content: string;
64
+ new_attachments?: Attachment[];
65
+ conversation_uid?: string;
66
+ }
67
+ export interface MessageDeletedEvent {
68
+ msg_id: number;
69
+ conversation_uid?: string;
70
+ }
71
+ export interface MessageReadEvent {
72
+ message_id: number;
73
+ reader_client_id: string;
74
+ conversation_uid: string;
75
+ sender_client_id?: string;
76
+ }
77
+ export interface ConversationReadEvent {
78
+ conversation_uid: string;
79
+ reader_client_id: string;
80
+ message_ids: number[];
81
+ other_client_id?: string;
82
+ }
83
+ export interface PollResponse {
84
+ events: RealtimeEvent[];
85
+ }
86
+ export interface QueuedMessage {
87
+ id: string;
88
+ message: SendMessageRequest;
89
+ attempts: number;
90
+ maxAttempts: number;
91
+ timestamp: number;
92
+ }
93
+ export interface AuthConfig {
94
+ token: string;
95
+ baseUrl: string;
96
+ socketBaseUrl: string;
97
+ client_id: string;
98
+ }
99
+ export interface User {
100
+ id: string;
101
+ client_id: string;
102
+ name: string;
103
+ avatar: string;
104
+ is_admin: boolean;
105
+ attributes: Record<string, any>;
106
+ file_storage_provider: string;
107
+ owner_client_id: string;
108
+ }
109
+ export interface Conversation {
110
+ id: string;
111
+ conversation_uid: string;
112
+ status: string;
113
+ user: User;
114
+ isArchived: boolean;
115
+ isCallCenter: boolean;
116
+ lastMessage: Message;
117
+ unreadCount: number;
118
+ }
119
+ export interface ConversationSearchResult {
120
+ conversation_uid: string;
121
+ search_term: string;
122
+ matching_messages: Message[];
123
+ count: number;
124
+ }
125
+ export interface Attachment {
126
+ id: number;
127
+ filename: string;
128
+ mime_type: string;
129
+ size_bytes: number;
130
+ url: string;
131
+ uploaded_at: string;
132
+ message_id?: number;
133
+ }
134
+ export interface SenderReceiverUser {
135
+ id: string;
136
+ client_id: string;
137
+ name: string;
138
+ avatar: string;
139
+ }
140
+ export interface Message {
141
+ id: number;
142
+ message: string;
143
+ sender: SenderReceiverUser;
144
+ receiver: SenderReceiverUser;
145
+ sender_client_id: string;
146
+ receiver_client_id: string;
147
+ edited: boolean;
148
+ conversation_uid: string;
149
+ sent_at: string;
150
+ status: string;
151
+ is_read: boolean;
152
+ attachments?: Attachment[];
153
+ }
154
+ export interface MessagesPagination {
155
+ page: number;
156
+ page_size: number;
157
+ total_pages: number;
158
+ total_items: number;
159
+ }
160
+ export interface MessagesResponse {
161
+ messages: Message[];
162
+ pagination: MessagesPagination;
163
+ }
164
+ export interface SendMessageRequest {
165
+ receiver_client_id: string;
166
+ content?: string;
167
+ attachments?: number[];
168
+ conversation_uid?: string;
169
+ }
170
+ export interface UpdateMessageRequest {
171
+ content: string;
172
+ attachments?: number[];
173
+ }
174
+ export interface ApiResponse {
175
+ message: string;
176
+ }
177
+ export interface ClientProfileResponse {
178
+ id: string;
179
+ client_id: string;
180
+ name: string;
181
+ avatar: string;
182
+ is_admin: boolean;
183
+ attributes: Record<string, any>;
184
+ file_storage_provider: string | null;
185
+ owner_client_id: string | null;
186
+ private_key?: string;
187
+ }
188
+ export interface SendMessageResponse {
189
+ message: Message;
190
+ }
191
+ export interface MarkConversationReadResponse extends ApiResponse {
192
+ marked_messages: number[];
193
+ count: number;
194
+ }
195
+ export interface UpdateMessageResponse {
196
+ message: Message;
197
+ }
198
+ export interface DeleteMessageResponse extends ApiResponse {
199
+ message_id: number;
200
+ }
201
+ export interface FileUploadResponse extends ApiResponse {
202
+ file_id: number;
203
+ filename: string;
204
+ storage_path: string;
205
+ mime_type: string;
206
+ size_bytes: number;
207
+ url: string;
208
+ uploaded_at: string;
209
+ }
210
+ export interface BanClientRequest {
211
+ client_id: string;
212
+ }
213
+ export interface UnbanClientRequest {
214
+ client_id: string;
215
+ }
216
+ export interface AdminBanClientRequest {
217
+ client_id: string;
218
+ reason?: string;
219
+ duration_days?: number;
220
+ }
221
+ export interface AdminUnbanClientRequest {
222
+ client_id: string;
223
+ }
224
+ export interface AdminBanInfo {
225
+ reason?: string;
226
+ expires_at?: string;
227
+ is_permanent: boolean;
228
+ }
229
+ export interface BanStatusResponse {
230
+ is_banned_by_you: boolean;
231
+ is_banned_by_admin: boolean;
232
+ admin_ban?: AdminBanInfo;
233
+ }
234
+ export interface ClientPreferences {
235
+ enable_read: boolean;
236
+ }
237
+ export interface ClientPreferencesResponse {
238
+ preferences: ClientPreferences;
239
+ client_id: number;
240
+ }
241
+ export interface UpdatePreferencesRequest {
242
+ preferences: Partial<ClientPreferences>;
243
+ }
244
+ export interface UpdatePreferencesResponse {
245
+ message: string;
246
+ preferences: ClientPreferences;
247
+ updated_at: string;
248
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Logger utility for detailed websocket connection logging
3
+ */
4
+ export declare enum LogLevel {
5
+ DEBUG = 0,
6
+ INFO = 1,
7
+ WARN = 2,
8
+ ERROR = 3,
9
+ NONE = 4
10
+ }
11
+ export interface LoggerConfig {
12
+ enabled: boolean;
13
+ level: LogLevel;
14
+ prefix?: string;
15
+ timestamp?: boolean;
16
+ includeData?: boolean;
17
+ prettyPrint?: boolean;
18
+ }
19
+ export declare class Logger {
20
+ private config;
21
+ constructor(config?: Partial<LoggerConfig>);
22
+ private shouldLog;
23
+ private formatMessage;
24
+ private formatData;
25
+ private maskSensitiveData;
26
+ debug(message: string, data?: any): void;
27
+ info(message: string, data?: any): void;
28
+ warn(message: string, data?: any): void;
29
+ error(message: string, data?: any): void;
30
+ group(label: string): void;
31
+ groupEnd(): void;
32
+ time(label: string): void;
33
+ timeEnd(label: string): void;
34
+ updateConfig(config: Partial<LoggerConfig>): void;
35
+ getConfig(): LoggerConfig;
36
+ }
37
+ export default Logger;
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@vserifsaglam/chat-react-client",
3
+ "version": "1.0.2",
4
+ "description": "Frontend library to easliy connect to the chat",
5
+ "author": "vahit",
6
+ "license": "MIT",
7
+ "repository": "",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.modern.js",
10
+ "source": "src/index.tsx",
11
+ "engines": {
12
+ "node": ">=10"
13
+ },
14
+ "scripts": {
15
+ "build": "microbundle-crl --no-compress --format modern,cjs",
16
+ "start": "microbundle-crl watch --no-compress --format modern,cjs",
17
+ "prepare": "run-s build",
18
+ "test": "run-s test:unit test:lint test:build",
19
+ "test:build": "run-s build",
20
+ "test:lint": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
21
+ "test:unit": "cross-env CI=1 react-scripts test --env=jsdom",
22
+ "test:watch": "react-scripts test --env=jsdom",
23
+ "predeploy": "cd example && yarn install && yarn run build",
24
+ "deploy": "gh-pages -d example/build"
25
+ },
26
+ "peerDependencies": {
27
+ "react": "^18.0.0"
28
+ },
29
+ "dependencies": {
30
+ "axios": "^0.21.1",
31
+ "babel-plugin-transform-async-to-promises": "0.8.18",
32
+ "socket.io-client": "4.8.1"
33
+ },
34
+ "devDependencies": {
35
+ "@testing-library/jest-dom": "^4.2.4",
36
+ "@testing-library/react": "^9.5.0",
37
+ "@testing-library/user-event": "^7.2.1",
38
+ "@types/jest": "^25.1.4",
39
+ "@types/node": "^12.12.38",
40
+ "@types/react": "^16.9.27",
41
+ "@types/react-dom": "^16.9.7",
42
+ "@typescript-eslint/eslint-plugin": "^2.26.0",
43
+ "@typescript-eslint/parser": "^2.26.0",
44
+ "microbundle-crl": "^0.13.10",
45
+ "babel-eslint": "^10.0.3",
46
+ "cross-env": "^7.0.2",
47
+ "eslint": "^6.8.0",
48
+ "eslint-config-prettier": "^6.7.0",
49
+ "eslint-config-standard": "^14.1.0",
50
+ "eslint-config-standard-react": "^9.2.0",
51
+ "eslint-plugin-import": "^2.18.2",
52
+ "eslint-plugin-node": "^11.0.0",
53
+ "eslint-plugin-prettier": "^3.1.1",
54
+ "eslint-plugin-promise": "^4.2.1",
55
+ "eslint-plugin-react": "^7.17.0",
56
+ "eslint-plugin-standard": "^4.0.1",
57
+ "gh-pages": "^2.2.0",
58
+ "npm-run-all": "^4.1.5",
59
+ "prettier": "^2.0.4",
60
+ "react": "^18.0.0",
61
+ "react-dom": "^18.0.0",
62
+ "react-scripts": "^3.4.1",
63
+ "typescript": "^3.7.5"
64
+ },
65
+ "files": [
66
+ "dist"
67
+ ]
68
+ }