@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
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,
|
|
@@ -13,7 +13,7 @@ const messages_1 = require("../messages");
|
|
|
13
13
|
const logger_1 = require("../logger");
|
|
14
14
|
const configAggregator_1 = require("../config/configAggregator");
|
|
15
15
|
const sfProject_1 = require("../sfProject");
|
|
16
|
-
const
|
|
16
|
+
const stateAggregator_1 = require("../stateAggregator");
|
|
17
17
|
const org_1 = require("./org");
|
|
18
18
|
const scratchOrgInfoApi_1 = require("./scratchOrgInfoApi");
|
|
19
19
|
const scratchOrgSettingsGenerator_1 = require("./scratchOrgSettingsGenerator");
|
|
@@ -24,7 +24,6 @@ const scratchOrgCache_1 = require("./scratchOrgCache");
|
|
|
24
24
|
const scratchOrgErrorCodes_1 = require("./scratchOrgErrorCodes");
|
|
25
25
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
26
26
|
const messages = messages_1.Messages.load('@salesforce/core', 'scratchOrgCreate', [
|
|
27
|
-
'SourceStatusResetFailureError',
|
|
28
27
|
'DurationDaysValidationMaxError',
|
|
29
28
|
'DurationDaysValidationMinError',
|
|
30
29
|
'RetryNotIntError',
|
|
@@ -74,12 +73,10 @@ const scratchOrgResume = async (jobId) => {
|
|
|
74
73
|
// At this point, the scratch org is "good".
|
|
75
74
|
// Some hubs have all the usernames set to `null`
|
|
76
75
|
const username = (_a = soi.Username) !== null && _a !== void 0 ? _a : soi.SignupUsername;
|
|
77
|
-
// re-auth only if the org isn't in
|
|
78
|
-
const
|
|
79
|
-
const scratchOrgAuthInfo =
|
|
80
|
-
? await authInfo_1.AuthInfo.create({
|
|
81
|
-
username,
|
|
82
|
-
})
|
|
76
|
+
// re-auth only if the org isn't in StateAggregator
|
|
77
|
+
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
78
|
+
const scratchOrgAuthInfo = (await stateAggregator.orgs.exists(username))
|
|
79
|
+
? await authInfo_1.AuthInfo.create({ username })
|
|
83
80
|
: await (0, scratchOrgInfoApi_1.authorizeScratchOrg)({
|
|
84
81
|
scratchOrgInfoComplete: soi,
|
|
85
82
|
hubOrg,
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
1
2
|
import { Nullable } from '@salesforce/ts-types';
|
|
3
|
+
import { ConfigContents } from '../../exported';
|
|
2
4
|
import { GlobalInfo } from '../globalInfoConfig';
|
|
3
5
|
import { SfAliases, SfOrg, SfToken } from '../types';
|
|
4
6
|
export declare type Aliasable = string | Partial<SfOrg> | Partial<SfToken>;
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
10
|
+
export declare class GlobalInfoAliasAccessor {
|
|
6
11
|
private globalInfo;
|
|
7
12
|
constructor(globalInfo: GlobalInfo);
|
|
8
13
|
/**
|
|
@@ -81,3 +86,76 @@ export declare class AliasAccessor {
|
|
|
81
86
|
*/
|
|
82
87
|
private getNameOf;
|
|
83
88
|
}
|
|
89
|
+
export declare class AliasAccessor extends AsyncOptionalCreatable {
|
|
90
|
+
private config;
|
|
91
|
+
/**
|
|
92
|
+
* Returns all the aliases for all the values
|
|
93
|
+
*/
|
|
94
|
+
getAll(): ConfigContents<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Returns all the aliases for a given entity
|
|
97
|
+
*
|
|
98
|
+
* @param entity the aliasable entity that you want to get the aliases of
|
|
99
|
+
*/
|
|
100
|
+
getAll(entity: Aliasable): string[];
|
|
101
|
+
/**
|
|
102
|
+
* Returns the first alias found for a given entity
|
|
103
|
+
*
|
|
104
|
+
* @param entity the aliasable entity that you want to get the alias of
|
|
105
|
+
*/
|
|
106
|
+
get(entity: Aliasable): Nullable<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Returns the value that corresponds to the given alias if it exists
|
|
109
|
+
*
|
|
110
|
+
* @param alias the alias that corresponds to a value
|
|
111
|
+
*/
|
|
112
|
+
getValue(alias: string): Nullable<string>;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the username that corresponds to the given alias if it exists
|
|
115
|
+
*
|
|
116
|
+
* @param alias the alias that corresponds to a username
|
|
117
|
+
*/
|
|
118
|
+
getUsername(alias: string): Nullable<string>;
|
|
119
|
+
/**
|
|
120
|
+
* If the provided string is an alias, it returns the corresponding value.
|
|
121
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
122
|
+
* is the value and return it.
|
|
123
|
+
*
|
|
124
|
+
* This method is helpful when you don't know if the string you have is a value
|
|
125
|
+
* or an alias.
|
|
126
|
+
*
|
|
127
|
+
* @param valueOrAlias a string that might be a value or might be an alias
|
|
128
|
+
*/
|
|
129
|
+
resolveValue(valueOrAlias: string): string;
|
|
130
|
+
/**
|
|
131
|
+
* If the provided string is an alias, it returns the corresponding username.
|
|
132
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
133
|
+
* is the username and return it.
|
|
134
|
+
*
|
|
135
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
136
|
+
* or an alias.
|
|
137
|
+
*
|
|
138
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
139
|
+
*/
|
|
140
|
+
resolveUsername(usernameOrAlias: string): string;
|
|
141
|
+
/**
|
|
142
|
+
* Set an alias for the given aliasable entity
|
|
143
|
+
*
|
|
144
|
+
* @param alias the alias you want to set
|
|
145
|
+
* @param entity the aliasable entity that's being aliased
|
|
146
|
+
*/
|
|
147
|
+
set(alias: string, entity: Aliasable): void;
|
|
148
|
+
unset(alias: string): void;
|
|
149
|
+
/**
|
|
150
|
+
* This method unsets all the aliases for the given entity.
|
|
151
|
+
*
|
|
152
|
+
* @param entity the aliasable entity for which you want to unset all aliases
|
|
153
|
+
*/
|
|
154
|
+
unsetAll(entity: Aliasable): void;
|
|
155
|
+
write(): Promise<ConfigContents>;
|
|
156
|
+
protected init(): Promise<void>;
|
|
157
|
+
/**
|
|
158
|
+
* Returns the username of given aliasable entity
|
|
159
|
+
*/
|
|
160
|
+
private getNameOf;
|
|
161
|
+
}
|
|
@@ -6,10 +6,15 @@
|
|
|
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
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.AliasAccessor = void 0;
|
|
9
|
+
exports.AliasAccessor = exports.GlobalInfoAliasAccessor = void 0;
|
|
10
|
+
const kit_1 = require("@salesforce/kit");
|
|
11
|
+
const aliasesConfig_1 = require("../../config/aliasesConfig");
|
|
10
12
|
const sfError_1 = require("../../sfError");
|
|
11
13
|
const types_1 = require("../types");
|
|
12
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
17
|
+
class GlobalInfoAliasAccessor {
|
|
13
18
|
constructor(globalInfo) {
|
|
14
19
|
this.globalInfo = globalInfo;
|
|
15
20
|
}
|
|
@@ -126,5 +131,117 @@ class AliasAccessor {
|
|
|
126
131
|
return aliaseeName;
|
|
127
132
|
}
|
|
128
133
|
}
|
|
134
|
+
exports.GlobalInfoAliasAccessor = GlobalInfoAliasAccessor;
|
|
135
|
+
class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
136
|
+
getAll(entity) {
|
|
137
|
+
// This will only return aliases under "orgs". This will need to be modified
|
|
138
|
+
// if/when we want to support more aliases groups.
|
|
139
|
+
const all = (this.config.getGroup() || {});
|
|
140
|
+
if (entity) {
|
|
141
|
+
const value = this.getNameOf(entity);
|
|
142
|
+
return Object.entries(all)
|
|
143
|
+
.filter((entry) => entry[1] === value)
|
|
144
|
+
.map((entry) => entry[0]);
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return all;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns the first alias found for a given entity
|
|
152
|
+
*
|
|
153
|
+
* @param entity the aliasable entity that you want to get the alias of
|
|
154
|
+
*/
|
|
155
|
+
get(entity) {
|
|
156
|
+
var _a;
|
|
157
|
+
return (_a = this.getAll(entity).find((alias) => alias)) !== null && _a !== void 0 ? _a : null;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns the value that corresponds to the given alias if it exists
|
|
161
|
+
*
|
|
162
|
+
* @param alias the alias that corresponds to a value
|
|
163
|
+
*/
|
|
164
|
+
getValue(alias) {
|
|
165
|
+
var _a;
|
|
166
|
+
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Returns the username that corresponds to the given alias if it exists
|
|
170
|
+
*
|
|
171
|
+
* @param alias the alias that corresponds to a username
|
|
172
|
+
*/
|
|
173
|
+
getUsername(alias) {
|
|
174
|
+
var _a;
|
|
175
|
+
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* If the provided string is an alias, it returns the corresponding value.
|
|
179
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
180
|
+
* is the value and return it.
|
|
181
|
+
*
|
|
182
|
+
* This method is helpful when you don't know if the string you have is a value
|
|
183
|
+
* or an alias.
|
|
184
|
+
*
|
|
185
|
+
* @param valueOrAlias a string that might be a value or might be an alias
|
|
186
|
+
*/
|
|
187
|
+
resolveValue(valueOrAlias) {
|
|
188
|
+
var _a;
|
|
189
|
+
return (_a = this.getValue(valueOrAlias)) !== null && _a !== void 0 ? _a : valueOrAlias;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* If the provided string is an alias, it returns the corresponding username.
|
|
193
|
+
* If the provided string is not an alias, we assume that the provided string
|
|
194
|
+
* is the username and return it.
|
|
195
|
+
*
|
|
196
|
+
* This method is helpful when you don't know if the string you have is a username
|
|
197
|
+
* or an alias.
|
|
198
|
+
*
|
|
199
|
+
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
200
|
+
*/
|
|
201
|
+
resolveUsername(usernameOrAlias) {
|
|
202
|
+
var _a;
|
|
203
|
+
return (_a = this.getUsername(usernameOrAlias)) !== null && _a !== void 0 ? _a : usernameOrAlias;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Set an alias for the given aliasable entity
|
|
207
|
+
*
|
|
208
|
+
* @param alias the alias you want to set
|
|
209
|
+
* @param entity the aliasable entity that's being aliased
|
|
210
|
+
*/
|
|
211
|
+
set(alias, entity) {
|
|
212
|
+
this.config.set(alias, this.getNameOf(entity));
|
|
213
|
+
}
|
|
214
|
+
unset(alias) {
|
|
215
|
+
this.config.unset(alias);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* This method unsets all the aliases for the given entity.
|
|
219
|
+
*
|
|
220
|
+
* @param entity the aliasable entity for which you want to unset all aliases
|
|
221
|
+
*/
|
|
222
|
+
unsetAll(entity) {
|
|
223
|
+
const aliases = this.getAll(entity);
|
|
224
|
+
aliases.forEach((alias) => this.unset(alias));
|
|
225
|
+
}
|
|
226
|
+
async write() {
|
|
227
|
+
return this.config.write();
|
|
228
|
+
}
|
|
229
|
+
async init() {
|
|
230
|
+
this.config = await aliasesConfig_1.AliasesConfig.create(aliasesConfig_1.AliasesConfig.getDefaultOptions());
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Returns the username of given aliasable entity
|
|
234
|
+
*/
|
|
235
|
+
getNameOf(entity) {
|
|
236
|
+
var _a;
|
|
237
|
+
if (typeof entity === 'string')
|
|
238
|
+
return entity;
|
|
239
|
+
const aliaseeName = (_a = entity.username) !== null && _a !== void 0 ? _a : entity.user;
|
|
240
|
+
if (!aliaseeName) {
|
|
241
|
+
throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
|
|
242
|
+
}
|
|
243
|
+
return aliaseeName;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
129
246
|
exports.AliasAccessor = AliasAccessor;
|
|
130
247
|
//# sourceMappingURL=aliasAccessor.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import { JsonMap, Nullable, Optional } from '@salesforce/ts-types';
|
|
4
|
+
import { AsyncOptionalCreatable } from '@salesforce/kit';
|
|
5
|
+
import { AuthInfoConfig } from '../../config/authInfoConfig';
|
|
6
|
+
import { GlobalInfo } from '../globalInfoConfig';
|
|
7
|
+
import { SfOrgs, SfOrg } from '../types';
|
|
8
|
+
import { AuthFields } from '../../org';
|
|
9
|
+
import { ConfigFile } from '../../config/configFile';
|
|
10
|
+
import { ConfigContents } from '../../config/configStore';
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
14
|
+
export declare class GlobalInfoOrgAccessor {
|
|
15
|
+
private globalInfo;
|
|
16
|
+
constructor(globalInfo: GlobalInfo);
|
|
17
|
+
getAll(decrypt?: boolean): SfOrgs;
|
|
18
|
+
get(username: string, decrypt?: boolean): Optional<SfOrg>;
|
|
19
|
+
has(username: string): boolean;
|
|
20
|
+
set(username: string, org: SfOrg): void;
|
|
21
|
+
update(username: string, org: Partial<SfOrg>): void;
|
|
22
|
+
unset(username: string): void;
|
|
23
|
+
}
|
|
24
|
+
export declare abstract class BaseOrgAccessor<T extends ConfigFile, P extends ConfigContents> extends AsyncOptionalCreatable {
|
|
25
|
+
private configs;
|
|
26
|
+
private contents;
|
|
27
|
+
private logger;
|
|
28
|
+
read(username: string, decrypt?: boolean, throwOnNotFound?: boolean): Promise<Nullable<P>>;
|
|
29
|
+
readAll(decrypt?: boolean): Promise<P[]>;
|
|
30
|
+
get(username: string, decrypt?: boolean): Nullable<P>;
|
|
31
|
+
getAll(decrypt?: boolean): P[];
|
|
32
|
+
has(username: string): boolean;
|
|
33
|
+
exists(username: string): Promise<boolean>;
|
|
34
|
+
stat(username: string): Promise<Nullable<fs.Stats>>;
|
|
35
|
+
hasFile(username: string): Promise<boolean>;
|
|
36
|
+
list(): Promise<string[]>;
|
|
37
|
+
set(username: string, org: P): void;
|
|
38
|
+
update(username: string, org: Partial<P> & JsonMap): void;
|
|
39
|
+
remove(username: string): Promise<void>;
|
|
40
|
+
write(username: string): Promise<Nullable<P>>;
|
|
41
|
+
protected init(): Promise<void>;
|
|
42
|
+
private getAllFiles;
|
|
43
|
+
private parseUsername;
|
|
44
|
+
private parseFilename;
|
|
45
|
+
protected abstract initAuthFile(username: string, throwOnNotFound?: boolean): Promise<T>;
|
|
46
|
+
protected abstract getFileRegex(): RegExp;
|
|
47
|
+
protected abstract getFileExtension(): string;
|
|
48
|
+
}
|
|
49
|
+
export declare class OrgAccessor extends BaseOrgAccessor<AuthInfoConfig, AuthFields> {
|
|
50
|
+
protected initAuthFile(username: string, throwOnNotFound?: boolean): Promise<AuthInfoConfig>;
|
|
51
|
+
protected getFileRegex(): RegExp;
|
|
52
|
+
protected getFileExtension(): string;
|
|
53
|
+
}
|