@accounts/server
Advanced tools
Comparing version 0.1.0-alpha.b5d6f4ab to 0.1.0-alpha.d1153bd0
@@ -91,5 +91,8 @@ "use strict"; | ||
for (var service in this.services) { | ||
this.services[service].db = this.db; | ||
this.services[service].setStore(this.db); | ||
this.services[service].server = this; | ||
} | ||
this.email = this.options.sendMail | ||
? { sendMail: this.options.sendMail } | ||
: new email_1.default(this.options.email); | ||
this.hooks = new events_1.EventEmitter(); | ||
@@ -161,3 +164,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var ip, userAgent, sessionId, _a, accessToken, refreshToken, loginResult; | ||
var ip, userAgent, sessionId, _a, accessToken, refreshToken, loginResult, e_1; | ||
return __generator(this, function (_b) { | ||
@@ -167,4 +170,7 @@ switch (_b.label) { | ||
ip = infos.ip, userAgent = infos.userAgent; | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
return [4, this.db.createSession(user.id, ip, userAgent)]; | ||
case 1: | ||
case 2: | ||
sessionId = _b.sent(); | ||
@@ -180,3 +186,9 @@ _a = this.createTokens(sessionId), accessToken = _a.accessToken, refreshToken = _a.refreshToken; | ||
}; | ||
this.hooks.emit(exports.ServerHooks.LoginSuccess, user); | ||
return [2, loginResult]; | ||
case 3: | ||
e_1 = _b.sent(); | ||
this.hooks.emit(exports.ServerHooks.LoginError, e_1); | ||
throw e_1; | ||
case 4: return [2]; | ||
} | ||
@@ -188,3 +200,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var session, user, impersonatedUser, isAuthorized, newSessionId, impersonationTokens, impersonationResult, e_1; | ||
var session, user, impersonatedUser, isAuthorized, newSessionId, impersonationTokens, impersonationResult, e_2; | ||
return __generator(this, function (_a) { | ||
@@ -242,5 +254,5 @@ switch (_a.label) { | ||
case 6: | ||
e_1 = _a.sent(); | ||
this.hooks.emit(exports.ServerHooks.ImpersonationError, e_1); | ||
throw e_1; | ||
e_2 = _a.sent(); | ||
this.hooks.emit(exports.ServerHooks.ImpersonationError, e_2); | ||
throw e_2; | ||
case 7: return [2]; | ||
@@ -363,3 +375,3 @@ } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var session, user, e_2, e_3; | ||
var session, user, e_3, e_4; | ||
return __generator(this, function (_a) { | ||
@@ -388,4 +400,4 @@ switch (_a.label) { | ||
case 5: | ||
e_2 = _a.sent(); | ||
throw new common_1.AccountsError(e_2, { id: session.userId }, 403); | ||
e_3 = _a.sent(); | ||
throw new common_1.AccountsError(e_3, { id: session.userId }, 403); | ||
case 6: | ||
@@ -398,5 +410,5 @@ this.hooks.emit(exports.ServerHooks.ResumeSessionSuccess, user, accessToken); | ||
case 8: | ||
e_3 = _a.sent(); | ||
this.hooks.emit(exports.ServerHooks.ResumeSessionError, e_3); | ||
throw e_3; | ||
e_4 = _a.sent(); | ||
this.hooks.emit(exports.ServerHooks.ResumeSessionError, e_4); | ||
throw e_4; | ||
case 9: return [2]; | ||
@@ -403,0 +415,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var emailjs_1 = require("emailjs"); | ||
var email = require("emailjs"); | ||
exports.emailTemplates = { | ||
@@ -28,3 +28,3 @@ from: 'js-accounts <no-reply@js-accounts.com>', | ||
if (emailConfig) { | ||
this.server = emailjs_1.default.server.connect(emailConfig); | ||
this.server = email.server.connect(emailConfig); | ||
} | ||
@@ -37,2 +37,3 @@ } | ||
console.warn('No configuration for email, you must set an email configuration'); | ||
console.log(mail); | ||
resolve(); | ||
@@ -39,0 +40,0 @@ return; |
@@ -5,3 +5,4 @@ import { AccountsServer } from './accounts-server'; | ||
import { generateRandomToken } from './tokens'; | ||
import { DBInterface } from './types'; | ||
export { AccountsServer, encryption, config, DBInterface, generateRandomToken }; | ||
import { AuthService, DBInterface } from './types'; | ||
export default AccountsServer; | ||
export { AccountsServer, AuthService, encryption, config, DBInterface, generateRandomToken }; |
@@ -11,2 +11,3 @@ "use strict"; | ||
exports.generateRandomToken = tokens_1.generateRandomToken; | ||
exports.default = accounts_server_1.AccountsServer; | ||
//# sourceMappingURL=index.js.map |
@@ -5,10 +5,14 @@ import { UserObjectType, CreateUserType, SessionType } from '@accounts/common'; | ||
export interface AuthService { | ||
db: DBInterface; | ||
server: AccountsServer; | ||
serviceName: string; | ||
authenticate(params: any): UserObjectType; | ||
setStore(store: DBInterface): void; | ||
authenticate(params: any): Promise<UserObjectType | null>; | ||
} | ||
export declare type UserObjectSanitizerFunction = (userObject: UserObjectType, omitFunction: (userDoc: object) => UserObjectType, pickFunction: (userDoc: object) => UserObjectType) => any; | ||
export declare type UserObjectSanitizerFunction = (userObject: UserObjectType, omitFunction: (userDoc: object, fields: string[]) => UserObjectType, pickFunction: (userDoc: object, fields: string[]) => UserObjectType) => any; | ||
export declare type ResumeSessionValidator = (user: UserObjectType, session: SessionType) => Promise<any>; | ||
export declare type PrepareMailFunction = (to: string, token: string, user: UserObjectType, pathFragment: string, emailTemplate: EmailTemplateType, from: string) => object; | ||
export declare type EmailType = EmailTemplateType & { | ||
to: string; | ||
}; | ||
export declare type SendMailFunction = (emailConfig: EmailType | object) => Promise<object>; | ||
export interface AccountsServerOptions { | ||
@@ -28,6 +32,8 @@ db: DBInterface; | ||
userObjectSanitizer?: UserObjectSanitizerFunction; | ||
impersonationAuthorize: (user: UserObjectType, impersonateToUser: UserObjectType) => Promise<any>; | ||
impersonationAuthorize?: (user: UserObjectType, impersonateToUser: UserObjectType) => Promise<any>; | ||
resumeSessionValidator?: ResumeSessionValidator; | ||
siteUrl?: string; | ||
prepareMail?: PrepareMailFunction; | ||
sendMail?: SendMailFunction; | ||
email?: object; | ||
} | ||
@@ -39,16 +45,16 @@ export interface ConnectionInformationsType { | ||
export interface DBInterface { | ||
findUserByEmail(email: string): Promise<UserObjectType>; | ||
findUserByUsername(username: string): Promise<UserObjectType>; | ||
findUserById(userId: string): Promise<UserObjectType>; | ||
findUserByEmail(email: string): Promise<UserObjectType | null>; | ||
findUserByUsername(username: string): Promise<UserObjectType | null>; | ||
findUserById(userId: string): Promise<UserObjectType | null>; | ||
createUser(user: CreateUserType): Promise<string>; | ||
setUsername(userId: string, newUsername: string): Promise<void>; | ||
setProfile(userId: string, profile: object): Promise<object>; | ||
findByService(serviceName: string, pickBy: object): Promise<UserObjectType>; | ||
setServiceData(serviceName: string, data: object): Promise<void>; | ||
findUserByServiceId(serviceName: string, serviceId: string): Promise<UserObjectType | null>; | ||
setService(userId: string, serviceName: string, data: object): Promise<void>; | ||
findPasswordHash(userId: string): Promise<string>; | ||
findUserByResetPasswordToken(token: string): Promise<UserObjectType>; | ||
findUserByResetPasswordToken(token: string): Promise<UserObjectType | null>; | ||
setPassword(userId: string, newPassword: string): Promise<void>; | ||
addResetPasswordToken(userId: string, email: string, token: string, reason?: string): Promise<void>; | ||
setResetPassword(userId: string, email: string, newPassword: string, token: string): Promise<void>; | ||
findUserByEmailVerificationToken(token: string): Promise<UserObjectType>; | ||
findUserByEmailVerificationToken(token: string): Promise<UserObjectType | null>; | ||
addEmail(userId: string, newEmail: string, verified: boolean): Promise<void>; | ||
@@ -55,0 +61,0 @@ removeEmail(userId: string, email: string): Promise<void>; |
{ | ||
"name": "@accounts/server", | ||
"version": "0.1.0-alpha.b5d6f4ab", | ||
"version": "0.1.0-alpha.d1153bd0", | ||
"description": "Fullstack authentication and accounts-management", | ||
@@ -15,6 +15,7 @@ "main": "lib/index.js", | ||
"compile": "tsc", | ||
"prepublish": "npm run compile", | ||
"prepublishOnly": "npm run compile", | ||
"test": "npm run testonly", | ||
"test-ci": "npm lint && npm coverage", | ||
"testonly": "jest", | ||
"test:watch": "jest --watch", | ||
"coverage": "npm run testonly -- --coverage", | ||
@@ -51,3 +52,3 @@ "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" | ||
"dependencies": { | ||
"@accounts/common": "^0.1.0-alpha.b5d6f4ab", | ||
"@accounts/common": "^0.1.0-alpha.d1153bd0", | ||
"babel-polyfill": "^6.23.0", | ||
@@ -64,4 +65,5 @@ "bcryptjs": "^2.4.0", | ||
"@types/jwt-decode": "^2.2.1", | ||
"coveralls": "^2.11.14" | ||
"coveralls": "^2.11.14", | ||
"rimraf": "^2.6.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
63217
4
25
951