[refactor(Account Switching)] Implement StateService (#424)
This commit is contained in:
parent
eb122532bd
commit
179f1dfe5d
2
jslib
2
jslib
|
@ -1 +1 @@
|
|||
Subproject commit 8fc3cf50d2967212ffbbf0d57cac71d0774aa2a8
|
||||
Subproject commit d68c1dafaf0528f5323dd595773b0fa122403d0d
|
132
src/bw.ts
132
src/bw.ts
|
@ -3,6 +3,7 @@ import * as fs from "fs";
|
|||
import * as jsdom from "jsdom";
|
||||
import * as path from "path";
|
||||
|
||||
import { KeySuffixOptions } from "jslib-common/enums/keySuffixOptions";
|
||||
import { LogLevelType } from "jslib-common/enums/logLevelType";
|
||||
|
||||
import { AuthService } from "jslib-common/services/auth.service";
|
||||
|
@ -17,7 +18,6 @@ import { AppIdService } from "jslib-common/services/appId.service";
|
|||
import { AuditService } from "jslib-common/services/audit.service";
|
||||
import { CipherService } from "jslib-common/services/cipher.service";
|
||||
import { CollectionService } from "jslib-common/services/collection.service";
|
||||
import { ConstantsService } from "jslib-common/services/constants.service";
|
||||
import { ContainerService } from "jslib-common/services/container.service";
|
||||
import { CryptoService } from "jslib-common/services/crypto.service";
|
||||
import { EnvironmentService } from "jslib-common/services/environment.service";
|
||||
|
@ -27,17 +27,21 @@ import { FolderService } from "jslib-common/services/folder.service";
|
|||
import { ImportService } from "jslib-common/services/import.service";
|
||||
import { KeyConnectorService } from "jslib-common/services/keyConnector.service";
|
||||
import { NoopMessagingService } from "jslib-common/services/noopMessaging.service";
|
||||
import { OrganizationService } from "jslib-common/services/organization.service";
|
||||
import { PasswordGenerationService } from "jslib-common/services/passwordGeneration.service";
|
||||
import { PolicyService } from "jslib-common/services/policy.service";
|
||||
import { ProviderService } from "jslib-common/services/provider.service";
|
||||
import { SearchService } from "jslib-common/services/search.service";
|
||||
import { SendService } from "jslib-common/services/send.service";
|
||||
import { SettingsService } from "jslib-common/services/settings.service";
|
||||
import { StateService } from "jslib-common/services/state.service";
|
||||
import { StateMigrationService } from "jslib-common/services/stateMigration.service";
|
||||
import { SyncService } from "jslib-common/services/sync.service";
|
||||
import { TokenService } from "jslib-common/services/token.service";
|
||||
import { TotpService } from "jslib-common/services/totp.service";
|
||||
import { UserService } from "jslib-common/services/user.service";
|
||||
import { UserVerificationService } from "jslib-common/services/userVerification.service";
|
||||
import { VaultTimeoutService } from "jslib-common/services/vaultTimeout.service";
|
||||
|
||||
import { LowdbStorageService } from "jslib-node/services/lowdbStorage.service";
|
||||
import { NodeApiService } from "jslib-node/services/nodeApi.service";
|
||||
import { NodeCryptoFunctionService } from "jslib-node/services/nodeCryptoFunction.service";
|
||||
|
@ -58,13 +62,11 @@ export class Main {
|
|||
secureStorageService: NodeEnvSecureStorageService;
|
||||
i18nService: I18nService;
|
||||
platformUtilsService: CliPlatformUtilsService;
|
||||
constantsService: ConstantsService;
|
||||
cryptoService: CryptoService;
|
||||
tokenService: TokenService;
|
||||
appIdService: AppIdService;
|
||||
apiService: NodeApiService;
|
||||
environmentService: EnvironmentService;
|
||||
userService: UserService;
|
||||
settingsService: SettingsService;
|
||||
cipherService: CipherService;
|
||||
folderService: FolderService;
|
||||
|
@ -89,6 +91,10 @@ export class Main {
|
|||
fileUploadService: FileUploadService;
|
||||
keyConnectorService: KeyConnectorService;
|
||||
userVerificationService: UserVerificationService;
|
||||
stateService: StateService;
|
||||
stateMigrationService: StateMigrationService;
|
||||
organizationService: OrganizationService;
|
||||
providerService: ProviderService;
|
||||
|
||||
constructor() {
|
||||
let p = null;
|
||||
|
@ -120,17 +126,30 @@ export class Main {
|
|||
this.logService,
|
||||
() => this.cryptoService
|
||||
);
|
||||
this.cryptoService = new CryptoService(
|
||||
|
||||
this.stateMigrationService = new StateMigrationService(
|
||||
this.storageService,
|
||||
this.secureStorageService
|
||||
);
|
||||
|
||||
this.stateService = new StateService(
|
||||
this.storageService,
|
||||
this.secureStorageService,
|
||||
this.logService,
|
||||
this.stateMigrationService
|
||||
);
|
||||
|
||||
this.cryptoService = new CryptoService(
|
||||
this.cryptoFunctionService,
|
||||
this.platformUtilsService,
|
||||
this.logService
|
||||
this.logService,
|
||||
this.stateService
|
||||
);
|
||||
|
||||
this.appIdService = new AppIdService(this.storageService);
|
||||
this.tokenService = new TokenService(this.storageService);
|
||||
this.tokenService = new TokenService(this.stateService);
|
||||
this.messagingService = new NoopMessagingService();
|
||||
this.environmentService = new EnvironmentService(this.storageService);
|
||||
this.environmentService = new EnvironmentService(this.stateService);
|
||||
this.apiService = new NodeApiService(
|
||||
this.tokenService,
|
||||
this.platformUtilsService,
|
||||
|
@ -143,97 +162,113 @@ export class Main {
|
|||
")",
|
||||
(clientId, clientSecret) => this.authService.logInApiKey(clientId, clientSecret)
|
||||
);
|
||||
this.userService = new UserService(this.tokenService, this.storageService);
|
||||
this.containerService = new ContainerService(this.cryptoService);
|
||||
this.settingsService = new SettingsService(this.userService, this.storageService);
|
||||
|
||||
this.settingsService = new SettingsService(this.stateService);
|
||||
|
||||
this.fileUploadService = new FileUploadService(this.logService, this.apiService);
|
||||
|
||||
this.cipherService = new CipherService(
|
||||
this.cryptoService,
|
||||
this.userService,
|
||||
this.settingsService,
|
||||
this.apiService,
|
||||
this.fileUploadService,
|
||||
this.storageService,
|
||||
this.i18nService,
|
||||
null,
|
||||
this.logService
|
||||
this.logService,
|
||||
this.stateService
|
||||
);
|
||||
|
||||
this.folderService = new FolderService(
|
||||
this.cryptoService,
|
||||
this.userService,
|
||||
this.apiService,
|
||||
this.storageService,
|
||||
this.i18nService,
|
||||
this.cipherService
|
||||
this.cipherService,
|
||||
this.stateService
|
||||
);
|
||||
|
||||
this.collectionService = new CollectionService(
|
||||
this.cryptoService,
|
||||
this.userService,
|
||||
this.storageService,
|
||||
this.i18nService
|
||||
this.i18nService,
|
||||
this.stateService
|
||||
);
|
||||
|
||||
this.searchService = new SearchService(this.cipherService, this.logService, this.i18nService);
|
||||
this.policyService = new PolicyService(this.userService, this.storageService, this.apiService);
|
||||
|
||||
this.providerService = new ProviderService(this.stateService);
|
||||
|
||||
this.organizationService = new OrganizationService(this.stateService);
|
||||
|
||||
this.policyService = new PolicyService(
|
||||
this.stateService,
|
||||
this.organizationService,
|
||||
this.apiService
|
||||
);
|
||||
|
||||
this.sendService = new SendService(
|
||||
this.cryptoService,
|
||||
this.userService,
|
||||
this.apiService,
|
||||
this.fileUploadService,
|
||||
this.storageService,
|
||||
this.i18nService,
|
||||
this.cryptoFunctionService
|
||||
this.cryptoFunctionService,
|
||||
this.stateService
|
||||
);
|
||||
|
||||
this.keyConnectorService = new KeyConnectorService(
|
||||
this.storageService,
|
||||
this.userService,
|
||||
this.stateService,
|
||||
this.cryptoService,
|
||||
this.apiService,
|
||||
this.tokenService,
|
||||
this.logService
|
||||
this.logService,
|
||||
this.organizationService
|
||||
);
|
||||
|
||||
this.vaultTimeoutService = new VaultTimeoutService(
|
||||
this.cipherService,
|
||||
this.folderService,
|
||||
this.collectionService,
|
||||
this.cryptoService,
|
||||
this.platformUtilsService,
|
||||
this.storageService,
|
||||
this.messagingService,
|
||||
this.searchService,
|
||||
this.userService,
|
||||
this.tokenService,
|
||||
this.policyService,
|
||||
this.keyConnectorService,
|
||||
async () => await this.cryptoService.clearStoredKey("auto"),
|
||||
this.stateService,
|
||||
async () => await this.cryptoService.clearStoredKey(KeySuffixOptions.Auto),
|
||||
null
|
||||
);
|
||||
|
||||
this.syncService = new SyncService(
|
||||
this.userService,
|
||||
this.apiService,
|
||||
this.settingsService,
|
||||
this.folderService,
|
||||
this.cipherService,
|
||||
this.cryptoService,
|
||||
this.collectionService,
|
||||
this.storageService,
|
||||
this.messagingService,
|
||||
this.policyService,
|
||||
this.sendService,
|
||||
this.logService,
|
||||
this.tokenService,
|
||||
this.keyConnectorService,
|
||||
this.stateService,
|
||||
this.organizationService,
|
||||
this.providerService,
|
||||
async (expired: boolean) => await this.logout()
|
||||
);
|
||||
|
||||
this.passwordGenerationService = new PasswordGenerationService(
|
||||
this.cryptoService,
|
||||
this.storageService,
|
||||
this.policyService
|
||||
this.policyService,
|
||||
this.stateService
|
||||
);
|
||||
|
||||
this.totpService = new TotpService(
|
||||
this.storageService,
|
||||
this.cryptoFunctionService,
|
||||
this.logService
|
||||
this.logService,
|
||||
this.stateService
|
||||
);
|
||||
|
||||
this.importService = new ImportService(
|
||||
this.cipherService,
|
||||
this.folderService,
|
||||
|
@ -249,10 +284,10 @@ export class Main {
|
|||
this.apiService,
|
||||
this.cryptoService
|
||||
);
|
||||
|
||||
this.authService = new AuthService(
|
||||
this.cryptoService,
|
||||
this.apiService,
|
||||
this.userService,
|
||||
this.tokenService,
|
||||
this.appIdService,
|
||||
this.i18nService,
|
||||
|
@ -261,10 +296,12 @@ export class Main {
|
|||
this.vaultTimeoutService,
|
||||
this.logService,
|
||||
this.cryptoFunctionService,
|
||||
this.environmentService,
|
||||
this.keyConnectorService,
|
||||
this.environmentService,
|
||||
this.stateService,
|
||||
true
|
||||
);
|
||||
|
||||
this.auditService = new AuditService(this.cryptoFunctionService, this.apiService);
|
||||
this.program = new Program(this);
|
||||
this.vaultProgram = new VaultProgram(this);
|
||||
|
@ -291,12 +328,11 @@ export class Main {
|
|||
}
|
||||
|
||||
async logout() {
|
||||
const userId = await this.userService.getUserId();
|
||||
const userId = await this.stateService.getUserId();
|
||||
await Promise.all([
|
||||
this.syncService.setLastSync(new Date(0)),
|
||||
this.tokenService.clearToken(),
|
||||
this.cryptoService.clearKeys(),
|
||||
this.userService.clear(),
|
||||
this.settingsService.clear(userId),
|
||||
this.cipherService.clear(userId),
|
||||
this.folderService.clear(userId),
|
||||
|
@ -304,29 +340,23 @@ export class Main {
|
|||
this.policyService.clear(userId),
|
||||
this.passwordGenerationService.clear(),
|
||||
]);
|
||||
await this.stateService.clean();
|
||||
process.env.BW_SESSION = null;
|
||||
}
|
||||
|
||||
private async init() {
|
||||
await this.storageService.init();
|
||||
await this.stateService.init();
|
||||
this.containerService.attachToWindow(global);
|
||||
await this.environmentService.setUrlsFromStorage();
|
||||
// Dev Server URLs. Comment out the line above.
|
||||
// this.apiService.setUrls({
|
||||
// base: null,
|
||||
// api: 'http://localhost:4000',
|
||||
// identity: 'http://localhost:33656',
|
||||
// });
|
||||
const locale = await this.storageService.get<string>(ConstantsService.localeKey);
|
||||
const locale = await this.stateService.getLocale();
|
||||
await this.i18nService.init(locale);
|
||||
this.authService.init();
|
||||
|
||||
const installedVersion = await this.storageService.get<string>(
|
||||
ConstantsService.installedVersionKey
|
||||
);
|
||||
const installedVersion = await this.stateService.getInstalledVersion();
|
||||
const currentVersion = await this.platformUtilsService.getApplicationVersion();
|
||||
if (installedVersion == null || installedVersion !== currentVersion) {
|
||||
await this.storageService.save(ConstantsService.installedVersionKey, currentVersion);
|
||||
await this.stateService.setInstalledVersion(currentVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import { ApiService } from "jslib-common/abstractions/api.service";
|
|||
import { CipherService } from "jslib-common/abstractions/cipher.service";
|
||||
import { CryptoService } from "jslib-common/abstractions/crypto.service";
|
||||
import { FolderService } from "jslib-common/abstractions/folder.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
|
||||
import { Cipher } from "jslib-common/models/export/cipher";
|
||||
import { Collection } from "jslib-common/models/export/collection";
|
||||
|
@ -31,7 +31,7 @@ export class CreateCommand {
|
|||
constructor(
|
||||
private cipherService: CipherService,
|
||||
private folderService: FolderService,
|
||||
private userService: UserService,
|
||||
private stateService: StateService,
|
||||
private cryptoService: CryptoService,
|
||||
private apiService: ApiService
|
||||
) {}
|
||||
|
@ -100,7 +100,7 @@ export class CreateCommand {
|
|||
return Response.notFound();
|
||||
}
|
||||
|
||||
if (cipher.organizationId == null && !(await this.userService.canAccessPremium())) {
|
||||
if (cipher.organizationId == null && !(await this.stateService.getCanAccessPremium())) {
|
||||
return Response.error("Premium status is required to use this feature.");
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import * as program from "commander";
|
|||
import { ApiService } from "jslib-common/abstractions/api.service";
|
||||
import { CipherService } from "jslib-common/abstractions/cipher.service";
|
||||
import { FolderService } from "jslib-common/abstractions/folder.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
|
||||
import { Response } from "jslib-node/cli/models/response";
|
||||
|
||||
|
@ -13,7 +13,7 @@ export class DeleteCommand {
|
|||
constructor(
|
||||
private cipherService: CipherService,
|
||||
private folderService: FolderService,
|
||||
private userService: UserService,
|
||||
private stateService: StateService,
|
||||
private apiService: ApiService
|
||||
) {}
|
||||
|
||||
|
@ -74,7 +74,7 @@ export class DeleteCommand {
|
|||
return Response.error("Attachment `" + id + "` was not found.");
|
||||
}
|
||||
|
||||
if (cipher.organizationId == null && !(await this.userService.canAccessPremium())) {
|
||||
if (cipher.organizationId == null && !(await this.stateService.getCanAccessPremium())) {
|
||||
return Response.error("Premium status is required to use this feature.");
|
||||
}
|
||||
|
||||
|
|
|
@ -112,9 +112,7 @@ export class ExportCommand {
|
|||
|
||||
private async verifyOTP() {
|
||||
await this.userVerificationService.requestOTP();
|
||||
const answer: inquirer.Answers = await inquirer.createPromptModule({
|
||||
output: process.stderr,
|
||||
})({
|
||||
const answer: inquirer.Answers = await inquirer.createPromptModule({ output: process.stderr })({
|
||||
type: "password",
|
||||
name: "otp",
|
||||
message: "A verification code has been emailed to you.\n Verification code:",
|
||||
|
|
|
@ -7,12 +7,11 @@ import { AuditService } from "jslib-common/abstractions/audit.service";
|
|||
import { CipherService } from "jslib-common/abstractions/cipher.service";
|
||||
import { CollectionService } from "jslib-common/abstractions/collection.service";
|
||||
import { CryptoService } from "jslib-common/abstractions/crypto.service";
|
||||
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
||||
import { FolderService } from "jslib-common/abstractions/folder.service";
|
||||
import { OrganizationService } from "jslib-common/abstractions/organization.service";
|
||||
import { SearchService } from "jslib-common/abstractions/search.service";
|
||||
import { SendService } from "jslib-common/abstractions/send.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
import { TotpService } from "jslib-common/abstractions/totp.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
|
||||
import { Organization } from "jslib-common/models/domain/organization";
|
||||
|
||||
|
@ -64,11 +63,10 @@ export class GetCommand extends DownloadCommand {
|
|||
private totpService: TotpService,
|
||||
private auditService: AuditService,
|
||||
cryptoService: CryptoService,
|
||||
private userService: UserService,
|
||||
private stateService: StateService,
|
||||
private searchService: SearchService,
|
||||
private apiService: ApiService,
|
||||
private sendService: SendService,
|
||||
private environmentService: EnvironmentService
|
||||
private organizationService: OrganizationService
|
||||
) {
|
||||
super(cryptoService);
|
||||
}
|
||||
|
@ -250,7 +248,7 @@ export class GetCommand extends DownloadCommand {
|
|||
return Response.error("Couldn't generate TOTP code.");
|
||||
}
|
||||
|
||||
const canAccessPremium = await this.userService.canAccessPremium();
|
||||
const canAccessPremium = await this.stateService.getCanAccessPremium();
|
||||
if (!canAccessPremium) {
|
||||
const originalCipher = await this.cipherService.get(cipher.id);
|
||||
if (
|
||||
|
@ -333,7 +331,7 @@ export class GetCommand extends DownloadCommand {
|
|||
return Response.multipleResults(attachments.map((a) => a.id));
|
||||
}
|
||||
|
||||
if (!(await this.userService.canAccessPremium())) {
|
||||
if (!(await this.stateService.getCanAccessPremium())) {
|
||||
const originalCipher = await this.cipherService.get(cipher.id);
|
||||
if (originalCipher == null || originalCipher.organizationId == null) {
|
||||
return Response.error("Premium status is required to use this feature.");
|
||||
|
@ -450,9 +448,9 @@ export class GetCommand extends DownloadCommand {
|
|||
private async getOrganization(id: string) {
|
||||
let org: Organization = null;
|
||||
if (Utils.isGuid(id)) {
|
||||
org = await this.userService.getOrganization(id);
|
||||
org = await this.organizationService.get(id);
|
||||
} else if (id.trim() !== "") {
|
||||
let orgs = await this.userService.getAllOrganizations();
|
||||
let orgs = await this.organizationService.getAll();
|
||||
orgs = CliUtils.searchOrganizations(orgs, id);
|
||||
if (orgs.length > 1) {
|
||||
return Response.multipleResults(orgs.map((c) => c.id));
|
||||
|
@ -522,7 +520,7 @@ export class GetCommand extends DownloadCommand {
|
|||
private async getFingerprint(id: string) {
|
||||
let fingerprint: string[] = null;
|
||||
if (id === "me") {
|
||||
fingerprint = await this.cryptoService.getFingerprint(await this.userService.getUserId());
|
||||
fingerprint = await this.cryptoService.getFingerprint(await this.stateService.getUserId());
|
||||
} else if (Utils.isGuid(id)) {
|
||||
try {
|
||||
const response = await this.apiService.getUserPublicKey(id);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import * as program from "commander";
|
||||
import { ImportService } from "jslib-common/abstractions/import.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
import { OrganizationService } from "jslib-common/abstractions/organization.service";
|
||||
|
||||
import { Response } from "jslib-node/cli/models/response";
|
||||
import { MessageResponse } from "jslib-node/cli/models/response/messageResponse";
|
||||
|
@ -8,12 +8,15 @@ import { MessageResponse } from "jslib-node/cli/models/response/messageResponse"
|
|||
import { CliUtils } from "../utils";
|
||||
|
||||
export class ImportCommand {
|
||||
constructor(private importService: ImportService, private userService: UserService) {}
|
||||
constructor(
|
||||
private importService: ImportService,
|
||||
private organizationService: OrganizationService
|
||||
) {}
|
||||
|
||||
async run(format: string, filepath: string, options: program.OptionValues): Promise<Response> {
|
||||
const organizationId = options.organizationid;
|
||||
if (organizationId != null) {
|
||||
const organization = await this.userService.getOrganization(organizationId);
|
||||
const organization = await this.organizationService.get(organizationId);
|
||||
|
||||
if (organization == null) {
|
||||
return Response.badRequest(
|
||||
|
|
|
@ -6,8 +6,8 @@ import { ApiService } from "jslib-common/abstractions/api.service";
|
|||
import { CipherService } from "jslib-common/abstractions/cipher.service";
|
||||
import { CollectionService } from "jslib-common/abstractions/collection.service";
|
||||
import { FolderService } from "jslib-common/abstractions/folder.service";
|
||||
import { OrganizationService } from "jslib-common/abstractions/organization.service";
|
||||
import { SearchService } from "jslib-common/abstractions/search.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
|
||||
import {
|
||||
CollectionDetailsResponse as ApiCollectionDetailsResponse,
|
||||
|
@ -37,7 +37,7 @@ export class ListCommand {
|
|||
private cipherService: CipherService,
|
||||
private folderService: FolderService,
|
||||
private collectionService: CollectionService,
|
||||
private userService: UserService,
|
||||
private organizationService: OrganizationService,
|
||||
private searchService: SearchService,
|
||||
private apiService: ApiService
|
||||
) {}
|
||||
|
@ -171,7 +171,7 @@ export class ListCommand {
|
|||
if (!Utils.isGuid(options.organizationid)) {
|
||||
return Response.error("`" + options.organizationid + "` is not a GUID.");
|
||||
}
|
||||
const organization = await this.userService.getOrganization(options.organizationid);
|
||||
const organization = await this.organizationService.get(options.organizationid);
|
||||
if (organization == null) {
|
||||
return Response.error("Organization not found.");
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ export class ListCommand {
|
|||
if (!Utils.isGuid(options.organizationid)) {
|
||||
return Response.error("`" + options.organizationid + "` is not a GUID.");
|
||||
}
|
||||
const organization = await this.userService.getOrganization(options.organizationid);
|
||||
const organization = await this.organizationService.get(options.organizationid);
|
||||
if (organization == null) {
|
||||
return Response.error("Organization not found.");
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ export class ListCommand {
|
|||
}
|
||||
|
||||
private async listOrganizations(options: program.OptionValues) {
|
||||
let organizations = await this.userService.getAllOrganizations();
|
||||
let organizations = await this.organizationService.getAll();
|
||||
|
||||
if (options.search != null && options.search.trim() !== "") {
|
||||
organizations = CliUtils.searchOrganizations(organizations, options.search);
|
||||
|
|
|
@ -11,8 +11,8 @@ import { KeyConnectorService } from "jslib-common/abstractions/keyConnector.serv
|
|||
import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service";
|
||||
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
|
||||
import { PolicyService } from "jslib-common/abstractions/policy.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
import { SyncService } from "jslib-common/abstractions/sync.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
|
||||
import { MessageResponse } from "jslib-node/cli/models/response/messageResponse";
|
||||
|
||||
|
@ -32,7 +32,7 @@ export class LoginCommand extends BaseLoginCommand {
|
|||
environmentService: EnvironmentService,
|
||||
passwordGenerationService: PasswordGenerationService,
|
||||
platformUtilsService: PlatformUtilsService,
|
||||
userService: UserService,
|
||||
stateService: StateService,
|
||||
cryptoService: CryptoService,
|
||||
policyService: PolicyService,
|
||||
keyConnectorService: KeyConnectorService,
|
||||
|
@ -46,7 +46,7 @@ export class LoginCommand extends BaseLoginCommand {
|
|||
passwordGenerationService,
|
||||
cryptoFunctionService,
|
||||
platformUtilsService,
|
||||
userService,
|
||||
stateService,
|
||||
cryptoService,
|
||||
policyService,
|
||||
"cli",
|
||||
|
|
|
@ -4,7 +4,7 @@ import * as path from "path";
|
|||
|
||||
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
||||
import { SendService } from "jslib-common/abstractions/send.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
|
||||
import { SendType } from "jslib-common/enums/sendType";
|
||||
|
||||
|
@ -21,7 +21,7 @@ import { CliUtils } from "../../utils";
|
|||
export class SendCreateCommand {
|
||||
constructor(
|
||||
private sendService: SendService,
|
||||
private userService: UserService,
|
||||
private stateService: StateService,
|
||||
private environmentService: EnvironmentService
|
||||
) {}
|
||||
|
||||
|
@ -73,7 +73,7 @@ export class SendCreateCommand {
|
|||
|
||||
switch (req.type) {
|
||||
case SendType.File:
|
||||
if (!(await this.userService.canAccessPremium())) {
|
||||
if (!(await this.stateService.getCanAccessPremium())) {
|
||||
return Response.error("Premium status is required to use this feature.");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import * as program from "commander";
|
||||
|
||||
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
||||
import { SendService } from "jslib-common/abstractions/send.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
|
||||
import { SendType } from "jslib-common/enums/sendType";
|
||||
import { Response } from "jslib-node/cli/models/response";
|
||||
|
@ -15,7 +14,7 @@ import { SendGetCommand } from "./get.command";
|
|||
export class SendEditCommand {
|
||||
constructor(
|
||||
private sendService: SendService,
|
||||
private userService: UserService,
|
||||
private stateService: StateService,
|
||||
private getCommand: SendGetCommand
|
||||
) {}
|
||||
|
||||
|
@ -52,7 +51,7 @@ export class SendEditCommand {
|
|||
return Response.badRequest("Cannot change a Send's type");
|
||||
}
|
||||
|
||||
if (send.type === SendType.File && !(await this.userService.canAccessPremium())) {
|
||||
if (send.type === SendType.File && !(await this.stateService.getCanAccessPremium())) {
|
||||
return Response.error("Premium status is required to use this feature.");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import * as program from "commander";
|
||||
|
||||
import { EnvironmentService } from "jslib-common/abstractions/environment.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
import { SyncService } from "jslib-common/abstractions/sync.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
import { VaultTimeoutService } from "jslib-common/abstractions/vaultTimeout.service";
|
||||
|
||||
import { Response } from "jslib-node/cli/models/response";
|
||||
|
@ -13,7 +13,7 @@ export class StatusCommand {
|
|||
constructor(
|
||||
private envService: EnvironmentService,
|
||||
private syncService: SyncService,
|
||||
private userService: UserService,
|
||||
private stateService: StateService,
|
||||
private vaultTimeoutService: VaultTimeoutService
|
||||
) {}
|
||||
|
||||
|
@ -22,8 +22,8 @@ export class StatusCommand {
|
|||
const baseUrl = this.baseUrl();
|
||||
const status = await this.status();
|
||||
const lastSync = await this.syncService.getLastSync();
|
||||
const userId = await this.userService.getUserId();
|
||||
const email = await this.userService.getEmail();
|
||||
const userId = await this.stateService.getUserId();
|
||||
const email = await this.stateService.getEmail();
|
||||
|
||||
return Response.success(
|
||||
new TemplateResponse({
|
||||
|
@ -44,7 +44,7 @@ export class StatusCommand {
|
|||
}
|
||||
|
||||
private async status(): Promise<string> {
|
||||
const authed = await this.userService.isAuthenticated();
|
||||
const authed = await this.stateService.getIsAuthenticated();
|
||||
if (!authed) {
|
||||
return "unauthenticated";
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import * as inquirer from "inquirer";
|
|||
import { ApiService } from "jslib-common/abstractions/api.service";
|
||||
import { CryptoService } from "jslib-common/abstractions/crypto.service";
|
||||
import { CryptoFunctionService } from "jslib-common/abstractions/cryptoFunction.service";
|
||||
import { UserService } from "jslib-common/abstractions/user.service";
|
||||
import { StateService } from "jslib-common/abstractions/state.service";
|
||||
|
||||
import { Response } from "jslib-node/cli/models/response";
|
||||
import { MessageResponse } from "jslib-node/cli/models/response/messageResponse";
|
||||
|
@ -20,7 +20,7 @@ import { ConsoleLogService } from "jslib-common/services/consoleLog.service";
|
|||
export class UnlockCommand {
|
||||
constructor(
|
||||
private cryptoService: CryptoService,
|
||||
private userService: UserService,
|
||||
private stateService: StateService,
|
||||
private cryptoFunctionService: CryptoFunctionService,
|
||||
private apiService: ApiService,
|
||||
private logService: ConsoleLogService
|
||||
|
@ -59,9 +59,9 @@ export class UnlockCommand {
|
|||
}
|
||||
|
||||
this.setNewSessionKey();
|
||||
const email = await this.userService.getEmail();
|
||||
const kdf = await this.userService.getKdf();
|
||||
const kdfIterations = await this.userService.getKdfIterations();
|
||||
const email = await this.stateService.getEmail();
|
||||
const kdf = await this.stateService.getKdfType();
|
||||
const kdfIterations = await this.stateService.getKdfIterations();
|
||||
const key = await this.cryptoService.makeKey(password, email, kdf, kdfIterations);
|
||||
const storedKeyHash = await this.cryptoService.getKeyHash();
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ const writeLn = CliUtils.writeLn;
|
|||
|
||||
export class Program extends BaseProgram {
|
||||
constructor(protected main: Main) {
|
||||
super(main.userService, writeLn);
|
||||
super(main.stateService, writeLn);
|
||||
}
|
||||
|
||||
async register() {
|
||||
|
@ -117,7 +117,7 @@ export class Program extends BaseProgram {
|
|||
"Path to a file containing your password as its first line"
|
||||
)
|
||||
.option("--check", "Check login status.", async () => {
|
||||
const authed = await this.main.userService.isAuthenticated();
|
||||
const authed = await this.main.stateService.getIsAuthenticated();
|
||||
if (authed) {
|
||||
const res = new MessageResponse("You are logged in!", null);
|
||||
this.processResponse(Response.success(res), true);
|
||||
|
@ -151,7 +151,7 @@ export class Program extends BaseProgram {
|
|||
this.main.environmentService,
|
||||
this.main.passwordGenerationService,
|
||||
this.main.platformUtilsService,
|
||||
this.main.userService,
|
||||
this.main.stateService,
|
||||
this.main.cryptoService,
|
||||
this.main.policyService,
|
||||
this.main.keyConnectorService,
|
||||
|
@ -251,7 +251,7 @@ export class Program extends BaseProgram {
|
|||
await this.exitIfNotAuthed();
|
||||
const command = new UnlockCommand(
|
||||
this.main.cryptoService,
|
||||
this.main.userService,
|
||||
this.main.stateService,
|
||||
this.main.cryptoFunctionService,
|
||||
this.main.apiService,
|
||||
this.main.logService
|
||||
|
@ -454,7 +454,7 @@ export class Program extends BaseProgram {
|
|||
const command = new StatusCommand(
|
||||
this.main.environmentService,
|
||||
this.main.syncService,
|
||||
this.main.userService,
|
||||
this.main.stateService,
|
||||
this.main.vaultTimeoutService
|
||||
);
|
||||
const response = await command.run();
|
||||
|
@ -488,7 +488,7 @@ export class Program extends BaseProgram {
|
|||
} else {
|
||||
const command = new UnlockCommand(
|
||||
this.main.cryptoService,
|
||||
this.main.userService,
|
||||
this.main.stateService,
|
||||
this.main.cryptoFunctionService,
|
||||
this.main.apiService,
|
||||
this.main.logService
|
||||
|
|
|
@ -152,11 +152,10 @@ export class SendProgram extends Program {
|
|||
this.main.totpService,
|
||||
this.main.auditService,
|
||||
this.main.cryptoService,
|
||||
this.main.userService,
|
||||
this.main.stateService,
|
||||
this.main.searchService,
|
||||
this.main.apiService,
|
||||
this.main.sendService,
|
||||
this.main.environmentService
|
||||
this.main.organizationService
|
||||
);
|
||||
const response = await cmd.run("template", object, null);
|
||||
this.processResponse(response);
|
||||
|
@ -263,7 +262,7 @@ export class SendProgram extends Program {
|
|||
this.main.searchService,
|
||||
this.main.cryptoService
|
||||
);
|
||||
const cmd = new SendEditCommand(this.main.sendService, this.main.userService, getCmd);
|
||||
const cmd = new SendEditCommand(this.main.sendService, this.main.stateService, getCmd);
|
||||
const response = await cmd.run(encodedJson, options);
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
@ -330,7 +329,7 @@ export class SendProgram extends Program {
|
|||
await this.exitIfLocked();
|
||||
const cmd = new SendCreateCommand(
|
||||
this.main.sendService,
|
||||
this.main.userService,
|
||||
this.main.stateService,
|
||||
this.main.environmentService
|
||||
);
|
||||
return await cmd.run(encodedJson, options);
|
||||
|
|
|
@ -118,7 +118,7 @@ export class VaultProgram extends Program {
|
|||
this.main.cipherService,
|
||||
this.main.folderService,
|
||||
this.main.collectionService,
|
||||
this.main.userService,
|
||||
this.main.organizationService,
|
||||
this.main.searchService,
|
||||
this.main.apiService
|
||||
);
|
||||
|
@ -190,11 +190,10 @@ export class VaultProgram extends Program {
|
|||
this.main.totpService,
|
||||
this.main.auditService,
|
||||
this.main.cryptoService,
|
||||
this.main.userService,
|
||||
this.main.stateService,
|
||||
this.main.searchService,
|
||||
this.main.apiService,
|
||||
this.main.sendService,
|
||||
this.main.environmentService
|
||||
this.main.organizationService
|
||||
);
|
||||
const response = await command.run(object, id, cmd);
|
||||
this.processResponse(response);
|
||||
|
@ -232,7 +231,7 @@ export class VaultProgram extends Program {
|
|||
const command = new CreateCommand(
|
||||
this.main.cipherService,
|
||||
this.main.folderService,
|
||||
this.main.userService,
|
||||
this.main.stateService,
|
||||
this.main.cryptoService,
|
||||
this.main.apiService
|
||||
);
|
||||
|
@ -318,7 +317,7 @@ export class VaultProgram extends Program {
|
|||
const command = new DeleteCommand(
|
||||
this.main.cipherService,
|
||||
this.main.folderService,
|
||||
this.main.userService,
|
||||
this.main.stateService,
|
||||
this.main.apiService
|
||||
);
|
||||
const response = await command.run(object, id, cmd);
|
||||
|
@ -440,7 +439,7 @@ export class VaultProgram extends Program {
|
|||
})
|
||||
.action(async (format, filepath, options) => {
|
||||
await this.exitIfLocked();
|
||||
const command = new ImportCommand(this.main.importService, this.main.userService);
|
||||
const command = new ImportCommand(this.main.importService, this.main.organizationService);
|
||||
const response = await command.run(format, filepath, options);
|
||||
this.processResponse(response);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue