Fix: pass in the id from sendEvent through to the API call

This commit is contained in:
Eric Allam
2023-02-21 14:12:14 +00:00
parent 6ced99fb02
commit 9eeacee7c2
2 changed files with 12 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/sdk": patch
---
Fix: pass in the id from sendEvent through to the API call
+7 -7
View File
@@ -1,31 +1,31 @@
import { triggerRunLocalStorage } from "./localStorage";
import type { TriggerCustomEvent } from "./types";
import fetch from "node-fetch";
import { ulid } from "ulid";
export function sendEvent(
id: string,
idOrKey: string,
event: TriggerCustomEvent
): Promise<void> {
const triggerRun = triggerRunLocalStorage.getStore();
if (!triggerRun) {
// Do it through the API
return sendEventFetch(event);
return sendEventFetch(idOrKey, event);
}
return triggerRun.sendEvent(id, event);
return triggerRun.sendEvent(idOrKey, event);
}
async function sendEventFetch(event: TriggerCustomEvent): Promise<void> {
async function sendEventFetch(
id: string,
event: TriggerCustomEvent
): Promise<void> {
if (!process.env.TRIGGER_API_KEY) {
throw new Error(
`There was a problem sending a custom event: the TRIGGER_API_KEY environment variable is not set`
);
}
const id = ulid();
const baseUrl = process.env.TRIGGER_API_URL || "https://app.trigger.dev";
const url = `${baseUrl}/api/v1/events`;