@finema/finework-layer 0.2.3 → 0.2.5

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,189 +1,189 @@
1
- export enum Permission {
2
- USER = 'USER',
3
- ADMIN = 'ADMIN',
4
- SUPER = 'SUPER',
5
- NONE = 'NONE',
6
- }
7
-
8
- export const PERMISSION_LABEL = {
9
- [Permission.ADMIN]: 'Admin',
10
- [Permission.USER]: 'User',
11
- [Permission.SUPER]: 'Settings',
12
- [Permission.NONE]: 'No Access',
13
- }
14
-
15
- export interface ITeam {
16
- id: string
17
- name: string
18
- code: string
19
- color: string
20
- description?: string
21
- working_start_at: string
22
- working_end_at: string
23
- users: IUser[] | null
24
- created_at: string
25
- updated_at: string
26
- }
27
-
28
- export interface IUser {
29
- id: string
30
- email: string
31
- full_name: string
32
- display_name: string
33
- position: string
34
- team: ITeam
35
- team_code: string
36
- avatar_url: string
37
- company: string
38
- access_level: IUserAccessLevel
39
- is_active: boolean
40
- joined_date: string
41
- slack_id: string
42
- created_at: string
43
- updated_at: string
44
- }
45
-
46
- export enum UserModule {
47
- CHECKIN = 'clockin',
48
- PMO = 'pmo',
49
- TIMESHEET = 'timesheet',
50
- SETTING = 'setting',
51
- }
52
-
53
- export interface IUserAccessLevel {
54
- used_id: string
55
- pmo: Permission.USER | Permission.ADMIN | Permission.SUPER
56
- clockin: Permission.USER | Permission.ADMIN
57
- timesheet: Permission.USER | Permission.ADMIN
58
- setting: Permission.USER | Permission.SUPER
59
- }
60
-
61
- export const useAuth = () => {
62
- const {
63
- auth,
64
- } = useRequestOptions()
65
-
66
- const token = useCookie('token', {
67
- path: '/',
68
- maxAge: 60 * 60 * 24 * 365,
69
- })
70
-
71
- const isAuthenticated = computed(() => !!token.value)
72
- const me = defineStore('auth.me', () => {
73
- const value = ref<IUser | null>(null)
74
-
75
- const set = (user: IUser | null) => {
76
- value.value = user
77
- }
78
-
79
- return {
80
- value,
81
- set,
82
- }
83
- })()
84
-
85
- const fetchMe = (() => {
86
- return useObjectLoader<IUser>({
87
- method: 'GET',
88
- url: '/me',
89
- getRequestOptions: auth,
90
- })
91
- })()
92
-
93
- const updateMe = (() => {
94
- return useObjectLoader<IUser>({
95
- method: 'PUT',
96
- url: '/me',
97
- getRequestOptions: auth,
98
- })
99
- })()
100
-
101
- const loginSlack = async () => {
102
- const config = useRuntimeConfig()
103
-
104
- window.location.href = config.public.baseAPI + '/auth/slack-login'
105
- }
106
-
107
- const loginMs = async () => {
108
- const config = useRuntimeConfig()
109
-
110
- window.location.href = config.public.baseAPI + '/auth/ms-login'
111
- }
112
-
113
- useWatchTrue(() => fetchMe.status.value.isSuccess, () => {
114
- me.set(fetchMe.data.value)
115
- })
116
-
117
- useWatchTrue(() => fetchMe.status.value.isError, () => {
118
- token.value = undefined
119
- me.set(null)
120
- })
121
-
122
- const hasPermission = (module: UserModule, ...permission: Permission[]) => {
123
- if (!me.value?.access_level) {
124
- return false
125
- }
126
-
127
- return permission.includes(me.value.access_level[module])
128
- }
129
-
130
- const isSuperAdmin = computed(() => {
131
- return me.value?.access_level?.setting === Permission.SUPER
132
- })
133
-
134
- const menusNavbar = computed(() => [
135
- {
136
- label: 'Clock-In',
137
- icon: '/admin/clock-in-logo.png',
138
- to: routes.clockin.home.to,
139
- },
140
- {
141
- label: 'Timesheet',
142
- icon: '/admin/timesheet-logo.png',
143
- to: routes.timesheet.home.to,
144
- },
145
- ...(hasPermission(UserModule.PMO, Permission.ADMIN, Permission.USER, Permission.SUPER)
146
- ? [{
147
- label: 'PMO',
148
- icon: '/admin/pmo-logo.png',
149
- to: routes.pmo.project.projects.to,
150
- }]
151
- : []),
152
- ...(hasPermission(UserModule.CHECKIN, Permission.ADMIN)
153
- ? [{
154
- label: 'Clock-In Admin',
155
- icon: '/admin/clock-in-admin-logo.png',
156
- to: routes.adminClockin.checkinDashboard.to,
157
- }]
158
- : []),
159
- ...(hasPermission(UserModule.TIMESHEET, Permission.ADMIN)
160
- ? [{
161
- label: 'Timesheet Admin',
162
- icon: '/admin/timesheet-admin-logo.png',
163
- to: routes.adminTimesheet.summaryReport.to,
164
- }]
165
- : []),
166
-
167
- ...(hasPermission(UserModule.SETTING, Permission.SUPER)
168
- ? [{
169
- label: 'Settings',
170
- icon: '/admin/super-admin-logo.png',
171
- to: routes.admin.users.to,
172
- }]
173
- : []),
174
- ])
175
-
176
- return {
177
- token,
178
- loginSlack,
179
- loginMs,
180
- isAuthenticated,
181
- me,
182
- fetchMe,
183
- updateMe,
184
- hasPermission,
185
- isSuperAdmin,
186
- menusNavbar,
187
-
188
- }
189
- }
1
+ export enum Permission {
2
+ USER = 'USER',
3
+ ADMIN = 'ADMIN',
4
+ SUPER = 'SUPER',
5
+ NONE = 'NONE',
6
+ }
7
+
8
+ export const PERMISSION_LABEL = {
9
+ [Permission.ADMIN]: 'Admin',
10
+ [Permission.USER]: 'User',
11
+ [Permission.SUPER]: 'Settings',
12
+ [Permission.NONE]: 'No Access',
13
+ }
14
+
15
+ export interface ITeam {
16
+ id: string
17
+ name: string
18
+ code: string
19
+ color: string
20
+ description?: string
21
+ working_start_at: string
22
+ working_end_at: string
23
+ users: IUser[] | null
24
+ created_at: string
25
+ updated_at: string
26
+ }
27
+
28
+ export interface IUser {
29
+ id: string
30
+ email: string
31
+ full_name: string
32
+ display_name: string
33
+ position: string
34
+ team: ITeam
35
+ team_code: string
36
+ avatar_url: string
37
+ company: string
38
+ access_level: IUserAccessLevel
39
+ is_active: boolean
40
+ joined_date: string
41
+ slack_id: string
42
+ created_at: string
43
+ updated_at: string
44
+ }
45
+
46
+ export enum UserModule {
47
+ CHECKIN = 'clockin',
48
+ PMO = 'pmo',
49
+ TIMESHEET = 'timesheet',
50
+ SETTING = 'setting',
51
+ }
52
+
53
+ export interface IUserAccessLevel {
54
+ used_id: string
55
+ pmo: Permission.USER | Permission.ADMIN | Permission.SUPER
56
+ clockin: Permission.USER | Permission.ADMIN
57
+ timesheet: Permission.USER | Permission.ADMIN
58
+ setting: Permission.USER | Permission.SUPER
59
+ }
60
+
61
+ export const useAuth = () => {
62
+ const {
63
+ auth,
64
+ } = useRequestOptions()
65
+
66
+ const token = useCookie('token', {
67
+ path: '/',
68
+ maxAge: 60 * 60 * 24 * 365,
69
+ })
70
+
71
+ const isAuthenticated = computed(() => !!token.value)
72
+ const me = defineStore('auth.me', () => {
73
+ const value = ref<IUser | null>(null)
74
+
75
+ const set = (user: IUser | null) => {
76
+ value.value = user
77
+ }
78
+
79
+ return {
80
+ value,
81
+ set,
82
+ }
83
+ })()
84
+
85
+ const fetchMe = (() => {
86
+ return useObjectLoader<IUser>({
87
+ method: 'GET',
88
+ url: '/me',
89
+ getRequestOptions: auth,
90
+ })
91
+ })()
92
+
93
+ const updateMe = (() => {
94
+ return useObjectLoader<IUser>({
95
+ method: 'PUT',
96
+ url: '/me',
97
+ getRequestOptions: auth,
98
+ })
99
+ })()
100
+
101
+ const loginSlack = async () => {
102
+ const config = useRuntimeConfig()
103
+
104
+ window.location.href = config.public.baseAPI + '/auth/slack-login'
105
+ }
106
+
107
+ const loginMs = async () => {
108
+ const config = useRuntimeConfig()
109
+
110
+ window.location.href = config.public.baseAPI + '/auth/ms-login'
111
+ }
112
+
113
+ useWatchTrue(() => fetchMe.status.value.isSuccess, () => {
114
+ me.set(fetchMe.data.value)
115
+ })
116
+
117
+ useWatchTrue(() => fetchMe.status.value.isError, () => {
118
+ token.value = undefined
119
+ me.set(null)
120
+ })
121
+
122
+ const hasPermission = (module: UserModule, ...permission: Permission[]) => {
123
+ if (!me.value?.access_level) {
124
+ return false
125
+ }
126
+
127
+ return permission.includes(me.value.access_level[module])
128
+ }
129
+
130
+ const isSuperAdmin = computed(() => {
131
+ return me.value?.access_level?.setting === Permission.SUPER
132
+ })
133
+
134
+ const menusNavbar = computed(() => [
135
+ {
136
+ label: 'Clock-In',
137
+ icon: '/admin/clock-in-logo.png',
138
+ to: routes.clockin.home.to,
139
+ },
140
+ {
141
+ label: 'Timesheet',
142
+ icon: '/admin/timesheet-logo.png',
143
+ to: routes.timesheet.home.to,
144
+ },
145
+ ...(hasPermission(UserModule.PMO, Permission.ADMIN, Permission.USER, Permission.SUPER)
146
+ ? [{
147
+ label: 'PMO',
148
+ icon: '/admin/pmo-logo.png',
149
+ to: routes.pmo.project.projects.to,
150
+ }]
151
+ : []),
152
+ ...(hasPermission(UserModule.CHECKIN, Permission.ADMIN)
153
+ ? [{
154
+ label: 'Clock-In Admin',
155
+ icon: '/admin/clock-in-admin-logo.png',
156
+ to: routes.adminClockin.checkinDashboard.to,
157
+ }]
158
+ : []),
159
+ ...(hasPermission(UserModule.TIMESHEET, Permission.ADMIN)
160
+ ? [{
161
+ label: 'Timesheet Admin',
162
+ icon: '/admin/timesheet-admin-logo.png',
163
+ to: routes.adminTimesheet.summaryReport.to,
164
+ }]
165
+ : []),
166
+
167
+ ...(hasPermission(UserModule.SETTING, Permission.SUPER)
168
+ ? [{
169
+ label: 'Settings',
170
+ icon: '/admin/super-admin-logo.png',
171
+ to: routes.admin.users.to,
172
+ }]
173
+ : []),
174
+ ])
175
+
176
+ return {
177
+ token,
178
+ loginSlack,
179
+ loginMs,
180
+ isAuthenticated,
181
+ me,
182
+ fetchMe,
183
+ updateMe,
184
+ hasPermission,
185
+ isSuperAdmin,
186
+ menusNavbar,
187
+
188
+ }
189
+ }
@@ -1,50 +1,50 @@
1
- import type { AxiosRequestConfig } from 'axios'
2
-
3
- export const useRequestOptions = () => {
4
- const config = useRuntimeConfig()
5
-
6
- const mock = (): Omit<AxiosRequestConfig, 'baseURL'> & {
7
- baseURL: string
8
- } => {
9
- return {
10
- baseURL: config.public.baseAPIMock || 'http://localhost:3000/api/mock',
11
- }
12
- }
13
-
14
- const base = (): Omit<AxiosRequestConfig, 'baseURL'> & {
15
- baseURL: string
16
- } => {
17
- return {
18
- baseURL: config.public.baseAPI,
19
- }
20
- }
21
-
22
- const auth = (): Omit<AxiosRequestConfig, 'baseURL'> & {
23
- baseURL: string
24
- } => {
25
- return {
26
- baseURL: config.public.baseAPI,
27
- headers: {
28
- Authorization: `Bearer ${useAuth().token.value}`,
29
- },
30
- }
31
- }
32
-
33
- const file = (): Omit<AxiosRequestConfig, 'baseURL'> & {
34
- baseURL: string
35
- } => {
36
- return {
37
- baseURL: config.public.baseAPI + '/uploads',
38
- headers: {
39
- Authorization: `Bearer ${useAuth().token.value}`,
40
- },
41
- }
42
- }
43
-
44
- return {
45
- base,
46
- mock,
47
- auth,
48
- file,
49
- }
50
- }
1
+ import type { AxiosRequestConfig } from 'axios'
2
+
3
+ export const useRequestOptions = () => {
4
+ const config = useRuntimeConfig()
5
+
6
+ const mock = (): Omit<AxiosRequestConfig, 'baseURL'> & {
7
+ baseURL: string
8
+ } => {
9
+ return {
10
+ baseURL: config.public.baseAPIMock || 'http://localhost:3000/api/mock',
11
+ }
12
+ }
13
+
14
+ const base = (): Omit<AxiosRequestConfig, 'baseURL'> & {
15
+ baseURL: string
16
+ } => {
17
+ return {
18
+ baseURL: config.public.baseAPI,
19
+ }
20
+ }
21
+
22
+ const auth = (): Omit<AxiosRequestConfig, 'baseURL'> & {
23
+ baseURL: string
24
+ } => {
25
+ return {
26
+ baseURL: config.public.baseAPI,
27
+ headers: {
28
+ Authorization: `Bearer ${useAuth().token.value}`,
29
+ },
30
+ }
31
+ }
32
+
33
+ const file = (): Omit<AxiosRequestConfig, 'baseURL'> & {
34
+ baseURL: string
35
+ } => {
36
+ return {
37
+ baseURL: config.public.baseAPI + '/uploads',
38
+ headers: {
39
+ Authorization: `Bearer ${useAuth().token.value}`,
40
+ },
41
+ }
42
+ }
43
+
44
+ return {
45
+ base,
46
+ mock,
47
+ auth,
48
+ file,
49
+ }
50
+ }