n8n-nodes-zalo-nnt
Version:
Unofficial Zalo integration for n8n - Send messages, manage groups, user operations with QR login. No API key required, works via browser simulation.
79 lines • 2.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateThreadId = validateThreadId;
exports.validatePin = validatePin;
exports.validateThreadType = validateThreadType;
exports.validateTtl = validateTtl;
exports.validateMuteDuration = validateMuteDuration;
exports.validateOffset = validateOffset;
exports.validateCount = validateCount;
exports.parseThreadIds = parseThreadIds;
function validateThreadId(threadId) {
if (!threadId || typeof threadId !== 'string' || threadId.trim().length === 0) {
throw new Error('Thread ID is required and must be a non-empty string');
}
}
function validatePin(pin) {
if (!pin || typeof pin !== 'string') {
throw new Error('PIN is required and must be a string');
}
if (!/^\d{4}$/.test(pin)) {
throw new Error('PIN must be exactly 4 digits (e.g., 1234)');
}
}
function validateThreadType(threadType) {
if (threadType !== 0 && threadType !== 1) {
throw new Error('Thread type must be 0 (User) or 1 (Group)');
}
}
function validateTtl(ttl) {
if (typeof ttl !== 'number' || isNaN(ttl)) {
throw new Error('TTL must be a valid number');
}
if (ttl < 0) {
throw new Error('TTL must be 0 or greater');
}
}
function validateMuteDuration(duration) {
const validDurations = [-1, 0, 1, 2, 3, 4];
if (!validDurations.includes(duration)) {
throw new Error('Invalid mute duration. Valid values: -1 (Forever), 0 (Unmute), 1 (1h), 2 (4h), 3 (8h), 4 (1d)');
}
}
function validateOffset(offset) {
if (offset !== undefined) {
if (typeof offset !== 'number' || isNaN(offset)) {
throw new Error('Offset must be a valid number');
}
if (offset < 0) {
throw new Error('Offset must be 0 or greater');
}
}
}
function validateCount(count) {
if (count !== undefined) {
if (typeof count !== 'number' || isNaN(count)) {
throw new Error('Count must be a valid number');
}
if (count < 1) {
throw new Error('Count must be at least 1');
}
if (count > 100) {
throw new Error('Count must not exceed 100');
}
}
}
function parseThreadIds(threadIds) {
if (!threadIds || typeof threadIds !== 'string') {
throw new Error('Thread IDs are required');
}
const ids = threadIds
.split(',')
.map((id) => id.trim())
.filter((id) => id.length > 0);
if (ids.length === 0) {
throw new Error('At least one valid Thread ID is required');
}
return ids;
}
//# sourceMappingURL=validator.js.map