@salesforce/core 4.0.0 → 4.0.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/LICENSE.txt +1 -1
- package/README.md +93 -44
- package/lib/config/aliasesConfig.d.ts +12 -0
- package/lib/config/aliasesConfig.js +28 -0
- package/lib/config/authInfoConfig.d.ts +19 -0
- package/lib/config/authInfoConfig.js +35 -0
- package/lib/config/config.d.ts +87 -22
- package/lib/config/config.js +117 -65
- package/lib/config/configAggregator.d.ts +41 -35
- package/lib/config/configAggregator.js +102 -73
- package/lib/config/configFile.d.ts +2 -2
- package/lib/config/configFile.js +38 -29
- package/lib/config/configGroup.d.ts +141 -0
- package/lib/config/configGroup.js +225 -0
- package/lib/config/configStore.d.ts +9 -9
- package/lib/config/configStore.js +17 -15
- package/lib/config/envVars.d.ts +15 -9
- package/lib/config/envVars.js +71 -47
- package/lib/config/orgUsersConfig.js +2 -0
- package/lib/config/sandboxOrgConfig.js +2 -0
- package/lib/config/sandboxProcessCache.d.ts +16 -0
- package/lib/config/sandboxProcessCache.js +38 -0
- package/lib/config/tokensConfig.d.ts +10 -0
- package/lib/config/tokensConfig.js +29 -0
- package/lib/config/ttlConfig.d.ts +34 -0
- package/lib/config/ttlConfig.js +50 -0
- package/lib/crypto/crypto.js +15 -22
- package/lib/crypto/keyChain.js +2 -3
- package/lib/crypto/keyChainImpl.d.ts +5 -3
- package/lib/crypto/keyChainImpl.js +58 -61
- package/lib/crypto/secureBuffer.d.ts +1 -1
- package/lib/deviceOauthService.d.ts +3 -3
- package/lib/deviceOauthService.js +27 -25
- package/lib/exported.d.ts +15 -12
- package/lib/exported.js +28 -16
- package/lib/global.d.ts +11 -3
- package/lib/global.js +39 -12
- package/lib/lifecycleEvents.d.ts +1 -1
- package/lib/lifecycleEvents.js +3 -0
- package/lib/logger.d.ts +19 -9
- package/lib/logger.js +112 -86
- package/lib/messages.d.ts +53 -36
- package/lib/messages.js +81 -91
- package/lib/org/authInfo.d.ts +56 -20
- package/lib/org/authInfo.js +232 -131
- package/lib/org/authRemover.d.ts +8 -7
- package/lib/org/authRemover.js +32 -28
- package/lib/org/connection.d.ts +13 -37
- package/lib/org/connection.js +78 -124
- package/lib/org/index.js +5 -1
- package/lib/org/org.d.ts +151 -48
- package/lib/org/org.js +466 -220
- package/lib/org/orgConfigProperties.d.ts +64 -3
- package/lib/org/orgConfigProperties.js +96 -4
- package/lib/org/permissionSetAssignment.js +4 -13
- package/lib/org/scratchOrgCache.d.ts +20 -0
- package/lib/org/scratchOrgCache.js +33 -0
- package/lib/org/scratchOrgCreate.d.ts +28 -17
- package/lib/org/scratchOrgCreate.js +125 -53
- package/lib/org/scratchOrgErrorCodes.d.ts +9 -3
- package/lib/org/scratchOrgErrorCodes.js +34 -17
- package/lib/org/scratchOrgFeatureDeprecation.js +1 -6
- package/lib/org/scratchOrgInfoApi.d.ts +21 -47
- package/lib/org/scratchOrgInfoApi.js +129 -63
- package/lib/org/scratchOrgInfoGenerator.d.ts +6 -5
- package/lib/org/scratchOrgInfoGenerator.js +76 -62
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
- package/lib/org/scratchOrgLifecycleEvents.js +41 -0
- package/lib/org/scratchOrgSettingsGenerator.d.ts +44 -21
- package/lib/org/scratchOrgSettingsGenerator.js +165 -98
- package/lib/org/scratchOrgTypes.d.ts +43 -0
- package/lib/org/scratchOrgTypes.js +9 -0
- package/lib/org/user.d.ts +1 -1
- package/lib/org/user.js +25 -34
- package/lib/schema/printer.d.ts +6 -0
- package/lib/schema/printer.js +34 -31
- package/lib/schema/validator.d.ts +12 -10
- package/lib/schema/validator.js +56 -76
- package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -20
- package/lib/{sfdxError.js → sfError.js} +40 -30
- package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
- package/lib/sfProject.js +651 -0
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +27 -12
- package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +47 -31
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
- package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
- package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
- package/lib/stateAggregator/index.d.ts +4 -0
- package/lib/stateAggregator/index.js +27 -0
- package/lib/stateAggregator/stateAggregator.d.ts +25 -0
- package/lib/stateAggregator/stateAggregator.js +46 -0
- package/lib/status/myDomainResolver.d.ts +1 -1
- package/lib/status/myDomainResolver.js +4 -4
- package/lib/status/pollingClient.js +4 -4
- package/lib/status/streamingClient.d.ts +2 -2
- package/lib/status/streamingClient.js +58 -63
- package/lib/status/types.d.ts +2 -2
- package/lib/testSetup.d.ts +206 -75
- package/lib/testSetup.js +463 -165
- package/lib/util/cache.d.ts +2 -2
- package/lib/util/cache.js +6 -6
- package/lib/util/checkLightningDomain.js +3 -4
- package/lib/util/directoryWriter.d.ts +12 -0
- package/lib/util/directoryWriter.js +54 -0
- package/lib/util/getJwtAudienceUrl.js +1 -1
- package/lib/util/internal.d.ts +28 -2
- package/lib/util/internal.js +65 -8
- package/lib/util/jsonXmlTools.js +2 -4
- package/lib/util/mapKeys.d.ts +9 -9
- package/lib/util/mapKeys.js +13 -9
- package/lib/util/sfdc.d.ts +51 -51
- package/lib/util/sfdc.js +74 -79
- package/lib/util/sfdcUrl.d.ts +5 -19
- package/lib/util/sfdcUrl.js +40 -49
- package/lib/util/structuredWriter.d.ts +9 -0
- package/lib/util/structuredWriter.js +3 -0
- package/lib/util/zipWriter.d.ts +8 -6
- package/lib/util/zipWriter.js +13 -13
- package/lib/webOAuthServer.d.ts +20 -6
- package/lib/webOAuthServer.js +102 -56
- package/messageTransformer/messageTransformer.ts +93 -0
- package/messages/auth.md +9 -1
- package/messages/config.md +42 -6
- package/messages/connection.md +8 -0
- package/messages/core.md +10 -0
- package/messages/envVars.md +37 -3
- package/messages/org.md +21 -1
- package/messages/scratchOrgCreate.md +2 -6
- package/messages/scratchOrgErrorCodes.md +17 -1
- package/messages/scratchOrgInfoApi.md +9 -0
- package/messages/scratchOrgInfoGenerator.md +9 -1
- package/package.json +121 -46
- package/CHANGELOG.md +0 -1244
- package/lib/config/keychainConfig.d.ts +0 -19
- package/lib/config/keychainConfig.js +0 -43
- 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/accessors/tokenAccessor.js +0 -35
- package/lib/globalInfo/globalInfoConfig.d.ts +0 -36
- package/lib/globalInfo/globalInfoConfig.js +0 -105
- package/lib/globalInfo/index.d.ts +0 -6
- package/lib/globalInfo/index.js +0 -29
- package/lib/globalInfo/sfdxDataHandler.d.ts +0 -43
- package/lib/globalInfo/sfdxDataHandler.js +0 -217
- package/lib/globalInfo/types.d.ts +0 -39
- package/lib/globalInfo/types.js +0 -10
- package/lib/sfdxProject.js +0 -557
- package/lib/util/fs.d.ts +0 -201
- package/lib/util/fs.js +0 -378
|
@@ -6,18 +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.checkScratchOrgInfoForErrors = void 0;
|
|
9
|
+
exports.checkScratchOrgInfoForErrors = exports.validateScratchOrgInfoForResume = void 0;
|
|
10
10
|
const messages_1 = require("../messages");
|
|
11
|
-
const
|
|
11
|
+
const sfError_1 = require("../sfError");
|
|
12
|
+
const logger_1 = require("../logger");
|
|
13
|
+
const scratchOrgCache_1 = require("./scratchOrgCache");
|
|
14
|
+
const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents");
|
|
12
15
|
const WORKSPACE_CONFIG_FILENAME = 'sfdx-project.json';
|
|
13
|
-
messages_1.Messages.
|
|
14
|
-
const
|
|
15
|
-
const namedMessages = messages_1.Messages.load('@salesforce/core', 'scratchOrgErrorCodes', [
|
|
16
|
-
'SignupFailedActionError',
|
|
17
|
-
'SignupFailedUnknownError',
|
|
18
|
-
'SignupFailedError',
|
|
19
|
-
'SignupUnexpectedError',
|
|
20
|
-
]);
|
|
16
|
+
const messages = new messages_1.Messages('@salesforce/core', 'scratchOrgErrorCodes', new Map([["SignupFailedError", "The request to create a scratch org failed with error code: %s."], ["SignupFailedUnknownError", "An unknown server error occurred. Please try again. If you still see this error, contact Salesforce support for assistance. Include the information from 'sfdx force:data:record:get -s ScratchOrgInfo -i %s -u %s'."], ["SignupFailedActionError", "See https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_error_codes.htm for information on error code %s."], ["SignupUnexpectedError", "The request to create a scratch org returned an unexpected status"], ["StillInProgressError", "The scratch org is not ready yet (Status = %s)."], ["action.StillInProgress", "Wait for a few minutes, and then try the command again"], ["NoScratchOrgInfoError", "No ScratchOrgInfo object found in the Dev Hub you specified. Check that the ID and the Dev Hub are correct."], ["ScratchOrgDeletedError", "That scratch org has been deleted, so you can't connect to it anymore."], ["INVALID_ID_FIELD", "Provide a valid template ID, in the format 0TTxxxxxxxxxxxx."], ["T-0002", "We couldn\u2019t find a template or snapshot with the ID or name specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["T-0003", "The template specified in the scratch org definition is unapproved. Contact Salesforce Support to request template approval."], ["T-0004", "The Trialforce Source Organization (TSO) for the template doesn\u2019t exist or has expired."], ["S-1006", "Provide a valid email address in your scratch org definition or your %s file."], ["S-2006", "Provide a valid country code in your scratch org definition or your %s file."], ["S-1017", "Specify a namespace that\u2019s used by a release org associated with your Dev Hub org."], ["S-1018", "Provide a valid My Domain value. This value can\u2019t include double hyphens, end in a hyphen, include restricted words, or be more than 40 characters long."], ["S-1019", "The My Domain value you chose is already in use."], ["S-1026", "Provide a valid namespace value. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["S-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance."], ["SH-0001", "Can\u2019t create scratch org. Contact the source org admin to add your Dev Hub org ID to Setup > Org Shape. Then try again."], ["SH-0002", "Can\u2019t create scratch org. No org shape exists for the specified sourceOrg. Create an org shape and try again."], ["SH-0003", "Can\u2019t create scratch org from org shape. The org shape version is outdated. Recreate the org shape and try again."], ["C-1007", "The username provided to the org:create command is already in use. Run 'force:org:list --clean' to remove stale org authentications or create the org with a different username."], ["C-1015", "We encountered a problem while registering your My Domain value with the DNS provider. Please try again."], ["C-1016", "We encountered a problem while attempting to configure and approve the Connected App for your org. Verify the Connected App configuration with your Salesforce admin."], ["C-1017", "Provide a valid namespace prefix. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["C-1020", "We couldn't find a template with the ID specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["C-1027", "The template specified in the Scratch Definition isn\u2019t supported. Specify a generic edition (such as Developer or Enterprise), or specify a template ID."], ["C-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance"]]));
|
|
17
|
+
const namedMessages = new messages_1.Messages('@salesforce/core', 'scratchOrgErrorCodes', new Map([["SignupFailedError", "The request to create a scratch org failed with error code: %s."], ["SignupFailedUnknownError", "An unknown server error occurred. Please try again. If you still see this error, contact Salesforce support for assistance. Include the information from 'sfdx force:data:record:get -s ScratchOrgInfo -i %s -u %s'."], ["SignupFailedActionError", "See https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_error_codes.htm for information on error code %s."], ["SignupUnexpectedError", "The request to create a scratch org returned an unexpected status"], ["StillInProgressError", "The scratch org is not ready yet (Status = %s)."], ["action.StillInProgress", "Wait for a few minutes, and then try the command again"], ["NoScratchOrgInfoError", "No ScratchOrgInfo object found in the Dev Hub you specified. Check that the ID and the Dev Hub are correct."], ["ScratchOrgDeletedError", "That scratch org has been deleted, so you can't connect to it anymore."], ["INVALID_ID_FIELD", "Provide a valid template ID, in the format 0TTxxxxxxxxxxxx."], ["T-0002", "We couldn\u2019t find a template or snapshot with the ID or name specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["T-0003", "The template specified in the scratch org definition is unapproved. Contact Salesforce Support to request template approval."], ["T-0004", "The Trialforce Source Organization (TSO) for the template doesn\u2019t exist or has expired."], ["S-1006", "Provide a valid email address in your scratch org definition or your %s file."], ["S-2006", "Provide a valid country code in your scratch org definition or your %s file."], ["S-1017", "Specify a namespace that\u2019s used by a release org associated with your Dev Hub org."], ["S-1018", "Provide a valid My Domain value. This value can\u2019t include double hyphens, end in a hyphen, include restricted words, or be more than 40 characters long."], ["S-1019", "The My Domain value you chose is already in use."], ["S-1026", "Provide a valid namespace value. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["S-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance."], ["SH-0001", "Can\u2019t create scratch org. Contact the source org admin to add your Dev Hub org ID to Setup > Org Shape. Then try again."], ["SH-0002", "Can\u2019t create scratch org. No org shape exists for the specified sourceOrg. Create an org shape and try again."], ["SH-0003", "Can\u2019t create scratch org from org shape. The org shape version is outdated. Recreate the org shape and try again."], ["C-1007", "The username provided to the org:create command is already in use. Run 'force:org:list --clean' to remove stale org authentications or create the org with a different username."], ["C-1015", "We encountered a problem while registering your My Domain value with the DNS provider. Please try again."], ["C-1016", "We encountered a problem while attempting to configure and approve the Connected App for your org. Verify the Connected App configuration with your Salesforce admin."], ["C-1017", "Provide a valid namespace prefix. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["C-1020", "We couldn't find a template with the ID specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["C-1027", "The template specified in the Scratch Definition isn\u2019t supported. Specify a generic edition (such as Developer or Enterprise), or specify a template ID."], ["C-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance"]]));
|
|
21
18
|
// getMessage will throw when the code isn't found
|
|
22
19
|
// and we don't know whether a given code takes arguments or not
|
|
23
20
|
const optionalErrorCodeMessage = (errorCode, args) => {
|
|
@@ -34,29 +31,49 @@ const optionalErrorCodeMessage = (errorCode, args) => {
|
|
|
34
31
|
return undefined;
|
|
35
32
|
}
|
|
36
33
|
};
|
|
37
|
-
const
|
|
38
|
-
if (!
|
|
39
|
-
|
|
34
|
+
const validateScratchOrgInfoForResume = async ({ jobId, scratchOrgInfo, cache, hubUsername, }) => {
|
|
35
|
+
if (!scratchOrgInfo?.Id || scratchOrgInfo.Status === 'Deleted') {
|
|
36
|
+
// 1. scratch org info does not exist in that dev hub or has been deleted
|
|
37
|
+
cache.unset(jobId);
|
|
38
|
+
await cache.write();
|
|
39
|
+
throw scratchOrgInfo.Status === 'Deleted'
|
|
40
|
+
? namedMessages.createError('ScratchOrgDeletedError')
|
|
41
|
+
: namedMessages.createError('NoScratchOrgInfoError');
|
|
42
|
+
}
|
|
43
|
+
if (['New', 'Creating'].includes(scratchOrgInfo.Status)) {
|
|
44
|
+
// 2. scratchOrgInfo exists, still isn't finished. Stays in cache for future attempts
|
|
45
|
+
throw namedMessages.createError('StillInProgressError', [scratchOrgInfo.Status], ['action.StillInProgress']);
|
|
46
|
+
}
|
|
47
|
+
return (0, exports.checkScratchOrgInfoForErrors)(scratchOrgInfo, hubUsername);
|
|
48
|
+
};
|
|
49
|
+
exports.validateScratchOrgInfoForResume = validateScratchOrgInfoForResume;
|
|
50
|
+
const checkScratchOrgInfoForErrors = async (orgInfo, hubUsername) => {
|
|
51
|
+
if (!orgInfo?.Id) {
|
|
52
|
+
throw new sfError_1.SfError('No scratch org info found.', 'ScratchOrgInfoNotFound');
|
|
40
53
|
}
|
|
41
54
|
if (orgInfo.Status === 'Active') {
|
|
55
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'available', scratchOrgInfo: orgInfo });
|
|
42
56
|
return orgInfo;
|
|
43
57
|
}
|
|
44
58
|
if (orgInfo.Status === 'Error' && orgInfo.ErrorCode) {
|
|
59
|
+
await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id);
|
|
45
60
|
const message = optionalErrorCodeMessage(orgInfo.ErrorCode, [WORKSPACE_CONFIG_FILENAME]);
|
|
46
61
|
if (message) {
|
|
47
|
-
throw new
|
|
62
|
+
throw new sfError_1.SfError(message, 'RemoteOrgSignupFailed', [
|
|
48
63
|
namedMessages.getMessage('SignupFailedActionError', [orgInfo.ErrorCode]),
|
|
49
64
|
]);
|
|
50
65
|
}
|
|
51
|
-
throw new
|
|
66
|
+
throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedError', [orgInfo.ErrorCode]));
|
|
52
67
|
}
|
|
53
68
|
if (orgInfo.Status === 'Error') {
|
|
69
|
+
await scratchOrgCache_1.ScratchOrgCache.unset(orgInfo.Id);
|
|
70
|
+
const logger = await logger_1.Logger.child('ScratchOrgErrorCodes');
|
|
54
71
|
// Maybe the request object can help the user somehow
|
|
55
72
|
logger.error('No error code on signup error! Logging request.');
|
|
56
73
|
logger.error(orgInfo);
|
|
57
|
-
throw new
|
|
74
|
+
throw new sfError_1.SfError(namedMessages.getMessage('SignupFailedUnknownError', [orgInfo.Id, hubUsername]), 'signupFailedUnknown');
|
|
58
75
|
}
|
|
59
|
-
throw new
|
|
76
|
+
throw new sfError_1.SfError(namedMessages.getMessage('SignupUnexpectedError'), 'UnexpectedSignupStatus');
|
|
60
77
|
};
|
|
61
78
|
exports.checkScratchOrgInfoForErrors = checkScratchOrgInfoForErrors;
|
|
62
79
|
//# sourceMappingURL=scratchOrgErrorCodes.js.map
|
|
@@ -14,12 +14,7 @@ exports.ScratchOrgFeatureDeprecation = void 0;
|
|
|
14
14
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
15
15
|
// Local
|
|
16
16
|
const messages_1 = require("../messages");
|
|
17
|
-
messages_1.Messages.
|
|
18
|
-
const messages = messages_1.Messages.load('@salesforce/core', 'scratchOrgFeatureDeprecation', [
|
|
19
|
-
'quantifiedFeatureWithoutQuantityWarning',
|
|
20
|
-
'mappedFeatureWarning',
|
|
21
|
-
'deprecatedFeatureWarning',
|
|
22
|
-
]);
|
|
17
|
+
const messages = new messages_1.Messages('@salesforce/core', 'scratchOrgFeatureDeprecation', new Map([["quantifiedFeatureWithoutQuantityWarning", "The feature %s will be deprecated in a future release. It's been replaced by %s:<value>, which requires you to specify a quantity."], ["mappedFeatureWarning", "The feature %s has been deprecated. It has been replaced with %s in this scratch org create request."], ["deprecatedFeatureWarning", "The feature %s has been deprecated. It has been removed from the list of requested features."]]));
|
|
23
18
|
const FEATURE_TYPES = {
|
|
24
19
|
// simpleFeatureMapping holds a set of direct replacement values for features.
|
|
25
20
|
simpleFeatureMapping: {
|
|
@@ -1,51 +1,20 @@
|
|
|
1
|
-
import { Optional } from '@salesforce/ts-types';
|
|
2
1
|
import { Duration } from '@salesforce/kit';
|
|
3
2
|
import { SaveResult } from 'jsforce';
|
|
4
3
|
import { AuthInfo } from './authInfo';
|
|
5
4
|
import { Org } from './org';
|
|
6
|
-
import SettingsGenerator
|
|
7
|
-
|
|
8
|
-
AdminEmail?: string;
|
|
9
|
-
readonly CreatedDate?: string;
|
|
10
|
-
ConnectedAppCallbackUrl?: string;
|
|
11
|
-
ConnectedAppConsumerKey?: string;
|
|
12
|
-
Country?: string;
|
|
13
|
-
Description?: string;
|
|
14
|
-
DurationDays?: string;
|
|
15
|
-
Edition?: string;
|
|
16
|
-
readonly ErrorCode?: string;
|
|
17
|
-
readonly ExpirationDate?: string;
|
|
18
|
-
Features?: string;
|
|
19
|
-
HasSampleData?: boolean;
|
|
20
|
-
readonly Id?: string;
|
|
21
|
-
Language?: string;
|
|
22
|
-
LoginUrl: string;
|
|
23
|
-
readonly Name?: string;
|
|
24
|
-
Namespace?: string;
|
|
25
|
-
OrgName?: string;
|
|
26
|
-
Release?: 'Current' | 'Previous' | 'Preview';
|
|
27
|
-
readonly ScratchOrg?: string;
|
|
28
|
-
SourceOrg?: string;
|
|
29
|
-
readonly AuthCode: string;
|
|
30
|
-
Snapshot: string;
|
|
31
|
-
readonly Status: 'New' | 'Creating' | 'Active' | 'Error' | 'Deleted';
|
|
32
|
-
readonly SignupEmail: string;
|
|
33
|
-
readonly SignupUsername: string;
|
|
34
|
-
readonly SignupInstance: string;
|
|
35
|
-
Username: string;
|
|
36
|
-
settings?: Record<string, unknown>;
|
|
37
|
-
objectSettings?: {
|
|
38
|
-
[objectName: string]: ObjectSetting;
|
|
39
|
-
};
|
|
40
|
-
orgPreferences?: {
|
|
41
|
-
enabled: string[];
|
|
42
|
-
disabled: string[];
|
|
43
|
-
};
|
|
44
|
-
}
|
|
5
|
+
import SettingsGenerator from './scratchOrgSettingsGenerator';
|
|
6
|
+
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
45
7
|
export interface JsForceError extends Error {
|
|
46
8
|
errorCode: string;
|
|
47
9
|
fields: string[];
|
|
48
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param hubOrg Org
|
|
14
|
+
* @param id Record ID for the ScratchOrgInfoObject
|
|
15
|
+
* @returns Promise<ScratchOrgInfo>
|
|
16
|
+
*/
|
|
17
|
+
export declare const queryScratchOrgInfo: (hubOrg: Org, id: string) => Promise<ScratchOrgInfo>;
|
|
49
18
|
/**
|
|
50
19
|
* after we successfully signup an org we need to trade the auth token for access and refresh token.
|
|
51
20
|
*
|
|
@@ -83,12 +52,17 @@ export declare const requestScratchOrgCreation: (hubOrg: Org, scratchOrgRequest:
|
|
|
83
52
|
*/
|
|
84
53
|
export declare const pollForScratchOrgInfo: (hubOrg: Org, scratchOrgInfoId: string, timeout?: Duration) => Promise<ScratchOrgInfo>;
|
|
85
54
|
/**
|
|
86
|
-
*
|
|
55
|
+
* Deploy settings to the newly created scratch org
|
|
56
|
+
*
|
|
57
|
+
* @param scratchOrg an instance of the Org class
|
|
58
|
+
* @param orgSettings an instance of the SettingsGenerator class
|
|
59
|
+
* @param apiVersion the api version (used when created the package.xml)
|
|
60
|
+
*/
|
|
61
|
+
export declare const deploySettings: (scratchOrg: Org, orgSettings: SettingsGenerator, apiVersion: string, timeout?: Duration) => Promise<void>;
|
|
62
|
+
/**
|
|
87
63
|
*
|
|
88
|
-
* @param scratchOrgAuthInfo
|
|
89
|
-
* @
|
|
90
|
-
* @param orgSettings - The ScratchOrg settings
|
|
91
|
-
* @param scratchOrg - The scratchOrg Org info
|
|
92
|
-
* @returns {Promise<Optional<AuthInfo>>}
|
|
64
|
+
* @param scratchOrgAuthInfo an AuthInfo class from the scratch org
|
|
65
|
+
* @returns AuthInfo
|
|
93
66
|
*/
|
|
94
|
-
export declare const
|
|
67
|
+
export declare const resolveUrl: (scratchOrgAuthInfo: AuthInfo) => Promise<AuthInfo>;
|
|
68
|
+
export declare const updateRevisionCounterToZero: (scratchOrg: Org) => Promise<void>;
|
|
@@ -6,23 +6,23 @@
|
|
|
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.
|
|
9
|
+
exports.updateRevisionCounterToZero = exports.resolveUrl = exports.deploySettings = exports.pollForScratchOrgInfo = exports.requestScratchOrgCreation = exports.authorizeScratchOrg = exports.queryScratchOrgInfo = void 0;
|
|
10
10
|
const kit_1 = require("@salesforce/kit");
|
|
11
|
-
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
11
|
const ts_retry_promise_1 = require("ts-retry-promise");
|
|
13
12
|
const logger_1 = require("../logger");
|
|
14
|
-
const mapKeys_1 = require("../util/mapKeys");
|
|
15
13
|
const messages_1 = require("../messages");
|
|
16
|
-
const
|
|
14
|
+
const sfError_1 = require("../sfError");
|
|
17
15
|
const sfdcUrl_1 = require("../util/sfdcUrl");
|
|
18
16
|
const pollingClient_1 = require("../status/pollingClient");
|
|
19
17
|
const myDomainResolver_1 = require("../status/myDomainResolver");
|
|
18
|
+
const lifecycleEvents_1 = require("../lifecycleEvents");
|
|
19
|
+
const mapKeys_1 = require("../util/mapKeys");
|
|
20
20
|
const authInfo_1 = require("./authInfo");
|
|
21
21
|
const org_1 = require("./org");
|
|
22
22
|
const scratchOrgErrorCodes_1 = require("./scratchOrgErrorCodes");
|
|
23
|
-
|
|
24
|
-
const messages = messages_1.Messages
|
|
25
|
-
const errorCodes = messages_1.Messages
|
|
23
|
+
const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents");
|
|
24
|
+
const messages = new messages_1.Messages('@salesforce/core', 'scratchOrgInfoApi', new Map([["SignupFieldsMissingError", "Required fields are missing for org creation: [%s]"], ["SignupDuplicateSettingsSpecifiedError", "You cannot use 'settings' and `'orgPreferences' in your scratch definition file, please specify one or the other."], ["DeprecatedPrefFormat", "We've deprecated OrgPreferences. Update the scratch org definition file to replace OrgPreferences with their corresponding settings."], ["SourceStatusResetFailureError", "Successfully created org with ID: %s and name: %s. Unfortunately, source tracking isn\u2019t working as expected. If you run force:source:status, the results may be incorrect. Try again by creating another scratch org."], ["hubOrgIsNotDevHub", "Make sure that the org with username %s and ID %s is enabled as a Dev Hub. To enable it, open the org in your browser, navigate to the Dev Hub page in Setup, and click Enable.\nIf you still see this error after enabling the Dev Hub feature, then re-authenticate to the org."]]));
|
|
25
|
+
const errorCodes = new messages_1.Messages('@salesforce/core', 'scratchOrgErrorCodes', new Map([["SignupFailedError", "The request to create a scratch org failed with error code: %s."], ["SignupFailedUnknownError", "An unknown server error occurred. Please try again. If you still see this error, contact Salesforce support for assistance. Include the information from 'sfdx force:data:record:get -s ScratchOrgInfo -i %s -u %s'."], ["SignupFailedActionError", "See https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs_error_codes.htm for information on error code %s."], ["SignupUnexpectedError", "The request to create a scratch org returned an unexpected status"], ["StillInProgressError", "The scratch org is not ready yet (Status = %s)."], ["action.StillInProgress", "Wait for a few minutes, and then try the command again"], ["NoScratchOrgInfoError", "No ScratchOrgInfo object found in the Dev Hub you specified. Check that the ID and the Dev Hub are correct."], ["ScratchOrgDeletedError", "That scratch org has been deleted, so you can't connect to it anymore."], ["INVALID_ID_FIELD", "Provide a valid template ID, in the format 0TTxxxxxxxxxxxx."], ["T-0002", "We couldn\u2019t find a template or snapshot with the ID or name specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["T-0003", "The template specified in the scratch org definition is unapproved. Contact Salesforce Support to request template approval."], ["T-0004", "The Trialforce Source Organization (TSO) for the template doesn\u2019t exist or has expired."], ["S-1006", "Provide a valid email address in your scratch org definition or your %s file."], ["S-2006", "Provide a valid country code in your scratch org definition or your %s file."], ["S-1017", "Specify a namespace that\u2019s used by a release org associated with your Dev Hub org."], ["S-1018", "Provide a valid My Domain value. This value can\u2019t include double hyphens, end in a hyphen, include restricted words, or be more than 40 characters long."], ["S-1019", "The My Domain value you chose is already in use."], ["S-1026", "Provide a valid namespace value. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["S-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance."], ["SH-0001", "Can\u2019t create scratch org. Contact the source org admin to add your Dev Hub org ID to Setup > Org Shape. Then try again."], ["SH-0002", "Can\u2019t create scratch org. No org shape exists for the specified sourceOrg. Create an org shape and try again."], ["SH-0003", "Can\u2019t create scratch org from org shape. The org shape version is outdated. Recreate the org shape and try again."], ["C-1007", "The username provided to the org:create command is already in use. Run 'force:org:list --clean' to remove stale org authentications or create the org with a different username."], ["C-1015", "We encountered a problem while registering your My Domain value with the DNS provider. Please try again."], ["C-1016", "We encountered a problem while attempting to configure and approve the Connected App for your org. Verify the Connected App configuration with your Salesforce admin."], ["C-1017", "Provide a valid namespace prefix. This value must begin with a letter. It can\u2019t include consecutive underscores, end in an underscore, be more than 15 characters long, or be a restricted or reserved namespace. Only alphanumeric characters and underscores are allowed."], ["C-1020", "We couldn't find a template with the ID specified in the scratch org definition. If you\u2019re sure the ID is correct, contact Salesforce Support."], ["C-1027", "The template specified in the Scratch Definition isn\u2019t supported. Specify a generic edition (such as Developer or Enterprise), or specify a template ID."], ["C-9999", "A fatal signup error occurred. Please try again. If you still see this error, contact Salesforce Support for assistance"]]));
|
|
26
26
|
/**
|
|
27
27
|
* Returns the url to be used to authorize into the new scratch org
|
|
28
28
|
*
|
|
@@ -45,7 +45,7 @@ const getOrgInstanceAuthority = function (scratchOrgInfoComplete, hubOrgLoginUrl
|
|
|
45
45
|
// For Falcon sandboxes, try the LoginURL instead; createdOrgInstance will not yield a valid URL
|
|
46
46
|
altUrl = scratchOrgInfoComplete.LoginUrl;
|
|
47
47
|
}
|
|
48
|
-
return signupTargetLoginUrlConfig
|
|
48
|
+
return signupTargetLoginUrlConfig ?? altUrl;
|
|
49
49
|
};
|
|
50
50
|
/**
|
|
51
51
|
* Returns OAuth2Options object
|
|
@@ -62,8 +62,8 @@ const buildOAuth2Options = async (options) => {
|
|
|
62
62
|
logger.debug(`isJwtFlow: ${isJwtFlow}`);
|
|
63
63
|
if (isJwtFlow && !process.env.SFDX_CLIENT_SECRET) {
|
|
64
64
|
oauth2Options.privateKeyFile = options.hubOrg.getConnection().getAuthInfoFields().privateKey;
|
|
65
|
-
const retries =
|
|
66
|
-
const timeoutInSeconds = kit_1.env.getNumber('SFDX_JWT_AUTH_RETRY_TIMEOUT')
|
|
65
|
+
const retries = options?.retry ?? kit_1.env.getNumber('SFDX_JWT_AUTH_RETRY_ATTEMPTS') ?? 0;
|
|
66
|
+
const timeoutInSeconds = kit_1.env.getNumber('SFDX_JWT_AUTH_RETRY_TIMEOUT') ?? 300;
|
|
67
67
|
const timeout = kit_1.Duration.seconds(timeoutInSeconds).milliseconds;
|
|
68
68
|
const delay = retries ? timeout / retries : 1000;
|
|
69
69
|
return {
|
|
@@ -130,6 +130,14 @@ const getAuthInfo = async (options) => {
|
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
};
|
|
133
|
+
/**
|
|
134
|
+
*
|
|
135
|
+
* @param hubOrg Org
|
|
136
|
+
* @param id Record ID for the ScratchOrgInfoObject
|
|
137
|
+
* @returns Promise<ScratchOrgInfo>
|
|
138
|
+
*/
|
|
139
|
+
const queryScratchOrgInfo = async (hubOrg, id) => (await hubOrg.getConnection().sobject('ScratchOrgInfo').retrieve(id));
|
|
140
|
+
exports.queryScratchOrgInfo = queryScratchOrgInfo;
|
|
133
141
|
/**
|
|
134
142
|
* after we successfully signup an org we need to trade the auth token for access and refresh token.
|
|
135
143
|
*
|
|
@@ -142,8 +150,8 @@ const getAuthInfo = async (options) => {
|
|
|
142
150
|
* @returns {Promise<AuthInfo>}
|
|
143
151
|
*/
|
|
144
152
|
const authorizeScratchOrg = async (options) => {
|
|
145
|
-
|
|
146
|
-
|
|
153
|
+
const { scratchOrgInfoComplete, hubOrg, clientSecret, signupTargetLoginUrlConfig, retry } = options;
|
|
154
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'authenticate', scratchOrgInfo: scratchOrgInfoComplete });
|
|
147
155
|
const logger = await logger_1.Logger.child('authorizeScratchOrg');
|
|
148
156
|
logger.debug(`scratchOrgInfoComplete: ${JSON.stringify(scratchOrgInfoComplete, null, 4)}`);
|
|
149
157
|
// if we didn't have it marked as a devhub but just successfully used it as one, this will update the authFile, fix cache, etc
|
|
@@ -154,7 +162,7 @@ const authorizeScratchOrg = async (options) => {
|
|
|
154
162
|
hubOrg,
|
|
155
163
|
clientSecret,
|
|
156
164
|
scratchOrgInfoComplete,
|
|
157
|
-
retry
|
|
165
|
+
retry,
|
|
158
166
|
signupTargetLoginUrlConfig,
|
|
159
167
|
});
|
|
160
168
|
const authInfo = await getAuthInfo({
|
|
@@ -167,7 +175,7 @@ const authorizeScratchOrg = async (options) => {
|
|
|
167
175
|
});
|
|
168
176
|
await authInfo.save({
|
|
169
177
|
devHubUsername: hubOrg.getUsername(),
|
|
170
|
-
created: new Date(
|
|
178
|
+
created: new Date(scratchOrgInfoComplete.CreatedDate ?? new Date()).valueOf().toString(),
|
|
171
179
|
expirationDate: scratchOrgInfoComplete.ExpirationDate,
|
|
172
180
|
clientId: scratchOrgInfoComplete.ConnectedAppConsumerKey,
|
|
173
181
|
createdOrgInstance: scratchOrgInfoComplete.SignupInstance,
|
|
@@ -182,19 +190,19 @@ const checkOrgDoesntExist = async (scratchOrgInfo) => {
|
|
|
182
190
|
if (!usernameKey) {
|
|
183
191
|
return;
|
|
184
192
|
}
|
|
185
|
-
const username =
|
|
193
|
+
const username = scratchOrgInfo[usernameKey];
|
|
186
194
|
if (username && username.length > 0) {
|
|
187
195
|
try {
|
|
188
196
|
await authInfo_1.AuthInfo.create({ username: username.toLowerCase() });
|
|
189
197
|
}
|
|
190
198
|
catch (error) {
|
|
191
|
-
const
|
|
199
|
+
const sfError = sfError_1.SfError.wrap(error);
|
|
192
200
|
// if an AuthInfo couldn't be created that means no AuthFile exists.
|
|
193
|
-
if (
|
|
201
|
+
if (sfError.name === 'NamedOrgNotFoundError') {
|
|
194
202
|
return;
|
|
195
203
|
}
|
|
196
204
|
// Something unexpected
|
|
197
|
-
throw
|
|
205
|
+
throw sfError;
|
|
198
206
|
}
|
|
199
207
|
// An org file already exists
|
|
200
208
|
throw errorCodes.createError('C-1007');
|
|
@@ -209,6 +217,9 @@ const checkOrgDoesntExist = async (scratchOrgInfo) => {
|
|
|
209
217
|
* @returns {Promise<SaveResult>}
|
|
210
218
|
*/
|
|
211
219
|
const requestScratchOrgCreation = async (hubOrg, scratchOrgRequest, settings) => {
|
|
220
|
+
if (!hubOrg.isDevHubOrg()) {
|
|
221
|
+
throw messages.createError('hubOrgIsNotDevHub', [hubOrg.getUsername(), hubOrg.getOrgId()]);
|
|
222
|
+
}
|
|
212
223
|
// If these were present, they were already used to initialize the scratchOrgSettingsGenerator.
|
|
213
224
|
// They shouldn't be submitted as part of the scratchOrgInfo.
|
|
214
225
|
delete scratchOrgRequest.settings;
|
|
@@ -216,24 +227,29 @@ const requestScratchOrgCreation = async (hubOrg, scratchOrgRequest, settings) =>
|
|
|
216
227
|
// We do not allow you to specify the old and the new way of doing post create settings
|
|
217
228
|
if (scratchOrgRequest.orgPreferences && settings.hasSettings()) {
|
|
218
229
|
// This is not allowed
|
|
219
|
-
throw new
|
|
230
|
+
throw new sfError_1.SfError('SignupDuplicateSettingsSpecifiedError');
|
|
220
231
|
}
|
|
221
232
|
// deprecated old style orgPreferences
|
|
222
233
|
if (scratchOrgRequest.orgPreferences) {
|
|
223
|
-
throw new
|
|
234
|
+
throw new sfError_1.SfError(messages.getMessage('DeprecatedPrefFormat'));
|
|
224
235
|
}
|
|
225
236
|
const scratchOrgInfo = (0, mapKeys_1.default)(scratchOrgRequest, kit_1.upperFirst, true);
|
|
237
|
+
if (typeof scratchOrgInfo.Username === 'string') {
|
|
238
|
+
scratchOrgInfo.Username = scratchOrgInfo.Username.toLowerCase();
|
|
239
|
+
}
|
|
226
240
|
await checkOrgDoesntExist(scratchOrgInfo); // throw if it does exist.
|
|
227
241
|
try {
|
|
242
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'send request' });
|
|
243
|
+
// return await will cause this catch block to run instead of the caller's catch block
|
|
228
244
|
return await hubOrg.getConnection().sobject('ScratchOrgInfo').create(scratchOrgInfo);
|
|
229
245
|
}
|
|
230
246
|
catch (error) {
|
|
231
247
|
// this is a jsforce error which contains the property "fields" which regular error don't
|
|
232
248
|
const jsForceError = error;
|
|
233
249
|
if (jsForceError.errorCode === 'REQUIRED_FIELD_MISSING') {
|
|
234
|
-
throw new
|
|
250
|
+
throw new sfError_1.SfError(messages.getMessage('SignupFieldsMissingError', [jsForceError.fields.toString()]));
|
|
235
251
|
}
|
|
236
|
-
throw
|
|
252
|
+
throw sfError_1.SfError.wrap(jsForceError);
|
|
237
253
|
}
|
|
238
254
|
};
|
|
239
255
|
exports.requestScratchOrgCreation = requestScratchOrgCreation;
|
|
@@ -253,7 +269,7 @@ timeout = kit_1.Duration.minutes(15)) => {
|
|
|
253
269
|
const pollingOptions = {
|
|
254
270
|
async poll() {
|
|
255
271
|
try {
|
|
256
|
-
const resultInProgress = await
|
|
272
|
+
const resultInProgress = await (0, exports.queryScratchOrgInfo)(hubOrg, scratchOrgInfoId);
|
|
257
273
|
logger.debug(`polling client result: ${JSON.stringify(resultInProgress, null, 4)}`);
|
|
258
274
|
// Once it's "done" we can return it
|
|
259
275
|
if (resultInProgress.Status === 'Active' || resultInProgress.Status === 'Error') {
|
|
@@ -262,6 +278,7 @@ timeout = kit_1.Duration.minutes(15)) => {
|
|
|
262
278
|
payload: resultInProgress,
|
|
263
279
|
};
|
|
264
280
|
}
|
|
281
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'wait for org', scratchOrgInfo: resultInProgress });
|
|
265
282
|
logger.debug(`Scratch org status is ${resultInProgress.Status}`);
|
|
266
283
|
return {
|
|
267
284
|
completed: false,
|
|
@@ -283,68 +300,117 @@ timeout = kit_1.Duration.minutes(15)) => {
|
|
|
283
300
|
const client = await pollingClient_1.PollingClient.create(pollingOptions);
|
|
284
301
|
try {
|
|
285
302
|
const resultInProgress = await client.subscribe();
|
|
286
|
-
return (0, scratchOrgErrorCodes_1.checkScratchOrgInfoForErrors)(resultInProgress, hubOrg.getUsername()
|
|
303
|
+
return await (0, scratchOrgErrorCodes_1.checkScratchOrgInfoForErrors)(resultInProgress, hubOrg.getUsername());
|
|
287
304
|
}
|
|
288
305
|
catch (error) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
306
|
+
if (error instanceof Error) {
|
|
307
|
+
const sfError = sfError_1.SfError.wrap(error);
|
|
308
|
+
sfError.setData({
|
|
309
|
+
username: hubOrg.getUsername(),
|
|
310
|
+
orgId: hubOrg.getOrgId(),
|
|
311
|
+
scratchOrgInfoId,
|
|
312
|
+
});
|
|
313
|
+
throw sfError;
|
|
292
314
|
}
|
|
293
|
-
throw new
|
|
315
|
+
throw new sfError_1.SfError(`The scratch org did not complete within ${timeout.minutes} minutes`, 'orgCreationTimeout', [
|
|
294
316
|
'Try your force:org:create command again with a longer --wait value',
|
|
295
317
|
]);
|
|
296
318
|
}
|
|
297
319
|
};
|
|
298
320
|
exports.pollForScratchOrgInfo = pollForScratchOrgInfo;
|
|
299
321
|
/**
|
|
300
|
-
*
|
|
322
|
+
* Deploy settings to the newly created scratch org
|
|
301
323
|
*
|
|
302
|
-
* @param
|
|
303
|
-
* @param
|
|
304
|
-
* @param
|
|
305
|
-
* @param scratchOrg - The scratchOrg Org info
|
|
306
|
-
* @returns {Promise<Optional<AuthInfo>>}
|
|
324
|
+
* @param scratchOrg an instance of the Org class
|
|
325
|
+
* @param orgSettings an instance of the SettingsGenerator class
|
|
326
|
+
* @param apiVersion the api version (used when created the package.xml)
|
|
307
327
|
*/
|
|
308
|
-
const
|
|
309
|
-
const logger = await logger_1.Logger.child('scratchOrgInfoApi-
|
|
328
|
+
const deploySettings = async (scratchOrg, orgSettings, apiVersion, timeout = kit_1.Duration.minutes(10)) => {
|
|
329
|
+
const logger = await logger_1.Logger.child('scratchOrgInfoApi-deploySettings');
|
|
310
330
|
if (orgSettings.hasSettings()) {
|
|
311
331
|
// deploy the settings to the newly created scratch org
|
|
312
332
|
logger.debug(`deploying scratch org settings with apiVersion ${apiVersion}`);
|
|
313
333
|
try {
|
|
314
334
|
await orgSettings.createDeploy();
|
|
315
|
-
await orgSettings.deploySettingsViaFolder(scratchOrg, apiVersion);
|
|
335
|
+
await orgSettings.deploySettingsViaFolder(scratchOrg, apiVersion, timeout);
|
|
336
|
+
// updating the revision num to zero during org:creation if source members are created during org:create.
|
|
337
|
+
// This only happens for some specific scratch org definition file.
|
|
338
|
+
await (0, exports.updateRevisionCounterToZero)(scratchOrg);
|
|
339
|
+
logger.trace('Settings deployed to org');
|
|
316
340
|
}
|
|
317
341
|
catch (error) {
|
|
318
|
-
throw
|
|
342
|
+
throw sfError_1.SfError.wrap(error);
|
|
319
343
|
}
|
|
320
344
|
}
|
|
345
|
+
};
|
|
346
|
+
exports.deploySettings = deploySettings;
|
|
347
|
+
/**
|
|
348
|
+
*
|
|
349
|
+
* @param scratchOrgAuthInfo an AuthInfo class from the scratch org
|
|
350
|
+
* @returns AuthInfo
|
|
351
|
+
*/
|
|
352
|
+
const resolveUrl = async (scratchOrgAuthInfo) => {
|
|
353
|
+
const logger = await logger_1.Logger.child('scratchOrgInfoApi-resolveUrl');
|
|
321
354
|
const { instanceUrl } = scratchOrgAuthInfo.getFields();
|
|
322
|
-
if (instanceUrl) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
instanceUrl,
|
|
341
|
-
});
|
|
342
|
-
logger.debug('processScratchOrgInfoResult - err data: %s', sfdxError.data);
|
|
343
|
-
}
|
|
344
|
-
throw sfdxError;
|
|
345
|
-
}
|
|
355
|
+
if (!instanceUrl) {
|
|
356
|
+
const sfError = new sfError_1.SfError('Org does not have instanceUrl');
|
|
357
|
+
sfError.setData({
|
|
358
|
+
orgId: scratchOrgAuthInfo.getFields().orgId,
|
|
359
|
+
username: scratchOrgAuthInfo.getFields().username,
|
|
360
|
+
instanceUrl,
|
|
361
|
+
});
|
|
362
|
+
throw sfError;
|
|
363
|
+
}
|
|
364
|
+
logger.debug(`processScratchOrgInfoResult - resultData.instanceUrl: ${instanceUrl}`);
|
|
365
|
+
const options = {
|
|
366
|
+
timeout: kit_1.Duration.minutes(3),
|
|
367
|
+
frequency: kit_1.Duration.seconds(10),
|
|
368
|
+
url: new sfdcUrl_1.SfdcUrl(instanceUrl),
|
|
369
|
+
};
|
|
370
|
+
try {
|
|
371
|
+
const resolver = await myDomainResolver_1.MyDomainResolver.create(options);
|
|
372
|
+
await resolver.resolve();
|
|
346
373
|
return scratchOrgAuthInfo;
|
|
347
374
|
}
|
|
375
|
+
catch (error) {
|
|
376
|
+
const sfError = sfError_1.SfError.wrap(error);
|
|
377
|
+
logger.debug('processScratchOrgInfoResult - err: %s', error);
|
|
378
|
+
if (sfError.name === 'MyDomainResolverTimeoutError') {
|
|
379
|
+
sfError.setData({
|
|
380
|
+
orgId: scratchOrgAuthInfo.getFields().orgId,
|
|
381
|
+
username: scratchOrgAuthInfo.getFields().username,
|
|
382
|
+
instanceUrl,
|
|
383
|
+
});
|
|
384
|
+
logger.debug('processScratchOrgInfoResult - err data: %s', sfError.data);
|
|
385
|
+
}
|
|
386
|
+
throw sfError;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
exports.resolveUrl = resolveUrl;
|
|
390
|
+
const updateRevisionCounterToZero = async (scratchOrg) => {
|
|
391
|
+
const conn = scratchOrg.getConnection();
|
|
392
|
+
const queryResult = await conn.tooling.sobject('SourceMember').find({ RevisionCounter: { $gt: 0 } }, ['Id']);
|
|
393
|
+
if (queryResult.length === 0) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
// jsforce has a bug in its `update` code such that tooling#update doesn't work right
|
|
398
|
+
// https://github.com/jsforce/jsforce/blob/265eba5c734439dd7b77610c05b63bde7d4b1e83/src/connection.ts#L1082
|
|
399
|
+
// will result in `this._ensureVersion is not a function`
|
|
400
|
+
// so until that is resolved, we hit the API with singular records
|
|
401
|
+
// once that's fixed, you can use the following code for a single API call
|
|
402
|
+
// await conn.tooling
|
|
403
|
+
// .sobject('SourceMember')
|
|
404
|
+
// .update(queryResult.map((record) => ({ Id: record.Id, RevisionCounter: 0 })));
|
|
405
|
+
await Promise.all(queryResult.map((record) => conn.tooling.sobject('SourceMember').update({ Id: record.Id, RevisionCounter: 0 })));
|
|
406
|
+
}
|
|
407
|
+
catch (err) {
|
|
408
|
+
await lifecycleEvents_1.Lifecycle.getInstance().emitWarning(messages.getMessage('SourceStatusResetFailureError', [
|
|
409
|
+
scratchOrg.getOrgId(),
|
|
410
|
+
scratchOrg.getUsername(),
|
|
411
|
+
err instanceof Error ? err.message : '',
|
|
412
|
+
]));
|
|
413
|
+
}
|
|
348
414
|
};
|
|
349
|
-
exports.
|
|
415
|
+
exports.updateRevisionCounterToZero = updateRevisionCounterToZero;
|
|
350
416
|
//# sourceMappingURL=scratchOrgInfoApi.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SfProjectJson } from '../sfProject';
|
|
2
2
|
import { Org } from './org';
|
|
3
|
-
import { ScratchOrgInfo } from './
|
|
4
|
-
|
|
3
|
+
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
4
|
+
type PartialScratchOrgInfo = Pick<ScratchOrgInfo, 'ConnectedAppConsumerKey' | 'AuthCode' | 'Snapshot' | 'Status' | 'LoginUrl' | 'SignupEmail' | 'SignupUsername' | 'SignupInstance' | 'Username'>;
|
|
5
5
|
export interface ScratchOrgInfoPayload extends PartialScratchOrgInfo {
|
|
6
6
|
orgName: string;
|
|
7
7
|
package2AncestorIds: string;
|
|
@@ -9,15 +9,16 @@ export interface ScratchOrgInfoPayload extends PartialScratchOrgInfo {
|
|
|
9
9
|
connectedAppConsumerKey: string;
|
|
10
10
|
namespace: string;
|
|
11
11
|
connectedAppCallbackUrl: string;
|
|
12
|
+
durationDays: number;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Generates the package2AncestorIds scratch org property
|
|
15
16
|
*
|
|
16
17
|
* @param scratchOrgInfo - the scratchOrgInfo passed in by the user
|
|
17
|
-
* @param projectJson -
|
|
18
|
+
* @param projectJson - sfProjectJson
|
|
18
19
|
* @param hubOrg - the hub org, in case we need to do queries
|
|
19
20
|
*/
|
|
20
|
-
export declare const getAncestorIds: (scratchOrgInfo: ScratchOrgInfoPayload, projectJson:
|
|
21
|
+
export declare const getAncestorIds: (scratchOrgInfo: ScratchOrgInfoPayload, projectJson: SfProjectJson, hubOrg: Org) => Promise<string>;
|
|
21
22
|
/**
|
|
22
23
|
* Takes in a scratchOrgInfo and fills in the missing fields
|
|
23
24
|
*
|