@go-avro/avro-js 0.0.2-beta.15 → 0.0.2-beta.151
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 +1 -0
- package/dist/auth/AuthManager.d.ts +14 -5
- package/dist/auth/AuthManager.js +59 -23
- package/dist/auth/storage.d.ts +8 -8
- package/dist/auth/storage.js +19 -14
- package/dist/client/AvroQueryClientProvider.d.ts +14 -0
- package/dist/client/AvroQueryClientProvider.js +32 -0
- package/dist/client/QueryClient.d.ts +492 -16
- package/dist/client/QueryClient.js +396 -214
- package/dist/client/core/fetch.d.ts +1 -0
- package/dist/client/core/fetch.js +64 -0
- package/dist/client/core/utils.d.ts +1 -0
- package/dist/client/core/utils.js +14 -0
- package/dist/client/core/xhr.d.ts +1 -0
- package/dist/client/core/xhr.js +90 -0
- package/dist/client/hooks/analytics.d.ts +1 -0
- package/dist/client/hooks/analytics.js +26 -0
- package/dist/client/hooks/avro.d.ts +1 -0
- package/dist/client/hooks/avro.js +9 -0
- package/dist/client/hooks/bills.d.ts +1 -0
- package/dist/client/hooks/bills.js +165 -0
- package/dist/client/hooks/chats.d.ts +1 -0
- package/dist/client/hooks/chats.js +37 -0
- package/dist/client/hooks/companies.d.ts +1 -0
- package/dist/client/hooks/companies.js +152 -0
- package/dist/client/hooks/events.d.ts +1 -0
- package/dist/client/hooks/events.js +308 -0
- package/dist/client/hooks/groups.d.ts +1 -0
- package/dist/client/hooks/groups.js +130 -0
- package/dist/client/hooks/jobs.d.ts +1 -0
- package/dist/client/hooks/jobs.js +213 -0
- package/dist/client/hooks/labels.d.ts +1 -0
- package/dist/client/hooks/labels.js +130 -0
- package/dist/client/hooks/messages.d.ts +1 -0
- package/dist/client/hooks/messages.js +30 -0
- package/dist/client/hooks/months.d.ts +1 -0
- package/dist/client/hooks/months.js +93 -0
- package/dist/client/hooks/plans.d.ts +1 -0
- package/dist/client/hooks/plans.js +8 -0
- package/dist/client/hooks/proposal.d.ts +1 -0
- package/dist/client/hooks/proposal.js +22 -0
- package/dist/client/hooks/root.d.ts +1 -0
- package/dist/client/hooks/root.js +8 -0
- package/dist/client/hooks/routes.d.ts +1 -0
- package/dist/client/hooks/routes.js +167 -0
- package/dist/client/hooks/sessions.d.ts +1 -0
- package/dist/client/hooks/sessions.js +175 -0
- package/dist/client/hooks/skills.d.ts +1 -0
- package/dist/client/hooks/skills.js +123 -0
- package/dist/client/hooks/teams.d.ts +1 -0
- package/dist/client/hooks/teams.js +128 -0
- package/dist/client/hooks/users.d.ts +1 -0
- package/dist/client/hooks/users.js +118 -0
- package/dist/index.d.ts +26 -1
- package/dist/index.js +26 -1
- package/dist/types/api.d.ts +146 -38
- package/dist/types/api.js +10 -1
- package/dist/types/auth.d.ts +6 -5
- package/dist/types/auth.js +5 -1
- package/dist/types/cache.d.ts +9 -0
- package/dist/types/cache.js +1 -0
- package/package.json +6 -4
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
import io from 'socket.io-client';
|
|
2
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { LoginResponse } from '../types/api';
|
|
4
|
+
import { AuthState } from '../types/auth';
|
|
1
5
|
import { StandardError } from '../types/error';
|
|
2
6
|
export class AvroQueryClient {
|
|
3
7
|
constructor(config) {
|
|
8
|
+
this._authState = AuthState.UNKNOWN;
|
|
9
|
+
this.companyId = null;
|
|
10
|
+
this.company = null;
|
|
11
|
+
this.authStateListeners = [];
|
|
4
12
|
this.config = {
|
|
5
13
|
baseUrl: config.baseUrl,
|
|
6
14
|
authManager: config.authManager,
|
|
@@ -8,234 +16,293 @@ export class AvroQueryClient {
|
|
|
8
16
|
retryStrategy: config.retryStrategy ?? 'fixed',
|
|
9
17
|
timeout: config.timeout ?? 0,
|
|
10
18
|
};
|
|
19
|
+
this.socket = io(config.baseUrl, { autoConnect: false, transports: ["websocket"], });
|
|
20
|
+
config.authManager.isAuthenticated().then(isAuth => {
|
|
21
|
+
this.setAuthState(isAuth);
|
|
22
|
+
this.getCompanyId().then(id => {
|
|
23
|
+
this.companyId = id;
|
|
24
|
+
});
|
|
25
|
+
if (!this.socket.connected && isAuth === AuthState.AUTHENTICATED) {
|
|
26
|
+
this.config.authManager.accessToken().then(token => {
|
|
27
|
+
console.log('Initializing socket connection with token:', token);
|
|
28
|
+
this.socket.auth = { token: token };
|
|
29
|
+
this.socket.connect();
|
|
30
|
+
}).catch(err => {
|
|
31
|
+
console.error('Not logged in:', err);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
this.socket.on('connect', () => {
|
|
36
|
+
this.setAuthState(AuthState.AUTHENTICATED);
|
|
37
|
+
console.log(`Socket connected with ID: ${this.socket?.id}`);
|
|
38
|
+
});
|
|
39
|
+
this.socket.on('disconnect', (reason) => {
|
|
40
|
+
console.log(`Socket disconnected: ${reason}`);
|
|
41
|
+
});
|
|
42
|
+
this.socket.on('connect_error', (err) => {
|
|
43
|
+
console.error(`Socket connection error: ${err.message}`);
|
|
44
|
+
});
|
|
45
|
+
this.config.authManager.onTokenRefreshed((newAccessToken) => {
|
|
46
|
+
if (this.socket && newAccessToken) {
|
|
47
|
+
this.setAuthState(AuthState.AUTHENTICATED);
|
|
48
|
+
console.log('Access token refreshed, updating socket auth...');
|
|
49
|
+
this.socket.auth = { token: newAccessToken };
|
|
50
|
+
this.socket.disconnect().connect();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
config.authManager.onTokenRefreshFailed(() => {
|
|
54
|
+
this.setAuthState(AuthState.UNAUTHENTICATED);
|
|
55
|
+
if (this.socket && this.socket.connected) {
|
|
56
|
+
this.socket.disconnect();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
11
59
|
}
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
else if (strategy === 'fixed') {
|
|
17
|
-
return 1000;
|
|
60
|
+
emit(eventName, data) {
|
|
61
|
+
if (!this.socket?.connected) {
|
|
62
|
+
console.error('Socket is not connected. Cannot emit event.');
|
|
63
|
+
return;
|
|
18
64
|
}
|
|
19
|
-
|
|
20
|
-
return Math.pow(2, attempt) * 100;
|
|
21
|
-
}
|
|
22
|
-
throw new Error(`Invalid retry strategy: ${strategy}`);
|
|
65
|
+
this.socket.emit(eventName, data);
|
|
23
66
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return this.config.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.config.authManager
|
|
51
|
-
.refreshTokens()
|
|
52
|
-
.then(() => {
|
|
53
|
-
this._xhr(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1).then(resolve, reject);
|
|
54
|
-
})
|
|
55
|
-
.catch(() => {
|
|
56
|
-
reject(new StandardError(401, 'Unauthorized (refresh failed)'));
|
|
57
|
-
});
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (xhr.status >= 200 && xhr.status < 300) {
|
|
61
|
-
try {
|
|
62
|
-
resolve(JSON.parse(xhr.responseText));
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
resolve(xhr.responseText);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
if (retryCount < this.config.maxRetries) {
|
|
70
|
-
const delay = this.getDelay(this.config.retryStrategy, retryCount);
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
this._xhr(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1).then(resolve, reject);
|
|
73
|
-
}, delay);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
let msg = xhr.statusText;
|
|
77
|
-
try {
|
|
78
|
-
const parsed = JSON.parse(xhr.responseText);
|
|
79
|
-
msg = parsed.message || msg;
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
console.warn('Failed to parse error response:', xhr.responseText);
|
|
83
|
-
}
|
|
84
|
-
reject(new StandardError(xhr.status, msg));
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
xhr.onerror = () => {
|
|
89
|
-
if (retryCount < this.config.maxRetries) {
|
|
90
|
-
const delay = this.getDelay(this.config.retryStrategy, retryCount);
|
|
91
|
-
setTimeout(() => {
|
|
92
|
-
this._xhr(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1).then(resolve, reject);
|
|
93
|
-
}, delay);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
reject(new StandardError(0, 'Network Error'));
|
|
67
|
+
on(eventName, callback) {
|
|
68
|
+
this.socket?.on(eventName, callback);
|
|
69
|
+
}
|
|
70
|
+
off(eventName, callback) {
|
|
71
|
+
this.socket?.off(eventName, callback);
|
|
72
|
+
}
|
|
73
|
+
get(path, cancelToken, headers = {}, progressUpdateCallback) {
|
|
74
|
+
return this._xhr('GET', path, null, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
75
|
+
}
|
|
76
|
+
post(path, data, cancelToken, headers = {}, progressUpdateCallback) {
|
|
77
|
+
return this._xhr('POST', path, data, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
78
|
+
}
|
|
79
|
+
put(path, data, cancelToken, headers = {}, progressUpdateCallback) {
|
|
80
|
+
return this._xhr('PUT', path, data, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
81
|
+
}
|
|
82
|
+
delete(path, cancelToken, headers = {}, progressUpdateCallback) {
|
|
83
|
+
return this._xhr('DELETE', path, null, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
84
|
+
}
|
|
85
|
+
useLogin() {
|
|
86
|
+
const queryClient = this.getQueryClient();
|
|
87
|
+
return useMutation({
|
|
88
|
+
mutationFn: async ({ username, password, code, cancelToken }) => {
|
|
89
|
+
const resp = await this.post('/login', JSON.stringify({ username, password, code }), cancelToken, { 'Content-Type': 'application/json' });
|
|
90
|
+
if (!resp || !('access_token' in resp)) {
|
|
91
|
+
if (resp.msg === "TOTP required") {
|
|
92
|
+
return LoginResponse.NEEDS_TOTP;
|
|
97
93
|
}
|
|
98
|
-
|
|
99
|
-
if (this.config.timeout) {
|
|
100
|
-
xhr.timeout = this.config.timeout;
|
|
101
|
-
xhr.ontimeout = () => reject(new StandardError(0, 'Request timed out'));
|
|
94
|
+
throw new StandardError(401, 'Invalid login response');
|
|
102
95
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
_fetch(method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount = 0) {
|
|
108
|
-
const checkCancelled = () => {
|
|
109
|
-
try {
|
|
110
|
-
if (cancelToken?.isCancelled()) {
|
|
111
|
-
return new StandardError(0, 'Request cancelled');
|
|
96
|
+
this.setAuthState(AuthState.AUTHENTICATED);
|
|
97
|
+
this.socket.auth = { token: resp.access_token };
|
|
98
|
+
if (!this.socket.connected) {
|
|
99
|
+
this.socket.connect();
|
|
112
100
|
}
|
|
101
|
+
await this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token });
|
|
102
|
+
return LoginResponse.SUCCESS;
|
|
103
|
+
},
|
|
104
|
+
onSettled: () => {
|
|
105
|
+
queryClient.invalidateQueries();
|
|
106
|
+
},
|
|
107
|
+
onError: (err) => {
|
|
108
|
+
this.config.authManager.clearCache();
|
|
109
|
+
throw new StandardError(401, err.message || 'Login failed');
|
|
113
110
|
}
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
useRequestCode() {
|
|
114
|
+
const queryClient = this.getQueryClient();
|
|
115
|
+
return useMutation({
|
|
116
|
+
mutationFn: async ({ username, email, cancelToken }) => {
|
|
117
|
+
const resp = await this.post('/code', JSON.stringify({ username, email }), cancelToken, { 'Content-Type': 'application/json' });
|
|
118
|
+
return resp;
|
|
119
|
+
},
|
|
120
|
+
onSettled: () => {
|
|
121
|
+
queryClient.invalidateQueries();
|
|
122
|
+
},
|
|
123
|
+
onError: (err) => {
|
|
124
|
+
throw new StandardError(err.status, err.message || 'Request code failed');
|
|
116
125
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
useUpdatePassword() {
|
|
129
|
+
const queryClient = this.getQueryClient();
|
|
130
|
+
return useMutation({
|
|
131
|
+
mutationFn: async ({ username, email, code, newPassword, cancelToken }) => {
|
|
132
|
+
await this.post(`/user/${username ?? email}/password`, JSON.stringify({ code, password: newPassword }), cancelToken, { 'Content-Type': 'application/json' });
|
|
133
|
+
},
|
|
134
|
+
onSettled: () => {
|
|
135
|
+
queryClient.invalidateQueries();
|
|
136
|
+
},
|
|
137
|
+
onError: (err) => {
|
|
138
|
+
throw new StandardError(err.status, err.message || 'Update password failed');
|
|
130
139
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.catch(() => Promise.reject(new StandardError(401, 'Unauthorized (refresh failed)')));
|
|
142
|
-
}
|
|
143
|
-
if (!response.ok) {
|
|
144
|
-
if (retryCount < this.config.maxRetries) {
|
|
145
|
-
const delay = this.getDelay(this.config.retryStrategy, retryCount);
|
|
146
|
-
return new Promise((resolve, reject) => {
|
|
147
|
-
setTimeout(() => {
|
|
148
|
-
this._fetch(method, path, body, cancelToken, headers, isIdempotent, retryCount + 1)
|
|
149
|
-
.then(resolve)
|
|
150
|
-
.catch(reject);
|
|
151
|
-
}, delay);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
return response.text().then(text => {
|
|
156
|
-
let msg = response.statusText;
|
|
157
|
-
try {
|
|
158
|
-
const parsed = JSON.parse(text);
|
|
159
|
-
msg = parsed.message || msg;
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
console.warn('Failed to parse error response:', text);
|
|
163
|
-
}
|
|
164
|
-
throw new StandardError(response.status, msg);
|
|
165
|
-
});
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
useGoogleLogin() {
|
|
143
|
+
const queryClient = this.getQueryClient();
|
|
144
|
+
return useMutation({
|
|
145
|
+
mutationFn: async ({ token, cancelToken }) => {
|
|
146
|
+
const resp = await this._xhr('POST', `/google/authorize?token=${token}`, {}, cancelToken, { 'Content-Type': 'application/json' });
|
|
147
|
+
if (!resp || !('access_token' in resp)) {
|
|
148
|
+
if (resp.msg === "TOTP required") {
|
|
149
|
+
return LoginResponse.NEEDS_TOTP;
|
|
166
150
|
}
|
|
151
|
+
throw new StandardError(401, 'Invalid Google login response');
|
|
167
152
|
}
|
|
168
|
-
|
|
169
|
-
|
|
153
|
+
this.setAuthState(AuthState.AUTHENTICATED);
|
|
154
|
+
this.socket.auth = { token: resp.access_token };
|
|
155
|
+
if (!this.socket.connected) {
|
|
156
|
+
this.socket.connect();
|
|
157
|
+
}
|
|
158
|
+
await this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token });
|
|
159
|
+
return LoginResponse.SUCCESS;
|
|
160
|
+
},
|
|
161
|
+
onSettled: () => {
|
|
162
|
+
queryClient.invalidateQueries();
|
|
163
|
+
},
|
|
164
|
+
onError: (err) => {
|
|
165
|
+
this.config.authManager.clearCache();
|
|
166
|
+
throw new StandardError(err.status, err.message || 'Google Login failed');
|
|
167
|
+
}
|
|
170
168
|
});
|
|
171
169
|
}
|
|
172
|
-
|
|
173
|
-
return this.
|
|
170
|
+
setTokens(tokens) {
|
|
171
|
+
return this.config.authManager.setTokens(tokens);
|
|
172
|
+
}
|
|
173
|
+
setCache(data) {
|
|
174
|
+
return this.config.authManager.setCache(data);
|
|
175
|
+
}
|
|
176
|
+
getCache(key) {
|
|
177
|
+
return this.config.authManager.getCache(key);
|
|
178
|
+
}
|
|
179
|
+
setCompanyId(companyId) {
|
|
180
|
+
this.companyId = companyId;
|
|
181
|
+
return this.config.authManager.setCompanyId(companyId);
|
|
182
|
+
}
|
|
183
|
+
getCompanyId() {
|
|
184
|
+
if (this.companyId) {
|
|
185
|
+
return Promise.resolve(this.companyId);
|
|
186
|
+
}
|
|
187
|
+
return this.config.authManager.getCompanyId();
|
|
188
|
+
}
|
|
189
|
+
clearCache() {
|
|
190
|
+
return this.config.authManager.clearCache();
|
|
191
|
+
}
|
|
192
|
+
onAuthStateChange(cb) {
|
|
193
|
+
this.authStateListeners.push(cb);
|
|
194
|
+
// call immediately with current value
|
|
195
|
+
try {
|
|
196
|
+
cb(this._authState);
|
|
197
|
+
}
|
|
198
|
+
catch (_) {
|
|
199
|
+
console.error(_);
|
|
200
|
+
}
|
|
201
|
+
return () => this.offAuthStateChange(cb);
|
|
202
|
+
}
|
|
203
|
+
offAuthStateChange(cb) {
|
|
204
|
+
this.authStateListeners = this.authStateListeners.filter(c => c !== cb);
|
|
205
|
+
}
|
|
206
|
+
setAuthState(state) {
|
|
207
|
+
this.authStateListeners.forEach(cb => cb(state));
|
|
208
|
+
this._authState = state;
|
|
209
|
+
}
|
|
210
|
+
getAuthState() {
|
|
211
|
+
return this._authState;
|
|
174
212
|
}
|
|
175
|
-
|
|
176
|
-
return this.
|
|
213
|
+
getAuthStateAsync() {
|
|
214
|
+
return this.config.authManager.isAuthenticated();
|
|
177
215
|
}
|
|
178
|
-
|
|
179
|
-
return
|
|
216
|
+
getQueryClient() {
|
|
217
|
+
return useQueryClient();
|
|
180
218
|
}
|
|
181
|
-
|
|
182
|
-
|
|
219
|
+
useLogout() {
|
|
220
|
+
const queryClient = this.getQueryClient();
|
|
221
|
+
return useMutation({
|
|
222
|
+
mutationFn: async (cancelToken) => {
|
|
223
|
+
await this.post('/logout', null, cancelToken);
|
|
224
|
+
await this.config.authManager.clearCache();
|
|
225
|
+
if (this.socket && this.socket.connected) {
|
|
226
|
+
this.socket.disconnect();
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
onSettled: () => {
|
|
230
|
+
this.clearCache();
|
|
231
|
+
this.setAuthState(AuthState.UNAUTHENTICATED);
|
|
232
|
+
queryClient.removeQueries();
|
|
233
|
+
},
|
|
234
|
+
onError: (err) => {
|
|
235
|
+
this.clearCache();
|
|
236
|
+
console.error('Logout failed:', err);
|
|
237
|
+
throw new StandardError(500, 'Logout failed');
|
|
238
|
+
}
|
|
239
|
+
});
|
|
183
240
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
241
|
+
fetchJobs(body = {}, cancelToken, headers = {}) {
|
|
242
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
243
|
+
throw new StandardError(400, 'Company ID is required');
|
|
244
|
+
}
|
|
245
|
+
return this._fetch('POST', `/company/${this.companyId}/jobs`, JSON.stringify(body), cancelToken, {
|
|
246
|
+
...headers,
|
|
247
|
+
'Content-Type': 'application/json',
|
|
248
|
+
})
|
|
249
|
+
.then(response => {
|
|
250
|
+
if (!response || !Array.isArray(response)) {
|
|
251
|
+
throw new StandardError(400, 'Invalid jobs response');
|
|
189
252
|
}
|
|
190
|
-
return
|
|
253
|
+
return response;
|
|
191
254
|
})
|
|
192
255
|
.catch(err => {
|
|
193
|
-
console.error('
|
|
194
|
-
throw new StandardError(
|
|
256
|
+
console.error('Failed to fetch jobs:', err);
|
|
257
|
+
throw new StandardError(500, `Failed to fetch jobs: ${err.message ?? err}`);
|
|
195
258
|
});
|
|
196
259
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
260
|
+
fetchChats(body = {}, cancelToken, headers = {}) {
|
|
261
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
262
|
+
throw new StandardError(400, 'Company ID is required');
|
|
263
|
+
}
|
|
264
|
+
return this._fetch('POST', `/company/${this.companyId}/chats`, JSON.stringify(body), cancelToken, {
|
|
265
|
+
...headers,
|
|
266
|
+
'Content-Type': 'application/json',
|
|
267
|
+
})
|
|
268
|
+
.then(response => {
|
|
269
|
+
if (!response || !Array.isArray(response)) {
|
|
270
|
+
throw new StandardError(400, 'Invalid chats response');
|
|
271
|
+
}
|
|
272
|
+
return response;
|
|
273
|
+
})
|
|
200
274
|
.catch(err => {
|
|
201
|
-
console.error('
|
|
202
|
-
throw new StandardError(500, '
|
|
275
|
+
console.error('Failed to fetch chats:', err);
|
|
276
|
+
throw new StandardError(500, 'Failed to fetch chats');
|
|
203
277
|
});
|
|
204
278
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
known_ids: knownIds,
|
|
209
|
-
unknown_ids: unknownIds,
|
|
210
|
-
query: keyword,
|
|
211
|
-
};
|
|
212
|
-
if (!companyGuid) {
|
|
213
|
-
return Promise.reject(new StandardError(400, 'Company GUID is required'));
|
|
279
|
+
fetchMessages(chatId, body = {}, cancelToken, headers = {}) {
|
|
280
|
+
if (!chatId || chatId.trim() === '') {
|
|
281
|
+
throw new StandardError(400, 'Chat ID is required');
|
|
214
282
|
}
|
|
215
|
-
return this._fetch('POST', `/
|
|
283
|
+
return this._fetch('POST', `/chat/${chatId}/messages`, JSON.stringify(body), cancelToken, {
|
|
284
|
+
...headers,
|
|
285
|
+
'Content-Type': 'application/json',
|
|
286
|
+
})
|
|
216
287
|
.then(response => {
|
|
217
288
|
if (!response || !Array.isArray(response)) {
|
|
218
|
-
throw new StandardError(400, 'Invalid
|
|
289
|
+
throw new StandardError(400, 'Invalid messages response');
|
|
219
290
|
}
|
|
220
291
|
return response;
|
|
221
292
|
})
|
|
222
293
|
.catch(err => {
|
|
223
|
-
console.error('Failed to fetch
|
|
224
|
-
throw new StandardError(500, 'Failed to fetch
|
|
294
|
+
console.error('Failed to fetch messages:', err);
|
|
295
|
+
throw new StandardError(500, 'Failed to fetch messages');
|
|
225
296
|
});
|
|
226
297
|
}
|
|
227
|
-
fetchEvents(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
known_ids: knownIds,
|
|
231
|
-
unknown_ids: unknownIds,
|
|
232
|
-
query: keyword,
|
|
233
|
-
job_id: jobId,
|
|
234
|
-
};
|
|
235
|
-
if (!companyGuid) {
|
|
236
|
-
return Promise.reject(new StandardError(400, 'Company GUID is required'));
|
|
298
|
+
async fetchEvents(body = {}, cancelToken, headers = {}) {
|
|
299
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
300
|
+
throw new StandardError(400, 'Company ID is required');
|
|
237
301
|
}
|
|
238
|
-
return this._fetch('POST', `/company/${
|
|
302
|
+
return this._fetch('POST', `/company/${this.companyId}/events`, JSON.stringify(body), cancelToken, {
|
|
303
|
+
...headers,
|
|
304
|
+
'Content-Type': 'application/json',
|
|
305
|
+
})
|
|
239
306
|
.then(response => {
|
|
240
307
|
if (!response || !Array.isArray(response)) {
|
|
241
308
|
throw new StandardError(400, 'Invalid events response');
|
|
@@ -247,18 +314,14 @@ export class AvroQueryClient {
|
|
|
247
314
|
throw new StandardError(500, 'Failed to fetch events');
|
|
248
315
|
});
|
|
249
316
|
}
|
|
250
|
-
fetchMonths(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
known_ids: knownIds,
|
|
254
|
-
unknown_ids: unknownIds,
|
|
255
|
-
query: keyword,
|
|
256
|
-
job_id: jobId,
|
|
257
|
-
};
|
|
258
|
-
if (!companyGuid) {
|
|
259
|
-
return Promise.reject(new StandardError(400, 'Company GUID is required'));
|
|
317
|
+
fetchMonths(body = {}, cancelToken, headers = {}) {
|
|
318
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
319
|
+
throw new StandardError(400, 'Company ID is required');
|
|
260
320
|
}
|
|
261
|
-
return this._fetch('POST', `/company/${
|
|
321
|
+
return this._fetch('POST', `/company/${this.companyId}/months`, JSON.stringify(body), cancelToken, {
|
|
322
|
+
...headers,
|
|
323
|
+
'Content-Type': 'application/json',
|
|
324
|
+
})
|
|
262
325
|
.then(response => {
|
|
263
326
|
if (!response || !Array.isArray(response)) {
|
|
264
327
|
throw new StandardError(400, 'Invalid months response');
|
|
@@ -270,17 +333,14 @@ export class AvroQueryClient {
|
|
|
270
333
|
throw new StandardError(500, 'Failed to fetch months');
|
|
271
334
|
});
|
|
272
335
|
}
|
|
273
|
-
fetchBills(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
known_ids: knownIds,
|
|
277
|
-
unknown_ids: unknownIds,
|
|
278
|
-
query: keyword,
|
|
279
|
-
};
|
|
280
|
-
if (!companyGuid) {
|
|
281
|
-
return Promise.reject(new StandardError(400, 'Company GUID is required'));
|
|
336
|
+
fetchBills(body = {}, cancelToken, headers = {}) {
|
|
337
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
338
|
+
throw new StandardError(400, 'Company ID is required');
|
|
282
339
|
}
|
|
283
|
-
return this._fetch('POST', `/company/${
|
|
340
|
+
return this._fetch('POST', `/company/${this.companyId}/bills`, JSON.stringify(body), cancelToken, {
|
|
341
|
+
...headers,
|
|
342
|
+
'Content-Type': 'application/json',
|
|
343
|
+
})
|
|
284
344
|
.then(response => {
|
|
285
345
|
if (!response || !Array.isArray(response)) {
|
|
286
346
|
throw new StandardError(400, 'Invalid bills response');
|
|
@@ -292,4 +352,126 @@ export class AvroQueryClient {
|
|
|
292
352
|
throw new StandardError(500, 'Failed to fetch bills');
|
|
293
353
|
});
|
|
294
354
|
}
|
|
355
|
+
fetchRoutes(body = {}, cancelToken, headers = {}) {
|
|
356
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
357
|
+
throw new StandardError(400, 'Company ID is required');
|
|
358
|
+
}
|
|
359
|
+
return this._fetch('POST', `/company/${this.companyId}/routes`, JSON.stringify(body), cancelToken, {
|
|
360
|
+
...headers,
|
|
361
|
+
'Content-Type': 'application/json',
|
|
362
|
+
})
|
|
363
|
+
.then(response => {
|
|
364
|
+
if (!response || !Array.isArray(response)) {
|
|
365
|
+
throw new StandardError(400, 'Invalid routes response');
|
|
366
|
+
}
|
|
367
|
+
return response;
|
|
368
|
+
})
|
|
369
|
+
.catch(err => {
|
|
370
|
+
console.error('Failed to fetch routes:', err);
|
|
371
|
+
throw new StandardError(500, 'Failed to fetch routes');
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
fetchTeams(body = {}, cancelToken, headers = {}) {
|
|
375
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
376
|
+
throw new StandardError(400, 'Company ID is required');
|
|
377
|
+
}
|
|
378
|
+
return this._fetch('POST', `/company/${this.companyId}/teams`, JSON.stringify(body), cancelToken, {
|
|
379
|
+
...headers,
|
|
380
|
+
'Content-Type': 'application/json',
|
|
381
|
+
})
|
|
382
|
+
.then(response => {
|
|
383
|
+
if (!response || !Array.isArray(response)) {
|
|
384
|
+
throw new StandardError(400, 'Invalid teams response');
|
|
385
|
+
}
|
|
386
|
+
return response;
|
|
387
|
+
})
|
|
388
|
+
.catch(err => {
|
|
389
|
+
console.error('Failed to fetch teams:', err);
|
|
390
|
+
throw new StandardError(500, 'Failed to fetch teams');
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
fetchLabels(body = {}, cancelToken, headers = {}) {
|
|
394
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
395
|
+
throw new StandardError(400, 'Company ID is required');
|
|
396
|
+
}
|
|
397
|
+
return this._fetch('POST', `/company/${this.companyId}/labels`, JSON.stringify(body), cancelToken, {
|
|
398
|
+
...headers,
|
|
399
|
+
'Content-Type': 'application/json',
|
|
400
|
+
})
|
|
401
|
+
.then(response => {
|
|
402
|
+
if (!response || !Array.isArray(response)) {
|
|
403
|
+
throw new StandardError(400, 'Invalid labels response');
|
|
404
|
+
}
|
|
405
|
+
return response;
|
|
406
|
+
})
|
|
407
|
+
.catch(err => {
|
|
408
|
+
console.error('Failed to fetch labels:', err);
|
|
409
|
+
throw new StandardError(500, 'Failed to fetch labels');
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
fetchGroups(body = {}, cancelToken, headers = {}) {
|
|
413
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
414
|
+
throw new StandardError(400, 'Company ID is required');
|
|
415
|
+
}
|
|
416
|
+
return this._fetch('POST', `/company/${this.companyId}/groups`, JSON.stringify(body), cancelToken, {
|
|
417
|
+
...headers,
|
|
418
|
+
'Content-Type': 'application/json',
|
|
419
|
+
})
|
|
420
|
+
.then(response => {
|
|
421
|
+
if (!response || !Array.isArray(response)) {
|
|
422
|
+
throw new StandardError(400, 'Invalid groups response');
|
|
423
|
+
}
|
|
424
|
+
return response;
|
|
425
|
+
})
|
|
426
|
+
.catch(err => {
|
|
427
|
+
console.error('Failed to fetch groups:', err);
|
|
428
|
+
throw new StandardError(500, 'Failed to fetch groups');
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
fetchSkills(body = {}, cancelToken, headers = {}) {
|
|
432
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
433
|
+
throw new StandardError(400, 'Company ID is required');
|
|
434
|
+
}
|
|
435
|
+
return this._fetch('POST', `/company/${this.companyId}/skills`, JSON.stringify(body), cancelToken, {
|
|
436
|
+
...headers,
|
|
437
|
+
'Content-Type': 'application/json',
|
|
438
|
+
})
|
|
439
|
+
.then(response => {
|
|
440
|
+
if (!response || !Array.isArray(response)) {
|
|
441
|
+
throw new StandardError(400, 'Invalid skills response');
|
|
442
|
+
}
|
|
443
|
+
return response;
|
|
444
|
+
})
|
|
445
|
+
.catch(err => {
|
|
446
|
+
console.error('Failed to fetch skills:', err);
|
|
447
|
+
throw new StandardError(500, 'Failed to fetch skills');
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
fetchSessions(body = {}, cancelToken, headers = {}) {
|
|
451
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
452
|
+
throw new StandardError(400, 'Company ID is required');
|
|
453
|
+
}
|
|
454
|
+
return this._fetch('POST', `/company/${this.companyId}/sessions`, JSON.stringify(body), cancelToken, {
|
|
455
|
+
...headers,
|
|
456
|
+
'Content-Type': 'application/json',
|
|
457
|
+
})
|
|
458
|
+
.then(response => {
|
|
459
|
+
if (!response || !Array.isArray(response)) {
|
|
460
|
+
throw new StandardError(400, 'Invalid sessions response');
|
|
461
|
+
}
|
|
462
|
+
return response;
|
|
463
|
+
})
|
|
464
|
+
.catch(err => {
|
|
465
|
+
console.error('Failed to fetch sessions:', err);
|
|
466
|
+
throw new StandardError(500, 'Failed to fetch sessions');
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
sendEmail(emailId, formData, progressUpdateCallback) {
|
|
470
|
+
try {
|
|
471
|
+
return this.post(`/email/${emailId}`, formData, undefined, {}, progressUpdateCallback);
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
throw new StandardError(500, `Failed to send email: ${error}`);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
295
477
|
}
|