@go-avro/avro-js 0.0.2-beta.51 → 0.0.2-beta.53
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.
|
@@ -12,7 +12,7 @@ export interface AvroQueryClientConfig {
|
|
|
12
12
|
}
|
|
13
13
|
declare module '../client/QueryClient' {
|
|
14
14
|
interface AvroQueryClient {
|
|
15
|
-
_xhr<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number): Promise<T>;
|
|
15
|
+
_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
16
|
_fetch<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number): Promise<T>;
|
|
17
17
|
getDelay(strategy: RetryStrategy, attempt: number): number;
|
|
18
18
|
useGetRoot(): UseQueryResult<ApiInfo, StandardError>;
|
|
@@ -173,10 +173,10 @@ declare module '../client/QueryClient' {
|
|
|
173
173
|
export declare class AvroQueryClient {
|
|
174
174
|
protected config: Required<AvroQueryClientConfig>;
|
|
175
175
|
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
|
|
176
|
+
get<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
177
|
+
post<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
178
|
+
put<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
179
|
+
delete<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
180
180
|
login(data: {
|
|
181
181
|
username: string;
|
|
182
182
|
password: string;
|
|
@@ -226,7 +226,7 @@ export declare class AvroQueryClient {
|
|
|
226
226
|
query?: string;
|
|
227
227
|
offset?: number;
|
|
228
228
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
229
|
-
sendEmail(emailId: string, formData: FormData): Promise<void>;
|
|
229
|
+
sendEmail(emailId: string, formData: FormData, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<void>;
|
|
230
230
|
createBill(companyGuid: string, data: {
|
|
231
231
|
line_items: LineItem[];
|
|
232
232
|
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)
|
|
@@ -122,9 +122,9 @@ export class AvroQueryClient {
|
|
|
122
122
|
throw new StandardError(500, 'Failed to fetch routes');
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
-
sendEmail(emailId, formData) {
|
|
125
|
+
sendEmail(emailId, formData, progressUpdateCallback) {
|
|
126
126
|
try {
|
|
127
|
-
return this.
|
|
127
|
+
return this.post(`/email/${emailId}`, formData, undefined, {}, progressUpdateCallback);
|
|
128
128
|
}
|
|
129
129
|
catch (error) {
|
|
130
130
|
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);
|
|
@@ -142,15 +142,16 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
142
142
|
if (previousJob) {
|
|
143
143
|
const updatedJob = {
|
|
144
144
|
...previousJob,
|
|
145
|
-
last_event:
|
|
146
|
-
last_completed_event: (updates.time_ended ?? -1) > -1 ? updates : previousJob.last_completed_event,
|
|
145
|
+
last_event: previousEvent ? { ...previousEvent, ...updates } : previousJob.last_event,
|
|
146
|
+
last_completed_event: (updates.time_ended ?? -1) > -1 && previousEvent ? { ...previousEvent, ...updates } : previousJob.last_completed_event,
|
|
147
147
|
};
|
|
148
148
|
updatedJob.tasks = previousJob.tasks.map((task) => {
|
|
149
149
|
if (updates.tasks?.includes(task.id)) {
|
|
150
150
|
return {
|
|
151
151
|
...task,
|
|
152
|
-
last_event:
|
|
153
|
-
last_completed_event:
|
|
152
|
+
last_event: previousEvent ? { ...previousEvent, ...updates } : task.last_event,
|
|
153
|
+
last_completed_event: (updates.time_ended ?? -1) > -1 ? (previousEvent ? { ...previousEvent, ...updates } : task.last_completed_event) : task.last_completed_event,
|
|
154
|
+
overdue_time: -task.frequency - task.delay,
|
|
154
155
|
};
|
|
155
156
|
}
|
|
156
157
|
return task;
|