Skip to content

Commit

Permalink
Merge branch 'main' into fix-unstable-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinkumar6 authored Aug 8, 2023
2 parents 839a868 + c6cb690 commit dc7f50a
Show file tree
Hide file tree
Showing 21 changed files with 865 additions and 1,577 deletions.
2 changes: 2 additions & 0 deletions .github/canary-config/canary-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ tests:
sample_name: [next-13-js]
spec: nextjs-13
browser: *minimal_browser_list
timeout_minutes: 45
retry_count: 10
- test_name: integ_rollup_datastore_basic_crud
desc: 'Rollup + DataStore - Basic CRUD'
framework: rollup
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"babel-jest": "^24.9.0",
"babel-loader": "^8.3.0",
"codecov": "^3.6.5",
"compression-webpack-plugin": "^1.1.3",
"husky": "^3.0.5",
"jest": "^24.x.x",
"jest-config": "24.8.0",
Expand All @@ -101,7 +100,6 @@
"typedoc": "^0.17.0",
"typescript": "~3.8.3",
"typescript-coverage-report": "^0.6.4",
"uglifyjs-webpack-plugin": "^0.4.6",
"uuid-validate": "^0.0.3",
"webpack": "^5.75.0",
"webpack-bundle-analyzer": "^4.7.0",
Expand Down
1 change: 0 additions & 1 deletion packages/amazon-cognito-identity-js/.eslintignore

This file was deleted.

30 changes: 0 additions & 30 deletions packages/amazon-cognito-identity-js/.eslintrc.yaml

This file was deleted.

This file was deleted.

17 changes: 2 additions & 15 deletions packages/amazon-cognito-identity-js/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 34 additions & 8 deletions packages/amazon-cognito-identity-js/internals/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 3 additions & 12 deletions packages/amazon-cognito-identity-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
"build:umd": "webpack",
"build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:umd",
"generate-version": "genversion src/Platform/version.ts --es6 --semi",
"lint": "eslint src",
"lint2": "eslint enhance-rn.js",
"test": "jest --config ./jest.config.js",
"format": "echo \"Not implemented\"",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json"
Expand Down Expand Up @@ -76,18 +74,11 @@
"@react-native-async-storage/async-storage": "^1.17.12",
"babel-loader": "^8.0.6",
"cross-env": "^3.1.4",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^5.0.2",
"eslint-config-prettier": "^6.3.0",
"eslint-import-resolver-webpack": "^0.5.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-node": "^5.2.0",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
"genversion": "^2.2.0",
"react": "^16.0.0",
"rimraf": "^2.5.4",
"uglifyjs-webpack-plugin": "^1.0.0",
"webpack": "^3.5.5"
"terser-webpack-plugin": "^1.4.3",
"webpack": "^4.46.0",
"webpack-cli": "^4.10.0"
}
}
1 change: 1 addition & 0 deletions packages/amazon-cognito-identity-js/src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export default class Client {
* @param {string} operation API operation
* @param {object} params Input parameters
* @param {function} callback Callback called when a response is returned
* @param {string} userAgentValue Optional string containing custom user agent value
* @returns {void}
*/
request(operation, params, callback, userAgentValue) {
Expand Down
167 changes: 10 additions & 157 deletions packages/amazon-cognito-identity-js/src/CognitoUserPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,13 @@
* SPDX-License-Identifier: Apache-2.0
*/

import Client from './Client';
import CognitoUser from './CognitoUser';
import StorageHelper from './StorageHelper';
import { InternalCognitoUserPool } from './internals';

const USER_POOL_ID_MAX_LENGTH = 55;

/** @class */
export default class CognitoUserPool {
/**
* Constructs a new CognitoUserPool object
* @param {object} data Creation options.
* @param {string} data.UserPoolId Cognito user pool id.
* @param {string} data.ClientId User pool application client id.
* @param {string} data.endpoint Optional custom service endpoint.
* @param {object} data.fetchOptions Optional options for fetch API.
* (only credentials option is supported)
* @param {object} data.Storage Optional storage object.
* @param {boolean} data.AdvancedSecurityDataCollectionFlag Optional:
* boolean flag indicating if the data collection is enabled
* to support cognito advanced security features. By default, this
* flag is set to true.
*/
constructor(data, wrapRefreshSessionCallback) {
const {
UserPoolId,
ClientId,
endpoint,
fetchOptions,
AdvancedSecurityDataCollectionFlag,
} = data || {};
if (!UserPoolId || !ClientId) {
throw new Error('Both UserPoolId and ClientId are required.');
}
if (UserPoolId.length > USER_POOL_ID_MAX_LENGTH || !/^[\w-]+_[0-9a-zA-Z]+$/.test(UserPoolId)) {
throw new Error('Invalid UserPoolId format.');
}
const region = UserPoolId.split('_')[0];

this.userPoolId = UserPoolId;
this.clientId = ClientId;

this.client = new Client(region, endpoint, fetchOptions);

/**
* By default, AdvancedSecurityDataCollectionFlag is set to true,
* if no input value is provided.
*/
this.advancedSecurityDataCollectionFlag =
AdvancedSecurityDataCollectionFlag !== false;

this.storage = data.Storage || new StorageHelper().getStorage();

if (wrapRefreshSessionCallback) {
this.wrapRefreshSessionCallback = wrapRefreshSessionCallback;
}
}

/**
* @returns {string} the user pool id
*/
getUserPoolId() {
return this.userPoolId;
}

/**
* @returns {string} the user pool name
*/
getUserPoolName() {
return this.getUserPoolId().split('_')[1];
}

/**
* @returns {string} the client id
*/
getClientId() {
return this.clientId;
}
export default class CognitoUserPool extends InternalCognitoUserPool {

/**
* @typedef {object} SignUpResult
Expand All @@ -105,90 +35,13 @@ export default class CognitoUserPool {
callback,
clientMetadata
) {
const jsonReq = {
ClientId: this.clientId,
Username: username,
Password: password,
UserAttributes: userAttributes,
ValidationData: validationData,
ClientMetadata: clientMetadata,
};
if (this.getUserContextData(username)) {
jsonReq.UserContextData = this.getUserContextData(username);
}
this.client.request('SignUp', jsonReq, (err, data) => {
if (err) {
return callback(err, null);
}

const cognitoUser = {
Username: username,
Pool: this,
Storage: this.storage,
};

const returnData = {
user: new CognitoUser(cognitoUser),
userConfirmed: data.UserConfirmed,
userSub: data.UserSub,
codeDeliveryDetails: data.CodeDeliveryDetails,
};

return callback(null, returnData);
});
}

/**
* method for getting the current user of the application from the local storage
*
* @returns {CognitoUser} the user retrieved from storage
*/
getCurrentUser() {
const lastUserKey = `CognitoIdentityServiceProvider.${this.clientId}.LastAuthUser`;

const lastAuthUser = this.storage.getItem(lastUserKey);
if (lastAuthUser) {
const cognitoUser = {
Username: lastAuthUser,
Pool: this,
Storage: this.storage,
};

return new CognitoUser(cognitoUser);
}

return null;
}

/**
* This method returns the encoded data string used for cognito advanced security feature.
* This would be generated only when developer has included the JS used for collecting the
* data on their client. Please refer to documentation to know more about using AdvancedSecurity
* features
* @param {string} username the username for the context data
* @returns {string} the user context data
**/
getUserContextData(username) {
if (typeof AmazonCognitoAdvancedSecurityData === 'undefined') {
return undefined;
}
/* eslint-disable */
const amazonCognitoAdvancedSecurityDataConst = AmazonCognitoAdvancedSecurityData;
/* eslint-enable */

if (this.advancedSecurityDataCollectionFlag) {
const advancedSecurityData = amazonCognitoAdvancedSecurityDataConst.getData(
username,
this.userPoolId,
this.clientId
);
if (advancedSecurityData) {
const userContextData = {
EncodedData: advancedSecurityData,
};
return userContextData;
}
}
return {};
return super.signUp(
username,
password,
userAttributes,
validationData,
callback,
clientMetadata
);
}
}
Loading

0 comments on commit dc7f50a

Please sign in to comment.