dymo-api
Version:
Flow system for Dymo API.
103 lines (102 loc) • 4.57 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidPwd = exports.satinizer = exports.getPrayerTimes = void 0;
const config_1 = __importStar(require("../config/index.cjs"));
const customError = (code, message) => {
return Object.assign(new Error(), { code, message: `[${config_1.default.lib.name}] ${message}` });
};
const getPrayerTimes = async (data) => {
const { lat, lon } = data;
if (lat === undefined || lon === undefined)
throw customError(1000, "You must provide a latitude and longitude.");
try {
const response = await config_1.axiosApiUrl.get("/public/islam/prayertimes", { params: data });
return response.data;
}
catch (error) {
throw customError(5000, error.response?.data?.message || error.message);
}
};
exports.getPrayerTimes = getPrayerTimes;
const satinizer = async (data) => {
const { input } = data;
if (input === undefined)
throw customError(1000, "You must specify at least the input.");
try {
const response = await config_1.axiosApiUrl.get("/public/inputSatinizer", { params: { input: encodeURIComponent(input) } });
return response.data;
}
catch (error) {
throw customError(5000, error.response?.data?.message || error.message);
}
};
exports.satinizer = satinizer;
const isValidPwd = async (data) => {
let { email, password, bannedWords, min, max } = data;
if (password === undefined)
throw customError(1000, "You must specify at least the password.");
const params = { password: encodeURIComponent(password) };
if (email) {
if (!/^[a-zA-Z0-9._\-+]+@?[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(email))
throw customError(1500, "If you provide an email address it must be valid.");
params.email = encodeURIComponent(email);
}
if (bannedWords) {
if (typeof bannedWords === "string")
bannedWords = bannedWords.slice(1, -1).trim().split(",").map(item => item.trim());
if (!Array.isArray(bannedWords) || bannedWords.length > 10)
throw customError(1500, "If you provide a list of banned words; the list may not exceed 10 words and must be of array type.");
if (!bannedWords.every(word => typeof word === "string") || new Set(bannedWords).size !== bannedWords.length)
throw customError(1500, "If you provide a list of banned words; all elements must be non-repeated strings.");
params.bannedWords = bannedWords;
}
if (min !== undefined && (!Number.isInteger(min) || min < 8 || min > 32))
throw customError(1500, "If you provide a minimum it must be valid.");
if (max !== undefined && (!Number.isInteger(max) || max < 32 || max > 100))
throw customError(1500, "If you provide a maximum it must be valid.");
if (min !== undefined)
params.min = min;
if (max !== undefined)
params.max = max;
try {
const response = await config_1.axiosApiUrl.get("/public/validPwd", { params });
return response.data;
}
catch (error) {
throw customError(5000, error.response?.data?.message || error.message);
}
};
exports.isValidPwd = isValidPwd;