Skip to content

Commit 4607d87

Browse files
author
Di Wu
authored
chore: kickoff release
2 parents 7b2809f + b0dbde9 commit 4607d87

File tree

36 files changed

+351
-95
lines changed

36 files changed

+351
-95
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// Copyright Amazon.com Inc. or its affiliates.
3+
// All Rights Reserved.
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
import Foundation
9+
10+
extension ModelSchema {
11+
func lazyReferenceIdentifiers(from modelObject: [String: JSONValue]) throws -> [LazyReferenceIdentifier] {
12+
enum ExtractionError: Error {
13+
case unsupportedLazyReferenceIdentifier(name: String, value: JSONValue?)
14+
}
15+
16+
var identifiers = [LazyReferenceIdentifier]()
17+
18+
for identifierField in primaryKey.fields {
19+
let object = modelObject[identifierField.name]
20+
21+
switch object {
22+
case .string(let identifierValue):
23+
identifiers.append(.init(name: identifierField.name, value: identifierValue))
24+
default:
25+
throw ExtractionError.unsupportedLazyReferenceIdentifier(
26+
name: identifierField.name,
27+
value: object
28+
)
29+
}
30+
}
31+
32+
return identifiers
33+
}
34+
}

Amplify/Categories/DataStore/Model/Lazy/LazyReference.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,16 @@ public class LazyReference<ModelType: Model>: Codable, _LazyReferenceValue {
9696
}
9797
let json = try JSONValue(from: decoder)
9898
switch json {
99-
case .object:
99+
case .object(let object):
100100
if let element = try? ModelType(from: decoder) {
101101
self.init(element)
102102
return
103103
}
104+
else {
105+
let identifiers = try ModelType.schema.lazyReferenceIdentifiers(from: object)
106+
self.init(identifiers: identifiers)
107+
return
108+
}
104109
default:
105110
break
106111
}

AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,7 @@
21902190
CODE_SIGN_STYLE = Automatic;
21912191
CURRENT_PROJECT_VERSION = 1;
21922192
GENERATE_INFOPLIST_FILE = YES;
2193-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
2193+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
21942194
LD_RUNPATH_SEARCH_PATHS = (
21952195
"$(inherited)",
21962196
"@executable_path/Frameworks",
@@ -2215,7 +2215,7 @@
22152215
CODE_SIGN_STYLE = Automatic;
22162216
CURRENT_PROJECT_VERSION = 1;
22172217
GENERATE_INFOPLIST_FILE = YES;
2218-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
2218+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
22192219
LD_RUNPATH_SEARCH_PATHS = (
22202220
"$(inherited)",
22212221
"@executable_path/Frameworks",

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

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

AmplifyPlugins/API/Tests/APIHostApp/APIHostApp/SubscriptionView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class SubscriptionViewModel: ObservableObject {
5555
self.todos.append(todo)
5656
}
5757
}
58+
@available(iOS 14.0, *)
5859
struct SubscriptionView: View {
5960
@StateObject var vm = SubscriptionViewModel()
6061

@@ -73,6 +74,7 @@ struct SubscriptionView: View {
7374

7475
}
7576

77+
@available(iOS 14.0, *)
7678
struct SubscriptionView_Previews: PreviewProvider {
7779
static var previews: some View {
7880
SubscriptionView()

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/InitiateAuthSRP.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct InitiateAuthSRP: Action {
104104
parameters: parameters)
105105
return SignInEvent(eventType: .receivedChallenge(respondToAuthChallenge))
106106
}
107-
return SignInEvent(eventType: .respondPasswordVerifier(srpStateData, response))
107+
return SignInEvent(eventType: .respondPasswordVerifier(srpStateData, response, clientMetadata))
108108
}
109109
}
110110

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Actions/SignIn/SRPAuth/VerifyPasswordSRP.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ struct VerifyPasswordSRP: Action {
1414

1515
let stateData: SRPStateData
1616
let authResponse: InitiateAuthOutputResponse
17+
let clientMetadata: ClientMetadata
1718

1819
init(stateData: SRPStateData,
19-
authResponse: InitiateAuthOutputResponse) {
20+
authResponse: InitiateAuthOutputResponse,
21+
clientMetadata: ClientMetadata) {
2022
self.stateData = stateData
2123
self.authResponse = authResponse
24+
self.clientMetadata = clientMetadata
2225
}
2326

2427
func execute(withDispatcher dispatcher: EventDispatcher,
@@ -60,6 +63,7 @@ struct VerifyPasswordSRP: Action {
6063
session: authResponse.session,
6164
secretBlock: secretBlockString,
6265
signature: signature,
66+
clientMetadata: clientMetadata,
6367
deviceMetadata: deviceMetadata,
6468
asfDeviceId: asfDeviceId,
6569
environment: userPoolEnv)
@@ -83,7 +87,7 @@ struct VerifyPasswordSRP: Action {
8387
logVerbose("\(#fileID) Received device not found \(error)", environment: environment)
8488
// Remove the saved device details and retry password verify
8589
await DeviceMetadataHelper.removeDeviceMetaData(for: username, with: environment)
86-
let event = SignInEvent(eventType: .retryRespondPasswordVerifier(stateData, authResponse))
90+
let event = SignInEvent(eventType: .retryRespondPasswordVerifier(stateData, authResponse, clientMetadata))
8791
logVerbose("\(#fileID) Sending event \(event)",
8892
environment: environment)
8993
await dispatcher.send(event)

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/CodeGen/Events/SignInEvent.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import AWSCognitoIdentityProvider
1010

1111
typealias Username = String
1212
typealias Password = String
13+
typealias ClientMetadata = [String: String]
1314

1415
struct SignInEvent: StateMachineEvent {
1516

@@ -27,9 +28,9 @@ struct SignInEvent: StateMachineEvent {
2728

2829
case initiateMigrateAuth(SignInEventData, DeviceMetadata)
2930

30-
case respondPasswordVerifier(SRPStateData, InitiateAuthOutputResponse)
31+
case respondPasswordVerifier(SRPStateData, InitiateAuthOutputResponse, ClientMetadata)
3132

32-
case retryRespondPasswordVerifier(SRPStateData, InitiateAuthOutputResponse)
33+
case retryRespondPasswordVerifier(SRPStateData, InitiateAuthOutputResponse, ClientMetadata)
3334

3435
case initiateDeviceSRP(Username, SignInResponseBehavior)
3536

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/StateMachine/Resolvers/SRP/SRPSignInState+Resolver.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ extension SRPSignInState {
3232
switch oldState {
3333
case .notStarted:
3434
return resolveNotStarted(byApplying: srpSignInEvent)
35-
case .initiatingSRPA:
36-
return resolveInitiatingSRPA(byApplying: srpSignInEvent, from: oldState)
35+
case .initiatingSRPA(let signInEventData):
36+
return resolveInitiatingSRPA(
37+
byApplying: srpSignInEvent,
38+
from: oldState)
3739
case .respondingPasswordVerifier(let srpStateData):
38-
return resolveRespondingVerifyPassword(srpStateData: srpStateData, byApplying: srpSignInEvent)
40+
return resolveRespondingVerifyPassword(
41+
srpStateData: srpStateData,
42+
byApplying: srpSignInEvent)
3943
case .signedIn, .error:
4044
return .from(oldState)
4145
case .cancelling:
@@ -83,9 +87,11 @@ extension SRPSignInState {
8387
from oldState: SRPSignInState)
8488
-> StateResolution<SRPSignInState> {
8589
switch signInEvent.eventType {
86-
case .respondPasswordVerifier(let srpStateData, let authResponse):
87-
let action = VerifyPasswordSRP(stateData: srpStateData,
88-
authResponse: authResponse)
90+
case .respondPasswordVerifier(let srpStateData, let authResponse, let clientMetadata):
91+
let action = VerifyPasswordSRP(
92+
stateData: srpStateData,
93+
authResponse: authResponse,
94+
clientMetadata: clientMetadata)
8995
return StateResolution(
9096
newState: SRPSignInState.respondingPasswordVerifier(srpStateData),
9197
actions: [action]
@@ -102,9 +108,11 @@ extension SRPSignInState {
102108
byApplying signInEvent: SignInEvent)
103109
-> StateResolution<SRPSignInState> {
104110
switch signInEvent.eventType {
105-
case .retryRespondPasswordVerifier(let srpStateData, let authResponse):
106-
let action = VerifyPasswordSRP(stateData: srpStateData,
107-
authResponse: authResponse)
111+
case .retryRespondPasswordVerifier(let srpStateData, let authResponse, let clientMetadata):
112+
let action = VerifyPasswordSRP(
113+
stateData: srpStateData,
114+
authResponse: authResponse,
115+
clientMetadata: clientMetadata)
108116
return StateResolution(
109117
newState: SRPSignInState.respondingPasswordVerifier(srpStateData),
110118
actions: [action]

AmplifyPlugins/Auth/Sources/AWSCognitoAuthPlugin/Support/Utils/RespondToAuthChallengeInput+Amplify.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extension RespondToAuthChallengeInput {
1515
session: String?,
1616
secretBlock: String,
1717
signature: String,
18+
clientMetadata: ClientMetadata,
1819
deviceMetadata: DeviceMetadata,
1920
asfDeviceId: String?,
2021
environment: UserPoolEnvironment) -> RespondToAuthChallengeInput {
@@ -29,7 +30,7 @@ extension RespondToAuthChallengeInput {
2930
challengeType: .passwordVerifier,
3031
challengeResponses: challengeResponses,
3132
session: session,
32-
clientMetadata: [:],
33+
clientMetadata: clientMetadata,
3334
asfDeviceId: asfDeviceId,
3435
deviceMetadata: deviceMetadata,
3536
environment: environment)
@@ -119,7 +120,7 @@ extension RespondToAuthChallengeInput {
119120
challengeType: CognitoIdentityProviderClientTypes.ChallengeNameType,
120121
challengeResponses: [String: String],
121122
session: String?,
122-
clientMetadata: [String: String],
123+
clientMetadata: ClientMetadata,
123124
asfDeviceId: String?,
124125
deviceMetadata: DeviceMetadata,
125126
environment: UserPoolEnvironment) -> RespondToAuthChallengeInput {

0 commit comments

Comments
 (0)