mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 17:53:39 +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
61
libs/importer/src/importers/passman-json-importer.ts
Normal file
61
libs/importer/src/importers/passman-json-importer.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { ImportResult } from "../models/import-result";
|
||||
|
||||
import { BaseImporter } from "./base-importer";
|
||||
import { Importer } from "./importer";
|
||||
|
||||
export class PassmanJsonImporter extends BaseImporter implements Importer {
|
||||
parse(data: string): Promise<ImportResult> {
|
||||
const result = new ImportResult();
|
||||
const results = JSON.parse(data);
|
||||
if (results == null || results.length === 0) {
|
||||
result.success = false;
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
results.forEach((credential: any) => {
|
||||
if (credential.tags != null && credential.tags.length > 0) {
|
||||
const folderName = credential.tags[0].text;
|
||||
this.processFolder(result, folderName);
|
||||
}
|
||||
|
||||
const cipher = this.initLoginCipher();
|
||||
cipher.name = credential.label;
|
||||
|
||||
cipher.login.username = this.getValueOrDefault(credential.username);
|
||||
if (this.isNullOrWhitespace(cipher.login.username)) {
|
||||
cipher.login.username = this.getValueOrDefault(credential.email);
|
||||
} else if (!this.isNullOrWhitespace(credential.email)) {
|
||||
cipher.notes = "Email: " + credential.email + "\n";
|
||||
}
|
||||
|
||||
cipher.login.password = this.getValueOrDefault(credential.password);
|
||||
cipher.login.uris = this.makeUriArray(credential.url);
|
||||
cipher.notes += this.getValueOrDefault(credential.description, "");
|
||||
if (credential.otp != null) {
|
||||
cipher.login.totp = this.getValueOrDefault(credential.otp.secret);
|
||||
}
|
||||
|
||||
if (credential.custom_fields != null) {
|
||||
credential.custom_fields.forEach((customField: any) => {
|
||||
switch (customField.field_type) {
|
||||
case "text":
|
||||
case "password":
|
||||
this.processKvp(cipher, customField.label, customField.value);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.convertToNoteIfNeeded(cipher);
|
||||
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