Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set dummy value for event key for local development #361

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/inngest/src/components/Inngest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
defaultDevServerHost,
defaultInngestBaseUrl,
defaultInngestEventBaseUrl,
dummyEventKey,
envKeys,
logPrefix,
} from "../helpers/consts";
Expand Down Expand Up @@ -165,7 +166,7 @@ export class Inngest<TOpts extends ClientOptions = ClientOptions> {

this.setEventKey(eventKey || processEnv(envKeys.InngestEventKey) || "");

if (!this.eventKey) {
if (!this.eventKeySet()) {
console.warn(
prettyError({
type: "warn",
Expand Down Expand Up @@ -289,14 +290,18 @@ export class Inngest<TOpts extends ClientOptions = ClientOptions> {
*/
eventKey: string
): void {
this.eventKey = eventKey;
this.eventKey = eventKey || dummyEventKey;

this.sendEventUrl = new URL(
`e/${this.eventKey}`,
this.baseUrl || defaultInngestEventBaseUrl
);
}

private eventKeySet(): boolean {
return Boolean(this.eventKey) && this.eventKey !== dummyEventKey;
}

/**
* Send one or many events to Inngest. Takes an entire payload (including
* name) as each input.
Expand Down Expand Up @@ -418,7 +423,7 @@ export class Inngest<TOpts extends ClientOptions = ClientOptions> {
url = devServerUrl(defaultDevServerHost, `e/${this.eventKey}`).href;
}
}
} else if (!this.eventKey) {
} else if (!this.eventKeySet()) {
throw new Error(
prettyError({
whatHappened: "Failed to send event",
Expand Down
2 changes: 2 additions & 0 deletions packages/inngest/src/helpers/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ export enum internalEvents {
export const logPrefix = chalk.magenta.bold("[Inngest]");

export const debugPrefix = "inngest";

export const dummyEventKey = "NO_EVENT_KEY_SET";