@salesforce/core 3.12.0 → 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,24 @@
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
+
11
+ ### [3.12.2](https://github.com/forcedotcom/sfdx-core/compare/v3.12.1...v3.12.2) (2022-04-14)
12
+
13
+ ### Bug Fixes
14
+
15
+ - sandbox cname recognition ([#556](https://github.com/forcedotcom/sfdx-core/issues/556)) ([2f85709](https://github.com/forcedotcom/sfdx-core/commit/2f8570912cae38fb0ddeaa37836395444c47611a))
16
+
17
+ ### [3.12.1](https://github.com/forcedotcom/sfdx-core/compare/v3.12.0...v3.12.1) (2022-04-05)
18
+
19
+ ### Bug Fixes
20
+
21
+ - more FormData with buffers and headers ([5ebf78f](https://github.com/forcedotcom/sfdx-core/commit/5ebf78fe2b037df395c87197b90ee06a0d34d5d0))
22
+
5
23
  ## [3.12.0](https://github.com/forcedotcom/sfdx-core/compare/v3.11.1...v3.12.0) (2022-04-04)
6
24
 
7
25
  ### Features
@@ -1,6 +1,6 @@
1
1
  import { AsyncCreatable } from '@salesforce/kit';
2
2
  import { OAuth2Config } from 'jsforce/lib/oauth2';
3
- import { Nullable, JsonMap } from '@salesforce/ts-types';
3
+ import { JsonMap, Nullable } from '@salesforce/ts-types';
4
4
  import { AuthInfo } from './org/authInfo';
5
5
  export interface DeviceCodeResponse extends JsonMap {
6
6
  device_code: string;
@@ -9,10 +9,10 @@
9
9
  /* eslint-disable @typescript-eslint/ban-types */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.DeviceOauthService = void 0;
12
- const url_1 = require("url");
13
12
  const transport_1 = require("jsforce/lib/transport");
14
13
  const kit_1 = require("@salesforce/kit");
15
14
  const ts_types_1 = require("@salesforce/ts-types");
15
+ const FormData = require("form-data");
16
16
  const logger_1 = require("./logger");
17
17
  const authInfo_1 = require("./org/authInfo");
18
18
  const sfError_1 = require("./sfError");
@@ -82,8 +82,7 @@ class DeviceOauthService extends kit_1.AsyncCreatable {
82
82
  const deviceFlowRequestUrl = this.getDeviceFlowRequestUrl();
83
83
  const pollingOptions = this.getPollingOptions(deviceFlowRequestUrl, loginData.device_code);
84
84
  const interval = kit_1.Duration.seconds(loginData.interval).milliseconds;
85
- const response = await this.pollForDeviceApproval(pollingOptions, interval);
86
- return response;
85
+ return await this.pollForDeviceApproval(pollingOptions, interval);
87
86
  }
88
87
  /**
89
88
  * Creates and saves new AuthInfo
@@ -108,27 +107,27 @@ class DeviceOauthService extends kit_1.AsyncCreatable {
108
107
  this.logger.debug(`this.options.loginUrl: ${this.options.loginUrl}`);
109
108
  }
110
109
  getLoginOptions(url) {
111
- const body = new url_1.URLSearchParams();
112
- body.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
113
- body.append('response_type', DeviceOauthService.RESPONSE_TYPE);
114
- body.append('scope', DeviceOauthService.SCOPE);
110
+ const form = new FormData();
111
+ form.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
112
+ form.append('response_type', DeviceOauthService.RESPONSE_TYPE);
113
+ form.append('scope', DeviceOauthService.SCOPE);
115
114
  return {
116
115
  url,
117
- headers: connection_1.SFDX_HTTP_HEADERS,
116
+ headers: { ...connection_1.SFDX_HTTP_HEADERS, ...form.getHeaders() },
118
117
  method: 'POST',
119
- body,
118
+ body: form.getBuffer(),
120
119
  };
121
120
  }
122
121
  getPollingOptions(url, code) {
123
- const body = new url_1.URLSearchParams();
124
- body.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
125
- body.append('grant_type', DeviceOauthService.GRANT_TYPE);
126
- body.append('code', code);
122
+ const form = new FormData();
123
+ form.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
124
+ form.append('grant_type', DeviceOauthService.GRANT_TYPE);
125
+ form.append('code', code);
127
126
  return {
128
127
  url,
129
- headers: connection_1.SFDX_HTTP_HEADERS,
128
+ headers: { ...connection_1.SFDX_HTTP_HEADERS, ...form.getHeaders() },
130
129
  method: 'POST',
131
- body,
130
+ body: form.getBuffer(),
132
131
  };
133
132
  }
134
133
  getDeviceFlowRequestUrl() {
@@ -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
@@ -165,6 +165,8 @@ class SfdcUrl extends url_1.URL {
165
165
  this.origin.endsWith('sandbox.my.salesforce.mil') ||
166
166
  /sandbox\.my\.salesforce\.com/gi.test(this.origin) || // enhanced domains >= 230
167
167
  /(cs[0-9]+(\.my|)\.salesforce\.com)/gi.test(this.origin) || // my domains on CS instance OR CS instance without my domain
168
+ /(cs[0-9]+\.force\.com)/gi.test(this.origin) || // sandboxes have cnames like cs123.force.com
169
+ /(\w+--\w+\.my\.salesforce\.com)/gi.test(this.origin) || // sandboxes myDomain like foo--bar.my.salesforce.com
168
170
  /([a-z]{3}[0-9]+s\.sfdc-.+\.salesforce\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
169
171
  /([a-z]{3}[0-9]+s\.sfdc-.+\.force\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.force.com
170
172
  this.hostname === 'test.salesforce.com');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.12.0",
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",