@go-avro/avro-js 0.0.2-beta.62 → 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.
@@ -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;
@@ -215,7 +215,7 @@ export declare class AvroQueryClient {
215
215
  username: string;
216
216
  password: string;
217
217
  code?: string;
218
- }, cancelToken?: CancelToken): Promise<Boolean>;
218
+ }, cancelToken?: CancelToken): Promise<LoginResponse>;
219
219
  setTokens(tokens: Tokens): Promise<void>;
220
220
  clearTokens(): Promise<void>;
221
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(tokens => {
66
- if (!tokens || !tokens.access_token || !tokens.refresh_token) {
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: tokens.access_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(tokens).then(() => true);
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);
@@ -257,12 +257,18 @@ export interface Group {
257
257
  time_created: number;
258
258
  time_updated: number;
259
259
  }
260
- export declare const NotificationLevel: Readonly<{
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: number[];
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
@@ -1,6 +1,10 @@
1
- export const NotificationLevel = Object.freeze({
1
+ export const NotificationLevel = {
2
2
  IN_APP: 0,
3
3
  EMAIL: 1,
4
4
  SMS: 2,
5
5
  PUSH: 3
6
- });
6
+ };
7
+ export const LoginResponse = {
8
+ SUCCESS: "SUCCESS",
9
+ NEEDS_TOTP: "NEEDS_TOTP",
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.62",
3
+ "version": "0.0.2-beta.63",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",