@forklaunch/core 0.19.4 → 1.0.1

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.
@@ -239,6 +239,45 @@ type RoleSet = {
239
239
  } | {
240
240
  readonly forbiddenRoles: Set<string>;
241
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;
280
+ };
242
281
  /**
243
282
  * Type representing the authentication methods.
244
283
  */
@@ -357,10 +396,7 @@ type PathParamHttpContractDetails<SV extends AnySchemaValidator, Name extends st
357
396
  readonly requestHeaders?: never;
358
397
  readonly responseHeaders?: never;
359
398
  readonly responses?: never;
360
- })) & {
361
- /** Optional authentication details for the contract */
362
- readonly auth?: Auth;
363
- };
399
+ })) & AccessAuth<Auth>;
364
400
  type VersionedHttpContractDetailsIO<SV extends AnySchemaValidator, VersionedApi extends VersionSchema<SV, HttpMethod>> = {
365
401
  readonly versions: VersionedApi;
366
402
  };
@@ -381,9 +417,7 @@ type HttpContractDetails<SV extends AnySchemaValidator, Name extends string = st
381
417
  readonly responseHeaders?: never;
382
418
  readonly body?: never;
383
419
  readonly responses?: never;
384
- })) & {
385
- readonly auth?: Auth;
386
- };
420
+ })) & AccessAuth<Auth>;
387
421
  /**
388
422
  * Interface representing HTTP contract details for middleware.
389
423
  *
@@ -1094,4 +1128,4 @@ type ResponseShape<Params, Headers, Query, Body> = {
1094
1128
  */
1095
1129
  type PathMatch<SuppliedPath extends `/${string}`, ActualPath extends `/${string}`> = ActualPath extends SuppliedPath ? SuppliedPath extends ActualPath ? SuppliedPath : never : never;
1096
1130
 
1097
- export { type ForklaunchResErrors 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 ErrorContainer as G, type HttpContractDetails as H, type ExpressLikeAuthMapper as I, type ExpressLikeGlobalAuthOptions as J, type ExpressLikeHandler as K, type LiveTypeFunction as L, type Method as M, type ExpressLikeSchemaGlobalAuthOptions 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 ExtractBody as U, type VersionSchema as V, type ExtractContentType as W, type ExtractResponseBody as X, type ExtractedParamsObject as Y, type FileBody as Z, type ForklaunchBaseRequest as _, type SessionObject as a, type HmacMethods as a0, type HttpMethod as a1, type JsonBody as a2, type JwtAuthMethods as a3, type LiveTypeFunctionRequestInit as a4, type MapParamsSchema as a5, type MapReqBodySchema as a6, type MapReqHeadersSchema as a7, type MapReqQuerySchema as a8, type MapResBodyMapSchema as a9, httpRequestsTotalCounter as aA, httpServerDurationHistogram as aB, type MapResHeadersSchema as aa, type MapSchema as ab, type MapSessionSchema as ac, type MapVersionedReqsSchema as ad, type MapVersionedRespsSchema as ae, type MetricType as af, type MultipartForm as ag, type NumberOnlyObject as ah, type PathParamMethod as ai, type RawTypedResponseBody as aj, type RequestContext as ak, type ResolvedForklaunchAuthRequest as al, type ResolvedForklaunchRequest as am, type ResolvedForklaunchResponse as an, type ResponseBody as ao, type ResponseCompiledSchema as ap, type ResponseShape as aq, type ServerSentEventBody as ar, type TextBody as as, type TypedBody as at, type TypedRequestBody as au, type TypedResponseBody as av, type UnknownBody as aw, type UnknownResponseBody as ax, type UrlEncodedForm as ay, type VersionedResponses 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 BodyObject as x, type DefaultSubscriptionData as y, type DocsConfiguration as z };
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 };
@@ -239,6 +239,45 @@ type RoleSet = {
239
239
  } | {
240
240
  readonly forbiddenRoles: Set<string>;
241
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;
280
+ };
242
281
  /**
243
282
  * Type representing the authentication methods.
244
283
  */
@@ -357,10 +396,7 @@ type PathParamHttpContractDetails<SV extends AnySchemaValidator, Name extends st
357
396
  readonly requestHeaders?: never;
358
397
  readonly responseHeaders?: never;
359
398
  readonly responses?: never;
360
- })) & {
361
- /** Optional authentication details for the contract */
362
- readonly auth?: Auth;
363
- };
399
+ })) & AccessAuth<Auth>;
364
400
  type VersionedHttpContractDetailsIO<SV extends AnySchemaValidator, VersionedApi extends VersionSchema<SV, HttpMethod>> = {
365
401
  readonly versions: VersionedApi;
366
402
  };
@@ -381,9 +417,7 @@ type HttpContractDetails<SV extends AnySchemaValidator, Name extends string = st
381
417
  readonly responseHeaders?: never;
382
418
  readonly body?: never;
383
419
  readonly responses?: never;
384
- })) & {
385
- readonly auth?: Auth;
386
- };
420
+ })) & AccessAuth<Auth>;
387
421
  /**
388
422
  * Interface representing HTTP contract details for middleware.
389
423
  *
@@ -1094,4 +1128,4 @@ type ResponseShape<Params, Headers, Query, Body> = {
1094
1128
  */
1095
1129
  type PathMatch<SuppliedPath extends `/${string}`, ActualPath extends `/${string}`> = ActualPath extends SuppliedPath ? SuppliedPath extends ActualPath ? SuppliedPath : never : never;
1096
1130
 
1097
- export { type ForklaunchResErrors 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 ErrorContainer as G, type HttpContractDetails as H, type ExpressLikeAuthMapper as I, type ExpressLikeGlobalAuthOptions as J, type ExpressLikeHandler as K, type LiveTypeFunction as L, type Method as M, type ExpressLikeSchemaGlobalAuthOptions 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 ExtractBody as U, type VersionSchema as V, type ExtractContentType as W, type ExtractResponseBody as X, type ExtractedParamsObject as Y, type FileBody as Z, type ForklaunchBaseRequest as _, type SessionObject as a, type HmacMethods as a0, type HttpMethod as a1, type JsonBody as a2, type JwtAuthMethods as a3, type LiveTypeFunctionRequestInit as a4, type MapParamsSchema as a5, type MapReqBodySchema as a6, type MapReqHeadersSchema as a7, type MapReqQuerySchema as a8, type MapResBodyMapSchema as a9, httpRequestsTotalCounter as aA, httpServerDurationHistogram as aB, type MapResHeadersSchema as aa, type MapSchema as ab, type MapSessionSchema as ac, type MapVersionedReqsSchema as ad, type MapVersionedRespsSchema as ae, type MetricType as af, type MultipartForm as ag, type NumberOnlyObject as ah, type PathParamMethod as ai, type RawTypedResponseBody as aj, type RequestContext as ak, type ResolvedForklaunchAuthRequest as al, type ResolvedForklaunchRequest as am, type ResolvedForklaunchResponse as an, type ResponseBody as ao, type ResponseCompiledSchema as ap, type ResponseShape as aq, type ServerSentEventBody as ar, type TextBody as as, type TypedBody as at, type TypedRequestBody as au, type TypedResponseBody as av, type UnknownBody as aw, type UnknownResponseBody as ax, type UrlEncodedForm as ay, type VersionedResponses 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 BodyObject as x, type DefaultSubscriptionData as y, type DocsConfiguration as z };
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 };
@@ -1,3 +1,5 @@
1
+ export { T as TtlCache, a as TtlCacheRecord } from '../ttlCache.interface-DClm-lSa.mjs';
2
+
1
3
  /**
2
4
  * Creates a function that generates cache keys with a given prefix.
3
5
  *
@@ -9,136 +11,4 @@
9
11
  */
10
12
  declare const createCacheKey: (cacheKeyPrefix: string) => (id: string) => string;
11
13
 
12
- /**
13
- * Type representing a TTL (Time-To-Live) cache record.
14
- *
15
- * @typedef {Object} TtlCacheRecord
16
- * @property {string} key - The key of the cache record.
17
- * @property {any} value - The value of the cache record.
18
- * @property {number} ttlMilliseconds - The time-to-live of the cache record in milliseconds.
19
- */
20
- type TtlCacheRecord<T> = {
21
- key: string;
22
- value: T;
23
- ttlMilliseconds: number;
24
- };
25
-
26
- /**
27
- * Interface representing a TTL (Time-To-Live) cache.
28
- */
29
- interface TtlCache {
30
- /**
31
- * Puts a record into the cache.
32
- *
33
- * @param {TtlCacheRecord} cacheRecord - The cache record to put into the cache.
34
- * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
35
- */
36
- putRecord<T>(cacheRecord: TtlCacheRecord<T>): Promise<void>;
37
- /**
38
- * Puts a batch of records into the cache.
39
- *
40
- * @param {TtlCacheRecord<T>[]} cacheRecords - The cache records to put into the cache.
41
- * @returns {Promise<void>} - A promise that resolves when the records are put into the cache.
42
- */
43
- putBatchRecords<T>(cacheRecords: TtlCacheRecord<T>[]): Promise<void>;
44
- /**
45
- * Enqueues a record into the cache.
46
- *
47
- * @param {string} cacheRecordKey - The key of the cache record to enqueue.
48
- * @returns {Promise<void>} - A promise that resolves when the record is enqueued into the cache.
49
- */
50
- enqueueRecord<T>(queueName: string, cacheRecord: T): Promise<void>;
51
- /**
52
- *
53
- * Enqueues a batch of records into the cache.
54
- *
55
- * @param {string[]} cacheRecordKeys - The keys of the cache records to enqueue.
56
- * @returns {Promise<void>} - A promise that resolves when the records are enqueued into the cache.
57
- */
58
- enqueueBatchRecords<T>(queueName: string, cacheRecords: T[]): Promise<void>;
59
- /**
60
- * Deletes a record from the cache.
61
- *
62
- * @param {string} cacheRecordKey - The key of the cache record to delete.
63
- * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.
64
- */
65
- deleteRecord(cacheRecordKey: string): Promise<void>;
66
- /**
67
- * Deletes a batch of records from the cache.
68
- *
69
- * @param {string[]} cacheRecordKeys - The keys of the cache records to delete.
70
- * @returns {Promise<void>} - A promise that resolves when the records are deleted from the cache.
71
- */
72
- deleteBatchRecords(cacheRecordKeys: string[]): Promise<void>;
73
- /**
74
- * Dequeues a record from the cache.
75
- *
76
- * @param {string} cacheRecordKey - The key of the cache record to dequeue.
77
- * @returns {Promise<void>} - A promise that resolves when the record is dequeued from the cache.
78
- */
79
- dequeueRecord<T>(queueName: string): Promise<T>;
80
- /**
81
- * Dequeues a batch of records from the cache.
82
- *
83
- * @param {string[]} cacheRecordKeys - The keys of the cache records to dequeue.
84
- * @returns {Promise<void>} - A promise that resolves when the records are dequeued from the cache.
85
- */
86
- dequeueBatchRecords<T>(queueName: string, pageSize: number): Promise<T[]>;
87
- /**
88
- * Reads a record from the cache.
89
- *
90
- * @param {string} cacheRecordKey - The key of the cache record to read.
91
- * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
92
- */
93
- readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>>;
94
- /**
95
- * Reads a batch of records from the cache.
96
- *
97
- * @param {string[] | string} cacheRecordKeysOrPrefix - The keys of the cache records to read or a prefix to match.
98
- * @returns {Promise<TtlCacheRecord<T>[]>} - A promise that resolves with the cache records.
99
- */
100
- readBatchRecords<T>(cacheRecordKeysOrPrefix: string[] | string): Promise<TtlCacheRecord<T>[]>;
101
- /**
102
- * Peeks at a record in the cache to check if it exists.
103
- *
104
- * @param {string} cacheRecordKey - The key of the cache record to peek at.
105
- * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.
106
- */
107
- peekRecord(cacheRecordKey: string): Promise<boolean>;
108
- /**
109
- * Peeks at a batch of records in the cache to check if they exist.
110
- *
111
- * @param {string[] | string} cacheRecordKeysOrPrefix - The keys of the cache records to peek at or a prefix to match.
112
- * @returns {Promise<boolean[]>} - A promise that resolves with an array of booleans indicating if the records exist.
113
- */
114
- peekBatchRecords(cacheRecordKeysOrPrefix: string[] | string): Promise<boolean[]>;
115
- /**
116
- * Peeks at a record in the cache to check if it exists.
117
- *
118
- * @param {string} queueName - The name of the queue to peek at.
119
- * @returns {Promise<T>} - A promise that resolves with the record.
120
- */
121
- peekQueueRecord<T>(queueName: string): Promise<T>;
122
- /**
123
- * Peeks at a batch of records in the cache to check if they exist.
124
- *
125
- * @param {string} queueName - The name of the queue to peek at.
126
- * @returns {Promise<T[]>} - A promise that resolves with the records.
127
- */
128
- peekQueueRecords<T>(queueName: string, pageSize: number): Promise<T[]>;
129
- /**
130
- * Gets the TTL (Time-To-Live) in milliseconds.
131
- *
132
- * @returns {number} - The TTL in milliseconds.
133
- */
134
- getTtlMilliseconds(): number;
135
- /**
136
- * Lists the keys in the cache that match a pattern prefix.
137
- *
138
- * @param {string} pattern_prefix - The pattern prefix to match.
139
- * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.
140
- */
141
- listKeys(pattern_prefix: string): Promise<string[]>;
142
- }
143
-
144
- export { type TtlCache, type TtlCacheRecord, createCacheKey };
14
+ export { createCacheKey };
@@ -1,3 +1,5 @@
1
+ export { T as TtlCache, a as TtlCacheRecord } from '../ttlCache.interface-DClm-lSa.js';
2
+
1
3
  /**
2
4
  * Creates a function that generates cache keys with a given prefix.
3
5
  *
@@ -9,136 +11,4 @@
9
11
  */
10
12
  declare const createCacheKey: (cacheKeyPrefix: string) => (id: string) => string;
11
13
 
12
- /**
13
- * Type representing a TTL (Time-To-Live) cache record.
14
- *
15
- * @typedef {Object} TtlCacheRecord
16
- * @property {string} key - The key of the cache record.
17
- * @property {any} value - The value of the cache record.
18
- * @property {number} ttlMilliseconds - The time-to-live of the cache record in milliseconds.
19
- */
20
- type TtlCacheRecord<T> = {
21
- key: string;
22
- value: T;
23
- ttlMilliseconds: number;
24
- };
25
-
26
- /**
27
- * Interface representing a TTL (Time-To-Live) cache.
28
- */
29
- interface TtlCache {
30
- /**
31
- * Puts a record into the cache.
32
- *
33
- * @param {TtlCacheRecord} cacheRecord - The cache record to put into the cache.
34
- * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.
35
- */
36
- putRecord<T>(cacheRecord: TtlCacheRecord<T>): Promise<void>;
37
- /**
38
- * Puts a batch of records into the cache.
39
- *
40
- * @param {TtlCacheRecord<T>[]} cacheRecords - The cache records to put into the cache.
41
- * @returns {Promise<void>} - A promise that resolves when the records are put into the cache.
42
- */
43
- putBatchRecords<T>(cacheRecords: TtlCacheRecord<T>[]): Promise<void>;
44
- /**
45
- * Enqueues a record into the cache.
46
- *
47
- * @param {string} cacheRecordKey - The key of the cache record to enqueue.
48
- * @returns {Promise<void>} - A promise that resolves when the record is enqueued into the cache.
49
- */
50
- enqueueRecord<T>(queueName: string, cacheRecord: T): Promise<void>;
51
- /**
52
- *
53
- * Enqueues a batch of records into the cache.
54
- *
55
- * @param {string[]} cacheRecordKeys - The keys of the cache records to enqueue.
56
- * @returns {Promise<void>} - A promise that resolves when the records are enqueued into the cache.
57
- */
58
- enqueueBatchRecords<T>(queueName: string, cacheRecords: T[]): Promise<void>;
59
- /**
60
- * Deletes a record from the cache.
61
- *
62
- * @param {string} cacheRecordKey - The key of the cache record to delete.
63
- * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.
64
- */
65
- deleteRecord(cacheRecordKey: string): Promise<void>;
66
- /**
67
- * Deletes a batch of records from the cache.
68
- *
69
- * @param {string[]} cacheRecordKeys - The keys of the cache records to delete.
70
- * @returns {Promise<void>} - A promise that resolves when the records are deleted from the cache.
71
- */
72
- deleteBatchRecords(cacheRecordKeys: string[]): Promise<void>;
73
- /**
74
- * Dequeues a record from the cache.
75
- *
76
- * @param {string} cacheRecordKey - The key of the cache record to dequeue.
77
- * @returns {Promise<void>} - A promise that resolves when the record is dequeued from the cache.
78
- */
79
- dequeueRecord<T>(queueName: string): Promise<T>;
80
- /**
81
- * Dequeues a batch of records from the cache.
82
- *
83
- * @param {string[]} cacheRecordKeys - The keys of the cache records to dequeue.
84
- * @returns {Promise<void>} - A promise that resolves when the records are dequeued from the cache.
85
- */
86
- dequeueBatchRecords<T>(queueName: string, pageSize: number): Promise<T[]>;
87
- /**
88
- * Reads a record from the cache.
89
- *
90
- * @param {string} cacheRecordKey - The key of the cache record to read.
91
- * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.
92
- */
93
- readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>>;
94
- /**
95
- * Reads a batch of records from the cache.
96
- *
97
- * @param {string[] | string} cacheRecordKeysOrPrefix - The keys of the cache records to read or a prefix to match.
98
- * @returns {Promise<TtlCacheRecord<T>[]>} - A promise that resolves with the cache records.
99
- */
100
- readBatchRecords<T>(cacheRecordKeysOrPrefix: string[] | string): Promise<TtlCacheRecord<T>[]>;
101
- /**
102
- * Peeks at a record in the cache to check if it exists.
103
- *
104
- * @param {string} cacheRecordKey - The key of the cache record to peek at.
105
- * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.
106
- */
107
- peekRecord(cacheRecordKey: string): Promise<boolean>;
108
- /**
109
- * Peeks at a batch of records in the cache to check if they exist.
110
- *
111
- * @param {string[] | string} cacheRecordKeysOrPrefix - The keys of the cache records to peek at or a prefix to match.
112
- * @returns {Promise<boolean[]>} - A promise that resolves with an array of booleans indicating if the records exist.
113
- */
114
- peekBatchRecords(cacheRecordKeysOrPrefix: string[] | string): Promise<boolean[]>;
115
- /**
116
- * Peeks at a record in the cache to check if it exists.
117
- *
118
- * @param {string} queueName - The name of the queue to peek at.
119
- * @returns {Promise<T>} - A promise that resolves with the record.
120
- */
121
- peekQueueRecord<T>(queueName: string): Promise<T>;
122
- /**
123
- * Peeks at a batch of records in the cache to check if they exist.
124
- *
125
- * @param {string} queueName - The name of the queue to peek at.
126
- * @returns {Promise<T[]>} - A promise that resolves with the records.
127
- */
128
- peekQueueRecords<T>(queueName: string, pageSize: number): Promise<T[]>;
129
- /**
130
- * Gets the TTL (Time-To-Live) in milliseconds.
131
- *
132
- * @returns {number} - The TTL in milliseconds.
133
- */
134
- getTtlMilliseconds(): number;
135
- /**
136
- * Lists the keys in the cache that match a pattern prefix.
137
- *
138
- * @param {string} pattern_prefix - The pattern prefix to match.
139
- * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.
140
- */
141
- listKeys(pattern_prefix: string): Promise<string[]>;
142
- }
143
-
144
- export { type TtlCache, type TtlCacheRecord, createCacheKey };
14
+ export { createCacheKey };
@@ -3,8 +3,8 @@ export { ParsedQs } from 'qs';
3
3
  import { Prettify, SanitizePathSlashes, PrettyCamelCase, TypeSafeFunction, UnionToIntersection, EmptyObject } from '@forklaunch/common';
4
4
  import { AnySchemaValidator } from '@forklaunch/validator';
5
5
  import { ServerOptions, IncomingMessage, ServerResponse } from 'node:http';
6
- import { M as Method, P as PathParamHttpContractDetails, H as HttpContractDetails, E as ExpressLikeRouterOptions, a as SessionObject, b as ParamsObject, R as ResponsesObject, B as Body, Q as QueryObject, c as HeadersObject, V as VersionSchema, d as SchemaAuthMethods, e as ExpressLikeSchemaHandler, f as ResolvedSessionObject, C as ContractDetails, g as PathMatch, L as LiveTypeFunction, h as LiveSdkFunction, A as AuthMethodsBase, O as OpenTelemetryCollector, i as MetricsDefinition, j as ExpressLikeApplicationOptions, k as ParamsDictionary, l as VersionedRequests, m as AuthMethods, D as DecodeResource, n as BasicAuthMethods, F as ForklaunchRequest, o as MiddlewareContractDetails, p as ExpressLikeSchemaAuthMapper, q as ForklaunchNextFunction, r as ForklaunchResponse, s as ForklaunchResHeaders, t as ForklaunchStatusResponse, u as ForklaunchSendableData, T as TelemetryOptions, v as LoggerMeta, w as LogFn } from '../apiDefinition.types-DnUkFmfT.mjs';
7
- export { x as BodyObject, y as DefaultSubscriptionData, z as DocsConfiguration, G as ErrorContainer, I as ExpressLikeAuthMapper, J as ExpressLikeGlobalAuthOptions, K as ExpressLikeHandler, N as ExpressLikeSchemaGlobalAuthOptions, U as ExtractBody, W as ExtractContentType, X as ExtractResponseBody, Y as ExtractedParamsObject, Z as FileBody, _ as ForklaunchBaseRequest, $ as ForklaunchResErrors, a0 as HmacMethods, a1 as HttpMethod, a2 as JsonBody, a3 as JwtAuthMethods, a4 as LiveTypeFunctionRequestInit, a5 as MapParamsSchema, a6 as MapReqBodySchema, a7 as MapReqHeadersSchema, a8 as MapReqQuerySchema, a9 as MapResBodyMapSchema, aa as MapResHeadersSchema, ab as MapSchema, ac as MapSessionSchema, ad as MapVersionedReqsSchema, ae as MapVersionedRespsSchema, af as MetricType, ag as MultipartForm, ah as NumberOnlyObject, ai as PathParamMethod, aj as RawTypedResponseBody, ak as RequestContext, al as ResolvedForklaunchAuthRequest, am as ResolvedForklaunchRequest, an as ResolvedForklaunchResponse, ao as ResponseBody, ap as ResponseCompiledSchema, aq as ResponseShape, ar as ServerSentEventBody, S as StringOnlyObject, as as TextBody, at as TypedBody, au as TypedRequestBody, av as TypedResponseBody, aw as UnknownBody, ax as UnknownResponseBody, ay as UrlEncodedForm, az as VersionedResponses, aA as httpRequestsTotalCounter, aB as httpServerDurationHistogram } from '../apiDefinition.types-DnUkFmfT.mjs';
6
+ import { M as Method, P as PathParamHttpContractDetails, H as HttpContractDetails, E as ExpressLikeRouterOptions, a as SessionObject, b as ParamsObject, R as ResponsesObject, B as Body, Q as QueryObject, c as HeadersObject, V as VersionSchema, d as SchemaAuthMethods, e as ExpressLikeSchemaHandler, f as ResolvedSessionObject, C as ContractDetails, g as PathMatch, L as LiveTypeFunction, h as LiveSdkFunction, A as AuthMethodsBase, O as OpenTelemetryCollector, i as MetricsDefinition, j as ExpressLikeApplicationOptions, k as ParamsDictionary, l as VersionedRequests, m as AuthMethods, D as DecodeResource, n as BasicAuthMethods, F as ForklaunchRequest, o as MiddlewareContractDetails, p as ExpressLikeSchemaAuthMapper, q as ForklaunchNextFunction, r as ForklaunchResponse, s as ForklaunchResHeaders, t as ForklaunchStatusResponse, u as ForklaunchSendableData, T as TelemetryOptions, v as LoggerMeta, w as LogFn } from '../apiDefinition.types-Br0fDuBQ.mjs';
7
+ export { x as AccessLevel, y as BodyObject, z as DefaultSubscriptionData, G as DocsConfiguration, I as ErrorContainer, J as ExpressLikeAuthMapper, K as ExpressLikeGlobalAuthOptions, N as ExpressLikeHandler, U as ExpressLikeSchemaGlobalAuthOptions, W as ExtractBody, X as ExtractContentType, Y as ExtractResponseBody, Z as ExtractedParamsObject, _ as FileBody, $ as ForklaunchBaseRequest, a0 as ForklaunchResErrors, a1 as HmacMethods, a2 as HttpMethod, a3 as JsonBody, a4 as JwtAuthMethods, a5 as LiveTypeFunctionRequestInit, a6 as MapParamsSchema, a7 as MapReqBodySchema, a8 as MapReqHeadersSchema, a9 as MapReqQuerySchema, aa as MapResBodyMapSchema, ab as MapResHeadersSchema, ac as MapSchema, ad as MapSessionSchema, ae as MapVersionedReqsSchema, af as MapVersionedRespsSchema, ag as MetricType, ah as MultipartForm, ai as NumberOnlyObject, aj as PathParamMethod, ak as PermissionSet, al as RawTypedResponseBody, am as RequestContext, an as ResolvedForklaunchAuthRequest, ao as ResolvedForklaunchRequest, ap as ResolvedForklaunchResponse, aq as ResponseBody, ar as ResponseCompiledSchema, as as ResponseShape, at as RoleSet, au as ServerSentEventBody, S as StringOnlyObject, av as TextBody, aw as TypedBody, ax as TypedRequestBody, ay as TypedResponseBody, az as UnknownBody, aA as UnknownResponseBody, aB as UrlEncodedForm, aC as VersionedResponses, aD as httpRequestsTotalCounter, aE as httpServerDurationHistogram } from '../apiDefinition.types-Br0fDuBQ.mjs';
8
8
  import { JWTPayload, JWK } from 'jose';
9
9
  import { ZodSchemaValidator } from '@forklaunch/validator/zod';
10
10
  import { FastMCP } from 'fastmcp';
@@ -13,6 +13,7 @@ import { OpenAPIObject } from 'openapi3-ts/oas31';
13
13
  import pino, { LevelWithSilentOrString, LevelWithSilent } from 'pino';
14
14
  export { LevelWithSilent, LevelWithSilentOrString, Logger } from 'pino';
15
15
  import { AnyValueMap } from '@opentelemetry/api-logs';
16
+ import { T as TtlCache } from '../ttlCache.interface-DClm-lSa.mjs';
16
17
  export { ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
17
18
  import '@opentelemetry/api';
18
19
  import 'stream';
@@ -1125,6 +1126,25 @@ declare function discriminateResponseBodies<SV extends AnySchemaValidator>(schem
1125
1126
  schema: SV["_ValidSchemaObject"];
1126
1127
  }>;
1127
1128
 
1129
+ type AuditEntry = {
1130
+ timestamp: string;
1131
+ userId: string | null;
1132
+ tenantId: string | null;
1133
+ route: string;
1134
+ method: string;
1135
+ bodyHash: string;
1136
+ status: number;
1137
+ duration: number;
1138
+ redactedFields: string[];
1139
+ eventType: 'http' | 'ws' | 'auth_failure' | 'rate_limit' | 'rbac_deny' | 'super_admin_bypass';
1140
+ };
1141
+ declare class AuditLogger {
1142
+ #private;
1143
+ constructor(otel: OpenTelemetryCollector<MetricsDefinition>);
1144
+ append(entry: AuditEntry): void;
1145
+ static hashBody(body: string | Buffer | undefined | null): string;
1146
+ }
1147
+
1128
1148
  declare const ATTR_API_NAME = "api.name";
1129
1149
  declare const ATTR_CORRELATION_ID = "correlation.id";
1130
1150
  declare const ATTR_APPLICATION_ID = "application_id";
@@ -1158,4 +1178,69 @@ declare function logger(level: LevelWithSilentOrString, meta?: AnyValueMap): Pin
1158
1178
 
1159
1179
  declare function recordMetric<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ResBodyMap extends Record<string, unknown>, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, unknown>, LocalsObj extends Record<string, unknown>, VersionedReqs extends VersionedRequests, SessionSchema extends Record<string, unknown>>(req: ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders, Extract<keyof VersionedReqs, string>, SessionSchema>, res: ForklaunchResponse<unknown, ResBodyMap, ResHeaders, LocalsObj, Extract<keyof VersionedReqs, string>>): void;
1160
1180
 
1161
- export { ATTR_API_NAME, ATTR_APPLICATION_ID, ATTR_CORRELATION_ID, AuthMethods, AuthMethodsBase, BasicAuthMethods, Body, type ClusterConfig, type ConstrainedForklaunchRouter, ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, DecodeResource, ExpressLikeApplicationOptions, type ExpressLikeRouter, ExpressLikeRouterOptions, ExpressLikeSchemaAuthMapper, ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractLiveTypeFn, type FetchFunction, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, ForklaunchNextFunction, ForklaunchRequest, ForklaunchResHeaders, ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, ForklaunchSendableData, ForklaunchStatusResponse, HTTPStatuses, HeadersObject, HttpContractDetails, LiveSdkFunction, LiveTypeFunction, type LiveTypeRouteDefinition, LogFn, LoggerMeta, type MapHandlerToLiveSdk, type MapToFetch, type MapToSdk, Method, MetricsDefinition, MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, OPENAPI_DEFAULT_VERSION, OpenTelemetryCollector, ParamsDictionary, ParamsObject, type PathBasedHandler, PathMatch, type PathOrMiddlewareBasedHandler, PathParamHttpContractDetails, PinoLogger, QueryObject, ResolvedSessionObject, ResponsesObject, type RouterMap, type RoutingStrategy, SchemaAuthMethods, type SdkHandler, type SdkHandlerObject, type SdkRouter, SessionObject, type StatusCode, TelemetryOptions, type ToFetchMap, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, VersionSchema, VersionedRequests, createContext, createHmacToken, delete_, discriminateAuthMethod, discriminateBody, discriminateResponseBodies, enrichExpressLikeSend, evaluateTelemetryOptions, extractRouteHandlers, generateHmacAuthHeaders, generateMcpServer, generateOpenApiSpecs, get, getCachedJwks, getCodeForStatus, head, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isPortBound, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedAuthHandler, typedHandler };
1181
+ /**
1182
+ * Configuration for rate limiting with separate read/write limits.
1183
+ */
1184
+ type RateLimitConfig = {
1185
+ /** Max requests per window for GET/HEAD/OPTIONS */
1186
+ read: number;
1187
+ /** Max requests per window for POST/PUT/PATCH/DELETE */
1188
+ write: number;
1189
+ /** Window duration in milliseconds */
1190
+ windowMs: number;
1191
+ };
1192
+ /**
1193
+ * Result of a rate limit check.
1194
+ */
1195
+ type RateLimitResult = {
1196
+ /** Whether the request is allowed */
1197
+ allowed: boolean;
1198
+ /** Number of remaining requests in the current window */
1199
+ remaining: number;
1200
+ /** Unix timestamp (ms) when the current window resets */
1201
+ resetAt: number;
1202
+ };
1203
+ /**
1204
+ * Rate limiter backed by a TtlCache.
1205
+ *
1206
+ * Uses a sliding-window counter pattern: each unique key maps to a
1207
+ * {@link RateLimitCounter} stored in the cache with a TTL equal to the
1208
+ * configured window duration.
1209
+ */
1210
+ declare class RateLimiter {
1211
+ private cache;
1212
+ constructor(cache: TtlCache);
1213
+ /**
1214
+ * Check whether the given key is within its rate limit.
1215
+ *
1216
+ * The counter is read from the cache, incremented, and written back.
1217
+ * If the cache is unreachable the limiter **fails open** (allows the
1218
+ * request) so that a cache outage does not take down the service.
1219
+ *
1220
+ * @param key - The rate limit key (see {@link RateLimiter.buildKey}).
1221
+ * @param limit - Maximum number of requests allowed in the window.
1222
+ * @param windowMs - Window duration in milliseconds.
1223
+ */
1224
+ check(key: string, limit: number, windowMs: number): Promise<RateLimitResult>;
1225
+ /**
1226
+ * Build a rate limit key from request context parts.
1227
+ *
1228
+ * Format: `ratelimit:{tenantId}:{route}:{userId}:{operationType}`
1229
+ *
1230
+ * When `tenantId` or `userId` is `null`, the placeholder `"anon"` is used.
1231
+ */
1232
+ static buildKey(parts: {
1233
+ tenantId: string | null;
1234
+ route: string;
1235
+ userId: string | null;
1236
+ operationType: 'read' | 'write';
1237
+ }): string;
1238
+ /**
1239
+ * Determine whether an HTTP method is a read or write operation.
1240
+ *
1241
+ * GET, HEAD, and OPTIONS are reads; everything else is a write.
1242
+ */
1243
+ static operationType(method: string): 'read' | 'write';
1244
+ }
1245
+
1246
+ export { ATTR_API_NAME, ATTR_APPLICATION_ID, ATTR_CORRELATION_ID, type AuditEntry, AuditLogger, AuthMethods, AuthMethodsBase, BasicAuthMethods, Body, type ClusterConfig, type ConstrainedForklaunchRouter, ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, DecodeResource, ExpressLikeApplicationOptions, type ExpressLikeRouter, ExpressLikeRouterOptions, ExpressLikeSchemaAuthMapper, ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractLiveTypeFn, type FetchFunction, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, ForklaunchNextFunction, ForklaunchRequest, ForklaunchResHeaders, ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, ForklaunchSendableData, ForklaunchStatusResponse, HTTPStatuses, HeadersObject, HttpContractDetails, LiveSdkFunction, LiveTypeFunction, type LiveTypeRouteDefinition, LogFn, LoggerMeta, type MapHandlerToLiveSdk, type MapToFetch, type MapToSdk, Method, MetricsDefinition, MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, OPENAPI_DEFAULT_VERSION, OpenTelemetryCollector, ParamsDictionary, ParamsObject, type PathBasedHandler, PathMatch, type PathOrMiddlewareBasedHandler, PathParamHttpContractDetails, PinoLogger, QueryObject, type RateLimitConfig, type RateLimitResult, RateLimiter, ResolvedSessionObject, ResponsesObject, type RouterMap, type RoutingStrategy, SchemaAuthMethods, type SdkHandler, type SdkHandlerObject, type SdkRouter, SessionObject, type StatusCode, TelemetryOptions, type ToFetchMap, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, VersionSchema, VersionedRequests, createContext, createHmacToken, delete_, discriminateAuthMethod, discriminateBody, discriminateResponseBodies, enrichExpressLikeSend, evaluateTelemetryOptions, extractRouteHandlers, generateHmacAuthHeaders, generateMcpServer, generateOpenApiSpecs, get, getCachedJwks, getCodeForStatus, head, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isPortBound, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedAuthHandler, typedHandler };