@salesforce/core 3.19.0 → 3.19.3
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 +7 -5
- package/lib/config/configAggregator.js +25 -9
- 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/envVars.d.ts +2 -3
- package/lib/config/envVars.js +8 -13
- 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 +3 -2
- 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 +50 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +197 -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
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
|
@@ -21,6 +21,7 @@ const sfError_1 = require("../sfError");
|
|
|
21
21
|
const sfdc_1 = require("../util/sfdc");
|
|
22
22
|
const messages_1 = require("../messages");
|
|
23
23
|
const lifecycleEvents_1 = require("../lifecycleEvents");
|
|
24
|
+
const orgConfigProperties_1 = require("./orgConfigProperties");
|
|
24
25
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
25
26
|
const messages = messages_1.Messages.load('@salesforce/core', 'connection', [
|
|
26
27
|
'incorrectAPIVersionError',
|
|
@@ -292,7 +293,7 @@ class Connection extends jsforce_1.Connection {
|
|
|
292
293
|
* Getter for the AuthInfo fields.
|
|
293
294
|
*/
|
|
294
295
|
getAuthInfoFields() {
|
|
295
|
-
// If the
|
|
296
|
+
// If the StateAggregator.orgs.remove is called, the AuthFields are no longer accessible.
|
|
296
297
|
return this.options.authInfo.getFields() || {};
|
|
297
298
|
}
|
|
298
299
|
/**
|
|
@@ -332,7 +333,7 @@ class Connection extends jsforce_1.Connection {
|
|
|
332
333
|
async autoFetchQuery(soql, queryOptions = {}) {
|
|
333
334
|
const config = await configAggregator_1.ConfigAggregator.create();
|
|
334
335
|
// take the limit from the calling function, then the config, then default 10,000
|
|
335
|
-
const maxFetch = config.getInfo(
|
|
336
|
+
const maxFetch = config.getInfo(orgConfigProperties_1.OrgConfigProperties.ORG_MAX_QUERY_LIMIT).value || queryOptions.maxFetch || 10000;
|
|
336
337
|
const options = Object.assign(queryOptions, {
|
|
337
338
|
autoFetch: true,
|
|
338
339
|
maxFetch,
|
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
|
*
|
package/lib/org/org.js
CHANGED
|
@@ -21,7 +21,7 @@ const sfError_1 = require("../sfError");
|
|
|
21
21
|
const sfdc_1 = require("../util/sfdc");
|
|
22
22
|
const webOAuthServer_1 = require("../webOAuthServer");
|
|
23
23
|
const messages_1 = require("../messages");
|
|
24
|
-
const
|
|
24
|
+
const stateAggregator_1 = require("../stateAggregator");
|
|
25
25
|
const pollingClient_1 = require("../status/pollingClient");
|
|
26
26
|
const connection_1 = require("./connection");
|
|
27
27
|
const authInfo_1 = require("./authInfo");
|
|
@@ -225,8 +225,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
225
225
|
async cleanLocalOrgData(orgDataPath, throwWhenRemoveFails = false) {
|
|
226
226
|
let dataPath;
|
|
227
227
|
try {
|
|
228
|
-
|
|
229
|
-
dataPath = (0, path_1.join)(rootFolder, global_1.Global.SFDX_STATE_FOLDER, orgDataPath ? orgDataPath : 'orgs');
|
|
228
|
+
dataPath = await this.getLocalDataDir(orgDataPath);
|
|
230
229
|
this.logger.debug(`cleaning data for path: ${dataPath}`);
|
|
231
230
|
}
|
|
232
231
|
catch (err) {
|
|
@@ -271,7 +270,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
271
270
|
*
|
|
272
271
|
*/
|
|
273
272
|
async isSandbox() {
|
|
274
|
-
return (await
|
|
273
|
+
return await (await stateAggregator_1.StateAggregator.getInstance()).sandboxes.hasFile(this.getOrgId());
|
|
275
274
|
}
|
|
276
275
|
/**
|
|
277
276
|
* Check that this org is a scratch org by asking the dev hub if it knows about it.
|
|
@@ -502,8 +501,8 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
502
501
|
const organization = await this.retrieveOrganizationInformation();
|
|
503
502
|
const isScratch = organization.IsSandbox && organization.TrialExpirationDate;
|
|
504
503
|
const isSandbox = organization.IsSandbox && !organization.TrialExpirationDate;
|
|
505
|
-
const
|
|
506
|
-
|
|
504
|
+
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
505
|
+
stateAggregator.orgs.update(username, {
|
|
507
506
|
[Org.Fields.NAME]: organization.Name,
|
|
508
507
|
[Org.Fields.INSTANCE_NAME]: organization.InstanceName,
|
|
509
508
|
[Org.Fields.NAMESPACE_PREFIX]: organization.NamespacePrefix,
|
|
@@ -511,7 +510,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
511
510
|
[Org.Fields.IS_SCRATCH]: isScratch,
|
|
512
511
|
[Org.Fields.TRIAL_EXPIRATION_DATE]: organization.TrialExpirationDate,
|
|
513
512
|
});
|
|
514
|
-
await
|
|
513
|
+
await stateAggregator.orgs.write(username);
|
|
515
514
|
}
|
|
516
515
|
}
|
|
517
516
|
/**
|
|
@@ -618,10 +617,10 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
618
617
|
* set the sandbox config related to this given org
|
|
619
618
|
*
|
|
620
619
|
* @param orgId {string} orgId of the sandbox
|
|
621
|
-
* @param config {
|
|
620
|
+
* @param config {SandboxFields} config of the sandbox
|
|
622
621
|
*/
|
|
623
622
|
async setSandboxConfig(orgId, config) {
|
|
624
|
-
(await
|
|
623
|
+
(await stateAggregator_1.StateAggregator.getInstance()).sandboxes.set(orgId, config);
|
|
625
624
|
return this;
|
|
626
625
|
}
|
|
627
626
|
/**
|
|
@@ -630,7 +629,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
630
629
|
* @param orgId {string} orgId of the sandbox
|
|
631
630
|
*/
|
|
632
631
|
async getSandboxConfig(orgId) {
|
|
633
|
-
return (await
|
|
632
|
+
return (await stateAggregator_1.StateAggregator.getInstance()).sandboxes.read(orgId);
|
|
634
633
|
}
|
|
635
634
|
/**
|
|
636
635
|
* Retrieves the highest api version that is supported by the target server instance. If the apiVersion configured for
|
|
@@ -733,7 +732,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
733
732
|
* Initialize async components.
|
|
734
733
|
*/
|
|
735
734
|
async init() {
|
|
736
|
-
const
|
|
735
|
+
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
737
736
|
this.logger = await logger_1.Logger.child('Org');
|
|
738
737
|
this.configAggregator = this.options.aggregator ? this.options.aggregator : await configAggregator_1.ConfigAggregator.create();
|
|
739
738
|
if (!this.options.connection) {
|
|
@@ -744,7 +743,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
744
743
|
: this.configAggregator.getPropertyValue(orgConfigProperties_1.OrgConfigProperties.TARGET_ORG);
|
|
745
744
|
this.options.aliasOrUsername = aliasOrUsername || undefined;
|
|
746
745
|
}
|
|
747
|
-
const username =
|
|
746
|
+
const username = stateAggregator.aliases.resolveUsername(this.options.aliasOrUsername);
|
|
748
747
|
if (!username) {
|
|
749
748
|
throw messages.createError('noUsernameFound');
|
|
750
749
|
}
|
|
@@ -764,6 +763,10 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
764
763
|
getDefaultOptions() {
|
|
765
764
|
throw new sfError_1.SfError('Not Supported', 'NotSupportedError');
|
|
766
765
|
}
|
|
766
|
+
async getLocalDataDir(orgDataPath) {
|
|
767
|
+
const rootFolder = await config_1.Config.resolveRootFolder(false);
|
|
768
|
+
return (0, path_1.join)(rootFolder, global_1.Global.SFDX_STATE_FOLDER, orgDataPath ? orgDataPath : 'orgs');
|
|
769
|
+
}
|
|
767
770
|
/**
|
|
768
771
|
* Gets the sandboxProcessObject and then polls for it to complete.
|
|
769
772
|
*
|
|
@@ -926,14 +929,14 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
926
929
|
* this Org. You don't want to call this method directly. Instead consider calling Org.remove()
|
|
927
930
|
*/
|
|
928
931
|
async removeAuth() {
|
|
929
|
-
const
|
|
932
|
+
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
930
933
|
const username = this.getUsername();
|
|
931
934
|
// If there is no username, it has already been removed from the globalInfo.
|
|
932
935
|
// We can skip the unset and just ensure that globalInfo is updated.
|
|
933
936
|
if (username) {
|
|
934
937
|
this.logger.debug(`Removing auth for user: ${username}`);
|
|
935
938
|
this.logger.debug(`Clearing auth cache for user: ${username}`);
|
|
936
|
-
|
|
939
|
+
await stateAggregator.orgs.remove(username);
|
|
937
940
|
}
|
|
938
941
|
}
|
|
939
942
|
/**
|
|
@@ -964,7 +967,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
964
967
|
*/
|
|
965
968
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
966
969
|
async removeUsers(throwWhenRemoveFails) {
|
|
967
|
-
const
|
|
970
|
+
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
968
971
|
this.logger.debug(`Removing users associate with org: ${this.getOrgId()}`);
|
|
969
972
|
const config = await this.retrieveOrgUsersConfig();
|
|
970
973
|
this.logger.debug(`using path for org users: ${config.getPath()}`);
|
|
@@ -972,8 +975,8 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
972
975
|
await Promise.all(authInfos
|
|
973
976
|
.map((auth) => auth.getFields().username)
|
|
974
977
|
.map(async (username) => {
|
|
975
|
-
const aliasKeys = (username &&
|
|
976
|
-
|
|
978
|
+
const aliasKeys = (username && stateAggregator.aliases.getAll(username)) || [];
|
|
979
|
+
stateAggregator.aliases.unsetAll(username);
|
|
977
980
|
const orgForUser = username === this.getUsername()
|
|
978
981
|
? this
|
|
979
982
|
: await Org.create({
|
|
@@ -988,12 +991,11 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
988
991
|
needsConfigUpdate ? config_1.Config.update(configInfo.isGlobal(), orgType, undefined) : undefined,
|
|
989
992
|
].filter(Boolean);
|
|
990
993
|
}));
|
|
991
|
-
await
|
|
994
|
+
await stateAggregator.aliases.write();
|
|
992
995
|
}
|
|
993
996
|
async removeSandboxConfig() {
|
|
994
|
-
const
|
|
995
|
-
|
|
996
|
-
await globalInfo.write();
|
|
997
|
+
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
998
|
+
await stateAggregator.sandboxes.remove(this.getOrgId());
|
|
997
999
|
}
|
|
998
1000
|
async writeSandboxAuthFile(sandboxProcessObj, sandboxRes) {
|
|
999
1001
|
this.logger.debug(`writeSandboxAuthFile sandboxProcessObj: ${JSON.stringify(sandboxProcessObj)}, sandboxRes: ${JSON.stringify(sandboxRes)}`);
|
|
@@ -1023,22 +1025,22 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
1023
1025
|
this.logger.debug('Creating AuthInfo for sandbox', sandboxRes.authUserName, productionAuthFields.username, oauth2Options);
|
|
1024
1026
|
// save auth info for new sandbox
|
|
1025
1027
|
await authInfo.save();
|
|
1026
|
-
|
|
1028
|
+
const sandboxOrgId = authInfo.getFields().orgId;
|
|
1029
|
+
if (!sandboxOrgId) {
|
|
1027
1030
|
throw messages.createError('AuthInfoOrgIdUndefined');
|
|
1028
1031
|
}
|
|
1029
1032
|
// set the sandbox config value
|
|
1030
1033
|
const sfSandbox = {
|
|
1031
1034
|
sandboxUsername: sandboxRes.authUserName,
|
|
1032
|
-
sandboxOrgId
|
|
1035
|
+
sandboxOrgId,
|
|
1033
1036
|
prodOrgUsername: this.getUsername(),
|
|
1034
1037
|
sandboxName: sandboxProcessObj.SandboxName,
|
|
1035
1038
|
sandboxProcessId: sandboxProcessObj.Id,
|
|
1036
1039
|
sandboxInfoId: sandboxProcessObj.SandboxInfoId,
|
|
1037
1040
|
timestamp: new Date().toISOString(),
|
|
1038
1041
|
};
|
|
1039
|
-
await this.setSandboxConfig(
|
|
1040
|
-
|
|
1041
|
-
await globalInfo.write();
|
|
1042
|
+
await this.setSandboxConfig(sandboxOrgId, sfSandbox);
|
|
1043
|
+
(await stateAggregator_1.StateAggregator.getInstance()).sandboxes.write(sandboxOrgId);
|
|
1042
1044
|
await lifecycleEvents_1.Lifecycle.getInstance().emit(SandboxEvents.EVENT_RESULT, {
|
|
1043
1045
|
sandboxProcessObj,
|
|
1044
1046
|
sandboxRes,
|