@accounts/client
Advanced tools
Comparing version 0.1.0-alpha.b5d6f4ab to 0.1.0-alpha.dab12c46
import { Map } from 'immutable'; | ||
import { CreateUserType, UserObjectType, TokensType, ImpersonateReturnType } from '@accounts/common'; | ||
import { CreateUserType, PasswordLoginUserType, LoginReturnType, UserObjectType, TokensType, PasswordType, ImpersonateReturnType } from '@accounts/common'; | ||
import { AccountsClientConfiguration } from './config'; | ||
@@ -30,2 +30,3 @@ 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; | ||
@@ -35,2 +36,5 @@ isLoading(): boolean; | ||
verifyEmail(token: string): Promise<void>; | ||
resetPassword(token: string, newPassword: string): Promise<void>; | ||
requestPasswordReset(email: string): Promise<void>; | ||
requestVerificationEmail(email: string): Promise<void>; | ||
} | ||
@@ -40,14 +44,16 @@ declare const Accounts: { | ||
ui: {}; | ||
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>; | ||
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>; | ||
loggingIn(): boolean; | ||
isLoading(): boolean; | ||
logout(callback: (err?: Error) => void): Promise<void>; | ||
tokens(): any; | ||
tokens(): TokensType; | ||
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>; | ||
@@ -57,4 +63,4 @@ impersonate(username: string): Promise<any>; | ||
isImpersonated(): boolean; | ||
originalTokens(): any; | ||
originalTokens(): TokensType; | ||
}; | ||
export default Accounts; |
@@ -52,2 +52,3 @@ "use strict"; | ||
var module_1 = require("./module"); | ||
var encryption_1 = require("./encryption"); | ||
var isValidUserObject = function (user) { | ||
@@ -384,7 +385,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, userToCreate, userId, onUserCreated, err_3, err_4; | ||
var hashAlgorithm, password, userToCreate, userId, onUserCreated, err_3, err_4; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (!user) { | ||
if (!user || user.password === undefined) { | ||
throw new common_1.AccountsError('Unrecognized options for create user request', { | ||
@@ -395,2 +396,7 @@ 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) && | ||
@@ -401,6 +407,9 @@ !common_1.validators.validateEmail(user.email)) { | ||
hashAlgorithm = this.options.passwordHashAlgorithm; | ||
userToCreate = __assign({}, user); | ||
password = user.password && hashAlgorithm | ||
? encryption_1.hashPassword(user.password, hashAlgorithm) | ||
: user.password; | ||
userToCreate = __assign({}, user, { password: password }); | ||
_a.label = 1; | ||
case 1: | ||
_a.trys.push([1, 7, , 8]); | ||
_a.trys.push([1, 8, , 9]); | ||
return [4, this.transport.createUser(userToCreate)]; | ||
@@ -425,4 +434,7 @@ case 2: | ||
return [3, 6]; | ||
case 6: return [3, 8]; | ||
case 6: return [4, this.loginWithPassword({ id: userId }, user.password)]; | ||
case 7: | ||
_a.sent(); | ||
return [3, 9]; | ||
case 8: | ||
err_4 = _a.sent(); | ||
@@ -433,3 +445,3 @@ if (callback && lodash_1.isFunction(callback)) { | ||
throw new common_1.AccountsError(err_4.message); | ||
case 8: return [2]; | ||
case 9: return [2]; | ||
} | ||
@@ -439,2 +451,53 @@ }); | ||
}; | ||
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 () { | ||
@@ -448,3 +511,3 @@ return this.getState().get('loggingIn'); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var accessToken, err_5; | ||
var accessToken, err_6; | ||
return __generator(this, function (_a) { | ||
@@ -473,9 +536,9 @@ switch (_a.label) { | ||
case 4: | ||
err_5 = _a.sent(); | ||
err_6 = _a.sent(); | ||
this.clearTokens(); | ||
this.store.dispatch(module_1.clearUser()); | ||
if (callback && lodash_1.isFunction(callback)) { | ||
callback(err_5); | ||
callback(err_6); | ||
} | ||
throw new common_1.AccountsError(err_5.message); | ||
throw new common_1.AccountsError(err_6.message); | ||
case 5: return [2]; | ||
@@ -488,3 +551,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var err_6; | ||
var err_7; | ||
return __generator(this, function (_a) { | ||
@@ -499,4 +562,4 @@ switch (_a.label) { | ||
case 2: | ||
err_6 = _a.sent(); | ||
throw new common_1.AccountsError(err_6.message); | ||
err_7 = _a.sent(); | ||
throw new common_1.AccountsError(err_7.message); | ||
case 3: return [2]; | ||
@@ -507,2 +570,78 @@ } | ||
}; | ||
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; | ||
@@ -564,2 +703,8 @@ }()); | ||
}, | ||
resetPassword: function (token, newPassword) { | ||
return this.instance.resetPassword(token, newPassword); | ||
}, | ||
requestPasswordReset: function (email) { | ||
return this.instance.requestPasswordReset(email); | ||
}, | ||
requestVerificationEmail: function (email) { | ||
@@ -566,0 +711,0 @@ return this.instance.requestVerificationEmail(email); |
@@ -1,2 +0,2 @@ | ||
import { AccountsCommonConfiguration, HookListener } from '@accounts/common'; | ||
import { AccountsCommonConfiguration, HookListener, PasswordSignupFields } from '@accounts/common'; | ||
import { Store, Middleware } from 'redux'; | ||
@@ -38,3 +38,45 @@ export interface TokenStorage { | ||
}; | ||
declare const _default: any; | ||
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"; | ||
}; | ||
export default _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var isString = require("lodash/isString"); | ||
var CryptoJS = require("crypto-js"); | ||
var mapHashConstant = { | ||
@@ -13,2 +15,13 @@ 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) => any; | ||
declare const _default: (path: string) => number; | ||
export default _default; |
@@ -1,7 +0,9 @@ | ||
import { CreateUserType, LoginReturnType, ImpersonateReturnType } from '@accounts/common'; | ||
import { CreateUserType, PasswordLoginUserType, LoginReturnType, PasswordType, 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>; | ||
@@ -8,0 +10,0 @@ sendVerificationEmail(email: string): Promise<void>; |
{ | ||
"name": "@accounts/client", | ||
"version": "0.1.0-alpha.b5d6f4ab", | ||
"version": "0.1.0-alpha.dab12c46", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -62,3 +62,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@accounts/common": "^0.0.18", | ||
"@accounts/common": "^0.1.0-alpha.dab12c46", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72383
28
1151
+ Added@accounts/common@0.1.0-beta.14(transitive)
- Removed@accounts/common@0.0.18(transitive)