@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.
- package/lib/http/index.d.mts +51 -222
- package/lib/http/index.d.ts +51 -222
- package/lib/http/index.js +59 -107
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +69 -113
- package/lib/http/index.mjs.map +1 -1
- package/package.json +10 -10
package/lib/http/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ParsedQs } from 'qs';
|
2
2
|
export { ParsedQs } from 'qs';
|
3
|
-
import { UnionToIntersection, TypeSafeFunction, StringWithoutSlash, Prettify,
|
3
|
+
import { UnionToIntersection, TypeSafeFunction, StringWithoutSlash, Prettify, MakePropertyOptionalIfChildrenOptional, SanitizePathSlashes, PrettyCamelCase, EmptyObject } from '@forklaunch/common';
|
4
4
|
import { AnySchemaValidator, UnboxedObjectSchema, IdiomaticSchema, Schema } from '@forklaunch/validator';
|
5
5
|
import { ServerOptions, IncomingMessage, ServerResponse } from 'node:http';
|
6
6
|
import { Counter, Gauge, Histogram, UpDownCounter, ObservableCounter, ObservableGauge, ObservableUpDownCounter, Span } from '@opentelemetry/api';
|
@@ -1111,6 +1111,13 @@ interface ForklaunchRouter<SV extends AnySchemaValidator> {
|
|
1111
1111
|
sdkPaths: Record<string, string>;
|
1112
1112
|
/** Options for the router */
|
1113
1113
|
routerOptions?: ExpressLikeRouterOptions<SV, SessionObject<SV>>;
|
1114
|
+
/** Insert the SDK path into the router */
|
1115
|
+
insertIntoRouterSdkPaths?: (params: {
|
1116
|
+
sdkPath: string;
|
1117
|
+
path: string;
|
1118
|
+
method: string;
|
1119
|
+
name: string;
|
1120
|
+
}) => void;
|
1114
1121
|
}
|
1115
1122
|
/**
|
1116
1123
|
* Interface representing a Forklaunch route.
|
@@ -1356,33 +1363,28 @@ type RouterMap<SV extends AnySchemaValidator> = {
|
|
1356
1363
|
[K: string]: SdkRouter | RouterMap<SV>;
|
1357
1364
|
};
|
1358
1365
|
/**
|
1359
|
-
*
|
1360
|
-
*
|
1361
|
-
* Traverses the nested router map and collects all SDK interfaces into a flat structure.
|
1366
|
+
* Recursive type representing a hierarchical map of SDK handlers.
|
1367
|
+
* Each key can either be a leaf node containing a SdkHandler, or a nested SdkHandlerObject for deeper structures.
|
1362
1368
|
*
|
1363
|
-
* @template SV - The schema validator type
|
1364
|
-
* @template T - The RouterMap to extract SDKs from
|
1365
|
-
* @template Acc - The accumulator type for collecting SDK interfaces (defaults to empty object)
|
1366
|
-
* @param SV - Must extend AnySchemaValidator
|
1367
|
-
* @param T - Must extend RouterMap<SV>
|
1368
|
-
* @param Acc - The accumulated SDK interfaces so far
|
1369
|
-
*
|
1370
|
-
* @returns A mapped type where each key corresponds to the original router structure,
|
1371
|
-
* but values are the extracted SDK interfaces instead of the full router configuration
|
1369
|
+
* @template SV - The schema validator type that constrains the handler structure.
|
1372
1370
|
*
|
1373
1371
|
* @example
|
1374
1372
|
* ```typescript
|
1375
|
-
*
|
1376
|
-
*
|
1377
|
-
*
|
1373
|
+
* const handlers: SdkHandlerObject<ZodValidator> = {
|
1374
|
+
* users: {
|
1375
|
+
* getUser: someSdkHandler,
|
1376
|
+
* posts: {
|
1377
|
+
* getPosts: anotherSdkHandler
|
1378
|
+
* }
|
1379
|
+
* }
|
1380
|
+
* };
|
1378
1381
|
* ```
|
1379
1382
|
*/
|
1380
|
-
type
|
1381
|
-
[K
|
1382
|
-
|
1383
|
-
} ? T[K]['sdk'] : T[K] extends RouterMap<SV> ? MapToSdk<SV, T[K], Acc> : never;
|
1384
|
-
}>;
|
1383
|
+
type SdkHandlerObject<SV extends AnySchemaValidator> = {
|
1384
|
+
[K: string]: SdkHandler | SdkHandlerObject<SV>;
|
1385
|
+
};
|
1385
1386
|
/**
|
1387
|
+
* @deprecated
|
1386
1388
|
* Tail-recursive type that extracts and flattens fetch map interfaces from a RouterMap structure.
|
1387
1389
|
* This version uses an accumulator pattern to avoid deep recursion and improve performance.
|
1388
1390
|
* Similar to MapToSdk but focuses on _fetchMap properties and merges all fetch maps into a single intersection type.
|
@@ -1409,7 +1411,6 @@ type MapToFetch<SV extends AnySchemaValidator, T extends RouterMap<SV>> = UnionT
|
|
1409
1411
|
_fetchMap: unknown;
|
1410
1412
|
} ? T[K]['_fetchMap'] extends Record<string, unknown> ? T[K]['_fetchMap'] : never : never;
|
1411
1413
|
}[keyof T]>>;
|
1412
|
-
type CollectionOptimized<T> = T extends infer U ? U : never;
|
1413
1414
|
/**
|
1414
1415
|
* Base interface for controller entries that defines the structure
|
1415
1416
|
* of each controller method with its path, HTTP method, and contract details.
|
@@ -1458,10 +1459,25 @@ type SdkHandler = {
|
|
1458
1459
|
versions?: unknown;
|
1459
1460
|
};
|
1460
1461
|
};
|
1461
|
-
type MapControllerToSdk<SV extends AnySchemaValidator, T extends Record<string, SdkHandler>> = CollectionOptimized<{
|
1462
|
-
[K in keyof T]: LiveSdkFunction<SV, T[K]['contractDetails']['params'] extends infer Params | undefined ? Params extends ParamsObject<SV> ? Params : ParamsObject<SV> : ParamsObject<SV>, T[K]['contractDetails']['responses'] extends infer Responses | undefined ? Responses extends ResponsesObject<SV> ? Responses : ResponsesObject<SV> : ResponsesObject<SV>, T[K]['contractDetails']['body'] extends infer B | undefined ? B extends Body<SV> ? B : Body<SV> : Body<SV>, T[K]['contractDetails']['query'] extends infer Q | undefined ? Q extends QueryObject<SV> ? Q : QueryObject<SV> : QueryObject<SV>, T[K]['contractDetails']['requestHeaders'] extends infer RequestHeaders | undefined ? RequestHeaders extends HeadersObject<SV> ? RequestHeaders : HeadersObject<SV> : HeadersObject<SV>, T[K]['contractDetails']['responseHeaders'] extends infer ResponseHeaders | undefined ? ResponseHeaders extends HeadersObject<SV> ? ResponseHeaders : HeadersObject<SV> : HeadersObject<SV>, T[K]['contractDetails']['versions'] extends infer Versions | undefined ? Versions extends VersionSchema<SV, Method> ? Versions : VersionSchema<SV, Method> : VersionSchema<SV, Method>, T[K]['contractDetails']['auth'] extends infer Auth | undefined ? Auth extends AuthMethodsBase ? Auth : AuthMethodsBase : AuthMethodsBase>;
|
1463
|
-
}>;
|
1464
1462
|
/**
|
1463
|
+
* Recursively maps a client controller definition to its corresponding live SDK function types.
|
1464
|
+
*
|
1465
|
+
* This utility type traverses the structure of a client controller object, replacing each
|
1466
|
+
* {@link SdkHandler} with its corresponding {@link MapHandlerToLiveSdk} type, while recursively
|
1467
|
+
* processing nested objects. This enables type-safe SDK generation for complex controller hierarchies.
|
1468
|
+
*
|
1469
|
+
* @template SV - The schema validator type (e.g., zod, typebox).
|
1470
|
+
* @template Client - The client controller object to map.
|
1471
|
+
*
|
1472
|
+
* @example
|
1473
|
+
* type MySdk = MapToSdk<typeof z, typeof myController>;
|
1474
|
+
*/
|
1475
|
+
type MapToSdk<SV extends AnySchemaValidator, Client> = {
|
1476
|
+
[K in keyof Client]: Client[K] extends SdkHandler ? MapHandlerToLiveSdk<SV, Client[K]> : MapToSdk<SV, Client[K]>;
|
1477
|
+
};
|
1478
|
+
type MapHandlerToLiveSdk<SV extends AnySchemaValidator, T extends SdkHandler> = LiveSdkFunction<SV, T['contractDetails']['params'] extends infer Params | undefined ? Params extends ParamsObject<SV> ? Params : ParamsObject<SV> : ParamsObject<SV>, T['contractDetails']['responses'] extends infer Responses | undefined ? Responses extends ResponsesObject<SV> ? Responses : ResponsesObject<SV> : ResponsesObject<SV>, T['contractDetails']['body'] extends infer B | undefined ? B extends Body<SV> ? B : Body<SV> : Body<SV>, T['contractDetails']['query'] extends infer Q | undefined ? Q extends QueryObject<SV> ? Q : QueryObject<SV> : QueryObject<SV>, T['contractDetails']['requestHeaders'] extends infer RequestHeaders | undefined ? RequestHeaders extends HeadersObject<SV> ? RequestHeaders : HeadersObject<SV> : HeadersObject<SV>, T['contractDetails']['responseHeaders'] extends infer ResponseHeaders | undefined ? ResponseHeaders extends HeadersObject<SV> ? ResponseHeaders : HeadersObject<SV> : HeadersObject<SV>, T['contractDetails']['versions'] extends infer Versions | undefined ? Versions extends VersionSchema<SV, Method> ? Versions : VersionSchema<SV, Method> : VersionSchema<SV, Method>, T['contractDetails']['auth'] extends infer Auth | undefined ? Auth extends AuthMethodsBase ? Auth : AuthMethodsBase : AuthMethodsBase>;
|
1479
|
+
/**
|
1480
|
+
* @deprecated
|
1465
1481
|
* Extracts and constructs a LiveTypeFunction from an SdkHandler object.
|
1466
1482
|
* This optimized version reduces redundant type inference while maintaining type safety.
|
1467
1483
|
*
|
@@ -1480,6 +1496,7 @@ type MapControllerToSdk<SV extends AnySchemaValidator, T extends Record<string,
|
|
1480
1496
|
*/
|
1481
1497
|
type ExtractLiveTypeFn<Entry extends SdkHandler, SV extends AnySchemaValidator, BasePath extends `/${string}`> = LiveTypeFunction<SV, Entry['_path'] extends infer Path | undefined ? Path extends `/${string}` ? `${BasePath}${Path}` : never : never, Entry['contractDetails']['params'] extends infer Params | undefined ? Params extends ParamsObject<SV> ? Params : ParamsObject<SV> : ParamsObject<SV>, Entry['contractDetails']['responses'] extends infer Responses | undefined ? Responses extends ResponsesObject<SV> ? Responses : ResponsesObject<SV> : ResponsesObject<SV>, Entry['contractDetails']['body'] extends infer B | undefined ? B extends Body<SV> ? B : Body<SV> : Body<SV>, Entry['contractDetails']['query'] extends infer Q | undefined ? Q extends QueryObject<SV> ? Q : QueryObject<SV> : QueryObject<SV>, Entry['contractDetails']['requestHeaders'] extends infer RequestHeaders | undefined ? RequestHeaders extends HeadersObject<SV> ? RequestHeaders : HeadersObject<SV> : HeadersObject<SV>, Entry['contractDetails']['responseHeaders'] extends infer ResponseHeaders | undefined ? ResponseHeaders extends HeadersObject<SV> ? ResponseHeaders : HeadersObject<SV> : HeadersObject<SV>, Entry['_method'] extends Method ? Entry['_method'] : never, Entry['contractDetails']['versions'] extends infer Versions | undefined ? Versions extends VersionSchema<SV, Method> ? Versions : VersionSchema<SV, Method> : VersionSchema<SV, Method>, Entry['contractDetails']['auth'] extends infer Auth | undefined ? Auth extends AuthMethodsBase ? Auth : AuthMethodsBase : AuthMethodsBase>;
|
1482
1498
|
/**
|
1499
|
+
* @deprecated
|
1483
1500
|
* Transforms a controller object into a fetch map structure that provides
|
1484
1501
|
* type-safe access to HTTP endpoints. This optimized version reduces complexity
|
1485
1502
|
* while maintaining full type safety and discriminated union behavior.
|
@@ -1657,6 +1674,14 @@ declare class ForklaunchExpressLikeRouter<SV extends AnySchemaValidator, BasePat
|
|
1657
1674
|
* @returns {ExpressRouter} - The Express router.
|
1658
1675
|
*/
|
1659
1676
|
trace: LiveTypeRouteDefinition<SV, BasePath, 'trace', RouterHandler, Internal, RouterSession, BaseRequest, BaseResponse, NextFunction, this>;
|
1677
|
+
insertIntoRouterSdkPaths({ sdkPath, path, method, name }: {
|
1678
|
+
sdkPath: string;
|
1679
|
+
name: string;
|
1680
|
+
path: string;
|
1681
|
+
method: string;
|
1682
|
+
}): void;
|
1683
|
+
private unpackSdks;
|
1684
|
+
registerSdks(sdks: SdkHandlerObject<SV>): void;
|
1660
1685
|
protected cloneInternals(clone: this): void;
|
1661
1686
|
clone(): this;
|
1662
1687
|
}
|
@@ -2038,202 +2063,6 @@ declare function discriminateResponseBodies<SV extends AnySchemaValidator>(schem
|
|
2038
2063
|
schema: SV["_ValidSchemaObject"];
|
2039
2064
|
}>;
|
2040
2065
|
|
2041
|
-
/**
|
2042
|
-
* Creates a complete SDK client from a RouterMap configuration.
|
2043
|
-
* This is the main entry point for creating type-safe SDK clients that combine
|
2044
|
-
* both SDK interfaces and fetch functionality from router configurations.
|
2045
|
-
*
|
2046
|
-
* @template SV - The schema validator type that constrains the router structure
|
2047
|
-
* @template T - The RouterMap type to create the SDK client from
|
2048
|
-
* @param schemaValidator - The schema validator instance used for validation and type constraints
|
2049
|
-
* @param routerMap - The router map containing the complete API configuration
|
2050
|
-
*
|
2051
|
-
* @returns An object containing both the SDK interface and fetch function:
|
2052
|
-
* - `sdk`: The extracted SDK interfaces for direct method calls
|
2053
|
-
* - `fetch`: The unified fetch function for making HTTP requests
|
2054
|
-
*
|
2055
|
-
* @example
|
2056
|
-
* ```typescript
|
2057
|
-
* const routerMap = {
|
2058
|
-
* api: {
|
2059
|
-
* users: {
|
2060
|
-
* sdk: { getUser: (id: string) => Promise.resolve({ id, name: 'John' }) },
|
2061
|
-
* _fetchMap: { getUser: { get: (id: string) => fetch(`/api/users/${id}`) } }
|
2062
|
-
* },
|
2063
|
-
* posts: {
|
2064
|
-
* sdk: { getPosts: () => Promise.resolve([]) },
|
2065
|
-
* _fetchMap: { getPosts: { get: () => fetch('/api/posts') } }
|
2066
|
-
* }
|
2067
|
-
* }
|
2068
|
-
* };
|
2069
|
-
*
|
2070
|
-
* const client = sdkClient(zodValidator, routerMap);
|
2071
|
-
*
|
2072
|
-
* // Use SDK methods directly
|
2073
|
-
* const user = await client.sdk.api.users.getUser('123');
|
2074
|
-
*
|
2075
|
-
* // Use fetch function for custom requests
|
2076
|
-
* const response = await client.fetch('getUser', { params: { id: '123' } });
|
2077
|
-
* ```
|
2078
|
-
*/
|
2079
|
-
declare function sdkClient<SV extends AnySchemaValidator, T extends RouterMap<SV>>(schemaValidator: SV, routerMap: T): {
|
2080
|
-
_finalizedSdk: true;
|
2081
|
-
sdk: MapToSdk<SV, T>;
|
2082
|
-
fetch: FetchFunction<MapToFetch<SV, T>>;
|
2083
|
-
};
|
2084
|
-
|
2085
|
-
/**
|
2086
|
-
* Creates a type-safe SDK router by mapping controller definitions to router SDK functions.
|
2087
|
-
* This function takes a controller object with contract details and maps each controller method
|
2088
|
-
* to the corresponding SDK function from the router, ensuring type safety throughout the process.
|
2089
|
-
* The function now uses `const` template parameters for better type inference and includes
|
2090
|
-
* a comprehensive fetch map for enhanced type safety.
|
2091
|
-
*
|
2092
|
-
* @template SV - The schema validator type that constrains the router and controller structure
|
2093
|
-
* @template T - The controller type containing contract details for each endpoint (const parameter)
|
2094
|
-
* @template Router - The router type that provides SDK functions, fetch, and _fetchMap capabilities (const parameter)
|
2095
|
-
* @param SV - Must extend AnySchemaValidator to ensure type safety
|
2096
|
-
* @param T - Must be a const record where each key maps to a controller method with contract details
|
2097
|
-
* @param Router - Must be a const object with optional sdk, fetch, and _fetchMap properties
|
2098
|
-
*
|
2099
|
-
* @param schemaValidator - The schema validator instance used for validation and type constraints
|
2100
|
-
* @param controller - The controller object containing contract details for each endpoint
|
2101
|
-
* @param router - The router instance that provides SDK functions, fetch, and _fetchMap capabilities
|
2102
|
-
*
|
2103
|
-
* @returns An object containing:
|
2104
|
-
* - `sdk`: Type-safe SDK functions mapped from controller methods using LiveSdkFunction
|
2105
|
-
* - `fetch`: The router's fetch function cast to FetchFunction with proper typing
|
2106
|
-
* - `_fetchMap`: A comprehensive fetch map with LiveTypeFunction for each endpoint and method
|
2107
|
-
*
|
2108
|
-
* @example
|
2109
|
-
* ```typescript
|
2110
|
-
* const controller = {
|
2111
|
-
* createAgent: {
|
2112
|
-
* _path: '/agents',
|
2113
|
-
* _method: 'POST',
|
2114
|
-
* contractDetails: {
|
2115
|
-
* name: 'createAgent',
|
2116
|
-
* body: { name: 'string', organizationId: 'string' },
|
2117
|
-
* responses: { 200: { id: 'string', name: 'string' } }
|
2118
|
-
* }
|
2119
|
-
* },
|
2120
|
-
* getAgent: {
|
2121
|
-
* _path: '/agents/:id',
|
2122
|
-
* _method: 'GET',
|
2123
|
-
* contractDetails: {
|
2124
|
-
* name: 'getAgent',
|
2125
|
-
* params: { id: 'string' },
|
2126
|
-
* responses: { 200: { id: 'string', name: 'string' } }
|
2127
|
-
* }
|
2128
|
-
* }
|
2129
|
-
* } as const;
|
2130
|
-
*
|
2131
|
-
* const router = {
|
2132
|
-
* sdk: { createAgent: () => Promise.resolve({}), getAgent: () => Promise.resolve({}) },
|
2133
|
-
* fetch: (path: string, options: any) => fetch(path, options),
|
2134
|
-
* _fetchMap: { '/agents': { POST: () => fetch('/agents', { method: 'POST' }) } }
|
2135
|
-
* } as const;
|
2136
|
-
*
|
2137
|
-
* const sdkRouter = sdkRouter(zodValidator, controller, router);
|
2138
|
-
*
|
2139
|
-
* // Use SDK functions with full type safety
|
2140
|
-
* const agent = await sdkRouter.sdk.createAgent({
|
2141
|
-
* body: { name: 'My Agent', organizationId: 'org123' }
|
2142
|
-
* });
|
2143
|
-
*
|
2144
|
-
* const agentData = await sdkRouter.sdk.getAgent({
|
2145
|
-
* params: { id: 'agent123' }
|
2146
|
-
* });
|
2147
|
-
*
|
2148
|
-
* // Use fetch function with enhanced type safety
|
2149
|
-
* const response = await sdkRouter.fetch('/agents', {
|
2150
|
-
* method: 'POST',
|
2151
|
-
* body: { name: 'Custom Agent', organizationId: 'org456' }
|
2152
|
-
* });
|
2153
|
-
*
|
2154
|
-
* // Access the fetch map for advanced usage
|
2155
|
-
* const _fetchMap = sdkRouter._fetchMap;
|
2156
|
-
* ```
|
2157
|
-
*/
|
2158
|
-
declare function sdkRouter<SV extends AnySchemaValidator, const T extends Record<string, SdkHandler>, const Router extends {
|
2159
|
-
sdk?: unknown;
|
2160
|
-
fetch?: unknown;
|
2161
|
-
_fetchMap?: unknown;
|
2162
|
-
basePath?: string;
|
2163
|
-
sdkPaths: Record<string, string>;
|
2164
|
-
}>(schemaValidator: SV, controller: T, router: Router): {
|
2165
|
-
sdk: MapControllerToSdk<SV, T>;
|
2166
|
-
fetch: FetchFunction<{ [K_1 in keyof T as T[K_1]["_path"] extends infer P | undefined ? P extends `/${string}` ? `${Router["basePath"] extends `/${string}` ? Router["basePath"] : "/"}${P}` : never : never]: { [M in T[K_1]["_method"] as M extends Method ? Uppercase<M> : never]: LiveTypeFunction<SV, Extract<T[K_1], {
|
2167
|
-
_path: T[K_1]["_path"];
|
2168
|
-
_method: M;
|
2169
|
-
}>["_path"] extends infer Path | undefined ? Path extends `/${string}` ? `${Router["basePath"] extends `/${string}` ? Router["basePath"] : "/"}${Path}` : never : never, Extract<T[K_1], {
|
2170
|
-
_path: T[K_1]["_path"];
|
2171
|
-
_method: M;
|
2172
|
-
}>["contractDetails"]["params"] extends infer Params | undefined ? Params extends ParamsObject<SV> ? Params : ParamsObject<SV> : ParamsObject<SV>, Extract<T[K_1], {
|
2173
|
-
_path: T[K_1]["_path"];
|
2174
|
-
_method: M;
|
2175
|
-
}>["contractDetails"]["responses"] extends infer Responses | undefined ? Responses extends ResponsesObject<SV> ? Responses : ResponsesObject<SV> : ResponsesObject<SV>, Extract<T[K_1], {
|
2176
|
-
_path: T[K_1]["_path"];
|
2177
|
-
_method: M;
|
2178
|
-
}>["contractDetails"]["body"] extends infer B | undefined ? B extends Body<SV> ? B : Body<SV> : Body<SV>, Extract<T[K_1], {
|
2179
|
-
_path: T[K_1]["_path"];
|
2180
|
-
_method: M;
|
2181
|
-
}>["contractDetails"]["query"] extends infer Q | undefined ? Q extends QueryObject<SV> ? Q : QueryObject<SV> : QueryObject<SV>, Extract<T[K_1], {
|
2182
|
-
_path: T[K_1]["_path"];
|
2183
|
-
_method: M;
|
2184
|
-
}>["contractDetails"]["requestHeaders"] extends infer RequestHeaders | undefined ? RequestHeaders extends HeadersObject<SV> ? RequestHeaders : HeadersObject<SV> : HeadersObject<SV>, Extract<T[K_1], {
|
2185
|
-
_path: T[K_1]["_path"];
|
2186
|
-
_method: M;
|
2187
|
-
}>["contractDetails"]["responseHeaders"] extends infer ResponseHeaders | undefined ? ResponseHeaders extends HeadersObject<SV> ? ResponseHeaders : HeadersObject<SV> : HeadersObject<SV>, Extract<T[K_1], {
|
2188
|
-
_path: T[K_1]["_path"];
|
2189
|
-
_method: M;
|
2190
|
-
}>["_method"] extends Method ? Extract<T[K_1], {
|
2191
|
-
_path: T[K_1]["_path"];
|
2192
|
-
_method: M;
|
2193
|
-
}>["_method"] : never, Extract<T[K_1], {
|
2194
|
-
_path: T[K_1]["_path"];
|
2195
|
-
_method: M;
|
2196
|
-
}>["contractDetails"]["versions"] extends infer Versions | undefined ? Versions extends VersionSchema<SV, Method> ? Versions : VersionSchema<SV, Method> : VersionSchema<SV, Method>, Extract<T[K_1], {
|
2197
|
-
_path: T[K_1]["_path"];
|
2198
|
-
_method: M;
|
2199
|
-
}>["contractDetails"]["auth"] extends infer Auth | undefined ? Auth extends AuthMethodsBase ? Auth : AuthMethodsBase : AuthMethodsBase>; }; } extends infer T_1 ? { [K in keyof T_1]: T_1[K]; } : never>;
|
2200
|
-
_fetchMap: { [K_1 in keyof T as T[K_1]["_path"] extends infer P | undefined ? P extends `/${string}` ? `${Router["basePath"] extends `/${string}` ? Router["basePath"] : "/"}${P}` : never : never]: { [M in T[K_1]["_method"] as M extends Method ? Uppercase<M> : never]: LiveTypeFunction<SV, Extract<T[K_1], {
|
2201
|
-
_path: T[K_1]["_path"];
|
2202
|
-
_method: M;
|
2203
|
-
}>["_path"] extends infer Path | undefined ? Path extends `/${string}` ? `${Router["basePath"] extends `/${string}` ? Router["basePath"] : "/"}${Path}` : never : never, Extract<T[K_1], {
|
2204
|
-
_path: T[K_1]["_path"];
|
2205
|
-
_method: M;
|
2206
|
-
}>["contractDetails"]["params"] extends infer Params | undefined ? Params extends ParamsObject<SV> ? Params : ParamsObject<SV> : ParamsObject<SV>, Extract<T[K_1], {
|
2207
|
-
_path: T[K_1]["_path"];
|
2208
|
-
_method: M;
|
2209
|
-
}>["contractDetails"]["responses"] extends infer Responses | undefined ? Responses extends ResponsesObject<SV> ? Responses : ResponsesObject<SV> : ResponsesObject<SV>, Extract<T[K_1], {
|
2210
|
-
_path: T[K_1]["_path"];
|
2211
|
-
_method: M;
|
2212
|
-
}>["contractDetails"]["body"] extends infer B | undefined ? B extends Body<SV> ? B : Body<SV> : Body<SV>, Extract<T[K_1], {
|
2213
|
-
_path: T[K_1]["_path"];
|
2214
|
-
_method: M;
|
2215
|
-
}>["contractDetails"]["query"] extends infer Q | undefined ? Q extends QueryObject<SV> ? Q : QueryObject<SV> : QueryObject<SV>, Extract<T[K_1], {
|
2216
|
-
_path: T[K_1]["_path"];
|
2217
|
-
_method: M;
|
2218
|
-
}>["contractDetails"]["requestHeaders"] extends infer RequestHeaders | undefined ? RequestHeaders extends HeadersObject<SV> ? RequestHeaders : HeadersObject<SV> : HeadersObject<SV>, Extract<T[K_1], {
|
2219
|
-
_path: T[K_1]["_path"];
|
2220
|
-
_method: M;
|
2221
|
-
}>["contractDetails"]["responseHeaders"] extends infer ResponseHeaders | undefined ? ResponseHeaders extends HeadersObject<SV> ? ResponseHeaders : HeadersObject<SV> : HeadersObject<SV>, Extract<T[K_1], {
|
2222
|
-
_path: T[K_1]["_path"];
|
2223
|
-
_method: M;
|
2224
|
-
}>["_method"] extends Method ? Extract<T[K_1], {
|
2225
|
-
_path: T[K_1]["_path"];
|
2226
|
-
_method: M;
|
2227
|
-
}>["_method"] : never, Extract<T[K_1], {
|
2228
|
-
_path: T[K_1]["_path"];
|
2229
|
-
_method: M;
|
2230
|
-
}>["contractDetails"]["versions"] extends infer Versions | undefined ? Versions extends VersionSchema<SV, Method> ? Versions : VersionSchema<SV, Method> : VersionSchema<SV, Method>, Extract<T[K_1], {
|
2231
|
-
_path: T[K_1]["_path"];
|
2232
|
-
_method: M;
|
2233
|
-
}>["contractDetails"]["auth"] extends infer Auth | undefined ? Auth extends AuthMethodsBase ? Auth : AuthMethodsBase : AuthMethodsBase>; }; } extends infer T_2 ? { [K in keyof T_2]: T_2[K]; } : never;
|
2234
|
-
sdkPaths: Router["sdkPaths"];
|
2235
|
-
};
|
2236
|
-
|
2237
2066
|
declare const ATTR_API_NAME = "api.name";
|
2238
2067
|
declare const ATTR_CORRELATION_ID = "correlation.id";
|
2239
2068
|
|
@@ -2267,4 +2096,4 @@ declare function logger(level: LevelWithSilentOrString, meta?: AnyValueMap): Pin
|
|
2267
2096
|
|
2268
2097
|
declare function recordMetric<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ResBodyMap extends Record<string, unknown>, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, unknown>, LocalsObj extends Record<string, unknown>, VersionedReqs extends VersionedRequests, SessionSchema extends Record<string, unknown>>(req: ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Extract<keyof VersionedReqs, string>, SessionSchema>, res: ForklaunchResponse<unknown, ResBodyMap, ResHeaders, LocalsObj, Extract<keyof VersionedReqs, string>>): void;
|
2269
2098
|
|
2270
|
-
export { ATTR_API_NAME, ATTR_CORRELATION_ID, type AuthMethods, type AuthMethodsBase, type BasicAuthMethods, type Body, type BodyObject, type ClusterConfig, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type DecodeResource, type DocsConfiguration, type ErrorContainer, type ExpressLikeApplicationOptions, type ExpressLikeAuthMapper, type ExpressLikeGlobalAuthOptions, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeRouterOptions, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaGlobalAuthOptions, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractBody, type ExtractContentType, type ExtractLiveTypeFn, type ExtractResponseBody, type ExtractedParamsObject, type FetchFunction, type FileBody, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HmacMethods, type HttpContractDetails, type HttpMethod, type JsonBody, type JwtAuthMethods, type LiveSdkFunction, type LiveTypeFunction, type LiveTypeFunctionRequestInit, type LiveTypeRouteDefinition, type LogFn, type LoggerMeta, type
|
2099
|
+
export { ATTR_API_NAME, ATTR_CORRELATION_ID, type AuthMethods, type AuthMethodsBase, type BasicAuthMethods, type Body, type BodyObject, type ClusterConfig, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type DecodeResource, type DocsConfiguration, type ErrorContainer, type ExpressLikeApplicationOptions, type ExpressLikeAuthMapper, type ExpressLikeGlobalAuthOptions, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeRouterOptions, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaGlobalAuthOptions, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractBody, type ExtractContentType, type ExtractLiveTypeFn, type ExtractResponseBody, type ExtractedParamsObject, type FetchFunction, type FileBody, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HmacMethods, type HttpContractDetails, type HttpMethod, type JsonBody, type JwtAuthMethods, type LiveSdkFunction, type LiveTypeFunction, type LiveTypeFunctionRequestInit, type LiveTypeRouteDefinition, type LogFn, type LoggerMeta, type MapHandlerToLiveSdk, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type MapSessionSchema, type MapToFetch, type MapToSdk, type MapVersionedReqsSchema, type MapVersionedRespsSchema, type Method, type MetricType, type MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type MultipartForm, type NestableRouterBasedHandler, type NumberOnlyObject, OPENAPI_DEFAULT_VERSION, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, type QueryObject, type RawTypedResponseBody, type RequestContext, type ResolvedForklaunchAuthRequest, type ResolvedForklaunchRequest, type ResolvedForklaunchResponse, type ResolvedSessionObject, type ResponseBody, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type RouterMap, type RoutingStrategy, type SchemaAuthMethods, type SdkHandler, type SdkHandlerObject, type SdkRouter, type ServerSentEventBody, type SessionObject, type StatusCode, type StringOnlyObject, type TelemetryOptions, type TextBody, type ToFetchMap, type TypedBody, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, type TypedRequestBody, type TypedResponseBody, type UnknownBody, type UnknownResponseBody, type UrlEncodedForm, type VersionSchema, type VersionedRequests, type VersionedResponses, createHmacToken, delete_, discriminateAuthMethod, discriminateBody, discriminateResponseBodies, enrichExpressLikeSend, evaluateTelemetryOptions, generateMcpServer, generateOpenApiSpecs, get, getCachedJwks, getCodeForStatus, head, httpRequestsTotalCounter, httpServerDurationHistogram, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isPortBound, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedAuthHandler, typedHandler };
|
package/lib/http/index.js
CHANGED
@@ -74,8 +74,6 @@ __export(http_exports, {
|
|
74
74
|
post: () => post,
|
75
75
|
put: () => put,
|
76
76
|
recordMetric: () => recordMetric,
|
77
|
-
sdkClient: () => sdkClient,
|
78
|
-
sdkRouter: () => sdkRouter,
|
79
77
|
trace: () => trace3,
|
80
78
|
typedAuthHandler: () => typedAuthHandler,
|
81
79
|
typedHandler: () => typedHandler
|
@@ -153,6 +151,11 @@ function isHttpContractDetails(maybeContractDetails) {
|
|
153
151
|
));
|
154
152
|
}
|
155
153
|
|
154
|
+
// src/http/guards/isSdkHandler.ts
|
155
|
+
function isSdkHandler(handler) {
|
156
|
+
return typeof handler === "object" && handler !== null && "_path" in handler && "_method" in handler && "contractDetails" in handler;
|
157
|
+
}
|
158
|
+
|
156
159
|
// src/http/guards/isTypedHandler.ts
|
157
160
|
function isTypedHandler(maybeTypedHandler) {
|
158
161
|
return maybeTypedHandler != null && typeof maybeTypedHandler === "object" && "_typedHandler" in maybeTypedHandler && maybeTypedHandler._typedHandler === true;
|
@@ -396,6 +399,13 @@ async function checkAuthorizationToken(req, authorizationMethod, authorizationTo
|
|
396
399
|
const parsedTimestamp = parseHmacTokenPart(timestamp, "ts");
|
397
400
|
const parsedNonce = parseHmacTokenPart(nonce, "nonce");
|
398
401
|
const parsedSignature = parseHmacTokenPart(signature, "signature");
|
402
|
+
console.log(
|
403
|
+
"parseditems",
|
404
|
+
parsedKeyId,
|
405
|
+
parsedTimestamp,
|
406
|
+
parsedNonce,
|
407
|
+
parsedSignature
|
408
|
+
);
|
399
409
|
if (!parsedKeyId || !parsedTimestamp || !parsedNonce || !parsedSignature) {
|
400
410
|
return invalidAuthorizationTokenFormat;
|
401
411
|
}
|
@@ -1895,6 +1905,53 @@ var ForklaunchExpressLikeRouter = class _ForklaunchExpressLikeRouter {
|
|
1895
1905
|
...middlewareOrMiddlewareWithTypedHandler
|
1896
1906
|
);
|
1897
1907
|
};
|
1908
|
+
insertIntoRouterSdkPaths({
|
1909
|
+
sdkPath,
|
1910
|
+
path,
|
1911
|
+
method,
|
1912
|
+
name
|
1913
|
+
}) {
|
1914
|
+
const routePath = [method, path].join(".");
|
1915
|
+
for (const route of this.routes) {
|
1916
|
+
if (route.path === path && route.method === method && route.contractDetails.name === name) {
|
1917
|
+
this.sdkPaths[routePath] = sdkPath;
|
1918
|
+
}
|
1919
|
+
}
|
1920
|
+
for (const router of this.routers) {
|
1921
|
+
router.insertIntoRouterSdkPaths?.({
|
1922
|
+
sdkPath,
|
1923
|
+
path,
|
1924
|
+
method,
|
1925
|
+
name
|
1926
|
+
});
|
1927
|
+
}
|
1928
|
+
}
|
1929
|
+
unpackSdks(sdks, path, routerUniquenessCache) {
|
1930
|
+
Object.entries(sdks).forEach(([key, maybeHandler]) => {
|
1931
|
+
if (isSdkHandler(maybeHandler)) {
|
1932
|
+
const cacheKey = (0, import_common9.hashString)((0, import_common9.safeStringify)(maybeHandler));
|
1933
|
+
if (routerUniquenessCache.has(cacheKey)) {
|
1934
|
+
throw new Error(`SDK handler ${key} is already registered`);
|
1935
|
+
}
|
1936
|
+
routerUniquenessCache.add(cacheKey);
|
1937
|
+
if (!maybeHandler._method || !maybeHandler._path) {
|
1938
|
+
throw new Error(`SDK handler ${key} is missing method or path`);
|
1939
|
+
}
|
1940
|
+
this.insertIntoRouterSdkPaths({
|
1941
|
+
sdkPath: [...path, key].join("."),
|
1942
|
+
path: maybeHandler._path,
|
1943
|
+
method: maybeHandler._method,
|
1944
|
+
name: maybeHandler.contractDetails.name
|
1945
|
+
});
|
1946
|
+
routerUniquenessCache.add(cacheKey);
|
1947
|
+
} else {
|
1948
|
+
this.unpackSdks(maybeHandler, [...path, key], routerUniquenessCache);
|
1949
|
+
}
|
1950
|
+
});
|
1951
|
+
}
|
1952
|
+
registerSdks(sdks) {
|
1953
|
+
this.unpackSdks(sdks, [], /* @__PURE__ */ new Set());
|
1954
|
+
}
|
1898
1955
|
cloneInternals(clone) {
|
1899
1956
|
clone.routers = [...this.routers];
|
1900
1957
|
clone.routes = [...this.routes];
|
@@ -3912,109 +3969,6 @@ function generateOpenApiSpecs(schemaValidator, serverUrls, serverDescriptions, a
|
|
3912
3969
|
);
|
3913
3970
|
}
|
3914
3971
|
|
3915
|
-
// src/http/sdk/sdkClient.ts
|
3916
|
-
var import_common14 = require("@forklaunch/common");
|
3917
|
-
|
3918
|
-
// src/http/guards/isSdkRouter.ts
|
3919
|
-
function isSdkRouter(value) {
|
3920
|
-
return typeof value === "object" && value !== null && "sdk" in value && "_fetchMap" in value && "sdkPaths" in value;
|
3921
|
-
}
|
3922
|
-
|
3923
|
-
// src/http/sdk/sdkClient.ts
|
3924
|
-
function mapToSdk(schemaValidator, routerMap, runningPath = void 0) {
|
3925
|
-
const routerUniquenessCache = /* @__PURE__ */ new Set();
|
3926
|
-
return Object.fromEntries(
|
3927
|
-
Object.entries(routerMap).map(([key, value]) => {
|
3928
|
-
if (routerUniquenessCache.has((0, import_common14.hashString)((0, import_common14.safeStringify)(value)))) {
|
3929
|
-
throw new Error(
|
3930
|
-
`SdkClient: Cannot use the same router pointer twice. Please clone the duplicate router with .clone() or only use the router once.`
|
3931
|
-
);
|
3932
|
-
}
|
3933
|
-
routerUniquenessCache.add((0, import_common14.hashString)((0, import_common14.safeStringify)(value)));
|
3934
|
-
const currentPath = runningPath ? [runningPath, key].join(".") : key;
|
3935
|
-
if (isSdkRouter(value)) {
|
3936
|
-
Object.entries(value.sdkPaths).forEach(([routePath, sdkKey]) => {
|
3937
|
-
if ("controllerSdkPaths" in value && Array.isArray(value.controllerSdkPaths) && value.controllerSdkPaths.includes(routePath)) {
|
3938
|
-
value.sdkPaths[routePath] = [currentPath, sdkKey].join(".");
|
3939
|
-
}
|
3940
|
-
});
|
3941
|
-
return [key, value.sdk];
|
3942
|
-
} else {
|
3943
|
-
return [
|
3944
|
-
key,
|
3945
|
-
mapToSdk(
|
3946
|
-
schemaValidator,
|
3947
|
-
value,
|
3948
|
-
runningPath ? [runningPath, key].join(".") : key
|
3949
|
-
)
|
3950
|
-
];
|
3951
|
-
}
|
3952
|
-
})
|
3953
|
-
);
|
3954
|
-
}
|
3955
|
-
function flattenFetchMap(schemaValidator, routerMap) {
|
3956
|
-
const _fetchMap = Object.entries(routerMap).reduce(
|
3957
|
-
(acc, [, value]) => {
|
3958
|
-
if ("_fetchMap" in value) {
|
3959
|
-
return {
|
3960
|
-
...acc,
|
3961
|
-
...value._fetchMap
|
3962
|
-
};
|
3963
|
-
} else {
|
3964
|
-
return {
|
3965
|
-
...acc,
|
3966
|
-
...flattenFetchMap(schemaValidator, value)
|
3967
|
-
};
|
3968
|
-
}
|
3969
|
-
},
|
3970
|
-
{}
|
3971
|
-
);
|
3972
|
-
return _fetchMap;
|
3973
|
-
}
|
3974
|
-
function mapToFetch(schemaValidator, routerMap) {
|
3975
|
-
const flattenedFetchMap = flattenFetchMap(
|
3976
|
-
schemaValidator,
|
3977
|
-
routerMap
|
3978
|
-
);
|
3979
|
-
return ((path, ...reqInit) => {
|
3980
|
-
const method = reqInit[0]?.method;
|
3981
|
-
const version = reqInit[0] != null && "version" in reqInit[0] ? reqInit[0].version : void 0;
|
3982
|
-
return (version ? (0, import_common14.toRecord)((0, import_common14.toRecord)(flattenedFetchMap[path])[method ?? "GET"])[version] : (0, import_common14.toRecord)(flattenedFetchMap[path])[method ?? "GET"])(path, reqInit[0]);
|
3983
|
-
});
|
3984
|
-
}
|
3985
|
-
function sdkClient(schemaValidator, routerMap) {
|
3986
|
-
return {
|
3987
|
-
_finalizedSdk: true,
|
3988
|
-
sdk: mapToSdk(schemaValidator, routerMap),
|
3989
|
-
fetch: mapToFetch(schemaValidator, routerMap)
|
3990
|
-
};
|
3991
|
-
}
|
3992
|
-
|
3993
|
-
// src/http/sdk/sdkRouter.ts
|
3994
|
-
var import_common15 = require("@forklaunch/common");
|
3995
|
-
function sdkRouter(schemaValidator, controller, router) {
|
3996
|
-
const controllerSdkPaths = [];
|
3997
|
-
const mappedSdk = Object.fromEntries(
|
3998
|
-
Object.entries(controller).map(([key, value]) => {
|
3999
|
-
const sdkPath = [value._method, value._path].join(".");
|
4000
|
-
controllerSdkPaths.push(sdkPath);
|
4001
|
-
router.sdkPaths[sdkPath] = key;
|
4002
|
-
return [
|
4003
|
-
key,
|
4004
|
-
router.sdk[(0, import_common15.toPrettyCamelCase)(value.contractDetails.name)]
|
4005
|
-
];
|
4006
|
-
})
|
4007
|
-
);
|
4008
|
-
const _fetchMap = router._fetchMap;
|
4009
|
-
return {
|
4010
|
-
sdk: mappedSdk,
|
4011
|
-
fetch: router.fetch,
|
4012
|
-
_fetchMap,
|
4013
|
-
sdkPaths: router.sdkPaths,
|
4014
|
-
controllerSdkPaths
|
4015
|
-
};
|
4016
|
-
}
|
4017
|
-
|
4018
3972
|
// src/http/telemetry/evaluateTelemetryOptions.ts
|
4019
3973
|
function evaluateTelemetryOptions(telemetryOptions) {
|
4020
3974
|
return {
|
@@ -4081,8 +4035,6 @@ function metricsDefinitions(metrics2) {
|
|
4081
4035
|
post,
|
4082
4036
|
put,
|
4083
4037
|
recordMetric,
|
4084
|
-
sdkClient,
|
4085
|
-
sdkRouter,
|
4086
4038
|
trace,
|
4087
4039
|
typedAuthHandler,
|
4088
4040
|
typedHandler
|