MCPcopy
hub / github.com/triggerdotdev/trigger.dev / sendEventCommand

Function sendEventCommand

packages/cli/src/commands/sendEvent.ts:18–64  ·  view source on GitHub ↗
(path: string, anyOptions: any)

Source from the content-addressed store, hash-verified

16export type SendEventCommandOptions = z.infer<typeof SendEventCommandOptionsSchema>;
17
18export async function sendEventCommand(path: string, anyOptions: any) {
19 const result = SendEventCommandOptionsSchema.safeParse(anyOptions);
20
21 if (!result.success) {
22 logger.error(result.error.message);
23 return;
24 }
25
26 console.log("Sending event", { options: result.data });
27
28 const options = result.data;
29
30 const resolvedPath = resolvePath(path);
31
32 // Read from .env.local or .env to get the TRIGGER_API_KEY and TRIGGER_API_URL
33 const apiDetails = await getTriggerApiDetails(resolvedPath, options.envFile);
34
35 if (!apiDetails) {
36 return;
37 }
38
39 const { apiUrl, apiKey } = apiDetails;
40
41 const parsedPayload = safeJSONParse(options.payload);
42
43 if (typeof parsedPayload !== "object") {
44 logger.error(
45 `The payload must be a valid JSON object. You can also pipe the payload in via stdin.`
46 );
47 return;
48 }
49
50 const id = options.id ?? randomUUID();
51 const name = options.name;
52
53 const spinner = ora(`[trigger.dev] Sending event ${name} with id ${id}`).start();
54
55 const triggerApi = new TriggerApi(apiKey, apiUrl);
56
57 const ok = await triggerApi.sendEvent(id, name, parsedPayload);
58
59 if (ok) {
60 spinner.succeed(`[trigger.dev] Event ${name} with id ${id} sent`);
61 } else {
62 spinner.fail(`[trigger.dev] Event ${name} with id ${id} failed to send`);
63 }
64}
65
66function safeJSONParse(payload: string): any {
67 try {

Callers 1

index.tsFile · 0.90

Calls 7

sendEventMethod · 0.95
resolvePathFunction · 0.90
getTriggerApiDetailsFunction · 0.90
safeJSONParseFunction · 0.85
errorMethod · 0.65
logMethod · 0.65
startMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…