@forklaunch/core 0.14.8 → 0.14.9
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/lib/http/index.d.mts +1 -1
- package/lib/http/index.d.ts +1 -1
- package/lib/http/index.js +77 -67
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +33 -23
- package/lib/http/index.mjs.map +1 -1
- package/package.json +3 -3
package/lib/http/index.mjs
CHANGED
@@ -86,6 +86,7 @@ import { isNever } from "@forklaunch/common";
|
|
86
86
|
import { jwtVerify } from "jose";
|
87
87
|
|
88
88
|
// src/http/createHmacToken.ts
|
89
|
+
import { safeStringify } from "@forklaunch/common";
|
89
90
|
import { createHmac } from "crypto";
|
90
91
|
function createHmacToken({
|
91
92
|
method,
|
@@ -96,10 +97,11 @@ function createHmacToken({
|
|
96
97
|
secretKey
|
97
98
|
}) {
|
98
99
|
const hmac = createHmac("sha256", secretKey);
|
100
|
+
const bodyString = body ? `${safeStringify(body)}
|
101
|
+
` : void 0;
|
99
102
|
hmac.update(`${method}
|
100
103
|
${path}
|
101
|
-
${
|
102
|
-
${timestamp}
|
104
|
+
${bodyString}${timestamp}
|
103
105
|
${nonce}`);
|
104
106
|
return hmac.digest("base64");
|
105
107
|
}
|
@@ -172,7 +174,15 @@ async function discriminateAuthMethod(auth) {
|
|
172
174
|
type: "hmac",
|
173
175
|
auth: {
|
174
176
|
secretKeys: auth.hmac.secretKeys,
|
175
|
-
verificationFunction: async (
|
177
|
+
verificationFunction: async ({
|
178
|
+
method,
|
179
|
+
path,
|
180
|
+
body,
|
181
|
+
timestamp,
|
182
|
+
nonce,
|
183
|
+
signature,
|
184
|
+
secretKey
|
185
|
+
}) => {
|
176
186
|
return createHmacToken({
|
177
187
|
method,
|
178
188
|
path,
|
@@ -285,15 +295,15 @@ async function checkAuthorizationToken(authorizationMethod, globalOptions, autho
|
|
285
295
|
if (!parsedKeyId || !parsedTimestamp || !parsedNonce || !parsedSignature) {
|
286
296
|
return invalidAuthorizationTokenFormat;
|
287
297
|
}
|
288
|
-
const verificationResult = await auth.verificationFunction(
|
289
|
-
req?.method ?? "",
|
290
|
-
req?.path ?? "",
|
291
|
-
|
292
|
-
parsedTimestamp,
|
293
|
-
parsedNonce,
|
294
|
-
parsedSignature,
|
295
|
-
collapsedAuthorizationMethod.hmac.secretKeys[parsedKeyId]
|
296
|
-
);
|
298
|
+
const verificationResult = await auth.verificationFunction({
|
299
|
+
method: req?.method ?? "",
|
300
|
+
path: req?.path ?? "",
|
301
|
+
body: req?.body,
|
302
|
+
timestamp: parsedTimestamp,
|
303
|
+
nonce: parsedNonce,
|
304
|
+
signature: parsedSignature,
|
305
|
+
secretKey: collapsedAuthorizationMethod.hmac.secretKeys[parsedKeyId]
|
306
|
+
});
|
297
307
|
if (!verificationResult) {
|
298
308
|
return invalidAuthorizationSignature;
|
299
309
|
}
|
@@ -2919,7 +2929,7 @@ var getCodeForStatus = (status) => {
|
|
2919
2929
|
var httpStatusCodes_default = HTTPStatuses;
|
2920
2930
|
|
2921
2931
|
// src/http/mcpGenerator/mcpGenerator.ts
|
2922
|
-
import { isNever as isNever3, isRecord as isRecord3, safeStringify } from "@forklaunch/common";
|
2932
|
+
import { isNever as isNever3, isRecord as isRecord3, safeStringify as safeStringify2 } from "@forklaunch/common";
|
2923
2933
|
import { FastMCP } from "@forklaunch/fastmcp-fork";
|
2924
2934
|
import { string, ZodSchemaValidator } from "@forklaunch/validator/zod";
|
2925
2935
|
|
@@ -3056,7 +3066,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3056
3066
|
if (discriminatedBody) {
|
3057
3067
|
switch (discriminatedBody.parserType) {
|
3058
3068
|
case "json": {
|
3059
|
-
parsedBody =
|
3069
|
+
parsedBody = safeStringify2(body);
|
3060
3070
|
break;
|
3061
3071
|
}
|
3062
3072
|
case "text": {
|
@@ -3088,7 +3098,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3088
3098
|
parsedBody = new URLSearchParams(
|
3089
3099
|
Object.entries(body).map(([key, value]) => [
|
3090
3100
|
key,
|
3091
|
-
|
3101
|
+
safeStringify2(value)
|
3092
3102
|
])
|
3093
3103
|
);
|
3094
3104
|
} else {
|
@@ -3098,7 +3108,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3098
3108
|
}
|
3099
3109
|
default: {
|
3100
3110
|
isNever3(discriminatedBody.parserType);
|
3101
|
-
parsedBody =
|
3111
|
+
parsedBody = safeStringify2(body);
|
3102
3112
|
break;
|
3103
3113
|
}
|
3104
3114
|
}
|
@@ -3107,7 +3117,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3107
3117
|
const queryString = new URLSearchParams(
|
3108
3118
|
Object.entries(query).map(([key, value]) => [
|
3109
3119
|
key,
|
3110
|
-
|
3120
|
+
safeStringify2(value)
|
3111
3121
|
])
|
3112
3122
|
).toString();
|
3113
3123
|
url += queryString ? `?${queryString}` : "";
|
@@ -3140,7 +3150,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3140
3150
|
content: [
|
3141
3151
|
{
|
3142
3152
|
type: "text",
|
3143
|
-
text:
|
3153
|
+
text: safeStringify2(await response.json())
|
3144
3154
|
}
|
3145
3155
|
]
|
3146
3156
|
};
|
@@ -3302,7 +3312,7 @@ import {
|
|
3302
3312
|
isNodeJsWriteableStream,
|
3303
3313
|
isRecord as isRecord4,
|
3304
3314
|
readableStreamToAsyncIterable,
|
3305
|
-
safeStringify as
|
3315
|
+
safeStringify as safeStringify3
|
3306
3316
|
} from "@forklaunch/common";
|
3307
3317
|
import { Readable, Transform } from "stream";
|
3308
3318
|
|
@@ -3406,7 +3416,7 @@ ${res.locals.errorMessage}`;
|
|
3406
3416
|
if (!errorSent) {
|
3407
3417
|
let data2 = "";
|
3408
3418
|
for (const [key, value] of Object.entries(chunk)) {
|
3409
|
-
data2 += `${key}: ${typeof value === "string" ? value :
|
3419
|
+
data2 += `${key}: ${typeof value === "string" ? value : safeStringify3(value)}
|
3410
3420
|
`;
|
3411
3421
|
}
|
3412
3422
|
data2 += "\n";
|
@@ -3810,7 +3820,7 @@ function generateOpenApiSpecs(schemaValidator, serverUrls, serverDescriptions, a
|
|
3810
3820
|
}
|
3811
3821
|
|
3812
3822
|
// src/http/sdk/sdkClient.ts
|
3813
|
-
import { hashString, safeStringify as
|
3823
|
+
import { hashString, safeStringify as safeStringify4, toRecord as toRecord2 } from "@forklaunch/common";
|
3814
3824
|
|
3815
3825
|
// src/http/guards/isSdkRouter.ts
|
3816
3826
|
function isSdkRouter(value) {
|
@@ -3822,12 +3832,12 @@ function mapToSdk(schemaValidator, routerMap, runningPath = void 0) {
|
|
3822
3832
|
const routerUniquenessCache = /* @__PURE__ */ new Set();
|
3823
3833
|
return Object.fromEntries(
|
3824
3834
|
Object.entries(routerMap).map(([key, value]) => {
|
3825
|
-
if (routerUniquenessCache.has(hashString(
|
3835
|
+
if (routerUniquenessCache.has(hashString(safeStringify4(value)))) {
|
3826
3836
|
throw new Error(
|
3827
3837
|
`SdkClient: Cannot use the same router pointer twice. Please clone the duplicate router with .clone() or only use the router once.`
|
3828
3838
|
);
|
3829
3839
|
}
|
3830
|
-
routerUniquenessCache.add(hashString(
|
3840
|
+
routerUniquenessCache.add(hashString(safeStringify4(value)));
|
3831
3841
|
const currentPath = runningPath ? [runningPath, key].join(".") : key;
|
3832
3842
|
if (isSdkRouter(value)) {
|
3833
3843
|
Object.entries(value.sdkPaths).forEach(([routePath, sdkKey]) => {
|