@ubkinfotech/tecaher-erp 0.1.0
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/LICENSE +21 -0
- package/README.md +413 -0
- package/lib/commonjs/core/api/apiClient.js +38 -0
- package/lib/commonjs/core/api/endpoints.js +139 -0
- package/lib/commonjs/core/api/interceptor.js +64 -0
- package/lib/commonjs/core/auth/authContext.js +30 -0
- package/lib/commonjs/core/auth/authService.js +12 -0
- package/lib/commonjs/core/hooks/useApiQuery.js +26 -0
- package/lib/commonjs/core/provider/ERPProvider.js +63 -0
- package/lib/commonjs/core/provider/types.js +5 -0
- package/lib/commonjs/core/provider/useERP.js +17 -0
- package/lib/commonjs/core/types/api.js +1 -0
- package/lib/commonjs/index.js +110 -0
- package/lib/commonjs/modules/assignment/hooks/useAssignmentList.js +16 -0
- package/lib/commonjs/modules/assignment/hooks/useHomeworkDetails.js +16 -0
- package/lib/commonjs/modules/assignment/hooks/useHomeworkSubmissions.js +16 -0
- package/lib/commonjs/modules/assignment/screens/AssignmentScreen.js +2615 -0
- package/lib/commonjs/modules/assignment/services/assignmentService.js +75 -0
- package/lib/commonjs/modules/attendance/hooks/useAttendance.js +16 -0
- package/lib/commonjs/modules/attendance/screens/AttendanceScreen.js +866 -0
- package/lib/commonjs/modules/attendance/services/attendanceService.js +31 -0
- package/lib/commonjs/modules/leaveRequest/hooks/useLeaveRequests.js +16 -0
- package/lib/commonjs/modules/leaveRequest/screens/LeaveRequestScreen.js +991 -0
- package/lib/commonjs/modules/leaveRequest/services/leaveRequestService.js +42 -0
- package/lib/commonjs/modules/marks/hooks/useMarks.js +14 -0
- package/lib/commonjs/modules/marks/screens/MarksScreen.js +1621 -0
- package/lib/commonjs/modules/marks/services/marksService.js +71 -0
- package/lib/commonjs/modules/myAttendance/hooks/useMyAttendance.js +16 -0
- package/lib/commonjs/modules/myAttendance/screens/MyAttendanceScreen.js +357 -0
- package/lib/commonjs/modules/myAttendance/services/myAttendanceService.js +11 -0
- package/lib/commonjs/modules/notes/hooks/useNotes.js +16 -0
- package/lib/commonjs/modules/notes/screens/NotesScreen.js +1287 -0
- package/lib/commonjs/modules/notes/services/notesService.js +65 -0
- package/lib/commonjs/modules/noticeboard/hooks/useNoticeboard.js +16 -0
- package/lib/commonjs/modules/noticeboard/screens/NoticeBoardScreen.js +381 -0
- package/lib/commonjs/modules/noticeboard/services/noticeboardService.js +16 -0
- package/lib/commonjs/modules/notification/hooks/useNotifications.js +16 -0
- package/lib/commonjs/modules/notification/screens/NotificationScreen.js +186 -0
- package/lib/commonjs/modules/notification/services/notificationService.js +16 -0
- package/lib/commonjs/modules/promoteStudent/hooks/usePromoteStudent.js +16 -0
- package/lib/commonjs/modules/promoteStudent/screens/PromoteStudentScreen.js +644 -0
- package/lib/commonjs/modules/promoteStudent/services/promoteStudentService.js +36 -0
- package/lib/commonjs/modules/timetable/hooks/useTimeTable.js +14 -0
- package/lib/commonjs/modules/timetable/screens/TimeTableScreen.js +258 -0
- package/lib/commonjs/modules/timetable/services/timetableService.js +16 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/shared/empty-states/EmptyState.js +45 -0
- package/lib/commonjs/shared/empty-states/ErrorState.js +45 -0
- package/lib/commonjs/shared/loaders/LoadingState.js +25 -0
- package/lib/commonjs/shared/theme/theme.js +22 -0
- package/lib/module/core/api/apiClient.js +32 -0
- package/lib/module/core/api/endpoints.js +135 -0
- package/lib/module/core/api/interceptor.js +60 -0
- package/lib/module/core/auth/authContext.js +23 -0
- package/lib/module/core/auth/authService.js +8 -0
- package/lib/module/core/hooks/useApiQuery.js +21 -0
- package/lib/module/core/provider/ERPProvider.js +56 -0
- package/lib/module/core/provider/types.js +3 -0
- package/lib/module/core/provider/useERP.js +12 -0
- package/lib/module/core/types/api.js +1 -0
- package/lib/module/index.js +17 -0
- package/lib/module/modules/assignment/hooks/useAssignmentList.js +12 -0
- package/lib/module/modules/assignment/hooks/useHomeworkDetails.js +12 -0
- package/lib/module/modules/assignment/hooks/useHomeworkSubmissions.js +12 -0
- package/lib/module/modules/assignment/screens/AssignmentScreen.js +2609 -0
- package/lib/module/modules/assignment/services/assignmentService.js +62 -0
- package/lib/module/modules/attendance/hooks/useAttendance.js +12 -0
- package/lib/module/modules/attendance/screens/AttendanceScreen.js +860 -0
- package/lib/module/modules/attendance/services/attendanceService.js +23 -0
- package/lib/module/modules/leaveRequest/hooks/useLeaveRequests.js +12 -0
- package/lib/module/modules/leaveRequest/screens/LeaveRequestScreen.js +985 -0
- package/lib/module/modules/leaveRequest/services/leaveRequestService.js +35 -0
- package/lib/module/modules/marks/hooks/useMarks.js +10 -0
- package/lib/module/modules/marks/screens/MarksScreen.js +1615 -0
- package/lib/module/modules/marks/services/marksService.js +55 -0
- package/lib/module/modules/myAttendance/hooks/useMyAttendance.js +12 -0
- package/lib/module/modules/myAttendance/screens/MyAttendanceScreen.js +351 -0
- package/lib/module/modules/myAttendance/services/myAttendanceService.js +7 -0
- package/lib/module/modules/notes/hooks/useNotes.js +12 -0
- package/lib/module/modules/notes/screens/NotesScreen.js +1281 -0
- package/lib/module/modules/notes/services/notesService.js +54 -0
- package/lib/module/modules/noticeboard/hooks/useNoticeboard.js +12 -0
- package/lib/module/modules/noticeboard/screens/NoticeBoardScreen.js +375 -0
- package/lib/module/modules/noticeboard/services/noticeboardService.js +12 -0
- package/lib/module/modules/notification/hooks/useNotifications.js +12 -0
- package/lib/module/modules/notification/screens/NotificationScreen.js +180 -0
- package/lib/module/modules/notification/services/notificationService.js +12 -0
- package/lib/module/modules/promoteStudent/hooks/usePromoteStudent.js +12 -0
- package/lib/module/modules/promoteStudent/screens/PromoteStudentScreen.js +638 -0
- package/lib/module/modules/promoteStudent/services/promoteStudentService.js +27 -0
- package/lib/module/modules/timetable/hooks/useTimeTable.js +10 -0
- package/lib/module/modules/timetable/screens/TimeTableScreen.js +252 -0
- package/lib/module/modules/timetable/services/timetableService.js +11 -0
- package/lib/module/package.json +1 -0
- package/lib/module/shared/empty-states/EmptyState.js +40 -0
- package/lib/module/shared/empty-states/ErrorState.js +40 -0
- package/lib/module/shared/loaders/LoadingState.js +20 -0
- package/lib/module/shared/theme/theme.js +18 -0
- package/lib/typescript/core/api/apiClient.d.ts +14 -0
- package/lib/typescript/core/api/endpoints.d.ts +164 -0
- package/lib/typescript/core/api/interceptor.d.ts +4 -0
- package/lib/typescript/core/auth/authContext.d.ts +11 -0
- package/lib/typescript/core/auth/authService.d.ts +9 -0
- package/lib/typescript/core/hooks/useApiQuery.d.ts +7 -0
- package/lib/typescript/core/provider/ERPProvider.d.ts +14 -0
- package/lib/typescript/core/provider/types.d.ts +34 -0
- package/lib/typescript/core/provider/useERP.d.ts +3 -0
- package/lib/typescript/core/types/api.d.ts +11 -0
- package/lib/typescript/index.d.ts +18 -0
- package/lib/typescript/modules/assignment/hooks/useAssignmentList.d.ts +3 -0
- package/lib/typescript/modules/assignment/hooks/useHomeworkDetails.d.ts +4 -0
- package/lib/typescript/modules/assignment/hooks/useHomeworkSubmissions.d.ts +4 -0
- package/lib/typescript/modules/assignment/screens/AssignmentScreen.d.ts +9 -0
- package/lib/typescript/modules/assignment/services/assignmentService.d.ts +89 -0
- package/lib/typescript/modules/attendance/hooks/useAttendance.d.ts +3 -0
- package/lib/typescript/modules/attendance/screens/AttendanceScreen.d.ts +5 -0
- package/lib/typescript/modules/attendance/services/attendanceService.d.ts +33 -0
- package/lib/typescript/modules/leaveRequest/hooks/useLeaveRequests.d.ts +3 -0
- package/lib/typescript/modules/leaveRequest/screens/LeaveRequestScreen.d.ts +5 -0
- package/lib/typescript/modules/leaveRequest/services/leaveRequestService.d.ts +39 -0
- package/lib/typescript/modules/marks/hooks/useMarks.d.ts +2 -0
- package/lib/typescript/modules/marks/screens/MarksScreen.d.ts +6 -0
- package/lib/typescript/modules/marks/services/marksService.d.ts +150 -0
- package/lib/typescript/modules/myAttendance/hooks/useMyAttendance.d.ts +3 -0
- package/lib/typescript/modules/myAttendance/screens/MyAttendanceScreen.d.ts +5 -0
- package/lib/typescript/modules/myAttendance/services/myAttendanceService.d.ts +10 -0
- package/lib/typescript/modules/notes/hooks/useNotes.d.ts +3 -0
- package/lib/typescript/modules/notes/screens/NotesScreen.d.ts +8 -0
- package/lib/typescript/modules/notes/services/notesService.d.ts +58 -0
- package/lib/typescript/modules/noticeboard/hooks/useNoticeboard.d.ts +3 -0
- package/lib/typescript/modules/noticeboard/screens/NoticeBoardScreen.d.ts +5 -0
- package/lib/typescript/modules/noticeboard/services/noticeboardService.d.ts +17 -0
- package/lib/typescript/modules/notification/hooks/useNotifications.d.ts +3 -0
- package/lib/typescript/modules/notification/screens/NotificationScreen.d.ts +5 -0
- package/lib/typescript/modules/notification/services/notificationService.d.ts +8 -0
- package/lib/typescript/modules/promoteStudent/hooks/usePromoteStudent.d.ts +3 -0
- package/lib/typescript/modules/promoteStudent/screens/PromoteStudentScreen.d.ts +5 -0
- package/lib/typescript/modules/promoteStudent/services/promoteStudentService.d.ts +40 -0
- package/lib/typescript/modules/timetable/hooks/useTimeTable.d.ts +3 -0
- package/lib/typescript/modules/timetable/screens/TimeTableScreen.d.ts +5 -0
- package/lib/typescript/modules/timetable/services/timetableService.d.ts +14 -0
- package/lib/typescript/shared/empty-states/EmptyState.d.ts +6 -0
- package/lib/typescript/shared/empty-states/ErrorState.d.ts +6 -0
- package/lib/typescript/shared/loaders/LoadingState.d.ts +3 -0
- package/lib/typescript/shared/theme/theme.d.ts +17 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 UBK INFOTECH PVT LTD
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
# @ubkinfotech/tecaher-erp
|
|
2
|
+
|
|
3
|
+
Professional React Native Teacher ERP module package with a centralized `ERPProvider`.
|
|
4
|
+
|
|
5
|
+
It lets you configure your API once and reuse production-ready teacher flows such as:
|
|
6
|
+
|
|
7
|
+
- `AssignmentScreen`
|
|
8
|
+
- `AttendanceScreen`
|
|
9
|
+
- `LeaveRequestScreen`
|
|
10
|
+
- `MarksScreen`
|
|
11
|
+
- `MyAttendanceScreen`
|
|
12
|
+
- `NotesScreen`
|
|
13
|
+
- `NoticeBoardScreen`
|
|
14
|
+
- `NotificationScreen`
|
|
15
|
+
- `PromoteStudentScreen`
|
|
16
|
+
- `TimeTableScreen`
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- Centralized API configuration with `ERPProvider`
|
|
21
|
+
- Supports `authToken` or async `getAuthToken()`
|
|
22
|
+
- Automatic `Authorization` header attachment through Axios interceptors
|
|
23
|
+
- Internal pagination and API management for list-based modules
|
|
24
|
+
- Real screen flows for teacher ERP modules instead of JSON placeholders
|
|
25
|
+
- Optional support for image picking, document picking, PDF viewing, and local file handling
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
Install the package:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm i @ubkinfotech/tecaher-erp
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Install the required peer dependencies:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm i @tanstack/react-query react-native-safe-area-context
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Your app must already use compatible versions of:
|
|
42
|
+
|
|
43
|
+
- `react >= 18`
|
|
44
|
+
- `react-native >= 0.75`
|
|
45
|
+
|
|
46
|
+
## Optional Native Prerequisites
|
|
47
|
+
|
|
48
|
+
Some modules support file upload, image preview, document viewing, and PDF preview. Install these only if you need those features:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
npm i react-native-calendars
|
|
52
|
+
npm i react-native-document-picker
|
|
53
|
+
npm i react-native-image-picker
|
|
54
|
+
npm i react-native-image-viewing
|
|
55
|
+
npm i react-native-fs
|
|
56
|
+
npm i react-native-file-viewer
|
|
57
|
+
npm i react-native-pdf
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Module Prerequisite Matrix
|
|
61
|
+
|
|
62
|
+
| Module | Required Props | Optional Native Packages |
|
|
63
|
+
| --- | --- | --- |
|
|
64
|
+
| `AssignmentScreen` | `sessionId` recommended | `react-native-document-picker`, `react-native-image-picker`, `react-native-image-viewing`, `react-native-fs`, `react-native-file-viewer`, `react-native-pdf` |
|
|
65
|
+
| `AttendanceScreen` | `classId`, `sectionId`, `sessionId` recommended | `react-native-calendars` if your host app uses calendar-based date flows |
|
|
66
|
+
| `LeaveRequestScreen` | none | `react-native-document-picker`, `react-native-image-picker` for attachments |
|
|
67
|
+
| `MarksScreen` | `sessionId` recommended | none |
|
|
68
|
+
| `MyAttendanceScreen` | `staffId`, `sessionId` recommended | none |
|
|
69
|
+
| `NotesScreen` | `sessionId` recommended | `react-native-document-picker`, `react-native-image-picker`, `react-native-image-viewing`, `react-native-fs`, `react-native-file-viewer`, `react-native-pdf` |
|
|
70
|
+
| `NoticeBoardScreen` | none | none |
|
|
71
|
+
| `NotificationScreen` | none | none |
|
|
72
|
+
| `PromoteStudentScreen` | `classId`, `sectionId` recommended | none |
|
|
73
|
+
| `TimeTableScreen` | `staffId` + `sessionId` for teacher mode, or `classId` + `sectionId` + `sessionId` for class mode | none |
|
|
74
|
+
|
|
75
|
+
## Provider Setup
|
|
76
|
+
|
|
77
|
+
### With direct token
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
import React from 'react';
|
|
81
|
+
import {ERPProvider} from '@ubkinfotech/tecaher-erp';
|
|
82
|
+
|
|
83
|
+
const API_BASE_URL = 'https://example.com/';
|
|
84
|
+
const API_DOWNLOAD_URL = 'https://example.com/uploads/';
|
|
85
|
+
|
|
86
|
+
export function ERPApp({
|
|
87
|
+
authToken,
|
|
88
|
+
children,
|
|
89
|
+
}: {
|
|
90
|
+
authToken: string;
|
|
91
|
+
children: React.ReactNode;
|
|
92
|
+
}) {
|
|
93
|
+
return (
|
|
94
|
+
<ERPProvider
|
|
95
|
+
baseUrl={API_BASE_URL}
|
|
96
|
+
fileBaseUrl={API_DOWNLOAD_URL}
|
|
97
|
+
authToken={authToken}
|
|
98
|
+
>
|
|
99
|
+
{children}
|
|
100
|
+
</ERPProvider>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### With async token getter
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import React from 'react';
|
|
109
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
110
|
+
import {ERPProvider} from '@ubkinfotech/tecaher-erp';
|
|
111
|
+
|
|
112
|
+
const API_BASE_URL = 'https://example.com/';
|
|
113
|
+
const API_DOWNLOAD_URL = 'https://example.com/uploads/';
|
|
114
|
+
|
|
115
|
+
export function ERPApp({children}: {children: React.ReactNode}) {
|
|
116
|
+
return (
|
|
117
|
+
<ERPProvider
|
|
118
|
+
baseUrl={API_BASE_URL}
|
|
119
|
+
fileBaseUrl={API_DOWNLOAD_URL}
|
|
120
|
+
getAuthToken={() => AsyncStorage.getItem('token')}
|
|
121
|
+
>
|
|
122
|
+
{children}
|
|
123
|
+
</ERPProvider>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## ERPProvider Props
|
|
129
|
+
|
|
130
|
+
| Prop | Type | Required | Description |
|
|
131
|
+
| --- | --- | --- | --- |
|
|
132
|
+
| `baseUrl` | `string` | yes | Base API URL used by all ERP modules |
|
|
133
|
+
| `fileBaseUrl` | `string` | no | Base file URL for attachments, images, and documents |
|
|
134
|
+
| `schoolCode` | `string` | no | Optional school identifier/header context |
|
|
135
|
+
| `authToken` | `string \| null` | no | Direct auth token |
|
|
136
|
+
| `getAuthToken` | `() => Promise<string \| null>` | no | Async token getter |
|
|
137
|
+
| `refreshAuthToken` | `() => Promise<string \| null>` | no | Optional token refresh handler |
|
|
138
|
+
| `headers` | `Record<string, string>` | no | Additional request headers |
|
|
139
|
+
| `retry` | `{retries: number; delayMs: number}` | no | Retry policy for network requests |
|
|
140
|
+
| `onError` | `(error) => void` | no | Global API error callback |
|
|
141
|
+
| `onUnauthorized` | `(error) => void` | no | Callback for unauthorized responses |
|
|
142
|
+
|
|
143
|
+
## Basic Usage
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
import React from 'react';
|
|
147
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
148
|
+
import {
|
|
149
|
+
ERPProvider,
|
|
150
|
+
AttendanceScreen,
|
|
151
|
+
} from '@ubkinfotech/tecaher-erp';
|
|
152
|
+
|
|
153
|
+
const API_BASE_URL = 'https://example.com/';
|
|
154
|
+
|
|
155
|
+
export function AppRoot() {
|
|
156
|
+
return (
|
|
157
|
+
<ERPProvider
|
|
158
|
+
baseUrl={API_BASE_URL}
|
|
159
|
+
getAuthToken={() => AsyncStorage.getItem('token')}
|
|
160
|
+
>
|
|
161
|
+
<AttendanceScreen classId={1} sectionId={1} sessionId={1} />
|
|
162
|
+
</ERPProvider>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Exported Components
|
|
168
|
+
|
|
169
|
+
- `ERPProvider`
|
|
170
|
+
- `useERP`
|
|
171
|
+
- `AssignmentScreen`
|
|
172
|
+
- `AttendanceScreen`
|
|
173
|
+
- `LeaveRequestScreen`
|
|
174
|
+
- `MarksScreen`
|
|
175
|
+
- `MyAttendanceScreen`
|
|
176
|
+
- `NotesScreen`
|
|
177
|
+
- `NoticeBoardScreen`
|
|
178
|
+
- `NotificationScreen`
|
|
179
|
+
- `PromoteStudentScreen`
|
|
180
|
+
- `TimeTableScreen`
|
|
181
|
+
- `LoadingState`
|
|
182
|
+
- `EmptyState`
|
|
183
|
+
- `ErrorState`
|
|
184
|
+
|
|
185
|
+
## Module Examples
|
|
186
|
+
|
|
187
|
+
### AssignmentScreen
|
|
188
|
+
|
|
189
|
+
Use this for assignment listing, create, edit, submissions, and marks workflows.
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
import React from 'react';
|
|
193
|
+
import {ERPProvider, AssignmentScreen} from '@ubkinfotech/tecaher-erp';
|
|
194
|
+
|
|
195
|
+
const API_BASE_URL = 'https://example.com/';
|
|
196
|
+
const API_DOWNLOAD_URL = 'https://example.com/uploads/';
|
|
197
|
+
|
|
198
|
+
export function AssignmentExample({authToken}: {authToken: string}) {
|
|
199
|
+
return (
|
|
200
|
+
<ERPProvider
|
|
201
|
+
baseUrl={API_BASE_URL}
|
|
202
|
+
fileBaseUrl={API_DOWNLOAD_URL}
|
|
203
|
+
authToken={authToken}
|
|
204
|
+
>
|
|
205
|
+
<AssignmentScreen sessionId={1} />
|
|
206
|
+
</ERPProvider>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### AttendanceScreen
|
|
212
|
+
|
|
213
|
+
Use this for teacher attendance take/view flow.
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
import React from 'react';
|
|
217
|
+
import {ERPProvider, AttendanceScreen} from '@ubkinfotech/tecaher-erp';
|
|
218
|
+
|
|
219
|
+
const API_BASE_URL = 'https://example.com/';
|
|
220
|
+
|
|
221
|
+
export function AttendanceExample({authToken}: {authToken: string}) {
|
|
222
|
+
return (
|
|
223
|
+
<ERPProvider baseUrl={API_BASE_URL} authToken={authToken}>
|
|
224
|
+
<AttendanceScreen classId={1} sectionId={1} sessionId={1} />
|
|
225
|
+
</ERPProvider>
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### LeaveRequestScreen
|
|
231
|
+
|
|
232
|
+
Use this for leave request list, status tabs, and apply leave flow.
|
|
233
|
+
|
|
234
|
+
```tsx
|
|
235
|
+
import React from 'react';
|
|
236
|
+
import {ERPProvider, LeaveRequestScreen} from '@ubkinfotech/tecaher-erp';
|
|
237
|
+
|
|
238
|
+
const API_BASE_URL = 'https://example.com/';
|
|
239
|
+
|
|
240
|
+
export function LeaveRequestExample({authToken}: {authToken: string}) {
|
|
241
|
+
return (
|
|
242
|
+
<ERPProvider baseUrl={API_BASE_URL} authToken={authToken}>
|
|
243
|
+
<LeaveRequestScreen />
|
|
244
|
+
</ERPProvider>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### MarksScreen
|
|
250
|
+
|
|
251
|
+
Use this for scholastic, co-scholastic, and exam remark entry flows.
|
|
252
|
+
|
|
253
|
+
```tsx
|
|
254
|
+
import React from 'react';
|
|
255
|
+
import {ERPProvider, MarksScreen} from '@ubkinfotech/tecaher-erp';
|
|
256
|
+
|
|
257
|
+
const API_BASE_URL = 'https://example.com/';
|
|
258
|
+
|
|
259
|
+
export function MarksExample({authToken}: {authToken: string}) {
|
|
260
|
+
return (
|
|
261
|
+
<ERPProvider baseUrl={API_BASE_URL} authToken={authToken}>
|
|
262
|
+
<MarksScreen sessionId={1} />
|
|
263
|
+
</ERPProvider>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### MyAttendanceScreen
|
|
269
|
+
|
|
270
|
+
Use this for teacher attendance summary and daily report.
|
|
271
|
+
|
|
272
|
+
```tsx
|
|
273
|
+
import React from 'react';
|
|
274
|
+
import {ERPProvider, MyAttendanceScreen} from '@ubkinfotech/tecaher-erp';
|
|
275
|
+
|
|
276
|
+
const API_BASE_URL = 'https://example.com/';
|
|
277
|
+
|
|
278
|
+
export function MyAttendanceExample({authToken}: {authToken: string}) {
|
|
279
|
+
return (
|
|
280
|
+
<ERPProvider baseUrl={API_BASE_URL} authToken={authToken}>
|
|
281
|
+
<MyAttendanceScreen staffId={12} sessionId={1} />
|
|
282
|
+
</ERPProvider>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
### NotesScreen
|
|
288
|
+
|
|
289
|
+
Use this for note listing, note detail, create note, edit note, upload image/document, and preview flows.
|
|
290
|
+
|
|
291
|
+
```tsx
|
|
292
|
+
import React from 'react';
|
|
293
|
+
import {ERPProvider, NotesScreen} from '@ubkinfotech/tecaher-erp';
|
|
294
|
+
|
|
295
|
+
const API_BASE_URL = 'https://example.com/';
|
|
296
|
+
const API_DOWNLOAD_URL = 'https://example.com/uploads/';
|
|
297
|
+
|
|
298
|
+
export function NotesExample({authToken}: {authToken: string}) {
|
|
299
|
+
return (
|
|
300
|
+
<ERPProvider
|
|
301
|
+
baseUrl={API_BASE_URL}
|
|
302
|
+
fileBaseUrl={API_DOWNLOAD_URL}
|
|
303
|
+
authToken={authToken}
|
|
304
|
+
>
|
|
305
|
+
<NotesScreen sessionId={1} />
|
|
306
|
+
</ERPProvider>
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### NoticeBoardScreen
|
|
312
|
+
|
|
313
|
+
Use this for notice board list and notice detail view.
|
|
314
|
+
|
|
315
|
+
```tsx
|
|
316
|
+
import React from 'react';
|
|
317
|
+
import {ERPProvider, NoticeBoardScreen} from '@ubkinfotech/tecaher-erp';
|
|
318
|
+
|
|
319
|
+
const API_BASE_URL = 'https://example.com/';
|
|
320
|
+
|
|
321
|
+
export function NoticeBoardExample({authToken}: {authToken: string}) {
|
|
322
|
+
return (
|
|
323
|
+
<ERPProvider baseUrl={API_BASE_URL} authToken={authToken}>
|
|
324
|
+
<NoticeBoardScreen />
|
|
325
|
+
</ERPProvider>
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### NotificationScreen
|
|
331
|
+
|
|
332
|
+
Use this for notification list with built-in pagination and refresh.
|
|
333
|
+
|
|
334
|
+
```tsx
|
|
335
|
+
import React from 'react';
|
|
336
|
+
import {ERPProvider, NotificationScreen} from '@ubkinfotech/tecaher-erp';
|
|
337
|
+
|
|
338
|
+
const API_BASE_URL = 'https://example.com/';
|
|
339
|
+
|
|
340
|
+
export function NotificationExample({authToken}: {authToken: string}) {
|
|
341
|
+
return (
|
|
342
|
+
<ERPProvider baseUrl={API_BASE_URL} authToken={authToken}>
|
|
343
|
+
<NotificationScreen />
|
|
344
|
+
</ERPProvider>
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
### PromoteStudentScreen
|
|
350
|
+
|
|
351
|
+
Use this for search, destination selection, and student promotion submission flow.
|
|
352
|
+
|
|
353
|
+
```tsx
|
|
354
|
+
import React from 'react';
|
|
355
|
+
import {ERPProvider, PromoteStudentScreen} from '@ubkinfotech/tecaher-erp';
|
|
356
|
+
|
|
357
|
+
const API_BASE_URL = 'https://example.com/';
|
|
358
|
+
|
|
359
|
+
export function PromoteStudentExample({authToken}: {authToken: string}) {
|
|
360
|
+
return (
|
|
361
|
+
<ERPProvider baseUrl={API_BASE_URL} authToken={authToken}>
|
|
362
|
+
<PromoteStudentScreen classId={1} sectionId={1} />
|
|
363
|
+
</ERPProvider>
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### TimeTableScreen
|
|
369
|
+
|
|
370
|
+
Teacher mode:
|
|
371
|
+
|
|
372
|
+
```tsx
|
|
373
|
+
import React from 'react';
|
|
374
|
+
import {ERPProvider, TimeTableScreen} from '@ubkinfotech/tecaher-erp';
|
|
375
|
+
|
|
376
|
+
const API_BASE_URL = 'https://example.com/';
|
|
377
|
+
|
|
378
|
+
export function TeacherTimeTableExample({authToken}: {authToken: string}) {
|
|
379
|
+
return (
|
|
380
|
+
<ERPProvider baseUrl={API_BASE_URL} authToken={authToken}>
|
|
381
|
+
<TimeTableScreen staffId={12} sessionId={1} />
|
|
382
|
+
</ERPProvider>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Class mode:
|
|
388
|
+
|
|
389
|
+
```tsx
|
|
390
|
+
import React from 'react';
|
|
391
|
+
import {ERPProvider, TimeTableScreen} from '@ubkinfotech/tecaher-erp';
|
|
392
|
+
|
|
393
|
+
const API_BASE_URL = 'https://example.com/';
|
|
394
|
+
|
|
395
|
+
export function ClassTimeTableExample({authToken}: {authToken: string}) {
|
|
396
|
+
return (
|
|
397
|
+
<ERPProvider baseUrl={API_BASE_URL} authToken={authToken}>
|
|
398
|
+
<TimeTableScreen classId={1} sectionId={1} sessionId={1} />
|
|
399
|
+
</ERPProvider>
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
## Notes
|
|
405
|
+
|
|
406
|
+
- The published package name is intentionally `@ubkinfotech/tecaher-erp`.
|
|
407
|
+
- `fileBaseUrl` is strongly recommended for modules that render attachments, documents, and images.
|
|
408
|
+
- Most list modules internally manage pagination, refresh, and API calls.
|
|
409
|
+
- Use `sessionId`, `staffId`, `classId`, and `sectionId` from your authenticated user/session context whenever possible.
|
|
410
|
+
|
|
411
|
+
## License
|
|
412
|
+
|
|
413
|
+
MIT
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createApiClient = createApiClient;
|
|
7
|
+
exports.normalizeApiError = normalizeApiError;
|
|
8
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
9
|
+
var _interceptor = require("./interceptor");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
function normalizeApiError(e) {
|
|
12
|
+
if (_axios.default.isAxiosError(e)) {
|
|
13
|
+
const err = e;
|
|
14
|
+
const status = err.response?.status;
|
|
15
|
+
const data = err.response?.data;
|
|
16
|
+
return {
|
|
17
|
+
message: err.message,
|
|
18
|
+
status,
|
|
19
|
+
data
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
if (e instanceof Error) {
|
|
23
|
+
return {
|
|
24
|
+
message: e.message
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
message: 'Unknown error'
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function createApiClient(args) {
|
|
32
|
+
const baseUrl = args.network.baseUrl.endsWith('/') ? args.network.baseUrl.slice(0, -1) : args.network.baseUrl;
|
|
33
|
+
const instance = _axios.default.create({
|
|
34
|
+
baseURL: baseUrl
|
|
35
|
+
});
|
|
36
|
+
(0, _interceptor.attachInterceptors)(instance, args);
|
|
37
|
+
return instance;
|
|
38
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.endpoints = void 0;
|
|
7
|
+
const endpoints = exports.endpoints = {
|
|
8
|
+
attendance: {
|
|
9
|
+
studentsForAttendance: args => {
|
|
10
|
+
const date = args.date ?? '';
|
|
11
|
+
return `staff/teacherAPP/AttendenceSection/studentlistforAttendence?class_id=${args.classId}§ion_id=${args.sectionId}&session_id=${args.sessionId}&date=${encodeURIComponent(date)}`;
|
|
12
|
+
},
|
|
13
|
+
updateStatus: 'staff/teacherAPP/AttendenceSection/studentstatusupdate',
|
|
14
|
+
notify: 'staff/teacherAPP/AttendenceSection/studentAttendanceNotification',
|
|
15
|
+
classDropdown: 'staff/teacherAPP/attendenceSection/getclassDropdownforTeacher',
|
|
16
|
+
sectionDropdown: args => {
|
|
17
|
+
return `staff/teacherAPP/attendenceSection/getsectionDropdownforTeacher?class_id=${args.classId}`;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
assignment: {
|
|
21
|
+
listByClassSection: args => {
|
|
22
|
+
const classPart = args.classId !== undefined ? `&class_id=${args.classId}` : '';
|
|
23
|
+
const sectionPart = args.sectionId !== undefined ? `§ion_id=${args.sectionId}` : '';
|
|
24
|
+
const subjectPart = args.subjectId !== undefined ? `&subject_id=${args.subjectId}` : '';
|
|
25
|
+
return `staff/teacherAPP/StaffHomework/gethomeworklistByClassSection?page=${args.page}&per_page=${args.perPage}${classPart}${sectionPart}${subjectPart}`;
|
|
26
|
+
},
|
|
27
|
+
add: 'staff/teacherAPP/StaffHomework/addHomework',
|
|
28
|
+
classDropdown: 'staff/teacherAPP/attendenceSection/getclassDropdownforTeacher',
|
|
29
|
+
sectionDropdown: args => {
|
|
30
|
+
return `staff/teacherAPP/attendenceSection/getsectionDropdownforTeacher?class_id=${args.classId}`;
|
|
31
|
+
},
|
|
32
|
+
teacherSubjectsByClass: args => {
|
|
33
|
+
return `staff/teacherAPP/teacherbasicDetails/getteacherSubjectsaccordingtoClass?session_id=${args.sessionId}&class_id=${args.classId}`;
|
|
34
|
+
},
|
|
35
|
+
uploadFile: 'superAdmin/uploadFile',
|
|
36
|
+
submissionsList: args => {
|
|
37
|
+
return `staff/teacherAPP/StaffHomework/studentsubmissionList?homework_id=${args.homeworkId}`;
|
|
38
|
+
},
|
|
39
|
+
giveMarks: 'staff/teacherAPP/StaffHomework/givemarkstoHomework',
|
|
40
|
+
showHomework: args => {
|
|
41
|
+
return `staff/teacherAPP/StaffHomework/showHomeWork?id=${args.homeworkId}`;
|
|
42
|
+
},
|
|
43
|
+
updateHomework: 'staff/teacherAPP/StaffHomework/updateHomework'
|
|
44
|
+
},
|
|
45
|
+
leaveRequest: {
|
|
46
|
+
table: args => {
|
|
47
|
+
return `staff/teacherAPP/staffLeave/leaveTable?page=${args.page}&per_page=${args.perPage}`;
|
|
48
|
+
},
|
|
49
|
+
leaveTypes: 'staff/teacherAPP/staffLeave/leavetypeDropdown',
|
|
50
|
+
apply: 'staff/teacherAPP/staffLeave/applyLeave'
|
|
51
|
+
},
|
|
52
|
+
marks: {
|
|
53
|
+
coscholasticGrades: 'staff/teacherAPP/ExamDetails/gradeDropdownCoScholastic',
|
|
54
|
+
classDropdown: 'staff/teacherAPP/attendenceSection/getclassDropdownforTeacher',
|
|
55
|
+
classTeacherClassList: 'staff/teacherAPP/ExamDetails/getClassTeacherClassList',
|
|
56
|
+
sectionDropdown: args => {
|
|
57
|
+
return `staff/teacherAPP/attendenceSection/getsectionDropdownforTeacher?class_id=${args.classId}`;
|
|
58
|
+
},
|
|
59
|
+
examDropdown: args => {
|
|
60
|
+
return `staff/teacherAPP/ExamDetails/examdropdown?session_id=${args.sessionId}&class_id=${args.classId}`;
|
|
61
|
+
},
|
|
62
|
+
teacherSubjectsForExam: args => {
|
|
63
|
+
return `staff/teacherAPP/ExamDetails/getSubjectofTeacherAccordingtoExam?session_id=${args.sessionId}&exam_id=${args.examId}&class_id=${args.classId}§ion_id=${args.sectionId}`;
|
|
64
|
+
},
|
|
65
|
+
coScholasticCategories: args => {
|
|
66
|
+
return `staff/teacherAPP/ExamDetails/getscholasticCategoryByClassId?session_id=${args.sessionId}&exam_id=${args.examId}&class_id=${args.classId}`;
|
|
67
|
+
},
|
|
68
|
+
studentListForExamAssessment: args => {
|
|
69
|
+
return `staff/teacherAPP/ExamDetails/getstudentlistforExamAssesment?class_id=${args.classId}&exam_id=${args.examId}§ion_id=${args.sectionId}&subject_id=${args.subjectId}`;
|
|
70
|
+
},
|
|
71
|
+
submitExamMarks: 'staff/teacherAPP/ExamDetails/addexamMarksV2',
|
|
72
|
+
studentListForCoScholastic: args => {
|
|
73
|
+
return `staff/teacherAPP/ExamDetails/getstudentlistforCoscholastic?class_id=${args.classId}&exam_id=${args.examId}§ion_id=${args.sectionId}&CoScholastic_category_id=${args.categoryId}`;
|
|
74
|
+
},
|
|
75
|
+
submitCoScholasticMarks: 'staff/teacherAPP/ExamDetails/assignCoscholasticMarks',
|
|
76
|
+
studentListRemarks: args => {
|
|
77
|
+
return `staff/teacherAPP/ExamDetails/getstudentListRemarks?class_id=${args.classId}&exam_id=${args.examId}§ion_id=${args.sectionId}`;
|
|
78
|
+
},
|
|
79
|
+
submitExamRemarks: 'staff/teacherAPP/ExamDetails/studentExamRemarks'
|
|
80
|
+
},
|
|
81
|
+
myAttendance: {
|
|
82
|
+
report: args => {
|
|
83
|
+
return `staff/teacherAPP/AttendenceSection/getAttendenceReportofstaffApp?id=${args.staffId}&month=${args.month}&year=${args.year}&session_id=${args.sessionId}`;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
notes: {
|
|
87
|
+
listByClassSection: args => {
|
|
88
|
+
const classPart = args.classId !== undefined ? `&class_id=${args.classId}` : '';
|
|
89
|
+
const sectionPart = args.sectionId !== undefined ? `§ion_id=${args.sectionId}` : '';
|
|
90
|
+
const subjectPart = args.subjectId !== undefined ? `&subject_id=${args.subjectId}` : '';
|
|
91
|
+
return `staff/teacherAPP/Notes/getnotelistByClassSection?page=${args.page}&per_page=${args.perPage}${classPart}${sectionPart}${subjectPart}`;
|
|
92
|
+
},
|
|
93
|
+
classDropdown: 'staff/teacherAPP/attendenceSection/getclassDropdownforTeacher',
|
|
94
|
+
sectionDropdown: args => {
|
|
95
|
+
return `staff/teacherAPP/attendenceSection/getsectionDropdownforTeacher?class_id=${args.classId}`;
|
|
96
|
+
},
|
|
97
|
+
teacherSubjectsByClass: args => {
|
|
98
|
+
return `staff/teacherAPP/StaffHomework/getsubjectDropdownByClass?class_id=${args.classId}&session_id=${args.sessionId}`;
|
|
99
|
+
},
|
|
100
|
+
details: args => {
|
|
101
|
+
return `staff/teacherAPP/Notes/getNotedatabyID?id=${args.noteId}`;
|
|
102
|
+
},
|
|
103
|
+
add: 'staff/teacherAPP/Notes/addNotes',
|
|
104
|
+
update: 'staff/teacherAPP/Notes/updateNote',
|
|
105
|
+
upload: 'staff/teacherAPP/Notes/uploadnotes'
|
|
106
|
+
},
|
|
107
|
+
noticeboard: {
|
|
108
|
+
list: args => {
|
|
109
|
+
return `staff/teacherAPP/Noticeboard?page=${args.page}&per_page=${args.perPage}`;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
notification: {
|
|
113
|
+
list: args => {
|
|
114
|
+
return `staff/teacherAPP/message/getnotificationlist?page=${args.page}&per_page=${args.perPage}`;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
promoteStudent: {
|
|
118
|
+
classDropdown: 'staff/teacherAPP/attendenceSection/getclassDropdownforTeacher',
|
|
119
|
+
sectionDropdown: args => {
|
|
120
|
+
return `staff/teacherAPP/attendenceSection/getsectionDropdownforTeacher?class_id=${args.classId}`;
|
|
121
|
+
},
|
|
122
|
+
allSectionDropdown: args => {
|
|
123
|
+
return `staff/teacherAPP/attendenceSection/getsectionDropdown?class_id=${args.classId}`;
|
|
124
|
+
},
|
|
125
|
+
sessionDropdown: 'staff/teacherAPP/StudentDetails/sessiondropdown',
|
|
126
|
+
searchByClassSection: args => {
|
|
127
|
+
return `staff/teacherAPP/StudentDetails/studentsearchbyClassSection?class_id=${args.classId}§ion_id=${args.sectionId}`;
|
|
128
|
+
},
|
|
129
|
+
submit: 'staff/teacherAPP/StudentDetails/promotestudent'
|
|
130
|
+
},
|
|
131
|
+
timetable: {
|
|
132
|
+
teacher: args => {
|
|
133
|
+
return `timetable/teacher/${args.staffId}?session_id=${args.sessionId}`;
|
|
134
|
+
},
|
|
135
|
+
classSection: args => {
|
|
136
|
+
return `timetable/class/${args.classId}/section/${args.sectionId}?session_id=${args.sessionId}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.attachInterceptors = attachInterceptors;
|
|
7
|
+
var _apiClient = require("./apiClient");
|
|
8
|
+
async function sleep(ms) {
|
|
9
|
+
await new Promise(resolve => setTimeout(() => resolve(), ms));
|
|
10
|
+
}
|
|
11
|
+
function shouldRetry(err) {
|
|
12
|
+
if (!err.response) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
const status = err.response.status;
|
|
16
|
+
return status >= 500 && status <= 599;
|
|
17
|
+
}
|
|
18
|
+
function attachInterceptors(instance, args) {
|
|
19
|
+
instance.interceptors.request.use(async config => {
|
|
20
|
+
const nextConfig = config;
|
|
21
|
+
nextConfig.headers = {
|
|
22
|
+
...(args.network.headers ?? {}),
|
|
23
|
+
...(nextConfig.headers ?? {})
|
|
24
|
+
};
|
|
25
|
+
const token = args.auth.authToken ?? (args.auth.getAuthToken ? await args.auth.getAuthToken() : null);
|
|
26
|
+
if (token) {
|
|
27
|
+
nextConfig.headers.Authorization = token;
|
|
28
|
+
}
|
|
29
|
+
if (args.network.schoolCode) {
|
|
30
|
+
nextConfig.headers.school_code = args.network.schoolCode;
|
|
31
|
+
}
|
|
32
|
+
return nextConfig;
|
|
33
|
+
});
|
|
34
|
+
instance.interceptors.response.use(res => res, async error => {
|
|
35
|
+
const config = error.config ?? {};
|
|
36
|
+
const status = error.response?.status;
|
|
37
|
+
if (status === 401 && !config.__didRefreshAuth && args.auth.refreshAuthToken) {
|
|
38
|
+
config.__didRefreshAuth = true;
|
|
39
|
+
const refreshed = await args.auth.refreshAuthToken();
|
|
40
|
+
if (refreshed) {
|
|
41
|
+
config.headers = {
|
|
42
|
+
...(config.headers ?? {}),
|
|
43
|
+
Authorization: refreshed
|
|
44
|
+
};
|
|
45
|
+
return instance.request(config);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (status === 401 && args.auth.onUnauthorized) {
|
|
49
|
+
args.auth.onUnauthorized((0, _apiClient.normalizeApiError)(error));
|
|
50
|
+
}
|
|
51
|
+
if (args.network.onError) {
|
|
52
|
+
args.network.onError((0, _apiClient.normalizeApiError)(error));
|
|
53
|
+
}
|
|
54
|
+
const retries = args.network.retry?.retries ?? 0;
|
|
55
|
+
const delayMs = args.network.retry?.delayMs ?? 500;
|
|
56
|
+
const count = config.__retryCount ?? 0;
|
|
57
|
+
if (count < retries && shouldRetry(error)) {
|
|
58
|
+
config.__retryCount = count + 1;
|
|
59
|
+
await sleep(delayMs * (count + 1));
|
|
60
|
+
return instance.request(config);
|
|
61
|
+
}
|
|
62
|
+
return Promise.reject(error);
|
|
63
|
+
});
|
|
64
|
+
}
|