Socket
Socket
Sign inDemoInstall

amazon-cognito-identity-js

Package Overview
Dependencies
Maintainers
13
Versions
1619
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amazon-cognito-identity-js - npm Package Compare versions

Comparing version 6.3.4 to 6.3.5-unstable.bdaee91.0

__tests__/internalsIndex.test.js

22

__tests__/CognitoUser.test.js

@@ -206,3 +206,3 @@ import CognitoUser from '../src/CognitoUser';

expect(spyon).toHaveBeenCalledWith(authDetails, callback, undefined);
expect(spyon).toHaveBeenCalledWith(authDetails, callback);
});

@@ -216,3 +216,3 @@

expect(spyon).toHaveBeenCalledWith(authDetails, callback, undefined);
expect(spyon).toHaveBeenCalledWith(authDetails, callback);

@@ -222,3 +222,3 @@ user.setAuthenticationFlowType('CUSTOM_AUTH');

expect(spyon).toHaveBeenCalledWith(authDetails, callback, undefined);
expect(spyon).toHaveBeenCalledWith(authDetails, callback);
});

@@ -316,4 +316,3 @@

userSpy3.mock.calls[0][1],
callback,
undefined
callback
);

@@ -763,4 +762,3 @@ expect(userSpy3.mock.results[0].value).toBe('test return value');

expect.any(AuthenticationHelper),
callback,
undefined
callback
);

@@ -1186,3 +1184,3 @@ });

test('confirmPassword happy path should callback onSuccess', () => {
test('happy path should callback onSuccess', () => {
netRequestMockSuccess(true);

@@ -1193,3 +1191,3 @@ cognitoUser.confirmPassword(...confirmPasswordDefaults);

test('confirmPassword client request throws an error', () => {
test('client request throws an error', () => {
netRequestMockSuccess(false);

@@ -1200,3 +1198,3 @@ cognitoUser.confirmPassword(...confirmPasswordDefaults);

test('forgotPassword happy path should callback onSuccess', () => {
test('happy path should callback onSuccess', () => {
callback.inputVerificationCode = null;

@@ -1208,3 +1206,3 @@ netRequestMockSuccess(true);

test('forgotPassword inputVerification code is a function should callback inputVerificationCode', () => {
test('inputVerification code is a function should callback inputVerificationCode', () => {
callback.inputVerificationCode = jest.fn();

@@ -1216,3 +1214,3 @@ netRequestMockSuccess(true);

test('forgotPassword client returning an error should call onFailure', () => {
test('client returning an error should call onFailure', () => {
netRequestMockSuccess(false);

@@ -1219,0 +1217,0 @@ cognitoUser.forgotPassword(...forgotPasswordDefaults);

@@ -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, userAgentValue) {
_proto.promisifyRequest = function promisifyRequest(operation, params) {
var _this2 = this;

@@ -57,6 +57,6 @@ return new Promise(function (resolve, reject) {

}
}, userAgentValue);
});
});
};
_proto.requestWithRetry = function requestWithRetry(operation, params, callback, userAgentValue) {
_proto.requestWithRetry = function requestWithRetry(operation, params, callback) {
var _this3 = this;

@@ -72,3 +72,3 @@ var MAX_DELAY_IN_MILLIS = 5 * 1000;

}
}, userAgentValue);
});
});

@@ -88,10 +88,9 @@ }, [params], MAX_DELAY_IN_MILLIS).then(function (result) {

* @param {function} callback Callback called when a response is returned
* @param {string} userAgentValue Optional string containing custom user agent value
* @returns {void}
*/;
_proto.request = function request(operation, params, callback, userAgentValue) {
_proto.request = function request(operation, params, callback) {
var headers = {
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': "AWSCognitoIdentityProviderService." + operation,
'X-Amz-User-Agent': userAgentValue || getAmplifyUserAgent(),
'X-Amz-User-Agent': getAmplifyUserAgent(),
'Cache-Control': 'no-store'

@@ -98,0 +97,0 @@ };

@@ -1,3 +0,1 @@

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); }
/*!

@@ -8,14 +6,75 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

import Client from './Client';
import CognitoUser from './CognitoUser';
import { InternalCognitoUserPool } from './internals';
import StorageHelper from './StorageHelper';
var USER_POOL_ID_MAX_LENGTH = 55;
/** @class */
var CognitoUserPool = /*#__PURE__*/function (_InternalCognitoUserP) {
_inheritsLoose(CognitoUserPool, _InternalCognitoUserP);
function CognitoUserPool() {
return _InternalCognitoUserP.apply(this, arguments) || this;
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;
}
}
/**
* @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

@@ -35,8 +94,83 @@ * @property {CognitoUser} user New user.

* @returns {void}
*/
*/;
_proto.signUp = function signUp(username, password, userAttributes, validationData, callback, clientMetadata) {
return _InternalCognitoUserP.prototype.signUp.call(this, 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 CognitoUserPool;
}(InternalCognitoUserPool);
}();
export { CognitoUserPool as default };

@@ -1,3 +0,1 @@

export { addAuthCategoryToCognitoUserAgent, addFrameworkToCognitoUserAgent } from '../UserAgent';
export { InternalCognitoUser } from './InternalCognitoUser';
export { InternalCognitoUserPool } from './InternalCognitoUserPool';
export { addAuthCategoryToCognitoUserAgent, addFrameworkToCognitoUserAgent } from '../UserAgent';

@@ -1,2 +0,1 @@

import { InternalCognitoUser, InternalCognitoUserPool } from './internals';
declare module 'amazon-cognito-identity-js' {

@@ -93,3 +92,15 @@ //import * as AWS from "aws-sdk";

export class CognitoUser extends InternalCognitoUser {
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;
public getSession(

@@ -324,3 +335,14 @@ callback:

export class CognitoUserPool extends InternalCognitoUserPool {
export class CognitoUserPool {
constructor(
data: ICognitoUserPoolData,
wrapRefreshSessionCallback?: (
target: NodeCallback.Any
) => NodeCallback.Any
);
public getUserPoolId(): string;
public getUserPoolName(): string;
public getClientId(): string;
public signUp(

@@ -334,2 +356,4 @@ username: string,

): void;
public getCurrentUser(): CognitoUser | null;
}

@@ -336,0 +360,0 @@

@@ -1,295 +0,2 @@

import {
AuthenticationDetails,
ChallengeName,
ClientMetadata,
CognitoRefreshToken,
CognitoUser,
CognitoUserAttribute,
CognitoUserSession,
GetSessionOptions,
IAuthenticationCallback,
ICognitoUserAttributeData,
ICognitoUserData,
ICognitoUserPoolData,
IMfaSettings,
ISignUpResult,
MFAOption,
NodeCallback,
UpdateAttributesNodeCallback,
UserData,
} 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>,
clientMetaData?: ClientMetadata,
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, userAgentValue) {
_proto.promisifyRequest = function promisifyRequest(operation, params) {
var _this2 = this;

@@ -61,6 +61,6 @@ return new Promise(function (resolve, reject) {

}
}, userAgentValue);
});
});
};
_proto.requestWithRetry = function requestWithRetry(operation, params, callback, userAgentValue) {
_proto.requestWithRetry = function requestWithRetry(operation, params, callback) {
var _this3 = this;

@@ -76,3 +76,3 @@ var MAX_DELAY_IN_MILLIS = 5 * 1000;

}
}, userAgentValue);
});
});

@@ -92,10 +92,9 @@ }, [params], MAX_DELAY_IN_MILLIS).then(function (result) {

* @param {function} callback Callback called when a response is returned
* @param {string} userAgentValue Optional string containing custom user agent value
* @returns {void}
*/;
_proto.request = function request(operation, params, callback, userAgentValue) {
_proto.request = function request(operation, params, callback) {
var headers = {
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': "AWSCognitoIdentityProviderService." + operation,
'X-Amz-User-Agent': userAgentValue || (0, _UserAgent.getAmplifyUserAgent)(),
'X-Amz-User-Agent': (0, _UserAgent.getAmplifyUserAgent)(),
'Cache-Control': 'no-store'

@@ -102,0 +101,0 @@ };

@@ -5,20 +5,81 @@ "use strict";

exports["default"] = void 0;
var _Client = _interopRequireDefault(require("./Client"));
var _CognitoUser = _interopRequireDefault(require("./CognitoUser"));
var _internals = require("./internals");
var _StorageHelper = _interopRequireDefault(require("./StorageHelper"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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
*/
/*!
* 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 (_InternalCognitoUserP) {
_inheritsLoose(CognitoUserPool, _InternalCognitoUserP);
function CognitoUserPool() {
return _InternalCognitoUserP.apply(this, arguments) || this;
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;
}
}
/**
* @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

@@ -38,8 +99,83 @@ * @property {CognitoUser} user New user.

* @returns {void}
*/
*/;
_proto.signUp = function signUp(username, password, userAttributes, validationData, callback, clientMetadata) {
return _InternalCognitoUserP.prototype.signUp.call(this, 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 CognitoUserPool;
}(_internals.InternalCognitoUserPool);
}();
exports["default"] = CognitoUserPool;
"use strict";
exports.__esModule = true;
exports.addFrameworkToCognitoUserAgent = exports.addAuthCategoryToCognitoUserAgent = exports.InternalCognitoUserPool = exports.InternalCognitoUser = void 0;
exports.addFrameworkToCognitoUserAgent = exports.addAuthCategoryToCognitoUserAgent = void 0;
var _UserAgent = require("../UserAgent");
exports.addAuthCategoryToCognitoUserAgent = _UserAgent.addAuthCategoryToCognitoUserAgent;
exports.addFrameworkToCognitoUserAgent = _UserAgent.addFrameworkToCognitoUserAgent;
var _InternalCognitoUser = require("./InternalCognitoUser");
exports.InternalCognitoUser = _InternalCognitoUser.InternalCognitoUser;
var _InternalCognitoUserPool = require("./InternalCognitoUserPool");
exports.InternalCognitoUserPool = _InternalCognitoUserPool.InternalCognitoUserPool;
exports.addFrameworkToCognitoUserAgent = _UserAgent.addFrameworkToCognitoUserAgent;
{
"name": "amazon-cognito-identity-js",
"description": "Amazon Cognito Identity Provider JavaScript SDK",
"version": "6.3.4",
"version": "6.3.5-unstable.bdaee91.0+bdaee91",
"author": {

@@ -77,3 +77,3 @@ "name": "Amazon Web Services",

},
"gitHead": "d33fbd59e6998045be17e03b77c3fb8992906a07"
"gitHead": "bdaee9114e2d8c8507b1e74e418d628b01a01a9f"
}

@@ -35,22 +35,17 @@ import 'isomorphic-unfetch';

*/
promisifyRequest(operation, params, userAgentValue) {
promisifyRequest(operation, params) {
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);
}
},
userAgentValue
);
this.request(operation, params, (err, data) => {
if (err) {
reject(
new CognitoError(err.message, err.code, err.name, err.statusCode)
);
} else {
resolve(data);
}
});
});
}
requestWithRetry(operation, params, callback, userAgentValue) {
requestWithRetry(operation, params, callback) {
const MAX_DELAY_IN_MILLIS = 5 * 1000;

@@ -61,14 +56,9 @@

new Promise((res, rej) => {
this.request(
operation,
p,
(error, result) => {
if (error) {
rej(error);
} else {
res(result);
}
},
userAgentValue
);
this.request(operation, p, (error, result) => {
if (error) {
rej(error);
} else {
res(result);
}
});
}),

@@ -88,10 +78,9 @@ [params],

* @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) {
request(operation, params, callback) {
const headers = {
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': `AWSCognitoIdentityProviderService.${operation}`,
'X-Amz-User-Agent': userAgentValue || getAmplifyUserAgent(),
'X-Amz-User-Agent': getAmplifyUserAgent(),
'Cache-Control': 'no-store',

@@ -98,0 +87,0 @@ };

@@ -6,4 +6,5 @@ /*!

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

@@ -13,5 +14,74 @@ const USER_POOL_ID_MAX_LENGTH = 55;

/** @class */
export default class CognitoUserPool extends InternalCognitoUserPool {
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;
}
/**
* @typedef {object} SignUpResult

@@ -40,11 +110,88 @@ * @property {CognitoUser} user New user.

) {
return super.signUp(
username,
password,
userAttributes,
validationData,
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 {};
}
}

@@ -5,4 +5,1 @@ 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc