"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1260.0/src/cli/commands/apps/create-app.ts" (4 Dec 2023, 1461 Bytes) of package /linux/misc/snyk-cli-1.1260.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 import * as Debug from 'debug';
    2 import {
    3   EAppsURL,
    4   getAppsURL,
    5   handleCreateAppRes,
    6   handleRestError,
    7   ICreateAppRequest,
    8   ICreateAppResponse,
    9   SNYK_APP_DEBUG,
   10 } from '../../../lib/apps';
   11 import { makeRequestRest } from '../../../lib/request/promise';
   12 import { spinner } from '../../../lib/spinner';
   13 
   14 const debug = Debug(SNYK_APP_DEBUG);
   15 
   16 /**
   17  * Function to process the app creation request and
   18  * handle any errors that are request error and print
   19  * in a formatted string. It throws is error is unknown
   20  * or cannot be handled.
   21  * @param {ICreateAppRequest} data to create the app
   22  * @returns {String} response formatted string
   23  */
   24 export async function createApp(
   25   data: ICreateAppRequest,
   26 ): Promise<string | void> {
   27   debug('App data', data);
   28   const {
   29     orgId,
   30     snykAppName: name,
   31     snykAppRedirectUris: redirectUris,
   32     snykAppScopes: scopes,
   33     context,
   34   } = data;
   35   const payload = {
   36     method: 'POST',
   37     url: getAppsURL(EAppsURL.CREATE_APP, { orgId }),
   38     body: {
   39       name,
   40       redirect_uris: redirectUris,
   41       scopes,
   42       context,
   43     },
   44     qs: {
   45       version: '2022-03-11~experimental',
   46     },
   47     noCompression: true,
   48   };
   49 
   50   try {
   51     await spinner('Creating your Snyk App');
   52     const response = await makeRequestRest<ICreateAppResponse>(payload);
   53     debug(response);
   54     spinner.clearAll();
   55     return handleCreateAppRes(response);
   56   } catch (error) {
   57     spinner.clearAll();
   58     handleRestError(error);
   59   }
   60 }