@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 +5 -0
- package/dist/auth.js +21 -22
- package/dist/migrate.d.ts +1 -1
- package/dist/migrate.js +4 -4
- package/package.json +1 -1
- package/bin/migrate.js +0 -10
package/bin/migrate
ADDED
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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(
|
|
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(
|
|
173
|
+
async migrate(connection, migrator, direction) {
|
|
174
174
|
try {
|
|
175
175
|
const queryWithLog = (sql) => {
|
|
176
176
|
this.log(chalk.yellow(sql.toString()));
|
|
177
|
-
return
|
|
177
|
+
return connection.query(sql);
|
|
178
178
|
};
|
|
179
|
-
const returnValue = await migrator[direction](queryWithLog.bind(
|
|
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