Keep Studio business branding in verified client storage
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const { fail } = require('./workspace.cjs');
|
||||
|
||||
function normalizeBrand(input, defaultName = '') {
|
||||
if (!input || typeof input !== 'object' || Array.isArray(input)) throw fail(400, 'INVALID_BRAND', 'Business তথ্য সঠিক নয়।');
|
||||
const text = (key, max) => {
|
||||
if (input[key] !== undefined && typeof input[key] !== 'string') throw fail(400, 'INVALID_BRAND', 'Business তথ্য text হতে হবে।');
|
||||
const value = (input[key] || '').trim();
|
||||
if (value.length > max || /[\u0000-\u001f\u007f]/.test(value)) throw fail(400, 'INVALID_BRAND', 'Business তথ্য সঠিক নয়।');
|
||||
return value;
|
||||
};
|
||||
const name = text('name', 256) || defaultName;
|
||||
let website = text('website', 2048);
|
||||
if (website) {
|
||||
let url;
|
||||
try { url = new URL(website); } catch { throw fail(400, 'INVALID_WEBSITE', 'সম্পূর্ণ http/https website URL দিন।'); }
|
||||
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw fail(400, 'INVALID_WEBSITE', 'Website URL-এ password, query বা fragment ব্যবহার করবেন না।');
|
||||
website = url.href.replace(/\/$/, '');
|
||||
}
|
||||
const phone = text('phone', 32).replace(/[\s().-]/g, '');
|
||||
if (phone && !/^\+[1-9]\d{6,14}$/.test(phone)) throw fail(400, 'INVALID_PHONE', 'Country code সহ international WhatsApp নম্বর দিন, যেমন +880…।');
|
||||
return { name, website, phone };
|
||||
}
|
||||
|
||||
module.exports = { normalizeBrand };
|
||||
Reference in New Issue
Block a user