Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
142 changes: 79 additions & 63 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ class CollectAndRevealViewController: UIViewController {
print("Record failed:", error, "httpCode:", result.httpCode)
}
}
if let fields = response.records.first?.fields {
updateRevealInputs(tokens: fields)
if let tokens = response.records.first?.tokens {
updateRevealInputs(tokens: tokens)
}
print("Successfully got response:", response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ class ViewController: UIViewController {
// If a record with a matching card_number already exists, its fields are merged
// in (updateType: .UPDATE) instead of creating a duplicate row.
let upsertOptions = [
Skyflow.UpsertOption(table: "credit_cards", uniqueColumns: ["card_number"], updateType: .UPDATE)
Skyflow.UpsertOption(tableName: "credit_cards", uniqueColumns: ["card_number"], updateType: .UPDATE)
]

// additionalFields: extra records submitted alongside whatever's collected from
// the mounted elements, one entry per table.
let additionalFields = Skyflow.AdditionalFields(records: [
Skyflow.AdditionalFieldsRecord(table: "credit_cards", fields: ["billing_zip": "94105"])
Skyflow.AdditionalFieldsRecord(tableName: "credit_cards", data: ["billing_zip": "94105"])
])

container!.collect(callback: collectCallback, options: Skyflow.CollectOptions(additionalFields: additionalFields, upsert: upsertOptions))
Expand All @@ -212,8 +212,8 @@ class ViewController: UIViewController {
print("Record failed:", error, "httpCode:", result.httpCode)
}
}
if let fields = response.records.first?.fields {
updateRevealInputs(tokens: fields)
if let tokens = response.records.first?.tokens {
updateRevealInputs(tokens: tokens)
}
print("Successfully got response:", response)
}
Expand Down
4 changes: 2 additions & 2 deletions Samples/InputFormatting/InputFormatting/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ class ViewController: UIViewController {
print("Record failed:", error, "httpCode:", result.httpCode)
}
}
if let fields = response.records.first?.fields {
updateRevealInputs(tokens: fields)
if let tokens = response.records.first?.tokens {
updateRevealInputs(tokens: tokens)
}
print("Successfully got response:", response)
}
Expand Down
6 changes: 3 additions & 3 deletions Samples/UpsertFeature/UpsertFeature/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class ViewController: UIViewController {

@objc func submitForm() {
let collectCallback = Skyflow.CollectCallback(onSuccess: updateSuccess, onFailure: updateFailure)
let upsertOptions = [Skyflow.UpsertOption(table: "persons", uniqueColumns: ["cardnumber"], updateType: .UPDATE)]
let upsertOptions = [Skyflow.UpsertOption(tableName: "persons", uniqueColumns: ["cardnumber"], updateType: .UPDATE)]
container!.collect(callback: collectCallback, options: Skyflow.CollectOptions(upsert: upsertOptions))
}

Expand All @@ -180,8 +180,8 @@ class ViewController: UIViewController {
print("Record failed:", error, "httpCode:", result.httpCode)
}
}
if let fields = response.records.first?.fields {
updateRevealInputs(tokens: fields)
if let tokens = response.records.first?.tokens {
updateRevealInputs(tokens: tokens)
}
print("Successfully got response:", response)
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Skyflow/collect/AdditionalFields.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import Foundation

public struct AdditionalFieldsRecord {
public let table: String
public let fields: [String: Any]
public let tableName: String
public let data: [String: Any]
// Present to update an existing record, absent to insert a new one.
public let skyflowId: String?

public init(table: String, fields: [String: Any], skyflowId: String? = nil) {
self.table = table
self.fields = fields
public init(tableName: String, data: [String: Any], skyflowId: String? = nil) {
self.tableName = tableName
self.data = data
self.skyflowId = skyflowId
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Skyflow/collect/CollectContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ public extension Container {
}

private func checkRecord(record: AdditionalFieldsRecord, index: Int) -> ErrorCodes? {
if record.table.isEmpty {
if record.tableName.isEmpty {
return .EMPTY_TABLE_NAME()
}
if record.fields.isEmpty {
if record.data.isEmpty {
return .EMPTY_FIELDS_KEY(value: "\(index)")
}
return nil
Expand Down
12 changes: 8 additions & 4 deletions Sources/Skyflow/collect/CollectResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ public struct CollectResponse {
// with its own httpCode.
public struct CollectRecord {
public let tableName: String?
public let skyflowID: String?
public let skyflowId: String?
// Keyed by column name, e.g. "card_number": [{"token": "...", "tokenGroupName": "..."}].
public let fields: [String: Any]?
public let tokens: [String: Any]?
// Keyed by column name, e.g. "card_number": [{"data": "...", "hashName": "..."}].
public let hashedData: [String: Any]?
public let httpCode: Int
public let error: String?

init(_ dict: [String: Any]) {
self.tableName = dict["tableName"] as? String
self.skyflowID = dict["skyflowID"] as? String
self.fields = dict["fields"] as? [String: Any]
// Wire key is intentionally left as "skyflowID" here - only the public Swift-facing
// property name changed, not the response dict this reads from.
self.skyflowId = dict["skyflowID"] as? String
// Dict key is intentionally left as "fields" here - only the public Swift-facing
// property name changed, not the response dict this reads from.
self.tokens = dict["fields"] as? [String: Any]
self.hashedData = dict["hashedData"] as? [String: Any]
self.httpCode = dict["httpCode"] as? Int ?? 0
self.error = dict["error"] as? String
Expand Down
4 changes: 2 additions & 2 deletions Sources/Skyflow/collect/FlowVaultCollectRequestBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ internal class FlowVaultCollectRequestBody {

if let additionalFields = additionalFields {
for entry in additionalFields.records {
let tableName = entry.table
let fields = entry.fields
let tableName = entry.tableName
let fields = entry.data
// Matches the element-based check below: an empty string is treated the same as
// absent, falling back to a plain insert rather than an update targeting "".
if let skyflowId = entry.skyflowId, !skyflowId.isEmpty {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Skyflow/collect/FlowVaultICOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal struct FlowVaultICOptions {
}

for (index, currUpsertOption) in self.upsert!.enumerated() {
if currUpsertOption.table == "" {
if currUpsertOption.tableName == "" {
let errorCode = ErrorCodes.TABLE_NAME_IS_EMPTY_FOR_ATLEAST_ONE_UPSERT_OPTION(value: "\(index)")
self.callback!.onFailure(errorCode.getErrorObject(contextOptions: self.contextOptions!))
return true
Expand Down
2 changes: 1 addition & 1 deletion Sources/Skyflow/collect/FlowVaultInsertRequestBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class FlowVaultInsertRequestBody {
temp["data"] = record["fields"]
if let tableName = record["table"] as? String {
temp["tableName"] = tableName
if let upsertOptions = options.upsert, let match = upsertOptions.first(where: { $0.table == tableName }) {
if let upsertOptions = options.upsert, let match = upsertOptions.first(where: { $0.tableName == tableName }) {
var upsertPayload: [String: Any] = ["uniqueColumns": match.uniqueColumns]
if let updateType = match.updateType {
upsertPayload["updateType"] = updateType.rawValue
Expand Down
6 changes: 3 additions & 3 deletions Sources/Skyflow/collect/UpsertOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ public enum UpdateType: String {
}

public struct UpsertOption {
public let table: String
public let tableName: String
public let uniqueColumns: [String]
public let updateType: UpdateType?

public init(table: String, uniqueColumns: [String], updateType: UpdateType? = nil) {
self.table = table
public init(tableName: String, uniqueColumns: [String], updateType: UpdateType? = nil) {
self.tableName = tableName
self.uniqueColumns = uniqueColumns
self.updateType = updateType
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Skyflow/composable/ComposableContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ public extension Container {
}

private func checkRecord(record: AdditionalFieldsRecord, index: Int) -> ErrorCodes? {
if record.table.isEmpty {
if record.tableName.isEmpty {
return .EMPTY_TABLE_NAME()
}
if record.fields.isEmpty {
if record.data.isEmpty {
return .EMPTY_FIELDS_KEY(value: "\(index)")
}
return nil
Expand Down
16 changes: 14 additions & 2 deletions Sources/Skyflow/reveal/RevealResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,30 @@ public struct RevealResponse {
public struct RevealRecord {
public let token: String?
public let tokenGroupName: String?
// Keyed by whatever fields the vault includes (e.g. "skyflowID", "tableName").
// Keyed by whatever fields the vault includes (e.g. "skyflowId", "tableName").
public let metadata: [String: Any]?
public let httpCode: Int
public let error: String?

init(_ dict: [String: Any]) {
self.token = dict["token"] as? String
self.tokenGroupName = dict["tokenGroupName"] as? String
self.metadata = dict["metadata"] as? [String: Any]
self.metadata = RevealRecord.normalizeMetadataKeys(dict["metadata"] as? [String: Any])
self.httpCode = dict["httpCode"] as? Int ?? 0
self.error = dict["error"] as? String
}

// The vault sends this key as "skyflowID" - normalized here to "skyflowId" so metadata's
// casing is consistent with Skyflow.CollectRecord.skyflowId rather than exposing the raw
// wire casing directly.
private static func normalizeMetadataKeys(_ metadata: [String: Any]?) -> [String: Any]? {
guard let metadata = metadata else { return nil }
var normalized: [String: Any] = [:]
for (key, value) in metadata {
normalized[key == "skyflowID" ? "skyflowId" : key] = value
}
return normalized
}
}

// A ready-made Skyflow.Callback that unwraps the raw responseBody/error into RevealResponse
Expand Down
12 changes: 6 additions & 6 deletions Tests/skyflow-iOS-collectTests/skyflow_iOS_collectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ final class skyflow_iOS_collectTests: XCTestCase {
}

func testCollectEmptyTableAddionalFields() {
let additionalFields = AdditionalFields(records: [AdditionalFieldsRecord(table: "", fields: ["field": "value"])])
let additionalFields = AdditionalFields(records: [AdditionalFieldsRecord(tableName: "", data: ["field": "value"])])
let container = skyflow.container(type: ContainerType.COLLECT)

let expectation = XCTestExpectation()
Expand All @@ -770,7 +770,7 @@ final class skyflow_iOS_collectTests: XCTestCase {
}

func testCollectEmptyFieldsAddionalFields() {
let additionalFields = AdditionalFields(records: [AdditionalFieldsRecord(table: "table", fields: [:])])
let additionalFields = AdditionalFields(records: [AdditionalFieldsRecord(tableName: "table", data: [:])])
let container = skyflow.container(type: ContainerType.COLLECT)

let expectation = XCTestExpectation()
Expand All @@ -795,7 +795,7 @@ final class skyflow_iOS_collectTests: XCTestCase {

func testCollectEmptyUniqueColumnsUpsertOption() {
let container = skyflow.container(type: ContainerType.COLLECT)
let upsertOptions = [UpsertOption(table: "card1", uniqueColumns: [])]
let upsertOptions = [UpsertOption(tableName: "card1", uniqueColumns: [])]
let expectation = XCTestExpectation()
let callback = DemoAPICallback(expectation: expectation)
container?.collect(callback: callback.asCollectCallback, options: CollectOptions(upsert:upsertOptions))
Expand All @@ -807,7 +807,7 @@ final class skyflow_iOS_collectTests: XCTestCase {

func testCollectEmptyTableNameUpsertOption() {
let container = skyflow.container(type: ContainerType.COLLECT)
let upsertOptions = [UpsertOption(table: "", uniqueColumns: ["person"])]
let upsertOptions = [UpsertOption(tableName: "", uniqueColumns: ["person"])]
let expectation = XCTestExpectation()
let callback = DemoAPICallback(expectation: expectation)
container?.collect(callback: callback.asCollectCallback, options: CollectOptions(upsert:upsertOptions))
Expand Down Expand Up @@ -839,7 +839,7 @@ final class skyflow_iOS_collectTests: XCTestCase {

func testInsertEmptyUniqueColumnsUpsertOption() {
let container = skyflow.container(type: ContainerType.COLLECT)
let upsertOptions = [UpsertOption(table: "card1", uniqueColumns: [])]
let upsertOptions = [UpsertOption(tableName: "card1", uniqueColumns: [])]
let expectation = XCTestExpectation()
let records = [
"records" : [[
Expand All @@ -860,7 +860,7 @@ final class skyflow_iOS_collectTests: XCTestCase {

func testInsertEmptyTableNameUpsertOption() {
let container = skyflow.container(type: ContainerType.COLLECT)
let upsertOptions = [UpsertOption(table: "", uniqueColumns: ["person"])]
let upsertOptions = [UpsertOption(tableName: "", uniqueColumns: ["person"])]
let expectation = XCTestExpectation()
let records = [
"records" : [[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ final class skyflow_iOS_composableEelementsTests: XCTestCase {
}
func testInsertEmptyTableNameForUpsertOption() {
_ = skyflow.container(type: ContainerType.COMPOSABLE)
let upsertOptions = [UpsertOption(table: "", uniqueColumns: ["person"])]
let upsertOptions = [UpsertOption(tableName: "", uniqueColumns: ["person"])]
let expectation = XCTestExpectation()
let records = [
"records" : [[
Expand Down
Loading
Loading