65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
function normalizeList(value) {
|
|
return Array.isArray(value) ? value.filter(Boolean) : [];
|
|
}
|
|
|
|
export function normalizeChannelsPayload(data) {
|
|
if (Array.isArray(data)) return data;
|
|
if (Array.isArray(data?.salesChannels)) return data.salesChannels;
|
|
if (Array.isArray(data?.channels)) return data.channels;
|
|
return [];
|
|
}
|
|
|
|
export function getChannelId(channel) {
|
|
return channel?.salesChannelId || channel?.id || channel?._id || '';
|
|
}
|
|
|
|
export function isChannelActive(channel) {
|
|
const status = String(channel?.status || channel?.state || '').toLowerCase();
|
|
|
|
if (typeof channel?.isActive === 'boolean') return channel.isActive;
|
|
if (typeof channel?.active === 'boolean') return channel.active;
|
|
if (typeof channel?.enabled === 'boolean') return channel.enabled;
|
|
if (status) return ['active', 'enabled', 'live', 'connected'].includes(status);
|
|
|
|
return true;
|
|
}
|
|
|
|
export function getBusinessName(entity) {
|
|
return entity?.brandName || entity?.name || entity?.title || 'Business';
|
|
}
|
|
|
|
export function getBusinessDomain(entity) {
|
|
const directDomain = String(entity?.domain || '').trim();
|
|
if (directDomain) return directDomain;
|
|
|
|
const websiteUrl = String(entity?.websiteUrl || entity?.url || '').trim();
|
|
if (!websiteUrl) return '';
|
|
|
|
return websiteUrl
|
|
.replace(/^https?:\/\//i, '')
|
|
.replace(/^www\./i, '')
|
|
.replace(/\/.*$/, '');
|
|
}
|
|
|
|
export function getBusinessTagline(entity) {
|
|
const taglines = normalizeList(entity?.taglines);
|
|
const firstTagline = taglines.find((tagline) => String(tagline || '').trim());
|
|
if (firstTagline) return String(firstTagline).trim();
|
|
|
|
const fallback = entity?.tagline || entity?.description || entity?.metaDescription || '';
|
|
return String(fallback).trim();
|
|
}
|
|
|
|
export function getBusinessImage(entity) {
|
|
const relevantImage = normalizeList(entity?.relevantImagePaths)[0];
|
|
if (relevantImage) return relevantImage;
|
|
|
|
return (
|
|
entity?.imageUrl
|
|
|| entity?.logoUrl
|
|
|| entity?.brandImageUrl
|
|
|| entity?.image
|
|
|| ''
|
|
);
|
|
}
|