better-call 1.0.28-beta.2 → 1.0.29
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/LICENSE +21 -0
- package/dist/index.cjs +18 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -10
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Bereket Engida
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -136,10 +136,16 @@ async function getBody(request, allowedMediaTypes) {
|
|
|
136
136
|
const normalizedContentTypeBase = normalizedContentType.split(";")[0].trim();
|
|
137
137
|
const normalizedAllowed = allowed.toLowerCase().trim();
|
|
138
138
|
return normalizedContentTypeBase === normalizedAllowed || normalizedContentTypeBase.includes(normalizedAllowed);
|
|
139
|
-
}))
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
})) {
|
|
140
|
+
if (!normalizedContentType) throw new APIError(415, {
|
|
141
|
+
message: `Content-Type is required. Allowed types: ${allowedMediaTypes.join(", ")}`,
|
|
142
|
+
code: "UNSUPPORTED_MEDIA_TYPE"
|
|
143
|
+
});
|
|
144
|
+
throw new APIError(415, {
|
|
145
|
+
message: `Content-Type "${contentType}" is not allowed. Allowed types: ${allowedMediaTypes.join(", ")}`,
|
|
146
|
+
code: "UNSUPPORTED_MEDIA_TYPE"
|
|
147
|
+
});
|
|
148
|
+
}
|
|
143
149
|
}
|
|
144
150
|
if (normalizedContentType.includes("application/json")) return await request.json();
|
|
145
151
|
if (normalizedContentType.includes("application/x-www-form-urlencoded")) {
|
|
@@ -215,12 +221,14 @@ function toResponse(data, init) {
|
|
|
215
221
|
const body$1 = data.body;
|
|
216
222
|
const routerResponse = data.routerResponse;
|
|
217
223
|
if (routerResponse instanceof Response) return routerResponse;
|
|
218
|
-
const headers$1 = new Headers(
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
+
const headers$1 = new Headers();
|
|
225
|
+
if (routerResponse?.headers) {
|
|
226
|
+
const headers$2 = new Headers(routerResponse.headers);
|
|
227
|
+
for (const [key, value] of headers$2.entries()) headers$2.set(key, value);
|
|
228
|
+
}
|
|
229
|
+
if (data.headers) for (const [key, value] of new Headers(data.headers).entries()) headers$1.set(key, value);
|
|
230
|
+
if (init?.headers) for (const [key, value] of new Headers(init.headers).entries()) headers$1.set(key, value);
|
|
231
|
+
headers$1.set("Content-Type", "application/json");
|
|
224
232
|
return new Response(JSON.stringify(body$1), {
|
|
225
233
|
...routerResponse,
|
|
226
234
|
headers: headers$1,
|