mirror of
https://github.com/bitwarden/browser
synced 2025-12-21 18:53:29 +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:
committed by
GitHub
parent
7cfabf053c
commit
a5a12a6723
69
libs/importer/src/importers/passwordsafe-xml-importer.ts
Normal file
69
libs/importer/src/importers/passwordsafe-xml-importer.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { ImportResult } from "../models/import-result";
|
||||
|
||||
import { BaseImporter } from "./base-importer";
|
||||
import { Importer } from "./importer";
|
||||
|
||||
export class PasswordSafeXmlImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): Promise<ImportResult> {
|
||||
const result = new ImportResult();
|
||||
const doc = this.parseXml(data);
|
||||
if (doc == null) {
|
||||
result.success = false;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
const passwordSafe = doc.querySelector("passwordsafe");
|
||||
if (passwordSafe == null) {
|
||||
result.errorMessage = "Missing `passwordsafe` node.";
|
||||
result.success = false;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
const notesDelimiter = passwordSafe.getAttribute("delimiter");
|
||||
const entries = doc.querySelectorAll("passwordsafe > entry");
|
||||
Array.from(entries).forEach((entry) => {
|
||||
const group = this.querySelectorDirectChild(entry, "group");
|
||||
const groupText =
|
||||
group != null && !this.isNullOrWhitespace(group.textContent)
|
||||
? group.textContent.split(".").join("/")
|
||||
: null;
|
||||
this.processFolder(result, groupText);
|
||||
|
||||
const title = this.querySelectorDirectChild(entry, "title");
|
||||
const username = this.querySelectorDirectChild(entry, "username");
|
||||
const email = this.querySelectorDirectChild(entry, "email");
|
||||
const password = this.querySelectorDirectChild(entry, "password");
|
||||
const url = this.querySelectorDirectChild(entry, "url");
|
||||
const notes = this.querySelectorDirectChild(entry, "notes");
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = title != null ? this.getValueOrDefault(title.textContent, "--") : "--";
|
||||
cipher.notes =
|
||||
notes != null
|
||||
? this.getValueOrDefault(notes.textContent, "").split(notesDelimiter).join("\n")
|
||||
: null;
|
||||
cipher.login.username =
|
||||
username != null ? this.getValueOrDefault(username.textContent) : null;
|
||||
cipher.login.password =
|
||||
password != null ? this.getValueOrDefault(password.textContent) : null;
|
||||
cipher.login.uris = url != null ? this.makeUriArray(url.textContent) : null;
|
||||
|
||||
if (this.isNullOrWhitespace(cipher.login.username) && email != null) {
|
||||
cipher.login.username = this.getValueOrDefault(email.textContent);
|
||||
} else if (email != null && !this.isNullOrWhitespace(email.textContent)) {
|
||||
cipher.notes = this.isNullOrWhitespace(cipher.notes)
|
||||
? "Email: " + email.textContent
|
||||
: cipher.notes + "\n" + "Email: " + email.textContent;
|
||||
}
|
||||
|
||||
this.cleanupCipher(cipher);
|
||||
result.ciphers.push(cipher);
|
||||
});
|
||||
|
||||
if (this.organization) {
|
||||
this.moveFoldersToCollections(result);
|
||||
}
|
||||
|
||||
result.success = true;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user