@webitel/chat-web-sdk 0.0.2 → 0.0.4
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 +3 -1
- package/dist/index.d.ts +45 -20
- package/dist/index.js +360 -140
- package/dist/index.js.map +1 -1
- package/package.json +39 -34
package/README.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import * as _webitel_api_services_gen_models from '@webitel/api-services/gen/models';
|
|
2
|
+
import { WebitelImApiGatewayV1HistoryMessage, WebitelImApiGatewayV1SearchMessageHistoryResponse, WebitelImApiGatewayV1SendDocumentRequest, WebitelImApiGatewayV1SendImageRequest, WebitelImApiGatewayV1ContactList, WebitelImApiGatewayV1Contact, WebitelImApiGatewayV1SendTextRequest, WebitelImApiGatewayV1SendTextResponse, ContactsSearchParams, MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams, WebitelImApiGatewayV1SendDocumentResponse, WebitelImApiGatewayV1SendImageResponse, WebitelImApiGatewayV1Thread, WebitelImApiGatewayV1SearchThreadResponse, ThreadManagementSearchParams } from '@webitel/api-services/gen/models';
|
|
3
|
+
export { WebitelImApiGatewayV1Authorization as AccountModel, WebitelImApiGatewayV1Contact as ContactModel, ContactsSearchParams as ContactSearchParams, MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams as MessageHistorySearchParams, WebitelImApiGatewayV1HistoryMessage as MessageModel, WebitelImApiGatewayV1Thread as ThreadModel, ThreadManagementSearchParams as ThreadSearchParams } from '@webitel/api-services/gen/models';
|
|
1
4
|
import { AxiosInstance } from 'axios';
|
|
2
|
-
import { WebitelImApiGatewayV1HistoryMessage, WebitelImApiGatewayV1SearchMessageHistoryResponse, WebitelImApiGatewayV1Thread, MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams, WebitelImApiGatewayV1SearchThreadResponse, ThreadManagementSearchParams, WebitelImApiGatewayV1ContactList, WebitelImApiGatewayV1Contact, ContactsSearchParams } from '@webitel/api-services/gen/models';
|
|
3
|
-
export { WebitelImApiGatewayV1Contact as ContactModel, ContactsSearchParams as ContactSearchParams, MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams as MessageHistorySearchParams, WebitelImApiGatewayV1HistoryMessage as MessageModel, WebitelImApiGatewayV1Thread as ThreadModel, ThreadManagementSearchParams as ThreadSearchParams } from '@webitel/api-services/gen/models';
|
|
4
5
|
|
|
5
6
|
type ServiceConfigInputSchema = {
|
|
6
7
|
baseUrl: string;
|
|
@@ -10,7 +11,7 @@ declare class ServiceConfig implements ServiceConfigInputSchema {
|
|
|
10
11
|
baseUrl: string;
|
|
11
12
|
accessToken: string | (() => string) | (() => Promise<string>);
|
|
12
13
|
axiosInstance: AxiosInstance;
|
|
13
|
-
constructor({ baseUrl, accessToken
|
|
14
|
+
constructor({ baseUrl, accessToken }: ServiceConfigInputSchema);
|
|
14
15
|
setupAxiosTokenHandler(): void;
|
|
15
16
|
}
|
|
16
17
|
declare function createServiceConfig(rawServiceConfig: ServiceConfigInputSchema): ServiceConfig;
|
|
@@ -22,7 +23,7 @@ type SocketConfigInputSchema = {
|
|
|
22
23
|
declare class SocketConfig implements SocketConfigInputSchema {
|
|
23
24
|
baseUrl: string;
|
|
24
25
|
accessToken: string | (() => string) | (() => Promise<string>);
|
|
25
|
-
constructor({ baseUrl, accessToken
|
|
26
|
+
constructor({ baseUrl, accessToken }: SocketConfigInputSchema);
|
|
26
27
|
}
|
|
27
28
|
declare function createSocketConfig(rawSocketConfig: SocketConfigInputSchema): SocketConfig;
|
|
28
29
|
|
|
@@ -30,30 +31,32 @@ interface ServiceConfigurable {
|
|
|
30
31
|
get serviceConfig(): ServiceConfig;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
declare function useAccountService(config: ServiceConfig): {
|
|
35
|
+
getAccount: () => Promise<_webitel_api_services_gen_models.WebitelImApiGatewayV1Authorization>;
|
|
36
|
+
};
|
|
37
|
+
|
|
33
38
|
interface IMessage extends WebitelImApiGatewayV1HistoryMessage {
|
|
34
39
|
markRead: () => Promise<void>;
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
37
42
|
* API response with `messages` replaced by instantiated SDK `Message` classes.
|
|
38
43
|
*/
|
|
39
|
-
type MessageHistorySearchResult = Omit<WebitelImApiGatewayV1SearchMessageHistoryResponse, '
|
|
40
|
-
|
|
44
|
+
type MessageHistorySearchResult = Omit<WebitelImApiGatewayV1SearchMessageHistoryResponse, 'items'> & {
|
|
45
|
+
items: IMessage[];
|
|
41
46
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
type ThreadSearchResult = Omit<WebitelImApiGatewayV1SearchThreadResponse, 'threads'> & {
|
|
48
|
-
threads: IThread[];
|
|
47
|
+
type MessageSendFileParams = Omit<WebitelImApiGatewayV1SendDocumentRequest, 'document'> & {
|
|
48
|
+
document?: NonNullable<WebitelImApiGatewayV1SendDocumentRequest['document']>;
|
|
49
|
+
file: File;
|
|
50
|
+
threadId: string;
|
|
49
51
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
type MessageSendImageParams = Omit<WebitelImApiGatewayV1SendImageRequest, 'image'> & {
|
|
53
|
+
image?: NonNullable<WebitelImApiGatewayV1SendImageRequest['image']>;
|
|
54
|
+
file: File;
|
|
55
|
+
threadId: string;
|
|
53
56
|
};
|
|
54
57
|
|
|
55
58
|
interface IContact extends WebitelImApiGatewayV1Contact, ServiceConfigurable {
|
|
56
|
-
|
|
59
|
+
sendTextMessage: (body: string, params?: Omit<WebitelImApiGatewayV1SendTextRequest, 'body' | 'to'>) => Promise<WebitelImApiGatewayV1SendTextResponse>;
|
|
57
60
|
}
|
|
58
61
|
type ContactSearchResult = Omit<WebitelImApiGatewayV1ContactList, 'items'> & {
|
|
59
62
|
items: IContact[];
|
|
@@ -63,9 +66,13 @@ declare function useContactsService(config: ServiceConfig): {
|
|
|
63
66
|
fetchContacts: (params?: ContactsSearchParams) => Promise<ContactSearchResult>;
|
|
64
67
|
};
|
|
65
68
|
|
|
66
|
-
|
|
69
|
+
interface IMessagesService {
|
|
67
70
|
fetchMessageHistory: (threadId: string, params?: MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams) => Promise<MessageHistorySearchResult>;
|
|
68
|
-
|
|
71
|
+
sendTextMessage: (params: WebitelImApiGatewayV1SendTextRequest) => Promise<WebitelImApiGatewayV1SendTextResponse>;
|
|
72
|
+
sendFileMessage: (params: MessageSendFileParams) => Promise<WebitelImApiGatewayV1SendDocumentResponse>;
|
|
73
|
+
sendImageMessage: (params: MessageSendImageParams) => Promise<WebitelImApiGatewayV1SendImageResponse>;
|
|
74
|
+
}
|
|
75
|
+
declare function useMessagesService(config: ServiceConfig): IMessagesService;
|
|
69
76
|
|
|
70
77
|
/**
|
|
71
78
|
* @see https://github.com/webitel/im-delivery-service/blob/main/api/asyncapi/asyncapi.yaml#L56
|
|
@@ -109,4 +116,22 @@ declare class ChatsSocketClient implements IChatsSocketClient {
|
|
|
109
116
|
}
|
|
110
117
|
declare function createChatsSocketClient(config: SocketConfig): ChatsSocketClient;
|
|
111
118
|
|
|
112
|
-
|
|
119
|
+
type ThreadSendTextMessageParams = Omit<WebitelImApiGatewayV1SendTextRequest, 'body' | 'to'>;
|
|
120
|
+
type ThreadSendFileMessageParams = Omit<MessageSendFileParams, 'file' | 'threadId' | 'to'>;
|
|
121
|
+
type ThreadSendImageMessageParams = Omit<MessageSendImageParams, 'file' | 'threadId' | 'to'>;
|
|
122
|
+
interface IThread extends WebitelImApiGatewayV1Thread, ServiceConfigurable {
|
|
123
|
+
id: string;
|
|
124
|
+
fetchMessageHistory: (params?: MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams) => Promise<MessageHistorySearchResult>;
|
|
125
|
+
sendTextMessage: (body: string, params?: ThreadSendTextMessageParams) => Promise<WebitelImApiGatewayV1SendTextResponse>;
|
|
126
|
+
sendFileMessage: (file: File, params?: ThreadSendFileMessageParams) => Promise<WebitelImApiGatewayV1SendDocumentResponse>;
|
|
127
|
+
sendImageMessage: (file: File, params?: ThreadSendImageMessageParams) => Promise<WebitelImApiGatewayV1SendImageResponse>;
|
|
128
|
+
}
|
|
129
|
+
type ThreadSearchResult = Omit<WebitelImApiGatewayV1SearchThreadResponse, 'items'> & {
|
|
130
|
+
items: IThread[];
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
declare function useThreadsService(config: ServiceConfig): {
|
|
134
|
+
fetchThreads: (params?: ThreadManagementSearchParams) => Promise<ThreadSearchResult>;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export { ChatsSocketMessage, type ContactSearchResult, type IContact, type IMessage, type IThread, type MessageHistorySearchResult, ServiceConfig, type ServiceConfigInputSchema, SocketConfig, type SocketConfigInputSchema, type ThreadSearchResult, createChatsSocketClient, createServiceConfig, createSocketConfig, useAccountService, useContactsService, useMessagesService, useThreadsService };
|