@salesforce/core 3.7.5 → 3.7.8

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +219 -0
  2. package/README.md +4 -4
  3. package/lib/config/config.d.ts +7 -5
  4. package/lib/config/config.js +14 -9
  5. package/lib/config/configAggregator.d.ts +2 -2
  6. package/lib/config/configAggregator.js +2 -2
  7. package/lib/config/configFile.d.ts +2 -2
  8. package/lib/config/configFile.js +22 -20
  9. package/lib/config/configStore.js +7 -6
  10. package/lib/config/keychainConfig.js +4 -3
  11. package/lib/crypto/keyChainImpl.js +12 -11
  12. package/lib/deviceOauthService.js +2 -2
  13. package/lib/exported.d.ts +6 -5
  14. package/lib/exported.js +11 -7
  15. package/lib/global.js +2 -2
  16. package/lib/globalInfo/accessors/aliasAccessor.js +2 -2
  17. package/lib/globalInfo/sfdxDataHandler.d.ts +1 -1
  18. package/lib/globalInfo/sfdxDataHandler.js +5 -4
  19. package/lib/lifecycleEvents.js +1 -1
  20. package/lib/logger.d.ts +3 -3
  21. package/lib/logger.js +20 -19
  22. package/lib/messages.d.ts +42 -3
  23. package/lib/messages.js +55 -12
  24. package/lib/org/authInfo.d.ts +1 -1
  25. package/lib/org/authInfo.js +8 -9
  26. package/lib/org/authRemover.d.ts +2 -2
  27. package/lib/org/authRemover.js +2 -2
  28. package/lib/org/connection.d.ts +7 -2
  29. package/lib/org/connection.js +17 -4
  30. package/lib/org/org.d.ts +16 -6
  31. package/lib/org/org.js +54 -51
  32. package/lib/org/permissionSetAssignment.js +2 -2
  33. package/lib/org/scratchOrgCreate.d.ts +43 -0
  34. package/lib/org/scratchOrgCreate.js +142 -0
  35. package/lib/org/scratchOrgErrorCodes.d.ts +4 -0
  36. package/lib/org/scratchOrgErrorCodes.js +62 -0
  37. package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -0
  38. package/lib/org/scratchOrgFeatureDeprecation.js +110 -0
  39. package/lib/org/scratchOrgInfoApi.d.ts +94 -0
  40. package/lib/org/scratchOrgInfoApi.js +350 -0
  41. package/lib/org/scratchOrgInfoGenerator.d.ts +63 -0
  42. package/lib/org/scratchOrgInfoGenerator.js +223 -0
  43. package/lib/org/scratchOrgSettingsGenerator.d.ts +56 -0
  44. package/lib/org/scratchOrgSettingsGenerator.js +210 -0
  45. package/lib/org/user.js +8 -7
  46. package/lib/schema/printer.js +2 -2
  47. package/lib/schema/validator.d.ts +4 -4
  48. package/lib/schema/validator.js +13 -13
  49. package/lib/{sfdxError.d.ts → sfError.d.ts} +14 -14
  50. package/lib/{sfdxError.js → sfError.js} +20 -21
  51. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +37 -27
  52. package/lib/{sfdxProject.js → sfProject.js} +77 -65
  53. package/lib/status/pollingClient.d.ts +2 -2
  54. package/lib/status/pollingClient.js +10 -4
  55. package/lib/status/streamingClient.d.ts +1 -1
  56. package/lib/status/streamingClient.js +6 -6
  57. package/lib/testSetup.d.ts +4 -4
  58. package/lib/testSetup.js +8 -8
  59. package/lib/util/internal.d.ts +28 -2
  60. package/lib/util/internal.js +64 -6
  61. package/lib/util/jsonXmlTools.d.ts +14 -0
  62. package/lib/util/jsonXmlTools.js +41 -0
  63. package/lib/util/mapKeys.d.ts +14 -0
  64. package/lib/util/mapKeys.js +48 -0
  65. package/lib/util/sfdcUrl.d.ts +2 -2
  66. package/lib/util/sfdcUrl.js +2 -2
  67. package/lib/util/zipWriter.d.ts +14 -0
  68. package/lib/util/zipWriter.js +68 -0
  69. package/lib/webOAuthServer.js +11 -11
  70. package/messages/org.md +4 -0
  71. package/messages/scratchOrgCreate.md +27 -0
  72. package/messages/scratchOrgErrorCodes.md +99 -0
  73. package/messages/scratchOrgFeatureDeprecation.md +11 -0
  74. package/messages/scratchOrgInfoApi.md +11 -0
  75. package/messages/scratchOrgInfoGenerator.md +19 -0
  76. package/messages/user.md +4 -0
  77. package/package.json +4 -1
  78. package/lib/util/fs.d.ts +0 -201
  79. package/lib/util/fs.js +0 -378
@@ -11,7 +11,7 @@ const kit_1 = require("@salesforce/kit");
11
11
  const ts_types_1 = require("@salesforce/ts-types");
12
12
  const ts_types_2 = require("@salesforce/ts-types");
13
13
  const crypto_1 = require("../crypto/crypto");
14
- const sfdxError_1 = require("../sfdxError");
14
+ const sfError_1 = require("../sfError");
15
15
  /**
16
16
  * An abstract class that implements all the config management functions but
17
17
  * none of the storage functions.
@@ -206,7 +206,8 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
206
206
  });
207
207
  }
208
208
  getEncryptedKeys() {
209
- return [...(this.options.encryptedKeys || []), ...(this.statics.encryptedKeys || [])];
209
+ var _a, _b;
210
+ return [...(((_a = this.options) === null || _a === void 0 ? void 0 : _a.encryptedKeys) || []), ...(((_b = this.statics) === null || _b === void 0 ? void 0 : _b.encryptedKeys) || [])];
210
211
  }
211
212
  /**
212
213
  * This config file has encrypted keys and it should attempt to encrypt them.
@@ -286,18 +287,18 @@ class BaseConfigStore extends kit_1.AsyncOptionalCreatable {
286
287
  if (!value)
287
288
  return;
288
289
  if (!this.crypto)
289
- throw new sfdxError_1.SfdxError('crypto is not initialized', 'CryptoNotInitializedError');
290
+ throw new sfError_1.SfError('crypto is not initialized', 'CryptoNotInitializedError');
290
291
  if (!(0, ts_types_2.isString)(value))
291
- throw new sfdxError_1.SfdxError(`can only encrypt strings but found: ${typeof value} : ${value}`, 'InvalidCryptoValueError');
292
+ throw new sfError_1.SfError(`can only encrypt strings but found: ${typeof value} : ${value}`, 'InvalidCryptoValueError');
292
293
  return this.crypto.isEncrypted(value) ? value : this.crypto.encrypt(value);
293
294
  }
294
295
  decrypt(value) {
295
296
  if (!value)
296
297
  return;
297
298
  if (!this.crypto)
298
- throw new sfdxError_1.SfdxError('crypto is not initialized', 'CryptoNotInitializedError');
299
+ throw new sfError_1.SfError('crypto is not initialized', 'CryptoNotInitializedError');
299
300
  if (!(0, ts_types_2.isString)(value))
300
- throw new sfdxError_1.SfdxError(`can only encrypt strings but found: ${typeof value} : ${value}`, 'InvalidCryptoValueError');
301
+ throw new sfError_1.SfError(`can only encrypt strings but found: ${typeof value} : ${value}`, 'InvalidCryptoValueError');
301
302
  return this.crypto.isEncrypted(value) ? this.crypto.decrypt(value) : value;
302
303
  }
303
304
  /**
@@ -8,7 +8,8 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.KeychainConfig = void 0;
10
10
  const path_1 = require("path");
11
- const fs_1 = require("../util/fs");
11
+ const fs = require("fs");
12
+ const mkdirp = require("mkdirp");
12
13
  const configFile_1 = require("./configFile");
13
14
  /**
14
15
  * Represent a key chain config backed by a json file.
@@ -34,8 +35,8 @@ class KeychainConfig extends configFile_1.ConfigFile {
34
35
  if (newContents != null) {
35
36
  this.setContents(newContents);
36
37
  }
37
- await fs_1.fs.mkdirp((0, path_1.dirname)(this.getPath()));
38
- await fs_1.fs.writeFile(this.getPath(), JSON.stringify(this.getContents(), null, 4), { mode: '600' });
38
+ await mkdirp((0, path_1.dirname)(this.getPath()));
39
+ await fs.promises.writeFile(this.getPath(), JSON.stringify(this.getContents(), null, 4), { mode: '600' });
39
40
  return this.getContents();
40
41
  }
41
42
  }
@@ -9,12 +9,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.keyChainImpl = exports.GenericWindowsKeychainAccess = exports.GenericUnixKeychainAccess = exports.GenericKeychainAccess = exports.KeychainAccess = void 0;
10
10
  const childProcess = require("child_process");
11
11
  const nodeFs = require("fs");
12
+ const fs = require("fs");
12
13
  const os = require("os");
13
- const path = require("path");
14
14
  const os_1 = require("os");
15
+ const path = require("path");
15
16
  const ts_types_1 = require("@salesforce/ts-types");
17
+ const kit_1 = require("@salesforce/kit");
18
+ const mkdirp = require("mkdirp");
16
19
  const global_1 = require("../global");
17
- const fs_1 = require("../util/fs");
18
20
  const messages_1 = require("../messages");
19
21
  messages_1.Messages.importMessagesDirectory(__dirname);
20
22
  const messages = messages_1.Messages.load('@salesforce/core', 'encryption', [
@@ -58,9 +60,9 @@ const _isExe = (mode, gid, uid) => {
58
60
  /**
59
61
  * Private helper to validate that a program exists on the file system and is executable.
60
62
  *
61
- * **Throws** *{@link SfdxError}{ name: 'MissingCredentialProgramError' }* When the OS credential program isn't found.
63
+ * **Throws** *{@link SfError}{ name: 'MissingCredentialProgramError' }* When the OS credential program isn't found.
62
64
  *
63
- * **Throws** *{@link SfdxError}{ name: 'CredentialProgramAccessError' }* When the OS credential program isn't accessible.
65
+ * **Throws** *{@link SfError}{ name: 'CredentialProgramAccessError' }* When the OS credential program isn't accessible.
64
66
  *
65
67
  * @param programPath The absolute path of the program.
66
68
  * @param fsIfc The file system interface.
@@ -216,7 +218,6 @@ const _linuxImpl = {
216
218
  // This is a workaround for linux.
217
219
  // Calling secret-tool too fast can cause it to return an unexpected error. (below)
218
220
  if (stderr != null && stderr.includes('invalid or unencryptable secret')) {
219
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
220
221
  // @ts-ignore TODO: make an error subclass with this field
221
222
  error.retry = true;
222
223
  // Throwing here allows us to perform a retry in KeychainAccess
@@ -330,8 +331,8 @@ async function _writeFile(opts, fn) {
330
331
  [SecretField.KEY]: opts.password,
331
332
  [SecretField.SERVICE]: opts.service,
332
333
  };
333
- await fs_1.fs.mkdirp(path.dirname(secretFile));
334
- await fs_1.fs.writeFile(secretFile, JSON.stringify(contents, null, 4), { mode: '600' });
334
+ await mkdirp(path.dirname(secretFile));
335
+ await fs.promises.writeFile(secretFile, JSON.stringify(contents, null, 4), { mode: '600' });
335
336
  fn(null, contents);
336
337
  }
337
338
  catch (err) {
@@ -340,7 +341,7 @@ async function _writeFile(opts, fn) {
340
341
  }
341
342
  async function _readFile() {
342
343
  // The file and access is validated before this method is called
343
- const fileContents = await fs_1.fs.readJsonMap(secretFile);
344
+ const fileContents = (0, kit_1.parseJsonMap)(await fs.promises.readFile(secretFile, 'utf8'));
344
345
  return {
345
346
  account: (0, ts_types_1.ensureString)(fileContents[SecretField.ACCOUNT]),
346
347
  password: (0, ts_types_1.asString)(fileContents[SecretField.KEY]),
@@ -407,7 +408,7 @@ class GenericKeychainAccess {
407
408
  async isValidFileAccess(cb) {
408
409
  try {
409
410
  const root = (0, os_1.homedir)();
410
- await fs_1.fs.access(path.join(root, global_1.Global.SFDX_STATE_FOLDER), fs_1.fs.constants.R_OK | fs_1.fs.constants.X_OK | fs_1.fs.constants.W_OK);
411
+ await fs.promises.access(path.join(root, global_1.Global.SFDX_STATE_FOLDER), fs.constants.R_OK | fs.constants.X_OK | fs.constants.W_OK);
411
412
  await cb(null);
412
413
  }
413
414
  catch (err) {
@@ -427,7 +428,7 @@ class GenericUnixKeychainAccess extends GenericKeychainAccess {
427
428
  await cb(err);
428
429
  }
429
430
  else {
430
- const stats = await fs_1.fs.stat(secretFile);
431
+ const stats = await fs.promises.stat(secretFile);
431
432
  const octalModeStr = (stats.mode & 0o777).toString(8);
432
433
  const EXPECTED_OCTAL_PERM_VALUE = '600';
433
434
  if (octalModeStr === EXPECTED_OCTAL_PERM_VALUE) {
@@ -452,7 +453,7 @@ class GenericWindowsKeychainAccess extends GenericKeychainAccess {
452
453
  }
453
454
  else {
454
455
  try {
455
- await fs_1.fs.access(secretFile, fs_1.fs.constants.R_OK | fs_1.fs.constants.W_OK);
456
+ await fs.promises.access(secretFile, fs.constants.R_OK | fs.constants.W_OK);
456
457
  await cb(null);
457
458
  }
458
459
  catch (e) {
@@ -15,7 +15,7 @@ const kit_1 = require("@salesforce/kit");
15
15
  const ts_types_1 = require("@salesforce/ts-types");
16
16
  const logger_1 = require("./logger");
17
17
  const authInfo_1 = require("./org/authInfo");
18
- const sfdxError_1 = require("./sfdxError");
18
+ const sfError_1 = require("./sfError");
19
19
  const connection_1 = require("./org/connection");
20
20
  const messages_1 = require("./messages");
21
21
  messages_1.Messages.importMessagesDirectory(__dirname);
@@ -29,7 +29,7 @@ async function makeRequest(options) {
29
29
  const rawResponse = await new transport_1.default().httpRequest(options);
30
30
  const response = (0, kit_1.parseJsonMap)(rawResponse.body);
31
31
  if (response.error) {
32
- const err = new sfdxError_1.SfdxError('Request Failed.');
32
+ const err = new sfError_1.SfError('Request Failed.');
33
33
  err.data = Object.assign(response, { status: rawResponse.statusCode });
34
34
  throw err;
35
35
  }
package/lib/exported.d.ts CHANGED
@@ -16,18 +16,19 @@ export { WebOAuthServer } from './webOAuthServer';
16
16
  export { SfdcUrl } from './util/sfdcUrl';
17
17
  export { getJwtAudienceUrl } from './util/getJwtAudienceUrl';
18
18
  export { Fields, FieldValue, LoggerLevel, LoggerLevelValue, LogLine, LoggerOptions, LoggerStream, Logger, } from './logger';
19
- export { Messages } from './messages';
20
- export { Org, SandboxProcessObject, StatusEvent, SandboxEvents, SandboxUserAuthResponse, SandboxUserAuthRequest, SandboxRequest, OrgTypes, ResultEvent, } from './org';
19
+ export { Messages, StructuredMessage } from './messages';
20
+ export { Org, SandboxProcessObject, StatusEvent, SandboxEvents, SandboxUserAuthResponse, SandboxUserAuthRequest, SandboxRequest, OrgTypes, ResultEvent, ScratchOrgRequest, } from './org';
21
21
  export { OrgConfigProperties, ORG_CONFIG_ALLOWED_PROPERTIES } from './org/orgConfigProperties';
22
- export { PackageDir, NamedPackageDir, PackageDirDependency, SfdxProject, SfdxProjectJson } from './sfdxProject';
22
+ export { PackageDir, NamedPackageDir, PackageDirDependency, SfProject, SfProjectJson, SfdxProject, SfdxProjectJson, } from './sfProject';
23
23
  export { SchemaPrinter } from './schema/printer';
24
24
  export { SchemaValidator } from './schema/validator';
25
- export { SfdxError } from './sfdxError';
25
+ export { SfError, SfdxError } from './sfError';
26
26
  export { PollingClient } from './status/pollingClient';
27
27
  export { CometClient, CometSubscription, StreamingClient, StatusResult } from './status/streamingClient';
28
28
  export { MyDomainResolver } from './status/myDomainResolver';
29
29
  export { DefaultUserFields, REQUIRED_FIELDS, User, UserFields } from './org/user';
30
30
  export { PermissionSetAssignment, PermissionSetAssignmentFields } from './org/permissionSetAssignment';
31
- export * from './util/fs';
31
+ export { ScratchOrgCreateOptions, ScratchOrgCreateResult, scratchOrgCreate } from './org/scratchOrgCreate';
32
+ export { ScratchOrgInfo } from './org/scratchOrgInfoApi';
32
33
  export * from './util/sfdc';
33
34
  export * from './util/sfdcUrl';
package/lib/exported.js CHANGED
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = exports.MyDomainResolver = exports.StreamingClient = exports.CometClient = exports.PollingClient = exports.SfdxError = exports.SchemaValidator = exports.SchemaPrinter = exports.SfdxProjectJson = exports.SfdxProject = 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.ConfigFile = void 0;
20
20
  const messages_1 = require("./messages");
21
21
  messages_1.Messages.importMessagesDirectory(__dirname);
22
22
  var configFile_1 = require("./config/configFile");
@@ -71,15 +71,18 @@ Object.defineProperty(exports, "OrgTypes", { enumerable: true, get: function ()
71
71
  var orgConfigProperties_1 = require("./org/orgConfigProperties");
72
72
  Object.defineProperty(exports, "OrgConfigProperties", { enumerable: true, get: function () { return orgConfigProperties_1.OrgConfigProperties; } });
73
73
  Object.defineProperty(exports, "ORG_CONFIG_ALLOWED_PROPERTIES", { enumerable: true, get: function () { return orgConfigProperties_1.ORG_CONFIG_ALLOWED_PROPERTIES; } });
74
- var sfdxProject_1 = require("./sfdxProject");
75
- Object.defineProperty(exports, "SfdxProject", { enumerable: true, get: function () { return sfdxProject_1.SfdxProject; } });
76
- Object.defineProperty(exports, "SfdxProjectJson", { enumerable: true, get: function () { return sfdxProject_1.SfdxProjectJson; } });
74
+ var sfProject_1 = require("./sfProject");
75
+ Object.defineProperty(exports, "SfProject", { enumerable: true, get: function () { return sfProject_1.SfProject; } });
76
+ Object.defineProperty(exports, "SfProjectJson", { enumerable: true, get: function () { return sfProject_1.SfProjectJson; } });
77
+ Object.defineProperty(exports, "SfdxProject", { enumerable: true, get: function () { return sfProject_1.SfdxProject; } });
78
+ Object.defineProperty(exports, "SfdxProjectJson", { enumerable: true, get: function () { return sfProject_1.SfdxProjectJson; } });
77
79
  var printer_1 = require("./schema/printer");
78
80
  Object.defineProperty(exports, "SchemaPrinter", { enumerable: true, get: function () { return printer_1.SchemaPrinter; } });
79
81
  var validator_1 = require("./schema/validator");
80
82
  Object.defineProperty(exports, "SchemaValidator", { enumerable: true, get: function () { return validator_1.SchemaValidator; } });
81
- var sfdxError_1 = require("./sfdxError");
82
- Object.defineProperty(exports, "SfdxError", { enumerable: true, get: function () { return sfdxError_1.SfdxError; } });
83
+ var sfError_1 = require("./sfError");
84
+ Object.defineProperty(exports, "SfError", { enumerable: true, get: function () { return sfError_1.SfError; } });
85
+ Object.defineProperty(exports, "SfdxError", { enumerable: true, get: function () { return sfError_1.SfdxError; } });
83
86
  var pollingClient_1 = require("./status/pollingClient");
84
87
  Object.defineProperty(exports, "PollingClient", { enumerable: true, get: function () { return pollingClient_1.PollingClient; } });
85
88
  var streamingClient_1 = require("./status/streamingClient");
@@ -93,8 +96,9 @@ Object.defineProperty(exports, "REQUIRED_FIELDS", { enumerable: true, get: funct
93
96
  Object.defineProperty(exports, "User", { enumerable: true, get: function () { return user_1.User; } });
94
97
  var permissionSetAssignment_1 = require("./org/permissionSetAssignment");
95
98
  Object.defineProperty(exports, "PermissionSetAssignment", { enumerable: true, get: function () { return permissionSetAssignment_1.PermissionSetAssignment; } });
99
+ var scratchOrgCreate_1 = require("./org/scratchOrgCreate");
100
+ Object.defineProperty(exports, "scratchOrgCreate", { enumerable: true, get: function () { return scratchOrgCreate_1.scratchOrgCreate; } });
96
101
  // Utility sub-modules
97
- __exportStar(require("./util/fs"), exports);
98
102
  __exportStar(require("./util/sfdc"), exports);
99
103
  __exportStar(require("./util/sfdcUrl"), exports);
100
104
  //# sourceMappingURL=exported.js.map
package/lib/global.js CHANGED
@@ -10,7 +10,7 @@ exports.Global = exports.Mode = void 0;
10
10
  const os = require("os");
11
11
  const path = require("path");
12
12
  const kit_1 = require("@salesforce/kit");
13
- const fs_1 = require("./util/fs");
13
+ const mkdirp = require("mkdirp");
14
14
  /**
15
15
  * Represents an environment mode. Supports `production`, `development`, `demo`, and `test`
16
16
  * with the default mode being `production`.
@@ -46,7 +46,7 @@ class Global {
46
46
  */
47
47
  static async createDir(dirPath) {
48
48
  dirPath = dirPath ? path.join(Global.SFDX_DIR, dirPath) : Global.SFDX_DIR;
49
- await fs_1.fs.mkdirp(dirPath, fs_1.fs.DEFAULT_USER_DIR_MODE);
49
+ await mkdirp(dirPath, '700');
50
50
  }
51
51
  }
52
52
  exports.Global = Global;
@@ -7,7 +7,7 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.AliasAccessor = void 0;
10
- const sfdxError_1 = require("../../sfdxError");
10
+ const sfError_1 = require("../../sfError");
11
11
  const types_1 = require("../types");
12
12
  class AliasAccessor {
13
13
  constructor(globalInfo) {
@@ -121,7 +121,7 @@ class AliasAccessor {
121
121
  return entity;
122
122
  const aliaseeName = (_a = entity.username) !== null && _a !== void 0 ? _a : entity.user;
123
123
  if (!aliaseeName) {
124
- throw new sfdxError_1.SfdxError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
124
+ throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
125
125
  }
126
126
  return aliaseeName;
127
127
  }
@@ -1,5 +1,5 @@
1
1
  import { ConfigFile } from '../config/configFile';
2
- import { SfOrgs, SfOrg, SfInfo, SfInfoKeys } from './types';
2
+ import { SfInfo, SfInfoKeys, SfOrg, SfOrgs } from './types';
3
3
  interface Handler<T extends SfInfoKeys> {
4
4
  sfKey: T;
5
5
  merge: (sfData: SfInfo) => Promise<Partial<SfInfo>>;
@@ -8,10 +8,10 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.AliasesHandler = exports.AuthHandler = exports.SfdxDataHandler = void 0;
10
10
  const path_1 = require("path");
11
+ const fs = require("fs");
11
12
  const kit_1 = require("@salesforce/kit");
12
13
  const ts_types_1 = require("@salesforce/ts-types");
13
14
  const global_1 = require("../global");
14
- const fs_1 = require("../util/fs");
15
15
  const configFile_1 = require("../config/configFile");
16
16
  const globalInfoConfig_1 = require("./globalInfoConfig");
17
17
  const types_1 = require("./types");
@@ -141,7 +141,7 @@ class AuthHandler extends BaseHandler {
141
141
  return config;
142
142
  }
143
143
  async listAllAuthFiles() {
144
- const globalFiles = await fs_1.fs.readdir(global_1.Global.SFDX_DIR);
144
+ const globalFiles = await fs.promises.readdir(global_1.Global.SFDX_DIR);
145
145
  return globalFiles.filter((file) => file.match(AuthHandler.authFilenameFilterRegEx));
146
146
  }
147
147
  async listAllAuthorizations() {
@@ -169,7 +169,8 @@ class AliasesHandler extends BaseHandler {
169
169
  async migrate() {
170
170
  const aliasesFilePath = (0, path_1.join)(global_1.Global.SFDX_DIR, AliasesHandler.SFDX_ALIASES_FILENAME);
171
171
  try {
172
- const sfdxAliases = (await fs_1.fs.readJson(aliasesFilePath)).orgs;
172
+ const x = await fs.promises.readFile(aliasesFilePath, 'utf8');
173
+ const sfdxAliases = (0, kit_1.parseJson)(x).orgs;
173
174
  return { [this.sfKey]: { ...sfdxAliases } };
174
175
  }
175
176
  catch (e) {
@@ -209,7 +210,7 @@ class AliasesHandler extends BaseHandler {
209
210
  }
210
211
  async write(latest) {
211
212
  const aliasesFilePath = (0, path_1.join)(global_1.Global.SFDX_DIR, AliasesHandler.SFDX_ALIASES_FILENAME);
212
- fs_1.fs.writeJson(aliasesFilePath, { orgs: latest[types_1.SfInfoKeys.ALIASES] });
213
+ await fs.promises.writeFile(aliasesFilePath, JSON.stringify({ orgs: latest[types_1.SfInfoKeys.ALIASES] }, null, 2));
213
214
  }
214
215
  }
215
216
  exports.AliasesHandler = AliasesHandler;
@@ -170,7 +170,7 @@ class Lifecycle {
170
170
  */
171
171
  async emit(eventName, data) {
172
172
  const listeners = this.getListeners(eventName);
173
- if (listeners.length === 0) {
173
+ if (listeners.length === 0 && eventName !== Lifecycle.warningEventName) {
174
174
  this.debug(`A lifecycle event with the name ${eventName} does not exist. An event must be registered before it can be emitted.`);
175
175
  }
176
176
  else {
package/lib/logger.d.ts CHANGED
@@ -174,7 +174,7 @@ export declare class Logger {
174
174
  *
175
175
  * @param optionsOrName A set of `LoggerOptions` or name to use with the default options.
176
176
  *
177
- * **Throws** *{@link SfdxError}{ name: 'RedundantRootLoggerError' }* More than one attempt is made to construct the root
177
+ * **Throws** *{@link SfError}{ name: 'RedundantRootLoggerError' }* More than one attempt is made to construct the root
178
178
  * `Logger`.
179
179
  */
180
180
  constructor(optionsOrName: LoggerOptions | string);
@@ -211,7 +211,7 @@ export declare class Logger {
211
211
  *
212
212
  * @param {string} levelName The level name to convert to a `LoggerLevel` enum value.
213
213
  *
214
- * **Throws** *{@link SfdxError}{ name: 'UnrecognizedLoggerLevelNameError' }* The level name was not case-insensitively recognized as a valid `LoggerLevel` value.
214
+ * **Throws** *{@link SfError}{ name: 'UnrecognizedLoggerLevelNameError' }* The level name was not case-insensitively recognized as a valid `LoggerLevel` value.
215
215
  * @see {@Link LoggerLevel}
216
216
  */
217
217
  static getLevelByName(levelName: string): LoggerLevelValue;
@@ -249,7 +249,7 @@ export declare class Logger {
249
249
  *
250
250
  * @param {LoggerLevelValue} [level] The logger level.
251
251
  *
252
- * **Throws** *{@link SfdxError}{ name: 'UnrecognizedLoggerLevelNameError' }* A value of `level` read from `SFDX_LOG_LEVEL`
252
+ * **Throws** *{@link SfError}{ name: 'UnrecognizedLoggerLevelNameError' }* A value of `level` read from `SFDX_LOG_LEVEL`
253
253
  * was invalid.
254
254
  *
255
255
  * ```
package/lib/logger.js CHANGED
@@ -11,15 +11,16 @@ const events_1 = require("events");
11
11
  const os = require("os");
12
12
  const path = require("path");
13
13
  const stream_1 = require("stream");
14
+ const fs = require("fs");
14
15
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
15
16
  // @ts-ignore
16
17
  const Bunyan = require("@salesforce/bunyan");
17
18
  const kit_1 = require("@salesforce/kit");
18
19
  const ts_types_1 = require("@salesforce/ts-types");
19
20
  const Debug = require("debug");
21
+ const mkdirp = require("mkdirp");
20
22
  const global_1 = require("./global");
21
- const sfdxError_1 = require("./sfdxError");
22
- const fs_1 = require("./util/fs");
23
+ const sfError_1 = require("./sfError");
23
24
  /**
24
25
  * Standard `Logger` levels.
25
26
  *
@@ -69,7 +70,7 @@ class Logger {
69
70
  *
70
71
  * @param optionsOrName A set of `LoggerOptions` or name to use with the default options.
71
72
  *
72
- * **Throws** *{@link SfdxError}{ name: 'RedundantRootLoggerError' }* More than one attempt is made to construct the root
73
+ * **Throws** *{@link SfError}{ name: 'RedundantRootLoggerError' }* More than one attempt is made to construct the root
73
74
  * `Logger`.
74
75
  */
75
76
  constructor(optionsOrName) {
@@ -103,7 +104,7 @@ class Logger {
103
104
  options = optionsOrName;
104
105
  }
105
106
  if (Logger.rootLogger && options.name === Logger.ROOT_NAME) {
106
- throw new sfdxError_1.SfdxError('Can not create another root logger.', 'RedundantRootLoggerError');
107
+ throw new sfError_1.SfError('Can not create another root logger.', 'RedundantRootLoggerError');
107
108
  }
108
109
  // Inspect format to know what logging format to use then delete from options to
109
110
  // ensure it doesn't conflict with Bunyan.
@@ -199,13 +200,13 @@ class Logger {
199
200
  *
200
201
  * @param {string} levelName The level name to convert to a `LoggerLevel` enum value.
201
202
  *
202
- * **Throws** *{@link SfdxError}{ name: 'UnrecognizedLoggerLevelNameError' }* The level name was not case-insensitively recognized as a valid `LoggerLevel` value.
203
+ * **Throws** *{@link SfError}{ name: 'UnrecognizedLoggerLevelNameError' }* The level name was not case-insensitively recognized as a valid `LoggerLevel` value.
203
204
  * @see {@Link LoggerLevel}
204
205
  */
205
206
  static getLevelByName(levelName) {
206
207
  levelName = levelName.toUpperCase();
207
208
  if (!(0, ts_types_1.isKeyOf)(LoggerLevel, levelName)) {
208
- throw new sfdxError_1.SfdxError(`Invalid log level "${levelName}".`, 'UnrecognizedLoggerLevelNameError');
209
+ throw new sfError_1.SfError(`Invalid log level "${levelName}".`, 'UnrecognizedLoggerLevelNameError');
209
210
  }
210
211
  return LoggerLevel[levelName];
211
212
  }
@@ -229,22 +230,22 @@ class Logger {
229
230
  async addLogFileStream(logFile) {
230
231
  try {
231
232
  // Check if we have write access to the log file (i.e., we created it already)
232
- await fs_1.fs.access(logFile, fs_1.fs.constants.W_OK);
233
+ await fs.promises.access(logFile, fs.constants.W_OK);
233
234
  }
234
235
  catch (err1) {
235
236
  try {
236
- await fs_1.fs.mkdirp(path.dirname(logFile), {
237
- mode: fs_1.fs.DEFAULT_USER_DIR_MODE,
237
+ await mkdirp(path.dirname(logFile), {
238
+ mode: '700',
238
239
  });
239
240
  }
240
241
  catch (err2) {
241
242
  // noop; directory exists already
242
243
  }
243
244
  try {
244
- await fs_1.fs.writeFile(logFile, '', { mode: fs_1.fs.DEFAULT_USER_FILE_MODE });
245
+ await fs.promises.writeFile(logFile, '', { mode: '600' });
245
246
  }
246
247
  catch (err3) {
247
- throw sfdxError_1.SfdxError.wrap(err3);
248
+ throw sfError_1.SfError.wrap(err3);
248
249
  }
249
250
  }
250
251
  // avoid multiple streams to same log file
@@ -269,22 +270,22 @@ class Logger {
269
270
  addLogFileStreamSync(logFile) {
270
271
  try {
271
272
  // Check if we have write access to the log file (i.e., we created it already)
272
- fs_1.fs.accessSync(logFile, fs_1.fs.constants.W_OK);
273
+ fs.accessSync(logFile, fs.constants.W_OK);
273
274
  }
274
275
  catch (err1) {
275
276
  try {
276
- fs_1.fs.mkdirpSync(path.dirname(logFile), {
277
- mode: fs_1.fs.DEFAULT_USER_DIR_MODE,
277
+ mkdirp.sync(path.dirname(logFile), {
278
+ mode: '700',
278
279
  });
279
280
  }
280
281
  catch (err2) {
281
282
  // noop; directory exists already
282
283
  }
283
284
  try {
284
- fs_1.fs.writeFileSync(logFile, '', { mode: fs_1.fs.DEFAULT_USER_FILE_MODE });
285
+ fs.writeFileSync(logFile, '', { mode: '600' });
285
286
  }
286
287
  catch (err3) {
287
- throw sfdxError_1.SfdxError.wrap(err3);
288
+ throw sfError_1.SfError.wrap(err3);
288
289
  }
289
290
  }
290
291
  // avoid multiple streams to same log file
@@ -320,7 +321,7 @@ class Logger {
320
321
  *
321
322
  * @param {LoggerLevelValue} [level] The logger level.
322
323
  *
323
- * **Throws** *{@link SfdxError}{ name: 'UnrecognizedLoggerLevelNameError' }* A value of `level` read from `SFDX_LOG_LEVEL`
324
+ * **Throws** *{@link SfError}{ name: 'UnrecognizedLoggerLevelNameError' }* A value of `level` read from `SFDX_LOG_LEVEL`
324
325
  * was invalid.
325
326
  *
326
327
  * ```
@@ -401,7 +402,7 @@ class Logger {
401
402
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
402
403
  this.bunyan.streams.forEach(async (stream) => {
403
404
  if (stream.type === 'file') {
404
- content += await fs_1.fs.readFile(stream.path, 'utf8');
405
+ content += await fs.promises.readFile(stream.path, 'utf8');
405
406
  }
406
407
  });
407
408
  return content;
@@ -453,7 +454,7 @@ class Logger {
453
454
  */
454
455
  child(name, fields = {}) {
455
456
  if (!name) {
456
- throw new sfdxError_1.SfdxError('LoggerNameRequired');
457
+ throw new sfError_1.SfError('LoggerNameRequired');
457
458
  }
458
459
  fields.log = name;
459
460
  const child = new Logger(name);
package/lib/messages.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { AnyJson } from '@salesforce/ts-types';
2
- import { SfdxError } from './sfdxError';
2
+ import { SfError } from './sfError';
3
3
  export declare type Tokens = Array<string | boolean | number | null | undefined>;
4
+ export declare type StructuredMessage = {
5
+ message: string;
6
+ name: string;
7
+ actions?: string[];
8
+ };
4
9
  /**
5
10
  * A loader function to return messages.
6
11
  *
@@ -244,9 +249,43 @@ export declare class Messages<T extends string> {
244
249
  * @param key The key of the error message.
245
250
  * @param tokens The error message tokens.
246
251
  * @param actionTokens The action messages tokens.
247
- * @param exitCodeOrCause The exit code which will be used by SfdxCommand or he underlying error that caused this error to be raised.
252
+ * @param exitCodeOrCause The exit code which will be used by SfdxCommand or the underlying error that caused this error to be raised.
248
253
  * @param cause The underlying error that caused this error to be raised.
249
254
  */
250
- createError(key: T, tokens?: Tokens, actionTokens?: Tokens, exitCodeOrCause?: number | Error, cause?: Error): SfdxError;
255
+ createError(key: T, tokens?: Tokens, actionTokens?: Tokens, exitCodeOrCause?: number | Error, cause?: Error): SfError;
256
+ /**
257
+ * Convenience method to create warning using message labels.
258
+ *
259
+ * `warning.name` will be the upper-cased key, remove prefixed `warning.` and will always end in Warning.
260
+ * `warning.actions` will be loaded using `${key}.actions` if available.
261
+ *
262
+ * @param key The key of the warning message.
263
+ * @param tokens The warning message tokens.
264
+ * @param actionTokens The action messages tokens.
265
+ */
266
+ createWarning(key: T, tokens?: Tokens, actionTokens?: Tokens): StructuredMessage;
267
+ /**
268
+ * Convenience method to create info using message labels.
269
+ *
270
+ * `info.name` will be the upper-cased key, remove prefixed `info.` and will always end in Info.
271
+ * `info.actions` will be loaded using `${key}.actions` if available.
272
+ *
273
+ * @param key The key of the warning message.
274
+ * @param tokens The warning message tokens.
275
+ * @param actionTokens The action messages tokens.
276
+ */
277
+ createInfo(key: T, tokens?: Tokens, actionTokens?: Tokens): StructuredMessage;
278
+ /**
279
+ * Formats message contents given a message type, key, tokens and actions tokens
280
+ *
281
+ * `<type>.name` will be the upper-cased key, remove prefixed `<type>.` and will always end in 'Error | Warning | Info.
282
+ * `<type>.actions` will be loaded using `${key}.actions` if available.
283
+ *
284
+ * @param type The type of the message set must 'error' | 'warning' | 'info'.
285
+ * @param key The key of the warning message.
286
+ * @param tokens The warning message tokens.
287
+ * @param actionTokens The action messages tokens.
288
+ */
289
+ private formatMessageContents;
251
290
  private getMessageWithMap;
252
291
  }