diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cb1cca..3d73a86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 13.1.0 + +* Deprecate `createVerification` method in `Account` service +* Add `createEmailVerification` method in `Account` service + ## 10.2.0 * Update sdk to use swift-native doc comments instead of jsdoc styled comments as per [Swift Documentation Comments](https://github.com/swiftlang/swift/blob/main/docs/DocumentationComments.md) diff --git a/README.md b/README.md index 354b98e..c3f4c35 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Add the package to your `Package.swift` dependencies: ```swift dependencies: [ - .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "13.0.0"), + .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "13.1.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index 45e3769..39905ff 100644 --- a/Sources/Appwrite/Client.swift +++ b/Sources/Appwrite/Client.swift @@ -21,7 +21,7 @@ open class Client { "x-sdk-name": "Swift", "x-sdk-platform": "server", "x-sdk-language": "swift", - "x-sdk-version": "13.0.0", + "x-sdk-version": "13.1.0", "x-appwrite-response-format": "1.8.0" ] diff --git a/Sources/Appwrite/Services/Account.swift b/Sources/Appwrite/Services/Account.swift index 2505dd3..e9a9d4d 100644 --- a/Sources/Appwrite/Services/Account.swift +++ b/Sources/Appwrite/Services/Account.swift @@ -2028,10 +2028,59 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Token /// + open func createEmailVerification( + url: String + ) async throws -> AppwriteModels.Token { + let apiPath: String = "/account/verifications/email" + + let apiParams: [String: Any?] = [ + "url": url + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Token = { response in + return AppwriteModels.Token.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "POST", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: 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. + /// + /// + /// - Parameters: + /// - url: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Token + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.createEmailVerification` instead.") open func createVerification( url: String ) async throws -> AppwriteModels.Token { - let apiPath: String = "/account/verification" + let apiPath: String = "/account/verifications/email" let apiParams: [String: Any?] = [ "url": url @@ -2066,11 +2115,52 @@ open class Account: Service { /// - Throws: Exception if the request fails /// - Returns: AppwriteModels.Token /// + open func updateEmailVerification( + userId: String, + secret: String + ) async throws -> AppwriteModels.Token { + let apiPath: String = "/account/verifications/email" + + let apiParams: [String: Any?] = [ + "userId": userId, + "secret": secret + ] + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + let converter: (Any) -> AppwriteModels.Token = { response in + return AppwriteModels.Token.from(map: response as! [String: Any]) + } + + return try await client.call( + method: "PUT", + path: apiPath, + headers: apiHeaders, + params: apiParams, + converter: 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. + /// + /// - Parameters: + /// - userId: String + /// - secret: String + /// - Throws: Exception if the request fails + /// - Returns: AppwriteModels.Token + /// + @available(*, deprecated, message: "This API has been deprecated since 1.8.0. Please use `Account.updateEmailVerification` instead.") open func updateVerification( userId: String, secret: String ) async throws -> AppwriteModels.Token { - let apiPath: String = "/account/verification" + let apiPath: String = "/account/verifications/email" let apiParams: [String: Any?] = [ "userId": userId, @@ -2109,7 +2199,7 @@ open class Account: Service { /// open func createPhoneVerification( ) async throws -> AppwriteModels.Token { - let apiPath: String = "/account/verification/phone" + let apiPath: String = "/account/verifications/phone" let apiParams: [String: Any] = [:] @@ -2146,7 +2236,7 @@ open class Account: Service { userId: String, secret: String ) async throws -> AppwriteModels.Token { - let apiPath: String = "/account/verification/phone" + let apiPath: String = "/account/verifications/phone" let apiParams: [String: Any?] = [ "userId": userId, diff --git a/Sources/Appwrite/Services/Functions.swift b/Sources/Appwrite/Services/Functions.swift index a26353f..881d62f 100644 --- a/Sources/Appwrite/Services/Functions.swift +++ b/Sources/Appwrite/Services/Functions.swift @@ -514,7 +514,7 @@ open class Functions: Service { /// Create a deployment based on a template. /// /// Use this endpoint with combination of - /// [listTemplates](https://appwrite.io/docs/server/functions#listTemplates) to + /// [listTemplates](https://appwrite.io/docs/products/functions/templates) to /// find the template details. /// /// - Parameters: diff --git a/Sources/Appwrite/Services/Sites.swift b/Sources/Appwrite/Services/Sites.swift index 290e495..3fba7ba 100644 --- a/Sources/Appwrite/Services/Sites.swift +++ b/Sources/Appwrite/Services/Sites.swift @@ -505,8 +505,8 @@ open class Sites: Service { /// Create a deployment based on a template. /// /// Use this endpoint with combination of - /// [listTemplates](https://appwrite.io/docs/server/sites#listTemplates) to - /// find the template details. + /// [listTemplates](https://appwrite.io/docs/products/sites/templates) to find + /// the template details. /// /// - Parameters: /// - siteId: String diff --git a/Sources/Appwrite/Services/TablesDb.swift b/Sources/Appwrite/Services/TablesDb.swift index 8bbbf4c..56cdf05 100644 --- a/Sources/Appwrite/Services/TablesDb.swift +++ b/Sources/Appwrite/Services/TablesDb.swift @@ -227,7 +227,7 @@ open class TablesDB: Service { /// /// Create a new Table. Before using this route, you should create a new /// database resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// /// - Parameters: @@ -2062,7 +2062,7 @@ open class TablesDB: Service { /// /// 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) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// /// - Parameters: @@ -2112,7 +2112,7 @@ open class TablesDB: Service { /// /// 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) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// /// - Parameters: @@ -2144,7 +2144,7 @@ open class TablesDB: Service { /// /// Create new Rows. Before using this route, you should create a new table /// resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// /// - Parameters: @@ -2188,7 +2188,7 @@ open class TablesDB: Service { /// /// Create new Rows. Before using this route, you should create a new table /// resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// /// - Parameters: @@ -2214,7 +2214,7 @@ open class TablesDB: Service { /// /// Create or update Rows. Before using this route, you should create a new /// table resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// /// @@ -2259,7 +2259,7 @@ open class TablesDB: Service { /// /// Create or update Rows. Before using this route, you should create a new /// table resource using either a [server - /// integration](https://appwrite.io/docs/server/tablesdb#tablesDBCreateTable) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// /// @@ -2494,7 +2494,7 @@ open class TablesDB: Service { /// /// 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) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// /// - Parameters: @@ -2544,7 +2544,7 @@ open class TablesDB: Service { /// /// 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) + /// integration](https://appwrite.io/docs/references/cloud/server-dart/tablesDB#createTable) /// API or directly from your database console. /// /// - Parameters: diff --git a/docs/examples/account/create-email-verification.md b/docs/examples/account/create-email-verification.md new file mode 100644 index 0000000..788fd95 --- /dev/null +++ b/docs/examples/account/create-email-verification.md @@ -0,0 +1,13 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let account = Account(client) + +let token = try await account.createEmailVerification( + url: "https://example.com" +) + diff --git a/docs/examples/account/update-email-verification.md b/docs/examples/account/update-email-verification.md new file mode 100644 index 0000000..10c8afe --- /dev/null +++ b/docs/examples/account/update-email-verification.md @@ -0,0 +1,14 @@ +import Appwrite + +let client = Client() + .setEndpoint("https://.cloud.appwrite.io/v1") // Your API Endpoint + .setProject("") // Your project ID + .setSession("") // The user session to authenticate with + +let account = Account(client) + +let token = try await account.updateEmailVerification( + userId: "", + secret: "" +) +