11import * as jwtImpl from 'jsonwebtoken'
22import type { SignOptions } from 'jsonwebtoken'
33import { LRUCache } from 'lru-cache'
4- import { createLogger , Logger , createValidateStatusCode } from '../utils'
4+ import { createValidateStatusCode } from '../utils'
55import { FetchOptions , makeRequest , withDefaultOptions , withHook , withRetry } from '../utils/http'
66
77const jwt = 'default' in jwtImpl ? jwtImpl . default : jwtImpl
@@ -24,18 +24,19 @@ let defaultCache: LRUCache<string, string> | undefined
2424const generateOneTimeToken = (
2525 privateKey : string ,
2626 { appId, keyId } : { appId : string ; keyId ?: string } ,
27- { log } : { log : Logger } ,
27+ // { log }: { log: Logger },
2828) : string => {
29- log ( 'Signing a JWT token with private key' )
29+ // log('Signing a JWT token with private key')
30+ // eslint-disable-next-line no-useless-catch
3031 try {
3132 const baseSignOptions : SignOptions = { algorithm : 'RS256' , issuer : appId , expiresIn : '10m' }
3233 const signOptions : SignOptions = keyId ? { ...baseSignOptions , keyid : keyId } : baseSignOptions
3334
3435 const token = sign ( { } , privateKey , signOptions )
35- log ( 'Successfully signed token' )
36+ // log('Successfully signed token')
3637 return token
3738 } catch ( e ) {
38- log ( 'Unable to sign token' )
39+ // log('Unable to sign token')
3940 throw e
4041 }
4142}
@@ -47,11 +48,11 @@ const getTokenFromOneTimeToken = async (
4748 spaceId,
4849 environmentId,
4950 } : { appInstallationId : string ; spaceId : string ; environmentId : string } ,
50- { log, fetchOptions } : { log : Logger ; fetchOptions : FetchOptions } ,
51+ { /* log, */ fetchOptions } : { /* log: Logger; */ fetchOptions : FetchOptions } ,
5152) : Promise < string > => {
5253 const validateStatusCode = createValidateStatusCode ( [ 201 ] )
5354
54- log ( `Requesting CMA Token with given App Token` )
55+ // log(`Requesting CMA Token with given App Token`)
5556
5657 const requestor = makeRequest (
5758 `/spaces/${ spaceId } /environments/${ environmentId } /app_installations/${ appInstallationId } /access_tokens` ,
@@ -67,9 +68,9 @@ const getTokenFromOneTimeToken = async (
6768 const retryRequestor = withRetry ( hookRequestor , fetchOptions )
6869 const response = await retryRequestor ( )
6970
70- log (
71- `Successfully retrieved CMA Token for app ${ appInstallationId } in space ${ spaceId } and environment ${ environmentId } ` ,
72- )
71+ // log(
72+ // `Successfully retrieved CMA Token for app ${appInstallationId} in space ${spaceId} and environment ${environmentId}`,
73+ // )
7374
7475 return ( ( await response . json ( ) ) as { token : string } ) . token
7576}
@@ -79,7 +80,7 @@ const getTokenFromOneTimeToken = async (
7980 * @internal
8081 */
8182export const createGetManagementToken = (
82- log : Logger ,
83+ // log: Logger,
8384 fetchOptions : FetchOptions ,
8485 cache : LRUCache < string , string > ,
8586) => {
@@ -104,9 +105,9 @@ export const createGetManagementToken = (
104105 const appToken = generateOneTimeToken (
105106 privateKey ,
106107 { appId : opts . appInstallationId , keyId : opts . keyId } ,
107- { log } ,
108+ // { log },
108109 )
109- const ott = await getTokenFromOneTimeToken ( appToken , opts , { log, fetchOptions } )
110+ const ott = await getTokenFromOneTimeToken ( appToken , opts , { /* log, */ fetchOptions } )
110111 if ( opts . reuseToken ) {
111112 const decoded = decode ( ott )
112113 if ( decoded && typeof decoded === 'object' && decoded . exp ) {
@@ -151,7 +152,7 @@ export const getManagementToken = async (privateKey: string, opts: GetManagement
151152 const httpClientOpts = typeof opts . host !== 'undefined' ? { prefixUrl : opts . host } : { }
152153
153154 return createGetManagementToken (
154- createLogger ( { filename : __filename } ) ,
155+ // createLogger({ filename: __filename }),
155156 withDefaultOptions ( httpClientOpts ) ,
156157 defaultCache ! ,
157158 ) ( privateKey , opts )
0 commit comments