import { BaseApi } from "./base-api.ts"; export type Oauth2ApplicationCreateParams = { name: string, redirect_uris: string[], confidential_client?: boolean, } export type Oauth2Application = { id: number, name: string, redirect_uris: string[], client_id: string, confidential_client: boolean, /** * @format date-time */ created: string, } export type Oauth2ApplicationResponse = { client_secret: string, } & Oauth2Application export class OAuth2Api extends BaseApi { private token: string; constructor(baseUrl: string, token: string) { super(baseUrl); this.token = token; } async createOauth2Application(params: Oauth2ApplicationCreateParams): Promise { return await this.request(`/api/v1/user/applications/oauth2`, { method: "POST", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json", }, body: JSON.stringify(params), }); } async getOauth2Applications(): Promise { return await this.request(`/api/v1/user/applications/oauth2`, { method: "GET", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json", }, }); } async deleteOauth2Application(id: number): Promise { if (!this.token) { throw new Error("Authentication required. Please login first."); } await this.request(`/api/v1/user/applications/oauth2/${id}`, { method: "DELETE", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json", }, }); } async updateOauth2Application(id: number, params: Oauth2ApplicationCreateParams): Promise { return await this.request(`/api/v1/user/applications/oauth2/${id}`, { method: "PATCH", headers: { "Authorization": `Bearer ${this.token}`, "Content-Type": "application/json", }, body: JSON.stringify(params), }); } }