@go-avro/avro-js 0.0.2-beta.2 → 0.0.2-beta.4
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/dist/auth/AuthManager.js
CHANGED
|
@@ -21,31 +21,29 @@ export class AuthManager {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
async fetchNewTokens() {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
for (const storage of this.storages) {
|
|
25
|
+
const tokens = await storage.get();
|
|
26
|
+
if (!tokens || !tokens.refresh_token)
|
|
27
|
+
continue;
|
|
28
|
+
try {
|
|
29
|
+
const response = await fetch(`${this.baseUrl}/refresh`, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: {
|
|
32
|
+
'Content-Type': 'application/json',
|
|
33
|
+
'Accept': 'application/json',
|
|
34
|
+
'Authorization': `Bearer ${tokens.refresh_token}`,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
if (response.ok) {
|
|
38
|
+
const newTokens = await response.json();
|
|
39
|
+
return newTokens;
|
|
29
40
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
throw new Error('No refresh token available');
|
|
35
|
-
}
|
|
36
|
-
const response = await fetch(`${this.baseUrl}/refresh`, {
|
|
37
|
-
method: 'POST',
|
|
38
|
-
headers: {
|
|
39
|
-
'Content-Type': 'application/json',
|
|
40
|
-
'Accept': 'application/json',
|
|
41
|
-
'Authorization': `Bearer ${refreshToken}`,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
if (!response.ok) {
|
|
45
|
-
throw new Error('Failed to refresh tokens');
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
storage.clear();
|
|
44
|
+
}
|
|
46
45
|
}
|
|
47
|
-
|
|
48
|
-
return tokens;
|
|
46
|
+
throw new Error('Failed to refresh tokens from all storages');
|
|
49
47
|
}
|
|
50
48
|
async accessToken() {
|
|
51
49
|
if (!this.storages.length) {
|
|
@@ -21,4 +21,6 @@ export declare class AvroQueryClient {
|
|
|
21
21
|
username: string;
|
|
22
22
|
password: string;
|
|
23
23
|
}, cancelToken?: CancelToken): Promise<Boolean>;
|
|
24
|
+
logout(cancelToken?: CancelToken): Promise<void>;
|
|
25
|
+
fetchJobs(companyGuid: string, amt?: number, knownIds?: string[], unknownIds?: string[], keyword?: string, offset?: number, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
24
26
|
}
|
|
@@ -176,7 +176,6 @@ export class AvroQueryClient {
|
|
|
176
176
|
delete(path, cancelToken, headers = {}) {
|
|
177
177
|
return this._xhr('DELETE', path, null, cancelToken, headers, false);
|
|
178
178
|
}
|
|
179
|
-
// add login that uses fetch and sets the tokens in the auth manager
|
|
180
179
|
login(data, cancelToken) {
|
|
181
180
|
return this._fetch('POST', '/login', data, cancelToken)
|
|
182
181
|
.then(tokens => {
|
|
@@ -190,4 +189,34 @@ export class AvroQueryClient {
|
|
|
190
189
|
throw new StandardError(401, 'Login failed');
|
|
191
190
|
});
|
|
192
191
|
}
|
|
192
|
+
logout(cancelToken) {
|
|
193
|
+
return this._fetch('POST', '/logout', null, cancelToken)
|
|
194
|
+
.then(() => this.config.authManager.clearTokens())
|
|
195
|
+
.catch(err => {
|
|
196
|
+
console.error('Logout failed:', err);
|
|
197
|
+
throw new StandardError(500, 'Logout failed');
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
fetchJobs(companyGuid, amt = 50, knownIds = [], unknownIds = [], keyword = '', offset = 0, cancelToken, headers = {}) {
|
|
201
|
+
const body = {
|
|
202
|
+
amt,
|
|
203
|
+
known_ids: knownIds,
|
|
204
|
+
unknown_ids: unknownIds,
|
|
205
|
+
query: keyword,
|
|
206
|
+
};
|
|
207
|
+
if (!companyGuid) {
|
|
208
|
+
return Promise.reject(new StandardError(400, 'Company GUID is required'));
|
|
209
|
+
}
|
|
210
|
+
return this._fetch('POST', `/company/${companyGuid}/jobs?amt=${amt}&offset=${offset}`, body, cancelToken, headers)
|
|
211
|
+
.then(response => {
|
|
212
|
+
if (!response || !Array.isArray(response)) {
|
|
213
|
+
throw new StandardError(400, 'Invalid jobs response');
|
|
214
|
+
}
|
|
215
|
+
return response;
|
|
216
|
+
})
|
|
217
|
+
.catch(err => {
|
|
218
|
+
console.error('Failed to fetch jobs:', err);
|
|
219
|
+
throw new StandardError(500, 'Failed to fetch jobs');
|
|
220
|
+
});
|
|
221
|
+
}
|
|
193
222
|
}
|