Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 85 additions & 2 deletions common/src/importers/mykiCsvImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,42 @@ import { CipherType } from "../enums/cipherType";
import { SecureNoteType } from "../enums/secureNoteType";
import { ImportResult } from "../models/domain/importResult";
import { CardView } from "../models/view/cardView";
import { CipherView } from "../models/view/cipherView";
import { IdentityView } from "../models/view/identityView";
import { SecureNoteView } from "../models/view/secureNoteView";

import { BaseImporter } from "./baseImporter";
import { Importer } from "./importer";

const mappedBaseColumns = ["nickname", "additionalInfo"];
const _mappedUserAccountColumns = new Set(
mappedBaseColumns.concat(["url", "username", "password", "twofaSecret"])
);
const _mappedCreditCardColumns = new Set(
mappedBaseColumns.concat(["cardNumber", "cardName", "exp_month", "exp_year", "cvv"])
);

const _mappedIdentityColumns = new Set(
mappedBaseColumns.concat([
"title",
"firstName",
"middleName",
"lastName",
"email",
"firstAddressLine",
"secondAddressLine",
"city",
"country",
"zipCode",
])
);

const _mappedIdCardColumns = new Set(mappedBaseColumns.concat(["idName", "idNumber", "idCountry"]));

const _mappedTwoFaColumns = new Set(mappedBaseColumns.concat(["authToken"]));

const _mappedUserNoteColumns = new Set(mappedBaseColumns.concat(["content"]));

export class MykiCsvImporter extends BaseImporter implements Importer {
parse(data: string): Promise<ImportResult> {
const result = new ImportResult();
Expand All @@ -27,7 +57,14 @@ export class MykiCsvImporter extends BaseImporter implements Importer {
cipher.login.uris = this.makeUriArray(value.url);
cipher.login.username = this.getValueOrDefault(value.username);
cipher.login.password = this.getValueOrDefault(value.password);
cipher.login.totp = this.getValueOrDefault(value.twoFactAuthToken);
cipher.login.totp = this.getValueOrDefault(value.twofaSecret);

this.importUnmappedFields(cipher, value, _mappedUserAccountColumns);
} else if (value.authToken !== undefined) {
// TwoFA
cipher.login.totp = this.getValueOrDefault(value.authToken);

this.importUnmappedFields(cipher, value, _mappedTwoFaColumns);
} else if (value.cardNumber !== undefined) {
// Cards
cipher.card = new CardView();
Expand All @@ -38,6 +75,8 @@ export class MykiCsvImporter extends BaseImporter implements Importer {
cipher.card.expMonth = this.getValueOrDefault(value.exp_month);
cipher.card.expYear = this.getValueOrDefault(value.exp_year);
cipher.card.code = this.getValueOrDefault(value.cvv);

this.importUnmappedFields(cipher, value, _mappedCreditCardColumns);
} else if (value.firstName !== undefined) {
// Identities
cipher.identity = new IdentityView();
Expand All @@ -53,13 +92,49 @@ export class MykiCsvImporter extends BaseImporter implements Importer {
cipher.identity.city = this.getValueOrDefault(value.city);
cipher.identity.country = this.getValueOrDefault(value.country);
cipher.identity.postalCode = this.getValueOrDefault(value.zipCode);

this.importUnmappedFields(cipher, value, _mappedIdentityColumns);
} else if (value.idType !== undefined) {
// IdCards

cipher.identity = new IdentityView();
cipher.type = CipherType.Identity;
this.processFullName(cipher, value.idName);
cipher.identity.country = this.getValueOrDefault(value.idCountry);

switch (value.idType) {
// case "Driver's License":
// case "ID Card":
// case "Outdoor License":
// case "Software License":
// case "Tax Number":
// case "Bank Account":
// case "Insurance Card":
// case "Health Card":
// case "Membership":
// case "Database":
// case "Reward Program":
// case "Tour Visa":
Comment on lines +106 to +117
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing MyKi doesn't have these id types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does have those idType but as there were no other good identity fields to map to, it uses the switch's default to map them to cipher.identity.licenseNumber

case "Passport":
cipher.identity.passportNumber = value.idNumber;
break;
case "Social Security":
cipher.identity.ssn = value.idNumber;
break;
default:
cipher.identity.licenseNumber = value.idNumber;
break;
}

this.importUnmappedFields(cipher, value, _mappedIdCardColumns);
} else if (value.content !== undefined) {
// Notes
cipher.secureNote = new SecureNoteView();
cipher.type = CipherType.SecureNote;
cipher.secureNote.type = SecureNoteType.Generic;
cipher.name = this.getValueOrDefault(value.title, "--");
cipher.notes = this.getValueOrDefault(value.content);

this.importUnmappedFields(cipher, value, _mappedUserNoteColumns);
} else {
return;
}
Expand All @@ -71,4 +146,12 @@ export class MykiCsvImporter extends BaseImporter implements Importer {
result.success = true;
return Promise.resolve(result);
}

importUnmappedFields(cipher: CipherView, row: any, mappedValues: Set<string>) {
const unmappedFields = Object.keys(row).filter((x) => !mappedValues.has(x));
unmappedFields.forEach((key) => {
const item = row as any;
this.processKvp(cipher, key, item[key]);
});
}
}
Loading