Skip to content

Commit 9e2b07b

Browse files
committed
replayRun function added to the SDK
1 parent 7ff4080 commit 9e2b07b

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

.changeset/new-rivers-tell.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@trigger.dev/sdk": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Added replayRun function to the SDK

packages/core/src/v3/apiClient/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
BatchTriggerTaskRequestBody,
1010
BatchTriggerTaskResponse,
1111
CreateUploadPayloadUrlResponseBody,
12+
ReplayRunResponse,
1213
} from "../schemas";
1314

1415
export type TriggerOptions = {
@@ -88,6 +89,18 @@ export class ApiClient {
8889
);
8990
}
9091

92+
replayRun(runId: string) {
93+
return zodfetch(
94+
ReplayRunResponse,
95+
`${this.baseUrl}/api/v1/runs/${runId}/replay`,
96+
{
97+
method: "POST",
98+
headers: this.#getHeaders(false),
99+
},
100+
zodFetchOptions
101+
);
102+
}
103+
91104
#getHeaders(spanParentAsLink: boolean) {
92105
const headers: Record<string, string> = {
93106
"Content-Type": "application/json",

packages/core/src/v3/schemas/api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,9 @@ export const CreateUploadPayloadUrlResponseBody = z.object({
198198
});
199199

200200
export type CreateUploadPayloadUrlResponseBody = z.infer<typeof CreateUploadPayloadUrlResponseBody>;
201+
202+
export const ReplayRunResponse = z.object({
203+
id: z.string(),
204+
});
205+
206+
export type ReplayRunResponse = z.infer<typeof ReplayRunResponse>;

packages/trigger-sdk/src/v3/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ import type { Context } from "./shared";
88
export type { Context };
99

1010
export { logger, type LogLevel } from "@trigger.dev/core/v3";
11+
12+
export { replayRun } from "./management";
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { ReplayRunResponse, apiClientManager } from "@trigger.dev/core/v3";
2+
import { apiClientMissingError } from "./shared";
3+
4+
export async function replayRun(runId: string): Promise<ReplayRunResponse> {
5+
const apiClient = apiClientManager.client;
6+
7+
if (!apiClient) {
8+
throw apiClientMissingError();
9+
}
10+
11+
const response = await apiClient.replayRun(runId);
12+
13+
if (!response.ok) {
14+
throw new Error(response.error);
15+
}
16+
17+
return response.data;
18+
}

packages/trigger-sdk/src/v3/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ async function handleTaskRunExecutionResult<TOutput>(
562562
}
563563
}
564564

565-
function apiClientMissingError() {
565+
export function apiClientMissingError() {
566566
const hasBaseUrl = !!apiClientManager.baseURL;
567567
const hasAccessToken = !!apiClientManager.accessToken;
568568
if (!hasBaseUrl && !hasAccessToken) {

0 commit comments

Comments
 (0)