@archon-inc/sdk
Version:
Integrate easily to our government platform using this SDK. More info on https://archon.inc/sdk
21 lines (18 loc) • 732 B
text/typescript
import { Archon } from "../Archon.js";
import { Role } from "../types/policy.js";
import { User, UserId } from "../types/user.js";
/**
* Given a user or user id, return the roles the user has.
*
* **Warning:** Provides one layer deep of parents for each role, but no further.
* @param user The user to get the roles for.
* @returns A list of roles the user has.
*/
export default async function getRoles(user: User | UserId): Promise<Role[]> {
const userId = typeof user === "string" ? user : user.id;
const response = await Archon.request(`/policy/roles/${userId}`, "GET");
if (response.status !== 200) {
throw new Error(`Failed to retrieve roles for user ${user}.`);
}
return response.data;
}