@scayle/h3-session 0.3.6 → 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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scayle/h3-session
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Export the `unsignCookie` utility function
8
+
3
9
  ## 0.3.6
4
10
 
5
11
  ### 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 { useSession, UnstorageSessionStore } from '@scayle/h3-session'
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 { subtle, randomUUID } from 'uncrypto';
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-ignore
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/h3-session",
3
- "version": "0.3.6",
3
+ "version": "0.4.0",
4
4
  "description": "Persistent sessions for h3",
5
5
  "author": "SCAYLE Commerce Engine",
6
6
  "license": "MIT",
@@ -30,18 +30,18 @@
30
30
  "defu": "6.1.4",
31
31
  "uncrypto": "0.1.3",
32
32
  "unstorage": "1.10.2",
33
- "zod": "3.22.4"
33
+ "zod": "3.23.5"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@changesets/types": "6.0.0",
37
- "@scayle/eslint-config-storefront": "3.2.7",
37
+ "@scayle/eslint-config-storefront": "4.1.0",
38
38
  "dprint": "0.45.1",
39
- "eslint": "8.57.0",
39
+ "eslint": "9.2.0",
40
40
  "eslint-formatter-gitlab": "5.1.0",
41
41
  "h3": "1.11.1",
42
- "typescript": "5.4.4"
42
+ "typescript": "5.4.5"
43
43
  },
44
44
  "volta": {
45
- "node": "20.12.1"
45
+ "node": "20.12.2"
46
46
  }
47
47
  }