@manonero/chat-client-sdk 0.0.1-beta.1
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 +2453 -0
- package/dist/ChatClient.d.ts +181 -0
- package/dist/ChatClient.d.ts.map +1 -0
- package/dist/ChatClient.js +246 -0
- package/dist/ChatClient.js.map +1 -0
- package/dist/errors/ChatApiError.d.ts +45 -0
- package/dist/errors/ChatApiError.d.ts.map +1 -0
- package/dist/errors/ChatApiError.js +69 -0
- package/dist/errors/ChatApiError.js.map +1 -0
- package/dist/http/AuthApi.d.ts +26 -0
- package/dist/http/AuthApi.d.ts.map +1 -0
- package/dist/http/AuthApi.js +35 -0
- package/dist/http/AuthApi.js.map +1 -0
- package/dist/http/BotApi.d.ts +43 -0
- package/dist/http/BotApi.d.ts.map +1 -0
- package/dist/http/BotApi.js +60 -0
- package/dist/http/BotApi.js.map +1 -0
- package/dist/http/ConversationApi.d.ts +92 -0
- package/dist/http/ConversationApi.d.ts.map +1 -0
- package/dist/http/ConversationApi.js +128 -0
- package/dist/http/ConversationApi.js.map +1 -0
- package/dist/http/FileApi.d.ts +60 -0
- package/dist/http/FileApi.d.ts.map +1 -0
- package/dist/http/FileApi.js +91 -0
- package/dist/http/FileApi.js.map +1 -0
- package/dist/http/HealthApi.d.ts +28 -0
- package/dist/http/HealthApi.d.ts.map +1 -0
- package/dist/http/HealthApi.js +34 -0
- package/dist/http/HealthApi.js.map +1 -0
- package/dist/http/HttpClient.d.ts +69 -0
- package/dist/http/HttpClient.d.ts.map +1 -0
- package/dist/http/HttpClient.js +244 -0
- package/dist/http/HttpClient.js.map +1 -0
- package/dist/http/MessageApi.d.ts +69 -0
- package/dist/http/MessageApi.d.ts.map +1 -0
- package/dist/http/MessageApi.js +104 -0
- package/dist/http/MessageApi.js.map +1 -0
- package/dist/http/ParticipantApi.d.ts +28 -0
- package/dist/http/ParticipantApi.d.ts.map +1 -0
- package/dist/http/ParticipantApi.js +37 -0
- package/dist/http/ParticipantApi.js.map +1 -0
- package/dist/http/ProxyApi.d.ts +59 -0
- package/dist/http/ProxyApi.d.ts.map +1 -0
- package/dist/http/ProxyApi.js +86 -0
- package/dist/http/ProxyApi.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/realtime/ChatHubClient.d.ts +143 -0
- package/dist/realtime/ChatHubClient.d.ts.map +1 -0
- package/dist/realtime/ChatHubClient.js +365 -0
- package/dist/realtime/ChatHubClient.js.map +1 -0
- package/dist/realtime/NotificationHubClient.d.ts +89 -0
- package/dist/realtime/NotificationHubClient.d.ts.map +1 -0
- package/dist/realtime/NotificationHubClient.js +191 -0
- package/dist/realtime/NotificationHubClient.js.map +1 -0
- package/dist/realtime/ReconnectionManager.d.ts +65 -0
- package/dist/realtime/ReconnectionManager.d.ts.map +1 -0
- package/dist/realtime/ReconnectionManager.js +129 -0
- package/dist/realtime/ReconnectionManager.js.map +1 -0
- package/dist/types/auth.d.ts +30 -0
- package/dist/types/auth.d.ts.map +1 -0
- package/dist/types/auth.js +3 -0
- package/dist/types/auth.js.map +1 -0
- package/dist/types/block.d.ts +163 -0
- package/dist/types/block.d.ts.map +1 -0
- package/dist/types/block.js +77 -0
- package/dist/types/block.js.map +1 -0
- package/dist/types/bot.d.ts +42 -0
- package/dist/types/bot.d.ts.map +1 -0
- package/dist/types/bot.js +3 -0
- package/dist/types/bot.js.map +1 -0
- package/dist/types/chat-events.d.ts +191 -0
- package/dist/types/chat-events.d.ts.map +1 -0
- package/dist/types/chat-events.js +3 -0
- package/dist/types/chat-events.js.map +1 -0
- package/dist/types/common.d.ts +64 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +3 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/conversation.d.ts +106 -0
- package/dist/types/conversation.d.ts.map +1 -0
- package/dist/types/conversation.js +3 -0
- package/dist/types/conversation.js.map +1 -0
- package/dist/types/file.d.ts +31 -0
- package/dist/types/file.d.ts.map +1 -0
- package/dist/types/file.js +3 -0
- package/dist/types/file.js.map +1 -0
- package/dist/types/message.d.ts +84 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +3 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/notification-events.d.ts +89 -0
- package/dist/types/notification-events.d.ts.map +1 -0
- package/dist/types/notification-events.js +3 -0
- package/dist/types/notification-events.js.map +1 -0
- package/dist/types/participant.d.ts +22 -0
- package/dist/types/participant.d.ts.map +1 -0
- package/dist/types/participant.js +3 -0
- package/dist/types/participant.js.map +1 -0
- package/dist/types/signalr.d.ts +84 -0
- package/dist/types/signalr.d.ts.map +1 -0
- package/dist/types/signalr.js +3 -0
- package/dist/types/signalr.js.map +1 -0
- package/dist/utils/TypedEventEmitter.d.ts +32 -0
- package/dist/utils/TypedEventEmitter.d.ts.map +1 -0
- package/dist/utils/TypedEventEmitter.js +60 -0
- package/dist/utils/TypedEventEmitter.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// ProxyApi.ts — Dynamic backend proxy endpoints
|
|
2
|
+
import { HttpClient } from './HttpClient.js';
|
|
3
|
+
/**
|
|
4
|
+
* Proxy API client.
|
|
5
|
+
* Forwards requests to registered backend services via the gateway.
|
|
6
|
+
*
|
|
7
|
+
* Example:
|
|
8
|
+
* proxy.get('trading', 'api/stocks/VN30')
|
|
9
|
+
* → GET /api/proxy/trading/api/stocks/VN30
|
|
10
|
+
*
|
|
11
|
+
* Auth: depends on the target service. Pass JWT when required.
|
|
12
|
+
* Error format: simple { "detail": "..." } — handled by ChatApiError.fromResponse().
|
|
13
|
+
*/
|
|
14
|
+
export class ProxyApi {
|
|
15
|
+
constructor(http) {
|
|
16
|
+
this.http = http;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generic proxy request supporting any HTTP method.
|
|
20
|
+
*
|
|
21
|
+
* @param target - The registered backend target name (e.g. "trading")
|
|
22
|
+
* @param url - The URL path to forward, may include path and query string (e.g. "api/stocks/VN30?page=1")
|
|
23
|
+
* @param options.method - HTTP method (default: GET)
|
|
24
|
+
* @param options.body - Request body (for POST/PATCH)
|
|
25
|
+
* @param options.headers - Additional headers to forward
|
|
26
|
+
*/
|
|
27
|
+
request(target, url, options) {
|
|
28
|
+
const method = (options?.method ?? 'GET').toUpperCase();
|
|
29
|
+
const path = this.buildPath(target, url);
|
|
30
|
+
switch (method) {
|
|
31
|
+
case 'POST':
|
|
32
|
+
return this.http.post(path, options?.body, options?.headers);
|
|
33
|
+
case 'PUT':
|
|
34
|
+
return this.http.put(path, options?.body, options?.headers);
|
|
35
|
+
case 'PATCH':
|
|
36
|
+
return this.http.patch(path, options?.body, options?.headers);
|
|
37
|
+
case 'DELETE':
|
|
38
|
+
return this.http.delete(path, options?.body, options?.headers);
|
|
39
|
+
default:
|
|
40
|
+
// GET and any other methods use the GET client
|
|
41
|
+
return this.http.get(path, options?.headers);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* GET /api/proxy/{target}/{url}
|
|
46
|
+
* Forward a GET request to the target service.
|
|
47
|
+
*/
|
|
48
|
+
get(target, url, headers) {
|
|
49
|
+
return this.http.get(this.buildPath(target, url), headers);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* POST /api/proxy/{target}/{url}
|
|
53
|
+
* Forward a POST request with an optional JSON body to the target service.
|
|
54
|
+
*/
|
|
55
|
+
post(target, url, body, headers) {
|
|
56
|
+
return this.http.post(this.buildPath(target, url), body, headers);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* PUT /api/proxy/{target}/{url}
|
|
60
|
+
* Forward a PUT request with an optional JSON body to the target service.
|
|
61
|
+
*/
|
|
62
|
+
put(target, url, body, headers) {
|
|
63
|
+
return this.http.put(this.buildPath(target, url), body, headers);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* PATCH /api/proxy/{target}/{url}
|
|
67
|
+
* Forward a PATCH request with an optional JSON body to the target service.
|
|
68
|
+
*/
|
|
69
|
+
patch(target, url, body, headers) {
|
|
70
|
+
return this.http.patch(this.buildPath(target, url), body, headers);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* DELETE /api/proxy/{target}/{url}
|
|
74
|
+
* Forward a DELETE request to the target service. An optional JSON body is
|
|
75
|
+
* forwarded verbatim per spec §10.1 ("Forward HTTP method, query string,
|
|
76
|
+
* request body, và tất cả request headers").
|
|
77
|
+
*/
|
|
78
|
+
delete(target, url, body, headers) {
|
|
79
|
+
return this.http.delete(this.buildPath(target, url), body, headers);
|
|
80
|
+
}
|
|
81
|
+
buildPath(target, url) {
|
|
82
|
+
const trimmed = url.replace(/^\/+/, '');
|
|
83
|
+
return `/api/proxy/${encodeURIComponent(target)}/${trimmed}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=ProxyApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProxyApi.js","sourceRoot":"","sources":["../../src/http/ProxyApi.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,MAAM,OAAO,QAAQ;IAGnB,YAAY,IAAgB;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;;;OAQG;IACH,OAAO,CACL,MAAc,EACd,GAAW,EACX,OAIC;QAED,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,IAAI,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;QACxD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACzC,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,IAAI,CAA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AAC;IAED;;;OAGG;IACH,KAAK,CACH,MAAc,EACd,GAAW,EACX,IAAc,EACd,OAAgC;QAEhC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACxE,CAAC;IAED;;;;;OAKG;IACH,MAAM,CACJ,MAAc,EACd,GAAW,EACX,IAAc,EACd,OAAgC;QAEhC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAI,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACzE,CAAC;IAEO,SAAS,CAAC,MAAc,EAAE,GAAW;QAC3C,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACxC,OAAO,cAAc,kBAAkB,CAAC,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;IAC/D,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type { CursorPaginatedResult, PagedResult, MediaReference, ProblemDetails, ProblemError, UploadProgressCallback, } from './types/common.js';
|
|
2
|
+
export type { GoogleLoginRequest, DsAccountLoginRequest, DevLoginRequest, LoginRequest, AuthResponse, AuthUserInfo } from './types/auth.js';
|
|
3
|
+
export type { ParticipantDto, CreateOrUpdateParticipantRequest } from './types/participant.js';
|
|
4
|
+
export type { ConversationParticipantDto, ConversationDto, ConversationListItemDto, ConversationMediaKindFilter, ConversationMediaKind, ConversationMediaBlockType, ConversationMediaItemDto, CreateConversationRequest, UpdateConversationRequest, AddParticipantRequest, } from './types/conversation.js';
|
|
5
|
+
export type { SenderType, SystemEventType, SystemEventInfo, ReactionGroup, ReactionSummary, MessageDto, SendMessageRequest, EditMessageRequest, } from './types/message.js';
|
|
6
|
+
export type { TextFormat, ButtonAction, ButtonStyle, ChoiceMode, QuickReplyAction, MentionType, TextBlock, ImageBlock, VideoBlock, AudioBlock, FileBlock, LinkPreviewBlock, EmbedBlock, LocationBlock, ContactBlock, ChoiceOption, ChoiceBlock, CardField, ActionButton, CardBlock, CarouselBlock, DividerBlock, CustomBlock, Block, QuickReply, Mention, } from './types/block.js';
|
|
7
|
+
export { isTextBlock, isImageBlock, isVideoBlock, isAudioBlock, isFileBlock, isLinkPreviewBlock, isEmbedBlock, isLocationBlock, isContactBlock, isChoiceBlock, isCardBlock, isCarouselBlock, isDividerBlock, isCustomBlock, withTypeFirst, normalizeBlocksForSend, } from './types/block.js';
|
|
8
|
+
export type { CreateUploadUrlRequest, CreateUploadUrlResponse, UploadResponse } from './types/file.js';
|
|
9
|
+
export type { BotDto, CreateBotRequest, UpdateBotRequest } from './types/bot.js';
|
|
10
|
+
export type { SystemEventDto, ReactionGroupDto, ChatMessageDto, MessageUpdatedDto, MessageDeletedDto, ReactionAddedDto, ReactionRemovedDto, TypingDto, MessageThumbnailDto, MessageThumbnailsReadyDto, StreamStartedDto, StreamStatusUpdatedDto, StreamChunkReceivedDto, StreamChunkPart, StreamChunkBatchReceivedDto, StreamCompletedDto, StreamAbortedDto, } from './types/chat-events.js';
|
|
11
|
+
export type { NewMessageNotificationDto, MentionedNotificationDto, ConversationCreatedDto, ConversationUpdatedDto, ParticipantJoinedDto, ParticipantLeftDto, ConversationPinnedDto, ConversationUnpinnedDto, } from './types/notification-events.js';
|
|
12
|
+
export type { ChatSendMessageRequest, ChatEditMessageRequest, ChatDeleteMessageRequest, ChatRecoverMessageRequest, ChatAddReactionRequest, ChatRemoveReactionRequest, SendMessageAck, EditMessageAck, DeleteMessageAck, RecoverMessageAck, ReactionAck, HubErrorDto, } from './types/signalr.js';
|
|
13
|
+
export { ChatApiError } from './errors/ChatApiError.js';
|
|
14
|
+
export { HttpClient } from './http/HttpClient.js';
|
|
15
|
+
export type { HttpClientOptions } from './http/HttpClient.js';
|
|
16
|
+
export { TypedEventEmitter } from './utils/TypedEventEmitter.js';
|
|
17
|
+
export type { Unsubscribe } from './utils/TypedEventEmitter.js';
|
|
18
|
+
export { ChatHubClient } from './realtime/ChatHubClient.js';
|
|
19
|
+
export type { ChatHubClientOptions, ChatHubEventMap } from './realtime/ChatHubClient.js';
|
|
20
|
+
export { NotificationHubClient } from './realtime/NotificationHubClient.js';
|
|
21
|
+
export type { NotificationHubClientOptions, NotificationHubEventMap, } from './realtime/NotificationHubClient.js';
|
|
22
|
+
export { ReconnectionManager } from './realtime/ReconnectionManager.js';
|
|
23
|
+
export type { ReconnectionManagerOptions } from './realtime/ReconnectionManager.js';
|
|
24
|
+
export { ChatClient } from './ChatClient.js';
|
|
25
|
+
export type { ChatClientOptions, ChatClientSignalrOptions, ChatClientRealtime } from './ChatClient.js';
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,qBAAqB,EACrB,WAAW,EACX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,eAAe,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG5I,YAAY,EAAE,cAAc,EAAE,gCAAgC,EAAE,MAAM,wBAAwB,CAAC;AAG/F,YAAY,EACV,0BAA0B,EAC1B,eAAe,EACf,uBAAuB,EACvB,2BAA2B,EAC3B,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,GACtB,MAAM,yBAAyB,CAAC;AAGjC,YAAY,EACV,UAAU,EACV,eAAe,EACf,eAAe,EACf,aAAa,EACb,eAAe,EACf,UAAU,EACV,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAG5B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yB,EACzB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,WAAW,GACZ,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAGzF,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,YAAY,EACV,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,qCAAqC,CAAC;AAG7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,YAAY,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAGpF,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,YAAY,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// index.ts — Public SDK API — re-exports everything
|
|
2
|
+
// Block type guards + serialization helpers
|
|
3
|
+
export { isTextBlock, isImageBlock, isVideoBlock, isAudioBlock, isFileBlock, isLinkPreviewBlock, isEmbedBlock, isLocationBlock, isContactBlock, isChoiceBlock, isCardBlock, isCarouselBlock, isDividerBlock, isCustomBlock, withTypeFirst, normalizeBlocksForSend, } from './types/block.js';
|
|
4
|
+
// Errors
|
|
5
|
+
export { ChatApiError } from './errors/ChatApiError.js';
|
|
6
|
+
// HTTP client
|
|
7
|
+
export { HttpClient } from './http/HttpClient.js';
|
|
8
|
+
// Utils — TypedEventEmitter
|
|
9
|
+
export { TypedEventEmitter } from './utils/TypedEventEmitter.js';
|
|
10
|
+
// Real-time — ChatHubClient
|
|
11
|
+
export { ChatHubClient } from './realtime/ChatHubClient.js';
|
|
12
|
+
// Real-time — NotificationHubClient
|
|
13
|
+
export { NotificationHubClient } from './realtime/NotificationHubClient.js';
|
|
14
|
+
// Real-time — ReconnectionManager
|
|
15
|
+
export { ReconnectionManager } from './realtime/ReconnectionManager.js';
|
|
16
|
+
// ChatClient — Main SDK facade (Phase 4)
|
|
17
|
+
export { ChatClient } from './ChatClient.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oDAAoD;AA0EpD,4CAA4C;AAC5C,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,cAAc,EACd,aAAa,EACb,WAAW,EACX,eAAe,EACf,cAAc,EACd,aAAa,EACb,aAAa,EACb,sBAAsB,GACvB,MAAM,kBAAkB,CAAC;AAyD1B,SAAS;AACT,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,cAAc;AACd,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,4BAA4B;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAGjE,4BAA4B;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,oCAAoC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAM5E,kCAAkC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAGxE,yCAAyC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { HubConnectionState, LogLevel } from '@microsoft/signalr';
|
|
2
|
+
import type { Unsubscribe } from '../utils/TypedEventEmitter.js';
|
|
3
|
+
import type { ChatMessageDto, MessageUpdatedDto, MessageDeletedDto, MessageThumbnailsReadyDto, ReactionAddedDto, ReactionRemovedDto, TypingDto, StreamStartedDto, StreamStatusUpdatedDto, StreamChunkReceivedDto, StreamChunkBatchReceivedDto, StreamCompletedDto, StreamAbortedDto } from '../types/chat-events.js';
|
|
4
|
+
import type { ChatSendMessageRequest, ChatEditMessageRequest, ChatDeleteMessageRequest, ChatRecoverMessageRequest, ChatAddReactionRequest, ChatRemoveReactionRequest, SendMessageAck, EditMessageAck, DeleteMessageAck, RecoverMessageAck, ReactionAck, HubErrorDto } from '../types/signalr.js';
|
|
5
|
+
export interface ChatHubEventMap {
|
|
6
|
+
messageReceived: ChatMessageDto;
|
|
7
|
+
messageUpdated: MessageUpdatedDto;
|
|
8
|
+
messageDeleted: MessageDeletedDto;
|
|
9
|
+
/** Payload is full ChatMessageDto — same shape as messageReceived */
|
|
10
|
+
messageRecovered: ChatMessageDto;
|
|
11
|
+
/** Server has finished generating thumbnails for media blocks — patch by blockIndex */
|
|
12
|
+
messageThumbnailsReady: MessageThumbnailsReadyDto;
|
|
13
|
+
reactionAdded: ReactionAddedDto;
|
|
14
|
+
reactionRemoved: ReactionRemovedDto;
|
|
15
|
+
typingStarted: TypingDto;
|
|
16
|
+
typingStopped: TypingDto;
|
|
17
|
+
streamStarted: StreamStartedDto;
|
|
18
|
+
streamStatusUpdated: StreamStatusUpdatedDto;
|
|
19
|
+
streamChunkReceived: StreamChunkReceivedDto;
|
|
20
|
+
streamChunkBatchReceived: StreamChunkBatchReceivedDto;
|
|
21
|
+
streamCompleted: StreamCompletedDto;
|
|
22
|
+
streamAborted: StreamAbortedDto;
|
|
23
|
+
error: HubErrorDto;
|
|
24
|
+
reconnecting: Error | undefined;
|
|
25
|
+
reconnected: string | undefined;
|
|
26
|
+
disconnected: Error | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface ChatHubClientOptions {
|
|
29
|
+
/** Full URL of the ChatHub endpoint, e.g. "https://api.example.com/hubs/chat" */
|
|
30
|
+
hubUrl: string;
|
|
31
|
+
/** Returns the current JWT token to use as access_token query param */
|
|
32
|
+
tokenProvider: () => string | null;
|
|
33
|
+
/** Minimum log level for SignalR internal logging (default: Warning) */
|
|
34
|
+
logLevel?: LogLevel;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Typed client for the ChatHub (`/hubs/chat`).
|
|
38
|
+
*
|
|
39
|
+
* Responsibilities:
|
|
40
|
+
* - Manages HubConnection lifecycle (connect / disconnect / auto-reconnect)
|
|
41
|
+
* - Exposes typed Hub methods (Client → Server)
|
|
42
|
+
* - Exposes typed event subscription (Server → Client)
|
|
43
|
+
* - Tracks joined conversations so ReconnectionManager can re-join on reconnect
|
|
44
|
+
*/
|
|
45
|
+
export declare class ChatHubClient {
|
|
46
|
+
private readonly options;
|
|
47
|
+
private connection;
|
|
48
|
+
private readonly emitter;
|
|
49
|
+
/** In-flight connect Promise, used to dedupe concurrent connect() calls. */
|
|
50
|
+
private connectingPromise;
|
|
51
|
+
/**
|
|
52
|
+
* True after a user-initiated disconnect() until the next connect() begins.
|
|
53
|
+
* ReconnectionManager uses this to skip auto-reconnect when the close was
|
|
54
|
+
* intentional rather than caused by a transport failure.
|
|
55
|
+
*/
|
|
56
|
+
private _intentionallyClosed;
|
|
57
|
+
/** Set of conversationIds that have been joined in the current session */
|
|
58
|
+
readonly joinedConversations: Set<string>;
|
|
59
|
+
/**
|
|
60
|
+
* Tracks join attempts that resolved successfully but may still be revoked by
|
|
61
|
+
* a follow-up server `Error` event (FORBIDDEN/UNAUTHORIZED). Entries auto-expire
|
|
62
|
+
* after PENDING_JOIN_TTL_MS to bound memory.
|
|
63
|
+
*/
|
|
64
|
+
private readonly pendingJoinAttempts;
|
|
65
|
+
private static readonly PENDING_JOIN_TTL_MS;
|
|
66
|
+
/** Server→client method names registered via conn.on() — used for cleanup. */
|
|
67
|
+
private static readonly HUB_EVENT_NAMES;
|
|
68
|
+
constructor(options: ChatHubClientOptions);
|
|
69
|
+
get state(): HubConnectionState;
|
|
70
|
+
/**
|
|
71
|
+
* True after a user-initiated disconnect() and until the next connect() starts.
|
|
72
|
+
* ReconnectionManager honors this to avoid reconnecting after an intentional close.
|
|
73
|
+
*/
|
|
74
|
+
get intentionallyClosed(): boolean;
|
|
75
|
+
/** Build a new HubConnection using the latest token from tokenProvider */
|
|
76
|
+
private buildConnection;
|
|
77
|
+
/** Attach SignalR server→client event handlers to the connection */
|
|
78
|
+
private attachHandlers;
|
|
79
|
+
/**
|
|
80
|
+
* Connect to ChatHub. If already connected, resolves immediately.
|
|
81
|
+
* Concurrent calls share a single in-flight Promise — building two
|
|
82
|
+
* connections at once would leak handlers.
|
|
83
|
+
* Builds a fresh connection using the current token.
|
|
84
|
+
*
|
|
85
|
+
* Throws synchronously when no authentication token is available so the
|
|
86
|
+
* caller gets a clear error rather than a malformed Authorization header.
|
|
87
|
+
*/
|
|
88
|
+
connect(): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Disconnect from ChatHub and clear joined conversation tracking.
|
|
91
|
+
* If a connect is in flight, it is awaited first so we always tear down a
|
|
92
|
+
* fully-formed connection (not a half-built one).
|
|
93
|
+
*
|
|
94
|
+
* Sets `intentionallyClosed` so ReconnectionManager skips its reconnect
|
|
95
|
+
* attempt for the resulting `disconnected` event.
|
|
96
|
+
*/
|
|
97
|
+
disconnect(): Promise<void>;
|
|
98
|
+
/** Detach all server→client method handlers registered via attachHandlers(). */
|
|
99
|
+
private detachHandlers;
|
|
100
|
+
private safeStop;
|
|
101
|
+
/**
|
|
102
|
+
* Re-join all tracked conversations. Called internally after reconnect.
|
|
103
|
+
* Called by ReconnectionManager as well.
|
|
104
|
+
*
|
|
105
|
+
* If a rejoin fails with an access-denied style error (e.g. user was kicked
|
|
106
|
+
* between disconnect and reconnect), the conversation is purged from
|
|
107
|
+
* `joinedConversations` so we do not retry it forever on every reconnect.
|
|
108
|
+
* Other errors keep the entry — the next reconnect will try again.
|
|
109
|
+
*/
|
|
110
|
+
rejoinConversations(): Promise<void>;
|
|
111
|
+
private isAccessDeniedError;
|
|
112
|
+
private invokeHub;
|
|
113
|
+
joinConversation(conversationId: string): Promise<void>;
|
|
114
|
+
leaveConversation(conversationId: string): Promise<void>;
|
|
115
|
+
startTyping(conversationId: string): Promise<void>;
|
|
116
|
+
stopTyping(conversationId: string): Promise<void>;
|
|
117
|
+
sendMessage(request: ChatSendMessageRequest): Promise<SendMessageAck>;
|
|
118
|
+
editMessage(request: ChatEditMessageRequest): Promise<EditMessageAck>;
|
|
119
|
+
/** Server expects an object { messageId }, not a bare string */
|
|
120
|
+
deleteMessage(request: ChatDeleteMessageRequest): Promise<DeleteMessageAck>;
|
|
121
|
+
/** Server expects an object { messageId }, not a bare string */
|
|
122
|
+
recoverMessage(request: ChatRecoverMessageRequest): Promise<RecoverMessageAck>;
|
|
123
|
+
addReaction(request: ChatAddReactionRequest): Promise<ReactionAck>;
|
|
124
|
+
removeReaction(request: ChatRemoveReactionRequest): Promise<ReactionAck>;
|
|
125
|
+
on<K extends keyof ChatHubEventMap>(event: K, handler: (payload: ChatHubEventMap[K]) => void): Unsubscribe;
|
|
126
|
+
off<K extends keyof ChatHubEventMap>(event: K, handler: (payload: ChatHubEventMap[K]) => void): void;
|
|
127
|
+
private markJoinPending;
|
|
128
|
+
private clearPendingJoinAttempts;
|
|
129
|
+
private revertJoin;
|
|
130
|
+
/**
|
|
131
|
+
* If a server-emitted Error indicates a join was rejected, remove the
|
|
132
|
+
* conversation from `joinedConversations` to prevent auto-rejoin on reconnect.
|
|
133
|
+
*
|
|
134
|
+
* Strategy:
|
|
135
|
+
* 1. If `error.details.conversationId` is provided AND matches a pending
|
|
136
|
+
* join attempt → revert that one (most reliable signal).
|
|
137
|
+
* 2. Else, if the message matches the spec's documented FORBIDDEN text
|
|
138
|
+
* ("not a participant") AND there is exactly one pending join → revert it.
|
|
139
|
+
* 3. Otherwise do nothing — we cannot safely correlate the error to a join.
|
|
140
|
+
*/
|
|
141
|
+
private handlePotentialJoinFailure;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=ChatHubClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatHubClient.d.ts","sourceRoot":"","sources":["../../src/realtime/ChatHubClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,kBAAkB,EAClB,QAAQ,EACT,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAqB,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEpF,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,sBAAsB,EACtB,yBAAyB,EACzB,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAO7B,MAAM,WAAW,eAAe;IAE9B,eAAe,EAAE,cAAc,CAAC;IAChC,cAAc,EAAE,iBAAiB,CAAC;IAClC,cAAc,EAAE,iBAAiB,CAAC;IAClC,qEAAqE;IACrE,gBAAgB,EAAE,cAAc,CAAC;IACjC,uFAAuF;IACvF,sBAAsB,EAAE,yBAAyB,CAAC;IAGlD,aAAa,EAAE,gBAAgB,CAAC;IAChC,eAAe,EAAE,kBAAkB,CAAC;IAGpC,aAAa,EAAE,SAAS,CAAC;IACzB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