@hashgraphonline/standards-sdk
Version:
The Hashgraph Online Standards SDK provides a complete implementation of the Hashgraph Consensus Standards (HCS), giving developers all the tools needed to build applications on Hedera.
108 lines (107 loc) • 2.7 kB
JavaScript
import { Logger } from "./standards-sdk.es22.js";
class PersonBuilder {
constructor() {
this.config = {
version: "1.0",
type: 0
};
this.logger = Logger.getInstance({
module: "PersonBuilder"
});
}
setName(name) {
this.config.display_name = name;
return this;
}
setAlias(alias) {
this.config.alias = alias;
return this;
}
setBio(bio) {
this.config.bio = bio;
return this;
}
/**
* @deprecated Use setBio instead
*/
setDescription(description) {
return this.setBio(description);
}
addSocial(platform, handle) {
if (!this.config.socials) {
this.config.socials = [];
}
const existingSocial = this.config.socials.find(
(s) => s.platform === platform
);
if (!existingSocial) {
this.config.socials.push({ platform, handle });
} else {
existingSocial.handle = handle;
}
return this;
}
setProfileImage(profileImage) {
this.config.profileImage = profileImage;
return this;
}
setProfilePicture(pfpBuffer, pfpFileName) {
this.config.pfpBuffer = pfpBuffer;
this.config.pfpFileName = pfpFileName;
return this;
}
setExistingProfilePicture(pfpTopicId) {
this.config.profileImage = `hcs://1/${pfpTopicId}`;
return this;
}
addProperty(key, value) {
if (!this.config.properties) {
this.config.properties = {};
}
this.config.properties[key] = value;
return this;
}
setInboundTopicId(topicId) {
this.config.inboundTopicId = topicId;
return this;
}
setOutboundTopicId(topicId) {
this.config.outboundTopicId = topicId;
return this;
}
getProfilePicture() {
return {
pfpBuffer: this.config.pfpBuffer,
pfpFileName: this.config.pfpFileName
};
}
build() {
if (!this.config.display_name) {
throw new Error("Display name is required for the profile");
}
if (!this.config.bio) {
this.logger.warn("No bio provided for person profile");
}
if (!this.config.pfpBuffer && !this.config.profileImage) {
this.logger.warn("No profile picture provided or referenced");
}
return {
version: this.config.version,
type: 0,
display_name: this.config.display_name,
alias: this.config.alias,
bio: this.config.bio,
socials: this.config.socials,
profileImage: this.config.profileImage,
properties: this.config.properties,
inboundTopicId: this.config.inboundTopicId,
outboundTopicId: this.config.outboundTopicId,
pfpBuffer: this.config.pfpBuffer,
pfpFileName: this.config.pfpFileName
};
}
}
export {
PersonBuilder
};
//# sourceMappingURL=standards-sdk.es12.js.map