Browse Source

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
get-get-hash
Matthew Raymer 1 week ago
parent
commit
4480778a49
  1. 15
      src/libs/util.ts

15
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<T>(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<Record<string, unknown>> {
@ -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;
});

Loading…
Cancel
Save