@salesforce/core 3.9.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 CHANGED
@@ -2,6 +2,18 @@
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
+
5
17
  ## [3.9.0](https://github.com/forcedotcom/sfdx-core/compare/v3.8.1...v3.9.0) (2022-03-21)
6
18
 
7
19
  ### Features
package/lib/exported.d.ts CHANGED
@@ -30,6 +30,7 @@ export { MyDomainResolver } from './status/myDomainResolver';
30
30
  export { DefaultUserFields, REQUIRED_FIELDS, User, UserFields } from './org/user';
31
31
  export { PermissionSetAssignment, PermissionSetAssignmentFields } from './org/permissionSetAssignment';
32
32
  export { ScratchOrgCreateOptions, ScratchOrgCreateResult, scratchOrgCreate } from './org/scratchOrgCreate';
33
- export { ScratchOrgInfo } from './org/scratchOrgInfoApi';
33
+ export { ScratchOrgInfo } from './org/scratchOrgTypes';
34
+ export { ScratchOrgLifecycleEvent, scratchOrgLifecycleEventName, scratchOrgLifecycleStages, } from './org/scratchOrgLifecycleEvents';
34
35
  export * from './util/sfdc';
35
36
  export * from './util/sfdcUrl';
package/lib/exported.js CHANGED
@@ -17,6 +17,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
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");
@@ -100,6 +101,9 @@ var permissionSetAssignment_1 = require("./org/permissionSetAssignment");
100
101
  Object.defineProperty(exports, "PermissionSetAssignment", { enumerable: true, get: function () { return permissionSetAssignment_1.PermissionSetAssignment; } });
101
102
  var scratchOrgCreate_1 = require("./org/scratchOrgCreate");
102
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; } });
103
107
  // Utility sub-modules
104
108
  __exportStar(require("./util/sfdc"), exports);
105
109
  __exportStar(require("./util/sfdcUrl"), exports);
@@ -1,6 +1,6 @@
1
1
  import { Duration } from '@salesforce/kit';
2
2
  import { Org } from './org';
3
- import { ScratchOrgInfo } from './scratchOrgInfoApi';
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 sfError_1 = require("../sfError");
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
- const message = messages.getMessage('SourceStatusResetFailureError', [
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 './scratchOrgInfoApi';
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, { ObjectSetting } from './scratchOrgSettingsGenerator';
7
- export interface ScratchOrgInfo {
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 './scratchOrgInfoApi';
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 './scratchOrgInfoApi';
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.9.0",
3
+ "version": "3.10.0",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",