Skip to content

Commit

Permalink
fix: use appexchange org for last resort api version (#1219)
Browse files Browse the repository at this point in the history
* fix: use org62 for last resort api version call

* fix: use appexchange since it is updated with R2

* fix: handle and throw a better error for getCurrentApiVersion
  • Loading branch information
shetzel authored Jan 23, 2024
1 parent a58a848 commit c9f15b2
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/registry/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import { OptionsOfTextResponseBody } from 'got';
import got from 'got';
import { ProxyAgent } from 'proxy-agent';
import { isString } from '@salesforce/ts-types';
import { SfError } from '@salesforce/core';
import { CoverageObject } from '../../src/registry/types';

const getProxiedOptions = (url: string): OptionsOfTextResponseBody => ({
Expand All @@ -27,10 +29,22 @@ type ApiVersion = {
version: string;
};

let apiVer: number;

export const getCurrentApiVersion = async (): Promise<number> => {
const apiVersionsUrl = 'https://dx-extended-coverage.my.salesforce-sites.com/services/data';
const lastVersionEntry = (await got(getProxiedOptions(apiVersionsUrl)).json<ApiVersion[]>()).pop() as ApiVersion;
return +lastVersionEntry.version;
if (apiVer === undefined) {
try {
const apiVersionsUrl = 'https://appexchange.salesforce.com/services/data';
const lastVersionEntry = (await got(getProxiedOptions(apiVersionsUrl)).json<ApiVersion[]>()).at(-1) as ApiVersion;
apiVer = +lastVersionEntry.version;
} catch (e: unknown) {
const err = e instanceof Error ? e : SfError.wrap(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 SfError(eMsg, 'ApiVersionRetrievalError', eActions, err);
}
}
return apiVer;
};

export const getCoverage = async (apiVersion: number): Promise<CoverageObject> => {
Expand Down

0 comments on commit c9f15b2

Please sign in to comment.