Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add shared identity models to core models (#2279)
Leendert de Borst8112428a9b30
diff --git a/core/models/build.sh b/core/models/build.shindex cdd9261f5..d7ca05ba6 100755--- a/core/models/build.sh+++ b/core/models/build.sh@@ -27,7 +27,7 @@ echo "π Generating language reference (C#)..."node scripts/generate-languages.cjsdist_path="dist"-files_to_copy=("webapi" "vault" "defaults" "metadata" "icons")+files_to_copy=("webapi" "vault" "defaults" "metadata" "icons" "identity")for target in "${TARGETS[@]}"; doecho "π Copying $package_name β $target"diff --git a/core/models/src/identity/Gender.ts b/core/models/src/identity/Gender.tsnew file mode 100644index 000000000..096049817--- /dev/null+++ b/core/models/src/identity/Gender.ts@@ -0,0 +1,9 @@+/**+ * Gender values used by generated identities and alias persona fields.+ * Matches the string values produced by the Rust core identity generator.+ */+export enum Gender {+ Male = 'Male',+ Female = 'Female',+ Other = 'Other'+}diff --git a/core/models/src/identity/Identity.ts b/core/models/src/identity/Identity.tsnew file mode 100644index 000000000..da26b267c--- /dev/null+++ b/core/models/src/identity/Identity.ts@@ -0,0 +1,16 @@+import type { Gender } from './Gender';++/**+ * A generated identity as returned by the Rust core identity generator+ * (JSON with camelCase fields).+ */+export type Identity = {+ firstName: string;+ lastName: string;+ gender: Gender | string;+ /** Birth date in yyyy-MM-dd format. */+ birthDate: string;+ emailPrefix: string;+ /** Username derived from the name and birth year (alphanumeric only). */+ nickName: string;+};diff --git a/core/models/src/identity/IdentityHelperUtils.ts b/core/models/src/identity/IdentityHelperUtils.tsnew file mode 100644index 000000000..295d9bbc1--- /dev/null+++ b/core/models/src/identity/IdentityHelperUtils.ts@@ -0,0 +1,62 @@+/**+ * Helper utilities for working with identity birth dates in the client UIs.+ */+export class IdentityHelperUtils {+ /**+ * Normalize a birth date to the standard format: "yyyy-MM-dd".+ * Handles various input formats including ISO strings with time components.+ * Returns empty string for invalid/empty dates.+ */+ public static normalizeBirthDate(input: string | undefined): string {+ if (!input || input.trim() === '' || input.startsWith('0001-01-01')) {+ return '';+ }++ const trimmed = input.trim();++ /*+ * Check if the format is a valid ISO-like string manually, to support pre-1970 dates.+ * Matches: yyyy-MM-dd, yyyy-MM-ddTHH:mm:ss, yyyy-MM-dd HH:mm:ss, yyyy-MM-dd HH:mm:ss.SSS, etc.+ */+ const match = trimmed.match(/^(\d{4})-(\d{2})-(\d{2})/);+ if (match) {+ const [, y, m, d] = match;+ return `${y}-${m}-${d}`;+ }++ // Fall back to native Date parsing only if regex match fails+ const parsedDate = new Date(trimmed);+ if (!isNaN(parsedDate.getTime())) {+ const year = parsedDate.getFullYear().toString().padStart(4, '0');+ const month = (parsedDate.getMonth() + 1).toString().padStart(2, '0');+ const day = parsedDate.getDate().toString().padStart(2, '0');+ return `${year}-${month}-${day}`;+ }++ return '';+ }++ /**+ * Check if a birth date is valid.+ */+ public static isValidBirthDate(input: string | undefined): boolean {+ if (!input || input.trim() === '') {+ return false;+ }++ if (input.startsWith('0001-01-01')) {+ return false;+ }++ const date = new Date(input);++ // Check if the date is valid+ if (isNaN(date.getTime())) {+ return false;+ }++ // Check if the year is valid+ const yearValid = date.getFullYear() > 1 && date.getFullYear() < 9999;+ return yearValid;+ }+}diff --git a/core/models/src/identity/index.ts b/core/models/src/identity/index.tsnew file mode 100644index 000000000..36e233b4e--- /dev/null+++ b/core/models/src/identity/index.ts@@ -0,0 +1,3 @@+export { Gender } from './Gender';+export type { Identity } from './Identity';+export { IdentityHelperUtils } from './IdentityHelperUtils';