@salesforce/core 3.8.1 → 3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,30 @@
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.1](https://github.com/forcedotcom/sfdx-core/compare/v3.10.0...v3.10.1) (2022-03-24)
6
+
7
+ ### Bug Fixes
8
+
9
+ - rotating file logs ([ef5df25](https://github.com/forcedotcom/sfdx-core/commit/ef5df25c17a67541d12d5c228c18b75775251d98))
10
+
11
+ ## [3.10.0](https://github.com/forcedotcom/sfdx-core/compare/v3.9.0...v3.10.0) (2022-03-23)
12
+
13
+ ### Features
14
+
15
+ - lifecycle events for scratch org create ([cba673b](https://github.com/forcedotcom/sfdx-core/commit/cba673b515df311165f3c392b155fcf5fbf9e2c6))
16
+ - scratch org lifecycle events ([541349d](https://github.com/forcedotcom/sfdx-core/commit/541349d84b4784356d8bc504d1e331450487b6ec))
17
+
18
+ ### Bug Fixes
19
+
20
+ - casing typo for import ([066a2bb](https://github.com/forcedotcom/sfdx-core/commit/066a2bbb37b07f62415f021ef511344976315128))
21
+ - warnings about tracking aren't a throw (org will still auth, default) ([38114a3](https://github.com/forcedotcom/sfdx-core/commit/38114a3526267a615fa8f5d3470b79c9b36a8fa8))
22
+
23
+ ## [3.9.0](https://github.com/forcedotcom/sfdx-core/compare/v3.8.1...v3.9.0) (2022-03-21)
24
+
25
+ ### Features
26
+
27
+ - add TTLConfig ([#538](https://github.com/forcedotcom/sfdx-core/issues/538)) ([e623241](https://github.com/forcedotcom/sfdx-core/commit/e623241c7e513778c8f179dde4dc16e603a3778c))
28
+
5
29
  ### [3.8.1](https://github.com/forcedotcom/sfdx-core/compare/v3.8.0...v3.8.1) (2022-03-18)
6
30
 
7
31
  ### Bug Fixes
@@ -26,6 +26,8 @@ export declare enum EnvironmentVariable {
26
26
  'SFDX_INSTANCE_URL' = "SFDX_INSTANCE_URL",
27
27
  'SFDX_JSON_TO_STDOUT' = "SFDX_JSON_TO_STDOUT",
28
28
  'SFDX_LOG_LEVEL' = "SFDX_LOG_LEVEL",
29
+ 'SFDX_LOG_ROTATION_COUNT' = "SFDX_LOG_ROTATION_COUNT",
30
+ 'SFDX_LOG_ROTATION_PERIOD' = "SFDX_LOG_ROTATION_PERIOD",
29
31
  'SFDX_MAX_QUERY_LIMIT' = "SFDX_MAX_QUERY_LIMIT",
30
32
  'SFDX_MDAPI_TEMP_DIR' = "SFDX_MDAPI_TEMP_DIR",
31
33
  'SFDX_NPM_REGISTRY' = "SFDX_NPM_REGISTRY",
@@ -58,6 +60,8 @@ export declare enum EnvironmentVariable {
58
60
  'SF_INSTANCE_URL' = "SF_INSTANCE_URL",
59
61
  'SF_JSON_TO_STDOUT' = "SF_JSON_TO_STDOUT",
60
62
  'SF_LOG_LEVEL' = "SF_LOG_LEVEL",
63
+ 'SF_LOG_ROTATION_COUNT' = "SF_LOG_ROTATION_COUNT",
64
+ 'SF_LOG_ROTATION_PERIOD' = "SF_LOG_ROTATION_PERIOD",
61
65
  'SF_MAX_QUERY_LIMIT' = "SF_MAX_QUERY_LIMIT",
62
66
  'SF_MDAPI_TEMP_DIR' = "SF_MDAPI_TEMP_DIR",
63
67
  'SF_NPM_REGISTRY' = "SF_NPM_REGISTRY",
@@ -40,6 +40,8 @@ var EnvironmentVariable;
40
40
  EnvironmentVariable["SFDX_INSTANCE_URL"] = "SFDX_INSTANCE_URL";
41
41
  EnvironmentVariable["SFDX_JSON_TO_STDOUT"] = "SFDX_JSON_TO_STDOUT";
42
42
  EnvironmentVariable["SFDX_LOG_LEVEL"] = "SFDX_LOG_LEVEL";
43
+ EnvironmentVariable["SFDX_LOG_ROTATION_COUNT"] = "SFDX_LOG_ROTATION_COUNT";
44
+ EnvironmentVariable["SFDX_LOG_ROTATION_PERIOD"] = "SFDX_LOG_ROTATION_PERIOD";
43
45
  EnvironmentVariable["SFDX_MAX_QUERY_LIMIT"] = "SFDX_MAX_QUERY_LIMIT";
44
46
  EnvironmentVariable["SFDX_MDAPI_TEMP_DIR"] = "SFDX_MDAPI_TEMP_DIR";
45
47
  EnvironmentVariable["SFDX_NPM_REGISTRY"] = "SFDX_NPM_REGISTRY";
@@ -72,6 +74,8 @@ var EnvironmentVariable;
72
74
  EnvironmentVariable["SF_INSTANCE_URL"] = "SF_INSTANCE_URL";
73
75
  EnvironmentVariable["SF_JSON_TO_STDOUT"] = "SF_JSON_TO_STDOUT";
74
76
  EnvironmentVariable["SF_LOG_LEVEL"] = "SF_LOG_LEVEL";
77
+ EnvironmentVariable["SF_LOG_ROTATION_COUNT"] = "SF_LOG_ROTATION_COUNT";
78
+ EnvironmentVariable["SF_LOG_ROTATION_PERIOD"] = "SF_LOG_ROTATION_PERIOD";
75
79
  EnvironmentVariable["SF_MAX_QUERY_LIMIT"] = "SF_MAX_QUERY_LIMIT";
76
80
  EnvironmentVariable["SF_MDAPI_TEMP_DIR"] = "SF_MDAPI_TEMP_DIR";
77
81
  EnvironmentVariable["SF_NPM_REGISTRY"] = "SF_NPM_REGISTRY";
@@ -186,6 +190,14 @@ exports.SUPPORTED_ENV_VARS = {
186
190
  description: getMessage(EnvironmentVariable.SFDX_LOG_LEVEL),
187
191
  synonymOf: EnvironmentVariable.SF_LOG_LEVEL,
188
192
  },
193
+ [EnvironmentVariable.SFDX_LOG_ROTATION_COUNT]: {
194
+ description: getMessage(EnvironmentVariable.SFDX_LOG_ROTATION_COUNT),
195
+ synonymOf: EnvironmentVariable.SF_LOG_ROTATION_COUNT,
196
+ },
197
+ [EnvironmentVariable.SFDX_LOG_ROTATION_PERIOD]: {
198
+ description: getMessage(EnvironmentVariable.SFDX_LOG_ROTATION_PERIOD),
199
+ synonymOf: EnvironmentVariable.SF_LOG_ROTATION_PERIOD,
200
+ },
189
201
  [EnvironmentVariable.SFDX_MAX_QUERY_LIMIT]: {
190
202
  description: getMessage(EnvironmentVariable.SFDX_MAX_QUERY_LIMIT),
191
203
  synonymOf: EnvironmentVariable.SF_MAX_QUERY_LIMIT,
@@ -315,6 +327,14 @@ exports.SUPPORTED_ENV_VARS = {
315
327
  description: getMessage(EnvironmentVariable.SF_LOG_LEVEL),
316
328
  synonymOf: null,
317
329
  },
330
+ [EnvironmentVariable.SF_LOG_ROTATION_COUNT]: {
331
+ description: getMessage(EnvironmentVariable.SF_LOG_ROTATION_COUNT),
332
+ synonymOf: null,
333
+ },
334
+ [EnvironmentVariable.SF_LOG_ROTATION_PERIOD]: {
335
+ description: getMessage(EnvironmentVariable.SF_LOG_ROTATION_PERIOD),
336
+ synonymOf: null,
337
+ },
318
338
  [EnvironmentVariable.SF_MAX_QUERY_LIMIT]: {
319
339
  description: getMessage(EnvironmentVariable.SF_MAX_QUERY_LIMIT),
320
340
  synonymOf: null,
@@ -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/scratchOrgInfoApi';
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/logger.d.ts CHANGED
@@ -163,6 +163,17 @@ export declare class Logger {
163
163
  static readonly LEVEL_NAMES: string[];
164
164
  private static readonly lifecycle;
165
165
  private static rootLogger?;
166
+ /**
167
+ * The default rotation period for logs. Example '1d' will rotate logs daily (at midnight).
168
+ * See 'period' docs here: https://github.com/forcedotcom/node-bunyan#stream-type-rotating-file
169
+ */
170
+ readonly logRotationPeriod: string;
171
+ /**
172
+ * The number of backup rotated log files to keep.
173
+ * Example: '3' will have the base sf.log file, and the past 3 (period) log files.
174
+ * See 'count' docs here: https://github.com/forcedotcom/node-bunyan#stream-type-rotating-file
175
+ */
176
+ readonly logRotationCount: number;
166
177
  /**
167
178
  * Whether debug is enabled for this Logger.
168
179
  */
package/lib/logger.js CHANGED
@@ -74,6 +74,17 @@ class Logger {
74
74
  * `Logger`.
75
75
  */
76
76
  constructor(optionsOrName) {
77
+ /**
78
+ * The default rotation period for logs. Example '1d' will rotate logs daily (at midnight).
79
+ * See 'period' docs here: https://github.com/forcedotcom/node-bunyan#stream-type-rotating-file
80
+ */
81
+ this.logRotationPeriod = new kit_1.Env().getString('SF_LOG_ROTATION_PERIOD') || '1d';
82
+ /**
83
+ * The number of backup rotated log files to keep.
84
+ * Example: '3' will have the base sf.log file, and the past 3 (period) log files.
85
+ * See 'count' docs here: https://github.com/forcedotcom/node-bunyan#stream-type-rotating-file
86
+ */
87
+ this.logRotationCount = new kit_1.Env().getNumber('SF_LOG_ROTATION_COUNT') || 2;
77
88
  /**
78
89
  * Whether debug is enabled for this Logger.
79
90
  */
@@ -252,12 +263,12 @@ class Logger {
252
263
  if (!this.bunyan.streams.find(
253
264
  // No bunyan typings
254
265
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
255
- (stream) => stream.type === 'file' && stream.path === logFile)) {
256
- // TODO: rotating-file
257
- // https://github.com/trentm/node-bunyan#stream-type-rotating-file
266
+ (stream) => stream.type === 'rotating-file' && stream.path === logFile)) {
258
267
  this.addStream({
259
- type: 'file',
268
+ type: 'rotating-file',
260
269
  path: logFile,
270
+ period: this.logRotationPeriod,
271
+ count: this.logRotationCount,
261
272
  level: this.bunyan.level(),
262
273
  });
263
274
  }
@@ -292,12 +303,12 @@ class Logger {
292
303
  if (!this.bunyan.streams.find(
293
304
  // No bunyan typings
294
305
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
295
- (stream) => stream.type === 'file' && stream.path === logFile)) {
296
- // TODO: rotating-file
297
- // https://github.com/trentm/node-bunyan#stream-type-rotating-file
306
+ (stream) => stream.type === 'rotating-file' && stream.path === logFile)) {
298
307
  this.addStream({
299
- type: 'file',
308
+ type: 'rotating-file',
300
309
  path: logFile,
310
+ period: this.logRotationPeriod,
311
+ count: this.logRotationCount,
301
312
  level: this.bunyan.level(),
302
313
  });
303
314
  }
@@ -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
@@ -94,6 +94,14 @@ Set to true to send messages resulting from failed Salesforce CLI commands to st
94
94
 
95
95
  Level of messages that the CLI writes to the log file. Valid values are trace, debug, info, warn, error, fatal. Default value is warn.
96
96
 
97
+ # sfdxLogRotationCount
98
+
99
+ The default rotation period for logs. Example '1d' will rotate logs daily (at midnight).
100
+
101
+ # sfdxLogRotationPeriod
102
+
103
+ The number of backup rotated log files to keep. Example: '3' will have the base sf.log file, and the past 3 (period) log files.
104
+
97
105
  # sfdxMaxQueryLimit
98
106
 
99
107
  Maximum number of Salesforce records returned by a CLI command. Default value is 10,000. Overrides the maxQueryLimit configuration value.
@@ -222,6 +230,14 @@ Set to true to send messages resulting from failed Salesforce CLI commands to st
222
230
 
223
231
  Level of messages that the CLI writes to the log file. Valid values are trace, debug, info, warn, error, fatal. Default value is warn.
224
232
 
233
+ # sfLogRotationCount
234
+
235
+ The default rotation period for logs. Example '1d' will rotate logs daily (at midnight).
236
+
237
+ # sfLogRotationPeriod
238
+
239
+ The number of backup rotated log files to keep. Example: '3' will have the base sf.log file, and the past 3 (period) log files.
240
+
225
241
  # sfMaxQueryLimit
226
242
 
227
243
  Maximum number of Salesforce records returned by a CLI command. Default value is 10,000. Overrides the maxQueryLimit configuration variable.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.8.1",
3
+ "version": "3.10.1",
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",