@salesforce/core 3.19.1 → 3.19.4
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 +3 -2
- package/lib/org/authInfo.js +55 -37
- 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 -8
- 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/lib/util/sfdcUrl.d.ts +3 -9
- package/lib/util/sfdcUrl.js +29 -28
- package/messages/core.md +10 -0
- package/messages/scratchOrgCreate.md +0 -4
- package/messages/scratchOrgInfoApi.md +4 -0
- package/package.json +4 -4
- 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
|
@@ -317,7 +317,7 @@ const _darwinImpl = {
|
|
|
317
317
|
}
|
|
318
318
|
},
|
|
319
319
|
};
|
|
320
|
-
const getSecretFile = () => path.join(global_1.Global.
|
|
320
|
+
const getSecretFile = () => path.join(global_1.Global.DIR, 'key.json');
|
|
321
321
|
var SecretField;
|
|
322
322
|
(function (SecretField) {
|
|
323
323
|
SecretField["SERVICE"] = "service";
|
package/lib/exported.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { ConfigFile } from './config/configFile';
|
|
|
3
3
|
export { TTLConfig } from './config/ttlConfig';
|
|
4
4
|
export { envVars, EnvironmentVariable, SUPPORTED_ENV_VARS, EnvVars } from './config/envVars';
|
|
5
5
|
export { BaseConfigStore, ConfigContents, ConfigEntry, ConfigStore, ConfigValue } from './config/configStore';
|
|
6
|
-
export { GlobalInfo, SfEntry, SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfToken, SfTokens } from './
|
|
6
|
+
export { GlobalInfo, SfEntry, SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfToken, SfTokens, StateAggregator, } from './stateAggregator';
|
|
7
7
|
export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } from './deviceOauthService';
|
|
8
8
|
export { OrgUsersConfig } from './config/orgUsersConfig';
|
|
9
9
|
export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config, SfdxPropertyKeys, SfConfigProperties, SFDX_ALLOWED_PROPERTIES, SF_ALLOWED_PROPERTIES, } from './config/config';
|
package/lib/exported.js
CHANGED
|
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.
|
|
20
|
-
exports.ScratchOrgCache = exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = exports.scratchOrgResume = exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = void 0;
|
|
19
|
+
exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SfError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.SfProjectJson = exports.SfProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = exports.OrgTypes = exports.SandboxEvents = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.AuthInfo = exports.SfdxConfigAggregator = exports.ConfigAggregator = exports.SandboxRequestCache = exports.SF_ALLOWED_PROPERTIES = exports.SFDX_ALLOWED_PROPERTIES = exports.SfConfigProperties = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.StateAggregator = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.TTLConfig = exports.ConfigFile = void 0;
|
|
20
|
+
exports.ScratchOrgCache = exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = exports.scratchOrgResume = exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = void 0;
|
|
21
21
|
const messages_1 = require("./messages");
|
|
22
22
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
23
23
|
var configFile_1 = require("./config/configFile");
|
|
@@ -31,9 +31,10 @@ Object.defineProperty(exports, "SUPPORTED_ENV_VARS", { enumerable: true, get: fu
|
|
|
31
31
|
Object.defineProperty(exports, "EnvVars", { enumerable: true, get: function () { return envVars_1.EnvVars; } });
|
|
32
32
|
var configStore_1 = require("./config/configStore");
|
|
33
33
|
Object.defineProperty(exports, "BaseConfigStore", { enumerable: true, get: function () { return configStore_1.BaseConfigStore; } });
|
|
34
|
-
var
|
|
35
|
-
Object.defineProperty(exports, "GlobalInfo", { enumerable: true, get: function () { return
|
|
36
|
-
Object.defineProperty(exports, "SfInfoKeys", { enumerable: true, get: function () { return
|
|
34
|
+
var stateAggregator_1 = require("./stateAggregator");
|
|
35
|
+
Object.defineProperty(exports, "GlobalInfo", { enumerable: true, get: function () { return stateAggregator_1.GlobalInfo; } });
|
|
36
|
+
Object.defineProperty(exports, "SfInfoKeys", { enumerable: true, get: function () { return stateAggregator_1.SfInfoKeys; } });
|
|
37
|
+
Object.defineProperty(exports, "StateAggregator", { enumerable: true, get: function () { return stateAggregator_1.StateAggregator; } });
|
|
37
38
|
var deviceOauthService_1 = require("./deviceOauthService");
|
|
38
39
|
Object.defineProperty(exports, "DeviceOauthService", { enumerable: true, get: function () { return deviceOauthService_1.DeviceOauthService; } });
|
|
39
40
|
var orgUsersConfig_1 = require("./config/orgUsersConfig");
|
package/lib/global.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export declare class Global {
|
|
|
28
28
|
* The global folder in which sf state is stored.
|
|
29
29
|
*/
|
|
30
30
|
static readonly SF_STATE_FOLDER = ".sf";
|
|
31
|
+
/**
|
|
32
|
+
* The peferred global folder in which state is stored.
|
|
33
|
+
*/
|
|
34
|
+
static readonly STATE_FOLDER = ".sfdx";
|
|
31
35
|
/**
|
|
32
36
|
* The full system path to the global sfdx state folder.
|
|
33
37
|
*
|
|
@@ -40,6 +44,10 @@ export declare class Global {
|
|
|
40
44
|
* **See** {@link Global.SF_STATE_FOLDER}
|
|
41
45
|
*/
|
|
42
46
|
static get SF_DIR(): string;
|
|
47
|
+
/**
|
|
48
|
+
* The full system path to the peferred global state folder
|
|
49
|
+
*/
|
|
50
|
+
static get DIR(): string;
|
|
43
51
|
/**
|
|
44
52
|
* The full system path to the global log file.
|
|
45
53
|
*/
|
package/lib/global.js
CHANGED
|
@@ -44,6 +44,12 @@ class Global {
|
|
|
44
44
|
static get SF_DIR() {
|
|
45
45
|
return path.join(os.homedir(), Global.SF_STATE_FOLDER);
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The full system path to the peferred global state folder
|
|
49
|
+
*/
|
|
50
|
+
static get DIR() {
|
|
51
|
+
return path.join(os.homedir(), Global.SFDX_STATE_FOLDER);
|
|
52
|
+
}
|
|
47
53
|
/**
|
|
48
54
|
* Gets the current mode environment variable as a {@link Mode} instance.
|
|
49
55
|
*
|
|
@@ -80,6 +86,10 @@ Global.SFDX_STATE_FOLDER = '.sfdx';
|
|
|
80
86
|
* The global folder in which sf state is stored.
|
|
81
87
|
*/
|
|
82
88
|
Global.SF_STATE_FOLDER = '.sf';
|
|
89
|
+
/**
|
|
90
|
+
* The peferred global folder in which state is stored.
|
|
91
|
+
*/
|
|
92
|
+
Global.STATE_FOLDER = Global.SFDX_STATE_FOLDER;
|
|
83
93
|
/**
|
|
84
94
|
* The full system path to the global log file.
|
|
85
95
|
*/
|
package/lib/org/authInfo.d.ts
CHANGED
|
@@ -126,7 +126,7 @@ export declare const DEFAULT_CONNECTED_APP_INFO: {
|
|
|
126
126
|
export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
|
|
127
127
|
private usingAccessToken;
|
|
128
128
|
private logger;
|
|
129
|
-
private
|
|
129
|
+
private stateAggregator;
|
|
130
130
|
private username;
|
|
131
131
|
private options;
|
|
132
132
|
/**
|
|
@@ -289,7 +289,8 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
|
|
|
289
289
|
private loadDecryptedAuthFromConfig;
|
|
290
290
|
private isTokenOptions;
|
|
291
291
|
private refreshFn;
|
|
292
|
-
private
|
|
292
|
+
private authJwt;
|
|
293
|
+
private tryJwtAuth;
|
|
293
294
|
private buildRefreshTokenConfig;
|
|
294
295
|
/**
|
|
295
296
|
* Performs an authCode exchange but the Oauth2 feature of jsforce is extended to include a code_challenge
|
package/lib/org/authInfo.js
CHANGED
|
@@ -21,7 +21,7 @@ const configAggregator_1 = require("../config/configAggregator");
|
|
|
21
21
|
const logger_1 = require("../logger");
|
|
22
22
|
const sfError_1 = require("../sfError");
|
|
23
23
|
const sfdc_1 = require("../util/sfdc");
|
|
24
|
-
const
|
|
24
|
+
const stateAggregator_1 = require("../stateAggregator");
|
|
25
25
|
const messages_1 = require("../messages");
|
|
26
26
|
const sfdcUrl_1 = require("../util/sfdcUrl");
|
|
27
27
|
const connection_1 = require("./connection");
|
|
@@ -38,6 +38,7 @@ const messages = messages_1.Messages.load('@salesforce/core', 'core', [
|
|
|
38
38
|
'jwtAuthError',
|
|
39
39
|
'authCodeUsernameRetrievalError',
|
|
40
40
|
'authCodeExchangeError',
|
|
41
|
+
'missingClientId',
|
|
41
42
|
]);
|
|
42
43
|
// Extend OAuth2 to add JWT Bearer Token Flow support.
|
|
43
44
|
class JwtOAuth2 extends jsforce_1.OAuth2 {
|
|
@@ -144,13 +145,13 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
144
145
|
*/
|
|
145
146
|
static async listAllAuthorizations(orgAuthFilter = (orgAuth) => !!orgAuth) {
|
|
146
147
|
var _a;
|
|
147
|
-
const
|
|
148
|
+
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
148
149
|
const config = (await configAggregator_1.ConfigAggregator.create()).getConfigInfo();
|
|
149
|
-
const orgs =
|
|
150
|
+
const orgs = await stateAggregator.orgs.readAll();
|
|
150
151
|
const final = [];
|
|
151
152
|
for (const org of orgs) {
|
|
152
153
|
const username = (0, ts_types_1.ensureString)(org.username);
|
|
153
|
-
const aliases = (_a =
|
|
154
|
+
const aliases = (_a = stateAggregator.aliases.getAll(username)) !== null && _a !== void 0 ? _a : undefined;
|
|
154
155
|
// Get a list of configuration values that are set to either the username or one
|
|
155
156
|
// of the aliases
|
|
156
157
|
const configs = config
|
|
@@ -166,7 +167,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
166
167
|
instanceUrl,
|
|
167
168
|
isScratchOrg: Boolean(devHubUsername),
|
|
168
169
|
isDevHub: isDevHub || false,
|
|
169
|
-
isSandbox:
|
|
170
|
+
isSandbox: await stateAggregator.sandboxes.hasFile(orgId),
|
|
170
171
|
orgId: orgId,
|
|
171
172
|
accessToken: authInfo.getConnectionOptions().accessToken,
|
|
172
173
|
oauthMethod: authInfo.isJwt() ? 'jwt' : authInfo.isOauth() ? 'web' : 'token',
|
|
@@ -196,7 +197,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
196
197
|
*/
|
|
197
198
|
static async hasAuthentications() {
|
|
198
199
|
try {
|
|
199
|
-
const auths = (await
|
|
200
|
+
const auths = await (await stateAggregator_1.StateAggregator.getInstance()).orgs.list();
|
|
200
201
|
return !(0, kit_1.isEmpty)(auths);
|
|
201
202
|
}
|
|
202
203
|
catch (err) {
|
|
@@ -295,7 +296,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
295
296
|
* Find all dev hubs available in the local environment.
|
|
296
297
|
*/
|
|
297
298
|
static async getDevHubAuthInfos() {
|
|
298
|
-
return
|
|
299
|
+
return await AuthInfo.listAllAuthorizations((possibleHub) => { var _a; return (_a = possibleHub === null || possibleHub === void 0 ? void 0 : possibleHub.isDevHub) !== null && _a !== void 0 ? _a : false; });
|
|
299
300
|
}
|
|
300
301
|
static async queryScratchOrg(devHubUsername, scratchOrgId) {
|
|
301
302
|
const devHubOrg = await org_1.Org.create({ aliasOrUsername: devHubUsername });
|
|
@@ -348,7 +349,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
348
349
|
this.logger.debug('Username is an accesstoken. Skip saving authinfo to disk.');
|
|
349
350
|
return this;
|
|
350
351
|
}
|
|
351
|
-
await this.
|
|
352
|
+
await this.stateAggregator.orgs.write(username);
|
|
352
353
|
this.logger.info(`Saved auth info for username: ${username}`);
|
|
353
354
|
return this;
|
|
354
355
|
}
|
|
@@ -359,13 +360,10 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
359
360
|
* @param authData Authorization fields to update.
|
|
360
361
|
*/
|
|
361
362
|
update(authData) {
|
|
362
|
-
// todo move into configstore
|
|
363
363
|
if (authData && (0, ts_types_1.isPlainObject)(authData)) {
|
|
364
364
|
this.username = authData.username || this.username;
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
this.globalInfo.orgs.set(this.getUsername(), mergedFields);
|
|
368
|
-
this.logger.info(`Updated auth info for username: ${this.getUsername()}`);
|
|
365
|
+
this.stateAggregator.orgs.update(this.username, authData);
|
|
366
|
+
this.logger.info(`Updated auth info for username: ${this.username}`);
|
|
369
367
|
}
|
|
370
368
|
return this;
|
|
371
369
|
}
|
|
@@ -423,7 +421,8 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
423
421
|
* @param decrypt Decrypt the fields.
|
|
424
422
|
*/
|
|
425
423
|
getFields(decrypt) {
|
|
426
|
-
|
|
424
|
+
var _a;
|
|
425
|
+
return (_a = this.stateAggregator.orgs.get(this.username, decrypt)) !== null && _a !== void 0 ? _a : {};
|
|
427
426
|
}
|
|
428
427
|
/**
|
|
429
428
|
* Get the org front door (used for web based oauth flows)
|
|
@@ -498,7 +497,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
498
497
|
config = await config_1.Config.create({ isGlobal: true });
|
|
499
498
|
}
|
|
500
499
|
const username = (0, ts_types_1.ensureString)(this.getUsername());
|
|
501
|
-
const alias = this.
|
|
500
|
+
const alias = this.stateAggregator.aliases.get(username);
|
|
502
501
|
const value = alias !== null && alias !== void 0 ? alias : username;
|
|
503
502
|
if (options.org) {
|
|
504
503
|
config.set(orgConfigProperties_1.OrgConfigProperties.TARGET_ORG, value);
|
|
@@ -514,14 +513,14 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
514
513
|
* @param alias alias to set
|
|
515
514
|
*/
|
|
516
515
|
async setAlias(alias) {
|
|
517
|
-
this.
|
|
516
|
+
this.stateAggregator.aliases.set(alias, this.getUsername());
|
|
517
|
+
await this.stateAggregator.aliases.write();
|
|
518
518
|
}
|
|
519
519
|
/**
|
|
520
520
|
* Initializes an instance of the AuthInfo class.
|
|
521
521
|
*/
|
|
522
522
|
async init() {
|
|
523
|
-
|
|
524
|
-
this.globalInfo = await globalInfo_1.GlobalInfo.getInstance();
|
|
523
|
+
this.stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
525
524
|
const username = this.options.username;
|
|
526
525
|
const authOptions = this.options.oauth2Options || this.options.accessTokenOptions;
|
|
527
526
|
// Must specify either username and/or options
|
|
@@ -531,14 +530,14 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
531
530
|
// If a username AND oauth options, ensure an authorization for the username doesn't
|
|
532
531
|
// already exist. Throw if it does so we don't overwrite the authorization.
|
|
533
532
|
if (username && authOptions) {
|
|
534
|
-
|
|
535
|
-
if (authExists) {
|
|
533
|
+
if (await this.stateAggregator.orgs.hasFile(username)) {
|
|
536
534
|
throw messages.createError('authInfoOverwriteError');
|
|
537
535
|
}
|
|
538
536
|
}
|
|
539
537
|
const oauthUsername = username || (0, ts_types_1.getString)(authOptions, 'username');
|
|
540
538
|
if (oauthUsername) {
|
|
541
539
|
this.username = oauthUsername;
|
|
540
|
+
await this.stateAggregator.orgs.read(oauthUsername, false, false);
|
|
542
541
|
} // Else it will be set in initAuthOptions below.
|
|
543
542
|
// If the username is an access token, use that for auth and don't persist
|
|
544
543
|
if ((0, ts_types_1.isString)(oauthUsername) && sfdc_1.sfdc.matchesAccessToken(oauthUsername)) {
|
|
@@ -555,7 +554,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
555
554
|
this.usingAccessToken = true;
|
|
556
555
|
}
|
|
557
556
|
// If a username with NO oauth options, ensure authorization already exist.
|
|
558
|
-
else if (username && !authOptions && !this.
|
|
557
|
+
else if (username && !authOptions && !(await this.stateAggregator.orgs.exists(username))) {
|
|
559
558
|
throw messages.createError('namedOrgNotFound', [username]);
|
|
560
559
|
}
|
|
561
560
|
else {
|
|
@@ -607,7 +606,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
607
606
|
options.privateKey = (0, path_1.resolve)(options.privateKeyFile);
|
|
608
607
|
}
|
|
609
608
|
if (options.privateKey) {
|
|
610
|
-
authConfig = await this.
|
|
609
|
+
authConfig = await this.authJwt(options);
|
|
611
610
|
}
|
|
612
611
|
else if (!options.authCode && options.refreshToken) {
|
|
613
612
|
// refresh token flow (from sfdxUrl or OAuth refreshFn)
|
|
@@ -624,6 +623,8 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
624
623
|
}
|
|
625
624
|
}
|
|
626
625
|
authConfig.isDevHub = await this.determineIfDevHub((0, ts_types_1.ensureString)(authConfig.instanceUrl), (0, ts_types_1.ensureString)(authConfig.accessToken));
|
|
626
|
+
if (authConfig.username)
|
|
627
|
+
await this.stateAggregator.orgs.read(authConfig.username, false, false);
|
|
627
628
|
// Update the auth fields WITH encryption
|
|
628
629
|
this.update(authConfig);
|
|
629
630
|
}
|
|
@@ -631,7 +632,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
631
632
|
}
|
|
632
633
|
async loadDecryptedAuthFromConfig(username) {
|
|
633
634
|
// Fetch from the persisted auth file
|
|
634
|
-
const authInfo = this.
|
|
635
|
+
const authInfo = this.stateAggregator.orgs.get(username, true);
|
|
635
636
|
if (!authInfo) {
|
|
636
637
|
throw messages.createError('namedOrgNotFound', [username]);
|
|
637
638
|
}
|
|
@@ -667,27 +668,32 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
667
668
|
}
|
|
668
669
|
}
|
|
669
670
|
// Build OAuth config for a JWT auth flow
|
|
670
|
-
async
|
|
671
|
+
async authJwt(options) {
|
|
672
|
+
if (!options.clientId) {
|
|
673
|
+
throw messages.createError('missingClientId');
|
|
674
|
+
}
|
|
671
675
|
const privateKeyContents = await fs.promises.readFile((0, ts_types_1.ensure)(options.privateKey), 'utf8');
|
|
672
676
|
const { loginUrl = sfdcUrl_1.SfdcUrl.PRODUCTION } = options;
|
|
673
677
|
const url = new sfdcUrl_1.SfdcUrl(loginUrl);
|
|
674
678
|
const createdOrgInstance = (0, ts_types_1.getString)(options, 'createdOrgInstance', '').trim().toLowerCase();
|
|
675
679
|
const audienceUrl = await url.getJwtAudienceUrl(createdOrgInstance);
|
|
676
|
-
const jwtToken = jwt.sign({
|
|
677
|
-
iss: options.clientId,
|
|
678
|
-
sub: this.getUsername(),
|
|
679
|
-
aud: audienceUrl,
|
|
680
|
-
exp: Date.now() + 300,
|
|
681
|
-
}, privateKeyContents, {
|
|
682
|
-
algorithm: 'RS256',
|
|
683
|
-
});
|
|
684
|
-
const oauth2 = new JwtOAuth2({ loginUrl: options.loginUrl });
|
|
685
680
|
let authFieldsBuilder;
|
|
686
|
-
|
|
687
|
-
|
|
681
|
+
const authErrors = [];
|
|
682
|
+
// given that we can no longer depend on instance names or URls to determine audience, let's try them all
|
|
683
|
+
const loginAndAudienceUrls = (0, sfdcUrl_1.getLoginAudienceCombos)(audienceUrl, loginUrl);
|
|
684
|
+
for (const [login, audience] of loginAndAudienceUrls) {
|
|
685
|
+
try {
|
|
686
|
+
authFieldsBuilder = await this.tryJwtAuth(options.clientId, login, audience, privateKeyContents);
|
|
687
|
+
break;
|
|
688
|
+
}
|
|
689
|
+
catch (err) {
|
|
690
|
+
const error = err;
|
|
691
|
+
const message = error.message.includes('audience') ? `${error.message}-${login}:${audience}` : error.message;
|
|
692
|
+
authErrors.push(message);
|
|
693
|
+
}
|
|
688
694
|
}
|
|
689
|
-
|
|
690
|
-
throw messages.createError('jwtAuthError', [
|
|
695
|
+
if (!authFieldsBuilder) {
|
|
696
|
+
throw messages.createError('jwtAuthError', [authErrors.join('\n')]);
|
|
691
697
|
}
|
|
692
698
|
const authFields = {
|
|
693
699
|
accessToken: (0, ts_types_1.asString)(authFieldsBuilder.access_token),
|
|
@@ -709,6 +715,18 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
709
715
|
}
|
|
710
716
|
return authFields;
|
|
711
717
|
}
|
|
718
|
+
async tryJwtAuth(clientId, loginUrl, audienceUrl, privateKeyContents) {
|
|
719
|
+
const jwtToken = jwt.sign({
|
|
720
|
+
iss: clientId,
|
|
721
|
+
sub: this.getUsername(),
|
|
722
|
+
aud: audienceUrl,
|
|
723
|
+
exp: Date.now() + 300,
|
|
724
|
+
}, privateKeyContents, {
|
|
725
|
+
algorithm: 'RS256',
|
|
726
|
+
});
|
|
727
|
+
const oauth2 = new JwtOAuth2({ loginUrl });
|
|
728
|
+
return (0, ts_types_1.ensureJsonMap)(await oauth2.jwtAuthorize(jwtToken));
|
|
729
|
+
}
|
|
712
730
|
// Build OAuth config for a refresh token auth flow
|
|
713
731
|
async buildRefreshTokenConfig(options) {
|
|
714
732
|
// Ideally, this would be removed at some point in the distant future when all auth files
|
package/lib/org/authRemover.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
2
|
-
import {
|
|
2
|
+
import { JsonMap } from '@salesforce/ts-types';
|
|
3
|
+
import { AuthFields } from '.';
|
|
3
4
|
/**
|
|
4
5
|
* Handles the removing of authorizations, which includes deleting the auth file
|
|
5
6
|
* in the global .sfdx folder, deleting any configs that are associated with the username/alias,
|
|
@@ -25,7 +26,7 @@ import { SfOrg, SfOrgs } from '../globalInfo';
|
|
|
25
26
|
*/
|
|
26
27
|
export declare class AuthRemover extends AsyncOptionalCreatable {
|
|
27
28
|
private config;
|
|
28
|
-
private
|
|
29
|
+
private stateAggregator;
|
|
29
30
|
private logger;
|
|
30
31
|
/**
|
|
31
32
|
* Removes the authentication and any configs or aliases associated with it
|
|
@@ -45,13 +46,13 @@ export declare class AuthRemover extends AsyncOptionalCreatable {
|
|
|
45
46
|
* @param usernameOrAlias username or alias of the auth you want to find, defaults to the configured target-org
|
|
46
47
|
* @returns {Promise<SfOrg>}
|
|
47
48
|
*/
|
|
48
|
-
findAuth(usernameOrAlias?: string): Promise<
|
|
49
|
+
findAuth(usernameOrAlias?: string): Promise<AuthFields>;
|
|
49
50
|
/**
|
|
50
51
|
* Finds all org authorizations in the global info file (.sf/sf.json)
|
|
51
52
|
*
|
|
52
|
-
* @returns {
|
|
53
|
+
* @returns {Record<string, AuthFields>}
|
|
53
54
|
*/
|
|
54
|
-
findAllAuths():
|
|
55
|
+
findAllAuths(): Record<string, AuthFields & JsonMap>;
|
|
55
56
|
protected init(): Promise<void>;
|
|
56
57
|
/**
|
|
57
58
|
* Returns the username for a given alias if the alias exists.
|
package/lib/org/authRemover.js
CHANGED
|
@@ -11,7 +11,7 @@ const kit_1 = require("@salesforce/kit");
|
|
|
11
11
|
const configAggregator_1 = require("../config/configAggregator");
|
|
12
12
|
const logger_1 = require("../logger");
|
|
13
13
|
const messages_1 = require("../messages");
|
|
14
|
-
const
|
|
14
|
+
const stateAggregator_1 = require("../stateAggregator");
|
|
15
15
|
const orgConfigProperties_1 = require("./orgConfigProperties");
|
|
16
16
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
17
17
|
const coreMessages = messages_1.Messages.load('@salesforce/core', 'core', ['namedOrgNotFound']);
|
|
@@ -50,9 +50,8 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
|
|
|
50
50
|
this.logger.debug(`Removing authorization for user ${username}`);
|
|
51
51
|
await this.unsetConfigValues(username);
|
|
52
52
|
await this.unsetAliases(username);
|
|
53
|
-
this.unsetTokens(username);
|
|
54
|
-
this.
|
|
55
|
-
await this.globalInfo.write();
|
|
53
|
+
await this.unsetTokens(username);
|
|
54
|
+
await this.stateAggregator.orgs.remove(username);
|
|
56
55
|
}
|
|
57
56
|
/**
|
|
58
57
|
* Removes all authentication files and any configs or aliases associated with them
|
|
@@ -73,8 +72,8 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
|
|
|
73
72
|
* @returns {Promise<SfOrg>}
|
|
74
73
|
*/
|
|
75
74
|
async findAuth(usernameOrAlias) {
|
|
76
|
-
const username =
|
|
77
|
-
const auth = this.
|
|
75
|
+
const username = await this.resolveUsername(usernameOrAlias || this.getTargetOrg());
|
|
76
|
+
const auth = this.stateAggregator.orgs.get(username);
|
|
78
77
|
if (!auth) {
|
|
79
78
|
throw coreMessages.createError('namedOrgNotFound');
|
|
80
79
|
}
|
|
@@ -83,15 +82,20 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
|
|
|
83
82
|
/**
|
|
84
83
|
* Finds all org authorizations in the global info file (.sf/sf.json)
|
|
85
84
|
*
|
|
86
|
-
* @returns {
|
|
85
|
+
* @returns {Record<string, AuthFields>}
|
|
87
86
|
*/
|
|
88
87
|
findAllAuths() {
|
|
89
|
-
|
|
88
|
+
const orgs = this.stateAggregator.orgs.getAll();
|
|
89
|
+
return orgs.reduce((x, y) => {
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
91
|
+
return { ...x, [y.username]: y };
|
|
92
|
+
}, {});
|
|
90
93
|
}
|
|
91
94
|
async init() {
|
|
92
95
|
this.logger = await logger_1.Logger.child(this.constructor.name);
|
|
93
96
|
this.config = await configAggregator_1.ConfigAggregator.create();
|
|
94
|
-
this.
|
|
97
|
+
this.stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
98
|
+
await this.stateAggregator.orgs.readAll();
|
|
95
99
|
}
|
|
96
100
|
/**
|
|
97
101
|
* Returns the username for a given alias if the alias exists.
|
|
@@ -100,7 +104,7 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
|
|
|
100
104
|
* @returns {Promise<string>}
|
|
101
105
|
*/
|
|
102
106
|
async resolveUsername(usernameOrAlias) {
|
|
103
|
-
return this.
|
|
107
|
+
return this.stateAggregator.aliases.resolveUsername(usernameOrAlias);
|
|
104
108
|
}
|
|
105
109
|
/**
|
|
106
110
|
* @returns {string}
|
|
@@ -119,7 +123,7 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
|
|
|
119
123
|
* @returns {Promise<string[]>}
|
|
120
124
|
*/
|
|
121
125
|
getAliases(username) {
|
|
122
|
-
return this.
|
|
126
|
+
return this.stateAggregator.aliases.getAll(username);
|
|
123
127
|
}
|
|
124
128
|
/**
|
|
125
129
|
* Unsets any configured values (both global and local) for provided username
|
|
@@ -158,20 +162,22 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
|
|
|
158
162
|
*/
|
|
159
163
|
async unsetAliases(username) {
|
|
160
164
|
this.logger.debug(`Clearing aliases for username: ${username}`);
|
|
161
|
-
const existingAliases = this.
|
|
165
|
+
const existingAliases = this.stateAggregator.aliases.getAll(username);
|
|
162
166
|
if (existingAliases.length === 0)
|
|
163
167
|
return;
|
|
164
168
|
this.logger.debug(`Found these aliases to remove: ${existingAliases}`);
|
|
165
|
-
existingAliases.forEach((alias) => this.
|
|
169
|
+
existingAliases.forEach((alias) => this.stateAggregator.aliases.unset(alias));
|
|
170
|
+
await this.stateAggregator.aliases.write();
|
|
166
171
|
}
|
|
167
|
-
unsetTokens(username) {
|
|
172
|
+
async unsetTokens(username) {
|
|
168
173
|
this.logger.debug(`Clearing tokens for username: ${username}`);
|
|
169
|
-
const tokens = this.
|
|
174
|
+
const tokens = this.stateAggregator.tokens.getAll();
|
|
170
175
|
for (const [key, token] of Object.entries(tokens)) {
|
|
171
176
|
if (token.user === username) {
|
|
172
|
-
this.
|
|
177
|
+
this.stateAggregator.tokens.unset(key);
|
|
173
178
|
}
|
|
174
179
|
}
|
|
180
|
+
await this.stateAggregator.tokens.write();
|
|
175
181
|
}
|
|
176
182
|
}
|
|
177
183
|
exports.AuthRemover = AuthRemover;
|
package/lib/org/connection.js
CHANGED
|
@@ -293,7 +293,7 @@ class Connection extends jsforce_1.Connection {
|
|
|
293
293
|
* Getter for the AuthInfo fields.
|
|
294
294
|
*/
|
|
295
295
|
getAuthInfoFields() {
|
|
296
|
-
// If the
|
|
296
|
+
// If the StateAggregator.orgs.remove is called, the AuthFields are no longer accessible.
|
|
297
297
|
return this.options.authInfo.getFields() || {};
|
|
298
298
|
}
|
|
299
299
|
/**
|
package/lib/org/org.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { AsyncOptionalCreatable, Duration } from '@salesforce/kit';
|
|
|
2
2
|
import { AnyJson, JsonMap, Nullable, Optional } from '@salesforce/ts-types';
|
|
3
3
|
import { ConfigAggregator } from '../config/configAggregator';
|
|
4
4
|
import { OrgUsersConfig } from '../config/orgUsersConfig';
|
|
5
|
-
import { SfSandbox } from '../globalInfo';
|
|
6
5
|
import { Connection } from './connection';
|
|
7
6
|
import { AuthFields, AuthInfo } from './authInfo';
|
|
8
7
|
import { ScratchOrgCreateOptions, ScratchOrgCreateResult } from './scratchOrgCreate';
|
|
@@ -70,6 +69,14 @@ export declare type ResumeSandboxRequest = {
|
|
|
70
69
|
SandboxProcessObjId?: string;
|
|
71
70
|
};
|
|
72
71
|
export declare type ScratchOrgRequest = Pick<ScratchOrgCreateOptions, 'connectedAppConsumerKey' | 'durationDays' | 'nonamespace' | 'noancestors' | 'wait' | 'retry' | 'apiversion' | 'definitionjson' | 'definitionfile' | 'orgConfig' | 'clientSecret'>;
|
|
72
|
+
export declare type SandboxFields = {
|
|
73
|
+
sandboxOrgId: string;
|
|
74
|
+
prodOrgUsername: string;
|
|
75
|
+
sandboxName?: string;
|
|
76
|
+
sandboxUsername?: string;
|
|
77
|
+
sandboxProcessId?: string;
|
|
78
|
+
sandboxInfoId?: string;
|
|
79
|
+
};
|
|
73
80
|
/**
|
|
74
81
|
* Provides a way to manage a locally authenticated Org.
|
|
75
82
|
*
|
|
@@ -312,15 +319,15 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
|
|
|
312
319
|
* set the sandbox config related to this given org
|
|
313
320
|
*
|
|
314
321
|
* @param orgId {string} orgId of the sandbox
|
|
315
|
-
* @param config {
|
|
322
|
+
* @param config {SandboxFields} config of the sandbox
|
|
316
323
|
*/
|
|
317
|
-
setSandboxConfig(orgId: string, config:
|
|
324
|
+
setSandboxConfig(orgId: string, config: SandboxFields): Promise<Org>;
|
|
318
325
|
/**
|
|
319
326
|
* get the sandbox config for the given orgId
|
|
320
327
|
*
|
|
321
328
|
* @param orgId {string} orgId of the sandbox
|
|
322
329
|
*/
|
|
323
|
-
getSandboxConfig(orgId: string): Promise<Nullable<
|
|
330
|
+
getSandboxConfig(orgId: string): Promise<Nullable<SandboxFields>>;
|
|
324
331
|
/**
|
|
325
332
|
* Retrieves the highest api version that is supported by the target server instance. If the apiVersion configured for
|
|
326
333
|
* Sfdx is greater than the one returned in this call an api version mismatch occurs. In the case of the CLI that
|
|
@@ -381,6 +388,7 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
|
|
|
381
388
|
* **Throws** *{@link SfError}{ name: 'NotSupportedError' }* Throws an unsupported error.
|
|
382
389
|
*/
|
|
383
390
|
protected getDefaultOptions(): Org.Options;
|
|
391
|
+
private getLocalDataDir;
|
|
384
392
|
/**
|
|
385
393
|
* Gets the sandboxProcessObject and then polls for it to complete.
|
|
386
394
|
*
|