@falconeta/capacitor-aws-amplify 0.0.21 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/capacitor/aws/amplify/AwsAmplify.java +103 -8
- package/android/src/main/java/com/capacitor/aws/amplify/AwsAmplifyPlugin.java +11 -0
- package/dist/esm/web.js +0 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +0 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +0 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/AwsAmplify.swift +2 -2
- package/package.json +1 -1
|
@@ -10,21 +10,21 @@ import androidx.annotation.Nullable;
|
|
|
10
10
|
import androidx.annotation.RequiresApi;
|
|
11
11
|
|
|
12
12
|
import com.amazonaws.mobile.client.AWSMobileClient;
|
|
13
|
-
import com.amazonaws.mobile.client.DeviceOperations;
|
|
14
|
-
import com.amazonaws.mobile.client.results.Device;
|
|
15
|
-
import com.amazonaws.mobile.client.results.ListDevicesResult;
|
|
16
13
|
import com.amazonaws.mobile.client.results.Tokens;
|
|
17
14
|
import com.amplifyframework.AmplifyException;
|
|
18
15
|
import com.amplifyframework.auth.AuthCategoryConfiguration;
|
|
19
16
|
import com.amplifyframework.auth.AuthException;
|
|
20
17
|
import com.amplifyframework.auth.AuthProvider;
|
|
18
|
+
import com.amplifyframework.auth.AuthUserAttribute;
|
|
19
|
+
import com.amplifyframework.auth.AuthUserAttributeKey;
|
|
21
20
|
import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin;
|
|
22
21
|
import com.amplifyframework.auth.cognito.AWSCognitoAuthSession;
|
|
22
|
+
import com.amplifyframework.auth.options.AuthUpdateUserAttributesOptions;
|
|
23
23
|
import com.amplifyframework.auth.result.AuthSessionResult;
|
|
24
|
-
import com.amplifyframework.auth.result.AuthSignInResult;
|
|
25
24
|
import com.amplifyframework.core.Amplify;
|
|
26
25
|
import com.amplifyframework.core.AmplifyConfiguration;
|
|
27
26
|
import com.amplifyframework.core.category.CategoryConfiguration;
|
|
27
|
+
import com.getcapacitor.JSArray;
|
|
28
28
|
import com.getcapacitor.JSObject;
|
|
29
29
|
|
|
30
30
|
import org.json.JSONException;
|
|
@@ -33,10 +33,12 @@ import org.json.JSONObject;
|
|
|
33
33
|
import java.util.HashMap;
|
|
34
34
|
import java.util.List;
|
|
35
35
|
import java.util.Map;
|
|
36
|
-
import java.util.Objects;
|
|
37
36
|
import java.util.function.Consumer;
|
|
37
|
+
import java.util.stream.Collectors;
|
|
38
38
|
|
|
39
39
|
public class AwsAmplify {
|
|
40
|
+
|
|
41
|
+
private String TAG = "AwsAmplify";
|
|
40
42
|
boolean isLoaded;
|
|
41
43
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
42
44
|
public void load(JSObject cognitoConfig, Context context, @NonNull Consumer onSuccess, @NonNull Consumer<Exception> onError) {
|
|
@@ -219,6 +221,83 @@ public class AwsAmplify {
|
|
|
219
221
|
});
|
|
220
222
|
}
|
|
221
223
|
|
|
224
|
+
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
225
|
+
public void updateUserAttributes(JSArray attributes,
|
|
226
|
+
@Nullable Consumer<JSObject> onSuccess,
|
|
227
|
+
@Nullable Consumer<Exception> onError) {
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
var attr = attributes.<JSONObject>toList().stream().map(item ->{
|
|
231
|
+
try {
|
|
232
|
+
return new AuthUserAttribute(this.getAttributeKey(item.getString("name")), item.getString("value"));
|
|
233
|
+
} catch (JSONException e) {
|
|
234
|
+
throw new RuntimeException(e);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
updateUserAttributesInternal(
|
|
239
|
+
attr.collect(Collectors.toList()),
|
|
240
|
+
userAttributes -> {
|
|
241
|
+
JSObject ret = new JSObject();
|
|
242
|
+
ret.put("status", 0);
|
|
243
|
+
ret.put("userAttributes", userAttributes);
|
|
244
|
+
onSuccess.accept(ret);
|
|
245
|
+
},
|
|
246
|
+
error -> {
|
|
247
|
+
if (onError != null) {
|
|
248
|
+
String message = error.getMessage();
|
|
249
|
+
String suggestion = error.getRecoverySuggestion();
|
|
250
|
+
Throwable cause = error.getCause();
|
|
251
|
+
JSObject ret = new JSObject();
|
|
252
|
+
ret.put("status", -1);
|
|
253
|
+
if (AuthException.SignedOutException.class.isInstance(error)) {
|
|
254
|
+
ret.put("status", -3);
|
|
255
|
+
}
|
|
256
|
+
onSuccess.accept(ret);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
} catch (JSONException e) {
|
|
261
|
+
throw new RuntimeException(e);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
private AuthUserAttributeKey getAttributeKey(String key){
|
|
268
|
+
switch(key){
|
|
269
|
+
case "address":
|
|
270
|
+
return AuthUserAttributeKey.address();
|
|
271
|
+
case "birthDate":
|
|
272
|
+
return AuthUserAttributeKey.birthdate();
|
|
273
|
+
case "email":
|
|
274
|
+
return AuthUserAttributeKey.email();
|
|
275
|
+
case "familyName":
|
|
276
|
+
return AuthUserAttributeKey.familyName();
|
|
277
|
+
case "gender":
|
|
278
|
+
return AuthUserAttributeKey.gender();
|
|
279
|
+
case "givenName":
|
|
280
|
+
return AuthUserAttributeKey.givenName();
|
|
281
|
+
case "locale":
|
|
282
|
+
return AuthUserAttributeKey.locale();
|
|
283
|
+
case "middleName":
|
|
284
|
+
return AuthUserAttributeKey.middleName();
|
|
285
|
+
case "name":
|
|
286
|
+
return AuthUserAttributeKey.name();
|
|
287
|
+
case "nickname":
|
|
288
|
+
return AuthUserAttributeKey.nickname();
|
|
289
|
+
case "phoneNumber":
|
|
290
|
+
return AuthUserAttributeKey.phoneNumber();
|
|
291
|
+
case "picture":
|
|
292
|
+
return AuthUserAttributeKey.picture();
|
|
293
|
+
case "preferredUsername":
|
|
294
|
+
return AuthUserAttributeKey.preferredUsername();
|
|
295
|
+
default:
|
|
296
|
+
return AuthUserAttributeKey.custom("custom:" + key);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
|
|
222
301
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
223
302
|
private void fetchSessionInternal(@Nullable Consumer<AwsAuthSession> onSuccess,
|
|
224
303
|
@Nullable Consumer<AuthException> onError) {
|
|
@@ -261,7 +340,7 @@ public class AwsAmplify {
|
|
|
261
340
|
}
|
|
262
341
|
},
|
|
263
342
|
error -> {
|
|
264
|
-
|
|
343
|
+
Log.e(TAG, "fetchSessionInternal error: ", error);
|
|
265
344
|
|
|
266
345
|
if (onError != null) {
|
|
267
346
|
onError.accept(error);
|
|
@@ -276,13 +355,29 @@ public class AwsAmplify {
|
|
|
276
355
|
attributes -> {
|
|
277
356
|
var userAttributes = new JSObject();
|
|
278
357
|
attributes.forEach(attribute -> {
|
|
279
|
-
userAttributes.put(attribute.getKey().getKeyString(), attribute.getValue());
|
|
358
|
+
userAttributes.put(attribute.getKey().getKeyString().replaceFirst("custom:", ""), attribute.getValue());
|
|
280
359
|
});
|
|
281
360
|
|
|
282
361
|
onSuccess.accept(userAttributes);
|
|
283
362
|
},
|
|
284
363
|
error -> {
|
|
285
|
-
|
|
364
|
+
Log.e(TAG, "fetchUserAttributesInternal error: ", error);
|
|
365
|
+
if (onError != null) {
|
|
366
|
+
onError.accept(error);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
372
|
+
private void updateUserAttributesInternal(List<AuthUserAttribute> attributes,
|
|
373
|
+
@Nullable Consumer<JSObject> onSuccess,
|
|
374
|
+
@Nullable Consumer<AuthException> onError) {
|
|
375
|
+
Amplify.Auth.updateUserAttributes(attributes, AuthUpdateUserAttributesOptions.defaults(),
|
|
376
|
+
result -> {
|
|
377
|
+
this.fetchUserAttributesInternal(onSuccess, onError);
|
|
378
|
+
},
|
|
379
|
+
error -> {
|
|
380
|
+
Log.e(TAG, "updateUserAttributesInternal error: ", error);
|
|
286
381
|
|
|
287
382
|
if (onError != null) {
|
|
288
383
|
onError.accept(error);
|
|
@@ -75,4 +75,15 @@ public class AwsAmplifyPlugin extends Plugin {
|
|
|
75
75
|
call.reject(error.toString());
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
80
|
+
@PluginMethod
|
|
81
|
+
public void updateUserAttributes(PluginCall call) {
|
|
82
|
+
var userAttributes = call.getArray("attributes");
|
|
83
|
+
implementation.updateUserAttributes(userAttributes,
|
|
84
|
+
result -> call.resolve(result),
|
|
85
|
+
error -> {
|
|
86
|
+
call.reject(error.toString());
|
|
87
|
+
});
|
|
88
|
+
}
|
|
78
89
|
}
|
package/dist/esm/web.js
CHANGED
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EACL,oBAAoB,GAIrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,OAAO,aAAc,SAAQ,SAAS;IAG1C,KAAK,CAAC,IAAI,CAAC,OAA4C;QACrD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,OAAO,CAAC,SAAS,mBAAM,OAAO,CAAC,aAAa,EAAG,CAAC;IAClD,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,OAGZ;QACC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACpC;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itor/core';\nimport type { CognitoUser } from 'amazon-cognito-identity-js';\nimport { Amplify, Auth } from 'aws-amplify';\n\nimport {\n AuthUserAttributeKey,\n AwsAmplifyPlugin,\n AWSCognitoConfig,\n CognitoAuthSession,\n} from './definitions';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\n\nexport class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {\n private cognitoConfig?: AWSCognitoConfig;\n\n async load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void> {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure({ ...options.cognitoConfig });\n }\n async signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n\n const user = (await Auth.signIn(\n options.email,\n options.password,\n )) as CognitoUser;\n\n return this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n } catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n\n async federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n\n await Auth.federatedSignIn(options as FederatedSignInOptions);\n return this.fetchAuthSession();\n } catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\n }\n\n async fetchAuthSession(): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession: CognitoAuthSession = this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n\n return cognitoAuthSession;\n } catch (error) {\n return this.handleError(error, 'fetchAuthSession');\n }\n }\n\n async getUserAttributes(): Promise<{\n status: AwsAmplifyPluginResponseStatus;\n userAttributes: Record<string, string>;\n }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes:\n attributes?.reduce(\n (acc, data) => ({ ...acc, [data.Name.replace('custom:', '')]: data.Value }),\n {},\n ) || {},\n });\n return;\n });\n });\n } catch (error) {\n return {\n ...this.handleError(error, 'getUserAttributes'),\n userAttributes: {},\n };\n }\n }\n\n async updateUserAttributes(options: {\n attributes: { name: AuthUserAttributeKey | string; value: string }[];\n }): Promise<{\n status: AwsAmplifyPluginResponseStatus;\n userAttributes: Record<string, string>;\n }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = await Auth.currentAuthenticatedUser();\n await new Promise<{\n status: AwsAmplifyPluginResponseStatus;\n }>((resolve, reject) => {\n user.updateAttributes(\n options.attributes.map(({ name, value }) => ({\n Name: Object.values(AuthUserAttributeKey).includes(\n name as AuthUserAttributeKey,\n )\n ? name\n : `custom:${name}`,\n Value: value,\n })),\n error => {\n // console.log('FROM updateUserAttributes', metadata);\n if (error) {\n reject(error);\n return;\n }\n\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n });\n return;\n },\n );\n });\n\n return this.getUserAttributes();\n } catch (error) {\n return {\n ...this.handleError(error, 'updateUserAttributes'),\n userAttributes: {},\n };\n }\n }\n\n async signOut(): Promise<{ status: AwsAmplifyPluginResponseStatus }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(error => this.handleError(error, 'signOut'));\n }\n\n private getCognitoAuthSession(user: CognitoUser, identityId: string) {\n const userSession = user.getSignInUserSession();\n\n const res: CognitoAuthSession = {\n accessToken: userSession?.getAccessToken().getJwtToken(),\n idToken: userSession?.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession?.getRefreshToken().getToken(),\n deviceKey: userSession?.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n\n private handleError(error: any, from: string): CognitoAuthSession {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res: CognitoAuthSession = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EACL,oBAAoB,GAIrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,OAAO,aAAc,SAAQ,SAAS;IAG1C,KAAK,CAAC,IAAI,CAAC,OAA4C;QACrD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,OAAO,CAAC,SAAS,mBAAM,OAAO,CAAC,aAAa,EAAG,CAAC;IAClD,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,OAGZ;QACC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACpC;QACD,IAAI;YACF,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC9C,IAAI,OAAO,CAAC,MAAM,KAAK,8BAA8B,CAAC,EAAE,EAAE;gBACxD,OAAO,OAAO,C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AAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAEhD,MAAM,GAAG,GAAuB;YAC9B,WAAW,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,GAAG,WAAW,EAAE;YACxD,OAAO,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,UAAU,GAAG,WAAW,EAAE;YAChD,UAAU,EAAE,UAAU;YACtB,YAAY,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,GAAG,QAAQ,EAAE;YACvD,SAAS,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,GAAG,aAAa,GAAG,UAAU;YACnE,MAAM,EAAE,WAAW;gBACjB,CAAC,CAAC,8BAA8B,CAAC,EAAE;gBACnC,CAAC,CAAC,8BAA8B,CAAC,EAAE;SACtC,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC;IAEO,WAAW,CAAC,KAAU,EAAE,IAAY;QAC1C,OAAO,CAAC,KAAK,CAAC,wCAAwC,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC;QACvE,MAAM,GAAG,GAAuB;YAC9B,MAAM,EAAE,8BAA8B,CAAC,EAAE;SAC1C,CAAC;QACF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,GAAG,CAAC;SACZ;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;YACvC,GAAG,CAAC,MAAM,GAAG,8BAA8B,CAAC,SAAS,CAAC;SACvD;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF","sourcesContent":["import type { FederatedSignInOptions } from '@aws-amplify/auth/lib/types';\nimport { WebPlugin } from '@capacitor/core';\nimport type { CognitoUser } from 'amazon-cognito-identity-js';\nimport { Amplify, Auth } from 'aws-amplify';\n\nimport {\n AuthUserAttributeKey,\n AwsAmplifyPlugin,\n AWSCognitoConfig,\n CognitoAuthSession,\n} from './definitions';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\n\nexport class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {\n private cognitoConfig?: AWSCognitoConfig;\n\n async load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void> {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure({ ...options.cognitoConfig });\n }\n async signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n\n const user = (await Auth.signIn(\n options.email,\n options.password,\n )) as CognitoUser;\n\n return this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n } catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n\n async federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n\n await Auth.federatedSignIn(options as FederatedSignInOptions);\n return this.fetchAuthSession();\n } catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\n }\n\n async fetchAuthSession(): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession: CognitoAuthSession = this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n\n return cognitoAuthSession;\n } catch (error) {\n return this.handleError(error, 'fetchAuthSession');\n }\n }\n\n async getUserAttributes(): Promise<{\n status: AwsAmplifyPluginResponseStatus;\n userAttributes: Record<string, string>;\n }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes:\n attributes?.reduce(\n (acc, data) => ({ ...acc, [data.Name.replace('custom:', '')]: data.Value }),\n {},\n ) || {},\n });\n return;\n });\n });\n } catch (error) {\n return {\n ...this.handleError(error, 'getUserAttributes'),\n userAttributes: {},\n };\n }\n }\n\n async updateUserAttributes(options: {\n attributes: { name: AuthUserAttributeKey | string; value: string }[];\n }): Promise<{\n status: AwsAmplifyPluginResponseStatus;\n userAttributes: Record<string, string>;\n }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = await Auth.currentAuthenticatedUser();\n await new Promise<{\n status: AwsAmplifyPluginResponseStatus;\n }>((resolve, reject) => {\n user.updateAttributes(\n options.attributes.map(({ name, value }) => ({\n Name: Object.values(AuthUserAttributeKey).includes(\n name as AuthUserAttributeKey,\n )\n ? name\n : `custom:${name}`,\n Value: value,\n })),\n error => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n });\n return;\n },\n );\n });\n return this.getUserAttributes();\n } catch (error) {\n return {\n ...this.handleError(error, 'updateUserAttributes'),\n userAttributes: {},\n };\n }\n }\n\n async signOut(): Promise<{ status: AwsAmplifyPluginResponseStatus }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(error => this.handleError(error, 'signOut'));\n }\n\n private getCognitoAuthSession(user: CognitoUser, identityId: string) {\n const userSession = user.getSignInUserSession();\n\n const res: CognitoAuthSession = {\n accessToken: userSession?.getAccessToken().getJwtToken(),\n idToken: userSession?.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession?.getRefreshToken().getToken(),\n deviceKey: userSession?.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n\n private handleError(error: any, from: string): CognitoAuthSession {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res: CognitoAuthSession = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Cancelled\"] = -2] = \"Cancelled\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"SignedOut\"] = -3] = \"SignedOut\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\nexport var AuthUserAttributeKey;\n(function (AuthUserAttributeKey) {\n /// Attribute key for user's address\n AuthUserAttributeKey[\"address\"] = \"address\";\n /// Attribute key for user's birthdate\n AuthUserAttributeKey[\"birthDate\"] = \"birthDate\";\n /// Attribute key for user's email\n AuthUserAttributeKey[\"email\"] = \"email\";\n /// Attribute key for user's family name\n AuthUserAttributeKey[\"familyName\"] = \"familyName\";\n /// Attribute key for user's gender\n AuthUserAttributeKey[\"gender\"] = \"gender\";\n /// Attribute key for user's given name\n AuthUserAttributeKey[\"givenName\"] = \"givenName\";\n /// Attribute key for user's locale\n AuthUserAttributeKey[\"locale\"] = \"locale\";\n /// Attribute key for user's middle name\n AuthUserAttributeKey[\"middleName\"] = \"middleName\";\n /// Attribute key for user's name\n AuthUserAttributeKey[\"name\"] = \"name\";\n /// Attribute key for user's nickname\n AuthUserAttributeKey[\"nickname\"] = \"nickname\";\n /// Attribute key for user's phone number\n AuthUserAttributeKey[\"phoneNumber\"] = \"phoneNumber\";\n /// Attribute key for user's picture\n AuthUserAttributeKey[\"picture\"] = \"picture\";\n /// Attribute key for user's preferred user name\n AuthUserAttributeKey[\"preferredUsername\"] = \"preferredUsername\";\n})(AuthUserAttributeKey || (AuthUserAttributeKey = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AuthUserAttributeKey, } from './definitions';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n async federatedSignIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n catch (error) {\n return this.handleError(error, 'fetchAuthSession');\n }\n }\n async getUserAttributes() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes: (attributes === null || attributes === void 0 ? void 0 : attributes.reduce((acc, data) => (Object.assign(Object.assign({}, acc), { [data.Name.replace('custom:', '')]: data.Value })), {})) || {},\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });\n }\n }\n async updateUserAttributes(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n await new Promise((resolve, reject) => {\n user.updateAttributes(options.attributes.map(({ name, value }) => ({\n Name: Object.values(AuthUserAttributeKey).includes(name)\n ? name\n : `custom:${name}`,\n Value: value,\n })), error => {\n // console.log('FROM updateUserAttributes', metadata);\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n });\n return;\n });\n });\n return this.getUserAttributes();\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'updateUserAttributes')), { userAttributes: {} });\n }\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(error => this.handleError(error, 'signOut'));\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n handleError(error, from) {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","AuthUserAttributeKey","registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AAAWA,gDAA+B;AAC1C,CAAC,UAAU,8BAA8B,EAAE;AAC3C,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;AACpF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AACrF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CA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E;AAC5H,YAAY,SAAS,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;AACxI,YAAY,MAAM,EAAE,WAAW;AAC/B,kBAAkBA,sCAA8B,CAAC,EAAE;AACnD,kBAAkBA,sCAA8B,CAAC,EAAE;AACnD,SAAS,CAAC;AACV,QAAQ,OAAO,GAAG,CAAC;AACnB,KAAK;AACL,IAAI,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE;AAC7B,QAAQ,OAAO,CAAC,KAAK,CAAC,CAAC,qCAAqC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/E,QAAQ,MAAM,GAAG,GAAG;AACpB,YAAY,MAAM,EAAEA,sCAA8B,CAAC,EAAE;AACrD,SAAS,CAAC;AACV,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AACvC,YAAY,OAAO,GAAG,CAAC;AACvB,SAAS;AACT,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;AACjD,YAAY,GAAG,CAAC,MAAM,GAAGA,sCAA8B,CAAC,SAAS,CAAC;AAClE,SAAS;AACT,QAAQ,OAAO,GAAG,CAAC;AACnB,KAAK;AACL;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Cancelled\"] = -2] = \"Cancelled\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"SignedOut\"] = -3] = \"SignedOut\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\nexport var AuthUserAttributeKey;\n(function (AuthUserAttributeKey) {\n /// Attribute key for user's address\n AuthUserAttributeKey[\"address\"] = \"address\";\n /// Attribute key for user's birthdate\n AuthUserAttributeKey[\"birthDate\"] = \"birthDate\";\n /// Attribute key for user's email\n AuthUserAttributeKey[\"email\"] = \"email\";\n /// Attribute key for user's family name\n AuthUserAttributeKey[\"familyName\"] = \"familyName\";\n /// Attribute key for user's gender\n AuthUserAttributeKey[\"gender\"] = \"gender\";\n /// Attribute key for user's given name\n AuthUserAttributeKey[\"givenName\"] = \"givenName\";\n /// Attribute key for user's locale\n AuthUserAttributeKey[\"locale\"] = \"locale\";\n /// Attribute key for user's middle name\n AuthUserAttributeKey[\"middleName\"] = \"middleName\";\n /// Attribute key for user's name\n AuthUserAttributeKey[\"name\"] = \"name\";\n /// Attribute key for user's nickname\n AuthUserAttributeKey[\"nickname\"] = \"nickname\";\n /// Attribute key for user's phone number\n AuthUserAttributeKey[\"phoneNumber\"] = \"phoneNumber\";\n /// Attribute key for user's picture\n AuthUserAttributeKey[\"picture\"] = \"picture\";\n /// Attribute key for user's preferred user name\n AuthUserAttributeKey[\"preferredUsername\"] = \"preferredUsername\";\n})(AuthUserAttributeKey || (AuthUserAttributeKey = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AuthUserAttributeKey, } from './definitions';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n async federatedSignIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n catch (error) {\n return this.handleError(error, 'fetchAuthSession');\n }\n }\n async getUserAttributes() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes: (attributes === null || attributes === void 0 ? void 0 : attributes.reduce((acc, data) => (Object.assign(Object.assign({}, acc), { [data.Name.replace('custom:', '')]: data.Value })), {})) || {},\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });\n }\n }\n async updateUserAttributes(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n await new Promise((resolve, reject) => {\n user.updateAttributes(options.attributes.map(({ name, value }) => ({\n Name: Object.values(AuthUserAttributeKey).includes(name)\n ? name\n : `custom:${name}`,\n Value: value,\n })), error => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n });\n return;\n });\n });\n return this.getUserAttributes();\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'updateUserAttributes')), { userAttributes: {} });\n }\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(error => this.handleError(error, 'signOut'));\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n handleError(error, from) {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","AuthUserAttributeKey","registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AAAWA,gDAA+B;AAC1C,CAAC,UAAU,8BAA8B,EAAE;AAC3C,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;AACpF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AACrF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;AACnG,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;AACnG,CAAC,EAAEA,sCAA8B,KAAKA,sCAA8B,GAAG,EAAE,CAAC,CAAC,CAAC;AACjEC,iDAAgC;AAC3C,CAAC,UAAU,+BAA+B,EAAE;AAC5C,IAAI,+BAA+B,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AAC3D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AACzD,IAAI,+BAA+B,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;AAC7D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAAC;AAClE,IAAI,+BAA+B,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC;AACjE,CAAC,EAAEA,uCAA+B,KAAKA,uCAA+B,GAAG,EAAE,CAAC,CAAC,CAAC;AACnEC,sCAAqB;AAChC,CAAC,UAAU,oBAAoB,EAAE;AACjC;AACA,IAAI,oBAAoB,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AAChD;AACA,IAAI,oBAAoB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,YAAY,GAAG,CAAC,MAAM,GAAGA,sCAA8B,CAAC,SAAS,CAAC;AAClE,SAAS;AACT,QAAQ,OAAO,GAAG,CAAC;AACnB,KAAK;AACL;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Cancelled\"] = -2] = \"Cancelled\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"SignedOut\"] = -3] = \"SignedOut\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\nexport var AuthUserAttributeKey;\n(function (AuthUserAttributeKey) {\n /// Attribute key for user's address\n AuthUserAttributeKey[\"address\"] = \"address\";\n /// Attribute key for user's birthdate\n AuthUserAttributeKey[\"birthDate\"] = \"birthDate\";\n /// Attribute key for user's email\n AuthUserAttributeKey[\"email\"] = \"email\";\n /// Attribute key for user's family name\n AuthUserAttributeKey[\"familyName\"] = \"familyName\";\n /// Attribute key for user's gender\n AuthUserAttributeKey[\"gender\"] = \"gender\";\n /// Attribute key for user's given name\n AuthUserAttributeKey[\"givenName\"] = \"givenName\";\n /// Attribute key for user's locale\n AuthUserAttributeKey[\"locale\"] = \"locale\";\n /// Attribute key for user's middle name\n AuthUserAttributeKey[\"middleName\"] = \"middleName\";\n /// Attribute key for user's name\n AuthUserAttributeKey[\"name\"] = \"name\";\n /// Attribute key for user's nickname\n AuthUserAttributeKey[\"nickname\"] = \"nickname\";\n /// Attribute key for user's phone number\n AuthUserAttributeKey[\"phoneNumber\"] = \"phoneNumber\";\n /// Attribute key for user's picture\n AuthUserAttributeKey[\"picture\"] = \"picture\";\n /// Attribute key for user's preferred user name\n AuthUserAttributeKey[\"preferredUsername\"] = \"preferredUsername\";\n})(AuthUserAttributeKey || (AuthUserAttributeKey = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AuthUserAttributeKey, } from './definitions';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n async federatedSignIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n catch (error) {\n return this.handleError(error, 'fetchAuthSession');\n }\n }\n async getUserAttributes() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes: (attributes === null || attributes === void 0 ? void 0 : attributes.reduce((acc, data) => (Object.assign(Object.assign({}, acc), { [data.Name.replace('custom:', '')]: data.Value })), {})) || {},\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });\n }\n }\n async updateUserAttributes(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n await new Promise((resolve, reject) => {\n user.updateAttributes(options.attributes.map(({ name, value }) => ({\n Name: Object.values(AuthUserAttributeKey).includes(name)\n ? name\n : `custom:${name}`,\n Value: value,\n })), error => {\n // console.log('FROM updateUserAttributes', metadata);\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n });\n return;\n });\n });\n return this.getUserAttributes();\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'updateUserAttributes')), { userAttributes: {} });\n }\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(error => this.handleError(error, 'signOut'));\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n handleError(error, from) {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","AuthUserAttributeKey","registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;AAAWA,oDAA+B;IAC1C,CAAC,UAAU,8BAA8B,EAAE;IAC3C,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IACpF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACrF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IACnG,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IACnG,CAAC,EAAEA,sCAA8B,KAAKA,sC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EAAE,CAAC,UAAU;IACxI,YAAY,MAAM,EAAE,WAAW;IAC/B,kBAAkBA,sCAA8B,CAAC,EAAE;IACnD,kBAAkBA,sCAA8B,CAAC,EAAE;IACnD,SAAS,CAAC;IACV,QAAQ,OAAO,GAAG,CAAC;IACnB,KAAK;IACL,IAAI,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE;IAC7B,QAAQ,OAAO,CAAC,KAAK,CAAC,CAAC,qCAAqC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/E,QAAQ,MAAM,GAAG,GAAG;IACpB,YAAY,MAAM,EAAEA,sCAA8B,CAAC,EAAE;IACrD,SAAS,CAAC;IACV,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;IACvC,YAAY,OAAO,GAAG,CAAC;IACvB,SAAS;IACT,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;IACjD,YAAY,GAAG,CAAC,MAAM,GAAGA,sCAA8B,CAAC,SAAS,CAAC;IAClE,SAAS;IACT,QAAQ,OAAO,GAAG,CAAC;IACnB,KAAK;IACL;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Cancelled\"] = -2] = \"Cancelled\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"SignedOut\"] = -3] = \"SignedOut\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\nexport var AuthUserAttributeKey;\n(function (AuthUserAttributeKey) {\n /// Attribute key for user's address\n AuthUserAttributeKey[\"address\"] = \"address\";\n /// Attribute key for user's birthdate\n AuthUserAttributeKey[\"birthDate\"] = \"birthDate\";\n /// Attribute key for user's email\n AuthUserAttributeKey[\"email\"] = \"email\";\n /// Attribute key for user's family name\n AuthUserAttributeKey[\"familyName\"] = \"familyName\";\n /// Attribute key for user's gender\n AuthUserAttributeKey[\"gender\"] = \"gender\";\n /// Attribute key for user's given name\n AuthUserAttributeKey[\"givenName\"] = \"givenName\";\n /// Attribute key for user's locale\n AuthUserAttributeKey[\"locale\"] = \"locale\";\n /// Attribute key for user's middle name\n AuthUserAttributeKey[\"middleName\"] = \"middleName\";\n /// Attribute key for user's name\n AuthUserAttributeKey[\"name\"] = \"name\";\n /// Attribute key for user's nickname\n AuthUserAttributeKey[\"nickname\"] = \"nickname\";\n /// Attribute key for user's phone number\n AuthUserAttributeKey[\"phoneNumber\"] = \"phoneNumber\";\n /// Attribute key for user's picture\n AuthUserAttributeKey[\"picture\"] = \"picture\";\n /// Attribute key for user's preferred user name\n AuthUserAttributeKey[\"preferredUsername\"] = \"preferredUsername\";\n})(AuthUserAttributeKey || (AuthUserAttributeKey = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AuthUserAttributeKey, } from './definitions';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n async federatedSignIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n catch (error) {\n return this.handleError(error, 'fetchAuthSession');\n }\n }\n async getUserAttributes() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes: (attributes === null || attributes === void 0 ? void 0 : attributes.reduce((acc, data) => (Object.assign(Object.assign({}, acc), { [data.Name.replace('custom:', '')]: data.Value })), {})) || {},\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });\n }\n }\n async updateUserAttributes(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n await new Promise((resolve, reject) => {\n user.updateAttributes(options.attributes.map(({ name, value }) => ({\n Name: Object.values(AuthUserAttributeKey).includes(name)\n ? name\n : `custom:${name}`,\n Value: value,\n })), error => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n });\n return;\n });\n });\n return this.getUserAttributes();\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'updateUserAttributes')), { userAttributes: {} });\n }\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(error => this.handleError(error, 'signOut'));\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n handleError(error, from) {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","AuthUser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;"}
|
|
@@ -196,7 +196,7 @@ import AWSMobileClient
|
|
|
196
196
|
var userAttributes: JSObject = [:]
|
|
197
197
|
|
|
198
198
|
attributes.forEach { attribute in
|
|
199
|
-
userAttributes[attribute.key.rawValue] = attribute.value
|
|
199
|
+
userAttributes[attribute.key.rawValue.replacingOccurrences(of: "custom:", with: "")] = attribute.value
|
|
200
200
|
}
|
|
201
201
|
ret["userAttributes"] = userAttributes
|
|
202
202
|
ret["status"] = 0
|
|
@@ -234,7 +234,7 @@ import AWSMobileClient
|
|
|
234
234
|
ret["status"] = 0
|
|
235
235
|
|
|
236
236
|
print("\(self.TAG) - update user attributes successfully")
|
|
237
|
-
onSuccess
|
|
237
|
+
self.getUserAttributes(onSuccess: onSuccess, onError: onError)
|
|
238
238
|
} catch {
|
|
239
239
|
ret["status"] = -1
|
|
240
240
|
if let authError = error as? AuthError
|