@tylix/auth 0.4.0 → 0.5.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tylix/auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tylix",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"test": "node --test src/**/*.test.js"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@tylix/core": "^0.
|
|
16
|
-
"@tylix/generator": "^0.
|
|
17
|
-
"@tylix/orm": "^0.
|
|
18
|
-
"@tylix/shared": "^0.
|
|
15
|
+
"@tylix/core": "^0.5.0",
|
|
16
|
+
"@tylix/generator": "^0.5.0",
|
|
17
|
+
"@tylix/orm": "^0.5.0",
|
|
18
|
+
"@tylix/shared": "^0.5.0"
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -1,33 +1,59 @@
|
|
|
1
|
-
import { test } from
|
|
2
|
-
import assert from
|
|
3
|
-
import fs from
|
|
4
|
-
import path from
|
|
5
|
-
import { fileURLToPath } from
|
|
6
|
-
import { AuthGenerator } from
|
|
7
|
-
|
|
8
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
9
|
-
|
|
10
|
-
test(
|
|
11
|
-
const outputDir = path.join(__dirname,
|
|
12
|
-
await fs.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
import { test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import fs from 'node:fs/promises'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
import { AuthGenerator } from './AuthGenerator.js'
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
|
|
10
|
+
test('generates auth models, validator, controller, mail files and migrations', async () => {
|
|
11
|
+
const outputDir = path.join(__dirname, '.tmp-test-output')
|
|
12
|
+
await fs.rm(outputDir, { recursive: true, force: true })
|
|
13
|
+
await fs.mkdir(outputDir, { recursive: true })
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const results = await new AuthGenerator().generate(outputDir)
|
|
17
|
+
|
|
18
|
+
// Every key the generator reports must point at a real file.
|
|
19
|
+
const expected = [
|
|
20
|
+
'userModel',
|
|
21
|
+
'refreshTokenModel',
|
|
22
|
+
'passwordResetModel',
|
|
23
|
+
'validator',
|
|
24
|
+
'controller',
|
|
25
|
+
'mailer',
|
|
26
|
+
'verifyEmailMail',
|
|
27
|
+
'resetPasswordMail',
|
|
28
|
+
'verifyEmailView',
|
|
29
|
+
'resetPasswordView',
|
|
30
|
+
'userMigration',
|
|
31
|
+
'refreshTokenMigration',
|
|
32
|
+
'passwordResetMigration',
|
|
33
|
+
]
|
|
34
|
+
for (const key of expected) {
|
|
35
|
+
assert.ok(results[key], `generate() returned no path for "${key}"`)
|
|
36
|
+
await fs.access(results[key])
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const read = (key) => fs.readFile(results[key], 'utf-8')
|
|
40
|
+
|
|
41
|
+
assert.match(await read('userModel'), /export class User extends Model/)
|
|
42
|
+
assert.match(await read('refreshTokenModel'), /export class RefreshToken/)
|
|
43
|
+
assert.match(await read('passwordResetModel'), /export class PasswordReset/)
|
|
44
|
+
assert.match(await read('validator'), /export function validateRegister/)
|
|
45
|
+
assert.match(await read('validator'), /export function validateLogin/)
|
|
46
|
+
|
|
47
|
+
const controller = await read('controller')
|
|
48
|
+
assert.match(controller, /export class AuthController/)
|
|
49
|
+
assert.match(controller, /async register\(req, res\)/)
|
|
50
|
+
assert.match(controller, /async login\(req, res\)/)
|
|
51
|
+
assert.match(controller, /async me\(req, res\)/)
|
|
52
|
+
|
|
53
|
+
assert.match(await read('userMigration'), /createTable\("users"/)
|
|
54
|
+
assert.match(await read('refreshTokenMigration'), /createTable\("refresh_tokens"/)
|
|
55
|
+
assert.match(await read('passwordResetMigration'), /createTable\("password_resets"/)
|
|
56
|
+
} finally {
|
|
57
|
+
await fs.rm(outputDir, { recursive: true, force: true })
|
|
58
|
+
}
|
|
59
|
+
})
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* in your .env / tylix.config.ts — no code changes needed here.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { MailConfig } from "@tylix/mail";
|
|
12
13
|
import { VerifyEmailMail } from "./VerifyEmailMail.js";
|
|
13
14
|
import { ResetPasswordMail } from "./ResetPasswordMail.js";
|
|
14
15
|
|
|
@@ -21,10 +22,10 @@ interface MailableUser {
|
|
|
21
22
|
|
|
22
23
|
export async function sendVerificationEmail(user: MailableUser, token: string, mailConfig: unknown) {
|
|
23
24
|
const verifyUrl = `${APP_URL}/api/auth/verify-email?token=${token}`;
|
|
24
|
-
await new VerifyEmailMail(verifyUrl).send(user.email, mailConfig);
|
|
25
|
+
await new VerifyEmailMail(verifyUrl).send(user.email, mailConfig as MailConfig);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export async function sendPasswordResetEmail(user: MailableUser, token: string, mailConfig: unknown) {
|
|
28
29
|
const resetUrl = `${APP_URL}/reset-password?token=${token}&email=${encodeURIComponent(user.email)}`;
|
|
29
|
-
await new ResetPasswordMail(resetUrl).send(user.email, mailConfig);
|
|
30
|
-
}
|
|
30
|
+
await new ResetPasswordMail(resetUrl).send(user.email, mailConfig as MailConfig);
|
|
31
|
+
}
|