Merge pull request #1340 from appwrite/feat-add-response-filters
feat: add V08 response filter and update web sdk
This commit is contained in:
commit
149462383d
|
@ -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);
|
||||
}
|
||||
|
|
5
public/dist/scripts/app-all.js
vendored
5
public/dist/scripts/app-all.js
vendored
|
@ -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"');}
|
||||
|
|
5
public/dist/scripts/app-dep.js
vendored
5
public/dist/scripts/app-dep.js
vendored
|
@ -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"');}
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
101
src/Appwrite/Utopia/Response/Filters/V08.php
Normal file
101
src/Appwrite/Utopia/Response/Filters/V08.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
|
||||
namespace Appwrite\Utopia\Response\Filters;
|
||||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Filter;
|
||||
use Exception;
|
||||
|
||||
|
||||
class V08 extends Filter {
|
||||
|
||||
// Convert 0.9 Data format to 0.8 format
|
||||
public function parse(array $content, string $model): array {
|
||||
|
||||
$parsedResponse = [];
|
||||
|
||||
switch($model) {
|
||||
|
||||
case Response::MODEL_DOCUMENT_LIST:
|
||||
case Response::MODEL_DOCUMENT:
|
||||
case Response::MODEL_USER_LIST:
|
||||
case Response::MODEL_USER:
|
||||
case Response::MODEL_COLLECTION_LIST:
|
||||
case Response::MODEL_COLLECTION:
|
||||
case Response::MODEL_FILE_LIST:
|
||||
case Response::MODEL_FILE:
|
||||
case Response::MODEL_TAG_LIST:
|
||||
case Response::MODEL_TAG:
|
||||
case Response::MODEL_EXECUTION_LIST:
|
||||
case Response::MODEL_EXECUTION:
|
||||
case Response::MODEL_TEAM_LIST:
|
||||
case Response::MODEL_TEAM:
|
||||
case Response::MODEL_MEMBERSHIP_LIST:
|
||||
case Response::MODEL_MEMBERSHIP:
|
||||
case Response::MODEL_SESSION_LIST:
|
||||
case Response::MODEL_SESSION:
|
||||
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:
|
||||
case Response::MODEL_NONE:
|
||||
case Response::MODEL_ERROR:
|
||||
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: /** 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue