@webitel/chat-web-sdk 0.0.1 → 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 +244 -134
- package/dist/index.js.map +1 -1
- package/package.json +39 -33
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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as qs2 from 'qs-esm';
|
|
1
2
|
import axios from 'axios';
|
|
2
3
|
import mitt from 'mitt';
|
|
3
4
|
|
|
@@ -192,24 +193,6 @@ var require_deep_copy = __commonJS({
|
|
|
192
193
|
}
|
|
193
194
|
});
|
|
194
195
|
|
|
195
|
-
// src/modules/messages/classes/Message.class.ts
|
|
196
|
-
var Message = class {
|
|
197
|
-
_serviceConfig;
|
|
198
|
-
constructor(rawMessage, { serviceConfig }) {
|
|
199
|
-
Object.assign(this, rawMessage);
|
|
200
|
-
this._serviceConfig = serviceConfig;
|
|
201
|
-
}
|
|
202
|
-
get serviceConfig() {
|
|
203
|
-
return this._serviceConfig;
|
|
204
|
-
}
|
|
205
|
-
async markRead() {
|
|
206
|
-
throw new Error("Method not implemented.");
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
function createMessage(rawMessage, { serviceConfig }) {
|
|
210
|
-
return new Message(rawMessage, { serviceConfig });
|
|
211
|
-
}
|
|
212
|
-
|
|
213
196
|
// node_modules/@webitel/api-services/src/api/transformers/applyTransform.ts
|
|
214
197
|
var applyTransform = (target, transformers, { debug = false, withContext = null } = {}) => {
|
|
215
198
|
return transformers.reduce((result, transformer, index) => {
|
|
@@ -7072,14 +7055,11 @@ function preprocess(fn, schema) {
|
|
|
7072
7055
|
// node_modules/zod/v4/classic/external.js
|
|
7073
7056
|
config2(en_default2());
|
|
7074
7057
|
|
|
7075
|
-
// src/modules/
|
|
7076
|
-
var
|
|
7058
|
+
// src/modules/account/api/Account.api.ts
|
|
7059
|
+
var getAccountService = ({ axiosInstance }) => {
|
|
7077
7060
|
return {
|
|
7078
|
-
|
|
7079
|
-
const
|
|
7080
|
-
camelToSnake_transformer_default()
|
|
7081
|
-
]);
|
|
7082
|
-
const response = await axiosInstance.get(`/v1/${threadId}/messages`, { params: transformedParams });
|
|
7061
|
+
getAccount: async () => {
|
|
7062
|
+
const response = await axiosInstance.get("/v1/auth/token");
|
|
7083
7063
|
return applyTransform(response.data, [
|
|
7084
7064
|
snakeToCamel_transformer_default()
|
|
7085
7065
|
]);
|
|
@@ -7087,56 +7067,106 @@ var getMessagesService = ({ axiosInstance }) => {
|
|
|
7087
7067
|
};
|
|
7088
7068
|
};
|
|
7089
7069
|
|
|
7090
|
-
// src/modules/
|
|
7091
|
-
var
|
|
7092
|
-
|
|
7093
|
-
return response;
|
|
7070
|
+
// src/modules/account/utils/fetchAccount.ts
|
|
7071
|
+
var fetchAccount = async (config3) => {
|
|
7072
|
+
return getAccountService(config3).getAccount();
|
|
7094
7073
|
};
|
|
7095
|
-
|
|
7096
|
-
|
|
7097
|
-
|
|
7098
|
-
var fetchMessageHistory = async (config3, threadId, params = {}) => {
|
|
7099
|
-
const rawResponse = await fetchRawMessageHistory(config3)(threadId, params);
|
|
7074
|
+
|
|
7075
|
+
// src/modules/account/accountSevice.ts
|
|
7076
|
+
function useAccountService(config3) {
|
|
7100
7077
|
return {
|
|
7101
|
-
|
|
7102
|
-
messages: instantiateMessages(rawResponse.messages ?? [], { serviceConfig: config3 })
|
|
7078
|
+
getAccount: () => fetchAccount(config3)
|
|
7103
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
|
+
}
|
|
7104
7106
|
};
|
|
7107
|
+
function createServiceConfig(rawServiceConfig) {
|
|
7108
|
+
return new ServiceConfig(rawServiceConfig);
|
|
7109
|
+
}
|
|
7105
7110
|
|
|
7106
|
-
// src/modules/
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
}
|
|
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);
|
|
7111
7122
|
}
|
|
7112
7123
|
|
|
7113
|
-
// src/modules/
|
|
7114
|
-
var
|
|
7124
|
+
// src/modules/messages/classes/Message.class.ts
|
|
7125
|
+
var Message = class {
|
|
7115
7126
|
_serviceConfig;
|
|
7116
|
-
|
|
7117
|
-
|
|
7118
|
-
|
|
7127
|
+
constructor(rawMessage, {
|
|
7128
|
+
serviceConfig
|
|
7129
|
+
}) {
|
|
7130
|
+
Object.assign(this, rawMessage);
|
|
7119
7131
|
this._serviceConfig = serviceConfig;
|
|
7120
7132
|
}
|
|
7121
|
-
async fetchMessageHistory(params) {
|
|
7122
|
-
return useMessagesService(this.serviceConfig).fetchMessageHistory(this.id, params);
|
|
7123
|
-
}
|
|
7124
7133
|
get serviceConfig() {
|
|
7125
7134
|
return this._serviceConfig;
|
|
7126
7135
|
}
|
|
7136
|
+
async markRead() {
|
|
7137
|
+
throw new Error("Method not implemented.");
|
|
7138
|
+
}
|
|
7127
7139
|
};
|
|
7128
|
-
function
|
|
7129
|
-
|
|
7140
|
+
function createMessage(rawMessage, {
|
|
7141
|
+
serviceConfig
|
|
7142
|
+
}) {
|
|
7143
|
+
return new Message(rawMessage, {
|
|
7144
|
+
serviceConfig
|
|
7145
|
+
});
|
|
7130
7146
|
}
|
|
7131
7147
|
|
|
7132
|
-
// src/modules/
|
|
7133
|
-
var
|
|
7148
|
+
// src/modules/messages/api/Messages.api.ts
|
|
7149
|
+
var getMessagesService = ({ axiosInstance }) => {
|
|
7134
7150
|
return {
|
|
7135
|
-
|
|
7151
|
+
getMessageHistory: async (threadId, params = {}) => {
|
|
7152
|
+
const transformedParams = applyTransform(params, [
|
|
7153
|
+
camelToSnake_transformer_default()
|
|
7154
|
+
]);
|
|
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) => {
|
|
7136
7163
|
const transformedParams = applyTransform(params, [
|
|
7137
7164
|
camelToSnake_transformer_default()
|
|
7138
7165
|
]);
|
|
7139
|
-
const response = await axiosInstance.
|
|
7166
|
+
const response = await axiosInstance.post(
|
|
7167
|
+
"/v1/messages/text",
|
|
7168
|
+
transformedParams
|
|
7169
|
+
);
|
|
7140
7170
|
return applyTransform(response.data, [
|
|
7141
7171
|
snakeToCamel_transformer_default()
|
|
7142
7172
|
]);
|
|
@@ -7144,31 +7174,81 @@ var getThreadsService = ({ axiosInstance }) => {
|
|
|
7144
7174
|
};
|
|
7145
7175
|
};
|
|
7146
7176
|
|
|
7147
|
-
// src/modules/
|
|
7148
|
-
var
|
|
7149
|
-
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
|
+
);
|
|
7150
7183
|
return response;
|
|
7151
7184
|
};
|
|
7152
|
-
var
|
|
7153
|
-
|
|
7185
|
+
var instantiateMessages = (rawMessages, {
|
|
7186
|
+
serviceConfig
|
|
7187
|
+
}) => {
|
|
7188
|
+
return rawMessages.map(
|
|
7189
|
+
(rawMessage) => createMessage(rawMessage, {
|
|
7190
|
+
serviceConfig
|
|
7191
|
+
})
|
|
7192
|
+
);
|
|
7154
7193
|
};
|
|
7155
|
-
var
|
|
7156
|
-
const
|
|
7194
|
+
var fetchMessageHistory = async (config3, threadId, params = {}) => {
|
|
7195
|
+
const rawResponse = await fetchRawMessageHistory(config3)(threadId, params);
|
|
7157
7196
|
return {
|
|
7158
|
-
...
|
|
7159
|
-
|
|
7197
|
+
...rawResponse,
|
|
7198
|
+
messages: instantiateMessages(rawResponse.messages ?? [], {
|
|
7160
7199
|
serviceConfig: config3
|
|
7161
7200
|
})
|
|
7162
7201
|
};
|
|
7163
7202
|
};
|
|
7164
7203
|
|
|
7165
|
-
// src/modules/
|
|
7166
|
-
|
|
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) {
|
|
7167
7211
|
return {
|
|
7168
|
-
|
|
7212
|
+
fetchMessageHistory: (threadId, params) => fetchMessageHistory(config3, threadId, params ?? {}),
|
|
7213
|
+
sendTextMessage: (params) => sendTextMessage(config3, params)
|
|
7169
7214
|
};
|
|
7170
7215
|
}
|
|
7171
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
|
+
|
|
7172
7252
|
// src/modules/contacts/api/Contacts.api.ts
|
|
7173
7253
|
var getContactsService = ({ axiosInstance }) => {
|
|
7174
7254
|
return {
|
|
@@ -7176,7 +7256,9 @@ var getContactsService = ({ axiosInstance }) => {
|
|
|
7176
7256
|
const transformedParams = applyTransform(params, [
|
|
7177
7257
|
camelToSnake_transformer_default()
|
|
7178
7258
|
]);
|
|
7179
|
-
const response = await axiosInstance.get("/v1/contacts", {
|
|
7259
|
+
const response = await axiosInstance.get("/v1/contacts", {
|
|
7260
|
+
params: transformedParams
|
|
7261
|
+
});
|
|
7180
7262
|
return applyTransform(response.data, [
|
|
7181
7263
|
snakeToCamel_transformer_default()
|
|
7182
7264
|
]);
|
|
@@ -7184,31 +7266,19 @@ var getContactsService = ({ axiosInstance }) => {
|
|
|
7184
7266
|
};
|
|
7185
7267
|
};
|
|
7186
7268
|
|
|
7187
|
-
// src/modules/contacts/classes/Contact.class.ts
|
|
7188
|
-
var Contact = class {
|
|
7189
|
-
_serviceConfig;
|
|
7190
|
-
constructor(rawContact, { serviceConfig }) {
|
|
7191
|
-
Object.assign(this, rawContact);
|
|
7192
|
-
this._serviceConfig = serviceConfig;
|
|
7193
|
-
}
|
|
7194
|
-
async sendMessage() {
|
|
7195
|
-
throw new Error("Method not implemented.");
|
|
7196
|
-
}
|
|
7197
|
-
get serviceConfig() {
|
|
7198
|
-
return this._serviceConfig;
|
|
7199
|
-
}
|
|
7200
|
-
};
|
|
7201
|
-
function createContact(rawContact, { serviceConfig }) {
|
|
7202
|
-
return new Contact(rawContact, { serviceConfig });
|
|
7203
|
-
}
|
|
7204
|
-
|
|
7205
7269
|
// src/modules/contacts/utils/fetchContacts.ts
|
|
7206
7270
|
var fetchRawContacts = (config3) => async (params = {}) => {
|
|
7207
7271
|
const response = await getContactsService(config3).getContactsList(params);
|
|
7208
7272
|
return response;
|
|
7209
7273
|
};
|
|
7210
|
-
var instantiateContacts = (rawContacts, {
|
|
7211
|
-
|
|
7274
|
+
var instantiateContacts = (rawContacts, {
|
|
7275
|
+
serviceConfig
|
|
7276
|
+
}) => {
|
|
7277
|
+
return rawContacts.map(
|
|
7278
|
+
(rawContact) => createContact(rawContact, {
|
|
7279
|
+
serviceConfig
|
|
7280
|
+
})
|
|
7281
|
+
);
|
|
7212
7282
|
};
|
|
7213
7283
|
var fetchContacts = async (config3, params = {}) => {
|
|
7214
7284
|
const rawResponse = await fetchRawContacts(config3)(params);
|
|
@@ -7226,51 +7296,6 @@ function useContactsService(config3) {
|
|
|
7226
7296
|
fetchContacts: (params) => fetchContacts(config3, params ?? {})
|
|
7227
7297
|
};
|
|
7228
7298
|
}
|
|
7229
|
-
var ServiceConfig = class {
|
|
7230
|
-
baseUrl;
|
|
7231
|
-
accessToken;
|
|
7232
|
-
axiosInstance;
|
|
7233
|
-
constructor({
|
|
7234
|
-
baseUrl,
|
|
7235
|
-
accessToken
|
|
7236
|
-
}) {
|
|
7237
|
-
this.baseUrl = baseUrl;
|
|
7238
|
-
this.accessToken = accessToken;
|
|
7239
|
-
this.axiosInstance = axios.create({
|
|
7240
|
-
baseURL: this.baseUrl
|
|
7241
|
-
});
|
|
7242
|
-
this.setupAxiosTokenHandler();
|
|
7243
|
-
}
|
|
7244
|
-
setupAxiosTokenHandler() {
|
|
7245
|
-
if (typeof this.accessToken === "function") {
|
|
7246
|
-
this.axiosInstance.interceptors.request.use(async (config3) => {
|
|
7247
|
-
config3.headers["X-Webitel-Access"] = await this.accessToken();
|
|
7248
|
-
return config3;
|
|
7249
|
-
});
|
|
7250
|
-
} else {
|
|
7251
|
-
this.axiosInstance.defaults.headers.common["X-Webitel-Access"] = this.accessToken;
|
|
7252
|
-
}
|
|
7253
|
-
}
|
|
7254
|
-
};
|
|
7255
|
-
function createServiceConfig(rawServiceConfig) {
|
|
7256
|
-
return new ServiceConfig(rawServiceConfig);
|
|
7257
|
-
}
|
|
7258
|
-
|
|
7259
|
-
// src/modules/configs/socketConfig/SocketConfig.class.ts
|
|
7260
|
-
var SocketConfig = class {
|
|
7261
|
-
baseUrl;
|
|
7262
|
-
accessToken;
|
|
7263
|
-
constructor({
|
|
7264
|
-
baseUrl,
|
|
7265
|
-
accessToken
|
|
7266
|
-
}) {
|
|
7267
|
-
this.baseUrl = baseUrl;
|
|
7268
|
-
this.accessToken = accessToken;
|
|
7269
|
-
}
|
|
7270
|
-
};
|
|
7271
|
-
function createSocketConfig(rawSocketConfig) {
|
|
7272
|
-
return new SocketConfig(rawSocketConfig);
|
|
7273
|
-
}
|
|
7274
7299
|
|
|
7275
7300
|
// src/modules/socket/enums/ChatsSocketMessage.enum.ts
|
|
7276
7301
|
var ChatsSocketMessage = {
|
|
@@ -7363,6 +7388,91 @@ function createChatsSocketClient(config3) {
|
|
|
7363
7388
|
return new ChatsSocketClient(config3);
|
|
7364
7389
|
}
|
|
7365
7390
|
|
|
7366
|
-
|
|
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 };
|
|
7367
7477
|
//# sourceMappingURL=index.js.map
|
|
7368
7478
|
//# sourceMappingURL=index.js.map
|