@forklaunch/core 0.14.14 → 0.14.16
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 +79 -1
- package/lib/http/index.d.ts +79 -1
- package/lib/http/index.js +24 -16
- package/lib/http/index.js.map +1 -1
- package/lib/http/index.mjs +22 -16
- package/lib/http/index.mjs.map +1 -1
- package/package.json +8 -8
package/lib/http/index.d.mts
CHANGED
@@ -1718,6 +1718,84 @@ declare function createHmacToken({ method, path, body, timestamp, nonce, secretK
|
|
1718
1718
|
secretKey: string;
|
1719
1719
|
}): string;
|
1720
1720
|
|
1721
|
+
/**
|
1722
|
+
* Retrieves and caches the JSON Web Key Set (JWKS) from a given public key URL.
|
1723
|
+
*
|
1724
|
+
* This function fetches the JWKS from the specified URL and caches the result in memory
|
1725
|
+
* to avoid unnecessary network requests. The cache is considered valid for a duration
|
1726
|
+
* specified by the `cache-control` header in the JWKS HTTP response (in seconds), or
|
1727
|
+
* falls back to a default TTL if the header is not present. If the cache is still valid,
|
1728
|
+
* the cached keys are returned immediately.
|
1729
|
+
*
|
1730
|
+
* @param {string} jwksPublicKeyUrl - The URL to fetch the JWKS from.
|
1731
|
+
* @returns {Promise<JWK[]>} A promise that resolves to an array of JWK objects.
|
1732
|
+
*
|
1733
|
+
* @example
|
1734
|
+
* const jwks = await getCachedJwks('https://example.com/.well-known/jwks.json');
|
1735
|
+
* // Use jwks for JWT verification, etc.
|
1736
|
+
*/
|
1737
|
+
declare function getCachedJwks(jwksPublicKeyUrl: string): Promise<JWK[]>;
|
1738
|
+
/**
|
1739
|
+
* Discriminates between different authentication methods and returns a typed result.
|
1740
|
+
*
|
1741
|
+
* This function analyzes the provided authentication configuration and determines
|
1742
|
+
* whether it uses basic authentication or JWT authentication. It returns a
|
1743
|
+
* discriminated union type that includes the authentication type and the
|
1744
|
+
* corresponding authentication configuration.
|
1745
|
+
*
|
1746
|
+
* @template SV - A type that extends AnySchemaValidator
|
1747
|
+
* @template P - A type that extends ParamsDictionary
|
1748
|
+
* @template ReqBody - A type that extends Record<string, unknown>
|
1749
|
+
* @template ReqQuery - A type that extends ParsedQs
|
1750
|
+
* @template ReqHeaders - A type that extends Record<string, unknown>
|
1751
|
+
* @template BaseRequest - The base request type
|
1752
|
+
*
|
1753
|
+
* @param auth - The authentication methods configuration object
|
1754
|
+
* @returns A discriminated union object with either:
|
1755
|
+
* - `{ type: 'basic', auth: BasicAuthMethods['basic'] }` for basic authentication
|
1756
|
+
* - `{ type: 'jwt', auth?: JwtAuthMethods['jwt'] }` for JWT authentication (auth is optional)
|
1757
|
+
*
|
1758
|
+
* @example
|
1759
|
+
* ```typescript
|
1760
|
+
* const authConfig = {
|
1761
|
+
* basic: {
|
1762
|
+
* login: (username: string, password: string) => boolean
|
1763
|
+
* }
|
1764
|
+
* };
|
1765
|
+
* const result = discriminateAuthMethod(authConfig);
|
1766
|
+
* // result.type === 'basic'
|
1767
|
+
* // result.auth === authConfig.basic
|
1768
|
+
* ```
|
1769
|
+
*/
|
1770
|
+
declare function discriminateAuthMethod<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, BaseRequest>(auth: AuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, BaseRequest>): Promise<{
|
1771
|
+
type: 'basic';
|
1772
|
+
auth: {
|
1773
|
+
decodeResource?: DecodeResource;
|
1774
|
+
login: BasicAuthMethods['basic']['login'];
|
1775
|
+
};
|
1776
|
+
} | {
|
1777
|
+
type: 'jwt';
|
1778
|
+
auth: {
|
1779
|
+
decodeResource?: DecodeResource;
|
1780
|
+
} | {
|
1781
|
+
verificationFunction: (token: string) => Promise<JWTPayload | undefined>;
|
1782
|
+
};
|
1783
|
+
} | {
|
1784
|
+
type: 'hmac';
|
1785
|
+
auth: {
|
1786
|
+
secretKeys: Record<string, string>;
|
1787
|
+
verificationFunction: ({ body, path, method, timestamp, nonce, signature, secretKey }: {
|
1788
|
+
method: string;
|
1789
|
+
path: string;
|
1790
|
+
body?: unknown;
|
1791
|
+
timestamp: Date;
|
1792
|
+
nonce: string;
|
1793
|
+
signature: string;
|
1794
|
+
secretKey: string;
|
1795
|
+
}) => Promise<boolean | undefined>;
|
1796
|
+
};
|
1797
|
+
}>;
|
1798
|
+
|
1721
1799
|
/**
|
1722
1800
|
* Type guard that checks if an object is a Forklaunch request.
|
1723
1801
|
* A Forklaunch request is an object that contains contract details and follows the Forklaunch request structure.
|
@@ -2189,4 +2267,4 @@ declare function logger(level: LevelWithSilentOrString, meta?: AnyValueMap): Pin
|
|
2189
2267
|
|
2190
2268
|
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;
|
2191
2269
|
|
2192
|
-
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 MapControllerToSdk, 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 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_, discriminateBody, discriminateResponseBodies, enrichExpressLikeSend, evaluateTelemetryOptions, generateMcpServer, generateOpenApiSpecs, get, getCodeForStatus, head, httpRequestsTotalCounter, httpServerDurationHistogram, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isPortBound, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, sdkClient, sdkRouter, trace, typedAuthHandler, typedHandler };
|
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 MapControllerToSdk, 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 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, sdkClient, sdkRouter, trace, typedAuthHandler, typedHandler };
|
package/lib/http/index.d.ts
CHANGED
@@ -1718,6 +1718,84 @@ declare function createHmacToken({ method, path, body, timestamp, nonce, secretK
|
|
1718
1718
|
secretKey: string;
|
1719
1719
|
}): string;
|
1720
1720
|
|
1721
|
+
/**
|
1722
|
+
* Retrieves and caches the JSON Web Key Set (JWKS) from a given public key URL.
|
1723
|
+
*
|
1724
|
+
* This function fetches the JWKS from the specified URL and caches the result in memory
|
1725
|
+
* to avoid unnecessary network requests. The cache is considered valid for a duration
|
1726
|
+
* specified by the `cache-control` header in the JWKS HTTP response (in seconds), or
|
1727
|
+
* falls back to a default TTL if the header is not present. If the cache is still valid,
|
1728
|
+
* the cached keys are returned immediately.
|
1729
|
+
*
|
1730
|
+
* @param {string} jwksPublicKeyUrl - The URL to fetch the JWKS from.
|
1731
|
+
* @returns {Promise<JWK[]>} A promise that resolves to an array of JWK objects.
|
1732
|
+
*
|
1733
|
+
* @example
|
1734
|
+
* const jwks = await getCachedJwks('https://example.com/.well-known/jwks.json');
|
1735
|
+
* // Use jwks for JWT verification, etc.
|
1736
|
+
*/
|
1737
|
+
declare function getCachedJwks(jwksPublicKeyUrl: string): Promise<JWK[]>;
|
1738
|
+
/**
|
1739
|
+
* Discriminates between different authentication methods and returns a typed result.
|
1740
|
+
*
|
1741
|
+
* This function analyzes the provided authentication configuration and determines
|
1742
|
+
* whether it uses basic authentication or JWT authentication. It returns a
|
1743
|
+
* discriminated union type that includes the authentication type and the
|
1744
|
+
* corresponding authentication configuration.
|
1745
|
+
*
|
1746
|
+
* @template SV - A type that extends AnySchemaValidator
|
1747
|
+
* @template P - A type that extends ParamsDictionary
|
1748
|
+
* @template ReqBody - A type that extends Record<string, unknown>
|
1749
|
+
* @template ReqQuery - A type that extends ParsedQs
|
1750
|
+
* @template ReqHeaders - A type that extends Record<string, unknown>
|
1751
|
+
* @template BaseRequest - The base request type
|
1752
|
+
*
|
1753
|
+
* @param auth - The authentication methods configuration object
|
1754
|
+
* @returns A discriminated union object with either:
|
1755
|
+
* - `{ type: 'basic', auth: BasicAuthMethods['basic'] }` for basic authentication
|
1756
|
+
* - `{ type: 'jwt', auth?: JwtAuthMethods['jwt'] }` for JWT authentication (auth is optional)
|
1757
|
+
*
|
1758
|
+
* @example
|
1759
|
+
* ```typescript
|
1760
|
+
* const authConfig = {
|
1761
|
+
* basic: {
|
1762
|
+
* login: (username: string, password: string) => boolean
|
1763
|
+
* }
|
1764
|
+
* };
|
1765
|
+
* const result = discriminateAuthMethod(authConfig);
|
1766
|
+
* // result.type === 'basic'
|
1767
|
+
* // result.auth === authConfig.basic
|
1768
|
+
* ```
|
1769
|
+
*/
|
1770
|
+
declare function discriminateAuthMethod<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, BaseRequest>(auth: AuthMethods<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, BaseRequest>): Promise<{
|
1771
|
+
type: 'basic';
|
1772
|
+
auth: {
|
1773
|
+
decodeResource?: DecodeResource;
|
1774
|
+
login: BasicAuthMethods['basic']['login'];
|
1775
|
+
};
|
1776
|
+
} | {
|
1777
|
+
type: 'jwt';
|
1778
|
+
auth: {
|
1779
|
+
decodeResource?: DecodeResource;
|
1780
|
+
} | {
|
1781
|
+
verificationFunction: (token: string) => Promise<JWTPayload | undefined>;
|
1782
|
+
};
|
1783
|
+
} | {
|
1784
|
+
type: 'hmac';
|
1785
|
+
auth: {
|
1786
|
+
secretKeys: Record<string, string>;
|
1787
|
+
verificationFunction: ({ body, path, method, timestamp, nonce, signature, secretKey }: {
|
1788
|
+
method: string;
|
1789
|
+
path: string;
|
1790
|
+
body?: unknown;
|
1791
|
+
timestamp: Date;
|
1792
|
+
nonce: string;
|
1793
|
+
signature: string;
|
1794
|
+
secretKey: string;
|
1795
|
+
}) => Promise<boolean | undefined>;
|
1796
|
+
};
|
1797
|
+
}>;
|
1798
|
+
|
1721
1799
|
/**
|
1722
1800
|
* Type guard that checks if an object is a Forklaunch request.
|
1723
1801
|
* A Forklaunch request is an object that contains contract details and follows the Forklaunch request structure.
|
@@ -2189,4 +2267,4 @@ declare function logger(level: LevelWithSilentOrString, meta?: AnyValueMap): Pin
|
|
2189
2267
|
|
2190
2268
|
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;
|
2191
2269
|
|
2192
|
-
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 MapControllerToSdk, 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 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_, discriminateBody, discriminateResponseBodies, enrichExpressLikeSend, evaluateTelemetryOptions, generateMcpServer, generateOpenApiSpecs, get, getCodeForStatus, head, httpRequestsTotalCounter, httpServerDurationHistogram, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isPortBound, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, sdkClient, sdkRouter, trace, typedAuthHandler, typedHandler };
|
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 MapControllerToSdk, 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 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, sdkClient, sdkRouter, trace, typedAuthHandler, typedHandler };
|
package/lib/http/index.js
CHANGED
@@ -43,6 +43,7 @@ __export(http_exports, {
|
|
43
43
|
OpenTelemetryCollector: () => OpenTelemetryCollector,
|
44
44
|
createHmacToken: () => createHmacToken,
|
45
45
|
delete_: () => delete_,
|
46
|
+
discriminateAuthMethod: () => discriminateAuthMethod,
|
46
47
|
discriminateBody: () => discriminateBody,
|
47
48
|
discriminateResponseBodies: () => discriminateResponseBodies,
|
48
49
|
enrichExpressLikeSend: () => enrichExpressLikeSend,
|
@@ -50,6 +51,7 @@ __export(http_exports, {
|
|
50
51
|
generateMcpServer: () => generateMcpServer,
|
51
52
|
generateOpenApiSpecs: () => generateOpenApiSpecs,
|
52
53
|
get: () => get,
|
54
|
+
getCachedJwks: () => getCachedJwks,
|
53
55
|
getCodeForStatus: () => getCodeForStatus,
|
54
56
|
head: () => head,
|
55
57
|
httpRequestsTotalCounter: () => httpRequestsTotalCounter,
|
@@ -202,12 +204,26 @@ function isJwtAuthMethod(maybeJwtAuthMethod) {
|
|
202
204
|
}
|
203
205
|
|
204
206
|
// src/http/discriminateAuthMethod.ts
|
205
|
-
var DEFAULT_TTL = 60 * 1e3 * 5;
|
206
|
-
var
|
207
|
+
var DEFAULT_TTL = process.env.JWKS_TTL ? parseInt(process.env.JWKS_TTL) : 60 * 1e3 * 5;
|
208
|
+
var cachedJwks = {
|
207
209
|
value: null,
|
208
210
|
lastUpdated: null,
|
209
211
|
ttl: DEFAULT_TTL
|
210
212
|
};
|
213
|
+
async function getCachedJwks(jwksPublicKeyUrl) {
|
214
|
+
if (cachedJwks.value && cachedJwks.lastUpdated && Date.now() - cachedJwks.lastUpdated.getTime() < cachedJwks.ttl) {
|
215
|
+
return cachedJwks.value;
|
216
|
+
} else {
|
217
|
+
const jwksResponse = await fetch(jwksPublicKeyUrl);
|
218
|
+
const jwks = (await jwksResponse.json()).keys;
|
219
|
+
cachedJwks.value = jwks;
|
220
|
+
cachedJwks.lastUpdated = /* @__PURE__ */ new Date();
|
221
|
+
cachedJwks.ttl = parseInt(
|
222
|
+
jwksResponse.headers.get("cache-control")?.split("=")[1] ?? `${DEFAULT_TTL / 1e3}`
|
223
|
+
) * 1e3;
|
224
|
+
return jwks;
|
225
|
+
}
|
226
|
+
}
|
211
227
|
async function discriminateAuthMethod(auth) {
|
212
228
|
let authMethod;
|
213
229
|
if (isBasicAuthMethod(auth)) {
|
@@ -232,17 +248,7 @@ async function discriminateAuthMethod(auth) {
|
|
232
248
|
} else {
|
233
249
|
let jwks;
|
234
250
|
if ("jwksPublicKeyUrl" in jwt) {
|
235
|
-
|
236
|
-
jwks = memoizedJwks.value;
|
237
|
-
} else {
|
238
|
-
const jwksResponse = await fetch(jwt.jwksPublicKeyUrl);
|
239
|
-
jwks = (await jwksResponse.json()).keys;
|
240
|
-
memoizedJwks.value = jwks;
|
241
|
-
memoizedJwks.lastUpdated = /* @__PURE__ */ new Date();
|
242
|
-
memoizedJwks.ttl = parseInt(
|
243
|
-
jwksResponse.headers.get("cache-control")?.split("=")[1] ?? `${DEFAULT_TTL / 1e3}`
|
244
|
-
) * 1e3;
|
245
|
-
}
|
251
|
+
jwks = await getCachedJwks(jwt.jwksPublicKeyUrl);
|
246
252
|
} else if ("jwksPublicKey" in jwt) {
|
247
253
|
jwks = [jwt.jwksPublicKey];
|
248
254
|
}
|
@@ -252,9 +258,9 @@ async function discriminateAuthMethod(auth) {
|
|
252
258
|
const { payload } = await (0, import_jose.jwtVerify)(token, key);
|
253
259
|
return payload;
|
254
260
|
} catch {
|
255
|
-
|
256
|
-
|
257
|
-
|
261
|
+
cachedJwks.value = null;
|
262
|
+
cachedJwks.lastUpdated = null;
|
263
|
+
cachedJwks.ttl = DEFAULT_TTL;
|
258
264
|
continue;
|
259
265
|
}
|
260
266
|
}
|
@@ -4044,6 +4050,7 @@ function metricsDefinitions(metrics2) {
|
|
4044
4050
|
OpenTelemetryCollector,
|
4045
4051
|
createHmacToken,
|
4046
4052
|
delete_,
|
4053
|
+
discriminateAuthMethod,
|
4047
4054
|
discriminateBody,
|
4048
4055
|
discriminateResponseBodies,
|
4049
4056
|
enrichExpressLikeSend,
|
@@ -4051,6 +4058,7 @@ function metricsDefinitions(metrics2) {
|
|
4051
4058
|
generateMcpServer,
|
4052
4059
|
generateOpenApiSpecs,
|
4053
4060
|
get,
|
4061
|
+
getCachedJwks,
|
4054
4062
|
getCodeForStatus,
|
4055
4063
|
head,
|
4056
4064
|
httpRequestsTotalCounter,
|