This commit is contained in:
2025-12-16 13:13:03 +01:00
parent 7d3393e1b9
commit 84f05598a6
78 changed files with 161 additions and 157 deletions

View File

@@ -5,7 +5,7 @@
*/
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '@core/shared/logging/Logger';
import type { Logger } from '@core/shared/application';
import { EngagementEvent, type EngagementAction, type EngagementEntityType } from '../../domain/entities/EngagementEvent';
import type { IEngagementRepository } from '../../domain/repositories/IEngagementRepository';
@@ -59,7 +59,7 @@ export class RecordEngagementUseCase
engagementWeight: event.getEngagementWeight(),
};
} catch (error) {
this.logger.error('Error recording engagement', error, { input });
this.logger.error('Error recording engagement', error instanceof Error ? error : new Error(String(error)), { input });
throw error;
}
}

View File

@@ -5,7 +5,7 @@
*/
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '@core/shared/logging/Logger';
import type { Logger } from '@core/shared/application';
import { PageView } from '../../domain/entities/PageView';
import type { EntityType, VisitorType } from '../../domain/types/PageView';
import type { IPageViewRepository } from '../../domain/repositories/IPageViewRepository';

View File

@@ -1,6 +1,6 @@
import type { LogLevel } from './LoggerLogLevel';
import type { LogContext } from './LoggerContext';
import type { Logger } from '@core/shared/logging/Logger';
import type { Logger } from '@core/shared/application';
/**
* LoggerPort - Port interface for application-layer logging.

View File

@@ -1,5 +1,5 @@
import { AuthenticationState } from '../../domain/value-objects/AuthenticationState';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import { Result } from '../../../shared/result/Result';
import type { AuthenticationServicePort } from '../ports/AuthenticationServicePort';
import { SessionLifetime } from '../../domain/value-objects/SessionLifetime';

View File

@@ -1,6 +1,6 @@
import { Result } from '../../../shared/result/Result';
import type { AuthenticationServicePort } from '../ports/AuthenticationServicePort';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
/**
* Use case for clearing the user's session (logout).

View File

@@ -1,7 +1,7 @@
import { Result } from '../../../shared/result/Result';
import { RaceCreationResult } from '../../domain/value-objects/RaceCreationResult';
import type { CheckoutServicePort } from '../ports/CheckoutServicePort';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
export class CompleteRaceCreationUseCase {
constructor(private readonly checkoutService: CheckoutServicePort, private readonly logger: Logger) {}

View File

@@ -1,5 +1,5 @@
import { Result } from '../../../shared/result/Result';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import type { CheckoutServicePort } from '../ports/CheckoutServicePort';
import type { CheckoutConfirmationPort } from '../ports/CheckoutConfirmationPort';
import { CheckoutStateEnum } from '../../domain/value-objects/CheckoutState';

View File

@@ -1,5 +1,5 @@
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import { AutomationSession } from '../../domain/entities/AutomationSession';
import type { HostedSessionConfig } from '../../domain/types/HostedSessionConfig';
import { AutomationEnginePort } from '../ports/AutomationEnginePort';

View File

@@ -1,7 +1,7 @@
import type { AuthenticationServicePort } from '../ports/AuthenticationServicePort';
import { Result } from '../../../shared/result/Result';
import { BrowserAuthenticationState } from '../../domain/value-objects/BrowserAuthenticationState';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
/**
* Use case for verifying browser shows authenticated page state.

View File

@@ -1,6 +1,6 @@
import type { LoggerPort } from '../../../application/ports/LoggerPort';
import type { LogContext } from '../../../application/ports/LoggerContext';
import type { Logger } from '@core/shared/logging/Logger';
import type { Logger } from '@core/shared/application';
export class NoOpLogAdapter implements LoggerPort, Logger {
debug(_message: string, _context?: LogContext): void {}

View File

@@ -2,7 +2,7 @@ import type { LoggerPort } from '@core/automation/application/ports/LoggerPort';
import type { LogContext } from '@core/automation/application/ports/LoggerContext';
import type { LogLevel } from '@core/automation/application/ports/LoggerLogLevel';
import { loadLoggingConfig, type LoggingEnvironmentConfig } from '../../config/LoggingConfig';
import type { Logger } from '@core/shared/logging/Logger';
import type { Logger } from '@core/shared/application';
const LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {
debug: 10,

View File

@@ -5,7 +5,7 @@
*/
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import type { Notification } from '../../domain/entities/Notification';
import type { INotificationRepository } from '../../domain/repositories/INotificationRepository';
@@ -35,7 +35,7 @@ export class GetUnreadNotificationsUseCase implements AsyncUseCase<string, Unrea
totalCount: notifications.length,
};
} catch (error) {
this.logger.error(`Failed to retrieve unread notifications for recipient ID: ${recipientId}`, error);
this.logger.error(`Failed to retrieve unread notifications for recipient ID: ${recipientId}`, error instanceof Error ? error : new Error(String(error)));
throw error;
}
}

View File

@@ -7,7 +7,7 @@
import type { AsyncUseCase } from '@core/shared/application';
import type { INotificationRepository } from '../../domain/repositories/INotificationRepository';
import { NotificationDomainError } from '../../domain/errors/NotificationDomainError';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
export interface MarkNotificationReadCommand {
notificationId: string;
@@ -44,7 +44,7 @@ export class MarkNotificationReadUseCase implements AsyncUseCase<MarkNotificatio
await this.notificationRepository.update(updatedNotification);
this.logger.info(`Notification ${command.notificationId} successfully marked as read.`);
} catch (error) {
this.logger.error(`Failed to mark notification ${command.notificationId} as read: ${error.message}`);
this.logger.error(`Failed to mark notification ${command.notificationId} as read: ${error instanceof Error ? error.message : String(error)}`);
throw error;
}
}

View File

@@ -5,7 +5,7 @@
*/
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '@core/shared/logging/Logger';
import type { Logger } from '@core/shared/application';
import { NotificationPreference } from '../../domain/entities/NotificationPreference';
import type { ChannelPreference, TypePreference } from '../../domain/entities/NotificationPreference';
import type { INotificationPreferenceRepository } from '../../domain/repositories/INotificationPreferenceRepository';

View File

@@ -7,7 +7,7 @@
import { v4 as uuid } from 'uuid';
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import { Notification } from '../../domain/entities/Notification';
import type { NotificationData } from '../../domain/entities/Notification';
import type { INotificationRepository } from '../../domain/repositories/INotificationRepository';
@@ -60,83 +60,87 @@ export class SendNotificationUseCase implements AsyncUseCase<SendNotificationCom
// Get recipient's preferences
this.logger.debug('Checking notification preferences.', { type: command.type, recipientId: command.recipientId });
const preferences = await this.preferenceRepository.getOrCreateDefault(command.recipientId);
// Check if this notification type is enabled
if (!preferences.isTypeEnabled(command.type)) {
// User has disabled this type - create but don't deliver
const notification = Notification.create({
id: uuid(),
recipientId: command.recipientId,
type: command.type,
title: command.title,
body: command.body,
channel: 'in_app',
status: 'dismissed', // Auto-dismiss since user doesn't want these
...(command.data ? { data: command.data } : {}),
...(command.actionUrl ? { actionUrl: command.actionUrl } : {}),
});
await this.notificationRepository.create(notification);
return {
notification,
deliveryResults: [],
};
}
// Determine which channels to use
const channels = command.forceChannels ?? preferences.getEnabledChannelsForType(command.type);
// Check quiet hours (skip external channels during quiet hours)
const effectiveChannels = preferences.isInQuietHours()
? channels.filter(ch => ch === 'in_app')
: channels;
// Ensure at least in_app is used
if (!effectiveChannels.includes('in_app')) {
effectiveChannels.unshift('in_app');
}
const deliveryResults: NotificationDeliveryResult[] = [];
let primaryNotification: Notification | null = null;
// Send through each channel
for (const channel of effectiveChannels) {
const notification = Notification.create({
id: uuid(),
recipientId: command.recipientId,
type: command.type,
title: command.title,
body: command.body,
channel,
...(command.urgency ? { urgency: command.urgency } : {}),
...(command.data ? { data: command.data } : {}),
...(command.actionUrl ? { actionUrl: command.actionUrl } : {}),
...(command.actions ? { actions: command.actions } : {}),
...(command.requiresResponse !== undefined
? { requiresResponse: command.requiresResponse }
: {}),
});
// Save to repository (in_app channel) or attempt delivery (external channels)
if (channel === 'in_app') {
await this.notificationRepository.create(notification);
primaryNotification = notification;
deliveryResults.push({
success: true,
channel,
attemptedAt: new Date(),
// Check if this notification type is enabled
if (!preferences.isTypeEnabled(command.type)) {
// User has disabled this type - create but don't deliver
const notification = Notification.create({
id: uuid(),
recipientId: command.recipientId,
type: command.type,
title: command.title,
body: command.body,
channel: 'in_app',
status: 'dismissed', // Auto-dismiss since user doesn't want these
...(command.data ? { data: command.data } : {}),
...(command.actionUrl ? { actionUrl: command.actionUrl } : {}),
});
} else {
// Attempt external delivery
const result = await this.gatewayRegistry.send(notification);
deliveryResults.push(result);
await this.notificationRepository.create(notification);
return {
notification,
deliveryResults: [],
};
}
// Determine which channels to use
const channels = command.forceChannels ?? preferences.getEnabledChannelsForType(command.type);
// Check quiet hours (skip external channels during quiet hours)
const effectiveChannels = preferences.isInQuietHours()
? channels.filter(ch => ch === 'in_app')
: channels;
// Ensure at least in_app is used
if (!effectiveChannels.includes('in_app')) {
effectiveChannels.unshift('in_app');
}
const deliveryResults: NotificationDeliveryResult[] = [];
let primaryNotification: Notification | null = null;
// Send through each channel
for (const channel of effectiveChannels) {
const notification = Notification.create({
id: uuid(),
recipientId: command.recipientId,
type: command.type,
title: command.title,
body: command.body,
channel,
...(command.urgency ? { urgency: command.urgency } : {}),
...(command.data ? { data: command.data } : {}),
...(command.actionUrl ? { actionUrl: command.actionUrl } : {}),
...(command.actions ? { actions: command.actions } : {}),
...(command.requiresResponse !== undefined
? { requiresResponse: command.requiresResponse }
: {}),
});
// Save to repository (in_app channel) or attempt delivery (external channels)
if (channel === 'in_app') {
await this.notificationRepository.create(notification);
primaryNotification = notification;
deliveryResults.push({
success: true,
channel,
attemptedAt: new Date(),
});
} else {
// Attempt external delivery
const result = await this.gatewayRegistry.send(notification);
deliveryResults.push(result);
}
}
return {
notification: primaryNotification!,
deliveryResults,
};
} catch (error) {
this.logger.error('Error sending notification', error as Error);
throw error;
}
return {
notification: primaryNotification!,
deliveryResults,
};
}
}

View File

@@ -5,7 +5,7 @@
* This creates an active sponsorship and notifies the sponsor.
*/
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import type { ISponsorshipRequestRepository } from '../../domain/repositories/ISponsorshipRequestRepository';
import type { ISeasonSponsorshipRepository } from '../../domain/repositories/ISeasonSponsorshipRepository';
import type { ISeasonRepository } from '../../domain/repositories/ISeasonRepository';

View File

@@ -16,7 +16,7 @@ import {
EntityNotFoundError,
BusinessRuleViolationError,
} from '../errors/RacingApplicationError';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
export interface ApplyForSponsorshipDTO {
sponsorId: string;

View File

@@ -12,7 +12,7 @@ import type { IRaceRepository } from '../../domain/repositories/IRaceRepository'
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import { randomUUID } from 'crypto';
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
export interface ApplyPenaltyCommand {
raceId: string;

View File

@@ -1,4 +1,4 @@
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import type { ITeamMembershipRepository } from '../../domain/repositories/ITeamMembershipRepository';
import type {
TeamMembership,

View File

@@ -1,6 +1,6 @@
import type { IRaceRepository } from '../../domain/repositories/IRaceRepository';
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
/**
* Use Case: CancelRaceUseCase

View File

@@ -6,7 +6,7 @@ import type { DriverRatingProvider } from '../ports/DriverRatingProvider';
import { Result } from '../../domain/entities/Result';
import { Standing } from '../../domain/entities/Standing';
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
/**
* Use Case: CompleteRaceUseCase

View File

@@ -8,7 +8,7 @@ import { Standing } from '../../domain/entities/Standing';
import { RaceResultGenerator } from '../utils/RaceResultGenerator';
import { RatingUpdateService } from '@core/identity/domain/services/RatingUpdateService';
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
/**
* Enhanced CompleteRaceUseCase that includes rating updates

View File

@@ -6,7 +6,7 @@ import type { ISeasonRepository } from '../../domain/repositories/ISeasonReposit
import type { ILeagueScoringConfigRepository } from '../../domain/repositories/ILeagueScoringConfigRepository';
import type { LeagueScoringConfig } from '../../domain/entities/LeagueScoringConfig';
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import type {
LeagueScoringPresetProvider,
LeagueScoringPresetDTO,

View File

@@ -1,6 +1,6 @@
import type { IRaceRepository } from '../../domain/repositories/IRaceRepository';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import type {
IAllRacesPagePresenter,
AllRacesPageResultDTO,
@@ -8,7 +8,7 @@ import type {
AllRacesListItemViewModel,
AllRacesFilterOptionsViewModel,
} from '../presenters/IAllRacesPagePresenter';
import type { UseCase } => '@gridpilot/shared/application';
import type { UseCase } from '@core/shared/application';
export class GetAllRacesPageDataUseCase
implements UseCase<void, AllRacesPageResultDTO, AllRacesPageViewModel, IAllRacesPagePresenter> {

View File

@@ -6,7 +6,7 @@ import type {
} from '../presenters/IAllTeamsPresenter';
import type { UseCase } from '@core/shared/application';
import type { Team } from '../../domain/entities/Team';
import { Logger } from "@gridpilot/core/shared/application";
import { Logger } from "@core/shared/application";
/**
* Use Case for retrieving all teams.

View File

@@ -6,7 +6,7 @@ import type {
DriverTeamViewModel,
} from '../presenters/IDriverTeamPresenter';
import type { UseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
/**
* Use Case for retrieving a driver's team.

View File

@@ -7,7 +7,7 @@ import type {
TeamJoinRequestsViewModel,
} from '../presenters/ITeamJoinRequestsPresenter';
import type { UseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
/**
* Use Case for retrieving team join requests.

View File

@@ -7,7 +7,7 @@ import type {
TeamMembersViewModel,
} from '../presenters/ITeamMembersPresenter';
import type { UseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
/**
* Use Case for retrieving team members.

View File

@@ -1,4 +1,4 @@
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import type {
ILeagueMembershipRepository,
} from '@core/racing/domain/repositories/ILeagueMembershipRepository';

View File

@@ -7,7 +7,7 @@ import type {
} from '../../domain/types/TeamMembership';
import type { JoinTeamCommandDTO } from '../dto/TeamCommandAndQueryDTO';
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import {
BusinessRuleViolationError,
EntityNotFoundError,

View File

@@ -11,7 +11,7 @@ import type { IRaceRepository } from '../../domain/repositories/IRaceRepository'
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import { randomUUID } from 'crypto';
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
export interface QuickPenaltyCommand {
raceId: string;

View File

@@ -3,7 +3,7 @@ import type { ILeagueMembershipRepository } from '@core/racing/domain/repositori
import { RaceRegistration } from '@core/racing/domain/entities/RaceRegistration';
import type { RegisterForRaceCommandDTO } from '../dto/RegisterForRaceCommandDTO';
import type { AsyncUseCase } from '@core/shared/application';
import { Logger } from '@core/shared/logging/Logger';
import { Logger } from '@core/shared/application';
import {
BusinessRuleViolationError,
PermissionDeniedError,

View File

@@ -1,5 +1,5 @@
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
import type { ISocialGraphRepository } from '../../domain/repositories/ISocialGraphRepository';
import type { CurrentUserSocialDTO } from '../dto/CurrentUserSocialDTO';
import type { FriendDTO } from '../dto/FriendDTO';

View File

@@ -6,7 +6,7 @@ import type {
IUserFeedPresenter,
UserFeedViewModel,
} from '../presenters/ISocialPresenters';
import type { Logger } from '../../../shared/src/logging/Logger';
import type { Logger } from '@core/shared/application';
export interface GetUserFeedParams {
driverId: string;

View File

@@ -2,7 +2,7 @@ import type { Driver } from '@core/racing/domain/entities/Driver';
import type { FeedItem } from '@core/social/domain/types/FeedItem';
import type { IFeedRepository } from '@core/social/domain/repositories/IFeedRepository';
import type { ISocialGraphRepository } from '@core/social/domain/repositories/ISocialGraphRepository';
import type { Logger } from '@core/shared/logging/Logger';
import type { Logger } from '@core/shared/application';
export type Friendship = {
driverId: string;