-
-
Notifications
You must be signed in to change notification settings - Fork 743
Waitpoint token callback URLs #2025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
62135c6
Initial commit with a plan for what we’re going to do
matt-aitken 78f534e
Some initial types and improved plan
matt-aitken d9aea07
Add Waitpoint resolver
matt-aitken 87e107d
Add resolver + status index
matt-aitken 59b13f6
Remove type + status index
matt-aitken 30a5497
Only drop if exists
matt-aitken b7218af
Remove type index
matt-aitken 601002b
Update waitpoint list presenter to use resolver
matt-aitken 79e98c1
Added resolver to the engine
matt-aitken 1c09fbe
Made the existing waitpoint list presenter more flexible
matt-aitken b9edd2e
Initial implentation ofr wait.forHttpCallback()
matt-aitken 93fbfb4
Added the callback endpoint (no API rate limit)
matt-aitken 6df4084
schema version
matt-aitken 676f676
Added jsdocs, removed schema version because of errors
matt-aitken 27f2bde
Show callback URL if it’s set
matt-aitken 25448bd
Dashboard pages and panels
matt-aitken 8bfc515
Remove todos
matt-aitken 2b21ca3
Added temporary icon
matt-aitken f5d73f4
Added a blank state
matt-aitken 1e5350a
Some tweaks and added a Replicate example
matt-aitken 71d88b9
Implement unwrap() for httpCallback
matt-aitken 7766c2f
Added unwrap to wait.forToken() as well
matt-aitken 54e76ce
Improved jsdocs
matt-aitken 6cd8870
Added docs
matt-aitken 3f50577
Added unwrap to the token docs
matt-aitken c48b27a
Merge branch 'main' into wait-for-http-callback
matt-aitken 455f5a2
Show a dash if there are no tags
matt-aitken d1c19fc
Make the timeout error safer
matt-aitken e2eb321
Fixed migrations… should use id desc not createdAt desc
matt-aitken b218ff8
Fixed page title
matt-aitken 8503cea
Fixed migration so it only adds them if they don’t exist. This allows…
matt-aitken 799f8e1
Respect the max content length by getting the length of the body
matt-aitken ec9fdf6
Added more docs details about the callback format
matt-aitken 49e7f15
Remove code comment
matt-aitken aad1278
Improved the error
matt-aitken 17bcce6
Added a hash to the HTTP callback URLs
matt-aitken 46c34f3
Add the apiKey to the API input type to fix TS error
matt-aitken 344dfde
Return the error responses. They were being caught and not preserved
matt-aitken fcbc275
The content-length header is required. Deal with an empty body
matt-aitken 4b790bd
Removed unused types
matt-aitken c0d01e4
Added some new span icons
matt-aitken beca6ea
Reworked http callback to be a create call then just use wait.forToken()
matt-aitken 4e9c2ba
Added a changeset
matt-aitken b87d98f
Updated the docs
matt-aitken 2536c10
Updated the wait overview docs
matt-aitken d8c76ee
Simplify to just a call
matt-aitken 9d01c88
WIP stripping right back to waitpoints just having a URL associated w…
matt-aitken 93263d9
More deletions
matt-aitken f7af73f
Remove missing icon
matt-aitken 2710501
Updated the changeset
matt-aitken 4b24a47
Add URL to the token return types
matt-aitken 776b7ea
Remove wait for http callback page
matt-aitken 474a333
Updated docs
matt-aitken e2b39cb
More tidying
matt-aitken a725140
Type and import fix
matt-aitken 0a97f3a
Remove unused import
matt-aitken d4b7135
Some type fixes for the retrieve
matt-aitken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@trigger.dev/sdk": patch | ||
--- | ||
|
||
When you create a Waitpoint token using `wait.createToken()` you get a URL back that can be used to complete it by making an HTTP POST request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
apps/webapp/app/routes/api.v1.waitpoints.tokens.$waitpointFriendlyId.callback.$hash.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { type ActionFunctionArgs, json } from "@remix-run/server-runtime"; | ||
import { | ||
type CompleteWaitpointTokenResponseBody, | ||
conditionallyExportPacket, | ||
stringifyIO, | ||
} from "@trigger.dev/core/v3"; | ||
import { WaitpointId } from "@trigger.dev/core/v3/isomorphic"; | ||
import { z } from "zod"; | ||
import { $replica } from "~/db.server"; | ||
import { env } from "~/env.server"; | ||
import { verifyHttpCallbackHash } from "~/services/httpCallback.server"; | ||
import { logger } from "~/services/logger.server"; | ||
import { engine } from "~/v3/runEngine.server"; | ||
|
||
const paramsSchema = z.object({ | ||
waitpointFriendlyId: z.string(), | ||
hash: z.string(), | ||
}); | ||
|
||
export async function action({ request, params }: ActionFunctionArgs) { | ||
if (request.method.toUpperCase() !== "POST") { | ||
return json({ error: "Method not allowed" }, { status: 405, headers: { Allow: "POST" } }); | ||
} | ||
|
||
const contentLength = request.headers.get("content-length"); | ||
if (!contentLength) { | ||
return json({ error: "Content-Length header is required" }, { status: 411 }); | ||
} | ||
|
||
if (parseInt(contentLength) > env.TASK_PAYLOAD_MAXIMUM_SIZE) { | ||
return json({ error: "Request body too large" }, { status: 413 }); | ||
} | ||
|
||
const { waitpointFriendlyId, hash } = paramsSchema.parse(params); | ||
const waitpointId = WaitpointId.toId(waitpointFriendlyId); | ||
|
||
try { | ||
const waitpoint = await $replica.waitpoint.findFirst({ | ||
where: { | ||
id: waitpointId, | ||
}, | ||
include: { | ||
environment: { | ||
select: { | ||
apiKey: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!waitpoint) { | ||
return json({ error: "Waitpoint not found" }, { status: 404 }); | ||
} | ||
|
||
if (!verifyHttpCallbackHash(waitpoint.id, hash, waitpoint.environment.apiKey)) { | ||
return json({ error: "Invalid URL, hash doesn't match" }, { status: 401 }); | ||
} | ||
|
||
if (waitpoint.status === "COMPLETED") { | ||
return json<CompleteWaitpointTokenResponseBody>({ | ||
success: true, | ||
}); | ||
} | ||
|
||
// If the request body is not valid JSON, return an empty object | ||
const body = await request.json().catch(() => ({})); | ||
|
||
const stringifiedData = await stringifyIO(body); | ||
const finalData = await conditionallyExportPacket( | ||
stringifiedData, | ||
`${waitpointId}/waitpoint/http-callback` | ||
); | ||
|
||
const result = await engine.completeWaitpoint({ | ||
id: waitpointId, | ||
output: finalData.data | ||
? { type: finalData.dataType, value: finalData.data, isError: false } | ||
: undefined, | ||
}); | ||
|
||
return json<CompleteWaitpointTokenResponseBody>( | ||
{ | ||
success: true, | ||
}, | ||
{ status: 200 } | ||
); | ||
} catch (error) { | ||
logger.error("Failed to complete HTTP callback", { error }); | ||
throw json({ error: "Failed to complete HTTP callback" }, { status: 500 }); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.