@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
|
@@ -7,11 +7,22 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.SandboxOrgConfig = void 0;
|
|
10
|
+
const global_1 = require("../global");
|
|
10
11
|
const configFile_1 = require("./configFile");
|
|
11
12
|
/**
|
|
12
13
|
* A config file that stores usernames for an org.
|
|
13
14
|
*/
|
|
14
15
|
class SandboxOrgConfig extends configFile_1.ConfigFile {
|
|
16
|
+
/**
|
|
17
|
+
* Constructor.
|
|
18
|
+
* **Do not directly construct instances of this class -- use {@link SandboxConfig.create} instead.**
|
|
19
|
+
*
|
|
20
|
+
* @param options The options for the class instance
|
|
21
|
+
* @ignore
|
|
22
|
+
*/
|
|
23
|
+
constructor(options) {
|
|
24
|
+
super(options);
|
|
25
|
+
}
|
|
15
26
|
/**
|
|
16
27
|
* Gets the config options for a given org ID.
|
|
17
28
|
*
|
|
@@ -23,6 +34,7 @@ class SandboxOrgConfig extends configFile_1.ConfigFile {
|
|
|
23
34
|
isState: true,
|
|
24
35
|
filename: `${orgId}.sandbox.json`,
|
|
25
36
|
orgId,
|
|
37
|
+
stateFolder: global_1.Global.SFDX_STATE_FOLDER,
|
|
26
38
|
};
|
|
27
39
|
}
|
|
28
40
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SandboxProcessObject, SandboxRequest } from '../org';
|
|
2
|
+
import { TTLConfig } from './ttlConfig';
|
|
3
|
+
export type SandboxRequestCacheEntry = {
|
|
4
|
+
alias?: string;
|
|
5
|
+
setDefault: boolean;
|
|
6
|
+
prodOrgUsername: string;
|
|
7
|
+
sandboxProcessObject: Partial<SandboxProcessObject>;
|
|
8
|
+
sandboxRequest: Partial<SandboxRequest>;
|
|
9
|
+
tracksSource?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare class SandboxRequestCache extends TTLConfig<TTLConfig.Options, SandboxRequestCacheEntry> {
|
|
12
|
+
static getDefaultOptions(): TTLConfig.Options;
|
|
13
|
+
static unset(key: string): Promise<void>;
|
|
14
|
+
static set(key: string, sandboxProcessObject: SandboxRequestCacheEntry): Promise<void>;
|
|
15
|
+
static getFileName(): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SandboxRequestCache = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
* Licensed under the BSD 3-Clause license.
|
|
8
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
|
+
*/
|
|
10
|
+
const kit_1 = require("@salesforce/kit");
|
|
11
|
+
const global_1 = require("../global");
|
|
12
|
+
const ttlConfig_1 = require("./ttlConfig");
|
|
13
|
+
class SandboxRequestCache extends ttlConfig_1.TTLConfig {
|
|
14
|
+
static getDefaultOptions() {
|
|
15
|
+
return {
|
|
16
|
+
isGlobal: true,
|
|
17
|
+
isState: true,
|
|
18
|
+
filename: SandboxRequestCache.getFileName(),
|
|
19
|
+
stateFolder: global_1.Global.SF_STATE_FOLDER,
|
|
20
|
+
ttl: kit_1.Duration.days(14),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
static async unset(key) {
|
|
24
|
+
const cache = await SandboxRequestCache.create();
|
|
25
|
+
cache.unset(key);
|
|
26
|
+
await cache.write();
|
|
27
|
+
}
|
|
28
|
+
static async set(key, sandboxProcessObject) {
|
|
29
|
+
const cache = await SandboxRequestCache.create();
|
|
30
|
+
cache.set(key, sandboxProcessObject);
|
|
31
|
+
await cache.write();
|
|
32
|
+
}
|
|
33
|
+
static getFileName() {
|
|
34
|
+
return 'sandbox-create-cache.json';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.SandboxRequestCache = SandboxRequestCache;
|
|
38
|
+
//# sourceMappingURL=sandboxProcessCache.js.map
|
|
@@ -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,29 @@
|
|
|
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
|
+
/* eslint-disable class-methods-use-this */
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.TokensConfig = void 0;
|
|
11
|
+
const configFile_1 = require("./configFile");
|
|
12
|
+
class TokensConfig extends configFile_1.ConfigFile {
|
|
13
|
+
static getDefaultOptions() {
|
|
14
|
+
return {
|
|
15
|
+
isGlobal: true,
|
|
16
|
+
isState: true,
|
|
17
|
+
filename: 'tokens.json',
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
getMethod(contents, key) {
|
|
21
|
+
return contents[key];
|
|
22
|
+
}
|
|
23
|
+
setMethod(contents, key, value) {
|
|
24
|
+
contents[key] = value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.TokensConfig = TokensConfig;
|
|
28
|
+
TokensConfig.encryptedKeys = [/token/i, /password/i, /secret/i];
|
|
29
|
+
//# sourceMappingURL=tokensConfig.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Duration } from '@salesforce/kit';
|
|
2
|
+
import { JsonMap, Nullable } from '@salesforce/ts-types';
|
|
3
|
+
import { ConfigFile } from './configFile';
|
|
4
|
+
/**
|
|
5
|
+
* A Time To Live configuration file where each entry is timestamped and removed once the TTL has expired.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```
|
|
9
|
+
* import { Duration } from '@salesforce/kit';
|
|
10
|
+
* const config = await TTLConfig.create({
|
|
11
|
+
* isGlobal: false,
|
|
12
|
+
* ttl: Duration.days(1)
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare class TTLConfig<T extends TTLConfig.Options, P extends JsonMap> extends ConfigFile<T, TTLConfig.Contents<P>> {
|
|
17
|
+
set(key: string, value: Partial<TTLConfig.Entry<P>>): void;
|
|
18
|
+
getLatestEntry(): Nullable<[string, TTLConfig.Entry<P>]>;
|
|
19
|
+
getLatestKey(): Nullable<string>;
|
|
20
|
+
isExpired(dateTime: number, value: P & {
|
|
21
|
+
timestamp: string;
|
|
22
|
+
}): boolean;
|
|
23
|
+
protected init(): Promise<void>;
|
|
24
|
+
private timestamp;
|
|
25
|
+
}
|
|
26
|
+
export declare namespace TTLConfig {
|
|
27
|
+
type Options = ConfigFile.Options & {
|
|
28
|
+
ttl: Duration;
|
|
29
|
+
};
|
|
30
|
+
type Entry<T extends JsonMap> = T & {
|
|
31
|
+
timestamp: string;
|
|
32
|
+
};
|
|
33
|
+
type Contents<T extends JsonMap> = Record<string, Entry<T>>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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.TTLConfig = void 0;
|
|
10
|
+
const configFile_1 = require("./configFile");
|
|
11
|
+
/**
|
|
12
|
+
* A Time To Live configuration file where each entry is timestamped and removed once the TTL has expired.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```
|
|
16
|
+
* import { Duration } from '@salesforce/kit';
|
|
17
|
+
* const config = await TTLConfig.create({
|
|
18
|
+
* isGlobal: false,
|
|
19
|
+
* ttl: Duration.days(1)
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class TTLConfig extends configFile_1.ConfigFile {
|
|
24
|
+
set(key, value) {
|
|
25
|
+
super.set(key, this.timestamp(value));
|
|
26
|
+
}
|
|
27
|
+
getLatestEntry() {
|
|
28
|
+
const entries = this.entries();
|
|
29
|
+
const sorted = entries.sort(([, valueA], [, valueB]) => new Date(valueB.timestamp).getTime() - new Date(valueA.timestamp).getTime());
|
|
30
|
+
return sorted.length > 0 ? sorted[0] : null;
|
|
31
|
+
}
|
|
32
|
+
getLatestKey() {
|
|
33
|
+
const [key] = this.getLatestEntry() ?? [null];
|
|
34
|
+
return key;
|
|
35
|
+
}
|
|
36
|
+
isExpired(dateTime, value) {
|
|
37
|
+
return dateTime - new Date(value.timestamp).getTime() > this.options.ttl.milliseconds;
|
|
38
|
+
}
|
|
39
|
+
async init() {
|
|
40
|
+
const contents = await this.read(this.options.throwOnNotFound);
|
|
41
|
+
const date = new Date().getTime();
|
|
42
|
+
this.setContents(Object.fromEntries(Object.entries(contents).filter(([, value]) => !this.isExpired(date, value))));
|
|
43
|
+
}
|
|
44
|
+
// eslint-disable-next-line class-methods-use-this
|
|
45
|
+
timestamp(value) {
|
|
46
|
+
return { ...value, timestamp: new Date().toISOString() };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.TTLConfig = TTLConfig;
|
|
50
|
+
//# sourceMappingURL=ttlConfig.js.map
|
package/lib/crypto/crypto.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Licensed under the BSD 3-Clause license.
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
8
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
10
|
exports.Crypto = void 0;
|
|
10
11
|
const crypto = require("crypto");
|
|
@@ -14,6 +15,8 @@ const ts_types_1 = require("@salesforce/ts-types");
|
|
|
14
15
|
const kit_1 = require("@salesforce/kit");
|
|
15
16
|
const logger_1 = require("../logger");
|
|
16
17
|
const messages_1 = require("../messages");
|
|
18
|
+
const cache_1 = require("../util/cache");
|
|
19
|
+
const global_1 = require("../global");
|
|
17
20
|
const keyChain_1 = require("./keyChain");
|
|
18
21
|
const secureBuffer_1 = require("./secureBuffer");
|
|
19
22
|
const TAG_DELIMITER = ':';
|
|
@@ -23,13 +26,12 @@ const AUTH_TAG_LENGTH = 32;
|
|
|
23
26
|
const ENCRYPTED_CHARS = /[a-f0-9]/;
|
|
24
27
|
const KEY_NAME = 'sfdx';
|
|
25
28
|
const ACCOUNT = 'local';
|
|
26
|
-
messages_1.Messages
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
'
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
]);
|
|
29
|
+
const messages = new messages_1.Messages('@salesforce/core', 'encryption', new Map([["invalidEncryptedFormatError", "The encrypted data is not properly formatted."], ["invalidEncryptedFormatError.actions", ["If attempting to create a scratch org then re-authorize. Otherwise create a new scratch org."]], ["authDecryptError", "Failed to decipher auth data. reason: %s."], ["unsupportedOperatingSystemError", "Unsupported Operating System: %s"], ["missingCredentialProgramError", "Unable to find required security software: %s"], ["credentialProgramAccessError", "Unable to execute security software: %s"], ["passwordRetryError", "Failed to get the password after %i retries."], ["passwordRequiredError", "A password is required."], ["keyChainServiceRequiredError", "Unable to get or set a keychain value without a service name."], ["keyChainAccountRequiredError", "Unable to get or set a keychain value without an account name."], ["keyChainUserCanceledError", "User canceled authentication."], ["keychainPasswordCreationError", "Failed to create a password in the keychain."], ["genericKeychainServiceError", "The service and account specified in %s do not match the version of the toolbelt."], ["genericKeychainServiceError.actions", ["Check your toolbelt version and re-auth."]], ["genericKeychainInvalidPermsError", "Invalid file permissions for secret file"], ["genericKeychainInvalidPermsError.actions", ["Ensure the file %s has the file permission octal value of %s."]], ["passwordNotFoundError", "Could not find password.\n%s"], ["passwordNotFoundError.actions", ["Ensure a valid password is returned with the following command: [%s]"]], ["setCredentialError", "Command failed with response:\n%s"], ["setCredentialError.actions", ["Determine why this command failed to set an encryption key for user %s: [%s]."]], ["macKeychainOutOfSync", "We\u2019ve encountered an error with the Mac keychain being out of sync with your `sfdx` credentials. To fix the problem, sync your credentials by authenticating into your org again using the auth commands."]]));
|
|
30
|
+
const makeSecureBuffer = (password) => {
|
|
31
|
+
const newSb = new secureBuffer_1.SecureBuffer();
|
|
32
|
+
newSb.consume(Buffer.from((0, ts_types_1.ensure)(password), 'utf8'));
|
|
33
|
+
return newSb;
|
|
34
|
+
};
|
|
33
35
|
/**
|
|
34
36
|
* osxKeyChain promise wrapper.
|
|
35
37
|
*/
|
|
@@ -42,11 +44,21 @@ const keychainPromises = {
|
|
|
42
44
|
* @param account The keychain account name.
|
|
43
45
|
*/
|
|
44
46
|
getPassword(_keychain, service, account) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return resolve({
|
|
49
|
-
|
|
47
|
+
const cacheKey = `${global_1.Global.DIR}:${service}:${account}`;
|
|
48
|
+
const sb = cache_1.Cache.get(cacheKey);
|
|
49
|
+
if (!sb) {
|
|
50
|
+
return new Promise((resolve, reject) => _keychain.getPassword({ service, account }, (err, password) => {
|
|
51
|
+
if (err)
|
|
52
|
+
return reject(err);
|
|
53
|
+
cache_1.Cache.set(cacheKey, makeSecureBuffer(password));
|
|
54
|
+
return resolve({ username: account, password: (0, ts_types_1.ensure)(password) });
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const pw = sb.value((buffer) => buffer.toString('utf8'));
|
|
59
|
+
cache_1.Cache.set(cacheKey, makeSecureBuffer(pw));
|
|
60
|
+
return new Promise((resolve) => resolve({ username: account, password: (0, ts_types_1.ensure)(pw) }));
|
|
61
|
+
}
|
|
50
62
|
},
|
|
51
63
|
/**
|
|
52
64
|
* Sets a generic password item in OSX keychain.
|
|
@@ -78,7 +90,7 @@ class Crypto extends kit_1.AsyncOptionalCreatable {
|
|
|
78
90
|
constructor(options) {
|
|
79
91
|
super(options);
|
|
80
92
|
this.key = new secureBuffer_1.SecureBuffer();
|
|
81
|
-
this.options = options
|
|
93
|
+
this.options = options ?? {};
|
|
82
94
|
}
|
|
83
95
|
encrypt(text) {
|
|
84
96
|
if (text == null) {
|
|
@@ -117,7 +129,7 @@ class Crypto extends kit_1.AsyncOptionalCreatable {
|
|
|
117
129
|
}
|
|
118
130
|
catch (err) {
|
|
119
131
|
const error = messages.createError('authDecryptError', [err.message], [], err);
|
|
120
|
-
const useGenericUnixKeychain = kit_1.env.getBoolean('
|
|
132
|
+
const useGenericUnixKeychain = kit_1.env.getBoolean('SF_USE_GENERIC_UNIX_KEYCHAIN') || kit_1.env.getBoolean('USE_GENERIC_UNIX_KEYCHAIN');
|
|
121
133
|
if (os.platform() === 'darwin' && !useGenericUnixKeychain) {
|
|
122
134
|
error.actions = [messages.getMessage('macKeychainOutOfSync')];
|
|
123
135
|
}
|
|
@@ -133,6 +145,7 @@ class Crypto extends kit_1.AsyncOptionalCreatable {
|
|
|
133
145
|
* @param text The text
|
|
134
146
|
* @returns true if the text is encrypted, false otherwise.
|
|
135
147
|
*/
|
|
148
|
+
// eslint-disable-next-line class-methods-use-this
|
|
136
149
|
isEncrypted(text) {
|
|
137
150
|
if (text == null) {
|
|
138
151
|
return false;
|
|
@@ -183,7 +196,7 @@ class Crypto extends kit_1.AsyncOptionalCreatable {
|
|
|
183
196
|
}
|
|
184
197
|
const key = crypto.randomBytes(Math.ceil(16)).toString('hex');
|
|
185
198
|
// Create a new password in the KeyChain.
|
|
186
|
-
await keychainPromises.setPassword(ts_types_1.ensure(this.options.keychain), KEY_NAME, ACCOUNT, key);
|
|
199
|
+
await keychainPromises.setPassword((0, ts_types_1.ensure)(this.options.keychain), KEY_NAME, ACCOUNT, key);
|
|
187
200
|
return this.init();
|
|
188
201
|
}
|
|
189
202
|
else {
|
|
@@ -193,7 +206,7 @@ class Crypto extends kit_1.AsyncOptionalCreatable {
|
|
|
193
206
|
}
|
|
194
207
|
async getKeyChain(platform) {
|
|
195
208
|
if (!this.options.keychain) {
|
|
196
|
-
this.options.keychain = await keyChain_1.retrieveKeychain(platform);
|
|
209
|
+
this.options.keychain = await (0, keyChain_1.retrieveKeychain)(platform);
|
|
197
210
|
}
|
|
198
211
|
return this.options.keychain;
|
|
199
212
|
}
|
package/lib/crypto/keyChain.js
CHANGED
|
@@ -11,18 +11,17 @@ const kit_1 = require("@salesforce/kit");
|
|
|
11
11
|
const logger_1 = require("../logger");
|
|
12
12
|
const messages_1 = require("../messages");
|
|
13
13
|
const keyChainImpl_1 = require("./keyChainImpl");
|
|
14
|
-
messages_1.Messages.
|
|
15
|
-
const messages = messages_1.Messages.load('@salesforce/core', 'encryption', ['unsupportedOperatingSystemError']);
|
|
14
|
+
const messages = new messages_1.Messages('@salesforce/core', 'encryption', new Map([["invalidEncryptedFormatError", "The encrypted data is not properly formatted."], ["invalidEncryptedFormatError.actions", ["If attempting to create a scratch org then re-authorize. Otherwise create a new scratch org."]], ["authDecryptError", "Failed to decipher auth data. reason: %s."], ["unsupportedOperatingSystemError", "Unsupported Operating System: %s"], ["missingCredentialProgramError", "Unable to find required security software: %s"], ["credentialProgramAccessError", "Unable to execute security software: %s"], ["passwordRetryError", "Failed to get the password after %i retries."], ["passwordRequiredError", "A password is required."], ["keyChainServiceRequiredError", "Unable to get or set a keychain value without a service name."], ["keyChainAccountRequiredError", "Unable to get or set a keychain value without an account name."], ["keyChainUserCanceledError", "User canceled authentication."], ["keychainPasswordCreationError", "Failed to create a password in the keychain."], ["genericKeychainServiceError", "The service and account specified in %s do not match the version of the toolbelt."], ["genericKeychainServiceError.actions", ["Check your toolbelt version and re-auth."]], ["genericKeychainInvalidPermsError", "Invalid file permissions for secret file"], ["genericKeychainInvalidPermsError.actions", ["Ensure the file %s has the file permission octal value of %s."]], ["passwordNotFoundError", "Could not find password.\n%s"], ["passwordNotFoundError.actions", ["Ensure a valid password is returned with the following command: [%s]"]], ["setCredentialError", "Command failed with response:\n%s"], ["setCredentialError.actions", ["Determine why this command failed to set an encryption key for user %s: [%s]."]], ["macKeychainOutOfSync", "We\u2019ve encountered an error with the Mac keychain being out of sync with your `sfdx` credentials. To fix the problem, sync your credentials by authenticating into your org again using the auth commands."]]));
|
|
16
15
|
/**
|
|
17
16
|
* Gets the os level keychain impl.
|
|
18
17
|
*
|
|
19
18
|
* @param platform The os platform.
|
|
20
19
|
* @ignore
|
|
21
20
|
*/
|
|
22
|
-
|
|
21
|
+
const retrieveKeychain = async (platform) => {
|
|
23
22
|
const logger = await logger_1.Logger.child('keyChain');
|
|
24
23
|
logger.debug(`platform: ${platform}`);
|
|
25
|
-
const useGenericUnixKeychainVar = kit_1.env.getBoolean('
|
|
24
|
+
const useGenericUnixKeychainVar = kit_1.env.getBoolean('SF_USE_GENERIC_UNIX_KEYCHAIN');
|
|
26
25
|
const shouldUseGenericUnixKeychain = useGenericUnixKeychainVar && useGenericUnixKeychainVar;
|
|
27
26
|
if (platform.startsWith('win')) {
|
|
28
27
|
return keyChainImpl_1.keyChainImpl.generic_windows;
|
|
@@ -58,4 +57,5 @@ exports.retrieveKeychain = async (platform) => {
|
|
|
58
57
|
throw messages.createError('unsupportedOperatingSystemError', [platform]);
|
|
59
58
|
}
|
|
60
59
|
};
|
|
60
|
+
exports.retrieveKeychain = retrieveKeychain;
|
|
61
61
|
//# sourceMappingURL=keyChain.js.map
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/// <reference types="node" />
|
|
2
4
|
import * as childProcess from 'child_process';
|
|
3
5
|
import * as nodeFs from 'fs';
|
|
4
6
|
import { Nullable } from '@salesforce/ts-types';
|
|
5
|
-
export
|
|
7
|
+
export type FsIfc = Pick<typeof nodeFs, 'statSync'>;
|
|
6
8
|
/**
|
|
7
9
|
* Basic keychain interface.
|
|
8
10
|
*/
|
|
@@ -75,7 +77,7 @@ declare enum SecretField {
|
|
|
75
77
|
ACCOUNT = "account",
|
|
76
78
|
KEY = "key"
|
|
77
79
|
}
|
|
78
|
-
|
|
80
|
+
type SecretContents = {
|
|
79
81
|
[SecretField.ACCOUNT]: string;
|
|
80
82
|
[SecretField.KEY]?: string;
|
|
81
83
|
[SecretField.SERVICE]: string;
|
|
@@ -110,5 +112,5 @@ export declare const keyChainImpl: {
|
|
|
110
112
|
linux: KeychainAccess;
|
|
111
113
|
validateProgram: (programPath: string, fsIfc: FsIfc, isExeIfc: (mode: number, gid: number, uid: number) => boolean) => Promise<void>;
|
|
112
114
|
};
|
|
113
|
-
export
|
|
115
|
+
export type KeyChain = GenericUnixKeychainAccess | GenericWindowsKeychainAccess | KeychainAccess;
|
|
114
116
|
export {};
|