mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 15:53:27 +00:00
* Use typescript-strict-plugin to iteratively turn on strict * Add strict testing to pipeline Can be executed locally through either `npm run test:types` for full type checking including spec files, or `npx tsc-strict` for only tsconfig.json included files. * turn on strict for scripts directory * Use plugin for all tsconfigs in monorepo vscode is capable of executing tsc with plugins, but uses the most relevant tsconfig to do so. If the plugin is not a part of that config, it is skipped and developers get no feedback of strict compile time issues. These updates remedy that at the cost of slightly more complex removal of the plugin when the time comes. * remove plugin from configs that extend one that already has it * Update workspace settings to honor strict plugin * Apply strict-plugin to native message test runner * Update vscode workspace to use root tsc version * `./node_modules/.bin/update-strict-comments` 🤖 This is a one-time operation. All future files should adhere to strict type checking. * Add fixme to `ts-strict-ignore` comments * `update-strict-comments` 🤖 repeated for new merge files
83 lines
2.7 KiB
TypeScript
83 lines
2.7 KiB
TypeScript
// FIXME: Update this file to be type safe and remove this and next line
|
|
// @ts-strict-ignore
|
|
import { AuthenticationType } from "@bitwarden/common/auth/enums/authentication-type";
|
|
import { KeyDefinition, LOGIN_STRATEGY_MEMORY } from "@bitwarden/common/platform/state";
|
|
|
|
import { AuthRequestLoginStrategyData } from "../../login-strategies/auth-request-login.strategy";
|
|
import { PasswordLoginStrategyData } from "../../login-strategies/password-login.strategy";
|
|
import { SsoLoginStrategyData } from "../../login-strategies/sso-login.strategy";
|
|
import { UserApiLoginStrategyData } from "../../login-strategies/user-api-login.strategy";
|
|
import { WebAuthnLoginStrategyData } from "../../login-strategies/webauthn-login.strategy";
|
|
|
|
/**
|
|
* The current login strategy in use.
|
|
*/
|
|
export const CURRENT_LOGIN_STRATEGY_KEY = new KeyDefinition<AuthenticationType | null>(
|
|
LOGIN_STRATEGY_MEMORY,
|
|
"currentLoginStrategy",
|
|
{
|
|
deserializer: (data) => data,
|
|
},
|
|
);
|
|
|
|
/**
|
|
* The expiration date for the login strategy cache.
|
|
* Used as a backup to the timer set on the service.
|
|
*/
|
|
export const CACHE_EXPIRATION_KEY = new KeyDefinition<Date | null>(
|
|
LOGIN_STRATEGY_MEMORY,
|
|
"loginStrategyCacheExpiration",
|
|
{
|
|
deserializer: (data) => (data ? null : new Date(data)),
|
|
},
|
|
);
|
|
|
|
/**
|
|
* Auth Request notification for all instances of the login strategy service.
|
|
* Note: this isn't an ideal approach, but allows both a background and
|
|
* foreground instance to send out the notification.
|
|
* TODO: Move to Auth Request service.
|
|
*/
|
|
export const AUTH_REQUEST_PUSH_NOTIFICATION_KEY = new KeyDefinition<string | null>(
|
|
LOGIN_STRATEGY_MEMORY,
|
|
"authRequestPushNotification",
|
|
{
|
|
deserializer: (data) => data,
|
|
},
|
|
);
|
|
|
|
export type CacheData = {
|
|
password?: PasswordLoginStrategyData;
|
|
sso?: SsoLoginStrategyData;
|
|
userApiKey?: UserApiLoginStrategyData;
|
|
authRequest?: AuthRequestLoginStrategyData;
|
|
webAuthn?: WebAuthnLoginStrategyData;
|
|
};
|
|
|
|
/**
|
|
* A cache for login strategies to use for data persistence through
|
|
* the login process.
|
|
*/
|
|
export const CACHE_KEY = new KeyDefinition<CacheData | null>(
|
|
LOGIN_STRATEGY_MEMORY,
|
|
"loginStrategyCache",
|
|
{
|
|
deserializer: (data) => {
|
|
if (data == null) {
|
|
return null;
|
|
}
|
|
return {
|
|
password: data.password ? PasswordLoginStrategyData.fromJSON(data.password) : undefined,
|
|
sso: data.sso ? SsoLoginStrategyData.fromJSON(data.sso) : undefined,
|
|
userApiKey: data.userApiKey
|
|
? UserApiLoginStrategyData.fromJSON(data.userApiKey)
|
|
: undefined,
|
|
authRequest: data.authRequest
|
|
? AuthRequestLoginStrategyData.fromJSON(data.authRequest)
|
|
: undefined,
|
|
webAuthn: data.webAuthn ? WebAuthnLoginStrategyData.fromJSON(data.webAuthn) : undefined,
|
|
};
|
|
},
|
|
},
|
|
);
|