diff --git a/src/plugins/api/apps.ts b/src/plugins/api/apps.ts index 3666e6b..16891d9 100644 --- a/src/plugins/api/apps.ts +++ b/src/plugins/api/apps.ts @@ -119,7 +119,7 @@ function appsRoute(server: FastifyInstance) { + interface Headers { + adminkey: string + } + + interface Params { + id: string + } + + const options: RouteShorthandOptions = { + schema: { + headers: { + type: 'object', + required: ['adminkey'], + properties: { + 'adminkey': { type: 'string' }, + }, + }, + params: { + type: 'object', + properties: { + id: { type: 'string' }, + }, + }, + response: { + 400: errorSchema, + } + }, + } + + server.post('/api/app/:id/activate', options, async (request, reply) => { + if (!server.database) return serverError(reply) + if (request.headers.adminkey !== process.env.ADMIN_KEY) return serverError(reply) + + const container = containerFor(server.database.client, 'Apps') + const item = container.item(request.params.id, APP_PARTITION_KEY) + + const { resource: app } = await item.read() + await item.replace({ + ...app, + active: true, + }) + + reply.code(204) + }) +} + +function setPreinstallRoute(server: FastifyInstance) { + interface Headers { + adminkey: string + } + + interface Params { + id: string + } + + const options: RouteShorthandOptions = { + schema: { + headers: { + type: 'object', + required: ['adminkey'], + properties: { + adminkey: { type: 'string' }, + }, + }, + params: { + type: 'object', + properties: { + id: { type: 'string' }, + }, + }, + response: { + 400: errorSchema, + } + }, + } + + server.post('/api/app/:id/preinstall', options, async (request, reply) => { + if (!server.database) return serverError(reply) + if (request.headers.adminkey !== process.env.ADMIN_KEY) return serverError(reply) + + const container = containerFor(server.database.client, 'Apps') + const item = container.item(request.params.id, APP_PARTITION_KEY) + + const { resource: app } = await item.read() + await item.replace({ + ...app, + preinstall: true, + active: true, + }) + + reply.code(204) + }) +} + const plugin: Plugin = async server => { availabilityRoute(server) appsRoute(server) @@ -697,6 +792,8 @@ const plugin: Plugin = a installRoute(server) uninstallRoute(server) installationsRoute(server) + activateRoute(server) + setPreinstallRoute(server) } export default plugin diff --git a/src/plugins/api/groups.ts b/src/plugins/api/groups.ts index 3a0579e..fdb22da 100644 --- a/src/plugins/api/groups.ts +++ b/src/plugins/api/groups.ts @@ -462,12 +462,23 @@ function unblockRoute(server: FastifyInstance) { + interface Headers { + adminkey: string + } + interface Params { id: string } const options: RouteShorthandOptions = { schema: { + headers: { + type: 'object', + required: ['adminkey'], + properties: { + adminkey: { type: 'string' }, + }, + }, params: { type: 'object', properties: { @@ -477,8 +488,9 @@ function activateRoute(server: FastifyInstance('/api/group/:id/activate', options, async (request, reply) => { + server.post('/api/group/:id/activate', options, async (request, reply) => { if (!server.database) return serverError(reply) + if (request.headers.adminkey !== process.env.ADMIN_KEY) return serverError(reply) const container = containerFor(server.database.client, 'Groups') const groupItem = container.item(request.params.id, request.params.id) diff --git a/src/plugins/api/index.ts b/src/plugins/api/index.ts index b39e65e..68a7c6b 100644 --- a/src/plugins/api/index.ts +++ b/src/plugins/api/index.ts @@ -62,6 +62,8 @@ const plugin: Plugin = a }) server.setErrorHandler(function(error, request, reply) { + request.log.error(error) + const response: HttpError = { message: error.message, } diff --git a/src/schemas.ts b/src/schemas.ts index 3eb8ee4..a47bd29 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -67,6 +67,8 @@ export const appSchema: JSONSchema = { publicKey: { type: 'string' }, privateKey: { type: 'string' }, + composerUrl: { type: 'string' }, + rendererUrl: { type: 'string' }, revisions: { type: 'array', items: {