diff --git a/app/controllers/general.php b/app/controllers/general.php index 5892aee47..cd95b74a0 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -16,6 +16,7 @@ use Appwrite\Database\Validator\Authorization; use Appwrite\Network\Validator\Origin; use Appwrite\Utopia\Response\Filters\V06; use Appwrite\Utopia\Response\Filters\V07; +use Appwrite\Utopia\Response\Filters\V08; use Utopia\CLI\Console; Config::setParam('domainVerification', false); @@ -140,6 +141,9 @@ App::init(function ($utopia, $request, $response, $console, $project, $consoleDB case version_compare ($responseFormat , '0.7.2', '<=') : Response::setFilter(new V07()); break; + case version_compare ($responseFormat , '0.8.0', '<=') : + Response::setFilter(new V08()); + break; default: Response::setFilter(null); } diff --git a/public/dist/scripts/app-all.js b/public/dist/scripts/app-all.js index 8941c1987..5f334eb7d 100644 --- a/public/dist/scripts/app-all.js +++ b/public/dist/scripts/app-all.js @@ -5,7 +5,7 @@ function rejected(value){try{step(generator["throw"](value));}catch(e){reject(e) function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected);} step((generator=generator.apply(thisArg,_arguments||[])).next());});} class AppwriteException extends Error{constructor(message,code=0,response=''){super(message);this.name='AppwriteException';this.message=message;this.code=code;this.response=response;}} -class Appwrite{constructor(){this.config={endpoint:'https://appwrite.io/v1',project:'',key:'',jwt:'',locale:'',mode:'',};this.headers={'x-sdk-version':'appwrite:web:2.0.0','X-Appwrite-Response-Format':'0.8.0',};this.account={get:()=>__awaiter(this,void 0,void 0,function*(){let path='/account';let payload={};const uri=new URL(this.config.endpoint+path);return yield this.call('get',uri,{'content-type':'application/json',},payload);}),create:(email,password,name)=>__awaiter(this,void 0,void 0,function*(){if(typeof email==='undefined'){throw new AppwriteException('Missing required parameter: "email"');} +class Appwrite{constructor(){this.config={endpoint:'https://appwrite.io/v1',project:'',key:'',jwt:'',locale:'',mode:'',};this.headers={'x-sdk-version':'appwrite:web:2.0.0','X-Appwrite-Response-Format':'0.9.0',};this.account={get:()=>__awaiter(this,void 0,void 0,function*(){let path='/account';let payload={};const uri=new URL(this.config.endpoint+path);return yield this.call('get',uri,{'content-type':'application/json',},payload);}),create:(email,password,name)=>__awaiter(this,void 0,void 0,function*(){if(typeof email==='undefined'){throw new AppwriteException('Missing required parameter: "email"');} if(typeof password==='undefined'){throw new AppwriteException('Missing required parameter: "password"');} let path='/account';let payload={};if(typeof email!=='undefined'){payload['email']=email;} if(typeof password!=='undefined'){payload['password']=password;} @@ -43,7 +43,8 @@ if(typeof failure!=='undefined'){payload['failure']=failure;} if(typeof scopes!=='undefined'){payload['scopes']=scopes;} const uri=new URL(this.config.endpoint+path);payload['project']=this.config.project;for(const[key,value]of Object.entries(this.flatten(payload))){uri.searchParams.append(key,value);} if(typeof window!=='undefined'&&(window===null||window===void 0?void 0:window.location)){window.location.href=uri.toString();} -else{return uri;}},deleteSession:(sessionId)=>__awaiter(this,void 0,void 0,function*(){if(typeof sessionId==='undefined'){throw new AppwriteException('Missing required parameter: "sessionId"');} +else{return uri;}},getSession:(sessionId)=>__awaiter(this,void 0,void 0,function*(){if(typeof sessionId==='undefined'){throw new AppwriteException('Missing required parameter: "sessionId"');} +let path='/account/sessions/{sessionId}'.replace('{sessionId}',sessionId);let payload={};const uri=new URL(this.config.endpoint+path);return yield this.call('get',uri,{'content-type':'application/json',},payload);}),deleteSession:(sessionId)=>__awaiter(this,void 0,void 0,function*(){if(typeof sessionId==='undefined'){throw new AppwriteException('Missing required parameter: "sessionId"');} let path='/account/sessions/{sessionId}'.replace('{sessionId}',sessionId);let payload={};const uri=new URL(this.config.endpoint+path);return yield this.call('delete',uri,{'content-type':'application/json',},payload);}),createVerification:(url)=>__awaiter(this,void 0,void 0,function*(){if(typeof url==='undefined'){throw new AppwriteException('Missing required parameter: "url"');} let path='/account/verification';let payload={};if(typeof url!=='undefined'){payload['url']=url;} const uri=new URL(this.config.endpoint+path);return yield this.call('post',uri,{'content-type':'application/json',},payload);}),updateVerification:(userId,secret)=>__awaiter(this,void 0,void 0,function*(){if(typeof userId==='undefined'){throw new AppwriteException('Missing required parameter: "userId"');} diff --git a/public/dist/scripts/app-dep.js b/public/dist/scripts/app-dep.js index 07fb8c0d1..4a5f30127 100644 --- a/public/dist/scripts/app-dep.js +++ b/public/dist/scripts/app-dep.js @@ -5,7 +5,7 @@ function rejected(value){try{step(generator["throw"](value));}catch(e){reject(e) function step(result){result.done?resolve(result.value):adopt(result.value).then(fulfilled,rejected);} step((generator=generator.apply(thisArg,_arguments||[])).next());});} class AppwriteException extends Error{constructor(message,code=0,response=''){super(message);this.name='AppwriteException';this.message=message;this.code=code;this.response=response;}} -class Appwrite{constructor(){this.config={endpoint:'https://appwrite.io/v1',project:'',key:'',jwt:'',locale:'',mode:'',};this.headers={'x-sdk-version':'appwrite:web:2.0.0','X-Appwrite-Response-Format':'0.8.0',};this.account={get:()=>__awaiter(this,void 0,void 0,function*(){let path='/account';let payload={};const uri=new URL(this.config.endpoint+path);return yield this.call('get',uri,{'content-type':'application/json',},payload);}),create:(email,password,name)=>__awaiter(this,void 0,void 0,function*(){if(typeof email==='undefined'){throw new AppwriteException('Missing required parameter: "email"');} +class Appwrite{constructor(){this.config={endpoint:'https://appwrite.io/v1',project:'',key:'',jwt:'',locale:'',mode:'',};this.headers={'x-sdk-version':'appwrite:web:2.0.0','X-Appwrite-Response-Format':'0.9.0',};this.account={get:()=>__awaiter(this,void 0,void 0,function*(){let path='/account';let payload={};const uri=new URL(this.config.endpoint+path);return yield this.call('get',uri,{'content-type':'application/json',},payload);}),create:(email,password,name)=>__awaiter(this,void 0,void 0,function*(){if(typeof email==='undefined'){throw new AppwriteException('Missing required parameter: "email"');} if(typeof password==='undefined'){throw new AppwriteException('Missing required parameter: "password"');} let path='/account';let payload={};if(typeof email!=='undefined'){payload['email']=email;} if(typeof password!=='undefined'){payload['password']=password;} @@ -43,7 +43,8 @@ if(typeof failure!=='undefined'){payload['failure']=failure;} if(typeof scopes!=='undefined'){payload['scopes']=scopes;} const uri=new URL(this.config.endpoint+path);payload['project']=this.config.project;for(const[key,value]of Object.entries(this.flatten(payload))){uri.searchParams.append(key,value);} if(typeof window!=='undefined'&&(window===null||window===void 0?void 0:window.location)){window.location.href=uri.toString();} -else{return uri;}},deleteSession:(sessionId)=>__awaiter(this,void 0,void 0,function*(){if(typeof sessionId==='undefined'){throw new AppwriteException('Missing required parameter: "sessionId"');} +else{return uri;}},getSession:(sessionId)=>__awaiter(this,void 0,void 0,function*(){if(typeof sessionId==='undefined'){throw new AppwriteException('Missing required parameter: "sessionId"');} +let path='/account/sessions/{sessionId}'.replace('{sessionId}',sessionId);let payload={};const uri=new URL(this.config.endpoint+path);return yield this.call('get',uri,{'content-type':'application/json',},payload);}),deleteSession:(sessionId)=>__awaiter(this,void 0,void 0,function*(){if(typeof sessionId==='undefined'){throw new AppwriteException('Missing required parameter: "sessionId"');} let path='/account/sessions/{sessionId}'.replace('{sessionId}',sessionId);let payload={};const uri=new URL(this.config.endpoint+path);return yield this.call('delete',uri,{'content-type':'application/json',},payload);}),createVerification:(url)=>__awaiter(this,void 0,void 0,function*(){if(typeof url==='undefined'){throw new AppwriteException('Missing required parameter: "url"');} let path='/account/verification';let payload={};if(typeof url!=='undefined'){payload['url']=url;} const uri=new URL(this.config.endpoint+path);return yield this.call('post',uri,{'content-type':'application/json',},payload);}),updateVerification:(userId,secret)=>__awaiter(this,void 0,void 0,function*(){if(typeof userId==='undefined'){throw new AppwriteException('Missing required parameter: "userId"');} diff --git a/public/scripts/dependencies/appwrite.js b/public/scripts/dependencies/appwrite.js index 1e55df715..c538693f6 100644 --- a/public/scripts/dependencies/appwrite.js +++ b/public/scripts/dependencies/appwrite.js @@ -47,7 +47,7 @@ }; this.headers = { 'x-sdk-version': 'appwrite:web:2.0.0', - 'X-Appwrite-Response-Format': '0.8.0', + 'X-Appwrite-Response-Format': '0.9.0', }; this.account = { /** @@ -448,9 +448,10 @@ * * Use this endpoint to allow a new user to register an anonymous account in * your project. This route will also create a new session for the user. To - * allow the new user to convert an anonymous account to a normal account - * account, you need to update its [email and - * password](/docs/client/account#accountUpdateEmail). + * allow the new user to convert an anonymous account to a normal account, you + * need to update its [email and + * password](/docs/client/account#accountUpdateEmail) or create an [OAuth2 + * session](/docs/client/account#accountCreateOAuth2Session). * * @throws {AppwriteException} * @returns {Promise} @@ -505,6 +506,27 @@ return uri; } }, + /** + * Get Session By ID + * + * Use this endpoint to get a logged in user's session using a Session ID. + * Inputting 'current' will return the current session being used. + * + * @param {string} sessionId + * @throws {AppwriteException} + * @returns {Promise} + */ + getSession: (sessionId) => __awaiter(this, void 0, void 0, function* () { + if (typeof sessionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "sessionId"'); + } + let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + let payload = {}; + const uri = new URL(this.config.endpoint + path); + return yield this.call('get', uri, { + 'content-type': 'application/json', + }, payload); + }), /** * Delete Account Session * diff --git a/src/Appwrite/Utopia/Response/Filters/V06.php b/src/Appwrite/Utopia/Response/Filters/V06.php index 2426916be..d3d5f0329 100644 --- a/src/Appwrite/Utopia/Response/Filters/V06.php +++ b/src/Appwrite/Utopia/Response/Filters/V06.php @@ -12,8 +12,6 @@ use Exception; use Utopia\Config\Config; use Utopia\Locale\Locale as Locale; -use function PHPSTORM_META\map; - class V06 extends Filter { // Convert 0.7 Data format to 0.6 format diff --git a/src/Appwrite/Utopia/Response/Filters/V07.php b/src/Appwrite/Utopia/Response/Filters/V07.php index 36831b473..86465a417 100644 --- a/src/Appwrite/Utopia/Response/Filters/V07.php +++ b/src/Appwrite/Utopia/Response/Filters/V07.php @@ -2,18 +2,9 @@ namespace Appwrite\Utopia\Response\Filters; -use Appwrite\Auth\Auth; -use Appwrite\Database\Database; -use Appwrite\Database\Validator\Authorization; -use Appwrite\OpenSSL\OpenSSL; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Filter; use Exception; -use Utopia\Config\Config; -use Utopia\Locale\Locale as Locale; - -use function PHPSTORM_META\map; - class V07 extends Filter { // Convert 0.8 Data format to 0.7 format @@ -31,8 +22,6 @@ class V07 extends Filter { case Response::MODEL_COLLECTION: case Response::MODEL_FILE_LIST: case Response::MODEL_FILE: - case Response::MODEL_FUNCTION_LIST: - case Response::MODEL_FUNCTION: case Response::MODEL_TAG_LIST: case Response::MODEL_TAG: case Response::MODEL_EXECUTION_LIST: @@ -44,14 +33,34 @@ class V07 extends Filter { case Response::MODEL_SESSION_LIST: /** [FIELDS ADDED in 0.8.x] provider, providerUid, providerToken */ case Response::MODEL_SESSION: /** [FIELDS ADDED in 0.8.x] provider, providerUid, providerToken */ case Response::MODEL_JWT: + case Response::MODEL_LOG: case Response::MODEL_LOG_LIST: case Response::MODEL_TOKEN: case Response::MODEL_LOCALE: + case Response::MODEL_COUNTRY: case Response::MODEL_COUNTRY_LIST: + case Response::MODEL_PHONE: case Response::MODEL_PHONE_LIST: + case Response::MODEL_CONTINENT: case Response::MODEL_CONTINENT_LIST: + case Response::MODEL_CURRENCY: case Response::MODEL_CURRENCY_LIST: + case Response::MODEL_LANGUAGE: case Response::MODEL_LANGUAGE_LIST: + case Response::MODEL_PROJECT: + case Response::MODEL_PROJECT_LIST: + case Response::MODEL_PLATFORM: + case Response::MODEL_PLATFORM_LIST: + case Response::MODEL_DOMAIN: + case Response::MODEL_DOMAIN_LIST: + case Response::MODEL_KEY: + case Response::MODEL_KEY_LIST: + case Response::MODEL_PERMISSIONS: + case Response::MODEL_RULE: + case Response::MODEL_TASK: + case Response::MODEL_WEBHOOK: + case Response::MODEL_WEBHOOK_LIST: + case Response::MODEL_MOCK: case Response::MODEL_ANY: case Response::MODEL_PREFERENCES: /** ANY was replaced by PREFERENCES in 0.8.x but this is backward compatible with 0.7.x */ case Response::MODEL_NONE: @@ -59,6 +68,12 @@ class V07 extends Filter { case Response::MODEL_ERROR_DEV: $parsedResponse = $content; break; + case Response::MODEL_FUNCTION_LIST: /** Function property env was renamed to runtime in 0.9.x */ + $parsedResponse = $this->parseFunctionList($content); + break; + case Response::MODEL_FUNCTION: + $parsedResponse = $this->parseFunctionList($content); /** Function property env was renamed to runtime in 0.9.x */ + break; default: throw new Exception('Received invalid model : '.$model); } @@ -66,4 +81,20 @@ class V07 extends Filter { return $parsedResponse; } + protected function parseFunction(array $content) { + $content['env'] = $content['runtime']; + unset($content['runtime']); + return $content; + } + + protected function parseFunctionList(array $content){ + $functions = $content['functions']; + $parsedResponse = []; + foreach($functions as $function) { + $parsedResponse[] = $this->parseFunction($function); + } + $content['functions'] = $parsedResponse; + return $content; + } + } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Filters/V08.php b/src/Appwrite/Utopia/Response/Filters/V08.php new file mode 100644 index 000000000..32d4cdc83 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Filters/V08.php @@ -0,0 +1,101 @@ +parseFunctionList($content); + break; + case Response::MODEL_FUNCTION: /** Function property env was renamed to runtime in 0.9.x */ + $parsedResponse = $this->parseFunctionList($content); + break; + default: + throw new Exception('Received invalid model : '.$model); + } + + return $parsedResponse; + } + + protected function parseFunction(array $content) { + $content['env'] = $content['runtime']; + unset($content['runtime']); + return $content; + } + + protected function parseFunctionList(array $content){ + $functions = $content['functions']; + $parsedResponse = []; + foreach($functions as $function) { + $parsedResponse[] = $this->parseFunction($function); + } + $content['functions'] = $parsedResponse; + return $content; + } +} \ No newline at end of file