@salesforce/core 3.8.0 → 3.10.0
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/lib/config/ttlConfig.d.ts +32 -0
- package/lib/config/ttlConfig.js +54 -0
- package/lib/exported.d.ts +3 -1
- package/lib/exported.js +7 -1
- package/lib/org/authInfo.d.ts +1 -1
- package/lib/org/authInfo.js +10 -8
- package/lib/org/scratchOrgCreate.d.ts +1 -1
- package/lib/org/scratchOrgCreate.js +9 -6
- package/lib/org/scratchOrgErrorCodes.d.ts +1 -1
- package/lib/org/scratchOrgInfoApi.d.ts +2 -39
- package/lib/org/scratchOrgInfoApi.js +6 -0
- package/lib/org/scratchOrgInfoGenerator.d.ts +1 -1
- package/lib/org/scratchOrgLifecycleEvents.d.ts +8 -0
- package/lib/org/scratchOrgLifecycleEvents.js +26 -0
- package/lib/org/scratchOrgSettingsGenerator.d.ts +1 -5
- package/lib/org/scratchOrgTypes.d.ts +43 -0
- package/lib/org/scratchOrgTypes.js +9 -0
- package/lib/testSetup.d.ts +5 -1
- package/lib/testSetup.js +9 -8
- package/package.json +1 -1
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
|
+
## [3.10.0](https://github.com/forcedotcom/sfdx-core/compare/v3.9.0...v3.10.0) (2022-03-23)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- lifecycle events for scratch org create ([cba673b](https://github.com/forcedotcom/sfdx-core/commit/cba673b515df311165f3c392b155fcf5fbf9e2c6))
|
|
10
|
+
- scratch org lifecycle events ([541349d](https://github.com/forcedotcom/sfdx-core/commit/541349d84b4784356d8bc504d1e331450487b6ec))
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- casing typo for import ([066a2bb](https://github.com/forcedotcom/sfdx-core/commit/066a2bbb37b07f62415f021ef511344976315128))
|
|
15
|
+
- warnings about tracking aren't a throw (org will still auth, default) ([38114a3](https://github.com/forcedotcom/sfdx-core/commit/38114a3526267a615fa8f5d3470b79c9b36a8fa8))
|
|
16
|
+
|
|
17
|
+
## [3.9.0](https://github.com/forcedotcom/sfdx-core/compare/v3.8.1...v3.9.0) (2022-03-21)
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
- add TTLConfig ([#538](https://github.com/forcedotcom/sfdx-core/issues/538)) ([e623241](https://github.com/forcedotcom/sfdx-core/commit/e623241c7e513778c8f179dde4dc16e603a3778c))
|
|
22
|
+
|
|
23
|
+
### [3.8.1](https://github.com/forcedotcom/sfdx-core/compare/v3.8.0...v3.8.1) (2022-03-18)
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
- adjust mock org test data to conform to v3 ([38faf50](https://github.com/forcedotcom/sfdx-core/commit/38faf5063931955066312c24b4188b12c40098a5))
|
|
28
|
+
- side effects function should not save when no changes ([#541](https://github.com/forcedotcom/sfdx-core/issues/541)) ([6bfb841](https://github.com/forcedotcom/sfdx-core/commit/6bfb84172fdf74882102b9ffc6e6fbfe58e6ffbc))
|
|
29
|
+
|
|
5
30
|
## [3.8.0](https://github.com/forcedotcom/sfdx-core/compare/v3.7.9...v3.8.0) (2022-03-09)
|
|
6
31
|
|
|
7
32
|
### Features
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Duration } from '@salesforce/kit';
|
|
2
|
+
import { JsonMap, Nullable } from '@salesforce/ts-types';
|
|
3
|
+
import { ConfigFile } from './configFile';
|
|
4
|
+
/**
|
|
5
|
+
* A Time To Live configuration file where each entry is timestamped and removed once the TTL has expired.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { Duration } from '@salesforce/kit';
|
|
9
|
+
* const config = await TTLConfig.create({
|
|
10
|
+
* isGlobal: false,
|
|
11
|
+
* ttl: Duration.days(1)
|
|
12
|
+
* });
|
|
13
|
+
*/
|
|
14
|
+
export declare class TTLConfig<T extends TTLConfig.Options, P extends JsonMap> extends ConfigFile<T, TTLConfig.Contents<P>> {
|
|
15
|
+
set(key: string, value: Partial<TTLConfig.Entry<P>>): void;
|
|
16
|
+
getLatestEntry(): Nullable<[string, TTLConfig.Entry<P>]>;
|
|
17
|
+
getLatestKey(): Nullable<string>;
|
|
18
|
+
isExpired(dateTime: number, value: P & {
|
|
19
|
+
timestamp: string;
|
|
20
|
+
}): boolean;
|
|
21
|
+
protected init(): Promise<void>;
|
|
22
|
+
private timestamp;
|
|
23
|
+
}
|
|
24
|
+
export declare namespace TTLConfig {
|
|
25
|
+
type Options = ConfigFile.Options & {
|
|
26
|
+
ttl: Duration;
|
|
27
|
+
};
|
|
28
|
+
type Entry<T extends JsonMap> = T & {
|
|
29
|
+
timestamp: string;
|
|
30
|
+
};
|
|
31
|
+
type Contents<T extends JsonMap> = Record<string, Entry<T>>;
|
|
32
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022, 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.TTLConfig = void 0;
|
|
10
|
+
const configFile_1 = require("./configFile");
|
|
11
|
+
/**
|
|
12
|
+
* A Time To Live configuration file where each entry is timestamped and removed once the TTL has expired.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { Duration } from '@salesforce/kit';
|
|
16
|
+
* const config = await TTLConfig.create({
|
|
17
|
+
* isGlobal: false,
|
|
18
|
+
* ttl: Duration.days(1)
|
|
19
|
+
* });
|
|
20
|
+
*/
|
|
21
|
+
class TTLConfig extends configFile_1.ConfigFile {
|
|
22
|
+
set(key, value) {
|
|
23
|
+
super.set(key, this.timestamp(value));
|
|
24
|
+
}
|
|
25
|
+
getLatestEntry() {
|
|
26
|
+
const entries = this.entries();
|
|
27
|
+
const sorted = entries.sort(([, valueA], [, valueB]) => {
|
|
28
|
+
return new Date(valueB.timestamp).getTime() - new Date(valueA.timestamp).getTime();
|
|
29
|
+
});
|
|
30
|
+
return sorted.length > 0 ? sorted[0] : null;
|
|
31
|
+
}
|
|
32
|
+
getLatestKey() {
|
|
33
|
+
const [key] = this.getLatestEntry() || [null];
|
|
34
|
+
return key;
|
|
35
|
+
}
|
|
36
|
+
isExpired(dateTime, value) {
|
|
37
|
+
return dateTime - new Date(value.timestamp).getTime() > this.options.ttl.milliseconds;
|
|
38
|
+
}
|
|
39
|
+
async init() {
|
|
40
|
+
const contents = await this.read(this.options.throwOnNotFound);
|
|
41
|
+
const purged = {};
|
|
42
|
+
const date = new Date().getTime();
|
|
43
|
+
for (const [key, opts] of Object.entries(contents)) {
|
|
44
|
+
if (!this.isExpired(date, opts))
|
|
45
|
+
purged[key] = opts;
|
|
46
|
+
}
|
|
47
|
+
this.setContents(purged);
|
|
48
|
+
}
|
|
49
|
+
timestamp(value) {
|
|
50
|
+
return { ...value, timestamp: new Date().toISOString() };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.TTLConfig = TTLConfig;
|
|
54
|
+
//# sourceMappingURL=ttlConfig.js.map
|
package/lib/exported.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { OAuth2Config } from 'jsforce';
|
|
2
2
|
export { ConfigFile } from './config/configFile';
|
|
3
|
+
export { TTLConfig } from './config/ttlConfig';
|
|
3
4
|
export { envVars, EnvironmentVariable, SUPPORTED_ENV_VARS, EnvVars } from './config/envVars';
|
|
4
5
|
export { BaseConfigStore, ConfigContents, ConfigEntry, ConfigStore, ConfigValue } from './config/configStore';
|
|
5
6
|
export { GlobalInfo, SfEntry, SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfToken, SfTokens } from './globalInfo';
|
|
@@ -29,6 +30,7 @@ export { MyDomainResolver } from './status/myDomainResolver';
|
|
|
29
30
|
export { DefaultUserFields, REQUIRED_FIELDS, User, UserFields } from './org/user';
|
|
30
31
|
export { PermissionSetAssignment, PermissionSetAssignmentFields } from './org/permissionSetAssignment';
|
|
31
32
|
export { ScratchOrgCreateOptions, ScratchOrgCreateResult, scratchOrgCreate } from './org/scratchOrgCreate';
|
|
32
|
-
export { ScratchOrgInfo } from './org/
|
|
33
|
+
export { ScratchOrgInfo } from './org/scratchOrgTypes';
|
|
34
|
+
export { ScratchOrgLifecycleEvent, scratchOrgLifecycleEventName, scratchOrgLifecycleStages, } from './org/scratchOrgLifecycleEvents';
|
|
33
35
|
export * from './util/sfdc';
|
|
34
36
|
export * from './util/sfdcUrl';
|
package/lib/exported.js
CHANGED
|
@@ -16,11 +16,14 @@ 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.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SfError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.SfProjectJson = exports.SfProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = 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.AuthInfo = exports.ConfigAggregator = exports.SFDX_ALLOWED_PROPERTIES = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.ConfigFile = void 0;
|
|
19
|
+
exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SfError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = exports.SfProjectJson = exports.SfProject = exports.ORG_CONFIG_ALLOWED_PROPERTIES = exports.OrgConfigProperties = 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.AuthInfo = exports.ConfigAggregator = exports.SFDX_ALLOWED_PROPERTIES = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.TTLConfig = exports.ConfigFile = void 0;
|
|
20
|
+
exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = void 0;
|
|
20
21
|
const messages_1 = require("./messages");
|
|
21
22
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
22
23
|
var configFile_1 = require("./config/configFile");
|
|
23
24
|
Object.defineProperty(exports, "ConfigFile", { enumerable: true, get: function () { return configFile_1.ConfigFile; } });
|
|
25
|
+
var ttlConfig_1 = require("./config/ttlConfig");
|
|
26
|
+
Object.defineProperty(exports, "TTLConfig", { enumerable: true, get: function () { return ttlConfig_1.TTLConfig; } });
|
|
24
27
|
var envVars_1 = require("./config/envVars");
|
|
25
28
|
Object.defineProperty(exports, "envVars", { enumerable: true, get: function () { return envVars_1.envVars; } });
|
|
26
29
|
Object.defineProperty(exports, "EnvironmentVariable", { enumerable: true, get: function () { return envVars_1.EnvironmentVariable; } });
|
|
@@ -98,6 +101,9 @@ var permissionSetAssignment_1 = require("./org/permissionSetAssignment");
|
|
|
98
101
|
Object.defineProperty(exports, "PermissionSetAssignment", { enumerable: true, get: function () { return permissionSetAssignment_1.PermissionSetAssignment; } });
|
|
99
102
|
var scratchOrgCreate_1 = require("./org/scratchOrgCreate");
|
|
100
103
|
Object.defineProperty(exports, "scratchOrgCreate", { enumerable: true, get: function () { return scratchOrgCreate_1.scratchOrgCreate; } });
|
|
104
|
+
var scratchOrgLifecycleEvents_1 = require("./org/scratchOrgLifecycleEvents");
|
|
105
|
+
Object.defineProperty(exports, "scratchOrgLifecycleEventName", { enumerable: true, get: function () { return scratchOrgLifecycleEvents_1.scratchOrgLifecycleEventName; } });
|
|
106
|
+
Object.defineProperty(exports, "scratchOrgLifecycleStages", { enumerable: true, get: function () { return scratchOrgLifecycleEvents_1.scratchOrgLifecycleStages; } });
|
|
101
107
|
// Utility sub-modules
|
|
102
108
|
__exportStar(require("./util/sfdc"), exports);
|
|
103
109
|
__exportStar(require("./util/sfdcUrl"), exports);
|
package/lib/org/authInfo.d.ts
CHANGED
|
@@ -232,7 +232,7 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
|
|
|
232
232
|
getSfdxAuthUrl(): string;
|
|
233
233
|
/**
|
|
234
234
|
* Convenience function to handle typical side effects encountered when dealing with an AuthInfo.
|
|
235
|
-
* Given the values supplied in parameter sideEffects, this
|
|
235
|
+
* Given the values supplied in parameter sideEffects, this function will set auth alias, default auth
|
|
236
236
|
* and default dev hub.
|
|
237
237
|
*
|
|
238
238
|
* @param sideEffects - instance of AuthSideEffects
|
package/lib/org/authInfo.js
CHANGED
|
@@ -400,19 +400,21 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
400
400
|
}
|
|
401
401
|
/**
|
|
402
402
|
* Convenience function to handle typical side effects encountered when dealing with an AuthInfo.
|
|
403
|
-
* Given the values supplied in parameter sideEffects, this
|
|
403
|
+
* Given the values supplied in parameter sideEffects, this function will set auth alias, default auth
|
|
404
404
|
* and default dev hub.
|
|
405
405
|
*
|
|
406
406
|
* @param sideEffects - instance of AuthSideEffects
|
|
407
407
|
*/
|
|
408
408
|
async handleAliasAndDefaultSettings(sideEffects) {
|
|
409
|
-
if (sideEffects.alias)
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
409
|
+
if (sideEffects.alias || sideEffects.setDefault || sideEffects.setDefaultDevHub) {
|
|
410
|
+
if (sideEffects.alias)
|
|
411
|
+
await this.setAlias(sideEffects.alias);
|
|
412
|
+
if (sideEffects.setDefault)
|
|
413
|
+
await this.setAsDefault({ org: true });
|
|
414
|
+
if (sideEffects.setDefaultDevHub)
|
|
415
|
+
await this.setAsDefault({ devHub: true });
|
|
416
|
+
await this.save();
|
|
417
|
+
}
|
|
416
418
|
}
|
|
417
419
|
/**
|
|
418
420
|
* Set the target-env (default) or the target-dev-hub to the alias if
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Duration } from '@salesforce/kit';
|
|
2
2
|
import { Org } from './org';
|
|
3
|
-
import { ScratchOrgInfo } from './
|
|
3
|
+
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
4
4
|
import { AuthFields, AuthInfo } from './authInfo';
|
|
5
5
|
export declare const DEFAULT_STREAM_TIMEOUT_MINUTES = 6;
|
|
6
6
|
export interface ScratchOrgCreateResult {
|
|
@@ -13,12 +13,13 @@ const messages_1 = require("../messages");
|
|
|
13
13
|
const logger_1 = require("../logger");
|
|
14
14
|
const configAggregator_1 = require("../config/configAggregator");
|
|
15
15
|
const sfProject_1 = require("../sfProject");
|
|
16
|
-
const
|
|
16
|
+
const lifecycleEvents_1 = require("../lifecycleEvents");
|
|
17
17
|
const org_1 = require("./org");
|
|
18
18
|
const scratchOrgInfoApi_1 = require("./scratchOrgInfoApi");
|
|
19
19
|
const scratchOrgSettingsGenerator_1 = require("./scratchOrgSettingsGenerator");
|
|
20
20
|
const scratchOrgInfoGenerator_1 = require("./scratchOrgInfoGenerator");
|
|
21
21
|
const connection_1 = require("./connection");
|
|
22
|
+
const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents");
|
|
22
23
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
23
24
|
const messages = messages_1.Messages.load('@salesforce/core', 'scratchOrgCreate', [
|
|
24
25
|
'SourceStatusResetFailureError',
|
|
@@ -58,6 +59,7 @@ const scratchOrgCreate = async (options) => {
|
|
|
58
59
|
var _a;
|
|
59
60
|
const logger = await logger_1.Logger.child('scratchOrgCreate');
|
|
60
61
|
logger.debug('scratchOrgCreate');
|
|
62
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'prepare request' });
|
|
61
63
|
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;
|
|
62
64
|
validateDuration(durationDays);
|
|
63
65
|
validateRetry(retry);
|
|
@@ -100,10 +102,12 @@ const scratchOrgCreate = async (options) => {
|
|
|
100
102
|
const username = scratchOrg.getUsername();
|
|
101
103
|
logger.debug(`scratch org username ${username}`);
|
|
102
104
|
const configAggregator = new configAggregator_1.ConfigAggregator();
|
|
105
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'deploy settings', scratchOrgInfo: scratchOrgInfoResult });
|
|
103
106
|
const authInfo = await (0, scratchOrgInfoApi_1.deploySettingsAndResolveUrl)(scratchOrgAuthInfo, (_a = apiversion !== null && apiversion !== void 0 ? apiversion : configAggregator.getPropertyValue('apiVersion')) !== null && _a !== void 0 ? _a : (await scratchOrg.retrieveMaxApiVersion()), settingsGenerator, scratchOrg);
|
|
104
107
|
logger.trace('Settings deployed to org');
|
|
105
108
|
/** 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.*/
|
|
106
109
|
await updateRevisionCounterToZero(scratchOrg);
|
|
110
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'done', scratchOrgInfo: scratchOrgInfoResult });
|
|
107
111
|
return {
|
|
108
112
|
username,
|
|
109
113
|
scratchOrgInfo: scratchOrgInfoResult,
|
|
@@ -126,17 +130,16 @@ const getSignupTargetLoginUrl = async () => {
|
|
|
126
130
|
const updateRevisionCounterToZero = async (scratchOrg) => {
|
|
127
131
|
const conn = scratchOrg.getConnection();
|
|
128
132
|
const queryResult = await conn.tooling.sobject('SourceMember').find({ RevisionCounter: { $gt: 0 } }, ['Id']);
|
|
133
|
+
if (queryResult.length === 0) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
129
136
|
try {
|
|
130
137
|
await conn.tooling
|
|
131
138
|
.sobject('SourceMember')
|
|
132
139
|
.update(queryResult.map((record) => ({ Id: record.Id, RevisionCounter: 0 })));
|
|
133
140
|
}
|
|
134
141
|
catch (err) {
|
|
135
|
-
|
|
136
|
-
scratchOrg.getOrgId(),
|
|
137
|
-
scratchOrg.getUsername(),
|
|
138
|
-
]);
|
|
139
|
-
throw new sfError_1.SfError(message, 'SourceStatusResetFailure');
|
|
142
|
+
await lifecycleEvents_1.Lifecycle.getInstance().emitWarning(messages.getMessage('SourceStatusResetFailureError', [scratchOrg.getOrgId(), scratchOrg.getUsername()]));
|
|
140
143
|
}
|
|
141
144
|
};
|
|
142
145
|
//# sourceMappingURL=scratchOrgCreate.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Optional } from '@salesforce/ts-types';
|
|
2
2
|
import { Logger } from '../logger';
|
|
3
|
-
import { ScratchOrgInfo } from './
|
|
3
|
+
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
4
4
|
export declare const checkScratchOrgInfoForErrors: (orgInfo: Optional<ScratchOrgInfo>, hubUsername: Optional<string>, logger: Logger) => ScratchOrgInfo;
|
|
@@ -3,45 +3,8 @@ import { Duration } from '@salesforce/kit';
|
|
|
3
3
|
import { SaveResult } from 'jsforce';
|
|
4
4
|
import { AuthInfo } from './authInfo';
|
|
5
5
|
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
|
-
}
|
|
6
|
+
import SettingsGenerator from './scratchOrgSettingsGenerator';
|
|
7
|
+
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
45
8
|
export interface JsForceError extends Error {
|
|
46
9
|
errorCode: string;
|
|
47
10
|
fields: string[];
|
|
@@ -20,6 +20,7 @@ const myDomainResolver_1 = require("../status/myDomainResolver");
|
|
|
20
20
|
const authInfo_1 = require("./authInfo");
|
|
21
21
|
const org_1 = require("./org");
|
|
22
22
|
const scratchOrgErrorCodes_1 = require("./scratchOrgErrorCodes");
|
|
23
|
+
const scratchOrgLifecycleEvents_1 = require("./scratchOrgLifecycleEvents");
|
|
23
24
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
24
25
|
const messages = messages_1.Messages.loadMessages('@salesforce/core', 'scratchOrgInfoApi');
|
|
25
26
|
const errorCodes = messages_1.Messages.load('@salesforce/core', 'scratchOrgErrorCodes', ['C-1007']);
|
|
@@ -144,6 +145,7 @@ const getAuthInfo = async (options) => {
|
|
|
144
145
|
const authorizeScratchOrg = async (options) => {
|
|
145
146
|
var _a;
|
|
146
147
|
const { scratchOrgInfoComplete, hubOrg, clientSecret, signupTargetLoginUrlConfig, retry: maxRetries } = options;
|
|
148
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'authenticate', scratchOrgInfo: scratchOrgInfoComplete });
|
|
147
149
|
const logger = await logger_1.Logger.child('authorizeScratchOrg');
|
|
148
150
|
logger.debug(`scratchOrgInfoComplete: ${JSON.stringify(scratchOrgInfoComplete, null, 4)}`);
|
|
149
151
|
// 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
|
|
@@ -225,6 +227,8 @@ const requestScratchOrgCreation = async (hubOrg, scratchOrgRequest, settings) =>
|
|
|
225
227
|
const scratchOrgInfo = (0, mapKeys_1.default)(scratchOrgRequest, kit_1.upperFirst, true);
|
|
226
228
|
await checkOrgDoesntExist(scratchOrgInfo); // throw if it does exist.
|
|
227
229
|
try {
|
|
230
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'send request' });
|
|
231
|
+
// return await will cause this catch block to run instead of the caller's catch block
|
|
228
232
|
return await hubOrg.getConnection().sobject('ScratchOrgInfo').create(scratchOrgInfo);
|
|
229
233
|
}
|
|
230
234
|
catch (error) {
|
|
@@ -257,11 +261,13 @@ timeout = kit_1.Duration.minutes(15)) => {
|
|
|
257
261
|
logger.debug(`polling client result: ${JSON.stringify(resultInProgress, null, 4)}`);
|
|
258
262
|
// Once it's "done" we can return it
|
|
259
263
|
if (resultInProgress.Status === 'Active' || resultInProgress.Status === 'Error') {
|
|
264
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'available', scratchOrgInfo: resultInProgress });
|
|
260
265
|
return {
|
|
261
266
|
completed: true,
|
|
262
267
|
payload: resultInProgress,
|
|
263
268
|
};
|
|
264
269
|
}
|
|
270
|
+
await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'wait for org', scratchOrgInfo: resultInProgress });
|
|
265
271
|
logger.debug(`Scratch org status is ${resultInProgress.Status}`);
|
|
266
272
|
return {
|
|
267
273
|
completed: false,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SfProjectJson } from '../sfProject';
|
|
2
2
|
import { Org } from './org';
|
|
3
|
-
import { ScratchOrgInfo } from './
|
|
3
|
+
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
4
4
|
declare type PartialScratchOrgInfo = Pick<ScratchOrgInfo, 'ConnectedAppConsumerKey' | 'AuthCode' | 'Snapshot' | 'Status' | 'LoginUrl' | 'SignupEmail' | 'SignupUsername' | 'SignupInstance' | 'Username'>;
|
|
5
5
|
export interface ScratchOrgInfoPayload extends PartialScratchOrgInfo {
|
|
6
6
|
orgName: string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
2
|
+
export declare const scratchOrgLifecycleEventName = "scratchOrgLifecycleEvent";
|
|
3
|
+
export declare const scratchOrgLifecycleStages: readonly ["prepare request", "send request", "wait for org", "available", "authenticate", "deploy settings", "done"];
|
|
4
|
+
export interface ScratchOrgLifecycleEvent {
|
|
5
|
+
stage: typeof scratchOrgLifecycleStages[number];
|
|
6
|
+
scratchOrgInfo?: ScratchOrgInfo;
|
|
7
|
+
}
|
|
8
|
+
export declare const emit: (event: ScratchOrgLifecycleEvent) => Promise<void>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emit = exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
* Licensed under the BSD 3-Clause license.
|
|
8
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
9
|
+
*/
|
|
10
|
+
const lifecycleEvents_1 = require("../lifecycleEvents");
|
|
11
|
+
const emitter = lifecycleEvents_1.Lifecycle.getInstance();
|
|
12
|
+
exports.scratchOrgLifecycleEventName = 'scratchOrgLifecycleEvent';
|
|
13
|
+
exports.scratchOrgLifecycleStages = [
|
|
14
|
+
'prepare request',
|
|
15
|
+
'send request',
|
|
16
|
+
'wait for org',
|
|
17
|
+
'available',
|
|
18
|
+
'authenticate',
|
|
19
|
+
'deploy settings',
|
|
20
|
+
'done',
|
|
21
|
+
];
|
|
22
|
+
const emit = async (event) => {
|
|
23
|
+
emitter.emit(exports.scratchOrgLifecycleEventName, event);
|
|
24
|
+
};
|
|
25
|
+
exports.emit = emit;
|
|
26
|
+
//# sourceMappingURL=scratchOrgLifecycleEvents.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonMap } from '@salesforce/ts-types';
|
|
2
|
-
import { ScratchOrgInfo } from './
|
|
2
|
+
import { ScratchOrgInfo } from './scratchOrgTypes';
|
|
3
3
|
import { Org } from './org';
|
|
4
4
|
export declare enum RequestStatus {
|
|
5
5
|
Pending = "Pending",
|
|
@@ -10,10 +10,6 @@ export declare enum RequestStatus {
|
|
|
10
10
|
Canceling = "Canceling",
|
|
11
11
|
Canceled = "Canceled"
|
|
12
12
|
}
|
|
13
|
-
export interface ObjectSetting extends JsonMap {
|
|
14
|
-
sharingModel?: string;
|
|
15
|
-
defaultRecordType?: string;
|
|
16
|
-
}
|
|
17
13
|
export interface BusinessProcessFileContent extends JsonMap {
|
|
18
14
|
fullName: string;
|
|
19
15
|
isActive: boolean;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { JsonMap } from '@salesforce/ts-types';
|
|
2
|
+
export interface ScratchOrgInfo {
|
|
3
|
+
AdminEmail?: string;
|
|
4
|
+
readonly CreatedDate?: string;
|
|
5
|
+
ConnectedAppCallbackUrl?: string;
|
|
6
|
+
ConnectedAppConsumerKey?: string;
|
|
7
|
+
Country?: string;
|
|
8
|
+
Description?: string;
|
|
9
|
+
DurationDays?: string;
|
|
10
|
+
Edition?: string;
|
|
11
|
+
readonly ErrorCode?: string;
|
|
12
|
+
readonly ExpirationDate?: string;
|
|
13
|
+
Features?: string;
|
|
14
|
+
HasSampleData?: boolean;
|
|
15
|
+
readonly Id?: string;
|
|
16
|
+
Language?: string;
|
|
17
|
+
LoginUrl: string;
|
|
18
|
+
readonly Name?: string;
|
|
19
|
+
Namespace?: string;
|
|
20
|
+
OrgName?: string;
|
|
21
|
+
Release?: 'Current' | 'Previous' | 'Preview';
|
|
22
|
+
readonly ScratchOrg?: string;
|
|
23
|
+
SourceOrg?: string;
|
|
24
|
+
readonly AuthCode: string;
|
|
25
|
+
Snapshot: string;
|
|
26
|
+
readonly Status: 'New' | 'Creating' | 'Active' | 'Error' | 'Deleted';
|
|
27
|
+
readonly SignupEmail: string;
|
|
28
|
+
readonly SignupUsername: string;
|
|
29
|
+
readonly SignupInstance: string;
|
|
30
|
+
Username: string;
|
|
31
|
+
settings?: Record<string, unknown>;
|
|
32
|
+
objectSettings?: {
|
|
33
|
+
[objectName: string]: ObjectSetting;
|
|
34
|
+
};
|
|
35
|
+
orgPreferences?: {
|
|
36
|
+
enabled: string[];
|
|
37
|
+
disabled: string[];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface ObjectSetting extends JsonMap {
|
|
41
|
+
sharingModel?: string;
|
|
42
|
+
defaultRecordType?: string;
|
|
43
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
//# sourceMappingURL=scratchOrgTypes.js.map
|
package/lib/testSetup.d.ts
CHANGED
|
@@ -377,7 +377,8 @@ export declare class StreamingMockCometClient extends CometClient {
|
|
|
377
377
|
*/
|
|
378
378
|
export declare class MockTestOrgData {
|
|
379
379
|
testId: string;
|
|
380
|
-
|
|
380
|
+
aliases?: string[];
|
|
381
|
+
configs?: string[];
|
|
381
382
|
username: string;
|
|
382
383
|
devHubUsername?: string;
|
|
383
384
|
orgId: string;
|
|
@@ -390,6 +391,9 @@ export declare class MockTestOrgData {
|
|
|
390
391
|
refreshToken: string;
|
|
391
392
|
userId: string;
|
|
392
393
|
redirectUri: string;
|
|
394
|
+
isDevHub?: boolean;
|
|
395
|
+
isScratchOrg?: boolean;
|
|
396
|
+
isExpired?: boolean | 'unknown';
|
|
393
397
|
constructor(id?: string, options?: {
|
|
394
398
|
username: string;
|
|
395
399
|
});
|
package/lib/testSetup.js
CHANGED
|
@@ -493,12 +493,13 @@ class MockTestOrgData {
|
|
|
493
493
|
this.devHubUsername = username;
|
|
494
494
|
}
|
|
495
495
|
makeDevHub() {
|
|
496
|
-
|
|
496
|
+
this.isDevHub = true;
|
|
497
497
|
}
|
|
498
498
|
createUser(user) {
|
|
499
499
|
const userMock = new MockTestOrgData();
|
|
500
500
|
userMock.username = user;
|
|
501
|
-
userMock.
|
|
501
|
+
userMock.aliases = this.aliases;
|
|
502
|
+
userMock.configs = this.configs;
|
|
502
503
|
userMock.devHubUsername = this.devHubUsername;
|
|
503
504
|
userMock.orgId = this.orgId;
|
|
504
505
|
userMock.loginUrl = this.loginUrl;
|
|
@@ -506,6 +507,9 @@ class MockTestOrgData {
|
|
|
506
507
|
userMock.clientId = this.clientId;
|
|
507
508
|
userMock.clientSecret = this.clientSecret;
|
|
508
509
|
userMock.redirectUri = this.redirectUri;
|
|
510
|
+
userMock.isDevHub = this.isDevHub;
|
|
511
|
+
userMock.isScratchOrg = this.isScratchOrg;
|
|
512
|
+
userMock.isExpired = this.isExpired;
|
|
509
513
|
return userMock;
|
|
510
514
|
}
|
|
511
515
|
getMockUserInfo() {
|
|
@@ -513,7 +517,8 @@ class MockTestOrgData {
|
|
|
513
517
|
Id: this.userId,
|
|
514
518
|
Username: this.username,
|
|
515
519
|
LastName: `user_lastname_${this.testId}`,
|
|
516
|
-
Alias: this.
|
|
520
|
+
Alias: this.aliases ? this.aliases[0] : 'user_alias_blah',
|
|
521
|
+
Configs: this.configs,
|
|
517
522
|
TimeZoneSidKey: `user_timezonesidkey_${this.testId}`,
|
|
518
523
|
LocaleSidKey: `user_localesidkey_${this.testId}`,
|
|
519
524
|
EmailEncodingKey: `user_emailencodingkey_${this.testId}`,
|
|
@@ -540,14 +545,10 @@ class MockTestOrgData {
|
|
|
540
545
|
config.createdOrgInstance = 'CS1';
|
|
541
546
|
config.created = '1519163543003';
|
|
542
547
|
config.userId = this.userId;
|
|
543
|
-
// config.devHubUsername = 'tn@su-blitz.org';
|
|
544
548
|
if (this.devHubUsername) {
|
|
545
549
|
config.devHubUsername = this.devHubUsername;
|
|
546
550
|
}
|
|
547
|
-
|
|
548
|
-
if (isDevHub) {
|
|
549
|
-
config.isDevHub = isDevHub;
|
|
550
|
-
}
|
|
551
|
+
config.isDevHub = this.isDevHub;
|
|
551
552
|
return config;
|
|
552
553
|
}
|
|
553
554
|
}
|