Fix: pass in the id from sendEvent through to the API call
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/sdk": patch
|
||||
---
|
||||
|
||||
Fix: pass in the id from sendEvent through to the API call
|
||||
@@ -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`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user