value is only ever present in the create response (confirmed live — apiKeys.list never includes it), so the model and call sites treat it as a one-time reveal, not persisted state. expiresAt omitted (not null) for a non-expiring key, matches synthesized Encodable's default encodeIfPresent behavior.
41 lines
1.3 KiB
Swift
41 lines
1.3 KiB
Swift
import Foundation
|
|
|
|
/// A personal API key (Settings → API & Access). Only the last 4 characters
|
|
/// of the actual token are ever returned by the server — there's no way to
|
|
/// see a full key again after creation, matching every other API-key UI
|
|
/// convention.
|
|
public struct OutlineAPIKey: Codable, Identifiable, Hashable, Sendable {
|
|
public let id: String
|
|
public let name: String
|
|
public let last4: String?
|
|
public let scope: [String]?
|
|
public let createdAt: Date
|
|
public let expiresAt: Date?
|
|
public let lastActiveAt: Date?
|
|
/// The full plaintext key — present *only* in `apiKeys.create`'s
|
|
/// response, confirmed live: `apiKeys.list` never includes it, matching
|
|
/// "shown once at creation" being enforced server-side, not just a
|
|
/// client-side UI convention this app has to uphold on its own.
|
|
public let value: String?
|
|
|
|
public init(
|
|
id: String,
|
|
name: String,
|
|
last4: String? = nil,
|
|
scope: [String]? = nil,
|
|
createdAt: Date,
|
|
expiresAt: Date? = nil,
|
|
lastActiveAt: Date? = nil,
|
|
value: String? = nil
|
|
) {
|
|
self.id = id
|
|
self.name = name
|
|
self.last4 = last4
|
|
self.scope = scope
|
|
self.createdAt = createdAt
|
|
self.expiresAt = expiresAt
|
|
self.lastActiveAt = lastActiveAt
|
|
self.value = value
|
|
}
|
|
}
|