Skip to content

Commit 76841fa

Browse files
authored
chore: kickoff release
2 parents b331b1d + f685304 commit 76841fa

File tree

148 files changed

+4752
-699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+4752
-699
lines changed

Amplify/Categories/Auth/AuthCategory+ClientBehavior.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ extension AuthCategory: AuthCategoryBehavior {
3131

3232
#if canImport(AuthenticationServices)
3333
public func signInWithWebUI(
34-
presentationAnchor: AuthUIPresentationAnchor,
34+
presentationAnchor: AuthUIPresentationAnchor? = nil,
3535
options: AuthWebUISignInRequest.Options? = nil) async throws -> AuthSignInResult {
3636
return try await plugin.signInWithWebUI(presentationAnchor: presentationAnchor, options: options)
3737
}
3838

3939
public func signInWithWebUI(
4040
for authProvider: AuthProvider,
41-
presentationAnchor: AuthUIPresentationAnchor,
41+
presentationAnchor: AuthUIPresentationAnchor? = nil,
4242
options: AuthWebUISignInRequest.Options? = nil) async throws -> AuthSignInResult {
4343
return try await plugin.signInWithWebUI(for: authProvider,
4444
presentationAnchor: presentationAnchor,

Amplify/Categories/Auth/AuthCategoryBehavior.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
6868
/// - Parameters:
6969
/// - presentationAnchor: Anchor on which the UI is presented.
7070
/// - options: Parameters specific to plugin behavior.
71-
func signInWithWebUI(presentationAnchor: AuthUIPresentationAnchor,
71+
func signInWithWebUI(presentationAnchor: AuthUIPresentationAnchor?,
7272
options: AuthWebUISignInRequest.Options?) async throws -> AuthSignInResult
7373

7474
/// SignIn using an auth provider on a web UI
@@ -82,7 +82,7 @@ public protocol AuthCategoryBehavior: AuthCategoryUserBehavior, AuthCategoryDevi
8282
/// - presentationAnchor: Anchor on which the UI is presented.
8383
/// - options: Parameters specific to plugin behavior.
8484
func signInWithWebUI(for authProvider: AuthProvider,
85-
presentationAnchor: AuthUIPresentationAnchor,
85+
presentationAnchor: AuthUIPresentationAnchor?,
8686
options: AuthWebUISignInRequest.Options?) async throws -> AuthSignInResult
8787
#endif
8888

Amplify/Categories/Auth/Request/AuthWebUISignInRequest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import Foundation
1414
public struct AuthWebUISignInRequest: AmplifyOperationRequest {
1515

1616
/// Presentation anchor on which the webUI is displayed
17-
public let presentationAnchor: AuthUIPresentationAnchor
17+
public let presentationAnchor: AuthUIPresentationAnchor?
1818

1919
/// Optional auth provider to directly sign in with the provider
2020
public let authProvider: AuthProvider?
2121

2222
/// Extra request options defined in `AuthWebUISignInRequest.Options`
2323
public var options: Options
2424

25-
public init(presentationAnchor: AuthUIPresentationAnchor,
25+
public init(presentationAnchor: AuthUIPresentationAnchor?,
2626
authProvider: AuthProvider? = nil,
2727
options: Options) {
2828
self.presentationAnchor = presentationAnchor

AmplifyPlugins/API/Sources/AWSAPIPlugin/Operation/AWSGraphQLSubscriptionTaskRunner.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ public class AWSGraphQLSubscriptionTaskRunner<R: Decodable>: InternalTaskRunner,
174174
return
175175
} else if case ConnectionProviderError.unauthorized = error {
176176
errorDescription += ": \(APIError.UnauthorizedMessageString)"
177+
} else if case ConnectionProviderError.connection = error {
178+
errorDescription += ": connection"
179+
let error = URLError(.networkConnectionLost)
180+
fail(APIError.networkError(errorDescription, nil, error))
181+
return
177182
}
178183

179184
fail(APIError.operationError(errorDescription, "", error))
@@ -361,8 +366,13 @@ final public class AWSGraphQLSubscriptionOperation<R: Decodable>: GraphQLSubscri
361366
return
362367
} else if case ConnectionProviderError.unauthorized = error {
363368
errorDescription += ": \(APIError.UnauthorizedMessageString)"
369+
} else if case ConnectionProviderError.connection = error {
370+
errorDescription += ": connection"
371+
let error = URLError(.networkConnectionLost)
372+
dispatch(result: .failure(APIError.networkError(errorDescription, nil, error)))
373+
finish()
374+
return
364375
}
365-
366376
dispatch(result: .failure(APIError.operationError(errorDescription, "", error)))
367377
finish()
368378
}

AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AmplifyPlugins/API/Tests/AWSAPIPluginTests/Operation/GraphQLSubscribeTaskTests.swift

Lines changed: 105 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class GraphQLSubscribeTasksTests: OperationTestBase {
3737

3838
var connectionStateSink: AnyCancellable?
3939
var subscriptionDataSink: AnyCancellable?
40+
var expectedCompletionFailureError: APIError?
4041

4142
override func setUp() async throws {
4243
try await super.setUp()
@@ -109,7 +110,7 @@ class GraphQLSubscribeTasksTests: OperationTestBase {
109110
await waitForSubscriptionExpectations()
110111
}
111112

112-
func testConnectionError() async throws {
113+
func testConnectionErrorWithLimitExceeded() async throws {
113114
await receivedCompletionSuccess.setShouldTrigger(false)
114115
await receivedCompletionFailure.setShouldTrigger(true)
115116
await receivedStateValueConnecting.setShouldTrigger(true)
@@ -123,8 +124,65 @@ class GraphQLSubscribeTasksTests: OperationTestBase {
123124
await waitForExpectations([onSubscribeInvoked], timeout: 0.05)
124125

125126
subscriptionEventHandler(.connection(.connecting), subscriptionItem)
126-
subscriptionEventHandler(.failed("Error"), subscriptionItem)
127+
subscriptionEventHandler(.failed(ConnectionProviderError.limitExceeded(nil)), subscriptionItem)
128+
expectedCompletionFailureError = APIError.operationError("", "", ConnectionProviderError.limitExceeded(nil))
129+
await waitForSubscriptionExpectations()
130+
}
131+
132+
func testConnectionErrorWithSubscriptionError() async throws {
133+
await receivedCompletionSuccess.setShouldTrigger(false)
134+
await receivedCompletionFailure.setShouldTrigger(true)
135+
await receivedStateValueConnecting.setShouldTrigger(true)
136+
await receivedStateValueConnected.setShouldTrigger(false)
137+
await receivedStateValueDisconnected.setShouldTrigger(false)
138+
139+
await receivedDataValueSuccess.setShouldTrigger(false)
140+
await receivedDataValueError.setShouldTrigger(false)
141+
142+
try await subscribe()
143+
await waitForExpectations([onSubscribeInvoked], timeout: 0.05)
127144

145+
subscriptionEventHandler(.connection(.connecting), subscriptionItem)
146+
subscriptionEventHandler(.failed(ConnectionProviderError.subscription("", nil)), subscriptionItem)
147+
expectedCompletionFailureError = APIError.operationError("", "", ConnectionProviderError.subscription("", nil))
148+
await waitForSubscriptionExpectations()
149+
}
150+
151+
func testConnectionErrorWithConnectionUnauthorizedError() async throws {
152+
await receivedCompletionSuccess.setShouldTrigger(false)
153+
await receivedCompletionFailure.setShouldTrigger(true)
154+
await receivedStateValueConnecting.setShouldTrigger(true)
155+
await receivedStateValueConnected.setShouldTrigger(false)
156+
await receivedStateValueDisconnected.setShouldTrigger(false)
157+
158+
await receivedDataValueSuccess.setShouldTrigger(false)
159+
await receivedDataValueError.setShouldTrigger(false)
160+
161+
try await subscribe()
162+
await waitForExpectations([onSubscribeInvoked], timeout: 0.05)
163+
164+
subscriptionEventHandler(.connection(.connecting), subscriptionItem)
165+
subscriptionEventHandler(.failed(ConnectionProviderError.unauthorized), subscriptionItem)
166+
expectedCompletionFailureError = APIError.operationError("", "", ConnectionProviderError.unauthorized)
167+
await waitForSubscriptionExpectations()
168+
}
169+
170+
func testConnectionErrorWithConnectionProviderConnectionError() async throws {
171+
await receivedCompletionSuccess.setShouldTrigger(false)
172+
await receivedCompletionFailure.setShouldTrigger(true)
173+
await receivedStateValueConnecting.setShouldTrigger(true)
174+
await receivedStateValueConnected.setShouldTrigger(false)
175+
await receivedStateValueDisconnected.setShouldTrigger(false)
176+
177+
await receivedDataValueSuccess.setShouldTrigger(false)
178+
await receivedDataValueError.setShouldTrigger(false)
179+
180+
try await subscribe()
181+
await waitForExpectations([onSubscribeInvoked], timeout: 0.05)
182+
183+
subscriptionEventHandler(.connection(.connecting), subscriptionItem)
184+
subscriptionEventHandler(.failed(ConnectionProviderError.connection), subscriptionItem)
185+
expectedCompletionFailureError = APIError.networkError("", nil, URLError(.networkConnectionLost))
128186
await waitForSubscriptionExpectations()
129187
}
130188

@@ -270,8 +328,53 @@ class GraphQLSubscribeTasksTests: OperationTestBase {
270328

271329
await self.receivedCompletionSuccess.fulfill()
272330
} catch {
331+
if let apiError = error as? APIError,
332+
let expectedError = expectedCompletionFailureError {
333+
XCTAssertEqual(apiError, expectedError)
334+
}
335+
273336
await self.receivedCompletionFailure.fulfill()
274337
}
275338
}
276339
}
277340
}
341+
342+
extension APIError: Equatable {
343+
public static func == (lhs: APIError, rhs: APIError) -> Bool {
344+
switch (lhs, rhs) {
345+
case (.unknown, .unknown),
346+
(.invalidConfiguration, .invalidConfiguration),
347+
(.httpStatusError, .httpStatusError),
348+
(.pluginError, .pluginError):
349+
return true
350+
case (.operationError(_, _, let lhs), .operationError(_, _, let rhs)):
351+
if let lhs = lhs as? ConnectionProviderError, let rhs = rhs as? ConnectionProviderError {
352+
switch (lhs, rhs) {
353+
case (.connection, .connection),
354+
(.jsonParse, .jsonParse),
355+
(.limitExceeded, .limitExceeded),
356+
(.subscription, .subscription),
357+
(.unauthorized, .unauthorized),
358+
(.unknown, .unknown):
359+
return true
360+
default:
361+
return false
362+
}
363+
} else if lhs == nil && rhs == nil {
364+
return true
365+
} else {
366+
return false
367+
}
368+
case (.networkError(_, _, let lhs), .networkError(_, _, let rhs)):
369+
if let lhs = lhs as? URLError, let rhs = rhs as? URLError {
370+
return lhs.code == rhs.code
371+
} else if lhs == nil && rhs == nil {
372+
return true
373+
} else {
374+
return false
375+
}
376+
default:
377+
return false
378+
}
379+
}
380+
}

AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Support/Extensions/Date+Formatting.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ extension DateFormatter {
1515
formatter.locale = Locale(identifier: "en_US_POSIX")
1616
return formatter
1717
}()
18+
19+
static let iso8601DateFormatterWithFractionalSeconds: DateFormatter = {
20+
let formatter = DateFormatter()
21+
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
22+
formatter.timeZone = TimeZone(secondsFromGMT: 0)
23+
formatter.locale = Locale(identifier: "en_US_POSIX")
24+
return formatter
25+
}()
1826
}
1927

2028
extension Date {

AmplifyPlugins/Analytics/Sources/AWSPinpointAnalyticsPlugin/Support/Extensions/PinpointClient+CredentialsProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import AWSPinpoint
1212
extension PinpointClient {
1313
convenience init(region: String, credentialsProvider: CredentialsProvider) throws {
1414
let configuration = try PinpointClientConfiguration(
15-
region: region,
1615
credentialsProvider: credentialsProvider,
17-
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData()
16+
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData(),
17+
region: region
1818
)
1919

2020
self.init(config: configuration)

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/AWSCognitoAuthPlugin+Configure.swift

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,12 @@ extension AWSCognitoAuthPlugin {
8484
private func makeUserPool() throws -> CognitoUserPoolBehavior {
8585
switch authConfiguration {
8686
case .userPools(let userPoolConfig), .userPoolsAndIdentityPools(let userPoolConfig, _):
87-
88-
let configuration: CognitoIdentityProviderClient.CognitoIdentityProviderClientConfiguration
89-
if let customEndpoint = userPoolConfig.endpoint {
90-
configuration = try .init(
91-
region: userPoolConfig.region,
92-
endpointResolver: customEndpoint.resolver,
93-
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData()
94-
)
95-
} else {
96-
configuration = try CognitoIdentityProviderClient.CognitoIdentityProviderClientConfiguration(
97-
region: userPoolConfig.region, frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData())
98-
}
99-
87+
let configuration = try CognitoIdentityProviderClient.CognitoIdentityProviderClientConfiguration(
88+
endpointResolver: userPoolConfig.endpoint?.resolver,
89+
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData(),
90+
region: userPoolConfig.region
91+
)
10092
return CognitoIdentityProviderClient(config: configuration)
101-
10293
default:
10394
fatalError()
10495
}
@@ -108,7 +99,9 @@ extension AWSCognitoAuthPlugin {
10899
switch authConfiguration {
109100
case .identityPools(let identityPoolConfig), .userPoolsAndIdentityPools(_, let identityPoolConfig):
110101
let configuration = try CognitoIdentityClient.CognitoIdentityClientConfiguration(
111-
region: identityPoolConfig.region, frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData())
102+
frameworkMetadata: AmplifyAWSServiceConfiguration.frameworkMetaData(),
103+
region: identityPoolConfig.region
104+
)
112105
return CognitoIdentityClient(config: configuration)
113106
default:
114107
fatalError()

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/DeviceSRPAuth/InitiateAuthDeviceSRP.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ struct InitiateAuthDeviceSRP: Action {
1414
let identifier = "InitiateAuthDeviceSRP"
1515

1616
let username: String
17-
let deviceMetadata: DeviceMetadata
1817
let authResponse: SignInResponseBehavior
1918

2019
func execute(withDispatcher dispatcher: EventDispatcher,
@@ -29,6 +28,11 @@ struct InitiateAuthDeviceSRP: Action {
2928
let gHexValue = srpEnv.srpConfiguration.gHexValue
3029
let srpKeyPair = srpClient.generateClientKeyPair()
3130

31+
// Get device metadata
32+
let deviceMetadata = await DeviceMetadataHelper.getDeviceMetadata(
33+
for: environment,
34+
with: username)
35+
3236
let srpStateData = SRPStateData(
3337
username: username,
3438
password: "",

0 commit comments

Comments
 (0)