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

Function whoamiCommand

packages/cli/src/commands/whoami.ts:16–65  ·  view source on GitHub ↗
(path: string, anyOptions: any)

Source from the content-addressed store, hash-verified

14export type WhoAmICommandOptions = z.infer<typeof WhoAmICommandOptionsSchema>;
15
16export async function whoamiCommand(path: string, anyOptions: any) {
17 const loadingSpinner = ora(`Hold while we fetch your data`);
18 loadingSpinner.start();
19
20 const result = WhoAmICommandOptionsSchema.safeParse(anyOptions);
21 if (!result.success) {
22 logger.error(result.error.message);
23 return;
24 }
25 const options = result.data;
26
27 const resolvedPath = resolvePath(path);
28
29 // Read from package.json to get the endpointId
30 const runtime = await getJsRuntime(resolvedPath, logger);
31 const endpointId = await getEndpointId(runtime);
32 if (!endpointId) {
33 logger.error(
34 "You must run the `init` command first to setup the project – you are missing \n'trigger.dev': { 'endpointId': 'your-client-id' } from your package.json file, or pass in the --client-id option to this command"
35 );
36 loadingSpinner.stop();
37 return;
38 }
39 // Read from .env.local or .env to get the TRIGGER_API_KEY and TRIGGER_API_URL
40 const apiDetails = await getTriggerApiDetails(resolvedPath, options.envFile);
41
42 if (!apiDetails) {
43 return;
44 }
45
46 const triggerAPI = new TriggerApi(apiDetails.apiKey, apiDetails.apiUrl);
47 const userData = await triggerAPI.whoami();
48
49 loadingSpinner.stop();
50
51 logger.info(`
52 environment: ${userData?.type}
53 Trigger Client Id: ${endpointId}
54 User ID: ${userData?.userId}
55 Project:
56 id: ${userData?.project.id}
57 slug: ${userData?.project.slug}
58 name: ${userData?.project.name}
59 Organization:
60 id: ${userData?.organization.id}
61 slug: ${userData?.organization.slug}
62 title: ${userData?.organization.title}
63 `);
64 process.exit(1);
65}

Callers 1

index.tsFile · 0.85

Calls 9

whoamiMethod · 0.95
resolvePathFunction · 0.90
getJsRuntimeFunction · 0.90
getEndpointIdFunction · 0.90
getTriggerApiDetailsFunction · 0.90
errorMethod · 0.65
infoMethod · 0.65
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…