1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00

[BEEEP: PM-10190] Use strict TS checks in CLI service container (#10298)

* move cli service-container to new folder

* fix imports

* add tsconfig and fix type issues in other services

* fix more imports in service-container

* make ts server happy in service-container

* fix actual bugs in cli service-container

* fix package json reference path

* fix service-container import

* update type on cipher service
This commit is contained in:
Jake Fink
2024-08-05 11:39:08 -04:00
committed by GitHub
parent 157f3a5d39
commit 2819ac597f
24 changed files with 110 additions and 81 deletions

View File

@@ -10,7 +10,7 @@ import { ListResponse } from "./models/response/list.response";
import { MessageResponse } from "./models/response/message.response";
import { StringResponse } from "./models/response/string.response";
import { TemplateResponse } from "./models/response/template.response";
import { ServiceContainer } from "./service-container";
import { ServiceContainer } from "./service-container/service-container";
import { CliUtils } from "./utils";
const writeLn = CliUtils.writeLn;

View File

@@ -3,7 +3,7 @@ import { program } from "commander";
import { OssServeConfigurator } from "./oss-serve-configurator";
import { registerOssPrograms } from "./register-oss-programs";
import { ServeProgram } from "./serve.program";
import { ServiceContainer } from "./service-container";
import { ServiceContainer } from "./service-container/service-container";
async function main() {
const serviceContainer = new ServiceContainer();

View File

@@ -7,7 +7,7 @@ import * as koaJson from "koa-json";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { OssServeConfigurator } from "../oss-serve-configurator";
import { ServiceContainer } from "../service-container";
import { ServiceContainer } from "../service-container/service-container";
export class ServeCommand {
constructor(

View File

@@ -13,7 +13,7 @@ import { RestoreCommand } from "./commands/restore.command";
import { StatusCommand } from "./commands/status.command";
import { Response } from "./models/response";
import { FileResponse } from "./models/response/file.response";
import { ServiceContainer } from "./service-container";
import { ServiceContainer } from "./service-container/service-container";
import { GenerateCommand } from "./tools/generate.command";
import {
SendEditCommand,

View File

@@ -1,5 +1,5 @@
import { Program } from "./program";
import { ServiceContainer } from "./service-container";
import { ServiceContainer } from "./service-container/service-container";
import { SendProgram } from "./tools/send/send.program";
import { VaultProgram } from "./vault.program";

View File

@@ -3,7 +3,7 @@ import { program } from "commander";
import { BaseProgram } from "./base-program";
import { ServeCommand } from "./commands/serve.command";
import { OssServeConfigurator } from "./oss-serve-configurator";
import { ServiceContainer } from "./service-container";
import { ServiceContainer } from "./service-container/service-container";
import { CliUtils } from "./utils";
const writeLn = CliUtils.writeLn;

View File

@@ -44,7 +44,10 @@ import { TokenService } from "@bitwarden/common/auth/services/token.service";
import { TwoFactorService } from "@bitwarden/common/auth/services/two-factor.service";
import { UserVerificationApiService } from "@bitwarden/common/auth/services/user-verification/user-verification-api.service";
import { UserVerificationService } from "@bitwarden/common/auth/services/user-verification/user-verification.service";
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
import {
AutofillSettingsService,
AutofillSettingsServiceAbstraction,
} from "@bitwarden/common/autofill/services/autofill-settings.service";
import {
DefaultDomainSettingsService,
DomainSettingsService,
@@ -147,18 +150,18 @@ import {
VaultExportServiceAbstraction,
} from "@bitwarden/vault-export-core";
import { CliPlatformUtilsService } from "./platform/services/cli-platform-utils.service";
import { ConsoleLogService } from "./platform/services/console-log.service";
import { I18nService } from "./platform/services/i18n.service";
import { LowdbStorageService } from "./platform/services/lowdb-storage.service";
import { NodeApiService } from "./platform/services/node-api.service";
import { NodeEnvSecureStorageService } from "./platform/services/node-env-secure-storage.service";
import { CliPlatformUtilsService } from "../platform/services/cli-platform-utils.service";
import { ConsoleLogService } from "../platform/services/console-log.service";
import { I18nService } from "../platform/services/i18n.service";
import { LowdbStorageService } from "../platform/services/lowdb-storage.service";
import { NodeApiService } from "../platform/services/node-api.service";
import { NodeEnvSecureStorageService } from "../platform/services/node-env-secure-storage.service";
// Polyfills
global.DOMParser = new jsdom.JSDOM().window.DOMParser;
// eslint-disable-next-line
const packageJson = require("../package.json");
const packageJson = require("../../package.json");
/**
* Instantiates services and makes them available for dependency injection.
@@ -254,13 +257,13 @@ export class ServiceContainer {
} else if (process.env.BITWARDENCLI_APPDATA_DIR) {
p = path.resolve(process.env.BITWARDENCLI_APPDATA_DIR);
} else if (process.platform === "darwin") {
p = path.join(process.env.HOME, "Library/Application Support/Bitwarden CLI");
p = path.join(process.env.HOME ?? "", "Library/Application Support/Bitwarden CLI");
} else if (process.platform === "win32") {
p = path.join(process.env.APPDATA, "Bitwarden CLI");
p = path.join(process.env.APPDATA ?? "", "Bitwarden CLI");
} else if (process.env.XDG_CONFIG_HOME) {
p = path.join(process.env.XDG_CONFIG_HOME, "Bitwarden CLI");
} else {
p = path.join(process.env.HOME, ".config/Bitwarden CLI");
p = path.join(process.env.HOME ?? "", ".config/Bitwarden CLI");
}
const logoutCallback = async () => await this.logout();
@@ -452,8 +455,6 @@ export class ServiceContainer {
customUserAgent,
);
this.organizationApiService = new OrganizationApiService(this.apiService, this.syncService);
this.containerService = new ContainerService(this.cryptoService, this.encryptService);
this.domainSettingsService = new DefaultDomainSettingsService(this.stateProvider);
@@ -524,6 +525,40 @@ export class ServiceContainer {
this.stateProvider,
);
this.authRequestService = new AuthRequestService(
this.appIdService,
this.accountService,
this.masterPasswordService,
this.cryptoService,
this.apiService,
this.stateProvider,
);
this.billingAccountProfileStateService = new DefaultBillingAccountProfileStateService(
this.stateProvider,
);
this.taskSchedulerService = new DefaultTaskSchedulerService(this.logService);
this.authService = new AuthService(
this.accountService,
this.messagingService,
this.cryptoService,
this.apiService,
this.stateService,
this.tokenService,
);
this.configApiService = new ConfigApiService(this.apiService, this.tokenService);
this.configService = new DefaultConfigService(
this.configApiService,
this.environmentService,
this.logService,
this.stateProvider,
this.authService,
);
this.devicesApiService = new DevicesApiServiceImplementation(this.apiService);
this.deviceTrustService = new DeviceTrustService(
this.keyGenerationService,
@@ -541,20 +576,6 @@ export class ServiceContainer {
this.configService,
);
this.authRequestService = new AuthRequestService(
this.appIdService,
this.accountService,
this.masterPasswordService,
this.cryptoService,
this.apiService,
this.stateProvider,
);
this.billingAccountProfileStateService = new DefaultBillingAccountProfileStateService(
this.stateProvider,
);
this.taskSchedulerService = new DefaultTaskSchedulerService(this.logService);
this.loginStrategyService = new LoginStrategyService(
this.accountService,
this.masterPasswordService,
@@ -583,23 +604,10 @@ export class ServiceContainer {
this.taskSchedulerService,
);
this.authService = new AuthService(
this.accountService,
this.messagingService,
this.cryptoService,
this.apiService,
this.stateService,
this.tokenService,
);
this.configApiService = new ConfigApiService(this.apiService, this.tokenService);
this.configService = new DefaultConfigService(
this.configApiService,
this.environmentService,
this.logService,
// FIXME: CLI does not support autofill
this.autofillSettingsService = new AutofillSettingsService(
this.stateProvider,
this.authService,
this.policyService,
);
this.cipherService = new CipherService(
@@ -661,7 +669,7 @@ export class ServiceContainer {
this.taskSchedulerService,
this.logService,
lockedCallback,
null,
undefined,
);
this.avatarService = new AvatarService(this.apiService, this.stateProvider);
@@ -752,6 +760,8 @@ export class ServiceContainer {
this.accountService,
);
this.organizationApiService = new OrganizationApiService(this.apiService, this.syncService);
this.providerApiService = new ProviderApiService(this.apiService);
}
@@ -774,7 +784,7 @@ export class ServiceContainer {
await this.stateService.clean();
await this.accountService.clean(userId);
await this.accountService.switchAccount(null);
process.env.BW_SESSION = null;
process.env.BW_SESSION = undefined;
}
async init() {
@@ -790,7 +800,7 @@ export class ServiceContainer {
this.twoFactorService.init();
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
if (activeAccount) {
if (activeAccount?.id) {
await this.userAutoUnlockKeyService.setUserKeyInMemoryIfAutoUserKeySet(activeAccount.id);
}

View File

@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"strictNullChecks": true,
"strictPropertyInitialization": true
}
}