Initial commit
This commit is contained in:
60
mcp-server/utils/helpers.js
Normal file
60
mcp-server/utils/helpers.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Utility functions shared across the MCP server
|
||||
*/
|
||||
|
||||
export const encodeBase64 = (value) => Buffer.from(value, "utf-8").toString("base64");
|
||||
|
||||
export const cleanDomainValue = (domain) => {
|
||||
if (!domain) {
|
||||
return null;
|
||||
}
|
||||
return domain.replace(/^https?:\/\//i, "").replace(/\/$/, "").toLowerCase();
|
||||
};
|
||||
|
||||
export const mapDomainsForOutput = (domains = []) =>
|
||||
domains.map((item) => ({
|
||||
num: item.num,
|
||||
domain: item.domain,
|
||||
label: item.domain,
|
||||
isMulti: item.is_multi_child === "1" || item.multiSite === "1",
|
||||
}));
|
||||
|
||||
export const extractTokenHash = (payload) => {
|
||||
if (!payload || typeof payload !== "object") {
|
||||
return null;
|
||||
}
|
||||
if (payload.tokenHash) {
|
||||
return payload.tokenHash;
|
||||
}
|
||||
if (payload.token_hash) {
|
||||
return payload.token_hash;
|
||||
}
|
||||
if (payload.data && typeof payload.data === "object") {
|
||||
return extractTokenHash(payload.data);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const pickDomain = (domains = [], domainInput, domainNumInput) => {
|
||||
if (!domains.length) {
|
||||
return null;
|
||||
}
|
||||
if (domainNumInput != null) {
|
||||
const domainNum = String(domainNumInput).trim();
|
||||
const domainByNum = domains.find((entry) => String(entry.num).trim() === domainNum);
|
||||
if (domainByNum) {
|
||||
return domainByNum;
|
||||
}
|
||||
}
|
||||
|
||||
if (!domainInput) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const normalizedDomain = cleanDomainValue(domainInput);
|
||||
return domains.find((entry) => cleanDomainValue(entry.domain) === normalizedDomain);
|
||||
};
|
||||
|
||||
export const getSessionKey = (username, password) => `${username}::${password}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user