d23fa38a0a
* Initial commit with a plan for what we’re going to do * Some initial types and improved plan * Add Waitpoint resolver * Add resolver + status index * Remove type + status index * Only drop if exists * Remove type index * Update waitpoint list presenter to use resolver * Added resolver to the engine * Made the existing waitpoint list presenter more flexible * Initial implentation ofr wait.forHttpCallback() * Added the callback endpoint (no API rate limit) * schema version * Added jsdocs, removed schema version because of errors * Show callback URL if it’s set * Dashboard pages and panels * Remove todos * Added temporary icon * Added a blank state * Some tweaks and added a Replicate example * Implement unwrap() for httpCallback * Added unwrap to wait.forToken() as well * Improved jsdocs * Added docs * Added unwrap to the token docs * Show a dash if there are no tags Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Make the timeout error safer * Fixed migrations… should use id desc not createdAt desc * Fixed page title * Fixed migration so it only adds them if they don’t exist. This allows us to manuall run in cloud first * Respect the max content length by getting the length of the body * Added more docs details about the callback format * Remove code comment * Improved the error * Added a hash to the HTTP callback URLs * Add the apiKey to the API input type to fix TS error * Return the error responses. They were being caught and not preserved * The content-length header is required. Deal with an empty body * Removed unused types * Added some new span icons * Reworked http callback to be a create call then just use wait.forToken() * Added a changeset * Updated the docs * Updated the wait overview docs * Simplify to just a call * WIP stripping right back to waitpoints just having a URL associated with them… * More deletions * Remove missing icon * Updated the changeset * Add URL to the token return types * Remove wait for http callback page * Updated docs * More tidying * Type and import fix * Remove unused import * Some type fixes for the retrieve --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
31 lines
961 B
TypeScript
31 lines
961 B
TypeScript
import { WaitpointId } from "@trigger.dev/core/v3/isomorphic";
|
|
import nodeCrypto from "node:crypto";
|
|
import { env } from "~/env.server";
|
|
|
|
export function generateHttpCallbackUrl(waitpointId: string, apiKey: string) {
|
|
const hash = generateHttpCallbackHash(waitpointId, apiKey);
|
|
|
|
return `${env.API_ORIGIN ?? env.APP_ORIGIN}/api/v1/waitpoints/tokens/${WaitpointId.toFriendlyId(
|
|
waitpointId
|
|
)}/callback/${hash}`;
|
|
}
|
|
|
|
function generateHttpCallbackHash(waitpointId: string, apiKey: string) {
|
|
const hmac = nodeCrypto.createHmac("sha256", apiKey);
|
|
hmac.update(waitpointId);
|
|
return hmac.digest("hex");
|
|
}
|
|
|
|
export function verifyHttpCallbackHash(waitpointId: string, hash: string, apiKey: string) {
|
|
const expectedHash = generateHttpCallbackHash(waitpointId, apiKey);
|
|
|
|
if (
|
|
hash.length === expectedHash.length &&
|
|
nodeCrypto.timingSafeEqual(Buffer.from(hash, "hex"), Buffer.from(expectedHash, "hex"))
|
|
) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|