Skip to content

Commit

Permalink
stash
Browse files Browse the repository at this point in the history
  • Loading branch information
lawmicha committed May 23, 2024
1 parent 63b4c1b commit fccd1d9
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public enum AppSyncRealTimeRequest {
case stop(String)

public struct StartRequest {
let id: String
public let id: String
let data: String
let auth: AppSyncRealTimeRequestAuth?
}

var id: String? {
public var id: String? {
switch self {
case let .start(request): return request.id
case let .stop(id): return id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import Foundation

protocol AppSyncRequestInterceptor {
public protocol AppSyncRequestInterceptor {
func interceptRequest(event: AppSyncRealTimeRequest, url: URL) async -> AppSyncRealTimeRequest
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import Foundation
import Combine
@_spi(WebSocket) import AWSPluginsCore
import AWSPluginsCore

protocol AppSyncWebSocketClientProtocol: AnyObject {
public protocol AppSyncWebSocketClientProtocol: AnyObject {
var isConnected: Bool { get async }
var publisher: AnyPublisher<WebSocketEvent, Never> { get async }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import Foundation
import Amplify
@_spi(WebSocket) import AWSPluginsCore

class APIKeyAuthInterceptor {
public class APIKeyAuthInterceptor {
private let apiKey: String
private let getAuthHeader = authHeaderBuilder()

init(apiKey: String) {
public init(apiKey: String) {
self.apiKey = apiKey
}

}

extension APIKeyAuthInterceptor: WebSocketInterceptor {
func interceptConnection(url: URL) async -> URL {
public func interceptConnection(url: URL) async -> URL {
let authHeader = getAuthHeader(apiKey, AppSyncRealTimeClientFactory.appSyncApiEndpoint(url).host!)
return AppSyncRealTimeRequestAuth.URLQuery(
header: .apiKey(authHeader)
Expand All @@ -30,7 +30,7 @@ extension APIKeyAuthInterceptor: WebSocketInterceptor {
}

extension APIKeyAuthInterceptor: AppSyncRequestInterceptor {
func interceptRequest(event: AppSyncRealTimeRequest, url: URL) async -> AppSyncRealTimeRequest {
public func interceptRequest(event: AppSyncRealTimeRequest, url: URL) async -> AppSyncRealTimeRequest {
let host = AppSyncRealTimeClientFactory.appSyncApiEndpoint(url).host!
guard case .start(let request) = event else {
return event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ extension AppSyncRealTimeClientFactory {
1. api.example.com/graphql -> api.example.com/graphql/realtime
2. abc.appsync-api.us-east-1.amazonaws.com/graphql -> abc.appsync-realtime-api.us-east-1.amazonaws.com/graphql
*/
static func appSyncRealTimeEndpoint(_ url: URL) -> URL {
public static func appSyncRealTimeEndpoint(_ url: URL) -> URL {
guard let host = url.host else {
return url
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
import Foundation

// TODO: remove this https://github.com/aws-amplify/amplify-ios/issues/75
struct URLRequestConstants {
public struct URLRequestConstants {
static let appSyncServiceName = "appsync"
static let apiGatewayServiceName = "execute-api"

struct Header {
public struct Header {
static let xAmzDate = "X-Amz-Date"
static let contentType = "Content-Type"
static let userAgent = "User-Agent"
public static let userAgent = "User-Agent"
static let xApiKey = "x-api-key"
static let host = "Host"
static let webSocketSubprotocols = "Sec-WebSocket-Protocol"
public static let webSocketSubprotocols = "Sec-WebSocket-Protocol"
}

struct ContentType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Network
import Combine

@_spi(WebSocket)
public final class AmplifyNetworkMonitor {

public enum State {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Combine
WebSocketClient wraps URLSessionWebSocketTask and offers
an abstraction of the data stream in the form of WebSocketEvent.
*/
@_spi(WebSocket)

public final actor WebSocketClient: NSObject {
public enum Error: Swift.Error {
case connectionLost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation

@_spi(WebSocket)
public enum WebSocketEvent {
case connected
case disconnected(URLSessionWebSocketTask.CloseCode, String?)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation

@_spi(WebSocket)
public protocol WebSocketInterceptor {
func interceptConnection(url: URL) async -> URL
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Foundation
import Combine

@_spi(WebSocket)
public protocol WebSocketNetworkMonitorProtocol {
var publisher: AnyPublisher<(AmplifyNetworkMonitor.State, AmplifyNetworkMonitor.State), Never> { get }
func updateState(_ nextState: AmplifyNetworkMonitor.State) async
Expand Down

0 comments on commit fccd1d9

Please sign in to comment.