@go-avro/avro-js 0.0.2-beta.13 → 0.0.2-beta.131
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 +12 -3
- package/dist/auth/AuthManager.js +56 -12
- package/dist/auth/storage.d.ts +8 -8
- package/dist/auth/storage.js +12 -10
- package/dist/client/QueryClient.d.ts +409 -15
- package/dist/client/QueryClient.js +343 -203
- package/dist/client/core/fetch.d.ts +1 -0
- package/dist/client/core/fetch.js +62 -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 +84 -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 +137 -0
- package/dist/client/hooks/events.d.ts +1 -0
- package/dist/client/hooks/events.js +308 -0
- package/dist/client/hooks/jobs.d.ts +1 -0
- package/dist/client/hooks/jobs.js +215 -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/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 +104 -0
- package/dist/index.d.ts +22 -1
- package/dist/index.js +22 -1
- package/dist/types/api.d.ts +124 -32
- package/dist/types/api.js +10 -1
- package/dist/types/auth.d.ts +0 -5
- package/dist/types/cache.d.ts +9 -0
- package/dist/types/cache.js +1 -0
- package/package.json +6 -4
|
@@ -1,241 +1,281 @@
|
|
|
1
|
+
import io from 'socket.io-client';
|
|
2
|
+
import { useMutation } from '@tanstack/react-query';
|
|
3
|
+
import { LoginResponse } from '../types/api';
|
|
1
4
|
import { StandardError } from '../types/error';
|
|
2
5
|
export class AvroQueryClient {
|
|
3
6
|
constructor(config) {
|
|
7
|
+
this._isAuthenticated = false;
|
|
8
|
+
this.companyId = null;
|
|
9
|
+
this.company = null;
|
|
4
10
|
this.config = {
|
|
5
11
|
baseUrl: config.baseUrl,
|
|
6
12
|
authManager: config.authManager,
|
|
13
|
+
queryClient: config.queryClient,
|
|
7
14
|
maxRetries: config.maxRetries ?? 3,
|
|
8
15
|
retryStrategy: config.retryStrategy ?? 'fixed',
|
|
9
16
|
timeout: config.timeout ?? 0,
|
|
10
17
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
config.authManager.isAuthenticated().then(isAuth => {
|
|
19
|
+
this._isAuthenticated = isAuth;
|
|
20
|
+
});
|
|
21
|
+
config.authManager.getCompanyId().then(companyId => {
|
|
22
|
+
this.companyId = companyId;
|
|
23
|
+
});
|
|
24
|
+
this.socket = io(config.baseUrl, { autoConnect: false, transports: ["websocket"], });
|
|
25
|
+
if (!this.socket.connected) {
|
|
26
|
+
this.config.authManager.accessToken().then(token => {
|
|
27
|
+
console.log('Initializing socket connection with token...');
|
|
28
|
+
this.socket.auth = { token: token };
|
|
29
|
+
this.socket.connect();
|
|
30
|
+
});
|
|
18
31
|
}
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
this.socket.on('connect', () => {
|
|
33
|
+
this._isAuthenticated = true;
|
|
34
|
+
console.log(`Socket connected with ID: ${this.socket?.id}`);
|
|
35
|
+
});
|
|
36
|
+
this.socket.on('disconnect', (reason) => {
|
|
37
|
+
console.log(`Socket disconnected: ${reason}`);
|
|
38
|
+
});
|
|
39
|
+
this.socket.on('connect_error', (err) => {
|
|
40
|
+
console.error(`Socket connection error: ${err.message}`);
|
|
41
|
+
});
|
|
42
|
+
this.config.authManager.onTokenRefreshed((newAccessToken) => {
|
|
43
|
+
if (this.socket && newAccessToken) {
|
|
44
|
+
this._isAuthenticated = true;
|
|
45
|
+
console.log('Access token refreshed, updating socket auth...');
|
|
46
|
+
this.socket.auth = { token: newAccessToken };
|
|
47
|
+
this.socket.disconnect().connect();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
config.authManager.onTokenRefreshFailed(() => {
|
|
51
|
+
this._isAuthenticated = false;
|
|
52
|
+
if (this.socket && this.socket.connected) {
|
|
53
|
+
this.socket.disconnect();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
emit(eventName, data) {
|
|
58
|
+
if (!this.socket?.connected) {
|
|
59
|
+
console.error('Socket is not connected. Cannot emit event.');
|
|
60
|
+
return;
|
|
21
61
|
}
|
|
22
|
-
|
|
62
|
+
this.socket.emit(eventName, data);
|
|
23
63
|
}
|
|
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'));
|
|
64
|
+
on(eventName, callback) {
|
|
65
|
+
this.socket?.on(eventName, callback);
|
|
66
|
+
}
|
|
67
|
+
off(eventName, callback) {
|
|
68
|
+
this.socket?.off(eventName, callback);
|
|
69
|
+
}
|
|
70
|
+
get(path, cancelToken, headers = {}, progressUpdateCallback) {
|
|
71
|
+
return this._xhr('GET', path, null, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
72
|
+
}
|
|
73
|
+
post(path, data, cancelToken, headers = {}, progressUpdateCallback) {
|
|
74
|
+
return this._xhr('POST', path, data, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
75
|
+
}
|
|
76
|
+
put(path, data, cancelToken, headers = {}, progressUpdateCallback) {
|
|
77
|
+
return this._xhr('PUT', path, data, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
78
|
+
}
|
|
79
|
+
delete(path, cancelToken, headers = {}, progressUpdateCallback) {
|
|
80
|
+
return this._xhr('DELETE', path, null, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
81
|
+
}
|
|
82
|
+
useLogin() {
|
|
83
|
+
const queryClient = this.getQueryClient();
|
|
84
|
+
return useMutation({
|
|
85
|
+
mutationFn: async ({ username, password, code, cancelToken }) => {
|
|
86
|
+
const resp = await this.post('/login', JSON.stringify({ username, password, code }), cancelToken, { 'Content-Type': 'application/json' });
|
|
87
|
+
if (!resp || !('access_token' in resp)) {
|
|
88
|
+
if (resp.msg === "TOTP required") {
|
|
89
|
+
return LoginResponse.NEEDS_TOTP;
|
|
97
90
|
}
|
|
98
|
-
|
|
99
|
-
if (this.config.timeout) {
|
|
100
|
-
xhr.timeout = this.config.timeout;
|
|
101
|
-
xhr.ontimeout = () => reject(new StandardError(0, 'Request timed out'));
|
|
91
|
+
throw new StandardError(401, 'Invalid login response');
|
|
102
92
|
}
|
|
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');
|
|
93
|
+
this._isAuthenticated = true;
|
|
94
|
+
this.socket.auth = { token: resp.access_token };
|
|
95
|
+
if (!this.socket.connected) {
|
|
96
|
+
this.socket.connect();
|
|
112
97
|
}
|
|
98
|
+
await this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token });
|
|
99
|
+
return LoginResponse.SUCCESS;
|
|
100
|
+
},
|
|
101
|
+
onSettled: () => {
|
|
102
|
+
queryClient.invalidateQueries();
|
|
103
|
+
},
|
|
104
|
+
onError: (err) => {
|
|
105
|
+
this.config.authManager.clearCache();
|
|
106
|
+
throw new StandardError(401, err.message || 'Login failed');
|
|
113
107
|
}
|
|
114
|
-
|
|
115
|
-
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
useRequestCode() {
|
|
111
|
+
const queryClient = this.getQueryClient();
|
|
112
|
+
return useMutation({
|
|
113
|
+
mutationFn: async ({ username, email, cancelToken }) => {
|
|
114
|
+
const resp = await this.post('/code', JSON.stringify({ username, email }), cancelToken, { 'Content-Type': 'application/json' });
|
|
115
|
+
return resp;
|
|
116
|
+
},
|
|
117
|
+
onSettled: () => {
|
|
118
|
+
queryClient.invalidateQueries();
|
|
119
|
+
},
|
|
120
|
+
onError: (err) => {
|
|
121
|
+
throw new StandardError(err.status, err.message || 'Request code failed');
|
|
116
122
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
useUpdatePassword() {
|
|
126
|
+
const queryClient = this.getQueryClient();
|
|
127
|
+
return useMutation({
|
|
128
|
+
mutationFn: async ({ username, email, code, newPassword, cancelToken }) => {
|
|
129
|
+
await this.post(`/user/${username ?? email}/password`, JSON.stringify({ code, password: newPassword }), cancelToken, { 'Content-Type': 'application/json' });
|
|
130
|
+
},
|
|
131
|
+
onSettled: () => {
|
|
132
|
+
queryClient.invalidateQueries();
|
|
133
|
+
},
|
|
134
|
+
onError: (err) => {
|
|
135
|
+
throw new StandardError(err.status, err.message || 'Update password failed');
|
|
130
136
|
}
|
|
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
|
-
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
useGoogleLogin() {
|
|
140
|
+
const queryClient = this.getQueryClient();
|
|
141
|
+
return useMutation({
|
|
142
|
+
mutationFn: async ({ token, cancelToken }) => {
|
|
143
|
+
const resp = await this._xhr('POST', `/google/authorize?token=${token}`, {}, cancelToken, { 'Content-Type': 'application/json' });
|
|
144
|
+
if (!resp || !('access_token' in resp)) {
|
|
145
|
+
if (resp.msg === "TOTP required") {
|
|
146
|
+
return LoginResponse.NEEDS_TOTP;
|
|
166
147
|
}
|
|
148
|
+
throw new StandardError(401, 'Invalid Google login response');
|
|
167
149
|
}
|
|
168
|
-
|
|
169
|
-
|
|
150
|
+
this._isAuthenticated = true;
|
|
151
|
+
this.socket.auth = { token: resp.access_token };
|
|
152
|
+
if (!this.socket.connected) {
|
|
153
|
+
this.socket.connect();
|
|
154
|
+
}
|
|
155
|
+
await this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token });
|
|
156
|
+
return LoginResponse.SUCCESS;
|
|
157
|
+
},
|
|
158
|
+
onSettled: () => {
|
|
159
|
+
queryClient.invalidateQueries();
|
|
160
|
+
},
|
|
161
|
+
onError: (err) => {
|
|
162
|
+
this.config.authManager.clearCache();
|
|
163
|
+
throw new StandardError(err.status, err.message || 'Google Login failed');
|
|
164
|
+
}
|
|
170
165
|
});
|
|
171
166
|
}
|
|
172
|
-
|
|
173
|
-
return this.
|
|
167
|
+
setTokens(tokens) {
|
|
168
|
+
return this.config.authManager.setTokens(tokens);
|
|
169
|
+
}
|
|
170
|
+
setCache(data) {
|
|
171
|
+
return this.config.authManager.setCache(data);
|
|
172
|
+
}
|
|
173
|
+
getCache(key) {
|
|
174
|
+
return this.config.authManager.getCache(key);
|
|
174
175
|
}
|
|
175
|
-
|
|
176
|
-
|
|
176
|
+
setCompanyId(companyId) {
|
|
177
|
+
this.companyId = companyId;
|
|
178
|
+
return this.config.authManager.setCompanyId(companyId);
|
|
177
179
|
}
|
|
178
|
-
|
|
179
|
-
return this.
|
|
180
|
+
clearCache() {
|
|
181
|
+
return this.config.authManager.clearCache();
|
|
180
182
|
}
|
|
181
|
-
|
|
182
|
-
return this.
|
|
183
|
+
isAuthenticated() {
|
|
184
|
+
return this._isAuthenticated;
|
|
183
185
|
}
|
|
184
|
-
|
|
185
|
-
return this.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
isAuthenticatedAsync() {
|
|
187
|
+
return this.config.authManager.isAuthenticated();
|
|
188
|
+
}
|
|
189
|
+
getQueryClient() {
|
|
190
|
+
return this.config.queryClient;
|
|
191
|
+
}
|
|
192
|
+
useLogout() {
|
|
193
|
+
const queryClient = this.getQueryClient();
|
|
194
|
+
return useMutation({
|
|
195
|
+
mutationFn: async (cancelToken) => {
|
|
196
|
+
await this.post('/logout', null, cancelToken);
|
|
197
|
+
await this.config.authManager.clearCache();
|
|
198
|
+
if (this.socket && this.socket.connected) {
|
|
199
|
+
this.socket.disconnect();
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
onSettled: () => {
|
|
203
|
+
this._isAuthenticated = false;
|
|
204
|
+
this.clearCache();
|
|
205
|
+
queryClient.invalidateQueries();
|
|
206
|
+
},
|
|
207
|
+
onError: (err) => {
|
|
208
|
+
this.clearCache();
|
|
209
|
+
console.error('Logout failed:', err);
|
|
210
|
+
throw new StandardError(500, 'Logout failed');
|
|
189
211
|
}
|
|
190
|
-
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
fetchJobs(body = {}, cancelToken, headers = {}) {
|
|
215
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
216
|
+
throw new StandardError(400, 'Company ID is required');
|
|
217
|
+
}
|
|
218
|
+
return this._fetch('POST', `/company/${this.companyId}/jobs`, JSON.stringify(body), cancelToken, {
|
|
219
|
+
...headers,
|
|
220
|
+
'Content-Type': 'application/json',
|
|
221
|
+
})
|
|
222
|
+
.then(response => {
|
|
223
|
+
if (!response || !Array.isArray(response)) {
|
|
224
|
+
throw new StandardError(400, 'Invalid jobs response');
|
|
225
|
+
}
|
|
226
|
+
return response;
|
|
191
227
|
})
|
|
192
228
|
.catch(err => {
|
|
193
|
-
console.error('
|
|
194
|
-
throw new StandardError(
|
|
229
|
+
console.error('Failed to fetch jobs:', err);
|
|
230
|
+
throw new StandardError(500, `Failed to fetch jobs: ${err.message ?? err}`);
|
|
195
231
|
});
|
|
196
232
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
233
|
+
fetchChats(body = {}, cancelToken, headers = {}) {
|
|
234
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
235
|
+
throw new StandardError(400, 'Company ID is required');
|
|
236
|
+
}
|
|
237
|
+
return this._fetch('POST', `/company/${this.companyId}/chats`, JSON.stringify(body), cancelToken, {
|
|
238
|
+
...headers,
|
|
239
|
+
'Content-Type': 'application/json',
|
|
240
|
+
})
|
|
241
|
+
.then(response => {
|
|
242
|
+
if (!response || !Array.isArray(response)) {
|
|
243
|
+
throw new StandardError(400, 'Invalid chats response');
|
|
244
|
+
}
|
|
245
|
+
return response;
|
|
246
|
+
})
|
|
200
247
|
.catch(err => {
|
|
201
|
-
console.error('
|
|
202
|
-
throw new StandardError(500, '
|
|
248
|
+
console.error('Failed to fetch chats:', err);
|
|
249
|
+
throw new StandardError(500, 'Failed to fetch chats');
|
|
203
250
|
});
|
|
204
251
|
}
|
|
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'));
|
|
252
|
+
fetchMessages(chatId, body = {}, cancelToken, headers = {}) {
|
|
253
|
+
if (!chatId || chatId.trim() === '') {
|
|
254
|
+
throw new StandardError(400, 'Chat ID is required');
|
|
214
255
|
}
|
|
215
|
-
return this._fetch('POST', `/
|
|
256
|
+
return this._fetch('POST', `/chat/${chatId}/messages`, JSON.stringify(body), cancelToken, {
|
|
257
|
+
...headers,
|
|
258
|
+
'Content-Type': 'application/json',
|
|
259
|
+
})
|
|
216
260
|
.then(response => {
|
|
217
261
|
if (!response || !Array.isArray(response)) {
|
|
218
|
-
throw new StandardError(400, 'Invalid
|
|
262
|
+
throw new StandardError(400, 'Invalid messages response');
|
|
219
263
|
}
|
|
220
264
|
return response;
|
|
221
265
|
})
|
|
222
266
|
.catch(err => {
|
|
223
|
-
console.error('Failed to fetch
|
|
224
|
-
throw new StandardError(500, 'Failed to fetch
|
|
267
|
+
console.error('Failed to fetch messages:', err);
|
|
268
|
+
throw new StandardError(500, 'Failed to fetch messages');
|
|
225
269
|
});
|
|
226
270
|
}
|
|
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'));
|
|
271
|
+
async fetchEvents(body = {}, cancelToken, headers = {}) {
|
|
272
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
273
|
+
throw new StandardError(400, 'Company ID is required');
|
|
237
274
|
}
|
|
238
|
-
return this._fetch('POST', `/company/${
|
|
275
|
+
return this._fetch('POST', `/company/${this.companyId}/events`, JSON.stringify(body), cancelToken, {
|
|
276
|
+
...headers,
|
|
277
|
+
'Content-Type': 'application/json',
|
|
278
|
+
})
|
|
239
279
|
.then(response => {
|
|
240
280
|
if (!response || !Array.isArray(response)) {
|
|
241
281
|
throw new StandardError(400, 'Invalid events response');
|
|
@@ -247,17 +287,33 @@ export class AvroQueryClient {
|
|
|
247
287
|
throw new StandardError(500, 'Failed to fetch events');
|
|
248
288
|
});
|
|
249
289
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
known_ids,
|
|
254
|
-
unknown_ids,
|
|
255
|
-
query: keyword,
|
|
256
|
-
};
|
|
257
|
-
if (!companyGuid) {
|
|
258
|
-
return Promise.reject(new StandardError(400, 'Company GUID is required'));
|
|
290
|
+
fetchMonths(body = {}, cancelToken, headers = {}) {
|
|
291
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
292
|
+
throw new StandardError(400, 'Company ID is required');
|
|
259
293
|
}
|
|
260
|
-
return this._fetch('POST', `/company/${
|
|
294
|
+
return this._fetch('POST', `/company/${this.companyId}/months`, JSON.stringify(body), cancelToken, {
|
|
295
|
+
...headers,
|
|
296
|
+
'Content-Type': 'application/json',
|
|
297
|
+
})
|
|
298
|
+
.then(response => {
|
|
299
|
+
if (!response || !Array.isArray(response)) {
|
|
300
|
+
throw new StandardError(400, 'Invalid months response');
|
|
301
|
+
}
|
|
302
|
+
return response;
|
|
303
|
+
})
|
|
304
|
+
.catch(err => {
|
|
305
|
+
console.error('Failed to fetch months:', err);
|
|
306
|
+
throw new StandardError(500, 'Failed to fetch months');
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
fetchBills(body = {}, cancelToken, headers = {}) {
|
|
310
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
311
|
+
throw new StandardError(400, 'Company ID is required');
|
|
312
|
+
}
|
|
313
|
+
return this._fetch('POST', `/company/${this.companyId}/bills`, JSON.stringify(body), cancelToken, {
|
|
314
|
+
...headers,
|
|
315
|
+
'Content-Type': 'application/json',
|
|
316
|
+
})
|
|
261
317
|
.then(response => {
|
|
262
318
|
if (!response || !Array.isArray(response)) {
|
|
263
319
|
throw new StandardError(400, 'Invalid bills response');
|
|
@@ -269,4 +325,88 @@ export class AvroQueryClient {
|
|
|
269
325
|
throw new StandardError(500, 'Failed to fetch bills');
|
|
270
326
|
});
|
|
271
327
|
}
|
|
328
|
+
fetchRoutes(body = {}, cancelToken, headers = {}) {
|
|
329
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
330
|
+
throw new StandardError(400, 'Company ID is required');
|
|
331
|
+
}
|
|
332
|
+
return this._fetch('POST', `/company/${this.companyId}/routes`, JSON.stringify(body), cancelToken, {
|
|
333
|
+
...headers,
|
|
334
|
+
'Content-Type': 'application/json',
|
|
335
|
+
})
|
|
336
|
+
.then(response => {
|
|
337
|
+
if (!response || !Array.isArray(response)) {
|
|
338
|
+
throw new StandardError(400, 'Invalid routes response');
|
|
339
|
+
}
|
|
340
|
+
return response;
|
|
341
|
+
})
|
|
342
|
+
.catch(err => {
|
|
343
|
+
console.error('Failed to fetch routes:', err);
|
|
344
|
+
throw new StandardError(500, 'Failed to fetch routes');
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
fetchTeams(body = {}, cancelToken, headers = {}) {
|
|
348
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
349
|
+
throw new StandardError(400, 'Company ID is required');
|
|
350
|
+
}
|
|
351
|
+
return this._fetch('POST', `/company/${this.companyId}/teams`, JSON.stringify(body), cancelToken, {
|
|
352
|
+
...headers,
|
|
353
|
+
'Content-Type': 'application/json',
|
|
354
|
+
})
|
|
355
|
+
.then(response => {
|
|
356
|
+
if (!response || !Array.isArray(response)) {
|
|
357
|
+
throw new StandardError(400, 'Invalid teams response');
|
|
358
|
+
}
|
|
359
|
+
return response;
|
|
360
|
+
})
|
|
361
|
+
.catch(err => {
|
|
362
|
+
console.error('Failed to fetch teams:', err);
|
|
363
|
+
throw new StandardError(500, 'Failed to fetch teams');
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
fetchSkills(body = {}, cancelToken, headers = {}) {
|
|
367
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
368
|
+
throw new StandardError(400, 'Company ID is required');
|
|
369
|
+
}
|
|
370
|
+
return this._fetch('POST', `/company/${this.companyId}/skills`, JSON.stringify(body), cancelToken, {
|
|
371
|
+
...headers,
|
|
372
|
+
'Content-Type': 'application/json',
|
|
373
|
+
})
|
|
374
|
+
.then(response => {
|
|
375
|
+
if (!response || !Array.isArray(response)) {
|
|
376
|
+
throw new StandardError(400, 'Invalid skills response');
|
|
377
|
+
}
|
|
378
|
+
return response;
|
|
379
|
+
})
|
|
380
|
+
.catch(err => {
|
|
381
|
+
console.error('Failed to fetch skills:', err);
|
|
382
|
+
throw new StandardError(500, 'Failed to fetch skills');
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
fetchSessions(body = {}, cancelToken, headers = {}) {
|
|
386
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
387
|
+
throw new StandardError(400, 'Company ID is required');
|
|
388
|
+
}
|
|
389
|
+
return this._fetch('POST', `/company/${this.companyId}/sessions`, JSON.stringify(body), cancelToken, {
|
|
390
|
+
...headers,
|
|
391
|
+
'Content-Type': 'application/json',
|
|
392
|
+
})
|
|
393
|
+
.then(response => {
|
|
394
|
+
if (!response || !Array.isArray(response)) {
|
|
395
|
+
throw new StandardError(400, 'Invalid sessions response');
|
|
396
|
+
}
|
|
397
|
+
return response;
|
|
398
|
+
})
|
|
399
|
+
.catch(err => {
|
|
400
|
+
console.error('Failed to fetch sessions:', err);
|
|
401
|
+
throw new StandardError(500, 'Failed to fetch sessions');
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
sendEmail(emailId, formData, progressUpdateCallback) {
|
|
405
|
+
try {
|
|
406
|
+
return this.post(`/email/${emailId}`, formData, undefined, {}, progressUpdateCallback);
|
|
407
|
+
}
|
|
408
|
+
catch (error) {
|
|
409
|
+
throw new StandardError(500, `Failed to send email: ${error}`);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
272
412
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|