unjwt 0.5.26 → 0.5.27
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/dist/adapters/h3.d.mts +58 -54
- package/dist/adapters/h3v1.d.mts +1 -1
- package/dist/adapters/h3v2.d.mts +58 -54
- package/package.json +1 -1
package/dist/adapters/h3.d.mts
CHANGED
|
@@ -7,57 +7,62 @@ import { H3Event } from 'h3';
|
|
|
7
7
|
import { c as JWSSignOptions } from '../shared/unjwt.BsLgL0DQ.mjs';
|
|
8
8
|
export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BjP_dGnX.mjs';
|
|
9
9
|
|
|
10
|
+
type SessionData<T extends JWTClaims = JWTClaims> = Omit<T, "jti" | "iat" | "exp">;
|
|
11
|
+
type SessionUpdate<T extends JWTClaims = JWTClaims> = Partial<SessionData<T>> | ((oldData: SessionData<T>) => Partial<SessionData<T>> | undefined);
|
|
12
|
+
interface SessionManager<T extends JWTClaims = JWTClaims, ConfigMaxAge extends number | undefined = number | undefined> {
|
|
13
|
+
readonly id: string | undefined;
|
|
14
|
+
readonly createdAt: number;
|
|
15
|
+
readonly expiresAt: T extends {
|
|
16
|
+
exp: number;
|
|
17
|
+
} ? number : ConfigMaxAge;
|
|
18
|
+
readonly data: SessionData<T>;
|
|
19
|
+
update: (update: SessionUpdate<T>) => Promise<SessionManager<T>>;
|
|
20
|
+
clear: () => Promise<SessionManager<T>>;
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
/**
|
|
11
24
|
* This is a fork of h3 library's session utility functions.
|
|
12
25
|
* @source https://github.com/h3js/h3/blob/b4dce71c256911335f3402d09f30ffad120ad61a/src/utils/session.ts
|
|
13
26
|
* @license MIT https://github.com/h3js/h3/blob/b4dce71c256911335f3402d09f30ffad120ad61a/LICENSE
|
|
14
27
|
*/
|
|
15
28
|
|
|
16
|
-
type SessionDataT$1 = Omit<JWTClaims, "jti" | "iat" | "exp">;
|
|
17
|
-
type SessionData<T extends SessionDataT$1 = SessionDataT$1> = T;
|
|
18
29
|
declare const kGetSessionPromise$1: unique symbol;
|
|
19
|
-
interface SessionJWE<T extends
|
|
30
|
+
interface SessionJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
20
31
|
id: string;
|
|
21
32
|
createdAt: number;
|
|
22
|
-
expiresAt
|
|
33
|
+
expiresAt: T extends {
|
|
34
|
+
exp: number;
|
|
35
|
+
} ? number : MaxAge;
|
|
23
36
|
data: SessionData<T>;
|
|
24
|
-
[kGetSessionPromise$1]?: Promise<SessionJWE<T>>;
|
|
37
|
+
[kGetSessionPromise$1]?: Promise<SessionJWE<T, MaxAge>>;
|
|
25
38
|
}
|
|
26
|
-
interface SessionHooksJWE {
|
|
39
|
+
interface SessionHooksJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
27
40
|
onRead?: (args: {
|
|
28
|
-
session: SessionJWE
|
|
41
|
+
session: SessionJWE<T, MaxAge>;
|
|
29
42
|
event: H3Event;
|
|
30
|
-
config: SessionConfigJWE
|
|
43
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
31
44
|
}) => void | Promise<void>;
|
|
32
45
|
onUpdate?: (args: {
|
|
33
|
-
session: SessionJWE
|
|
46
|
+
session: SessionJWE<T, MaxAge>;
|
|
34
47
|
event: H3Event;
|
|
35
|
-
config: SessionConfigJWE
|
|
48
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
36
49
|
}) => void | Promise<void>;
|
|
37
50
|
onClear?: (args: {
|
|
38
51
|
event: H3Event;
|
|
39
|
-
config: Partial<SessionConfigJWE
|
|
52
|
+
config: Partial<SessionConfigJWE<T, MaxAge>>;
|
|
40
53
|
}) => void | Promise<void>;
|
|
41
54
|
onExpire?: (args: {
|
|
42
55
|
event: H3Event;
|
|
43
56
|
error: Error;
|
|
44
|
-
config: SessionConfigJWE
|
|
57
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
45
58
|
}) => void | Promise<void>;
|
|
46
59
|
onError?: (args: {
|
|
47
60
|
event: H3Event;
|
|
48
61
|
error: any;
|
|
49
|
-
config: SessionConfigJWE
|
|
62
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
50
63
|
}) => void | Promise<void>;
|
|
51
64
|
}
|
|
52
|
-
interface
|
|
53
|
-
readonly id: string | undefined;
|
|
54
|
-
readonly createdAt: number;
|
|
55
|
-
readonly expiresAt: number | undefined;
|
|
56
|
-
readonly data: SessionData<T>;
|
|
57
|
-
update: (update: SessionUpdate$1<T>) => Promise<SessionManager<T>>;
|
|
58
|
-
clear: () => Promise<SessionManager<T>>;
|
|
59
|
-
}
|
|
60
|
-
interface SessionConfigJWE {
|
|
65
|
+
interface SessionConfigJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
61
66
|
/** @deprecated use `key` instead */
|
|
62
67
|
secret?: string | JWK_Symmetric | {
|
|
63
68
|
privateKey: JWK_Private | JWK_Symmetric;
|
|
@@ -69,7 +74,7 @@ interface SessionConfigJWE {
|
|
|
69
74
|
publicKey?: JWK_Public;
|
|
70
75
|
};
|
|
71
76
|
/** Session lifetime in seconds (used to derive exp from iat) */
|
|
72
|
-
maxAge?:
|
|
77
|
+
maxAge?: MaxAge;
|
|
73
78
|
/** Default is "h3" */
|
|
74
79
|
name?: string;
|
|
75
80
|
/** Default is secure, httpOnly, path="/" */
|
|
@@ -83,7 +88,7 @@ interface SessionConfigJWE {
|
|
|
83
88
|
encryptOptions?: Omit<JWEEncryptOptions, "expiresIn">;
|
|
84
89
|
decryptOptions?: JWTClaimValidationOptions;
|
|
85
90
|
};
|
|
86
|
-
hooks?: SessionHooksJWE
|
|
91
|
+
hooks?: SessionHooksJWE<T, MaxAge>;
|
|
87
92
|
}
|
|
88
93
|
/**
|
|
89
94
|
* @deprecated use `SessionConfigJWE` instead
|
|
@@ -98,19 +103,18 @@ type CompatEvent$1 = {
|
|
|
98
103
|
headers: Headers;
|
|
99
104
|
context: any;
|
|
100
105
|
};
|
|
101
|
-
type SessionUpdate$1<T extends SessionDataT$1 = SessionDataT$1> = Partial<SessionData<T>> | ((oldData: SessionData<T>) => Partial<SessionData<T>> | undefined);
|
|
102
106
|
/**
|
|
103
107
|
* Create a session manager for the current request.
|
|
104
108
|
*/
|
|
105
|
-
declare function useJWESession<T extends
|
|
109
|
+
declare function useJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): Promise<SessionManager<T, MaxAge>>;
|
|
106
110
|
/**
|
|
107
111
|
* Get (and lazily initialize) the session for the current request.
|
|
108
112
|
*/
|
|
109
|
-
declare function getJWESession<T extends
|
|
113
|
+
declare function getJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): Promise<SessionJWE<T, MaxAge>>;
|
|
110
114
|
/**
|
|
111
115
|
* Update the session (optionally mutating the session data) and re-issue the JWE token.
|
|
112
116
|
*/
|
|
113
|
-
declare function updateJWESession<T extends
|
|
117
|
+
declare function updateJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event, config: SessionConfigJWE<T, MaxAge>, update?: SessionUpdate<T>): Promise<SessionJWE<T, MaxAge>>;
|
|
114
118
|
/**
|
|
115
119
|
* Produce a JWE for the current session.
|
|
116
120
|
* Payload structure:
|
|
@@ -121,15 +125,15 @@ declare function updateJWESession<T extends SessionDataT$1 = SessionDataT$1>(eve
|
|
|
121
125
|
* data: Record<string, any>;
|
|
122
126
|
* }
|
|
123
127
|
*/
|
|
124
|
-
declare function sealJWESession<T extends
|
|
128
|
+
declare function sealJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): Promise<string>;
|
|
125
129
|
/**
|
|
126
130
|
* Decrypt the JWE and return a Session-compatible object.
|
|
127
131
|
*/
|
|
128
|
-
declare function unsealJWESession(_event: H3Event | CompatEvent$1, config: SessionConfigJWE, sealed: string): Promise<Partial<SessionJWE
|
|
132
|
+
declare function unsealJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(_event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>, sealed: string): Promise<Partial<SessionJWE<T, MaxAge>>>;
|
|
129
133
|
/**
|
|
130
134
|
* Clear the session (delete from context and drop cookie).
|
|
131
135
|
*/
|
|
132
|
-
declare function clearJWESession(event: H3Event, config: Partial<SessionConfigJWE
|
|
136
|
+
declare function clearJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event, config: Partial<SessionConfigJWE<T, MaxAge>>): Promise<void>;
|
|
133
137
|
|
|
134
138
|
/**
|
|
135
139
|
* This is a fork of h3 library's session utility functions.
|
|
@@ -137,42 +141,43 @@ declare function clearJWESession(event: H3Event, config: Partial<SessionConfigJW
|
|
|
137
141
|
* @license MIT https://github.com/h3js/h3/blob/b4dce71c256911335f3402d09f30ffad120ad61a/LICENSE
|
|
138
142
|
*/
|
|
139
143
|
|
|
140
|
-
type SessionDataT = Omit<JWTClaims, "jti" | "iat" | "exp">;
|
|
141
144
|
declare const kGetSessionPromise: unique symbol;
|
|
142
|
-
interface SessionJWS<T extends
|
|
145
|
+
interface SessionJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
143
146
|
id: string;
|
|
144
147
|
createdAt: number;
|
|
145
|
-
expiresAt
|
|
148
|
+
expiresAt: T extends {
|
|
149
|
+
exp: number;
|
|
150
|
+
} ? number : MaxAge;
|
|
146
151
|
data: SessionData<T>;
|
|
147
|
-
[kGetSessionPromise]?: Promise<SessionJWS<T>>;
|
|
152
|
+
[kGetSessionPromise]?: Promise<SessionJWS<T, MaxAge>>;
|
|
148
153
|
}
|
|
149
|
-
interface SessionHooksJWS {
|
|
154
|
+
interface SessionHooksJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
150
155
|
onRead?: (args: {
|
|
151
|
-
session: SessionJWS
|
|
156
|
+
session: SessionJWS<T, MaxAge>;
|
|
152
157
|
event: H3Event;
|
|
153
|
-
config: SessionConfigJWS
|
|
158
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
154
159
|
}) => void | Promise<void>;
|
|
155
160
|
onUpdate?: (args: {
|
|
156
|
-
session: SessionJWS
|
|
161
|
+
session: SessionJWS<T, MaxAge>;
|
|
157
162
|
event: H3Event;
|
|
158
|
-
config: SessionConfigJWS
|
|
163
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
159
164
|
}) => void | Promise<void>;
|
|
160
165
|
onClear?: (args: {
|
|
161
166
|
event: H3Event;
|
|
162
|
-
config: Partial<SessionConfigJWS
|
|
167
|
+
config: Partial<SessionConfigJWS<T, MaxAge>>;
|
|
163
168
|
}) => void | Promise<void>;
|
|
164
169
|
onExpire?: (args: {
|
|
165
170
|
event: H3Event;
|
|
166
171
|
error: Error;
|
|
167
|
-
config: SessionConfigJWS
|
|
172
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
168
173
|
}) => void | Promise<void>;
|
|
169
174
|
onError?: (args: {
|
|
170
175
|
event: H3Event;
|
|
171
176
|
error: any;
|
|
172
|
-
config: SessionConfigJWS
|
|
177
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
173
178
|
}) => void | Promise<void>;
|
|
174
179
|
}
|
|
175
|
-
interface SessionConfigJWS {
|
|
180
|
+
interface SessionConfigJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
176
181
|
/**
|
|
177
182
|
* JWK (private for signing with RS/ES/PS, or symmetric oct) used for signing.
|
|
178
183
|
*/
|
|
@@ -181,7 +186,7 @@ interface SessionConfigJWS {
|
|
|
181
186
|
publicKey: JWK_Public | JWK_Public[] | JWKSet;
|
|
182
187
|
};
|
|
183
188
|
/** Session lifetime in seconds (sets exp = iat + maxAge) */
|
|
184
|
-
maxAge?:
|
|
189
|
+
maxAge?: MaxAge;
|
|
185
190
|
/** Default cookie / header name base */
|
|
186
191
|
name?: string;
|
|
187
192
|
/** Cookie options (false to disable cookies) */
|
|
@@ -195,7 +200,7 @@ interface SessionConfigJWS {
|
|
|
195
200
|
signOptions?: Omit<JWSSignOptions, "expiresIn">;
|
|
196
201
|
verifyOptions?: JWTClaimValidationOptions;
|
|
197
202
|
};
|
|
198
|
-
hooks?: SessionHooksJWS
|
|
203
|
+
hooks?: SessionHooksJWS<T, MaxAge>;
|
|
199
204
|
}
|
|
200
205
|
/**
|
|
201
206
|
* @deprecated use `SessionConfigJWS` instead
|
|
@@ -210,26 +215,25 @@ type CompatEvent = {
|
|
|
210
215
|
headers: Headers;
|
|
211
216
|
context: any;
|
|
212
217
|
};
|
|
213
|
-
type SessionUpdate<T extends SessionDataT = SessionDataT> = Partial<SessionData<T>> | ((oldData: SessionData<T>) => Partial<SessionData<T>> | undefined);
|
|
214
218
|
/**
|
|
215
219
|
* Create a session manager for the current request using JWS (signed only, not encrypted).
|
|
216
220
|
* NOTE: Contents are visible to clients (Base64URL-decoded JSON). Do not store secrets in session data.
|
|
217
221
|
*/
|
|
218
|
-
declare function useJWSSession<T extends
|
|
222
|
+
declare function useJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionManager<T, MaxAge>>;
|
|
219
223
|
/**
|
|
220
224
|
* Retrieve (and lazily initialize) the session.
|
|
221
225
|
*/
|
|
222
|
-
declare function getJWSSession<T extends
|
|
226
|
+
declare function getJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionJWS<T, MaxAge>>;
|
|
223
227
|
/**
|
|
224
228
|
* Update session data (if provided) and reissue JWS.
|
|
225
229
|
*/
|
|
226
|
-
declare function updateJWSSession<T extends
|
|
230
|
+
declare function updateJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event, config: SessionConfigJWS<T, MaxAge>, update?: SessionUpdate<T>): Promise<SessionJWS<T, MaxAge>>;
|
|
227
231
|
/**
|
|
228
232
|
* Sign current session as a compact JWS.
|
|
229
233
|
* Payload claims:
|
|
230
234
|
* jti, iat, exp?, data, plus optional extraClaims (cannot override reserved)
|
|
231
235
|
*/
|
|
232
|
-
declare function signJWSSession<T extends
|
|
236
|
+
declare function signJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>): Promise<string>;
|
|
233
237
|
/**
|
|
234
238
|
* Verify and parse a compact JWS into a Session structure.
|
|
235
239
|
* Performs:
|
|
@@ -238,11 +242,11 @@ declare function signJWSSession<T extends SessionDataT = SessionDataT>(event: H3
|
|
|
238
242
|
* - ensures jti & iat presence
|
|
239
243
|
* - enforces maxAge if provided
|
|
240
244
|
*/
|
|
241
|
-
declare function verifyJWSSession(_event: H3Event | CompatEvent, config: SessionConfigJWS, token: string): Promise<Partial<SessionJWS
|
|
245
|
+
declare function verifyJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(_event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>, token: string): Promise<Partial<SessionJWS<T, MaxAge>>>;
|
|
242
246
|
/**
|
|
243
247
|
* Destroy the session (context + cookie).
|
|
244
248
|
*/
|
|
245
|
-
declare function clearJWSSession(event: H3Event, config: Partial<SessionConfigJWS
|
|
249
|
+
declare function clearJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event, config: Partial<SessionConfigJWS<T, MaxAge>>): Promise<void>;
|
|
246
250
|
|
|
247
251
|
export { JWEEncryptOptions, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
|
248
|
-
export type { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager };
|
|
252
|
+
export type { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, SessionUpdate };
|
package/dist/adapters/h3v1.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { d as JWEDecryptOptions, e as JWEDecryptResult, b as JWEEncryptOptions, J as JWEHeaderParameters, c as JWEKeyLookupFunction, a as JWEKeyManagementHeaderParameters } from '../shared/unjwt.9mL1vSFP.mjs';
|
|
2
2
|
export { C as CompositeKey, f as ContentEncryptionAlgorithm, D as DeriveKeyOptions, e as DeriveKeyReturn, c as GenerateJWKOptions, d as GenerateJWKReturn, G as GenerateKeyAlgorithm, a as GenerateKeyOptions, b as GenerateKeyReturn, v as JWK, S as JWKAlgorithm, T as JWKPEMAlgorithm, J as JWKParameters, w as JWKSet, I as JWK_AES_CBC_HMAC, L as JWK_AES_GCM, H as JWK_AES_GCM_KW, F as JWK_AES_KW, s as JWK_Asymmetric, R as JWK_Asymmetric_Algorithm, j as JWK_EC, O as JWK_ECDH_ES, A as JWK_ECDSA, i as JWK_EC_Private, h as JWK_EC_Public, x as JWK_HMAC, p as JWK_OKP, o as JWK_OKP_Private, n as JWK_OKP_Public, P as JWK_OKP_SIGN, N as JWK_PBES2, u as JWK_Private, t as JWK_Public, m as JWK_RSA, B as JWK_RSA_ENC, z as JWK_RSA_PSS, l as JWK_RSA_Private, k as JWK_RSA_Public, y as JWK_RSA_SIGN, r as JWK_Symmetric, Q as JWK_Symmetric_Algorithm, q as JWK_oct, Y as JWT, Z as JWTClaimValidationOptions, X as JWTClaims, V as JoseHeaderParameters, K as KeyManagementAlgorithm, U as UnwrapKeyOptions, W as WrapKeyOptions, g as WrapKeyResult } from '../shared/unjwt.CtHrClHc.mjs';
|
|
3
|
-
export { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession } from './h3.mjs';
|
|
3
|
+
export { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWEConfig, SessionJWS, SessionJWSConfig, SessionManager, SessionUpdate, clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession } from './h3.mjs';
|
|
4
4
|
export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BjP_dGnX.mjs';
|
|
5
5
|
import 'cookie-es';
|
|
6
6
|
import 'h3';
|
package/dist/adapters/h3v2.d.mts
CHANGED
|
@@ -7,58 +7,63 @@ import { CookieSerializeOptions } from 'cookie-es';
|
|
|
7
7
|
import { c as JWSSignOptions } from '../shared/unjwt.BsLgL0DQ.mjs';
|
|
8
8
|
export { d as deriveJWKFromPassword, e as exportJWKToPEM, g as generateJWK, i as importJWKFromPEM } from '../shared/unjwt.BjP_dGnX.mjs';
|
|
9
9
|
|
|
10
|
-
type
|
|
11
|
-
type
|
|
10
|
+
type SessionData<T extends JWTClaims = JWTClaims> = Omit<T, "jti" | "iat" | "exp">;
|
|
11
|
+
type SessionUpdate<T extends JWTClaims = JWTClaims> = Partial<SessionData<T>> | ((oldData: SessionData<T>) => Partial<SessionData<T>> | undefined);
|
|
12
|
+
interface SessionManager<T extends JWTClaims = JWTClaims, ConfigMaxAge extends number | undefined = number | undefined> {
|
|
13
|
+
readonly id: string | undefined;
|
|
14
|
+
readonly createdAt: number;
|
|
15
|
+
readonly expiresAt: T extends {
|
|
16
|
+
exp: number;
|
|
17
|
+
} ? number : ConfigMaxAge;
|
|
18
|
+
readonly data: SessionData<T>;
|
|
19
|
+
update: (update: SessionUpdate<T>) => Promise<SessionManager<T>>;
|
|
20
|
+
clear: () => Promise<SessionManager<T>>;
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
declare const kGetSessionPromise$1: unique symbol;
|
|
13
|
-
interface SessionJWE<T extends
|
|
24
|
+
interface SessionJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
14
25
|
id: string;
|
|
15
26
|
createdAt: number;
|
|
16
|
-
expiresAt
|
|
27
|
+
expiresAt: T extends {
|
|
28
|
+
exp: number;
|
|
29
|
+
} ? number : MaxAge;
|
|
17
30
|
data: SessionData<T>;
|
|
18
|
-
[kGetSessionPromise$1]?: Promise<SessionJWE<T>>;
|
|
31
|
+
[kGetSessionPromise$1]?: Promise<SessionJWE<T, MaxAge>>;
|
|
19
32
|
}
|
|
20
|
-
interface SessionHooksJWE {
|
|
33
|
+
interface SessionHooksJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
21
34
|
onRead?: (args: {
|
|
22
|
-
session: SessionJWE
|
|
35
|
+
session: SessionJWE<T, MaxAge>;
|
|
23
36
|
event: HTTPEvent;
|
|
24
|
-
config: SessionConfigJWE
|
|
37
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
25
38
|
}) => void | Promise<void>;
|
|
26
39
|
onUpdate?: (args: {
|
|
27
|
-
session: SessionJWE
|
|
40
|
+
session: SessionJWE<T, MaxAge>;
|
|
28
41
|
event: HTTPEvent;
|
|
29
|
-
config: SessionConfigJWE
|
|
42
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
30
43
|
}) => void | Promise<void>;
|
|
31
44
|
onClear?: (args: {
|
|
32
45
|
event: HTTPEvent;
|
|
33
|
-
config: Partial<SessionConfigJWE
|
|
46
|
+
config: Partial<SessionConfigJWE<T, MaxAge>>;
|
|
34
47
|
}) => void | Promise<void>;
|
|
35
48
|
onExpire?: (args: {
|
|
36
49
|
event: HTTPEvent;
|
|
37
50
|
error: Error;
|
|
38
|
-
config: SessionConfigJWE
|
|
51
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
39
52
|
}) => void | Promise<void>;
|
|
40
53
|
onError?: (args: {
|
|
41
54
|
event: HTTPEvent;
|
|
42
55
|
error: any;
|
|
43
|
-
config: SessionConfigJWE
|
|
56
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
44
57
|
}) => void | Promise<void>;
|
|
45
58
|
}
|
|
46
|
-
interface
|
|
47
|
-
readonly id: string | undefined;
|
|
48
|
-
readonly createdAt: number;
|
|
49
|
-
readonly expiresAt: number | undefined;
|
|
50
|
-
readonly data: SessionData<T>;
|
|
51
|
-
update: (update: SessionUpdate$1<T>) => Promise<SessionManager<T>>;
|
|
52
|
-
clear: () => Promise<SessionManager<T>>;
|
|
53
|
-
}
|
|
54
|
-
interface SessionConfigJWE {
|
|
59
|
+
interface SessionConfigJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
55
60
|
/** Shared secret used, string for PBES2 or Json Web Key (JWK) */
|
|
56
61
|
key: string | JWK_Symmetric | {
|
|
57
62
|
privateKey: JWK_Private | JWK_Symmetric;
|
|
58
63
|
publicKey?: JWK_Public;
|
|
59
64
|
};
|
|
60
65
|
/** Session lifetime in seconds (used to derive exp from iat) */
|
|
61
|
-
maxAge?:
|
|
66
|
+
maxAge?: MaxAge;
|
|
62
67
|
/** Default is "h3" */
|
|
63
68
|
name?: string;
|
|
64
69
|
/** Default is secure, httpOnly, path="/" */
|
|
@@ -74,75 +79,75 @@ interface SessionConfigJWE {
|
|
|
74
79
|
encryptOptions?: Omit<JWEEncryptOptions, "expiresIn">;
|
|
75
80
|
decryptOptions?: JWTClaimValidationOptions;
|
|
76
81
|
};
|
|
77
|
-
hooks?: SessionHooksJWE
|
|
82
|
+
hooks?: SessionHooksJWE<T, MaxAge>;
|
|
78
83
|
}
|
|
79
|
-
type SessionUpdate$1<T extends SessionDataT$1 = SessionDataT$1> = Partial<SessionData<T>> | ((oldData: SessionData<T>) => Partial<SessionData<T>> | undefined);
|
|
80
84
|
/**
|
|
81
85
|
* Create a session manager for the current request.
|
|
82
86
|
*/
|
|
83
|
-
declare function useJWESession<T extends
|
|
87
|
+
declare function useJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>): Promise<SessionManager<T, MaxAge>>;
|
|
84
88
|
/**
|
|
85
89
|
* Get the session for the current request.
|
|
86
90
|
*/
|
|
87
|
-
declare function getJWESession<T extends
|
|
91
|
+
declare function getJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>): Promise<SessionJWE<T, MaxAge>>;
|
|
88
92
|
/**
|
|
89
93
|
* Update the session data for the current request.
|
|
90
94
|
*/
|
|
91
|
-
declare function updateJWESession<T extends
|
|
95
|
+
declare function updateJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>, update?: SessionUpdate<T>): Promise<SessionJWE<T, MaxAge>>;
|
|
92
96
|
/**
|
|
93
97
|
* Produce a JWE for the current session.
|
|
94
98
|
*/
|
|
95
|
-
declare function sealJWESession<T extends
|
|
99
|
+
declare function sealJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>): Promise<string>;
|
|
96
100
|
/**
|
|
97
101
|
* Decrypt the JWE and return a Session-compatible object.
|
|
98
102
|
*/
|
|
99
|
-
declare function unsealJWESession(_event: HTTPEvent, config: SessionConfigJWE, sealed: string): Promise<Partial<SessionJWE
|
|
103
|
+
declare function unsealJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(_event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>, sealed: string): Promise<Partial<SessionJWE<T, MaxAge>>>;
|
|
100
104
|
/**
|
|
101
105
|
* Clear the session (delete from context and drop cookie).
|
|
102
106
|
*/
|
|
103
|
-
declare function clearJWESession(event: HTTPEvent, config: Partial<SessionConfigJWE
|
|
107
|
+
declare function clearJWESession<T extends JWTClaims, MaxAge extends number | undefined>(event: HTTPEvent, config: Partial<SessionConfigJWE<T, MaxAge>>): Promise<void>;
|
|
104
108
|
|
|
105
|
-
type SessionDataT = Omit<JWTClaims, "jti" | "iat" | "exp">;
|
|
106
109
|
declare const kGetSessionPromise: unique symbol;
|
|
107
|
-
interface SessionJWS<T extends
|
|
110
|
+
interface SessionJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
108
111
|
id: string;
|
|
109
112
|
createdAt: number;
|
|
110
|
-
expiresAt
|
|
113
|
+
expiresAt: T extends {
|
|
114
|
+
exp: number;
|
|
115
|
+
} ? number : MaxAge;
|
|
111
116
|
data: SessionData<T>;
|
|
112
|
-
[kGetSessionPromise]?: Promise<SessionJWS<T>>;
|
|
117
|
+
[kGetSessionPromise]?: Promise<SessionJWS<T, MaxAge>>;
|
|
113
118
|
}
|
|
114
|
-
interface SessionHooksJWS {
|
|
119
|
+
interface SessionHooksJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
115
120
|
onRead?: (args: {
|
|
116
|
-
session: SessionJWS
|
|
121
|
+
session: SessionJWS<T, MaxAge>;
|
|
117
122
|
event: HTTPEvent;
|
|
118
|
-
config: SessionConfigJWS
|
|
123
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
119
124
|
}) => void | Promise<void>;
|
|
120
125
|
onUpdate?: (args: {
|
|
121
|
-
session: SessionJWS
|
|
126
|
+
session: SessionJWS<T, MaxAge>;
|
|
122
127
|
event: HTTPEvent;
|
|
123
|
-
config: SessionConfigJWS
|
|
128
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
124
129
|
}) => void | Promise<void>;
|
|
125
130
|
onClear?: (args: {
|
|
126
131
|
event: HTTPEvent;
|
|
127
|
-
config: Partial<SessionConfigJWS
|
|
132
|
+
config: Partial<SessionConfigJWS<T, MaxAge>>;
|
|
128
133
|
}) => void | Promise<void>;
|
|
129
134
|
onExpire?: (args: {
|
|
130
135
|
event: HTTPEvent;
|
|
131
136
|
error: Error;
|
|
132
|
-
config: SessionConfigJWS
|
|
137
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
133
138
|
}) => void | Promise<void>;
|
|
134
139
|
onError?: (args: {
|
|
135
140
|
event: HTTPEvent;
|
|
136
141
|
error: any;
|
|
137
|
-
config: SessionConfigJWS
|
|
142
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
138
143
|
}) => void | Promise<void>;
|
|
139
144
|
}
|
|
140
|
-
interface SessionConfigJWS {
|
|
145
|
+
interface SessionConfigJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
141
146
|
key: JWK_Symmetric | {
|
|
142
147
|
privateKey: JWK_Private;
|
|
143
148
|
publicKey: JWK_Public | JWK_Public[] | JWKSet;
|
|
144
149
|
};
|
|
145
|
-
maxAge?:
|
|
150
|
+
maxAge?: MaxAge;
|
|
146
151
|
name?: string;
|
|
147
152
|
cookie?: false | (CookieSerializeOptions & {
|
|
148
153
|
chunkMaxLength?: number;
|
|
@@ -153,15 +158,14 @@ interface SessionConfigJWS {
|
|
|
153
158
|
signOptions?: Omit<JWSSignOptions, "expiresIn">;
|
|
154
159
|
verifyOptions?: JWTClaimValidationOptions;
|
|
155
160
|
};
|
|
156
|
-
hooks?: SessionHooksJWS
|
|
161
|
+
hooks?: SessionHooksJWS<T, MaxAge>;
|
|
157
162
|
}
|
|
158
|
-
|
|
159
|
-
declare function
|
|
160
|
-
declare function
|
|
161
|
-
declare function
|
|
162
|
-
declare function
|
|
163
|
-
declare function
|
|
164
|
-
declare function clearJWSSession(event: HTTPEvent, config: Partial<SessionConfigJWS>): Promise<void>;
|
|
163
|
+
declare function useJWSSession<T extends JWTClaims, MaxAge extends number | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionManager<T, MaxAge>>;
|
|
164
|
+
declare function getJWSSession<T extends JWTClaims, MaxAge extends number | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionJWS<T, MaxAge>>;
|
|
165
|
+
declare function updateJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>, update?: SessionUpdate<T>): Promise<SessionJWS<T, MaxAge>>;
|
|
166
|
+
declare function signJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<string>;
|
|
167
|
+
declare function verifyJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(_event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>, token: string): Promise<Partial<SessionJWS<T, MaxAge>>>;
|
|
168
|
+
declare function clearJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: Partial<SessionConfigJWS<T, MaxAge>>): Promise<void>;
|
|
165
169
|
|
|
166
170
|
export { JWEEncryptOptions, JWKSet, JWK_Private, JWK_Public, JWK_Symmetric, JWTClaimValidationOptions, JWTClaims, clearJWESession, clearJWSSession, getJWESession, getJWSSession, sealJWESession, signJWSSession, unsealJWESession, updateJWESession, updateJWSSession, useJWESession, useJWSSession, verifyJWSSession };
|
|
167
|
-
export type { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWS, SessionManager };
|
|
171
|
+
export type { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWS, SessionManager, SessionUpdate };
|