Skip to content

Commit 52798cb

Browse files
authored
Merge pull request #2851 from aws-amplify/liveness.main
2 parents 8410fea + 69344b0 commit 52798cb

File tree

142 files changed

+3209
-293
lines changed

Some content is hidden

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

142 files changed

+3209
-293
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/Amplify-Package.xcscheme

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,20 @@
342342
ReferencedContainer = "container:">
343343
</BuildableReference>
344344
</BuildActionEntry>
345+
<BuildActionEntry
346+
buildForTesting = "YES"
347+
buildForRunning = "YES"
348+
buildForProfiling = "YES"
349+
buildForArchiving = "YES"
350+
buildForAnalyzing = "YES">
351+
<BuildableReference
352+
BuildableIdentifier = "primary"
353+
BlueprintIdentifier = "AWSPredictionsPlugin"
354+
BuildableName = "AWSPredictionsPlugin"
355+
BlueprintName = "AWSPredictionsPlugin"
356+
ReferencedContainer = "container:">
357+
</BuildableReference>
358+
</BuildActionEntry>
345359
</BuildActionEntries>
346360
</BuildAction>
347361
<TestAction
@@ -495,6 +509,16 @@
495509
ReferencedContainer = "container:">
496510
</BuildableReference>
497511
</TestableReference>
512+
<TestableReference
513+
skipped = "NO">
514+
<BuildableReference
515+
BuildableIdentifier = "primary"
516+
BlueprintIdentifier = "AWSPredictionsPluginUnitTests"
517+
BuildableName = "AWSPredictionsPluginUnitTests"
518+
BlueprintName = "AWSPredictionsPluginUnitTests"
519+
ReferencedContainer = "container:">
520+
</BuildableReference>
521+
</TestableReference>
498522
</Testables>
499523
</TestAction>
500524
<LaunchAction

AmplifyPlugins/Core/AWSPluginsCore/Auth/Provider/AuthAWSCredentialsProvider.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ public protocol AuthAWSCredentialsProvider {
1212
func getAWSCredentials() -> Result<AWSCredentials, AuthError>
1313
}
1414

15+
public protocol AWSCredentialsProvider {
16+
func fetchAWSCredentials() async throws -> AWSCredentials
17+
}
18+
1519
public protocol AWSTemporaryCredentials: AWSCredentials {
1620

1721
var sessionToken: String { get }

AmplifyPlugins/Predictions/AWSPredictionsPlugin/AWSPredictionsPlugin+ClientBehavior.swift

Lines changed: 30 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -10,100 +10,53 @@ import Amplify
1010

1111
extension AWSPredictionsPlugin {
1212

13-
public func convert(textToTranslate: String,
14-
language: LanguageType?,
15-
targetLanguage: LanguageType?,
16-
options: PredictionsTranslateTextRequest.Options?,
17-
listener: PredictionsTranslateTextOperation.ResultListener? = nil)
18-
-> PredictionsTranslateTextOperation {
19-
20-
let request = PredictionsTranslateTextRequest(textToTranslate: textToTranslate,
21-
targetLanguage: targetLanguage,
22-
language: language,
23-
options: options ?? PredictionsTranslateTextRequest.Options())
24-
let convertOperation = AWSTranslateOperation(request,
25-
predictionsService: predictionsService,
26-
resultListener: listener)
27-
queue.addOperation(convertOperation)
28-
return convertOperation
13+
public func convert(
14+
textToTranslate: String,
15+
language: LanguageType?,
16+
targetLanguage: LanguageType?,
17+
options: PredictionsTranslateTextRequest.Options?,
18+
listener: PredictionsTranslateTextOperation.ResultListener? = nil
19+
)
20+
-> PredictionsTranslateTextOperation {
21+
fatalError()
2922
}
3023

31-
public func convert(textToSpeech: String,
32-
options: PredictionsTextToSpeechRequest.Options?,
33-
listener: PredictionsTextToSpeechOperation.ResultListener? = nil)
34-
-> PredictionsTextToSpeechOperation {
35-
let request = PredictionsTextToSpeechRequest(
36-
textToSpeech: textToSpeech,
37-
options: options ?? PredictionsTextToSpeechRequest.Options())
38-
39-
let convertOperation = AWSPollyOperation(request,
40-
predictionsService: predictionsService,
41-
resultListener: listener)
42-
43-
queue.addOperation(convertOperation)
44-
return convertOperation
45-
24+
public func convert(
25+
textToSpeech: String,
26+
options: PredictionsTextToSpeechRequest.Options?,
27+
listener: PredictionsTextToSpeechOperation.ResultListener? = nil
28+
)
29+
-> PredictionsTextToSpeechOperation {
30+
fatalError()
4631
}
4732

4833
public func convert(
4934
speechToText: URL,
5035
options: PredictionsSpeechToTextRequest.Options?,
5136
listener: PredictionsSpeechToTextOperation.ResultListener?
5237
) -> PredictionsSpeechToTextOperation {
53-
let request = PredictionsSpeechToTextRequest(speechToText: speechToText,
54-
options: options ?? PredictionsSpeechToTextRequest.Options())
55-
56-
let multiService = TranscribeMultiService(coreMLService: coreMLService, predictionsService: predictionsService)
57-
58-
// only one transcription request can be sent at a time otherwise you receive an error
59-
let requestInProcess = queue.operations.contains(where: { $0 is AWSTranscribeOperation})
60-
61-
let operation = AWSTranscribeOperation(request: request,
62-
multiService: multiService,
63-
requestInProcess: requestInProcess,
64-
resultListener: listener)
65-
queue.addOperation(operation)
66-
return operation
67-
38+
fatalError()
6839
}
6940

70-
public func identify(type: IdentifyAction,
71-
image: URL,
72-
options: PredictionsIdentifyRequest.Options?,
73-
listener: PredictionsIdentifyOperation.ResultListener? = nil) -> PredictionsIdentifyOperation {
74-
let options = options
75-
76-
let request = PredictionsIdentifyRequest(image: image,
77-
identifyType: type,
78-
options: options ?? PredictionsIdentifyRequest.Options())
79-
let multiService = IdentifyMultiService(coreMLService: coreMLService,
80-
predictionsService: predictionsService)
81-
let operation = IdentifyOperation(request: request,
82-
multiService: multiService,
83-
resultListener: listener)
84-
85-
queue.addOperation(operation)
86-
return operation
87-
41+
public func identify(
42+
type: IdentifyAction,
43+
image: URL,
44+
options: PredictionsIdentifyRequest.Options?,
45+
listener: PredictionsIdentifyOperation.ResultListener? = nil
46+
) -> PredictionsIdentifyOperation {
47+
fatalError()
8848
}
8949

9050
/// Interprets the input text and detects sentiment, language, syntax, and key phrases
9151
///
9252
/// - Parameter text: input text
9353
/// - Parameter options: Option for the plugin
9454
/// - Parameter resultListener: Listener to which events are send
95-
public func interpret(text: String,
96-
options: PredictionsInterpretRequest.Options?,
97-
listener: PredictionsInterpretOperation.ResultListener?) -> PredictionsInterpretOperation {
98-
99-
let request = PredictionsInterpretRequest(textToInterpret: text,
100-
options: options ?? PredictionsInterpretRequest.Options())
101-
let multiService = InterpretTextMultiService(coreMLService: coreMLService,
102-
predictionsService: predictionsService)
103-
let operation = InterpretTextOperation(request,
104-
multiService: multiService,
105-
resultListener: listener)
106-
queue.addOperation(operation)
107-
return operation
55+
public func interpret(
56+
text: String,
57+
options: PredictionsInterpretRequest.Options?,
58+
listener: PredictionsInterpretOperation.ResultListener?
59+
) -> PredictionsInterpretOperation {
60+
fatalError()
10861
}
10962
}

AmplifyPlugins/Predictions/AWSPredictionsPlugin/AWSPredictionsPlugin+Configure.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import Amplify
99
import Foundation
1010
import AWSPluginsCore
11-
import AWSCore
1211

1312
extension AWSPredictionsPlugin {
1413

@@ -21,7 +20,7 @@ extension AWSPredictionsPlugin {
2120
/// - Throws:
2221
/// - PluginError.pluginConfigurationError: If one of the configuration values is invalid or empty
2322
public func configure(using configuration: Any?) throws {
24-
23+
/*
2524
guard let jsonValueConfiguration = configuration as? JSONValue else {
2625
throw PluginError.pluginConfigurationError(PluginErrorMessage.decodeConfigurationError.errorDescription,
2726
PluginErrorMessage.decodeConfigurationError.recoverySuggestion)
@@ -40,8 +39,10 @@ extension AWSPredictionsPlugin {
4039
coreMLSerivce: coremlService,
4140
authService: authService,
4241
config: predictionsConfiguration)
42+
*/
4343
}
4444

45+
/*
4546
func configure(predictionsService: AWSPredictionsService,
4647
coreMLSerivce: CoreMLPredictionBehavior,
4748
authService: AWSAuthServiceBehavior,
@@ -53,4 +54,5 @@ extension AWSPredictionsPlugin {
5354
self.config = config
5455
self.queue = queue
5556
}
57+
*/
5658
}

AmplifyPlugins/Predictions/AWSPredictionsPlugin/AWSPredictionsPlugin+Reset.swift

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,8 @@ import Foundation
99
import Amplify
1010

1111
extension AWSPredictionsPlugin {
12-
13-
public func reset(onComplete: @escaping BasicClosure) {
14-
if predictionsService != nil {
15-
predictionsService.reset()
16-
predictionsService = nil
17-
}
18-
19-
if authService != nil {
20-
authService = nil
21-
}
22-
23-
if queue != nil {
24-
queue = nil
25-
}
26-
27-
onComplete()
12+
public func reset() async {
13+
// TODO: Reset services
14+
queue = nil
2815
}
2916
}

AmplifyPlugins/Predictions/AWSPredictionsPlugin/AWSPredictionsPlugin.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import Amplify
99
import Foundation
1010
import AWSPluginsCore
11-
import AWSCore
1211

1312
final public class AWSPredictionsPlugin: PredictionsCategoryPlugin {
1413

@@ -18,13 +17,15 @@ final public class AWSPredictionsPlugin: PredictionsCategoryPlugin {
1817
var queue: OperationQueue!
1918

2019
/// An instance of the predictions service
20+
/*
2121
var predictionsService: AWSPredictionsService!
2222

2323
var coreMLService: CoreMLPredictionBehavior!
2424

2525
var authService: AWSAuthServiceBehavior!
2626

2727
var config: PredictionsPluginConfiguration!
28+
*/
2829

2930
/// public limit rekognition has on number of faces it can detect.
3031
public static let rekognitionMaxEntitiesLimit = 50
@@ -34,9 +35,11 @@ final public class AWSPredictionsPlugin: PredictionsCategoryPlugin {
3435
return awsPredictionsPluginKey
3536
}
3637

38+
/*
3739
public func getEscapeHatch(key: PredictionsAWSService) -> AWSService {
3840
return predictionsService.getEscapeHatch(key: key)
3941
}
42+
*/
4043

4144
public init() {
4245
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 Date {
11+
var epochMilliseconds: UInt64 {
12+
UInt64(self.timeIntervalSince1970 * 1_000)
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
@_spi(PredictionsFaceLiveness)
11+
public struct CompletedEvent<T> {
12+
public init(initialEvent: T, endTimestamp: UInt64) {
13+
self.initialEvent = initialEvent
14+
self.endTimestamp = endTimestamp
15+
}
16+
17+
let initialEvent: T
18+
let endTimestamp: UInt64
19+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
@_spi(PredictionsFaceLiveness)
11+
public struct LivenessEvent<T> {
12+
let payload: Data
13+
let eventKind: LivenessEventKind
14+
let eventTypeHeader: String
15+
}
16+
17+
@_spi(PredictionsFaceLiveness)
18+
public enum LivenessEventKind {
19+
public struct Server: Hashable {
20+
public static let challenge = Server()
21+
public static let disconnect = Server()
22+
}
23+
case server(Server)
24+
25+
public struct Client: Equatable {
26+
let id: UInt8
27+
28+
public static let initialFaceDetected = Client(id: 0)
29+
public static let video = Client(id: 1)
30+
public static let freshness = Client(id: 2)
31+
public static let final = Client(id: 3)
32+
}
33+
case client(Client)
34+
}
35+
36+
extension LivenessEventKind: CustomDebugStringConvertible {
37+
public var debugDescription: String {
38+
switch self {
39+
case .server(.challenge): return ".server(.challenge)"
40+
case .server(.disconnect): return ".server(.disconnect)"
41+
case .client(.initialFaceDetected): return ".client(.initialFaceDetected)"
42+
case .client(.video): return ".client(.video)"
43+
case .client(.freshness): return ".client(.freshness)"
44+
case .client(.final): return ".client(.final)"
45+
default: return "unknown"
46+
}
47+
}
48+
}
49+
50+
extension LivenessEvent: CustomDebugStringConvertible {
51+
public var debugDescription: String {
52+
return """
53+
LivenessEvent<\(T.self)>(
54+
payload: \(payload),
55+
eventKind: \(eventKind),
56+
eventTypeHeader: \(eventTypeHeader)
57+
)
58+
"""
59+
}
60+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
@_spi(PredictionsFaceLiveness)
11+
public struct FaceDetection {
12+
let boundingBox: FaceLivenessSession.BoundingBox
13+
let startTimestamp: UInt64
14+
15+
public init(boundingBox: FaceLivenessSession.BoundingBox, startTimestamp: UInt64) {
16+
self.boundingBox = boundingBox
17+
self.startTimestamp = startTimestamp
18+
}
19+
}

0 commit comments

Comments
 (0)