import { Service } from '@usercentrics/cmp-browser-sdk'; import { DefaultServiceLabels } from '@usercentrics/cmp-browser-sdk/dist/src/services/SettingsV2/Labels/interfaces'; export type ServiceData = { data: T; title: string; description?: string; componentType: 'v-card' | 'list' | 'link' | 'text' | 'text-link'; }; export type VCardData = { name?: string; address?: string }; export type ServiceDataTypes = number | string | string[] | VCardData | undefined | null; export function getServiceData( service: Service, labels?: DefaultServiceLabels ): ServiceData[] { if (!labels) { return []; } const processingCompany: ServiceData = { title: labels.dataRecipients.title, componentType: 'v-card', data: { name: service?.processingCompany?.name, address: service?.processingCompany?.address, }, }; const dataPurposes: ServiceData = { componentType: 'list', title: labels.dataPurposes.title, description: labels.dataPurposes.description, data: service?.dataPurposes, }; const technologiesUsed: ServiceData = { componentType: 'list', title: labels.technologiesUsed.title, description: labels.technologiesUsed.description, data: service?.technologiesUsed, }; const dataCollected: ServiceData = { componentType: 'list', title: labels.dataCollected.title, description: labels.dataCollected.description, data: service?.dataCollected, }; const legalBasis: ServiceData = { componentType: 'list', title: labels.legalBasis.title, description: labels.legalBasis.description, data: service?.legalBasis, }; const locationOfProcessing: ServiceData = { componentType: 'text', data: service?.dataDistribution?.processingLocation ?? '', title: labels.dataDistribution.processingLocationTitle, description: labels.dataDistribution.processingLocationDescription, }; const retentionPeriod: ServiceData = { componentType: 'text', title: labels.retentionPeriod.title, description: labels.retentionPeriod.description, data: service?.retentionPeriodDescription, }; const dataRecipients: ServiceData = { componentType: 'list', title: labels.dataRecipients.title, description: labels.dataRecipients.description, data: service?.dataRecipients, }; const dataProtectionOfficer: ServiceData = { componentType: 'text-link', title: labels.dataProtectionOfficer.title, description: labels.dataProtectionOfficer.description, data: service?.processingCompany?.dataProtectionOfficer, }; const rawData = (service?.dataDistribution?.thirdPartyCountries as unknown as string) || []; const thirdPartyCountries: ServiceData = { componentType: 'list', //specified type string[] is set incorrectly by library sometimes data: Array.isArray(rawData) ? rawData : rawData.split(','), title: labels.dataDistribution.thirdPartyCountriesTitle, description: labels.dataDistribution.thirdPartyCountriesDescription, }; const privacyPolicy: ServiceData = { componentType: 'link', data: service?.urls?.privacyPolicy, title: labels.urls.privacyPolicyTitle, }; const optOut: ServiceData = { componentType: 'link', data: service?.urls?.optOut, title: labels.urls.optOutTitle, }; const cookiePolicy: ServiceData = { componentType: 'link', data: service?.urls?.cookiePolicy, title: labels.urls.cookiePolicyTitle, }; return [ processingCompany, dataPurposes, technologiesUsed, dataCollected, legalBasis, locationOfProcessing, retentionPeriod, dataRecipients, dataProtectionOfficer, thirdPartyCountries, privacyPolicy, optOut, cookiePolicy, ]; }