shared-ritm 1.3.123 → 1.3.125

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.
Files changed (82) hide show
  1. package/dist/index.css +1 -1
  2. package/dist/shared-ritm.es.js +20 -14
  3. package/dist/shared-ritm.umd.js +3 -3
  4. package/dist/types/api/services/MetricsService.d.ts +2 -0
  5. package/package.json +70 -70
  6. package/src/App.vue +2461 -2461
  7. package/src/api/services/AuthService.ts +67 -67
  8. package/src/api/services/ControlsService.ts +100 -100
  9. package/src/api/services/EquipmentService.ts +68 -68
  10. package/src/api/services/GanttService.ts +58 -58
  11. package/src/api/services/InstrumentsService.ts +76 -76
  12. package/src/api/services/MetricsService.ts +6 -0
  13. package/src/api/services/RepairsService.ts +111 -111
  14. package/src/api/services/TasksService.ts +165 -165
  15. package/src/api/services/UserIssueService.ts +32 -32
  16. package/src/api/services/UserService.ts +129 -129
  17. package/src/api/services/VideoService.ts +118 -118
  18. package/src/api/settings/ApiService.ts +185 -185
  19. package/src/api/types/Api_Auth.ts +121 -121
  20. package/src/api/types/Api_Controls.ts +112 -112
  21. package/src/api/types/Api_Equipment.ts +54 -54
  22. package/src/api/types/Api_Instruments.ts +182 -182
  23. package/src/api/types/Api_Metrics.ts +89 -89
  24. package/src/api/types/Api_Repairs.ts +200 -200
  25. package/src/api/types/Api_Search.ts +81 -81
  26. package/src/api/types/Api_Tasks.ts +378 -378
  27. package/src/api/types/Api_User.ts +161 -161
  28. package/src/api/types/Api_User_Issue.ts +36 -36
  29. package/src/api/types/Api_Video.ts +244 -244
  30. package/src/common/app-button/Button.stories.ts +369 -369
  31. package/src/common/app-checkbox/AppCheckbox.vue +31 -31
  32. package/src/common/app-checkbox/Checkbox.stories.ts +252 -252
  33. package/src/common/app-date-picker/DatePicker.stories.ts +66 -66
  34. package/src/common/app-datepicker/Datepicker.stories.ts +145 -145
  35. package/src/common/app-dialogs/AppConfirmDialog.vue +109 -109
  36. package/src/common/app-dialogs/Confirm.stories.ts +93 -93
  37. package/src/common/app-dropdown/Dropdown.stories.ts +94 -94
  38. package/src/common/app-file/File.stories.ts +104 -104
  39. package/src/common/app-icon/AppIcon.vue +110 -110
  40. package/src/common/app-icon/Icon.stories.ts +91 -91
  41. package/src/common/app-input/AppInput.vue +150 -150
  42. package/src/common/app-input/Input.stories.ts +160 -160
  43. package/src/common/app-input-new/AppInputNew.vue +181 -181
  44. package/src/common/app-input-new/InputNew.stories.ts +240 -240
  45. package/src/common/app-input-search/InputSearch.stories.ts +149 -149
  46. package/src/common/app-layout/components/AppLayoutHeader.vue +289 -289
  47. package/src/common/app-loader/Loader.stories.ts +114 -114
  48. package/src/common/app-modal/index.vue +101 -101
  49. package/src/common/app-select/AppSelect.vue +159 -159
  50. package/src/common/app-select/Select.stories.ts +155 -155
  51. package/src/common/app-sheet-new/AppSheetNew.vue +254 -254
  52. package/src/common/app-sidebar/AppSidebar.vue +177 -177
  53. package/src/common/app-table/AppTable.vue +313 -313
  54. package/src/common/app-table/components/ModalSelect.stories.ts +323 -323
  55. package/src/common/app-table/components/ModalSelect.vue +302 -302
  56. package/src/common/app-table/components/TableModal.vue +369 -369
  57. package/src/common/app-table/controllers/useColumnSelector.ts +45 -45
  58. package/src/common/app-table/controllers/useTableModel.ts +98 -98
  59. package/src/common/app-toggle/AppToggle.vue +12 -12
  60. package/src/common/app-toggle/Toggle.stories.ts +245 -245
  61. package/src/common/app-wrapper/AppWrapper.vue +31 -31
  62. package/src/configs/storybook.ts +14 -14
  63. package/src/icons/sidebar/user-requests-icon.vue +23 -23
  64. package/src/index.ts +134 -134
  65. package/src/shared/styles/general.css +140 -140
  66. package/src/styles/variables.sass +12 -12
  67. package/src/utils/files.ts +38 -38
  68. package/src/utils/helpers.ts +59 -59
  69. package/dist/types/api/services/PhotoService.d.ts +0 -40
  70. package/dist/types/stories/Button.stories.d.ts +0 -13
  71. package/dist/types/stories/Checkbox.stories.d.ts +0 -7
  72. package/dist/types/stories/Confirm.stories.d.ts +0 -8
  73. package/dist/types/stories/DatePicker.stories.d.ts +0 -8
  74. package/dist/types/stories/Dropdown.stories.d.ts +0 -8
  75. package/dist/types/stories/File.stories.d.ts +0 -8
  76. package/dist/types/stories/Icon.stories.d.ts +0 -7
  77. package/dist/types/stories/Input.stories.d.ts +0 -11
  78. package/dist/types/stories/InputNew.stories.d.ts +0 -12
  79. package/dist/types/stories/InputSearch.stories.d.ts +0 -10
  80. package/dist/types/stories/Loader.stories.d.ts +0 -8
  81. package/dist/types/stories/Select.stories.d.ts +0 -7
  82. package/dist/types/stories/Toggle.stories.d.ts +0 -8
@@ -1,118 +1,118 @@
1
- import ApiService from '../settings/ApiService'
2
- import { ResponseApi } from '@/api/types/Api_Service'
3
- import {
4
- Api_Video_Combination,
5
- Api_Video_Source_By_Repair,
6
- Api_Video_Source_Create,
7
- Api_Video_Source_Economics,
8
- Api_Video_Source_Search,
9
- Api_Video_Training_Status,
10
- Api_Work_Zone,
11
- Api_Work_Zone_Search,
12
- } from '@/api/types/Api_Video'
13
-
14
- class VideoService extends ApiService {
15
- public async startVideoAnalytics(): Promise<boolean> {
16
- return await this.post('/statanly/start', null)
17
- }
18
-
19
- public reloadVideoAnalytics(ids: string[]): Promise<any> {
20
- return this.post('/horizon/video-source/reload', { video_source_ids: ids })
21
- }
22
-
23
- public hardReloadStream(): Promise<any> {
24
- return this.post('horizon/video-source/streams/add', null)
25
- }
26
-
27
- public async fetchWorkZones(params?: any): Promise<ResponseApi<Api_Work_Zone_Search[]>> {
28
- return await this.get('/search/work_zones', { params })
29
- }
30
-
31
- public async fetchWorkZone(id: string): Promise<ResponseApi<Api_Work_Zone>> {
32
- return await this.get(`/work_zone/get_work_zone/${id}`)
33
- }
34
-
35
- public async editWorkZone(id: string, body: { title: string }): Promise<{ data: Api_Work_Zone; status: number }> {
36
- return await this.put(`/admin/work-zones/${id}`, body)
37
- }
38
-
39
- public async deleteWorkZone(id: string): Promise<{ data: boolean; status: number }> {
40
- return await this.delete(`/admin/work-zones/${id}`)
41
- }
42
-
43
- public async fetchVideoSources(params?: any): Promise<ResponseApi<Api_Video_Source_Search[]>> {
44
- return await this.get('/search/video_sources/list', { params })
45
- }
46
-
47
- public async fetchVideoSourceEconomics(params?: any): Promise<ResponseApi<Api_Video_Source_Economics>> {
48
- return await this.get('horizon/video-source/economics', { params })
49
- }
50
-
51
- public async createVideoSource(body: Api_Video_Source_Create): Promise<Api_Video_Source_Search> {
52
- return await this.post('horizon/video-source', body)
53
- }
54
-
55
- public async editVideoSource(id: string, body: Partial<Api_Video_Source_Create>): Promise<Api_Video_Source_Search> {
56
- return await this.put(`/horizon/video-source/${id}`, body)
57
- }
58
-
59
- public async deleteVideoSource(id: string): Promise<void> {
60
- await this.delete(`/horizon/video-source/${id}`)
61
- }
62
-
63
- public async fetchListRepairsVideoSource(params?: any): Promise<Api_Video_Source_By_Repair[]> {
64
- return await this.get('work_zone/get_list_video_source_by_repair', { params })
65
- }
66
-
67
- public async sendCombination(body: { cameras_id: string[] }): Promise<any> {
68
- return await this.post('horizon/video-source/training', body)
69
- }
70
-
71
- public async saveCombination(body: any): Promise<any> {
72
- return await this.post('horizon/video-source/bind', body)
73
- }
74
-
75
- public async fetchCombination(params?: Record<string, string>): Promise<Api_Video_Combination> {
76
- return await this.get('horizon/video-source/bind/show', { params })
77
- }
78
-
79
- public async startTraining(body: { cameras_id: string[] }): Promise<any> {
80
- return await this.post('horizon/video-source/training/start', body)
81
- }
82
-
83
- public async stopTraining(body: { cameras_id: string[] }): Promise<any> {
84
- return await this.post('horizon/video-source/training/stop', body)
85
- }
86
-
87
- public async fetchTrainingInfo(params?: Record<string, string>): Promise<any> {
88
- return await this.get('horizon/video-source/training/info', { params })
89
- }
90
-
91
- public async fetchTrainingStatus(params?: Record<string, string>): Promise<Api_Video_Training_Status> {
92
- return await this.get('horizon/video-source/training/status', { params })
93
- }
94
-
95
- public async fetchVisualizationDataLink(params?: Record<string, string>): Promise<string> {
96
- return await this.get('horizon/video-source/link/video/training', { params })
97
- }
98
-
99
- public async updateVisualizationData(params?: Record<string, string>): Promise<number> {
100
- return await this.get('horizon/video-source/download/video/training', { params })
101
- }
102
-
103
- public async deleteFrameFromVideo(id: string): Promise<void> {
104
- await this.delete(`horizon/video-source/delete/fragment/video/training/${id}`)
105
- }
106
-
107
- // Для тестирования ws видеостены
108
- public async sendEvent(params?: Record<string, any>): Promise<number> {
109
- return await this.post('alerts_callback_url', params)
110
- }
111
- }
112
-
113
- let api: VideoService
114
-
115
- export default function useVideoService() {
116
- if (!api) api = new VideoService()
117
- return api
118
- }
1
+ import ApiService from '../settings/ApiService'
2
+ import { ResponseApi } from '@/api/types/Api_Service'
3
+ import {
4
+ Api_Video_Combination,
5
+ Api_Video_Source_By_Repair,
6
+ Api_Video_Source_Create,
7
+ Api_Video_Source_Economics,
8
+ Api_Video_Source_Search,
9
+ Api_Video_Training_Status,
10
+ Api_Work_Zone,
11
+ Api_Work_Zone_Search,
12
+ } from '@/api/types/Api_Video'
13
+
14
+ class VideoService extends ApiService {
15
+ public async startVideoAnalytics(): Promise<boolean> {
16
+ return await this.post('/statanly/start', null)
17
+ }
18
+
19
+ public reloadVideoAnalytics(ids: string[]): Promise<any> {
20
+ return this.post('/horizon/video-source/reload', { video_source_ids: ids })
21
+ }
22
+
23
+ public hardReloadStream(): Promise<any> {
24
+ return this.post('horizon/video-source/streams/add', null)
25
+ }
26
+
27
+ public async fetchWorkZones(params?: any): Promise<ResponseApi<Api_Work_Zone_Search[]>> {
28
+ return await this.get('/search/work_zones', { params })
29
+ }
30
+
31
+ public async fetchWorkZone(id: string): Promise<ResponseApi<Api_Work_Zone>> {
32
+ return await this.get(`/work_zone/get_work_zone/${id}`)
33
+ }
34
+
35
+ public async editWorkZone(id: string, body: { title: string }): Promise<{ data: Api_Work_Zone; status: number }> {
36
+ return await this.put(`/admin/work-zones/${id}`, body)
37
+ }
38
+
39
+ public async deleteWorkZone(id: string): Promise<{ data: boolean; status: number }> {
40
+ return await this.delete(`/admin/work-zones/${id}`)
41
+ }
42
+
43
+ public async fetchVideoSources(params?: any): Promise<ResponseApi<Api_Video_Source_Search[]>> {
44
+ return await this.get('/search/video_sources/list', { params })
45
+ }
46
+
47
+ public async fetchVideoSourceEconomics(params?: any): Promise<ResponseApi<Api_Video_Source_Economics>> {
48
+ return await this.get('horizon/video-source/economics', { params })
49
+ }
50
+
51
+ public async createVideoSource(body: Api_Video_Source_Create): Promise<Api_Video_Source_Search> {
52
+ return await this.post('horizon/video-source', body)
53
+ }
54
+
55
+ public async editVideoSource(id: string, body: Partial<Api_Video_Source_Create>): Promise<Api_Video_Source_Search> {
56
+ return await this.put(`/horizon/video-source/${id}`, body)
57
+ }
58
+
59
+ public async deleteVideoSource(id: string): Promise<void> {
60
+ await this.delete(`/horizon/video-source/${id}`)
61
+ }
62
+
63
+ public async fetchListRepairsVideoSource(params?: any): Promise<Api_Video_Source_By_Repair[]> {
64
+ return await this.get('work_zone/get_list_video_source_by_repair', { params })
65
+ }
66
+
67
+ public async sendCombination(body: { cameras_id: string[] }): Promise<any> {
68
+ return await this.post('horizon/video-source/training', body)
69
+ }
70
+
71
+ public async saveCombination(body: any): Promise<any> {
72
+ return await this.post('horizon/video-source/bind', body)
73
+ }
74
+
75
+ public async fetchCombination(params?: Record<string, string>): Promise<Api_Video_Combination> {
76
+ return await this.get('horizon/video-source/bind/show', { params })
77
+ }
78
+
79
+ public async startTraining(body: { cameras_id: string[] }): Promise<any> {
80
+ return await this.post('horizon/video-source/training/start', body)
81
+ }
82
+
83
+ public async stopTraining(body: { cameras_id: string[] }): Promise<any> {
84
+ return await this.post('horizon/video-source/training/stop', body)
85
+ }
86
+
87
+ public async fetchTrainingInfo(params?: Record<string, string>): Promise<any> {
88
+ return await this.get('horizon/video-source/training/info', { params })
89
+ }
90
+
91
+ public async fetchTrainingStatus(params?: Record<string, string>): Promise<Api_Video_Training_Status> {
92
+ return await this.get('horizon/video-source/training/status', { params })
93
+ }
94
+
95
+ public async fetchVisualizationDataLink(params?: Record<string, string>): Promise<string> {
96
+ return await this.get('horizon/video-source/link/video/training', { params })
97
+ }
98
+
99
+ public async updateVisualizationData(params?: Record<string, string>): Promise<number> {
100
+ return await this.get('horizon/video-source/download/video/training', { params })
101
+ }
102
+
103
+ public async deleteFrameFromVideo(id: string): Promise<void> {
104
+ await this.delete(`horizon/video-source/delete/fragment/video/training/${id}`)
105
+ }
106
+
107
+ // Для тестирования ws видеостены
108
+ public async sendEvent(params?: Record<string, any>): Promise<number> {
109
+ return await this.post('alerts_callback_url', params)
110
+ }
111
+ }
112
+
113
+ let api: VideoService
114
+
115
+ export default function useVideoService() {
116
+ if (!api) api = new VideoService()
117
+ return api
118
+ }
@@ -1,185 +1,185 @@
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
- }
12
-
13
- export enum ApiServiceType {
14
- SERVICE_AUTH = 'SERVICE_AUTH',
15
- }
16
-
17
- export default class ApiService {
18
- private axiosInstance: AxiosInstance
19
-
20
- constructor() {
21
- this.axiosInstance = axios.create({
22
- //@ts-ignore
23
- baseURL: window.__ENV__.VUE_APP_BACKEND,
24
- headers: {
25
- 'Content-Type': 'application/json',
26
- Accept: 'application/json',
27
- },
28
- withCredentials: true,
29
- })
30
-
31
- this.axiosInstance.interceptors.request.use(
32
- (config: InternalAxiosRequestConfig) => {
33
- config.headers.Authorization = `Bearer ${this.getAccessToken()}`
34
- return config
35
- },
36
- (error: AxiosError) => {
37
- return Promise.reject(error)
38
- },
39
- )
40
-
41
- this.axiosInstance.interceptors.response.use(
42
- (response: AxiosResponse) => {
43
- return response.data
44
- },
45
- async error => {
46
- const originalRequest = error.config
47
-
48
- if (
49
- error.response?.status !== 401 ||
50
- originalRequest.url === '/v2/auth/refresh' ||
51
- originalRequest.url === '/v2/login' ||
52
- originalRequest._retry
53
- ) {
54
- return Promise.reject(error)
55
- }
56
-
57
- originalRequest._retry = true
58
-
59
- if (isRefreshing) {
60
- return new Promise(resolve => {
61
- this.subscribeTokenRefresh(() => resolve(this.axiosInstance(originalRequest)))
62
- })
63
- }
64
-
65
- isRefreshing = true
66
-
67
- try {
68
- const response = await this.refresh()
69
-
70
- const newToken = response.accessToken
71
- if (!newToken) {
72
- this.logoutUser()
73
- return Promise.reject(error)
74
- }
75
-
76
- this.setAccessToken(newToken)
77
- this.onRefreshed()
78
- isRefreshing = false
79
- return this.axiosInstance(originalRequest)
80
- } catch (e) {
81
- this.logoutUser()
82
- return Promise.reject(e)
83
- }
84
- },
85
- )
86
- }
87
-
88
- private setAccessToken(token: string) {
89
- localStorage.setItem('token', token)
90
- }
91
- private getAccessToken() {
92
- return localStorage.getItem('token')
93
- }
94
-
95
- private removeToken() {
96
- localStorage.removeItem('token')
97
- }
98
-
99
- private subscribeTokenRefresh(cb: any) {
100
- refreshSubscribers.push(cb)
101
- }
102
-
103
- private refresh(): Promise<Api_Auth_Refresh> {
104
- return this.post<null, Api_Auth_Login>(`/v2/auth/refresh`, null)
105
- }
106
-
107
- private onRefreshed() {
108
- refreshSubscribers.forEach(cb => cb())
109
- refreshSubscribers = []
110
- }
111
-
112
- public logoutUser(): any {
113
- isRefreshing = false
114
- this.post<any, any>(`/v2/logout`, null)
115
- this.removeToken()
116
- window.location.href = '/sign-in'
117
- }
118
-
119
- private handleError(error: AxiosError): void {
120
- if (error.response) {
121
- console.error('API Error:', error.response.status, error.response.data)
122
- } else if (error.request) {
123
- console.error('No response received:', error.request)
124
- } else {
125
- console.error('Error during request setup:', error.message)
126
- }
127
- }
128
-
129
- protected async get<T>(url: string, options?: AxiosRequestConfig) {
130
- try {
131
- const response: AxiosResponse<T> = await this.axiosInstance.get<T>(url, options)
132
- if (response?.data === false) return false as unknown as T
133
-
134
- return response?.data ?? (response as unknown as T)
135
- } catch (error) {
136
- const axiosError = error as AxiosError
137
- this.handleError(axiosError)
138
- throw error
139
- }
140
- }
141
-
142
- protected async delete<T>(url: string, options?: AxiosRequestConfig) {
143
- try {
144
- return await this.axiosInstance.delete<T>(url, options)
145
- } catch (error) {
146
- const axiosError = error as AxiosError
147
- this.handleError(axiosError)
148
- throw error
149
- }
150
- }
151
-
152
- protected async post<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
153
- try {
154
- const response: AxiosResponse<T2> = await this.axiosInstance.post<T1, AxiosResponse<T2>>(url, payload, options)
155
- if (response?.data === false) return false
156
- return response?.data || (response as any)
157
- } catch (error) {
158
- const axiosError = error as AxiosError
159
- this.handleError(axiosError)
160
- throw error
161
- }
162
- }
163
-
164
- protected async patch<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig): Promise<T2> {
165
- try {
166
- const response: AxiosResponse<T2> = await this.axiosInstance.patch<T1, AxiosResponse<T2>>(url, payload, options)
167
- return response.data
168
- } catch (error) {
169
- const axiosError = error as AxiosError
170
- this.handleError(axiosError)
171
- throw error
172
- }
173
- }
174
-
175
- protected async put<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
176
- try {
177
- const response: AxiosResponse<T2> = await this.axiosInstance.put<T1, AxiosResponse<T2>>(url, payload, options)
178
- return response.data
179
- } catch (error) {
180
- const axiosError = error as AxiosError
181
- this.handleError(axiosError)
182
- throw error
183
- }
184
- }
185
- }
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
+ }
12
+
13
+ export enum ApiServiceType {
14
+ SERVICE_AUTH = 'SERVICE_AUTH',
15
+ }
16
+
17
+ export default class ApiService {
18
+ private axiosInstance: AxiosInstance
19
+
20
+ constructor() {
21
+ this.axiosInstance = axios.create({
22
+ //@ts-ignore
23
+ baseURL: window.__ENV__.VUE_APP_BACKEND,
24
+ headers: {
25
+ 'Content-Type': 'application/json',
26
+ Accept: 'application/json',
27
+ },
28
+ withCredentials: true,
29
+ })
30
+
31
+ this.axiosInstance.interceptors.request.use(
32
+ (config: InternalAxiosRequestConfig) => {
33
+ config.headers.Authorization = `Bearer ${this.getAccessToken()}`
34
+ return config
35
+ },
36
+ (error: AxiosError) => {
37
+ return Promise.reject(error)
38
+ },
39
+ )
40
+
41
+ this.axiosInstance.interceptors.response.use(
42
+ (response: AxiosResponse) => {
43
+ return response.data
44
+ },
45
+ async error => {
46
+ const originalRequest = error.config
47
+
48
+ if (
49
+ error.response?.status !== 401 ||
50
+ originalRequest.url === '/v2/auth/refresh' ||
51
+ originalRequest.url === '/v2/login' ||
52
+ originalRequest._retry
53
+ ) {
54
+ return Promise.reject(error)
55
+ }
56
+
57
+ originalRequest._retry = true
58
+
59
+ if (isRefreshing) {
60
+ return new Promise(resolve => {
61
+ this.subscribeTokenRefresh(() => resolve(this.axiosInstance(originalRequest)))
62
+ })
63
+ }
64
+
65
+ isRefreshing = true
66
+
67
+ try {
68
+ const response = await this.refresh()
69
+
70
+ const newToken = response.accessToken
71
+ if (!newToken) {
72
+ this.logoutUser()
73
+ return Promise.reject(error)
74
+ }
75
+
76
+ this.setAccessToken(newToken)
77
+ this.onRefreshed()
78
+ isRefreshing = false
79
+ return this.axiosInstance(originalRequest)
80
+ } catch (e) {
81
+ this.logoutUser()
82
+ return Promise.reject(e)
83
+ }
84
+ },
85
+ )
86
+ }
87
+
88
+ private setAccessToken(token: string) {
89
+ localStorage.setItem('token', token)
90
+ }
91
+ private getAccessToken() {
92
+ return localStorage.getItem('token')
93
+ }
94
+
95
+ private removeToken() {
96
+ localStorage.removeItem('token')
97
+ }
98
+
99
+ private subscribeTokenRefresh(cb: any) {
100
+ refreshSubscribers.push(cb)
101
+ }
102
+
103
+ private refresh(): Promise<Api_Auth_Refresh> {
104
+ return this.post<null, Api_Auth_Login>(`/v2/auth/refresh`, null)
105
+ }
106
+
107
+ private onRefreshed() {
108
+ refreshSubscribers.forEach(cb => cb())
109
+ refreshSubscribers = []
110
+ }
111
+
112
+ public logoutUser(): any {
113
+ isRefreshing = false
114
+ this.post<any, any>(`/v2/logout`, null)
115
+ this.removeToken()
116
+ window.location.href = '/sign-in'
117
+ }
118
+
119
+ private handleError(error: AxiosError): void {
120
+ if (error.response) {
121
+ console.error('API Error:', error.response.status, error.response.data)
122
+ } else if (error.request) {
123
+ console.error('No response received:', error.request)
124
+ } else {
125
+ console.error('Error during request setup:', error.message)
126
+ }
127
+ }
128
+
129
+ protected async get<T>(url: string, options?: AxiosRequestConfig) {
130
+ try {
131
+ const response: AxiosResponse<T> = await this.axiosInstance.get<T>(url, options)
132
+ if (response?.data === false) return false as unknown as T
133
+
134
+ return response?.data ?? (response as unknown as T)
135
+ } catch (error) {
136
+ const axiosError = error as AxiosError
137
+ this.handleError(axiosError)
138
+ throw error
139
+ }
140
+ }
141
+
142
+ protected async delete<T>(url: string, options?: AxiosRequestConfig) {
143
+ try {
144
+ return await this.axiosInstance.delete<T>(url, options)
145
+ } catch (error) {
146
+ const axiosError = error as AxiosError
147
+ this.handleError(axiosError)
148
+ throw error
149
+ }
150
+ }
151
+
152
+ protected async post<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
153
+ try {
154
+ const response: AxiosResponse<T2> = await this.axiosInstance.post<T1, AxiosResponse<T2>>(url, payload, options)
155
+ if (response?.data === false) return false
156
+ return response?.data || (response as any)
157
+ } catch (error) {
158
+ const axiosError = error as AxiosError
159
+ this.handleError(axiosError)
160
+ throw error
161
+ }
162
+ }
163
+
164
+ protected async patch<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig): Promise<T2> {
165
+ try {
166
+ const response: AxiosResponse<T2> = await this.axiosInstance.patch<T1, AxiosResponse<T2>>(url, payload, options)
167
+ return response.data
168
+ } catch (error) {
169
+ const axiosError = error as AxiosError
170
+ this.handleError(axiosError)
171
+ throw error
172
+ }
173
+ }
174
+
175
+ protected async put<T1, T2>(url: string, payload: T1, options?: AxiosRequestConfig) {
176
+ try {
177
+ const response: AxiosResponse<T2> = await this.axiosInstance.put<T1, AxiosResponse<T2>>(url, payload, options)
178
+ return response.data
179
+ } catch (error) {
180
+ const axiosError = error as AxiosError
181
+ this.handleError(axiosError)
182
+ throw error
183
+ }
184
+ }
185
+ }