alepha 0.9.4 → 0.10.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/LICENSE +21 -21
- package/README.md +47 -93
- package/batch.d.ts +491 -16
- package/bucket.d.ts +449 -12
- package/cache.d.ts +132 -1
- package/command.d.ts +32 -8
- package/core.d.ts +462 -369
- package/email.cjs +8 -0
- package/email.d.ts +328 -0
- package/email.js +1 -0
- package/lock.d.ts +412 -23
- package/logger.d.ts +83 -45
- package/package.json +62 -44
- package/postgres.d.ts +1731 -205
- package/queue/redis.d.ts +3 -3
- package/queue.d.ts +591 -8
- package/react/auth.d.ts +101 -112
- package/react/form.d.ts +14 -4
- package/react/head.d.ts +1 -1
- package/react/i18n.d.ts +13 -5
- package/react.d.ts +318 -180
- package/redis.d.ts +11 -11
- package/router.d.ts +1 -0
- package/security.d.ts +29 -29
- package/server/cache.d.ts +1 -0
- package/server/health.d.ts +6 -6
- package/server/links.d.ts +40 -29
- package/server/proxy.d.ts +192 -0
- package/server.d.ts +645 -88
- package/topic.d.ts +803 -12
- package/vite.d.ts +32 -4
package/redis.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { Alepha, Static
|
|
1
|
+
import * as _alepha_core3 from "alepha";
|
|
2
|
+
import { Alepha, Static } from "alepha";
|
|
3
3
|
import * as _alepha_logger0 from "alepha/logger";
|
|
4
4
|
import { RedisClientType, SetOptions, createClient } from "@redis/client";
|
|
5
5
|
|
|
6
6
|
//#region src/providers/RedisProvider.d.ts
|
|
7
|
-
declare const envSchema: TObject<{
|
|
8
|
-
REDIS_PORT:
|
|
9
|
-
REDIS_HOST: TString;
|
|
10
|
-
REDIS_PASSWORD: TOptional<TString>;
|
|
7
|
+
declare const envSchema: _alepha_core3.TObject<{
|
|
8
|
+
REDIS_PORT: _alepha_core3.TInteger;
|
|
9
|
+
REDIS_HOST: _alepha_core3.TString;
|
|
10
|
+
REDIS_PASSWORD: _alepha_core3.TOptional<_alepha_core3.TString>;
|
|
11
11
|
}>;
|
|
12
12
|
declare module "alepha" {
|
|
13
13
|
interface Env extends Partial<Static<typeof envSchema>> {}
|
|
@@ -30,8 +30,8 @@ declare class RedisProvider {
|
|
|
30
30
|
};
|
|
31
31
|
protected readonly client: RedisClient;
|
|
32
32
|
get publisher(): RedisClient;
|
|
33
|
-
protected readonly start:
|
|
34
|
-
protected readonly stop:
|
|
33
|
+
protected readonly start: _alepha_core3.HookDescriptor<"start">;
|
|
34
|
+
protected readonly stop: _alepha_core3.HookDescriptor<"stop">;
|
|
35
35
|
/**
|
|
36
36
|
* Connect to the Redis server.
|
|
37
37
|
*/
|
|
@@ -59,8 +59,8 @@ declare class RedisSubscriberProvider {
|
|
|
59
59
|
protected readonly redisProvider: RedisProvider;
|
|
60
60
|
protected readonly client: RedisClient;
|
|
61
61
|
get subscriber(): RedisClient;
|
|
62
|
-
protected readonly start:
|
|
63
|
-
protected readonly stop:
|
|
62
|
+
protected readonly start: _alepha_core3.HookDescriptor<"start">;
|
|
63
|
+
protected readonly stop: _alepha_core3.HookDescriptor<"stop">;
|
|
64
64
|
connect(): Promise<void>;
|
|
65
65
|
close(): Promise<void>;
|
|
66
66
|
/**
|
|
@@ -76,7 +76,7 @@ declare class RedisSubscriberProvider {
|
|
|
76
76
|
* @see {@link RedisProvider}
|
|
77
77
|
* @module alepha.redis
|
|
78
78
|
*/
|
|
79
|
-
declare const AlephaRedis:
|
|
79
|
+
declare const AlephaRedis: _alepha_core3.Service<_alepha_core3.Module>;
|
|
80
80
|
//#endregion
|
|
81
81
|
export { AlephaRedis, RedisClient, RedisClientOptions, RedisProvider, RedisSetOptions, RedisSubscriberProvider };
|
|
82
82
|
//# sourceMappingURL=index.d.ts.map
|
package/router.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ declare abstract class RouterProvider<T extends Route = Route> {
|
|
|
3
3
|
protected routePathRegex: RegExp;
|
|
4
4
|
protected tree: Tree<T>;
|
|
5
5
|
match(path: string): RouteMatch<T>;
|
|
6
|
+
protected test(path: string): void;
|
|
6
7
|
protected push(route: T): void;
|
|
7
8
|
protected createRouteMatch(path: string): RouteMatch<T>;
|
|
8
9
|
protected mapParams(match: RouteMatch<T>): RouteMatch<T>;
|
package/security.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import * as _alepha_core1 from "alepha";
|
|
2
2
|
import { Alepha, Descriptor, KIND, Static } from "alepha";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _alepha_logger0 from "alepha/logger";
|
|
4
4
|
import { DateTimeProvider, Duration, DurationLike } from "alepha/datetime";
|
|
5
5
|
import { CryptoKey, FlattenedJWSInput, JSONWebKeySet, JWSHeaderParameters, JWTHeaderParameters, JWTPayload, JWTVerifyResult, KeyObject } from "jose";
|
|
6
|
-
import * as
|
|
6
|
+
import * as typebox0 from "typebox";
|
|
7
7
|
import { JWTVerifyOptions } from "jose/jwt/verify";
|
|
8
8
|
|
|
9
9
|
//#region src/schemas/userAccountInfoSchema.d.ts
|
|
10
|
-
declare const userAccountInfoSchema:
|
|
11
|
-
id:
|
|
12
|
-
name:
|
|
13
|
-
email:
|
|
14
|
-
username:
|
|
15
|
-
picture:
|
|
16
|
-
sessionId:
|
|
17
|
-
organizations:
|
|
18
|
-
roles:
|
|
10
|
+
declare const userAccountInfoSchema: typebox0.TObject<{
|
|
11
|
+
id: typebox0.TString;
|
|
12
|
+
name: typebox0.TOptional<typebox0.TString>;
|
|
13
|
+
email: typebox0.TOptional<typebox0.TString>;
|
|
14
|
+
username: typebox0.TOptional<typebox0.TString>;
|
|
15
|
+
picture: typebox0.TOptional<typebox0.TString>;
|
|
16
|
+
sessionId: typebox0.TOptional<typebox0.TString>;
|
|
17
|
+
organizations: typebox0.TOptional<typebox0.TArray<typebox0.TString>>;
|
|
18
|
+
roles: typebox0.TOptional<typebox0.TArray<typebox0.TString>>;
|
|
19
19
|
}>;
|
|
20
20
|
type UserAccount = Static<typeof userAccountInfoSchema>;
|
|
21
21
|
//#endregion
|
|
@@ -41,24 +41,24 @@ interface UserAccountToken extends UserAccount {
|
|
|
41
41
|
}
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/schemas/permissionSchema.d.ts
|
|
44
|
-
declare const permissionSchema:
|
|
45
|
-
name:
|
|
46
|
-
group:
|
|
47
|
-
description:
|
|
48
|
-
method:
|
|
49
|
-
path:
|
|
44
|
+
declare const permissionSchema: typebox0.TObject<{
|
|
45
|
+
name: typebox0.TString;
|
|
46
|
+
group: typebox0.TOptional<typebox0.TString>;
|
|
47
|
+
description: typebox0.TOptional<typebox0.TString>;
|
|
48
|
+
method: typebox0.TOptional<typebox0.TString>;
|
|
49
|
+
path: typebox0.TOptional<typebox0.TString>;
|
|
50
50
|
}>;
|
|
51
51
|
type Permission = Static<typeof permissionSchema>;
|
|
52
52
|
//#endregion
|
|
53
53
|
//#region src/schemas/roleSchema.d.ts
|
|
54
|
-
declare const roleSchema:
|
|
55
|
-
name:
|
|
56
|
-
description:
|
|
57
|
-
default:
|
|
58
|
-
permissions:
|
|
59
|
-
name:
|
|
60
|
-
ownership:
|
|
61
|
-
exclude:
|
|
54
|
+
declare const roleSchema: typebox0.TObject<{
|
|
55
|
+
name: typebox0.TString;
|
|
56
|
+
description: typebox0.TOptional<typebox0.TString>;
|
|
57
|
+
default: typebox0.TOptional<typebox0.TBoolean>;
|
|
58
|
+
permissions: typebox0.TArray<typebox0.TObject<{
|
|
59
|
+
name: typebox0.TString;
|
|
60
|
+
ownership: typebox0.TOptional<typebox0.TBoolean>;
|
|
61
|
+
exclude: typebox0.TOptional<typebox0.TArray<typebox0.TString>>;
|
|
62
62
|
}>>;
|
|
63
63
|
}>;
|
|
64
64
|
type Role = Static<typeof roleSchema>;
|
|
@@ -68,7 +68,7 @@ type Role = Static<typeof roleSchema>;
|
|
|
68
68
|
* Provides utilities for working with JSON Web Tokens (JWT).
|
|
69
69
|
*/
|
|
70
70
|
declare class JwtProvider {
|
|
71
|
-
protected readonly log:
|
|
71
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
72
72
|
protected readonly keystore: KeyLoaderHolder[];
|
|
73
73
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
74
74
|
protected readonly encoder: TextEncoder;
|
|
@@ -140,7 +140,7 @@ declare class SecurityProvider {
|
|
|
140
140
|
protected readonly UNKNOWN_USER_NAME = "Anonymous User";
|
|
141
141
|
protected readonly PERMISSION_REGEXP: RegExp;
|
|
142
142
|
protected readonly PERMISSION_REGEXP_WILDCARD: RegExp;
|
|
143
|
-
protected readonly log:
|
|
143
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
144
144
|
protected readonly jwt: JwtProvider;
|
|
145
145
|
protected readonly env: {
|
|
146
146
|
SECURITY_SECRET_KEY: string;
|
|
@@ -154,7 +154,7 @@ declare class SecurityProvider {
|
|
|
154
154
|
* The realms configured for the security provider.
|
|
155
155
|
*/
|
|
156
156
|
protected readonly realms: Realm[];
|
|
157
|
-
protected
|
|
157
|
+
protected start: _alepha_core1.HookDescriptor<"start">;
|
|
158
158
|
/**
|
|
159
159
|
* Adds a role to one or more realms.
|
|
160
160
|
*
|
|
@@ -397,7 +397,7 @@ declare class RealmDescriptor extends Descriptor<RealmDescriptorOptions> {
|
|
|
397
397
|
protected readonly securityProvider: SecurityProvider;
|
|
398
398
|
protected readonly dateTimeProvider: DateTimeProvider;
|
|
399
399
|
protected readonly jwt: JwtProvider;
|
|
400
|
-
protected readonly log:
|
|
400
|
+
protected readonly log: _alepha_logger0.Logger;
|
|
401
401
|
get name(): string;
|
|
402
402
|
get accessTokenExpiration(): Duration;
|
|
403
403
|
get refreshTokenExpiration(): Duration;
|
package/server/cache.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { RequestConfigSchema, ServerRequest, ServerRoute } from "alepha/server";
|
|
|
10
10
|
declare module "alepha/server" {
|
|
11
11
|
interface ServerRoute {
|
|
12
12
|
cache?: ServerRouteCache;
|
|
13
|
+
etag?: string;
|
|
13
14
|
}
|
|
14
15
|
interface ActionDescriptor<TConfig extends RequestConfigSchema> {
|
|
15
16
|
invalidate: () => Promise<void>;
|
package/server/health.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _alepha_core0 from "alepha";
|
|
|
2
2
|
import { Alepha } from "alepha";
|
|
3
3
|
import * as _alepha_server0 from "alepha/server";
|
|
4
4
|
import { DateTimeProvider } from "alepha/datetime";
|
|
5
|
-
import * as
|
|
5
|
+
import * as typebox0 from "typebox";
|
|
6
6
|
|
|
7
7
|
//#region src/providers/ServerHealthProvider.d.ts
|
|
8
8
|
/**
|
|
@@ -14,11 +14,11 @@ declare class ServerHealthProvider {
|
|
|
14
14
|
protected readonly time: DateTimeProvider;
|
|
15
15
|
protected readonly alepha: Alepha;
|
|
16
16
|
readonly health: _alepha_server0.RouteDescriptor<{
|
|
17
|
-
response:
|
|
18
|
-
message:
|
|
19
|
-
uptime:
|
|
20
|
-
date:
|
|
21
|
-
ready:
|
|
17
|
+
response: typebox0.TObject<{
|
|
18
|
+
message: typebox0.TString;
|
|
19
|
+
uptime: typebox0.TNumber;
|
|
20
|
+
date: typebox0.TString;
|
|
21
|
+
ready: typebox0.TBoolean;
|
|
22
22
|
}>;
|
|
23
23
|
}>;
|
|
24
24
|
}
|
package/server/links.d.ts
CHANGED
|
@@ -7,26 +7,26 @@ 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
|
-
import * as
|
|
10
|
+
import * as typebox0 from "typebox";
|
|
11
11
|
|
|
12
12
|
//#region src/schemas/apiLinksResponseSchema.d.ts
|
|
13
|
-
declare const apiLinkSchema:
|
|
14
|
-
name:
|
|
15
|
-
group:
|
|
16
|
-
path:
|
|
17
|
-
method:
|
|
18
|
-
requestBodyType:
|
|
19
|
-
service:
|
|
13
|
+
declare const apiLinkSchema: typebox0.TObject<{
|
|
14
|
+
name: typebox0.TString;
|
|
15
|
+
group: typebox0.TOptional<typebox0.TString>;
|
|
16
|
+
path: typebox0.TString;
|
|
17
|
+
method: typebox0.TOptional<typebox0.TString>;
|
|
18
|
+
requestBodyType: typebox0.TOptional<typebox0.TString>;
|
|
19
|
+
service: typebox0.TOptional<typebox0.TString>;
|
|
20
20
|
}>;
|
|
21
|
-
declare const apiLinksResponseSchema:
|
|
22
|
-
prefix:
|
|
23
|
-
links:
|
|
24
|
-
name:
|
|
25
|
-
group:
|
|
26
|
-
path:
|
|
27
|
-
method:
|
|
28
|
-
requestBodyType:
|
|
29
|
-
service:
|
|
21
|
+
declare const apiLinksResponseSchema: typebox0.TObject<{
|
|
22
|
+
prefix: typebox0.TOptional<typebox0.TString>;
|
|
23
|
+
links: typebox0.TArray<typebox0.TObject<{
|
|
24
|
+
name: typebox0.TString;
|
|
25
|
+
group: typebox0.TOptional<typebox0.TString>;
|
|
26
|
+
path: typebox0.TString;
|
|
27
|
+
method: typebox0.TOptional<typebox0.TString>;
|
|
28
|
+
requestBodyType: typebox0.TOptional<typebox0.TString>;
|
|
29
|
+
service: typebox0.TOptional<typebox0.TString>;
|
|
30
30
|
}>>;
|
|
31
31
|
}>;
|
|
32
32
|
type ApiLinksResponse = Static<typeof apiLinksResponseSchema>;
|
|
@@ -257,15 +257,15 @@ declare class ServerLinksProvider {
|
|
|
257
257
|
* This is based on the user's permissions.
|
|
258
258
|
*/
|
|
259
259
|
readonly links: _alepha_server0.RouteDescriptor<{
|
|
260
|
-
response:
|
|
261
|
-
prefix:
|
|
262
|
-
links:
|
|
263
|
-
name:
|
|
264
|
-
group:
|
|
265
|
-
path:
|
|
266
|
-
method:
|
|
267
|
-
requestBodyType:
|
|
268
|
-
service:
|
|
260
|
+
response: typebox0.TObject<{
|
|
261
|
+
prefix: typebox0.TOptional<typebox0.TString>;
|
|
262
|
+
links: typebox0.TArray<typebox0.TObject<{
|
|
263
|
+
name: typebox0.TString;
|
|
264
|
+
group: typebox0.TOptional<typebox0.TString>;
|
|
265
|
+
path: typebox0.TString;
|
|
266
|
+
method: typebox0.TOptional<typebox0.TString>;
|
|
267
|
+
requestBodyType: typebox0.TOptional<typebox0.TString>;
|
|
268
|
+
service: typebox0.TOptional<typebox0.TString>;
|
|
269
269
|
}>>;
|
|
270
270
|
}>;
|
|
271
271
|
}>;
|
|
@@ -276,10 +276,10 @@ declare class ServerLinksProvider {
|
|
|
276
276
|
* I mean for 150+ links, you got 50ms of serialization time.
|
|
277
277
|
*/
|
|
278
278
|
readonly schema: _alepha_server0.RouteDescriptor<{
|
|
279
|
-
params:
|
|
280
|
-
name:
|
|
279
|
+
params: typebox0.TObject<{
|
|
280
|
+
name: typebox0.TString;
|
|
281
281
|
}>;
|
|
282
|
-
response:
|
|
282
|
+
response: typebox0.TRecord<string, typebox0.TAny>;
|
|
283
283
|
}>;
|
|
284
284
|
getSchemaByName(name: string, options?: GetApiLinksOptions): Promise<RequestConfigSchema>;
|
|
285
285
|
/**
|
|
@@ -299,6 +299,17 @@ declare module "alepha" {
|
|
|
299
299
|
api?: ApiLinksResponse;
|
|
300
300
|
}
|
|
301
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
|
+
*/
|
|
302
313
|
declare const AlephaServerLinks: _alepha_core2.Service<_alepha_core2.Module>;
|
|
303
314
|
//#endregion
|
|
304
315
|
export { $client, $remote, AlephaServerLinks, ApiLink, ApiLinksResponse, ClientScope, FetchLinksOptions, GetApiLinksOptions, HttpClientLink, HttpVirtualClient, LinkProvider, RemoteDescriptor, RemoteDescriptorOptions, RemoteDescriptorProvider, ServerLinksProvider, ServerRemote, VirtualAction, apiLinkSchema, apiLinksResponseSchema };
|
package/server/proxy.d.ts
CHANGED
|
@@ -4,16 +4,208 @@ import { ServerHandler, ServerRequest, ServerRouterProvider } from "alepha/serve
|
|
|
4
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> {}
|