@salesforce/core 3.23.8 → 3.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/lib/config/config.js +5 -7
- package/lib/config/configAggregator.js +5 -7
- package/lib/config/configStore.js +1 -2
- package/lib/config/envVars.js +1 -2
- package/lib/deviceOauthService.d.ts +2 -2
- package/lib/deviceOauthService.js +6 -7
- package/lib/org/authInfo.d.ts +4 -12
- package/lib/org/authInfo.js +18 -44
- package/lib/org/connection.d.ts +3 -8
- package/lib/org/connection.js +10 -58
- package/lib/org/org.d.ts +1 -1
- package/lib/org/org.js +18 -28
- package/lib/org/permissionSetAssignment.js +1 -2
- package/lib/org/scratchOrgCreate.d.ts +1 -1
- package/lib/org/scratchOrgCreate.js +13 -16
- package/lib/org/scratchOrgErrorCodes.js +7 -3
- package/lib/org/scratchOrgInfoApi.js +3 -4
- package/lib/org/scratchOrgInfoGenerator.js +9 -12
- package/lib/org/scratchOrgSettingsGenerator.js +3 -3
- package/lib/org/user.js +2 -3
- package/lib/sfProject.js +1 -2
- package/lib/stateAggregator/accessors/aliasAccessor.js +13 -26
- package/lib/stateAggregator/accessors/orgAccessor.js +5 -9
- package/lib/stateAggregator/accessors/sandboxAccessor.js +2 -4
- package/lib/stateAggregator/sfdxDataHandler.js +6 -10
- package/lib/status/pollingClient.js +1 -2
- package/lib/testSetup.js +9 -12
- package/lib/util/checkLightningDomain.js +2 -3
- package/lib/webOAuthServer.d.ts +3 -2
- package/lib/webOAuthServer.js +6 -6
- package/messages/scratchOrgCreate.md +0 -20
- package/messages/scratchOrgErrorCodes.md +16 -0
- package/package.json +2 -2
package/lib/org/org.js
CHANGED
|
@@ -90,7 +90,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
90
90
|
constructor(options) {
|
|
91
91
|
super(options);
|
|
92
92
|
this.status = Org.Status.UNKNOWN;
|
|
93
|
-
this.options = options
|
|
93
|
+
this.options = options ?? {};
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* create a sandbox from a production org
|
|
@@ -151,7 +151,6 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
151
151
|
async: false,
|
|
152
152
|
interval: kit_1.Duration.seconds(30),
|
|
153
153
|
}) {
|
|
154
|
-
var _a;
|
|
155
154
|
this.logger.debug(`ResumeSandbox called with ResumeSandboxRequest: ${resumeSandboxRequest}`);
|
|
156
155
|
let sandboxCreationProgress;
|
|
157
156
|
// seed the sandboxCreationProgress via the resumeSandboxRequest options
|
|
@@ -163,7 +162,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
163
162
|
}
|
|
164
163
|
else {
|
|
165
164
|
throw messages.createError('sandboxNotFound', [
|
|
166
|
-
|
|
165
|
+
resumeSandboxRequest.SandboxName ?? resumeSandboxRequest.SandboxProcessObjId,
|
|
167
166
|
]);
|
|
168
167
|
}
|
|
169
168
|
this.logger.debug(`Return from calling singleRecordQuery with tooling: ${sandboxCreationProgress}`);
|
|
@@ -529,11 +528,10 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
529
528
|
* Reads and returns the content of all user auth files for this org as an array.
|
|
530
529
|
*/
|
|
531
530
|
async readUserAuthFiles() {
|
|
532
|
-
var _a;
|
|
533
531
|
const config = await this.retrieveOrgUsersConfig();
|
|
534
532
|
const contents = await config.read();
|
|
535
533
|
const thisUsername = (0, ts_types_1.ensure)(this.getUsername());
|
|
536
|
-
const usernames = (0, ts_types_1.ensureJsonArray)(
|
|
534
|
+
const usernames = (0, ts_types_1.ensureJsonArray)(contents.usernames ?? [thisUsername]);
|
|
537
535
|
return Promise.all(usernames.map((username) => {
|
|
538
536
|
if (username === thisUsername) {
|
|
539
537
|
return authInfo_1.AuthInfo.create({
|
|
@@ -563,7 +561,6 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
563
561
|
* @param {AuthInfo | string} auth The AuthInfo for the username to add.
|
|
564
562
|
*/
|
|
565
563
|
async addUsername(auth) {
|
|
566
|
-
var _a;
|
|
567
564
|
if (!auth) {
|
|
568
565
|
throw new sfError_1.SfError('Missing auth info', 'MissingAuthInfo');
|
|
569
566
|
}
|
|
@@ -573,7 +570,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
573
570
|
const contents = await orgConfig.read();
|
|
574
571
|
// TODO: This is kind of screwy because contents values can be `AnyJson | object`...
|
|
575
572
|
// needs config refactoring to improve
|
|
576
|
-
const usernames =
|
|
573
|
+
const usernames = contents.usernames ?? [];
|
|
577
574
|
if (!(0, ts_types_1.isArray)(usernames)) {
|
|
578
575
|
throw new sfError_1.SfError('Usernames is not an array', 'UnexpectedDataFormat');
|
|
579
576
|
}
|
|
@@ -602,7 +599,6 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
602
599
|
* @param {AuthInfo | string} auth The AuthInfo containing the username to remove.
|
|
603
600
|
*/
|
|
604
601
|
async removeUsername(auth) {
|
|
605
|
-
var _a;
|
|
606
602
|
if (!auth) {
|
|
607
603
|
throw new sfError_1.SfError('Missing auth info', 'MissingAuthInfoError');
|
|
608
604
|
}
|
|
@@ -611,7 +607,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
611
607
|
const orgConfig = await this.retrieveOrgUsersConfig();
|
|
612
608
|
const contents = await orgConfig.read();
|
|
613
609
|
const targetUser = authInfo.getFields().username;
|
|
614
|
-
const usernames = (
|
|
610
|
+
const usernames = (contents.usernames ?? []);
|
|
615
611
|
contents.usernames = usernames.filter((username) => username !== targetUser);
|
|
616
612
|
await orgConfig.write();
|
|
617
613
|
return this;
|
|
@@ -652,8 +648,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
652
648
|
* Returns the orgId for this org.
|
|
653
649
|
*/
|
|
654
650
|
getOrgId() {
|
|
655
|
-
|
|
656
|
-
return (_a = this.orgId) !== null && _a !== void 0 ? _a : this.getField(Org.Fields.ORG_ID);
|
|
651
|
+
return this.orgId ?? this.getField(Org.Fields.ORG_ID);
|
|
657
652
|
}
|
|
658
653
|
/**
|
|
659
654
|
* Returns for the config aggregator.
|
|
@@ -807,13 +802,12 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
807
802
|
* @returns {SandboxProcessObject} The SandboxProcessObject for the sandbox
|
|
808
803
|
*/
|
|
809
804
|
async queryLatestSandboxProcessBySandboxName(sandboxNameIn) {
|
|
810
|
-
var _a;
|
|
811
805
|
const { tooling } = this.getConnection();
|
|
812
806
|
this.logger.debug('QueryLatestSandboxProcessBySandboxName called with SandboxName: %s ', sandboxNameIn);
|
|
813
807
|
const queryStr = `SELECT Id, Status, SandboxName, SandboxInfoId, LicenseType, CreatedDate, CopyProgress, SandboxOrganization, SourceId, Description, EndDate FROM SandboxProcess WHERE SandboxName='${sandboxNameIn}' AND Status != 'D' ORDER BY CreatedDate DESC LIMIT 1`;
|
|
814
808
|
const queryResult = await tooling.query(queryStr);
|
|
815
809
|
this.logger.debug('Return from calling queryToolingApi: %s ', queryResult);
|
|
816
|
-
if (
|
|
810
|
+
if (queryResult?.records?.length === 1) {
|
|
817
811
|
return queryResult.records[0];
|
|
818
812
|
}
|
|
819
813
|
else if (queryResult.records && queryResult.records.length > 1) {
|
|
@@ -839,18 +833,17 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
839
833
|
* @private
|
|
840
834
|
*/
|
|
841
835
|
async deleteSandbox(prodOrg) {
|
|
842
|
-
var _a, _b;
|
|
843
836
|
const sandbox = await this.getSandboxConfig(this.getOrgId());
|
|
844
|
-
prodOrg
|
|
837
|
+
prodOrg ?? (prodOrg = await Org.create({
|
|
845
838
|
aggregator: this.configAggregator,
|
|
846
|
-
aliasOrUsername: sandbox
|
|
839
|
+
aliasOrUsername: sandbox?.prodOrgUsername,
|
|
847
840
|
}));
|
|
848
|
-
let sandboxInfoId = sandbox
|
|
841
|
+
let sandboxInfoId = sandbox?.sandboxInfoId;
|
|
849
842
|
if (!sandboxInfoId) {
|
|
850
843
|
let result;
|
|
851
844
|
try {
|
|
852
845
|
// grab sandboxName from config or try to calculate from the sandbox username
|
|
853
|
-
const sandboxName =
|
|
846
|
+
const sandboxName = sandbox?.sandboxName ?? (this.getUsername() ?? '').split(`${prodOrg.getUsername()}.`)[1];
|
|
854
847
|
if (!sandboxName) {
|
|
855
848
|
this.logger.debug('Sandbox name is not available');
|
|
856
849
|
// jump to query by orgId
|
|
@@ -896,7 +889,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
896
889
|
*/
|
|
897
890
|
async deleteScratchOrg(devHub) {
|
|
898
891
|
// if we didn't get a devHub, we'll get it from the this org
|
|
899
|
-
devHub
|
|
892
|
+
devHub ?? (devHub = await this.getDevHubOrg());
|
|
900
893
|
if (!devHub) {
|
|
901
894
|
throw messages.createError('noDevHubFound');
|
|
902
895
|
}
|
|
@@ -980,8 +973,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
980
973
|
await Promise.all(authInfos
|
|
981
974
|
.map((auth) => auth.getFields().username)
|
|
982
975
|
.map(async (username) => {
|
|
983
|
-
|
|
984
|
-
const aliasKeys = (_a = (username && stateAggregator.aliases.getAll(username))) !== null && _a !== void 0 ? _a : [];
|
|
976
|
+
const aliasKeys = (username && stateAggregator.aliases.getAll(username)) ?? [];
|
|
985
977
|
stateAggregator.aliases.unsetAll(username);
|
|
986
978
|
const orgForUser = username === this.getUsername()
|
|
987
979
|
? this
|
|
@@ -1063,7 +1055,6 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
1063
1055
|
let waitingOnAuth = false;
|
|
1064
1056
|
const pollingClient = await pollingClient_1.PollingClient.create({
|
|
1065
1057
|
poll: async () => {
|
|
1066
|
-
var _a;
|
|
1067
1058
|
const sandboxProcessObj = await this.querySandboxProcessBySandboxInfoId(options.sandboxProcessObj.SandboxInfoId);
|
|
1068
1059
|
// check to see if sandbox can authenticate via sandboxAuth endpoint
|
|
1069
1060
|
const sandboxInfo = await this.sandboxSignupComplete(sandboxProcessObj);
|
|
@@ -1077,7 +1068,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
1077
1068
|
catch (err) {
|
|
1078
1069
|
const error = err;
|
|
1079
1070
|
this.logger.debug('Exception while calling writeSandboxAuthFile', err);
|
|
1080
|
-
if (
|
|
1071
|
+
if (error?.name === 'JwtAuthError' && error?.stack?.includes("user hasn't approved")) {
|
|
1081
1072
|
waitingOnAuth = true;
|
|
1082
1073
|
}
|
|
1083
1074
|
else {
|
|
@@ -1148,8 +1139,8 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
1148
1139
|
const error = err;
|
|
1149
1140
|
// There are cases where the endDate is set before the sandbox has actually completed.
|
|
1150
1141
|
// In that case, the sandboxAuth call will throw a specific exception.
|
|
1151
|
-
if (
|
|
1152
|
-
this.logger.debug('Error while authenticating the user', error
|
|
1142
|
+
if (error?.name === 'INVALID_STATUS') {
|
|
1143
|
+
this.logger.debug('Error while authenticating the user', error?.toString());
|
|
1153
1144
|
}
|
|
1154
1145
|
else {
|
|
1155
1146
|
// If it fails for any unexpected reason, just pass that through
|
|
@@ -1158,9 +1149,8 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
1158
1149
|
}
|
|
1159
1150
|
}
|
|
1160
1151
|
validateWaitOptions(options) {
|
|
1161
|
-
|
|
1162
|
-
const
|
|
1163
|
-
const interval = (_b = options.interval) !== null && _b !== void 0 ? _b : kit_1.Duration.seconds(30);
|
|
1152
|
+
const wait = options.wait ?? kit_1.Duration.minutes(30);
|
|
1153
|
+
const interval = options.interval ?? kit_1.Duration.seconds(30);
|
|
1164
1154
|
let pollInterval = options.async ? kit_1.Duration.seconds(0) : interval;
|
|
1165
1155
|
// pollInterval cannot be > wait.
|
|
1166
1156
|
pollInterval = pollInterval.seconds > wait.seconds ? wait : pollInterval;
|
|
@@ -49,7 +49,6 @@ class PermissionSetAssignment {
|
|
|
49
49
|
* @param permSetString An array of permission set names.
|
|
50
50
|
*/
|
|
51
51
|
async create(id, permSetString) {
|
|
52
|
-
var _a;
|
|
53
52
|
if (!id) {
|
|
54
53
|
throw messages.createError('userIdRequired');
|
|
55
54
|
}
|
|
@@ -62,7 +61,7 @@ class PermissionSetAssignment {
|
|
|
62
61
|
query += ` AND NamespacePrefix='${nsPrefix}'`;
|
|
63
62
|
}
|
|
64
63
|
const result = await this.org.getConnection().query(query);
|
|
65
|
-
const permissionSetId =
|
|
64
|
+
const permissionSetId = result?.records[0]?.Id;
|
|
66
65
|
if (!permissionSetId) {
|
|
67
66
|
if (nsPrefix) {
|
|
68
67
|
throw messages.createError('assignCommandPermissionSetNotFoundForNSError', [permSetName, nsPrefix]);
|
|
@@ -47,7 +47,7 @@ export interface ScratchOrgCreateOptions {
|
|
|
47
47
|
alias?: string;
|
|
48
48
|
/** after complete, set the org as the default */
|
|
49
49
|
setDefault?: boolean;
|
|
50
|
-
/** do not use source tracking for this org */
|
|
50
|
+
/** if false, do not use source tracking for this scratch org */
|
|
51
51
|
tracksSource?: boolean;
|
|
52
52
|
}
|
|
53
53
|
export declare const scratchOrgResume: (jobId: string) => Promise<ScratchOrgCreateResult>;
|
|
@@ -27,13 +27,8 @@ const messages = messages_1.Messages.load('@salesforce/core', 'scratchOrgCreate'
|
|
|
27
27
|
'DurationDaysValidationMaxError',
|
|
28
28
|
'DurationDaysValidationMinError',
|
|
29
29
|
'RetryNotIntError',
|
|
30
|
-
'WaitValidationMaxError',
|
|
31
30
|
'DurationDaysNotIntError',
|
|
32
|
-
'NoScratchOrgInfoError',
|
|
33
|
-
'ScratchOrgDeletedError',
|
|
34
|
-
'StillInProgressError',
|
|
35
31
|
'CacheMissError',
|
|
36
|
-
'action.StillInProgress',
|
|
37
32
|
]);
|
|
38
33
|
exports.DEFAULT_STREAM_TIMEOUT_MINUTES = 6;
|
|
39
34
|
const validateDuration = (durationDays) => {
|
|
@@ -56,7 +51,6 @@ const validateRetry = (retry) => {
|
|
|
56
51
|
}
|
|
57
52
|
};
|
|
58
53
|
const scratchOrgResume = async (jobId) => {
|
|
59
|
-
var _a, _b, _c;
|
|
60
54
|
const [logger, cache] = await Promise.all([
|
|
61
55
|
logger_1.Logger.child('scratchOrgResume'),
|
|
62
56
|
scratchOrgCache_1.ScratchOrgCache.create(),
|
|
@@ -72,7 +66,7 @@ const scratchOrgResume = async (jobId) => {
|
|
|
72
66
|
await (0, scratchOrgErrorCodes_1.validateScratchOrgInfoForResume)({ jobId, scratchOrgInfo: soi, cache, hubUsername });
|
|
73
67
|
// At this point, the scratch org is "good".
|
|
74
68
|
// Some hubs have all the usernames set to `null`
|
|
75
|
-
const username =
|
|
69
|
+
const username = soi.Username ?? soi.SignupUsername;
|
|
76
70
|
// re-auth only if the org isn't in StateAggregator
|
|
77
71
|
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
78
72
|
const scratchOrgAuthInfo = (await stateAggregator.orgs.exists(username))
|
|
@@ -90,15 +84,17 @@ const scratchOrgResume = async (jobId) => {
|
|
|
90
84
|
settingsGenerator.extract({ ...soi, ...definitionjson });
|
|
91
85
|
const [authInfo] = await Promise.all([
|
|
92
86
|
(0, scratchOrgInfoApi_1.resolveUrl)(scratchOrgAuthInfo),
|
|
93
|
-
(0, scratchOrgInfoApi_1.deploySettings)(scratchOrg, settingsGenerator,
|
|
87
|
+
(0, scratchOrgInfoApi_1.deploySettings)(scratchOrg, settingsGenerator, apiVersion ??
|
|
88
|
+
new configAggregator_1.ConfigAggregator().getPropertyValue('apiVersion') ??
|
|
89
|
+
(await scratchOrg.retrieveMaxApiVersion())),
|
|
94
90
|
]);
|
|
95
91
|
await scratchOrgAuthInfo.handleAliasAndDefaultSettings({
|
|
96
92
|
alias,
|
|
97
|
-
setDefault: setDefault
|
|
93
|
+
setDefault: setDefault ?? false,
|
|
98
94
|
setDefaultDevHub: false,
|
|
99
|
-
setTracksSource: tracksSource
|
|
95
|
+
setTracksSource: tracksSource ?? true,
|
|
100
96
|
});
|
|
101
|
-
cache.unset(
|
|
97
|
+
cache.unset(soi.Id ?? jobId);
|
|
102
98
|
const authFields = authInfo.getFields();
|
|
103
99
|
await Promise.all([(0, scratchOrgLifecycleEvents_1.emit)({ stage: 'done', scratchOrgInfo: soi }), cache.write(), (0, scratchOrgLifecycleEvents_1.emitPostOrgCreate)(authFields)]);
|
|
104
100
|
return {
|
|
@@ -111,7 +107,6 @@ const scratchOrgResume = async (jobId) => {
|
|
|
111
107
|
};
|
|
112
108
|
exports.scratchOrgResume = scratchOrgResume;
|
|
113
109
|
const scratchOrgCreate = async (options) => {
|
|
114
|
-
var _a, _b, _c;
|
|
115
110
|
const logger = await logger_1.Logger.child('scratchOrgCreate');
|
|
116
111
|
logger.debug('scratchOrgCreate');
|
|
117
112
|
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'prepare request' });
|
|
@@ -146,7 +141,7 @@ const scratchOrgCreate = async (options) => {
|
|
|
146
141
|
const cache = await scratchOrgCache_1.ScratchOrgCache.create();
|
|
147
142
|
cache.set(scratchOrgInfoId, {
|
|
148
143
|
hubUsername: hubOrg.getUsername(),
|
|
149
|
-
hubBaseUrl:
|
|
144
|
+
hubBaseUrl: hubOrg.getField(org_1.Org.Fields.INSTANCE_URL)?.toString(),
|
|
150
145
|
definitionjson: { ...(definitionjson ? JSON.parse(definitionjson) : {}), ...orgConfig, ...settings },
|
|
151
146
|
clientSecret,
|
|
152
147
|
alias,
|
|
@@ -174,14 +169,16 @@ const scratchOrgCreate = async (options) => {
|
|
|
174
169
|
});
|
|
175
170
|
// we'll need this scratch org connection later;
|
|
176
171
|
const scratchOrg = await org_1.Org.create({
|
|
177
|
-
aliasOrUsername:
|
|
172
|
+
aliasOrUsername: soi.Username ?? soi.SignupUsername,
|
|
178
173
|
});
|
|
179
174
|
const username = scratchOrg.getUsername();
|
|
180
175
|
logger.debug(`scratch org username ${username}`);
|
|
181
176
|
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'deploy settings', scratchOrgInfo: soi });
|
|
182
177
|
const [authInfo] = await Promise.all([
|
|
183
178
|
(0, scratchOrgInfoApi_1.resolveUrl)(scratchOrgAuthInfo),
|
|
184
|
-
(0, scratchOrgInfoApi_1.deploySettings)(scratchOrg, settingsGenerator,
|
|
179
|
+
(0, scratchOrgInfoApi_1.deploySettings)(scratchOrg, settingsGenerator, apiversion ??
|
|
180
|
+
new configAggregator_1.ConfigAggregator().getPropertyValue('org-api-version') ??
|
|
181
|
+
(await scratchOrg.retrieveMaxApiVersion())),
|
|
185
182
|
]);
|
|
186
183
|
await scratchOrgAuthInfo.handleAliasAndDefaultSettings({
|
|
187
184
|
...{
|
|
@@ -198,7 +195,7 @@ const scratchOrgCreate = async (options) => {
|
|
|
198
195
|
username,
|
|
199
196
|
scratchOrgInfo: soi,
|
|
200
197
|
authInfo,
|
|
201
|
-
authFields: authInfo
|
|
198
|
+
authFields: authInfo?.getFields(),
|
|
202
199
|
warnings,
|
|
203
200
|
};
|
|
204
201
|
};
|
|
@@ -20,6 +20,10 @@ const namedMessages = messages_1.Messages.load('@salesforce/core', 'scratchOrgEr
|
|
|
20
20
|
'SignupFailedUnknownError',
|
|
21
21
|
'SignupFailedError',
|
|
22
22
|
'SignupUnexpectedError',
|
|
23
|
+
'StillInProgressError',
|
|
24
|
+
'action.StillInProgress',
|
|
25
|
+
'ScratchOrgDeletedError',
|
|
26
|
+
'NoScratchOrgInfoError',
|
|
23
27
|
]);
|
|
24
28
|
// getMessage will throw when the code isn't found
|
|
25
29
|
// and we don't know whether a given code takes arguments or not
|
|
@@ -43,12 +47,12 @@ const validateScratchOrgInfoForResume = async ({ jobId, scratchOrgInfo, cache, h
|
|
|
43
47
|
cache.unset(jobId);
|
|
44
48
|
await cache.write();
|
|
45
49
|
throw scratchOrgInfo.Status === 'Deleted'
|
|
46
|
-
?
|
|
47
|
-
:
|
|
50
|
+
? namedMessages.createError('ScratchOrgDeletedError')
|
|
51
|
+
: namedMessages.createError('NoScratchOrgInfoError');
|
|
48
52
|
}
|
|
49
53
|
if (['New', 'Creating'].includes(scratchOrgInfo.Status)) {
|
|
50
54
|
// 2. scratchOrgInfo exists, still isn't finished. Stays in cache for future attempts
|
|
51
|
-
throw
|
|
55
|
+
throw namedMessages.createError('StillInProgressError', [scratchOrgInfo.Status], ['action.StillInProgress']);
|
|
52
56
|
}
|
|
53
57
|
return (0, exports.checkScratchOrgInfoForErrors)(scratchOrgInfo, hubUsername);
|
|
54
58
|
};
|
|
@@ -46,7 +46,7 @@ const getOrgInstanceAuthority = function (scratchOrgInfoComplete, hubOrgLoginUrl
|
|
|
46
46
|
// For Falcon sandboxes, try the LoginURL instead; createdOrgInstance will not yield a valid URL
|
|
47
47
|
altUrl = scratchOrgInfoComplete.LoginUrl;
|
|
48
48
|
}
|
|
49
|
-
return signupTargetLoginUrlConfig
|
|
49
|
+
return signupTargetLoginUrlConfig ?? altUrl;
|
|
50
50
|
};
|
|
51
51
|
/**
|
|
52
52
|
* Returns OAuth2Options object
|
|
@@ -63,7 +63,7 @@ const buildOAuth2Options = async (options) => {
|
|
|
63
63
|
logger.debug(`isJwtFlow: ${isJwtFlow}`);
|
|
64
64
|
if (isJwtFlow && !process.env.SFDX_CLIENT_SECRET) {
|
|
65
65
|
oauth2Options.privateKeyFile = options.hubOrg.getConnection().getAuthInfoFields().privateKey;
|
|
66
|
-
const retries =
|
|
66
|
+
const retries = options?.retry || kit_1.env.getNumber('SFDX_JWT_AUTH_RETRY_ATTEMPTS') || 0;
|
|
67
67
|
const timeoutInSeconds = kit_1.env.getNumber('SFDX_JWT_AUTH_RETRY_TIMEOUT') || 300;
|
|
68
68
|
const timeout = kit_1.Duration.seconds(timeoutInSeconds).milliseconds;
|
|
69
69
|
const delay = retries ? timeout / retries : 1000;
|
|
@@ -153,7 +153,6 @@ exports.queryScratchOrgInfo = queryScratchOrgInfo;
|
|
|
153
153
|
* @returns {Promise<AuthInfo>}
|
|
154
154
|
*/
|
|
155
155
|
const authorizeScratchOrg = async (options) => {
|
|
156
|
-
var _a;
|
|
157
156
|
const { scratchOrgInfoComplete, hubOrg, clientSecret, signupTargetLoginUrlConfig, retry } = options;
|
|
158
157
|
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'authenticate', scratchOrgInfo: scratchOrgInfoComplete });
|
|
159
158
|
const logger = await logger_1.Logger.child('authorizeScratchOrg');
|
|
@@ -179,7 +178,7 @@ const authorizeScratchOrg = async (options) => {
|
|
|
179
178
|
});
|
|
180
179
|
await authInfo.save({
|
|
181
180
|
devHubUsername: hubOrg.getUsername(),
|
|
182
|
-
created: new Date(
|
|
181
|
+
created: new Date(scratchOrgInfoComplete.CreatedDate ?? new Date()).valueOf().toString(),
|
|
183
182
|
expirationDate: scratchOrgInfoComplete.ExpirationDate,
|
|
184
183
|
clientId: scratchOrgInfoComplete.ConnectedAppConsumerKey,
|
|
185
184
|
createdOrgInstance: scratchOrgInfoComplete.SignupInstance,
|
|
@@ -65,7 +65,6 @@ const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
|
|
|
65
65
|
return '';
|
|
66
66
|
}
|
|
67
67
|
const ancestorIds = await Promise.all(packagesWithAncestors.map(async (packageDir) => {
|
|
68
|
-
var _a, _b, _c;
|
|
69
68
|
// ancestorID can be 05i, or 04t, alias; OR "ancestorVersion": "4.6.0.1"
|
|
70
69
|
// according to docs, 05i is not ok: https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev2gp_config_file.htm
|
|
71
70
|
if (packageDir.ancestorVersion) {
|
|
@@ -74,7 +73,7 @@ const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
|
|
|
74
73
|
}
|
|
75
74
|
// package can be an ID, but not according to docs
|
|
76
75
|
const packageAliases = projectJson.get('packageAliases');
|
|
77
|
-
const packageId =
|
|
76
|
+
const packageId = packageAliases[(0, ts_types_1.ensureString)(packageDir.package)] ?? packageDir.package;
|
|
78
77
|
const [major, minor, patch] = packageDir.ancestorVersion.split('.');
|
|
79
78
|
let releasedAncestor;
|
|
80
79
|
try {
|
|
@@ -93,11 +92,11 @@ const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
|
|
|
93
92
|
}
|
|
94
93
|
return releasedAncestor.Id;
|
|
95
94
|
}
|
|
96
|
-
if (
|
|
95
|
+
if (packageDir?.ancestorId?.startsWith('05i')) {
|
|
97
96
|
// if it's already a 05i return it, otherwise query for it
|
|
98
97
|
return packageDir.ancestorId;
|
|
99
98
|
}
|
|
100
|
-
if (
|
|
99
|
+
if (packageDir?.ancestorId?.startsWith('04t')) {
|
|
101
100
|
// query for the Id
|
|
102
101
|
return (await hubOrg
|
|
103
102
|
.getConnection()
|
|
@@ -105,7 +104,7 @@ const getAncestorIds = async (scratchOrgInfo, projectJson, hubOrg) => {
|
|
|
105
104
|
}
|
|
106
105
|
// ancestorID can be an alias get it from projectJson
|
|
107
106
|
const packageAliases = projectJson.get('packageAliases');
|
|
108
|
-
if (packageDir.ancestorId &&
|
|
107
|
+
if (packageDir.ancestorId && packageAliases?.[packageDir.ancestorId]) {
|
|
109
108
|
return packageAliases[packageDir.ancestorId];
|
|
110
109
|
}
|
|
111
110
|
throw new sfError_1.SfError(`Invalid ancestorId ${packageDir.ancestorId}`, 'InvalidAncestorId');
|
|
@@ -122,7 +121,6 @@ exports.getAncestorIds = getAncestorIds;
|
|
|
122
121
|
* @param ignoreAncestorIds true if the sfdx-project.json ancestorId keys should be ignored
|
|
123
122
|
*/
|
|
124
123
|
const generateScratchOrgInfo = async ({ hubOrg, scratchOrgInfoPayload, nonamespace, ignoreAncestorIds, }) => {
|
|
125
|
-
var _a, _b;
|
|
126
124
|
let sfProject;
|
|
127
125
|
try {
|
|
128
126
|
sfProject = await sfProject_1.SfProjectJson.create({});
|
|
@@ -130,17 +128,17 @@ const generateScratchOrgInfo = async ({ hubOrg, scratchOrgInfoPayload, nonamespa
|
|
|
130
128
|
catch (e) {
|
|
131
129
|
// project is not required
|
|
132
130
|
}
|
|
133
|
-
scratchOrgInfoPayload.orgName =
|
|
131
|
+
scratchOrgInfoPayload.orgName = scratchOrgInfoPayload.orgName ?? 'Company';
|
|
134
132
|
scratchOrgInfoPayload.package2AncestorIds =
|
|
135
|
-
!ignoreAncestorIds &&
|
|
133
|
+
!ignoreAncestorIds && sfProject?.hasPackages()
|
|
136
134
|
? await (0, exports.getAncestorIds)(scratchOrgInfoPayload, sfProject, hubOrg)
|
|
137
135
|
: '';
|
|
138
136
|
// Use the Hub org's client ID value, if one wasn't provided to us, or the default
|
|
139
137
|
if (!scratchOrgInfoPayload.connectedAppConsumerKey) {
|
|
140
138
|
scratchOrgInfoPayload.connectedAppConsumerKey =
|
|
141
|
-
|
|
139
|
+
hubOrg.getConnection().getAuthInfoFields().clientId ?? defaultConnectedAppInfo.clientId;
|
|
142
140
|
}
|
|
143
|
-
if (!nonamespace &&
|
|
141
|
+
if (!nonamespace && sfProject?.get('namespace')) {
|
|
144
142
|
scratchOrgInfoPayload.namespace = sfProject.get('namespace');
|
|
145
143
|
}
|
|
146
144
|
// we already have the info, and want to get rid of configApi, so this doesn't use that
|
|
@@ -164,11 +162,10 @@ exports.generateScratchOrgInfo = generateScratchOrgInfo;
|
|
|
164
162
|
warnings: string[];
|
|
165
163
|
*/
|
|
166
164
|
const getScratchOrgInfoPayload = async (options) => {
|
|
167
|
-
var _a;
|
|
168
165
|
let warnings = [];
|
|
169
166
|
// orgConfig input overrides definitionjson (-j option; hidden/deprecated)
|
|
170
167
|
const definitionJson = options.definitionjson ? JSON.parse(options.definitionjson) : {};
|
|
171
|
-
const orgConfigInput = { ...definitionJson, ...(
|
|
168
|
+
const orgConfigInput = { ...definitionJson, ...(options.orgConfig ?? {}) };
|
|
172
169
|
let scratchOrgInfoPayload = orgConfigInput;
|
|
173
170
|
// the -f option
|
|
174
171
|
if (options.definitionfile) {
|
|
@@ -141,11 +141,11 @@ class SettingsGenerator {
|
|
|
141
141
|
this.allBusinessProcesses = [];
|
|
142
142
|
this.logger = logger_1.Logger.childFromRoot('SettingsGenerator');
|
|
143
143
|
// If SFDX_MDAPI_TEMP_DIR is set, copy settings to that dir for people to inspect.
|
|
144
|
-
const mdApiTmpDir =
|
|
145
|
-
this.shapeDirName =
|
|
144
|
+
const mdApiTmpDir = options?.mdApiTmpDir || kit_1.env.getString('SFDX_MDAPI_TEMP_DIR');
|
|
145
|
+
this.shapeDirName = options?.shapeDirName || `shape_${Date.now()}`;
|
|
146
146
|
this.packageFilePath = path.join(this.shapeDirName, 'package.xml');
|
|
147
147
|
let storePath;
|
|
148
|
-
if (!
|
|
148
|
+
if (!options?.asDirectory) {
|
|
149
149
|
storePath = mdApiTmpDir ? path.join(mdApiTmpDir, `${this.shapeDirName}.zip`) : undefined;
|
|
150
150
|
this.writer = new zipWriter_1.ZipWriter(storePath);
|
|
151
151
|
}
|
package/lib/org/user.js
CHANGED
|
@@ -225,10 +225,10 @@ class User extends kit_1.AsyncCreatable {
|
|
|
225
225
|
this.logger.debug(`Attempting to set password for userId: ${info.getFields().userId} username: ${info.getFields().username}`);
|
|
226
226
|
const userConnection = await connection_1.Connection.create({ authInfo: info });
|
|
227
227
|
return new Promise((resolve, reject) => {
|
|
228
|
+
// no promises in async method
|
|
228
229
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
229
230
|
password.value(async (buffer) => {
|
|
230
231
|
try {
|
|
231
|
-
// @ts-ignore TODO: expose `soap` on Connection however appropriate
|
|
232
232
|
const soap = userConnection.soap;
|
|
233
233
|
await soap.setPassword((0, ts_types_1.ensureString)(info.getFields().userId), buffer.toString('utf8'));
|
|
234
234
|
this.logger.debug(`Set password for userId: ${info.getFields().userId}`);
|
|
@@ -293,7 +293,6 @@ class User extends kit_1.AsyncCreatable {
|
|
|
293
293
|
* ```
|
|
294
294
|
*/
|
|
295
295
|
async createUser(fields) {
|
|
296
|
-
var _a;
|
|
297
296
|
// Create a user and get a refresh token
|
|
298
297
|
const refreshTokenSecret = await this.createUserInternal(fields);
|
|
299
298
|
// Create the initial auth info
|
|
@@ -302,7 +301,7 @@ class User extends kit_1.AsyncCreatable {
|
|
|
302
301
|
// Setup oauth options for the new user
|
|
303
302
|
const oauthOptions = {
|
|
304
303
|
// Communities users require the instance for auth
|
|
305
|
-
loginUrl:
|
|
304
|
+
loginUrl: adminUserAuthFields.instanceUrl ?? adminUserAuthFields.loginUrl,
|
|
306
305
|
refreshToken: refreshTokenSecret.buffer.value((buffer) => buffer.toString('utf8')),
|
|
307
306
|
clientId: adminUserAuthFields.clientId,
|
|
308
307
|
clientSecret: adminUserAuthFields.clientSecret,
|
package/lib/sfProject.js
CHANGED
|
@@ -525,7 +525,6 @@ class SfProject {
|
|
|
525
525
|
* properties, including some 3rd party custom properties.
|
|
526
526
|
*/
|
|
527
527
|
async resolveProjectConfig() {
|
|
528
|
-
var _a;
|
|
529
528
|
if (!this.projectConfig) {
|
|
530
529
|
// Do fs operations in parallel
|
|
531
530
|
const [global, local, configAggregator] = await Promise.all([
|
|
@@ -539,7 +538,7 @@ class SfProject {
|
|
|
539
538
|
Object.assign(this.projectConfig, configAggregator.getConfig());
|
|
540
539
|
// we don't have a login url yet, so use instanceUrl from config or default
|
|
541
540
|
if (!this.projectConfig.sfdcLoginUrl) {
|
|
542
|
-
this.projectConfig.sfdcLoginUrl =
|
|
541
|
+
this.projectConfig.sfdcLoginUrl = configAggregator.getConfig()['org-instance-url'] ?? sfdcUrl_1.SfdcUrl.PRODUCTION;
|
|
543
542
|
}
|
|
544
543
|
// LEGACY - Allow override of sfdcLoginUrl via env var FORCE_SFDC_LOGIN_URL
|
|
545
544
|
if (process.env.FORCE_SFDC_LOGIN_URL) {
|
|
@@ -36,8 +36,7 @@ class GlobalInfoAliasAccessor {
|
|
|
36
36
|
* @param entity the aliasable entity that you want to get the alias of
|
|
37
37
|
*/
|
|
38
38
|
get(entity) {
|
|
39
|
-
|
|
40
|
-
return (_a = this.getAll(entity).find((alias) => alias)) !== null && _a !== void 0 ? _a : null;
|
|
39
|
+
return this.getAll(entity).find((alias) => alias) ?? null;
|
|
41
40
|
}
|
|
42
41
|
/**
|
|
43
42
|
* Returns the value that corresponds to the given alias if it exists
|
|
@@ -45,8 +44,7 @@ class GlobalInfoAliasAccessor {
|
|
|
45
44
|
* @param alias the alias that corresponds to a value
|
|
46
45
|
*/
|
|
47
46
|
getValue(alias) {
|
|
48
|
-
|
|
49
|
-
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
47
|
+
return this.getAll()[alias] ?? null;
|
|
50
48
|
}
|
|
51
49
|
/**
|
|
52
50
|
* Returns the username that corresponds to the given alias if it exists
|
|
@@ -54,8 +52,7 @@ class GlobalInfoAliasAccessor {
|
|
|
54
52
|
* @param alias the alias that corresponds to a username
|
|
55
53
|
*/
|
|
56
54
|
getUsername(alias) {
|
|
57
|
-
|
|
58
|
-
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
55
|
+
return this.getAll()[alias] ?? null;
|
|
59
56
|
}
|
|
60
57
|
/**
|
|
61
58
|
* If the provided string is an alias, it returns the corresponding value.
|
|
@@ -68,8 +65,7 @@ class GlobalInfoAliasAccessor {
|
|
|
68
65
|
* @param valueOrAlias a string that might be a value or might be an alias
|
|
69
66
|
*/
|
|
70
67
|
resolveValue(valueOrAlias) {
|
|
71
|
-
|
|
72
|
-
return (_a = this.getValue(valueOrAlias)) !== null && _a !== void 0 ? _a : valueOrAlias;
|
|
68
|
+
return this.getValue(valueOrAlias) ?? valueOrAlias;
|
|
73
69
|
}
|
|
74
70
|
/**
|
|
75
71
|
* If the provided string is an alias, it returns the corresponding username.
|
|
@@ -82,8 +78,7 @@ class GlobalInfoAliasAccessor {
|
|
|
82
78
|
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
83
79
|
*/
|
|
84
80
|
resolveUsername(usernameOrAlias) {
|
|
85
|
-
|
|
86
|
-
return (_a = this.getUsername(usernameOrAlias)) !== null && _a !== void 0 ? _a : usernameOrAlias;
|
|
81
|
+
return this.getUsername(usernameOrAlias) ?? usernameOrAlias;
|
|
87
82
|
}
|
|
88
83
|
/**
|
|
89
84
|
* Set an alias for the given aliasable entity
|
|
@@ -121,10 +116,9 @@ class GlobalInfoAliasAccessor {
|
|
|
121
116
|
* Returns the username of given aliasable entity
|
|
122
117
|
*/
|
|
123
118
|
getNameOf(entity) {
|
|
124
|
-
var _a;
|
|
125
119
|
if (typeof entity === 'string')
|
|
126
120
|
return entity;
|
|
127
|
-
const aliaseeName =
|
|
121
|
+
const aliaseeName = entity.username ?? entity.user;
|
|
128
122
|
if (!aliaseeName) {
|
|
129
123
|
throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
|
|
130
124
|
}
|
|
@@ -153,8 +147,7 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
153
147
|
* @param entity the aliasable entity that you want to get the alias of
|
|
154
148
|
*/
|
|
155
149
|
get(entity) {
|
|
156
|
-
|
|
157
|
-
return (_a = this.getAll(entity).find((alias) => alias)) !== null && _a !== void 0 ? _a : null;
|
|
150
|
+
return this.getAll(entity).find((alias) => alias) ?? null;
|
|
158
151
|
}
|
|
159
152
|
/**
|
|
160
153
|
* Returns the value that corresponds to the given alias if it exists
|
|
@@ -162,8 +155,7 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
162
155
|
* @param alias the alias that corresponds to a value
|
|
163
156
|
*/
|
|
164
157
|
getValue(alias) {
|
|
165
|
-
|
|
166
|
-
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
158
|
+
return this.getAll()[alias] ?? null;
|
|
167
159
|
}
|
|
168
160
|
/**
|
|
169
161
|
* Returns the username that corresponds to the given alias if it exists
|
|
@@ -171,8 +163,7 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
171
163
|
* @param alias the alias that corresponds to a username
|
|
172
164
|
*/
|
|
173
165
|
getUsername(alias) {
|
|
174
|
-
|
|
175
|
-
return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
|
|
166
|
+
return this.getAll()[alias] ?? null;
|
|
176
167
|
}
|
|
177
168
|
/**
|
|
178
169
|
* If the provided string is an alias, it returns the corresponding value.
|
|
@@ -185,8 +176,7 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
185
176
|
* @param valueOrAlias a string that might be a value or might be an alias
|
|
186
177
|
*/
|
|
187
178
|
resolveValue(valueOrAlias) {
|
|
188
|
-
|
|
189
|
-
return (_a = this.getValue(valueOrAlias)) !== null && _a !== void 0 ? _a : valueOrAlias;
|
|
179
|
+
return this.getValue(valueOrAlias) ?? valueOrAlias;
|
|
190
180
|
}
|
|
191
181
|
/**
|
|
192
182
|
* If the provided string is an alias, it returns the corresponding username.
|
|
@@ -199,8 +189,7 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
199
189
|
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
200
190
|
*/
|
|
201
191
|
resolveUsername(usernameOrAlias) {
|
|
202
|
-
|
|
203
|
-
return (_a = this.getUsername(usernameOrAlias)) !== null && _a !== void 0 ? _a : usernameOrAlias;
|
|
192
|
+
return this.getUsername(usernameOrAlias) ?? usernameOrAlias;
|
|
204
193
|
}
|
|
205
194
|
/**
|
|
206
195
|
* If the provided string is an alias, return it.
|
|
@@ -212,10 +201,9 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
212
201
|
* @param usernameOrAlias a string that might be a username or might be an alias
|
|
213
202
|
*/
|
|
214
203
|
resolveAlias(usernameOrAlias) {
|
|
215
|
-
var _a;
|
|
216
204
|
if (this.has(usernameOrAlias))
|
|
217
205
|
return usernameOrAlias;
|
|
218
|
-
return
|
|
206
|
+
return Object.entries(this.getAll()).find(([, username]) => username === usernameOrAlias)?.[0];
|
|
219
207
|
}
|
|
220
208
|
/**
|
|
221
209
|
* Set an alias for the given aliasable entity
|
|
@@ -260,10 +248,9 @@ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
|
|
|
260
248
|
* Returns the username of given aliasable entity
|
|
261
249
|
*/
|
|
262
250
|
getNameOf(entity) {
|
|
263
|
-
var _a;
|
|
264
251
|
if (typeof entity === 'string')
|
|
265
252
|
return entity;
|
|
266
|
-
const aliaseeName =
|
|
253
|
+
const aliaseeName = entity.username ?? entity.user;
|
|
267
254
|
if (!aliaseeName) {
|
|
268
255
|
throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
|
|
269
256
|
}
|