Files
MatrixGW/matrixgw_frontend/src/api/TokensApi.ts
Pierre HUBERT fb35fca56e
Some checks failed
continuous-integration/drone/pr Build is failing
continuous-integration/drone/push Build is passing
Fix build issues
2025-12-03 14:53:06 +01:00

57 lines
1.0 KiB
TypeScript

import { APIClient } from "./ApiClient";
export interface BaseToken {
name: string;
networks?: string[];
max_inactivity: number;
expiration?: number;
read_only: boolean;
}
export interface Token extends BaseToken {
id: number;
created: number;
last_used: number;
}
export interface TokenWithSecret extends Token {
secret: string;
}
export class TokensApi {
/**
* Get the list of tokens of the current user
*/
static async GetList(): Promise<Token[]> {
return (
await APIClient.exec({
uri: "/tokens",
method: "GET",
})
).data as Token[];
}
/**
* Create a new token
*/
static async Create(t: BaseToken): Promise<TokenWithSecret> {
return (
await APIClient.exec({
uri: "/token",
method: "POST",
jsonData: t,
})
).data as TokenWithSecret;
}
/**
* Delete a token
*/
static async Delete(t: Token): Promise<void> {
await APIClient.exec({
uri: `/token/${t.id}`,
method: "DELETE",
});
}
}