import type { GigyaSdkConsentSchemaType, GigyaSdkConsentsStatementsType } from '../types' import sendApiCall from './sendApiCall' type PartialGigyaSchema = { preferencesSchema: { fields: Record } } export default function (): Promise { return new Promise(async (resolve, reject) => { try { const completeGigyaSchema = await sendApiCall('accounts.getSchema') const currentSiteConsents = await sendApiCall('accounts.getConsentsStatements') let output: GigyaSdkConsentSchemaType[] = [] Object.entries(currentSiteConsents?.preferences ?? {}).forEach((entry) => { const consentStatementSchema = completeGigyaSchema?.preferencesSchema?.fields[entry[0]] if (entry[1]?.isActive && !entry[1]?.isMandatory && consentStatementSchema) { consentStatementSchema.key = entry[0] output = [...output, consentStatementSchema] } }) resolve(output) } catch (e) { reject(e) } }) }