hono 4.3.6 → 4.3.8

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.
@@ -64,23 +64,7 @@ var EventProcessor = class {
64
64
  const path = this.getPath(event);
65
65
  const urlPath = `https://${domainName}${path}`;
66
66
  const url = queryString ? `${urlPath}?${queryString}` : urlPath;
67
- const headers = new Headers();
68
- this.getCookies(event, headers);
69
- if (event.headers) {
70
- for (const [k, v] of Object.entries(event.headers)) {
71
- if (v) {
72
- headers.set(k, v);
73
- }
74
- }
75
- }
76
- if (event.multiValueHeaders) {
77
- for (const [k, values] of Object.entries(event.multiValueHeaders)) {
78
- if (values) {
79
- const foundK = headers.get(k);
80
- values.forEach((v) => (!foundK || !foundK.includes(v)) && headers.append(k, v));
81
- }
82
- }
83
- }
67
+ const headers = this.getHeaders(event);
84
68
  const method = this.getMethod(event);
85
69
  const requestInit = {
86
70
  headers,
@@ -102,24 +86,28 @@ var EventProcessor = class {
102
86
  const result = {
103
87
  body,
104
88
  headers: {},
89
+ multiValueHeaders: event.multiValueHeaders ? {} : void 0,
105
90
  statusCode: res.status,
106
91
  isBase64Encoded
107
92
  };
108
93
  this.setCookies(event, res, result);
109
94
  res.headers.forEach((value, key) => {
110
95
  result.headers[key] = value;
96
+ if (event.multiValueHeaders && result.multiValueHeaders) {
97
+ result.multiValueHeaders[key] = [value];
98
+ }
111
99
  });
112
100
  return result;
113
101
  }
114
- setCookies = (event, res, result) => {
102
+ setCookies(event, res, result) {
115
103
  if (res.headers.has("set-cookie")) {
116
104
  const cookies = res.headers.get("set-cookie")?.split(", ");
117
105
  if (Array.isArray(cookies)) {
118
- this.setCookiesToResult(result, cookies);
106
+ this.setCookiesToResult(event, result, cookies);
119
107
  res.headers.delete("set-cookie");
120
108
  }
121
109
  }
122
- };
110
+ }
123
111
  };
124
112
  var v2Processor = new class EventV2Processor extends EventProcessor {
125
113
  getPath(event) {
@@ -136,9 +124,21 @@ var v2Processor = new class EventV2Processor extends EventProcessor {
136
124
  headers.set("Cookie", event.cookies.join("; "));
137
125
  }
138
126
  }
139
- setCookiesToResult(result, cookies) {
127
+ setCookiesToResult(_, result, cookies) {
140
128
  result.cookies = cookies;
141
129
  }
130
+ getHeaders(event) {
131
+ const headers = new Headers();
132
+ this.getCookies(event, headers);
133
+ if (event.headers) {
134
+ for (const [k, v] of Object.entries(event.headers)) {
135
+ if (v) {
136
+ headers.set(k, v);
137
+ }
138
+ }
139
+ }
140
+ return headers;
141
+ }
142
142
  }();
143
143
  var v1Processor = new class EventV1Processor extends EventProcessor {
144
144
  getPath(event) {
@@ -152,18 +152,104 @@ var v1Processor = new class EventV1Processor extends EventProcessor {
152
152
  }
153
153
  getCookies(event, headers) {
154
154
  }
155
- setCookiesToResult(result, cookies) {
155
+ getHeaders(event) {
156
+ const headers = new Headers();
157
+ this.getCookies(event, headers);
158
+ if (event.headers) {
159
+ for (const [k, v] of Object.entries(event.headers)) {
160
+ if (v) {
161
+ headers.set(k, v);
162
+ }
163
+ }
164
+ }
165
+ if (event.multiValueHeaders) {
166
+ for (const [k, values] of Object.entries(event.multiValueHeaders)) {
167
+ if (values) {
168
+ const foundK = headers.get(k);
169
+ values.forEach((v) => (!foundK || !foundK.includes(v)) && headers.append(k, v));
170
+ }
171
+ }
172
+ }
173
+ return headers;
174
+ }
175
+ setCookiesToResult(_, result, cookies) {
156
176
  result.multiValueHeaders = {
157
177
  "set-cookie": cookies
158
178
  };
159
179
  }
160
180
  }();
181
+ var albProcessor = new class ALBProcessor extends EventProcessor {
182
+ getHeaders(event) {
183
+ const headers = new Headers();
184
+ if (event.multiValueHeaders) {
185
+ for (const [key, values] of Object.entries(event.multiValueHeaders)) {
186
+ if (values && Array.isArray(values)) {
187
+ headers.set(key, values.join("; "));
188
+ }
189
+ }
190
+ } else {
191
+ for (const [key, value] of Object.entries(event.headers ?? {})) {
192
+ if (value) {
193
+ headers.set(key, value);
194
+ }
195
+ }
196
+ }
197
+ return headers;
198
+ }
199
+ setHeadersToResult(event, result, headers) {
200
+ if (event.multiValueHeaders) {
201
+ const multiValueHeaders = {};
202
+ for (const [key, value] of headers.entries()) {
203
+ multiValueHeaders[key] = [value];
204
+ }
205
+ result.multiValueHeaders = multiValueHeaders;
206
+ } else {
207
+ const singleValueHeaders = {};
208
+ for (const [key, value] of headers.entries()) {
209
+ singleValueHeaders[key] = value;
210
+ }
211
+ result.headers = singleValueHeaders;
212
+ }
213
+ }
214
+ getPath(event) {
215
+ return event.path;
216
+ }
217
+ getMethod(event) {
218
+ return event.httpMethod;
219
+ }
220
+ getQueryString(event) {
221
+ return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
222
+ }
223
+ getCookies(event, headers) {
224
+ let cookie;
225
+ if (event.multiValueHeaders) {
226
+ cookie = event.multiValueHeaders["cookie"]?.join("; ");
227
+ } else {
228
+ cookie = event.headers ? event.headers["cookie"] : void 0;
229
+ }
230
+ if (cookie) {
231
+ headers.append("Cookie", cookie);
232
+ }
233
+ }
234
+ setCookiesToResult(event, result, cookies) {
235
+ if (event.multiValueHeaders && result.multiValueHeaders) {
236
+ result.multiValueHeaders["set-cookie"] = cookies;
237
+ } else {
238
+ result.headers["set-cookie"] = cookies.join(", ");
239
+ }
240
+ }
241
+ }();
161
242
  var getProcessor = (event) => {
243
+ if (isProxyEventALB(event)) {
244
+ return albProcessor;
245
+ }
162
246
  if (isProxyEventV2(event)) {
163
247
  return v2Processor;
164
- } else {
165
- return v1Processor;
166
248
  }
249
+ return v1Processor;
250
+ };
251
+ var isProxyEventALB = (event) => {
252
+ return Object.prototype.hasOwnProperty.call(event.requestContext, "elb");
167
253
  };
168
254
  var isProxyEventV2 = (event) => {
169
255
  return Object.prototype.hasOwnProperty.call(event, "rawPath");
@@ -96,23 +96,7 @@ class EventProcessor {
96
96
  const path = this.getPath(event);
97
97
  const urlPath = `https://${domainName}${path}`;
98
98
  const url = queryString ? `${urlPath}?${queryString}` : urlPath;
99
- const headers = new Headers();
100
- this.getCookies(event, headers);
101
- if (event.headers) {
102
- for (const [k, v] of Object.entries(event.headers)) {
103
- if (v) {
104
- headers.set(k, v);
105
- }
106
- }
107
- }
108
- if (event.multiValueHeaders) {
109
- for (const [k, values] of Object.entries(event.multiValueHeaders)) {
110
- if (values) {
111
- const foundK = headers.get(k);
112
- values.forEach((v) => (!foundK || !foundK.includes(v)) && headers.append(k, v));
113
- }
114
- }
115
- }
99
+ const headers = this.getHeaders(event);
116
100
  const method = this.getMethod(event);
117
101
  const requestInit = {
118
102
  headers,
@@ -134,24 +118,28 @@ class EventProcessor {
134
118
  const result = {
135
119
  body,
136
120
  headers: {},
121
+ multiValueHeaders: event.multiValueHeaders ? {} : void 0,
137
122
  statusCode: res.status,
138
123
  isBase64Encoded
139
124
  };
140
125
  this.setCookies(event, res, result);
141
126
  res.headers.forEach((value, key) => {
142
127
  result.headers[key] = value;
128
+ if (event.multiValueHeaders && result.multiValueHeaders) {
129
+ result.multiValueHeaders[key] = [value];
130
+ }
143
131
  });
144
132
  return result;
145
133
  }
146
- setCookies = (event, res, result) => {
134
+ setCookies(event, res, result) {
147
135
  if (res.headers.has("set-cookie")) {
148
136
  const cookies = res.headers.get("set-cookie")?.split(", ");
149
137
  if (Array.isArray(cookies)) {
150
- this.setCookiesToResult(result, cookies);
138
+ this.setCookiesToResult(event, result, cookies);
151
139
  res.headers.delete("set-cookie");
152
140
  }
153
141
  }
154
- };
142
+ }
155
143
  }
156
144
  const v2Processor = new class EventV2Processor extends EventProcessor {
157
145
  getPath(event) {
@@ -168,9 +156,21 @@ const v2Processor = new class EventV2Processor extends EventProcessor {
168
156
  headers.set("Cookie", event.cookies.join("; "));
169
157
  }
170
158
  }
171
- setCookiesToResult(result, cookies) {
159
+ setCookiesToResult(_, result, cookies) {
172
160
  result.cookies = cookies;
173
161
  }
162
+ getHeaders(event) {
163
+ const headers = new Headers();
164
+ this.getCookies(event, headers);
165
+ if (event.headers) {
166
+ for (const [k, v] of Object.entries(event.headers)) {
167
+ if (v) {
168
+ headers.set(k, v);
169
+ }
170
+ }
171
+ }
172
+ return headers;
173
+ }
174
174
  }();
175
175
  const v1Processor = new class EventV1Processor extends EventProcessor {
176
176
  getPath(event) {
@@ -184,18 +184,104 @@ const v1Processor = new class EventV1Processor extends EventProcessor {
184
184
  }
185
185
  getCookies(event, headers) {
186
186
  }
187
- setCookiesToResult(result, cookies) {
187
+ getHeaders(event) {
188
+ const headers = new Headers();
189
+ this.getCookies(event, headers);
190
+ if (event.headers) {
191
+ for (const [k, v] of Object.entries(event.headers)) {
192
+ if (v) {
193
+ headers.set(k, v);
194
+ }
195
+ }
196
+ }
197
+ if (event.multiValueHeaders) {
198
+ for (const [k, values] of Object.entries(event.multiValueHeaders)) {
199
+ if (values) {
200
+ const foundK = headers.get(k);
201
+ values.forEach((v) => (!foundK || !foundK.includes(v)) && headers.append(k, v));
202
+ }
203
+ }
204
+ }
205
+ return headers;
206
+ }
207
+ setCookiesToResult(_, result, cookies) {
188
208
  result.multiValueHeaders = {
189
209
  "set-cookie": cookies
190
210
  };
191
211
  }
192
212
  }();
213
+ const albProcessor = new class ALBProcessor extends EventProcessor {
214
+ getHeaders(event) {
215
+ const headers = new Headers();
216
+ if (event.multiValueHeaders) {
217
+ for (const [key, values] of Object.entries(event.multiValueHeaders)) {
218
+ if (values && Array.isArray(values)) {
219
+ headers.set(key, values.join("; "));
220
+ }
221
+ }
222
+ } else {
223
+ for (const [key, value] of Object.entries(event.headers ?? {})) {
224
+ if (value) {
225
+ headers.set(key, value);
226
+ }
227
+ }
228
+ }
229
+ return headers;
230
+ }
231
+ setHeadersToResult(event, result, headers) {
232
+ if (event.multiValueHeaders) {
233
+ const multiValueHeaders = {};
234
+ for (const [key, value] of headers.entries()) {
235
+ multiValueHeaders[key] = [value];
236
+ }
237
+ result.multiValueHeaders = multiValueHeaders;
238
+ } else {
239
+ const singleValueHeaders = {};
240
+ for (const [key, value] of headers.entries()) {
241
+ singleValueHeaders[key] = value;
242
+ }
243
+ result.headers = singleValueHeaders;
244
+ }
245
+ }
246
+ getPath(event) {
247
+ return event.path;
248
+ }
249
+ getMethod(event) {
250
+ return event.httpMethod;
251
+ }
252
+ getQueryString(event) {
253
+ return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
254
+ }
255
+ getCookies(event, headers) {
256
+ let cookie;
257
+ if (event.multiValueHeaders) {
258
+ cookie = event.multiValueHeaders["cookie"]?.join("; ");
259
+ } else {
260
+ cookie = event.headers ? event.headers["cookie"] : void 0;
261
+ }
262
+ if (cookie) {
263
+ headers.append("Cookie", cookie);
264
+ }
265
+ }
266
+ setCookiesToResult(event, result, cookies) {
267
+ if (event.multiValueHeaders && result.multiValueHeaders) {
268
+ result.multiValueHeaders["set-cookie"] = cookies;
269
+ } else {
270
+ result.headers["set-cookie"] = cookies.join(", ");
271
+ }
272
+ }
273
+ }();
193
274
  const getProcessor = (event) => {
275
+ if (isProxyEventALB(event)) {
276
+ return albProcessor;
277
+ }
194
278
  if (isProxyEventV2(event)) {
195
279
  return v2Processor;
196
- } else {
197
- return v1Processor;
198
280
  }
281
+ return v1Processor;
282
+ };
283
+ const isProxyEventALB = (event) => {
284
+ return Object.prototype.hasOwnProperty.call(event.requestContext, "elb");
199
285
  };
200
286
  const isProxyEventV2 = (event) => {
201
287
  return Object.prototype.hasOwnProperty.call(event, "rawPath");
@@ -155,7 +155,11 @@ class Context {
155
155
  const header = new Headers(arg.headers);
156
156
  if (this.#headers) {
157
157
  this.#headers.forEach((v, k) => {
158
- header.set(k, v);
158
+ if (k === "set-cookie") {
159
+ header.append(k, v);
160
+ } else {
161
+ header.set(k, v);
162
+ }
159
163
  });
160
164
  }
161
165
  const headers2 = setHeaders(header, this.#preparedHeaders);
@@ -30,6 +30,7 @@ var import_mime = require("../../utils/mime");
30
30
  var import_middleware = require("./middleware");
31
31
  var import_utils2 = require("./utils");
32
32
  const DEFAULT_CONCURRENCY = 2;
33
+ const DEFAULT_CONTENT_TYPE = "text/plain";
33
34
  const generateFilePath = (routePath, outDir, mimeType, extensionMap) => {
34
35
  const extension = determineExtension(mimeType, extensionMap);
35
36
  if (routePath.endsWith(`.${extension}`)) {
@@ -121,7 +122,7 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
121
122
  }
122
123
  response = maybeResponse;
123
124
  }
124
- const mimeType = response.headers.get("Content-Type")?.split(";")[0] || "text/plain";
125
+ const mimeType = response.headers.get("Content-Type")?.split(";")[0] || DEFAULT_CONTENT_TYPE;
125
126
  const content = await parseResponseContent(response);
126
127
  resolveReq({
127
128
  routePath: replacedUrlParam,
@@ -21,7 +21,6 @@ __export(method_override_exports, {
21
21
  methodOverride: () => methodOverride
22
22
  });
23
23
  module.exports = __toCommonJS(method_override_exports);
24
- var import_url = require("url");
25
24
  var import_body = require("../../utils/body");
26
25
  const DEFAULT_METHOD_FORM_NAME = "_method";
27
26
  const methodOverride = (options) => async function methodOverride2(c, next) {
@@ -56,7 +55,7 @@ const methodOverride = (options) => async function methodOverride2(c, next) {
56
55
  const method = params[methodFormName];
57
56
  if (method) {
58
57
  delete params[methodFormName];
59
- const newParams = new import_url.URLSearchParams(params);
58
+ const newParams = new URLSearchParams(params);
60
59
  const request = new Request(newRequest, {
61
60
  body: newParams,
62
61
  method
@@ -134,7 +134,7 @@ const _serialize = (name, value, opt = {}) => {
134
134
  cookie += "; Secure";
135
135
  }
136
136
  if (opt.sameSite) {
137
- cookie += `; SameSite=${opt.sameSite}`;
137
+ cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
138
138
  }
139
139
  if (opt.partitioned) {
140
140
  if (!opt.secure) {
@@ -34,7 +34,11 @@ const encodeJwtPart = (part) => (0, import_encode.encodeBase64Url)(import_utf8.u
34
34
  const encodeSignaturePart = (buf) => (0, import_encode.encodeBase64Url)(buf).replace(/=/g, "");
35
35
  const decodeJwtPart = (part) => JSON.parse(import_utf8.utf8Decoder.decode((0, import_encode.decodeBase64Url)(part)));
36
36
  function isTokenHeader(obj) {
37
- return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(import_jwa.AlgorithmTypes).includes(obj.alg) && (!("typ" in obj) || obj.typ === "JWT");
37
+ if (typeof obj === "object" && obj !== null) {
38
+ const objWithAlg = obj;
39
+ return "alg" in objWithAlg && Object.values(import_jwa.AlgorithmTypes).includes(objWithAlg.alg) && (!("typ" in objWithAlg) || objWithAlg.typ === "JWT");
40
+ }
41
+ return false;
38
42
  }
39
43
  const sign = async (payload, privateKey, alg = "HS256") => {
40
44
  const encodedPayload = encodeJwtPart(payload);
package/dist/context.js CHANGED
@@ -132,7 +132,11 @@ var Context = class {
132
132
  const header = new Headers(arg.headers);
133
133
  if (this.#headers) {
134
134
  this.#headers.forEach((v, k) => {
135
- header.set(k, v);
135
+ if (k === "set-cookie") {
136
+ header.append(k, v);
137
+ } else {
138
+ header.set(k, v);
139
+ }
136
140
  });
137
141
  }
138
142
  const headers2 = setHeaders(header, this.#preparedHeaders);
@@ -5,6 +5,7 @@ import { getExtension } from "../../utils/mime.js";
5
5
  import { X_HONO_DISABLE_SSG_HEADER_KEY, SSG_CONTEXT } from "./middleware.js";
6
6
  import { joinPaths, dirname, filterStaticGenerateRoutes } from "./utils.js";
7
7
  var DEFAULT_CONCURRENCY = 2;
8
+ var DEFAULT_CONTENT_TYPE = "text/plain";
8
9
  var generateFilePath = (routePath, outDir, mimeType, extensionMap) => {
9
10
  const extension = determineExtension(mimeType, extensionMap);
10
11
  if (routePath.endsWith(`.${extension}`)) {
@@ -96,7 +97,7 @@ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, c
96
97
  }
97
98
  response = maybeResponse;
98
99
  }
99
- const mimeType = response.headers.get("Content-Type")?.split(";")[0] || "text/plain";
100
+ const mimeType = response.headers.get("Content-Type")?.split(";")[0] || DEFAULT_CONTENT_TYPE;
100
101
  const content = await parseResponseContent(response);
101
102
  resolveReq({
102
103
  routePath: replacedUrlParam,
@@ -1,5 +1,4 @@
1
1
  // src/middleware/method-override/index.ts
2
- import { URLSearchParams } from "url";
3
2
  import { parseBody } from "../../utils/body.js";
4
3
  var DEFAULT_METHOD_FORM_NAME = "_method";
5
4
  var methodOverride = (options) => async function methodOverride2(c, next) {
@@ -73,11 +73,12 @@ declare abstract class EventProcessor<E extends LambdaEvent> {
73
73
  protected abstract getPath(event: E): string;
74
74
  protected abstract getMethod(event: E): string;
75
75
  protected abstract getQueryString(event: E): string;
76
+ protected abstract getHeaders(event: E): Headers;
76
77
  protected abstract getCookies(event: E, headers: Headers): void;
77
- protected abstract setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
78
+ protected abstract setCookiesToResult(event: E, result: APIGatewayProxyResult, cookies: string[]): void;
78
79
  createRequest(event: E): Request;
79
80
  createResult(event: E, res: Response): Promise<APIGatewayProxyResult>;
80
- setCookies: (event: LambdaEvent, res: Response, result: APIGatewayProxyResult) => void;
81
+ setCookies(event: E, res: Response, result: APIGatewayProxyResult): void;
81
82
  }
82
83
  export declare const getProcessor: (event: LambdaEvent) => EventProcessor<LambdaEvent>;
83
84
  export declare const isContentTypeBinary: (contentType: string) => boolean;
@@ -1,7 +1,7 @@
1
1
  import type { HonoRequest } from './request';
2
2
  import type { Env, FetchEventLike, Input, NotFoundHandler, TypedResponse } from './types';
3
3
  import type { RedirectStatusCode, StatusCode } from './utils/http-status';
4
- import type { JSONValue, JSONParsed, IsAny, Simplify } from './utils/types';
4
+ import type { IsAny, JSONParsed, JSONValue, Simplify } from './utils/types';
5
5
  type HeaderRecord = Record<string, string | string[]>;
6
6
  export type Data = string | ArrayBuffer | ReadableStream;
7
7
  export interface ExecutionContext {
@@ -31,8 +31,8 @@ declare const _default: {
31
31
  useId: () => string;
32
32
  useDebugValue: (_value: unknown, _formatter?: ((value: unknown) => string) | undefined) => void;
33
33
  createRef: <T_8>() => import("../hooks").RefObject<T_8>;
34
- forwardRef: <T_9, P = {}>(Component: (props: P, ref: import("../hooks").RefObject<T_9>) => JSX.Element) => (props: P & {
35
- ref: import("../hooks").RefObject<T_9>;
34
+ forwardRef: <T_9, P = {}>(Component: (props: P, ref?: import("../hooks").RefObject<T_9> | undefined) => JSX.Element) => (props: P & {
35
+ ref?: import("../hooks").RefObject<T_9> | undefined;
36
36
  }) => JSX.Element;
37
37
  useImperativeHandle: <T_10>(ref: import("../hooks").RefObject<T_10>, createHandle: () => T_10, deps: readonly unknown[]) => void;
38
38
  useSyncExternalStore: <T_11>(subscribe: (callback: (value: T_11) => void) => () => void, getSnapshot: () => T_11, getServerSnapshot?: (() => T_11) | undefined) => T_11;
@@ -32,8 +32,8 @@ export declare const useMemo: <T>(factory: () => T, deps: readonly unknown[]) =>
32
32
  export declare const useId: () => string;
33
33
  export declare const useDebugValue: (_value: unknown, _formatter?: ((value: unknown) => string) | undefined) => void;
34
34
  export declare const createRef: <T>() => RefObject<T>;
35
- export declare const forwardRef: <T, P = {}>(Component: (props: P, ref: RefObject<T>) => JSX.Element) => (props: P & {
36
- ref: RefObject<T>;
35
+ export declare const forwardRef: <T, P = {}>(Component: (props: P, ref?: RefObject<T> | undefined) => JSX.Element) => (props: P & {
36
+ ref?: RefObject<T> | undefined;
37
37
  }) => JSX.Element;
38
38
  export declare const useImperativeHandle: <T>(ref: RefObject<T>, createHandle: () => T, deps: readonly unknown[]) => void;
39
39
  export declare const useSyncExternalStore: <T>(subscribe: (callback: (value: T) => void) => () => void, getSnapshot: () => T, getServerSnapshot?: (() => T) | undefined) => T;
@@ -41,8 +41,8 @@ declare const _default: {
41
41
  useMemo: <T_11>(factory: () => T_11, deps: readonly unknown[]) => T_11;
42
42
  useLayoutEffect: (effect: () => void | (() => void), deps?: readonly unknown[] | undefined) => void;
43
43
  createRef: <T_12>() => import("./hooks").RefObject<T_12>;
44
- forwardRef: <T_13, P = {}>(Component: (props: P, ref: import("./hooks").RefObject<T_13>) => JSX.Element) => (props: P & {
45
- ref: import("./hooks").RefObject<T_13>;
44
+ forwardRef: <T_13, P = {}>(Component: (props: P, ref?: import("./hooks").RefObject<T_13> | undefined) => JSX.Element) => (props: P & {
45
+ ref?: import("./hooks").RefObject<T_13> | undefined;
46
46
  }) => JSX.Element;
47
47
  useImperativeHandle: <T_14>(ref: import("./hooks").RefObject<T_14>, createHandle: () => T_14, deps: readonly unknown[]) => void;
48
48
  useSyncExternalStore: <T_15>(subscribe: (callback: (value: T_15) => void) => () => void, getSnapshot: () => T_15, getServerSnapshot?: (() => T_15) | undefined) => T_15;
@@ -11,9 +11,9 @@ export declare const jwt: (options: {
11
11
  cookie?: string;
12
12
  alg?: SignatureAlgorithm;
13
13
  }) => MiddlewareHandler;
14
- export declare const verify: (token: string, publicKey: import("../../utils/jwt/jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<any>;
14
+ export declare const verify: (token: string, publicKey: import("../../utils/jwt/jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<import("../../utils/jwt/types").JWTPayload>;
15
15
  export declare const decode: (token: string) => {
16
- header: any;
17
- payload: any;
16
+ header: import("../../utils/jwt/jwt").TokenHeader;
17
+ payload: import("../../utils/jwt/types").JWTPayload;
18
18
  };
19
19
  export declare const sign: (payload: import("../../utils/jwt/types").JWTPayload, privateKey: import("../../utils/jwt/jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<string>;
@@ -49,7 +49,7 @@ interface SecureHeadersOptions {
49
49
  crossOriginEmbedderPolicy?: overridableHeader;
50
50
  crossOriginResourcePolicy?: overridableHeader;
51
51
  crossOriginOpenerPolicy?: overridableHeader;
52
- originAgentCluster: overridableHeader;
52
+ originAgentCluster?: overridableHeader;
53
53
  referrerPolicy?: overridableHeader;
54
54
  reportingEndpoints?: ReportingEndpointOptions[];
55
55
  reportTo?: ReportToOptions[];
@@ -62,5 +62,5 @@ interface SecureHeadersOptions {
62
62
  xXssProtection?: overridableHeader;
63
63
  }
64
64
  export declare const NONCE: ContentSecurityPolicyOptionHandler;
65
- export declare const secureHeaders: (customOptions?: Partial<SecureHeadersOptions>) => MiddlewareHandler;
65
+ export declare const secureHeaders: (customOptions?: SecureHeadersOptions) => MiddlewareHandler;
66
66
  export {};
@@ -14,13 +14,13 @@ interface Timer {
14
14
  start: number;
15
15
  }
16
16
  interface TimingOptions {
17
- total: boolean;
18
- enabled: boolean | ((c: Context) => boolean);
19
- totalDescription: string;
20
- autoEnd: boolean;
21
- crossOrigin: boolean | string | ((c: Context) => boolean | string);
17
+ total?: boolean;
18
+ enabled?: boolean | ((c: Context) => boolean);
19
+ totalDescription?: string;
20
+ autoEnd?: boolean;
21
+ crossOrigin?: boolean | string | ((c: Context) => boolean | string);
22
22
  }
23
- export declare const timing: (config?: Partial<TimingOptions>) => MiddlewareHandler;
23
+ export declare const timing: (config?: TimingOptions) => MiddlewareHandler;
24
24
  interface SetMetric {
25
25
  (c: Context, name: string, value: number, description?: string, precision?: number): void;
26
26
  (c: Context, name: string, description?: string): void;
@@ -23,7 +23,7 @@ export type CookieOptions = {
23
23
  path?: string;
24
24
  secure?: boolean;
25
25
  signingSecret?: string;
26
- sameSite?: 'Strict' | 'Lax' | 'None';
26
+ sameSite?: 'Strict' | 'Lax' | 'None' | 'strict' | 'lax' | 'none';
27
27
  partitioned?: boolean;
28
28
  prefix?: CookiePrefixOptions;
29
29
  } & PartitionCookieConstraint;
@@ -1,8 +1,8 @@
1
1
  export declare const Jwt: {
2
2
  sign: (payload: import("./types").JWTPayload, privateKey: import("./jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<string>;
3
- verify: (token: string, publicKey: import("./jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<any>;
3
+ verify: (token: string, publicKey: import("./jws").SignatureKey, alg?: "HS256" | "HS384" | "HS512" | "RS256" | "RS384" | "RS512" | "PS256" | "PS384" | "PS512" | "ES256" | "ES384" | "ES512" | "EdDSA") => Promise<import("./types").JWTPayload>;
4
4
  decode: (token: string) => {
5
- header: any;
6
- payload: any;
5
+ header: import("./jwt").TokenHeader;
6
+ payload: import("./types").JWTPayload;
7
7
  };
8
8
  };
@@ -1,14 +1,14 @@
1
- import type { SignatureAlgorithm } from './jwa';
2
- import type { SignatureKey } from './jws';
1
+ import { type SignatureAlgorithm } from './jwa';
2
+ import { type SignatureKey } from './jws';
3
3
  import { type JWTPayload } from './types';
4
4
  export interface TokenHeader {
5
5
  alg: SignatureAlgorithm;
6
6
  typ?: 'JWT';
7
7
  }
8
- export declare function isTokenHeader(obj: any): obj is TokenHeader;
8
+ export declare function isTokenHeader(obj: unknown): obj is TokenHeader;
9
9
  export declare const sign: (payload: JWTPayload, privateKey: SignatureKey, alg?: SignatureAlgorithm) => Promise<string>;
10
- export declare const verify: (token: string, publicKey: SignatureKey, alg?: SignatureAlgorithm) => Promise<any>;
10
+ export declare const verify: (token: string, publicKey: SignatureKey, alg?: SignatureAlgorithm) => Promise<JWTPayload>;
11
11
  export declare const decode: (token: string) => {
12
- header: any;
13
- payload: any;
12
+ header: TokenHeader;
13
+ payload: JWTPayload;
14
14
  };
@@ -32,7 +32,7 @@ export declare enum CryptoKeyUsage {
32
32
  /**
33
33
  * JWT Payload
34
34
  */
35
- export type JWTPayload = (unknown & {}) | {
35
+ export type JWTPayload = {
36
36
  [key: string]: unknown;
37
37
  /**
38
38
  * The token is checked to ensure it has not expired.
@@ -109,7 +109,7 @@ var _serialize = (name, value, opt = {}) => {
109
109
  cookie += "; Secure";
110
110
  }
111
111
  if (opt.sameSite) {
112
- cookie += `; SameSite=${opt.sameSite}`;
112
+ cookie += `; SameSite=${opt.sameSite.charAt(0).toUpperCase() + opt.sameSite.slice(1)}`;
113
113
  }
114
114
  if (opt.partitioned) {
115
115
  if (!opt.secure) {
@@ -15,7 +15,11 @@ var encodeJwtPart = (part) => encodeBase64Url(utf8Encoder.encode(JSON.stringify(
15
15
  var encodeSignaturePart = (buf) => encodeBase64Url(buf).replace(/=/g, "");
16
16
  var decodeJwtPart = (part) => JSON.parse(utf8Decoder.decode(decodeBase64Url(part)));
17
17
  function isTokenHeader(obj) {
18
- return typeof obj === "object" && obj !== null && "alg" in obj && Object.values(AlgorithmTypes).includes(obj.alg) && (!("typ" in obj) || obj.typ === "JWT");
18
+ if (typeof obj === "object" && obj !== null) {
19
+ const objWithAlg = obj;
20
+ return "alg" in objWithAlg && Object.values(AlgorithmTypes).includes(objWithAlg.alg) && (!("typ" in objWithAlg) || objWithAlg.typ === "JWT");
21
+ }
22
+ return false;
19
23
  }
20
24
  var sign = async (payload, privateKey, alg = "HS256") => {
21
25
  const encodedPayload = encodeJwtPart(payload);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.3.6",
3
+ "version": "4.3.8",
4
4
  "description": "Ultrafast web framework for the Edges",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",