diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index c1168c47c..48ad94826 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -25,8 +25,8 @@ use Appwrite\Utopia\Response; use DeviceDetector\DeviceDetector; use Utopia\Validator\ArrayList; -$oauthDefaultSuccess = '/auth/oauth2/success'; -$oauthDefaultFailure = '/auth/oauth2/failure'; +$oauthDefaultSuccess = App::getEnv('_APP_HOME').'/auth/oauth2/success'; +$oauthDefaultFailure = App::getEnv('_APP_HOME').'/auth/oauth2/failure'; $oauth2Keys = []; diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 1676d3f8e..ea8c179ef 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -16,6 +16,7 @@ App::get('/v1/mock/tests/foo') ->label('sdk.namespace', 'foo') ->label('sdk.method', 'get') ->label('sdk.description', 'Mock a get request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -28,6 +29,7 @@ App::post('/v1/mock/tests/foo') ->label('sdk.namespace', 'foo') ->label('sdk.method', 'post') ->label('sdk.description', 'Mock a post request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -40,6 +42,7 @@ App::patch('/v1/mock/tests/foo') ->label('sdk.namespace', 'foo') ->label('sdk.method', 'patch') ->label('sdk.description', 'Mock a get request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -52,6 +55,7 @@ App::put('/v1/mock/tests/foo') ->label('sdk.namespace', 'foo') ->label('sdk.method', 'put') ->label('sdk.description', 'Mock a put request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -64,6 +68,7 @@ App::delete('/v1/mock/tests/foo') ->label('sdk.namespace', 'foo') ->label('sdk.method', 'delete') ->label('sdk.description', 'Mock a delete request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -76,6 +81,7 @@ App::get('/v1/mock/tests/bar') ->label('sdk.namespace', 'bar') ->label('sdk.method', 'get') ->label('sdk.description', 'Mock a get request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -88,6 +94,7 @@ App::post('/v1/mock/tests/bar') ->label('sdk.namespace', 'bar') ->label('sdk.method', 'post') ->label('sdk.description', 'Mock a post request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -100,6 +107,7 @@ App::patch('/v1/mock/tests/bar') ->label('sdk.namespace', 'bar') ->label('sdk.method', 'patch') ->label('sdk.description', 'Mock a get request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -112,6 +120,7 @@ App::put('/v1/mock/tests/bar') ->label('sdk.namespace', 'bar') ->label('sdk.method', 'put') ->label('sdk.description', 'Mock a put request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -124,6 +133,7 @@ App::delete('/v1/mock/tests/bar') ->label('sdk.namespace', 'bar') ->label('sdk.method', 'delete') ->label('sdk.description', 'Mock a delete request for SDK tests') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -137,6 +147,7 @@ App::post('/v1/mock/tests/general/upload') ->label('sdk.method', 'upload') ->label('sdk.description', 'Mock a delete request for SDK tests') ->label('sdk.consumes', 'multipart/form-data') + ->label('sdk.mock', true) ->param('x', '', function () { return new Text(100); }, 'Sample string param') ->param('y', '', function () { return new Numeric(); }, 'Sample numeric param') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') @@ -174,6 +185,7 @@ App::get('/v1/mock/tests/general/redirect') ->label('sdk.namespace', 'general') ->label('sdk.method', 'redirect') ->label('sdk.description', 'Mock a redirect request for SDK tests') + ->label('sdk.mock', true) ->action(function ($response) { /** @var Utopia\Response $response */ @@ -186,6 +198,7 @@ App::get('/v1/mock/tests/general/redirected') ->label('sdk.namespace', 'general') ->label('sdk.method', 'redirected') ->label('sdk.description', 'Mock a redirected request for SDK tests') + ->label('sdk.mock', true) ->action(function () { }); @@ -195,6 +208,7 @@ App::get('/v1/mock/tests/general/set-cookie') ->label('sdk.namespace', 'general') ->label('sdk.method', 'setCookie') ->label('sdk.description', 'Mock a set cookie request for SDK tests') + ->label('sdk.mock', true) ->action(function ($response) { /** @var Utopia\Response $response */ @@ -207,6 +221,7 @@ App::get('/v1/mock/tests/general/get-cookie') ->label('sdk.namespace', 'general') ->label('sdk.method', 'getCookie') ->label('sdk.description', 'Mock a get cookie request for SDK tests') + ->label('sdk.mock', true) ->action(function ($request) { /** @var Utopia\Request $request */ @@ -221,6 +236,7 @@ App::get('/v1/mock/tests/general/empty') ->label('sdk.namespace', 'general') ->label('sdk.method', 'empty') ->label('sdk.description', 'Mock a redirected request for SDK tests') + ->label('sdk.mock', true) ->action(function ($response) { /** @var Utopia\Response $response */ @@ -232,6 +248,7 @@ App::get('/v1/mock/tests/general/oauth2') ->desc('Mock an OAuth2 login route') ->label('scope', 'public') ->label('docs', false) + ->label('sdk.mock', true) ->param('client_id', '', function () { return new Text(100); }, 'OAuth2 Client ID.') ->param('redirect_uri', '', function () { return new Host(['localhost']); }, 'OAuth2 Redirect URI.') // Important to deny an open redirect attack ->param('scope', '', function () { return new Text(100); }, 'OAuth2 scope list.') @@ -246,6 +263,7 @@ App::get('/v1/mock/tests/general/oauth2/token') ->desc('Mock an OAuth2 login route') ->label('scope', 'public') ->label('docs', false) + ->label('sdk.mock', true) ->param('client_id', '', function () { return new Text(100); }, 'OAuth2 Client ID.') ->param('redirect_uri', '', function () { return new Host(['localhost']); }, 'OAuth2 Redirect URI.') ->param('client_secret', '', function () { return new Text(100); }, 'OAuth2 scope list.') diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index 334d51c3d..b265fe1c8 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -363,6 +363,10 @@ App::get('/open-api-2.json') continue; } + if ($route->getLabel('sdk.mock', false)) { + continue; + } + if (empty($route->getLabel('sdk.namespace', null))) { continue; } diff --git a/app/sdks/client-web/docs/examples/avatars/get-initials.md b/app/sdks/client-web/docs/examples/avatars/get-initials.md index a54310a6a..ef04988e2 100644 --- a/app/sdks/client-web/docs/examples/avatars/get-initials.md +++ b/app/sdks/client-web/docs/examples/avatars/get-initials.md @@ -7,4 +7,4 @@ sdk let result = sdk.avatars.getInitials(); -console.log(result); // Resource URL +console.log(result); // Resource URL \ No newline at end of file diff --git a/app/sdks/client-web/src/sdk.js b/app/sdks/client-web/src/sdk.js index 4bc64c99d..90c9b8021 100644 --- a/app/sdks/client-web/src/sdk.js +++ b/app/sdks/client-web/src/sdk.js @@ -787,16 +787,17 @@ * 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 + * have provided to be attached to the verification email. The provided URL + * should redirect the user back to 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/client/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) + * 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} @@ -1208,60 +1209,6 @@ return config.endpoint + path + ((query) ? '?' + query : ''); }, - /** - * Get User Initials - * - * Use this endpoint to show your user initials avatar icon on your website or - * app. By default, this route will try to print your logged-in user name or - * email initials. You can also overwrite the user name if you pass the 'name' - * parameter. If no name is given and no user is logged, an empty avatar will - * be returned. - * - * You can use the color and background params to change the avatar colors. By - * default, a random theme will be selected. The random theme will persist for - * the user's initials when reloading the same theme will always return for - * the same initials. - * - * @param {string} name - * @param {number} width - * @param {number} height - * @param {string} color - * @param {string} background - * @throws {Error} - * @return {string} - */ - getInitials: function(name = '', width = 500, height = 500, color = '', background = '') { - let path = '/avatars/initials'; - - let payload = {}; - - if(name) { - payload['name'] = name; - } - - if(width) { - payload['width'] = width; - } - - if(height) { - payload['height'] = height; - } - - if(color) { - payload['color'] = color; - } - - if(background) { - payload['background'] = background; - } - - payload['project'] = config.project; - - let query = Object.keys(payload).map(key => key + '=' + encodeURIComponent(payload[key])).join('&'); - - return config.endpoint + path + ((query) ? '?' + query : ''); - }, - /** * Get QR Code * @@ -1271,11 +1218,11 @@ * @param {string} text * @param {number} size * @param {number} margin - * @param {number} download + * @param {boolean} download * @throws {Error} * @return {string} */ - getQR: function(text, size = 400, margin = 1, download = 0) { + getQR: function(text, size = 400, margin = 1, download = false) { if(text === undefined) { throw new Error('Missing required parameter: "text"'); } @@ -1335,18 +1282,16 @@ * * @param {string} collectionId * @param {string[]} filters - * @param {number} offset * @param {number} limit + * @param {number} offset * @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) { + listDocuments: function(collectionId, filters = [], limit = 25, offset = 0, orderField = '$id', orderType = 'ASC', orderCast = 'string', search = '') { if(collectionId === undefined) { throw new Error('Missing required parameter: "collectionId"'); } @@ -1359,14 +1304,14 @@ payload['filters'] = filters; } - if(offset) { - payload['offset'] = offset; - } - if(limit) { payload['limit'] = limit; } + if(offset) { + payload['offset'] = offset; + } + if(orderField) { payload['orderField'] = orderField; } @@ -1383,14 +1328,6 @@ payload['search'] = search; } - if(first) { - payload['first'] = first; - } - - if(last) { - payload['last'] = last; - } - return http .get(path, { 'content-type': 'application/json', diff --git a/app/sdks/client-web/src/sdk.min.js b/app/sdks/client-web/src/sdk.min.js index a19dd9b75..2bc06cc93 100644 --- a/app/sdks/client-web/src/sdk.min.js +++ b/app/sdks/client-web/src/sdk.min.js @@ -79,27 +79,27 @@ query=query.join("&");return config.endpoint+path+((query)?'?'+query:'')},getIma let path='/avatars/image';let payload={};if(url){payload.url=url} if(width){payload.width=width} if(height){payload.height=height} -payload.project=config.project;let query=Object.keys(payload).map(key=>key+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')},getInitials:function(name='',width=500,height=500,color='',background=''){let path='/avatars/initials';let payload={};if(name){payload.name=name} +payload.project=config.project;let query=[];for(let p in payload){if(Array.isArray(payload[p])){for(let index=0;indexkey+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')},getQR:function(text,size=400,margin=1,download=0){if(text===undefined){throw new Error('Missing required parameter: "text"')} +payload.project=config.project;let query=[];for(let p in payload){if(Array.isArray(payload[p])){for(let index=0;index; + listDocuments(collectionId: string, filters: string[], limit: number, offset: number, orderField: string, orderType: string, orderCast: string, search: string): Promise; /** * Create Document diff --git a/app/sdks/console-web/docs/examples/avatars/get-initials.md b/app/sdks/console-web/docs/examples/avatars/get-initials.md index 41f8388e1..dab6417ca 100644 --- a/app/sdks/console-web/docs/examples/avatars/get-initials.md +++ b/app/sdks/console-web/docs/examples/avatars/get-initials.md @@ -8,4 +8,4 @@ sdk let result = sdk.avatars.getInitials(); -console.log(result); // Resource URL +console.log(result); // Resource URL \ No newline at end of file diff --git a/app/sdks/console-web/docs/examples/bar/delete.md b/app/sdks/console-web/docs/examples/bar/delete.md new file mode 100644 index 000000000..c60d7a75f --- /dev/null +++ b/app/sdks/console-web/docs/examples/bar/delete.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.bar.delete('[]', null, []); + +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-web/docs/examples/bar/get.md b/app/sdks/console-web/docs/examples/bar/get.md new file mode 100644 index 000000000..a690ffc03 --- /dev/null +++ b/app/sdks/console-web/docs/examples/bar/get.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.bar.get('[]', null, []); + +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-web/docs/examples/bar/patch.md b/app/sdks/console-web/docs/examples/bar/patch.md new file mode 100644 index 000000000..46ac2d743 --- /dev/null +++ b/app/sdks/console-web/docs/examples/bar/patch.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.bar.patch('[]', null, []); + +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-web/docs/examples/bar/post.md b/app/sdks/console-web/docs/examples/bar/post.md new file mode 100644 index 000000000..4b21090c3 --- /dev/null +++ b/app/sdks/console-web/docs/examples/bar/post.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.bar.post('[]', null, []); + +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-web/docs/examples/bar/put.md b/app/sdks/console-web/docs/examples/bar/put.md new file mode 100644 index 000000000..8eac3ebad --- /dev/null +++ b/app/sdks/console-web/docs/examples/bar/put.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.bar.put('[]', null, []); + +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-web/docs/examples/foo/delete.md b/app/sdks/console-web/docs/examples/foo/delete.md new file mode 100644 index 000000000..715289a5b --- /dev/null +++ b/app/sdks/console-web/docs/examples/foo/delete.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.foo.delete('[]', null, []); + +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-web/docs/examples/foo/get.md b/app/sdks/console-web/docs/examples/foo/get.md new file mode 100644 index 000000000..cb3ee31c9 --- /dev/null +++ b/app/sdks/console-web/docs/examples/foo/get.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.foo.get('[]', null, []); + +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-web/docs/examples/foo/patch.md b/app/sdks/console-web/docs/examples/foo/patch.md new file mode 100644 index 000000000..e39222e71 --- /dev/null +++ b/app/sdks/console-web/docs/examples/foo/patch.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.foo.patch('[]', null, []); + +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-web/docs/examples/foo/post.md b/app/sdks/console-web/docs/examples/foo/post.md new file mode 100644 index 000000000..4c236776f --- /dev/null +++ b/app/sdks/console-web/docs/examples/foo/post.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.foo.post('[]', null, []); + +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-web/docs/examples/foo/put.md b/app/sdks/console-web/docs/examples/foo/put.md new file mode 100644 index 000000000..d13c4c44f --- /dev/null +++ b/app/sdks/console-web/docs/examples/foo/put.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.foo.put('[]', null, []); + +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-web/docs/examples/functions/create-tag.md b/app/sdks/console-web/docs/examples/functions/create-tag.md index 4b60270a9..6f08f7a10 100644 --- a/app/sdks/console-web/docs/examples/functions/create-tag.md +++ b/app/sdks/console-web/docs/examples/functions/create-tag.md @@ -6,7 +6,7 @@ sdk .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -let promise = sdk.functions.createTag('[FUNCTION_ID]', 'node-14', '[COMMAND]', '[CODE]'); +let promise = sdk.functions.createTag('[FUNCTION_ID]', '[COMMAND]', '[CODE]'); promise.then(function (response) { console.log(response); // Success diff --git a/app/sdks/console-web/docs/examples/functions/create.md b/app/sdks/console-web/docs/examples/functions/create.md index 768f20cc5..6fb506816 100644 --- a/app/sdks/console-web/docs/examples/functions/create.md +++ b/app/sdks/console-web/docs/examples/functions/create.md @@ -6,7 +6,7 @@ sdk .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -let promise = sdk.functions.create('[NAME]'); +let promise = sdk.functions.create('[NAME]', 'node-14'); promise.then(function (response) { console.log(response); // Success diff --git a/app/sdks/console-web/docs/examples/general/empty.md b/app/sdks/console-web/docs/examples/general/empty.md new file mode 100644 index 000000000..50fd0e8a5 --- /dev/null +++ b/app/sdks/console-web/docs/examples/general/empty.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.general.empty(); + +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-web/docs/examples/general/get-cookie.md b/app/sdks/console-web/docs/examples/general/get-cookie.md new file mode 100644 index 000000000..5785a0323 --- /dev/null +++ b/app/sdks/console-web/docs/examples/general/get-cookie.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.general.getCookie(); + +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-web/docs/examples/general/redirect.md b/app/sdks/console-web/docs/examples/general/redirect.md new file mode 100644 index 000000000..769533f6f --- /dev/null +++ b/app/sdks/console-web/docs/examples/general/redirect.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.general.redirect(); + +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-web/docs/examples/general/redirected.md b/app/sdks/console-web/docs/examples/general/redirected.md new file mode 100644 index 000000000..712e614ac --- /dev/null +++ b/app/sdks/console-web/docs/examples/general/redirected.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.general.redirected(); + +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-web/docs/examples/general/set-cookie.md b/app/sdks/console-web/docs/examples/general/set-cookie.md new file mode 100644 index 000000000..ee0f85cc1 --- /dev/null +++ b/app/sdks/console-web/docs/examples/general/set-cookie.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.general.setCookie(); + +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-web/docs/examples/general/upload.md b/app/sdks/console-web/docs/examples/general/upload.md new file mode 100644 index 000000000..bbc2bee92 --- /dev/null +++ b/app/sdks/console-web/docs/examples/general/upload.md @@ -0,0 +1,15 @@ +let sdk = new Appwrite(); + +sdk + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +let promise = sdk.general.upload('[]', null, [], 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-web/docs/examples/projects/create-task.md b/app/sdks/console-web/docs/examples/projects/create-task.md index 5698d000e..9b0f3c1e0 100644 --- a/app/sdks/console-web/docs/examples/projects/create-task.md +++ b/app/sdks/console-web/docs/examples/projects/create-task.md @@ -6,7 +6,7 @@ sdk .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -let promise = sdk.projects.createTask('[PROJECT_ID]', '[NAME]', 'play', '', 0, 'GET', 'https://example.com'); +let promise = sdk.projects.createTask('[PROJECT_ID]', '[NAME]', 'play', '', false, 'GET', 'https://example.com'); promise.then(function (response) { console.log(response); // Success diff --git a/app/sdks/console-web/docs/examples/projects/create-webhook.md b/app/sdks/console-web/docs/examples/projects/create-webhook.md index 728786f9f..be722f3db 100644 --- a/app/sdks/console-web/docs/examples/projects/create-webhook.md +++ b/app/sdks/console-web/docs/examples/projects/create-webhook.md @@ -6,7 +6,7 @@ sdk .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -let promise = sdk.projects.createWebhook('[PROJECT_ID]', '[NAME]', [], '[URL]', 0); +let promise = sdk.projects.createWebhook('[PROJECT_ID]', '[NAME]', [], 'https://example.com', false); promise.then(function (response) { console.log(response); // Success diff --git a/app/sdks/console-web/docs/examples/projects/update-task.md b/app/sdks/console-web/docs/examples/projects/update-task.md index dc95cfda9..38744a36b 100644 --- a/app/sdks/console-web/docs/examples/projects/update-task.md +++ b/app/sdks/console-web/docs/examples/projects/update-task.md @@ -6,7 +6,7 @@ sdk .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -let promise = sdk.projects.updateTask('[PROJECT_ID]', '[TASK_ID]', '[NAME]', 'play', '', 0, 'GET', 'https://example.com'); +let promise = sdk.projects.updateTask('[PROJECT_ID]', '[TASK_ID]', '[NAME]', 'play', '', false, 'GET', 'https://example.com'); promise.then(function (response) { console.log(response); // Success diff --git a/app/sdks/console-web/docs/examples/projects/update-webhook.md b/app/sdks/console-web/docs/examples/projects/update-webhook.md index b1ead71e9..cdef2ec47 100644 --- a/app/sdks/console-web/docs/examples/projects/update-webhook.md +++ b/app/sdks/console-web/docs/examples/projects/update-webhook.md @@ -6,7 +6,7 @@ sdk .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -let promise = sdk.projects.updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], '[URL]', 0); +let promise = sdk.projects.updateWebhook('[PROJECT_ID]', '[WEBHOOK_ID]', '[NAME]', [], 'https://example.com', false); promise.then(function (response) { console.log(response); // Success diff --git a/app/sdks/console-web/src/sdk.js b/app/sdks/console-web/src/sdk.js index 376406f95..3919a751a 100644 --- a/app/sdks/console-web/src/sdk.js +++ b/app/sdks/console-web/src/sdk.js @@ -825,16 +825,17 @@ * 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 + * have provided to be attached to the verification email. The provided URL + * should redirect the user back to 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/client/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) + * 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} @@ -1258,62 +1259,6 @@ return config.endpoint + path + ((query) ? '?' + query : ''); }, - /** - * Get User Initials - * - * Use this endpoint to show your user initials avatar icon on your website or - * app. By default, this route will try to print your logged-in user name or - * email initials. You can also overwrite the user name if you pass the 'name' - * parameter. If no name is given and no user is logged, an empty avatar will - * be returned. - * - * You can use the color and background params to change the avatar colors. By - * default, a random theme will be selected. The random theme will persist for - * the user's initials when reloading the same theme will always return for - * the same initials. - * - * @param {string} name - * @param {number} width - * @param {number} height - * @param {string} color - * @param {string} background - * @throws {Error} - * @return {string} - */ - getInitials: function(name = '', width = 500, height = 500, color = '', background = '') { - let path = '/avatars/initials'; - - let payload = {}; - - if(name) { - payload['name'] = name; - } - - if(width) { - payload['width'] = width; - } - - if(height) { - payload['height'] = height; - } - - if(color) { - payload['color'] = color; - } - - if(background) { - payload['background'] = background; - } - - 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 QR Code * @@ -1323,11 +1268,11 @@ * @param {string} text * @param {number} size * @param {number} margin - * @param {number} download + * @param {boolean} download * @throws {Error} * @return {string} */ - getQR: function(text, size = 400, margin = 1, download = 0) { + getQR: function(text, size = 400, margin = 1, download = false) { if(text === undefined) { throw new Error('Missing required parameter: "text"'); } @@ -1592,18 +1537,16 @@ * * @param {string} collectionId * @param {string[]} filters - * @param {number} offset * @param {number} limit + * @param {number} offset * @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) { + listDocuments: function(collectionId, filters = [], limit = 25, offset = 0, orderField = '$id', orderType = 'ASC', orderCast = 'string', search = '') { if(collectionId === undefined) { throw new Error('Missing required parameter: "collectionId"'); } @@ -1616,14 +1559,14 @@ payload['filters'] = filters; } - if(offset) { - payload['offset'] = offset; - } - if(limit) { payload['limit'] = limit; } + if(offset) { + payload['offset'] = offset; + } + if(orderField) { payload['orderField'] = orderField; } @@ -1640,14 +1583,6 @@ payload['search'] = search; } - if(first) { - payload['first'] = first; - } - - if(last) { - payload['last'] = last; - } - return http .get(path, { 'content-type': 'application/json', @@ -1837,29 +1772,6 @@ .delete(path, { 'content-type': 'application/json', }, payload); - }, - - /** - * Get Collection Logs - * - * - * @param {string} collectionId - * @throws {Error} - * @return {Promise} - */ - getCollectionLogs: function(collectionId) { - if(collectionId === undefined) { - throw new Error('Missing required parameter: "collectionId"'); - } - - let path = '/database/collections/{collectionId}/logs'.replace(new RegExp('{collectionId}', 'g'), collectionId); - - let payload = {}; - - return http - .get(path, { - 'content-type': 'application/json', - }, payload); } }; @@ -1908,6 +1820,7 @@ * * * @param {string} name + * @param {string} env * @param {object} vars * @param {string[]} events * @param {string} schedule @@ -1915,11 +1828,15 @@ * @throws {Error} * @return {Promise} */ - create: function(name, vars = [], events = [], schedule = '', timeout = 15) { + create: function(name, env, vars = [], events = [], schedule = '', timeout = 15) { if(name === undefined) { throw new Error('Missing required parameter: "name"'); } + if(env === undefined) { + throw new Error('Missing required parameter: "env"'); + } + let path = '/functions'; let payload = {}; @@ -1928,6 +1845,10 @@ payload['name'] = name; } + if(env) { + payload['env'] = env; + } + if(vars) { payload['vars'] = vars; } @@ -2227,21 +2148,16 @@ * * * @param {string} functionId - * @param {string} env * @param {string} command * @param {string} code * @throws {Error} * @return {Promise} */ - createTag: function(functionId, env, command, code) { + createTag: function(functionId, command, code) { if(functionId === undefined) { throw new Error('Missing required parameter: "functionId"'); } - if(env === undefined) { - throw new Error('Missing required parameter: "env"'); - } - if(command === undefined) { throw new Error('Missing required parameter: "command"'); } @@ -2254,10 +2170,6 @@ let payload = {}; - if(env) { - payload['env'] = env; - } - if(command) { payload['command'] = command; } @@ -2726,14 +2638,34 @@ * List Projects * * + * @param {string} search + * @param {number} limit + * @param {number} offset + * @param {string} orderType * @throws {Error} * @return {Promise} */ - list: function() { + list: function(search = '', limit = 25, offset = 0, orderType = 'ASC') { let path = '/projects'; 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', @@ -3518,7 +3450,7 @@ * @param {string} name * @param {string} status * @param {string} schedule - * @param {number} security + * @param {boolean} security * @param {string} httpMethod * @param {string} httpUrl * @param {string[]} httpHeaders @@ -3639,7 +3571,7 @@ * @param {string} name * @param {string} status * @param {string} schedule - * @param {number} security + * @param {boolean} security * @param {string} httpMethod * @param {string} httpUrl * @param {string[]} httpHeaders @@ -3814,7 +3746,7 @@ * @param {string} name * @param {string[]} events * @param {string} url - * @param {number} security + * @param {boolean} security * @param {string} httpUser * @param {string} httpPass * @throws {Error} @@ -3912,7 +3844,7 @@ * @param {string} name * @param {string[]} events * @param {string} url - * @param {number} security + * @param {boolean} security * @param {string} httpUser * @param {string} httpPass * @throws {Error} diff --git a/app/sdks/console-web/src/sdk.min.js b/app/sdks/console-web/src/sdk.min.js index 7a4cd20f7..dace36b3e 100644 --- a/app/sdks/console-web/src/sdk.min.js +++ b/app/sdks/console-web/src/sdk.min.js @@ -79,12 +79,14 @@ query=query.join("&");return config.endpoint+path+((query)?'?'+query:'')},getIma let path='/avatars/image';let payload={};if(url){payload.url=url} if(width){payload.width=width} if(height){payload.height=height} -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:'')},getInitials:function(name='',width=500,height=500,color='',background=''){let path='/avatars/initials';let payload={};if(name){payload.name=name} +payload.project=config.project;payload.key=config.key;let query=[];for(let p in payload){if(Array.isArray(payload[p])){for(let index=0;indexkey+'='+encodeURIComponent(payload[key])).join('&');return config.endpoint+path+((query)?'?'+query:'')},getQR:function(text,size=400,margin=1,download=0){if(text===undefined){throw new Error('Missing required parameter: "text"')} +payload.project=config.project;payload.key=config.key;let query=[];for(let p in payload){if(Array.isArray(payload[p])){for(let index=0;index; + listDocuments(collectionId: string, filters: string[], limit: number, offset: number, orderField: string, orderType: string, orderCast: string, search: string): Promise; /** * Create Document @@ -606,16 +605,6 @@ declare namespace Appwrite { */ deleteDocument(collectionId: string, documentId: string): Promise; - /** - * Get Collection Logs - * - * - * @param {string} collectionId - * @throws {Error} - * @return {Promise} - */ - getCollectionLogs(collectionId: string): Promise; - } export interface Functions { @@ -638,6 +627,7 @@ declare namespace Appwrite { * * * @param {string} name + * @param {string} env * @param {object} vars * @param {string[]} events * @param {string} schedule @@ -645,7 +635,7 @@ declare namespace Appwrite { * @throws {Error} * @return {Promise} */ - create(name: string, vars: object, events: string[], schedule: string, timeout: number): Promise; + create(name: string, env: string, vars: object, events: string[], schedule: string, timeout: number): Promise; /** * Get Function @@ -748,13 +738,12 @@ declare namespace Appwrite { * * * @param {string} functionId - * @param {string} env * @param {string} command * @param {string} code * @throws {Error} * @return {Promise} */ - createTag(functionId: string, env: string, command: string, code: string): Promise; + createTag(functionId: string, command: string, code: string): Promise; /** * Get Tag @@ -1008,10 +997,14 @@ declare namespace Appwrite { * List Projects * * + * @param {string} search + * @param {number} limit + * @param {number} offset + * @param {string} orderType * @throws {Error} * @return {Promise} */ - list(): Promise; + list(search: string, limit: number, offset: number, orderType: string): Promise; /** * Create Project @@ -1278,7 +1271,7 @@ declare namespace Appwrite { * @param {string} name * @param {string} status * @param {string} schedule - * @param {number} security + * @param {boolean} security * @param {string} httpMethod * @param {string} httpUrl * @param {string[]} httpHeaders @@ -1287,7 +1280,7 @@ declare namespace Appwrite { * @throws {Error} * @return {Promise} */ - createTask(projectId: string, name: string, status: string, schedule: string, security: number, httpMethod: string, httpUrl: string, httpHeaders: string[], httpUser: string, httpPass: string): Promise; + createTask(projectId: string, name: string, status: string, schedule: string, security: boolean, httpMethod: string, httpUrl: string, httpHeaders: string[], httpUser: string, httpPass: string): Promise; /** * Get Task @@ -1309,7 +1302,7 @@ declare namespace Appwrite { * @param {string} name * @param {string} status * @param {string} schedule - * @param {number} security + * @param {boolean} security * @param {string} httpMethod * @param {string} httpUrl * @param {string[]} httpHeaders @@ -1318,7 +1311,7 @@ declare namespace Appwrite { * @throws {Error} * @return {Promise} */ - updateTask(projectId: string, taskId: string, name: string, status: string, schedule: string, security: number, httpMethod: string, httpUrl: string, httpHeaders: string[], httpUser: string, httpPass: string): Promise; + updateTask(projectId: string, taskId: string, name: string, status: string, schedule: string, security: boolean, httpMethod: string, httpUrl: string, httpHeaders: string[], httpUser: string, httpPass: string): Promise; /** * Delete Task @@ -1360,13 +1353,13 @@ declare namespace Appwrite { * @param {string} name * @param {string[]} events * @param {string} url - * @param {number} security + * @param {boolean} security * @param {string} httpUser * @param {string} httpPass * @throws {Error} * @return {Promise} */ - createWebhook(projectId: string, name: string, events: string[], url: string, security: number, httpUser: string, httpPass: string): Promise; + createWebhook(projectId: string, name: string, events: string[], url: string, security: boolean, httpUser: string, httpPass: string): Promise; /** * Get Webhook @@ -1388,13 +1381,13 @@ declare namespace Appwrite { * @param {string} name * @param {string[]} events * @param {string} url - * @param {number} security + * @param {boolean} security * @param {string} httpUser * @param {string} httpPass * @throws {Error} * @return {Promise} */ - updateWebhook(projectId: string, webhookId: string, name: string, events: string[], url: string, security: number, httpUser: string, httpPass: string): Promise; + updateWebhook(projectId: string, webhookId: string, name: string, events: string[], url: string, security: boolean, httpUser: string, httpPass: string): Promise; /** * Delete Webhook