main
swift 78 lines 2.45 KB
Raw
1 import Foundation
2
3 /// Result of ``AuthCoreClient/login(username:password:)``.
4 ///
5 /// Mirrors `smbcloud_model::login::AccountStatus`, as mapped from the HTTP
6 /// response by the Rust SDK's `request_login`.
7 public enum AccountStatus: Sendable, Equatable {
8 /// No account matches the supplied email.
9 case notFound
10 /// Logged in. `accessToken` is the full `Authorization` header value — it
11 /// already includes the `Bearer ` prefix and is passed back verbatim to
12 /// ``AuthCoreClient/me(accessToken:)`` and friends.
13 case ready(accessToken: String)
14 /// The account exists but isn't usable yet (e.g. email unverified).
15 case incomplete(status: AccountErrorCode)
16 }
17
18 /// A tenant auth app end user, as returned by `GET /v1/client/me`.
19 ///
20 /// Mirrors `smbcloud_model::account::User` — the canonical SDK decodes only
21 /// these fields even though the backend payload carries more.
22 public struct User: Codable, Sendable, Equatable {
23 public let id: Int
24 public let email: String
25 public let createdAt: Date
26 public let updatedAt: Date
27
28 enum CodingKeys: String, CodingKey {
29 case id, email
30 case createdAt = "created_at"
31 case updatedAt = "updated_at"
32 }
33 }
34
35 /// Result of ``AuthCoreClient/signup(email:password:)``.
36 ///
37 /// Mirrors `smbcloud_model::signup::SignupResult`.
38 public struct SignupResult: Codable, Sendable, Equatable {
39 public let code: Int?
40 public let message: String
41 public let data: AccountData?
42 }
43
44 /// Mirrors `smbcloud_model::account::Data`.
45 public struct AccountData: Codable, Sendable, Equatable {
46 public let id: Int
47 public let email: String
48 public let createdAt: String
49
50 enum CodingKeys: String, CodingKey {
51 case id, email
52 case createdAt = "created_at"
53 }
54 }
55
56 // MARK: - Apple provider (tenant)
57
58 /// A prepared Apple sign-in authorization request (tenant plane).
59 ///
60 /// Mirrors `apple::AppleAuthorizationRequest`.
61 public struct AppleAuthorizationRequest: Sendable, Equatable {
62 public let authorizeURL: URL
63 public let redirectURI: String
64 public let state: String
65 }
66
67 /// The tenant auth session parsed from an Apple callback URL.
68 ///
69 /// Mirrors `apple::AppleAuthSession`.
70 public struct AppleAuthSession: Sendable, Equatable {
71 public let accessToken: String
72 public let refreshToken: String?
73 public let email: String?
74 public let name: String?
75 public let provider: String
76 public let providerAccountId: String
77 public let state: String?
78 }