@salesforce/core 2.35.3 → 2.36.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
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.36.2](https://github.com/forcedotcom/sfdx-core/compare/v2.36.1...v2.36.2) (2022-04-20)
6
+
7
+ ### [2.36.1](https://github.com/forcedotcom/sfdx-core/compare/v2.36.0...v2.36.1) (2022-04-14)
8
+
9
+ ### Bug Fixes
10
+
11
+ - sandbox cname recognition ([#555](https://github.com/forcedotcom/sfdx-core/issues/555)) ([105bc9a](https://github.com/forcedotcom/sfdx-core/commit/105bc9a043b3c984846e060e5176b290fe49b5bc))
12
+
13
+ ## [2.36.0](https://github.com/forcedotcom/sfdx-core/compare/v2.35.3...v2.36.0) (2022-03-23)
14
+
15
+ ### Features
16
+
17
+ - rotating log file ([d185e00](https://github.com/forcedotcom/sfdx-core/commit/d185e00aa66fc558f3c0d710cb2fafa0655a9fbc))
18
+
19
+ ### Bug Fixes
20
+
21
+ - bump jsforce types ([ddacb98](https://github.com/forcedotcom/sfdx-core/commit/ddacb987068d00aec2147130f3464232a6bdccdf))
22
+ - check env before resetting ([abf6ea1](https://github.com/forcedotcom/sfdx-core/commit/abf6ea1bd721f773c09f346ff9ae8d01a915e5cd))
23
+
5
24
  ### [2.35.3](https://github.com/forcedotcom/sfdx-core/compare/v2.35.2...v2.35.3) (2022-02-23)
6
25
 
7
26
  ### Bug Fixes
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 sfdx.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
@@ -72,6 +72,17 @@ class Logger {
72
72
  * `Logger`.
73
73
  */
74
74
  constructor(optionsOrName) {
75
+ /**
76
+ * The default rotation period for logs. Example '1d' will rotate logs daily (at midnight).
77
+ * See 'period' docs here: https://github.com/forcedotcom/node-bunyan#stream-type-rotating-file
78
+ */
79
+ this.logRotationPeriod = new kit_1.Env().getString('SFDX_LOG_ROTATION_PERIOD') || '1d';
80
+ /**
81
+ * The number of backup rotated log files to keep.
82
+ * Example: '3' will have the base sfdx.log file, and the past 3 (period) log files.
83
+ * See 'count' docs here: https://github.com/forcedotcom/node-bunyan#stream-type-rotating-file
84
+ */
85
+ this.logRotationCount = new kit_1.Env().getNumber('SFDX_LOG_ROTATION_COUNT') || 2;
75
86
  /**
76
87
  * Whether debug is enabled for this Logger.
77
88
  */
@@ -250,12 +261,12 @@ class Logger {
250
261
  if (!this.bunyan.streams.find(
251
262
  // No bunyan typings
252
263
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
253
- (stream) => stream.type === 'file' && stream.path === logFile)) {
254
- // TODO: rotating-file
255
- // https://github.com/trentm/node-bunyan#stream-type-rotating-file
264
+ (stream) => stream.type === 'rotating-file' && stream.path === logFile)) {
256
265
  this.addStream({
257
- type: 'file',
266
+ type: 'rotating-file',
258
267
  path: logFile,
268
+ period: this.logRotationPeriod,
269
+ count: this.logRotationCount,
259
270
  level: this.bunyan.level(),
260
271
  });
261
272
  }
@@ -290,12 +301,12 @@ class Logger {
290
301
  if (!this.bunyan.streams.find(
291
302
  // No bunyan typings
292
303
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
293
- (stream) => stream.type === 'file' && stream.path === logFile)) {
294
- // TODO: rotating-file
295
- // https://github.com/trentm/node-bunyan#stream-type-rotating-file
304
+ (stream) => stream.type === 'rotating-file' && stream.path === logFile)) {
296
305
  this.addStream({
297
- type: 'file',
306
+ type: 'rotating-file',
298
307
  path: logFile,
308
+ period: this.logRotationPeriod,
309
+ count: this.logRotationCount,
299
310
  level: this.bunyan.level(),
300
311
  });
301
312
  }
package/lib/org.d.ts CHANGED
@@ -113,6 +113,17 @@ export declare class Org extends AsyncCreatable<Org.Options> {
113
113
  * @returns {ScratchOrgCreateResult}
114
114
  */
115
115
  scratchOrgCreate(options: ScratchOrgRequest): Promise<ScratchOrgCreateResult>;
116
+ /**
117
+ * Reports sandbox org creation status. If the org is ready, authenticates to the org.
118
+ *
119
+ * @param {sandboxname} string the sandbox name
120
+ * @param options Wait: The amount of time to wait before timing out, Interval: The time interval between polling
121
+ * @returns {SandboxProcessObject} the sandbox process object
122
+ */
123
+ sandboxStatus(sandboxname: string, options: {
124
+ wait?: Duration;
125
+ interval?: Duration;
126
+ }): Promise<SandboxProcessObject>;
116
127
  /**
117
128
  * Clean all data files in the org's data path. Usually <workspace>/.sfdx/orgs/<username>.
118
129
  *
@@ -264,6 +275,29 @@ export declare class Org extends AsyncCreatable<Org.Options> {
264
275
  * **Throws** *{@link SfdxError} Throws and unsupported error.
265
276
  */
266
277
  protected getDefaultOptions(): Org.Options;
278
+ /**
279
+ * Query the sandbox for the SandboxProcessObject by sandbox name
280
+ *
281
+ * @param sandboxName The name of the sandbox to query
282
+ * @returns {SandboxProcessObject} The SandboxProcessObject for the sandbox
283
+ */
284
+ private queryLatestSandboxProcessBySandboxName;
285
+ /**
286
+ * Gets the sandboxProcessObject and then polls for it to complete.
287
+ *
288
+ * @param sandboxProcessName sanbox process name
289
+ * @param options { wait?: Duration; interval?: Duration }
290
+ * @returns {SandboxProcessObject} The SandboxProcessObject for the sandbox
291
+ */
292
+ private authWithRetriesByName;
293
+ /**
294
+ * Polls the sandbox org for the sandboxProcessObject.
295
+ *
296
+ * @param sandboxProcessObj: The in-progress sandbox signup request
297
+ * @param options { wait?: Duration; interval?: Duration }
298
+ * @returns {SandboxProcessObject}
299
+ */
300
+ private authWithRetries;
267
301
  private queryProduction;
268
302
  /**
269
303
  * this method will delete the sandbox org from the production org and clean up any local files
package/lib/org.js CHANGED
@@ -110,6 +110,16 @@ class Org extends kit_1.AsyncCreatable {
110
110
  async scratchOrgCreate(options) {
111
111
  return scratchOrgCreate_1.scratchOrgCreate({ ...options, hubOrg: this });
112
112
  }
113
+ /**
114
+ * Reports sandbox org creation status. If the org is ready, authenticates to the org.
115
+ *
116
+ * @param {sandboxname} string the sandbox name
117
+ * @param options Wait: The amount of time to wait before timing out, Interval: The time interval between polling
118
+ * @returns {SandboxProcessObject} the sandbox process object
119
+ */
120
+ async sandboxStatus(sandboxname, options) {
121
+ return this.authWithRetriesByName(sandboxname, options);
122
+ }
113
123
  /**
114
124
  * Clean all data files in the org's data path. Usually <workspace>/.sfdx/orgs/<username>.
115
125
  *
@@ -500,6 +510,58 @@ class Org extends kit_1.AsyncCreatable {
500
510
  getDefaultOptions() {
501
511
  throw new sfdxError_1.SfdxError('Not Supported');
502
512
  }
513
+ /**
514
+ * Query the sandbox for the SandboxProcessObject by sandbox name
515
+ *
516
+ * @param sandboxName The name of the sandbox to query
517
+ * @returns {SandboxProcessObject} The SandboxProcessObject for the sandbox
518
+ */
519
+ async queryLatestSandboxProcessBySandboxName(sandboxNameIn) {
520
+ var _a;
521
+ const { tooling } = this.getConnection();
522
+ this.logger.debug('QueryLatestSandboxProcessBySandboxName called with SandboxName: %s ', sandboxNameIn);
523
+ const queryStr = `SELECT Id, Status, SandboxName, SandboxInfoId, LicenseType, CreatedDate, CopyProgress, SandboxOrganization, SourceId, Description, EndDate FROM SandboxProcess WHERE SandboxName='${sandboxNameIn}' AND Status != 'D' ORDER BY CreatedDate DESC LIMIT 1`;
524
+ const queryResult = await tooling.query(queryStr);
525
+ this.logger.debug('Return from calling queryToolingApi: %s ', queryResult);
526
+ if (((_a = queryResult === null || queryResult === void 0 ? void 0 : queryResult.records) === null || _a === void 0 ? void 0 : _a.length) === 1) {
527
+ return queryResult.records[0];
528
+ }
529
+ else if (queryResult.records && queryResult.records.length > 1) {
530
+ throw sfdxError_1.SfdxError.create('@salesforce/core', 'org', 'MultiSandboxProcessNotFoundBySandboxName', [sandboxNameIn]);
531
+ }
532
+ else {
533
+ throw sfdxError_1.SfdxError.create('@salesforce/core', 'org', 'SandboxProcessNotFoundBySandboxName', [sandboxNameIn]);
534
+ }
535
+ }
536
+ /**
537
+ * Gets the sandboxProcessObject and then polls for it to complete.
538
+ *
539
+ * @param sandboxProcessName sanbox process name
540
+ * @param options { wait?: Duration; interval?: Duration }
541
+ * @returns {SandboxProcessObject} The SandboxProcessObject for the sandbox
542
+ */
543
+ async authWithRetriesByName(sandboxProcessName, options) {
544
+ return this.authWithRetries(await this.queryLatestSandboxProcessBySandboxName(sandboxProcessName), options);
545
+ }
546
+ /**
547
+ * Polls the sandbox org for the sandboxProcessObject.
548
+ *
549
+ * @param sandboxProcessObj: The in-progress sandbox signup request
550
+ * @param options { wait?: Duration; interval?: Duration }
551
+ * @returns {SandboxProcessObject}
552
+ */
553
+ async authWithRetries(sandboxProcessObj, options) {
554
+ var _a;
555
+ const retries = options.wait ? options.wait.seconds / kit_1.Duration.seconds(30).seconds : 0;
556
+ const pollInterval = (_a = options.interval) !== null && _a !== void 0 ? _a : kit_1.Duration.seconds(30);
557
+ this.logger.debug('AuthWithRetries sandboxProcessObj %s, retries %i', sandboxProcessObj, retries);
558
+ return this.pollStatusAndAuth({
559
+ sandboxProcessObj,
560
+ retries,
561
+ shouldPoll: retries > 0,
562
+ pollInterval,
563
+ });
564
+ }
503
565
  async queryProduction(org, field, value) {
504
566
  return org.connection.singleRecordQuery(`SELECT SandboxInfoId FROM SandboxProcess WHERE ${field} ='${value}' AND Status NOT IN ('D', 'E')`, { tooling: true });
505
567
  }
@@ -62,7 +62,7 @@ export declare class SfdcUrl extends URL {
62
62
  isSandboxUrl(createdOrgInstance?: string): boolean;
63
63
  /**
64
64
  * Tests whether this url is a sandbox url
65
- * otherwise tryies to resolve dns cnames and then look if any is sandbox url
65
+ * otherwise tries to resolve dns cnames and then look if any is sandbox url
66
66
  *
67
67
  * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
68
68
  * @returns {Promise<boolean>} true if this domain resolves to sanbox url
@@ -156,13 +156,15 @@ class SfdcUrl extends url_1.URL {
156
156
  this.origin.endsWith('sandbox.my.salesforce.mil') ||
157
157
  /sandbox\.my\.salesforce\.com/gi.test(this.origin) || // enhanced domains >= 230
158
158
  /(cs[0-9]+(\.my|)\.salesforce\.com)/gi.test(this.origin) || // my domains on CS instance OR CS instance without my domain
159
+ /(cs[0-9]+\.force\.com)/gi.test(this.origin) || // sandboxes have cnames like cs123.force.com
160
+ /(\w+--\w+\.my\.salesforce\.com)/gi.test(this.origin) || // sandboxes myDomain like foo--bar.my.salesforce.com
159
161
  /([a-z]{3}[0-9]+s\.sfdc-.+\.salesforce\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
160
162
  /([a-z]{3}[0-9]+s\.sfdc-.+\.force\.com)/gi.test(this.origin) || // falcon sandbox ex: usa2s.sfdc-whatever.force.com
161
163
  this.hostname === 'test.salesforce.com');
162
164
  }
163
165
  /**
164
166
  * Tests whether this url is a sandbox url
165
- * otherwise tryies to resolve dns cnames and then look if any is sandbox url
167
+ * otherwise tries to resolve dns cnames and then look if any is sandbox url
166
168
  *
167
169
  * @param createdOrgInstance The Salesforce instance the org was created on. e.g. `cs42`
168
170
  * @returns {Promise<boolean>} true if this domain resolves to sanbox url
package/messages/org.json CHANGED
@@ -9,5 +9,7 @@
9
9
  "SandboxNotFound": "We can't find a SandboxProcess for the sandbox org %s.",
10
10
  "SandboxInfoCreateFailed": "The sandbox org creation failed with a result of %s.",
11
11
  "MissingAuthUsername": "The sandbox %s does not have an authorized username.",
12
- "OrgPollingTimeout": "Sandbox status is %s; timed out waiting for completion."
12
+ "OrgPollingTimeout": "Sandbox status is %s; timed out waiting for completion.",
13
+ "SandboxProcessNotFoundBySandboxName": "We can't find a SandboxProcess with the SandboxName %s.",
14
+ "MultiSandboxProcessNotFoundBySandboxName": "We found more than one SandboxProcess with the SandboxName %s."
13
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "2.35.3",
3
+ "version": "2.36.2",
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",
@@ -39,7 +39,7 @@
39
39
  "@salesforce/schemas": "^1.0.1",
40
40
  "@salesforce/ts-types": "^1.5.20",
41
41
  "@types/graceful-fs": "^4.1.5",
42
- "@types/jsforce": "^1.9.38",
42
+ "@types/jsforce": "^1.9.41",
43
43
  "@types/mkdirp": "^1.0.1",
44
44
  "archiver": "^5.3.0",
45
45
  "debug": "^3.1.0",