unjwt 0.5.26 → 0.5.28
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 +54 -54
- package/dist/adapters/h3v1.d.mts +1 -1
- package/dist/adapters/h3v2.d.mts +54 -54
- package/package.json +1 -1
package/dist/adapters/h3.d.mts
CHANGED
|
@@ -7,57 +7,60 @@ 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: MaxAge extends number ? number : T["exp"];
|
|
23
34
|
data: SessionData<T>;
|
|
24
|
-
[kGetSessionPromise$1]?: Promise<SessionJWE<T>>;
|
|
35
|
+
[kGetSessionPromise$1]?: Promise<SessionJWE<T, MaxAge>>;
|
|
25
36
|
}
|
|
26
|
-
interface SessionHooksJWE {
|
|
37
|
+
interface SessionHooksJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
27
38
|
onRead?: (args: {
|
|
28
|
-
session: SessionJWE
|
|
39
|
+
session: SessionJWE<T, MaxAge>;
|
|
29
40
|
event: H3Event;
|
|
30
|
-
config: SessionConfigJWE
|
|
41
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
31
42
|
}) => void | Promise<void>;
|
|
32
43
|
onUpdate?: (args: {
|
|
33
|
-
session: SessionJWE
|
|
44
|
+
session: SessionJWE<T, MaxAge>;
|
|
34
45
|
event: H3Event;
|
|
35
|
-
config: SessionConfigJWE
|
|
46
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
36
47
|
}) => void | Promise<void>;
|
|
37
48
|
onClear?: (args: {
|
|
38
49
|
event: H3Event;
|
|
39
|
-
config: Partial<SessionConfigJWE
|
|
50
|
+
config: Partial<SessionConfigJWE<T, MaxAge>>;
|
|
40
51
|
}) => void | Promise<void>;
|
|
41
52
|
onExpire?: (args: {
|
|
42
53
|
event: H3Event;
|
|
43
54
|
error: Error;
|
|
44
|
-
config: SessionConfigJWE
|
|
55
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
45
56
|
}) => void | Promise<void>;
|
|
46
57
|
onError?: (args: {
|
|
47
58
|
event: H3Event;
|
|
48
59
|
error: any;
|
|
49
|
-
config: SessionConfigJWE
|
|
60
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
50
61
|
}) => void | Promise<void>;
|
|
51
62
|
}
|
|
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 {
|
|
63
|
+
interface SessionConfigJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
61
64
|
/** @deprecated use `key` instead */
|
|
62
65
|
secret?: string | JWK_Symmetric | {
|
|
63
66
|
privateKey: JWK_Private | JWK_Symmetric;
|
|
@@ -69,7 +72,7 @@ interface SessionConfigJWE {
|
|
|
69
72
|
publicKey?: JWK_Public;
|
|
70
73
|
};
|
|
71
74
|
/** Session lifetime in seconds (used to derive exp from iat) */
|
|
72
|
-
maxAge?:
|
|
75
|
+
maxAge?: MaxAge;
|
|
73
76
|
/** Default is "h3" */
|
|
74
77
|
name?: string;
|
|
75
78
|
/** Default is secure, httpOnly, path="/" */
|
|
@@ -83,7 +86,7 @@ interface SessionConfigJWE {
|
|
|
83
86
|
encryptOptions?: Omit<JWEEncryptOptions, "expiresIn">;
|
|
84
87
|
decryptOptions?: JWTClaimValidationOptions;
|
|
85
88
|
};
|
|
86
|
-
hooks?: SessionHooksJWE
|
|
89
|
+
hooks?: SessionHooksJWE<T, MaxAge>;
|
|
87
90
|
}
|
|
88
91
|
/**
|
|
89
92
|
* @deprecated use `SessionConfigJWE` instead
|
|
@@ -98,19 +101,18 @@ type CompatEvent$1 = {
|
|
|
98
101
|
headers: Headers;
|
|
99
102
|
context: any;
|
|
100
103
|
};
|
|
101
|
-
type SessionUpdate$1<T extends SessionDataT$1 = SessionDataT$1> = Partial<SessionData<T>> | ((oldData: SessionData<T>) => Partial<SessionData<T>> | undefined);
|
|
102
104
|
/**
|
|
103
105
|
* Create a session manager for the current request.
|
|
104
106
|
*/
|
|
105
|
-
declare function useJWESession<T extends
|
|
107
|
+
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
108
|
/**
|
|
107
109
|
* Get (and lazily initialize) the session for the current request.
|
|
108
110
|
*/
|
|
109
|
-
declare function getJWESession<T extends
|
|
111
|
+
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
112
|
/**
|
|
111
113
|
* Update the session (optionally mutating the session data) and re-issue the JWE token.
|
|
112
114
|
*/
|
|
113
|
-
declare function updateJWESession<T extends
|
|
115
|
+
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
116
|
/**
|
|
115
117
|
* Produce a JWE for the current session.
|
|
116
118
|
* Payload structure:
|
|
@@ -121,15 +123,15 @@ declare function updateJWESession<T extends SessionDataT$1 = SessionDataT$1>(eve
|
|
|
121
123
|
* data: Record<string, any>;
|
|
122
124
|
* }
|
|
123
125
|
*/
|
|
124
|
-
declare function sealJWESession<T extends
|
|
126
|
+
declare function sealJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event | CompatEvent$1, config: SessionConfigJWE<T, MaxAge>): Promise<string>;
|
|
125
127
|
/**
|
|
126
128
|
* Decrypt the JWE and return a Session-compatible object.
|
|
127
129
|
*/
|
|
128
|
-
declare function unsealJWESession(_event: H3Event | CompatEvent$1, config: SessionConfigJWE, sealed: string): Promise<Partial<SessionJWE
|
|
130
|
+
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
131
|
/**
|
|
130
132
|
* Clear the session (delete from context and drop cookie).
|
|
131
133
|
*/
|
|
132
|
-
declare function clearJWESession(event: H3Event, config: Partial<SessionConfigJWE
|
|
134
|
+
declare function clearJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event, config: Partial<SessionConfigJWE<T, MaxAge>>): Promise<void>;
|
|
133
135
|
|
|
134
136
|
/**
|
|
135
137
|
* This is a fork of h3 library's session utility functions.
|
|
@@ -137,42 +139,41 @@ declare function clearJWESession(event: H3Event, config: Partial<SessionConfigJW
|
|
|
137
139
|
* @license MIT https://github.com/h3js/h3/blob/b4dce71c256911335f3402d09f30ffad120ad61a/LICENSE
|
|
138
140
|
*/
|
|
139
141
|
|
|
140
|
-
type SessionDataT = Omit<JWTClaims, "jti" | "iat" | "exp">;
|
|
141
142
|
declare const kGetSessionPromise: unique symbol;
|
|
142
|
-
interface SessionJWS<T extends
|
|
143
|
+
interface SessionJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
143
144
|
id: string;
|
|
144
145
|
createdAt: number;
|
|
145
|
-
expiresAt
|
|
146
|
+
expiresAt: MaxAge extends number ? number : T["exp"];
|
|
146
147
|
data: SessionData<T>;
|
|
147
|
-
[kGetSessionPromise]?: Promise<SessionJWS<T>>;
|
|
148
|
+
[kGetSessionPromise]?: Promise<SessionJWS<T, MaxAge>>;
|
|
148
149
|
}
|
|
149
|
-
interface SessionHooksJWS {
|
|
150
|
+
interface SessionHooksJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
150
151
|
onRead?: (args: {
|
|
151
|
-
session: SessionJWS
|
|
152
|
+
session: SessionJWS<T, MaxAge>;
|
|
152
153
|
event: H3Event;
|
|
153
|
-
config: SessionConfigJWS
|
|
154
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
154
155
|
}) => void | Promise<void>;
|
|
155
156
|
onUpdate?: (args: {
|
|
156
|
-
session: SessionJWS
|
|
157
|
+
session: SessionJWS<T, MaxAge>;
|
|
157
158
|
event: H3Event;
|
|
158
|
-
config: SessionConfigJWS
|
|
159
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
159
160
|
}) => void | Promise<void>;
|
|
160
161
|
onClear?: (args: {
|
|
161
162
|
event: H3Event;
|
|
162
|
-
config: Partial<SessionConfigJWS
|
|
163
|
+
config: Partial<SessionConfigJWS<T, MaxAge>>;
|
|
163
164
|
}) => void | Promise<void>;
|
|
164
165
|
onExpire?: (args: {
|
|
165
166
|
event: H3Event;
|
|
166
167
|
error: Error;
|
|
167
|
-
config: SessionConfigJWS
|
|
168
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
168
169
|
}) => void | Promise<void>;
|
|
169
170
|
onError?: (args: {
|
|
170
171
|
event: H3Event;
|
|
171
172
|
error: any;
|
|
172
|
-
config: SessionConfigJWS
|
|
173
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
173
174
|
}) => void | Promise<void>;
|
|
174
175
|
}
|
|
175
|
-
interface SessionConfigJWS {
|
|
176
|
+
interface SessionConfigJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
176
177
|
/**
|
|
177
178
|
* JWK (private for signing with RS/ES/PS, or symmetric oct) used for signing.
|
|
178
179
|
*/
|
|
@@ -181,7 +182,7 @@ interface SessionConfigJWS {
|
|
|
181
182
|
publicKey: JWK_Public | JWK_Public[] | JWKSet;
|
|
182
183
|
};
|
|
183
184
|
/** Session lifetime in seconds (sets exp = iat + maxAge) */
|
|
184
|
-
maxAge?:
|
|
185
|
+
maxAge?: MaxAge;
|
|
185
186
|
/** Default cookie / header name base */
|
|
186
187
|
name?: string;
|
|
187
188
|
/** Cookie options (false to disable cookies) */
|
|
@@ -195,7 +196,7 @@ interface SessionConfigJWS {
|
|
|
195
196
|
signOptions?: Omit<JWSSignOptions, "expiresIn">;
|
|
196
197
|
verifyOptions?: JWTClaimValidationOptions;
|
|
197
198
|
};
|
|
198
|
-
hooks?: SessionHooksJWS
|
|
199
|
+
hooks?: SessionHooksJWS<T, MaxAge>;
|
|
199
200
|
}
|
|
200
201
|
/**
|
|
201
202
|
* @deprecated use `SessionConfigJWS` instead
|
|
@@ -210,26 +211,25 @@ type CompatEvent = {
|
|
|
210
211
|
headers: Headers;
|
|
211
212
|
context: any;
|
|
212
213
|
};
|
|
213
|
-
type SessionUpdate<T extends SessionDataT = SessionDataT> = Partial<SessionData<T>> | ((oldData: SessionData<T>) => Partial<SessionData<T>> | undefined);
|
|
214
214
|
/**
|
|
215
215
|
* Create a session manager for the current request using JWS (signed only, not encrypted).
|
|
216
216
|
* NOTE: Contents are visible to clients (Base64URL-decoded JSON). Do not store secrets in session data.
|
|
217
217
|
*/
|
|
218
|
-
declare function useJWSSession<T extends
|
|
218
|
+
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
219
|
/**
|
|
220
220
|
* Retrieve (and lazily initialize) the session.
|
|
221
221
|
*/
|
|
222
|
-
declare function getJWSSession<T extends
|
|
222
|
+
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
223
|
/**
|
|
224
224
|
* Update session data (if provided) and reissue JWS.
|
|
225
225
|
*/
|
|
226
|
-
declare function updateJWSSession<T extends
|
|
226
|
+
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
227
|
/**
|
|
228
228
|
* Sign current session as a compact JWS.
|
|
229
229
|
* Payload claims:
|
|
230
230
|
* jti, iat, exp?, data, plus optional extraClaims (cannot override reserved)
|
|
231
231
|
*/
|
|
232
|
-
declare function signJWSSession<T extends
|
|
232
|
+
declare function signJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event | CompatEvent, config: SessionConfigJWS<T, MaxAge>): Promise<string>;
|
|
233
233
|
/**
|
|
234
234
|
* Verify and parse a compact JWS into a Session structure.
|
|
235
235
|
* Performs:
|
|
@@ -238,11 +238,11 @@ declare function signJWSSession<T extends SessionDataT = SessionDataT>(event: H3
|
|
|
238
238
|
* - ensures jti & iat presence
|
|
239
239
|
* - enforces maxAge if provided
|
|
240
240
|
*/
|
|
241
|
-
declare function verifyJWSSession(_event: H3Event | CompatEvent, config: SessionConfigJWS, token: string): Promise<Partial<SessionJWS
|
|
241
|
+
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
242
|
/**
|
|
243
243
|
* Destroy the session (context + cookie).
|
|
244
244
|
*/
|
|
245
|
-
declare function clearJWSSession(event: H3Event, config: Partial<SessionConfigJWS
|
|
245
|
+
declare function clearJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: H3Event, config: Partial<SessionConfigJWS<T, MaxAge>>): Promise<void>;
|
|
246
246
|
|
|
247
247
|
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 };
|
|
248
|
+
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,61 @@ 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: MaxAge extends number ? number : T["exp"];
|
|
17
28
|
data: SessionData<T>;
|
|
18
|
-
[kGetSessionPromise$1]?: Promise<SessionJWE<T>>;
|
|
29
|
+
[kGetSessionPromise$1]?: Promise<SessionJWE<T, MaxAge>>;
|
|
19
30
|
}
|
|
20
|
-
interface SessionHooksJWE {
|
|
31
|
+
interface SessionHooksJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
21
32
|
onRead?: (args: {
|
|
22
|
-
session: SessionJWE
|
|
33
|
+
session: SessionJWE<T, MaxAge>;
|
|
23
34
|
event: HTTPEvent;
|
|
24
|
-
config: SessionConfigJWE
|
|
35
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
25
36
|
}) => void | Promise<void>;
|
|
26
37
|
onUpdate?: (args: {
|
|
27
|
-
session: SessionJWE
|
|
38
|
+
session: SessionJWE<T, MaxAge>;
|
|
28
39
|
event: HTTPEvent;
|
|
29
|
-
config: SessionConfigJWE
|
|
40
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
30
41
|
}) => void | Promise<void>;
|
|
31
42
|
onClear?: (args: {
|
|
32
43
|
event: HTTPEvent;
|
|
33
|
-
config: Partial<SessionConfigJWE
|
|
44
|
+
config: Partial<SessionConfigJWE<T, MaxAge>>;
|
|
34
45
|
}) => void | Promise<void>;
|
|
35
46
|
onExpire?: (args: {
|
|
36
47
|
event: HTTPEvent;
|
|
37
48
|
error: Error;
|
|
38
|
-
config: SessionConfigJWE
|
|
49
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
39
50
|
}) => void | Promise<void>;
|
|
40
51
|
onError?: (args: {
|
|
41
52
|
event: HTTPEvent;
|
|
42
53
|
error: any;
|
|
43
|
-
config: SessionConfigJWE
|
|
54
|
+
config: SessionConfigJWE<T, MaxAge>;
|
|
44
55
|
}) => void | Promise<void>;
|
|
45
56
|
}
|
|
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 {
|
|
57
|
+
interface SessionConfigJWE<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
55
58
|
/** Shared secret used, string for PBES2 or Json Web Key (JWK) */
|
|
56
59
|
key: string | JWK_Symmetric | {
|
|
57
60
|
privateKey: JWK_Private | JWK_Symmetric;
|
|
58
61
|
publicKey?: JWK_Public;
|
|
59
62
|
};
|
|
60
63
|
/** Session lifetime in seconds (used to derive exp from iat) */
|
|
61
|
-
maxAge?:
|
|
64
|
+
maxAge?: MaxAge;
|
|
62
65
|
/** Default is "h3" */
|
|
63
66
|
name?: string;
|
|
64
67
|
/** Default is secure, httpOnly, path="/" */
|
|
@@ -74,75 +77,73 @@ interface SessionConfigJWE {
|
|
|
74
77
|
encryptOptions?: Omit<JWEEncryptOptions, "expiresIn">;
|
|
75
78
|
decryptOptions?: JWTClaimValidationOptions;
|
|
76
79
|
};
|
|
77
|
-
hooks?: SessionHooksJWE
|
|
80
|
+
hooks?: SessionHooksJWE<T, MaxAge>;
|
|
78
81
|
}
|
|
79
|
-
type SessionUpdate$1<T extends SessionDataT$1 = SessionDataT$1> = Partial<SessionData<T>> | ((oldData: SessionData<T>) => Partial<SessionData<T>> | undefined);
|
|
80
82
|
/**
|
|
81
83
|
* Create a session manager for the current request.
|
|
82
84
|
*/
|
|
83
|
-
declare function useJWESession<T extends
|
|
85
|
+
declare function useJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>): Promise<SessionManager<T, MaxAge>>;
|
|
84
86
|
/**
|
|
85
87
|
* Get the session for the current request.
|
|
86
88
|
*/
|
|
87
|
-
declare function getJWESession<T extends
|
|
89
|
+
declare function getJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>): Promise<SessionJWE<T, MaxAge>>;
|
|
88
90
|
/**
|
|
89
91
|
* Update the session data for the current request.
|
|
90
92
|
*/
|
|
91
|
-
declare function updateJWESession<T extends
|
|
93
|
+
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
94
|
/**
|
|
93
95
|
* Produce a JWE for the current session.
|
|
94
96
|
*/
|
|
95
|
-
declare function sealJWESession<T extends
|
|
97
|
+
declare function sealJWESession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWE<T, MaxAge>): Promise<string>;
|
|
96
98
|
/**
|
|
97
99
|
* Decrypt the JWE and return a Session-compatible object.
|
|
98
100
|
*/
|
|
99
|
-
declare function unsealJWESession(_event: HTTPEvent, config: SessionConfigJWE, sealed: string): Promise<Partial<SessionJWE
|
|
101
|
+
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
102
|
/**
|
|
101
103
|
* Clear the session (delete from context and drop cookie).
|
|
102
104
|
*/
|
|
103
|
-
declare function clearJWESession(event: HTTPEvent, config: Partial<SessionConfigJWE
|
|
105
|
+
declare function clearJWESession<T extends JWTClaims, MaxAge extends number | undefined>(event: HTTPEvent, config: Partial<SessionConfigJWE<T, MaxAge>>): Promise<void>;
|
|
104
106
|
|
|
105
|
-
type SessionDataT = Omit<JWTClaims, "jti" | "iat" | "exp">;
|
|
106
107
|
declare const kGetSessionPromise: unique symbol;
|
|
107
|
-
interface SessionJWS<T extends
|
|
108
|
+
interface SessionJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
108
109
|
id: string;
|
|
109
110
|
createdAt: number;
|
|
110
|
-
expiresAt
|
|
111
|
+
expiresAt: MaxAge extends number ? number : T["exp"];
|
|
111
112
|
data: SessionData<T>;
|
|
112
|
-
[kGetSessionPromise]?: Promise<SessionJWS<T>>;
|
|
113
|
+
[kGetSessionPromise]?: Promise<SessionJWS<T, MaxAge>>;
|
|
113
114
|
}
|
|
114
|
-
interface SessionHooksJWS {
|
|
115
|
+
interface SessionHooksJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
115
116
|
onRead?: (args: {
|
|
116
|
-
session: SessionJWS
|
|
117
|
+
session: SessionJWS<T, MaxAge>;
|
|
117
118
|
event: HTTPEvent;
|
|
118
|
-
config: SessionConfigJWS
|
|
119
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
119
120
|
}) => void | Promise<void>;
|
|
120
121
|
onUpdate?: (args: {
|
|
121
|
-
session: SessionJWS
|
|
122
|
+
session: SessionJWS<T, MaxAge>;
|
|
122
123
|
event: HTTPEvent;
|
|
123
|
-
config: SessionConfigJWS
|
|
124
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
124
125
|
}) => void | Promise<void>;
|
|
125
126
|
onClear?: (args: {
|
|
126
127
|
event: HTTPEvent;
|
|
127
|
-
config: Partial<SessionConfigJWS
|
|
128
|
+
config: Partial<SessionConfigJWS<T, MaxAge>>;
|
|
128
129
|
}) => void | Promise<void>;
|
|
129
130
|
onExpire?: (args: {
|
|
130
131
|
event: HTTPEvent;
|
|
131
132
|
error: Error;
|
|
132
|
-
config: SessionConfigJWS
|
|
133
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
133
134
|
}) => void | Promise<void>;
|
|
134
135
|
onError?: (args: {
|
|
135
136
|
event: HTTPEvent;
|
|
136
137
|
error: any;
|
|
137
|
-
config: SessionConfigJWS
|
|
138
|
+
config: SessionConfigJWS<T, MaxAge>;
|
|
138
139
|
}) => void | Promise<void>;
|
|
139
140
|
}
|
|
140
|
-
interface SessionConfigJWS {
|
|
141
|
+
interface SessionConfigJWS<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined> {
|
|
141
142
|
key: JWK_Symmetric | {
|
|
142
143
|
privateKey: JWK_Private;
|
|
143
144
|
publicKey: JWK_Public | JWK_Public[] | JWKSet;
|
|
144
145
|
};
|
|
145
|
-
maxAge?:
|
|
146
|
+
maxAge?: MaxAge;
|
|
146
147
|
name?: string;
|
|
147
148
|
cookie?: false | (CookieSerializeOptions & {
|
|
148
149
|
chunkMaxLength?: number;
|
|
@@ -153,15 +154,14 @@ interface SessionConfigJWS {
|
|
|
153
154
|
signOptions?: Omit<JWSSignOptions, "expiresIn">;
|
|
154
155
|
verifyOptions?: JWTClaimValidationOptions;
|
|
155
156
|
};
|
|
156
|
-
hooks?: SessionHooksJWS
|
|
157
|
+
hooks?: SessionHooksJWS<T, MaxAge>;
|
|
157
158
|
}
|
|
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>;
|
|
159
|
+
declare function useJWSSession<T extends JWTClaims, MaxAge extends number | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionManager<T, MaxAge>>;
|
|
160
|
+
declare function getJWSSession<T extends JWTClaims, MaxAge extends number | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<SessionJWS<T, MaxAge>>;
|
|
161
|
+
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>>;
|
|
162
|
+
declare function signJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: SessionConfigJWS<T, MaxAge>): Promise<string>;
|
|
163
|
+
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>>>;
|
|
164
|
+
declare function clearJWSSession<T extends JWTClaims = JWTClaims, MaxAge extends number | undefined = number | undefined>(event: HTTPEvent, config: Partial<SessionConfigJWS<T, MaxAge>>): Promise<void>;
|
|
165
165
|
|
|
166
166
|
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 };
|
|
167
|
+
export type { SessionConfigJWE, SessionConfigJWS, SessionData, SessionHooksJWE, SessionHooksJWS, SessionJWE, SessionJWS, SessionManager, SessionUpdate };
|