-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add additional supported interfaces
This includes the relevant auth headers and a simplification of several others.
- Loading branch information
Showing
12 changed files
with
107 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* Credentials identifying an entity accessing or owning data. | ||
*/ | ||
export interface Credentials { | ||
webID: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Credentials } from './Credentials'; | ||
import { HttpRequest } from '../server/HttpRequest'; | ||
|
||
/** | ||
* Responsible for extracting credentials. | ||
*/ | ||
export interface CredentialsExtractor { | ||
/** | ||
* Extracts the credentials found in an HttpRequest. | ||
* | ||
* @param request - The incoming request. | ||
* @returns A promise resolving to the credentials. | ||
*/ | ||
extractCredentials: (request: HttpRequest) => Promise<Credentials>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Credentials } from '../authentication/Credentials'; | ||
import { PermissionSet } from '../ldp/permissions/PermissionSet'; | ||
import { ResourceIdentifier } from '../ldp/http/ResourceIdentifier'; | ||
|
||
/** | ||
* Responsible for the permission verification. | ||
*/ | ||
export interface Authorizer { | ||
/** | ||
* Verifies if the given credentials have access to the given permissions on the given resource. | ||
* @param credentials - Credentials of the entity that wants to use the resource. | ||
* @param identifier - Identifier of the resource that will be read/modified. | ||
* @param permissions - Permissions that are requested on the resource. | ||
* | ||
* @returns A promise resolving when the Authorizer is finished. | ||
* An {@link Error} with the necessary explanation will be thrown when permissions are not granted. | ||
*/ | ||
ensurePermissions: ( | ||
credentials: Credentials, | ||
identifier: ResourceIdentifier, | ||
permissions: PermissionSet, | ||
) => Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import { Representation } from './Representation'; | ||
|
||
/** | ||
* Represents the changes needed for a PATCH request. | ||
*/ | ||
export interface Patch {} | ||
export interface Patch extends Representation {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AsyncHandler } from '../../util/AsyncHandler'; | ||
import { HttpRequest } from '../../server/HttpRequest'; | ||
import { Operation } from '../operations/Operation'; | ||
|
||
/** | ||
* Converts an incoming HttpRequest to an Operation. | ||
*/ | ||
export type RequestParser = AsyncHandler<HttpRequest, Operation>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
import { AsyncHandler } from '../../util/AsyncHandler'; | ||
import { Operation } from './Operation'; | ||
|
||
/** | ||
* Handler for a specific operation type. | ||
*/ | ||
export interface OperationHandler { | ||
/** | ||
* Checks if the handler supports the given operation. | ||
* @param operation - The input operation. | ||
* | ||
* @returns A promise resolving to a boolean indicating if this handler supports the operation. | ||
*/ | ||
canHandle: (operation: Operation) => Promise<boolean>; | ||
/** | ||
* Handles the given operation. | ||
* @param operation - The input operation. | ||
* | ||
* @returns A promise resolving when the operation is handled. | ||
*/ | ||
handle: (operation: Operation) => Promise<void>; | ||
} | ||
export type OperationHandler = AsyncHandler<Operation>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* A data interface indicating which permissions are allowed (based on the context). | ||
*/ | ||
export interface PermissionSet { | ||
read: boolean; | ||
append: boolean; | ||
write: boolean; | ||
delete: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AsyncHandler } from '../../util/AsyncHandler'; | ||
import { Operation } from '../operations/Operation'; | ||
import { PermissionSet } from './PermissionSet'; | ||
|
||
/** | ||
* Verifies which permissions are requested on a given {@link Operation}. | ||
*/ | ||
export type PermissionsExtractor = AsyncHandler<Operation, PermissionSet>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,8 @@ | ||
import { IncomingMessage, ServerResponse } from 'http'; | ||
import { AsyncHandler } from '../util/AsyncHandler'; | ||
import { HttpRequest } from './HttpRequest'; | ||
import { HttpResponse } from './HttpResponse'; | ||
|
||
/** | ||
* An HTTP request handler. | ||
*/ | ||
export interface HttpHandler { | ||
/** | ||
* Checks whether this handler supports the given request. | ||
* @param req - The input request. | ||
* | ||
* @returns A promise that indicates if this request is supported after resolving. | ||
*/ | ||
canHandle: (req: Request) => Promise<boolean>; | ||
/** | ||
* Handles the given request. | ||
* @param req - The input request. | ||
* @param res - The response needed for responding to the request. | ||
* | ||
* @returns A promise resolving when the handling is finished. | ||
*/ | ||
handle: (req: IncomingMessage, res: ServerResponse) => Promise<void>; | ||
} | ||
export type HttpHandler = AsyncHandler<{ request: HttpRequest; response: HttpResponse }>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IncomingMessage } from 'http'; | ||
|
||
/** | ||
* An incoming HTTP request; | ||
*/ | ||
export type HttpRequest = IncomingMessage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { OutgoingMessage } from 'http'; | ||
|
||
/** | ||
* An outgoing HTTP response; | ||
*/ | ||
export type HttpResponse = OutgoingMessage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Simple interface for classes that can potentially handle a specific kind of data asynchronously. | ||
*/ | ||
export interface AsyncHandler<TInput, TOutput = void> { | ||
/** | ||
* Checks if the input data can be handled by this class. | ||
* @param input - Input data that would be handled potentially. | ||
* @returns A promise resolving to if this input can be handled. | ||
*/ | ||
canHandle: (input: TInput) => Promise<boolean>; | ||
/** | ||
* Handles the given input. This should only be done if the {@link canHandle} function returned `true`. | ||
* @param input - Input data that needs to be handled. | ||
* @returns A promise resolving when the handling is finished. Return value depends on the given type. | ||
*/ | ||
handle: (input: TInput) => Promise<TOutput>; | ||
} |