@salesforce/core 4.0.0-v3.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 (160) 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 +181 -48
  8. package/lib/config/config.js +382 -159
  9. package/lib/config/configAggregator.d.ts +59 -42
  10. package/lib/config/configAggregator.js +135 -82
  11. package/lib/config/configFile.d.ts +2 -2
  12. package/lib/config/configFile.js +40 -31
  13. package/lib/config/configGroup.d.ts +9 -9
  14. package/lib/config/configGroup.js +13 -11
  15. package/lib/config/configStore.d.ts +9 -9
  16. package/lib/config/configStore.js +29 -26
  17. package/lib/config/envVars.d.ts +102 -0
  18. package/lib/config/envVars.js +457 -0
  19. package/lib/config/orgUsersConfig.d.ts +8 -0
  20. package/lib/config/orgUsersConfig.js +12 -0
  21. package/lib/config/sandboxOrgConfig.d.ts +8 -0
  22. package/lib/config/sandboxOrgConfig.js +12 -0
  23. package/lib/config/sandboxProcessCache.d.ts +16 -0
  24. package/lib/config/sandboxProcessCache.js +38 -0
  25. package/lib/config/tokensConfig.d.ts +10 -0
  26. package/lib/config/tokensConfig.js +29 -0
  27. package/lib/config/ttlConfig.d.ts +34 -0
  28. package/lib/config/ttlConfig.js +50 -0
  29. package/lib/crypto/crypto.js +29 -16
  30. package/lib/crypto/keyChain.js +4 -4
  31. package/lib/crypto/keyChainImpl.d.ts +5 -3
  32. package/lib/crypto/keyChainImpl.js +65 -66
  33. package/lib/crypto/secureBuffer.d.ts +1 -1
  34. package/lib/crypto/secureBuffer.js +1 -1
  35. package/lib/deviceOauthService.d.ts +5 -5
  36. package/lib/deviceOauthService.js +37 -33
  37. package/lib/exported.d.ts +22 -15
  38. package/lib/exported.js +49 -25
  39. package/lib/global.d.ts +17 -3
  40. package/lib/global.js +46 -13
  41. package/lib/lifecycleEvents.d.ts +39 -2
  42. package/lib/lifecycleEvents.js +77 -3
  43. package/lib/logger.d.ts +21 -11
  44. package/lib/logger.js +121 -105
  45. package/lib/messages.d.ts +53 -36
  46. package/lib/messages.js +89 -97
  47. package/lib/org/authInfo.d.ts +84 -72
  48. package/lib/org/authInfo.js +326 -320
  49. package/lib/org/authRemover.d.ts +16 -23
  50. package/lib/org/authRemover.js +62 -60
  51. package/lib/org/connection.d.ts +33 -59
  52. package/lib/org/connection.js +129 -190
  53. package/lib/org/index.js +6 -2
  54. package/lib/org/org.d.ts +263 -38
  55. package/lib/org/org.js +734 -149
  56. package/lib/org/orgConfigProperties.d.ts +69 -0
  57. package/lib/org/orgConfigProperties.js +121 -0
  58. package/lib/org/permissionSetAssignment.js +6 -15
  59. package/lib/org/scratchOrgCache.d.ts +20 -0
  60. package/lib/org/scratchOrgCache.js +33 -0
  61. package/lib/org/scratchOrgCreate.d.ts +54 -0
  62. package/lib/org/scratchOrgCreate.js +214 -0
  63. package/lib/org/scratchOrgErrorCodes.d.ts +10 -0
  64. package/lib/org/scratchOrgErrorCodes.js +79 -0
  65. package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -0
  66. package/lib/org/scratchOrgFeatureDeprecation.js +105 -0
  67. package/lib/org/scratchOrgInfoApi.d.ts +68 -0
  68. package/lib/org/scratchOrgInfoApi.js +416 -0
  69. package/lib/org/scratchOrgInfoGenerator.d.ts +64 -0
  70. package/lib/org/scratchOrgInfoGenerator.js +237 -0
  71. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
  72. package/lib/org/scratchOrgLifecycleEvents.js +41 -0
  73. package/lib/org/scratchOrgSettingsGenerator.d.ts +79 -0
  74. package/lib/org/scratchOrgSettingsGenerator.js +277 -0
  75. package/lib/org/scratchOrgTypes.d.ts +43 -0
  76. package/lib/{status/client.js → org/scratchOrgTypes.js} +1 -1
  77. package/lib/org/user.d.ts +7 -2
  78. package/lib/org/user.js +78 -54
  79. package/lib/schema/printer.d.ts +6 -0
  80. package/lib/schema/printer.js +49 -46
  81. package/lib/schema/validator.d.ts +12 -10
  82. package/lib/schema/validator.js +56 -76
  83. package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -15
  84. package/lib/{sfdxError.js → sfError.js} +42 -24
  85. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
  86. package/lib/sfProject.js +651 -0
  87. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -0
  88. package/lib/stateAggregator/accessors/aliasAccessor.js +146 -0
  89. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
  90. package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
  91. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
  92. package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
  93. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
  94. package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
  95. package/lib/stateAggregator/index.d.ts +4 -0
  96. package/lib/stateAggregator/index.js +27 -0
  97. package/lib/stateAggregator/stateAggregator.d.ts +25 -0
  98. package/lib/stateAggregator/stateAggregator.js +46 -0
  99. package/lib/status/myDomainResolver.d.ts +1 -1
  100. package/lib/status/myDomainResolver.js +10 -10
  101. package/lib/status/pollingClient.d.ts +2 -6
  102. package/lib/status/pollingClient.js +38 -64
  103. package/lib/status/streamingClient.d.ts +5 -80
  104. package/lib/status/streamingClient.js +74 -94
  105. package/lib/status/types.d.ts +89 -0
  106. package/lib/status/types.js +18 -0
  107. package/lib/testSetup.d.ts +212 -79
  108. package/lib/testSetup.js +478 -182
  109. package/lib/util/cache.d.ts +11 -0
  110. package/lib/util/cache.js +70 -0
  111. package/lib/util/checkLightningDomain.d.ts +1 -0
  112. package/lib/util/checkLightningDomain.js +29 -0
  113. package/lib/util/directoryWriter.d.ts +12 -0
  114. package/lib/util/directoryWriter.js +54 -0
  115. package/lib/util/getJwtAudienceUrl.d.ts +4 -0
  116. package/lib/util/getJwtAudienceUrl.js +19 -0
  117. package/lib/util/internal.d.ts +28 -2
  118. package/lib/util/internal.js +65 -8
  119. package/lib/util/jsonXmlTools.d.ts +14 -0
  120. package/lib/util/jsonXmlTools.js +39 -0
  121. package/lib/util/mapKeys.d.ts +14 -0
  122. package/lib/util/mapKeys.js +52 -0
  123. package/lib/util/sfdc.d.ts +51 -63
  124. package/lib/util/sfdc.js +75 -127
  125. package/lib/util/sfdcUrl.d.ts +64 -0
  126. package/lib/util/sfdcUrl.js +197 -0
  127. package/lib/util/structuredWriter.d.ts +9 -0
  128. package/lib/util/structuredWriter.js +3 -0
  129. package/lib/util/zipWriter.d.ts +16 -0
  130. package/lib/util/zipWriter.js +68 -0
  131. package/lib/webOAuthServer.d.ts +20 -7
  132. package/lib/webOAuthServer.js +107 -60
  133. package/messageTransformer/messageTransformer.ts +93 -0
  134. package/messages/auth.md +11 -3
  135. package/messages/config.md +94 -6
  136. package/messages/connection.md +8 -0
  137. package/messages/core.json +3 -3
  138. package/messages/core.md +11 -1
  139. package/messages/envVars.md +313 -0
  140. package/messages/org.md +64 -0
  141. package/messages/scratchOrgCreate.md +23 -0
  142. package/messages/scratchOrgErrorCodes.md +115 -0
  143. package/messages/scratchOrgFeatureDeprecation.md +11 -0
  144. package/messages/scratchOrgInfoApi.md +20 -0
  145. package/messages/scratchOrgInfoGenerator.md +27 -0
  146. package/messages/user.md +12 -0
  147. package/package.json +138 -66
  148. package/CHANGELOG.md +0 -699
  149. package/lib/config/aliases.d.ts +0 -56
  150. package/lib/config/aliases.js +0 -96
  151. package/lib/config/globalInfoConfig.d.ts +0 -74
  152. package/lib/config/globalInfoConfig.js +0 -144
  153. package/lib/config/keychainConfig.d.ts +0 -19
  154. package/lib/config/keychainConfig.js +0 -43
  155. package/lib/config/sfdxDataHandler.d.ts +0 -36
  156. package/lib/config/sfdxDataHandler.js +0 -165
  157. package/lib/sfdxProject.js +0 -546
  158. package/lib/status/client.d.ts +0 -15
  159. package/lib/util/fs.d.ts +0 -198
  160. package/lib/util/fs.js +0 -374
@@ -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,7 +78,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
77
78
  return {
78
79
  isGlobal,
79
80
  isState: true,
80
- filename: filename || this.getFileName(),
81
+ filename: filename ?? this.getFileName(),
81
82
  stateFolder: global_1.Global.SFDX_STATE_FOLDER,
82
83
  };
83
84
  }
@@ -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 ? os_1.homedir() : await 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.
@@ -95,7 +96,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
95
96
  * @param isGlobal True if the config should be global. False for local.
96
97
  */
97
98
  static resolveRootFolderSync(isGlobal) {
98
- return isGlobal ? os_1.homedir() : internal_1.resolveProjectPathSync();
99
+ return isGlobal ? (0, os_1.homedir)() : (0, internal_1.resolveProjectPathSync)();
99
100
  }
100
101
  /**
101
102
  * Determines if the config file is read/write accessible. Returns `true` if the user has capabilities specified
@@ -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(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
  /**
@@ -223,19 +229,24 @@ class ConfigFile extends configStore_1.BaseConfigStore {
223
229
  * @param newContents The new contents of the file.
224
230
  */
225
231
  writeSync(newContents) {
226
- if (ts_types_1.isPlainObject(newContents)) {
232
+ if ((0, ts_types_1.isPlainObject)(newContents)) {
227
233
  this.setContents(newContents);
228
234
  }
229
- fs_2.fs.mkdirpSync(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,18 +306,16 @@ 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 = ts_types_1.isBoolean(this.options.isGlobal) && this.options.isGlobal;
301
- const _isState = 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 = 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
- this.path = path_1.join(configRootFolder, this.options.filePath ? this.options.filePath : '', this.options.filename);
318
+ this.path = (0, path_1.join)(configRootFolder, this.options.filePath ? this.options.filePath : '', this.options.filename);
310
319
  }
311
320
  return this.path;
312
321
  }
@@ -1,6 +1,6 @@
1
1
  import { Dictionary, JsonMap, Optional } from '@salesforce/ts-types';
2
2
  import { ConfigFile } from './configFile';
3
- import { ConfigContents, ConfigEntry, ConfigValue, Key } from './configStore';
3
+ import { ConfigContents, ConfigEntry, ConfigValue } from './configStore';
4
4
  /**
5
5
  * A config file that stores config values in groups. e.g. to store different config
6
6
  * values for different commands, without having manually manipulate the config.
@@ -20,8 +20,8 @@ import { ConfigContents, ConfigEntry, ConfigValue, Key } from './configStore';
20
20
  * await myConfig.write();
21
21
  * ```
22
22
  */
23
- export declare class ConfigGroup<T extends ConfigGroup.Options = ConfigGroup.Options, P extends ConfigContents = ConfigContents> extends ConfigFile<T, P> {
24
- protected defaultGroup: Extract<keyof P, string>;
23
+ export declare class ConfigGroup<T extends ConfigGroup.Options> extends ConfigFile<T> {
24
+ protected defaultGroup: string;
25
25
  /**
26
26
  * Get ConfigGroup specific options, such as the default group.
27
27
  *
@@ -31,11 +31,11 @@ export declare class ConfigGroup<T extends ConfigGroup.Options = ConfigGroup.Opt
31
31
  static getOptions(defaultGroup: string, filename?: string): ConfigGroup.Options;
32
32
  /**
33
33
  * Sets the default group for all {@link BaseConfigStore} methods to use.
34
- * **Throws** *{@link SfdxError}{ name: 'MissingGroupNameError' }* The group parameter is null or undefined.
34
+ * **Throws** *{@link SfError}{ name: 'MissingGroupName' }* The group parameter is null or undefined.
35
35
  *
36
36
  * @param group The group.
37
37
  */
38
- setDefaultGroup(group: Key<P>): void;
38
+ setDefaultGroup(group: string): void;
39
39
  /**
40
40
  * Set a group of entries in a bulk save. Returns The new properties that were saved.
41
41
  *
@@ -60,7 +60,7 @@ export declare class ConfigGroup<T extends ConfigGroup.Options = ConfigGroup.Opt
60
60
  *
61
61
  * @param key The key.
62
62
  */
63
- get<K extends Extract<keyof P, string>>(key: string): P[K];
63
+ get(key: string): Optional<ConfigValue>;
64
64
  /**
65
65
  * Returns a boolean if an element with the specified key exists in the default group.
66
66
  *
@@ -70,7 +70,7 @@ export declare class ConfigGroup<T extends ConfigGroup.Options = ConfigGroup.Opt
70
70
  /**
71
71
  * Returns an array of the keys from the default group.
72
72
  */
73
- keys(): Array<Key<P>>;
73
+ keys(): string[];
74
74
  /**
75
75
  * Returns an array of the values from the default group.
76
76
  */
@@ -81,7 +81,7 @@ export declare class ConfigGroup<T extends ConfigGroup.Options = ConfigGroup.Opt
81
81
  * @param key The key.
82
82
  * @param value The value.
83
83
  */
84
- set<K extends Extract<keyof P, string>>(key: K, value: P[K]): P;
84
+ set(key: string, value: ConfigValue): ConfigContents;
85
85
  /**
86
86
  * Removes an element with the specified key from the default group. Returns `true` if the item was deleted.
87
87
  *
@@ -97,7 +97,7 @@ export declare class ConfigGroup<T extends ConfigGroup.Options = ConfigGroup.Opt
97
97
  *
98
98
  * @param {string} [group = 'default'] The group.
99
99
  */
100
- getGroup(group?: Extract<keyof P, string>): Optional<ConfigContents>;
100
+ getGroup(group?: string): Optional<ConfigContents>;
101
101
  /**
102
102
  * Returns the value associated to the key and group, or undefined if there is none.
103
103
  *
@@ -8,7 +8,7 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.ConfigGroup = void 0;
10
10
  const ts_types_1 = require("@salesforce/ts-types");
11
- const sfdxError_1 = require("../sfdxError");
11
+ const sfError_1 = require("../sfError");
12
12
  const configFile_1 = require("./configFile");
13
13
  /**
14
14
  * A config file that stores config values in groups. e.g. to store different config
@@ -48,13 +48,13 @@ class ConfigGroup extends configFile_1.ConfigFile {
48
48
  }
49
49
  /**
50
50
  * Sets the default group for all {@link BaseConfigStore} methods to use.
51
- * **Throws** *{@link SfdxError}{ name: 'MissingGroupNameError' }* The group parameter is null or undefined.
51
+ * **Throws** *{@link SfError}{ name: 'MissingGroupName' }* The group parameter is null or undefined.
52
52
  *
53
53
  * @param group The group.
54
54
  */
55
55
  setDefaultGroup(group) {
56
56
  if (!group) {
57
- throw new sfdxError_1.SfdxError('null or undefined group', 'MissingGroupNameError');
57
+ throw new sfError_1.SfError('null or undefined group', 'MissingGroupName');
58
58
  }
59
59
  this.defaultGroup = group;
60
60
  }
@@ -67,7 +67,7 @@ class ConfigGroup extends configFile_1.ConfigFile {
67
67
  async updateValues(newEntries, group) {
68
68
  // Make sure the contents are loaded
69
69
  await this.read();
70
- Object.entries(newEntries).forEach(([key, val]) => this.setInGroup(key, val, group || this.defaultGroup));
70
+ Object.entries(newEntries).forEach(([key, val]) => this.setInGroup(key, val, group ?? this.defaultGroup));
71
71
  await this.write();
72
72
  return newEntries;
73
73
  }
@@ -81,7 +81,7 @@ class ConfigGroup extends configFile_1.ConfigFile {
81
81
  async updateValue(key, value, group) {
82
82
  // Make sure the content is loaded
83
83
  await this.read();
84
- this.setInGroup(key, value, group || this.defaultGroup);
84
+ this.setInGroup(key, value, group ?? this.defaultGroup);
85
85
  // Then save it
86
86
  await this.write();
87
87
  }
@@ -91,7 +91,7 @@ class ConfigGroup extends configFile_1.ConfigFile {
91
91
  entries() {
92
92
  const group = this.getGroup();
93
93
  if (group) {
94
- return ts_types_1.definiteEntriesOf(group);
94
+ return (0, ts_types_1.definiteEntriesOf)(group);
95
95
  }
96
96
  return [];
97
97
  }
@@ -116,13 +116,13 @@ class ConfigGroup extends configFile_1.ConfigFile {
116
116
  * Returns an array of the keys from the default group.
117
117
  */
118
118
  keys() {
119
- return Object.keys(this.getGroup(this.defaultGroup) || {});
119
+ return Object.keys(this.getGroup(this.defaultGroup) ?? {});
120
120
  }
121
121
  /**
122
122
  * Returns an array of the values from the default group.
123
123
  */
124
124
  values() {
125
- return ts_types_1.definiteValuesOf(this.getGroup(this.defaultGroup) || {});
125
+ return (0, ts_types_1.definiteValuesOf)(this.getGroup(this.defaultGroup) ?? {});
126
126
  }
127
127
  /**
128
128
  * Add or updates an element with the specified key in the default group.
@@ -158,7 +158,7 @@ class ConfigGroup extends configFile_1.ConfigFile {
158
158
  * @param {string} [group = 'default'] The group.
159
159
  */
160
160
  getGroup(group = this.defaultGroup) {
161
- return ts_types_1.getJsonMap(this.getContents(), group) || undefined;
161
+ return (0, ts_types_1.getJsonMap)(this.getContents(), group) ?? undefined;
162
162
  }
163
163
  /**
164
164
  * Returns the value associated to the key and group, or undefined if there is none.
@@ -183,11 +183,13 @@ class ConfigGroup extends configFile_1.ConfigFile {
183
183
  *
184
184
  * @param {object} obj The object.
185
185
  */
186
+ // eslint-disable-next-line @typescript-eslint/ban-types
186
187
  setContentsFromObject(obj) {
187
188
  const contents = new Map(Object.entries(obj));
188
189
  Array.from(contents.entries()).forEach(([groupKey, groupContents]) => {
189
190
  if (groupContents) {
190
191
  Object.entries(groupContents).forEach(([contentKey, contentValue]) => {
192
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
191
193
  this.setInGroup(contentKey, contentValue, groupKey);
192
194
  });
193
195
  }
@@ -201,11 +203,11 @@ class ConfigGroup extends configFile_1.ConfigFile {
201
203
  * @param group The group. Uses the default group if not specified.
202
204
  */
203
205
  setInGroup(key, value, group) {
204
- group = group || this.defaultGroup;
206
+ group = group ?? this.defaultGroup;
205
207
  if (!super.has(group)) {
206
208
  super.set(group, {});
207
209
  }
208
- const content = this.getGroup(group) || {};
210
+ const content = this.getGroup(group) ?? {};
209
211
  this.setMethod(content, key, value);
210
212
  return content;
211
213
  }
@@ -4,16 +4,16 @@ import { Crypto } from '../crypto/crypto';
4
4
  /**
5
5
  * The allowed types stored in a config store.
6
6
  */
7
- export declare type ConfigValue = AnyJson;
7
+ export type ConfigValue = AnyJson;
8
8
  /**
9
9
  * The type of entries in a config store defined by the key and value type of {@link ConfigContents}.
10
10
  */
11
- export declare type ConfigEntry = [string, ConfigValue];
11
+ export type ConfigEntry = [string, ConfigValue];
12
12
  /**
13
13
  * The type of content a config stores.
14
14
  */
15
- export declare type ConfigContents = Dictionary<ConfigValue>;
16
- export declare type Key<P extends ConfigContents> = Extract<keyof P, string>;
15
+ export type ConfigContents<T = ConfigValue> = Dictionary<T>;
16
+ export type Key<P extends ConfigContents> = Extract<keyof P, string>;
17
17
  /**
18
18
  * An interface for a config object with a persistent store.
19
19
  */
@@ -68,7 +68,7 @@ export declare abstract class BaseConfigStore<T extends BaseConfigStore.Options
68
68
  * If the value is an object, a clone will be returned.
69
69
  */
70
70
  get<K extends Key<P>>(key: K, decrypt?: boolean): P[K];
71
- get<T = ConfigValue>(key: string, decrypt?: boolean): T;
71
+ get<V = ConfigValue>(key: string, decrypt?: boolean): V;
72
72
  /**
73
73
  * Returns the list of keys that contain a value.
74
74
  *
@@ -93,7 +93,7 @@ export declare abstract class BaseConfigStore<T extends BaseConfigStore.Options
93
93
  * @param value The value.
94
94
  */
95
95
  set<K extends Key<P>>(key: K, value: P[K]): void;
96
- set<T = ConfigValue>(key: string, value: T): void;
96
+ set<V = ConfigValue>(key: string, value: V): void;
97
97
  /**
98
98
  * Updates the value for the key in the config object. If the value is an object, it
99
99
  * will be merged with the existing object.
@@ -102,7 +102,7 @@ export declare abstract class BaseConfigStore<T extends BaseConfigStore.Options
102
102
  * @param value The value.
103
103
  */
104
104
  update<K extends Key<P>>(key: K, value: Partial<P[K]>): void;
105
- update<T = ConfigValue>(key: string, value: Partial<T>): void;
105
+ update<V = ConfigValue>(key: string, value: Partial<V>): void;
106
106
  /**
107
107
  * Returns `true` if an element in the config object existed and has been removed, or `false` if the element does not
108
108
  * exist. {@link BaseConfigStore.has} will return false afterwards.
@@ -166,7 +166,7 @@ export declare abstract class BaseConfigStore<T extends BaseConfigStore.Options
166
166
  *
167
167
  * @param obj The object.
168
168
  */
169
- setContentsFromObject<U extends object>(obj: U): void;
169
+ setContentsFromObject<U extends JsonMap>(obj: U): void;
170
170
  protected getEncryptedKeys(): Array<string | RegExp>;
171
171
  /**
172
172
  * This config file has encrypted keys and it should attempt to encrypt them.
@@ -204,7 +204,7 @@ export declare abstract class BaseConfigStore<T extends BaseConfigStore.Options
204
204
  * @param keyPaths: The complete path of the (nested) data
205
205
  * @param data: The current (nested) data being worked on.
206
206
  */
207
- protected recursiveEncrypt<T extends JsonMap>(data: T, parentKey?: string): T;
207
+ protected recursiveEncrypt<J extends JsonMap>(data: J, parentKey?: string): J;
208
208
  /**
209
209
  * Decrypt all values in a nested JsonMap.
210
210
  *
@@ -11,7 +11,7 @@ const kit_1 = require("@salesforce/kit");
11
11
  const ts_types_1 = require("@salesforce/ts-types");
12
12
  const ts_types_2 = require("@salesforce/ts-types");
13
13
  const crypto_1 = require("../crypto/crypto");
14
- const sfdxError_1 = require("../sfdxError");
14
+ const sfError_1 = require("../sfError");
15
15
  /**
16
16
  * An abstract class that implements all the config management functions but
17
17
  * none of the storage functions.
@@ -28,21 +28,21 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
28
28
  constructor(options) {
29
29
  super(options);
30
30
  this.statics = this.constructor;
31
- this.options = options || {};
31
+ this.options = options ?? {};
32
32
  this.setContents(this.initialContents());
33
33
  }
34
34
  /**
35
35
  * Returns an array of {@link ConfigEntry} for each element in the config.
36
36
  */
37
37
  entries() {
38
- return ts_types_2.definiteEntriesOf(this.contents);
38
+ return (0, ts_types_2.definiteEntriesOf)(this.contents);
39
39
  }
40
40
  get(key, decrypt = false) {
41
41
  const k = key;
42
42
  let value = this.getMethod(this.contents, k);
43
43
  if (this.hasEncryption() && decrypt) {
44
- if (ts_types_2.isJsonMap(value)) {
45
- value = this.recursiveDecrypt(kit_1.cloneJson(value), k);
44
+ if ((0, ts_types_2.isJsonMap)(value)) {
45
+ value = this.recursiveDecrypt((0, kit_1.cloneJson)(value), k);
46
46
  }
47
47
  else if (this.isCryptoKey(k)) {
48
48
  value = this.decrypt(value);
@@ -76,7 +76,7 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
76
76
  }
77
77
  set(key, value) {
78
78
  if (this.hasEncryption()) {
79
- if (ts_types_2.isJsonMap(value)) {
79
+ if ((0, ts_types_2.isJsonMap)(value)) {
80
80
  value = this.recursiveEncrypt(value, key);
81
81
  }
82
82
  else if (this.isCryptoKey(key)) {
@@ -87,7 +87,7 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
87
87
  }
88
88
  update(key, value) {
89
89
  const existingValue = this.get(key, true);
90
- if (ts_types_1.isPlainObject(existingValue) && ts_types_1.isPlainObject(value)) {
90
+ if ((0, ts_types_1.isPlainObject)(existingValue) && (0, ts_types_1.isPlainObject)(value)) {
91
91
  value = Object.assign({}, existingValue, value);
92
92
  }
93
93
  this.set(key, value);
@@ -130,7 +130,7 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
130
130
  * Returns an array that contains the values for each element in the config object.
131
131
  */
132
132
  values() {
133
- return ts_types_2.definiteValuesOf(this.contents);
133
+ return (0, ts_types_2.definiteValuesOf)(this.contents);
134
134
  }
135
135
  /**
136
136
  * Returns the entire config contents.
@@ -147,7 +147,7 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
147
147
  this.setContents();
148
148
  }
149
149
  if (this.hasEncryption() && decrypt) {
150
- return this.recursiveDecrypt(kit_1.cloneJson(this.contents));
150
+ return this.recursiveDecrypt((0, kit_1.cloneJson)(this.contents));
151
151
  }
152
152
  return this.contents;
153
153
  }
@@ -183,6 +183,8 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
183
183
  async awaitEach(actionFn) {
184
184
  const entries = this.entries();
185
185
  for (const entry of entries) {
186
+ // prevent ConfigFile collision bug
187
+ // eslint-disable-next-line no-await-in-loop
186
188
  await actionFn(entry[0], entry[1]);
187
189
  }
188
190
  }
@@ -199,13 +201,13 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
199
201
  * @param obj The object.
200
202
  */
201
203
  setContentsFromObject(obj) {
202
- this.contents = {};
204
+ this.contents = (this.hasEncryption() ? this.recursiveEncrypt(obj) : {});
203
205
  Object.entries(obj).forEach(([key, value]) => {
204
206
  this.setMethod(this.contents, key, value);
205
207
  });
206
208
  }
207
209
  getEncryptedKeys() {
208
- return [...(this.options.encryptedKeys || []), ...(this.statics.encryptedKeys || [])];
210
+ return [...(this.options?.encryptedKeys ?? []), ...(this.statics?.encryptedKeys || [])];
209
211
  }
210
212
  /**
211
213
  * This config file has encrypted keys and it should attempt to encrypt them.
@@ -217,16 +219,18 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
217
219
  }
218
220
  // Allows extended classes the ability to override the set method. i.e. maybe they want
219
221
  // nested object set from kit.
220
- // NOTE: Key and value must stay string and value to be reliably overwritten.
222
+ // eslint-disable-next-line class-methods-use-this
221
223
  setMethod(contents, key, value) {
222
- kit_1.set(contents, key, value);
224
+ (0, kit_1.set)(contents, key, value);
223
225
  }
224
226
  // Allows extended classes the ability to override the get method. i.e. maybe they want
225
227
  // nested object get from ts-types.
226
228
  // NOTE: Key must stay string to be reliably overwritten.
229
+ // eslint-disable-next-line class-methods-use-this
227
230
  getMethod(contents, key) {
228
- return ts_types_2.get(contents, key);
231
+ return (0, ts_types_2.get)(contents, key);
229
232
  }
233
+ // eslint-disable-next-line class-methods-use-this
230
234
  initialContents() {
231
235
  return {};
232
236
  }
@@ -268,7 +272,7 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
268
272
  const dotAccessor = /\.([a-zA-Z0-9@._-]+)$/;
269
273
  const singleQuoteAccessor = /\['([a-zA-Z0-9@._-]+)'\]$/;
270
274
  const doubleQuoteAccessor = /\["([a-zA-Z0-9@._-]+)"\]$/;
271
- const matcher = dotAccessor.exec(key) || singleQuoteAccessor.exec(key) || doubleQuoteAccessor.exec(key);
275
+ const matcher = dotAccessor.exec(key) ?? singleQuoteAccessor.exec(key) ?? doubleQuoteAccessor.exec(key);
272
276
  return matcher ? matcher[1] : key;
273
277
  }
274
278
  // Any keys named the following should be encrypted/decrypted
@@ -286,18 +290,18 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
286
290
  if (!value)
287
291
  return;
288
292
  if (!this.crypto)
289
- throw new sfdxError_1.SfdxError('crypto is not initialized', 'CryptoNotInitializedError');
290
- if (!ts_types_2.isString(value))
291
- throw new sfdxError_1.SfdxError(`can only encrypt strings but found: ${typeof value} : ${value}`, 'InvalidCryptoValueError');
293
+ throw new sfError_1.SfError('crypto is not initialized', 'CryptoNotInitializedError');
294
+ if (!(0, ts_types_2.isString)(value))
295
+ throw new sfError_1.SfError(`can only encrypt strings but found: ${typeof value} : ${value.toString()}`, 'InvalidCryptoValueError');
292
296
  return this.crypto.isEncrypted(value) ? value : this.crypto.encrypt(value);
293
297
  }
294
298
  decrypt(value) {
295
299
  if (!value)
296
300
  return;
297
301
  if (!this.crypto)
298
- throw new sfdxError_1.SfdxError('crypto is not initialized', 'CryptoNotInitializedError');
299
- if (!ts_types_2.isString(value))
300
- throw new sfdxError_1.SfdxError(`can only encrypt strings but found: ${typeof value} : ${value}`, 'InvalidCryptoValueError');
302
+ throw new sfError_1.SfError('crypto is not initialized', 'CryptoNotInitializedError');
303
+ if (!(0, ts_types_2.isString)(value))
304
+ throw new sfError_1.SfError(`can only encrypt strings but found: ${typeof value} : ${value.toString()}`, 'InvalidCryptoValueError');
301
305
  return this.crypto.isEncrypted(value) ? this.crypto.decrypt(value) : value;
302
306
  }
303
307
  /**
@@ -333,18 +337,17 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
333
337
  recursiveCrypto(method, keyPaths, data) {
334
338
  const key = keyPaths.pop();
335
339
  const value = data[key];
336
- if (ts_types_2.isJsonMap(value)) {
340
+ if ((0, ts_types_2.isJsonMap)(value)) {
337
341
  for (const newKey of Object.keys(value)) {
338
342
  this.recursiveCrypto(method, [...keyPaths, key, newKey], value);
339
343
  }
340
344
  }
341
- else {
342
- if (this.isCryptoKey(key)) {
343
- data[key] = method(value);
344
- }
345
+ else if (this.isCryptoKey(key)) {
346
+ data[key] = method(value);
345
347
  }
346
348
  }
347
349
  }
348
350
  exports.BaseConfigStore = BaseConfigStore;
351
+ // If encryptedKeys is an array of RegExps, they should not contain the /g (global) or /y (sticky) flags to avoid stateful issues.
349
352
  BaseConfigStore.encryptedKeys = [];
350
353
  //# sourceMappingURL=configStore.js.map