Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add capabilities to models (#2159)
Leendert de Borst7db87975ac62
diff --git a/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts b/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.tsindex 38a72444b..1d21b6927 100644--- a/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts+++ b/apps/browser-extension/src/utils/dist/core/models/webapi/index.d.ts@@ -82,9 +82,9 @@ type StatusResponseV2 = {clientVersionSupported: boolean;serverVersion: string;manifestRevisions: ManifestRevision[];- /** The manifest owned by the user's personal group; every other entry is a shared one. */personalManifestId: string | null;srpSalt: string;+ capabilities?: Record<string, string>;};/**@@ -635,4 +635,31 @@ type CreateGroupInvitationResponse = {invitationId: string;};-export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type CreateGroupInvitationRequest, type CreateGroupInvitationResponse, type CreateSharedManifestRequest, type CreateSharedManifestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type EmailDecryptionKey, type FaviconExtractModel, type GrantRecipient, type GroupInfo, type GroupInvitationRecipientRequest, type GroupInvitationRecipientResponse, type GroupMemberInfo, type GroupOverviewResponse, type GroupRole, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type ManifestGrant, ManifestKeyType, type ManifestKeyTypeValue, type ManifestRevision, type MobileLoginInitiateRequest, type MobileLoginInitiateResponse, type MobileLoginPollResponse, type MobileLoginSubmitRequest, type PasswordChangeInitiateResponse, type ReceivedGroupInvitation, type RefreshToken, type SentGroupInvitation, type StatusResponse, type StatusResponseV2, type TokenModel, UnlockMethodType, type UnlockMethodTypeValue, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, VaultKeyAlgorithm, type VaultKeyAlgorithmValue, type VaultKeyGetResponse, type VaultKeyResponse, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };+/**+ * The capability keys the server resolves and hands to clients on the status response.+ *+ * A key travels between the server and every client and is stored in rule rows, so renaming one means a+ * coordinated release across the API, the extension, the mobile app and the web client: name the capability,+ * never the screen or the marketing name it currently ships under.+ *+ * Mirrored on the server side in AliasVault.Shared.Server/Capabilities/CapabilityKeys.cs.+ */+declare const CapabilityKeys: {+ /**+ * Shared vaults: creating one, inviting people to it, and accepting an invitation to one. The capability+ * behind the Family Sharing screens, and behind anything else built on a vault more than one account holds.+ */+ readonly VaultSharing: "vault-sharing";+};+/**+ * A capability key known to this build.+ */+type CapabilityKey = typeof CapabilityKeys[keyof typeof CapabilityKeys];+/**+ * Whether a resolved value means the capability is on. Anything that is not "true" is off, so a value this build+ * does not understand fails closed rather than exposing a capability.+ * @param value - the value the server resolved, or undefined when it did not mention the key at all.+ */+declare function isCapabilityEnabled(value: string | undefined): boolean;++export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type CapabilityKey, CapabilityKeys, type CreateGroupInvitationRequest, type CreateGroupInvitationResponse, type CreateSharedManifestRequest, type CreateSharedManifestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type EmailDecryptionKey, type FaviconExtractModel, type GrantRecipient, type GroupInfo, type GroupInvitationRecipientRequest, type GroupInvitationRecipientResponse, type GroupMemberInfo, type GroupOverviewResponse, type GroupRole, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type ManifestGrant, ManifestKeyType, type ManifestKeyTypeValue, type ManifestRevision, type MobileLoginInitiateRequest, type MobileLoginInitiateResponse, type MobileLoginPollResponse, type MobileLoginSubmitRequest, type PasswordChangeInitiateResponse, type ReceivedGroupInvitation, type RefreshToken, type SentGroupInvitation, type StatusResponse, type StatusResponseV2, type TokenModel, UnlockMethodType, type UnlockMethodTypeValue, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, VaultKeyAlgorithm, type VaultKeyAlgorithmValue, type VaultKeyGetResponse, type VaultKeyResponse, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse, isCapabilityEnabled };diff --git a/apps/browser-extension/src/utils/dist/core/models/webapi/index.js b/apps/browser-extension/src/utils/dist/core/models/webapi/index.jsindex 5860e5256..a9f38eb42 100644--- a/apps/browser-extension/src/utils/dist/core/models/webapi/index.js+++ b/apps/browser-extension/src/utils/dist/core/models/webapi/index.js@@ -50,4 +50,16 @@ var VaultKeyAlgorithm = {RsaOaepSha256: "rsa-oaep-sha256"};-export { AuthEventType, ManifestKeyType, UnlockMethodType, VaultKeyAlgorithm };+// src/webapi/CapabilityKeys.ts+var CapabilityKeys = {+ /**+ * Shared vaults: creating one, inviting people to it, and accepting an invitation to one. The capability+ * behind the Family Sharing screens, and behind anything else built on a vault more than one account holds.+ */+ VaultSharing: "vault-sharing"+};+function isCapabilityEnabled(value) {+ return value?.toLowerCase() === "true";+}++export { AuthEventType, CapabilityKeys, ManifestKeyType, UnlockMethodType, VaultKeyAlgorithm, isCapabilityEnabled };diff --git a/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts b/apps/mobile-app/utils/dist/core/models/webapi/index.d.tsindex 38a72444b..1d21b6927 100644--- a/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts+++ b/apps/mobile-app/utils/dist/core/models/webapi/index.d.ts@@ -82,9 +82,9 @@ type StatusResponseV2 = {clientVersionSupported: boolean;serverVersion: string;manifestRevisions: ManifestRevision[];- /** The manifest owned by the user's personal group; every other entry is a shared one. */personalManifestId: string | null;srpSalt: string;+ capabilities?: Record<string, string>;};/**@@ -635,4 +635,31 @@ type CreateGroupInvitationResponse = {invitationId: string;};-export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type CreateGroupInvitationRequest, type CreateGroupInvitationResponse, type CreateSharedManifestRequest, type CreateSharedManifestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type EmailDecryptionKey, type FaviconExtractModel, type GrantRecipient, type GroupInfo, type GroupInvitationRecipientRequest, type GroupInvitationRecipientResponse, type GroupMemberInfo, type GroupOverviewResponse, type GroupRole, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type ManifestGrant, ManifestKeyType, type ManifestKeyTypeValue, type ManifestRevision, type MobileLoginInitiateRequest, type MobileLoginInitiateResponse, type MobileLoginPollResponse, type MobileLoginSubmitRequest, type PasswordChangeInitiateResponse, type ReceivedGroupInvitation, type RefreshToken, type SentGroupInvitation, type StatusResponse, type StatusResponseV2, type TokenModel, UnlockMethodType, type UnlockMethodTypeValue, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, VaultKeyAlgorithm, type VaultKeyAlgorithmValue, type VaultKeyGetResponse, type VaultKeyResponse, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse };+/**+ * The capability keys the server resolves and hands to clients on the status response.+ *+ * A key travels between the server and every client and is stored in rule rows, so renaming one means a+ * coordinated release across the API, the extension, the mobile app and the web client: name the capability,+ * never the screen or the marketing name it currently ships under.+ *+ * Mirrored on the server side in AliasVault.Shared.Server/Capabilities/CapabilityKeys.cs.+ */+declare const CapabilityKeys: {+ /**+ * Shared vaults: creating one, inviting people to it, and accepting an invitation to one. The capability+ * behind the Family Sharing screens, and behind anything else built on a vault more than one account holds.+ */+ readonly VaultSharing: "vault-sharing";+};+/**+ * A capability key known to this build.+ */+type CapabilityKey = typeof CapabilityKeys[keyof typeof CapabilityKeys];+/**+ * Whether a resolved value means the capability is on. Anything that is not "true" is off, so a value this build+ * does not understand fails closed rather than exposing a capability.+ * @param value - the value the server resolved, or undefined when it did not mention the key at all.+ */+declare function isCapabilityEnabled(value: string | undefined): boolean;++export { type ApiErrorResponse, AuthEventType, type AuthLogModel, type BadRequestResponse, type CapabilityKey, CapabilityKeys, type CreateGroupInvitationRequest, type CreateGroupInvitationResponse, type CreateSharedManifestRequest, type CreateSharedManifestResponse, type DeleteAccountInitiateRequest, type DeleteAccountInitiateResponse, type DeleteAccountRequest, type Email, type EmailAttachment, type EmailDecryptionKey, type FaviconExtractModel, type GrantRecipient, type GroupInfo, type GroupInvitationRecipientRequest, type GroupInvitationRecipientResponse, type GroupMemberInfo, type GroupOverviewResponse, type GroupRole, type LoginRequest, type LoginResponse, type MailboxBulkRequest, type MailboxBulkResponse, type MailboxEmail, type ManifestGrant, ManifestKeyType, type ManifestKeyTypeValue, type ManifestRevision, type MobileLoginInitiateRequest, type MobileLoginInitiateResponse, type MobileLoginPollResponse, type MobileLoginSubmitRequest, type PasswordChangeInitiateResponse, type ReceivedGroupInvitation, type RefreshToken, type SentGroupInvitation, type StatusResponse, type StatusResponseV2, type TokenModel, UnlockMethodType, type UnlockMethodTypeValue, type ValidateLoginRequest, type ValidateLoginRequest2Fa, type ValidateLoginResponse, type Vault, VaultKeyAlgorithm, type VaultKeyAlgorithmValue, type VaultKeyGetResponse, type VaultKeyResponse, type VaultPasswordChangeRequest, type VaultPostResponse, type VaultResponse, isCapabilityEnabled };diff --git a/apps/mobile-app/utils/dist/core/models/webapi/index.js b/apps/mobile-app/utils/dist/core/models/webapi/index.jsindex 5860e5256..a9f38eb42 100644--- a/apps/mobile-app/utils/dist/core/models/webapi/index.js+++ b/apps/mobile-app/utils/dist/core/models/webapi/index.js@@ -50,4 +50,16 @@ var VaultKeyAlgorithm = {RsaOaepSha256: "rsa-oaep-sha256"};-export { AuthEventType, ManifestKeyType, UnlockMethodType, VaultKeyAlgorithm };+// src/webapi/CapabilityKeys.ts+var CapabilityKeys = {+ /**+ * Shared vaults: creating one, inviting people to it, and accepting an invitation to one. The capability+ * behind the Family Sharing screens, and behind anything else built on a vault more than one account holds.+ */+ VaultSharing: "vault-sharing"+};+function isCapabilityEnabled(value) {+ return value?.toLowerCase() === "true";+}++export { AuthEventType, CapabilityKeys, ManifestKeyType, UnlockMethodType, VaultKeyAlgorithm, isCapabilityEnabled };diff --git a/apps/server/AliasVault.Api/Services/CapabilityService.cs b/apps/server/AliasVault.Api/Services/CapabilityService.csindex 17468fc62..998d86560 100644--- a/apps/server/AliasVault.Api/Services/CapabilityService.cs+++ b/apps/server/AliasVault.Api/Services/CapabilityService.cs@@ -27,16 +27,23 @@ public class CapabilityService(IAliasServerDbContextFactory dbContextFactory, IMprivate const string EnabledRulesCacheKey = "CapabilityRules_Enabled";/// <summary>- /// Resolves the caller's capabilities, every one this build knows about, on or off.+ /// Resolves the capabilities to hand the caller. Ones that resolve to off are left out./// </summary>/// <param name="userId">The calling account.</param>/// <param name="clientHeader">The raw client header the call arrived with, used by client-scoped rules.</param>- /// <returns>Every known capability key and its resolved value.</returns>+ /// <returns>The capability keys that resolved to something other than off, with their values.</returns>public async Task<Dictionary<string, string>> GetCapabilitiesAsync(string userId, string? clientHeader){var rules = await GetEnabledRulesAsync();var subject = await BuildSubjectAsync(userId, clientHeader, rules);- return CapabilityResolver.ResolveAll(rules, subject, timeProvider.UtcNow);+ var resolved = CapabilityResolver.ResolveAll(rules, subject, timeProvider.UtcNow);++ /*+ * Filter on the off value itself rather than on IsEnabled: values are strings so one can carry a cap or a+ * variant name, and those are not "true" but do still need to reach the client.+ */+ var enabled = resolved.Where(x => !string.Equals(x.Value, CapabilityValue.Off, StringComparison.OrdinalIgnoreCase));+ return enabled.ToDictionary(x => x.Key, x => x.Value, StringComparer.Ordinal);}/// <summary>diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Status/StatusResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Status/StatusResponse.csindex 1276c6d25..4361538b4 100644--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Status/StatusResponse.cs+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Status/StatusResponse.cs@@ -50,8 +50,7 @@ public class StatusResponsepublic List<BucketRevision> BucketRevisions { get; set; } = [];/// <summary>- /// Gets or sets what this caller may do, keyed by capability. Includes the ones that are off, so an absent key- /// means only that this server does not know the capability.+ /// Gets or sets what this caller may do, keyed by capability./// </summary>public Dictionary<string, string> Capabilities { get; set; } = [];diff --git a/core/models/src/webapi/CapabilityKeys.ts b/core/models/src/webapi/CapabilityKeys.tsnew file mode 100644index 000000000..74b03224f--- /dev/null+++ b/core/models/src/webapi/CapabilityKeys.ts@@ -0,0 +1,26 @@+/**+ * The capability keys the server resolves and hands to clients on the status response.+ *+ * Mirrored on the server side in AliasVault.Shared.Server/Capabilities/CapabilityKeys.cs.+ */+export const CapabilityKeys = {+ /**+ * Shared vaults: creating one, inviting people to it, and accepting an invitation to one. The capability+ * behind the Family Sharing screens, and behind anything else built on a vault more than one account holds.+ */+ VaultSharing: 'vault-sharing',+} as const;++/**+ * A capability key known to this build.+ */+export type CapabilityKey = typeof CapabilityKeys[keyof typeof CapabilityKeys];++/**+ * Whether a resolved value means the capability is on. Anything that is not "true" is off, so a value this build+ * does not understand fails closed rather than exposing a capability.+ * @param value - the value the server resolved, or undefined when it did not mention the key at all.+ */+export function isCapabilityEnabled(value: string | undefined): boolean {+ return value?.toLowerCase() === 'true';+}diff --git a/core/models/src/webapi/StatusResponseV2.ts b/core/models/src/webapi/StatusResponseV2.tsindex c6266c5e3..a8b7220b9 100644--- a/core/models/src/webapi/StatusResponseV2.ts+++ b/core/models/src/webapi/StatusResponseV2.ts@@ -13,7 +13,7 @@ export type StatusResponseV2 = {clientVersionSupported: boolean;serverVersion: string;manifestRevisions: ManifestRevision[];- /** The manifest owned by the user's personal group; every other entry is a shared one. */personalManifestId: string | null;srpSalt: string;+ capabilities?: Record<string, string>;}diff --git a/core/models/src/webapi/index.ts b/core/models/src/webapi/index.tsindex 3fb395efa..e5cff2842 100644--- a/core/models/src/webapi/index.ts+++ b/core/models/src/webapi/index.ts@@ -29,3 +29,4 @@ export * from './UnlockMethodType';export * from './ManifestKeyType';export * from './VaultKeyAlgorithm';export * from './Groups';+export * from './CapabilityKeys';