amazon-cognito-identity-js
Advanced tools
Comparing version 6.3.2-v5-auth-internals.3500229.17 to 6.3.2-v5-auth-internals.9bf4dba.21
@@ -206,3 +206,3 @@ import CognitoUser from '../src/CognitoUser'; | ||
expect(spyon).toHaveBeenCalledWith(authDetails, callback); | ||
expect(spyon).toHaveBeenCalledWith(authDetails, callback, undefined); | ||
}); | ||
@@ -216,3 +216,3 @@ | ||
expect(spyon).toHaveBeenCalledWith(authDetails, callback); | ||
expect(spyon).toHaveBeenCalledWith(authDetails, callback, undefined); | ||
@@ -222,3 +222,3 @@ user.setAuthenticationFlowType('CUSTOM_AUTH'); | ||
expect(spyon).toHaveBeenCalledWith(authDetails, callback); | ||
expect(spyon).toHaveBeenCalledWith(authDetails, callback, undefined); | ||
}); | ||
@@ -316,3 +316,4 @@ | ||
userSpy3.mock.calls[0][1], | ||
callback | ||
callback, | ||
undefined | ||
); | ||
@@ -762,3 +763,4 @@ expect(userSpy3.mock.results[0].value).toBe('test return value'); | ||
expect.any(AuthenticationHelper), | ||
callback | ||
callback, | ||
undefined | ||
); | ||
@@ -1184,3 +1186,3 @@ }); | ||
test('happy path should callback onSuccess', () => { | ||
test('confirmPassword happy path should callback onSuccess', () => { | ||
netRequestMockSuccess(true); | ||
@@ -1191,3 +1193,3 @@ cognitoUser.confirmPassword(...confirmPasswordDefaults); | ||
test('client request throws an error', () => { | ||
test('confirmPassword client request throws an error', () => { | ||
netRequestMockSuccess(false); | ||
@@ -1198,3 +1200,3 @@ cognitoUser.confirmPassword(...confirmPasswordDefaults); | ||
test('happy path should callback onSuccess', () => { | ||
test('forgotPassword happy path should callback onSuccess', () => { | ||
callback.inputVerificationCode = null; | ||
@@ -1206,3 +1208,3 @@ netRequestMockSuccess(true); | ||
test('inputVerification code is a function should callback inputVerificationCode', () => { | ||
test('forgotPassword inputVerification code is a function should callback inputVerificationCode', () => { | ||
callback.inputVerificationCode = jest.fn(); | ||
@@ -1214,3 +1216,3 @@ netRequestMockSuccess(true); | ||
test('client returning an error should call onFailure', () => { | ||
test('forgotPassword client returning an error should call onFailure', () => { | ||
netRequestMockSuccess(false); | ||
@@ -1217,0 +1219,0 @@ cognitoUser.forgotPassword(...forgotPasswordDefaults); |
@@ -9,2 +9,4 @@ import * as exported from '../src/internals/index'; | ||
"addFrameworkToCognitoUserAgent", | ||
"InternalCognitoUser", | ||
"InternalCognitoUserPool", | ||
] | ||
@@ -11,0 +13,0 @@ `); |
@@ -47,3 +47,3 @@ function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } | ||
var _proto = Client.prototype; | ||
_proto.promisifyRequest = function promisifyRequest(operation, params) { | ||
_proto.promisifyRequest = function promisifyRequest(operation, params, userAgentValue) { | ||
var _this2 = this; | ||
@@ -57,6 +57,6 @@ return new Promise(function (resolve, reject) { | ||
} | ||
}); | ||
}, userAgentValue); | ||
}); | ||
}; | ||
_proto.requestWithRetry = function requestWithRetry(operation, params, callback) { | ||
_proto.requestWithRetry = function requestWithRetry(operation, params, callback, userAgentValue) { | ||
var _this3 = this; | ||
@@ -72,3 +72,3 @@ var MAX_DELAY_IN_MILLIS = 5 * 1000; | ||
} | ||
}); | ||
}, userAgentValue); | ||
}); | ||
@@ -90,7 +90,7 @@ }, [params], MAX_DELAY_IN_MILLIS).then(function (result) { | ||
*/; | ||
_proto.request = function request(operation, params, callback) { | ||
_proto.request = function request(operation, params, callback, userAgentValue) { | ||
var headers = { | ||
'Content-Type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': "AWSCognitoIdentityProviderService." + operation, | ||
'X-Amz-User-Agent': getAmplifyUserAgent(), | ||
'X-Amz-User-Agent': userAgentValue || getAmplifyUserAgent(), | ||
'Cache-Control': 'no-store' | ||
@@ -97,0 +97,0 @@ }; |
@@ -0,1 +1,3 @@ | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
/*! | ||
@@ -6,75 +8,14 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
import Client from './Client'; | ||
import CognitoUser from './CognitoUser'; | ||
import StorageHelper from './StorageHelper'; | ||
import { InternalCognitoUserPool } from './internals'; | ||
var USER_POOL_ID_MAX_LENGTH = 55; | ||
/** @class */ | ||
var CognitoUserPool = /*#__PURE__*/function () { | ||
/** | ||
* 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. | ||
*/ | ||
function CognitoUserPool(data, wrapRefreshSessionCallback) { | ||
var _ref = data || {}, | ||
UserPoolId = _ref.UserPoolId, | ||
ClientId = _ref.ClientId, | ||
endpoint = _ref.endpoint, | ||
fetchOptions = _ref.fetchOptions, | ||
AdvancedSecurityDataCollectionFlag = _ref.AdvancedSecurityDataCollectionFlag; | ||
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.'); | ||
} | ||
var 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; | ||
} | ||
var CognitoUserPool = /*#__PURE__*/function (_InternalCognitoUserP) { | ||
_inheritsLoose(CognitoUserPool, _InternalCognitoUserP); | ||
function CognitoUserPool() { | ||
return _InternalCognitoUserP.apply(this, arguments) || this; | ||
} | ||
/** | ||
* @returns {string} the user pool id | ||
*/ | ||
var _proto = CognitoUserPool.prototype; | ||
_proto.getUserPoolId = function getUserPoolId() { | ||
return this.userPoolId; | ||
} | ||
/** | ||
* @returns {string} the user pool name | ||
*/; | ||
_proto.getUserPoolName = function getUserPoolName() { | ||
return this.getUserPoolId().split('_')[1]; | ||
} | ||
/** | ||
* @returns {string} the client id | ||
*/; | ||
_proto.getClientId = function getClientId() { | ||
return this.clientId; | ||
} | ||
/** | ||
* @typedef {object} SignUpResult | ||
@@ -94,83 +35,8 @@ * @property {CognitoUser} user New user. | ||
* @returns {void} | ||
*/; | ||
*/ | ||
_proto.signUp = function signUp(username, password, userAttributes, validationData, callback, clientMetadata) { | ||
var _this = this; | ||
var 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, function (err, data) { | ||
if (err) { | ||
return callback(err, null); | ||
} | ||
var cognitoUser = { | ||
Username: username, | ||
Pool: _this, | ||
Storage: _this.storage | ||
}; | ||
var 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 | ||
*/; | ||
_proto.getCurrentUser = function getCurrentUser() { | ||
var lastUserKey = "CognitoIdentityServiceProvider." + this.clientId + ".LastAuthUser"; | ||
var lastAuthUser = this.storage.getItem(lastUserKey); | ||
if (lastAuthUser) { | ||
var 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 | ||
**/; | ||
_proto.getUserContextData = function getUserContextData(username) { | ||
if (typeof AmazonCognitoAdvancedSecurityData === 'undefined') { | ||
return undefined; | ||
} | ||
/* eslint-disable */ | ||
var amazonCognitoAdvancedSecurityDataConst = AmazonCognitoAdvancedSecurityData; | ||
/* eslint-enable */ | ||
if (this.advancedSecurityDataCollectionFlag) { | ||
var advancedSecurityData = amazonCognitoAdvancedSecurityDataConst.getData(username, this.userPoolId, this.clientId); | ||
if (advancedSecurityData) { | ||
var userContextData = { | ||
EncodedData: advancedSecurityData | ||
}; | ||
return userContextData; | ||
} | ||
} | ||
return {}; | ||
return _InternalCognitoUserP.prototype.signUp.call(this, username, password, userAttributes, validationData, callback, clientMetadata); | ||
}; | ||
return CognitoUserPool; | ||
}(); | ||
}(InternalCognitoUserPool); | ||
export { CognitoUserPool as default }; |
@@ -1,1 +0,3 @@ | ||
export { addAuthCategoryToCognitoUserAgent, addFrameworkToCognitoUserAgent } from '../UserAgent'; | ||
export { addAuthCategoryToCognitoUserAgent, addFrameworkToCognitoUserAgent } from '../UserAgent'; | ||
export { InternalCognitoUser } from './InternalCognitoUser'; | ||
export { InternalCognitoUserPool } from './InternalCognitoUserPool'; |
@@ -0,1 +1,2 @@ | ||
import { InternalCognitoUser, InternalCognitoUserPool } from './internals'; | ||
declare module 'amazon-cognito-identity-js' { | ||
@@ -92,15 +93,3 @@ //import * as AWS from "aws-sdk"; | ||
export class CognitoUser { | ||
constructor(data: ICognitoUserData); | ||
challengeName?: ChallengeName; | ||
public setSignInUserSession(signInUserSession: CognitoUserSession): void; | ||
public getSignInUserSession(): CognitoUserSession | null; | ||
public getUsername(): string; | ||
public getAuthenticationFlowType(): string; | ||
public setAuthenticationFlowType(authenticationFlowType: string): string; | ||
public getCachedDeviceKeyAndPassword(): void; | ||
export class CognitoUser extends InternalCognitoUser { | ||
public getSession( | ||
@@ -335,14 +324,3 @@ callback: | ||
export class CognitoUserPool { | ||
constructor( | ||
data: ICognitoUserPoolData, | ||
wrapRefreshSessionCallback?: ( | ||
target: NodeCallback.Any | ||
) => NodeCallback.Any | ||
); | ||
public getUserPoolId(): string; | ||
public getUserPoolName(): string; | ||
public getClientId(): string; | ||
export class CognitoUserPool extends InternalCognitoUserPool { | ||
public signUp( | ||
@@ -356,4 +334,2 @@ username: string, | ||
): void; | ||
public getCurrentUser(): CognitoUser | null; | ||
} | ||
@@ -360,0 +336,0 @@ |
@@ -0,2 +1,294 @@ | ||
import { | ||
NodeCallback, | ||
UpdateAttributesNodeCallback, | ||
ClientMetadata, | ||
IAuthenticationCallback, | ||
IMfaSettings, | ||
AuthenticationDetails, | ||
ICognitoUserData, | ||
GetSessionOptions, | ||
ChallengeName, | ||
CognitoUserSession, | ||
CognitoRefreshToken, | ||
CognitoUserAttribute, | ||
ICognitoUserAttributeData, | ||
MFAOption, | ||
UserData, | ||
CognitoUser, | ||
ICognitoUserPoolData, | ||
ISignUpResult, | ||
} from 'amazon-cognito-identity-js'; | ||
export const addAuthCategoryToCognitoUserAgent: () => void; | ||
export const addFrameworkToCognitoUserAgent: (content: string) => void; | ||
export class InternalCognitoUser { | ||
constructor(data: ICognitoUserData); | ||
challengeName?: ChallengeName; | ||
public setSignInUserSession(signInUserSession: CognitoUserSession): void; | ||
public getSignInUserSession(): CognitoUserSession | null; | ||
public getUsername(): string; | ||
public getAuthenticationFlowType(): string; | ||
public setAuthenticationFlowType(authenticationFlowType: string): string; | ||
public getCachedDeviceKeyAndPassword(): void; | ||
public getSession( | ||
callback: | ||
| ((error: Error, session: null) => void) | ||
| ((error: null, session: CognitoUserSession) => void), | ||
options?: GetSessionOptions, | ||
userAgentValue?: string | ||
): void; | ||
public refreshSession( | ||
refreshToken: CognitoRefreshToken, | ||
callback: NodeCallback<any, any>, | ||
clientMetadata?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public authenticateUser( | ||
authenticationDetails: AuthenticationDetails, | ||
callbacks: IAuthenticationCallback, | ||
userAgentValue?: string | ||
): void; | ||
public initiateAuth( | ||
authenticationDetails: AuthenticationDetails, | ||
callbacks: IAuthenticationCallback, | ||
userAgentValue?: string | ||
): void; | ||
public confirmRegistration( | ||
code: string, | ||
forceAliasCreation: boolean, | ||
callback: NodeCallback<any, any>, | ||
clientMetadata?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public sendCustomChallengeAnswer( | ||
answerChallenge: any, | ||
callback: IAuthenticationCallback, | ||
clientMetaData?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public resendConfirmationCode( | ||
callback: NodeCallback<Error, any>, | ||
clientMetaData?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public changePassword( | ||
oldPassword: string, | ||
newPassword: string, | ||
callback: NodeCallback<Error, 'SUCCESS'>, | ||
clientMetadata?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public forgotPassword( | ||
callbacks: { | ||
onSuccess: (data: any) => void; | ||
onFailure: (err: Error) => void; | ||
inputVerificationCode?: (data: any) => void; | ||
}, | ||
clientMetaData?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public confirmPassword( | ||
verificationCode: string, | ||
newPassword: string, | ||
callbacks: { | ||
onSuccess: (success: string) => void; | ||
onFailure: (err: Error) => void; | ||
}, | ||
clientMetaData?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public setDeviceStatusRemembered( | ||
callbacks: { | ||
onSuccess: (success: string) => void; | ||
onFailure: (err: any) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
public setDeviceStatusNotRemembered( | ||
callbacks: { | ||
onSuccess: (success: string) => void; | ||
onFailure: (err: any) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
public getDevice( | ||
callbacks: { | ||
onSuccess: (success: string) => void; | ||
onFailure: (err: Error) => void; | ||
}, | ||
userAgentValue?: string | ||
): any; | ||
public forgetDevice( | ||
callbacks: { | ||
onSuccess: (success: string) => void; | ||
onFailure: (err: Error) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
public forgetSpecificDevice( | ||
deviceKey: string, | ||
callbacks: { | ||
onSuccess: (success: string) => void; | ||
onFailure: (err: Error) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
public sendMFACode( | ||
confirmationCode: string, | ||
callbacks: { | ||
onSuccess: ( | ||
session: CognitoUserSession, | ||
userConfirmationNecessary?: boolean | ||
) => void; | ||
onFailure: (err: any) => void; | ||
}, | ||
mfaType?: string, | ||
clientMetadata?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public listDevices( | ||
limit: number, | ||
paginationToken: string | null, | ||
callbacks: { | ||
onSuccess: (data: any) => void; | ||
onFailure: (err: Error) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
public completeNewPasswordChallenge( | ||
newPassword: string, | ||
requiredAttributeData: any, | ||
callbacks: IAuthenticationCallback, | ||
clientMetadata?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public signOut(callback?: () => void, userAgentValue?: string): void; | ||
public globalSignOut( | ||
callbacks: { | ||
onSuccess: (msg: string) => void; | ||
onFailure: (err: Error) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
public verifyAttribute( | ||
attributeName: string, | ||
confirmationCode: string, | ||
callbacks: { | ||
onSuccess: (success: string) => void; | ||
onFailure: (err: Error) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
public getUserAttributes( | ||
callback: NodeCallback<Error, CognitoUserAttribute[]>, | ||
userAgentValue?: string | ||
): void; | ||
public updateAttributes( | ||
attributes: (CognitoUserAttribute | ICognitoUserAttributeData)[], | ||
callback: UpdateAttributesNodeCallback<Error, string, any>, | ||
clientMetadata?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public deleteAttributes( | ||
attributeList: string[], | ||
callback: NodeCallback<Error, string>, | ||
userAgentValue?: string | ||
): void; | ||
public getAttributeVerificationCode( | ||
name: string, | ||
callback: { | ||
onSuccess: (success: string) => void; | ||
onFailure: (err: Error) => void; | ||
inputVerificationCode?: (data: string) => void | null; | ||
}, | ||
clientMetadata?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public deleteUser( | ||
callback: NodeCallback<Error, string>, | ||
userAgentValue?: string | ||
): void; | ||
public enableMFA( | ||
callback: NodeCallback<Error, string>, | ||
userAgentValue?: string | ||
): void; | ||
public disableMFA( | ||
callback: NodeCallback<Error, string>, | ||
userAgentValue?: string | ||
): void; | ||
public getMFAOptions( | ||
callback: NodeCallback<Error, MFAOption[]>, | ||
userAgentValue?: string | ||
): void; | ||
public getUserData( | ||
callback: NodeCallback<Error, UserData>, | ||
params?: any, | ||
userAgentValue?: string | ||
): void; | ||
public associateSoftwareToken( | ||
callbacks: { | ||
associateSecretCode: (secretCode: string) => void; | ||
onFailure: (err: any) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
public verifySoftwareToken( | ||
totpCode: string, | ||
friendlyDeviceName: string, | ||
callbacks: { | ||
onSuccess: (session: CognitoUserSession) => void; | ||
onFailure: (err: Error) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
public setUserMfaPreference( | ||
smsMfaSettings: IMfaSettings | null, | ||
softwareTokenMfaSettings: IMfaSettings | null, | ||
callback: NodeCallback<Error, string>, | ||
userAgentValue?: string | ||
): void; | ||
public sendMFASelectionAnswer( | ||
answerChallenge: string, | ||
callbacks: { | ||
onSuccess: (session: CognitoUserSession) => void; | ||
onFailure: (err: any) => void; | ||
mfaRequired?: ( | ||
challengeName: ChallengeName, | ||
challengeParameters: any | ||
) => void; | ||
totpRequired?: ( | ||
challengeName: ChallengeName, | ||
challengeParameters: any | ||
) => void; | ||
}, | ||
userAgentValue?: string | ||
): void; | ||
} | ||
export class InternalCognitoUserPool { | ||
constructor( | ||
data: ICognitoUserPoolData, | ||
wrapRefreshSessionCallback?: (target: NodeCallback.Any) => NodeCallback.Any | ||
); | ||
public getUserPoolId(): string; | ||
public getUserPoolName(): string; | ||
public getClientId(): string; | ||
public signUp( | ||
username: string, | ||
password: string, | ||
userAttributes: CognitoUserAttribute[], | ||
validationData: CognitoUserAttribute[], | ||
callback: NodeCallback<Error, ISignUpResult>, | ||
clientMetadata?: ClientMetadata, | ||
userAgentValue?: string | ||
): void; | ||
public getCurrentUser(): CognitoUser | null; | ||
} |
@@ -51,3 +51,3 @@ "use strict"; | ||
var _proto = Client.prototype; | ||
_proto.promisifyRequest = function promisifyRequest(operation, params) { | ||
_proto.promisifyRequest = function promisifyRequest(operation, params, userAgentValue) { | ||
var _this2 = this; | ||
@@ -61,6 +61,6 @@ return new Promise(function (resolve, reject) { | ||
} | ||
}); | ||
}, userAgentValue); | ||
}); | ||
}; | ||
_proto.requestWithRetry = function requestWithRetry(operation, params, callback) { | ||
_proto.requestWithRetry = function requestWithRetry(operation, params, callback, userAgentValue) { | ||
var _this3 = this; | ||
@@ -76,3 +76,3 @@ var MAX_DELAY_IN_MILLIS = 5 * 1000; | ||
} | ||
}); | ||
}, userAgentValue); | ||
}); | ||
@@ -94,7 +94,7 @@ }, [params], MAX_DELAY_IN_MILLIS).then(function (result) { | ||
*/; | ||
_proto.request = function request(operation, params, callback) { | ||
_proto.request = function request(operation, params, callback, userAgentValue) { | ||
var headers = { | ||
'Content-Type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': "AWSCognitoIdentityProviderService." + operation, | ||
'X-Amz-User-Agent': (0, _UserAgent.getAmplifyUserAgent)(), | ||
'X-Amz-User-Agent': userAgentValue || (0, _UserAgent.getAmplifyUserAgent)(), | ||
'Cache-Control': 'no-store' | ||
@@ -101,0 +101,0 @@ }; |
@@ -5,81 +5,20 @@ "use strict"; | ||
exports["default"] = void 0; | ||
var _Client = _interopRequireDefault(require("./Client")); | ||
var _CognitoUser = _interopRequireDefault(require("./CognitoUser")); | ||
var _StorageHelper = _interopRequireDefault(require("./StorageHelper")); | ||
var _internals = require("./internals"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } /*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
var USER_POOL_ID_MAX_LENGTH = 55; | ||
/** @class */ | ||
var CognitoUserPool = /*#__PURE__*/function () { | ||
/** | ||
* 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. | ||
*/ | ||
function CognitoUserPool(data, wrapRefreshSessionCallback) { | ||
var _ref = data || {}, | ||
UserPoolId = _ref.UserPoolId, | ||
ClientId = _ref.ClientId, | ||
endpoint = _ref.endpoint, | ||
fetchOptions = _ref.fetchOptions, | ||
AdvancedSecurityDataCollectionFlag = _ref.AdvancedSecurityDataCollectionFlag; | ||
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.'); | ||
} | ||
var region = UserPoolId.split('_')[0]; | ||
this.userPoolId = UserPoolId; | ||
this.clientId = ClientId; | ||
this.client = new _Client["default"](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["default"]().getStorage(); | ||
if (wrapRefreshSessionCallback) { | ||
this.wrapRefreshSessionCallback = wrapRefreshSessionCallback; | ||
} | ||
var CognitoUserPool = /*#__PURE__*/function (_InternalCognitoUserP) { | ||
_inheritsLoose(CognitoUserPool, _InternalCognitoUserP); | ||
function CognitoUserPool() { | ||
return _InternalCognitoUserP.apply(this, arguments) || this; | ||
} | ||
/** | ||
* @returns {string} the user pool id | ||
*/ | ||
var _proto = CognitoUserPool.prototype; | ||
_proto.getUserPoolId = function getUserPoolId() { | ||
return this.userPoolId; | ||
} | ||
/** | ||
* @returns {string} the user pool name | ||
*/; | ||
_proto.getUserPoolName = function getUserPoolName() { | ||
return this.getUserPoolId().split('_')[1]; | ||
} | ||
/** | ||
* @returns {string} the client id | ||
*/; | ||
_proto.getClientId = function getClientId() { | ||
return this.clientId; | ||
} | ||
/** | ||
* @typedef {object} SignUpResult | ||
@@ -99,83 +38,8 @@ * @property {CognitoUser} user New user. | ||
* @returns {void} | ||
*/; | ||
*/ | ||
_proto.signUp = function signUp(username, password, userAttributes, validationData, callback, clientMetadata) { | ||
var _this = this; | ||
var 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, function (err, data) { | ||
if (err) { | ||
return callback(err, null); | ||
} | ||
var cognitoUser = { | ||
Username: username, | ||
Pool: _this, | ||
Storage: _this.storage | ||
}; | ||
var returnData = { | ||
user: new _CognitoUser["default"](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 | ||
*/; | ||
_proto.getCurrentUser = function getCurrentUser() { | ||
var lastUserKey = "CognitoIdentityServiceProvider." + this.clientId + ".LastAuthUser"; | ||
var lastAuthUser = this.storage.getItem(lastUserKey); | ||
if (lastAuthUser) { | ||
var cognitoUser = { | ||
Username: lastAuthUser, | ||
Pool: this, | ||
Storage: this.storage | ||
}; | ||
return new _CognitoUser["default"](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 | ||
**/; | ||
_proto.getUserContextData = function getUserContextData(username) { | ||
if (typeof AmazonCognitoAdvancedSecurityData === 'undefined') { | ||
return undefined; | ||
} | ||
/* eslint-disable */ | ||
var amazonCognitoAdvancedSecurityDataConst = AmazonCognitoAdvancedSecurityData; | ||
/* eslint-enable */ | ||
if (this.advancedSecurityDataCollectionFlag) { | ||
var advancedSecurityData = amazonCognitoAdvancedSecurityDataConst.getData(username, this.userPoolId, this.clientId); | ||
if (advancedSecurityData) { | ||
var userContextData = { | ||
EncodedData: advancedSecurityData | ||
}; | ||
return userContextData; | ||
} | ||
} | ||
return {}; | ||
return _InternalCognitoUserP.prototype.signUp.call(this, username, password, userAttributes, validationData, callback, clientMetadata); | ||
}; | ||
return CognitoUserPool; | ||
}(); | ||
}(_internals.InternalCognitoUserPool); | ||
exports["default"] = CognitoUserPool; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.addFrameworkToCognitoUserAgent = exports.addAuthCategoryToCognitoUserAgent = void 0; | ||
exports.addFrameworkToCognitoUserAgent = exports.addAuthCategoryToCognitoUserAgent = exports.InternalCognitoUserPool = exports.InternalCognitoUser = void 0; | ||
var _UserAgent = require("../UserAgent"); | ||
exports.addAuthCategoryToCognitoUserAgent = _UserAgent.addAuthCategoryToCognitoUserAgent; | ||
exports.addFrameworkToCognitoUserAgent = _UserAgent.addFrameworkToCognitoUserAgent; | ||
exports.addFrameworkToCognitoUserAgent = _UserAgent.addFrameworkToCognitoUserAgent; | ||
var _InternalCognitoUser = require("./InternalCognitoUser"); | ||
exports.InternalCognitoUser = _InternalCognitoUser.InternalCognitoUser; | ||
var _InternalCognitoUserPool = require("./InternalCognitoUserPool"); | ||
exports.InternalCognitoUserPool = _InternalCognitoUserPool.InternalCognitoUserPool; |
{ | ||
"name": "amazon-cognito-identity-js", | ||
"description": "Amazon Cognito Identity Provider JavaScript SDK", | ||
"version": "6.3.2-v5-auth-internals.3500229.17+3500229f2", | ||
"version": "6.3.2-v5-auth-internals.9bf4dba.21+9bf4dbab9", | ||
"author": { | ||
@@ -95,3 +95,3 @@ "name": "Amazon Web Services", | ||
}, | ||
"gitHead": "3500229f23f0adfe43d811ea425afeeb12617766" | ||
"gitHead": "9bf4dbab9d1c7eb665391b7aa62c9afbd0178922" | ||
} |
@@ -35,17 +35,22 @@ import 'isomorphic-unfetch'; | ||
*/ | ||
promisifyRequest(operation, params) { | ||
promisifyRequest(operation, params, userAgentValue) { | ||
return new Promise((resolve, reject) => { | ||
this.request(operation, params, (err, data) => { | ||
if (err) { | ||
reject( | ||
new CognitoError(err.message, err.code, err.name, err.statusCode) | ||
); | ||
} else { | ||
resolve(data); | ||
} | ||
}); | ||
this.request( | ||
operation, | ||
params, | ||
(err, data) => { | ||
if (err) { | ||
reject( | ||
new CognitoError(err.message, err.code, err.name, err.statusCode) | ||
); | ||
} else { | ||
resolve(data); | ||
} | ||
}, | ||
userAgentValue | ||
); | ||
}); | ||
} | ||
requestWithRetry(operation, params, callback) { | ||
requestWithRetry(operation, params, callback, userAgentValue) { | ||
const MAX_DELAY_IN_MILLIS = 5 * 1000; | ||
@@ -56,9 +61,14 @@ | ||
new Promise((res, rej) => { | ||
this.request(operation, p, (error, result) => { | ||
if (error) { | ||
rej(error); | ||
} else { | ||
res(result); | ||
} | ||
}); | ||
this.request( | ||
operation, | ||
p, | ||
(error, result) => { | ||
if (error) { | ||
rej(error); | ||
} else { | ||
res(result); | ||
} | ||
}, | ||
userAgentValue | ||
); | ||
}), | ||
@@ -80,7 +90,7 @@ [params], | ||
*/ | ||
request(operation, params, callback) { | ||
request(operation, params, callback, userAgentValue) { | ||
const headers = { | ||
'Content-Type': 'application/x-amz-json-1.1', | ||
'X-Amz-Target': `AWSCognitoIdentityProviderService.${operation}`, | ||
'X-Amz-User-Agent': getAmplifyUserAgent(), | ||
'X-Amz-User-Agent': userAgentValue || getAmplifyUserAgent(), | ||
'Cache-Control': 'no-store', | ||
@@ -87,0 +97,0 @@ }; |
@@ -6,5 +6,4 @@ /*! | ||
import Client from './Client'; | ||
import CognitoUser from './CognitoUser'; | ||
import StorageHelper from './StorageHelper'; | ||
import { InternalCognitoUserPool } from './internals'; | ||
@@ -14,74 +13,5 @@ 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]; | ||
export default class CognitoUserPool extends InternalCognitoUserPool { | ||
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; | ||
} | ||
/** | ||
* @typedef {object} SignUpResult | ||
@@ -110,88 +40,11 @@ * @property {CognitoUser} user New user. | ||
) { | ||
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); | ||
}); | ||
return super.signUp( | ||
username, | ||
password, | ||
userAttributes, | ||
validationData, | ||
callback, | ||
clientMetadata | ||
); | ||
} | ||
/** | ||
* 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 {}; | ||
} | ||
} |
@@ -5,1 +5,4 @@ export { | ||
} from '../UserAgent'; | ||
export { InternalCognitoUser } from './InternalCognitoUser'; | ||
export { InternalCognitoUserPool } from './InternalCognitoUserPool'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
1468477
158
26223
15