hono 3.8.3 → 3.8.4
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.
|
@@ -13,10 +13,10 @@ var handle = (app) => {
|
|
|
13
13
|
requestContext,
|
|
14
14
|
lambdaContext
|
|
15
15
|
});
|
|
16
|
-
return createResult(res);
|
|
16
|
+
return createResult(event, res);
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
var createResult = async (res) => {
|
|
19
|
+
var createResult = async (event, res) => {
|
|
20
20
|
const contentType = res.headers.get("content-type");
|
|
21
21
|
let isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
|
|
22
22
|
if (!isBase64Encoded) {
|
|
@@ -36,6 +36,7 @@ var createResult = async (res) => {
|
|
|
36
36
|
statusCode: res.status,
|
|
37
37
|
isBase64Encoded
|
|
38
38
|
};
|
|
39
|
+
setCookies(event, res, result);
|
|
39
40
|
res.headers.forEach((value, key) => {
|
|
40
41
|
result.headers[key] = value;
|
|
41
42
|
});
|
|
@@ -46,6 +47,7 @@ var createRequest = (event) => {
|
|
|
46
47
|
const urlPath = `https://${event.requestContext.domainName}${isProxyEvent(event) ? event.path : event.rawPath}`;
|
|
47
48
|
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
|
|
48
49
|
const headers = new Headers();
|
|
50
|
+
getCookies(event, headers);
|
|
49
51
|
for (const [k, v] of Object.entries(event.headers)) {
|
|
50
52
|
if (v)
|
|
51
53
|
headers.set(k, v);
|
|
@@ -66,6 +68,26 @@ var extractQueryString = (event) => {
|
|
|
66
68
|
}
|
|
67
69
|
return isProxyEventV2(event) ? event.rawQueryString : event.rawQueryString;
|
|
68
70
|
};
|
|
71
|
+
var getCookies = (event, headers) => {
|
|
72
|
+
if (isProxyEventV2(event) && Array.isArray(event.cookies)) {
|
|
73
|
+
headers.set("Cookie", event.cookies.join("; "));
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var setCookies = (event, res, result) => {
|
|
77
|
+
if (res.headers.has("set-cookie")) {
|
|
78
|
+
const cookies = res.headers.get("set-cookie")?.split(", ");
|
|
79
|
+
if (Array.isArray(cookies)) {
|
|
80
|
+
if (isProxyEventV2(event)) {
|
|
81
|
+
result.cookies = cookies;
|
|
82
|
+
} else {
|
|
83
|
+
result.multiValueHeaders = {
|
|
84
|
+
"set-cookie": cookies
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
res.headers.delete("set-cookie");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
69
91
|
var isProxyEvent = (event) => {
|
|
70
92
|
return Object.prototype.hasOwnProperty.call(event, "path");
|
|
71
93
|
};
|
|
@@ -43,10 +43,10 @@ const handle = (app) => {
|
|
|
43
43
|
requestContext,
|
|
44
44
|
lambdaContext
|
|
45
45
|
});
|
|
46
|
-
return createResult(res);
|
|
46
|
+
return createResult(event, res);
|
|
47
47
|
};
|
|
48
48
|
};
|
|
49
|
-
const createResult = async (res) => {
|
|
49
|
+
const createResult = async (event, res) => {
|
|
50
50
|
const contentType = res.headers.get("content-type");
|
|
51
51
|
let isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
|
|
52
52
|
if (!isBase64Encoded) {
|
|
@@ -66,6 +66,7 @@ const createResult = async (res) => {
|
|
|
66
66
|
statusCode: res.status,
|
|
67
67
|
isBase64Encoded
|
|
68
68
|
};
|
|
69
|
+
setCookies(event, res, result);
|
|
69
70
|
res.headers.forEach((value, key) => {
|
|
70
71
|
result.headers[key] = value;
|
|
71
72
|
});
|
|
@@ -76,6 +77,7 @@ const createRequest = (event) => {
|
|
|
76
77
|
const urlPath = `https://${event.requestContext.domainName}${isProxyEvent(event) ? event.path : event.rawPath}`;
|
|
77
78
|
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
|
|
78
79
|
const headers = new Headers();
|
|
80
|
+
getCookies(event, headers);
|
|
79
81
|
for (const [k, v] of Object.entries(event.headers)) {
|
|
80
82
|
if (v)
|
|
81
83
|
headers.set(k, v);
|
|
@@ -96,6 +98,26 @@ const extractQueryString = (event) => {
|
|
|
96
98
|
}
|
|
97
99
|
return isProxyEventV2(event) ? event.rawQueryString : event.rawQueryString;
|
|
98
100
|
};
|
|
101
|
+
const getCookies = (event, headers) => {
|
|
102
|
+
if (isProxyEventV2(event) && Array.isArray(event.cookies)) {
|
|
103
|
+
headers.set("Cookie", event.cookies.join("; "));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const setCookies = (event, res, result) => {
|
|
107
|
+
if (res.headers.has("set-cookie")) {
|
|
108
|
+
const cookies = res.headers.get("set-cookie")?.split(", ");
|
|
109
|
+
if (Array.isArray(cookies)) {
|
|
110
|
+
if (isProxyEventV2(event)) {
|
|
111
|
+
result.cookies = cookies;
|
|
112
|
+
} else {
|
|
113
|
+
result.multiValueHeaders = {
|
|
114
|
+
"set-cookie": cookies
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
res.headers.delete("set-cookie");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
99
121
|
const isProxyEvent = (event) => {
|
|
100
122
|
return Object.prototype.hasOwnProperty.call(event, "path");
|
|
101
123
|
};
|
|
@@ -5,6 +5,7 @@ import type { LambdaContext } from './types';
|
|
|
5
5
|
interface APIGatewayProxyEventV2 {
|
|
6
6
|
httpMethod: string;
|
|
7
7
|
headers: Record<string, string | undefined>;
|
|
8
|
+
cookies?: string[];
|
|
8
9
|
rawPath: string;
|
|
9
10
|
rawQueryString: string;
|
|
10
11
|
body: string | null;
|
|
@@ -14,6 +15,9 @@ interface APIGatewayProxyEventV2 {
|
|
|
14
15
|
interface APIGatewayProxyEvent {
|
|
15
16
|
httpMethod: string;
|
|
16
17
|
headers: Record<string, string | undefined>;
|
|
18
|
+
multiValueHeaders?: {
|
|
19
|
+
[headerKey: string]: string[];
|
|
20
|
+
};
|
|
17
21
|
path: string;
|
|
18
22
|
body: string | null;
|
|
19
23
|
isBase64Encoded: boolean;
|
|
@@ -32,6 +36,10 @@ interface APIGatewayProxyResult {
|
|
|
32
36
|
statusCode: number;
|
|
33
37
|
body: string;
|
|
34
38
|
headers: Record<string, string>;
|
|
39
|
+
cookies?: string[];
|
|
40
|
+
multiValueHeaders?: {
|
|
41
|
+
[headerKey: string]: string[];
|
|
42
|
+
};
|
|
35
43
|
isBase64Encoded: boolean;
|
|
36
44
|
}
|
|
37
45
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Hono } from '../hono';
|
|
2
2
|
import type { Schema } from '../types';
|
|
3
|
-
import type {
|
|
3
|
+
import type { HasRequiredKeys } from '../utils/types';
|
|
4
4
|
declare type HonoRequest = typeof Hono.prototype['request'];
|
|
5
5
|
export declare type ClientRequestOptions<T = unknown> = keyof T extends never ? {
|
|
6
6
|
headers?: Record<string, string>;
|
|
@@ -13,7 +13,7 @@ declare type ClientRequest<S extends Schema> = {
|
|
|
13
13
|
[M in keyof S]: S[M] extends {
|
|
14
14
|
input: infer R;
|
|
15
15
|
output: infer O;
|
|
16
|
-
} ?
|
|
16
|
+
} ? R extends object ? HasRequiredKeys<R> extends true ? (args: R, options?: ClientRequestOptions) => Promise<ClientResponse<O>> : (args?: R, options?: ClientRequestOptions) => Promise<ClientResponse<O>> : never : never;
|
|
17
17
|
} & {
|
|
18
18
|
$url: () => URL;
|
|
19
19
|
};
|
|
@@ -14,3 +14,7 @@ export declare type JSONValue = JSONObject | JSONArray | JSONPrimitive;
|
|
|
14
14
|
export declare type InterfaceToType<T> = T extends Function ? T : {
|
|
15
15
|
[K in keyof T]: InterfaceToType<T[K]>;
|
|
16
16
|
};
|
|
17
|
+
export declare type RequiredKeysOf<BaseType extends object> = Exclude<{
|
|
18
|
+
[Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]> ? Key : never;
|
|
19
|
+
}[keyof BaseType], undefined>;
|
|
20
|
+
export declare type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.4",
|
|
4
4
|
"description": "Ultrafast web framework for the Edges",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
"import": "./dist/index.js",
|
|
40
40
|
"require": "./dist/cjs/index.js"
|
|
41
41
|
},
|
|
42
|
+
"./types": {
|
|
43
|
+
"types": "./dist/types/types.d.ts",
|
|
44
|
+
"import": "./dist/types.js",
|
|
45
|
+
"require": "./dist/cjs/types.js"
|
|
46
|
+
},
|
|
42
47
|
"./hono-base": {
|
|
43
48
|
"types": "./dist/types/hono-base.d.ts",
|
|
44
49
|
"import": "./dist/hono-base.js",
|