-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Olivier Léobal <[email protected]>
- Loading branch information
Showing
6 changed files
with
83 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
import { AxiosResponse } from 'axios'; | ||
|
||
import API from '@/libs/request'; | ||
|
||
import { RawBearerTokenT, RawNewBearerTokenT } from './BearerTokenTypes'; | ||
|
||
const URLS = { | ||
API_TOKEN: `/api-token`, | ||
ACTIVE_API_TOKENS: `/active-api-tokens`, | ||
}; | ||
|
||
export const requestToken = () => { | ||
export const requestToken = (): Promise<AxiosResponse<RawNewBearerTokenT>> => { | ||
return API.authenticatedGet(URLS.API_TOKEN); | ||
}; | ||
|
||
export const listActiveTokens = () => { | ||
export const listActiveTokens = (): Promise< | ||
AxiosResponse<{ tokens: RawBearerTokenT[] }> | ||
> => { | ||
return API.authenticatedGet(URLS.ACTIVE_API_TOKENS); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,21 @@ | ||
import { | ||
listActiveTokens as listActiveTokensFromApi, | ||
requestToken as requestTokensFromApi, | ||
} from './BearerTokenApi'; | ||
import { | ||
BearerTokenT, | ||
NewBearerTokenT, | ||
RawBearerTokenT, | ||
RawNewBearerTokenT, | ||
} from './BearerTokenTypes'; | ||
|
||
const parseToken = (object: RawBearerTokenT): BearerTokenT => { | ||
export const parseToken = (object: RawBearerTokenT): BearerTokenT => { | ||
return { | ||
created_at: new Date(object.created_at), | ||
expires_at: new Date(object.expires_at), | ||
}; | ||
}; | ||
|
||
const parseNewToken = (object: RawNewBearerTokenT): NewBearerTokenT => { | ||
export const parseNewToken = (object: RawNewBearerTokenT): NewBearerTokenT => { | ||
return { | ||
token: object.token, | ||
created_at: new Date(object.created_at), | ||
expires_at: new Date(object.expires_at), | ||
}; | ||
}; | ||
|
||
export const requestToken = (): Promise<NewBearerTokenT> => { | ||
return requestTokensFromApi().then((response) => { | ||
return parseNewToken(response.data); | ||
}); | ||
}; | ||
|
||
export const listActiveTokens = (): Promise<BearerTokenT[]> => { | ||
return listActiveTokensFromApi().then((response) => { | ||
return (response.data.tokens as RawBearerTokenT[]).map(parseToken); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters