shared-ritm 1.3.70 → 1.3.72

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.
@@ -8,6 +8,7 @@ declare class AuthService extends ApiService {
8
8
  userInfo(): Promise<any>;
9
9
  configs(): Promise<ConfigResponse>;
10
10
  changePassword(id: string, password: string, password_confirmation: string): Promise<ChangePasswordResponse>;
11
+ changePasswordAndActivate(email: string, currentPassword: string, password: string, passwordConfirmation: string): Promise<any>;
11
12
  }
12
13
  export default function useAuthService(): AuthService;
13
14
  export {};
@@ -1,6 +1,6 @@
1
1
  import ApiService from '../settings/ApiService';
2
2
  import { ResponseApi } from '../types/Api_Service';
3
- import { Api_Metrics_Personnel_Plan, Api_Metrics_Unused_Personnel } from '@/api/types/Api_Metrics';
3
+ import { Api_Metrics_Personnel_Plan, Api_Metrics_Personnel_Plan_Project, Api_Metrics_Personnel_Plan_Project_Body, Api_Metrics_Unused_Personnel } from '@/api/types/Api_Metrics';
4
4
  declare class MetricsService extends ApiService {
5
5
  fetchPieProjects(queryString: string): Promise<ResponseApi<any>>;
6
6
  fetchPieTasks(queryString: string): Promise<ResponseApi<any>>;
@@ -31,6 +31,7 @@ declare class MetricsService extends ApiService {
31
31
  fetchPieAllTasks(queryString: string): Promise<any>;
32
32
  fetchPieAllTasksInfo(queryString: string): Promise<any>;
33
33
  fetchPersonnelPlan(params: any): Promise<Api_Metrics_Personnel_Plan>;
34
+ fetchPersonnelPlanProjects(body: Api_Metrics_Personnel_Plan_Project_Body): Promise<Api_Metrics_Personnel_Plan_Project[]>;
34
35
  }
35
36
  export default function useMetricsService(): MetricsService;
36
37
  export {};
@@ -0,0 +1,15 @@
1
+ import ApiService from '../settings/ApiService';
2
+ import { Api_User_Issue, Api_User_Issue_Body, Api_User_Issue_List_Item, Api_User_Issue_Properties } from '@/api/types/Api_User_Issue';
3
+ import { ResponseApi } from '@/api/types/Api_Service';
4
+ declare class UserIssueService extends ApiService {
5
+ createUserIssue(body: Api_User_Issue_Body): Promise<Api_User_Issue_List_Item>;
6
+ getUserIssue(id: string): Promise<Api_User_Issue>;
7
+ getUserIssueList(params: any): Promise<ResponseApi<Api_User_Issue_List_Item>>;
8
+ getProperties(): Promise<Api_User_Issue_Properties>;
9
+ deleteUserIssue(id: string): Promise<{
10
+ data: boolean;
11
+ status: number;
12
+ }>;
13
+ }
14
+ export default function useUserIssueService(): UserIssueService;
15
+ export {};
@@ -1,5 +1,5 @@
1
1
  import ApiService from '../settings/ApiService';
2
- import { Api_User, Api_User_Create, Api_User_Delete_Body, Api_User_Delete_Photos_Body, Api_User_Position, Api_User_Role, Api_User_Team, Api_User_Team_Search, Api_User_Warehouse } from '../types/Api_User';
2
+ import { Api_User, Api_User_Create, Api_User_Delete_Body, Api_User_Delete_Photos_Body, Api_User_Position, Api_User_Role, Api_User_Team, Api_User_Team_Search, Api_User_Warehouse, Api_User_Change_Password_Payload } from '../types/Api_User';
3
3
  import { ResponseApi } from '../types/Api_Service';
4
4
  declare class UserService extends ApiService {
5
5
  editUser({ id, model }: {
@@ -7,6 +7,7 @@ declare class UserService extends ApiService {
7
7
  model: any;
8
8
  }): Promise<Api_User>;
9
9
  getUser(id: string): Promise<Api_User>;
10
+ changeUserPassword(payload: Api_User_Change_Password_Payload): Promise<Api_User>;
10
11
  getUserWarehouses(params: {
11
12
  user_id: string;
12
13
  page?: number;
@@ -5,9 +5,13 @@ export declare enum ApiServiceType {
5
5
  export default class ApiService {
6
6
  private axiosInstance;
7
7
  constructor();
8
- private getToken;
8
+ private setAccessToken;
9
+ private getAccessToken;
9
10
  private removeToken;
10
- logout(): void;
11
+ private subscribeTokenRefresh;
12
+ private refresh;
13
+ private onRefreshed;
14
+ logoutUser(): any;
11
15
  private handleError;
12
16
  protected get<T>(url: string, options?: AxiosRequestConfig): Promise<T>;
13
17
  protected delete<T>(url: string, options?: AxiosRequestConfig): Promise<AxiosResponse<T, any, {}>>;
@@ -64,6 +64,15 @@ export type Api_Auth_User = {
64
64
  roles: Api_Auth_User_Role[];
65
65
  security_warnings: any[];
66
66
  teams: Api_Auth_User_Team[];
67
+ avatar: null;
68
+ change_password: null;
69
+ created_at: string;
70
+ deleted_at: null;
71
+ face_recognition_id: null;
72
+ password_change_available_at: string;
73
+ password_change_due_at: string;
74
+ password_last_changed_at: string;
75
+ updated_at: string;
67
76
  };
68
77
  export type Api_Auth_Login = {
69
78
  token: string;
@@ -73,5 +82,11 @@ export type ChangePasswordPayload = {
73
82
  password: string;
74
83
  password_confirmation: string;
75
84
  };
85
+ export type ChangePasswordAndActivatePayload = {
86
+ email: string;
87
+ currentPassword: string;
88
+ password: string;
89
+ passwordConfirmation: string;
90
+ };
76
91
  export type ChangePasswordResponse = Pick<Api_User, 'id' | 'archiveHistory' | 'assigned_tasks' | 'divisions' | 'email' | 'full_name' | 'passes' | 'personnel_number' | 'phone' | 'photos' | 'positions' | 'responsible_tasks' | 'teams' | 'warehouses'>;
77
92
  export type ConfigResponse = any;
@@ -21,3 +21,10 @@ export type Api_Metrics_Personnel_Plan = {
21
21
  fixed_repair: Api_Metrics_Personnel_Plan_Position[];
22
22
  ready: Api_Metrics_Personnel_Plan_User[];
23
23
  };
24
+ export type Api_Metrics_Personnel_Plan_Project = {
25
+ id: string;
26
+ name: string;
27
+ };
28
+ export type Api_Metrics_Personnel_Plan_Project_Body = {
29
+ repairs: string[];
30
+ };
@@ -71,6 +71,15 @@ export type Api_User = {
71
71
  id: string;
72
72
  name: string;
73
73
  }[];
74
+ password_change_available_at: string;
75
+ password_change_due_at: string;
76
+ password_last_changed_at: string;
77
+ };
78
+ export type Api_User_Change_Password_Payload = {
79
+ email: string;
80
+ password: string;
81
+ currentPassword: string;
82
+ passwordConfirmation: string;
74
83
  };
75
84
  export type Api_User_Create = {
76
85
  last_name?: string;
@@ -0,0 +1,37 @@
1
+ export type Api_User_Issue_List_Item = {
2
+ id: string;
3
+ section: string;
4
+ status: string;
5
+ type: string;
6
+ topic: string;
7
+ created_at: string;
8
+ };
9
+ export type Api_User_Issue_Msg = {
10
+ id: string;
11
+ message: string;
12
+ thread_id: string;
13
+ user: {
14
+ id: string;
15
+ full_name: string;
16
+ };
17
+ };
18
+ export type Api_User_Issue = {
19
+ id: string;
20
+ section: string;
21
+ status: string;
22
+ type: string;
23
+ topic: string;
24
+ messages: Api_User_Issue_Msg[];
25
+ };
26
+ export type Api_User_Issue_Body = {
27
+ section: string;
28
+ type: string;
29
+ topic: string;
30
+ description: string;
31
+ files?: string[];
32
+ };
33
+ export type Api_User_Issue_Properties = {
34
+ section: Record<string, string>;
35
+ status: Record<string, string>;
36
+ type: Record<string, string>;
37
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shared-ritm",
3
- "version": "1.3.70",
3
+ "version": "1.3.72",
4
4
  "private": false,
5
5
  "files": [
6
6
  "dist",
@@ -1,6 +1,7 @@
1
1
  import ApiService from '../settings/ApiService'
2
2
  import {
3
3
  Api_Auth_Login,
4
+ ChangePasswordAndActivatePayload,
4
5
  ChangePasswordPayload,
5
6
  ChangePasswordResponse,
6
7
  ConfigResponse,
@@ -9,7 +10,7 @@ import {
9
10
 
10
11
  class AuthService extends ApiService {
11
12
  public login(email: string, password: string): Promise<Api_Auth_Login> {
12
- return this.post<LoginPayload, Api_Auth_Login>(`/login`, {
13
+ return this.post<LoginPayload, Api_Auth_Login>(`/v2/login`, {
13
14
  email,
14
15
  password,
15
16
  })
@@ -26,7 +27,7 @@ class AuthService extends ApiService {
26
27
  }
27
28
 
28
29
  public logout(): Promise<Api_Auth_Login> {
29
- return this.post<null, Api_Auth_Login>(`/logout`, null)
30
+ return this.logoutUser()
30
31
  }
31
32
 
32
33
  public userInfo() {
@@ -34,15 +35,28 @@ class AuthService extends ApiService {
34
35
  }
35
36
 
36
37
  public configs(): Promise<ConfigResponse> {
37
- return this.get<ConfigResponse>(`/configs`)
38
+ return this.get<ConfigResponse>(`/v2/configs`)
38
39
  }
39
40
 
40
41
  public changePassword(id: string, password: string, password_confirmation: string) {
41
- return this.put<ChangePasswordPayload, ChangePasswordResponse>(`/users/${id}/password`, {
42
+ return this.put<ChangePasswordPayload, ChangePasswordResponse>(`/v2/auth/users/${id}/password`, {
42
43
  password,
43
44
  password_confirmation,
44
45
  })
45
46
  }
47
+ public changePasswordAndActivate(
48
+ email: string,
49
+ currentPassword: string,
50
+ password: string,
51
+ passwordConfirmation: string,
52
+ ) {
53
+ return this.post<ChangePasswordAndActivatePayload, ChangePasswordResponse>(`/v2/auth/users/activate`, {
54
+ email,
55
+ currentPassword,
56
+ password,
57
+ passwordConfirmation,
58
+ })
59
+ }
46
60
  }
47
61
 
48
62
  let api: AuthService
@@ -1,6 +1,11 @@
1
1
  import ApiService from '../settings/ApiService'
2
2
  import { ResponseApi } from '../types/Api_Service'
3
- import { Api_Metrics_Personnel_Plan, Api_Metrics_Unused_Personnel } from '@/api/types/Api_Metrics'
3
+ import {
4
+ Api_Metrics_Personnel_Plan,
5
+ Api_Metrics_Personnel_Plan_Project,
6
+ Api_Metrics_Personnel_Plan_Project_Body,
7
+ Api_Metrics_Unused_Personnel,
8
+ } from '@/api/types/Api_Metrics'
4
9
 
5
10
  class MetricsService extends ApiService {
6
11
  public async fetchPieProjects(queryString: string): Promise<ResponseApi<any>> {
@@ -115,7 +120,13 @@ class MetricsService extends ApiService {
115
120
  }
116
121
 
117
122
  public fetchPersonnelPlan(params: any): Promise<Api_Metrics_Personnel_Plan> {
118
- return this.get(`repairs/metrics/personnel_plan`, { params })
123
+ return this.get('repairs/metrics/personnel_plan', { params })
124
+ }
125
+
126
+ public fetchPersonnelPlanProjects(
127
+ body: Api_Metrics_Personnel_Plan_Project_Body,
128
+ ): Promise<Api_Metrics_Personnel_Plan_Project[]> {
129
+ return this.post('repairs/metrics/projects_with_personnel_plan', body)
119
130
  }
120
131
  }
121
132
 
@@ -9,7 +9,9 @@ import {
9
9
  Api_User_Team,
10
10
  Api_User_Team_Search,
11
11
  Api_User_Warehouse,
12
+ Api_User_Change_Password_Payload,
12
13
  } from '../types/Api_User'
14
+
13
15
  import { ResponseApi } from '../types/Api_Service'
14
16
 
15
17
  class UserService extends ApiService {
@@ -21,6 +23,10 @@ class UserService extends ApiService {
21
23
  return await this.get<Api_User>(`/admin/users/${id}`)
22
24
  }
23
25
 
26
+ public async changeUserPassword(payload: Api_User_Change_Password_Payload): Promise<Api_User> {
27
+ return await this.patch<Api_User_Change_Password_Payload, Api_User>(`/v2/auth/users/password`, payload)
28
+ }
29
+
24
30
  public async getUserWarehouses(params: {
25
31
  user_id: string
26
32
  page?: number
@@ -1,4 +1,14 @@
1
1
  import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
2
+ import { Api_Auth_Login } from '@/api/types/Api_Auth'
3
+
4
+ // eslint-disable-next-line
5
+ var isRefreshing = false
6
+ // eslint-disable-next-line
7
+ var refreshSubscribers: any[] = []
8
+
9
+ interface Api_Auth_Refresh {
10
+ accessToken: string
11
+ }
2
12
 
3
13
  export enum ApiServiceType {
4
14
  SERVICE_AUTH = 'SERVICE_AUTH',
@@ -14,14 +24,12 @@ export default class ApiService {
14
24
  'Content-Type': 'application/json',
15
25
  Accept: 'application/json',
16
26
  },
27
+ withCredentials: true,
17
28
  })
18
29
 
19
30
  this.axiosInstance.interceptors.request.use(
20
31
  (config: InternalAxiosRequestConfig) => {
21
- const token = this.getToken()
22
- if (token && config.headers) {
23
- config.headers.Authorization = `Bearer ${token}`
24
- }
32
+ config.headers.Authorization = `Bearer ${this.getAccessToken()}`
25
33
  return config
26
34
  },
27
35
  (error: AxiosError) => {
@@ -33,16 +41,53 @@ export default class ApiService {
33
41
  (response: AxiosResponse) => {
34
42
  return response.data
35
43
  },
36
- (error: AxiosError) => {
37
- if (error.response?.status === 401 || error.response?.status === 403) {
38
- this.logout()
44
+ async error => {
45
+ const originalRequest = error.config
46
+
47
+ if (
48
+ error.response?.status !== 401 ||
49
+ originalRequest.url === '/v2/auth/refresh' ||
50
+ originalRequest.url === '/v2/login' ||
51
+ originalRequest._retry
52
+ ) {
53
+ return Promise.reject(error)
54
+ }
55
+
56
+ originalRequest._retry = true
57
+
58
+ if (isRefreshing) {
59
+ return new Promise(resolve => {
60
+ this.subscribeTokenRefresh(() => resolve(this.axiosInstance(originalRequest)))
61
+ })
62
+ }
63
+
64
+ isRefreshing = true
65
+
66
+ try {
67
+ const response = await this.refresh()
68
+
69
+ const newToken = response.accessToken
70
+ if (!newToken) {
71
+ this.logoutUser()
72
+ return Promise.reject(error)
73
+ }
74
+
75
+ this.setAccessToken(newToken)
76
+ this.onRefreshed()
77
+ isRefreshing = false
78
+ return this.axiosInstance(originalRequest)
79
+ } catch (e) {
80
+ this.logoutUser()
81
+ return Promise.reject(e)
39
82
  }
40
- return Promise.reject(error)
41
83
  },
42
84
  )
43
85
  }
44
86
 
45
- private getToken() {
87
+ private setAccessToken(token: string) {
88
+ localStorage.setItem('token', token)
89
+ }
90
+ private getAccessToken() {
46
91
  return localStorage.getItem('token')
47
92
  }
48
93
 
@@ -50,7 +95,22 @@ export default class ApiService {
50
95
  localStorage.removeItem('token')
51
96
  }
52
97
 
53
- public logout(): void {
98
+ private subscribeTokenRefresh(cb: any) {
99
+ refreshSubscribers.push(cb)
100
+ }
101
+
102
+ private refresh(): Promise<Api_Auth_Refresh> {
103
+ return this.post<null, Api_Auth_Login>(`/v2/auth/refresh`, null)
104
+ }
105
+
106
+ private onRefreshed() {
107
+ refreshSubscribers.forEach(cb => cb())
108
+ refreshSubscribers = []
109
+ }
110
+
111
+ public logoutUser(): any {
112
+ isRefreshing = false
113
+ this.post<any, any>(`/v2/logout`, {})
54
114
  this.removeToken()
55
115
  window.location.href = '/sign-in'
56
116
  }
@@ -72,6 +72,15 @@ export type Api_Auth_User = {
72
72
  roles: Api_Auth_User_Role[]
73
73
  security_warnings: any[]
74
74
  teams: Api_Auth_User_Team[]
75
+ avatar: null
76
+ change_password: null
77
+ created_at: string
78
+ deleted_at: null
79
+ face_recognition_id: null
80
+ password_change_available_at: string
81
+ password_change_due_at: string
82
+ password_last_changed_at: string
83
+ updated_at: string
75
84
  }
76
85
 
77
86
  export type Api_Auth_Login = {
@@ -84,6 +93,13 @@ export type ChangePasswordPayload = {
84
93
  password_confirmation: string
85
94
  }
86
95
 
96
+ export type ChangePasswordAndActivatePayload = {
97
+ email: string
98
+ currentPassword: string
99
+ password: string
100
+ passwordConfirmation: string
101
+ }
102
+
87
103
  export type ChangePasswordResponse = Pick<
88
104
  Api_User,
89
105
  | 'id'
@@ -24,3 +24,12 @@ export type Api_Metrics_Personnel_Plan = {
24
24
  fixed_repair: Api_Metrics_Personnel_Plan_Position[]
25
25
  ready: Api_Metrics_Personnel_Plan_User[]
26
26
  }
27
+
28
+ export type Api_Metrics_Personnel_Plan_Project = {
29
+ id: string
30
+ name: string
31
+ }
32
+
33
+ export type Api_Metrics_Personnel_Plan_Project_Body = {
34
+ repairs: string[]
35
+ }
@@ -74,6 +74,16 @@ export type Api_User = {
74
74
  positions: Api_Search_User_Positions[]
75
75
  warehouses?: Partial<Api_User_Warehouse>[]
76
76
  brigades: { id: string; name: string }[]
77
+ password_change_available_at: string
78
+ password_change_due_at: string
79
+ password_last_changed_at: string
80
+ }
81
+
82
+ export type Api_User_Change_Password_Payload = {
83
+ email: string
84
+ password: string
85
+ currentPassword: string
86
+ passwordConfirmation: string
77
87
  }
78
88
 
79
89
  export type Api_User_Create = {