Added better Next Steps in the init cli command
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@trigger.dev/cli": patch
|
||||
---
|
||||
|
||||
Added better Next Steps in the init cli command
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { LoaderArgs } from "@remix-run/server-runtime";
|
||||
import { json } from "@remix-run/server-runtime";
|
||||
import { authenticateApiRequest } from "~/services/apiAuth.server";
|
||||
|
||||
export async function loader({ request }: LoaderArgs) {
|
||||
// Next authenticate the request
|
||||
const authenticatedEnv = await authenticateApiRequest(request);
|
||||
|
||||
if (!authenticatedEnv) {
|
||||
return json({ error: "Invalid or Missing API key" }, { status: 401 });
|
||||
}
|
||||
|
||||
return json(authenticatedEnv);
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import { resolvePath } from "../utils/parseNameAndPath.js";
|
||||
import { renderApiKey } from "../utils/renderApiKey.js";
|
||||
import { renderTitle } from "../utils/renderTitle.js";
|
||||
import { detectNextJsProject } from "../utils/detectNextJsProject.js";
|
||||
import { TriggerApi, WhoamiResponse } from "../utils/triggerApi.js";
|
||||
|
||||
export type InitCommandOptions = {
|
||||
projectPath: string;
|
||||
@@ -83,6 +84,17 @@ export const initCommand = async (options: InitCommandOptions) => {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const apiClient = new TriggerApi(apiKey, resolvedOptions.triggerUrl);
|
||||
const authorizedKey = await apiClient.whoami(apiKey);
|
||||
|
||||
if (!authorizedKey) {
|
||||
logger.error(
|
||||
`🛑 The API key you provided is not authorized. Try visiting your dashboard at ${resolvedOptions.triggerUrl} to get a new API key.`
|
||||
);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await addDependencies(resolvedPath, [
|
||||
{ name: "@trigger.dev/sdk", tag: "next" },
|
||||
{ name: "@trigger.dev/nextjs", tag: "latest" },
|
||||
@@ -111,16 +123,28 @@ export const initCommand = async (options: InitCommandOptions) => {
|
||||
|
||||
await addConfigurationToPackageJson(resolvedPath, resolvedOptions);
|
||||
|
||||
await printNextSteps(resolvedOptions);
|
||||
await printNextSteps(resolvedOptions, authorizedKey);
|
||||
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
async function printNextSteps(options: ResolvedOptions) {
|
||||
async function printNextSteps(
|
||||
options: ResolvedOptions,
|
||||
authorizedKey: WhoamiResponse
|
||||
) {
|
||||
const projectUrl = `${options.triggerUrl}/orgs/${authorizedKey.organization.slug}/projects/${authorizedKey.project.slug}`;
|
||||
|
||||
logger.success(`✅ Successfully initialized Trigger.dev!`);
|
||||
|
||||
logger.info("Next steps:");
|
||||
logger.info(` 1. Run your Next.js project locally with 'npm run dev'`);
|
||||
logger.info(
|
||||
`🔗 You can now connect to ${options.triggerUrl} and run jobs locally using the '@trigger.dev/cli dev' command`
|
||||
` 2. Run 'npx @trigger.dev/cli dev' to watch for changes and automatically register Trigger.dev jobs`
|
||||
);
|
||||
logger.info(` 3. View your jobs at ${projectUrl}`);
|
||||
|
||||
logger.info(
|
||||
`🔗 Head over to our docs at https://trigger.dev/docs to learn more about how to create different kinds of jobs and add integrations.`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,55 @@ export type EndpointResponse =
|
||||
}
|
||||
| { ok: false; error: string };
|
||||
|
||||
const WhoamiResponseSchema = z.object({
|
||||
id: z.string(),
|
||||
slug: z.string(),
|
||||
type: z.string(),
|
||||
createdAt: z.coerce.date(),
|
||||
updatedAt: z.coerce.date(),
|
||||
project: z.object({
|
||||
id: z.string(),
|
||||
slug: z.string(),
|
||||
name: z.string(),
|
||||
createdAt: z.coerce.date(),
|
||||
updatedAt: z.coerce.date(),
|
||||
}),
|
||||
organization: z.object({
|
||||
id: z.string(),
|
||||
slug: z.string(),
|
||||
title: z.string(),
|
||||
createdAt: z.coerce.date(),
|
||||
updatedAt: z.coerce.date(),
|
||||
}),
|
||||
});
|
||||
|
||||
export type WhoamiResponse = z.infer<typeof WhoamiResponseSchema>;
|
||||
|
||||
export class TriggerApi {
|
||||
constructor(private apiKey: string, private baseUrl: string) {}
|
||||
|
||||
async whoami(apiKey: string): Promise<WhoamiResponse | undefined> {
|
||||
const response = await fetch(`${this.baseUrl}/api/v1/whoami`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const body = await response.json();
|
||||
|
||||
const parsed = WhoamiResponseSchema.safeParse(body);
|
||||
|
||||
if (parsed.success) {
|
||||
return parsed.data;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
async registerEndpoint(
|
||||
options: CreateEndpointOptions
|
||||
): Promise<EndpointResponse> {
|
||||
|
||||
Generated
+6
-6
@@ -476,8 +476,8 @@ importers:
|
||||
typescript: 5.1.6
|
||||
dependencies:
|
||||
'@clerk/nextjs': 4.21.12_5v7kwk6wz2hvmegftnptprfjvm
|
||||
'@trigger.dev/nextjs': 1.0.0-next.5_2p6duyjdlqfptvv2ohfljlwidy
|
||||
'@trigger.dev/sdk': 2.0.0-next.4
|
||||
'@trigger.dev/nextjs': 1.0.0-next.5_yuyr3hquo7tgjdmhxnzkuafg3m
|
||||
'@trigger.dev/sdk': 2.0.0-next.5
|
||||
'@types/node': 20.3.2
|
||||
'@types/react': 18.0.26
|
||||
'@types/react-dom': 18.0.10
|
||||
@@ -10694,22 +10694,22 @@ packages:
|
||||
react-dom: 18.2.0_react@18.2.0
|
||||
dev: false
|
||||
|
||||
/@trigger.dev/nextjs/1.0.0-next.5_2p6duyjdlqfptvv2ohfljlwidy:
|
||||
/@trigger.dev/nextjs/1.0.0-next.5_yuyr3hquo7tgjdmhxnzkuafg3m:
|
||||
resolution: {integrity: sha512-41/RvyfuR3cPDCKAAhWOJMNw3KgA9uho7vcg8Q0ri8NCObsvxbStpnb5lpvNsUVOTyB7qy3tHULVJhKANczQqQ==}
|
||||
engines: {node: '>=18'}
|
||||
peerDependencies:
|
||||
'@trigger.dev/sdk': ^2.0.0-next.2
|
||||
next: ^13.3.1
|
||||
dependencies:
|
||||
'@trigger.dev/sdk': 2.0.0-next.4
|
||||
'@trigger.dev/sdk': 2.0.0-next.5
|
||||
debug: 4.3.4
|
||||
next: 13.4.7_biqbaboplfbrettd7655fr4n2y
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/@trigger.dev/sdk/2.0.0-next.4:
|
||||
resolution: {integrity: sha512-9N2YcM/Tt3Gu4Btf1EiHmRlsTuLyR9M+XLpbzOgli3MbhfHF0d39isE5M4Jz9qY+dQYeh5Rlyx+MEHTJxwvOdw==}
|
||||
/@trigger.dev/sdk/2.0.0-next.5:
|
||||
resolution: {integrity: sha512-ERnhWSiWSO1sOkKVZfFP+bmbDOtgyviahY7tVP/8LD0cJb/uz5zSufcqHRHhVCXU423u24tJcYYJcXKNyoSmHQ==}
|
||||
engines: {node: '>=18'}
|
||||
dependencies:
|
||||
chalk: 5.2.0
|
||||
|
||||
Reference in New Issue
Block a user