@salesforce/core 3.12.2 → 3.14.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.14.0](https://github.com/forcedotcom/sfdx-core/compare/v3.13.1...v3.14.0) (2022-04-25)
6
+
7
+ ### Features
8
+
9
+ - add SfdxConfigAggregator ([#563](https://github.com/forcedotcom/sfdx-core/issues/563)) ([cd4debd](https://github.com/forcedotcom/sfdx-core/commit/cd4debdc99046580090b5d21bbd9da9030822d4a))
10
+
11
+ ### [3.13.1](https://github.com/forcedotcom/sfdx-core/compare/v3.13.0...v3.13.1) (2022-04-21)
12
+
13
+ ### Bug Fixes
14
+
15
+ - log rotation errors ([#564](https://github.com/forcedotcom/sfdx-core/issues/564)) ([8a4c9de](https://github.com/forcedotcom/sfdx-core/commit/8a4c9de85840ae0efa0ee8a27494d63a61545da5))
16
+
17
+ ## [3.13.0](https://github.com/forcedotcom/sfdx-core/compare/v3.12.2...v3.13.0) (2022-04-20)
18
+
19
+ ### Features
20
+
21
+ - 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))
22
+
5
23
  ### [3.12.2](https://github.com/forcedotcom/sfdx-core/compare/v3.12.1...v3.12.2) (2022-04-14)
6
24
 
7
25
  ### Bug Fixes
@@ -1,4 +1,4 @@
1
- import { JsonPrimitive } from '@salesforce/ts-types';
1
+ import { JsonPrimitive, Nullable } from '@salesforce/ts-types';
2
2
  import { OrgConfigProperties } from '../org/orgConfigProperties';
3
3
  import { ConfigFile } from './configFile';
4
4
  import { ConfigContents, ConfigValue } from './configStore';
@@ -240,6 +240,7 @@ export declare class Config extends ConfigFile<ConfigFile.Options, ConfigPropert
240
240
  * Clear all the configured properties both local and global.
241
241
  */
242
242
  static clear(): Promise<void>;
243
+ static getPropertyConfigMeta(propertyName: string): Nullable<ConfigPropertyMeta>;
243
244
  private static propertyConfigMap;
244
245
  /**
245
246
  * Read, assign, and return the config contents.
@@ -298,3 +299,24 @@ export declare class Config extends ConfigFile<ConfigFile.Options, ConfigPropert
298
299
  */
299
300
  private cryptProperties;
300
301
  }
302
+ export declare class SfdxConfig {
303
+ private options;
304
+ private config;
305
+ private sfdxPath;
306
+ constructor(options: ConfigFile.Options, config: Config);
307
+ /**
308
+ * If Global.SFDX_INTEROPERABILITY is enabled, merge the sfdx config into the sf config
309
+ */
310
+ merge(config: ConfigProperties): ConfigProperties | undefined;
311
+ write(config?: import("@salesforce/ts-types").JsonMap): Promise<void>;
312
+ private readSync;
313
+ private getSfdxPath;
314
+ /**
315
+ * If toNew is specified: migrate all deprecated configs with a newKey to the newKey.
316
+ * - For example, defaultusername will be renamed to target-org.
317
+ *
318
+ * If toOld is specified: migrate all deprecated configs back to their original key.
319
+ * - For example, target-org will be renamed to defaultusername.
320
+ */
321
+ private translate;
322
+ }
@@ -6,7 +6,7 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.Config = exports.SfProperty = exports.SFDX_ALLOWED_PROPERTIES = exports.SfdxPropertyKeys = exports.SF_ALLOWED_PROPERTIES = exports.SfConfigProperties = void 0;
9
+ exports.SfdxConfig = exports.Config = exports.SfProperty = exports.SFDX_ALLOWED_PROPERTIES = exports.SfdxPropertyKeys = exports.SF_ALLOWED_PROPERTIES = exports.SfConfigProperties = void 0;
10
10
  const path_1 = require("path");
11
11
  const fs = require("fs");
12
12
  const kit_1 = require("@salesforce/kit");
@@ -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);
@@ -314,6 +316,13 @@ class Config extends configFile_1.ConfigFile {
314
316
  localConfig.clear();
315
317
  await localConfig.write();
316
318
  }
319
+ static getPropertyConfigMeta(propertyName) {
320
+ const prop = Config.propertyConfigMap()[propertyName];
321
+ if ((prop === null || prop === void 0 ? void 0 : prop.deprecated) && (prop === null || prop === void 0 ? void 0 : prop.newKey)) {
322
+ return Config.propertyConfigMap()[prop.newKey];
323
+ }
324
+ return prop;
325
+ }
317
326
  static propertyConfigMap() {
318
327
  return (0, kit_1.keyBy)(Config.allowedProperties, 'key');
319
328
  }
@@ -352,7 +361,7 @@ class Config extends configFile_1.ConfigFile {
352
361
  await this.cryptProperties(true);
353
362
  await super.write();
354
363
  if (global_1.Global.SFDX_INTEROPERABILITY)
355
- await this.sfdxConfig.writeSync();
364
+ await this.sfdxConfig.write();
356
365
  await this.cryptProperties(false);
357
366
  return this.getContents();
358
367
  }
@@ -497,25 +506,25 @@ class SfdxConfig {
497
506
  }
498
507
  return Object.assign(config, sfdxConfig);
499
508
  }
500
- readSync() {
509
+ async write(config = this.config.toObject()) {
501
510
  try {
502
- const contents = (0, kit_1.parseJsonMap)(fs.readFileSync(this.getSfdxPath(), 'utf8'));
503
- return this.normalize(contents, 'toNew');
511
+ const translated = this.translate(config, 'toOld');
512
+ const sfdxPath = this.getSfdxPath();
513
+ await mkdirp((0, path_1.dirname)(sfdxPath));
514
+ await fs.promises.writeFile(sfdxPath, JSON.stringify(translated, null, 2));
504
515
  }
505
516
  catch (error) {
506
517
  /* Do nothing */
507
- return {};
508
518
  }
509
519
  }
510
- async writeSync(config = this.config.toObject()) {
520
+ readSync() {
511
521
  try {
512
- const sfdxPath = this.getSfdxPath();
513
- await mkdirp((0, path_1.dirname)(sfdxPath));
514
- const mapped = this.normalize(config, 'toOld');
515
- await fs.promises.writeFile(sfdxPath, JSON.stringify(mapped, null, 2));
522
+ const contents = (0, kit_1.parseJsonMap)(fs.readFileSync(this.getSfdxPath(), 'utf8'));
523
+ return this.translate(contents, 'toNew');
516
524
  }
517
525
  catch (error) {
518
526
  /* Do nothing */
527
+ return {};
519
528
  }
520
529
  }
521
530
  getSfdxPath() {
@@ -542,22 +551,23 @@ class SfdxConfig {
542
551
  * If toOld is specified: migrate all deprecated configs back to their original key.
543
552
  * - For example, target-org will be renamed to defaultusername.
544
553
  */
545
- normalize(contents, direction) {
554
+ translate(contents, direction) {
546
555
  var _a;
547
- const mapped = {};
556
+ const translated = {};
548
557
  for (const [key, value] of Object.entries(contents)) {
549
558
  const propConfig = direction === 'toNew'
550
559
  ? this.config.getPropertyConfig(key)
551
560
  : (_a = Config.getAllowedProperties().find((c) => c.newKey === key)) !== null && _a !== void 0 ? _a : {};
552
561
  if (propConfig.deprecated && propConfig.newKey) {
553
562
  const normalizedKey = direction === 'toNew' ? propConfig.newKey : propConfig.key;
554
- mapped[normalizedKey] = value;
563
+ translated[normalizedKey] = value;
555
564
  }
556
565
  else {
557
- mapped[key] = value;
566
+ translated[key] = value;
558
567
  }
559
568
  }
560
- return mapped;
569
+ return translated;
561
570
  }
562
571
  }
572
+ exports.SfdxConfig = SfdxConfig;
563
573
  //# sourceMappingURL=config.js.map
@@ -40,11 +40,11 @@ export interface ConfigInfo {
40
40
  }
41
41
  /**
42
42
  * Aggregate global and local project config files, as well as environment variables for
43
- * `sfdx-config.json`. The resolution happens in the following bottom-up order:
43
+ * `config.json`. The resolution happens in the following bottom-up order:
44
44
  *
45
- * 1. Environment variables (`SFDX_LOG_LEVEL`)
46
- * 1. Workspace settings (`<workspace-root>/.sfdx/sfdx-config.json`)
47
- * 1. Global settings (`$HOME/.sfdx/sfdx-config.json`)
45
+ * 1. Environment variables (`SF_LOG_LEVEL`)
46
+ * 1. Workspace settings (`<workspace-root>/.sf/config.json`)
47
+ * 1. Global settings (`$HOME/.sf/config.json`)
48
48
  *
49
49
  * Use {@link ConfigAggregator.create} to instantiate the aggregator.
50
50
  *
@@ -67,12 +67,6 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
67
67
  * @ignore
68
68
  */
69
69
  constructor(options?: JsonMap);
70
- /**
71
- * Get the static ConfigAggregator instance. If one doesn't exist, one will be created with
72
- * the **encrypted** config values. Encrypted config values need to be resolved
73
- * asynchronously by calling {@link ConfigAggregator.reload}
74
- */
75
- static getInstance<P, T extends AsyncOptionalCreatable<P>>(this: new () => T): T;
76
70
  static create<P, T extends AsyncOptionalCreatable<P>>(this: new (options?: P) => T, options?: P): Promise<T>;
77
71
  /**
78
72
  * Get the info for a given key. If the ConfigAggregator was not asynchronously created OR
@@ -81,6 +75,12 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
81
75
  * @param key The config key.
82
76
  */
83
77
  static getValue(key: string): ConfigInfo;
78
+ /**
79
+ * Get the static ConfigAggregator instance. If one doesn't exist, one will be created with
80
+ * the **encrypted** config values. Encrypted config values need to be resolved
81
+ * asynchronously by calling {@link ConfigAggregator.reload}
82
+ */
83
+ private static getInstance;
84
84
  /**
85
85
  * Initialize this instances async dependencies.
86
86
  */
@@ -123,9 +123,9 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
123
123
  * Get a resolved file path or environment variable name of the property.
124
124
  *
125
125
  * For example, `getPath('logLevel')` will return:
126
- * 1. `$SFDX_LOG_LEVEL` if resolved to an environment variable.
127
- * 1. `./.sfdx/sfdx-config.json` if resolved to the local config.
128
- * 1. `~/.sfdx/sfdx-config.json` if resolved to the global config.
126
+ * 1. `$SF_LOG_LEVEL` if resolved to an environment variable.
127
+ * 1. `./.sf/config.json` if resolved to the local config.
128
+ * 1. `~/.sf/config.json` if resolved to the global config.
129
129
  * 1. `undefined`, if not resolved.
130
130
  *
131
131
  * **Note:** that the path returned may be the absolute path instead of
@@ -140,7 +140,7 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
140
140
  * ```
141
141
  * > console.log(aggregator.getConfigInfo());
142
142
  * [
143
- * { key: 'logLevel', val: 'INFO', location: 'Environment', path: '$SFDX_LOG_LEVEL'}
143
+ * { key: 'logLevel', val: 'INFO', location: 'Environment', path: '$SF_LOG_LEVEL'}
144
144
  * { key: 'target-org', val: '<username>', location: 'Local', path: './.sf/config.json'}
145
145
  * ]
146
146
  * ```
@@ -170,6 +170,16 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
170
170
  * Add an allowed config property.
171
171
  */
172
172
  addAllowedProperties(configMetas: ConfigPropertyMeta | ConfigPropertyMeta[]): void;
173
+ /**
174
+ * Set the allowed properties.
175
+ *
176
+ * @param properties The properties to set.
177
+ */
178
+ protected setAllowedProperties(properties: ConfigPropertyMeta[]): void;
179
+ /**
180
+ * Get the allowed properties.
181
+ */
182
+ protected getAllowedProperties(): ConfigPropertyMeta[];
173
183
  /**
174
184
  * Loads all the properties and aggregates them according to location.
175
185
  */
@@ -179,16 +189,6 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<JsonMap> {
179
189
  */
180
190
  private loadPropertiesSync;
181
191
  private resolveProperties;
182
- /**
183
- * Get the allowed properties.
184
- */
185
- private getAllowedProperties;
186
- /**
187
- * Set the allowed properties.
188
- *
189
- * @param properties The properties to set.
190
- */
191
- private setAllowedProperties;
192
192
  }
193
193
  export declare namespace ConfigAggregator {
194
194
  /**
@@ -209,3 +209,16 @@ export declare namespace ConfigAggregator {
209
209
  ENVIRONMENT = "Environment"
210
210
  }
211
211
  }
212
+ /**
213
+ * A ConfigAggregator that will work with deprecated config vars (e.g. defaultusername, apiVersion).
214
+ * We do NOT recommend using this class unless you absolutelty have to.
215
+ */
216
+ export declare class SfdxConfigAggregator extends ConfigAggregator {
217
+ getPropertyMeta(key: string): ConfigPropertyMeta;
218
+ getPropertyValue<T extends AnyJson>(key: string): Optional<T>;
219
+ getInfo(key: string): ConfigInfo;
220
+ getLocation(key: string): Optional<ConfigAggregator.Location>;
221
+ getPath(key: string): Optional<string>;
222
+ getConfigInfo(): ConfigInfo[];
223
+ private translate;
224
+ }
@@ -6,23 +6,21 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.ConfigAggregator = void 0;
9
+ exports.SfdxConfigAggregator = exports.ConfigAggregator = void 0;
10
10
  const kit_1 = require("@salesforce/kit");
11
11
  const ts_types_1 = require("@salesforce/ts-types");
12
- const change_case_1 = require("change-case");
13
12
  const messages_1 = require("../messages");
14
13
  const envVars_1 = require("./envVars");
15
14
  const config_1 = require("./config");
16
15
  messages_1.Messages.importMessagesDirectory(__dirname);
17
16
  const messages = messages_1.Messages.load('@salesforce/core', 'config', ['unknownConfigKey', 'deprecatedConfigKey']);
18
- const propertyToEnvName = (property, prefix = 'SFDX_') => `${prefix || ''}${(0, change_case_1.snakeCase)(property).toUpperCase()}`;
19
17
  /**
20
18
  * Aggregate global and local project config files, as well as environment variables for
21
- * `sfdx-config.json`. The resolution happens in the following bottom-up order:
19
+ * `config.json`. The resolution happens in the following bottom-up order:
22
20
  *
23
- * 1. Environment variables (`SFDX_LOG_LEVEL`)
24
- * 1. Workspace settings (`<workspace-root>/.sfdx/sfdx-config.json`)
25
- * 1. Global settings (`$HOME/.sfdx/sfdx-config.json`)
21
+ * 1. Environment variables (`SF_LOG_LEVEL`)
22
+ * 1. Workspace settings (`<workspace-root>/.sf/config.json`)
23
+ * 1. Global settings (`$HOME/.sf/config.json`)
26
24
  *
27
25
  * Use {@link ConfigAggregator.create} to instantiate the aggregator.
28
26
  *
@@ -55,20 +53,6 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
55
53
  get config() {
56
54
  return this.resolveProperties(this.globalConfig.getContents(), this.localConfig && this.localConfig.getContents());
57
55
  }
58
- /**
59
- * Get the static ConfigAggregator instance. If one doesn't exist, one will be created with
60
- * the **encrypted** config values. Encrypted config values need to be resolved
61
- * asynchronously by calling {@link ConfigAggregator.reload}
62
- */
63
- // Use typing from AsyncOptionalCreatable to support extending ConfigAggregator.
64
- // We really don't want ConfigAggregator extended but typescript doesn't support a final.
65
- static getInstance() {
66
- if (!ConfigAggregator.instance) {
67
- ConfigAggregator.instance = new this();
68
- ConfigAggregator.instance.loadPropertiesSync();
69
- }
70
- return ConfigAggregator.instance;
71
- }
72
56
  // Use typing from AsyncOptionalCreatable to support extending ConfigAggregator.
73
57
  // We really don't want ConfigAggregator extended but typescript doesn't support a final.
74
58
  static async create(options) {
@@ -91,6 +75,20 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
91
75
  static getValue(key) {
92
76
  return this.getInstance().getInfo(key);
93
77
  }
78
+ /**
79
+ * Get the static ConfigAggregator instance. If one doesn't exist, one will be created with
80
+ * the **encrypted** config values. Encrypted config values need to be resolved
81
+ * asynchronously by calling {@link ConfigAggregator.reload}
82
+ */
83
+ // Use typing from AsyncOptionalCreatable to support extending ConfigAggregator.
84
+ // We really don't want ConfigAggregator extended but typescript doesn't support a final.
85
+ static getInstance() {
86
+ if (!ConfigAggregator.instance) {
87
+ ConfigAggregator.instance = new this();
88
+ ConfigAggregator.instance.loadPropertiesSync();
89
+ }
90
+ return ConfigAggregator.instance;
91
+ }
94
92
  /**
95
93
  * Initialize this instances async dependencies.
96
94
  */
@@ -106,7 +104,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
106
104
  */
107
105
  getPropertyValue(key) {
108
106
  if (this.getAllowedProperties().some((element) => key === element.key)) {
109
- return this.getConfig()[key];
107
+ return this.getConfig()[key] || this.getEnvVars().get(key);
110
108
  }
111
109
  else {
112
110
  throw messages.createError('unknownConfigKey', [key]);
@@ -177,9 +175,9 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
177
175
  * Get a resolved file path or environment variable name of the property.
178
176
  *
179
177
  * For example, `getPath('logLevel')` will return:
180
- * 1. `$SFDX_LOG_LEVEL` if resolved to an environment variable.
181
- * 1. `./.sfdx/sfdx-config.json` if resolved to the local config.
182
- * 1. `~/.sfdx/sfdx-config.json` if resolved to the global config.
178
+ * 1. `$SF_LOG_LEVEL` if resolved to an environment variable.
179
+ * 1. `./.sf/config.json` if resolved to the local config.
180
+ * 1. `~/.sf/config.json` if resolved to the global config.
183
181
  * 1. `undefined`, if not resolved.
184
182
  *
185
183
  * **Note:** that the path returned may be the absolute path instead of
@@ -189,7 +187,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
189
187
  */
190
188
  getPath(key) {
191
189
  if (this.envVars.getString(key) != null) {
192
- return `$${propertyToEnvName(key)}`;
190
+ return `$${this.envVars.propertyToEnvName(key)}`;
193
191
  }
194
192
  if (this.localConfig && this.localConfig.getContents()[key] != null) {
195
193
  return this.localConfig.getPath();
@@ -204,7 +202,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
204
202
  * ```
205
203
  * > console.log(aggregator.getConfigInfo());
206
204
  * [
207
- * { key: 'logLevel', val: 'INFO', location: 'Environment', path: '$SFDX_LOG_LEVEL'}
205
+ * { key: 'logLevel', val: 'INFO', location: 'Environment', path: '$SF_LOG_LEVEL'}
208
206
  * { key: 'target-org', val: '<username>', location: 'Local', path: './.sf/config.json'}
209
207
  * ]
210
208
  * ```
@@ -258,6 +256,20 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
258
256
  this.allowedProperties.push(configMetas);
259
257
  }
260
258
  }
259
+ /**
260
+ * Set the allowed properties.
261
+ *
262
+ * @param properties The properties to set.
263
+ */
264
+ setAllowedProperties(properties) {
265
+ this.allowedProperties = properties;
266
+ }
267
+ /**
268
+ * Get the allowed properties.
269
+ */
270
+ getAllowedProperties() {
271
+ return this.allowedProperties;
272
+ }
261
273
  /**
262
274
  * Loads all the properties and aggregates them according to location.
263
275
  */
@@ -288,21 +300,51 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
288
300
  const reduced = configs.filter(ts_types_1.isJsonMap).reduce((acc, el) => (0, kit_1.merge)(acc, el), json);
289
301
  return reduced;
290
302
  }
291
- /**
292
- * Get the allowed properties.
293
- */
294
- getAllowedProperties() {
295
- return this.allowedProperties;
296
- }
297
- /**
298
- * Set the allowed properties.
299
- *
300
- * @param properties The properties to set.
301
- */
302
- setAllowedProperties(properties) {
303
- this.allowedProperties = properties;
304
- }
305
303
  }
306
304
  exports.ConfigAggregator = ConfigAggregator;
307
305
  ConfigAggregator.encrypted = true;
306
+ /**
307
+ * A ConfigAggregator that will work with deprecated config vars (e.g. defaultusername, apiVersion).
308
+ * We do NOT recommend using this class unless you absolutelty have to.
309
+ */
310
+ class SfdxConfigAggregator extends ConfigAggregator {
311
+ getPropertyMeta(key) {
312
+ const match = this.getAllowedProperties().find((element) => key === element.key);
313
+ if ((match === null || match === void 0 ? void 0 : match.deprecated) && (match === null || match === void 0 ? void 0 : match.newKey)) {
314
+ return this.getPropertyMeta(match.newKey);
315
+ }
316
+ else if (match) {
317
+ return match;
318
+ }
319
+ else {
320
+ throw messages.createError('unknownConfigKey', [key]);
321
+ }
322
+ }
323
+ getPropertyValue(key) {
324
+ return super.getPropertyValue(this.translate(key));
325
+ }
326
+ getInfo(key) {
327
+ return super.getInfo(this.translate(key));
328
+ }
329
+ getLocation(key) {
330
+ return super.getLocation(this.translate(key));
331
+ }
332
+ getPath(key) {
333
+ return super.getPath(this.translate(key));
334
+ }
335
+ getConfigInfo() {
336
+ return super.getConfigInfo().map((c) => {
337
+ c.key = this.translate(c.key, 'toOld');
338
+ return c;
339
+ });
340
+ }
341
+ translate(key, direction = 'toNew') {
342
+ var _a;
343
+ const propConfig = direction === 'toNew'
344
+ ? this.getPropertyMeta(key)
345
+ : (_a = config_1.Config.getAllowedProperties().find((c) => c.newKey === key)) !== null && _a !== void 0 ? _a : {};
346
+ return propConfig.key || key;
347
+ }
348
+ }
349
+ exports.SfdxConfigAggregator = SfdxConfigAggregator;
308
350
  //# sourceMappingURL=configAggregator.js.map
@@ -260,11 +260,11 @@ exports.SUPPORTED_ENV_VARS = {
260
260
  },
261
261
  [EnvironmentVariable.SF_TARGET_ORG]: {
262
262
  description: getMessage(EnvironmentVariable.SF_TARGET_ORG),
263
- synonymOf: null,
263
+ synonymOf: EnvironmentVariable.SFDX_DEFAULTUSERNAME,
264
264
  },
265
265
  [EnvironmentVariable.SF_TARGET_DEV_HUB]: {
266
266
  description: getMessage(EnvironmentVariable.SF_TARGET_DEV_HUB),
267
- synonymOf: null,
267
+ synonymOf: EnvironmentVariable.SFDX_DEFAULTDEVHUBUSERNAME,
268
268
  },
269
269
  // sf vars
270
270
  [EnvironmentVariable.SF_ACCESS_TOKEN]: {
@@ -273,7 +273,7 @@ exports.SUPPORTED_ENV_VARS = {
273
273
  },
274
274
  [EnvironmentVariable.SF_ORG_API_VERSION]: {
275
275
  description: getMessage(EnvironmentVariable.SF_ORG_API_VERSION),
276
- synonymOf: null,
276
+ synonymOf: EnvironmentVariable.SFDX_API_VERSION,
277
277
  },
278
278
  [EnvironmentVariable.SF_AUDIENCE_URL]: {
279
279
  description: getMessage(EnvironmentVariable.SF_AUDIENCE_URL),
package/lib/exported.d.ts CHANGED
@@ -7,7 +7,7 @@ export { GlobalInfo, SfEntry, SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfToken, SfToke
7
7
  export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } from './deviceOauthService';
8
8
  export { OrgUsersConfig } from './config/orgUsersConfig';
9
9
  export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config, SfdxPropertyKeys, SfConfigProperties, SFDX_ALLOWED_PROPERTIES, SF_ALLOWED_PROPERTIES, } from './config/config';
10
- export { ConfigInfo, ConfigAggregator } from './config/configAggregator';
10
+ export { ConfigInfo, ConfigAggregator, SfdxConfigAggregator } from './config/configAggregator';
11
11
  export { AuthFields, AuthInfo, AuthSideEffects, OrgAuthorization } from './org/authInfo';
12
12
  export { AuthRemover } from './org/authRemover';
13
13
  export { Connection, SFDX_HTTP_HEADERS } from './org/connection';
package/lib/exported.js CHANGED
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SfError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.SfProjectJson = exports.SfProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = exports.OrgTypes = exports.SandboxEvents = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.AuthInfo = exports.ConfigAggregator = exports.SF_ALLOWED_PROPERTIES = exports.SFDX_ALLOWED_PROPERTIES = exports.SfConfigProperties = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.TTLConfig = exports.ConfigFile = void 0;
20
- exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = exports.scratchOrgCreate = exports.PermissionSetAssignment = void 0;
19
+ exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SfError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.SfProjectJson = exports.SfProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = exports.OrgTypes = exports.SandboxEvents = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.AuthInfo = exports.SfdxConfigAggregator = exports.ConfigAggregator = exports.SF_ALLOWED_PROPERTIES = exports.SFDX_ALLOWED_PROPERTIES = exports.SfConfigProperties = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.TTLConfig = exports.ConfigFile = void 0;
20
+ exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = void 0;
21
21
  const messages_1 = require("./messages");
22
22
  messages_1.Messages.importMessagesDirectory(__dirname);
23
23
  var configFile_1 = require("./config/configFile");
@@ -46,6 +46,7 @@ Object.defineProperty(exports, "SFDX_ALLOWED_PROPERTIES", { enumerable: true, ge
46
46
  Object.defineProperty(exports, "SF_ALLOWED_PROPERTIES", { enumerable: true, get: function () { return config_1.SF_ALLOWED_PROPERTIES; } });
47
47
  var configAggregator_1 = require("./config/configAggregator");
48
48
  Object.defineProperty(exports, "ConfigAggregator", { enumerable: true, get: function () { return configAggregator_1.ConfigAggregator; } });
49
+ Object.defineProperty(exports, "SfdxConfigAggregator", { enumerable: true, get: function () { return configAggregator_1.SfdxConfigAggregator; } });
49
50
  var authInfo_1 = require("./org/authInfo");
50
51
  Object.defineProperty(exports, "AuthInfo", { enumerable: true, get: function () { return authInfo_1.AuthInfo; } });
51
52
  var authRemover_1 = require("./org/authRemover");
@@ -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
  /**
@@ -130,7 +130,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
130
130
  * @returns {string}
131
131
  */
132
132
  static getDefaultInstanceUrl() {
133
- const configuredInstanceUrl = configAggregator_1.ConfigAggregator.getValue('instanceUrl').value;
133
+ const configuredInstanceUrl = configAggregator_1.ConfigAggregator.getValue(orgConfigProperties_1.OrgConfigProperties.ORG_INSTANCE_URL).value;
134
134
  return configuredInstanceUrl || sfdcUrl_1.SfdcUrl.PRODUCTION;
135
135
  }
136
136
  /**
@@ -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
@@ -86,7 +86,7 @@ class Connection extends jsforce_1.Connection {
86
86
  if (!baseOptions.version) {
87
87
  // Set the API version obtained from the config aggregator.
88
88
  const configAggregator = options.configAggregator || (await configAggregator_1.ConfigAggregator.create());
89
- baseOptions.version = (0, ts_types_1.asString)(configAggregator.getInfo('apiVersion').value);
89
+ baseOptions.version = (0, ts_types_1.asString)(configAggregator.getInfo('org-api-version').value);
90
90
  }
91
91
  const providedOptions = options.authInfo.getConnectionOptions();
92
92
  // Get connection options from auth info and create a new jsForce connection
@@ -102,7 +102,7 @@ class Connection extends jsforce_1.Connection {
102
102
  }
103
103
  }
104
104
  else {
105
- conn.logger.debug(`The apiVersion ${baseOptions.version} was found from ${((_b = options.connectionOptions) === null || _b === void 0 ? void 0 : _b.version) ? 'passed in options' : 'config'}`);
105
+ conn.logger.debug(`The org-api-version ${baseOptions.version} was found from ${((_b = options.connectionOptions) === null || _b === void 0 ? void 0 : _b.version) ? 'passed in options' : 'config'}`);
106
106
  }
107
107
  }
108
108
  catch (err) {
@@ -334,7 +334,7 @@ class Connection extends jsforce_1.Connection {
334
334
  async autoFetchQuery(soql, queryOptions = {}) {
335
335
  const config = await configAggregator_1.ConfigAggregator.create();
336
336
  // take the limit from the calling function, then the config, then default 10,000
337
- const maxFetch = config.getInfo('maxQueryLimit').value || queryOptions.maxFetch || 10000;
337
+ const maxFetch = config.getInfo('org-max-query-limit').value || queryOptions.maxFetch || 10000;
338
338
  const options = Object.assign(queryOptions, {
339
339
  autoFetch: true,
340
340
  maxFetch,
@@ -418,7 +418,7 @@ class Connection extends jsforce_1.Connection {
418
418
  // so get the latest.
419
419
  await useLatest();
420
420
  }
421
- this.logger.debug(`Loaded latest apiVersion ${version}`);
421
+ this.logger.debug(`Loaded latest org-api-version ${version}`);
422
422
  return version;
423
423
  }
424
424
  }
@@ -103,7 +103,7 @@ const scratchOrgCreate = async (options) => {
103
103
  logger.debug(`scratch org username ${username}`);
104
104
  const configAggregator = new configAggregator_1.ConfigAggregator();
105
105
  await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'deploy settings', scratchOrgInfo: scratchOrgInfoResult });
106
- const authInfo = await (0, scratchOrgInfoApi_1.deploySettingsAndResolveUrl)(scratchOrgAuthInfo, (_a = apiversion !== null && apiversion !== void 0 ? apiversion : configAggregator.getPropertyValue('apiVersion')) !== null && _a !== void 0 ? _a : (await scratchOrg.retrieveMaxApiVersion()), settingsGenerator, scratchOrg);
106
+ const authInfo = await (0, scratchOrgInfoApi_1.deploySettingsAndResolveUrl)(scratchOrgAuthInfo, (_a = apiversion !== null && apiversion !== void 0 ? apiversion : configAggregator.getPropertyValue('org-api-version')) !== null && _a !== void 0 ? _a : (await scratchOrg.retrieveMaxApiVersion()), settingsGenerator, scratchOrg);
107
107
  logger.trace('Settings deployed to org');
108
108
  /** updating the revision num to zero during org:creation if source members are created during org:create.This only happens for some specific scratch org definition file.*/
109
109
  await updateRevisionCounterToZero(scratchOrg);
package/lib/sfProject.js CHANGED
@@ -537,7 +537,7 @@ class SfProject {
537
537
  Object.assign(this.projectConfig, configAggregator.getConfig());
538
538
  // we don't have a login url yet, so use instanceUrl from config or default
539
539
  if (!this.projectConfig.sfdcLoginUrl) {
540
- this.projectConfig.sfdcLoginUrl = (_a = configAggregator.getConfig().instanceUrl) !== null && _a !== void 0 ? _a : sfdcUrl_1.SfdcUrl.PRODUCTION;
540
+ this.projectConfig.sfdcLoginUrl = (_a = configAggregator.getConfig()['org-instance-url']) !== null && _a !== void 0 ? _a : sfdcUrl_1.SfdcUrl.PRODUCTION;
541
541
  }
542
542
  // LEGACY - Allow override of sfdcLoginUrl via env var FORCE_SFDC_LOGIN_URL
543
543
  if (process.env.FORCE_SFDC_LOGIN_URL) {
package/lib/testSetup.js CHANGED
@@ -165,8 +165,6 @@ exports.instantiateContext = instantiateContext;
165
165
  const stubContext = (testContext) => {
166
166
  // Turn off the interoperability feature so that we don't have to mock
167
167
  // the old .sfdx config files
168
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
169
- // @ts-ignore
170
168
  global_1.Global.SFDX_INTEROPERABILITY = false;
171
169
  // Most core files create a child logger so stub this to return our test logger.
172
170
  (0, ts_sinon_1.stubMethod)(testContext.SANDBOX, logger_1.Logger, 'child').returns(Promise.resolve(testContext.TEST_LOGGER));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.12.2",
3
+ "version": "3.14.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",