import { OAuth2Client, OAuth2Fetch } from '@badgateway/oauth2-client';
import * as wmill from '[email protected]';
type CIfsDeployment = {
server: string;
clientId: string;
oidcPath: string;
clientSecret: string;
};
async function getConfiguration(deployment: string): Promise<CIfsDeployment> {
const configuration = await wmill.getResource(`f/settings/ifs-${deployment}`);
return configuration;
}
export async function main(deployment: string, projection: string, isEntity: boolean) {
const config = await getConfiguration(deployment);
const client = new OAuth2Client({
server: config.server,
discoveryEndpoint: config.oidcPath,
clientId: config.clientId,
clientSecret: config.clientSecret,
authenticationMethod: 'client_secret_post',
});
const fetcher = new OAuth2Fetch({
client,
getNewToken: async () => {
return client.clientCredentials();
},
onError: (error) => {
console.error('error: ', error);
},
});
try {
const url = `${config.server}/main/ifsapplications/projection/v1/${projection}`;
const response = await fetcher.fetch(url);
const data = await response.json();
return data;
} catch (error) {
console.error('error: ', error);
return { error: error };
}
}Submitted by hugo989 6 days ago