Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 32 additions & 10 deletions packages/federation-sdk/src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,24 @@ export class ConfigService {
try {
this.config = AppConfigSchema.parse(values);
} catch (error) {
if (error instanceof z.ZodError) {
this.logger.error({
msg: 'Configuration validation failed:',
err: error,
});
throw new Error(
`Invalid configuration: ${error.errors.map((e) => `${e.path.join('.')}: ${e.message}`).join(', ')}`,
);
}
throw error;
this.handleValidationError(error, 'Configuration validation failed:');
}
}

private handleValidationError(err: unknown, contextMsg?: string): never {
if (err instanceof z.ZodError) {
const errorDetails = err.errors
.map((e) => `${e.path.join('.')}: ${e.message}`)
.join(', ');
this.logger.error({
msg: contextMsg || 'Validation failed',
errors: errorDetails,
});
throw new Error(`Invalid configuration: ${errorDetails}`);
}
throw err;
}

get serverName(): string {
return this.config.serverName;
}
Expand Down Expand Up @@ -156,4 +161,21 @@ export class ConfigService {
const signingKeys = await this.getSigningKey();
return toUnpaddedBase64(signingKeys[0].publicKey);
}

updateConfig(values: AppConfig): void {
try {
const validatedConfig = AppConfigSchema.parse(values);
this.config = validatedConfig;
this.serverKeys = [];
this.logger.debug({
msg: 'Configuration updated',
serverName: validatedConfig.serverName,
});
} catch (error) {
this.handleValidationError(
error,
'Configuration validation failed - check your federation settings',
);
}
}
}