@forklaunch/core 0.14.15 → 0.15.0

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;
@@ -1829,6 +1836,53 @@ var ForklaunchExpressLikeRouter = class _ForklaunchExpressLikeRouter {
1829
1836
  ...middlewareOrMiddlewareWithTypedHandler
1830
1837
  );
1831
1838
  };
1839
+ insertIntoRouterSdkPaths({
1840
+ sdkPath,
1841
+ path,
1842
+ method,
1843
+ name
1844
+ }) {
1845
+ const routePath = [method, path].join(".");
1846
+ for (const route of this.routes) {
1847
+ if (route.path === path && route.method === method && route.contractDetails.name === name) {
1848
+ this.sdkPaths[routePath] = sdkPath;
1849
+ }
1850
+ }
1851
+ for (const router of this.routers) {
1852
+ router.insertIntoRouterSdkPaths?.({
1853
+ sdkPath,
1854
+ path,
1855
+ method,
1856
+ name
1857
+ });
1858
+ }
1859
+ }
1860
+ unpackSdks(sdks, path, routerUniquenessCache) {
1861
+ Object.entries(sdks).forEach(([key, maybeHandler]) => {
1862
+ if (isSdkHandler(maybeHandler)) {
1863
+ const cacheKey = hashString(safeStringify2(maybeHandler));
1864
+ if (routerUniquenessCache.has(cacheKey)) {
1865
+ throw new Error(`SDK handler ${key} is already registered`);
1866
+ }
1867
+ routerUniquenessCache.add(cacheKey);
1868
+ if (!maybeHandler._method || !maybeHandler._path) {
1869
+ throw new Error(`SDK handler ${key} is missing method or path`);
1870
+ }
1871
+ this.insertIntoRouterSdkPaths({
1872
+ sdkPath: [...path, key].join("."),
1873
+ path: maybeHandler._path,
1874
+ method: maybeHandler._method,
1875
+ name: maybeHandler.contractDetails.name
1876
+ });
1877
+ routerUniquenessCache.add(cacheKey);
1878
+ } else {
1879
+ this.unpackSdks(maybeHandler, [...path, key], routerUniquenessCache);
1880
+ }
1881
+ });
1882
+ }
1883
+ registerSdks(sdks) {
1884
+ this.unpackSdks(sdks, [], /* @__PURE__ */ new Set());
1885
+ }
1832
1886
  cloneInternals(clone) {
1833
1887
  clone.routers = [...this.routers];
1834
1888
  clone.routes = [...this.routes];
@@ -2970,7 +3024,7 @@ var getCodeForStatus = (status) => {
2970
3024
  var httpStatusCodes_default = HTTPStatuses;
2971
3025
 
2972
3026
  // src/http/mcpGenerator/mcpGenerator.ts
2973
- import { isNever as isNever3, isRecord as isRecord3, safeStringify as safeStringify2 } from "@forklaunch/common";
3027
+ import { isNever as isNever3, isRecord as isRecord3, safeStringify as safeStringify3 } from "@forklaunch/common";
2974
3028
  import { FastMCP } from "@forklaunch/fastmcp-fork";
2975
3029
  import { string, ZodSchemaValidator } from "@forklaunch/validator/zod";
2976
3030
 
@@ -3107,7 +3161,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3107
3161
  if (discriminatedBody) {
3108
3162
  switch (discriminatedBody.parserType) {
3109
3163
  case "json": {
3110
- parsedBody = safeStringify2(body);
3164
+ parsedBody = safeStringify3(body);
3111
3165
  break;
3112
3166
  }
3113
3167
  case "text": {
@@ -3139,7 +3193,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3139
3193
  parsedBody = new URLSearchParams(
3140
3194
  Object.entries(body).map(([key, value]) => [
3141
3195
  key,
3142
- safeStringify2(value)
3196
+ safeStringify3(value)
3143
3197
  ])
3144
3198
  );
3145
3199
  } else {
@@ -3149,7 +3203,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3149
3203
  }
3150
3204
  default: {
3151
3205
  isNever3(discriminatedBody.parserType);
3152
- parsedBody = safeStringify2(body);
3206
+ parsedBody = safeStringify3(body);
3153
3207
  break;
3154
3208
  }
3155
3209
  }
@@ -3158,7 +3212,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3158
3212
  const queryString = new URLSearchParams(
3159
3213
  Object.entries(query).map(([key, value]) => [
3160
3214
  key,
3161
- safeStringify2(value)
3215
+ safeStringify3(value)
3162
3216
  ])
3163
3217
  ).toString();
3164
3218
  url += queryString ? `?${queryString}` : "";
@@ -3191,7 +3245,7 @@ function generateMcpServer(schemaValidator, protocol, host, port, version, appli
3191
3245
  content: [
3192
3246
  {
3193
3247
  type: "text",
3194
- text: safeStringify2(await response.json())
3248
+ text: safeStringify3(await response.json())
3195
3249
  }
3196
3250
  ]
3197
3251
  };
@@ -3353,7 +3407,7 @@ import {
3353
3407
  isNodeJsWriteableStream,
3354
3408
  isRecord as isRecord4,
3355
3409
  readableStreamToAsyncIterable,
3356
- safeStringify as safeStringify3
3410
+ safeStringify as safeStringify4
3357
3411
  } from "@forklaunch/common";
3358
3412
  import { Readable, Transform } from "stream";
3359
3413
 
@@ -3457,7 +3511,7 @@ ${res.locals.errorMessage}`;
3457
3511
  if (!errorSent) {
3458
3512
  let data2 = "";
3459
3513
  for (const [key, value] of Object.entries(chunk)) {
3460
- data2 += `${key}: ${typeof value === "string" ? value : safeStringify3(value)}
3514
+ data2 += `${key}: ${typeof value === "string" ? value : safeStringify4(value)}
3461
3515
  `;
3462
3516
  }
3463
3517
  data2 += "\n";
@@ -3860,109 +3914,6 @@ function generateOpenApiSpecs(schemaValidator, serverUrls, serverDescriptions, a
3860
3914
  );
3861
3915
  }
3862
3916
 
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
3917
  // src/http/telemetry/evaluateTelemetryOptions.ts
3967
3918
  function evaluateTelemetryOptions(telemetryOptions) {
3968
3919
  return {
@@ -3997,6 +3948,7 @@ export {
3997
3948
  OpenTelemetryCollector,
3998
3949
  createHmacToken,
3999
3950
  delete_,
3951
+ discriminateAuthMethod,
4000
3952
  discriminateBody,
4001
3953
  discriminateResponseBodies,
4002
3954
  enrichExpressLikeSend,
@@ -4004,6 +3956,7 @@ export {
4004
3956
  generateMcpServer,
4005
3957
  generateOpenApiSpecs,
4006
3958
  get,
3959
+ getCachedJwks,
4007
3960
  getCodeForStatus,
4008
3961
  head,
4009
3962
  httpRequestsTotalCounter,
@@ -4026,8 +3979,6 @@ export {
4026
3979
  post,
4027
3980
  put,
4028
3981
  recordMetric,
4029
- sdkClient,
4030
- sdkRouter,
4031
3982
  trace3 as trace,
4032
3983
  typedAuthHandler,
4033
3984
  typedHandler