mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 02:03:39 +00:00
[PS-1805] BEEEP: Renamed importers based on agreed naming-convention (#3978)
* Rename all importer related files Renamed all files based on our naming convention which we decided on with https://github.com/bitwarden/adr/blob/master/decisions/0012-angular-filename-convention.md * Removed entries from whitelist-capital-letters.txt * Rename missing safeInCloud test data * Fix broken import * Renamed folders (removed capital letters) * Fix filename of BitwardenCsvImporter * Fix imports of onepassword mac/win importer tests * Remove already renamed folders from whitelist * Rename dashlaneImporters to dashlane Rename the folder Fix all the imports Remove dashlaneImporters from white-list * Rename keeperImporters to keeper Rename the folder Fix all the imports Remove keeperImporters from white-list * Rename onepasswordImporters to onepassword Rename the folder Fix all the imports Remove onepasswordImporters from white-list * Rename safeinCloud test data folder * Fix onepassword importer type imports
This commit is contained in:
committed by
GitHub
parent
235fb8f6ee
commit
0e78910582
87
libs/common/src/importers/truekey-csv-importer.ts
Normal file
87
libs/common/src/importers/truekey-csv-importer.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { CipherType } from "../enums/cipherType";
|
||||
import { SecureNoteType } from "../enums/secureNoteType";
|
||||
import { ImportResult } from "../models/domain/import-result";
|
||||
import { CardView } from "../models/view/card.view";
|
||||
import { SecureNoteView } from "../models/view/secure-note.view";
|
||||
|
||||
import { BaseImporter } from "./base-importer";
|
||||
import { Importer } from "./importer";
|
||||
|
||||
const PropertiesToIgnore = [
|
||||
"kind",
|
||||
"autologin",
|
||||
"favorite",
|
||||
"hexcolor",
|
||||
"protectedwithpassword",
|
||||
"subdomainonly",
|
||||
"type",
|
||||
"tk_export_version",
|
||||
"note",
|
||||
"title",
|
||||
"document_content",
|
||||
];
|
||||
|
||||
export class TrueKeyCsvImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): Promise<ImportResult> {
|
||||
const result = new ImportResult();
|
||||
const results = this.parseCsv(data, true);
|
||||
if (results == null) {
|
||||
result.success = false;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
results.forEach((value) => {
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.favorite = this.getValueOrDefault(value.favorite, "").toLowerCase() === "true";
|
||||
cipher.name = this.getValueOrDefault(value.name, "--");
|
||||
cipher.notes = this.getValueOrDefault(value.memo, "");
|
||||
cipher.login.username = this.getValueOrDefault(value.login);
|
||||
cipher.login.password = this.getValueOrDefault(value.password);
|
||||
cipher.login.uris = this.makeUriArray(value.url);
|
||||
|
||||
if (value.kind !== "login") {
|
||||
cipher.name = this.getValueOrDefault(value.title, "--");
|
||||
cipher.notes = this.getValueOrDefault(value.note, "");
|
||||
}
|
||||
|
||||
if (value.kind === "cc") {
|
||||
cipher.type = CipherType.Card;
|
||||
cipher.card = new CardView();
|
||||
cipher.card.cardholderName = this.getValueOrDefault(value.cardholder);
|
||||
cipher.card.number = this.getValueOrDefault(value.number);
|
||||
cipher.card.brand = this.getCardBrand(cipher.card.number);
|
||||
if (!this.isNullOrWhitespace(value.expiryDate)) {
|
||||
try {
|
||||
const expDate = new Date(value.expiryDate);
|
||||
cipher.card.expYear = expDate.getFullYear().toString();
|
||||
cipher.card.expMonth = (expDate.getMonth() + 1).toString();
|
||||
} catch {
|
||||
// Ignore error
|
||||
}
|
||||
}
|
||||
} else if (value.kind !== "login") {
|
||||
cipher.type = CipherType.SecureNote;
|
||||
cipher.secureNote = new SecureNoteView();
|
||||
cipher.secureNote.type = SecureNoteType.Generic;
|
||||
if (!this.isNullOrWhitespace(cipher.notes)) {
|
||||
cipher.notes = this.getValueOrDefault(value.document_content, "");
|
||||
}
|
||||
for (const property in value) {
|
||||
if (
|
||||
value.hasOwnProperty(property) && // eslint-disable-line
|
||||
PropertiesToIgnore.indexOf(property.toLowerCase()) < 0 &&
|
||||
!this.isNullOrWhitespace(value[property])
|
||||
) {
|
||||
this.processKvp(cipher, property, value[property]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
result.success = true;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user