Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdks 3608 add missing docs #18

Merged
merged 7 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Davinci/Davinci/Agent.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Agent.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand Down Expand Up @@ -50,6 +50,7 @@ internal class CreateAgent: Agent {

}


extension Session {
func authCode(pkce: Pkce?) -> AuthCode {
// parse the response and return the auth code
Expand Down
2 changes: 1 addition & 1 deletion Davinci/Davinci/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Constants.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand Down
5 changes: 4 additions & 1 deletion Davinci/Davinci/Davinci.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// DaVinci.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand All @@ -17,6 +17,9 @@ public typealias DaVinci = Workflow
public typealias DaVinciConfig = WorkflowConfig

extension DaVinci {
/// Method to create a DaVinci instance.
/// - Parameter block: The configuration block.
/// - Returns: The DaVinci instance.
public static func createDaVinci(block: (DaVinciConfig) -> Void = {_ in }) -> DaVinci {
let config = DaVinciConfig()
config.module(CustomHeader.config) { customHeaderConfig in
Expand Down
8 changes: 5 additions & 3 deletions Davinci/Davinci/User.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// User.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand Down Expand Up @@ -57,13 +57,15 @@ extension DaVinci {
}
}

/// Extension property for SuccessNodet o cast the `SuccessNode.session` to a User.

extension SuccessNode {
var user: User? {
/// Extension property for SuccessNode to cast the `SuccessNode.session` to a User.
public var user: User? {
return session as? User
}
}


/// Struct representing a UserDelegate.
/// This struct is a delegate for the User and Session interfaces.
/// It overrides the logout function to remove the cached user from the context and sign off the user.
Expand Down
7 changes: 5 additions & 2 deletions Davinci/Davinci/collector/Collector.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// FlowCollector.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand All @@ -17,7 +17,9 @@ public protocol Collector: Action, Identifiable {
init(with json: [String: Any])
}

extension ContinueNode {

extension ContinueNode {
/// Returns the list of collectors from the actions.
public var collectors: [any Collector] {
return actions.compactMap { $0 as? (any Collector) }
}
Expand All @@ -26,6 +28,7 @@ public protocol Collector: Action, Identifiable {
/// Type alias for a list of collectors.
public typealias Collectors = [any Collector]


extension Collectors {
/// Finds the event type from a list of collectors.
///This function iterates over the list of collectors and returns the value if the collector's value is not empty.
Expand Down
14 changes: 8 additions & 6 deletions Davinci/Davinci/collector/CollectorFactory.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// CollectorFactory.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand All @@ -14,10 +14,11 @@ import PingOrchestrate
/// The CollectorFactory singleton is responsible for creating and managing Collector instances.
/// It maintains a dictionary of collector creation functions, keyed by type.
/// It also provides functions to register new types of collectors and to create collectors from a JSON array.
final class CollectorFactory {
public final class CollectorFactory {
// A dictionary to hold the collector creation functions.
public var collectors: [String: any Collector.Type] = [:]

var collectors: [String: any Collector.Type] = [:]

/// The shared instance of the CollectorFactory.
public static let shared = CollectorFactory()

init() {
Expand All @@ -39,7 +40,7 @@ final class CollectorFactory {
/// Each dictionary should have a "type" field that matches a registered Collector type.
/// - Parameter array: The array of dictionaries to create the Collectors from.
/// - Returns: A list of Collector instances.
func collector(from array: [[String: Any]]) -> Collectors {
public func collector(from array: [[String: Any]]) -> Collectors {
var list: [any Collector] = []
for item in array {
if let type = item[Constants.type] as? String, let collectorType = collectors[type] {
Expand All @@ -49,7 +50,8 @@ final class CollectorFactory {
return list
}

func reset() {
/// Resets the CollectorFactory by clearing all registered collectors.
public func reset() {
collectors.removeAll()
}
}
10 changes: 7 additions & 3 deletions Davinci/Davinci/collector/FieldCollector.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// FieldCollector.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand All @@ -15,14 +15,18 @@ import Foundation
/// - property key: The key of the field collector.
/// - property label The label of the field collector.
/// - property value The value of the field collector. It's open for modification.
/// - property id The UUID of the field collector.
open class FieldCollector: Collector {
public var key: String = ""
public var label: String = ""
public var value: String = ""
public let id = UUID()


/// Initializes a new instance of `FieldCollector`.
public init() {}


/// Initializes a new instance of `FieldCollector`.
/// - Parameter json: The json to initialize from.
required public init(with json: [String: Any]) {
key = json[Constants.key] as? String ?? ""
label = json[Constants.label] as? String ?? ""
Expand Down
2 changes: 1 addition & 1 deletion Davinci/Davinci/collector/FlowCollector.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// FlowCollector.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand Down
3 changes: 1 addition & 2 deletions Davinci/Davinci/collector/Form.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Form.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand All @@ -14,7 +14,6 @@ import Foundation
/// Class that handles the parsing and JSON representation of collectors.
/// This class provides functions to parse a JSON object into a list of collectors and to represent a list of collectors as a JSON object.
class Form {

/// Parses a JSON object into a list of collectors.
/// This function takes a JSON object and extracts the "form" field. It then iterates over the "fields" array in the "components" object,
/// parsing each field into a collector and adding it to a list.
Expand Down
3 changes: 2 additions & 1 deletion Davinci/Davinci/collector/PasswordCollector.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// PasswordCollector.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand All @@ -16,6 +16,7 @@ import PingOrchestrate
/// This class inherits from the FieldCollector class and implements the Closeable and Collector protocols.
/// It is used to collect password data.
public class PasswordCollector: FieldCollector, Closeable {
/// A flag to determine whether to clear the password or not after submission.
public var clearPassword: Bool = true

/// Overrides the close function from the Closeable protocol.
Expand Down
2 changes: 1 addition & 1 deletion Davinci/Davinci/collector/SubmitCollector.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SubmitCollector.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand Down
2 changes: 1 addition & 1 deletion Davinci/Davinci/collector/TextCollector.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// TextCollector.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand Down
22 changes: 15 additions & 7 deletions Davinci/Davinci/module/Connector.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Connector.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand All @@ -10,24 +10,26 @@

import PingOrchestrate

/// Extension to get the id of a ContinueNode.
extension ContinueNode {
/// Extension property to get the id of a Connector.
public var id: String {
return (self as? Connector)?.idValue ?? ""
}

/// Extension property to get the name of a Connector.
public var name: String {
return (self as? Connector)?.nameValue ?? ""
}

/// Extension property to get the description of a Connector.
public var description: String {
return (self as? Connector)?.descriptionValue ?? ""
}

/// Extension property to get the category of a Connector.
public var category: String {
return (self as? Connector)?.categoryValue ?? ""
}

}


Expand All @@ -37,10 +39,16 @@ extension ContinueNode {
///- property input: The input JsonObject of the ContinueNode.
///- property collectors: The collectors of the ContinueNode.
class Connector: ContinueNode {

init(context: FlowContext, davinci: DaVinci, input: [String: Any], collectors: Collectors) {
super.init(context: context, workflow: davinci, input: input, actions: collectors)
}

/// Initializer to create a new instance of Connector.
/// - Parameters:
/// - context: The FlowContext of the ContinueNode.
/// - davinci: The Davinci Flow of the ContinueNode.
/// - input: The input JsonObject of the ContinueNode.
/// - collectors: The collectors of the ContinueNode.
init(context: FlowContext, davinci: DaVinci, input: [String: Any], collectors: Collectors) {
super.init(context: context, workflow: davinci, input: input, actions: collectors)
}

/// Function to convert the connector to a dictionary.
/// - returns: The connector as a JsonObject.
Expand Down
10 changes: 9 additions & 1 deletion Davinci/Davinci/module/Oidc.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// OIDC.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand All @@ -13,10 +13,13 @@ import Foundation
import PingOidc
import PingOrchestrate

/// A module that integrates OIDC capabilities into the DaVinci workflow.
public class OidcModule {

/// Initializes a new instance of `OidcModule`.
public init() {}

/// The configuration for the OIDC module.
public static let config: Module<OidcClientConfig> = Module.of ({ OidcClientConfig() }) { setup in

let config: OidcClientConfig = setup.config
Expand Down Expand Up @@ -75,7 +78,12 @@ public class OidcModule {
}

extension SharedContext.Keys {
/// The key used to store the PKCE value in the shared context.
public static let pkceKey = "com.pingidentity.davinci.PKCE"

/// The key used to store the user in the shared context.
public static let userKey = "com.pingidentity.davinci.User"

/// The key used to store the OIDC client configuration in the shared context.
public static let oidcClientConfigKey = "com.pingidentity.davinci.OidcClientConfig"
}
3 changes: 2 additions & 1 deletion Davinci/Davinci/module/Request.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Request.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand Down Expand Up @@ -59,6 +59,7 @@ extension OidcClientConfig {
}
}


extension OidcClient.Constants {
static let response_mode = "response_mode"
static let response_type = "response_type"
Expand Down
22 changes: 18 additions & 4 deletions Davinci/Davinci/module/Transform.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Transform.swift
// Davinci
// PingDavinci
//
// Copyright (c) 2024 Ping Identity. All rights reserved.
//
Expand All @@ -16,6 +16,7 @@ import PingOrchestrate
/// Module for transforming the response from DaVinci to `Node`.
public class NodeTransformModule {

/// The module configuration for transforming the response from DaVinci to `Node`.
public static let config: Module<Void> = Module.of(setup: { setup in
setup.transform { flowContext, response in
let status = response.status()
Expand Down Expand Up @@ -88,22 +89,35 @@ public class NodeTransformModule {
}
}

struct SessionResponse: Session {

/// Represents a session response parsed from a JSON object.
public struct SessionResponse: Session {
/// The raw JSON data of the session response.
public let json: [String: Any]

/// Initializes a new session response with the given JSON data.
/// - Parameter json: The JSON data representing the session response.
public init(json: [String: Any] = [:]) {
self.json = json
}

var value: String {
/// The session value extracted from the JSON response.
/// - Returns: A string representing the session code or an empty string if not available.
public var value: String {
get {
let authResponse = json[Constants.authorizeResponse] as? [String: Any]
return authResponse?[Constants.code] as? String ?? ""
}
}

}


/// Represents API errors that occur during response transformation.
public enum ApiError: Error {
/// An error containing an HTTP status code, a JSON object, and a descriptive message.
/// - Parameters:
/// - status: The HTTP status code of the error.
/// - json: The JSON data associated with the error.
/// - message: A descriptive message explaining the error.
case error(Int, [String: Any], String)
}
Loading