Skip to content

Commit

Permalink
Update lexicon models, methods to latest changes
Browse files Browse the repository at this point in the history
The following lexicon methods and models have been edited:
- ComAtprotoServerCreateAppPassword
- CreateAppPassword
- ComAtprotoServerListAppPasswords
  • Loading branch information
MasterJ93 committed Jun 2, 2024
1 parent 9c5b8f6 commit 605d447
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ extension ComAtprotoLexicon.Server {
/// - Note: According to the AT Protocol specifications: "A short name for the
/// App Password, to help distinguish them."
public let name: String

/// Indicates whether this App Password can be used to access sensitive content from
/// the user account.
///
/// - Note: According to the AT Protocol specifications: "If an app password has
/// 'privileged' access to possibly sensitive account state. Meant for use with
/// trusted clients."
public let isPrivileged: Bool?

enum CodingKeys: String, CodingKey {
case name
case isPrivileged = "privileged"
}
}

/// An output model for creating an App Password.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,36 @@ extension ComAtprotoLexicon.Server {
/// The date and date the App Password was created.
@DateFormatting public var createdAt: Date

public init(name: String, createdAt: Date) {
/// Indicates whether this App Password can be used to access sensitive content from
/// the user account.
public let isPrivileged: Bool?

public init(name: String, createdAt: Date, isPrivileged: Bool?) {
self.name = name
self._createdAt = DateFormatting(wrappedValue: createdAt)
self.isPrivileged = isPrivileged
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

self.name = try container.decode(String.self, forKey: .name)
self.createdAt = try container.decode(DateFormatting.self, forKey: .createdAt).wrappedValue
self.isPrivileged = try container.decodeIfPresent(Bool.self, forKey: .isPrivileged)
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

try container.encode(self.name, forKey: .name)
try container.encode(self._createdAt, forKey: .createdAt)
try container.encodeIfPresent(self.isPrivileged, forKey: .isPrivileged)
}

enum CodingKeys: CodingKey {
enum CodingKeys: String, CodingKey {
case name
case createdAt
case isPrivileged = "privileged"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extension ToolsOzoneLexicon.Moderation {
/// The subject handle of the event view. Optional.
public var subjectHandle: String?

public init(id: Int, event: ATUnion.ModerationEventViewUnion, subject: ATUnion.ModerationEventViewSubjectUnion, subjectBlobCIDHashes: [String], createdBy: String,
createdAt: Date, creatorHandle: String?, subjectHandle: String?) {
public init(id: Int, event: ATUnion.ModerationEventViewUnion, subject: ATUnion.ModerationEventViewSubjectUnion, subjectBlobCIDHashes: [String],
createdBy: String, createdAt: Date, creatorHandle: String?, subjectHandle: String?) {
self.id = id
self.event = event
self.subject = subject
Expand Down Expand Up @@ -115,8 +115,8 @@ extension ToolsOzoneLexicon.Moderation {
/// The date and time the event view was created.
@DateFormatting public var createdAt: Date

public init(id: Int, event: ATUnion.ModerationEventViewDetailUnion, subject: ATUnion.ModerationEventViewDetailSubjectUnion, subjectBlobs: [ToolsOzoneLexicon.Moderation.BlobViewDefinition],
createdBy: String, createdAt: Date) {
public init(id: Int, event: ATUnion.ModerationEventViewDetailUnion, subject: ATUnion.ModerationEventViewDetailSubjectUnion,
subjectBlobs: [ToolsOzoneLexicon.Moderation.BlobViewDefinition], createdBy: String, createdAt: Date) {
self.id = id
self.event = event
self.subject = subject
Expand Down Expand Up @@ -232,10 +232,10 @@ extension ToolsOzoneLexicon.Moderation {
/// An array of tags. Optional.
public var tags: [String]?

public init(id: Int, subject: ATUnion.SubjectStatusViewSubjectUnion, subjectBlobCIDHashes: [String]?, subjectRepoHandle: String?, updatedAt: Date, createdAt: Date,
reviewState: ToolsOzoneLexicon.Moderation.SubjectReviewStateDefinition, comment: String?, muteUntil: Date?, muteReportingUntil: Date?,
lastReviewedBy: String?, lastReviewedAt: Date?, lastReportedAt: Date?, lastAppealedAt: Date?, isTakenDown: Bool?, wasAppealed: Bool?,
suspendUntil: Date?, tags: [String]?) {
public init(id: Int, subject: ATUnion.SubjectStatusViewSubjectUnion, subjectBlobCIDHashes: [String]?, subjectRepoHandle: String?, updatedAt: Date,
createdAt: Date, reviewState: ToolsOzoneLexicon.Moderation.SubjectReviewStateDefinition, comment: String?, muteUntil: Date?,
muteReportingUntil: Date?, lastReviewedBy: String?, lastReviewedAt: Date?, lastReportedAt: Date?, lastAppealedAt: Date?, isTakenDown: Bool?,
wasAppealed: Bool?, suspendUntil: Date?, tags: [String]?) {
self.id = id
self.subject = subject
self.subjectBlobCIDHashes = subjectBlobCIDHashes
Expand Down Expand Up @@ -689,8 +689,8 @@ extension ToolsOzoneLexicon.Moderation {
public var inviteNote: String?

public init(actorDID: String, handle: String, email: String? = nil, relatedRecords: UnknownType, indexedAt: Date,
moderation: ToolsOzoneLexicon.Moderation.ModerationDefinition, invitedBy: ComAtprotoLexicon.Server.InviteCodeDefinition? = nil, areInvitesDisabled: Bool? = nil,
inviteNote: String? = nil) {
moderation: ToolsOzoneLexicon.Moderation.ModerationDefinition, invitedBy: ComAtprotoLexicon.Server.InviteCodeDefinition? = nil,
areInvitesDisabled: Bool? = nil, inviteNote: String? = nil) {
self.actorDID = actorDID
self.handle = handle
self.email = email
Expand Down
14 changes: 10 additions & 4 deletions Sources/ATProtoKit/Networking/CoreAPI/CreateAppPassword.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ extension ATProtoKit {
///
/// [github]: https://github.com/bluesky-social/atproto/blob/main/lexicons/com/atproto/server/createAppPassword.json
///
/// - Parameter passwordName: The name given to the App Password to help distingush it
/// from others.
/// - Parameters:
/// - passwordName: The name given to the App Password to help distingush it from others.
/// - isPrivileged: Indicates whether this App Password can be used to access sensitive
/// content from the user account.
/// - Returns: A `Result`, either containing a ``ComAtprotoLexicon/Server/CreateAppPasswordOutput``
/// if successful, or an `Error` if not.
public func createAppPassword(named passwordName: String) async throws -> Result<ComAtprotoLexicon.Server.CreateAppPasswordOutput, Error> {
public func createAppPassword(
named passwordName: String,
isPrivileged: Bool?
) async throws -> Result<ComAtprotoLexicon.Server.CreateAppPasswordOutput, Error> {
guard session != nil,
let accessToken = session?.accessToken else {
return .failure(ATRequestPrepareError.missingActiveSession)
Expand All @@ -37,7 +42,8 @@ extension ATProtoKit {
}

let requestBody = ComAtprotoLexicon.Server.CreateAppPasswordRequestBody(
name: passwordName
name: passwordName,
isPrivileged: isPrivileged
)

do {
Expand Down

0 comments on commit 605d447

Please sign in to comment.