@aws-amplify/datastore 3.12.4-unstable.2 → 3.12.4-unstable.3

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.
@@ -60712,6 +60712,7 @@ var dispatchAuthEvent = function dispatchAuthEvent(event, data, message) {
60712
60712
 
60713
60713
 
60714
60714
  var MAX_DEVICES = 60;
60715
+ var MAX_AUTOSIGNIN_POLLING_MS = 3 * 60 * 1000;
60715
60716
  /**
60716
60717
  * Provide authentication steps
60717
60718
  */
@@ -60729,6 +60730,7 @@ function () {
60729
60730
  this.userPool = null;
60730
60731
  this.user = null;
60731
60732
  this.oAuthFlowInProgress = false;
60733
+ this.autoSignInInitiated = false;
60732
60734
  this.Credentials = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Credentials"];
60733
60735
 
60734
60736
  this.wrapRefreshSessionCallback = function (callback) {
@@ -60874,6 +60876,19 @@ function () {
60874
60876
  }
60875
60877
 
60876
60878
  dispatchAuthEvent('configured', null, "The Auth category has been configured successfully");
60879
+
60880
+ if (!this.autoSignInInitiated && typeof this._storage['getItem'] === 'function') {
60881
+ var pollingInitiated = this.isTrueStorageValue('amplify-polling-started');
60882
+
60883
+ if (pollingInitiated) {
60884
+ dispatchAuthEvent('autoSignIn_failure', null, _types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].AutoSignInError);
60885
+
60886
+ this._storage.removeItem('amplify-auto-sign-in');
60887
+ }
60888
+
60889
+ this._storage.removeItem('amplify-polling-started');
60890
+ }
60891
+
60877
60892
  return this._config;
60878
60893
  };
60879
60894
  /**
@@ -60893,6 +60908,8 @@ function () {
60893
60908
  restOfAttrs[_i - 1] = arguments[_i];
60894
60909
  }
60895
60910
 
60911
+ var _a, _b, _c;
60912
+
60896
60913
  if (!this.userPool) {
60897
60914
  return this.rejectNoUserPool();
60898
60915
  }
@@ -60902,6 +60919,11 @@ function () {
60902
60919
  var attributes = [];
60903
60920
  var validationData = null;
60904
60921
  var clientMetadata;
60922
+ var autoSignIn = {
60923
+ enabled: false
60924
+ };
60925
+ var autoSignInValidationData = {};
60926
+ var autoSignInClientMetaData = {};
60905
60927
 
60906
60928
  if (params && typeof params === 'string') {
60907
60929
  username = params;
@@ -60948,6 +60970,17 @@ function () {
60948
60970
  }));
60949
60971
  });
60950
60972
  }
60973
+
60974
+ autoSignIn = (_a = params.autoSignIn) !== null && _a !== void 0 ? _a : {
60975
+ enabled: false
60976
+ };
60977
+
60978
+ if (autoSignIn.enabled) {
60979
+ this._storage.setItem('amplify-auto-sign-in', true);
60980
+
60981
+ autoSignInValidationData = (_b = autoSignIn.validationData) !== null && _b !== void 0 ? _b : {};
60982
+ autoSignInClientMetaData = (_c = autoSignIn.clientMetaData) !== null && _c !== void 0 ? _c : {};
60983
+ }
60951
60984
  } else {
60952
60985
  return this.rejectAuthError(_types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].SignUpError);
60953
60986
  }
@@ -60969,11 +61002,126 @@ function () {
60969
61002
  reject(err);
60970
61003
  } else {
60971
61004
  dispatchAuthEvent('signUp', data, username + " has signed up successfully");
61005
+
61006
+ if (autoSignIn.enabled) {
61007
+ _this.handleAutoSignIn(username, password, autoSignInValidationData, autoSignInClientMetaData, data);
61008
+ }
61009
+
60972
61010
  resolve(data);
60973
61011
  }
60974
61012
  }, clientMetadata);
60975
61013
  });
60976
61014
  };
61015
+
61016
+ AuthClass.prototype.handleAutoSignIn = function (username, password, validationData, clientMetadata, data) {
61017
+ this.autoSignInInitiated = true;
61018
+ var authDetails = new amazon_cognito_identity_js__WEBPACK_IMPORTED_MODULE_2__["AuthenticationDetails"]({
61019
+ Username: username,
61020
+ Password: password,
61021
+ ValidationData: validationData,
61022
+ ClientMetadata: clientMetadata
61023
+ });
61024
+
61025
+ if (data.userConfirmed) {
61026
+ this.signInAfterUserConfirmed(authDetails);
61027
+ } else if (this._config.signUpVerificationMethod === 'link') {
61028
+ this.handleLinkAutoSignIn(authDetails);
61029
+ } else {
61030
+ this.handleCodeAutoSignIn(authDetails);
61031
+ }
61032
+ };
61033
+
61034
+ AuthClass.prototype.handleCodeAutoSignIn = function (authDetails) {
61035
+ var _this = this;
61036
+
61037
+ var listenEvent = function listenEvent(_a) {
61038
+ var payload = _a.payload;
61039
+
61040
+ if (payload.event === 'confirmSignUp') {
61041
+ _this.signInAfterUserConfirmed(authDetails, listenEvent);
61042
+ }
61043
+ };
61044
+
61045
+ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Hub"].listen('auth', listenEvent);
61046
+ };
61047
+
61048
+ AuthClass.prototype.handleLinkAutoSignIn = function (authDetails) {
61049
+ var _this = this;
61050
+
61051
+ this._storage.setItem('amplify-polling-started', true);
61052
+
61053
+ var start = Date.now();
61054
+ var autoSignInPollingIntervalId = setInterval(function () {
61055
+ if (Date.now() - start > MAX_AUTOSIGNIN_POLLING_MS) {
61056
+ clearInterval(autoSignInPollingIntervalId);
61057
+ dispatchAuthEvent('autoSignIn_failure', null, 'Please confirm your account and use your credentials to sign in.');
61058
+
61059
+ _this._storage.removeItem('amplify-auto-sign-in');
61060
+ } else {
61061
+ _this.signInAfterUserConfirmed(authDetails, null, autoSignInPollingIntervalId);
61062
+ }
61063
+ }, 5000);
61064
+ };
61065
+
61066
+ AuthClass.prototype.signInAfterUserConfirmed = function (authDetails, listenEvent, autoSignInPollingIntervalId) {
61067
+ return __awaiter(this, void 0, void 0, function () {
61068
+ var user, error_1;
61069
+
61070
+ var _this = this;
61071
+
61072
+ return __generator(this, function (_a) {
61073
+ switch (_a.label) {
61074
+ case 0:
61075
+ user = this.createCognitoUser(authDetails.getUsername());
61076
+ _a.label = 1;
61077
+
61078
+ case 1:
61079
+ _a.trys.push([1, 3,, 4]);
61080
+
61081
+ return [4
61082
+ /*yield*/
61083
+ , user.authenticateUser(authDetails, this.authCallbacks(user, function (value) {
61084
+ dispatchAuthEvent('autoSignIn', value, authDetails.getUsername() + " has signed in successfully");
61085
+
61086
+ if (listenEvent) {
61087
+ _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Hub"].remove('auth', listenEvent);
61088
+ }
61089
+
61090
+ if (autoSignInPollingIntervalId) {
61091
+ clearInterval(autoSignInPollingIntervalId);
61092
+
61093
+ _this._storage.removeItem('amplify-polling-started');
61094
+ }
61095
+
61096
+ _this._storage.removeItem('amplify-auto-sign-in');
61097
+ }, function (error) {
61098
+ logger.error(error);
61099
+
61100
+ _this._storage.removeItem('amplify-auto-sign-in');
61101
+ }))];
61102
+
61103
+ case 2:
61104
+ _a.sent();
61105
+
61106
+ return [3
61107
+ /*break*/
61108
+ , 4];
61109
+
61110
+ case 3:
61111
+ error_1 = _a.sent();
61112
+ logger.error(error_1);
61113
+ return [3
61114
+ /*break*/
61115
+ , 4];
61116
+
61117
+ case 4:
61118
+ return [2
61119
+ /*return*/
61120
+ ];
61121
+ }
61122
+ });
61123
+ });
61124
+ };
60977
61125
  /**
60978
61126
  * Send the verification code to confirm sign up
60979
61127
  * @param {String} username - The username to be confirmed
@@ -60984,6 +61132,8 @@ function () {
60984
61132
 
60985
61133
 
60986
61134
  AuthClass.prototype.confirmSignUp = function (username, code, options) {
61135
+ var _this = this;
61136
+
60987
61137
  if (!this.userPool) {
60988
61138
  return this.rejectNoUserPool();
60989
61139
  }
@@ -61011,11 +61161,27 @@ function () {
61011
61161
  if (err) {
61012
61162
  reject(err);
61013
61163
  } else {
61164
+ dispatchAuthEvent('confirmSignUp', data, username + " has been confirmed successfully");
61165
+
61166
+ var autoSignIn = _this.isTrueStorageValue('amplify-auto-sign-in');
61167
+
61168
+ if (autoSignIn && !_this.autoSignInInitiated) {
61169
+ dispatchAuthEvent('autoSignIn_failure', null, _types_Auth__WEBPACK_IMPORTED_MODULE_7__["AuthErrorTypes"].AutoSignInError);
61170
+
61171
+ _this._storage.removeItem('amplify-auto-sign-in');
61172
+ }
61173
+
61014
61174
  resolve(data);
61015
61175
  }
61016
61176
  }, clientMetadata);
61017
61177
  });
61018
61178
  };
61179
+
61180
+ AuthClass.prototype.isTrueStorageValue = function (value) {
61181
+ var item = this._storage.getItem(value);
61182
+
61183
+ return item ? item === 'true' : false;
61184
+ };
61019
61185
  /**
61020
61186
  * Resend the verification code
61021
61187
  * @param {String} username - The username to be confirmed
@@ -63713,7 +63879,7 @@ function () {
63713
63879
 
63714
63880
  AuthClass.prototype.rememberDevice = function () {
63715
63881
  return __awaiter(this, void 0, void 0, function () {
63716
- var currUser, error_1;
63882
+ var currUser, error_2;
63717
63883
  return __generator(this, function (_a) {
63718
63884
  switch (_a.label) {
63719
63885
  case 0:
@@ -63730,8 +63896,8 @@ function () {
63730
63896
  , 3];
63731
63897
 
63732
63898
  case 2:
63733
- error_1 = _a.sent();
63734
- logger.debug('The user is not authenticated by the error', error_1);
63899
+ error_2 = _a.sent();
63900
+ logger.debug('The user is not authenticated by the error', error_2);
63735
63901
  return [2
63736
63902
  /*return*/
63737
63903
  , Promise.reject('The user is not authenticated')];
@@ -63763,7 +63929,7 @@ function () {
63763
63929
 
63764
63930
  AuthClass.prototype.forgetDevice = function () {
63765
63931
  return __awaiter(this, void 0, void 0, function () {
63766
- var currUser, error_2;
63932
+ var currUser, error_3;
63767
63933
  return __generator(this, function (_a) {
63768
63934
  switch (_a.label) {
63769
63935
  case 0:
@@ -63780,8 +63946,8 @@ function () {
63780
63946
  , 3];
63781
63947
 
63782
63948
  case 2:
63783
- error_2 = _a.sent();
63784
- logger.debug('The user is not authenticated by the error', error_2);
63949
+ error_3 = _a.sent();
63950
+ logger.debug('The user is not authenticated by the error', error_3);
63785
63951
  return [2
63786
63952
  /*return*/
63787
63953
  , Promise.reject('The user is not authenticated')];
@@ -63813,7 +63979,7 @@ function () {
63813
63979
 
63814
63980
  AuthClass.prototype.fetchDevices = function () {
63815
63981
  return __awaiter(this, void 0, void 0, function () {
63816
- var currUser, error_3;
63982
+ var currUser, error_4;
63817
63983
  return __generator(this, function (_a) {
63818
63984
  switch (_a.label) {
63819
63985
  case 0:
@@ -63830,8 +63996,8 @@ function () {
63830
63996
  , 3];
63831
63997
 
63832
63998
  case 2:
63833
- error_3 = _a.sent();
63834
- logger.debug('The user is not authenticated by the error', error_3);
63999
+ error_4 = _a.sent();
64000
+ logger.debug('The user is not authenticated by the error', error_4);
63835
64001
  throw new Error('The user is not authenticated');
63836
64002
 
63837
64003
  case 3:
@@ -64027,6 +64193,9 @@ var authErrorMessages = {
64027
64193
  networkError: {
64028
64194
  message: _common_AuthErrorStrings__WEBPACK_IMPORTED_MODULE_1__["AuthErrorStrings"].NETWORK_ERROR
64029
64195
  },
64196
+ autoSignInError: {
64197
+ message: _common_AuthErrorStrings__WEBPACK_IMPORTED_MODULE_1__["AuthErrorStrings"].AUTOSIGNIN_ERROR
64198
+ },
64030
64199
  "default": {
64031
64200
  message: _common_AuthErrorStrings__WEBPACK_IMPORTED_MODULE_1__["AuthErrorStrings"].DEFAULT_MSG
64032
64201
  }
@@ -64753,6 +64922,7 @@ var AuthErrorStrings;
64753
64922
  AuthErrorStrings["NO_USER_SESSION"] = "Failed to get the session because the user is empty";
64754
64923
  AuthErrorStrings["NETWORK_ERROR"] = "Network Error";
64755
64924
  AuthErrorStrings["DEVICE_CONFIG"] = "Device tracking has not been configured in this User Pool";
64925
+ AuthErrorStrings["AUTOSIGNIN_ERROR"] = "Please use your credentials to sign in";
64756
64926
  })(AuthErrorStrings || (AuthErrorStrings = {}));
64757
64927
 
64758
64928
  /***/ }),
@@ -64886,6 +65056,7 @@ var AuthErrorTypes;
64886
65056
  AuthErrorTypes["Default"] = "default";
64887
65057
  AuthErrorTypes["DeviceConfig"] = "deviceConfig";
64888
65058
  AuthErrorTypes["NetworkError"] = "networkError";
65059
+ AuthErrorTypes["AutoSignInError"] = "autoSignInError";
64889
65060
  })(AuthErrorTypes || (AuthErrorTypes = {}));
64890
65061
 
64891
65062
  function isUsernamePasswordOpts(obj) {
@@ -71111,7 +71282,8 @@ var parseMobileHubConfig = function parseMobileHubConfig(config) {
71111
71282
  region: config['aws_cognito_region'],
71112
71283
  identityPoolId: config['aws_cognito_identity_pool_id'],
71113
71284
  identityPoolRegion: config['aws_cognito_region'],
71114
- mandatorySignIn: config['aws_mandatory_sign_in'] === 'enable'
71285
+ mandatorySignIn: config['aws_mandatory_sign_in'] === 'enable',
71286
+ signUpVerificationMethod: config['aws_cognito_sign_up_verification_method'] || 'code'
71115
71287
  };
71116
71288
  } // Storage
71117
71289