Skip to content

Commit 3b20b48

Browse files
authored
Merge pull request #57 from appwrite/dev
fix: minor bugs
2 parents c39030d + 1ec6331 commit 3b20b48

22 files changed

+254
-171
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let package = Package(
2222
),
2323
],
2424
dependencies: [
25-
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.9.0"),
25+
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.17.0"),
2626
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
2727
],
2828
targets: [

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![Swift Package Manager](https://img.shields.io/github/v/release/appwrite/sdk-for-apple.svg?color=green&style=flat-square)
44
![License](https://img.shields.io/github/license/appwrite/sdk-for-apple.svg?style=flat-square)
5-
![Version](https://img.shields.io/badge/api%20version-1.5.0-blue.svg?style=flat-square)
5+
![Version](https://img.shields.io/badge/api%20version-1.5.6-blue.svg?style=flat-square)
66
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
77
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
88
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
@@ -31,7 +31,7 @@ Add the package to your `Package.swift` dependencies:
3131

3232
```swift
3333
dependencies: [
34-
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "5.0.0"),
34+
.package(url: "[email protected]:appwrite/sdk-for-apple.git", from: "6.0.0"),
3535
],
3636
```
3737

Sources/Appwrite/Client.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class Client {
2323
"x-sdk-name": "Apple",
2424
"x-sdk-platform": "client",
2525
"x-sdk-language": "apple",
26-
"x-sdk-version": "5.0.0",
26+
"x-sdk-version": "6.0.0",
2727
"x-appwrite-response-format": "1.5.0"
2828
]
2929

@@ -577,6 +577,8 @@ extension Client {
577577
return "tvos"
578578
#elseif os(macOS)
579579
return "macos"
580+
#elseif os(visionOS)
581+
return "visionos"
580582
#elseif os(Linux)
581583
return "linux"
582584
#elseif os(Windows)

Sources/Appwrite/DeviceInfo/OSDeviceInfo.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
class OSDeviceInfo {
44

5-
#if os(iOS) || os(tvOS)
5+
#if os(iOS) || os(tvOS) || os(visionOS)
66
var iOSInfo: IOSDeviceInfo?
77
#elseif os(watchOS)
88
var watchOSInfo: WatchOSDeviceInfo?
@@ -15,7 +15,7 @@ class OSDeviceInfo {
1515
#endif
1616

1717
init() {
18-
#if os(iOS) || os(tvOS)
18+
#if os(iOS) || os(tvOS) || os(visionOS)
1919
self.iOSInfo = IOSDeviceInfo()
2020
#elseif os(watchOS)
2121
self.watchOSInfo = WatchOSDeviceInfo()

Sources/Appwrite/DeviceInfo/iOS/IOSDeviceInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS) || os(tvOS)
1+
#if os(iOS) || os(tvOS) || os(visionOS)
22
import Foundation
33
import UIKit
44

Sources/Appwrite/DeviceInfo/iOS/UIDevice+ModelName.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS) || os(tvOS)
1+
#if os(iOS) || os(tvOS) || os(visionOS)
22
import Foundation
33
import UIKit
44

@@ -82,7 +82,7 @@ public extension UIDevice {
8282
case "iPad8,5", "iPad8,6", "iPad8,7", "iPad8,8": return "iPad Pro (12.9-inch) (3rd generation)"
8383
case "iPad8,11", "iPad8,12": return "iPad Pro (12.9-inch) (4th generation)"
8484
case "iPad13,8", "iPad13,9", "iPad13,10", "iPad13,11":return "iPad Pro (12.9-inch) (5th generation)"
85-
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
85+
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "iOS"))"
8686
default: return identifier
8787
#elseif os(tvOS)
8888
case "AppleTV1,1": return "Apple TV (1st generation)"
@@ -91,8 +91,12 @@ public extension UIDevice {
9191
case "AppleTV5,3": return "Apple TV (4th generation)"
9292
case "AppleTV6,2": return "Apple TV 4K (1st generation)"
9393
case "AppleTV11,1": return "Apple TV 4K (2nd generation)"
94-
case "i386", "x86_64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))"
95-
default: return identifier
94+
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "tvOS"))"
95+
default: return identifier
96+
#elseif os(visionOS)
97+
case "RealityDevice14,1": return "Apple Vision Pro"
98+
case "i386", "x86_64", "arm64": return "Simulator \(mapToDevice(identifier: ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "visionOS"))"
99+
default: return identifier
96100
#endif
97101
}
98102
}

Sources/Appwrite/ID.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1+
import Foundation
2+
13
public class ID {
4+
// Generate an hex ID based on timestamp
5+
// Recreated from https://www.php.net/manual/en/function.uniqid.php
6+
private static func hexTimestamp() -> String {
7+
let now = Date()
8+
let secs = Int(now.timeIntervalSince1970)
9+
let usec = Int((now.timeIntervalSince1970 - Double(secs)) * 1_000_000)
10+
let hexTimestamp = String(format: "%08x%05x", secs, usec)
11+
return hexTimestamp
12+
}
13+
214
public static func custom(_ id: String) -> String {
315
return id
416
}
517

6-
public static func unique() -> String {
7-
return "unique()"
18+
// Generate a unique ID with padding to have a longer ID
19+
public static func unique(padding: Int = 7) -> String {
20+
let baseId = Self.hexTimestamp()
21+
let randomPadding = (1...padding).map {
22+
_ in String(format: "%x", Int.random(in: 0..<16))
23+
}.joined()
24+
return baseId + randomPadding
825
}
9-
}
26+
}

Sources/Appwrite/Models/RealtimeModels.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import Foundation
22

33
public class RealtimeSubscription {
4-
public var close: () -> Void
4+
private var close: () async throws -> Void
55

6-
init(close: @escaping () -> Void) {
6+
init(close: @escaping () async throws-> Void) {
77
self.close = close
88
}
9+
10+
public func close() async throws {
11+
try await self.close()
12+
}
913
}
1014

1115
public class RealtimeCallback {
@@ -14,7 +18,7 @@ public class RealtimeCallback {
1418

1519
init(
1620
for channels: Set<String>,
17-
and callback: @escaping (RealtimeResponseEvent) -> Void
21+
with callback: @escaping (RealtimeResponseEvent) -> Void
1822
) {
1923
self.channels = channels
2024
self.callback = callback

Sources/Appwrite/OAuth/View+OAuth.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
typealias OSApplication = NSApplication
33
typealias OSViewController = NSViewController
44
let notificationType = NSApplication.willBecomeActiveNotification
5-
#elseif os(iOS) || os(tvOS)
5+
#elseif os(iOS) || os(tvOS) || os(visionOS)
66
typealias OSApplication = UIApplication
77
typealias OSViewController = UIViewController
88
let notificationType = UIApplication.willEnterForegroundNotification
@@ -14,7 +14,7 @@ let notificationType = WKApplication.willEnterForegroundNotification
1414

1515
#if canImport(SwiftUI)
1616
import SwiftUI
17-
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
17+
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, visionOS 1.0, *)
1818
extension View {
1919
public func registerOAuthHandler() -> some View {
2020
onOpenURL { url in
@@ -27,12 +27,12 @@ extension View {
2727
#endif
2828

2929
#if canImport(OSViewController)
30-
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
30+
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, visionOS 1.0, *)
3131
extension OSViewController {
3232
public func registerOAuthHandler() {
3333
#if os(macOS)
3434
typealias OSHostingController = NSHostingController
35-
#elseif os(iOS) || os(tvOS) || os(watchOS)
35+
#elseif os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
3636
typealias OSHostingController = UIHostingController
3737
#endif
3838
self.addChild(OSHostingController(rootView: EmptyView().registerOAuthHandler()))

Sources/Appwrite/OAuth/WebAuthComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import SwiftUI
1010
/// Used to authenticate with external OAuth2 providers. Launches browser windows and handles
1111
/// suspension until the user completes the process or otherwise returns to the app.
1212
///
13-
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
13+
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, visionOS 1.0, *)
1414
public class WebAuthComponent {
1515

1616
#if canImport(SwiftUI)

Sources/Appwrite/PackageInfo/OSPackageInfo.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
class OSPackageInfo {
44

55
public static func get() -> PackageInfo {
6-
#if os(iOS) || os(watchOS) || os(tvOS) || os(macOS)
6+
#if os(iOS) || os(watchOS) || os(tvOS) || os(macOS) || os(visionOS)
77
return PackageInfo.getApplePackage()
88
#elseif os(Linux)
99
return PackageInfo.getLinuxPackage()

Sources/Appwrite/Services/Account.swift

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ open class Account: Service {
406406
///
407407
/// Add an authenticator app to be used as an MFA factor. Verify the
408408
/// authenticator using the [verify
409-
/// authenticator](/docs/references/cloud/client-web/account#verifyAuthenticator)
409+
/// authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator)
410410
/// method.
411411
///
412412
/// @param AppwriteEnums.AuthenticatorType type
@@ -442,8 +442,8 @@ open class Account: Service {
442442
/// Verify Authenticator
443443
///
444444
/// Verify an authenticator app after adding it using the [add
445-
/// authenticator](/docs/references/cloud/client-web/account#addAuthenticator)
446-
/// method.
445+
/// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
446+
/// method. add
447447
///
448448
/// @param AppwriteEnums.AuthenticatorType type
449449
/// @param String otp
@@ -483,8 +483,8 @@ open class Account: Service {
483483
/// Verify Authenticator
484484
///
485485
/// Verify an authenticator app after adding it using the [add
486-
/// authenticator](/docs/references/cloud/client-web/account#addAuthenticator)
487-
/// method.
486+
/// authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator)
487+
/// method. add
488488
///
489489
/// @param AppwriteEnums.AuthenticatorType type
490490
/// @param String otp
@@ -512,11 +512,10 @@ open class Account: Service {
512512
/// @throws Exception
513513
/// @return array
514514
///
515-
open func deleteMfaAuthenticator<T>(
515+
open func deleteMfaAuthenticator(
516516
type: AppwriteEnums.AuthenticatorType,
517-
otp: String,
518-
nestedType: T.Type
519-
) async throws -> AppwriteModels.User<T> {
517+
otp: String
518+
) async throws -> Any {
520519
let apiPath: String = "/account/mfa/authenticators/{type}"
521520
.replacingOccurrences(of: "{type}", with: type.rawValue)
522521

@@ -528,38 +527,11 @@ open class Account: Service {
528527
"content-type": "application/json"
529528
]
530529

531-
let converter: (Any) -> AppwriteModels.User<T> = { response in
532-
return AppwriteModels.User.from(map: response as! [String: Any])
533-
}
534-
535530
return try await client.call(
536531
method: "DELETE",
537532
path: apiPath,
538533
headers: apiHeaders,
539-
params: apiParams,
540-
converter: converter
541-
)
542-
}
543-
544-
///
545-
/// Delete Authenticator
546-
///
547-
/// Delete an authenticator for a user by ID.
548-
///
549-
/// @param AppwriteEnums.AuthenticatorType type
550-
/// @param String otp
551-
/// @throws Exception
552-
/// @return array
553-
///
554-
open func deleteMfaAuthenticator(
555-
type: AppwriteEnums.AuthenticatorType,
556-
otp: String
557-
) async throws -> AppwriteModels.User<[String: AnyCodable]> {
558-
return try await deleteMfaAuthenticator(
559-
type: type,
560-
otp: otp,
561-
nestedType: [String: AnyCodable].self
562-
)
534+
params: apiParams )
563535
}
564536

565537
///

0 commit comments

Comments
 (0)