-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathapi.v1.idempotencyKeys.$key.reset.ts
More file actions
51 lines (44 loc) · 1.51 KB
/
api.v1.idempotencyKeys.$key.reset.ts
File metadata and controls
51 lines (44 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { json } from "@remix-run/server-runtime";
import { ServiceValidationError } from "~/v3/services/baseService.server";
import { z } from "zod";
import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
import { ResetIdempotencyKeyService } from "~/v3/services/resetIdempotencyKey.server";
import { logger } from "~/services/logger.server";
const ParamsSchema = z.object({
key: z.string(),
});
const BodySchema = z.object({
taskIdentifier: z.string().min(1, "Task identifier is required"),
});
export const { action } = createActionApiRoute(
{
params: ParamsSchema,
body: BodySchema,
allowJWT: true,
corsStrategy: "all",
authorization: {
action: "write",
resource: () => ({}),
superScopes: ["write:runs", "admin"],
},
},
async ({ params, body, authentication }) => {
const service = new ResetIdempotencyKeyService();
try {
const result = await service.call(
params.key,
body.taskIdentifier,
authentication.environment
);
return json(result, { status: 200 });
} catch (error) {
if (error instanceof ServiceValidationError) {
return json({ error: error.message }, { status: error.status ?? 400 });
}
logger.error("Failed to reset idempotency key via API", {
error: error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : String(error),
});
return json({ error: "Internal Server Error" }, { status: 500 });
}
}
);