diff --git a/LICENSE b/LICENSE index 5479bb8..c1602fc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors. +Copyright (c) 2025 Appwrite (https://appwrite.io) and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.md b/README.md index c670df4..160afa8 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: "6.2.0"), + .package(url: "git@github.com:appwrite/sdk-for-swift.git", from: "7.0.0"), ], ``` diff --git a/Sources/Appwrite/Client.swift b/Sources/Appwrite/Client.swift index ecd48cd..1b39b35 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": "6.2.0", + "x-sdk-version": "7.0.0", "x-appwrite-response-format": "1.6.0" ] @@ -257,6 +257,26 @@ open class Client { ) ?? "" } + /// + /// Sends a "ping" request to Appwrite to verify connectivity. + /// + /// @return String + /// @throws Exception + /// + open func ping() async throws -> String { + let apiPath: String = "/ping" + + let apiHeaders: [String: String] = [ + "content-type": "application/json" + ] + + return try await call( + method: "GET", + path: apiPath, + headers: apiHeaders + ) + } + /// /// Make an API call /// @@ -392,15 +412,18 @@ open class Client { } } + var data = try await response.body.collect(upTo: Int.max) + switch response.status.code { case 0..<400: switch T.self { case is Bool.Type: return true as! T + case is String.Type: + return (data.readString(length: data.readableBytes) ?? "") as! T case is ByteBuffer.Type: - return try await response.body.collect(upTo: Int.max) as! T + return data as! T default: - let data = try await response.body.collect(upTo: Int.max) if data.readableBytes == 0 { return true as! T } @@ -410,7 +433,6 @@ open class Client { } default: var message = "" - var data = try await response.body.collect(upTo: Int.max) var type = "" do { @@ -466,7 +488,7 @@ open class Client { var offset = 0 var result = [String:Any]() - if idParamName != nil && params[idParamName!] as! String != "unique()" { + if idParamName != nil { // Make a request to check if a file already exists do { let map = try await call( diff --git a/Sources/Appwrite/Services/Account.swift b/Sources/Appwrite/Services/Account.swift index 2bf91c7..cce7e89 100644 --- a/Sources/Appwrite/Services/Account.swift +++ b/Sources/Appwrite/Services/Account.swift @@ -584,7 +584,7 @@ open class Account: Service { open func updateMfaChallenge( challengeId: String, otp: String - ) async throws -> Any { + ) async throws -> AppwriteModels.Session { let apiPath: String = "/account/mfa/challenge" let apiParams: [String: Any?] = [ @@ -596,11 +596,17 @@ open class Account: Service { "content-type": "application/json" ] + let converter: (Any) -> AppwriteModels.Session = { response in + return AppwriteModels.Session.from(map: response as! [String: Any]) + } + return try await client.call( method: "PUT", path: apiPath, headers: apiHeaders, - params: apiParams ) + params: apiParams, + converter: converter + ) } /// diff --git a/Sources/Appwrite/Services/Functions.swift b/Sources/Appwrite/Services/Functions.swift index ba39620..28d5963 100644 --- a/Sources/Appwrite/Services/Functions.swift +++ b/Sources/Appwrite/Services/Functions.swift @@ -572,6 +572,12 @@ open class Functions: Service { /// /// Rebuild deployment /// + /// Create a new build for an existing function deployment. This endpoint + /// allows you to rebuild a deployment with the updated function configuration, + /// including its entrypoint and build commands if they have been modified The + /// build process will be queued and executed asynchronously. The original + /// deployment's code will be preserved and used for the new build. + /// /// @param String functionId /// @param String deploymentId /// @param String buildId @@ -605,6 +611,12 @@ open class Functions: Service { /// /// Cancel deployment /// + /// Cancel an ongoing function deployment build. If the build is already in + /// progress, it will be stopped and marked as canceled. If the build hasn't + /// started yet, it will be marked as canceled without executing. You cannot + /// cancel builds that have already completed (status 'ready') or failed. The + /// response includes the final build status and details. + /// /// @param String functionId /// @param String deploymentId /// @throws Exception diff --git a/Sources/Appwrite/Services/Messaging.swift b/Sources/Appwrite/Services/Messaging.swift index e785a42..636fbe1 100644 --- a/Sources/Appwrite/Services/Messaging.swift +++ b/Sources/Appwrite/Services/Messaging.swift @@ -418,7 +418,7 @@ open class Messaging: Service { /// /// Update SMS /// - /// Update an email message by its unique ID. + /// Update an SMS message by its unique ID. /// /// /// @param String messageId diff --git a/Sources/Appwrite/Services/Users.swift b/Sources/Appwrite/Services/Users.swift index f9e7361..3b78b8a 100644 --- a/Sources/Appwrite/Services/Users.swift +++ b/Sources/Appwrite/Services/Users.swift @@ -1217,11 +1217,10 @@ open class Users: Service { /// @throws Exception /// @return array /// - open func deleteMfaAuthenticator( + open func deleteMfaAuthenticator( userId: String, - type: AppwriteEnums.AuthenticatorType, - nestedType: T.Type - ) async throws -> AppwriteModels.User { + type: AppwriteEnums.AuthenticatorType + ) async throws -> Any { let apiPath: String = "/users/{userId}/mfa/authenticators/{type}" .replacingOccurrences(of: "{userId}", with: userId) .replacingOccurrences(of: "{type}", with: type.rawValue) @@ -1232,38 +1231,11 @@ open class Users: Service { "content-type": "application/json" ] - let converter: (Any) -> AppwriteModels.User = { response in - return AppwriteModels.User.from(map: response as! [String: Any]) - } - return try await client.call( method: "DELETE", path: apiPath, headers: apiHeaders, - params: apiParams, - converter: converter - ) - } - - /// - /// Delete authenticator - /// - /// Delete an authenticator app. - /// - /// @param String userId - /// @param AppwriteEnums.AuthenticatorType type - /// @throws Exception - /// @return array - /// - open func deleteMfaAuthenticator( - userId: String, - type: AppwriteEnums.AuthenticatorType - ) async throws -> AppwriteModels.User<[String: AnyCodable]> { - return try await deleteMfaAuthenticator( - userId: userId, - type: type, - nestedType: [String: AnyCodable].self - ) + params: apiParams ) } /// diff --git a/Sources/AppwriteEnums/ImageFormat.swift b/Sources/AppwriteEnums/ImageFormat.swift index 2081ed0..c31fb47 100644 --- a/Sources/AppwriteEnums/ImageFormat.swift +++ b/Sources/AppwriteEnums/ImageFormat.swift @@ -6,6 +6,7 @@ public enum ImageFormat: String, CustomStringConvertible { case gif = "gif" case png = "png" case webp = "webp" + case heic = "heic" case avif = "avif" public var description: String { diff --git a/docs/examples/account/update-mfa-challenge.md b/docs/examples/account/update-mfa-challenge.md index eed3bfa..fee76bf 100644 --- a/docs/examples/account/update-mfa-challenge.md +++ b/docs/examples/account/update-mfa-challenge.md @@ -7,7 +7,7 @@ let client = Client() let account = Account(client) -let result = try await account.updateMfaChallenge( +let session = try await account.updateMfaChallenge( challengeId: "", otp: "" ) diff --git a/docs/examples/users/delete-mfa-authenticator.md b/docs/examples/users/delete-mfa-authenticator.md index 902d0c9..5f1d6a0 100644 --- a/docs/examples/users/delete-mfa-authenticator.md +++ b/docs/examples/users/delete-mfa-authenticator.md @@ -8,7 +8,7 @@ let client = Client() let users = Users(client) -let user = try await users.deleteMfaAuthenticator( +let result = try await users.deleteMfaAuthenticator( userId: "", type: .totp )