@salesforce/core 3.30.14 → 3.31.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +11 -11
- package/README.md +222 -227
- package/lib/config/aliasesConfig.d.ts +12 -12
- package/lib/config/aliasesConfig.js +27 -27
- package/lib/config/authInfoConfig.d.ts +19 -19
- package/lib/config/authInfoConfig.js +34 -34
- package/lib/config/config.d.ts +311 -311
- package/lib/config/config.js +574 -574
- package/lib/config/configAggregator.d.ts +232 -232
- package/lib/config/configAggregator.js +379 -379
- package/lib/config/configFile.d.ts +199 -199
- package/lib/config/configFile.js +340 -340
- package/lib/config/configGroup.d.ts +141 -141
- package/lib/config/configGroup.js +224 -224
- package/lib/config/configStore.d.ts +241 -241
- package/lib/config/configStore.js +352 -352
- package/lib/config/envVars.d.ts +101 -101
- package/lib/config/envVars.js +456 -456
- package/lib/config/orgUsersConfig.d.ts +31 -31
- package/lib/config/orgUsersConfig.js +41 -41
- package/lib/config/sandboxOrgConfig.d.ts +37 -37
- package/lib/config/sandboxOrgConfig.js +50 -50
- package/lib/config/sandboxProcessCache.d.ts +16 -16
- package/lib/config/sandboxProcessCache.js +37 -37
- package/lib/config/tokensConfig.d.ts +10 -10
- package/lib/config/tokensConfig.js +28 -28
- package/lib/config/ttlConfig.d.ts +34 -34
- package/lib/config/ttlConfig.js +54 -54
- package/lib/crypto/crypto.d.ts +54 -54
- package/lib/crypto/crypto.js +220 -220
- package/lib/crypto/keyChain.d.ts +8 -8
- package/lib/crypto/keyChain.js +61 -61
- package/lib/crypto/keyChainImpl.d.ts +116 -116
- package/lib/crypto/keyChainImpl.js +486 -486
- package/lib/crypto/secureBuffer.d.ts +46 -46
- package/lib/crypto/secureBuffer.js +82 -82
- package/lib/deviceOauthService.d.ts +71 -71
- package/lib/deviceOauthService.js +191 -191
- package/lib/exported.d.ts +38 -38
- package/lib/exported.js +118 -118
- package/lib/global.d.ts +70 -70
- package/lib/global.js +109 -109
- package/lib/lifecycleEvents.d.ts +93 -93
- package/lib/lifecycleEvents.js +188 -188
- package/lib/logger.d.ts +381 -381
- package/lib/logger.js +734 -734
- package/lib/messages.d.ts +291 -291
- package/lib/messages.js +543 -543
- package/lib/org/authInfo.d.ts +344 -344
- package/lib/org/authInfo.js +892 -892
- package/lib/org/authRemover.d.ts +88 -88
- package/lib/org/authRemover.js +182 -182
- package/lib/org/connection.d.ts +197 -197
- package/lib/org/connection.js +395 -395
- package/lib/org/index.d.ts +6 -6
- package/lib/org/index.js +28 -28
- package/lib/org/org.d.ts +558 -558
- package/lib/org/org.js +1267 -1267
- package/lib/org/orgConfigProperties.d.ts +69 -69
- package/lib/org/orgConfigProperties.js +136 -136
- package/lib/org/permissionSetAssignment.d.ts +35 -35
- package/lib/org/permissionSetAssignment.js +125 -125
- package/lib/org/scratchOrgCache.d.ts +20 -20
- package/lib/org/scratchOrgCache.js +32 -32
- package/lib/org/scratchOrgCreate.d.ts +54 -54
- package/lib/org/scratchOrgCreate.js +216 -216
- package/lib/org/scratchOrgErrorCodes.d.ts +10 -10
- package/lib/org/scratchOrgErrorCodes.js +88 -88
- package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -26
- package/lib/org/scratchOrgFeatureDeprecation.js +109 -109
- package/lib/org/scratchOrgInfoApi.d.ts +68 -68
- package/lib/org/scratchOrgInfoApi.js +413 -413
- package/lib/org/scratchOrgInfoGenerator.d.ts +64 -64
- package/lib/org/scratchOrgInfoGenerator.js +241 -241
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -10
- package/lib/org/scratchOrgLifecycleEvents.js +40 -40
- package/lib/org/scratchOrgSettingsGenerator.d.ts +78 -78
- package/lib/org/scratchOrgSettingsGenerator.js +276 -276
- package/lib/org/scratchOrgTypes.d.ts +43 -43
- package/lib/org/scratchOrgTypes.js +8 -8
- package/lib/org/user.d.ts +187 -187
- package/lib/org/user.js +448 -448
- package/lib/schema/printer.d.ts +79 -79
- package/lib/schema/printer.js +260 -260
- package/lib/schema/validator.d.ts +70 -70
- package/lib/schema/validator.js +169 -169
- package/lib/sfError.d.ts +73 -73
- package/lib/sfError.js +136 -136
- package/lib/sfProject.d.ts +357 -357
- package/lib/sfProject.js +671 -671
- package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -98
- package/lib/stateAggregator/accessors/aliasAccessor.js +145 -145
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -101
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -240
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -8
- package/lib/stateAggregator/accessors/sandboxAccessor.js +27 -27
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -63
- package/lib/stateAggregator/accessors/tokenAccessor.js +79 -79
- package/lib/stateAggregator/index.d.ts +4 -4
- package/lib/stateAggregator/index.js +26 -26
- package/lib/stateAggregator/stateAggregator.d.ts +25 -25
- package/lib/stateAggregator/stateAggregator.js +45 -45
- package/lib/status/myDomainResolver.d.ts +66 -66
- package/lib/status/myDomainResolver.js +124 -124
- package/lib/status/pollingClient.d.ts +85 -85
- package/lib/status/pollingClient.js +115 -115
- package/lib/status/streamingClient.d.ts +244 -244
- package/lib/status/streamingClient.js +436 -436
- package/lib/status/types.d.ts +89 -89
- package/lib/status/types.js +17 -17
- package/lib/testSetup.d.ts +553 -530
- package/lib/testSetup.js +871 -727
- package/lib/util/cache.d.ts +11 -11
- package/lib/util/cache.js +69 -69
- package/lib/util/checkLightningDomain.d.ts +1 -1
- package/lib/util/checkLightningDomain.js +28 -28
- package/lib/util/directoryWriter.d.ts +12 -12
- package/lib/util/directoryWriter.js +53 -53
- package/lib/util/getJwtAudienceUrl.d.ts +4 -4
- package/lib/util/getJwtAudienceUrl.js +18 -18
- package/lib/util/internal.d.ts +58 -58
- package/lib/util/internal.js +118 -118
- package/lib/util/jsonXmlTools.d.ts +14 -14
- package/lib/util/jsonXmlTools.js +38 -38
- package/lib/util/mapKeys.d.ts +14 -14
- package/lib/util/mapKeys.js +51 -51
- package/lib/util/sfdc.d.ts +52 -52
- package/lib/util/sfdc.js +85 -85
- package/lib/util/sfdcUrl.d.ts +72 -72
- package/lib/util/sfdcUrl.js +215 -215
- package/lib/util/structuredWriter.d.ts +9 -9
- package/lib/util/structuredWriter.js +2 -2
- package/lib/util/zipWriter.d.ts +16 -16
- package/lib/util/zipWriter.js +67 -67
- package/lib/webOAuthServer.d.ts +156 -156
- package/lib/webOAuthServer.js +388 -388
- package/messages/auth.md +37 -37
- package/messages/config.md +156 -156
- package/messages/connection.md +30 -30
- package/messages/core.json +20 -20
- package/messages/core.md +67 -67
- package/messages/encryption.md +85 -85
- package/messages/envVars.md +303 -303
- package/messages/org.md +63 -63
- package/messages/permissionSetAssignment.md +31 -31
- package/messages/scratchOrgCreate.md +23 -23
- package/messages/scratchOrgErrorCodes.md +115 -115
- package/messages/scratchOrgFeatureDeprecation.md +11 -11
- package/messages/scratchOrgInfoApi.md +15 -15
- package/messages/scratchOrgInfoGenerator.md +23 -23
- package/messages/streaming.md +23 -23
- package/messages/user.md +35 -35
- package/package.json +97 -97
|
@@ -1,217 +1,217 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.scratchOrgCreate = exports.scratchOrgResume = exports.DEFAULT_STREAM_TIMEOUT_MINUTES = void 0;
|
|
4
|
-
/*
|
|
5
|
-
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
|
-
* All rights reserved.
|
|
7
|
-
* Licensed under the BSD 3-Clause license.
|
|
8
|
-
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
|
-
*/
|
|
10
|
-
const kit_1 = require("@salesforce/kit");
|
|
11
|
-
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
|
-
const messages_1 = require("../messages");
|
|
13
|
-
const logger_1 = require("../logger");
|
|
14
|
-
const configAggregator_1 = require("../config/configAggregator");
|
|
15
|
-
const orgConfigProperties_1 = require("../org/orgConfigProperties");
|
|
16
|
-
const sfProject_1 = require("../sfProject");
|
|
17
|
-
const stateAggregator_1 = require("../stateAggregator");
|
|
18
|
-
const org_1 = require("./org");
|
|
19
|
-
const scratchOrgInfoApi_1 = require("./scratchOrgInfoApi");
|
|
20
|
-
const scratchOrgSettingsGenerator_1 = require("./scratchOrgSettingsGenerator");
|
|
21
|
-
const scratchOrgInfoGenerator_1 = require("./scratchOrgInfoGenerator");
|
|
22
|
-
const authInfo_1 = require("./authInfo");
|
|
23
|
-
const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents");
|
|
24
|
-
const scratchOrgCache_1 = require("./scratchOrgCache");
|
|
25
|
-
const scratchOrgErrorCodes_1 = require("./scratchOrgErrorCodes");
|
|
26
|
-
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
27
|
-
const messages = messages_1.Messages.load('@salesforce/core', 'scratchOrgCreate', [
|
|
28
|
-
'DurationDaysValidationMaxError',
|
|
29
|
-
'DurationDaysValidationMinError',
|
|
30
|
-
'RetryNotIntError',
|
|
31
|
-
'DurationDaysNotIntError',
|
|
32
|
-
'CacheMissError',
|
|
33
|
-
]);
|
|
34
|
-
exports.DEFAULT_STREAM_TIMEOUT_MINUTES = 6;
|
|
35
|
-
const validateDuration = (durationDays) => {
|
|
36
|
-
const min = 1;
|
|
37
|
-
const max = 30;
|
|
38
|
-
if (Number.isInteger(durationDays)) {
|
|
39
|
-
if (durationDays < min) {
|
|
40
|
-
throw messages.createError('DurationDaysValidationMinError', [min, durationDays]);
|
|
41
|
-
}
|
|
42
|
-
if (durationDays > max) {
|
|
43
|
-
throw messages.createError('DurationDaysValidationMaxError', [max, durationDays]);
|
|
44
|
-
}
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
throw messages.createError('DurationDaysNotIntError');
|
|
48
|
-
};
|
|
49
|
-
const validateRetry = (retry) => {
|
|
50
|
-
if (!Number.isInteger(retry)) {
|
|
51
|
-
throw messages.createError('RetryNotIntError');
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const scratchOrgResume = async (jobId) => {
|
|
55
|
-
const [logger, cache] = await Promise.all([
|
|
56
|
-
logger_1.Logger.child('scratchOrgResume'),
|
|
57
|
-
scratchOrgCache_1.ScratchOrgCache.create(),
|
|
58
|
-
(0, scratchOrgLifecycleEvents_1.emit)({ stage: 'send request' }),
|
|
59
|
-
]);
|
|
60
|
-
logger.debug(`resuming scratch org creation for jobId: ${jobId}`);
|
|
61
|
-
if (!cache.has(jobId)) {
|
|
62
|
-
throw messages.createError('CacheMissError', [jobId]);
|
|
63
|
-
}
|
|
64
|
-
const { hubUsername, apiVersion, clientSecret, signupTargetLoginUrlConfig, definitionjson, alias, setDefault, tracksSource, } = cache.get(jobId);
|
|
65
|
-
const hubOrg = await org_1.Org.create({ aliasOrUsername: hubUsername });
|
|
66
|
-
const soi = await (0, scratchOrgInfoApi_1.queryScratchOrgInfo)(hubOrg, jobId);
|
|
67
|
-
await (0, scratchOrgErrorCodes_1.validateScratchOrgInfoForResume)({ jobId, scratchOrgInfo: soi, cache, hubUsername });
|
|
68
|
-
// At this point, the scratch org is "good".
|
|
69
|
-
// Some hubs have all the usernames set to `null`
|
|
70
|
-
const username = soi.Username ?? soi.SignupUsername;
|
|
71
|
-
// re-auth only if the org isn't in StateAggregator
|
|
72
|
-
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
73
|
-
const scratchOrgAuthInfo = (await stateAggregator.orgs.exists(username))
|
|
74
|
-
? await authInfo_1.AuthInfo.create({ username })
|
|
75
|
-
: await (0, scratchOrgInfoApi_1.authorizeScratchOrg)({
|
|
76
|
-
scratchOrgInfoComplete: soi,
|
|
77
|
-
hubOrg,
|
|
78
|
-
clientSecret,
|
|
79
|
-
signupTargetLoginUrlConfig,
|
|
80
|
-
retry: 0,
|
|
81
|
-
});
|
|
82
|
-
const scratchOrg = await org_1.Org.create({ aliasOrUsername: username });
|
|
83
|
-
const configAggregator = await configAggregator_1.ConfigAggregator.create();
|
|
84
|
-
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'deploy settings', scratchOrgInfo: soi });
|
|
85
|
-
const settingsGenerator = new scratchOrgSettingsGenerator_1.default();
|
|
86
|
-
await settingsGenerator.extract({ ...soi, ...definitionjson });
|
|
87
|
-
const [authInfo] = await Promise.all([
|
|
88
|
-
(0, scratchOrgInfoApi_1.resolveUrl)(scratchOrgAuthInfo),
|
|
89
|
-
(0, scratchOrgInfoApi_1.deploySettings)(scratchOrg, settingsGenerator, apiVersion ??
|
|
90
|
-
configAggregator.getPropertyValue(orgConfigProperties_1.OrgConfigProperties.ORG_API_VERSION) ??
|
|
91
|
-
(await scratchOrg.retrieveMaxApiVersion())),
|
|
92
|
-
]);
|
|
93
|
-
await scratchOrgAuthInfo.handleAliasAndDefaultSettings({
|
|
94
|
-
alias,
|
|
95
|
-
setDefault: setDefault ?? false,
|
|
96
|
-
setDefaultDevHub: false,
|
|
97
|
-
setTracksSource: tracksSource ?? true,
|
|
98
|
-
});
|
|
99
|
-
cache.unset(soi.Id ?? jobId);
|
|
100
|
-
const authFields = authInfo.getFields();
|
|
101
|
-
await Promise.all([(0, scratchOrgLifecycleEvents_1.emit)({ stage: 'done', scratchOrgInfo: soi }), cache.write(), (0, scratchOrgLifecycleEvents_1.emitPostOrgCreate)(authFields)]);
|
|
102
|
-
return {
|
|
103
|
-
username,
|
|
104
|
-
scratchOrgInfo: soi,
|
|
105
|
-
authInfo,
|
|
106
|
-
authFields,
|
|
107
|
-
warnings: [],
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
exports.scratchOrgResume = scratchOrgResume;
|
|
111
|
-
const scratchOrgCreate = async (options) => {
|
|
112
|
-
const logger = await logger_1.Logger.child('scratchOrgCreate');
|
|
113
|
-
logger.debug('scratchOrgCreate');
|
|
114
|
-
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'prepare request' });
|
|
115
|
-
const { hubOrg, connectedAppConsumerKey, durationDays = 1, nonamespace, noancestors, wait = kit_1.Duration.minutes(exports.DEFAULT_STREAM_TIMEOUT_MINUTES), retry = 0, apiversion, definitionjson, definitionfile, orgConfig, clientSecret = undefined, alias, setDefault = false, tracksSource = true, } = options;
|
|
116
|
-
validateDuration(durationDays);
|
|
117
|
-
validateRetry(retry);
|
|
118
|
-
const { scratchOrgInfoPayload, ignoreAncestorIds, warnings } = await (0, scratchOrgInfoGenerator_1.getScratchOrgInfoPayload)({
|
|
119
|
-
definitionjson,
|
|
120
|
-
definitionfile,
|
|
121
|
-
connectedAppConsumerKey,
|
|
122
|
-
durationDays,
|
|
123
|
-
nonamespace,
|
|
124
|
-
noancestors,
|
|
125
|
-
orgConfig,
|
|
126
|
-
});
|
|
127
|
-
const scratchOrgInfo = await (0, scratchOrgInfoGenerator_1.generateScratchOrgInfo)({
|
|
128
|
-
hubOrg,
|
|
129
|
-
scratchOrgInfoPayload,
|
|
130
|
-
nonamespace,
|
|
131
|
-
ignoreAncestorIds,
|
|
132
|
-
});
|
|
133
|
-
// gets the scratch org settings (will use in both signup paths AND to deploy the settings)
|
|
134
|
-
const settingsGenerator = new scratchOrgSettingsGenerator_1.default();
|
|
135
|
-
const settings = await settingsGenerator.extract(scratchOrgInfo);
|
|
136
|
-
logger.debug(`the scratch org def file has settings: ${settingsGenerator.hasSettings()}`);
|
|
137
|
-
const [scratchOrgInfoRequestResult, signupTargetLoginUrlConfig] = await Promise.all([
|
|
138
|
-
// creates the scratch org info in the devhub
|
|
139
|
-
(0, scratchOrgInfoApi_1.requestScratchOrgCreation)(hubOrg, scratchOrgInfo, settingsGenerator),
|
|
140
|
-
getSignupTargetLoginUrl(),
|
|
141
|
-
]);
|
|
142
|
-
const scratchOrgInfoId = (0, ts_types_1.ensureString)(scratchOrgInfoRequestResult.id);
|
|
143
|
-
const cache = await scratchOrgCache_1.ScratchOrgCache.create();
|
|
144
|
-
cache.set(scratchOrgInfoId, {
|
|
145
|
-
hubUsername: hubOrg.getUsername(),
|
|
146
|
-
hubBaseUrl: hubOrg.getField(org_1.Org.Fields.INSTANCE_URL)?.toString(),
|
|
147
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
148
|
-
definitionjson: { ...(definitionjson ? JSON.parse(definitionjson) : {}), ...orgConfig, ...settings },
|
|
149
|
-
clientSecret,
|
|
150
|
-
alias,
|
|
151
|
-
setDefault,
|
|
152
|
-
tracksSource,
|
|
153
|
-
});
|
|
154
|
-
await cache.write();
|
|
155
|
-
logger.debug(`scratch org has recordId ${scratchOrgInfoId}`);
|
|
156
|
-
// this is where we stop--no polling
|
|
157
|
-
if (wait.minutes === 0) {
|
|
158
|
-
const soi = await (0, scratchOrgInfoApi_1.queryScratchOrgInfo)(hubOrg, scratchOrgInfoId);
|
|
159
|
-
return {
|
|
160
|
-
username: soi.SignupUsername,
|
|
161
|
-
warnings: [],
|
|
162
|
-
scratchOrgInfo: soi,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
const soi = await (0, scratchOrgInfoApi_1.pollForScratchOrgInfo)(hubOrg, scratchOrgInfoId, wait);
|
|
166
|
-
const scratchOrgAuthInfo = await (0, scratchOrgInfoApi_1.authorizeScratchOrg)({
|
|
167
|
-
scratchOrgInfoComplete: soi,
|
|
168
|
-
hubOrg,
|
|
169
|
-
clientSecret,
|
|
170
|
-
signupTargetLoginUrlConfig,
|
|
171
|
-
retry: retry || 0,
|
|
172
|
-
});
|
|
173
|
-
// we'll need this scratch org connection later;
|
|
174
|
-
const scratchOrg = await org_1.Org.create({
|
|
175
|
-
aliasOrUsername: soi.Username ?? soi.SignupUsername,
|
|
176
|
-
});
|
|
177
|
-
const username = scratchOrg.getUsername();
|
|
178
|
-
logger.debug(`scratch org username ${username}`);
|
|
179
|
-
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'deploy settings', scratchOrgInfo: soi });
|
|
180
|
-
const configAggregator = await configAggregator_1.ConfigAggregator.create();
|
|
181
|
-
const [authInfo] = await Promise.all([
|
|
182
|
-
(0, scratchOrgInfoApi_1.resolveUrl)(scratchOrgAuthInfo),
|
|
183
|
-
(0, scratchOrgInfoApi_1.deploySettings)(scratchOrg, settingsGenerator, apiversion ??
|
|
184
|
-
configAggregator.getPropertyValue(orgConfigProperties_1.OrgConfigProperties.ORG_API_VERSION) ??
|
|
185
|
-
(await scratchOrg.retrieveMaxApiVersion())),
|
|
186
|
-
]);
|
|
187
|
-
await scratchOrgAuthInfo.handleAliasAndDefaultSettings({
|
|
188
|
-
...{
|
|
189
|
-
alias,
|
|
190
|
-
setDefault,
|
|
191
|
-
setDefaultDevHub: false,
|
|
192
|
-
setTracksSource: tracksSource === false ? false : true,
|
|
193
|
-
},
|
|
194
|
-
});
|
|
195
|
-
cache.unset(scratchOrgInfoId);
|
|
196
|
-
const authFields = authInfo.getFields();
|
|
197
|
-
await Promise.all([(0, scratchOrgLifecycleEvents_1.emit)({ stage: 'done', scratchOrgInfo: soi }), cache.write(), (0, scratchOrgLifecycleEvents_1.emitPostOrgCreate)(authFields)]);
|
|
198
|
-
return {
|
|
199
|
-
username,
|
|
200
|
-
scratchOrgInfo: soi,
|
|
201
|
-
authInfo,
|
|
202
|
-
authFields: authInfo?.getFields(),
|
|
203
|
-
warnings,
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
exports.scratchOrgCreate = scratchOrgCreate;
|
|
207
|
-
const getSignupTargetLoginUrl = async () => {
|
|
208
|
-
try {
|
|
209
|
-
const project = await sfProject_1.SfProject.resolve();
|
|
210
|
-
const projectJson = await project.resolveProjectConfig();
|
|
211
|
-
return projectJson.signupTargetLoginUrl;
|
|
212
|
-
}
|
|
213
|
-
catch {
|
|
214
|
-
// a project isn't required for org:create
|
|
215
|
-
}
|
|
216
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.scratchOrgCreate = exports.scratchOrgResume = exports.DEFAULT_STREAM_TIMEOUT_MINUTES = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
* Licensed under the BSD 3-Clause license.
|
|
8
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
|
+
*/
|
|
10
|
+
const kit_1 = require("@salesforce/kit");
|
|
11
|
+
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
|
+
const messages_1 = require("../messages");
|
|
13
|
+
const logger_1 = require("../logger");
|
|
14
|
+
const configAggregator_1 = require("../config/configAggregator");
|
|
15
|
+
const orgConfigProperties_1 = require("../org/orgConfigProperties");
|
|
16
|
+
const sfProject_1 = require("../sfProject");
|
|
17
|
+
const stateAggregator_1 = require("../stateAggregator");
|
|
18
|
+
const org_1 = require("./org");
|
|
19
|
+
const scratchOrgInfoApi_1 = require("./scratchOrgInfoApi");
|
|
20
|
+
const scratchOrgSettingsGenerator_1 = require("./scratchOrgSettingsGenerator");
|
|
21
|
+
const scratchOrgInfoGenerator_1 = require("./scratchOrgInfoGenerator");
|
|
22
|
+
const authInfo_1 = require("./authInfo");
|
|
23
|
+
const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents");
|
|
24
|
+
const scratchOrgCache_1 = require("./scratchOrgCache");
|
|
25
|
+
const scratchOrgErrorCodes_1 = require("./scratchOrgErrorCodes");
|
|
26
|
+
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
27
|
+
const messages = messages_1.Messages.load('@salesforce/core', 'scratchOrgCreate', [
|
|
28
|
+
'DurationDaysValidationMaxError',
|
|
29
|
+
'DurationDaysValidationMinError',
|
|
30
|
+
'RetryNotIntError',
|
|
31
|
+
'DurationDaysNotIntError',
|
|
32
|
+
'CacheMissError',
|
|
33
|
+
]);
|
|
34
|
+
exports.DEFAULT_STREAM_TIMEOUT_MINUTES = 6;
|
|
35
|
+
const validateDuration = (durationDays) => {
|
|
36
|
+
const min = 1;
|
|
37
|
+
const max = 30;
|
|
38
|
+
if (Number.isInteger(durationDays)) {
|
|
39
|
+
if (durationDays < min) {
|
|
40
|
+
throw messages.createError('DurationDaysValidationMinError', [min, durationDays]);
|
|
41
|
+
}
|
|
42
|
+
if (durationDays > max) {
|
|
43
|
+
throw messages.createError('DurationDaysValidationMaxError', [max, durationDays]);
|
|
44
|
+
}
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
throw messages.createError('DurationDaysNotIntError');
|
|
48
|
+
};
|
|
49
|
+
const validateRetry = (retry) => {
|
|
50
|
+
if (!Number.isInteger(retry)) {
|
|
51
|
+
throw messages.createError('RetryNotIntError');
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const scratchOrgResume = async (jobId) => {
|
|
55
|
+
const [logger, cache] = await Promise.all([
|
|
56
|
+
logger_1.Logger.child('scratchOrgResume'),
|
|
57
|
+
scratchOrgCache_1.ScratchOrgCache.create(),
|
|
58
|
+
(0, scratchOrgLifecycleEvents_1.emit)({ stage: 'send request' }),
|
|
59
|
+
]);
|
|
60
|
+
logger.debug(`resuming scratch org creation for jobId: ${jobId}`);
|
|
61
|
+
if (!cache.has(jobId)) {
|
|
62
|
+
throw messages.createError('CacheMissError', [jobId]);
|
|
63
|
+
}
|
|
64
|
+
const { hubUsername, apiVersion, clientSecret, signupTargetLoginUrlConfig, definitionjson, alias, setDefault, tracksSource, } = cache.get(jobId);
|
|
65
|
+
const hubOrg = await org_1.Org.create({ aliasOrUsername: hubUsername });
|
|
66
|
+
const soi = await (0, scratchOrgInfoApi_1.queryScratchOrgInfo)(hubOrg, jobId);
|
|
67
|
+
await (0, scratchOrgErrorCodes_1.validateScratchOrgInfoForResume)({ jobId, scratchOrgInfo: soi, cache, hubUsername });
|
|
68
|
+
// At this point, the scratch org is "good".
|
|
69
|
+
// Some hubs have all the usernames set to `null`
|
|
70
|
+
const username = soi.Username ?? soi.SignupUsername;
|
|
71
|
+
// re-auth only if the org isn't in StateAggregator
|
|
72
|
+
const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
|
|
73
|
+
const scratchOrgAuthInfo = (await stateAggregator.orgs.exists(username))
|
|
74
|
+
? await authInfo_1.AuthInfo.create({ username })
|
|
75
|
+
: await (0, scratchOrgInfoApi_1.authorizeScratchOrg)({
|
|
76
|
+
scratchOrgInfoComplete: soi,
|
|
77
|
+
hubOrg,
|
|
78
|
+
clientSecret,
|
|
79
|
+
signupTargetLoginUrlConfig,
|
|
80
|
+
retry: 0,
|
|
81
|
+
});
|
|
82
|
+
const scratchOrg = await org_1.Org.create({ aliasOrUsername: username });
|
|
83
|
+
const configAggregator = await configAggregator_1.ConfigAggregator.create();
|
|
84
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'deploy settings', scratchOrgInfo: soi });
|
|
85
|
+
const settingsGenerator = new scratchOrgSettingsGenerator_1.default();
|
|
86
|
+
await settingsGenerator.extract({ ...soi, ...definitionjson });
|
|
87
|
+
const [authInfo] = await Promise.all([
|
|
88
|
+
(0, scratchOrgInfoApi_1.resolveUrl)(scratchOrgAuthInfo),
|
|
89
|
+
(0, scratchOrgInfoApi_1.deploySettings)(scratchOrg, settingsGenerator, apiVersion ??
|
|
90
|
+
configAggregator.getPropertyValue(orgConfigProperties_1.OrgConfigProperties.ORG_API_VERSION) ??
|
|
91
|
+
(await scratchOrg.retrieveMaxApiVersion())),
|
|
92
|
+
]);
|
|
93
|
+
await scratchOrgAuthInfo.handleAliasAndDefaultSettings({
|
|
94
|
+
alias,
|
|
95
|
+
setDefault: setDefault ?? false,
|
|
96
|
+
setDefaultDevHub: false,
|
|
97
|
+
setTracksSource: tracksSource ?? true,
|
|
98
|
+
});
|
|
99
|
+
cache.unset(soi.Id ?? jobId);
|
|
100
|
+
const authFields = authInfo.getFields();
|
|
101
|
+
await Promise.all([(0, scratchOrgLifecycleEvents_1.emit)({ stage: 'done', scratchOrgInfo: soi }), cache.write(), (0, scratchOrgLifecycleEvents_1.emitPostOrgCreate)(authFields)]);
|
|
102
|
+
return {
|
|
103
|
+
username,
|
|
104
|
+
scratchOrgInfo: soi,
|
|
105
|
+
authInfo,
|
|
106
|
+
authFields,
|
|
107
|
+
warnings: [],
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
exports.scratchOrgResume = scratchOrgResume;
|
|
111
|
+
const scratchOrgCreate = async (options) => {
|
|
112
|
+
const logger = await logger_1.Logger.child('scratchOrgCreate');
|
|
113
|
+
logger.debug('scratchOrgCreate');
|
|
114
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'prepare request' });
|
|
115
|
+
const { hubOrg, connectedAppConsumerKey, durationDays = 1, nonamespace, noancestors, wait = kit_1.Duration.minutes(exports.DEFAULT_STREAM_TIMEOUT_MINUTES), retry = 0, apiversion, definitionjson, definitionfile, orgConfig, clientSecret = undefined, alias, setDefault = false, tracksSource = true, } = options;
|
|
116
|
+
validateDuration(durationDays);
|
|
117
|
+
validateRetry(retry);
|
|
118
|
+
const { scratchOrgInfoPayload, ignoreAncestorIds, warnings } = await (0, scratchOrgInfoGenerator_1.getScratchOrgInfoPayload)({
|
|
119
|
+
definitionjson,
|
|
120
|
+
definitionfile,
|
|
121
|
+
connectedAppConsumerKey,
|
|
122
|
+
durationDays,
|
|
123
|
+
nonamespace,
|
|
124
|
+
noancestors,
|
|
125
|
+
orgConfig,
|
|
126
|
+
});
|
|
127
|
+
const scratchOrgInfo = await (0, scratchOrgInfoGenerator_1.generateScratchOrgInfo)({
|
|
128
|
+
hubOrg,
|
|
129
|
+
scratchOrgInfoPayload,
|
|
130
|
+
nonamespace,
|
|
131
|
+
ignoreAncestorIds,
|
|
132
|
+
});
|
|
133
|
+
// gets the scratch org settings (will use in both signup paths AND to deploy the settings)
|
|
134
|
+
const settingsGenerator = new scratchOrgSettingsGenerator_1.default();
|
|
135
|
+
const settings = await settingsGenerator.extract(scratchOrgInfo);
|
|
136
|
+
logger.debug(`the scratch org def file has settings: ${settingsGenerator.hasSettings()}`);
|
|
137
|
+
const [scratchOrgInfoRequestResult, signupTargetLoginUrlConfig] = await Promise.all([
|
|
138
|
+
// creates the scratch org info in the devhub
|
|
139
|
+
(0, scratchOrgInfoApi_1.requestScratchOrgCreation)(hubOrg, scratchOrgInfo, settingsGenerator),
|
|
140
|
+
getSignupTargetLoginUrl(),
|
|
141
|
+
]);
|
|
142
|
+
const scratchOrgInfoId = (0, ts_types_1.ensureString)(scratchOrgInfoRequestResult.id);
|
|
143
|
+
const cache = await scratchOrgCache_1.ScratchOrgCache.create();
|
|
144
|
+
cache.set(scratchOrgInfoId, {
|
|
145
|
+
hubUsername: hubOrg.getUsername(),
|
|
146
|
+
hubBaseUrl: hubOrg.getField(org_1.Org.Fields.INSTANCE_URL)?.toString(),
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
148
|
+
definitionjson: { ...(definitionjson ? JSON.parse(definitionjson) : {}), ...orgConfig, ...settings },
|
|
149
|
+
clientSecret,
|
|
150
|
+
alias,
|
|
151
|
+
setDefault,
|
|
152
|
+
tracksSource,
|
|
153
|
+
});
|
|
154
|
+
await cache.write();
|
|
155
|
+
logger.debug(`scratch org has recordId ${scratchOrgInfoId}`);
|
|
156
|
+
// this is where we stop--no polling
|
|
157
|
+
if (wait.minutes === 0) {
|
|
158
|
+
const soi = await (0, scratchOrgInfoApi_1.queryScratchOrgInfo)(hubOrg, scratchOrgInfoId);
|
|
159
|
+
return {
|
|
160
|
+
username: soi.SignupUsername,
|
|
161
|
+
warnings: [],
|
|
162
|
+
scratchOrgInfo: soi,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const soi = await (0, scratchOrgInfoApi_1.pollForScratchOrgInfo)(hubOrg, scratchOrgInfoId, wait);
|
|
166
|
+
const scratchOrgAuthInfo = await (0, scratchOrgInfoApi_1.authorizeScratchOrg)({
|
|
167
|
+
scratchOrgInfoComplete: soi,
|
|
168
|
+
hubOrg,
|
|
169
|
+
clientSecret,
|
|
170
|
+
signupTargetLoginUrlConfig,
|
|
171
|
+
retry: retry || 0,
|
|
172
|
+
});
|
|
173
|
+
// we'll need this scratch org connection later;
|
|
174
|
+
const scratchOrg = await org_1.Org.create({
|
|
175
|
+
aliasOrUsername: soi.Username ?? soi.SignupUsername,
|
|
176
|
+
});
|
|
177
|
+
const username = scratchOrg.getUsername();
|
|
178
|
+
logger.debug(`scratch org username ${username}`);
|
|
179
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'deploy settings', scratchOrgInfo: soi });
|
|
180
|
+
const configAggregator = await configAggregator_1.ConfigAggregator.create();
|
|
181
|
+
const [authInfo] = await Promise.all([
|
|
182
|
+
(0, scratchOrgInfoApi_1.resolveUrl)(scratchOrgAuthInfo),
|
|
183
|
+
(0, scratchOrgInfoApi_1.deploySettings)(scratchOrg, settingsGenerator, apiversion ??
|
|
184
|
+
configAggregator.getPropertyValue(orgConfigProperties_1.OrgConfigProperties.ORG_API_VERSION) ??
|
|
185
|
+
(await scratchOrg.retrieveMaxApiVersion())),
|
|
186
|
+
]);
|
|
187
|
+
await scratchOrgAuthInfo.handleAliasAndDefaultSettings({
|
|
188
|
+
...{
|
|
189
|
+
alias,
|
|
190
|
+
setDefault,
|
|
191
|
+
setDefaultDevHub: false,
|
|
192
|
+
setTracksSource: tracksSource === false ? false : true,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
cache.unset(scratchOrgInfoId);
|
|
196
|
+
const authFields = authInfo.getFields();
|
|
197
|
+
await Promise.all([(0, scratchOrgLifecycleEvents_1.emit)({ stage: 'done', scratchOrgInfo: soi }), cache.write(), (0, scratchOrgLifecycleEvents_1.emitPostOrgCreate)(authFields)]);
|
|
198
|
+
return {
|
|
199
|
+
username,
|
|
200
|
+
scratchOrgInfo: soi,
|
|
201
|
+
authInfo,
|
|
202
|
+
authFields: authInfo?.getFields(),
|
|
203
|
+
warnings,
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
exports.scratchOrgCreate = scratchOrgCreate;
|
|
207
|
+
const getSignupTargetLoginUrl = async () => {
|
|
208
|
+
try {
|
|
209
|
+
const project = await sfProject_1.SfProject.resolve();
|
|
210
|
+
const projectJson = await project.resolveProjectConfig();
|
|
211
|
+
return projectJson.signupTargetLoginUrl;
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
// a project isn't required for org:create
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
217
|
//# sourceMappingURL=scratchOrgCreate.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Optional } from '@salesforce/ts-types';
|
|
2
|
-
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
3
|
-
import { ScratchOrgCache } from './scratchOrgCache';
|
|
4
|
-
export declare const validateScratchOrgInfoForResume: ({ jobId, scratchOrgInfo, cache, hubUsername, }: {
|
|
5
|
-
jobId: string;
|
|
6
|
-
scratchOrgInfo: ScratchOrgInfo;
|
|
7
|
-
cache: ScratchOrgCache;
|
|
8
|
-
hubUsername: string;
|
|
9
|
-
}) => Promise<ScratchOrgInfo>;
|
|
10
|
-
export declare const checkScratchOrgInfoForErrors: (orgInfo: Optional<ScratchOrgInfo>, hubUsername: Optional<string>) => Promise<ScratchOrgInfo>;
|
|
1
|
+
import { Optional } from '@salesforce/ts-types';
|
|
2
|
+
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
3
|
+
import { ScratchOrgCache } from './scratchOrgCache';
|
|
4
|
+
export declare const validateScratchOrgInfoForResume: ({ jobId, scratchOrgInfo, cache, hubUsername, }: {
|
|
5
|
+
jobId: string;
|
|
6
|
+
scratchOrgInfo: ScratchOrgInfo;
|
|
7
|
+
cache: ScratchOrgCache;
|
|
8
|
+
hubUsername: string;
|
|
9
|
+
}) => Promise<ScratchOrgInfo>;
|
|
10
|
+
export declare const checkScratchOrgInfoForErrors: (orgInfo: Optional<ScratchOrgInfo>, hubUsername: Optional<string>) => Promise<ScratchOrgInfo>;
|
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2021, salesforce.com, inc.
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
* Licensed under the BSD 3-Clause license.
|
|
6
|
-
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.checkScratchOrgInfoForErrors = exports.validateScratchOrgInfoForResume = void 0;
|
|
10
|
-
const messages_1 = require("../messages");
|
|
11
|
-
const sfError_1 = require("../sfError");
|
|
12
|
-
const logger_1 = require("../logger");
|
|
13
|
-
const scratchOrgCache_1 = require("./scratchOrgCache");
|
|
14
|
-
const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents");
|
|
15
|
-
const WORKSPACE_CONFIG_FILENAME = 'sfdx-project.json';
|
|
16
|
-
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
17
|
-
const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgErrorCodes');
|
|
18
|
-
const namedMessages = messages_1.Messages.load('@salesforce/core', 'scratchOrgErrorCodes', [
|
|
19
|
-
'SignupFailedActionError',
|
|
20
|
-
'SignupFailedUnknownError',
|
|
21
|
-
'SignupFailedError',
|
|
22
|
-
'SignupUnexpectedError',
|
|
23
|
-
'StillInProgressError',
|
|
24
|
-
'action.StillInProgress',
|
|
25
|
-
'ScratchOrgDeletedError',
|
|
26
|
-
'NoScratchOrgInfoError',
|
|
27
|
-
]);
|
|
28
|
-
// getMessage will throw when the code isn't found
|
|
29
|
-
// and we don't know whether a given code takes arguments or not
|
|
30
|
-
const optionalErrorCodeMessage = (errorCode, args) => {
|
|
31
|
-
try {
|
|
32
|
-
// only apply args if message requires them
|
|
33
|
-
let message = messages.getMessage(errorCode);
|
|
34
|
-
if (message.includes('%s')) {
|
|
35
|
-
message = messages.getMessage(errorCode, args);
|
|
36
|
-
}
|
|
37
|
-
return message;
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
// generic error message
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
const validateScratchOrgInfoForResume = async ({ jobId, scratchOrgInfo, cache, hubUsername, }) => {
|
|
45
|
-
if (!scratchOrgInfo || !scratchOrgInfo.Id || scratchOrgInfo.Status === 'Deleted') {
|
|
46
|
-
// 1. scratch org info does not exist in that dev hub or has been deleted
|
|
47
|
-
cache.unset(jobId);
|
|
48
|
-
await cache.write();
|
|
49
|
-
throw scratchOrgInfo.Status === 'Deleted'
|
|
50
|
-
? namedMessages.createError('ScratchOrgDeletedError')
|
|
51
|
-
: namedMessages.createError('NoScratchOrgInfoError');
|
|
52
|
-
}
|
|
53
|
-
if (['New', 'Creating'].includes(scratchOrgInfo.Status)) {
|
|
54
|
-
// 2. scratchOrgInfo exists, still isn't finished. Stays in cache for future attempts
|
|
55
|
-
throw namedMessages.createError('StillInProgressError', [scratchOrgInfo.Status], ['action.StillInProgress']);
|
|
56
|
-
}
|
|
57
|
-
return (0, exports.checkScratchOrgInfoForErrors)(scratchOrgInfo, hubUsername);
|
|
58
|
-
};
|
|
59
|
-
exports.validateScratchOrgInfoForResume = validateScratchOrgInfoForResume;
|
|
60
|
-
const checkScratchOrgInfoForErrors = async (orgInfo, hubUsername) => {
|
|
61
|
-
if (!orgInfo || !orgInfo.Id) {
|
|
62
|
-
throw new sfError_1.SfError('No scratch org info found.', 'ScratchOrgInfoNotFound');
|
|
63
|
-
}
|
|
64
|
-
if (orgInfo.Status === 'Active') {
|
|
65
|
-
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'available', scratchOrgInfo: orgInfo });
|
|
66
|
-
return orgInfo;
|
|
67
|
-
}
|
|
68
|
-
if (orgInfo.Status === 'Error' && orgInfo.ErrorCode) {
|
|
69
|
-
await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id);
|
|
70
|
-
const message = optionalErrorCodeMessage(orgInfo.ErrorCode, [WORKSPACE_CONFIG_FILENAME]);
|
|
71
|
-
if (message) {
|
|
72
|
-
throw new sfError_1.SfError(message, 'RemoteOrgSignupFailed', [
|
|
73
|
-
namedMessages.getMessage('SignupFailedActionError', [orgInfo.ErrorCode]),
|
|
74
|
-
]);
|
|
75
|
-
}
|
|
76
|
-
throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedError', [orgInfo.ErrorCode]));
|
|
77
|
-
}
|
|
78
|
-
if (orgInfo.Status === 'Error') {
|
|
79
|
-
await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id);
|
|
80
|
-
const logger = await logger_1.Logger.child('ScratchOrgErrorCodes');
|
|
81
|
-
// Maybe the request object can help the user somehow
|
|
82
|
-
logger.error('No error code on signup error! Logging request.');
|
|
83
|
-
logger.error(orgInfo);
|
|
84
|
-
throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedUnknownError', [orgInfo.Id, hubUsername]), 'signupFailedUnknown');
|
|
85
|
-
}
|
|
86
|
-
throw new sfError_1.SfError(namedMessages.getMessage('SignupUnexpectedError'), 'UnexpectedSignupStatus');
|
|
87
|
-
};
|
|
88
|
-
exports.checkScratchOrgInfoForErrors = checkScratchOrgInfoForErrors;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.checkScratchOrgInfoForErrors = exports.validateScratchOrgInfoForResume = void 0;
|
|
10
|
+
const messages_1 = require("../messages");
|
|
11
|
+
const sfError_1 = require("../sfError");
|
|
12
|
+
const logger_1 = require("../logger");
|
|
13
|
+
const scratchOrgCache_1 = require("./scratchOrgCache");
|
|
14
|
+
const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents");
|
|
15
|
+
const WORKSPACE_CONFIG_FILENAME = 'sfdx-project.json';
|
|
16
|
+
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
17
|
+
const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgErrorCodes');
|
|
18
|
+
const namedMessages = messages_1.Messages.load('@salesforce/core', 'scratchOrgErrorCodes', [
|
|
19
|
+
'SignupFailedActionError',
|
|
20
|
+
'SignupFailedUnknownError',
|
|
21
|
+
'SignupFailedError',
|
|
22
|
+
'SignupUnexpectedError',
|
|
23
|
+
'StillInProgressError',
|
|
24
|
+
'action.StillInProgress',
|
|
25
|
+
'ScratchOrgDeletedError',
|
|
26
|
+
'NoScratchOrgInfoError',
|
|
27
|
+
]);
|
|
28
|
+
// getMessage will throw when the code isn't found
|
|
29
|
+
// and we don't know whether a given code takes arguments or not
|
|
30
|
+
const optionalErrorCodeMessage = (errorCode, args) => {
|
|
31
|
+
try {
|
|
32
|
+
// only apply args if message requires them
|
|
33
|
+
let message = messages.getMessage(errorCode);
|
|
34
|
+
if (message.includes('%s')) {
|
|
35
|
+
message = messages.getMessage(errorCode, args);
|
|
36
|
+
}
|
|
37
|
+
return message;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// generic error message
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const validateScratchOrgInfoForResume = async ({ jobId, scratchOrgInfo, cache, hubUsername, }) => {
|
|
45
|
+
if (!scratchOrgInfo || !scratchOrgInfo.Id || scratchOrgInfo.Status === 'Deleted') {
|
|
46
|
+
// 1. scratch org info does not exist in that dev hub or has been deleted
|
|
47
|
+
cache.unset(jobId);
|
|
48
|
+
await cache.write();
|
|
49
|
+
throw scratchOrgInfo.Status === 'Deleted'
|
|
50
|
+
? namedMessages.createError('ScratchOrgDeletedError')
|
|
51
|
+
: namedMessages.createError('NoScratchOrgInfoError');
|
|
52
|
+
}
|
|
53
|
+
if (['New', 'Creating'].includes(scratchOrgInfo.Status)) {
|
|
54
|
+
// 2. scratchOrgInfo exists, still isn't finished. Stays in cache for future attempts
|
|
55
|
+
throw namedMessages.createError('StillInProgressError', [scratchOrgInfo.Status], ['action.StillInProgress']);
|
|
56
|
+
}
|
|
57
|
+
return (0, exports.checkScratchOrgInfoForErrors)(scratchOrgInfo, hubUsername);
|
|
58
|
+
};
|
|
59
|
+
exports.validateScratchOrgInfoForResume = validateScratchOrgInfoForResume;
|
|
60
|
+
const checkScratchOrgInfoForErrors = async (orgInfo, hubUsername) => {
|
|
61
|
+
if (!orgInfo || !orgInfo.Id) {
|
|
62
|
+
throw new sfError_1.SfError('No scratch org info found.', 'ScratchOrgInfoNotFound');
|
|
63
|
+
}
|
|
64
|
+
if (orgInfo.Status === 'Active') {
|
|
65
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'available', scratchOrgInfo: orgInfo });
|
|
66
|
+
return orgInfo;
|
|
67
|
+
}
|
|
68
|
+
if (orgInfo.Status === 'Error' && orgInfo.ErrorCode) {
|
|
69
|
+
await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id);
|
|
70
|
+
const message = optionalErrorCodeMessage(orgInfo.ErrorCode, [WORKSPACE_CONFIG_FILENAME]);
|
|
71
|
+
if (message) {
|
|
72
|
+
throw new sfError_1.SfError(message, 'RemoteOrgSignupFailed', [
|
|
73
|
+
namedMessages.getMessage('SignupFailedActionError', [orgInfo.ErrorCode]),
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedError', [orgInfo.ErrorCode]));
|
|
77
|
+
}
|
|
78
|
+
if (orgInfo.Status === 'Error') {
|
|
79
|
+
await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id);
|
|
80
|
+
const logger = await logger_1.Logger.child('ScratchOrgErrorCodes');
|
|
81
|
+
// Maybe the request object can help the user somehow
|
|
82
|
+
logger.error('No error code on signup error! Logging request.');
|
|
83
|
+
logger.error(orgInfo);
|
|
84
|
+
throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedUnknownError', [orgInfo.Id, hubUsername]), 'signupFailedUnknown');
|
|
85
|
+
}
|
|
86
|
+
throw new sfError_1.SfError(namedMessages.getMessage('SignupUnexpectedError'), 'UnexpectedSignupStatus');
|
|
87
|
+
};
|
|
88
|
+
exports.checkScratchOrgInfoForErrors = checkScratchOrgInfoForErrors;
|
|
89
89
|
//# sourceMappingURL=scratchOrgErrorCodes.js.map
|