balda 0.0.52 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +17 -17
- package/lib/cli.js.map +1 -1
- package/lib/index.cjs +25 -25
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +71 -22
- package/lib/index.d.ts +71 -22
- package/lib/index.js +25 -25
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.d.cts
CHANGED
|
@@ -1831,6 +1831,18 @@ interface Route {
|
|
|
1831
1831
|
*/
|
|
1832
1832
|
type ClientRouter = Omit<Router, "applyGlobalMiddlewaresToAllRoutes" | "addOrUpdate">;
|
|
1833
1833
|
|
|
1834
|
+
/**
|
|
1835
|
+
* Custom handler invoked when a policy check fails.
|
|
1836
|
+
* When set, replaces the default `res.unauthorized({ error: "Unauthorized" })` response.
|
|
1837
|
+
*/
|
|
1838
|
+
type PolicyErrorHandler = (req: Request, res: Response$1) => SyncOrAsync;
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* Custom handler invoked when request validation fails.
|
|
1842
|
+
* When set, replaces the default `res.badRequest(error)` response.
|
|
1843
|
+
*/
|
|
1844
|
+
type ValidationErrorHandler = (req: Request, res: Response$1, error: unknown) => SyncOrAsync;
|
|
1845
|
+
|
|
1834
1846
|
/**
|
|
1835
1847
|
* The server class that is used to create and manage the server
|
|
1836
1848
|
*/
|
|
@@ -1879,6 +1891,8 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
|
|
|
1879
1891
|
mountExpressRouter(basePath: string, expressRouter: Router$1): void;
|
|
1880
1892
|
setErrorHandler(errorHandler?: ServerErrorHandler): void;
|
|
1881
1893
|
setNotFoundHandler(notFoundHandler?: ServerRouteHandler): void;
|
|
1894
|
+
setValidationErrorHandler(handler: ValidationErrorHandler): void;
|
|
1895
|
+
setPolicyErrorHandler(handler: PolicyErrorHandler): void;
|
|
1882
1896
|
beforeStart(hook: ServerHook): void;
|
|
1883
1897
|
beforeClose(hook: ServerHook): void;
|
|
1884
1898
|
listen(cb?: ServerListenCallback): void;
|
|
@@ -2385,6 +2399,36 @@ type TrustProxyOptions = {
|
|
|
2385
2399
|
hop?: "first" | "last";
|
|
2386
2400
|
};
|
|
2387
2401
|
|
|
2402
|
+
declare class PolicyManager<T extends Record<string, PolicyProvider>> {
|
|
2403
|
+
private readonly providers;
|
|
2404
|
+
constructor(providers: T);
|
|
2405
|
+
/**
|
|
2406
|
+
* Creates a decorator for the policy manager with typed parameters
|
|
2407
|
+
*/
|
|
2408
|
+
createDecorator(): PolicyDecorator<T>;
|
|
2409
|
+
/**
|
|
2410
|
+
* Checks if the user has access to the given scope and handler
|
|
2411
|
+
* @param scope - The scope to check access for
|
|
2412
|
+
* @param handler - The handler to check access for
|
|
2413
|
+
* @param args - The arguments to pass to the handler
|
|
2414
|
+
*/
|
|
2415
|
+
canAccess<K extends keyof T, L extends T[K]>(scope: K, handler: keyof L, ...args: Parameters<T[K][keyof T[K]]>): ReturnType<T[K][keyof T[K]]>;
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
type PolicyProvider = {
|
|
2419
|
+
[K: string]: (...args: any[]) => Promise<boolean> | boolean;
|
|
2420
|
+
};
|
|
2421
|
+
type PolicyDecorator<T extends Record<string, PolicyProvider>> = <S extends keyof T & string, H extends keyof T[S] & string>(scope: S, handler: H) => (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => any;
|
|
2422
|
+
/**
|
|
2423
|
+
* Configuration for applying a policy to a route via the options object.
|
|
2424
|
+
* Provides the same type-safe scope/handler selection as the decorator approach.
|
|
2425
|
+
*/
|
|
2426
|
+
type PolicyRouteConfig<T extends Record<string, PolicyProvider> = Record<string, PolicyProvider>> = {
|
|
2427
|
+
manager: PolicyManager<T>;
|
|
2428
|
+
scope: keyof T & string;
|
|
2429
|
+
handler: string;
|
|
2430
|
+
};
|
|
2431
|
+
|
|
2388
2432
|
type ServerHandlerReturnType<TResponseMap extends Record<number, any> = Record<number, any>> = void | Promise<void> | ResponseBodyForStatus<TResponseMap, 200> | Promise<ResponseBodyForStatus<TResponseMap, 200>>;
|
|
2389
2433
|
type ServerPlugin = {
|
|
2390
2434
|
bodyParser?: BodyParserOptions;
|
|
@@ -2638,6 +2682,30 @@ interface ServerInterface {
|
|
|
2638
2682
|
* });
|
|
2639
2683
|
*/
|
|
2640
2684
|
setNotFoundHandler: (notFoundHandler?: ServerRouteHandler) => void;
|
|
2685
|
+
/**
|
|
2686
|
+
* Set a custom handler for validation errors (body/query validation failures).
|
|
2687
|
+
* When set, replaces the default `res.badRequest(error)` response.
|
|
2688
|
+
* @param handler - The handler to invoke when validation fails
|
|
2689
|
+
* @example
|
|
2690
|
+
* ```ts
|
|
2691
|
+
* server.setValidationErrorHandler((req, res, error) => {
|
|
2692
|
+
* res.status(422).json({ code: "VALIDATION_FAILED", details: error });
|
|
2693
|
+
* });
|
|
2694
|
+
* ```
|
|
2695
|
+
*/
|
|
2696
|
+
setValidationErrorHandler: (handler: ValidationErrorHandler) => void;
|
|
2697
|
+
/**
|
|
2698
|
+
* Set a custom handler for policy authorization failures.
|
|
2699
|
+
* When set, replaces the default `res.unauthorized({ error: "Unauthorized" })` response.
|
|
2700
|
+
* @param handler - The handler to invoke when a policy check fails
|
|
2701
|
+
* @example
|
|
2702
|
+
* ```ts
|
|
2703
|
+
* server.setPolicyErrorHandler((req, res) => {
|
|
2704
|
+
* res.status(403).json({ code: "FORBIDDEN", message: "Access denied" });
|
|
2705
|
+
* });
|
|
2706
|
+
* ```
|
|
2707
|
+
*/
|
|
2708
|
+
setPolicyErrorHandler: (handler: PolicyErrorHandler) => void;
|
|
2641
2709
|
/**
|
|
2642
2710
|
* Register a hook to be called after bootstrap (controllers imported, plugins applied) but before the server starts accepting requests.
|
|
2643
2711
|
* Multiple hooks are called in the order they are registered.
|
|
@@ -2720,6 +2788,8 @@ type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Re
|
|
|
2720
2788
|
swagger?: SwaggerRouteOptions;
|
|
2721
2789
|
/** Cache configuration for this route. Requires cache to be initialized via initCacheService(). */
|
|
2722
2790
|
cache?: TypedCacheRouteConfig<TBody, TQuery, TPath>;
|
|
2791
|
+
/** Policy configuration for this route. Accepts a single policy or an array of policies. */
|
|
2792
|
+
policy?: PolicyRouteConfig | PolicyRouteConfig[];
|
|
2723
2793
|
};
|
|
2724
2794
|
type ServerHook = () => SyncOrAsync;
|
|
2725
2795
|
type SignalEvent = Deno.Signal | NodeJS.Signals;
|
|
@@ -4446,27 +4516,6 @@ declare const timeout: (options: TimeoutOptions) => TypedMiddleware<{
|
|
|
4446
4516
|
*/
|
|
4447
4517
|
declare const trustProxy: (options?: TrustProxyOptions) => ServerRouteMiddleware;
|
|
4448
4518
|
|
|
4449
|
-
type PolicyProvider = {
|
|
4450
|
-
[K: string]: (...args: any[]) => Promise<boolean> | boolean;
|
|
4451
|
-
};
|
|
4452
|
-
type PolicyDecorator<T extends Record<string, PolicyProvider>> = <S extends keyof T & string, H extends keyof T[S] & string>(scope: S, handler: H) => (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => any;
|
|
4453
|
-
|
|
4454
|
-
declare class PolicyManager<T extends Record<string, PolicyProvider>> {
|
|
4455
|
-
private readonly providers;
|
|
4456
|
-
constructor(providers: T);
|
|
4457
|
-
/**
|
|
4458
|
-
* Creates a decorator for the policy manager with typed parameters
|
|
4459
|
-
*/
|
|
4460
|
-
createDecorator(): PolicyDecorator<T>;
|
|
4461
|
-
/**
|
|
4462
|
-
* Checks if the user has access to the given scope and handler
|
|
4463
|
-
* @param scope - The scope to check access for
|
|
4464
|
-
* @param handler - The handler to check access for
|
|
4465
|
-
* @param args - The arguments to pass to the handler
|
|
4466
|
-
*/
|
|
4467
|
-
canAccess<K extends keyof T, L extends T[K]>(scope: K, handler: keyof L, ...args: Parameters<T[K][keyof T[K]]>): ReturnType<T[K][keyof T[K]]>;
|
|
4468
|
-
}
|
|
4469
|
-
|
|
4470
4519
|
declare const createPolicyDecorator: <T extends Record<string, PolicyProvider>>(manager: PolicyManager<T>) => PolicyDecorator<T>;
|
|
4471
4520
|
|
|
4472
4521
|
/**
|
|
@@ -4656,4 +4705,4 @@ declare enum CacheStatus {
|
|
|
4656
4705
|
*/
|
|
4657
4706
|
declare const router: ClientRouter;
|
|
4658
4707
|
|
|
4659
|
-
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, PolicyManager, type PolicyProvider, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
|
|
4708
|
+
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, type PolicyErrorHandler, PolicyManager, type PolicyProvider, type PolicyRouteConfig, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationErrorHandler, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
|
package/lib/index.d.ts
CHANGED
|
@@ -1831,6 +1831,18 @@ interface Route {
|
|
|
1831
1831
|
*/
|
|
1832
1832
|
type ClientRouter = Omit<Router, "applyGlobalMiddlewaresToAllRoutes" | "addOrUpdate">;
|
|
1833
1833
|
|
|
1834
|
+
/**
|
|
1835
|
+
* Custom handler invoked when a policy check fails.
|
|
1836
|
+
* When set, replaces the default `res.unauthorized({ error: "Unauthorized" })` response.
|
|
1837
|
+
*/
|
|
1838
|
+
type PolicyErrorHandler = (req: Request, res: Response$1) => SyncOrAsync;
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* Custom handler invoked when request validation fails.
|
|
1842
|
+
* When set, replaces the default `res.badRequest(error)` response.
|
|
1843
|
+
*/
|
|
1844
|
+
type ValidationErrorHandler = (req: Request, res: Response$1, error: unknown) => SyncOrAsync;
|
|
1845
|
+
|
|
1834
1846
|
/**
|
|
1835
1847
|
* The server class that is used to create and manage the server
|
|
1836
1848
|
*/
|
|
@@ -1879,6 +1891,8 @@ declare class Server<H extends NodeHttpClient = NodeHttpClient> implements Serve
|
|
|
1879
1891
|
mountExpressRouter(basePath: string, expressRouter: Router$1): void;
|
|
1880
1892
|
setErrorHandler(errorHandler?: ServerErrorHandler): void;
|
|
1881
1893
|
setNotFoundHandler(notFoundHandler?: ServerRouteHandler): void;
|
|
1894
|
+
setValidationErrorHandler(handler: ValidationErrorHandler): void;
|
|
1895
|
+
setPolicyErrorHandler(handler: PolicyErrorHandler): void;
|
|
1882
1896
|
beforeStart(hook: ServerHook): void;
|
|
1883
1897
|
beforeClose(hook: ServerHook): void;
|
|
1884
1898
|
listen(cb?: ServerListenCallback): void;
|
|
@@ -2385,6 +2399,36 @@ type TrustProxyOptions = {
|
|
|
2385
2399
|
hop?: "first" | "last";
|
|
2386
2400
|
};
|
|
2387
2401
|
|
|
2402
|
+
declare class PolicyManager<T extends Record<string, PolicyProvider>> {
|
|
2403
|
+
private readonly providers;
|
|
2404
|
+
constructor(providers: T);
|
|
2405
|
+
/**
|
|
2406
|
+
* Creates a decorator for the policy manager with typed parameters
|
|
2407
|
+
*/
|
|
2408
|
+
createDecorator(): PolicyDecorator<T>;
|
|
2409
|
+
/**
|
|
2410
|
+
* Checks if the user has access to the given scope and handler
|
|
2411
|
+
* @param scope - The scope to check access for
|
|
2412
|
+
* @param handler - The handler to check access for
|
|
2413
|
+
* @param args - The arguments to pass to the handler
|
|
2414
|
+
*/
|
|
2415
|
+
canAccess<K extends keyof T, L extends T[K]>(scope: K, handler: keyof L, ...args: Parameters<T[K][keyof T[K]]>): ReturnType<T[K][keyof T[K]]>;
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
type PolicyProvider = {
|
|
2419
|
+
[K: string]: (...args: any[]) => Promise<boolean> | boolean;
|
|
2420
|
+
};
|
|
2421
|
+
type PolicyDecorator<T extends Record<string, PolicyProvider>> = <S extends keyof T & string, H extends keyof T[S] & string>(scope: S, handler: H) => (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => any;
|
|
2422
|
+
/**
|
|
2423
|
+
* Configuration for applying a policy to a route via the options object.
|
|
2424
|
+
* Provides the same type-safe scope/handler selection as the decorator approach.
|
|
2425
|
+
*/
|
|
2426
|
+
type PolicyRouteConfig<T extends Record<string, PolicyProvider> = Record<string, PolicyProvider>> = {
|
|
2427
|
+
manager: PolicyManager<T>;
|
|
2428
|
+
scope: keyof T & string;
|
|
2429
|
+
handler: string;
|
|
2430
|
+
};
|
|
2431
|
+
|
|
2388
2432
|
type ServerHandlerReturnType<TResponseMap extends Record<number, any> = Record<number, any>> = void | Promise<void> | ResponseBodyForStatus<TResponseMap, 200> | Promise<ResponseBodyForStatus<TResponseMap, 200>>;
|
|
2389
2433
|
type ServerPlugin = {
|
|
2390
2434
|
bodyParser?: BodyParserOptions;
|
|
@@ -2638,6 +2682,30 @@ interface ServerInterface {
|
|
|
2638
2682
|
* });
|
|
2639
2683
|
*/
|
|
2640
2684
|
setNotFoundHandler: (notFoundHandler?: ServerRouteHandler) => void;
|
|
2685
|
+
/**
|
|
2686
|
+
* Set a custom handler for validation errors (body/query validation failures).
|
|
2687
|
+
* When set, replaces the default `res.badRequest(error)` response.
|
|
2688
|
+
* @param handler - The handler to invoke when validation fails
|
|
2689
|
+
* @example
|
|
2690
|
+
* ```ts
|
|
2691
|
+
* server.setValidationErrorHandler((req, res, error) => {
|
|
2692
|
+
* res.status(422).json({ code: "VALIDATION_FAILED", details: error });
|
|
2693
|
+
* });
|
|
2694
|
+
* ```
|
|
2695
|
+
*/
|
|
2696
|
+
setValidationErrorHandler: (handler: ValidationErrorHandler) => void;
|
|
2697
|
+
/**
|
|
2698
|
+
* Set a custom handler for policy authorization failures.
|
|
2699
|
+
* When set, replaces the default `res.unauthorized({ error: "Unauthorized" })` response.
|
|
2700
|
+
* @param handler - The handler to invoke when a policy check fails
|
|
2701
|
+
* @example
|
|
2702
|
+
* ```ts
|
|
2703
|
+
* server.setPolicyErrorHandler((req, res) => {
|
|
2704
|
+
* res.status(403).json({ code: "FORBIDDEN", message: "Access denied" });
|
|
2705
|
+
* });
|
|
2706
|
+
* ```
|
|
2707
|
+
*/
|
|
2708
|
+
setPolicyErrorHandler: (handler: PolicyErrorHandler) => void;
|
|
2641
2709
|
/**
|
|
2642
2710
|
* Register a hook to be called after bootstrap (controllers imported, plugins applied) but before the server starts accepting requests.
|
|
2643
2711
|
* Multiple hooks are called in the order they are registered.
|
|
@@ -2720,6 +2788,8 @@ type StandardMethodOptions<TResponses extends Record<number, RequestSchema> = Re
|
|
|
2720
2788
|
swagger?: SwaggerRouteOptions;
|
|
2721
2789
|
/** Cache configuration for this route. Requires cache to be initialized via initCacheService(). */
|
|
2722
2790
|
cache?: TypedCacheRouteConfig<TBody, TQuery, TPath>;
|
|
2791
|
+
/** Policy configuration for this route. Accepts a single policy or an array of policies. */
|
|
2792
|
+
policy?: PolicyRouteConfig | PolicyRouteConfig[];
|
|
2723
2793
|
};
|
|
2724
2794
|
type ServerHook = () => SyncOrAsync;
|
|
2725
2795
|
type SignalEvent = Deno.Signal | NodeJS.Signals;
|
|
@@ -4446,27 +4516,6 @@ declare const timeout: (options: TimeoutOptions) => TypedMiddleware<{
|
|
|
4446
4516
|
*/
|
|
4447
4517
|
declare const trustProxy: (options?: TrustProxyOptions) => ServerRouteMiddleware;
|
|
4448
4518
|
|
|
4449
|
-
type PolicyProvider = {
|
|
4450
|
-
[K: string]: (...args: any[]) => Promise<boolean> | boolean;
|
|
4451
|
-
};
|
|
4452
|
-
type PolicyDecorator<T extends Record<string, PolicyProvider>> = <S extends keyof T & string, H extends keyof T[S] & string>(scope: S, handler: H) => (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => any;
|
|
4453
|
-
|
|
4454
|
-
declare class PolicyManager<T extends Record<string, PolicyProvider>> {
|
|
4455
|
-
private readonly providers;
|
|
4456
|
-
constructor(providers: T);
|
|
4457
|
-
/**
|
|
4458
|
-
* Creates a decorator for the policy manager with typed parameters
|
|
4459
|
-
*/
|
|
4460
|
-
createDecorator(): PolicyDecorator<T>;
|
|
4461
|
-
/**
|
|
4462
|
-
* Checks if the user has access to the given scope and handler
|
|
4463
|
-
* @param scope - The scope to check access for
|
|
4464
|
-
* @param handler - The handler to check access for
|
|
4465
|
-
* @param args - The arguments to pass to the handler
|
|
4466
|
-
*/
|
|
4467
|
-
canAccess<K extends keyof T, L extends T[K]>(scope: K, handler: keyof L, ...args: Parameters<T[K][keyof T[K]]>): ReturnType<T[K][keyof T[K]]>;
|
|
4468
|
-
}
|
|
4469
|
-
|
|
4470
4519
|
declare const createPolicyDecorator: <T extends Record<string, PolicyProvider>>(manager: PolicyManager<T>) => PolicyDecorator<T>;
|
|
4471
4520
|
|
|
4472
4521
|
/**
|
|
@@ -4656,4 +4705,4 @@ declare enum CacheStatus {
|
|
|
4656
4705
|
*/
|
|
4657
4706
|
declare const router: ClientRouter;
|
|
4658
4707
|
|
|
4659
|
-
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, PolicyManager, type PolicyProvider, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
|
|
4708
|
+
export { type AsyncLocalStorageContextSetters, AzureBlobStorageProvider, BaseCron, BasePlugin, type BaseStorageProviderOptions, type BlobStorageProviderOptions, BullMQConfiguration, type BullMQConfigurationOptions, BullMQPubSub, CACHE_STATUS_HEADER, type CacheKeyIncludes, type CacheMiddlewareOptions, type CachePluginOptions, type CacheProvider, type CacheRedisOptions, type CacheRouteConfig, CacheService, type CacheServiceInterface, type CacheStats, CacheStatus, Command, type CommandOptions, CommandRegistry, type CompressionOptions, type CookieMiddlewareOptions, type CorsOptions, type CronSchedule, type CronScheduleParams, CronService, type CronUIOptions, CustomAdapter, type CustomQueueConfiguration, type CustomStorageProviderOptions, CustomTypedQueue, type CustomValidationError, DEFAULT_CACHE_OPTIONS, EdgeAdapter, EjsAdapter, type ExtractParams, GraphQL, type GraphQLContext, type GraphQLOptions, type GraphQLResolverFunction, type GraphQLResolverMap, type GraphQLResolverType, type GraphQLResolvers, type GraphQLSchemaInput, type GraphQLTypeDef, type GroupRouter, HandlebarsAdapter, type HelmetOptions, type HttpMethod, type HttpsOptions, type InferMiddlewareExtension, type InferMiddlewareExtensions, type InferResponseMap, type InferSchemaType, LocalStorageProvider, type LocalStorageProviderOptions, type LockBehavior, type LogOptions, type LoggerOptions, type MailOptions, MailOptionsBuilder, MailProvider, type MailProviderInterface, Mailer, type MailerInterface, type MailerOptions, type MailerProviderOptions, MemoryCacheProvider, MemoryPubSub, type MethodOverrideOptions, MockResponse, MockServer, type MockServerOptions, type MqttConnectionOptions, type MqttHandler, type MqttPublishOptions, MqttService, type MqttSubscribeOptions, type MqttSubscription, type MqttTopics, MustacheAdapter, type NextFunction, type NodeHttpClient, type NodeServer as NodeHttpServerClient, PGBossConfiguration, type PGBossConfigurationOptions, PGBossPubSub, type PolicyDecorator, type PolicyErrorHandler, PolicyManager, type PolicyProvider, type PolicyRouteConfig, type PublishTopic, QueueManager, QueueService, type RateLimiterKeyOptions, RedisCacheProvider, Request, type RequestSchema, Response$1 as Response, type ResponseBodyForStatus, type RuntimeServer, S3StorageProvider, type S3StorageProviderOptions, SQSConfiguration, type SQSConfigurationOptions, SQSPubSub, type CacheMetrics as SchemaCacheMetrics, type SerializeOptions, Server, type ServerConnectInput, type ServerErrorHandler, type ServerHook, type ServerInterface, type ServerListenCallback, type ServerOptions, type ServerRouteHandler, type ServerRouteMiddleware, type ServerTapOptions, type SessionOptions, type SignalEvent, type StaticPluginOptions, Storage, type StorageInterface, type StorageOptions, type StorageProviderOptions, type TemplateMailOptions, type TimeoutOptions, type TrustProxyOptions, type TypedCacheKeyIncludes, type TypedCacheRouteConfig, type TypedHandler, type TypedMiddleware, TypedQueue, type TypedRouteMetadata, type ValidatedData, type ValidationErrorHandler, type ValidationOptions, arg, asyncLocalStorage, asyncStorage, bullmqQueue, cache, cacheMiddleware, clearAllCaches as clearAllSchemaCaches, commandRegistry, compression, controller, cookie, cors, createExpressAdapter, createPolicyDecorator, createQueue, cron, cronUIInstance, cronUi, Server as default, defineMiddleware, defineQueueConfiguration, del, expressHandler, expressMiddleware, flag, get, getCacheService, getCacheMetrics as getSchemaCacheMetrics, hash, helmet, initCacheService, log, logCacheMetrics as logSchemaCacheMetrics, logger, memoryQueue, methodOverride, middleware, mountExpressRouter, mqtt, patch, pgbossQueue, post, put, rateLimiter, resetCacheService, router, serialize, serveStatic, session, setCronGlobalErrorHandler, setMqttGlobalErrorHandler, sqsQueue, timeout as timeoutMw, trustProxy, validate };
|