@salesforce/core 4.0.0 → 4.0.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.
Files changed (153) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +93 -44
  3. package/lib/config/aliasesConfig.d.ts +12 -0
  4. package/lib/config/aliasesConfig.js +28 -0
  5. package/lib/config/authInfoConfig.d.ts +19 -0
  6. package/lib/config/authInfoConfig.js +35 -0
  7. package/lib/config/config.d.ts +87 -22
  8. package/lib/config/config.js +117 -65
  9. package/lib/config/configAggregator.d.ts +41 -35
  10. package/lib/config/configAggregator.js +102 -73
  11. package/lib/config/configFile.d.ts +2 -2
  12. package/lib/config/configFile.js +38 -29
  13. package/lib/config/configGroup.d.ts +141 -0
  14. package/lib/config/configGroup.js +225 -0
  15. package/lib/config/configStore.d.ts +9 -9
  16. package/lib/config/configStore.js +17 -15
  17. package/lib/config/envVars.d.ts +15 -9
  18. package/lib/config/envVars.js +71 -47
  19. package/lib/config/orgUsersConfig.js +2 -0
  20. package/lib/config/sandboxOrgConfig.js +2 -0
  21. package/lib/config/sandboxProcessCache.d.ts +16 -0
  22. package/lib/config/sandboxProcessCache.js +38 -0
  23. package/lib/config/tokensConfig.d.ts +10 -0
  24. package/lib/config/tokensConfig.js +29 -0
  25. package/lib/config/ttlConfig.d.ts +34 -0
  26. package/lib/config/ttlConfig.js +50 -0
  27. package/lib/crypto/crypto.js +15 -22
  28. package/lib/crypto/keyChain.js +2 -3
  29. package/lib/crypto/keyChainImpl.d.ts +5 -3
  30. package/lib/crypto/keyChainImpl.js +58 -61
  31. package/lib/crypto/secureBuffer.d.ts +1 -1
  32. package/lib/deviceOauthService.d.ts +3 -3
  33. package/lib/deviceOauthService.js +27 -25
  34. package/lib/exported.d.ts +15 -12
  35. package/lib/exported.js +28 -16
  36. package/lib/global.d.ts +11 -3
  37. package/lib/global.js +39 -12
  38. package/lib/lifecycleEvents.d.ts +1 -1
  39. package/lib/lifecycleEvents.js +3 -0
  40. package/lib/logger.d.ts +19 -9
  41. package/lib/logger.js +112 -86
  42. package/lib/messages.d.ts +53 -36
  43. package/lib/messages.js +81 -91
  44. package/lib/org/authInfo.d.ts +56 -20
  45. package/lib/org/authInfo.js +232 -131
  46. package/lib/org/authRemover.d.ts +8 -7
  47. package/lib/org/authRemover.js +32 -28
  48. package/lib/org/connection.d.ts +13 -37
  49. package/lib/org/connection.js +78 -124
  50. package/lib/org/index.js +5 -1
  51. package/lib/org/org.d.ts +151 -48
  52. package/lib/org/org.js +466 -220
  53. package/lib/org/orgConfigProperties.d.ts +64 -3
  54. package/lib/org/orgConfigProperties.js +96 -4
  55. package/lib/org/permissionSetAssignment.js +4 -13
  56. package/lib/org/scratchOrgCache.d.ts +20 -0
  57. package/lib/org/scratchOrgCache.js +33 -0
  58. package/lib/org/scratchOrgCreate.d.ts +28 -17
  59. package/lib/org/scratchOrgCreate.js +125 -53
  60. package/lib/org/scratchOrgErrorCodes.d.ts +9 -3
  61. package/lib/org/scratchOrgErrorCodes.js +34 -17
  62. package/lib/org/scratchOrgFeatureDeprecation.js +1 -6
  63. package/lib/org/scratchOrgInfoApi.d.ts +21 -47
  64. package/lib/org/scratchOrgInfoApi.js +129 -63
  65. package/lib/org/scratchOrgInfoGenerator.d.ts +6 -5
  66. package/lib/org/scratchOrgInfoGenerator.js +76 -62
  67. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
  68. package/lib/org/scratchOrgLifecycleEvents.js +41 -0
  69. package/lib/org/scratchOrgSettingsGenerator.d.ts +44 -21
  70. package/lib/org/scratchOrgSettingsGenerator.js +165 -98
  71. package/lib/org/scratchOrgTypes.d.ts +43 -0
  72. package/lib/org/scratchOrgTypes.js +9 -0
  73. package/lib/org/user.d.ts +1 -1
  74. package/lib/org/user.js +25 -34
  75. package/lib/schema/printer.d.ts +6 -0
  76. package/lib/schema/printer.js +34 -31
  77. package/lib/schema/validator.d.ts +12 -10
  78. package/lib/schema/validator.js +56 -76
  79. package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -20
  80. package/lib/{sfdxError.js → sfError.js} +40 -30
  81. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
  82. package/lib/sfProject.js +651 -0
  83. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +27 -12
  84. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +47 -31
  85. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
  86. package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
  87. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
  88. package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
  89. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
  90. package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
  91. package/lib/stateAggregator/index.d.ts +4 -0
  92. package/lib/stateAggregator/index.js +27 -0
  93. package/lib/stateAggregator/stateAggregator.d.ts +25 -0
  94. package/lib/stateAggregator/stateAggregator.js +46 -0
  95. package/lib/status/myDomainResolver.d.ts +1 -1
  96. package/lib/status/myDomainResolver.js +4 -4
  97. package/lib/status/pollingClient.js +4 -4
  98. package/lib/status/streamingClient.d.ts +2 -2
  99. package/lib/status/streamingClient.js +58 -63
  100. package/lib/status/types.d.ts +2 -2
  101. package/lib/testSetup.d.ts +206 -75
  102. package/lib/testSetup.js +463 -165
  103. package/lib/util/cache.d.ts +2 -2
  104. package/lib/util/cache.js +6 -6
  105. package/lib/util/checkLightningDomain.js +3 -4
  106. package/lib/util/directoryWriter.d.ts +12 -0
  107. package/lib/util/directoryWriter.js +54 -0
  108. package/lib/util/getJwtAudienceUrl.js +1 -1
  109. package/lib/util/internal.d.ts +28 -2
  110. package/lib/util/internal.js +65 -8
  111. package/lib/util/jsonXmlTools.js +2 -4
  112. package/lib/util/mapKeys.d.ts +9 -9
  113. package/lib/util/mapKeys.js +13 -9
  114. package/lib/util/sfdc.d.ts +51 -51
  115. package/lib/util/sfdc.js +74 -79
  116. package/lib/util/sfdcUrl.d.ts +5 -19
  117. package/lib/util/sfdcUrl.js +40 -49
  118. package/lib/util/structuredWriter.d.ts +9 -0
  119. package/lib/util/structuredWriter.js +3 -0
  120. package/lib/util/zipWriter.d.ts +8 -6
  121. package/lib/util/zipWriter.js +13 -13
  122. package/lib/webOAuthServer.d.ts +20 -6
  123. package/lib/webOAuthServer.js +102 -56
  124. package/messageTransformer/messageTransformer.ts +93 -0
  125. package/messages/auth.md +9 -1
  126. package/messages/config.md +42 -6
  127. package/messages/connection.md +8 -0
  128. package/messages/core.md +10 -0
  129. package/messages/envVars.md +37 -3
  130. package/messages/org.md +21 -1
  131. package/messages/scratchOrgCreate.md +2 -6
  132. package/messages/scratchOrgErrorCodes.md +17 -1
  133. package/messages/scratchOrgInfoApi.md +9 -0
  134. package/messages/scratchOrgInfoGenerator.md +9 -1
  135. package/package.json +121 -46
  136. package/CHANGELOG.md +0 -1244
  137. package/lib/config/keychainConfig.d.ts +0 -19
  138. package/lib/config/keychainConfig.js +0 -43
  139. package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
  140. package/lib/globalInfo/accessors/orgAccessor.js +0 -45
  141. package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
  142. package/lib/globalInfo/accessors/tokenAccessor.js +0 -35
  143. package/lib/globalInfo/globalInfoConfig.d.ts +0 -36
  144. package/lib/globalInfo/globalInfoConfig.js +0 -105
  145. package/lib/globalInfo/index.d.ts +0 -6
  146. package/lib/globalInfo/index.js +0 -29
  147. package/lib/globalInfo/sfdxDataHandler.d.ts +0 -43
  148. package/lib/globalInfo/sfdxDataHandler.js +0 -217
  149. package/lib/globalInfo/types.d.ts +0 -39
  150. package/lib/globalInfo/types.js +0 -10
  151. package/lib/sfdxProject.js +0 -557
  152. package/lib/util/fs.d.ts +0 -201
  153. package/lib/util/fs.js +0 -378
@@ -9,20 +9,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  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");
13
+ const lifecycleEvents_1 = require("../lifecycleEvents");
14
14
  const envVars_1 = require("./envVars");
15
15
  const config_1 = require("./config");
16
- messages_1.Messages.importMessagesDirectory(__dirname);
17
- 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()}`;
16
+ const messages = new messages_1.Messages('@salesforce/core', 'config', new Map([["unknownConfigKey", "Unknown config name: %s."], ["deprecatedConfigKey", "Deprecated config name: %s. Please use %s instead."], ["invalidWrite", "The writeSync method is not allowed on SfdxConfig. Use the async write method instead."], ["invalidConfigValue", "Invalid config value: %s."], ["invalidInstanceUrl", "Specify a valid Salesforce instance URL."], ["invalidApiVersion", "Specify a valid Salesforce API version, for example, 42.0."], ["invalidCustomOrgMetadataTemplates", "Specify a valid repository URL or directory for the custom org metadata templates."], ["invalidIsvDebuggerSid", "Specify a valid Debugger SID."], ["invalidIsvDebuggerUrl", "Specify a valid Debugger URL."], ["invalidNumberConfigValue", "Specify a valid positive integer, for example, 150000."], ["invalidBooleanConfigValue", "The config value can only be set to true or false."], ["invalidProjectWorkspace", "This directory does not contain a valid Salesforce DX project."], ["schemaValidationError", "The config file \"%s\" is not schema valid.\nDue to: %s"], ["schemaValidationError.actions", ["Fix the invalid entries at %s."]], ["missingDefaultPath", "In sfdx-project.json, be sure to specify which package directory (path) is the default. Example: `[{ \"path\": \"packageDirectory1\", \"default\": true }, { \"path\": \"packageDirectory2\" }]`"], ["missingPackageDirectory", "The path \"%s\", specified in sfdx-project.json, does not exist. Be sure this directory is included in your project root."], ["invalidPackageDirectory", "The path \"%s\", specified in sfdx-project.json, must be indicated as a relative path to the project root."], ["multipleDefaultPaths", "In sfdx-project.json, indicate only one package directory (path) as the default."], ["singleNonDefaultPackage", "The sfdx-project.json file must include one, and only one, default package directory (path). Because your sfdx-project.json file contains only one package directory, it must be the default. Remove the `\"default\": false` key and try again."], ["target-org", "Username or alias of the org that all commands run against by default. (sf only)"], ["target-dev-hub", "Username or alias of your default Dev Hub org. (sf only)"], ["defaultUsername", "Username or alias of the org that all commands run against by default. (sfdx only)"], ["defaultDevHubUsername", "Username or alias of your default Dev Hub org. (sfdx only)"], ["isvDebuggerSid", "ISV debugger SID (sfdx only)"], ["isvDebuggerUrl", "ISV debugger URL (sfdx only)"], ["org-isv-debugger-sid", "ISV debugger SID."], ["org-isv-debugger-url", "ISV debugger URL."], ["apiVersion", "API version of your project. Default: API version of your Dev Hub org. (sfdx only)"], ["org-api-version", "API version of your project. Default: API version of your Dev Hub org."], ["disableTelemetry", "Disables the collection of usage and user environment information, etc. Default: false. (sfdx only)"], ["disable-telemetry", "Disables the collection of usage and user environment information, etc. Default: false."], ["maxQueryLimit", "Maximum number of Salesforce records returned by a CLI command. Default: 10,000. (sfdx only)"], ["org-max-query-limit", "Maximum number of Salesforce records returned by a CLI command. Default: 10,000."], ["restDeploy", "Whether deployments use the Metadata REST API (true) or SOAP API (false, default value). (sfdx only)"], ["instanceUrl", "URL of the Salesforce instance hosting your org. Default: https://login.salesforce.com. (sfdx only)"], ["org-instance-url", "URL of the Salesforce instance hosting your org. Default: https://login.salesforce.com."], ["customOrgMetadataTemplates", "A valid repository URL or directory for the custom org metadata templates."], ["org-custom-metadata-templates", "A valid repository URL or directory for the custom org metadata templates."], ["invalidId", "The given id %s is not a valid 15 or 18 character Salesforce ID."]]));
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
  *
@@ -38,7 +36,8 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
38
36
  * @ignore
39
37
  */
40
38
  constructor(options) {
41
- super(options || {});
39
+ super(options ?? {});
40
+ this.envVars = {};
42
41
  // Don't throw an project error with the aggregator, since it should resolve to global if
43
42
  // there is no project.
44
43
  try {
@@ -53,21 +52,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
53
52
  this.setAllowedProperties(config_1.Config.getAllowedProperties());
54
53
  }
55
54
  get config() {
56
- return this.resolveProperties(this.globalConfig.getContents(), this.localConfig && this.localConfig.getContents());
57
- }
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;
55
+ return this.resolveProperties(this.globalConfig.getContents(), this.localConfig?.getContents());
71
56
  }
72
57
  // Use typing from AsyncOptionalCreatable to support extending ConfigAggregator.
73
58
  // We really don't want ConfigAggregator extended but typescript doesn't support a final.
@@ -80,6 +65,9 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
80
65
  if (ConfigAggregator.encrypted) {
81
66
  await config.loadProperties();
82
67
  }
68
+ if (options?.customConfigMeta) {
69
+ config_1.Config.addAllowedProperties(options.customConfigMeta);
70
+ }
83
71
  return ConfigAggregator.instance;
84
72
  }
85
73
  /**
@@ -91,6 +79,20 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
91
79
  static getValue(key) {
92
80
  return this.getInstance().getInfo(key);
93
81
  }
82
+ /**
83
+ * Get the static ConfigAggregator instance. If one doesn't exist, one will be created with
84
+ * the **encrypted** config values. Encrypted config values need to be resolved
85
+ * asynchronously by calling {@link ConfigAggregator.reload}
86
+ */
87
+ // Use typing from AsyncOptionalCreatable to support extending ConfigAggregator.
88
+ // We really don't want ConfigAggregator extended but typescript doesn't support a final.
89
+ static getInstance() {
90
+ if (!ConfigAggregator.instance) {
91
+ ConfigAggregator.instance = new this();
92
+ ConfigAggregator.instance.loadPropertiesSync();
93
+ }
94
+ return ConfigAggregator.instance;
95
+ }
94
96
  /**
95
97
  * Initialize this instances async dependencies.
96
98
  */
@@ -99,13 +101,22 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
99
101
  }
100
102
  /**
101
103
  * Get a resolved config property.
104
+ * If you use a deprecated property, a warning will be emitted and it will attempt to resolve the new property's value
102
105
  *
103
- * **Throws** *{@link SfdxError}{ name: 'UnknownConfigKeyError' }* An attempt to get a property that's not supported.
106
+ * **Throws** *{@link SfError}{ name: 'UnknownConfigKeyError' }* An attempt to get a property that's not supported.
104
107
  *
105
108
  * @param key The key of the property.
106
109
  */
107
110
  getPropertyValue(key) {
108
- if (this.getAllowedProperties().some((element) => key === element.key)) {
111
+ const match = this.getAllowedProperties().find((element) => key === element.key);
112
+ if (match?.deprecated && match.newKey) {
113
+ void lifecycleEvents_1.Lifecycle.getInstance().emitWarning(messages.getMessage('deprecatedConfigKey', [key, match.newKey]));
114
+ const newKeyMatch = this.getAllowedProperties().find((element) => match.newKey === element.key);
115
+ if (newKeyMatch) {
116
+ return this.getConfig()[newKeyMatch.key] ?? this.getConfig()[match.key];
117
+ }
118
+ }
119
+ if (this.getAllowedProperties().some((element) => key === element.key || key === element.newKey)) {
109
120
  return this.getConfig()[key];
110
121
  }
111
122
  else {
@@ -114,42 +125,55 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
114
125
  }
115
126
  /**
116
127
  * Get a resolved config property meta.
128
+ * If the property is deprecated, it will return the new key's meta, if it exists, with a deprecation warning
117
129
  *
118
- * **Throws** *{@link SfdxError}{ name: 'UnknownConfigKeyError' }* An attempt to get a property that's not supported.
130
+ * **Throws** *{@link SfError}{ name: 'UnknownConfigKeyError' }* An attempt to get a property that's not supported.
119
131
  *
120
132
  * @param key The key of the property.
121
133
  */
122
134
  getPropertyMeta(key) {
123
135
  const match = this.getAllowedProperties().find((element) => key === element.key);
124
136
  if (match) {
137
+ if (match.deprecated && match.newKey) {
138
+ void lifecycleEvents_1.Lifecycle.getInstance().emitWarning(messages.getMessage('deprecatedConfigKey', [key, match.newKey]));
139
+ const newKeyMatch = this.getAllowedProperties().find((element) => key === element.newKey);
140
+ if (newKeyMatch) {
141
+ return newKeyMatch ?? match;
142
+ }
143
+ }
125
144
  return match;
126
145
  }
127
- else {
128
- throw messages.createError('unknownConfigKey', [key]);
146
+ const matchFromNewKey = this.getAllowedProperties().find((element) => key === element.newKey);
147
+ if (matchFromNewKey) {
148
+ return matchFromNewKey;
129
149
  }
150
+ throw messages.createError('unknownConfigKey', [key]);
130
151
  }
131
152
  /**
132
153
  * Get a resolved config property.
154
+ * If a property is deprecated, it will try to use the the new key, if there is a config there.
133
155
  *
134
156
  * @param key The key of the property.
135
157
  * @param throwOnDeprecation True, if you want an error throw when reading a deprecated config
136
158
  */
137
159
  getInfo(key, throwOnDeprecation = false) {
138
- var _a;
139
160
  const meta = this.getPropertyMeta(key);
140
- if (throwOnDeprecation && meta.deprecated && meta.newKey) {
141
- throw messages.createError('deprecatedConfigKey', [key, meta.newKey]);
161
+ if (meta.deprecated && meta.newKey) {
162
+ if (throwOnDeprecation) {
163
+ throw messages.createError('deprecatedConfigKey', [key, meta.newKey]);
164
+ }
165
+ // we don't need to emit a deprecatedConfigKey warning here because getPropertyMeta does that
142
166
  }
143
- const location = this.getLocation(key);
167
+ const location = meta.newKey ? this.getLocation(meta.newKey) : this.getLocation(key);
144
168
  return {
145
- key,
169
+ key: meta.newKey ?? key,
146
170
  location,
147
- value: this.getPropertyValue(key),
148
- path: this.getPath(key),
149
- isLocal: () => location === "Local" /* LOCAL */,
150
- isGlobal: () => location === "Global" /* GLOBAL */,
151
- isEnvVar: () => location === "Environment" /* ENVIRONMENT */,
152
- deprecated: (_a = meta.deprecated) !== null && _a !== void 0 ? _a : false,
171
+ value: this.getPropertyValue(meta.newKey ?? key),
172
+ path: this.getPath(meta.newKey ?? key),
173
+ isLocal: () => location === "Local" /* ConfigAggregator.Location.LOCAL */,
174
+ isGlobal: () => location === "Global" /* ConfigAggregator.Location.GLOBAL */,
175
+ isEnvVar: () => location === "Environment" /* ConfigAggregator.Location.ENVIRONMENT */,
176
+ deprecated: meta.deprecated ?? false,
153
177
  };
154
178
  }
155
179
  /**
@@ -163,23 +187,24 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
163
187
  * @param key The key of the property.
164
188
  */
165
189
  getLocation(key) {
166
- if (this.getEnvVars().get(key) != null) {
167
- return "Environment" /* ENVIRONMENT */;
190
+ // envs populate old and new automatically
191
+ if (this.envVars[key] != null) {
192
+ return "Environment" /* ConfigAggregator.Location.ENVIRONMENT */;
168
193
  }
169
- if (this.localConfig && this.localConfig.get(key)) {
170
- return "Local" /* LOCAL */;
194
+ if (this.localConfig?.get(key)) {
195
+ return "Local" /* ConfigAggregator.Location.LOCAL */;
171
196
  }
172
- if (this.globalConfig && this.globalConfig.get(key)) {
173
- return "Global" /* GLOBAL */;
197
+ if (this.globalConfig?.get(key)) {
198
+ return "Global" /* ConfigAggregator.Location.GLOBAL */;
174
199
  }
175
200
  }
176
201
  /**
177
202
  * Get a resolved file path or environment variable name of the property.
178
203
  *
179
204
  * 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.
205
+ * 1. `$SF_LOG_LEVEL` if resolved to an environment variable.
206
+ * 1. `./.sf/config.json` if resolved to the local config.
207
+ * 1. `~/.sf/config.json` if resolved to the global config.
183
208
  * 1. `undefined`, if not resolved.
184
209
  *
185
210
  * **Note:** that the path returned may be the absolute path instead of
@@ -188,10 +213,11 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
188
213
  * @param key The key of the property.
189
214
  */
190
215
  getPath(key) {
191
- if (this.envVars.getString(key) != null) {
192
- return `$${propertyToEnvName(key)}`;
216
+ // TODO: make EnvVars always prefer the "new" regardless of CLI
217
+ if (this.envVars[key] != null) {
218
+ return `$${envVars_1.EnvVars.propertyToEnvName(key)}`;
193
219
  }
194
- if (this.localConfig && this.localConfig.getContents()[key] != null) {
220
+ if (this.localConfig?.getContents()[key] != null) {
195
221
  return this.localConfig.getPath();
196
222
  }
197
223
  if (this.globalConfig.getContents()[key] != null) {
@@ -204,14 +230,14 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
204
230
  * ```
205
231
  * > console.log(aggregator.getConfigInfo());
206
232
  * [
207
- * { key: 'logLevel', val: 'INFO', location: 'Environment', path: '$SFDX_LOG_LEVEL'}
233
+ * { key: 'logLevel', val: 'INFO', location: 'Environment', path: '$SF_LOG_LEVEL'}
208
234
  * { key: 'target-org', val: '<username>', location: 'Local', path: './.sf/config.json'}
209
235
  * ]
210
236
  * ```
211
237
  */
212
238
  getConfigInfo() {
213
239
  const infos = Object.keys(this.getConfig())
214
- .filter((key) => this.getAllowedProperties().some((element) => key === element.key))
240
+ .filter((key) => this.getAllowedProperties().some((element) => key === element.key || key === element.newKey))
215
241
  .map((key) => this.getInfo(key))
216
242
  .filter((info) => !!info);
217
243
  return (0, kit_1.sortBy)(infos, 'key');
@@ -238,7 +264,7 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
238
264
  * Get the config properties that are environment variables.
239
265
  */
240
266
  getEnvVars() {
241
- return this.envVars.asMap();
267
+ return this.envVars;
242
268
  }
243
269
  /**
244
270
  * Re-read all property configurations from disk.
@@ -258,6 +284,20 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
258
284
  this.allowedProperties.push(configMetas);
259
285
  }
260
286
  }
287
+ /**
288
+ * Set the allowed properties.
289
+ *
290
+ * @param properties The properties to set.
291
+ */
292
+ setAllowedProperties(properties) {
293
+ this.allowedProperties = properties;
294
+ }
295
+ /**
296
+ * Get the allowed properties.
297
+ */
298
+ getAllowedProperties() {
299
+ return this.allowedProperties;
300
+ }
261
301
  /**
262
302
  * Loads all the properties and aggregates them according to location.
263
303
  */
@@ -269,12 +309,15 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
269
309
  * Loads all the properties and aggregates them according to location.
270
310
  */
271
311
  loadPropertiesSync() {
272
- this.resolveProperties(this.globalConfig.readSync(), this.localConfig && this.localConfig.readSync());
312
+ this.resolveProperties(this.globalConfig.readSync(), this.localConfig?.readSync());
273
313
  }
274
314
  resolveProperties(globalConfig, localConfig) {
275
- this.envVars = new envVars_1.EnvVars();
315
+ const envVars = new envVars_1.EnvVars();
276
316
  for (const property of this.getAllowedProperties()) {
277
- this.envVars.setPropertyFromEnv(property.key);
317
+ const key = property.newKey ? property.newKey : property.key;
318
+ const value = envVars.getPropertyFromEnv(property.key);
319
+ if (value)
320
+ this.envVars[key] = value;
278
321
  }
279
322
  // Global config must be read first so it is on the left hand of the
280
323
  // object assign and is overwritten by the local config.
@@ -283,25 +326,11 @@ class ConfigAggregator extends kit_1.AsyncOptionalCreatable {
283
326
  if (localConfig) {
284
327
  configs.push(localConfig);
285
328
  }
286
- configs.push(this.envVars.asDictionary());
329
+ configs.push(this.envVars);
287
330
  const json = {};
288
331
  const reduced = configs.filter(ts_types_1.isJsonMap).reduce((acc, el) => (0, kit_1.merge)(acc, el), json);
289
332
  return reduced;
290
333
  }
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
334
  }
306
335
  exports.ConfigAggregator = ConfigAggregator;
307
336
  ConfigAggregator.encrypted = true;
@@ -78,7 +78,7 @@ export declare class ConfigFile<T extends ConfigFile.Options = ConfigFile.Option
78
78
  * Read the config file and set the config contents. Returns the config contents of the config file. As an
79
79
  * optimization, files are only read once per process and updated in memory and via `write()`. To force
80
80
  * a read from the filesystem pass `force=true`.
81
- * **Throws** *{@link SfdxError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file.
81
+ * **Throws** *{@link SfError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file.
82
82
  *
83
83
  * @param [throwOnNotFound = false] Optionally indicate if a throw should occur on file read.
84
84
  * @param [force = false] Optionally force the file to be read from disk even when already read within the process.
@@ -88,7 +88,7 @@ export declare class ConfigFile<T extends ConfigFile.Options = ConfigFile.Option
88
88
  * Read the config file and set the config contents. Returns the config contents of the config file. As an
89
89
  * optimization, files are only read once per process and updated in memory and via `write()`. To force
90
90
  * a read from the filesystem pass `force=true`.
91
- * **Throws** *{@link SfdxError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file.
91
+ * **Throws** *{@link SfError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file.
92
92
  *
93
93
  * @param [throwOnNotFound = false] Optionally indicate if a throw should occur on file read.
94
94
  * @param [force = false] Optionally force the file to be read from disk even when already read within the process.
@@ -7,14 +7,15 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.ConfigFile = void 0;
10
+ const fs = require("fs");
10
11
  const fs_1 = require("fs");
11
12
  const os_1 = require("os");
12
13
  const path_1 = require("path");
13
14
  const ts_types_1 = require("@salesforce/ts-types");
15
+ const kit_1 = require("@salesforce/kit");
14
16
  const global_1 = require("../global");
15
17
  const logger_1 = require("../logger");
16
- const sfdxError_1 = require("../sfdxError");
17
- const fs_2 = require("../util/fs");
18
+ const sfError_1 = require("../sfError");
18
19
  const internal_1 = require("../util/internal");
19
20
  const configStore_1 = require("./configStore");
20
21
  /**
@@ -65,7 +66,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
65
66
  */
66
67
  static getFileName() {
67
68
  // Can not have abstract static methods, so throw a runtime error.
68
- throw new sfdxError_1.SfdxError('Unknown filename for config file.');
69
+ throw new sfError_1.SfError('Unknown filename for config file.');
69
70
  }
70
71
  /**
71
72
  * Returns the default options for the config file.
@@ -77,8 +78,8 @@ class ConfigFile extends configStore_1.BaseConfigStore {
77
78
  return {
78
79
  isGlobal,
79
80
  isState: true,
80
- filename: filename || this.getFileName(),
81
- stateFolder: global_1.Global.SF_STATE_FOLDER,
81
+ filename: filename ?? this.getFileName(),
82
+ stateFolder: global_1.Global.SFDX_STATE_FOLDER,
82
83
  };
83
84
  }
84
85
  /**
@@ -87,7 +88,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
87
88
  * @param isGlobal True if the config should be global. False for local.
88
89
  */
89
90
  static async resolveRootFolder(isGlobal) {
90
- return isGlobal ? (0, os_1.homedir)() : await (0, internal_1.resolveProjectPath)();
91
+ return isGlobal ? (0, os_1.homedir)() : (0, internal_1.resolveProjectPath)();
91
92
  }
92
93
  /**
93
94
  * Helper used to determine what the local and global folder point to. Returns the file path of the root folder.
@@ -107,7 +108,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
107
108
  */
108
109
  async access(perm) {
109
110
  try {
110
- await fs_2.fs.access(this.getPath(), perm);
111
+ await fs.promises.access(this.getPath(), perm);
111
112
  return true;
112
113
  }
113
114
  catch (err) {
@@ -124,7 +125,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
124
125
  */
125
126
  accessSync(perm) {
126
127
  try {
127
- fs_2.fs.accessSync(this.getPath(), perm);
128
+ fs.accessSync(this.getPath(), perm);
128
129
  return true;
129
130
  }
130
131
  catch (err) {
@@ -135,7 +136,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
135
136
  * Read the config file and set the config contents. Returns the config contents of the config file. As an
136
137
  * optimization, files are only read once per process and updated in memory and via `write()`. To force
137
138
  * a read from the filesystem pass `force=true`.
138
- * **Throws** *{@link SfdxError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file.
139
+ * **Throws** *{@link SfError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file.
139
140
  *
140
141
  * @param [throwOnNotFound = false] Optionally indicate if a throw should occur on file read.
141
142
  * @param [force = false] Optionally force the file to be read from disk even when already read within the process.
@@ -146,7 +147,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
146
147
  // internally and updated persistently via write().
147
148
  if (!this.hasRead || force) {
148
149
  this.logger.info(`Reading config file: ${this.getPath()}`);
149
- const obj = await fs_2.fs.readJsonMap(this.getPath());
150
+ const obj = (0, kit_1.parseJsonMap)(await fs.promises.readFile(this.getPath(), 'utf8'));
150
151
  this.setContentsFromObject(obj);
151
152
  }
152
153
  return this.getContents();
@@ -170,7 +171,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
170
171
  * Read the config file and set the config contents. Returns the config contents of the config file. As an
171
172
  * optimization, files are only read once per process and updated in memory and via `write()`. To force
172
173
  * a read from the filesystem pass `force=true`.
173
- * **Throws** *{@link SfdxError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file.
174
+ * **Throws** *{@link SfError}{ name: 'UnexpectedJsonFileFormat' }* There was a problem reading or parsing the file.
174
175
  *
175
176
  * @param [throwOnNotFound = false] Optionally indicate if a throw should occur on file read.
176
177
  * @param [force = false] Optionally force the file to be read from disk even when already read within the process.
@@ -181,7 +182,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
181
182
  // internally and updated persistently via write().
182
183
  if (!this.hasRead || force) {
183
184
  this.logger.info(`Reading config file: ${this.getPath()}`);
184
- const obj = fs_2.fs.readJsonMapSync(this.getPath());
185
+ const obj = (0, kit_1.parseJsonMap)(fs.readFileSync(this.getPath(), 'utf8'));
185
186
  this.setContentsFromObject(obj);
186
187
  }
187
188
  return this.getContents();
@@ -211,9 +212,14 @@ class ConfigFile extends configStore_1.BaseConfigStore {
211
212
  if (newContents) {
212
213
  this.setContents(newContents);
213
214
  }
214
- await fs_2.fs.mkdirp((0, path_1.dirname)(this.getPath()));
215
+ try {
216
+ await fs.promises.mkdir((0, path_1.dirname)(this.getPath()), { recursive: true });
217
+ }
218
+ catch (err) {
219
+ throw sfError_1.SfError.wrap(err);
220
+ }
215
221
  this.logger.info(`Writing to config file: ${this.getPath()}`);
216
- await fs_2.fs.writeJson(this.getPath(), this.toObject());
222
+ await fs.promises.writeFile(this.getPath(), JSON.stringify(this.toObject(), null, 2));
217
223
  return this.getContents();
218
224
  }
219
225
  /**
@@ -226,16 +232,21 @@ class ConfigFile extends configStore_1.BaseConfigStore {
226
232
  if ((0, ts_types_1.isPlainObject)(newContents)) {
227
233
  this.setContents(newContents);
228
234
  }
229
- fs_2.fs.mkdirpSync((0, path_1.dirname)(this.getPath()));
235
+ try {
236
+ fs.mkdirSync((0, path_1.dirname)(this.getPath()), { recursive: true });
237
+ }
238
+ catch (err) {
239
+ throw sfError_1.SfError.wrap(err);
240
+ }
230
241
  this.logger.info(`Writing to config file: ${this.getPath()}`);
231
- fs_2.fs.writeJsonSync(this.getPath(), this.toObject());
242
+ fs.writeFileSync(this.getPath(), JSON.stringify(this.toObject(), null, 2));
232
243
  return this.getContents();
233
244
  }
234
245
  /**
235
246
  * Check to see if the config file exists. Returns `true` if the config file exists and has access, false otherwise.
236
247
  */
237
248
  async exists() {
238
- return await this.access(fs_1.constants.R_OK);
249
+ return this.access(fs_1.constants.R_OK);
239
250
  }
240
251
  /**
241
252
  * Check to see if the config file exists. Returns `true` if the config file exists and has access, false otherwise.
@@ -249,7 +260,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
249
260
  * {@link fs.stat}
250
261
  */
251
262
  async stat() {
252
- return fs_2.fs.stat(this.getPath());
263
+ return fs.promises.stat(this.getPath());
253
264
  }
254
265
  /**
255
266
  * Get the stats of the file. Returns the stats of the file.
@@ -257,7 +268,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
257
268
  * {@link fs.stat}
258
269
  */
259
270
  statSync() {
260
- return fs_2.fs.statSync(this.getPath());
271
+ return fs.statSync(this.getPath());
261
272
  }
262
273
  /**
263
274
  * Delete the config file if it exists.
@@ -268,9 +279,9 @@ class ConfigFile extends configStore_1.BaseConfigStore {
268
279
  async unlink() {
269
280
  const exists = await this.exists();
270
281
  if (exists) {
271
- return await fs_2.fs.unlink(this.getPath());
282
+ return fs.promises.unlink(this.getPath());
272
283
  }
273
- throw new sfdxError_1.SfdxError(`Target file doesn't exist. path: ${this.getPath()}`, 'TargetFileNotFound');
284
+ throw new sfError_1.SfError(`Target file doesn't exist. path: ${this.getPath()}`, 'TargetFileNotFound');
274
285
  }
275
286
  /**
276
287
  * Delete the config file if it exists.
@@ -281,9 +292,9 @@ class ConfigFile extends configStore_1.BaseConfigStore {
281
292
  unlinkSync() {
282
293
  const exists = this.existsSync();
283
294
  if (exists) {
284
- return fs_2.fs.unlinkSync(this.getPath());
295
+ return fs.unlinkSync(this.getPath());
285
296
  }
286
- throw new sfdxError_1.SfdxError(`Target file doesn't exist. path: ${this.getPath()}`, 'TargetFileNotFound');
297
+ throw new sfError_1.SfError(`Target file doesn't exist. path: ${this.getPath()}`, 'TargetFileNotFound');
287
298
  }
288
299
  /**
289
300
  * Returns the absolute path to the config file.
@@ -295,16 +306,14 @@ class ConfigFile extends configStore_1.BaseConfigStore {
295
306
  getPath() {
296
307
  if (!this.path) {
297
308
  if (!this.options.filename) {
298
- throw new sfdxError_1.SfdxError('The ConfigOptions filename parameter is invalid.', 'InvalidParameter');
309
+ throw new sfError_1.SfError('The ConfigOptions filename parameter is invalid.', 'InvalidParameter');
299
310
  }
300
- const _isGlobal = (0, ts_types_1.isBoolean)(this.options.isGlobal) && this.options.isGlobal;
301
- const _isState = (0, ts_types_1.isBoolean)(this.options.isState) && this.options.isState;
302
311
  // Don't let users store config files in homedir without being in the state folder.
303
312
  let configRootFolder = this.options.rootFolder
304
313
  ? this.options.rootFolder
305
- : ConfigFile.resolveRootFolderSync(!!this.options.isGlobal);
306
- if (_isGlobal || _isState) {
307
- configRootFolder = (0, path_1.join)(configRootFolder, this.options.stateFolder || global_1.Global.SFDX_STATE_FOLDER);
314
+ : ConfigFile.resolveRootFolderSync(Boolean(this.options.isGlobal));
315
+ if (this.options.isGlobal === true || this.options.isState === true) {
316
+ configRootFolder = (0, path_1.join)(configRootFolder, this.options.stateFolder ?? global_1.Global.SFDX_STATE_FOLDER);
308
317
  }
309
318
  this.path = (0, path_1.join)(configRootFolder, this.options.filePath ? this.options.filePath : '', this.options.filename);
310
319
  }