Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Update import unknown custom field type handling

Leendert de Borsteee3f826de42
diff --git a/core/client/src/transfer/import/importers/aliasvault/AvuxImportService.ts b/core/client/src/transfer/import/importers/aliasvault/AvuxImportService.ts
index 178974f8e..dcbaf3bd9 100644
--- a/core/client/src/transfer/import/importers/aliasvault/AvuxImportService.ts
+++ b/core/client/src/transfer/import/importers/aliasvault/AvuxImportService.ts
@@ -344,12 +344,12 @@ export class AvuxImportService {
}
/**
- * Map a field type string to a known field type, Text for anything unknown.
+ * Read a field type, keeping one this build does not know as-is (it renders as text, like on sync); Text when empty.
* @param value - The field type text
* @returns The field type
*/
- private static toFieldType(value: string): FieldType {
- return (Object.values(FieldTypes) as string[]).includes(value) ? value as FieldType : FieldTypes.Text;
+ private static toFieldType(value: string | null | undefined): FieldType {
+ return value ? value as FieldType : FieldTypes.Text;
}
/**
diff --git a/core/client/src/transfer/import/writers/ItemConverter.ts b/core/client/src/transfer/import/writers/ItemConverter.ts
index 666808c79..ce85ad973 100644
--- a/core/client/src/transfer/import/writers/ItemConverter.ts
+++ b/core/client/src/transfer/import/writers/ItemConverter.ts
@@ -1,4 +1,4 @@
-import { FieldKey, ItemTypes, type ItemType } from '@aliasvault/models/vault';
+import { FieldKey, FieldTypes, ItemTypes, type ItemType } from '@aliasvault/models/vault';
import { logExpected } from '../../../utilities/Diagnostics';
import { formatDateOnly } from '../../shared/DateTimeUtils';
@@ -90,7 +90,7 @@ export function convertToItem(credential: ImportedCredential, folderPathToId: Ma
// Values of the same source definition share one definition.
const definitionsBySourceId = new Map<string, FieldDefinitionEntity>();
for (const customField of credential.CustomFieldValues ?? []) {
- if (isBlank(customField.Value)) {
+ if (isBlank(customField.Value) && holdsValue(customField.FieldType)) {
continue;
}
@@ -110,7 +110,7 @@ export function convertToItem(credential: ImportedCredential, folderPathToId: Ma
definitionsBySourceId.set(customField.DefinitionId, definition);
}
- item.FieldValues.push({ Id: crypto.randomUUID(), ItemId: itemId, FieldDefinition: definition, FieldDefinitionId: definition.Id, FieldKey: null, Value: customField.Value, Weight: customField.ValueWeight, ...row });
+ item.FieldValues.push({ Id: crypto.randomUUID(), ItemId: itemId, FieldDefinition: definition, FieldDefinitionId: definition.Id, FieldKey: null, Value: customField.Value ?? '', Weight: customField.ValueWeight, ...row });
}
return item;
@@ -152,3 +152,12 @@ function hasAliasData(credential: ImportedCredential): boolean {
const alias = credential.Alias;
return !!alias && (!!alias.FirstName || !!alias.LastName || !!alias.Gender || !!alias.BirthDate);
}
+
+/**
+ * Whether a custom field type is one this build knows to carry a value; blank fields of other types (a section, a newer layout type) are kept.
+ * @param fieldType - The field type
+ * @returns True for a known value type
+ */
+function holdsValue(fieldType: string): boolean {
+ return fieldType !== FieldTypes.Section && (Object.values(FieldTypes) as string[]).includes(fieldType);
+}