alepha 0.9.3 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,29 @@
1
- import * as _alepha_core0 from "alepha";
2
- import { Alepha, HookDescriptor } from "alepha";
1
+ import * as _alepha_core1 from "alepha";
2
+ import { Alepha } from "alepha";
3
3
 
4
4
  //#region src/providers/ServerHelmetProvider.d.ts
5
5
  type CspDirective = string | string[];
6
+ interface CspDirectives {
7
+ "default-src"?: CspDirective;
8
+ "script-src"?: CspDirective;
9
+ "style-src"?: CspDirective;
10
+ "img-src"?: CspDirective;
11
+ "connect-src"?: CspDirective;
12
+ "font-src"?: CspDirective;
13
+ "object-src"?: CspDirective;
14
+ "media-src"?: CspDirective;
15
+ "frame-src"?: CspDirective;
16
+ sandbox?: CspDirective | boolean;
17
+ "report-uri"?: string;
18
+ "child-src"?: CspDirective;
19
+ "form-action"?: CspDirective;
20
+ "frame-ancestors"?: CspDirective;
21
+ "plugin-types"?: CspDirective;
22
+ "base-uri"?: CspDirective;
23
+ [key: string]: CspDirective | undefined | boolean;
24
+ }
6
25
  interface CspOptions {
7
- directives: {
8
- "default-src"?: CspDirective;
9
- "script-src"?: CspDirective;
10
- "style-src"?: CspDirective;
11
- "img-src"?: CspDirective;
12
- "connect-src"?: CspDirective;
13
- "font-src"?: CspDirective;
14
- "object-src"?: CspDirective;
15
- "media-src"?: CspDirective;
16
- "frame-src"?: CspDirective;
17
- sandbox?: CspDirective | boolean;
18
- "report-uri"?: string;
19
- "child-src"?: CspDirective;
20
- "form-action"?: CspDirective;
21
- "frame-ancestors"?: CspDirective;
22
- "plugin-types"?: CspDirective;
23
- "base-uri"?: CspDirective;
24
- [key: string]: CspDirective | undefined | boolean;
25
- };
26
+ directives: CspDirectives;
26
27
  }
27
28
  interface HstsOptions {
28
29
  maxAge?: number;
@@ -35,7 +36,7 @@ interface HelmetOptions {
35
36
  xContentTypeOptions?: false;
36
37
  xFrameOptions?: "DENY" | "SAMEORIGIN" | false;
37
38
  xXssProtection?: false;
38
- contentSecurityPolicy?: CspOptions | false;
39
+ contentSecurityPolicy?: CspOptions | false | "default";
39
40
  referrerPolicy?: "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | false;
40
41
  }
41
42
  /**
@@ -49,8 +50,9 @@ declare class ServerHelmetProvider {
49
50
  * the application's configuration phase using `alepha.configure()`.
50
51
  */
51
52
  options: HelmetOptions;
52
- private buildHeaders;
53
- protected readonly onResponse: HookDescriptor<"server:onResponse">;
53
+ protected defaultCspDirectives(): CspDirectives;
54
+ protected buildHeaders(): Record<string, string>;
55
+ protected readonly onResponse: _alepha_core1.HookDescriptor<"server:onResponse">;
54
56
  }
55
57
  //#endregion
56
58
  //#region src/index.d.ts
@@ -61,9 +63,7 @@ declare class ServerHelmetProvider {
61
63
  * @see {@link ServerHelmetProvider}
62
64
  * @module alepha.server.helmet
63
65
  */
64
- declare const AlephaServerHelmet: _alepha_core0.Service<_alepha_core0.Module>;
65
- //# sourceMappingURL=index.d.ts.map
66
-
66
+ declare const AlephaServerHelmet: _alepha_core1.Service<_alepha_core1.Module>;
67
67
  //#endregion
68
- export { AlephaServerHelmet, CspOptions, HelmetOptions, HstsOptions, ServerHelmetProvider };
68
+ export { AlephaServerHelmet, CspDirectives, CspOptions, HelmetOptions, HstsOptions, ServerHelmetProvider };
69
69
  //# sourceMappingURL=index.d.ts.map
package/server/links.d.ts CHANGED
@@ -1,33 +1,83 @@
1
+ import "alepha/server/security";
1
2
  import * as _alepha_core2 from "alepha";
2
- import * as _alepha_core1 from "alepha";
3
- import * as _alepha_core0 from "alepha";
4
- import { Alepha, Descriptor, KIND, Logger } from "alepha";
3
+ import { Alepha, Descriptor, KIND, Static } from "alepha";
5
4
  import * as _alepha_server0 from "alepha/server";
6
- import { ActionDescriptor, ApiLink, ApiLinksResponse, ClientRequestEntry, ClientRequestOptions, ClientRequestResponse, FetchResponse, HttpClient, RequestConfigSchema, ServerHandler, ServerRequestConfigEntry } from "alepha/server";
5
+ import { ActionDescriptor, ClientRequestEntry, ClientRequestOptions, ClientRequestResponse, FetchResponse, HttpClient, RequestConfigSchema, ServerHandler, ServerRequestConfigEntry, ServerTimingProvider } from "alepha/server";
6
+ import * as _alepha_logger0 from "alepha/logger";
7
7
  import * as _alepha_retry0 from "alepha/retry";
8
8
  import { ProxyDescriptorOptions, ServerProxyProvider } from "alepha/server/proxy";
9
9
  import { ServiceAccountDescriptor, UserAccountToken } from "alepha/security";
10
10
  import * as _sinclair_typebox0 from "@sinclair/typebox";
11
11
 
12
+ //#region src/schemas/apiLinksResponseSchema.d.ts
13
+ declare const apiLinkSchema: _sinclair_typebox0.TObject<{
14
+ name: _sinclair_typebox0.TString;
15
+ group: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
16
+ path: _sinclair_typebox0.TString;
17
+ method: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
18
+ requestBodyType: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
19
+ service: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
20
+ }>;
21
+ declare const apiLinksResponseSchema: _sinclair_typebox0.TObject<{
22
+ prefix: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
23
+ links: _sinclair_typebox0.TArray<_sinclair_typebox0.TObject<{
24
+ name: _sinclair_typebox0.TString;
25
+ group: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
26
+ path: _sinclair_typebox0.TString;
27
+ method: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
28
+ requestBodyType: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
29
+ service: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
30
+ }>>;
31
+ }>;
32
+ type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
33
+ type ApiLink = Static<typeof apiLinkSchema>;
34
+ //#endregion
12
35
  //#region src/providers/LinkProvider.d.ts
36
+ /**
37
+ * Browser, SSR friendly, service to handle links.
38
+ */
13
39
  declare class LinkProvider {
14
- readonly URL_LINKS = "/api/_links";
15
- protected readonly log: Logger;
40
+ static path: {
41
+ apiLinks: string;
42
+ apiSchema: string;
43
+ };
44
+ protected readonly log: _alepha_logger0.Logger;
16
45
  protected readonly alepha: Alepha;
17
46
  protected readonly httpClient: HttpClient;
18
- links?: Array<HttpClientLink>;
19
- pushLink(link: HttpClientLink): void;
20
- getLinks(force?: boolean): Promise<HttpClientLink[]>;
47
+ protected serverLinks: Array<HttpClientLink>;
48
+ /**
49
+ * Get applicative links registered on the server.
50
+ * This does not include lazy-loaded remote links.
51
+ */
52
+ getServerLinks(): HttpClientLink[];
53
+ /**
54
+ * Register a new link for the application.
55
+ */
56
+ registerLink(link: HttpClientLink): void;
57
+ get links(): HttpClientLink[];
58
+ /**
59
+ * Force browser to refresh links from the server.
60
+ */
61
+ fetchLinks(): Promise<HttpClientLink[]>;
62
+ /**
63
+ * Create a virtual client that can be used to call actions.
64
+ *
65
+ * Use js Proxy under the hood.
66
+ */
21
67
  client<T extends object>(scope?: ClientScope): HttpVirtualClient<T>;
22
- protected createVirtualAction<T extends RequestConfigSchema>(name: string, scope?: ClientScope): VirtualAction<T>;
68
+ /**
69
+ * Check if a link with the given name exists.
70
+ * @param name
71
+ */
72
+ can(name: string): boolean;
23
73
  /**
24
74
  * Resolve a link by its name and call it.
25
75
  * - If link is local, it will call the local handler.
26
76
  * - If link is remote, it will make a fetch request to the remote server.
27
77
  */
28
78
  follow(name: string, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions & ClientScope): Promise<any>;
79
+ protected createVirtualAction<T extends RequestConfigSchema>(name: string, scope?: ClientScope): VirtualAction<T>;
29
80
  protected followRemote(link: HttpClientLink, config?: Partial<ServerRequestConfigEntry>, options?: ClientRequestOptions): Promise<FetchResponse>;
30
- can(name: string): boolean;
31
81
  protected getLinkByName(name: string, options?: ClientScope): Promise<HttpClientLink>;
32
82
  }
33
83
  interface HttpClientLink extends ApiLink {
@@ -41,13 +91,13 @@ interface HttpClientLink extends ApiLink {
41
91
  interface ClientScope {
42
92
  group?: string;
43
93
  service?: string;
94
+ hostname?: string;
44
95
  }
45
96
  type HttpVirtualClient<T> = { [K in keyof T as T[K] extends ActionDescriptor<RequestConfigSchema> ? K : never]: T[K] extends ActionDescriptor<infer Schema> ? VirtualAction<Schema> : never };
46
97
  interface VirtualAction<T extends RequestConfigSchema> extends Pick<ActionDescriptor<T>, "name" | "run" | "fetch"> {
47
98
  (config?: ClientRequestEntry<T>, opts?: ClientRequestOptions): Promise<ClientRequestResponse<T>>;
48
99
  can: () => boolean;
49
100
  }
50
- //# sourceMappingURL=LinkProvider.d.ts.map
51
101
  //#endregion
52
102
  //#region src/descriptors/$client.d.ts
53
103
  /**
@@ -57,8 +107,6 @@ declare const $client: {
57
107
  <T extends object>(scope?: ClientScope): HttpVirtualClient<T>;
58
108
  [KIND]: string;
59
109
  };
60
- //# sourceMappingURL=$client.d.ts.map
61
-
62
110
  //#endregion
63
111
  //#region src/descriptors/$remote.d.ts
64
112
  /**
@@ -121,18 +169,17 @@ interface RemoteDescriptorOptions {
121
169
  declare class RemoteDescriptor extends Descriptor<RemoteDescriptorOptions> {
122
170
  get name(): string;
123
171
  }
124
- //# sourceMappingURL=$remote.d.ts.map
125
172
  //#endregion
126
173
  //#region src/providers/RemoteDescriptorProvider.d.ts
127
174
  declare class RemoteDescriptorProvider {
128
- static path: {
129
- apiLinks: string;
175
+ protected readonly env: {
176
+ SERVER_API_PREFIX: string;
130
177
  };
131
178
  protected readonly alepha: Alepha;
132
- protected readonly client: LinkProvider;
133
179
  protected readonly proxyProvider: ServerProxyProvider;
180
+ protected readonly linkProvider: LinkProvider;
134
181
  protected readonly remotes: Array<ServerRemote>;
135
- protected readonly log: Logger;
182
+ protected readonly log: _alepha_logger0.Logger;
136
183
  getRemotes(): ServerRemote[];
137
184
  readonly configure: _alepha_core2.HookDescriptor<"configure">;
138
185
  readonly start: _alepha_core2.HookDescriptor<"start">;
@@ -140,64 +187,130 @@ declare class RemoteDescriptorProvider {
140
187
  protected readonly fetchLinks: _alepha_retry0.RetryDescriptorFn<(opts: FetchLinksOptions) => Promise<ApiLinksResponse>>;
141
188
  }
142
189
  interface FetchLinksOptions {
190
+ /**
191
+ * Name of the remote service.
192
+ */
143
193
  service: string;
194
+ /**
195
+ * URL to fetch links from.
196
+ */
144
197
  url: string;
198
+ /**
199
+ * Authorization header containing access token.
200
+ */
145
201
  authorization?: string;
146
202
  }
147
203
  interface ServerRemote {
204
+ /**
205
+ * URL of the remote service.
206
+ */
148
207
  url: string;
208
+ /**
209
+ * Name of the remote service.
210
+ */
149
211
  name: string;
212
+ /**
213
+ * Expose links as endpoint. It's not only internal.
214
+ */
150
215
  proxy: boolean;
216
+ /**
217
+ * It's only used inside the application.
218
+ */
151
219
  internal: boolean;
220
+ /**
221
+ * Links fetcher.
222
+ */
152
223
  links: (args: {
153
224
  authorization?: string;
154
225
  }) => Promise<ApiLinksResponse>;
226
+ /**
227
+ * Fetches schema for the remote service.
228
+ */
155
229
  schema: (args: {
156
230
  name: string;
157
231
  authorization?: string;
158
232
  }) => Promise<any>;
233
+ /**
234
+ * Force a default access token provider when not provided.
235
+ */
159
236
  serviceAccount?: ServiceAccountDescriptor;
237
+ /**
238
+ * Prefix for the remote service links.
239
+ */
160
240
  prefix: string;
161
241
  }
162
- //# sourceMappingURL=RemoteDescriptorProvider.d.ts.map
163
242
  //#endregion
164
243
  //#region src/providers/ServerLinksProvider.d.ts
165
244
  declare class ServerLinksProvider {
245
+ protected readonly env: {
246
+ SERVER_API_PREFIX: string;
247
+ };
166
248
  protected readonly alepha: Alepha;
167
- protected readonly client: LinkProvider;
249
+ protected readonly linkProvider: LinkProvider;
168
250
  protected readonly remoteProvider: RemoteDescriptorProvider;
169
- readonly onRoute: _alepha_core1.HookDescriptor<"configure">;
251
+ protected readonly serverTimingProvider: ServerTimingProvider;
252
+ get prefix(): string;
253
+ readonly onRoute: _alepha_core2.HookDescriptor<"configure">;
254
+ /**
255
+ * First API - Get all API links for the user.
256
+ *
257
+ * This is based on the user's permissions.
258
+ */
170
259
  readonly links: _alepha_server0.RouteDescriptor<{
171
260
  response: _sinclair_typebox0.TObject<{
172
261
  prefix: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
173
262
  links: _sinclair_typebox0.TArray<_sinclair_typebox0.TObject<{
174
263
  name: _sinclair_typebox0.TString;
264
+ group: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
175
265
  path: _sinclair_typebox0.TString;
176
266
  method: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
177
- group: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
178
267
  requestBodyType: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
179
268
  service: _sinclair_typebox0.TOptional<_sinclair_typebox0.TString>;
180
269
  }>>;
181
270
  }>;
182
271
  }>;
272
+ /**
273
+ * Second API - Get schema for a specific API link.
274
+ *
275
+ * Note: Body/Response schema are not included in `links` API because it's TOO BIG.
276
+ * I mean for 150+ links, you got 50ms of serialization time.
277
+ */
183
278
  readonly schema: _alepha_server0.RouteDescriptor<{
184
279
  params: _sinclair_typebox0.TObject<{
185
280
  name: _sinclair_typebox0.TString;
186
281
  }>;
187
282
  response: _sinclair_typebox0.TRecord<_sinclair_typebox0.TString, _sinclair_typebox0.TAny>;
188
283
  }>;
189
- getLinks(options: GetLinksOptions): Promise<ApiLinksResponse>;
284
+ getSchemaByName(name: string, options?: GetApiLinksOptions): Promise<RequestConfigSchema>;
285
+ /**
286
+ * Retrieves API links for the user based on their permissions.
287
+ * Will check on local links and remote links.
288
+ */
289
+ getUserApiLinks(options: GetApiLinksOptions): Promise<ApiLinksResponse>;
190
290
  }
191
- interface GetLinksOptions {
291
+ interface GetApiLinksOptions {
192
292
  user?: UserAccountToken;
193
293
  authorization?: string;
194
294
  }
195
- //# sourceMappingURL=ServerLinksProvider.d.ts.map
196
295
  //#endregion
197
296
  //#region src/index.d.ts
198
- declare const AlephaServerLinks: _alepha_core0.Service<_alepha_core0.Module>;
199
- //# sourceMappingURL=index.d.ts.map
200
-
297
+ declare module "alepha" {
298
+ interface State {
299
+ api?: ApiLinksResponse;
300
+ }
301
+ }
302
+ /**
303
+ * Provides server-side link management and remote capabilities for client-server interactions.
304
+ *
305
+ * The server-links module enables declarative link definitions using `$remote` and `$client` descriptors,
306
+ * facilitating seamless API endpoint management and client-server communication. It integrates with server
307
+ * security features to ensure safe and controlled access to resources.
308
+ *
309
+ * @see {@link $remote}
310
+ * @see {@link $client}
311
+ * @module alepha.server.links
312
+ */
313
+ declare const AlephaServerLinks: _alepha_core2.Service<_alepha_core2.Module>;
201
314
  //#endregion
202
- export { $client, $remote, AlephaServerLinks, ClientScope, FetchLinksOptions, GetLinksOptions, HttpClientLink, HttpVirtualClient, LinkProvider, RemoteDescriptor, RemoteDescriptorOptions, RemoteDescriptorProvider, ServerLinksProvider, ServerRemote, VirtualAction };
315
+ export { $client, $remote, AlephaServerLinks, ApiLink, ApiLinksResponse, ClientScope, FetchLinksOptions, GetApiLinksOptions, HttpClientLink, HttpVirtualClient, LinkProvider, RemoteDescriptor, RemoteDescriptorOptions, RemoteDescriptorProvider, ServerLinksProvider, ServerRemote, VirtualAction, apiLinkSchema, apiLinksResponseSchema };
203
316
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,4 @@
1
1
  import * as _alepha_core1 from "alepha";
2
- import * as _alepha_core0 from "alepha";
3
2
  import { Alepha } from "alepha";
4
3
  import * as _alepha_server0 from "alepha/server";
5
4
  import { Histogram, Registry } from "prom-client";
@@ -21,7 +20,6 @@ interface ServerMetricsProviderOptions {
21
20
  eventLoopMonitoringPrecision?: number;
22
21
  labels?: object;
23
22
  }
24
- //# sourceMappingURL=ServerMetricsProvider.d.ts.map
25
23
  //#endregion
26
24
  //#region src/index.d.ts
27
25
  /**
@@ -31,9 +29,7 @@ interface ServerMetricsProviderOptions {
31
29
  * @see {@link ServerMetricsProvider}
32
30
  * @module alepha.server.metrics
33
31
  */
34
- declare const AlephaServerMetrics: _alepha_core0.Service<_alepha_core0.Module>;
35
- //# sourceMappingURL=index.d.ts.map
36
-
32
+ declare const AlephaServerMetrics: _alepha_core1.Service<_alepha_core1.Module>;
37
33
  //#endregion
38
34
  export { AlephaServerMetrics, ServerMetricsProvider, ServerMetricsProviderOptions };
39
35
  //# sourceMappingURL=index.d.ts.map
@@ -37,8 +37,6 @@ interface HybridFile extends FileLike {
37
37
  * @module alepha.server.multipart
38
38
  */
39
39
  declare const AlephaServerMultipart: _alepha_core0.Service<_alepha_core0.Module>;
40
- //# sourceMappingURL=index.d.ts.map
41
-
42
40
  //#endregion
43
41
  export { AlephaServerMultipart, ServerMultipartProvider };
44
42
  //# sourceMappingURL=index.d.ts.map
package/server/proxy.d.ts CHANGED
@@ -1,27 +1,218 @@
1
1
  import * as _alepha_core1 from "alepha";
2
- import * as _alepha_core0 from "alepha";
3
2
  import { Alepha, Async, Descriptor, KIND } from "alepha";
4
3
  import { ServerHandler, ServerRequest, ServerRouterProvider } from "alepha/server";
4
+ import * as _alepha_logger0 from "alepha/logger";
5
5
 
6
6
  //#region src/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
+ */
7
91
  declare const $proxy: {
8
92
  (options: ProxyDescriptorOptions): ProxyDescriptor;
9
93
  [KIND]: typeof ProxyDescriptor;
10
94
  };
11
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
+ */
12
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
+ */
13
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
+ */
14
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
+ */
15
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
+ */
16
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
+ */
17
209
  rewrite?: (url: URL) => void;
18
210
  };
19
211
  declare class ProxyDescriptor extends Descriptor<ProxyDescriptorOptions> {}
20
- //# sourceMappingURL=$proxy.d.ts.map
21
212
  //#endregion
22
213
  //#region src/providers/ServerProxyProvider.d.ts
23
214
  declare class ServerProxyProvider {
24
- protected readonly log: _alepha_core1.Logger;
215
+ protected readonly log: _alepha_logger0.Logger;
25
216
  protected readonly routerProvider: ServerRouterProvider;
26
217
  protected readonly alepha: Alepha;
27
218
  protected readonly configure: _alepha_core1.HookDescriptor<"configure">;
@@ -29,7 +220,6 @@ declare class ServerProxyProvider {
29
220
  createProxyHandler(target: string, options: Omit<ProxyDescriptorOptions, "path">): ServerHandler;
30
221
  private getRawRequestBody;
31
222
  }
32
- //# sourceMappingURL=ServerProxyProvider.d.ts.map
33
223
  //#endregion
34
224
  //#region src/index.d.ts
35
225
  /**
@@ -38,9 +228,7 @@ declare class ServerProxyProvider {
38
228
  * @see {@link $proxy}
39
229
  * @module alepha.server.proxy
40
230
  */
41
- declare const AlephaServerProxy: _alepha_core0.Service<_alepha_core0.Module>;
42
- //# sourceMappingURL=index.d.ts.map
43
-
231
+ declare const AlephaServerProxy: _alepha_core1.Service<_alepha_core1.Module>;
44
232
  //#endregion
45
233
  export { $proxy, AlephaServerProxy, ProxyDescriptor, ProxyDescriptorOptions, ServerProxyProvider };
46
234
  //# sourceMappingURL=index.d.ts.map