Edits history of script submission #9900 for ' Get an IFS OData projection (ifs)'

  • deno
    import { OAuth2Client, OAuth2Fetch } from 'npm:@badgateway/oauth2-client';
    import * as wmill from 'npm:[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 hugo697 399 days ago

  • deno
    import { OAuth2Client, OAuth2Fetch } from 'npm:@badgateway/oauth2-client';
    import * as wmill from 'npm:[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 chris edgington162 564 days ago