@scayle/h3-session 0.3.6 → 0.4.1
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/CHANGELOG.md +15 -0
- package/README.md +5 -1
- package/dist/index.js +8 -7
- package/dist/unstorage-store.js +1 -1
- package/package.json +11 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @scayle/h3-session
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependency `defu@6.1.4` to `defu@^6.1.4`
|
|
8
|
+
- Updated dependency `uncrypto@0.1.3` to `uncrypto@^0.1.3`
|
|
9
|
+
- Updated dependency `unstorage@1.10.2` to `unstorage@^1.10.2`
|
|
10
|
+
- Updated dependency `zod@3.23.5` to `zod@^3.23.8`
|
|
11
|
+
|
|
12
|
+
## 0.4.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- Export the `unsignCookie` utility function
|
|
17
|
+
|
|
3
18
|
## 0.3.6
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ npm install @scayle/h3-session
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
24
|
```ts
|
|
25
|
-
import {
|
|
25
|
+
import { UnstorageSessionStore, useSession } from '@scayle/h3-session'
|
|
26
26
|
import { createStorage } from 'unstorage'
|
|
27
27
|
|
|
28
28
|
const DEFAULT_TTL = 60 * 60 * 24
|
|
@@ -140,6 +140,10 @@ declare module '@scayle/h3-session' {
|
|
|
140
140
|
}
|
|
141
141
|
```
|
|
142
142
|
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
Licensed under the [MIT License](https://opensource.org/license/mit/)
|
|
146
|
+
|
|
143
147
|
<!-- Badges -->
|
|
144
148
|
|
|
145
149
|
[npm-version-src]: https://img.shields.io/npm/v/@scayle/h3-session/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// A session implementation for h3 based on express-session
|
|
2
|
+
import { Buffer } from 'node:buffer';
|
|
2
3
|
import { getCookie, setCookie } from 'h3';
|
|
3
4
|
import { defu } from 'defu';
|
|
4
|
-
import {
|
|
5
|
+
import { randomUUID, subtle } from 'uncrypto';
|
|
5
6
|
import { Session } from './session';
|
|
6
7
|
/**
|
|
7
8
|
* Verify that a cookie was signed with one of the secrets
|
|
@@ -10,7 +11,7 @@ import { Session } from './session';
|
|
|
10
11
|
* @param value a cookie value in the format `s:[value].[signature]`
|
|
11
12
|
* @param secrets an array of secret strings to verify with
|
|
12
13
|
*/
|
|
13
|
-
async function unsignCookie(value, secrets) {
|
|
14
|
+
export async function unsignCookie(value, secrets) {
|
|
14
15
|
// Validate cookie format
|
|
15
16
|
const matches = /s:([^.]*)\.(.*)/.exec(value);
|
|
16
17
|
if (!matches) {
|
|
@@ -85,6 +86,10 @@ export async function useSession(event, config) {
|
|
|
85
86
|
data: sessionConfig.generate(),
|
|
86
87
|
});
|
|
87
88
|
};
|
|
89
|
+
// Secret can be a string or array, normalize to an array
|
|
90
|
+
const normalizedSecrets = Array.isArray(sessionConfig.secret)
|
|
91
|
+
? sessionConfig.secret
|
|
92
|
+
: [sessionConfig.secret];
|
|
88
93
|
const createSessionCookie = async (sid) => {
|
|
89
94
|
let signedCookie;
|
|
90
95
|
const cookie = {
|
|
@@ -101,17 +106,13 @@ export async function useSession(event, config) {
|
|
|
101
106
|
// We can't hook into the onBeforeResponse, so this is the best alternative
|
|
102
107
|
return new Proxy(cookie, {
|
|
103
108
|
set(target, property, value) {
|
|
104
|
-
// @ts-
|
|
109
|
+
// @ts-expect-error Implicitly has type any
|
|
105
110
|
target[property] = value;
|
|
106
111
|
setCookie(event, sessionConfig.name, signedCookie, cookie);
|
|
107
112
|
return true;
|
|
108
113
|
},
|
|
109
114
|
});
|
|
110
115
|
};
|
|
111
|
-
// Secret can be a string or array, normalize to an array
|
|
112
|
-
const normalizedSecrets = Array.isArray(sessionConfig.secret)
|
|
113
|
-
? sessionConfig.secret
|
|
114
|
-
: [sessionConfig.secret];
|
|
115
116
|
// Check the request for a session cookie
|
|
116
117
|
const rawCookie = getCookie(event, sessionConfig.name);
|
|
117
118
|
// Extract the ID from the cookie
|
package/dist/unstorage-store.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/h3-session",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Persistent sessions for h3",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,21 +27,20 @@
|
|
|
27
27
|
"h3": "^1.10.0"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"defu": "6.1.4",
|
|
31
|
-
"uncrypto": "0.1.3",
|
|
32
|
-
"unstorage": "1.10.2",
|
|
33
|
-
"zod": "3.
|
|
30
|
+
"defu": "^6.1.4",
|
|
31
|
+
"uncrypto": "^0.1.3",
|
|
32
|
+
"unstorage": "^1.10.2",
|
|
33
|
+
"zod": "^3.23.8"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"eslint": "8.57.0",
|
|
36
|
+
"@scayle/eslint-config-storefront": "4.3.1",
|
|
37
|
+
"dprint": "0.47.2",
|
|
38
|
+
"eslint": "9.12.0",
|
|
40
39
|
"eslint-formatter-gitlab": "5.1.0",
|
|
41
|
-
"h3": "1.
|
|
42
|
-
"typescript": "5.
|
|
40
|
+
"h3": "1.13.0",
|
|
41
|
+
"typescript": "5.6.3"
|
|
43
42
|
},
|
|
44
43
|
"volta": {
|
|
45
|
-
"node": "20.
|
|
44
|
+
"node": "20.18.0"
|
|
46
45
|
}
|
|
47
46
|
}
|