shokupan 0.6.0 → 0.7.0
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/README.md +4 -2
- package/dist/{openapi-analyzer-Bei1sVWp.cjs → analyzer-Bei1sVWp.cjs} +1 -1
- package/dist/analyzer-Bei1sVWp.cjs.map +1 -0
- package/dist/{openapi-analyzer-Ce_7JxZh.js → analyzer-Ce_7JxZh.js} +1 -1
- package/dist/analyzer-Ce_7JxZh.js.map +1 -0
- package/dist/cli.cjs +2 -2
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/context.d.ts +72 -11
- package/dist/{server-adapter-0xH174zz.js → http-server-0xH174zz.js} +1 -1
- package/dist/http-server-0xH174zz.js.map +1 -0
- package/dist/{server-adapter-DFhwlK8e.cjs → http-server-DFhwlK8e.cjs} +1 -1
- package/dist/http-server-DFhwlK8e.cjs.map +1 -0
- package/dist/index.cjs +1022 -801
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -17
- package/dist/index.js +1022 -800
- package/dist/index.js.map +1 -1
- package/dist/middleware.d.ts +1 -1
- package/dist/plugins/{auth.d.ts → application/auth.d.ts} +72 -3
- package/dist/plugins/application/cluster.d.ts +33 -0
- package/dist/plugins/{failed-request-recorder.d.ts → application/dashboard/failed-request-recorder.d.ts} +1 -1
- package/dist/plugins/{debugview → application/dashboard}/plugin.d.ts +13 -6
- package/dist/plugins/{server-adapter.d.ts → application/http-server.d.ts} +1 -1
- package/dist/plugins/{idempotency → application/idempotency}/plugin.d.ts +7 -1
- package/dist/plugins/{openapi.d.ts → application/openapi/openapi.d.ts} +2 -2
- package/dist/plugins/application/scalar.d.ts +36 -0
- package/dist/plugins/middleware/compression.d.ts +17 -0
- package/dist/plugins/middleware/cors.d.ts +34 -0
- package/dist/plugins/{express.d.ts → middleware/express.d.ts} +1 -1
- package/dist/plugins/{openapi-validator.d.ts → middleware/openapi-validator.d.ts} +2 -2
- package/dist/plugins/middleware/proxy.d.ts +37 -0
- package/dist/plugins/middleware/rate-limit.d.ts +58 -0
- package/dist/plugins/{security-headers.d.ts → middleware/security-headers.d.ts} +51 -1
- package/dist/plugins/{serve-static.d.ts → middleware/serve-static.d.ts} +1 -1
- package/dist/plugins/{session.d.ts → middleware/session.d.ts} +89 -3
- package/dist/plugins/{validation.d.ts → middleware/validation.d.ts} +6 -1
- package/dist/router.d.ts +99 -40
- package/dist/shokupan.d.ts +74 -4
- package/dist/util/async-hooks.d.ts +8 -2
- package/dist/{decorators.d.ts → util/decorators.d.ts} +1 -1
- package/dist/util/http-status.d.ts +2 -0
- package/dist/util/instrumentation.d.ts +1 -1
- package/dist/{router → util}/trie.d.ts +1 -1
- package/dist/{types.d.ts → util/types.d.ts} +41 -2
- package/package.json +5 -5
- package/dist/openapi-analyzer-Bei1sVWp.cjs.map +0 -1
- package/dist/openapi-analyzer-Ce_7JxZh.js.map +0 -1
- package/dist/plugins/compression.d.ts +0 -5
- package/dist/plugins/cors.d.ts +0 -11
- package/dist/plugins/proxy.d.ts +0 -9
- package/dist/plugins/rate-limit.d.ts +0 -14
- package/dist/plugins/scalar.d.ts +0 -15
- package/dist/server-adapter-0xH174zz.js.map +0 -1
- package/dist/server-adapter-DFhwlK8e.cjs.map +0 -1
- /package/dist/{analysis/openapi-analyzer.d.ts → plugins/application/openapi/analyzer.d.ts} +0 -0
- /package/dist/{di.d.ts → util/di.d.ts} +0 -0
- /package/dist/{request.d.ts → util/request.d.ts} +0 -0
- /package/dist/{response.d.ts → util/response.d.ts} +0 -0
- /package/dist/{symbol.d.ts → util/symbol.d.ts} +0 -0
package/dist/middleware.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { ShokupanContext } from '
|
|
2
|
-
import { ShokupanRouter } from '
|
|
1
|
+
import { ShokupanContext } from '../../context';
|
|
2
|
+
import { ShokupanRouter } from '../../router';
|
|
3
|
+
import { Shokupan } from '../../shokupan';
|
|
4
|
+
import { ShokupanPlugin, ShokupanPluginOptions } from '../../util/types';
|
|
3
5
|
export interface AuthUser {
|
|
4
6
|
id: string;
|
|
5
7
|
email?: string;
|
|
@@ -9,29 +11,92 @@ export interface AuthUser {
|
|
|
9
11
|
raw?: any;
|
|
10
12
|
}
|
|
11
13
|
export interface ProviderConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Client ID
|
|
16
|
+
*/
|
|
12
17
|
clientId: string;
|
|
18
|
+
/**
|
|
19
|
+
* Client secret
|
|
20
|
+
*/
|
|
13
21
|
clientSecret: string;
|
|
22
|
+
/**
|
|
23
|
+
* Redirect URI
|
|
24
|
+
*/
|
|
14
25
|
redirectUri: string;
|
|
26
|
+
/**
|
|
27
|
+
* Scopes
|
|
28
|
+
*/
|
|
15
29
|
scopes?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Tenant ID (MSFT AD)
|
|
32
|
+
*/
|
|
16
33
|
tenantId?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Domain (Auth0, Okta)
|
|
36
|
+
*/
|
|
17
37
|
domain?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Team ID (Apple)
|
|
40
|
+
*/
|
|
18
41
|
teamId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Key ID (Apple)
|
|
44
|
+
*/
|
|
19
45
|
keyId?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Auth URL (Generic OAuth2)
|
|
48
|
+
*/
|
|
20
49
|
authUrl?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Token URL (Generic OAuth2)
|
|
52
|
+
*/
|
|
21
53
|
tokenUrl?: string;
|
|
54
|
+
/**
|
|
55
|
+
* User info URL (Generic OAuth2)
|
|
56
|
+
*/
|
|
22
57
|
userInfoUrl?: string;
|
|
23
58
|
}
|
|
24
59
|
export interface AuthConfig {
|
|
60
|
+
/**
|
|
61
|
+
* JWT secret
|
|
62
|
+
*/
|
|
25
63
|
jwtSecret: string | Uint8Array;
|
|
64
|
+
/**
|
|
65
|
+
* JWT expiration
|
|
66
|
+
*/
|
|
26
67
|
jwtExpiration?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Cookie options
|
|
70
|
+
*/
|
|
27
71
|
cookieOptions?: {
|
|
72
|
+
/**
|
|
73
|
+
* HTTP only
|
|
74
|
+
*/
|
|
28
75
|
httpOnly?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Secure
|
|
78
|
+
*/
|
|
29
79
|
secure?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Same site
|
|
82
|
+
*/
|
|
30
83
|
sameSite?: "Strict" | "Lax" | "None";
|
|
84
|
+
/**
|
|
85
|
+
* Path
|
|
86
|
+
*/
|
|
31
87
|
path?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Max age
|
|
90
|
+
*/
|
|
32
91
|
maxAge?: number;
|
|
33
92
|
};
|
|
93
|
+
/**
|
|
94
|
+
* Success callback
|
|
95
|
+
*/
|
|
34
96
|
onSuccess?: (user: AuthUser, ctx: ShokupanContext) => Promise<any> | any;
|
|
97
|
+
/**
|
|
98
|
+
* Providers
|
|
99
|
+
*/
|
|
35
100
|
providers: {
|
|
36
101
|
github?: ProviderConfig;
|
|
37
102
|
google?: ProviderConfig;
|
|
@@ -43,10 +108,14 @@ export interface AuthConfig {
|
|
|
43
108
|
[key: string]: ProviderConfig | undefined;
|
|
44
109
|
};
|
|
45
110
|
}
|
|
46
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Authentication plugin
|
|
113
|
+
*/
|
|
114
|
+
export declare class AuthPlugin extends ShokupanRouter<any> implements ShokupanPlugin {
|
|
47
115
|
private authConfig;
|
|
48
116
|
private secret;
|
|
49
117
|
constructor(authConfig: AuthConfig);
|
|
118
|
+
onInit(app: Shokupan, options?: ShokupanPluginOptions): void;
|
|
50
119
|
private getProviderInstance;
|
|
51
120
|
private createSession;
|
|
52
121
|
private init;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Shokupan } from '../../shokupan';
|
|
2
|
+
import { ShokupanPlugin } from '../../util/types';
|
|
3
|
+
export interface ClusterOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Number of workers to spawn.
|
|
6
|
+
* Set to -1 or 'auto' to spawn one worker per available CPU.
|
|
7
|
+
* @default 'auto'
|
|
8
|
+
*/
|
|
9
|
+
workers?: number | 'auto';
|
|
10
|
+
/**
|
|
11
|
+
* Whether to pipe stdout/stderr to the parent process.
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
silent?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Enable sticky sessions (useful for Socket.io).
|
|
17
|
+
* Currently only supported in Node.js runtime.
|
|
18
|
+
* @default false
|
|
19
|
+
*/
|
|
20
|
+
sticky?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Cluster Plugin
|
|
24
|
+
*
|
|
25
|
+
* Automatically manages clustering for Node.js and Bun.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ClusterPlugin implements ShokupanPlugin {
|
|
28
|
+
private options;
|
|
29
|
+
constructor(options?: ClusterOptions);
|
|
30
|
+
onInit(app: Shokupan): void;
|
|
31
|
+
private handleBun;
|
|
32
|
+
private handleNode;
|
|
33
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ShokupanContext } from '../../../context';
|
|
2
|
+
import { ShokupanRouter } from '../../../router';
|
|
3
|
+
import { ShokupanHooks } from '../../../util/types';
|
|
3
4
|
export interface RequestLog {
|
|
4
5
|
method: string;
|
|
5
6
|
url: string;
|
|
@@ -8,17 +9,23 @@ export interface RequestLog {
|
|
|
8
9
|
timestamp: number;
|
|
9
10
|
handlerStack?: any[];
|
|
10
11
|
}
|
|
11
|
-
export interface
|
|
12
|
-
|
|
12
|
+
export interface DashboardConfig {
|
|
13
|
+
/**
|
|
14
|
+
* Function to get request headers to include in the debug dashboard
|
|
15
|
+
*/
|
|
16
|
+
getHeaders?: (ctx: ShokupanContext) => Record<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Retention time in milliseconds
|
|
19
|
+
*/
|
|
13
20
|
retentionMs?: number;
|
|
14
21
|
}
|
|
15
|
-
export declare class
|
|
22
|
+
export declare class Dashboard extends ShokupanRouter {
|
|
16
23
|
private readonly dashboardConfig;
|
|
17
24
|
private metrics;
|
|
18
25
|
private eta;
|
|
19
26
|
private startTime;
|
|
20
27
|
private instrumented;
|
|
21
|
-
constructor(dashboardConfig?:
|
|
28
|
+
constructor(dashboardConfig?: DashboardConfig);
|
|
22
29
|
private instrumentApp;
|
|
23
30
|
private assignIdsToRegistry;
|
|
24
31
|
recordNodeMetric(id: string, type: string, duration: number, isError: boolean): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Middleware } from '
|
|
1
|
+
import { Middleware } from '../../../util/types';
|
|
2
2
|
export interface IdempotencyOptions {
|
|
3
3
|
/**
|
|
4
4
|
* Header name to use for the idempotency key.
|
|
@@ -11,4 +11,10 @@ export interface IdempotencyOptions {
|
|
|
11
11
|
*/
|
|
12
12
|
ttl?: number;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Idempotency middleware. This middleware will cache responses based on the idempotency key
|
|
16
|
+
* to prevent duplicate server processing of requests.
|
|
17
|
+
* @param options Idempotency options
|
|
18
|
+
* @returns Middleware
|
|
19
|
+
*/
|
|
14
20
|
export declare function Idempotency(options?: IdempotencyOptions): Middleware;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ShokupanRouter } from '
|
|
2
|
-
import { OpenAPIOptions } from '
|
|
1
|
+
import { ShokupanRouter } from '../../../router';
|
|
2
|
+
import { OpenAPIOptions } from '../../../util/types';
|
|
3
3
|
/**
|
|
4
4
|
* Statically generate an OpenAPI spec from a ShokupanRouter instance.
|
|
5
5
|
*
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ApiReferenceConfiguration } from '@scalar/api-reference';
|
|
2
|
+
import { OpenAPI } from '@scalar/openapi-types';
|
|
3
|
+
import { ShokupanRouter } from '../../router';
|
|
4
|
+
import { Shokupan } from '../../shokupan';
|
|
5
|
+
import { DeepPartial, ShokupanPlugin, ShokupanPluginOptions } from '../../util/types';
|
|
6
|
+
export type ScalarPluginOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Base document to use for API reference.
|
|
9
|
+
*/
|
|
10
|
+
baseDocument?: DeepPartial<OpenAPI.Document>;
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for API reference.
|
|
13
|
+
*/
|
|
14
|
+
config?: Partial<ApiReferenceConfiguration>;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to enable static analysis.
|
|
17
|
+
* When this is enabled, the plugin will run static analysis on the entrypoint
|
|
18
|
+
* and generate an OpenAPI document. This is useful for when you want to generate
|
|
19
|
+
* an OpenAPI document without having to manually define it.
|
|
20
|
+
*
|
|
21
|
+
* Only works with TypeScript entrypoints.
|
|
22
|
+
*/
|
|
23
|
+
enableStaticAnalysis?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Scalar plugin. This plugin provides an API reference interface for your API.
|
|
27
|
+
* @param options Scalar plugin options
|
|
28
|
+
* @returns Scalar plugin instance
|
|
29
|
+
*/
|
|
30
|
+
export declare class ScalarPlugin extends ShokupanRouter<any> implements ShokupanPlugin {
|
|
31
|
+
private readonly pluginOptions;
|
|
32
|
+
constructor(pluginOptions?: ScalarPluginOptions);
|
|
33
|
+
onInit(app: Shokupan, options?: ShokupanPluginOptions): void;
|
|
34
|
+
private init;
|
|
35
|
+
onMount(parent: ShokupanRouter<any>): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Middleware } from '../../util/types';
|
|
2
|
+
export interface CompressionOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Minimum byte size to compress
|
|
5
|
+
*/
|
|
6
|
+
threshold?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Allowed algorithms
|
|
9
|
+
*/
|
|
10
|
+
allowedAlgorithms?: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Compression middleware.
|
|
14
|
+
* @param options Compression options
|
|
15
|
+
* @returns Middleware function
|
|
16
|
+
*/
|
|
17
|
+
export declare function Compression(options?: CompressionOptions): Middleware;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { ShokupanContext } from '../../context';
|
|
2
|
+
import { Middleware } from '../../util/types';
|
|
3
|
+
export interface CorsOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Origin to allow. Can be a string, array of strings, or function that returns a string.
|
|
6
|
+
*/
|
|
7
|
+
origin?: string | string[] | ((ctx: ShokupanContext) => string | undefined | null | boolean);
|
|
8
|
+
/**
|
|
9
|
+
* HTTP methods to allow.
|
|
10
|
+
*/
|
|
11
|
+
methods?: string | string[];
|
|
12
|
+
/**
|
|
13
|
+
* HTTP headers to allow.
|
|
14
|
+
*/
|
|
15
|
+
allowedHeaders?: string | string[];
|
|
16
|
+
/**
|
|
17
|
+
* HTTP headers to expose.
|
|
18
|
+
*/
|
|
19
|
+
exposedHeaders?: string | string[];
|
|
20
|
+
/**
|
|
21
|
+
* Whether to allow credentials.
|
|
22
|
+
*/
|
|
23
|
+
credentials?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Maximum age of preflight request.
|
|
26
|
+
*/
|
|
27
|
+
maxAge?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* CORS middleware.
|
|
31
|
+
* @param options CORS options
|
|
32
|
+
* @returns Middleware function
|
|
33
|
+
*/
|
|
34
|
+
export declare function Cors(options?: CorsOptions): Middleware;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Middleware } from '
|
|
1
|
+
import { Middleware } from '../../util/types';
|
|
2
2
|
type ValidatorCache = Map<string, {
|
|
3
3
|
[method: string]: {
|
|
4
4
|
body?: import('ajv').ValidateFunction;
|
|
@@ -26,5 +26,5 @@ export declare function precompileValidators(app: any, spec: any): void;
|
|
|
26
26
|
*
|
|
27
27
|
* @param app The Shokupan application instance
|
|
28
28
|
*/
|
|
29
|
-
export declare function enableOpenApiValidation(app: import('
|
|
29
|
+
export declare function enableOpenApiValidation(app: import('../../shokupan').Shokupan): void;
|
|
30
30
|
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Middleware } from '../../util/types';
|
|
2
|
+
export interface ProxyOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Target URL to proxy requests to.
|
|
5
|
+
*/
|
|
6
|
+
target: string;
|
|
7
|
+
/**
|
|
8
|
+
* Function to rewrite the path of the request.
|
|
9
|
+
*/
|
|
10
|
+
pathRewrite?: (path: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to change the origin of the request.
|
|
13
|
+
*/
|
|
14
|
+
changeOrigin?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to proxy WebSocket connections.
|
|
17
|
+
*/
|
|
18
|
+
ws?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Additional headers to send with the request.
|
|
21
|
+
*/
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Whitelist of allowed target hosts.
|
|
25
|
+
*/
|
|
26
|
+
allowedHosts?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Whether to allow private IPs (disabled by default).
|
|
29
|
+
*/
|
|
30
|
+
allowPrivateIPs?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Proxy middleware. This will proxy requests that match the path to the target URL.
|
|
34
|
+
* @param options Proxy options
|
|
35
|
+
* @returns Middleware function
|
|
36
|
+
*/
|
|
37
|
+
export declare function Proxy(options: ProxyOptions): Middleware;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ShokupanContext } from '../../context';
|
|
2
|
+
import { Middleware } from '../../util/types';
|
|
3
|
+
export interface RateLimitOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Window in milliseconds
|
|
6
|
+
*/
|
|
7
|
+
windowMs?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Maximum number of requests allowed in the window
|
|
10
|
+
*/
|
|
11
|
+
max?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Alias for max
|
|
14
|
+
*/
|
|
15
|
+
limit?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Message to send when rate limited
|
|
18
|
+
*/
|
|
19
|
+
message?: string | object | ((ctx: ShokupanContext, key: string) => string | object);
|
|
20
|
+
/**
|
|
21
|
+
* Status code to send when rate limited
|
|
22
|
+
*/
|
|
23
|
+
statusCode?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to include X-RateLimit headers in the response
|
|
26
|
+
*/
|
|
27
|
+
headers?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Function to generate a unique key for each request
|
|
30
|
+
* This is used to identify the user or source of the request
|
|
31
|
+
* Defaults to the request's ip address.
|
|
32
|
+
*/
|
|
33
|
+
keyGenerator?: (ctx: ShokupanContext) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Function to execute when a request is rate limited
|
|
36
|
+
*/
|
|
37
|
+
onRateLimited?: (ctx: ShokupanContext, key: string) => void | Response | Promise<void | Response>;
|
|
38
|
+
/**
|
|
39
|
+
* Function to determine whether to skip rate limiting
|
|
40
|
+
*/
|
|
41
|
+
skip?: (ctx: ShokupanContext) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Mode to use for rate limiting
|
|
44
|
+
* - user: Rate limit per user (generated key, defaults to ip address)
|
|
45
|
+
* - absolute: Rate limit for all users
|
|
46
|
+
*/
|
|
47
|
+
mode?: 'user' | 'absolute';
|
|
48
|
+
/**
|
|
49
|
+
* List of trusted proxy IPs
|
|
50
|
+
*/
|
|
51
|
+
trustedProxies?: string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Rate limit middleware.
|
|
55
|
+
* @param options Rate limit options
|
|
56
|
+
* @returns Middleware function
|
|
57
|
+
*/
|
|
58
|
+
export declare function RateLimitMiddleware(options?: RateLimitOptions): Middleware;
|
|
@@ -1,36 +1,86 @@
|
|
|
1
|
-
import { Middleware } from '
|
|
1
|
+
import { Middleware } from '../../util/types';
|
|
2
2
|
export interface SecurityHeadersOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Content Security Policy
|
|
5
|
+
*/
|
|
3
6
|
contentSecurityPolicy?: boolean | Record<string, any>;
|
|
7
|
+
/**
|
|
8
|
+
* Cross-Origin Embedder Policy
|
|
9
|
+
*/
|
|
4
10
|
crossOriginEmbedderPolicy?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Cross-Origin Opener Policy
|
|
13
|
+
*/
|
|
5
14
|
crossOriginOpenerPolicy?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Cross-Origin Resource Policy
|
|
17
|
+
*/
|
|
6
18
|
crossOriginResourcePolicy?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* DNS Prefetch Control
|
|
21
|
+
*/
|
|
7
22
|
dnsPrefetchControl?: boolean | {
|
|
8
23
|
allow: boolean;
|
|
9
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Expect CT
|
|
27
|
+
*/
|
|
10
28
|
expectCt?: boolean | {
|
|
11
29
|
maxAge?: number;
|
|
12
30
|
enforce?: boolean;
|
|
13
31
|
reportUri?: string;
|
|
14
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Frameguard
|
|
35
|
+
*/
|
|
15
36
|
frameguard?: boolean | {
|
|
16
37
|
action: 'deny' | 'sameorigin' | 'allow-from';
|
|
17
38
|
domain?: string;
|
|
18
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Hide Powered By
|
|
42
|
+
*/
|
|
19
43
|
hidePoweredBy?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* HTTP Strict Transport Security
|
|
46
|
+
*/
|
|
20
47
|
hsts?: boolean | {
|
|
21
48
|
maxAge?: number;
|
|
22
49
|
includeSubDomains?: boolean;
|
|
23
50
|
preload?: boolean;
|
|
24
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* IE No Open
|
|
54
|
+
*/
|
|
25
55
|
ieNoOpen?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* No Sniff
|
|
58
|
+
*/
|
|
26
59
|
noSniff?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Origin Agent Cluster
|
|
62
|
+
*/
|
|
27
63
|
originAgentCluster?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Permitted Cross Domain Policies
|
|
66
|
+
*/
|
|
28
67
|
permittedCrossDomainPolicies?: boolean | {
|
|
29
68
|
permittedPolicies: 'none' | 'master-only' | 'by-content-type' | 'all';
|
|
30
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Referrer Policy
|
|
72
|
+
*/
|
|
31
73
|
referrerPolicy?: boolean | {
|
|
32
74
|
policy: string | string[];
|
|
33
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* X-XSS-Protection
|
|
78
|
+
*/
|
|
34
79
|
xssFilter?: boolean;
|
|
35
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Security headers middleware.
|
|
83
|
+
* @param options Security headers options
|
|
84
|
+
* @returns Middleware function
|
|
85
|
+
*/
|
|
36
86
|
export declare function SecurityHeaders(options?: SecurityHeadersOptions): Middleware;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Middleware, StaticServeOptions } from '
|
|
1
|
+
import { Middleware, StaticServeOptions } from '../../util/types';
|
|
2
2
|
export declare function serveStatic<T extends Record<string, any>>(config: StaticServeOptions<T>, prefix: string): Middleware;
|
|
@@ -1,43 +1,124 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import { ShokupanContext } from '
|
|
3
|
-
import { Middleware } from '
|
|
2
|
+
import { ShokupanContext } from '../../context';
|
|
3
|
+
import { Middleware } from '../../util/types';
|
|
4
4
|
export interface SessionData {
|
|
5
5
|
cookie: Cookie;
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}
|
|
8
8
|
export interface SessionCookieOptions {
|
|
9
|
+
/**
|
|
10
|
+
* Maximum age of the session cookie in milliseconds.
|
|
11
|
+
*/
|
|
9
12
|
maxAge?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the session cookie should be signed.
|
|
15
|
+
*/
|
|
10
16
|
signed?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Expiration date of the session cookie.
|
|
19
|
+
*/
|
|
11
20
|
expires?: Date;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the session cookie should be HTTP-only.
|
|
23
|
+
*/
|
|
12
24
|
httpOnly?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Path of the session cookie.
|
|
27
|
+
*/
|
|
13
28
|
path?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Domain of the session cookie.
|
|
31
|
+
*/
|
|
14
32
|
domain?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Whether the session cookie should be secure.
|
|
35
|
+
*/
|
|
15
36
|
secure?: boolean | 'auto';
|
|
37
|
+
/**
|
|
38
|
+
* SameSite attribute of the session cookie.
|
|
39
|
+
*/
|
|
16
40
|
sameSite?: boolean | 'lax' | 'strict' | 'none';
|
|
41
|
+
/**
|
|
42
|
+
* Priority of the session cookie.
|
|
43
|
+
*/
|
|
17
44
|
priority?: 'low' | 'medium' | 'high';
|
|
18
45
|
}
|
|
19
46
|
export interface SessionOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Secret used to sign the session cookie.
|
|
49
|
+
*/
|
|
20
50
|
secret: string | string[];
|
|
51
|
+
/**
|
|
52
|
+
* Name of the session cookie.
|
|
53
|
+
*/
|
|
21
54
|
name?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Store to use for session data.
|
|
57
|
+
*/
|
|
22
58
|
store?: Store;
|
|
59
|
+
/**
|
|
60
|
+
* Options for the session cookie.
|
|
61
|
+
*/
|
|
23
62
|
cookie?: SessionCookieOptions;
|
|
63
|
+
/**
|
|
64
|
+
* Function to generate a session ID.
|
|
65
|
+
*/
|
|
24
66
|
genid?: (ctx: ShokupanContext) => string;
|
|
67
|
+
/**
|
|
68
|
+
* Whether to force a session identifier cookie to be set on every response.
|
|
69
|
+
*/
|
|
25
70
|
resave?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Whether to save the session on every request.
|
|
73
|
+
*/
|
|
26
74
|
saveUninitialized?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to update the session cookie on every request.
|
|
77
|
+
*/
|
|
27
78
|
rolling?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Whether to destroy or keep the session on logout.
|
|
81
|
+
*/
|
|
28
82
|
unset?: 'destroy' | 'keep';
|
|
29
83
|
}
|
|
30
84
|
export interface Store extends EventEmitter {
|
|
85
|
+
/**
|
|
86
|
+
* Retrieves a session by ID.
|
|
87
|
+
*/
|
|
31
88
|
get(sid: string, callback: (err: any, session?: SessionData | null) => void): void;
|
|
89
|
+
/**
|
|
90
|
+
* Stores a session.
|
|
91
|
+
*/
|
|
32
92
|
set(sid: string, session: SessionData, callback?: (err?: any) => void): void;
|
|
93
|
+
/**
|
|
94
|
+
* Destroys a session.
|
|
95
|
+
*/
|
|
33
96
|
destroy(sid: string, callback?: (err?: any) => void): void;
|
|
97
|
+
/**
|
|
98
|
+
* Touches a session.
|
|
99
|
+
*/
|
|
34
100
|
touch?(sid: string, session: SessionData, callback?: (err?: any) => void): void;
|
|
101
|
+
/**
|
|
102
|
+
* Retrieves all sessions.
|
|
103
|
+
*/
|
|
35
104
|
all?(callback: (err: any, obj?: {
|
|
36
105
|
[sid: string]: SessionData;
|
|
37
106
|
} | null) => void): void;
|
|
107
|
+
/**
|
|
108
|
+
* Retrieves the number of sessions.
|
|
109
|
+
*/
|
|
38
110
|
length?(callback: (err: any, length?: number) => void): void;
|
|
111
|
+
/**
|
|
112
|
+
* Clears all sessions.
|
|
113
|
+
*/
|
|
39
114
|
clear?(callback?: (err?: any) => void): void;
|
|
115
|
+
/**
|
|
116
|
+
* Loads a session.
|
|
117
|
+
*/
|
|
40
118
|
load?(sid: string, fn: (err: any, session?: SessionData | null) => void): void;
|
|
119
|
+
/**
|
|
120
|
+
* Creates a session.
|
|
121
|
+
*/
|
|
41
122
|
createSession?(req: any, session: SessionData): SessionData;
|
|
42
123
|
}
|
|
43
124
|
declare class Cookie implements SessionCookieOptions {
|
|
@@ -76,12 +157,17 @@ export interface SessionContext {
|
|
|
76
157
|
sessionID: string;
|
|
77
158
|
sessionStore: Store;
|
|
78
159
|
}
|
|
79
|
-
declare module "
|
|
160
|
+
declare module "../../context" {
|
|
80
161
|
interface ShokupanContext {
|
|
81
162
|
session: SessionContext['session'];
|
|
82
163
|
sessionID: string;
|
|
83
164
|
sessionStore: Store;
|
|
84
165
|
}
|
|
85
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Session middleware.
|
|
169
|
+
* @param options Session options
|
|
170
|
+
* @returns Middleware function
|
|
171
|
+
*/
|
|
86
172
|
export declare function Session(options: SessionOptions): Middleware;
|
|
87
173
|
export {};
|