alepha 0.13.0 → 0.13.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.
Files changed (195) hide show
  1. package/dist/api-jobs/index.d.ts +26 -26
  2. package/dist/api-users/index.d.ts +1 -1
  3. package/dist/cli/{dist-Sz2EXvQX.cjs → dist-Dl9Vl7Ur.js} +17 -13
  4. package/dist/cli/{dist-BBPjuQ56.js.map → dist-Dl9Vl7Ur.js.map} +1 -1
  5. package/dist/cli/index.d.ts +3 -11
  6. package/dist/cli/index.js +106 -74
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/email/index.js +71 -73
  9. package/dist/email/index.js.map +1 -1
  10. package/dist/orm/index.d.ts +1 -1
  11. package/dist/orm/index.js.map +1 -1
  12. package/dist/queue/index.d.ts +4 -4
  13. package/dist/retry/index.d.ts +1 -1
  14. package/dist/retry/index.js +2 -2
  15. package/dist/retry/index.js.map +1 -1
  16. package/dist/scheduler/index.d.ts +6 -6
  17. package/dist/security/index.d.ts +28 -28
  18. package/dist/server/index.js +1 -1
  19. package/dist/server/index.js.map +1 -1
  20. package/dist/server-health/index.d.ts +17 -17
  21. package/dist/server-metrics/index.js +170 -174
  22. package/dist/server-metrics/index.js.map +1 -1
  23. package/dist/server-security/index.d.ts +9 -9
  24. package/dist/vite/index.js +4 -5
  25. package/dist/vite/index.js.map +1 -1
  26. package/dist/websocket/index.d.ts +7 -7
  27. package/package.json +52 -103
  28. package/src/cli/apps/AlephaPackageBuilderCli.ts +7 -2
  29. package/src/cli/assets/appRouterTs.ts +9 -0
  30. package/src/cli/assets/indexHtml.ts +2 -1
  31. package/src/cli/assets/mainBrowserTs.ts +10 -0
  32. package/src/cli/commands/CoreCommands.ts +6 -5
  33. package/src/cli/commands/DrizzleCommands.ts +65 -57
  34. package/src/cli/commands/VerifyCommands.ts +1 -1
  35. package/src/cli/services/ProjectUtils.ts +44 -38
  36. package/src/orm/providers/DrizzleKitProvider.ts +1 -1
  37. package/src/retry/descriptors/$retry.ts +5 -3
  38. package/src/server/providers/NodeHttpServerProvider.ts +1 -1
  39. package/src/vite/helpers/boot.ts +3 -3
  40. package/dist/api-files/index.cjs +0 -1293
  41. package/dist/api-files/index.cjs.map +0 -1
  42. package/dist/api-files/index.d.cts +0 -829
  43. package/dist/api-jobs/index.cjs +0 -274
  44. package/dist/api-jobs/index.cjs.map +0 -1
  45. package/dist/api-jobs/index.d.cts +0 -654
  46. package/dist/api-notifications/index.cjs +0 -380
  47. package/dist/api-notifications/index.cjs.map +0 -1
  48. package/dist/api-notifications/index.d.cts +0 -289
  49. package/dist/api-parameters/index.cjs +0 -66
  50. package/dist/api-parameters/index.cjs.map +0 -1
  51. package/dist/api-parameters/index.d.cts +0 -84
  52. package/dist/api-users/index.cjs +0 -6009
  53. package/dist/api-users/index.cjs.map +0 -1
  54. package/dist/api-users/index.d.cts +0 -4740
  55. package/dist/api-verifications/index.cjs +0 -407
  56. package/dist/api-verifications/index.cjs.map +0 -1
  57. package/dist/api-verifications/index.d.cts +0 -207
  58. package/dist/batch/index.cjs +0 -408
  59. package/dist/batch/index.cjs.map +0 -1
  60. package/dist/batch/index.d.cts +0 -330
  61. package/dist/bin/index.cjs +0 -17
  62. package/dist/bin/index.cjs.map +0 -1
  63. package/dist/bin/index.d.cts +0 -1
  64. package/dist/bucket/index.cjs +0 -303
  65. package/dist/bucket/index.cjs.map +0 -1
  66. package/dist/bucket/index.d.cts +0 -355
  67. package/dist/cache/index.cjs +0 -241
  68. package/dist/cache/index.cjs.map +0 -1
  69. package/dist/cache/index.d.cts +0 -202
  70. package/dist/cache-redis/index.cjs +0 -84
  71. package/dist/cache-redis/index.cjs.map +0 -1
  72. package/dist/cache-redis/index.d.cts +0 -40
  73. package/dist/cli/chunk-DSlc6foC.cjs +0 -43
  74. package/dist/cli/dist-BBPjuQ56.js +0 -2778
  75. package/dist/cli/dist-Sz2EXvQX.cjs.map +0 -1
  76. package/dist/cli/index.cjs +0 -1241
  77. package/dist/cli/index.cjs.map +0 -1
  78. package/dist/cli/index.d.cts +0 -422
  79. package/dist/command/index.cjs +0 -693
  80. package/dist/command/index.cjs.map +0 -1
  81. package/dist/command/index.d.cts +0 -340
  82. package/dist/core/index.cjs +0 -2264
  83. package/dist/core/index.cjs.map +0 -1
  84. package/dist/core/index.d.cts +0 -1927
  85. package/dist/datetime/index.cjs +0 -318
  86. package/dist/datetime/index.cjs.map +0 -1
  87. package/dist/datetime/index.d.cts +0 -145
  88. package/dist/email/index.cjs +0 -10874
  89. package/dist/email/index.cjs.map +0 -1
  90. package/dist/email/index.d.cts +0 -186
  91. package/dist/fake/index.cjs +0 -34641
  92. package/dist/fake/index.cjs.map +0 -1
  93. package/dist/fake/index.d.cts +0 -74
  94. package/dist/file/index.cjs +0 -1212
  95. package/dist/file/index.cjs.map +0 -1
  96. package/dist/file/index.d.cts +0 -698
  97. package/dist/lock/index.cjs +0 -226
  98. package/dist/lock/index.cjs.map +0 -1
  99. package/dist/lock/index.d.cts +0 -361
  100. package/dist/lock-redis/index.cjs +0 -113
  101. package/dist/lock-redis/index.cjs.map +0 -1
  102. package/dist/lock-redis/index.d.cts +0 -24
  103. package/dist/logger/index.cjs +0 -521
  104. package/dist/logger/index.cjs.map +0 -1
  105. package/dist/logger/index.d.cts +0 -281
  106. package/dist/orm/index.cjs +0 -2986
  107. package/dist/orm/index.cjs.map +0 -1
  108. package/dist/orm/index.d.cts +0 -2213
  109. package/dist/queue/index.cjs +0 -1044
  110. package/dist/queue/index.cjs.map +0 -1
  111. package/dist/queue/index.d.cts +0 -1265
  112. package/dist/queue-redis/index.cjs +0 -873
  113. package/dist/queue-redis/index.cjs.map +0 -1
  114. package/dist/queue-redis/index.d.cts +0 -82
  115. package/dist/redis/index.cjs +0 -153
  116. package/dist/redis/index.cjs.map +0 -1
  117. package/dist/redis/index.d.cts +0 -82
  118. package/dist/retry/index.cjs +0 -146
  119. package/dist/retry/index.cjs.map +0 -1
  120. package/dist/retry/index.d.cts +0 -172
  121. package/dist/router/index.cjs +0 -111
  122. package/dist/router/index.cjs.map +0 -1
  123. package/dist/router/index.d.cts +0 -46
  124. package/dist/scheduler/index.cjs +0 -576
  125. package/dist/scheduler/index.cjs.map +0 -1
  126. package/dist/scheduler/index.d.cts +0 -145
  127. package/dist/security/index.cjs +0 -2402
  128. package/dist/security/index.cjs.map +0 -1
  129. package/dist/security/index.d.cts +0 -598
  130. package/dist/server/index.cjs +0 -1680
  131. package/dist/server/index.cjs.map +0 -1
  132. package/dist/server/index.d.cts +0 -810
  133. package/dist/server-auth/index.cjs +0 -3146
  134. package/dist/server-auth/index.cjs.map +0 -1
  135. package/dist/server-auth/index.d.cts +0 -1164
  136. package/dist/server-cache/index.cjs +0 -252
  137. package/dist/server-cache/index.cjs.map +0 -1
  138. package/dist/server-cache/index.d.cts +0 -164
  139. package/dist/server-compress/index.cjs +0 -141
  140. package/dist/server-compress/index.cjs.map +0 -1
  141. package/dist/server-compress/index.d.cts +0 -38
  142. package/dist/server-cookies/index.cjs +0 -234
  143. package/dist/server-cookies/index.cjs.map +0 -1
  144. package/dist/server-cookies/index.d.cts +0 -144
  145. package/dist/server-cors/index.cjs +0 -201
  146. package/dist/server-cors/index.cjs.map +0 -1
  147. package/dist/server-cors/index.d.cts +0 -140
  148. package/dist/server-health/index.cjs +0 -62
  149. package/dist/server-health/index.cjs.map +0 -1
  150. package/dist/server-health/index.d.cts +0 -58
  151. package/dist/server-helmet/index.cjs +0 -131
  152. package/dist/server-helmet/index.cjs.map +0 -1
  153. package/dist/server-helmet/index.d.cts +0 -97
  154. package/dist/server-links/index.cjs +0 -992
  155. package/dist/server-links/index.cjs.map +0 -1
  156. package/dist/server-links/index.d.cts +0 -513
  157. package/dist/server-metrics/index.cjs +0 -4535
  158. package/dist/server-metrics/index.cjs.map +0 -1
  159. package/dist/server-metrics/index.d.cts +0 -35
  160. package/dist/server-multipart/index.cjs +0 -237
  161. package/dist/server-multipart/index.cjs.map +0 -1
  162. package/dist/server-multipart/index.d.cts +0 -50
  163. package/dist/server-proxy/index.cjs +0 -186
  164. package/dist/server-proxy/index.cjs.map +0 -1
  165. package/dist/server-proxy/index.d.cts +0 -234
  166. package/dist/server-rate-limit/index.cjs +0 -241
  167. package/dist/server-rate-limit/index.cjs.map +0 -1
  168. package/dist/server-rate-limit/index.d.cts +0 -183
  169. package/dist/server-security/index.cjs +0 -316
  170. package/dist/server-security/index.cjs.map +0 -1
  171. package/dist/server-security/index.d.cts +0 -173
  172. package/dist/server-static/index.cjs +0 -170
  173. package/dist/server-static/index.cjs.map +0 -1
  174. package/dist/server-static/index.d.cts +0 -121
  175. package/dist/server-swagger/index.cjs +0 -1021
  176. package/dist/server-swagger/index.cjs.map +0 -1
  177. package/dist/server-swagger/index.d.cts +0 -382
  178. package/dist/sms/index.cjs +0 -221
  179. package/dist/sms/index.cjs.map +0 -1
  180. package/dist/sms/index.d.cts +0 -130
  181. package/dist/thread/index.cjs +0 -350
  182. package/dist/thread/index.cjs.map +0 -1
  183. package/dist/thread/index.d.cts +0 -260
  184. package/dist/topic/index.cjs +0 -282
  185. package/dist/topic/index.cjs.map +0 -1
  186. package/dist/topic/index.d.cts +0 -523
  187. package/dist/topic-redis/index.cjs +0 -71
  188. package/dist/topic-redis/index.cjs.map +0 -1
  189. package/dist/topic-redis/index.d.cts +0 -42
  190. package/dist/vite/index.cjs +0 -1077
  191. package/dist/vite/index.cjs.map +0 -1
  192. package/dist/vite/index.d.cts +0 -542
  193. package/dist/websocket/index.cjs +0 -1117
  194. package/dist/websocket/index.cjs.map +0 -1
  195. package/dist/websocket/index.d.cts +0 -861
@@ -1,234 +0,0 @@
1
- import * as alepha1 from "alepha";
2
- import { Alepha, Async, Descriptor, KIND } from "alepha";
3
- import { ServerHandler, ServerRequest, ServerRouterProvider } from "alepha/server";
4
- import * as alepha_logger0 from "alepha/logger";
5
-
6
- //#region src/server-proxy/descriptors/$proxy.d.ts
7
-
8
- /**
9
- * Creates a proxy descriptor to forward requests to another server.
10
- *
11
- * This descriptor enables you to create reverse proxy functionality, allowing your Alepha server
12
- * to forward requests to other services while maintaining a unified API surface. It's particularly
13
- * useful for microservice architectures, API gateways, or when you need to aggregate multiple
14
- * services behind a single endpoint.
15
- *
16
- * **Key Features**
17
- *
18
- * - **Path-based routing**: Match specific paths or patterns to proxy
19
- * - **Dynamic targets**: Support both static and dynamic target resolution
20
- * - **Request/Response hooks**: Modify requests before forwarding and responses after receiving
21
- * - **URL rewriting**: Transform URLs before forwarding to the target
22
- * - **Conditional proxying**: Enable/disable proxies based on environment or conditions
23
- *
24
- * @example
25
- * **Basic proxy setup:**
26
- * ```ts
27
- * import { $proxy } from "alepha/server/proxy";
28
- *
29
- * class ApiGateway {
30
- * // Forward all /api/* requests to external service
31
- * api = $proxy({
32
- * path: "/api/*",
33
- * target: "https://api.example.com"
34
- * });
35
- * }
36
- * ```
37
- *
38
- * @example
39
- * **Dynamic target with environment-based routing:**
40
- * ```ts
41
- * class ApiGateway {
42
- * // Route to different environments based on configuration
43
- * api = $proxy({
44
- * path: "/api/*",
45
- * target: () => process.env.NODE_ENV === "production"
46
- * ? "https://api.prod.example.com"
47
- * : "https://api.dev.example.com"
48
- * });
49
- * }
50
- * ```
51
- *
52
- * @example
53
- * **Advanced proxy with request/response modification:**
54
- * ```ts
55
- * class SecureProxy {
56
- * secure = $proxy({
57
- * path: "/secure/*",
58
- * target: "https://secure-api.example.com",
59
- * beforeRequest: async (request, proxyRequest) => {
60
- * // Add authentication headers
61
- * proxyRequest.headers = {
62
- * ...proxyRequest.headers,
63
- * 'Authorization': `Bearer ${await getServiceToken()}`,
64
- * 'X-Forwarded-For': request.headers['x-forwarded-for'] || request.ip
65
- * };
66
- * },
67
- * afterResponse: async (request, proxyResponse) => {
68
- * // Log response for monitoring
69
- * console.log(`Proxied ${request.url} -> ${proxyResponse.status}`);
70
- * },
71
- * rewrite: (url) => {
72
- * // Remove /secure prefix when forwarding
73
- * url.pathname = url.pathname.replace('/secure', '');
74
- * }
75
- * });
76
- * }
77
- * ```
78
- *
79
- * @example
80
- * **Conditional proxy based on feature flags:**
81
- * ```ts
82
- * class FeatureProxy {
83
- * newApi = $proxy({
84
- * path: "/v2/*",
85
- * target: "https://new-api.example.com",
86
- * disabled: !process.env.ENABLE_V2_API // Disable if feature flag is off
87
- * });
88
- * }
89
- * ```
90
- */
91
- declare const $proxy: {
92
- (options: ProxyDescriptorOptions): ProxyDescriptor;
93
- [KIND]: typeof ProxyDescriptor;
94
- };
95
- type ProxyDescriptorOptions = {
96
- /**
97
- * Path pattern to match for proxying requests.
98
- *
99
- * Supports wildcards and path parameters:
100
- * - `/api/*` - Matches all paths starting with `/api/`
101
- * - `/api/v1/*` - Matches all paths starting with `/api/v1/`
102
- * - `/users/:id` - Matches `/users/123`, `/users/abc`, etc.
103
- *
104
- * @example "/api/*"
105
- * @example "/secure/admin/*"
106
- * @example "/users/:id/posts"
107
- */
108
- path: string;
109
- /**
110
- * Target URL to which matching requests should be forwarded.
111
- *
112
- * Can be either:
113
- * - **Static string**: A fixed URL like `"https://api.example.com"`
114
- * - **Dynamic function**: A function that returns the URL, enabling runtime target resolution
115
- *
116
- * The target URL will be combined with the remaining path from the original request.
117
- *
118
- * @example "https://api.example.com"
119
- * @example () => process.env.API_URL || "http://localhost:3001"
120
- */
121
- target: string | (() => string);
122
- /**
123
- * Whether this proxy is disabled.
124
- *
125
- * When `true`, requests matching the path will not be proxied and will be handled
126
- * by other routes or return 404. Useful for feature toggles or conditional proxying.
127
- *
128
- * @default false
129
- * @example !process.env.ENABLE_PROXY
130
- */
131
- disabled?: boolean;
132
- /**
133
- * Hook called before forwarding the request to the target server.
134
- *
135
- * Use this to:
136
- * - Add authentication headers
137
- * - Modify request headers or body
138
- * - Add request tracking/logging
139
- * - Transform the request before forwarding
140
- *
141
- * @param request - The original incoming server request
142
- * @param proxyRequest - The request that will be sent to the target (modifiable)
143
- *
144
- * @example
145
- * ```ts
146
- * beforeRequest: async (request, proxyRequest) => {
147
- * proxyRequest.headers = {
148
- * ...proxyRequest.headers,
149
- * 'Authorization': `Bearer ${await getToken()}`,
150
- * 'X-Request-ID': generateRequestId()
151
- * };
152
- * }
153
- * ```
154
- */
155
- beforeRequest?: (request: ServerRequest, proxyRequest: RequestInit) => Async<void>;
156
- /**
157
- * Hook called after receiving the response from the target server.
158
- *
159
- * Use this to:
160
- * - Log response details for monitoring
161
- * - Add custom headers to the response
162
- * - Transform response data
163
- * - Handle error responses
164
- *
165
- * @param request - The original incoming server request
166
- * @param proxyResponse - The response received from the target server
167
- *
168
- * @example
169
- * ```ts
170
- * afterResponse: async (request, proxyResponse) => {
171
- * console.log(`Proxy ${request.method} ${request.url} -> ${proxyResponse.status}`);
172
- *
173
- * if (!proxyResponse.ok) {
174
- * await logError(`Proxy error: ${proxyResponse.status}`, { request, response: proxyResponse });
175
- * }
176
- * }
177
- * ```
178
- */
179
- afterResponse?: (request: ServerRequest, proxyResponse: Response) => Async<void>;
180
- /**
181
- * Function to rewrite the URL before sending to the target server.
182
- *
183
- * Use this to:
184
- * - Remove or add path prefixes
185
- * - Transform path parameters
186
- * - Modify query parameters
187
- * - Change the URL structure entirely
188
- *
189
- * The function receives a mutable URL object and should modify it in-place.
190
- *
191
- * @param url - The URL object to modify (mutable)
192
- *
193
- * @example
194
- * ```ts
195
- * // Remove /api prefix when forwarding
196
- * rewrite: (url) => {
197
- * url.pathname = url.pathname.replace('/api', '');
198
- * }
199
- * ```
200
- *
201
- * @example
202
- * ```ts
203
- * // Add version prefix
204
- * rewrite: (url) => {
205
- * url.pathname = `/v2${url.pathname}`;
206
- * }
207
- * ```
208
- */
209
- rewrite?: (url: URL) => void;
210
- };
211
- declare class ProxyDescriptor extends Descriptor<ProxyDescriptorOptions> {}
212
- //#endregion
213
- //#region src/server-proxy/providers/ServerProxyProvider.d.ts
214
- declare class ServerProxyProvider {
215
- protected readonly log: alepha_logger0.Logger;
216
- protected readonly routerProvider: ServerRouterProvider;
217
- protected readonly alepha: Alepha;
218
- protected readonly configure: alepha1.HookDescriptor<"configure">;
219
- createProxy(options: ProxyDescriptorOptions): void;
220
- createProxyHandler(target: string, options: Omit<ProxyDescriptorOptions, "path">): ServerHandler;
221
- private getRawRequestBody;
222
- }
223
- //#endregion
224
- //#region src/server-proxy/index.d.ts
225
- /**
226
- * Plugin for Alepha that provides a proxy server functionality.
227
- *
228
- * @see {@link $proxy}
229
- * @module alepha.server.proxy
230
- */
231
- declare const AlephaServerProxy: alepha1.Service<alepha1.Module>;
232
- //#endregion
233
- export { $proxy, AlephaServerProxy, ProxyDescriptor, ProxyDescriptorOptions, ServerProxyProvider };
234
- //# sourceMappingURL=index.d.cts.map
@@ -1,241 +0,0 @@
1
- let alepha = require("alepha");
2
- let alepha_server = require("alepha/server");
3
- let alepha_cache = require("alepha/cache");
4
- let alepha_logger = require("alepha/logger");
5
-
6
- //#region src/server-rate-limit/providers/ServerRateLimitProvider.ts
7
- /**
8
- * Rate limit configuration atom (global defaults)
9
- */
10
- const rateLimitOptions = (0, alepha.$atom)({
11
- name: "alepha.server.rate-limit.options",
12
- schema: alepha.t.object({
13
- windowMs: alepha.t.optional(alepha.t.number({ description: "Window duration in milliseconds" })),
14
- max: alepha.t.optional(alepha.t.number({ description: "Maximum number of requests per window" })),
15
- skipFailedRequests: alepha.t.optional(alepha.t.boolean({ description: "Skip rate limiting for failed requests" })),
16
- skipSuccessfulRequests: alepha.t.optional(alepha.t.boolean({ description: "Skip rate limiting for successful requests" }))
17
- }),
18
- default: {}
19
- });
20
- const envSchema = alepha.t.object({
21
- RATE_LIMIT_WINDOW_MS: alepha.t.number({
22
- default: 900 * 1e3,
23
- description: "Rate limit window in milliseconds"
24
- }),
25
- RATE_LIMIT_MAX_REQUESTS: alepha.t.number({
26
- default: 100,
27
- description: "Maximum requests per window"
28
- })
29
- });
30
- var ServerRateLimitProvider = class {
31
- log = (0, alepha_logger.$logger)();
32
- serverRouterProvider = (0, alepha.$inject)(alepha_server.ServerRouterProvider);
33
- env = (0, alepha.$env)(envSchema);
34
- cache = (0, alepha_cache.$cache)({
35
- name: "server-rate-limit",
36
- ttl: [this.env.RATE_LIMIT_WINDOW_MS, "milliseconds"]
37
- });
38
- globalOptions = (0, alepha.$use)(rateLimitOptions);
39
- /**
40
- * Registered rate limit configurations with their path patterns
41
- */
42
- registeredConfigs = [];
43
- /**
44
- * Register a rate limit configuration (called by descriptors)
45
- */
46
- registerRateLimit(config) {
47
- this.registeredConfigs.push(config);
48
- }
49
- onStart = (0, alepha.$hook)({
50
- on: "start",
51
- handler: async () => {
52
- for (const config of this.registeredConfigs) if (config.paths) for (const pattern of config.paths) {
53
- const matchedRoutes = this.serverRouterProvider.getRoutes(pattern);
54
- for (const route of matchedRoutes) route.rateLimit = this.buildRateLimitOptions(config);
55
- }
56
- if (this.registeredConfigs.length > 0) this.log.info(`Initialized with ${this.registeredConfigs.length} registered rate-limit configurations.`);
57
- }
58
- });
59
- onRequest = (0, alepha.$hook)({
60
- on: "server:onRequest",
61
- handler: async ({ route, request }) => {
62
- const rateLimitConfig = route.rateLimit ?? this.globalOptions;
63
- if (!rateLimitConfig.max && !rateLimitConfig.windowMs) return;
64
- const result = await this.checkLimit(request, rateLimitConfig);
65
- this.setRateLimitHeaders(request, result);
66
- if (!result.allowed) throw new alepha_server.HttpError({
67
- status: 429,
68
- message: "Too Many Requests"
69
- });
70
- }
71
- });
72
- onActionRequest = (0, alepha.$hook)({
73
- on: "action:onRequest",
74
- handler: async ({ action, request }) => {
75
- const rateLimit = action.options?.rateLimit;
76
- if (!rateLimit) return;
77
- if (!(await this.checkLimit(request, rateLimit)).allowed) throw new alepha_server.HttpError({
78
- status: 429,
79
- message: "Too Many Requests"
80
- });
81
- }
82
- });
83
- /**
84
- * Build complete rate limit options by merging with global defaults
85
- */
86
- buildRateLimitOptions(config) {
87
- return {
88
- max: config.max ?? this.globalOptions.max,
89
- windowMs: config.windowMs ?? this.globalOptions.windowMs,
90
- keyGenerator: config.keyGenerator,
91
- skipFailedRequests: config.skipFailedRequests ?? this.globalOptions.skipFailedRequests,
92
- skipSuccessfulRequests: config.skipSuccessfulRequests ?? this.globalOptions.skipSuccessfulRequests
93
- };
94
- }
95
- /**
96
- * Set rate limit headers on the response
97
- */
98
- setRateLimitHeaders(request, result) {
99
- request.reply.setHeader("X-RateLimit-Limit", result.limit.toString());
100
- request.reply.setHeader("X-RateLimit-Remaining", result.remaining.toString());
101
- request.reply.setHeader("X-RateLimit-Reset", Math.ceil(result.resetTime / 1e3).toString());
102
- if (!result.allowed && result.retryAfter) request.reply.setHeader("Retry-After", result.retryAfter.toString());
103
- }
104
- async checkLimit(req, options = {}) {
105
- const windowMs = options.windowMs ?? this.env.RATE_LIMIT_WINDOW_MS;
106
- const max = options.max ?? this.env.RATE_LIMIT_MAX_REQUESTS;
107
- const key = this.generateKey(req);
108
- const now = Date.now();
109
- const windowStart = now - windowMs;
110
- const currentData = await this.cache.get(key) || {
111
- count: 0,
112
- windowStart: now,
113
- hits: []
114
- };
115
- const validHits = currentData.hits.filter((hit) => hit >= windowStart);
116
- const allowed = validHits.length < max;
117
- const remaining = Math.max(0, max - validHits.length);
118
- const resetTime = Math.max(...validHits, windowStart) + windowMs;
119
- if (allowed) {
120
- validHits.push(now);
121
- await this.cache.set(key, {
122
- count: validHits.length,
123
- windowStart: Math.min(currentData.windowStart, windowStart),
124
- hits: validHits
125
- });
126
- }
127
- const result = {
128
- allowed,
129
- limit: max,
130
- remaining: allowed ? remaining - 1 : remaining,
131
- resetTime
132
- };
133
- if (!allowed) result.retryAfter = Math.ceil((resetTime - now) / 1e3);
134
- return result;
135
- }
136
- generateKey(req) {
137
- return `ip:${this.getClientIP(req)}`;
138
- }
139
- getClientIP(req) {
140
- const forwarded = req.headers?.["x-forwarded-for"];
141
- if (forwarded) {
142
- const firstIp = forwarded.split(",")[0].trim();
143
- if (firstIp) return firstIp;
144
- }
145
- return req.ip || "unknown";
146
- }
147
- };
148
-
149
- //#endregion
150
- //#region src/server-rate-limit/descriptors/$rateLimit.ts
151
- /**
152
- * Declares rate limiting for server routes or custom usage.
153
- * This descriptor provides methods to check rate limits and configure behavior
154
- * within the server request/response cycle.
155
- *
156
- * @example
157
- * ```ts
158
- * class ApiService {
159
- * // Apply rate limiting to specific paths
160
- * apiRateLimit = $rateLimit({
161
- * paths: ["/api/*"],
162
- * max: 100,
163
- * windowMs: 15 * 60 * 1000, // 15 minutes
164
- * });
165
- *
166
- * // Or use check() method for manual rate limiting
167
- * customAction = $action({
168
- * handler: async (req) => {
169
- * const result = await this.apiRateLimit.check(req);
170
- * if (!result.allowed) throw new Error("Rate limited");
171
- * return "ok";
172
- * },
173
- * });
174
- * }
175
- * ```
176
- */
177
- const $rateLimit = (options = {}) => {
178
- return (0, alepha.createDescriptor)(RateLimitDescriptor, options);
179
- };
180
- var RateLimitDescriptor = class extends alepha.Descriptor {
181
- serverRateLimitProvider = (0, alepha.$inject)(ServerRateLimitProvider);
182
- get name() {
183
- return this.options.name ?? `${this.config.propertyKey}`;
184
- }
185
- onInit() {
186
- this.serverRateLimitProvider.registerRateLimit(this.options);
187
- }
188
- /**
189
- * Checks rate limit for the given request using this descriptor's configuration.
190
- */
191
- async check(request, options) {
192
- const mergedOptions = {
193
- ...this.options,
194
- ...options
195
- };
196
- return this.serverRateLimitProvider.checkLimit(request, mergedOptions);
197
- }
198
- };
199
- $rateLimit[alepha.KIND] = RateLimitDescriptor;
200
-
201
- //#endregion
202
- //#region src/server-rate-limit/index.ts
203
- /**
204
- * Provides rate limiting capabilities for server routes and actions with configurable limits and windows.
205
- *
206
- * The server-rate-limit module enables per-route and per-action rate limiting using either:
207
- * - The `$rateLimit` descriptor with `paths` option for path-based rate limiting
208
- * - The `rateLimit` option in action descriptors for action-specific limiting
209
- *
210
- * It offers sliding window rate limiting, custom key generation, and seamless integration with server routes.
211
- *
212
- * @example
213
- * ```ts
214
- * import { $rateLimit, AlephaServerRateLimit } from "alepha/server-rate-limit";
215
- *
216
- * class ApiService {
217
- * // Path-specific rate limiting
218
- * apiRateLimit = $rateLimit({
219
- * paths: ["/api/*"],
220
- * max: 100,
221
- * windowMs: 15 * 60 * 1000, // 15 minutes
222
- * });
223
- * }
224
- * ```
225
- *
226
- * @see {@link $rateLimit}
227
- * @module alepha.server.rate-limit
228
- */
229
- const AlephaServerRateLimit = (0, alepha.$module)({
230
- name: "alepha.server.rate-limit",
231
- descriptors: [$rateLimit],
232
- services: [alepha_server.AlephaServer, ServerRateLimitProvider]
233
- });
234
-
235
- //#endregion
236
- exports.$rateLimit = $rateLimit;
237
- exports.AlephaServerRateLimit = AlephaServerRateLimit;
238
- exports.RateLimitDescriptor = RateLimitDescriptor;
239
- exports.ServerRateLimitProvider = ServerRateLimitProvider;
240
- exports.rateLimitOptions = rateLimitOptions;
241
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","names":["t","ServerRouterProvider","HttpError","result: RateLimitResult","Descriptor","KIND","AlephaServer"],"sources":["../../src/server-rate-limit/providers/ServerRateLimitProvider.ts","../../src/server-rate-limit/descriptors/$rateLimit.ts","../../src/server-rate-limit/index.ts"],"sourcesContent":["import { $atom, $env, $hook, $inject, $use, type Static, t } from \"alepha\";\nimport { $cache } from \"alepha/cache\";\nimport { $logger } from \"alepha/logger\";\nimport {\n HttpError,\n type ServerRequest,\n ServerRouterProvider,\n} from \"alepha/server\";\nimport type { RateLimitDescriptorOptions } from \"../descriptors/$rateLimit.ts\";\nimport type { RateLimitOptions } from \"../index.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface RateLimitResult {\n allowed: boolean;\n limit: number;\n remaining: number;\n resetTime: number;\n retryAfter?: number;\n}\n\n/**\n * Rate limit configuration atom (global defaults)\n */\nexport const rateLimitOptions = $atom({\n name: \"alepha.server.rate-limit.options\",\n schema: t.object({\n windowMs: t.optional(\n t.number({\n description: \"Window duration in milliseconds\",\n }),\n ),\n max: t.optional(\n t.number({\n description: \"Maximum number of requests per window\",\n }),\n ),\n skipFailedRequests: t.optional(\n t.boolean({\n description: \"Skip rate limiting for failed requests\",\n }),\n ),\n skipSuccessfulRequests: t.optional(\n t.boolean({\n description: \"Skip rate limiting for successful requests\",\n }),\n ),\n }),\n default: {},\n});\n\nexport type RateLimitAtomOptions = Static<typeof rateLimitOptions.schema>;\n\ndeclare module \"alepha\" {\n interface State {\n [rateLimitOptions.key]: RateLimitAtomOptions;\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nconst envSchema = t.object({\n RATE_LIMIT_WINDOW_MS: t.number({\n default: 15 * 60 * 1000, // 15 minutes\n description: \"Rate limit window in milliseconds\",\n }),\n RATE_LIMIT_MAX_REQUESTS: t.number({\n default: 100,\n description: \"Maximum requests per window\",\n }),\n});\n\nexport class ServerRateLimitProvider {\n protected readonly log = $logger();\n protected readonly serverRouterProvider = $inject(ServerRouterProvider);\n protected readonly env = $env(envSchema);\n\n protected readonly cache = $cache<RateLimitData>({\n name: \"server-rate-limit\",\n ttl: [this.env.RATE_LIMIT_WINDOW_MS, \"milliseconds\"],\n });\n\n protected readonly globalOptions = $use(rateLimitOptions);\n\n /**\n * Registered rate limit configurations with their path patterns\n */\n public readonly registeredConfigs: RateLimitDescriptorOptions[] = [];\n\n /**\n * Register a rate limit configuration (called by descriptors)\n */\n public registerRateLimit(config: RateLimitDescriptorOptions): void {\n this.registeredConfigs.push(config);\n }\n\n protected readonly onStart = $hook({\n on: \"start\",\n handler: async () => {\n // Apply path-specific rate limit configs to routes\n for (const config of this.registeredConfigs) {\n if (config.paths) {\n for (const pattern of config.paths) {\n const matchedRoutes = this.serverRouterProvider.getRoutes(pattern);\n for (const route of matchedRoutes) {\n route.rateLimit = this.buildRateLimitOptions(config);\n }\n }\n }\n }\n\n if (this.registeredConfigs.length > 0) {\n this.log.info(\n `Initialized with ${this.registeredConfigs.length} registered rate-limit configurations.`,\n );\n }\n },\n });\n\n public readonly onRequest = $hook({\n on: \"server:onRequest\",\n handler: async ({ route, request }) => {\n // Use route-specific rate limit if defined, otherwise use global options\n const rateLimitConfig = route.rateLimit ?? this.globalOptions;\n\n // Skip if no rate limiting configured\n if (!rateLimitConfig.max && !rateLimitConfig.windowMs) {\n return;\n }\n\n const result = await this.checkLimit(request, rateLimitConfig);\n this.setRateLimitHeaders(request, result);\n\n if (!result.allowed) {\n throw new HttpError({\n status: 429,\n message: \"Too Many Requests\",\n });\n }\n },\n });\n\n public readonly onActionRequest = $hook({\n on: \"action:onRequest\",\n handler: async ({ action, request }) => {\n // Check if this action has rate limiting enabled\n const rateLimit = action.options?.rateLimit;\n if (!rateLimit) {\n return; // No rate limiting for this action\n }\n\n const result = await this.checkLimit(request, rateLimit);\n\n if (!result.allowed) {\n // Actions are internal - don't set HTTP headers\n // Only throw error to prevent action execution\n throw new HttpError({\n status: 429,\n message: \"Too Many Requests\",\n });\n }\n\n // Action allowed - no headers to set since actions are internal\n },\n });\n\n /**\n * Build complete rate limit options by merging with global defaults\n */\n protected buildRateLimitOptions(\n config: RateLimitDescriptorOptions,\n ): RateLimitOptions {\n return {\n max: config.max ?? this.globalOptions.max,\n windowMs: config.windowMs ?? this.globalOptions.windowMs,\n keyGenerator: config.keyGenerator,\n skipFailedRequests:\n config.skipFailedRequests ?? this.globalOptions.skipFailedRequests,\n skipSuccessfulRequests:\n config.skipSuccessfulRequests ??\n this.globalOptions.skipSuccessfulRequests,\n };\n }\n\n /**\n * Set rate limit headers on the response\n */\n protected setRateLimitHeaders(\n request: ServerRequest,\n result: RateLimitResult,\n ): void {\n request.reply.setHeader(\"X-RateLimit-Limit\", result.limit.toString());\n request.reply.setHeader(\n \"X-RateLimit-Remaining\",\n result.remaining.toString(),\n );\n request.reply.setHeader(\n \"X-RateLimit-Reset\",\n Math.ceil(result.resetTime / 1000).toString(),\n );\n\n if (!result.allowed && result.retryAfter) {\n request.reply.setHeader(\"Retry-After\", result.retryAfter.toString());\n }\n }\n\n public async checkLimit(\n req: ServerRequest,\n options: RateLimitOptions = {},\n ): Promise<RateLimitResult> {\n const windowMs = options.windowMs ?? this.env.RATE_LIMIT_WINDOW_MS;\n const max = options.max ?? this.env.RATE_LIMIT_MAX_REQUESTS;\n const key = this.generateKey(req);\n\n const now = Date.now();\n const windowStart = now - windowMs;\n\n // Get current rate limit data\n const currentData = (await this.cache.get(key)) || {\n count: 0,\n windowStart: now,\n hits: [],\n };\n\n // Clean old hits outside the current window\n const validHits = currentData.hits.filter(\n (hit: number) => hit >= windowStart,\n );\n\n // Check if limit exceeded\n const allowed = validHits.length < max;\n const remaining = Math.max(0, max - validHits.length);\n const resetTime = Math.max(...validHits, windowStart) + windowMs;\n\n // If allowed, record this request\n if (allowed) {\n validHits.push(now);\n await this.cache.set(key, {\n count: validHits.length,\n windowStart: Math.min(currentData.windowStart, windowStart),\n hits: validHits,\n });\n }\n\n const result: RateLimitResult = {\n allowed,\n limit: max,\n remaining: allowed ? remaining - 1 : remaining,\n resetTime,\n };\n\n if (!allowed) {\n result.retryAfter = Math.ceil((resetTime - now) / 1000);\n }\n\n return result;\n }\n\n protected generateKey(req: ServerRequest): string {\n // Default to IP-based rate limiting\n const ip = this.getClientIP(req);\n return `ip:${ip}`;\n }\n\n protected getClientIP(req: ServerRequest): string {\n // Check x-forwarded-for header first (for proxies/load balancers)\n const forwarded = req.headers?.[\"x-forwarded-for\"];\n if (forwarded) {\n // x-forwarded-for can contain multiple IPs, get the first one (original client)\n const firstIp = forwarded.split(\",\")[0].trim();\n if (firstIp) return firstIp;\n }\n\n return req.ip || \"unknown\";\n }\n}\n\ninterface RateLimitData {\n count: number;\n windowStart: number;\n hits: number[];\n}\n","import { $inject, createDescriptor, Descriptor, KIND } from \"alepha\";\nimport type { ServerRequest } from \"alepha/server\";\nimport type { RateLimitOptions } from \"../index.ts\";\nimport {\n type RateLimitResult,\n ServerRateLimitProvider,\n} from \"../providers/ServerRateLimitProvider.ts\";\n\n/**\n * Declares rate limiting for server routes or custom usage.\n * This descriptor provides methods to check rate limits and configure behavior\n * within the server request/response cycle.\n *\n * @example\n * ```ts\n * class ApiService {\n * // Apply rate limiting to specific paths\n * apiRateLimit = $rateLimit({\n * paths: [\"/api/*\"],\n * max: 100,\n * windowMs: 15 * 60 * 1000, // 15 minutes\n * });\n *\n * // Or use check() method for manual rate limiting\n * customAction = $action({\n * handler: async (req) => {\n * const result = await this.apiRateLimit.check(req);\n * if (!result.allowed) throw new Error(\"Rate limited\");\n * return \"ok\";\n * },\n * });\n * }\n * ```\n */\nexport const $rateLimit = (\n options: RateLimitDescriptorOptions = {},\n): AbstractRateLimitDescriptor => {\n return createDescriptor(RateLimitDescriptor, options);\n};\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface RateLimitDescriptorOptions extends RateLimitOptions {\n /** Name identifier for this rate limit (default: property key) */\n name?: string;\n /** Path patterns to match (supports wildcards like /api/*) */\n paths?: string[];\n}\n\nexport interface AbstractRateLimitDescriptor {\n readonly name: string;\n readonly options: RateLimitDescriptorOptions;\n check(\n request: ServerRequest,\n options?: RateLimitOptions,\n ): Promise<RateLimitResult>;\n}\n\nexport class RateLimitDescriptor\n extends Descriptor<RateLimitDescriptorOptions>\n implements AbstractRateLimitDescriptor\n{\n protected readonly serverRateLimitProvider = $inject(ServerRateLimitProvider);\n\n public get name(): string {\n return this.options.name ?? `${this.config.propertyKey}`;\n }\n\n protected onInit() {\n // Register this rate limit configuration with the provider\n this.serverRateLimitProvider.registerRateLimit(this.options);\n }\n\n /**\n * Checks rate limit for the given request using this descriptor's configuration.\n */\n public async check(\n request: ServerRequest,\n options?: RateLimitOptions,\n ): Promise<RateLimitResult> {\n const mergedOptions = { ...this.options, ...options };\n return this.serverRateLimitProvider.checkLimit(request, mergedOptions);\n }\n}\n\n$rateLimit[KIND] = RateLimitDescriptor;\n","import { $module } from \"alepha\";\nimport { AlephaServer } from \"alepha/server\";\nimport { $rateLimit } from \"./descriptors/$rateLimit.ts\";\nimport { ServerRateLimitProvider } from \"./providers/ServerRateLimitProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport * from \"./descriptors/$rateLimit.ts\";\nexport * from \"./providers/ServerRateLimitProvider.ts\";\n\n// ---------------------------------------------------------------------------------------------------------------------\n\ndeclare module \"alepha/server\" {\n interface ActionDescriptorOptions<TConfig> {\n /**\n * Rate limiting configuration for this action.\n * When specified, the action will be rate limited according to these settings.\n */\n rateLimit?: RateLimitOptions;\n }\n\n interface ServerRoute {\n /**\n * Route-specific rate limit configuration.\n * If set, overrides the global rate limit options for this route.\n */\n rateLimit?: RateLimitOptions;\n }\n}\n\n// ---------------------------------------------------------------------------------------------------------------------\n\nexport interface RateLimitOptions {\n /** Maximum number of requests per window (default: 100) */\n max?: number;\n /** Window duration in milliseconds (default: 15 minutes) */\n windowMs?: number;\n /** Custom key generator function */\n keyGenerator?: (req: any) => string;\n /** Skip rate limiting for failed requests */\n skipFailedRequests?: boolean;\n /** Skip rate limiting for successful requests */\n skipSuccessfulRequests?: boolean;\n}\n\n/**\n * Provides rate limiting capabilities for server routes and actions with configurable limits and windows.\n *\n * The server-rate-limit module enables per-route and per-action rate limiting using either:\n * - The `$rateLimit` descriptor with `paths` option for path-based rate limiting\n * - The `rateLimit` option in action descriptors for action-specific limiting\n *\n * It offers sliding window rate limiting, custom key generation, and seamless integration with server routes.\n *\n * @example\n * ```ts\n * import { $rateLimit, AlephaServerRateLimit } from \"alepha/server-rate-limit\";\n *\n * class ApiService {\n * // Path-specific rate limiting\n * apiRateLimit = $rateLimit({\n * paths: [\"/api/*\"],\n * max: 100,\n * windowMs: 15 * 60 * 1000, // 15 minutes\n * });\n * }\n * ```\n *\n * @see {@link $rateLimit}\n * @module alepha.server.rate-limit\n */\nexport const AlephaServerRateLimit = $module({\n name: \"alepha.server.rate-limit\",\n descriptors: [$rateLimit],\n services: [AlephaServer, ServerRateLimitProvider],\n});\n"],"mappings":";;;;;;;;;AAwBA,MAAa,qCAAyB;CACpC,MAAM;CACN,QAAQA,SAAE,OAAO;EACf,UAAUA,SAAE,SACVA,SAAE,OAAO,EACP,aAAa,mCACd,CAAC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