Skip to content

Commit 6336713

Browse files
committed
style(webapp): prettier pass on touched routes
1 parent 7529ea8 commit 6336713

20 files changed

Lines changed: 907 additions & 912 deletions

apps/webapp/app/routes/api.v1.artifacts.ts

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -14,81 +14,81 @@ export async function action({ request }: ActionFunctionArgs) {
1414
}
1515

1616
try {
17-
const authenticationResult = await authenticateRequest(request, {
18-
apiKey: true,
19-
organizationAccessToken: false,
20-
personalAccessToken: false,
21-
});
17+
const authenticationResult = await authenticateRequest(request, {
18+
apiKey: true,
19+
organizationAccessToken: false,
20+
personalAccessToken: false,
21+
});
2222

23-
if (!authenticationResult || !authenticationResult.result.ok) {
24-
logger.info("Invalid or missing api key", { url: request.url });
25-
return json({ error: "Invalid or Missing API key" }, { status: 401 });
26-
}
23+
if (!authenticationResult || !authenticationResult.result.ok) {
24+
logger.info("Invalid or missing api key", { url: request.url });
25+
return json({ error: "Invalid or Missing API key" }, { status: 401 });
26+
}
2727

28-
const [, rawBody] = await tryCatch(request.json());
29-
const body = CreateArtifactRequestBody.safeParse(rawBody ?? {});
28+
const [, rawBody] = await tryCatch(request.json());
29+
const body = CreateArtifactRequestBody.safeParse(rawBody ?? {});
3030

31-
if (!body.success) {
32-
return json({ error: "Invalid request body", issues: body.error.issues }, { status: 400 });
33-
}
31+
if (!body.success) {
32+
return json({ error: "Invalid request body", issues: body.error.issues }, { status: 400 });
33+
}
3434

35-
const { environment: authenticatedEnv } = authenticationResult.result;
35+
const { environment: authenticatedEnv } = authenticationResult.result;
3636

37-
const service = new ArtifactsService();
38-
return await service
39-
.createArtifact(body.data.type, authenticatedEnv, body.data.contentLength)
40-
.match(
41-
(result) => {
42-
return json(
43-
{
44-
artifactKey: result.artifactKey,
45-
uploadUrl: result.uploadUrl,
46-
uploadFields: result.uploadFields,
47-
expiresAt: result.expiresAt.toISOString(),
48-
} satisfies CreateArtifactResponseBody,
49-
{ status: 201 }
50-
);
51-
},
52-
(error) => {
53-
switch (error.type) {
54-
case "artifact_size_exceeds_limit": {
55-
logger.warn("Artifact size exceeds limit", { error });
56-
const sizeMB = parseFloat((error.contentLength / (1024 * 1024)).toFixed(1));
57-
const limitMB = parseFloat((error.sizeLimit / (1024 * 1024)).toFixed(1));
37+
const service = new ArtifactsService();
38+
return await service
39+
.createArtifact(body.data.type, authenticatedEnv, body.data.contentLength)
40+
.match(
41+
(result) => {
42+
return json(
43+
{
44+
artifactKey: result.artifactKey,
45+
uploadUrl: result.uploadUrl,
46+
uploadFields: result.uploadFields,
47+
expiresAt: result.expiresAt.toISOString(),
48+
} satisfies CreateArtifactResponseBody,
49+
{ status: 201 }
50+
);
51+
},
52+
(error) => {
53+
switch (error.type) {
54+
case "artifact_size_exceeds_limit": {
55+
logger.warn("Artifact size exceeds limit", { error });
56+
const sizeMB = parseFloat((error.contentLength / (1024 * 1024)).toFixed(1));
57+
const limitMB = parseFloat((error.sizeLimit / (1024 * 1024)).toFixed(1));
5858

59-
let errorMessage;
59+
let errorMessage;
6060

61-
switch (body.data.type) {
62-
case "deployment_context":
63-
errorMessage = `Artifact size (${sizeMB} MB) exceeds the allowed limit of ${limitMB} MB. Make sure you are in the correct directory of your Trigger.dev project. Reach out to us if you are seeing this error consistently.`;
64-
break;
65-
default:
66-
body.data.type satisfies never;
67-
errorMessage = `Artifact size (${sizeMB} MB) exceeds the allowed limit of ${limitMB} MB`;
61+
switch (body.data.type) {
62+
case "deployment_context":
63+
errorMessage = `Artifact size (${sizeMB} MB) exceeds the allowed limit of ${limitMB} MB. Make sure you are in the correct directory of your Trigger.dev project. Reach out to us if you are seeing this error consistently.`;
64+
break;
65+
default:
66+
body.data.type satisfies never;
67+
errorMessage = `Artifact size (${sizeMB} MB) exceeds the allowed limit of ${limitMB} MB`;
68+
}
69+
return json(
70+
{
71+
error: errorMessage,
72+
},
73+
{ status: 400 }
74+
);
75+
}
76+
case "failed_to_create_presigned_post": {
77+
logger.error("Failed to create presigned POST", { error });
78+
return json({ error: "Failed to generate artifact upload URL" }, { status: 500 });
79+
}
80+
case "artifacts_bucket_not_configured": {
81+
logger.error("Artifacts bucket not configured", { error });
82+
return json({ error: "Internal server error" }, { status: 500 });
83+
}
84+
default: {
85+
error satisfies never;
86+
logger.error("Failed creating artifact", { error });
87+
return json({ error: "Internal server error" }, { status: 500 });
6888
}
69-
return json(
70-
{
71-
error: errorMessage,
72-
},
73-
{ status: 400 }
74-
);
75-
}
76-
case "failed_to_create_presigned_post": {
77-
logger.error("Failed to create presigned POST", { error });
78-
return json({ error: "Failed to generate artifact upload URL" }, { status: 500 });
79-
}
80-
case "artifacts_bucket_not_configured": {
81-
logger.error("Artifacts bucket not configured", { error });
82-
return json({ error: "Internal server error" }, { status: 500 });
83-
}
84-
default: {
85-
error satisfies never;
86-
logger.error("Failed creating artifact", { error });
87-
return json({ error: "Internal server error" }, { status: 500 });
8889
}
8990
}
90-
}
91-
);
91+
);
9292
} catch (error) {
9393
if (error instanceof Response) throw error;
9494
logger.error("Failed to create artifact", { error });

apps/webapp/app/routes/api.v1.auth.jwt.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,38 @@ const RequestBodySchema = z.object({
1616

1717
export async function action({ request }: LoaderFunctionArgs) {
1818
try {
19-
// Next authenticate the request
20-
const authenticationResult = await authenticateApiRequest(request);
21-
22-
if (!authenticationResult) {
23-
return json({ error: "Invalid or Missing API key" }, { status: 401 });
24-
}
25-
26-
const parsedBody = RequestBodySchema.safeParse(await request.json());
27-
28-
if (!parsedBody.success) {
29-
return json(
30-
{ error: "Invalid request body", issues: parsedBody.error.issues },
31-
{ status: 400 }
32-
);
33-
}
34-
35-
const claims = {
36-
sub: authenticationResult.environment.id,
37-
pub: true,
38-
...parsedBody.data.claims,
39-
};
40-
41-
// Sign with the environment's current canonical key, not the raw header key,
42-
// so JWTs minted with a revoked (grace-window) key still validate — validation
43-
// in jwtAuth.server.ts uses environment.apiKey.
44-
const jwt = await internal_generateJWT({
45-
secretKey: authenticationResult.environment.apiKey,
46-
payload: claims,
47-
expirationTime: parsedBody.data.expirationTime ?? "1h",
48-
});
49-
50-
return json({ token: jwt });
19+
// Next authenticate the request
20+
const authenticationResult = await authenticateApiRequest(request);
21+
22+
if (!authenticationResult) {
23+
return json({ error: "Invalid or Missing API key" }, { status: 401 });
24+
}
25+
26+
const parsedBody = RequestBodySchema.safeParse(await request.json());
27+
28+
if (!parsedBody.success) {
29+
return json(
30+
{ error: "Invalid request body", issues: parsedBody.error.issues },
31+
{ status: 400 }
32+
);
33+
}
34+
35+
const claims = {
36+
sub: authenticationResult.environment.id,
37+
pub: true,
38+
...parsedBody.data.claims,
39+
};
40+
41+
// Sign with the environment's current canonical key, not the raw header key,
42+
// so JWTs minted with a revoked (grace-window) key still validate — validation
43+
// in jwtAuth.server.ts uses environment.apiKey.
44+
const jwt = await internal_generateJWT({
45+
secretKey: authenticationResult.environment.apiKey,
46+
payload: claims,
47+
expirationTime: parsedBody.data.expirationTime ?? "1h",
48+
});
49+
50+
return json({ token: jwt });
5151
} catch (error) {
5252
if (error instanceof Response) throw error;
5353
logger.error("Failed to mint auth jwt", { error });

apps/webapp/app/routes/api.v1.batches.$batchParam.results.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,34 @@ const ParamsSchema = z.object({
1313

1414
export async function loader({ request, params }: LoaderFunctionArgs) {
1515
try {
16-
// Authenticate the request
17-
const authenticationResult = await authenticateApiRequest(request);
16+
// Authenticate the request
17+
const authenticationResult = await authenticateApiRequest(request);
1818

19-
if (!authenticationResult) {
20-
return json({ error: "Invalid or Missing API Key" }, { status: 401 });
21-
}
19+
if (!authenticationResult) {
20+
return json({ error: "Invalid or Missing API Key" }, { status: 401 });
21+
}
2222

23-
const parsed = ParamsSchema.safeParse(params);
23+
const parsed = ParamsSchema.safeParse(params);
2424

25-
if (!parsed.success) {
26-
return json({ error: "Invalid or missing run ID" }, { status: 400 });
27-
}
25+
if (!parsed.success) {
26+
return json({ error: "Invalid or missing run ID" }, { status: 400 });
27+
}
2828

29-
const { batchParam } = parsed.data;
29+
const { batchParam } = parsed.data;
3030

31-
try {
32-
const presenter = new ApiBatchResultsPresenter();
33-
const result = await presenter.call(batchParam, authenticationResult.environment);
31+
try {
32+
const presenter = new ApiBatchResultsPresenter();
33+
const result = await presenter.call(batchParam, authenticationResult.environment);
3434

35-
if (!result) {
36-
return json({ error: "Batch not found" }, { status: 404 });
37-
}
35+
if (!result) {
36+
return json({ error: "Batch not found" }, { status: 404 });
37+
}
3838

39-
return json(result);
40-
} catch (error) {
41-
logger.error("Failed to load batch results", { error });
42-
return json({ error: "Something went wrong, please try again." }, { status: 500 });
43-
}
39+
return json(result);
40+
} catch (error) {
41+
logger.error("Failed to load batch results", { error });
42+
return json({ error: "Something went wrong, please try again." }, { status: 500 });
43+
}
4444
} catch (error) {
4545
if (error instanceof Response) throw error;
4646
logger.error("Failed to load batch results (outer)", { error });

apps/webapp/app/routes/api.v1.deployments.$deploymentId.background-workers.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,59 +24,59 @@ export async function action({ request, params }: ActionFunctionArgs) {
2424
}
2525

2626
try {
27-
// Next authenticate the request
28-
const authenticationResult = await authenticateApiRequest(request);
27+
// Next authenticate the request
28+
const authenticationResult = await authenticateApiRequest(request);
2929

30-
if (!authenticationResult) {
31-
logger.info("Invalid or missing api key", { url: request.url });
32-
return json({ error: "Invalid or Missing API key" }, { status: 401 });
33-
}
34-
35-
const authenticatedEnv = authenticationResult.environment;
30+
if (!authenticationResult) {
31+
logger.info("Invalid or missing api key", { url: request.url });
32+
return json({ error: "Invalid or Missing API key" }, { status: 401 });
33+
}
3634

37-
const { deploymentId } = parsedParams.data;
35+
const authenticatedEnv = authenticationResult.environment;
3836

39-
const rawBody = await request.json();
40-
const body = CreateBackgroundWorkerRequestBody.safeParse(rawBody);
37+
const { deploymentId } = parsedParams.data;
4138

42-
if (!body.success) {
43-
return json({ error: "Invalid body", issues: body.error.issues }, { status: 400 });
44-
}
39+
const rawBody = await request.json();
40+
const body = CreateBackgroundWorkerRequestBody.safeParse(rawBody);
4541

46-
const service = new CreateDeploymentBackgroundWorkerServiceV4();
42+
if (!body.success) {
43+
return json({ error: "Invalid body", issues: body.error.issues }, { status: 400 });
44+
}
4745

48-
try {
49-
const backgroundWorker = await service.call(authenticatedEnv, deploymentId, body.data);
46+
const service = new CreateDeploymentBackgroundWorkerServiceV4();
47+
48+
try {
49+
const backgroundWorker = await service.call(authenticatedEnv, deploymentId, body.data);
50+
51+
if (!backgroundWorker) {
52+
return json({ error: "Failed to create background worker" }, { status: 500 });
53+
}
54+
55+
return json(
56+
{
57+
id: backgroundWorker.friendlyId,
58+
version: backgroundWorker.version,
59+
contentHash: backgroundWorker.contentHash,
60+
},
61+
{ status: 200 }
62+
);
63+
} catch (e) {
64+
// Customer-facing validation failures (invalid task config, customer cron
65+
// expression, etc.). The handler returns 4xx with the message; system
66+
// handles it gracefully, no alert needed.
67+
if (e instanceof ServiceValidationError) {
68+
logger.warn("Failed to create background worker", { error: e.message });
69+
return json({ error: e.message }, { status: e.status ?? 400 });
70+
}
71+
if (e instanceof CreateDeclarativeScheduleError) {
72+
logger.warn("Failed to create background worker", { error: e.message });
73+
return json({ error: e.message }, { status: 400 });
74+
}
75+
76+
logger.error("Failed to create background worker", { error: e });
5077

51-
if (!backgroundWorker) {
5278
return json({ error: "Failed to create background worker" }, { status: 500 });
5379
}
54-
55-
return json(
56-
{
57-
id: backgroundWorker.friendlyId,
58-
version: backgroundWorker.version,
59-
contentHash: backgroundWorker.contentHash,
60-
},
61-
{ status: 200 }
62-
);
63-
} catch (e) {
64-
// Customer-facing validation failures (invalid task config, customer cron
65-
// expression, etc.). The handler returns 4xx with the message; system
66-
// handles it gracefully, no alert needed.
67-
if (e instanceof ServiceValidationError) {
68-
logger.warn("Failed to create background worker", { error: e.message });
69-
return json({ error: e.message }, { status: e.status ?? 400 });
70-
}
71-
if (e instanceof CreateDeclarativeScheduleError) {
72-
logger.warn("Failed to create background worker", { error: e.message });
73-
return json({ error: e.message }, { status: 400 });
74-
}
75-
76-
logger.error("Failed to create background worker", { error: e });
77-
78-
return json({ error: "Failed to create background worker" }, { status: 500 });
79-
}
8080
} catch (error) {
8181
if (error instanceof Response) throw error;
8282
logger.error("Failed to create deployment background worker", { error });

0 commit comments

Comments
 (0)