website refactor
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import type { FeatureState, PolicyApiClient, PolicySnapshotDto } from '@/lib/api/policy/PolicyApiClient';
|
||||
import { PolicyApiClient, type FeatureState, type PolicySnapshotDto } from '@/lib/api/policy/PolicyApiClient';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { DomainError, Service } from '@/lib/contracts/services/Service';
|
||||
import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl';
|
||||
import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger';
|
||||
import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter';
|
||||
|
||||
export interface CapabilityEvaluationResult {
|
||||
isLoading: boolean;
|
||||
@@ -8,11 +13,23 @@ export interface CapabilityEvaluationResult {
|
||||
shouldShowComingSoon: boolean;
|
||||
}
|
||||
|
||||
export class PolicyService {
|
||||
constructor(private readonly apiClient: PolicyApiClient) {}
|
||||
export class PolicyService implements Service {
|
||||
private readonly apiClient: PolicyApiClient;
|
||||
|
||||
getSnapshot(): Promise<PolicySnapshotDto> {
|
||||
return this.apiClient.getSnapshot();
|
||||
constructor() {
|
||||
const baseUrl = getWebsiteApiBaseUrl();
|
||||
const logger = new ConsoleLogger();
|
||||
const errorReporter = new EnhancedErrorReporter(logger);
|
||||
this.apiClient = new PolicyApiClient(baseUrl, errorReporter, logger);
|
||||
}
|
||||
|
||||
async getSnapshot(): Promise<Result<PolicySnapshotDto, DomainError>> {
|
||||
try {
|
||||
const data = await this.apiClient.getSnapshot();
|
||||
return Result.ok(data);
|
||||
} catch (error: any) {
|
||||
return Result.err({ type: 'serverError', message: error.message || 'Failed to get policy snapshot' });
|
||||
}
|
||||
}
|
||||
|
||||
getCapabilityState(snapshot: PolicySnapshotDto, capabilityKey: string): FeatureState {
|
||||
@@ -79,4 +96,4 @@ export class PolicyService {
|
||||
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user