@1auth/account-username 0.0.0-alpha.3 → 0.0.0-alpha.30
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/index.js +15 -13
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -5,17 +5,21 @@ import {
|
|
|
5
5
|
|
|
6
6
|
import { createDigest } from '@1auth/crypto'
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
// Only allow characters that are safe to encode
|
|
9
|
+
// . not allowed because it can be used to declare and extension
|
|
10
|
+
export const regexp = /^[a-z0-9_-]*$/
|
|
9
11
|
export const jsonSchema = {
|
|
10
12
|
type: 'string',
|
|
11
|
-
pattern: '^[a-z0-
|
|
13
|
+
pattern: '^[a-z0-9_-]*$',
|
|
12
14
|
minLength: 1,
|
|
13
15
|
maxLength: 32
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
const options = {
|
|
17
19
|
id: 'username',
|
|
18
|
-
blacklist: [
|
|
20
|
+
blacklist: []
|
|
21
|
+
// minLength: 1,
|
|
22
|
+
// maxLength: 32
|
|
19
23
|
}
|
|
20
24
|
export default (params) => {
|
|
21
25
|
Object.assign(options, accountOptions(), params)
|
|
@@ -31,23 +35,21 @@ export const exists = async (username) => {
|
|
|
31
35
|
export const lookup = async (username) => {
|
|
32
36
|
if (!username) return {}
|
|
33
37
|
const usernameSanitized = __sanitize(username)
|
|
34
|
-
return (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
})) ?? {}
|
|
38
|
-
)
|
|
38
|
+
return await options.store.select(options.table, {
|
|
39
|
+
digest: await createDigest(usernameSanitized)
|
|
40
|
+
})
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export const create = async (sub, username) => {
|
|
42
|
-
|
|
44
|
+
const usernameSanitized = __sanitize(username)
|
|
45
|
+
if (!__validate(usernameSanitized)) {
|
|
43
46
|
throw new Error('400 invalid characters')
|
|
44
47
|
}
|
|
45
|
-
if (!__blacklist(
|
|
48
|
+
if (!__blacklist(usernameSanitized) || (await exists(usernameSanitized))) {
|
|
46
49
|
throw new Error('409 Conflict')
|
|
47
50
|
}
|
|
48
|
-
const usernameSanitized = __sanitize(username)
|
|
49
51
|
await accountUpdate(sub, {
|
|
50
|
-
username
|
|
52
|
+
username,
|
|
51
53
|
digest: await createDigest(usernameSanitized)
|
|
52
54
|
})
|
|
53
55
|
}
|
|
@@ -63,7 +65,7 @@ export const recover = async (sub) => {
|
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
export const __sanitize = (value) => {
|
|
66
|
-
return value.trim()
|
|
68
|
+
return value.trim().toLocaleLowerCase()
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
export const __validate = (value) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1auth/account-username",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.30",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"url": "https://github.com/willfarrell/1auth/issues"
|
|
49
49
|
},
|
|
50
50
|
"homepage": "https://github.com/willfarrell/1auth",
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "bba2971096bfd6bcc30e7613fae272896456ecfa",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@1auth/account": "0.0.0-alpha.
|
|
53
|
+
"@1auth/account": "0.0.0-alpha.30"
|
|
54
54
|
}
|
|
55
55
|
}
|