From 9eeacee7c246d8829797286c931e64322a90db76 Mon Sep 17 00:00:00 2001 From: Eric Allam Date: Tue, 21 Feb 2023 14:12:14 +0000 Subject: [PATCH] Fix: pass in the id from sendEvent through to the API call --- .changeset/smart-doors-admire.md | 5 +++++ packages/trigger-sdk/src/customEvents.ts | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 .changeset/smart-doors-admire.md diff --git a/.changeset/smart-doors-admire.md b/.changeset/smart-doors-admire.md new file mode 100644 index 000000000..f8588a76a --- /dev/null +++ b/.changeset/smart-doors-admire.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/sdk": patch +--- + +Fix: pass in the id from sendEvent through to the API call diff --git a/packages/trigger-sdk/src/customEvents.ts b/packages/trigger-sdk/src/customEvents.ts index a9220d375..d6648ce73 100644 --- a/packages/trigger-sdk/src/customEvents.ts +++ b/packages/trigger-sdk/src/customEvents.ts @@ -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 { 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 { +async function sendEventFetch( + id: string, + event: TriggerCustomEvent +): Promise { 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`;