1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 10:43:35 +00:00

[PM-328] Move common/importer to libs/importer (tools-migration) (#5060)

* Create and register new libs/importer

Create package.json
Create tsconfig
Create jest.config
Extend shared and root tsconfig and jest.configs
Register with eslint

* Move importer-related files to libs/importer

* Move importer-spec-related files to libs/importer

Move import.service.spec

* Update package-lock.json

* Set CODEOWNERS for new libs/importer

* Register libs/importer with cli and fix imports

* Register libs/importer with web and fix imports

* Move importOption into models

Rename importOptions to import-options

* Fix linting issues after updating prettier

* Only expose necessary files from libs/importer

Fix tsconfig files
- Removes the trailing /index on imports in web/cli

As the spec-files no longer can access the internals via @bitwarden/importer they import by path (../src/importers)

* Add barrel files to vendors with more than one importer
This commit is contained in:
Daniel James Smith
2023-03-23 11:43:27 +01:00
committed by GitHub
parent 7cfabf053c
commit a5a12a6723
202 changed files with 706 additions and 479 deletions

View File

@@ -0,0 +1,131 @@
import { CipherType } from "@bitwarden/common/vault/enums/cipher-type";
import { CardView } from "@bitwarden/common/vault/models/view/card.view";
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
import { ImportResult } from "../models/import-result";
import { BaseImporter } from "./base-importer";
import { Importer } from "./importer";
export class PasswordBossJsonImporter extends BaseImporter implements Importer {
parse(data: string): Promise<ImportResult> {
const result = new ImportResult();
const results = JSON.parse(data);
if (results == null || results.items == null) {
result.success = false;
return Promise.resolve(result);
}
const foldersMap = new Map<string, string>();
results.folders.forEach((value: any) => {
foldersMap.set(value.id, value.name);
});
const foldersIndexMap = new Map<string, number>();
foldersMap.forEach((val, key) => {
foldersIndexMap.set(key, result.folders.length);
const f = new FolderView();
f.name = val;
result.folders.push(f);
});
results.items.forEach((value: any) => {
const cipher = this.initLoginCipher();
cipher.name = this.getValueOrDefault(value.name, "--");
cipher.login.uris = this.makeUriArray(value.login_url);
if (value.folder != null && foldersIndexMap.has(value.folder)) {
result.folderRelationships.push([result.ciphers.length, foldersIndexMap.get(value.folder)]);
}
if (value.identifiers == null) {
return;
}
if (!this.isNullOrWhitespace(value.identifiers.notes)) {
cipher.notes = value.identifiers.notes.split("\\r\\n").join("\n").split("\\n").join("\n");
}
if (value.type === "CreditCard") {
cipher.card = new CardView();
cipher.type = CipherType.Card;
}
for (const property in value.identifiers) {
// eslint-disable-next-line
if (!value.identifiers.hasOwnProperty(property)) {
continue;
}
const valObj = value.identifiers[property];
const val = valObj != null ? valObj.toString() : null;
if (
this.isNullOrWhitespace(val) ||
property === "notes" ||
property === "ignoreItemInSecurityScore"
) {
continue;
}
if (property === "custom_fields") {
valObj.forEach((cf: any) => {
this.processKvp(cipher, cf.name, cf.value);
});
continue;
}
if (cipher.type === CipherType.Card) {
if (property === "cardNumber") {
cipher.card.number = val;
cipher.card.brand = this.getCardBrand(val);
continue;
} else if (property === "nameOnCard") {
cipher.card.cardholderName = val;
continue;
} else if (property === "security_code") {
cipher.card.code = val;
continue;
} else if (property === "expires") {
try {
const expDate = new Date(val);
cipher.card.expYear = expDate.getFullYear().toString();
cipher.card.expMonth = (expDate.getMonth() + 1).toString();
} catch {
// Ignore error
}
continue;
} else if (property === "cardType") {
continue;
}
} else {
if (
(property === "username" || property === "email") &&
this.isNullOrWhitespace(cipher.login.username)
) {
cipher.login.username = val;
continue;
} else if (property === "password") {
cipher.login.password = val;
continue;
} else if (property === "totp") {
cipher.login.totp = val;
continue;
} else if (
(cipher.login.uris == null || cipher.login.uris.length === 0) &&
this.uriFieldNames.indexOf(property) > -1
) {
cipher.login.uris = this.makeUriArray(val);
continue;
}
}
this.processKvp(cipher, property, val);
}
this.convertToNoteIfNeeded(cipher);
this.cleanupCipher(cipher);
result.ciphers.push(cipher);
});
result.success = true;
return Promise.resolve(result);
}
}