1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-24030] Migrate abstract services in libs/common strict TS (#15727)

Migrates the abstract classes in libs/common to be strict ts compatible. Primarily by adding abstract to every field and converting it to a function syntax instead of lambda.
This commit is contained in:
Oscar Hinton
2025-07-22 18:48:00 +02:00
committed by GitHub
parent 6aa59d5ba7
commit 8aeeb92958
39 changed files with 595 additions and 614 deletions

View File

@@ -1,7 +1,9 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { ZXCVBNResult } from "zxcvbn";
export abstract class PasswordStrengthServiceAbstraction {
getPasswordStrength: (password: string, email?: string, userInputs?: string[]) => ZXCVBNResult;
abstract getPasswordStrength(
password: string,
email?: string,
userInputs?: string[],
): ZXCVBNResult;
}

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { ListResponse } from "../../../models/response/list.response";
import { EncArrayBuffer } from "../../../platform/models/domain/enc-array-buffer";
import { Send } from "../models/domain/send";
@@ -12,26 +10,29 @@ import { SendResponse } from "../models/response/send.response";
import { SendAccessView } from "../models/view/send-access.view";
export abstract class SendApiService {
getSend: (id: string) => Promise<SendResponse>;
postSendAccess: (
abstract getSend(id: string): Promise<SendResponse>;
abstract postSendAccess(
id: string,
request: SendAccessRequest,
apiUrl?: string,
) => Promise<SendAccessResponse>;
getSends: () => Promise<ListResponse<SendResponse>>;
postSend: (request: SendRequest) => Promise<SendResponse>;
postFileTypeSend: (request: SendRequest) => Promise<SendFileUploadDataResponse>;
postSendFile: (sendId: string, fileId: string, data: FormData) => Promise<any>;
putSend: (id: string, request: SendRequest) => Promise<SendResponse>;
putSendRemovePassword: (id: string) => Promise<SendResponse>;
deleteSend: (id: string) => Promise<any>;
getSendFileDownloadData: (
): Promise<SendAccessResponse>;
abstract getSends(): Promise<ListResponse<SendResponse>>;
abstract postSend(request: SendRequest): Promise<SendResponse>;
abstract postFileTypeSend(request: SendRequest): Promise<SendFileUploadDataResponse>;
abstract postSendFile(sendId: string, fileId: string, data: FormData): Promise<any>;
abstract putSend(id: string, request: SendRequest): Promise<SendResponse>;
abstract putSendRemovePassword(id: string): Promise<SendResponse>;
abstract deleteSend(id: string): Promise<any>;
abstract getSendFileDownloadData(
send: SendAccessView,
request: SendAccessRequest,
apiUrl?: string,
) => Promise<SendFileDownloadDataResponse>;
renewSendFileUploadUrl: (sendId: string, fileId: string) => Promise<SendFileUploadDataResponse>;
removePassword: (id: string) => Promise<any>;
delete: (id: string) => Promise<any>;
save: (sendData: [Send, EncArrayBuffer]) => Promise<Send>;
): Promise<SendFileDownloadDataResponse>;
abstract renewSendFileUploadUrl(
sendId: string,
fileId: string,
): Promise<SendFileUploadDataResponse>;
abstract removePassword(id: string): Promise<any>;
abstract delete(id: string): Promise<any>;
abstract save(sendData: [Send, EncArrayBuffer]): Promise<Send>;
}

View File

@@ -1,5 +1,3 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { Observable } from "rxjs";
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
@@ -16,49 +14,49 @@ import { SendWithIdRequest } from "../models/request/send-with-id.request";
import { SendView } from "../models/view/send.view";
export abstract class SendService implements UserKeyRotationDataProvider<SendWithIdRequest> {
sends$: Observable<Send[]>;
sendViews$: Observable<SendView[]>;
abstract sends$: Observable<Send[]>;
abstract sendViews$: Observable<SendView[]>;
encrypt: (
abstract encrypt(
model: SendView,
file: File | ArrayBuffer,
password: string,
key?: SymmetricCryptoKey,
) => Promise<[Send, EncArrayBuffer]>;
): Promise<[Send, EncArrayBuffer]>;
/**
* Provides a send for a determined id
* updates after a change occurs to the send that matches the id
* @param id The id of the desired send
* @returns An observable that listens to the value of the desired send
*/
get$: (id: string) => Observable<Send | undefined>;
abstract get$(id: string): Observable<Send | undefined>;
/**
* Provides re-encrypted user sends for the key rotation process
* @param newUserKey The new user key to use for re-encryption
* @throws Error if the new user key is null or undefined
* @returns A list of user sends that have been re-encrypted with the new user key
*/
getRotatedData: (
abstract getRotatedData(
originalUserKey: UserKey,
newUserKey: UserKey,
userId: UserId,
) => Promise<SendWithIdRequest[]>;
): Promise<SendWithIdRequest[]>;
/**
* @deprecated Do not call this, use the sends$ observable collection
*/
getAll: () => Promise<Send[]>;
abstract getAll(): Promise<Send[]>;
/**
* @deprecated Only use in CLI
*/
getFromState: (id: string) => Promise<Send>;
abstract getFromState(id: string): Promise<Send>;
/**
* @deprecated Only use in CLI
*/
getAllDecryptedFromState: (userId: UserId) => Promise<SendView[]>;
abstract getAllDecryptedFromState(userId: UserId): Promise<SendView[]>;
}
export abstract class InternalSendService extends SendService {
upsert: (send: SendData | SendData[]) => Promise<any>;
replace: (sends: { [id: string]: SendData }, userId: UserId) => Promise<void>;
delete: (id: string | string[]) => Promise<any>;
abstract upsert(send: SendData | SendData[]): Promise<any>;
abstract replace(sends: { [id: string]: SendData }, userId: UserId): Promise<void>;
abstract delete(id: string | string[]): Promise<any>;
}