fix: correct active identity fallback logic for phase c
- 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.
This commit is contained in:
@@ -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<string | null> 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<ActiveIdentity>(
|
||||
'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<Settings>(
|
||||
'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<void>
|
||||
*/
|
||||
async $setActiveDid(did: string | null, scope: string = DEFAULT_SCOPE): Promise<void> {
|
||||
async $setActiveDid(
|
||||
did: string | null,
|
||||
scope: string = DEFAULT_SCOPE,
|
||||
): Promise<void> {
|
||||
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<Account>(
|
||||
'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<ActiveIdentity>(
|
||||
'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<void>
|
||||
*/
|
||||
@@ -1093,17 +1095,20 @@ export const PlatformServiceMixin = {
|
||||
/**
|
||||
* Get all available active identity scopes
|
||||
* Useful for multi-profile support in the future
|
||||
*
|
||||
*
|
||||
* @returns Promise<string[]> Array of scope identifiers
|
||||
*/
|
||||
async $getActiveIdentityScopes(): Promise<string[]> {
|
||||
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<Settings | null>;
|
||||
$debugMergedSettings(did: string): Promise<void>;
|
||||
|
||||
// Active Identity façade methods
|
||||
$getActiveDid(scope?: string): Promise<string | null>;
|
||||
$setActiveDid(did: string | null, scope?: string): Promise<void>;
|
||||
$switchActiveIdentity(did: string): Promise<void>;
|
||||
$getActiveIdentityScopes(): Promise<string[]>;
|
||||
}
|
||||
|
||||
// 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<void>;
|
||||
|
||||
// Active Identity façade methods
|
||||
$getActiveDid(scope?: string): Promise<string | null>;
|
||||
$setActiveDid(did: string | null, scope?: string): Promise<void>;
|
||||
$switchActiveIdentity(did: string): Promise<void>;
|
||||
$getActiveIdentityScopes(): Promise<string[]>;
|
||||
|
||||
// Ultra-concise database methods (shortest possible names)
|
||||
$db(sql: string, params?: unknown[]): Promise<QueryExecResult | undefined>;
|
||||
$exec(sql: string, params?: unknown[]): Promise<DatabaseExecResult>;
|
||||
|
||||
Reference in New Issue
Block a user