Skip to content

Commit 78f534e

Browse files
committed
Some initial types and improved plan
1 parent 62135c6 commit 78f534e

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export * from "./tasks.js";
77
export * from "./idempotencyKeys.js";
88
export * from "./tools.js";
99
export * from "./queues.js";
10+
export * from "./waitpoints.js";
1011

1112
type ResolveEnvironmentVariablesOptions = {
1213
variables: Record<string, string> | Array<{ name: string; value: string }>;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { AnySchemaParseFn, inferSchemaIn, inferSchemaOut, Schema } from "./schemas.js";
2+
3+
export type HttpCallbackSchema = Schema;
4+
export type HttpCallbackResultTypeFromSchema<TSchema extends HttpCallbackSchema> =
5+
inferSchemaOut<TSchema>;
6+
export type HttpCallbackResult<TResult> =
7+
| {
8+
ok: true;
9+
result: TResult;
10+
}
11+
| {
12+
ok: false;
13+
error: Error;
14+
};

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

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import {
2020
WaitpointTokenStatus,
2121
WaitpointRetrieveTokenResponse,
2222
CreateWaitpointTokenResponse,
23+
HttpCallbackSchema,
24+
HttpCallbackResultTypeFromSchema,
25+
HttpCallbackResult,
2326
} from "@trigger.dev/core/v3";
2427
import { tracer } from "./tracer.js";
2528
import { conditionallyImportAndParsePacket } from "@trigger.dev/core/v3/utils/ioSerialization";
@@ -310,31 +313,44 @@ async function completeToken<T>(
310313
}
311314

312315
async function forHttpCallback<TResult>(
313-
callback: (successUrl: string, failureUrl: string) => Promise<TResult>
314-
) {
316+
callback: (url: string) => Promise<void>,
317+
options?: {
318+
timeout?: string | Date | undefined;
319+
}
320+
): Promise<HttpCallbackResult<TResult>> {
315321
//TODO:
316322
// Support a schema passed in, infer the type, or a generic supplied type
317-
// 1. Create a span for the main call
318-
// 2. Make an API call to api.trigger.dev/v1/http-callback/create
319-
// 3. Return the successUrl and failureUrl and a waitpoint id (but don't block the run yet)
320-
// 4. Set the successUrl, failureUrl and waitpoint entity type and id as attributes on the parent span
323+
// Support a timeout passed in
324+
// 1. Make an API call to engine.trigger.dev/v1/waitpoints/http-callback/create. New Waitpoint type "HTTPCallback"
325+
// 2. Return the url and a waitpoint id (but don't block the run yet)
326+
// 3. Create a span for the main call
327+
// 4. Set the url and waitpoint entity type and id as attributes on the parent span
321328
// 5. Create a span around the callback
322329
// 6. Deal with errors thrown in the callback use `tryCatch()`
323-
// 7. If that callback is successfully called, wait for the waitpoint with an API call to api.trigger.dev/v1/http-callback/wait
330+
// 7. If that callback is successfully called, wait for the waitpoint with an API call to engine.trigger.dev/v1/waitpoints/http-callback/{waitpointId}/block
324331
// 8. Wait for the waitpoint in the runtime
325-
// 9. On the backend when the success/fail API is hit, complete the waitpoint with the result
332+
// 9. On the backend when the API is hit, complete the waitpoint with the result api.trigger.dev/v1/waitpoints/http-callback/{waitpointId}/callback
326333
// 10. Receive the result here and import the packet, then get the result in the right format
327334
// 11. Make unwrap work
328335

329-
const successUrl = "https://trigger.dev/wait/success";
330-
const failureUrl = "https://trigger.dev/wait/failure";
336+
const url = "https://trigger.dev/wait/success";
331337

332-
const result = await callback(successUrl, failureUrl);
338+
const result = await callback(url);
333339

334340
return {
335341
ok: true,
336342
output: result,
337-
};
343+
} as any;
344+
}
345+
346+
async function forHttpCallbackWithSchema<TSchema extends HttpCallbackSchema>(
347+
schema: TSchema,
348+
callback: (successUrl: string, failureUrl: string) => Promise<void>,
349+
options?: {
350+
timeout?: string | Date | undefined;
351+
}
352+
): Promise<HttpCallbackResult<HttpCallbackResultTypeFromSchema<TSchema>>> {
353+
return {} as any;
338354
}
339355

340356
export type CommonWaitOptions = {

0 commit comments

Comments
 (0)