@forklaunch/core 0.14.7 → 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 +24 -5
- package/lib/http/index.d.ts +24 -5
- package/lib/http/index.js +104 -74
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +59 -30
- package/lib/http/index.mjs.map +1 -1
- package/package.json +4 -4
package/lib/http/index.mjs
CHANGED
@@ -83,9 +83,29 @@ function isTypedHandler(maybeTypedHandler) {
|
|
83
83
|
import { isNever } from "@forklaunch/common";
|
84
84
|
|
85
85
|
// src/http/discriminateAuthMethod.ts
|
86
|
-
import { createHmac } from "crypto";
|
87
86
|
import { jwtVerify } from "jose";
|
88
87
|
|
88
|
+
// src/http/createHmacToken.ts
|
89
|
+
import { safeStringify } from "@forklaunch/common";
|
90
|
+
import { createHmac } from "crypto";
|
91
|
+
function createHmacToken({
|
92
|
+
method,
|
93
|
+
path,
|
94
|
+
body,
|
95
|
+
timestamp,
|
96
|
+
nonce,
|
97
|
+
secretKey
|
98
|
+
}) {
|
99
|
+
const hmac = createHmac("sha256", secretKey);
|
100
|
+
const bodyString = body ? `${safeStringify(body)}
|
101
|
+
` : void 0;
|
102
|
+
hmac.update(`${method}
|
103
|
+
${path}
|
104
|
+
${bodyString}${timestamp}
|
105
|
+
${nonce}`);
|
106
|
+
return hmac.digest("base64");
|
107
|
+
}
|
108
|
+
|
89
109
|
// src/http/guards/isBasicAuthMethod.ts
|
90
110
|
function isBasicAuthMethod(maybeBasicAuthMethod) {
|
91
111
|
return typeof maybeBasicAuthMethod === "object" && maybeBasicAuthMethod !== null && "basic" in maybeBasicAuthMethod && maybeBasicAuthMethod.basic != null;
|
@@ -154,15 +174,23 @@ async function discriminateAuthMethod(auth) {
|
|
154
174
|
type: "hmac",
|
155
175
|
auth: {
|
156
176
|
secretKeys: auth.hmac.secretKeys,
|
157
|
-
verificationFunction: async (
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
177
|
+
verificationFunction: async ({
|
178
|
+
method,
|
179
|
+
path,
|
180
|
+
body,
|
181
|
+
timestamp,
|
182
|
+
nonce,
|
183
|
+
signature,
|
184
|
+
secretKey
|
185
|
+
}) => {
|
186
|
+
return createHmacToken({
|
187
|
+
method,
|
188
|
+
path,
|
189
|
+
body,
|
190
|
+
timestamp,
|
191
|
+
nonce,
|
192
|
+
secretKey
|
193
|
+
}) === signature;
|
166
194
|
}
|
167
195
|
}
|
168
196
|
};
|
@@ -267,15 +295,15 @@ async function checkAuthorizationToken(authorizationMethod, globalOptions, autho
|
|
267
295
|
if (!parsedKeyId || !parsedTimestamp || !parsedNonce || !parsedSignature) {
|
268
296
|
return invalidAuthorizationTokenFormat;
|
269
297
|
}
|
270
|
-
const verificationResult = await auth.verificationFunction(
|
271
|
-
req?.method ?? "",
|
272
|
-
req?.path ?? "",
|
273
|
-
|
274
|
-
parsedTimestamp,
|
275
|
-
parsedNonce,
|
276
|
-
parsedSignature,
|
277
|
-
collapsedAuthorizationMethod.hmac.secretKeys[parsedKeyId]
|
278
|
-
);
|
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
|
+
});
|
279
307
|
if (!verificationResult) {
|
280
308
|
return invalidAuthorizationSignature;
|
281
309
|
}
|
@@ -2901,7 +2929,7 @@ var getCodeForStatus = (status) => {
|
|
2901
2929
|
var httpStatusCodes_default = HTTPStatuses;
|
2902
2930
|
|
2903
2931
|
// src/http/mcpGenerator/mcpGenerator.ts
|
2904
|
-
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";
|
2905
2933
|
import { FastMCP } from "@forklaunch/fastmcp-fork";
|
2906
2934
|
import { string, ZodSchemaValidator } from "@forklaunch/validator/zod";
|
2907
2935
|
|
@@ -3038,7 +3066,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3038
3066
|
if (discriminatedBody) {
|
3039
3067
|
switch (discriminatedBody.parserType) {
|
3040
3068
|
case "json": {
|
3041
|
-
parsedBody =
|
3069
|
+
parsedBody = safeStringify2(body);
|
3042
3070
|
break;
|
3043
3071
|
}
|
3044
3072
|
case "text": {
|
@@ -3070,7 +3098,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3070
3098
|
parsedBody = new URLSearchParams(
|
3071
3099
|
Object.entries(body).map(([key, value]) => [
|
3072
3100
|
key,
|
3073
|
-
|
3101
|
+
safeStringify2(value)
|
3074
3102
|
])
|
3075
3103
|
);
|
3076
3104
|
} else {
|
@@ -3080,7 +3108,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3080
3108
|
}
|
3081
3109
|
default: {
|
3082
3110
|
isNever3(discriminatedBody.parserType);
|
3083
|
-
parsedBody =
|
3111
|
+
parsedBody = safeStringify2(body);
|
3084
3112
|
break;
|
3085
3113
|
}
|
3086
3114
|
}
|
@@ -3089,7 +3117,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3089
3117
|
const queryString = new URLSearchParams(
|
3090
3118
|
Object.entries(query).map(([key, value]) => [
|
3091
3119
|
key,
|
3092
|
-
|
3120
|
+
safeStringify2(value)
|
3093
3121
|
])
|
3094
3122
|
).toString();
|
3095
3123
|
url += queryString ? `?${queryString}` : "";
|
@@ -3122,7 +3150,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
|
|
3122
3150
|
content: [
|
3123
3151
|
{
|
3124
3152
|
type: "text",
|
3125
|
-
text:
|
3153
|
+
text: safeStringify2(await response.json())
|
3126
3154
|
}
|
3127
3155
|
]
|
3128
3156
|
};
|
@@ -3284,7 +3312,7 @@ import {
|
|
3284
3312
|
isNodeJsWriteableStream,
|
3285
3313
|
isRecord as isRecord4,
|
3286
3314
|
readableStreamToAsyncIterable,
|
3287
|
-
safeStringify as
|
3315
|
+
safeStringify as safeStringify3
|
3288
3316
|
} from "@forklaunch/common";
|
3289
3317
|
import { Readable, Transform } from "stream";
|
3290
3318
|
|
@@ -3388,7 +3416,7 @@ ${res.locals.errorMessage}`;
|
|
3388
3416
|
if (!errorSent) {
|
3389
3417
|
let data2 = "";
|
3390
3418
|
for (const [key, value] of Object.entries(chunk)) {
|
3391
|
-
data2 += `${key}: ${typeof value === "string" ? value :
|
3419
|
+
data2 += `${key}: ${typeof value === "string" ? value : safeStringify3(value)}
|
3392
3420
|
`;
|
3393
3421
|
}
|
3394
3422
|
data2 += "\n";
|
@@ -3792,7 +3820,7 @@ function generateOpenApiSpecs(schemaValidator, serverUrls, serverDescriptions, a
|
|
3792
3820
|
}
|
3793
3821
|
|
3794
3822
|
// src/http/sdk/sdkClient.ts
|
3795
|
-
import { hashString, safeStringify as
|
3823
|
+
import { hashString, safeStringify as safeStringify4, toRecord as toRecord2 } from "@forklaunch/common";
|
3796
3824
|
|
3797
3825
|
// src/http/guards/isSdkRouter.ts
|
3798
3826
|
function isSdkRouter(value) {
|
@@ -3804,12 +3832,12 @@ function mapToSdk(schemaValidator, routerMap, runningPath = void 0) {
|
|
3804
3832
|
const routerUniquenessCache = /* @__PURE__ */ new Set();
|
3805
3833
|
return Object.fromEntries(
|
3806
3834
|
Object.entries(routerMap).map(([key, value]) => {
|
3807
|
-
if (routerUniquenessCache.has(hashString(
|
3835
|
+
if (routerUniquenessCache.has(hashString(safeStringify4(value)))) {
|
3808
3836
|
throw new Error(
|
3809
3837
|
`SdkClient: Cannot use the same router pointer twice. Please clone the duplicate router with .clone() or only use the router once.`
|
3810
3838
|
);
|
3811
3839
|
}
|
3812
|
-
routerUniquenessCache.add(hashString(
|
3840
|
+
routerUniquenessCache.add(hashString(safeStringify4(value)));
|
3813
3841
|
const currentPath = runningPath ? [runningPath, key].join(".") : key;
|
3814
3842
|
if (isSdkRouter(value)) {
|
3815
3843
|
Object.entries(value.sdkPaths).forEach(([routePath, sdkKey]) => {
|
@@ -3926,6 +3954,7 @@ export {
|
|
3926
3954
|
HTTPStatuses,
|
3927
3955
|
OPENAPI_DEFAULT_VERSION,
|
3928
3956
|
OpenTelemetryCollector,
|
3957
|
+
createHmacToken,
|
3929
3958
|
delete_,
|
3930
3959
|
discriminateBody,
|
3931
3960
|
discriminateResponseBodies,
|