diff --git a/LICENSE b/LICENSE index 96201c4..b0761cc 100644 --- a/LICENSE +++ b/LICENSE @@ -9,4 +9,4 @@ Redistribution and use in source and binary forms, with or without modification, 3. Neither the name Appwrite nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md index 34de28a..5d802b3 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite Node.js SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-node.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-0.15.0-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.0.0-RC1-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 0.15.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).** +**This SDK is compatible with Appwrite server version 1.0.0-RC1. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-node/releases).** > This is the Node.js SDK for integrating with Appwrite from your Node.js server-side code. If you're looking to integrate from the browser, you should check [appwrite/sdk-for-web](https://github.com/appwrite/sdk-for-web) diff --git a/docs/examples/databases/create-boolean-attribute.md b/docs/examples/databases/create-boolean-attribute.md index f6786c9..616b3fc 100644 --- a/docs/examples/databases/create-boolean-attribute.md +++ b/docs/examples/databases/create-boolean-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createBooleanAttribute('[COLLECTION_ID]', '', false); +const promise = databases.createBooleanAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-collection.md b/docs/examples/databases/create-collection.md index c79904f..098f050 100644 --- a/docs/examples/databases/create-collection.md +++ b/docs/examples/databases/create-collection.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createCollection('[COLLECTION_ID]', '[NAME]', 'document', ["role:all"], ["role:all"]); +const promise = databases.createCollection('[DATABASE_ID]', '[COLLECTION_ID]', '[NAME]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-datetime-attribute.md b/docs/examples/databases/create-datetime-attribute.md new file mode 100644 index 0000000..c16bf0a --- /dev/null +++ b/docs/examples/databases/create-datetime-attribute.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const databases = new sdk.Databases(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = databases.createDatetimeAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index d59909d..cdc7442 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createDocument('[COLLECTION_ID]', '[DOCUMENT_ID]', {}); +const promise = databases.createDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]', {}); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-email-attribute.md b/docs/examples/databases/create-email-attribute.md index 9d5e640..890b425 100644 --- a/docs/examples/databases/create-email-attribute.md +++ b/docs/examples/databases/create-email-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createEmailAttribute('[COLLECTION_ID]', '', false); +const promise = databases.createEmailAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-enum-attribute.md b/docs/examples/databases/create-enum-attribute.md index c03a284..75e4954 100644 --- a/docs/examples/databases/create-enum-attribute.md +++ b/docs/examples/databases/create-enum-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createEnumAttribute('[COLLECTION_ID]', '', [], false); +const promise = databases.createEnumAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', [], false); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-float-attribute.md b/docs/examples/databases/create-float-attribute.md index 8961cc1..1a26025 100644 --- a/docs/examples/databases/create-float-attribute.md +++ b/docs/examples/databases/create-float-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createFloatAttribute('[COLLECTION_ID]', '', false); +const promise = databases.createFloatAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-index.md b/docs/examples/databases/create-index.md index 67401a0..07ff87f 100644 --- a/docs/examples/databases/create-index.md +++ b/docs/examples/databases/create-index.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createIndex('[COLLECTION_ID]', '', 'key', []); +const promise = databases.createIndex('[DATABASE_ID]', '[COLLECTION_ID]', '', 'key', []); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-integer-attribute.md b/docs/examples/databases/create-integer-attribute.md index 9cbb9c4..52acd48 100644 --- a/docs/examples/databases/create-integer-attribute.md +++ b/docs/examples/databases/create-integer-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createIntegerAttribute('[COLLECTION_ID]', '', false); +const promise = databases.createIntegerAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-ip-attribute.md b/docs/examples/databases/create-ip-attribute.md index 88e8b7b..8cb193a 100644 --- a/docs/examples/databases/create-ip-attribute.md +++ b/docs/examples/databases/create-ip-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createIpAttribute('[COLLECTION_ID]', '', false); +const promise = databases.createIpAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-string-attribute.md b/docs/examples/databases/create-string-attribute.md index 59b57dc..e12b71d 100644 --- a/docs/examples/databases/create-string-attribute.md +++ b/docs/examples/databases/create-string-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createStringAttribute('[COLLECTION_ID]', '', 1, false); +const promise = databases.createStringAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', 1, false); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create-url-attribute.md b/docs/examples/databases/create-url-attribute.md index b947177..6738cd7 100644 --- a/docs/examples/databases/create-url-attribute.md +++ b/docs/examples/databases/create-url-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.createUrlAttribute('[COLLECTION_ID]', '', false); +const promise = databases.createUrlAttribute('[DATABASE_ID]', '[COLLECTION_ID]', '', false); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/create.md b/docs/examples/databases/create.md index 4184862..b6fb6c6 100644 --- a/docs/examples/databases/create.md +++ b/docs/examples/databases/create.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.create('[NAME]'); +const promise = databases.create('[DATABASE_ID]', '[NAME]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/delete-attribute.md b/docs/examples/databases/delete-attribute.md index 11331a1..312135e 100644 --- a/docs/examples/databases/delete-attribute.md +++ b/docs/examples/databases/delete-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.deleteAttribute('[COLLECTION_ID]', ''); +const promise = databases.deleteAttribute('[DATABASE_ID]', '[COLLECTION_ID]', ''); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/delete-collection.md b/docs/examples/databases/delete-collection.md index 4c38acb..8b1ee5f 100644 --- a/docs/examples/databases/delete-collection.md +++ b/docs/examples/databases/delete-collection.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.deleteCollection('[COLLECTION_ID]'); +const promise = databases.deleteCollection('[DATABASE_ID]', '[COLLECTION_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/delete-document.md b/docs/examples/databases/delete-document.md index d4644e5..9229166 100644 --- a/docs/examples/databases/delete-document.md +++ b/docs/examples/databases/delete-document.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.deleteDocument('[COLLECTION_ID]', '[DOCUMENT_ID]'); +const promise = databases.deleteDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/delete-index.md b/docs/examples/databases/delete-index.md index b614793..ffa04b4 100644 --- a/docs/examples/databases/delete-index.md +++ b/docs/examples/databases/delete-index.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.deleteIndex('[COLLECTION_ID]', ''); +const promise = databases.deleteIndex('[DATABASE_ID]', '[COLLECTION_ID]', ''); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/delete.md b/docs/examples/databases/delete.md index 9a6b599..f2534e5 100644 --- a/docs/examples/databases/delete.md +++ b/docs/examples/databases/delete.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.delete(); +const promise = databases.delete('[DATABASE_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/get-attribute.md b/docs/examples/databases/get-attribute.md index 30f6c7b..d167582 100644 --- a/docs/examples/databases/get-attribute.md +++ b/docs/examples/databases/get-attribute.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.getAttribute('[COLLECTION_ID]', ''); +const promise = databases.getAttribute('[DATABASE_ID]', '[COLLECTION_ID]', ''); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/get-collection.md b/docs/examples/databases/get-collection.md index 9188fff..fdaa714 100644 --- a/docs/examples/databases/get-collection.md +++ b/docs/examples/databases/get-collection.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.getCollection('[COLLECTION_ID]'); +const promise = databases.getCollection('[DATABASE_ID]', '[COLLECTION_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md index e4dd083..abb57a4 100644 --- a/docs/examples/databases/get-document.md +++ b/docs/examples/databases/get-document.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.getDocument('[COLLECTION_ID]', '[DOCUMENT_ID]'); +const promise = databases.getDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/get-index.md b/docs/examples/databases/get-index.md index 755f59d..469f75e 100644 --- a/docs/examples/databases/get-index.md +++ b/docs/examples/databases/get-index.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.getIndex('[COLLECTION_ID]', ''); +const promise = databases.getIndex('[DATABASE_ID]', '[COLLECTION_ID]', ''); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/get.md b/docs/examples/databases/get.md index af26599..dc11458 100644 --- a/docs/examples/databases/get.md +++ b/docs/examples/databases/get.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.get(); +const promise = databases.get('[DATABASE_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/list-attributes.md b/docs/examples/databases/list-attributes.md index 8414b89..b3e0986 100644 --- a/docs/examples/databases/list-attributes.md +++ b/docs/examples/databases/list-attributes.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.listAttributes('[COLLECTION_ID]'); +const promise = databases.listAttributes('[DATABASE_ID]', '[COLLECTION_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/list-collections.md b/docs/examples/databases/list-collections.md index bf96396..37b594f 100644 --- a/docs/examples/databases/list-collections.md +++ b/docs/examples/databases/list-collections.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.listCollections(); +const promise = databases.listCollections('[DATABASE_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index 1197f70..89aa4f7 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.listDocuments('[COLLECTION_ID]'); +const promise = databases.listDocuments('[DATABASE_ID]', '[COLLECTION_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/list-indexes.md b/docs/examples/databases/list-indexes.md index 0ed620c..36954b2 100644 --- a/docs/examples/databases/list-indexes.md +++ b/docs/examples/databases/list-indexes.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.listIndexes('[COLLECTION_ID]'); +const promise = databases.listIndexes('[DATABASE_ID]', '[COLLECTION_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/list.md b/docs/examples/databases/list.md index dae95f0..8e3857e 100644 --- a/docs/examples/databases/list.md +++ b/docs/examples/databases/list.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint diff --git a/docs/examples/databases/update-collection.md b/docs/examples/databases/update-collection.md index aa409b3..1205a26 100644 --- a/docs/examples/databases/update-collection.md +++ b/docs/examples/databases/update-collection.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.updateCollection('[COLLECTION_ID]', '[NAME]', 'document'); +const promise = databases.updateCollection('[DATABASE_ID]', '[COLLECTION_ID]', '[NAME]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 402312d..edd4ea6 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.updateDocument('[COLLECTION_ID]', '[DOCUMENT_ID]'); +const promise = databases.updateDocument('[DATABASE_ID]', '[COLLECTION_ID]', '[DOCUMENT_ID]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/databases/update.md b/docs/examples/databases/update.md index f9aa561..f829bc8 100644 --- a/docs/examples/databases/update.md +++ b/docs/examples/databases/update.md @@ -3,7 +3,7 @@ const sdk = require('node-appwrite'); // Init SDK const client = new sdk.Client(); -const databases = new sdk.Databases(client, '[DATABASE_ID]'); +const databases = new sdk.Databases(client); client .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = databases.update('[NAME]'); +const promise = databases.update('[DATABASE_ID]', '[NAME]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/functions/create-deployment.md b/docs/examples/functions/create-deployment.md index ce8e480..c48153b 100644 --- a/docs/examples/functions/create-deployment.md +++ b/docs/examples/functions/create-deployment.md @@ -12,7 +12,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = functions.createDeployment('[FUNCTION_ID]', '[ENTRYPOINT]', 'file.png', false); +const promise = functions.createDeployment('[FUNCTION_ID]', '[ENTRYPOINT]', InputFile.fromPath('/path/to/file.png', 'file.png'), false); promise.then(function (response) { console.log(response); diff --git a/docs/examples/functions/create-variable.md b/docs/examples/functions/create-variable.md new file mode 100644 index 0000000..3d233b8 --- /dev/null +++ b/docs/examples/functions/create-variable.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const functions = new sdk.Functions(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = functions.createVariable('[FUNCTION_ID]', '[KEY]', '[VALUE]'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/functions/create.md b/docs/examples/functions/create.md index 47865bc..c4ab049 100644 --- a/docs/examples/functions/create.md +++ b/docs/examples/functions/create.md @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = functions.create('[FUNCTION_ID]', '[NAME]', [], 'node-14.5'); +const promise = functions.create('[FUNCTION_ID]', '[NAME]', ["any"], 'node-14.5'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/functions/delete-variable.md b/docs/examples/functions/delete-variable.md new file mode 100644 index 0000000..0190ee8 --- /dev/null +++ b/docs/examples/functions/delete-variable.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const functions = new sdk.Functions(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = functions.deleteVariable('[FUNCTION_ID]', '[VARIABLE_ID]'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/functions/get-variable.md b/docs/examples/functions/get-variable.md new file mode 100644 index 0000000..f3cfbff --- /dev/null +++ b/docs/examples/functions/get-variable.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const functions = new sdk.Functions(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = functions.getVariable('[FUNCTION_ID]', '[VARIABLE_ID]'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/functions/list-variables.md b/docs/examples/functions/list-variables.md new file mode 100644 index 0000000..4120d96 --- /dev/null +++ b/docs/examples/functions/list-variables.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const functions = new sdk.Functions(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = functions.listVariables('[FUNCTION_ID]'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/functions/update-variable.md b/docs/examples/functions/update-variable.md new file mode 100644 index 0000000..e4262de --- /dev/null +++ b/docs/examples/functions/update-variable.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const functions = new sdk.Functions(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = functions.updateVariable('[FUNCTION_ID]', '[VARIABLE_ID]', '[KEY]'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/functions/update.md b/docs/examples/functions/update.md index b7f3a4d..c37837b 100644 --- a/docs/examples/functions/update.md +++ b/docs/examples/functions/update.md @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = functions.update('[FUNCTION_ID]', '[NAME]', []); +const promise = functions.update('[FUNCTION_ID]', '[NAME]', ["any"]); promise.then(function (response) { console.log(response); diff --git a/docs/examples/storage/create-bucket.md b/docs/examples/storage/create-bucket.md index c95c154..4f355b3 100644 --- a/docs/examples/storage/create-bucket.md +++ b/docs/examples/storage/create-bucket.md @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = storage.createBucket('[BUCKET_ID]', '[NAME]', 'file'); +const promise = storage.createBucket('[BUCKET_ID]', '[NAME]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index d74cfd9..4e3138e 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -12,7 +12,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = storage.createFile('[BUCKET_ID]', '[FILE_ID]', 'file.png'); +const promise = storage.createFile('[BUCKET_ID]', '[FILE_ID]', InputFile.fromPath('/path/to/file.png', 'file.png')); promise.then(function (response) { console.log(response); diff --git a/docs/examples/storage/update-bucket.md b/docs/examples/storage/update-bucket.md index 70863a8..35f1358 100644 --- a/docs/examples/storage/update-bucket.md +++ b/docs/examples/storage/update-bucket.md @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = storage.updateBucket('[BUCKET_ID]', '[NAME]', 'file'); +const promise = storage.updateBucket('[BUCKET_ID]', '[NAME]'); promise.then(function (response) { console.log(response); diff --git a/docs/examples/users/create-argon2user.md b/docs/examples/users/create-argon2user.md new file mode 100644 index 0000000..00eb91d --- /dev/null +++ b/docs/examples/users/create-argon2user.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const users = new sdk.Users(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = users.createArgon2User('[USER_ID]', 'email@example.com', 'password'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/users/create-bcrypt-user.md b/docs/examples/users/create-bcrypt-user.md new file mode 100644 index 0000000..42b3108 --- /dev/null +++ b/docs/examples/users/create-bcrypt-user.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const users = new sdk.Users(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = users.createBcryptUser('[USER_ID]', 'email@example.com', 'password'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/users/create-m-d5user.md b/docs/examples/users/create-m-d5user.md new file mode 100644 index 0000000..b7a7c0c --- /dev/null +++ b/docs/examples/users/create-m-d5user.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const users = new sdk.Users(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = users.createMD5User('[USER_ID]', 'email@example.com', 'password'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/users/create-p-h-pass-user.md b/docs/examples/users/create-p-h-pass-user.md new file mode 100644 index 0000000..477a88e --- /dev/null +++ b/docs/examples/users/create-p-h-pass-user.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const users = new sdk.Users(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = users.createPHPassUser('[USER_ID]', 'email@example.com', 'password'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/users/create-s-h-a-user.md b/docs/examples/users/create-s-h-a-user.md new file mode 100644 index 0000000..482aa0b --- /dev/null +++ b/docs/examples/users/create-s-h-a-user.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const users = new sdk.Users(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = users.createSHAUser('[USER_ID]', 'email@example.com', 'password'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/users/create-scrypt-modified-user.md b/docs/examples/users/create-scrypt-modified-user.md new file mode 100644 index 0000000..c267797 --- /dev/null +++ b/docs/examples/users/create-scrypt-modified-user.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const users = new sdk.Users(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = users.createScryptModifiedUser('[USER_ID]', 'email@example.com', 'password', '[PASSWORD_SALT]', '[PASSWORD_SALT_SEPARATOR]', '[PASSWORD_SIGNER_KEY]'); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/users/create-scrypt-user.md b/docs/examples/users/create-scrypt-user.md new file mode 100644 index 0000000..bd067e6 --- /dev/null +++ b/docs/examples/users/create-scrypt-user.md @@ -0,0 +1,20 @@ +const sdk = require('node-appwrite'); + +// Init SDK +const client = new sdk.Client(); + +const users = new sdk.Users(client); + +client + .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setProject('5df5acd0d48c2') // Your project ID + .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key +; + +const promise = users.createScryptUser('[USER_ID]', 'email@example.com', 'password', '[PASSWORD_SALT]', null, null, null, null); + +promise.then(function (response) { + console.log(response); +}, function (error) { + console.log(error); +}); \ No newline at end of file diff --git a/docs/examples/users/create.md b/docs/examples/users/create.md index d7a5406..6455ff4 100644 --- a/docs/examples/users/create.md +++ b/docs/examples/users/create.md @@ -11,7 +11,7 @@ client .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key ; -const promise = users.create('[USER_ID]', 'email@example.com', 'password'); +const promise = users.create('[USER_ID]'); promise.then(function (response) { console.log(response); diff --git a/index.d.ts b/index.d.ts index 17ddec6..79d2e88 100644 --- a/index.d.ts +++ b/index.d.ts @@ -261,6 +261,19 @@ declare module "node-appwrite" { phones: Phone[]; } /** + * Variables List + */ + export type VariableList = { + /** + * Total number of variables documents that matched your query. + */ + total: number; + /** + * List of variables. + */ + variables: Variable[]; + } + /** * Database */ export type Database = { @@ -272,6 +285,14 @@ declare module "node-appwrite" { * Database name. */ name: string; + /** + * Database creation date in ISO 8601 format. + */ + $createdAt: string; + /** + * Database update date in ISO 8601 format. + */ + $updatedAt: string; } /** * Collection @@ -282,21 +303,17 @@ declare module "node-appwrite" { */ $id: string; /** - * Collection creation date in Unix timestamp. + * Collection creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** - * Collection update date in Unix timestamp. + * Collection update date in ISO 8601 format. */ - $updatedAt: number; + $updatedAt: string; /** - * Collection read permissions. + * Collection permissions. [Learn more about permissions](/docs/permissions). */ - $read: string[]; - /** - * Collection write permissions. - */ - $write: string[]; + $permissions: string[]; /** * Database ID. */ @@ -310,9 +327,9 @@ declare module "node-appwrite" { */ enabled: boolean; /** - * Collection permission model. Possible values: `document` or `collection` + * Whether document-level permissions are enabled. [Learn more about permissions](/docs/permissions). */ - permission: string; + documentSecurity: boolean; /** * Collection attributes. */ @@ -608,6 +625,39 @@ declare module "node-appwrite" { xdefault?: string; } /** + * AttributeDatetime + */ + export type AttributeDatetime = { + /** + * Attribute Key. + */ + key: string; + /** + * Attribute type. + */ + type: string; + /** + * Attribute status. Possible values: `available`, `processing`, `deleting`, `stuck`, or `failed` + */ + status: string; + /** + * Is attribute required? + */ + required: boolean; + /** + * Is attribute an array? + */ + array?: boolean; + /** + * ISO 8601 format. + */ + format: string; + /** + * Default value for attribute when not provided. Only null is optional + */ + xdefault?: string; + } + /** * Index */ export type Index = { @@ -630,7 +680,7 @@ declare module "node-appwrite" { /** * Index orders. */ - orders: string[]; + orders?: string[]; } /** * Document @@ -645,21 +695,17 @@ declare module "node-appwrite" { */ $collection: string; /** - * Document creation date in Unix timestamp. - */ - $createdAt: number; - /** - * Document update date in Unix timestamp. + * Document creation date in ISO 8601 format. */ - $updatedAt: number; + $createdAt: string; /** - * Document read permissions. + * Document update date in ISO 8601 format. */ - $read: string[]; + $updatedAt: string; /** - * Document write permissions. + * Document permissions. [Learn more about permissions](/docs/permissions). */ - $write: string[]; + $permissions: string[]; } /** * Log @@ -690,9 +736,9 @@ declare module "node-appwrite" { */ ip: string; /** - * Log creation time in Unix timestamp. + * Log creation date in ISO 8601 format. */ - time: number; + time: string; /** * Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json). */ @@ -759,29 +805,169 @@ declare module "node-appwrite" { */ $id: string; /** - * User creation date in Unix timestamp. + * User creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** - * User update date in Unix timestamp. + * User update date in ISO 8601 format. */ - $updatedAt: number; + $updatedAt: string; /** * User name. */ name: string; /** - * User registration date in Unix timestamp. + * Hashed user password. + */ + password: string; + /** + * Password hashing algorithm. + */ + hash: string; + /** + * Password hashing algorithm configuration. */ - registration: number; + hashOptions: object; + /** + * User registration date in ISO 8601 format. + */ + registration: string; /** * User status. Pass `true` for enabled and `false` for disabled. */ status: boolean; /** - * Unix timestamp of the most recent password update + * Password update time in ISO 8601 format. */ - passwordUpdate: number; + passwordUpdate: string; + /** + * User email address. + */ + email: string; + /** + * User phone number in E.164 format. + */ + phone: string; + /** + * Email verification status. + */ + emailVerification: boolean; + /** + * Phone verification status. + */ + phoneVerification: boolean; + /** + * User preferences as a key-value object + */ + prefs: Preferences; + } + /** + * AlgoMD5 + */ + export type AlgoMd5 = { + } + /** + * AlgoSHA + */ + export type AlgoSha = { + } + /** + * AlgoPHPass + */ + export type AlgoPhpass = { + } + /** + * AlgoBcrypt + */ + export type AlgoBcrypt = { + } + /** + * AlgoScrypt + */ + export type AlgoScrypt = { + /** + * CPU complexity of computed hash. + */ + costCpu: number; + /** + * Memory complexity of computed hash. + */ + costMemory: number; + /** + * Parallelization of computed hash. + */ + costParallel: number; + /** + * Length used to compute hash. + */ + length: number; + } + /** + * AlgoScryptModified + */ + export type AlgoScryptModified = { + /** + * Salt used to compute hash. + */ + salt: string; + /** + * Separator used to compute hash. + */ + saltSeparator: string; + /** + * Key used to compute hash. + */ + signerKey: string; + } + /** + * AlgoArgon2 + */ + export type AlgoArgon2 = { + /** + * Memory used to compute hash. + */ + memoryCost: number; + /** + * Amount of time consumed to compute hash + */ + timeCost: number; + /** + * Number of threads used to compute hash. + */ + threads: number; + } + /** + * Account + */ + export type Account = { + /** + * User ID. + */ + $id: string; + /** + * User creation date in ISO 8601 format. + */ + $createdAt: string; + /** + * User update date in ISO 8601 format. + */ + $updatedAt: string; + /** + * User name. + */ + name: string; + /** + * User registration date in ISO 8601 format. + */ + registration: string; + /** + * User status. Pass `true` for enabled and `false` for disabled. + */ + status: boolean; + /** + * Password update time in ISO 8601 format. + */ + passwordUpdate: string; /** * User email address. */ @@ -817,17 +1003,17 @@ declare module "node-appwrite" { */ $id: string; /** - * Session creation date in Unix timestamp. + * Session creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** * User ID. */ userId: string; /** - * Session expiration date in Unix timestamp. + * Session expiration date in ISO 8601 format. */ - expire: number; + expire: string; /** * Session Provider. */ @@ -841,9 +1027,9 @@ declare module "node-appwrite" { */ providerAccessToken: string; /** - * Date, the Unix timestamp of when the access token expires. + * The date of when the access token expires in ISO 8601 format. */ - providerAccessTokenExpiry: number; + providerAccessTokenExpiry: string; /** * Session Provider Refresh Token. */ @@ -922,9 +1108,9 @@ declare module "node-appwrite" { */ $id: string; /** - * Token creation date in Unix timestamp. + * Token creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** * User ID. */ @@ -934,9 +1120,9 @@ declare module "node-appwrite" { */ secret: string; /** - * Token expiration date in Unix timestamp. + * Token expiration date in ISO 8601 format. */ - expire: number; + expire: string; } /** * Locale @@ -984,21 +1170,17 @@ declare module "node-appwrite" { */ bucketId: string; /** - * File creation date in Unix timestamp. + * File creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** - * File update date in Unix timestamp. + * File update date in ISO 8601 format. */ - $updatedAt: number; + $updatedAt: string; /** - * File read permissions. + * File permissions. [Learn more about permissions](/docs/permissions). */ - $read: string[]; - /** - * File write permissions. - */ - $write: string[]; + $permissions: string[]; /** * File name. */ @@ -1033,25 +1215,21 @@ declare module "node-appwrite" { */ $id: string; /** - * Bucket creation date in Unix timestamp. + * Bucket creation time in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** - * Bucket update date in Unix timestamp. + * Bucket update date in ISO 8601 format. */ - $updatedAt: number; + $updatedAt: string; /** - * File read permissions. + * Bucket permissions. [Learn more about permissions](/docs/permissions). */ - $read: string[]; + $permissions: string[]; /** - * File write permissions. + * Whether file-level security is enabled. [Learn more about permissions](/docs/permissions). */ - $write: string[]; - /** - * Bucket permission model. Possible values: `bucket` or `file` - */ - permission: string; + fileSecurity: string; /** * Bucket name. */ @@ -1069,6 +1247,10 @@ declare module "node-appwrite" { */ allowedFileExtensions: string[]; /** + * Compression algorithm choosen for compression. Will be one of none, [gzip](https://en.wikipedia.org/wiki/Gzip), or [zstd](https://en.wikipedia.org/wiki/Zstd). + */ + compression: string; + /** * Bucket is encrypted. */ encryption: boolean; @@ -1086,13 +1268,13 @@ declare module "node-appwrite" { */ $id: string; /** - * Team creation date in Unix timestamp. + * Team creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** - * Team update date in Unix timestamp. + * Team update date in ISO 8601 format. */ - $updatedAt: number; + $updatedAt: string; /** * Team name. */ @@ -1111,13 +1293,13 @@ declare module "node-appwrite" { */ $id: string; /** - * Membership creation date in Unix timestamp. + * Membership creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** - * Membership update date in Unix timestamp. + * Membership update date in ISO 8601 format. */ - $updatedAt: number; + $updatedAt: string; /** * User ID. */ @@ -1139,13 +1321,13 @@ declare module "node-appwrite" { */ teamName: string; /** - * Date, the user has been invited to join the team in Unix timestamp. + * Date, the user has been invited to join the team in ISO 8601 format. */ - invited: number; + invited: string; /** - * Date, the user has accepted the invitation to join the team in Unix timestamp. + * Date, the user has accepted the invitation to join the team in ISO 8601 format. */ - joined: number; + joined: string; /** * User confirmation status, true if the user has joined the team or false otherwise. */ @@ -1164,13 +1346,13 @@ declare module "node-appwrite" { */ $id: string; /** - * Function creation date in Unix timestamp. + * Function creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** - * Function update date in Unix timestamp. + * Function update date in ISO 8601 format. */ - $updatedAt: number; + $updatedAt: string; /** * Execution permissions. */ @@ -1192,9 +1374,9 @@ declare module "node-appwrite" { */ deployment: string; /** - * Function environment variables. + * Function variables. */ - vars: object; + vars: Variable[]; /** * Function trigger events. */ @@ -1204,13 +1386,13 @@ declare module "node-appwrite" { */ schedule: string; /** - * Function next scheduled execution date in Unix timestamp. + * Function's next scheduled execution time in ISO 8601 format. */ - scheduleNext: number; + scheduleNext: string; /** - * Function next scheduled execution date in Unix timestamp. + * Function's previous scheduled execution time in ISO 8601 format. */ - schedulePrevious: number; + schedulePrevious: string; /** * Function execution timeout in seconds. */ @@ -1258,13 +1440,13 @@ declare module "node-appwrite" { */ $id: string; /** - * Deployment creation date in Unix timestamp. + * Deployment creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** - * Deployment update date in Unix timestamp. + * Deployment update date in ISO 8601 format. */ - $updatedAt: number; + $updatedAt: string; /** * Resource ID. */ @@ -1290,7 +1472,7 @@ declare module "node-appwrite" { */ activate: boolean; /** - * The deployment status. + * The deployment status. Possible values are "processing", "building", "pending", "ready", and "failed". */ status: string; /** @@ -1311,17 +1493,17 @@ declare module "node-appwrite" { */ $id: string; /** - * Execution creation date in Unix timestamp. + * Execution creation date in ISO 8601 format. */ - $createdAt: number; + $createdAt: string; /** - * Execution update date in Unix timestamp. + * Execution upate date in ISO 8601 format. */ - $updatedAt: number; + $updatedAt: string; /** - * Execution read permissions. + * Execution roles. */ - $read: string[]; + $permissions: string[]; /** * Function ID. */ @@ -1343,7 +1525,11 @@ declare module "node-appwrite" { */ response: string; /** - * The script stderr output string. Logs the last 4,000 characters of the execution stderr output + * The script stdout output string. Logs the last 4,000 characters of the execution stdout output. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. + */ + stdout: string; + /** + * The script stderr output string. Logs the last 4,000 characters of the execution stderr output. This will return an empty string unless the response is returned using an API key or as part of a webhook payload. */ stderr: string; /** @@ -1352,6 +1538,35 @@ declare module "node-appwrite" { time: number; } /** + * Variable + */ + export type Variable = { + /** + * Variable ID. + */ + $id: string; + /** + * Variable creation date in ISO 8601 format. + */ + $createdAt: string; + /** + * Variable creation date in ISO 8601 format. + */ + $updatedAt: string; + /** + * Variable key. + */ + key: string; + /** + * Variable value. + */ + value: string; + /** + * Function ID. + */ + functionId: string; + } + /** * Country */ export type Country = { @@ -1591,17 +1806,29 @@ declare module "node-appwrite" { static notEqual(attribute: string, value: QueryTypes): string; - static lesser(attribute: string, value: QueryTypes): string; + static lessThan(attribute: string, value: QueryTypes): string; - static lesserEqual(attribute: string, value: QueryTypes): string; + static lessThanEqual(attribute: string, value: QueryTypes): string; - static greater(attribute: string, value: QueryTypes): string; + static greaterThan(attribute: string, value: QueryTypes): string; - static greaterEqual(attribute: string, value: QueryTypes): string; + static greaterThanEqual(attribute: string, value: QueryTypes): string; static search(attribute: string, value: string): string; - private static addQuery(attribute: string, oper: string, value: QueryTypes): string; + static orderDesc(attribute: string): string; + + static orderAsc(attribute: string): string; + + static cursorAfter(documentId: string): string; + + static cursorBefore(documentId: string): string; + + static limit(value: number): string; + + static offset = (value: number): string; + + private static addQuery(attribute: string, method: string, value: QueryTypes): string; private static parseValues(value: QueryTypes): string; } @@ -1617,7 +1844,7 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - get(): Promise>; + get(): Promise>; /** * Update Account Email * @@ -1635,19 +1862,18 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - updateEmail(email: string, password: string): Promise>; + updateEmail(email: string, password: string): Promise>; /** * 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. * - * @param {number} limit - * @param {number} offset + * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} */ - getLogs(limit?: number, offset?: number): Promise; + getLogs(queries?: string[]): Promise; /** * Update Account Name * @@ -1657,7 +1883,7 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - updateName(name: string): Promise>; + updateName(name: string): Promise>; /** * Update Account Password * @@ -1670,7 +1896,7 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - updatePassword(password: string, oldPassword?: string): Promise>; + updatePassword(password: string, oldPassword?: string): Promise>; /** * Update Account Phone * @@ -1680,12 +1906,12 @@ declare module "node-appwrite" { * /account/verification/phone](/docs/client/account#accountCreatePhoneVerification) * endpoint to send a confirmation SMS. * - * @param {string} number + * @param {string} phone * @param {string} password * @throws {AppwriteException} * @returns {Promise} */ - updatePhone(number: string, password: string): Promise>; + updatePhone(phone: string, password: string): Promise>; /** * Get Account Preferences * @@ -1706,7 +1932,7 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - updatePrefs(prefs: object): Promise>; + updatePrefs(prefs: object): Promise>; /** * Create Password Recovery * @@ -1812,7 +2038,7 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - updateStatus(): Promise>; + updateStatus(): Promise>; /** * Create Email Verification * @@ -1942,7 +2168,8 @@ declare module "node-appwrite" { * * 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. + * height and quality arguments to change the output settings. Country codes + * follow the [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) standard. * * When one dimension is specified and the other is 0, the image is scaled * with preserved aspect ratio. If both dimensions are 0, the API provides an @@ -2002,12 +2229,11 @@ declare module "node-appwrite" { * @param {string} name * @param {number} width * @param {number} height - * @param {string} color * @param {string} background * @throws {AppwriteException} * @returns {Promise} */ - getInitials(name?: string, width?: number, height?: number, color?: string, background?: string): Promise; + getInitials(name?: string, width?: number, height?: number, background?: string): Promise; /** * Get QR Code * @@ -2025,131 +2251,150 @@ declare module "node-appwrite" { getQR(text: string, size?: number, margin?: number, download?: boolean): Promise; } export class Databases extends Service { - constructor(client: Client, databaseId: string); + constructor(client: Client); - /** - * Get databaseId. - * - * @returns {string} - */ - getDatabaseId(): string; - - /** - * Set databaseId. - * - * @param {string} databaseId - * @returns {void} - */ - setDatabaseId(databaseId: string): void; - /** * List Databases * + * Get a list of all databases from the current Appwrite project. You can use + * the search parameter to filter your results. + * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - list(search?: string, limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderType?: string): Promise; + list(queries?: string[], search?: string): Promise; /** * Create Database * + * Create a new Database. + * + * + * @param {string} databaseId * @param {string} name * @throws {AppwriteException} * @returns {Promise} */ - create(name: string): Promise; + create(databaseId: string, name: string): Promise; /** * Get Database * + * Get a database by its unique ID. This endpoint response returns a JSON + * object with the database metadata. + * + * @param {string} databaseId * @throws {AppwriteException} * @returns {Promise} */ - get(): Promise; + get(databaseId: string): Promise; /** * Update Database * + * Update a database by its unique ID. + * + * @param {string} databaseId * @param {string} name * @throws {AppwriteException} * @returns {Promise} */ - update(name: string): Promise; + update(databaseId: string, name: string): Promise; /** * Delete Database * + * Delete a database by its unique ID. Only API keys with with databases.write + * scope can delete a database. + * + * @param {string} databaseId * @throws {AppwriteException} * @returns {Promise} */ - delete(): Promise; + delete(databaseId: string): Promise; /** * List Collections * + * Get a list of all collections that belong to the provided databaseId. You + * can use the search parameter to filter your results. + * + * @param {string} databaseId + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - listCollections(search?: string, limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderType?: string): Promise; + listCollections(databaseId: string, queries?: string[], search?: string): Promise; /** * Create Collection * + * Create a new Collection. Before using this route, you should create a new + * database resource using either a [server + * integration](/docs/server/databases#databasesCreateCollection) API or + * directly from your database console. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} name - * @param {string} permission - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions + * @param {boolean} documentSecurity * @throws {AppwriteException} * @returns {Promise} */ - createCollection(collectionId: string, name: string, permission: string, read: string[], write: string[]): Promise; + createCollection(databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean): Promise; /** * Get Collection * + * Get a collection by its unique ID. This endpoint response returns a JSON + * object with the collection metadata. + * + * @param {string} databaseId * @param {string} collectionId * @throws {AppwriteException} * @returns {Promise} */ - getCollection(collectionId: string): Promise; + getCollection(databaseId: string, collectionId: string): Promise; /** * Update Collection * + * Update a collection by its unique ID. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} name - * @param {string} permission - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions + * @param {boolean} documentSecurity * @param {boolean} enabled * @throws {AppwriteException} * @returns {Promise} */ - updateCollection(collectionId: string, name: string, permission: string, read?: string[], write?: string[], enabled?: boolean): Promise; + updateCollection(databaseId: string, collectionId: string, name: string, permissions?: string[], documentSecurity?: boolean, enabled?: boolean): Promise; /** * Delete Collection * + * Delete a collection by its unique ID. Only users with write permissions + * have access to delete this resource. + * + * @param {string} databaseId * @param {string} collectionId * @throws {AppwriteException} * @returns {Promise} */ - deleteCollection(collectionId: string): Promise; + deleteCollection(databaseId: string, collectionId: string): Promise; /** * List Attributes * + * @param {string} databaseId * @param {string} collectionId * @throws {AppwriteException} * @returns {Promise} */ - listAttributes(collectionId: string): Promise; + listAttributes(databaseId: string, collectionId: string): Promise; /** * Create Boolean Attribute * + * Create a boolean attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -2158,10 +2403,27 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - createBooleanAttribute(collectionId: string, key: string, required: boolean, xdefault?: boolean, array?: boolean): Promise; + createBooleanAttribute(databaseId: string, collectionId: string, key: string, required: boolean, xdefault?: boolean, array?: boolean): Promise; + /** + * Create DateTime Attribute + * + * @param {string} databaseId + * @param {string} collectionId + * @param {string} key + * @param {boolean} required + * @param {string} default + * @param {boolean} array + * @throws {AppwriteException} + * @returns {Promise} + */ + createDatetimeAttribute(databaseId: string, collectionId: string, key: string, required: boolean, xdefault?: string, array?: boolean): Promise; /** * Create Email Attribute * + * Create an email attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -2170,10 +2432,11 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - createEmailAttribute(collectionId: string, key: string, required: boolean, xdefault?: string, array?: boolean): Promise; + createEmailAttribute(databaseId: string, collectionId: string, key: string, required: boolean, xdefault?: string, array?: boolean): Promise; /** * Create Enum Attribute * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {string[]} elements @@ -2183,10 +2446,15 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - createEnumAttribute(collectionId: string, key: string, elements: string[], required: boolean, xdefault?: string, array?: boolean): Promise; + createEnumAttribute(databaseId: string, collectionId: string, key: string, elements: string[], required: boolean, xdefault?: string, array?: boolean): Promise; /** * Create Float Attribute * + * Create a float attribute. Optionally, minimum and maximum values can be + * provided. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -2197,10 +2465,15 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - createFloatAttribute(collectionId: string, key: string, required: boolean, min?: number, max?: number, xdefault?: number, array?: boolean): Promise; + createFloatAttribute(databaseId: string, collectionId: string, key: string, required: boolean, min?: number, max?: number, xdefault?: number, array?: boolean): Promise; /** * Create Integer Attribute * + * Create an integer attribute. Optionally, minimum and maximum values can be + * provided. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -2211,10 +2484,14 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - createIntegerAttribute(collectionId: string, key: string, required: boolean, min?: number, max?: number, xdefault?: number, array?: boolean): Promise; + createIntegerAttribute(databaseId: string, collectionId: string, key: string, required: boolean, min?: number, max?: number, xdefault?: number, array?: boolean): Promise; /** * Create IP Address Attribute * + * Create IP address attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -2223,10 +2500,14 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - createIpAttribute(collectionId: string, key: string, required: boolean, xdefault?: string, array?: boolean): Promise; + createIpAttribute(databaseId: string, collectionId: string, key: string, required: boolean, xdefault?: string, array?: boolean): Promise; /** * Create String Attribute * + * Create a string attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {number} size @@ -2236,10 +2517,14 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - createStringAttribute(collectionId: string, key: string, size: number, required: boolean, xdefault?: string, array?: boolean): Promise; + createStringAttribute(databaseId: string, collectionId: string, key: string, size: number, required: boolean, xdefault?: string, array?: boolean): Promise; /** * Create URL Attribute * + * Create a URL attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -2248,93 +2533,112 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - createUrlAttribute(collectionId: string, key: string, required: boolean, xdefault?: string, array?: boolean): Promise; + createUrlAttribute(databaseId: string, collectionId: string, key: string, required: boolean, xdefault?: string, array?: boolean): Promise; /** * Get Attribute * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @throws {AppwriteException} * @returns {Promise} */ - getAttribute(collectionId: string, key: string): Promise; + getAttribute(databaseId: string, collectionId: string, key: string): Promise; /** * Delete Attribute * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @throws {AppwriteException} * @returns {Promise} */ - deleteAttribute(collectionId: string, key: string): Promise; + deleteAttribute(databaseId: string, collectionId: string, key: string): Promise; /** * List Documents * + * Get a list of all the user's documents in a given collection. You can use + * the query params to filter your results. On admin mode, this endpoint will + * return a list of all of documents belonging to the provided collectionId. + * [Learn more about different API modes](/docs/admin). + * + * @param {string} databaseId * @param {string} collectionId * @param {string[]} queries - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string[]} orderAttributes - * @param {string[]} orderTypes * @throws {AppwriteException} * @returns {Promise} */ - listDocuments(collectionId: string, queries?: string[], limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderAttributes?: string[], orderTypes?: string[]): Promise>; + listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise>; /** * Create Document * + * Create a new Document. Before using this route, you should create a new + * collection resource using either a [server + * integration](/docs/server/databases#databasesCreateCollection) API or + * directly from your database console. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} documentId * @param {object} data - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} */ - createDocument(collectionId: string, documentId: string, data: object, read?: string[], write?: string[]): Promise; + createDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise; /** * Get Document * + * Get a document by its unique ID. This endpoint response returns a JSON + * object with the document data. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} documentId * @throws {AppwriteException} * @returns {Promise} */ - getDocument(collectionId: string, documentId: string): Promise; + getDocument(databaseId: string, collectionId: string, documentId: string): Promise; /** * Update Document * + * Update a document by its unique ID. Using the patch method you can pass + * only specific fields that will get updated. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} documentId * @param {object} data - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} */ - updateDocument(collectionId: string, documentId: string, data?: object, read?: string[], write?: string[]): Promise; + updateDocument(databaseId: string, collectionId: string, documentId: string, data?: object, permissions?: string[]): Promise; /** * Delete Document * + * Delete a document by its unique ID. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} documentId * @throws {AppwriteException} * @returns {Promise} */ - deleteDocument(collectionId: string, documentId: string): Promise; + deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise; /** * List Indexes * + * @param {string} databaseId * @param {string} collectionId * @throws {AppwriteException} * @returns {Promise} */ - listIndexes(collectionId: string): Promise; + listIndexes(databaseId: string, collectionId: string): Promise; /** * Create Index * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {string} type @@ -2343,25 +2647,27 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - createIndex(collectionId: string, key: string, type: string, attributes: string[], orders?: string[]): Promise; + createIndex(databaseId: string, collectionId: string, key: string, type: string, attributes: string[], orders?: string[]): Promise; /** * Get Index * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @throws {AppwriteException} * @returns {Promise} */ - getIndex(collectionId: string, key: string): Promise; + getIndex(databaseId: string, collectionId: string, key: string): Promise; /** * Delete Index * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @throws {AppwriteException} * @returns {Promise} */ - deleteIndex(collectionId: string, key: string): Promise; + deleteIndex(databaseId: string, collectionId: string, key: string): Promise; } export class Functions extends Service { constructor(client: Client); @@ -2372,16 +2678,12 @@ declare module "node-appwrite" { * Get a list of all the project's functions. You can use the query params to * filter your results. * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - list(search?: string, limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderType?: string): Promise; + list(queries?: string[], search?: string): Promise; /** * Create Function * @@ -2393,14 +2695,13 @@ declare module "node-appwrite" { * @param {string} name * @param {string[]} execute * @param {string} runtime - * @param {object} vars * @param {string[]} events * @param {string} schedule * @param {number} timeout * @throws {AppwriteException} * @returns {Promise} */ - create(functionId: string, name: string, execute: string[], runtime: string, vars?: object, events?: string[], schedule?: string, timeout?: number): Promise; + create(functionId: string, name: string, execute: string[], runtime: string, events?: string[], schedule?: string, timeout?: number): Promise; /** * List runtimes * @@ -2428,14 +2729,13 @@ declare module "node-appwrite" { * @param {string} functionId * @param {string} name * @param {string[]} execute - * @param {object} vars * @param {string[]} events * @param {string} schedule * @param {number} timeout * @throws {AppwriteException} * @returns {Promise} */ - update(functionId: string, name: string, execute: string[], vars?: object, events?: string[], schedule?: string, timeout?: number): Promise; + update(functionId: string, name: string, execute: string[], events?: string[], schedule?: string, timeout?: number): Promise; /** * Delete Function * @@ -2453,16 +2753,12 @@ declare module "node-appwrite" { * params to filter your results. * * @param {string} functionId + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - listDeployments(functionId: string, search?: string, limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderType?: string): Promise; + listDeployments(functionId: string, queries?: string[], search?: string): Promise; /** * Create Deployment * @@ -2495,7 +2791,7 @@ declare module "node-appwrite" { * @throws {AppwriteException} * @returns {Promise} */ - getDeployment(functionId: string, deploymentId: string): Promise; + getDeployment(functionId: string, deploymentId: string): Promise; /** * Update Function Deployment * @@ -2539,15 +2835,12 @@ declare module "node-appwrite" { * different API modes](/docs/admin). * * @param {string} functionId - * @param {number} limit - * @param {number} offset + * @param {string[]} queries * @param {string} search - * @param {string} cursor - * @param {string} cursorDirection * @throws {AppwriteException} * @returns {Promise} */ - listExecutions(functionId: string, limit?: number, offset?: number, search?: string, cursor?: string, cursorDirection?: string): Promise; + listExecutions(functionId: string, queries?: string[], search?: string): Promise; /** * Create Execution * @@ -2574,6 +2867,66 @@ declare module "node-appwrite" { * @returns {Promise} */ getExecution(functionId: string, executionId: string): Promise; + /** + * List Variables + * + * Get a list of all variables of a specific function. + * + * @param {string} functionId + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + listVariables(functionId: string, queries?: string[], search?: string): Promise; + /** + * Create Variable + * + * Create a new function variable. These variables can be accessed within + * function in the `env` object under the request variable. + * + * @param {string} functionId + * @param {string} key + * @param {string} value + * @throws {AppwriteException} + * @returns {Promise} + */ + createVariable(functionId: string, key: string, value: string): Promise; + /** + * Get Variable + * + * Get a variable by its unique ID. + * + * @param {string} functionId + * @param {string} variableId + * @throws {AppwriteException} + * @returns {Promise} + */ + getVariable(functionId: string, variableId: string): Promise; + /** + * Update Variable + * + * Update variable by its unique ID. + * + * @param {string} functionId + * @param {string} variableId + * @param {string} key + * @param {string} value + * @throws {AppwriteException} + * @returns {Promise} + */ + updateVariable(functionId: string, variableId: string, key: string, value?: string): Promise; + /** + * Delete Variable + * + * Delete a variable by its unique ID. + * + * @param {string} functionId + * @param {string} variableId + * @throws {AppwriteException} + * @returns {Promise} + */ + deleteVariable(functionId: string, variableId: string): Promise; } export class Health extends Service { constructor(client: Client); @@ -2766,16 +3119,12 @@ declare module "node-appwrite" { * Get a list of all the storage buckets. You can use the query params to * filter your results. * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - listBuckets(search?: string, limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderType?: string): Promise; + listBuckets(queries?: string[], search?: string): Promise; /** * Create bucket * @@ -2783,18 +3132,18 @@ declare module "node-appwrite" { * * @param {string} bucketId * @param {string} name - * @param {string} permission - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions + * @param {boolean} fileSecurity * @param {boolean} enabled * @param {number} maximumFileSize * @param {string[]} allowedFileExtensions + * @param {string} compression * @param {boolean} encryption * @param {boolean} antivirus * @throws {AppwriteException} * @returns {Promise} */ - createBucket(bucketId: string, name: string, permission: string, read?: string[], write?: string[], enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], encryption?: boolean, antivirus?: boolean): Promise; + createBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: string, encryption?: boolean, antivirus?: boolean): Promise; /** * Get Bucket * @@ -2813,18 +3162,18 @@ declare module "node-appwrite" { * * @param {string} bucketId * @param {string} name - * @param {string} permission - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions + * @param {boolean} fileSecurity * @param {boolean} enabled * @param {number} maximumFileSize * @param {string[]} allowedFileExtensions + * @param {string} compression * @param {boolean} encryption * @param {boolean} antivirus * @throws {AppwriteException} * @returns {Promise} */ - updateBucket(bucketId: string, name: string, permission: string, read?: string[], write?: string[], enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], encryption?: boolean, antivirus?: boolean): Promise; + updateBucket(bucketId: string, name: string, permissions?: string[], fileSecurity?: boolean, enabled?: boolean, maximumFileSize?: number, allowedFileExtensions?: string[], compression?: string, encryption?: boolean, antivirus?: boolean): Promise; /** * Delete Bucket * @@ -2843,23 +3192,19 @@ declare module "node-appwrite" { * project's files. [Learn more about different API modes](/docs/admin). * * @param {string} bucketId + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - listFiles(bucketId: string, search?: string, limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderType?: string): Promise; + listFiles(bucketId: string, queries?: string[], search?: string): Promise; /** * Create File * * Create a new file. Before using this route, you should create a new bucket * resource using either a [server - * integration](/docs/server/database#storageCreateBucket) API or directly - * from your Appwrite console. + * integration](/docs/server/storage#storageCreateBucket) API or directly from + * your Appwrite console. * * Larger files should be uploaded using multiple requests with the * [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) @@ -2878,12 +3223,11 @@ declare module "node-appwrite" { * @param {string} bucketId * @param {string} fileId * @param {InputFile} file - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} */ - createFile(bucketId: string, fileId: string, file: InputFile, read?: string[], write?: string[]): Promise; + createFile(bucketId: string, fileId: string, file: InputFile, permissions?: string[]): Promise; /** * Get File * @@ -2904,12 +3248,11 @@ declare module "node-appwrite" { * * @param {string} bucketId * @param {string} fileId - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} */ - updateFile(bucketId: string, fileId: string, read?: string[], write?: string[]): Promise; + updateFile(bucketId: string, fileId: string, permissions?: string[]): Promise; /** * Delete File * @@ -2987,16 +3330,12 @@ declare module "node-appwrite" { * In admin mode, this endpoint returns a list of all the teams in the current * project. [Learn more about different API modes](/docs/admin). * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - list(search?: string, limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderType?: string): Promise; + list(queries?: string[], search?: string): Promise; /** * Create Team * @@ -3051,16 +3390,12 @@ declare module "node-appwrite" { * members have read access to this endpoint. * * @param {string} teamId + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - getMemberships(teamId: string, search?: string, limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderType?: string): Promise; + getMemberships(teamId: string, queries?: string[], search?: string): Promise; /** * Create Team Membership * @@ -3157,16 +3492,12 @@ declare module "node-appwrite" { * Get a list of all the project's users. You can use the query params to * filter your results. * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - list(search?: string, limit?: number, offset?: number, cursor?: string, cursorDirection?: string, orderType?: string): Promise>; + list(queries?: string[], search?: string): Promise>; /** * Create User * @@ -3174,12 +3505,134 @@ declare module "node-appwrite" { * * @param {string} userId * @param {string} email + * @param {string} phone * @param {string} password * @param {string} name * @throws {AppwriteException} * @returns {Promise} */ - create(userId: string, email: string, password: string, name?: string): Promise>; + create(userId: string, email?: string, phone?: string, password?: string, name?: string): Promise>; + /** + * Create User with Argon2 Password + * + * Create a new user. Password provided must be hashed with the + * [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + createArgon2User(userId: string, email: string, password: string, name?: string): Promise>; + /** + * Create User with Bcrypt Password + * + * Create a new user. Password provided must be hashed with the + * [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + createBcryptUser(userId: string, email: string, password: string, name?: string): Promise>; + /** + * Create User with MD5 Password + * + * Create a new user. Password provided must be hashed with the + * [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + createMD5User(userId: string, email: string, password: string, name?: string): Promise>; + /** + * Create User with PHPass Password + * + * Create a new user. Password provided must be hashed with the + * [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + createPHPassUser(userId: string, email: string, password: string, name?: string): Promise>; + /** + * Create User with Scrypt Password + * + * Create a new user. Password provided must be hashed with the + * [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} passwordSalt + * @param {number} passwordCpu + * @param {number} passwordMemory + * @param {number} passwordParallel + * @param {number} passwordLength + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + createScryptUser(userId: string, email: string, password: string, passwordSalt: string, passwordCpu: number, passwordMemory: number, passwordParallel: number, passwordLength: number, name?: string): Promise>; + /** + * Create User with Scrypt Modified Password + * + * Create a new user. Password provided must be hashed with the [Scrypt + * Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) + * algorithm. Use the [POST /users](/docs/server/users#usersCreate) endpoint + * to create users with a plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} passwordSalt + * @param {string} passwordSaltSeparator + * @param {string} passwordSignerKey + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + createScryptModifiedUser(userId: string, email: string, password: string, passwordSalt: string, passwordSaltSeparator: string, passwordSignerKey: string, name?: string): Promise>; + /** + * Create User with SHA Password + * + * Create a new user. Password provided must be hashed with the + * [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use + * the [POST /users](/docs/server/users#usersCreate) endpoint to create users + * with a plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} passwordVersion + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + createSHAUser(userId: string, email: string, password: string, passwordVersion?: string, name?: string): Promise>; /** * Get User * @@ -3221,12 +3674,11 @@ declare module "node-appwrite" { * Get the user activity logs list by its unique ID. * * @param {string} userId - * @param {number} limit - * @param {number} offset + * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} */ - getLogs(userId: string, limit?: number, offset?: number): Promise; + getLogs(userId: string, queries?: string[]): Promise; /** * Get User Memberships * diff --git a/index.js b/index.js index 638c50a..4e1181f 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,8 @@ const Client = require('./lib/client.js'); const Query = require('./lib/query.js'); +const Permission = require('./lib/permission.js'); +const Role = require('./lib/role.js'); +const ID = require('./lib/id.js'); const InputFile = require('./lib/inputFile.js'); const AppwriteException = require('./lib/exception.js'); const Account = require('./lib/services/account.js'); @@ -15,6 +18,9 @@ const Users = require('./lib/services/users.js'); module.exports = { Client, Query, + Permission, + Role, + ID, InputFile, AppwriteException, Account, diff --git a/lib/client.js b/lib/client.js index bc69246..5b582c5 100644 --- a/lib/client.js +++ b/lib/client.js @@ -10,8 +10,11 @@ class Client { this.endpoint = 'https://HOSTNAME/v1'; this.headers = { 'content-type': '', - 'x-sdk-version': 'appwrite:nodejs:7.0.2', - 'X-Appwrite-Response-Format' : '0.15.0', + 'x-sdk-name': 'Node.js', + 'x-sdk-platform': 'server', + 'x-sdk-language': 'nodejs', + 'x-sdk-version': '8.0.0-RC1', + 'X-Appwrite-Response-Format' : '1.0.0-RC1', }; this.selfSigned = false; } diff --git a/lib/id.js b/lib/id.js new file mode 100644 index 0000000..d168caf --- /dev/null +++ b/lib/id.js @@ -0,0 +1,12 @@ +class ID { + + static unique = () => { + return 'unique()' + } + + static custom = (id) => { + return id + } +} + +module.exports = ID; diff --git a/lib/permission.js b/lib/permission.js new file mode 100644 index 0000000..67a7003 --- /dev/null +++ b/lib/permission.js @@ -0,0 +1,24 @@ +class Permission { + + static read = (role) => { + return `read("${role}")` + } + + static write = (role) => { + return `write("${role}")` + } + + static create = (role) => { + return `create("${role}")` + } + + static update = (role) => { + return `update("${role}")` + } + + static delete = (role) => { + return `delete("${role}")` + } +} + +module.exports = Permission; diff --git a/lib/query.js b/lib/query.js index 1014131..2534686 100644 --- a/lib/query.js +++ b/lib/query.js @@ -5,27 +5,45 @@ class Query { static notEqual = (attribute, value) => Query.addQuery(attribute, "notEqual", value); - static lesser = (attribute, value) => - Query.addQuery(attribute, "lesser", value); + static lessThan = (attribute, value) => + Query.addQuery(attribute, "lessThan", value); - static lesserEqual = (attribute, value) => - Query.addQuery(attribute, "lesserEqual", value); + static lessThanEqual = (attribute, value) => + Query.addQuery(attribute, "lessThanEqual", value); - static greater = (attribute, value) => - Query.addQuery(attribute, "greater", value); + static greaterThan = (attribute, value) => + Query.addQuery(attribute, "greaterThan", value); - static greaterEqual = (attribute, value) => - Query.addQuery(attribute, "greaterEqual", value); + static greaterThanEqual = (attribute, value) => + Query.addQuery(attribute, "greaterThanEqual", value); static search = (attribute, value) => Query.addQuery(attribute, "search", value); - static addQuery = (attribute, oper, value) => + static orderDesc = (attribute) => + `orderDesc("${attribute}")`; + + static orderAsc = (attribute) => + `orderAsc("${attribute}")`; + + static cursorAfter = (documentId) => + `cursorAfter("${documentId}")`; + + static cursorBefore = (documentId) => + `cursorBefore("${documentId}")`; + + static limit = (limit) => + `limit(${limit})`; + + static offset = (offset) => + `offset(${offset})`; + + static addQuery = (attribute, method, value) => value instanceof Array - ? `${attribute}.${oper}(${value + ? `${method}("${attribute}", [${value .map((v) => Query.parseValues(v)) - .join(",")})` - : `${attribute}.${oper}(${Query.parseValues(value)})`; + .join(",")}])` + : `${method}("${attribute}", [${Query.parseValues(value)}])`; static parseValues = (value) => typeof value === "string" || value instanceof String diff --git a/lib/role.js b/lib/role.js new file mode 100644 index 0000000..bb35d0f --- /dev/null +++ b/lib/role.js @@ -0,0 +1,25 @@ +class Role { + static any = () => { + return 'any' + } + static user = (id) => { + return 'user:' + id + } + static users = () => { + return 'users' + } + static guests = () => { + return 'guests' + } + static team = (id, role = '') => { + if(role === '') { + return 'team:' + id + } + return 'team:' + id + '/' + role + } + static status = (status) => { + return 'status:' + status + } +} + +module.exports = Role; \ No newline at end of file diff --git a/lib/services/account.js b/lib/services/account.js index 385df2e..bc7bd2b 100644 --- a/lib/services/account.js +++ b/lib/services/account.js @@ -8,6 +8,12 @@ const fs = require('fs'); class Account extends Service { + constructor(client) + { + super(client); + } + + /** * Get Account * @@ -43,6 +49,8 @@ class Account extends Service { * @returns {Promise} */ async updateEmail(email, password) { + let path = '/account/email'; + let payload = {}; if (typeof email === 'undefined') { throw new AppwriteException('Missing required parameter: "email"'); } @@ -51,8 +59,6 @@ class Account extends Service { throw new AppwriteException('Missing required parameter: "password"'); } - let path = '/account/email'; - let payload = {}; if (typeof email !== 'undefined') { payload['email'] = email; @@ -73,21 +79,16 @@ class Account extends Service { * Get currently logged in user list of latest security activity logs. Each * log returns user IP address, location and date and time of log. * - * @param {number} limit - * @param {number} offset + * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} */ - async getLogs(limit, offset) { + async getLogs(queries) { let path = '/account/logs'; let payload = {}; - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - - if (typeof offset !== 'undefined') { - payload['offset'] = offset; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } return await this.client.call('get', path, { @@ -105,12 +106,12 @@ class Account extends Service { * @returns {Promise} */ async updateName(name) { + let path = '/account/name'; + let payload = {}; if (typeof name === 'undefined') { throw new AppwriteException('Missing required parameter: "name"'); } - let path = '/account/name'; - let payload = {}; if (typeof name !== 'undefined') { payload['name'] = name; @@ -134,12 +135,12 @@ class Account extends Service { * @returns {Promise} */ async updatePassword(password, oldPassword) { + let path = '/account/password'; + let payload = {}; if (typeof password === 'undefined') { throw new AppwriteException('Missing required parameter: "password"'); } - let path = '/account/password'; - let payload = {}; if (typeof password !== 'undefined') { payload['password'] = password; @@ -163,25 +164,25 @@ class Account extends Service { * /account/verification/phone](/docs/client/account#accountCreatePhoneVerification) * endpoint to send a confirmation SMS. * - * @param {string} number + * @param {string} phone * @param {string} password * @throws {AppwriteException} * @returns {Promise} */ - async updatePhone(number, password) { - if (typeof number === 'undefined') { - throw new AppwriteException('Missing required parameter: "number"'); + async updatePhone(phone, password) { + let path = '/account/phone'; + let payload = {}; + if (typeof phone === 'undefined') { + throw new AppwriteException('Missing required parameter: "phone"'); } if (typeof password === 'undefined') { throw new AppwriteException('Missing required parameter: "password"'); } - let path = '/account/phone'; - let payload = {}; - if (typeof number !== 'undefined') { - payload['number'] = number; + if (typeof phone !== 'undefined') { + payload['phone'] = phone; } if (typeof password !== 'undefined') { @@ -222,12 +223,12 @@ class Account extends Service { * @returns {Promise} */ async updatePrefs(prefs) { + let path = '/account/prefs'; + let payload = {}; if (typeof prefs === 'undefined') { throw new AppwriteException('Missing required parameter: "prefs"'); } - let path = '/account/prefs'; - let payload = {}; if (typeof prefs !== 'undefined') { payload['prefs'] = prefs; @@ -256,6 +257,8 @@ class Account extends Service { * @returns {Promise} */ async createRecovery(email, url) { + let path = '/account/recovery'; + let payload = {}; if (typeof email === 'undefined') { throw new AppwriteException('Missing required parameter: "email"'); } @@ -264,8 +267,6 @@ class Account extends Service { throw new AppwriteException('Missing required parameter: "url"'); } - let path = '/account/recovery'; - let payload = {}; if (typeof email !== 'undefined') { payload['email'] = email; @@ -301,6 +302,8 @@ class Account extends Service { * @returns {Promise} */ async updateRecovery(userId, secret, password, passwordAgain) { + let path = '/account/recovery'; + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -317,8 +320,6 @@ class Account extends Service { throw new AppwriteException('Missing required parameter: "passwordAgain"'); } - let path = '/account/recovery'; - let payload = {}; if (typeof userId !== 'undefined') { payload['userId'] = userId; @@ -388,12 +389,12 @@ class Account extends Service { * @returns {Promise} */ async getSession(sessionId) { + let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + let payload = {}; if (typeof sessionId === 'undefined') { throw new AppwriteException('Missing required parameter: "sessionId"'); } - let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -412,12 +413,12 @@ class Account extends Service { * @returns {Promise} */ async updateSession(sessionId) { + let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + let payload = {}; if (typeof sessionId === 'undefined') { throw new AppwriteException('Missing required parameter: "sessionId"'); } - let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); - let payload = {}; return await this.client.call('patch', path, { 'content-type': 'application/json', @@ -437,12 +438,12 @@ class Account extends Service { * @returns {Promise} */ async deleteSession(sessionId) { + let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + let payload = {}; if (typeof sessionId === 'undefined') { throw new AppwriteException('Missing required parameter: "sessionId"'); } - let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -492,12 +493,12 @@ class Account extends Service { * @returns {Promise} */ async createVerification(url) { + let path = '/account/verification'; + let payload = {}; if (typeof url === 'undefined') { throw new AppwriteException('Missing required parameter: "url"'); } - let path = '/account/verification'; - let payload = {}; if (typeof url !== 'undefined') { payload['url'] = url; @@ -522,6 +523,8 @@ class Account extends Service { * @returns {Promise} */ async updateVerification(userId, secret) { + let path = '/account/verification'; + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -530,8 +533,6 @@ class Account extends Service { throw new AppwriteException('Missing required parameter: "secret"'); } - let path = '/account/verification'; - let payload = {}; if (typeof userId !== 'undefined') { payload['userId'] = userId; @@ -582,6 +583,8 @@ class Account extends Service { * @returns {Promise} */ async updatePhoneVerification(userId, secret) { + let path = '/account/verification/phone'; + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -590,8 +593,6 @@ class Account extends Service { throw new AppwriteException('Missing required parameter: "secret"'); } - let path = '/account/verification/phone'; - let payload = {}; if (typeof userId !== 'undefined') { payload['userId'] = userId; @@ -607,4 +608,4 @@ class Account extends Service { } } -module.exports = Account; \ No newline at end of file +module.exports = Account; diff --git a/lib/services/avatars.js b/lib/services/avatars.js index 0a56509..32d662a 100644 --- a/lib/services/avatars.js +++ b/lib/services/avatars.js @@ -8,6 +8,12 @@ const fs = require('fs'); class Avatars extends Service { + constructor(client) + { + super(client); + } + + /** * Get Browser Icon * @@ -29,12 +35,12 @@ class Avatars extends Service { * @returns {Promise} */ async getBrowser(code, width, height, quality) { + let path = '/avatars/browsers/{code}'.replace('{code}', code); + let payload = {}; if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); } - let path = '/avatars/browsers/{code}'.replace('{code}', code); - let payload = {}; if (typeof width !== 'undefined') { payload['width'] = width; @@ -74,12 +80,12 @@ class Avatars extends Service { * @returns {Promise} */ async getCreditCard(code, width, height, quality) { + let path = '/avatars/credit-cards/{code}'.replace('{code}', code); + let payload = {}; if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); } - let path = '/avatars/credit-cards/{code}'.replace('{code}', code); - let payload = {}; if (typeof width !== 'undefined') { payload['width'] = width; @@ -110,12 +116,12 @@ class Avatars extends Service { * @returns {Promise} */ async getFavicon(url) { + let path = '/avatars/favicon'; + let payload = {}; if (typeof url === 'undefined') { throw new AppwriteException('Missing required parameter: "url"'); } - let path = '/avatars/favicon'; - let payload = {}; if (typeof url !== 'undefined') { payload['url'] = url; @@ -131,7 +137,8 @@ class Avatars extends Service { * * 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. + * height and quality arguments to change the output settings. Country codes + * follow the [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) standard. * * When one dimension is specified and the other is 0, the image is scaled * with preserved aspect ratio. If both dimensions are 0, the API provides an @@ -147,12 +154,12 @@ class Avatars extends Service { * @returns {Promise} */ async getFlag(code, width, height, quality) { + let path = '/avatars/flags/{code}'.replace('{code}', code); + let payload = {}; if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); } - let path = '/avatars/flags/{code}'.replace('{code}', code); - let payload = {}; if (typeof width !== 'undefined') { payload['width'] = width; @@ -192,12 +199,12 @@ class Avatars extends Service { * @returns {Promise} */ async getImage(url, width, height) { + let path = '/avatars/image'; + let payload = {}; if (typeof url === 'undefined') { throw new AppwriteException('Missing required parameter: "url"'); } - let path = '/avatars/image'; - let payload = {}; if (typeof url !== 'undefined') { payload['url'] = url; @@ -239,12 +246,11 @@ class Avatars extends Service { * @param {string} name * @param {number} width * @param {number} height - * @param {string} color * @param {string} background * @throws {AppwriteException} * @returns {Promise} */ - async getInitials(name, width, height, color, background) { + async getInitials(name, width, height, background) { let path = '/avatars/initials'; let payload = {}; @@ -260,10 +266,6 @@ class Avatars extends Service { payload['height'] = height; } - if (typeof color !== 'undefined') { - payload['color'] = color; - } - if (typeof background !== 'undefined') { payload['background'] = background; } @@ -288,12 +290,12 @@ class Avatars extends Service { * @returns {Promise} */ async getQR(text, size, margin, download) { + let path = '/avatars/qr'; + let payload = {}; if (typeof text === 'undefined') { throw new AppwriteException('Missing required parameter: "text"'); } - let path = '/avatars/qr'; - let payload = {}; if (typeof text !== 'undefined') { payload['text'] = text; @@ -317,4 +319,4 @@ class Avatars extends Service { } } -module.exports = Avatars; \ No newline at end of file +module.exports = Avatars; diff --git a/lib/services/databases.js b/lib/services/databases.js index cf8c61d..494d408 100644 --- a/lib/services/databases.js +++ b/lib/services/databases.js @@ -7,72 +7,34 @@ const { promisify } = require('util'); const fs = require('fs'); class Databases extends Service { - databaseId; - /** - * Set databaseId. - * - * @param {string} databaseId - * - * @return void - */ - setDatabaseId(databaseId) - { - this.databaseId = databaseId; - } - /** - * Get databaseId. - * - * @return string - */ - getDatabaseId() - { - return this.databaseId; - } - constructor(client, databaseId) + + constructor(client) { super(client); - - this.databaseId = databaseId; } + /** * List Databases * + * Get a list of all databases from the current Appwrite project. You can use + * the search parameter to filter your results. + * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - async list(search, limit, offset, cursor, cursorDirection, orderType) { + async list(queries, search) { let path = '/databases'; let payload = {}; - if (typeof search !== 'undefined') { - payload['search'] = search; - } - - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - - if (typeof offset !== 'undefined') { - payload['offset'] = offset; - } - - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } - if (typeof orderType !== 'undefined') { - payload['orderType'] = orderType; + if (typeof search !== 'undefined') { + payload['search'] = search; } return await this.client.call('get', path, { @@ -83,20 +45,28 @@ class Databases extends Service { /** * Create Database * + * Create a new Database. + * + * + * @param {string} databaseId * @param {string} name * @throws {AppwriteException} * @returns {Promise} */ - async create(name) { + async create(databaseId, name) { + let path = '/databases'; + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof name === 'undefined') { throw new AppwriteException('Missing required parameter: "name"'); } - let path = '/databases'; - let payload = {}; - if (typeof this.databaseId !== 'undefined') { - payload['databaseId'] = this.databaseId; + if (typeof databaseId !== 'undefined') { + payload['databaseId'] = databaseId; } if (typeof name !== 'undefined') { @@ -111,12 +81,20 @@ class Databases extends Service { /** * Get Database * + * Get a database by its unique ID. This endpoint response returns a JSON + * object with the database metadata. + * + * @param {string} databaseId * @throws {AppwriteException} * @returns {Promise} */ - async get() { - let path = '/databases/{databaseId}'.replace('{databaseId}', this.databaseId); + async get(databaseId) { + let path = '/databases/{databaseId}'.replace('{databaseId}', databaseId); let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + return await this.client.call('get', path, { 'content-type': 'application/json', @@ -126,17 +104,24 @@ class Databases extends Service { /** * Update Database * + * Update a database by its unique ID. + * + * @param {string} databaseId * @param {string} name * @throws {AppwriteException} * @returns {Promise} */ - async update(name) { + async update(databaseId, name) { + let path = '/databases/{databaseId}'.replace('{databaseId}', databaseId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof name === 'undefined') { throw new AppwriteException('Missing required parameter: "name"'); } - let path = '/databases/{databaseId}'.replace('{databaseId}', this.databaseId); - let payload = {}; if (typeof name !== 'undefined') { payload['name'] = name; @@ -150,12 +135,20 @@ class Databases extends Service { /** * Delete Database * + * Delete a database by its unique ID. Only API keys with with databases.write + * scope can delete a database. + * + * @param {string} databaseId * @throws {AppwriteException} * @returns {Promise} */ - async delete() { - let path = '/databases/{databaseId}'.replace('{databaseId}', this.databaseId); + async delete(databaseId) { + let path = '/databases/{databaseId}'.replace('{databaseId}', databaseId); let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -165,41 +158,29 @@ class Databases extends Service { /** * List Collections * + * Get a list of all collections that belong to the provided databaseId. You + * can use the search parameter to filter your results. + * + * @param {string} databaseId + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - async listCollections(search, limit, offset, cursor, cursorDirection, orderType) { - let path = '/databases/{databaseId}/collections'.replace('{databaseId}', this.databaseId); + async listCollections(databaseId, queries, search) { + let path = '/databases/{databaseId}/collections'.replace('{databaseId}', databaseId); let payload = {}; - - if (typeof search !== 'undefined') { - payload['search'] = search; - } - - if (typeof limit !== 'undefined') { - payload['limit'] = limit; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); } - if (typeof offset !== 'undefined') { - payload['offset'] = offset; - } - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } - if (typeof orderType !== 'undefined') { - payload['orderType'] = orderType; + if (typeof search !== 'undefined') { + payload['search'] = search; } return await this.client.call('get', path, { @@ -210,15 +191,26 @@ class Databases extends Service { /** * Create Collection * + * Create a new Collection. Before using this route, you should create a new + * database resource using either a [server + * integration](/docs/server/databases#databasesCreateCollection) API or + * directly from your database console. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} name - * @param {string} permission - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions + * @param {boolean} documentSecurity * @throws {AppwriteException} * @returns {Promise} */ - async createCollection(collectionId, name, permission, read, write) { + async createCollection(databaseId, collectionId, name, permissions, documentSecurity) { + let path = '/databases/{databaseId}/collections'.replace('{databaseId}', databaseId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -227,20 +219,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "name"'); } - if (typeof permission === 'undefined') { - throw new AppwriteException('Missing required parameter: "permission"'); - } - - if (typeof read === 'undefined') { - throw new AppwriteException('Missing required parameter: "read"'); - } - - if (typeof write === 'undefined') { - throw new AppwriteException('Missing required parameter: "write"'); - } - - let path = '/databases/{databaseId}/collections'.replace('{databaseId}', this.databaseId); - let payload = {}; if (typeof collectionId !== 'undefined') { payload['collectionId'] = collectionId; @@ -250,16 +228,12 @@ class Databases extends Service { payload['name'] = name; } - if (typeof permission !== 'undefined') { - payload['permission'] = permission; - } - - if (typeof read !== 'undefined') { - payload['read'] = read; + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; } - if (typeof write !== 'undefined') { - payload['write'] = write; + if (typeof documentSecurity !== 'undefined') { + payload['documentSecurity'] = documentSecurity; } return await this.client.call('post', path, { @@ -270,17 +244,25 @@ class Databases extends Service { /** * Get Collection * + * Get a collection by its unique ID. This endpoint response returns a JSON + * object with the collection metadata. + * + * @param {string} databaseId * @param {string} collectionId * @throws {AppwriteException} * @returns {Promise} */ - async getCollection(collectionId) { + async getCollection(databaseId, collectionId) { + let path = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } - let path = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -290,16 +272,24 @@ class Databases extends Service { /** * Update Collection * + * Update a collection by its unique ID. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} name - * @param {string} permission - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions + * @param {boolean} documentSecurity * @param {boolean} enabled * @throws {AppwriteException} * @returns {Promise} */ - async updateCollection(collectionId, name, permission, read, write, enabled) { + async updateCollection(databaseId, collectionId, name, permissions, documentSecurity, enabled) { + let path = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -308,27 +298,17 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "name"'); } - if (typeof permission === 'undefined') { - throw new AppwriteException('Missing required parameter: "permission"'); - } - - let path = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof name !== 'undefined') { payload['name'] = name; } - if (typeof permission !== 'undefined') { - payload['permission'] = permission; + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; } - if (typeof read !== 'undefined') { - payload['read'] = read; - } - - if (typeof write !== 'undefined') { - payload['write'] = write; + if (typeof documentSecurity !== 'undefined') { + payload['documentSecurity'] = documentSecurity; } if (typeof enabled !== 'undefined') { @@ -343,17 +323,25 @@ class Databases extends Service { /** * Delete Collection * + * Delete a collection by its unique ID. Only users with write permissions + * have access to delete this resource. + * + * @param {string} databaseId * @param {string} collectionId * @throws {AppwriteException} * @returns {Promise} */ - async deleteCollection(collectionId) { + async deleteCollection(databaseId, collectionId) { + let path = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } - let path = '/databases/{databaseId}/collections/{collectionId}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -363,17 +351,22 @@ class Databases extends Service { /** * List Attributes * + * @param {string} databaseId * @param {string} collectionId * @throws {AppwriteException} * @returns {Promise} */ - async listAttributes(collectionId) { + async listAttributes(databaseId, collectionId) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -383,6 +376,10 @@ class Databases extends Service { /** * Create Boolean Attribute * + * Create a boolean attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -391,7 +388,13 @@ class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createBooleanAttribute(collectionId, key, required, xdefault, array) { + async createBooleanAttribute(databaseId, collectionId, key, required, xdefault, array) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -404,8 +407,59 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "required"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/boolean'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); + + if (typeof key !== 'undefined') { + payload['key'] = key; + } + + if (typeof required !== 'undefined') { + payload['required'] = required; + } + + if (typeof xdefault !== 'undefined') { + payload['default'] = xdefault; + } + + if (typeof array !== 'undefined') { + payload['array'] = array; + } + + return await this.client.call('post', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create DateTime Attribute + * + * @param {string} databaseId + * @param {string} collectionId + * @param {string} key + * @param {boolean} required + * @param {string} xdefault + * @param {boolean} array + * @throws {AppwriteException} + * @returns {Promise} + */ + async createDatetimeAttribute(databaseId, collectionId, key, required, xdefault, array) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/datetime'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + + if (typeof key === 'undefined') { + throw new AppwriteException('Missing required parameter: "key"'); + } + + if (typeof required === 'undefined') { + throw new AppwriteException('Missing required parameter: "required"'); + } + if (typeof key !== 'undefined') { payload['key'] = key; @@ -431,6 +485,10 @@ class Databases extends Service { /** * Create Email Attribute * + * Create an email attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -439,7 +497,13 @@ class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createEmailAttribute(collectionId, key, required, xdefault, array) { + async createEmailAttribute(databaseId, collectionId, key, required, xdefault, array) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/email'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -452,8 +516,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "required"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/email'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof key !== 'undefined') { payload['key'] = key; @@ -479,6 +541,7 @@ class Databases extends Service { /** * Create Enum Attribute * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {string[]} elements @@ -488,7 +551,13 @@ class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createEnumAttribute(collectionId, key, elements, required, xdefault, array) { + async createEnumAttribute(databaseId, collectionId, key, elements, required, xdefault, array) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/enum'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -505,8 +574,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "required"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/enum'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof key !== 'undefined') { payload['key'] = key; @@ -536,6 +603,11 @@ class Databases extends Service { /** * Create Float Attribute * + * Create a float attribute. Optionally, minimum and maximum values can be + * provided. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -546,7 +618,13 @@ class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createFloatAttribute(collectionId, key, required, min, max, xdefault, array) { + async createFloatAttribute(databaseId, collectionId, key, required, min, max, xdefault, array) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/float'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -559,8 +637,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "required"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/float'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof key !== 'undefined') { payload['key'] = key; @@ -594,6 +670,11 @@ class Databases extends Service { /** * Create Integer Attribute * + * Create an integer attribute. Optionally, minimum and maximum values can be + * provided. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -604,7 +685,13 @@ class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createIntegerAttribute(collectionId, key, required, min, max, xdefault, array) { + async createIntegerAttribute(databaseId, collectionId, key, required, min, max, xdefault, array) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/integer'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -617,8 +704,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "required"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/integer'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof key !== 'undefined') { payload['key'] = key; @@ -652,6 +737,10 @@ class Databases extends Service { /** * Create IP Address Attribute * + * Create IP address attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -660,7 +749,13 @@ class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createIpAttribute(collectionId, key, required, xdefault, array) { + async createIpAttribute(databaseId, collectionId, key, required, xdefault, array) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/ip'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -673,8 +768,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "required"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/ip'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof key !== 'undefined') { payload['key'] = key; @@ -700,6 +793,10 @@ class Databases extends Service { /** * Create String Attribute * + * Create a string attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {number} size @@ -709,7 +806,13 @@ class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createStringAttribute(collectionId, key, size, required, xdefault, array) { + async createStringAttribute(databaseId, collectionId, key, size, required, xdefault, array) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/string'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -726,8 +829,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "required"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/string'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof key !== 'undefined') { payload['key'] = key; @@ -757,6 +858,10 @@ class Databases extends Service { /** * Create URL Attribute * + * Create a URL attribute. + * + * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {boolean} required @@ -765,7 +870,13 @@ class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createUrlAttribute(collectionId, key, required, xdefault, array) { + async createUrlAttribute(databaseId, collectionId, key, required, xdefault, array) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/url'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -778,8 +889,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "required"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/url'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof key !== 'undefined') { payload['key'] = key; @@ -805,12 +914,19 @@ class Databases extends Service { /** * Get Attribute * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @throws {AppwriteException} * @returns {Promise} */ - async getAttribute(collectionId, key) { + async getAttribute(databaseId, collectionId, key) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -819,8 +935,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "key"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId).replace('{key}', key); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -830,12 +944,19 @@ class Databases extends Service { /** * Delete Attribute * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @throws {AppwriteException} * @returns {Promise} */ - async deleteAttribute(collectionId, key) { + async deleteAttribute(databaseId, collectionId, key) { + let path = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -844,8 +965,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "key"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/attributes/{key}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId).replace('{key}', key); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -855,53 +974,33 @@ class Databases extends Service { /** * List Documents * + * Get a list of all the user's documents in a given collection. You can use + * the query params to filter your results. On admin mode, this endpoint will + * return a list of all of documents belonging to the provided collectionId. + * [Learn more about different API modes](/docs/admin). + * + * @param {string} databaseId * @param {string} collectionId * @param {string[]} queries - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string[]} orderAttributes - * @param {string[]} orderTypes * @throws {AppwriteException} * @returns {Promise} */ - async listDocuments(collectionId, queries, limit, offset, cursor, cursorDirection, orderAttributes, orderTypes) { + async listDocuments(databaseId, collectionId, queries) { + let path = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof queries !== 'undefined') { payload['queries'] = queries; } - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - - if (typeof offset !== 'undefined') { - payload['offset'] = offset; - } - - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; - } - - if (typeof orderAttributes !== 'undefined') { - payload['orderAttributes'] = orderAttributes; - } - - if (typeof orderTypes !== 'undefined') { - payload['orderTypes'] = orderTypes; - } - return await this.client.call('get', path, { 'content-type': 'application/json', }, payload); @@ -910,15 +1009,26 @@ class Databases extends Service { /** * Create Document * + * Create a new Document. Before using this route, you should create a new + * collection resource using either a [server + * integration](/docs/server/databases#databasesCreateCollection) API or + * directly from your database console. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} documentId * @param {object} data - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} */ - async createDocument(collectionId, documentId, data, read, write) { + async createDocument(databaseId, collectionId, documentId, data, permissions) { + let path = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -931,8 +1041,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "data"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof documentId !== 'undefined') { payload['documentId'] = documentId; @@ -942,12 +1050,8 @@ class Databases extends Service { payload['data'] = data; } - if (typeof read !== 'undefined') { - payload['read'] = read; - } - - if (typeof write !== 'undefined') { - payload['write'] = write; + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; } return await this.client.call('post', path, { @@ -958,12 +1062,22 @@ class Databases extends Service { /** * Get Document * + * Get a document by its unique ID. This endpoint response returns a JSON + * object with the document data. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} documentId * @throws {AppwriteException} * @returns {Promise} */ - async getDocument(collectionId, documentId) { + async getDocument(databaseId, collectionId, documentId) { + let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -972,8 +1086,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "documentId"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -983,15 +1095,24 @@ class Databases extends Service { /** * Update Document * + * Update a document by its unique ID. Using the patch method you can pass + * only specific fields that will get updated. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} documentId * @param {object} data - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} */ - async updateDocument(collectionId, documentId, data, read, write) { + async updateDocument(databaseId, collectionId, documentId, data, permissions) { + let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -1000,19 +1121,13 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "documentId"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); - let payload = {}; if (typeof data !== 'undefined') { payload['data'] = data; } - if (typeof read !== 'undefined') { - payload['read'] = read; - } - - if (typeof write !== 'undefined') { - payload['write'] = write; + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; } return await this.client.call('patch', path, { @@ -1023,12 +1138,21 @@ class Databases extends Service { /** * Delete Document * + * Delete a document by its unique ID. + * + * @param {string} databaseId * @param {string} collectionId * @param {string} documentId * @throws {AppwriteException} * @returns {Promise} */ - async deleteDocument(collectionId, documentId) { + async deleteDocument(databaseId, collectionId, documentId) { + let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -1037,8 +1161,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "documentId"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -1048,17 +1170,22 @@ class Databases extends Service { /** * List Indexes * + * @param {string} databaseId * @param {string} collectionId * @throws {AppwriteException} * @returns {Promise} */ - async listIndexes(collectionId) { + async listIndexes(databaseId, collectionId) { + let path = '/databases/{databaseId}/collections/{collectionId}/indexes'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/indexes'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -1068,6 +1195,7 @@ class Databases extends Service { /** * Create Index * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @param {string} type @@ -1076,7 +1204,13 @@ class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createIndex(collectionId, key, type, attributes, orders) { + async createIndex(databaseId, collectionId, key, type, attributes, orders) { + let path = '/databases/{databaseId}/collections/{collectionId}/indexes'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -1093,8 +1227,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "attributes"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/indexes'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId); - let payload = {}; if (typeof key !== 'undefined') { payload['key'] = key; @@ -1120,12 +1252,19 @@ class Databases extends Service { /** * Get Index * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @throws {AppwriteException} * @returns {Promise} */ - async getIndex(collectionId, key) { + async getIndex(databaseId, collectionId, key) { + let path = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -1134,8 +1273,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "key"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId).replace('{key}', key); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -1145,12 +1282,19 @@ class Databases extends Service { /** * Delete Index * + * @param {string} databaseId * @param {string} collectionId * @param {string} key * @throws {AppwriteException} * @returns {Promise} */ - async deleteIndex(collectionId, key) { + async deleteIndex(databaseId, collectionId, key) { + let path = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{key}', key); + let payload = {}; + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + if (typeof collectionId === 'undefined') { throw new AppwriteException('Missing required parameter: "collectionId"'); } @@ -1159,8 +1303,6 @@ class Databases extends Service { throw new AppwriteException('Missing required parameter: "key"'); } - let path = '/databases/{databaseId}/collections/{collectionId}/indexes/{key}'.replace('{databaseId}', this.databaseId).replace('{collectionId}', collectionId).replace('{key}', key); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -1168,4 +1310,4 @@ class Databases extends Service { } } -module.exports = Databases; \ No newline at end of file +module.exports = Databases; diff --git a/lib/services/functions.js b/lib/services/functions.js index 075e2de..d4970ee 100644 --- a/lib/services/functions.js +++ b/lib/services/functions.js @@ -8,47 +8,33 @@ const fs = require('fs'); class Functions extends Service { + constructor(client) + { + super(client); + } + + /** * List Functions * * Get a list of all the project's functions. You can use the query params to * filter your results. * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - async list(search, limit, offset, cursor, cursorDirection, orderType) { + async list(queries, search) { let path = '/functions'; let payload = {}; - if (typeof search !== 'undefined') { - payload['search'] = search; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - - if (typeof offset !== 'undefined') { - payload['offset'] = offset; - } - - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; - } - - if (typeof orderType !== 'undefined') { - payload['orderType'] = orderType; + if (typeof search !== 'undefined') { + payload['search'] = search; } return await this.client.call('get', path, { @@ -67,14 +53,15 @@ class Functions extends Service { * @param {string} name * @param {string[]} execute * @param {string} runtime - * @param {object} vars * @param {string[]} events * @param {string} schedule * @param {number} timeout * @throws {AppwriteException} * @returns {Promise} */ - async create(functionId, name, execute, runtime, vars, events, schedule, timeout) { + async create(functionId, name, execute, runtime, events, schedule, timeout) { + let path = '/functions'; + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -91,8 +78,6 @@ class Functions extends Service { throw new AppwriteException('Missing required parameter: "runtime"'); } - let path = '/functions'; - let payload = {}; if (typeof functionId !== 'undefined') { payload['functionId'] = functionId; @@ -110,10 +95,6 @@ class Functions extends Service { payload['runtime'] = runtime; } - if (typeof vars !== 'undefined') { - payload['vars'] = vars; - } - if (typeof events !== 'undefined') { payload['events'] = events; } @@ -158,12 +139,12 @@ class Functions extends Service { * @returns {Promise} */ async get(functionId) { + let path = '/functions/{functionId}'.replace('{functionId}', functionId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } - let path = '/functions/{functionId}'.replace('{functionId}', functionId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -178,14 +159,15 @@ class Functions extends Service { * @param {string} functionId * @param {string} name * @param {string[]} execute - * @param {object} vars * @param {string[]} events * @param {string} schedule * @param {number} timeout * @throws {AppwriteException} * @returns {Promise} */ - async update(functionId, name, execute, vars, events, schedule, timeout) { + async update(functionId, name, execute, events, schedule, timeout) { + let path = '/functions/{functionId}'.replace('{functionId}', functionId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -198,8 +180,6 @@ class Functions extends Service { throw new AppwriteException('Missing required parameter: "execute"'); } - let path = '/functions/{functionId}'.replace('{functionId}', functionId); - let payload = {}; if (typeof name !== 'undefined') { payload['name'] = name; @@ -209,10 +189,6 @@ class Functions extends Service { payload['execute'] = execute; } - if (typeof vars !== 'undefined') { - payload['vars'] = vars; - } - if (typeof events !== 'undefined') { payload['events'] = events; } @@ -240,12 +216,12 @@ class Functions extends Service { * @returns {Promise} */ async delete(functionId) { + let path = '/functions/{functionId}'.replace('{functionId}', functionId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } - let path = '/functions/{functionId}'.replace('{functionId}', functionId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -259,45 +235,25 @@ class Functions extends Service { * params to filter your results. * * @param {string} functionId + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - async listDeployments(functionId, search, limit, offset, cursor, cursorDirection, orderType) { - if (typeof functionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "functionId"'); - } - + async listDeployments(functionId, queries, search) { let path = '/functions/{functionId}/deployments'.replace('{functionId}', functionId); let payload = {}; - - if (typeof search !== 'undefined') { - payload['search'] = search; - } - - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - - if (typeof offset !== 'undefined') { - payload['offset'] = offset; + if (typeof functionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "functionId"'); } - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } - if (typeof orderType !== 'undefined') { - payload['orderType'] = orderType; + if (typeof search !== 'undefined') { + payload['search'] = search; } return await this.client.call('get', path, { @@ -327,6 +283,8 @@ class Functions extends Service { * @returns {Promise} */ async createDeployment(functionId, entrypoint, code, activate, onProgress = () => {}) { + let path = '/functions/{functionId}/deployments'.replace('{functionId}', functionId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -343,8 +301,6 @@ class Functions extends Service { throw new AppwriteException('Missing required parameter: "activate"'); } - let path = '/functions/{functionId}/deployments'.replace('{functionId}', functionId); - let payload = {}; if (typeof entrypoint !== 'undefined') { payload['entrypoint'] = entrypoint; @@ -469,6 +425,7 @@ class Functions extends Service { code.stream.pipe(writeStream); }); + } /** @@ -482,6 +439,8 @@ class Functions extends Service { * @returns {Promise} */ async getDeployment(functionId, deploymentId) { + let path = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -490,8 +449,6 @@ class Functions extends Service { throw new AppwriteException('Missing required parameter: "deploymentId"'); } - let path = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -511,6 +468,8 @@ class Functions extends Service { * @returns {Promise} */ async updateDeployment(functionId, deploymentId) { + let path = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -519,8 +478,6 @@ class Functions extends Service { throw new AppwriteException('Missing required parameter: "deploymentId"'); } - let path = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); - let payload = {}; return await this.client.call('patch', path, { 'content-type': 'application/json', @@ -538,6 +495,8 @@ class Functions extends Service { * @returns {Promise} */ async deleteDeployment(functionId, deploymentId) { + let path = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -546,8 +505,6 @@ class Functions extends Service { throw new AppwriteException('Missing required parameter: "deploymentId"'); } - let path = '/functions/{functionId}/deployments/{deploymentId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -564,6 +521,8 @@ class Functions extends Service { * @returns {Promise} */ async retryBuild(functionId, deploymentId, buildId) { + let path = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId).replace('{buildId}', buildId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -576,8 +535,6 @@ class Functions extends Service { throw new AppwriteException('Missing required parameter: "buildId"'); } - let path = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'.replace('{functionId}', functionId).replace('{deploymentId}', deploymentId).replace('{buildId}', buildId); - let payload = {}; return await this.client.call('post', path, { 'content-type': 'application/json', @@ -593,42 +550,27 @@ class Functions extends Service { * different API modes](/docs/admin). * * @param {string} functionId - * @param {number} limit - * @param {number} offset + * @param {string[]} queries * @param {string} search - * @param {string} cursor - * @param {string} cursorDirection * @throws {AppwriteException} * @returns {Promise} */ - async listExecutions(functionId, limit, offset, search, cursor, cursorDirection) { + async listExecutions(functionId, queries, search) { + let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } - let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); - let payload = {}; - - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - if (typeof offset !== 'undefined') { - payload['offset'] = offset; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } if (typeof search !== 'undefined') { payload['search'] = search; } - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; - } - return await this.client.call('get', path, { 'content-type': 'application/json', }, payload); @@ -649,12 +591,12 @@ class Functions extends Service { * @returns {Promise} */ async createExecution(functionId, data, async) { + let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } - let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); - let payload = {}; if (typeof data !== 'undefined') { payload['data'] = data; @@ -680,6 +622,8 @@ class Functions extends Service { * @returns {Promise} */ async getExecution(functionId, executionId) { + let path = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); + let payload = {}; if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -688,13 +632,179 @@ class Functions extends Service { throw new AppwriteException('Missing required parameter: "executionId"'); } - let path = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); + + return await this.client.call('get', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List Variables + * + * Get a list of all variables of a specific function. + * + * @param {string} functionId + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + async listVariables(functionId, queries, search) { + let path = '/functions/{functionId}/variables'.replace('{functionId}', functionId); let payload = {}; + if (typeof functionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "functionId"'); + } + + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + if (typeof search !== 'undefined') { + payload['search'] = search; + } + + return await this.client.call('get', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Variable + * + * Create a new function variable. These variables can be accessed within + * function in the `env` object under the request variable. + * + * @param {string} functionId + * @param {string} key + * @param {string} value + * @throws {AppwriteException} + * @returns {Promise} + */ + async createVariable(functionId, key, value) { + let path = '/functions/{functionId}/variables'.replace('{functionId}', functionId); + let payload = {}; + if (typeof functionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "functionId"'); + } + + if (typeof key === 'undefined') { + throw new AppwriteException('Missing required parameter: "key"'); + } + + if (typeof value === 'undefined') { + throw new AppwriteException('Missing required parameter: "value"'); + } + + + if (typeof key !== 'undefined') { + payload['key'] = key; + } + + if (typeof value !== 'undefined') { + payload['value'] = value; + } + + return await this.client.call('post', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Get Variable + * + * Get a variable by its unique ID. + * + * @param {string} functionId + * @param {string} variableId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getVariable(functionId, variableId) { + let path = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId); + let payload = {}; + if (typeof functionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "functionId"'); + } + + if (typeof variableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "variableId"'); + } + return await this.client.call('get', path, { 'content-type': 'application/json', }, payload); } + + /** + * Update Variable + * + * Update variable by its unique ID. + * + * @param {string} functionId + * @param {string} variableId + * @param {string} key + * @param {string} value + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateVariable(functionId, variableId, key, value) { + let path = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId); + let payload = {}; + if (typeof functionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "functionId"'); + } + + if (typeof variableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "variableId"'); + } + + if (typeof key === 'undefined') { + throw new AppwriteException('Missing required parameter: "key"'); + } + + + if (typeof key !== 'undefined') { + payload['key'] = key; + } + + if (typeof value !== 'undefined') { + payload['value'] = value; + } + + return await this.client.call('put', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Delete Variable + * + * Delete a variable by its unique ID. + * + * @param {string} functionId + * @param {string} variableId + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteVariable(functionId, variableId) { + let path = '/functions/{functionId}/variables/{variableId}'.replace('{functionId}', functionId).replace('{variableId}', variableId); + let payload = {}; + if (typeof functionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "functionId"'); + } + + if (typeof variableId === 'undefined') { + throw new AppwriteException('Missing required parameter: "variableId"'); + } + + + return await this.client.call('delete', path, { + 'content-type': 'application/json', + }, payload); + } } -module.exports = Functions; \ No newline at end of file +module.exports = Functions; diff --git a/lib/services/health.js b/lib/services/health.js index 3fbfc61..33432ab 100644 --- a/lib/services/health.js +++ b/lib/services/health.js @@ -8,6 +8,12 @@ const fs = require('fs'); class Health extends Service { + constructor(client) + { + super(client); + } + + /** * Get HTTP * @@ -188,4 +194,4 @@ class Health extends Service { } } -module.exports = Health; \ No newline at end of file +module.exports = Health; diff --git a/lib/services/locale.js b/lib/services/locale.js index 71c411c..4e445b5 100644 --- a/lib/services/locale.js +++ b/lib/services/locale.js @@ -8,6 +8,12 @@ const fs = require('fs'); class Locale extends Service { + constructor(client) + { + super(client); + } + + /** * Get User Locale * @@ -140,4 +146,4 @@ class Locale extends Service { } } -module.exports = Locale; \ No newline at end of file +module.exports = Locale; diff --git a/lib/services/storage.js b/lib/services/storage.js index c1ca385..2b5e69b 100644 --- a/lib/services/storage.js +++ b/lib/services/storage.js @@ -8,47 +8,33 @@ const fs = require('fs'); class Storage extends Service { + constructor(client) + { + super(client); + } + + /** * List buckets * * Get a list of all the storage buckets. You can use the query params to * filter your results. * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - async listBuckets(search, limit, offset, cursor, cursorDirection, orderType) { + async listBuckets(queries, search) { let path = '/storage/buckets'; let payload = {}; - if (typeof search !== 'undefined') { - payload['search'] = search; - } - - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - - if (typeof offset !== 'undefined') { - payload['offset'] = offset; - } - - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } - if (typeof orderType !== 'undefined') { - payload['orderType'] = orderType; + if (typeof search !== 'undefined') { + payload['search'] = search; } return await this.client.call('get', path, { @@ -63,18 +49,20 @@ class Storage extends Service { * * @param {string} bucketId * @param {string} name - * @param {string} permission - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions + * @param {boolean} fileSecurity * @param {boolean} enabled * @param {number} maximumFileSize * @param {string[]} allowedFileExtensions + * @param {string} compression * @param {boolean} encryption * @param {boolean} antivirus * @throws {AppwriteException} * @returns {Promise} */ - async createBucket(bucketId, name, permission, read, write, enabled, maximumFileSize, allowedFileExtensions, encryption, antivirus) { + async createBucket(bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus) { + let path = '/storage/buckets'; + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -83,12 +71,6 @@ class Storage extends Service { throw new AppwriteException('Missing required parameter: "name"'); } - if (typeof permission === 'undefined') { - throw new AppwriteException('Missing required parameter: "permission"'); - } - - let path = '/storage/buckets'; - let payload = {}; if (typeof bucketId !== 'undefined') { payload['bucketId'] = bucketId; @@ -98,16 +80,12 @@ class Storage extends Service { payload['name'] = name; } - if (typeof permission !== 'undefined') { - payload['permission'] = permission; + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; } - if (typeof read !== 'undefined') { - payload['read'] = read; - } - - if (typeof write !== 'undefined') { - payload['write'] = write; + if (typeof fileSecurity !== 'undefined') { + payload['fileSecurity'] = fileSecurity; } if (typeof enabled !== 'undefined') { @@ -122,6 +100,10 @@ class Storage extends Service { payload['allowedFileExtensions'] = allowedFileExtensions; } + if (typeof compression !== 'undefined') { + payload['compression'] = compression; + } + if (typeof encryption !== 'undefined') { payload['encryption'] = encryption; } @@ -146,12 +128,12 @@ class Storage extends Service { * @returns {Promise} */ async getBucket(bucketId) { + let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } - let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -165,18 +147,20 @@ class Storage extends Service { * * @param {string} bucketId * @param {string} name - * @param {string} permission - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions + * @param {boolean} fileSecurity * @param {boolean} enabled * @param {number} maximumFileSize * @param {string[]} allowedFileExtensions + * @param {string} compression * @param {boolean} encryption * @param {boolean} antivirus * @throws {AppwriteException} * @returns {Promise} */ - async updateBucket(bucketId, name, permission, read, write, enabled, maximumFileSize, allowedFileExtensions, encryption, antivirus) { + async updateBucket(bucketId, name, permissions, fileSecurity, enabled, maximumFileSize, allowedFileExtensions, compression, encryption, antivirus) { + let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -185,27 +169,17 @@ class Storage extends Service { throw new AppwriteException('Missing required parameter: "name"'); } - if (typeof permission === 'undefined') { - throw new AppwriteException('Missing required parameter: "permission"'); - } - - let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); - let payload = {}; if (typeof name !== 'undefined') { payload['name'] = name; } - if (typeof permission !== 'undefined') { - payload['permission'] = permission; + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; } - if (typeof read !== 'undefined') { - payload['read'] = read; - } - - if (typeof write !== 'undefined') { - payload['write'] = write; + if (typeof fileSecurity !== 'undefined') { + payload['fileSecurity'] = fileSecurity; } if (typeof enabled !== 'undefined') { @@ -220,6 +194,10 @@ class Storage extends Service { payload['allowedFileExtensions'] = allowedFileExtensions; } + if (typeof compression !== 'undefined') { + payload['compression'] = compression; + } + if (typeof encryption !== 'undefined') { payload['encryption'] = encryption; } @@ -243,12 +221,12 @@ class Storage extends Service { * @returns {Promise} */ async deleteBucket(bucketId) { + let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } - let path = '/storage/buckets/{bucketId}'.replace('{bucketId}', bucketId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -263,45 +241,25 @@ class Storage extends Service { * project's files. [Learn more about different API modes](/docs/admin). * * @param {string} bucketId + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - async listFiles(bucketId, search, limit, offset, cursor, cursorDirection, orderType) { - if (typeof bucketId === 'undefined') { - throw new AppwriteException('Missing required parameter: "bucketId"'); - } - + async listFiles(bucketId, queries, search) { let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); let payload = {}; - - if (typeof search !== 'undefined') { - payload['search'] = search; - } - - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - - if (typeof offset !== 'undefined') { - payload['offset'] = offset; + if (typeof bucketId === 'undefined') { + throw new AppwriteException('Missing required parameter: "bucketId"'); } - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } - if (typeof orderType !== 'undefined') { - payload['orderType'] = orderType; + if (typeof search !== 'undefined') { + payload['search'] = search; } return await this.client.call('get', path, { @@ -314,8 +272,8 @@ class Storage extends Service { * * Create a new file. Before using this route, you should create a new bucket * resource using either a [server - * integration](/docs/server/database#storageCreateBucket) API or directly - * from your Appwrite console. + * integration](/docs/server/storage#storageCreateBucket) API or directly from + * your Appwrite console. * * Larger files should be uploaded using multiple requests with the * [content-range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range) @@ -334,12 +292,13 @@ class Storage extends Service { * @param {string} bucketId * @param {string} fileId * @param {InputFile} file - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} */ - async createFile(bucketId, fileId, file, read, write, onProgress = () => {}) { + async createFile(bucketId, fileId, file, permissions, onProgress = () => {}) { + let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -352,8 +311,6 @@ class Storage extends Service { throw new AppwriteException('Missing required parameter: "file"'); } - let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); - let payload = {}; if (typeof fileId !== 'undefined') { payload['fileId'] = fileId; @@ -363,12 +320,8 @@ class Storage extends Service { payload['file'] = file; } - if (typeof read !== 'undefined') { - payload['read'] = read; - } - - if (typeof write !== 'undefined') { - payload['write'] = write; + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; } const size = file.size; @@ -489,6 +442,7 @@ class Storage extends Service { file.stream.pipe(writeStream); }); + } /** @@ -503,6 +457,8 @@ class Storage extends Service { * @returns {Promise} */ async getFile(bucketId, fileId) { + let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -511,8 +467,6 @@ class Storage extends Service { throw new AppwriteException('Missing required parameter: "fileId"'); } - let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -527,12 +481,13 @@ class Storage extends Service { * * @param {string} bucketId * @param {string} fileId - * @param {string[]} read - * @param {string[]} write + * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} */ - async updateFile(bucketId, fileId, read, write) { + async updateFile(bucketId, fileId, permissions) { + let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -541,15 +496,9 @@ class Storage extends Service { throw new AppwriteException('Missing required parameter: "fileId"'); } - let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload = {}; - - if (typeof read !== 'undefined') { - payload['read'] = read; - } - if (typeof write !== 'undefined') { - payload['write'] = write; + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; } return await this.client.call('put', path, { @@ -569,6 +518,8 @@ class Storage extends Service { * @returns {Promise} */ async deleteFile(bucketId, fileId) { + let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -577,8 +528,6 @@ class Storage extends Service { throw new AppwriteException('Missing required parameter: "fileId"'); } - let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -598,6 +547,8 @@ class Storage extends Service { * @returns {Promise} */ async getFileDownload(bucketId, fileId) { + let path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -606,8 +557,6 @@ class Storage extends Service { throw new AppwriteException('Missing required parameter: "fileId"'); } - let path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -640,6 +589,8 @@ class Storage extends Service { * @returns {Promise} */ async getFilePreview(bucketId, fileId, width, height, gravity, quality, borderWidth, borderColor, borderRadius, opacity, rotation, background, output) { + let path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -648,8 +599,6 @@ class Storage extends Service { throw new AppwriteException('Missing required parameter: "fileId"'); } - let path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload = {}; if (typeof width !== 'undefined') { payload['width'] = width; @@ -713,6 +662,8 @@ class Storage extends Service { * @returns {Promise} */ async getFileView(bucketId, fileId) { + let path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload = {}; if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -721,8 +672,6 @@ class Storage extends Service { throw new AppwriteException('Missing required parameter: "fileId"'); } - let path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -730,4 +679,4 @@ class Storage extends Service { } } -module.exports = Storage; \ No newline at end of file +module.exports = Storage; diff --git a/lib/services/teams.js b/lib/services/teams.js index 1fe3564..c2db8dc 100644 --- a/lib/services/teams.js +++ b/lib/services/teams.js @@ -8,6 +8,12 @@ const fs = require('fs'); class Teams extends Service { + constructor(client) + { + super(client); + } + + /** * List Teams * @@ -17,41 +23,21 @@ class Teams extends Service { * In admin mode, this endpoint returns a list of all the teams in the current * project. [Learn more about different API modes](/docs/admin). * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - async list(search, limit, offset, cursor, cursorDirection, orderType) { + async list(queries, search) { let path = '/teams'; let payload = {}; - if (typeof search !== 'undefined') { - payload['search'] = search; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - - if (typeof offset !== 'undefined') { - payload['offset'] = offset; - } - - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; - } - - if (typeof orderType !== 'undefined') { - payload['orderType'] = orderType; + if (typeof search !== 'undefined') { + payload['search'] = search; } return await this.client.call('get', path, { @@ -73,6 +59,8 @@ class Teams extends Service { * @returns {Promise} */ async create(teamId, name, roles) { + let path = '/teams'; + let payload = {}; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -81,8 +69,6 @@ class Teams extends Service { throw new AppwriteException('Missing required parameter: "name"'); } - let path = '/teams'; - let payload = {}; if (typeof teamId !== 'undefined') { payload['teamId'] = teamId; @@ -111,12 +97,12 @@ class Teams extends Service { * @returns {Promise} */ async get(teamId) { + let path = '/teams/{teamId}'.replace('{teamId}', teamId); + let payload = {}; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } - let path = '/teams/{teamId}'.replace('{teamId}', teamId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -135,6 +121,8 @@ class Teams extends Service { * @returns {Promise} */ async update(teamId, name) { + let path = '/teams/{teamId}'.replace('{teamId}', teamId); + let payload = {}; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -143,8 +131,6 @@ class Teams extends Service { throw new AppwriteException('Missing required parameter: "name"'); } - let path = '/teams/{teamId}'.replace('{teamId}', teamId); - let payload = {}; if (typeof name !== 'undefined') { payload['name'] = name; @@ -166,12 +152,12 @@ class Teams extends Service { * @returns {Promise} */ async delete(teamId) { + let path = '/teams/{teamId}'.replace('{teamId}', teamId); + let payload = {}; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } - let path = '/teams/{teamId}'.replace('{teamId}', teamId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -185,45 +171,25 @@ class Teams extends Service { * members have read access to this endpoint. * * @param {string} teamId + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - async getMemberships(teamId, search, limit, offset, cursor, cursorDirection, orderType) { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - + async getMemberships(teamId, queries, search) { let path = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); let payload = {}; - - if (typeof search !== 'undefined') { - payload['search'] = search; - } - - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - - if (typeof offset !== 'undefined') { - payload['offset'] = offset; + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); } - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; - } - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } - if (typeof orderType !== 'undefined') { - payload['orderType'] = orderType; + if (typeof search !== 'undefined') { + payload['search'] = search; } return await this.client.call('get', path, { @@ -259,6 +225,8 @@ class Teams extends Service { * @returns {Promise} */ async createMembership(teamId, email, roles, url, name) { + let path = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); + let payload = {}; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -275,8 +243,6 @@ class Teams extends Service { throw new AppwriteException('Missing required parameter: "url"'); } - let path = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); - let payload = {}; if (typeof email !== 'undefined') { payload['email'] = email; @@ -311,6 +277,8 @@ class Teams extends Service { * @returns {Promise} */ async getMembership(teamId, membershipId) { + let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + let payload = {}; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -319,8 +287,6 @@ class Teams extends Service { throw new AppwriteException('Missing required parameter: "membershipId"'); } - let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -341,6 +307,8 @@ class Teams extends Service { * @returns {Promise} */ async updateMembershipRoles(teamId, membershipId, roles) { + let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + let payload = {}; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -353,8 +321,6 @@ class Teams extends Service { throw new AppwriteException('Missing required parameter: "roles"'); } - let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - let payload = {}; if (typeof roles !== 'undefined') { payload['roles'] = roles; @@ -378,6 +344,8 @@ class Teams extends Service { * @returns {Promise} */ async deleteMembership(teamId, membershipId) { + let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + let payload = {}; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -386,8 +354,6 @@ class Teams extends Service { throw new AppwriteException('Missing required parameter: "membershipId"'); } - let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -413,6 +379,8 @@ class Teams extends Service { * @returns {Promise} */ async updateMembershipStatus(teamId, membershipId, userId, secret) { + let path = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + let payload = {}; if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -429,8 +397,6 @@ class Teams extends Service { throw new AppwriteException('Missing required parameter: "secret"'); } - let path = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - let payload = {}; if (typeof userId !== 'undefined') { payload['userId'] = userId; @@ -446,4 +412,4 @@ class Teams extends Service { } } -module.exports = Teams; \ No newline at end of file +module.exports = Teams; diff --git a/lib/services/users.js b/lib/services/users.js index 4c99022..57d479b 100644 --- a/lib/services/users.js +++ b/lib/services/users.js @@ -8,58 +8,93 @@ const fs = require('fs'); class Users extends Service { + constructor(client) + { + super(client); + } + + /** * List Users * * Get a list of all the project's users. You can use the query params to * filter your results. * + * @param {string[]} queries * @param {string} search - * @param {number} limit - * @param {number} offset - * @param {string} cursor - * @param {string} cursorDirection - * @param {string} orderType * @throws {AppwriteException} * @returns {Promise} */ - async list(search, limit, offset, cursor, cursorDirection, orderType) { + async list(queries, search) { let path = '/users'; let payload = {}; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + if (typeof search !== 'undefined') { payload['search'] = search; } - if (typeof limit !== 'undefined') { - payload['limit'] = limit; + return await this.client.call('get', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create User + * + * Create a new user. + * + * @param {string} userId + * @param {string} email + * @param {string} phone + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async create(userId, email, phone, password, name) { + let path = '/users'; + let payload = {}; + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; } - if (typeof offset !== 'undefined') { - payload['offset'] = offset; + if (typeof email !== 'undefined') { + payload['email'] = email; } - if (typeof cursor !== 'undefined') { - payload['cursor'] = cursor; + if (typeof phone !== 'undefined') { + payload['phone'] = phone; } - if (typeof cursorDirection !== 'undefined') { - payload['cursorDirection'] = cursorDirection; + if (typeof password !== 'undefined') { + payload['password'] = password; } - if (typeof orderType !== 'undefined') { - payload['orderType'] = orderType; + if (typeof name !== 'undefined') { + payload['name'] = name; } - return await this.client.call('get', path, { + return await this.client.call('post', path, { 'content-type': 'application/json', }, payload); } /** - * Create User + * Create User with Argon2 Password * - * Create a new user. + * Create a new user. Password provided must be hashed with the + * [Argon2](https://en.wikipedia.org/wiki/Argon2) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. * * @param {string} userId * @param {string} email @@ -68,7 +103,9 @@ class Users extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async create(userId, email, password, name) { + async createArgon2User(userId, email, password, name) { + let path = '/users/argon2'; + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -81,8 +118,110 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "password"'); } - let path = '/users'; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + return await this.client.call('post', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create User with Bcrypt Password + * + * Create a new user. Password provided must be hashed with the + * [Bcrypt](https://en.wikipedia.org/wiki/Bcrypt) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async createBcryptUser(userId, email, password, name) { + let path = '/users/bcrypt'; + let payload = {}; + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + return await this.client.call('post', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create User with MD5 Password + * + * Create a new user. Password provided must be hashed with the + * [MD5](https://en.wikipedia.org/wiki/MD5) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMD5User(userId, email, password, name) { + let path = '/users/md5'; let payload = {}; + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + if (typeof userId !== 'undefined') { payload['userId'] = userId; @@ -105,6 +244,291 @@ class Users extends Service { }, payload); } + /** + * Create User with PHPass Password + * + * Create a new user. Password provided must be hashed with the + * [PHPass](https://www.openwall.com/phpass/) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async createPHPassUser(userId, email, password, name) { + let path = '/users/phpass'; + let payload = {}; + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + return await this.client.call('post', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create User with Scrypt Password + * + * Create a new user. Password provided must be hashed with the + * [Scrypt](https://github.com/Tarsnap/scrypt) algorithm. Use the [POST + * /users](/docs/server/users#usersCreate) endpoint to create users with a + * plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} passwordSalt + * @param {number} passwordCpu + * @param {number} passwordMemory + * @param {number} passwordParallel + * @param {number} passwordLength + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async createScryptUser(userId, email, password, passwordSalt, passwordCpu, passwordMemory, passwordParallel, passwordLength, name) { + let path = '/users/scrypt'; + let payload = {}; + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + if (typeof passwordSalt === 'undefined') { + throw new AppwriteException('Missing required parameter: "passwordSalt"'); + } + + if (typeof passwordCpu === 'undefined') { + throw new AppwriteException('Missing required parameter: "passwordCpu"'); + } + + if (typeof passwordMemory === 'undefined') { + throw new AppwriteException('Missing required parameter: "passwordMemory"'); + } + + if (typeof passwordParallel === 'undefined') { + throw new AppwriteException('Missing required parameter: "passwordParallel"'); + } + + if (typeof passwordLength === 'undefined') { + throw new AppwriteException('Missing required parameter: "passwordLength"'); + } + + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + if (typeof passwordSalt !== 'undefined') { + payload['passwordSalt'] = passwordSalt; + } + + if (typeof passwordCpu !== 'undefined') { + payload['passwordCpu'] = passwordCpu; + } + + if (typeof passwordMemory !== 'undefined') { + payload['passwordMemory'] = passwordMemory; + } + + if (typeof passwordParallel !== 'undefined') { + payload['passwordParallel'] = passwordParallel; + } + + if (typeof passwordLength !== 'undefined') { + payload['passwordLength'] = passwordLength; + } + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + return await this.client.call('post', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create User with Scrypt Modified Password + * + * Create a new user. Password provided must be hashed with the [Scrypt + * Modified](https://gist.github.com/Meldiron/eecf84a0225eccb5a378d45bb27462cc) + * algorithm. Use the [POST /users](/docs/server/users#usersCreate) endpoint + * to create users with a plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} passwordSalt + * @param {string} passwordSaltSeparator + * @param {string} passwordSignerKey + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async createScryptModifiedUser(userId, email, password, passwordSalt, passwordSaltSeparator, passwordSignerKey, name) { + let path = '/users/scrypt-modified'; + let payload = {}; + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + if (typeof passwordSalt === 'undefined') { + throw new AppwriteException('Missing required parameter: "passwordSalt"'); + } + + if (typeof passwordSaltSeparator === 'undefined') { + throw new AppwriteException('Missing required parameter: "passwordSaltSeparator"'); + } + + if (typeof passwordSignerKey === 'undefined') { + throw new AppwriteException('Missing required parameter: "passwordSignerKey"'); + } + + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + if (typeof passwordSalt !== 'undefined') { + payload['passwordSalt'] = passwordSalt; + } + + if (typeof passwordSaltSeparator !== 'undefined') { + payload['passwordSaltSeparator'] = passwordSaltSeparator; + } + + if (typeof passwordSignerKey !== 'undefined') { + payload['passwordSignerKey'] = passwordSignerKey; + } + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + return await this.client.call('post', path, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create User with SHA Password + * + * Create a new user. Password provided must be hashed with the + * [SHA](https://en.wikipedia.org/wiki/Secure_Hash_Algorithm) algorithm. Use + * the [POST /users](/docs/server/users#usersCreate) endpoint to create users + * with a plain text password. + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} passwordVersion + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async createSHAUser(userId, email, password, passwordVersion, name) { + let path = '/users/sha'; + let payload = {}; + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + if (typeof passwordVersion !== 'undefined') { + payload['passwordVersion'] = passwordVersion; + } + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + return await this.client.call('post', path, { + 'content-type': 'application/json', + }, payload); + } + /** * Get User * @@ -115,12 +539,12 @@ class Users extends Service { * @returns {Promise} */ async get(userId) { + let path = '/users/{userId}'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } - let path = '/users/{userId}'.replace('{userId}', userId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -141,12 +565,12 @@ class Users extends Service { * @returns {Promise} */ async delete(userId) { + let path = '/users/{userId}'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } - let path = '/users/{userId}'.replace('{userId}', userId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -164,6 +588,8 @@ class Users extends Service { * @returns {Promise} */ async updateEmail(userId, email) { + let path = '/users/{userId}/email'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -172,8 +598,6 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "email"'); } - let path = '/users/{userId}/email'.replace('{userId}', userId); - let payload = {}; if (typeof email !== 'undefined') { payload['email'] = email; @@ -190,25 +614,20 @@ class Users extends Service { * Get the user activity logs list by its unique ID. * * @param {string} userId - * @param {number} limit - * @param {number} offset + * @param {string[]} queries * @throws {AppwriteException} * @returns {Promise} */ - async getLogs(userId, limit, offset) { + async getLogs(userId, queries) { + let path = '/users/{userId}/logs'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } - let path = '/users/{userId}/logs'.replace('{userId}', userId); - let payload = {}; - - if (typeof limit !== 'undefined') { - payload['limit'] = limit; - } - if (typeof offset !== 'undefined') { - payload['offset'] = offset; + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } return await this.client.call('get', path, { @@ -226,12 +645,12 @@ class Users extends Service { * @returns {Promise} */ async getMemberships(userId) { + let path = '/users/{userId}/memberships'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } - let path = '/users/{userId}/memberships'.replace('{userId}', userId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -249,6 +668,8 @@ class Users extends Service { * @returns {Promise} */ async updateName(userId, name) { + let path = '/users/{userId}/name'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -257,8 +678,6 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "name"'); } - let path = '/users/{userId}/name'.replace('{userId}', userId); - let payload = {}; if (typeof name !== 'undefined') { payload['name'] = name; @@ -280,6 +699,8 @@ class Users extends Service { * @returns {Promise} */ async updatePassword(userId, password) { + let path = '/users/{userId}/password'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -288,8 +709,6 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "password"'); } - let path = '/users/{userId}/password'.replace('{userId}', userId); - let payload = {}; if (typeof password !== 'undefined') { payload['password'] = password; @@ -311,6 +730,8 @@ class Users extends Service { * @returns {Promise} */ async updatePhone(userId, number) { + let path = '/users/{userId}/phone'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -319,8 +740,6 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "number"'); } - let path = '/users/{userId}/phone'.replace('{userId}', userId); - let payload = {}; if (typeof number !== 'undefined') { payload['number'] = number; @@ -341,12 +760,12 @@ class Users extends Service { * @returns {Promise} */ async getPrefs(userId) { + let path = '/users/{userId}/prefs'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } - let path = '/users/{userId}/prefs'.replace('{userId}', userId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -366,6 +785,8 @@ class Users extends Service { * @returns {Promise} */ async updatePrefs(userId, prefs) { + let path = '/users/{userId}/prefs'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -374,8 +795,6 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "prefs"'); } - let path = '/users/{userId}/prefs'.replace('{userId}', userId); - let payload = {}; if (typeof prefs !== 'undefined') { payload['prefs'] = prefs; @@ -396,12 +815,12 @@ class Users extends Service { * @returns {Promise} */ async getSessions(userId) { + let path = '/users/{userId}/sessions'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } - let path = '/users/{userId}/sessions'.replace('{userId}', userId); - let payload = {}; return await this.client.call('get', path, { 'content-type': 'application/json', @@ -418,12 +837,12 @@ class Users extends Service { * @returns {Promise} */ async deleteSessions(userId) { + let path = '/users/{userId}/sessions'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } - let path = '/users/{userId}/sessions'.replace('{userId}', userId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -441,6 +860,8 @@ class Users extends Service { * @returns {Promise} */ async deleteSession(userId, sessionId) { + let path = '/users/{userId}/sessions/{sessionId}'.replace('{userId}', userId).replace('{sessionId}', sessionId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -449,8 +870,6 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "sessionId"'); } - let path = '/users/{userId}/sessions/{sessionId}'.replace('{userId}', userId).replace('{sessionId}', sessionId); - let payload = {}; return await this.client.call('delete', path, { 'content-type': 'application/json', @@ -469,6 +888,8 @@ class Users extends Service { * @returns {Promise} */ async updateStatus(userId, status) { + let path = '/users/{userId}/status'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -477,8 +898,6 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "status"'); } - let path = '/users/{userId}/status'.replace('{userId}', userId); - let payload = {}; if (typeof status !== 'undefined') { payload['status'] = status; @@ -500,6 +919,8 @@ class Users extends Service { * @returns {Promise} */ async updateEmailVerification(userId, emailVerification) { + let path = '/users/{userId}/verification'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -508,8 +929,6 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "emailVerification"'); } - let path = '/users/{userId}/verification'.replace('{userId}', userId); - let payload = {}; if (typeof emailVerification !== 'undefined') { payload['emailVerification'] = emailVerification; @@ -531,6 +950,8 @@ class Users extends Service { * @returns {Promise} */ async updatePhoneVerification(userId, phoneVerification) { + let path = '/users/{userId}/verification/phone'.replace('{userId}', userId); + let payload = {}; if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -539,8 +960,6 @@ class Users extends Service { throw new AppwriteException('Missing required parameter: "phoneVerification"'); } - let path = '/users/{userId}/verification/phone'.replace('{userId}', userId); - let payload = {}; if (typeof phoneVerification !== 'undefined') { payload['phoneVerification'] = phoneVerification; @@ -552,4 +971,4 @@ class Users extends Service { } } -module.exports = Users; \ No newline at end of file +module.exports = Users; diff --git a/package.json b/package.json index 280b457..04c42a8 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "node-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "7.0.2", + "version": "8.0.0-RC1", "license": "BSD-3-Clause", "main": "./index.js", "types": "./index.d.ts",