From 4480778a4988ac63bf0c33519de982efc0feced8 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Wed, 6 Aug 2025 06:33:57 +0000 Subject: [PATCH] fix: export contactMethods as JSON arrays instead of strings - Fixed contactsToExportJson to properly handle contactMethods as arrays - Fixed contactToCsvLine to correctly stringify contactMethods arrays - Removed unused parseJsonField function (consolidated with PlatformServiceMixin) - Resolves issue where contact backup exports showed contactMethods as strings instead of JSON arrays --- src/libs/util.ts | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/libs/util.ts b/src/libs/util.ts index 3404054d..ae056fe6 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -35,17 +35,6 @@ import { IIdentifier } from "@veramo/core"; import { DEFAULT_ROOT_DERIVATION_PATH } from "./crypto"; // Consolidate this with src/utils/PlatformServiceMixin._parseJsonField -function parseJsonField(value: unknown, defaultValue: T): T { - if (typeof value === "string") { - try { - return JSON.parse(value); - } catch { - return defaultValue; - } - } - return (value as T) || defaultValue; -} - function mapQueryResultToValues( record: { columns: string[]; values: unknown[][] } | undefined, ): Array> { @@ -806,7 +795,7 @@ export const contactToCsvLine = (contact: Contact): string => { // Handle contactMethods array by stringifying it const contactMethodsStr = contact.contactMethods - ? escapeField(JSON.stringify(parseJsonField(contact.contactMethods, []))) + ? escapeField(JSON.stringify(contact.contactMethods)) : ""; const fields = [ @@ -918,7 +907,7 @@ export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => { contact, ); exContact.contactMethods = contact.contactMethods - ? JSON.stringify(parseJsonField(contact.contactMethods, [])) + ? JSON.stringify(contact.contactMethods) : undefined; return exContact; });