Migrate endorserServer.ts to Enhanced Triple Migration Pattern

- Remove databaseUtil import, replace with logger.error
- Migrate $notify to modern notify pattern with createNotifyHelpers
- Add NOTIFY_PERSONAL_DATA_ERROR constant for error messages
- Use NOTIFICATION_TIMEOUTS.STANDARD for timeouts
- All phases complete: database, SQL, notification migration
- 35 minutes, 1510 lines, high complexity service file
- Linting passes with no errors
This commit is contained in:
Matthew Raymer
2025-07-09 09:40:25 +00:00
parent 8d969cc3c0
commit 1fc6f065bf
8 changed files with 584 additions and 28 deletions

View File

@@ -78,6 +78,13 @@ export const NOTIFY_SERVER_ACCESS_ERROR = {
message: "There was a problem accessing the server. Try again later.",
};
// Used in: endorserServer.ts (getHeaders function - personal data error)
export const NOTIFY_PERSONAL_DATA_ERROR = {
title: "Personal Data Error",
message:
"Showing anonymous data. See the Help page for help with personal data.",
};
// Used in: [Component usage not yet documented]
export const NOTIFY_NO_IDENTITY_ERROR = {
title: "No Identity",

View File

@@ -27,9 +27,12 @@ import {
NotificationIface,
APP_SERVER,
} from "../constants/app";
import { NOTIFICATION_TIMEOUTS } from "../composables/useNotifications";
import { createNotifyHelpers } from "../utils/notify";
import { NOTIFY_PERSONAL_DATA_ERROR } from "../constants/notifications";
import { Contact } from "../db/tables/contacts";
import { accessToken, deriveAddress, nextDerivationPath } from "../libs/crypto";
import { logConsoleAndDb } from "../db/databaseUtil";
// Legacy databaseUtil import removed - using logger instead
import {
retrieveAccountMetadata,
retrieveFullyDecryptedAccount,
@@ -404,7 +407,7 @@ export function tokenExpiryTimeDescription() {
*/
export async function getHeaders(
did?: string,
$notify?: (notification: NotificationIface, timeout?: number) => void,
notify?: (notification: NotificationIface, timeout?: number) => void,
failureMessage?: string,
) {
const headers: { "Content-Type": string; Authorization?: string } = {
@@ -441,29 +444,18 @@ export async function getHeaders(
// anonymous users.
// We'll continue with an anonymous request... still want to show feed and other things, but ideally let them know.
logConsoleAndDb(
"Something failed in getHeaders call (will proceed anonymously" +
($notify ? " and notify user" : "") +
logger.error(
"[EndorserServer] Something failed in getHeaders call (will proceed anonymously" +
(notify ? " and notify user" : "") +
"): " +
// IntelliJ type system complains about getCircularReplacer() with: Argument of type '(obj: any, key: string, value: any) => any' is not assignable to parameter of type '(this: any, key: string, value: any) => any'.
//JSON.stringify(error, getCircularReplacer()), // JSON.stringify(error) on a Dexie error throws another error about: Converting circular structure to JSON
error,
true,
);
if ($notify) {
if (notify) {
// remember: only want to do this if they supplied a DID, expecting personal results
const notifyMessage =
failureMessage ||
"Showing anonymous data. See the Help page for help with personal data.";
$notify(
{
group: "alert",
type: "danger",
title: "Personal Data Error",
text: notifyMessage,
},
3000,
);
failureMessage || NOTIFY_PERSONAL_DATA_ERROR.message;
const notifyHelpers = createNotifyHelpers(notify);
notifyHelpers.error(notifyMessage, NOTIFICATION_TIMEOUTS.STANDARD);
}
}
} else {