@devmoods/express-extras 0.17.4 → 0.17.7

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.
package/bin/migrate ADDED
@@ -0,0 +1,5 @@
1
+ #/bin/bash
2
+
3
+ set -e
4
+
5
+ node_modules/.bin/ts-node --esm cli.cjs ${*:1}
package/dist/auth.js CHANGED
@@ -63,28 +63,27 @@ export function createAuth({ getUserByToken, methods: { emailAndPassword }, filt
63
63
  type: 'string',
64
64
  minLength: 4,
65
65
  };
66
- router.post('/reset/:token', validateParams(tokenSchema), validateBody({
67
- type: 'object',
68
- properties: {
69
- password: { type: 'string', minLength: 8 },
70
- },
71
- required: ['password'],
72
- }), route(async (req) => {
73
- const { password } = req.body;
74
- const { token } = req.params;
75
- if (!emailAndPassword) {
76
- throw new Error('Not applicable for login method');
77
- }
78
- const email = await redis.get(token);
79
- if (!email) {
80
- throw BadRequest('invalid reset token');
81
- }
82
- const user = await emailAndPassword(email, skipPasswordCheck);
83
- await onPasswordChanged?.(user, await hashPassword(password));
84
- await redis.del(token);
85
- logger.info('user changed password', { email });
86
- return 200;
87
- }));
66
+ if (emailAndPassword) {
67
+ router.post('/reset/:token', validateParams(tokenSchema), validateBody({
68
+ type: 'object',
69
+ properties: {
70
+ password: { type: 'string', minLength: 8 },
71
+ },
72
+ required: ['password'],
73
+ }), route(async (req) => {
74
+ const { password } = req.body;
75
+ const { token } = req.params;
76
+ const email = await redis.get(token);
77
+ if (!email) {
78
+ throw BadRequest('invalid reset token');
79
+ }
80
+ const user = await emailAndPassword(email, skipPasswordCheck);
81
+ await onPasswordChanged?.(user, await hashPassword(password));
82
+ await redis.del(token);
83
+ logger.info('user changed password', { email });
84
+ return 200;
85
+ }));
86
+ }
88
87
  router.get('/reset/:token', validateParams(tokenSchema), route(async (req) => {
89
88
  const token = req.params.token;
90
89
  const email = await redis.get(token);
package/dist/migrate.d.ts CHANGED
@@ -29,7 +29,7 @@ export declare class Migrator {
29
29
  log(...args: any[]): void;
30
30
  executeMigration(migrations: Migration[], currentVersion: number, direction: 'up' | 'down'): Promise<number>;
31
31
  readMigrationFile(filename: string): Promise<MigrationFileAPI>;
32
- migrate(tx: Connection, migrator: MigrationFileAPI, direction: 'up' | 'down'): Promise<void>;
32
+ migrate(connection: Connection, migrator: MigrationFileAPI, direction: 'up' | 'down'): Promise<void>;
33
33
  updateCurrentVersion(connection: Connection, version: number): Promise<import("pg").QueryResult<import("pg").QueryResultRow>>;
34
34
  getCurrentVersion(): Promise<number>;
35
35
  getMigrations(): Promise<{
package/dist/migrate.js CHANGED
@@ -161,7 +161,7 @@ export class Migrator {
161
161
  const content = await fs.readFile(filename, 'utf-8');
162
162
  const [up, down] = content.split('-- ROLLBACK --');
163
163
  return {
164
- useTransaction: content.includes('-- NO TRANSACTION --'),
164
+ useTransaction: !content.includes('-- NO TRANSACTION --'),
165
165
  up() {
166
166
  return up.trim();
167
167
  },
@@ -170,13 +170,13 @@ export class Migrator {
170
170
  },
171
171
  };
172
172
  }
173
- async migrate(tx, migrator, direction) {
173
+ async migrate(connection, migrator, direction) {
174
174
  try {
175
175
  const queryWithLog = (sql) => {
176
176
  this.log(chalk.yellow(sql.toString()));
177
- return tx.query(sql);
177
+ return connection.query(sql);
178
178
  };
179
- const returnValue = await migrator[direction](queryWithLog.bind(tx));
179
+ const returnValue = await migrator[direction](queryWithLog.bind(connection));
180
180
  if (typeof returnValue === 'string') {
181
181
  if (returnValue !== '') {
182
182
  await queryWithLog(returnValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devmoods/express-extras",
3
- "version": "0.17.4",
3
+ "version": "0.17.7",
4
4
  "description": "Kubernetes-ready utilities for rapid Node.js application development",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/bin/migrate.js DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env -S node --loader ts-node/esm
2
-
3
- import 'dotenv/config';
4
-
5
- async function run() {
6
- const { cli } = await import('../dist/migrate.js');
7
- cli();
8
- }
9
-
10
- run();