Merge pull request #23 from hlqviet/refactor/domain-process

Domain process code refactor
This commit is contained in:
mrrfv
2023-09-17 17:23:28 +02:00
committed by GitHub
8 changed files with 266 additions and 139 deletions
+19
View File
@@ -44,3 +44,22 @@ const request = async (url, options) => {
*/
export const requestGateway = (path, options) =>
request(`${API_HOST}/accounts/${ACCOUNT_ID}/gateway${path}`, options);
/**
* Normalizes a domain.
* @param {string} value The value to be normalized.
* @param {boolean} isAllowlisting Whether the value is to be whitelisted.
* @returns {string}
*/
export const normalizeDomain = (value, isAllowlisting) => {
const normalized = value
.replace(/(0\.0\.0\.0|127\.0\.0\.1|::1|::)\s+/, "")
.replace("||", "")
.replace("^$important", "")
.replace("*.", "")
.replace("^", "");
if (isAllowlisting) return normalized.replace("@@||", "");
return normalized;
};