import { GraphqlClient } from './../common/GraphqlClient'; import { ManagementTokenProvider } from './ManagementTokenProvider'; import { BatchFetchUserTypes, ManagementClientOptions, UserActions } from './types'; import { User, PaginatedUsers, CreateUserInput, RefreshToken, CommonMessage, UpdateUserInput, PaginatedGroups, PaginatedRoles, PaginatedAuthorizedResources, ResourceType, QuerySearchUserArgs } from '../../types/graphql.v2'; import { HttpClient } from '../common/HttpClient'; import { DeepPartial, KeyValuePair } from '../../types/index'; import { PublicKeyManager } from '../common/PublicKeyManager'; /** * @name UsersManagementClient * @description Approw User management module. * * This module can perform operations such as adding, deleting, modifying and querying user directories, searching for users, refreshing user tokens, managing user groups, managing user roles, and managing user policy authorization. * * All operations issued by this module will be performed as an administrator, so there is no need to perform operations such as suggesting SMS verification codes. If you want to operate as a normal user, please use AuthenticationClient. * * @example * * Please use the module in the following ways: * \`\`\`javascript * import { ManagementClient } from "appow-js-sdk" * const managementClient = new ManagementClient({ * userPoolId: "YOUR_USERPOOL_ID", * secret: "YOUR_USERPOOL_SECRET", * }) * * managementClient.users.list // Get user list * managementClient.users.create // Create user * managementClient.users.listRoles // Get a list of user roles * managementClient.users.search // Search users * \`\`\` * * @class UsersManagementClient Manage users */ export declare class UsersManagementClient { options: ManagementClientOptions; graphqlClient: GraphqlClient; httpClient: HttpClient; tokenProvider: ManagementTokenProvider; publickKeyManager: PublicKeyManager; constructor(options: ManagementClientOptions, graphqlClient: GraphqlClient, httpClient: HttpClient, tokenProvider: ManagementTokenProvider, publickKeyManager: PublicKeyManager); /** * @name create * @name_zh Create user * @description This interface will create a user as an administrator and does not need to perform security checks such as mobile phone number verification code verification. * * @param {CreateUserInput} userInfo user information * @param {string} userInfo.email email, unique in user pool * @param {boolean} userInfo.emailVerified if the email vertifuied * @param {string} userInfo.phone phone number * @param {boolean} userInfo.phoneVerified Is the phone number verified * @param {string} userInfo.unionid For users who log in socially, this field is the unique ID of the user in the third-party social login service provider * @param {string} userInfo.openid Openid returned by WeChat login * @param {string} userInfo.password password * @param {string} userInfo.registerSource Registration source, you can choose more than one * @param {string} userInfo.username user name * @param {string} userInfo.nickname nick name * @param {string} userInfo.photo photo * @param {string} userInfo.company company * @param {string} userInfo.browser browser * @param {number} userInfo.loginsCount The number of logins, you can set this field when you migrate from the original user system to Approw. * @param {string} userInfo.lastLogin Last login time, a time string conforming to the ISO8601 format. (E.g. "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00") * @param {string} userInfo.lastIP The IP of the user's last login (or other activity) * @param {string} userInfo.signedUp Registration time, a time string conforming to the ISO8601 format. (E.g. "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00") * @param {boolean} userInfo.blocked Whether the account is disabled * @param {boolean} userInfo.isDeleted Mark whether the account has been deleted * @param {string} userInfo.device device * @param {string} userInfo.lastIP last IP * @param {string} userInfo.name Name * @param {string} userInfo.givenName Given Name * @param {string} userInfo.familyName Family Name * @param {string} userInfo.middleName Middle Name * @param {string} userInfo.profile Profile Url * @param {string} userInfo.preferredUsername Preferred Name * @param {string} userInfo.website pesonal website * @param {string} userInfo.gender gender, F for male, W for famale, U for unknow * @param {string} userInfo.birthdate bithdate * @param {string} userInfo.zoneinfo time zone * @param {string} userInfo.locale language * @param {string} userInfo.address address * @param {string} userInfo.streetAddress street address * @param {string} userInfo.locality * @param {string} userInfo.region rergion * @param {string} userInfo.postalCode zip code * @param {string} userInfo.city city * @param {string} userInfo.province province * @param {string} userInfo.country contry * * @example * * const user = await managementClient.users.create({ * username: 'bob', * password: 'passw0rd' * }) * * @example * * const user = await managementClient.users.create({ * nickname: 'Nick', * phone: '176xxxx7041', // Since it is an administrator operation, check the verification code of the mobile phone number, if you need to check, please use AuthenticationClient * loginsCount: 2 // The number of user logins recorded by the original user system * signedUp: '2020-10-15T17:55:37+08:00' // User registration time recorded by the original user system * }) * * @returns {Promise} * @memberof UsersManagementClient */ create(userInfo: CreateUserInput, options?: { keepPassword?: boolean; }): Promise; /** * @name update * @name_zh update use * @description update use * * @param {string} id user ID * @param {UpdateUserInput} updates update use * @param {string} updates.email email * @param {boolean} updates.emailVerified whether the email vertified * @param {string} updates.phone phone number * @param {boolean} updates.phoneVerified Is the phone number verified * @param {string} updates.unionid For users who log in socially, this field is the unique ID of the user in the third-party social login service provider * @param {string} updates.openid Openid returned by WeChat login * @param {string} updates.password password * @param {string} updates.registerSource Registration source, you can choose more than one * @param {string} updates.tokenExpiredAt The token expiration time, a time string conforming to the ISO8601 format. (Such as "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00"). * Setting this field to be less than the current time can invalidate the user's token. * @param {string} updates.username user name * @param {string} updates.nickname nick name * @param {string} updates.photo photo * @param {string} updates.company company * @param {string} updates.browser browser * @param {number} updates.loginsCount The number of logins, you can set this field when you migrate from the original user system to Approw. * @param {string} updates.lastLogin Last login time, a time string conforming to the ISO8601 format. (E.g. "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00") * @param {string} updates.lastIP The IP of the user's last login (or other activity) * @param {string} updates.signedUp Registration time, a time string conforming to the ISO8601 format. (E.g. "2017-06-07T14:34:08.700Z", "2017-06-07T14:34:08.700 or "2017-06-07T14:34:08+04:00") * @param {boolean} updates.blocked Whether the account is disabled * @param {string} updates.device device * @param {string} updates.lastIP last IP * @param {string} updates.name Name * @param {string} updates.givenName Given Name * @param {string} updates.familyName Family Name * @param {string} updates.middleName Middle Name * @param {string} updates.profile Profile Url * @param {string} updates.preferredUsername Preferred Name * @param {string} updates.website pesonal website * @param {string} updates.gender gender, F for male, W for famale, U for unknow * @param {string} updates.birthdate bithdate * @param {string} updates.zoneinfo time zone * @param {string} updates.locale language * @param {string} updates.address address * @param {string} updates.streetAddress street address * @param {string} updates.locality * @param {string} updates.region rergion * @param {string} updates.postalCode zip code * @param {string} updates.city city * @param {string} updates.province province * @param {string} updates.country contry * * @example * * const user = await managementClient.users.update("USERID", { * nickname: "Nick" * }) * * @example * * const user = await managementClient.users.update("USERID" ,{ * nickname: 'Nick', * phone: '176xxxx7041', // Since it is an administrator operation, check the verification code of the mobile phone number, if you need to check, please use AuthenticationClient * tokenExpiredAt: '2020-10-15T17:55:37+08:00' * }) * * @returns {Promise} * @memberof UsersManagementClient * */ update(id: string, updates: UpdateUserInput): Promise; /** * @name detail * @name_zh Get user details * @description Get user details by user ID. If you want to get user details by token, please use AuthenticationClient SDK. * * @param {string} userId user ID * * @example * * const user = await managementClient.users.detail('USERID'); * * @returns {Promise} * @memberof UsersManagementClient */ detail(userId: string): Promise; /** * @name delete * @name_zh delete user * @description delete user * * @param {string} userId user ID * * @example * * const user = await managementClient.users.delete('USERID'); * * @returns {Promise} * @memberof UsersManagementClient */ delete(userId: string): Promise; /** * @name deleteMany * @name_zh batch delete users * @description batch delete users * * @param {string[]} userIds user ID list * * @example * * const user = await managementClient.users.deleteMany(['USERID']); * * @returns {Promise} * @memberof UsersManagementClient */ deleteMany(userIds: string[]): Promise; /** * @name batch * @name_zh betch get users * @description Get user details in batches by ID, username, email, phone, email, externalId * * @param {string[]} identifiers List of data to be queried, such as user ID list * @param {string} [type] List type, optional values are'id' ,'username' ,'phone' ,'email','externalId', the default is'id' * * @example * * const users = await managementClient.users.batch(['USERID'], options); * * @returns {Promise} * @memberof UsersManagementClient */ batch(ids: string[], options?: { queryField: BatchFetchUserTypes; }): Promise; /** * @name list * @name_zh get user list * @description get user list * * @param {number} [page=1] page number, Start from 1 * @param {number} [limit=10] Number of users per page * * @example * * const user = await managementClient.users.list(); * * @returns * @memberof UsersManagementClient */ list(page?: number, limit?: number): Promise<{ totalCount: number; list: { id: string; arn: string; userPoolId: string; status?: import("../../types/graphql.v2").UserStatus; username?: string; email?: string; emailVerified?: boolean; phone?: string; phoneVerified?: boolean; unionid?: string; openid?: string; nickname?: string; registerSource?: string[]; photo?: string; password?: string; oauth?: string; token?: string; tokenExpiredAt?: string; loginsCount?: number; lastLogin?: string; lastIP?: string; signedUp?: string; blocked?: boolean; isDeleted?: boolean; device?: string; browser?: string; company?: string; name?: string; givenName?: string; familyName?: string; middleName?: string; profile?: string; preferredUsername?: string; website?: string; gender?: string; birthdate?: string; zoneinfo?: string; locale?: string; address?: string; formatted?: string; streetAddress?: string; locality?: string; region?: string; postalCode?: string; city?: string; province?: string; country?: string; createdAt?: string; updatedAt?: string; externalId?: string; }[]; }>; /** * @name listArchivedUsers * @name_zh Get a list of archived users * @description Get a list of archived users * * @param {number} [page=1] page number, Start from 1 * @param {number} [limit=10] Number of users per page * * @example * * const user = await managementClient.users.listArchivedUsers(); * * @returns * @memberof UsersManagementClient */ listArchivedUsers(page?: number, limit?: number): Promise<{ totalCount: number; list: { id: string; arn: string; status?: import("../../types/graphql.v2").UserStatus; userPoolId: string; username?: string; email?: string; emailVerified?: boolean; phone?: string; phoneVerified?: boolean; unionid?: string; openid?: string; nickname?: string; registerSource?: string[]; photo?: string; password?: string; oauth?: string; token?: string; tokenExpiredAt?: string; loginsCount?: number; lastLogin?: string; lastIP?: string; signedUp?: string; blocked?: boolean; isDeleted?: boolean; device?: string; browser?: string; company?: string; name?: string; givenName?: string; familyName?: string; middleName?: string; profile?: string; preferredUsername?: string; website?: string; gender?: string; birthdate?: string; zoneinfo?: string; locale?: string; address?: string; formatted?: string; streetAddress?: string; locality?: string; region?: string; postalCode?: string; city?: string; province?: string; country?: string; createdAt?: string; updatedAt?: string; externalId?: string; }[]; }>; /** * @name exists * @name_zh check whether the user existed * @description Check whether the user exists. The currently detectable fields are user name, email address, and mobile phone number. * * * @param {Object} options * @param {string} [options.username] User name, case sensitive. * @param {string} [options.email] Mailbox, the mailbox is not case sensitive. * @param {string} [options.phone] phone number * * @example * * const exists = await managementClient.users.exists({ * username: "bob" * }); * * @returns {Promise} * @memberof UsersManagementClient */ exists(options: { username?: string; email?: string; phone?: string; externalId?: string; }): Promise; /** * @name find * @name_zh find user * @description Find users by username, email, mobile phone number * * @param {Object} options * @param {string} [options.username] User name, case sensitive. * @param {string} [options.email] Mailbox, the mailbox is not case sensitive. * @param {string} [options.phone] phone number * @param {string} [options.externalId] externalId * * @memberof UsersManagementClient */ find(options: { username?: string; email?: string; phone?: string; externalId?: string; }): Promise<{ id: string; arn: string; userPoolId: string; status?: import("../../types/graphql.v2").UserStatus; username?: string; email?: string; emailVerified?: boolean; phone?: string; phoneVerified?: boolean; unionid?: string; openid?: string; nickname?: string; registerSource?: string[]; photo?: string; password?: string; oauth?: string; token?: string; tokenExpiredAt?: string; loginsCount?: number; lastLogin?: string; lastIP?: string; signedUp?: string; blocked?: boolean; isDeleted?: boolean; device?: string; browser?: string; company?: string; name?: string; givenName?: string; familyName?: string; middleName?: string; profile?: string; preferredUsername?: string; website?: string; gender?: string; birthdate?: string; zoneinfo?: string; locale?: string; address?: string; formatted?: string; streetAddress?: string; locality?: string; region?: string; postalCode?: string; city?: string; province?: string; country?: string; createdAt?: string; updatedAt?: string; externalId?: string; }>; /** * @name search * @name_zh Search for users * @description Search users based on keywords * * @param query Query content * @param options Options * @param {string[]} [options.fields] Search user fields. If not specified, the fuzzy search will be performed by default from username, nickname, email, phone, company, name, givenName, familyName, middleName, profile, preferredUsername fields. * If you need a precise search, please use the find method. * @param {number} [options.page=1] * @param {number} [options.limit=10] * @param {Object} [options.departmentOpts] Restrictions, the department the user is in * @param {string} [options.departmentOpts.departmentId] department ID * @param {string} [options.departmentOpts.includeChildrenDepartments] Whether to include the sub-departments of this department * * @example * * const { totalCount, list } = await managementClient.users.search("Bob"); * * @returns {Promise} * @memberof UsersManagementClient */ search(query: string, options?: { fields?: string[]; page?: number; limit?: number; departmentOpts?: QuerySearchUserArgs['departmentOpts']; groupOpts?: QuerySearchUserArgs['groupOpts']; roleOpts?: QuerySearchUserArgs['roleOpts']; }): Promise; /** * @name refreshToken * @name_zh refresh user token * @description refresh user token * * @param {string} id user ID * * @example * * const { token } = await managementClient.users.refreshToken("USERID"); * * // Check the latest status of the token and get the token corresponding to the user * * const data = await managementClient.checkLoginStatus(token, { * fetchUserDetail: true * }); * * @returns {Promise} * @memberof UsersManagementClient */ refreshToken(id: string): Promise; /** * @name listGroups * @name_zh Get user group list * @description Get user group list * * @param {string} userId user ID * * @example * * const { list, totalCount} = await managementClient.users.listGroups("USERID"); * * @returns {Promise>} * @memberof UsersManagementClient */ listGroups(userId: string): Promise>; /** * @name addGroup * @name_zh add group * @description add group * * @param {string} userId uuser ID * @param {string} group group code * * @example * * const { code, message } = await managementClient.users.addGroup("USERID", "GROUP_CODE"); * * @returns {Promise} * @memberof UsersManagementClient */ addGroup(userId: string, group: string): Promise; /** * @name removeGroup * @name_zh remove group * @description remove group * * @param {string} userId user ID * @param {string} group group code * * @example * * const { code, message } = await managementClient.users.removeGroup("USERID", "GROUP_CODE"); * * @returns {Promise} * @memberof UsersManagementClient */ removeGroup(userId: string, group: string): Promise; /** * @name listRoles * @name_zh get role list * @description get role list * * @param {string} userId user ID * @param {string} namespace namespace * * @example * * const { list, totalCount} = await managementClient.users.listRoles("USERID"); * * @returns {Promise>} * @memberof UsersManagementClient */ listRoles(userId: string, namespace?: string): Promise>; /** * @name addRoles * @name_zh add roles * @description add user to roles * * @param {string} userId user ID * @param {string} roles role code list * @param {string} namespace namespace * * @example * * const { code, message } = await managementClient.users.addRoles("USERID", ["ROLEA"]); * * @returns {Promise} * @memberof UsersManagementClient */ addRoles(userId: string, roles: string[], namespace?: string): Promise; /** * @name removeRoles * @name_zh remove roles * @description romve user from roles * * @param {string} userId user ID * @param {string} roles role code list * @param {string} namespace nampace code * * @example * * const { code, message } = await managementClient.users.removeRoles("USERID", ["ROLEA"]); * * @returns {Promise} * @memberof UsersManagementClient */ removeRoles(userId: string, roles: string[], namespace?: string): Promise; /** * @name listOrg * @name_zh Get the user's organization * @description Get the user's organization, And his node path within the organization. * * @param {string} userId user ID * * @example * * const data = await managementClient.users.listOrgs("USERID"); * * @returns {Promise} * * @memberof UsersManagementClient */ listOrgs(userId: string): Promise; /** * @name listDepartment * @name_zh Get the user's department * @description Get the user's department * * @param {string} userId user ID * * @example * * const data = await managementClient.users.listDepartment("USERID"); * * @returns {Promise} * * @memberof UsersManagementClient */ listDepartment(userId: string): Promise<{ totalCount: number; list: { isMainDepartment: boolean; joinedAt?: string; department: { id: string; orgId?: string; name: string; nameI18n?: string; description?: string; descriptionI18n?: string; order?: number; code?: string; root?: boolean; depth?: number; path: string[]; codePath: string[]; namePath: string[]; createdAt?: string; updatedAt?: string; children?: string[]; }; }[]; }>; /** * @description Get all resources authorized by the user * * @param userId * @param namespace */ listAuthorizedResources(userId: string, namespace: string, options?: { resourceType?: ResourceType; }): Promise; /** * @description Get all custom data of a user * @param userId: user ID * */ getUdfValue(userId: string): Promise; /** * @description Get custom data of multiple users in batch * * @param userIds: user ID list */ getUdfValueBatch(userIds: string[]): Promise<{ [x: string]: KeyValuePair; }>; /** * @description Set custom data for a user * * @param userId * @param data */ setUdfValue(userId: string, data: KeyValuePair): Promise; /** * @description Set custom data in bulk * */ setUdfValueBatch(input: { userId: string; data: KeyValuePair; }[]): Promise; /** * @description Clear user's custom data * */ removeUdfValue(userId: string, key: string): Promise; /** * Determine whether the user has a certain role * @param userId user ID * @param roleCode role Code * @param namespace Permission group ID */ hasRole(userId: string, roleCode: string, namespace?: string): Promise; /** * @description Force a batch of users offline */ kick(userIds: string[]): Promise<{ code: number; message: string; }>; /** * Audit log list * @param options.page current page * @param options.limit Number of items displayed per page * @param options.clientIp client IP address * @param options.operationName operation name * @param options.operatoArn user get Arn by searchUser * @returns Promise */ listUserActions(options?: { page?: number; limit?: number; clientIp?: string; operationName?: string; operatoArn?: string; }): Promise; }