@antzsoft/chat-core 1.2.1 → 1.2.3
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 +82 -2
- package/dist/index.cjs +134 -91
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -3
- package/dist/index.d.ts +18 -3
- package/dist/index.js +130 -88
- package/dist/index.js.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/{storage-BBScliNR.d.cts → storage-DO8QIqKq.d.cts} +27 -2
- package/dist/{storage-BBScliNR.d.ts → storage-DO8QIqKq.d.ts} +27 -2
- package/docs/integration-guide.html +300 -8
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as Attachment, C as CompressedFile, e as CompressionAlgorithm, f as CompressionConfig,
|
|
1
|
+
import { U as ResolvedCompressionConfig, n as LoginCredentials, c as AuthResponse, S as RegisterData, d as AuthTokens, a2 as User, a as AppConfig, Y as SendMessagePayload, k as CursorPaginatedResponse, M as Message, P as PaginatedResponse, w as MessageReceiptsResponse, h as ConversationListParams, g as Conversation, D as Participant, j as ConversationUnreadCount, _ as UnreadSummary, a3 as UserPreferences, V as ResolvedConfig, E as PersistStorage, I as PresignedUrlRequest, J as PresignedUrlResponse, F as FileResponse, m as FileType, A as AntzChatConfig, a1 as UploadableFile, B as BatchUploadResult } from './storage-DO8QIqKq.cjs';
|
|
2
|
+
export { b as Attachment, C as CompressedFile, e as CompressionAlgorithm, f as CompressionConfig, i as ConversationType, l as FileSizeLimits, L as LastReaction, o as MessageAckEvent, p as MessageContent, q as MessageDeletedEvent, r as MessageDeletedForMeEvent, s as MessageDeliveredEvent, t as MessageMetadata, u as MessageReaction, v as MessageReceiptEntry, x as MessageReplyReference, y as MessageUpdatedEvent, z as MessagesDeliveredEvent, N as NewMessageEvent, O as OptimisticAttachment, G as PlatformCompressFn, H as PlatformUploadFn, Q as QuietHours, R as ReactionUpdatedEvent, K as ReadReceiptEvent, T as ReplyAttachmentSnapshot, W as ResolvedFileSizeLimits, X as SendMessageAttachment, Z as TypingIndicatorEvent, $ as UploadConfig, a0 as UploadProgress, a4 as UserStatusEvent, a5 as resolveConfig, a6 as storageApi, a7 as uploadBatch } from './storage-DO8QIqKq.cjs';
|
|
3
3
|
import { AxiosInstance } from 'axios';
|
|
4
4
|
import { Socket } from 'socket.io-client';
|
|
5
5
|
import * as zustand_middleware from 'zustand/middleware';
|
|
@@ -72,6 +72,7 @@ declare const messagesApi: {
|
|
|
72
72
|
pin(messageId: string): Promise<Message>;
|
|
73
73
|
unpin(messageId: string): Promise<Message>;
|
|
74
74
|
getPinned(conversationId: string): Promise<Message[]>;
|
|
75
|
+
getReceipts(messageId: string): Promise<MessageReceiptsResponse>;
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
declare function normalizeConversation(conv: any): Conversation;
|
|
@@ -420,6 +421,19 @@ interface ChatState {
|
|
|
420
421
|
}
|
|
421
422
|
declare const useChatStore: zustand.UseBoundStore<zustand.StoreApi<ChatState>>;
|
|
422
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Resolves viewer-aware display text for system messages.
|
|
426
|
+
*
|
|
427
|
+
* The server stores a neutral third-person text in content.text (used for push
|
|
428
|
+
* notifications and exports) and structured actor/target fields in metadata.
|
|
429
|
+
* This function uses those fields plus the current viewer's userId to produce
|
|
430
|
+
* the correct first-person variant ("You removed Ajay", "Anil removed you", etc.).
|
|
431
|
+
*
|
|
432
|
+
* Backward compatible: if the server does not send actorUserId (old server), the
|
|
433
|
+
* raw content.text is returned unchanged so old behaviour is preserved.
|
|
434
|
+
*/
|
|
435
|
+
declare function resolveSystemMessageText(message: Message, currentUserId: string): string;
|
|
436
|
+
|
|
423
437
|
interface ClientSocketHandle {
|
|
424
438
|
emit: typeof socketEmit;
|
|
425
439
|
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
@@ -476,6 +490,7 @@ declare class AntzChatClient {
|
|
|
476
490
|
pin(messageId: string): Promise<Message>;
|
|
477
491
|
unpin(messageId: string): Promise<Message>;
|
|
478
492
|
getPinned(conversationId: string): Promise<Message[]>;
|
|
493
|
+
getReceipts(messageId: string): Promise<MessageReceiptsResponse>;
|
|
479
494
|
};
|
|
480
495
|
readonly conversations: {
|
|
481
496
|
list(params?: ConversationListParams): Promise<PaginatedResponse<Conversation>>;
|
|
@@ -547,4 +562,4 @@ declare class AntzChatClient {
|
|
|
547
562
|
uploadIcon(conversationId: string, file: UploadableFile): Promise<Conversation>;
|
|
548
563
|
}
|
|
549
564
|
|
|
550
|
-
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, Conversation, ConversationListParams, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CursorPaginatedResponse, FileResponse, FileType, type LastReadEntry, type ListMessagesParams, LoginCredentials, Message, type MobileDeviceToken, PaginatedResponse, Participant, PersistStorage, PresignedUrlRequest, PresignedUrlResponse, RegisterData, type RegisterDeviceTokenPayload, ResolvedCompressionConfig, ResolvedConfig, type SearchParams, type SendData, SendMessagePayload, type SocketStatus, type StatusListener, type TokenStore, UnreadSummary, type UpdateConversationData, type UpdateProfilePayload, UploadableFile, User, UserPreferences, type WebPushDeviceToken, appConfigApi, authApi, connectSocket, conversationsApi, createAuthStore, devicesApi, disconnectSocket, getApiClient, getAuthStore, getCompressionStrategy, getSocket, getSocketStatus, initApiClient, initAuthStore, messagesApi, normalizeConversation, onSocketStatus, reconnectSocket, refreshSocketAuth, resetAuthStore, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
|
565
|
+
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, Conversation, ConversationListParams, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CursorPaginatedResponse, FileResponse, FileType, type LastReadEntry, type ListMessagesParams, LoginCredentials, Message, MessageReceiptsResponse, type MobileDeviceToken, PaginatedResponse, Participant, PersistStorage, PresignedUrlRequest, PresignedUrlResponse, RegisterData, type RegisterDeviceTokenPayload, ResolvedCompressionConfig, ResolvedConfig, type SearchParams, type SendData, SendMessagePayload, type SocketStatus, type StatusListener, type TokenStore, UnreadSummary, type UpdateConversationData, type UpdateProfilePayload, UploadableFile, User, UserPreferences, type WebPushDeviceToken, appConfigApi, authApi, connectSocket, conversationsApi, createAuthStore, devicesApi, disconnectSocket, getApiClient, getAuthStore, getCompressionStrategy, getSocket, getSocketStatus, initApiClient, initAuthStore, messagesApi, normalizeConversation, onSocketStatus, reconnectSocket, refreshSocketAuth, resetAuthStore, resolveSystemMessageText, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { b as Attachment, C as CompressedFile, e as CompressionAlgorithm, f as CompressionConfig,
|
|
1
|
+
import { U as ResolvedCompressionConfig, n as LoginCredentials, c as AuthResponse, S as RegisterData, d as AuthTokens, a2 as User, a as AppConfig, Y as SendMessagePayload, k as CursorPaginatedResponse, M as Message, P as PaginatedResponse, w as MessageReceiptsResponse, h as ConversationListParams, g as Conversation, D as Participant, j as ConversationUnreadCount, _ as UnreadSummary, a3 as UserPreferences, V as ResolvedConfig, E as PersistStorage, I as PresignedUrlRequest, J as PresignedUrlResponse, F as FileResponse, m as FileType, A as AntzChatConfig, a1 as UploadableFile, B as BatchUploadResult } from './storage-DO8QIqKq.js';
|
|
2
|
+
export { b as Attachment, C as CompressedFile, e as CompressionAlgorithm, f as CompressionConfig, i as ConversationType, l as FileSizeLimits, L as LastReaction, o as MessageAckEvent, p as MessageContent, q as MessageDeletedEvent, r as MessageDeletedForMeEvent, s as MessageDeliveredEvent, t as MessageMetadata, u as MessageReaction, v as MessageReceiptEntry, x as MessageReplyReference, y as MessageUpdatedEvent, z as MessagesDeliveredEvent, N as NewMessageEvent, O as OptimisticAttachment, G as PlatformCompressFn, H as PlatformUploadFn, Q as QuietHours, R as ReactionUpdatedEvent, K as ReadReceiptEvent, T as ReplyAttachmentSnapshot, W as ResolvedFileSizeLimits, X as SendMessageAttachment, Z as TypingIndicatorEvent, $ as UploadConfig, a0 as UploadProgress, a4 as UserStatusEvent, a5 as resolveConfig, a6 as storageApi, a7 as uploadBatch } from './storage-DO8QIqKq.js';
|
|
3
3
|
import { AxiosInstance } from 'axios';
|
|
4
4
|
import { Socket } from 'socket.io-client';
|
|
5
5
|
import * as zustand_middleware from 'zustand/middleware';
|
|
@@ -72,6 +72,7 @@ declare const messagesApi: {
|
|
|
72
72
|
pin(messageId: string): Promise<Message>;
|
|
73
73
|
unpin(messageId: string): Promise<Message>;
|
|
74
74
|
getPinned(conversationId: string): Promise<Message[]>;
|
|
75
|
+
getReceipts(messageId: string): Promise<MessageReceiptsResponse>;
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
declare function normalizeConversation(conv: any): Conversation;
|
|
@@ -420,6 +421,19 @@ interface ChatState {
|
|
|
420
421
|
}
|
|
421
422
|
declare const useChatStore: zustand.UseBoundStore<zustand.StoreApi<ChatState>>;
|
|
422
423
|
|
|
424
|
+
/**
|
|
425
|
+
* Resolves viewer-aware display text for system messages.
|
|
426
|
+
*
|
|
427
|
+
* The server stores a neutral third-person text in content.text (used for push
|
|
428
|
+
* notifications and exports) and structured actor/target fields in metadata.
|
|
429
|
+
* This function uses those fields plus the current viewer's userId to produce
|
|
430
|
+
* the correct first-person variant ("You removed Ajay", "Anil removed you", etc.).
|
|
431
|
+
*
|
|
432
|
+
* Backward compatible: if the server does not send actorUserId (old server), the
|
|
433
|
+
* raw content.text is returned unchanged so old behaviour is preserved.
|
|
434
|
+
*/
|
|
435
|
+
declare function resolveSystemMessageText(message: Message, currentUserId: string): string;
|
|
436
|
+
|
|
423
437
|
interface ClientSocketHandle {
|
|
424
438
|
emit: typeof socketEmit;
|
|
425
439
|
on(event: string, handler: (...args: unknown[]) => void): void;
|
|
@@ -476,6 +490,7 @@ declare class AntzChatClient {
|
|
|
476
490
|
pin(messageId: string): Promise<Message>;
|
|
477
491
|
unpin(messageId: string): Promise<Message>;
|
|
478
492
|
getPinned(conversationId: string): Promise<Message[]>;
|
|
493
|
+
getReceipts(messageId: string): Promise<MessageReceiptsResponse>;
|
|
479
494
|
};
|
|
480
495
|
readonly conversations: {
|
|
481
496
|
list(params?: ConversationListParams): Promise<PaginatedResponse<Conversation>>;
|
|
@@ -547,4 +562,4 @@ declare class AntzChatClient {
|
|
|
547
562
|
uploadIcon(conversationId: string, file: UploadableFile): Promise<Conversation>;
|
|
548
563
|
}
|
|
549
564
|
|
|
550
|
-
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, Conversation, ConversationListParams, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CursorPaginatedResponse, FileResponse, FileType, type LastReadEntry, type ListMessagesParams, LoginCredentials, Message, type MobileDeviceToken, PaginatedResponse, Participant, PersistStorage, PresignedUrlRequest, PresignedUrlResponse, RegisterData, type RegisterDeviceTokenPayload, ResolvedCompressionConfig, ResolvedConfig, type SearchParams, type SendData, SendMessagePayload, type SocketStatus, type StatusListener, type TokenStore, UnreadSummary, type UpdateConversationData, type UpdateProfilePayload, UploadableFile, User, UserPreferences, type WebPushDeviceToken, appConfigApi, authApi, connectSocket, conversationsApi, createAuthStore, devicesApi, disconnectSocket, getApiClient, getAuthStore, getCompressionStrategy, getSocket, getSocketStatus, initApiClient, initAuthStore, messagesApi, normalizeConversation, onSocketStatus, reconnectSocket, refreshSocketAuth, resetAuthStore, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
|
565
|
+
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, Conversation, ConversationListParams, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CursorPaginatedResponse, FileResponse, FileType, type LastReadEntry, type ListMessagesParams, LoginCredentials, Message, MessageReceiptsResponse, type MobileDeviceToken, PaginatedResponse, Participant, PersistStorage, PresignedUrlRequest, PresignedUrlResponse, RegisterData, type RegisterDeviceTokenPayload, ResolvedCompressionConfig, ResolvedConfig, type SearchParams, type SendData, SendMessagePayload, type SocketStatus, type StatusListener, type TokenStore, UnreadSummary, type UpdateConversationData, type UpdateProfilePayload, UploadableFile, User, UserPreferences, type WebPushDeviceToken, appConfigApi, authApi, connectSocket, conversationsApi, createAuthStore, devicesApi, disconnectSocket, getApiClient, getAuthStore, getCompressionStrategy, getSocket, getSocketStatus, initApiClient, initAuthStore, messagesApi, normalizeConversation, onSocketStatus, reconnectSocket, refreshSocketAuth, resetAuthStore, resolveSystemMessageText, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
package/dist/index.js
CHANGED
|
@@ -128,6 +128,123 @@ var appConfigApi = {
|
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
+
// src/stores/auth.store.ts
|
|
132
|
+
import { create } from "zustand";
|
|
133
|
+
import { persist } from "zustand/middleware";
|
|
134
|
+
function createAuthStore(storage) {
|
|
135
|
+
if (!storage) throw new Error("[AntzChat] createAuthStore requires a valid PersistStorage \u2014 received undefined. Make sure the SDK config is fully resolved before initializing the store.");
|
|
136
|
+
const ref = { store: null };
|
|
137
|
+
const store = create()(
|
|
138
|
+
persist(
|
|
139
|
+
(set) => ({
|
|
140
|
+
user: null,
|
|
141
|
+
tokens: null,
|
|
142
|
+
isAuthenticated: false,
|
|
143
|
+
isLoading: false,
|
|
144
|
+
isHydrated: false,
|
|
145
|
+
setAuth: (user, tokens) => set({ user, tokens, isAuthenticated: true, isLoading: false }),
|
|
146
|
+
setTokens: (tokens) => set({ tokens }),
|
|
147
|
+
setUser: (user) => set({ user }),
|
|
148
|
+
logout: () => set({ user: null, tokens: null, isAuthenticated: false, isLoading: false }),
|
|
149
|
+
setLoading: (isLoading) => set({ isLoading }),
|
|
150
|
+
setHydrated: (isHydrated) => set({ isHydrated })
|
|
151
|
+
}),
|
|
152
|
+
{
|
|
153
|
+
name: "antz-chat-auth",
|
|
154
|
+
storage: {
|
|
155
|
+
getItem: (name) => {
|
|
156
|
+
const result = storage.getItem(name);
|
|
157
|
+
if (result instanceof Promise) {
|
|
158
|
+
return result.then((str) => str ? JSON.parse(str) : null);
|
|
159
|
+
}
|
|
160
|
+
return result ? JSON.parse(result) : null;
|
|
161
|
+
},
|
|
162
|
+
setItem: (name, value) => {
|
|
163
|
+
storage.setItem(name, JSON.stringify(value));
|
|
164
|
+
},
|
|
165
|
+
removeItem: (name) => storage.removeItem(name)
|
|
166
|
+
},
|
|
167
|
+
partialize: (state) => ({
|
|
168
|
+
user: state.user,
|
|
169
|
+
tokens: state.tokens,
|
|
170
|
+
isAuthenticated: state.isAuthenticated
|
|
171
|
+
}),
|
|
172
|
+
onRehydrateStorage: () => (state, error) => {
|
|
173
|
+
if (error) {
|
|
174
|
+
console.warn("[AntzChat] Auth store rehydration failed:", error);
|
|
175
|
+
}
|
|
176
|
+
ref.store?.setState({ isHydrated: true });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
)
|
|
180
|
+
);
|
|
181
|
+
ref.store = store;
|
|
182
|
+
if (!store.getState().isHydrated) {
|
|
183
|
+
const hydrationTimeout = setTimeout(() => {
|
|
184
|
+
if (!store.getState().isHydrated) {
|
|
185
|
+
store.setState({ isHydrated: true });
|
|
186
|
+
}
|
|
187
|
+
}, 3e3);
|
|
188
|
+
const unsub = store.subscribe((s) => {
|
|
189
|
+
if (s.isHydrated) {
|
|
190
|
+
clearTimeout(hydrationTimeout);
|
|
191
|
+
unsub();
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
const tokenStore = {
|
|
196
|
+
getAccessToken: () => store.getState().tokens?.accessToken,
|
|
197
|
+
getRefreshToken: () => store.getState().tokens?.refreshToken,
|
|
198
|
+
setTokens: (tokens) => store.getState().setTokens(tokens),
|
|
199
|
+
clearTokens: () => store.getState().logout()
|
|
200
|
+
};
|
|
201
|
+
return { useAuthStore: store, authTokenStore: tokenStore };
|
|
202
|
+
}
|
|
203
|
+
var _authStore = null;
|
|
204
|
+
function initAuthStore(storage) {
|
|
205
|
+
if (!_authStore) {
|
|
206
|
+
_authStore = createAuthStore(storage);
|
|
207
|
+
}
|
|
208
|
+
return _authStore;
|
|
209
|
+
}
|
|
210
|
+
function getAuthStore() {
|
|
211
|
+
if (!_authStore) throw new Error("[AntzChat] Auth store not initialized. Call initAuthStore first.");
|
|
212
|
+
return _authStore;
|
|
213
|
+
}
|
|
214
|
+
function resetAuthStore() {
|
|
215
|
+
_authStore = null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/utils/resolveSystemMessageText.ts
|
|
219
|
+
function resolveSystemMessageText(message, currentUserId) {
|
|
220
|
+
const m = message.metadata;
|
|
221
|
+
if (!m?.systemOperationType || !m.actorUserId) {
|
|
222
|
+
return message.content.text ?? "";
|
|
223
|
+
}
|
|
224
|
+
const iActor = m.actorUserId === currentUserId;
|
|
225
|
+
const iTarget = m.targetUserId === currentUserId;
|
|
226
|
+
const actor = iActor ? "You" : m.actorUserName ?? "Someone";
|
|
227
|
+
const target = iTarget ? "you" : m.targetUserName ?? "a member";
|
|
228
|
+
switch (m.systemOperationType) {
|
|
229
|
+
case "group_created":
|
|
230
|
+
return iActor ? "You created the group" : `${actor} created the group`;
|
|
231
|
+
case "user_added":
|
|
232
|
+
return iActor ? `You added ${target}` : `${actor} added ${target}`;
|
|
233
|
+
case "user_removed":
|
|
234
|
+
return iActor ? `You removed ${target}` : `${actor} removed ${target}`;
|
|
235
|
+
case "user_left":
|
|
236
|
+
return iActor ? "You left the group" : `${actor} left the group`;
|
|
237
|
+
case "admin_promoted":
|
|
238
|
+
return iActor ? `You made ${target} an admin` : `${actor} made ${target} an admin`;
|
|
239
|
+
case "admin_demoted":
|
|
240
|
+
return iActor ? `You removed ${target} as admin` : `${actor} removed ${target} as admin`;
|
|
241
|
+
case "group_updated":
|
|
242
|
+
return iActor ? "You updated the group" : `${actor} updated the group`;
|
|
243
|
+
default:
|
|
244
|
+
return message.content.text ?? "";
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
131
248
|
// src/api/messages.ts
|
|
132
249
|
var messagesApi = {
|
|
133
250
|
async list(conversationId, params = {}) {
|
|
@@ -140,7 +257,14 @@ var messagesApi = {
|
|
|
140
257
|
`/conversations/${conversationId}/messages`,
|
|
141
258
|
{ params: serverParams }
|
|
142
259
|
);
|
|
143
|
-
|
|
260
|
+
const currentUserId = getAuthStore().useAuthStore.getState().user?.id;
|
|
261
|
+
if (!currentUserId) return data;
|
|
262
|
+
return {
|
|
263
|
+
...data,
|
|
264
|
+
data: data.data.map(
|
|
265
|
+
(m) => m.content.type === "system" ? { ...m, content: { ...m.content, text: resolveSystemMessageText(m, currentUserId) } } : m
|
|
266
|
+
)
|
|
267
|
+
};
|
|
144
268
|
},
|
|
145
269
|
async get(messageId) {
|
|
146
270
|
const { data } = await getApiClient().get(`/messages/${messageId}`);
|
|
@@ -207,6 +331,10 @@ var messagesApi = {
|
|
|
207
331
|
async getPinned(conversationId) {
|
|
208
332
|
const { data } = await getApiClient().get(`/conversations/${conversationId}/pinned-messages`);
|
|
209
333
|
return data;
|
|
334
|
+
},
|
|
335
|
+
async getReceipts(messageId) {
|
|
336
|
+
const { data } = await getApiClient().get(`/messages/${messageId}/receipts`);
|
|
337
|
+
return data;
|
|
210
338
|
}
|
|
211
339
|
};
|
|
212
340
|
|
|
@@ -940,93 +1068,6 @@ var socketEmit = {
|
|
|
940
1068
|
}
|
|
941
1069
|
};
|
|
942
1070
|
|
|
943
|
-
// src/stores/auth.store.ts
|
|
944
|
-
import { create } from "zustand";
|
|
945
|
-
import { persist } from "zustand/middleware";
|
|
946
|
-
function createAuthStore(storage) {
|
|
947
|
-
if (!storage) throw new Error("[AntzChat] createAuthStore requires a valid PersistStorage \u2014 received undefined. Make sure the SDK config is fully resolved before initializing the store.");
|
|
948
|
-
const ref = { store: null };
|
|
949
|
-
const store = create()(
|
|
950
|
-
persist(
|
|
951
|
-
(set) => ({
|
|
952
|
-
user: null,
|
|
953
|
-
tokens: null,
|
|
954
|
-
isAuthenticated: false,
|
|
955
|
-
isLoading: false,
|
|
956
|
-
isHydrated: false,
|
|
957
|
-
setAuth: (user, tokens) => set({ user, tokens, isAuthenticated: true, isLoading: false }),
|
|
958
|
-
setTokens: (tokens) => set({ tokens }),
|
|
959
|
-
setUser: (user) => set({ user }),
|
|
960
|
-
logout: () => set({ user: null, tokens: null, isAuthenticated: false, isLoading: false }),
|
|
961
|
-
setLoading: (isLoading) => set({ isLoading }),
|
|
962
|
-
setHydrated: (isHydrated) => set({ isHydrated })
|
|
963
|
-
}),
|
|
964
|
-
{
|
|
965
|
-
name: "antz-chat-auth",
|
|
966
|
-
storage: {
|
|
967
|
-
getItem: (name) => {
|
|
968
|
-
const result = storage.getItem(name);
|
|
969
|
-
if (result instanceof Promise) {
|
|
970
|
-
return result.then((str) => str ? JSON.parse(str) : null);
|
|
971
|
-
}
|
|
972
|
-
return result ? JSON.parse(result) : null;
|
|
973
|
-
},
|
|
974
|
-
setItem: (name, value) => {
|
|
975
|
-
storage.setItem(name, JSON.stringify(value));
|
|
976
|
-
},
|
|
977
|
-
removeItem: (name) => storage.removeItem(name)
|
|
978
|
-
},
|
|
979
|
-
partialize: (state) => ({
|
|
980
|
-
user: state.user,
|
|
981
|
-
tokens: state.tokens,
|
|
982
|
-
isAuthenticated: state.isAuthenticated
|
|
983
|
-
}),
|
|
984
|
-
onRehydrateStorage: () => (state, error) => {
|
|
985
|
-
if (error) {
|
|
986
|
-
console.warn("[AntzChat] Auth store rehydration failed:", error);
|
|
987
|
-
}
|
|
988
|
-
ref.store?.setState({ isHydrated: true });
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
)
|
|
992
|
-
);
|
|
993
|
-
ref.store = store;
|
|
994
|
-
if (!store.getState().isHydrated) {
|
|
995
|
-
const hydrationTimeout = setTimeout(() => {
|
|
996
|
-
if (!store.getState().isHydrated) {
|
|
997
|
-
store.setState({ isHydrated: true });
|
|
998
|
-
}
|
|
999
|
-
}, 3e3);
|
|
1000
|
-
const unsub = store.subscribe((s) => {
|
|
1001
|
-
if (s.isHydrated) {
|
|
1002
|
-
clearTimeout(hydrationTimeout);
|
|
1003
|
-
unsub();
|
|
1004
|
-
}
|
|
1005
|
-
});
|
|
1006
|
-
}
|
|
1007
|
-
const tokenStore = {
|
|
1008
|
-
getAccessToken: () => store.getState().tokens?.accessToken,
|
|
1009
|
-
getRefreshToken: () => store.getState().tokens?.refreshToken,
|
|
1010
|
-
setTokens: (tokens) => store.getState().setTokens(tokens),
|
|
1011
|
-
clearTokens: () => store.getState().logout()
|
|
1012
|
-
};
|
|
1013
|
-
return { useAuthStore: store, authTokenStore: tokenStore };
|
|
1014
|
-
}
|
|
1015
|
-
var _authStore = null;
|
|
1016
|
-
function initAuthStore(storage) {
|
|
1017
|
-
if (!_authStore) {
|
|
1018
|
-
_authStore = createAuthStore(storage);
|
|
1019
|
-
}
|
|
1020
|
-
return _authStore;
|
|
1021
|
-
}
|
|
1022
|
-
function getAuthStore() {
|
|
1023
|
-
if (!_authStore) throw new Error("[AntzChat] Auth store not initialized. Call initAuthStore first.");
|
|
1024
|
-
return _authStore;
|
|
1025
|
-
}
|
|
1026
|
-
function resetAuthStore() {
|
|
1027
|
-
_authStore = null;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
1071
|
// src/client-facade.ts
|
|
1031
1072
|
var AntzChatClient = class {
|
|
1032
1073
|
constructor(rawConfig) {
|
|
@@ -1099,6 +1140,7 @@ export {
|
|
|
1099
1140
|
refreshSocketAuth,
|
|
1100
1141
|
resetAuthStore,
|
|
1101
1142
|
resolveConfig,
|
|
1143
|
+
resolveSystemMessageText,
|
|
1102
1144
|
setApiClientInstance,
|
|
1103
1145
|
setTransitSession,
|
|
1104
1146
|
socketEmit,
|