@scayle/h3-session 0.3.5 → 0.4.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/CHANGELOG.md +12 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/index.js +8 -7
- package/dist/session.js +2 -2
- package/package.json +11 -12
package/CHANGELOG.md
CHANGED
package/LICENSE
CHANGED
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
|
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/session.js
CHANGED
|
@@ -18,8 +18,8 @@ export class Session {
|
|
|
18
18
|
await this.#store.set(this.#id, { ...this.data, cookie: this.cookie });
|
|
19
19
|
}
|
|
20
20
|
async reload() {
|
|
21
|
-
this.data =
|
|
22
|
-
(await this.#
|
|
21
|
+
this.data = (await this.#store.get(this.#id)) ??
|
|
22
|
+
(await this.#generate()).data;
|
|
23
23
|
}
|
|
24
24
|
async destroy() {
|
|
25
25
|
// Delete the cookie by setting maxAge to 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scayle/h3-session",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Persistent sessions for h3",
|
|
5
5
|
"author": "SCAYLE Commerce Engine",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "yarn tsc -p tsconfig.json",
|
|
21
|
-
"format": "
|
|
22
|
-
"format:fix": "
|
|
21
|
+
"format": "dprint check",
|
|
22
|
+
"format:fix": "dprint fmt",
|
|
23
23
|
"lint": "eslint . --format gitlab",
|
|
24
24
|
"lint:fix": "eslint . --fix"
|
|
25
25
|
},
|
|
@@ -29,20 +29,19 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"defu": "6.1.4",
|
|
31
31
|
"uncrypto": "0.1.3",
|
|
32
|
-
"unstorage": "1.10.
|
|
33
|
-
"zod": "3.
|
|
32
|
+
"unstorage": "1.10.2",
|
|
33
|
+
"zod": "3.23.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@changesets/types": "6.0.0",
|
|
37
|
-
"@scayle/eslint-config-storefront": "
|
|
38
|
-
"
|
|
39
|
-
"eslint": "
|
|
37
|
+
"@scayle/eslint-config-storefront": "4.1.0",
|
|
38
|
+
"dprint": "0.45.1",
|
|
39
|
+
"eslint": "9.2.0",
|
|
40
40
|
"eslint-formatter-gitlab": "5.1.0",
|
|
41
|
-
"h3": "1.
|
|
42
|
-
"
|
|
43
|
-
"typescript": "5.3.3"
|
|
41
|
+
"h3": "1.11.1",
|
|
42
|
+
"typescript": "5.4.5"
|
|
44
43
|
},
|
|
45
44
|
"volta": {
|
|
46
|
-
"node": "20.
|
|
45
|
+
"node": "20.12.2"
|
|
47
46
|
}
|
|
48
47
|
}
|