2023-10-04 09:30:05 +02:00
|
|
|
import { httpClientFactory } from '@/services/httpClientFactory'
|
|
|
|
|
|
|
|
const apiClient = httpClientFactory('api')
|
2023-10-05 14:05:42 +02:00
|
|
|
const webClient = httpClientFactory('web')
|
2023-10-04 09:30:05 +02:00
|
|
|
|
|
|
|
export default {
|
2024-02-18 14:58:21 +01:00
|
|
|
/**
|
|
|
|
* Get current signed-in user preferences
|
|
|
|
*
|
|
|
|
* @returns promise
|
|
|
|
*/
|
|
|
|
getPreferences(config = {}) {
|
|
|
|
return apiClient.get('/user/preferences', { ...config })
|
|
|
|
},
|
|
|
|
|
2023-10-04 09:30:05 +02:00
|
|
|
/**
|
2023-10-05 14:05:42 +02:00
|
|
|
* Update a user preference
|
2023-10-04 09:30:05 +02:00
|
|
|
*
|
2023-10-05 14:05:42 +02:00
|
|
|
* @param {string} name
|
|
|
|
* @param {any} value
|
|
|
|
* @returns promise
|
2023-10-04 09:30:05 +02:00
|
|
|
*/
|
2023-10-30 12:57:19 +01:00
|
|
|
updatePreference(name, value, config = {}) {
|
|
|
|
return apiClient.put('/user/preferences/' + name, { value: value }, { ...config })
|
2023-10-04 09:30:05 +02:00
|
|
|
},
|
2023-10-05 14:09:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all webauthn devices
|
|
|
|
*
|
|
|
|
* @param {string} name
|
|
|
|
* @param {any} value
|
|
|
|
* @returns promise
|
|
|
|
*/
|
|
|
|
getWebauthnDevices(config = {}) {
|
2023-10-30 12:57:19 +01:00
|
|
|
return webClient.get('/webauthn/credentials', { ...config })
|
2023-10-05 14:09:04 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Revoke a webauthn device
|
|
|
|
*
|
|
|
|
* @param {string} name
|
|
|
|
* @param {any} value
|
|
|
|
* @returns promise
|
|
|
|
*/
|
|
|
|
revokeWebauthnDevice(credentialId, config = {}) {
|
2023-10-30 12:57:19 +01:00
|
|
|
return webClient.delete('/webauthn/credentials/' + credentialId, { ...config })
|
2023-10-05 14:09:04 +02:00
|
|
|
},
|
2023-10-06 10:45:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all user PATs
|
|
|
|
*
|
|
|
|
* @param {*} config
|
2024-01-29 08:55:56 +01:00
|
|
|
* @returns promise
|
2023-10-06 10:45:10 +02:00
|
|
|
*/
|
|
|
|
getPersonalAccessTokens(config = {}) {
|
2023-10-30 12:57:19 +01:00
|
|
|
return webClient.get('/oauth/personal-access-tokens', { ...config })
|
2023-10-06 10:45:10 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete a user PAT
|
|
|
|
*
|
|
|
|
* @param {*} tokenId
|
2024-01-29 08:55:56 +01:00
|
|
|
* @returns promise
|
2023-10-06 10:45:10 +02:00
|
|
|
*/
|
|
|
|
deletePersonalAccessToken(tokenId, config = {}) {
|
2023-10-30 12:57:19 +01:00
|
|
|
return webClient.delete('/oauth/personal-access-tokens/' + tokenId, { ...config })
|
2024-01-29 08:55:56 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get all registered users
|
|
|
|
*
|
|
|
|
* @returns promise
|
|
|
|
*/
|
|
|
|
getAll(config = {}) {
|
|
|
|
return apiClient.get('/users', { ...config })
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a registered user by id
|
|
|
|
*
|
|
|
|
* @returns promise
|
|
|
|
*/
|
|
|
|
getById(id, config = {}) {
|
|
|
|
return apiClient.get('/users/' + id, { ...config })
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset user password
|
|
|
|
*
|
|
|
|
* @returns promise
|
|
|
|
*/
|
|
|
|
resetPassword(id, config = {}) {
|
|
|
|
return apiClient.patch('/users/' + id + '/password/reset', {}, { ...config })
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete user
|
|
|
|
*
|
|
|
|
* @returns promise
|
|
|
|
*/
|
|
|
|
delete(id, config = {}) {
|
|
|
|
return apiClient.delete('/users/' + id, { ...config })
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2024-03-14 15:09:05 +01:00
|
|
|
* Promote or demote user from the admin role
|
2024-01-29 08:55:56 +01:00
|
|
|
*
|
|
|
|
* @returns promise
|
|
|
|
*/
|
2024-03-14 15:09:05 +01:00
|
|
|
promote(id, payload, config = {}) {
|
|
|
|
return apiClient.patch('/users/' + id + '/promote', payload, { ...config })
|
2024-01-29 08:55:56 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Purge user's PATs
|
|
|
|
*
|
|
|
|
* @returns promise
|
|
|
|
*/
|
|
|
|
revokePATs(id, config = {}) {
|
|
|
|
return apiClient.delete('/users/' + id + '/pats', { ...config })
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Purge user's PATs
|
|
|
|
*
|
|
|
|
* @returns promise
|
|
|
|
*/
|
|
|
|
revokeWebauthnCredentials(id, config = {}) {
|
|
|
|
return apiClient.delete('/users/' + id + '/credentials', { ...config })
|
|
|
|
},
|
2024-04-15 00:44:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get user's authentication logs
|
|
|
|
*
|
|
|
|
* @returns promise
|
|
|
|
*/
|
2024-04-15 18:39:37 +02:00
|
|
|
getauthentications(id, period = 90, limit, config = {}) {
|
|
|
|
return apiClient.get('/users/' + id + '/authentications?period=' + period + (limit ? '&limit=' + limit : ''), { ...config })
|
2024-04-15 00:44:18 +02:00
|
|
|
},
|
2023-10-04 09:30:05 +02:00
|
|
|
|
|
|
|
}
|