@1auth/account-username 0.0.0-alpha.56 → 0.0.0-alpha.58
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 +11 -9
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
lookup as accountLookup
|
|
5
5
|
} from '@1auth/account'
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { createSeasonedDigest, symmetricDecryptFields } from '@1auth/crypto'
|
|
8
8
|
|
|
9
9
|
// Only allow characters that are safe to encode
|
|
10
10
|
// . not allowed because it can be used to declare and extension
|
|
@@ -26,7 +26,7 @@ export default (params) => {
|
|
|
26
26
|
|
|
27
27
|
export const exists = async (username) => {
|
|
28
28
|
const usernameSanitized = sanitize(username)
|
|
29
|
-
const usernameDigest =
|
|
29
|
+
const usernameDigest = createSeasonedDigest(usernameSanitized)
|
|
30
30
|
return options.store.exists(options.table, {
|
|
31
31
|
digest: usernameDigest
|
|
32
32
|
})
|
|
@@ -34,7 +34,7 @@ export const exists = async (username) => {
|
|
|
34
34
|
|
|
35
35
|
export const lookup = async (username) => {
|
|
36
36
|
const usernameSanitized = sanitize(username)
|
|
37
|
-
const usernameDigest =
|
|
37
|
+
const usernameDigest = createSeasonedDigest(usernameSanitized)
|
|
38
38
|
|
|
39
39
|
let item = await options.store.select(options.table, {
|
|
40
40
|
digest: usernameDigest
|
|
@@ -55,14 +55,16 @@ export const create = async (sub, username) => {
|
|
|
55
55
|
const usernameSanitized = sanitize(username)
|
|
56
56
|
const usernameValidate = validate(usernameSanitized)
|
|
57
57
|
if (usernameValidate !== true) {
|
|
58
|
-
throw new Error(
|
|
58
|
+
throw new Error(usernameValidate, {
|
|
59
|
+
cause: { username, usernameSanitized }
|
|
60
|
+
})
|
|
59
61
|
}
|
|
60
|
-
const usernameDigest =
|
|
62
|
+
const usernameDigest = createSeasonedDigest(usernameSanitized)
|
|
61
63
|
const usernameExists = await options.store.exists(options.table, {
|
|
62
64
|
digest: usernameDigest
|
|
63
65
|
})
|
|
64
66
|
if (usernameExists) {
|
|
65
|
-
throw new Error('409 Conflict')
|
|
67
|
+
throw new Error('409 Conflict', { cause: { username, usernameSanitized } })
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
await accountUpdate(sub, {
|
|
@@ -99,7 +101,7 @@ export const validate = (value) => {
|
|
|
99
101
|
|
|
100
102
|
export const validateLength = (value) => {
|
|
101
103
|
if (value.length < 1 && options.maxLength < value.length) {
|
|
102
|
-
return '400'
|
|
104
|
+
return '400 Bad Request'
|
|
103
105
|
}
|
|
104
106
|
return true
|
|
105
107
|
}
|
|
@@ -107,14 +109,14 @@ export const validateLength = (value) => {
|
|
|
107
109
|
export const validateAllowedChar = (value) => {
|
|
108
110
|
// TODO URL encode compare
|
|
109
111
|
if (!options.allowedCharRegExp.test(value)) {
|
|
110
|
-
return '400'
|
|
112
|
+
return '400 Bad Request'
|
|
111
113
|
}
|
|
112
114
|
return true
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
export const validateBlacklist = (value) => {
|
|
116
118
|
if (usernameBlacklistRegExp?.test(value)) {
|
|
117
|
-
return '409'
|
|
119
|
+
return '409 Conflict'
|
|
118
120
|
}
|
|
119
121
|
return true
|
|
120
122
|
}
|
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.58",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -50,6 +50,6 @@
|
|
|
50
50
|
"homepage": "https://github.com/willfarrell/1auth",
|
|
51
51
|
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@1auth/account": "0.0.0-alpha.
|
|
53
|
+
"@1auth/account": "0.0.0-alpha.58"
|
|
54
54
|
}
|
|
55
55
|
}
|