@go-avro/avro-js 0.0.2-beta.5 → 0.0.2-beta.7

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.
@@ -26,7 +26,23 @@ export class AuthManager {
26
26
  'Authorization': `Bearer ${tokens.access_token}`,
27
27
  },
28
28
  });
29
- return response.ok;
29
+ if (response.ok) {
30
+ return true;
31
+ }
32
+ else {
33
+ // Attempt token refresh if validation fails
34
+ const newTokens = await this.refreshTokens();
35
+ if (newTokens && newTokens.access_token) {
36
+ const retryResponse = await fetch(`${this.baseUrl}/validate`, {
37
+ method: 'POST',
38
+ headers: {
39
+ 'Content-Type': 'application/json',
40
+ 'Authorization': `Bearer ${newTokens.access_token}`,
41
+ },
42
+ });
43
+ return retryResponse.ok;
44
+ }
45
+ }
30
46
  }
31
47
  catch (error) {
32
48
  console.error('Error validating access token:', error);
@@ -23,4 +23,5 @@ export declare class AvroQueryClient {
23
23
  }, cancelToken?: CancelToken): Promise<Boolean>;
24
24
  logout(cancelToken?: CancelToken): Promise<void>;
25
25
  fetchJobs(companyGuid: string, amt?: number, knownIds?: string[], unknownIds?: string[], keyword?: string, offset?: number, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
26
+ fetchEvents(companyGuid: string, amt?: number, known_ids?: string[], unknown_ids?: string[], keyword?: string, offset?: number, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
26
27
  }
@@ -219,4 +219,26 @@ export class AvroQueryClient {
219
219
  throw new StandardError(500, 'Failed to fetch jobs');
220
220
  });
221
221
  }
222
+ fetchEvents(companyGuid, amt = 50, known_ids = [], unknown_ids = [], keyword = '', offset = 0, cancelToken, headers = {}) {
223
+ const body = {
224
+ amt,
225
+ known_ids,
226
+ unknown_ids,
227
+ query: keyword,
228
+ };
229
+ if (!companyGuid) {
230
+ return Promise.reject(new StandardError(400, 'Company GUID is required'));
231
+ }
232
+ return this._fetch('POST', `/company/${companyGuid}/events?amt=${amt}&offset=${offset}`, body, cancelToken, headers)
233
+ .then(response => {
234
+ if (!response || !Array.isArray(response)) {
235
+ throw new StandardError(400, 'Invalid events response');
236
+ }
237
+ return response;
238
+ })
239
+ .catch(err => {
240
+ console.error('Failed to fetch events:', err);
241
+ throw new StandardError(500, 'Failed to fetch events');
242
+ });
243
+ }
222
244
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.5",
3
+ "version": "0.0.2-beta.7",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",