diff --git a/CHANGES.md b/CHANGES.md index b57ae948b1..c5c78fd024 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +# Version 0.6.0 (PRE-RELEASE) + +## Breaking Changes + +* Updated all the REST API query params to be in camelCase + # Version 0.5.3 (PRE-RELEASE) ## Bug Fixes diff --git a/app/app.php b/app/app.php index 16f8421a7c..3c8c295474 100644 --- a/app/app.php +++ b/app/app.php @@ -3,12 +3,13 @@ // Init require_once __DIR__.'/init.php'; -global $env, $utopia, $request, $response, $register, $consoleDB, $project, $domain, $version, $service, $protocol, $domainVerification; +global $utopia, $request, $response, $register, $consoleDB, $project, $service; use Utopia\App; use Utopia\Request; use Utopia\View; use Utopia\Exception; +use Utopia\Config\Config; use Utopia\Domains\Domain; use Appwrite\Auth\Auth; use Appwrite\Database\Database; @@ -50,7 +51,7 @@ $clients = array_unique(array_merge($clientsConsole, array_map(function ($node) return false; })))); -$utopia->init(function () use ($utopia, $request, $response, &$user, $project, $roles, $webhook, $audit, $usage, $domain, $clients, &$domainVerification) { +$utopia->init(function () use ($utopia, $request, $response, &$user, $project, $roles, $webhook, $audit, $usage, $clients) { $route = $utopia->match($request); @@ -62,10 +63,10 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $ $refDomain = $protocol.'://'.((in_array($origin, $clients)) ? $origin : 'localhost') . (!empty($port) ? ':'.$port : ''); - $selfDomain = new Domain($domain); + $selfDomain = new Domain(Config::getParam('domain')); $endDomain = new Domain($origin); - $domainVerification = ($selfDomain->getRegisterable() === $endDomain->getRegisterable()); + Config::setParam('domainVerification', ($selfDomain->getRegisterable() === $endDomain->getRegisterable())); /* * Security Headers @@ -138,7 +139,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $ $user = new Document([ '$id' => 0, 'status' => Auth::USER_STATUS_ACTIVATED, - 'email' => 'app.'.$project->getId().'@service.'.$domain, + 'email' => 'app.'.$project->getId().'@service.'.Config::getParam('domain'), 'password' => '', 'name' => $project->getAttribute('name', 'Untitled'), ]); @@ -247,7 +248,10 @@ $utopia->options(function () use ($request, $response) { ->send(); }); -$utopia->error(function ($error /* @var $error Exception */) use ($request, $response, $utopia, $project, $env, $version) { +$utopia->error(function ($error /* @var $error Exception */) use ($request, $response, $utopia, $project) { + $env = Config::getParam('env'); + $version = Config::getParam('version'); + switch ($error->getCode()) { case 400: // Error allowed publicly case 401: // Error allowed publicly @@ -401,12 +405,6 @@ $utopia->get('/.well-known/acme-challenge') } ); - - - - - - $name = APP_NAME; if (array_key_exists($service, $services)) { /** @noinspection PhpIncludeInspection */ diff --git a/app/config/collections.php b/app/config/collections.php index 1314db6894..4b23a1edde 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1,9 +1,12 @@ [ '$id' => 'console', @@ -1189,15 +1192,15 @@ $collections = [ /* * Add enabled OAuth2 providers to default data rules */ -foreach ($providers as $key => $provider) { +foreach ($providers as $index => $provider) { if (!$provider['enabled']) { continue; } $collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'][] = [ '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth2 '.ucfirst($key).' ID', - 'key' => 'usersOauth2'.ucfirst($key).'Appid', + 'label' => 'OAuth2 '.ucfirst($index).' ID', + 'key' => 'usersOauth2'.ucfirst($index).'Appid', 'type' => 'text', 'default' => '', 'required' => false, @@ -1206,8 +1209,8 @@ foreach ($providers as $key => $provider) { $collections[Database::SYSTEM_COLLECTION_PROJECTS]['rules'][] = [ '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth2 '.ucfirst($key).' Secret', - 'key' => 'usersOauth2'.ucfirst($key).'Secret', + 'label' => 'OAuth2 '.ucfirst($index).' Secret', + 'key' => 'usersOauth2'.ucfirst($index).'Secret', 'type' => 'text', 'default' => '', 'required' => false, @@ -1216,8 +1219,8 @@ foreach ($providers as $key => $provider) { $collections[Database::SYSTEM_COLLECTION_USERS]['rules'][] = [ '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth2 '.ucfirst($key).' ID', - 'key' => 'oauth2'.ucfirst($key), + 'label' => 'OAuth2 '.ucfirst($index).' ID', + 'key' => 'oauth2'.ucfirst($index), 'type' => 'text', 'default' => '', 'required' => false, @@ -1226,8 +1229,8 @@ foreach ($providers as $key => $provider) { $collections[Database::SYSTEM_COLLECTION_USERS]['rules'][] = [ '$collection' => Database::SYSTEM_COLLECTION_RULES, - 'label' => 'OAuth2 '.ucfirst($key).' Access Token', - 'key' => 'oauth2'.ucfirst($key).'AccessToken', + 'label' => 'OAuth2 '.ucfirst($index).' Access Token', + 'key' => 'oauth2'.ucfirst($index).'AccessToken', 'type' => 'text', 'default' => '', 'required' => false, diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 7c319d296d..1c93c2c396 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1,10 +1,11 @@ init(function() use ($providers, &$oauth2Keys) { - foreach ($providers as $key => $provider) { +$utopia->init(function() use (&$oauth2Keys) { + foreach (Config::getParam('providers') as $key => $provider) { if (!$provider['enabled']) { continue; } @@ -155,7 +156,8 @@ $utopia->post('/v1/account/sessions') ->param('email', '', function () { return new Email(); }, 'User email.') ->param('password', '', function () { return new Password(); }, 'User password.') ->action( - function ($email, $password) use ($response, $request, $projectDB, $audit, $webhook, $protocol, $domainVerification) { + function ($email, $password) use ($response, $request, $projectDB, $audit, $webhook) { + $protocol = Config::getParam('protocol'); $profile = $projectDB->getCollection([ // Get user by email address 'limit' => 1, 'first' => true, @@ -216,7 +218,7 @@ $utopia->post('/v1/account/sessions') ->setParam('resource', 'users/'.$profile->getId()) ; - if(!$domainVerification) { + if(!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', json_encode([Auth::$cookieName => Auth::encodeSession($profile->getId(), $secret)])) ; @@ -244,11 +246,12 @@ $utopia->get('/v1/account/sessions/oauth2/:provider') ->label('sdk.location', true) ->label('abuse-limit', 50) ->label('abuse-key', 'ip:{ip}') - ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth2 Provider. Currently, supported providers are: ' . implode(', ', array_keys(array_filter($providers, function($node) {return (!$node['mock']);}))).'.') + ->param('provider', '', function () { return new WhiteList(array_keys(Config::getParam('providers'))); }, 'OAuth2 Provider. Currently, supported providers are: ' . implode(', ', array_keys(array_filter(Config::getParam('providers'), function($node) {return (!$node['mock']);}))).'.') ->param('success', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a successful login attempt.') ->param('failure', '', function () use ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt.') ->action( - function ($provider, $success, $failure) use ($response, $request, $project, $protocol) { + function ($provider, $success, $failure) use ($response, $request, $project) { + $protocol = Config::getParam('protocol'); $callback = $protocol.'://'.$request->getServer('HTTP_HOST').'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId(); $appId = $project->getAttribute('usersOauth2'.ucfirst($provider).'Appid', ''); $appSecret = $project->getAttribute('usersOauth2'.ucfirst($provider).'Secret', '{}'); @@ -282,11 +285,13 @@ $utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->label('scope', 'public') ->label('docs', false) ->param('projectId', '', function () { return new Text(1024); }, 'Project unique ID.') - ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth2 provider.') + ->param('provider', '', function () { return new WhiteList(array_keys(Config::getParam('providers'))); }, 'OAuth2 provider.') ->param('code', '', function () { return new Text(1024); }, 'OAuth2 code.') ->param('state', '', function () { return new Text(2048); }, 'Login state params.', true) ->action( - function ($projectId, $provider, $code, $state) use ($response, $request, $domain, $protocol) { + function ($projectId, $provider, $code, $state) use ($response) { + $domain = Config::getParam('domain'); + $protocol = Config::getParam('protocol'); $response->redirect($protocol.'://'.$domain.'/v1/account/sessions/oauth2/'.$provider.'/redirect?' .http_build_query(['project' => $projectId, 'code' => $code, 'state' => $state])); } @@ -300,11 +305,12 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect') ->label('abuse-limit', 50) ->label('abuse-key', 'ip:{ip}') ->label('docs', false) - ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'OAuth2 provider.') + ->param('provider', '', function () { return new WhiteList(array_keys(Config::getParam('providers'))); }, 'OAuth2 provider.') ->param('code', '', function () { return new Text(1024); }, 'OAuth2 code.') ->param('state', '', function () { return new Text(2048); }, 'OAuth2 state params.', true) ->action( - function ($provider, $code, $state) use ($response, $request, $user, $projectDB, $project, $audit, $protocol, $domainVerification) { + function ($provider, $code, $state) use ($response, $request, $user, $projectDB, $project, $audit) { + $protocol = Config::getParam('protocol'); $callback = $protocol.'://'.$request->getServer('HTTP_HOST').'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId(); $defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => '']; $validateURL = new URL(); @@ -457,7 +463,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect') ->setParam('data', ['provider' => $provider]) ; - if(!$domainVerification) { + if(!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)])) ; @@ -692,7 +698,7 @@ $utopia->patch('/v1/account/password') ->label('sdk.method', 'updatePassword') ->label('sdk.description', '/docs/references/account/update-password.md') ->param('password', '', function () { return new Password(); }, 'New user password.') - ->param('old-password', '', function () { return new Password(); }, 'Old user password.') + ->param('oldPassword', '', function () { return new Password(); }, 'Old user password.') ->action( function ($password, $oldPassword) use ($response, $user, $projectDB, $audit, $oauth2Keys) { if (!Auth::passwordVerify($oldPassword, $user->getAttribute('password'))) { // Double check user password @@ -832,7 +838,8 @@ $utopia->delete('/v1/account') ->label('sdk.method', 'delete') ->label('sdk.description', '/docs/references/account/delete.md') ->action( - function () use ($response, $user, $projectDB, $audit, $webhook, $protocol, $domainVerification) { + function () use ($response, $user, $projectDB, $audit, $webhook) { + $protocol = Config::getParam('protocol'); $user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [ 'status' => Auth::USER_STATUS_BLOCKED, ])); @@ -863,7 +870,7 @@ $utopia->delete('/v1/account') ]) ; - if(!$domainVerification) { + if(!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', json_encode([])) ; @@ -888,7 +895,8 @@ $utopia->delete('/v1/account/sessions/:sessionId') ->label('abuse-limit', 100) ->param('sessionId', null, function () { return new UID(); }, 'Session unique ID. Use the string \'current\' to delete the current device session.') ->action( - function ($sessionId) use ($response, $user, $projectDB, $webhook, $audit, $protocol, $domainVerification) { + function ($sessionId) use ($response, $user, $projectDB, $webhook, $audit) { + $protocol = Config::getParam('protocol'); $sessionId = ($sessionId === 'current') ? Auth::tokenVerify($user->getAttribute('tokens'), Auth::TOKEN_TYPE_LOGIN, Auth::$secret) : $sessionId; @@ -914,7 +922,7 @@ $utopia->delete('/v1/account/sessions/:sessionId') ]) ; - if(!$domainVerification) { + if(!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', json_encode([])) ; @@ -945,7 +953,8 @@ $utopia->delete('/v1/account/sessions') ->label('sdk.description', '/docs/references/account/delete-sessions.md') ->label('abuse-limit', 100) ->action( - function () use ($response, $user, $projectDB, $audit, $webhook, $protocol, $domainVerification) { + function () use ($response, $user, $projectDB, $audit, $webhook) { + $protocol = Config::getParam('protocol'); $tokens = $user->getAttribute('tokens', []); foreach ($tokens as $token) { /* @var $token Document */ @@ -966,7 +975,7 @@ $utopia->delete('/v1/account/sessions') ]) ; - if(!$domainVerification) { + if(!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', json_encode([])) ; @@ -1087,11 +1096,11 @@ $utopia->put('/v1/account/recovery') ->label('abuse-key', 'url:{url},userId:{param-userId}') ->param('userId', '', function () { return new UID(); }, 'User account UID address.') ->param('secret', '', function () { return new Text(256); }, 'Valid reset token.') - ->param('password-a', '', function () { return new Password(); }, 'New password.') - ->param('password-b', '', function () {return new Password(); }, 'New password again.') + ->param('password', '', function () { return new Password(); }, 'New password.') + ->param('passwordAgain', '', function () {return new Password(); }, 'New password again.') ->action( - function ($userId, $secret, $passwordA, $passwordB) use ($response, $projectDB, $audit) { - if ($passwordA !== $passwordB) { + function ($userId, $secret, $password, $passwordAgain) use ($response, $projectDB, $audit) { + if ($password !== $passwordAgain) { throw new Exception('Passwords must match', 400); } @@ -1117,7 +1126,7 @@ $utopia->put('/v1/account/recovery') Authorization::setRole('user:'.$profile->getId()); $profile = $projectDB->updateDocument(array_merge($profile->getArrayCopy(), [ - 'password' => Auth::passwordHash($passwordA), + 'password' => Auth::passwordHash($password), 'password-update' => time(), 'emailVerification' => true, ])); diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index fb00725c43..6f26f0eea8 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -1,6 +1,6 @@ get('/v1/avatars/favicon') ->label('sdk.method', 'getFavicon') ->label('sdk.description', '/docs/references/avatars/get-favicon.md') ->action( - function ($url) use ($response, $request, $version) { + function ($url) use ($response, $request) { $width = 56; $height = 56; $quality = 80; @@ -238,7 +239,7 @@ $utopia->get('/v1/avatars/favicon') CURLOPT_MAXREDIRS => 3, CURLOPT_URL => $url, CURLOPT_USERAGENT => sprintf(APP_USERAGENT, - $version, + Config::getParam('version'), $request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY) ), ]); diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 00c4db9f72..6f1dc4ec2a 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -391,9 +391,9 @@ $utopia->get('/v1/database/collections/:collectionId/documents') ->param('filters', [], function () { return new ArrayList(new Text(128)); }, 'Array of filter strings. Each filter is constructed from a key name, comparison operator (=, !=, >, <, <=, >=) and a value. You can also use a dot (.) separator in attribute names to filter by child document attributes. Examples: \'name=John Doe\' or \'category.$id>=5bed2d152c362\'.', true) ->param('offset', 0, function () { return new Range(0, 900000000); }, 'Offset value. Use this value to manage pagination.', true) ->param('limit', 50, function () { return new Range(0, 1000); }, 'Maximum number of documents to return in response. Use this value to manage pagination.', true) - ->param('order-field', '$id', function () { return new Text(128); }, 'Document field that results will be sorted by.', true) - ->param('order-type', 'ASC', function () { return new WhiteList(array('DESC', 'ASC')); }, 'Order direction. Possible values are DESC for descending order, or ASC for ascending order.', true) - ->param('order-cast', 'string', function () { return new WhiteList(array('int', 'string', 'date', 'time', 'datetime')); }, 'Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.', true) + ->param('orderField', '$id', function () { return new Text(128); }, 'Document field that results will be sorted by.', true) + ->param('orderType', 'ASC', function () { return new WhiteList(array('DESC', 'ASC')); }, 'Order direction. Possible values are DESC for descending order, or ASC for ascending order.', true) + ->param('orderCast', 'string', function () { return new WhiteList(array('int', 'string', 'date', 'time', 'datetime')); }, 'Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.', true) ->param('search', '', function () { return new Text(256); }, 'Search query. Enter any free text search. The database will try to find a match against all document attributes and children.', true) ->param('first', 0, function () { return new Range(0, 1); }, 'Return only first document. Pass 1 for true or 0 for false. The default value is 0.', true) ->param('last', 0, function () { return new Range(0, 1); }, 'Return only last document. Pass 1 for true or 0 for false. The default value is 0.', true) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 43dbf5877e..fe1fcc386e 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1,6 +1,6 @@ get('/v1/projects') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'list') ->action( - function () use ($request, $response, $providers, $consoleDB) { + function () use ($request, $response, $consoleDB) { $results = $consoleDB->getCollection([ 'limit' => 20, 'offset' => 0, @@ -105,7 +106,7 @@ $utopia->get('/v1/projects') ]); foreach ($results as $project) { - foreach ($providers as $provider => $node) { + foreach (Config::getParam('providers') as $provider => $node) { $secret = json_decode($project->getAttribute('usersOauth2'.ucfirst($provider).'Secret', '{}'), true); if (!empty($secret) && isset($secret['version'])) { @@ -126,14 +127,14 @@ $utopia->get('/v1/projects/:projectId') ->label('sdk.method', 'get') ->param('projectId', '', function () { return new UID(); }, 'Project unique ID.') ->action( - function ($projectId) use ($request, $response, $providers, $consoleDB) { + function ($projectId) use ($request, $response, $consoleDB) { $project = $consoleDB->getDocument($projectId); if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) { throw new Exception('Project not found', 404); } - foreach ($providers as $provider => $node) { + foreach (Config::getParam('providers') as $provider => $node) { $secret = json_decode($project->getAttribute('usersOauth2'.ucfirst($provider).'Secret', '{}'), true); if (!empty($secret) && isset($secret['version'])) { @@ -331,7 +332,7 @@ $utopia->patch('/v1/projects/:projectId/oauth2') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'updateOAuth2') ->param('projectId', '', function () { return new UID(); }, 'Project unique ID.') - ->param('provider', '', function () use ($providers) { return new WhiteList(array_keys($providers)); }, 'Provider Name', false) + ->param('provider', '', function () { return new WhiteList(array_keys(Config::getParam('providers'))); }, 'Provider Name', false) ->param('appId', '', function () { return new Text(256); }, 'Provider app ID.', true) ->param('secret', '', function () { return new text(256); }, 'Provider secret key.', true) ->action( @@ -1201,8 +1202,9 @@ $utopia->post('/v1/projects/:projectId/domains') ->param('projectId', null, function () { return new UID(); }, 'Project unique ID.') ->param('domain', null, function () { return new DomainValidator(); }, 'Domain name.') ->action( - function ($projectId, $domain) use ($request, $response, $consoleDB) { + function ($projectId) use ($request, $response, $consoleDB) { $project = $consoleDB->getDocument($projectId); + $domain = Config::getParam('domain'); if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) { throw new Exception('Project not found', 404); @@ -1283,7 +1285,7 @@ $utopia->get('/v1/projects/:projectId/domains/:domainId') ->param('projectId', null, function () { return new UID(); }, 'Project unique ID.') ->param('domainId', null, function () { return new UID(); }, 'Domain unique ID.') ->action( - function ($projectId, $domainId) use ($request, $response, $consoleDB) { + function ($projectId, $domainId) use ($response, $consoleDB) { $project = $consoleDB->getDocument($projectId); if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) { diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 2f0000beb7..4a84dbf8dd 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -1,6 +1,6 @@ get('/v1/storage/files/:fileId/preview') //->param('storage', 'local', function () {return new WhiteList(array('local'));}, 'Selected storage device. defaults to local') //->param('token', '', function () {return new Text(128);}, 'Preview token', true) ->action( - function ($fileId, $width, $height, $quality, $background, $output) use ($request, $response, $projectDB, $project, $inputs, $outputs, $fileLogos, $version) { + function ($fileId, $width, $height, $quality, $background, $output) use ($request, $response, $projectDB, $project, $inputs, $outputs, $fileLogos) { $storage = 'local'; if (!extension_loaded('imagick')) { @@ -354,7 +354,7 @@ $utopia->get('/v1/storage/files/:fileId/preview') } $date = date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache - $key = md5($version.$fileId.$width.$height.$quality.$background.$storage.$output); + $key = md5($fileId.$width.$height.$quality.$background.$storage.$output); $file = $projectDB->getDocument($fileId); @@ -374,7 +374,7 @@ $utopia->get('/v1/storage/files/:fileId/preview') $cipher = null; $background = (empty($background)) ? 'eceff1' : $background; $type = strtolower(pathinfo($path, PATHINFO_EXTENSION)); - $key = md5($version.$path.$width.$height.$quality.$background.$storage.$output); + $key = md5($path.$width.$height.$quality.$background.$storage.$output); } $compressor = new GZIP(); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index a410bcc9af..ccea694833 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -4,6 +4,7 @@ global $utopia, $register, $request, $response, $projectDB, $project, $user, $au use Utopia\Exception; use Utopia\Response; +use Utopia\Config\Config; use Utopia\Validator\Email; use Utopia\Validator\Text; use Utopia\Validator\Host; @@ -431,7 +432,8 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status') ->param('userId', '', function () { return new UID(); }, 'User unique ID.') ->param('secret', '', function () { return new Text(256); }, 'Secret key.') ->action( - function ($teamId, $inviteId, $userId, $secret) use ($response, $request, $user, $audit, $projectDB, $protocol, $domainVerification) { + function ($teamId, $inviteId, $userId, $secret) use ($response, $request, $user, $audit, $projectDB) { + $protocol = Config::getParam('protocol'); $membership = $projectDB->getDocument($inviteId); if (empty($membership->getId()) || Database::SYSTEM_COLLECTION_MEMBERSHIPS != $membership->getCollection()) { @@ -525,7 +527,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status') ->setParam('resource', 'teams/'.$teamId) ; - if(!$domainVerification) { + if(!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)])) ; diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 7563264ecf..e1153a7af9 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1,6 +1,6 @@ post('/v1/users') ->param('password', '', function () { return new Password(); }, 'User password.') ->param('name', '', function () { return new Text(100); }, 'User name.', true) ->action( - function ($email, $password, $name) use ($response, $register, $projectDB, $providers) { + function ($email, $password, $name) use ($response, $projectDB) { $profile = $projectDB->getCollection([ // Get user by email address 'limit' => 1, 'first' => true, @@ -69,7 +70,7 @@ $utopia->post('/v1/users') $oauth2Keys = []; - foreach ($providers as $key => $provider) { + foreach (Config::getParam('providers') as $key => $provider) { if (!$provider['enabled']) { continue; } @@ -103,7 +104,7 @@ $utopia->get('/v1/users') ->param('offset', 0, function () { return new Range(0, 2000); }, 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', function () { return new WhiteList(['ASC', 'DESC']); }, 'Order result by ASC or DESC order.', true) ->action( - function ($search, $limit, $offset, $orderType) use ($response, $projectDB, $providers) { + function ($search, $limit, $offset, $orderType) use ($response, $projectDB) { $results = $projectDB->getCollection([ 'limit' => $limit, 'offset' => $offset, @@ -118,7 +119,7 @@ $utopia->get('/v1/users') $oauth2Keys = []; - foreach ($providers as $key => $provider) { + foreach (Config::getParam('providers') as $key => $provider) { if (!$provider['enabled']) { continue; } @@ -154,7 +155,7 @@ $utopia->get('/v1/users/:userId') ->label('sdk.description', '/docs/references/users/get-user.md') ->param('userId', '', function () { return new UID(); }, 'User unique ID.') ->action( - function ($userId) use ($response, $projectDB, $providers) { + function ($userId) use ($response, $projectDB) { $user = $projectDB->getDocument($userId); if (empty($user->getId()) || Database::SYSTEM_COLLECTION_USERS != $user->getCollection()) { @@ -163,7 +164,7 @@ $utopia->get('/v1/users/:userId') $oauth2Keys = []; - foreach ($providers as $key => $provider) { + foreach (Config::getParam('providers') as $key => $provider) { if (!$provider['enabled']) { continue; } @@ -352,7 +353,7 @@ $utopia->patch('/v1/users/:userId/status') ->param('userId', '', function () { return new UID(); }, 'User unique ID.') ->param('status', '', function () { return new WhiteList([Auth::USER_STATUS_ACTIVATED, Auth::USER_STATUS_BLOCKED, Auth::USER_STATUS_UNACTIVATED]); }, 'User Status code. To activate the user pass '.Auth::USER_STATUS_ACTIVATED.', to block the user pass '.Auth::USER_STATUS_BLOCKED.' and for disabling the user pass '.Auth::USER_STATUS_UNACTIVATED) ->action( - function ($userId, $status) use ($response, $projectDB, $providers) { + function ($userId, $status) use ($response, $projectDB) { $user = $projectDB->getDocument($userId); if (empty($user->getId()) || Database::SYSTEM_COLLECTION_USERS != $user->getCollection()) { @@ -369,7 +370,7 @@ $utopia->patch('/v1/users/:userId/status') $oauth2Keys = []; - foreach ($providers as $key => $provider) { + foreach (Config::getParam('providers') as $key => $provider) { if (!$provider['enabled']) { continue; } @@ -400,7 +401,7 @@ $utopia->patch('/v1/users/:userId/prefs') ->param('userId', '', function () { return new UID(); }, 'User unique ID.') ->param('prefs', '', function () { return new Assoc();}, 'Prefs key-value JSON object.') ->action( - function ($userId, $prefs) use ($response, $projectDB, $providers) { + function ($userId, $prefs) use ($response, $projectDB) { $user = $projectDB->getDocument($userId); if (empty($user->getId()) || Database::SYSTEM_COLLECTION_USERS != $user->getCollection()) { diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index e2ef34104f..9f148817a2 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -1,10 +1,9 @@ getQuery('version', ''))) { $layout ->setParam('title', APP_NAME) - ->setParam('protocol', $protocol) + ->setParam('protocol', Config::getParam('protocol')) ->setParam('domain', $domain) ->setParam('home', $request->getServer('_APP_HOME')) ->setParam('setup', $request->getServer('_APP_SETUP')) @@ -32,9 +31,9 @@ $layout ->setParam('env', $utopia->getEnv()) ; -$utopia->shutdown(function () use ($utopia, $response, $request, $layout, $version, $env) { +$utopia->shutdown(function () use ($utopia, $response, $request, $layout) { $time = (60 * 60 * 24 * 45); // 45 days cache - $isDev = (\Utopia\App::ENV_TYPE_DEVELOPMENT == $env); + $isDev = (\Utopia\App::ENV_TYPE_DEVELOPMENT == Config::getParam('env')); $response ->addHeader('Cache-Control', 'public, max-age='.$time) @@ -44,7 +43,7 @@ $utopia->shutdown(function () use ($utopia, $response, $request, $layout, $versi $route = $utopia->match($request); $scope = $route->getLabel('scope', ''); $layout - ->setParam('version', $version) + ->setParam('version', Config::getParam('version')) ->setParam('isDev', $isDev) ->setParam('class', $scope) ; diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index 15aa0098a8..5b959e6ed9 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -2,9 +2,10 @@ include_once __DIR__ . '/../shared/web.php'; -global $utopia, $response, $request, $layout, $version, $providers, $projectDB; +global $utopia, $response, $request, $layout, $projectDB; use Utopia\View; +use Utopia\Config\Config; use Utopia\Domains\Domain; use Appwrite\Database\Database; use Appwrite\Database\Validator\UID; @@ -16,25 +17,18 @@ $utopia->init(function () use ($layout, $utopia) { ; }); -$utopia->shutdown(function () use ($utopia, $response, $request, $layout, $version) { +$utopia->shutdown(function () use ($response, $request, $layout) { $header = new View(__DIR__.'/../../views/console/comps/header.phtml'); $footer = new View(__DIR__.'/../../views/console/comps/footer.phtml'); $footer ->setParam('home', $request->getServer('_APP_HOME', '')) - ->setParam('version', $version) + ->setParam('version', Config::getParam('version')) ; $layout ->setParam('header', [$header]) ->setParam('footer', [$footer]) - ->setParam('prefetch', [ - //'/console/database?version=' . $version, - //'/console/storage?version=' . $version, - //'/console/users?version=' . $version, - //'/console/settings?version=' . $version, - //'/console/account?version=' . $version, - ]) ; $response->send($layout->render()); @@ -229,10 +223,10 @@ $utopia->get('/console/users') ->desc('Platform console project settings') ->label('permission', 'public') ->label('scope', 'console') - ->action(function () use ($layout, $providers) { + ->action(function () use ($layout) { $page = new View(__DIR__.'/../../views/console/users/index.phtml'); - $page->setParam('providers', $providers); + $page->setParam('providers', Config::getParam('providers')); $layout ->setParam('title', APP_NAME.' - Users') @@ -243,7 +237,7 @@ $utopia->get('/console/users/view') ->desc('Platform console project user') ->label('permission', 'public') ->label('scope', 'console') - ->action(function () use ($layout, $providers) { + ->action(function () use ($layout) { $page = new View(__DIR__.'/../../views/console/users/view.phtml'); $layout diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index 1a758aac26..c53fff8870 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -2,22 +2,23 @@ include_once __DIR__ . '/../shared/web.php'; -global $utopia, $response, $request, $layout, $version, $providers, $platforms; +global $utopia, $response, $request, $layout; use Utopia\View; +use Utopia\Config\Config; $header = new View(__DIR__.'/../../views/home/comps/header.phtml'); $footer = new View(__DIR__.'/../../views/home/comps/footer.phtml'); $footer - ->setParam('version', $version) + ->setParam('version', Config::getParam('version')) ; $layout ->setParam('title', APP_NAME) ->setParam('description', '') ->setParam('class', 'home') - ->setParam('platforms', $platforms) + ->setParam('platforms', Config::getParam('platforms')) ->setParam('header', [$header]) ->setParam('footer', [$footer]) ; diff --git a/app/init.php b/app/init.php index 6f5586da01..cb89f0dd7e 100644 --- a/app/init.php +++ b/app/init.php @@ -14,6 +14,7 @@ if (file_exists(__DIR__.'/../vendor/autoload.php')) { use Utopia\App; use Utopia\Request; use Utopia\Response; +use Utopia\Config\Config; use Utopia\Locale\Locale; use Utopia\Registry\Registry; use Appwrite\Auth\Auth; @@ -52,30 +53,31 @@ $response = new Response(); /* * ENV vars */ -$env = $request->getServer('_APP_ENV', App::ENV_TYPE_PRODUCTION); -$domain = $request->getServer('HTTP_HOST', ''); -$domainVerification = false; -$version = $request->getServer('_APP_VERSION', 'UNKNOWN'); -$providers = include __DIR__.'/../app/config/providers.php'; // OAuth2 providers list -$platforms = include __DIR__.'/../app/config/platforms.php'; -$locales = include __DIR__.'/../app/config/locales.php'; // Locales list -$collections = include __DIR__.'/../app/config/collections.php'; // Collections list -$redisHost = $request->getServer('_APP_REDIS_HOST', ''); -$redisPort = $request->getServer('_APP_REDIS_PORT', ''); -$utopia = new App('Asia/Tel_Aviv', $env); -$protocol = $request->getServer('HTTP_X_FORWARDED_PROTO', $request->getServer('REQUEST_SCHEME', 'https')); -$port = (string) parse_url($protocol.'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_PORT); +Config::load('providers', __DIR__.'/../app/config/providers.php'); +Config::load('platforms', __DIR__.'/../app/config/platforms.php'); +Config::load('locales', __DIR__.'/../app/config/locales.php'); +Config::load('collections', __DIR__.'/../app/config/collections.php'); -Resque::setBackend($redisHost.':'.$redisPort); +Config::setParam('env', $request->getServer('_APP_ENV', App::ENV_TYPE_PRODUCTION)); +Config::setParam('domain', $request->getServer('HTTP_HOST', '')); +Config::setParam('domainVerification', false); +Config::setParam('version', $request->getServer('_APP_VERSION', 'UNKNOWN')); +Config::setParam('protocol', $request->getServer('HTTP_X_FORWARDED_PROTO', $request->getServer('REQUEST_SCHEME', 'https'))); +Config::setParam('port', (string) parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_PORT)); + +$utopia = new App('Asia/Tel_Aviv', Config::getParam('env')); + +Resque::setBackend($request->getServer('_APP_REDIS_HOST', '') + .':'.$request->getServer('_APP_REDIS_PORT', '')); define('COOKIE_DOMAIN', ( $request->getServer('HTTP_HOST', null) === 'localhost' || - $request->getServer('HTTP_HOST', null) === 'localhost:'.$port || + $request->getServer('HTTP_HOST', null) === 'localhost:'.Config::getParam('port') || (filter_var($request->getServer('HTTP_HOST', null), FILTER_VALIDATE_IP) !== false) ) ? null - : '.'.parse_url($protocol.'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_HOST)); + : '.'.parse_url(Config::getParam('protocol').'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_HOST)); define('COOKIE_SAMESITE', Response::COOKIE_SAMESITE_NONE); /* @@ -119,10 +121,11 @@ $register->set('statsd', function () use ($request) { // Register DB connection return $statsd; }); -$register->set('cache', function () use ($redisHost, $redisPort) { // Register cache connection +$register->set('cache', function () use ($request) { // Register cache connection $redis = new Redis(); - $redis->connect($redisHost, $redisPort); + $redis->connect($request->getServer('_APP_REDIS_HOST', ''), + $request->getServer('_APP_REDIS_PORT', '')); return $redis; }); @@ -209,7 +212,7 @@ Locale::setLanguage('zh-tw', include __DIR__.'/config/locales/zh-tw.php'); Locale::setDefault('en'); -if (in_array($locale, $locales)) { +if (in_array($locale, Config::getParam('locales'))) { Locale::setDefault($locale); } @@ -217,7 +220,7 @@ stream_context_set_default([ // Set global user agent and http settings 'http' => [ 'method' => 'GET', 'user_agent' => sprintf(APP_USERAGENT, - $version, + Config::getParam('version'), $request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)), 'timeout' => 2, ], @@ -229,8 +232,8 @@ stream_context_set_default([ // Set global user agent and http settings $consoleDB = new Database(); $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $consoleDB->setNamespace('app_console'); // Should be replaced with param if we want to have parent projects -$consoleDB->setMocks($collections); +$consoleDB->setMocks(Config::getParam('collections', [])); Authorization::disable(); $project = $consoleDB->getDocument($request->getParam('project', $request->getHeader('X-Appwrite-Project', null))); @@ -268,7 +271,7 @@ Auth::$secret = $session['secret']; $projectDB = new Database(); $projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $projectDB->setNamespace('app_'.$project->getId()); -$projectDB->setMocks($collections); +$projectDB->setMocks(Config::getParam('collections', [])); $user = $projectDB->getDocument(Auth::$unique); diff --git a/app/tasks/sdks.php b/app/tasks/sdks.php index eef7452f74..334e92a934 100644 --- a/app/tasks/sdks.php +++ b/app/tasks/sdks.php @@ -4,6 +4,7 @@ require_once __DIR__.'/../../vendor/autoload.php'; require_once __DIR__.'/../../app/init.php'; +use Utopia\Config\Config; use Utopia\CLI\CLI; use Utopia\CLI\Console; use Appwrite\Spec\Swagger2; @@ -15,6 +16,7 @@ use Appwrite\SDK\Language\Python; use Appwrite\SDK\Language\Ruby; use Appwrite\SDK\Language\Dart; use Appwrite\SDK\Language\Go; +use Appwrite\SDK\Language\Typescript; $cli = new CLI(); @@ -38,7 +40,7 @@ $cli return $result; } - $platforms = include __DIR__ . '/../config/platforms.php'; + $platforms = Config::getParam('platforms'); $message = Console::confirm('Please enter your commit message:'); $production = (Console::confirm('Type "Appwrite" to deploy for production') == 'Appwrite'); @@ -88,6 +90,13 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ->setBowerPackage('appwrite') ; break; + case 'typescript': + $config = new Typescript(); + $config + ->setNPMPackage('appwrite') + ->setBowerPackage('appwrite') + ; + break; case 'nodejs': $config = new Node(); $config diff --git a/app/tasks/upgrade.php b/app/tasks/upgrade.php index 80c3b96b9b..c2a8723f99 100644 --- a/app/tasks/upgrade.php +++ b/app/tasks/upgrade.php @@ -3,8 +3,9 @@ require_once __DIR__.'/../init.php'; -global $register, $projectDB, $console, $providers, $request; +global $register, $projectDB, $console, $request; +use Utopia\Config\Config; use Utopia\CLI\CLI; use Utopia\CLI\Console; use Appwrite\Database\Database; @@ -93,7 +94,7 @@ $callbacks = [ ]; function fixDocument(Document $document) { - global $providers; + $providers = Config::getParam('providers'); if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_PROJECTS){ foreach($providers as $key => $provider) { diff --git a/app/views/console/storage/index.phtml b/app/views/console/storage/index.phtml index b386eaddb3..0014863cd7 100644 --- a/app/views/console/storage/index.phtml +++ b/app/views/console/storage/index.phtml @@ -60,7 +60,7 @@ $fileLimitHuman = $this->getParam('fileLimitHuman', 0); data-param-search="{{router.params.search}}" data-param-limit="" data-param-offset="" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-files" data-success="state" @@ -81,7 +81,7 @@ $fileLimitHuman = $this->getParam('fileLimitHuman', 0); data-param-search="{{router.params.search}}" data-param-limit="" data-param-offset="{{router.params.offset}}" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-files"> @@ -210,7 +210,7 @@ $fileLimitHuman = $this->getParam('fileLimitHuman', 0); data-event="submit" data-param-search="{{router.params.search}}" data-param-limit="" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-files" data-success="state" @@ -225,7 +225,7 @@ $fileLimitHuman = $this->getParam('fileLimitHuman', 0); data-event="submit" data-param-search="{{router.params.search}}" data-param-limit="" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-files" data-success="state" diff --git a/app/views/console/users/index.phtml b/app/views/console/users/index.phtml index 7a846fff95..18b20b59d4 100644 --- a/app/views/console/users/index.phtml +++ b/app/views/console/users/index.phtml @@ -56,7 +56,7 @@ $providers = $this->getParam('providers', []); data-param-search="{{router.params.search}}" data-param-limit="" data-param-offset="" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-users" data-success="state" @@ -77,7 +77,7 @@ $providers = $this->getParam('providers', []); data-param-search="{{router.params.search}}" data-param-limit="" data-param-offset="{{router.params.offset}}" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-users"> @@ -141,7 +141,7 @@ $providers = $this->getParam('providers', []); data-event="submit" data-param-search="{{router.params.search}}" data-param-limit="" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-users" data-success="state" @@ -156,7 +156,7 @@ $providers = $this->getParam('providers', []); data-event="submit" data-param-search="{{router.params.search}}" data-param-limit="" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-users" data-success="state" @@ -203,7 +203,7 @@ $providers = $this->getParam('providers', []); data-param-search="{{router.params.search}}" data-param-limit="" data-param-offset="" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-teams" data-success="state" @@ -224,7 +224,7 @@ $providers = $this->getParam('providers', []); data-param-search="{{router.params.search}}" data-param-limit="" data-param-offset="{{router.params.offset}}" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-teams"> @@ -298,7 +298,7 @@ $providers = $this->getParam('providers', []); data-event="submit" data-param-search="{{router.params.search}}" data-param-limit="" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-teams" data-success="state" @@ -313,7 +313,7 @@ $providers = $this->getParam('providers', []); data-event="submit" data-param-search="{{router.params.search}}" data-param-limit="" - data-param-order-type="DESC" + data-param-orderType="DESC" data-scope="sdk" data-name="project-teams" data-success="state" diff --git a/app/views/home/auth/recovery/reset.phtml b/app/views/home/auth/recovery/reset.phtml index 2ee1e23954..581447ec10 100644 --- a/app/views/home/auth/recovery/reset.phtml +++ b/app/views/home/auth/recovery/reset.phtml @@ -26,10 +26,10 @@ - + - + diff --git a/app/workers/certificates.php b/app/workers/certificates.php index c087a59e34..73a59ca17a 100644 --- a/app/workers/certificates.php +++ b/app/workers/certificates.php @@ -1,6 +1,7 @@ getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY) )); curl_setopt( diff --git a/app/workers/usage.php b/app/workers/usage.php index 18e7d50422..e5f6733611 100644 --- a/app/workers/usage.php +++ b/app/workers/usage.php @@ -1,5 +1,7 @@ args['projectId']; $method = $this->args['method']; @@ -29,7 +31,7 @@ class UsageV1 $statsd = $register->get('statsd', true); - $tags = ",project={$projectId},version=".$version.''; + $tags = ",project={$projectId},version=".Config::getParam('version').''; // the global namespace is prepended to every key (optional) $statsd->setNamespace('appwrite.usage'); diff --git a/app/workers/webhooks.php b/app/workers/webhooks.php index 1eb0ec7289..e7c6157a8f 100644 --- a/app/workers/webhooks.php +++ b/app/workers/webhooks.php @@ -6,6 +6,7 @@ cli_set_process_title('Webhooks V1 Worker'); echo APP_NAME.' webhooks worker v1 has started'; +use Utopia\Config\Config; use Appwrite\Database\Database; use Appwrite\Database\Validator\Authorization; @@ -19,7 +20,7 @@ class WebhooksV1 public function perform() { - global $consoleDB, $version, $request; + global $consoleDB, $request; $errors = []; @@ -59,7 +60,7 @@ class WebhooksV1 curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, sprintf(APP_USERAGENT, - $version, + Config::getParam('version'), $request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY) )); curl_setopt( diff --git a/composer.json b/composer.json index 4adc670cfe..5b158063e7 100644 --- a/composer.json +++ b/composer.json @@ -37,6 +37,7 @@ "utopia-php/audit": "0.2.*", "utopia-php/cache": "0.2.*", "utopia-php/cli": "0.4.*", + "utopia-php/config": "0.2.*", "utopia-php/locale": "0.2.*", "utopia-php/registry": "0.2.*", "utopia-php/domains": "0.2.*", diff --git a/composer.lock b/composer.lock index bcb28b4ceb..62b26899d7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "54701e5067d9b94ae765f3f0e560b531", + "content-hash": "d19ba7d1c39970839f6f191664e9498d", "packages": [ { "name": "appwrite/php-clamav", @@ -1381,6 +1381,52 @@ ], "time": "2020-03-25T04:46:43+00:00" }, + { + "name": "utopia-php/config", + "version": "0.2.0", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/config.git", + "reference": "f1f41d3863eb00bd2837b45c2e17e8b5da1cf46d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/config/zipball/f1f41d3863eb00bd2837b45c2e17e8b5da1cf46d", + "reference": "f1f41d3863eb00bd2837b45c2e17e8b5da1cf46d", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\Config\\": "src/Config" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Eldad Fux", + "email": "eldad@appwrite.io" + } + ], + "description": "A simple Config library to managing application config variables", + "keywords": [ + "config", + "framework", + "php", + "upf", + "utopia" + ], + "time": "2020-03-28T10:24:18+00:00" + }, { "name": "utopia-php/domains", "version": "0.2.0", @@ -1576,7 +1622,7 @@ "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator", - "reference": "dccb6830aca1681dc4c3730652c1b7636e25fe9e" + "reference": "97cb12c9c187a42a545060c324b0960c99582893" }, "require": { "ext-curl": "*", @@ -1606,7 +1652,7 @@ } ], "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", - "time": "2020-03-26T07:14:16+00:00" + "time": "2020-03-27T15:12:28+00:00" }, { "name": "doctrine/instantiator", @@ -3206,12 +3252,12 @@ "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "27af7d9cd1b77fcb13b4ed452c291d9defad088b" + "reference": "6df2e2c3181e6d0b961fc341fbe8269fefc933c6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/27af7d9cd1b77fcb13b4ed452c291d9defad088b", - "reference": "27af7d9cd1b77fcb13b4ed452c291d9defad088b", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/6df2e2c3181e6d0b961fc341fbe8269fefc933c6", + "reference": "6df2e2c3181e6d0b961fc341fbe8269fefc933c6", "shasum": "" }, "require": { @@ -3263,7 +3309,7 @@ "keywords": [ "templating" ], - "time": "2020-03-24T12:35:30+00:00" + "time": "2020-03-27T16:41:01+00:00" }, { "name": "webmozart/assert", diff --git a/public/dist/scripts/app-all.js b/public/dist/scripts/app-all.js index 5e78213b31..7968e91bfa 100644 --- a/public/dist/scripts/app-all.js +++ b/public/dist/scripts/app-all.js @@ -33,21 +33,21 @@ let path='/account/name';let payload={};if(name){payload['name']=name;} return http.patch(path,{'content-type':'application/json',},payload);},updatePassword:function(password,oldPassword){if(password===undefined){throw new Error('Missing required parameter: "password"');} if(oldPassword===undefined){throw new Error('Missing required parameter: "oldPassword"');} let path='/account/password';let payload={};if(password){payload['password']=password;} -if(oldPassword){payload['old-password']=oldPassword;} +if(oldPassword){payload['oldPassword']=oldPassword;} return http.patch(path,{'content-type':'application/json',},payload);},getPrefs:function(){let path='/account/prefs';let payload={};return http.get(path,{'content-type':'application/json',},payload);},updatePrefs:function(prefs){if(prefs===undefined){throw new Error('Missing required parameter: "prefs"');} let path='/account/prefs';let payload={};if(prefs){payload['prefs']=prefs;} return http.patch(path,{'content-type':'application/json',},payload);},createRecovery:function(email,url){if(email===undefined){throw new Error('Missing required parameter: "email"');} if(url===undefined){throw new Error('Missing required parameter: "url"');} let path='/account/recovery';let payload={};if(email){payload['email']=email;} if(url){payload['url']=url;} -return http.post(path,{'content-type':'application/json',},payload);},updateRecovery:function(userId,secret,passwordA,passwordB){if(userId===undefined){throw new Error('Missing required parameter: "userId"');} +return http.post(path,{'content-type':'application/json',},payload);},updateRecovery:function(userId,secret,password,passwordAgain){if(userId===undefined){throw new Error('Missing required parameter: "userId"');} if(secret===undefined){throw new Error('Missing required parameter: "secret"');} -if(passwordA===undefined){throw new Error('Missing required parameter: "passwordA"');} -if(passwordB===undefined){throw new Error('Missing required parameter: "passwordB"');} +if(password===undefined){throw new Error('Missing required parameter: "password"');} +if(passwordAgain===undefined){throw new Error('Missing required parameter: "passwordAgain"');} let path='/account/recovery';let payload={};if(userId){payload['userId']=userId;} if(secret){payload['secret']=secret;} -if(passwordA){payload['password-a']=passwordA;} -if(passwordB){payload['password-b']=passwordB;} +if(password){payload['password']=password;} +if(passwordAgain){payload['passwordAgain']=passwordAgain;} return http.put(path,{'content-type':'application/json',},payload);},getSessions:function(){let path='/account/sessions';let payload={};return http.get(path,{'content-type':'application/json',},payload);},createSession:function(email,password){if(email===undefined){throw new Error('Missing required parameter: "email"');} if(password===undefined){throw new Error('Missing required parameter: "password"');} let path='/account/sessions';let payload={};if(email){payload['email']=email;} @@ -113,9 +113,9 @@ let path='/database/collections/{collectionId}'.replace(new RegExp('{collectionI let path='/database/collections/{collectionId}/documents'.replace(new RegExp('{collectionId}','g'),collectionId);let payload={};if(filters){payload['filters']=filters;} if(offset){payload['offset']=offset;} if(limit){payload['limit']=limit;} -if(orderField){payload['order-field']=orderField;} -if(orderType){payload['order-type']=orderType;} -if(orderCast){payload['order-cast']=orderCast;} +if(orderField){payload['orderField']=orderField;} +if(orderType){payload['orderType']=orderType;} +if(orderCast){payload['orderCast']=orderCast;} if(search){payload['search']=search;} if(first){payload['first']=first;} if(last){payload['last']=last;} diff --git a/public/dist/scripts/app-dep.js b/public/dist/scripts/app-dep.js index 79b84a8a00..415984bee6 100644 --- a/public/dist/scripts/app-dep.js +++ b/public/dist/scripts/app-dep.js @@ -33,21 +33,21 @@ let path='/account/name';let payload={};if(name){payload['name']=name;} return http.patch(path,{'content-type':'application/json',},payload);},updatePassword:function(password,oldPassword){if(password===undefined){throw new Error('Missing required parameter: "password"');} if(oldPassword===undefined){throw new Error('Missing required parameter: "oldPassword"');} let path='/account/password';let payload={};if(password){payload['password']=password;} -if(oldPassword){payload['old-password']=oldPassword;} +if(oldPassword){payload['oldPassword']=oldPassword;} return http.patch(path,{'content-type':'application/json',},payload);},getPrefs:function(){let path='/account/prefs';let payload={};return http.get(path,{'content-type':'application/json',},payload);},updatePrefs:function(prefs){if(prefs===undefined){throw new Error('Missing required parameter: "prefs"');} let path='/account/prefs';let payload={};if(prefs){payload['prefs']=prefs;} return http.patch(path,{'content-type':'application/json',},payload);},createRecovery:function(email,url){if(email===undefined){throw new Error('Missing required parameter: "email"');} if(url===undefined){throw new Error('Missing required parameter: "url"');} let path='/account/recovery';let payload={};if(email){payload['email']=email;} if(url){payload['url']=url;} -return http.post(path,{'content-type':'application/json',},payload);},updateRecovery:function(userId,secret,passwordA,passwordB){if(userId===undefined){throw new Error('Missing required parameter: "userId"');} +return http.post(path,{'content-type':'application/json',},payload);},updateRecovery:function(userId,secret,password,passwordAgain){if(userId===undefined){throw new Error('Missing required parameter: "userId"');} if(secret===undefined){throw new Error('Missing required parameter: "secret"');} -if(passwordA===undefined){throw new Error('Missing required parameter: "passwordA"');} -if(passwordB===undefined){throw new Error('Missing required parameter: "passwordB"');} +if(password===undefined){throw new Error('Missing required parameter: "password"');} +if(passwordAgain===undefined){throw new Error('Missing required parameter: "passwordAgain"');} let path='/account/recovery';let payload={};if(userId){payload['userId']=userId;} if(secret){payload['secret']=secret;} -if(passwordA){payload['password-a']=passwordA;} -if(passwordB){payload['password-b']=passwordB;} +if(password){payload['password']=password;} +if(passwordAgain){payload['passwordAgain']=passwordAgain;} return http.put(path,{'content-type':'application/json',},payload);},getSessions:function(){let path='/account/sessions';let payload={};return http.get(path,{'content-type':'application/json',},payload);},createSession:function(email,password){if(email===undefined){throw new Error('Missing required parameter: "email"');} if(password===undefined){throw new Error('Missing required parameter: "password"');} let path='/account/sessions';let payload={};if(email){payload['email']=email;} @@ -113,9 +113,9 @@ let path='/database/collections/{collectionId}'.replace(new RegExp('{collectionI let path='/database/collections/{collectionId}/documents'.replace(new RegExp('{collectionId}','g'),collectionId);let payload={};if(filters){payload['filters']=filters;} if(offset){payload['offset']=offset;} if(limit){payload['limit']=limit;} -if(orderField){payload['order-field']=orderField;} -if(orderType){payload['order-type']=orderType;} -if(orderCast){payload['order-cast']=orderCast;} +if(orderField){payload['orderField']=orderField;} +if(orderType){payload['orderType']=orderType;} +if(orderCast){payload['orderCast']=orderCast;} if(search){payload['search']=search;} if(first){payload['first']=first;} if(last){payload['last']=last;} diff --git a/public/scripts/dependencies/appwrite.js b/public/scripts/dependencies/appwrite.js index f707b7f779..c0b210dad9 100644 --- a/public/scripts/dependencies/appwrite.js +++ b/public/scripts/dependencies/appwrite.js @@ -516,7 +516,7 @@ } if(oldPassword) { - payload['old-password'] = oldPassword; + payload['oldPassword'] = oldPassword; } return http @@ -630,12 +630,12 @@ * * @param {string} userId * @param {string} secret - * @param {string} passwordA - * @param {string} passwordB + * @param {string} password + * @param {string} passwordAgain * @throws {Error} * @return {Promise} */ - updateRecovery: function(userId, secret, passwordA, passwordB) { + updateRecovery: function(userId, secret, password, passwordAgain) { if(userId === undefined) { throw new Error('Missing required parameter: "userId"'); } @@ -644,12 +644,12 @@ throw new Error('Missing required parameter: "secret"'); } - if(passwordA === undefined) { - throw new Error('Missing required parameter: "passwordA"'); + if(password === undefined) { + throw new Error('Missing required parameter: "password"'); } - if(passwordB === undefined) { - throw new Error('Missing required parameter: "passwordB"'); + if(passwordAgain === undefined) { + throw new Error('Missing required parameter: "passwordAgain"'); } let path = '/account/recovery'; @@ -664,12 +664,12 @@ payload['secret'] = secret; } - if(passwordA) { - payload['password-a'] = passwordA; + if(password) { + payload['password'] = password; } - if(passwordB) { - payload['password-b'] = passwordB; + if(passwordAgain) { + payload['passwordAgain'] = passwordAgain; } return http @@ -1401,15 +1401,15 @@ } if(orderField) { - payload['order-field'] = orderField; + payload['orderField'] = orderField; } if(orderType) { - payload['order-type'] = orderType; + payload['orderType'] = orderType; } if(orderCast) { - payload['order-cast'] = orderCast; + payload['orderCast'] = orderCast; } if(search) { diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index bb9b3d8d60..0bd7a1a661 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -449,7 +449,7 @@ trait AccountBase 'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session, ]), [ 'password' => 'new-password', - 'old-password' => $password, + 'oldPassword' => $password, ]); $this->assertEquals($response['headers']['status-code'], 200); @@ -1019,8 +1019,8 @@ trait AccountBase ]), [ 'userId' => $id, 'secret' => $recovery, - 'password-a' => $newPassowrd, - 'password-b' => $newPassowrd, + 'password' => $newPassowrd, + 'passwordAgain' => $newPassowrd, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -1035,8 +1035,8 @@ trait AccountBase ]), [ 'userId' => 'ewewe', 'secret' => $recovery, - 'password-a' => $newPassowrd, - 'password-b' => $newPassowrd, + 'password' => $newPassowrd, + 'passwordAgain' => $newPassowrd, ]); $this->assertEquals(404, $response['headers']['status-code']); @@ -1048,8 +1048,8 @@ trait AccountBase ]), [ 'userId' => $id, 'secret' => 'sdasdasdasd', - 'password-a' => $newPassowrd, - 'password-b' => $newPassowrd, + 'password' => $newPassowrd, + 'passwordAgain' => $newPassowrd, ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -1061,8 +1061,8 @@ trait AccountBase ]), [ 'userId' => $id, 'secret' => $recovery, - 'password-a' => $newPassowrd.'x', - 'password-b' => $newPassowrd, + 'password' => $newPassowrd.'x', + 'passwordAgain' => $newPassowrd, ]); $this->assertEquals(400, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Database/DatabaseBase.php b/tests/e2e/Services/Database/DatabaseBase.php index 15ffb19014..60dc1f81cc 100644 --- a/tests/e2e/Services/Database/DatabaseBase.php +++ b/tests/e2e/Services/Database/DatabaseBase.php @@ -254,9 +254,9 @@ trait DatabaseBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', + 'orderField' => 'releaseYear', + 'orderType' => 'ASC', + 'orderCast' => 'int', ]); $this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']); @@ -268,9 +268,9 @@ trait DatabaseBase 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'order-field' => 'releaseYear', - 'order-type' => 'DESC', - 'order-cast' => 'int', + 'orderField' => 'releaseYear', + 'orderType' => 'DESC', + 'orderCast' => 'int', ]); $this->assertEquals(1944, $documents['body']['documents'][2]['releaseYear']); @@ -291,9 +291,9 @@ trait DatabaseBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'limit' => 1, - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', + 'orderField' => 'releaseYear', + 'orderType' => 'ASC', + 'orderCast' => 'int', ]); $this->assertEquals(1944, $documents['body']['documents'][0]['releaseYear']); @@ -305,9 +305,9 @@ trait DatabaseBase ], $this->getHeaders()), [ 'limit' => 2, 'offset' => 1, - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', + 'orderField' => 'releaseYear', + 'orderType' => 'ASC', + 'orderCast' => 'int', ]); $this->assertEquals(2017, $documents['body']['documents'][0]['releaseYear']); @@ -327,9 +327,9 @@ trait DatabaseBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'limit' => 1, - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', + 'orderField' => 'releaseYear', + 'orderType' => 'ASC', + 'orderCast' => 'int', 'first' => true, ]); @@ -341,9 +341,9 @@ trait DatabaseBase ], $this->getHeaders()), [ 'limit' => 2, 'offset' => 1, - 'order-field' => 'releaseYear', - 'order-type' => 'ASC', - 'order-cast' => 'int', + 'orderField' => 'releaseYear', + 'orderType' => 'ASC', + 'orderCast' => 'int', 'last' => true, ]);