mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-04 04:22:50 +00:00
feat: add model for plugin register route
This commit is contained in:
@@ -140,6 +140,37 @@ export class SCNotFoundErrorResponse extends SCError {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An error that is returned whenever there is an unexpected error while creating a plugin
|
||||
*/
|
||||
export class SCPluginRegisteringFailedErrorResponse extends SCError {
|
||||
/**
|
||||
* Create a PluginRegisteringFailedError
|
||||
* @param message Describes what went wrong wile registering the plugin
|
||||
* @param stack Set to true if a stack trace should be created
|
||||
*/
|
||||
constructor(message: string, stack?: boolean) {
|
||||
super('PluginRegisteringFailedError', message, 500, stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An error that is returned whenever there is a plugin request that is supposed to register a route, that is already
|
||||
* registered
|
||||
*/
|
||||
export class SCPluginRouteAlreadyRegisteredErrorResponse extends SCError {
|
||||
/**
|
||||
* Create a PluginRouteAlreadyRegisteredError
|
||||
* @param registeredName The name by the plugin that has already registered the route previously
|
||||
* @param registeredUrl The URL by the plugin that has already registered the route previously
|
||||
* @param stack Set to true if a stack trace should be created
|
||||
*/
|
||||
constructor(registeredName: string, registeredUrl: string, stack?: boolean) {
|
||||
super('PluginRouteAlreadyRegisteredError',
|
||||
`Already registered by "${registeredName}" under URL "${registeredUrl}".`, 409, stack);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An error that is returned whenever there is a syntax error
|
||||
*/
|
||||
|
||||
94
src/core/protocol/routes/plugin/PluginRegisterRequest.ts
Normal file
94
src/core/protocol/routes/plugin/PluginRegisterRequest.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Schema} from 'jsonschema';
|
||||
import {SCAbstractRoute, SCRouteHttpVerbs} from '../../../Route';
|
||||
import {
|
||||
SCInternalServerErrorResponse,
|
||||
SCMethodNotAllowedErrorResponse, SCPluginRegisteringFailedErrorResponse, SCPluginRouteAlreadyRegisteredErrorResponse,
|
||||
SCRequestBodyTooLargeErrorResponse,
|
||||
SCSyntaxErrorResponse,
|
||||
} from '../../errors/ErrorResponse';
|
||||
|
||||
/**
|
||||
* Plugin register request
|
||||
*
|
||||
* @validatable
|
||||
*/
|
||||
export type SCPluginRegisterRequest = AddPlugin | RemovePlugin;
|
||||
interface AddPlugin {
|
||||
/**
|
||||
* The desired action, so whether the plugin should be added or removed.
|
||||
*/
|
||||
action: 'add';
|
||||
|
||||
/**
|
||||
* The address of the plugin.
|
||||
*/
|
||||
address: string;
|
||||
|
||||
/**
|
||||
* The name of the plugin.
|
||||
* Just for debugging purposes, to more easily identify conflicts.
|
||||
*/
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* How the requests of the plugin looks like, a JSON schema for validation
|
||||
*/
|
||||
pluginRequestSchema: Schema;
|
||||
|
||||
/**
|
||||
* How the responses of the plugin looks like, a JSON schema for validation
|
||||
*/
|
||||
pluginResponseSchema: Schema;
|
||||
|
||||
/**
|
||||
* the desired route, for example /feedback.
|
||||
*/
|
||||
route: string;
|
||||
}
|
||||
interface RemovePlugin {
|
||||
/**
|
||||
* The desired action, so whether the plugin should be added or removed.
|
||||
*/
|
||||
action: 'remove';
|
||||
|
||||
/**
|
||||
* The route of the plugin you want to remove
|
||||
*/
|
||||
route: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Route to register Plugins
|
||||
*/
|
||||
export class SCPluginRegisterRoute extends SCAbstractRoute {
|
||||
constructor() {
|
||||
super();
|
||||
this.errorNames = [
|
||||
SCInternalServerErrorResponse,
|
||||
SCMethodNotAllowedErrorResponse,
|
||||
SCPluginRegisteringFailedErrorResponse,
|
||||
SCPluginRouteAlreadyRegisteredErrorResponse,
|
||||
SCRequestBodyTooLargeErrorResponse,
|
||||
SCSyntaxErrorResponse,
|
||||
];
|
||||
this.method = SCRouteHttpVerbs.POST;
|
||||
this.requestBodyName = 'SCPluginRegisterRequest';
|
||||
this.responseBodyName = 'SCPluginRegisterResponse';
|
||||
this.statusCodeSuccess = 200;
|
||||
this.urlFragment = '/plugin/register';
|
||||
}
|
||||
}
|
||||
26
src/core/protocol/routes/plugin/PluginRegisterResponse.ts
Normal file
26
src/core/protocol/routes/plugin/PluginRegisterResponse.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugin register response
|
||||
*
|
||||
* @validatable
|
||||
*/
|
||||
export interface SCPluginRegisterResponse {
|
||||
/**
|
||||
* Whether the desired action succeeded or failed (true for success, false if an error occurred).
|
||||
*/
|
||||
success: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user