From cdbe1d4bc02c20d2ab7152f3df11f0e7b697d094 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sat, 4 Jan 2020 17:45:59 +0200 Subject: [PATCH] Updated webhooks event list --- CHANGES.md | 2 + app/app.php | 67 +++++++++++++++++++++++- app/config/services.php | 71 +++++++++++++------------- app/views/console/webhooks/index.phtml | 25 ++++++--- 4 files changed, 120 insertions(+), 45 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 769e87c6b7..e1bedb5124 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -7,6 +7,8 @@ * Update docs example with auth info * Allow non-web platform skip origin header * Limited to console UI to show max 5 alerts at the same time +* Added new webhooks events +* Normnailized all webhooks event names ## Bug Fixes diff --git a/app/app.php b/app/app.php index 7d1116fa27..f6e46bbaae 100644 --- a/app/app.php +++ b/app/app.php @@ -410,7 +410,7 @@ $utopia->get('/v1/proxy') } ); -$utopia->get('/v1/open-api-2.json') + $utopia->get('/v1/open-api-2.json') ->label('scope', 'public') ->label('docs', false) ->param('platform', 'client', function () {return new WhiteList(['client', 'server']);}, 'Choose target platform.', true) @@ -733,6 +733,71 @@ $utopia->get('/v1/open-api-2.json') } ); + +$utopia->get('/v1/debug') + ->label('scope', 'public') + ->label('docs', false) + ->action( + function () use ($response, $request, $utopia, $domain, $services) { + $output = [ + 'webhooks' => [], + 'methods' => [], + 'routes' => [], + ]; + + foreach ($services as $service) { /* @noinspection PhpIncludeInspection */ + /** @noinspection PhpIncludeInspection */ + if($service['tests']) { + continue; + } + + include_once $service['controller']; + } + + $i = 0; + + foreach ($utopia->getRoutes() as $key => $method) { + foreach ($method as $route) { /* @var $route \Utopia\Route */ + if (!$route->getLabel('docs', true)) { + continue; + } + + if (empty($route->getLabel('sdk.namespace', null))) { + continue; + } + + if ($route->getLabel('webhook', false)) { + if(array_key_exists($route->getLabel('webhook', false), $output['webhooks'])) { + throw new Exception('Webhook ('.$route->getLabel('webhook', false).') is already in use by another route', 500); + } + + $output['webhooks'][$route->getLabel('webhook', false)] = $route->getMethod().' '.$route->getURL(); + } + + if ($route->getLabel('sdk.namespace', false)) { + $method = $route->getLabel('sdk.namespace', false).'->'.$route->getLabel('sdk.method', false).'()'; + if(array_key_exists($method, $output['methods'])) { + throw new Exception('Method ('.$method.') is already in use by another route', 500); + } + + $output['methods'][$method] = $route->getMethod().' '.$route->getURL(); + } + + $output['routes'][$route->getURL().' ('.$route->getMethod().')'] = []; + + $i++; + } + } + + ksort($output['webhooks']); + ksort($output['methods']); + ksort($output['routes']); + + $response + ->json($output); + } + ); + $name = APP_NAME; if (array_key_exists($service, $services)) { /** @noinspection PhpIncludeInspection */ diff --git a/app/config/services.php b/app/config/services.php index 01de0c0985..fd17e84811 100644 --- a/app/config/services.php +++ b/app/config/services.php @@ -20,13 +20,13 @@ return [ 'sdk' => true, 'tests' => false, ], - 'v1/auth' => [ // Add to docs later: You can also learn how to [configure support for our supported OAuth providers](/docs/oauth) - 'name' => 'Auth', - 'description' => '/docs/services/auth.md', - 'controller' => 'controllers/api/auth.php', - 'sdk' => true, - 'tests' => false, - ], + // 'v1/auth' => [ // Add to docs later: You can also learn how to [configure support for our supported OAuth providers](/docs/oauth) + // 'name' => 'Auth', + // 'description' => '/docs/services/auth.md', + // 'controller' => 'controllers/api/auth.php', + // 'sdk' => true, + // 'tests' => false, + // ], 'v1/avatars' => [ 'name' => 'Avatars', 'description' => '/docs/services/avatars.md', @@ -88,35 +88,34 @@ return [ 'sdk' => false, 'tests' => true, ], - - 'v1/keys' => [ - 'name' => 'Keys', - 'description' => '', - 'controller' => 'controllers/api/keys.php', - 'sdk' => true, - 'tests' => false, - ], - 'v1/platforms' => [ - 'name' => 'Platforms', - 'description' => '', - 'controller' => 'controllers/api/platforms.php', - 'sdk' => true, - 'tests' => false, - ], - 'v1/tasks' => [ - 'name' => 'Tasks', - 'description' => '', - 'controller' => 'controllers/api/tasks.php', - 'sdk' => true, - 'tests' => false, - ], - 'v1/webhooks' => [ - 'name' => 'Webhooks', - 'description' => '', - 'controller' => 'controllers/api/webhooks.php', - 'sdk' => true, - 'tests' => false, - ], + // 'v1/keys' => [ + // 'name' => 'Keys', + // 'description' => '', + // 'controller' => 'controllers/api/keys.php', + // 'sdk' => true, + // 'tests' => false, + // ], + // 'v1/platforms' => [ + // 'name' => 'Platforms', + // 'description' => '', + // 'controller' => 'controllers/api/platforms.php', + // 'sdk' => true, + // 'tests' => false, + // ], + // 'v1/tasks' => [ + // 'name' => 'Tasks', + // 'description' => '', + // 'controller' => 'controllers/api/tasks.php', + // 'sdk' => true, + // 'tests' => false, + // ], + // 'v1/webhooks' => [ + // 'name' => 'Webhooks', + // 'description' => '', + // 'controller' => 'controllers/api/webhooks.php', + // 'sdk' => true, + // 'tests' => false, + // ], 'v1/graphql' => [ 'name' => 'GraphQL', 'description' => 'GraphQL Endpoint', diff --git a/app/views/console/webhooks/index.phtml b/app/views/console/webhooks/index.phtml index 15443e90d2..0318b1b3aa 100644 --- a/app/views/console/webhooks/index.phtml +++ b/app/views/console/webhooks/index.phtml @@ -1,16 +1,25 @@