@accounts/client
Advanced tools
Comparing version 0.0.21 to 0.1.0-alpha.42868044
import { Map } from 'immutable'; | ||
import { CreateUserType, PasswordLoginUserType, LoginReturnType, UserObjectType, TokensType, PasswordType, ImpersonateReturnType } from '@accounts/common'; | ||
import { CreateUserType, LoginUserIdentityType, LoginReturnType, 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>; | ||
} | ||
@@ -48,3 +44,3 @@ declare const Accounts: { | ||
createUser(user: CreateUserType, callback?: (err?: Error) => void): Promise<void>; | ||
loginWithPassword(user: PasswordLoginUserType, password: string, callback?: (err?: Error, res?: LoginReturnType) => void): Promise<void>; | ||
loginWithPassword(user: LoginUserIdentityType, password: string, callback?: (err?: Error, res?: LoginReturnType) => void): Promise<void>; | ||
loggingIn(): boolean; | ||
@@ -57,4 +53,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>; | ||
@@ -61,0 +55,0 @@ impersonate(username: string): Promise<any>; |
@@ -52,3 +52,2 @@ "use strict"; | ||
var module_1 = require("./module"); | ||
var encryption_1 = require("./encryption"); | ||
var isValidUserObject = function (user) { | ||
@@ -385,7 +384,7 @@ return lodash_1.has(user, 'username') || lodash_1.has(user, 'email') || lodash_1.has(user, 'id'); | ||
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); |
"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,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.0.21", | ||
"version": "0.1.0-alpha.42868044", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -62,3 +62,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@accounts/common": "^0.0.21", | ||
"@accounts/common": "^0.1.0-alpha.42868044", | ||
"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
85495
29
1705
+ Added@accounts/common@0.1.0-beta.14(transitive)
- Removed@accounts/common@0.0.21(transitive)