@antzsoft/chat-core 1.2.5 → 1.2.7
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 +505 -1
- package/dist/{chunk-ZNA6B2R5.js → chunk-XTQYF5HU.js} +99 -4
- package/dist/chunk-XTQYF5HU.js.map +1 -0
- package/dist/index.cjs +158 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -3
- package/dist/index.d.ts +62 -3
- package/dist/index.js +64 -13
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +6 -1
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +1 -1
- package/dist/{storage-CctLCOnZ.d.cts → storage-CW70b4vi.d.cts} +53 -1
- package/dist/{storage-CctLCOnZ.d.ts → storage-CW70b4vi.d.ts} +53 -1
- package/docs/integration-guide.html +988 -114
- package/package.json +1 -1
- package/dist/chunk-ZNA6B2R5.js.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as ResolvedCompressionConfig, L as LoginCredentials, A as AuthResponse, a as RegisterData, b as AuthTokens, U as User, c as AppConfig, S as SendMessagePayload,
|
|
2
|
-
export {
|
|
1
|
+
import { R as ResolvedCompressionConfig, L as LoginCredentials, A as AuthResponse, a as RegisterData, b as AuthTokens, U as User, C as CrossConversationSyncResponse, c as ConversationSyncResponse, d as AppConfig, S as SendMessagePayload, e as CursorPaginatedResponse, M as Message, P as PaginatedResponse, f as MessageReceiptsResponse, g as ConversationListParams, h as Conversation, i as Participant, j as ConversationUnreadCount, k as UnreadSummary, l as UserPreferences, m as ResolvedConfig, n as PersistStorage, o as PresignedUrlRequest, p as PresignedUrlResponse, F as FileResponse, q as CompletedPart, r as FileType, s as AntzChatConfig, t as UploadableFile, B as BatchUploadResult } from './storage-CW70b4vi.cjs';
|
|
2
|
+
export { u as Attachment, v as CompressedFile, w as CompressionAlgorithm, x as CompressionConfig, y as ConversationType, z as FileSizeLimits, D as LastReaction, E as MessageAckEvent, G as MessageContent, H as MessageDeletedEvent, I as MessageDeletedForMeEvent, J as MessageDeliveredEvent, K as MessageMetadata, N as MessageReaction, O as MessageReceiptEntry, Q as MessageReplyReference, T as MessageStarUpdatedEvent, V as MessageUpdatedEvent, W as MessagesDeliveredEvent, X as MultipartPartUrl, Y as MultipartUploadInfo, Z as NewMessageEvent, _ as OptimisticAttachment, $ as PlatformCompressFn, a0 as PlatformUploadFn, a1 as PlatformUploadPartFn, a2 as QuietHours, a3 as ReactionUpdatedEvent, a4 as ReadReceiptEvent, a5 as ReplyAttachmentSnapshot, a6 as ResolvedFileSizeLimits, a7 as SendMessageAttachment, a8 as SyncDeletedForMe, a9 as SyncParticipantChange, aa as SyncReactions, ab as SyncReadReceipt, ac as SyncStarEntry, ad as SystemMessageMetadata, ae as TypingIndicatorEvent, af as UploadConfig, ag as UploadProgress, ah as UserStatusEvent, ai as resolveConfig, aj as storageApi, ak as uploadBatch } from './storage-CW70b4vi.cjs';
|
|
3
3
|
import { AxiosInstance } from 'axios';
|
|
4
4
|
import { Socket } from 'socket.io-client';
|
|
5
5
|
import * as zustand_middleware from 'zustand/middleware';
|
|
@@ -26,6 +26,23 @@ declare const authApi: {
|
|
|
26
26
|
}>;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
declare const syncApi: {
|
|
30
|
+
/**
|
|
31
|
+
* Cross-conversation delta sync — call on every socket reconnect.
|
|
32
|
+
* `since` is the ISO timestamp returned as `syncedAt` from the previous call.
|
|
33
|
+
* Returns `stale: true` (with empty arrays) when the gap exceeds 60 days —
|
|
34
|
+
* the app should mark all conversations `needs_refresh` and lazy-sync on open.
|
|
35
|
+
*/
|
|
36
|
+
pull(since: string): Promise<CrossConversationSyncResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Per-conversation delta sync — call when a conversation has `needs_refresh = true`
|
|
39
|
+
* or on fresh install (omit `since` to receive the full message history).
|
|
40
|
+
* Covers messages, deletedForMe, full reaction state, stars, participant changes,
|
|
41
|
+
* and read receipts — everything needed to make local SQLite authoritative.
|
|
42
|
+
*/
|
|
43
|
+
pullConversation(conversationId: string, since?: string): Promise<ConversationSyncResponse>;
|
|
44
|
+
};
|
|
45
|
+
|
|
29
46
|
declare const appConfigApi: {
|
|
30
47
|
get(): Promise<AppConfig>;
|
|
31
48
|
};
|
|
@@ -123,6 +140,7 @@ declare const conversationsApi: {
|
|
|
123
140
|
*/
|
|
124
141
|
uploadIcon(conversationId: string, fileId: string): Promise<Conversation>;
|
|
125
142
|
removeIcon(conversationId: string): Promise<Conversation>;
|
|
143
|
+
clearChat(conversationId: string): Promise<void>;
|
|
126
144
|
};
|
|
127
145
|
|
|
128
146
|
/** Shared fields for every device registration. */
|
|
@@ -267,6 +285,7 @@ declare const socketEmit: {
|
|
|
267
285
|
updateMessage(messageId: string, text: string): Promise<unknown>;
|
|
268
286
|
deleteMessage(messageId: string): Promise<unknown>;
|
|
269
287
|
deleteMessageForMe(messageId: string): Promise<unknown>;
|
|
288
|
+
clearChat(conversationId: string): Promise<unknown>;
|
|
270
289
|
addReaction(messageId: string, emoji: string): Promise<unknown>;
|
|
271
290
|
removeReaction(messageId: string, emoji: string): Promise<unknown>;
|
|
272
291
|
pinMessage(messageId: string): Promise<unknown>;
|
|
@@ -453,6 +472,45 @@ interface ChatState {
|
|
|
453
472
|
}
|
|
454
473
|
declare const useChatStore: zustand.UseBoundStore<zustand.StoreApi<ChatState>>;
|
|
455
474
|
|
|
475
|
+
declare class AntzChatError extends Error {
|
|
476
|
+
readonly code: string;
|
|
477
|
+
readonly retryable: boolean;
|
|
478
|
+
readonly context?: Record<string, unknown>;
|
|
479
|
+
constructor(code: string, message: string, retryable?: boolean, context?: Record<string, unknown>);
|
|
480
|
+
}
|
|
481
|
+
/** Thrown on 401 (after refresh also fails) or when no refresh token exists. */
|
|
482
|
+
declare class AntzChatAuthError extends AntzChatError {
|
|
483
|
+
constructor(message: string, code?: string, context?: Record<string, unknown>);
|
|
484
|
+
}
|
|
485
|
+
/** Thrown on 400 / 422 — bad input, validation failure. */
|
|
486
|
+
declare class AntzChatValidationError extends AntzChatError {
|
|
487
|
+
/** Server-returned field error array (when the server sends message as string[]). */
|
|
488
|
+
readonly fields?: string[];
|
|
489
|
+
constructor(message: string | string[], context?: Record<string, unknown>);
|
|
490
|
+
}
|
|
491
|
+
/** Thrown on network failures, timeouts, socket disconnections, and queue overflow. retryable = true. */
|
|
492
|
+
declare class AntzChatNetworkError extends AntzChatError {
|
|
493
|
+
constructor(message: string, code?: string, context?: Record<string, unknown>);
|
|
494
|
+
}
|
|
495
|
+
/** Thrown on 403 — insufficient permissions. */
|
|
496
|
+
declare class AntzChatPermissionError extends AntzChatError {
|
|
497
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
498
|
+
}
|
|
499
|
+
/** Thrown on 5xx or other unexpected server errors. retryable = true. */
|
|
500
|
+
declare class AntzChatServerError extends AntzChatError {
|
|
501
|
+
readonly httpStatus?: number;
|
|
502
|
+
constructor(message: string, httpStatus?: number, context?: Record<string, unknown>);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Converts a raw axios error (or any unknown throw) into a typed AntzChatError.
|
|
506
|
+
*
|
|
507
|
+
* Call site: client.ts response interceptor — runs AFTER transit decryption,
|
|
508
|
+
* so error.response.data is always plaintext by the time this function sees it.
|
|
509
|
+
* If decryption itself failed, error.response.data remains the raw encrypted
|
|
510
|
+
* envelope — detected via isTransitEnvelope() and noted in context.
|
|
511
|
+
*/
|
|
512
|
+
declare function normalizeAxiosError(error: unknown): AntzChatError;
|
|
513
|
+
|
|
456
514
|
/**
|
|
457
515
|
* Resolves viewer-aware display text for system messages.
|
|
458
516
|
*
|
|
@@ -544,6 +602,7 @@ declare class AntzChatClient {
|
|
|
544
602
|
getUnreadSummary(): Promise<UnreadSummary>;
|
|
545
603
|
uploadIcon(conversationId: string, fileId: string): Promise<Conversation>;
|
|
546
604
|
removeIcon(conversationId: string): Promise<Conversation>;
|
|
605
|
+
clearChat(conversationId: string): Promise<void>;
|
|
547
606
|
};
|
|
548
607
|
readonly storage: {
|
|
549
608
|
requestPresignedUrl(payload: PresignedUrlRequest): Promise<PresignedUrlResponse>;
|
|
@@ -595,4 +654,4 @@ declare class AntzChatClient {
|
|
|
595
654
|
uploadIcon(conversationId: string, file: UploadableFile): Promise<Conversation>;
|
|
596
655
|
}
|
|
597
656
|
|
|
598
|
-
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, CompletedPart, 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, createRestTransitSession, decryptPayload, devicesApi, disconnectSocket, encryptPayload, fetchServerKeys, generateEphemeralKey, getApiClient, getAuthStore, getCompressionStrategy, getSessionId, getSessionKey, getSocket, getSocketStatus, initApiClient, initAuthStore, isTransitEnvelope, messagesApi, normalizeConversation, onSocketStatus, performHandshake, reconnectSocket, refreshSocketAuth, resetAuthStore, resolveSystemMessageText, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
|
657
|
+
export { AntzChatAuthError, AntzChatClient, AntzChatConfig, AntzChatError, AntzChatNetworkError, AntzChatPermissionError, AntzChatServerError, AntzChatValidationError, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, CompletedPart, Conversation, ConversationListParams, ConversationSyncResponse, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CrossConversationSyncResponse, 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, createRestTransitSession, decryptPayload, devicesApi, disconnectSocket, encryptPayload, fetchServerKeys, generateEphemeralKey, getApiClient, getAuthStore, getCompressionStrategy, getSessionId, getSessionKey, getSocket, getSocketStatus, initApiClient, initAuthStore, isTransitEnvelope, messagesApi, normalizeAxiosError, normalizeConversation, onSocketStatus, performHandshake, reconnectSocket, refreshSocketAuth, resetAuthStore, resolveSystemMessageText, setApiClientInstance, setTransitSession, socketEmit, syncApi, tryGetSocket, useChatStore, usersApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as ResolvedCompressionConfig, L as LoginCredentials, A as AuthResponse, a as RegisterData, b as AuthTokens, U as User, c as AppConfig, S as SendMessagePayload,
|
|
2
|
-
export {
|
|
1
|
+
import { R as ResolvedCompressionConfig, L as LoginCredentials, A as AuthResponse, a as RegisterData, b as AuthTokens, U as User, C as CrossConversationSyncResponse, c as ConversationSyncResponse, d as AppConfig, S as SendMessagePayload, e as CursorPaginatedResponse, M as Message, P as PaginatedResponse, f as MessageReceiptsResponse, g as ConversationListParams, h as Conversation, i as Participant, j as ConversationUnreadCount, k as UnreadSummary, l as UserPreferences, m as ResolvedConfig, n as PersistStorage, o as PresignedUrlRequest, p as PresignedUrlResponse, F as FileResponse, q as CompletedPart, r as FileType, s as AntzChatConfig, t as UploadableFile, B as BatchUploadResult } from './storage-CW70b4vi.js';
|
|
2
|
+
export { u as Attachment, v as CompressedFile, w as CompressionAlgorithm, x as CompressionConfig, y as ConversationType, z as FileSizeLimits, D as LastReaction, E as MessageAckEvent, G as MessageContent, H as MessageDeletedEvent, I as MessageDeletedForMeEvent, J as MessageDeliveredEvent, K as MessageMetadata, N as MessageReaction, O as MessageReceiptEntry, Q as MessageReplyReference, T as MessageStarUpdatedEvent, V as MessageUpdatedEvent, W as MessagesDeliveredEvent, X as MultipartPartUrl, Y as MultipartUploadInfo, Z as NewMessageEvent, _ as OptimisticAttachment, $ as PlatformCompressFn, a0 as PlatformUploadFn, a1 as PlatformUploadPartFn, a2 as QuietHours, a3 as ReactionUpdatedEvent, a4 as ReadReceiptEvent, a5 as ReplyAttachmentSnapshot, a6 as ResolvedFileSizeLimits, a7 as SendMessageAttachment, a8 as SyncDeletedForMe, a9 as SyncParticipantChange, aa as SyncReactions, ab as SyncReadReceipt, ac as SyncStarEntry, ad as SystemMessageMetadata, ae as TypingIndicatorEvent, af as UploadConfig, ag as UploadProgress, ah as UserStatusEvent, ai as resolveConfig, aj as storageApi, ak as uploadBatch } from './storage-CW70b4vi.js';
|
|
3
3
|
import { AxiosInstance } from 'axios';
|
|
4
4
|
import { Socket } from 'socket.io-client';
|
|
5
5
|
import * as zustand_middleware from 'zustand/middleware';
|
|
@@ -26,6 +26,23 @@ declare const authApi: {
|
|
|
26
26
|
}>;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
declare const syncApi: {
|
|
30
|
+
/**
|
|
31
|
+
* Cross-conversation delta sync — call on every socket reconnect.
|
|
32
|
+
* `since` is the ISO timestamp returned as `syncedAt` from the previous call.
|
|
33
|
+
* Returns `stale: true` (with empty arrays) when the gap exceeds 60 days —
|
|
34
|
+
* the app should mark all conversations `needs_refresh` and lazy-sync on open.
|
|
35
|
+
*/
|
|
36
|
+
pull(since: string): Promise<CrossConversationSyncResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Per-conversation delta sync — call when a conversation has `needs_refresh = true`
|
|
39
|
+
* or on fresh install (omit `since` to receive the full message history).
|
|
40
|
+
* Covers messages, deletedForMe, full reaction state, stars, participant changes,
|
|
41
|
+
* and read receipts — everything needed to make local SQLite authoritative.
|
|
42
|
+
*/
|
|
43
|
+
pullConversation(conversationId: string, since?: string): Promise<ConversationSyncResponse>;
|
|
44
|
+
};
|
|
45
|
+
|
|
29
46
|
declare const appConfigApi: {
|
|
30
47
|
get(): Promise<AppConfig>;
|
|
31
48
|
};
|
|
@@ -123,6 +140,7 @@ declare const conversationsApi: {
|
|
|
123
140
|
*/
|
|
124
141
|
uploadIcon(conversationId: string, fileId: string): Promise<Conversation>;
|
|
125
142
|
removeIcon(conversationId: string): Promise<Conversation>;
|
|
143
|
+
clearChat(conversationId: string): Promise<void>;
|
|
126
144
|
};
|
|
127
145
|
|
|
128
146
|
/** Shared fields for every device registration. */
|
|
@@ -267,6 +285,7 @@ declare const socketEmit: {
|
|
|
267
285
|
updateMessage(messageId: string, text: string): Promise<unknown>;
|
|
268
286
|
deleteMessage(messageId: string): Promise<unknown>;
|
|
269
287
|
deleteMessageForMe(messageId: string): Promise<unknown>;
|
|
288
|
+
clearChat(conversationId: string): Promise<unknown>;
|
|
270
289
|
addReaction(messageId: string, emoji: string): Promise<unknown>;
|
|
271
290
|
removeReaction(messageId: string, emoji: string): Promise<unknown>;
|
|
272
291
|
pinMessage(messageId: string): Promise<unknown>;
|
|
@@ -453,6 +472,45 @@ interface ChatState {
|
|
|
453
472
|
}
|
|
454
473
|
declare const useChatStore: zustand.UseBoundStore<zustand.StoreApi<ChatState>>;
|
|
455
474
|
|
|
475
|
+
declare class AntzChatError extends Error {
|
|
476
|
+
readonly code: string;
|
|
477
|
+
readonly retryable: boolean;
|
|
478
|
+
readonly context?: Record<string, unknown>;
|
|
479
|
+
constructor(code: string, message: string, retryable?: boolean, context?: Record<string, unknown>);
|
|
480
|
+
}
|
|
481
|
+
/** Thrown on 401 (after refresh also fails) or when no refresh token exists. */
|
|
482
|
+
declare class AntzChatAuthError extends AntzChatError {
|
|
483
|
+
constructor(message: string, code?: string, context?: Record<string, unknown>);
|
|
484
|
+
}
|
|
485
|
+
/** Thrown on 400 / 422 — bad input, validation failure. */
|
|
486
|
+
declare class AntzChatValidationError extends AntzChatError {
|
|
487
|
+
/** Server-returned field error array (when the server sends message as string[]). */
|
|
488
|
+
readonly fields?: string[];
|
|
489
|
+
constructor(message: string | string[], context?: Record<string, unknown>);
|
|
490
|
+
}
|
|
491
|
+
/** Thrown on network failures, timeouts, socket disconnections, and queue overflow. retryable = true. */
|
|
492
|
+
declare class AntzChatNetworkError extends AntzChatError {
|
|
493
|
+
constructor(message: string, code?: string, context?: Record<string, unknown>);
|
|
494
|
+
}
|
|
495
|
+
/** Thrown on 403 — insufficient permissions. */
|
|
496
|
+
declare class AntzChatPermissionError extends AntzChatError {
|
|
497
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
498
|
+
}
|
|
499
|
+
/** Thrown on 5xx or other unexpected server errors. retryable = true. */
|
|
500
|
+
declare class AntzChatServerError extends AntzChatError {
|
|
501
|
+
readonly httpStatus?: number;
|
|
502
|
+
constructor(message: string, httpStatus?: number, context?: Record<string, unknown>);
|
|
503
|
+
}
|
|
504
|
+
/**
|
|
505
|
+
* Converts a raw axios error (or any unknown throw) into a typed AntzChatError.
|
|
506
|
+
*
|
|
507
|
+
* Call site: client.ts response interceptor — runs AFTER transit decryption,
|
|
508
|
+
* so error.response.data is always plaintext by the time this function sees it.
|
|
509
|
+
* If decryption itself failed, error.response.data remains the raw encrypted
|
|
510
|
+
* envelope — detected via isTransitEnvelope() and noted in context.
|
|
511
|
+
*/
|
|
512
|
+
declare function normalizeAxiosError(error: unknown): AntzChatError;
|
|
513
|
+
|
|
456
514
|
/**
|
|
457
515
|
* Resolves viewer-aware display text for system messages.
|
|
458
516
|
*
|
|
@@ -544,6 +602,7 @@ declare class AntzChatClient {
|
|
|
544
602
|
getUnreadSummary(): Promise<UnreadSummary>;
|
|
545
603
|
uploadIcon(conversationId: string, fileId: string): Promise<Conversation>;
|
|
546
604
|
removeIcon(conversationId: string): Promise<Conversation>;
|
|
605
|
+
clearChat(conversationId: string): Promise<void>;
|
|
547
606
|
};
|
|
548
607
|
readonly storage: {
|
|
549
608
|
requestPresignedUrl(payload: PresignedUrlRequest): Promise<PresignedUrlResponse>;
|
|
@@ -595,4 +654,4 @@ declare class AntzChatClient {
|
|
|
595
654
|
uploadIcon(conversationId: string, file: UploadableFile): Promise<Conversation>;
|
|
596
655
|
}
|
|
597
656
|
|
|
598
|
-
export { AntzChatClient, AntzChatConfig, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, CompletedPart, 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, createRestTransitSession, decryptPayload, devicesApi, disconnectSocket, encryptPayload, fetchServerKeys, generateEphemeralKey, getApiClient, getAuthStore, getCompressionStrategy, getSessionId, getSessionKey, getSocket, getSocketStatus, initApiClient, initAuthStore, isTransitEnvelope, messagesApi, normalizeConversation, onSocketStatus, performHandshake, reconnectSocket, refreshSocketAuth, resetAuthStore, resolveSystemMessageText, setApiClientInstance, setTransitSession, socketEmit, tryGetSocket, useChatStore, usersApi };
|
|
657
|
+
export { AntzChatAuthError, AntzChatClient, AntzChatConfig, AntzChatError, AntzChatNetworkError, AntzChatPermissionError, AntzChatServerError, AntzChatValidationError, AppConfig, AuthResponse, AuthTokens, BatchUploadResult, CompletedPart, Conversation, ConversationListParams, ConversationSyncResponse, ConversationUnreadCount, type CreateDirectData, type CreateGroupData, CrossConversationSyncResponse, 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, createRestTransitSession, decryptPayload, devicesApi, disconnectSocket, encryptPayload, fetchServerKeys, generateEphemeralKey, getApiClient, getAuthStore, getCompressionStrategy, getSessionId, getSessionKey, getSocket, getSocketStatus, initApiClient, initAuthStore, isTransitEnvelope, messagesApi, normalizeAxiosError, normalizeConversation, onSocketStatus, performHandshake, reconnectSocket, refreshSocketAuth, resetAuthStore, resolveSystemMessageText, setApiClientInstance, setTransitSession, socketEmit, syncApi, tryGetSocket, useChatStore, usersApi };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AntzChatAuthError,
|
|
3
|
+
AntzChatError,
|
|
4
|
+
AntzChatNetworkError,
|
|
5
|
+
AntzChatPermissionError,
|
|
6
|
+
AntzChatServerError,
|
|
7
|
+
AntzChatValidationError,
|
|
2
8
|
clearTransitSession,
|
|
3
9
|
configureTransit,
|
|
4
10
|
createRestTransitSession,
|
|
@@ -16,13 +22,14 @@ import {
|
|
|
16
22
|
initApiClient,
|
|
17
23
|
isTransitEnabled,
|
|
18
24
|
isTransitEnvelope,
|
|
25
|
+
normalizeAxiosError,
|
|
19
26
|
performHandshake,
|
|
20
27
|
resetAlgoCache,
|
|
21
28
|
setApiClientInstance,
|
|
22
29
|
setTransitSession,
|
|
23
30
|
storageApi,
|
|
24
31
|
uploadBatch
|
|
25
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-XTQYF5HU.js";
|
|
26
33
|
import {
|
|
27
34
|
useChatStore
|
|
28
35
|
} from "./chunk-EOL5B7GS.js";
|
|
@@ -130,6 +137,30 @@ var authApi = {
|
|
|
130
137
|
}
|
|
131
138
|
};
|
|
132
139
|
|
|
140
|
+
// src/api/sync.ts
|
|
141
|
+
var syncApi = {
|
|
142
|
+
/**
|
|
143
|
+
* Cross-conversation delta sync — call on every socket reconnect.
|
|
144
|
+
* `since` is the ISO timestamp returned as `syncedAt` from the previous call.
|
|
145
|
+
* Returns `stale: true` (with empty arrays) when the gap exceeds 60 days —
|
|
146
|
+
* the app should mark all conversations `needs_refresh` and lazy-sync on open.
|
|
147
|
+
*/
|
|
148
|
+
pull(since) {
|
|
149
|
+
return getApiClient().get("/sync", { params: { since } }).then((r) => r.data);
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Per-conversation delta sync — call when a conversation has `needs_refresh = true`
|
|
153
|
+
* or on fresh install (omit `since` to receive the full message history).
|
|
154
|
+
* Covers messages, deletedForMe, full reaction state, stars, participant changes,
|
|
155
|
+
* and read receipts — everything needed to make local SQLite authoritative.
|
|
156
|
+
*/
|
|
157
|
+
pullConversation(conversationId, since) {
|
|
158
|
+
return getApiClient().get(`/conversations/${conversationId}/sync`, {
|
|
159
|
+
params: since ? { since } : {}
|
|
160
|
+
}).then((r) => r.data);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
133
164
|
// src/api/app-config.ts
|
|
134
165
|
var appConfigApi = {
|
|
135
166
|
async get() {
|
|
@@ -501,6 +532,9 @@ var conversationsApi = {
|
|
|
501
532
|
async removeIcon(conversationId) {
|
|
502
533
|
const { data } = await getApiClient().post(`/conversations/${conversationId}/icon/remove`);
|
|
503
534
|
return normalizeConversation(data);
|
|
535
|
+
},
|
|
536
|
+
async clearChat(conversationId) {
|
|
537
|
+
await getApiClient().post(`/conversations/${conversationId}/clear-for-me`);
|
|
504
538
|
}
|
|
505
539
|
};
|
|
506
540
|
|
|
@@ -694,8 +728,11 @@ async function _doConnect(config, getToken) {
|
|
|
694
728
|
try {
|
|
695
729
|
const serverKeys = await fetchServerKeys(config.apiUrl);
|
|
696
730
|
if (!serverKeys.enabled) {
|
|
697
|
-
throw new
|
|
698
|
-
"
|
|
731
|
+
throw new AntzChatError(
|
|
732
|
+
"TRANSIT_MISMATCH",
|
|
733
|
+
"[AntzChat] Transit encryption mismatch: SDK has transitEncryption=true but server has TRANSIT_ENCRYPTION_ENABLED=false. Align the config on both sides.",
|
|
734
|
+
false,
|
|
735
|
+
{ sdkEnabled: true, serverEnabled: false }
|
|
699
736
|
);
|
|
700
737
|
}
|
|
701
738
|
const algo = globalThis.crypto?.subtle ? await detectTransitAlgo() : "x25519";
|
|
@@ -708,12 +745,15 @@ async function _doConnect(config, getToken) {
|
|
|
708
745
|
try {
|
|
709
746
|
const serverKeys = await fetchServerKeys(config.apiUrl);
|
|
710
747
|
if (serverKeys.enabled) {
|
|
711
|
-
throw new
|
|
712
|
-
"
|
|
748
|
+
throw new AntzChatError(
|
|
749
|
+
"TRANSIT_MISMATCH",
|
|
750
|
+
"[AntzChat] Transit encryption mismatch: SDK has transitEncryption=false but server has TRANSIT_ENCRYPTION_ENABLED=true. Align the config on both sides.",
|
|
751
|
+
false,
|
|
752
|
+
{ sdkEnabled: false, serverEnabled: true }
|
|
713
753
|
);
|
|
714
754
|
}
|
|
715
755
|
} catch (err) {
|
|
716
|
-
if (err
|
|
756
|
+
if (err?.code === "TRANSIT_MISMATCH") throw err;
|
|
717
757
|
}
|
|
718
758
|
}
|
|
719
759
|
_socket = io(`${config.socketOrigin}/chat`, {
|
|
@@ -857,7 +897,7 @@ async function drainSendQueue(conversationId) {
|
|
|
857
897
|
while (queue.length > 0) {
|
|
858
898
|
const entry = queue.shift();
|
|
859
899
|
if (Date.now() - entry.enqueuedAt > QUEUE_ENTRY_TTL) {
|
|
860
|
-
entry.reject(new
|
|
900
|
+
entry.reject(new AntzChatNetworkError("Message dropped: queued too long", "MESSAGE_DROPPED"));
|
|
861
901
|
continue;
|
|
862
902
|
}
|
|
863
903
|
entry.run().then(entry.resolve).catch(entry.reject);
|
|
@@ -870,7 +910,7 @@ function queueSendMessage(payload) {
|
|
|
870
910
|
if (!sendQueues.has(conversationId)) sendQueues.set(conversationId, []);
|
|
871
911
|
const queue = sendQueues.get(conversationId);
|
|
872
912
|
if (queue.length >= QUEUE_MAX_SIZE) {
|
|
873
|
-
return Promise.reject(new
|
|
913
|
+
return Promise.reject(new AntzChatNetworkError("Send queue full: too many messages in flight", "SEND_QUEUE_FULL", { conversationId }));
|
|
874
914
|
}
|
|
875
915
|
return new Promise((resolve, reject) => {
|
|
876
916
|
queue.push({ run: () => withAck("send_message", payload), resolve, reject, enqueuedAt: Date.now() });
|
|
@@ -881,7 +921,7 @@ function waitForReconnect() {
|
|
|
881
921
|
return new Promise((resolve, reject) => {
|
|
882
922
|
const timer = setTimeout(() => {
|
|
883
923
|
unsubscribe();
|
|
884
|
-
reject(new
|
|
924
|
+
reject(new AntzChatNetworkError("Socket reconnect timeout", "SOCKET_TIMEOUT"));
|
|
885
925
|
}, RECONNECT_WAIT_TIMEOUT);
|
|
886
926
|
const unsubscribe = onSocketStatus((status) => {
|
|
887
927
|
if (status === "connected") {
|
|
@@ -891,7 +931,7 @@ function waitForReconnect() {
|
|
|
891
931
|
} else if (status === "error") {
|
|
892
932
|
clearTimeout(timer);
|
|
893
933
|
unsubscribe();
|
|
894
|
-
reject(new
|
|
934
|
+
reject(new AntzChatNetworkError("Socket reconnect failed", "SOCKET_NOT_CONNECTED"));
|
|
895
935
|
}
|
|
896
936
|
});
|
|
897
937
|
});
|
|
@@ -902,14 +942,14 @@ async function withAck(event, payload) {
|
|
|
902
942
|
await waitForReconnect();
|
|
903
943
|
socket = tryGetSocket();
|
|
904
944
|
}
|
|
905
|
-
if (!socket) return Promise.reject(new
|
|
945
|
+
if (!socket) return Promise.reject(new AntzChatNetworkError(`Socket not connected (event: ${event})`, "SOCKET_NOT_CONNECTED", { event }));
|
|
906
946
|
return new Promise((resolve, reject) => {
|
|
907
947
|
let timer;
|
|
908
948
|
secureEmit(socket, event, payload, (response) => {
|
|
909
949
|
clearTimeout(timer);
|
|
910
950
|
resolve(response);
|
|
911
951
|
}).then(() => {
|
|
912
|
-
timer = setTimeout(() => reject(new
|
|
952
|
+
timer = setTimeout(() => reject(new AntzChatNetworkError(`Socket ack timeout: ${event}`, "SOCKET_TIMEOUT", { event })), ACK_TIMEOUT);
|
|
913
953
|
}).catch(reject);
|
|
914
954
|
});
|
|
915
955
|
}
|
|
@@ -937,6 +977,9 @@ var socketEmit = {
|
|
|
937
977
|
deleteMessageForMe(messageId) {
|
|
938
978
|
return withAck("delete_message_for_me", { messageId });
|
|
939
979
|
},
|
|
980
|
+
clearChat(conversationId) {
|
|
981
|
+
return withAck("clear_chat_for_me", { conversationId });
|
|
982
|
+
},
|
|
940
983
|
addReaction(messageId, emoji) {
|
|
941
984
|
return withAck("add_reaction", { messageId, emoji });
|
|
942
985
|
},
|
|
@@ -972,7 +1015,7 @@ var socketEmit = {
|
|
|
972
1015
|
resolve([]);
|
|
973
1016
|
}
|
|
974
1017
|
}).then(() => {
|
|
975
|
-
timer = setTimeout(() => reject(new
|
|
1018
|
+
timer = setTimeout(() => reject(new AntzChatNetworkError("Socket ack timeout: get_online_users", "SOCKET_TIMEOUT", { event: "get_online_users" })), ACK_TIMEOUT);
|
|
976
1019
|
}).catch(reject);
|
|
977
1020
|
});
|
|
978
1021
|
},
|
|
@@ -1031,7 +1074,13 @@ var AntzChatClient = class {
|
|
|
1031
1074
|
}
|
|
1032
1075
|
};
|
|
1033
1076
|
export {
|
|
1077
|
+
AntzChatAuthError,
|
|
1034
1078
|
AntzChatClient,
|
|
1079
|
+
AntzChatError,
|
|
1080
|
+
AntzChatNetworkError,
|
|
1081
|
+
AntzChatPermissionError,
|
|
1082
|
+
AntzChatServerError,
|
|
1083
|
+
AntzChatValidationError,
|
|
1035
1084
|
appConfigApi,
|
|
1036
1085
|
authApi,
|
|
1037
1086
|
connectSocket,
|
|
@@ -1055,6 +1104,7 @@ export {
|
|
|
1055
1104
|
initAuthStore,
|
|
1056
1105
|
isTransitEnvelope,
|
|
1057
1106
|
messagesApi,
|
|
1107
|
+
normalizeAxiosError,
|
|
1058
1108
|
normalizeConversation,
|
|
1059
1109
|
onSocketStatus,
|
|
1060
1110
|
performHandshake,
|
|
@@ -1067,6 +1117,7 @@ export {
|
|
|
1067
1117
|
setTransitSession,
|
|
1068
1118
|
socketEmit,
|
|
1069
1119
|
storageApi,
|
|
1120
|
+
syncApi,
|
|
1070
1121
|
tryGetSocket,
|
|
1071
1122
|
uploadBatch,
|
|
1072
1123
|
useChatStore,
|