From 382374e4d69b23a17a4f74bbc78d35a939199701 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Thu, 28 Nov 2024 11:11:18 +0100 Subject: [PATCH] feat(client): :sparkles: Add full 0.8 Role API --- client/types/versia.ts | 4 +- client/versia/client.ts | 136 ++++++++++++++++++++++++++++++++++++---- 2 files changed, 125 insertions(+), 15 deletions(-) diff --git a/client/types/versia.ts b/client/types/versia.ts index 59e42e9..ab7a5ca 100644 --- a/client/types/versia.ts +++ b/client/types/versia.ts @@ -3,9 +3,9 @@ export type VersiaRole = { name: string; permissions: RolePermission[]; priority: number; - description: string | null; + description?: string; visible: boolean; - icon: string | null; + icon?: string; }; // Last updated: 2024-11-28 diff --git a/client/versia/client.ts b/client/versia/client.ts index 7c1c435..8e0a206 100644 --- a/client/versia/client.ts +++ b/client/versia/client.ts @@ -104,16 +104,22 @@ export class Client extends BaseClient { } /** - * POST /api/v1/roles/:roleId + * POST /api/v1/accounts/:account_id/roles/:role_id * * Versia API only. - * @param roleId ID of the role to add to the requesting account. + * @param account_id The account ID. + * @param role_id The role ID. */ - public addRole( + public assignRole( + account_id: string, role_id: string, extra?: RequestInit, ): Promise> { - return this.post(`/api/v1/roles/${role_id}`, undefined, extra); + return this.post( + `/api/v1/accounts/${account_id}/roles/${role_id}`, + undefined, + extra, + ); } /** @@ -242,6 +248,36 @@ export class Client extends BaseClient { return this.post("/api/v1/lists", { title }, extra); } + /** + * POST /api/v1/roles + * + * Versia API only. + * @param name Name of the role. + * @param options.permissions Array of permissions. + * @param options.priority Role priority. + * @param options.description Role description. + * @param options.visible Role visibility. + * @param options.icon Role icon (URL). + * @returns Role + */ + public createRole( + name: string, + options: Partial<{ + permissions: string[]; + priority: number; + description: string; + visible: boolean; + icon: string; + }>, + extra?: RequestInit, + ): Promise> { + return this.post( + "/api/v1/roles", + { name, ...options }, + extra, + ); + } + /** * DELETE /api/v1/lists/:id/accounts * @@ -279,6 +315,7 @@ export class Client extends BaseClient { /** * DELETE /api/v1/emojis/:id * + * Versia API only. * @param id The emoji to delete's ID. * @return Empty. */ @@ -338,6 +375,17 @@ export class Client extends BaseClient { return this.delete("/api/v1/push/subscription", undefined, extra); } + /** + * DELETE /api/v1/roles/:id + * + * Versia API only. + * @param id The role ID. + * @return Empty. + */ + public deleteRole(id: string, extra?: RequestInit): Promise> { + return this.delete(`/api/v1/roles/${id}`, undefined, extra); + } + /** * DELETE /api/v1/statuses/:id * @@ -423,11 +471,7 @@ export class Client extends BaseClient { }>, extra?: RequestInit, ): Promise> { - return this.put( - `/api/v1/statuses/${id}`, - { ...options }, - extra, - ); + return this.put(`/api/v1/statuses/${id}`, options, extra); } /** @@ -497,7 +541,7 @@ export class Client extends BaseClient { ): Promise> { return this.post( `/api/v1/accounts/${id}/follow`, - { ...options }, + options, extra, ); } @@ -664,6 +708,20 @@ export class Client extends BaseClient { return this.get(`/api/v1/accounts/${id}/lists`, extra); } + /** + * GET /api/v1/accounts/:id/roles + * + * Versia API only. + * @param id The account ID. + * @return Array of roles. + */ + public getAccountRoles( + id: string, + extra?: RequestInit, + ): Promise> { + return this.get(`/api/v1/accounts/${id}/roles`, extra); + } + /** * GET /api/v1/accounts/:id/statuses * @@ -916,6 +974,7 @@ export class Client extends BaseClient { /** * GET /api/v1/emojis/:id * + * Versia API only. * @param id The emoji ID. * @return Emoji. */ @@ -1589,6 +1648,7 @@ export class Client extends BaseClient { /** * GET /api/v1/roles/:id * + * Versia API only. * @param id Target role ID. * @return Role. */ @@ -1932,7 +1992,7 @@ export class Client extends BaseClient { ): Promise> { return this.post( `/api/v1/accounts/${id}/mute`, - { ...options }, + options, extra, ); } @@ -2063,7 +2123,7 @@ export class Client extends BaseClient { ): Promise> { return this.post( `/api/v1/statuses/${id}/reblog`, - { ...options }, + options, extra, ); } @@ -2470,6 +2530,26 @@ export class Client extends BaseClient { // TODO: tagStreaming + /** + * DELETE /api/v1/accounts/:account_id/roles/:role_id + * + * Versia API only. + * @param account_id Account ID to remove the role from. + * @param role_id Role ID to remove from the account. + * @returns No content. + */ + public unassignRole( + account_id: string, + role_id: string, + extra?: RequestInit, + ): Promise> { + return this.delete( + `/api/v1/accounts/${account_id}/roles/${role_id}`, + undefined, + extra, + ); + } + /** * POST /api/v1/accounts/:id/unblock * @@ -2663,6 +2743,7 @@ export class Client extends BaseClient { /** * PATCH /api/v1/emojis/:id * + * Versia API only. * @param id Target emoji ID. * @param options.shortcode Emoji shortcode. * @param options.image Emoji image, as a File, or a URL. @@ -2716,7 +2797,7 @@ export class Client extends BaseClient { }, extra?: RequestInit, ): Promise> { - return this.put(`/api/v1/lists/${id}`, { ...options }, extra); + return this.put(`/api/v1/lists/${id}`, options, extra); } /** @@ -2787,9 +2868,38 @@ export class Client extends BaseClient { ); } + /** + * PATCH /api/v1/roles/:id + * + * Versia API only. + * @param id Role ID to update. + * @param options.name New role name. + * @param options.permissions New role permissions. + * @param options.priority New role priority. + * @param options.description New role description. + * @param options.visible New role visibility. + * @param options.icon New role icon. + * @returns New role data. + */ + public updateRole( + id: string, + options: Partial<{ + name: string; + permissions: string[]; + priority: number; + description: string; + visible: boolean; + icon: string; + }>, + extra?: RequestInit, + ): Promise> { + return this.patch(`/api/v1/roles/${id}`, options, extra); + } + /** * POST /api/v1/emojis * + * Versia API only. * @param shortcode The shortcode of the emoji. * @param image The image file to be uploaded, as a File or URL. * @param options.category A category for the emoji.