Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

amazon-cognito-identity-js

Package Overview
Dependencies
Maintainers
13
Versions
1620
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.2-api-v6.35 to 6.3.2-api-v6.4d00072.0

es/internals/InternalCognitoUser.js

22

__tests__/CognitoUser.test.js

@@ -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);

@@ -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);
});

@@ -88,9 +88,10 @@ }, [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) {
_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 +98,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 {
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 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;
}
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;
}

@@ -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);
});

@@ -92,9 +92,10 @@ }, [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) {
_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 +102,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-api-v6.35+98c172c32",
"version": "6.3.2-api-v6.4d00072.0+4d00072",
"author": {

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

"scripts": {
"clean": "rimraf lib es",
"clean": "rimraf lib es dist",
"build:cjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",

@@ -47,6 +47,3 @@ "build:cjs:watch": "cross-env BABEL_ENV=commonjs babel src --out-dir lib --watch",

"build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:umd",
"doc": "jsdoc src -d docs",
"generate-version": "genversion src/Platform/version.ts --es6 --semi",
"lint": "eslint src",
"lint2": "eslint enhance-rn.js",
"test": "jest --config ./jest.config.js",

@@ -75,25 +72,10 @@ "format": "echo \"Not implemented\"",

"devDependencies": {
"@babel/cli": "7.17.0",
"@babel/core": "7.17.2",
"@babel/preset-env": "^7.7.4",
"@babel/preset-react": "^7.0.0",
"@react-native-async-storage/async-storage": "1.15.17",
"babel-loader": "^8.0.6",
"@react-native-async-storage/async-storage": "^1.17.12",
"compression-webpack-plugin": "^10.0.0",
"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",
"jsdoc": "3.4.0",
"react": "^16.0.0",
"rimraf": "^2.5.4",
"uglifyjs-webpack-plugin": "^1.0.0",
"webpack": "^3.5.5"
"rimraf": "^2.5.4"
},
"gitHead": "98c172c32bc793b99b31442ea2d84829baea6e3c"
"gitHead": "4d00072e865c55d87a425f6746b27f4963f5d19b"
}

@@ -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
);
}),

@@ -78,9 +88,10 @@ [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) {
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 +98,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';

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

// version 3.11.0
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin");

@@ -14,3 +13,3 @@ /* eslint-disable */

var config = {
module.exports = {
entry: {

@@ -20,2 +19,5 @@ 'amazon-cognito-identity': './src/index.js',

},
externals: {
crypto: 'crypto',
},
output: {

@@ -29,27 +31,38 @@ filename: '[name].js',

},
externals: {
crypto: 'crypto',
resolve: {
extensions: ['.js', '.json'],
},
mode: 'production',
plugins: [
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.BannerPlugin({ banner, raw: true }),
new UglifyJsPlugin({
sourceMap: true,
include: /\.min\.js$/,
}),
new CompressionPlugin({
include: /\.min\.js$/,
}),
})
],
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: true,
sourceMap: true,
},
include: /\.min\.js$/,
})
]
},
module: {
rules: [
// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
//{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
{
test: /\.js$/,
test: /\.js?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
cacheDirectory: './node_modules/.cache/babel',
},
use: [
'babel-loader',
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
],
},

@@ -59,3 +72,1 @@ ],

};
module.exports = config;

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