hono 4.10.4 → 4.10.6
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/aws-lambda/handler.js +63 -2
- package/dist/cjs/adapter/aws-lambda/handler.js +64 -2
- package/dist/cjs/jsx/base.js +5 -4
- package/dist/cjs/middleware/bearer-auth/index.js +8 -7
- package/dist/cjs/middleware/cache/index.js +7 -0
- package/dist/cjs/utils/url.js +5 -2
- package/dist/jsx/base.js +5 -4
- package/dist/middleware/bearer-auth/index.js +8 -7
- package/dist/middleware/cache/index.js +7 -0
- package/dist/types/adapter/aws-lambda/handler.d.ts +28 -8
- package/dist/types/adapter/aws-lambda/types.d.ts +19 -0
- package/dist/types/adapter/cloudflare-pages/handler.d.ts +1 -1
- package/dist/types/adapter/cloudflare-workers/websocket.d.ts +1 -1
- package/dist/types/adapter/lambda-edge/handler.d.ts +2 -2
- package/dist/types/client/types.d.ts +7 -7
- package/dist/types/client/utils.d.ts +1 -1
- package/dist/types/compose.d.ts +1 -11
- package/dist/types/context.d.ts +19 -29
- package/dist/types/helper/adapter/index.d.ts +1 -1
- package/dist/types/helper/conninfo/types.d.ts +2 -2
- package/dist/types/helper/css/common.d.ts +1 -6
- package/dist/types/helper/factory/index.d.ts +12 -285
- package/dist/types/helper/proxy/index.d.ts +2 -5
- package/dist/types/helper/ssg/ssg.d.ts +1 -1
- package/dist/types/helper/websocket/index.d.ts +3 -2
- package/dist/types/hono-base.d.ts +15 -18
- package/dist/types/hono.d.ts +1 -1
- package/dist/types/jsx/base.d.ts +1 -4
- package/dist/types/jsx/dom/hooks/index.d.ts +3 -9
- package/dist/types/jsx/dom/index.d.ts +7 -28
- package/dist/types/jsx/dom/intrinsic-element/components.d.ts +6 -6
- package/dist/types/jsx/dom/render.d.ts +4 -28
- package/dist/types/jsx/dom/server.d.ts +7 -28
- package/dist/types/jsx/hooks/index.d.ts +5 -20
- package/dist/types/jsx/index.d.ts +7 -28
- package/dist/types/jsx/intrinsic-element/components.d.ts +4 -4
- package/dist/types/jsx/intrinsic-elements.d.ts +46 -46
- package/dist/types/middleware/bearer-auth/index.d.ts +34 -3
- package/dist/types/middleware/compress/index.d.ts +1 -4
- package/dist/types/middleware/csrf/index.d.ts +1 -6
- package/dist/types/middleware/language/language.d.ts +3 -3
- package/dist/types/middleware/secure-headers/permissions-policy.d.ts +3 -3
- package/dist/types/middleware/secure-headers/secure-headers.d.ts +3 -1
- package/dist/types/preset/quick.d.ts +1 -1
- package/dist/types/preset/tiny.d.ts +1 -1
- package/dist/types/request.d.ts +4 -9
- package/dist/types/router/linear-router/router.d.ts +1 -0
- package/dist/types/router/pattern-router/router.d.ts +1 -0
- package/dist/types/router/reg-exp-router/matcher.d.ts +2 -9
- package/dist/types/router/reg-exp-router/node.d.ts +2 -4
- package/dist/types/router/reg-exp-router/prepared-router.d.ts +2 -6
- package/dist/types/router/reg-exp-router/router.d.ts +1 -0
- package/dist/types/router/reg-exp-router/trie.d.ts +2 -5
- package/dist/types/router/smart-router/router.d.ts +1 -0
- package/dist/types/router/trie-router/node.d.ts +2 -6
- package/dist/types/router/trie-router/router.d.ts +1 -0
- package/dist/types/router.d.ts +2 -20
- package/dist/types/types.d.ts +113 -1994
- package/dist/types/utils/cookie.d.ts +4 -4
- package/dist/types/utils/headers.d.ts +3 -3
- package/dist/types/utils/html.d.ts +2 -6
- package/dist/types/utils/jwt/jwt.d.ts +1 -1
- package/dist/types/utils/mime.d.ts +2 -2
- package/dist/types/utils/stream.d.ts +4 -0
- package/dist/types/utils/url.d.ts +1 -5
- package/dist/types/validator/validator.d.ts +6 -18
- package/dist/utils/url.js +5 -2
- package/package.json +2 -1
|
@@ -73,9 +73,25 @@ var handle = (app, { isContentTypeBinary } = { isContentTypeBinary: void 0 }) =>
|
|
|
73
73
|
};
|
|
74
74
|
};
|
|
75
75
|
var EventProcessor = class {
|
|
76
|
+
getHeaderValue(headers, key) {
|
|
77
|
+
const value = headers ? Array.isArray(headers[key]) ? headers[key][0] : headers[key] : void 0;
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
getDomainName(event) {
|
|
81
|
+
if (event.requestContext && "domainName" in event.requestContext) {
|
|
82
|
+
return event.requestContext.domainName;
|
|
83
|
+
}
|
|
84
|
+
const hostFromHeaders = this.getHeaderValue(event.headers, "host");
|
|
85
|
+
if (hostFromHeaders) {
|
|
86
|
+
return hostFromHeaders;
|
|
87
|
+
}
|
|
88
|
+
const multiValueHeaders = "multiValueHeaders" in event ? event.multiValueHeaders : {};
|
|
89
|
+
const hostFromMultiValueHeaders = this.getHeaderValue(multiValueHeaders, "host");
|
|
90
|
+
return hostFromMultiValueHeaders;
|
|
91
|
+
}
|
|
76
92
|
createRequest(event) {
|
|
77
93
|
const queryString = this.getQueryString(event);
|
|
78
|
-
const domainName =
|
|
94
|
+
const domainName = this.getDomainName(event);
|
|
79
95
|
const path = this.getPath(event);
|
|
80
96
|
const urlPath = `https://${domainName}${path}`;
|
|
81
97
|
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
|
|
@@ -103,7 +119,7 @@ var EventProcessor = class {
|
|
|
103
119
|
body,
|
|
104
120
|
statusCode: res.status,
|
|
105
121
|
isBase64Encoded,
|
|
106
|
-
...event.multiValueHeaders ? {
|
|
122
|
+
..."multiValueHeaders" in event && event.multiValueHeaders ? {
|
|
107
123
|
multiValueHeaders: {}
|
|
108
124
|
} : {
|
|
109
125
|
headers: {}
|
|
@@ -263,6 +279,41 @@ var ALBProcessor = class extends EventProcessor {
|
|
|
263
279
|
}
|
|
264
280
|
};
|
|
265
281
|
var albProcessor = new ALBProcessor();
|
|
282
|
+
var LatticeV2Processor = class extends EventProcessor {
|
|
283
|
+
getPath(event) {
|
|
284
|
+
return event.path;
|
|
285
|
+
}
|
|
286
|
+
getMethod(event) {
|
|
287
|
+
return event.method;
|
|
288
|
+
}
|
|
289
|
+
getQueryString() {
|
|
290
|
+
return "";
|
|
291
|
+
}
|
|
292
|
+
getHeaders(event) {
|
|
293
|
+
const headers = new Headers();
|
|
294
|
+
if (event.headers) {
|
|
295
|
+
for (const [k, values] of Object.entries(event.headers)) {
|
|
296
|
+
if (values) {
|
|
297
|
+
const foundK = headers.get(k);
|
|
298
|
+
values.forEach((v) => {
|
|
299
|
+
const sanitizedValue = sanitizeHeaderValue(v);
|
|
300
|
+
return (!foundK || !foundK.includes(sanitizedValue)) && headers.append(k, sanitizedValue);
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return headers;
|
|
306
|
+
}
|
|
307
|
+
getCookies() {
|
|
308
|
+
}
|
|
309
|
+
setCookiesToResult(result, cookies) {
|
|
310
|
+
result.headers = {
|
|
311
|
+
...result.headers,
|
|
312
|
+
"set-cookie": cookies.join(", ")
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
var latticeV2Processor = new LatticeV2Processor();
|
|
266
317
|
var getProcessor = (event) => {
|
|
267
318
|
if (isProxyEventALB(event)) {
|
|
268
319
|
return albProcessor;
|
|
@@ -270,6 +321,9 @@ var getProcessor = (event) => {
|
|
|
270
321
|
if (isProxyEventV2(event)) {
|
|
271
322
|
return v2Processor;
|
|
272
323
|
}
|
|
324
|
+
if (isLatticeEventV2(event)) {
|
|
325
|
+
return latticeV2Processor;
|
|
326
|
+
}
|
|
273
327
|
return v1Processor;
|
|
274
328
|
};
|
|
275
329
|
var isProxyEventALB = (event) => {
|
|
@@ -281,6 +335,12 @@ var isProxyEventALB = (event) => {
|
|
|
281
335
|
var isProxyEventV2 = (event) => {
|
|
282
336
|
return Object.hasOwn(event, "rawPath");
|
|
283
337
|
};
|
|
338
|
+
var isLatticeEventV2 = (event) => {
|
|
339
|
+
if (event.requestContext) {
|
|
340
|
+
return Object.hasOwn(event.requestContext, "serviceArn");
|
|
341
|
+
}
|
|
342
|
+
return false;
|
|
343
|
+
};
|
|
284
344
|
var defaultIsContentTypeBinary = (contentType) => {
|
|
285
345
|
return !/^text\/(?:plain|html|css|javascript|csv)|(?:\/|\+)(?:json|xml)\s*(?:;|$)/.test(
|
|
286
346
|
contentType
|
|
@@ -297,6 +357,7 @@ export {
|
|
|
297
357
|
EventProcessor,
|
|
298
358
|
EventV1Processor,
|
|
299
359
|
EventV2Processor,
|
|
360
|
+
LatticeV2Processor,
|
|
300
361
|
defaultIsContentTypeBinary,
|
|
301
362
|
getProcessor,
|
|
302
363
|
handle,
|
|
@@ -22,6 +22,7 @@ __export(handler_exports, {
|
|
|
22
22
|
EventProcessor: () => EventProcessor,
|
|
23
23
|
EventV1Processor: () => EventV1Processor,
|
|
24
24
|
EventV2Processor: () => EventV2Processor,
|
|
25
|
+
LatticeV2Processor: () => LatticeV2Processor,
|
|
25
26
|
defaultIsContentTypeBinary: () => defaultIsContentTypeBinary,
|
|
26
27
|
getProcessor: () => getProcessor,
|
|
27
28
|
handle: () => handle,
|
|
@@ -103,9 +104,25 @@ const handle = (app, { isContentTypeBinary } = { isContentTypeBinary: void 0 })
|
|
|
103
104
|
};
|
|
104
105
|
};
|
|
105
106
|
class EventProcessor {
|
|
107
|
+
getHeaderValue(headers, key) {
|
|
108
|
+
const value = headers ? Array.isArray(headers[key]) ? headers[key][0] : headers[key] : void 0;
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
getDomainName(event) {
|
|
112
|
+
if (event.requestContext && "domainName" in event.requestContext) {
|
|
113
|
+
return event.requestContext.domainName;
|
|
114
|
+
}
|
|
115
|
+
const hostFromHeaders = this.getHeaderValue(event.headers, "host");
|
|
116
|
+
if (hostFromHeaders) {
|
|
117
|
+
return hostFromHeaders;
|
|
118
|
+
}
|
|
119
|
+
const multiValueHeaders = "multiValueHeaders" in event ? event.multiValueHeaders : {};
|
|
120
|
+
const hostFromMultiValueHeaders = this.getHeaderValue(multiValueHeaders, "host");
|
|
121
|
+
return hostFromMultiValueHeaders;
|
|
122
|
+
}
|
|
106
123
|
createRequest(event) {
|
|
107
124
|
const queryString = this.getQueryString(event);
|
|
108
|
-
const domainName =
|
|
125
|
+
const domainName = this.getDomainName(event);
|
|
109
126
|
const path = this.getPath(event);
|
|
110
127
|
const urlPath = `https://${domainName}${path}`;
|
|
111
128
|
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
|
|
@@ -133,7 +150,7 @@ class EventProcessor {
|
|
|
133
150
|
body,
|
|
134
151
|
statusCode: res.status,
|
|
135
152
|
isBase64Encoded,
|
|
136
|
-
...event.multiValueHeaders ? {
|
|
153
|
+
..."multiValueHeaders" in event && event.multiValueHeaders ? {
|
|
137
154
|
multiValueHeaders: {}
|
|
138
155
|
} : {
|
|
139
156
|
headers: {}
|
|
@@ -293,6 +310,41 @@ class ALBProcessor extends EventProcessor {
|
|
|
293
310
|
}
|
|
294
311
|
}
|
|
295
312
|
const albProcessor = new ALBProcessor();
|
|
313
|
+
class LatticeV2Processor extends EventProcessor {
|
|
314
|
+
getPath(event) {
|
|
315
|
+
return event.path;
|
|
316
|
+
}
|
|
317
|
+
getMethod(event) {
|
|
318
|
+
return event.method;
|
|
319
|
+
}
|
|
320
|
+
getQueryString() {
|
|
321
|
+
return "";
|
|
322
|
+
}
|
|
323
|
+
getHeaders(event) {
|
|
324
|
+
const headers = new Headers();
|
|
325
|
+
if (event.headers) {
|
|
326
|
+
for (const [k, values] of Object.entries(event.headers)) {
|
|
327
|
+
if (values) {
|
|
328
|
+
const foundK = headers.get(k);
|
|
329
|
+
values.forEach((v) => {
|
|
330
|
+
const sanitizedValue = sanitizeHeaderValue(v);
|
|
331
|
+
return (!foundK || !foundK.includes(sanitizedValue)) && headers.append(k, sanitizedValue);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return headers;
|
|
337
|
+
}
|
|
338
|
+
getCookies() {
|
|
339
|
+
}
|
|
340
|
+
setCookiesToResult(result, cookies) {
|
|
341
|
+
result.headers = {
|
|
342
|
+
...result.headers,
|
|
343
|
+
"set-cookie": cookies.join(", ")
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const latticeV2Processor = new LatticeV2Processor();
|
|
296
348
|
const getProcessor = (event) => {
|
|
297
349
|
if (isProxyEventALB(event)) {
|
|
298
350
|
return albProcessor;
|
|
@@ -300,6 +352,9 @@ const getProcessor = (event) => {
|
|
|
300
352
|
if (isProxyEventV2(event)) {
|
|
301
353
|
return v2Processor;
|
|
302
354
|
}
|
|
355
|
+
if (isLatticeEventV2(event)) {
|
|
356
|
+
return latticeV2Processor;
|
|
357
|
+
}
|
|
303
358
|
return v1Processor;
|
|
304
359
|
};
|
|
305
360
|
const isProxyEventALB = (event) => {
|
|
@@ -311,6 +366,12 @@ const isProxyEventALB = (event) => {
|
|
|
311
366
|
const isProxyEventV2 = (event) => {
|
|
312
367
|
return Object.hasOwn(event, "rawPath");
|
|
313
368
|
};
|
|
369
|
+
const isLatticeEventV2 = (event) => {
|
|
370
|
+
if (event.requestContext) {
|
|
371
|
+
return Object.hasOwn(event.requestContext, "serviceArn");
|
|
372
|
+
}
|
|
373
|
+
return false;
|
|
374
|
+
};
|
|
314
375
|
const defaultIsContentTypeBinary = (contentType) => {
|
|
315
376
|
return !/^text\/(?:plain|html|css|javascript|csv)|(?:\/|\+)(?:json|xml)\s*(?:;|$)/.test(
|
|
316
377
|
contentType
|
|
@@ -328,6 +389,7 @@ const isContentEncodingBinary = (contentEncoding) => {
|
|
|
328
389
|
EventProcessor,
|
|
329
390
|
EventV1Processor,
|
|
330
391
|
EventV2Processor,
|
|
392
|
+
LatticeV2Processor,
|
|
331
393
|
defaultIsContentTypeBinary,
|
|
332
394
|
getProcessor,
|
|
333
395
|
handle,
|
package/dist/cjs/jsx/base.js
CHANGED
|
@@ -206,10 +206,11 @@ class JSXNode {
|
|
|
206
206
|
class JSXFunctionNode extends JSXNode {
|
|
207
207
|
toStringToBuffer(buffer) {
|
|
208
208
|
const { children } = this;
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
children
|
|
212
|
-
}
|
|
209
|
+
const props = { ...this.props };
|
|
210
|
+
if (children.length) {
|
|
211
|
+
props.children = children.length === 1 ? children[0] : children;
|
|
212
|
+
}
|
|
213
|
+
const res = this.tag.call(null, props);
|
|
213
214
|
if (typeof res === "boolean" || res == null) {
|
|
214
215
|
return;
|
|
215
216
|
} else if (res instanceof Promise) {
|
|
@@ -41,8 +41,9 @@ const bearerAuth = (options) => {
|
|
|
41
41
|
const regexp = new RegExp(`^${prefixRegexStr}(${TOKEN_STRINGS}) *$`);
|
|
42
42
|
const wwwAuthenticatePrefix = options.prefix === "" ? "" : `${options.prefix} `;
|
|
43
43
|
const throwHTTPException = async (c, status, wwwAuthenticateHeader, messageOption) => {
|
|
44
|
+
const wwwAuthenticateHeaderValue = typeof wwwAuthenticateHeader === "function" ? await wwwAuthenticateHeader(c) : wwwAuthenticateHeader;
|
|
44
45
|
const headers = {
|
|
45
|
-
"WWW-Authenticate":
|
|
46
|
+
"WWW-Authenticate": typeof wwwAuthenticateHeaderValue === "string" ? wwwAuthenticateHeaderValue : `${wwwAuthenticatePrefix}${Object.entries(wwwAuthenticateHeaderValue).map(([key, value]) => `${key}="${value}"`).join(",")}`
|
|
46
47
|
};
|
|
47
48
|
const responseMessage = typeof messageOption === "function" ? await messageOption(c) : messageOption;
|
|
48
49
|
const res = typeof responseMessage === "string" ? new Response(responseMessage, { status, headers }) : new Response(JSON.stringify(responseMessage), {
|
|
@@ -60,8 +61,8 @@ const bearerAuth = (options) => {
|
|
|
60
61
|
await throwHTTPException(
|
|
61
62
|
c,
|
|
62
63
|
401,
|
|
63
|
-
`${wwwAuthenticatePrefix}realm="${realm}"`,
|
|
64
|
-
options.noAuthenticationHeaderMessage || "Unauthorized"
|
|
64
|
+
options.noAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}realm="${realm}"`,
|
|
65
|
+
options.noAuthenticationHeader?.message || options.noAuthenticationHeaderMessage || "Unauthorized"
|
|
65
66
|
);
|
|
66
67
|
} else {
|
|
67
68
|
const match = regexp.exec(headerToken);
|
|
@@ -69,8 +70,8 @@ const bearerAuth = (options) => {
|
|
|
69
70
|
await throwHTTPException(
|
|
70
71
|
c,
|
|
71
72
|
400,
|
|
72
|
-
`${wwwAuthenticatePrefix}error="invalid_request"`,
|
|
73
|
-
options.invalidAuthenticationHeaderMessage || "Bad Request"
|
|
73
|
+
options.invalidAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_request"`,
|
|
74
|
+
options.invalidAuthenticationHeader?.message || options.invalidAuthenticationHeaderMessage || "Bad Request"
|
|
74
75
|
);
|
|
75
76
|
} else {
|
|
76
77
|
let equal = false;
|
|
@@ -90,8 +91,8 @@ const bearerAuth = (options) => {
|
|
|
90
91
|
await throwHTTPException(
|
|
91
92
|
c,
|
|
92
93
|
401,
|
|
93
|
-
`${wwwAuthenticatePrefix}error="invalid_token"`,
|
|
94
|
-
options.invalidTokenMessage || "Unauthorized"
|
|
94
|
+
options.invalidToken?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_token"`,
|
|
95
|
+
options.invalidToken?.message || options.invalidTokenMessage || "Unauthorized"
|
|
95
96
|
);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
@@ -22,6 +22,10 @@ __export(cache_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(cache_exports);
|
|
24
24
|
const defaultCacheableStatusCodes = [200];
|
|
25
|
+
const shouldSkipCache = (res) => {
|
|
26
|
+
const vary = res.headers.get("Vary");
|
|
27
|
+
return vary && vary.includes("*");
|
|
28
|
+
};
|
|
25
29
|
const cache = (options) => {
|
|
26
30
|
if (!globalThis.caches) {
|
|
27
31
|
console.log("Cache Middleware is not enabled because caches is not defined.");
|
|
@@ -81,6 +85,9 @@ const cache = (options) => {
|
|
|
81
85
|
return;
|
|
82
86
|
}
|
|
83
87
|
addHeader(c);
|
|
88
|
+
if (shouldSkipCache(c.res)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
84
91
|
const res = c.res.clone();
|
|
85
92
|
if (options.wait) {
|
|
86
93
|
await cache3.put(key, res);
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -167,9 +167,12 @@ const _decodeURI = (value) => {
|
|
|
167
167
|
const _getQueryParam = (url, key, multiple) => {
|
|
168
168
|
let encoded;
|
|
169
169
|
if (!multiple && key && !/[%+]/.test(key)) {
|
|
170
|
-
let keyIndex2 = url.indexOf(
|
|
170
|
+
let keyIndex2 = url.indexOf("?", 8);
|
|
171
171
|
if (keyIndex2 === -1) {
|
|
172
|
-
|
|
172
|
+
return void 0;
|
|
173
|
+
}
|
|
174
|
+
if (!url.startsWith(key, keyIndex2 + 1)) {
|
|
175
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
173
176
|
}
|
|
174
177
|
while (keyIndex2 !== -1) {
|
|
175
178
|
const trailingKeyCode = url.charCodeAt(keyIndex2 + key.length + 1);
|
package/dist/jsx/base.js
CHANGED
|
@@ -167,10 +167,11 @@ var JSXNode = class {
|
|
|
167
167
|
var JSXFunctionNode = class extends JSXNode {
|
|
168
168
|
toStringToBuffer(buffer) {
|
|
169
169
|
const { children } = this;
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
children
|
|
173
|
-
}
|
|
170
|
+
const props = { ...this.props };
|
|
171
|
+
if (children.length) {
|
|
172
|
+
props.children = children.length === 1 ? children[0] : children;
|
|
173
|
+
}
|
|
174
|
+
const res = this.tag.call(null, props);
|
|
174
175
|
if (typeof res === "boolean" || res == null) {
|
|
175
176
|
return;
|
|
176
177
|
} else if (res instanceof Promise) {
|
|
@@ -19,8 +19,9 @@ var bearerAuth = (options) => {
|
|
|
19
19
|
const regexp = new RegExp(`^${prefixRegexStr}(${TOKEN_STRINGS}) *$`);
|
|
20
20
|
const wwwAuthenticatePrefix = options.prefix === "" ? "" : `${options.prefix} `;
|
|
21
21
|
const throwHTTPException = async (c, status, wwwAuthenticateHeader, messageOption) => {
|
|
22
|
+
const wwwAuthenticateHeaderValue = typeof wwwAuthenticateHeader === "function" ? await wwwAuthenticateHeader(c) : wwwAuthenticateHeader;
|
|
22
23
|
const headers = {
|
|
23
|
-
"WWW-Authenticate":
|
|
24
|
+
"WWW-Authenticate": typeof wwwAuthenticateHeaderValue === "string" ? wwwAuthenticateHeaderValue : `${wwwAuthenticatePrefix}${Object.entries(wwwAuthenticateHeaderValue).map(([key, value]) => `${key}="${value}"`).join(",")}`
|
|
24
25
|
};
|
|
25
26
|
const responseMessage = typeof messageOption === "function" ? await messageOption(c) : messageOption;
|
|
26
27
|
const res = typeof responseMessage === "string" ? new Response(responseMessage, { status, headers }) : new Response(JSON.stringify(responseMessage), {
|
|
@@ -38,8 +39,8 @@ var bearerAuth = (options) => {
|
|
|
38
39
|
await throwHTTPException(
|
|
39
40
|
c,
|
|
40
41
|
401,
|
|
41
|
-
`${wwwAuthenticatePrefix}realm="${realm}"`,
|
|
42
|
-
options.noAuthenticationHeaderMessage || "Unauthorized"
|
|
42
|
+
options.noAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}realm="${realm}"`,
|
|
43
|
+
options.noAuthenticationHeader?.message || options.noAuthenticationHeaderMessage || "Unauthorized"
|
|
43
44
|
);
|
|
44
45
|
} else {
|
|
45
46
|
const match = regexp.exec(headerToken);
|
|
@@ -47,8 +48,8 @@ var bearerAuth = (options) => {
|
|
|
47
48
|
await throwHTTPException(
|
|
48
49
|
c,
|
|
49
50
|
400,
|
|
50
|
-
`${wwwAuthenticatePrefix}error="invalid_request"`,
|
|
51
|
-
options.invalidAuthenticationHeaderMessage || "Bad Request"
|
|
51
|
+
options.invalidAuthenticationHeader?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_request"`,
|
|
52
|
+
options.invalidAuthenticationHeader?.message || options.invalidAuthenticationHeaderMessage || "Bad Request"
|
|
52
53
|
);
|
|
53
54
|
} else {
|
|
54
55
|
let equal = false;
|
|
@@ -68,8 +69,8 @@ var bearerAuth = (options) => {
|
|
|
68
69
|
await throwHTTPException(
|
|
69
70
|
c,
|
|
70
71
|
401,
|
|
71
|
-
`${wwwAuthenticatePrefix}error="invalid_token"`,
|
|
72
|
-
options.invalidTokenMessage || "Unauthorized"
|
|
72
|
+
options.invalidToken?.wwwAuthenticateHeader || `${wwwAuthenticatePrefix}error="invalid_token"`,
|
|
73
|
+
options.invalidToken?.message || options.invalidTokenMessage || "Unauthorized"
|
|
73
74
|
);
|
|
74
75
|
}
|
|
75
76
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// src/middleware/cache/index.ts
|
|
2
2
|
var defaultCacheableStatusCodes = [200];
|
|
3
|
+
var shouldSkipCache = (res) => {
|
|
4
|
+
const vary = res.headers.get("Vary");
|
|
5
|
+
return vary && vary.includes("*");
|
|
6
|
+
};
|
|
3
7
|
var cache = (options) => {
|
|
4
8
|
if (!globalThis.caches) {
|
|
5
9
|
console.log("Cache Middleware is not enabled because caches is not defined.");
|
|
@@ -59,6 +63,9 @@ var cache = (options) => {
|
|
|
59
63
|
return;
|
|
60
64
|
}
|
|
61
65
|
addHeader(c);
|
|
66
|
+
if (shouldSkipCache(c.res)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
62
69
|
const res = c.res.clone();
|
|
63
70
|
if (options.wait) {
|
|
64
71
|
await cache3.put(key, res);
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { Hono } from '../../hono';
|
|
2
2
|
import type { Env, Schema } from '../../types';
|
|
3
|
-
import type { ALBRequestContext, ApiGatewayRequestContext, ApiGatewayRequestContextV2, Handler, LambdaContext } from './types';
|
|
4
|
-
export type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2 | ALBProxyEvent;
|
|
3
|
+
import type { ALBRequestContext, ApiGatewayRequestContext, ApiGatewayRequestContextV2, Handler, LambdaContext, LatticeRequestContextV2 } from './types';
|
|
4
|
+
export type LambdaEvent = APIGatewayProxyEvent | APIGatewayProxyEventV2 | ALBProxyEvent | LatticeProxyEventV2;
|
|
5
|
+
export interface LatticeProxyEventV2 {
|
|
6
|
+
version: string;
|
|
7
|
+
path: string;
|
|
8
|
+
method: string;
|
|
9
|
+
headers: Record<string, string[] | undefined>;
|
|
10
|
+
queryStringParameters: Record<string, string[] | undefined>;
|
|
11
|
+
body: string | null;
|
|
12
|
+
isBase64Encoded: boolean;
|
|
13
|
+
requestContext: LatticeRequestContextV2;
|
|
14
|
+
}
|
|
5
15
|
export interface APIGatewayProxyEventV2 {
|
|
6
16
|
version: string;
|
|
7
17
|
routeKey: string;
|
|
@@ -124,8 +134,10 @@ export declare abstract class EventProcessor<E extends LambdaEvent> {
|
|
|
124
134
|
protected abstract getHeaders(event: E): Headers;
|
|
125
135
|
protected abstract getCookies(event: E, headers: Headers): void;
|
|
126
136
|
protected abstract setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
|
|
137
|
+
protected getHeaderValue(headers: E['headers'], key: string): string | undefined;
|
|
138
|
+
protected getDomainName(event: E): string | undefined;
|
|
127
139
|
createRequest(event: E): Request;
|
|
128
|
-
createResult(event: E, res: Response, options: Pick<HandleOptions,
|
|
140
|
+
createResult(event: E, res: Response, options: Pick<HandleOptions, 'isContentTypeBinary'>): Promise<APIGatewayProxyResult>;
|
|
129
141
|
setCookies(event: E, res: Response, result: APIGatewayProxyResult): void;
|
|
130
142
|
}
|
|
131
143
|
export declare class EventV2Processor extends EventProcessor<APIGatewayProxyEventV2> {
|
|
@@ -136,11 +148,11 @@ export declare class EventV2Processor extends EventProcessor<APIGatewayProxyEven
|
|
|
136
148
|
protected setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
|
|
137
149
|
protected getHeaders(event: APIGatewayProxyEventV2): Headers;
|
|
138
150
|
}
|
|
139
|
-
export declare class EventV1Processor extends EventProcessor<
|
|
140
|
-
protected getPath(event:
|
|
141
|
-
protected getMethod(event:
|
|
142
|
-
protected getQueryString(event:
|
|
143
|
-
protected getCookies(event:
|
|
151
|
+
export declare class EventV1Processor extends EventProcessor<APIGatewayProxyEvent> {
|
|
152
|
+
protected getPath(event: APIGatewayProxyEvent): string;
|
|
153
|
+
protected getMethod(event: APIGatewayProxyEvent): string;
|
|
154
|
+
protected getQueryString(event: APIGatewayProxyEvent): string;
|
|
155
|
+
protected getCookies(event: APIGatewayProxyEvent, headers: Headers): void;
|
|
144
156
|
protected getHeaders(event: APIGatewayProxyEvent): Headers;
|
|
145
157
|
protected setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
|
|
146
158
|
}
|
|
@@ -152,6 +164,14 @@ export declare class ALBProcessor extends EventProcessor<ALBProxyEvent> {
|
|
|
152
164
|
protected getCookies(event: ALBProxyEvent, headers: Headers): void;
|
|
153
165
|
protected setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
|
|
154
166
|
}
|
|
167
|
+
export declare class LatticeV2Processor extends EventProcessor<LatticeProxyEventV2> {
|
|
168
|
+
protected getPath(event: LatticeProxyEventV2): string;
|
|
169
|
+
protected getMethod(event: LatticeProxyEventV2): string;
|
|
170
|
+
protected getQueryString(): string;
|
|
171
|
+
protected getHeaders(event: LatticeProxyEventV2): Headers;
|
|
172
|
+
protected getCookies(): void;
|
|
173
|
+
protected setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void;
|
|
174
|
+
}
|
|
155
175
|
export declare const getProcessor: (event: LambdaEvent) => EventProcessor<LambdaEvent>;
|
|
156
176
|
/**
|
|
157
177
|
* Check if the given content type is binary.
|
|
@@ -122,4 +122,23 @@ export interface ALBRequestContext {
|
|
|
122
122
|
targetGroupArn: string;
|
|
123
123
|
};
|
|
124
124
|
}
|
|
125
|
+
export interface LatticeRequestContextV2 {
|
|
126
|
+
serviceNetworkArn: string;
|
|
127
|
+
serviceArn: string;
|
|
128
|
+
targetGroupArn: string;
|
|
129
|
+
region: string;
|
|
130
|
+
timeEpoch: string;
|
|
131
|
+
identity: {
|
|
132
|
+
sourceVpcArn?: string;
|
|
133
|
+
type?: string;
|
|
134
|
+
principal?: string;
|
|
135
|
+
principalOrgID?: string;
|
|
136
|
+
sessionName?: string;
|
|
137
|
+
x509IssuerOu?: string;
|
|
138
|
+
x509SanDns?: string;
|
|
139
|
+
x509SanNameCn?: string;
|
|
140
|
+
x509SanUri?: string;
|
|
141
|
+
x509SubjectCn?: string;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
125
144
|
export {};
|
|
@@ -22,7 +22,7 @@ export declare function handleMiddleware<E extends Env = {}, P extends string =
|
|
|
22
22
|
Bindings: {
|
|
23
23
|
eventContext: EventContext;
|
|
24
24
|
};
|
|
25
|
-
}, P, I>): PagesFunction<E[
|
|
25
|
+
}, P, I>): PagesFunction<E['Bindings']>;
|
|
26
26
|
/**
|
|
27
27
|
*
|
|
28
28
|
* @description `serveStatic()` is for advanced mode:
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { UpgradeWebSocket, WSEvents } from '../../helper/websocket';
|
|
2
|
-
export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, any, Omit<WSEvents<WebSocket>,
|
|
2
|
+
export declare const upgradeWebSocket: UpgradeWebSocket<WebSocket, any, Omit<WSEvents<WebSocket>, 'onOpen'>>;
|
|
@@ -17,7 +17,7 @@ interface CloudFrontCustomOrigin {
|
|
|
17
17
|
sslProtocols: string[];
|
|
18
18
|
}
|
|
19
19
|
interface CloudFrontS3Origin {
|
|
20
|
-
authMethod:
|
|
20
|
+
authMethod: 'origin-access-identity' | 'none';
|
|
21
21
|
customHeaders: CloudFrontHeaders;
|
|
22
22
|
domainName: string;
|
|
23
23
|
path: string;
|
|
@@ -79,7 +79,7 @@ interface CloudFrontResult {
|
|
|
79
79
|
}[];
|
|
80
80
|
};
|
|
81
81
|
body?: string;
|
|
82
|
-
bodyEncoding?:
|
|
82
|
+
bodyEncoding?: 'text' | 'base64';
|
|
83
83
|
}
|
|
84
84
|
export declare const handle: (app: Hono<any>) => ((event: CloudFrontEdgeEvent, context?: CloudFrontContext, callback?: Callback) => Promise<CloudFrontResult>);
|
|
85
85
|
export declare const createBody: (method: string, requestBody: CloudFrontRequest["body"]) => string | Uint8Array<ArrayBuffer> | undefined;
|
|
@@ -3,7 +3,7 @@ import type { HonoBase } from '../hono-base';
|
|
|
3
3
|
import type { Endpoint, ResponseFormat, Schema } from '../types';
|
|
4
4
|
import type { StatusCode, SuccessStatusCode } from '../utils/http-status';
|
|
5
5
|
import type { HasRequiredKeys } from '../utils/types';
|
|
6
|
-
type HonoRequest = (typeof Hono.prototype)[
|
|
6
|
+
type HonoRequest = (typeof Hono.prototype)['request'];
|
|
7
7
|
export type ClientRequestOptions<T = unknown> = {
|
|
8
8
|
fetch?: typeof fetch | HonoRequest;
|
|
9
9
|
webSocket?: (...args: ConstructorParameters<typeof WebSocket>) => WebSocket;
|
|
@@ -40,9 +40,9 @@ export type ClientRequest<S extends Schema> = {
|
|
|
40
40
|
} ? {
|
|
41
41
|
query: Q;
|
|
42
42
|
} : {} : {}) => URL;
|
|
43
|
-
} & (S[
|
|
44
|
-
outputFormat:
|
|
45
|
-
} ? S[
|
|
43
|
+
} & (S['$get'] extends {
|
|
44
|
+
outputFormat: 'ws';
|
|
45
|
+
} ? S['$get'] extends {
|
|
46
46
|
input: infer I;
|
|
47
47
|
} ? {
|
|
48
48
|
$ws: (args?: I) => WebSocket;
|
|
@@ -62,8 +62,8 @@ export interface ClientResponse<T, U extends number = StatusCode, F extends Resp
|
|
|
62
62
|
url: string;
|
|
63
63
|
redirect(url: string, status: number): Response;
|
|
64
64
|
clone(): Response;
|
|
65
|
-
json(): F extends
|
|
66
|
-
text(): F extends
|
|
65
|
+
json(): F extends 'text' ? Promise<never> : F extends 'json' ? Promise<T> : Promise<unknown>;
|
|
66
|
+
text(): F extends 'text' ? (T extends string ? Promise<T> : Promise<never>) : Promise<string>;
|
|
67
67
|
blob(): Promise<Blob>;
|
|
68
68
|
formData(): Promise<FormData>;
|
|
69
69
|
arrayBuffer(): Promise<ArrayBuffer>;
|
|
@@ -96,7 +96,7 @@ export type FilterClientResponseByStatusCode<T extends ClientResponse<any, any,
|
|
|
96
96
|
type PathToChain<Path extends string, E extends Schema, Original extends string = Path> = Path extends `/${infer P}` ? PathToChain<P, E, Path> : Path extends `${infer P}/${infer R}` ? {
|
|
97
97
|
[K in P]: PathToChain<R, E, Original>;
|
|
98
98
|
} : {
|
|
99
|
-
[K in Path extends
|
|
99
|
+
[K in Path extends '' ? 'index' : Path]: ClientRequest<E extends Record<string, unknown> ? E[Original] : never>;
|
|
100
100
|
};
|
|
101
101
|
export type Client<T> = T extends HonoBase<any, infer S, any> ? S extends Record<infer K, Schema> ? K extends string ? PathToChain<K, S> : never : never : never;
|
|
102
102
|
export type Callback = (opts: CallbackOptions) => unknown;
|
|
@@ -15,4 +15,4 @@ export declare function deepMerge<T>(target: T, source: Record<string, unknown>)
|
|
|
15
15
|
*
|
|
16
16
|
* @example const result = await parseResponse(client.posts.$get())
|
|
17
17
|
*/
|
|
18
|
-
export declare function parseResponse<T extends ClientResponse<any>>(fetchRes: T | Promise<T>): Promise<FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends never ? undefined : FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends ClientResponse<infer RT, infer _, infer RF> ? RF extends
|
|
18
|
+
export declare function parseResponse<T extends ClientResponse<any>>(fetchRes: T | Promise<T>): Promise<FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends never ? undefined : FilterClientResponseByStatusCode<T, Exclude<ContentfulStatusCode, ClientErrorStatusCode | ServerErrorStatusCode>> extends ClientResponse<infer RT, infer _, infer RF> ? RF extends 'json' ? RT : RT extends string ? RT : string : undefined>;
|
package/dist/types/compose.d.ts
CHANGED
|
@@ -11,14 +11,4 @@ import type { Env, ErrorHandler, Next, NotFoundHandler } from './types';
|
|
|
11
11
|
*
|
|
12
12
|
* @returns {(context: Context, next?: Next) => Promise<Context>} - A composed middleware function.
|
|
13
13
|
*/
|
|
14
|
-
export declare const compose: <E extends Env = Env>(middleware: [
|
|
15
|
-
[
|
|
16
|
-
Function,
|
|
17
|
-
unknown
|
|
18
|
-
],
|
|
19
|
-
unknown
|
|
20
|
-
][] | [
|
|
21
|
-
[
|
|
22
|
-
Function
|
|
23
|
-
]
|
|
24
|
-
][], onError?: ErrorHandler<E>, onNotFound?: NotFoundHandler<E>) => ((context: Context, next?: Next) => Promise<Context>);
|
|
14
|
+
export declare const compose: <E extends Env = Env>(middleware: [[Function, unknown], unknown][] | [[Function]][], onError?: ErrorHandler<E>, onNotFound?: NotFoundHandler<E>) => ((context: Context, next?: Next) => Promise<Context>);
|