@beignet/core 0.0.3 → 0.0.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.
- package/CHANGELOG.md +159 -0
- package/README.md +792 -50
- package/dist/application/index.d.ts +28 -2
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +140 -12
- package/dist/application/index.js.map +1 -1
- package/dist/client/client.d.ts +2 -2
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +136 -48
- package/dist/client/client.js.map +1 -1
- package/dist/client/error-messages.d.ts +14 -0
- package/dist/client/error-messages.d.ts.map +1 -0
- package/dist/client/error-messages.js +23 -0
- package/dist/client/error-messages.js.map +1 -0
- package/dist/client/index.d.ts +8 -4
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +6 -2
- package/dist/client/index.js.map +1 -1
- package/dist/client/types.d.ts +35 -5
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client-only.d.ts +8 -0
- package/dist/client-only.d.ts.map +1 -0
- package/dist/client-only.js +8 -0
- package/dist/client-only.js.map +1 -0
- package/dist/config/index.d.ts +5 -5
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +2 -2
- package/dist/config/index.js.map +1 -1
- package/dist/contracts/catalog-errors.d.ts +27 -0
- package/dist/contracts/catalog-errors.d.ts.map +1 -0
- package/dist/contracts/catalog-errors.js +69 -0
- package/dist/contracts/catalog-errors.js.map +1 -0
- package/dist/contracts/contract-builder.d.ts +15 -12
- package/dist/contracts/contract-builder.d.ts.map +1 -1
- package/dist/contracts/contract-builder.js +15 -41
- package/dist/contracts/contract-builder.js.map +1 -1
- package/dist/contracts/contract-group.d.ts +11 -8
- package/dist/contracts/contract-group.d.ts.map +1 -1
- package/dist/contracts/contract-group.js +13 -40
- package/dist/contracts/contract-group.js.map +1 -1
- package/dist/contracts/contract-like.d.ts +1 -1
- package/dist/contracts/contract-like.d.ts.map +1 -1
- package/dist/contracts/index.d.ts +13 -9
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +9 -5
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/openapi-meta.d.ts +48 -0
- package/dist/contracts/openapi-meta.d.ts.map +1 -1
- package/dist/contracts/openapi-meta.js +3 -0
- package/dist/contracts/openapi-meta.js.map +1 -1
- package/dist/contracts/path-template.d.ts +1 -1
- package/dist/contracts/path-template.js +2 -2
- package/dist/contracts/path-template.js.map +1 -1
- package/dist/contracts/schema-shape.d.ts +37 -0
- package/dist/contracts/schema-shape.d.ts.map +1 -0
- package/dist/contracts/schema-shape.js +61 -0
- package/dist/contracts/schema-shape.js.map +1 -0
- package/dist/contracts/success-status.d.ts +32 -0
- package/dist/contracts/success-status.d.ts.map +1 -0
- package/dist/contracts/success-status.js +18 -0
- package/dist/contracts/success-status.js.map +1 -0
- package/dist/contracts/types.d.ts +25 -5
- package/dist/contracts/types.d.ts.map +1 -1
- package/dist/contracts/types.js.map +1 -1
- package/dist/contracts/utils.d.ts +1 -1
- package/dist/contracts/utils.d.ts.map +1 -1
- package/dist/contracts/utils.js +1 -1
- package/dist/contracts/utils.js.map +1 -1
- package/dist/domain/events.d.ts +1 -1
- package/dist/domain/events.d.ts.map +1 -1
- package/dist/domain/events.js +1 -1
- package/dist/domain/events.js.map +1 -1
- package/dist/domain/index.d.ts +3 -3
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js +3 -3
- package/dist/domain/index.js.map +1 -1
- package/dist/errors/catalog.d.ts +9 -1
- package/dist/errors/catalog.d.ts.map +1 -1
- package/dist/errors/catalog.js +7 -1
- package/dist/errors/catalog.js.map +1 -1
- package/dist/errors/http.d.ts +10 -0
- package/dist/errors/http.d.ts.map +1 -1
- package/dist/errors/http.js +11 -1
- package/dist/errors/http.js.map +1 -1
- package/dist/errors/index.d.ts +4 -4
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +4 -4
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/response.d.ts +4 -1
- package/dist/errors/response.d.ts.map +1 -1
- package/dist/errors/response.js.map +1 -1
- package/dist/events/index.d.ts +10 -12
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +10 -10
- package/dist/events/index.js.map +1 -1
- package/dist/idempotency/index.d.ts +5 -3
- package/dist/idempotency/index.d.ts.map +1 -1
- package/dist/idempotency/index.js.map +1 -1
- package/dist/jobs/index.d.ts +12 -14
- package/dist/jobs/index.d.ts.map +1 -1
- package/dist/jobs/index.js +13 -13
- package/dist/jobs/index.js.map +1 -1
- package/dist/notifications/index.d.ts +14 -16
- package/dist/notifications/index.d.ts.map +1 -1
- package/dist/notifications/index.js +14 -14
- package/dist/notifications/index.js.map +1 -1
- package/dist/openapi/index.d.ts +8 -3
- package/dist/openapi/index.d.ts.map +1 -1
- package/dist/openapi/index.js +41 -29
- package/dist/openapi/index.js.map +1 -1
- package/dist/openapi/schema-introspector.d.ts +37 -0
- package/dist/openapi/schema-introspector.d.ts.map +1 -1
- package/dist/openapi/schema-introspector.js +23 -17
- package/dist/openapi/schema-introspector.js.map +1 -1
- package/dist/outbox/index.d.ts +15 -6
- package/dist/outbox/index.d.ts.map +1 -1
- package/dist/outbox/index.js +60 -16
- package/dist/outbox/index.js.map +1 -1
- package/dist/ports/audit.d.ts +56 -10
- package/dist/ports/audit.d.ts.map +1 -1
- package/dist/ports/audit.js +71 -3
- package/dist/ports/audit.js.map +1 -1
- package/dist/ports/auth.d.ts +92 -0
- package/dist/ports/auth.d.ts.map +1 -1
- package/dist/ports/auth.js +92 -0
- package/dist/ports/auth.js.map +1 -1
- package/dist/ports/events.d.ts +2 -2
- package/dist/ports/events.d.ts.map +1 -1
- package/dist/ports/index.d.ts +62 -33
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +28 -34
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/policy.d.ts +32 -3
- package/dist/ports/policy.d.ts.map +1 -1
- package/dist/ports/policy.js +13 -2
- package/dist/ports/policy.js.map +1 -1
- package/dist/ports/testing.d.ts +1030 -2
- package/dist/ports/testing.d.ts.map +1 -1
- package/dist/ports/testing.js +1031 -1
- package/dist/ports/testing.js.map +1 -1
- package/dist/ports/unbound.d.ts +21 -0
- package/dist/ports/unbound.d.ts.map +1 -0
- package/dist/ports/unbound.js +57 -0
- package/dist/ports/unbound.js.map +1 -0
- package/dist/ports/unit-of-work.d.ts +1 -1
- package/dist/ports/unit-of-work.d.ts.map +1 -1
- package/dist/ports/unit-of-work.js +1 -1
- package/dist/ports/unit-of-work.js.map +1 -1
- package/dist/providers/index.d.ts +3 -2
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +3 -2
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/instrumentation.d.ts +45 -4
- package/dist/providers/instrumentation.d.ts.map +1 -1
- package/dist/providers/instrumentation.js +25 -6
- package/dist/providers/instrumentation.js.map +1 -1
- package/dist/providers/metadata.d.ts +39 -0
- package/dist/providers/metadata.d.ts.map +1 -0
- package/dist/providers/metadata.js +169 -0
- package/dist/providers/metadata.js.map +1 -0
- package/dist/providers/provider.d.ts +114 -9
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/provider.js +3 -20
- package/dist/providers/provider.js.map +1 -1
- package/dist/schedules/index.d.ts +94 -13
- package/dist/schedules/index.d.ts.map +1 -1
- package/dist/schedules/index.js +66 -12
- package/dist/schedules/index.js.map +1 -1
- package/dist/server/audit-context.d.ts +29 -0
- package/dist/server/audit-context.d.ts.map +1 -0
- package/dist/server/audit-context.js +44 -0
- package/dist/server/audit-context.js.map +1 -0
- package/dist/server/context.d.ts +141 -0
- package/dist/server/context.d.ts.map +1 -0
- package/dist/server/context.js +39 -0
- package/dist/server/context.js.map +1 -0
- package/dist/server/contract-like.d.ts +1 -1
- package/dist/server/contract-like.d.ts.map +1 -1
- package/dist/server/contract-like.js +1 -1
- package/dist/server/contract-like.js.map +1 -1
- package/dist/server/health.d.ts +2 -2
- package/dist/server/health.d.ts.map +1 -1
- package/dist/server/hooks/auth.d.ts +49 -10
- package/dist/server/hooks/auth.d.ts.map +1 -1
- package/dist/server/hooks/auth.js +77 -37
- package/dist/server/hooks/auth.js.map +1 -1
- package/dist/server/hooks/cors.d.ts +1 -1
- package/dist/server/hooks/cors.d.ts.map +1 -1
- package/dist/server/hooks/errors.d.ts +2 -2
- package/dist/server/hooks/errors.d.ts.map +1 -1
- package/dist/server/hooks/errors.js +2 -2
- package/dist/server/hooks/errors.js.map +1 -1
- package/dist/server/hooks/idempotency.d.ts +78 -0
- package/dist/server/hooks/idempotency.d.ts.map +1 -0
- package/dist/server/hooks/idempotency.js +154 -0
- package/dist/server/hooks/idempotency.js.map +1 -0
- package/dist/server/hooks/index.d.ts +8 -7
- package/dist/server/hooks/index.d.ts.map +1 -1
- package/dist/server/hooks/index.js +6 -5
- package/dist/server/hooks/index.js.map +1 -1
- package/dist/server/hooks/logging.d.ts +2 -2
- package/dist/server/hooks/logging.d.ts.map +1 -1
- package/dist/server/hooks/logging.js +1 -1
- package/dist/server/hooks/logging.js.map +1 -1
- package/dist/server/hooks/rate-limit.d.ts +25 -7
- package/dist/server/hooks/rate-limit.d.ts.map +1 -1
- package/dist/server/hooks/rate-limit.js +47 -12
- package/dist/server/hooks/rate-limit.js.map +1 -1
- package/dist/server/hooks.d.ts +1 -1
- package/dist/server/hooks.d.ts.map +1 -1
- package/dist/server/hooks.js +1 -1
- package/dist/server/hooks.js.map +1 -1
- package/dist/server/http.d.ts +61 -35
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js +1 -20
- package/dist/server/http.js.map +1 -1
- package/dist/server/index.d.ts +36 -12
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +24 -8
- package/dist/server/index.js.map +1 -1
- package/dist/server/instrumentation.d.ts +108 -0
- package/dist/server/instrumentation.d.ts.map +1 -0
- package/dist/server/instrumentation.js +297 -0
- package/dist/server/instrumentation.js.map +1 -0
- package/dist/server/openapi.d.ts +3 -3
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/openapi.js +1 -1
- package/dist/server/openapi.js.map +1 -1
- package/dist/server/providers/index.d.ts +3 -3
- package/dist/server/providers/index.d.ts.map +1 -1
- package/dist/server/providers/index.js +3 -3
- package/dist/server/providers/index.js.map +1 -1
- package/dist/server/providers/loadProviderConfig.d.ts +2 -2
- package/dist/server/providers/loadProviderConfig.d.ts.map +1 -1
- package/dist/server/providers/loadProviderConfig.js +2 -2
- package/dist/server/providers/loadProviderConfig.js.map +1 -1
- package/dist/server/request-context.d.ts +67 -0
- package/dist/server/request-context.d.ts.map +1 -0
- package/dist/server/request-context.js +79 -0
- package/dist/server/request-context.js.map +1 -0
- package/dist/server/server-context.d.ts +38 -0
- package/dist/server/server-context.d.ts.map +1 -0
- package/dist/server/server-context.js +38 -0
- package/dist/server/server-context.js.map +1 -0
- package/dist/server/server.d.ts +105 -33
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/server.js +434 -118
- package/dist/server/server.js.map +1 -1
- package/dist/server/types.d.ts +2 -2
- package/dist/server/types.d.ts.map +1 -1
- package/dist/server/types.js +2 -2
- package/dist/server/types.js.map +1 -1
- package/dist/server/use-case-route.d.ts +263 -0
- package/dist/server/use-case-route.d.ts.map +1 -0
- package/dist/server/use-case-route.js +77 -0
- package/dist/server/use-case-route.js.map +1 -0
- package/dist/server-only.d.ts +8 -0
- package/dist/server-only.d.ts.map +1 -0
- package/dist/server-only.js +8 -0
- package/dist/server-only.js.map +1 -0
- package/dist/tasks/index.d.ts +139 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/index.js +98 -0
- package/dist/tasks/index.js.map +1 -0
- package/dist/testing/index.d.ts +607 -5
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +426 -4
- package/dist/testing/index.js.map +1 -1
- package/dist/tracing/index.d.ts +89 -0
- package/dist/tracing/index.d.ts.map +1 -0
- package/dist/tracing/index.js +101 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/uploads/client.d.ts +1 -1
- package/dist/uploads/client.d.ts.map +1 -1
- package/dist/uploads/index.d.ts +2 -2
- package/dist/uploads/index.d.ts.map +1 -1
- package/dist/uploads/index.js +1 -1
- package/dist/uploads/index.js.map +1 -1
- package/package.json +24 -2
- package/src/application/index.ts +193 -10
- package/src/client/client.ts +148 -150
- package/src/client/error-messages.ts +35 -0
- package/src/client/index.ts +12 -4
- package/src/client/types.ts +44 -5
- package/src/client-only.ts +7 -0
- package/src/config/index.ts +6 -6
- package/src/contracts/catalog-errors.ts +115 -0
- package/src/contracts/contract-builder.ts +39 -76
- package/src/contracts/contract-group.ts +33 -68
- package/src/contracts/contract-like.ts +1 -1
- package/src/contracts/index.ts +24 -11
- package/src/contracts/openapi-meta.ts +55 -0
- package/src/contracts/path-template.ts +2 -2
- package/src/contracts/schema-shape.ts +75 -0
- package/src/contracts/success-status.ts +68 -0
- package/src/contracts/types.ts +32 -5
- package/src/contracts/utils.ts +5 -2
- package/src/domain/events.ts +6 -2
- package/src/domain/index.ts +3 -3
- package/src/errors/catalog.ts +9 -1
- package/src/errors/http.ts +11 -1
- package/src/errors/index.ts +4 -4
- package/src/errors/response.ts +4 -1
- package/src/events/index.ts +12 -26
- package/src/idempotency/index.ts +5 -3
- package/src/jobs/index.ts +14 -24
- package/src/notifications/index.ts +17 -27
- package/src/openapi/index.ts +73 -38
- package/src/openapi/schema-introspector.ts +68 -17
- package/src/outbox/index.ts +84 -19
- package/src/ports/audit.ts +120 -11
- package/src/ports/auth.ts +132 -0
- package/src/ports/events.ts +2 -2
- package/src/ports/index.ts +104 -35
- package/src/ports/policy.ts +50 -3
- package/src/ports/testing.ts +2220 -33
- package/src/ports/unbound.ts +64 -0
- package/src/ports/unit-of-work.ts +6 -2
- package/src/providers/index.ts +16 -3
- package/src/providers/instrumentation.ts +86 -7
- package/src/providers/metadata.ts +234 -0
- package/src/providers/provider.ts +168 -9
- package/src/schedules/index.ts +173 -23
- package/src/server/audit-context.ts +45 -0
- package/src/server/context.ts +224 -0
- package/src/server/contract-like.ts +1 -1
- package/src/server/health.ts +2 -2
- package/src/server/hooks/auth.ts +141 -51
- package/src/server/hooks/cors.ts +1 -1
- package/src/server/hooks/errors.ts +7 -4
- package/src/server/hooks/idempotency.ts +263 -0
- package/src/server/hooks/index.ts +14 -7
- package/src/server/hooks/logging.ts +3 -3
- package/src/server/hooks/rate-limit.ts +85 -17
- package/src/server/hooks.ts +1 -1
- package/src/server/http.ts +78 -51
- package/src/server/index.ts +62 -12
- package/src/server/instrumentation.ts +470 -0
- package/src/server/openapi.ts +4 -4
- package/src/server/providers/index.ts +6 -3
- package/src/server/providers/loadProviderConfig.ts +4 -4
- package/src/server/request-context.ts +116 -0
- package/src/server/server-context.ts +44 -0
- package/src/server/server.ts +886 -238
- package/src/server/types.ts +2 -2
- package/src/server/use-case-route.ts +430 -0
- package/src/server-only.ts +7 -0
- package/src/tasks/index.ts +275 -0
- package/src/testing/index.ts +1142 -6
- package/src/tracing/index.ts +176 -0
- package/src/uploads/client.ts +1 -1
- package/src/uploads/index.ts +7 -3
- package/dist/ports/mailer.d.ts +0 -6
- package/dist/ports/mailer.d.ts.map +0 -1
- package/dist/ports/mailer.js +0 -2
- package/dist/ports/mailer.js.map +0 -1
- package/dist/ports/schedules.d.ts +0 -9
- package/dist/ports/schedules.d.ts.map +0 -1
- package/dist/ports/schedules.js +0 -2
- package/dist/ports/schedules.js.map +0 -1
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Rate limit hooks for @beignet/core/server
|
|
3
3
|
*/
|
|
4
|
-
import { AppError, httpErrors } from "../../errors";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
import { AppError, httpErrors } from "../../errors/index.js";
|
|
5
|
+
import { createProviderInstrumentation, } from "../../providers/index.js";
|
|
6
|
+
function parseForwardedFor(req) {
|
|
7
|
+
const header = req.headers.get("x-forwarded-for") ?? "";
|
|
8
|
+
return header
|
|
9
|
+
.split(",")
|
|
10
|
+
.map((entry) => entry.trim())
|
|
11
|
+
.filter(Boolean);
|
|
12
|
+
}
|
|
13
|
+
function resolveClientIp(req, ipSource) {
|
|
14
|
+
if (typeof ipSource === "function") {
|
|
15
|
+
return ipSource(req) || undefined;
|
|
16
|
+
}
|
|
17
|
+
const entries = parseForwardedFor(req);
|
|
18
|
+
if (entries.length === 0) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return ipSource === "x-forwarded-for-first"
|
|
22
|
+
? entries[0]
|
|
23
|
+
: entries[entries.length - 1];
|
|
8
24
|
}
|
|
9
25
|
function emitUserKey(userId) {
|
|
10
26
|
return `user:${userId}`;
|
|
@@ -30,8 +46,8 @@ function defaultEarlyRateLimitKey(args, getClientIp) {
|
|
|
30
46
|
}
|
|
31
47
|
return "global";
|
|
32
48
|
}
|
|
33
|
-
async function enforceRateLimit(
|
|
34
|
-
const result = await rateLimit.hit({
|
|
49
|
+
async function enforceRateLimit(ports, args) {
|
|
50
|
+
const result = await ports.rateLimit.hit({
|
|
35
51
|
key: args.key,
|
|
36
52
|
limit: args.limit,
|
|
37
53
|
windowSec: args.windowSec,
|
|
@@ -39,8 +55,24 @@ async function enforceRateLimit(rateLimit, args) {
|
|
|
39
55
|
if (result.allowed) {
|
|
40
56
|
return;
|
|
41
57
|
}
|
|
58
|
+
// App ports may carry an `instrumentation` or `devtools` sink alongside the
|
|
59
|
+
// typed rate-limit port; the helper resolves them at runtime.
|
|
60
|
+
const instrumentation = createProviderInstrumentation(ports, {
|
|
61
|
+
providerName: "rate-limit",
|
|
62
|
+
watcher: "rateLimit",
|
|
63
|
+
});
|
|
64
|
+
instrumentation.custom({
|
|
65
|
+
name: "rateLimit.denied",
|
|
66
|
+
label: "Rate limit denied",
|
|
67
|
+
summary: `Rate limit denied for ${args.key}`,
|
|
68
|
+
details: {
|
|
69
|
+
key: args.key,
|
|
70
|
+
scope: args.scope,
|
|
71
|
+
limit: args.limit,
|
|
72
|
+
windowSec: args.windowSec,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
42
75
|
throw new AppError(httpErrors.TooManyRequests, {
|
|
43
|
-
key: args.key,
|
|
44
76
|
scope: args.scope,
|
|
45
77
|
retryAfterSeconds: result.retryAfterSeconds,
|
|
46
78
|
resetAt: result.resetAt?.toISOString() ?? null,
|
|
@@ -52,13 +84,16 @@ async function enforceRateLimit(rateLimit, args) {
|
|
|
52
84
|
* The hook reads `contract.metadata.rateLimit`. Global and IP-scoped limits run
|
|
53
85
|
* in `onRequest` before context creation; user-scoped limits run in
|
|
54
86
|
* `beforeHandle` after `ctx.actor` is available. Exceeded limits throw the
|
|
55
|
-
* framework `TooManyRequests` app error
|
|
87
|
+
* framework `TooManyRequests` app error with `scope`, `retryAfterSeconds`, and
|
|
88
|
+
* `resetAt` details. The bucket key is never sent to clients; denials emit a
|
|
89
|
+
* `rateLimit.denied` instrumentation event that carries the key for operators.
|
|
56
90
|
*
|
|
57
|
-
* @param options - Optional key builders and client-IP
|
|
91
|
+
* @param options - Optional key builders and client-IP source.
|
|
58
92
|
* @returns A server hook backed by `ctx.ports.rateLimit`.
|
|
59
93
|
*/
|
|
60
94
|
export function createRateLimitHooks(options = {}) {
|
|
61
|
-
const
|
|
95
|
+
const ipSource = options.ipSource ?? "x-forwarded-for-last";
|
|
96
|
+
const getClientIp = (req) => resolveClientIp(req, ipSource);
|
|
62
97
|
return {
|
|
63
98
|
name: "rate-limit",
|
|
64
99
|
onRequest: async ({ contract, ports, req }) => {
|
|
@@ -72,7 +107,7 @@ export function createRateLimitHooks(options = {}) {
|
|
|
72
107
|
}
|
|
73
108
|
const key = options.earlyKey?.({ req, scope }) ??
|
|
74
109
|
defaultEarlyRateLimitKey({ req, scope }, getClientIp);
|
|
75
|
-
await enforceRateLimit(ports
|
|
110
|
+
await enforceRateLimit(ports, {
|
|
76
111
|
key,
|
|
77
112
|
limit: rlMeta.max,
|
|
78
113
|
windowSec: rlMeta.windowSec,
|
|
@@ -91,7 +126,7 @@ export function createRateLimitHooks(options = {}) {
|
|
|
91
126
|
}
|
|
92
127
|
const key = options.key?.({ ctx, req, scope }) ??
|
|
93
128
|
defaultRateLimitKey({ ctx, req, scope }, getClientIp);
|
|
94
|
-
await enforceRateLimit(ctx.ports
|
|
129
|
+
await enforceRateLimit(ctx.ports, {
|
|
95
130
|
key,
|
|
96
131
|
limit: rlMeta.max,
|
|
97
132
|
windowSec: rlMeta.windowSec,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../../src/server/hooks/rate-limit.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../../../src/server/hooks/rate-limit.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,EACL,6BAA6B,GAE9B,MAAM,0BAA0B,CAAC;AAqElC,SAAS,iBAAiB,CAAC,GAAoB;IAC7C,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;IACxD,OAAO,MAAM;SACV,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC;AAED,SAAS,eAAe,CACtB,GAAoB,EACpB,QAA2B;IAE3B,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;QACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;IACpC,CAAC;IAED,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACvC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CA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,CAAC,CAAC;YAExD,MAAM,gBAAgB,CAAC,GAAG,CAAC,KAAK,EAAE;gBAChC,GAAG;gBACH,KAAK,EAAE,MAAM,CAAC,GAAG;gBACjB,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,KAAK;aACN,CAAC,CAAC;YAEH,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/server/hooks.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./hooks/index";
|
|
1
|
+
export * from "./hooks/index.js";
|
|
2
2
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/server/hooks.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/server/hooks.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
package/dist/server/hooks.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./hooks/index";
|
|
1
|
+
export * from "./hooks/index.js";
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
package/dist/server/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/server/hooks.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/server/hooks.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|
package/dist/server/http.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { HttpContractConfig, InferHeaderSchemaOutput, InferOutput, StandardSchema } from "../contracts";
|
|
2
|
-
import type { AnyPorts } from "../ports";
|
|
1
|
+
import type { HttpContractConfig, InferHeaderSchemaOutput, InferOutput, StandardSchema } from "../contracts/index.js";
|
|
2
|
+
import type { AnyPorts } from "../ports/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* Framework-neutral request shape consumed by Beignet server adapters.
|
|
5
5
|
*
|
|
@@ -75,6 +75,41 @@ export interface HttpResponseLike {
|
|
|
75
75
|
* `Response` only when the current adapter can pass it through unchanged.
|
|
76
76
|
*/
|
|
77
77
|
export type HttpResponse = HttpResponseLike | Response;
|
|
78
|
+
/**
|
|
79
|
+
* Framework-neutral Beignet API handler consumed by HTTP adapters.
|
|
80
|
+
*/
|
|
81
|
+
export type HttpAdapterApiHandler = (req: HttpRequestLike) => Promise<HttpResponse>;
|
|
82
|
+
/**
|
|
83
|
+
* Native handler shape produced by an HTTP adapter.
|
|
84
|
+
*/
|
|
85
|
+
export type HttpAdapterHandler<NativeRequest, NativeResponse> = (req: NativeRequest) => Promise<NativeResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Contract implemented by packages that adapt Beignet's framework-neutral
|
|
88
|
+
* server runtime to a platform HTTP API.
|
|
89
|
+
*
|
|
90
|
+
* Core owns request parsing, hooks, route matching, validation, error mapping,
|
|
91
|
+
* response ownership, and provider lifecycle. Adapters own only the conversion
|
|
92
|
+
* between the platform request/response types and Beignet's `HttpRequestLike`
|
|
93
|
+
* / `HttpResponse` boundary.
|
|
94
|
+
*/
|
|
95
|
+
export interface HttpAdapter<NativeRequest, NativeResponse> {
|
|
96
|
+
/**
|
|
97
|
+
* Human-readable adapter name for diagnostics and documentation.
|
|
98
|
+
*/
|
|
99
|
+
name: string;
|
|
100
|
+
/**
|
|
101
|
+
* Convert a platform request into Beignet's framework-neutral request shape.
|
|
102
|
+
*/
|
|
103
|
+
toRequestLike(req: NativeRequest): HttpRequestLike;
|
|
104
|
+
/**
|
|
105
|
+
* Convert a Beignet response into the platform response type.
|
|
106
|
+
*/
|
|
107
|
+
toNativeResponse(res: HttpResponse): NativeResponse | Promise<NativeResponse>;
|
|
108
|
+
/**
|
|
109
|
+
* Wrap a Beignet API handler in the platform's native handler shape.
|
|
110
|
+
*/
|
|
111
|
+
createHandler(handler: HttpAdapterApiHandler): HttpAdapterHandler<NativeRequest, NativeResponse>;
|
|
112
|
+
}
|
|
78
113
|
type InferSchemaOrFallback<T extends StandardSchema | null, Fallback> = T extends StandardSchema ? InferOutput<T> : Fallback;
|
|
79
114
|
/**
|
|
80
115
|
* Infer the handler path parameter type for a contract.
|
|
@@ -101,7 +136,7 @@ export interface HandlerArgs<Ctx, C extends HttpContractConfig> {
|
|
|
101
136
|
*/
|
|
102
137
|
req: HttpRequestLike;
|
|
103
138
|
/**
|
|
104
|
-
* Application context
|
|
139
|
+
* Application context assembled by the server context blueprint.
|
|
105
140
|
*/
|
|
106
141
|
ctx: Ctx;
|
|
107
142
|
/**
|
|
@@ -144,8 +179,14 @@ export type RouteHookArgs<Ctx, C extends HttpContractConfig = HttpContractConfig
|
|
|
144
179
|
* Route hooks are for scoped policy and context enrichment such as
|
|
145
180
|
* authentication, tenant resolution, feature gates, and idempotency. They add
|
|
146
181
|
* fields to the handler context instead of replacing the app context.
|
|
182
|
+
*
|
|
183
|
+
* Hook additions must not include `gate`: the server re-attaches the gate
|
|
184
|
+
* declared by the context blueprint after every hook, so identity changes are
|
|
185
|
+
* picked up automatically.
|
|
147
186
|
*/
|
|
148
|
-
export interface RouteHook<Ctx, AddedCtx extends object
|
|
187
|
+
export interface RouteHook<Ctx, AddedCtx extends object & {
|
|
188
|
+
gate?: never;
|
|
189
|
+
} = Record<string, never>> {
|
|
149
190
|
/**
|
|
150
191
|
* Optional name used in diagnostics and devtools.
|
|
151
192
|
*/
|
|
@@ -155,36 +196,12 @@ export interface RouteHook<Ctx, AddedCtx extends object = Record<string, never>>
|
|
|
155
196
|
*/
|
|
156
197
|
resolve: (args: RouteHookArgs<Ctx>) => MaybePromise<AddedCtx | undefined>;
|
|
157
198
|
}
|
|
199
|
+
type AddedCtxFromHook<Hook> = Hook extends RouteHook<infer _Ctx, infer AddedCtx> ? AddedCtx : unknown;
|
|
200
|
+
type UnionToIntersection<Union> = (Union extends unknown ? (value: Union) => void : never) extends (value: infer Intersection) => void ? Intersection : never;
|
|
158
201
|
/**
|
|
159
|
-
*
|
|
160
|
-
*/
|
|
161
|
-
export type RouteHookBuilder<Ctx> = {
|
|
162
|
-
/**
|
|
163
|
-
* Assign a diagnostic name to the hook.
|
|
164
|
-
*/
|
|
165
|
-
name: (name: string) => RouteHookNamedBuilder<Ctx>;
|
|
166
|
-
/**
|
|
167
|
-
* Define the hook resolver.
|
|
168
|
-
*/
|
|
169
|
-
resolve: <AddedCtx extends object>(resolve: RouteHook<Ctx, AddedCtx>["resolve"]) => RouteHook<Ctx, AddedCtx>;
|
|
170
|
-
};
|
|
171
|
-
/**
|
|
172
|
-
* Named builder for route-scoped hooks.
|
|
202
|
+
* Intersection of the context fields added by a route hook list.
|
|
173
203
|
*/
|
|
174
|
-
export type
|
|
175
|
-
/**
|
|
176
|
-
* Define the hook resolver.
|
|
177
|
-
*/
|
|
178
|
-
resolve: <AddedCtx extends object>(resolve: RouteHook<Ctx, AddedCtx>["resolve"]) => RouteHook<Ctx, AddedCtx>;
|
|
179
|
-
};
|
|
180
|
-
/**
|
|
181
|
-
* Define a route-scoped hook.
|
|
182
|
-
*
|
|
183
|
-
* Route hooks enrich handler context for one route or route group. They should
|
|
184
|
-
* throw application/framework errors for denials instead of returning HTTP
|
|
185
|
-
* responses directly.
|
|
186
|
-
*/
|
|
187
|
-
export declare function defineRouteHook<Ctx>(): RouteHookBuilder<Ctx>;
|
|
204
|
+
export type AddedCtxFromHooks<Hooks extends readonly unknown[]> = Hooks extends readonly [] ? unknown : UnionToIntersection<AddedCtxFromHook<Hooks[number]>>;
|
|
188
205
|
/**
|
|
189
206
|
* Hook that runs after a route is matched but before request parsing and
|
|
190
207
|
* context creation.
|
|
@@ -220,10 +237,11 @@ export type BeforeHandleHook<Ctx, C extends HttpContractConfig = HttpContractCon
|
|
|
220
237
|
body: InferBody<C>;
|
|
221
238
|
}) => MaybePromise<BeforeHandleResult<Ctx>>;
|
|
222
239
|
/**
|
|
223
|
-
* Hook that runs before
|
|
240
|
+
* Hook that runs before the response is returned.
|
|
224
241
|
*
|
|
225
242
|
* Return a response to replace or decorate the outgoing response. Hooks run in
|
|
226
|
-
* declaration order.
|
|
243
|
+
* declaration order. For native web `Response` results the hook receives a
|
|
244
|
+
* headers-only view and only header changes are applied.
|
|
227
245
|
*/
|
|
228
246
|
export type BeforeSendHook<Ctx, C extends HttpContractConfig = HttpContractConfig> = (args: {
|
|
229
247
|
req: HttpRequestLike;
|
|
@@ -235,6 +253,13 @@ export type BeforeSendHook<Ctx, C extends HttpContractConfig = HttpContractConfi
|
|
|
235
253
|
body?: InferBody<C>;
|
|
236
254
|
response: HttpResponseLike;
|
|
237
255
|
error?: unknown;
|
|
256
|
+
/**
|
|
257
|
+
* True when the route returned a native web Response. The response argument
|
|
258
|
+
* is a headers-only view ({ status, headers }); the body is not readable and
|
|
259
|
+
* returned body/status changes are ignored. Header changes are merged onto
|
|
260
|
+
* the native Response.
|
|
261
|
+
*/
|
|
262
|
+
native?: boolean;
|
|
238
263
|
}) => MaybePromise<HttpResponseLike | undefined>;
|
|
239
264
|
/**
|
|
240
265
|
* Hook that runs after the response has been prepared.
|
|
@@ -305,7 +330,8 @@ export interface ServerHook<Ctx, Ports extends AnyPorts = AnyPorts> {
|
|
|
305
330
|
*/
|
|
306
331
|
beforeHandle?: BeforeHandleHook<Ctx>;
|
|
307
332
|
/**
|
|
308
|
-
* Runs before
|
|
333
|
+
* Runs before the response is returned. Native web `Response` results get a
|
|
334
|
+
* headers-only view with `native: true`.
|
|
309
335
|
*/
|
|
310
336
|
beforeSend?: BeforeSendHook<Ctx>;
|
|
311
337
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/server/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,WAAW,EACX,cAAc,EACf,MAAM,
|
|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
* Define a route-scoped hook.
|
|
3
|
-
*
|
|
4
|
-
* Route hooks enrich handler context for one route or route group. They should
|
|
5
|
-
* throw application/framework errors for denials instead of returning HTTP
|
|
6
|
-
* responses directly.
|
|
7
|
-
*/
|
|
8
|
-
export function defineRouteHook() {
|
|
9
|
-
return {
|
|
10
|
-
name: (name) => ({
|
|
11
|
-
resolve: (resolve) => ({
|
|
12
|
-
name,
|
|
13
|
-
resolve,
|
|
14
|
-
}),
|
|
15
|
-
}),
|
|
16
|
-
resolve: (resolve) => ({
|
|
17
|
-
resolve,
|
|
18
|
-
}),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
1
|
+
export {};
|
|
21
2
|
//# sourceMappingURL=http.js.map
|
package/dist/server/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/server/http.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/server/http.ts"],"names":[],"mappings":""}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -7,31 +7,55 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Contract and schema types re-exported for server users.
|
|
9
9
|
*/
|
|
10
|
-
export type { HttpContractConfig, InferOutput, StandardSchema, StandardSchemaV1, } from "../contracts";
|
|
10
|
+
export type { HttpContractConfig, InferOutput, StandardSchema, StandardSchemaV1, } from "../contracts/index.js";
|
|
11
11
|
/**
|
|
12
12
|
* Application error base class re-exported for server users.
|
|
13
13
|
*/
|
|
14
|
-
export { AppError } from "../errors";
|
|
14
|
+
export { AppError } from "../errors/index.js";
|
|
15
15
|
/**
|
|
16
16
|
* Any-ports helper type re-exported for server users.
|
|
17
17
|
*/
|
|
18
|
-
export type { AnyPorts } from "../ports";
|
|
18
|
+
export type { AnyPorts } from "../ports/index.js";
|
|
19
19
|
/**
|
|
20
20
|
* Provider type re-exported for server users.
|
|
21
21
|
*/
|
|
22
|
-
export type { ServiceProvider } from "../providers";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export
|
|
27
|
-
|
|
22
|
+
export type { ServiceProvider } from "../providers/index.js";
|
|
23
|
+
/**
|
|
24
|
+
* Ambient audit enrichment for app audit ports.
|
|
25
|
+
*/
|
|
26
|
+
export { createAmbientAuditLog } from "./audit-context.js";
|
|
27
|
+
/**
|
|
28
|
+
* Server context blueprint types.
|
|
29
|
+
*/
|
|
30
|
+
export type { ContextSeed, RequestContextArgs, ServerContextConfig, ServerContextOptions, ServiceContextArgs, ServiceContextInputArgs, } from "./context.js";
|
|
31
|
+
export * from "./health.js";
|
|
32
|
+
export * from "./hooks.js";
|
|
33
|
+
export * from "./http.js";
|
|
34
|
+
/**
|
|
35
|
+
* Server-owned request instrumentation types.
|
|
36
|
+
*/
|
|
37
|
+
export type { RequestCorrelation, ServerInstrumentationOptions, } from "./instrumentation.js";
|
|
38
|
+
export * from "./openapi.js";
|
|
39
|
+
export * from "./providers/index.js";
|
|
40
|
+
/**
|
|
41
|
+
* Ambient request correlation context shared with instrumentation sinks.
|
|
42
|
+
*/
|
|
43
|
+
export { type ActiveRequestContext, clearActiveRequestContext, enterActiveRequestContext, getActiveRequestContext, inheritActiveRequestContext, } from "./request-context.js";
|
|
28
44
|
/**
|
|
29
45
|
* Server configuration and route types.
|
|
30
46
|
*/
|
|
31
|
-
export type { CreateServerOptions, RouteDef, RouteGroup, ServerInstance, } from "./server";
|
|
47
|
+
export type { CreateServerOptions, HandlerRouteDef, RouteDef, RouteGroup, ServerInstance, } from "./server.js";
|
|
32
48
|
/**
|
|
33
49
|
* Server runtime helpers.
|
|
34
50
|
*/
|
|
35
|
-
export { contractsFromRoutes, createServer, defineRoute, defineRouteGroup, defineRoutes, } from "./server";
|
|
36
|
-
|
|
51
|
+
export { contractsFromRoutes, createServer, defineRoute, defineRouteGroup, defineRoutes, } from "./server.js";
|
|
52
|
+
/**
|
|
53
|
+
* Server context blueprint declaration helper.
|
|
54
|
+
*/
|
|
55
|
+
export { defineServerContext } from "./server-context.js";
|
|
56
|
+
export * from "./types.js";
|
|
57
|
+
/**
|
|
58
|
+
* Contract-aware route binder types and helpers.
|
|
59
|
+
*/
|
|
60
|
+
export { type AnyUseCaseLike, type AnyUseCaseRouteDef, type BinderStatusOption, defaultBinderInput, type UseCaseFitsRoute, type UseCaseRouteDef, type UseCaseRouteInput, type UseCaseRouteInputParts, } from "./use-case-route.js";
|
|
37
61
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,gBAAgB,GACjB,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,YAAY,EACV,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAC/B;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C;;GAEG;AACH,YAAY,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD;;GAEG;AACH,YAAY,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D;;GAEG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D;;GAEG;AACH,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,cAAc,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B;;GAEG;AACH,YAAY,EACV,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,sBAAsB,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC;;GAEG;AACH,OAAO,EACL,KAAK,oBAAoB,EACzB,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,sBAAsB,CAAC;AAC9B;;GAEG;AACH,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,QAAQ,EACR,UAAU,EACV,cAAc,GACf,MAAM,aAAa,CAAC;AACrB;;GAEG;AACH,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,cAAc,YAAY,CAAC;AAC3B;;GAEG;AACH,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,kBAAkB,EAClB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,GAC5B,MAAM,qBAAqB,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -7,15 +7,31 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Application error base class re-exported for server users.
|
|
9
9
|
*/
|
|
10
|
-
export { AppError } from "../errors";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
export * from "./
|
|
10
|
+
export { AppError } from "../errors/index.js";
|
|
11
|
+
/**
|
|
12
|
+
* Ambient audit enrichment for app audit ports.
|
|
13
|
+
*/
|
|
14
|
+
export { createAmbientAuditLog } from "./audit-context.js";
|
|
15
|
+
export * from "./health.js";
|
|
16
|
+
export * from "./hooks.js";
|
|
17
|
+
export * from "./http.js";
|
|
18
|
+
export * from "./openapi.js";
|
|
19
|
+
export * from "./providers/index.js";
|
|
20
|
+
/**
|
|
21
|
+
* Ambient request correlation context shared with instrumentation sinks.
|
|
22
|
+
*/
|
|
23
|
+
export { clearActiveRequestContext, enterActiveRequestContext, getActiveRequestContext, inheritActiveRequestContext, } from "./request-context.js";
|
|
16
24
|
/**
|
|
17
25
|
* Server runtime helpers.
|
|
18
26
|
*/
|
|
19
|
-
export { contractsFromRoutes, createServer, defineRoute, defineRouteGroup, defineRoutes, } from "./server";
|
|
20
|
-
|
|
27
|
+
export { contractsFromRoutes, createServer, defineRoute, defineRouteGroup, defineRoutes, } from "./server.js";
|
|
28
|
+
/**
|
|
29
|
+
* Server context blueprint declaration helper.
|
|
30
|
+
*/
|
|
31
|
+
export { defineServerContext } from "./server-context.js";
|
|
32
|
+
export * from "./types.js";
|
|
33
|
+
/**
|
|
34
|
+
* Contract-aware route binder types and helpers.
|
|
35
|
+
*/
|
|
36
|
+
export { defaultBinderInput, } from "./use-case-route.js";
|
|
21
37
|
//# sourceMappingURL=index.js.map
|
package/dist/server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH;;GAEG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAS9C;;GAEG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAY3D,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAQ1B,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC;;GAEG;AACH,OAAO,EAEL,yBAAyB,EACzB,yBAAyB,EACzB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,sBAAsB,CAAC;AAW9B;;GAEG;AACH,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,YAAY,GACb,MAAM,aAAa,CAAC;AACrB;;GAEG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,cAAc,YAAY,CAAC;AAC3B;;GAEG;AACH,OAAO,EAIL,kBAAkB,GAKnB,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { type HttpContractConfig } from "../contracts/index.js";
|
|
2
|
+
import type { AnyPorts } from "../ports/index.js";
|
|
3
|
+
import { type ProviderInstrumentationEventInput } from "../providers/instrumentation.js";
|
|
4
|
+
import { type TraceContext } from "../tracing/index.js";
|
|
5
|
+
import type { HttpRequestLike, HttpResponseLike, ServerHook } from "./http.js";
|
|
6
|
+
/**
|
|
7
|
+
* Options for the server-owned request instrumentation pipeline.
|
|
8
|
+
*
|
|
9
|
+
* The server resolves request IDs and W3C trace context before user hooks and
|
|
10
|
+
* context creation run, writes them to response headers, and records request
|
|
11
|
+
* and error events into the resolved provider instrumentation port
|
|
12
|
+
* (`ports.instrumentation`, then `ports.devtools`) after responses are sent.
|
|
13
|
+
*
|
|
14
|
+
* Pass `instrumentation: false` to `createServer(...)` to disable headers and
|
|
15
|
+
* event recording entirely.
|
|
16
|
+
*/
|
|
17
|
+
export interface ServerInstrumentationOptions<Ctx = unknown> {
|
|
18
|
+
/**
|
|
19
|
+
* Request/response header used for the request correlation ID.
|
|
20
|
+
*
|
|
21
|
+
* Pass `false` to avoid reading or writing a request ID header.
|
|
22
|
+
*
|
|
23
|
+
* @default "x-request-id"
|
|
24
|
+
*/
|
|
25
|
+
requestIdHeader?: string | false;
|
|
26
|
+
/**
|
|
27
|
+
* W3C trace context header used to correlate events with distributed
|
|
28
|
+
* traces.
|
|
29
|
+
*
|
|
30
|
+
* Pass `false` to avoid reading or writing a trace context header.
|
|
31
|
+
*
|
|
32
|
+
* @default "traceparent"
|
|
33
|
+
*/
|
|
34
|
+
traceContextHeader?: string | false;
|
|
35
|
+
/**
|
|
36
|
+
* Request path prefixes that should not enter ambient correlation or record
|
|
37
|
+
* events. Response headers are still written.
|
|
38
|
+
*
|
|
39
|
+
* Defaults to the devtools dashboard prefix so its polling traffic does not
|
|
40
|
+
* fill the event timeline.
|
|
41
|
+
*
|
|
42
|
+
* @default ["/api/devtools"]
|
|
43
|
+
*/
|
|
44
|
+
ignorePaths?: readonly string[];
|
|
45
|
+
/**
|
|
46
|
+
* Apply a custom redactor to events produced by the server. Sink-level
|
|
47
|
+
* redaction (such as the devtools redactor) still runs when events are
|
|
48
|
+
* stored.
|
|
49
|
+
*/
|
|
50
|
+
redact?: (event: ProviderInstrumentationEventInput) => ProviderInstrumentationEventInput;
|
|
51
|
+
/**
|
|
52
|
+
* Decide whether to capture a completed request event.
|
|
53
|
+
*/
|
|
54
|
+
shouldCapture?: (args: {
|
|
55
|
+
req: HttpRequestLike;
|
|
56
|
+
ctx?: Ctx;
|
|
57
|
+
contract: HttpContractConfig;
|
|
58
|
+
response: HttpResponseLike;
|
|
59
|
+
error?: unknown;
|
|
60
|
+
}) => boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Correlation values resolved by the server for one request or service
|
|
64
|
+
* context.
|
|
65
|
+
*/
|
|
66
|
+
export interface RequestCorrelation {
|
|
67
|
+
/**
|
|
68
|
+
* Request correlation ID.
|
|
69
|
+
*/
|
|
70
|
+
requestId: string;
|
|
71
|
+
/**
|
|
72
|
+
* W3C trace context.
|
|
73
|
+
*/
|
|
74
|
+
trace: TraceContext;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Internal runtime created by `createServer(...)` from its `instrumentation`
|
|
78
|
+
* option.
|
|
79
|
+
*/
|
|
80
|
+
export interface ServerInstrumentationRuntime<Ctx> {
|
|
81
|
+
/**
|
|
82
|
+
* Resolve the instrumentation sink once final ports are known.
|
|
83
|
+
*/
|
|
84
|
+
attachPorts(ports: AnyPorts): void;
|
|
85
|
+
/**
|
|
86
|
+
* Resolve (and cache per request) the request ID and trace context.
|
|
87
|
+
*/
|
|
88
|
+
prepareRequest(req: HttpRequestLike): RequestCorrelation;
|
|
89
|
+
/**
|
|
90
|
+
* Create fresh correlation values for a service context.
|
|
91
|
+
*/
|
|
92
|
+
createServiceCorrelation(): RequestCorrelation;
|
|
93
|
+
/**
|
|
94
|
+
* Pipeline hook installed before user hooks, when instrumentation is
|
|
95
|
+
* enabled.
|
|
96
|
+
*/
|
|
97
|
+
hook?: ServerHook<Ctx, AnyPorts>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Create the server-owned instrumentation runtime for `createServer(...)`.
|
|
101
|
+
*
|
|
102
|
+
* Correlation values (request ID and trace context) are always resolved so
|
|
103
|
+
* context factories receive stable `requestId`/`trace` arguments, even when
|
|
104
|
+
* instrumentation is disabled. Headers and event recording only run when
|
|
105
|
+
* instrumentation is enabled.
|
|
106
|
+
*/
|
|
107
|
+
export declare function createServerInstrumentation<Ctx>(options: ServerInstrumentationOptions<Ctx> | false | undefined): ServerInstrumentationRuntime<Ctx>;
|
|
108
|
+
//# sourceMappingURL=instrumentation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instrumentation.d.ts","sourceRoot":"","sources":["../../src/server/instrumentation.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EACL,KAAK,iCAAiC,EAGvC,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAQ/E;;;;;;;;;;GAUG;AACH,MAAM,WAAW,4BAA4B,CAAC,GAAG,GAAG,OAAO;IACzD;;;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