Skip to content

Commit b315656

Browse files
committed
Enable deployments with the CLI using OATs
1 parent 7815a2f commit b315656

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

packages/cli-v3/src/commands/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
308308

309309
const deploymentResponse = await projectClient.client.initializeDeployment({
310310
contentHash: buildManifest.contentHash,
311-
userId: authorization.userId,
311+
userId: authorization.auth.tokenType === "personal" ? authorization.userId : undefined,
312312
gitMeta,
313313
type: features.run_engine_v2 ? "MANAGED" : "V1",
314314
runtime: buildManifest.runtime,

packages/cli-v3/src/commands/login.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ import { env, isCI } from "std-env";
3030
import { CLOUD_API_URL } from "../consts.js";
3131
import {
3232
isPersonalAccessToken,
33+
isOrganizationAccessToken,
34+
validateAccessToken,
3335
NotPersonalAccessTokenError,
36+
NotAccessTokenError,
3437
} from "../utilities/isPersonalAccessToken.js";
3538
import { links } from "@trigger.dev/core/v3";
3639

@@ -94,8 +97,12 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
9497
const accessTokenFromEnv = env.TRIGGER_ACCESS_TOKEN;
9598

9699
if (accessTokenFromEnv) {
97-
if (!isPersonalAccessToken(accessTokenFromEnv)) {
98-
throw new NotPersonalAccessTokenError(
100+
const validationResult = validateAccessToken(accessTokenFromEnv);
101+
102+
if (!validationResult.success) {
103+
// We deliberately don't surface the existence of organization access tokens to the user for now, as they're only used internally.
104+
// Once we expose them in the application, we should also communicate that option here.
105+
throw new NotAccessTokenError(
99106
"Your TRIGGER_ACCESS_TOKEN is not a Personal Access Token, they start with 'tr_pat_'. You can generate one here: https://cloud.trigger.dev/account/tokens"
100107
);
101108
}
@@ -119,6 +126,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
119126
dashboardUrl: userData.data.dashboardUrl,
120127
auth: {
121128
accessToken: auth.accessToken,
129+
tokenType: validationResult.type,
122130
apiUrl: auth.apiUrl,
123131
},
124132
};
@@ -188,6 +196,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
188196
auth: {
189197
accessToken: authConfig.accessToken,
190198
apiUrl: authConfig.apiUrl ?? opts.defaultApiUrl,
199+
tokenType: "personal" as const,
191200
},
192201
};
193202
}
@@ -209,6 +218,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
209218
auth: {
210219
accessToken: authConfig.accessToken,
211220
apiUrl: authConfig.apiUrl ?? opts.defaultApiUrl,
221+
tokenType: "personal" as const,
212222
},
213223
};
214224
}
@@ -270,7 +280,10 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
270280
getPersonalAccessTokenSpinner.stop(`Logged in with token ${indexResult.obfuscatedToken}`);
271281

272282
writeAuthConfigProfile(
273-
{ accessToken: indexResult.token, apiUrl: opts.defaultApiUrl },
283+
{
284+
accessToken: indexResult.token,
285+
apiUrl: opts.defaultApiUrl,
286+
},
274287
options?.profile
275288
);
276289

@@ -309,6 +322,7 @@ export async function login(options?: LoginOptions): Promise<LoginResult> {
309322
auth: {
310323
accessToken: indexResult.token,
311324
apiUrl: authConfig?.apiUrl ?? opts.defaultApiUrl,
325+
tokenType: "personal" as const,
312326
},
313327
};
314328
} catch (e) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const tokenPrefix = "tr_oat_";
2+
3+
export function isOrganizationAccessToken(token: string) {
4+
return token.startsWith(tokenPrefix);
5+
}
6+
7+
export class NotOrganizationAccessTokenError extends Error {
8+
constructor(message: string) {
9+
super(message);
10+
this.name = "NotOrganizationAccessTokenError";
11+
}
12+
}

packages/cli-v3/src/utilities/session.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type LoginResultOk = {
1313
auth: {
1414
apiUrl: string;
1515
accessToken: string;
16+
tokenType: "personal" | "organization";
1617
};
1718
};
1819

@@ -24,6 +25,7 @@ export type LoginResult =
2425
auth?: {
2526
apiUrl: string;
2627
accessToken: string;
28+
tokenType: "personal" | "organization";
2729
};
2830
};
2931

@@ -45,6 +47,7 @@ export async function isLoggedIn(profile: string = "default"): Promise<LoginResu
4547
auth: {
4648
apiUrl: config.apiUrl,
4749
accessToken: config.accessToken,
50+
tokenType: "personal",
4851
},
4952
};
5053
}
@@ -58,6 +61,7 @@ export async function isLoggedIn(profile: string = "default"): Promise<LoginResu
5861
auth: {
5962
apiUrl: config.apiUrl,
6063
accessToken: config.accessToken,
64+
tokenType: "personal",
6165
},
6266
};
6367
} catch (e) {

0 commit comments

Comments
 (0)