@beignet/core 0.0.3 → 0.0.4
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 +157 -0
- package/README.md +785 -43
- 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
package/dist/schedules/index.js
CHANGED
|
@@ -65,9 +65,18 @@ function normalizeOptionalDate(value, field) {
|
|
|
65
65
|
return undefined;
|
|
66
66
|
return normalizeDate(value, field, () => new Date());
|
|
67
67
|
}
|
|
68
|
+
function normalizeOptionalAttempt(value) {
|
|
69
|
+
if (value === undefined)
|
|
70
|
+
return undefined;
|
|
71
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
72
|
+
throw new ScheduleRunContextError("Schedule run attempt must be a positive integer.");
|
|
73
|
+
}
|
|
74
|
+
return value;
|
|
75
|
+
}
|
|
68
76
|
function createRunContext(options, now) {
|
|
69
77
|
return {
|
|
70
78
|
id: options.id,
|
|
79
|
+
attempt: normalizeOptionalAttempt(options.attempt),
|
|
71
80
|
scheduledAt: normalizeOptionalDate(options.scheduledAt, "scheduledAt"),
|
|
72
81
|
triggeredAt: normalizeDate(options.triggeredAt, "triggeredAt", now),
|
|
73
82
|
source: options.source,
|
|
@@ -117,13 +126,38 @@ async function runErrorHook(handler, onHookError, args) {
|
|
|
117
126
|
});
|
|
118
127
|
}
|
|
119
128
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
async function recordScheduleEvent(options, schedule, status, run, args) {
|
|
130
|
+
if (!options.instrumentation)
|
|
131
|
+
return;
|
|
132
|
+
try {
|
|
133
|
+
options.instrumentation.record({
|
|
134
|
+
type: "schedule",
|
|
135
|
+
watcher: "schedules",
|
|
136
|
+
requestId: options.instrumentationContext?.requestId,
|
|
137
|
+
traceId: options.instrumentationContext?.traceId,
|
|
138
|
+
scheduleName: schedule.name,
|
|
139
|
+
status,
|
|
140
|
+
cron: schedule.cron,
|
|
141
|
+
timezone: schedule.timezone,
|
|
142
|
+
details: {
|
|
143
|
+
source: run.source,
|
|
144
|
+
scheduledAt: run.scheduledAt?.toISOString(),
|
|
145
|
+
...args.details,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
await reportHookError(options.onHookError, {
|
|
151
|
+
schedule,
|
|
152
|
+
payload: args.payload,
|
|
153
|
+
run,
|
|
154
|
+
hook: args.hook,
|
|
155
|
+
error,
|
|
156
|
+
scheduleError: args.scheduleError,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function defineScheduleImpl(name, options) {
|
|
127
161
|
return {
|
|
128
162
|
kind: "schedule",
|
|
129
163
|
name,
|
|
@@ -168,6 +202,10 @@ export function createInlineScheduleRunner(options = {}) {
|
|
|
168
202
|
try {
|
|
169
203
|
payload = await resolveSchedulePayload(schedule, runOptions, run);
|
|
170
204
|
const lifecycleArgs = { schedule, payload, run };
|
|
205
|
+
await recordScheduleEvent(options, schedule, "started", run, {
|
|
206
|
+
payload,
|
|
207
|
+
hook: "start",
|
|
208
|
+
});
|
|
171
209
|
await runLifecycleHook("start", options.onStart, options.onHookError, lifecycleArgs);
|
|
172
210
|
await schedule.handle({
|
|
173
211
|
schedule,
|
|
@@ -175,9 +213,19 @@ export function createInlineScheduleRunner(options = {}) {
|
|
|
175
213
|
ctx: await resolveCtx(options.ctx),
|
|
176
214
|
run,
|
|
177
215
|
});
|
|
216
|
+
await recordScheduleEvent(options, schedule, "completed", run, {
|
|
217
|
+
payload,
|
|
218
|
+
hook: "success",
|
|
219
|
+
});
|
|
178
220
|
await runLifecycleHook("success", options.onSuccess, options.onHookError, lifecycleArgs);
|
|
179
221
|
}
|
|
180
222
|
catch (error) {
|
|
223
|
+
await recordScheduleEvent(options, schedule, "failed", run, {
|
|
224
|
+
payload,
|
|
225
|
+
hook: "error",
|
|
226
|
+
scheduleError: error,
|
|
227
|
+
details: { error },
|
|
228
|
+
});
|
|
181
229
|
await runErrorHook(options.onError, options.onHookError, {
|
|
182
230
|
error,
|
|
183
231
|
schedule,
|
|
@@ -191,14 +239,20 @@ export function createInlineScheduleRunner(options = {}) {
|
|
|
191
239
|
}
|
|
192
240
|
/**
|
|
193
241
|
* Create schedule helper methods bound to an application context type.
|
|
242
|
+
*
|
|
243
|
+
* Call it once in `lib/schedules.ts`:
|
|
244
|
+
*
|
|
245
|
+
* ```ts
|
|
246
|
+
* export const { defineSchedule } = createSchedules<AppContext>();
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* Cron and timezone are metadata for schedule providers. The inline runner only
|
|
250
|
+
* runs schedules when its `run(...)` method is called.
|
|
194
251
|
*/
|
|
195
|
-
export function
|
|
252
|
+
export function createSchedules() {
|
|
196
253
|
return {
|
|
197
254
|
defineSchedule(name, options) {
|
|
198
|
-
return
|
|
199
|
-
},
|
|
200
|
-
createInlineScheduleRunner(options = {}) {
|
|
201
|
-
return createInlineScheduleRunner(options);
|
|
255
|
+
return defineScheduleImpl(name, options);
|
|
202
256
|
},
|
|
203
257
|
};
|
|
204
258
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schedules/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schedules/index.ts"],"names":[],"mappings":"AAkcA;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD;;OAEG;IACM,MAAM,CAAoC;IAEnD,YAAY,IAGX;QACC,KAAK,CACH,aAAa,IAAI,CAAC,IAAI,gCAAgC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAClF,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;QACtC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACxC,CAAC;CACF;AAED,SAAS,UAAU,CAAC,IAAoC;IACtD,IAAI,CAAC,IAAI,EAAE,MAAM;QAAE,OAAO,EAAE,CAAC;IAE7B,OAAO,IAAI;SACR,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACf,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,IAAI,OAAO;QACjE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;QACrB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CACpB;SACA,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CA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AAC,OAAO,EACf,OAAO,CAAC,WAAW,EACnB,aAAa,CACd,CAAC;gBACF,MAAM,QAAQ,CAAC,MAAM,CAAC;oBACpB,QAAQ;oBACR,OAAO;oBACP,GAAG,EAAE,MAAM,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC;oBAClC,GAAG;iBACJ,CAAC,CAAC;gBACH,MAAM,mBAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE;oBAC7D,OAAO;oBACP,IAAI,EAAE,SAAS;iBAChB,CAAC,CAAC;gBACH,MAAM,gBAAgB,CACpB,SAAS,EACT,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,WAAW,EACnB,aAAa,CACd,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,mBAAmB,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE;oBAC1D,OAAO;oBACP,IAAI,EAAE,OAAO;oBACb,aAAa,EAAE,KAAK;oBACpB,OAAO,EAAE,EAAE,KAAK,EAAE;iBACnB,CAAC,CAAC;gBACH,MAAM,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE;oBACvD,KAAK;oBACL,QAAQ;oBACR,OAAO;oBACP,GAAG;iBACJ,CAAC,CAAC;gBACH,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO;QACL,cAAc,CACZ,IAAU,EACV,OAAkD;YAElD,OAAO,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AuditLogPort } from "../ports/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Wrap an audit log port so missing `actor`, `tenant`, `requestId`, and
|
|
4
|
+
* `traceId` fields are filled from the ambient request context at record time.
|
|
5
|
+
*
|
|
6
|
+
* The server keeps the ambient context current for requests (including
|
|
7
|
+
* identity elevated by hooks) and for service contexts created for jobs,
|
|
8
|
+
* listeners, schedules, and tasks. Because enrichment happens when
|
|
9
|
+
* `record(...)` runs, the wrapper also works for ports rebuilt per
|
|
10
|
+
* transaction inside a unit of work — wrap both the top-level audit port and
|
|
11
|
+
* the per-transaction rebuild.
|
|
12
|
+
*
|
|
13
|
+
* Fields provided on the entry always win; only missing fields are filled.
|
|
14
|
+
* When no ambient context is active (for example on runtimes without
|
|
15
|
+
* `AsyncLocalStorage` propagation), entries pass through unchanged.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const audit = createAmbientAuditLog(
|
|
20
|
+
* createInstrumentedAuditLog({ audit: createDrizzleAuditLog(db), instrumentation: ports }),
|
|
21
|
+
* );
|
|
22
|
+
* await audit.record({ action: "posts.publish", resource: { type: "post", id } });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param audit - Underlying audit log port to write enriched entries to.
|
|
26
|
+
* @returns An audit log port that fills missing context fields before writing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createAmbientAuditLog(audit: AuditLogPort): AuditLogPort;
|
|
29
|
+
//# sourceMappingURL=audit-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-context.d.ts","sourceRoot":"","sources":["../../src/server/audit-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,YAAY,CAevE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getActiveRequestContext } from "./request-context.js";
|
|
2
|
+
/**
|
|
3
|
+
* Wrap an audit log port so missing `actor`, `tenant`, `requestId`, and
|
|
4
|
+
* `traceId` fields are filled from the ambient request context at record time.
|
|
5
|
+
*
|
|
6
|
+
* The server keeps the ambient context current for requests (including
|
|
7
|
+
* identity elevated by hooks) and for service contexts created for jobs,
|
|
8
|
+
* listeners, schedules, and tasks. Because enrichment happens when
|
|
9
|
+
* `record(...)` runs, the wrapper also works for ports rebuilt per
|
|
10
|
+
* transaction inside a unit of work — wrap both the top-level audit port and
|
|
11
|
+
* the per-transaction rebuild.
|
|
12
|
+
*
|
|
13
|
+
* Fields provided on the entry always win; only missing fields are filled.
|
|
14
|
+
* When no ambient context is active (for example on runtimes without
|
|
15
|
+
* `AsyncLocalStorage` propagation), entries pass through unchanged.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const audit = createAmbientAuditLog(
|
|
20
|
+
* createInstrumentedAuditLog({ audit: createDrizzleAuditLog(db), instrumentation: ports }),
|
|
21
|
+
* );
|
|
22
|
+
* await audit.record({ action: "posts.publish", resource: { type: "post", id } });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param audit - Underlying audit log port to write enriched entries to.
|
|
26
|
+
* @returns An audit log port that fills missing context fields before writing.
|
|
27
|
+
*/
|
|
28
|
+
export function createAmbientAuditLog(audit) {
|
|
29
|
+
return {
|
|
30
|
+
record(entry) {
|
|
31
|
+
const context = getActiveRequestContext();
|
|
32
|
+
if (!context)
|
|
33
|
+
return audit.record(entry);
|
|
34
|
+
return audit.record({
|
|
35
|
+
...entry,
|
|
36
|
+
actor: entry.actor ?? context.actor,
|
|
37
|
+
tenant: entry.tenant ?? context.tenant,
|
|
38
|
+
requestId: entry.requestId ?? context.requestId,
|
|
39
|
+
traceId: entry.traceId ?? context.traceId,
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=audit-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-context.js","sourceRoot":"","sources":["../../src/server/audit-context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAAmB;IACvD,OAAO;QACL,MAAM,CAAC,KAAK;YACV,MAAM,OAAO,GAAG,uBAAuB,EAAE,CAAC;YAC1C,IAAI,CAAC,OAAO;gBAAE,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAEzC,OAAO,KAAK,CAAC,MAAM,CAAC;gBAClB,GAAG,KAAK;gBACR,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK;gBACnC,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM;gBACtC,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS;gBAC/C,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO;aAC1C,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { HttpContractConfig } from "../contracts/index.js";
|
|
2
|
+
import type { AnyPorts, BoundGate, GatePort, PolicyDefinition } from "../ports/index.js";
|
|
3
|
+
import type { TraceContext } from "../tracing/index.js";
|
|
4
|
+
import type { HttpRequestLike, MaybePromise } from "./http.js";
|
|
5
|
+
/**
|
|
6
|
+
* Arguments passed to the `context.request` factory after a route is matched.
|
|
7
|
+
*/
|
|
8
|
+
export type RequestContextArgs<Ports extends AnyPorts = AnyPorts> = {
|
|
9
|
+
/**
|
|
10
|
+
* Framework-neutral request.
|
|
11
|
+
*/
|
|
12
|
+
req: HttpRequestLike;
|
|
13
|
+
/**
|
|
14
|
+
* Final app ports, including ports contributed by providers.
|
|
15
|
+
*/
|
|
16
|
+
ports: Ports;
|
|
17
|
+
/**
|
|
18
|
+
* Matched contract, when the request resolved to a registered route.
|
|
19
|
+
*/
|
|
20
|
+
contract?: HttpContractConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Request correlation ID resolved by the server from the configured request
|
|
23
|
+
* ID header, or generated when the request did not send one.
|
|
24
|
+
*/
|
|
25
|
+
requestId: string;
|
|
26
|
+
/**
|
|
27
|
+
* W3C trace context resolved by the server from the incoming `traceparent`
|
|
28
|
+
* header, or generated when the request did not send one. Spread this into
|
|
29
|
+
* the context (`...trace`) to correlate downstream activity.
|
|
30
|
+
*/
|
|
31
|
+
trace: TraceContext;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Arguments passed to the `context.service` factory.
|
|
35
|
+
*/
|
|
36
|
+
export type ServiceContextArgs<Ports extends AnyPorts = AnyPorts, ServiceInput = void> = {
|
|
37
|
+
/**
|
|
38
|
+
* Final app ports, including ports contributed by providers.
|
|
39
|
+
*/
|
|
40
|
+
ports: Ports;
|
|
41
|
+
/**
|
|
42
|
+
* Caller-provided input such as the service actor or tenant.
|
|
43
|
+
*/
|
|
44
|
+
input: ServiceInput;
|
|
45
|
+
/**
|
|
46
|
+
* Fresh correlation ID generated for this service context.
|
|
47
|
+
*/
|
|
48
|
+
requestId: string;
|
|
49
|
+
/**
|
|
50
|
+
* Fresh W3C trace context generated for this service context. Spread this
|
|
51
|
+
* into the context (`...trace`) to correlate downstream activity.
|
|
52
|
+
*/
|
|
53
|
+
trace: TraceContext;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* App context without its `gate` property.
|
|
57
|
+
*
|
|
58
|
+
* Context factories return seeds; the server attaches the gate declared by
|
|
59
|
+
* the blueprint's `gate` selector, so hand-binding `gate` in a factory is a
|
|
60
|
+
* type error.
|
|
61
|
+
*/
|
|
62
|
+
export type ContextSeed<Ctx> = Omit<Ctx, "gate"> & {
|
|
63
|
+
gate?: never;
|
|
64
|
+
};
|
|
65
|
+
type ContextGateOption<Ctx, Ports extends AnyPorts> = [Ctx] extends [
|
|
66
|
+
{
|
|
67
|
+
gate: BoundGate<infer TPolicies extends readonly PolicyDefinition[]>;
|
|
68
|
+
}
|
|
69
|
+
] ? {
|
|
70
|
+
/**
|
|
71
|
+
* Select the gate port the server attaches to every context it builds.
|
|
72
|
+
*/
|
|
73
|
+
gate: (ports: Ports) => GatePort<ContextSeed<Ctx>, TPolicies>;
|
|
74
|
+
} : {
|
|
75
|
+
/**
|
|
76
|
+
* Gate selection is only available when the context type declares a
|
|
77
|
+
* `gate` property.
|
|
78
|
+
*/
|
|
79
|
+
gate?: never;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Context blueprint accepted by `createServer(...)`.
|
|
83
|
+
*
|
|
84
|
+
* The server owns context assembly: `request` and `service` return context
|
|
85
|
+
* seeds, and the server attaches the gate declared by `gate` so identity
|
|
86
|
+
* changes can never authorize against a stale context.
|
|
87
|
+
*/
|
|
88
|
+
export type ServerContextOptions<Ctx, Ports extends AnyPorts = AnyPorts, ServiceInput = void> = {
|
|
89
|
+
/**
|
|
90
|
+
* Build the per-request context seed.
|
|
91
|
+
*/
|
|
92
|
+
request: (args: RequestContextArgs<Ports>) => MaybePromise<ContextSeed<Ctx>>;
|
|
93
|
+
/**
|
|
94
|
+
* Build a service context seed for schedules, outbox drains, tasks, and
|
|
95
|
+
* background work. Required before `server.createServiceContext(...)` can
|
|
96
|
+
* be called.
|
|
97
|
+
*/
|
|
98
|
+
service?: (args: ServiceContextArgs<Ports, ServiceInput>) => MaybePromise<ContextSeed<Ctx>>;
|
|
99
|
+
} & ContextGateOption<Ctx, Ports>;
|
|
100
|
+
/**
|
|
101
|
+
* Context configuration accepted by `createServer(...)`.
|
|
102
|
+
*
|
|
103
|
+
* Contexts without a `gate` property may use the plain request-factory
|
|
104
|
+
* shorthand. Contexts with a `gate` must use the blueprint form so the server
|
|
105
|
+
* owns gate attachment.
|
|
106
|
+
*/
|
|
107
|
+
export type ServerContextConfig<Ctx, Ports extends AnyPorts = AnyPorts, ServiceInput = void> = [Ctx] extends [{
|
|
108
|
+
gate: unknown;
|
|
109
|
+
}] ? ServerContextOptions<Ctx, Ports, ServiceInput> : ((args: RequestContextArgs<Ports>) => MaybePromise<Ctx>) | ServerContextOptions<Ctx, Ports, ServiceInput>;
|
|
110
|
+
/**
|
|
111
|
+
* Argument tuple for `createServiceContext(...)`.
|
|
112
|
+
*
|
|
113
|
+
* Servers without a declared service input are callable with no arguments;
|
|
114
|
+
* optional inputs stay optional at the call site.
|
|
115
|
+
*/
|
|
116
|
+
export type ServiceContextInputArgs<ServiceInput> = [ServiceInput] extends [
|
|
117
|
+
void
|
|
118
|
+
] ? [] : undefined extends ServiceInput ? [input?: ServiceInput] : [input: ServiceInput];
|
|
119
|
+
type AnyGateSelector<Ports extends AnyPorts> = (ports: Ports) => Pick<GatePort<unknown>, "attach">;
|
|
120
|
+
/**
|
|
121
|
+
* Normalized runtime view of a server context configuration.
|
|
122
|
+
*/
|
|
123
|
+
export type ResolvedServerContext<Ctx, Ports extends AnyPorts, ServiceInput> = {
|
|
124
|
+
request: (args: RequestContextArgs<Ports>) => MaybePromise<ContextSeed<Ctx> | Ctx>;
|
|
125
|
+
service?: (args: ServiceContextArgs<Ports, ServiceInput>) => MaybePromise<ContextSeed<Ctx>>;
|
|
126
|
+
gate?: AnyGateSelector<Ports>;
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Normalize a server context configuration into its runtime parts.
|
|
130
|
+
*/
|
|
131
|
+
export declare function resolveServerContext<Ctx, Ports extends AnyPorts, ServiceInput>(config: ServerContextConfig<Ctx, Ports, ServiceInput>): ResolvedServerContext<Ctx, Ports, ServiceInput>;
|
|
132
|
+
/**
|
|
133
|
+
* Create the context finalizer for a resolved server context.
|
|
134
|
+
*
|
|
135
|
+
* When the blueprint declares a gate, the finalizer strips hand-assigned
|
|
136
|
+
* `gate` values from seeds and attaches the live gate. Without a gate
|
|
137
|
+
* declaration the seed is the context.
|
|
138
|
+
*/
|
|
139
|
+
export declare function createContextFinalizer<Ctx, Ports extends AnyPorts, ServiceInput>(resolved: ResolvedServerContext<Ctx, Ports, ServiceInput>, getPorts: () => Ports): (seed: ContextSeed<Ctx> | Ctx) => Ctx;
|
|
140
|
+
export {};
|
|
141
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/server/context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,gBAAgB,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,QAAQ,GAAG,QAAQ,IAAI;IAClE;;OAEG;IACH,GAAG,EAAE,eAAe,CAAC;IACrB;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IACb;;OAEG;IACH,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAC5B,KAAK,SAAS,QAAQ,GAAG,QAAQ,EACjC,YAAY,GAAG,IAAI,IACjB;IACF;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IACb;;OAEG;IACH,KAAK,EAAE,YAAY,CAAC;IACpB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,KAAK,EAAE,YAAY,CAAC;CACrB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CAAC,GAAG,IAAI,IAAI,CA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AC,GAAG,EAAE,KAAK,EAAE,YAAY,CAAC,EACzD,QAAQ,EAAE,MAAM,KAAK,GACpB,CAAC,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,GAAG,CAoBvC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalize a server context configuration into its runtime parts.
|
|
3
|
+
*/
|
|
4
|
+
export function resolveServerContext(config) {
|
|
5
|
+
const value = config;
|
|
6
|
+
if (typeof value === "function") {
|
|
7
|
+
return { request: value };
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
request: value.request,
|
|
11
|
+
service: value.service,
|
|
12
|
+
gate: value.gate,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create the context finalizer for a resolved server context.
|
|
17
|
+
*
|
|
18
|
+
* When the blueprint declares a gate, the finalizer strips hand-assigned
|
|
19
|
+
* `gate` values from seeds and attaches the live gate. Without a gate
|
|
20
|
+
* declaration the seed is the context.
|
|
21
|
+
*/
|
|
22
|
+
export function createContextFinalizer(resolved, getPorts) {
|
|
23
|
+
const gateSelector = resolved.gate;
|
|
24
|
+
if (!gateSelector) {
|
|
25
|
+
return (seed) => seed;
|
|
26
|
+
}
|
|
27
|
+
return (seed) => {
|
|
28
|
+
const target = seed;
|
|
29
|
+
const existing = Object.getOwnPropertyDescriptor(target, "gate");
|
|
30
|
+
if (existing && existing.get === undefined) {
|
|
31
|
+
if (process.env.NODE_ENV !== "production") {
|
|
32
|
+
console.warn("[beignet] Ignoring a hand-assigned ctx.gate value. The server context blueprint owns gate attachment; remove `gate` from context factories and hook additions.");
|
|
33
|
+
}
|
|
34
|
+
delete target.gate;
|
|
35
|
+
}
|
|
36
|
+
return gateSelector(getPorts()).attach(target);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/server/context.ts"],"names":[],"mappings":"AAsKA;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAqD;IAErD,MAAM,KAAK,GAAG,MAIR,CAAC;IAEP,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,KAAK,CAAC,IAAI;KACjB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAKpC,QAAyD,EACzD,QAAqB;IAErB,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC;IACnC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,IAAW,CAAC;IAC/B,CAAC;IAED,OAAO,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,MAAM,GAAG,IAAc,CAAC;QAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjE,IAAI,QAAQ,IAAI,QAAQ,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;gBAC1C,OAAO,CAAC,IAAI,CACV,gKAAgK,CACjK,CAAC;YACJ,CAAC;YACD,OAAQ,MAA6B,CAAC,IAAI,CAAC;QAC7C,CAAC;QAED,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAQ,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Re-export contract resolution utilities for the server runtime.
|
|
3
3
|
*/
|
|
4
|
-
export { type ContractLike, type ResolveContract, resolveContract, } from "../contracts";
|
|
4
|
+
export { type ContractLike, type ResolveContract, resolveContract, } from "../contracts/index.js";
|
|
5
5
|
//# sourceMappingURL=contract-like.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-like.d.ts","sourceRoot":"","sources":["../../src/server/contract-like.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,eAAe,GAChB,MAAM,
|
|
1
|
+
{"version":3,"file":"contract-like.d.ts","sourceRoot":"","sources":["../../src/server/contract-like.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,eAAe,GAChB,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-like.js","sourceRoot":"","sources":["../../src/server/contract-like.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAGL,eAAe,GAChB,MAAM,
|
|
1
|
+
{"version":3,"file":"contract-like.js","sourceRoot":"","sources":["../../src/server/contract-like.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAGL,eAAe,GAChB,MAAM,uBAAuB,CAAC"}
|
package/dist/server/health.d.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Health check handler
|
|
3
3
|
* Health check handler for Beignet server adapters.
|
|
4
4
|
*/
|
|
5
|
-
import type { AnyPorts } from "../ports";
|
|
6
|
-
import type { HttpRequestLike, HttpResponseLike } from "./types";
|
|
5
|
+
import type { AnyPorts } from "../ports/index.js";
|
|
6
|
+
import type { HttpRequestLike, HttpResponseLike } from "./types.js";
|
|
7
7
|
/**
|
|
8
8
|
* Health check result returned by health handlers.
|
|
9
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,EAAE,EAAE,OAAO,CAAC;IACZ;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC7D;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,KAAK;IACjC,8CAA8C;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,YAAY,GAAG,MAAM,CAAC;AAEnE;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,SAAS,QAAQ,EACxD,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,CAAC,KAAK,CAAC,GAAG,SAAS,EAC7C,GAAG,EAAE,cAAc,GAClB,CAAC,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAoCrD"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { InferOutput, StandardSchema } from "../../contracts/index.js";
|
|
2
|
+
import type { HttpRequestLike, RouteHook } from "../types.js";
|
|
2
3
|
type MaybePromise<T> = T | Promise<T>;
|
|
3
4
|
/**
|
|
4
5
|
* Arguments passed to auth route-hook callbacks.
|
|
5
6
|
*/
|
|
6
|
-
export type AuthHookArgs<Ctx> = {
|
|
7
|
+
export type AuthHookArgs<Ctx, HeadersSchema extends StandardSchema | undefined = undefined> = {
|
|
7
8
|
/**
|
|
8
9
|
* Framework-neutral request.
|
|
9
10
|
*/
|
|
@@ -27,9 +28,14 @@ export type AuthHookArgs<Ctx> = {
|
|
|
27
28
|
*/
|
|
28
29
|
query: unknown;
|
|
29
30
|
/**
|
|
30
|
-
*
|
|
31
|
+
* Hook-owned request headers.
|
|
32
|
+
*
|
|
33
|
+
* When the auth hooks declare a `headers` schema, this is that schema's
|
|
34
|
+
* output parsed from the raw lowercase request header record. Without a
|
|
35
|
+
* schema it is the raw lowercase header record itself, so auth resolution
|
|
36
|
+
* never depends on each route's contract header schema.
|
|
31
37
|
*/
|
|
32
|
-
headers:
|
|
38
|
+
headers: HeadersSchema extends StandardSchema ? InferOutput<HeadersSchema> : Record<string, string>;
|
|
33
39
|
/**
|
|
34
40
|
* Parsed request body.
|
|
35
41
|
*/
|
|
@@ -37,24 +43,41 @@ export type AuthHookArgs<Ctx> = {
|
|
|
37
43
|
};
|
|
38
44
|
/**
|
|
39
45
|
* Options for route-scoped auth hooks.
|
|
46
|
+
*
|
|
47
|
+
* Auth additions must not include `gate`: the server re-attaches the gate
|
|
48
|
+
* declared by the context blueprint after every hook, so elevated identities
|
|
49
|
+
* are authorized against the updated context automatically.
|
|
40
50
|
*/
|
|
41
|
-
export type AuthHooksOptions<Ctx, AddedCtx extends object
|
|
51
|
+
export type AuthHooksOptions<Ctx, AddedCtx extends object & {
|
|
52
|
+
gate?: never;
|
|
53
|
+
}, HeadersSchema extends StandardSchema | undefined = undefined> = {
|
|
42
54
|
/**
|
|
43
55
|
* Hook name prefix used in diagnostics.
|
|
44
56
|
*/
|
|
45
57
|
name?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Optional Standard Schema for the credential headers this hook reads.
|
|
60
|
+
*
|
|
61
|
+
* The schema is validated against the raw lowercase request header record
|
|
62
|
+
* before `resolve` runs. On `required()` hooks a schema failure rejects the
|
|
63
|
+
* request with a framework-owned 401; on `optional()` hooks a schema failure
|
|
64
|
+
* skips auth resolution; `public()` hooks never parse headers.
|
|
65
|
+
*/
|
|
66
|
+
headers?: HeadersSchema;
|
|
46
67
|
/**
|
|
47
68
|
* Resolve authenticated context additions for the current request.
|
|
48
69
|
*
|
|
49
70
|
* Return `null` when the request is unauthenticated. Required hooks will
|
|
50
71
|
* reject that request; optional hooks will add no auth context.
|
|
51
72
|
*/
|
|
52
|
-
resolve: (args: AuthHookArgs<Ctx>) => MaybePromise<AddedCtx | null>;
|
|
73
|
+
resolve: (args: AuthHookArgs<Ctx, HeadersSchema>) => MaybePromise<AddedCtx | null>;
|
|
53
74
|
};
|
|
54
75
|
/**
|
|
55
76
|
* Route-scoped auth hook set.
|
|
56
77
|
*/
|
|
57
|
-
export type AuthRouteHooks<Ctx, AddedCtx extends object
|
|
78
|
+
export type AuthRouteHooks<Ctx, AddedCtx extends object & {
|
|
79
|
+
gate?: never;
|
|
80
|
+
}> = {
|
|
58
81
|
/**
|
|
59
82
|
* Mark a route as intentionally public.
|
|
60
83
|
*/
|
|
@@ -71,14 +94,30 @@ export type AuthRouteHooks<Ctx, AddedCtx extends object> = {
|
|
|
71
94
|
/**
|
|
72
95
|
* Create route-scoped authentication hooks.
|
|
73
96
|
*
|
|
97
|
+
* The outer call binds the app context; the inner call takes auth options and
|
|
98
|
+
* infers the added context from `resolve`:
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* const auth = createAuthHooks<AppContext>()({
|
|
102
|
+
* resolve: ({ ctx }) => (ctx.auth ? { user: ctx.auth.user } : null),
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
74
106
|
* Use `auth.required()` on routes that require an authenticated actor and
|
|
75
107
|
* `auth.optional()` where handlers can use auth when present. The returned
|
|
76
108
|
* route hooks enrich handler `ctx`; business authorization still belongs in
|
|
77
109
|
* feature policies or use cases.
|
|
78
110
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
111
|
+
* Declare a `headers` schema when credentials live in request headers. The
|
|
112
|
+
* hook validates the raw lowercase header record itself, so `resolve` receives
|
|
113
|
+
* typed headers without contract casts and a `required()` hook rejects
|
|
114
|
+
* missing or malformed credentials with a framework-owned 401.
|
|
115
|
+
*
|
|
116
|
+
* @returns A function that takes auth options and returns public, optional,
|
|
117
|
+
* and required route-hook factories.
|
|
81
118
|
*/
|
|
82
|
-
export declare function createAuthHooks<Ctx
|
|
119
|
+
export declare function createAuthHooks<Ctx>(): <AddedCtx extends object & {
|
|
120
|
+
gate?: never;
|
|
121
|
+
}, HeadersSchema extends StandardSchema | undefined = undefined>(options: AuthHooksOptions<Ctx, AddedCtx, HeadersSchema>) => AuthRouteHooks<Ctx, AddedCtx>;
|
|
83
122
|
export {};
|
|
84
123
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/server/hooks/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/server/hooks/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE5E,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE9D,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,MAAM,YAAY,CACtB,GAAG,EACH,aAAa,SAAS,cAAc,GAAG,SAAS,GAAG,SAAS,IAC1D;IACF;;OAEG;IACH,GAAG,EAAE,eAAe,CAAC;IACrB;;OAEG;IACH,GAAG,EA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