@salesforce/core 2.33.0 → 2.34.3
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/connection.d.ts +5 -0
- package/lib/connection.js +15 -0
- package/lib/exported.d.ts +3 -1
- package/lib/exported.js +3 -1
- package/lib/org.d.ts +10 -0
- package/lib/org.js +12 -6
- 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/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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [2.34.3](https://github.com/forcedotcom/sfdx-core/compare/v2.34.2...v2.34.3) (2022-01-25)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- refresh auth on a connection, too ([ff32a70](https://github.com/forcedotcom/sfdx-core/commit/ff32a705d87d6e410d06597eefa407b54eeb215d))
|
|
10
|
+
|
|
11
|
+
### [2.34.2](https://github.com/forcedotcom/sfdx-core/compare/v2.33.2...v2.34.2) (2022-01-25)
|
|
12
|
+
|
|
13
|
+
### [2.33.2](https://github.com/forcedotcom/sfdx-core/compare/v2.33.1...v2.33.2) (2022-01-25)
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
- cant use require on json as module use readFileSync instead ([3085029](https://github.com/forcedotcom/sfdx-core/commit/3085029e70d7f88e2535bf0b80240855f13abf37))
|
|
18
|
+
- correct import declaration ([4c69d2d](https://github.com/forcedotcom/sfdx-core/commit/4c69d2dc3370c5f920becfe260ccb178279e4d92))
|
|
19
|
+
- exit deploy loop with error on status SucceededPartial ([492e891](https://github.com/forcedotcom/sfdx-core/commit/492e89184e4c865cc7fcf7df41b9c6af6a6f2237))
|
|
20
|
+
- remove unwanted dep ([12ccc3a](https://github.com/forcedotcom/sfdx-core/commit/12ccc3adc0efbe687059187ab4d849b1741c823d))
|
|
21
|
+
- save auth info ([226bbd2](https://github.com/forcedotcom/sfdx-core/commit/226bbd2dc09a7a8df5887c0ae7548c83ae19b748))
|
|
22
|
+
- use correct dir structure ([e947fec](https://github.com/forcedotcom/sfdx-core/commit/e947fecf33a1c19ff80b33f7515e39d4e524f77f))
|
|
23
|
+
|
|
24
|
+
### [2.33.1](https://github.com/forcedotcom/sfdx-core/compare/v2.33.0...v2.33.1) (2021-12-15)
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
- faye doesn't use custom stuff passed it ([b1cefc7](https://github.com/forcedotcom/sfdx-core/commit/b1cefc76afde7f0dd56ed72b5539a47c118eef63))
|
|
29
|
+
|
|
5
30
|
## [2.33.0](https://github.com/forcedotcom/sfdx-core/compare/v2.32.0...v2.33.0) (2021-12-14)
|
|
6
31
|
|
|
7
32
|
### Features
|
package/LICENSE.txt
CHANGED
package/lib/connection.d.ts
CHANGED
|
@@ -173,6 +173,11 @@ export declare class Connection extends JSForceConnection {
|
|
|
173
173
|
* @param options The query options.
|
|
174
174
|
*/
|
|
175
175
|
singleRecordQuery<T>(soql: string, options?: SingleRecordQueryOptions): Promise<T>;
|
|
176
|
+
/**
|
|
177
|
+
* Executes a get request on the baseUrl to force an auth refresh
|
|
178
|
+
* Useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes
|
|
179
|
+
*/
|
|
180
|
+
refreshAuth(): Promise<void>;
|
|
176
181
|
private loadInstanceApiVersion;
|
|
177
182
|
}
|
|
178
183
|
export declare const SingleRecordQueryErrors: {
|
package/lib/connection.js
CHANGED
|
@@ -127,6 +127,8 @@ class Connection extends jsforce_1.Connection {
|
|
|
127
127
|
delete options.rest;
|
|
128
128
|
if (rest) {
|
|
129
129
|
this.logger.debug('deploy with REST');
|
|
130
|
+
// do a quick auth refresh because the raw transport used doesn't handle expired AccessTokens
|
|
131
|
+
await this.refreshAuth();
|
|
130
132
|
const headers = {
|
|
131
133
|
Authorization: this && `OAuth ${this.accessToken}`,
|
|
132
134
|
clientId: this.oauth2 && this.oauth2.clientId,
|
|
@@ -182,6 +184,7 @@ class Connection extends jsforce_1.Connection {
|
|
|
182
184
|
* @param request HTTP request object or URL to GET request.
|
|
183
185
|
*/
|
|
184
186
|
async requestRaw(request) {
|
|
187
|
+
await this.refreshAuth();
|
|
185
188
|
const headers = this.accessToken ? { Authorization: `Bearer ${this.accessToken}` } : {};
|
|
186
189
|
kit_1.merge(headers, exports.SFDX_HTTP_HEADERS, request.headers);
|
|
187
190
|
return this._transport.httpRequest({
|
|
@@ -389,6 +392,18 @@ class Connection extends jsforce_1.Connection {
|
|
|
389
392
|
}
|
|
390
393
|
return result.records[0];
|
|
391
394
|
}
|
|
395
|
+
/**
|
|
396
|
+
* Executes a get request on the baseUrl to force an auth refresh
|
|
397
|
+
* Useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes
|
|
398
|
+
*/
|
|
399
|
+
async refreshAuth() {
|
|
400
|
+
this.logger.debug('Refreshing auth for org.');
|
|
401
|
+
const requestInfo = {
|
|
402
|
+
url: this.baseUrl(),
|
|
403
|
+
method: 'GET',
|
|
404
|
+
};
|
|
405
|
+
await this.request(requestInfo);
|
|
406
|
+
}
|
|
392
407
|
async loadInstanceApiVersion() {
|
|
393
408
|
const authFileFields = this.options.authInfo.getFields();
|
|
394
409
|
const lastCheckedDateString = authFileFields.instanceApiVersionLastRetrieved;
|
package/lib/exported.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export { SfdcUrl } from './util/sfdcUrl';
|
|
|
18
18
|
export { getJwtAudienceUrl } from './util/getJwtAudienceUrl';
|
|
19
19
|
export { Fields, FieldValue, LoggerLevel, LoggerLevelValue, LogLine, LoggerOptions, LoggerStream, Logger, } from './logger';
|
|
20
20
|
export { Messages } from './messages';
|
|
21
|
-
export { Org, SandboxProcessObject, StatusEvent, SandboxEvents, SandboxUserAuthResponse, SandboxUserAuthRequest, SandboxRequest, OrgTypes, ResultEvent, } from './org';
|
|
21
|
+
export { Org, SandboxProcessObject, StatusEvent, SandboxEvents, SandboxUserAuthResponse, SandboxUserAuthRequest, SandboxRequest, OrgTypes, ResultEvent, ScratchOrgRequest, } from './org';
|
|
22
22
|
export { PackageDir, NamedPackageDir, PackageDirDependency, SfdxProject, SfdxProjectJson } from './sfdxProject';
|
|
23
23
|
export { SchemaPrinter } from './schema/printer';
|
|
24
24
|
export { SchemaValidator } from './schema/validator';
|
|
@@ -29,5 +29,7 @@ export { CometClient, CometSubscription, StreamingClient } from './status/stream
|
|
|
29
29
|
export { MyDomainResolver } from './status/myDomainResolver';
|
|
30
30
|
export { DefaultUserFields, REQUIRED_FIELDS, User, UserFields } from './user';
|
|
31
31
|
export { PermissionSetAssignment, PermissionSetAssignmentFields } from './permissionSetAssignment';
|
|
32
|
+
export { ScratchOrgCreateOptions, ScratchOrgCreateResult, scratchOrgCreate } from './scratchOrgCreate';
|
|
33
|
+
export { ScratchOrgInfo } from './scratchOrgInfoApi';
|
|
32
34
|
export * from './util/fs';
|
|
33
35
|
export * from './util/sfdc';
|
package/lib/exported.js
CHANGED
|
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxErrorConfig = exports.SfdxError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.OrgTypes = exports.SandboxEvents = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.OAuth2WithVerifier = exports.AuthInfo = exports.ConfigAggregator = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.BaseConfigStore = exports.ConfigGroup = exports.ConfigFile = exports.AuthInfoConfig = exports.AliasGroup = exports.Aliases = void 0;
|
|
19
|
+
exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxErrorConfig = exports.SfdxError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.OrgTypes = exports.SandboxEvents = exports.Org = exports.Messages = exports.Logger = exports.LoggerLevel = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.WebOAuthServer = exports.Lifecycle = exports.Global = exports.Mode = exports.SFDX_HTTP_HEADERS = exports.Connection = exports.AuthRemover = exports.OAuth2WithVerifier = exports.AuthInfo = exports.ConfigAggregator = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.BaseConfigStore = exports.ConfigGroup = exports.ConfigFile = exports.AuthInfoConfig = exports.AliasGroup = exports.Aliases = void 0;
|
|
20
20
|
const messages_1 = require("./messages");
|
|
21
21
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
22
22
|
var aliases_1 = require("./config/aliases");
|
|
@@ -89,6 +89,8 @@ Object.defineProperty(exports, "REQUIRED_FIELDS", { enumerable: true, get: funct
|
|
|
89
89
|
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return user_1.User; } });
|
|
90
90
|
var permissionSetAssignment_1 = require("./permissionSetAssignment");
|
|
91
91
|
Object.defineProperty(exports, "PermissionSetAssignment", { enumerable: true, get: function () { return permissionSetAssignment_1.PermissionSetAssignment; } });
|
|
92
|
+
var scratchOrgCreate_1 = require("./scratchOrgCreate");
|
|
93
|
+
Object.defineProperty(exports, "scratchOrgCreate", { enumerable: true, get: function () { return scratchOrgCreate_1.scratchOrgCreate; } });
|
|
92
94
|
// Utility sub-modules
|
|
93
95
|
__exportStar(require("./util/fs"), exports);
|
|
94
96
|
__exportStar(require("./util/sfdc"), exports);
|
package/lib/org.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AsyncCreatable, Duration } from '@salesforce/kit';
|
|
2
2
|
import { AnyJson, JsonMap, Optional } from '@salesforce/ts-types';
|
|
3
|
+
import { ScratchOrgCreateOptions, ScratchOrgCreateResult } from './scratchOrgCreate';
|
|
3
4
|
import { AuthFields, AuthInfo } from './authInfo';
|
|
4
5
|
import { ConfigAggregator } from './config/configAggregator';
|
|
5
6
|
import { OrgUsersConfig } from './config/orgUsersConfig';
|
|
@@ -56,6 +57,7 @@ export declare type SandboxRequest = {
|
|
|
56
57
|
SourceId?: string;
|
|
57
58
|
Description?: string;
|
|
58
59
|
};
|
|
60
|
+
export declare type ScratchOrgRequest = Pick<ScratchOrgCreateOptions, 'connectedAppConsumerKey' | 'durationDays' | 'nonamespace' | 'noancestors' | 'wait' | 'retry' | 'apiversion' | 'definitionjson' | 'definitionfile' | 'orgConfig' | 'clientSecret'>;
|
|
59
61
|
/**
|
|
60
62
|
* Provides a way to manage a locally authenticated Org.
|
|
61
63
|
*
|
|
@@ -103,6 +105,14 @@ export declare class Org extends AsyncCreatable<Org.Options> {
|
|
|
103
105
|
wait?: Duration;
|
|
104
106
|
interval?: Duration;
|
|
105
107
|
}): Promise<SandboxProcessObject>;
|
|
108
|
+
/**
|
|
109
|
+
* Creates a scratchOrg
|
|
110
|
+
* 'this' needs to be a valid dev-hub
|
|
111
|
+
*
|
|
112
|
+
* @param {options} ScratchOrgCreateOptions
|
|
113
|
+
* @returns {ScratchOrgCreateResult}
|
|
114
|
+
*/
|
|
115
|
+
scratchOrgCreate(options: ScratchOrgRequest): Promise<ScratchOrgCreateResult>;
|
|
106
116
|
/**
|
|
107
117
|
* Clean all data files in the org's data path. Usually <workspace>/.sfdx/orgs/<username>.
|
|
108
118
|
*
|
package/lib/org.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.Org = exports.SandboxEvents = exports.OrgTypes = void 0;
|
|
|
10
10
|
const path_1 = require("path");
|
|
11
11
|
const kit_1 = require("@salesforce/kit");
|
|
12
12
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
13
|
+
const scratchOrgCreate_1 = require("./scratchOrgCreate");
|
|
13
14
|
const authInfo_1 = require("./authInfo");
|
|
14
15
|
const aliases_1 = require("./config/aliases");
|
|
15
16
|
const authInfoConfig_1 = require("./config/authInfoConfig");
|
|
@@ -99,6 +100,16 @@ class Org extends kit_1.AsyncCreatable {
|
|
|
99
100
|
pollInterval,
|
|
100
101
|
});
|
|
101
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates a scratchOrg
|
|
105
|
+
* 'this' needs to be a valid dev-hub
|
|
106
|
+
*
|
|
107
|
+
* @param {options} ScratchOrgCreateOptions
|
|
108
|
+
* @returns {ScratchOrgCreateResult}
|
|
109
|
+
*/
|
|
110
|
+
async scratchOrgCreate(options) {
|
|
111
|
+
return scratchOrgCreate_1.scratchOrgCreate({ ...options, hubOrg: this });
|
|
112
|
+
}
|
|
102
113
|
/**
|
|
103
114
|
* Clean all data files in the org's data path. Usually <workspace>/.sfdx/orgs/<username>.
|
|
104
115
|
*
|
|
@@ -295,13 +306,8 @@ class Org extends kit_1.AsyncCreatable {
|
|
|
295
306
|
* Refreshes the auth for this org's instance by calling HTTP GET on the baseUrl of the connection object.
|
|
296
307
|
*/
|
|
297
308
|
async refreshAuth() {
|
|
298
|
-
this.logger.debug('Refreshing auth for org.');
|
|
299
|
-
const requestInfo = {
|
|
300
|
-
url: this.getConnection().baseUrl(),
|
|
301
|
-
method: 'GET',
|
|
302
|
-
};
|
|
303
309
|
const conn = this.getConnection();
|
|
304
|
-
await conn.
|
|
310
|
+
await conn.refreshAuth();
|
|
305
311
|
}
|
|
306
312
|
/**
|
|
307
313
|
* Reads and returns the content of all user auth files for this org as an array.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Duration } from '@salesforce/kit';
|
|
2
|
+
import { Org } from './org';
|
|
3
|
+
import { AuthInfo, AuthFields } from './authInfo';
|
|
4
|
+
import { ScratchOrgInfo } from './scratchOrgInfoApi';
|
|
5
|
+
export declare const DEFAULT_STREAM_TIMEOUT_MINUTES = 6;
|
|
6
|
+
export interface ScratchOrgCreateResult {
|
|
7
|
+
username?: string;
|
|
8
|
+
scratchOrgInfo?: ScratchOrgInfo;
|
|
9
|
+
authInfo?: AuthInfo;
|
|
10
|
+
authFields?: AuthFields;
|
|
11
|
+
warnings: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* interface ScratchOrgCreateOptions
|
|
15
|
+
*
|
|
16
|
+
* @param hubOrg the environment hub org
|
|
17
|
+
* @param connectedAppConsumerKey The connected app consumer key.
|
|
18
|
+
* @param durationDays duration of the scratch org (in days) (default:1, min:1, max:30)
|
|
19
|
+
* @param nonamespace create the scratch org with no namespace
|
|
20
|
+
* @param noancestors do not include second-generation package ancestors in the scratch org
|
|
21
|
+
* @param wait the streaming client socket timeout (in minutes) must be an instance of the Duration utility class (default:6, min:2)
|
|
22
|
+
* @param retry number of scratch org auth retries after scratch org is successfully signed up (default:0, min:0, max:10)
|
|
23
|
+
* @param apiversion target server instance API version
|
|
24
|
+
* @param definitionjson org definition in JSON format
|
|
25
|
+
* @param definitionfile path to an org definition file
|
|
26
|
+
* @param orgConfig overrides definitionjson
|
|
27
|
+
* @param clientSecret OAuth client secret of personal connected app
|
|
28
|
+
*/
|
|
29
|
+
export interface ScratchOrgCreateOptions {
|
|
30
|
+
hubOrg: Org;
|
|
31
|
+
connectedAppConsumerKey?: string;
|
|
32
|
+
durationDays?: number;
|
|
33
|
+
nonamespace?: boolean;
|
|
34
|
+
noancestors?: boolean;
|
|
35
|
+
wait?: Duration;
|
|
36
|
+
retry?: number;
|
|
37
|
+
apiversion?: string;
|
|
38
|
+
definitionjson?: string;
|
|
39
|
+
definitionfile?: string;
|
|
40
|
+
orgConfig?: Record<string, unknown>;
|
|
41
|
+
clientSecret?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare const scratchOrgCreate: (options: ScratchOrgCreateOptions) => Promise<ScratchOrgCreateResult>;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020, 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.scratchOrgCreate = exports.DEFAULT_STREAM_TIMEOUT_MINUTES = void 0;
|
|
10
|
+
// third
|
|
11
|
+
const kit_1 = require("@salesforce/kit");
|
|
12
|
+
const ts_types_1 = require("@salesforce/ts-types");
|
|
13
|
+
// Local
|
|
14
|
+
const org_1 = require("./org");
|
|
15
|
+
const logger_1 = require("./logger");
|
|
16
|
+
const messages_1 = require("./messages");
|
|
17
|
+
const sfdxError_1 = require("./sfdxError");
|
|
18
|
+
const connection_1 = require("./connection");
|
|
19
|
+
const sfdxProject_1 = require("./sfdxProject");
|
|
20
|
+
const configAggregator_1 = require("./config/configAggregator");
|
|
21
|
+
const scratchOrgInfoApi_1 = require("./scratchOrgInfoApi");
|
|
22
|
+
const scratchOrgSettingsGenerator_1 = require("./scratchOrgSettingsGenerator");
|
|
23
|
+
const scratchOrgInfoGenerator_1 = require("./scratchOrgInfoGenerator");
|
|
24
|
+
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
25
|
+
const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgCreate');
|
|
26
|
+
exports.DEFAULT_STREAM_TIMEOUT_MINUTES = 6;
|
|
27
|
+
const validateDuration = (durationDays) => {
|
|
28
|
+
const min = 1;
|
|
29
|
+
const max = 30;
|
|
30
|
+
if (Number.isInteger(durationDays)) {
|
|
31
|
+
if (durationDays < min) {
|
|
32
|
+
throw new sfdxError_1.SfdxError(`Expected 'durationDays' greater than or equal to ${min} but received ${durationDays}`, 'BoundsError');
|
|
33
|
+
}
|
|
34
|
+
if (durationDays > max) {
|
|
35
|
+
throw new sfdxError_1.SfdxError(`Expected 'durationDays' less than or equal to ${max} but received ${durationDays}`, 'BoundsError');
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
throw new sfdxError_1.SfdxError("Expected 'durationDays' to be an integer number", 'TypeError');
|
|
40
|
+
};
|
|
41
|
+
const validateRetry = (retry) => {
|
|
42
|
+
if (Number.isInteger(retry)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
throw new sfdxError_1.SfdxError("Expected 'retry' to be an integer number", 'TypeError');
|
|
46
|
+
};
|
|
47
|
+
const validateWait = (wait) => {
|
|
48
|
+
const min = 2;
|
|
49
|
+
if (wait.minutes < min) {
|
|
50
|
+
throw new sfdxError_1.SfdxError(`Expected 'wait' greater than or equal to ${min} but received ${wait}`, 'BoundsError');
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const scratchOrgCreate = async (options) => {
|
|
54
|
+
var _a;
|
|
55
|
+
const logger = await logger_1.Logger.child('scratchOrgCreate');
|
|
56
|
+
logger.debug('scratchOrgCreate');
|
|
57
|
+
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, } = options;
|
|
58
|
+
validateDuration(durationDays);
|
|
59
|
+
validateRetry(retry);
|
|
60
|
+
validateWait(wait);
|
|
61
|
+
const { scratchOrgInfoPayload, ignoreAncestorIds, warnings } = await scratchOrgInfoGenerator_1.getScratchOrgInfoPayload({
|
|
62
|
+
definitionjson,
|
|
63
|
+
definitionfile,
|
|
64
|
+
connectedAppConsumerKey,
|
|
65
|
+
durationDays,
|
|
66
|
+
nonamespace,
|
|
67
|
+
noancestors,
|
|
68
|
+
orgConfig,
|
|
69
|
+
});
|
|
70
|
+
const scratchOrgInfo = await scratchOrgInfoGenerator_1.generateScratchOrgInfo({
|
|
71
|
+
hubOrg,
|
|
72
|
+
scratchOrgInfoPayload,
|
|
73
|
+
nonamespace,
|
|
74
|
+
ignoreAncestorIds,
|
|
75
|
+
});
|
|
76
|
+
// gets the scratch org settings (will use in both signup paths AND to deploy the settings)
|
|
77
|
+
const settingsGenerator = new scratchOrgSettingsGenerator_1.default();
|
|
78
|
+
await settingsGenerator.extract(scratchOrgInfo);
|
|
79
|
+
logger.debug(`the scratch org def file has settings: ${settingsGenerator.hasSettings()}`);
|
|
80
|
+
// creates the scratch org info in the devhub
|
|
81
|
+
const scratchOrgInfoRequestResult = await scratchOrgInfoApi_1.requestScratchOrgCreation(hubOrg, scratchOrgInfo, settingsGenerator);
|
|
82
|
+
const scratchOrgInfoId = ts_types_1.ensureString(ts_types_1.getString(scratchOrgInfoRequestResult, 'id'));
|
|
83
|
+
logger.debug(`scratch org has recordId ${scratchOrgInfoId}`);
|
|
84
|
+
const scratchOrgInfoResult = await scratchOrgInfoApi_1.pollForScratchOrgInfo(hubOrg, scratchOrgInfoId, wait);
|
|
85
|
+
const signupTargetLoginUrlConfig = await getSignupTargetLoginUrl();
|
|
86
|
+
const scratchOrgAuthInfo = await scratchOrgInfoApi_1.authorizeScratchOrg({
|
|
87
|
+
scratchOrgInfoComplete: scratchOrgInfoResult,
|
|
88
|
+
hubOrg,
|
|
89
|
+
clientSecret,
|
|
90
|
+
signupTargetLoginUrlConfig,
|
|
91
|
+
retry: retry || 0,
|
|
92
|
+
});
|
|
93
|
+
// we'll need this scratch org connection later;
|
|
94
|
+
const connection = await connection_1.Connection.create({ authInfo: scratchOrgAuthInfo });
|
|
95
|
+
const scratchOrg = await org_1.Org.create({ connection }); // scartchOrg should come from command
|
|
96
|
+
const username = scratchOrg.getUsername();
|
|
97
|
+
logger.debug(`scratch org username ${username}`);
|
|
98
|
+
const configAggregator = new configAggregator_1.ConfigAggregator();
|
|
99
|
+
const authInfo = await scratchOrgInfoApi_1.deploySettingsAndResolveUrl(scratchOrgAuthInfo, (_a = apiversion !== null && apiversion !== void 0 ? apiversion : configAggregator.getPropertyValue('apiVersion')) !== null && _a !== void 0 ? _a : (await scratchOrg.retrieveMaxApiVersion()), settingsGenerator, scratchOrg);
|
|
100
|
+
logger.trace('Settings deployed to org');
|
|
101
|
+
/** updating the revision num to zero during org:creation if source members are created during org:create.This only happens for some specific scratch org definition file.*/
|
|
102
|
+
await updateRevisionCounterToZero(scratchOrg);
|
|
103
|
+
return {
|
|
104
|
+
username,
|
|
105
|
+
scratchOrgInfo: scratchOrgInfoResult,
|
|
106
|
+
authInfo,
|
|
107
|
+
authFields: authInfo === null || authInfo === void 0 ? void 0 : authInfo.getFields(),
|
|
108
|
+
warnings,
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
exports.scratchOrgCreate = scratchOrgCreate;
|
|
112
|
+
const getSignupTargetLoginUrl = async () => {
|
|
113
|
+
try {
|
|
114
|
+
const project = await sfdxProject_1.SfdxProject.resolve();
|
|
115
|
+
const projectJson = await project.resolveProjectConfig();
|
|
116
|
+
return projectJson.signupTargetLoginUrl;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// a project isn't required for org:create
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const updateRevisionCounterToZero = async (scratchOrg) => {
|
|
123
|
+
const conn = scratchOrg.getConnection();
|
|
124
|
+
const queryResult = await conn.tooling.sobject('SourceMember').find({ RevisionCounter: { $gt: 0 } }, ['Id']);
|
|
125
|
+
try {
|
|
126
|
+
await conn.tooling
|
|
127
|
+
.sobject('SourceMember')
|
|
128
|
+
.update(queryResult.map((record) => ({ Id: record.Id, RevisionCounter: 0 })));
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
const message = messages.getMessage('SourceStatusResetFailure', [scratchOrg.getOrgId(), scratchOrg.getUsername()]);
|
|
132
|
+
throw new sfdxError_1.SfdxError(message, 'SourceStatusResetFailure');
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=scratchOrgCreate.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Optional } from '@salesforce/ts-types';
|
|
2
|
+
import { Logger } from './logger';
|
|
3
|
+
import { ScratchOrgInfo } from './scratchOrgInfoApi';
|
|
4
|
+
export declare const checkScratchOrgInfoForErrors: (orgInfo: ScratchOrgInfo, hubUsername: Optional<string>, logger: Logger) => ScratchOrgInfo;
|
|
@@ -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
|