Skip to content

fix: use appexchange org for last resort api version #1219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more meta--if this does fail (network issues, org down, etc) would the error be meaningful for users to know what's happening?

it's

Uncaught RequestError: getaddrinfo ENOTFOUND appexchange.salesforce.com

And I think it'd be nice to tell them why we were doing that and what they might do about it (ex: setting or passing in an api version). It's hard for SDR to know what they're doing to be more specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Internally, the error is never displayed to an end user because if it fails, the code in ComponentSet will just use api version 58.0.

Seems this method is exported though which means anyone could call it, and in that case this function has a misleading name and could cause other problems. I would argue this should not be exported.

};

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