mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
* Move DeprecatedVaultFilterService to vault folder * [libs] move VaultItemsComponent * [libs] move AddEditComponent * [libs] move AddEditCustomFields * [libs] move attachmentsComponent * [libs] folderAddEditComponent * [libs] IconComponent * [libs] PasswordRepormptComponent * [libs] PremiumComponent * [libs] ViewCustomFieldsComponent * [libs] ViewComponent * [libs] PasswordRepromptService * [libs] Move FolderService and FolderApiService abstractions * [libs] FolderService imports * [libs] PasswordHistoryComponent * [libs] move Sync and SyncNotifier abstractions * [libs] SyncService imports * [libs] fix file casing for passwordReprompt abstraction * [libs] SyncNotifier import fix * [libs] CipherServiceAbstraction * [libs] PasswordRepromptService abstraction * [libs] Fix file casing for angular passwordReprompt service * [libs] fix file casing for SyncNotifierService * [libs] CipherRepromptType * [libs] rename CipherRepromptType * [libs] CipherType * [libs] Rename CipherType * [libs] CipherData * [libs] FolderData * [libs] PasswordHistoryData * [libs] AttachmentData * [libs] CardData * [libs] FieldData * [libs] IdentityData * [libs] LocalData * [libs] LoginData * [libs] SecureNoteData * [libs] LoginUriData * [libs] Domain classes * [libs] SecureNote * [libs] Request models * [libs] Response models * [libs] View part 1 * [libs] Views part 2 * [libs] Move folder services * [libs] Views fixes * [libs] Move sync services * [libs] cipher service * [libs] Types * [libs] Sync file casing * [libs] Fix folder service import * [libs] Move spec files * [libs] casing fixes on spec files * [browser] Autofill background, clipboard, commands * [browser] Fix ContextMenusBackground casing * [browser] Rename fix * [browser] Autofill content * [browser] autofill.js * [libs] enpass importer spec fix * [browser] autofill models * [browser] autofill manifest path updates * [browser] Autofill notification files * [browser] autofill services * [browser] Fix file casing * [browser] Vault popup loose components * [browser] Vault components * [browser] Manifest fixes * [browser] Vault services * [cli] vault commands and models * [browser] File capitilization fixes * [desktop] Vault components and services * [web] vault loose components * [web] Vault components * [browser] Fix misc-utils import * [libs] Fix psono spec imports * [fix] Add comments to address lint rules
88 lines
3.0 KiB
TypeScript
88 lines
3.0 KiB
TypeScript
import { SecureNoteType } from "../enums/secureNoteType";
|
|
import { ImportResult } from "../models/domain/import-result";
|
|
import { CipherType } from "../vault/enums/cipher-type";
|
|
import { CardView } from "../vault/models/view/card.view";
|
|
import { SecureNoteView } from "../vault/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);
|
|
}
|
|
}
|