diff --git a/README.md b/README.md index 94816ac..805d737 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Appwrite React Native SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-react-native.svg?style=flat-square) -![Version](https://img.shields.io/badge/api%20version-1.5.7-blue.svg?style=flat-square) +![Version](https://img.shields.io/badge/api%20version-1.6.0-blue.svg?style=flat-square) [![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator) [![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite) [![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord) -**This SDK is compatible with Appwrite server version 1.5.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).** +**This SDK is compatible with Appwrite server version 1.6.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-react-native/releases).** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the React Native SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs) diff --git a/docs/examples/account/create-anonymous-session.md b/docs/examples/account/create-anonymous-session.md index 1c807bd..333e199 100644 --- a/docs/examples/account/create-anonymous-session.md +++ b/docs/examples/account/create-anonymous-session.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.createAnonymousSession(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-email-password-session.md b/docs/examples/account/create-email-password-session.md index d338cbe..0718e39 100644 --- a/docs/examples/account/create-email-password-session.md +++ b/docs/examples/account/create-email-password-session.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.createEmailPasswordSession( 'password' // password ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-email-token.md b/docs/examples/account/create-email-token.md index cb2a311..13d08f0 100644 --- a/docs/examples/account/create-email-token.md +++ b/docs/examples/account/create-email-token.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -12,4 +12,4 @@ const result = await account.createEmailToken( false // phrase (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-j-w-t.md b/docs/examples/account/create-j-w-t.md index 88ea31c..fd060c8 100644 --- a/docs/examples/account/create-j-w-t.md +++ b/docs/examples/account/create-j-w-t.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.createJWT(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-magic-u-r-l-token.md b/docs/examples/account/create-magic-u-r-l-token.md index f2e7e8f..b627ca6 100644 --- a/docs/examples/account/create-magic-u-r-l-token.md +++ b/docs/examples/account/create-magic-u-r-l-token.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -13,4 +13,4 @@ const result = await account.createMagicURLToken( false // phrase (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-mfa-authenticator.md b/docs/examples/account/create-mfa-authenticator.md index 88bc313..d34d995 100644 --- a/docs/examples/account/create-mfa-authenticator.md +++ b/docs/examples/account/create-mfa-authenticator.md @@ -2,7 +2,7 @@ import { Client, Account, AuthenticatorType } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.createMfaAuthenticator( AuthenticatorType.Totp // type ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-mfa-challenge.md b/docs/examples/account/create-mfa-challenge.md index 119a204..f5c9490 100644 --- a/docs/examples/account/create-mfa-challenge.md +++ b/docs/examples/account/create-mfa-challenge.md @@ -2,7 +2,7 @@ import { Client, Account, AuthenticationFactor } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.createMfaChallenge( AuthenticationFactor.Email // factor ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-mfa-recovery-codes.md b/docs/examples/account/create-mfa-recovery-codes.md index 4ffd8a3..66ec368 100644 --- a/docs/examples/account/create-mfa-recovery-codes.md +++ b/docs/examples/account/create-mfa-recovery-codes.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.createMfaRecoveryCodes(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-o-auth2session.md b/docs/examples/account/create-o-auth2session.md index 2302aaa..7dff573 100644 --- a/docs/examples/account/create-o-auth2session.md +++ b/docs/examples/account/create-o-auth2session.md @@ -2,7 +2,7 @@ import { Client, Account, OAuthProvider } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); diff --git a/docs/examples/account/create-o-auth2token.md b/docs/examples/account/create-o-auth2token.md index 3479924..85ffb2a 100644 --- a/docs/examples/account/create-o-auth2token.md +++ b/docs/examples/account/create-o-auth2token.md @@ -2,7 +2,7 @@ import { Client, Account, OAuthProvider } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); diff --git a/docs/examples/account/create-phone-token.md b/docs/examples/account/create-phone-token.md index 93fc1b7..3398888 100644 --- a/docs/examples/account/create-phone-token.md +++ b/docs/examples/account/create-phone-token.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.createPhoneToken( '+12065550100' // phone ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-phone-verification.md b/docs/examples/account/create-phone-verification.md index 28833c1..39a3313 100644 --- a/docs/examples/account/create-phone-verification.md +++ b/docs/examples/account/create-phone-verification.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.createPhoneVerification(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-push-target.md b/docs/examples/account/create-push-target.md index dd15821..da020da 100644 --- a/docs/examples/account/create-push-target.md +++ b/docs/examples/account/create-push-target.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -12,4 +12,4 @@ const result = await account.createPushTarget( '' // providerId (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-recovery.md b/docs/examples/account/create-recovery.md index 5d28554..c46c907 100644 --- a/docs/examples/account/create-recovery.md +++ b/docs/examples/account/create-recovery.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.createRecovery( 'https://example.com' // url ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-session.md b/docs/examples/account/create-session.md index f8a9f10..3c85dc8 100644 --- a/docs/examples/account/create-session.md +++ b/docs/examples/account/create-session.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.createSession( '' // secret ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create-verification.md b/docs/examples/account/create-verification.md index d072126..cce3e1a 100644 --- a/docs/examples/account/create-verification.md +++ b/docs/examples/account/create-verification.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.createVerification( 'https://example.com' // url ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/create.md b/docs/examples/account/create.md index 300f59b..5db3d7d 100644 --- a/docs/examples/account/create.md +++ b/docs/examples/account/create.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -13,4 +13,4 @@ const result = await account.create( '' // name (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/delete-identity.md b/docs/examples/account/delete-identity.md index 9ff1bbd..c25a5a4 100644 --- a/docs/examples/account/delete-identity.md +++ b/docs/examples/account/delete-identity.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.deleteIdentity( '' // identityId ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/delete-mfa-authenticator.md b/docs/examples/account/delete-mfa-authenticator.md index c5f5695..5be2b16 100644 --- a/docs/examples/account/delete-mfa-authenticator.md +++ b/docs/examples/account/delete-mfa-authenticator.md @@ -2,13 +2,12 @@ import { Client, Account, AuthenticatorType } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.deleteMfaAuthenticator( - AuthenticatorType.Totp, // type - '' // otp + AuthenticatorType.Totp // type ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/delete-push-target.md b/docs/examples/account/delete-push-target.md index 351b933..34e89ab 100644 --- a/docs/examples/account/delete-push-target.md +++ b/docs/examples/account/delete-push-target.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.deletePushTarget( '' // targetId ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/delete-session.md b/docs/examples/account/delete-session.md index 2296649..6079128 100644 --- a/docs/examples/account/delete-session.md +++ b/docs/examples/account/delete-session.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.deleteSession( '' // sessionId ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/delete-sessions.md b/docs/examples/account/delete-sessions.md index b0967bf..67652f2 100644 --- a/docs/examples/account/delete-sessions.md +++ b/docs/examples/account/delete-sessions.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.deleteSessions(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/get-mfa-recovery-codes.md b/docs/examples/account/get-mfa-recovery-codes.md index d1c38fd..06f09b8 100644 --- a/docs/examples/account/get-mfa-recovery-codes.md +++ b/docs/examples/account/get-mfa-recovery-codes.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.getMfaRecoveryCodes(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/get-prefs.md b/docs/examples/account/get-prefs.md index b2502d7..ef4185c 100644 --- a/docs/examples/account/get-prefs.md +++ b/docs/examples/account/get-prefs.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.getPrefs(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/get-session.md b/docs/examples/account/get-session.md index 3ecb79f..ca6cfb7 100644 --- a/docs/examples/account/get-session.md +++ b/docs/examples/account/get-session.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.getSession( '' // sessionId ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/get.md b/docs/examples/account/get.md index 94f0779..cd5d50f 100644 --- a/docs/examples/account/get.md +++ b/docs/examples/account/get.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.get(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/list-identities.md b/docs/examples/account/list-identities.md index e7ca637..6189f80 100644 --- a/docs/examples/account/list-identities.md +++ b/docs/examples/account/list-identities.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.listIdentities( [] // queries (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/list-logs.md b/docs/examples/account/list-logs.md index 424f8d7..48fe10b 100644 --- a/docs/examples/account/list-logs.md +++ b/docs/examples/account/list-logs.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.listLogs( [] // queries (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/list-mfa-factors.md b/docs/examples/account/list-mfa-factors.md index c6343a7..ada7d48 100644 --- a/docs/examples/account/list-mfa-factors.md +++ b/docs/examples/account/list-mfa-factors.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.listMfaFactors(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/list-sessions.md b/docs/examples/account/list-sessions.md index b0840c5..cc081d5 100644 --- a/docs/examples/account/list-sessions.md +++ b/docs/examples/account/list-sessions.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.listSessions(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-email.md b/docs/examples/account/update-email.md index 560581e..5f87998 100644 --- a/docs/examples/account/update-email.md +++ b/docs/examples/account/update-email.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updateEmail( 'password' // password ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-m-f-a.md b/docs/examples/account/update-m-f-a.md index 38fd716..30f5f64 100644 --- a/docs/examples/account/update-m-f-a.md +++ b/docs/examples/account/update-m-f-a.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.updateMFA( false // mfa ); -console.log(response); +console.log(result); 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 bb0c000..a5b9276 100644 --- a/docs/examples/account/update-magic-u-r-l-session.md +++ b/docs/examples/account/update-magic-u-r-l-session.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updateMagicURLSession( '' // secret ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-mfa-authenticator.md b/docs/examples/account/update-mfa-authenticator.md index d8ec7ae..f3f3276 100644 --- a/docs/examples/account/update-mfa-authenticator.md +++ b/docs/examples/account/update-mfa-authenticator.md @@ -2,7 +2,7 @@ import { Client, Account, AuthenticatorType } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updateMfaAuthenticator( '' // otp ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md index 7d87506..b26d387 100644 --- a/docs/examples/account/update-mfa-challenge.md +++ b/docs/examples/account/update-mfa-challenge.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updateMfaChallenge( '' // otp ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-mfa-recovery-codes.md b/docs/examples/account/update-mfa-recovery-codes.md index cfbbf6f..81d27f7 100644 --- a/docs/examples/account/update-mfa-recovery-codes.md +++ b/docs/examples/account/update-mfa-recovery-codes.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.updateMfaRecoveryCodes(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-name.md b/docs/examples/account/update-name.md index 8a403f2..47e5db9 100644 --- a/docs/examples/account/update-name.md +++ b/docs/examples/account/update-name.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.updateName( '' // name ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-password.md b/docs/examples/account/update-password.md index 09edf09..a37ee4c 100644 --- a/docs/examples/account/update-password.md +++ b/docs/examples/account/update-password.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updatePassword( 'password' // oldPassword (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-phone-session.md b/docs/examples/account/update-phone-session.md index cf02622..d7098e5 100644 --- a/docs/examples/account/update-phone-session.md +++ b/docs/examples/account/update-phone-session.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updatePhoneSession( '' // secret ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-phone-verification.md b/docs/examples/account/update-phone-verification.md index 8467309..582061f 100644 --- a/docs/examples/account/update-phone-verification.md +++ b/docs/examples/account/update-phone-verification.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updatePhoneVerification( '' // secret ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-phone.md b/docs/examples/account/update-phone.md index 46efc14..cc39c5e 100644 --- a/docs/examples/account/update-phone.md +++ b/docs/examples/account/update-phone.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updatePhone( 'password' // password ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-prefs.md b/docs/examples/account/update-prefs.md index a3ff8c3..4478e02 100644 --- a/docs/examples/account/update-prefs.md +++ b/docs/examples/account/update-prefs.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.updatePrefs( {} // prefs ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-push-target.md b/docs/examples/account/update-push-target.md index 8096568..6871a10 100644 --- a/docs/examples/account/update-push-target.md +++ b/docs/examples/account/update-push-target.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updatePushTarget( '' // identifier ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-recovery.md b/docs/examples/account/update-recovery.md index 1ee93d3..73184b8 100644 --- a/docs/examples/account/update-recovery.md +++ b/docs/examples/account/update-recovery.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -12,4 +12,4 @@ const result = await account.updateRecovery( '' // password ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-session.md b/docs/examples/account/update-session.md index 397e07e..34bc567 100644 --- a/docs/examples/account/update-session.md +++ b/docs/examples/account/update-session.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -10,4 +10,4 @@ const result = await account.updateSession( '' // sessionId ); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-status.md b/docs/examples/account/update-status.md index 27ce518..0b6ec6f 100644 --- a/docs/examples/account/update-status.md +++ b/docs/examples/account/update-status.md @@ -2,10 +2,10 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); const result = await account.updateStatus(); -console.log(response); +console.log(result); diff --git a/docs/examples/account/update-verification.md b/docs/examples/account/update-verification.md index 0007335..9d00a48 100644 --- a/docs/examples/account/update-verification.md +++ b/docs/examples/account/update-verification.md @@ -2,7 +2,7 @@ import { Client, Account } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const account = new Account(client); @@ -11,4 +11,4 @@ const result = await account.updateVerification( '' // secret ); -console.log(response); +console.log(result); diff --git a/docs/examples/avatars/get-browser.md b/docs/examples/avatars/get-browser.md index 9ceb1a3..bbcb0df 100644 --- a/docs/examples/avatars/get-browser.md +++ b/docs/examples/avatars/get-browser.md @@ -2,7 +2,7 @@ import { Client, Avatars, Browser } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const avatars = new Avatars(client); diff --git a/docs/examples/avatars/get-credit-card.md b/docs/examples/avatars/get-credit-card.md index 0de6319..a97cc6c 100644 --- a/docs/examples/avatars/get-credit-card.md +++ b/docs/examples/avatars/get-credit-card.md @@ -2,7 +2,7 @@ import { Client, Avatars, CreditCard } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const avatars = new Avatars(client); diff --git a/docs/examples/avatars/get-favicon.md b/docs/examples/avatars/get-favicon.md index 6e23a77..067aa74 100644 --- a/docs/examples/avatars/get-favicon.md +++ b/docs/examples/avatars/get-favicon.md @@ -2,7 +2,7 @@ import { Client, Avatars } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const avatars = new Avatars(client); diff --git a/docs/examples/avatars/get-flag.md b/docs/examples/avatars/get-flag.md index 6761052..f2268fc 100644 --- a/docs/examples/avatars/get-flag.md +++ b/docs/examples/avatars/get-flag.md @@ -2,7 +2,7 @@ import { Client, Avatars, Flag } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const avatars = new Avatars(client); diff --git a/docs/examples/avatars/get-image.md b/docs/examples/avatars/get-image.md index b4956df..3816e7b 100644 --- a/docs/examples/avatars/get-image.md +++ b/docs/examples/avatars/get-image.md @@ -2,7 +2,7 @@ import { Client, Avatars } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const avatars = new Avatars(client); diff --git a/docs/examples/avatars/get-initials.md b/docs/examples/avatars/get-initials.md index ba70a9c..b8545b3 100644 --- a/docs/examples/avatars/get-initials.md +++ b/docs/examples/avatars/get-initials.md @@ -2,7 +2,7 @@ import { Client, Avatars } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const avatars = new Avatars(client); diff --git a/docs/examples/avatars/get-q-r.md b/docs/examples/avatars/get-q-r.md index d4f2db2..5c80c6a 100644 --- a/docs/examples/avatars/get-q-r.md +++ b/docs/examples/avatars/get-q-r.md @@ -2,7 +2,7 @@ import { Client, Avatars } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const avatars = new Avatars(client); diff --git a/docs/examples/databases/create-document.md b/docs/examples/databases/create-document.md index 15d1afc..58053ca 100644 --- a/docs/examples/databases/create-document.md +++ b/docs/examples/databases/create-document.md @@ -2,7 +2,7 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const databases = new Databases(client); @@ -14,4 +14,4 @@ const result = await databases.createDocument( ["read("any")"] // permissions (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/databases/delete-document.md b/docs/examples/databases/delete-document.md index f6fef3b..beeb7b2 100644 --- a/docs/examples/databases/delete-document.md +++ b/docs/examples/databases/delete-document.md @@ -2,7 +2,7 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const databases = new Databases(client); @@ -12,4 +12,4 @@ const result = await databases.deleteDocument( '' // documentId ); -console.log(response); +console.log(result); diff --git a/docs/examples/databases/get-document.md b/docs/examples/databases/get-document.md index 502f2f4..df2333b 100644 --- a/docs/examples/databases/get-document.md +++ b/docs/examples/databases/get-document.md @@ -2,7 +2,7 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const databases = new Databases(client); @@ -13,4 +13,4 @@ const result = await databases.getDocument( [] // queries (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/databases/list-documents.md b/docs/examples/databases/list-documents.md index 90dcd63..88d94a9 100644 --- a/docs/examples/databases/list-documents.md +++ b/docs/examples/databases/list-documents.md @@ -2,7 +2,7 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const databases = new Databases(client); @@ -12,4 +12,4 @@ const result = await databases.listDocuments( [] // queries (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/databases/update-document.md b/docs/examples/databases/update-document.md index fa04f21..5021c0b 100644 --- a/docs/examples/databases/update-document.md +++ b/docs/examples/databases/update-document.md @@ -2,7 +2,7 @@ import { Client, Databases } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const databases = new Databases(client); @@ -14,4 +14,4 @@ const result = await databases.updateDocument( ["read("any")"] // permissions (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/functions/create-execution.md b/docs/examples/functions/create-execution.md index 1b4bfaa..db8c8f4 100644 --- a/docs/examples/functions/create-execution.md +++ b/docs/examples/functions/create-execution.md @@ -2,17 +2,18 @@ import { Client, Functions, ExecutionMethod } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const functions = new Functions(client); const result = await functions.createExecution( '', // functionId - '', // body (optional) + await pickSingle(), // body (optional) false, // async (optional) '', // path (optional) ExecutionMethod.GET, // method (optional) - {} // headers (optional) + {}, // headers (optional) + '' // scheduledAt (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/functions/get-execution.md b/docs/examples/functions/get-execution.md index adda043..79fffec 100644 --- a/docs/examples/functions/get-execution.md +++ b/docs/examples/functions/get-execution.md @@ -2,7 +2,7 @@ import { Client, Functions } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const functions = new Functions(client); @@ -11,4 +11,4 @@ const result = await functions.getExecution( '' // executionId ); -console.log(response); +console.log(result); diff --git a/docs/examples/functions/list-executions.md b/docs/examples/functions/list-executions.md index b1fdd6b..0615ecb 100644 --- a/docs/examples/functions/list-executions.md +++ b/docs/examples/functions/list-executions.md @@ -2,7 +2,7 @@ import { Client, Functions } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const functions = new Functions(client); @@ -12,4 +12,4 @@ const result = await functions.listExecutions( '' // search (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/graphql/mutation.md b/docs/examples/graphql/mutation.md index b3c3583..2fae478 100644 --- a/docs/examples/graphql/mutation.md +++ b/docs/examples/graphql/mutation.md @@ -2,7 +2,7 @@ import { Client, Graphql } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const graphql = new Graphql(client); @@ -10,4 +10,4 @@ const result = await graphql.mutation( {} // query ); -console.log(response); +console.log(result); diff --git a/docs/examples/graphql/query.md b/docs/examples/graphql/query.md index e15400d..39d8cb1 100644 --- a/docs/examples/graphql/query.md +++ b/docs/examples/graphql/query.md @@ -2,7 +2,7 @@ import { Client, Graphql } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const graphql = new Graphql(client); @@ -10,4 +10,4 @@ const result = await graphql.query( {} // query ); -console.log(response); +console.log(result); diff --git a/docs/examples/locale/get.md b/docs/examples/locale/get.md index 4af9df3..0d48cd8 100644 --- a/docs/examples/locale/get.md +++ b/docs/examples/locale/get.md @@ -2,10 +2,10 @@ import { Client, Locale } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.get(); -console.log(response); +console.log(result); diff --git a/docs/examples/locale/list-codes.md b/docs/examples/locale/list-codes.md index 8737fde..f1466be 100644 --- a/docs/examples/locale/list-codes.md +++ b/docs/examples/locale/list-codes.md @@ -2,10 +2,10 @@ import { Client, Locale } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.listCodes(); -console.log(response); +console.log(result); diff --git a/docs/examples/locale/list-continents.md b/docs/examples/locale/list-continents.md index e8c3920..a813a69 100644 --- a/docs/examples/locale/list-continents.md +++ b/docs/examples/locale/list-continents.md @@ -2,10 +2,10 @@ import { Client, Locale } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.listContinents(); -console.log(response); +console.log(result); diff --git a/docs/examples/locale/list-countries-e-u.md b/docs/examples/locale/list-countries-e-u.md index 0a2abc5..7ba7149 100644 --- a/docs/examples/locale/list-countries-e-u.md +++ b/docs/examples/locale/list-countries-e-u.md @@ -2,10 +2,10 @@ import { Client, Locale } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.listCountriesEU(); -console.log(response); +console.log(result); diff --git a/docs/examples/locale/list-countries-phones.md b/docs/examples/locale/list-countries-phones.md index d4d00ae..6d3093d 100644 --- a/docs/examples/locale/list-countries-phones.md +++ b/docs/examples/locale/list-countries-phones.md @@ -2,10 +2,10 @@ import { Client, Locale } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.listCountriesPhones(); -console.log(response); +console.log(result); diff --git a/docs/examples/locale/list-countries.md b/docs/examples/locale/list-countries.md index 8839b6f..9ffb09b 100644 --- a/docs/examples/locale/list-countries.md +++ b/docs/examples/locale/list-countries.md @@ -2,10 +2,10 @@ import { Client, Locale } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.listCountries(); -console.log(response); +console.log(result); diff --git a/docs/examples/locale/list-currencies.md b/docs/examples/locale/list-currencies.md index 6700ef1..0632665 100644 --- a/docs/examples/locale/list-currencies.md +++ b/docs/examples/locale/list-currencies.md @@ -2,10 +2,10 @@ import { Client, Locale } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.listCurrencies(); -console.log(response); +console.log(result); diff --git a/docs/examples/locale/list-languages.md b/docs/examples/locale/list-languages.md index db9b172..1ef69e5 100644 --- a/docs/examples/locale/list-languages.md +++ b/docs/examples/locale/list-languages.md @@ -2,10 +2,10 @@ import { Client, Locale } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const locale = new Locale(client); const result = await locale.listLanguages(); -console.log(response); +console.log(result); diff --git a/docs/examples/messaging/create-subscriber.md b/docs/examples/messaging/create-subscriber.md index bf5a0ce..153cd2e 100644 --- a/docs/examples/messaging/create-subscriber.md +++ b/docs/examples/messaging/create-subscriber.md @@ -2,7 +2,7 @@ import { Client, Messaging } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const messaging = new Messaging(client); @@ -12,4 +12,4 @@ const result = await messaging.createSubscriber( '' // targetId ); -console.log(response); +console.log(result); diff --git a/docs/examples/messaging/delete-subscriber.md b/docs/examples/messaging/delete-subscriber.md index da995fc..6d61172 100644 --- a/docs/examples/messaging/delete-subscriber.md +++ b/docs/examples/messaging/delete-subscriber.md @@ -2,7 +2,7 @@ import { Client, Messaging } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const messaging = new Messaging(client); @@ -11,4 +11,4 @@ const result = await messaging.deleteSubscriber( '' // subscriberId ); -console.log(response); +console.log(result); diff --git a/docs/examples/storage/create-file.md b/docs/examples/storage/create-file.md index 73908c6..f6e4f47 100644 --- a/docs/examples/storage/create-file.md +++ b/docs/examples/storage/create-file.md @@ -2,7 +2,7 @@ import { Client, Storage } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const storage = new Storage(client); @@ -13,4 +13,4 @@ const result = await storage.createFile( ["read("any")"] // permissions (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/storage/delete-file.md b/docs/examples/storage/delete-file.md index 4373ebe..55aed16 100644 --- a/docs/examples/storage/delete-file.md +++ b/docs/examples/storage/delete-file.md @@ -2,7 +2,7 @@ import { Client, Storage } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const storage = new Storage(client); @@ -11,4 +11,4 @@ const result = await storage.deleteFile( '' // fileId ); -console.log(response); +console.log(result); diff --git a/docs/examples/storage/get-file-download.md b/docs/examples/storage/get-file-download.md index 943bf9d..b4b1374 100644 --- a/docs/examples/storage/get-file-download.md +++ b/docs/examples/storage/get-file-download.md @@ -2,7 +2,7 @@ import { Client, Storage } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const storage = new Storage(client); diff --git a/docs/examples/storage/get-file-preview.md b/docs/examples/storage/get-file-preview.md index 76713c8..10d473a 100644 --- a/docs/examples/storage/get-file-preview.md +++ b/docs/examples/storage/get-file-preview.md @@ -2,7 +2,7 @@ import { Client, Storage, ImageGravity, ImageFormat } from "react-native-appwrit const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const storage = new Storage(client); diff --git a/docs/examples/storage/get-file-view.md b/docs/examples/storage/get-file-view.md index b551e02..1a54452 100644 --- a/docs/examples/storage/get-file-view.md +++ b/docs/examples/storage/get-file-view.md @@ -2,7 +2,7 @@ import { Client, Storage } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const storage = new Storage(client); diff --git a/docs/examples/storage/get-file.md b/docs/examples/storage/get-file.md index 8731c84..bbbb3fe 100644 --- a/docs/examples/storage/get-file.md +++ b/docs/examples/storage/get-file.md @@ -2,7 +2,7 @@ import { Client, Storage } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const storage = new Storage(client); @@ -11,4 +11,4 @@ const result = await storage.getFile( '' // fileId ); -console.log(response); +console.log(result); diff --git a/docs/examples/storage/list-files.md b/docs/examples/storage/list-files.md index c72b9ba..731a1d1 100644 --- a/docs/examples/storage/list-files.md +++ b/docs/examples/storage/list-files.md @@ -2,7 +2,7 @@ import { Client, Storage } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const storage = new Storage(client); @@ -12,4 +12,4 @@ const result = await storage.listFiles( '' // search (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/storage/update-file.md b/docs/examples/storage/update-file.md index 87f81ab..ba8cc60 100644 --- a/docs/examples/storage/update-file.md +++ b/docs/examples/storage/update-file.md @@ -2,7 +2,7 @@ import { Client, Storage } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const storage = new Storage(client); @@ -13,4 +13,4 @@ const result = await storage.updateFile( ["read("any")"] // permissions (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/create-membership.md b/docs/examples/teams/create-membership.md index a5d6fa0..c4fc557 100644 --- a/docs/examples/teams/create-membership.md +++ b/docs/examples/teams/create-membership.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -16,4 +16,4 @@ const result = await teams.createMembership( '' // name (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/create.md b/docs/examples/teams/create.md index f61df43..c252f3d 100644 --- a/docs/examples/teams/create.md +++ b/docs/examples/teams/create.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -12,4 +12,4 @@ const result = await teams.create( [] // roles (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/delete-membership.md b/docs/examples/teams/delete-membership.md index f5ed1bc..683c92d 100644 --- a/docs/examples/teams/delete-membership.md +++ b/docs/examples/teams/delete-membership.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -11,4 +11,4 @@ const result = await teams.deleteMembership( '' // membershipId ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/delete.md b/docs/examples/teams/delete.md index 77dac56..dfd63fc 100644 --- a/docs/examples/teams/delete.md +++ b/docs/examples/teams/delete.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -10,4 +10,4 @@ const result = await teams.delete( '' // teamId ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/get-membership.md b/docs/examples/teams/get-membership.md index 44a664c..4e30d1b 100644 --- a/docs/examples/teams/get-membership.md +++ b/docs/examples/teams/get-membership.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -11,4 +11,4 @@ const result = await teams.getMembership( '' // membershipId ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/get-prefs.md b/docs/examples/teams/get-prefs.md index 5f7cf16..40cffb1 100644 --- a/docs/examples/teams/get-prefs.md +++ b/docs/examples/teams/get-prefs.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -10,4 +10,4 @@ const result = await teams.getPrefs( '' // teamId ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/get.md b/docs/examples/teams/get.md index 28d8895..dc2d6cd 100644 --- a/docs/examples/teams/get.md +++ b/docs/examples/teams/get.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -10,4 +10,4 @@ const result = await teams.get( '' // teamId ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/list-memberships.md b/docs/examples/teams/list-memberships.md index afc2e39..7eabeee 100644 --- a/docs/examples/teams/list-memberships.md +++ b/docs/examples/teams/list-memberships.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -12,4 +12,4 @@ const result = await teams.listMemberships( '' // search (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/list.md b/docs/examples/teams/list.md index cd97431..64b9324 100644 --- a/docs/examples/teams/list.md +++ b/docs/examples/teams/list.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -11,4 +11,4 @@ const result = await teams.list( '' // search (optional) ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/update-membership-status.md b/docs/examples/teams/update-membership-status.md index 85eecb9..0e42de9 100644 --- a/docs/examples/teams/update-membership-status.md +++ b/docs/examples/teams/update-membership-status.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -13,4 +13,4 @@ const result = await teams.updateMembershipStatus( '' // secret ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/update-membership.md b/docs/examples/teams/update-membership.md index 684c40a..e22fc97 100644 --- a/docs/examples/teams/update-membership.md +++ b/docs/examples/teams/update-membership.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -12,4 +12,4 @@ const result = await teams.updateMembership( [] // roles ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/update-name.md b/docs/examples/teams/update-name.md index 75f3fda..27447af 100644 --- a/docs/examples/teams/update-name.md +++ b/docs/examples/teams/update-name.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -11,4 +11,4 @@ const result = await teams.updateName( '' // name ); -console.log(response); +console.log(result); diff --git a/docs/examples/teams/update-prefs.md b/docs/examples/teams/update-prefs.md index f9c4c21..02be2ac 100644 --- a/docs/examples/teams/update-prefs.md +++ b/docs/examples/teams/update-prefs.md @@ -2,7 +2,7 @@ import { Client, Teams } from "react-native-appwrite"; const client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint - .setProject('5df5acd0d48c2'); // Your project ID + .setProject(''); // Your project ID const teams = new Teams(client); @@ -11,4 +11,4 @@ const result = await teams.updatePrefs( {} // prefs ); -console.log(response); +console.log(result); diff --git a/package.json b/package.json index 3873c5f..6dd5634 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-appwrite", "homepage": "https://appwrite.io/support", "description": "Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API", - "version": "0.4.0", + "version": "0.6.0", "license": "BSD-3-Clause", "main": "dist/cjs/sdk.js", "exports": { @@ -26,7 +26,6 @@ }, "devDependencies": { "@rollup/plugin-typescript": "8.3.2", - "playwright": "1.15.0", "rollup": "2.75.4", "serve-handler": "6.1.0", "tslib": "2.4.0", @@ -34,6 +33,7 @@ }, "dependencies": { "expo-file-system": "16.0.8", + "parse-multipart-data": "^1.5.0", "react-native": "^0.73.6" }, "peerDependencies": { diff --git a/src/client.ts b/src/client.ts index 87e42a3..1044a2d 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,8 +1,11 @@ -import { Models } from './models'; -import { Service } from './service'; import { Platform } from 'react-native'; +import { getBoundary, parse as parseMultipart} from './multipart'; +import { Service } from './service'; +import { Payload } from './payload'; +import { Models } from './models'; + -type Payload = { +type Params = { [key: string]: any; } @@ -103,8 +106,8 @@ class Client { 'x-sdk-name': 'React Native', 'x-sdk-platform': 'client', 'x-sdk-language': 'reactnative', - 'x-sdk-version': '0.4.0', - 'X-Appwrite-Response-Format': '1.5.0', + 'x-sdk-version': '0.6.0', + 'X-Appwrite-Response-Format': '1.6.0', }; /** @@ -383,7 +386,7 @@ class Client { } } - async call(method: string, url: URL, headers: Headers = {}, params: Payload = {}): Promise { + async call(method: string, url: URL, headers: Headers = {}, params: Params = {}): Promise { method = method.toUpperCase(); headers = Object.assign({}, this.headers, headers); @@ -428,8 +431,43 @@ class Client { let data = null; const response = await fetch(url.toString(), options); + const warnings = response.headers.get('x-appwrite-warning'); + if (warnings) { + warnings.split(';').forEach((warning: string) => console.warn('Warning: ' + warning)); + } + if (response.headers.get('content-type')?.includes('application/json')) { data = await response.json(); + } else if (response.headers.get('content-type')?.includes('multipart/form-data')) { + const boundary = getBoundary( + response.headers.get("content-type") || "" + ); + + const body = new Uint8Array(await response.arrayBuffer()); + const parts = parseMultipart(body, boundary); + const partsObject: { [key: string]: any } = {}; + + for (const part of parts) { + if (!part.name) { + continue; + } + if (part.name === "responseBody") { + partsObject[part.name] = Payload.fromBinary(part.data, part.filename); + } else if (part.name === "responseStatusCode") { + partsObject[part.name] = parseInt(part.data.toString()); + } else if (part.name === "duration") { + partsObject[part.name] = parseFloat(part.data.toString()); + } else if (part.type === 'application/json') { + try { + partsObject[part.name] = JSON.parse(part.data.toString()); + } catch (e) { + throw new Error(`Error parsing JSON for part ${part.name}: ${e instanceof Error ? e.message : 'Unknown error'}`); + } + } else { + partsObject[part.name] = part.data.toString(); + } + } + data = partsObject; } else { data = { message: await response.text() @@ -458,4 +496,4 @@ class Client { } export { Client, AppwriteException }; -export type { Models, Payload }; +export type { Models, Params }; diff --git a/src/enums/image-format.ts b/src/enums/image-format.ts index 7e96fd8..8599e30 100644 --- a/src/enums/image-format.ts +++ b/src/enums/image-format.ts @@ -4,4 +4,5 @@ export enum ImageFormat { Gif = 'gif', Png = 'png', Webp = 'webp', + Avif = 'avif', } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index bbc74cc..74e230c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,12 +8,13 @@ export { Locale } from './services/locale'; export { Messaging } from './services/messaging'; export { Storage } from './services/storage'; export { Teams } from './services/teams'; -export type { Models, Payload, RealtimeResponseEvent, UploadProgress } from './client'; +export type { Models, Params, RealtimeResponseEvent, UploadProgress } from './client'; export type { QueryTypes, QueryTypesList } from './query'; export { Query } from './query'; export { Permission } from './permission'; export { Role } from './role'; export { ID } from './id'; +export { Payload } from './payload'; export { AuthenticatorType } from './enums/authenticator-type'; export { AuthenticationFactor } from './enums/authentication-factor'; export { OAuthProvider } from './enums/o-auth-provider'; diff --git a/src/models.ts b/src/models.ts index cdbd36f..b35cc1f 100644 --- a/src/models.ts +++ b/src/models.ts @@ -1,3 +1,5 @@ +import { Payload } from './payload'; + export namespace Models { /** * Documents List @@ -926,7 +928,7 @@ export namespace Models { /** * HTTP response body. This will return empty unless execution is created as synchronous. */ - responseBody: string; + responseBody: Payload; /** * HTTP response headers as a key-value object. This will return only whitelisted headers. All headers are returned if execution is created as synchronous. */ @@ -943,6 +945,10 @@ export namespace Models { * Function execution duration in seconds. */ duration: number; + /** + * The scheduled time for execution. If left empty, execution will be queued immediately. + */ + scheduledAt?: string; } /** * Country diff --git a/src/multipart.ts b/src/multipart.ts new file mode 100644 index 0000000..21ec6e3 --- /dev/null +++ b/src/multipart.ts @@ -0,0 +1,214 @@ +/** + * Port of: https://github.com/nachomazzara/parse-multipart-data/blob/master/src/multipart.ts + * Includes few changes for Deno compatibility. Textdiff should show the changes. + * Copied from master with commit 56052e860bc4e3fa7fe4763f69e88ec79b295a3c + * + * + * Multipart Parser (Finite State Machine) + * usage: + * const multipart = require('./multipart.js'); + * const body = multipart.DemoData(); // raw body + * const body = Buffer.from(event['body-json'].toString(),'base64'); // AWS case + * const boundary = multipart.getBoundary(event.params.header['content-type']); + * const parts = multipart.Parse(body,boundary); + * each part is: + * { filename: 'A.txt', type: 'text/plain', data: } + * or { name: 'key', data: } + */ + +type Part = { + contentDispositionHeader: string; + contentTypeHeader: string; + part: number[]; +}; + +type Input = { + filename?: string; + name?: string; + type: string; + data: Uint8Array; +}; + +enum ParsingState { + INIT, + READING_HEADERS, + READING_DATA, + READING_PART_SEPARATOR, +} + +export function parse( + multipartBodyBuffer: Uint8Array, + boundary: string +): Input[] { + let lastline = ""; + let contentDispositionHeader = ""; + let contentTypeHeader = ""; + let state: ParsingState = ParsingState.INIT; + let buffer: number[] = []; + const allParts: Input[] = []; + + let currentPartHeaders: string[] = []; + + for (let i = 0; i < multipartBodyBuffer.length; i++) { + const oneByte: number = multipartBodyBuffer[i]; + const prevByte: number | null = i > 0 ? multipartBodyBuffer[i - 1] : null; + // 0x0a => \n + // 0x0d => \r + const newLineDetected: boolean = oneByte === 0x0a && prevByte === 0x0d; + const newLineChar: boolean = oneByte === 0x0a || oneByte === 0x0d; + + if (!newLineChar) lastline += String.fromCharCode(oneByte); + if (ParsingState.INIT === state && newLineDetected) { + // searching for boundary + if ("--" + boundary === lastline) { + state = ParsingState.READING_HEADERS; // found boundary. start reading headers + } + lastline = ""; + } else if (ParsingState.READING_HEADERS === state && newLineDetected) { + // parsing headers. Headers are separated by an empty line from the content. Stop reading headers when the line is empty + if (lastline.length) { + currentPartHeaders.push(lastline); + } else { + // found empty line. search for the headers we want and set the values + for (const h of currentPartHeaders) { + if (h.toLowerCase().startsWith("content-disposition:")) { + contentDispositionHeader = h; + } else if (h.toLowerCase().startsWith("content-type:")) { + contentTypeHeader = h; + } + } + state = ParsingState.READING_DATA; + buffer = []; + } + lastline = ""; + } else if (ParsingState.READING_DATA === state) { + // parsing data + if (lastline.length > boundary.length + 4) { + lastline = ""; // mem save + } + if ("--" + boundary === lastline) { + const j = buffer.length - lastline.length; + const part = buffer.slice(0, j - 1); + + allParts.push( + process({ contentDispositionHeader, contentTypeHeader, part }) + ); + buffer = []; + currentPartHeaders = []; + lastline = ""; + state = ParsingState.READING_PART_SEPARATOR; + contentDispositionHeader = ""; + contentTypeHeader = ""; + } else { + buffer.push(oneByte); + } + if (newLineDetected) { + lastline = ""; + } + } else if (ParsingState.READING_PART_SEPARATOR === state) { + if (newLineDetected) { + state = ParsingState.READING_HEADERS; + } + } + } + return allParts; +} + +// read the boundary from the content-type header sent by the http client +// this value may be similar to: +// 'multipart/form-data; boundary=----WebKitFormBoundaryvm5A9tzU1ONaGP5B', +export function getBoundary(header: string): string { + const items = header.split(";"); + if (items) { + for (let i = 0; i < items.length; i++) { + const item = new String(items[i]).trim(); + if (item.indexOf("boundary") >= 0) { + const k = item.split("="); + return new String(k[1]).trim().replace(/^["']|["']$/g, ""); + } + } + } + return ""; +} + +export function DemoData(): { body: Uint8Array; boundary: string } { + let body = "trash1\r\n"; + body += "------WebKitFormBoundaryvef1fLxmoUdYZWXp\r\n"; + body += "Content-Type: text/plain\r\n"; + body += + 'Content-Disposition: form-data; name="uploads[]"; filename="A.txt"\r\n'; + body += "\r\n"; + body += "@11X"; + body += "111Y\r\n"; + body += "111Z\rCCCC\nCCCC\r\nCCCCC@\r\n\r\n"; + body += "------WebKitFormBoundaryvef1fLxmoUdYZWXp\r\n"; + body += "Content-Type: text/plain\r\n"; + body += + 'Content-Disposition: form-data; name="uploads[]"; filename="B.txt"\r\n'; + body += "\r\n"; + body += "@22X"; + body += "222Y\r\n"; + body += "222Z\r222W\n2220\r\n666@\r\n"; + body += "------WebKitFormBoundaryvef1fLxmoUdYZWXp\r\n"; + body += 'Content-Disposition: form-data; name="input1"\r\n'; + body += "\r\n"; + body += "value1\r\n"; + body += "------WebKitFormBoundaryvef1fLxmoUdYZWXp--\r\n"; + + return { + body: new TextEncoder().encode(body), + boundary: "----WebKitFormBoundaryvef1fLxmoUdYZWXp", + }; +} + +function process(part: Part): Input { + // will transform this object: + // { header: 'Content-Disposition: form-data; name="uploads[]"; filename="A.txt"', + // info: 'Content-Type: text/plain', + // part: 'AAAABBBB' } + // into this one: + // { filename: 'A.txt', type: 'text/plain', data: } + const obj = function (str: string) { + const k = str.split("="); + const a = k[0].trim(); + + const b = JSON.parse(k[1].trim()); + const o = {}; + Object.defineProperty(o, a, { + value: b, + writable: true, + enumerable: true, + configurable: true, + }); + return o; + }; + const header = part.contentDispositionHeader.split(";"); + + const filenameData = header[2]; + let input = {}; + if (filenameData) { + input = obj(filenameData); + const contentType = part.contentTypeHeader.split(":")[1].trim(); + Object.defineProperty(input, "type", { + value: contentType, + writable: true, + enumerable: true, + configurable: true, + }); + } + // always process the name field + Object.defineProperty(input, "name", { + value: header[1].split("=")[1].replace(/"/g, ""), + writable: true, + enumerable: true, + configurable: true, + }); + + Object.defineProperty(input, "data", { + value: new Uint8Array(part.part), + writable: true, + enumerable: true, + configurable: true, + }); + return input as Input; +} diff --git a/src/payload.ts b/src/payload.ts new file mode 100644 index 0000000..facd1d3 --- /dev/null +++ b/src/payload.ts @@ -0,0 +1,82 @@ +interface ReactNativeFileObject { + uri: string; + type?: string; + name?: string; +} + +export class Payload { + public uri: string; + public size: number; + public filename?: string; + public type?: string; + + constructor(uri: string, filename?: string, type?: string, size?: number) { + this.uri = uri; + this.filename = filename; + this.type = type; + + if (size === undefined) { + const base64Data = uri.split(',')[1]; + const binary = atob(base64Data); + this.size = binary.length; + } else { + this.size = size; + } + } + + public toBinary(offset: number = 0, length?: number): Uint8Array { + const base64Data = this.uri.split(',')[1]; + const binary = atob(base64Data); + const bytes = new Uint8Array(binary.length); + for (let i = 0; i < binary.length; i++) { + bytes[i] = binary.charCodeAt(i); + } + if (offset === 0 && length === undefined) { + return bytes; + } else if (length === undefined) { + return bytes.subarray(offset); + } else { + return bytes.subarray(offset, offset + length); + } + } + + public toFileObject(): ReactNativeFileObject { + return { + uri: this.uri, + type: this.type, + name: this.filename, + }; + } + + public toJson(): T { + return JSON.parse(this.toString()); + } + + public toString(): string { + const binary = this.toBinary(); + return new TextDecoder().decode(binary); + } + + public static fromJson(object: any, name?: string): Payload { + const jsonString = JSON.stringify(object); + const base64Data = btoa(jsonString); + const dataUri = `data:application/json;base64,${base64Data}`; + return new Payload(dataUri, name, 'application/json'); + } + + public static fromString(text: string, name?: string, type?: string): Payload { + const base64Data = btoa(text); + const dataUri = `data:${type || 'text/plain'};base64,${base64Data}`; + return new Payload(dataUri, name, type || 'text/plain'); + } + + public static fromBinary(binary: Uint8Array, name?: string, type?: string): Payload { + const base64Data = btoa(String.fromCharCode(...binary)); + const dataUri = `data:${type || 'application/octet-stream'};base64,${base64Data}`; + return new Payload(dataUri, name, type || 'application/octet-stream'); + } + + public static fromFileObject(file: ReactNativeFileObject): Payload { + return new Payload(file.uri, file.name, file.type); + } +} diff --git a/src/service.ts b/src/service.ts index fe17699..cbc2701 100644 --- a/src/service.ts +++ b/src/service.ts @@ -1,5 +1,5 @@ import { Client } from './client'; -import type { Payload } from './client'; +import type { Params } from './client'; export class Service { static CHUNK_SIZE = 5*1024*1024; // 5MB @@ -10,9 +10,9 @@ export class Service { this.client = client; } - static flatten(data: Payload, prefix = ''): Payload { - let output: Payload = {}; - + static flatten(data: Params, prefix = ''): Params { + let output: Params = {}; + for (const [key, value] of Object.entries(data)) { let finalKey = prefix ? prefix + '[' + key +']' : key; if (Array.isArray(value)) { diff --git a/src/services/account.ts b/src/services/account.ts index 57b7544..5046996 100644 --- a/src/services/account.ts +++ b/src/services/account.ts @@ -1,14 +1,15 @@ import { Service } from '../service'; import { AppwriteException, Client } from '../client'; +import { Payload } from '../payload'; import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; +import type { UploadProgress, Params } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; -import { AuthenticatorType } from '../enums/authenticator-type'; -import { AuthenticationFactor } from '../enums/authentication-factor'; -import { OAuthProvider } from '../enums/o-auth-provider'; - + import { AuthenticatorType } from '../enums/authenticator-type'; + import { AuthenticationFactor } from '../enums/authentication-factor'; + import { OAuthProvider } from '../enums/o-auth-provider'; + export class Account extends Service { constructor(client: Client) @@ -26,24 +27,21 @@ export class Account extends Service { */ async get(): Promise> { const apiPath = '/account'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) - * 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). + * 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](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) 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](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession). * * @param {string} userId * @param {string} email @@ -52,7 +50,7 @@ export class Account extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async create(userId: string, email: string, password: string, name?: string): Promise> { + async create(userId: string,email: string,password: string,name?: string): Promise> { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -66,48 +64,46 @@ export class Account extends Service { } const apiPath = '/account'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof email !== 'undefined') { - payload['email'] = email; + params['email'] = email; } if (typeof password !== 'undefined') { - payload['password'] = password; + params['password'] = password; } if (typeof name !== 'undefined') { - payload['name'] = name; + params['name'] = name; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * 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. - * + * 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> { + async updateEmail(email: string,password: string): Promise> { if (typeof email === 'undefined') { throw new AppwriteException('Missing required parameter: "email"'); } @@ -117,24 +113,27 @@ export class Account extends Service { } const apiPath = '/account/email'; - const payload: Payload = {}; + const params: Params = {}; if (typeof email !== 'undefined') { - payload['email'] = email; + params['email'] = email; } if (typeof password !== 'undefined') { - payload['password'] = password; + params['password'] = password; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** - * List Identities + * List identities * * Get the list of identities for the currently logged in user. * @@ -144,16 +143,19 @@ export class Account extends Service { */ async listIdentities(queries?: string[]): Promise { const apiPath = '/account/identities'; - const payload: Payload = {}; + const params: Params = {}; if (typeof queries !== 'undefined') { - payload['queries'] = queries; + params['queries'] = queries; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** @@ -171,41 +173,42 @@ export class Account extends Service { } const apiPath = '/account/identities/{identityId}'.replace('{identityId}', identityId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } /** * 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. + * 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 { - const apiPath = '/account/jwt'; - const payload: Payload = {}; + const apiPath = '/account/jwts'; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * List logs * - * Get the list of latest security activity logs for the currently logged in - * user. Each log returns user IP address, location and date and time of log. + * Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log. * * @param {string[]} queries * @throws {AppwriteException} @@ -213,16 +216,19 @@ export class Account extends Service { */ async listLogs(queries?: string[]): Promise { const apiPath = '/account/logs'; - const payload: Payload = {}; + const params: Params = {}; if (typeof queries !== 'undefined') { - payload['queries'] = queries; + params['queries'] = queries; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** @@ -240,25 +246,25 @@ export class Account extends Service { } const apiPath = '/account/mfa'; - const payload: Payload = {}; + const params: Params = {}; if (typeof mfa !== 'undefined') { - payload['mfa'] = mfa; + params['mfa'] = mfa; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** - * Add Authenticator + * Create authenticator * - * Add an authenticator app to be used as an MFA factor. Verify the - * authenticator using the [verify - * authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) - * method. + * Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method. * * @param {AuthenticatorType} type * @throws {AppwriteException} @@ -270,27 +276,28 @@ export class Account extends Service { } const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** - * Verify Authenticator + * Verify authenticator * - * Verify an authenticator app after adding it using the [add - * authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) - * method. add + * Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method. * * @param {AuthenticatorType} type * @param {string} otp * @throws {AppwriteException} * @returns {Promise} */ - async updateMfaAuthenticator(type: AuthenticatorType, otp: string): Promise> { + async updateMfaAuthenticator(type: AuthenticatorType,otp: string): Promise> { if (typeof type === 'undefined') { throw new AppwriteException('Missing required parameter: "type"'); } @@ -300,56 +307,51 @@ export class Account extends Service { } const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); - const payload: Payload = {}; + const params: Params = {}; if (typeof otp !== 'undefined') { - payload['otp'] = otp; + params['otp'] = otp; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } /** - * Delete Authenticator + * Delete authenticator * * Delete an authenticator for a user by ID. * * @param {AuthenticatorType} type - * @param {string} otp * @throws {AppwriteException} * @returns {Promise} */ - async deleteMfaAuthenticator(type: AuthenticatorType, otp: string): Promise<{}> { + async deleteMfaAuthenticator(type: AuthenticatorType): Promise<{}> { if (typeof type === 'undefined') { throw new AppwriteException('Missing required parameter: "type"'); } - if (typeof otp === 'undefined') { - throw new AppwriteException('Missing required parameter: "otp"'); - } - const apiPath = '/account/mfa/authenticators/{type}'.replace('{type}', type); - const payload: Payload = {}; - - if (typeof otp !== 'undefined') { - payload['otp'] = otp; - } + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } /** - * Create 2FA Challenge + * Create MFA challenge * - * Begin the process of MFA verification after sign-in. Finish the flow with - * [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) - * method. + * Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method. * * @param {AuthenticationFactor} factor * @throws {AppwriteException} @@ -361,33 +363,32 @@ export class Account extends Service { } const apiPath = '/account/mfa/challenge'; - const payload: Payload = {}; + const params: Params = {}; if (typeof factor !== 'undefined') { - payload['factor'] = factor; + params['factor'] = factor; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** - * Create MFA Challenge (confirmation) + * Create MFA challenge (confirmation) * - * Complete the MFA challenge by providing the one-time password. Finish the - * process of MFA verification by providing the one-time password. To begin - * the flow, use - * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - * method. + * Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method. * * @param {string} challengeId * @param {string} otp * @throws {AppwriteException} * @returns {Promise} */ - async updateMfaChallenge(challengeId: string, otp: string): Promise<{}> { + async updateMfaChallenge(challengeId: string,otp: string): Promise<{}> { if (typeof challengeId === 'undefined') { throw new AppwriteException('Missing required parameter: "challengeId"'); } @@ -397,24 +398,27 @@ export class Account extends Service { } const apiPath = '/account/mfa/challenge'; - const payload: Payload = {}; + const params: Params = {}; if (typeof challengeId !== 'undefined') { - payload['challengeId'] = challengeId; + params['challengeId'] = challengeId; } if (typeof otp !== 'undefined') { - payload['otp'] = otp; + params['otp'] = otp; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } /** - * List Factors + * List factors * * List the factors available on the account to be used as a MFA challange. * @@ -423,76 +427,78 @@ export class Account extends Service { */ async listMfaFactors(): Promise { const apiPath = '/account/mfa/factors'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** - * Get MFA Recovery Codes + * Get MFA recovery codes * - * Get recovery codes that can be used as backup for MFA flow. Before getting - * codes, they must be generated using - * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - * method. An OTP challenge is required to read recovery codes. + * Get recovery codes that can be used as backup for MFA flow. Before getting codes, they must be generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to read recovery codes. * * @throws {AppwriteException} * @returns {Promise} */ async getMfaRecoveryCodes(): Promise { const apiPath = '/account/mfa/recovery-codes'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** - * Create MFA Recovery Codes + * Create MFA recovery codes * - * Generate recovery codes as backup for MFA flow. It's recommended to - * generate and show then immediately after user successfully adds their - * authehticator. Recovery codes can be used as a MFA verification type in - * [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) - * method. + * Generate recovery codes as backup for MFA flow. It's recommended to generate and show then immediately after user successfully adds their authehticator. Recovery codes can be used as a MFA verification type in [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method. * * @throws {AppwriteException} * @returns {Promise} */ async createMfaRecoveryCodes(): Promise { const apiPath = '/account/mfa/recovery-codes'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** - * Regenerate MFA Recovery Codes + * Regenerate MFA recovery codes * - * Regenerate recovery codes that can be used as backup for MFA flow. Before - * regenerating codes, they must be first generated using - * [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) - * method. An OTP challenge is required to regenreate recovery codes. + * Regenerate recovery codes that can be used as backup for MFA flow. Before regenerating codes, they must be first generated using [createMfaRecoveryCodes](/docs/references/cloud/client-web/account#createMfaRecoveryCodes) method. An OTP challenge is required to regenreate recovery codes. * * @throws {AppwriteException} * @returns {Promise} */ async updateMfaRecoveryCodes(): Promise { const apiPath = '/account/mfa/recovery-codes'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** @@ -510,67 +516,67 @@ export class Account extends Service { } const apiPath = '/account/name'; - const payload: Payload = {}; + const params: Params = {}; if (typeof name !== 'undefined') { - payload['name'] = name; + params['name'] = name; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** * 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. + * 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> { + async updatePassword(password: string,oldPassword?: string): Promise> { if (typeof password === 'undefined') { throw new AppwriteException('Missing required parameter: "password"'); } const apiPath = '/account/password'; - const payload: Payload = {}; + const params: Params = {}; if (typeof password !== 'undefined') { - payload['password'] = password; + params['password'] = password; } if (typeof oldPassword !== 'undefined') { - payload['oldPassword'] = oldPassword; + params['oldPassword'] = oldPassword; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) - * endpoint to send a confirmation SMS. + * 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](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) endpoint to send a confirmation SMS. * * @param {string} phone * @param {string} password * @throws {AppwriteException} * @returns {Promise} */ - async updatePhone(phone: string, password: string): Promise> { + async updatePhone(phone: string,password: string): Promise> { if (typeof phone === 'undefined') { throw new AppwriteException('Missing required parameter: "phone"'); } @@ -580,20 +586,23 @@ export class Account extends Service { } const apiPath = '/account/phone'; - const payload: Payload = {}; + const params: Params = {}; if (typeof phone !== 'undefined') { - payload['phone'] = phone; + params['phone'] = phone; } if (typeof password !== 'undefined') { - payload['password'] = password; + params['password'] = password; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** @@ -606,20 +615,21 @@ export class Account extends Service { */ async getPrefs(): Promise { const apiPath = '/account/prefs'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * 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. + * 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 {object} prefs * @throws {AppwriteException} @@ -631,36 +641,32 @@ export class Account extends Service { } const apiPath = '/account/prefs'; - const payload: Payload = {}; + const params: Params = {}; if (typeof prefs !== 'undefined') { - payload['prefs'] = prefs; + params['prefs'] = prefs; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) - * endpoint to complete the process. The verification link sent to the user's - * email address is valid for 1 hour. + * 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](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) 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 { + async createRecovery(email: string,url: string): Promise { if (typeof email === 'undefined') { throw new AppwriteException('Missing required parameter: "email"'); } @@ -670,35 +676,31 @@ export class Account extends Service { } const apiPath = '/account/recovery'; - const payload: Payload = {}; + const params: Params = {}; if (typeof email !== 'undefined') { - payload['email'] = email; + params['email'] = email; } if (typeof url !== 'undefined') { - payload['url'] = url; + params['url'] = url; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) - * 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. + * 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](https://appwrite.io/docs/references/cloud/client-web/account#createRecovery) 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 @@ -706,7 +708,7 @@ export class Account extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async updateRecovery(userId: string, secret: string, password: string): Promise { + async updateRecovery(userId: string,secret: string,password: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -720,104 +722,105 @@ export class Account extends Service { } const apiPath = '/account/recovery'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof secret !== 'undefined') { - payload['secret'] = secret; + params['secret'] = secret; } if (typeof password !== 'undefined') { - payload['password'] = password; + params['password'] = password; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } /** * List sessions * - * Get the list of active sessions across different devices for the currently - * logged in user. + * Get the list of active sessions across different devices for the currently logged in user. * * @throws {AppwriteException} * @returns {Promise} */ async listSessions(): Promise { const apiPath = '/account/sessions'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * Delete sessions * - * Delete all sessions from the user account and remove any sessions cookies - * from the end client. + * Delete all sessions from the user account and remove any sessions cookies from the end client. * * @throws {AppwriteException} * @returns {Promise} */ async deleteSessions(): Promise<{}> { const apiPath = '/account/sessions'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) - * or create an [OAuth2 - * session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). + * 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](https://appwrite.io/docs/references/cloud/client-web/account#updateEmail) or create an [OAuth2 session](https://appwrite.io/docs/references/cloud/client-web/account#CreateOAuth2Session). * * @throws {AppwriteException} * @returns {Promise} */ async createAnonymousSession(): Promise { const apiPath = '/account/sessions/anonymous'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * Create email password 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](https://appwrite.io/docs/authentication-security#limits). + * 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](https://appwrite.io/docs/authentication-security#limits). * * @param {string} email * @param {string} password * @throws {AppwriteException} * @returns {Promise} */ - async createEmailPasswordSession(email: string, password: string): Promise { + async createEmailPasswordSession(email: string,password: string): Promise { if (typeof email === 'undefined') { throw new AppwriteException('Missing required parameter: "email"'); } @@ -827,35 +830,36 @@ export class Account extends Service { } const apiPath = '/account/sessions/email'; - const payload: Payload = {}; + const params: Params = {}; if (typeof email !== 'undefined') { - payload['email'] = email; + params['email'] = email; } if (typeof password !== 'undefined') { - payload['password'] = password; + params['password'] = password; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * Update magic URL session * - * Use this endpoint to create a session from token. Provide the **userId** - * and **secret** parameters from the successful response of authentication - * flows initiated by token creation. For example, magic URL and phone login. + * Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login. * * @param {string} userId * @param {string} secret * @throws {AppwriteException} * @returns {Promise} */ - async updateMagicURLSession(userId: string, secret: string): Promise { + async updateMagicURLSession(userId: string,secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -865,41 +869,34 @@ export class Account extends Service { } const apiPath = '/account/sessions/magic-url'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof secret !== 'undefined') { - payload['secret'] = secret; + params['secret'] = secret; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/authentication-security#limits). - * + * 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](https://appwrite.io/docs/authentication-security#limits). + * * @param {OAuthProvider} provider * @param {string} success @@ -908,31 +905,31 @@ export class Account extends Service { * @throws {AppwriteException} * @returns {void|string} */ - createOAuth2Session(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): void | URL { + createOAuth2Session(provider: OAuthProvider,success?: string,failure?: string,scopes?: string[]): void | URL { if (typeof provider === 'undefined') { throw new AppwriteException('Missing required parameter: "provider"'); } const apiPath = '/account/sessions/oauth2/{provider}'.replace('{provider}', provider); - const payload: Payload = {}; + const params: Params = {}; if (typeof success !== 'undefined') { - payload['success'] = success; + params['success'] = success; } if (typeof failure !== 'undefined') { - payload['failure'] = failure; + params['failure'] = failure; } if (typeof scopes !== 'undefined') { - payload['scopes'] = scopes; + params['scopes'] = scopes; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -941,16 +938,14 @@ export class Account extends Service { /** * Update phone session * - * Use this endpoint to create a session from token. Provide the **userId** - * and **secret** parameters from the successful response of authentication - * flows initiated by token creation. For example, magic URL and phone login. + * Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login. * * @param {string} userId * @param {string} secret * @throws {AppwriteException} * @returns {Promise} */ - async updatePhoneSession(userId: string, secret: string): Promise { + async updatePhoneSession(userId: string,secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -960,35 +955,36 @@ export class Account extends Service { } const apiPath = '/account/sessions/phone'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof secret !== 'undefined') { - payload['secret'] = secret; + params['secret'] = secret; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } /** * Create session * - * Use this endpoint to create a session from token. Provide the **userId** - * and **secret** parameters from the successful response of authentication - * flows initiated by token creation. For example, magic URL and phone login. + * Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login. * * @param {string} userId * @param {string} secret * @throws {AppwriteException} * @returns {Promise} */ - async createSession(userId: string, secret: string): Promise { + async createSession(userId: string,secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -998,27 +994,29 @@ export class Account extends Service { } const apiPath = '/account/sessions/token'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof secret !== 'undefined') { - payload['secret'] = secret; + params['secret'] = secret; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * 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. + * 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} @@ -1030,20 +1028,21 @@ export class Account extends Service { } const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * Update session * - * Use this endpoint to extend a session's length. Extending a session is - * useful when session expiry is short. If the session was created using an - * OAuth provider, this endpoint refreshes the access token from the provider. + * Use this endpoint to extend a session's length. Extending a session is useful when session expiry is short. If the session was created using an OAuth provider, this endpoint refreshes the access token from the provider. * * @param {string} sessionId * @throws {AppwriteException} @@ -1055,22 +1054,21 @@ export class Account extends Service { } const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** * Delete session * - * Logout the user. Use 'current' as the session ID to logout on this device, - * use a session ID to logout on another device. If you're looking to logout - * the user on all devices, use [Delete - * Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) - * instead. + * Logout the user. Use 'current' as the session ID to logout on this device, use a session ID to logout on another device. If you're looking to logout the user on all devices, use [Delete Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) instead. * * @param {string} sessionId * @throws {AppwriteException} @@ -1082,32 +1080,36 @@ export class Account extends Service { } const apiPath = '/account/sessions/{sessionId}'.replace('{sessionId}', sessionId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } /** * 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. + * 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> { const apiPath = '/account/status'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** @@ -1120,7 +1122,7 @@ export class Account extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createPushTarget(targetId: string, identifier: string, providerId?: string): Promise { + async createPushTarget(targetId: string,identifier: string,providerId?: string): Promise { if (typeof targetId === 'undefined') { throw new AppwriteException('Missing required parameter: "targetId"'); } @@ -1130,24 +1132,27 @@ export class Account extends Service { } const apiPath = '/account/targets/push'; - const payload: Payload = {}; + const params: Params = {}; if (typeof targetId !== 'undefined') { - payload['targetId'] = targetId; + params['targetId'] = targetId; } if (typeof identifier !== 'undefined') { - payload['identifier'] = identifier; + params['identifier'] = identifier; } if (typeof providerId !== 'undefined') { - payload['providerId'] = providerId; + params['providerId'] = providerId; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** @@ -1159,7 +1164,7 @@ export class Account extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async updatePushTarget(targetId: string, identifier: string): Promise { + async updatePushTarget(targetId: string,identifier: string): Promise { if (typeof targetId === 'undefined') { throw new AppwriteException('Missing required parameter: "targetId"'); } @@ -1169,16 +1174,19 @@ export class Account extends Service { } const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId); - const payload: Payload = {}; + const params: Params = {}; if (typeof identifier !== 'undefined') { - payload['identifier'] = identifier; + params['identifier'] = identifier; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } /** @@ -1195,27 +1203,23 @@ export class Account extends Service { } const apiPath = '/account/targets/{targetId}/push'.replace('{targetId}', targetId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } /** * Create email token (OTP) * - * 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. Use the - * returned user ID and secret and submit a request to the [POST - * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - * endpoint to complete the login process. The secret sent to the user's email - * is valid for 15 minutes. - * - * A user is limited to 10 active sessions at a time by default. [Learn more - * about session - * limits](https://appwrite.io/docs/authentication-security#limits). + * 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. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's email is valid for 15 minutes. + +A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * * @param {string} userId * @param {string} email @@ -1223,7 +1227,7 @@ export class Account extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createEmailToken(userId: string, email: string, phrase?: boolean): Promise { + async createEmailToken(userId: string,email: string,phrase?: boolean): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -1233,45 +1237,36 @@ export class Account extends Service { } const apiPath = '/account/tokens/email'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof email !== 'undefined') { - payload['email'] = email; + params['email'] = email; } if (typeof phrase !== 'undefined') { - payload['phrase'] = phrase; + params['phrase'] = phrase; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * Create magic URL token * - * Sends the user an email with a secret key for creating a session. If the - * provided user ID has not been 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 - * [POST - * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - * 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](https://appwrite.io/docs/authentication-security#limits). - * + * Sends the user an email with a secret key for creating a session. If the provided user ID has not been 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 [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) 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](https://appwrite.io/docs/authentication-security#limits). + * * @param {string} userId * @param {string} email @@ -1280,7 +1275,7 @@ export class Account extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createMagicURLToken(userId: string, email: string, url?: string, phrase?: boolean): Promise { + async createMagicURLToken(userId: string,email: string,url?: string,phrase?: boolean): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -1290,47 +1285,41 @@ export class Account extends Service { } const apiPath = '/account/tokens/magic-url'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof email !== 'undefined') { - payload['email'] = email; + params['email'] = email; } if (typeof url !== 'undefined') { - payload['url'] = url; + params['url'] = url; } if (typeof phrase !== 'undefined') { - payload['phrase'] = phrase; + params['phrase'] = phrase; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * Create OAuth2 token * - * 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 authentication succeeds, `userId` and `secret` of a token will be - * appended to the success URL as query parameters. These can be used to - * create a new session using the [Create - * session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - * endpoint. - * - * A user is limited to 10 active sessions at a time by default. [Learn more - * about session - * limits](https://appwrite.io/docs/authentication-security#limits). + * 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 authentication succeeds, `userId` and `secret` of a token will be appended to the success URL as query parameters. These can be used to create a new session using the [Create session](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint. + +A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits). * * @param {OAuthProvider} provider * @param {string} success @@ -1339,31 +1328,31 @@ export class Account extends Service { * @throws {AppwriteException} * @returns {void|string} */ - createOAuth2Token(provider: OAuthProvider, success?: string, failure?: string, scopes?: string[]): void | URL { + createOAuth2Token(provider: OAuthProvider,success?: string,failure?: string,scopes?: string[]): void | URL { if (typeof provider === 'undefined') { throw new AppwriteException('Missing required parameter: "provider"'); } const apiPath = '/account/tokens/oauth2/{provider}'.replace('{provider}', provider); - const payload: Payload = {}; + const params: Params = {}; if (typeof success !== 'undefined') { - payload['success'] = success; + params['success'] = success; } if (typeof failure !== 'undefined') { - payload['failure'] = failure; + params['failure'] = failure; } if (typeof scopes !== 'undefined') { - payload['scopes'] = scopes; + params['scopes'] = scopes; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -1372,23 +1361,16 @@ export class Account extends Service { /** * Create phone token * - * 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 [POST - * /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) - * 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](https://appwrite.io/docs/authentication-security#limits). + * 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 [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) 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](https://appwrite.io/docs/authentication-security#limits). * * @param {string} userId * @param {string} phone * @throws {AppwriteException} * @returns {Promise} */ - async createPhoneToken(userId: string, phone: string): Promise { + async createPhoneToken(userId: string,phone: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -1398,40 +1380,32 @@ export class Account extends Service { } const apiPath = '/account/tokens/phone'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof phone !== 'undefined') { - payload['phone'] = phone; + params['phone'] = phone; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). - * 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. - * + * 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](https://appwrite.io/docs/references/cloud/client-web/account#updateVerification). 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} @@ -1443,32 +1417,32 @@ export class Account extends Service { } const apiPath = '/account/verification'; - const payload: Payload = {}; + const params: Params = {}; if (typeof url !== 'undefined') { - payload['url'] = url; + params['url'] = url; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * 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. + * 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 { + async updateVerification(userId: string,secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -1478,61 +1452,57 @@ export class Account extends Service { } const apiPath = '/account/verification'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof secret !== 'undefined') { - payload['secret'] = secret; + params['secret'] = secret; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) - * endpoint. Learn more about how to [complete the verification - * process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). - * The verification code sent to the user's phone number is valid for 15 - * minutes. + * 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](https://appwrite.io/docs/references/cloud/client-web/account#updatePhone) endpoint. Learn more about how to [complete the verification process](https://appwrite.io/docs/references/cloud/client-web/account#updatePhoneVerification). The verification code sent to the user's phone number is valid for 15 minutes. * * @throws {AppwriteException} * @returns {Promise} */ async createPhoneVerification(): Promise { const apiPath = '/account/verification/phone'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** - * Create phone verification (confirmation) + * Update 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. + * 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 { + async updatePhoneVerification(userId: string,secret: string): Promise { if (typeof userId === 'undefined') { throw new AppwriteException('Missing required parameter: "userId"'); } @@ -1542,19 +1512,22 @@ export class Account extends Service { } const apiPath = '/account/verification/phone'; - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof secret !== 'undefined') { - payload['secret'] = secret; + params['secret'] = secret; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } }; diff --git a/src/services/avatars.ts b/src/services/avatars.ts index fd6017e..6858f1c 100644 --- a/src/services/avatars.ts +++ b/src/services/avatars.ts @@ -1,13 +1,14 @@ import { Service } from '../service'; import { AppwriteException, Client } from '../client'; +import { Payload } from '../payload'; import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; +import type { UploadProgress, Params } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; -import { Browser } from '../enums/browser'; -import { CreditCard } from '../enums/credit-card'; -import { Flag } from '../enums/flag'; + import { Browser } from '../enums/browser'; + import { CreditCard } from '../enums/credit-card'; + import { Flag } from '../enums/flag'; export class Avatars extends Service { @@ -19,16 +20,9 @@ export class Avatars extends Service { /** * 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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) - * 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. + * 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](https://appwrite.io/docs/references/cloud/client-web/account#getSessions) 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 {Browser} code * @param {number} width @@ -37,31 +31,31 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {URL} */ - getBrowser(code: Browser, width?: number, height?: number, quality?: number): URL { + getBrowser(code: Browser,width?: number,height?: number,quality?: number): URL { if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); } const apiPath = '/avatars/browsers/{code}'.replace('{code}', code); - const payload: Payload = {}; + const params: Params = {}; if (typeof width !== 'undefined') { - payload['width'] = width; + params['width'] = width; } if (typeof height !== 'undefined') { - payload['height'] = height; + params['height'] = height; } if (typeof quality !== 'undefined') { - payload['quality'] = quality; + params['quality'] = quality; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -70,15 +64,10 @@ export class Avatars extends Service { /** * 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. - * + * 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 {CreditCard} code * @param {number} width @@ -87,31 +76,31 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {URL} */ - getCreditCard(code: CreditCard, width?: number, height?: number, quality?: number): URL { + getCreditCard(code: CreditCard,width?: number,height?: number,quality?: number): URL { if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); } const apiPath = '/avatars/credit-cards/{code}'.replace('{code}', code); - const payload: Payload = {}; + const params: Params = {}; if (typeof width !== 'undefined') { - payload['width'] = width; + params['width'] = width; } if (typeof height !== 'undefined') { - payload['height'] = height; + params['height'] = height; } if (typeof quality !== 'undefined') { - payload['quality'] = quality; + params['quality'] = quality; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -120,9 +109,9 @@ export class Avatars extends Service { /** * Get favicon * - * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote - * website URL. - * + * Use this endpoint to fetch the favorite icon (AKA favicon) of any remote website URL. + +This endpoint does not follow HTTP redirects. * * @param {string} url * @throws {AppwriteException} @@ -134,17 +123,17 @@ export class Avatars extends Service { } const apiPath = '/avatars/favicon'; - const payload: Payload = {}; + const params: Params = {}; if (typeof url !== 'undefined') { - payload['url'] = url; + params['url'] = url; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -153,16 +142,10 @@ export class Avatars extends Service { /** * 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](https://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. - * + * 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](https://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 {Flag} code * @param {number} width @@ -171,31 +154,31 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {URL} */ - getFlag(code: Flag, width?: number, height?: number, quality?: number): URL { + getFlag(code: Flag,width?: number,height?: number,quality?: number): URL { if (typeof code === 'undefined') { throw new AppwriteException('Missing required parameter: "code"'); } const apiPath = '/avatars/flags/{code}'.replace('{code}', code); - const payload: Payload = {}; + const params: Params = {}; if (typeof width !== 'undefined') { - payload['width'] = width; + params['width'] = width; } if (typeof height !== 'undefined') { - payload['height'] = height; + params['height'] = height; } if (typeof quality !== 'undefined') { - payload['quality'] = quality; + params['quality'] = quality; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -204,16 +187,11 @@ export class Avatars extends Service { /** * 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. - * + * 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. + +This endpoint does not follow HTTP redirects. * * @param {string} url * @param {number} width @@ -221,31 +199,31 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {URL} */ - getImage(url: string, width?: number, height?: number): URL { + getImage(url: string,width?: number,height?: number): URL { if (typeof url === 'undefined') { throw new AppwriteException('Missing required parameter: "url"'); } const apiPath = '/avatars/image'; - const payload: Payload = {}; + const params: Params = {}; if (typeof url !== 'undefined') { - payload['url'] = url; + params['url'] = url; } if (typeof width !== 'undefined') { - payload['width'] = width; + params['width'] = width; } if (typeof height !== 'undefined') { - payload['height'] = height; + params['height'] = height; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -254,22 +232,12 @@ export class Avatars extends Service { /** * 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. - * + * 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 @@ -278,31 +246,31 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {URL} */ - getInitials(name?: string, width?: number, height?: number, background?: string): URL { + getInitials(name?: string,width?: number,height?: number,background?: string): URL { const apiPath = '/avatars/initials'; - const payload: Payload = {}; + const params: Params = {}; if (typeof name !== 'undefined') { - payload['name'] = name; + params['name'] = name; } if (typeof width !== 'undefined') { - payload['width'] = width; + params['width'] = width; } if (typeof height !== 'undefined') { - payload['height'] = height; + params['height'] = height; } if (typeof background !== 'undefined') { - payload['background'] = background; + params['background'] = background; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -311,9 +279,8 @@ export class Avatars extends Service { /** * 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. - * + * 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 @@ -322,35 +289,35 @@ export class Avatars extends Service { * @throws {AppwriteException} * @returns {URL} */ - getQR(text: string, size?: number, margin?: number, download?: boolean): URL { + getQR(text: string,size?: number,margin?: number,download?: boolean): URL { if (typeof text === 'undefined') { throw new AppwriteException('Missing required parameter: "text"'); } const apiPath = '/avatars/qr'; - const payload: Payload = {}; + const params: Params = {}; if (typeof text !== 'undefined') { - payload['text'] = text; + params['text'] = text; } if (typeof size !== 'undefined') { - payload['size'] = size; + params['size'] = size; } if (typeof margin !== 'undefined') { - payload['margin'] = margin; + params['margin'] = margin; } if (typeof download !== 'undefined') { - payload['download'] = download; + params['download'] = download; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; diff --git a/src/services/databases.ts b/src/services/databases.ts index eb36315..c4b1b4d 100644 --- a/src/services/databases.ts +++ b/src/services/databases.ts @@ -1,7 +1,8 @@ import { Service } from '../service'; import { AppwriteException, Client } from '../client'; +import { Payload } from '../payload'; import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; +import type { UploadProgress, Params } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; @@ -16,8 +17,7 @@ export class Databases extends Service { /** * List documents * - * Get a list of all the user's documents in a given collection. You can use - * the query params to filter your results. + * 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 @@ -25,7 +25,7 @@ export class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async listDocuments(databaseId: string, collectionId: string, queries?: string[]): Promise> { + async listDocuments(databaseId: string,collectionId: string,queries?: string[]): Promise> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -35,25 +35,25 @@ export class Databases extends Service { } const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); - const payload: Payload = {}; + const params: Params = {}; if (typeof queries !== 'undefined') { - payload['queries'] = queries; + params['queries'] = queries; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * Create document * - * Create a new Document. Before using this route, you should create a new - * collection resource using either a [server - * integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) - * API or directly from your database console. + * Create a new Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. * * @param {string} databaseId * @param {string} collectionId @@ -63,7 +63,7 @@ export class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createDocument(databaseId: string, collectionId: string, documentId: string, data: object, permissions?: string[]): Promise { + async createDocument(databaseId: string,collectionId: string,documentId: string,data: object,permissions?: string[]): Promise { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -81,31 +81,33 @@ export class Databases extends Service { } const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId); - const payload: Payload = {}; + const params: Params = {}; if (typeof documentId !== 'undefined') { - payload['documentId'] = documentId; + params['documentId'] = documentId; } if (typeof data !== 'undefined') { - payload['data'] = data; + params['data'] = data; } if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; + params['permissions'] = permissions; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * Get document * - * Get a document by its unique ID. This endpoint response returns a JSON - * object with the document data. + * Get a document by its unique ID. This endpoint response returns a JSON object with the document data. * * @param {string} databaseId * @param {string} collectionId @@ -114,7 +116,7 @@ export class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async getDocument(databaseId: string, collectionId: string, documentId: string, queries?: string[]): Promise { + async getDocument(databaseId: string,collectionId: string,documentId: string,queries?: string[]): Promise { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -128,23 +130,25 @@ export class Databases extends Service { } const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); - const payload: Payload = {}; + const params: Params = {}; if (typeof queries !== 'undefined') { - payload['queries'] = queries; + params['queries'] = queries; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * Update document * - * Update a document by its unique ID. Using the patch method you can pass - * only specific fields that will get updated. + * 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 @@ -154,7 +158,7 @@ export class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async updateDocument(databaseId: string, collectionId: string, documentId: string, data?: object, permissions?: string[]): Promise { + async updateDocument(databaseId: string,collectionId: string,documentId: string,data?: object,permissions?: string[]): Promise { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -168,20 +172,23 @@ export class Databases extends Service { } const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); - const payload: Payload = {}; + const params: Params = {}; if (typeof data !== 'undefined') { - payload['data'] = data; + params['data'] = data; } if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; + params['permissions'] = permissions; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** @@ -195,7 +202,7 @@ export class Databases extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async deleteDocument(databaseId: string, collectionId: string, documentId: string): Promise<{}> { + async deleteDocument(databaseId: string,collectionId: string,documentId: string): Promise<{}> { if (typeof databaseId === 'undefined') { throw new AppwriteException('Missing required parameter: "databaseId"'); } @@ -209,11 +216,14 @@ export class Databases extends Service { } const apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } }; diff --git a/src/services/functions.ts b/src/services/functions.ts index a31f273..eb5b046 100644 --- a/src/services/functions.ts +++ b/src/services/functions.ts @@ -1,11 +1,12 @@ import { Service } from '../service'; import { AppwriteException, Client } from '../client'; +import { Payload } from '../payload'; import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; +import type { UploadProgress, Params } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; -import { ExecutionMethod } from '../enums/execution-method'; + import { ExecutionMethod } from '../enums/execution-method'; export class Functions extends Service { @@ -17,8 +18,7 @@ export class Functions extends Service { /** * List executions * - * Get a list of all the current user function execution logs. You can use the - * query params to filter your results. + * 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 @@ -26,77 +26,85 @@ export class Functions extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async listExecutions(functionId: string, queries?: string[], search?: string): Promise { + async listExecutions(functionId: string,queries?: string[],search?: string): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); - const payload: Payload = {}; + const params: Params = {}; if (typeof queries !== 'undefined') { - payload['queries'] = queries; + params['queries'] = queries; } if (typeof search !== 'undefined') { - payload['search'] = search; + params['search'] = search; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * 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. + * 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} body + * @param {Payload} body * @param {boolean} async * @param {string} xpath * @param {ExecutionMethod} method * @param {object} headers + * @param {string} scheduledAt * @throws {AppwriteException} * @returns {Promise} */ - async createExecution(functionId: string, body?: string, async?: boolean, xpath?: string, method?: ExecutionMethod, headers?: object): Promise { + async createExecution(functionId: string,body?: Payload,async?: boolean,xpath?: string,method?: ExecutionMethod,headers?: object,scheduledAt?: string, onProgress = (progress: UploadProgress) => {}): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } const apiPath = '/functions/{functionId}/executions'.replace('{functionId}', functionId); - const payload: Payload = {}; + const params: Params = {}; if (typeof body !== 'undefined') { - payload['body'] = body; + params['body'] = body; } if (typeof async !== 'undefined') { - payload['async'] = async; + params['async'] = async; } if (typeof xpath !== 'undefined') { - payload['path'] = xpath; + params['path'] = xpath; } if (typeof method !== 'undefined') { - payload['method'] = method; + params['method'] = method; } if (typeof headers !== 'undefined') { - payload['headers'] = headers; + params['headers'] = headers; + } + + if (typeof scheduledAt !== 'undefined') { + params['scheduledAt'] = scheduledAt; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { - 'content-type': 'application/json', - }, payload); + + const apiHeaders: { [header: string]: string } = { + 'content-type': 'multipart/form-data', + } + + return await this.client.call('post', uri, apiHeaders, params); } /** @@ -109,7 +117,7 @@ export class Functions extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async getExecution(functionId: string, executionId: string): Promise { + async getExecution(functionId: string,executionId: string): Promise { if (typeof functionId === 'undefined') { throw new AppwriteException('Missing required parameter: "functionId"'); } @@ -119,11 +127,14 @@ export class Functions extends Service { } const apiPath = '/functions/{functionId}/executions/{executionId}'.replace('{functionId}', functionId).replace('{executionId}', executionId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } }; diff --git a/src/services/graphql.ts b/src/services/graphql.ts index 8b1f2b8..4ab3b4b 100644 --- a/src/services/graphql.ts +++ b/src/services/graphql.ts @@ -1,7 +1,8 @@ import { Service } from '../service'; import { AppwriteException, Client } from '../client'; +import { Payload } from '../payload'; import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; +import type { UploadProgress, Params } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; @@ -28,17 +29,20 @@ export class Graphql extends Service { } const apiPath = '/graphql'; - const payload: Payload = {}; + const params: Params = {}; if (typeof query !== 'undefined') { - payload['query'] = query; + params['query'] = query; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'x-sdk-graphql': 'true', 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** @@ -56,16 +60,19 @@ export class Graphql extends Service { } const apiPath = '/graphql/mutation'; - const payload: Payload = {}; + const params: Params = {}; if (typeof query !== 'undefined') { - payload['query'] = query; + params['query'] = query; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'x-sdk-graphql': 'true', 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } }; diff --git a/src/services/locale.ts b/src/services/locale.ts index de62cfb..78bee44 100644 --- a/src/services/locale.ts +++ b/src/services/locale.ts @@ -1,7 +1,8 @@ import { Service } from '../service'; import { AppwriteException, Client } from '../client'; +import { Payload } from '../payload'; import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; +import type { UploadProgress, Params } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; @@ -16,157 +17,170 @@ export class Locale extends Service { /** * 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)) + * 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 { const apiPath = '/locale'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** - * List Locale Codes + * List locale codes * - * List of all locale codes in [ISO - * 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). + * List of all locale codes in [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes). * * @throws {AppwriteException} * @returns {Promise} */ async listCodes(): Promise { const apiPath = '/locale/codes'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * List continents * - * List of all continents. You can use the locale header to get the data in a - * supported language. + * 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 { const apiPath = '/locale/continents'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * List countries * - * List of all countries. You can use the locale header to get the data in a - * supported language. + * 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 { const apiPath = '/locale/countries'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * 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. + * 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 { const apiPath = '/locale/countries/eu'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * List countries phone codes * - * List of all countries phone codes. You can use the locale header to get the - * data in a supported language. + * 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 { const apiPath = '/locale/countries/phones'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * 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. + * 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 { const apiPath = '/locale/currencies'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * List languages * - * List of all languages classified by ISO 639-1 including 2-letter code, name - * in English, and name in the respective language. + * 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 { const apiPath = '/locale/languages'; - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } }; diff --git a/src/services/messaging.ts b/src/services/messaging.ts index 26ceb31..6e4732d 100644 --- a/src/services/messaging.ts +++ b/src/services/messaging.ts @@ -1,7 +1,8 @@ import { Service } from '../service'; import { AppwriteException, Client } from '../client'; +import { Payload } from '../payload'; import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; +import type { UploadProgress, Params } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; @@ -24,7 +25,7 @@ export class Messaging extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createSubscriber(topicId: string, subscriberId: string, targetId: string): Promise { + async createSubscriber(topicId: string,subscriberId: string,targetId: string): Promise { if (typeof topicId === 'undefined') { throw new AppwriteException('Missing required parameter: "topicId"'); } @@ -38,20 +39,23 @@ export class Messaging extends Service { } const apiPath = '/messaging/topics/{topicId}/subscribers'.replace('{topicId}', topicId); - const payload: Payload = {}; + const params: Params = {}; if (typeof subscriberId !== 'undefined') { - payload['subscriberId'] = subscriberId; + params['subscriberId'] = subscriberId; } if (typeof targetId !== 'undefined') { - payload['targetId'] = targetId; + params['targetId'] = targetId; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** @@ -64,7 +68,7 @@ export class Messaging extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async deleteSubscriber(topicId: string, subscriberId: string): Promise<{}> { + async deleteSubscriber(topicId: string,subscriberId: string): Promise<{}> { if (typeof topicId === 'undefined') { throw new AppwriteException('Missing required parameter: "topicId"'); } @@ -74,11 +78,14 @@ export class Messaging extends Service { } const apiPath = '/messaging/topics/{topicId}/subscribers/{subscriberId}'.replace('{topicId}', topicId).replace('{subscriberId}', subscriberId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } }; diff --git a/src/services/storage.ts b/src/services/storage.ts index 1f1ebd4..e95da11 100644 --- a/src/services/storage.ts +++ b/src/services/storage.ts @@ -1,12 +1,13 @@ import { Service } from '../service'; import { AppwriteException, Client } from '../client'; +import { Payload } from '../payload'; import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; +import type { UploadProgress, Params } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; -import { ImageGravity } from '../enums/image-gravity'; -import { ImageFormat } from '../enums/image-format'; + import { ImageGravity } from '../enums/image-gravity'; + import { ImageFormat } from '../enums/image-format'; export class Storage extends Service { @@ -18,8 +19,7 @@ export class Storage extends Service { /** * List files * - * Get a list of all the user files. You can use the query params to filter - * your results. + * Get a list of all the user files. You can use the query params to filter your results. * * @param {string} bucketId * @param {string[]} queries @@ -27,58 +27,51 @@ export class Storage extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async listFiles(bucketId: string, queries?: string[], search?: string): Promise { + async listFiles(bucketId: string,queries?: string[],search?: string): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); - const payload: Payload = {}; + const params: Params = {}; if (typeof queries !== 'undefined') { - payload['queries'] = queries; + params['queries'] = queries; } if (typeof search !== 'undefined') { - payload['search'] = search; + params['search'] = search; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * Create file * - * Create a new file. Before using this route, you should create a new bucket - * resource using either a [server - * integration](https://appwrite.io/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. - * + * Create a new file. Before using this route, you should create a new bucket resource using either a [server integration](https://appwrite.io/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 {{name: string, type: string, size: number, uri: string}} file + * @param {Payload} file * @param {string[]} permissions * @throws {AppwriteException} * @returns {Promise} */ - async createFile(bucketId: string, fileId: string, file: {name: string, type: string, size: number, uri: string}, permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise { + async createFile(bucketId: string,fileId: string,file: Payload,permissions?: string[], onProgress = (progress: UploadProgress) => {}): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -92,32 +85,32 @@ export class Storage extends Service { } const apiPath = '/storage/buckets/{bucketId}/files'.replace('{bucketId}', bucketId); - const payload: Payload = {}; + const params: Params = {}; if (typeof fileId !== 'undefined') { - payload['fileId'] = fileId; + params['fileId'] = fileId; } if (typeof file !== 'undefined') { - payload['file'] = file; + params['file'] = file; } if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; + params['permissions'] = permissions; } const uri = new URL(this.client.config.endpoint + apiPath); + const apiHeaders: { [header: string]: string } = { + 'content-type': 'multipart/form-data', + } + + const size = file.size; if (size <= Service.CHUNK_SIZE) { - return await this.client.call('post', uri, { - 'content-type': 'multipart/form-data', - }, payload); - } - - const apiHeaders: { [header: string]: string } = { - 'content-type': 'multipart/form-data', + params['file'] = file.toFileObject(); + return await this.client.call('post', uri, apiHeaders, params); } let offset = 0; @@ -139,20 +132,22 @@ export class Storage extends Service { apiHeaders['x-appwrite-id'] = response.$id; } - let chunk = await FileSystem.readAsStringAsync(file.uri, { - encoding: FileSystem.EncodingType.Base64, - position: offset, - length: Service.CHUNK_SIZE - }); - var path = `data:${file.type};base64,${chunk}`; + let chunkBuffer = file.toBinary(offset, end - offset + 1); + let chunk = btoa(String.fromCharCode(...chunkBuffer)); + + var path = `data:$file.type};base64,${chunk}`; if (Platform.OS.toLowerCase() === 'android') { path = FileSystem.cacheDirectory + '/tmp_chunk_' + timestamp; await FileSystem.writeAsStringAsync(path, chunk, {encoding: FileSystem.EncodingType.Base64}); } - payload['file'] = { uri: path, name: file.name, type: file.type }; + params['file'] = { + uri: path, + name: file.filename, + type: file.type + }; - response = await this.client.call('post', uri, apiHeaders, payload); + response = await this.client.call('post', uri, apiHeaders, params); if (onProgress) { onProgress({ @@ -171,15 +166,14 @@ export class Storage extends Service { /** * Get file * - * Get a file by its unique ID. This endpoint response returns a JSON object - * with the file metadata. + * 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 { + async getFile(bucketId: string,fileId: string): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -189,19 +183,21 @@ export class Storage extends Service { } const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * Update file * - * Update a file by its unique ID. Only users with write permissions have - * access to update this resource. + * Update a file by its unique ID. Only users with write permissions have access to update this resource. * * @param {string} bucketId * @param {string} fileId @@ -210,7 +206,7 @@ export class Storage extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async updateFile(bucketId: string, fileId: string, name?: string, permissions?: string[]): Promise { + async updateFile(bucketId: string,fileId: string,name?: string,permissions?: string[]): Promise { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -220,34 +216,36 @@ export class Storage extends Service { } const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - const payload: Payload = {}; + const params: Params = {}; if (typeof name !== 'undefined') { - payload['name'] = name; + params['name'] = name; } if (typeof permissions !== 'undefined') { - payload['permissions'] = permissions; + params['permissions'] = permissions; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } /** - * Delete File + * Delete file * - * Delete a file by its unique ID. Only users with write permissions have - * access to delete this resource. + * 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<{}> { + async deleteFile(bucketId: string,fileId: string): Promise<{}> { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -257,27 +255,28 @@ export class Storage extends Service { } const apiPath = '/storage/buckets/{bucketId}/files/{fileId}'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } /** * 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. + * 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 { + getFileDownload(bucketId: string,fileId: string): URL { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -287,13 +286,13 @@ export class Storage extends Service { } const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/download'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -302,11 +301,7 @@ export class Storage extends Service { /** * 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. + * 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 @@ -324,7 +319,7 @@ export class Storage extends Service { * @throws {AppwriteException} * @returns {URL} */ - getFilePreview(bucketId: string, fileId: string, width?: number, height?: number, gravity?: ImageGravity, quality?: number, borderWidth?: number, borderColor?: string, borderRadius?: number, opacity?: number, rotation?: number, background?: string, output?: ImageFormat): URL { + getFilePreview(bucketId: string,fileId: string,width?: number,height?: number,gravity?: ImageGravity,quality?: number,borderWidth?: number,borderColor?: string,borderRadius?: number,opacity?: number,rotation?: number,background?: string,output?: ImageFormat): URL { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -334,57 +329,57 @@ export class Storage extends Service { } const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/preview'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - const payload: Payload = {}; + const params: Params = {}; if (typeof width !== 'undefined') { - payload['width'] = width; + params['width'] = width; } if (typeof height !== 'undefined') { - payload['height'] = height; + params['height'] = height; } if (typeof gravity !== 'undefined') { - payload['gravity'] = gravity; + params['gravity'] = gravity; } if (typeof quality !== 'undefined') { - payload['quality'] = quality; + params['quality'] = quality; } if (typeof borderWidth !== 'undefined') { - payload['borderWidth'] = borderWidth; + params['borderWidth'] = borderWidth; } if (typeof borderColor !== 'undefined') { - payload['borderColor'] = borderColor; + params['borderColor'] = borderColor; } if (typeof borderRadius !== 'undefined') { - payload['borderRadius'] = borderRadius; + params['borderRadius'] = borderRadius; } if (typeof opacity !== 'undefined') { - payload['opacity'] = opacity; + params['opacity'] = opacity; } if (typeof rotation !== 'undefined') { - payload['rotation'] = rotation; + params['rotation'] = rotation; } if (typeof background !== 'undefined') { - payload['background'] = background; + params['background'] = background; } if (typeof output !== 'undefined') { - payload['output'] = output; + params['output'] = output; } const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; @@ -393,16 +388,14 @@ export class Storage extends Service { /** * 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. + * 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 { + getFileView(bucketId: string,fileId: string): URL { if (typeof bucketId === 'undefined') { throw new AppwriteException('Missing required parameter: "bucketId"'); } @@ -412,13 +405,13 @@ export class Storage extends Service { } const apiPath = '/storage/buckets/{bucketId}/files/{fileId}/view'.replace('{bucketId}', bucketId).replace('{fileId}', fileId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - payload['project'] = this.client.config.project; + params['project'] = this.client.config.project; - for (const [key, value] of Object.entries(Service.flatten(payload))) { + for (const [key, value] of Object.entries(Service.flatten(params))) { uri.searchParams.append(key, value); } return uri; diff --git a/src/services/teams.ts b/src/services/teams.ts index 88a71ec..5232e45 100644 --- a/src/services/teams.ts +++ b/src/services/teams.ts @@ -1,7 +1,8 @@ import { Service } from '../service'; import { AppwriteException, Client } from '../client'; +import { Payload } from '../payload'; import type { Models } from '../models'; -import type { UploadProgress, Payload } from '../client'; +import type { UploadProgress, Params } from '../client'; import * as FileSystem from 'expo-file-system'; import { Platform } from 'react-native'; @@ -16,38 +17,38 @@ export class Teams extends Service { /** * 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. + * 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> { + async list(queries?: string[],search?: string): Promise> { const apiPath = '/teams'; - const payload: Payload = {}; + const params: Params = {}; if (typeof queries !== 'undefined') { - payload['queries'] = queries; + params['queries'] = queries; } if (typeof search !== 'undefined') { - payload['search'] = search; + params['search'] = search; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * 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. + * 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 @@ -55,7 +56,7 @@ export class Teams extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async create(teamId: string, name: string, roles?: string[]): Promise> { + async create(teamId: string,name: string,roles?: string[]): Promise> { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -65,24 +66,27 @@ export class Teams extends Service { } const apiPath = '/teams'; - const payload: Payload = {}; + const params: Params = {}; if (typeof teamId !== 'undefined') { - payload['teamId'] = teamId; + params['teamId'] = teamId; } if (typeof name !== 'undefined') { - payload['name'] = name; + params['name'] = name; } if (typeof roles !== 'undefined') { - payload['roles'] = roles; + params['roles'] = roles; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** @@ -100,25 +104,28 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * Update name * - * Update the team's name by its unique ID. + * 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> { + async updateName(teamId: string,name: string): Promise> { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -128,23 +135,25 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); - const payload: Payload = {}; + const params: Params = {}; if (typeof name !== 'undefined') { - payload['name'] = name; + params['name'] = name; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } /** * Delete team * - * Delete a team using its ID. Only team members with the owner role can - * delete the team. + * Delete a team using its ID. Only team members with the owner role can delete the team. * * @param {string} teamId * @throws {AppwriteException} @@ -156,19 +165,21 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}'.replace('{teamId}', teamId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } /** * 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. + * 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 @@ -176,52 +187,42 @@ export class Teams extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async listMemberships(teamId: string, queries?: string[], search?: string): Promise { + async listMemberships(teamId: string,queries?: string[],search?: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); - const payload: Payload = {}; + const params: Params = {}; if (typeof queries !== 'undefined') { - payload['queries'] = queries; + params['queries'] = queries; } if (typeof search !== 'undefined') { - payload['search'] = search; + params['search'] = search; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) - * 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. - * + * 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](https://appwrite.io/docs/references/cloud/client-web/teams#updateMembershipStatus) 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 @@ -233,7 +234,7 @@ export class Teams extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async createMembership(teamId: string, roles: string[], email?: string, userId?: string, phone?: string, url?: string, name?: string): Promise { + async createMembership(teamId: string,roles: string[],email?: string,userId?: string,phone?: string,url?: string,name?: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -243,50 +244,52 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}/memberships'.replace('{teamId}', teamId); - const payload: Payload = {}; + const params: Params = {}; if (typeof email !== 'undefined') { - payload['email'] = email; + params['email'] = email; } if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof phone !== 'undefined') { - payload['phone'] = phone; + params['phone'] = phone; } if (typeof roles !== 'undefined') { - payload['roles'] = roles; + params['roles'] = roles; } if (typeof url !== 'undefined') { - payload['url'] = url; + params['url'] = url; } if (typeof name !== 'undefined') { - payload['name'] = name; + params['name'] = name; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('post', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('post', uri, apiHeaders, params); } /** * Get team membership * - * Get a team member by the membership unique id. All team members have read - * access for this resource. + * 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 { + async getMembership(teamId: string,membershipId: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -296,21 +299,22 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * Update membership * - * 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](https://appwrite.io/docs/permissions). - * + * 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](https://appwrite.io/docs/permissions). + * * @param {string} teamId * @param {string} membershipId @@ -318,7 +322,7 @@ export class Teams extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async updateMembership(teamId: string, membershipId: string, roles: string[]): Promise { + async updateMembership(teamId: string,membershipId: string,roles: string[]): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -332,31 +336,32 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - const payload: Payload = {}; + const params: Params = {}; if (typeof roles !== 'undefined') { - payload['roles'] = roles; + params['roles'] = roles; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** * 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. + * 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<{}> { + async deleteMembership(teamId: string,membershipId: string): Promise<{}> { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -366,24 +371,24 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}/memberships/{membershipId}'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('delete', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('delete', uri, apiHeaders, params); } /** * 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. - * + * 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 @@ -392,7 +397,7 @@ export class Teams extends Service { * @throws {AppwriteException} * @returns {Promise} */ - async updateMembershipStatus(teamId: string, membershipId: string, userId: string, secret: string): Promise { + async updateMembershipStatus(teamId: string,membershipId: string,userId: string,secret: string): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -410,28 +415,29 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}/memberships/{membershipId}/status'.replace('{teamId}', teamId).replace('{membershipId}', membershipId); - const payload: Payload = {}; + const params: Params = {}; if (typeof userId !== 'undefined') { - payload['userId'] = userId; + params['userId'] = userId; } if (typeof secret !== 'undefined') { - payload['secret'] = secret; + params['secret'] = secret; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('patch', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('patch', uri, apiHeaders, params); } /** * 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](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). + * 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](https://appwrite.io/docs/references/cloud/client-web/account#getPrefs). * * @param {string} teamId * @throws {AppwriteException} @@ -443,27 +449,28 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); - const payload: Payload = {}; + const params: Params = {}; const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('get', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('get', uri, apiHeaders, params); } /** * 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. + * 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 { + async updatePrefs(teamId: string,prefs: object): Promise { if (typeof teamId === 'undefined') { throw new AppwriteException('Missing required parameter: "teamId"'); } @@ -473,15 +480,18 @@ export class Teams extends Service { } const apiPath = '/teams/{teamId}/prefs'.replace('{teamId}', teamId); - const payload: Payload = {}; + const params: Params = {}; if (typeof prefs !== 'undefined') { - payload['prefs'] = prefs; + params['prefs'] = prefs; } const uri = new URL(this.client.config.endpoint + apiPath); - return await this.client.call('put', uri, { + + const apiHeaders: { [header: string]: string } = { 'content-type': 'application/json', - }, payload); + } + + return await this.client.call('put', uri, apiHeaders, params); } }; diff --git a/tsconfig.json b/tsconfig.json index 8a27d1f..d469a2f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,22 +1,33 @@ { "compilerOptions": { + "target": "esnext", + "module": "esnext", + "types": ["react-native"], + "lib": [ + "dom", + "es2019", + "es2020.bigint", + "es2020.date", + "es2020.number", + "es2020.promise", + "es2020.string", + "es2020.symbol.wellknown", + "es2021.promise", + "es2021.string", + "es2021.weakref", + "es2022.array", + "es2022.object", + "es2022.string" + ], "allowJs": true, + "jsx": "react-native", + "isolatedModules": true, + "strict": true, + "moduleResolution": "node", + "resolveJsonModule": true, "allowSyntheticDefaultImports": true, - "baseUrl": "src", - "declaration": false, "esModuleInterop": true, - "inlineSourceMap": false, - "lib": ["ESNext", "DOM"], - "listEmittedFiles": false, - "listFiles": false, - "moduleResolution": "node", - "noFallthroughCasesInSwitch": true, - "pretty": true, - "rootDir": "src", - "skipLibCheck": true, - "strict": true, - "target": "ES6", - "traceResolution": false, + "skipLibCheck": true }, "compileOnSave": false, "exclude": ["node_modules", "dist"],