@go-avro/avro-js 0.0.2-beta.61 → 0.0.2-beta.63
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/client/QueryClient.d.ts +4 -3
- package/dist/client/QueryClient.js +11 -5
- package/dist/types/api.d.ts +13 -7
- package/dist/types/api.js +6 -2
- package/package.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { Socket } from 'socket.io-client';
|
|
1
2
|
import { InfiniteData, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
2
3
|
import { AuthManager } from '../auth/AuthManager';
|
|
3
|
-
import { _Event, ApiInfo, Bill, Break, Company, Job, LineItem, Route, ServiceMonth, Session, User, UserCompanyAssociation } from '../types/api';
|
|
4
|
+
import { _Event, ApiInfo, Bill, Break, Company, Job, LineItem, LoginResponse, Route, ServiceMonth, Session, User, UserCompanyAssociation } from '../types/api';
|
|
4
5
|
import { Tokens } from '../types/auth';
|
|
5
6
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
6
7
|
import { StandardError } from '../types/error';
|
|
7
|
-
import { Socket } from 'socket.io-client';
|
|
8
8
|
export interface AvroQueryClientConfig {
|
|
9
9
|
baseUrl: string;
|
|
10
10
|
authManager: AuthManager;
|
|
@@ -214,7 +214,8 @@ export declare class AvroQueryClient {
|
|
|
214
214
|
login(data: {
|
|
215
215
|
username: string;
|
|
216
216
|
password: string;
|
|
217
|
-
|
|
217
|
+
code?: string;
|
|
218
|
+
}, cancelToken?: CancelToken): Promise<LoginResponse>;
|
|
218
219
|
setTokens(tokens: Tokens): Promise<void>;
|
|
219
220
|
clearTokens(): Promise<void>;
|
|
220
221
|
useLogout(): ReturnType<typeof useMutation<void, StandardError, CancelToken | undefined>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import io from 'socket.io-client';
|
|
1
2
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { LoginResponse } from '../types/api';
|
|
2
4
|
import { StandardError } from '../types/error';
|
|
3
|
-
import io from 'socket.io-client';
|
|
4
5
|
export class AvroQueryClient {
|
|
5
6
|
constructor(config) {
|
|
6
7
|
this.config = {
|
|
@@ -62,15 +63,20 @@ export class AvroQueryClient {
|
|
|
62
63
|
}
|
|
63
64
|
login(data, cancelToken) {
|
|
64
65
|
return this._fetch('POST', '/login', data, cancelToken)
|
|
65
|
-
.then(
|
|
66
|
-
if (!
|
|
66
|
+
.then(resp => {
|
|
67
|
+
if (!resp || !('access_token' in resp)) {
|
|
68
|
+
if (resp.msg === "TOTP email sent") {
|
|
69
|
+
return LoginResponse.NEEDS_TOTP;
|
|
70
|
+
}
|
|
67
71
|
throw new StandardError(401, 'Invalid login response');
|
|
68
72
|
}
|
|
69
|
-
this.socket.auth = { token:
|
|
73
|
+
this.socket.auth = { token: resp.access_token };
|
|
70
74
|
if (!this.socket.connected) {
|
|
71
75
|
this.socket.connect();
|
|
72
76
|
}
|
|
73
|
-
return this.config.authManager.setTokens(
|
|
77
|
+
return this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token }).then(() => {
|
|
78
|
+
return LoginResponse.SUCCESS;
|
|
79
|
+
});
|
|
74
80
|
})
|
|
75
81
|
.catch(err => {
|
|
76
82
|
console.error('Login failed:', err);
|
package/dist/types/api.d.ts
CHANGED
|
@@ -257,12 +257,18 @@ export interface Group {
|
|
|
257
257
|
time_created: number;
|
|
258
258
|
time_updated: number;
|
|
259
259
|
}
|
|
260
|
-
export declare const NotificationLevel:
|
|
261
|
-
IN_APP: 0;
|
|
262
|
-
EMAIL: 1;
|
|
263
|
-
SMS: 2;
|
|
264
|
-
PUSH: 3;
|
|
265
|
-
}
|
|
260
|
+
export declare const NotificationLevel: {
|
|
261
|
+
readonly IN_APP: 0;
|
|
262
|
+
readonly EMAIL: 1;
|
|
263
|
+
readonly SMS: 2;
|
|
264
|
+
readonly PUSH: 3;
|
|
265
|
+
};
|
|
266
|
+
export type NotificationLevel = typeof NotificationLevel[keyof typeof NotificationLevel];
|
|
267
|
+
export declare const LoginResponse: {
|
|
268
|
+
readonly SUCCESS: "SUCCESS";
|
|
269
|
+
readonly NEEDS_TOTP: "NEEDS_TOTP";
|
|
270
|
+
};
|
|
271
|
+
export type LoginResponse = typeof LoginResponse[keyof typeof LoginResponse];
|
|
266
272
|
export interface UserCompanyAssociation {
|
|
267
273
|
id: string;
|
|
268
274
|
user: User;
|
|
@@ -271,7 +277,7 @@ export interface UserCompanyAssociation {
|
|
|
271
277
|
effective_permissions: string[];
|
|
272
278
|
time_created: number | null;
|
|
273
279
|
time_updated: number | null;
|
|
274
|
-
notification_setting:
|
|
280
|
+
notification_setting: (typeof NotificationLevel)[];
|
|
275
281
|
share_email_company_wide: boolean;
|
|
276
282
|
notifications: Notification[];
|
|
277
283
|
groups: string[];
|
package/dist/types/api.js
CHANGED