Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add email error response parsing to browser extension and mobile app (#900)

Leendert de Borstf9987b5e2ab9
diff --git a/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx b/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx
index 894ed57a4..f6484bc46 100644
--- a/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx
+++ b/apps/browser-extension/src/entrypoints/popup/components/EmailPreview.tsx
@@ -5,7 +5,7 @@ import { useDb } from '@/entrypoints/popup/context/DbContext';
import { useWebApi } from '@/entrypoints/popup/context/WebApiContext';
import { AppInfo } from '@/utils/AppInfo';
-import type { MailboxEmail } from '@/utils/dist/shared/models/webapi';
+import type { ApiErrorResponse, MailboxEmail } from '@/utils/dist/shared/models/webapi';
import { EncryptionUtility } from '@/utils/EncryptionUtility';
import { storage } from '#imports';
@@ -22,6 +22,7 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {
const [loading, setLoading] = useState(true);
const [lastEmailId, setLastEmailId] = useState<number>(0);
const [isSpamOk, setIsSpamOk] = useState(false);
+ const [error, setError] = useState<string | null>(null);
const webApi = useWebApi();
const dbContext = useDb();
@@ -40,6 +41,7 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {
*/
const loadEmails = async (): Promise<void> => {
try {
+ setError(null);
const isPublic = await isPublicDomain(email);
setIsSpamOk(isPublic);
@@ -52,6 +54,12 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {
'X-Asdasd-Platform-Version': AppInfo.VERSION,
}
});
+
+ if (!response.ok) {
+ setError('An error occurred while loading emails. Please try again later.');
+ return;
+ }
+
const data = await response.json();
// Only show the latest 2 emails to save space in UI
@@ -67,30 +75,55 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {
setEmails(latestMails);
} else {
// For private domains, use existing encrypted email logic
- const response = await webApi.get(`EmailBox/${email}`);
- const data = response as { mails: MailboxEmail[] };
-
- // Only show the latest 2 emails to save space in UI
- const latestMails = data.mails
- .toSorted((a, b) => new Date(b.dateSystem).getTime() - new Date(a.dateSystem).getTime())
- .slice(0, 2);
-
- if (latestMails) {
- // Loop through all emails and decrypt them locally
- const decryptedEmails: MailboxEmail[] = await EncryptionUtility.decryptEmailList(
- latestMails,
- dbContext.sqliteClient!.getAllEncryptionKeys()
- );
-
- if (loading && decryptedEmails.length > 0) {
- setLastEmailId(decryptedEmails[0].id);
+ try {
+ /**
+ * We use authFetch here because we don't want to the inner method to throw an error if HTTP status is not 200.
+ * Instead we want to catch the error ourselves.
+ */
+ const response = await webApi.authFetch(`EmailBox/${email}`, { method: 'GET' }, true, false);
+ try {
+ const data = response as { mails: MailboxEmail[] };
+
+ // Only show the latest 2 emails to save space in UI
+ const latestMails = data.mails
+ .toSorted((a, b) => new Date(b.dateSystem).getTime() - new Date(a.dateSystem).getTime())
+ .slice(0, 2);
+
+ if (latestMails) {
+ // Loop through all emails and decrypt them locally
+ const decryptedEmails: MailboxEmail[] = await EncryptionUtility.decryptEmailList(
+ latestMails,
+ dbContext.sqliteClient!.getAllEncryptionKeys()
+ );
+
+ if (loading && decryptedEmails.length > 0) {
+ setLastEmailId(decryptedEmails[0].id);
+ }
+
+ setEmails(decryptedEmails);
+ }
+ } catch {
+ // Try to parse as error response instead
+ const apiErrorResponse = response as ApiErrorResponse;
+
+ if (apiErrorResponse?.code === 'CLAIM_DOES_NOT_MATCH_USER') {
+ setError('The current chosen email address is already in use. Please change the email address by editing this credential.');
+ } else if (apiErrorResponse?.code === 'CLAIM_DOES_NOT_EXIST') {
+ setError('An error occurred while trying to load the emails. Please try to edit and save the credential entry to synchronize the database, then try again.');
+ } else {
+ setError('An error occurred while loading emails. Please try again later.');
+ }
+
+ return;
}
-
- setEmails(decryptedEmails);
+ } catch {
+ setError('An error occurred while loading emails. Please try again later.');
+ return;
}
}
} catch (err) {
console.error('Error loading emails:', err);
+ setError('An unexpected error occurred while loading emails. Please try again later.');
}
setLoading(false);
};
@@ -101,6 +134,19 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) => {
return () : void => clearInterval(interval);
}, [email, loading, webApi, dbContext]);
+ if (error) {
+ return (
+ <div className="text-gray-500 dark:text-gray-400 mb-4">
+ <div className="flex items-center gap-2 mb-2">
+ <h2 className="text-xl font-semibold text-gray-900 dark:text-white">Recent emails</h2>
+ </div>
+ <div className="p-3 bg-red-50 dark:bg-red-900/30 border border-red-200 dark:border-red-800 rounded">
+ <p className="text-sm text-red-600 dark:text-red-400">{error}</p>
+ </div>
+ </div>
+ );
+ }
+
if (loading) {
return (
<div className="text-gray-500 dark:text-gray-400 mb-4">
diff --git a/apps/browser-extension/src/utils/WebApiService.ts b/apps/browser-extension/src/utils/WebApiService.ts
index aa0ae0dfe..95b191336 100644
--- a/apps/browser-extension/src/utils/WebApiService.ts
+++ b/apps/browser-extension/src/utils/WebApiService.ts
@@ -43,7 +43,8 @@ export class WebApiService {
public async authFetch<T>(
endpoint: string,
options: RequestInit = {},
- parseJson: boolean = true
+ parseJson: boolean = true,
+ throwOnError: boolean = true
): Promise<T> {
const headers = new Headers(options.headers ?? {});
@@ -81,7 +82,7 @@ export class WebApiService {
}
}
- if (!response.ok) {
+ if (!response.ok && throwOnError) {
throw new Error(`HTTP error! status: ${response.status}`);
}
diff --git a/apps/browser-extension/src/utils/dist/shared/models/webapi/index.d.ts b/apps/browser-extension/src/utils/dist/shared/models/webapi/index.d.ts
index 53dd0e958..4e5f860e2 100644
--- a/apps/browser-extension/src/utils/dist/shared/models/webapi/index.d.ts
+++ b/apps/browser-extension/src/utils/dist/shared/models/webapi/index.d.ts
@@ -1,3 +1,29 @@
+/**
+ * Represents the error response returned by the API.
+ */
+type ApiErrorResponse = {
+ /**
+ * The main error message.
+ */
+ message: string;
+ /**
+ * The error code associated with this error.
+ */
+ code: string;
+ /**
+ * Additional details about the error.
+ */
+ details: Record<string, unknown>;
+ /**
+ * The HTTP status code associated with this error.
+ */
+ statusCode: number;
+ /**
+ * The timestamp when the error occurred.
+ */
+ timestamp: string;
+};
+
/**
* Vault type.
*/
@@ -353,4 +379,4 @@ declare enum AuthEventType {
AccountDeletion = 99
}
-export { AuthEventType, type AuthLogModel, type BadRequestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type FaviconExtractModel, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type PasswordChangeInitiateResponse, type RefreshToken, type StatusResponse, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };
+export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type FaviconExtractModel, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type PasswordChangeInitiateResponse, type RefreshToken, type StatusResponse, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };
diff --git a/apps/mobile-app/components/credentials/details/EmailPreview.tsx b/apps/mobile-app/components/credentials/details/EmailPreview.tsx
index 61a95889b..b7167f188 100644
--- a/apps/mobile-app/components/credentials/details/EmailPreview.tsx
+++ b/apps/mobile-app/components/credentials/details/EmailPreview.tsx
@@ -4,7 +4,7 @@ import React, { useState, useEffect, useCallback } from 'react';
import { View, StyleSheet, TouchableOpacity, Linking, AppState } from 'react-native';
import { AppInfo } from '@/utils/AppInfo';
-import type { MailboxBulkRequest, MailboxBulkResponse, MailboxEmail } from '@/utils/dist/shared/models/webapi';
+import type { ApiErrorResponse, MailboxEmail } from '@/utils/dist/shared/models/webapi';
import EncryptionUtility from '@/utils/EncryptionUtility';
import { useColors } from '@/hooks/useColorScheme';
@@ -29,6 +29,7 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) : React.Rea
const [lastEmailId, setLastEmailId] = useState<number>(0);
const [isSpamOk, setIsSpamOk] = useState(false);
const [isComponentVisible, setIsComponentVisible] = useState(true);
+ const [error, setError] = useState<string | null>(null);
const webApi = useWebApi();
const dbContext = useDb();
const authContext = useAuth();
@@ -96,6 +97,12 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) : React.Rea
'X-Asdasd-Platform-Version': AppInfo.VERSION,
}
});
+
+ if (!response.ok) {
+ setError('An error occurred while loading emails. Please try again later.');
+ return;
+ }
+
const data = await response.json();
// Only show the latest 2 emails to save space in UI
@@ -115,41 +122,59 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) : React.Rea
return;
}
- // Get all encryption keys
- const encryptionKeys = await dbContext.sqliteClient.getAllEncryptionKeys();
+ try {
+ // Get all encryption keys
+ const encryptionKeys = await dbContext.sqliteClient.getAllEncryptionKeys();
- // Only fetch emails for the provided email address
- const data = await webApi.post<MailboxBulkRequest, MailboxBulkResponse>('EmailBox/bulk', {
- addresses: [email],
- page: 1,
- pageSize: 2,
- });
+ // Use single emailbox operator instead of bulk
+ const response = await webApi.authFetch(`EmailBox/${email}`, { method: 'GET' }, true, false);
+ try {
+ const data = response as { mails: MailboxEmail[] };
- // For each email, find its matching encryption key based on the public key
- const decryptedEmails = await Promise.all(data.mails.map(async (mail) => {
- const matchingKey = encryptionKeys.find(key => key.PublicKey === mail.encryptionKey);
- if (!matchingKey) {
- console.error('No encryption key found for email:', mail.id);
- return null;
- }
- return await EncryptionUtility.decryptEmailList([mail], [matchingKey]);
- }));
+ // Only show the latest 2 emails to save space in UI
+ const latestMails = data.mails
+ .sort((a, b) => new Date(b.dateSystem).getTime() - new Date(a.dateSystem).getTime())
+ .slice(0, 2);
- // Filter out any null results and set the emails
- const validEmails = decryptedEmails
- .filter((result): result is MailboxEmail[] => result !== null)
- .flat();
+ if (latestMails) {
+ // Loop through all emails and decrypt them locally
+ const decryptedEmails = await EncryptionUtility.decryptEmailList(
+ latestMails,
+ encryptionKeys
+ );
- if (loading && validEmails.length > 0) {
- setLastEmailId(validEmails[0].id);
- }
+ if (loading && decryptedEmails.length > 0) {
+ setLastEmailId(decryptedEmails[0].id);
+ }
- setEmails(validEmails);
+ setEmails(decryptedEmails);
+
+ // Reset error
+ setError(null);
+ }
+ } catch {
+ // Try to parse as error response instead
+ const apiErrorResponse = response as ApiErrorResponse;
+
+ if (apiErrorResponse?.code === 'CLAIM_DOES_NOT_MATCH_USER') {
+ setError('The current chosen email address is already in use. Please change the email address by editing this credential.');
+ } else if (apiErrorResponse?.code === 'CLAIM_DOES_NOT_EXIST') {
+ setError('An error occurred while trying to load the emails. Please try to edit and save the credential entry to synchronize the database, then try again.');
+ } else {
+ setError('An error occurred while loading emails. Please try again later.');
+ }
+ return;
+ }
+ } catch {
+ setError('An error occurred while loading emails. Please try again later.');
+ return;
+ } finally {
+ setLoading(false);
+ }
}
} catch (err) {
console.error('Error loading emails:', err);
- } finally {
- setLoading(false);
+ setError('An unexpected error occurred while loading emails. Please try again later.');
}
};
@@ -178,6 +203,18 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) : React.Rea
marginTop: 8,
padding: 12,
},
+ errorContainer: {
+ backgroundColor: colors.errorBackground,
+ borderColor: colors.errorBorder,
+ borderRadius: 8,
+ borderWidth: 1,
+ marginTop: 8,
+ padding: 12,
+ },
+ errorText: {
+ color: colors.errorText,
+ fontSize: 14,
+ },
placeholderText: {
color: colors.textMuted,
marginBottom: 8,
@@ -207,6 +244,19 @@ export const EmailPreview: React.FC<EmailPreviewProps> = ({ email }) : React.Rea
return null;
}
+ if (error) {
+ return (
+ <ThemedView style={styles.section}>
+ <View style={styles.titleContainer}>
+ <ThemedText type="title" style={styles.title}>Recent emails</ThemedText>
+ </View>
+ <View style={styles.errorContainer}>
+ <ThemedText style={styles.errorText}>{error}</ThemedText>
+ </View>
+ </ThemedView>
+ );
+ }
+
if (loading) {
return (
<ThemedView style={styles.section}>
diff --git a/apps/mobile-app/utils/WebApiService.ts b/apps/mobile-app/utils/WebApiService.ts
index c7950e81b..25ef6b8c6 100644
--- a/apps/mobile-app/utils/WebApiService.ts
+++ b/apps/mobile-app/utils/WebApiService.ts
@@ -42,7 +42,8 @@ export class WebApiService {
public async authFetch<T>(
endpoint: string,
options: RequestInit = {},
- parseJson: boolean = true
+ parseJson: boolean = true,
+ throwOnError: boolean = true
): Promise<T> {
const headers = new Headers(options.headers ?? {});
@@ -80,7 +81,7 @@ export class WebApiService {
}
}
- if (!response.ok) {
+ if (!response.ok && throwOnError) {
throw new Error(`HTTP error! status: ${response.status}`);
}
@@ -314,6 +315,25 @@ export class WebApiService {
return null;
}
+ /**
+ * Validates the status response and returns an error message if validation fails.
+ */
+ public validateStatusResponse(statusResponse: StatusResponse): string | null {
+ if (statusResponse.serverVersion === '0.0.0') {
+ return 'The AliasVault server is not available. Please try again later or contact support if the problem persists.';
+ }
+
+ if (!statusResponse.clientVersionSupported) {
+ return 'This version of the AliasVault mobile app is not supported by the server anymore. Please update your app to the latest version.';
+ }
+
+ if (!AppInfo.isServerVersionSupported(statusResponse.serverVersion)) {
+ return 'The AliasVault server needs to be updated to a newer version in order to use this mobile app. Please contact support if you need help.';
+ }
+
+ return null;
+ }
+
/**
* Get the current access token from storage.
*/
diff --git a/apps/mobile-app/utils/dist/shared/identity-generator/index.d.ts b/apps/mobile-app/utils/dist/shared/identity-generator/index.d.ts
index c15c50d9f..0bfea65ed 100644
--- a/apps/mobile-app/utils/dist/shared/identity-generator/index.d.ts
+++ b/apps/mobile-app/utils/dist/shared/identity-generator/index.d.ts
@@ -24,14 +24,14 @@ interface IIdentityGenerator {
* Base identity generator.
*/
declare abstract class IdentityGenerator implements IIdentityGenerator {
- protected firstNamesMale: string[];
- protected firstNamesFemale: string[];
- protected lastNames: string[];
- private readonly random;
- /**
- * Constructor.
- */
- constructor();
+ protected firstNamesMale: string[];
+ protected firstNamesFemale: string[];
+ protected lastNames: string[];
+ private readonly random;
+ /**
+ * Constructor.
+ */
+ constructor();
protected abstract getFirstNamesMaleJson(): string[];
protected abstract getFirstNamesFemaleJson(): string[];
protected abstract getLastNamesJson(): string[];
@@ -49,87 +49,87 @@ declare abstract class IdentityGenerator implements IIdentityGenerator {
* Identity generator for English language using English word dictionaries.
*/
declare class IdentityGeneratorEn extends IdentityGenerator {
- /**
- * Get the male first names.
- */
- protected getFirstNamesMaleJson(): string[];
- /**
- * Get the female first names.
- */
- protected getFirstNamesFemaleJson(): string[];
- /**
- * Get the last names.
- */
- protected getLastNamesJson(): string[];
+ /**
+ * Get the male first names.
+ */
+ protected getFirstNamesMaleJson(): string[];
+ /**
+ * Get the female first names.
+ */
+ protected getFirstNamesFemaleJson(): string[];
+ /**
+ * Get the last names.
+ */
+ protected getLastNamesJson(): string[];
}
/**
* Identity generator for Dutch language using Dutch word dictionaries.
*/
declare class IdentityGeneratorNl extends IdentityGenerator {
- /**
- * Get the male first names.
- */
- protected getFirstNamesMaleJson(): string[];
- /**
- * Get the female first names.
- */
- protected getFirstNamesFemaleJson(): string[];
- /**
- * Get the last names.
- */
- protected getLastNamesJson(): string[];
+ /**
+ * Get the male first names.
+ */
+ protected getFirstNamesMaleJson(): string[];
+ /**
+ * Get the female first names.
+ */
+ protected getFirstNamesFemaleJson(): string[];
+ /**
+ * Get the last names.
+ */
+ protected getLastNamesJson(): string[];
}
/**
* Helper utilities for identity generation that can be used by multiple client applications.
*/
declare class IdentityHelperUtils {
- /**
- * Normalize a birth date for display.
- */
- static normalizeBirthDateForDisplay(birthDate: string | undefined): string;
- /**
- * Normalize a birth date for database.
- */
- static normalizeBirthDateForDb(input: string | undefined): string;
- /**
- * Check if a birth date is valid.
- */
- static isValidBirthDate(input: string | undefined): boolean;
+ /**
+ * Normalize a birth date for display.
+ */
+ static normalizeBirthDateForDisplay(birthDate: string | undefined): string;
+ /**
+ * Normalize a birth date for database.
+ */
+ static normalizeBirthDateForDb(input: string | undefined): string;
+ /**
+ * Check if a birth date is valid.
+ */
+ static isValidBirthDate(input: string | undefined): boolean;
}
/**
* Generate a username or email prefix.
*/
declare class UsernameEmailGenerator {
- private static readonly MIN_LENGTH;
- private static readonly MAX_LENGTH;
- private readonly symbols;
- /**
- * Generate a username based on an identity.
- */
- generateUsername(identity: Identity): string;
- /**
- * Generate an email prefix based on an identity.
- */
- generateEmailPrefix(identity: Identity): string;
- /**
- * Sanitize an email prefix.
- */
- private sanitizeEmailPrefix;
- /**
- * Get a random symbol.
- */
- private getRandomSymbol;
- /**
- * Generate a random string.
- */
- private generateRandomString;
- /**
- * Generate a secure random integer between 0 (inclusive) and max (exclusive)
- */
- private getSecureRandom;
+ private static readonly MIN_LENGTH;
+ private static readonly MAX_LENGTH;
+ private readonly symbols;
+ /**
+ * Generate a username based on an identity.
+ */
+ generateUsername(identity: Identity): string;
+ /**
+ * Generate an email prefix based on an identity.
+ */
+ generateEmailPrefix(identity: Identity): string;
+ /**
+ * Sanitize an email prefix.
+ */
+ private sanitizeEmailPrefix;
+ /**
+ * Get a random symbol.
+ */
+ private getRandomSymbol;
+ /**
+ * Generate a random string.
+ */
+ private generateRandomString;
+ /**
+ * Generate a secure random integer between 0 (inclusive) and max (exclusive)
+ */
+ private getSecureRandom;
}
/**
diff --git a/apps/mobile-app/utils/dist/shared/models/webapi/index.d.ts b/apps/mobile-app/utils/dist/shared/models/webapi/index.d.ts
index 53dd0e958..4e5f860e2 100644
--- a/apps/mobile-app/utils/dist/shared/models/webapi/index.d.ts
+++ b/apps/mobile-app/utils/dist/shared/models/webapi/index.d.ts
@@ -1,3 +1,29 @@
+/**
+ * Represents the error response returned by the API.
+ */
+type ApiErrorResponse = {
+ /**
+ * The main error message.
+ */
+ message: string;
+ /**
+ * The error code associated with this error.
+ */
+ code: string;
+ /**
+ * Additional details about the error.
+ */
+ details: Record<string, unknown>;
+ /**
+ * The HTTP status code associated with this error.
+ */
+ statusCode: number;
+ /**
+ * The timestamp when the error occurred.
+ */
+ timestamp: string;
+};
+
/**
* Vault type.
*/
@@ -353,4 +379,4 @@ declare enum AuthEventType {
AccountDeletion = 99
}
-export { AuthEventType, type AuthLogModel, type BadRequestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type FaviconExtractModel, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type PasswordChangeInitiateResponse, type RefreshToken, type StatusResponse, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };
+export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type FaviconExtractModel, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type PasswordChangeInitiateResponse, type RefreshToken, type StatusResponse, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };
diff --git a/apps/mobile-app/utils/dist/shared/password-generator/index.d.ts b/apps/mobile-app/utils/dist/shared/password-generator/index.d.ts
index 9ccceba69..723e4f172 100644
--- a/apps/mobile-app/utils/dist/shared/password-generator/index.d.ts
+++ b/apps/mobile-app/utils/dist/shared/password-generator/index.d.ts
@@ -32,82 +32,82 @@ type PasswordSettings = {
* Generate a random password.
*/
declare class PasswordGenerator {
- private readonly lowercaseChars;
- private readonly uppercaseChars;
- private readonly numberChars;
- private readonly specialChars;
- private readonly ambiguousChars;
- private length;
- private useLowercase;
- private useUppercase;
- private useNumbers;
- private useSpecial;
- private useNonAmbiguous;
- /**
- * Create a new instance of PasswordGenerator.
- * @param settings Optional password settings to initialize with.
- */
- constructor(settings?: PasswordSettings);
- /**
- * Apply password settings to this generator.
- */
- applySettings(settings: PasswordSettings): this;
- /**
- * Set the length of the password.
- */
- setLength(length: number): this;
- /**
- * Set if lowercase letters should be used.
- */
- useLowercaseLetters(use: boolean): this;
- /**
- * Set if uppercase letters should be used.
- */
- useUppercaseLetters(use: boolean): this;
- /**
- * Set if numeric characters should be used.
- */
- useNumericCharacters(use: boolean): this;
- /**
- * Set if special characters should be used.
- */
- useSpecialCharacters(use: boolean): this;
- /**
- * Set if only non-ambiguous characters should be used.
- */
- useNonAmbiguousCharacters(use: boolean): this;
- /**
- * Get a random index from the crypto module.
- */
- private getUnbiasedRandomIndex;
- /**
- * Generate a random password.
- */
- generateRandomPassword(): string;
- /**
- * Build character set based on selected options.
- */
- private buildCharacterSet;
- /**
- * Remove ambiguous characters from a character set.
- */
- private removeAmbiguousCharacters;
- /**
- * Generate initial random password.
- */
- private generateInitialPassword;
- /**
- * Ensure the generated password meets all specified requirements.
- */
- private ensureRequirements;
- /**
- * Get a character set with ambiguous characters removed if needed.
- */
- private getSafeCharacterSet;
- /**
- * Add a character from the given set at a random position in the password.
- */
- private addCharacterFromSet;
+ private readonly lowercaseChars;
+ private readonly uppercaseChars;
+ private readonly numberChars;
+ private readonly specialChars;
+ private readonly ambiguousChars;
+ private length;
+ private useLowercase;
+ private useUppercase;
+ private useNumbers;
+ private useSpecial;
+ private useNonAmbiguous;
+ /**
+ * Create a new instance of PasswordGenerator.
+ * @param settings Optional password settings to initialize with.
+ */
+ constructor(settings?: PasswordSettings);
+ /**
+ * Apply password settings to this generator.
+ */
+ applySettings(settings: PasswordSettings): this;
+ /**
+ * Set the length of the password.
+ */
+ setLength(length: number): this;
+ /**
+ * Set if lowercase letters should be used.
+ */
+ useLowercaseLetters(use: boolean): this;
+ /**
+ * Set if uppercase letters should be used.
+ */
+ useUppercaseLetters(use: boolean): this;
+ /**
+ * Set if numeric characters should be used.
+ */
+ useNumericCharacters(use: boolean): this;
+ /**
+ * Set if special characters should be used.
+ */
+ useSpecialCharacters(use: boolean): this;
+ /**
+ * Set if only non-ambiguous characters should be used.
+ */
+ useNonAmbiguousCharacters(use: boolean): this;
+ /**
+ * Get a random index from the crypto module.
+ */
+ private getUnbiasedRandomIndex;
+ /**
+ * Generate a random password.
+ */
+ generateRandomPassword(): string;
+ /**
+ * Build character set based on selected options.
+ */
+ private buildCharacterSet;
+ /**
+ * Remove ambiguous characters from a character set.
+ */
+ private removeAmbiguousCharacters;
+ /**
+ * Generate initial random password.
+ */
+ private generateInitialPassword;
+ /**
+ * Ensure the generated password meets all specified requirements.
+ */
+ private ensureRequirements;
+ /**
+ * Get a character set with ambiguous characters removed if needed.
+ */
+ private getSafeCharacterSet;
+ /**
+ * Add a character from the given set at a random position in the password.
+ */
+ private addCharacterFromSet;
}
/**
diff --git a/shared/models/src/webapi/ApiErrorResponse.ts b/shared/models/src/webapi/ApiErrorResponse.ts
new file mode 100644
index 000000000..d8300a959
--- /dev/null
+++ b/shared/models/src/webapi/ApiErrorResponse.ts
@@ -0,0 +1,29 @@
+/**
+ * Represents the error response returned by the API.
+ */
+export type ApiErrorResponse = {
+ /**
+ * The main error message.
+ */
+ message: string;
+
+ /**
+ * The error code associated with this error.
+ */
+ code: string;
+
+ /**
+ * Additional details about the error.
+ */
+ details: Record<string, unknown>;
+
+ /**
+ * The HTTP status code associated with this error.
+ */
+ statusCode: number;
+
+ /**
+ * The timestamp when the error occurred.
+ */
+ timestamp: string; // Using string for ISO date format
+};
diff --git a/shared/models/src/webapi/index.ts b/shared/models/src/webapi/index.ts
index b604649e9..75c1c8832 100644
--- a/shared/models/src/webapi/index.ts
+++ b/shared/models/src/webapi/index.ts
@@ -1,6 +1,7 @@
/**
* Export all web API models that are returned by the web API.
*/
+export * from './ApiErrorResponse';
export * from './VaultResponse';
export * from './Vault';
export * from './VaultPostResponse';