hono 4.12.31 → 4.12.33

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.
@@ -42,7 +42,7 @@ class SSEStreamingApi extends import_stream.StreamingApi {
42
42
  const sseData = [
43
43
  message.event && `event: ${message.event}`,
44
44
  dataLines,
45
- message.id && `id: ${message.id}`,
45
+ message.id !== void 0 && `id: ${message.id}`,
46
46
  message.retry !== void 0 && `retry: ${message.retry}`
47
47
  ].filter(Boolean).join("\n") + "\n\n";
48
48
  await this.write(sseData);
@@ -330,19 +330,22 @@ const useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
330
330
  }
331
331
  return getServerSnapshot();
332
332
  }
333
- const [serverSnapshotIsUsed] = useState(!!(buildData[0][4] && getServerSnapshot));
334
- const [state, setState] = useState(
335
- () => serverSnapshotIsUsed ? getServerSnapshot() : getSnapshot()
336
- );
333
+ const snapshot = buildData[0][4] && getServerSnapshot ? getServerSnapshot() : getSnapshot();
334
+ const [, setVersion] = useState(0);
335
+ const latestSnapshot = useRef([snapshot, getSnapshot]);
336
+ latestSnapshot.current = [snapshot, getSnapshot];
337
+ const unsubscribeRef = useRef(null);
337
338
  useEffect(() => {
338
- if (serverSnapshotIsUsed) {
339
- setState(getSnapshot());
339
+ const update2 = () => setVersion((version) => version + 1);
340
+ unsubscribeRef.current?.();
341
+ unsubscribeRef.current = subscribe(update2);
342
+ const [snapshot2, getSnapshot2] = latestSnapshot.current;
343
+ if (!Object.is(snapshot2, getSnapshot2())) {
344
+ update2();
340
345
  }
341
- return subscribe(() => {
342
- setState(getSnapshot());
343
- });
344
- }, []);
345
- return state;
346
+ }, [subscribe]);
347
+ useEffect(() => () => unsubscribeRef.current?.(), []);
348
+ return snapshot;
346
349
  };
347
350
  // Annotate the CommonJS export names for ESM import in node:
348
351
  0 && (module.exports = {
@@ -71,14 +71,20 @@ const secureHeaders = (customOptions) => {
71
71
  const headersToSet = getFilteredHeaders(options);
72
72
  const callbacks = [];
73
73
  if (options.contentSecurityPolicy) {
74
- const [callback, value] = getCSPDirectives(options.contentSecurityPolicy);
74
+ const [callback, value] = getCSPDirectives(
75
+ options.contentSecurityPolicy,
76
+ "Content-Security-Policy"
77
+ );
75
78
  if (callback) {
76
79
  callbacks.push(callback);
77
80
  }
78
81
  headersToSet.push(["Content-Security-Policy", value]);
79
82
  }
80
83
  if (options.contentSecurityPolicyReportOnly) {
81
- const [callback, value] = getCSPDirectives(options.contentSecurityPolicyReportOnly);
84
+ const [callback, value] = getCSPDirectives(
85
+ options.contentSecurityPolicyReportOnly,
86
+ "Content-Security-Policy-Report-Only"
87
+ );
82
88
  if (callback) {
83
89
  callbacks.push(callback);
84
90
  }
@@ -111,7 +117,7 @@ function getFilteredHeaders(options) {
111
117
  return typeof overrideValue === "string" ? [defaultValue[0], overrideValue] : defaultValue;
112
118
  });
113
119
  }
114
- function getCSPDirectives(contentSecurityPolicy) {
120
+ function getCSPDirectives(contentSecurityPolicy, headerName) {
115
121
  const callbacks = [];
116
122
  const resultValues = [];
117
123
  for (const [directive, value] of Object.entries(contentSecurityPolicy)) {
@@ -136,7 +142,7 @@ function getCSPDirectives(contentSecurityPolicy) {
136
142
  resultValues.pop();
137
143
  return callbacks.length === 0 ? [void 0, resultValues.join("")] : [
138
144
  (ctx, headersToSet) => headersToSet.map((values) => {
139
- if (values[0] === "Content-Security-Policy" || values[0] === "Content-Security-Policy-Report-Only") {
145
+ if (values[0] === headerName) {
140
146
  const clone = values[1].slice();
141
147
  callbacks.forEach((cb) => {
142
148
  cb(ctx, clone);
@@ -98,7 +98,7 @@ class HonoRequest {
98
98
  if (name) {
99
99
  return this.raw.headers.get(name) ?? void 0;
100
100
  }
101
- const headerData = {};
101
+ const headerData = /* @__PURE__ */ Object.create(null);
102
102
  this.raw.headers.forEach((value, key) => {
103
103
  headerData[key] = value;
104
104
  });
@@ -146,7 +146,7 @@ const getNextParam = (acceptHeader, startIndex) => {
146
146
  const getNextAcceptValue = (acceptHeader, startIndex) => {
147
147
  const accept = {
148
148
  type: "",
149
- params: {},
149
+ params: /* @__PURE__ */ Object.create(null),
150
150
  q: 1
151
151
  };
152
152
  startIndex = consumeWhitespace(acceptHeader, startIndex);
@@ -47,6 +47,7 @@ const verifySignature = async (base64Signature, value, secret) => {
47
47
  }
48
48
  };
49
49
  const validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
50
+ const relaxedCookieNameRegEx = /^[!#-:<>-[\]-~]+$/;
50
51
  const validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
51
52
  const trimCookieWhitespace = (value) => {
52
53
  let start = 0;
@@ -79,7 +80,7 @@ const parse = (cookie, name) => {
79
80
  continue;
80
81
  }
81
82
  const cookieName = trimCookieWhitespace(pairStr.substring(0, valueStartPos));
82
- if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName) || cookieName in parsedCookie) {
83
+ if (name && name !== cookieName || !relaxedCookieNameRegEx.test(cookieName) || cookieName in parsedCookie) {
83
84
  continue;
84
85
  }
85
86
  let cookieValue = trimCookieWhitespace(pairStr.substring(valueStartPos + 1));
@@ -192,7 +192,7 @@ const _getQueryParam = (url, key, multiple) => {
192
192
  return void 0;
193
193
  }
194
194
  }
195
- const results = {};
195
+ const results = /* @__PURE__ */ Object.create(null);
196
196
  encoded ??= /[%+]/.test(url);
197
197
  let keyIndex = url.indexOf("?", 8);
198
198
  while (keyIndex !== -1) {
@@ -20,7 +20,7 @@ var SSEStreamingApi = class extends StreamingApi {
20
20
  const sseData = [
21
21
  message.event && `event: ${message.event}`,
22
22
  dataLines,
23
- message.id && `id: ${message.id}`,
23
+ message.id !== void 0 && `id: ${message.id}`,
24
24
  message.retry !== void 0 && `retry: ${message.retry}`
25
25
  ].filter(Boolean).join("\n") + "\n\n";
26
26
  await this.write(sseData);
@@ -289,19 +289,22 @@ var useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
289
289
  }
290
290
  return getServerSnapshot();
291
291
  }
292
- const [serverSnapshotIsUsed] = useState(!!(buildData[0][4] && getServerSnapshot));
293
- const [state, setState] = useState(
294
- () => serverSnapshotIsUsed ? getServerSnapshot() : getSnapshot()
295
- );
292
+ const snapshot = buildData[0][4] && getServerSnapshot ? getServerSnapshot() : getSnapshot();
293
+ const [, setVersion] = useState(0);
294
+ const latestSnapshot = useRef([snapshot, getSnapshot]);
295
+ latestSnapshot.current = [snapshot, getSnapshot];
296
+ const unsubscribeRef = useRef(null);
296
297
  useEffect(() => {
297
- if (serverSnapshotIsUsed) {
298
- setState(getSnapshot());
298
+ const update2 = () => setVersion((version) => version + 1);
299
+ unsubscribeRef.current?.();
300
+ unsubscribeRef.current = subscribe(update2);
301
+ const [snapshot2, getSnapshot2] = latestSnapshot.current;
302
+ if (!Object.is(snapshot2, getSnapshot2())) {
303
+ update2();
299
304
  }
300
- return subscribe(() => {
301
- setState(getSnapshot());
302
- });
303
- }, []);
304
- return state;
305
+ }, [subscribe]);
306
+ useEffect(() => () => unsubscribeRef.current?.(), []);
307
+ return snapshot;
305
308
  };
306
309
  export {
307
310
  STASH_EFFECT,
@@ -49,14 +49,20 @@ var secureHeaders = (customOptions) => {
49
49
  const headersToSet = getFilteredHeaders(options);
50
50
  const callbacks = [];
51
51
  if (options.contentSecurityPolicy) {
52
- const [callback, value] = getCSPDirectives(options.contentSecurityPolicy);
52
+ const [callback, value] = getCSPDirectives(
53
+ options.contentSecurityPolicy,
54
+ "Content-Security-Policy"
55
+ );
53
56
  if (callback) {
54
57
  callbacks.push(callback);
55
58
  }
56
59
  headersToSet.push(["Content-Security-Policy", value]);
57
60
  }
58
61
  if (options.contentSecurityPolicyReportOnly) {
59
- const [callback, value] = getCSPDirectives(options.contentSecurityPolicyReportOnly);
62
+ const [callback, value] = getCSPDirectives(
63
+ options.contentSecurityPolicyReportOnly,
64
+ "Content-Security-Policy-Report-Only"
65
+ );
60
66
  if (callback) {
61
67
  callbacks.push(callback);
62
68
  }
@@ -89,7 +95,7 @@ function getFilteredHeaders(options) {
89
95
  return typeof overrideValue === "string" ? [defaultValue[0], overrideValue] : defaultValue;
90
96
  });
91
97
  }
92
- function getCSPDirectives(contentSecurityPolicy) {
98
+ function getCSPDirectives(contentSecurityPolicy, headerName) {
93
99
  const callbacks = [];
94
100
  const resultValues = [];
95
101
  for (const [directive, value] of Object.entries(contentSecurityPolicy)) {
@@ -114,7 +120,7 @@ function getCSPDirectives(contentSecurityPolicy) {
114
120
  resultValues.pop();
115
121
  return callbacks.length === 0 ? [void 0, resultValues.join("")] : [
116
122
  (ctx, headersToSet) => headersToSet.map((values) => {
117
- if (values[0] === "Content-Security-Policy" || values[0] === "Content-Security-Policy-Report-Only") {
123
+ if (values[0] === headerName) {
118
124
  const clone = values[1].slice();
119
125
  callbacks.forEach((cb) => {
120
126
  cb(ctx, clone);
package/dist/request.js CHANGED
@@ -76,7 +76,7 @@ var HonoRequest = class {
76
76
  if (name) {
77
77
  return this.raw.headers.get(name) ?? void 0;
78
78
  }
79
- const headerData = {};
79
+ const headerData = /* @__PURE__ */ Object.create(null);
80
80
  this.raw.headers.forEach((value, key) => {
81
81
  headerData[key] = value;
82
82
  });
@@ -96,6 +96,15 @@ interface Authorizer {
96
96
  userArn: string;
97
97
  userId: string;
98
98
  };
99
+ jwt?: {
100
+ claims: Record<string, string | number | boolean | string[]>;
101
+ scopes: string[] | null;
102
+ };
103
+ /**
104
+ * The `context` object returned by a Lambda (REQUEST) authorizer.
105
+ * It is `null` when the authorizer returns no context.
106
+ */
107
+ lambda?: Record<string, unknown> | null;
99
108
  }
100
109
  export interface ApiGatewayRequestContextV2 {
101
110
  accountId: string;
@@ -125,7 +125,7 @@ var getNextParam = (acceptHeader, startIndex) => {
125
125
  var getNextAcceptValue = (acceptHeader, startIndex) => {
126
126
  const accept = {
127
127
  type: "",
128
- params: {},
128
+ params: /* @__PURE__ */ Object.create(null),
129
129
  q: 1
130
130
  };
131
131
  startIndex = consumeWhitespace(acceptHeader, startIndex);
@@ -23,6 +23,7 @@ var verifySignature = async (base64Signature, value, secret) => {
23
23
  }
24
24
  };
25
25
  var validCookieNameRegEx = /^[\w!#$%&'*.^`|~+-]+$/;
26
+ var relaxedCookieNameRegEx = /^[!#-:<>-[\]-~]+$/;
26
27
  var validCookieValueRegEx = /^[ !#-:<-[\]-~]*$/;
27
28
  var trimCookieWhitespace = (value) => {
28
29
  let start = 0;
@@ -55,7 +56,7 @@ var parse = (cookie, name) => {
55
56
  continue;
56
57
  }
57
58
  const cookieName = trimCookieWhitespace(pairStr.substring(0, valueStartPos));
58
- if (name && name !== cookieName || !validCookieNameRegEx.test(cookieName) || cookieName in parsedCookie) {
59
+ if (name && name !== cookieName || !relaxedCookieNameRegEx.test(cookieName) || cookieName in parsedCookie) {
59
60
  continue;
60
61
  }
61
62
  let cookieValue = trimCookieWhitespace(pairStr.substring(valueStartPos + 1));
package/dist/utils/url.js CHANGED
@@ -159,7 +159,7 @@ var _getQueryParam = (url, key, multiple) => {
159
159
  return void 0;
160
160
  }
161
161
  }
162
- const results = {};
162
+ const results = /* @__PURE__ */ Object.create(null);
163
163
  encoded ??= /[%+]/.test(url);
164
164
  let keyIndex = url.indexOf("?", 8);
165
165
  while (keyIndex !== -1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "4.12.31",
3
+ "version": "4.12.33",
4
4
  "description": "Web framework built on Web Standards",
5
5
  "main": "dist/cjs/index.js",
6
6
  "type": "module",
@@ -667,7 +667,7 @@
667
667
  ],
668
668
  "devDependencies": {
669
669
  "@hono/eslint-config": "^2.1.1",
670
- "@hono/node-server": "^2.0.2",
670
+ "@hono/node-server": "^2.0.12",
671
671
  "@types/jsdom": "^21.1.7",
672
672
  "@types/node": "^24.3.0",
673
673
  "@types/ws": "^8.18.1",
@@ -685,7 +685,6 @@
685
685
  "prettier": "3.7.4",
686
686
  "publint": "0.3.15",
687
687
  "typescript": "^6.0.3",
688
- "undici": "^6.27.0",
689
688
  "vite-plugin-fastly-js-compute": "^0.4.2",
690
689
  "vitest": "^4.1.9",
691
690
  "wrangler": "4.107.0",