diff --git a/CHANGES.md b/CHANGES.md index 51239015fd..b7277908d0 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -23,6 +23,9 @@ * Added ENV vars to change system email sender name and address * Usage for requests made by project admin in the console are not counted as API usage * Added ENV var to change default file upload size limit. New default value is 100MB +* Added option to delete file directly from the dashboard +* Added option to view file preview from the dashboard +* Added option to add custom domains with auto SSL certificate generator ## Bug Fixes diff --git a/Dockerfile b/Dockerfile index 3d2adff509..84638b219e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,6 +46,8 @@ ENV TZ=Asia/Tel_Aviv \ DEBIAN_FRONTEND=noninteractive \ PHP_VERSION=7.4 \ _APP_ENV=production \ + _APP_DOMAIN=localhost \ + _APP_DOMAIN_TARGET=localhost \ _APP_HOME=https://appwrite.io \ _APP_EDITION=community \ _APP_OPTIONS_ABUSE=enabled \ @@ -99,8 +101,12 @@ RUN \ rm -rf /var/lib/apt/lists/* # Set Upload Limit (default to 100MB) -RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" > /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini -RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" > /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini +RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini +RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini +RUN echo "env[TESTME] = your-secret-key" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini + +# Add logs file +RUN echo "" >> /var/log/appwrite.log # Nginx Configuration (with self-signed ssl certificates) COPY ./docker/nginx.conf /etc/nginx/nginx.conf @@ -128,6 +134,9 @@ COPY ./docker/supervisord.conf /etc/supervisord.conf COPY ./docker/entrypoint.sh /entrypoint.sh RUN chmod 775 /entrypoint.sh +# Letsencrypt Permissions +RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ + EXPOSE 80 WORKDIR /usr/share/nginx/html diff --git a/app/app.php b/app/app.php index 089598edcf..8a15b78f41 100644 --- a/app/app.php +++ b/app/app.php @@ -3,7 +3,7 @@ // Init require_once __DIR__.'/init.php'; -global $env, $utopia, $request, $response, $register, $consoleDB, $project, $domain, $version, $service; +global $env, $utopia, $request, $response, $register, $consoleDB, $project, $domain, $version, $service, $protocol; use Utopia\App; use Utopia\Request; @@ -76,6 +76,7 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $ ->addHeader('X-Content-Type-Options', 'nosniff') ->addHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE') ->addHeader('Access-Control-Allow-Headers', 'Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-SDK-Version') + ->addHeader('Access-Control-Expose-Headers', 'X-Fallback-Cookies') ->addHeader('Access-Control-Allow-Origin', $refDomain) ->addHeader('Access-Control-Allow-Credentials', 'true') ; @@ -234,7 +235,8 @@ $utopia->options(function () use ($request, $response, $domain, $project) { $response ->addHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE') - ->addHeader('Access-Control-Allow-Headers', 'Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-SDK-Version') + ->addHeader('Access-Control-Allow-Headers', 'Origin, Cookie, Set-Cookie, X-Requested-With, Content-Type, Access-Control-Allow-Origin, Access-Control-Request-Headers, Accept, X-Appwrite-Project, X-Appwrite-Key, X-Appwrite-Locale, X-Appwrite-Mode, X-SDK-Version, X-Fallback-Cookies') + ->addHeader('Access-Control-Expose-Headers', 'X-Fallback-Cookies') ->addHeader('Access-Control-Allow-Origin', $origin) ->addHeader('Access-Control-Allow-Credentials', 'true') ->send(); @@ -364,39 +366,37 @@ $utopia->get('/.well-known/acme-challenge') ->label('docs', false) ->action( function () use ($request, $response) { - $base = realpath(__DIR__.'/../certs'); + $base = realpath(APP_STORAGE_CERTIFICATES); $path = str_replace('/.well-known/acme-challenge/', '', $request->getParam('q')); - $absolute = realpath($base.'/'.$path); - + $absolute = realpath($base.'/.well-known/acme-challenge/'.$path); + + if(!$base) { + throw new Exception('Storage error', 500); + } + if(!$absolute) { - //throw new Exception('Unknown Path', 404); - $response->json([ - 'error' => 'unknown path', - 'base' => scandir($base), - 'base/well' => scandir($base . '/.well-known/'), - 'base/well/acme' => scandir($base . '/.well-known/acme-challenge/'), - 'base/well/acme/query' => ($absolute) ? scandir($absolute) : ['not-a-dir'], - ]); - return; + throw new Exception('Unknown path', 404); } if(!substr($absolute, 0, strlen($base)) === $base) { - //throw new Exception('Invalid Path', 401); - $response->json([ - 'error' => 'invalid path', - 'base' => scandir($base), - 'base/well' => scandir($base . '/.well-known/'), - 'base/well/acme' => scandir($base . '/.well-known/acme-challenge/'), - 'base/well/acme/query' => ($absolute) ? scandir($absolute) : ['not-a-dir'], - ]); - return; + throw new Exception('Invalid path', 401); } - $response->text(file_get_contents($absolute)); + if(!file_exists($absolute)) { + throw new Exception('Unknown path', 404); + } + + $content = @file_get_contents($absolute); + + if(!$content) { + throw new Exception('Failed to get contents', 500); + } + + $response->text($content); } ); -$utopia->get('/v1/info') // This is only visible to gods +$utopia->get('/v1/info') // This is only visible to the gods ->label('scope', 'god') ->label('docs', false) ->action( @@ -453,7 +453,7 @@ $utopia->get('/v1/open-api-2.json') ->param('extensions', 0, function () {return new Range(0, 1);}, 'Show extra data.', true) ->param('tests', 0, function () {return new Range(0, 1);}, 'Include only test services.', true) ->action( - function ($platform, $extensions, $tests) use ($response, $request, $utopia, $domain, $services) { + function ($platform, $extensions, $tests) use ($response, $request, $utopia, $domain, $services, $protocol) { function fromCamelCase($input) { preg_match_all('!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $input, $matches); @@ -588,7 +588,7 @@ $utopia->get('/v1/open-api-2.json') ], 'externalDocs' => [ 'description' => 'Full API docs, specs and tutorials', - 'url' => $request->getServer('REQUEST_SCHEME', 'https').'://'.$domain.'/docs', + 'url' => $protocol.'://'.$domain.'/docs', ], ]; diff --git a/app/config/collections.php b/app/config/collections.php index 45ad9a3a5b..cd3353d1a2 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -606,6 +606,16 @@ $collections = [ 'array' => true, 'list' => [Database::SYSTEM_COLLECTION_PLATFORMS], ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Domains', + 'key' => 'domains', + 'type' => 'document', + 'default' => [], + 'required' => false, + 'array' => true, + 'list' => [Database::SYSTEM_COLLECTION_DOMAINS], + ], ], ], Database::SYSTEM_COLLECTION_WEBHOOKS => [ @@ -931,6 +941,123 @@ $collections = [ ], ], ], + Database::SYSTEM_COLLECTION_DOMAINS => [ + '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, + '$id' => Database::SYSTEM_COLLECTION_DOMAINS, + '$permissions' => ['read' => ['*']], + 'name' => 'Domains', + 'structure' => true, + 'rules' => [ + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Domain', + 'key' => 'domain', + 'type' => 'text', + 'default' => null, + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Updated', + 'key' => 'updated', + 'type' => 'numeric', + 'default' => 0, + 'required' => false, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Top Level Domain', + 'key' => 'tld', + 'type' => 'text', + 'default' => '', + 'required' => false, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Registerable Domain', + 'key' => 'registerable', + 'type' => 'text', + 'default' => '', + 'required' => false, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Verification', + 'key' => 'verification', + 'type' => 'boolean', + 'default' => false, + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Certificate ID', + 'key' => 'certificateId', + 'type' => 'key', + 'default' => '', + 'required' => false, + 'array' => false, + ], + ], + ], + Database::SYSTEM_COLLECTION_CERTIFICATES => [ + '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, + '$id' => Database::SYSTEM_COLLECTION_CERTIFICATES, + '$permissions' => ['read' => ['*']], + 'name' => 'Certificates', + 'structure' => true, + 'rules' => [ + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Domain', + 'key' => 'domain', + 'type' => 'text', + 'default' => null, + 'required' => true, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Issue Date', + 'key' => 'issueDate', + 'type' => 'numeric', + 'default' => 0, + 'required' => false, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Renew Date', + 'key' => 'renewDate', + 'type' => 'numeric', + 'default' => 0, + 'required' => false, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Attempts', + 'key' => 'attempts', + 'type' => 'numeric', + 'default' => 0, + 'required' => false, + 'array' => false, + ], + [ + '$collection' => Database::SYSTEM_COLLECTION_RULES, + 'label' => 'Log', + 'key' => 'log', + 'type' => 'text', + 'default' => '', + 'required' => false, + 'array' => false, + ], + ], + ], Database::SYSTEM_COLLECTION_FILES => [ '$collection' => Database::SYSTEM_COLLECTION_COLLECTIONS, '$id' => Database::SYSTEM_COLLECTION_FILES, @@ -1126,4 +1253,4 @@ foreach ($providers as $key => $provider) { ]; } -return $collections; +return $collections; \ No newline at end of file diff --git a/app/config/files/excel.png b/app/config/files/excel.png new file mode 100644 index 0000000000..ebf1a7cd99 Binary files /dev/null and b/app/config/files/excel.png differ diff --git a/app/config/files/none.png b/app/config/files/none.png new file mode 100644 index 0000000000..003ae49b53 Binary files /dev/null and b/app/config/files/none.png differ diff --git a/app/config/files/pdf.png b/app/config/files/pdf.png new file mode 100644 index 0000000000..8bbc791d18 Binary files /dev/null and b/app/config/files/pdf.png differ diff --git a/app/config/files/ppt.png b/app/config/files/ppt.png new file mode 100644 index 0000000000..4db13644d3 Binary files /dev/null and b/app/config/files/ppt.png differ diff --git a/app/config/files/video.png b/app/config/files/video.png new file mode 100644 index 0000000000..8cb7519f1b Binary files /dev/null and b/app/config/files/video.png differ diff --git a/app/config/files/word.png b/app/config/files/word.png new file mode 100644 index 0000000000..4b13f18f91 Binary files /dev/null and b/app/config/files/word.png differ diff --git a/app/config/platforms.php b/app/config/platforms.php index 25a21f2ac7..e4d10a20db 100644 --- a/app/config/platforms.php +++ b/app/config/platforms.php @@ -27,7 +27,7 @@ return [ 'beta' => false, 'family' => APP_PLATFORM_CLIENT, 'prism' => 'javascript', - 'source' => realpath(__DIR__ . '/../sdks/javascript'), + 'source' => realpath(__DIR__ . '/../sdks/web-javascript'), 'gitUrl' => 'git@github.com:appwrite/sdk-for-js.git', 'gitRepoName' => 'sdk-for-js', 'gitUserName' => 'appwrite', @@ -136,7 +136,7 @@ return [ 'beta' => true, 'family' => APP_PLATFORM_CLIENT, 'prism' => 'dart', - 'source' => realpath(__DIR__ . '/../sdks/dart'), + 'source' => realpath(__DIR__ . '/../sdks/flutter-dart'), 'gitUrl' => 'git@github.com:appwrite/sdk-for-dart.git', 'gitRepoName' => 'sdk-for-dart', 'gitUserName' => 'appwrite', @@ -144,27 +144,28 @@ return [ ], ], - // APP_PLATFORM_CONSOLE => [ - // 'name' => 'Console', - // 'enabled' => false, - // 'beta' => false, - // 'languages' => [ - // [ - // 'key' => 'javascript', - // 'name' => 'JS', - // 'version' => '1.0.0', - // 'url' => 'https://github.com/appwrite/sdk-for-console', - // 'enabled' => true, - // 'beta' => false, - // 'family' => APP_PLATFORM_CONSOLE, - // 'prism' => 'console', - // 'source' => realpath(__DIR__ . '/../sdks/console'), - // 'gitUrl' => 'git@github.com:appwrite/sdk-for-console.git', - // 'gitRepoName' => 'sdk-for-console', - // 'gitUserName' => 'appwrite', - // ], - // ], - // ], + APP_PLATFORM_CONSOLE => [ + 'key' => APP_PLATFORM_CONSOLE, + 'name' => 'Console', + 'enabled' => false, + 'beta' => false, + 'languages' => [ + [ + 'key' => 'javascript', + 'name' => 'JS', + 'version' => '1.0.0', + 'url' => 'https://github.com/appwrite/sdk-for-console', + 'enabled' => true, + 'beta' => false, + 'family' => APP_PLATFORM_CONSOLE, + 'prism' => 'console', + 'source' => realpath(__DIR__ . '/../sdks/console-javascript'), + 'gitUrl' => null, + 'gitRepoName' => 'sdk-for-console', + 'gitUserName' => 'appwrite', + ], + ], + ], APP_PLATFORM_SERVER => [ 'key' => APP_PLATFORM_SERVER, @@ -182,7 +183,7 @@ return [ 'beta' => false, 'family' => APP_PLATFORM_SERVER, 'prism' => 'javascript', - 'source' => realpath(__DIR__ . '/../sdks/nodejs'), + 'source' => realpath(__DIR__ . '/../sdks/server-nodejs'), 'gitUrl' => 'git@github.com:appwrite/sdk-for-node.git', 'gitRepoName' => 'sdk-for-node', 'gitUserName' => 'appwrite', @@ -196,7 +197,7 @@ return [ 'beta' => false, 'family' => APP_PLATFORM_SERVER, 'prism' => 'php', - 'source' => realpath(__DIR__ . '/../sdks/php'), + 'source' => realpath(__DIR__ . '/../sdks/server-php'), 'gitUrl' => 'git@github.com:appwrite/sdk-for-php.git', 'gitRepoName' => 'sdk-for-php', 'gitUserName' => 'appwrite', @@ -210,7 +211,7 @@ return [ 'beta' => true, 'family' => APP_PLATFORM_SERVER, 'prism' => 'python', - 'source' => realpath(__DIR__ . '/../sdks/python'), + 'source' => realpath(__DIR__ . '/../sdks/server-python'), 'gitUrl' => 'git@github.com:appwrite/sdk-for-python.git', 'gitRepoName' => 'sdk-for-python', 'gitUserName' => 'appwrite', @@ -224,7 +225,7 @@ return [ 'beta' => true, 'family' => APP_PLATFORM_SERVER, 'prism' => 'ruby', - 'source' => realpath(__DIR__ . '/../sdks/ruby'), + 'source' => realpath(__DIR__ . '/../sdks/server-ruby'), 'gitUrl' => 'git@github.com:appwrite/sdk-for-ruby.git', 'gitRepoName' => 'sdk-for-ruby', 'gitUserName' => 'appwrite', @@ -238,7 +239,7 @@ return [ 'beta' => true, 'family' => APP_PLATFORM_SERVER, 'prism' => 'go', - 'source' => realpath(__DIR__ . '/../sdks/go'), + 'source' => realpath(__DIR__ . '/../sdks/server-go'), 'gitUrl' => 'git@github.com:appwrite/sdk-for-go.git', 'gitRepoName' => 'sdk-for-go', 'gitUserName' => 'appwrite', diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 19d3d9fff3..fea9cefcb9 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1,7 +1,7 @@ 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) { + function ($email, $password) use ($response, $request, $projectDB, $audit, $webhook, $protocol) { $profile = $projectDB->getCollection([ // Get user by email address 'limit' => 1, 'first' => true, @@ -212,8 +212,9 @@ $utopia->post('/v1/account/sessions') ; $response - ->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($profile->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, null) - ->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, COOKIE_SAMESITE) + ->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($profile->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE) + ->addHeader('X-Fallback-Cookies', json_encode([Auth::$cookieName => Auth::encodeSession($profile->getId(), $secret)])) ->setStatusCode(Response::STATUS_CODE_CREATED) ->json($session->getArrayCopy(['$id', 'type', 'expire'])) ; @@ -237,8 +238,8 @@ $utopia->get('/v1/account/sessions/oauth2/:provider') ->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) { - $callback = $request->getServer('REQUEST_SCHEME', 'https').'://'.$request->getServer('HTTP_HOST').'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId(); + function ($provider, $success, $failure) use ($response, $request, $project, $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', '{}'); @@ -275,8 +276,8 @@ $utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->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) { - $response->redirect($request->getServer('REQUEST_SCHEME', 'https').'://'.$domain.'/v1/account/sessions/oauth2/'.$provider.'/redirect?' + function ($projectId, $provider, $code, $state) use ($response, $request, $domain, $protocol) { + $response->redirect($protocol.'://'.$domain.'/v1/account/sessions/oauth2/'.$provider.'/redirect?' .http_build_query(['project' => $projectId, 'code' => $code, 'state' => $state])); } ); @@ -293,8 +294,8 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect') ->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) { - $callback = $request->getServer('REQUEST_SCHEME', 'https').'://'.$request->getServer('HTTP_HOST').'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId(); + function ($provider, $code, $state) use ($response, $request, $user, $projectDB, $project, $audit, $protocol) { + $callback = $protocol.'://'.$request->getServer('HTTP_HOST').'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId(); $defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => '']; $validateURL = new URL(); @@ -443,8 +444,9 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect') ; $response - ->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, null) - ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, COOKIE_SAMESITE) + ->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE) + ->addHeader('X-Fallback-Cookies', json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)])) ->redirect($state['success']) ; } @@ -810,7 +812,7 @@ $utopia->delete('/v1/account') ->label('sdk.method', 'delete') ->label('sdk.description', '/docs/references/account/delete.md') ->action( - function () use ($response, $request, $user, $projectDB, $audit, $webhook) { + function () use ($response, $user, $projectDB, $audit, $webhook, $protocol) { $user = $projectDB->updateDocument(array_merge($user->getArrayCopy(), [ 'status' => Auth::USER_STATUS_BLOCKED, ])); @@ -842,8 +844,9 @@ $utopia->delete('/v1/account') ; $response - ->addCookie(Auth::$cookieName.'_legacy', '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, null) - ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, COOKIE_SAMESITE) + ->addCookie(Auth::$cookieName.'_legacy', '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE) + ->addHeader('X-Fallback-Cookies', json_encode([])) ->noContent() ; } @@ -860,7 +863,7 @@ $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, $request, $user, $projectDB, $webhook, $audit) { + function ($sessionId) use ($response, $user, $projectDB, $webhook, $audit, $protocol) { $sessionId = ($sessionId === 'current') ? Auth::tokenVerify($user->getAttribute('tokens'), Auth::TOKEN_TYPE_LOGIN, Auth::$secret) : $sessionId; @@ -888,8 +891,9 @@ $utopia->delete('/v1/account/sessions/:sessionId') if ($token->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too $response - ->addCookie(Auth::$cookieName.'_legacy', '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, null) - ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, COOKIE_SAMESITE) + ->addCookie(Auth::$cookieName.'_legacy', '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE) + ->addHeader('X-Fallback-Cookies', json_encode([])) ; } @@ -911,7 +915,7 @@ $utopia->delete('/v1/account/sessions') ->label('sdk.description', '/docs/references/account/delete-sessions.md') ->label('abuse-limit', 100) ->action( - function () use ($response, $request, $user, $projectDB, $audit, $webhook) { + function () use ($response, $user, $projectDB, $audit, $webhook, $protocol) { $tokens = $user->getAttribute('tokens', []); foreach ($tokens as $token) { /* @var $token Document */ @@ -934,8 +938,9 @@ $utopia->delete('/v1/account/sessions') if ($token->getAttribute('secret') == Auth::hash(Auth::$secret)) { // If current session delete the cookies too $response - ->addCookie(Auth::$cookieName.'_legacy', '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, null) - ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, COOKIE_SAMESITE) + ->addCookie(Auth::$cookieName.'_legacy', '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, '', time() - 3600, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE) + ->addHeader('X-Fallback-Cookies', json_encode([])) ; } } diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 90c0000f20..675a871731 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -49,7 +49,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types throw new Exception('File not readable in '.$path, 500); } - $cache = new Cache(new Filesystem('/storage/cache/app-0')); // Limit file number or size + $cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-0')); // Limit file number or size $data = $cache->load($key, 60 * 60 * 24 * 30 * 3 /* 3 months */); if ($data) { @@ -146,7 +146,7 @@ $utopia->get('/v1/avatars/image') $date = date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache $key = md5('/v2/avatars/images-'.$url.'-'.$width.'/'.$height.'/'.$quality); $type = 'png'; - $cache = new Cache(new Filesystem('/storage/cache/app-0')); // Limit file number or size + $cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-0')); // Limit file number or size $data = $cache->load($key, 60 * 60 * 24 * 7 /* 1 week */); if ($data) { @@ -206,7 +206,7 @@ $utopia->get('/v1/avatars/favicon') ->label('sdk.method', 'getFavicon') ->label('sdk.description', '/docs/references/avatars/get-favicon.md') ->action( - function ($url) use ($response, $version) { + function ($url) use ($response, $request, $version) { $width = 56; $height = 56; $quality = 80; @@ -214,7 +214,7 @@ $utopia->get('/v1/avatars/favicon') $date = date('D, d M Y H:i:s', time() + (60 * 60 * 24 * 45)).' GMT'; // 45 days cache $key = md5('/v2/avatars/favicon-'.$url); $type = 'png'; - $cache = new Cache(new Filesystem('/storage/cache/app-0')); // Limit file number or size + $cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-0')); // Limit file number or size $data = $cache->load($key, 60 * 60 * 24 * 30 * 3 /* 3 months */); if ($data) { @@ -237,7 +237,10 @@ $utopia->get('/v1/avatars/favicon') CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 3, CURLOPT_URL => $url, - CURLOPT_USERAGENT => sprintf(APP_USERAGENT, $version), + CURLOPT_USERAGENT => sprintf(APP_USERAGENT, + $version, + $request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY) + ), ]); $html = curl_exec($curl); diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index ad1beef9a4..b5f239046c 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -119,7 +119,7 @@ $utopia->get('/v1/health/storage/local') ->label('docs', false) ->action( function () use ($response) { - $device = new Local('/storage/uploads/'); + $device = new Local(APP_STORAGE_UPLOADS.'/'); if (!is_readable($device->getRoot().'/..')) { throw new Exception('Device is not readable'); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index f7cfb77399..1625e9fc25 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -6,16 +6,19 @@ use Auth\Auth; use Utopia\Exception; use Utopia\Response; use Utopia\Validator\ArrayList; +use Utopia\Validator\Domain as DomainValidator; use Utopia\Validator\Text; use Utopia\Validator\WhiteList; use Utopia\Validator\Range; use Utopia\Validator\URL; +use Utopia\Domains\Domain; use Task\Validator\Cron; use Database\Database; use Database\Document; use Database\Validator\UID; use OpenSSL\OpenSSL; use Cron\CronExpression; +use Network\Validators\CNAME; include_once __DIR__ . '/../shared/api.php'; @@ -515,7 +518,7 @@ $utopia->get('/v1/projects/:projectId/webhooks/:webhookId') $webhook = $project->search('$id', $webhookId, $project->getAttribute('webhooks', [])); - if (empty($webhook) && $webhook instanceof Document) { + if (empty($webhook) || !$webhook instanceof Document) { throw new Exception('Webhook not found', 404); } @@ -565,7 +568,7 @@ $utopia->put('/v1/projects/:projectId/webhooks/:webhookId') $webhook = $project->search('$id', $webhookId, $project->getAttribute('webhooks', [])); - if (empty($webhook) && $webhook instanceof Document) { + if (empty($webhook) || !$webhook instanceof Document) { throw new Exception('Webhook not found', 404); } @@ -603,7 +606,7 @@ $utopia->delete('/v1/projects/:projectId/webhooks/:webhookId') $webhook = $project->search('$id', $webhookId, $project->getAttribute('webhooks', [])); - if (empty($webhook) && $webhook instanceof Document) { + if (empty($webhook) || !$webhook instanceof Document) { throw new Exception('Webhook not found', 404); } @@ -698,7 +701,7 @@ $utopia->get('/v1/projects/:projectId/keys/:keyId') $key = $project->search('$id', $keyId, $project->getAttribute('keys', [])); - if (empty($key) && $key instanceof Document) { + if (empty($key) || !$key instanceof Document) { throw new Exception('Key not found', 404); } @@ -725,7 +728,7 @@ $utopia->put('/v1/projects/:projectId/keys/:keyId') $key = $project->search('$id', $keyId, $project->getAttribute('keys', [])); - if (empty($key) && $key instanceof Document) { + if (empty($key) || !$key instanceof Document) { throw new Exception('Key not found', 404); } @@ -759,7 +762,7 @@ $utopia->delete('/v1/projects/:projectId/keys/:keyId') $key = $project->search('$id', $keyId, $project->getAttribute('keys', [])); - if (empty($key) && $key instanceof Document) { + if (empty($key) || !$key instanceof Document) { throw new Exception('Key not found', 404); } @@ -904,7 +907,7 @@ $utopia->get('/v1/projects/:projectId/tasks/:taskId') $task = $project->search('$id', $taskId, $project->getAttribute('tasks', [])); - if (empty($task) && $task instanceof Document) { + if (empty($task) || !$task instanceof Document) { throw new Exception('Task not found', 404); } @@ -945,7 +948,7 @@ $utopia->put('/v1/projects/:projectId/tasks/:taskId') $task = $project->search('$id', $taskId, $project->getAttribute('tasks', [])); - if (empty($task) && $task instanceof Document) { + if (empty($task) || !$task instanceof Document) { throw new Exception('Task not found', 404); } @@ -1006,7 +1009,7 @@ $utopia->delete('/v1/projects/:projectId/tasks/:taskId') $task = $project->search('$id', $taskId, $project->getAttribute('tasks', [])); - if (empty($task) && $task instanceof Document) { + if (empty($task) || !$task instanceof Document) { throw new Exception('Task not found', 404); } @@ -1110,7 +1113,7 @@ $utopia->get('/v1/projects/:projectId/platforms/:platformId') $platform = $project->search('$id', $platformId, $project->getAttribute('platforms', [])); - if (empty($platform) && $platform instanceof Document) { + if (empty($platform) || !$platform instanceof Document) { throw new Exception('Platform not found', 404); } @@ -1139,7 +1142,7 @@ $utopia->put('/v1/projects/:projectId/platforms/:platformId') $platform = $project->search('$id', $platformId, $project->getAttribute('platforms', [])); - if (empty($platform) && $platform instanceof Document) { + if (empty($platform) || !$platform instanceof Document) { throw new Exception('Platform not found', 404); } @@ -1176,7 +1179,7 @@ $utopia->delete('/v1/projects/:projectId/platforms/:platformId') $platform = $project->search('$id', $platformId, $project->getAttribute('platforms', [])); - if (empty($platform) && $platform instanceof Document) { + if (empty($platform) || !$platform instanceof Document) { throw new Exception('Platform not found', 404); } @@ -1186,4 +1189,218 @@ $utopia->delete('/v1/projects/:projectId/platforms/:platformId') $response->noContent(); } + ); + +// Domains + +$utopia->post('/v1/projects/:projectId/domains') + ->desc('Create Domain') + ->label('scope', 'projects.write') + ->label('sdk.namespace', 'projects') + ->label('sdk.method', 'createDomain') + ->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) { + $project = $consoleDB->getDocument($projectId); + + if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) { + throw new Exception('Project not found', 404); + } + + $document = $project->search('domain', $domain, $project->getAttribute('domains', [])); + + if (!empty($document)) { + throw new Exception('Domain already exists', 409); + } + + $target = new Domain($request->getServer('_APP_DOMAIN_TARGET', '')); + + if(!$target->isKnown() || $target->isTest()) { + throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500); + } + + $domain = new Domain($domain); + + $domain = $consoleDB->createDocument([ + '$collection' => Database::SYSTEM_COLLECTION_DOMAINS, + '$permissions' => [ + 'read' => ['team:'.$project->getAttribute('teamId', null)], + 'write' => ['team:'.$project->getAttribute('teamId', null).'/owner', 'team:'.$project->getAttribute('teamId', null).'/developer'], + ], + 'updated' => time(), + 'domain' => $domain->get(), + 'tld' => $domain->getSuffix(), + 'registerable' => $domain->getRegisterable(), + 'verification' => false, + 'certificateId' => null, + ]); + + if (false === $domain) { + throw new Exception('Failed saving domain to DB', 500); + } + + $project->setAttribute('domains', $domain, Document::SET_TYPE_APPEND); + + $project = $consoleDB->updateDocument($project->getArrayCopy()); + + if (false === $project) { + throw new Exception('Failed saving project to DB', 500); + } + + $response + ->setStatusCode(Response::STATUS_CODE_CREATED) + ->json($domain->getArrayCopy()) + ; + } + ); + +$utopia->get('/v1/projects/:projectId/domains') + ->desc('List Domains') + ->label('scope', 'projects.read') + ->label('sdk.namespace', 'projects') + ->label('sdk.method', 'listDomains') + ->param('projectId', '', function () { return new UID(); }, 'Project unique ID.') + ->action( + function ($projectId) use ($response, $consoleDB) { + $project = $consoleDB->getDocument($projectId); + + if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) { + throw new Exception('Project not found', 404); + } + + $domains = $project->getAttribute('domains', []); + + $response->json($domains); + } + ); + +$utopia->get('/v1/projects/:projectId/domains/:domainId') + ->desc('Get Domain') + ->label('scope', 'projects.read') + ->label('sdk.namespace', 'projects') + ->label('sdk.method', 'getDomain') + ->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) { + $project = $consoleDB->getDocument($projectId); + + if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) { + throw new Exception('Project not found', 404); + } + + $domain = $project->search('$id', $domainId, $project->getAttribute('domains', [])); + + if (empty($domain) || !$domain instanceof Document) { + throw new Exception('Domain not found', 404); + } + + $response->json($domain->getArrayCopy()); + } + ); + +$utopia->patch('/v1/projects/:projectId/domains/:domainId/verification') + ->desc('Update Domain Verification Status') + ->label('scope', 'projects.write') + ->label('sdk.namespace', 'projects') + ->label('sdk.method', 'updateDomainVerification') + ->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) { + $project = $consoleDB->getDocument($projectId); + + if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) { + throw new Exception('Project not found', 404); + } + + $domain = $project->search('$id', $domainId, $project->getAttribute('domains', [])); + + if (empty($domain) || !$domain instanceof Document) { + throw new Exception('Domain not found', 404); + } + + $target = new Domain($request->getServer('_APP_DOMAIN_TARGET', '')); + + if(!$target->isKnown() || $target->isTest()) { + throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500); + } + + if($domain->getAttribute('verification') === true) { + return $response->json($domain->getArrayCopy()); + } + + // Verify Domain with DNS records + $validator = new CNAME($target->get()); + + if(!$validator->isValid($domain->getAttribute('domain', ''))) { + throw new Exception('Failed to verify domain', 401); + } + + $domain + ->setAttribute('verification', true) + ; + + if (false === $consoleDB->updateDocument($domain->getArrayCopy())) { + throw new Exception('Failed saving domains to DB', 500); + } + + // Issue a TLS certificate when domain is verified + Resque::enqueue('v1-certificates', 'CertificatesV1', [ + 'document' => $domain->getArrayCopy(), + 'domain' => $domain->getAttribute('domain'), + ]); + + $response->json($domain->getArrayCopy()); + } + ); + +$utopia->delete('/v1/projects/:projectId/domains/:domainId') + ->desc('Delete Domain') + ->label('scope', 'projects.write') + ->label('sdk.namespace', 'projects') + ->label('sdk.method', 'deleteDomain') + ->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 ($response, $consoleDB) { + $project = $consoleDB->getDocument($projectId); + + if (empty($project->getId()) || Database::SYSTEM_COLLECTION_PROJECTS != $project->getCollection()) { + throw new Exception('Project not found', 404); + } + + $domain = $project->search('$id', $domainId, $project->getAttribute('domains', [])); + + if (empty($domain) || !$domain instanceof Document) { + throw new Exception('Domain not found', 404); + } + + if (!$consoleDB->deleteDocument($domain->getId())) { + throw new Exception('Failed to remove domains from DB', 500); + } + + $response->noContent(); + } + ); + + + +$utopia->get('/v1/projects/x/certs') + ->desc('List Domains') + ->label('scope', 'public') + ->action( + function () use ($response, $consoleDB) { + \Database\Validator\Authorization::disable(); + $results = $consoleDB->getCollection([ + 'limit' => 2000, + 'offset' => 0, + 'filters' => [ + '$collection='.Database::SYSTEM_COLLECTION_USERS, + ], + ]); + \Database\Validator\Authorization::reset(); + $response->json($results); + } ); \ No newline at end of file diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 5ded8df37a..c74b9412c2 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -1,6 +1,6 @@ getId())); +Storage::addDevice('local', new Local(APP_STORAGE_UPLOADS.'/app-'.$project->getId())); $fileLogos = [ // Based on this list @see http://stackoverflow.com/a/4212908/2299554 - 'default' => 'default.gif', + 'default' => __DIR__.'/../../config/files/none.png', + + // Video Files + 'video/mp4' => __DIR__.'/../../config/files/video.png', + 'video/x-flv' => __DIR__.'/../../config/files/video.png', + 'application/x-mpegURL' => __DIR__.'/../../config/files/video.png', + 'video/MP2T' => __DIR__.'/../../config/files/video.png', + 'video/3gpp' => __DIR__.'/../../config/files/video.png', + 'video/quicktime' => __DIR__.'/../../config/files/video.png', + 'video/x-msvideo' => __DIR__.'/../../config/files/video.png', + 'video/x-ms-wmv' => __DIR__.'/../../config/files/video.png', - // Microsoft Word - 'application/msword' => 'word.gif', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'word.gif', - 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'word.gif', - 'application/vnd.ms-word.document.macroEnabled.12' => 'word.gif', + // // Microsoft Word + 'application/msword' => __DIR__.'/../../config/files/word.png', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => __DIR__.'/../../config/files/word.png', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => __DIR__.'/../../config/files/word.png', + 'application/vnd.ms-word.document.macroEnabled.12' => __DIR__.'/../../config/files/word.png', - // Microsoft Excel - 'application/vnd.ms-excel' => 'excel.gif', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'excel.gif', - 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'excel.gif', - 'application/vnd.ms-excel.sheet.macroEnabled.12' => 'excel.gif', - 'application/vnd.ms-excel.template.macroEnabled.12' => 'excel.gif', - 'application/vnd.ms-excel.addin.macroEnabled.12' => 'excel.gif', - 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'excel.gif', + // // Microsoft Excel + 'application/vnd.ms-excel' => __DIR__.'/../../config/files/excel.png', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => __DIR__.'/../../config/files/excel.png', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => __DIR__.'/../../config/files/excel.png', + 'application/vnd.ms-excel.sheet.macroEnabled.12' => __DIR__.'/../../config/files/excel.png', + 'application/vnd.ms-excel.template.macroEnabled.12' => __DIR__.'/../../config/files/excel.png', + 'application/vnd.ms-excel.addin.macroEnabled.12' => __DIR__.'/../../config/files/excel.png', + 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => __DIR__.'/../../config/files/excel.png', - // Microsoft Power Point - 'application/vnd.ms-powerpoint' => 'powerpoint.gif', - 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'powerpoint.gif', - 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'powerpoint.gif', - 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'powerpoint.gif', - 'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'powerpoint.gif', - 'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'powerpoint.gif', - 'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'powerpoint.gif', - 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'powerpoint.gif', - - // Microsoft Access - 'application/vnd.ms-access' => 'access.gif', + // // Microsoft Power Point + 'application/vnd.ms-powerpoint' => __DIR__.'/../../config/files/ppt.png', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => __DIR__.'/../../config/files/ppt.png', + 'application/vnd.openxmlformats-officedocument.presentationml.template' => __DIR__.'/../../config/files/ppt.png', + 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => __DIR__.'/../../config/files/ppt.png', + 'application/vnd.ms-powerpoint.addin.macroEnabled.12' => __DIR__.'/../../config/files/ppt.png', + 'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => __DIR__.'/../../config/files/ppt.png', + 'application/vnd.ms-powerpoint.template.macroEnabled.12' => __DIR__.'/../../config/files/ppt.png', + 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => __DIR__.'/../../config/files/ppt.png', // Adobe PDF - 'application/pdf' => 'pdf.gif', + 'application/pdf' => __DIR__.'/../../config/files/pdf.png', ]; $inputs = [ @@ -84,6 +91,16 @@ $mimes = [ 'image/png', 'image/webp', + // Video Files + 'video/mp4', + 'video/x-flv', + 'application/x-mpegURL', + 'video/MP2T', + 'video/3gpp', + 'video/quicktime', + 'video/x-msvideo', + 'video/x-ms-wmv', + // Microsoft Word 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', @@ -321,7 +338,7 @@ $utopia->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) { + function ($fileId, $width, $height, $quality, $background, $output) use ($request, $response, $projectDB, $project, $inputs, $outputs, $fileLogos, $version) { $storage = 'local'; if (!extension_loaded('imagick')) { @@ -337,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($fileId.$width.$height.$quality.$background.$storage.$output); + $key = md5($version.$fileId.$width.$height.$quality.$background.$storage.$output); $file = $projectDB->getDocument($fileId); @@ -346,18 +363,28 @@ $utopia->get('/v1/storage/files/:fileId/preview') } $path = $file->getAttribute('path'); - $algorithm = $file->getAttribute('algorithm'); $type = strtolower(pathinfo($path, PATHINFO_EXTENSION)); + $algorithm = $file->getAttribute('algorithm'); $cipher = $file->getAttribute('fileOpenSSLCipher'); + $mime = $file->getAttribute('mimeType'); + + if(!in_array($mime, $inputs)) { + $path = (array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default']; + $algorithm = null; + $cipher = null; + $background = (empty($background)) ? 'eceff1' : $background; + $type = strtolower(pathinfo($path, PATHINFO_EXTENSION)); + $key = md5($version.$path.$width.$height.$quality.$background.$storage.$output); + } $compressor = new GZIP(); $device = Storage::getDevice('local'); if (!file_exists($path)) { - throw new Exception('File not found in '.$path, 404); + throw new Exception('File not found', 404); } - $cache = new Cache(new Filesystem('/storage/cache/app-'.$project->getId())); // Limit file number or size + $cache = new Cache(new Filesystem(APP_STORAGE_CACHE.'/app-'.$project->getId())); // Limit file number or size $data = $cache->load($key, 60 * 60 * 24 * 30 * 3 /* 3 months */); if ($data) { diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index d14e9fb046..0897f74148 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -426,7 +426,7 @@ $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) { + function ($teamId, $inviteId, $userId, $secret) use ($response, $request, $user, $audit, $projectDB, $protocol) { $membership = $projectDB->getDocument($inviteId); if (empty($membership->getId()) || Database::SYSTEM_COLLECTION_MEMBERSHIPS != $membership->getCollection()) { @@ -521,8 +521,9 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status') ; $response - ->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, null) - ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $request->getServer('REQUEST_SCHEME', 'https')), true, COOKIE_SAMESITE) + ->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null) + ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE) + ->addHeader('X-Fallback-Cookies', json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)])) ->json(array_merge($membership->getArrayCopy([ '$id', 'userId', diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 2f1535b662..6b63bb53ad 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -321,7 +321,7 @@ $utopia->get('/v1/mock/tests/general/oauth2/failure') $utopia->shutdown(function() use ($response, $request, &$result, $utopia) { $route = $utopia->match($request); - $path = '/storage/cache/tests.json'; + $path = APP_STORAGE_CACHE.'/tests.json'; $tests = (file_exists($path)) ? json_decode(file_get_contents($path), true) : []; if(!is_array($tests)) { diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index e23dc4f9c3..e2ef34104f 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -3,6 +3,8 @@ use Utopia\View; use Utopia\Locale\Locale; +global $protocol; + Locale::$exceptions = false; $roles = [ @@ -20,7 +22,7 @@ if (!empty($request->getQuery('version', ''))) { $layout ->setParam('title', APP_NAME) - ->setParam('protocol', $request->getServer('REQUEST_SCHEME', 'https')) + ->setParam('protocol', $protocol) ->setParam('domain', $domain) ->setParam('home', $request->getServer('_APP_HOME')) ->setParam('setup', $request->getServer('_APP_SETUP')) diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index 39ccaa930b..47c19ea8ea 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -5,6 +5,7 @@ include_once __DIR__ . '/../shared/web.php'; global $utopia, $response, $request, $layout, $version, $providers, $projectDB; use Utopia\View; +use Utopia\Domains\Domain; use Database\Database; use Database\Validator\UID; use Storage\Storage; @@ -116,9 +117,16 @@ $utopia->get('/console/settings') ->desc('Platform console project settings') ->label('permission', 'public') ->label('scope', 'console') - ->action(function () use ($layout) { + ->action(function () use ($request, $layout) { + $target = new Domain($request->getServer('_APP_DOMAIN_TARGET', '')); + $page = new View(__DIR__.'/../../views/console/settings/index.phtml'); + $page + ->setParam('customDomainsEnabled', ($target->isKnown() && !$target->isTest())) + ->setParam('customDomainsTarget', $target->get()) + ; + $layout ->setParam('title', APP_NAME.' - Settings') ->setParam('body', $page); diff --git a/app/init.php b/app/init.php index 6a6b830321..56d9051b9f 100644 --- a/app/init.php +++ b/app/init.php @@ -20,12 +20,24 @@ use PHPMailer\PHPMailer\PHPMailer; const APP_NAME = 'Appwrite'; const APP_DOMAIN = 'appwrite.io'; -const APP_EMAIL_TEAM = 'team@'.APP_DOMAIN; -const APP_EMAIL_SECURITY = 'security@'.APP_DOMAIN; -const APP_USERAGENT = APP_NAME.'-Server/%s Please report abuse at '.APP_EMAIL_SECURITY; +const APP_EMAIL_TEAM = 'team@localhost.test'; // Default email address +const APP_EMAIL_SECURITY = 'security@localhost.test'; // Default security email address +const APP_USERAGENT = APP_NAME.'-Server v%s. Please report abuse at %s'; const APP_MODE_ADMIN = 'admin'; const APP_PAGING_LIMIT = 15; +const APP_CACHE_BUSTER = 48; const APP_VERSION_STABLE = '0.5.0'; +const APP_STORAGE_UPLOADS = '/storage/uploads'; +const APP_STORAGE_CACHE = '/storage/cache'; +const APP_STORAGE_CERTIFICATES = '/storage/certificates'; +const APP_STORAGE_CONFIG = '/storage/config'; +const APP_SOCIAL_TWITTER = 'https://twitter.com/appwrite_io'; +const APP_SOCIAL_TWITTER_HANDLE = 'appwrite_io'; +const APP_SOCIAL_FACEBOOK = 'https://www.facebook.com/appwrite.io'; +const APP_SOCIAL_LINKEDIN = 'https://www.linkedin.com/company/appwrite'; +const APP_SOCIAL_INSTAGRAM = 'https://www.instagram.com/appwrite.io'; +const APP_SOCIAL_GITHUB = 'https://github.com/appwrite'; +const APP_SOCIAL_DISCORD = 'https://discord.gg/GSeTUeA'; $register = new Registry(); $request = new Request(); @@ -44,8 +56,8 @@ $collections = include __DIR__.'/../app/config/collections.php'; // Collections $redisHost = $request->getServer('_APP_REDIS_HOST', ''); $redisPort = $request->getServer('_APP_REDIS_PORT', ''); $utopia = new App('Asia/Tel_Aviv', $env); -$scheme = $request->getServer('REQUEST_SCHEME', ''); -$port = (string) parse_url($scheme.'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_PORT); +$protocol = $request->getServer('HTTP_X_FORWARDED_PROTO', $request->getServer('REQUEST_SCHEME', 'https')); +$port = (string) parse_url($protocol.'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_PORT); Resque::setBackend($redisHost.':'.$redisPort); @@ -56,7 +68,7 @@ define('COOKIE_DOMAIN', (filter_var($request->getServer('HTTP_HOST', null), FILTER_VALIDATE_IP) !== false) ) ? null - : '.'.parse_url($scheme.'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_HOST)); + : '.'.parse_url($protocol.'://'.$request->getServer('HTTP_HOST', ''), PHP_URL_HOST)); define('COOKIE_SAMESITE', Response::COOKIE_SAMESITE_NONE); /* @@ -197,7 +209,9 @@ if (in_array($locale, $locales)) { stream_context_set_default([ // Set global user agent and http settings 'http' => [ 'method' => 'GET', - 'user_agent' => sprintf(APP_USERAGENT, $version), + 'user_agent' => sprintf(APP_USERAGENT, + $version, + $request->getServer('_APP_SYSTEM_SECURITY_EMAIL_ADDRESS', APP_EMAIL_SECURITY)), 'timeout' => 2, ], ]); @@ -229,7 +243,18 @@ if (APP_MODE_ADMIN === $mode) { $session = Auth::decodeSession( $request->getCookie(Auth::$cookieName, // Get sessions $request->getCookie(Auth::$cookieName.'_legacy', // Get fallback session from old clients (no SameSite support) - $request->getHeader('X-Appwrite-Key', '')))); // Get API Key + $request->getHeader('X-Appwrite-Key', '')))); // Get API Key + +// Get fallback session from clients who block 3rd-party cookies +$response->addHeader('X-Debug-Fallback', 'false'); + +if(empty($session['id']) && empty($session['secret'])) { + $response->addHeader('X-Debug-Fallback', 'true'); + $fallback = $request->getHeader('X-Fallback-Cookies', null); + $fallback = json_decode($fallback, true); + $session = Auth::decodeSession(((isset($fallback[Auth::$cookieName])) ? $fallback[Auth::$cookieName] : '')); +} + Auth::$unique = $session['id']; Auth::$secret = $session['secret']; diff --git a/app/sdks/dart/LICENSE b/app/sdks/console-javascript/LICENSE similarity index 100% rename from app/sdks/dart/LICENSE rename to app/sdks/console-javascript/LICENSE diff --git a/app/sdks/console-javascript/README.md b/app/sdks/console-javascript/README.md new file mode 100644 index 0000000000..005e2d2364 --- /dev/null +++ b/app/sdks/console-javascript/README.md @@ -0,0 +1,38 @@ +# Appwrite SDK for JavaScript + + + + +Appwrite backend as a service cuts up to 70% of the time and costs required for building a modern application. We abstract and simplify common development tasks behind a REST APIs, to help you develop your app in a fast and secure way. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) + + + +## Installation + +### NPM + +To install via [NPM](https://www.npmjs.com/): + +```bash +npm install appwrite --save +``` + +If you're using a bundler (like [Browserify](http://browserify.org/) or [webpack](https://webpack.js.org/)), you can import the Appwrite module when you need it: + +```js +import * as Appwrite from "appwrite"; +``` + +### CDN + +To install with a CDN (content delivery network) add the following scripts to the bottom of your
tag, but before you use any Appwrite services: + +```html + +``` + + + +## License + +Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/create-o-auth2session.md b/app/sdks/console-javascript/docs/examples/account/create-o-auth2session.md new file mode 100644 index 0000000000..f4577b551f --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/create-o-auth2session.md @@ -0,0 +1,10 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let result = sdk.account.createOAuth2Session('bitbucket', 'https://example.com', 'https://example.com'); + +console.log(result); // Resource URL diff --git a/app/sdks/console-javascript/docs/examples/account/create-recovery.md b/app/sdks/console-javascript/docs/examples/account/create-recovery.md new file mode 100644 index 0000000000..7b636943e3 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/create-recovery.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.createRecovery('email@example.com', 'https://example.com'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/create-session.md b/app/sdks/console-javascript/docs/examples/account/create-session.md new file mode 100644 index 0000000000..1f930eddc5 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/create-session.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.createSession('email@example.com', 'password'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/create-verification.md b/app/sdks/console-javascript/docs/examples/account/create-verification.md new file mode 100644 index 0000000000..d9088638df --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/create-verification.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.createVerification('https://example.com'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/create.md b/app/sdks/console-javascript/docs/examples/account/create.md new file mode 100644 index 0000000000..ef9b9b7f95 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/create.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.create('email@example.com', 'password'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/delete-session.md b/app/sdks/console-javascript/docs/examples/account/delete-session.md new file mode 100644 index 0000000000..7d813a356c --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/delete-session.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.deleteSession('[SESSION_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/delete-sessions.md b/app/sdks/console-javascript/docs/examples/account/delete-sessions.md new file mode 100644 index 0000000000..fef0113dc7 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/delete-sessions.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.deleteSessions(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/delete.md b/app/sdks/console-javascript/docs/examples/account/delete.md new file mode 100644 index 0000000000..cc953421a5 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/delete.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.delete(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/get-logs.md b/app/sdks/console-javascript/docs/examples/account/get-logs.md new file mode 100644 index 0000000000..9186ca2ab3 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/get-logs.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.getLogs(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/get-prefs.md b/app/sdks/console-javascript/docs/examples/account/get-prefs.md new file mode 100644 index 0000000000..c80508e3ee --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/get-prefs.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.getPrefs(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/get-sessions.md b/app/sdks/console-javascript/docs/examples/account/get-sessions.md new file mode 100644 index 0000000000..1595e7a7ee --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/get-sessions.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.getSessions(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/get.md b/app/sdks/console-javascript/docs/examples/account/get.md new file mode 100644 index 0000000000..8e88b195ae --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/get.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.get(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/update-email.md b/app/sdks/console-javascript/docs/examples/account/update-email.md new file mode 100644 index 0000000000..c53eb579aa --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/update-email.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.updateEmail('email@example.com', 'password'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/update-name.md b/app/sdks/console-javascript/docs/examples/account/update-name.md new file mode 100644 index 0000000000..f9a3fdeffd --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/update-name.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.updateName('[NAME]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/update-password.md b/app/sdks/console-javascript/docs/examples/account/update-password.md new file mode 100644 index 0000000000..a0058d972a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/update-password.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.updatePassword('password', 'password'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/update-prefs.md b/app/sdks/console-javascript/docs/examples/account/update-prefs.md new file mode 100644 index 0000000000..fa55eea179 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/update-prefs.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.updatePrefs({}); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/update-recovery.md b/app/sdks/console-javascript/docs/examples/account/update-recovery.md new file mode 100644 index 0000000000..883df2f9b2 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/update-recovery.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.updateRecovery('[USER_ID]', '[SECRET]', 'password', 'password'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/account/update-verification.md b/app/sdks/console-javascript/docs/examples/account/update-verification.md new file mode 100644 index 0000000000..d04203a3cb --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/account/update-verification.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.account.updateVerification('[USER_ID]', '[SECRET]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/avatars/get-browser.md b/app/sdks/console-javascript/docs/examples/avatars/get-browser.md new file mode 100644 index 0000000000..fd5959f1bb --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/avatars/get-browser.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.avatars.getBrowser('aa'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/avatars/get-credit-card.md b/app/sdks/console-javascript/docs/examples/avatars/get-credit-card.md new file mode 100644 index 0000000000..45c87c783a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/avatars/get-credit-card.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.avatars.getCreditCard('amex'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/avatars/get-favicon.md b/app/sdks/console-javascript/docs/examples/avatars/get-favicon.md new file mode 100644 index 0000000000..2b8d94c4c6 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/avatars/get-favicon.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.avatars.getFavicon('https://example.com'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/avatars/get-flag.md b/app/sdks/console-javascript/docs/examples/avatars/get-flag.md new file mode 100644 index 0000000000..a2723be671 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/avatars/get-flag.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.avatars.getFlag('af'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/avatars/get-image.md b/app/sdks/console-javascript/docs/examples/avatars/get-image.md new file mode 100644 index 0000000000..c9d6b6cf79 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/avatars/get-image.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.avatars.getImage('https://example.com'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/avatars/get-q-r.md b/app/sdks/console-javascript/docs/examples/avatars/get-q-r.md new file mode 100644 index 0000000000..39938a47bf --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/avatars/get-q-r.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.avatars.getQR('[TEXT]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/create-collection.md b/app/sdks/console-javascript/docs/examples/database/create-collection.md new file mode 100644 index 0000000000..13bd67171c --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/create-collection.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.createCollection('[NAME]', [], [], []); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/create-document.md b/app/sdks/console-javascript/docs/examples/database/create-document.md new file mode 100644 index 0000000000..41908a3820 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/create-document.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.createDocument('[COLLECTION_ID]', {}, [], []); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/delete-collection.md b/app/sdks/console-javascript/docs/examples/database/delete-collection.md new file mode 100644 index 0000000000..4a7753685b --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/delete-collection.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.deleteCollection('[COLLECTION_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/delete-document.md b/app/sdks/console-javascript/docs/examples/database/delete-document.md new file mode 100644 index 0000000000..246454a0d4 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/delete-document.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.deleteDocument('[COLLECTION_ID]', '[DOCUMENT_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/get-collection.md b/app/sdks/console-javascript/docs/examples/database/get-collection.md new file mode 100644 index 0000000000..c58d3bf21e --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/get-collection.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.getCollection('[COLLECTION_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/get-document.md b/app/sdks/console-javascript/docs/examples/database/get-document.md new file mode 100644 index 0000000000..7674814399 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/get-document.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.getDocument('[COLLECTION_ID]', '[DOCUMENT_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/list-collections.md b/app/sdks/console-javascript/docs/examples/database/list-collections.md new file mode 100644 index 0000000000..73a45b621a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/list-collections.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.listCollections(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/list-documents.md b/app/sdks/console-javascript/docs/examples/database/list-documents.md new file mode 100644 index 0000000000..10100f59d5 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/list-documents.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.listDocuments('[COLLECTION_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/update-collection.md b/app/sdks/console-javascript/docs/examples/database/update-collection.md new file mode 100644 index 0000000000..c3d663bb1e --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/update-collection.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.updateCollection('[COLLECTION_ID]', '[NAME]', [], []); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/database/update-document.md b/app/sdks/console-javascript/docs/examples/database/update-document.md new file mode 100644 index 0000000000..d4570fe32b --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/database/update-document.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.database.updateDocument('[COLLECTION_ID]', '[DOCUMENT_ID]', {}, [], []); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/locale/get-continents.md b/app/sdks/console-javascript/docs/examples/locale/get-continents.md new file mode 100644 index 0000000000..f21e10337d --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/locale/get-continents.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.locale.getContinents(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/locale/get-countries-e-u.md b/app/sdks/console-javascript/docs/examples/locale/get-countries-e-u.md new file mode 100644 index 0000000000..7ade8b1808 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/locale/get-countries-e-u.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.locale.getCountriesEU(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/locale/get-countries-phones.md b/app/sdks/console-javascript/docs/examples/locale/get-countries-phones.md new file mode 100644 index 0000000000..bc0fb2a6f5 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/locale/get-countries-phones.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.locale.getCountriesPhones(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/locale/get-countries.md b/app/sdks/console-javascript/docs/examples/locale/get-countries.md new file mode 100644 index 0000000000..21dd02a789 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/locale/get-countries.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.locale.getCountries(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/locale/get-currencies.md b/app/sdks/console-javascript/docs/examples/locale/get-currencies.md new file mode 100644 index 0000000000..617398e2f3 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/locale/get-currencies.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.locale.getCurrencies(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/locale/get.md b/app/sdks/console-javascript/docs/examples/locale/get.md new file mode 100644 index 0000000000..ad06454b69 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/locale/get.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.locale.get(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/create-domain.md b/app/sdks/console-javascript/docs/examples/projects/create-domain.md new file mode 100644 index 0000000000..3362de91c3 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/create-domain.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.createDomain('[PROJECT_ID]', ''); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/create-key.md b/app/sdks/console-javascript/docs/examples/projects/create-key.md new file mode 100644 index 0000000000..1632d24862 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/create-key.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.createKey('[PROJECT_ID]', '[NAME]', []); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/create-platform.md b/app/sdks/console-javascript/docs/examples/projects/create-platform.md new file mode 100644 index 0000000000..474640705a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/create-platform.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.createPlatform('[PROJECT_ID]', 'web', '[NAME]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/create-task.md b/app/sdks/console-javascript/docs/examples/projects/create-task.md new file mode 100644 index 0000000000..ccec45a35a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/create-task.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.createTask('[PROJECT_ID]', '[NAME]', 'play', '', 0, 'GET', 'https://example.com'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/create-webhook.md b/app/sdks/console-javascript/docs/examples/projects/create-webhook.md new file mode 100644 index 0000000000..4bb7400949 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/create-webhook.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 0); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/create.md b/app/sdks/console-javascript/docs/examples/projects/create.md new file mode 100644 index 0000000000..c5cfac1bc4 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/create.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.create('[NAME]', '[TEAM_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/delete-domain.md b/app/sdks/console-javascript/docs/examples/projects/delete-domain.md new file mode 100644 index 0000000000..04d4c18343 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/delete-domain.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.deleteDomain('[PROJECT_ID]', '[DOMAIN_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/delete-key.md b/app/sdks/console-javascript/docs/examples/projects/delete-key.md new file mode 100644 index 0000000000..f71b115718 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/delete-key.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.deleteKey('[PROJECT_ID]', '[KEY_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/delete-platform.md b/app/sdks/console-javascript/docs/examples/projects/delete-platform.md new file mode 100644 index 0000000000..2f29f97b5a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/delete-platform.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.deletePlatform('[PROJECT_ID]', '[PLATFORM_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/delete-task.md b/app/sdks/console-javascript/docs/examples/projects/delete-task.md new file mode 100644 index 0000000000..5c82493859 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/delete-task.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.deleteTask('[PROJECT_ID]', '[TASK_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/delete-webhook.md b/app/sdks/console-javascript/docs/examples/projects/delete-webhook.md new file mode 100644 index 0000000000..776df8864a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/delete-webhook.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.deleteWebhook('[PROJECT_ID]', '[WEBHOOK_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/delete.md b/app/sdks/console-javascript/docs/examples/projects/delete.md new file mode 100644 index 0000000000..ae4ff5ccb1 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/delete.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.delete('[PROJECT_ID]', '[PASSWORD]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/get-domain.md b/app/sdks/console-javascript/docs/examples/projects/get-domain.md new file mode 100644 index 0000000000..4b3d9c52ed --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/get-domain.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.getDomain('[PROJECT_ID]', '[DOMAIN_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/get-key.md b/app/sdks/console-javascript/docs/examples/projects/get-key.md new file mode 100644 index 0000000000..8cecb69760 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/get-key.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.getKey('[PROJECT_ID]', '[KEY_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/get-platform.md b/app/sdks/console-javascript/docs/examples/projects/get-platform.md new file mode 100644 index 0000000000..2968e093ef --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/get-platform.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.getPlatform('[PROJECT_ID]', '[PLATFORM_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/get-task.md b/app/sdks/console-javascript/docs/examples/projects/get-task.md new file mode 100644 index 0000000000..4cdd44ec6c --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/get-task.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.getTask('[PROJECT_ID]', '[TASK_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/get-usage.md b/app/sdks/console-javascript/docs/examples/projects/get-usage.md new file mode 100644 index 0000000000..3503d3ee1a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/get-usage.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.getUsage('[PROJECT_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/get-webhook.md b/app/sdks/console-javascript/docs/examples/projects/get-webhook.md new file mode 100644 index 0000000000..0d92c8a507 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/get-webhook.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.getWebhook('[PROJECT_ID]', '[WEBHOOK_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/get.md b/app/sdks/console-javascript/docs/examples/projects/get.md new file mode 100644 index 0000000000..98b4ef15ad --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/get.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.get('[PROJECT_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/list-domains.md b/app/sdks/console-javascript/docs/examples/projects/list-domains.md new file mode 100644 index 0000000000..48dcaaf31e --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/list-domains.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.listDomains('[PROJECT_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/list-keys.md b/app/sdks/console-javascript/docs/examples/projects/list-keys.md new file mode 100644 index 0000000000..122ff5d676 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/list-keys.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.listKeys('[PROJECT_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/list-platforms.md b/app/sdks/console-javascript/docs/examples/projects/list-platforms.md new file mode 100644 index 0000000000..3dba8f1be4 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/list-platforms.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.listPlatforms('[PROJECT_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/list-tasks.md b/app/sdks/console-javascript/docs/examples/projects/list-tasks.md new file mode 100644 index 0000000000..dfbd51039d --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/list-tasks.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.listTasks('[PROJECT_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/list-webhooks.md b/app/sdks/console-javascript/docs/examples/projects/list-webhooks.md new file mode 100644 index 0000000000..32660f6447 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/list-webhooks.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.listWebhooks('[PROJECT_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/list.md b/app/sdks/console-javascript/docs/examples/projects/list.md new file mode 100644 index 0000000000..32a2e112cc --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/list.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.list(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/update-domain-verification.md b/app/sdks/console-javascript/docs/examples/projects/update-domain-verification.md new file mode 100644 index 0000000000..7a60d9443a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/update-domain-verification.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.updateDomainVerification('[PROJECT_ID]', '[DOMAIN_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/update-key.md b/app/sdks/console-javascript/docs/examples/projects/update-key.md new file mode 100644 index 0000000000..196e6ceac0 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/update-key.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.updateKey('[PROJECT_ID]', '[KEY_ID]', '[NAME]', []); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/update-o-auth2.md b/app/sdks/console-javascript/docs/examples/projects/update-o-auth2.md new file mode 100644 index 0000000000..5c202778f5 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/update-o-auth2.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.updateOAuth2('[PROJECT_ID]', 'bitbucket'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/update-platform.md b/app/sdks/console-javascript/docs/examples/projects/update-platform.md new file mode 100644 index 0000000000..606872f9ce --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/update-platform.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.updatePlatform('[PROJECT_ID]', '[PLATFORM_ID]', '[NAME]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/update-task.md b/app/sdks/console-javascript/docs/examples/projects/update-task.md new file mode 100644 index 0000000000..8b23e7a0dc --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/update-task.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.updateTask('[PROJECT_ID]', '[TASK_ID]', '[NAME]', 'play', '', 0, 'GET', 'https://example.com'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/update-webhook.md b/app/sdks/console-javascript/docs/examples/projects/update-webhook.md new file mode 100644 index 0000000000..6b1cc8cbed --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/update-webhook.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 0); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/projects/update.md b/app/sdks/console-javascript/docs/examples/projects/update.md new file mode 100644 index 0000000000..34cda4b9e2 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/projects/update.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.projects.update('[PROJECT_ID]', '[NAME]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/storage/create-file.md b/app/sdks/console-javascript/docs/examples/storage/create-file.md new file mode 100644 index 0000000000..0aa8829fe8 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/storage/create-file.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.storage.createFile(document.getElementById('uploader').files[0], [], []); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/storage/delete-file.md b/app/sdks/console-javascript/docs/examples/storage/delete-file.md new file mode 100644 index 0000000000..e37c8937b0 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/storage/delete-file.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.storage.deleteFile('[FILE_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/storage/get-file-download.md b/app/sdks/console-javascript/docs/examples/storage/get-file-download.md new file mode 100644 index 0000000000..0d0ff8fc3e --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/storage/get-file-download.md @@ -0,0 +1,10 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let result = sdk.storage.getFileDownload('[FILE_ID]'); + +console.log(result); // Resource URL diff --git a/app/sdks/console-javascript/docs/examples/storage/get-file-preview.md b/app/sdks/console-javascript/docs/examples/storage/get-file-preview.md new file mode 100644 index 0000000000..712b38917a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/storage/get-file-preview.md @@ -0,0 +1,10 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let result = sdk.storage.getFilePreview('[FILE_ID]'); + +console.log(result); // Resource URL diff --git a/app/sdks/javascript/docs/examples/account/create-o-auth-session.md b/app/sdks/console-javascript/docs/examples/storage/get-file-view.md similarity index 50% rename from app/sdks/javascript/docs/examples/account/create-o-auth-session.md rename to app/sdks/console-javascript/docs/examples/storage/get-file-view.md index a201c8b4c1..08368f8b19 100644 --- a/app/sdks/javascript/docs/examples/account/create-o-auth-session.md +++ b/app/sdks/console-javascript/docs/examples/storage/get-file-view.md @@ -2,8 +2,9 @@ let sdk = new Appwrite(); sdk .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -let result = sdk.account.createOAuthSession('bitbucket', 'https://example.com', 'https://example.com'); +let result = sdk.storage.getFileView('[FILE_ID]'); console.log(result); // Resource URL diff --git a/app/sdks/console-javascript/docs/examples/storage/get-file.md b/app/sdks/console-javascript/docs/examples/storage/get-file.md new file mode 100644 index 0000000000..f9707981b7 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/storage/get-file.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.storage.getFile('[FILE_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/storage/list-files.md b/app/sdks/console-javascript/docs/examples/storage/list-files.md new file mode 100644 index 0000000000..3a40057b7c --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/storage/list-files.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.storage.listFiles(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/storage/update-file.md b/app/sdks/console-javascript/docs/examples/storage/update-file.md new file mode 100644 index 0000000000..630ec6c9fc --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/storage/update-file.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.storage.updateFile('[FILE_ID]', [], []); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/teams/create-membership.md b/app/sdks/console-javascript/docs/examples/teams/create-membership.md new file mode 100644 index 0000000000..7d60897edf --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/teams/create-membership.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.teams.createMembership('[TEAM_ID]', 'email@example.com', [], 'https://example.com'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/teams/create.md b/app/sdks/console-javascript/docs/examples/teams/create.md new file mode 100644 index 0000000000..573557179a --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/teams/create.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.teams.create('[NAME]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/teams/delete-membership.md b/app/sdks/console-javascript/docs/examples/teams/delete-membership.md new file mode 100644 index 0000000000..01dc2dfc95 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/teams/delete-membership.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.teams.deleteMembership('[TEAM_ID]', '[INVITE_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/teams/delete.md b/app/sdks/console-javascript/docs/examples/teams/delete.md new file mode 100644 index 0000000000..d8eb25bf87 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/teams/delete.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.teams.delete('[TEAM_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/teams/get-memberships.md b/app/sdks/console-javascript/docs/examples/teams/get-memberships.md new file mode 100644 index 0000000000..1b51d214df --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/teams/get-memberships.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.teams.getMemberships('[TEAM_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/teams/get.md b/app/sdks/console-javascript/docs/examples/teams/get.md new file mode 100644 index 0000000000..2c14d01ebd --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/teams/get.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.teams.get('[TEAM_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/teams/list.md b/app/sdks/console-javascript/docs/examples/teams/list.md new file mode 100644 index 0000000000..a266273f3d --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/teams/list.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.teams.list(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/teams/update-membership-status.md b/app/sdks/console-javascript/docs/examples/teams/update-membership-status.md new file mode 100644 index 0000000000..3942b0a788 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/teams/update-membership-status.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.teams.updateMembershipStatus('[TEAM_ID]', '[INVITE_ID]', '[USER_ID]', '[SECRET]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/teams/update.md b/app/sdks/console-javascript/docs/examples/teams/update.md new file mode 100644 index 0000000000..00b718e431 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/teams/update.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.teams.update('[TEAM_ID]', '[NAME]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/create.md b/app/sdks/console-javascript/docs/examples/users/create.md new file mode 100644 index 0000000000..c4d5acb17d --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/create.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.create('email@example.com', 'password'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/delete-session.md b/app/sdks/console-javascript/docs/examples/users/delete-session.md new file mode 100644 index 0000000000..dac3ed7c39 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/delete-session.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.deleteSession('[USER_ID]', '[SESSION_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/delete-sessions.md b/app/sdks/console-javascript/docs/examples/users/delete-sessions.md new file mode 100644 index 0000000000..6386b536d5 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/delete-sessions.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.deleteSessions('[USER_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/get-logs.md b/app/sdks/console-javascript/docs/examples/users/get-logs.md new file mode 100644 index 0000000000..cdaf3e8b76 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/get-logs.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.getLogs('[USER_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/get-prefs.md b/app/sdks/console-javascript/docs/examples/users/get-prefs.md new file mode 100644 index 0000000000..a861db2607 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/get-prefs.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.getPrefs('[USER_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/get-sessions.md b/app/sdks/console-javascript/docs/examples/users/get-sessions.md new file mode 100644 index 0000000000..4281e3c27e --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/get-sessions.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.getSessions('[USER_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/get.md b/app/sdks/console-javascript/docs/examples/users/get.md new file mode 100644 index 0000000000..cccbd13855 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/get.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.get('[USER_ID]'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/list.md b/app/sdks/console-javascript/docs/examples/users/list.md new file mode 100644 index 0000000000..34888458cd --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/list.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.list(); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/update-prefs.md b/app/sdks/console-javascript/docs/examples/users/update-prefs.md new file mode 100644 index 0000000000..ed254f0608 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/update-prefs.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.updatePrefs('[USER_ID]', {}); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/docs/examples/users/update-status.md b/app/sdks/console-javascript/docs/examples/users/update-status.md new file mode 100644 index 0000000000..c82fd1faa7 --- /dev/null +++ b/app/sdks/console-javascript/docs/examples/users/update-status.md @@ -0,0 +1,14 @@ +let sdk = new Appwrite(); + +sdk + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.users.updateStatus('[USER_ID]', '1'); + +promise.then(function (response) { + console.log(response); // Success +}, function (error) { + console.log(error); // Failure +}); \ No newline at end of file diff --git a/app/sdks/console-javascript/package.json b/app/sdks/console-javascript/package.json new file mode 100644 index 0000000000..d4be0c0d03 --- /dev/null +++ b/app/sdks/console-javascript/package.json @@ -0,0 +1,14 @@ +{ + "name": "appwrite", + "homepage": "https://appwrite.io/support", + "description": "Appwrite backend as a service cuts up to 70% of the time and costs required for building a modern application. We abstract and simplify common development tasks behind a REST APIs, to help you develop your app in a fast and secure way. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)", + "version": "1.0.0", + "license": "BSD-3-Clause", + "main": "src/sdk.js", + "repository": { + "type": "git", + "url": "https://github.com/appwrite/sdk-for-console" + }, + "devDependencies": {}, + "dependencies": {} +} \ No newline at end of file diff --git a/app/sdks/console-javascript/src/sdk.js b/app/sdks/console-javascript/src/sdk.js new file mode 100644 index 0000000000..e1fc51b8e8 --- /dev/null +++ b/app/sdks/console-javascript/src/sdk.js @@ -0,0 +1,3979 @@ +(function (window) { + + 'use strict'; + + window.Appwrite = function () { + + let config = { + endpoint: 'https://appwrite.io/v1', + project: '', + key: '', + locale: '', + mode: '', + }; + + /** + * @param {string} endpoint + * @returns {this} + */ + let setEndpoint = function(endpoint) { + config.endpoint = endpoint; + + return this; + }; + + /** + * Set Project + * + * Your project ID + * + * @param value string + * + * @return this + */ + let setProject = function (value) + { + http.addGlobalHeader('X-Appwrite-Project', value); + + config.project = value; + + return this; + }; + + /** + * Set Key + * + * Your secret API key + * + * @param value string + * + * @return this + */ + let setKey = function (value) + { + http.addGlobalHeader('X-Appwrite-Key', value); + + config.key = value; + + return this; + }; + + /** + * Set Locale + * + * @param value string + * + * @return this + */ + let setLocale = function (value) + { + http.addGlobalHeader('X-Appwrite-Locale', value); + + config.locale = value; + + return this; + }; + + /** + * Set Mode + * + * @param value string + * + * @return this + */ + let setMode = function (value) + { + http.addGlobalHeader('X-Appwrite-Mode', value); + + config.mode = value; + + return this; + }; + + let http = function(document) { + let globalParams = [], + globalHeaders = []; + + let addParam = function (url, param, value) { + let a = document.createElement('a'), regex = /(?:\?|&|&)+([^=]+)(?:=([^&]*))*/g; + let match, str = []; + a.href = url; + param = encodeURIComponent(param); + + while (match = regex.exec(a.search)) if (param !== match[1]) str.push(match[1] + (match[2] ? "=" + match[2] : "")); + + str.push(param + (value ? "=" + encodeURIComponent(value) : "")); + + a.search = str.join("&"); + + return a.href; + }; + + /** + * @param {Object} params + * @returns {string} + */ + let buildQuery = function(params) { + let str = []; + + for (let p in params) { + if(Array.isArray(params[p])) { + for (let index = 0; index < params[p].length; index++) { + let param = params[p][index]; + str.push(encodeURIComponent(p + '[]') + "=" + encodeURIComponent(param)); + } + } + else { + str.push(encodeURIComponent(p) + "=" + encodeURIComponent(params[p])); + } + } + + return str.join("&"); + }; + + let addGlobalHeader = function(key, value) { + globalHeaders[key] = {key: key.toLowerCase(), value: value.toLowerCase()}; + }; + + let addGlobalParam = function(key, value) { + globalParams.push({key: key, value: value}); + }; + + addGlobalHeader('x-sdk-version', 'appwrite:javascript:1.0.0'); + addGlobalHeader('content-type', ''); + + /** + * @param {string} method + * @param {string} path string + * @param {Object} headers + * @param {Object} params + * @param {function} progress + * @returns {Promise} + */ + let call = function (method, path, headers = {}, params = {}, progress = null) { + let i; + + path = config.endpoint + path; + + if (-1 === ['GET', 'POST', 'PUT', 'DELETE', 'TRACE', 'HEAD', 'OPTIONS', 'CONNECT', 'PATCH'].indexOf(method)) { + throw new Error('var method must contain a valid HTTP method name'); + } + + if (typeof path !== 'string') { + throw new Error('var path must be of type string'); + } + + if (typeof headers !== 'object') { + throw new Error('var headers must be of type object'); + } + + for (i = 0; i < globalParams.length; i++) { // Add global params to URL + path = addParam(path, globalParams[i].key, globalParams[i].value); + } + + for (let key in globalHeaders) { // Add Global Headers + if (globalHeaders.hasOwnProperty(key)) { + if (!headers[globalHeaders[key].key]) { + headers[globalHeaders[key].key] = globalHeaders[key].value; + } + } + } + + if(method === 'GET') { + for (let param in params) { + if (param.hasOwnProperty(key)) { + path = addParam(path, key + (Array.isArray(param) ? '[]' : ''), params[key]); + } + } + } + + switch (headers['content-type']) { // Parse request by content type + case 'application/json': + params = JSON.stringify(params); + break; + + case 'multipart/form-data': + let formData = new FormData(); + + Object.keys(params).forEach(function(key) { + let param = params[key]; + formData.append(key + (Array.isArray(param) ? '[]' : ''), param); + }); + + params = formData; + break; + } + + return new Promise(function (resolve, reject) { + + let request = new XMLHttpRequest(), key; + + request.withCredentials = true; + request.open(method, path, true); + + for (key in headers) { // Set Headers + if (headers.hasOwnProperty(key)) { + if (key === 'content-type' && headers[key] === 'multipart/form-data') { // Skip to avoid missing boundary + continue; + } + + request.setRequestHeader(key, headers[key]); + } + } + + request.onload = function () { + if (4 === request.readyState && 399 >= request.status) { + let data = request.response; + let contentType = this.getResponseHeader('content-type') || ''; + contentType = contentType.substring(0, contentType.indexOf(';')); + + switch (contentType) { + case 'application/json': + data = JSON.parse(data); + break; + } + + resolve(data); + + } else { + reject(new Error(request.statusText)); + } + }; + + if (progress) { + request.addEventListener('progress', progress); + request.upload.addEventListener('progress', progress, false); + } + + // Handle network errors + request.onerror = function () { + reject(new Error("Network Error")); + }; + + request.send(params); + }) + }; + + return { + 'get': function(path, headers = {}, params = {}) { + return call('GET', path + ((Object.keys(params).length > 0) ? '?' + buildQuery(params) : ''), headers, {}); + }, + 'post': function(path, headers = {}, params = {}, progress = null) { + return call('POST', path, headers, params, progress); + }, + 'put': function(path, headers = {}, params = {}, progress = null) { + return call('PUT', path, headers, params, progress); + }, + 'patch': function(path, headers = {}, params = {}, progress = null) { + return call('PATCH', path, headers, params, progress); + }, + 'delete': function(path, headers = {}, params = {}, progress = null) { + return call('DELETE', path, headers, params, progress); + }, + 'addGlobalParam': addGlobalParam, + 'addGlobalHeader': addGlobalHeader + } + }(window.document); + + let iframe = function(method, url, params) { + let form = document.createElement('form'); + + form.setAttribute('method', method); + form.setAttribute('action', config.endpoint + url); + + for(let key in params) { + if(params.hasOwnProperty(key)) { + let hiddenField = document.createElement("input"); + hiddenField.setAttribute("type", "hidden"); + hiddenField.setAttribute("name", key); + hiddenField.setAttribute("value", params[key]); + + form.appendChild(hiddenField); + } + } + + document.body.appendChild(form); + + return form.submit(); + }; + + let account = { + + /** + * Get Account + * + * Get currently logged in user data as JSON object. + * + * @throws {Error} + * @return {Promise} + */ + get: function() { + let path = '/account'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Account + * + * Use this endpoint to allow a new user to register a new account in your + * project. After the user registration completes successfully, you can use + * the [/account/verfication](/docs/account#createVerification) route to start + * verifying the user email address. To allow your new user to login to his + * new account, you need to create a new [account + * session](/docs/account#createSession). + * + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {Error} + * @return {Promise} + */ + create: function(email, password, name = '') { + if(email === undefined) { + throw new Error('Missing required parameter: "email"'); + } + + if(password === undefined) { + throw new Error('Missing required parameter: "password"'); + } + + let path = '/account'; + + let payload = {}; + + if(email) { + payload['email'] = email; + } + + if(password) { + payload['password'] = password; + } + + if(name) { + payload['name'] = name; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Account + * + * Delete a currently logged in user account. Behind the scene, the user + * record is not deleted but permanently blocked from any access. This is done + * to avoid deleted accounts being overtaken by new users with the same email + * address. Any user-related resources like documents or storage files should + * be deleted separately. + * + * @throws {Error} + * @return {Promise} + */ + delete: function() { + let path = '/account'; + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Account Email + * + * Update currently logged in user account email address. After changing user + * address, user confirmation status is being reset and a new confirmation + * mail is sent. For security measures, user password is required to complete + * this request. + * + * @param {string} email + * @param {string} password + * @throws {Error} + * @return {Promise} + */ + updateEmail: 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/email'; + + let payload = {}; + + if(email) { + payload['email'] = email; + } + + if(password) { + payload['password'] = password; + } + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Account Logs + * + * Get currently logged in user list of latest security activity logs. Each + * log returns user IP address, location and date and time of log. + * + * @throws {Error} + * @return {Promise} + */ + getLogs: function() { + let path = '/account/logs'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Account Name + * + * Update currently logged in user account name. + * + * @param {string} name + * @throws {Error} + * @return {Promise} + */ + updateName: function(name) { + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + let path = '/account/name'; + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Account Password + * + * Update currently logged in user password. For validation, user is required + * to pass the password twice. + * + * @param {string} password + * @param {string} oldPassword + * @throws {Error} + * @return {Promise} + */ + 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; + } + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Account Preferences + * + * Get currently logged in user preferences as a key-value object. + * + * @throws {Error} + * @return {Promise} + */ + getPrefs: function() { + let path = '/account/prefs'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Account Preferences + * + * Update currently logged in user account preferences. You can pass only the + * specific settings you wish to update. + * + * @param {object} prefs + * @throws {Error} + * @return {Promise} + */ + 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); + }, + + /** + * Create Password Recovery + * + * Sends the user an email with a temporary secret key for password reset. + * When the user clicks the confirmation link he is redirected back to your + * app password reset URL with the secret key and email address values + * attached to the URL query string. Use the query string params to submit a + * request to the [PUT /account/recovery](/docs/account#updateRecovery) + * endpoint to complete the process. + * + * @param {string} email + * @param {string} url + * @throws {Error} + * @return {Promise} + */ + 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); + }, + + /** + * Complete Password Recovery + * + * Use this endpoint to complete the user account password reset. Both the + * **userId** and **secret** arguments will be passed as query parameters to + * the redirect URL you have provided when sending your request to the [POST + * /account/recovery](/docs/account#createRecovery) endpoint. + * + * Please note that in order to avoid a [Redirect + * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) + * the only valid redirect URLs are the ones from domains you have set when + * adding your platforms in the console interface. + * + * @param {string} userId + * @param {string} secret + * @param {string} passwordA + * @param {string} passwordB + * @throws {Error} + * @return {Promise} + */ + updateRecovery: function(userId, secret, passwordA, passwordB) { + 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"'); + } + + 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; + } + + return http + .put(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Account Sessions + * + * Get currently logged in user list of active sessions across different + * devices. + * + * @throws {Error} + * @return {Promise} + */ + getSessions: function() { + let path = '/account/sessions'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Account Session + * + * Allow the user to login into his account by providing a valid email and + * password combination. This route will create a new session for the user. + * + * @param {string} email + * @param {string} password + * @throws {Error} + * @return {Promise} + */ + 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; + } + + if(password) { + payload['password'] = password; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete All Account Sessions + * + * Delete all sessions from the user account and remove any sessions cookies + * from the end client. + * + * @throws {Error} + * @return {Promise} + */ + deleteSessions: function() { + let path = '/account/sessions'; + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Account Session with OAuth2 + * + * Allow the user to login to his account using the OAuth2 provider of his + * choice. Each OAuth2 provider should be enabled from the Appwrite console + * first. Use the success and failure arguments to provide a redirect URL's + * back to your app when login is completed. + * + * @param {string} provider + * @param {string} success + * @param {string} failure + * @throws {Error} + * @return {string} + */ + createOAuth2Session: function(provider, success, failure) { + if(provider === undefined) { + throw new Error('Missing required parameter: "provider"'); + } + + if(success === undefined) { + throw new Error('Missing required parameter: "success"'); + } + + if(failure === undefined) { + throw new Error('Missing required parameter: "failure"'); + } + + let path = '/account/sessions/oauth2/{provider}'.replace(new RegExp('{provider}', 'g'), provider); + + let payload = {}; + + if(success) { + payload['success'] = success; + } + + if(failure) { + payload['failure'] = failure; + } + + payload['project'] = config.project; + + payload['key'] = config.key; + + let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&'); + + return config.endpoint + path + ((query) ? '?' + query : ''); + }, + + /** + * Delete Account Session + * + * Use this endpoint to log out the currently logged in user from all his + * account sessions across all his different devices. When using the option id + * argument, only the session unique ID provider will be deleted. + * + * @param {string} sessionId + * @throws {Error} + * @return {Promise} + */ + deleteSession: function(sessionId) { + if(sessionId === undefined) { + throw new Error('Missing required parameter: "sessionId"'); + } + + let path = '/account/sessions/{sessionId}'.replace(new RegExp('{sessionId}', 'g'), sessionId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Email Verification + * + * Use this endpoint to send a verification message to your user email address + * to confirm they are the valid owners of that address. Both the **userId** + * and **secret** arguments will be passed as query parameters to the URL you + * have provider to be attached to the verification email. The provided URL + * should redirect the user back for your app and allow you to complete the + * verification process by verifying both the **userId** and **secret** + * parameters. Learn more about how to [complete the verification + * process](/docs/account#updateAccountVerification). + * + * Please note that in order to avoid a [Redirect + * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) + * the only valid redirect URLs are the ones from domains you have set when + * adding your platforms in the console interface. + * + * @param {string} url + * @throws {Error} + * @return {Promise} + */ + createVerification: function(url) { + if(url === undefined) { + throw new Error('Missing required parameter: "url"'); + } + + let path = '/account/verification'; + + let payload = {}; + + if(url) { + payload['url'] = url; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Complete Email Verification + * + * Use this endpoint to complete the user email verification process. Use both + * the **userId** and **secret** parameters that were attached to your app URL + * to verify the user email ownership. If confirmed this route will return a + * 200 status code. + * + * @param {string} userId + * @param {string} secret + * @throws {Error} + * @return {Promise} + */ + updateVerification: function(userId, secret) { + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + if(secret === undefined) { + throw new Error('Missing required parameter: "secret"'); + } + + let path = '/account/verification'; + + let payload = {}; + + if(userId) { + payload['userId'] = userId; + } + + if(secret) { + payload['secret'] = secret; + } + + return http + .put(path, { + 'content-type': 'application/json', + }, payload); + } + }; + + let avatars = { + + /** + * Get Browser Icon + * + * You can use this endpoint to show different browser icons to your users. + * The code argument receives the browser code as it appears in your user + * /account/sessions endpoint. Use width, height and quality arguments to + * change the output settings. + * + * @param {string} code + * @param {number} width + * @param {number} height + * @param {number} quality + * @throws {Error} + * @return {Promise} + */ + getBrowser: function(code, width = 100, height = 100, quality = 100) { + if(code === undefined) { + throw new Error('Missing required parameter: "code"'); + } + + let path = '/avatars/browsers/{code}'.replace(new RegExp('{code}', 'g'), code); + + let payload = {}; + + if(width) { + payload['width'] = width; + } + + if(height) { + payload['height'] = height; + } + + if(quality) { + payload['quality'] = quality; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Credit Card Icon + * + * Need to display your users with your billing method or their payment + * methods? The credit card endpoint will return you the icon of the credit + * card provider you need. Use width, height and quality arguments to change + * the output settings. + * + * @param {string} code + * @param {number} width + * @param {number} height + * @param {number} quality + * @throws {Error} + * @return {Promise} + */ + getCreditCard: function(code, width = 100, height = 100, quality = 100) { + if(code === undefined) { + throw new Error('Missing required parameter: "code"'); + } + + let path = '/avatars/credit-cards/{code}'.replace(new RegExp('{code}', 'g'), code); + + let payload = {}; + + if(width) { + payload['width'] = width; + } + + if(height) { + payload['height'] = height; + } + + if(quality) { + payload['quality'] = quality; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Favicon + * + * Use this endpoint to fetch the favorite icon (AKA favicon) of a any remote + * website URL. + * + * @param {string} url + * @throws {Error} + * @return {Promise} + */ + getFavicon: function(url) { + if(url === undefined) { + throw new Error('Missing required parameter: "url"'); + } + + let path = '/avatars/favicon'; + + let payload = {}; + + if(url) { + payload['url'] = url; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Country Flag + * + * You can use this endpoint to show different country flags icons to your + * users. The code argument receives the 2 letter country code. Use width, + * height and quality arguments to change the output settings. + * + * @param {string} code + * @param {number} width + * @param {number} height + * @param {number} quality + * @throws {Error} + * @return {Promise} + */ + getFlag: function(code, width = 100, height = 100, quality = 100) { + if(code === undefined) { + throw new Error('Missing required parameter: "code"'); + } + + let path = '/avatars/flags/{code}'.replace(new RegExp('{code}', 'g'), code); + + let payload = {}; + + if(width) { + payload['width'] = width; + } + + if(height) { + payload['height'] = height; + } + + if(quality) { + payload['quality'] = quality; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Image from URL + * + * Use this endpoint to fetch a remote image URL and crop it to any image size + * you want. This endpoint is very useful if you need to crop and display + * remote images in your app or in case you want to make sure a 3rd party + * image is properly served using a TLS protocol. + * + * @param {string} url + * @param {number} width + * @param {number} height + * @throws {Error} + * @return {Promise} + */ + getImage: function(url, width = 400, height = 400) { + if(url === undefined) { + throw new Error('Missing required parameter: "url"'); + } + + let path = '/avatars/image'; + + let payload = {}; + + if(url) { + payload['url'] = url; + } + + if(width) { + payload['width'] = width; + } + + if(height) { + payload['height'] = height; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get QR Code + * + * Converts a given plain text to a QR code image. You can use the query + * parameters to change the size and style of the resulting image. + * + * @param {string} text + * @param {number} size + * @param {number} margin + * @param {number} download + * @throws {Error} + * @return {Promise} + */ + getQR: function(text, size = 400, margin = 1, download = 0) { + if(text === undefined) { + throw new Error('Missing required parameter: "text"'); + } + + let path = '/avatars/qr'; + + let payload = {}; + + if(text) { + payload['text'] = text; + } + + if(size) { + payload['size'] = size; + } + + if(margin) { + payload['margin'] = margin; + } + + if(download) { + payload['download'] = download; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + } + }; + + let database = { + + /** + * List Collections + * + * Get a list of all the user collections. You can use the query params to + * filter your results. On admin mode, this endpoint will return a list of all + * of the project collections. [Learn more about different API + * modes](/docs/admin). + * + * @param {string} search + * @param {number} limit + * @param {number} offset + * @param {string} orderType + * @throws {Error} + * @return {Promise} + */ + listCollections: function(search = '', limit = 25, offset = 0, orderType = 'ASC') { + let path = '/database/collections'; + + let payload = {}; + + if(search) { + payload['search'] = search; + } + + if(limit) { + payload['limit'] = limit; + } + + if(offset) { + payload['offset'] = offset; + } + + if(orderType) { + payload['orderType'] = orderType; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Collection + * + * Create a new Collection. + * + * @param {string} name + * @param {array} read + * @param {array} write + * @param {array} rules + * @throws {Error} + * @return {Promise} + */ + createCollection: function(name, read, write, rules) { + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + if(read === undefined) { + throw new Error('Missing required parameter: "read"'); + } + + if(write === undefined) { + throw new Error('Missing required parameter: "write"'); + } + + if(rules === undefined) { + throw new Error('Missing required parameter: "rules"'); + } + + let path = '/database/collections'; + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(read) { + payload['read'] = read; + } + + if(write) { + payload['write'] = write; + } + + if(rules) { + payload['rules'] = rules; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Collection + * + * Get collection by its unique ID. This endpoint response returns a JSON + * object with the collection metadata. + * + * @param {string} collectionId + * @throws {Error} + * @return {Promise} + */ + getCollection: function(collectionId) { + if(collectionId === undefined) { + throw new Error('Missing required parameter: "collectionId"'); + } + + let path = '/database/collections/{collectionId}'.replace(new RegExp('{collectionId}', 'g'), collectionId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Collection + * + * Update collection by its unique ID. + * + * @param {string} collectionId + * @param {string} name + * @param {array} read + * @param {array} write + * @param {array} rules + * @throws {Error} + * @return {Promise} + */ + updateCollection: function(collectionId, name, read, write, rules = []) { + if(collectionId === undefined) { + throw new Error('Missing required parameter: "collectionId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + if(read === undefined) { + throw new Error('Missing required parameter: "read"'); + } + + if(write === undefined) { + throw new Error('Missing required parameter: "write"'); + } + + let path = '/database/collections/{collectionId}'.replace(new RegExp('{collectionId}', 'g'), collectionId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(read) { + payload['read'] = read; + } + + if(write) { + payload['write'] = write; + } + + if(rules) { + payload['rules'] = rules; + } + + return http + .put(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Collection + * + * Delete a collection by its unique ID. Only users with write permissions + * have access to delete this resource. + * + * @param {string} collectionId + * @throws {Error} + * @return {Promise} + */ + deleteCollection: function(collectionId) { + if(collectionId === undefined) { + throw new Error('Missing required parameter: "collectionId"'); + } + + let path = '/database/collections/{collectionId}'.replace(new RegExp('{collectionId}', 'g'), collectionId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Documents + * + * Get a list of all the user documents. You can use the query params to + * filter your results. On admin mode, this endpoint will return a list of all + * of the project documents. [Learn more about different API + * modes](/docs/admin). + * + * @param {string} collectionId + * @param {array} filters + * @param {number} offset + * @param {number} limit + * @param {string} orderField + * @param {string} orderType + * @param {string} orderCast + * @param {string} search + * @param {number} first + * @param {number} last + * @throws {Error} + * @return {Promise} + */ + listDocuments: function(collectionId, filters = [], offset = 0, limit = 50, orderField = '$id', orderType = 'ASC', orderCast = 'string', search = '', first = 0, last = 0) { + if(collectionId === undefined) { + throw new Error('Missing required parameter: "collectionId"'); + } + + 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(search) { + payload['search'] = search; + } + + if(first) { + payload['first'] = first; + } + + if(last) { + payload['last'] = last; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Document + * + * Create a new Document. + * + * @param {string} collectionId + * @param {object} data + * @param {array} read + * @param {array} write + * @param {string} parentDocument + * @param {string} parentProperty + * @param {string} parentPropertyType + * @throws {Error} + * @return {Promise} + */ + createDocument: function(collectionId, data, read, write, parentDocument = '', parentProperty = '', parentPropertyType = 'assign') { + if(collectionId === undefined) { + throw new Error('Missing required parameter: "collectionId"'); + } + + if(data === undefined) { + throw new Error('Missing required parameter: "data"'); + } + + if(read === undefined) { + throw new Error('Missing required parameter: "read"'); + } + + if(write === undefined) { + throw new Error('Missing required parameter: "write"'); + } + + let path = '/database/collections/{collectionId}/documents'.replace(new RegExp('{collectionId}', 'g'), collectionId); + + let payload = {}; + + if(data) { + payload['data'] = data; + } + + if(read) { + payload['read'] = read; + } + + if(write) { + payload['write'] = write; + } + + if(parentDocument) { + payload['parentDocument'] = parentDocument; + } + + if(parentProperty) { + payload['parentProperty'] = parentProperty; + } + + if(parentPropertyType) { + payload['parentPropertyType'] = parentPropertyType; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Document + * + * Get document by its unique ID. This endpoint response returns a JSON object + * with the document data. + * + * @param {string} collectionId + * @param {string} documentId + * @throws {Error} + * @return {Promise} + */ + getDocument: function(collectionId, documentId) { + if(collectionId === undefined) { + throw new Error('Missing required parameter: "collectionId"'); + } + + if(documentId === undefined) { + throw new Error('Missing required parameter: "documentId"'); + } + + let path = '/database/collections/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Document + * + * + * @param {string} collectionId + * @param {string} documentId + * @param {object} data + * @param {array} read + * @param {array} write + * @throws {Error} + * @return {Promise} + */ + updateDocument: function(collectionId, documentId, data, read, write) { + if(collectionId === undefined) { + throw new Error('Missing required parameter: "collectionId"'); + } + + if(documentId === undefined) { + throw new Error('Missing required parameter: "documentId"'); + } + + if(data === undefined) { + throw new Error('Missing required parameter: "data"'); + } + + if(read === undefined) { + throw new Error('Missing required parameter: "read"'); + } + + if(write === undefined) { + throw new Error('Missing required parameter: "write"'); + } + + let path = '/database/collections/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId); + + let payload = {}; + + if(data) { + payload['data'] = data; + } + + if(read) { + payload['read'] = read; + } + + if(write) { + payload['write'] = write; + } + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Document + * + * Delete document by its unique ID. This endpoint deletes only the parent + * documents, his attributes and relations to other documents. Child documents + * **will not** be deleted. + * + * @param {string} collectionId + * @param {string} documentId + * @throws {Error} + * @return {Promise} + */ + deleteDocument: function(collectionId, documentId) { + if(collectionId === undefined) { + throw new Error('Missing required parameter: "collectionId"'); + } + + if(documentId === undefined) { + throw new Error('Missing required parameter: "documentId"'); + } + + let path = '/database/collections/{collectionId}/documents/{documentId}'.replace(new RegExp('{collectionId}', 'g'), collectionId).replace(new RegExp('{documentId}', 'g'), documentId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + } + }; + + let locale = { + + /** + * Get User Locale + * + * Get the current user location based on IP. Returns an object with user + * country code, country name, continent name, continent code, ip address and + * suggested currency. You can use the locale header to get the data in a + * supported language. + * + * ([IP Geolocation by DB-IP](https://db-ip.com)) + * + * @throws {Error} + * @return {Promise} + */ + get: function() { + let path = '/locale'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Countries + * + * List of all continents. You can use the locale header to get the data in a + * supported language. + * + * @throws {Error} + * @return {Promise} + */ + getContinents: function() { + let path = '/locale/continents'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Countries + * + * List of all countries. You can use the locale header to get the data in a + * supported language. + * + * @throws {Error} + * @return {Promise} + */ + getCountries: function() { + let path = '/locale/countries'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List EU Countries + * + * List of all countries that are currently members of the EU. You can use the + * locale header to get the data in a supported language. + * + * @throws {Error} + * @return {Promise} + */ + getCountriesEU: function() { + let path = '/locale/countries/eu'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Countries Phone Codes + * + * List of all countries phone codes. You can use the locale header to get the + * data in a supported language. + * + * @throws {Error} + * @return {Promise} + */ + getCountriesPhones: function() { + let path = '/locale/countries/phones'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Currencies + * + * List of all currencies, including currency symol, name, plural, and decimal + * digits for all major and minor currencies. You can use the locale header to + * get the data in a supported language. + * + * @throws {Error} + * @return {Promise} + */ + getCurrencies: function() { + let path = '/locale/currencies'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + } + }; + + let projects = { + + /** + * List Projects + * + * + * @throws {Error} + * @return {Promise} + */ + list: function() { + let path = '/projects'; + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Project + * + * + * @param {string} name + * @param {string} teamId + * @param {string} description + * @param {string} logo + * @param {string} url + * @param {string} legalName + * @param {string} legalCountry + * @param {string} legalState + * @param {string} legalCity + * @param {string} legalAddress + * @param {string} legalTaxId + * @throws {Error} + * @return {Promise} + */ + create: function(name, teamId, description = '', logo = '', url = '', legalName = '', legalCountry = '', legalState = '', legalCity = '', legalAddress = '', legalTaxId = '') { + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + if(teamId === undefined) { + throw new Error('Missing required parameter: "teamId"'); + } + + let path = '/projects'; + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(teamId) { + payload['teamId'] = teamId; + } + + if(description) { + payload['description'] = description; + } + + if(logo) { + payload['logo'] = logo; + } + + if(url) { + payload['url'] = url; + } + + if(legalName) { + payload['legalName'] = legalName; + } + + if(legalCountry) { + payload['legalCountry'] = legalCountry; + } + + if(legalState) { + payload['legalState'] = legalState; + } + + if(legalCity) { + payload['legalCity'] = legalCity; + } + + if(legalAddress) { + payload['legalAddress'] = legalAddress; + } + + if(legalTaxId) { + payload['legalTaxId'] = legalTaxId; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Project + * + * + * @param {string} projectId + * @throws {Error} + * @return {Promise} + */ + get: function(projectId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + let path = '/projects/{projectId}'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Project + * + * + * @param {string} projectId + * @param {string} name + * @param {string} description + * @param {string} logo + * @param {string} url + * @param {string} legalName + * @param {string} legalCountry + * @param {string} legalState + * @param {string} legalCity + * @param {string} legalAddress + * @param {string} legalTaxId + * @throws {Error} + * @return {Promise} + */ + update: function(projectId, name, description = '', logo = '', url = '', legalName = '', legalCountry = '', legalState = '', legalCity = '', legalAddress = '', legalTaxId = '') { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + let path = '/projects/{projectId}'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(description) { + payload['description'] = description; + } + + if(logo) { + payload['logo'] = logo; + } + + if(url) { + payload['url'] = url; + } + + if(legalName) { + payload['legalName'] = legalName; + } + + if(legalCountry) { + payload['legalCountry'] = legalCountry; + } + + if(legalState) { + payload['legalState'] = legalState; + } + + if(legalCity) { + payload['legalCity'] = legalCity; + } + + if(legalAddress) { + payload['legalAddress'] = legalAddress; + } + + if(legalTaxId) { + payload['legalTaxId'] = legalTaxId; + } + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Project + * + * + * @param {string} projectId + * @param {string} password + * @throws {Error} + * @return {Promise} + */ + delete: function(projectId, password) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(password === undefined) { + throw new Error('Missing required parameter: "password"'); + } + + let path = '/projects/{projectId}'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + if(password) { + payload['password'] = password; + } + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Domains + * + * + * @param {string} projectId + * @throws {Error} + * @return {Promise} + */ + listDomains: function(projectId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + let path = '/projects/{projectId}/domains'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Domain + * + * + * @param {string} projectId + * @param {string} domain + * @throws {Error} + * @return {Promise} + */ + createDomain: function(projectId, domain) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(domain === undefined) { + throw new Error('Missing required parameter: "domain"'); + } + + let path = '/projects/{projectId}/domains'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + if(domain) { + payload['domain'] = domain; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Domain + * + * + * @param {string} projectId + * @param {string} domainId + * @throws {Error} + * @return {Promise} + */ + getDomain: function(projectId, domainId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(domainId === undefined) { + throw new Error('Missing required parameter: "domainId"'); + } + + let path = '/projects/{projectId}/domains/{domainId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{domainId}', 'g'), domainId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Domain + * + * + * @param {string} projectId + * @param {string} domainId + * @throws {Error} + * @return {Promise} + */ + deleteDomain: function(projectId, domainId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(domainId === undefined) { + throw new Error('Missing required parameter: "domainId"'); + } + + let path = '/projects/{projectId}/domains/{domainId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{domainId}', 'g'), domainId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Domain Verification Status + * + * + * @param {string} projectId + * @param {string} domainId + * @throws {Error} + * @return {Promise} + */ + updateDomainVerification: function(projectId, domainId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(domainId === undefined) { + throw new Error('Missing required parameter: "domainId"'); + } + + let path = '/projects/{projectId}/domains/{domainId}/verification'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{domainId}', 'g'), domainId); + + let payload = {}; + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Keys + * + * + * @param {string} projectId + * @throws {Error} + * @return {Promise} + */ + listKeys: function(projectId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + let path = '/projects/{projectId}/keys'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Key + * + * + * @param {string} projectId + * @param {string} name + * @param {array} scopes + * @throws {Error} + * @return {Promise} + */ + createKey: function(projectId, name, scopes) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + if(scopes === undefined) { + throw new Error('Missing required parameter: "scopes"'); + } + + let path = '/projects/{projectId}/keys'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(scopes) { + payload['scopes'] = scopes; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Key + * + * + * @param {string} projectId + * @param {string} keyId + * @throws {Error} + * @return {Promise} + */ + getKey: function(projectId, keyId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(keyId === undefined) { + throw new Error('Missing required parameter: "keyId"'); + } + + let path = '/projects/{projectId}/keys/{keyId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{keyId}', 'g'), keyId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Key + * + * + * @param {string} projectId + * @param {string} keyId + * @param {string} name + * @param {array} scopes + * @throws {Error} + * @return {Promise} + */ + updateKey: function(projectId, keyId, name, scopes) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(keyId === undefined) { + throw new Error('Missing required parameter: "keyId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + if(scopes === undefined) { + throw new Error('Missing required parameter: "scopes"'); + } + + let path = '/projects/{projectId}/keys/{keyId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{keyId}', 'g'), keyId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(scopes) { + payload['scopes'] = scopes; + } + + return http + .put(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Key + * + * + * @param {string} projectId + * @param {string} keyId + * @throws {Error} + * @return {Promise} + */ + deleteKey: function(projectId, keyId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(keyId === undefined) { + throw new Error('Missing required parameter: "keyId"'); + } + + let path = '/projects/{projectId}/keys/{keyId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{keyId}', 'g'), keyId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Project OAuth2 + * + * + * @param {string} projectId + * @param {string} provider + * @param {string} appId + * @param {string} secret + * @throws {Error} + * @return {Promise} + */ + updateOAuth2: function(projectId, provider, appId = '', secret = '') { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(provider === undefined) { + throw new Error('Missing required parameter: "provider"'); + } + + let path = '/projects/{projectId}/oauth2'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + if(provider) { + payload['provider'] = provider; + } + + if(appId) { + payload['appId'] = appId; + } + + if(secret) { + payload['secret'] = secret; + } + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Platforms + * + * + * @param {string} projectId + * @throws {Error} + * @return {Promise} + */ + listPlatforms: function(projectId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + let path = '/projects/{projectId}/platforms'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Platform + * + * + * @param {string} projectId + * @param {string} type + * @param {string} name + * @param {string} key + * @param {string} store + * @param {string} url + * @throws {Error} + * @return {Promise} + */ + createPlatform: function(projectId, type, name, key = '', store = '', url = '') { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(type === undefined) { + throw new Error('Missing required parameter: "type"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + let path = '/projects/{projectId}/platforms'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + if(type) { + payload['type'] = type; + } + + if(name) { + payload['name'] = name; + } + + if(key) { + payload['key'] = key; + } + + if(store) { + payload['store'] = store; + } + + if(url) { + payload['url'] = url; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Platform + * + * + * @param {string} projectId + * @param {string} platformId + * @throws {Error} + * @return {Promise} + */ + getPlatform: function(projectId, platformId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(platformId === undefined) { + throw new Error('Missing required parameter: "platformId"'); + } + + let path = '/projects/{projectId}/platforms/{platformId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{platformId}', 'g'), platformId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Platform + * + * + * @param {string} projectId + * @param {string} platformId + * @param {string} name + * @param {string} key + * @param {string} store + * @param {string} url + * @throws {Error} + * @return {Promise} + */ + updatePlatform: function(projectId, platformId, name, key = '', store = '', url = '') { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(platformId === undefined) { + throw new Error('Missing required parameter: "platformId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + let path = '/projects/{projectId}/platforms/{platformId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{platformId}', 'g'), platformId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(key) { + payload['key'] = key; + } + + if(store) { + payload['store'] = store; + } + + if(url) { + payload['url'] = url; + } + + return http + .put(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Platform + * + * + * @param {string} projectId + * @param {string} platformId + * @throws {Error} + * @return {Promise} + */ + deletePlatform: function(projectId, platformId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(platformId === undefined) { + throw new Error('Missing required parameter: "platformId"'); + } + + let path = '/projects/{projectId}/platforms/{platformId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{platformId}', 'g'), platformId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Tasks + * + * + * @param {string} projectId + * @throws {Error} + * @return {Promise} + */ + listTasks: function(projectId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + let path = '/projects/{projectId}/tasks'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Task + * + * + * @param {string} projectId + * @param {string} name + * @param {string} status + * @param {string} schedule + * @param {number} security + * @param {string} httpMethod + * @param {string} httpUrl + * @param {array} httpHeaders + * @param {string} httpUser + * @param {string} httpPass + * @throws {Error} + * @return {Promise} + */ + createTask: function(projectId, name, status, schedule, security, httpMethod, httpUrl, httpHeaders = [], httpUser = '', httpPass = '') { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + if(status === undefined) { + throw new Error('Missing required parameter: "status"'); + } + + if(schedule === undefined) { + throw new Error('Missing required parameter: "schedule"'); + } + + if(security === undefined) { + throw new Error('Missing required parameter: "security"'); + } + + if(httpMethod === undefined) { + throw new Error('Missing required parameter: "httpMethod"'); + } + + if(httpUrl === undefined) { + throw new Error('Missing required parameter: "httpUrl"'); + } + + let path = '/projects/{projectId}/tasks'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(status) { + payload['status'] = status; + } + + if(schedule) { + payload['schedule'] = schedule; + } + + if(security) { + payload['security'] = security; + } + + if(httpMethod) { + payload['httpMethod'] = httpMethod; + } + + if(httpUrl) { + payload['httpUrl'] = httpUrl; + } + + if(httpHeaders) { + payload['httpHeaders'] = httpHeaders; + } + + if(httpUser) { + payload['httpUser'] = httpUser; + } + + if(httpPass) { + payload['httpPass'] = httpPass; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Task + * + * + * @param {string} projectId + * @param {string} taskId + * @throws {Error} + * @return {Promise} + */ + getTask: function(projectId, taskId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(taskId === undefined) { + throw new Error('Missing required parameter: "taskId"'); + } + + let path = '/projects/{projectId}/tasks/{taskId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{taskId}', 'g'), taskId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Task + * + * + * @param {string} projectId + * @param {string} taskId + * @param {string} name + * @param {string} status + * @param {string} schedule + * @param {number} security + * @param {string} httpMethod + * @param {string} httpUrl + * @param {array} httpHeaders + * @param {string} httpUser + * @param {string} httpPass + * @throws {Error} + * @return {Promise} + */ + updateTask: function(projectId, taskId, name, status, schedule, security, httpMethod, httpUrl, httpHeaders = [], httpUser = '', httpPass = '') { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(taskId === undefined) { + throw new Error('Missing required parameter: "taskId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + if(status === undefined) { + throw new Error('Missing required parameter: "status"'); + } + + if(schedule === undefined) { + throw new Error('Missing required parameter: "schedule"'); + } + + if(security === undefined) { + throw new Error('Missing required parameter: "security"'); + } + + if(httpMethod === undefined) { + throw new Error('Missing required parameter: "httpMethod"'); + } + + if(httpUrl === undefined) { + throw new Error('Missing required parameter: "httpUrl"'); + } + + let path = '/projects/{projectId}/tasks/{taskId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{taskId}', 'g'), taskId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(status) { + payload['status'] = status; + } + + if(schedule) { + payload['schedule'] = schedule; + } + + if(security) { + payload['security'] = security; + } + + if(httpMethod) { + payload['httpMethod'] = httpMethod; + } + + if(httpUrl) { + payload['httpUrl'] = httpUrl; + } + + if(httpHeaders) { + payload['httpHeaders'] = httpHeaders; + } + + if(httpUser) { + payload['httpUser'] = httpUser; + } + + if(httpPass) { + payload['httpPass'] = httpPass; + } + + return http + .put(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Task + * + * + * @param {string} projectId + * @param {string} taskId + * @throws {Error} + * @return {Promise} + */ + deleteTask: function(projectId, taskId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(taskId === undefined) { + throw new Error('Missing required parameter: "taskId"'); + } + + let path = '/projects/{projectId}/tasks/{taskId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{taskId}', 'g'), taskId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Project + * + * + * @param {string} projectId + * @throws {Error} + * @return {Promise} + */ + getUsage: function(projectId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + let path = '/projects/{projectId}/usage'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * List Webhooks + * + * + * @param {string} projectId + * @throws {Error} + * @return {Promise} + */ + listWebhooks: function(projectId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + let path = '/projects/{projectId}/webhooks'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Webhook + * + * + * @param {string} projectId + * @param {string} name + * @param {array} events + * @param {string} url + * @param {number} security + * @param {string} httpUser + * @param {string} httpPass + * @throws {Error} + * @return {Promise} + */ + createWebhook: function(projectId, name, events, url, security, httpUser = '', httpPass = '') { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + if(events === undefined) { + throw new Error('Missing required parameter: "events"'); + } + + if(url === undefined) { + throw new Error('Missing required parameter: "url"'); + } + + if(security === undefined) { + throw new Error('Missing required parameter: "security"'); + } + + let path = '/projects/{projectId}/webhooks'.replace(new RegExp('{projectId}', 'g'), projectId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(events) { + payload['events'] = events; + } + + if(url) { + payload['url'] = url; + } + + if(security) { + payload['security'] = security; + } + + if(httpUser) { + payload['httpUser'] = httpUser; + } + + if(httpPass) { + payload['httpPass'] = httpPass; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Webhook + * + * + * @param {string} projectId + * @param {string} webhookId + * @throws {Error} + * @return {Promise} + */ + getWebhook: function(projectId, webhookId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(webhookId === undefined) { + throw new Error('Missing required parameter: "webhookId"'); + } + + let path = '/projects/{projectId}/webhooks/{webhookId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{webhookId}', 'g'), webhookId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Webhook + * + * + * @param {string} projectId + * @param {string} webhookId + * @param {string} name + * @param {array} events + * @param {string} url + * @param {number} security + * @param {string} httpUser + * @param {string} httpPass + * @throws {Error} + * @return {Promise} + */ + updateWebhook: function(projectId, webhookId, name, events, url, security, httpUser = '', httpPass = '') { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(webhookId === undefined) { + throw new Error('Missing required parameter: "webhookId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + if(events === undefined) { + throw new Error('Missing required parameter: "events"'); + } + + if(url === undefined) { + throw new Error('Missing required parameter: "url"'); + } + + if(security === undefined) { + throw new Error('Missing required parameter: "security"'); + } + + let path = '/projects/{projectId}/webhooks/{webhookId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{webhookId}', 'g'), webhookId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(events) { + payload['events'] = events; + } + + if(url) { + payload['url'] = url; + } + + if(security) { + payload['security'] = security; + } + + if(httpUser) { + payload['httpUser'] = httpUser; + } + + if(httpPass) { + payload['httpPass'] = httpPass; + } + + return http + .put(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Webhook + * + * + * @param {string} projectId + * @param {string} webhookId + * @throws {Error} + * @return {Promise} + */ + deleteWebhook: function(projectId, webhookId) { + if(projectId === undefined) { + throw new Error('Missing required parameter: "projectId"'); + } + + if(webhookId === undefined) { + throw new Error('Missing required parameter: "webhookId"'); + } + + let path = '/projects/{projectId}/webhooks/{webhookId}'.replace(new RegExp('{projectId}', 'g'), projectId).replace(new RegExp('{webhookId}', 'g'), webhookId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + } + }; + + let storage = { + + /** + * List Files + * + * Get a list of all the user files. You can use the query params to filter + * your results. On admin mode, this endpoint will return a list of all of the + * project files. [Learn more about different API modes](/docs/admin). + * + * @param {string} search + * @param {number} limit + * @param {number} offset + * @param {string} orderType + * @throws {Error} + * @return {Promise} + */ + listFiles: function(search = '', limit = 25, offset = 0, orderType = 'ASC') { + let path = '/storage/files'; + + let payload = {}; + + if(search) { + payload['search'] = search; + } + + if(limit) { + payload['limit'] = limit; + } + + if(offset) { + payload['offset'] = offset; + } + + if(orderType) { + payload['orderType'] = orderType; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create File + * + * Create a new file. The user who creates the file will automatically be + * assigned to read and write access unless he has passed custom values for + * read and write arguments. + * + * @param {File} file + * @param {array} read + * @param {array} write + * @throws {Error} + * @return {Promise} + */ + createFile: function(file, read, write) { + if(file === undefined) { + throw new Error('Missing required parameter: "file"'); + } + + if(read === undefined) { + throw new Error('Missing required parameter: "read"'); + } + + if(write === undefined) { + throw new Error('Missing required parameter: "write"'); + } + + let path = '/storage/files'; + + let payload = {}; + + if(file) { + payload['file'] = file; + } + + if(read) { + payload['read'] = read; + } + + if(write) { + payload['write'] = write; + } + + return http + .post(path, { + 'content-type': 'multipart/form-data', + }, payload); + }, + + /** + * Get File + * + * Get file by its unique ID. This endpoint response returns a JSON object + * with the file metadata. + * + * @param {string} fileId + * @throws {Error} + * @return {Promise} + */ + getFile: function(fileId) { + if(fileId === undefined) { + throw new Error('Missing required parameter: "fileId"'); + } + + let path = '/storage/files/{fileId}'.replace(new RegExp('{fileId}', 'g'), fileId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update File + * + * Update file by its unique ID. Only users with write permissions have access + * to update this resource. + * + * @param {string} fileId + * @param {array} read + * @param {array} write + * @throws {Error} + * @return {Promise} + */ + updateFile: function(fileId, read, write) { + if(fileId === undefined) { + throw new Error('Missing required parameter: "fileId"'); + } + + if(read === undefined) { + throw new Error('Missing required parameter: "read"'); + } + + if(write === undefined) { + throw new Error('Missing required parameter: "write"'); + } + + let path = '/storage/files/{fileId}'.replace(new RegExp('{fileId}', 'g'), fileId); + + let payload = {}; + + if(read) { + payload['read'] = read; + } + + if(write) { + payload['write'] = write; + } + + return http + .put(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete File + * + * Delete a file by its unique ID. Only users with write permissions have + * access to delete this resource. + * + * @param {string} fileId + * @throws {Error} + * @return {Promise} + */ + deleteFile: function(fileId) { + if(fileId === undefined) { + throw new Error('Missing required parameter: "fileId"'); + } + + let path = '/storage/files/{fileId}'.replace(new RegExp('{fileId}', 'g'), fileId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get File for Download + * + * Get file content by its unique ID. The endpoint response return with a + * 'Content-Disposition: attachment' header that tells the browser to start + * downloading the file to user downloads directory. + * + * @param {string} fileId + * @throws {Error} + * @return {string} + */ + getFileDownload: function(fileId) { + if(fileId === undefined) { + throw new Error('Missing required parameter: "fileId"'); + } + + let path = '/storage/files/{fileId}/download'.replace(new RegExp('{fileId}', 'g'), fileId); + + let payload = {}; + + payload['project'] = config.project; + + payload['key'] = config.key; + + let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&'); + + return config.endpoint + path + ((query) ? '?' + query : ''); + }, + + /** + * Get File Preview + * + * Get a file preview image. Currently, this method supports preview for image + * files (jpg, png, and gif), other supported formats, like pdf, docs, slides, + * and spreadsheets, will return the file icon image. You can also pass query + * string arguments for cutting and resizing your preview image. + * + * @param {string} fileId + * @param {number} width + * @param {number} height + * @param {number} quality + * @param {string} background + * @param {string} output + * @throws {Error} + * @return {string} + */ + getFilePreview: function(fileId, width = 0, height = 0, quality = 100, background = '', output = '') { + if(fileId === undefined) { + throw new Error('Missing required parameter: "fileId"'); + } + + let path = '/storage/files/{fileId}/preview'.replace(new RegExp('{fileId}', 'g'), fileId); + + let payload = {}; + + if(width) { + payload['width'] = width; + } + + if(height) { + payload['height'] = height; + } + + if(quality) { + payload['quality'] = quality; + } + + if(background) { + payload['background'] = background; + } + + if(output) { + payload['output'] = output; + } + + payload['project'] = config.project; + + payload['key'] = config.key; + + let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&'); + + return config.endpoint + path + ((query) ? '?' + query : ''); + }, + + /** + * Get File for View + * + * Get file content by its unique ID. This endpoint is similar to the download + * method but returns with no 'Content-Disposition: attachment' header. + * + * @param {string} fileId + * @param {string} as + * @throws {Error} + * @return {string} + */ + getFileView: function(fileId, as = '') { + if(fileId === undefined) { + throw new Error('Missing required parameter: "fileId"'); + } + + let path = '/storage/files/{fileId}/view'.replace(new RegExp('{fileId}', 'g'), fileId); + + let payload = {}; + + if(as) { + payload['as'] = as; + } + + payload['project'] = config.project; + + payload['key'] = config.key; + + let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&'); + + return config.endpoint + path + ((query) ? '?' + query : ''); + } + }; + + let teams = { + + /** + * List Teams + * + * Get a list of all the current user teams. You can use the query params to + * filter your results. On admin mode, this endpoint will return a list of all + * of the project teams. [Learn more about different API modes](/docs/admin). + * + * @param {string} search + * @param {number} limit + * @param {number} offset + * @param {string} orderType + * @throws {Error} + * @return {Promise} + */ + list: function(search = '', limit = 25, offset = 0, orderType = 'ASC') { + let path = '/teams'; + + let payload = {}; + + if(search) { + payload['search'] = search; + } + + if(limit) { + payload['limit'] = limit; + } + + if(offset) { + payload['offset'] = offset; + } + + if(orderType) { + payload['orderType'] = orderType; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Team + * + * Create a new team. The user who creates the team will automatically be + * assigned as the owner of the team. The team owner can invite new members, + * who will be able add new owners and update or delete the team from your + * project. + * + * @param {string} name + * @param {array} roles + * @throws {Error} + * @return {Promise} + */ + create: function(name, roles = ["owner"]) { + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + let path = '/teams'; + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + if(roles) { + payload['roles'] = roles; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Team + * + * Get team by its unique ID. All team members have read access for this + * resource. + * + * @param {string} teamId + * @throws {Error} + * @return {Promise} + */ + get: function(teamId) { + if(teamId === undefined) { + throw new Error('Missing required parameter: "teamId"'); + } + + let path = '/teams/{teamId}'.replace(new RegExp('{teamId}', 'g'), teamId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Team + * + * Update team by its unique ID. Only team owners have write access for this + * resource. + * + * @param {string} teamId + * @param {string} name + * @throws {Error} + * @return {Promise} + */ + update: function(teamId, name) { + if(teamId === undefined) { + throw new Error('Missing required parameter: "teamId"'); + } + + if(name === undefined) { + throw new Error('Missing required parameter: "name"'); + } + + let path = '/teams/{teamId}'.replace(new RegExp('{teamId}', 'g'), teamId); + + let payload = {}; + + if(name) { + payload['name'] = name; + } + + return http + .put(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Team + * + * Delete team by its unique ID. Only team owners have write access for this + * resource. + * + * @param {string} teamId + * @throws {Error} + * @return {Promise} + */ + delete: function(teamId) { + if(teamId === undefined) { + throw new Error('Missing required parameter: "teamId"'); + } + + let path = '/teams/{teamId}'.replace(new RegExp('{teamId}', 'g'), teamId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get Team Memberships + * + * Get team members by the team unique ID. All team members have read access + * for this list of resources. + * + * @param {string} teamId + * @throws {Error} + * @return {Promise} + */ + getMemberships: function(teamId) { + if(teamId === undefined) { + throw new Error('Missing required parameter: "teamId"'); + } + + let path = '/teams/{teamId}/memberships'.replace(new RegExp('{teamId}', 'g'), teamId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create Team Membership + * + * Use this endpoint to invite a new member to join your team. An email with a + * link to join the team will be sent to the new member email address if the + * member doesn't exist in the project it will be created automatically. + * + * Use the 'URL' parameter to redirect the user from the invitation email back + * to your app. When the user is redirected, use the [Update Team Membership + * Status](/docs/teams#updateMembershipStatus) endpoint to allow the user to + * accept the invitation to the team. + * + * Please note that in order to avoid a [Redirect + * Attacks](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) + * the only valid redirect URL's are the once from domains you have set when + * added your platforms in the console interface. + * + * @param {string} teamId + * @param {string} email + * @param {array} roles + * @param {string} url + * @param {string} name + * @throws {Error} + * @return {Promise} + */ + createMembership: function(teamId, email, roles, url, name = '') { + if(teamId === undefined) { + throw new Error('Missing required parameter: "teamId"'); + } + + if(email === undefined) { + throw new Error('Missing required parameter: "email"'); + } + + if(roles === undefined) { + throw new Error('Missing required parameter: "roles"'); + } + + if(url === undefined) { + throw new Error('Missing required parameter: "url"'); + } + + let path = '/teams/{teamId}/memberships'.replace(new RegExp('{teamId}', 'g'), teamId); + + let payload = {}; + + if(email) { + payload['email'] = email; + } + + if(name) { + payload['name'] = name; + } + + if(roles) { + payload['roles'] = roles; + } + + if(url) { + payload['url'] = url; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete Team Membership + * + * This endpoint allows a user to leave a team or for a team owner to delete + * the membership of any other team member. You can also use this endpoint to + * delete a user membership even if he didn't accept it. + * + * @param {string} teamId + * @param {string} inviteId + * @throws {Error} + * @return {Promise} + */ + deleteMembership: function(teamId, inviteId) { + if(teamId === undefined) { + throw new Error('Missing required parameter: "teamId"'); + } + + if(inviteId === undefined) { + throw new Error('Missing required parameter: "inviteId"'); + } + + let path = '/teams/{teamId}/memberships/{inviteId}'.replace(new RegExp('{teamId}', 'g'), teamId).replace(new RegExp('{inviteId}', 'g'), inviteId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update Team Membership Status + * + * Use this endpoint to allow a user to accept an invitation to join a team + * after he is being redirected back to your app from the invitation email he + * was sent. + * + * @param {string} teamId + * @param {string} inviteId + * @param {string} userId + * @param {string} secret + * @throws {Error} + * @return {Promise} + */ + updateMembershipStatus: function(teamId, inviteId, userId, secret) { + if(teamId === undefined) { + throw new Error('Missing required parameter: "teamId"'); + } + + if(inviteId === undefined) { + throw new Error('Missing required parameter: "inviteId"'); + } + + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + if(secret === undefined) { + throw new Error('Missing required parameter: "secret"'); + } + + let path = '/teams/{teamId}/memberships/{inviteId}/status'.replace(new RegExp('{teamId}', 'g'), teamId).replace(new RegExp('{inviteId}', 'g'), inviteId); + + let payload = {}; + + if(userId) { + payload['userId'] = userId; + } + + if(secret) { + payload['secret'] = secret; + } + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + } + }; + + let users = { + + /** + * List Users + * + * Get a list of all the project users. You can use the query params to filter + * your results. + * + * @param {string} search + * @param {number} limit + * @param {number} offset + * @param {string} orderType + * @throws {Error} + * @return {Promise} + */ + list: function(search = '', limit = 25, offset = 0, orderType = 'ASC') { + let path = '/users'; + + let payload = {}; + + if(search) { + payload['search'] = search; + } + + if(limit) { + payload['limit'] = limit; + } + + if(offset) { + payload['offset'] = offset; + } + + if(orderType) { + payload['orderType'] = orderType; + } + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Create User + * + * Create a new user. + * + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {Error} + * @return {Promise} + */ + create: function(email, password, name = '') { + if(email === undefined) { + throw new Error('Missing required parameter: "email"'); + } + + if(password === undefined) { + throw new Error('Missing required parameter: "password"'); + } + + let path = '/users'; + + let payload = {}; + + if(email) { + payload['email'] = email; + } + + if(password) { + payload['password'] = password; + } + + if(name) { + payload['name'] = name; + } + + return http + .post(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get User + * + * Get user by its unique ID. + * + * @param {string} userId + * @throws {Error} + * @return {Promise} + */ + get: function(userId) { + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + let path = '/users/{userId}'.replace(new RegExp('{userId}', 'g'), userId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get User Logs + * + * Get user activity logs list by its unique ID. + * + * @param {string} userId + * @throws {Error} + * @return {Promise} + */ + getLogs: function(userId) { + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + let path = '/users/{userId}/logs'.replace(new RegExp('{userId}', 'g'), userId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get User Preferences + * + * Get user preferences by its unique ID. + * + * @param {string} userId + * @throws {Error} + * @return {Promise} + */ + getPrefs: function(userId) { + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + let path = '/users/{userId}/prefs'.replace(new RegExp('{userId}', 'g'), userId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update User Preferences + * + * Update user preferences by its unique ID. You can pass only the specific + * settings you wish to update. + * + * @param {string} userId + * @param {object} prefs + * @throws {Error} + * @return {Promise} + */ + updatePrefs: function(userId, prefs) { + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + if(prefs === undefined) { + throw new Error('Missing required parameter: "prefs"'); + } + + let path = '/users/{userId}/prefs'.replace(new RegExp('{userId}', 'g'), userId); + + let payload = {}; + + if(prefs) { + payload['prefs'] = prefs; + } + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Get User Sessions + * + * Get user sessions list by its unique ID. + * + * @param {string} userId + * @throws {Error} + * @return {Promise} + */ + getSessions: function(userId) { + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + let path = '/users/{userId}/sessions'.replace(new RegExp('{userId}', 'g'), userId); + + let payload = {}; + + return http + .get(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete User Sessions + * + * Delete all user sessions by its unique ID. + * + * @param {string} userId + * @throws {Error} + * @return {Promise} + */ + deleteSessions: function(userId) { + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + let path = '/users/{userId}/sessions'.replace(new RegExp('{userId}', 'g'), userId); + + let payload = {}; + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Delete User Session + * + * Delete user sessions by its unique ID. + * + * @param {string} userId + * @param {string} sessionId + * @throws {Error} + * @return {Promise} + */ + deleteSession: function(userId, sessionId) { + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + if(sessionId === undefined) { + throw new Error('Missing required parameter: "sessionId"'); + } + + let path = '/users/{userId}/sessions/:session'.replace(new RegExp('{userId}', 'g'), userId); + + let payload = {}; + + if(sessionId) { + payload['sessionId'] = sessionId; + } + + return http + .delete(path, { + 'content-type': 'application/json', + }, payload); + }, + + /** + * Update User Status + * + * Update user status by its unique ID. + * + * @param {string} userId + * @param {string} status + * @throws {Error} + * @return {Promise} + */ + updateStatus: function(userId, status) { + if(userId === undefined) { + throw new Error('Missing required parameter: "userId"'); + } + + if(status === undefined) { + throw new Error('Missing required parameter: "status"'); + } + + let path = '/users/{userId}/status'.replace(new RegExp('{userId}', 'g'), userId); + + let payload = {}; + + if(status) { + payload['status'] = status; + } + + return http + .patch(path, { + 'content-type': 'application/json', + }, payload); + } + }; + + return { + setEndpoint: setEndpoint, + setProject: setProject, + setKey: setKey, + setLocale: setLocale, + setMode: setMode, + account: account, + avatars: avatars, + database: database, + locale: locale, + projects: projects, + storage: storage, + teams: teams, + users: users + }; + }; + + if(typeof module !== "undefined") { + module.exports = window.Appwrite; + } + +})((typeof window !== "undefined") ? window : {}); \ No newline at end of file diff --git a/app/sdks/console-javascript/src/sdk.min.js b/app/sdks/console-javascript/src/sdk.min.js new file mode 100644 index 0000000000..69a10cd5af --- /dev/null +++ b/app/sdks/console-javascript/src/sdk.min.js @@ -0,0 +1,361 @@ +(function(window){'use strict';window.Appwrite=function(){let config={endpoint:'https://appwrite.io/v1',project:'',key:'',locale:'',mode:'',};let setEndpoint=function(endpoint){config.endpoint=endpoint;return this};let setProject=function(value){http.addGlobalHeader('X-Appwrite-Project',value);config.project=value;return this};let setKey=function(value){http.addGlobalHeader('X-Appwrite-Key',value);config.key=value;return this};let setLocale=function(value){http.addGlobalHeader('X-Appwrite-Locale',value);config.locale=value;return this};let setMode=function(value){http.addGlobalHeader('X-Appwrite-Mode',value);config.mode=value;return this};let http=function(document){let globalParams=[],globalHeaders=[];let addParam=function(url,param,value){let a=document.createElement('a'),regex=/(?:\?|&|&)+([^=]+)(?:=([^&]*))*/g;let match,str=[];a.href=url;param=encodeURIComponent(param);while(match=regex.exec(a.search))if(param!==match[1])str.push(match[1]+(match[2]?"="+match[2]:""));str.push(param+(value?"="+encodeURIComponent(value):""));a.search=str.join("&");return a.href};let buildQuery=function(params){let str=[];for(let p in params){if(Array.isArray(params[p])){for(let index=0;index