@salesforce/core 3.11.1 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [3.12.0](https://github.com/forcedotcom/sfdx-core/compare/v3.11.1...v3.12.0) (2022-04-04)
6
+
7
+ ### Features
8
+
9
+ - move common authinfo utils to core ([01b8cf3](https://github.com/forcedotcom/sfdx-core/commit/01b8cf3fa38162380da5ce15f6dee1d2a5d2d72d))
10
+
5
11
  ### [3.11.1](https://github.com/forcedotcom/sfdx-core/compare/v3.11.0...v3.11.1) (2022-04-01)
6
12
 
7
13
  ## [3.11.0](https://github.com/forcedotcom/sfdx-core/compare/v3.10.1...v3.11.0) (2022-03-30)
@@ -171,6 +171,19 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
171
171
  * @param sfdxAuthUrl
172
172
  */
173
173
  static parseSfdxAuthUrl(sfdxAuthUrl: string): Pick<AuthFields, 'clientId' | 'clientSecret' | 'refreshToken' | 'loginUrl'>;
174
+ /**
175
+ * Given a set of decrypted fields and an authInfo, determine if the org belongs to an available
176
+ * dev hub.
177
+ *
178
+ * @param fields
179
+ * @param orgAuthInfo
180
+ */
181
+ static identifyPossibleScratchOrgs(fields: AuthFields, orgAuthInfo: AuthInfo): Promise<void>;
182
+ /**
183
+ * Find all dev hubs available in the local environment.
184
+ */
185
+ static getDevHubAuthInfos(): Promise<OrgAuthorization[]>;
186
+ private static queryScratchOrg;
174
187
  /**
175
188
  * Get the username.
176
189
  */
@@ -26,6 +26,7 @@ const messages_1 = require("../messages");
26
26
  const sfdcUrl_1 = require("../util/sfdcUrl");
27
27
  const connection_1 = require("./connection");
28
28
  const orgConfigProperties_1 = require("./orgConfigProperties");
29
+ const org_1 = require("./org");
29
30
  messages_1.Messages.importMessagesDirectory(__dirname);
30
31
  const messages = messages_1.Messages.load('@salesforce/core', 'core', [
31
32
  'authInfoCreationError',
@@ -246,6 +247,61 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
246
247
  loginUrl: `https://${loginUrl}`,
247
248
  };
248
249
  }
250
+ /**
251
+ * Given a set of decrypted fields and an authInfo, determine if the org belongs to an available
252
+ * dev hub.
253
+ *
254
+ * @param fields
255
+ * @param orgAuthInfo
256
+ */
257
+ static async identifyPossibleScratchOrgs(fields, orgAuthInfo) {
258
+ // fields property is passed in because the consumers of this method have performed the decrypt.
259
+ // This is so we don't have to call authInfo.getFields(true) and decrypt again OR accidentally save an
260
+ // authInfo before it is necessary.
261
+ const logger = await logger_1.Logger.child('Common', { tag: 'identifyPossibleScratchOrgs' });
262
+ // return if we already know the hub org we know it is a devhub or prod-like or no orgId present
263
+ if (fields.isDevHub || fields.devHubUsername || !fields.orgId)
264
+ return;
265
+ logger.debug('getting devHubs');
266
+ // TODO: return if url is not sandbox-like to avoid constantly asking about production orgs
267
+ // TODO: someday we make this easier by asking the org if it is a scratch org
268
+ const hubAuthInfos = await AuthInfo.getDevHubAuthInfos();
269
+ logger.debug(`found ${hubAuthInfos.length} DevHubs`);
270
+ if (hubAuthInfos.length === 0)
271
+ return;
272
+ // ask all those orgs if they know this orgId
273
+ await Promise.all(hubAuthInfos.map(async (hubAuthInfo) => {
274
+ try {
275
+ const data = await AuthInfo.queryScratchOrg(hubAuthInfo.username, fields.orgId);
276
+ if (data.totalSize > 0) {
277
+ // if any return a result
278
+ logger.debug(`found orgId ${fields.orgId} in devhub ${hubAuthInfo.username}`);
279
+ try {
280
+ await orgAuthInfo.save({ ...fields, devHubUsername: hubAuthInfo.username });
281
+ logger.debug(`set ${hubAuthInfo.username} as devhub for scratch org ${orgAuthInfo.getUsername()}`);
282
+ }
283
+ catch (error) {
284
+ logger.debug(`error updating auth file for ${orgAuthInfo.getUsername()}`, error);
285
+ }
286
+ }
287
+ }
288
+ catch (error) {
289
+ logger.error(`Error connecting to devhub ${hubAuthInfo.username}`, error);
290
+ }
291
+ }));
292
+ }
293
+ /**
294
+ * Find all dev hubs available in the local environment.
295
+ */
296
+ static async getDevHubAuthInfos() {
297
+ return (await AuthInfo.listAllAuthorizations()).filter((possibleHub) => possibleHub === null || possibleHub === void 0 ? void 0 : possibleHub.isDevHub);
298
+ }
299
+ static async queryScratchOrg(devHubUsername, scratchOrgId) {
300
+ const devHubOrg = await org_1.Org.create({ aliasOrUsername: devHubUsername });
301
+ const conn = devHubOrg.getConnection();
302
+ const data = await conn.query(`select Id from ScratchOrgInfo where ScratchOrg = '${sfdc_1.sfdc.trimTo15(scratchOrgId)}'`);
303
+ return data;
304
+ }
249
305
  /**
250
306
  * Get the username.
251
307
  */
package/lib/testSetup.js CHANGED
@@ -480,8 +480,8 @@ class MockTestOrgData {
480
480
  this.userId = `user_id_${this.testId}`;
481
481
  this.orgId = `${this.testId}`;
482
482
  this.username = (options === null || options === void 0 ? void 0 : options.username) || `admin_${this.testId}@gb.org`;
483
- this.loginUrl = `http://login.${this.testId}.salesforce.com`;
484
- this.instanceUrl = `http://instance.${this.testId}.salesforce.com`;
483
+ this.loginUrl = `https://login.${this.testId}.salesforce.com`;
484
+ this.instanceUrl = `https://instance.${this.testId}.salesforce.com`;
485
485
  this.clientId = `${this.testId}/client_id`;
486
486
  this.clientSecret = `${this.testId}/client_secret`;
487
487
  this.authcode = `${this.testId}/authcode`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.11.1",
3
+ "version": "3.12.0",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",