@leitwerk-dev/server 0.4.2 → 0.4.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.
Files changed (67) hide show
  1. package/dist/app-2TCRADVA.js +8 -0
  2. package/dist/{app-CtlotzYm.d.ts → app-DZUsf76a.d.ts} +30 -1
  3. package/dist/app.d.ts.map +1 -1
  4. package/dist/auth/api-token-routes.d.ts.map +1 -1
  5. package/dist/auth/api-token-service.d.ts +4 -3
  6. package/dist/auth/api-token-service.d.ts.map +1 -1
  7. package/dist/auth/auth-client.d.ts +17 -12
  8. package/dist/auth/auth-client.d.ts.map +1 -1
  9. package/dist/auth/auth-config.d.ts +2 -1
  10. package/dist/auth/auth-config.d.ts.map +1 -1
  11. package/dist/auth/auth-service.d.ts +10 -10
  12. package/dist/auth/auth-service.d.ts.map +1 -1
  13. package/dist/auth/auth-test-helpers.d.ts +24 -0
  14. package/dist/auth/auth-test-helpers.d.ts.map +1 -1
  15. package/dist/auth/github-oauth-client.d.ts +3 -13
  16. package/dist/auth/github-oauth-client.d.ts.map +1 -1
  17. package/dist/auth/oidc-client.d.ts +6 -14
  18. package/dist/auth/oidc-client.d.ts.map +1 -1
  19. package/dist/auth/oidc-evidence.d.ts +22 -0
  20. package/dist/auth/oidc-evidence.d.ts.map +1 -0
  21. package/dist/auth/routes.d.ts.map +1 -1
  22. package/dist/{chunk-YLWY4UTT.js → chunk-6EEU4QOU.js} +162 -5
  23. package/dist/chunk-6EEU4QOU.js.map +1 -0
  24. package/dist/{chunk-OUA5EZS2.js → chunk-AJ2DQWI3.js} +225 -189
  25. package/dist/chunk-AJ2DQWI3.js.map +1 -0
  26. package/dist/config/config-loader.d.ts.map +1 -1
  27. package/dist/config/config-types.d.ts +17 -0
  28. package/dist/config/config-types.d.ts.map +1 -1
  29. package/dist/db/api-token-repo.d.ts +3 -0
  30. package/dist/db/api-token-repo.d.ts.map +1 -1
  31. package/dist/db/auth-repo.d.ts +5 -0
  32. package/dist/db/auth-repo.d.ts.map +1 -1
  33. package/dist/db/database.d.ts.map +1 -1
  34. package/dist/db/schema.d.ts +32 -0
  35. package/dist/db/schema.d.ts.map +1 -1
  36. package/dist/index.js +2 -2
  37. package/dist/launch-pipeline.d.ts.map +1 -1
  38. package/dist/main.js +3 -3
  39. package/dist/process-launcher-registry.d.ts +3 -0
  40. package/dist/process-launcher-registry.d.ts.map +1 -1
  41. package/dist/routes/launchers.d.ts.map +1 -1
  42. package/dist/testing.js +1 -1
  43. package/package.json +12 -12
  44. package/src/app.ts +1 -0
  45. package/src/auth/api-token-routes.ts +17 -18
  46. package/src/auth/api-token-service.ts +9 -10
  47. package/src/auth/auth-client.ts +18 -18
  48. package/src/auth/auth-config.ts +18 -19
  49. package/src/auth/auth-service.ts +54 -72
  50. package/src/auth/auth-test-helpers.ts +101 -0
  51. package/src/auth/github-oauth-client.ts +8 -22
  52. package/src/auth/oidc-client.ts +34 -28
  53. package/src/auth/oidc-evidence.ts +168 -0
  54. package/src/auth/routes.ts +22 -6
  55. package/src/config/config-loader.ts +34 -0
  56. package/src/config/config-types.ts +18 -0
  57. package/src/db/api-token-repo.ts +6 -1
  58. package/src/db/auth-repo.ts +7 -0
  59. package/src/db/database.ts +14 -0
  60. package/src/db/schema.ts +2 -0
  61. package/src/launch-pipeline.ts +6 -0
  62. package/src/process-launcher-registry.ts +56 -6
  63. package/src/routes/launchers.ts +35 -20
  64. package/dist/app-KR3N2JAE.js +0 -8
  65. package/dist/chunk-OUA5EZS2.js.map +0 -1
  66. package/dist/chunk-YLWY4UTT.js.map +0 -1
  67. /package/dist/{app-KR3N2JAE.js.map → app-2TCRADVA.js.map} +0 -0
@@ -2,7 +2,7 @@ import type { AuthMeResponseBody } from "@leitwerk-dev/protocol/http-contracts";
2
2
  import type { FastifyInstance } from "fastify";
3
3
  import { registerApiTokenRoutes } from "./api-token-routes.js";
4
4
  import type { AuthService } from "./auth-service.js";
5
- import { authenticateRequest } from "./fastify-auth.js";
5
+ import { authenticateRequest, hasAuthorization } from "./fastify-auth.js";
6
6
 
7
7
  function cookieMaxAgeSeconds(expiresAt: string): number {
8
8
  return Math.max(0, Math.floor((new Date(expiresAt).getTime() - Date.now()) / 1000));
@@ -20,6 +20,14 @@ function cookieOptions(input: { secure: boolean; maxAge: number }) {
20
20
 
21
21
  export function registerAuthRoutes(app: FastifyInstance, auth: AuthService): void {
22
22
  registerApiTokenRoutes(app, auth);
23
+ app.get("/api/auth/user-information", async (request, reply) => {
24
+ reply.header("Cache-Control", "no-store");
25
+ if (hasAuthorization(request))
26
+ return reply.code(401).send({ error: "Session access required" });
27
+ const information = auth.userInformation(request.cookies?.[auth.config.sessionCookieName]);
28
+ if (!information) return reply.code(401).send({ error: "OIDC session required" });
29
+ return reply.send(information);
30
+ });
23
31
  app.get("/api/auth/me", async (request, reply) => {
24
32
  const actor = authenticateRequest(auth, request);
25
33
  if (!actor) {
@@ -27,7 +35,15 @@ export function registerAuthRoutes(app: FastifyInstance, auth: AuthService): voi
27
35
  .code(401)
28
36
  .send({ authEnabled: auth.config.enabled, actor: null } satisfies AuthMeResponseBody);
29
37
  }
30
- return reply.send({ authEnabled: auth.config.enabled, actor } satisfies AuthMeResponseBody);
38
+ return reply.send({
39
+ authEnabled: auth.config.enabled,
40
+ actor,
41
+ userInformationAvailable:
42
+ !request.headers.authorization &&
43
+ auth.config.providers.some(
44
+ (provider) => provider.kind === "oidc" && provider.id === actor.provider,
45
+ ),
46
+ } satisfies AuthMeResponseBody);
31
47
  });
32
48
 
33
49
  app.get("/auth/login", async (_request, reply) => {
@@ -45,8 +61,8 @@ export function registerAuthRoutes(app: FastifyInstance, auth: AuthService): voi
45
61
  }),
46
62
  );
47
63
  return reply.redirect(login.redirectUrl);
48
- } catch (error) {
49
- app.log.warn({ err: error }, "Failed to start OIDC login");
64
+ } catch {
65
+ app.log.warn("Failed to start OIDC login");
50
66
  return reply.code(503).send({ error: "Login is temporarily unavailable" });
51
67
  }
52
68
  });
@@ -74,8 +90,8 @@ export function registerAuthRoutes(app: FastifyInstance, auth: AuthService): voi
74
90
  }),
75
91
  );
76
92
  return reply.redirect("/");
77
- } catch (error) {
78
- app.log.warn({ err: error }, "Failed to complete OIDC login");
93
+ } catch {
94
+ app.log.warn("Failed to complete OIDC login");
79
95
  reply.clearCookie(auth.config.loginFlowCookieName, { path: "/" });
80
96
  return reply.code(403).send({ error: "Login failed" });
81
97
  }
@@ -12,6 +12,7 @@ import { createDefu } from "defu";
12
12
  import * as v from "valibot";
13
13
  import { parse as parseYaml } from "yaml";
14
14
  import { resolveApiTokenPolicy } from "../auth/api-token-policy.js";
15
+ import { policyErrors } from "../auth/oidc-evidence.js";
15
16
  import { normalizeRepositoryLocator } from "../commit-message-policy.js";
16
17
  import { resolveDockerRegistryCredentials } from "../docker-registry-credentials.js";
17
18
  import { isValidStorageSize } from "../process-storage-size.js";
@@ -122,6 +123,20 @@ export function loadConfigFromFile(filePath: string): ConfigLoadResult | ConfigL
122
123
  };
123
124
  }
124
125
  const config = applyConfigDefaults(parsedRecord.output);
126
+ for (const [index, provider] of (config.auth?.providers ?? []).entries()) {
127
+ if (provider.kind !== "oidc" || typeof provider.client_secret !== "string") continue;
128
+ provider.client_secret = provider.client_secret.replace(
129
+ /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,
130
+ (_placeholder, variable: string) => {
131
+ const value = process.env[variable];
132
+ if (!value)
133
+ throw new Error(
134
+ `auth.providers[${index}].client_secret: environment variable ${variable} is missing or empty`,
135
+ );
136
+ return value;
137
+ },
138
+ );
139
+ }
125
140
  const errors = validateResolvedConfig(config as unknown as Record<string, unknown>);
126
141
  if (errors.length > 0) {
127
142
  return { ok: false, error: `Config validation errors:\n${errors.join("\n")}` };
@@ -164,6 +179,16 @@ const authOidcProviderSchema = v.looseObject({
164
179
  redirect_uri: v.optional(authNonEmptyString),
165
180
  scopes: v.optional(v.pipe(stringArraySchema, v.nonEmpty())),
166
181
  identity_claim: v.optional(authNonEmptyString),
182
+ access: v.optional(
183
+ v.strictObject({
184
+ mode: v.picklist(["all", "restricted"]),
185
+ match: v.optional(v.picklist(["all", "any"])),
186
+ users: v.optional(v.array(authNonEmptyString)),
187
+ groups: v.optional(v.array(authNonEmptyString)),
188
+ groups_claim: v.optional(authNonEmptyString),
189
+ email_domains: v.optional(v.array(authNonEmptyString)),
190
+ }),
191
+ ),
167
192
  });
168
193
 
169
194
  const authGithubProviderSchema = v.looseObject({
@@ -822,6 +847,15 @@ function collectAuthConfigErrors(config: LeitwerkConfig): string[] {
822
847
  } catch (error) {
823
848
  errors.push(error instanceof Error ? error.message : "Invalid auth.api_tokens configuration");
824
849
  }
850
+ for (const [index, provider] of (auth?.providers ?? []).entries()) {
851
+ if (provider.kind === "oidc" && provider.access) {
852
+ errors.push(
853
+ ...policyErrors(provider.access, auth?.allowlist !== undefined).map(
854
+ (message) => `auth.providers[${index}].access: ${message}`,
855
+ ),
856
+ );
857
+ }
858
+ }
825
859
  if (!auth || auth.enabled !== true) {
826
860
  return errors;
827
861
  }
@@ -45,6 +45,22 @@ export interface AuthSessionConfig {
45
45
  ttl?: string;
46
46
  }
47
47
 
48
+ /** @internal */
49
+ export interface OidcAccessPolicy {
50
+ /** @internal */
51
+ mode: "all" | "restricted";
52
+ /** Defaults to all. @internal */
53
+ match?: "all" | "any";
54
+ /** @internal */
55
+ users?: string[];
56
+ /** @internal */
57
+ groups?: string[];
58
+ /** @internal */
59
+ groups_claim?: string;
60
+ /** @internal */
61
+ email_domains?: string[];
62
+ }
63
+
48
64
  /** @internal */
49
65
  export interface AuthOidcProviderConfig {
50
66
  /** @internal */
@@ -63,6 +79,8 @@ export interface AuthOidcProviderConfig {
63
79
  scopes?: string[];
64
80
  /** @internal */
65
81
  identity_claim?: string;
82
+ /** @internal */
83
+ access?: OidcAccessPolicy;
66
84
  }
67
85
 
68
86
  /** @internal */
@@ -1,6 +1,7 @@
1
1
  import type { Actor } from "@leitwerk-dev/domain";
2
2
  import type { ApiTokenMetadata } from "@leitwerk-dev/protocol/http-contracts";
3
3
  import { and, desc, eq, isNull } from "drizzle-orm";
4
+ import type { OidcEvidence } from "../auth/oidc-evidence.js";
4
5
  import type { LeitwerkDb } from "./database.js";
5
6
  import { apiTokens } from "./schema.js";
6
7
 
@@ -34,6 +35,8 @@ export interface ApiTokenOwner {
34
35
  actor: Actor;
35
36
  /** @internal */
36
37
  providerBinding: TokenProviderBinding | null;
38
+ /** @internal */
39
+ oidcEvidence?: OidcEvidence | null;
37
40
  }
38
41
  /** @internal */
39
42
  export interface ApiTokenRecord extends ApiTokenMetadata {
@@ -43,10 +46,11 @@ export interface ApiTokenRecord extends ApiTokenMetadata {
43
46
  owner: ApiTokenOwner;
44
47
  }
45
48
  function record(row: typeof apiTokens.$inferSelect): ApiTokenRecord {
46
- const { ownerKind, ownerId, actorJson, providerBindingJson, ...fields } = row;
49
+ const { ownerKind, ownerId, actorJson, providerBindingJson, oidcEvidenceJson, ...fields } = row;
47
50
  return {
48
51
  ...fields,
49
52
  owner: {
53
+ oidcEvidence: oidcEvidenceJson ? JSON.parse(oidcEvidenceJson) : null,
50
54
  kind: ownerKind,
51
55
  id: ownerId,
52
56
  actor: JSON.parse(actorJson),
@@ -68,6 +72,7 @@ export function createApiTokenRepo(db: LeitwerkDb) {
68
72
  ownerKind: owner.kind,
69
73
  ownerId: owner.id,
70
74
  actorJson: JSON.stringify(owner.actor),
75
+ oidcEvidenceJson: owner.oidcEvidence ? JSON.stringify(owner.oidcEvidence) : null,
71
76
  providerBindingJson: owner.providerBinding ? JSON.stringify(owner.providerBinding) : null,
72
77
  })
73
78
  .run();
@@ -1,5 +1,6 @@
1
1
  import type { Actor } from "@leitwerk-dev/domain";
2
2
  import { and, eq, gt, lt } from "drizzle-orm";
3
+ import type { OidcEvidence } from "../auth/oidc-evidence.js";
3
4
  import type { LeitwerkDb } from "./database.js";
4
5
  import { now } from "./repo-helpers.js";
5
6
  import * as s from "./schema.js";
@@ -11,6 +12,8 @@ export interface AuthSessionRecord {
11
12
  /** @internal */
12
13
  actor: Actor;
13
14
  /** @internal */
15
+ oidcEvidence: OidcEvidence | null;
16
+ /** @internal */
14
17
  createdAt: string;
15
18
  /** @internal */
16
19
  expiresAt: string;
@@ -35,6 +38,7 @@ export interface AuthLoginFlowRecord {
35
38
  function sessionRowToRecord(row: typeof s.authSessions.$inferSelect): AuthSessionRecord {
36
39
  return {
37
40
  idHash: row.idHash,
41
+ oidcEvidence: row.oidcEvidenceJson ? JSON.parse(row.oidcEvidenceJson) : null,
38
42
  actor: {
39
43
  id: row.actorId,
40
44
  kind: "user",
@@ -56,12 +60,15 @@ export function createAuthSessionRepo(db: LeitwerkDb) {
56
60
  /** @internal */
57
61
  actor: Actor;
58
62
  /** @internal */
63
+ oidcEvidence?: OidcEvidence | null;
64
+ /** @internal */
59
65
  expiresAt: string;
60
66
  }): AuthSessionRecord {
61
67
  const ts = now();
62
68
  const values = {
63
69
  idHash: input.idHash,
64
70
  actorId: input.actor.id,
71
+ oidcEvidenceJson: input.oidcEvidence ? JSON.stringify(input.oidcEvidence) : null,
65
72
  actorProvider: input.actor.provider,
66
73
  displayName: input.actor.displayName ?? null,
67
74
  createdAt: ts,
@@ -466,6 +466,20 @@ const KNOWN_MIGRATIONS: readonly KnownMigration[] = [
466
466
  existingTableSql(sqlite, "auth_sessions") !== null &&
467
467
  existingTableSql(sqlite, "api_tokens") === null,
468
468
  ),
469
+ {
470
+ id: "20260909_add_oidc_evidence",
471
+ tableNames: ["auth_sessions", "api_tokens"],
472
+ matches: (sqlite) =>
473
+ existingTableSql(sqlite, "auth_sessions") !== null &&
474
+ (!tableHasColumn(sqlite, "auth_sessions", "oidc_evidence_json") ||
475
+ !tableHasColumn(sqlite, "api_tokens", "oidc_evidence_json")),
476
+ apply(sqlite) {
477
+ for (const table of ["auth_sessions", "api_tokens"]) {
478
+ if (!tableHasColumn(sqlite, table, "oidc_evidence_json"))
479
+ sqlite.exec(`ALTER TABLE ${table} ADD COLUMN oidc_evidence_json text`);
480
+ }
481
+ },
482
+ },
469
483
  {
470
484
  id: "20260901_add_session_transfers",
471
485
  tableNames: ["session_transfer_grants", "session_transfer_attempts"],
package/src/db/schema.ts CHANGED
@@ -574,6 +574,7 @@ export const authSessions = sqliteTable(
574
574
  displayName: text("display_name"),
575
575
  createdAt: text("created_at").notNull(),
576
576
  expiresAt: text("expires_at").notNull(),
577
+ oidcEvidenceJson: text("oidc_evidence_json"),
577
578
  },
578
579
  (t) => [
579
580
  index("idx_auth_sessions_expires").on(t.expiresAt),
@@ -957,6 +958,7 @@ export const apiTokens = sqliteTable(
957
958
  expiresAt: text("expires_at"),
958
959
  revokedAt: text("revoked_at"),
959
960
  lastUsedAt: text("last_used_at"),
961
+ oidcEvidenceJson: text("oidc_evidence_json"),
960
962
  },
961
963
  (t) => [
962
964
  uniqueIndex("idx_api_tokens_secret_hash").on(t.secretHash),
@@ -400,6 +400,11 @@ export function createLaunchPipeline(deps: {
400
400
  mutate(launchRunId, (run) => transitionLaunchStep(run, id, "completed"));
401
401
  } catch (error) {
402
402
  controller.abort();
403
+ if (!(error instanceof SafeLaunchPreparationError)) {
404
+ logger.warn(
405
+ `Launch preparation failed; correlationId=${launchRunId}; check=${check.id}`,
406
+ );
407
+ }
403
408
  const safeSummary =
404
409
  error instanceof SafeLaunchPreparationError
405
410
  ? error.safeSummary
@@ -442,6 +447,7 @@ export function createLaunchPipeline(deps: {
442
447
  reused: committed.kind === "committed" ? committed.reused : false,
443
448
  };
444
449
  } catch (error) {
450
+ logger.warn(`Unexpected launch failure; correlationId=${launchRunId}`);
445
451
  const run = deps.launchRuns.getById(launchRunId);
446
452
  const failure = adapter.unexpectedFailure?.(error) ?? {
447
453
  safeSummary: "The launch could not be completed. Try again.",
@@ -1,15 +1,17 @@
1
+ import { randomUUID } from "node:crypto";
1
2
  import type { ExtensionCatalog } from "@leitwerk-dev/extension-runtime";
2
3
  import type {
3
4
  ExtensionProcessDefinition,
4
5
  LauncherContext,
5
6
  LauncherModelProfileSummary,
7
+ LauncherReadiness,
6
8
  ProcessLaunchConfig,
7
9
  ProcessLauncherDefinition,
8
10
  ProcessLauncherService,
9
11
  ResolvedProcessLauncher,
10
12
  UiLauncherSummary,
11
13
  } from "@leitwerk-dev/process-sdk";
12
- import { buildProcessLaunchers } from "@leitwerk-dev/process-sdk";
14
+ import { buildProcessLaunchers, SafeLaunchPreparationError } from "@leitwerk-dev/process-sdk";
13
15
  import type { CommitMessageConfig } from "./config/config-types.js";
14
16
  import { buildProcessLaunchPlan, validateLaunchPreparationChecks } from "./process-launch-plan.js";
15
17
 
@@ -24,6 +26,7 @@ interface ProcessLauncherRegistryOptions {
24
26
  modelProfiles?: readonly LauncherModelProfileSummary[];
25
27
  getModelProfilesForProcess?: (processId: string) => readonly LauncherModelProfileSummary[];
26
28
  commitMessages?: CommitMessageConfig;
29
+ logger?: { warn(message: string): void };
27
30
  }
28
31
 
29
32
  function buildResolvedProcessLauncher(
@@ -112,6 +115,30 @@ export function buildProcessLauncherRegistry(
112
115
  };
113
116
  }
114
117
 
118
+ function resolveUiReadiness(
119
+ launcherId: string,
120
+ input: Record<string, unknown>,
121
+ ): LauncherReadiness {
122
+ const { ui } = requireUiLauncher(launcherId);
123
+ try {
124
+ return ui.readiness?.(input) ?? { status: "ready", issues: [] };
125
+ } catch {
126
+ const correlationId = randomUUID();
127
+ // Do not log exception messages: integration errors may contain credentials.
128
+ options.logger?.warn(`Launcher readiness failed; correlationId=${correlationId}`);
129
+ return {
130
+ status: "blocked",
131
+ issues: [
132
+ {
133
+ code: "launcher_readiness_failed",
134
+ summary: "Configuration readiness could not be checked.",
135
+ remediation: `Ask an operator to inspect the server logs. Reference: ${correlationId}`,
136
+ },
137
+ ],
138
+ };
139
+ }
140
+ }
141
+
115
142
  const uiLaunchers = [...launchers.values()]
116
143
  .filter((launcher) => launcher.definition.ui)
117
144
  .map(
@@ -133,9 +160,16 @@ export function buildProcessLauncherRegistry(
133
160
 
134
161
  return {
135
162
  listUiLaunchers() {
136
- return uiLaunchers;
163
+ return uiLaunchers.map((launcher) => ({
164
+ ...launcher,
165
+ ...(requireUiLauncher(launcher.id).ui.readiness
166
+ ? { readiness: resolveUiReadiness(launcher.id, {}) }
167
+ : {}),
168
+ }));
137
169
  },
138
170
 
171
+ resolveUiReadiness,
172
+
139
173
  async resolveUiDefaults(launcherId, ctx = {}) {
140
174
  const { launcher, ui } = requireUiLauncher(launcherId);
141
175
  return (await ui.resolveDefaults?.(createLauncherContext(launcher.processId, ctx))) ?? {};
@@ -159,10 +193,26 @@ export function buildProcessLauncherRegistry(
159
193
 
160
194
  resolvePreparationChecks(launcherId, input, launchConfig) {
161
195
  const { ui } = requireUiLauncher(launcherId);
162
- return validateLaunchPreparationChecks(
163
- ui.preparationChecks?.(input, launchConfig),
164
- `Launcher '${launcherId}'`,
165
- );
196
+ const checks = [...(ui.preparationChecks?.(input, launchConfig) ?? [])];
197
+ if (ui.readiness) {
198
+ checks.unshift({
199
+ id: "launcher-readiness",
200
+ label: "Check launcher configuration",
201
+ async run() {
202
+ const readiness = resolveUiReadiness(launcherId, input);
203
+ if (readiness.status !== "ready") {
204
+ const summary = readiness.issues
205
+ .map((issue) => `${issue.summary} ${issue.remediation}`)
206
+ .join(" ");
207
+ throw new SafeLaunchPreparationError(
208
+ "Launcher configuration is incomplete",
209
+ summary || "Complete launcher configuration before launching.",
210
+ );
211
+ }
212
+ },
213
+ });
214
+ }
215
+ return validateLaunchPreparationChecks(checks, `Launcher '${launcherId}'`);
166
216
  },
167
217
 
168
218
  async resolveUiLauncher(launcherId, input, ctx = {}) {
@@ -3,6 +3,7 @@ import type {
3
3
  LauncherDefaultsResponseBody,
4
4
  LauncherModelConfigPreviewResponseBody,
5
5
  LauncherOptionsResponseBody,
6
+ LauncherReadinessResponseBody,
6
7
  LauncherRecentValuesResponseBody,
7
8
  LaunchersResponseBody,
8
9
  LauncherValidationResponseBody,
@@ -195,27 +196,41 @@ export function registerLauncherRoutes(
195
196
  },
196
197
  );
197
198
 
198
- app.post<{ Params: { launcherId: string }; Body: unknown }>(
199
- "/api/launchers/:launcherId/options",
200
- async (req, reply) => {
201
- const normalized = normalizeLauncherRequest(req.body);
202
- if (!normalized.ok) {
203
- return sendLauncherRequestNormalizationError(reply, normalized.error);
204
- }
205
- try {
206
- const options = await deps.launcherService.resolveUiOptions(
207
- req.params.launcherId,
208
- normalized.request.launcherInput,
209
- );
210
- const body = { options } satisfies LauncherOptionsResponseBody;
211
- return body;
212
- } catch (error) {
213
- if (sendLauncherLookupFailure(reply, error)) {
214
- return;
199
+ function postLauncherInput(
200
+ path: string,
201
+ resolve: (launcherId: string, input: Record<string, unknown>) => unknown,
202
+ ) {
203
+ app.post<{ Params: { launcherId: string }; Body: unknown }>(
204
+ `/api/launchers/:launcherId/${path}`,
205
+ async (req, reply) => {
206
+ const normalized = normalizeLauncherRequest(req.body);
207
+ if (!normalized.ok) return sendLauncherRequestNormalizationError(reply, normalized.error);
208
+ try {
209
+ return await resolve(req.params.launcherId, normalized.request.launcherInput);
210
+ } catch (error) {
211
+ if (sendLauncherLookupFailure(reply, error)) return;
212
+ throw error;
215
213
  }
216
- throw error;
217
- }
218
- },
214
+ },
215
+ );
216
+ }
217
+
218
+ postLauncherInput(
219
+ "readiness",
220
+ (launcherId, input) =>
221
+ ({
222
+ readiness: deps.launcherService.resolveUiReadiness?.(launcherId, input) ?? {
223
+ status: "ready",
224
+ issues: [],
225
+ },
226
+ }) satisfies LauncherReadinessResponseBody,
227
+ );
228
+ postLauncherInput(
229
+ "options",
230
+ async (launcherId, input) =>
231
+ ({
232
+ options: await deps.launcherService.resolveUiOptions(launcherId, input),
233
+ }) satisfies LauncherOptionsResponseBody,
219
234
  );
220
235
 
221
236
  app.post<{ Params: { launcherId: string }; Body: unknown }>(
@@ -1,8 +0,0 @@
1
- import {
2
- createAppContext
3
- } from "./chunk-OUA5EZS2.js";
4
- import "./chunk-YLWY4UTT.js";
5
- export {
6
- createAppContext
7
- };
8
- //# sourceMappingURL=app-KR3N2JAE.js.map