-
-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TRI-1006] New @trigger.dev/cli whoami command. (#316)
* FIx: [TRI-1006] New @trigger.dev/cli whoami command. * revert dev.ts zod schema to original * Removed telemetry * remove all telemetry * Made the clientId optional again --------- Co-authored-by: Matt Aitken <matt@mattaitken.com>
- Loading branch information
1 parent
e20fa3c
commit bbaa6ba
Showing
5 changed files
with
86 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"compilerOptions": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { z } from "zod"; | ||
import { logger } from "../utils/logger.js"; | ||
import { resolvePath } from "../utils/parseNameAndPath.js"; | ||
import { TriggerApi } from "../utils/triggerApi.js"; | ||
import { DevCommandOptions, getEndpointIdFromPackageJson, getTriggerApiDetails } from "./dev.js"; | ||
import ora from "ora"; | ||
|
||
export const WhoAmICommandOptionsSchema = z.object({ | ||
envFile: z.string() | ||
}); | ||
|
||
export type WhoAmICommandOptions = z.infer<typeof WhoAmICommandOptionsSchema>; | ||
|
||
export async function whoamiCommand(path: string, anyOptions: any) { | ||
const loadingSpinner = ora(`Hold while we fetch your data`); | ||
loadingSpinner.start(); | ||
|
||
const result = WhoAmICommandOptionsSchema.safeParse(anyOptions); | ||
if (!result.success) { | ||
logger.error(result.error.message); | ||
return; | ||
} | ||
const options = result.data; | ||
|
||
const resolvedPath = resolvePath(path); | ||
|
||
// Read from package.json to get the endpointId | ||
const endpointId = await getEndpointIdFromPackageJson(resolvedPath, options as DevCommandOptions); | ||
if (!endpointId) { | ||
logger.error( | ||
"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" | ||
); | ||
loadingSpinner.stop(); | ||
return; | ||
} | ||
// Read from .env.local or .env to get the TRIGGER_API_KEY and TRIGGER_API_URL | ||
const apiDetails = await getTriggerApiDetails(resolvedPath, options.envFile); | ||
|
||
if (!apiDetails) { | ||
return; | ||
} | ||
|
||
const triggerAPI = new TriggerApi(apiDetails.apiKey, apiDetails.apiUrl); | ||
const userData = await triggerAPI.whoami(apiDetails.apiKey); | ||
|
||
loadingSpinner.stop(); | ||
|
||
logger.info(` | ||
environment: ${userData?.type} | ||
Trigger Client Id: ${endpointId} | ||
User ID: ${userData?.userId} | ||
Project: | ||
id: ${userData?.project.id} | ||
slug: ${userData?.project.slug} | ||
name: ${userData?.project.name} | ||
Organization: | ||
id: ${userData?.organization.id} | ||
slug: ${userData?.organization.slug} | ||
title: ${userData?.organization.title} | ||
`); | ||
process.exit(1); | ||
} |