@forklaunch/core 0.14.16 → 0.15.1-debug-hmac

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.
@@ -21,7 +21,9 @@ function cors(corsOptions) {
21
21
 
22
22
  // src/http/router/expressLikeRouter.ts
23
23
  import {
24
+ hashString,
24
25
  isRecord as isRecord2,
26
+ safeStringify as safeStringify2,
25
27
  sanitizePathSlashes,
26
28
  toPrettyCamelCase,
27
29
  toRecord
@@ -74,6 +76,11 @@ function isHttpContractDetails(maybeContractDetails) {
74
76
  ));
75
77
  }
76
78
 
79
+ // src/http/guards/isSdkHandler.ts
80
+ function isSdkHandler(handler) {
81
+ return typeof handler === "object" && handler !== null && "_path" in handler && "_method" in handler && "contractDetails" in handler;
82
+ }
83
+
77
84
  // src/http/guards/isTypedHandler.ts
78
85
  function isTypedHandler(maybeTypedHandler) {
79
86
  return maybeTypedHandler != null && typeof maybeTypedHandler === "object" && "_typedHandler" in maybeTypedHandler && maybeTypedHandler._typedHandler === true;
@@ -319,6 +326,13 @@ async function checkAuthorizationToken(req, authorizationMethod, authorizationTo
319
326
  const parsedTimestamp = parseHmacTokenPart(timestamp, "ts");
320
327
  const parsedNonce = parseHmacTokenPart(nonce, "nonce");
321
328
  const parsedSignature = parseHmacTokenPart(signature, "signature");
329
+ console.log(
330
+ "parseditems",
331
+ parsedKeyId,
332
+ parsedTimestamp,
333
+ parsedNonce,
334
+ parsedSignature
335
+ );
322
336
  if (!parsedKeyId || !parsedTimestamp || !parsedNonce || !parsedSignature) {
323
337
  return invalidAuthorizationTokenFormat;
324
338
  }
@@ -1829,6 +1843,53 @@ var ForklaunchExpressLikeRouter = class _ForklaunchExpressLikeRouter {
1829
1843
  ...middlewareOrMiddlewareWithTypedHandler
1830
1844
  );
1831
1845
  };
1846
+ insertIntoRouterSdkPaths({
1847
+ sdkPath,
1848
+ path,
1849
+ method,
1850
+ name
1851
+ }) {
1852
+ const routePath = [method, path].join(".");
1853
+ for (const route of this.routes) {
1854
+ if (route.path === path && route.method === method && route.contractDetails.name === name) {
1855
+ this.sdkPaths[routePath] = sdkPath;
1856
+ }
1857
+ }
1858
+ for (const router of this.routers) {
1859
+ router.insertIntoRouterSdkPaths?.({
1860
+ sdkPath,
1861
+ path,
1862
+ method,
1863
+ name
1864
+ });
1865
+ }
1866
+ }
1867
+ unpackSdks(sdks, path, routerUniquenessCache) {
1868
+ Object.entries(sdks).forEach(([key, maybeHandler]) => {
1869
+ if (isSdkHandler(maybeHandler)) {
1870
+ const cacheKey = hashString(safeStringify2(maybeHandler));
1871
+ if (routerUniquenessCache.has(cacheKey)) {
1872
+ throw new Error(`SDK handler ${key} is already registered`);
1873
+ }
1874
+ routerUniquenessCache.add(cacheKey);
1875
+ if (!maybeHandler._method || !maybeHandler._path) {
1876
+ throw new Error(`SDK handler ${key} is missing method or path`);
1877
+ }
1878
+ this.insertIntoRouterSdkPaths({
1879
+ sdkPath: [...path, key].join("."),
1880
+ path: maybeHandler._path,
1881
+ method: maybeHandler._method,
1882
+ name: maybeHandler.contractDetails.name
1883
+ });
1884
+ routerUniquenessCache.add(cacheKey);
1885
+ } else {
1886
+ this.unpackSdks(maybeHandler, [...path, key], routerUniquenessCache);
1887
+ }
1888
+ });
1889
+ }
1890
+ registerSdks(sdks) {
1891
+ this.unpackSdks(sdks, [], /* @__PURE__ */ new Set());
1892
+ }
1832
1893
  cloneInternals(clone) {
1833
1894
  clone.routers = [...this.routers];
1834
1895
  clone.routes = [...this.routes];
@@ -2970,7 +3031,7 @@ var getCodeForStatus = (status) => {
2970
3031
  var httpStatusCodes_default = HTTPStatuses;
2971
3032
 
2972
3033
  // src/http/mcpGenerator/mcpGenerator.ts
2973
- import { isNever as isNever3, isRecord as isRecord3, safeStringify as safeStringify2 } from "@forklaunch/common";
3034
+ import { isNever as isNever3, isRecord as isRecord3, safeStringify as safeStringify3 } from "@forklaunch/common";
2974
3035
  import { FastMCP } from "@forklaunch/fastmcp-fork";
2975
3036
  import { string, ZodSchemaValidator } from "@forklaunch/validator/zod";
2976
3037
 
@@ -3107,7 +3168,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3107
3168
  if (discriminatedBody) {
3108
3169
  switch (discriminatedBody.parserType) {
3109
3170
  case "json": {
3110
- parsedBody = safeStringify2(body);
3171
+ parsedBody = safeStringify3(body);
3111
3172
  break;
3112
3173
  }
3113
3174
  case "text": {
@@ -3139,7 +3200,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3139
3200
  parsedBody = new URLSearchParams(
3140
3201
  Object.entries(body).map(([key, value]) => [
3141
3202
  key,
3142
- safeStringify2(value)
3203
+ safeStringify3(value)
3143
3204
  ])
3144
3205
  );
3145
3206
  } else {
@@ -3149,7 +3210,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3149
3210
  }
3150
3211
  default: {
3151
3212
  isNever3(discriminatedBody.parserType);
3152
- parsedBody = safeStringify2(body);
3213
+ parsedBody = safeStringify3(body);
3153
3214
  break;
3154
3215
  }
3155
3216
  }
@@ -3158,7 +3219,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3158
3219
  const queryString = new URLSearchParams(
3159
3220
  Object.entries(query).map(([key, value]) => [
3160
3221
  key,
3161
- safeStringify2(value)
3222
+ safeStringify3(value)
3162
3223
  ])
3163
3224
  ).toString();
3164
3225
  url += queryString ? `?${queryString}` : "";
@@ -3191,7 +3252,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3191
3252
  content: [
3192
3253
  {
3193
3254
  type: "text",
3194
- text: safeStringify2(await response.json())
3255
+ text: safeStringify3(await response.json())
3195
3256
  }
3196
3257
  ]
3197
3258
  };
@@ -3353,7 +3414,7 @@ import {
3353
3414
  isNodeJsWriteableStream,
3354
3415
  isRecord as isRecord4,
3355
3416
  readableStreamToAsyncIterable,
3356
- safeStringify as safeStringify3
3417
+ safeStringify as safeStringify4
3357
3418
  } from "@forklaunch/common";
3358
3419
  import { Readable, Transform } from "stream";
3359
3420
 
@@ -3457,7 +3518,7 @@ ${res.locals.errorMessage}`;
3457
3518
  if (!errorSent) {
3458
3519
  let data2 = "";
3459
3520
  for (const [key, value] of Object.entries(chunk)) {
3460
- data2 += `${key}: ${typeof value === "string" ? value : safeStringify3(value)}
3521
+ data2 += `${key}: ${typeof value === "string" ? value : safeStringify4(value)}
3461
3522
  `;
3462
3523
  }
3463
3524
  data2 += "\n";
@@ -3860,109 +3921,6 @@ function generateOpenApiSpecs(schemaValidator, serverUrls, serverDescriptions, a
3860
3921
  );
3861
3922
  }
3862
3923
 
3863
- // src/http/sdk/sdkClient.ts
3864
- import { hashString, safeStringify as safeStringify4, toRecord as toRecord2 } from "@forklaunch/common";
3865
-
3866
- // src/http/guards/isSdkRouter.ts
3867
- function isSdkRouter(value) {
3868
- return typeof value === "object" && value !== null && "sdk" in value && "_fetchMap" in value && "sdkPaths" in value;
3869
- }
3870
-
3871
- // src/http/sdk/sdkClient.ts
3872
- function mapToSdk(schemaValidator, routerMap, runningPath = void 0) {
3873
- const routerUniquenessCache = /* @__PURE__ */ new Set();
3874
- return Object.fromEntries(
3875
- Object.entries(routerMap).map(([key, value]) => {
3876
- if (routerUniquenessCache.has(hashString(safeStringify4(value)))) {
3877
- throw new Error(
3878
- `SdkClient: Cannot use the same router pointer twice. Please clone the duplicate router with .clone() or only use the router once.`
3879
- );
3880
- }
3881
- routerUniquenessCache.add(hashString(safeStringify4(value)));
3882
- const currentPath = runningPath ? [runningPath, key].join(".") : key;
3883
- if (isSdkRouter(value)) {
3884
- Object.entries(value.sdkPaths).forEach(([routePath, sdkKey]) => {
3885
- if ("controllerSdkPaths" in value && Array.isArray(value.controllerSdkPaths) && value.controllerSdkPaths.includes(routePath)) {
3886
- value.sdkPaths[routePath] = [currentPath, sdkKey].join(".");
3887
- }
3888
- });
3889
- return [key, value.sdk];
3890
- } else {
3891
- return [
3892
- key,
3893
- mapToSdk(
3894
- schemaValidator,
3895
- value,
3896
- runningPath ? [runningPath, key].join(".") : key
3897
- )
3898
- ];
3899
- }
3900
- })
3901
- );
3902
- }
3903
- function flattenFetchMap(schemaValidator, routerMap) {
3904
- const _fetchMap = Object.entries(routerMap).reduce(
3905
- (acc, [, value]) => {
3906
- if ("_fetchMap" in value) {
3907
- return {
3908
- ...acc,
3909
- ...value._fetchMap
3910
- };
3911
- } else {
3912
- return {
3913
- ...acc,
3914
- ...flattenFetchMap(schemaValidator, value)
3915
- };
3916
- }
3917
- },
3918
- {}
3919
- );
3920
- return _fetchMap;
3921
- }
3922
- function mapToFetch(schemaValidator, routerMap) {
3923
- const flattenedFetchMap = flattenFetchMap(
3924
- schemaValidator,
3925
- routerMap
3926
- );
3927
- return ((path, ...reqInit) => {
3928
- const method = reqInit[0]?.method;
3929
- const version = reqInit[0] != null && "version" in reqInit[0] ? reqInit[0].version : void 0;
3930
- return (version ? toRecord2(toRecord2(flattenedFetchMap[path])[method ?? "GET"])[version] : toRecord2(flattenedFetchMap[path])[method ?? "GET"])(path, reqInit[0]);
3931
- });
3932
- }
3933
- function sdkClient(schemaValidator, routerMap) {
3934
- return {
3935
- _finalizedSdk: true,
3936
- sdk: mapToSdk(schemaValidator, routerMap),
3937
- fetch: mapToFetch(schemaValidator, routerMap)
3938
- };
3939
- }
3940
-
3941
- // src/http/sdk/sdkRouter.ts
3942
- import { toPrettyCamelCase as toPrettyCamelCase2 } from "@forklaunch/common";
3943
- function sdkRouter(schemaValidator, controller, router) {
3944
- const controllerSdkPaths = [];
3945
- const mappedSdk = Object.fromEntries(
3946
- Object.entries(controller).map(([key, value]) => {
3947
- const sdkPath = [value._method, value._path].join(".");
3948
- controllerSdkPaths.push(sdkPath);
3949
- router.sdkPaths[sdkPath] = key;
3950
- return [
3951
- key,
3952
- router.sdk[toPrettyCamelCase2(value.contractDetails.name)]
3953
- ];
3954
- })
3955
- );
3956
- const _fetchMap = router._fetchMap;
3957
- return {
3958
- sdk: mappedSdk,
3959
- fetch: router.fetch,
3960
- _fetchMap,
3961
- sdkPaths: router.sdkPaths,
3962
- controllerSdkPaths
3963
- };
3964
- }
3965
-
3966
3924
  // src/http/telemetry/evaluateTelemetryOptions.ts
3967
3925
  function evaluateTelemetryOptions(telemetryOptions) {
3968
3926
  return {
@@ -4028,8 +3986,6 @@ export {
4028
3986
  post,
4029
3987
  put,
4030
3988
  recordMetric,
4031
- sdkClient,
4032
- sdkRouter,
4033
3989
  trace3 as trace,
4034
3990
  typedAuthHandler,
4035
3991
  typedHandler