Skip to content

Commit

Permalink
feat: Support /api/v1/admin/domain_allows (#744)
Browse files Browse the repository at this point in the history
* adding a new v4 andpoint allow-domain

* adding a new v4 andpoint allow-domain - fixing some of implementations

* change CreateDomainAllowParams to CreateDomainAllowParamss
  • Loading branch information
JacksonSamuel42 committed Dec 4, 2022
1 parent c59c6d7 commit dbdf59f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/clients/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export class MastoAdminClient {
readonly account: AdminRepositories.AccountRepository;
readonly report: AdminRepositories.ReportRepository;
readonly domainBlocks: AdminRepositories.DomainBlockRepository;
readonly domainAllows: AdminRepositories.DomainAllowRepository;

constructor(
private readonly http: Http,
Expand All @@ -29,6 +30,12 @@ export class MastoAdminClient {
this.version,
this.config,
);

this.domainAllows = new AdminRepositories.DomainAllowRepository(
this.http,
this.version,
this.config,
);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/entities/admin/domain-allow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface DomainAllow {
/** The ID of the domain allow in the database. */
id: string;
/** The domain of the domain allow in the database. */
domain: string;
/** The create date of the domain allow in the database. */
createdAt: string;
}
1 change: 1 addition & 0 deletions src/entities/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export type { AccountRole, Account } from './account';
export type { Report } from './report';
export type { DomainBlock, DomainBlockSeverity } from './domain-block';
export type { DomainAllow } from './domain-allow';
75 changes: 75 additions & 0 deletions src/repositories/admin/domain-allow-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import type { MastoConfig } from '../../config';
import { version } from '../../decorators';
import type { Admin } from '../../entities';
import type { Http } from '../../http';
import type { Repository } from '../repository';

export type FetchAllDomainAllowsParams = {
readonly limit?: number;
};

export interface CreateDomainAllowParams {
readonly domain: string;
}

export class DomainAllowRepository
implements
Repository<
Admin.DomainAllow,
CreateDomainAllowParams,
never,
never,
FetchAllDomainAllowsParams
>
{
constructor(
private readonly http: Http,
readonly version: string,
readonly config: MastoConfig,
) {}

/**
* Show information about all allowed domains
* @param params Parameters
* @return Array of DomainAllow
* @see https://docs.joinmastodon.org/methods/admin/
*/
@version({ since: '4.0.0' })
fetchAll(params?: FetchAllDomainAllowsParams): Promise<Admin.DomainAllow[]> {
return this.http.get('/api/v1/admin/domain_allows', params);
}

/**
* Show information about a single allowed domain
* @param id id of the domain
* @return DomainAllow
* @see https://docs.joinmastodon.org/methods/admin/
*/
@version({ since: '4.0.0' })
fetch(id: string): Promise<Admin.DomainAllow> {
return this.http.get(`/api/v1/admin/domain_allows/${id}`);
}

/**
* Add a domain to the list of domains allowed to federate,
* to be used when the instance is in allow-list federation mode.
* @param params parameters
* @return DomainAllow
* @see https://docs.joinmastodon.org/methods/admin/
*/
@version({ since: '4.0.0' })
create(params: CreateDomainAllowParams): Promise<Admin.DomainAllow> {
return this.http.post('/api/v1/admin/domain_allows', params);
}

/**
* Delete a domain from the allowed domains list.
* @param id id of domain
* @return DomainAllow
* @see https://docs.joinmastodon.org/methods/admin/
*/
@version({ since: '4.0.0' })
remove(id: string): Promise<Admin.DomainAllow> {
return this.http.delete(`/api/v1/admin/domain_allows/${id}`);
}
}
1 change: 1 addition & 0 deletions src/repositories/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './report-repository';
export * from './account-repository';
export * from './domain-block-repository';
export * from './domain-allow-repository';

0 comments on commit dbdf59f

Please sign in to comment.