UNPKG

@platformic/argocd-client

Version:
35 lines (34 loc) 1.87 kB
'use strict' var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value) }) } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)) } catch (e) { reject(e) } } function rejected(value) { try { step(generator['throw'](value)) } catch (e) { reject(e) } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected) } step((generator = generator.apply(thisArg, _arguments || [])).next()) }) } var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { 'default': mod } } Object.defineProperty(exports, '__esModule', { value: true }) exports.client = void 0 const process_1 = __importDefault(require('process')) const { ARGOCD_API_URL, ARGOCD_API_TOKEN } = process_1.default.env const client = (_a) => __awaiter(void 0, [_a], void 0, function* ({ url, method, params, headers, data }) { var _b if (typeof ARGOCD_API_TOKEN === 'undefined' || typeof ARGOCD_API_URL === 'undefined') throw new Error('Error: ENV variables are missing.') const response = yield fetch(`${ARGOCD_API_URL !== null && ARGOCD_API_URL !== void 0 ? ARGOCD_API_URL : ''}${url}` + new URLSearchParams(params), Object.assign({ method, headers: Object.assign({ 'Authorization': (_b = `Bearer ${ARGOCD_API_TOKEN}`) !== null && _b !== void 0 ? _b : '' }, headers) }, (data ? { body: JSON.stringify(data) } : {}))) // Handle response errors switch (response.status) { case 404: throw Error('Error: not found.') case 500: throw Error('Error: server error.') } return response.json() }) exports.client = client exports.default = exports.client