import { Logger } from 'winston'; import { IPermitConfig } from '../config'; import { PaginatedResultUserRead, RoleAssignmentCreate, RoleAssignmentRead, RoleAssignmentRemove, UserCreate, UserRead, UserUpdate } from '../openapi'; import { BasePermitApi, IPagination } from './base'; export { PaginatedResultUserRead, RoleAssignmentCreate, RoleAssignmentRead, RoleAssignmentRemove, UserCreate, UserRead, UserUpdate, } from '../openapi'; export interface ICreateOrUpdateUserResult { /** * the created or updated user */ user: UserRead; /** * whether the user was newly created */ created: boolean; } export interface IGetUserRoles { /** * id or key of the user * @type {string} */ readonly user: string; /** * optional tenant filter, will only return role assignments granted in that tenant (id or key). * @type {string} */ readonly tenant?: string; /** * Page number of the results to fetch, starting at 1. * @type {number} */ readonly page?: number; /** * The number of results per page (max 100). * @type {number} */ readonly perPage?: number; } export interface IUsersApi { /** * Retrieves a list of users. * * @param pagination The pagination options, @see {@link IPagination} * @returns A promise that resolves to a PaginatedResultUserRead object containing the list of users. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ list(pagination?: IPagination): Promise; /** * Retrieves a user by its key. * * @param userKey The key of the user. * @returns A promise that resolves to the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ get(userKey: string): Promise; /** * Retrieves a user by its key. * Alias for the {@link get} method. * * @param userKey The key of the user. * @returns A promise that resolves to the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ getByKey(userKey: string): Promise; /** * Retrieves a user by its ID. * Alias for the {@link get} method. * * @param userId The ID of the user. * @returns A promise that resolves to the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ getById(userId: string): Promise; /** * Creates a new user. * * @param userData The data for the new user. * @returns A promise that resolves to the created user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ create(userData: UserCreate): Promise; /** * Updates a user. * * @param userKey The key of the user. * @param userData The updated data for the user. * @returns A promise that resolves to the updated user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ update(userKey: string, userData: UserUpdate): Promise; /** * Synchronizes user data by creating or updating a user. * * @param userData - The data of the user to be synchronized. * @returns A promise that resolves with the result of the user creation or update operation. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ sync(userData: UserCreate): Promise; /** * Deletes a user. * * @param userKey The key of the user to delete. * @returns A promise that resolves when the user is deleted. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ delete(userKey: string): Promise; /** * Assigns a role to a user in the scope of a given tenant. * * @param assignment - The role assignment details. * @returns A promise that resolves with the assigned role. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ assignRole(assignment: RoleAssignmentCreate): Promise; /** * Unassigns a role from a user in the scope of a given tenant. * * @param unassignment - The role unassignment details. * @returns A promise that resolves when the role is successfully unassigned from the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ unassignRole(unassignment: RoleAssignmentRemove): Promise; /** * Retrieves the roles assigned to a user in a given tenant (if the tenant filter is provided) * or across all tenants (if the tenant filter in not provided). * * @param roleFilters - The filters for retrieving role assignments. * @returns A promise that resolves with an array of role assignments for the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ getAssignedRoles({ user, tenant, page, perPage }: IGetUserRoles): Promise; } /** * The UsersApi class provides methods for interacting with Permit Users. */ export declare class UsersApi extends BasePermitApi implements IUsersApi { private users; private roleAssignments; /** * Creates an instance of the UsersApi. * @param config - The configuration object for the Permit SDK. * @param logger - The logger instance for logging. */ constructor(config: IPermitConfig, logger: Logger); /** * Retrieves a list of users. * * @param pagination The pagination options, @see {@link IPagination} * @returns A promise that resolves to a PaginatedResultUserRead object containing the list of users. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ list(pagination?: IPagination): Promise; /** * Retrieves a user by its key. * * @param userKey The key of the user. * @returns A promise that resolves to the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ get(userKey: string): Promise; /** * Retrieves a user by its key. * Alias for the {@link get} method. * * @param userKey The key of the user. * @returns A promise that resolves to the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ getByKey(userKey: string): Promise; /** * Retrieves a user by its ID. * Alias for the {@link get} method. * * @param userId The ID of the user. * @returns A promise that resolves to the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ getById(userId: string): Promise; /** * Creates a new user. * * @param userData The data for the new user. * @returns A promise that resolves to the created user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ create(userData: UserCreate): Promise; /** * Updates a user. * * @param userKey The key of the user. * @param userData The updated data for the user. * @returns A promise that resolves to the updated user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ update(userKey: string, userData: UserUpdate): Promise; /** * Synchronizes user data by creating or updating a user. * * @param userData - The data of the user to be synchronized. * @returns A promise that resolves with the result of the user creation or update operation. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ sync(userData: UserCreate): Promise; /** * Deletes a user. * * @param userKey The key of the user to delete. * @returns A promise that resolves when the user is deleted. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ delete(userKey: string): Promise; /** * Assigns a role to a user in the scope of a given tenant. * * @param assignment - The role assignment details. * @returns A promise that resolves with the assigned role. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ assignRole(assignment: RoleAssignmentCreate): Promise; /** * Unassigns a role from a user in the scope of a given tenant. * * @param unassignment - The role unassignment details. * @returns A promise that resolves when the role is successfully unassigned from the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ unassignRole(unassignment: RoleAssignmentRemove): Promise; /** * Retrieves the roles assigned to a user in a given tenant (if the tenant filter is provided) * or across all tenants (if the tenant filter in not provided). * * @param roleFilters - The filters for retrieving role assignments. * @returns A promise that resolves with an array of role assignments for the user. * @throws {@link PermitApiError} If the API returns an error HTTP status code. * @throws {@link PermitContextError} If the configured {@link ApiContext} does not match the required endpoint context. */ getAssignedRoles({ user, tenant, page, perPage, }: IGetUserRoles): Promise; }