@go-avro/avro-js 0.0.2-beta.17 → 0.0.2-beta.170
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 +529 -16
- package/dist/client/QueryClient.js +397 -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/catalog_items.d.ts +1 -0
- package/dist/client/hooks/catalog_items.js +90 -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 +185 -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 +296 -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 +174 -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 +27 -1
- package/dist/index.js +27 -1
- package/dist/types/api.d.ts +243 -53
- package/dist/types/api.js +57 -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 = undefined;
|
|
10
|
+
this.company = undefined;
|
|
11
|
+
this.authStateListeners = [];
|
|
4
12
|
this.config = {
|
|
5
13
|
baseUrl: config.baseUrl,
|
|
6
14
|
authManager: config.authManager,
|
|
@@ -8,234 +16,294 @@ 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 = {}, companyId, cancelToken, headers = {}) {
|
|
242
|
+
const companyIdToUse = companyId ?? this.companyId;
|
|
243
|
+
if (!companyIdToUse || companyIdToUse.trim() === '') {
|
|
244
|
+
throw new StandardError(400, 'Company ID is required');
|
|
245
|
+
}
|
|
246
|
+
return this._fetch('POST', `/company/${companyIdToUse}/jobs`, JSON.stringify(body), cancelToken, {
|
|
247
|
+
...headers,
|
|
248
|
+
'Content-Type': 'application/json',
|
|
249
|
+
})
|
|
250
|
+
.then(response => {
|
|
251
|
+
if (!response || !Array.isArray(response)) {
|
|
252
|
+
throw new StandardError(400, 'Invalid jobs response');
|
|
189
253
|
}
|
|
190
|
-
return
|
|
254
|
+
return response;
|
|
191
255
|
})
|
|
192
256
|
.catch(err => {
|
|
193
|
-
console.error('
|
|
194
|
-
throw new StandardError(
|
|
257
|
+
console.error('Failed to fetch jobs:', err);
|
|
258
|
+
throw new StandardError(500, `Failed to fetch jobs: ${err.message ?? err}`);
|
|
195
259
|
});
|
|
196
260
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
261
|
+
fetchChats(body = {}, cancelToken, headers = {}) {
|
|
262
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
263
|
+
throw new StandardError(400, 'Company ID is required');
|
|
264
|
+
}
|
|
265
|
+
return this._fetch('POST', `/company/${this.companyId}/chats`, JSON.stringify(body), cancelToken, {
|
|
266
|
+
...headers,
|
|
267
|
+
'Content-Type': 'application/json',
|
|
268
|
+
})
|
|
269
|
+
.then(response => {
|
|
270
|
+
if (!response || !Array.isArray(response)) {
|
|
271
|
+
throw new StandardError(400, 'Invalid chats response');
|
|
272
|
+
}
|
|
273
|
+
return response;
|
|
274
|
+
})
|
|
200
275
|
.catch(err => {
|
|
201
|
-
console.error('
|
|
202
|
-
throw new StandardError(500, '
|
|
276
|
+
console.error('Failed to fetch chats:', err);
|
|
277
|
+
throw new StandardError(500, 'Failed to fetch chats');
|
|
203
278
|
});
|
|
204
279
|
}
|
|
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'));
|
|
280
|
+
fetchMessages(chatId, body = {}, cancelToken, headers = {}) {
|
|
281
|
+
if (!chatId || chatId.trim() === '') {
|
|
282
|
+
throw new StandardError(400, 'Chat ID is required');
|
|
214
283
|
}
|
|
215
|
-
return this._fetch('POST', `/
|
|
284
|
+
return this._fetch('POST', `/chat/${chatId}/messages`, JSON.stringify(body), cancelToken, {
|
|
285
|
+
...headers,
|
|
286
|
+
'Content-Type': 'application/json',
|
|
287
|
+
})
|
|
216
288
|
.then(response => {
|
|
217
289
|
if (!response || !Array.isArray(response)) {
|
|
218
|
-
throw new StandardError(400, 'Invalid
|
|
290
|
+
throw new StandardError(400, 'Invalid messages response');
|
|
219
291
|
}
|
|
220
292
|
return response;
|
|
221
293
|
})
|
|
222
294
|
.catch(err => {
|
|
223
|
-
console.error('Failed to fetch
|
|
224
|
-
throw new StandardError(500, 'Failed to fetch
|
|
295
|
+
console.error('Failed to fetch messages:', err);
|
|
296
|
+
throw new StandardError(500, 'Failed to fetch messages');
|
|
225
297
|
});
|
|
226
298
|
}
|
|
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'));
|
|
299
|
+
async fetchEvents(body = {}, cancelToken, headers = {}) {
|
|
300
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
301
|
+
throw new StandardError(400, 'Company ID is required');
|
|
237
302
|
}
|
|
238
|
-
return this._fetch('POST', `/company/${
|
|
303
|
+
return this._fetch('POST', `/company/${this.companyId}/events`, JSON.stringify(body), cancelToken, {
|
|
304
|
+
...headers,
|
|
305
|
+
'Content-Type': 'application/json',
|
|
306
|
+
})
|
|
239
307
|
.then(response => {
|
|
240
308
|
if (!response || !Array.isArray(response)) {
|
|
241
309
|
throw new StandardError(400, 'Invalid events response');
|
|
@@ -247,18 +315,14 @@ export class AvroQueryClient {
|
|
|
247
315
|
throw new StandardError(500, 'Failed to fetch events');
|
|
248
316
|
});
|
|
249
317
|
}
|
|
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'));
|
|
318
|
+
fetchMonths(body = {}, cancelToken, headers = {}) {
|
|
319
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
320
|
+
throw new StandardError(400, 'Company ID is required');
|
|
260
321
|
}
|
|
261
|
-
return this._fetch('POST', `/company/${
|
|
322
|
+
return this._fetch('POST', `/company/${this.companyId}/months`, JSON.stringify(body), cancelToken, {
|
|
323
|
+
...headers,
|
|
324
|
+
'Content-Type': 'application/json',
|
|
325
|
+
})
|
|
262
326
|
.then(response => {
|
|
263
327
|
if (!response || !Array.isArray(response)) {
|
|
264
328
|
throw new StandardError(400, 'Invalid months response');
|
|
@@ -270,17 +334,14 @@ export class AvroQueryClient {
|
|
|
270
334
|
throw new StandardError(500, 'Failed to fetch months');
|
|
271
335
|
});
|
|
272
336
|
}
|
|
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'));
|
|
337
|
+
fetchBills(body = {}, cancelToken, headers = {}) {
|
|
338
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
339
|
+
throw new StandardError(400, 'Company ID is required');
|
|
282
340
|
}
|
|
283
|
-
return this._fetch('POST', `/company/${
|
|
341
|
+
return this._fetch('POST', `/company/${this.companyId}/bills`, JSON.stringify(body), cancelToken, {
|
|
342
|
+
...headers,
|
|
343
|
+
'Content-Type': 'application/json',
|
|
344
|
+
})
|
|
284
345
|
.then(response => {
|
|
285
346
|
if (!response || !Array.isArray(response)) {
|
|
286
347
|
throw new StandardError(400, 'Invalid bills response');
|
|
@@ -292,4 +353,126 @@ export class AvroQueryClient {
|
|
|
292
353
|
throw new StandardError(500, 'Failed to fetch bills');
|
|
293
354
|
});
|
|
294
355
|
}
|
|
356
|
+
fetchRoutes(body = {}, cancelToken, headers = {}) {
|
|
357
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
358
|
+
throw new StandardError(400, 'Company ID is required');
|
|
359
|
+
}
|
|
360
|
+
return this._fetch('POST', `/company/${this.companyId}/routes`, JSON.stringify(body), cancelToken, {
|
|
361
|
+
...headers,
|
|
362
|
+
'Content-Type': 'application/json',
|
|
363
|
+
})
|
|
364
|
+
.then(response => {
|
|
365
|
+
if (!response || !Array.isArray(response)) {
|
|
366
|
+
throw new StandardError(400, 'Invalid routes response');
|
|
367
|
+
}
|
|
368
|
+
return response;
|
|
369
|
+
})
|
|
370
|
+
.catch(err => {
|
|
371
|
+
console.error('Failed to fetch routes:', err);
|
|
372
|
+
throw new StandardError(500, 'Failed to fetch routes');
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
fetchTeams(body = {}, cancelToken, headers = {}) {
|
|
376
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
377
|
+
throw new StandardError(400, 'Company ID is required');
|
|
378
|
+
}
|
|
379
|
+
return this._fetch('POST', `/company/${this.companyId}/teams`, JSON.stringify(body), cancelToken, {
|
|
380
|
+
...headers,
|
|
381
|
+
'Content-Type': 'application/json',
|
|
382
|
+
})
|
|
383
|
+
.then(response => {
|
|
384
|
+
if (!response || !Array.isArray(response)) {
|
|
385
|
+
throw new StandardError(400, 'Invalid teams response');
|
|
386
|
+
}
|
|
387
|
+
return response;
|
|
388
|
+
})
|
|
389
|
+
.catch(err => {
|
|
390
|
+
console.error('Failed to fetch teams:', err);
|
|
391
|
+
throw new StandardError(500, 'Failed to fetch teams');
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
fetchLabels(body = {}, cancelToken, headers = {}) {
|
|
395
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
396
|
+
throw new StandardError(400, 'Company ID is required');
|
|
397
|
+
}
|
|
398
|
+
return this._fetch('POST', `/company/${this.companyId}/labels`, JSON.stringify(body), cancelToken, {
|
|
399
|
+
...headers,
|
|
400
|
+
'Content-Type': 'application/json',
|
|
401
|
+
})
|
|
402
|
+
.then(response => {
|
|
403
|
+
if (!response || !Array.isArray(response)) {
|
|
404
|
+
throw new StandardError(400, 'Invalid labels response');
|
|
405
|
+
}
|
|
406
|
+
return response;
|
|
407
|
+
})
|
|
408
|
+
.catch(err => {
|
|
409
|
+
console.error('Failed to fetch labels:', err);
|
|
410
|
+
throw new StandardError(500, 'Failed to fetch labels');
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
fetchGroups(body = {}, cancelToken, headers = {}) {
|
|
414
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
415
|
+
throw new StandardError(400, 'Company ID is required');
|
|
416
|
+
}
|
|
417
|
+
return this._fetch('POST', `/company/${this.companyId}/groups`, JSON.stringify(body), cancelToken, {
|
|
418
|
+
...headers,
|
|
419
|
+
'Content-Type': 'application/json',
|
|
420
|
+
})
|
|
421
|
+
.then(response => {
|
|
422
|
+
if (!response || !Array.isArray(response)) {
|
|
423
|
+
throw new StandardError(400, 'Invalid groups response');
|
|
424
|
+
}
|
|
425
|
+
return response;
|
|
426
|
+
})
|
|
427
|
+
.catch(err => {
|
|
428
|
+
console.error('Failed to fetch groups:', err);
|
|
429
|
+
throw new StandardError(500, 'Failed to fetch groups');
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
fetchSkills(body = {}, cancelToken, headers = {}) {
|
|
433
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
434
|
+
throw new StandardError(400, 'Company ID is required');
|
|
435
|
+
}
|
|
436
|
+
return this._fetch('POST', `/company/${this.companyId}/skills`, JSON.stringify(body), cancelToken, {
|
|
437
|
+
...headers,
|
|
438
|
+
'Content-Type': 'application/json',
|
|
439
|
+
})
|
|
440
|
+
.then(response => {
|
|
441
|
+
if (!response || !Array.isArray(response)) {
|
|
442
|
+
throw new StandardError(400, 'Invalid skills response');
|
|
443
|
+
}
|
|
444
|
+
return response;
|
|
445
|
+
})
|
|
446
|
+
.catch(err => {
|
|
447
|
+
console.error('Failed to fetch skills:', err);
|
|
448
|
+
throw new StandardError(500, 'Failed to fetch skills');
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
fetchSessions(body = {}, cancelToken, headers = {}) {
|
|
452
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
453
|
+
throw new StandardError(400, 'Company ID is required');
|
|
454
|
+
}
|
|
455
|
+
return this._fetch('POST', `/company/${this.companyId}/sessions`, JSON.stringify(body), cancelToken, {
|
|
456
|
+
...headers,
|
|
457
|
+
'Content-Type': 'application/json',
|
|
458
|
+
})
|
|
459
|
+
.then(response => {
|
|
460
|
+
if (!response || !Array.isArray(response)) {
|
|
461
|
+
throw new StandardError(400, 'Invalid sessions response');
|
|
462
|
+
}
|
|
463
|
+
return response;
|
|
464
|
+
})
|
|
465
|
+
.catch(err => {
|
|
466
|
+
console.error('Failed to fetch sessions:', err);
|
|
467
|
+
throw new StandardError(500, 'Failed to fetch sessions');
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
sendEmail(emailId, formData, progressUpdateCallback) {
|
|
471
|
+
try {
|
|
472
|
+
return this.post(`/email/${emailId}`, formData, undefined, {}, progressUpdateCallback);
|
|
473
|
+
}
|
|
474
|
+
catch (error) {
|
|
475
|
+
throw new StandardError(500, `Failed to send email: ${error}`);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
295
478
|
}
|