Skip to content

Commit

Permalink
feat(federation): ✨ Add full 0.8 Role API
Browse files Browse the repository at this point in the history
  • Loading branch information
CPlusPatch committed Nov 28, 2024
1 parent 6660065 commit 0ff6cdd
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 15 deletions.
4 changes: 2 additions & 2 deletions client/types/versia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
136 changes: 123 additions & 13 deletions client/versia/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output<void>> {
return this.post<void>(`/api/v1/roles/${role_id}`, undefined, extra);
return this.post<void>(
`/api/v1/accounts/${account_id}/roles/${role_id}`,
undefined,
extra,
);
}

/**
Expand Down Expand Up @@ -242,6 +248,36 @@ export class Client extends BaseClient {
return this.post<List>("/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<Output<VersiaRole>> {
return this.post<VersiaRole>(
"/api/v1/roles",
{ name, ...options },
extra,
);
}

/**
* DELETE /api/v1/lists/:id/accounts
*
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -338,6 +375,17 @@ export class Client extends BaseClient {
return this.delete<void>("/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<Output<void>> {
return this.delete<void>(`/api/v1/roles/${id}`, undefined, extra);
}

/**
* DELETE /api/v1/statuses/:id
*
Expand Down Expand Up @@ -423,11 +471,7 @@ export class Client extends BaseClient {
}>,
extra?: RequestInit,
): Promise<Output<Status>> {
return this.put<Status>(
`/api/v1/statuses/${id}`,
{ ...options },
extra,
);
return this.put<Status>(`/api/v1/statuses/${id}`, options, extra);
}

/**
Expand Down Expand Up @@ -497,7 +541,7 @@ export class Client extends BaseClient {
): Promise<Output<Relationship>> {
return this.post<Relationship>(
`/api/v1/accounts/${id}/follow`,
{ ...options },
options,
extra,
);
}
Expand Down Expand Up @@ -664,6 +708,20 @@ export class Client extends BaseClient {
return this.get<List[]>(`/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<Output<VersiaRole[]>> {
return this.get<VersiaRole[]>(`/api/v1/accounts/${id}/roles`, extra);
}

/**
* GET /api/v1/accounts/:id/statuses
*
Expand Down Expand Up @@ -916,6 +974,7 @@ export class Client extends BaseClient {
/**
* GET /api/v1/emojis/:id
*
* Versia API only.
* @param id The emoji ID.
* @return Emoji.
*/
Expand Down Expand Up @@ -1589,6 +1648,7 @@ export class Client extends BaseClient {
/**
* GET /api/v1/roles/:id
*
* Versia API only.
* @param id Target role ID.
* @return Role.
*/
Expand Down Expand Up @@ -1932,7 +1992,7 @@ export class Client extends BaseClient {
): Promise<Output<Relationship>> {
return this.post<Relationship>(
`/api/v1/accounts/${id}/mute`,
{ ...options },
options,
extra,
);
}
Expand Down Expand Up @@ -2063,7 +2123,7 @@ export class Client extends BaseClient {
): Promise<Output<Status>> {
return this.post<Status>(
`/api/v1/statuses/${id}/reblog`,
{ ...options },
options,
extra,
);
}
Expand Down Expand Up @@ -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<Output<void>> {
return this.delete<void>(
`/api/v1/accounts/${account_id}/roles/${role_id}`,
undefined,
extra,
);
}

/**
* POST /api/v1/accounts/:id/unblock
*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -2716,7 +2797,7 @@ export class Client extends BaseClient {
},
extra?: RequestInit,
): Promise<Output<List>> {
return this.put<List>(`/api/v1/lists/${id}`, { ...options }, extra);
return this.put<List>(`/api/v1/lists/${id}`, options, extra);
}

/**
Expand Down Expand Up @@ -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<Output<VersiaRole>> {
return this.patch<VersiaRole>(`/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.
Expand Down

0 comments on commit 0ff6cdd

Please sign in to comment.