unjwt 0.5.24 → 0.5.25
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/h3v2.mjs +1 -97
- package/package.json +4 -4
package/dist/adapters/h3v2.mjs
CHANGED
|
@@ -1,106 +1,10 @@
|
|
|
1
1
|
export { k as deriveJWKFromPassword, h as exportJWKToPEM, c as generateJWK, f as importJWKFromPEM } from '../shared/unjwt.epPK1KFr.mjs';
|
|
2
|
-
import { getEventContext } from 'h3';
|
|
3
|
-
import { serialize, parseSetCookie, parse } from 'cookie-es';
|
|
2
|
+
import { getEventContext, getChunkedCookie, setChunkedCookie } from 'h3';
|
|
4
3
|
import { NullProtoObj } from 'rou3';
|
|
5
4
|
import { e as encrypt, d as decrypt } from '../shared/unjwt.CiBEuvtQ.mjs';
|
|
6
5
|
import { p as isSymmetricJWK, q as isPrivateJWK, u as isPublicJWK } from '../shared/unjwt.C86hA0o-.mjs';
|
|
7
6
|
import { s as sign, v as verify } from '../shared/unjwt.D-FATaw1.mjs';
|
|
8
7
|
|
|
9
|
-
const CHUNKED_COOKIE = "__chunked__";
|
|
10
|
-
const CHUNKS_MAX_LENGTH = 4e3;
|
|
11
|
-
function parseCookies(event) {
|
|
12
|
-
return parse(event.req.headers.get("cookie") || "");
|
|
13
|
-
}
|
|
14
|
-
function getCookie(event, name) {
|
|
15
|
-
return parseCookies(event)[name];
|
|
16
|
-
}
|
|
17
|
-
function setCookie(event, name, value, options) {
|
|
18
|
-
const newCookie = serialize(name, value, { path: "/", ...options });
|
|
19
|
-
const currentCookies = event.res.headers.getSetCookie();
|
|
20
|
-
if (currentCookies.length === 0) {
|
|
21
|
-
event.res.headers.set("set-cookie", newCookie);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const newCookieKey = _getDistinctCookieKey(
|
|
25
|
-
name,
|
|
26
|
-
options || {}
|
|
27
|
-
);
|
|
28
|
-
event.res.headers.delete("set-cookie");
|
|
29
|
-
for (const cookie of currentCookies) {
|
|
30
|
-
const _key = _getDistinctCookieKey(
|
|
31
|
-
cookie.split("=")[0],
|
|
32
|
-
parseSetCookie(cookie)
|
|
33
|
-
);
|
|
34
|
-
if (_key === newCookieKey) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
event.res.headers.append("set-cookie", cookie);
|
|
38
|
-
}
|
|
39
|
-
event.res.headers.append("set-cookie", newCookie);
|
|
40
|
-
}
|
|
41
|
-
function deleteCookie(event, name, serializeOptions) {
|
|
42
|
-
setCookie(event, name, "", {
|
|
43
|
-
...serializeOptions,
|
|
44
|
-
maxAge: 0
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function getChunkedCookie(event, name) {
|
|
48
|
-
const mainCookie = getCookie(event, name);
|
|
49
|
-
if (!mainCookie || !mainCookie.startsWith(CHUNKED_COOKIE)) {
|
|
50
|
-
return mainCookie;
|
|
51
|
-
}
|
|
52
|
-
const chunksCount = getChunkedCookieCount(mainCookie);
|
|
53
|
-
if (chunksCount === 0) {
|
|
54
|
-
return void 0;
|
|
55
|
-
}
|
|
56
|
-
const chunks = [];
|
|
57
|
-
for (let i = 1; i <= chunksCount; i++) {
|
|
58
|
-
const chunk = getCookie(event, chunkCookieName(name, i));
|
|
59
|
-
if (!chunk) {
|
|
60
|
-
return void 0;
|
|
61
|
-
}
|
|
62
|
-
chunks.push(chunk);
|
|
63
|
-
}
|
|
64
|
-
return chunks.join("");
|
|
65
|
-
}
|
|
66
|
-
function setChunkedCookie(event, name, value, options) {
|
|
67
|
-
const chunkMaxLength = options?.chunkMaxLength || CHUNKS_MAX_LENGTH;
|
|
68
|
-
const chunkCount = Math.ceil(value.length / chunkMaxLength);
|
|
69
|
-
const previousCookie = getCookie(event, name);
|
|
70
|
-
if (previousCookie?.startsWith(CHUNKED_COOKIE)) {
|
|
71
|
-
const previousChunkCount = getChunkedCookieCount(previousCookie);
|
|
72
|
-
if (previousChunkCount > chunkCount) {
|
|
73
|
-
for (let i = chunkCount; i <= previousChunkCount; i++) {
|
|
74
|
-
deleteCookie(event, chunkCookieName(name, i), options);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (chunkCount <= 1) {
|
|
79
|
-
setCookie(event, name, value, options);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const mainCookieValue = `${CHUNKED_COOKIE}${chunkCount}`;
|
|
83
|
-
setCookie(event, name, mainCookieValue, options);
|
|
84
|
-
for (let i = 1; i <= chunkCount; i++) {
|
|
85
|
-
const start = (i - 1) * chunkMaxLength;
|
|
86
|
-
const end = start + chunkMaxLength;
|
|
87
|
-
const chunkValue = value.slice(start, end);
|
|
88
|
-
setCookie(event, chunkCookieName(name, i), chunkValue, options);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function _getDistinctCookieKey(name, options) {
|
|
92
|
-
return [name, options.domain || "", options.path || "/"].join(";");
|
|
93
|
-
}
|
|
94
|
-
function getChunkedCookieCount(cookie) {
|
|
95
|
-
if (!cookie?.startsWith(CHUNKED_COOKIE)) {
|
|
96
|
-
return Number.NaN;
|
|
97
|
-
}
|
|
98
|
-
return Number.parseInt(cookie.slice(CHUNKED_COOKIE.length));
|
|
99
|
-
}
|
|
100
|
-
function chunkCookieName(name, chunkNumber) {
|
|
101
|
-
return `${name}.${chunkNumber}`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
8
|
const kGetSessionPromise$1 = Symbol("h3_jwe_getSession");
|
|
105
9
|
const DEFAULT_NAME$1 = "h3-jwe";
|
|
106
10
|
const DEFAULT_COOKIE$1 = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unjwt",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.25",
|
|
4
4
|
"description": "Low-level JWT utilities",
|
|
5
5
|
"repository": "sandros94/unjwt",
|
|
6
6
|
"license": "MIT",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"eslint": "^9.36.0",
|
|
74
74
|
"eslint-config-unjs": "^0.5.0",
|
|
75
75
|
"h3v1": "npm:h3@^1.15.4",
|
|
76
|
-
"h3v2": "npm:h3@^2.0.
|
|
76
|
+
"h3v2": "npm:h3@^2.0.1-rc.2",
|
|
77
77
|
"jose": "^6.1.0",
|
|
78
78
|
"prettier": "^3.6.2",
|
|
79
79
|
"supertest": "^7.1.4",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"cookie-es": "^1.2.2 || ^2.0.0",
|
|
86
|
-
"h3": "^1.15.4 || >=2.0.
|
|
86
|
+
"h3": "^1.15.4 || >=2.0.1-rc.2 || ^2.0.1",
|
|
87
87
|
"rou3": "^0.7.7"
|
|
88
88
|
},
|
|
89
89
|
"peerDependenciesMeta": {
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"optional": true
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
|
-
"packageManager": "pnpm@10.
|
|
97
|
+
"packageManager": "pnpm@10.18.3"
|
|
98
98
|
}
|