From 83cc88bf5e09e8a0a8afb19e73b1c364e4fd5be1 Mon Sep 17 00:00:00 2001 From: addison Date: Mon, 1 Nov 2021 14:04:43 -0400 Subject: [PATCH] [chore] Remove unused services Several services are no longer in use because of the expanded state service. These have simply been removed. --- common/src/abstractions/apiKey.service.ts | 9 - common/src/abstractions/user.service.ts | 32 --- common/src/services/apiKey.service.ts | 86 -------- common/src/services/constants.service.ts | 68 ------- common/src/services/user.service.ts | 232 ---------------------- 5 files changed, 427 deletions(-) delete mode 100644 common/src/abstractions/apiKey.service.ts delete mode 100644 common/src/abstractions/user.service.ts delete mode 100644 common/src/services/apiKey.service.ts delete mode 100644 common/src/services/constants.service.ts delete mode 100644 common/src/services/user.service.ts diff --git a/common/src/abstractions/apiKey.service.ts b/common/src/abstractions/apiKey.service.ts deleted file mode 100644 index bc4b8a44..00000000 --- a/common/src/abstractions/apiKey.service.ts +++ /dev/null @@ -1,9 +0,0 @@ -export abstract class ApiKeyService { - setInformation: (clientId: string, clientSecret: string) => Promise; - clear: () => Promise; - getClientId: () => Promise; - getClientSecret: () => Promise; - getEntityType: () => Promise; - getEntityId: () => Promise; - isAuthenticated: () => Promise; -} diff --git a/common/src/abstractions/user.service.ts b/common/src/abstractions/user.service.ts deleted file mode 100644 index 0cf6dc77..00000000 --- a/common/src/abstractions/user.service.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { OrganizationData } from '../models/data/organizationData'; -import { ProviderData } from '../models/data/providerData'; -import { Organization } from '../models/domain/organization'; -import { Provider } from '../models/domain/provider'; - -import { KdfType } from '../enums/kdfType'; - -export abstract class UserService { - setInformation: (userId: string, email: string, kdf: KdfType, kdfIterations: number) => Promise; - setEmailVerified: (emailVerified: boolean) => Promise; - setSecurityStamp: (stamp: string) => Promise; - setForcePasswordReset: (forcePasswordReset: boolean) => Promise; - getUserId: () => Promise; - getEmail: () => Promise; - getSecurityStamp: () => Promise; - getKdf: () => Promise; - getKdfIterations: () => Promise; - getEmailVerified: () => Promise; - getForcePasswordReset: () => Promise; - clear: () => Promise; - isAuthenticated: () => Promise; - canAccessPremium: () => Promise; - getOrganization: (id: string) => Promise; - getOrganizationByIdentifier: (identifier: string) => Promise; - getAllOrganizations: () => Promise; - replaceOrganizations: (organizations: { [id: string]: OrganizationData; }) => Promise; - clearOrganizations: (userId: string) => Promise; - getProvider: (id: string) => Promise; - getAllProviders: () => Promise; - replaceProviders: (providers: { [id: string]: ProviderData; }) => Promise; - clearProviders: (userId: string) => Promise; -} diff --git a/common/src/services/apiKey.service.ts b/common/src/services/apiKey.service.ts deleted file mode 100644 index 0b67781b..00000000 --- a/common/src/services/apiKey.service.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { ApiKeyService as ApiKeyServiceAbstraction } from '../abstractions/apiKey.service'; -import { StorageService } from '../abstractions/storage.service'; -import { TokenService } from '../abstractions/token.service'; - -import { Utils } from '../misc/utils'; - -const Keys = { - clientId: 'clientId', - clientSecret: 'clientSecret', - entityType: 'entityType', - entityId: 'entityId', -}; - - -export class ApiKeyService implements ApiKeyServiceAbstraction { - private clientId: string; - private clientSecret: string; - private entityType: string; - private entityId: string; - - constructor(private tokenService: TokenService, private storageService: StorageService) { } - - async setInformation(clientId: string, clientSecret: string) { - this.clientId = clientId; - this.clientSecret = clientSecret; - const idParts = clientId.split('.'); - - if (idParts.length !== 2 || !Utils.isGuid(idParts[1])) { - throw Error('Invalid clientId'); - } - this.entityType = idParts[0]; - this.entityId = idParts[1]; - - await this.storageService.save(Keys.clientId, this.clientId); - await this.storageService.save(Keys.entityId, this.entityId); - await this.storageService.save(Keys.entityType, this.entityType); - await this.storageService.save(Keys.clientSecret, this.clientSecret); - } - - async getClientId(): Promise { - if (this.clientId == null) { - this.clientId = await this.storageService.get(Keys.clientId); - } - return this.clientId; - } - - async getClientSecret(): Promise { - if (this.clientSecret == null) { - this.clientSecret = await this.storageService.get(Keys.clientSecret); - } - return this.clientSecret; - } - - async getEntityType(): Promise { - if (this.entityType == null) { - this.entityType = await this.storageService.get(Keys.entityType); - } - return this.entityType; - } - - async getEntityId(): Promise { - if (this.entityId == null) { - this.entityId = await this.storageService.get(Keys.entityId); - } - return this.entityId; - } - - async clear(): Promise { - await this.storageService.remove(Keys.clientId); - await this.storageService.remove(Keys.clientSecret); - await this.storageService.remove(Keys.entityId); - await this.storageService.remove(Keys.entityType); - - this.clientId = this.clientSecret = this.entityId = this.entityType = null; - } - - async isAuthenticated(): Promise { - const token = await this.tokenService.getToken(); - if (token == null) { - return false; - } - - const entityId = await this.getEntityId(); - return entityId != null; - } -} diff --git a/common/src/services/constants.service.ts b/common/src/services/constants.service.ts deleted file mode 100644 index 9202f862..00000000 --- a/common/src/services/constants.service.ts +++ /dev/null @@ -1,68 +0,0 @@ -export class ConstantsService { - static readonly environmentUrlsKey: string = 'environmentUrls'; - static readonly disableGaKey: string = 'disableGa'; - static readonly disableAddLoginNotificationKey: string = 'disableAddLoginNotification'; - static readonly disableChangedPasswordNotificationKey: string = 'disableChangedPasswordNotification'; - static readonly disableContextMenuItemKey: string = 'disableContextMenuItem'; - static readonly disableFaviconKey: string = 'disableFavicon'; - static readonly disableBadgeCounterKey: string = 'disableBadgeCounter'; - static readonly disableAutoTotpCopyKey: string = 'disableAutoTotpCopy'; - static readonly disableAutoBiometricsPromptKey: string = 'noAutoPromptBiometrics'; - static readonly enableAutoFillOnPageLoadKey: string = 'enableAutoFillOnPageLoad'; - static readonly autoFillOnPageLoadDefaultKey: string = 'autoFillOnPageLoadDefault'; - static readonly vaultTimeoutKey: string = 'lockOption'; - static readonly vaultTimeoutActionKey: string = 'vaultTimeoutAction'; - static readonly lastActiveKey: string = 'lastActive'; - static readonly neverDomainsKey: string = 'neverDomains'; - static readonly installedVersionKey: string = 'installedVersion'; - static readonly localeKey: string = 'locale'; - static readonly themeKey: string = 'theme'; - static readonly collapsedGroupingsKey: string = 'collapsedGroupings'; - static readonly autoConfirmFingerprints: string = 'autoConfirmFingerprints'; - static readonly dontShowCardsCurrentTab: string = 'dontShowCardsCurrentTab'; - static readonly dontShowIdentitiesCurrentTab: string = 'dontShowIdentitiesCurrentTab'; - static readonly defaultUriMatch: string = 'defaultUriMatch'; - static readonly pinProtectedKey: string = 'pinProtectedKey'; - static readonly protectedPin: string = 'protectedPin'; - static readonly clearClipboardKey: string = 'clearClipboardKey'; - static readonly eventCollectionKey: string = 'eventCollection'; - static readonly ssoCodeVerifierKey: string = 'ssoCodeVerifier'; - static readonly ssoStateKey: string = 'ssoState'; - static readonly biometricUnlockKey: string = 'biometric'; - static readonly biometricText: string = 'biometricText'; - static readonly biometricAwaitingAcceptance: string = 'biometricAwaitingAcceptance'; - static readonly biometricFingerprintValidated: string = 'biometricFingerprintValidated'; - - readonly environmentUrlsKey: string = ConstantsService.environmentUrlsKey; - readonly disableGaKey: string = ConstantsService.disableGaKey; - readonly disableAddLoginNotificationKey: string = ConstantsService.disableAddLoginNotificationKey; - readonly disableContextMenuItemKey: string = ConstantsService.disableContextMenuItemKey; - readonly disableFaviconKey: string = ConstantsService.disableFaviconKey; - readonly disableBadgeCounterKey: string = ConstantsService.disableBadgeCounterKey; - readonly disableAutoTotpCopyKey: string = ConstantsService.disableAutoTotpCopyKey; - readonly disableAutoBiometricsPromptKey: string = ConstantsService.disableAutoBiometricsPromptKey; - readonly enableAutoFillOnPageLoadKey: string = ConstantsService.enableAutoFillOnPageLoadKey; - readonly autoFillOnPageLoadDefaultKey: string = ConstantsService.autoFillOnPageLoadDefaultKey; - readonly vaultTimeoutKey: string = ConstantsService.vaultTimeoutKey; - readonly vaultTimeoutActionKey: string = ConstantsService.vaultTimeoutActionKey; - readonly lastActiveKey: string = ConstantsService.lastActiveKey; - readonly neverDomainsKey: string = ConstantsService.neverDomainsKey; - readonly installedVersionKey: string = ConstantsService.installedVersionKey; - readonly localeKey: string = ConstantsService.localeKey; - readonly themeKey: string = ConstantsService.themeKey; - readonly collapsedGroupingsKey: string = ConstantsService.collapsedGroupingsKey; - readonly autoConfirmFingerprints: string = ConstantsService.autoConfirmFingerprints; - readonly dontShowCardsCurrentTab: string = ConstantsService.dontShowCardsCurrentTab; - readonly dontShowIdentitiesCurrentTab: string = ConstantsService.dontShowIdentitiesCurrentTab; - readonly defaultUriMatch: string = ConstantsService.defaultUriMatch; - readonly pinProtectedKey: string = ConstantsService.pinProtectedKey; - readonly protectedPin: string = ConstantsService.protectedPin; - readonly clearClipboardKey: string = ConstantsService.clearClipboardKey; - readonly eventCollectionKey: string = ConstantsService.eventCollectionKey; - readonly ssoCodeVerifierKey: string = ConstantsService.ssoCodeVerifierKey; - readonly ssoStateKey: string = ConstantsService.ssoStateKey; - readonly biometricUnlockKey: string = ConstantsService.biometricUnlockKey; - readonly biometricText: string = ConstantsService.biometricText; - readonly biometricAwaitingAcceptance: string = ConstantsService.biometricAwaitingAcceptance; - readonly biometricFingerprintValidated: string = ConstantsService.biometricFingerprintValidated; -} diff --git a/common/src/services/user.service.ts b/common/src/services/user.service.ts deleted file mode 100644 index f031babb..00000000 --- a/common/src/services/user.service.ts +++ /dev/null @@ -1,232 +0,0 @@ -import { StorageService } from '../abstractions/storage.service'; -import { TokenService } from '../abstractions/token.service'; -import { UserService as UserServiceAbstraction } from '../abstractions/user.service'; - -import { OrganizationData } from '../models/data/organizationData'; -import { Organization } from '../models/domain/organization'; - -import { KdfType } from '../enums/kdfType'; -import { ProviderData } from '../models/data/providerData'; -import { Provider } from '../models/domain/provider'; - -const Keys = { - userId: 'userId', - userEmail: 'userEmail', - stamp: 'securityStamp', - kdf: 'kdf', - kdfIterations: 'kdfIterations', - organizationsPrefix: 'organizations_', - providersPrefix: 'providers_', - emailVerified: 'emailVerified', - forcePasswordReset: 'forcePasswordReset', -}; - -export class UserService implements UserServiceAbstraction { - private userId: string; - private email: string; - private stamp: string; - private kdf: KdfType; - private kdfIterations: number; - private emailVerified: boolean; - private forcePasswordReset: boolean; - - constructor(private tokenService: TokenService, private storageService: StorageService) { } - - async setInformation(userId: string, email: string, kdf: KdfType, kdfIterations: number): Promise { - this.email = email; - this.userId = userId; - this.kdf = kdf; - this.kdfIterations = kdfIterations; - - await this.storageService.save(Keys.userEmail, email); - await this.storageService.save(Keys.userId, userId); - await this.storageService.save(Keys.kdf, kdf); - await this.storageService.save(Keys.kdfIterations, kdfIterations); - } - - setSecurityStamp(stamp: string): Promise { - this.stamp = stamp; - return this.storageService.save(Keys.stamp, stamp); - } - - setEmailVerified(emailVerified: boolean) { - this.emailVerified = emailVerified; - return this.storageService.save(Keys.emailVerified, emailVerified); - } - - setForcePasswordReset(forcePasswordReset: boolean) { - this.forcePasswordReset = forcePasswordReset; - return this.storageService.save(Keys.forcePasswordReset, forcePasswordReset); - } - - async getUserId(): Promise { - if (this.userId == null) { - this.userId = await this.storageService.get(Keys.userId); - } - return this.userId; - } - - async getEmail(): Promise { - if (this.email == null) { - this.email = await this.storageService.get(Keys.userEmail); - } - return this.email; - } - - async getSecurityStamp(): Promise { - if (this.stamp == null) { - this.stamp = await this.storageService.get(Keys.stamp); - } - return this.stamp; - } - - async getKdf(): Promise { - if (this.kdf == null) { - this.kdf = await this.storageService.get(Keys.kdf); - } - return this.kdf; - } - - async getKdfIterations(): Promise { - if (this.kdfIterations == null) { - this.kdfIterations = await this.storageService.get(Keys.kdfIterations); - } - return this.kdfIterations; - } - - async getEmailVerified(): Promise { - if (this.emailVerified == null) { - this.emailVerified = await this.storageService.get(Keys.emailVerified); - } - return this.emailVerified; - } - - async getForcePasswordReset(): Promise { - if (this.forcePasswordReset == null) { - this.forcePasswordReset = await this.storageService.get(Keys.forcePasswordReset); - } - return this.forcePasswordReset; - } - - async clear(): Promise { - const userId = await this.getUserId(); - - await this.storageService.remove(Keys.userId); - await this.storageService.remove(Keys.userEmail); - await this.storageService.remove(Keys.stamp); - await this.storageService.remove(Keys.kdf); - await this.storageService.remove(Keys.kdfIterations); - await this.storageService.remove(Keys.forcePasswordReset); - await this.clearOrganizations(userId); - await this.clearProviders(userId); - - this.userId = this.email = this.stamp = null; - this.kdf = null; - this.kdfIterations = null; - } - - async isAuthenticated(): Promise { - const token = await this.tokenService.getToken(); - if (token == null) { - return false; - } - - const userId = await this.getUserId(); - return userId != null; - } - - async canAccessPremium(): Promise { - const authed = await this.isAuthenticated(); - if (!authed) { - return false; - } - - const tokenPremium = this.tokenService.getPremium(); - if (tokenPremium) { - return true; - } - - const orgs = await this.getAllOrganizations(); - for (let i = 0; i < orgs.length; i++) { - if (orgs[i].usersGetPremium && orgs[i].enabled) { - return true; - } - } - return false; - } - - async getOrganization(id: string): Promise { - const userId = await this.getUserId(); - const organizations = await this.storageService.get<{ [id: string]: OrganizationData; }>( - Keys.organizationsPrefix + userId); - if (organizations == null || !organizations.hasOwnProperty(id)) { - return null; - } - - return new Organization(organizations[id]); - } - - async getOrganizationByIdentifier(identifier: string): Promise { - const organizations = await this.getAllOrganizations(); - if (organizations == null || organizations.length === 0) { - return null; - } - - return organizations.find(o => o.identifier === identifier); - } - - async getAllOrganizations(): Promise { - const userId = await this.getUserId(); - const organizations = await this.storageService.get<{ [id: string]: OrganizationData; }>( - Keys.organizationsPrefix + userId); - const response: Organization[] = []; - for (const id in organizations) { - if (organizations.hasOwnProperty(id) && !organizations[id].isProviderUser) { - response.push(new Organization(organizations[id])); - } - } - return response; - } - - async replaceOrganizations(organizations: { [id: string]: OrganizationData; }): Promise { - const userId = await this.getUserId(); - await this.storageService.save(Keys.organizationsPrefix + userId, organizations); - } - - async clearOrganizations(userId: string): Promise { - await this.storageService.remove(Keys.organizationsPrefix + userId); - } - - async getProvider(id: string): Promise { - const userId = await this.getUserId(); - const providers = await this.storageService.get<{ [id: string]: ProviderData; }>( - Keys.providersPrefix + userId); - if (providers == null || !providers.hasOwnProperty(id)) { - return null; - } - - return new Provider(providers[id]); - } - - async getAllProviders(): Promise { - const userId = await this.getUserId(); - const providers = await this.storageService.get<{ [id: string]: ProviderData; }>( - Keys.providersPrefix + userId); - const response: Provider[] = []; - for (const id in providers) { - if (providers.hasOwnProperty(id)) { - response.push(new Provider(providers[id])); - } - } - return response; - } - - async replaceProviders(providers: { [id: string]: ProviderData; }): Promise { - const userId = await this.getUserId(); - await this.storageService.save(Keys.providersPrefix + userId, providers); - } - - async clearProviders(userId: string): Promise { - await this.storageService.remove(Keys.providersPrefix + userId); - } -}