Files
crowd-funder-for-time-pwa/src/services/notifications/notificationLog.ts
T
Jose Olarte III 724131d9a8 Retire app consumption of WAKEUP_PING → /notifications/refresh → api_* scheduling.
Phase 2 of legacy notification retirement: drop the production push refresh chain and dead debug/composable paths while keeping FCM registration, AlertSearch, daily reminder, and dual notifications intact.
2026-09-22 20:39:37 +08:00

77 lines
2.0 KiB
TypeScript

/**
* Shared observability helpers for notification flows (console + debug panel).
*/
import { logNotification } from "./NotificationDebugEvents";
export function truncateFcmTokenForLog(token: string): string {
const t = token.trim();
if (t.length <= 24) {
return t;
}
return `${t.slice(0, 12)}…${t.slice(-8)}`;
}
export function logPushNotificationReceived(notification: {
title?: string;
data?: Record<string, unknown>;
}): void {
const type =
typeof notification.data?.type === "string"
? notification.data.type
: "(none)";
logNotification(`pushNotificationReceived type=${type}`, {
title: notification.title,
dataType: type,
});
}
export function logPushNotificationActionPerformed(action: {
actionId?: string;
notification?: { title?: string; data?: Record<string, unknown> };
}): void {
const type =
typeof action.notification?.data?.type === "string"
? action.notification.data.type
: "(none)";
logNotification(
`pushNotificationActionPerformed actionId=${action.actionId ?? "(none)"} type=${type}`,
{
actionId: action.actionId,
dataType: type,
},
);
}
export function logTokenRegistrationStarted(token: string): void {
logNotification("Token registration started", {
token: truncateFcmTokenForLog(token),
});
}
export function logTokenRegistrationSuccess(token: string): void {
logNotification("Token registration success", {
token: truncateFcmTokenForLog(token),
});
}
export function logTokenRegistrationSkippedDuplicate(token: string): void {
logNotification("Token registration skipped (duplicate token)", {
token: truncateFcmTokenForLog(token),
});
}
export function logTokenRegistrationFailure(
token: string,
error: unknown,
): void {
const message = error instanceof Error ? error.message : String(error);
logNotification(`Token registration failure: ${message}`, {
token: truncateFcmTokenForLog(token),
});
}
export function logNotificationClearing(method: string): void {
logNotification(`Clearing notifications via ${method}`);
}