mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Make IDP routes independent of handlers
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import type { InteractionRoute } from './InteractionRoute';
|
||||
|
||||
/**
|
||||
* A route that returns the input string as path.
|
||||
*/
|
||||
export class AbsolutePathInteractionRoute implements InteractionRoute {
|
||||
private readonly path: string;
|
||||
|
||||
public constructor(path: string) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public getPath(): string {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,28 @@
|
||||
import type { Representation } from '../../../http/representation/Representation';
|
||||
import { NotFoundHttpError } from '../../../util/errors/NotFoundHttpError';
|
||||
import { UnsupportedAsyncHandler } from '../../../util/handlers/UnsupportedAsyncHandler';
|
||||
import { InteractionHandler } from '../InteractionHandler';
|
||||
import type { InteractionHandlerInput } from '../InteractionHandler';
|
||||
import { InteractionHandler } from '../InteractionHandler';
|
||||
import type { InteractionRoute } from './InteractionRoute';
|
||||
|
||||
/**
|
||||
* Default implementation of an InteractionHandler with an InteractionRoute.
|
||||
* InteractionHandler that only accepts operations with an expected path.
|
||||
*
|
||||
* Rejects operations that target a different path,
|
||||
* otherwise the input parameters get passed to the source handler.
|
||||
*
|
||||
* In case no source handler is provided it defaults to an {@link UnsupportedAsyncHandler}.
|
||||
* This can be useful if you want an object with just the route.
|
||||
* otherwise the input parameters are passed to the source handler.
|
||||
*/
|
||||
export class BasicInteractionRoute extends InteractionHandler implements InteractionRoute {
|
||||
private readonly path: string;
|
||||
export class InteractionRouteHandler extends InteractionHandler {
|
||||
private readonly route: InteractionRoute;
|
||||
private readonly source: InteractionHandler;
|
||||
|
||||
public constructor(path: string, source?: InteractionHandler) {
|
||||
public constructor(route: InteractionRoute, source: InteractionHandler) {
|
||||
super();
|
||||
this.path = path;
|
||||
this.source = source ?? new UnsupportedAsyncHandler('This route has no associated handler.');
|
||||
}
|
||||
|
||||
public getPath(): string {
|
||||
return this.path;
|
||||
this.route = route;
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public async canHandle(input: InteractionHandlerInput): Promise<void> {
|
||||
const { target } = input.operation;
|
||||
const path = this.getPath();
|
||||
const path = this.route.getPath();
|
||||
if (target.path !== path) {
|
||||
throw new NotFoundHttpError();
|
||||
}
|
||||
@@ -1,18 +1,16 @@
|
||||
import { joinUrl } from '../../../util/PathUtil';
|
||||
import type { InteractionHandler } from '../InteractionHandler';
|
||||
import { BasicInteractionRoute } from './BasicInteractionRoute';
|
||||
import { AbsolutePathInteractionRoute } from './AbsolutePathInteractionRoute';
|
||||
import type { InteractionRoute } from './InteractionRoute';
|
||||
|
||||
/**
|
||||
* A route that is relative to another route.
|
||||
* The relative path will be joined to the input base,
|
||||
* which can either be an absolute URL or an InteractionRoute of which the path will be used.
|
||||
* The source handler will be called for all operation requests
|
||||
*/
|
||||
export class RelativeInteractionRoute extends BasicInteractionRoute {
|
||||
public constructor(base: InteractionRoute | string, relativePath: string, source?: InteractionHandler) {
|
||||
export class RelativePathInteractionRoute extends AbsolutePathInteractionRoute {
|
||||
public constructor(base: InteractionRoute | string, relativePath: string) {
|
||||
const url = typeof base === 'string' ? base : base.getPath();
|
||||
const path = joinUrl(url, relativePath);
|
||||
super(path, source);
|
||||
super(path);
|
||||
}
|
||||
}
|
||||
@@ -145,9 +145,10 @@ export * from './identity/interaction/email-password/util/RegistrationManager';
|
||||
export * from './identity/interaction/email-password/EmailPasswordUtil';
|
||||
|
||||
// Identity/Interaction/Routing
|
||||
export * from './identity/interaction/routing/BasicInteractionRoute';
|
||||
export * from './identity/interaction/routing/AbsolutePathInteractionRoute';
|
||||
export * from './identity/interaction/routing/InteractionRoute';
|
||||
export * from './identity/interaction/routing/RelativeInteractionRoute';
|
||||
export * from './identity/interaction/routing/InteractionRouteHandler';
|
||||
export * from './identity/interaction/routing/RelativePathInteractionRoute';
|
||||
|
||||
// Identity/Interaction/Util
|
||||
export * from './identity/interaction/util/BaseEmailSender';
|
||||
|
||||
Reference in New Issue
Block a user