From 892283f4f7a8153ef82a74be899fcea278ecde61 Mon Sep 17 00:00:00 2001 From: Mike Amirault Date: Fri, 13 Nov 2026 14:54:14 -0400 Subject: [PATCH] [PM-43238] Fix credit card imports from Dashlane (#24026) * [PM-43238] Fix credit card imports from Dashlane * Address AI comment --- .../dashlane/dashlane-csv-importer.spec.ts | 70 +++++++++++-------- .../dashlane/dashlane-csv-importer.ts | 8 +++ .../dashlane/types/dashlane-csv-types.ts | 1 + .../spec-data/dashlane-csv/payments.csv.ts | 7 +- 4 files changed, 55 insertions(+), 31 deletions(-) diff --git a/libs/importer/src/importers/dashlane/dashlane-csv-importer.spec.ts b/libs/importer/src/importers/dashlane/dashlane-csv-importer.spec.ts index d802cb84718..4d7565a4f14 100644 --- a/libs/importer/src/importers/dashlane/dashlane-csv-importer.spec.ts +++ b/libs/importer/src/importers/dashlane/dashlane-csv-importer.spec.ts @@ -8,7 +8,7 @@ import { credentialsData_otpUrl } from "../spec-data/dashlane-csv/credentials-ot import { credentialsData } from "../spec-data/dashlane-csv/credentials.csv"; import { identityData } from "../spec-data/dashlane-csv/id.csv"; import { multiplePersonalInfoData } from "../spec-data/dashlane-csv/multiple-personal-info.csv"; -import { paymentsData } from "../spec-data/dashlane-csv/payments.csv"; +import { currentCCData, legacyCCData, paymentsData } from "../spec-data/dashlane-csv/payments.csv"; import { personalInfoData } from "../spec-data/dashlane-csv/personal-info.csv"; import { secureNoteData } from "../spec-data/dashlane-csv/securenotes.csv"; import { assertCustomFieldsStructure } from "../spec-data/importer-test-utils"; @@ -67,7 +67,7 @@ describe("Dashlane CSV Importer", () => { it("with new item types feature flag OFF", async () => { const result = await getImportResult(paymentsData); - expect(result.ciphers.length).toEqual(2); + expect(result.ciphers.length).toEqual(1); // Account const cipher = result.ciphers[0]; @@ -86,29 +86,13 @@ describe("Dashlane CSV Importer", () => { ["country", "US"], ["issuing_bank", "US-ALLY"], ]); - - // CreditCard - const cipher2 = result.ciphers[1]; - expect(cipher2.type).toEqual(CipherType.Card); - expect(cipher2.name).toEqual("John Doe"); - expect(cipher2.card.brand).toEqual("Visa"); - expect(cipher2.card.cardholderName).toEqual("John Doe"); - expect(cipher2.card.number).toEqual("41111111111111111"); - expect(cipher2.card.code).toEqual("123"); - expect(cipher2.card.expMonth).toEqual("1"); - expect(cipher2.card.expYear).toEqual("2023"); - - assertCustomFieldsStructure(cipher2.fields, [ - ["type", "credit_card"], - ["country", "US"], - ]); }); it("with new item types feature flag ON", async () => { configService.getFeatureFlag.mockResolvedValueOnce(true); const result = await getImportResult(paymentsData); - expect(result.ciphers.length).toEqual(2); + expect(result.ciphers.length).toEqual(1); // Account const cipher = result.ciphers[0]; @@ -122,23 +106,49 @@ describe("Dashlane CSV Importer", () => { ["country", "US"], ["issuing_bank", "US-ALLY"], ]); + }); - // CreditCard - const cipher2 = result.ciphers[1]; - expect(cipher2.type).toEqual(CipherType.Card); - expect(cipher2.name).toEqual("John Doe"); - expect(cipher2.card.brand).toEqual("Visa"); - expect(cipher2.card.cardholderName).toEqual("John Doe"); - expect(cipher2.card.number).toEqual("41111111111111111"); - expect(cipher2.card.code).toEqual("123"); - expect(cipher2.card.expMonth).toEqual("1"); - expect(cipher2.card.expYear).toEqual("2023"); + it("parses the legacy credit_card export format for credit cards", async () => { + const result = await getImportResult(legacyCCData); - assertCustomFieldsStructure(cipher2.fields, [ + expect(result.ciphers.length).toEqual(1); + + const cipher = result.ciphers[0]; + expect(cipher.type).toEqual(CipherType.Card); + expect(cipher.name).toEqual("John Doe"); + expect(cipher.card.brand).toEqual("Visa"); + expect(cipher.card.cardholderName).toEqual("John Doe"); + expect(cipher.card.number).toEqual("41111111111111111"); + expect(cipher.card.code).toEqual("123"); + expect(cipher.card.expMonth).toEqual("1"); + expect(cipher.card.expYear).toEqual("2023"); + + assertCustomFieldsStructure(cipher.fields, [ ["type", "credit_card"], ["country", "US"], ]); }); + + it("parses the current payment_card export format for credit cards", async () => { + const result = await getImportResult(currentCCData); + + expect(result.ciphers.length).toEqual(1); + + const cipher = result.ciphers[0]; + expect(cipher.type).toEqual(CipherType.Card); + expect(cipher.name).toEqual("Test Credit Card"); + expect(cipher.card.brand).toEqual("Visa"); + expect(cipher.card.cardholderName).toEqual("John Doe"); + expect(cipher.card.number).toEqual("41111111111111111"); + expect(cipher.card.code).toEqual("123"); + expect(cipher.card.expMonth).toEqual("1"); + expect(cipher.card.expYear).toEqual("2023"); + + assertCustomFieldsStructure(cipher.fields, [ + ["type", "payment_card"], + ["country", "US"], + ]); + }); }); describe("should parse ids records", () => { diff --git a/libs/importer/src/importers/dashlane/dashlane-csv-importer.ts b/libs/importer/src/importers/dashlane/dashlane-csv-importer.ts index d967e9836d9..3d307bd9c81 100644 --- a/libs/importer/src/importers/dashlane/dashlane-csv-importer.ts +++ b/libs/importer/src/importers/dashlane/dashlane-csv-importer.ts @@ -147,6 +147,13 @@ export class DashlaneCsvImporter extends BaseImporter implements Importer { let mappedValues: string[] = []; switch (row.type) { case "credit_card": + case "payment_card": + // Dashlane's curent CSV export uses `payment_card` instead of `credit_card`, but we support both + // If a credit card item has no specific item name (exported to the `name` column in the current + // export format) the cardholder name in `account_name` is used as the item title instead + cipher.type = CipherType.Card; + cipher.card = new CardView(); + cipher.name = !this.isNullOrWhitespace(row.name) ? row.name : row.account_name; cipher.card.cardholderName = row.account_name; cipher.card.number = row.cc_number; cipher.card.brand = CardView.getCardBrandByPatterns(cipher.card.number); @@ -161,6 +168,7 @@ export class DashlaneCsvImporter extends BaseImporter implements Importer { "code", "expiration_month", "expiration_year", + "name", ]; break; case "bank": diff --git a/libs/importer/src/importers/dashlane/types/dashlane-csv-types.ts b/libs/importer/src/importers/dashlane/types/dashlane-csv-types.ts index d8fcdfe5dde..00e1e261ed2 100644 --- a/libs/importer/src/importers/dashlane/types/dashlane-csv-types.ts +++ b/libs/importer/src/importers/dashlane/types/dashlane-csv-types.ts @@ -26,6 +26,7 @@ export class PaymentsRecord { account_number: string; country: string; issuing_bank: string; + name?: string; } export class IdRecord { diff --git a/libs/importer/src/importers/spec-data/dashlane-csv/payments.csv.ts b/libs/importer/src/importers/spec-data/dashlane-csv/payments.csv.ts index 336986c1c49..8f4d4016d94 100644 --- a/libs/importer/src/importers/spec-data/dashlane-csv/payments.csv.ts +++ b/libs/importer/src/importers/spec-data/dashlane-csv/payments.csv.ts @@ -1,3 +1,8 @@ export const paymentsData = `type,account_name,account_holder,cc_number,code,expiration_month,expiration_year,routing_number,account_number,country,issuing_bank -bank,John's savings account,John Doe,,,,,routingNumber,accountNumber,US,US-ALLY +bank,John's savings account,John Doe,,,,,routingNumber,accountNumber,US,US-ALLY`; + +export const legacyCCData = `type,account_name,account_holder,cc_number,code,expiration_month,expiration_year,routing_number,account_number,country,issuing_bank credit_card,John Doe,,41111111111111111,123,01,2023,,,US,`; + +export const currentCCData = `type,account_name,account_holder,cc_number,code,expiration_month,expiration_year,routing_number,account_number,country,issuing_bank,note,name +payment_card,John Doe,,41111111111111111,123,01,2023,,,US,,,Test Credit Card`;