mirror of
https://github.com/versia-pub/api.git
synced 2025-12-06 08:28:19 +01:00
feat(client): ✨ Add role API, expose more HTTP internals
This commit is contained in:
parent
d54a7462ce
commit
24c5f3effd
|
|
@ -134,7 +134,7 @@ export class BaseClient {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async get<ReturnType>(
|
public async get<ReturnType>(
|
||||||
path: string,
|
path: string,
|
||||||
extra?: RequestInit,
|
extra?: RequestInit,
|
||||||
): Promise<Output<ReturnType>> {
|
): Promise<Output<ReturnType>> {
|
||||||
|
|
@ -143,7 +143,7 @@ export class BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async post<ReturnType>(
|
public async post<ReturnType>(
|
||||||
path: string,
|
path: string,
|
||||||
body?: object,
|
body?: object,
|
||||||
extra?: RequestInit,
|
extra?: RequestInit,
|
||||||
|
|
@ -153,7 +153,7 @@ export class BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async postForm<ReturnType>(
|
public async postForm<ReturnType>(
|
||||||
path: string,
|
path: string,
|
||||||
body: FormData | ConvertibleObject,
|
body: FormData | ConvertibleObject,
|
||||||
extra?: RequestInit,
|
extra?: RequestInit,
|
||||||
|
|
@ -168,7 +168,7 @@ export class BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async put<ReturnType>(
|
public async put<ReturnType>(
|
||||||
path: string,
|
path: string,
|
||||||
body?: object,
|
body?: object,
|
||||||
extra?: RequestInit,
|
extra?: RequestInit,
|
||||||
|
|
@ -178,7 +178,7 @@ export class BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async putForm<ReturnType>(
|
public async putForm<ReturnType>(
|
||||||
path: string,
|
path: string,
|
||||||
body: FormData | ConvertibleObject,
|
body: FormData | ConvertibleObject,
|
||||||
extra?: RequestInit,
|
extra?: RequestInit,
|
||||||
|
|
@ -193,7 +193,7 @@ export class BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async patch<ReturnType>(
|
public async patch<ReturnType>(
|
||||||
path: string,
|
path: string,
|
||||||
body?: object,
|
body?: object,
|
||||||
extra?: RequestInit,
|
extra?: RequestInit,
|
||||||
|
|
@ -203,7 +203,7 @@ export class BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async patchForm<ReturnType>(
|
public async patchForm<ReturnType>(
|
||||||
path: string,
|
path: string,
|
||||||
body: FormData | ConvertibleObject,
|
body: FormData | ConvertibleObject,
|
||||||
extra?: RequestInit,
|
extra?: RequestInit,
|
||||||
|
|
@ -218,7 +218,7 @@ export class BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async delete<ReturnType>(
|
public async delete<ReturnType>(
|
||||||
path: string,
|
path: string,
|
||||||
body?: object,
|
body?: object,
|
||||||
extra?: RequestInit,
|
extra?: RequestInit,
|
||||||
|
|
@ -228,7 +228,7 @@ export class BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async deleteForm<ReturnType>(
|
public async deleteForm<ReturnType>(
|
||||||
path: string,
|
path: string,
|
||||||
body: FormData | ConvertibleObject,
|
body: FormData | ConvertibleObject,
|
||||||
extra?: RequestInit,
|
extra?: RequestInit,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import type { Emoji } from "../types/emoji";
|
||||||
import type { FeaturedTag } from "../types/featured_tag";
|
import type { FeaturedTag } from "../types/featured_tag";
|
||||||
import type { ExtendedDescription, Instance } from "../types/instance";
|
import type { ExtendedDescription, Instance } from "../types/instance";
|
||||||
import type { List } from "../types/list";
|
import type { List } from "../types/list";
|
||||||
|
import type { LysandRole } from "../types/lysand";
|
||||||
import type { Marker } from "../types/marker";
|
import type { Marker } from "../types/marker";
|
||||||
import type { Notification } from "../types/notification";
|
import type { Notification } from "../types/notification";
|
||||||
import type { Poll } from "../types/poll";
|
import type { Poll } from "../types/poll";
|
||||||
|
|
@ -98,6 +99,16 @@ export class LysandClient extends BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /api/v1/roles/:roleId
|
||||||
|
*
|
||||||
|
* Lysand API only.
|
||||||
|
* @param roleId ID of the role to add to the requesting account.
|
||||||
|
*/
|
||||||
|
public addRole(roleId: string, extra?: RequestInit): Promise<Output<void>> {
|
||||||
|
return this.post<void>(`/api/v1/roles/${roleId}`, undefined, extra);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /api/v1/accounts/:id/block
|
* POST /api/v1/accounts/:id/block
|
||||||
*
|
*
|
||||||
|
|
@ -1359,6 +1370,29 @@ export class LysandClient extends BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/v1/roles/:id
|
||||||
|
*
|
||||||
|
* @param id Target role ID.
|
||||||
|
* @return Role.
|
||||||
|
*/
|
||||||
|
public getRole(
|
||||||
|
id: string,
|
||||||
|
extra?: RequestInit,
|
||||||
|
): Promise<Output<LysandRole>> {
|
||||||
|
return this.get<LysandRole>(`/api/v1/roles/${id}`, extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/v1/roles
|
||||||
|
*
|
||||||
|
* Lysand API only.
|
||||||
|
* @returns Array of roles.
|
||||||
|
*/
|
||||||
|
public getRoles(extra?: RequestInit): Promise<Output<LysandRole[]>> {
|
||||||
|
return this.get<LysandRole[]>("/api/v1/roles", extra);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api/v1/scheduled_statuses/:id
|
* GET /api/v1/scheduled_statuses/:id
|
||||||
*
|
*
|
||||||
|
|
@ -1889,6 +1923,20 @@ export class LysandClient extends BaseClient {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE /api/v1/roles/:roleId
|
||||||
|
*
|
||||||
|
* Lysand API only.
|
||||||
|
* @param roleId Role ID to remove from requesting account.
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public removeRole(
|
||||||
|
roleId: string,
|
||||||
|
extra?: RequestInit,
|
||||||
|
): Promise<Output<void>> {
|
||||||
|
return this.delete<void>(`/api/v1/roles/${roleId}`, undefined, extra);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* POST /api/v1/reports
|
* POST /api/v1/reports
|
||||||
*
|
*
|
||||||
|
|
|
||||||
56
client/types/lysand.ts
Normal file
56
client/types/lysand.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
export type LysandRole = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
permissions: LysandRolePermissions[];
|
||||||
|
priority: number;
|
||||||
|
description: string | null;
|
||||||
|
visible: boolean;
|
||||||
|
icon: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Last updated: 2024-06-07
|
||||||
|
export enum LysandRolePermissions {
|
||||||
|
MANAGE_NOTES = "notes",
|
||||||
|
MANAGE_OWN_NOTES = "owner:note",
|
||||||
|
VIEW_NOTES = "read:note",
|
||||||
|
VIEW_NOTE_LIKES = "read:note_likes",
|
||||||
|
VIEW_NOTE_BOOSTS = "read:note_boosts",
|
||||||
|
MANAGE_ACCOUNTS = "accounts",
|
||||||
|
MANAGE_OWN_ACCOUNT = "owner:account",
|
||||||
|
VIEW_ACCOUNT_FOLLOWS = "read:account_follows",
|
||||||
|
MANAGE_LIKES = "likes",
|
||||||
|
MANAGE_OWN_LIKES = "owner:like",
|
||||||
|
MANAGE_BOOSTS = "boosts",
|
||||||
|
MANAGE_OWN_BOOSTS = "owner:boost",
|
||||||
|
VIEW_ACCOUNTS = "read:account",
|
||||||
|
MANAGE_EMOJIS = "emojis",
|
||||||
|
VIEW_EMOJIS = "read:emoji",
|
||||||
|
MANAGE_OWN_EMOJIS = "owner:emoji",
|
||||||
|
MANAGE_MEDIA = "media",
|
||||||
|
MANAGE_OWN_MEDIA = "owner:media",
|
||||||
|
MANAGE_BLOCKS = "blocks",
|
||||||
|
MANAGE_OWN_BLOCKS = "owner:block",
|
||||||
|
MANAGE_FILTERS = "filters",
|
||||||
|
MANAGE_OWN_FILTERS = "owner:filter",
|
||||||
|
MANAGE_MUTES = "mutes",
|
||||||
|
MANAGE_OWN_MUTES = "owner:mute",
|
||||||
|
MANAGE_REPORTS = "reports",
|
||||||
|
MANAGE_OWN_REPORTS = "owner:report",
|
||||||
|
MANAGE_SETTINGS = "settings",
|
||||||
|
MANAGE_OWN_SETTINGS = "owner:settings",
|
||||||
|
MANAGE_ROLES = "roles",
|
||||||
|
MANAGE_NOTIFICATIONS = "notifications",
|
||||||
|
MANAGE_OWN_NOTIFICATIONS = "owner:notification",
|
||||||
|
MANAGE_FOLLOWS = "follows",
|
||||||
|
MANAGE_OWN_FOLLOWS = "owner:follow",
|
||||||
|
MANAGE_OWN_APPS = "owner:app",
|
||||||
|
SEARCH = "search",
|
||||||
|
VIEW_PUBLIC_TIMELINES = "public_timelines",
|
||||||
|
VIEW_PRIVATE_TIMELINES = "private_timelines",
|
||||||
|
IGNORE_RATE_LIMITS = "ignore_rate_limits",
|
||||||
|
IMPERSONATE = "impersonate",
|
||||||
|
MANAGE_INSTANCE = "instance",
|
||||||
|
MANAGE_INSTANCE_FEDERATION = "instance:federation",
|
||||||
|
MANAGE_INSTANCE_SETTINGS = "instance:settings",
|
||||||
|
OAUTH = "oauth",
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue