From 61323efd68b28e8b0b0c709b48db59d01ade5941 Mon Sep 17 00:00:00 2001 From: Daniel Kift Date: Tue, 16 Jun 2026 12:23:56 +0100 Subject: [PATCH] hide communication client Assisted-By: devx/6488e3d0-f47f-4171-a1c4-d2432b2a653c --- Package.swift | 2 +- .../ios/ProtocolRelay.swift | 13 +- .../Wallets/AcceleratedCheckoutButtons.swift | 5 +- .../CheckoutCommunicationProtocol.swift | 2 +- .../CheckoutViewController.swift | 10 +- .../CheckoutWebViewController.swift | 2 +- .../ShopifyCheckoutKit.swift | 11 +- .../api/ShopifyAcceleratedCheckouts.json | 28 +++- platforms/swift/api/ShopifyCheckoutKit.json | 135 ++++++++++++++++-- 9 files changed, 179 insertions(+), 29 deletions(-) diff --git a/Package.swift b/Package.swift index 11a7d44e6..0cdc17aa9 100644 --- a/Package.swift +++ b/Package.swift @@ -43,7 +43,7 @@ let package = Package( ), .target( name: "ShopifyAcceleratedCheckouts", - dependencies: ["ShopifyCheckoutKit"], + dependencies: ["ShopifyCheckoutKit", "ShopifyCheckoutProtocol"], path: "platforms/swift/Sources/ShopifyAcceleratedCheckouts", resources: [.process("Localizable.xcstrings"), .process("Media.xcassets")] ), diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ProtocolRelay.swift b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ProtocolRelay.swift index da135ca2a..885af5392 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ProtocolRelay.swift +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ProtocolRelay.swift @@ -1,10 +1,19 @@ import Foundation #if COCOAPODS import ShopifyCheckoutKit - - extension CheckoutProtocol.Client: @retroactive CheckoutCommunicationProtocol {} #else import ShopifyCheckoutProtocol + + enum CheckoutProtocol { + typealias Client = EmbeddedCheckoutProtocol.Client + + static let complete = EmbeddedCheckoutProtocol.Event.complete + static let error = EmbeddedCheckoutProtocol.Event.error + static let lineItemsChange = EmbeddedCheckoutProtocol.Event.lineItemsChange + static let messagesChange = EmbeddedCheckoutProtocol.Event.messagesChange + static let start = EmbeddedCheckoutProtocol.Event.start + static let totalsChange = EmbeddedCheckoutProtocol.Event.totalsChange + } #endif struct DispatchEnvelope: Encodable { diff --git a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/AcceleratedCheckoutButtons.swift b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/AcceleratedCheckoutButtons.swift index f47a9b1ca..09f8db565 100644 --- a/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/AcceleratedCheckoutButtons.swift +++ b/platforms/swift/Sources/ShopifyAcceleratedCheckouts/Wallets/AcceleratedCheckoutButtons.swift @@ -1,5 +1,8 @@ import PassKit import ShopifyCheckoutKit +#if !COCOAPODS + import ShopifyCheckoutProtocol +#endif import SwiftUI /// Render state for AcceleratedCheckoutButtons @@ -230,7 +233,7 @@ extension AcceleratedCheckoutButtons { return newView } - public func connect(_ client: (any CheckoutCommunicationProtocol)?) -> AcceleratedCheckoutButtons { + public func connect(_ client: CheckoutProtocol.Client?) -> AcceleratedCheckoutButtons { var newView = self newView.clientContainer = CheckoutProtocolClientContainer(client) return newView diff --git a/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutCommunicationProtocol.swift b/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutCommunicationProtocol.swift index 6db884367..d2b22f5cd 100644 --- a/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutCommunicationProtocol.swift +++ b/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutCommunicationProtocol.swift @@ -3,7 +3,7 @@ #endif import Foundation -public protocol CheckoutCommunicationProtocol: Sendable { +package protocol CheckoutCommunicationProtocol: Sendable { func process(_ message: String) async -> String? } diff --git a/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutViewController.swift b/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutViewController.swift index 0f59fc30b..3b190f158 100644 --- a/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutViewController.swift +++ b/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutViewController.swift @@ -6,7 +6,7 @@ import UIKit @MainActor public class CheckoutViewController: UINavigationController { - public init(checkout url: URL, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil) { + public init(checkout url: URL, delegate: (any CheckoutDelegate)? = nil, client: CheckoutProtocol.Client? = nil) { let rootViewController = CheckoutWebViewController(checkoutURL: url, delegate: delegate, client: client, entryPoint: nil) super.init(rootViewController: rootViewController) presentationController?.delegate = rootViewController @@ -62,7 +62,13 @@ public struct ShopifyCheckout: UIViewControllerRepresentable, CheckoutConfigurab webViewController.onFail = onFailAction } - @discardableResult public func connect(_ handler: any CheckoutCommunicationProtocol) -> Self { + @discardableResult public func connect(_ handler: CheckoutProtocol.Client) -> Self { + var copy = self + copy.client = handler + return copy + } + + @discardableResult package func connect(_ handler: any CheckoutCommunicationProtocol) -> Self { var copy = self copy.client = handler return copy diff --git a/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift b/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift index c26347c33..70af81282 100644 --- a/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift +++ b/platforms/swift/Sources/ShopifyCheckoutKit/CheckoutWebViewController.swift @@ -55,7 +55,7 @@ class CheckoutWebViewController: UIViewController, UIAdaptivePresentationControl // MARK: Initializers - public init(checkoutURL url: URL, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil, entryPoint: MetaData.EntryPoint? = nil) { + init(checkoutURL url: URL, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil, entryPoint: MetaData.EntryPoint? = nil) { checkoutURL = url self.delegate = delegate self.client = client diff --git a/platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift b/platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift index 32f567904..e44772abe 100644 --- a/platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift +++ b/platforms/swift/Sources/ShopifyCheckoutKit/ShopifyCheckoutKit.swift @@ -60,7 +60,16 @@ public func invalidate() { @MainActor @discardableResult -public func present(checkout url: URL, from: UIViewController, delegate: (any CheckoutDelegate)? = nil, client: (any CheckoutCommunicationProtocol)? = nil) -> CheckoutViewController { +public func present(checkout url: URL, from: UIViewController, delegate: (any CheckoutDelegate)? = nil, client: CheckoutProtocol.Client? = nil) -> CheckoutViewController { + let decorated = CheckoutProtocol.url(for: url) + let viewController = CheckoutViewController(checkout: decorated, delegate: delegate, client: client) + from.present(viewController, animated: true) + return viewController +} + +@MainActor +@discardableResult +package func present(checkout url: URL, from: UIViewController, delegate: (any CheckoutDelegate)? = nil, client: any CheckoutCommunicationProtocol) -> CheckoutViewController { let decorated = CheckoutProtocol.url(for: url) let viewController = CheckoutViewController(checkout: decorated, delegate: delegate, client: client) from.present(viewController, animated: true) diff --git a/platforms/swift/api/ShopifyAcceleratedCheckouts.json b/platforms/swift/api/ShopifyAcceleratedCheckouts.json index 314f38f01..6beec34c9 100644 --- a/platforms/swift/api/ShopifyAcceleratedCheckouts.json +++ b/platforms/swift/api/ShopifyAcceleratedCheckouts.json @@ -60,6 +60,13 @@ "declKind": "Import", "moduleName": "ShopifyAcceleratedCheckouts" }, + { + "kind": "Import", + "name": "ShopifyCheckoutProtocol", + "printedName": "ShopifyCheckoutProtocol", + "declKind": "Import", + "moduleName": "ShopifyAcceleratedCheckouts" + }, { "kind": "Import", "name": "SwiftOnoneSupport", @@ -2220,21 +2227,28 @@ { "kind": "TypeNominal", "name": "Optional", - "printedName": "(any ShopifyCheckoutKit.CheckoutCommunicationProtocol)?", + "printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client?", "children": [ { - "kind": "TypeNominal", - "name": "CheckoutCommunicationProtocol", - "printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol", - "usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP" + "kind": "TypeNameAlias", + "name": "Client", + "printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client", + "children": [ + { + "kind": "TypeNominal", + "name": "Client", + "printedName": "ShopifyCheckoutProtocol.EmbeddedCheckoutProtocol.Client", + "usr": "s:23ShopifyCheckoutProtocol08EmbeddedbC0O6ClientV" + } + ] } ], "usr": "s:Sq" } ], "declKind": "Func", - "usr": "s:27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD3Kit0D21CommunicationProtocol_pSgF", - "mangledName": "$s27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD3Kit0D21CommunicationProtocol_pSgF", + "usr": "s:27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD8Protocol08EmbeddeddG0O6ClientVSgF", + "mangledName": "$s27ShopifyAcceleratedCheckouts0B15CheckoutButtonsV7connectyAC0aD8Protocol08EmbeddeddG0O6ClientVSgF", "moduleName": "ShopifyAcceleratedCheckouts", "declAttributes": [ "Preconcurrency", diff --git a/platforms/swift/api/ShopifyCheckoutKit.json b/platforms/swift/api/ShopifyCheckoutKit.json index 8cddb3552..6ce87f10f 100644 --- a/platforms/swift/api/ShopifyCheckoutKit.json +++ b/platforms/swift/api/ShopifyCheckoutKit.json @@ -153,6 +153,7 @@ "moduleName": "ShopifyCheckoutKit", "genericSig": "", "protocolReq": true, + "isInternal": true, "reqNewWitnessTableEntry": true, "funcSelfKind": "NonMutating" } @@ -162,6 +163,7 @@ "mangledName": "$s18ShopifyCheckoutKit0B21CommunicationProtocolP", "moduleName": "ShopifyCheckoutKit", "genericSig": "", + "isInternal": true, "conformances": [ { "kind": "Conformance", @@ -1833,13 +1835,20 @@ { "kind": "TypeNominal", "name": "Optional", - "printedName": "(any ShopifyCheckoutKit.CheckoutCommunicationProtocol)?", + "printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client?", "children": [ { - "kind": "TypeNominal", - "name": "CheckoutCommunicationProtocol", - "printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol", - "usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP" + "kind": "TypeNameAlias", + "name": "Client", + "printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client", + "children": [ + { + "kind": "TypeNominal", + "name": "Client", + "printedName": "ShopifyCheckoutProtocol.EmbeddedCheckoutProtocol.Client", + "usr": "s:23ShopifyCheckoutProtocol08EmbeddedbC0O6ClientV" + } + ] } ], "hasDefaultArg": true, @@ -1847,8 +1856,8 @@ } ], "declKind": "Constructor", - "usr": "s:18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtcfc", - "mangledName": "$s18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtcfc", + "usr": "s:18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSg0aB8Protocol08EmbeddedbL0O6ClientVSgtcfc", + "mangledName": "$s18ShopifyCheckoutKit0B14ViewControllerC8checkout8delegate6clientAC10Foundation3URLV_AA0B8Delegate_pSg0aB8Protocol08EmbeddedbL0O6ClientVSgtcfc", "moduleName": "ShopifyCheckoutKit", "declAttributes": [ "Custom" @@ -2416,6 +2425,42 @@ ], "funcSelfKind": "NonMutating" }, + { + "kind": "Function", + "name": "connect", + "printedName": "connect(_:)", + "children": [ + { + "kind": "TypeNominal", + "name": "ShopifyCheckout", + "printedName": "ShopifyCheckoutKit.ShopifyCheckout", + "usr": "s:18ShopifyCheckoutKit0aB0V" + }, + { + "kind": "TypeNameAlias", + "name": "Client", + "printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client", + "children": [ + { + "kind": "TypeNominal", + "name": "Client", + "printedName": "ShopifyCheckoutProtocol.EmbeddedCheckoutProtocol.Client", + "usr": "s:23ShopifyCheckoutProtocol08EmbeddedbC0O6ClientV" + } + ] + } + ], + "declKind": "Func", + "usr": "s:18ShopifyCheckoutKit0aB0V7connectyAC0aB8Protocol08EmbeddedbE0O6ClientVF", + "mangledName": "$s18ShopifyCheckoutKit0aB0V7connectyAC0aB8Protocol08EmbeddedbE0O6ClientVF", + "moduleName": "ShopifyCheckoutKit", + "declAttributes": [ + "Preconcurrency", + "DiscardableResult", + "Custom" + ], + "funcSelfKind": "NonMutating" + }, { "kind": "Function", "name": "connect", @@ -2438,6 +2483,7 @@ "usr": "s:18ShopifyCheckoutKit0aB0V7connectyAcA0B21CommunicationProtocol_pF", "mangledName": "$s18ShopifyCheckoutKit0aB0V7connectyAcA0B21CommunicationProtocol_pF", "moduleName": "ShopifyCheckoutKit", + "isInternal": true, "declAttributes": [ "Preconcurrency", "DiscardableResult", @@ -6492,23 +6538,86 @@ { "kind": "TypeNominal", "name": "Optional", - "printedName": "(any ShopifyCheckoutKit.CheckoutCommunicationProtocol)?", + "printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client?", + "children": [ + { + "kind": "TypeNameAlias", + "name": "Client", + "printedName": "ShopifyCheckoutKit.CheckoutProtocol.Client", + "children": [ + { + "kind": "TypeNominal", + "name": "Client", + "printedName": "ShopifyCheckoutProtocol.EmbeddedCheckoutProtocol.Client", + "usr": "s:23ShopifyCheckoutProtocol08EmbeddedbC0O6ClientV" + } + ] + } + ], + "hasDefaultArg": true, + "usr": "s:Sq" + } + ], + "declKind": "Func", + "usr": "s:18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSg0aB8Protocol08EmbeddedbO0O6ClientVSgtF", + "mangledName": "$s18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSg0aB8Protocol08EmbeddedbO0O6ClientVSgtF", + "moduleName": "ShopifyCheckoutKit", + "declAttributes": [ + "DiscardableResult", + "Custom" + ], + "funcSelfKind": "NonMutating" + }, + { + "kind": "Function", + "name": "present", + "printedName": "present(checkout:from:delegate:client:)", + "children": [ + { + "kind": "TypeNominal", + "name": "CheckoutViewController", + "printedName": "ShopifyCheckoutKit.CheckoutViewController", + "usr": "c:@M@ShopifyCheckoutKit@objc(cs)CheckoutViewController" + }, + { + "kind": "TypeNominal", + "name": "URL", + "printedName": "Foundation.URL", + "usr": "s:10Foundation3URLV" + }, + { + "kind": "TypeNominal", + "name": "UIViewController", + "printedName": "UIKit.UIViewController", + "usr": "c:objc(cs)UIViewController" + }, + { + "kind": "TypeNominal", + "name": "Optional", + "printedName": "(any ShopifyCheckoutKit.CheckoutDelegate)?", "children": [ { "kind": "TypeNominal", - "name": "CheckoutCommunicationProtocol", - "printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol", - "usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP" + "name": "CheckoutDelegate", + "printedName": "any ShopifyCheckoutKit.CheckoutDelegate", + "usr": "s:18ShopifyCheckoutKit0B8DelegateP" } ], "hasDefaultArg": true, "usr": "s:Sq" + }, + { + "kind": "TypeNominal", + "name": "CheckoutCommunicationProtocol", + "printedName": "any ShopifyCheckoutKit.CheckoutCommunicationProtocol", + "usr": "s:18ShopifyCheckoutKit0B21CommunicationProtocolP" } ], "declKind": "Func", - "usr": "s:18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtF", - "mangledName": "$s18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_pSgtF", + "usr": "s:18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_ptF", + "mangledName": "$s18ShopifyCheckoutKit7present8checkout4from8delegate6clientAA0B14ViewControllerC10Foundation3URLV_So06UIViewJ0CAA0B8Delegate_pSgAA0B21CommunicationProtocol_ptF", "moduleName": "ShopifyCheckoutKit", + "isInternal": true, "declAttributes": [ "DiscardableResult", "Custom"