UNPKG

@salesforce/source-deploy-retrieve

Version:

JavaScript library to run Salesforce metadata deploys and retrieves

76 lines 3.03 kB
"use strict"; /* * Copyright (c) 2020, salesforce.com, inc. * All rights reserved. * Licensed under the BSD 3-Clause license. * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ /* eslint-disable no-console */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCoverage = exports.getCurrentApiVersion = void 0; const got_1 = __importDefault(require("got")); const proxy_agent_1 = require("proxy-agent"); const ts_types_1 = require("@salesforce/ts-types"); const core_1 = require("@salesforce/core"); const getProxiedOptions = (url) => ({ timeout: { request: 10_000, }, agent: { https: new proxy_agent_1.ProxyAgent(), }, url, }); let apiVer; const getCurrentApiVersion = async () => { if (apiVer === undefined) { try { const apiVersionsUrl = 'https://appexchange.salesforce.com/services/data'; const lastVersionEntry = (await (0, got_1.default)(getProxiedOptions(apiVersionsUrl)).json()).at(-1); apiVer = +lastVersionEntry.version; } catch (e) { const err = e instanceof Error ? e : core_1.SfError.wrap((0, ts_types_1.isString)(e) ? e : 'unknown'); const eMsg = 'Unable to get a current API version from the appexchange org'; const eActions = ['Provide an API version explicitly', 'Set an API version in the project configuration']; throw new core_1.SfError(eMsg, 'ApiVersionRetrievalError', eActions, err); } } return apiVer; }; exports.getCurrentApiVersion = getCurrentApiVersion; const getCoverage = async (apiVersion) => { const versionSources = [ { cell: 'sdb3', test: 1 }, { cell: 'ora15', test: 1 }, { cell: 'sdb4s', test: 1 }, { cell: 'sdb6', test: 1 }, { cell: 'ora14', test: 1 }, { cell: 'sdb10s', test: 1 }, { cell: 'sdb27', test: 1 }, { cell: 'ora16', test: 2 }, { cell: 'sdb14', test: 2 }, { cell: 'sdb15', test: 2 }, { cell: 'sdb17s', test: 2 }, { cell: 'sdb18s', test: 2 }, ]; const urls = versionSources.map(({ cell, test }) => `https://${cell}.test${test}.pc-rnd.pc-aws.salesforce.com/mdcoverage/api.jsp`); const results = await Promise.allSettled(urls.map(getProxiedOptions).map(async (proxy) => (0, got_1.default)(proxy).json())); for (const result of results) { if (result.status === 'fulfilled' && result.value?.apiVersion === apiVersion) { return result.value; } } console.log(`WARNING: Could not find coverage for api version ${apiVersion}. Urls attempted:`); urls.forEach((url) => console.log(url)); return { apiVersion, release: '', types: {}, }; }; exports.getCoverage = getCoverage; //# sourceMappingURL=coverage.js.map