@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.
- package/LICENSE.txt +1 -1
- package/README.md +93 -44
- package/lib/config/aliasesConfig.d.ts +12 -0
- package/lib/config/aliasesConfig.js +28 -0
- package/lib/config/authInfoConfig.d.ts +19 -0
- package/lib/config/authInfoConfig.js +35 -0
- package/lib/config/config.d.ts +181 -48
- package/lib/config/config.js +382 -159
- package/lib/config/configAggregator.d.ts +59 -42
- package/lib/config/configAggregator.js +135 -82
- package/lib/config/configFile.d.ts +2 -2
- package/lib/config/configFile.js +40 -31
- package/lib/config/configGroup.d.ts +9 -9
- package/lib/config/configGroup.js +13 -11
- package/lib/config/configStore.d.ts +9 -9
- package/lib/config/configStore.js +29 -26
- package/lib/config/envVars.d.ts +102 -0
- package/lib/config/envVars.js +457 -0
- package/lib/config/orgUsersConfig.d.ts +8 -0
- package/lib/config/orgUsersConfig.js +12 -0
- package/lib/config/sandboxOrgConfig.d.ts +8 -0
- package/lib/config/sandboxOrgConfig.js +12 -0
- package/lib/config/sandboxProcessCache.d.ts +16 -0
- package/lib/config/sandboxProcessCache.js +38 -0
- package/lib/config/tokensConfig.d.ts +10 -0
- package/lib/config/tokensConfig.js +29 -0
- package/lib/config/ttlConfig.d.ts +34 -0
- package/lib/config/ttlConfig.js +50 -0
- package/lib/crypto/crypto.js +29 -16
- package/lib/crypto/keyChain.js +4 -4
- package/lib/crypto/keyChainImpl.d.ts +5 -3
- package/lib/crypto/keyChainImpl.js +65 -66
- package/lib/crypto/secureBuffer.d.ts +1 -1
- package/lib/crypto/secureBuffer.js +1 -1
- package/lib/deviceOauthService.d.ts +5 -5
- package/lib/deviceOauthService.js +37 -33
- package/lib/exported.d.ts +22 -15
- package/lib/exported.js +49 -25
- package/lib/global.d.ts +17 -3
- package/lib/global.js +46 -13
- package/lib/lifecycleEvents.d.ts +39 -2
- package/lib/lifecycleEvents.js +77 -3
- package/lib/logger.d.ts +21 -11
- package/lib/logger.js +121 -105
- package/lib/messages.d.ts +53 -36
- package/lib/messages.js +89 -97
- package/lib/org/authInfo.d.ts +84 -72
- package/lib/org/authInfo.js +326 -320
- package/lib/org/authRemover.d.ts +16 -23
- package/lib/org/authRemover.js +62 -60
- package/lib/org/connection.d.ts +33 -59
- package/lib/org/connection.js +129 -190
- package/lib/org/index.js +6 -2
- package/lib/org/org.d.ts +263 -38
- package/lib/org/org.js +734 -149
- package/lib/org/orgConfigProperties.d.ts +69 -0
- package/lib/org/orgConfigProperties.js +121 -0
- package/lib/org/permissionSetAssignment.js +6 -15
- package/lib/org/scratchOrgCache.d.ts +20 -0
- package/lib/org/scratchOrgCache.js +33 -0
- package/lib/org/scratchOrgCreate.d.ts +54 -0
- package/lib/org/scratchOrgCreate.js +214 -0
- package/lib/org/scratchOrgErrorCodes.d.ts +10 -0
- package/lib/org/scratchOrgErrorCodes.js +79 -0
- package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -0
- package/lib/org/scratchOrgFeatureDeprecation.js +105 -0
- package/lib/org/scratchOrgInfoApi.d.ts +68 -0
- package/lib/org/scratchOrgInfoApi.js +416 -0
- package/lib/org/scratchOrgInfoGenerator.d.ts +64 -0
- package/lib/org/scratchOrgInfoGenerator.js +237 -0
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
- package/lib/org/scratchOrgLifecycleEvents.js +41 -0
- package/lib/org/scratchOrgSettingsGenerator.d.ts +79 -0
- package/lib/org/scratchOrgSettingsGenerator.js +277 -0
- package/lib/org/scratchOrgTypes.d.ts +43 -0
- package/lib/{status/client.js → org/scratchOrgTypes.js} +1 -1
- package/lib/org/user.d.ts +7 -2
- package/lib/org/user.js +78 -54
- package/lib/schema/printer.d.ts +6 -0
- package/lib/schema/printer.js +49 -46
- package/lib/schema/validator.d.ts +12 -10
- package/lib/schema/validator.js +56 -76
- package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -15
- package/lib/{sfdxError.js → sfError.js} +42 -24
- package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
- package/lib/sfProject.js +651 -0
- package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -0
- package/lib/stateAggregator/accessors/aliasAccessor.js +146 -0
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
- package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
- package/lib/stateAggregator/index.d.ts +4 -0
- package/lib/stateAggregator/index.js +27 -0
- package/lib/stateAggregator/stateAggregator.d.ts +25 -0
- package/lib/stateAggregator/stateAggregator.js +46 -0
- package/lib/status/myDomainResolver.d.ts +1 -1
- package/lib/status/myDomainResolver.js +10 -10
- package/lib/status/pollingClient.d.ts +2 -6
- package/lib/status/pollingClient.js +38 -64
- package/lib/status/streamingClient.d.ts +5 -80
- package/lib/status/streamingClient.js +74 -94
- package/lib/status/types.d.ts +89 -0
- package/lib/status/types.js +18 -0
- package/lib/testSetup.d.ts +212 -79
- package/lib/testSetup.js +478 -182
- package/lib/util/cache.d.ts +11 -0
- package/lib/util/cache.js +70 -0
- package/lib/util/checkLightningDomain.d.ts +1 -0
- package/lib/util/checkLightningDomain.js +29 -0
- package/lib/util/directoryWriter.d.ts +12 -0
- package/lib/util/directoryWriter.js +54 -0
- package/lib/util/getJwtAudienceUrl.d.ts +4 -0
- package/lib/util/getJwtAudienceUrl.js +19 -0
- package/lib/util/internal.d.ts +28 -2
- package/lib/util/internal.js +65 -8
- package/lib/util/jsonXmlTools.d.ts +14 -0
- package/lib/util/jsonXmlTools.js +39 -0
- package/lib/util/mapKeys.d.ts +14 -0
- package/lib/util/mapKeys.js +52 -0
- package/lib/util/sfdc.d.ts +51 -63
- package/lib/util/sfdc.js +75 -127
- package/lib/util/sfdcUrl.d.ts +64 -0
- package/lib/util/sfdcUrl.js +197 -0
- package/lib/util/structuredWriter.d.ts +9 -0
- package/lib/util/structuredWriter.js +3 -0
- package/lib/util/zipWriter.d.ts +16 -0
- package/lib/util/zipWriter.js +68 -0
- package/lib/webOAuthServer.d.ts +20 -7
- package/lib/webOAuthServer.js +107 -60
- package/messageTransformer/messageTransformer.ts +93 -0
- package/messages/auth.md +11 -3
- package/messages/config.md +94 -6
- package/messages/connection.md +8 -0
- package/messages/core.json +3 -3
- package/messages/core.md +11 -1
- package/messages/envVars.md +313 -0
- package/messages/org.md +64 -0
- package/messages/scratchOrgCreate.md +23 -0
- package/messages/scratchOrgErrorCodes.md +115 -0
- package/messages/scratchOrgFeatureDeprecation.md +11 -0
- package/messages/scratchOrgInfoApi.md +20 -0
- package/messages/scratchOrgInfoGenerator.md +27 -0
- package/messages/user.md +12 -0
- package/package.json +138 -66
- package/CHANGELOG.md +0 -699
- package/lib/config/aliases.d.ts +0 -56
- package/lib/config/aliases.js +0 -96
- package/lib/config/globalInfoConfig.d.ts +0 -74
- package/lib/config/globalInfoConfig.js +0 -144
- package/lib/config/keychainConfig.d.ts +0 -19
- package/lib/config/keychainConfig.js +0 -43
- package/lib/config/sfdxDataHandler.d.ts +0 -36
- package/lib/config/sfdxDataHandler.js +0 -165
- package/lib/sfdxProject.js +0 -546
- package/lib/status/client.d.ts +0 -15
- package/lib/util/fs.d.ts +0 -198
- package/lib/util/fs.js +0 -374
package/lib/config/configFile.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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() :
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
282
|
+
return fs.promises.unlink(this.getPath());
|
|
272
283
|
}
|
|
273
|
-
throw new
|
|
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
|
|
295
|
+
return fs.unlinkSync(this.getPath());
|
|
285
296
|
}
|
|
286
|
-
throw new
|
|
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
|
|
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(
|
|
306
|
-
if (
|
|
307
|
-
configRootFolder = path_1.join(configRootFolder, this.options.stateFolder
|
|
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
|
|
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
|
|
24
|
-
protected defaultGroup:
|
|
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
|
|
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:
|
|
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
|
|
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():
|
|
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
|
|
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?:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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)
|
|
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
|
|
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
|
|
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
|
|
11
|
+
export type ConfigEntry = [string, ConfigValue];
|
|
12
12
|
/**
|
|
13
13
|
* The type of content a config stores.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
16
|
-
export
|
|
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<
|
|
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<
|
|
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<
|
|
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
|
|
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<
|
|
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
|
|
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
|
|
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
|
-
//
|
|
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)
|
|
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
|
|
290
|
-
if (!ts_types_2.isString(value))
|
|
291
|
-
throw new
|
|
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
|
|
299
|
-
if (!ts_types_2.isString(value))
|
|
300
|
-
throw new
|
|
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
|
-
|
|
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
|