From e172faaaf2471f4f4bff65b60c99278368609be2 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Fri, 22 Aug 2025 10:39:13 +0000 Subject: [PATCH] fix: correct active identity fallback logic for phase c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix fallback condition to use DROP_SETTINGS_ACTIVEDID flag - Update code formatting and import organization - Add missing Active Identity façade method declarations - Ensure proper TypeScript interface coverage This fixes the fallback logic that was incorrectly checking USE_ACTIVE_IDENTITY_ONLY instead of DROP_SETTINGS_ACTIVEDID, preventing proper Phase C behavior. --- src/utils/PlatformServiceMixin.ts | 83 +++++++++++++++++++------------ 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index 99d1046d..ccf56e63 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -49,10 +49,7 @@ import { type Settings, type SettingsWithJsonStrings, } from "@/db/tables/settings"; -import { - DEFAULT_SCOPE, - type ActiveIdentity -} from "@/db/tables/activeIdentity"; +import { DEFAULT_SCOPE, type ActiveIdentity } from "@/db/tables/activeIdentity"; import { FLAGS } from "@/config/featureFlags"; import { logger } from "@/utils/logger"; import { Contact, ContactMaybeWithJsonStrings } from "@/db/tables/contacts"; @@ -976,7 +973,7 @@ export const PlatformServiceMixin = { /** * Get the current active DID from the active_identity table * Falls back to legacy settings.activeDid during Phase A transition - * + * * @param scope Scope identifier (default: 'default') * @returns Promise The active DID or null if not found */ @@ -984,30 +981,30 @@ export const PlatformServiceMixin = { try { // Try new active_identity table first const row = await this.$first( - 'SELECT active_did FROM active_identity WHERE scope = ? LIMIT 1', - [scope] + "SELECT active_did FROM active_identity WHERE scope = ? LIMIT 1", + [scope], ); - + if (row?.active_did) { return row.active_did; } - // Fallback to legacy settings.activeDid during Phase A (unless flag prevents it) - if (!FLAGS.USE_ACTIVE_IDENTITY_ONLY) { + // Fallback to legacy settings.activeDid during Phase A/B (unless Phase C is complete) + if (!FLAGS.DROP_SETTINGS_ACTIVEDID) { if (FLAGS.LOG_ACTIVE_ID_FALLBACK) { - logger.warn('[ActiveDid] Fallback to legacy settings.activeDid'); + logger.warn("[ActiveDid] Fallback to legacy settings.activeDid"); } - + const legacy = await this.$first( - 'SELECT activeDid FROM settings WHERE id = ? LIMIT 1', - [MASTER_SETTINGS_KEY] + "SELECT activeDid FROM settings WHERE id = ? LIMIT 1", + [MASTER_SETTINGS_KEY], ); return legacy?.activeDid || null; } return null; } catch (error) { - logger.error('[PlatformServiceMixin] Error getting activeDid:', error); + logger.error("[PlatformServiceMixin] Error getting activeDid:", error); return null; } }, @@ -1015,32 +1012,37 @@ export const PlatformServiceMixin = { /** * Update the active DID in the active_identity table * Also maintains legacy settings.activeDid during Phase A transition - * + * * @param did The DID to set as active (or null to clear) * @param scope Scope identifier (default: 'default') * @returns Promise */ - async $setActiveDid(did: string | null, scope: string = DEFAULT_SCOPE): Promise { + async $setActiveDid( + did: string | null, + scope: string = DEFAULT_SCOPE, + ): Promise { try { if (!did) { - throw new Error('Cannot set null DID as active'); + throw new Error("Cannot set null DID as active"); } // Validate that the DID exists in accounts table const accountExists = await this.$first( - 'SELECT did FROM accounts WHERE did = ? LIMIT 1', - [did] + "SELECT did FROM accounts WHERE did = ? LIMIT 1", + [did], ); if (!accountExists) { - throw new Error(`Cannot set activeDid to non-existent account: ${did}`); + throw new Error( + `Cannot set activeDid to non-existent account: ${did}`, + ); } await this.$withTransaction(async () => { // Update/insert into active_identity table const existingRecord = await this.$first( - 'SELECT id FROM active_identity WHERE scope = ? LIMIT 1', - [scope] + "SELECT id FROM active_identity WHERE scope = ? LIMIT 1", + [scope], ); if (existingRecord) { @@ -1049,22 +1051,22 @@ export const PlatformServiceMixin = { `UPDATE active_identity SET active_did = ?, updated_at = strftime('%Y-%m-%dT%H:%M:%fZ','now') WHERE scope = ?`, - [did, scope] + [did, scope], ); } else { // Insert new record await this.$dbExec( `INSERT INTO active_identity (scope, active_did, updated_at) VALUES (?, ?, strftime('%Y-%m-%dT%H:%M:%fZ','now'))`, - [scope, did] + [scope, did], ); } // Maintain legacy settings.activeDid during Phase A (unless Phase C is complete) if (!FLAGS.DROP_SETTINGS_ACTIVEDID) { await this.$dbExec( - 'UPDATE settings SET activeDid = ? WHERE id = ?', - [did, MASTER_SETTINGS_KEY] + "UPDATE settings SET activeDid = ? WHERE id = ?", + [did, MASTER_SETTINGS_KEY], ); } }); @@ -1074,7 +1076,7 @@ export const PlatformServiceMixin = { logger.info(`[PlatformServiceMixin] Active DID updated to: ${did}`); } catch (error) { - logger.error('[PlatformServiceMixin] Error setting activeDid:', error); + logger.error("[PlatformServiceMixin] Error setting activeDid:", error); throw error; } }, @@ -1082,7 +1084,7 @@ export const PlatformServiceMixin = { /** * Switch to a different active identity * Convenience method that validates and sets the new active DID - * + * * @param did The DID to switch to * @returns Promise */ @@ -1093,17 +1095,20 @@ export const PlatformServiceMixin = { /** * Get all available active identity scopes * Useful for multi-profile support in the future - * + * * @returns Promise Array of scope identifiers */ async $getActiveIdentityScopes(): Promise { try { const scopes = await this.$query<{ scope: string }>( - 'SELECT DISTINCT scope FROM active_identity ORDER BY scope' + "SELECT DISTINCT scope FROM active_identity ORDER BY scope", ); - return scopes.map(row => row.scope); + return scopes.map((row) => row.scope); } catch (error) { - logger.error('[PlatformServiceMixin] Error getting active identity scopes:', error); + logger.error( + "[PlatformServiceMixin] Error getting active identity scopes:", + error, + ); return []; } }, @@ -1852,6 +1857,12 @@ export interface IPlatformServiceMixin { // Debug methods $debugDidSettings(did: string): Promise; $debugMergedSettings(did: string): Promise; + + // Active Identity façade methods + $getActiveDid(scope?: string): Promise; + $setActiveDid(did: string | null, scope?: string): Promise; + $switchActiveIdentity(did: string): Promise; + $getActiveIdentityScopes(): Promise; } // TypeScript declaration merging to eliminate (this as any) type assertions @@ -1868,6 +1879,12 @@ declare module "@vue/runtime-core" { currentActiveDid: string | null; $updateActiveDid(newDid: string | null): Promise; + // Active Identity façade methods + $getActiveDid(scope?: string): Promise; + $setActiveDid(did: string | null, scope?: string): Promise; + $switchActiveIdentity(did: string): Promise; + $getActiveIdentityScopes(): Promise; + // Ultra-concise database methods (shortest possible names) $db(sql: string, params?: unknown[]): Promise; $exec(sql: string, params?: unknown[]): Promise;