@@ -7,13 +7,13 @@ import { Org, Project } from "../util/types.js";
77import { getSlugFromName } from "./index.js" ;
88import chalk from "chalk" ;
99
10- export async function sendGraphQLReqToHypermode ( jwt : string , query : string ) : Promise < any > {
11- const url = "https ://api.hypermode.com /graphql" ;
10+ export async function sendGraphQLReqToHypermode ( apiKey : string , query : string ) : Promise < any > {
11+ const url = "http ://localhost:9081 /graphql" ;
1212
1313 const options = {
1414 body : JSON . stringify ( { query } ) ,
1515 headers : {
16- Authorization : ` ${ jwt } ` ,
16+ "X-API-Key" : apiKey ,
1717 "Content-Type" : "application/json" ,
1818 } ,
1919 method : "POST" ,
@@ -25,7 +25,7 @@ export async function sendGraphQLReqToHypermode(jwt: string, query: string): Pro
2525 if ( ! response . ok ) {
2626 if ( response . status === 401 ) {
2727 console . error ( `Unauthorized. Please try ${ chalk . blueBright ( "hyp login" ) } again.` ) ;
28- throw new Error ( "Unauthorized: Invalid or expired JWT token ." ) ;
28+ throw new Error ( "Unauthorized: Invalid or expired API key ." ) ;
2929 } else {
3030 throw new Error ( `HTTP Error: ${ response . status } ${ response . statusText } ` ) ;
3131 }
@@ -38,7 +38,7 @@ export async function sendGraphQLReqToHypermode(jwt: string, query: string): Pro
3838 }
3939}
4040
41- export async function sendMapRepoAndFinishProjectCreationReq ( jwt : string , id : string , repoId : string , repoName : string ) : Promise < Project > {
41+ export async function sendMapRepoAndFinishProjectCreationReq ( apiKey : string , id : string , repoId : string , repoName : string ) : Promise < Project > {
4242 const query = `
4343 mutation MapRepoAndFinishProjectCreation {
4444 mapRepoAndFinishProjectCreation(input: {id: "${ id } ", repoName: "${ repoName } ", repoId: "${ repoId } ", sourceType: CUSTOM, defaultBranchName: "main"}) {
@@ -48,14 +48,14 @@ export async function sendMapRepoAndFinishProjectCreationReq(jwt: string, id: st
4848 }
4949 }` ;
5050
51- const data : any = await sendGraphQLReqToHypermode ( jwt , query ) ;
51+ const data : any = await sendGraphQLReqToHypermode ( apiKey , query ) ;
5252
5353 const project : Project = data . data . mapRepoAndFinishProjectCreation ;
5454
5555 return project ;
5656}
5757
58- export async function sendCreateProjectReq ( jwt : string , orgId : string , projectName : string , repoId : string , repoName : string ) : Promise < Project > {
58+ export async function sendCreateProjectReq ( apiKey : string , orgId : string , projectName : string , repoId : string , repoName : string ) : Promise < Project > {
5959 const slug = getSlugFromName ( projectName ) ;
6060 const query = `
6161 mutation CreateProjectBranchRuntime {
@@ -67,14 +67,14 @@ export async function sendCreateProjectReq(jwt: string, orgId: string, projectNa
6767 }
6868 }` ;
6969
70- const res : any = await sendGraphQLReqToHypermode ( jwt , query ) ;
70+ const res : any = await sendGraphQLReqToHypermode ( apiKey , query ) ;
7171
7272 const project : Project = res . data . createProjectBranchRuntime ;
7373
7474 return project ;
7575}
7676
77- export async function sendGetOrgsReq ( jwt : string ) : Promise < Org [ ] > {
77+ export async function sendGetOrgsReq ( apiKey : string ) : Promise < Org [ ] > {
7878 const query = `
7979 query GetOrgs {
8080 getOrgs {
@@ -83,14 +83,14 @@ export async function sendGetOrgsReq(jwt: string): Promise<Org[]> {
8383 }
8484 }` ;
8585
86- const data : any = await sendGraphQLReqToHypermode ( jwt , query ) ;
86+ const data : any = await sendGraphQLReqToHypermode ( apiKey , query ) ;
8787
8888 const orgs : Org [ ] = data . data . getOrgs ;
8989
9090 return orgs ;
9191}
9292
93- export async function getProjectsByOrgReq ( jwt : string , orgId : string ) : Promise < Project [ ] > {
93+ export async function getProjectsByOrgReq ( apiKey : string , orgId : string ) : Promise < Project [ ] > {
9494 const query = `
9595 query GetProjectsByOrg {
9696 getOrg(id: "${ orgId } ") {
@@ -103,20 +103,20 @@ export async function getProjectsByOrgReq(jwt: string, orgId: string): Promise<P
103103 }
104104 }` ;
105105
106- const data : any = await sendGraphQLReqToHypermode ( jwt , query ) ;
106+ const data : any = await sendGraphQLReqToHypermode ( apiKey , query ) ;
107107
108108 const projects : Project [ ] = data . data . getOrg . projects ;
109109
110110 return projects ;
111111}
112112
113- export async function sendGetRepoIdReq ( jwt : string , installationId : string , gitUrl : string ) : Promise < string > {
113+ export async function sendGetRepoIdReq ( apiKey : string , installationId : string , gitUrl : string ) : Promise < string > {
114114 const query = `
115115 query getUserRepoIdByUrl {
116116 getUserRepoIdByUrl(installationId: "${ installationId } ", gitUrl: "${ gitUrl } ")
117117 }` ;
118118
119- const res : any = await sendGraphQLReqToHypermode ( jwt , query ) ;
119+ const res : any = await sendGraphQLReqToHypermode ( apiKey , query ) ;
120120
121121 if ( ! res . data . getUserRepoIdByUrl ) {
122122 throw new Error ( "No repoId found for the given installationId and gitUrl" ) ;
0 commit comments