elysia 2.0.0-beta.2 → 2.0.0-beta.21
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/adapter/bun/index.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
package/dist/cookie/crypto.js
CHANGED
|
@@ -10,22 +10,17 @@ const algorithm = {
|
|
|
10
10
|
};
|
|
11
11
|
const encoder = new TextEncoder();
|
|
12
12
|
let _nodeCrypto;
|
|
13
|
-
let _nodeCryptoResolved = false;
|
|
14
13
|
function nodeCrypto() {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
_nodeCrypto = globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
19
|
-
} catch {}
|
|
20
|
-
}
|
|
14
|
+
try {
|
|
15
|
+
_nodeCrypto ??= globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
16
|
+
} catch {}
|
|
21
17
|
return _nodeCrypto;
|
|
22
18
|
}
|
|
23
|
-
const HMAC_PROBE_DIGEST = "bzs6y9cVmkYub8fplSKaOuuqMqJlDwhMypFT/jSdCEk=";
|
|
24
19
|
const bunCryptoHasher = (() => {
|
|
25
20
|
const hasher = globalThis.Bun?.CryptoHasher;
|
|
26
|
-
if (typeof hasher !== "function") return void 0;
|
|
21
|
+
if (typeof hasher !== "function" || typeof hasher.prototype?.copy !== "function") return void 0;
|
|
27
22
|
try {
|
|
28
|
-
return new hasher("sha256", "elysia").update("probe").digest("base64") ===
|
|
23
|
+
return new hasher("sha256", "elysia").update("probe").digest("base64") === "bzs6y9cVmkYub8fplSKaOuuqMqJlDwhMypFT/jSdCEk=" ? hasher : void 0;
|
|
29
24
|
} catch {
|
|
30
25
|
return;
|
|
31
26
|
}
|
|
@@ -37,7 +32,15 @@ function coerceValue(val) {
|
|
|
37
32
|
if (typeof val !== "string") return val + "";
|
|
38
33
|
return val;
|
|
39
34
|
}
|
|
40
|
-
const
|
|
35
|
+
const bunHasherCache = /* @__PURE__ */ new Map();
|
|
36
|
+
const signCookieBun = (val, secret) => {
|
|
37
|
+
let keyed = bunHasherCache.get(secret);
|
|
38
|
+
if (!keyed) {
|
|
39
|
+
if (bunHasherCache.size >= 256) require_utils.evictOldestHalf(bunHasherCache);
|
|
40
|
+
bunHasherCache.set(secret, keyed = new bunCryptoHasher("sha256", secret));
|
|
41
|
+
}
|
|
42
|
+
return `${val}.${keyed.copy().update(val).digest("base64").replace(removeTrailingEquals, "")}`;
|
|
43
|
+
};
|
|
41
44
|
const signCookieNode = (val, secret) => `${val}.${nodeCrypto().createHmac("sha256", secret).update(val).digest("base64").replace(removeTrailingEquals, "")}`;
|
|
42
45
|
const signCookieSyncImpl = hmacProvider === "bun" ? signCookieBun : signCookieNode;
|
|
43
46
|
const keyCache = /* @__PURE__ */ new Map();
|
|
@@ -62,19 +65,22 @@ async function signCookieSubtle(val, secret) {
|
|
|
62
65
|
const hmacBuffer = await crypto.subtle.sign("HMAC", await importSecretKey(secret), encoder.encode(val));
|
|
63
66
|
return `${val}.${btoa(String.fromCharCode(...new Uint8Array(hmacBuffer))).replace(removeTrailingEquals, "")}`;
|
|
64
67
|
}
|
|
65
|
-
|
|
68
|
+
const deriveSignKey = (secret, name) => `${name.length}\0${name}${secret}`;
|
|
69
|
+
async function signCookie(val, secret, name) {
|
|
66
70
|
val = coerceValue(val);
|
|
67
|
-
if (secret
|
|
71
|
+
if (!secret?.trim()) throw new TypeError("Secret key must be provided");
|
|
72
|
+
if (name !== void 0) secret = deriveSignKey(secret, name);
|
|
68
73
|
if (hasSyncHmac) return signCookieSyncImpl(val, secret);
|
|
69
74
|
return signCookieSubtle(val, secret);
|
|
70
75
|
}
|
|
71
|
-
function signCookieSync(val, secret) {
|
|
76
|
+
function signCookieSync(val, secret, name) {
|
|
72
77
|
val = coerceValue(val);
|
|
73
|
-
if (secret
|
|
78
|
+
if (!secret?.trim()) throw new TypeError("Secret key must be provided");
|
|
74
79
|
if (!hasSyncHmac) throw new Error("signCookieSync called without a sync HMAC available");
|
|
80
|
+
if (name !== void 0) secret = deriveSignKey(secret, name);
|
|
75
81
|
return signCookieSyncImpl(val, secret);
|
|
76
82
|
}
|
|
77
|
-
async function unsignCookie(input, secret) {
|
|
83
|
+
async function unsignCookie(input, secret, name) {
|
|
78
84
|
if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
|
|
79
85
|
const dot = input.lastIndexOf(".");
|
|
80
86
|
if (dot === -1) {
|
|
@@ -82,10 +88,10 @@ async function unsignCookie(input, secret) {
|
|
|
82
88
|
return false;
|
|
83
89
|
}
|
|
84
90
|
const tentativeValue = input.slice(0, dot);
|
|
85
|
-
if (secret
|
|
86
|
-
return require_utils.constantTimeEqual(await signCookie(tentativeValue, secret), input) ? tentativeValue : false;
|
|
91
|
+
if (!secret?.trim()) return false;
|
|
92
|
+
return require_utils.constantTimeEqual(await signCookie(tentativeValue, secret, name), input) ? tentativeValue : false;
|
|
87
93
|
}
|
|
88
|
-
function unsignCookieSync(input, secret) {
|
|
94
|
+
function unsignCookieSync(input, secret, name) {
|
|
89
95
|
if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
|
|
90
96
|
const dot = input.lastIndexOf(".");
|
|
91
97
|
if (dot === -1) {
|
|
@@ -93,32 +99,36 @@ function unsignCookieSync(input, secret) {
|
|
|
93
99
|
return false;
|
|
94
100
|
}
|
|
95
101
|
const tentativeValue = input.slice(0, dot);
|
|
96
|
-
if (secret
|
|
97
|
-
return require_utils.constantTimeEqual(signCookieSync(tentativeValue, secret), input) ? tentativeValue : false;
|
|
102
|
+
if (!secret?.trim()) return false;
|
|
103
|
+
return require_utils.constantTimeEqual(signCookieSync(tentativeValue, secret, name), input) ? tentativeValue : false;
|
|
98
104
|
}
|
|
99
|
-
function unsignWithSecretsSync(name, value, secrets) {
|
|
105
|
+
function unsignWithSecretsSync(name, value, secrets, legacy) {
|
|
100
106
|
if (typeof value !== "string") throw require_cookie_error.InvalidCookie.signature(name);
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
108
|
+
const bound = pass === 0 ? name : void 0;
|
|
109
|
+
if (typeof secrets === "string") {
|
|
110
|
+
const temp = unsignCookieSync(value, secrets, bound);
|
|
111
|
+
if (temp !== false) return temp;
|
|
112
|
+
} else if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
|
|
113
|
+
const temp = unsignCookieSync(value, secrets[i], bound);
|
|
114
|
+
if (temp !== false) return temp;
|
|
115
|
+
}
|
|
116
|
+
if (!legacy) break;
|
|
109
117
|
}
|
|
110
118
|
throw require_cookie_error.InvalidCookie.signature(name);
|
|
111
119
|
}
|
|
112
|
-
async function unsignWithSecrets(name, value, secrets) {
|
|
120
|
+
async function unsignWithSecrets(name, value, secrets, legacy) {
|
|
113
121
|
if (typeof value !== "string") throw require_cookie_error.InvalidCookie.signature(name);
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
123
|
+
const bound = pass === 0 ? name : void 0;
|
|
124
|
+
if (typeof secrets === "string") {
|
|
125
|
+
const temp = await unsignCookie(value, secrets, bound);
|
|
126
|
+
if (temp !== false) return temp;
|
|
127
|
+
} else if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
|
|
128
|
+
const temp = await unsignCookie(value, secrets[i], bound);
|
|
129
|
+
if (temp !== false) return temp;
|
|
130
|
+
}
|
|
131
|
+
if (!legacy) break;
|
|
122
132
|
}
|
|
123
133
|
throw require_cookie_error.InvalidCookie.signature(name);
|
|
124
134
|
}
|
|
@@ -139,7 +149,7 @@ function resolvePendingCookie(entry, name) {
|
|
|
139
149
|
const value = entry.value;
|
|
140
150
|
if (typeof value !== "string") throw require_cookie_error.InvalidCookie.signature(name);
|
|
141
151
|
if (!hasSyncHmac) throw new Error(`resolvePendingCookie called without sync HMAC. Unreachable under correct lane gating (cookie: "${name}")`);
|
|
142
|
-
const resolvedValue = maybeJsonDecode(unsignWithSecretsSync(name, value, entry["~unsign"]));
|
|
152
|
+
const resolvedValue = maybeJsonDecode(unsignWithSecretsSync(name, value, entry["~unsign"], !entry["~strict"]));
|
|
143
153
|
entry.value = resolvedValue;
|
|
144
154
|
if (resolvedValue !== null && typeof resolvedValue === "object") {
|
|
145
155
|
const raw = rawJsonValue.get(resolvedValue);
|
|
@@ -149,6 +159,7 @@ function resolvePendingCookie(entry, name) {
|
|
|
149
159
|
}
|
|
150
160
|
|
|
151
161
|
//#endregion
|
|
162
|
+
exports.deriveSignKey = deriveSignKey;
|
|
152
163
|
exports.hasSyncHmac = hasSyncHmac;
|
|
153
164
|
exports.hmacProvider = hmacProvider;
|
|
154
165
|
exports.importSecretKey = importSecretKey;
|
package/dist/cookie/crypto.mjs
CHANGED
|
@@ -9,22 +9,17 @@ const algorithm = {
|
|
|
9
9
|
};
|
|
10
10
|
const encoder = new TextEncoder();
|
|
11
11
|
let _nodeCrypto;
|
|
12
|
-
let _nodeCryptoResolved = false;
|
|
13
12
|
function nodeCrypto() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
_nodeCrypto = globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
18
|
-
} catch {}
|
|
19
|
-
}
|
|
13
|
+
try {
|
|
14
|
+
_nodeCrypto ??= globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
15
|
+
} catch {}
|
|
20
16
|
return _nodeCrypto;
|
|
21
17
|
}
|
|
22
|
-
const HMAC_PROBE_DIGEST = "bzs6y9cVmkYub8fplSKaOuuqMqJlDwhMypFT/jSdCEk=";
|
|
23
18
|
const bunCryptoHasher = (() => {
|
|
24
19
|
const hasher = globalThis.Bun?.CryptoHasher;
|
|
25
|
-
if (typeof hasher !== "function") return void 0;
|
|
20
|
+
if (typeof hasher !== "function" || typeof hasher.prototype?.copy !== "function") return void 0;
|
|
26
21
|
try {
|
|
27
|
-
return new hasher("sha256", "elysia").update("probe").digest("base64") ===
|
|
22
|
+
return new hasher("sha256", "elysia").update("probe").digest("base64") === "bzs6y9cVmkYub8fplSKaOuuqMqJlDwhMypFT/jSdCEk=" ? hasher : void 0;
|
|
28
23
|
} catch {
|
|
29
24
|
return;
|
|
30
25
|
}
|
|
@@ -36,7 +31,15 @@ function coerceValue(val) {
|
|
|
36
31
|
if (typeof val !== "string") return val + "";
|
|
37
32
|
return val;
|
|
38
33
|
}
|
|
39
|
-
const
|
|
34
|
+
const bunHasherCache = /* @__PURE__ */ new Map();
|
|
35
|
+
const signCookieBun = (val, secret) => {
|
|
36
|
+
let keyed = bunHasherCache.get(secret);
|
|
37
|
+
if (!keyed) {
|
|
38
|
+
if (bunHasherCache.size >= 256) evictOldestHalf(bunHasherCache);
|
|
39
|
+
bunHasherCache.set(secret, keyed = new bunCryptoHasher("sha256", secret));
|
|
40
|
+
}
|
|
41
|
+
return `${val}.${keyed.copy().update(val).digest("base64").replace(removeTrailingEquals, "")}`;
|
|
42
|
+
};
|
|
40
43
|
const signCookieNode = (val, secret) => `${val}.${nodeCrypto().createHmac("sha256", secret).update(val).digest("base64").replace(removeTrailingEquals, "")}`;
|
|
41
44
|
const signCookieSyncImpl = hmacProvider === "bun" ? signCookieBun : signCookieNode;
|
|
42
45
|
const keyCache = /* @__PURE__ */ new Map();
|
|
@@ -61,19 +64,22 @@ async function signCookieSubtle(val, secret) {
|
|
|
61
64
|
const hmacBuffer = await crypto.subtle.sign("HMAC", await importSecretKey(secret), encoder.encode(val));
|
|
62
65
|
return `${val}.${btoa(String.fromCharCode(...new Uint8Array(hmacBuffer))).replace(removeTrailingEquals, "")}`;
|
|
63
66
|
}
|
|
64
|
-
|
|
67
|
+
const deriveSignKey = (secret, name) => `${name.length}\0${name}${secret}`;
|
|
68
|
+
async function signCookie(val, secret, name) {
|
|
65
69
|
val = coerceValue(val);
|
|
66
|
-
if (secret
|
|
70
|
+
if (!secret?.trim()) throw new TypeError("Secret key must be provided");
|
|
71
|
+
if (name !== void 0) secret = deriveSignKey(secret, name);
|
|
67
72
|
if (hasSyncHmac) return signCookieSyncImpl(val, secret);
|
|
68
73
|
return signCookieSubtle(val, secret);
|
|
69
74
|
}
|
|
70
|
-
function signCookieSync(val, secret) {
|
|
75
|
+
function signCookieSync(val, secret, name) {
|
|
71
76
|
val = coerceValue(val);
|
|
72
|
-
if (secret
|
|
77
|
+
if (!secret?.trim()) throw new TypeError("Secret key must be provided");
|
|
73
78
|
if (!hasSyncHmac) throw new Error("signCookieSync called without a sync HMAC available");
|
|
79
|
+
if (name !== void 0) secret = deriveSignKey(secret, name);
|
|
74
80
|
return signCookieSyncImpl(val, secret);
|
|
75
81
|
}
|
|
76
|
-
async function unsignCookie(input, secret) {
|
|
82
|
+
async function unsignCookie(input, secret, name) {
|
|
77
83
|
if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
|
|
78
84
|
const dot = input.lastIndexOf(".");
|
|
79
85
|
if (dot === -1) {
|
|
@@ -81,10 +87,10 @@ async function unsignCookie(input, secret) {
|
|
|
81
87
|
return false;
|
|
82
88
|
}
|
|
83
89
|
const tentativeValue = input.slice(0, dot);
|
|
84
|
-
if (secret
|
|
85
|
-
return constantTimeEqual(await signCookie(tentativeValue, secret), input) ? tentativeValue : false;
|
|
90
|
+
if (!secret?.trim()) return false;
|
|
91
|
+
return constantTimeEqual(await signCookie(tentativeValue, secret, name), input) ? tentativeValue : false;
|
|
86
92
|
}
|
|
87
|
-
function unsignCookieSync(input, secret) {
|
|
93
|
+
function unsignCookieSync(input, secret, name) {
|
|
88
94
|
if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
|
|
89
95
|
const dot = input.lastIndexOf(".");
|
|
90
96
|
if (dot === -1) {
|
|
@@ -92,32 +98,36 @@ function unsignCookieSync(input, secret) {
|
|
|
92
98
|
return false;
|
|
93
99
|
}
|
|
94
100
|
const tentativeValue = input.slice(0, dot);
|
|
95
|
-
if (secret
|
|
96
|
-
return constantTimeEqual(signCookieSync(tentativeValue, secret), input) ? tentativeValue : false;
|
|
101
|
+
if (!secret?.trim()) return false;
|
|
102
|
+
return constantTimeEqual(signCookieSync(tentativeValue, secret, name), input) ? tentativeValue : false;
|
|
97
103
|
}
|
|
98
|
-
function unsignWithSecretsSync(name, value, secrets) {
|
|
104
|
+
function unsignWithSecretsSync(name, value, secrets, legacy) {
|
|
99
105
|
if (typeof value !== "string") throw InvalidCookie.signature(name);
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
107
|
+
const bound = pass === 0 ? name : void 0;
|
|
108
|
+
if (typeof secrets === "string") {
|
|
109
|
+
const temp = unsignCookieSync(value, secrets, bound);
|
|
110
|
+
if (temp !== false) return temp;
|
|
111
|
+
} else if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
|
|
112
|
+
const temp = unsignCookieSync(value, secrets[i], bound);
|
|
113
|
+
if (temp !== false) return temp;
|
|
114
|
+
}
|
|
115
|
+
if (!legacy) break;
|
|
108
116
|
}
|
|
109
117
|
throw InvalidCookie.signature(name);
|
|
110
118
|
}
|
|
111
|
-
async function unsignWithSecrets(name, value, secrets) {
|
|
119
|
+
async function unsignWithSecrets(name, value, secrets, legacy) {
|
|
112
120
|
if (typeof value !== "string") throw InvalidCookie.signature(name);
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
for (let pass = 0; pass < 2; pass++) {
|
|
122
|
+
const bound = pass === 0 ? name : void 0;
|
|
123
|
+
if (typeof secrets === "string") {
|
|
124
|
+
const temp = await unsignCookie(value, secrets, bound);
|
|
125
|
+
if (temp !== false) return temp;
|
|
126
|
+
} else if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
|
|
127
|
+
const temp = await unsignCookie(value, secrets[i], bound);
|
|
128
|
+
if (temp !== false) return temp;
|
|
129
|
+
}
|
|
130
|
+
if (!legacy) break;
|
|
121
131
|
}
|
|
122
132
|
throw InvalidCookie.signature(name);
|
|
123
133
|
}
|
|
@@ -138,7 +148,7 @@ function resolvePendingCookie(entry, name) {
|
|
|
138
148
|
const value = entry.value;
|
|
139
149
|
if (typeof value !== "string") throw InvalidCookie.signature(name);
|
|
140
150
|
if (!hasSyncHmac) throw new Error(`resolvePendingCookie called without sync HMAC. Unreachable under correct lane gating (cookie: "${name}")`);
|
|
141
|
-
const resolvedValue = maybeJsonDecode(unsignWithSecretsSync(name, value, entry["~unsign"]));
|
|
151
|
+
const resolvedValue = maybeJsonDecode(unsignWithSecretsSync(name, value, entry["~unsign"], !entry["~strict"]));
|
|
142
152
|
entry.value = resolvedValue;
|
|
143
153
|
if (resolvedValue !== null && typeof resolvedValue === "object") {
|
|
144
154
|
const raw = rawJsonValue.get(resolvedValue);
|
|
@@ -148,4 +158,4 @@ function resolvePendingCookie(entry, name) {
|
|
|
148
158
|
}
|
|
149
159
|
|
|
150
160
|
//#endregion
|
|
151
|
-
export { hasSyncHmac, hmacProvider, importSecretKey, keyCache, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieBun, signCookieNode, signCookieSubtle, signCookieSync, signCookieSyncImpl, unsignCookie, unsignCookieSync, unsignWithSecrets, unsignWithSecretsSync };
|
|
161
|
+
export { deriveSignKey, hasSyncHmac, hmacProvider, importSecretKey, keyCache, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieBun, signCookieNode, signCookieSubtle, signCookieSync, signCookieSyncImpl, unsignCookie, unsignCookieSync, unsignWithSecrets, unsignWithSecretsSync };
|
package/dist/cookie/error.d.ts
CHANGED
|
@@ -5,8 +5,7 @@ declare class InvalidCookie extends ElysiaError {
|
|
|
5
5
|
key?: string | undefined;
|
|
6
6
|
response: string;
|
|
7
7
|
status: 400;
|
|
8
|
-
|
|
9
|
-
problemTitle: string;
|
|
8
|
+
readonly code = "invalid-cookie";
|
|
10
9
|
constructor(key?: string | undefined, response?: string, status?: number);
|
|
11
10
|
static signature(key: string): InvalidCookie;
|
|
12
11
|
static secret(key?: string): Omit<InvalidCookie, 'status'> & {
|
package/dist/cookie/error.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_universal_is_production = require('../universal/is-production.js');
|
|
2
3
|
const require_error = require('../error.js');
|
|
3
4
|
|
|
4
5
|
//#region src/cookie/error.ts
|
|
@@ -8,16 +9,17 @@ var InvalidCookie = class InvalidCookie extends require_error.ElysiaError {
|
|
|
8
9
|
this.key = key;
|
|
9
10
|
this.response = response;
|
|
10
11
|
this.status = 400;
|
|
11
|
-
this.
|
|
12
|
-
this.problemTitle = "Invalid Cookie";
|
|
12
|
+
this.code = "invalid-cookie";
|
|
13
13
|
if (status) this.status = status;
|
|
14
14
|
}
|
|
15
15
|
static signature(key) {
|
|
16
16
|
return new InvalidCookie(key, `"${key}" has invalid cookie signature`);
|
|
17
17
|
}
|
|
18
18
|
static secret(key) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const advice = `${key ? `Cookie "${key}"` : "A cookie"} is signed but \`cookie.secrets\` is missing or empty`;
|
|
20
|
+
const error = new InvalidCookie(key, require_universal_is_production.isProduction() ? "Internal Server Error" : advice, 500);
|
|
21
|
+
error.message = advice;
|
|
22
|
+
return error;
|
|
21
23
|
}
|
|
22
24
|
};
|
|
23
25
|
|
package/dist/cookie/error.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isProduction } from "../universal/is-production.mjs";
|
|
1
2
|
import { ElysiaError } from "../error.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/cookie/error.ts
|
|
@@ -7,16 +8,17 @@ var InvalidCookie = class InvalidCookie extends ElysiaError {
|
|
|
7
8
|
this.key = key;
|
|
8
9
|
this.response = response;
|
|
9
10
|
this.status = 400;
|
|
10
|
-
this.
|
|
11
|
-
this.problemTitle = "Invalid Cookie";
|
|
11
|
+
this.code = "invalid-cookie";
|
|
12
12
|
if (status) this.status = status;
|
|
13
13
|
}
|
|
14
14
|
static signature(key) {
|
|
15
15
|
return new InvalidCookie(key, `"${key}" has invalid cookie signature`);
|
|
16
16
|
}
|
|
17
17
|
static secret(key) {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const advice = `${key ? `Cookie "${key}"` : "A cookie"} is signed but \`cookie.secrets\` is missing or empty`;
|
|
19
|
+
const error = new InvalidCookie(key, isProduction() ? "Internal Server Error" : advice, 500);
|
|
20
|
+
error.message = advice;
|
|
21
|
+
return error;
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
24
|
|
package/dist/cookie/lib.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_constants = require('../constants.js');
|
|
2
3
|
const require_utils = require('../utils.js');
|
|
3
4
|
const require_cookie_error = require('./error.js');
|
|
4
5
|
|
|
@@ -21,7 +22,7 @@ function parse(str) {
|
|
|
21
22
|
while (ks < ke && ((c = str.charCodeAt(ks)) === 32 || c === 9)) ks++;
|
|
22
23
|
while (ke > ks && ((c = str.charCodeAt(ke - 1)) === 32 || c === 9)) ke--;
|
|
23
24
|
const key = str.slice(ks, ke);
|
|
24
|
-
if (obj[key] === void 0) {
|
|
25
|
+
if (obj[key] === void 0 && !require_constants.dangerousKeys.has(key)) {
|
|
25
26
|
let vs = eq + 1, ve = semi;
|
|
26
27
|
while (vs < ve && ((c = str.charCodeAt(vs)) === 32 || c === 9)) vs++;
|
|
27
28
|
while (ve > vs && ((c = str.charCodeAt(ve - 1)) === 32 || c === 9)) ve--;
|
|
@@ -40,7 +41,11 @@ function serialize(name, value = "", options) {
|
|
|
40
41
|
if (value) value = encodeURIComponent(value);
|
|
41
42
|
let str = `${name}=${value}`;
|
|
42
43
|
const maxAge = options.maxAge;
|
|
43
|
-
if (maxAge !== void 0)
|
|
44
|
+
if (maxAge !== void 0) {
|
|
45
|
+
const age = Math.floor(maxAge);
|
|
46
|
+
if (!Number.isFinite(age)) throw new require_cookie_error.InvalidCookie(`Invalid cookie Max-Age ${JSON.stringify(maxAge)}.`);
|
|
47
|
+
str += "; Max-Age=" + age;
|
|
48
|
+
}
|
|
44
49
|
const domain = options.domain;
|
|
45
50
|
if (domain) {
|
|
46
51
|
if (COOKIE_ATTR_INVALID.test(domain)) throw new require_cookie_error.InvalidCookie(`Invalid cookie Domain ${JSON.stringify(domain)}.`);
|
package/dist/cookie/lib.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { dangerousKeys } from "../constants.mjs";
|
|
1
2
|
import { nullObject } from "../utils.mjs";
|
|
2
3
|
import { InvalidCookie } from "./error.mjs";
|
|
3
4
|
|
|
@@ -20,7 +21,7 @@ function parse(str) {
|
|
|
20
21
|
while (ks < ke && ((c = str.charCodeAt(ks)) === 32 || c === 9)) ks++;
|
|
21
22
|
while (ke > ks && ((c = str.charCodeAt(ke - 1)) === 32 || c === 9)) ke--;
|
|
22
23
|
const key = str.slice(ks, ke);
|
|
23
|
-
if (obj[key] === void 0) {
|
|
24
|
+
if (obj[key] === void 0 && !dangerousKeys.has(key)) {
|
|
24
25
|
let vs = eq + 1, ve = semi;
|
|
25
26
|
while (vs < ve && ((c = str.charCodeAt(vs)) === 32 || c === 9)) vs++;
|
|
26
27
|
while (ve > vs && ((c = str.charCodeAt(ve - 1)) === 32 || c === 9)) ve--;
|
|
@@ -39,7 +40,11 @@ function serialize(name, value = "", options) {
|
|
|
39
40
|
if (value) value = encodeURIComponent(value);
|
|
40
41
|
let str = `${name}=${value}`;
|
|
41
42
|
const maxAge = options.maxAge;
|
|
42
|
-
if (maxAge !== void 0)
|
|
43
|
+
if (maxAge !== void 0) {
|
|
44
|
+
const age = Math.floor(maxAge);
|
|
45
|
+
if (!Number.isFinite(age)) throw new InvalidCookie(`Invalid cookie Max-Age ${JSON.stringify(maxAge)}.`);
|
|
46
|
+
str += "; Max-Age=" + age;
|
|
47
|
+
}
|
|
43
48
|
const domain = options.domain;
|
|
44
49
|
if (domain) {
|
|
45
50
|
if (COOKIE_ATTR_INVALID.test(domain)) throw new InvalidCookie(`Invalid cookie Domain ${JSON.stringify(domain)}.`);
|
package/dist/cookie/serialize.js
CHANGED
|
@@ -7,7 +7,7 @@ function serializeCookie(cookies) {
|
|
|
7
7
|
if (!cookies || !require_utils.isNotEmpty(cookies)) return;
|
|
8
8
|
let set;
|
|
9
9
|
let isArray = false;
|
|
10
|
-
for (const key
|
|
10
|
+
for (const key of Object.keys(cookies)) {
|
|
11
11
|
if (!key) continue;
|
|
12
12
|
const property = cookies[key];
|
|
13
13
|
if (!property) continue;
|
|
@@ -6,7 +6,7 @@ function serializeCookie(cookies) {
|
|
|
6
6
|
if (!cookies || !isNotEmpty(cookies)) return;
|
|
7
7
|
let set;
|
|
8
8
|
let isArray = false;
|
|
9
|
-
for (const key
|
|
9
|
+
for (const key of Object.keys(cookies)) {
|
|
10
10
|
if (!key) continue;
|
|
11
11
|
const property = cookies[key];
|
|
12
12
|
if (!property) continue;
|
package/dist/cookie/types.d.ts
CHANGED
|
@@ -108,6 +108,16 @@ interface CookieOptions {
|
|
|
108
108
|
* `null` in the array makes Elysia accept an unsigned cookie (intended only for a one-way unsigned→signed migration)
|
|
109
109
|
*/
|
|
110
110
|
secrets?: string | null | (string | null)[];
|
|
111
|
+
/**
|
|
112
|
+
* Only use secret for signing cookie instead of secret + seperator + name
|
|
113
|
+
*
|
|
114
|
+
* Set to `false` once every signed cookie in circulation has been re-issued
|
|
115
|
+
*
|
|
116
|
+
* Applies to the app and route level
|
|
117
|
+
*
|
|
118
|
+
* @default true
|
|
119
|
+
*/
|
|
120
|
+
legacySignature?: boolean;
|
|
111
121
|
}
|
|
112
122
|
//#endregion
|
|
113
123
|
export { BaseCookie, CookieOptions };
|
package/dist/cookie/utils.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { CookieOptions } from "./types.js";
|
|
2
1
|
import { Cookie } from "./cookie.js";
|
|
3
2
|
import { Context } from "../context.js";
|
|
4
3
|
import { CompiledCookieConfig } from "./config.js";
|
|
5
4
|
import { hasSyncHmac } from "./crypto.js";
|
|
6
5
|
|
|
7
6
|
//#region src/cookie/utils.d.ts
|
|
8
|
-
declare function
|
|
9
|
-
sign?: true | string | string[];
|
|
10
|
-
}): Promise<Record<string, Cookie<unknown>>>;
|
|
11
|
-
declare function parseCookieRawSync(cookieString: string | null | undefined, _config: CompiledCookieConfig): Record<string, unknown>;
|
|
7
|
+
declare function parseCookieRawSync(cookieString: string | null | undefined, _config: CompiledCookieConfig): any;
|
|
12
8
|
/**
|
|
13
9
|
* Unsigned + unvalidated lane only
|
|
14
10
|
*
|
|
@@ -17,9 +13,9 @@ declare function parseCookieRawSync(cookieString: string | null | undefined, _co
|
|
|
17
13
|
*/
|
|
18
14
|
declare function parseCookieRawDeferred(cookieString: string | null | undefined, _config: CompiledCookieConfig): Record<string, unknown>;
|
|
19
15
|
declare function parseCookieRawLazy(cookieString: string | null | undefined, config: CompiledCookieConfig): Record<string, unknown>;
|
|
20
|
-
declare function parseCookieRaw(cookieString: string | null | undefined, config: CompiledCookieConfig): Promise<Record<string, unknown>>;
|
|
21
|
-
declare function parseCookieRawSigned(cookieString: string | null | undefined, config: CompiledCookieConfig): Record<string, unknown>;
|
|
16
|
+
declare function parseCookieRaw(cookieString: string | null | undefined, config: CompiledCookieConfig, lazy?: 1): Promise<Record<string, unknown>>;
|
|
17
|
+
declare function parseCookieRawSigned(cookieString: string | null | undefined, config: CompiledCookieConfig, lazy?: 1): Record<string, unknown>;
|
|
22
18
|
declare function buildCookieJar(set: Context['set'], raw: Record<string, unknown>, config: CompiledCookieConfig, lazySign?: 1, deferDecode?: 1): Record<string, Cookie<unknown>>;
|
|
23
19
|
declare function signCookieValues(cookies: Context['set']['cookie'] | undefined, config: CompiledCookieConfig): Promise<void> | undefined;
|
|
24
20
|
//#endregion
|
|
25
|
-
export { buildCookieJar, hasSyncHmac,
|
|
21
|
+
export { buildCookieJar, hasSyncHmac, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues };
|