@salesforce/core 3.19.2 → 3.19.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +6 -18
- package/lib/config/aliasesConfig.d.ts +12 -0
- package/lib/config/aliasesConfig.js +27 -0
- package/lib/config/authInfoConfig.d.ts +19 -0
- package/lib/config/authInfoConfig.js +35 -0
- package/lib/config/configAggregator.d.ts +5 -3
- package/lib/config/configAggregator.js +13 -1
- package/lib/config/configFile.js +2 -2
- package/lib/config/configGroup.d.ts +141 -0
- package/lib/config/configGroup.js +224 -0
- package/lib/config/configStore.d.ts +2 -2
- package/lib/config/configStore.js +1 -2
- package/lib/config/tokensConfig.d.ts +10 -0
- package/lib/config/tokensConfig.js +28 -0
- package/lib/crypto/keyChainImpl.js +1 -1
- package/lib/exported.d.ts +1 -1
- package/lib/exported.js +6 -5
- package/lib/global.d.ts +8 -0
- package/lib/global.js +10 -0
- package/lib/org/authInfo.d.ts +1 -1
- package/lib/org/authInfo.js +22 -22
- package/lib/org/authRemover.d.ts +6 -5
- package/lib/org/authRemover.js +22 -16
- package/lib/org/connection.js +1 -1
- package/lib/org/org.d.ts +12 -4
- package/lib/org/org.js +28 -26
- package/lib/org/scratchOrgCreate.js +5 -7
- package/lib/org/scratchOrgInfoApi.js +1 -1
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +79 -1
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +119 -2
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +53 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +201 -0
- package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.d.ts +12 -1
- package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.js +22 -2
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +28 -0
- package/lib/{globalInfo → stateAggregator}/accessors/tokenAccessor.js +34 -2
- package/lib/{globalInfo → stateAggregator}/globalInfoConfig.d.ts +11 -8
- package/lib/{globalInfo → stateAggregator}/globalInfoConfig.js +7 -4
- package/lib/stateAggregator/index.d.ts +7 -0
- package/lib/{globalInfo → stateAggregator}/index.js +5 -1
- package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.d.ts +7 -1
- package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.js +25 -2
- package/lib/stateAggregator/stateAggregator.d.ts +20 -0
- package/lib/stateAggregator/stateAggregator.js +38 -0
- package/lib/{globalInfo → stateAggregator}/types.d.ts +25 -10
- package/lib/{globalInfo → stateAggregator}/types.js +3 -0
- package/lib/testSetup.d.ts +30 -6
- package/lib/testSetup.js +79 -11
- package/package.json +1 -1
- package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
- package/lib/globalInfo/accessors/orgAccessor.js +0 -45
- package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
- package/lib/globalInfo/index.d.ts +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [3.19.5](https://github.com/forcedotcom/sfdx-core/compare/v3.19.4...v3.19.5) (2022-06-06)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- update `NamedOrgNotFound` err name ([6a6a627](https://github.com/forcedotcom/sfdx-core/commit/6a6a62782046858c062ecb24a1d28631ea1f3bbe))
|
|
10
|
+
|
|
11
|
+
### [3.19.4](https://github.com/forcedotcom/sfdx-core/compare/v3.19.3...v3.19.4) (2022-06-06)
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
- add stat method to OrgAccessor ([f4e297c](https://github.com/forcedotcom/sfdx-core/commit/f4e297c576647b32be62621377d6e3fc5c8dc5f1))
|
|
16
|
+
|
|
17
|
+
### [3.19.3](https://github.com/forcedotcom/sfdx-core/compare/v3.19.2...v3.19.3) (2022-06-06)
|
|
18
|
+
|
|
5
19
|
### [3.19.2](https://github.com/forcedotcom/sfdx-core/compare/v3.19.1...v3.19.2) (2022-06-02)
|
|
6
20
|
|
|
7
21
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -36,14 +36,8 @@ const $$ = testSetup();
|
|
|
36
36
|
describe('Mocking Auth data', () => {
|
|
37
37
|
it('example', async () => {
|
|
38
38
|
const testData = new MockTestOrgData();
|
|
39
|
-
$$.
|
|
40
|
-
|
|
41
|
-
orgs: {
|
|
42
|
-
[testData.username]: await testData.getConfig(),
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
const auth: AuthInfo = await AuthInfo.create({ username: testData.username });
|
|
39
|
+
await $$.stubAuths(testData)
|
|
40
|
+
const auth = await AuthInfo.create({ username: testData.username });
|
|
47
41
|
strictEqual(auth.getUsername(), testData.username);
|
|
48
42
|
});
|
|
49
43
|
});
|
|
@@ -65,25 +59,19 @@ describe('Mocking a force server call', () => {
|
|
|
65
59
|
it('example', async () => {
|
|
66
60
|
const records: AnyJson = { records: ['123456', '234567'] };
|
|
67
61
|
const testData = new MockTestOrgData();
|
|
68
|
-
$$.
|
|
69
|
-
contents: {
|
|
70
|
-
orgs: {
|
|
71
|
-
[testData.username]: await testData.getConfig(),
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
});
|
|
62
|
+
await $$.stubAuths(testData);
|
|
75
63
|
$$.fakeConnectionRequest = (request: AnyJson): Promise<AnyJson> => {
|
|
76
|
-
const _request
|
|
64
|
+
const _request = ensureJsonMap(request);
|
|
77
65
|
if (request && ensureString(_request.url).includes('Account')) {
|
|
78
66
|
return Promise.resolve(records);
|
|
79
67
|
} else {
|
|
80
68
|
return Promise.reject(new SfError(`Unexpected request: ${_request.url}`));
|
|
81
69
|
}
|
|
82
70
|
};
|
|
83
|
-
const connection
|
|
71
|
+
const connection = await Connection.create({
|
|
84
72
|
authInfo: await AuthInfo.create({ username: testData.username }),
|
|
85
73
|
});
|
|
86
|
-
const result
|
|
74
|
+
const result = await connection.query('select Id From Account');
|
|
87
75
|
deepStrictEqual(result, records);
|
|
88
76
|
});
|
|
89
77
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConfigGroup } from './configGroup';
|
|
2
|
+
import { ConfigContents, ConfigValue } from './configStore';
|
|
3
|
+
/**
|
|
4
|
+
* Different groups of aliases. Currently only support orgs.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum AliasGroup {
|
|
7
|
+
ORGS = "orgs"
|
|
8
|
+
}
|
|
9
|
+
export declare class AliasesConfig extends ConfigGroup<ConfigGroup.Options> {
|
|
10
|
+
static getDefaultOptions(): ConfigGroup.Options;
|
|
11
|
+
protected setMethod(contents: ConfigContents, key: string, value?: ConfigValue): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AliasesConfig = exports.AliasGroup = void 0;
|
|
10
|
+
const configGroup_1 = require("./configGroup");
|
|
11
|
+
/**
|
|
12
|
+
* Different groups of aliases. Currently only support orgs.
|
|
13
|
+
*/
|
|
14
|
+
var AliasGroup;
|
|
15
|
+
(function (AliasGroup) {
|
|
16
|
+
AliasGroup["ORGS"] = "orgs";
|
|
17
|
+
})(AliasGroup = exports.AliasGroup || (exports.AliasGroup = {}));
|
|
18
|
+
class AliasesConfig extends configGroup_1.ConfigGroup {
|
|
19
|
+
static getDefaultOptions() {
|
|
20
|
+
return { ...configGroup_1.ConfigGroup.getOptions(AliasGroup.ORGS, 'alias.json'), isGlobal: true, isState: true };
|
|
21
|
+
}
|
|
22
|
+
setMethod(contents, key, value) {
|
|
23
|
+
contents[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.AliasesConfig = AliasesConfig;
|
|
27
|
+
//# sourceMappingURL=aliasesConfig.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AuthFields } from '../org';
|
|
2
|
+
import { ConfigFile } from './configFile';
|
|
3
|
+
/**
|
|
4
|
+
* An auth config file that stores information such as access tokens, usernames, etc.,
|
|
5
|
+
* in the global sfdx directory (~/.sfdx).
|
|
6
|
+
*
|
|
7
|
+
* ```
|
|
8
|
+
* const authInfo = await AuthInfoConfig.create(AuthInfoConfig.getOptions(username));
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare class AuthInfoConfig extends ConfigFile<ConfigFile.Options, AuthFields> {
|
|
12
|
+
protected static encryptedKeys: RegExp[];
|
|
13
|
+
/**
|
|
14
|
+
* Gets the config options for a given org ID.
|
|
15
|
+
*
|
|
16
|
+
* @param username The username for the org.
|
|
17
|
+
*/
|
|
18
|
+
static getOptions(username: string): ConfigFile.Options;
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AuthInfoConfig = void 0;
|
|
10
|
+
const configFile_1 = require("./configFile");
|
|
11
|
+
/**
|
|
12
|
+
* An auth config file that stores information such as access tokens, usernames, etc.,
|
|
13
|
+
* in the global sfdx directory (~/.sfdx).
|
|
14
|
+
*
|
|
15
|
+
* ```
|
|
16
|
+
* const authInfo = await AuthInfoConfig.create(AuthInfoConfig.getOptions(username));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
class AuthInfoConfig extends configFile_1.ConfigFile {
|
|
20
|
+
/**
|
|
21
|
+
* Gets the config options for a given org ID.
|
|
22
|
+
*
|
|
23
|
+
* @param username The username for the org.
|
|
24
|
+
*/
|
|
25
|
+
static getOptions(username) {
|
|
26
|
+
return {
|
|
27
|
+
isGlobal: true,
|
|
28
|
+
isState: true,
|
|
29
|
+
filename: `${username}.json`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.AuthInfoConfig = AuthInfoConfig;
|
|
34
|
+
AuthInfoConfig.encryptedKeys = [/token/gi, /password/gi, /secret/gi];
|
|
35
|
+
//# sourceMappingURL=authInfoConfig.js.map
|
|
@@ -54,8 +54,8 @@ export interface ConfigInfo {
|
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
56
|
export declare class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggregator.Options> {
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
protected static instance: AsyncOptionalCreatable;
|
|
58
|
+
protected static encrypted: boolean;
|
|
59
59
|
private allowedProperties;
|
|
60
60
|
private localConfig?;
|
|
61
61
|
private globalConfig;
|
|
@@ -183,7 +183,7 @@ export declare class ConfigAggregator extends AsyncOptionalCreatable<ConfigAggre
|
|
|
183
183
|
/**
|
|
184
184
|
* Loads all the properties and aggregates them according to location.
|
|
185
185
|
*/
|
|
186
|
-
|
|
186
|
+
protected loadProperties(): Promise<void>;
|
|
187
187
|
/**
|
|
188
188
|
* Loads all the properties and aggregates them according to location.
|
|
189
189
|
*/
|
|
@@ -219,6 +219,8 @@ export declare namespace ConfigAggregator {
|
|
|
219
219
|
* @deprecated
|
|
220
220
|
*/
|
|
221
221
|
export declare class SfdxConfigAggregator extends ConfigAggregator {
|
|
222
|
+
protected static instance: AsyncOptionalCreatable;
|
|
223
|
+
protected static encrypted: boolean;
|
|
222
224
|
static create<P, T extends AsyncOptionalCreatable<P>>(this: new (options?: ConfigAggregator.Options) => T, options?: ConfigAggregator.Options): Promise<T>;
|
|
223
225
|
getPropertyMeta(key: string): ConfigPropertyMeta;
|
|
224
226
|
getPropertyValue<T extends AnyJson>(key: string): Optional<T>;
|
|
@@ -324,7 +324,18 @@ class SfdxConfigAggregator extends ConfigAggregator {
|
|
|
324
324
|
const restDeploy = config_1.SFDX_ALLOWED_PROPERTIES.find((p) => p.key === config_1.SfdxPropertyKeys.REST_DEPLOY);
|
|
325
325
|
const orgRestDeploy = Object.assign({}, restDeploy, { key: 'org-metadata-rest-deploy', deprecated: false });
|
|
326
326
|
options.customConfigMeta = [...customConfigMeta, orgRestDeploy];
|
|
327
|
-
|
|
327
|
+
let config = SfdxConfigAggregator.instance;
|
|
328
|
+
if (!config) {
|
|
329
|
+
config = SfdxConfigAggregator.instance = new this(options);
|
|
330
|
+
await config.init();
|
|
331
|
+
}
|
|
332
|
+
if (SfdxConfigAggregator.encrypted) {
|
|
333
|
+
await config.loadProperties();
|
|
334
|
+
}
|
|
335
|
+
if (options === null || options === void 0 ? void 0 : options.customConfigMeta) {
|
|
336
|
+
config_1.Config.addAllowedProperties(options.customConfigMeta);
|
|
337
|
+
}
|
|
338
|
+
return SfdxConfigAggregator.instance;
|
|
328
339
|
}
|
|
329
340
|
getPropertyMeta(key) {
|
|
330
341
|
const match = this.getAllowedProperties().find((element) => key === element.key);
|
|
@@ -367,4 +378,5 @@ class SfdxConfigAggregator extends ConfigAggregator {
|
|
|
367
378
|
}
|
|
368
379
|
}
|
|
369
380
|
exports.SfdxConfigAggregator = SfdxConfigAggregator;
|
|
381
|
+
SfdxConfigAggregator.encrypted = true;
|
|
370
382
|
//# sourceMappingURL=configAggregator.js.map
|
package/lib/config/configFile.js
CHANGED
|
@@ -80,7 +80,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
|
|
|
80
80
|
isGlobal,
|
|
81
81
|
isState: true,
|
|
82
82
|
filename: filename || this.getFileName(),
|
|
83
|
-
stateFolder: global_1.Global.
|
|
83
|
+
stateFolder: global_1.Global.SFDX_STATE_FOLDER,
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
@@ -306,7 +306,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
|
|
|
306
306
|
? this.options.rootFolder
|
|
307
307
|
: ConfigFile.resolveRootFolderSync(!!this.options.isGlobal);
|
|
308
308
|
if (_isGlobal || _isState) {
|
|
309
|
-
configRootFolder = (0, path_1.join)(configRootFolder, this.options.stateFolder || global_1.Global.
|
|
309
|
+
configRootFolder = (0, path_1.join)(configRootFolder, this.options.stateFolder || global_1.Global.SFDX_STATE_FOLDER);
|
|
310
310
|
}
|
|
311
311
|
this.path = (0, path_1.join)(configRootFolder, this.options.filePath ? this.options.filePath : '', this.options.filename);
|
|
312
312
|
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Dictionary, JsonMap, Optional } from '@salesforce/ts-types';
|
|
2
|
+
import { ConfigFile } from './configFile';
|
|
3
|
+
import { ConfigContents, ConfigEntry, ConfigValue } from './configStore';
|
|
4
|
+
/**
|
|
5
|
+
* A config file that stores config values in groups. e.g. to store different config
|
|
6
|
+
* values for different commands, without having manually manipulate the config.
|
|
7
|
+
*
|
|
8
|
+
* **Note:** All config methods are overwritten to use the {@link ConfigGroup.setDefaultGroup}.
|
|
9
|
+
*
|
|
10
|
+
* ```
|
|
11
|
+
* class MyPluginConfig extends ConfigGroup<ConfigGroup.Options> {
|
|
12
|
+
* public static getFileName(): string {
|
|
13
|
+
* return 'myPluginConfigFilename.json';
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* const myConfig = await MyPluginConfig.create(ConfigGroup.getOptions('all'));
|
|
17
|
+
* myConfig.setDefaultGroup('myCommand'); // Can be set in your command's init.
|
|
18
|
+
* myConfig.set('mykey', 'myvalue'); // Sets 'myKey' for the 'myCommand' group.
|
|
19
|
+
* myConfig.setInGroup('myKey', 'myvalue', 'all'); // Manually set in another group.
|
|
20
|
+
* await myConfig.write();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class ConfigGroup<T extends ConfigGroup.Options> extends ConfigFile<T> {
|
|
24
|
+
protected defaultGroup: string;
|
|
25
|
+
/**
|
|
26
|
+
* Get ConfigGroup specific options, such as the default group.
|
|
27
|
+
*
|
|
28
|
+
* @param defaultGroup The default group to use when creating the config.
|
|
29
|
+
* @param filename The filename of the config file. Uses the static {@link getFileName} by default.
|
|
30
|
+
*/
|
|
31
|
+
static getOptions(defaultGroup: string, filename?: string): ConfigGroup.Options;
|
|
32
|
+
/**
|
|
33
|
+
* Sets the default group for all {@link BaseConfigStore} methods to use.
|
|
34
|
+
* **Throws** *{@link SfError}{ name: 'MissingGroupName' }* The group parameter is null or undefined.
|
|
35
|
+
*
|
|
36
|
+
* @param group The group.
|
|
37
|
+
*/
|
|
38
|
+
setDefaultGroup(group: string): void;
|
|
39
|
+
/**
|
|
40
|
+
* Set a group of entries in a bulk save. Returns The new properties that were saved.
|
|
41
|
+
*
|
|
42
|
+
* @param newEntries An object representing the aliases to set.
|
|
43
|
+
* @param group The group the property belongs to.
|
|
44
|
+
*/
|
|
45
|
+
updateValues(newEntries: Dictionary<ConfigValue>, group?: string): Promise<Dictionary<ConfigValue>>;
|
|
46
|
+
/**
|
|
47
|
+
* Set a value on a group. Returns the promise resolved when the value is set.
|
|
48
|
+
*
|
|
49
|
+
* @param key The key.
|
|
50
|
+
* @param value The value.
|
|
51
|
+
* @param group The group.
|
|
52
|
+
*/
|
|
53
|
+
updateValue(key: string, value: ConfigValue, group?: string): Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Gets an array of key value pairs.
|
|
56
|
+
*/
|
|
57
|
+
entries(): ConfigEntry[];
|
|
58
|
+
/**
|
|
59
|
+
* Returns a specified element from ConfigGroup. Returns the associated value.
|
|
60
|
+
*
|
|
61
|
+
* @param key The key.
|
|
62
|
+
*/
|
|
63
|
+
get(key: string): Optional<ConfigValue>;
|
|
64
|
+
/**
|
|
65
|
+
* Returns a boolean if an element with the specified key exists in the default group.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} key The key.
|
|
68
|
+
*/
|
|
69
|
+
has(key: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Returns an array of the keys from the default group.
|
|
72
|
+
*/
|
|
73
|
+
keys(): string[];
|
|
74
|
+
/**
|
|
75
|
+
* Returns an array of the values from the default group.
|
|
76
|
+
*/
|
|
77
|
+
values(): ConfigValue[];
|
|
78
|
+
/**
|
|
79
|
+
* Add or updates an element with the specified key in the default group.
|
|
80
|
+
*
|
|
81
|
+
* @param key The key.
|
|
82
|
+
* @param value The value.
|
|
83
|
+
*/
|
|
84
|
+
set(key: string, value: ConfigValue): ConfigContents;
|
|
85
|
+
/**
|
|
86
|
+
* Removes an element with the specified key from the default group. Returns `true` if the item was deleted.
|
|
87
|
+
*
|
|
88
|
+
* @param key The key.
|
|
89
|
+
*/
|
|
90
|
+
unset(key: string): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Remove all key value pairs from the default group.
|
|
93
|
+
*/
|
|
94
|
+
clear(): void;
|
|
95
|
+
/**
|
|
96
|
+
* Get all config contents for a group.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} [group = 'default'] The group.
|
|
99
|
+
*/
|
|
100
|
+
getGroup(group?: string): Optional<ConfigContents>;
|
|
101
|
+
/**
|
|
102
|
+
* Returns the value associated to the key and group, or undefined if there is none.
|
|
103
|
+
*
|
|
104
|
+
* @param key The key.
|
|
105
|
+
* @param group The group. Defaults to the default group.
|
|
106
|
+
*/
|
|
107
|
+
getInGroup(key: string, group?: string): Optional<ConfigValue>;
|
|
108
|
+
/**
|
|
109
|
+
* Convert the config object to a json object.
|
|
110
|
+
*/
|
|
111
|
+
toObject(): JsonMap;
|
|
112
|
+
/**
|
|
113
|
+
* Convert an object to a {@link ConfigContents} and set it as the config contents.
|
|
114
|
+
*
|
|
115
|
+
* @param {object} obj The object.
|
|
116
|
+
*/
|
|
117
|
+
setContentsFromObject<U extends object>(obj: U): void;
|
|
118
|
+
/**
|
|
119
|
+
* Sets the value for the key and group in the config object.
|
|
120
|
+
*
|
|
121
|
+
* @param key The key.
|
|
122
|
+
* @param value The value.
|
|
123
|
+
* @param group The group. Uses the default group if not specified.
|
|
124
|
+
*/
|
|
125
|
+
setInGroup(key: string, value?: ConfigValue, group?: string): ConfigContents;
|
|
126
|
+
/**
|
|
127
|
+
* Initialize the asynchronous dependencies.
|
|
128
|
+
*/
|
|
129
|
+
init(): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
export declare namespace ConfigGroup {
|
|
132
|
+
/**
|
|
133
|
+
* Options when creating the config file.
|
|
134
|
+
*/
|
|
135
|
+
interface Options extends ConfigFile.Options {
|
|
136
|
+
/**
|
|
137
|
+
* The default group for properties to go into.
|
|
138
|
+
*/
|
|
139
|
+
defaultGroup?: string;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.ConfigGroup = void 0;
|
|
10
|
+
const ts_types_1 = require("@salesforce/ts-types");
|
|
11
|
+
const sfError_1 = require("../sfError");
|
|
12
|
+
const configFile_1 = require("./configFile");
|
|
13
|
+
/**
|
|
14
|
+
* A config file that stores config values in groups. e.g. to store different config
|
|
15
|
+
* values for different commands, without having manually manipulate the config.
|
|
16
|
+
*
|
|
17
|
+
* **Note:** All config methods are overwritten to use the {@link ConfigGroup.setDefaultGroup}.
|
|
18
|
+
*
|
|
19
|
+
* ```
|
|
20
|
+
* class MyPluginConfig extends ConfigGroup<ConfigGroup.Options> {
|
|
21
|
+
* public static getFileName(): string {
|
|
22
|
+
* return 'myPluginConfigFilename.json';
|
|
23
|
+
* }
|
|
24
|
+
* }
|
|
25
|
+
* const myConfig = await MyPluginConfig.create(ConfigGroup.getOptions('all'));
|
|
26
|
+
* myConfig.setDefaultGroup('myCommand'); // Can be set in your command's init.
|
|
27
|
+
* myConfig.set('mykey', 'myvalue'); // Sets 'myKey' for the 'myCommand' group.
|
|
28
|
+
* myConfig.setInGroup('myKey', 'myvalue', 'all'); // Manually set in another group.
|
|
29
|
+
* await myConfig.write();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
class ConfigGroup extends configFile_1.ConfigFile {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(...arguments);
|
|
35
|
+
this.defaultGroup = 'default';
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get ConfigGroup specific options, such as the default group.
|
|
39
|
+
*
|
|
40
|
+
* @param defaultGroup The default group to use when creating the config.
|
|
41
|
+
* @param filename The filename of the config file. Uses the static {@link getFileName} by default.
|
|
42
|
+
*/
|
|
43
|
+
static getOptions(defaultGroup, filename) {
|
|
44
|
+
const options = configFile_1.ConfigFile.getDefaultOptions(true, filename);
|
|
45
|
+
const configGroupOptions = { defaultGroup };
|
|
46
|
+
Object.assign(configGroupOptions, options);
|
|
47
|
+
return configGroupOptions;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Sets the default group for all {@link BaseConfigStore} methods to use.
|
|
51
|
+
* **Throws** *{@link SfError}{ name: 'MissingGroupName' }* The group parameter is null or undefined.
|
|
52
|
+
*
|
|
53
|
+
* @param group The group.
|
|
54
|
+
*/
|
|
55
|
+
setDefaultGroup(group) {
|
|
56
|
+
if (!group) {
|
|
57
|
+
throw new sfError_1.SfError('null or undefined group', 'MissingGroupName');
|
|
58
|
+
}
|
|
59
|
+
this.defaultGroup = group;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Set a group of entries in a bulk save. Returns The new properties that were saved.
|
|
63
|
+
*
|
|
64
|
+
* @param newEntries An object representing the aliases to set.
|
|
65
|
+
* @param group The group the property belongs to.
|
|
66
|
+
*/
|
|
67
|
+
async updateValues(newEntries, group) {
|
|
68
|
+
// Make sure the contents are loaded
|
|
69
|
+
await this.read();
|
|
70
|
+
Object.entries(newEntries).forEach(([key, val]) => this.setInGroup(key, val, group || this.defaultGroup));
|
|
71
|
+
await this.write();
|
|
72
|
+
return newEntries;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Set a value on a group. Returns the promise resolved when the value is set.
|
|
76
|
+
*
|
|
77
|
+
* @param key The key.
|
|
78
|
+
* @param value The value.
|
|
79
|
+
* @param group The group.
|
|
80
|
+
*/
|
|
81
|
+
async updateValue(key, value, group) {
|
|
82
|
+
// Make sure the content is loaded
|
|
83
|
+
await this.read();
|
|
84
|
+
this.setInGroup(key, value, group || this.defaultGroup);
|
|
85
|
+
// Then save it
|
|
86
|
+
await this.write();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Gets an array of key value pairs.
|
|
90
|
+
*/
|
|
91
|
+
entries() {
|
|
92
|
+
const group = this.getGroup();
|
|
93
|
+
if (group) {
|
|
94
|
+
return (0, ts_types_1.definiteEntriesOf)(group);
|
|
95
|
+
}
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns a specified element from ConfigGroup. Returns the associated value.
|
|
100
|
+
*
|
|
101
|
+
* @param key The key.
|
|
102
|
+
*/
|
|
103
|
+
get(key) {
|
|
104
|
+
return this.getInGroup(key);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns a boolean if an element with the specified key exists in the default group.
|
|
108
|
+
*
|
|
109
|
+
* @param {string} key The key.
|
|
110
|
+
*/
|
|
111
|
+
has(key) {
|
|
112
|
+
const group = this.getGroup();
|
|
113
|
+
return !!group && super.has(this.defaultGroup) && !!group[key];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns an array of the keys from the default group.
|
|
117
|
+
*/
|
|
118
|
+
keys() {
|
|
119
|
+
return Object.keys(this.getGroup(this.defaultGroup) || {});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Returns an array of the values from the default group.
|
|
123
|
+
*/
|
|
124
|
+
values() {
|
|
125
|
+
return (0, ts_types_1.definiteValuesOf)(this.getGroup(this.defaultGroup) || {});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Add or updates an element with the specified key in the default group.
|
|
129
|
+
*
|
|
130
|
+
* @param key The key.
|
|
131
|
+
* @param value The value.
|
|
132
|
+
*/
|
|
133
|
+
set(key, value) {
|
|
134
|
+
return this.setInGroup(key, value, this.defaultGroup);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Removes an element with the specified key from the default group. Returns `true` if the item was deleted.
|
|
138
|
+
*
|
|
139
|
+
* @param key The key.
|
|
140
|
+
*/
|
|
141
|
+
unset(key) {
|
|
142
|
+
const groupContents = this.getGroup(this.defaultGroup);
|
|
143
|
+
if (groupContents) {
|
|
144
|
+
delete groupContents[key];
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Remove all key value pairs from the default group.
|
|
151
|
+
*/
|
|
152
|
+
clear() {
|
|
153
|
+
delete this.getContents()[this.defaultGroup];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get all config contents for a group.
|
|
157
|
+
*
|
|
158
|
+
* @param {string} [group = 'default'] The group.
|
|
159
|
+
*/
|
|
160
|
+
getGroup(group = this.defaultGroup) {
|
|
161
|
+
return (0, ts_types_1.getJsonMap)(this.getContents(), group) || undefined;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Returns the value associated to the key and group, or undefined if there is none.
|
|
165
|
+
*
|
|
166
|
+
* @param key The key.
|
|
167
|
+
* @param group The group. Defaults to the default group.
|
|
168
|
+
*/
|
|
169
|
+
getInGroup(key, group) {
|
|
170
|
+
const groupContents = this.getGroup(group);
|
|
171
|
+
if (groupContents) {
|
|
172
|
+
return groupContents[key];
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Convert the config object to a json object.
|
|
177
|
+
*/
|
|
178
|
+
toObject() {
|
|
179
|
+
return this.getContents();
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Convert an object to a {@link ConfigContents} and set it as the config contents.
|
|
183
|
+
*
|
|
184
|
+
* @param {object} obj The object.
|
|
185
|
+
*/
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
187
|
+
setContentsFromObject(obj) {
|
|
188
|
+
const contents = new Map(Object.entries(obj));
|
|
189
|
+
Array.from(contents.entries()).forEach(([groupKey, groupContents]) => {
|
|
190
|
+
if (groupContents) {
|
|
191
|
+
Object.entries(groupContents).forEach(([contentKey, contentValue]) => {
|
|
192
|
+
this.setInGroup(contentKey, contentValue, groupKey);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Sets the value for the key and group in the config object.
|
|
199
|
+
*
|
|
200
|
+
* @param key The key.
|
|
201
|
+
* @param value The value.
|
|
202
|
+
* @param group The group. Uses the default group if not specified.
|
|
203
|
+
*/
|
|
204
|
+
setInGroup(key, value, group) {
|
|
205
|
+
group = group || this.defaultGroup;
|
|
206
|
+
if (!super.has(group)) {
|
|
207
|
+
super.set(group, {});
|
|
208
|
+
}
|
|
209
|
+
const content = this.getGroup(group) || {};
|
|
210
|
+
this.setMethod(content, key, value);
|
|
211
|
+
return content;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Initialize the asynchronous dependencies.
|
|
215
|
+
*/
|
|
216
|
+
async init() {
|
|
217
|
+
await super.init();
|
|
218
|
+
if (this.options.defaultGroup) {
|
|
219
|
+
this.setDefaultGroup(this.options.defaultGroup);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
exports.ConfigGroup = ConfigGroup;
|
|
224
|
+
//# sourceMappingURL=configGroup.js.map
|
|
@@ -12,7 +12,7 @@ export declare type ConfigEntry = [string, ConfigValue];
|
|
|
12
12
|
/**
|
|
13
13
|
* The type of content a config stores.
|
|
14
14
|
*/
|
|
15
|
-
export declare type ConfigContents = Dictionary<
|
|
15
|
+
export declare type ConfigContents<T = ConfigValue> = Dictionary<T>;
|
|
16
16
|
export declare type Key<P extends ConfigContents> = Extract<keyof P, string>;
|
|
17
17
|
/**
|
|
18
18
|
* An interface for a config object with a persistent store.
|
|
@@ -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.
|
|
@@ -198,9 +198,8 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
|
|
|
198
198
|
*
|
|
199
199
|
* @param obj The object.
|
|
200
200
|
*/
|
|
201
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
202
201
|
setContentsFromObject(obj) {
|
|
203
|
-
this.contents = {};
|
|
202
|
+
this.contents = (this.hasEncryption() ? this.recursiveEncrypt(obj) : {});
|
|
204
203
|
Object.entries(obj).forEach(([key, value]) => {
|
|
205
204
|
this.setMethod(this.contents, key, value);
|
|
206
205
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Optional } from '@salesforce/ts-types';
|
|
2
|
+
import { SfTokens } from '../stateAggregator';
|
|
3
|
+
import { ConfigFile } from './configFile';
|
|
4
|
+
import { ConfigContents, ConfigValue } from './configStore';
|
|
5
|
+
export declare class TokensConfig extends ConfigFile<ConfigFile.Options, SfTokens> {
|
|
6
|
+
protected static encryptedKeys: RegExp[];
|
|
7
|
+
static getDefaultOptions(): ConfigFile.Options;
|
|
8
|
+
protected getMethod(contents: ConfigContents, key: string): Optional<ConfigValue>;
|
|
9
|
+
protected setMethod(contents: ConfigContents, key: string, value?: ConfigValue): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TokensConfig = void 0;
|
|
10
|
+
const configFile_1 = require("./configFile");
|
|
11
|
+
class TokensConfig extends configFile_1.ConfigFile {
|
|
12
|
+
static getDefaultOptions() {
|
|
13
|
+
return {
|
|
14
|
+
isGlobal: true,
|
|
15
|
+
isState: true,
|
|
16
|
+
filename: 'tokens.json',
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
getMethod(contents, key) {
|
|
20
|
+
return contents[key];
|
|
21
|
+
}
|
|
22
|
+
setMethod(contents, key, value) {
|
|
23
|
+
contents[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.TokensConfig = TokensConfig;
|
|
27
|
+
TokensConfig.encryptedKeys = [/token/gi, /password/gi, /secret/gi];
|
|
28
|
+
//# sourceMappingURL=tokensConfig.js.map
|