@stacksjs/defaults 0.75.692 → 0.75.694
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.
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, expect, it, mock } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
class PasskeyError extends Error {}
|
|
4
|
+
let keyCount = 1
|
|
5
|
+
const HASH = 'hash:right'
|
|
6
|
+
|
|
7
|
+
mock.module('./passkey-config', () => ({
|
|
8
|
+
passkeyParty: () => ({ origin: 'https://app.example', name: 'App' }),
|
|
9
|
+
passkeyJSON: (value: unknown) => Response.json(value),
|
|
10
|
+
passkeyFailure: (error: unknown) => {
|
|
11
|
+
if (!(error instanceof PasskeyError)) throw error
|
|
12
|
+
return Response.json({ error: error.message }, { status: 400 })
|
|
13
|
+
},
|
|
14
|
+
}))
|
|
15
|
+
mock.module('@stacksjs/security', () => ({ verifyHash: async (value: string, hash: string) => `hash:${value}` === hash }))
|
|
16
|
+
mock.module('@stacksjs/auth', () => ({
|
|
17
|
+
PasskeyError,
|
|
18
|
+
// The real one's rule: the last passkey goes only with another way in.
|
|
19
|
+
removePasskey: async (_user: number, _id: string, alternative: (row: Record<string, unknown>) => Promise<boolean>) => {
|
|
20
|
+
const other = await alternative({ password: HASH })
|
|
21
|
+
if (keyCount === 1 && !other) throw new PasskeyError('Add a password or another passkey before removing your last passkey.')
|
|
22
|
+
return true
|
|
23
|
+
},
|
|
24
|
+
}))
|
|
25
|
+
|
|
26
|
+
const action = (await import('./PasskeyDestroyAction')).default as unknown as { handle: (request: unknown) => Promise<Response> }
|
|
27
|
+
const request = (password?: string) => ({
|
|
28
|
+
user: async () => ({ id: 1 }),
|
|
29
|
+
getParam: () => 'credential-1',
|
|
30
|
+
get: (key: string) => key === 'password' ? password : undefined,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('removing a passkey', () => {
|
|
34
|
+
it('removes the last one given the password', async () => {
|
|
35
|
+
keyCount = 1
|
|
36
|
+
expect((await action.handle(request('right'))).status).toBe(200)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('says the password is wrong, not that there is none', async () => {
|
|
40
|
+
keyCount = 1
|
|
41
|
+
const response = await action.handle(request('wrong'))
|
|
42
|
+
expect(response.status).toBe(422)
|
|
43
|
+
expect(await response.json()).toEqual({ error: 'The password is not right.' })
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('removes one of several with the session alone', async () => {
|
|
47
|
+
keyCount = 2
|
|
48
|
+
expect((await action.handle(request())).status).toBe(200)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
2
|
import { verifyHash } from '@stacksjs/security'
|
|
3
|
-
import { removePasskey } from '@stacksjs/auth'
|
|
3
|
+
import { PasskeyError, removePasskey } from '@stacksjs/auth'
|
|
4
4
|
import { passkeyParty, passkeyFailure, passkeyJSON } from './passkey-config'
|
|
5
5
|
|
|
6
6
|
export default new Action({
|
|
@@ -14,10 +14,21 @@ export default new Action({
|
|
|
14
14
|
if (!user) return new Response(null, { status: 401 })
|
|
15
15
|
const id = request.getParam('id')
|
|
16
16
|
if (typeof id !== 'string' || !/^[A-Za-z0-9_-]{1,1366}$/.test(id)) return new Response(null, { status: 422 })
|
|
17
|
+
// The password proves another way in. A wrong one is its own answer:
|
|
18
|
+
// reported as "add a password first", it sent an owner who has one
|
|
19
|
+
// looking for a setting rather than retyping it.
|
|
20
|
+
let wrongPassword = false
|
|
17
21
|
return await removePasskey(Number(user.id), id, async row => {
|
|
22
|
+
if (typeof row.password !== 'string' || !row.password) return false
|
|
18
23
|
const password = request.get('password')
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
const proved = typeof password === 'string' && !!password && await verifyHash(password, row.password)
|
|
25
|
+
wrongPassword = !proved
|
|
26
|
+
return proved
|
|
27
|
+
}).catch((error) => {
|
|
28
|
+
if (wrongPassword && error instanceof PasskeyError)
|
|
29
|
+
return Response.json({ error: 'The password is not right.' }, { status: 422, headers: { 'Cache-Control': 'no-store' } })
|
|
30
|
+
throw error
|
|
31
|
+
}).then(removed => removed instanceof Response ? removed : removed ? passkeyJSON({ ok: true }) : new Response(null, { status: 404 }))
|
|
21
32
|
}
|
|
22
33
|
catch (error) { return passkeyFailure(error) }
|
|
23
34
|
},
|
package/ide/vscode/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"publisher": "Stacks",
|
|
3
3
|
"name": "vscode-stacks",
|
|
4
4
|
"displayName": "Stacks",
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.694",
|
|
6
6
|
"description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/defaults",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.694",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"@iconify-json/f7": "^1.2.2",
|
|
47
47
|
"@iconify-json/hugeicons": "^1.2.35",
|
|
48
48
|
"@stacksjs/desktop": "^0.2.938",
|
|
49
|
-
"@stacksjs/mobile": "0.75.
|
|
49
|
+
"@stacksjs/mobile": "0.75.694",
|
|
50
50
|
"@stacksjs/sanitizer": "^0.2.938",
|
|
51
51
|
"@stacksjs/stx": "^0.2.938",
|
|
52
|
-
"@stacksjs/strings": "0.75.
|
|
52
|
+
"@stacksjs/strings": "0.75.694",
|
|
53
53
|
"@xterm/addon-fit": "^0.11.0",
|
|
54
54
|
"@xterm/xterm": "^6.0.0",
|
|
55
55
|
"ts-qr-codes": "^0.1.8",
|
|
56
|
-
"@stacksjs/support": "0.75.
|
|
57
|
-
"@stacksjs/browser": "0.75.
|
|
56
|
+
"@stacksjs/support": "0.75.694",
|
|
57
|
+
"@stacksjs/browser": "0.75.694"
|
|
58
58
|
}
|
|
59
59
|
}
|