Added a more helpful message when adding an API key
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@trigger.dev/sdk": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Added a more helpful error message when missing an API key
|
||||||
@@ -37,8 +37,10 @@
|
|||||||
"build:tsup": "tsup --dts-resolve"
|
"build:tsup": "tsup --dts-resolve"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"chalk": "^5.2.0",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"evt": "^2.4.13",
|
"evt": "^2.4.13",
|
||||||
|
"get-caller-file": "^2.0.5",
|
||||||
"node-fetch": "2.6.x",
|
"node-fetch": "2.6.x",
|
||||||
"slug": "^6.0.0",
|
"slug": "^6.0.0",
|
||||||
"terminal-link": "^3.0.0",
|
"terminal-link": "^3.0.0",
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
import { TriggerClient } from "../client";
|
import { TriggerClient } from "../client";
|
||||||
import { LogLevel } from "internal-bridge";
|
import { LogLevel } from "internal-bridge";
|
||||||
import { TriggerEvent } from "../events";
|
import { TriggerEvent } from "../events";
|
||||||
|
import chalk from "chalk";
|
||||||
|
|
||||||
import type { TriggerContext } from "../types";
|
import type { TriggerContext } from "../types";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import terminalLink from "terminal-link";
|
||||||
|
|
||||||
export type TriggerOptions<TSchema extends z.ZodTypeAny> = {
|
export type TriggerOptions<TSchema extends z.ZodTypeAny> = {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -31,6 +33,23 @@ export class Trigger<TSchema extends z.ZodTypeAny> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async listen() {
|
async listen() {
|
||||||
|
if (this.#isMissingApiKey) {
|
||||||
|
console.log(
|
||||||
|
`${chalk.red("Trigger.dev error")}: ${chalk.bold(
|
||||||
|
this.id
|
||||||
|
)} is missing an API key, please set the TRIGGER_API_KEY environment variable or pass the apiKey option to the Trigger constructor. ${terminalLink(
|
||||||
|
"Get your API key here",
|
||||||
|
"https://app.trigger.dev",
|
||||||
|
{
|
||||||
|
fallback(text, url) {
|
||||||
|
return `${text} 👉 ${url}`;
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.#client) {
|
if (!this.#client) {
|
||||||
this.#client = new TriggerClient(this, this.options);
|
this.#client = new TriggerClient(this, this.options);
|
||||||
}
|
}
|
||||||
@@ -53,4 +72,8 @@ export class Trigger<TSchema extends z.ZodTypeAny> {
|
|||||||
get on() {
|
get on() {
|
||||||
return this.options.on;
|
return this.options.on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get #isMissingApiKey() {
|
||||||
|
return !this.options.apiKey && !process.env.TRIGGER_API_KEY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+4
@@ -1187,8 +1187,10 @@ importers:
|
|||||||
'@types/slug': ^5.0.3
|
'@types/slug': ^5.0.3
|
||||||
'@types/uuid': ^9.0.0
|
'@types/uuid': ^9.0.0
|
||||||
'@types/ws': ^8.5.3
|
'@types/ws': ^8.5.3
|
||||||
|
chalk: ^5.2.0
|
||||||
debug: ^4.3.4
|
debug: ^4.3.4
|
||||||
evt: ^2.4.13
|
evt: ^2.4.13
|
||||||
|
get-caller-file: ^2.0.5
|
||||||
internal-bridge: workspace:*
|
internal-bridge: workspace:*
|
||||||
node-fetch: 2.6.x
|
node-fetch: 2.6.x
|
||||||
rimraf: ^3.0.2
|
rimraf: ^3.0.2
|
||||||
@@ -1203,8 +1205,10 @@ importers:
|
|||||||
zod-error: ^1.1.0
|
zod-error: ^1.1.0
|
||||||
zod-to-json-schema: ^3.20.2
|
zod-to-json-schema: ^3.20.2
|
||||||
dependencies:
|
dependencies:
|
||||||
|
chalk: 5.2.0
|
||||||
debug: 4.3.4
|
debug: 4.3.4
|
||||||
evt: 2.4.13
|
evt: 2.4.13
|
||||||
|
get-caller-file: 2.0.5
|
||||||
node-fetch: 2.6.7
|
node-fetch: 2.6.7
|
||||||
slug: 6.1.0
|
slug: 6.1.0
|
||||||
terminal-link: 3.0.0
|
terminal-link: 3.0.0
|
||||||
|
|||||||
Reference in New Issue
Block a user