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

@accounts/client

Package Overview
Dependencies
Maintainers
5
Versions
201
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@accounts/client - npm Package Compare versions

Comparing version 0.1.0-alpha.4b98ebbe to 0.1.0-alpha.55f51f1c

tmp_tests_/accounts-client.ts

22

lib/accounts-client.d.ts
import { Map } from 'immutable';
import { CreateUserType, PasswordLoginUserType, LoginReturnType, UserObjectType, TokensType, PasswordType, ImpersonateReturnType } from '@accounts/common';
import { CreateUserType, UserObjectType, TokensType, ImpersonateReturnType } from '@accounts/common';
import { AccountsClientConfiguration } from './config';

@@ -30,3 +30,2 @@ import { TransportInterface } from './transport-interface';

createUser(user: CreateUserType, callback?: (err?: Error) => void): Promise<void>;
loginWithPassword(user: PasswordLoginUserType, password: PasswordType, callback?: (err?: Error, res?: LoginReturnType) => void): Promise<LoginReturnType>;
loggingIn(): boolean;

@@ -36,5 +35,2 @@ isLoading(): boolean;

verifyEmail(token: string): Promise<void>;
resetPassword(token: string, newPassword: string): Promise<void>;
requestPasswordReset(email: string): Promise<void>;
requestVerificationEmail(email: string): Promise<void>;
}

@@ -44,16 +40,14 @@ declare const Accounts: {

ui: {};
config(options: AccountsClientConfiguration, transport: TransportInterface): Promise<AccountsClient>;
user(): UserObjectType;
options(): AccountsClientConfiguration;
createUser(user: CreateUserType, callback?: (err?: Error) => void): Promise<void>;
loginWithPassword(user: PasswordLoginUserType, password: string, callback?: (err?: Error, res?: LoginReturnType) => void): Promise<void>;
config(options: any, transport: TransportInterface): Promise<AccountsClient>;
user(): any;
options(): any;
createUser(user: any, callback?: (err?: Error) => void): Promise<void>;
loginWithPassword(user: any, password: string, callback?: (err?: Error, res?: any) => void): Promise<void>;
loggingIn(): boolean;
isLoading(): boolean;
logout(callback: (err?: Error) => void): Promise<void>;
tokens(): TokensType;
tokens(): any;
resumeSession(): Promise<void>;
refreshSession(): Promise<void>;
verifyEmail(token: string): Promise<void>;
resetPassword(token: string, newPassword: string): Promise<void>;
requestPasswordReset(email?: string): Promise<void>;
requestVerificationEmail(email?: string): Promise<void>;

@@ -63,4 +57,4 @@ impersonate(username: string): Promise<any>;

isImpersonated(): boolean;
originalTokens(): TokensType;
originalTokens(): any;
};
export default Accounts;

@@ -52,5 +52,4 @@ "use strict";

var module_1 = require("./module");
var encryption_1 = require("./encryption");
var isValidUserObject = function (user) {
return lodash_1.has(user, 'user') || lodash_1.has(user, 'email') || lodash_1.has(user, 'id');
return lodash_1.has(user, 'username') || lodash_1.has(user, 'email') || lodash_1.has(user, 'id');
};

@@ -385,7 +384,7 @@ var ACCESS_TOKEN = 'accounts:accessToken';

return __awaiter(this, void 0, void 0, function () {
var hashAlgorithm, password, userToCreate, userId, onUserCreated, err_3, err_4;
var hashAlgorithm, userToCreate, userId, onUserCreated, err_3, err_4;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!user || user.password === undefined) {
if (!user) {
throw new common_1.AccountsError('Unrecognized options for create user request', {

@@ -396,7 +395,2 @@ username: user && user.username,

}
if (!user.password ||
(lodash_1.isString(user.password) &&
!common_1.validators.validatePassword(user.password))) {
throw new common_1.AccountsError('Password is required');
}
if (!common_1.validators.validateUsername(user.username) &&

@@ -407,9 +401,6 @@ !common_1.validators.validateEmail(user.email)) {

hashAlgorithm = this.options.passwordHashAlgorithm;
password = user.password && hashAlgorithm
? encryption_1.hashPassword(user.password, hashAlgorithm)
: user.password;
userToCreate = __assign({}, user, { password: password });
userToCreate = __assign({}, user);
_a.label = 1;
case 1:
_a.trys.push([1, 8, , 9]);
_a.trys.push([1, 7, , 8]);
return [4, this.transport.createUser(userToCreate)];

@@ -434,7 +425,4 @@ case 2:

return [3, 6];
case 6: return [4, this.loginWithPassword({ id: userId }, user.password)];
case 6: return [3, 8];
case 7:
_a.sent();
return [3, 9];
case 8:
err_4 = _a.sent();

@@ -445,3 +433,3 @@ if (callback && lodash_1.isFunction(callback)) {

throw new common_1.AccountsError(err_4.message);
case 9: return [2];
case 8: return [2];
}

@@ -451,53 +439,2 @@ });

};
AccountsClient.prototype.loginWithPassword = function (user, password, callback) {
return __awaiter(this, void 0, void 0, function () {
var hashAlgorithm, pass, res, err_5;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!password || !user) {
throw new common_1.AccountsError('Unrecognized options for login request', user, 400);
}
if ((!lodash_1.isString(user) &&
!isValidUserObject(user)) ||
!lodash_1.isString(password)) {
throw new common_1.AccountsError('Match failed', user, 400);
}
this.store.dispatch(module_1.loggingIn(true));
_a.label = 1;
case 1:
_a.trys.push([1, 4, , 5]);
hashAlgorithm = this.options.passwordHashAlgorithm;
pass = hashAlgorithm
? encryption_1.hashPassword(password, hashAlgorithm)
: password;
return [4, this.transport.loginWithPassword(user, pass)];
case 2:
res = _a.sent();
this.store.dispatch(module_1.loggingIn(false));
return [4, this.storeTokens(res.tokens)];
case 3:
_a.sent();
this.store.dispatch(module_1.setTokens(res.tokens));
this.store.dispatch(module_1.setUser(res.user));
if (this.options.onSignedInHook &&
lodash_1.isFunction(this.options.onSignedInHook)) {
this.options.onSignedInHook();
}
if (callback && lodash_1.isFunction(callback)) {
callback(null, res);
}
return [2, res];
case 4:
err_5 = _a.sent();
this.store.dispatch(module_1.loggingIn(false));
if (callback && lodash_1.isFunction(callback)) {
callback(err_5, null);
}
throw new common_1.AccountsError(err_5.message);
case 5: return [2];
}
});
});
};
AccountsClient.prototype.loggingIn = function () {

@@ -511,3 +448,3 @@ return this.getState().get('loggingIn');

return __awaiter(this, void 0, void 0, function () {
var accessToken, err_6;
var accessToken, err_5;
return __generator(this, function (_a) {

@@ -536,9 +473,9 @@ switch (_a.label) {

case 4:
err_6 = _a.sent();
err_5 = _a.sent();
this.clearTokens();
this.store.dispatch(module_1.clearUser());
if (callback && lodash_1.isFunction(callback)) {
callback(err_6);
callback(err_5);
}
throw new common_1.AccountsError(err_6.message);
throw new common_1.AccountsError(err_5.message);
case 5: return [2];

@@ -551,3 +488,3 @@ }

return __awaiter(this, void 0, void 0, function () {
var err_7;
var err_6;
return __generator(this, function (_a) {

@@ -562,4 +499,4 @@ switch (_a.label) {

case 2:
err_7 = _a.sent();
throw new common_1.AccountsError(err_7.message);
err_6 = _a.sent();
throw new common_1.AccountsError(err_6.message);
case 3: return [2];

@@ -570,78 +507,2 @@ }

};
AccountsClient.prototype.resetPassword = function (token, newPassword) {
return __awaiter(this, void 0, void 0, function () {
var hashAlgorithm, password, err_8;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!common_1.validators.validatePassword(newPassword)) {
throw new common_1.AccountsError('Password is invalid!');
}
hashAlgorithm = this.options.passwordHashAlgorithm;
password = hashAlgorithm
? encryption_1.hashPassword(newPassword, hashAlgorithm)
: newPassword;
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4, this.transport.resetPassword(token, password)];
case 2:
_a.sent();
return [3, 4];
case 3:
err_8 = _a.sent();
throw new common_1.AccountsError(err_8.message);
case 4: return [2];
}
});
});
};
AccountsClient.prototype.requestPasswordReset = function (email) {
return __awaiter(this, void 0, void 0, function () {
var err_9;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!common_1.validators.validateEmail(email)) {
throw new common_1.AccountsError('Valid email must be provided');
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4, this.transport.sendResetPasswordEmail(email)];
case 2:
_a.sent();
return [3, 4];
case 3:
err_9 = _a.sent();
throw new common_1.AccountsError(err_9.message);
case 4: return [2];
}
});
});
};
AccountsClient.prototype.requestVerificationEmail = function (email) {
return __awaiter(this, void 0, void 0, function () {
var err_10;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!common_1.validators.validateEmail(email)) {
throw new common_1.AccountsError('Valid email must be provided');
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
return [4, this.transport.sendVerificationEmail(email)];
case 2:
_a.sent();
return [3, 4];
case 3:
err_10 = _a.sent();
throw new common_1.AccountsError(err_10.message);
case 4: return [2];
}
});
});
};
return AccountsClient;

@@ -703,8 +564,2 @@ }());

},
resetPassword: function (token, newPassword) {
return this.instance.resetPassword(token, newPassword);
},
requestPasswordReset: function (email) {
return this.instance.requestPasswordReset(email);
},
requestVerificationEmail: function (email) {

@@ -711,0 +566,0 @@ return this.instance.requestVerificationEmail(email);

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

import { AccountsCommonConfiguration, HookListener, PasswordSignupFields } from '@accounts/common';
import { AccountsCommonConfiguration, HookListener } from '@accounts/common';
import { Store, Middleware } from 'redux';

@@ -38,45 +38,3 @@ export interface TokenStorage {

};
declare const _default: {
store: any;
reduxLogger: any;
reduxStoreKey: string;
tokenStorage: {
getItem(key: string): Promise<string>;
removeItem(key: string): Promise<string>;
setItem(key: string, value: string): Promise<string>;
};
server: string;
tokenStoragePrefix: string;
title: string;
requestPermissions: any[];
requestOfflineToken: {};
forceApprovalPrompt: {};
requireEmailVerification: boolean;
loginPath: string;
signUpPath: any;
resetPasswordPath: any;
profilePath: string;
changePasswordPath: any;
homePath: string;
signOutPath: string;
onEnrollAccountHook: () => number;
onResetPasswordHook: () => number;
onVerifyEmailHook: () => number;
onSignedInHook: () => number;
onSignedOutHook: () => number;
loginOnSignUp: boolean;
persistImpersonation: boolean;
siteUrl?: string;
sendVerificationEmail?: boolean;
sendEnrollmentEmail?: boolean;
sendWelcomeEmail?: boolean;
forbidClientAccountCreation?: boolean;
restrictCreationByEmailDomain?: string;
passwordResetTokenExpirationInDays?: number;
passwordEnrollTokenExpirationInDays?: number;
passwordSignupFields?: PasswordSignupFields;
minimumPasswordLength?: number;
path?: string;
passwordHashAlgorithm?: "sha" | "sha1" | "sha224" | "sha256" | "sha384" | "sha512" | "md5" | "ripemd160";
};
declare const _default: any;
export default _default;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var isString = require("lodash/isString");
var CryptoJS = require("crypto-js");
var mapHashConstant = {

@@ -15,13 +13,2 @@ sha: 'SHA',

};
exports.hashPassword = function (password, algorithm) {
if (isString(password)) {
var cryptoAlgoKey = mapHashConstant[algorithm];
var cryptoFunction = CryptoJS[cryptoAlgoKey];
return {
digest: cryptoFunction(password).toString(),
algorithm: algorithm,
};
}
return password;
};
//# sourceMappingURL=encryption.js.map

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

declare const _default: (path: string) => number;
declare const _default: (path: string) => any;
export default _default;

@@ -1,9 +0,7 @@

import { CreateUserType, PasswordLoginUserType, LoginReturnType, PasswordType, ImpersonateReturnType } from '@accounts/common';
import { CreateUserType, LoginReturnType, ImpersonateReturnType } from '@accounts/common';
export interface TransportInterface {
createUser(user: CreateUserType): Promise<string>;
loginWithPassword(user: PasswordLoginUserType, password: PasswordType): Promise<LoginReturnType>;
logout(accessToken: string): Promise<void>;
refreshTokens(accessToken: string, refreshToken: string): Promise<LoginReturnType>;
verifyEmail(token: string): Promise<void>;
resetPassword(token: string, newPassword: PasswordType): Promise<void>;
sendResetPasswordEmail(email: string): Promise<void>;

@@ -10,0 +8,0 @@ sendVerificationEmail(email: string): Promise<void>;

{
"name": "@accounts/client",
"version": "0.1.0-alpha.4b98ebbe",
"version": "0.1.0-alpha.55f51f1c",
"description": "Fullstack authentication and accounts-management",

@@ -62,3 +62,3 @@ "main": "lib/index.js",

"dependencies": {
"@accounts/common": "^0.1.0-alpha.4b98ebbe",
"@accounts/common": "^0.0.18",
"crypto-js": "^3.1.9-1",

@@ -65,0 +65,0 @@ "immutable": "^3.8.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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