@loomcore/api 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,6 +56,7 @@ export class TestExpressApp {
56
56
  if (!this.db) {
57
57
  this.mongoServer = await MongoMemoryServer.create({
58
58
  instance: {
59
+ ip: '127.0.0.1',
59
60
  port: 0,
60
61
  },
61
62
  binary: {
@@ -1,7 +1,7 @@
1
1
  import { ObjectId } from 'mongodb';
2
2
  import moment from 'moment';
3
3
  import crypto from 'crypto';
4
- import { EmptyUserContext, UserSpec, getSystemUserContext } from '@loomcore/common/models';
4
+ import { EmptyUserContext, passwordValidator, UserSpec, getSystemUserContext } from '@loomcore/common/models';
5
5
  import { entityUtils } from '@loomcore/common/utils';
6
6
  import { BadRequestError, ServerError } from '../errors/index.js';
7
7
  import { JwtService, EmailService } from './index.js';
@@ -93,7 +93,8 @@ export class AuthService extends GenericApiService {
93
93
  return result;
94
94
  }
95
95
  async changePassword(userContext, queryObject, password) {
96
- const updates = { password: password, _lastPasswordChange: moment().utc().toDate() };
96
+ const hashedPassword = await passwordUtils.hashPassword(password);
97
+ const updates = { password: hashedPassword, _lastPasswordChange: moment().utc().toDate() };
97
98
  const updatedUsers = await super.update(userContext, queryObject, updates);
98
99
  const result = {
99
100
  acknowledged: true,
@@ -180,6 +181,8 @@ export class AuthService extends GenericApiService {
180
181
  if (retrievedPasswordResetToken.token !== passwordResetToken || retrievedPasswordResetToken.expiresOn < Date.now()) {
181
182
  throw new BadRequestError('Invalid password reset token');
182
183
  }
184
+ const validationErrors = entityUtils.validate(passwordValidator, { password: password });
185
+ entityUtils.handleValidationResult(validationErrors, 'AuthService.resetPassword');
183
186
  const result = await this.changePassword(EmptyUserContext, { email: lowerCaseEmail }, password);
184
187
  console.log(`password changed using forgot-password for email: ${lowerCaseEmail}`);
185
188
  await this.passwordResetTokenService.deleteById(EmptyUserContext, retrievedPasswordResetToken._id.toString());
@@ -1,5 +1,6 @@
1
+ import * as Mailjet from 'node-mailjet';
1
2
  export declare class EmailService {
2
3
  private mailjet;
3
4
  constructor();
4
- sendHtmlEmail(emailAddress: string, subject: string, body: string): Promise<any>;
5
+ sendHtmlEmail(emailAddress: string, subject: string, body: string): Promise<Mailjet.LibraryResponse<import("node-mailjet/declarations/request/Request.js").RequestData>>;
5
6
  }
@@ -1,10 +1,13 @@
1
- import { Client } from 'node-mailjet';
1
+ import * as Mailjet from 'node-mailjet';
2
2
  import { ServerError } from '../errors/index.js';
3
3
  import { config } from '../config/index.js';
4
4
  export class EmailService {
5
5
  mailjet;
6
6
  constructor() {
7
- this.mailjet = Client.apiConnect(config.email.emailApiKey || '', config.email.emailApiSecret || '');
7
+ this.mailjet = new Mailjet.default({
8
+ apiKey: config.email.emailApiKey || '',
9
+ apiSecret: config.email.emailApiSecret || ''
10
+ });
8
11
  }
9
12
  async sendHtmlEmail(emailAddress, subject, body) {
10
13
  const messageData = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb",
6
6
  "scripts": {