2020-03-23 01:15:38 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
|
|
|
|
export interface ApiKey {
|
|
|
|
identifier: string;
|
|
|
|
description: string;
|
|
|
|
createdAt: Date | null;
|
|
|
|
lastUsedAt: Date | null;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const rawDataToApiKey = (data: any): ApiKey => ({
|
2021-07-29 03:53:54 +00:00
|
|
|
identifier: data.token_id,
|
2020-03-23 01:15:38 +00:00
|
|
|
description: data.description,
|
|
|
|
createdAt: data.created_at ? new Date(data.created_at) : null,
|
|
|
|
lastUsedAt: data.last_used_at ? new Date(data.last_used_at) : null,
|
|
|
|
});
|
|
|
|
|
|
|
|
export default (): Promise<ApiKey[]> => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http.get('/api/client/account/api-keys')
|
2020-03-23 01:25:29 +00:00
|
|
|
.then(({ data }) => resolve((data.data || []).map((d: any) => rawDataToApiKey(d.attributes))))
|
2020-03-23 01:15:38 +00:00
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|