diff --git a/CHANGELOG.md b/CHANGELOG.md index 38d0c4b..b6b9e40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 11.1.0 + +* Deprecate `createVerification` method in `Account` service +* Add `createEmailVerification` method in `Account` service + ## 8.2.0 * Add `incrementDocumentAttribute` and `decrementDocumentAttribute` support to `Databases` service diff --git a/README.md b/README.md index 769492f..bd59ff0 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ repositories { Next, add the dependency to your project's `build.gradle(.kts)` file: ```groovy -implementation("io.appwrite:sdk-for-android:11.0.0") +implementation("io.appwrite:sdk-for-android:11.1.0") ``` ### Maven @@ -49,7 +49,7 @@ Add this to your project's `pom.xml` file: io.appwrite sdk-for-android - 11.0.0 + 11.1.0 ``` diff --git a/docs/examples/java/account/create-email-verification.md b/docs/examples/java/account/create-email-verification.md new file mode 100644 index 0000000..dfbf059 --- /dev/null +++ b/docs/examples/java/account/create-email-verification.md @@ -0,0 +1,22 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.createEmailVerification( + "https://example.com", // url + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + diff --git a/docs/examples/java/account/update-email-verification.md b/docs/examples/java/account/update-email-verification.md new file mode 100644 index 0000000..9d157c8 --- /dev/null +++ b/docs/examples/java/account/update-email-verification.md @@ -0,0 +1,23 @@ +import io.appwrite.Client; +import io.appwrite.coroutines.CoroutineCallback; +import io.appwrite.services.Account; + +Client client = new Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject(""); // Your project ID + +Account account = new Account(client); + +account.updateEmailVerification( + "", // userId + "", // secret + new CoroutineCallback<>((result, error) -> { + if (error != null) { + error.printStackTrace(); + return; + } + + Log.d("Appwrite", result.toString()); + }) +); + diff --git a/docs/examples/kotlin/account/create-email-verification.md b/docs/examples/kotlin/account/create-email-verification.md new file mode 100644 index 0000000..dc87901 --- /dev/null +++ b/docs/examples/kotlin/account/create-email-verification.md @@ -0,0 +1,13 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.createEmailVerification( + url = "https://example.com", +) \ No newline at end of file diff --git a/docs/examples/kotlin/account/update-email-verification.md b/docs/examples/kotlin/account/update-email-verification.md new file mode 100644 index 0000000..9fb21d2 --- /dev/null +++ b/docs/examples/kotlin/account/update-email-verification.md @@ -0,0 +1,14 @@ +import io.appwrite.Client +import io.appwrite.coroutines.CoroutineCallback +import io.appwrite.services.Account + +val client = Client(context) + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + +val account = Account(client) + +val result = account.updateEmailVerification( + userId = "", + secret = "", +) \ No newline at end of file diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index d29fb28..c046dff 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -87,7 +87,7 @@ class Client @JvmOverloads constructor( "x-sdk-name" to "Android", "x-sdk-platform" to "client", "x-sdk-language" to "android", - "x-sdk-version" to "11.0.0", + "x-sdk-version" to "11.1.0", "x-appwrite-response-format" to "1.8.0" ) config = mutableMapOf() diff --git a/library/src/main/java/io/appwrite/services/Account.kt b/library/src/main/java/io/appwrite/services/Account.kt index a3f94d3..9851a04 100644 --- a/library/src/main/java/io/appwrite/services/Account.kt +++ b/library/src/main/java/io/appwrite/services/Account.kt @@ -2029,10 +2029,49 @@ class Account(client: Client) : Service(client) { * @param url URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. * @return [io.appwrite.models.Token] */ + suspend fun createEmailVerification( + url: String, + ): io.appwrite.models.Token { + val apiPath = "/account/verifications/email" + + val apiParams = mutableMapOf( + "url" to url, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Token.from(map = it as Map) + } + return client.call( + "POST", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Token::class.java, + converter, + ) + } + + + /** + * 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 url URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API. + * @return [io.appwrite.models.Token] + */ + @Deprecated( + message = "This API has been deprecated since 1.8.0. Please use `Account.createEmailVerification` instead.", + replaceWith = ReplaceWith("io.appwrite.services.Account.createEmailVerification") + ) suspend fun createVerification( url: String, ): io.appwrite.models.Token { - val apiPath = "/account/verification" + val apiPath = "/account/verifications/email" val apiParams = mutableMapOf( "url" to url, @@ -2062,11 +2101,50 @@ class Account(client: Client) : Service(client) { * @param secret Valid verification token. * @return [io.appwrite.models.Token] */ + suspend fun updateEmailVerification( + userId: String, + secret: String, + ): io.appwrite.models.Token { + val apiPath = "/account/verifications/email" + + val apiParams = mutableMapOf( + "userId" to userId, + "secret" to secret, + ) + val apiHeaders = mutableMapOf( + "content-type" to "application/json", + ) + val converter: (Any) -> io.appwrite.models.Token = { + @Suppress("UNCHECKED_CAST") + io.appwrite.models.Token.from(map = it as Map) + } + return client.call( + "PUT", + apiPath, + apiHeaders, + apiParams, + responseType = io.appwrite.models.Token::class.java, + converter, + ) + } + + + /** + * 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 userId User ID. + * @param secret Valid verification token. + * @return [io.appwrite.models.Token] + */ + @Deprecated( + message = "This API has been deprecated since 1.8.0. Please use `Account.updateEmailVerification` instead.", + replaceWith = ReplaceWith("io.appwrite.services.Account.updateEmailVerification") + ) suspend fun updateVerification( userId: String, secret: String, ): io.appwrite.models.Token { - val apiPath = "/account/verification" + val apiPath = "/account/verifications/email" val apiParams = mutableMapOf( "userId" to userId, @@ -2097,7 +2175,7 @@ class Account(client: Client) : Service(client) { */ suspend fun createPhoneVerification( ): io.appwrite.models.Token { - val apiPath = "/account/verification/phone" + val apiPath = "/account/verifications/phone" val apiParams = mutableMapOf( ) @@ -2130,7 +2208,7 @@ class Account(client: Client) : Service(client) { userId: String, secret: String, ): io.appwrite.models.Token { - val apiPath = "/account/verification/phone" + val apiPath = "/account/verifications/phone" val apiParams = mutableMapOf( "userId" to userId, diff --git a/library/src/main/java/io/appwrite/services/TablesDb.kt b/library/src/main/java/io/appwrite/services/TablesDb.kt index 597ee8c..b05303f 100644 --- a/library/src/main/java/io/appwrite/services/TablesDb.kt +++ b/library/src/main/java/io/appwrite/services/TablesDb.kt @@ -18,7 +18,7 @@ class TablesDB(client: Client) : Service(client) { * Get a list of all the user's rows in a given table. You can use the query params to filter your results. * * @param databaseId Database ID. - * @param tableId Table ID. You can create a new table using the TableDB service [server integration](https://appwrite.io/docs/server/tablesdbdb#tablesdbCreate). + * @param tableId Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/products/databases/tables#create-table). * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @return [io.appwrite.models.RowList] */ @@ -56,7 +56,7 @@ class TablesDB(client: Client) : Service(client) { * Get a list of all the user's rows in a given table. You can use the query params to filter your results. * * @param databaseId Database ID. - * @param tableId Table ID. You can create a new table using the TableDB service [server integration](https://appwrite.io/docs/server/tablesdbdb#tablesdbCreate). + * @param tableId Table ID. You can create a new table using the TablesDB service [server integration](https://appwrite.io/docs/products/databases/tables#create-table). * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @return [io.appwrite.models.RowList] */ @@ -74,10 +74,10 @@ class TablesDB(client: Client) : Service(client) { ) /** - * Create a new Row. Before using this route, you should create a new table resource using either a [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) API or directly from your database console. + * Create a new Row. Before using this route, you should create a new table resource using either a [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) API or directly from your database console. * * @param databaseId Database ID. - * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate). Make sure to define columns before creating rows. + * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable). Make sure to define columns before creating rows. * @param rowId Row ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param data Row data as JSON object. * @param permissions An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). @@ -119,10 +119,10 @@ class TablesDB(client: Client) : Service(client) { } /** - * Create a new Row. Before using this route, you should create a new table resource using either a [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) API or directly from your database console. + * Create a new Row. Before using this route, you should create a new table resource using either a [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) API or directly from your database console. * * @param databaseId Database ID. - * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate). Make sure to define columns before creating rows. + * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable). Make sure to define columns before creating rows. * @param rowId Row ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. * @param data Row data as JSON object. * @param permissions An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions). @@ -149,7 +149,7 @@ class TablesDB(client: Client) : Service(client) { * Get a row by its unique ID. This endpoint response returns a JSON object with the row data. * * @param databaseId Database ID. - * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate). + * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable). * @param rowId Row ID. * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @return [io.appwrite.models.Row] @@ -190,7 +190,7 @@ class TablesDB(client: Client) : Service(client) { * Get a row by its unique ID. This endpoint response returns a JSON object with the row data. * * @param databaseId Database ID. - * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate). + * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable). * @param rowId Row ID. * @param queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. * @return [io.appwrite.models.Row] @@ -211,7 +211,7 @@ class TablesDB(client: Client) : Service(client) { ) /** - * Create or update a Row. Before using this route, you should create a new table resource using either a [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) API or directly from your database console. + * Create or update a Row. Before using this route, you should create a new table resource using either a [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) API or directly from your database console. * * @param databaseId Database ID. * @param tableId Table ID. @@ -256,7 +256,7 @@ class TablesDB(client: Client) : Service(client) { } /** - * Create or update a Row. Before using this route, you should create a new table resource using either a [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) API or directly from your database console. + * Create or update a Row. Before using this route, you should create a new table resource using either a [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) API or directly from your database console. * * @param databaseId Database ID. * @param tableId Table ID. @@ -358,7 +358,7 @@ class TablesDB(client: Client) : Service(client) { * Delete a row by its unique ID. * * @param databaseId Database ID. - * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreate). + * @param tableId Table ID. You can create a new table using the Database service [server integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable). * @param rowId Row ID. * @return [Any] */