From 24c5f3effdca4c3fe9f0be6c3ba93351f73d61d1 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sun, 9 Jun 2024 15:46:44 -1000 Subject: [PATCH] feat(client): :sparkles: Add role API, expose more HTTP internals --- client/lysand/base.ts | 18 ++++++------- client/lysand/lysand.ts | 48 +++++++++++++++++++++++++++++++++++ client/types/lysand.ts | 56 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 9 deletions(-) create mode 100644 client/types/lysand.ts diff --git a/client/lysand/base.ts b/client/lysand/base.ts index 45b57be..32dc888 100644 --- a/client/lysand/base.ts +++ b/client/lysand/base.ts @@ -134,7 +134,7 @@ export class BaseClient { }); } - protected async get( + public async get( path: string, extra?: RequestInit, ): Promise> { @@ -143,7 +143,7 @@ export class BaseClient { ); } - protected async post( + public async post( path: string, body?: object, extra?: RequestInit, @@ -153,7 +153,7 @@ export class BaseClient { ); } - protected async postForm( + public async postForm( path: string, body: FormData | ConvertibleObject, extra?: RequestInit, @@ -168,7 +168,7 @@ export class BaseClient { ); } - protected async put( + public async put( path: string, body?: object, extra?: RequestInit, @@ -178,7 +178,7 @@ export class BaseClient { ); } - protected async putForm( + public async putForm( path: string, body: FormData | ConvertibleObject, extra?: RequestInit, @@ -193,7 +193,7 @@ export class BaseClient { ); } - protected async patch( + public async patch( path: string, body?: object, extra?: RequestInit, @@ -203,7 +203,7 @@ export class BaseClient { ); } - protected async patchForm( + public async patchForm( path: string, body: FormData | ConvertibleObject, extra?: RequestInit, @@ -218,7 +218,7 @@ export class BaseClient { ); } - protected async delete( + public async delete( path: string, body?: object, extra?: RequestInit, @@ -228,7 +228,7 @@ export class BaseClient { ); } - protected async deleteForm( + public async deleteForm( path: string, body: FormData | ConvertibleObject, extra?: RequestInit, diff --git a/client/lysand/lysand.ts b/client/lysand/lysand.ts index b060479..9b69045 100644 --- a/client/lysand/lysand.ts +++ b/client/lysand/lysand.ts @@ -11,6 +11,7 @@ import type { Emoji } from "../types/emoji"; import type { FeaturedTag } from "../types/featured_tag"; import type { ExtendedDescription, Instance } from "../types/instance"; import type { List } from "../types/list"; +import type { LysandRole } from "../types/lysand"; import type { Marker } from "../types/marker"; import type { Notification } from "../types/notification"; 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> { + return this.post(`/api/v1/roles/${roleId}`, undefined, extra); + } + /** * 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> { + return this.get(`/api/v1/roles/${id}`, extra); + } + + /** + * GET /api/v1/roles + * + * Lysand API only. + * @returns Array of roles. + */ + public getRoles(extra?: RequestInit): Promise> { + return this.get("/api/v1/roles", extra); + } + /** * 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> { + return this.delete(`/api/v1/roles/${roleId}`, undefined, extra); + } + /** * POST /api/v1/reports * diff --git a/client/types/lysand.ts b/client/types/lysand.ts new file mode 100644 index 0000000..83f59f5 --- /dev/null +++ b/client/types/lysand.ts @@ -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", +}