diff --git a/README.md b/README.md index 4a4231e..3845c5f 100644 --- a/README.md +++ b/README.md @@ -96,10 +96,10 @@ account.create(ID.unique(), 'me@example.com', 'password', 'Jane Doe') ### Learn more You can use the following resources to learn more and get help -- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-flutter) +- 🚀 [Getting Started Tutorial](https://appwrite.io/docs/getting-started-for-web) - 📜 [Appwrite Docs](https://appwrite.io/docs) - 💬 [Discord Community](https://appwrite.io/discord) -- 🚂 [Appwrite Flutter Playground](https://github.com/appwrite/playground-for-flutter) +- 🚂 [Appwrite Web Playground](https://github.com/appwrite/playground-for-web) ## Contribution diff --git a/docs/examples/account/create-anonymous-session.md b/docs/examples/account/create-anonymous-session.md index a1ff484..c331fc8 100644 --- a/docs/examples/account/create-anonymous-session.md +++ b/docs/examples/account/create-anonymous-session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/create-email-session.md b/docs/examples/account/create-email-session.md index 43a0aa2..76e2e31 100644 --- a/docs/examples/account/create-email-session.md +++ b/docs/examples/account/create-email-session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/create-j-w-t.md b/docs/examples/account/create-j-w-t.md index 3b5c7ed..f388a3d 100644 --- a/docs/examples/account/create-j-w-t.md +++ b/docs/examples/account/create-j-w-t.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/create-magic-u-r-l-session.md b/docs/examples/account/create-magic-u-r-l-session.md index 9339d67..d48f031 100644 --- a/docs/examples/account/create-magic-u-r-l-session.md +++ b/docs/examples/account/create-magic-u-r-l-session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/create-o-auth2session.md b/docs/examples/account/create-o-auth2session.md index 25e67b1..3757a1c 100644 --- a/docs/examples/account/create-o-auth2session.md +++ b/docs/examples/account/create-o-auth2session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/create-phone-session.md b/docs/examples/account/create-phone-session.md index df2efe0..e5a23aa 100644 --- a/docs/examples/account/create-phone-session.md +++ b/docs/examples/account/create-phone-session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/create-phone-verification.md b/docs/examples/account/create-phone-verification.md index f325a92..a1cbd55 100644 --- a/docs/examples/account/create-phone-verification.md +++ b/docs/examples/account/create-phone-verification.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/create-recovery.md b/docs/examples/account/create-recovery.md index 4f737ed..1838c04 100644 --- a/docs/examples/account/create-recovery.md +++ b/docs/examples/account/create-recovery.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/create-verification.md b/docs/examples/account/create-verification.md index 0e7162c..4d8446e 100644 --- a/docs/examples/account/create-verification.md +++ b/docs/examples/account/create-verification.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md index 1f993d8..fda1d88 100644 --- a/docs/examples/account/create.md +++ b/docs/examples/account/create.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/delete-session.md b/docs/examples/account/delete-session.md index a23a1f2..c342afb 100644 --- a/docs/examples/account/delete-session.md +++ b/docs/examples/account/delete-session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/delete-sessions.md b/docs/examples/account/delete-sessions.md index 5849538..82133e3 100644 --- a/docs/examples/account/delete-sessions.md +++ b/docs/examples/account/delete-sessions.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/get-prefs.md b/docs/examples/account/get-prefs.md index a355c68..b98776f 100644 --- a/docs/examples/account/get-prefs.md +++ b/docs/examples/account/get-prefs.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/get-session.md b/docs/examples/account/get-session.md index dd0c086..43edd7d 100644 --- a/docs/examples/account/get-session.md +++ b/docs/examples/account/get-session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/get.md b/docs/examples/account/get.md index fd26ad7..878227f 100644 --- a/docs/examples/account/get.md +++ b/docs/examples/account/get.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md index 4ce60e4..d710f7d 100644 --- a/docs/examples/account/list-logs.md +++ b/docs/examples/account/list-logs.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/list-sessions.md b/docs/examples/account/list-sessions.md index d7e901c..ce6ec74 100644 --- a/docs/examples/account/list-sessions.md +++ b/docs/examples/account/list-sessions.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-email.md b/docs/examples/account/update-email.md index 6e3d603..baac3a0 100644 --- a/docs/examples/account/update-email.md +++ b/docs/examples/account/update-email.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-magic-u-r-l-session.md b/docs/examples/account/update-magic-u-r-l-session.md index 1934263..c07fee2 100644 --- a/docs/examples/account/update-magic-u-r-l-session.md +++ b/docs/examples/account/update-magic-u-r-l-session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-name.md b/docs/examples/account/update-name.md index 24a27f1..4af963d 100644 --- a/docs/examples/account/update-name.md +++ b/docs/examples/account/update-name.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md index 6f59478..2404a74 100644 --- a/docs/examples/account/update-password.md +++ b/docs/examples/account/update-password.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-phone-session.md b/docs/examples/account/update-phone-session.md index 8ad2051..b3b2948 100644 --- a/docs/examples/account/update-phone-session.md +++ b/docs/examples/account/update-phone-session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-phone-verification.md b/docs/examples/account/update-phone-verification.md index b96f3be..a274c9b 100644 --- a/docs/examples/account/update-phone-verification.md +++ b/docs/examples/account/update-phone-verification.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-phone.md b/docs/examples/account/update-phone.md index 33dac51..a1017fc 100644 --- a/docs/examples/account/update-phone.md +++ b/docs/examples/account/update-phone.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md index 4948631..ecceff3 100644 --- a/docs/examples/account/update-prefs.md +++ b/docs/examples/account/update-prefs.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md index 85915f1..eb78a8a 100644 --- a/docs/examples/account/update-recovery.md +++ b/docs/examples/account/update-recovery.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-session.md b/docs/examples/account/update-session.md index 70fe5fa..a7a42c6 100644 --- a/docs/examples/account/update-session.md +++ b/docs/examples/account/update-session.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-status.md b/docs/examples/account/update-status.md index a7c7817..9cbe78c 100644 --- a/docs/examples/account/update-status.md +++ b/docs/examples/account/update-status.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/account/update-verification.md b/docs/examples/account/update-verification.md index 27d5cbc..73338da 100644 --- a/docs/examples/account/update-verification.md +++ b/docs/examples/account/update-verification.md @@ -5,7 +5,7 @@ const client = new Client(); const account = new Account(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/avatars/get-browser.md b/docs/examples/avatars/get-browser.md index 20480ce..0b4c2de 100644 --- a/docs/examples/avatars/get-browser.md +++ b/docs/examples/avatars/get-browser.md @@ -5,7 +5,7 @@ const client = new Client(); const avatars = new Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/avatars/get-credit-card.md b/docs/examples/avatars/get-credit-card.md index cdbc4a0..082ed92 100644 --- a/docs/examples/avatars/get-credit-card.md +++ b/docs/examples/avatars/get-credit-card.md @@ -5,7 +5,7 @@ const client = new Client(); const avatars = new Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/avatars/get-favicon.md b/docs/examples/avatars/get-favicon.md index f8db5c3..7ee6bd3 100644 --- a/docs/examples/avatars/get-favicon.md +++ b/docs/examples/avatars/get-favicon.md @@ -5,7 +5,7 @@ const client = new Client(); const avatars = new Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/avatars/get-flag.md b/docs/examples/avatars/get-flag.md index e609fb2..a43827a 100644 --- a/docs/examples/avatars/get-flag.md +++ b/docs/examples/avatars/get-flag.md @@ -5,7 +5,7 @@ const client = new Client(); const avatars = new Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/avatars/get-image.md b/docs/examples/avatars/get-image.md index 468f6a3..ea186a1 100644 --- a/docs/examples/avatars/get-image.md +++ b/docs/examples/avatars/get-image.md @@ -5,7 +5,7 @@ const client = new Client(); const avatars = new Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/avatars/get-initials.md b/docs/examples/avatars/get-initials.md index d061813..7e8c8ec 100644 --- a/docs/examples/avatars/get-initials.md +++ b/docs/examples/avatars/get-initials.md @@ -5,7 +5,7 @@ const client = new Client(); const avatars = new Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/avatars/get-q-r.md b/docs/examples/avatars/get-q-r.md index 86fed12..b957084 100644 --- a/docs/examples/avatars/get-q-r.md +++ b/docs/examples/avatars/get-q-r.md @@ -5,7 +5,7 @@ const client = new Client(); const avatars = new Avatars(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index 5b8d89a..9279206 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -5,7 +5,7 @@ const client = new Client(); const databases = new Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/databases/delete-document.md b/docs/examples/databases/delete-document.md index e201280..9e281e7 100644 --- a/docs/examples/databases/delete-document.md +++ b/docs/examples/databases/delete-document.md @@ -5,7 +5,7 @@ const client = new Client(); const databases = new Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md index 89314e8..ea80328 100644 --- a/docs/examples/databases/get-document.md +++ b/docs/examples/databases/get-document.md @@ -5,7 +5,7 @@ const client = new Client(); const databases = new Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index a4afd21..4a94c99 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -5,7 +5,7 @@ const client = new Client(); const databases = new Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index 2d59a8a..cc5ef1c 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -5,7 +5,7 @@ const client = new Client(); const databases = new Databases(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index 2b64bc9..4fc7ac7 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -5,7 +5,7 @@ const client = new Client(); const functions = new Functions(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/functions/get-execution.md b/docs/examples/functions/get-execution.md index f5046a0..2473572 100644 --- a/docs/examples/functions/get-execution.md +++ b/docs/examples/functions/get-execution.md @@ -5,7 +5,7 @@ const client = new Client(); const functions = new Functions(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md index 99186a9..481986e 100644 --- a/docs/examples/functions/list-executions.md +++ b/docs/examples/functions/list-executions.md @@ -5,7 +5,7 @@ const client = new Client(); const functions = new Functions(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/graphql/mutation.md b/docs/examples/graphql/mutation.md index 331e828..1a0b61c 100644 --- a/docs/examples/graphql/mutation.md +++ b/docs/examples/graphql/mutation.md @@ -5,7 +5,7 @@ const client = new Client(); const graphql = new Graphql(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/graphql/query.md b/docs/examples/graphql/query.md index b56829c..e507fbb 100644 --- a/docs/examples/graphql/query.md +++ b/docs/examples/graphql/query.md @@ -5,7 +5,7 @@ const client = new Client(); const graphql = new Graphql(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/locale/get.md b/docs/examples/locale/get.md index 634256c..e15bad2 100644 --- a/docs/examples/locale/get.md +++ b/docs/examples/locale/get.md @@ -5,7 +5,7 @@ const client = new Client(); const locale = new Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/locale/list-continents.md b/docs/examples/locale/list-continents.md index e79a8ea..aa3716e 100644 --- a/docs/examples/locale/list-continents.md +++ b/docs/examples/locale/list-continents.md @@ -5,7 +5,7 @@ const client = new Client(); const locale = new Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/locale/list-countries-e-u.md b/docs/examples/locale/list-countries-e-u.md index 964bed3..c924b8d 100644 --- a/docs/examples/locale/list-countries-e-u.md +++ b/docs/examples/locale/list-countries-e-u.md @@ -5,7 +5,7 @@ const client = new Client(); const locale = new Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/locale/list-countries-phones.md b/docs/examples/locale/list-countries-phones.md index 65ec4f4..0ab6076 100644 --- a/docs/examples/locale/list-countries-phones.md +++ b/docs/examples/locale/list-countries-phones.md @@ -5,7 +5,7 @@ const client = new Client(); const locale = new Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/locale/list-countries.md b/docs/examples/locale/list-countries.md index 6b7e8e6..ee8c454 100644 --- a/docs/examples/locale/list-countries.md +++ b/docs/examples/locale/list-countries.md @@ -5,7 +5,7 @@ const client = new Client(); const locale = new Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/locale/list-currencies.md b/docs/examples/locale/list-currencies.md index 3638c2e..dd37b14 100644 --- a/docs/examples/locale/list-currencies.md +++ b/docs/examples/locale/list-currencies.md @@ -5,7 +5,7 @@ const client = new Client(); const locale = new Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/locale/list-languages.md b/docs/examples/locale/list-languages.md index bffa5eb..89ae06d 100644 --- a/docs/examples/locale/list-languages.md +++ b/docs/examples/locale/list-languages.md @@ -5,7 +5,7 @@ const client = new Client(); const locale = new Locale(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index 10992d2..0cddb08 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -5,7 +5,7 @@ const client = new Client(); const storage = new Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/storage/delete-file.md b/docs/examples/storage/delete-file.md index 4512a8c..257d855 100644 --- a/docs/examples/storage/delete-file.md +++ b/docs/examples/storage/delete-file.md @@ -5,7 +5,7 @@ const client = new Client(); const storage = new Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/storage/get-file-download.md b/docs/examples/storage/get-file-download.md index 17c0660..d8a3542 100644 --- a/docs/examples/storage/get-file-download.md +++ b/docs/examples/storage/get-file-download.md @@ -5,7 +5,7 @@ const client = new Client(); const storage = new Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/storage/get-file-preview.md b/docs/examples/storage/get-file-preview.md index 52866d1..f0588ba 100644 --- a/docs/examples/storage/get-file-preview.md +++ b/docs/examples/storage/get-file-preview.md @@ -5,7 +5,7 @@ const client = new Client(); const storage = new Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/storage/get-file-view.md b/docs/examples/storage/get-file-view.md index 7bb6c67..5eb2855 100644 --- a/docs/examples/storage/get-file-view.md +++ b/docs/examples/storage/get-file-view.md @@ -5,7 +5,7 @@ const client = new Client(); const storage = new Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/storage/get-file.md b/docs/examples/storage/get-file.md index 3263865..6b39ee3 100644 --- a/docs/examples/storage/get-file.md +++ b/docs/examples/storage/get-file.md @@ -5,7 +5,7 @@ const client = new Client(); const storage = new Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md index 92d7574..696d401 100644 --- a/docs/examples/storage/list-files.md +++ b/docs/examples/storage/list-files.md @@ -5,7 +5,7 @@ const client = new Client(); const storage = new Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md index 1313e30..d22a2f6 100644 --- a/docs/examples/storage/update-file.md +++ b/docs/examples/storage/update-file.md @@ -5,7 +5,7 @@ const client = new Client(); const storage = new Storage(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index 3f4eb7a..fded560 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/create.md b/docs/examples/teams/create.md index 2c40c90..c9037e9 100644 --- a/docs/examples/teams/create.md +++ b/docs/examples/teams/create.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/delete-membership.md b/docs/examples/teams/delete-membership.md index 828674a..c42d669 100644 --- a/docs/examples/teams/delete-membership.md +++ b/docs/examples/teams/delete-membership.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/delete.md b/docs/examples/teams/delete.md index b9b79ed..0c99b7a 100644 --- a/docs/examples/teams/delete.md +++ b/docs/examples/teams/delete.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/get-membership.md b/docs/examples/teams/get-membership.md index cce63e7..d4d3c5a 100644 --- a/docs/examples/teams/get-membership.md +++ b/docs/examples/teams/get-membership.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/get-prefs.md b/docs/examples/teams/get-prefs.md index 50be11b..bcf3f43 100644 --- a/docs/examples/teams/get-prefs.md +++ b/docs/examples/teams/get-prefs.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/get.md b/docs/examples/teams/get.md index 3a71853..396916e 100644 --- a/docs/examples/teams/get.md +++ b/docs/examples/teams/get.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md index 12bef1a..dfa0163 100644 --- a/docs/examples/teams/list-memberships.md +++ b/docs/examples/teams/list-memberships.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md index 1aea267..daf799b 100644 --- a/docs/examples/teams/list.md +++ b/docs/examples/teams/list.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/update-membership-roles.md b/docs/examples/teams/update-membership-roles.md index ca76ead..55b2267 100644 --- a/docs/examples/teams/update-membership-roles.md +++ b/docs/examples/teams/update-membership-roles.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/update-membership-status.md b/docs/examples/teams/update-membership-status.md index 4a29cdc..de1b7f8 100644 --- a/docs/examples/teams/update-membership-status.md +++ b/docs/examples/teams/update-membership-status.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/update-name.md b/docs/examples/teams/update-name.md index 8ae1a52..3159d51 100644 --- a/docs/examples/teams/update-name.md +++ b/docs/examples/teams/update-name.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/docs/examples/teams/update-prefs.md b/docs/examples/teams/update-prefs.md index bb89c9e..36f60b1 100644 --- a/docs/examples/teams/update-prefs.md +++ b/docs/examples/teams/update-prefs.md @@ -5,7 +5,7 @@ const client = new Client(); const teams = new Teams(client); client - .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint + .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject('5df5acd0d48c2') // Your project ID ; diff --git a/package.json b/package.json index c1f506b..c0bd5be 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "exports": { ".": { "import": "./dist/esm/sdk.js", - "require": "./dist/cjs/sdk.js" + "require": "./dist/cjs/sdk.js", + "types": "./types/index.d.ts" }, "./package.json": "./package.json" }, diff --git a/src/services/account.ts b/src/services/account.ts index 927e40d..f73de07 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -10,1000 +10,1000 @@ export class Account extends Service { super(client); } - /** - * Get Account - * - * Get currently logged in user data as JSON object. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async get(): Promise> { - let path = '/account'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Account - * - * Use this endpoint to allow a new user to register a new account in your - * project. After the user registration completes successfully, you can use - * the [/account/verfication](/docs/client/account#accountCreateVerification) - * route to start verifying the user email address. To allow the new user to - * login to their new account, you need to create a new [account - * session](/docs/client/account#accountCreateSession). - * - * @param {string} userId - * @param {string} email - * @param {string} password - * @param {string} name - * @throws {AppwriteException} - * @returns {Promise} - */ - async create(userId: string, email: string, password: string, name?: string): Promise> { - 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"'); - } - - let path = '/account'; - let payload: Payload = {}; - - 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; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Email - * - * Update currently logged in user account email address. After changing user - * address, the user confirmation status will get reset. A new confirmation - * email is not sent automatically however you can use the send confirmation - * email endpoint again to send the confirmation email. For security measures, - * user password is required to complete this request. - * This endpoint can also be used to convert an anonymous account to a normal - * one, by passing an email address and a new password. - * - * - * @param {string} email - * @param {string} password - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateEmail(email: string, password: string): Promise> { - if (typeof email === 'undefined') { - throw new AppwriteException('Missing required parameter: "email"'); - } - - if (typeof password === 'undefined') { - throw new AppwriteException('Missing required parameter: "password"'); - } - - let path = '/account/email'; - let payload: Payload = {}; - - if (typeof email !== 'undefined') { - payload['email'] = email; - } - - if (typeof password !== 'undefined') { - payload['password'] = password; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create JWT - * - * Use this endpoint to create a JSON Web Token. You can use the resulting JWT - * to authenticate on behalf of the current user when working with the - * Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes - * from its creation and will be invalid if the user will logout in that time - * frame. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async createJWT(): Promise { - let path = '/account/jwt'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * List 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 {string[]} queries - * @throws {AppwriteException} - * @returns {Promise} - */ - async listLogs(queries?: string[]): Promise { - let path = '/account/logs'; - let payload: Payload = {}; - - if (typeof queries !== 'undefined') { - payload['queries'] = queries; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Name - * - * Update currently logged in user account name. - * - * @param {string} name - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateName(name: string): Promise> { - if (typeof name === 'undefined') { - throw new AppwriteException('Missing required parameter: "name"'); - } - - let path = '/account/name'; - let payload: Payload = {}; - - if (typeof name !== 'undefined') { - payload['name'] = name; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Password - * - * Update currently logged in user password. For validation, user is required - * to pass in the new password, and the old password. For users created with - * OAuth, Team Invites and Magic URL, oldPassword is optional. - * - * @param {string} password - * @param {string} oldPassword - * @throws {AppwriteException} - * @returns {Promise} - */ - async updatePassword(password: string, oldPassword?: string): Promise> { - if (typeof password === 'undefined') { - throw new AppwriteException('Missing required parameter: "password"'); - } - - let path = '/account/password'; - let payload: Payload = {}; - - if (typeof password !== 'undefined') { - payload['password'] = password; - } - - if (typeof oldPassword !== 'undefined') { - payload['oldPassword'] = oldPassword; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Phone - * - * Update the currently logged in user's phone number. After updating the - * phone number, the phone verification status will be reset. A confirmation - * SMS is not sent automatically, however you can use the [POST - * /account/verification/phone](/docs/client/account#accountCreatePhoneVerification) - * endpoint to send a confirmation SMS. - * - * @param {string} phone - * @param {string} password - * @throws {AppwriteException} - * @returns {Promise} - */ - async updatePhone(phone: string, password: string): Promise> { - 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: Payload = {}; - - if (typeof phone !== 'undefined') { - payload['phone'] = phone; - } - - if (typeof password !== 'undefined') { - payload['password'] = password; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Get Account Preferences - * - * Get currently logged in user preferences as a key-value object. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async getPrefs(): Promise { - let path = '/account/prefs'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Preferences - * - * Update currently logged in user account preferences. The object you pass is - * stored as is, and replaces any previous value. The maximum allowed prefs - * size is 64kB and throws error if exceeded. - * - * @param {Partial} prefs - * @throws {AppwriteException} - * @returns {Promise} - */ - async updatePrefs(prefs: Partial): Promise> { - if (typeof prefs === 'undefined') { - throw new AppwriteException('Missing required parameter: "prefs"'); - } - - let path = '/account/prefs'; - let payload: Payload = {}; - - if (typeof prefs !== 'undefined') { - payload['prefs'] = prefs; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Password Recovery - * - * Sends the user an email with a temporary secret key for password reset. - * When the user clicks the confirmation link he is redirected back to your - * app password reset URL with the secret key and email address values - * attached to the URL query string. Use the query string params to submit a - * request to the [PUT - * /account/recovery](/docs/client/account#accountUpdateRecovery) endpoint to - * complete the process. The verification link sent to the user's email - * address is valid for 1 hour. - * - * @param {string} email - * @param {string} url - * @throws {AppwriteException} - * @returns {Promise} - */ - async createRecovery(email: string, url: string): Promise { - if (typeof email === 'undefined') { - throw new AppwriteException('Missing required parameter: "email"'); - } - - if (typeof url === 'undefined') { - throw new AppwriteException('Missing required parameter: "url"'); - } - - let path = '/account/recovery'; - let payload: Payload = {}; - - if (typeof email !== 'undefined') { - payload['email'] = email; - } - - if (typeof url !== 'undefined') { - payload['url'] = url; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Password Recovery (confirmation) - * - * Use this endpoint to complete the user account password reset. Both the - * **userId** and **secret** arguments will be passed as query parameters to - * the redirect URL you have provided when sending your request to the [POST - * /account/recovery](/docs/client/account#accountCreateRecovery) endpoint. - * - * Please note that in order to avoid a [Redirect - * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) - * the only valid redirect URLs are the ones from domains you have set when - * adding your platforms in the console interface. - * - * @param {string} userId - * @param {string} secret - * @param {string} password - * @param {string} passwordAgain - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateRecovery(userId: string, secret: string, password: string, passwordAgain: string): Promise { - if (typeof userId === 'undefined') { - throw new AppwriteException('Missing required parameter: "userId"'); - } - - if (typeof secret === 'undefined') { - throw new AppwriteException('Missing required parameter: "secret"'); - } - - if (typeof password === 'undefined') { - throw new AppwriteException('Missing required parameter: "password"'); - } - - if (typeof passwordAgain === 'undefined') { - throw new AppwriteException('Missing required parameter: "passwordAgain"'); - } - - let path = '/account/recovery'; - let payload: Payload = {}; - - if (typeof userId !== 'undefined') { - payload['userId'] = userId; - } - - if (typeof secret !== 'undefined') { - payload['secret'] = secret; - } - - if (typeof password !== 'undefined') { - payload['password'] = password; - } - - if (typeof passwordAgain !== 'undefined') { - payload['passwordAgain'] = passwordAgain; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('put', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * List Sessions - * - * Get currently logged in user list of active sessions across different - * devices. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async listSessions(): Promise { - let path = '/account/sessions'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Delete Sessions - * - * Delete all sessions from the user account and remove any sessions cookies - * from the end client. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async deleteSessions(): Promise<{}> { - let path = '/account/sessions'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('delete', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Anonymous Session - * - * Use this endpoint to allow a new user to register an anonymous account in - * your project. This route will also create a new session for the user. To - * allow the new user to convert an anonymous account to a normal account, you - * need to update its [email and - * password](/docs/client/account#accountUpdateEmail) or create an [OAuth2 - * session](/docs/client/account#accountCreateOAuth2Session). - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async createAnonymousSession(): Promise { - let path = '/account/sessions/anonymous'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Email Session - * - * Allow the user to login into their account by providing a valid email and - * password combination. This route will create a new session for the user. - * - * A user is limited to 10 active sessions at a time by default. [Learn more - * about session limits](/docs/authentication-security#limits). - * - * @param {string} email - * @param {string} password - * @throws {AppwriteException} - * @returns {Promise} - */ - async createEmailSession(email: string, password: string): Promise { - if (typeof email === 'undefined') { - throw new AppwriteException('Missing required parameter: "email"'); - } - - if (typeof password === 'undefined') { - throw new AppwriteException('Missing required parameter: "password"'); - } - - let path = '/account/sessions/email'; - let payload: Payload = {}; - - if (typeof email !== 'undefined') { - payload['email'] = email; - } - - if (typeof password !== 'undefined') { - payload['password'] = password; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Magic URL session - * - * Sends the user an email with a secret key for creating a session. If the - * provided user ID has not be registered, a new user will be created. When - * the user clicks the link in the email, the user is redirected back to the - * URL you provided with the secret key and userId values attached to the URL - * query string. Use the query string parameters to submit a request to the - * [PUT - * /account/sessions/magic-url](/docs/client/account#accountUpdateMagicURLSession) - * endpoint to complete the login process. The link sent to the user's email - * address is valid for 1 hour. If you are on a mobile device you can leave - * the URL parameter empty, so that the login completion will be handled by - * your Appwrite instance by default. - * - * A user is limited to 10 active sessions at a time by default. [Learn more - * about session limits](/docs/authentication-security#limits). - * - * @param {string} userId - * @param {string} email - * @param {string} url - * @throws {AppwriteException} - * @returns {Promise} - */ - async createMagicURLSession(userId: string, email: string, url?: string): Promise { - if (typeof userId === 'undefined') { - throw new AppwriteException('Missing required parameter: "userId"'); - } - - if (typeof email === 'undefined') { - throw new AppwriteException('Missing required parameter: "email"'); - } - - let path = '/account/sessions/magic-url'; - let payload: Payload = {}; - - if (typeof userId !== 'undefined') { - payload['userId'] = userId; - } - - if (typeof email !== 'undefined') { - payload['email'] = email; - } - - if (typeof url !== 'undefined') { - payload['url'] = url; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Magic URL session (confirmation) - * - * Use this endpoint to complete creating the session with the Magic URL. Both - * the **userId** and **secret** arguments will be passed as query parameters - * to the redirect URL you have provided when sending your request to the - * [POST - * /account/sessions/magic-url](/docs/client/account#accountCreateMagicURLSession) - * endpoint. - * - * Please note that in order to avoid a [Redirect - * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) - * the only valid redirect URLs are the ones from domains you have set when - * adding your platforms in the console interface. - * - * @param {string} userId - * @param {string} secret - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateMagicURLSession(userId: string, secret: string): Promise { - if (typeof userId === 'undefined') { - throw new AppwriteException('Missing required parameter: "userId"'); - } - - if (typeof secret === 'undefined') { - throw new AppwriteException('Missing required parameter: "secret"'); - } - - let path = '/account/sessions/magic-url'; - let payload: Payload = {}; - - if (typeof userId !== 'undefined') { - payload['userId'] = userId; - } - - if (typeof secret !== 'undefined') { - payload['secret'] = secret; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('put', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create OAuth2 Session - * - * Allow the user to login to their account using the OAuth2 provider of their - * choice. Each OAuth2 provider should be enabled from the Appwrite console - * first. Use the success and failure arguments to provide a redirect URL's - * back to your app when login is completed. - * - * If there is already an active session, the new session will be attached to - * the logged-in account. If there are no active sessions, the server will - * attempt to look for a user with the same email address as the email - * received from the OAuth2 provider and attach the new session to the - * existing user. If no matching user is found - the server will create a new - * user. - * - * A user is limited to 10 active sessions at a time by default. [Learn more - * about session limits](/docs/authentication-security#limits). - * - * - * @param {string} provider - * @param {string} success - * @param {string} failure - * @param {string[]} scopes - * @throws {AppwriteException} - * @returns {void|string} - */ - createOAuth2Session(provider: string, success?: string, failure?: string, scopes?: string[]): void | URL { - if (typeof provider === 'undefined') { - throw new AppwriteException('Missing required parameter: "provider"'); - } - - let path = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider); - let payload: Payload = {}; - - if (typeof success !== 'undefined') { - payload['success'] = success; - } - - if (typeof failure !== 'undefined') { - payload['failure'] = failure; - } - - if (typeof scopes !== 'undefined') { - payload['scopes'] = scopes; - } - - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; - - - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - if (typeof window !== 'undefined' && window?.location) { - window.location.href = uri.toString(); - } else { - return uri; - } - } - - /** - * Create Phone session - * - * Sends the user an SMS with a secret key for creating a session. If the - * provided user ID has not be registered, a new user will be created. Use the - * returned user ID and secret and submit a request to the [PUT - * /account/sessions/phone](/docs/client/account#accountUpdatePhoneSession) - * endpoint to complete the login process. The secret sent to the user's phone - * is valid for 15 minutes. - * - * A user is limited to 10 active sessions at a time by default. [Learn more - * about session limits](/docs/authentication-security#limits). - * - * @param {string} userId - * @param {string} phone - * @throws {AppwriteException} - * @returns {Promise} - */ - async createPhoneSession(userId: string, phone: string): Promise { - if (typeof userId === 'undefined') { - throw new AppwriteException('Missing required parameter: "userId"'); - } - - if (typeof phone === 'undefined') { - throw new AppwriteException('Missing required parameter: "phone"'); - } - - let path = '/account/sessions/phone'; - let payload: Payload = {}; - - if (typeof userId !== 'undefined') { - payload['userId'] = userId; - } - - if (typeof phone !== 'undefined') { - payload['phone'] = phone; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Phone Session (confirmation) - * - * Use this endpoint to complete creating a session with SMS. Use the - * **userId** from the - * [createPhoneSession](/docs/client/account#accountCreatePhoneSession) - * endpoint and the **secret** received via SMS to successfully update and - * confirm the phone session. - * - * @param {string} userId - * @param {string} secret - * @throws {AppwriteException} - * @returns {Promise} - */ - async updatePhoneSession(userId: string, secret: string): Promise { - if (typeof userId === 'undefined') { - throw new AppwriteException('Missing required parameter: "userId"'); - } - - if (typeof secret === 'undefined') { - throw new AppwriteException('Missing required parameter: "secret"'); - } - - let path = '/account/sessions/phone'; - let payload: Payload = {}; - - if (typeof userId !== 'undefined') { - payload['userId'] = userId; - } - - if (typeof secret !== 'undefined') { - payload['secret'] = secret; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('put', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Get Session - * - * Use this endpoint to get a logged in user's session using a Session ID. - * Inputting 'current' will return the current session being used. - * - * @param {string} sessionId - * @throws {AppwriteException} - * @returns {Promise} - */ - async getSession(sessionId: string): Promise { - if (typeof sessionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "sessionId"'); - } - - let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update OAuth Session (Refresh Tokens) - * - * Access tokens have limited lifespan and expire to mitigate security risks. - * If session was created using an OAuth provider, this route can be used to - * "refresh" the access token. - * - * @param {string} sessionId - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateSession(sessionId: string): Promise { - if (typeof sessionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "sessionId"'); - } - - let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Delete Session - * - * Use this endpoint to log out the currently logged in user from all their - * account sessions across all of their different devices. When using the - * Session ID argument, only the unique session ID provided is deleted. - * - * - * @param {string} sessionId - * @throws {AppwriteException} - * @returns {Promise} - */ - async deleteSession(sessionId: string): Promise<{}> { - if (typeof sessionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "sessionId"'); - } - - let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('delete', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Status - * - * Block the currently logged in user account. Behind the scene, the user - * record is not deleted but permanently blocked from any access. To - * completely delete a user, use the Users API instead. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateStatus(): Promise> { - let path = '/account/status'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Email Verification - * - * Use this endpoint to send a verification message to your user email address - * to confirm they are the valid owners of that address. Both the **userId** - * and **secret** arguments will be passed as query parameters to the URL you - * have provided to be attached to the verification email. The provided URL - * should redirect the user back to your app and allow you to complete the - * verification process by verifying both the **userId** and **secret** - * parameters. Learn more about how to [complete the verification - * process](/docs/client/account#accountUpdateEmailVerification). The - * verification link sent to the user's email address is valid for 7 days. - * - * Please note that in order to avoid a [Redirect - * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), - * the only valid redirect URLs are the ones from domains you have set when - * adding your platforms in the console interface. - * - * - * @param {string} url - * @throws {AppwriteException} - * @returns {Promise} - */ - async createVerification(url: string): Promise { - if (typeof url === 'undefined') { - throw new AppwriteException('Missing required parameter: "url"'); - } - - let path = '/account/verification'; - let payload: Payload = {}; - - if (typeof url !== 'undefined') { - payload['url'] = url; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Email Verification (confirmation) - * - * Use this endpoint to complete the user email verification process. Use both - * the **userId** and **secret** parameters that were attached to your app URL - * to verify the user email ownership. If confirmed this route will return a - * 200 status code. - * - * @param {string} userId - * @param {string} secret - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateVerification(userId: string, secret: string): Promise { - if (typeof userId === 'undefined') { - throw new AppwriteException('Missing required parameter: "userId"'); - } - - if (typeof secret === 'undefined') { - throw new AppwriteException('Missing required parameter: "secret"'); - } - - let path = '/account/verification'; - let payload: Payload = {}; - - if (typeof userId !== 'undefined') { - payload['userId'] = userId; - } - - if (typeof secret !== 'undefined') { - payload['secret'] = secret; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('put', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Phone Verification - * - * Use this endpoint to send a verification SMS to the currently logged in - * user. This endpoint is meant for use after updating a user's phone number - * using the [accountUpdatePhone](/docs/client/account#accountUpdatePhone) - * endpoint. Learn more about how to [complete the verification - * process](/docs/client/account#accountUpdatePhoneVerification). The - * verification code sent to the user's phone number is valid for 15 minutes. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async createPhoneVerification(): Promise { - let path = '/account/verification/phone'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Phone Verification (confirmation) - * - * Use this endpoint to complete the user phone verification process. Use the - * **userId** and **secret** that were sent to your user's phone number to - * verify the user email ownership. If confirmed this route will return a 200 - * status code. - * - * @param {string} userId - * @param {string} secret - * @throws {AppwriteException} - * @returns {Promise} - */ - async updatePhoneVerification(userId: string, secret: string): Promise { - if (typeof userId === 'undefined') { - throw new AppwriteException('Missing required parameter: "userId"'); - } - - if (typeof secret === 'undefined') { - throw new AppwriteException('Missing required parameter: "secret"'); - } - - let path = '/account/verification/phone'; - let payload: Payload = {}; - - if (typeof userId !== 'undefined') { - payload['userId'] = userId; - } - - if (typeof secret !== 'undefined') { - payload['secret'] = secret; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('put', uri, { - 'content-type': 'application/json', - }, payload); + /** + * Get Account + * + * Get currently logged in user data as JSON object. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async get(): Promise> { + let path = '/account'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Account + * + * Use this endpoint to allow a new user to register a new account in your + * project. After the user registration completes successfully, you can use + * the [/account/verfication](/docs/client/account#accountCreateVerification) + * route to start verifying the user email address. To allow the new user to + * login to their new account, you need to create a new [account + * session](/docs/client/account#accountCreateSession). + * + * @param {string} userId + * @param {string} email + * @param {string} password + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async create(userId: string, email: string, password: string, name?: string): Promise> { + 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"'); + } + + let path = '/account'; + let payload: Payload = {}; + + 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; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Email + * + * Update currently logged in user account email address. After changing user + * address, the user confirmation status will get reset. A new confirmation + * email is not sent automatically however you can use the send confirmation + * email endpoint again to send the confirmation email. For security measures, + * user password is required to complete this request. + * This endpoint can also be used to convert an anonymous account to a normal + * one, by passing an email address and a new password. + * + * + * @param {string} email + * @param {string} password + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateEmail(email: string, password: string): Promise> { + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + let path = '/account/email'; + let payload: Payload = {}; + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create JWT + * + * Use this endpoint to create a JSON Web Token. You can use the resulting JWT + * to authenticate on behalf of the current user when working with the + * Appwrite server-side API and SDKs. The JWT secret is valid for 15 minutes + * from its creation and will be invalid if the user will logout in that time + * frame. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async createJWT(): Promise { + let path = '/account/jwt'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List 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 {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + async listLogs(queries?: string[]): Promise { + let path = '/account/logs'; + let payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Name + * + * Update currently logged in user account name. + * + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateName(name: string): Promise> { + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + let path = '/account/name'; + let payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Password + * + * Update currently logged in user password. For validation, user is required + * to pass in the new password, and the old password. For users created with + * OAuth, Team Invites and Magic URL, oldPassword is optional. + * + * @param {string} password + * @param {string} oldPassword + * @throws {AppwriteException} + * @returns {Promise} + */ + async updatePassword(password: string, oldPassword?: string): Promise> { + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + let path = '/account/password'; + let payload: Payload = {}; + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + if (typeof oldPassword !== 'undefined') { + payload['oldPassword'] = oldPassword; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Phone + * + * Update the currently logged in user's phone number. After updating the + * phone number, the phone verification status will be reset. A confirmation + * SMS is not sent automatically, however you can use the [POST + * /account/verification/phone](/docs/client/account#accountCreatePhoneVerification) + * endpoint to send a confirmation SMS. + * + * @param {string} phone + * @param {string} password + * @throws {AppwriteException} + * @returns {Promise} + */ + async updatePhone(phone: string, password: string): Promise> { + 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: Payload = {}; + + if (typeof phone !== 'undefined') { + payload['phone'] = phone; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Get Account Preferences + * + * Get currently logged in user preferences as a key-value object. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async getPrefs(): Promise { + let path = '/account/prefs'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Preferences + * + * Update currently logged in user account preferences. The object you pass is + * stored as is, and replaces any previous value. The maximum allowed prefs + * size is 64kB and throws error if exceeded. + * + * @param {Partial} prefs + * @throws {AppwriteException} + * @returns {Promise} + */ + async updatePrefs(prefs: Partial): Promise> { + if (typeof prefs === 'undefined') { + throw new AppwriteException('Missing required parameter: "prefs"'); + } + + let path = '/account/prefs'; + let payload: Payload = {}; + + if (typeof prefs !== 'undefined') { + payload['prefs'] = prefs; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Password Recovery + * + * Sends the user an email with a temporary secret key for password reset. + * When the user clicks the confirmation link he is redirected back to your + * app password reset URL with the secret key and email address values + * attached to the URL query string. Use the query string params to submit a + * request to the [PUT + * /account/recovery](/docs/client/account#accountUpdateRecovery) endpoint to + * complete the process. The verification link sent to the user's email + * address is valid for 1 hour. + * + * @param {string} email + * @param {string} url + * @throws {AppwriteException} + * @returns {Promise} + */ + async createRecovery(email: string, url: string): Promise { + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof url === 'undefined') { + throw new AppwriteException('Missing required parameter: "url"'); + } + + let path = '/account/recovery'; + let payload: Payload = {}; + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof url !== 'undefined') { + payload['url'] = url; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Password Recovery (confirmation) + * + * Use this endpoint to complete the user account password reset. Both the + * **userId** and **secret** arguments will be passed as query parameters to + * the redirect URL you have provided when sending your request to the [POST + * /account/recovery](/docs/client/account#accountCreateRecovery) endpoint. + * + * Please note that in order to avoid a [Redirect + * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) + * the only valid redirect URLs are the ones from domains you have set when + * adding your platforms in the console interface. + * + * @param {string} userId + * @param {string} secret + * @param {string} password + * @param {string} passwordAgain + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateRecovery(userId: string, secret: string, password: string, passwordAgain: string): Promise { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof secret === 'undefined') { + throw new AppwriteException('Missing required parameter: "secret"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + if (typeof passwordAgain === 'undefined') { + throw new AppwriteException('Missing required parameter: "passwordAgain"'); + } + + let path = '/account/recovery'; + let payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + if (typeof passwordAgain !== 'undefined') { + payload['passwordAgain'] = passwordAgain; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('put', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List Sessions + * + * Get currently logged in user list of active sessions across different + * devices. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async listSessions(): Promise { + let path = '/account/sessions'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Delete Sessions + * + * Delete all sessions from the user account and remove any sessions cookies + * from the end client. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteSessions(): Promise<{}> { + let path = '/account/sessions'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('delete', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Anonymous Session + * + * Use this endpoint to allow a new user to register an anonymous account in + * your project. This route will also create a new session for the user. To + * allow the new user to convert an anonymous account to a normal account, you + * need to update its [email and + * password](/docs/client/account#accountUpdateEmail) or create an [OAuth2 + * session](/docs/client/account#accountCreateOAuth2Session). + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async createAnonymousSession(): Promise { + let path = '/account/sessions/anonymous'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Email Session + * + * Allow the user to login into their account by providing a valid email and + * password combination. This route will create a new session for the user. + * + * A user is limited to 10 active sessions at a time by default. [Learn more + * about session limits](/docs/authentication-security#limits). + * + * @param {string} email + * @param {string} password + * @throws {AppwriteException} + * @returns {Promise} + */ + async createEmailSession(email: string, password: string): Promise { + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + if (typeof password === 'undefined') { + throw new AppwriteException('Missing required parameter: "password"'); + } + + let path = '/account/sessions/email'; + let payload: Payload = {}; + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof password !== 'undefined') { + payload['password'] = password; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Magic URL session + * + * Sends the user an email with a secret key for creating a session. If the + * provided user ID has not be registered, a new user will be created. When + * the user clicks the link in the email, the user is redirected back to the + * URL you provided with the secret key and userId values attached to the URL + * query string. Use the query string parameters to submit a request to the + * [PUT + * /account/sessions/magic-url](/docs/client/account#accountUpdateMagicURLSession) + * endpoint to complete the login process. The link sent to the user's email + * address is valid for 1 hour. If you are on a mobile device you can leave + * the URL parameter empty, so that the login completion will be handled by + * your Appwrite instance by default. + * + * A user is limited to 10 active sessions at a time by default. [Learn more + * about session limits](/docs/authentication-security#limits). + * + * @param {string} userId + * @param {string} email + * @param {string} url + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMagicURLSession(userId: string, email: string, url?: string): Promise { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof email === 'undefined') { + throw new AppwriteException('Missing required parameter: "email"'); + } + + let path = '/account/sessions/magic-url'; + let payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof url !== 'undefined') { + payload['url'] = url; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Magic URL session (confirmation) + * + * Use this endpoint to complete creating the session with the Magic URL. Both + * the **userId** and **secret** arguments will be passed as query parameters + * to the redirect URL you have provided when sending your request to the + * [POST + * /account/sessions/magic-url](/docs/client/account#accountCreateMagicURLSession) + * endpoint. + * + * Please note that in order to avoid a [Redirect + * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) + * the only valid redirect URLs are the ones from domains you have set when + * adding your platforms in the console interface. + * + * @param {string} userId + * @param {string} secret + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMagicURLSession(userId: string, secret: string): Promise { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof secret === 'undefined') { + throw new AppwriteException('Missing required parameter: "secret"'); + } + + let path = '/account/sessions/magic-url'; + let payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('put', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create OAuth2 Session + * + * Allow the user to login to their account using the OAuth2 provider of their + * choice. Each OAuth2 provider should be enabled from the Appwrite console + * first. Use the success and failure arguments to provide a redirect URL's + * back to your app when login is completed. + * + * If there is already an active session, the new session will be attached to + * the logged-in account. If there are no active sessions, the server will + * attempt to look for a user with the same email address as the email + * received from the OAuth2 provider and attach the new session to the + * existing user. If no matching user is found - the server will create a new + * user. + * + * A user is limited to 10 active sessions at a time by default. [Learn more + * about session limits](/docs/authentication-security#limits). + * + * + * @param {string} provider + * @param {string} success + * @param {string} failure + * @param {string[]} scopes + * @throws {AppwriteException} + * @returns {void|string} + */ + createOAuth2Session(provider: string, success?: string, failure?: string, scopes?: string[]): void | URL { + if (typeof provider === 'undefined') { + throw new AppwriteException('Missing required parameter: "provider"'); + } + + let path = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider); + let payload: Payload = {}; + + if (typeof success !== 'undefined') { + payload['success'] = success; + } + + if (typeof failure !== 'undefined') { + payload['failure'] = failure; + } + + if (typeof scopes !== 'undefined') { + payload['scopes'] = scopes; + } + + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; + + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + if (typeof window !== 'undefined' && window?.location) { + window.location.href = uri.toString(); + } else { + return uri; + } + } + + /** + * Create Phone session + * + * Sends the user an SMS with a secret key for creating a session. If the + * provided user ID has not be registered, a new user will be created. Use the + * returned user ID and secret and submit a request to the [PUT + * /account/sessions/phone](/docs/client/account#accountUpdatePhoneSession) + * endpoint to complete the login process. The secret sent to the user's phone + * is valid for 15 minutes. + * + * A user is limited to 10 active sessions at a time by default. [Learn more + * about session limits](/docs/authentication-security#limits). + * + * @param {string} userId + * @param {string} phone + * @throws {AppwriteException} + * @returns {Promise} + */ + async createPhoneSession(userId: string, phone: string): Promise { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof phone === 'undefined') { + throw new AppwriteException('Missing required parameter: "phone"'); + } + + let path = '/account/sessions/phone'; + let payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof phone !== 'undefined') { + payload['phone'] = phone; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Phone Session (confirmation) + * + * Use this endpoint to complete creating a session with SMS. Use the + * **userId** from the + * [createPhoneSession](/docs/client/account#accountCreatePhoneSession) + * endpoint and the **secret** received via SMS to successfully update and + * confirm the phone session. + * + * @param {string} userId + * @param {string} secret + * @throws {AppwriteException} + * @returns {Promise} + */ + async updatePhoneSession(userId: string, secret: string): Promise { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof secret === 'undefined') { + throw new AppwriteException('Missing required parameter: "secret"'); + } + + let path = '/account/sessions/phone'; + let payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('put', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Get Session + * + * Use this endpoint to get a logged in user's session using a Session ID. + * Inputting 'current' will return the current session being used. + * + * @param {string} sessionId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getSession(sessionId: string): Promise { + if (typeof sessionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "sessionId"'); + } + + let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update OAuth Session (Refresh Tokens) + * + * Access tokens have limited lifespan and expire to mitigate security risks. + * If session was created using an OAuth provider, this route can be used to + * "refresh" the access token. + * + * @param {string} sessionId + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateSession(sessionId: string): Promise { + if (typeof sessionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "sessionId"'); + } + + let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Delete Session + * + * Use this endpoint to log out the currently logged in user from all their + * account sessions across all of their different devices. When using the + * Session ID argument, only the unique session ID provided is deleted. + * + * + * @param {string} sessionId + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteSession(sessionId: string): Promise<{}> { + if (typeof sessionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "sessionId"'); + } + + let path = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('delete', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Status + * + * Block the currently logged in user account. Behind the scene, the user + * record is not deleted but permanently blocked from any access. To + * completely delete a user, use the Users API instead. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateStatus(): Promise> { + let path = '/account/status'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Email Verification + * + * Use this endpoint to send a verification message to your user email address + * to confirm they are the valid owners of that address. Both the **userId** + * and **secret** arguments will be passed as query parameters to the URL you + * have provided to be attached to the verification email. The provided URL + * should redirect the user back to your app and allow you to complete the + * verification process by verifying both the **userId** and **secret** + * parameters. Learn more about how to [complete the verification + * process](/docs/client/account#accountUpdateEmailVerification). The + * verification link sent to the user's email address is valid for 7 days. + * + * Please note that in order to avoid a [Redirect + * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), + * the only valid redirect URLs are the ones from domains you have set when + * adding your platforms in the console interface. + * + * + * @param {string} url + * @throws {AppwriteException} + * @returns {Promise} + */ + async createVerification(url: string): Promise { + if (typeof url === 'undefined') { + throw new AppwriteException('Missing required parameter: "url"'); + } + + let path = '/account/verification'; + let payload: Payload = {}; + + if (typeof url !== 'undefined') { + payload['url'] = url; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Email Verification (confirmation) + * + * Use this endpoint to complete the user email verification process. Use both + * the **userId** and **secret** parameters that were attached to your app URL + * to verify the user email ownership. If confirmed this route will return a + * 200 status code. + * + * @param {string} userId + * @param {string} secret + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateVerification(userId: string, secret: string): Promise { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof secret === 'undefined') { + throw new AppwriteException('Missing required parameter: "secret"'); + } + + let path = '/account/verification'; + let payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('put', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Phone Verification + * + * Use this endpoint to send a verification SMS to the currently logged in + * user. This endpoint is meant for use after updating a user's phone number + * using the [accountUpdatePhone](/docs/client/account#accountUpdatePhone) + * endpoint. Learn more about how to [complete the verification + * process](/docs/client/account#accountUpdatePhoneVerification). The + * verification code sent to the user's phone number is valid for 15 minutes. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async createPhoneVerification(): Promise { + let path = '/account/verification/phone'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Phone Verification (confirmation) + * + * Use this endpoint to complete the user phone verification process. Use the + * **userId** and **secret** that were sent to your user's phone number to + * verify the user email ownership. If confirmed this route will return a 200 + * status code. + * + * @param {string} userId + * @param {string} secret + * @throws {AppwriteException} + * @returns {Promise} + */ + async updatePhoneVerification(userId: string, secret: string): Promise { + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof secret === 'undefined') { + throw new AppwriteException('Missing required parameter: "secret"'); + } + + let path = '/account/verification/phone'; + let payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('put', uri, { + 'content-type': 'application/json', + }, payload); + } }; diff --git a/src/services/avatars.ts b/src/services/avatars.ts index 8887269..90e7c89 100644 --- a/src/services/avatars.ts +++ b/src/services/avatars.ts @@ -10,342 +10,342 @@ export class Avatars extends Service { super(client); } - /** - * Get Browser Icon - * - * You can use this endpoint to show different browser icons to your users. - * The code argument receives the browser code as it appears in your user [GET - * /account/sessions](/docs/client/account#accountGetSessions) endpoint. Use - * width, height and quality arguments to change the output settings. - * - * 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 - * image at source quality. If dimensions are not specified, the default size - * of image returned is 100x100px. - * - * @param {string} code - * @param {number} width - * @param {number} height - * @param {number} quality - * @throws {AppwriteException} - * @returns {URL} - */ - getBrowser(code: string, width?: number, height?: number, quality?: number): URL { - if (typeof code === 'undefined') { - throw new AppwriteException('Missing required parameter: "code"'); - } - - let path = '/avatars/browsers/{code}'.replace('{code}', code); - let payload: Payload = {}; - - if (typeof width !== 'undefined') { - payload['width'] = width; - } - - if (typeof height !== 'undefined') { - payload['height'] = height; - } - - if (typeof quality !== 'undefined') { - payload['quality'] = quality; - } - - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; - - - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; - } - - /** - * Get Credit Card Icon - * - * The credit card endpoint will return you the icon of the credit card - * provider you need. Use width, height and quality arguments to change the - * output settings. - * - * 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 - * image at source quality. If dimensions are not specified, the default size - * of image returned is 100x100px. - * - * - * @param {string} code - * @param {number} width - * @param {number} height - * @param {number} quality - * @throws {AppwriteException} - * @returns {URL} - */ - getCreditCard(code: string, width?: number, height?: number, quality?: number): URL { - if (typeof code === 'undefined') { - throw new AppwriteException('Missing required parameter: "code"'); - } - - let path = '/avatars/credit-cards/{code}'.replace('{code}', code); - let payload: Payload = {}; - - if (typeof width !== 'undefined') { - payload['width'] = width; - } - - if (typeof height !== 'undefined') { - payload['height'] = height; - } - - if (typeof quality !== 'undefined') { - payload['quality'] = quality; - } - - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; - - - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; - } - - /** - * Get Favicon - * - * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote - * website URL. - * - * - * @param {string} url - * @throws {AppwriteException} - * @returns {URL} - */ - getFavicon(url: string): URL { - if (typeof url === 'undefined') { - throw new AppwriteException('Missing required parameter: "url"'); - } - - let path = '/avatars/favicon'; - let payload: Payload = {}; - - if (typeof url !== 'undefined') { - payload['url'] = url; - } - - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; - - - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; - } - - /** - * Get Country Flag - * - * You can use this endpoint to show different country flags icons to your - * users. The code argument receives the 2 letter country code. Use width, - * height and quality arguments to change the output settings. 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 - * image at source quality. If dimensions are not specified, the default size - * of image returned is 100x100px. - * - * - * @param {string} code - * @param {number} width - * @param {number} height - * @param {number} quality - * @throws {AppwriteException} - * @returns {URL} - */ - getFlag(code: string, width?: number, height?: number, quality?: number): URL { - if (typeof code === 'undefined') { - throw new AppwriteException('Missing required parameter: "code"'); - } - - let path = '/avatars/flags/{code}'.replace('{code}', code); - let payload: Payload = {}; - - if (typeof width !== 'undefined') { - payload['width'] = width; - } - - if (typeof height !== 'undefined') { - payload['height'] = height; - } - - if (typeof quality !== 'undefined') { - payload['quality'] = quality; - } - - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; - - - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; - } - - /** - * Get Image from URL - * - * Use this endpoint to fetch a remote image URL and crop it to any image size - * you want. This endpoint is very useful if you need to crop and display - * remote images in your app or in case you want to make sure a 3rd party - * image is properly served using a TLS protocol. - * - * 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 - * image at source quality. If dimensions are not specified, the default size - * of image returned is 400x400px. - * - * - * @param {string} url - * @param {number} width - * @param {number} height - * @throws {AppwriteException} - * @returns {URL} - */ - getImage(url: string, width?: number, height?: number): URL { - if (typeof url === 'undefined') { - throw new AppwriteException('Missing required parameter: "url"'); - } - - let path = '/avatars/image'; - let payload: Payload = {}; - - if (typeof url !== 'undefined') { - payload['url'] = url; - } - - if (typeof width !== 'undefined') { - payload['width'] = width; - } - - if (typeof height !== 'undefined') { - payload['height'] = height; - } - - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; - - - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; - } - - /** - * Get User Initials - * - * Use this endpoint to show your user initials avatar icon on your website or - * app. By default, this route will try to print your logged-in user name or - * email initials. You can also overwrite the user name if you pass the 'name' - * parameter. If no name is given and no user is logged, an empty avatar will - * be returned. - * - * You can use the color and background params to change the avatar colors. By - * default, a random theme will be selected. The random theme will persist for - * the user's initials when reloading the same theme will always return for - * the same initials. - * - * 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 - * image at source quality. If dimensions are not specified, the default size - * of image returned is 100x100px. - * - * - * @param {string} name - * @param {number} width - * @param {number} height - * @param {string} background - * @throws {AppwriteException} - * @returns {URL} - */ - getInitials(name?: string, width?: number, height?: number, background?: string): URL { - let path = '/avatars/initials'; - let payload: Payload = {}; - - if (typeof name !== 'undefined') { - payload['name'] = name; - } - - if (typeof width !== 'undefined') { - payload['width'] = width; - } - - if (typeof height !== 'undefined') { - payload['height'] = height; - } - - if (typeof background !== 'undefined') { - payload['background'] = background; - } - - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; - - - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; - } - - /** - * Get QR Code - * - * Converts a given plain text to a QR code image. You can use the query - * parameters to change the size and style of the resulting image. - * - * - * @param {string} text - * @param {number} size - * @param {number} margin - * @param {boolean} download - * @throws {AppwriteException} - * @returns {URL} - */ - getQR(text: string, size?: number, margin?: number, download?: boolean): URL { - if (typeof text === 'undefined') { - throw new AppwriteException('Missing required parameter: "text"'); - } - - let path = '/avatars/qr'; - let payload: Payload = {}; - - if (typeof text !== 'undefined') { - payload['text'] = text; - } - - if (typeof size !== 'undefined') { - payload['size'] = size; - } - - if (typeof margin !== 'undefined') { - payload['margin'] = margin; - } - - if (typeof download !== 'undefined') { - payload['download'] = download; - } - - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; - - - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; + /** + * Get Browser Icon + * + * You can use this endpoint to show different browser icons to your users. + * The code argument receives the browser code as it appears in your user [GET + * /account/sessions](/docs/client/account#accountGetSessions) endpoint. Use + * width, height and quality arguments to change the output settings. + * + * 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 + * image at source quality. If dimensions are not specified, the default size + * of image returned is 100x100px. + * + * @param {string} code + * @param {number} width + * @param {number} height + * @param {number} quality + * @throws {AppwriteException} + * @returns {URL} + */ + getBrowser(code: string, width?: number, height?: number, quality?: number): URL { + if (typeof code === 'undefined') { + throw new AppwriteException('Missing required parameter: "code"'); } + + let path = '/avatars/browsers/{code}'.replace('{code}', code); + let payload: Payload = {}; + + if (typeof width !== 'undefined') { + payload['width'] = width; + } + + if (typeof height !== 'undefined') { + payload['height'] = height; + } + + if (typeof quality !== 'undefined') { + payload['quality'] = quality; + } + + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; + + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + return uri; + } + + /** + * Get Credit Card Icon + * + * The credit card endpoint will return you the icon of the credit card + * provider you need. Use width, height and quality arguments to change the + * output settings. + * + * 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 + * image at source quality. If dimensions are not specified, the default size + * of image returned is 100x100px. + * + * + * @param {string} code + * @param {number} width + * @param {number} height + * @param {number} quality + * @throws {AppwriteException} + * @returns {URL} + */ + getCreditCard(code: string, width?: number, height?: number, quality?: number): URL { + if (typeof code === 'undefined') { + throw new AppwriteException('Missing required parameter: "code"'); + } + + let path = '/avatars/credit-cards/{code}'.replace('{code}', code); + let payload: Payload = {}; + + if (typeof width !== 'undefined') { + payload['width'] = width; + } + + if (typeof height !== 'undefined') { + payload['height'] = height; + } + + if (typeof quality !== 'undefined') { + payload['quality'] = quality; + } + + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; + + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + return uri; + } + + /** + * Get Favicon + * + * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote + * website URL. + * + * + * @param {string} url + * @throws {AppwriteException} + * @returns {URL} + */ + getFavicon(url: string): URL { + if (typeof url === 'undefined') { + throw new AppwriteException('Missing required parameter: "url"'); + } + + let path = '/avatars/favicon'; + let payload: Payload = {}; + + if (typeof url !== 'undefined') { + payload['url'] = url; + } + + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; + + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + return uri; + } + + /** + * Get Country Flag + * + * You can use this endpoint to show different country flags icons to your + * users. The code argument receives the 2 letter country code. Use width, + * height and quality arguments to change the output settings. 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 + * image at source quality. If dimensions are not specified, the default size + * of image returned is 100x100px. + * + * + * @param {string} code + * @param {number} width + * @param {number} height + * @param {number} quality + * @throws {AppwriteException} + * @returns {URL} + */ + getFlag(code: string, width?: number, height?: number, quality?: number): URL { + if (typeof code === 'undefined') { + throw new AppwriteException('Missing required parameter: "code"'); + } + + let path = '/avatars/flags/{code}'.replace('{code}', code); + let payload: Payload = {}; + + if (typeof width !== 'undefined') { + payload['width'] = width; + } + + if (typeof height !== 'undefined') { + payload['height'] = height; + } + + if (typeof quality !== 'undefined') { + payload['quality'] = quality; + } + + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; + + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + return uri; + } + + /** + * Get Image from URL + * + * Use this endpoint to fetch a remote image URL and crop it to any image size + * you want. This endpoint is very useful if you need to crop and display + * remote images in your app or in case you want to make sure a 3rd party + * image is properly served using a TLS protocol. + * + * 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 + * image at source quality. If dimensions are not specified, the default size + * of image returned is 400x400px. + * + * + * @param {string} url + * @param {number} width + * @param {number} height + * @throws {AppwriteException} + * @returns {URL} + */ + getImage(url: string, width?: number, height?: number): URL { + if (typeof url === 'undefined') { + throw new AppwriteException('Missing required parameter: "url"'); + } + + let path = '/avatars/image'; + let payload: Payload = {}; + + if (typeof url !== 'undefined') { + payload['url'] = url; + } + + if (typeof width !== 'undefined') { + payload['width'] = width; + } + + if (typeof height !== 'undefined') { + payload['height'] = height; + } + + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; + + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + return uri; + } + + /** + * Get User Initials + * + * Use this endpoint to show your user initials avatar icon on your website or + * app. By default, this route will try to print your logged-in user name or + * email initials. You can also overwrite the user name if you pass the 'name' + * parameter. If no name is given and no user is logged, an empty avatar will + * be returned. + * + * You can use the color and background params to change the avatar colors. By + * default, a random theme will be selected. The random theme will persist for + * the user's initials when reloading the same theme will always return for + * the same initials. + * + * 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 + * image at source quality. If dimensions are not specified, the default size + * of image returned is 100x100px. + * + * + * @param {string} name + * @param {number} width + * @param {number} height + * @param {string} background + * @throws {AppwriteException} + * @returns {URL} + */ + getInitials(name?: string, width?: number, height?: number, background?: string): URL { + let path = '/avatars/initials'; + let payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + if (typeof width !== 'undefined') { + payload['width'] = width; + } + + if (typeof height !== 'undefined') { + payload['height'] = height; + } + + if (typeof background !== 'undefined') { + payload['background'] = background; + } + + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; + + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + return uri; + } + + /** + * Get QR Code + * + * Converts a given plain text to a QR code image. You can use the query + * parameters to change the size and style of the resulting image. + * + * + * @param {string} text + * @param {number} size + * @param {number} margin + * @param {boolean} download + * @throws {AppwriteException} + * @returns {URL} + */ + getQR(text: string, size?: number, margin?: number, download?: boolean): URL { + if (typeof text === 'undefined') { + throw new AppwriteException('Missing required parameter: "text"'); + } + + let path = '/avatars/qr'; + let payload: Payload = {}; + + if (typeof text !== 'undefined') { + payload['text'] = text; + } + + if (typeof size !== 'undefined') { + payload['size'] = size; + } + + if (typeof margin !== 'undefined') { + payload['margin'] = margin; + } + + if (typeof download !== 'undefined') { + payload['download'] = download; + } + + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; + + + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + return uri; + } }; diff --git a/src/services/databases.ts b/src/services/databases.ts index 21181e9..d260d88 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -10,207 +10,207 @@ export class Databases extends Service { super(client); } - /** - * 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. - * - * @param {string} databaseId - * @param {string} collectionId - * @param {string[]} queries - * @throws {AppwriteException} - * @returns {Promise} - */ - async listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> { - 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}', databaseId).replace('{collectionId}', collectionId); - let payload: Payload = {}; - - if (typeof queries !== 'undefined') { - payload['queries'] = queries; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * 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 {Omit} data - * @param {string[]} permissions - * @throws {AppwriteException} - * @returns {Promise} - */ - async createDocument(databaseId: string, collectionId: string, documentId: string, data: Omit, permissions?: string[]): Promise { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof collectionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "collectionId"'); - } - - if (typeof documentId === 'undefined') { - throw new AppwriteException('Missing required parameter: "documentId"'); - } - - if (typeof data === 'undefined') { - throw new AppwriteException('Missing required parameter: "data"'); - } - - let path = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); - let payload: Payload = {}; - - if (typeof documentId !== 'undefined') { - payload['documentId'] = documentId; - } - - if (typeof data !== 'undefined') { - payload['data'] = data; - } - - if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * 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 - * @param {string[]} queries - * @throws {AppwriteException} - * @returns {Promise} - */ - async getDocument(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof collectionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "collectionId"'); - } - - if (typeof documentId === 'undefined') { - throw new AppwriteException('Missing required parameter: "documentId"'); - } - - let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); - let payload: Payload = {}; - - if (typeof queries !== 'undefined') { - payload['queries'] = queries; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * 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 {Partial>} data - * @param {string[]} permissions - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateDocument(databaseId: string, collectionId: string, documentId: string, data?: Partial>, permissions?: string[]): Promise { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof collectionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "collectionId"'); - } - - if (typeof documentId === 'undefined') { - throw new AppwriteException('Missing required parameter: "documentId"'); - } - - let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); - let payload: Payload = {}; - - if (typeof data !== 'undefined') { - payload['data'] = data; - } - - if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Delete Document - * - * Delete a document by its unique ID. - * - * @param {string} databaseId - * @param {string} collectionId - * @param {string} documentId - * @throws {AppwriteException} - * @returns {Promise} - */ - async deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<{}> { - if (typeof databaseId === 'undefined') { - throw new AppwriteException('Missing required parameter: "databaseId"'); - } - - if (typeof collectionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "collectionId"'); - } - - if (typeof documentId === 'undefined') { - throw new AppwriteException('Missing required parameter: "documentId"'); - } - - let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('delete', uri, { - 'content-type': 'application/json', - }, payload); + /** + * 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. + * + * @param {string} databaseId + * @param {string} collectionId + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + async listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> { + 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}', databaseId).replace('{collectionId}', collectionId); + let payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * 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 {Omit} data + * @param {string[]} permissions + * @throws {AppwriteException} + * @returns {Promise} + */ + async createDocument(databaseId: string, collectionId: string, documentId: string, data: Omit, permissions?: string[]): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + + if (typeof documentId === 'undefined') { + throw new AppwriteException('Missing required parameter: "documentId"'); + } + + if (typeof data === 'undefined') { + throw new AppwriteException('Missing required parameter: "data"'); + } + + let path = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); + let payload: Payload = {}; + + if (typeof documentId !== 'undefined') { + payload['documentId'] = documentId; + } + + if (typeof data !== 'undefined') { + payload['data'] = data; + } + + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * 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 + * @param {string[]} queries + * @throws {AppwriteException} + * @returns {Promise} + */ + async getDocument(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + + if (typeof documentId === 'undefined') { + throw new AppwriteException('Missing required parameter: "documentId"'); + } + + let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + let payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * 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 {Partial>} data + * @param {string[]} permissions + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateDocument(databaseId: string, collectionId: string, documentId: string, data?: Partial>, permissions?: string[]): Promise { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + + if (typeof documentId === 'undefined') { + throw new AppwriteException('Missing required parameter: "documentId"'); + } + + let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + let payload: Payload = {}; + + if (typeof data !== 'undefined') { + payload['data'] = data; + } + + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Delete Document + * + * Delete a document by its unique ID. + * + * @param {string} databaseId + * @param {string} collectionId + * @param {string} documentId + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<{}> { + if (typeof databaseId === 'undefined') { + throw new AppwriteException('Missing required parameter: "databaseId"'); + } + + if (typeof collectionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "collectionId"'); + } + + if (typeof documentId === 'undefined') { + throw new AppwriteException('Missing required parameter: "documentId"'); + } + + let path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('delete', uri, { + 'content-type': 'application/json', + }, payload); + } }; diff --git a/src/services/functions.ts b/src/services/functions.ts index fdd963a..d166636 100644 --- a/src/services/functions.ts +++ b/src/services/functions.ts @@ -10,101 +10,101 @@ export class Functions extends Service { super(client); } - /** - * List Executions - * - * Get a list of all the current user function execution logs. You can use the - * query params to filter your results. - * - * @param {string} functionId - * @param {string[]} queries - * @param {string} search - * @throws {AppwriteException} - * @returns {Promise} - */ - async listExecutions(functionId: string, queries?: string[], search?: string): Promise { - if (typeof functionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "functionId"'); - } - - let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); - let payload: Payload = {}; - - if (typeof queries !== 'undefined') { - payload['queries'] = queries; - } - - if (typeof search !== 'undefined') { - payload['search'] = search; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); + /** + * List Executions + * + * Get a list of all the current user function execution logs. You can use the + * query params to filter your results. + * + * @param {string} functionId + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + async listExecutions(functionId: string, queries?: string[], search?: string): Promise { + if (typeof functionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "functionId"'); } - /** - * Create Execution - * - * Trigger a function execution. The returned object will return you the - * current execution status. You can ping the `Get Execution` endpoint to get - * updates on the current execution status. Once this endpoint is called, your - * function execution process will start asynchronously. - * - * @param {string} functionId - * @param {string} data - * @param {boolean} async - * @throws {AppwriteException} - * @returns {Promise} - */ - async createExecution(functionId: string, data?: string, async?: boolean): Promise { - if (typeof functionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "functionId"'); - } - - let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); - let payload: Payload = {}; - - if (typeof data !== 'undefined') { - payload['data'] = data; - } - - if (typeof async !== 'undefined') { - payload['async'] = async; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); + let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); + let payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + if (typeof search !== 'undefined') { + payload['search'] = search; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Execution + * + * Trigger a function execution. The returned object will return you the + * current execution status. You can ping the `Get Execution` endpoint to get + * updates on the current execution status. Once this endpoint is called, your + * function execution process will start asynchronously. + * + * @param {string} functionId + * @param {string} data + * @param {boolean} async + * @throws {AppwriteException} + * @returns {Promise} + */ + async createExecution(functionId: string, data?: string, async?: boolean): Promise { + if (typeof functionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "functionId"'); + } + + let path = '/functions/{functionId}/executions'.replace('{functionId}', functionId); + let payload: Payload = {}; + + if (typeof data !== 'undefined') { + payload['data'] = data; + } + + if (typeof async !== 'undefined') { + payload['async'] = async; } - /** - * Get Execution - * - * Get a function execution log by its unique ID. - * - * @param {string} functionId - * @param {string} executionId - * @throws {AppwriteException} - * @returns {Promise} - */ - async getExecution(functionId: string, executionId: string): Promise { - if (typeof functionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "functionId"'); - } - - if (typeof executionId === 'undefined') { - throw new AppwriteException('Missing required parameter: "executionId"'); - } - - let path = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Get Execution + * + * Get a function execution log by its unique ID. + * + * @param {string} functionId + * @param {string} executionId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getExecution(functionId: string, executionId: string): Promise { + if (typeof functionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "functionId"'); } + + if (typeof executionId === 'undefined') { + throw new AppwriteException('Missing required parameter: "executionId"'); + } + + let path = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } }; diff --git a/src/services/graphql.ts b/src/services/graphql.ts index f2b288d..f05a51c 100644 --- a/src/services/graphql.ts +++ b/src/services/graphql.ts @@ -10,59 +10,59 @@ export class Graphql extends Service { super(client); } - /** - * GraphQL Endpoint - * - * Execute a GraphQL mutation. - * - * @param {object} query - * @throws {AppwriteException} - * @returns {Promise} - */ - async query(query: object): Promise<{}> { - if (typeof query === 'undefined') { - throw new AppwriteException('Missing required parameter: "query"'); - } - - let path = '/graphql'; - let payload: Payload = {}; + /** + * GraphQL Endpoint + * + * Execute a GraphQL mutation. + * + * @param {object} query + * @throws {AppwriteException} + * @returns {Promise} + */ + async query(query: object): Promise<{}> { + if (typeof query === 'undefined') { + throw new AppwriteException('Missing required parameter: "query"'); + } - if (typeof query !== 'undefined') { - payload['query'] = query; - } + let path = '/graphql'; + let payload: Payload = {}; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }, payload); + if (typeof query !== 'undefined') { + payload['query'] = query; } - /** - * GraphQL Endpoint - * - * Execute a GraphQL mutation. - * - * @param {object} query - * @throws {AppwriteException} - * @returns {Promise} - */ - async mutation(query: object): Promise<{}> { - if (typeof query === 'undefined') { - throw new AppwriteException('Missing required parameter: "query"'); - } + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'x-sdk-graphql': 'true', + 'content-type': 'application/json', + }, payload); + } - let path = '/graphql/mutation'; - let payload: Payload = {}; + /** + * GraphQL Endpoint + * + * Execute a GraphQL mutation. + * + * @param {object} query + * @throws {AppwriteException} + * @returns {Promise} + */ + async mutation(query: object): Promise<{}> { + if (typeof query === 'undefined') { + throw new AppwriteException('Missing required parameter: "query"'); + } - if (typeof query !== 'undefined') { - payload['query'] = query; - } + let path = '/graphql/mutation'; + let payload: Payload = {}; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'x-sdk-graphql': 'true', - 'content-type': 'application/json', - }, payload); + if (typeof query !== 'undefined') { + payload['query'] = query; } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'x-sdk-graphql': 'true', + 'content-type': 'application/json', + }, payload); + } }; diff --git a/src/services/locale.ts b/src/services/locale.ts index 62a2347..438e2d0 100644 --- a/src/services/locale.ts +++ b/src/services/locale.ts @@ -10,141 +10,141 @@ export class Locale extends Service { super(client); } - /** - * Get User Locale - * - * Get the current user location based on IP. Returns an object with user - * country code, country name, continent name, continent code, ip address and - * suggested currency. You can use the locale header to get the data in a - * supported language. - * - * ([IP Geolocation by DB-IP](https://db-ip.com)) - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async get(): Promise { - let path = '/locale'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * List Continents - * - * List of all continents. You can use the locale header to get the data in a - * supported language. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async listContinents(): Promise { - let path = '/locale/continents'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * List Countries - * - * List of all countries. You can use the locale header to get the data in a - * supported language. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async listCountries(): Promise { - let path = '/locale/countries'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * List EU Countries - * - * List of all countries that are currently members of the EU. You can use the - * locale header to get the data in a supported language. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async listCountriesEU(): Promise { - let path = '/locale/countries/eu'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * List Countries Phone Codes - * - * List of all countries phone codes. You can use the locale header to get the - * data in a supported language. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async listCountriesPhones(): Promise { - let path = '/locale/countries/phones'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * List Currencies - * - * List of all currencies, including currency symbol, name, plural, and - * decimal digits for all major and minor currencies. You can use the locale - * header to get the data in a supported language. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async listCurrencies(): Promise { - let path = '/locale/currencies'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * List Languages - * - * List of all languages classified by ISO 639-1 including 2-letter code, name - * in English, and name in the respective language. - * - * @throws {AppwriteException} - * @returns {Promise} - */ - async listLanguages(): Promise { - let path = '/locale/languages'; - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } + /** + * Get User Locale + * + * Get the current user location based on IP. Returns an object with user + * country code, country name, continent name, continent code, ip address and + * suggested currency. You can use the locale header to get the data in a + * supported language. + * + * ([IP Geolocation by DB-IP](https://db-ip.com)) + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async get(): Promise { + let path = '/locale'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List Continents + * + * List of all continents. You can use the locale header to get the data in a + * supported language. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async listContinents(): Promise { + let path = '/locale/continents'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List Countries + * + * List of all countries. You can use the locale header to get the data in a + * supported language. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async listCountries(): Promise { + let path = '/locale/countries'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List EU Countries + * + * List of all countries that are currently members of the EU. You can use the + * locale header to get the data in a supported language. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async listCountriesEU(): Promise { + let path = '/locale/countries/eu'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List Countries Phone Codes + * + * List of all countries phone codes. You can use the locale header to get the + * data in a supported language. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async listCountriesPhones(): Promise { + let path = '/locale/countries/phones'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List Currencies + * + * List of all currencies, including currency symbol, name, plural, and + * decimal digits for all major and minor currencies. You can use the locale + * header to get the data in a supported language. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async listCurrencies(): Promise { + let path = '/locale/currencies'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List Languages + * + * List of all languages classified by ISO 639-1 including 2-letter code, name + * in English, and name in the respective language. + * + * @throws {AppwriteException} + * @returns {Promise} + */ + async listLanguages(): Promise { + let path = '/locale/languages'; + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } }; diff --git a/src/services/storage.ts b/src/services/storage.ts index 89f88ff..07e2da9 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -10,409 +10,409 @@ export class Storage extends Service { super(client); } - /** - * List Files - * - * Get a list of all the user files. You can use the query params to filter - * your results. - * - * @param {string} bucketId - * @param {string[]} queries - * @param {string} search - * @throws {AppwriteException} - * @returns {Promise} - */ - async listFiles(bucketId: string, queries?: string[], search?: string): Promise { - if (typeof bucketId === 'undefined') { - throw new AppwriteException('Missing required parameter: "bucketId"'); - } - - let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); - let payload: Payload = {}; - - if (typeof queries !== 'undefined') { - payload['queries'] = queries; - } + /** + * List Files + * + * Get a list of all the user files. You can use the query params to filter + * your results. + * + * @param {string} bucketId + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + async listFiles(bucketId: string, queries?: string[], search?: string): Promise { + if (typeof bucketId === 'undefined') { + throw new AppwriteException('Missing required parameter: "bucketId"'); + } - if (typeof search !== 'undefined') { - payload['search'] = search; - } + let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); + let payload: Payload = {}; - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } - /** - * Create File - * - * Create a new file. Before using this route, you should create a new bucket - * resource using either a [server - * 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) - * header to send a partial request with a maximum supported chunk of `5MB`. - * The `content-range` header values should always be in bytes. - * - * When the first request is sent, the server will return the **File** object, - * and the subsequent part request must include the file's **id** in - * `x-appwrite-id` header to allow the server to know that the partial upload - * is for the existing file and not for a new one. - * - * If you're creating a new file using one of the Appwrite SDKs, all the - * chunking logic will be managed by the SDK internally. - * - * - * @param {string} bucketId - * @param {string} fileId - * @param {File} file - * @param {string[]} permissions - * @throws {AppwriteException} - * @returns {Promise} - */ - async createFile(bucketId: string, fileId: string, file: File, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise { - if (typeof bucketId === 'undefined') { - throw new AppwriteException('Missing required parameter: "bucketId"'); - } + if (typeof search !== 'undefined') { + payload['search'] = search; + } - if (typeof fileId === 'undefined') { - throw new AppwriteException('Missing required parameter: "fileId"'); - } + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create File + * + * Create a new file. Before using this route, you should create a new bucket + * resource using either a [server + * 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) + * header to send a partial request with a maximum supported chunk of `5MB`. + * The `content-range` header values should always be in bytes. + * + * When the first request is sent, the server will return the **File** object, + * and the subsequent part request must include the file's **id** in + * `x-appwrite-id` header to allow the server to know that the partial upload + * is for the existing file and not for a new one. + * + * If you're creating a new file using one of the Appwrite SDKs, all the + * chunking logic will be managed by the SDK internally. + * + * + * @param {string} bucketId + * @param {string} fileId + * @param {File} file + * @param {string[]} permissions + * @throws {AppwriteException} + * @returns {Promise} + */ + async createFile(bucketId: string, fileId: string, file: File, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise { + if (typeof bucketId === 'undefined') { + throw new AppwriteException('Missing required parameter: "bucketId"'); + } - if (typeof file === 'undefined') { - throw new AppwriteException('Missing required parameter: "file"'); - } + if (typeof fileId === 'undefined') { + throw new AppwriteException('Missing required parameter: "fileId"'); + } - let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); - let payload: Payload = {}; + if (typeof file === 'undefined') { + throw new AppwriteException('Missing required parameter: "file"'); + } - if (typeof fileId !== 'undefined') { - payload['fileId'] = fileId; - } + let path = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); + let payload: Payload = {}; - if (typeof file !== 'undefined') { - payload['file'] = file; - } + if (typeof fileId !== 'undefined') { + payload['fileId'] = fileId; + } - if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; - } + if (typeof file !== 'undefined') { + payload['file'] = file; + } - const uri = new URL(this.client.config.endpoint + path); + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; + } - if(!(file instanceof File)) { - throw new AppwriteException('Parameter "file" has to be a File.'); - } + const uri = new URL(this.client.config.endpoint + path); - const size = file.size; + if(!(file instanceof File)) { + throw new AppwriteException('Parameter "file" has to be a File.'); + } - if (size <= Service.CHUNK_SIZE) { - return await this.client.call('post', uri, { + const size = file.size; - 'content-type': 'multipart/form-data', - }, payload); - } - let id = undefined; - let response = undefined; + if (size <= Service.CHUNK_SIZE) { + return await this.client.call('post', uri, { - const headers: { [header: string]: string } = { 'content-type': 'multipart/form-data', - } - - let counter = 0; - const totalCounters = Math.ceil(size / Service.CHUNK_SIZE); - if(fileId != 'unique()') { - try { - response = await this.client.call('GET', new URL(this.client.config.endpoint + path + '/' + fileId), headers); - counter = response.chunksUploaded; - } catch(e) { - } - } + }, payload); + } + let id = undefined; + let response = undefined; - for (counter; counter < totalCounters; counter++) { - const start = (counter * Service.CHUNK_SIZE); - const end = Math.min((((counter * Service.CHUNK_SIZE) + Service.CHUNK_SIZE) - 1), size); + const headers: { [header: string]: string } = { + 'content-type': 'multipart/form-data', + } - headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size + let counter = 0; + const totalCounters = Math.ceil(size / Service.CHUNK_SIZE); + if(fileId != 'unique()') { + try { + response = await this.client.call('GET', new URL(this.client.config.endpoint + path + '/' + fileId), headers); + counter = response.chunksUploaded; + } catch(e) { + } + } - if (id) { - headers['x-appwrite-id'] = id; - } + for (counter; counter < totalCounters; counter++) { + const start = (counter * Service.CHUNK_SIZE); + const end = Math.min((((counter * Service.CHUNK_SIZE) + Service.CHUNK_SIZE) - 1), size); - const stream = file.slice(start, end + 1); - payload['file'] = new File([stream], file.name); + headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size - response = await this.client.call('post', uri, headers, payload); + if (id) { + headers['x-appwrite-id'] = id; + } - if (!id) { - id = response['$id']; - } + const stream = file.slice(start, end + 1); + payload['file'] = new File([stream], file.name); - if (onProgress) { - onProgress({ - $id: response.$id, - progress: Math.min((counter + 1) * Service.CHUNK_SIZE - 1, size) / size * 100, - sizeUploaded: end, - chunksTotal: response.chunksTotal, - chunksUploaded: response.chunksUploaded - }); - } - } + response = await this.client.call('post', uri, headers, payload); - return response; - } - - /** - * Get File - * - * Get a file by its unique ID. This endpoint response returns a JSON object - * with the file metadata. - * - * @param {string} bucketId - * @param {string} fileId - * @throws {AppwriteException} - * @returns {Promise} - */ - async getFile(bucketId: string, fileId: string): Promise { - if (typeof bucketId === 'undefined') { - throw new AppwriteException('Missing required parameter: "bucketId"'); + if (!id) { + id = response['$id']; } - if (typeof fileId === 'undefined') { - throw new AppwriteException('Missing required parameter: "fileId"'); + if (onProgress) { + onProgress({ + $id: response.$id, + progress: Math.min((counter + 1) * Service.CHUNK_SIZE - 1, size) / size * 100, + sizeUploaded: end, + chunksTotal: response.chunksTotal, + chunksUploaded: response.chunksUploaded + }); } - - let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); } - /** - * Update File - * - * Update a file by its unique ID. Only users with write permissions have - * access to update this resource. - * - * @param {string} bucketId - * @param {string} fileId - * @param {string[]} permissions - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateFile(bucketId: string, fileId: string, permissions?: string[]): Promise { - if (typeof bucketId === 'undefined') { - throw new AppwriteException('Missing required parameter: "bucketId"'); - } - - if (typeof fileId === 'undefined') { - throw new AppwriteException('Missing required parameter: "fileId"'); - } + return response; + } + + /** + * Get File + * + * Get a file by its unique ID. This endpoint response returns a JSON object + * with the file metadata. + * + * @param {string} bucketId + * @param {string} fileId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getFile(bucketId: string, fileId: string): Promise { + if (typeof bucketId === 'undefined') { + throw new AppwriteException('Missing required parameter: "bucketId"'); + } - let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload: Payload = {}; + if (typeof fileId === 'undefined') { + throw new AppwriteException('Missing required parameter: "fileId"'); + } - if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; - } + let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update File + * + * Update a file by its unique ID. Only users with write permissions have + * access to update this resource. + * + * @param {string} bucketId + * @param {string} fileId + * @param {string[]} permissions + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateFile(bucketId: string, fileId: string, permissions?: string[]): Promise { + if (typeof bucketId === 'undefined') { + throw new AppwriteException('Missing required parameter: "bucketId"'); + } - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('put', uri, { - 'content-type': 'application/json', - }, payload); + if (typeof fileId === 'undefined') { + throw new AppwriteException('Missing required parameter: "fileId"'); } - /** - * Delete File - * - * Delete a file by its unique ID. Only users with write permissions have - * access to delete this resource. - * - * @param {string} bucketId - * @param {string} fileId - * @throws {AppwriteException} - * @returns {Promise} - */ - async deleteFile(bucketId: string, fileId: string): Promise<{}> { - if (typeof bucketId === 'undefined') { - throw new AppwriteException('Missing required parameter: "bucketId"'); - } + let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload: Payload = {}; - if (typeof fileId === 'undefined') { - throw new AppwriteException('Missing required parameter: "fileId"'); - } + if (typeof permissions !== 'undefined') { + payload['permissions'] = permissions; + } - let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload: Payload = {}; + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('put', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Delete File + * + * Delete a file by its unique ID. Only users with write permissions have + * access to delete this resource. + * + * @param {string} bucketId + * @param {string} fileId + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteFile(bucketId: string, fileId: string): Promise<{}> { + if (typeof bucketId === 'undefined') { + throw new AppwriteException('Missing required parameter: "bucketId"'); + } - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('delete', uri, { - 'content-type': 'application/json', - }, payload); + if (typeof fileId === 'undefined') { + throw new AppwriteException('Missing required parameter: "fileId"'); } - /** - * Get File for Download - * - * Get a file content by its unique ID. The endpoint response return with a - * 'Content-Disposition: attachment' header that tells the browser to start - * downloading the file to user downloads directory. - * - * @param {string} bucketId - * @param {string} fileId - * @throws {AppwriteException} - * @returns {URL} - */ - getFileDownload(bucketId: string, fileId: string): URL { - if (typeof bucketId === 'undefined') { - throw new AppwriteException('Missing required parameter: "bucketId"'); - } + let path = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('delete', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Get File for Download + * + * Get a file content by its unique ID. The endpoint response return with a + * 'Content-Disposition: attachment' header that tells the browser to start + * downloading the file to user downloads directory. + * + * @param {string} bucketId + * @param {string} fileId + * @throws {AppwriteException} + * @returns {URL} + */ + getFileDownload(bucketId: string, fileId: string): URL { + if (typeof bucketId === 'undefined') { + throw new AppwriteException('Missing required parameter: "bucketId"'); + } - if (typeof fileId === 'undefined') { - throw new AppwriteException('Missing required parameter: "fileId"'); - } + if (typeof fileId === 'undefined') { + throw new AppwriteException('Missing required parameter: "fileId"'); + } - let path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload: Payload = {}; + let path = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload: Payload = {}; - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; - } - - /** - * Get File Preview - * - * Get a file preview image. Currently, this method supports preview for image - * files (jpg, png, and gif), other supported formats, like pdf, docs, slides, - * and spreadsheets, will return the file icon image. You can also pass query - * string arguments for cutting and resizing your preview image. Preview is - * supported only for image files smaller than 10MB. - * - * @param {string} bucketId - * @param {string} fileId - * @param {number} width - * @param {number} height - * @param {string} gravity - * @param {number} quality - * @param {number} borderWidth - * @param {string} borderColor - * @param {number} borderRadius - * @param {number} opacity - * @param {number} rotation - * @param {string} background - * @param {string} output - * @throws {AppwriteException} - * @returns {URL} - */ - getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: string, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: string): URL { - if (typeof bucketId === 'undefined') { - throw new AppwriteException('Missing required parameter: "bucketId"'); - } + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + return uri; + } + + /** + * Get File Preview + * + * Get a file preview image. Currently, this method supports preview for image + * files (jpg, png, and gif), other supported formats, like pdf, docs, slides, + * and spreadsheets, will return the file icon image. You can also pass query + * string arguments for cutting and resizing your preview image. Preview is + * supported only for image files smaller than 10MB. + * + * @param {string} bucketId + * @param {string} fileId + * @param {number} width + * @param {number} height + * @param {string} gravity + * @param {number} quality + * @param {number} borderWidth + * @param {string} borderColor + * @param {number} borderRadius + * @param {number} opacity + * @param {number} rotation + * @param {string} background + * @param {string} output + * @throws {AppwriteException} + * @returns {URL} + */ + getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: string, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: string): URL { + if (typeof bucketId === 'undefined') { + throw new AppwriteException('Missing required parameter: "bucketId"'); + } - if (typeof fileId === 'undefined') { - throw new AppwriteException('Missing required parameter: "fileId"'); - } + if (typeof fileId === 'undefined') { + throw new AppwriteException('Missing required parameter: "fileId"'); + } - let path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload: Payload = {}; + let path = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload: Payload = {}; - if (typeof width !== 'undefined') { - payload['width'] = width; - } + if (typeof width !== 'undefined') { + payload['width'] = width; + } - if (typeof height !== 'undefined') { - payload['height'] = height; - } + if (typeof height !== 'undefined') { + payload['height'] = height; + } - if (typeof gravity !== 'undefined') { - payload['gravity'] = gravity; - } + if (typeof gravity !== 'undefined') { + payload['gravity'] = gravity; + } - if (typeof quality !== 'undefined') { - payload['quality'] = quality; - } + if (typeof quality !== 'undefined') { + payload['quality'] = quality; + } - if (typeof borderWidth !== 'undefined') { - payload['borderWidth'] = borderWidth; - } + if (typeof borderWidth !== 'undefined') { + payload['borderWidth'] = borderWidth; + } - if (typeof borderColor !== 'undefined') { - payload['borderColor'] = borderColor; - } + if (typeof borderColor !== 'undefined') { + payload['borderColor'] = borderColor; + } - if (typeof borderRadius !== 'undefined') { - payload['borderRadius'] = borderRadius; - } + if (typeof borderRadius !== 'undefined') { + payload['borderRadius'] = borderRadius; + } - if (typeof opacity !== 'undefined') { - payload['opacity'] = opacity; - } + if (typeof opacity !== 'undefined') { + payload['opacity'] = opacity; + } - if (typeof rotation !== 'undefined') { - payload['rotation'] = rotation; - } + if (typeof rotation !== 'undefined') { + payload['rotation'] = rotation; + } - if (typeof background !== 'undefined') { - payload['background'] = background; - } + if (typeof background !== 'undefined') { + payload['background'] = background; + } - if (typeof output !== 'undefined') { - payload['output'] = output; - } + if (typeof output !== 'undefined') { + payload['output'] = output; + } - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; - } - - /** - * Get File for View - * - * Get a file content by its unique ID. This endpoint is similar to the - * download method but returns with no 'Content-Disposition: attachment' - * header. - * - * @param {string} bucketId - * @param {string} fileId - * @throws {AppwriteException} - * @returns {URL} - */ - getFileView(bucketId: string, fileId: string): URL { - if (typeof bucketId === 'undefined') { - throw new AppwriteException('Missing required parameter: "bucketId"'); - } + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); + } + return uri; + } + + /** + * Get File for View + * + * Get a file content by its unique ID. This endpoint is similar to the + * download method but returns with no 'Content-Disposition: attachment' + * header. + * + * @param {string} bucketId + * @param {string} fileId + * @throws {AppwriteException} + * @returns {URL} + */ + getFileView(bucketId: string, fileId: string): URL { + if (typeof bucketId === 'undefined') { + throw new AppwriteException('Missing required parameter: "bucketId"'); + } - if (typeof fileId === 'undefined') { - throw new AppwriteException('Missing required parameter: "fileId"'); - } + if (typeof fileId === 'undefined') { + throw new AppwriteException('Missing required parameter: "fileId"'); + } - let path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - let payload: Payload = {}; + let path = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); + let payload: Payload = {}; - const uri = new URL(this.client.config.endpoint + path); - payload['project'] = this.client.config.project; + const uri = new URL(this.client.config.endpoint + path); + payload['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { - uri.searchParams.append(key, value); - } - return uri; + for (const [key, value] of Object.entries(Service.flatten(payload))) { + uri.searchParams.append(key, value); } + return uri; + } }; diff --git a/src/services/teams.ts b/src/services/teams.ts index 9f9b6c1..b8525d1 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -10,478 +10,478 @@ export class Teams extends Service { super(client); } - /** - * List Teams - * - * Get a list of all the teams in which the current user is a member. You can - * use the parameters to filter your results. - * - * @param {string[]} queries - * @param {string} search - * @throws {AppwriteException} - * @returns {Promise} - */ - async list(queries?: string[], search?: string): Promise> { - let path = '/teams'; - let payload: Payload = {}; - - if (typeof queries !== 'undefined') { - payload['queries'] = queries; - } - - if (typeof search !== 'undefined') { - payload['search'] = search; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Team - * - * Create a new team. The user who creates the team will automatically be - * assigned as the owner of the team. Only the users with the owner role can - * invite new members, add new owners and delete or update the team. - * - * @param {string} teamId - * @param {string} name - * @param {string[]} roles - * @throws {AppwriteException} - * @returns {Promise} - */ - async create(teamId: string, name: string, roles?: string[]): Promise> { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - if (typeof name === 'undefined') { - throw new AppwriteException('Missing required parameter: "name"'); - } - - let path = '/teams'; - let payload: Payload = {}; - - if (typeof teamId !== 'undefined') { - payload['teamId'] = teamId; - } - - if (typeof name !== 'undefined') { - payload['name'] = name; - } - - if (typeof roles !== 'undefined') { - payload['roles'] = roles; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Get Team - * - * Get a team by its ID. All team members have read access for this resource. - * - * @param {string} teamId - * @throws {AppwriteException} - * @returns {Promise} - */ - async get(teamId: string): Promise> { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - let path = '/teams/{teamId}'.replace('{teamId}', teamId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Name - * - * Update the team's name by its unique ID. - * - * @param {string} teamId - * @param {string} name - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateName(teamId: string, name: string): Promise> { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - if (typeof name === 'undefined') { - throw new AppwriteException('Missing required parameter: "name"'); - } - - let path = '/teams/{teamId}'.replace('{teamId}', teamId); - let payload: Payload = {}; - - if (typeof name !== 'undefined') { - payload['name'] = name; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('put', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Delete Team - * - * Delete a team using its ID. Only team members with the owner role can - * delete the team. - * - * @param {string} teamId - * @throws {AppwriteException} - * @returns {Promise} - */ - async delete(teamId: string): Promise<{}> { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - let path = '/teams/{teamId}'.replace('{teamId}', teamId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('delete', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * List Team Memberships - * - * Use this endpoint to list a team's members using the team's ID. All team - * members have read access to this endpoint. - * - * @param {string} teamId - * @param {string[]} queries - * @param {string} search - * @throws {AppwriteException} - * @returns {Promise} - */ - async listMemberships(teamId: string, queries?: string[], search?: string): Promise { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - let path = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); - let payload: Payload = {}; - - if (typeof queries !== 'undefined') { - payload['queries'] = queries; - } - - if (typeof search !== 'undefined') { - payload['search'] = search; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Create Team Membership - * - * Invite a new member to join your team. Provide an ID for existing users, or - * invite unregistered users using an email or phone number. If initiated from - * a Client SDK, Appwrite will send an email or sms with a link to join the - * team to the invited user, and an account will be created for them if one - * doesn't exist. If initiated from a Server SDK, the new member will be added - * automatically to the team. - * - * You only need to provide one of a user ID, email, or phone number. Appwrite - * will prioritize accepting the user ID > email > phone number if you provide - * more than one of these parameters. - * - * Use the `url` parameter to redirect the user from the invitation email to - * your app. After the user is redirected, use the [Update Team Membership - * Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow - * the user to accept the invitation to the team. - * - * Please note that to avoid a [Redirect - * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) - * Appwrite will accept the only redirect URLs under the domains you have - * added as a platform on the Appwrite Console. - * - * - * @param {string} teamId - * @param {string[]} roles - * @param {string} url - * @param {string} email - * @param {string} userId - * @param {string} phone - * @param {string} name - * @throws {AppwriteException} - * @returns {Promise} - */ - async createMembership(teamId: string, roles: string[], url: string, email?: string, userId?: string, phone?: string, name?: string): Promise { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - if (typeof roles === 'undefined') { - throw new AppwriteException('Missing required parameter: "roles"'); - } - - if (typeof url === 'undefined') { - throw new AppwriteException('Missing required parameter: "url"'); - } - - let path = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); - let payload: Payload = {}; - - if (typeof email !== 'undefined') { - payload['email'] = email; - } - - if (typeof userId !== 'undefined') { - payload['userId'] = userId; - } - - if (typeof phone !== 'undefined') { - payload['phone'] = phone; - } - - if (typeof roles !== 'undefined') { - payload['roles'] = roles; - } - - if (typeof url !== 'undefined') { - payload['url'] = url; - } - - if (typeof name !== 'undefined') { - payload['name'] = name; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Get Team Membership - * - * Get a team member by the membership unique id. All team members have read - * access for this resource. - * - * @param {string} teamId - * @param {string} membershipId - * @throws {AppwriteException} - * @returns {Promise} - */ - async getMembership(teamId: string, membershipId: string): Promise { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - if (typeof membershipId === 'undefined') { - throw new AppwriteException('Missing required parameter: "membershipId"'); - } - - let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Membership Roles - * - * Modify the roles of a team member. Only team members with the owner role - * have access to this endpoint. Learn more about [roles and - * permissions](/docs/permissions). - * - * @param {string} teamId - * @param {string} membershipId - * @param {string[]} roles - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateMembershipRoles(teamId: string, membershipId: string, roles: string[]): Promise { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - if (typeof membershipId === 'undefined') { - throw new AppwriteException('Missing required parameter: "membershipId"'); - } - - if (typeof roles === 'undefined') { - throw new AppwriteException('Missing required parameter: "roles"'); - } - - let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - let payload: Payload = {}; - - if (typeof roles !== 'undefined') { - payload['roles'] = roles; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Delete Team Membership - * - * This endpoint allows a user to leave a team or for a team owner to delete - * the membership of any other team member. You can also use this endpoint to - * delete a user membership even if it is not accepted. - * - * @param {string} teamId - * @param {string} membershipId - * @throws {AppwriteException} - * @returns {Promise} - */ - async deleteMembership(teamId: string, membershipId: string): Promise<{}> { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - if (typeof membershipId === 'undefined') { - throw new AppwriteException('Missing required parameter: "membershipId"'); - } - - let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('delete', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Team Membership Status - * - * Use this endpoint to allow a user to accept an invitation to join a team - * after being redirected back to your app from the invitation email received - * by the user. - * - * If the request is successful, a session for the user is automatically - * created. - * - * - * @param {string} teamId - * @param {string} membershipId - * @param {string} userId - * @param {string} secret - * @throws {AppwriteException} - * @returns {Promise} - */ - async updateMembershipStatus(teamId: string, membershipId: string, userId: string, secret: string): Promise { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - if (typeof membershipId === 'undefined') { - throw new AppwriteException('Missing required parameter: "membershipId"'); - } - - if (typeof userId === 'undefined') { - throw new AppwriteException('Missing required parameter: "userId"'); - } - - if (typeof secret === 'undefined') { - throw new AppwriteException('Missing required parameter: "secret"'); - } - - let path = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - let payload: Payload = {}; - - if (typeof userId !== 'undefined') { - payload['userId'] = userId; - } - - if (typeof secret !== 'undefined') { - payload['secret'] = secret; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('patch', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Get Team Preferences - * - * Get the team's shared preferences by its unique ID. If a preference doesn't - * need to be shared by all team members, prefer storing them in [user - * preferences](/docs/client/account#accountGetPrefs). - * - * @param {string} teamId - * @throws {AppwriteException} - * @returns {Promise} - */ - async getPrefs(teamId: string): Promise { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - let path = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); - let payload: Payload = {}; - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('get', uri, { - 'content-type': 'application/json', - }, payload); - } - - /** - * Update Preferences - * - * Update the team's preferences by its unique ID. The object you pass is - * stored as is and replaces any previous value. The maximum allowed prefs - * size is 64kB and throws an error if exceeded. - * - * @param {string} teamId - * @param {object} prefs - * @throws {AppwriteException} - * @returns {Promise} - */ - async updatePrefs(teamId: string, prefs: object): Promise { - if (typeof teamId === 'undefined') { - throw new AppwriteException('Missing required parameter: "teamId"'); - } - - if (typeof prefs === 'undefined') { - throw new AppwriteException('Missing required parameter: "prefs"'); - } - - let path = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); - let payload: Payload = {}; - - if (typeof prefs !== 'undefined') { - payload['prefs'] = prefs; - } - - const uri = new URL(this.client.config.endpoint + path); - return await this.client.call('put', uri, { - 'content-type': 'application/json', - }, payload); + /** + * List Teams + * + * Get a list of all the teams in which the current user is a member. You can + * use the parameters to filter your results. + * + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + async list(queries?: string[], search?: string): Promise> { + let path = '/teams'; + let payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; } + + if (typeof search !== 'undefined') { + payload['search'] = search; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Team + * + * Create a new team. The user who creates the team will automatically be + * assigned as the owner of the team. Only the users with the owner role can + * invite new members, add new owners and delete or update the team. + * + * @param {string} teamId + * @param {string} name + * @param {string[]} roles + * @throws {AppwriteException} + * @returns {Promise} + */ + async create(teamId: string, name: string, roles?: string[]): Promise> { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + let path = '/teams'; + let payload: Payload = {}; + + if (typeof teamId !== 'undefined') { + payload['teamId'] = teamId; + } + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + if (typeof roles !== 'undefined') { + payload['roles'] = roles; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Get Team + * + * Get a team by its ID. All team members have read access for this resource. + * + * @param {string} teamId + * @throws {AppwriteException} + * @returns {Promise} + */ + async get(teamId: string): Promise> { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + let path = '/teams/{teamId}'.replace('{teamId}', teamId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Name + * + * Update the team's name by its unique ID. + * + * @param {string} teamId + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateName(teamId: string, name: string): Promise> { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + if (typeof name === 'undefined') { + throw new AppwriteException('Missing required parameter: "name"'); + } + + let path = '/teams/{teamId}'.replace('{teamId}', teamId); + let payload: Payload = {}; + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('put', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Delete Team + * + * Delete a team using its ID. Only team members with the owner role can + * delete the team. + * + * @param {string} teamId + * @throws {AppwriteException} + * @returns {Promise} + */ + async delete(teamId: string): Promise<{}> { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + let path = '/teams/{teamId}'.replace('{teamId}', teamId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('delete', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * List Team Memberships + * + * Use this endpoint to list a team's members using the team's ID. All team + * members have read access to this endpoint. + * + * @param {string} teamId + * @param {string[]} queries + * @param {string} search + * @throws {AppwriteException} + * @returns {Promise} + */ + async listMemberships(teamId: string, queries?: string[], search?: string): Promise { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + let path = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); + let payload: Payload = {}; + + if (typeof queries !== 'undefined') { + payload['queries'] = queries; + } + + if (typeof search !== 'undefined') { + payload['search'] = search; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Create Team Membership + * + * Invite a new member to join your team. Provide an ID for existing users, or + * invite unregistered users using an email or phone number. If initiated from + * a Client SDK, Appwrite will send an email or sms with a link to join the + * team to the invited user, and an account will be created for them if one + * doesn't exist. If initiated from a Server SDK, the new member will be added + * automatically to the team. + * + * You only need to provide one of a user ID, email, or phone number. Appwrite + * will prioritize accepting the user ID > email > phone number if you provide + * more than one of these parameters. + * + * Use the `url` parameter to redirect the user from the invitation email to + * your app. After the user is redirected, use the [Update Team Membership + * Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow + * the user to accept the invitation to the team. + * + * Please note that to avoid a [Redirect + * Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) + * Appwrite will accept the only redirect URLs under the domains you have + * added as a platform on the Appwrite Console. + * + * + * @param {string} teamId + * @param {string[]} roles + * @param {string} url + * @param {string} email + * @param {string} userId + * @param {string} phone + * @param {string} name + * @throws {AppwriteException} + * @returns {Promise} + */ + async createMembership(teamId: string, roles: string[], url: string, email?: string, userId?: string, phone?: string, name?: string): Promise { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + if (typeof roles === 'undefined') { + throw new AppwriteException('Missing required parameter: "roles"'); + } + + if (typeof url === 'undefined') { + throw new AppwriteException('Missing required parameter: "url"'); + } + + let path = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); + let payload: Payload = {}; + + if (typeof email !== 'undefined') { + payload['email'] = email; + } + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof phone !== 'undefined') { + payload['phone'] = phone; + } + + if (typeof roles !== 'undefined') { + payload['roles'] = roles; + } + + if (typeof url !== 'undefined') { + payload['url'] = url; + } + + if (typeof name !== 'undefined') { + payload['name'] = name; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('post', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Get Team Membership + * + * Get a team member by the membership unique id. All team members have read + * access for this resource. + * + * @param {string} teamId + * @param {string} membershipId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getMembership(teamId: string, membershipId: string): Promise { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + if (typeof membershipId === 'undefined') { + throw new AppwriteException('Missing required parameter: "membershipId"'); + } + + let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Membership Roles + * + * Modify the roles of a team member. Only team members with the owner role + * have access to this endpoint. Learn more about [roles and + * permissions](/docs/permissions). + * + * @param {string} teamId + * @param {string} membershipId + * @param {string[]} roles + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMembershipRoles(teamId: string, membershipId: string, roles: string[]): Promise { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + if (typeof membershipId === 'undefined') { + throw new AppwriteException('Missing required parameter: "membershipId"'); + } + + if (typeof roles === 'undefined') { + throw new AppwriteException('Missing required parameter: "roles"'); + } + + let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + let payload: Payload = {}; + + if (typeof roles !== 'undefined') { + payload['roles'] = roles; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Delete Team Membership + * + * This endpoint allows a user to leave a team or for a team owner to delete + * the membership of any other team member. You can also use this endpoint to + * delete a user membership even if it is not accepted. + * + * @param {string} teamId + * @param {string} membershipId + * @throws {AppwriteException} + * @returns {Promise} + */ + async deleteMembership(teamId: string, membershipId: string): Promise<{}> { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + if (typeof membershipId === 'undefined') { + throw new AppwriteException('Missing required parameter: "membershipId"'); + } + + let path = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('delete', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Team Membership Status + * + * Use this endpoint to allow a user to accept an invitation to join a team + * after being redirected back to your app from the invitation email received + * by the user. + * + * If the request is successful, a session for the user is automatically + * created. + * + * + * @param {string} teamId + * @param {string} membershipId + * @param {string} userId + * @param {string} secret + * @throws {AppwriteException} + * @returns {Promise} + */ + async updateMembershipStatus(teamId: string, membershipId: string, userId: string, secret: string): Promise { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + if (typeof membershipId === 'undefined') { + throw new AppwriteException('Missing required parameter: "membershipId"'); + } + + if (typeof userId === 'undefined') { + throw new AppwriteException('Missing required parameter: "userId"'); + } + + if (typeof secret === 'undefined') { + throw new AppwriteException('Missing required parameter: "secret"'); + } + + let path = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); + let payload: Payload = {}; + + if (typeof userId !== 'undefined') { + payload['userId'] = userId; + } + + if (typeof secret !== 'undefined') { + payload['secret'] = secret; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('patch', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Get Team Preferences + * + * Get the team's shared preferences by its unique ID. If a preference doesn't + * need to be shared by all team members, prefer storing them in [user + * preferences](/docs/client/account#accountGetPrefs). + * + * @param {string} teamId + * @throws {AppwriteException} + * @returns {Promise} + */ + async getPrefs(teamId: string): Promise { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + let path = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); + let payload: Payload = {}; + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('get', uri, { + 'content-type': 'application/json', + }, payload); + } + + /** + * Update Preferences + * + * Update the team's preferences by its unique ID. The object you pass is + * stored as is and replaces any previous value. The maximum allowed prefs + * size is 64kB and throws an error if exceeded. + * + * @param {string} teamId + * @param {object} prefs + * @throws {AppwriteException} + * @returns {Promise} + */ + async updatePrefs(teamId: string, prefs: object): Promise { + if (typeof teamId === 'undefined') { + throw new AppwriteException('Missing required parameter: "teamId"'); + } + + if (typeof prefs === 'undefined') { + throw new AppwriteException('Missing required parameter: "prefs"'); + } + + let path = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); + let payload: Payload = {}; + + if (typeof prefs !== 'undefined') { + payload['prefs'] = prefs; + } + + const uri = new URL(this.client.config.endpoint + path); + return await this.client.call('put', uri, { + 'content-type': 'application/json', + }, payload); + } };