mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { getLoggerFor } from '../../../../logging/LogUtil';
|
|
import { readJsonStream } from '../../../../util/StreamUtil';
|
|
import type { RegistrationManager, RegistrationResponse } from '../util/RegistrationManager';
|
|
import type { InteractionResponseResult, InteractionHandlerInput } from './InteractionHandler';
|
|
import { InteractionHandler } from './InteractionHandler';
|
|
|
|
/**
|
|
* Supports registration based on the `RegistrationManager` behaviour.
|
|
*/
|
|
export class RegistrationHandler extends InteractionHandler {
|
|
protected readonly logger = getLoggerFor(this);
|
|
|
|
private readonly registrationManager: RegistrationManager;
|
|
|
|
public constructor(registrationManager: RegistrationManager) {
|
|
super();
|
|
this.registrationManager = registrationManager;
|
|
}
|
|
|
|
public async handle({ operation }: InteractionHandlerInput):
|
|
Promise<InteractionResponseResult<RegistrationResponse>> {
|
|
const data = await readJsonStream(operation.body.data);
|
|
const validated = this.registrationManager.validateInput(data, false);
|
|
const details = await this.registrationManager.register(validated, false);
|
|
return { type: 'response', details };
|
|
}
|
|
}
|