UNPKG

@unito/integration-cli

Version:

Integration CLI

33 lines (32 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateAuthenticated = validateAuthenticated; const tslib_1 = require("tslib"); const IntegrationsPlatformClient = tslib_1.__importStar(require("../services/integrationsPlatform")); const errors_1 = require("../errors"); const GlobalConfiguration = tslib_1.__importStar(require("./globalConfiguration")); async function validateAuthenticated(globalConfiguration, environment) { let apiKey = undefined; if (environment === GlobalConfiguration.Environment.Local) { apiKey = globalConfiguration.apiKeyLocal; } else if (environment === GlobalConfiguration.Environment.Staging) { apiKey = globalConfiguration.apiKeyStaging; } else { apiKey = globalConfiguration.apiKey; } // The API key to talk to the platform is missing. Out! if (!apiKey) { throw new errors_1.MissingApiKey(); } // Setup the platform client. IntegrationsPlatformClient.setEnvironment(environment); IntegrationsPlatformClient.setApiKey(apiKey); try { await IntegrationsPlatformClient.getProfile(); } catch { throw new errors_1.AuthenticationFailed(); } }