@go-avro/avro-js 0.0.2-beta.52 → 0.0.2-beta.54
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { InfiniteData, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
import { AuthManager } from '../auth/AuthManager';
|
|
3
3
|
import { _Event, ApiInfo, Bill, Company, Job, LineItem, Route, ServiceMonth, Session, User } from '../types/api';
|
|
4
|
+
import { Tokens } from '../types/auth';
|
|
4
5
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
5
6
|
import { StandardError } from '../types/error';
|
|
6
7
|
export interface AvroQueryClientConfig {
|
|
@@ -12,7 +13,7 @@ export interface AvroQueryClientConfig {
|
|
|
12
13
|
}
|
|
13
14
|
declare module '../client/QueryClient' {
|
|
14
15
|
interface AvroQueryClient {
|
|
15
|
-
_xhr<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number): Promise<T>;
|
|
16
|
+
_xhr<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
16
17
|
_fetch<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number): Promise<T>;
|
|
17
18
|
getDelay(strategy: RetryStrategy, attempt: number): number;
|
|
18
19
|
useGetRoot(): UseQueryResult<ApiInfo, StandardError>;
|
|
@@ -173,14 +174,16 @@ declare module '../client/QueryClient' {
|
|
|
173
174
|
export declare class AvroQueryClient {
|
|
174
175
|
protected config: Required<AvroQueryClientConfig>;
|
|
175
176
|
constructor(config: AvroQueryClientConfig);
|
|
176
|
-
get<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string
|
|
177
|
-
post<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string
|
|
178
|
-
put<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string
|
|
179
|
-
delete<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string
|
|
177
|
+
get<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
178
|
+
post<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
179
|
+
put<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
180
|
+
delete<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
180
181
|
login(data: {
|
|
181
182
|
username: string;
|
|
182
183
|
password: string;
|
|
183
184
|
}, cancelToken?: CancelToken): Promise<Boolean>;
|
|
185
|
+
setTokens(tokens: Tokens): Promise<void>;
|
|
186
|
+
clearTokens(): Promise<void>;
|
|
184
187
|
logout(cancelToken?: CancelToken): Promise<void>;
|
|
185
188
|
fetchJobs(companyGuid: string, body?: {
|
|
186
189
|
amt?: number;
|
|
@@ -226,7 +229,7 @@ export declare class AvroQueryClient {
|
|
|
226
229
|
query?: string;
|
|
227
230
|
offset?: number;
|
|
228
231
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
229
|
-
sendEmail(emailId: string, formData: FormData): Promise<void>;
|
|
232
|
+
sendEmail(emailId: string, formData: FormData, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<void>;
|
|
230
233
|
createBill(companyGuid: string, data: {
|
|
231
234
|
line_items: LineItem[];
|
|
232
235
|
due_date: number;
|
|
@@ -9,17 +9,17 @@ export class AvroQueryClient {
|
|
|
9
9
|
timeout: config.timeout ?? 0,
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
get(path, cancelToken, headers = {}) {
|
|
13
|
-
return this._xhr('GET', path, null, cancelToken, headers, true);
|
|
12
|
+
get(path, cancelToken, headers = {}, progressUpdateCallback) {
|
|
13
|
+
return this._xhr('GET', path, null, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
14
14
|
}
|
|
15
|
-
post(path, data, cancelToken, headers = {}) {
|
|
16
|
-
return this._xhr('POST', path, data, cancelToken, headers, false);
|
|
15
|
+
post(path, data, cancelToken, headers = {}, progressUpdateCallback) {
|
|
16
|
+
return this._xhr('POST', path, data, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
17
17
|
}
|
|
18
|
-
put(path, data, cancelToken, headers = {}) {
|
|
19
|
-
return this._xhr('PUT', path, data, cancelToken, headers, true);
|
|
18
|
+
put(path, data, cancelToken, headers = {}, progressUpdateCallback) {
|
|
19
|
+
return this._xhr('PUT', path, data, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
20
20
|
}
|
|
21
|
-
delete(path, cancelToken, headers = {}) {
|
|
22
|
-
return this._xhr('DELETE', path, null, cancelToken, headers, false);
|
|
21
|
+
delete(path, cancelToken, headers = {}, progressUpdateCallback) {
|
|
22
|
+
return this._xhr('DELETE', path, null, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
23
23
|
}
|
|
24
24
|
login(data, cancelToken) {
|
|
25
25
|
return this._fetch('POST', '/login', data, cancelToken)
|
|
@@ -34,6 +34,12 @@ export class AvroQueryClient {
|
|
|
34
34
|
throw new StandardError(401, 'Login failed');
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
setTokens(tokens) {
|
|
38
|
+
return this.config.authManager.setTokens(tokens);
|
|
39
|
+
}
|
|
40
|
+
clearTokens() {
|
|
41
|
+
return this.config.authManager.clearTokens();
|
|
42
|
+
}
|
|
37
43
|
logout(cancelToken) {
|
|
38
44
|
return this._fetch('POST', '/logout', null, cancelToken)
|
|
39
45
|
.then(() => this.config.authManager.clearTokens())
|
|
@@ -122,9 +128,9 @@ export class AvroQueryClient {
|
|
|
122
128
|
throw new StandardError(500, 'Failed to fetch routes');
|
|
123
129
|
});
|
|
124
130
|
}
|
|
125
|
-
sendEmail(emailId, formData) {
|
|
131
|
+
sendEmail(emailId, formData, progressUpdateCallback) {
|
|
126
132
|
try {
|
|
127
|
-
return this.
|
|
133
|
+
return this.post(`/email/${emailId}`, formData, undefined, {}, progressUpdateCallback);
|
|
128
134
|
}
|
|
129
135
|
catch (error) {
|
|
130
136
|
throw new StandardError(500, `Failed to send email: ${error}`);
|
package/dist/client/core/xhr.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
2
2
|
import { StandardError } from '../../types/error';
|
|
3
|
-
AvroQueryClient.prototype._xhr = function (method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount = 0) {
|
|
3
|
+
AvroQueryClient.prototype._xhr = function (method, path, body, cancelToken, headers = {}, isIdempotent = false, retryCount = 0, progressUpdateCallback) {
|
|
4
4
|
const checkCancelled = () => {
|
|
5
5
|
if (cancelToken?.isCancelled()) {
|
|
6
6
|
return new StandardError(0, 'Request cancelled');
|
|
@@ -59,6 +59,13 @@ AvroQueryClient.prototype._xhr = function (method, path, body, cancelToken, head
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
+
if (progressUpdateCallback && xhr.upload) {
|
|
63
|
+
xhr.upload.onprogress = (event) => {
|
|
64
|
+
if (event.lengthComputable) {
|
|
65
|
+
progressUpdateCallback(event.loaded, event.total);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
62
69
|
xhr.onerror = () => {
|
|
63
70
|
if (retryCount < this.config.maxRetries) {
|
|
64
71
|
const delay = this.getDelay(this.config.retryStrategy, retryCount);
|