@webitel/chat-web-sdk 0.0.2 → 0.0.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 +3 -1
- package/dist/index.d.ts +25 -18
- package/dist/index.js +243 -135
- 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, WebitelImApiGatewayV1ContactList, WebitelImApiGatewayV1Contact, WebitelImApiGatewayV1SendTextRequest, WebitelImApiGatewayV1SendTextResponse, ContactsSearchParams, MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams, 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,6 +31,10 @@ 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
|
}
|
|
@@ -40,20 +45,8 @@ type MessageHistorySearchResult = Omit<WebitelImApiGatewayV1SearchMessageHistory
|
|
|
40
45
|
messages: IMessage[];
|
|
41
46
|
};
|
|
42
47
|
|
|
43
|
-
interface IThread extends WebitelImApiGatewayV1Thread, ServiceConfigurable {
|
|
44
|
-
id: string;
|
|
45
|
-
fetchMessageHistory: (params?: MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams) => Promise<MessageHistorySearchResult>;
|
|
46
|
-
}
|
|
47
|
-
type ThreadSearchResult = Omit<WebitelImApiGatewayV1SearchThreadResponse, 'threads'> & {
|
|
48
|
-
threads: IThread[];
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
declare function useThreadsService(config: ServiceConfig): {
|
|
52
|
-
fetchThreads: (params?: ThreadManagementSearchParams) => Promise<ThreadSearchResult>;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
48
|
interface IContact extends WebitelImApiGatewayV1Contact, ServiceConfigurable {
|
|
56
|
-
|
|
49
|
+
sendTextMessage: (body: string, params?: Omit<WebitelImApiGatewayV1SendTextRequest, 'body' | 'to'>) => Promise<WebitelImApiGatewayV1SendTextResponse>;
|
|
57
50
|
}
|
|
58
51
|
type ContactSearchResult = Omit<WebitelImApiGatewayV1ContactList, 'items'> & {
|
|
59
52
|
items: IContact[];
|
|
@@ -65,6 +58,7 @@ declare function useContactsService(config: ServiceConfig): {
|
|
|
65
58
|
|
|
66
59
|
declare function useMessagesService(config: ServiceConfig): {
|
|
67
60
|
fetchMessageHistory: (threadId: string, params?: MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams) => Promise<MessageHistorySearchResult>;
|
|
61
|
+
sendTextMessage: (params: WebitelImApiGatewayV1SendTextRequest) => Promise<_webitel_api_services_gen_models.WebitelImApiGatewayV1SendTextResponse>;
|
|
68
62
|
};
|
|
69
63
|
|
|
70
64
|
/**
|
|
@@ -109,4 +103,17 @@ declare class ChatsSocketClient implements IChatsSocketClient {
|
|
|
109
103
|
}
|
|
110
104
|
declare function createChatsSocketClient(config: SocketConfig): ChatsSocketClient;
|
|
111
105
|
|
|
112
|
-
|
|
106
|
+
interface IThread extends WebitelImApiGatewayV1Thread, ServiceConfigurable {
|
|
107
|
+
id: string;
|
|
108
|
+
fetchMessageHistory: (params?: MessageHistorySearchThreadMessagesHistoryWebitelImApiGatewayV1MessageHistoryParams) => Promise<MessageHistorySearchResult>;
|
|
109
|
+
sendTextMessage: (body: string, params?: Omit<WebitelImApiGatewayV1SendTextRequest, 'body' | 'to'>) => Promise<WebitelImApiGatewayV1SendTextResponse>;
|
|
110
|
+
}
|
|
111
|
+
type ThreadSearchResult = Omit<WebitelImApiGatewayV1SearchThreadResponse, 'threads'> & {
|
|
112
|
+
threads: IThread[];
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
declare function useThreadsService(config: ServiceConfig): {
|
|
116
|
+
fetchThreads: (params?: ThreadManagementSearchParams) => Promise<ThreadSearchResult>;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -193,24 +193,6 @@ var require_deep_copy = __commonJS({
|
|
|
193
193
|
}
|
|
194
194
|
});
|
|
195
195
|
|
|
196
|
-
// src/modules/messages/classes/Message.class.ts
|
|
197
|
-
var Message = class {
|
|
198
|
-
_serviceConfig;
|
|
199
|
-
constructor(rawMessage, { serviceConfig }) {
|
|
200
|
-
Object.assign(this, rawMessage);
|
|
201
|
-
this._serviceConfig = serviceConfig;
|
|
202
|
-
}
|
|
203
|
-
get serviceConfig() {
|
|
204
|
-
return this._serviceConfig;
|
|
205
|
-
}
|
|
206
|
-
async markRead() {
|
|
207
|
-
throw new Error("Method not implemented.");
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
function createMessage(rawMessage, { serviceConfig }) {
|
|
211
|
-
return new Message(rawMessage, { serviceConfig });
|
|
212
|
-
}
|
|
213
|
-
|
|
214
196
|
// node_modules/@webitel/api-services/src/api/transformers/applyTransform.ts
|
|
215
197
|
var applyTransform = (target, transformers, { debug = false, withContext = null } = {}) => {
|
|
216
198
|
return transformers.reduce((result, transformer, index) => {
|
|
@@ -7073,14 +7055,11 @@ function preprocess(fn, schema) {
|
|
|
7073
7055
|
// node_modules/zod/v4/classic/external.js
|
|
7074
7056
|
config2(en_default2());
|
|
7075
7057
|
|
|
7076
|
-
// src/modules/
|
|
7077
|
-
var
|
|
7058
|
+
// src/modules/account/api/Account.api.ts
|
|
7059
|
+
var getAccountService = ({ axiosInstance }) => {
|
|
7078
7060
|
return {
|
|
7079
|
-
|
|
7080
|
-
const
|
|
7081
|
-
camelToSnake_transformer_default()
|
|
7082
|
-
]);
|
|
7083
|
-
const response = await axiosInstance.get(`/v1/${threadId}/messages`, { params: transformedParams });
|
|
7061
|
+
getAccount: async () => {
|
|
7062
|
+
const response = await axiosInstance.get("/v1/auth/token");
|
|
7084
7063
|
return applyTransform(response.data, [
|
|
7085
7064
|
snakeToCamel_transformer_default()
|
|
7086
7065
|
]);
|
|
@@ -7088,56 +7067,106 @@ var getMessagesService = ({ axiosInstance }) => {
|
|
|
7088
7067
|
};
|
|
7089
7068
|
};
|
|
7090
7069
|
|
|
7091
|
-
// src/modules/
|
|
7092
|
-
var
|
|
7093
|
-
|
|
7094
|
-
return response;
|
|
7070
|
+
// src/modules/account/utils/fetchAccount.ts
|
|
7071
|
+
var fetchAccount = async (config3) => {
|
|
7072
|
+
return getAccountService(config3).getAccount();
|
|
7095
7073
|
};
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
var fetchMessageHistory = async (config3, threadId, params = {}) => {
|
|
7100
|
-
const rawResponse = await fetchRawMessageHistory(config3)(threadId, params);
|
|
7074
|
+
|
|
7075
|
+
// src/modules/account/accountSevice.ts
|
|
7076
|
+
function useAccountService(config3) {
|
|
7101
7077
|
return {
|
|
7102
|
-
|
|
7103
|
-
messages: instantiateMessages(rawResponse.messages ?? [], { serviceConfig: config3 })
|
|
7078
|
+
getAccount: () => fetchAccount(config3)
|
|
7104
7079
|
};
|
|
7080
|
+
}
|
|
7081
|
+
var ServiceConfig = class {
|
|
7082
|
+
baseUrl;
|
|
7083
|
+
accessToken;
|
|
7084
|
+
axiosInstance;
|
|
7085
|
+
constructor({ baseUrl, accessToken }) {
|
|
7086
|
+
this.baseUrl = baseUrl;
|
|
7087
|
+
this.accessToken = accessToken;
|
|
7088
|
+
this.axiosInstance = axios.create({
|
|
7089
|
+
baseURL: this.baseUrl,
|
|
7090
|
+
paramsSerializer: (params) => qs2.stringify(params, {
|
|
7091
|
+
allowDots: true
|
|
7092
|
+
})
|
|
7093
|
+
});
|
|
7094
|
+
this.setupAxiosTokenHandler();
|
|
7095
|
+
}
|
|
7096
|
+
setupAxiosTokenHandler() {
|
|
7097
|
+
if (typeof this.accessToken === "function") {
|
|
7098
|
+
this.axiosInstance.interceptors.request.use(async (config3) => {
|
|
7099
|
+
config3.headers["X-Webitel-Access"] = await this.accessToken();
|
|
7100
|
+
return config3;
|
|
7101
|
+
});
|
|
7102
|
+
} else {
|
|
7103
|
+
this.axiosInstance.defaults.headers.common["X-Webitel-Access"] = this.accessToken;
|
|
7104
|
+
}
|
|
7105
|
+
}
|
|
7105
7106
|
};
|
|
7107
|
+
function createServiceConfig(rawServiceConfig) {
|
|
7108
|
+
return new ServiceConfig(rawServiceConfig);
|
|
7109
|
+
}
|
|
7106
7110
|
|
|
7107
|
-
// src/modules/
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
}
|
|
7111
|
+
// src/modules/configs/socketConfig/SocketConfig.class.ts
|
|
7112
|
+
var SocketConfig = class {
|
|
7113
|
+
baseUrl;
|
|
7114
|
+
accessToken;
|
|
7115
|
+
constructor({ baseUrl, accessToken }) {
|
|
7116
|
+
this.baseUrl = baseUrl;
|
|
7117
|
+
this.accessToken = accessToken;
|
|
7118
|
+
}
|
|
7119
|
+
};
|
|
7120
|
+
function createSocketConfig(rawSocketConfig) {
|
|
7121
|
+
return new SocketConfig(rawSocketConfig);
|
|
7112
7122
|
}
|
|
7113
7123
|
|
|
7114
|
-
// src/modules/
|
|
7115
|
-
var
|
|
7124
|
+
// src/modules/messages/classes/Message.class.ts
|
|
7125
|
+
var Message = class {
|
|
7116
7126
|
_serviceConfig;
|
|
7117
|
-
|
|
7118
|
-
|
|
7119
|
-
|
|
7127
|
+
constructor(rawMessage, {
|
|
7128
|
+
serviceConfig
|
|
7129
|
+
}) {
|
|
7130
|
+
Object.assign(this, rawMessage);
|
|
7120
7131
|
this._serviceConfig = serviceConfig;
|
|
7121
7132
|
}
|
|
7122
|
-
async fetchMessageHistory(params) {
|
|
7123
|
-
return useMessagesService(this.serviceConfig).fetchMessageHistory(this.id, params);
|
|
7124
|
-
}
|
|
7125
7133
|
get serviceConfig() {
|
|
7126
7134
|
return this._serviceConfig;
|
|
7127
7135
|
}
|
|
7136
|
+
async markRead() {
|
|
7137
|
+
throw new Error("Method not implemented.");
|
|
7138
|
+
}
|
|
7128
7139
|
};
|
|
7129
|
-
function
|
|
7130
|
-
|
|
7140
|
+
function createMessage(rawMessage, {
|
|
7141
|
+
serviceConfig
|
|
7142
|
+
}) {
|
|
7143
|
+
return new Message(rawMessage, {
|
|
7144
|
+
serviceConfig
|
|
7145
|
+
});
|
|
7131
7146
|
}
|
|
7132
7147
|
|
|
7133
|
-
// src/modules/
|
|
7134
|
-
var
|
|
7148
|
+
// src/modules/messages/api/Messages.api.ts
|
|
7149
|
+
var getMessagesService = ({ axiosInstance }) => {
|
|
7135
7150
|
return {
|
|
7136
|
-
|
|
7151
|
+
getMessageHistory: async (threadId, params = {}) => {
|
|
7137
7152
|
const transformedParams = applyTransform(params, [
|
|
7138
7153
|
camelToSnake_transformer_default()
|
|
7139
7154
|
]);
|
|
7140
|
-
const response = await axiosInstance.get(
|
|
7155
|
+
const response = await axiosInstance.get(`/v1/${threadId}/messages`, {
|
|
7156
|
+
params: transformedParams
|
|
7157
|
+
});
|
|
7158
|
+
return applyTransform(response.data, [
|
|
7159
|
+
snakeToCamel_transformer_default()
|
|
7160
|
+
]);
|
|
7161
|
+
},
|
|
7162
|
+
sendTextMessage: async (params) => {
|
|
7163
|
+
const transformedParams = applyTransform(params, [
|
|
7164
|
+
camelToSnake_transformer_default()
|
|
7165
|
+
]);
|
|
7166
|
+
const response = await axiosInstance.post(
|
|
7167
|
+
"/v1/messages/text",
|
|
7168
|
+
transformedParams
|
|
7169
|
+
);
|
|
7141
7170
|
return applyTransform(response.data, [
|
|
7142
7171
|
snakeToCamel_transformer_default()
|
|
7143
7172
|
]);
|
|
@@ -7145,31 +7174,81 @@ var getThreadsService = ({ axiosInstance }) => {
|
|
|
7145
7174
|
};
|
|
7146
7175
|
};
|
|
7147
7176
|
|
|
7148
|
-
// src/modules/
|
|
7149
|
-
var
|
|
7150
|
-
const response = await
|
|
7177
|
+
// src/modules/messages/utils/fetchMessageHistory.ts
|
|
7178
|
+
var fetchRawMessageHistory = (config3) => async (threadId, params = {}) => {
|
|
7179
|
+
const response = await getMessagesService(config3).getMessageHistory(
|
|
7180
|
+
threadId,
|
|
7181
|
+
params
|
|
7182
|
+
);
|
|
7151
7183
|
return response;
|
|
7152
7184
|
};
|
|
7153
|
-
var
|
|
7154
|
-
|
|
7185
|
+
var instantiateMessages = (rawMessages, {
|
|
7186
|
+
serviceConfig
|
|
7187
|
+
}) => {
|
|
7188
|
+
return rawMessages.map(
|
|
7189
|
+
(rawMessage) => createMessage(rawMessage, {
|
|
7190
|
+
serviceConfig
|
|
7191
|
+
})
|
|
7192
|
+
);
|
|
7155
7193
|
};
|
|
7156
|
-
var
|
|
7157
|
-
const
|
|
7194
|
+
var fetchMessageHistory = async (config3, threadId, params = {}) => {
|
|
7195
|
+
const rawResponse = await fetchRawMessageHistory(config3)(threadId, params);
|
|
7158
7196
|
return {
|
|
7159
|
-
...
|
|
7160
|
-
|
|
7197
|
+
...rawResponse,
|
|
7198
|
+
messages: instantiateMessages(rawResponse.messages ?? [], {
|
|
7161
7199
|
serviceConfig: config3
|
|
7162
7200
|
})
|
|
7163
7201
|
};
|
|
7164
7202
|
};
|
|
7165
7203
|
|
|
7166
|
-
// src/modules/
|
|
7167
|
-
|
|
7204
|
+
// src/modules/messages/utils/sendTextMessage.ts
|
|
7205
|
+
var sendTextMessage = async (config3, params) => {
|
|
7206
|
+
return getMessagesService(config3).sendTextMessage(params);
|
|
7207
|
+
};
|
|
7208
|
+
|
|
7209
|
+
// src/modules/messages/messagesSevice.ts
|
|
7210
|
+
function useMessagesService(config3) {
|
|
7168
7211
|
return {
|
|
7169
|
-
|
|
7212
|
+
fetchMessageHistory: (threadId, params) => fetchMessageHistory(config3, threadId, params ?? {}),
|
|
7213
|
+
sendTextMessage: (params) => sendTextMessage(config3, params)
|
|
7170
7214
|
};
|
|
7171
7215
|
}
|
|
7172
7216
|
|
|
7217
|
+
// src/modules/contacts/classes/Contact.class.ts
|
|
7218
|
+
var Contact = class {
|
|
7219
|
+
_serviceConfig;
|
|
7220
|
+
subject;
|
|
7221
|
+
issId;
|
|
7222
|
+
constructor(rawContact, {
|
|
7223
|
+
serviceConfig
|
|
7224
|
+
}) {
|
|
7225
|
+
Object.assign(this, rawContact);
|
|
7226
|
+
this._serviceConfig = serviceConfig;
|
|
7227
|
+
}
|
|
7228
|
+
async sendTextMessage(body, params = {}) {
|
|
7229
|
+
return useMessagesService(this.serviceConfig).sendTextMessage({
|
|
7230
|
+
...params,
|
|
7231
|
+
body,
|
|
7232
|
+
to: {
|
|
7233
|
+
contact: {
|
|
7234
|
+
sub: this.subject,
|
|
7235
|
+
iss: this.issId
|
|
7236
|
+
}
|
|
7237
|
+
}
|
|
7238
|
+
});
|
|
7239
|
+
}
|
|
7240
|
+
get serviceConfig() {
|
|
7241
|
+
return this._serviceConfig;
|
|
7242
|
+
}
|
|
7243
|
+
};
|
|
7244
|
+
function createContact(rawContact, {
|
|
7245
|
+
serviceConfig
|
|
7246
|
+
}) {
|
|
7247
|
+
return new Contact(rawContact, {
|
|
7248
|
+
serviceConfig
|
|
7249
|
+
});
|
|
7250
|
+
}
|
|
7251
|
+
|
|
7173
7252
|
// src/modules/contacts/api/Contacts.api.ts
|
|
7174
7253
|
var getContactsService = ({ axiosInstance }) => {
|
|
7175
7254
|
return {
|
|
@@ -7177,7 +7256,9 @@ var getContactsService = ({ axiosInstance }) => {
|
|
|
7177
7256
|
const transformedParams = applyTransform(params, [
|
|
7178
7257
|
camelToSnake_transformer_default()
|
|
7179
7258
|
]);
|
|
7180
|
-
const response = await axiosInstance.get("/v1/contacts", {
|
|
7259
|
+
const response = await axiosInstance.get("/v1/contacts", {
|
|
7260
|
+
params: transformedParams
|
|
7261
|
+
});
|
|
7181
7262
|
return applyTransform(response.data, [
|
|
7182
7263
|
snakeToCamel_transformer_default()
|
|
7183
7264
|
]);
|
|
@@ -7185,31 +7266,19 @@ var getContactsService = ({ axiosInstance }) => {
|
|
|
7185
7266
|
};
|
|
7186
7267
|
};
|
|
7187
7268
|
|
|
7188
|
-
// src/modules/contacts/classes/Contact.class.ts
|
|
7189
|
-
var Contact = class {
|
|
7190
|
-
_serviceConfig;
|
|
7191
|
-
constructor(rawContact, { serviceConfig }) {
|
|
7192
|
-
Object.assign(this, rawContact);
|
|
7193
|
-
this._serviceConfig = serviceConfig;
|
|
7194
|
-
}
|
|
7195
|
-
async sendMessage() {
|
|
7196
|
-
throw new Error("Method not implemented.");
|
|
7197
|
-
}
|
|
7198
|
-
get serviceConfig() {
|
|
7199
|
-
return this._serviceConfig;
|
|
7200
|
-
}
|
|
7201
|
-
};
|
|
7202
|
-
function createContact(rawContact, { serviceConfig }) {
|
|
7203
|
-
return new Contact(rawContact, { serviceConfig });
|
|
7204
|
-
}
|
|
7205
|
-
|
|
7206
7269
|
// src/modules/contacts/utils/fetchContacts.ts
|
|
7207
7270
|
var fetchRawContacts = (config3) => async (params = {}) => {
|
|
7208
7271
|
const response = await getContactsService(config3).getContactsList(params);
|
|
7209
7272
|
return response;
|
|
7210
7273
|
};
|
|
7211
|
-
var instantiateContacts = (rawContacts, {
|
|
7212
|
-
|
|
7274
|
+
var instantiateContacts = (rawContacts, {
|
|
7275
|
+
serviceConfig
|
|
7276
|
+
}) => {
|
|
7277
|
+
return rawContacts.map(
|
|
7278
|
+
(rawContact) => createContact(rawContact, {
|
|
7279
|
+
serviceConfig
|
|
7280
|
+
})
|
|
7281
|
+
);
|
|
7213
7282
|
};
|
|
7214
7283
|
var fetchContacts = async (config3, params = {}) => {
|
|
7215
7284
|
const rawResponse = await fetchRawContacts(config3)(params);
|
|
@@ -7227,52 +7296,6 @@ function useContactsService(config3) {
|
|
|
7227
7296
|
fetchContacts: (params) => fetchContacts(config3, params ?? {})
|
|
7228
7297
|
};
|
|
7229
7298
|
}
|
|
7230
|
-
var ServiceConfig = class {
|
|
7231
|
-
baseUrl;
|
|
7232
|
-
accessToken;
|
|
7233
|
-
axiosInstance;
|
|
7234
|
-
constructor({
|
|
7235
|
-
baseUrl,
|
|
7236
|
-
accessToken
|
|
7237
|
-
}) {
|
|
7238
|
-
this.baseUrl = baseUrl;
|
|
7239
|
-
this.accessToken = accessToken;
|
|
7240
|
-
this.axiosInstance = axios.create({
|
|
7241
|
-
baseURL: this.baseUrl,
|
|
7242
|
-
paramsSerializer: (params) => qs2.stringify(params, { allowDots: true })
|
|
7243
|
-
});
|
|
7244
|
-
this.setupAxiosTokenHandler();
|
|
7245
|
-
}
|
|
7246
|
-
setupAxiosTokenHandler() {
|
|
7247
|
-
if (typeof this.accessToken === "function") {
|
|
7248
|
-
this.axiosInstance.interceptors.request.use(async (config3) => {
|
|
7249
|
-
config3.headers["X-Webitel-Access"] = await this.accessToken();
|
|
7250
|
-
return config3;
|
|
7251
|
-
});
|
|
7252
|
-
} else {
|
|
7253
|
-
this.axiosInstance.defaults.headers.common["X-Webitel-Access"] = this.accessToken;
|
|
7254
|
-
}
|
|
7255
|
-
}
|
|
7256
|
-
};
|
|
7257
|
-
function createServiceConfig(rawServiceConfig) {
|
|
7258
|
-
return new ServiceConfig(rawServiceConfig);
|
|
7259
|
-
}
|
|
7260
|
-
|
|
7261
|
-
// src/modules/configs/socketConfig/SocketConfig.class.ts
|
|
7262
|
-
var SocketConfig = class {
|
|
7263
|
-
baseUrl;
|
|
7264
|
-
accessToken;
|
|
7265
|
-
constructor({
|
|
7266
|
-
baseUrl,
|
|
7267
|
-
accessToken
|
|
7268
|
-
}) {
|
|
7269
|
-
this.baseUrl = baseUrl;
|
|
7270
|
-
this.accessToken = accessToken;
|
|
7271
|
-
}
|
|
7272
|
-
};
|
|
7273
|
-
function createSocketConfig(rawSocketConfig) {
|
|
7274
|
-
return new SocketConfig(rawSocketConfig);
|
|
7275
|
-
}
|
|
7276
7299
|
|
|
7277
7300
|
// src/modules/socket/enums/ChatsSocketMessage.enum.ts
|
|
7278
7301
|
var ChatsSocketMessage = {
|
|
@@ -7365,6 +7388,91 @@ function createChatsSocketClient(config3) {
|
|
|
7365
7388
|
return new ChatsSocketClient(config3);
|
|
7366
7389
|
}
|
|
7367
7390
|
|
|
7368
|
-
|
|
7391
|
+
// src/modules/threads/classes/Thread.class.ts
|
|
7392
|
+
var Thread = class {
|
|
7393
|
+
_serviceConfig;
|
|
7394
|
+
id;
|
|
7395
|
+
constructor(rawThread, {
|
|
7396
|
+
serviceConfig
|
|
7397
|
+
}) {
|
|
7398
|
+
Object.assign(this, rawThread);
|
|
7399
|
+
this._serviceConfig = serviceConfig;
|
|
7400
|
+
}
|
|
7401
|
+
async fetchMessageHistory(params) {
|
|
7402
|
+
return useMessagesService(this.serviceConfig).fetchMessageHistory(
|
|
7403
|
+
this.id,
|
|
7404
|
+
params
|
|
7405
|
+
);
|
|
7406
|
+
}
|
|
7407
|
+
async sendTextMessage(body, params = {}) {
|
|
7408
|
+
return useMessagesService(this.serviceConfig).sendTextMessage({
|
|
7409
|
+
...params,
|
|
7410
|
+
body,
|
|
7411
|
+
to: {
|
|
7412
|
+
threadId: this.id
|
|
7413
|
+
}
|
|
7414
|
+
});
|
|
7415
|
+
}
|
|
7416
|
+
get serviceConfig() {
|
|
7417
|
+
return this._serviceConfig;
|
|
7418
|
+
}
|
|
7419
|
+
};
|
|
7420
|
+
function createThread(rawThread, {
|
|
7421
|
+
serviceConfig
|
|
7422
|
+
}) {
|
|
7423
|
+
return new Thread(rawThread, {
|
|
7424
|
+
serviceConfig
|
|
7425
|
+
});
|
|
7426
|
+
}
|
|
7427
|
+
|
|
7428
|
+
// src/modules/threads/api/Threads.api.ts
|
|
7429
|
+
var getThreadsService = ({ axiosInstance }) => {
|
|
7430
|
+
return {
|
|
7431
|
+
getThreadsList: async (params = {}) => {
|
|
7432
|
+
const transformedParams = applyTransform(params, [
|
|
7433
|
+
camelToSnake_transformer_default()
|
|
7434
|
+
]);
|
|
7435
|
+
const response = await axiosInstance.get("/v1/threads", {
|
|
7436
|
+
params: transformedParams
|
|
7437
|
+
});
|
|
7438
|
+
return applyTransform(response.data, [
|
|
7439
|
+
snakeToCamel_transformer_default()
|
|
7440
|
+
]);
|
|
7441
|
+
}
|
|
7442
|
+
};
|
|
7443
|
+
};
|
|
7444
|
+
|
|
7445
|
+
// src/modules/threads/utils/fetchThreads.ts
|
|
7446
|
+
var fetchRawThreads = (config3) => async (params = {}) => {
|
|
7447
|
+
const response = await getThreadsService(config3).getThreadsList(params);
|
|
7448
|
+
return response;
|
|
7449
|
+
};
|
|
7450
|
+
var instantiateThreads = (rawThreads, {
|
|
7451
|
+
serviceConfig
|
|
7452
|
+
}) => {
|
|
7453
|
+
return rawThreads.map(
|
|
7454
|
+
(rawThread) => createThread(rawThread, {
|
|
7455
|
+
serviceConfig
|
|
7456
|
+
})
|
|
7457
|
+
);
|
|
7458
|
+
};
|
|
7459
|
+
var fetchThreads = async (config3, params = {}) => {
|
|
7460
|
+
const rawThreadsResponse = await fetchRawThreads(config3)(params);
|
|
7461
|
+
return {
|
|
7462
|
+
...rawThreadsResponse,
|
|
7463
|
+
threads: instantiateThreads(rawThreadsResponse.threads ?? [], {
|
|
7464
|
+
serviceConfig: config3
|
|
7465
|
+
})
|
|
7466
|
+
};
|
|
7467
|
+
};
|
|
7468
|
+
|
|
7469
|
+
// src/modules/threads/threadsSevice.ts
|
|
7470
|
+
function useThreadsService(config3) {
|
|
7471
|
+
return {
|
|
7472
|
+
fetchThreads: (params) => fetchThreads(config3, params ?? {})
|
|
7473
|
+
};
|
|
7474
|
+
}
|
|
7475
|
+
|
|
7476
|
+
export { ChatsSocketMessage, createChatsSocketClient, createServiceConfig, createSocketConfig, useAccountService, useContactsService, useMessagesService, useThreadsService };
|
|
7369
7477
|
//# sourceMappingURL=index.js.map
|
|
7370
7478
|
//# sourceMappingURL=index.js.map
|