@salesforce/core 3.12.2 → 3.13.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.13.0](https://github.com/forcedotcom/sfdx-core/compare/v3.12.2...v3.13.0) (2022-04-20)
6
+
7
+ ### Features
8
+
9
+ - detect if org is a devhub at auth time ([#560](https://github.com/forcedotcom/sfdx-core/issues/560)) ([958e2e7](https://github.com/forcedotcom/sfdx-core/commit/958e2e7317e670b738b3e7c82260ef741e1416d2))
10
+
5
11
  ### [3.12.2](https://github.com/forcedotcom/sfdx-core/compare/v3.12.1...v3.12.2) (2022-04-14)
6
12
 
7
13
  ### Bug Fixes
@@ -303,6 +303,12 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
303
303
  * @private
304
304
  */
305
305
  private throwUserGetException;
306
+ /**
307
+ * Returns `true` if the org is a Dev Hub.
308
+ *
309
+ * Check access to the ScratchOrgInfo object to determine if the org is a dev hub.
310
+ */
311
+ private determineIfDevHub;
306
312
  }
307
313
  export declare namespace AuthInfo {
308
314
  /**
@@ -614,6 +614,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
614
614
  }
615
615
  }
616
616
  }
617
+ authConfig.isDevHub = await this.determineIfDevHub((0, ts_types_1.ensureString)(authConfig.instanceUrl), (0, ts_types_1.ensureString)(authConfig.accessToken));
617
618
  // Update the auth fields WITH encryption
618
619
  this.update(authConfig);
619
620
  }
@@ -844,6 +845,32 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
844
845
  }
845
846
  throw new sfError_1.SfError(errorMsg);
846
847
  }
848
+ /**
849
+ * Returns `true` if the org is a Dev Hub.
850
+ *
851
+ * Check access to the ScratchOrgInfo object to determine if the org is a dev hub.
852
+ */
853
+ async determineIfDevHub(instanceUrl, accessToken) {
854
+ // Make a REST call for the ScratchOrgInfo obj directly. Normally this is done via a connection
855
+ // but we don't want to create circular dependencies or lots of snowflakes
856
+ // within this file to support it.
857
+ const apiVersion = 'v51.0'; // hardcoding to v51.0 just for this call is okay.
858
+ const instance = (0, ts_types_1.ensure)(instanceUrl);
859
+ const baseUrl = new sfdcUrl_1.SfdcUrl(instance);
860
+ const scratchOrgInfoUrl = `${baseUrl}/services/data/${apiVersion}/query?q=SELECT%20Id%20FROM%20ScratchOrgInfo%20limit%201`;
861
+ const headers = Object.assign({ Authorization: `Bearer ${accessToken}` }, connection_1.SFDX_HTTP_HEADERS);
862
+ try {
863
+ const res = await new transport_1.default().httpRequest({ url: scratchOrgInfoUrl, method: 'GET', headers });
864
+ if (res.statusCode >= 400) {
865
+ return false;
866
+ }
867
+ return true;
868
+ }
869
+ catch (err) {
870
+ /* Not a dev hub */
871
+ return false;
872
+ }
873
+ }
847
874
  }
848
875
  exports.AuthInfo = AuthInfo;
849
876
  //# sourceMappingURL=authInfo.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.12.2",
3
+ "version": "3.13.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",