15
15
import Logging
16
16
import NIOCore
17
17
18
+ // MARK: - Client Context
19
+
20
+ /// AWS Mobile SDK client fields.
21
+ public struct ClientApplication : Codable , Sendable {
22
+ /// The mobile app installation id
23
+ public let installationID : String ?
24
+ /// The app title for the mobile app as registered with AWS' mobile services.
25
+ public let appTitle : String ?
26
+ /// The version name of the application as registered with AWS' mobile services.
27
+ public let appVersionName : String ?
28
+ /// The app version code.
29
+ public let appVersionCode : String ?
30
+ /// The package name for the mobile application invoking the function
31
+ public let appPackageName : String ?
32
+
33
+ private enum CodingKeys : String , CodingKey {
34
+ case installationID = " installation_id "
35
+ case appTitle = " app_title "
36
+ case appVersionName = " app_version_name "
37
+ case appVersionCode = " app_version_code "
38
+ case appPackageName = " app_package_name "
39
+ }
40
+
41
+ public init (
42
+ installationID: String ? = nil ,
43
+ appTitle: String ? = nil ,
44
+ appVersionName: String ? = nil ,
45
+ appVersionCode: String ? = nil ,
46
+ appPackageName: String ? = nil
47
+ ) {
48
+ self . installationID = installationID
49
+ self . appTitle = appTitle
50
+ self . appVersionName = appVersionName
51
+ self . appVersionCode = appVersionCode
52
+ self . appPackageName = appPackageName
53
+ }
54
+ }
55
+
56
+ /// For invocations from the AWS Mobile SDK, data about the client application and device.
57
+ public struct ClientContext : Codable , Sendable {
58
+ /// Information about the mobile application invoking the function.
59
+ public let client : ClientApplication ?
60
+ /// Custom properties attached to the mobile event context.
61
+ public let custom : [ String : String ] ?
62
+ /// Environment settings from the mobile client.
63
+ public let environment : [ String : String ] ?
64
+
65
+ private enum CodingKeys : String , CodingKey {
66
+ case client
67
+ case custom
68
+ case environment = " env "
69
+ }
70
+
71
+ public init (
72
+ client: ClientApplication ? = nil ,
73
+ custom: [ String : String ] ? = nil ,
74
+ environment: [ String : String ] ? = nil
75
+ ) {
76
+ self . client = client
77
+ self . custom = custom
78
+ self . environment = environment
79
+ }
80
+ }
81
+
18
82
// MARK: - Context
19
83
20
84
/// Lambda runtime context.
@@ -26,7 +90,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
26
90
let invokedFunctionARN : String
27
91
let deadline : LambdaClock . Instant
28
92
let cognitoIdentity : String ?
29
- let clientContext : String ?
93
+ let clientContext : ClientContext ?
30
94
let logger : Logger
31
95
32
96
init (
@@ -35,7 +99,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
35
99
invokedFunctionARN: String ,
36
100
deadline: LambdaClock . Instant ,
37
101
cognitoIdentity: String ? ,
38
- clientContext: String ? ,
102
+ clientContext: ClientContext ? ,
39
103
logger: Logger
40
104
) {
41
105
self . requestID = requestID
@@ -76,7 +140,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
76
140
}
77
141
78
142
/// For invocations from the AWS Mobile SDK, data about the client application and device.
79
- public var clientContext : String ? {
143
+ public var clientContext : ClientContext ? {
80
144
self . storage. clientContext
81
145
}
82
146
@@ -93,7 +157,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
93
157
invokedFunctionARN: String ,
94
158
deadline: LambdaClock . Instant ,
95
159
cognitoIdentity: String ? = nil ,
96
- clientContext: String ? = nil ,
160
+ clientContext: ClientContext ? = nil ,
97
161
logger: Logger
98
162
) {
99
163
self . storage = _Storage (
@@ -113,7 +177,7 @@ public struct LambdaContext: CustomDebugStringConvertible, Sendable {
113
177
}
114
178
115
179
public var debugDescription : String {
116
- " \( Self . self) (requestID: \( self . requestID) , traceID: \( self . traceID) , invokedFunctionARN: \( self . invokedFunctionARN) , cognitoIdentity: \( self . cognitoIdentity ?? " nil " ) , clientContext: \( self . clientContext ?? " nil " ) , deadline: \( self . deadline) ) "
180
+ " \( Self . self) (requestID: \( self . requestID) , traceID: \( self . traceID) , invokedFunctionARN: \( self . invokedFunctionARN) , cognitoIdentity: \( self . cognitoIdentity ?? " nil " ) , clientContext: \( String ( describing : self . clientContext) ) , deadline: \( self . deadline) ) "
117
181
}
118
182
119
183
/// This interface is not part of the public API and must not be used by adopters. This API is not part of semver versioning.
0 commit comments