@salesforce/core 2.32.0 → 2.34.2
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 +25 -0
- package/LICENSE.txt +1 -1
- package/lib/exported.d.ts +3 -1
- package/lib/exported.js +5 -1
- package/lib/org.d.ts +99 -1
- package/lib/org.js +215 -1
- package/lib/scratchOrgCreate.d.ts +43 -0
- package/lib/scratchOrgCreate.js +135 -0
- package/lib/scratchOrgErrorCodes.d.ts +4 -0
- package/lib/scratchOrgErrorCodes.js +53 -0
- package/lib/scratchOrgFeatureDeprecation.d.ts +26 -0
- package/lib/scratchOrgFeatureDeprecation.js +106 -0
- package/lib/scratchOrgInfoApi.d.ts +94 -0
- package/lib/scratchOrgInfoApi.js +331 -0
- package/lib/scratchOrgInfoGenerator.d.ts +62 -0
- package/lib/scratchOrgInfoGenerator.js +226 -0
- package/lib/scratchOrgSettingsGenerator.d.ts +56 -0
- package/lib/scratchOrgSettingsGenerator.js +208 -0
- package/lib/status/streamingClient.d.ts +0 -1
- package/lib/status/streamingClient.js +5 -13
- package/lib/util/jsonXmlTools.d.ts +14 -0
- package/lib/util/jsonXmlTools.js +41 -0
- package/lib/util/mapKeys.d.ts +14 -0
- package/lib/util/mapKeys.js +48 -0
- package/lib/util/zipWriter.d.ts +14 -0
- package/lib/util/zipWriter.js +68 -0
- package/lib/webOAuthServer.js +1 -1
- package/messages/org.json +4 -1
- package/messages/scratchOrgCreate.json +4 -0
- package/messages/scratchOrgErrorCodes.json +27 -0
- package/messages/scratchOrgFeatureDeprecation.json +5 -0
- package/messages/scratchOrgInfoApi.json +5 -0
- package/messages/scratchOrgInfoGenerator.json +7 -0
- package/package.json +9 -6
|
@@ -0,0 +1,53 @@
|
|
|
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 = void 0;
|
|
10
|
+
const messages_1 = require("./messages");
|
|
11
|
+
const sfdxError_1 = require("./sfdxError");
|
|
12
|
+
const WORKSPACE_CONFIG_FILENAME = 'sfdx-project.json';
|
|
13
|
+
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
14
|
+
const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgErrorCodes');
|
|
15
|
+
// getMessage will throw when the code isn't found
|
|
16
|
+
// and we don't know whether a given code takes arguments or not
|
|
17
|
+
const optionalErrorCodeMessage = (errorCode, args) => {
|
|
18
|
+
try {
|
|
19
|
+
// only apply args if message requires them
|
|
20
|
+
let message = messages.getMessage(errorCode);
|
|
21
|
+
if (message.includes('%s')) {
|
|
22
|
+
message = messages.getMessage(errorCode, args);
|
|
23
|
+
}
|
|
24
|
+
return message;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// generic error message
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const checkScratchOrgInfoForErrors = (orgInfo, hubUsername, logger) => {
|
|
32
|
+
if (orgInfo.Status === 'Active') {
|
|
33
|
+
return orgInfo;
|
|
34
|
+
}
|
|
35
|
+
if (orgInfo.Status === 'Error' && orgInfo.ErrorCode) {
|
|
36
|
+
const message = optionalErrorCodeMessage(orgInfo.ErrorCode, [WORKSPACE_CONFIG_FILENAME]);
|
|
37
|
+
if (message) {
|
|
38
|
+
throw new sfdxError_1.SfdxError(message, 'RemoteOrgSignupFailed', [
|
|
39
|
+
messages.getMessage('signupFailedAction', [orgInfo.ErrorCode]),
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
throw new sfdxError_1.SfdxError(messages.getMessage('signupFailed', [orgInfo.ErrorCode]));
|
|
43
|
+
}
|
|
44
|
+
if (orgInfo.Status === 'Error') {
|
|
45
|
+
// Maybe the request object can help the user somehow
|
|
46
|
+
logger.error('No error code on signup error! Logging request.');
|
|
47
|
+
logger.error(orgInfo);
|
|
48
|
+
throw new sfdxError_1.SfdxError(messages.getMessage('signupFailedUnknown', [orgInfo.Id, hubUsername]), 'signupFailedUnknown');
|
|
49
|
+
}
|
|
50
|
+
throw new sfdxError_1.SfdxError(messages.getMessage('signupUnexpected'), 'UnexpectedSignupStatus');
|
|
51
|
+
};
|
|
52
|
+
exports.checkScratchOrgInfoForErrors = checkScratchOrgInfoForErrors;
|
|
53
|
+
//# sourceMappingURL=scratchOrgErrorCodes.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
interface FeatureTypes {
|
|
2
|
+
simpleFeatureMapping: {
|
|
3
|
+
[key: string]: string[];
|
|
4
|
+
};
|
|
5
|
+
quantifiedFeatureMapping: Record<string, string | number | boolean | null | undefined>;
|
|
6
|
+
deprecatedFeatures: string[];
|
|
7
|
+
}
|
|
8
|
+
export declare class ScratchOrgFeatureDeprecation {
|
|
9
|
+
private featureTypes;
|
|
10
|
+
constructor(options?: FeatureTypes);
|
|
11
|
+
/**
|
|
12
|
+
* Gets list of feature warnings that should be logged
|
|
13
|
+
*
|
|
14
|
+
* @param features The requested features.
|
|
15
|
+
* @returns List of string feature warnings.
|
|
16
|
+
*/
|
|
17
|
+
getFeatureWarnings(features: string | string[]): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Removes all deprecated features for the organization.
|
|
20
|
+
*
|
|
21
|
+
* @param features List of features to filter
|
|
22
|
+
* @returns feature array with proper mapping.
|
|
23
|
+
*/
|
|
24
|
+
filterDeprecatedFeatures(features: string[]): string[];
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
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.ScratchOrgFeatureDeprecation = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Certain Org Features require a translation or should be deprecated.
|
|
12
|
+
* Encapsulates feature mappings and deprecated features.
|
|
13
|
+
*/
|
|
14
|
+
const ts_types_1 = require("@salesforce/ts-types");
|
|
15
|
+
// Local
|
|
16
|
+
const messages_1 = require("./messages");
|
|
17
|
+
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
18
|
+
const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgFeatureDeprecation');
|
|
19
|
+
const FEATURE_TYPES = {
|
|
20
|
+
// simpleFeatureMapping holds a set of direct replacement values for features.
|
|
21
|
+
simpleFeatureMapping: {
|
|
22
|
+
SALESWAVE: ['DEVELOPMENTWAVE'],
|
|
23
|
+
SERVICEWAVE: ['DEVELOPMENTWAVE'],
|
|
24
|
+
},
|
|
25
|
+
quantifiedFeatureMapping: {},
|
|
26
|
+
deprecatedFeatures: [
|
|
27
|
+
'EXPANDEDSOURCETRACKING',
|
|
28
|
+
'LISTCUSTOMSETTINGCREATION',
|
|
29
|
+
'AppNavCapabilities',
|
|
30
|
+
'EditInSubtab',
|
|
31
|
+
'OldNewRecordFlowConsole',
|
|
32
|
+
'OldNewRecordFlowStd',
|
|
33
|
+
'DesktopLayoutStandardOff',
|
|
34
|
+
'SplitViewOnStandardOff',
|
|
35
|
+
'PopOutUtilities',
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
class ScratchOrgFeatureDeprecation {
|
|
39
|
+
// Allow override for testing.
|
|
40
|
+
constructor(options = FEATURE_TYPES) {
|
|
41
|
+
this.featureTypes = options;
|
|
42
|
+
this.featureTypes.deprecatedFeatures = this.featureTypes.deprecatedFeatures.map((deprecatedFeature) => deprecatedFeature.toUpperCase());
|
|
43
|
+
// Make all of the keys in simpleFeatureMapping upper case.
|
|
44
|
+
const sfm = {};
|
|
45
|
+
Object.keys(this.featureTypes.simpleFeatureMapping).forEach((key) => {
|
|
46
|
+
sfm[key.toUpperCase()] = this.featureTypes.simpleFeatureMapping[key];
|
|
47
|
+
});
|
|
48
|
+
this.featureTypes.simpleFeatureMapping = sfm;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Gets list of feature warnings that should be logged
|
|
52
|
+
*
|
|
53
|
+
* @param features The requested features.
|
|
54
|
+
* @returns List of string feature warnings.
|
|
55
|
+
*/
|
|
56
|
+
getFeatureWarnings(features) {
|
|
57
|
+
/* Get warning messages for deprecated features and feature mappings.*/
|
|
58
|
+
const featureWarningMessages = [];
|
|
59
|
+
const requestedFeatures = (ts_types_1.isString(features) ? features : features.join(';')).toUpperCase();
|
|
60
|
+
/* If a public quantified feature is defined without a quantity, throw a warning.*/
|
|
61
|
+
Object.keys(this.featureTypes.quantifiedFeatureMapping).forEach((key) => {
|
|
62
|
+
if (new RegExp(`${key};|${key},|${key}$`, 'i').test(requestedFeatures)) {
|
|
63
|
+
featureWarningMessages.push(messages.getMessage('quantifiedFeatureWithoutQuantityWarning', [
|
|
64
|
+
key,
|
|
65
|
+
this.featureTypes.quantifiedFeatureMapping[key],
|
|
66
|
+
]));
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
/* If a simply mapped feature is defined, log a warning.*/
|
|
70
|
+
Object.keys(this.featureTypes.simpleFeatureMapping).forEach((key) => {
|
|
71
|
+
if (new RegExp(`${key};|${key},|${key}$`, 'i').test(requestedFeatures)) {
|
|
72
|
+
const tokens = '[' + this.featureTypes.simpleFeatureMapping[key].map((v) => "'" + v + "'").join(',') + ']';
|
|
73
|
+
featureWarningMessages.push(messages.getMessage('mappedFeatureWarning', [key, tokens]));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
/* If a deprecated feature is identified as deprecated, throw a warning.*/
|
|
77
|
+
this.featureTypes.deprecatedFeatures.forEach((deprecatedFeature) => {
|
|
78
|
+
if (requestedFeatures.includes(deprecatedFeature)) {
|
|
79
|
+
featureWarningMessages.push(messages.getMessage('deprecatedFeatureWarning', [deprecatedFeature]));
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return featureWarningMessages;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Removes all deprecated features for the organization.
|
|
86
|
+
*
|
|
87
|
+
* @param features List of features to filter
|
|
88
|
+
* @returns feature array with proper mapping.
|
|
89
|
+
*/
|
|
90
|
+
filterDeprecatedFeatures(features) {
|
|
91
|
+
return features.reduce((previousValue, currentValue) => {
|
|
92
|
+
const feature = currentValue.toUpperCase();
|
|
93
|
+
if (this.featureTypes.deprecatedFeatures.includes(feature)) {
|
|
94
|
+
return previousValue;
|
|
95
|
+
}
|
|
96
|
+
else if (this.featureTypes.simpleFeatureMapping[feature]) {
|
|
97
|
+
/* If a simply mapped feature is specified, then perform the mapping. */
|
|
98
|
+
const simpleFeatureMapping = this.featureTypes.simpleFeatureMapping[feature];
|
|
99
|
+
return [...previousValue, ...simpleFeatureMapping];
|
|
100
|
+
}
|
|
101
|
+
return [...previousValue, currentValue];
|
|
102
|
+
}, []);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.ScratchOrgFeatureDeprecation = ScratchOrgFeatureDeprecation;
|
|
106
|
+
//# sourceMappingURL=scratchOrgFeatureDeprecation.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Optional } from '@salesforce/ts-types';
|
|
2
|
+
import { Duration } from '@salesforce/kit';
|
|
3
|
+
import { RecordResult } from 'jsforce';
|
|
4
|
+
import { retry } from 'ts-retry-promise';
|
|
5
|
+
import { Org } from './org';
|
|
6
|
+
import { AuthInfo } from './authInfo';
|
|
7
|
+
import SettingsGenerator, { ObjectSetting } from './scratchOrgSettingsGenerator';
|
|
8
|
+
export interface ScratchOrgInfo {
|
|
9
|
+
AdminEmail?: string;
|
|
10
|
+
readonly CreatedDate?: string;
|
|
11
|
+
ConnectedAppCallbackUrl?: string;
|
|
12
|
+
ConnectedAppConsumerKey?: string;
|
|
13
|
+
Country?: string;
|
|
14
|
+
Description?: string;
|
|
15
|
+
DurationDays?: string;
|
|
16
|
+
Edition?: string;
|
|
17
|
+
readonly ErrorCode?: string;
|
|
18
|
+
readonly ExpirationDate?: string;
|
|
19
|
+
Features?: string;
|
|
20
|
+
HasSampleData?: boolean;
|
|
21
|
+
readonly Id?: string;
|
|
22
|
+
Language?: string;
|
|
23
|
+
LoginUrl: string;
|
|
24
|
+
readonly Name?: string;
|
|
25
|
+
Namespace?: string;
|
|
26
|
+
OrgName?: string;
|
|
27
|
+
Release?: 'Current' | 'Previous' | 'Preview';
|
|
28
|
+
readonly ScratchOrg?: string;
|
|
29
|
+
SourceOrg?: string;
|
|
30
|
+
readonly AuthCode: string;
|
|
31
|
+
Snapshot: string;
|
|
32
|
+
readonly Status: 'New' | 'Creating' | 'Active' | 'Error' | 'Deleted';
|
|
33
|
+
readonly SignupEmail: string;
|
|
34
|
+
readonly SignupUsername: string;
|
|
35
|
+
readonly SignupInstance: string;
|
|
36
|
+
Username: string;
|
|
37
|
+
settings?: Record<string, unknown>;
|
|
38
|
+
objectSettings?: {
|
|
39
|
+
[objectName: string]: ObjectSetting;
|
|
40
|
+
};
|
|
41
|
+
orgPreferences?: {
|
|
42
|
+
enabled: string[];
|
|
43
|
+
disabled: string[];
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export interface JsForceError extends Error {
|
|
47
|
+
errorCode: string;
|
|
48
|
+
fields: string[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* after we successfully signup an org we need to trade the auth token for access and refresh token.
|
|
52
|
+
*
|
|
53
|
+
* @param scratchOrgInfoComplete - The completed ScratchOrgInfo which should contain an access token.
|
|
54
|
+
* @param hubOrg - the environment hub org
|
|
55
|
+
* @param clientSecret - The OAuth client secret. May be null for JWT OAuth flow.
|
|
56
|
+
* @param signupTargetLoginUrlConfig - Login url
|
|
57
|
+
* @param retry - auth retry attempts
|
|
58
|
+
* @returns {Promise<AuthInfo>}
|
|
59
|
+
*/
|
|
60
|
+
export declare const authorizeScratchOrg: (options: {
|
|
61
|
+
scratchOrgInfoComplete: ScratchOrgInfo;
|
|
62
|
+
hubOrg: Org;
|
|
63
|
+
clientSecret?: string;
|
|
64
|
+
signupTargetLoginUrlConfig?: string;
|
|
65
|
+
retry?: number;
|
|
66
|
+
}) => Promise<AuthInfo>;
|
|
67
|
+
/**
|
|
68
|
+
* This extracts orgPrefs/settings from the user input and performs a basic scratchOrgInfo request.
|
|
69
|
+
*
|
|
70
|
+
* @param hubOrg - the environment hub org
|
|
71
|
+
* @param scratchOrgRequest - An object containing the fields of the ScratchOrgInfo
|
|
72
|
+
* @param settings - An object containing org settings
|
|
73
|
+
* @returns {Promise<RecordResult>}
|
|
74
|
+
*/
|
|
75
|
+
export declare const requestScratchOrgCreation: (hubOrg: Org, scratchOrgRequest: ScratchOrgInfo, settings: SettingsGenerator) => Promise<RecordResult>;
|
|
76
|
+
/**
|
|
77
|
+
* This retrieves the ScratchOrgInfo, polling until the status is Active or Error
|
|
78
|
+
*
|
|
79
|
+
* @param hubOrg
|
|
80
|
+
* @param scratchOrgInfoId - the id of the scratchOrgInfo that we are retrieving
|
|
81
|
+
* @param timeout - A Duration object
|
|
82
|
+
* @returns {Promise<ScratchOrgInfo>}
|
|
83
|
+
*/
|
|
84
|
+
export declare const pollForScratchOrgInfo: (hubOrg: Org, scratchOrgInfoId: string, timeout?: Duration) => Promise<ScratchOrgInfo>;
|
|
85
|
+
/**
|
|
86
|
+
* This authenticates into the newly created org and sets org preferences
|
|
87
|
+
*
|
|
88
|
+
* @param scratchOrgAuthInfo - an object containing the AuthInfo of the ScratchOrg
|
|
89
|
+
* @param apiVersion - the target api version
|
|
90
|
+
* @param orgSettings - The ScratchOrg settings
|
|
91
|
+
* @param scratchOrg - The scratchOrg Org info
|
|
92
|
+
* @returns {Promise<Optional<AuthInfo>>}
|
|
93
|
+
*/
|
|
94
|
+
export declare const deploySettingsAndResolveUrl: (scratchOrgAuthInfo: AuthInfo, apiVersion: string, orgSettings: SettingsGenerator, scratchOrg: Org) => Promise<Optional<AuthInfo>>;
|
|
@@ -0,0 +1,331 @@
|
|
|
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.deploySettingsAndResolveUrl = exports.pollForScratchOrgInfo = exports.requestScratchOrgCreation = exports.authorizeScratchOrg = void 0;
|
|
10
|
+
const kit_1 = require("@salesforce/kit");
|
|
11
|
+
const ts_types_1 = require("@salesforce/ts-types");
|
|
12
|
+
const ts_retry_promise_1 = require("ts-retry-promise");
|
|
13
|
+
// Local
|
|
14
|
+
const org_1 = require("./org");
|
|
15
|
+
const logger_1 = require("./logger");
|
|
16
|
+
const mapKeys_1 = require("./util/mapKeys");
|
|
17
|
+
const authInfo_1 = require("./authInfo");
|
|
18
|
+
const messages_1 = require("./messages");
|
|
19
|
+
const sfdxError_1 = require("./sfdxError");
|
|
20
|
+
const sfdcUrl_1 = require("./util/sfdcUrl");
|
|
21
|
+
const myDomainResolver_1 = require("./status/myDomainResolver");
|
|
22
|
+
const scratchOrgErrorCodes_1 = require("./scratchOrgErrorCodes");
|
|
23
|
+
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
24
|
+
const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgInfoApi');
|
|
25
|
+
/**
|
|
26
|
+
* Returns the url to be used to authorize into the new scratch org
|
|
27
|
+
*
|
|
28
|
+
* @param scratchOrgInfoComplete The completed ScratchOrgInfo
|
|
29
|
+
* @param hubOrgLoginUrl the hun org login url
|
|
30
|
+
* @param signupTargetLoginUrlConfig the login url
|
|
31
|
+
* @returns {string}
|
|
32
|
+
*/
|
|
33
|
+
const getOrgInstanceAuthority = function (scratchOrgInfoComplete, hubOrgLoginUrl, signupTargetLoginUrlConfig) {
|
|
34
|
+
const createdOrgInstance = scratchOrgInfoComplete.SignupInstance;
|
|
35
|
+
if (createdOrgInstance === 'utf8') {
|
|
36
|
+
return hubOrgLoginUrl;
|
|
37
|
+
}
|
|
38
|
+
let altUrl;
|
|
39
|
+
// For non-Falcon (ie - instance names not ending in -s) sandboxes, use the instance URL
|
|
40
|
+
if (createdOrgInstance && !createdOrgInstance.toLowerCase().endsWith('s')) {
|
|
41
|
+
altUrl = `https://${createdOrgInstance}.salesforce.com`;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// For Falcon sandboxes, try the LoginURL instead; createdOrgInstance will not yield a valid URL
|
|
45
|
+
altUrl = scratchOrgInfoComplete.LoginUrl;
|
|
46
|
+
}
|
|
47
|
+
return signupTargetLoginUrlConfig !== null && signupTargetLoginUrlConfig !== void 0 ? signupTargetLoginUrlConfig : altUrl;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Returns OAuth2Options object
|
|
51
|
+
*
|
|
52
|
+
* @param hubOrg the environment hub org
|
|
53
|
+
* @param clientSecret The OAuth client secret. May be null for JWT OAuth flow.
|
|
54
|
+
* @param scratchOrgInfoComplete The completed ScratchOrgInfo which should contain an access token.
|
|
55
|
+
* @param retry auth retry attempts
|
|
56
|
+
* @param signupTargetLoginUrlConfig the login url
|
|
57
|
+
* @returns {OAuth2Options, number, number, number} options, retries, timeout, delay
|
|
58
|
+
*/
|
|
59
|
+
const buildOAuth2Options = async (options) => {
|
|
60
|
+
const logger = await logger_1.Logger.child('buildOAuth2Options');
|
|
61
|
+
const isJwtFlow = !!options.hubOrg.getConnection().getAuthInfoFields().privateKey;
|
|
62
|
+
const oauth2Options = {
|
|
63
|
+
loginUrl: getOrgInstanceAuthority(options.scratchOrgInfoComplete, options.hubOrg.getField(org_1.Org.Fields.LOGIN_URL), options.signupTargetLoginUrlConfig),
|
|
64
|
+
};
|
|
65
|
+
logger.debug(`isJwtFlow: ${isJwtFlow}`);
|
|
66
|
+
if (isJwtFlow && !process.env.SFDX_CLIENT_SECRET) {
|
|
67
|
+
oauth2Options.privateKeyFile = options.hubOrg.getConnection().getAuthInfoFields().privateKey;
|
|
68
|
+
const retries = (options === null || options === void 0 ? void 0 : options.retry) || kit_1.env.getNumber('SFDX_JWT_AUTH_RETRY_ATTEMPTS') || 0;
|
|
69
|
+
const timeoutInSeconds = kit_1.env.getNumber('SFDX_JWT_AUTH_RETRY_TIMEOUT') || 300;
|
|
70
|
+
const timeout = kit_1.Duration.seconds(timeoutInSeconds).milliseconds;
|
|
71
|
+
const delay = retries ? timeout / retries : 1000;
|
|
72
|
+
return {
|
|
73
|
+
options: oauth2Options,
|
|
74
|
+
retries,
|
|
75
|
+
timeout,
|
|
76
|
+
delay,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// Web Server OAuth "auth code exchange" flow
|
|
81
|
+
if (process.env.SFDX_CLIENT_SECRET) {
|
|
82
|
+
oauth2Options.clientSecret = process.env.SFDX_CLIENT_SECRET;
|
|
83
|
+
}
|
|
84
|
+
else if (options.clientSecret) {
|
|
85
|
+
oauth2Options.clientSecret = options.clientSecret;
|
|
86
|
+
}
|
|
87
|
+
oauth2Options.redirectUri = options.scratchOrgInfoComplete.ConnectedAppCallbackUrl;
|
|
88
|
+
oauth2Options.authCode = options.scratchOrgInfoComplete.AuthCode;
|
|
89
|
+
return {
|
|
90
|
+
options: oauth2Options,
|
|
91
|
+
retries: 0,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Returns OAuth2Options object
|
|
97
|
+
*
|
|
98
|
+
* @param hubOrg the environment hub org
|
|
99
|
+
* @param username The OAuth client secret. May be null for JWT OAuth flow.
|
|
100
|
+
* @param oauth2Options The completed ScratchOrgInfo which should contain an access token.
|
|
101
|
+
* @param retries auth retry attempts
|
|
102
|
+
* @param timeout the login url
|
|
103
|
+
* @param delay the login url
|
|
104
|
+
* @returns {OAuth2Options, number, number, number} options, retries, timeout, delay
|
|
105
|
+
*/
|
|
106
|
+
const getAuthInfo = async (options) => {
|
|
107
|
+
const logger = await logger_1.Logger.child('getAuthInfo');
|
|
108
|
+
const retryAuthorize = ts_retry_promise_1.retryDecorator(async (opts) => authInfo_1.AuthInfo.create(opts), {
|
|
109
|
+
timeout: options.timeout,
|
|
110
|
+
delay: options.delay,
|
|
111
|
+
retries: options.retries,
|
|
112
|
+
});
|
|
113
|
+
if (options.retries) {
|
|
114
|
+
try {
|
|
115
|
+
return await retryAuthorize({
|
|
116
|
+
username: options.username,
|
|
117
|
+
parentUsername: options.hubOrg.getUsername(),
|
|
118
|
+
oauth2Options: options.oauth2Options,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
const error = err;
|
|
123
|
+
logger.error(error);
|
|
124
|
+
throw error.lastError || error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return authInfo_1.AuthInfo.create({
|
|
129
|
+
username: options.username,
|
|
130
|
+
parentUsername: options.hubOrg.getUsername(),
|
|
131
|
+
oauth2Options: options.oauth2Options,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* after we successfully signup an org we need to trade the auth token for access and refresh token.
|
|
137
|
+
*
|
|
138
|
+
* @param scratchOrgInfoComplete - The completed ScratchOrgInfo which should contain an access token.
|
|
139
|
+
* @param hubOrg - the environment hub org
|
|
140
|
+
* @param clientSecret - The OAuth client secret. May be null for JWT OAuth flow.
|
|
141
|
+
* @param signupTargetLoginUrlConfig - Login url
|
|
142
|
+
* @param retry - auth retry attempts
|
|
143
|
+
* @returns {Promise<AuthInfo>}
|
|
144
|
+
*/
|
|
145
|
+
const authorizeScratchOrg = async (options) => {
|
|
146
|
+
var _a;
|
|
147
|
+
const { scratchOrgInfoComplete, hubOrg, clientSecret, signupTargetLoginUrlConfig, retry: maxRetries } = options;
|
|
148
|
+
const logger = await logger_1.Logger.child('authorizeScratchOrg');
|
|
149
|
+
logger.debug(`scratchOrgInfoComplete: ${JSON.stringify(scratchOrgInfoComplete, null, 4)}`);
|
|
150
|
+
// 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
|
|
151
|
+
if (!hubOrg.isDevHubOrg()) {
|
|
152
|
+
await hubOrg.determineIfDevHubOrg(true);
|
|
153
|
+
}
|
|
154
|
+
const oAuth2Options = await buildOAuth2Options({
|
|
155
|
+
hubOrg,
|
|
156
|
+
clientSecret,
|
|
157
|
+
scratchOrgInfoComplete,
|
|
158
|
+
retry: maxRetries,
|
|
159
|
+
signupTargetLoginUrlConfig,
|
|
160
|
+
});
|
|
161
|
+
const authInfo = await getAuthInfo({
|
|
162
|
+
hubOrg,
|
|
163
|
+
username: scratchOrgInfoComplete.SignupUsername,
|
|
164
|
+
oauth2Options: oAuth2Options.options,
|
|
165
|
+
retries: oAuth2Options.retries,
|
|
166
|
+
timeout: oAuth2Options.timeout,
|
|
167
|
+
delay: oAuth2Options.delay,
|
|
168
|
+
});
|
|
169
|
+
await authInfo.save({
|
|
170
|
+
devHubUsername: hubOrg.getUsername(),
|
|
171
|
+
created: new Date((_a = scratchOrgInfoComplete.CreatedDate) !== null && _a !== void 0 ? _a : new Date()).valueOf().toString(),
|
|
172
|
+
expirationDate: scratchOrgInfoComplete.ExpirationDate,
|
|
173
|
+
clientId: scratchOrgInfoComplete.ConnectedAppConsumerKey,
|
|
174
|
+
createdOrgInstance: scratchOrgInfoComplete.SignupInstance,
|
|
175
|
+
isDevHub: false,
|
|
176
|
+
snapshot: scratchOrgInfoComplete.Snapshot,
|
|
177
|
+
});
|
|
178
|
+
return authInfo;
|
|
179
|
+
};
|
|
180
|
+
exports.authorizeScratchOrg = authorizeScratchOrg;
|
|
181
|
+
const checkOrgDoesntExist = async (scratchOrgInfo) => {
|
|
182
|
+
const usernameKey = Object.keys(scratchOrgInfo).find((key) => key.toUpperCase() === 'USERNAME');
|
|
183
|
+
if (!usernameKey) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const username = ts_types_1.getString(scratchOrgInfo, usernameKey);
|
|
187
|
+
if (username && username.length > 0) {
|
|
188
|
+
try {
|
|
189
|
+
await authInfo_1.AuthInfo.create({ username: username.toLowerCase() });
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
const sfdxError = sfdxError_1.SfdxError.wrap(error);
|
|
193
|
+
// if an AuthInfo couldn't be created that means no AuthFile exists.
|
|
194
|
+
if (sfdxError.name === 'NamedOrgNotFound') {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
// Something unexpected
|
|
198
|
+
throw sfdxError;
|
|
199
|
+
}
|
|
200
|
+
// An org file already exists
|
|
201
|
+
throw sfdxError_1.SfdxError.create('@salesforce/core', 'scratchOrgErrorCodes', 'C-1007');
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* This extracts orgPrefs/settings from the user input and performs a basic scratchOrgInfo request.
|
|
206
|
+
*
|
|
207
|
+
* @param hubOrg - the environment hub org
|
|
208
|
+
* @param scratchOrgRequest - An object containing the fields of the ScratchOrgInfo
|
|
209
|
+
* @param settings - An object containing org settings
|
|
210
|
+
* @returns {Promise<RecordResult>}
|
|
211
|
+
*/
|
|
212
|
+
const requestScratchOrgCreation = async (hubOrg, scratchOrgRequest, settings) => {
|
|
213
|
+
// If these were present, they were already used to initialize the scratchOrgSettingsGenerator.
|
|
214
|
+
// They shouldn't be submitted as part of the scratchOrgInfo.
|
|
215
|
+
delete scratchOrgRequest.settings;
|
|
216
|
+
delete scratchOrgRequest.objectSettings;
|
|
217
|
+
// We do not allow you to specify the old and the new way of doing post create settings
|
|
218
|
+
if (scratchOrgRequest.orgPreferences && settings.hasSettings()) {
|
|
219
|
+
// This is not allowed
|
|
220
|
+
throw new sfdxError_1.SfdxError('signupDuplicateSettingsSpecified');
|
|
221
|
+
}
|
|
222
|
+
// deprecated old style orgPreferences
|
|
223
|
+
if (scratchOrgRequest.orgPreferences) {
|
|
224
|
+
throw new sfdxError_1.SfdxError(messages.getMessage('deprecatedPrefFormat'));
|
|
225
|
+
}
|
|
226
|
+
const scratchOrgInfo = mapKeys_1.default(scratchOrgRequest, kit_1.upperFirst, true);
|
|
227
|
+
await checkOrgDoesntExist(scratchOrgInfo); // throw if it does exists.
|
|
228
|
+
try {
|
|
229
|
+
return await hubOrg.getConnection().sobject('ScratchOrgInfo').create(scratchOrgInfo);
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
// this is a jsforce error which contains the property "fields" which regular error don't
|
|
233
|
+
const jsForceError = error;
|
|
234
|
+
if (jsForceError.errorCode === 'REQUIRED_FIELD_MISSING') {
|
|
235
|
+
throw new sfdxError_1.SfdxError(messages.getMessage('signupFieldsMissing', [jsForceError.fields.toString()]));
|
|
236
|
+
}
|
|
237
|
+
throw sfdxError_1.SfdxError.wrap(jsForceError);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
exports.requestScratchOrgCreation = requestScratchOrgCreation;
|
|
241
|
+
/**
|
|
242
|
+
* This retrieves the ScratchOrgInfo, polling until the status is Active or Error
|
|
243
|
+
*
|
|
244
|
+
* @param hubOrg
|
|
245
|
+
* @param scratchOrgInfoId - the id of the scratchOrgInfo that we are retrieving
|
|
246
|
+
* @param timeout - A Duration object
|
|
247
|
+
* @returns {Promise<ScratchOrgInfo>}
|
|
248
|
+
*/
|
|
249
|
+
const pollForScratchOrgInfo = async (hubOrg, scratchOrgInfoId,
|
|
250
|
+
// org:create specifies a default timeout of 6. This longer default is for other consumers
|
|
251
|
+
timeout = kit_1.Duration.minutes(15)) => {
|
|
252
|
+
const logger = await logger_1.Logger.child('scratchOrgInfoApi-pollForScratchOrgInfo');
|
|
253
|
+
logger.debug(`PollingTimeout in minutes: ${timeout.minutes}`);
|
|
254
|
+
const response = await ts_retry_promise_1.retry(async () => {
|
|
255
|
+
const resultInProgress = await hubOrg
|
|
256
|
+
.getConnection()
|
|
257
|
+
.sobject('ScratchOrgInfo')
|
|
258
|
+
.retrieve(scratchOrgInfoId);
|
|
259
|
+
logger.debug(`polling client result: ${JSON.stringify(resultInProgress, null, 4)}`);
|
|
260
|
+
// Once it's "done" we can return it
|
|
261
|
+
if (resultInProgress.Status === 'Active' || resultInProgress.Status === 'Error') {
|
|
262
|
+
return resultInProgress;
|
|
263
|
+
}
|
|
264
|
+
// all other statuses, OR lack of status (e.g. network errors) will cause a retry
|
|
265
|
+
throw new sfdxError_1.SfdxError(`Scratch org status is ${resultInProgress.Status}`);
|
|
266
|
+
}, {
|
|
267
|
+
retries: 'INFINITELY',
|
|
268
|
+
timeout: timeout.milliseconds,
|
|
269
|
+
delay: kit_1.Duration.seconds(2).milliseconds,
|
|
270
|
+
backoff: 'LINEAR',
|
|
271
|
+
maxBackOff: kit_1.Duration.seconds(30).milliseconds,
|
|
272
|
+
}).catch(() => {
|
|
273
|
+
throw new sfdxError_1.SfdxError(`The scratch org did not complete within ${timeout.minutes} minutes`, 'orgCreationTimeout', [
|
|
274
|
+
'Try your force:org:create command again with a longer --wait value',
|
|
275
|
+
]);
|
|
276
|
+
});
|
|
277
|
+
return scratchOrgErrorCodes_1.checkScratchOrgInfoForErrors(response, hubOrg.getUsername(), logger);
|
|
278
|
+
};
|
|
279
|
+
exports.pollForScratchOrgInfo = pollForScratchOrgInfo;
|
|
280
|
+
/**
|
|
281
|
+
* This authenticates into the newly created org and sets org preferences
|
|
282
|
+
*
|
|
283
|
+
* @param scratchOrgAuthInfo - an object containing the AuthInfo of the ScratchOrg
|
|
284
|
+
* @param apiVersion - the target api version
|
|
285
|
+
* @param orgSettings - The ScratchOrg settings
|
|
286
|
+
* @param scratchOrg - The scratchOrg Org info
|
|
287
|
+
* @returns {Promise<Optional<AuthInfo>>}
|
|
288
|
+
*/
|
|
289
|
+
const deploySettingsAndResolveUrl = async (scratchOrgAuthInfo, apiVersion, orgSettings, scratchOrg) => {
|
|
290
|
+
const logger = await logger_1.Logger.child('scratchOrgInfoApi-deploySettingsAndResolveUrl');
|
|
291
|
+
if (orgSettings.hasSettings()) {
|
|
292
|
+
// deploy the settings to the newly created scratch org
|
|
293
|
+
logger.debug(`deploying scratch org settings with apiVersion ${apiVersion}`);
|
|
294
|
+
try {
|
|
295
|
+
await orgSettings.createDeploy();
|
|
296
|
+
await orgSettings.deploySettingsViaFolder(scratchOrg, apiVersion);
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
throw sfdxError_1.SfdxError.wrap(error);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const { instanceUrl } = scratchOrgAuthInfo.getFields();
|
|
303
|
+
if (instanceUrl) {
|
|
304
|
+
logger.debug(`processScratchOrgInfoResult - resultData.instanceUrl: ${instanceUrl}`);
|
|
305
|
+
const options = {
|
|
306
|
+
timeout: kit_1.Duration.minutes(3),
|
|
307
|
+
frequency: kit_1.Duration.seconds(10),
|
|
308
|
+
url: new sfdcUrl_1.SfdcUrl(instanceUrl),
|
|
309
|
+
};
|
|
310
|
+
try {
|
|
311
|
+
const resolver = await myDomainResolver_1.MyDomainResolver.create(options);
|
|
312
|
+
await resolver.resolve();
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
const sfdxError = sfdxError_1.SfdxError.wrap(error);
|
|
316
|
+
logger.debug('processScratchOrgInfoResult - err: %s', error);
|
|
317
|
+
if (sfdxError.name === 'MyDomainResolverTimeoutError') {
|
|
318
|
+
sfdxError.setData({
|
|
319
|
+
orgId: scratchOrgAuthInfo.getFields().orgId,
|
|
320
|
+
username: scratchOrgAuthInfo.getFields().username,
|
|
321
|
+
instanceUrl,
|
|
322
|
+
});
|
|
323
|
+
logger.debug('processScratchOrgInfoResult - err data: %s', sfdxError.data);
|
|
324
|
+
}
|
|
325
|
+
throw sfdxError;
|
|
326
|
+
}
|
|
327
|
+
return scratchOrgAuthInfo;
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
exports.deploySettingsAndResolveUrl = deploySettingsAndResolveUrl;
|
|
331
|
+
//# sourceMappingURL=scratchOrgInfoApi.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Org } from './org';
|
|
2
|
+
import { SfdxProjectJson } from './sfdxProject';
|
|
3
|
+
import { ScratchOrgInfo } from './scratchOrgInfoApi';
|
|
4
|
+
declare type PartialScratchOrgInfo = Pick<ScratchOrgInfo, 'ConnectedAppConsumerKey' | 'AuthCode' | 'Snapshot' | 'Status' | 'LoginUrl' | 'SignupEmail' | 'SignupUsername' | 'SignupInstance' | 'Username'>;
|
|
5
|
+
export interface ScratchOrgInfoPayload extends PartialScratchOrgInfo {
|
|
6
|
+
orgName: string;
|
|
7
|
+
package2AncestorIds: string;
|
|
8
|
+
features: string | string[];
|
|
9
|
+
connectedAppConsumerKey: string;
|
|
10
|
+
namespace: string;
|
|
11
|
+
connectedAppCallbackUrl: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generates the package2AncestorIds scratch org property
|
|
15
|
+
*
|
|
16
|
+
* @param scratchOrgInfo - the scratchOrgInfo passed in by the user
|
|
17
|
+
* @param projectJson - sfdxProjectJson
|
|
18
|
+
* @param hubOrg - the hub org, in case we need to do queries
|
|
19
|
+
*/
|
|
20
|
+
export declare const getAncestorIds: (scratchOrgInfo: ScratchOrgInfoPayload, projectJson: SfdxProjectJson, hubOrg: Org) => Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Takes in a scratchOrgInfo and fills in the missing fields
|
|
23
|
+
*
|
|
24
|
+
* @param hubOrg the environment hub org
|
|
25
|
+
* @param scratchOrgInfoPayload - the scratchOrgInfo passed in by the user
|
|
26
|
+
* @param nonamespace create the scratch org with no namespace
|
|
27
|
+
* @param ignoreAncestorIds true if the sfdx-project.json ancestorId keys should be ignored
|
|
28
|
+
*/
|
|
29
|
+
export declare const generateScratchOrgInfo: ({ hubOrg, scratchOrgInfoPayload, nonamespace, ignoreAncestorIds, }: {
|
|
30
|
+
hubOrg: Org;
|
|
31
|
+
scratchOrgInfoPayload: ScratchOrgInfoPayload;
|
|
32
|
+
nonamespace?: boolean | undefined;
|
|
33
|
+
ignoreAncestorIds?: boolean | undefined;
|
|
34
|
+
}) => Promise<ScratchOrgInfoPayload>;
|
|
35
|
+
/**
|
|
36
|
+
* Returns a valid signup json
|
|
37
|
+
*
|
|
38
|
+
* @param definitionjson org definition in JSON format
|
|
39
|
+
* @param definitionfile path to an org definition file
|
|
40
|
+
* @param connectedAppConsumerKey The connected app consumer key. May be null for JWT OAuth flow.
|
|
41
|
+
* @param durationdays duration of the scratch org (in days) (default:1, min:1, max:30)
|
|
42
|
+
* @param nonamespace create the scratch org with no namespace
|
|
43
|
+
* @param noancestors do not include second-generation package ancestors in the scratch org
|
|
44
|
+
* @param orgConfig overrides definitionjson
|
|
45
|
+
* @returns scratchOrgInfoPayload: ScratchOrgInfoPayload;
|
|
46
|
+
ignoreAncestorIds: boolean;
|
|
47
|
+
warnings: string[];
|
|
48
|
+
*/
|
|
49
|
+
export declare const getScratchOrgInfoPayload: (options: {
|
|
50
|
+
definitionjson?: string;
|
|
51
|
+
definitionfile?: string;
|
|
52
|
+
connectedAppConsumerKey?: string;
|
|
53
|
+
durationDays: number;
|
|
54
|
+
nonamespace?: boolean;
|
|
55
|
+
noancestors?: boolean;
|
|
56
|
+
orgConfig?: Record<string, unknown>;
|
|
57
|
+
}) => Promise<{
|
|
58
|
+
scratchOrgInfoPayload: ScratchOrgInfoPayload;
|
|
59
|
+
ignoreAncestorIds: boolean;
|
|
60
|
+
warnings: string[];
|
|
61
|
+
}>;
|
|
62
|
+
export {};
|