import { GraphqlClient } from './../common/GraphqlClient'; import { ManagementTokenProvider } from './ManagementTokenProvider'; import { ExtendedOrg, ManagementClientOptions } from './types'; import { CommonMessage, PaginatedAuthorizedResources, PaginatedUsers, ResourceType } from '../../types/graphql.v2'; import { HttpClient } from '../common/HttpClient'; /** * @class OrgManagementClient Management organization * @description An appow user pool can create multiple organizations. This module is used to manage the appow organization, and can perform operations such as adding, deleting, modifying, adding and deleting mobile nodes, and importing organizations. * * @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.org.list // Get the list of user pool organizations * managementClient.org.moveNode // Get organization details * managementClient.org.listMembers // Get the list of node users * \`\`\` * * @name OrgManagementClient */ export declare class OrgManagementClient { options: ManagementClientOptions; graphqlClient: GraphqlClient; tokenProvider: ManagementTokenProvider; httpClient: HttpClient; constructor(options: ManagementClientOptions, graphqlClient: GraphqlClient, httpClient: HttpClient, tokenProvider: ManagementTokenProvider); private buildTree; /** * @name create * @name_zh Create an organization * @description Creating an organization will create an organization with only one node. * If you want to import a complete organization tree, please use the importByJson method. * * @param {string} name Organization name, which will be the name of the root node of the organization. * @param {string} [description] Root node description * @param {string} [code] The unique mark of the root node must be a legal English character. * * @example * * const org = await managementClient.org.create('beijing feifan tech', 'beijing feifan technology Inc', 'feifan'); * * @memberof OrgManagementClient */ create(name: string, description?: string, code?: string): Promise<{ id: string; rootNode: { id: string; orgId?: string; name: string; nameI18n?: string; description?: string; descriptionI18n?: string; order?: number; code?: string; root?: boolean; depth?: number; path: string[]; createdAt?: string; updatedAt?: string; children?: string[]; }; nodes: { id: string; orgId?: string; name: string; nameI18n?: string; description?: string; descriptionI18n?: string; order?: number; code?: string; root?: boolean; depth?: number; path: string[]; createdAt?: string; updatedAt?: string; children?: string[]; }[]; }>; /** * @name deleteById * @name_zh Delete organization * @description Delete organization tree * @param {string} id Orgganization ID * * @returns {Promise} * @memberof OrgManagementClient */ deleteById(id: string): Promise; /** * @name list * @name_zh Get the list of user pool organizations * @description Get the list of user pool organizations * * @param {number} [page=1] * @param {number} [limit=10] * * @example * * const { totalCount, list } = await managementClient.org.list() * * @returns * @memberof OrgManagementClient */ list(page?: number, limit?: number): Promise<{ totalCount: number; list: ExtendedOrg[]; }>; /** * @name addNode * @name_zh Add node * @description Add a node in the organization * * @param {string} orgId Organization ID * @param {string} parentNodeId Parent node ID * @param {Object} data Node data * @param {string} data.name Data name * @param {string} [data.code] Node unique identifier * @param {string} [data.description] Node description information * * @example * * const org = await managementClient.org.create('beijing feifan tech', 'beijing feifan technology Inc', 'feifan'); * const { id: orgId, rootNode } = org * const newOrg = await managementClient.org.addNode(orgId, rootNode.id, { name: 'operation department' }) * * // newOrg.nodes.length 现在为 2 * * @returns {Promise} * @memberof OrgManagementClient */ addNode(orgId: string, parentNodeId: string, data: { name: string; code?: string; order?: number; nameI18n?: string; description?: string; descriptionI18n?: string; }): Promise<{ id: string; orgId?: string; name: string; nameI18n?: string; description?: string; descriptionI18n?: string; order?: number; code?: string; root?: boolean; depth?: number; path: string[]; createdAt?: string; updatedAt?: string; children?: string[]; }>; /** * @name getNodeById * @name_zh Get details of a node * @description Get details of a node * * @param {string} nodeId Node ID * * @example * * const node = await managementClient.org.getNodeById('NODE_ID'); * * // newOrg.nodes.length current is 2 * * @returns {Promise} * @memberof OrgManagementClient */ getNodeById(nodeId: string): Promise<{ id: string; orgId?: string; name: string; nameI18n?: string; description?: string; descriptionI18n?: string; order?: number; code?: string; root?: boolean; depth?: number; path: string[]; createdAt?: string; updatedAt?: string; children?: string[]; }>; /** * @name updateNode * @name_zh Modify node * @description Modify node data * * @param {string} id Node ID * @param {Object} updates Update node * @param {string} [updates.name] Node name * @param {string} [updates.code] Node unique identifier * @param {string} [updates.description] Node description * * @example * * await managementClient.org.updateNode("NDOEID", { * name: 'new node name' * }) * * @returns {Promise} * @memberof OrgManagementClient */ updateNode(id: string, updates: { name?: string; code?: string; order?: number; nameI18n?: string; description?: string; descriptionI18n?: string; }): Promise<{ id: string; orgId?: string; name: string; nameI18n?: string; description?: string; descriptionI18n?: string; order?: number; code?: string; root?: boolean; depth?: number; path: string[]; createdAt?: string; updatedAt?: string; children?: string[]; users: { totalCount: number; }; }>; /** * @name findById * @name_zh Get organization details * @description Get organization details through organization ID * * @param {string} id Organizaiton ID * * @returns {Promise} * @memberof OrgManagementClient */ findById(id: string): Promise; /** * @name deleteNode * @name_zh Delete node * @description Delete a node in the organization tree * * @param {string} orgId Organization ID * @param {string} nodeId Node ID * * @returns {Promise} * @memberof OrgManagementClient */ deleteNode(orgId: string, nodeId: string): Promise<{ message?: string; code?: number; }>; /** * @name moveNode Move node * @name_zh Move node * @description To move an organization node, when moving a node, you need to specify the node's new parent node. Note that you cannot move a node under its own child nodes. * * @param {string} orgId Organization ID * @param {string} nodeId The ID of the node that needs to be moved * @param {string} targetParentId target parent ID * * @example * * await managementClient.org.moveNode("ORGID", "NODEID", "TRAGET_NODE_ID") * * @returns {Promise} Latest structure tree * @memberof OrgManagementClient * */ moveNode(orgId: string, nodeId: string, targetParentId: string): Promise; /** * @name isRootNode * @name_zh Determine whether it is the root node * @description Determine whether a node is the root node of the organization tree * * @param {string} orgId Organization ID * @param {string} nodeId Organization ID * * * @returns {Promise} * @memberof OrgManagementClient */ isRootNode(orgId: string, nodeId: string): Promise; /** * @name listChildren * @name_zh Get the list of children nodes * @description Query the list of all children nodes * * @param {string} orgId Organization ID * @param {string} nodeId Organization ID * * @example * * // children list * cosnt children = await managementClient.org.moveNode("ORGID", "NODEID") * * * @returns {Promise} * @memberof OrgManagementClient */ listChildren(orgId: string, nodeId: string): Promise<{ id: string; orgId?: string; name: string; nameI18n?: string; description?: string; descriptionI18n?: string; order?: number; code?: string; root?: boolean; depth?: number; path: string[]; createdAt?: string; updatedAt?: string; children?: string[]; }[]>; /** * @name rootNode * @name_zh Get root node * @description Get root node * * @param {string} orgId Orgganization ID * * @example * * const rootNode = await managementClient.org.rootNode("ORGID") * * @returns {Promise} * @memberof OrgManagementClient */ rootNode(orgId: string): Promise<{ 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[]; }>; /** * @name importByJson * @name_zh Import by JSON * @description Import organization through a JSON tree structure * * @param {Object} json The tree structure in JSON format, please refer to the sample code for the detailed format. * * @example * * const tree = { * name: 'beijing feifan technology Inc', * code: 'feifan', * children: [ * { * code: 'operation', * name: 'Operation', * description: 'Commercialization Department' * }, * { * code: 'dev', * name: 'develop', * description: 'R & D department', * children: [ * { * code: 'backend', * name: 'backend', * description: 'Back-end R&D department' * } * ] * } * ] * }; * const org = await managementClient.org.importByJson(tree); * * @returns {Promise} * @memberof OrgManagementClient */ importByJson(json: { [x: string]: any; }): Promise; /** * @name addMembers * @name_zh Add members * @description Add node members * * @param {string} nodeId node ID * @param {string[]} userIds user ID list * * @returns {Promise} * @memberof OrgManagementClient * */ addMembers(nodeId: string, userIds: string[]): Promise; /** * @name listMembers * @name_zh Get node members * @description Get the node members, you can get the users directly added to the node, or you can get the users of the child nodes of the node. * * @param {string} nodeId Node ID * @param {Object} options Query parameters * @param {number} [options.page=1] * @param {number} [options.limit=10] * @param {boolean} [options.includeChildrenNodes=false] Whether to get the members of all child nodes * * * @returns {Promise} * @memberof OrgManagementClient * */ listMembers(nodeId: string, options?: { page?: number; limit?: number; includeChildrenNodes?: boolean; }): Promise; /** * @name removeMembers * @name_zh Delete members * @description Delete node members * * @param {string} nodeId node ID * @param {string[]} userIds user ID list * * @returns {Promise} * @memberof OrgManagementClient * */ removeMembers(nodeId: string, userIds: string[]): Promise; /** * @name setMainDepartment * @name_zh Set Main department * @description Set Main department * * @param {string} userId user ID * @param {string} departmentId department ID * * @returns {Promise} * @memberof OrgManagementClient * */ setMainDepartment(userId: string, departmentId: string): Promise; /** * @description Export all organizations */ exportAll(): Promise; /** * @description Export one organization */ exportByOrgId(orgId: string): Promise; /** * @description Get all the resources authorized by the organization node * * @param nodeId: Node ID * @param namespace: Namespace code * @param options.resourceType Resource type */ listAuthorizedResourcesByNodeId(nodeId: string, namespace: string, options?: { resourceType?: ResourceType; }): Promise; /** * @description Get all the resources authorized by the organization node * * @param orgId: Organization ID; * @param code: Node code * @param namespace: Namespace code * @param options.resourceType Resource type */ listAuthorizedResourcesByNodeCode(orgId: string, code: string, namespace: string, options?: { resourceType?: ResourceType; }): Promise; }