Node Sharing
Node sharing allows you to share access to your nodes with other users, enabling collaborative device management.
Overview
Node sharing in RainMaker enables you to:
- Share nodes with other users
- Remove sharing for specific users
- Transfer node ownership to another user
Share Node
Share a node with another user using the shareWith method.
try {
const shareRequest = {
username: "target_username",
makePrimary: false,
metadata: {
description: "Shared for home automation access",
},
};
const requestId = await node.shareWith(shareRequest);
console.log("Node sharing request created:", requestId);
} catch (error) {
console.error("Error sharing node:", error);
}
ShareWithRequest Interface
The shareWith method requires a ShareWithRequest object with the following properties:
| Property | Type | Required | Description |
|---|---|---|---|
| username* | string | Yes | The username of the user to share the node with. |
| makePrimary | boolean | No | Whether to make the shared user a primary user. |
| metadata | Record<string, any> | No | Optional metadata associated with the sharing request. |
Example: Basic Sharing
try {
const shareRequest = {
username: "family_member@example.com",
};
const requestId = await node.shareWith(shareRequest);
console.log("Sharing request created with ID:", requestId);
} catch (error) {
console.error("Error sharing node:", error);
}
Example: Share with Primary User
try {
const shareRequest = {
username: "admin@example.com",
makePrimary: true,
metadata: {
role: "administrator",
accessLevel: "full",
},
};
const requestId = await node.shareWith(shareRequest);
console.log("Node shared as primary user:", requestId);
} catch (error) {
console.error("Error sharing node:", error);
}
Example: Share with Metadata
try {
const shareRequest = {
username: "guest@example.com",
makePrimary: false,
metadata: {
purpose: "temporary_access",
expiryDate: "2024-12-31",
permissions: ["read", "control"],
},
};
const requestId = await node.shareWith(shareRequest);
console.log("Node shared with metadata:", requestId);
} catch (error) {
console.error("Error sharing node:", error);
}
Remove Sharing
Remove sharing of the current node for a specified user using the removeSharingFor method.
try {
const username = "target_username";
const response = await node.removeSharingFor(username);
console.log("Sharing removed successfully:", response);
} catch (error) {
console.error("Error removing sharing:", error);
}
removeSharingFor API
| Parameter | Type | Description |
|---|---|---|
| username* | string | The username of the user for whom the sharing is to be removed. |
Returns: Promise<ESPAPIResponse> - A promise that resolves to a success response upon successful removal.
Example: Remove Sharing
try {
const username = "former_user@example.com";
const response = await node.removeSharingFor(username);
if (response.status === "success") {
console.log("Sharing removed successfully for:", username);
}
} catch (error) {
console.error("Error removing sharing:", error);
}
Transfer Node
Create a transfer request to transfer the current node to a specified user using the transferNode method. This transfers ownership of the node to another user.
try {
const transferRequest = {
toUserName: "new_owner@example.com",
selfToSecondary: false,
};
const requestId = await node.transferNode(transferRequest);
console.log("Node transfer request created:", requestId);
} catch (error) {
console.error("Error transferring node:", error);
}
TransferNodeRequest Interface
The transferNode method requires a TransferNodeRequest object with the following properties:
| Property | Type | Required | Description |
|---|---|---|---|
| toUserName* | string | Yes | The username of the user to transfer the node to. |
| selfToSecondary | boolean | No | Whether to make the current owner a secondary user after transfer. |
Returns: Promise<string> - A promise that resolves to a requestId upon successful transfer request creation.