@forklaunch/core 1.0.8 → 1.0.10

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.
@@ -1,7 +1,7 @@
1
- import { UnionToIntersection, TypeSafeFunction, StringWithoutSlash, Prettify, SanitizePathSlashes, MakePropertyOptionalIfChildrenOptional } from '@forklaunch/common';
1
+ import { Prettify, SanitizePathSlashes, MakePropertyOptionalIfChildrenOptional, UnionToIntersection, TypeSafeFunction, StringWithoutSlash } from '@forklaunch/common';
2
2
  import { AnySchemaValidator, UnboxedObjectSchema, IdiomaticSchema, Schema } from '@forklaunch/validator';
3
- import { Counter, Gauge, Histogram, UpDownCounter, ObservableCounter, ObservableGauge, ObservableUpDownCounter, Span } from '@opentelemetry/api';
4
3
  import { JWTPayload, JWK } from 'jose';
4
+ import { Counter, Gauge, Histogram, UpDownCounter, ObservableCounter, ObservableGauge, ObservableUpDownCounter, Span } from '@opentelemetry/api';
5
5
  import { ParsedQs } from 'qs';
6
6
  import { Readable } from 'stream';
7
7
  import { LevelWithSilentOrString, LevelWithSilent } from 'pino';
@@ -57,1075 +57,1075 @@ declare const httpServerDurationHistogram: Histogram<{
57
57
  "http.response.status_code": number;
58
58
  }>;
59
59
 
60
- /**
61
- * Dictionary type for URL parameters.
62
- */
63
- type ParamsDictionary = {
64
- [key: string]: string;
60
+ type DocsConfiguration = ({
61
+ type: 'scalar';
62
+ } & Partial<Omit<ApiReferenceConfiguration, 'spec'>>) | {
63
+ type: 'swagger';
65
64
  };
65
+
66
66
  /**
67
- * Type representing an object with only string keys.
68
- *
69
- * @template SV - A type that extends AnySchemaValidator.
70
- */
71
- type StringOnlyObject<SV extends AnySchemaValidator> = Omit<UnboxedObjectSchema<SV>, number | symbol>;
72
- /**
73
- * Type representing an object with only number keys.
74
- *
75
- * @template SV - A type that extends AnySchemaValidator.
76
- */
77
- type NumberOnlyObject<SV extends AnySchemaValidator> = Omit<UnboxedObjectSchema<SV>, string | symbol>;
78
- /**
79
- * Type representing the body object in a request.
80
- *
81
- * @template SV - A type that extends AnySchemaValidator.
82
- */
83
- type BodyObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
84
- /**
85
- * Type representing the parameters object in a request.
86
- *
87
- * @template SV - A type that extends AnySchemaValidator.
88
- */
89
- type ParamsObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
90
- /**
91
- * Type representing the query object in a request.
92
- *
93
- * @template SV - A type that extends AnySchemaValidator.
67
+ * Default subscription data structure.
68
+ * Applications can override this with their own subscription type.
94
69
  */
95
- type QueryObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
70
+ type DefaultSubscriptionData = {
71
+ subscriptionId: string;
72
+ planId: string;
73
+ planName: string;
74
+ status: string;
75
+ currentPeriodEnd: Date;
76
+ } | null;
96
77
  /**
97
- * Type representing the headers object in a request.
78
+ * Options for global authentication in Express-like applications.
98
79
  *
99
- * @template SV - A type that extends AnySchemaValidator.
100
- */
101
- type HeadersObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
102
- type RawTypedResponseBody<SV extends AnySchemaValidator> = TextBody<SV> | JsonBody<SV> | FileBody<SV> | ServerSentEventBody<SV> | UnknownResponseBody<SV>;
103
- type ExclusiveResponseBodyBase<SV extends AnySchemaValidator> = {
104
- [K in keyof UnionToIntersection<RawTypedResponseBody<SV>>]?: undefined;
105
- };
106
- type ExclusiveSchemaCatchall<SV extends AnySchemaValidator> = {
107
- [K in keyof SV['_SchemaCatchall'] as string extends K ? never : number extends K ? never : symbol extends K ? never : K]?: undefined;
108
- };
109
- type TypedResponseBody<SV extends AnySchemaValidator> = {
110
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof TextBody<SV> ? TextBody<SV>[K] : undefined;
111
- } | {
112
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof JsonBody<SV> ? JsonBody<SV>[K] : undefined;
113
- } | {
114
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof FileBody<SV> ? FileBody<SV>[K] : undefined;
115
- } | {
116
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof ServerSentEventBody<SV> ? ServerSentEventBody<SV>[K] : undefined;
117
- } | {
118
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof UnknownResponseBody<SV> ? UnknownResponseBody<SV>[K] : undefined;
119
- };
120
- type ResponseBody<SV extends AnySchemaValidator> = TypedResponseBody<SV> | (ExclusiveResponseBodyBase<SV> & SV['_ValidSchemaObject']) | (ExclusiveResponseBodyBase<SV> & UnboxedObjectSchema<SV>) | (ExclusiveResponseBodyBase<SV> & SV['string']) | (ExclusiveResponseBodyBase<SV> & SV['number']) | (ExclusiveResponseBodyBase<SV> & SV['boolean']) | (ExclusiveResponseBodyBase<SV> & SV['date']) | (ExclusiveResponseBodyBase<SV> & SV['array']) | (ExclusiveResponseBodyBase<SV> & SV['file']);
121
- /**
122
- * Type representing the responses object in a request.
80
+ * @template SV - The schema validator type.
81
+ * @template SessionSchema - The session schema type.
82
+ * @template SubscriptionData - The subscription data type (defaults to DefaultSubscriptionData, must extend Record<string, unknown> | null).
123
83
  *
124
- * @template SV - A type that extends AnySchemaValidator.
84
+ * Can be `false` to disable authentication, or an object specifying session schema and
85
+ * functions to surface scopes, permissions, roles, subscription, and features from the JWT/session.
125
86
  */
126
- type ResponsesObject<SV extends AnySchemaValidator> = {
127
- [K: number]: ResponseBody<SV>;
128
- };
129
- type JsonBody<SV extends AnySchemaValidator> = {
130
- contentType?: 'application/json' | string;
131
- json: BodyObject<SV> | SV['_ValidSchemaObject'] | SV['_SchemaCatchall'];
87
+ type ExpressLikeGlobalAuthOptions<SV extends AnySchemaValidator, SessionSchema extends Record<string, unknown>, SubscriptionData extends Record<string, unknown> | null = DefaultSubscriptionData> = false | {
88
+ /**
89
+ * Optional session schema for the authentication context.
90
+ */
91
+ sessionSchema?: SessionSchema;
92
+ /**
93
+ * Optional array describing the scope hierarchy for authorization.
94
+ */
95
+ scopeHeirarchy?: string[];
96
+ /**
97
+ * Function to extract a set of scopes from the JWT payload and request.
98
+ */
99
+ surfaceScopes?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
100
+ /**
101
+ * Function to extract a set of permissions from the JWT payload and request.
102
+ */
103
+ surfacePermissions?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
104
+ /**
105
+ * Function to extract a set of roles from the JWT payload and request.
106
+ */
107
+ surfaceRoles?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
108
+ /**
109
+ * Function to extract subscription data from the JWT payload and request.
110
+ * Returns subscription information (status, plan, etc.) or null if no subscription.
111
+ */
112
+ surfaceSubscription?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => SubscriptionData | Promise<SubscriptionData>;
113
+ /**
114
+ * Function to extract a set of feature flags from the JWT payload and request.
115
+ * Returns features available to the organization based on their billing plan.
116
+ */
117
+ surfaceFeatures?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
132
118
  };
133
119
  /**
134
- * Type representing the body in a request.
120
+ * Schema-aware version of ExpressLikeGlobalAuthOptions.
135
121
  *
136
- * @template SV - A type that extends AnySchemaValidator.
122
+ * @template SV - The schema validator type.
123
+ * @template SessionSchema - The session object type.
124
+ * @template SubscriptionData - The subscription data type.
137
125
  */
138
- type TextBody<SV extends AnySchemaValidator> = {
139
- contentType?: 'application/xml' | 'text/plain' | 'text/html' | 'text/css' | 'text/javascript' | 'text/csv' | 'text/markdown' | 'text/xml' | 'text/rtf' | 'text/x-yaml' | 'text/yaml' | string;
140
- text: SV['string'];
141
- };
142
- type FileBody<SV extends AnySchemaValidator> = {
143
- contentType?: 'application/octet-stream' | 'application/pdf' | 'application/vnd.ms-excel' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'application/msword' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/zip' | 'image/jpeg' | 'image/png' | 'image/gif' | 'audio/mpeg' | 'audio/wav' | 'video/mp4' | string;
144
- file: SV['file'];
145
- };
126
+ type ExpressLikeSchemaGlobalAuthOptions<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>, SubscriptionData extends Record<string, unknown> | null = DefaultSubscriptionData> = ExpressLikeGlobalAuthOptions<SV, MapSessionSchema<SV, SessionSchema>, SubscriptionData>;
146
127
  /**
147
- * Type representing the body in a request.
128
+ * Options for configuring an Express-like router.
148
129
  *
149
- * @template SV - A type that extends AnySchemaValidator.
130
+ * @template SV - The schema validator type.
131
+ * @template SessionSchema - The session object type.
132
+ * @template SubscriptionData - The subscription data type.
150
133
  */
151
- type MultipartForm<SV extends AnySchemaValidator> = {
152
- contentType?: 'multipart/form-data' | 'multipart/mixed' | 'multipart/alternative' | 'multipart/related' | 'multipart/signed' | 'multipart/encrypted' | string;
153
- multipartForm: BodyObject<SV>;
134
+ type ExpressLikeRouterOptions<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>, SubscriptionData extends Record<string, unknown> | null = DefaultSubscriptionData> = {
135
+ /**
136
+ * Authentication options for the router.
137
+ */
138
+ auth?: ExpressLikeSchemaGlobalAuthOptions<SV, SessionSchema, SubscriptionData>;
139
+ /**
140
+ * Validation options for request and response.
141
+ * Can be `false` to disable validation, or an object to configure request/response validation levels.
142
+ */
143
+ validation?: false | {
144
+ /**
145
+ * Request validation mode: 'none', 'warning', or 'error'.
146
+ */
147
+ request?: 'none' | 'warning' | 'error';
148
+ /**
149
+ * Response validation mode: 'none', 'warning', or 'error'.
150
+ */
151
+ response?: 'none' | 'warning' | 'error';
152
+ };
153
+ /**
154
+ * OpenAPI documentation options.
155
+ */
156
+ openapi?: boolean;
157
+ /**
158
+ * MCP options.
159
+ */
160
+ mcp?: boolean;
154
161
  };
155
162
  /**
156
- * Type representing the body in a request.
163
+ * Options for configuring an Express-like application.
157
164
  *
158
- * @template SV - A type that extends AnySchemaValidator.
165
+ * @template SV - The schema validator type.
166
+ * @template SessionSchema - The session object type.
167
+ * @template SubscriptionData - The subscription data type.
159
168
  */
160
- type UrlEncodedForm<SV extends AnySchemaValidator> = {
161
- contentType?: 'application/x-www-form-urlencoded' | 'application/x-url-encoded' | 'application/x-www-url-encoded' | 'application/x-urlencode' | string;
162
- urlEncodedForm: BodyObject<SV>;
163
- };
164
- type ServerSentEventBody<SV extends AnySchemaValidator> = {
165
- contentType?: 'text/event-stream' | string;
166
- event: {
167
- id: SV['string'];
168
- data: SV['string'] | BodyObject<SV>;
169
- };
170
- };
171
- type UnknownBody<SV extends AnySchemaValidator> = {
172
- contentType?: string;
173
- schema: BodyObject<SV> | SV['_ValidSchemaObject'] | SV['_SchemaCatchall'];
174
- };
175
- type UnknownResponseBody<SV extends AnySchemaValidator> = {
176
- contentType?: string;
177
- schema: BodyObject<SV> | SV['_ValidSchemaObject'] | SV['_SchemaCatchall'];
178
- };
179
- type ExclusiveRequestBodyBase<SV extends AnySchemaValidator> = {
180
- [K in keyof UnionToIntersection<TypedBody<SV>>]?: undefined;
181
- };
182
- type TypedRequestBody<SV extends AnySchemaValidator> = {
183
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof TextBody<SV> ? TextBody<SV>[K] : undefined;
184
- } | {
185
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof JsonBody<SV> ? JsonBody<SV>[K] : undefined;
186
- } | {
187
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof FileBody<SV> ? FileBody<SV>[K] : undefined;
188
- } | {
189
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof MultipartForm<SV> ? MultipartForm<SV>[K] : undefined;
190
- } | {
191
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof UrlEncodedForm<SV> ? UrlEncodedForm<SV>[K] : undefined;
192
- } | {
193
- [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof UnknownBody<SV> ? UnknownBody<SV>[K] : undefined;
194
- };
195
- type TypedBody<SV extends AnySchemaValidator> = JsonBody<SV> | TextBody<SV> | FileBody<SV> | MultipartForm<SV> | UrlEncodedForm<SV> | UnknownBody<SV>;
196
- type Body<SV extends AnySchemaValidator> = TypedRequestBody<SV> | (ExclusiveRequestBodyBase<SV> & SV['_ValidSchemaObject']) | (ExclusiveRequestBodyBase<SV> & UnboxedObjectSchema<SV>) | (ExclusiveRequestBodyBase<SV> & SV['string']) | (ExclusiveRequestBodyBase<SV> & SV['number']) | (ExclusiveRequestBodyBase<SV> & SV['boolean']) | (ExclusiveRequestBodyBase<SV> & SV['date']) | (ExclusiveRequestBodyBase<SV> & SV['array']) | (ExclusiveRequestBodyBase<SV> & SV['file']) | (ExclusiveRequestBodyBase<SV> & SV['any']) | (ExclusiveRequestBodyBase<SV> & SV['unknown']) | (ExclusiveRequestBodyBase<SV> & SV['binary']) | (ExclusiveRequestBodyBase<SV> & (SV['type'] extends TypeSafeFunction ? ReturnType<SV['type']> : never));
197
- type SessionObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
198
- type BasicAuthMethods = {
199
- readonly basic: {
200
- readonly login: (username: string, password: string) => boolean;
169
+ type ExpressLikeApplicationOptions<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>, SubscriptionData extends Record<string, unknown> | null = DefaultSubscriptionData> = Omit<ExpressLikeRouterOptions<SV, SessionSchema, SubscriptionData>, 'openapi' | 'mcp'> & {
170
+ /**
171
+ * Documentation configuration.
172
+ */
173
+ docs?: DocsConfiguration;
174
+ /**
175
+ * Hosting/server options.
176
+ */
177
+ hosting?: {
178
+ /**
179
+ * SSL configuration or boolean to enable/disable SSL.
180
+ */
181
+ ssl?: {
182
+ /**
183
+ * SSL certificate as a string.
184
+ */
185
+ certFile: string;
186
+ /**
187
+ * SSL key as a string.
188
+ */
189
+ keyFile: string;
190
+ /**
191
+ * SSL CA as a string.
192
+ */
193
+ caFile: string;
194
+ };
195
+ /**
196
+ * Number of worker processes to spawn.
197
+ */
198
+ workerCount?: number;
199
+ /**
200
+ * Routing strategy to use.
201
+ */
202
+ routingStrategy?: 'round-robin' | 'sticky' | 'random';
201
203
  };
202
- readonly jwt?: never;
203
- readonly hmac?: never;
204
- };
205
- type JwtAuthMethods = {
206
- jwt: {
207
- readonly jwksPublicKey: JWK;
208
- } | {
209
- readonly jwksPublicKeyUrl: string;
210
- } | {
211
- readonly signatureKey: string;
204
+ /**
205
+ * FastMCP (management/control plane) options.
206
+ * Can be `false` to disable, or an object to configure.
207
+ */
208
+ mcp?: false | {
209
+ /**
210
+ * Port for the MCP server.
211
+ */
212
+ port?: number;
213
+ /**
214
+ * Endpoint for the MCP server.
215
+ */
216
+ path?: `/${string}`;
217
+ /**
218
+ * Additional options for FastMCP.
219
+ */
220
+ options?: ConstructorParameters<typeof FastMCP>[0];
221
+ /**
222
+ * Optional authentication callback for validating MCP requests.
223
+ * Called by FastMCP for each request to verify the session token.
224
+ * Return user info object if authenticated, undefined otherwise.
225
+ * Example: { email: 'user@example.com', name: 'User' }
226
+ */
227
+ authenticate?: (request: http.IncomingMessage) => Promise<Record<string, unknown> | undefined>;
228
+ /**
229
+ * Additional tools to register with the MCP server.
230
+ */
231
+ additionalTools?: (mcpServer: FastMCP) => void;
232
+ /**
233
+ * Content type mapping for the MCP server.
234
+ */
235
+ contentTypeMapping?: Record<string, string>;
236
+ /**
237
+ * Version of the MCP server.
238
+ */
239
+ version?: `${number}.${number}.${number}`;
212
240
  };
213
- readonly basic?: never;
214
- readonly hmac?: never;
215
- };
216
- type HmacMethods = {
217
- readonly hmac: {
218
- readonly secretKeys: Record<string, string>;
241
+ /**
242
+ * OpenAPI documentation options.
243
+ * Can be `false` to disable, or an object to configure.
244
+ */
245
+ openapi?: false | {
246
+ /**
247
+ * Path to serve the OpenAPI docs (e.g., '/openapi').
248
+ */
249
+ path?: `/${string}`;
250
+ /**
251
+ * Title for the OpenAPI documentation.
252
+ */
253
+ title?: string;
254
+ /**
255
+ * Description for the OpenAPI documentation.
256
+ */
257
+ description?: string;
258
+ /**
259
+ * Contact information for the API.
260
+ */
261
+ contact?: {
262
+ /**
263
+ * Contact name.
264
+ */
265
+ name?: string;
266
+ /**
267
+ * Contact email.
268
+ */
269
+ email?: string;
270
+ };
271
+ /**
272
+ * Whether to enable discrete versioning for OpenAPI docs.
273
+ */
274
+ discreteVersions?: boolean;
219
275
  };
220
- readonly sessionSchema?: never;
221
- readonly basic?: never;
222
- readonly jwt?: never;
223
- };
224
- type TokenOptions = {
225
- readonly tokenPrefix?: string;
226
- readonly headerName?: string;
227
- };
228
- type DecodeResource = (token: string) => JWTPayload | Promise<JWTPayload>;
229
- type AuthMethodsBase = TokenOptions & (HmacMethods | ({
230
- readonly decodeResource?: DecodeResource;
231
- } & (PermissionSet | RoleSet) & (BasicAuthMethods | JwtAuthMethods)));
232
- type PermissionSet = {
233
- readonly allowedPermissions: Set<string>;
234
- } | {
235
- readonly forbiddenPermissions: Set<string>;
236
- };
237
- type RoleSet = {
238
- readonly allowedRoles: Set<string>;
239
- } | {
240
- readonly forbiddenRoles: Set<string>;
241
- };
242
- /**
243
- * Route access level — determines authentication and authorization requirements.
244
- *
245
- * - `'public'` — No authentication required. `auth` must not be provided.
246
- * - `'authenticated'` — JWT or Basic auth required, any valid user. RBAC optional.
247
- * - `'protected'` — JWT or Basic auth required. Must declare roles, permissions, or scope.
248
- * - `'internal'` — HMAC auth required (inter-service communication).
249
- */
250
- type AccessLevel = 'public' | 'authenticated' | 'protected' | 'internal';
251
- /**
252
- * Discriminated union that narrows the `auth` type based on the `access` level.
253
- * - `public`: auth not allowed
254
- * - `authenticated`: auth optional (JWT/Basic, RBAC not required)
255
- * - `protected`: auth required, must include at least one RBAC declaration
256
- * - `internal`: auth required, must be HMAC
257
- */
258
- type AccessAuth<Auth> = {
259
- readonly access: 'public';
260
- readonly auth?: never;
261
- } | {
262
- readonly access: 'authenticated';
263
- readonly auth?: Auth;
264
- } | {
265
- readonly access: 'protected';
266
- readonly auth: Auth & ({
267
- readonly allowedPermissions: Set<string>;
268
- } | {
269
- readonly forbiddenPermissions: Set<string>;
270
- } | {
271
- readonly allowedRoles: Set<string>;
272
- } | {
273
- readonly forbiddenRoles: Set<string>;
274
- } | {
275
- readonly requiredScope: string;
276
- });
277
- } | {
278
- readonly access: 'internal';
279
- readonly auth: Auth & HmacMethods;
276
+ /**
277
+ * CORS configuration options.
278
+ */
279
+ cors?: CorsOptions;
280
280
  };
281
+
281
282
  /**
282
- * Type representing the authentication methods.
283
+ * Interface representing the context of a request.
283
284
  */
284
- type SchemaAuthMethods<SV extends AnySchemaValidator, ParamsSchema extends ParamsObject<SV>, ReqBody extends Body<SV>, QuerySchema extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method>, BaseRequest> = AuthMethodsBase & {
285
- readonly sessionSchema?: SessionObject<SV>;
286
- readonly requiredScope?: string;
287
- readonly scopeHeirarchy?: string[];
288
- readonly surfaceScopes?: ExpressLikeSchemaAuthMapper<SV, ParamsSchema, ReqBody, QuerySchema, ReqHeaders, VersionedApi, SessionObject<SV>, BaseRequest>;
289
- readonly requiredFeatures?: string[];
290
- readonly requireActiveSubscription?: boolean;
291
- } & ({
292
- readonly surfacePermissions?: ExpressLikeSchemaAuthMapper<SV, ParamsSchema, ReqBody, QuerySchema, ReqHeaders, VersionedApi, SessionObject<SV>, BaseRequest>;
293
- } | {
294
- readonly surfaceRoles?: ExpressLikeSchemaAuthMapper<SV, ParamsSchema, ReqBody, QuerySchema, ReqHeaders, VersionedApi, SessionObject<SV>, BaseRequest>;
295
- });
296
- type AuthMethods<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, BaseRequest> = AuthMethodsBase & {
297
- readonly sessionSchema?: SessionObject<SV>;
298
- readonly requiredScope?: string;
299
- readonly scopeHeirarchy?: string[];
300
- readonly surfaceScopes?: ExpressLikeAuthMapper<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionObject<SV>, BaseRequest>;
301
- readonly requiredFeatures?: string[];
302
- readonly requireActiveSubscription?: boolean;
303
- } & (({
304
- readonly surfacePermissions?: ExpressLikeAuthMapper<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionObject<SV>, BaseRequest>;
305
- } & PermissionSet) | ({
306
- readonly surfaceRoles?: ExpressLikeAuthMapper<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionObject<SV>, BaseRequest>;
307
- } & RoleSet));
285
+ interface RequestContext {
286
+ /** Correlation ID for tracking requests */
287
+ correlationId: string;
288
+ /** Optional idempotency key for ensuring idempotent requests */
289
+ idempotencyKey?: string;
290
+ /** Active OpenTelemetry Span */
291
+ span?: Span;
292
+ }
293
+ interface ForklaunchBaseRequest<P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>> {
294
+ /** Request parameters */
295
+ params: P;
296
+ /** Request headers */
297
+ headers: ReqHeaders;
298
+ /** Request body */
299
+ body: ReqBody;
300
+ /** Request query */
301
+ query: ReqQuery;
302
+ /** Method */
303
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE';
304
+ /** Request path */
305
+ path: string;
306
+ /** Original path */
307
+ originalPath: string;
308
+ /** OpenTelemetry Collector */
309
+ openTelemetryCollector?: OpenTelemetryCollector<MetricsDefinition>;
310
+ }
308
311
  /**
309
- * Type representing a mapped schema.
310
- *s ParamsDictionary,
311
- // ReqBody extends Record<string, unknown>,
312
- //
312
+ * Interface representing a Forklaunch request.
313
+ *
313
314
  * @template SV - A type that extends AnySchemaValidator.
314
- * @template T - A type that extends IdiomaticSchema or a valid schema object.
315
- */
316
- type MapSchema<SV extends AnySchemaValidator, T extends IdiomaticSchema<SV> | SV['_ValidSchemaObject']> = Schema<T, SV> extends infer U ? (T extends U ? unknown : U) : never;
317
- /**
318
- * Type representing the parameters in a request.
315
+ * @template P - A type for request parameters, defaulting to ParamsDictionary.
316
+ * @template ReqBody - A type for the request body, defaulting to unknown.
317
+ * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
318
+ * @template Headers - A type for the request headers, defaulting to IncomingHttpHeaders.
319
319
  */
320
- type ExtractParams<Path extends `/${string}`> = Path extends `${string}/:${infer Param}/${infer Rest}` ? Param | ExtractParams<`/${Rest}`> : Path extends `${string}/:${infer Param}` ? Param : never;
320
+ interface ForklaunchRequest<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, unknown>, Version extends string, SessionSchema extends Record<string, unknown>> {
321
+ /** Context of the request */
322
+ context: Prettify<RequestContext>;
323
+ /** API Version of the request */
324
+ version: Version;
325
+ /** Request parameters */
326
+ params: P;
327
+ /** Request headers */
328
+ headers: ReqHeaders;
329
+ /** Request body */
330
+ body: ReqBody;
331
+ /** Request query */
332
+ query: ReqQuery;
333
+ /** Contract details for the request */
334
+ contractDetails: PathParamHttpContractDetails<SV> | HttpContractDetails<SV>;
335
+ /** Schema validator */
336
+ schemaValidator: SV;
337
+ /** Method */
338
+ method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE';
339
+ /** Request path */
340
+ path: string;
341
+ /** Request schema, compiled */
342
+ requestSchema: unknown | Record<string, unknown>;
343
+ /** Original path */
344
+ originalPath: string;
345
+ /** OpenTelemetry Collector */
346
+ openTelemetryCollector?: OpenTelemetryCollector<MetricsDefinition>;
347
+ /** Session */
348
+ session: JWTPayload & SessionSchema;
349
+ /** Parsed versions */
350
+ _parsedVersions: string[] | number;
351
+ /** Raw body before schema validation (for HMAC verification) */
352
+ _rawBody?: unknown;
353
+ /** Global options */
354
+ _globalOptions: () => ExpressLikeRouterOptions<SV, SessionSchema> | undefined;
355
+ }
321
356
  /**
322
- * Type representing the parameters in a request.
357
+ * Represents the types of data that can be sent in a response.
323
358
  */
324
- type ExtractedParamsObject<Path extends `/${string}`> = Record<ExtractParams<Path>, unknown>;
359
+ type ForklaunchSendableData = Record<string, unknown> | string | Buffer | ArrayBuffer | NodeJS.ReadableStream | null | undefined;
325
360
  /**
326
- * Represents the path parameter methods.
361
+ * Interface representing a Forklaunch response status.
362
+ * @template ResBody - A type for the response body.
327
363
  */
328
- type PathParamMethod = 'get' | 'delete' | 'options' | 'head' | 'trace';
364
+ interface ForklaunchStatusResponse<ResBody> {
365
+ /**
366
+ * Sends the response.
367
+ * @param {ResBodyMap} [body] - The response body.
368
+ * @param {boolean} [close_connection] - Whether to close the connection.
369
+ * @returns {T} - The sent response.
370
+ */
371
+ send: {
372
+ (body?: ResBody extends AsyncGenerator<unknown> ? never : ResBody extends Blob ? Blob | File | Buffer | ArrayBuffer | NodeJS.ReadableStream : ResBody | null, close_connection?: boolean): boolean;
373
+ <U>(body?: ResBody extends AsyncGenerator<unknown> ? never : ResBody extends Blob ? Blob | File | Buffer | ArrayBuffer | NodeJS.ReadableStream : ResBody | null, close_connection?: boolean): U;
374
+ };
375
+ /**
376
+ * Sends a JSON response.
377
+ * @param {ResBodyMap} [body] - The response body.
378
+ * @returns {boolean|T} - The JSON response.
379
+ */
380
+ json: {
381
+ (body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): boolean;
382
+ <U>(body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): U;
383
+ };
384
+ /**
385
+ * Sends a JSONP response.
386
+ * @param {ResBodyMap} [body] - The response body.
387
+ * @returns {boolean|T} - The JSONP response.
388
+ */
389
+ jsonp: {
390
+ (body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): boolean;
391
+ <U>(body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): U;
392
+ };
393
+ /**
394
+ * Sends a Server-Sent Event (SSE) response.
395
+ * @param {ResBodyMap} [body] - The response body.
396
+ * @param {number} interval - The interval between events.
397
+ */
398
+ sseEmitter: (generator: () => AsyncGenerator<ResBody extends AsyncGenerator<infer T> ? T : never, void, unknown>) => void;
399
+ }
400
+ type ToNumber<T extends string | number | symbol> = T extends number ? T : T extends `${infer N extends number}` ? N : never;
329
401
  /**
330
- * Represents the body parameter methods.
402
+ * Interface representing a Forklaunch response.
403
+ *
404
+ * @template ResBodyMap - A type for the response body, defaulting to common status code responses.
405
+ * @template StatusCode - A type for the status code, defaulting to number.
331
406
  */
332
- type HttpMethod = 'post' | 'patch' | 'put';
407
+ interface ForklaunchResponse<BaseResponse, ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, unknown>, LocalsObj extends Record<string, unknown>, Version extends string> {
408
+ /** Data of the response body */
409
+ bodyData: unknown;
410
+ /** Status code of the response */
411
+ statusCode: number;
412
+ /** Whether the response is finished */
413
+ headersSent: boolean;
414
+ /**
415
+ * Gets the headers of the response.
416
+ * @returns {Omit<ResHeaders, keyof ForklaunchResHeaders> & ForklaunchResHeaders} - The headers of the response.
417
+ */
418
+ getHeaders: () => Omit<ResHeaders, keyof ForklaunchResHeaders> & ForklaunchResHeaders;
419
+ /**
420
+ * Gets a header for the response.
421
+ * @param {string} key - The header key.
422
+ * @returns {string | string[] | undefined} The header value.
423
+ */
424
+ getHeader: (key: string) => string | string[] | undefined;
425
+ /**
426
+ * Sets a header for the response.
427
+ * @param {string} key - The header key.
428
+ * @param {string} value - The header value.
429
+ */
430
+ setHeader: {
431
+ <K extends keyof (ResHeaders & ForklaunchResHeaders)>(key: K, value: K extends keyof ForklaunchResHeaders ? ForklaunchResHeaders[K] : ResHeaders[K]): void;
432
+ <K extends keyof (ResHeaders & ForklaunchResHeaders)>(key: K, value: K extends keyof ForklaunchResHeaders ? ForklaunchResHeaders[K] : ResHeaders[K]): BaseResponse;
433
+ };
434
+ /**
435
+ * Adds an event listener to the response.
436
+ * @param {string} event - The event to listen for.
437
+ * @param {Function} listener - The listener function.
438
+ */
439
+ on(event: 'close', listener: () => void): BaseResponse & this;
440
+ on(event: 'drain', listener: () => void): BaseResponse & this;
441
+ on(event: 'error', listener: (err: Error) => void): BaseResponse & this;
442
+ on(event: 'finish', listener: () => void): BaseResponse & this;
443
+ on(event: 'pipe', listener: (src: Readable) => void): BaseResponse & this;
444
+ on(event: 'unpipe', listener: (src: Readable) => void): BaseResponse & this;
445
+ on(event: string | symbol, listener: (...args: unknown[]) => void): BaseResponse & this;
446
+ /**
447
+ * Sets the status of the response.
448
+ * @param {U} code - The status code.
449
+ * @param {string} [message] - Optional message.
450
+ * @returns {ForklaunchResponse<(ResBodyMap)[U], ResHeaders, U, LocalsObj>} - The response with the given status.
451
+ */
452
+ status: {
453
+ <U extends ToNumber<keyof (ResBodyMap & ForklaunchResErrors)>>(code: U): Omit<BaseResponse, keyof ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>> & ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>;
454
+ <U extends ToNumber<keyof (ResBodyMap & ForklaunchResErrors)>>(code: U, message?: string): Omit<BaseResponse, keyof ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>> & ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>;
455
+ };
456
+ /**
457
+ * Ends the response.
458
+ * @param {string} [data] - Optional data to send.
459
+ */
460
+ end: {
461
+ (data?: string): void;
462
+ (cb?: (() => void) | undefined): BaseResponse;
463
+ };
464
+ /**
465
+ * Sets the content type of the response.
466
+ * @param {string} type - The content type.
467
+ */
468
+ type: {
469
+ (type: string): void;
470
+ (type: string): BaseResponse;
471
+ };
472
+ /** Local variables */
473
+ locals: LocalsObj;
474
+ /** Cors */
475
+ cors: boolean;
476
+ /** Response schema, compiled */
477
+ responseSchemas: ResponseCompiledSchema | Record<string, ResponseCompiledSchema>;
478
+ /** Whether the metric has been recorded */
479
+ metricRecorded: boolean;
480
+ /** Whether the response has been sent */
481
+ sent: boolean;
482
+ /** Versioned responses */
483
+ version: Version;
484
+ }
333
485
  /**
334
- * Represents all supported typed methods.
486
+ * Type representing the next function in a middleware.
487
+ * @param {unknown} [err] - Optional error parameter.
335
488
  */
336
- type Method = PathParamMethod | HttpMethod | 'middleware';
489
+ type ForklaunchNextFunction = (err?: unknown) => void;
490
+ type VersionedRequests = Record<string, {
491
+ requestHeaders?: Record<string, unknown>;
492
+ body?: Record<string, unknown>;
493
+ query?: Record<string, unknown>;
494
+ }>;
495
+ type ResolvedForklaunchRequestBase<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, unknown>, Version extends string, SessionSchema extends Record<string, unknown>, BaseRequest> = unknown extends BaseRequest ? ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Version, SessionSchema> : Omit<BaseRequest, keyof ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Version, SessionSchema>> & ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Version, SessionSchema>;
337
496
  /**
338
- * Interface representing a compiled schema for a response.
497
+ * Type representing the resolved forklaunch request from a base request type.
498
+ * @template SV - A type that extends AnySchemaValidator.
499
+ * @template P - A type for request parameters, defaulting to ParamsDictionary.
500
+ * @template ReqBody - A type for the request body, defaulting to Record<string, unknown>.
501
+ * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
502
+ * @template ReqHeaders - A type for the request headers, defaulting to Record<string, unknown>.
503
+ * @template BaseRequest - A type for the base request.
339
504
  */
340
- type ResponseCompiledSchema = {
341
- headers?: unknown;
342
- responses: Record<number, unknown>;
343
- };
344
- type BasePathParamHttpContractDetailsIO<SV extends AnySchemaValidator, BodySchema extends Body<SV> | undefined = Body<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, QuerySchema extends QueryObject<SV> | undefined = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> | undefined = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> | undefined = HeadersObject<SV>> = {
345
- /** Optional body for the contract */
346
- readonly body?: BodySchema;
347
- /** Response schemas for the contract */
348
- readonly responses: ResponseSchemas;
349
- /** Optional request headers for the contract */
350
- readonly requestHeaders?: ReqHeaders;
351
- /** Optional response headers for the contract */
352
- readonly responseHeaders?: ResHeaders;
353
- /** Optional query schemas for the contract */
354
- readonly query?: QuerySchema;
505
+ type ResolvedForklaunchRequest<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, SessionSchema extends Record<string, unknown>, BaseRequest> = VersionedRequests extends VersionedReqs ? ResolvedForklaunchRequestBase<SV, P, ReqBody, ReqQuery, ReqHeaders, never, SessionSchema, BaseRequest> : {
506
+ [K in keyof VersionedReqs]: ResolvedForklaunchRequestBase<SV, P, VersionedReqs[K]['body'] extends Record<string, unknown> ? VersionedReqs[K]['body'] : Record<string, unknown>, VersionedReqs[K]['query'] extends Record<string, unknown> ? VersionedReqs[K]['query'] : ParsedQs, VersionedReqs[K]['requestHeaders'] extends Record<string, unknown> ? VersionedReqs[K]['requestHeaders'] : Record<string, string>, K extends string ? K : never, SessionSchema, BaseRequest>;
507
+ }[keyof VersionedReqs];
508
+ type ResolvedForklaunchAuthRequest<P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, BaseRequest> = unknown extends BaseRequest ? ForklaunchBaseRequest<P, ReqBody, ReqQuery, ReqHeaders> : {
509
+ [key in keyof BaseRequest]: key extends keyof ForklaunchBaseRequest<P, ReqBody, ReqQuery, ReqHeaders> ? ForklaunchBaseRequest<P, ReqBody, ReqQuery, ReqHeaders>[key] : key extends keyof BaseRequest ? BaseRequest[key] : never;
355
510
  };
356
- type VersionedBasePathParamHttpContractDetailsIO<SV extends AnySchemaValidator, VersionedApi extends VersionSchema<SV, PathParamMethod>> = {
357
- readonly versions: VersionedApi;
511
+ type VersionedResponses = Record<string, {
512
+ responseHeaders?: Record<string, unknown>;
513
+ responses: Record<number, unknown>;
514
+ }>;
515
+ type ResolvedForklaunchResponseBase<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, unknown>, LocalsObj extends Record<string, unknown>, Version extends string, BaseResponse> = unknown extends BaseResponse ? ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version> : (string extends Version ? unknown : {
516
+ version?: Version;
517
+ }) & {
518
+ [K in keyof BaseResponse | keyof ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version>]: K extends keyof ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version> ? ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version>[K] : K extends keyof BaseResponse ? BaseResponse[K] : never;
358
519
  };
359
- type BasePathParamHttpContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>> = {
360
- /** Name of the contract */
361
- readonly name: StringWithoutSlash<Name>;
362
- /** Summary of the contract */
363
- readonly summary: string;
364
- /** Options for the contract */
365
- readonly options?: {
366
- /** Optional request validation for the contract */
367
- readonly requestValidation?: 'error' | 'warning' | 'none';
368
- /** Optional response validation for the contract */
369
- readonly responseValidation?: 'error' | 'warning' | 'none';
370
- /** Optional MCP details for the contract */
371
- readonly mcp?: boolean;
372
- /** Optional OpenAPI details for the contract */
373
- readonly openapi?: boolean;
374
- };
375
- } & (string | number | symbol extends ExtractedParamsObject<Path> ? {
376
- /** Optional parameters for the contract */
377
- readonly params?: ParamsSchema;
378
- } : {
379
- /** Required parameters for the contract */
380
- readonly params: {
381
- [K in keyof ExtractedParamsObject<Path>]: ParamsSchema[K];
382
- };
383
- });
520
+ type ResolvedForklaunchResponse<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>, VersionedResps extends VersionedResponses, BaseResponse> = VersionedResponses extends VersionedResps ? ResolvedForklaunchResponseBase<ResBodyMap, ResHeaders, LocalsObj, never, BaseResponse> : {
521
+ [K in keyof VersionedResps]: ResolvedForklaunchResponseBase<VersionedResps[K]['responses'], VersionedResps[K]['responseHeaders'] extends Record<string, unknown> ? VersionedResps[K]['responseHeaders'] : Record<string, string>, LocalsObj, K extends string ? K : never, BaseResponse>;
522
+ }[keyof VersionedResps];
384
523
  /**
385
- * Interface representing HTTP contract details for path parameters.
524
+ * Represents a middleware handler with schema validation.
386
525
  *
387
526
  * @template SV - A type that extends AnySchemaValidator.
388
- * @template ParamsSchema - A type for parameter schemas, defaulting to ParamsObject.
389
- * @template ResponseSchemas - A type for response schemas, defaulting to ResponsesObject.
390
- * @template QuerySchema - A type for query schemas, defaulting to QueryObject.
527
+ * @template P - A type for request parameters, defaulting to ParamsDictionary.
528
+ * @template ResBodyMap - A type for the response body, defaulting to unknown.
529
+ * @template ReqBody - A type for the request body, defaulting to unknown.
530
+ * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
531
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
532
+ * @template StatusCode - A type for the status code, defaulting to number.
391
533
  */
392
- type PathParamHttpContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, BodySchema extends Body<SV> = Body<SV>, QuerySchema extends QueryObject<SV> = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> = HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method> = VersionSchema<SV, PathParamMethod>, BaseRequest = unknown, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest> = SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = BasePathParamHttpContractDetails<SV, Name, Path, ParamsSchema> & ((BasePathParamHttpContractDetailsIO<SV, never, ResponseSchemas, QuerySchema, ReqHeaders, ResHeaders> & {
393
- readonly versions?: never;
394
- }) | (VersionedBasePathParamHttpContractDetailsIO<SV, VersionedApi> & {
395
- readonly query?: never;
396
- readonly requestHeaders?: never;
397
- readonly responseHeaders?: never;
398
- readonly responses?: never;
399
- })) & AccessAuth<Auth>;
400
- type VersionedHttpContractDetailsIO<SV extends AnySchemaValidator, VersionedApi extends VersionSchema<SV, HttpMethod>> = {
401
- readonly versions: VersionedApi;
534
+ interface ExpressLikeHandler<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>, VersionedReqs extends VersionedRequests, VersionedResps extends VersionedResponses, SessionSchema extends Record<string, unknown>, BaseRequest, BaseResponse, NextFunction> {
535
+ (req: ResolvedForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionSchema, BaseRequest>, res: ResolvedForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj, VersionedResps, BaseResponse>, next: NextFunction): unknown;
536
+ }
537
+ type MapParamsSchema<SV extends AnySchemaValidator, P extends ParamsObject<SV>> = MapSchema<SV, P> extends infer Params ? unknown extends Params ? ParamsDictionary : Params : ParamsDictionary;
538
+ type ExtractContentType<SV extends AnySchemaValidator, T extends ResponseBody<SV> | unknown> = T extends {
539
+ contentType: string;
540
+ } ? T['contentType'] : T extends JsonBody<SV> ? 'application/json' : T extends TextBody<SV> ? 'text/plain' : T extends FileBody<SV> ? 'application/octet-stream' : T extends ServerSentEventBody<SV> ? 'text/event-stream' : T extends UnknownResponseBody<SV> ? 'application/json' : T extends SV['file'] ? 'application/octet-stream' : 'text/plain';
541
+ type ExtractResponseBody<SV extends AnySchemaValidator, T extends ResponseBody<SV> | unknown> = T extends JsonBody<SV> ? MapSchema<SV, T['json']> : T extends TextBody<SV> ? MapSchema<SV, T['text']> : T extends FileBody<SV> ? File | Blob : T extends ServerSentEventBody<SV> ? AsyncGenerator<MapSchema<SV, T['event']>> : T extends UnknownResponseBody<SV> ? MapSchema<SV, T['schema']> : MapSchema<SV, T>;
542
+ type MapResBodyMapSchema<SV extends AnySchemaValidator, ResBodyMap extends ResponsesObject<SV>> = unknown extends ResBodyMap ? ForklaunchResErrors : {
543
+ [K in keyof ResBodyMap]: ExtractResponseBody<SV, ResBodyMap[K]>;
402
544
  };
545
+ type ExtractBody<SV extends AnySchemaValidator, T extends Body<SV>> = T extends JsonBody<SV> ? T['json'] : T extends TextBody<SV> ? T['text'] : T extends FileBody<SV> ? T['file'] : T extends MultipartForm<SV> ? T['multipartForm'] : T extends UrlEncodedForm<SV> ? T['urlEncodedForm'] : T extends UnknownBody<SV> ? T['schema'] : T;
546
+ type MapReqBodySchema<SV extends AnySchemaValidator, ReqBody extends Body<SV>> = MapSchema<SV, ExtractBody<SV, ReqBody>> extends infer Body ? unknown extends Body ? Record<string, unknown> : Body : Record<string, unknown>;
547
+ type MapReqQuerySchema<SV extends AnySchemaValidator, ReqQuery extends QueryObject<SV>> = MapSchema<SV, ReqQuery> extends infer Query ? unknown extends Query ? ParsedQs : Query : ParsedQs;
548
+ type MapReqHeadersSchema<SV extends AnySchemaValidator, ReqHeaders extends HeadersObject<SV>> = MapSchema<SV, ReqHeaders> extends infer RequestHeaders ? unknown extends RequestHeaders ? Record<string, string> : RequestHeaders : Record<string, string>;
549
+ type MapResHeadersSchema<SV extends AnySchemaValidator, ResHeaders extends HeadersObject<SV>> = MapSchema<SV, ResHeaders> extends infer ResponseHeaders ? unknown extends ResponseHeaders ? ForklaunchResHeaders : ResponseHeaders : ForklaunchResHeaders;
550
+ type MapVersionedReqsSchema<SV extends AnySchemaValidator, VersionedReqs extends VersionSchema<SV, Method>> = {
551
+ [K in keyof VersionedReqs]: (VersionedReqs[K]['requestHeaders'] extends HeadersObject<SV> ? {
552
+ requestHeaders: MapReqHeadersSchema<SV, VersionedReqs[K]['requestHeaders']>;
553
+ } : unknown) & (VersionedReqs[K]['body'] extends Body<SV> ? {
554
+ body: MapReqBodySchema<SV, VersionedReqs[K]['body']>;
555
+ } : unknown) & (VersionedReqs[K]['query'] extends QueryObject<SV> ? {
556
+ query: MapReqQuerySchema<SV, VersionedReqs[K]['query']>;
557
+ } : unknown);
558
+ } extends infer MappedVersionedReqs ? MappedVersionedReqs extends VersionedRequests ? MappedVersionedReqs : VersionedRequests : VersionedRequests;
559
+ type MapVersionedRespsSchema<SV extends AnySchemaValidator, VersionedResps extends VersionSchema<SV, Method>> = {
560
+ [K in keyof VersionedResps]: (VersionedResps[K]['responseHeaders'] extends HeadersObject<SV> ? {
561
+ responseHeaders: MapResHeadersSchema<SV, VersionedResps[K]['responseHeaders']>;
562
+ } : unknown) & (VersionedResps[K]['responses'] extends ResponsesObject<SV> ? {
563
+ responses: MapResBodyMapSchema<SV, VersionedResps[K]['responses']>;
564
+ } : unknown);
565
+ } extends infer MappedVersionedResps ? MappedVersionedResps extends VersionedResponses ? MappedVersionedResps : VersionedResponses : VersionedResponses;
566
+ type MapSessionSchema<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>> = SessionSchema extends infer UnmappedSessionSchema ? UnmappedSessionSchema extends SessionObject<SV> ? MapSchema<SV, UnmappedSessionSchema> : never : never;
403
567
  /**
404
- * Interface representing HTTP contract details.
405
- *
406
- * @template SV - A type that extends AnySchemaValidator.
407
- * @template ParamsSchema - A type for parameter schemas, defaulting to ParamsObject.
408
- * @template ResponseSchemas - A type for response schemas, defaulting to ResponsesObject.
409
- * @template BodySchema - A type for the body schema, defaulting to Body.
410
- * @template QuerySchema - A type for query schemas, defaulting to QueryObject.
411
- */
412
- type HttpContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, BodySchema extends Body<SV> = Body<SV>, QuerySchema extends QueryObject<SV> = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> = HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method> = VersionSchema<SV, HttpMethod>, BaseRequest = unknown, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest> = SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = BasePathParamHttpContractDetails<SV, Name, Path, ParamsSchema> & ((BasePathParamHttpContractDetailsIO<SV, BodySchema, ResponseSchemas, QuerySchema, ReqHeaders, ResHeaders> & {
413
- readonly versions?: never;
414
- }) | (VersionedHttpContractDetailsIO<SV, VersionedApi> & {
415
- readonly query?: never;
416
- readonly requestHeaders?: never;
417
- readonly responseHeaders?: never;
418
- readonly body?: never;
419
- readonly responses?: never;
420
- })) & AccessAuth<Auth>;
421
- /**
422
- * Interface representing HTTP contract details for middleware.
568
+ * Represents a schema middleware handler with typed parameters, responses, body, and query.
423
569
  *
424
570
  * @template SV - A type that extends AnySchemaValidator.
425
- * @template ParamsSchema - A type for parameter schemas, defaulting to ParamsObject.
426
- * @template ResponseSchemas - A type for response schemas, defaulting to ResponsesObject.
427
- * @template QuerySchema - A type for query schemas, defaulting to QueryObject.
428
- * @template ReqHeaders - A type for request headers, defaulting to HeadersObject.
429
- * @template ResHeaders - A type for response headers, defaulting to HeadersObject.
430
- */
431
- type MiddlewareContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, BodySchema extends Body<SV> = Body<SV>, QuerySchema extends QueryObject<SV> = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> = HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method> = VersionSchema<SV, 'middleware'>, BaseRequest = unknown, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest> = SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = Omit<Partial<HttpContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth>>, 'responses'>;
432
- type VersionSchema<SV extends AnySchemaValidator, ContractMethod extends Method> = Record<string, BasePathParamHttpContractDetailsIO<SV, ContractMethod extends PathParamMethod ? never : Body<SV>, ResponsesObject<SV>, QueryObject<SV>, HeadersObject<SV>, HeadersObject<SV>>>;
433
- /**
434
- * Utility for different Contract Detail types
571
+ * @template P - A type for parameter schemas, defaulting to ParamsObject.
572
+ * @template ResBodyMap - A type for response schemas, defaulting to ResponsesObject.
573
+ * @template ReqBody - A type for the request body, defaulting to Body.
574
+ * @template ReqQuery - A type for the request query, defaulting to QueryObject.
575
+ * @template LocalsObj - A type for local variables, defaulting to an empty object.
435
576
  */
436
- type ContractDetails<SV extends AnySchemaValidator, Name extends string, ContractMethod extends Method, Path extends `/${string}`, ParamsSchema extends ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV>, BodySchema extends Body<SV>, QuerySchema extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, VersionedApi extends VersionSchema<SV, ContractMethod>, BaseRequest, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = ContractMethod extends PathParamMethod ? PathParamHttpContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth> : ContractMethod extends HttpMethod ? HttpContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth> : ContractMethod extends 'middleware' ? MiddlewareContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth> : never;
577
+ type ExpressLikeSchemaHandler<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, VersionedApi extends VersionSchema<SV, Method>, SessionSchema extends Record<string, unknown>, BaseRequest, BaseResponse, NextFunction> = ExpressLikeHandler<SV, MapParamsSchema<SV, P>, MapResBodyMapSchema<SV, ResBodyMap>, MapReqBodySchema<SV, ReqBody>, MapReqQuerySchema<SV, ReqQuery>, MapReqHeadersSchema<SV, ReqHeaders>, MapResHeadersSchema<SV, ResHeaders>, LocalsObj, MapVersionedReqsSchema<SV, VersionedApi>, MapVersionedRespsSchema<SV, VersionedApi>, MapSessionSchema<SV, SessionSchema>, BaseRequest, BaseResponse, NextFunction>;
437
578
  /**
438
- * Resolves the session object type to use for authentication.
579
+ * Represents a function that maps an authenticated request with schema validation
580
+ * to a set of authorization strings, with request properties automatically inferred from the schema.
439
581
  *
440
- * If `AuthSession` is provided and extends `SessionObject<SV>`, it is used as the session type.
441
- * Otherwise, the `FallbackSession` type is used.
582
+ * @template SV - The type representing the schema validator.
583
+ * @template P - The type representing request parameters inferred from the schema.
584
+ * @template ReqBody - The type representing the request body inferred from the schema.
585
+ * @template ReqQuery - The type representing the request query parameters inferred from the schema.
586
+ * @template ReqHeaders - The type representing the request headers inferred from the schema.
442
587
  *
443
- * @template SV - The schema validator type.
444
- * @template AuthSession - The session object type provided by the authentication method, or undefined.
445
- * @template FallbackSession - The fallback session object type to use if `AuthSession` is not provided.
588
+ * @param {ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>} req - The request object with schema validation.
589
+ * @returns {Set<string> | Promise<Set<string>>} - A set of authorization strings or a promise that resolves to it.
446
590
  */
447
- type ResolvedSessionObject<SV extends AnySchemaValidator, AuthSession extends SessionObject<SV> | undefined, FallbackSession extends SessionObject<SV>> = AuthSession extends {
448
- readonly sessionSchema?: infer ResolvedSessionSchema | undefined;
449
- } | undefined ? ResolvedSessionSchema extends SessionObject<SV> ? ResolvedSessionSchema : FallbackSession : FallbackSession;
450
-
451
- type DocsConfiguration = ({
452
- type: 'scalar';
453
- } & Partial<Omit<ApiReferenceConfiguration, 'spec'>>) | {
454
- type: 'swagger';
591
+ type ExpressLikeSchemaAuthMapper<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, VersionedReqs extends VersionSchema<SV, Method>, SessionSchema extends SessionObject<SV>, BaseRequest> = ExpressLikeAuthMapper<SV, P extends infer UnmappedParams ? UnmappedParams extends ParamsObject<SV> ? MapParamsSchema<SV, UnmappedParams> : never : never, ReqBody extends infer UnmappedReqBody ? UnmappedReqBody extends Body<SV> ? MapReqBodySchema<SV, UnmappedReqBody> : never : never, ReqQuery extends infer UnmappedReqQuery ? UnmappedReqQuery extends QueryObject<SV> ? MapReqQuerySchema<SV, UnmappedReqQuery> : never : never, ReqHeaders extends infer UnmappedReqHeaders ? UnmappedReqHeaders extends HeadersObject<SV> ? MapReqHeadersSchema<SV, UnmappedReqHeaders> : never : never, VersionedReqs extends infer UnmappedVersionedReqs ? UnmappedVersionedReqs extends VersionSchema<SV, Method> ? MapVersionedReqsSchema<SV, UnmappedVersionedReqs> : never : never, SessionSchema extends infer UnmappedSessionSchema ? UnmappedSessionSchema extends Record<string, unknown> ? MapSessionSchema<SV, UnmappedSessionSchema> : never : never, BaseRequest>;
592
+ type ExpressLikeAuthMapper<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, SessionSchema extends Record<string, unknown>, BaseRequest> = (payload: JWTPayload & SessionSchema, req?: ResolvedForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionSchema, BaseRequest>) => Set<string> | Promise<Set<string>>;
593
+ type TokenPrefix<Auth extends AuthMethodsBase> = undefined extends Auth['tokenPrefix'] ? Auth extends BasicAuthMethods ? 'Basic ' : Auth extends HmacMethods ? 'HMAC ' : 'Bearer ' : `${Auth['tokenPrefix']} `;
594
+ type AuthHeaders<Auth extends AuthMethodsBase> = undefined extends Auth['headerName'] ? {
595
+ authorization: Auth extends HmacMethods ? `${TokenPrefix<Auth>}keyId=${string} ts=${string} nonce=${string} signature=${string}` : `${TokenPrefix<Auth>}${string}`;
596
+ } : {
597
+ [K in NonNullable<Auth['headerName']>]: `${TokenPrefix<Auth>}${string}`;
455
598
  };
456
-
457
- /**
458
- * Default subscription data structure.
459
- * Applications can override this with their own subscription type.
460
- */
461
- type DefaultSubscriptionData = {
462
- subscriptionId: string;
463
- planId: string;
464
- planName: string;
465
- status: string;
466
- currentPeriodEnd: Date;
467
- } | null;
599
+ type AuthCollapse<Auth extends AuthMethodsBase> = undefined extends Auth['jwt'] ? undefined extends Auth['basic'] ? undefined extends Auth['hmac'] ? true : false : false : false;
600
+ type LiveTypeFunctionRequestInit<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ReqBody extends Body<SV> | undefined, ReqQuery extends QueryObject<SV> | undefined, ReqHeaders extends HeadersObject<SV> | undefined, Auth extends AuthMethodsBase> = MakePropertyOptionalIfChildrenOptional<(Body<SV> extends ReqBody ? unknown : {
601
+ body: MapSchema<SV, ReqBody>;
602
+ }) & (QueryObject<SV> extends ReqQuery ? unknown : {
603
+ query: MapSchema<SV, ReqQuery>;
604
+ }) & (HeadersObject<SV> extends ReqHeaders ? true extends AuthCollapse<Auth> ? unknown : {
605
+ headers: AuthHeaders<Auth>;
606
+ } : true extends AuthCollapse<Auth> ? {
607
+ headers: MapSchema<SV, ReqHeaders>;
608
+ } : {
609
+ headers: MapSchema<SV, ReqHeaders> & AuthHeaders<Auth>;
610
+ }) & (ParamsObject<SV> extends P ? unknown : {
611
+ params: MapSchema<SV, P>;
612
+ })>;
468
613
  /**
469
- * Options for global authentication in Express-like applications.
614
+ * Represents a live type function for the SDK.
470
615
  *
471
- * @template SV - The schema validator type.
472
- * @template SessionSchema - The session schema type.
473
- * @template SubscriptionData - The subscription data type (defaults to DefaultSubscriptionData, must extend Record<string, unknown> | null).
616
+ * @template SV - A type that extends AnySchemaValidator.
617
+ * @template Path - A type for the route path.
618
+ * @template P - A type for request parameters.
619
+ * @template ResBodyMap - A type for response schemas.
620
+ * @template ReqBody - A type for the request body.
621
+ * @template ReqQuery - A type for the request query.
622
+ * @template ReqHeaders - A type for the request headers.
623
+ * @template ResHeaders - A type for the response headers.
474
624
  *
475
- * Can be `false` to disable authentication, or an object specifying session schema and
476
- * functions to surface scopes, permissions, roles, subscription, and features from the JWT/session.
477
625
  */
478
- type ExpressLikeGlobalAuthOptions<SV extends AnySchemaValidator, SessionSchema extends Record<string, unknown>, SubscriptionData extends Record<string, unknown> | null = DefaultSubscriptionData> = false | {
479
- /**
480
- * Optional session schema for the authentication context.
481
- */
482
- sessionSchema?: SessionSchema;
483
- /**
484
- * Optional array describing the scope hierarchy for authorization.
485
- */
486
- scopeHeirarchy?: string[];
487
- /**
488
- * Function to extract a set of scopes from the JWT payload and request.
489
- */
490
- surfaceScopes?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
491
- /**
492
- * Function to extract a set of permissions from the JWT payload and request.
493
- */
494
- surfacePermissions?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
495
- /**
496
- * Function to extract a set of roles from the JWT payload and request.
497
- */
498
- surfaceRoles?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
499
- /**
500
- * Function to extract subscription data from the JWT payload and request.
501
- * Returns subscription information (status, plan, etc.) or null if no subscription.
502
- */
503
- surfaceSubscription?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => SubscriptionData | Promise<SubscriptionData>;
504
- /**
505
- * Function to extract a set of feature flags from the JWT payload and request.
506
- * Returns features available to the organization based on their billing plan.
507
- */
508
- surfaceFeatures?: (payload: JWTPayload & SessionSchema, req?: ForklaunchRequest<SV, Record<string, string>, Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, string, SessionSchema>) => Set<string> | Promise<Set<string>>;
626
+ type LiveTypeFunction<SV extends AnySchemaValidator, Route extends string, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, ContractMethod extends Method, VersionedApi extends VersionSchema<SV, ContractMethod>, Auth extends AuthMethodsBase> = string extends keyof VersionedApi ? (route: SanitizePathSlashes<Route>, ...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & {
627
+ method: Uppercase<ContractMethod>;
628
+ } & LiveTypeFunctionRequestInit<SV, P, ReqBody, ReqQuery, ReqHeaders, Auth>> extends infer ReqInit ? ReqInit extends {
629
+ body: unknown;
630
+ } | {
631
+ params: unknown;
632
+ } | {
633
+ query: unknown;
634
+ } | {
635
+ headers: unknown;
636
+ } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends ResBodyMap ? Record<number, unknown> : ResBodyMap, ForklaunchResHeaders extends ResHeaders ? unknown : MapSchema<SV, ResHeaders>>>> : {
637
+ [K in keyof VersionedApi]: (...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & LiveTypeFunctionRequestInit<SV, P, VersionedApi[K]['body'] extends Body<SV> ? VersionedApi[K]['body'] : Body<SV>, VersionedApi[K]['query'] extends QueryObject<SV> ? VersionedApi[K]['query'] : QueryObject<SV>, VersionedApi[K]['requestHeaders'] extends HeadersObject<SV> ? VersionedApi[K]['requestHeaders'] : HeadersObject<SV>, Auth>> & {
638
+ version: K;
639
+ } extends infer ReqInit ? ReqInit extends {
640
+ body: unknown;
641
+ } | {
642
+ params: unknown;
643
+ } | {
644
+ query: unknown;
645
+ } | {
646
+ headers: unknown;
647
+ } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends VersionedApi[K]['responses'] ? Record<number, unknown> : VersionedApi[K]['responses'], ForklaunchResHeaders extends VersionedApi[K]['responseHeaders'] ? unknown : MapSchema<SV, VersionedApi[K]['responseHeaders']>>>>;
509
648
  };
510
649
  /**
511
- * Schema-aware version of ExpressLikeGlobalAuthOptions.
650
+ * Represents a live type function for the SDK.
512
651
  *
513
- * @template SV - The schema validator type.
514
- * @template SessionSchema - The session object type.
515
- * @template SubscriptionData - The subscription data type.
516
- */
517
- type ExpressLikeSchemaGlobalAuthOptions<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>, SubscriptionData extends Record<string, unknown> | null = DefaultSubscriptionData> = ExpressLikeGlobalAuthOptions<SV, MapSessionSchema<SV, SessionSchema>, SubscriptionData>;
518
- /**
519
- * Options for configuring an Express-like router.
652
+ * @template SV - A type that extends AnySchemaValidator.
653
+ * @template P - A type for request parameters.
654
+ * @template ResBodyMap - A type for response schemas.
655
+ * @template ReqBody - A type for the request body.
656
+ * @template ReqQuery - A type for the request query.
657
+ * @template ReqHeaders - A type for the request headers.
658
+ * @template ResHeaders - A type for the response headers.
520
659
  *
521
- * @template SV - The schema validator type.
522
- * @template SessionSchema - The session object type.
523
- * @template SubscriptionData - The subscription data type.
524
660
  */
525
- type ExpressLikeRouterOptions<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>, SubscriptionData extends Record<string, unknown> | null = DefaultSubscriptionData> = {
526
- /**
527
- * Authentication options for the router.
528
- */
529
- auth?: ExpressLikeSchemaGlobalAuthOptions<SV, SessionSchema, SubscriptionData>;
530
- /**
531
- * Validation options for request and response.
532
- * Can be `false` to disable validation, or an object to configure request/response validation levels.
533
- */
534
- validation?: false | {
535
- /**
536
- * Request validation mode: 'none', 'warning', or 'error'.
537
- */
538
- request?: 'none' | 'warning' | 'error';
539
- /**
540
- * Response validation mode: 'none', 'warning', or 'error'.
541
- */
542
- response?: 'none' | 'warning' | 'error';
543
- };
544
- /**
545
- * OpenAPI documentation options.
546
- */
547
- openapi?: boolean;
548
- /**
549
- * MCP options.
550
- */
551
- mcp?: boolean;
661
+ type LiveSdkFunction<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method>, Auth extends AuthMethodsBase> = string extends keyof VersionedApi ? (...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & LiveTypeFunctionRequestInit<SV, P, ReqBody, ReqQuery, ReqHeaders, Auth>> extends infer ReqInit ? ReqInit extends {
662
+ body: unknown;
663
+ } | {
664
+ params: unknown;
665
+ } | {
666
+ query: unknown;
667
+ } | {
668
+ headers: unknown;
669
+ } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends ResBodyMap ? Record<number, unknown> : ResBodyMap, ForklaunchResHeaders extends ResHeaders ? unknown : MapSchema<SV, ResHeaders>>>> : {
670
+ [K in keyof VersionedApi]: (...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & LiveTypeFunctionRequestInit<SV, P, VersionedApi[K]['body'] extends Body<SV> ? VersionedApi[K]['body'] : Body<SV>, VersionedApi[K]['query'] extends QueryObject<SV> ? VersionedApi[K]['query'] : QueryObject<SV>, VersionedApi[K]['requestHeaders'] extends HeadersObject<SV> ? VersionedApi[K]['requestHeaders'] : HeadersObject<SV>, Auth>> extends infer ReqInit ? ReqInit extends {
671
+ body: unknown;
672
+ } | {
673
+ params: unknown;
674
+ } | {
675
+ query: unknown;
676
+ } | {
677
+ headers: unknown;
678
+ } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends VersionedApi[K]['responses'] ? Record<number, unknown> : VersionedApi[K]['responses'], ForklaunchResHeaders extends VersionedApi[K]['responseHeaders'] ? unknown : MapSchema<SV, VersionedApi[K]['responseHeaders']>>>>;
552
679
  };
553
680
  /**
554
- * Options for configuring an Express-like application.
681
+ * Represents a basic SDK Response object.
555
682
  *
556
- * @template SV - The schema validator type.
557
- * @template SessionSchema - The session object type.
558
- * @template SubscriptionData - The subscription data type.
683
+ * @template ResBodyMap - A type for the response body.
684
+ * @template ResHeaders - A type for the response headers.
559
685
  */
560
- type ExpressLikeApplicationOptions<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>, SubscriptionData extends Record<string, unknown> | null = DefaultSubscriptionData> = Omit<ExpressLikeRouterOptions<SV, SessionSchema, SubscriptionData>, 'openapi' | 'mcp'> & {
561
- /**
562
- * Documentation configuration.
563
- */
564
- docs?: DocsConfiguration;
565
- /**
566
- * Hosting/server options.
567
- */
568
- hosting?: {
569
- /**
570
- * SSL configuration or boolean to enable/disable SSL.
571
- */
572
- ssl?: {
573
- /**
574
- * SSL certificate as a string.
575
- */
576
- certFile: string;
577
- /**
578
- * SSL key as a string.
579
- */
580
- keyFile: string;
581
- /**
582
- * SSL CA as a string.
583
- */
584
- caFile: string;
585
- };
586
- /**
587
- * Number of worker processes to spawn.
588
- */
589
- workerCount?: number;
590
- /**
591
- * Routing strategy to use.
592
- */
593
- routingStrategy?: 'round-robin' | 'sticky' | 'random';
594
- };
595
- /**
596
- * FastMCP (management/control plane) options.
597
- * Can be `false` to disable, or an object to configure.
598
- */
599
- mcp?: false | {
600
- /**
601
- * Port for the MCP server.
602
- */
603
- port?: number;
604
- /**
605
- * Endpoint for the MCP server.
606
- */
607
- path?: `/${string}`;
608
- /**
609
- * Additional options for FastMCP.
610
- */
611
- options?: ConstructorParameters<typeof FastMCP>[0];
612
- /**
613
- * Optional authentication callback for validating MCP requests.
614
- * Called by FastMCP for each request to verify the session token.
615
- * Return user info object if authenticated, undefined otherwise.
616
- * Example: { email: 'user@example.com', name: 'User' }
617
- */
618
- authenticate?: (request: http.IncomingMessage) => Promise<Record<string, unknown> | undefined>;
619
- /**
620
- * Additional tools to register with the MCP server.
621
- */
622
- additionalTools?: (mcpServer: FastMCP) => void;
623
- /**
624
- * Content type mapping for the MCP server.
625
- */
626
- contentTypeMapping?: Record<string, string>;
627
- /**
628
- * Version of the MCP server.
629
- */
630
- version?: `${number}.${number}.${number}`;
631
- };
632
- /**
633
- * OpenAPI documentation options.
634
- * Can be `false` to disable, or an object to configure.
635
- */
636
- openapi?: false | {
637
- /**
638
- * Path to serve the OpenAPI docs (e.g., '/openapi').
639
- */
640
- path?: `/${string}`;
641
- /**
642
- * Title for the OpenAPI documentation.
643
- */
644
- title?: string;
645
- /**
646
- * Description for the OpenAPI documentation.
647
- */
648
- description?: string;
649
- /**
650
- * Contact information for the API.
651
- */
652
- contact?: {
653
- /**
654
- * Contact name.
655
- */
656
- name?: string;
657
- /**
658
- * Contact email.
659
- */
660
- email?: string;
661
- };
662
- /**
663
- * Whether to enable discrete versioning for OpenAPI docs.
664
- */
665
- discreteVersions?: boolean;
666
- };
667
- /**
668
- * CORS configuration options.
669
- */
670
- cors?: CorsOptions;
686
+ type SdkResponse<SV extends AnySchemaValidator, ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, unknown> | unknown> = ({
687
+ [K in keyof Omit<ForklaunchResErrors, keyof ResBodyMap>]: {
688
+ code: K;
689
+ contentType: 'text/plain';
690
+ response: ForklaunchResErrors[K];
691
+ };
692
+ } & {
693
+ [K in keyof ResBodyMap]: {
694
+ code: K;
695
+ contentType: ExtractContentType<SV, ResBodyMap[K]>;
696
+ response: ExtractResponseBody<SV, ResBodyMap[K]>;
697
+ } & (unknown extends ResHeaders ? unknown : {
698
+ headers: ResHeaders;
699
+ });
700
+ })[keyof (Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)];
701
+ /**
702
+ * Represents the default error types for responses.
703
+ */
704
+ type ForklaunchResErrors<BadRequest = string, Unauthorized = string, NotFound = string, Forbidden = string, InternalServerErrorType = string> = {
705
+ 400: BadRequest;
706
+ 401: Unauthorized;
707
+ 404: NotFound;
708
+ 403: Forbidden;
709
+ 500: InternalServerErrorType;
710
+ };
711
+ /**
712
+ * Represents the default header types for responses.
713
+ */
714
+ type ForklaunchResHeaders = {
715
+ 'x-correlation-id': string;
716
+ };
717
+ /**
718
+ * Represents the default error types for responses.
719
+ */
720
+ type ErrorContainer<Code extends number> = {
721
+ /** The error code */
722
+ code: Code;
723
+ /** The error message */
724
+ error: string;
725
+ };
726
+ /**
727
+ * Represents a parsed response shape.
728
+ */
729
+ type ResponseShape<Params, Headers, Query, Body> = {
730
+ params: Params;
731
+ headers: Headers;
732
+ query: Query;
733
+ body: Body;
671
734
  };
735
+ /**
736
+ * Represents a path match.
737
+ */
738
+ type PathMatch<SuppliedPath extends `/${string}`, ActualPath extends `/${string}`> = ActualPath extends SuppliedPath ? SuppliedPath extends ActualPath ? SuppliedPath : never : never;
672
739
 
673
740
  /**
674
- * Interface representing the context of a request.
741
+ * Dictionary type for URL parameters.
675
742
  */
676
- interface RequestContext {
677
- /** Correlation ID for tracking requests */
678
- correlationId: string;
679
- /** Optional idempotency key for ensuring idempotent requests */
680
- idempotencyKey?: string;
681
- /** Active OpenTelemetry Span */
682
- span?: Span;
683
- }
684
- interface ForklaunchBaseRequest<P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>> {
685
- /** Request parameters */
686
- params: P;
687
- /** Request headers */
688
- headers: ReqHeaders;
689
- /** Request body */
690
- body: ReqBody;
691
- /** Request query */
692
- query: ReqQuery;
693
- /** Method */
694
- method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE';
695
- /** Request path */
696
- path: string;
697
- /** Original path */
698
- originalPath: string;
699
- /** OpenTelemetry Collector */
700
- openTelemetryCollector?: OpenTelemetryCollector<MetricsDefinition>;
701
- }
743
+ type ParamsDictionary = {
744
+ [key: string]: string;
745
+ };
702
746
  /**
703
- * Interface representing a Forklaunch request.
747
+ * Type representing an object with only string keys.
704
748
  *
705
749
  * @template SV - A type that extends AnySchemaValidator.
706
- * @template P - A type for request parameters, defaulting to ParamsDictionary.
707
- * @template ReqBody - A type for the request body, defaulting to unknown.
708
- * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
709
- * @template Headers - A type for the request headers, defaulting to IncomingHttpHeaders.
710
- */
711
- interface ForklaunchRequest<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, unknown>, Version extends string, SessionSchema extends Record<string, unknown>> {
712
- /** Context of the request */
713
- context: Prettify<RequestContext>;
714
- /** API Version of the request */
715
- version: Version;
716
- /** Request parameters */
717
- params: P;
718
- /** Request headers */
719
- headers: ReqHeaders;
720
- /** Request body */
721
- body: ReqBody;
722
- /** Request query */
723
- query: ReqQuery;
724
- /** Contract details for the request */
725
- contractDetails: PathParamHttpContractDetails<SV> | HttpContractDetails<SV>;
726
- /** Schema validator */
727
- schemaValidator: SV;
728
- /** Method */
729
- method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'CONNECT' | 'TRACE';
730
- /** Request path */
731
- path: string;
732
- /** Request schema, compiled */
733
- requestSchema: unknown | Record<string, unknown>;
734
- /** Original path */
735
- originalPath: string;
736
- /** OpenTelemetry Collector */
737
- openTelemetryCollector?: OpenTelemetryCollector<MetricsDefinition>;
738
- /** Session */
739
- session: JWTPayload & SessionSchema;
740
- /** Parsed versions */
741
- _parsedVersions: string[] | number;
742
- /** Raw body before schema validation (for HMAC verification) */
743
- _rawBody?: unknown;
744
- /** Global options */
745
- _globalOptions: () => ExpressLikeRouterOptions<SV, SessionSchema> | undefined;
746
- }
747
- /**
748
- * Represents the types of data that can be sent in a response.
749
750
  */
750
- type ForklaunchSendableData = Record<string, unknown> | string | Buffer | ArrayBuffer | NodeJS.ReadableStream | null | undefined;
751
+ type StringOnlyObject<SV extends AnySchemaValidator> = Omit<UnboxedObjectSchema<SV>, number | symbol>;
751
752
  /**
752
- * Interface representing a Forklaunch response status.
753
- * @template ResBody - A type for the response body.
753
+ * Type representing an object with only number keys.
754
+ *
755
+ * @template SV - A type that extends AnySchemaValidator.
754
756
  */
755
- interface ForklaunchStatusResponse<ResBody> {
756
- /**
757
- * Sends the response.
758
- * @param {ResBodyMap} [body] - The response body.
759
- * @param {boolean} [close_connection] - Whether to close the connection.
760
- * @returns {T} - The sent response.
761
- */
762
- send: {
763
- (body?: ResBody extends AsyncGenerator<unknown> ? never : ResBody extends Blob ? Blob | File | Buffer | ArrayBuffer | NodeJS.ReadableStream : ResBody | null, close_connection?: boolean): boolean;
764
- <U>(body?: ResBody extends AsyncGenerator<unknown> ? never : ResBody extends Blob ? Blob | File | Buffer | ArrayBuffer | NodeJS.ReadableStream : ResBody | null, close_connection?: boolean): U;
765
- };
766
- /**
767
- * Sends a JSON response.
768
- * @param {ResBodyMap} [body] - The response body.
769
- * @returns {boolean|T} - The JSON response.
770
- */
771
- json: {
772
- (body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): boolean;
773
- <U>(body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): U;
774
- };
775
- /**
776
- * Sends a JSONP response.
777
- * @param {ResBodyMap} [body] - The response body.
778
- * @returns {boolean|T} - The JSONP response.
779
- */
780
- jsonp: {
781
- (body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): boolean;
782
- <U>(body: ResBody extends string | AsyncGenerator<unknown> ? never : ResBody | null): U;
783
- };
784
- /**
785
- * Sends a Server-Sent Event (SSE) response.
786
- * @param {ResBodyMap} [body] - The response body.
787
- * @param {number} interval - The interval between events.
788
- */
789
- sseEmitter: (generator: () => AsyncGenerator<ResBody extends AsyncGenerator<infer T> ? T : never, void, unknown>) => void;
790
- }
791
- type ToNumber<T extends string | number | symbol> = T extends number ? T : T extends `${infer N extends number}` ? N : never;
757
+ type NumberOnlyObject<SV extends AnySchemaValidator> = Omit<UnboxedObjectSchema<SV>, string | symbol>;
792
758
  /**
793
- * Interface representing a Forklaunch response.
759
+ * Type representing the body object in a request.
794
760
  *
795
- * @template ResBodyMap - A type for the response body, defaulting to common status code responses.
796
- * @template StatusCode - A type for the status code, defaulting to number.
761
+ * @template SV - A type that extends AnySchemaValidator.
797
762
  */
798
- interface ForklaunchResponse<BaseResponse, ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, unknown>, LocalsObj extends Record<string, unknown>, Version extends string> {
799
- /** Data of the response body */
800
- bodyData: unknown;
801
- /** Status code of the response */
802
- statusCode: number;
803
- /** Whether the response is finished */
804
- headersSent: boolean;
805
- /**
806
- * Gets the headers of the response.
807
- * @returns {Omit<ResHeaders, keyof ForklaunchResHeaders> & ForklaunchResHeaders} - The headers of the response.
808
- */
809
- getHeaders: () => Omit<ResHeaders, keyof ForklaunchResHeaders> & ForklaunchResHeaders;
810
- /**
811
- * Gets a header for the response.
812
- * @param {string} key - The header key.
813
- * @returns {string | string[] | undefined} The header value.
814
- */
815
- getHeader: (key: string) => string | string[] | undefined;
816
- /**
817
- * Sets a header for the response.
818
- * @param {string} key - The header key.
819
- * @param {string} value - The header value.
820
- */
821
- setHeader: {
822
- <K extends keyof (ResHeaders & ForklaunchResHeaders)>(key: K, value: K extends keyof ForklaunchResHeaders ? ForklaunchResHeaders[K] : ResHeaders[K]): void;
823
- <K extends keyof (ResHeaders & ForklaunchResHeaders)>(key: K, value: K extends keyof ForklaunchResHeaders ? ForklaunchResHeaders[K] : ResHeaders[K]): BaseResponse;
824
- };
825
- /**
826
- * Adds an event listener to the response.
827
- * @param {string} event - The event to listen for.
828
- * @param {Function} listener - The listener function.
829
- */
830
- on(event: 'close', listener: () => void): BaseResponse & this;
831
- on(event: 'drain', listener: () => void): BaseResponse & this;
832
- on(event: 'error', listener: (err: Error) => void): BaseResponse & this;
833
- on(event: 'finish', listener: () => void): BaseResponse & this;
834
- on(event: 'pipe', listener: (src: Readable) => void): BaseResponse & this;
835
- on(event: 'unpipe', listener: (src: Readable) => void): BaseResponse & this;
836
- on(event: string | symbol, listener: (...args: unknown[]) => void): BaseResponse & this;
837
- /**
838
- * Sets the status of the response.
839
- * @param {U} code - The status code.
840
- * @param {string} [message] - Optional message.
841
- * @returns {ForklaunchResponse<(ResBodyMap)[U], ResHeaders, U, LocalsObj>} - The response with the given status.
842
- */
843
- status: {
844
- <U extends ToNumber<keyof (ResBodyMap & ForklaunchResErrors)>>(code: U): Omit<BaseResponse, keyof ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>> & ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>;
845
- <U extends ToNumber<keyof (ResBodyMap & ForklaunchResErrors)>>(code: U, message?: string): Omit<BaseResponse, keyof ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>> & ForklaunchStatusResponse<(Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)[U]>;
846
- };
847
- /**
848
- * Ends the response.
849
- * @param {string} [data] - Optional data to send.
850
- */
851
- end: {
852
- (data?: string): void;
853
- (cb?: (() => void) | undefined): BaseResponse;
854
- };
855
- /**
856
- * Sets the content type of the response.
857
- * @param {string} type - The content type.
858
- */
859
- type: {
860
- (type: string): void;
861
- (type: string): BaseResponse;
862
- };
863
- /** Local variables */
864
- locals: LocalsObj;
865
- /** Cors */
866
- cors: boolean;
867
- /** Response schema, compiled */
868
- responseSchemas: ResponseCompiledSchema | Record<string, ResponseCompiledSchema>;
869
- /** Whether the metric has been recorded */
870
- metricRecorded: boolean;
871
- /** Whether the response has been sent */
872
- sent: boolean;
873
- /** Versioned responses */
874
- version: Version;
875
- }
763
+ type BodyObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
764
+ /**
765
+ * Type representing the parameters object in a request.
766
+ *
767
+ * @template SV - A type that extends AnySchemaValidator.
768
+ */
769
+ type ParamsObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
876
770
  /**
877
- * Type representing the next function in a middleware.
878
- * @param {unknown} [err] - Optional error parameter.
771
+ * Type representing the query object in a request.
772
+ *
773
+ * @template SV - A type that extends AnySchemaValidator.
879
774
  */
880
- type ForklaunchNextFunction = (err?: unknown) => void;
881
- type VersionedRequests = Record<string, {
882
- requestHeaders?: Record<string, unknown>;
883
- body?: Record<string, unknown>;
884
- query?: Record<string, unknown>;
885
- }>;
886
- type ResolvedForklaunchRequestBase<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, unknown>, Version extends string, SessionSchema extends Record<string, unknown>, BaseRequest> = unknown extends BaseRequest ? ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Version, SessionSchema> : Omit<BaseRequest, keyof ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Version, SessionSchema>> & ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Version, SessionSchema>;
775
+ type QueryObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
887
776
  /**
888
- * Type representing the resolved forklaunch request from a base request type.
777
+ * Type representing the headers object in a request.
778
+ *
889
779
  * @template SV - A type that extends AnySchemaValidator.
890
- * @template P - A type for request parameters, defaulting to ParamsDictionary.
891
- * @template ReqBody - A type for the request body, defaulting to Record<string, unknown>.
892
- * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
893
- * @template ReqHeaders - A type for the request headers, defaulting to Record<string, unknown>.
894
- * @template BaseRequest - A type for the base request.
895
780
  */
896
- type ResolvedForklaunchRequest<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, SessionSchema extends Record<string, unknown>, BaseRequest> = VersionedRequests extends VersionedReqs ? ResolvedForklaunchRequestBase<SV, P, ReqBody, ReqQuery, ReqHeaders, never, SessionSchema, BaseRequest> : {
897
- [K in keyof VersionedReqs]: ResolvedForklaunchRequestBase<SV, P, VersionedReqs[K]['body'] extends Record<string, unknown> ? VersionedReqs[K]['body'] : Record<string, unknown>, VersionedReqs[K]['query'] extends Record<string, unknown> ? VersionedReqs[K]['query'] : ParsedQs, VersionedReqs[K]['requestHeaders'] extends Record<string, unknown> ? VersionedReqs[K]['requestHeaders'] : Record<string, string>, K extends string ? K : never, SessionSchema, BaseRequest>;
898
- }[keyof VersionedReqs];
899
- type ResolvedForklaunchAuthRequest<P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, BaseRequest> = unknown extends BaseRequest ? ForklaunchBaseRequest<P, ReqBody, ReqQuery, ReqHeaders> : {
900
- [key in keyof BaseRequest]: key extends keyof ForklaunchBaseRequest<P, ReqBody, ReqQuery, ReqHeaders> ? ForklaunchBaseRequest<P, ReqBody, ReqQuery, ReqHeaders>[key] : key extends keyof BaseRequest ? BaseRequest[key] : never;
781
+ type HeadersObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
782
+ type RawTypedResponseBody<SV extends AnySchemaValidator> = TextBody<SV> | JsonBody<SV> | FileBody<SV> | ServerSentEventBody<SV> | UnknownResponseBody<SV>;
783
+ type ExclusiveResponseBodyBase<SV extends AnySchemaValidator> = {
784
+ [K in keyof UnionToIntersection<RawTypedResponseBody<SV>>]?: undefined;
901
785
  };
902
- type VersionedResponses = Record<string, {
903
- responseHeaders?: Record<string, unknown>;
904
- responses: Record<number, unknown>;
905
- }>;
906
- type ResolvedForklaunchResponseBase<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, unknown>, LocalsObj extends Record<string, unknown>, Version extends string, BaseResponse> = unknown extends BaseResponse ? ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version> : (string extends Version ? unknown : {
907
- version?: Version;
908
- }) & {
909
- [K in keyof BaseResponse | keyof ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version>]: K extends keyof ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version> ? ForklaunchResponse<BaseResponse, ResBodyMap, ResHeaders, LocalsObj, Version>[K] : K extends keyof BaseResponse ? BaseResponse[K] : never;
786
+ type ExclusiveSchemaCatchall<SV extends AnySchemaValidator> = {
787
+ [K in keyof SV['_SchemaCatchall'] as string extends K ? never : number extends K ? never : symbol extends K ? never : K]?: undefined;
910
788
  };
911
- type ResolvedForklaunchResponse<ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>, VersionedResps extends VersionedResponses, BaseResponse> = VersionedResponses extends VersionedResps ? ResolvedForklaunchResponseBase<ResBodyMap, ResHeaders, LocalsObj, never, BaseResponse> : {
912
- [K in keyof VersionedResps]: ResolvedForklaunchResponseBase<VersionedResps[K]['responses'], VersionedResps[K]['responseHeaders'] extends Record<string, unknown> ? VersionedResps[K]['responseHeaders'] : Record<string, string>, LocalsObj, K extends string ? K : never, BaseResponse>;
913
- }[keyof VersionedResps];
789
+ type TypedResponseBody<SV extends AnySchemaValidator> = {
790
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof TextBody<SV> ? TextBody<SV>[K] : undefined;
791
+ } | {
792
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof JsonBody<SV> ? JsonBody<SV>[K] : undefined;
793
+ } | {
794
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof FileBody<SV> ? FileBody<SV>[K] : undefined;
795
+ } | {
796
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof ServerSentEventBody<SV> ? ServerSentEventBody<SV>[K] : undefined;
797
+ } | {
798
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveResponseBodyBase<SV>)]?: K extends keyof UnknownResponseBody<SV> ? UnknownResponseBody<SV>[K] : undefined;
799
+ };
800
+ type ResponseBody<SV extends AnySchemaValidator> = TypedResponseBody<SV> | (ExclusiveResponseBodyBase<SV> & SV['_ValidSchemaObject']) | (ExclusiveResponseBodyBase<SV> & UnboxedObjectSchema<SV>) | (ExclusiveResponseBodyBase<SV> & SV['string']) | (ExclusiveResponseBodyBase<SV> & SV['number']) | (ExclusiveResponseBodyBase<SV> & SV['boolean']) | (ExclusiveResponseBodyBase<SV> & SV['date']) | (ExclusiveResponseBodyBase<SV> & SV['array']) | (ExclusiveResponseBodyBase<SV> & SV['file']);
914
801
  /**
915
- * Represents a middleware handler with schema validation.
802
+ * Type representing the responses object in a request.
916
803
  *
917
804
  * @template SV - A type that extends AnySchemaValidator.
918
- * @template P - A type for request parameters, defaulting to ParamsDictionary.
919
- * @template ResBodyMap - A type for the response body, defaulting to unknown.
920
- * @template ReqBody - A type for the request body, defaulting to unknown.
921
- * @template ReqQuery - A type for the request query, defaulting to ParsedQs.
922
- * @template LocalsObj - A type for local variables, defaulting to an empty object.
923
- * @template StatusCode - A type for the status code, defaulting to number.
924
805
  */
925
- interface ExpressLikeHandler<SV extends AnySchemaValidator, P extends ParamsDictionary, ResBodyMap extends Record<number, unknown>, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>, VersionedReqs extends VersionedRequests, VersionedResps extends VersionedResponses, SessionSchema extends Record<string, unknown>, BaseRequest, BaseResponse, NextFunction> {
926
- (req: ResolvedForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionSchema, BaseRequest>, res: ResolvedForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj, VersionedResps, BaseResponse>, next: NextFunction): unknown;
927
- }
928
- type MapParamsSchema<SV extends AnySchemaValidator, P extends ParamsObject<SV>> = MapSchema<SV, P> extends infer Params ? unknown extends Params ? ParamsDictionary : Params : ParamsDictionary;
929
- type ExtractContentType<SV extends AnySchemaValidator, T extends ResponseBody<SV> | unknown> = T extends {
930
- contentType: string;
931
- } ? T['contentType'] : T extends JsonBody<SV> ? 'application/json' : T extends TextBody<SV> ? 'text/plain' : T extends FileBody<SV> ? 'application/octet-stream' : T extends ServerSentEventBody<SV> ? 'text/event-stream' : T extends UnknownResponseBody<SV> ? 'application/json' : T extends SV['file'] ? 'application/octet-stream' : 'text/plain';
932
- type ExtractResponseBody<SV extends AnySchemaValidator, T extends ResponseBody<SV> | unknown> = T extends JsonBody<SV> ? MapSchema<SV, T['json']> : T extends TextBody<SV> ? MapSchema<SV, T['text']> : T extends FileBody<SV> ? File | Blob : T extends ServerSentEventBody<SV> ? AsyncGenerator<MapSchema<SV, T['event']>> : T extends UnknownResponseBody<SV> ? MapSchema<SV, T['schema']> : MapSchema<SV, T>;
933
- type MapResBodyMapSchema<SV extends AnySchemaValidator, ResBodyMap extends ResponsesObject<SV>> = unknown extends ResBodyMap ? ForklaunchResErrors : {
934
- [K in keyof ResBodyMap]: ExtractResponseBody<SV, ResBodyMap[K]>;
806
+ type ResponsesObject<SV extends AnySchemaValidator> = {
807
+ [K: number]: ResponseBody<SV>;
808
+ };
809
+ type JsonBody<SV extends AnySchemaValidator> = {
810
+ contentType?: 'application/json' | string;
811
+ json: BodyObject<SV> | SV['_ValidSchemaObject'] | SV['_SchemaCatchall'];
935
812
  };
936
- type ExtractBody<SV extends AnySchemaValidator, T extends Body<SV>> = T extends JsonBody<SV> ? T['json'] : T extends TextBody<SV> ? T['text'] : T extends FileBody<SV> ? T['file'] : T extends MultipartForm<SV> ? T['multipartForm'] : T extends UrlEncodedForm<SV> ? T['urlEncodedForm'] : T extends UnknownBody<SV> ? T['schema'] : T;
937
- type MapReqBodySchema<SV extends AnySchemaValidator, ReqBody extends Body<SV>> = MapSchema<SV, ExtractBody<SV, ReqBody>> extends infer Body ? unknown extends Body ? Record<string, unknown> : Body : Record<string, unknown>;
938
- type MapReqQuerySchema<SV extends AnySchemaValidator, ReqQuery extends QueryObject<SV>> = MapSchema<SV, ReqQuery> extends infer Query ? unknown extends Query ? ParsedQs : Query : ParsedQs;
939
- type MapReqHeadersSchema<SV extends AnySchemaValidator, ReqHeaders extends HeadersObject<SV>> = MapSchema<SV, ReqHeaders> extends infer RequestHeaders ? unknown extends RequestHeaders ? Record<string, string> : RequestHeaders : Record<string, string>;
940
- type MapResHeadersSchema<SV extends AnySchemaValidator, ResHeaders extends HeadersObject<SV>> = MapSchema<SV, ResHeaders> extends infer ResponseHeaders ? unknown extends ResponseHeaders ? ForklaunchResHeaders : ResponseHeaders : ForklaunchResHeaders;
941
- type MapVersionedReqsSchema<SV extends AnySchemaValidator, VersionedReqs extends VersionSchema<SV, Method>> = {
942
- [K in keyof VersionedReqs]: (VersionedReqs[K]['requestHeaders'] extends HeadersObject<SV> ? {
943
- requestHeaders: MapReqHeadersSchema<SV, VersionedReqs[K]['requestHeaders']>;
944
- } : unknown) & (VersionedReqs[K]['body'] extends Body<SV> ? {
945
- body: MapReqBodySchema<SV, VersionedReqs[K]['body']>;
946
- } : unknown) & (VersionedReqs[K]['query'] extends QueryObject<SV> ? {
947
- query: MapReqQuerySchema<SV, VersionedReqs[K]['query']>;
948
- } : unknown);
949
- } extends infer MappedVersionedReqs ? MappedVersionedReqs extends VersionedRequests ? MappedVersionedReqs : VersionedRequests : VersionedRequests;
950
- type MapVersionedRespsSchema<SV extends AnySchemaValidator, VersionedResps extends VersionSchema<SV, Method>> = {
951
- [K in keyof VersionedResps]: (VersionedResps[K]['responseHeaders'] extends HeadersObject<SV> ? {
952
- responseHeaders: MapResHeadersSchema<SV, VersionedResps[K]['responseHeaders']>;
953
- } : unknown) & (VersionedResps[K]['responses'] extends ResponsesObject<SV> ? {
954
- responses: MapResBodyMapSchema<SV, VersionedResps[K]['responses']>;
955
- } : unknown);
956
- } extends infer MappedVersionedResps ? MappedVersionedResps extends VersionedResponses ? MappedVersionedResps : VersionedResponses : VersionedResponses;
957
- type MapSessionSchema<SV extends AnySchemaValidator, SessionSchema extends SessionObject<SV>> = SessionSchema extends infer UnmappedSessionSchema ? UnmappedSessionSchema extends SessionObject<SV> ? MapSchema<SV, UnmappedSessionSchema> : never : never;
958
813
  /**
959
- * Represents a schema middleware handler with typed parameters, responses, body, and query.
814
+ * Type representing the body in a request.
960
815
  *
961
816
  * @template SV - A type that extends AnySchemaValidator.
962
- * @template P - A type for parameter schemas, defaulting to ParamsObject.
963
- * @template ResBodyMap - A type for response schemas, defaulting to ResponsesObject.
964
- * @template ReqBody - A type for the request body, defaulting to Body.
965
- * @template ReqQuery - A type for the request query, defaulting to QueryObject.
966
- * @template LocalsObj - A type for local variables, defaulting to an empty object.
967
817
  */
968
- type ExpressLikeSchemaHandler<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>, VersionedApi extends VersionSchema<SV, Method>, SessionSchema extends Record<string, unknown>, BaseRequest, BaseResponse, NextFunction> = ExpressLikeHandler<SV, MapParamsSchema<SV, P>, MapResBodyMapSchema<SV, ResBodyMap>, MapReqBodySchema<SV, ReqBody>, MapReqQuerySchema<SV, ReqQuery>, MapReqHeadersSchema<SV, ReqHeaders>, MapResHeadersSchema<SV, ResHeaders>, LocalsObj, MapVersionedReqsSchema<SV, VersionedApi>, MapVersionedRespsSchema<SV, VersionedApi>, MapSessionSchema<SV, SessionSchema>, BaseRequest, BaseResponse, NextFunction>;
818
+ type TextBody<SV extends AnySchemaValidator> = {
819
+ contentType?: 'application/xml' | 'text/plain' | 'text/html' | 'text/css' | 'text/javascript' | 'text/csv' | 'text/markdown' | 'text/xml' | 'text/rtf' | 'text/x-yaml' | 'text/yaml' | string;
820
+ text: SV['string'];
821
+ };
822
+ type FileBody<SV extends AnySchemaValidator> = {
823
+ contentType?: 'application/octet-stream' | 'application/pdf' | 'application/vnd.ms-excel' | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | 'application/msword' | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' | 'application/zip' | 'image/jpeg' | 'image/png' | 'image/gif' | 'audio/mpeg' | 'audio/wav' | 'video/mp4' | string;
824
+ file: SV['file'];
825
+ };
969
826
  /**
970
- * Represents a function that maps an authenticated request with schema validation
971
- * to a set of authorization strings, with request properties automatically inferred from the schema.
972
- *
973
- * @template SV - The type representing the schema validator.
974
- * @template P - The type representing request parameters inferred from the schema.
975
- * @template ReqBody - The type representing the request body inferred from the schema.
976
- * @template ReqQuery - The type representing the request query parameters inferred from the schema.
977
- * @template ReqHeaders - The type representing the request headers inferred from the schema.
827
+ * Type representing the body in a request.
978
828
  *
979
- * @param {ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>} req - The request object with schema validation.
980
- * @returns {Set<string> | Promise<Set<string>>} - A set of authorization strings or a promise that resolves to it.
829
+ * @template SV - A type that extends AnySchemaValidator.
981
830
  */
982
- type ExpressLikeSchemaAuthMapper<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, VersionedReqs extends VersionSchema<SV, Method>, SessionSchema extends SessionObject<SV>, BaseRequest> = ExpressLikeAuthMapper<SV, P extends infer UnmappedParams ? UnmappedParams extends ParamsObject<SV> ? MapParamsSchema<SV, UnmappedParams> : never : never, ReqBody extends infer UnmappedReqBody ? UnmappedReqBody extends Body<SV> ? MapReqBodySchema<SV, UnmappedReqBody> : never : never, ReqQuery extends infer UnmappedReqQuery ? UnmappedReqQuery extends QueryObject<SV> ? MapReqQuerySchema<SV, UnmappedReqQuery> : never : never, ReqHeaders extends infer UnmappedReqHeaders ? UnmappedReqHeaders extends HeadersObject<SV> ? MapReqHeadersSchema<SV, UnmappedReqHeaders> : never : never, VersionedReqs extends infer UnmappedVersionedReqs ? UnmappedVersionedReqs extends VersionSchema<SV, Method> ? MapVersionedReqsSchema<SV, UnmappedVersionedReqs> : never : never, SessionSchema extends infer UnmappedSessionSchema ? UnmappedSessionSchema extends Record<string, unknown> ? MapSessionSchema<SV, UnmappedSessionSchema> : never : never, BaseRequest>;
983
- type ExpressLikeAuthMapper<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, SessionSchema extends Record<string, unknown>, BaseRequest> = (payload: JWTPayload & SessionSchema, req?: ResolvedForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionSchema, BaseRequest>) => Set<string> | Promise<Set<string>>;
984
- type TokenPrefix<Auth extends AuthMethodsBase> = undefined extends Auth['tokenPrefix'] ? Auth extends BasicAuthMethods ? 'Basic ' : Auth extends HmacMethods ? 'HMAC ' : 'Bearer ' : `${Auth['tokenPrefix']} `;
985
- type AuthHeaders<Auth extends AuthMethodsBase> = undefined extends Auth['headerName'] ? {
986
- authorization: Auth extends HmacMethods ? `${TokenPrefix<Auth>}keyId=${string} ts=${string} nonce=${string} signature=${string}` : `${TokenPrefix<Auth>}${string}`;
987
- } : {
988
- [K in NonNullable<Auth['headerName']>]: `${TokenPrefix<Auth>}${string}`;
831
+ type MultipartForm<SV extends AnySchemaValidator> = {
832
+ contentType?: 'multipart/form-data' | 'multipart/mixed' | 'multipart/alternative' | 'multipart/related' | 'multipart/signed' | 'multipart/encrypted' | string;
833
+ multipartForm: BodyObject<SV>;
989
834
  };
990
- type AuthCollapse<Auth extends AuthMethodsBase> = undefined extends Auth['jwt'] ? undefined extends Auth['basic'] ? undefined extends Auth['hmac'] ? true : false : false : false;
991
- type LiveTypeFunctionRequestInit<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ReqBody extends Body<SV> | undefined, ReqQuery extends QueryObject<SV> | undefined, ReqHeaders extends HeadersObject<SV> | undefined, Auth extends AuthMethodsBase> = MakePropertyOptionalIfChildrenOptional<(Body<SV> extends ReqBody ? unknown : {
992
- body: MapSchema<SV, ReqBody>;
993
- }) & (QueryObject<SV> extends ReqQuery ? unknown : {
994
- query: MapSchema<SV, ReqQuery>;
995
- }) & (HeadersObject<SV> extends ReqHeaders ? true extends AuthCollapse<Auth> ? unknown : {
996
- headers: AuthHeaders<Auth>;
997
- } : true extends AuthCollapse<Auth> ? {
998
- headers: MapSchema<SV, ReqHeaders>;
999
- } : {
1000
- headers: MapSchema<SV, ReqHeaders> & AuthHeaders<Auth>;
1001
- }) & (ParamsObject<SV> extends P ? unknown : {
1002
- params: MapSchema<SV, P>;
1003
- })>;
1004
835
  /**
1005
- * Represents a live type function for the SDK.
836
+ * Type representing the body in a request.
1006
837
  *
1007
838
  * @template SV - A type that extends AnySchemaValidator.
1008
- * @template Path - A type for the route path.
1009
- * @template P - A type for request parameters.
1010
- * @template ResBodyMap - A type for response schemas.
1011
- * @template ReqBody - A type for the request body.
1012
- * @template ReqQuery - A type for the request query.
1013
- * @template ReqHeaders - A type for the request headers.
1014
- * @template ResHeaders - A type for the response headers.
1015
- *
1016
839
  */
1017
- type LiveTypeFunction<SV extends AnySchemaValidator, Route extends string, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, ContractMethod extends Method, VersionedApi extends VersionSchema<SV, ContractMethod>, Auth extends AuthMethodsBase> = string extends keyof VersionedApi ? (route: SanitizePathSlashes<Route>, ...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & {
1018
- method: Uppercase<ContractMethod>;
1019
- } & LiveTypeFunctionRequestInit<SV, P, ReqBody, ReqQuery, ReqHeaders, Auth>> extends infer ReqInit ? ReqInit extends {
1020
- body: unknown;
840
+ type UrlEncodedForm<SV extends AnySchemaValidator> = {
841
+ contentType?: 'application/x-www-form-urlencoded' | 'application/x-url-encoded' | 'application/x-www-url-encoded' | 'application/x-urlencode' | string;
842
+ urlEncodedForm: BodyObject<SV>;
843
+ };
844
+ type ServerSentEventBody<SV extends AnySchemaValidator> = {
845
+ contentType?: 'text/event-stream' | string;
846
+ event: {
847
+ id: SV['string'];
848
+ data: SV['string'] | BodyObject<SV>;
849
+ };
850
+ };
851
+ type UnknownBody<SV extends AnySchemaValidator> = {
852
+ contentType?: string;
853
+ schema: BodyObject<SV> | SV['_ValidSchemaObject'] | SV['_SchemaCatchall'];
854
+ };
855
+ type UnknownResponseBody<SV extends AnySchemaValidator> = {
856
+ contentType?: string;
857
+ schema: BodyObject<SV> | SV['_ValidSchemaObject'] | SV['_SchemaCatchall'];
858
+ };
859
+ type ExclusiveRequestBodyBase<SV extends AnySchemaValidator> = {
860
+ [K in keyof UnionToIntersection<TypedBody<SV>>]?: undefined;
861
+ };
862
+ type TypedRequestBody<SV extends AnySchemaValidator> = {
863
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof TextBody<SV> ? TextBody<SV>[K] : undefined;
1021
864
  } | {
1022
- params: unknown;
865
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof JsonBody<SV> ? JsonBody<SV>[K] : undefined;
1023
866
  } | {
1024
- query: unknown;
867
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof FileBody<SV> ? FileBody<SV>[K] : undefined;
1025
868
  } | {
1026
- headers: unknown;
1027
- } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends ResBodyMap ? Record<number, unknown> : ResBodyMap, ForklaunchResHeaders extends ResHeaders ? unknown : MapSchema<SV, ResHeaders>>>> : {
1028
- [K in keyof VersionedApi]: (...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & LiveTypeFunctionRequestInit<SV, P, VersionedApi[K]['body'] extends Body<SV> ? VersionedApi[K]['body'] : Body<SV>, VersionedApi[K]['query'] extends QueryObject<SV> ? VersionedApi[K]['query'] : QueryObject<SV>, VersionedApi[K]['requestHeaders'] extends HeadersObject<SV> ? VersionedApi[K]['requestHeaders'] : HeadersObject<SV>, Auth>> & {
1029
- version: K;
1030
- } extends infer ReqInit ? ReqInit extends {
1031
- body: unknown;
1032
- } | {
1033
- params: unknown;
869
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof MultipartForm<SV> ? MultipartForm<SV>[K] : undefined;
870
+ } | {
871
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof UrlEncodedForm<SV> ? UrlEncodedForm<SV>[K] : undefined;
872
+ } | {
873
+ [K in keyof (ExclusiveSchemaCatchall<SV> & ExclusiveRequestBodyBase<SV>)]?: K extends keyof UnknownBody<SV> ? UnknownBody<SV>[K] : undefined;
874
+ };
875
+ type TypedBody<SV extends AnySchemaValidator> = JsonBody<SV> | TextBody<SV> | FileBody<SV> | MultipartForm<SV> | UrlEncodedForm<SV> | UnknownBody<SV>;
876
+ type Body<SV extends AnySchemaValidator> = TypedRequestBody<SV> | (ExclusiveRequestBodyBase<SV> & SV['_ValidSchemaObject']) | (ExclusiveRequestBodyBase<SV> & UnboxedObjectSchema<SV>) | (ExclusiveRequestBodyBase<SV> & SV['string']) | (ExclusiveRequestBodyBase<SV> & SV['number']) | (ExclusiveRequestBodyBase<SV> & SV['boolean']) | (ExclusiveRequestBodyBase<SV> & SV['date']) | (ExclusiveRequestBodyBase<SV> & SV['array']) | (ExclusiveRequestBodyBase<SV> & SV['file']) | (ExclusiveRequestBodyBase<SV> & SV['any']) | (ExclusiveRequestBodyBase<SV> & SV['unknown']) | (ExclusiveRequestBodyBase<SV> & SV['binary']) | (ExclusiveRequestBodyBase<SV> & (SV['type'] extends TypeSafeFunction ? ReturnType<SV['type']> : never));
877
+ type SessionObject<SV extends AnySchemaValidator> = StringOnlyObject<SV>;
878
+ type BasicAuthMethods = {
879
+ readonly basic: {
880
+ readonly login: (username: string, password: string) => boolean;
881
+ };
882
+ readonly jwt?: never;
883
+ readonly hmac?: never;
884
+ };
885
+ type JwtAuthMethods = {
886
+ jwt: {
887
+ readonly jwksPublicKey: JWK;
1034
888
  } | {
1035
- query: unknown;
889
+ readonly jwksPublicKeyUrl: string;
1036
890
  } | {
1037
- headers: unknown;
1038
- } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends VersionedApi[K]['responses'] ? Record<number, unknown> : VersionedApi[K]['responses'], ForklaunchResHeaders extends VersionedApi[K]['responseHeaders'] ? unknown : MapSchema<SV, VersionedApi[K]['responseHeaders']>>>>;
891
+ readonly signatureKey: string;
892
+ };
893
+ readonly basic?: never;
894
+ readonly hmac?: never;
895
+ };
896
+ type HmacMethods = {
897
+ readonly hmac: {
898
+ readonly secretKeys: Record<string, string>;
899
+ };
900
+ readonly sessionSchema?: never;
901
+ readonly basic?: never;
902
+ readonly jwt?: never;
903
+ };
904
+ type TokenOptions = {
905
+ readonly tokenPrefix?: string;
906
+ readonly headerName?: string;
907
+ };
908
+ type DecodeResource = (token: string) => JWTPayload | Promise<JWTPayload>;
909
+ type AuthMethodsBase = TokenOptions & (HmacMethods | ({
910
+ readonly decodeResource?: DecodeResource;
911
+ } & (PermissionSet | RoleSet) & (BasicAuthMethods | JwtAuthMethods)));
912
+ type PermissionSet = {
913
+ readonly allowedPermissions: Set<string>;
914
+ } | {
915
+ readonly forbiddenPermissions: Set<string>;
916
+ };
917
+ type RoleSet = {
918
+ readonly allowedRoles: Set<string>;
919
+ } | {
920
+ readonly forbiddenRoles: Set<string>;
1039
921
  };
1040
922
  /**
1041
- * Represents a live type function for the SDK.
1042
- *
1043
- * @template SV - A type that extends AnySchemaValidator.
1044
- * @template P - A type for request parameters.
1045
- * @template ResBodyMap - A type for response schemas.
1046
- * @template ReqBody - A type for the request body.
1047
- * @template ReqQuery - A type for the request query.
1048
- * @template ReqHeaders - A type for the request headers.
1049
- * @template ResHeaders - A type for the response headers.
923
+ * Route access level determines authentication and authorization requirements.
1050
924
  *
925
+ * - `'public'` — No authentication required. `auth` must not be provided.
926
+ * - `'authenticated'` — JWT or Basic auth required, any valid user. RBAC optional.
927
+ * - `'protected'` — JWT or Basic auth required. Must declare roles, permissions, or scope.
928
+ * - `'internal'` — HMAC auth required (inter-service communication).
1051
929
  */
1052
- type LiveSdkFunction<SV extends AnySchemaValidator, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method>, Auth extends AuthMethodsBase> = string extends keyof VersionedApi ? (...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & LiveTypeFunctionRequestInit<SV, P, ReqBody, ReqQuery, ReqHeaders, Auth>> extends infer ReqInit ? ReqInit extends {
1053
- body: unknown;
1054
- } | {
1055
- params: unknown;
930
+ type AccessLevel = 'public' | 'authenticated' | 'protected' | 'internal';
931
+ /**
932
+ * Discriminated union that narrows the `auth` type based on the `access` level.
933
+ * - `public`: auth not allowed
934
+ * - `authenticated`: auth optional (JWT/Basic, RBAC not required)
935
+ * - `protected`: auth required, must include at least one RBAC declaration
936
+ * - `internal`: auth required, must be HMAC
937
+ */
938
+ type AccessAuth<Auth> = {
939
+ readonly access: 'public';
940
+ readonly auth?: never;
1056
941
  } | {
1057
- query: unknown;
942
+ readonly access: 'authenticated';
943
+ readonly auth?: Auth;
1058
944
  } | {
1059
- headers: unknown;
1060
- } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends ResBodyMap ? Record<number, unknown> : ResBodyMap, ForklaunchResHeaders extends ResHeaders ? unknown : MapSchema<SV, ResHeaders>>>> : {
1061
- [K in keyof VersionedApi]: (...reqInit: Prettify<Omit<RequestInit, 'method' | 'body' | 'query' | 'headers' | 'params'> & LiveTypeFunctionRequestInit<SV, P, VersionedApi[K]['body'] extends Body<SV> ? VersionedApi[K]['body'] : Body<SV>, VersionedApi[K]['query'] extends QueryObject<SV> ? VersionedApi[K]['query'] : QueryObject<SV>, VersionedApi[K]['requestHeaders'] extends HeadersObject<SV> ? VersionedApi[K]['requestHeaders'] : HeadersObject<SV>, Auth>> extends infer ReqInit ? ReqInit extends {
1062
- body: unknown;
945
+ readonly access: 'protected';
946
+ readonly auth: Auth & ({
947
+ readonly allowedPermissions: Set<string>;
1063
948
  } | {
1064
- params: unknown;
949
+ readonly forbiddenPermissions: Set<string>;
1065
950
  } | {
1066
- query: unknown;
951
+ readonly allowedRoles: Set<string>;
1067
952
  } | {
1068
- headers: unknown;
1069
- } ? [reqInit: Prettify<ReqInit>] : [reqInit?: Prettify<ReqInit>] : never) => Promise<Prettify<SdkResponse<SV, ResponsesObject<SV> extends VersionedApi[K]['responses'] ? Record<number, unknown> : VersionedApi[K]['responses'], ForklaunchResHeaders extends VersionedApi[K]['responseHeaders'] ? unknown : MapSchema<SV, VersionedApi[K]['responseHeaders']>>>>;
953
+ readonly forbiddenRoles: Set<string>;
954
+ } | {
955
+ readonly requiredScope: string;
956
+ });
957
+ } | {
958
+ readonly access: 'internal';
959
+ readonly auth: Auth & HmacMethods;
1070
960
  };
1071
961
  /**
1072
- * Represents a basic SDK Response object.
1073
- *
1074
- * @template ResBodyMap - A type for the response body.
1075
- * @template ResHeaders - A type for the response headers.
962
+ * Type representing the authentication methods.
1076
963
  */
1077
- type SdkResponse<SV extends AnySchemaValidator, ResBodyMap extends Record<number, unknown>, ResHeaders extends Record<string, unknown> | unknown> = ({
1078
- [K in keyof Omit<ForklaunchResErrors, keyof ResBodyMap>]: {
1079
- code: K;
1080
- contentType: 'text/plain';
1081
- response: ForklaunchResErrors[K];
1082
- };
1083
- } & {
1084
- [K in keyof ResBodyMap]: {
1085
- code: K;
1086
- contentType: ExtractContentType<SV, ResBodyMap[K]>;
1087
- response: ExtractResponseBody<SV, ResBodyMap[K]>;
1088
- } & (unknown extends ResHeaders ? unknown : {
1089
- headers: ResHeaders;
1090
- });
1091
- })[keyof (Omit<ForklaunchResErrors, keyof ResBodyMap> & ResBodyMap)];
964
+ type SchemaAuthMethods<SV extends AnySchemaValidator, ParamsSchema extends ParamsObject<SV>, ReqBody extends Body<SV>, QuerySchema extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method>, BaseRequest> = AuthMethodsBase & {
965
+ readonly sessionSchema?: SessionObject<SV>;
966
+ readonly requiredScope?: string;
967
+ readonly scopeHeirarchy?: string[];
968
+ readonly surfaceScopes?: ExpressLikeSchemaAuthMapper<SV, ParamsSchema, ReqBody, QuerySchema, ReqHeaders, VersionedApi, SessionObject<SV>, BaseRequest>;
969
+ readonly requiredFeatures?: string[];
970
+ readonly requireActiveSubscription?: boolean;
971
+ } & ({
972
+ readonly surfacePermissions?: ExpressLikeSchemaAuthMapper<SV, ParamsSchema, ReqBody, QuerySchema, ReqHeaders, VersionedApi, SessionObject<SV>, BaseRequest>;
973
+ } | {
974
+ readonly surfaceRoles?: ExpressLikeSchemaAuthMapper<SV, ParamsSchema, ReqBody, QuerySchema, ReqHeaders, VersionedApi, SessionObject<SV>, BaseRequest>;
975
+ });
976
+ type AuthMethods<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends Record<string, unknown>, ReqHeaders extends Record<string, string>, VersionedReqs extends VersionedRequests, BaseRequest> = AuthMethodsBase & {
977
+ readonly sessionSchema?: SessionObject<SV>;
978
+ readonly requiredScope?: string;
979
+ readonly scopeHeirarchy?: string[];
980
+ readonly surfaceScopes?: ExpressLikeAuthMapper<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionObject<SV>, BaseRequest>;
981
+ readonly requiredFeatures?: string[];
982
+ readonly requireActiveSubscription?: boolean;
983
+ } & (({
984
+ readonly surfacePermissions?: ExpressLikeAuthMapper<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionObject<SV>, BaseRequest>;
985
+ } & PermissionSet) | ({
986
+ readonly surfaceRoles?: ExpressLikeAuthMapper<SV, P, ReqBody, ReqQuery, ReqHeaders, VersionedReqs, SessionObject<SV>, BaseRequest>;
987
+ } & RoleSet));
1092
988
  /**
1093
- * Represents the default error types for responses.
989
+ * Type representing a mapped schema.
990
+ *s ParamsDictionary,
991
+ // ReqBody extends Record<string, unknown>,
992
+ //
993
+ * @template SV - A type that extends AnySchemaValidator.
994
+ * @template T - A type that extends IdiomaticSchema or a valid schema object.
1094
995
  */
1095
- type ForklaunchResErrors<BadRequest = string, Unauthorized = string, NotFound = string, Forbidden = string, InternalServerErrorType = string> = {
1096
- 400: BadRequest;
1097
- 401: Unauthorized;
1098
- 404: NotFound;
1099
- 403: Forbidden;
1100
- 500: InternalServerErrorType;
1101
- };
996
+ type MapSchema<SV extends AnySchemaValidator, T extends IdiomaticSchema<SV> | SV['_ValidSchemaObject']> = Schema<T, SV> extends infer U ? (T extends U ? unknown : U) : never;
1102
997
  /**
1103
- * Represents the default header types for responses.
998
+ * Type representing the parameters in a request.
1104
999
  */
1105
- type ForklaunchResHeaders = {
1106
- 'x-correlation-id': string;
1107
- };
1000
+ type ExtractParams<Path extends `/${string}`> = Path extends `${string}/:${infer Param}/${infer Rest}` ? Param | ExtractParams<`/${Rest}`> : Path extends `${string}/:${infer Param}` ? Param : never;
1108
1001
  /**
1109
- * Represents the default error types for responses.
1002
+ * Type representing the parameters in a request.
1110
1003
  */
1111
- type ErrorContainer<Code extends number> = {
1112
- /** The error code */
1113
- code: Code;
1114
- /** The error message */
1115
- error: string;
1004
+ type ExtractedParamsObject<Path extends `/${string}`> = Record<ExtractParams<Path>, unknown>;
1005
+ /**
1006
+ * Represents the path parameter methods.
1007
+ */
1008
+ type PathParamMethod = 'get' | 'delete' | 'options' | 'head' | 'trace';
1009
+ /**
1010
+ * Represents the body parameter methods.
1011
+ */
1012
+ type HttpMethod = 'post' | 'patch' | 'put';
1013
+ /**
1014
+ * Represents all supported typed methods.
1015
+ */
1016
+ type Method = PathParamMethod | HttpMethod | 'middleware';
1017
+ /**
1018
+ * Interface representing a compiled schema for a response.
1019
+ */
1020
+ type ResponseCompiledSchema = {
1021
+ headers?: unknown;
1022
+ responses: Record<number, unknown>;
1023
+ };
1024
+ type BasePathParamHttpContractDetailsIO<SV extends AnySchemaValidator, BodySchema extends Body<SV> | undefined = Body<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, QuerySchema extends QueryObject<SV> | undefined = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> | undefined = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> | undefined = HeadersObject<SV>> = {
1025
+ /** Optional body for the contract */
1026
+ readonly body?: BodySchema;
1027
+ /** Response schemas for the contract */
1028
+ readonly responses: ResponseSchemas;
1029
+ /** Optional request headers for the contract */
1030
+ readonly requestHeaders?: ReqHeaders;
1031
+ /** Optional response headers for the contract */
1032
+ readonly responseHeaders?: ResHeaders;
1033
+ /** Optional query schemas for the contract */
1034
+ readonly query?: QuerySchema;
1035
+ };
1036
+ type VersionedBasePathParamHttpContractDetailsIO<SV extends AnySchemaValidator, VersionedApi extends VersionSchema<SV, PathParamMethod>> = {
1037
+ readonly versions: VersionedApi;
1116
1038
  };
1039
+ type BasePathParamHttpContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>> = {
1040
+ /** Name of the contract */
1041
+ readonly name: StringWithoutSlash<Name>;
1042
+ /** Summary of the contract */
1043
+ readonly summary: string;
1044
+ /** Options for the contract */
1045
+ readonly options?: {
1046
+ /** Optional request validation for the contract */
1047
+ readonly requestValidation?: 'error' | 'warning' | 'none';
1048
+ /** Optional response validation for the contract */
1049
+ readonly responseValidation?: 'error' | 'warning' | 'none';
1050
+ /** Optional MCP details for the contract */
1051
+ readonly mcp?: boolean;
1052
+ /** Optional OpenAPI details for the contract */
1053
+ readonly openapi?: boolean;
1054
+ };
1055
+ } & (string | number | symbol extends ExtractedParamsObject<Path> ? {
1056
+ /** Optional parameters for the contract */
1057
+ readonly params?: ParamsSchema;
1058
+ } : {
1059
+ /** Required parameters for the contract */
1060
+ readonly params: {
1061
+ [K in keyof ExtractedParamsObject<Path>]: ParamsSchema[K];
1062
+ };
1063
+ });
1117
1064
  /**
1118
- * Represents a parsed response shape.
1065
+ * Interface representing HTTP contract details for path parameters.
1066
+ *
1067
+ * @template SV - A type that extends AnySchemaValidator.
1068
+ * @template ParamsSchema - A type for parameter schemas, defaulting to ParamsObject.
1069
+ * @template ResponseSchemas - A type for response schemas, defaulting to ResponsesObject.
1070
+ * @template QuerySchema - A type for query schemas, defaulting to QueryObject.
1119
1071
  */
1120
- type ResponseShape<Params, Headers, Query, Body> = {
1121
- params: Params;
1122
- headers: Headers;
1123
- query: Query;
1124
- body: Body;
1072
+ type PathParamHttpContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, BodySchema extends Body<SV> = Body<SV>, QuerySchema extends QueryObject<SV> = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> = HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method> = VersionSchema<SV, PathParamMethod>, BaseRequest = unknown, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest> = SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = BasePathParamHttpContractDetails<SV, Name, Path, ParamsSchema> & ((BasePathParamHttpContractDetailsIO<SV, never, ResponseSchemas, QuerySchema, ReqHeaders, ResHeaders> & {
1073
+ readonly versions?: never;
1074
+ }) | (VersionedBasePathParamHttpContractDetailsIO<SV, VersionedApi> & {
1075
+ readonly query?: never;
1076
+ readonly requestHeaders?: never;
1077
+ readonly responseHeaders?: never;
1078
+ readonly responses?: never;
1079
+ })) & AccessAuth<Auth>;
1080
+ type VersionedHttpContractDetailsIO<SV extends AnySchemaValidator, VersionedApi extends VersionSchema<SV, HttpMethod>> = {
1081
+ readonly versions: VersionedApi;
1125
1082
  };
1126
1083
  /**
1127
- * Represents a path match.
1084
+ * Interface representing HTTP contract details.
1085
+ *
1086
+ * @template SV - A type that extends AnySchemaValidator.
1087
+ * @template ParamsSchema - A type for parameter schemas, defaulting to ParamsObject.
1088
+ * @template ResponseSchemas - A type for response schemas, defaulting to ResponsesObject.
1089
+ * @template BodySchema - A type for the body schema, defaulting to Body.
1090
+ * @template QuerySchema - A type for query schemas, defaulting to QueryObject.
1128
1091
  */
1129
- type PathMatch<SuppliedPath extends `/${string}`, ActualPath extends `/${string}`> = ActualPath extends SuppliedPath ? SuppliedPath extends ActualPath ? SuppliedPath : never : never;
1092
+ type HttpContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, BodySchema extends Body<SV> = Body<SV>, QuerySchema extends QueryObject<SV> = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> = HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method> = VersionSchema<SV, HttpMethod>, BaseRequest = unknown, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest> = SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = BasePathParamHttpContractDetails<SV, Name, Path, ParamsSchema> & ((BasePathParamHttpContractDetailsIO<SV, BodySchema, ResponseSchemas, QuerySchema, ReqHeaders, ResHeaders> & {
1093
+ readonly versions?: never;
1094
+ }) | (VersionedHttpContractDetailsIO<SV, VersionedApi> & {
1095
+ readonly query?: never;
1096
+ readonly requestHeaders?: never;
1097
+ readonly responseHeaders?: never;
1098
+ readonly body?: never;
1099
+ readonly responses?: never;
1100
+ })) & AccessAuth<Auth>;
1101
+ /**
1102
+ * Interface representing HTTP contract details for middleware.
1103
+ *
1104
+ * @template SV - A type that extends AnySchemaValidator.
1105
+ * @template ParamsSchema - A type for parameter schemas, defaulting to ParamsObject.
1106
+ * @template ResponseSchemas - A type for response schemas, defaulting to ResponsesObject.
1107
+ * @template QuerySchema - A type for query schemas, defaulting to QueryObject.
1108
+ * @template ReqHeaders - A type for request headers, defaulting to HeadersObject.
1109
+ * @template ResHeaders - A type for response headers, defaulting to HeadersObject.
1110
+ */
1111
+ type MiddlewareContractDetails<SV extends AnySchemaValidator, Name extends string = string, Path extends `/${string}` = `/${string}`, ParamsSchema extends ParamsObject<SV> = ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV> = ResponsesObject<SV>, BodySchema extends Body<SV> = Body<SV>, QuerySchema extends QueryObject<SV> = QueryObject<SV>, ReqHeaders extends HeadersObject<SV> = HeadersObject<SV>, ResHeaders extends HeadersObject<SV> = HeadersObject<SV>, VersionedApi extends VersionSchema<SV, Method> = VersionSchema<SV, 'middleware'>, BaseRequest = unknown, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest> = SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = Omit<Partial<HttpContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth>>, 'responses'>;
1112
+ type VersionSchema<SV extends AnySchemaValidator, ContractMethod extends Method> = Record<string, BasePathParamHttpContractDetailsIO<SV, ContractMethod extends PathParamMethod ? never : Body<SV>, ResponsesObject<SV>, QueryObject<SV>, HeadersObject<SV>, HeadersObject<SV>>>;
1113
+ /**
1114
+ * Utility for different Contract Detail types
1115
+ */
1116
+ type ContractDetails<SV extends AnySchemaValidator, Name extends string, ContractMethod extends Method, Path extends `/${string}`, ParamsSchema extends ParamsObject<SV>, ResponseSchemas extends ResponsesObject<SV>, BodySchema extends Body<SV>, QuerySchema extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, VersionedApi extends VersionSchema<SV, ContractMethod>, BaseRequest, Auth extends SchemaAuthMethods<SV, ParamsSchema, BodySchema, QuerySchema, ReqHeaders, VersionedApi, BaseRequest>> = ContractMethod extends PathParamMethod ? PathParamHttpContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth> : ContractMethod extends HttpMethod ? HttpContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth> : ContractMethod extends 'middleware' ? MiddlewareContractDetails<SV, Name, Path, ParamsSchema, ResponseSchemas, BodySchema, QuerySchema, ReqHeaders, ResHeaders, VersionedApi, BaseRequest, Auth> : never;
1117
+ /**
1118
+ * Resolves the session object type to use for authentication.
1119
+ *
1120
+ * If `AuthSession` is provided and extends `SessionObject<SV>`, it is used as the session type.
1121
+ * Otherwise, the `FallbackSession` type is used.
1122
+ *
1123
+ * @template SV - The schema validator type.
1124
+ * @template AuthSession - The session object type provided by the authentication method, or undefined.
1125
+ * @template FallbackSession - The fallback session object type to use if `AuthSession` is not provided.
1126
+ */
1127
+ type ResolvedSessionObject<SV extends AnySchemaValidator, AuthSession extends SessionObject<SV> | undefined, FallbackSession extends SessionObject<SV>> = AuthSession extends {
1128
+ readonly sessionSchema?: infer ResolvedSessionSchema | undefined;
1129
+ } | undefined ? ResolvedSessionSchema extends SessionObject<SV> ? ResolvedSessionSchema : FallbackSession : FallbackSession;
1130
1130
 
1131
1131
  export { type ForklaunchBaseRequest as $, type AuthMethodsBase as A, type Body as B, type ContractDetails as C, type DecodeResource as D, type ExpressLikeRouterOptions as E, type ForklaunchRequest as F, type DocsConfiguration as G, type HttpContractDetails as H, type ErrorContainer as I, type ExpressLikeAuthMapper as J, type ExpressLikeGlobalAuthOptions as K, type LiveTypeFunction as L, type Method as M, type ExpressLikeHandler as N, OpenTelemetryCollector as O, type PathParamHttpContractDetails as P, type QueryObject as Q, type ResponsesObject as R, type StringOnlyObject as S, type TelemetryOptions as T, type ExpressLikeSchemaGlobalAuthOptions as U, type VersionSchema as V, type ExtractBody as W, type ExtractContentType as X, type ExtractResponseBody as Y, type ExtractedParamsObject as Z, type FileBody as _, type SessionObject as a, type ForklaunchResErrors as a0, type HmacMethods as a1, type HttpMethod as a2, type JsonBody as a3, type JwtAuthMethods as a4, type LiveTypeFunctionRequestInit as a5, type MapParamsSchema as a6, type MapReqBodySchema as a7, type MapReqHeadersSchema as a8, type MapReqQuerySchema as a9, type UnknownResponseBody as aA, type UrlEncodedForm as aB, type VersionedResponses as aC, httpRequestsTotalCounter as aD, httpServerDurationHistogram as aE, type MapResBodyMapSchema as aa, type MapResHeadersSchema as ab, type MapSchema as ac, type MapSessionSchema as ad, type MapVersionedReqsSchema as ae, type MapVersionedRespsSchema as af, type MetricType as ag, type MultipartForm as ah, type NumberOnlyObject as ai, type PathParamMethod as aj, type PermissionSet as ak, type RawTypedResponseBody as al, type RequestContext as am, type ResolvedForklaunchAuthRequest as an, type ResolvedForklaunchRequest as ao, type ResolvedForklaunchResponse as ap, type ResponseBody as aq, type ResponseCompiledSchema as ar, type ResponseShape as as, type RoleSet as at, type ServerSentEventBody as au, type TextBody as av, type TypedBody as aw, type TypedRequestBody as ax, type TypedResponseBody as ay, type UnknownBody as az, type ParamsObject as b, type HeadersObject as c, type SchemaAuthMethods as d, type ExpressLikeSchemaHandler as e, type ResolvedSessionObject as f, type PathMatch as g, type LiveSdkFunction as h, type MetricsDefinition as i, type ExpressLikeApplicationOptions as j, type ParamsDictionary as k, type VersionedRequests as l, type AuthMethods as m, type BasicAuthMethods as n, type MiddlewareContractDetails as o, type ExpressLikeSchemaAuthMapper as p, type ForklaunchNextFunction as q, type ForklaunchResponse as r, type ForklaunchResHeaders as s, type ForklaunchStatusResponse as t, type ForklaunchSendableData as u, type LoggerMeta as v, type LogFn as w, type AccessLevel as x, type BodyObject as y, type DefaultSubscriptionData as z };