Skip to content

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

Add item render type models (#1404)

Leendert de Borsta3db88ee42e8
diff --git a/apps/browser-extension/src/utils/dist/shared/models/vault/index.d.ts b/apps/browser-extension/src/utils/dist/shared/models/vault/index.d.ts
index 54689e5f2..98ed50608 100644
--- a/apps/browser-extension/src/utils/dist/shared/models/vault/index.d.ts
+++ b/apps/browser-extension/src/utils/dist/shared/models/vault/index.d.ts
@@ -321,4 +321,80 @@ type ItemTag = {
IsDeleted: number;
};
-export { type Alias, type Attachment, type Credential, type EncryptionKey, FieldKey, type FieldKeyValue, type ItemTag, type Passkey, type PasswordSettings, type Tag, type TotpCode };
+/**
+ * Item types supported by the vault
+ */
+type ItemType = 'Login' | 'CreditCard' | 'Identity' | 'Note';
+/**
+ * Item type representing vault entries in the new field-based data model.
+ * Replaces the old Credential type.
+ */
+type Item = {
+ Id: string;
+ Name: string | null;
+ ItemType: ItemType;
+ Logo?: Uint8Array | number[];
+ FolderId?: string | null;
+ FolderPath?: string | null;
+ Tags?: ItemTagRef[];
+ Fields: ItemField[];
+ HasPasskey?: boolean;
+ HasAttachment?: boolean;
+ HasTotp?: boolean;
+ CreatedAt: string;
+ UpdatedAt: string;
+};
+/**
+ * Field value within an item
+ */
+type ItemField = {
+ FieldKey: string;
+ Label: string;
+ FieldType: FieldType;
+ Value: string | string[];
+ IsHidden: boolean;
+ DisplayOrder: number;
+};
+/**
+ * Field types for rendering and validation
+ */
+type FieldType = 'Text' | 'Password' | 'Email' | 'URL' | 'Date' | 'Number' | 'Phone' | 'TextArea';
+/**
+ * Tag reference for display within an item
+ */
+type ItemTagRef = {
+ Id: string;
+ Name: string;
+ Color?: string;
+};
+
+/**
+ * Helper functions for working with Item model
+ */
+/**
+ * Get a single field value by FieldKey
+ */
+declare function getFieldValue(item: Item, fieldKey: string): string | undefined;
+/**
+ * Get all values for a multi-value field
+ */
+declare function getFieldValues(item: Item, fieldKey: string): string[];
+/**
+ * Check if a field exists and has a value
+ */
+declare function hasField(item: Item, fieldKey: string): boolean;
+/**
+ * Group fields by a categorization function
+ */
+declare function groupFields(item: Item, grouper: (field: ItemField) => string): Record<string, ItemField[]>;
+/**
+ * Group fields by standard categories (Login, Alias, Custom)
+ */
+declare function groupFieldsByCategory(item: Item): Record<string, ItemField[]>;
+/**
+ * Convert new Item model to legacy Credential model for backward compatibility.
+ * @deprecated Use Item model directly. This is a temporary compatibility layer.
+ */
+declare function itemToCredential(item: Item): Credential;
+
+export { type Alias, type Attachment, type Credential, type EncryptionKey, FieldKey, type FieldKeyValue, type FieldType, type Item, type ItemField, type ItemTag, type ItemTagRef, type ItemType, type Passkey, type PasswordSettings, type Tag, type TotpCode, getFieldValue, getFieldValues, groupFields, groupFieldsByCategory, hasField, itemToCredential };
diff --git a/apps/browser-extension/src/utils/dist/shared/models/vault/index.js b/apps/browser-extension/src/utils/dist/shared/models/vault/index.js
index bfd93ec24..6a864a01a 100644
--- a/apps/browser-extension/src/utils/dist/shared/models/vault/index.js
+++ b/apps/browser-extension/src/utils/dist/shared/models/vault/index.js
@@ -151,6 +151,78 @@ var FieldKey = {
AliasBirthdate: "alias.birthdate"
};
-export { FieldKey };
+// src/vault/ItemMethods.ts
+function getFieldValue(item, fieldKey) {
+ const field = item.Fields.find((f) => f.FieldKey === fieldKey);
+ if (!field) {
+ return void 0;
+ }
+ return Array.isArray(field.Value) ? field.Value[0] : field.Value;
+}
+function getFieldValues(item, fieldKey) {
+ const field = item.Fields.find((f) => f.FieldKey === fieldKey);
+ if (!field) {
+ return [];
+ }
+ return Array.isArray(field.Value) ? field.Value : [field.Value];
+}
+function hasField(item, fieldKey) {
+ const value = getFieldValue(item, fieldKey);
+ return value !== void 0 && value !== "";
+}
+function groupFields(item, grouper) {
+ const groups = {};
+ item.Fields.forEach((field) => {
+ const group = grouper(field);
+ if (!groups[group]) {
+ groups[group] = [];
+ }
+ groups[group].push(field);
+ });
+ return groups;
+}
+function groupFieldsByCategory(item) {
+ return groupFields(item, (field) => {
+ if (field.FieldKey.startsWith("login.")) {
+ return "Login";
+ }
+ if (field.FieldKey.startsWith("alias.")) {
+ return "Alias";
+ }
+ if (field.FieldKey.startsWith("card.")) {
+ return "Card";
+ }
+ if (field.FieldKey.startsWith("identity.")) {
+ return "Identity";
+ }
+ if (field.FieldKey.startsWith("api.")) {
+ return "API";
+ }
+ return "Custom";
+ });
+}
+function itemToCredential(item) {
+ return {
+ Id: item.Id,
+ Username: getFieldValue(item, FieldKey.LoginUsername),
+ Password: getFieldValue(item, FieldKey.LoginPassword) || "",
+ ServiceName: item.Name || "",
+ ServiceUrl: getFieldValue(item, FieldKey.LoginUrl),
+ Logo: item.Logo,
+ Notes: getFieldValue(item, FieldKey.LoginNotes),
+ Alias: {
+ FirstName: getFieldValue(item, FieldKey.AliasFirstName),
+ LastName: getFieldValue(item, FieldKey.AliasLastName),
+ NickName: getFieldValue(item, FieldKey.AliasNickname),
+ BirthDate: getFieldValue(item, FieldKey.AliasBirthdate) || "",
+ Gender: getFieldValue(item, FieldKey.AliasGender),
+ Email: getFieldValue(item, FieldKey.AliasEmail)
+ },
+ HasPasskey: item.HasPasskey,
+ HasAttachment: item.HasAttachment
+ };
+}
+
+export { FieldKey, getFieldValue, getFieldValues, groupFields, groupFieldsByCategory, hasField, itemToCredential };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts b/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts
index 54689e5f2..98ed50608 100644
--- a/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts
+++ b/apps/mobile-app/utils/dist/shared/models/vault/index.d.ts
@@ -321,4 +321,80 @@ type ItemTag = {
IsDeleted: number;
};
-export { type Alias, type Attachment, type Credential, type EncryptionKey, FieldKey, type FieldKeyValue, type ItemTag, type Passkey, type PasswordSettings, type Tag, type TotpCode };
+/**
+ * Item types supported by the vault
+ */
+type ItemType = 'Login' | 'CreditCard' | 'Identity' | 'Note';
+/**
+ * Item type representing vault entries in the new field-based data model.
+ * Replaces the old Credential type.
+ */
+type Item = {
+ Id: string;
+ Name: string | null;
+ ItemType: ItemType;
+ Logo?: Uint8Array | number[];
+ FolderId?: string | null;
+ FolderPath?: string | null;
+ Tags?: ItemTagRef[];
+ Fields: ItemField[];
+ HasPasskey?: boolean;
+ HasAttachment?: boolean;
+ HasTotp?: boolean;
+ CreatedAt: string;
+ UpdatedAt: string;
+};
+/**
+ * Field value within an item
+ */
+type ItemField = {
+ FieldKey: string;
+ Label: string;
+ FieldType: FieldType;
+ Value: string | string[];
+ IsHidden: boolean;
+ DisplayOrder: number;
+};
+/**
+ * Field types for rendering and validation
+ */
+type FieldType = 'Text' | 'Password' | 'Email' | 'URL' | 'Date' | 'Number' | 'Phone' | 'TextArea';
+/**
+ * Tag reference for display within an item
+ */
+type ItemTagRef = {
+ Id: string;
+ Name: string;
+ Color?: string;
+};
+
+/**
+ * Helper functions for working with Item model
+ */
+/**
+ * Get a single field value by FieldKey
+ */
+declare function getFieldValue(item: Item, fieldKey: string): string | undefined;
+/**
+ * Get all values for a multi-value field
+ */
+declare function getFieldValues(item: Item, fieldKey: string): string[];
+/**
+ * Check if a field exists and has a value
+ */
+declare function hasField(item: Item, fieldKey: string): boolean;
+/**
+ * Group fields by a categorization function
+ */
+declare function groupFields(item: Item, grouper: (field: ItemField) => string): Record<string, ItemField[]>;
+/**
+ * Group fields by standard categories (Login, Alias, Custom)
+ */
+declare function groupFieldsByCategory(item: Item): Record<string, ItemField[]>;
+/**
+ * Convert new Item model to legacy Credential model for backward compatibility.
+ * @deprecated Use Item model directly. This is a temporary compatibility layer.
+ */
+declare function itemToCredential(item: Item): Credential;
+
+export { type Alias, type Attachment, type Credential, type EncryptionKey, FieldKey, type FieldKeyValue, type FieldType, type Item, type ItemField, type ItemTag, type ItemTagRef, type ItemType, type Passkey, type PasswordSettings, type Tag, type TotpCode, getFieldValue, getFieldValues, groupFields, groupFieldsByCategory, hasField, itemToCredential };
diff --git a/apps/mobile-app/utils/dist/shared/models/vault/index.js b/apps/mobile-app/utils/dist/shared/models/vault/index.js
index bfd93ec24..6a864a01a 100644
--- a/apps/mobile-app/utils/dist/shared/models/vault/index.js
+++ b/apps/mobile-app/utils/dist/shared/models/vault/index.js
@@ -151,6 +151,78 @@ var FieldKey = {
AliasBirthdate: "alias.birthdate"
};
-export { FieldKey };
+// src/vault/ItemMethods.ts
+function getFieldValue(item, fieldKey) {
+ const field = item.Fields.find((f) => f.FieldKey === fieldKey);
+ if (!field) {
+ return void 0;
+ }
+ return Array.isArray(field.Value) ? field.Value[0] : field.Value;
+}
+function getFieldValues(item, fieldKey) {
+ const field = item.Fields.find((f) => f.FieldKey === fieldKey);
+ if (!field) {
+ return [];
+ }
+ return Array.isArray(field.Value) ? field.Value : [field.Value];
+}
+function hasField(item, fieldKey) {
+ const value = getFieldValue(item, fieldKey);
+ return value !== void 0 && value !== "";
+}
+function groupFields(item, grouper) {
+ const groups = {};
+ item.Fields.forEach((field) => {
+ const group = grouper(field);
+ if (!groups[group]) {
+ groups[group] = [];
+ }
+ groups[group].push(field);
+ });
+ return groups;
+}
+function groupFieldsByCategory(item) {
+ return groupFields(item, (field) => {
+ if (field.FieldKey.startsWith("login.")) {
+ return "Login";
+ }
+ if (field.FieldKey.startsWith("alias.")) {
+ return "Alias";
+ }
+ if (field.FieldKey.startsWith("card.")) {
+ return "Card";
+ }
+ if (field.FieldKey.startsWith("identity.")) {
+ return "Identity";
+ }
+ if (field.FieldKey.startsWith("api.")) {
+ return "API";
+ }
+ return "Custom";
+ });
+}
+function itemToCredential(item) {
+ return {
+ Id: item.Id,
+ Username: getFieldValue(item, FieldKey.LoginUsername),
+ Password: getFieldValue(item, FieldKey.LoginPassword) || "",
+ ServiceName: item.Name || "",
+ ServiceUrl: getFieldValue(item, FieldKey.LoginUrl),
+ Logo: item.Logo,
+ Notes: getFieldValue(item, FieldKey.LoginNotes),
+ Alias: {
+ FirstName: getFieldValue(item, FieldKey.AliasFirstName),
+ LastName: getFieldValue(item, FieldKey.AliasLastName),
+ NickName: getFieldValue(item, FieldKey.AliasNickname),
+ BirthDate: getFieldValue(item, FieldKey.AliasBirthdate) || "",
+ Gender: getFieldValue(item, FieldKey.AliasGender),
+ Email: getFieldValue(item, FieldKey.AliasEmail)
+ },
+ HasPasskey: item.HasPasskey,
+ HasAttachment: item.HasAttachment
+ };
+}
+
+export { FieldKey, getFieldValue, getFieldValues, groupFields, groupFieldsByCategory, hasField, itemToCredential };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
\ No newline at end of file
diff --git a/shared/models/src/vault/CredentialCompat.ts b/shared/models/src/vault/CredentialCompat.ts
new file mode 100644
index 000000000..3f6a131ca
--- /dev/null
+++ b/shared/models/src/vault/CredentialCompat.ts
@@ -0,0 +1,5 @@
+/**
+ * @deprecated This file is deprecated. Use ItemMethods.ts instead.
+ * Kept for backward compatibility during migration.
+ */
+export { itemToCredential } from './ItemMethods';
diff --git a/shared/models/src/vault/Item.ts b/shared/models/src/vault/Item.ts
new file mode 100644
index 000000000..0f9b95095
--- /dev/null
+++ b/shared/models/src/vault/Item.ts
@@ -0,0 +1,62 @@
+/**
+ * Item types supported by the vault
+ */
+export type ItemType =
+ | 'Login'
+ | 'CreditCard'
+ | 'Identity'
+ | 'Note';
+
+/**
+ * Item type representing vault entries in the new field-based data model.
+ * Replaces the old Credential type.
+ */
+export type Item = {
+ Id: string;
+ Name: string | null;
+ ItemType: ItemType;
+ Logo?: Uint8Array | number[];
+ FolderId?: string | null;
+ FolderPath?: string | null;
+ Tags?: ItemTagRef[];
+ Fields: ItemField[];
+ HasPasskey?: boolean;
+ HasAttachment?: boolean;
+ HasTotp?: boolean;
+ CreatedAt: string;
+ UpdatedAt: string;
+}
+
+/**
+ * Field value within an item
+ */
+export type ItemField = {
+ FieldKey: string;
+ Label: string;
+ FieldType: FieldType;
+ Value: string | string[];
+ IsHidden: boolean;
+ DisplayOrder: number;
+}
+
+/**
+ * Field types for rendering and validation
+ */
+export type FieldType =
+ | 'Text'
+ | 'Password'
+ | 'Email'
+ | 'URL'
+ | 'Date'
+ | 'Number'
+ | 'Phone'
+ | 'TextArea';
+
+/**
+ * Tag reference for display within an item
+ */
+export type ItemTagRef = {
+ Id: string;
+ Name: string;
+ Color?: string;
+}
diff --git a/shared/models/src/vault/ItemMethods.ts b/shared/models/src/vault/ItemMethods.ts
new file mode 100644
index 000000000..103219c4a
--- /dev/null
+++ b/shared/models/src/vault/ItemMethods.ts
@@ -0,0 +1,107 @@
+import type { Item, ItemField } from './Item';
+import type { Credential } from './Credential';
+import { FieldKey } from './FieldKey';
+
+/**
+ * Helper functions for working with Item model
+ */
+
+/**
+ * Get a single field value by FieldKey
+ */
+export function getFieldValue(item: Item, fieldKey: string): string | undefined {
+ const field = item.Fields.find(f => f.FieldKey === fieldKey);
+ if (!field) {
+ return undefined;
+ }
+ return Array.isArray(field.Value) ? field.Value[0] : field.Value;
+}
+
+/**
+ * Get all values for a multi-value field
+ */
+export function getFieldValues(item: Item, fieldKey: string): string[] {
+ const field = item.Fields.find(f => f.FieldKey === fieldKey);
+ if (!field) {
+ return [];
+ }
+ return Array.isArray(field.Value) ? field.Value : [field.Value];
+}
+
+/**
+ * Check if a field exists and has a value
+ */
+export function hasField(item: Item, fieldKey: string): boolean {
+ const value = getFieldValue(item, fieldKey);
+ return value !== undefined && value !== '';
+}
+
+/**
+ * Group fields by a categorization function
+ */
+export function groupFields(
+ item: Item,
+ grouper: (field: ItemField) => string
+): Record<string, ItemField[]> {
+ const groups: Record<string, ItemField[]> = {};
+
+ item.Fields.forEach(field => {
+ const group = grouper(field);
+ if (!groups[group]) {
+ groups[group] = [];
+ }
+ groups[group].push(field);
+ });
+
+ return groups;
+}
+
+/**
+ * Group fields by standard categories (Login, Alias, Custom)
+ */
+export function groupFieldsByCategory(item: Item): Record<string, ItemField[]> {
+ return groupFields(item, (field) => {
+ if (field.FieldKey.startsWith('login.')) {
+ return 'Login';
+ }
+ if (field.FieldKey.startsWith('alias.')) {
+ return 'Alias';
+ }
+ if (field.FieldKey.startsWith('card.')) {
+ return 'Card';
+ }
+ if (field.FieldKey.startsWith('identity.')) {
+ return 'Identity';
+ }
+ if (field.FieldKey.startsWith('api.')) {
+ return 'API';
+ }
+ return 'Custom';
+ });
+}
+
+/**
+ * Convert new Item model to legacy Credential model for backward compatibility.
+ * @deprecated Use Item model directly. This is a temporary compatibility layer.
+ */
+export function itemToCredential(item: Item): Credential {
+ return {
+ Id: item.Id,
+ Username: getFieldValue(item, FieldKey.LoginUsername),
+ Password: getFieldValue(item, FieldKey.LoginPassword) || '',
+ ServiceName: item.Name || '',
+ ServiceUrl: getFieldValue(item, FieldKey.LoginUrl),
+ Logo: item.Logo,
+ Notes: getFieldValue(item, FieldKey.LoginNotes),
+ Alias: {
+ FirstName: getFieldValue(item, FieldKey.AliasFirstName),
+ LastName: getFieldValue(item, FieldKey.AliasLastName),
+ NickName: getFieldValue(item, FieldKey.AliasNickname),
+ BirthDate: getFieldValue(item, FieldKey.AliasBirthdate) || '',
+ Gender: getFieldValue(item, FieldKey.AliasGender),
+ Email: getFieldValue(item, FieldKey.AliasEmail)
+ },
+ HasPasskey: item.HasPasskey,
+ HasAttachment: item.HasAttachment
+ };
+}
diff --git a/shared/models/src/vault/index.ts b/shared/models/src/vault/index.ts
index 8d439690e..796c2e152 100644
--- a/shared/models/src/vault/index.ts
+++ b/shared/models/src/vault/index.ts
@@ -10,3 +10,6 @@ export * from './Passkey';
export * from './FieldKey';
export * from './Tag';
export * from './ItemTag';
+export * from './Item';
+export * from './CredentialCompat';
+export * from './ItemMethods';