@@ -9,7 +9,6 @@ const __dirname = path.dirname(__filename);
99const wait = ( milliseconds ) => {
1010 return new Promise ( resolve => setTimeout ( resolve , milliseconds ) ) ;
1111} ;
12- const fetchDynamic = async ( ) => ( await import ( "node-fetch" ) ) . default ;
1312const TOKEN_FILE = path . resolve ( __dirname , "token.json" ) ;
1413export const authState = {
1514 deviceCode : "" ,
@@ -21,7 +20,7 @@ export async function authenticate() {
2120 log ( "info" , "Starting authentication process..." ) ;
2221 const authUrl = "https://cloud.mongodb.com/api/private/unauth/account/device/authorize" ;
2322 log ( "info" , `Client ID: ${ authState . clientId } ` ) ;
24- const deviceCodeResponse = await ( await fetchDynamic ( ) ) ( authUrl , {
23+ const deviceCodeResponse = await fetch ( authUrl , {
2524 method : "POST" ,
2625 headers : {
2726 "Content-Type" : "application/x-www-form-urlencoded" ,
@@ -59,7 +58,7 @@ export async function pollToken() {
5958 const expiresAt = Date . now ( ) + 2 * 60 * 1000 ;
6059 while ( Date . now ( ) < expiresAt ) {
6160 await wait ( interval ) ;
62- const OAuthToken = await ( await fetchDynamic ( ) ) ( tokenEndpoint , {
61+ const OAuthToken = await fetch ( tokenEndpoint , {
6362 method : "POST" ,
6463 headers : {
6564 "Content-Type" : "application/x-www-form-urlencoded" ,
@@ -191,7 +190,7 @@ function validateToken(tokenData) {
191190}
192191async function refreshToken ( token ) {
193192 try {
194- const response = await ( await fetchDynamic ( ) ) ( "https://cloud.mongodb.com/api/private/unauth/account/device/token" , {
193+ const response = await fetch ( "https://cloud.mongodb.com/api/private/unauth/account/device/token" , {
195194 method : "POST" ,
196195 headers : {
197196 "Content-Type" : "application/x-www-form-urlencoded" ,
@@ -217,7 +216,7 @@ async function refreshToken(token) {
217216}
218217async function revokeToken ( token ) {
219218 try {
220- const response = await ( await fetchDynamic ( ) ) ( "https://cloud.mongodb.com/api/private/unauth/account/device/revoke" , {
219+ const response = await fetch ( "https://cloud.mongodb.com/api/private/unauth/account/device/revoke" , {
221220 method : "POST" ,
222221 headers : {
223222 "Content-Type" : "application/x-www-form-urlencoded" ,
0 commit comments