@@ -14,13 +14,15 @@ import Foundation
1414
1515/// Represents Amplify's Gen2 configuration for all categories intended to be used in an application.
1616///
17+ /// Currently supports schema version `1` of the `amplify_outputs.json` format.
18+ ///
1719/// See: [Amplify.configure](x-source-tag://Amplify.configure)
1820///
1921/// - Tag: AmplifyOutputs
2022///
21- @_spi ( InternalAmplifyConfiguration)
2223public struct AmplifyOutputsData : Codable {
23- public let version : String
24+ static let currentVersion = " 1 "
25+ let version : String
2426 public let analytics : Analytics ?
2527 public let auth : Auth ?
2628 public let data : DataCategory ?
@@ -29,17 +31,24 @@ public struct AmplifyOutputsData: Codable {
2931 public let storage : Storage ?
3032 public let custom : CustomOutput ?
3133
32- @_spi ( InternalAmplifyConfiguration)
3334 public struct Analytics : Codable {
3435 public let amazonPinpoint : AmazonPinpoint ?
3536
3637 public struct AmazonPinpoint : Codable {
3738 public let awsRegion : AWSRegion
3839 public let appId : String
40+
41+ public init ( awsRegion: AWSRegion , appId: String ) {
42+ self . awsRegion = awsRegion
43+ self . appId = appId
44+ }
45+ }
46+
47+ public init ( amazonPinpoint: AmazonPinpoint ? = nil ) {
48+ self . amazonPinpoint = amazonPinpoint
3949 }
4050 }
4151
42- @_spi ( InternalAmplifyConfiguration)
4352 public struct Auth : Codable {
4453 public let awsRegion : AWSRegion
4554 public let userPoolId : String
@@ -54,38 +63,64 @@ public struct AmplifyOutputsData: Codable {
5463 public let mfaConfiguration : String ?
5564 public let mfaMethods : [ String ] ?
5665
57- @_spi ( InternalAmplifyConfiguration)
5866 public struct PasswordPolicy : Codable {
5967 public let minLength : UInt
6068 public let requireNumbers : Bool
6169 public let requireLowercase : Bool
6270 public let requireUppercase : Bool
6371 public let requireSymbols : Bool
72+
73+ public init (
74+ minLength: UInt ,
75+ requireNumbers: Bool ,
76+ requireLowercase: Bool ,
77+ requireUppercase: Bool ,
78+ requireSymbols: Bool
79+ ) {
80+ self . minLength = minLength
81+ self . requireNumbers = requireNumbers
82+ self . requireLowercase = requireLowercase
83+ self . requireUppercase = requireUppercase
84+ self . requireSymbols = requireSymbols
85+ }
6486 }
6587
66- @_spi ( InternalAmplifyConfiguration)
6788 public struct OAuth : Codable {
6889 public let identityProviders : [ String ]
6990 public let domain : String
7091 public let scopes : [ String ]
7192 public let redirectSignInUri : [ String ]
7293 public let redirectSignOutUri : [ String ]
7394 public let responseType : String
95+
96+ public init (
97+ identityProviders: [ String ] ,
98+ domain: String ,
99+ scopes: [ String ] ,
100+ redirectSignInUri: [ String ] ,
101+ redirectSignOutUri: [ String ] ,
102+ responseType: String
103+ ) {
104+ self . identityProviders = identityProviders
105+ self . domain = domain
106+ self . scopes = scopes
107+ self . redirectSignInUri = redirectSignInUri
108+ self . redirectSignOutUri = redirectSignOutUri
109+ self . responseType = responseType
110+ }
74111 }
75112
76- @_spi ( InternalAmplifyConfiguration)
77113 public enum UsernameAttributes : String , Codable {
78114 case email
79115 case phoneNumber = " phone_number "
80116 }
81117
82- @_spi ( InternalAmplifyConfiguration)
83118 public enum UserVerificationType : String , Codable {
84119 case email
85120 case phoneNumber = " phone_number "
86121 }
87122
88- init (
123+ public init (
89124 awsRegion: AWSRegion ,
90125 userPoolId: String ,
91126 userPoolClientId: String ,
@@ -115,48 +150,76 @@ public struct AmplifyOutputsData: Codable {
115150
116151 }
117152
118- @_spi ( InternalAmplifyConfiguration)
119153 public struct DataCategory : Codable {
120154 public let awsRegion : AWSRegion
121155 public let url : String
122156 public let modelIntrospection : JSONValue ?
123157 public let apiKey : String ?
124158 public let defaultAuthorizationType : AWSAppSyncAuthorizationType
125159 public let authorizationTypes : [ AWSAppSyncAuthorizationType ]
160+
161+ public init (
162+ awsRegion: AWSRegion ,
163+ url: String ,
164+ modelIntrospection: JSONValue ? = nil ,
165+ apiKey: String ? = nil ,
166+ defaultAuthorizationType: AWSAppSyncAuthorizationType ,
167+ authorizationTypes: [ AWSAppSyncAuthorizationType ]
168+ ) {
169+ self . awsRegion = awsRegion
170+ self . url = url
171+ self . modelIntrospection = modelIntrospection
172+ self . apiKey = apiKey
173+ self . defaultAuthorizationType = defaultAuthorizationType
174+ self . authorizationTypes = authorizationTypes
175+ }
126176 }
127177
128- @_spi ( InternalAmplifyConfiguration)
129178 public struct Geo : Codable {
130179 public let awsRegion : AWSRegion
131180 public let maps : Maps ?
132181 public let searchIndices : SearchIndices ?
133182 public let geofenceCollections : GeofenceCollections ?
134183
135- @_spi ( InternalAmplifyConfiguration)
136184 public struct Maps : Codable {
137185 public let items : [ String : AmazonLocationServiceConfig ]
138186 public let `default` : String
139187
140- @_spi ( InternalAmplifyConfiguration)
141188 public struct AmazonLocationServiceConfig : Codable {
142189 public let style : String
190+
191+ public init ( style: String ) {
192+ self . style = style
193+ }
194+ }
195+
196+ public init ( items: [ String : AmazonLocationServiceConfig ] , default defaultMap: String ) {
197+ self . items = items
198+ self . default = defaultMap
143199 }
144200 }
145201
146- @_spi ( InternalAmplifyConfiguration)
147202 public struct SearchIndices : Codable {
148203 public let items : [ String ]
149204 public let `default` : String
205+
206+ public init ( items: [ String ] , default defaultIndex: String ) {
207+ self . items = items
208+ self . default = defaultIndex
209+ }
150210 }
151211
152- @_spi ( InternalAmplifyConfiguration)
153212 public struct GeofenceCollections : Codable {
154213 public let items : [ String ]
155214 public let `default` : String
215+
216+ public init ( items: [ String ] , default defaultCollection: String ) {
217+ self . items = items
218+ self . default = defaultCollection
219+ }
156220 }
157221
158- // Internal init used for testing
159- init (
222+ public init (
160223 awsRegion: AWSRegion ,
161224 maps: Maps ? = nil ,
162225 searchIndices: SearchIndices ? = nil ,
@@ -169,28 +232,36 @@ public struct AmplifyOutputsData: Codable {
169232 }
170233 }
171234
172- @_spi ( InternalAmplifyConfiguration)
173235 public struct Notifications : Codable {
174236 public let awsRegion : String
175237 public let amazonPinpointAppId : String
176238 public let channels : [ AmazonPinpointChannelType ]
239+
240+ public init ( awsRegion: String , amazonPinpointAppId: String , channels: [ AmazonPinpointChannelType ] ) {
241+ self . awsRegion = awsRegion
242+ self . amazonPinpointAppId = amazonPinpointAppId
243+ self . channels = channels
244+ }
177245 }
178246
179- @_spi ( InternalAmplifyConfiguration)
180247 public struct Storage : Codable {
181248 public let awsRegion : AWSRegion
182249 public let bucketName : String
183250 public let buckets : [ Bucket ] ?
184251
185- @_spi ( InternalAmplifyConfiguration)
186252 public struct Bucket : Codable {
187253 public let name : String
188254 public let bucketName : String
189255 public let awsRegion : AWSRegion
256+
257+ public init ( name: String , bucketName: String , awsRegion: AWSRegion ) {
258+ self . name = name
259+ self . bucketName = bucketName
260+ self . awsRegion = awsRegion
261+ }
190262 }
191263
192- // Internal init used for testing
193- init (
264+ public init (
194265 awsRegion: AWSRegion ,
195266 bucketName: String ,
196267 buckets: [ Bucket ] ? = nil
@@ -201,13 +272,10 @@ public struct AmplifyOutputsData: Codable {
201272 }
202273 }
203274
204- @_spi ( InternalAmplifyConfiguration)
205275 public struct CustomOutput : Codable { }
206276
207- @_spi ( InternalAmplifyConfiguration)
208277 public typealias AWSRegion = String
209278
210- @_spi ( InternalAmplifyConfiguration)
211279 public enum AmazonCognitoStandardAttributes : String , Codable , CodingKeyRepresentable {
212280 case address
213281 case birthdate
@@ -229,7 +297,6 @@ public struct AmplifyOutputsData: Codable {
229297 case zoneinfo
230298 }
231299
232- @_spi ( InternalAmplifyConfiguration)
233300 public enum AWSAppSyncAuthorizationType : String , Codable {
234301 case amazonCognitoUserPools = " AMAZON_COGNITO_USER_POOLS "
235302 case apiKey = " API_KEY "
@@ -238,7 +305,6 @@ public struct AmplifyOutputsData: Codable {
238305 case openIDConnect = " OPENID_CONNECT "
239306 }
240307
241- @_spi ( InternalAmplifyConfiguration)
242308 public enum AmazonPinpointChannelType : String , Codable {
243309 case inAppMessaging = " IN_APP_MESSAGING "
244310 case fcm = " FCM "
@@ -247,7 +313,28 @@ public struct AmplifyOutputsData: Codable {
247313 case sms = " SMS "
248314 }
249315
250- // Internal init used for testing
316+ public init (
317+ analytics: Analytics ? = nil ,
318+ auth: Auth ? = nil ,
319+ data: DataCategory ? = nil ,
320+ geo: Geo ? = nil ,
321+ notifications: Notifications ? = nil ,
322+ storage: Storage ? = nil ,
323+ custom: CustomOutput ? = nil
324+ ) {
325+ self . init (
326+ version: AmplifyOutputsData . currentVersion,
327+ analytics: analytics,
328+ auth: auth,
329+ data: data,
330+ geo: geo,
331+ notifications: notifications,
332+ storage: storage,
333+ custom: custom
334+ )
335+ }
336+
337+ // Internal init preserving version parameter for backward compatibility
251338 init (
252339 version: String = " " ,
253340 analytics: Analytics ? = nil ,
@@ -276,13 +363,12 @@ public struct AmplifyOutputsData: Codable {
276363public struct AmplifyOutputs : @unchecked Sendable {
277364
278365 /// A closure that resolves the `AmplifyOutputsData` configuration
279- @_spi ( InternalAmplifyConfiguration)
280366 public let resolveConfiguration : ( ) throws -> AmplifyOutputsData
281367
282368 /// Resolves configuration with `amplify_outputs.json` in the main bundle.
283369 public static let amplifyOutputs : AmplifyOutputs = . init {
284- try AmplifyOutputsData ( bundle: Bundle . main, resource: " amplify_outputs " )
285- }
370+ try AmplifyOutputsData ( bundle: Bundle . main, resource: " amplify_outputs " )
371+ }
286372
287373 /// Resolves configuration with a data object, from the contents of an `amplify_outputs.json` file.
288374 public static func data( _ data: Data ) -> AmplifyOutputs {
@@ -336,7 +422,6 @@ public extension Amplify {
336422 /// - Parameter configuration: The AmplifyOutputsData object
337423 ///
338424 /// - Tag: Amplify.configure
339- @_spi ( InternalAmplifyConfiguration)
340425 static func configure( _ configuration: AmplifyOutputsData ) throws {
341426 // Always configure logging first since Auth dependings on logging
342427 try configure ( CategoryType . logging. category, using: configuration)
0 commit comments