@@ -309,6 +309,34 @@ async function completeToken<T>(
309309 return apiClient . completeWaitpointToken ( tokenId , { data } , $requestOptions ) ;
310310}
311311
312+ async function forHttpCallback < TResult > (
313+ callback : ( successUrl : string , failureUrl : string ) => Promise < TResult >
314+ ) {
315+ //TODO:
316+ // 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
321+ // 5. Create a span around the callback
322+ // 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
324+ // 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
326+ // 10. Receive the result here and import the packet, then get the result in the right format
327+ // 11. Make unwrap work
328+
329+ const successUrl = "https://trigger.dev/wait/success" ;
330+ const failureUrl = "https://trigger.dev/wait/failure" ;
331+
332+ const result = await callback ( successUrl , failureUrl ) ;
333+
334+ return {
335+ ok : true ,
336+ output : result ,
337+ } ;
338+ }
339+
312340export type CommonWaitOptions = {
313341 /**
314342 * An optional idempotency key for the waitpoint.
0 commit comments