diff --git a/src/client/Mastodon.ts b/src/client/Mastodon.ts index 81c2de7c7..f62c8a910 100644 --- a/src/client/Mastodon.ts +++ b/src/client/Mastodon.ts @@ -3,7 +3,7 @@ import { EventHandler } from './EventHandler'; import { getNextUrl } from './linkHeader'; import * as Options from './options'; -import { Account, AccountCredentials } from '../entities/Account'; +import { Account, AccountCredentials, AccountToken } from '../entities/Account'; import { Application, OAuth } from '../entities/Application'; import { Attachment } from '../entities/Attachment'; import { Card } from '../entities/Card'; @@ -123,7 +123,7 @@ export class Mastodon extends Gateway { * @see https://docs.joinmastodon.org/api/authentication/ */ public async fetchAccessToken (code: string, client_id: string, client_secret: string, redirect_uri: string, grant_type = 'authorization_code') { - return (await this.post<{ access_token: string }>(`${this.url}/oauth/token`, { code, client_id, client_secret, redirect_uri, grant_type })).data; + return (await this.post(`${this.url}/oauth/token`, { code, client_id, client_secret, redirect_uri, grant_type })).data; } /** @@ -136,6 +136,15 @@ export class Mastodon extends Gateway { return (await this.get(`${this.url}/api/v1/accounts/${id}`)).data; } + /** + * Create an account + * @param options Data of the user to create + * @return Access token + */ + public async createAccount (options: Options.CreateAccount) { + return (await this.post(`${this.url}/api/v1/accounts`, options)); + } + /** * User’s own account. * @return Returns Account with an extra source attribute. diff --git a/src/client/options.ts b/src/client/options.ts index 9dcaba800..42329c8d2 100644 --- a/src/client/options.ts +++ b/src/client/options.ts @@ -152,3 +152,17 @@ export interface AddPushSubscription { } export type UpdatePushSubscription = Pick; + +export interface CreateAccount { + /** Username to create */ + username: string; + + /** Password of the user */ + password: string; + + /** Email of the user */ + email: string; + + /** Whether the user has been agreed to the agreement of the Mastodon instance */ + agreement: boolean; +} diff --git a/src/entities/Account.ts b/src/entities/Account.ts index 64fe77f0f..bfcee277e 100644 --- a/src/entities/Account.ts +++ b/src/entities/Account.ts @@ -69,10 +69,10 @@ export interface AccountField { } export interface AccountCredentials extends Account { - source: AccountCredentialsSource; + source: AccountSource; } -export interface AccountCredentialsSource { +export interface AccountSource { /** Selected preference: Default privacy of new toots */ privacy?: StatusVisibility | null; @@ -89,3 +89,16 @@ export interface AccountCredentialsSource { fields: AccountField; } +export interface AccountToken { + /** Access token of the account */ + access_token: string; + + /** Type of the token */ + token_type: string; + + /** Scope of the token */ + scope: string; + + /** Created date of the token */ + created_at: string; +}