@salesforce/core 3.12.1 → 3.13.1

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.1](https://github.com/forcedotcom/sfdx-core/compare/v3.13.0...v3.13.1) (2022-04-21)
6
+
7
+ ### Bug Fixes
8
+
9
+ - log rotation errors ([#564](https://github.com/forcedotcom/sfdx-core/issues/564)) ([8a4c9de](https://github.com/forcedotcom/sfdx-core/commit/8a4c9de85840ae0efa0ee8a27494d63a61545da5))
10
+
11
+ ## [3.13.0](https://github.com/forcedotcom/sfdx-core/compare/v3.12.2...v3.13.0) (2022-04-20)
12
+
13
+ ### Features
14
+
15
+ - 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))
16
+
17
+ ### [3.12.2](https://github.com/forcedotcom/sfdx-core/compare/v3.12.1...v3.12.2) (2022-04-14)
18
+
19
+ ### Bug Fixes
20
+
21
+ - sandbox cname recognition ([#556](https://github.com/forcedotcom/sfdx-core/issues/556)) ([2f85709](https://github.com/forcedotcom/sfdx-core/commit/2f8570912cae38fb0ddeaa37836395444c47611a))
22
+
5
23
  ### [3.12.1](https://github.com/forcedotcom/sfdx-core/compare/v3.12.0...v3.12.1) (2022-04-05)
6
24
 
7
25
  ### Bug Fixes
@@ -42,7 +42,6 @@ const messages = messages_1.Messages.load('@salesforce/core', 'config', [
42
42
  'instanceUrl',
43
43
  'disable-telemetry',
44
44
  ]);
45
- const log = logger_1.Logger.childFromRoot('core:config');
46
45
  const SFDX_CONFIG_FILE_NAME = 'sfdx-config.json';
47
46
  const CONFIG_FILE_NAME = 'config.json';
48
47
  var SfConfigProperties;
@@ -277,9 +276,12 @@ class Config extends configFile_1.ConfigFile {
277
276
  */
278
277
  static addAllowedProperties(metas) {
279
278
  const currentMetaKeys = Object.keys(Config.propertyConfigMap());
279
+ // If logger is needed elsewhere in this file, do not move this outside of the Config class.
280
+ // It was causing issues with Bunyan log rotation. See https://github.com/forcedotcom/sfdx-core/pull/562
281
+ const logger = logger_1.Logger.childFromRoot('core:config');
280
282
  metas.forEach((meta) => {
281
283
  if (currentMetaKeys.includes(meta.key)) {
282
- log.info(`Key ${meta.key} already exists in allowedProperties, skipping.`);
284
+ logger.info(`Key ${meta.key} already exists in allowedProperties, skipping.`);
283
285
  return;
284
286
  }
285
287
  Config.allowedProperties.push(meta);
@@ -31,10 +31,8 @@ class SfdxDataHandler {
31
31
  this.handlers = [new AuthHandler(), new AliasesHandler()];
32
32
  }
33
33
  async write(latest = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
34
- for (const handler of this.handlers) {
35
- await handler.write(latest, this.original);
36
- this.setOriginal(latest);
37
- }
34
+ await Promise.all(this.handlers.map((handler) => handler.write(latest, this.original)));
35
+ this.setOriginal(latest);
38
36
  }
39
37
  async merge(sfData = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
40
38
  let merged = (0, globalInfoConfig_1.deepCopy)(sfData);
@@ -103,17 +101,17 @@ class AuthHandler extends BaseHandler {
103
101
  }
104
102
  async write(latest, original) {
105
103
  const { changed, deleted } = await this.findChanges(latest, original);
106
- for (const [username, authData] of Object.entries(changed)) {
107
- if (authData) {
108
- const config = await this.createAuthFileConfig(username);
109
- config.setContentsFromObject(authData);
110
- await config.write();
111
- }
112
- }
113
- for (const username of deleted) {
104
+ await Promise.all(Object.entries(changed)
105
+ .filter(([, authData]) => authData)
106
+ .map(async ([username, authData]) => {
114
107
  const config = await this.createAuthFileConfig(username);
115
- await config.unlink();
116
- }
108
+ config.setContentsFromObject(authData);
109
+ return config.write();
110
+ }));
111
+ await Promise.all(deleted.map(async (username) => {
112
+ const config = await this.createAuthFileConfig(username);
113
+ return config.unlink();
114
+ }));
117
115
  }
118
116
  async findChanges(latest, original) {
119
117
  var _a;
@@ -146,16 +144,14 @@ class AuthHandler extends BaseHandler {
146
144
  }
147
145
  async listAllAuthorizations() {
148
146
  const filenames = await this.listAllAuthFiles();
149
- const auths = [];
150
- for (const filename of filenames) {
151
- const username = (0, path_1.basename)(filename, (0, path_1.extname)(filename));
147
+ return Promise.all(filenames
148
+ .map((f) => (0, path_1.basename)(f, (0, path_1.extname)(f)))
149
+ .map(async (username) => {
152
150
  const configFile = await this.createAuthFileConfig(username);
153
151
  const contents = configFile.getContents();
154
152
  const stat = await configFile.stat();
155
- const auth = Object.assign(contents, { timestamp: stat.mtime.toISOString() });
156
- auths.push(auth);
157
- }
158
- return auths;
153
+ return { ...contents, timestamp: stat.mtime.toISOString() };
154
+ }));
159
155
  }
160
156
  }
161
157
  exports.AuthHandler = AuthHandler;
@@ -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.1",
3
+ "version": "3.13.1",
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",