# Manage Orgnizations
An Authing user pool can create multiple organizations. This module is used to manage the Authing organization, and can perform operations such as adding, deleting, modifying, adding and deleting mobile nodes, and importing organizations.
Please use the module in the following ways:
import {ManagementClient} from "authing-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
# Create an organization
OrgManagementClient().create(name, description, code)
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.
# Parameters
name
<string> The name of the organization, which will be the name of the root node of the organization.description
<string> Root node descriptioncode
<string> The only sign of the root node, which must be a legal English character.
# Example
const org = await managementClient.org.create('Beijing FeiFan Technology','Beijing FeiFan Technology Co., Ltd.','feifan');
# Delete organization
OrgManagementClient().deleteById(id)
Delete organization tree
# Parameters
id
<string> Organization ID
# Example
# return value
Promise<CommonMessage>
# Get the list of user pool organizations
OrgManagementClient().list(page, limit)
Get the list of user pool organizations
# Parameters
page
<number> The default value is:1
.limit
<number> The default value is10
.
# Example
const {totalCount, list} = await managementClient.org.list()
# return value
null
# Add node
OrgManagementClient().addNode(orgId, parentNodeId, data)
Add a node in the organization
# Parameters
orgId
<string> Organization IDparentNodeId
<string> parent node IDdata
<Object> node datadata.name
<string> node namedata.code
<string> unique identifier of the nodedata.description
<string> node description information
# Example
const org = await managementClient.org.create('Beijing FeiFan Technology','Beijing FeiFan Technology Co., Ltd.','feifan');
const {id: orgId, rootNode} = org
const newOrg = await managementClient.org.addNode(orgId, rootNode.id, {name:'Operation Department' })
// newOrg.nodes.length is now 2
# return value
Promise<Org>
# Modify node
OrgManagementClient().updateNode(id, updates)
Modify node data
# Parameters
id
<string> node IDupdates
<Object> modify dataupdates.name
<string> node nameupdates.code
<string> unique identifier of the nodeupdates.description
<string> node description information
# Example
await managementClient.org.updateNode("NDOEID", {
name:'New node name'
})
# return value
Promise<Org>
# Get organization details
OrgManagementClient().findById(id)
Get organization details through organization ID
# Parameters
id
<string> Organization ID
# Example
# return value
Promise<Org>
# Delete node
OrgManagementClient().deleteNode(orgId, nodeId)
Delete a node in the organization tree
# Parameters
orgId
<string> Organization IDnodeId
<string> node ID
# Example
# return value
Promise<CommonMessage>
# Mobile Node
OrgManagementClient().moveNode(orgId, nodeId, targetParentId)
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 to its own child nodes.
# Parameters
orgId
<string> Organization IDnodeId
<string> ID of the node to be movedtargetParentId
<string> target parent node ID
# Example
await managementClient.org.moveNode("ORGID", "NODEID", "TRAGET_NODE_ID")
# return value
Promise<Org>
latest tree structure
# Determine whether it is the root node
OrgManagementClient().isRootNode(orgId, nodeId)
Determine whether a node is the root node of the organization tree
# Parameters
orgId
<string> Organization IDnodeId
<string> Organization ID
# Example
# return value
Promise<boolean>
# Get the list of child nodes
OrgManagementClient().listChildren(orgId, nodeId)
Query the list of child nodes of a node
# Parameters
orgId
<string> Organization IDnodeId
<string> Organization ID
# Example
// list of child nodes
cosnt children = await managementClient.org.moveNode("ORGID", "NODEID")
# return value
Promise<Node[]>
# Get the root node
OrgManagementClient().rootNode(orgId)
Get the root node of an organization
# Parameters
orgId
<string> Organization ID
# Example
const rootNode = await managementClient.org.rootNode("ORGID")
# return value
Promise<Node[]>
# Import via JSON
OrgManagementClient().importByJson(json)
Import organization through a JSON tree structure
# Parameters
json
<Object> Tree structure in JSON format, please refer to the sample code for the detailed format.
# Example
const tree = {
name:'Beijing Extraordinary Technology Co., Ltd.',
code:'feifan',
children: [
{
code:'operation',
name:'Operation',
description:'Commercialization Department'
},
{
code:'dev',
name:'R&D',
description:'R&D department',
children: [
{
code:'backend',
name:'Backend',
description:'Back-end R&D department'
}
]
}
]
};
const org = await managementClient.org.importByJson(tree);
# return value
Promise<Node[]>
# Added successfully
OrgManagementClient().addMembers(nodeId, userIds)
Node add members
# Parameters
nodeId
<string> node IDuserIds
<string[]> list of user IDs
# Example
# return value
Promise<PaginatedUsers>
# Get node members
OrgManagementClient().listMembers(nodeId, options)
Get node members, you can get users directly added to the node, or users of the node's child nodes.
# Parameters
nodeId
<string> node IDoptions
<Object> query parametersoptions.page
<number> The default value is:1
.options.limit
<number> The default value is:10
.options.includeChildrenNodes
<boolean> Whether to get the members of all child nodes. The default value isfalse
.
# Example
# return value
Promise<PaginatedUsers>
# successfully deleted
OrgManagementClient().removeMembers(nodeId, userIds)
Delete node member
# Parameters
nodeId
<string> node IDuserIds
<string[]> list of user IDs
# Example
# return value
Promise<PaginatedUsers>