Custom Data
Custom data management in the @espressif/rainmaker-base-sdk allows you to store, retrieve, and manage custom user data with fine-grained permissions. You can also manage geographical coordinates and time zone information as part of custom data.
备注
The userInstance mentioned below refers to the ESPRMUser instance obtained during User Sign in.
Custom Data Operations
Fetch Custom Data
Retrieve custom data using the getCustomData method.
try {
const customData = await userInstance.getCustomData();
console.log("Custom data fetched successfully:", customData);
} catch (error) {
console.error("Error fetching custom data:", error);
}
Set Custom Data
Set custom data using the setCustomData method.
const customDataRequest = {
name: {
value: "jack",
perms: [{ read: ["user", "admin"], write: ["user"] }],
},
};
try {
const response = await userInstance.setCustomData(customDataRequest);
console.log("Custom data set successfully:", response);
} catch (error) {
console.error("Error setting custom data:", error);
}
Delete Custom Data
Delete Value
Remove the value of a specific key using deleteCustomData.
try {
const response = await userInstance.deleteCustomData("exampleKey");
console.log("Custom data value deleted successfully:", response);
} catch (error) {
console.error("Error deleting custom data value:", error);
}
Delete Key
Delete an entire custom data entry using deleteCustomDataKey.
try {
const response = await userInstance.deleteCustomDataKey("exampleKey");
console.log("Custom data key deleted successfully:", response);
} catch (error) {
console.error("Error deleting custom data key:", error);
}
Delete Permissions
Remove permissions for a specific key using deleteCustomDataPermissions.
try {
const response = await userInstance.deleteCustomDataPermissions("exampleKey");
console.log("Custom data permissions deleted successfully:", response);
} catch (error) {
console.error("Error deleting custom data permissions:", error);
}