(path: string, anyOptions: any)
| 14 | export type WhoAmICommandOptions = z.infer<typeof WhoAmICommandOptionsSchema>; |
| 15 | |
| 16 | export 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 | } |
no test coverage detected
searching dependent graphs…