@salesforce/core 3.7.7 → 3.8.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,24 @@
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.8.0](https://github.com/forcedotcom/sfdx-core/compare/v3.7.9...v3.8.0) (2022-03-09)
6
+
7
+ ### Features
8
+
9
+ - add handle side effect function to authinfo ([64c78e7](https://github.com/forcedotcom/sfdx-core/commit/64c78e74bc5e1cfb748fd2d64e4b1e8fc1062bf6))
10
+
11
+ ### [3.7.9](https://github.com/forcedotcom/sfdx-core/compare/v3.7.8...v3.7.9) (2022-03-04)
12
+
13
+ ### Bug Fixes
14
+
15
+ - error literal to match the error thrown ([#533](https://github.com/forcedotcom/sfdx-core/issues/533)) ([b91ce5c](https://github.com/forcedotcom/sfdx-core/commit/b91ce5c329c9b2b88fb4b0ad028aee5f6d5b6e77))
16
+
17
+ ### [3.7.8](https://github.com/forcedotcom/sfdx-core/compare/v3.7.7...v3.7.8) (2022-03-03)
18
+
19
+ ### Bug Fixes
20
+
21
+ - add create warning and info convenience functions ([#526](https://github.com/forcedotcom/sfdx-core/issues/526)) ([e3428b3](https://github.com/forcedotcom/sfdx-core/commit/e3428b35e00b9cee3c90153ed6ce08b352535ff7))
22
+
5
23
  ### [3.7.7](https://github.com/forcedotcom/sfdx-core/compare/v3.7.6...v3.7.7) (2022-03-01)
6
24
 
7
25
  ### [3.7.6](https://github.com/forcedotcom/sfdx-core/compare/v4.0.0...v3.7.6) (2022-02-28)
@@ -56,12 +56,14 @@ export declare enum SfdxPropertyKeys {
56
56
  * Username associated with the default dev hub org.
57
57
  *
58
58
  * @deprecated Replaced by OrgConfigProperties.TARGET_DEV_HUB in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
59
+ * will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
59
60
  */
60
61
  DEFAULT_DEV_HUB_USERNAME = "defaultdevhubusername",
61
62
  /**
62
63
  * Username associate with the default org.
63
64
  *
64
65
  * @deprecated Replaced by OrgConfigProperties.TARGET_ORG in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
66
+ * will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
65
67
  */
66
68
  DEFAULT_USERNAME = "defaultusername",
67
69
  /**
@@ -8,13 +8,14 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Config = exports.SfProperty = exports.SFDX_ALLOWED_PROPERTIES = exports.SfdxPropertyKeys = 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");
14
+ const mkdirp = require("mkdirp");
13
15
  const global_1 = require("../global");
14
16
  const logger_1 = require("../logger");
15
17
  const messages_1 = require("../messages");
16
18
  const sfdc_1 = require("../util/sfdc");
17
- const fs_1 = require("../util/fs");
18
19
  const sfdcUrl_1 = require("../util/sfdcUrl");
19
20
  const orgConfigProperties_1 = require("../org/orgConfigProperties");
20
21
  const configFile_1 = require("./configFile");
@@ -49,12 +50,14 @@ var SfdxPropertyKeys;
49
50
  * Username associated with the default dev hub org.
50
51
  *
51
52
  * @deprecated Replaced by OrgConfigProperties.TARGET_DEV_HUB in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
53
+ * will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
52
54
  */
53
55
  SfdxPropertyKeys["DEFAULT_DEV_HUB_USERNAME"] = "defaultdevhubusername";
54
56
  /**
55
57
  * Username associate with the default org.
56
58
  *
57
59
  * @deprecated Replaced by OrgConfigProperties.TARGET_ORG in v3 {@link https://github.com/forcedotcom/sfdx-core/blob/v3/MIGRATING_V2-V3.md#config}
60
+ * will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
58
61
  */
59
62
  SfdxPropertyKeys["DEFAULT_USERNAME"] = "defaultusername";
60
63
  /**
@@ -115,12 +118,14 @@ exports.SFDX_ALLOWED_PROPERTIES = [
115
118
  },
116
119
  },
117
120
  {
121
+ // will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
118
122
  key: SfdxPropertyKeys.DEFAULT_DEV_HUB_USERNAME,
119
123
  newKey: orgConfigProperties_1.OrgConfigProperties.TARGET_DEV_HUB,
120
124
  deprecated: true,
121
125
  description: messages.getMessage('defaultDevHubUsername'),
122
126
  },
123
127
  {
128
+ // will remain in v3 for the foreseeable future so that `sfdx-core` can map between `sf` and `sfdx` config values
124
129
  key: SfdxPropertyKeys.DEFAULT_USERNAME,
125
130
  newKey: orgConfigProperties_1.OrgConfigProperties.TARGET_ORG,
126
131
  deprecated: true,
@@ -446,7 +451,7 @@ class SfdxConfig {
446
451
  }
447
452
  readSync() {
448
453
  try {
449
- const contents = fs_1.fs.readJsonMapSync(this.getSfdxPath());
454
+ const contents = (0, kit_1.parseJsonMap)(fs.readFileSync(this.getSfdxPath(), 'utf8'));
450
455
  return this.normalize(contents, 'toNew');
451
456
  }
452
457
  catch (error) {
@@ -457,9 +462,9 @@ class SfdxConfig {
457
462
  async writeSync(config = this.config.toObject()) {
458
463
  try {
459
464
  const sfdxPath = this.getSfdxPath();
460
- await fs_1.fs.mkdirp((0, path_1.dirname)(sfdxPath));
465
+ await mkdirp((0, path_1.dirname)(sfdxPath));
461
466
  const mapped = this.normalize(config, 'toOld');
462
- await fs_1.fs.writeJson(sfdxPath, mapped);
467
+ await fs.promises.writeFile(sfdxPath, JSON.stringify(mapped, null, 2));
463
468
  }
464
469
  catch (error) {
465
470
  /* Do nothing */
@@ -7,14 +7,16 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.ConfigFile = void 0;
10
+ const fs = require("fs");
10
11
  const fs_1 = require("fs");
11
12
  const os_1 = require("os");
12
13
  const path_1 = require("path");
13
14
  const ts_types_1 = require("@salesforce/ts-types");
15
+ const kit_1 = require("@salesforce/kit");
16
+ const mkdirp = require("mkdirp");
14
17
  const global_1 = require("../global");
15
18
  const logger_1 = require("../logger");
16
19
  const sfError_1 = require("../sfError");
17
- const fs_2 = require("../util/fs");
18
20
  const internal_1 = require("../util/internal");
19
21
  const configStore_1 = require("./configStore");
20
22
  /**
@@ -107,7 +109,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
107
109
  */
108
110
  async access(perm) {
109
111
  try {
110
- await fs_2.fs.access(this.getPath(), perm);
112
+ await fs.promises.access(this.getPath(), perm);
111
113
  return true;
112
114
  }
113
115
  catch (err) {
@@ -124,7 +126,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
124
126
  */
125
127
  accessSync(perm) {
126
128
  try {
127
- fs_2.fs.accessSync(this.getPath(), perm);
129
+ fs.accessSync(this.getPath(), perm);
128
130
  return true;
129
131
  }
130
132
  catch (err) {
@@ -146,7 +148,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
146
148
  // internally and updated persistently via write().
147
149
  if (!this.hasRead || force) {
148
150
  this.logger.info(`Reading config file: ${this.getPath()}`);
149
- const obj = await fs_2.fs.readJsonMap(this.getPath());
151
+ const obj = (0, kit_1.parseJsonMap)(await fs.promises.readFile(this.getPath(), 'utf8'));
150
152
  this.setContentsFromObject(obj);
151
153
  }
152
154
  return this.getContents();
@@ -181,7 +183,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
181
183
  // internally and updated persistently via write().
182
184
  if (!this.hasRead || force) {
183
185
  this.logger.info(`Reading config file: ${this.getPath()}`);
184
- const obj = fs_2.fs.readJsonMapSync(this.getPath());
186
+ const obj = (0, kit_1.parseJsonMap)(fs.readFileSync(this.getPath(), 'utf8'));
185
187
  this.setContentsFromObject(obj);
186
188
  }
187
189
  return this.getContents();
@@ -211,9 +213,9 @@ class ConfigFile extends configStore_1.BaseConfigStore {
211
213
  if (newContents) {
212
214
  this.setContents(newContents);
213
215
  }
214
- await fs_2.fs.mkdirp((0, path_1.dirname)(this.getPath()));
216
+ await mkdirp((0, path_1.dirname)(this.getPath()));
215
217
  this.logger.info(`Writing to config file: ${this.getPath()}`);
216
- await fs_2.fs.writeJson(this.getPath(), this.toObject());
218
+ await fs.promises.writeFile(this.getPath(), JSON.stringify(this.toObject(), null, 2));
217
219
  return this.getContents();
218
220
  }
219
221
  /**
@@ -226,9 +228,9 @@ class ConfigFile extends configStore_1.BaseConfigStore {
226
228
  if ((0, ts_types_1.isPlainObject)(newContents)) {
227
229
  this.setContents(newContents);
228
230
  }
229
- fs_2.fs.mkdirpSync((0, path_1.dirname)(this.getPath()));
231
+ mkdirp.sync((0, path_1.dirname)(this.getPath()));
230
232
  this.logger.info(`Writing to config file: ${this.getPath()}`);
231
- fs_2.fs.writeJsonSync(this.getPath(), this.toObject());
233
+ fs.writeFileSync(this.getPath(), JSON.stringify(this.toObject(), null, 2));
232
234
  return this.getContents();
233
235
  }
234
236
  /**
@@ -249,7 +251,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
249
251
  * {@link fs.stat}
250
252
  */
251
253
  async stat() {
252
- return fs_2.fs.stat(this.getPath());
254
+ return fs.promises.stat(this.getPath());
253
255
  }
254
256
  /**
255
257
  * Get the stats of the file. Returns the stats of the file.
@@ -257,7 +259,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
257
259
  * {@link fs.stat}
258
260
  */
259
261
  statSync() {
260
- return fs_2.fs.statSync(this.getPath());
262
+ return fs.statSync(this.getPath());
261
263
  }
262
264
  /**
263
265
  * Delete the config file if it exists.
@@ -268,7 +270,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
268
270
  async unlink() {
269
271
  const exists = await this.exists();
270
272
  if (exists) {
271
- return await fs_2.fs.unlink(this.getPath());
273
+ return await fs.promises.unlink(this.getPath());
272
274
  }
273
275
  throw new sfError_1.SfError(`Target file doesn't exist. path: ${this.getPath()}`, 'TargetFileNotFound');
274
276
  }
@@ -281,7 +283,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
281
283
  unlinkSync() {
282
284
  const exists = this.existsSync();
283
285
  if (exists) {
284
- return fs_2.fs.unlinkSync(this.getPath());
286
+ return fs.unlinkSync(this.getPath());
285
287
  }
286
288
  throw new sfError_1.SfError(`Target file doesn't exist. path: ${this.getPath()}`, 'TargetFileNotFound');
287
289
  }
@@ -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', [
@@ -329,8 +331,8 @@ async function _writeFile(opts, fn) {
329
331
  [SecretField.KEY]: opts.password,
330
332
  [SecretField.SERVICE]: opts.service,
331
333
  };
332
- await fs_1.fs.mkdirp(path.dirname(secretFile));
333
- 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' });
334
336
  fn(null, contents);
335
337
  }
336
338
  catch (err) {
@@ -339,7 +341,7 @@ async function _writeFile(opts, fn) {
339
341
  }
340
342
  async function _readFile() {
341
343
  // The file and access is validated before this method is called
342
- const fileContents = await fs_1.fs.readJsonMap(secretFile);
344
+ const fileContents = (0, kit_1.parseJsonMap)(await fs.promises.readFile(secretFile, 'utf8'));
343
345
  return {
344
346
  account: (0, ts_types_1.ensureString)(fileContents[SecretField.ACCOUNT]),
345
347
  password: (0, ts_types_1.asString)(fileContents[SecretField.KEY]),
@@ -406,7 +408,7 @@ class GenericKeychainAccess {
406
408
  async isValidFileAccess(cb) {
407
409
  try {
408
410
  const root = (0, os_1.homedir)();
409
- 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);
410
412
  await cb(null);
411
413
  }
412
414
  catch (err) {
@@ -426,7 +428,7 @@ class GenericUnixKeychainAccess extends GenericKeychainAccess {
426
428
  await cb(err);
427
429
  }
428
430
  else {
429
- const stats = await fs_1.fs.stat(secretFile);
431
+ const stats = await fs.promises.stat(secretFile);
430
432
  const octalModeStr = (stats.mode & 0o777).toString(8);
431
433
  const EXPECTED_OCTAL_PERM_VALUE = '600';
432
434
  if (octalModeStr === EXPECTED_OCTAL_PERM_VALUE) {
@@ -451,7 +453,7 @@ class GenericWindowsKeychainAccess extends GenericKeychainAccess {
451
453
  }
452
454
  else {
453
455
  try {
454
- 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);
455
457
  await cb(null);
456
458
  }
457
459
  catch (e) {
package/lib/exported.d.ts CHANGED
@@ -7,7 +7,7 @@ export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } fro
7
7
  export { OrgUsersConfig } from './config/orgUsersConfig';
8
8
  export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config, SfdxPropertyKeys, SFDX_ALLOWED_PROPERTIES, } from './config/config';
9
9
  export { ConfigInfo, ConfigAggregator } from './config/configAggregator';
10
- export { AuthFields, AuthInfo, OrgAuthorization } from './org/authInfo';
10
+ export { AuthFields, AuthInfo, AuthSideEffects, OrgAuthorization } from './org/authInfo';
11
11
  export { AuthRemover } from './org/authRemover';
12
12
  export { Connection, SFDX_HTTP_HEADERS } from './org/connection';
13
13
  export { Mode, Global } from './global';
@@ -16,7 +16,7 @@ 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';
19
+ export { Messages, StructuredMessage } from './messages';
20
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
22
  export { PackageDir, NamedPackageDir, PackageDirDependency, SfProject, SfProjectJson, SfdxProject, SfdxProjectJson, } from './sfProject';
@@ -30,6 +30,5 @@ export { DefaultUserFields, REQUIRED_FIELDS, User, UserFields } from './org/user
30
30
  export { PermissionSetAssignment, PermissionSetAssignmentFields } from './org/permissionSetAssignment';
31
31
  export { ScratchOrgCreateOptions, ScratchOrgCreateResult, scratchOrgCreate } from './org/scratchOrgCreate';
32
32
  export { ScratchOrgInfo } from './org/scratchOrgInfoApi';
33
- export * from './util/fs';
34
33
  export * from './util/sfdc';
35
34
  export * from './util/sfdcUrl';
package/lib/exported.js CHANGED
@@ -99,7 +99,6 @@ Object.defineProperty(exports, "PermissionSetAssignment", { enumerable: true, ge
99
99
  var scratchOrgCreate_1 = require("./org/scratchOrgCreate");
100
100
  Object.defineProperty(exports, "scratchOrgCreate", { enumerable: true, get: function () { return scratchOrgCreate_1.scratchOrgCreate; } });
101
101
  // Utility sub-modules
102
- __exportStar(require("./util/fs"), exports);
103
102
  __exportStar(require("./util/sfdc"), exports);
104
103
  __exportStar(require("./util/sfdcUrl"), exports);
105
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;
@@ -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;
package/lib/logger.js CHANGED
@@ -11,14 +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");
15
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
14
16
  // @ts-ignore
15
17
  const Bunyan = require("@salesforce/bunyan");
16
18
  const kit_1 = require("@salesforce/kit");
17
19
  const ts_types_1 = require("@salesforce/ts-types");
18
20
  const Debug = require("debug");
21
+ const mkdirp = require("mkdirp");
19
22
  const global_1 = require("./global");
20
23
  const sfError_1 = require("./sfError");
21
- const fs_1 = require("./util/fs");
22
24
  /**
23
25
  * Standard `Logger` levels.
24
26
  *
@@ -228,19 +230,19 @@ class Logger {
228
230
  async addLogFileStream(logFile) {
229
231
  try {
230
232
  // Check if we have write access to the log file (i.e., we created it already)
231
- await fs_1.fs.access(logFile, fs_1.fs.constants.W_OK);
233
+ await fs.promises.access(logFile, fs.constants.W_OK);
232
234
  }
233
235
  catch (err1) {
234
236
  try {
235
- await fs_1.fs.mkdirp(path.dirname(logFile), {
236
- mode: fs_1.fs.DEFAULT_USER_DIR_MODE,
237
+ await mkdirp(path.dirname(logFile), {
238
+ mode: '700',
237
239
  });
238
240
  }
239
241
  catch (err2) {
240
242
  // noop; directory exists already
241
243
  }
242
244
  try {
243
- await fs_1.fs.writeFile(logFile, '', { mode: fs_1.fs.DEFAULT_USER_FILE_MODE });
245
+ await fs.promises.writeFile(logFile, '', { mode: '600' });
244
246
  }
245
247
  catch (err3) {
246
248
  throw sfError_1.SfError.wrap(err3);
@@ -268,19 +270,19 @@ class Logger {
268
270
  addLogFileStreamSync(logFile) {
269
271
  try {
270
272
  // Check if we have write access to the log file (i.e., we created it already)
271
- fs_1.fs.accessSync(logFile, fs_1.fs.constants.W_OK);
273
+ fs.accessSync(logFile, fs.constants.W_OK);
272
274
  }
273
275
  catch (err1) {
274
276
  try {
275
- fs_1.fs.mkdirpSync(path.dirname(logFile), {
276
- mode: fs_1.fs.DEFAULT_USER_DIR_MODE,
277
+ mkdirp.sync(path.dirname(logFile), {
278
+ mode: '700',
277
279
  });
278
280
  }
279
281
  catch (err2) {
280
282
  // noop; directory exists already
281
283
  }
282
284
  try {
283
- fs_1.fs.writeFileSync(logFile, '', { mode: fs_1.fs.DEFAULT_USER_FILE_MODE });
285
+ fs.writeFileSync(logFile, '', { mode: '600' });
284
286
  }
285
287
  catch (err3) {
286
288
  throw sfError_1.SfError.wrap(err3);
@@ -400,7 +402,7 @@ class Logger {
400
402
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
401
403
  this.bunyan.streams.forEach(async (stream) => {
402
404
  if (stream.type === 'file') {
403
- content += await fs_1.fs.readFile(stream.path, 'utf8');
405
+ content += await fs.promises.readFile(stream.path, 'utf8');
404
406
  }
405
407
  });
406
408
  return content;
package/lib/messages.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { AnyJson } from '@salesforce/ts-types';
2
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
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
  }
package/lib/messages.js CHANGED
@@ -438,25 +438,68 @@ class Messages {
438
438
  * @param key The key of the error message.
439
439
  * @param tokens The error message tokens.
440
440
  * @param actionTokens The action messages tokens.
441
- * @param exitCodeOrCause The exit code which will be used by SfdxCommand or he underlying error that caused this error to be raised.
441
+ * @param exitCodeOrCause The exit code which will be used by SfdxCommand or the underlying error that caused this error to be raised.
442
442
  * @param cause The underlying error that caused this error to be raised.
443
443
  */
444
444
  createError(key, tokens = [], actionTokens = [], exitCodeOrCause, cause) {
445
+ const structuredMessage = this.formatMessageContents('error', key, tokens, actionTokens);
446
+ return new sfError_1.SfError(structuredMessage.message, structuredMessage.name, structuredMessage.actions, exitCodeOrCause, cause);
447
+ }
448
+ /**
449
+ * Convenience method to create warning using message labels.
450
+ *
451
+ * `warning.name` will be the upper-cased key, remove prefixed `warning.` and will always end in Warning.
452
+ * `warning.actions` will be loaded using `${key}.actions` if available.
453
+ *
454
+ * @param key The key of the warning message.
455
+ * @param tokens The warning message tokens.
456
+ * @param actionTokens The action messages tokens.
457
+ */
458
+ createWarning(key, tokens = [], actionTokens = []) {
459
+ return this.formatMessageContents('warning', key, tokens, actionTokens);
460
+ }
461
+ /**
462
+ * Convenience method to create info using message labels.
463
+ *
464
+ * `info.name` will be the upper-cased key, remove prefixed `info.` and will always end in Info.
465
+ * `info.actions` will be loaded using `${key}.actions` if available.
466
+ *
467
+ * @param key The key of the warning message.
468
+ * @param tokens The warning message tokens.
469
+ * @param actionTokens The action messages tokens.
470
+ */
471
+ createInfo(key, tokens = [], actionTokens = []) {
472
+ return this.formatMessageContents('info', key, tokens, actionTokens);
473
+ }
474
+ /**
475
+ * Formats message contents given a message type, key, tokens and actions tokens
476
+ *
477
+ * `<type>.name` will be the upper-cased key, remove prefixed `<type>.` and will always end in 'Error | Warning | Info.
478
+ * `<type>.actions` will be loaded using `${key}.actions` if available.
479
+ *
480
+ * @param type The type of the message set must 'error' | 'warning' | 'info'.
481
+ * @param key The key of the warning message.
482
+ * @param tokens The warning message tokens.
483
+ * @param actionTokens The action messages tokens.
484
+ */
485
+ formatMessageContents(type, key, tokens = [], actionTokens = []) {
486
+ const label = (0, kit_1.upperFirst)(type);
487
+ const labelRegExp = new RegExp(`${label}$`);
488
+ const searchValue = type === 'error' ? /^error.*\./ : new RegExp(`^${type}.`);
445
489
  // Convert key to name:
446
- // 'myMessage' -> `MyMessageError`
490
+ // 'myMessage' -> `MyMessageWarning`
447
491
  // 'myMessageError' -> `MyMessageError`
448
- // 'error.myMessage' -> `MyMessageError`
449
- // 'errors.myMessage' -> `MyMessageError`
450
- const errName = `${(0, kit_1.upperFirst)(key.replace(/^errors*\./, ''))}${/Error$/.exec(key) ? '' : 'Error'}`;
451
- const errMessage = this.getMessage(key, tokens);
452
- let errActions;
492
+ // 'warning.myMessage' -> `MyMessageWarning`
493
+ const name = `${(0, kit_1.upperFirst)(key.replace(searchValue, ''))}${labelRegExp.exec(key) ? '' : label}`;
494
+ const message = this.getMessage(key, tokens);
495
+ let actions;
453
496
  try {
454
- errActions = this.getMessageWithMap(`${key}.actions`, actionTokens, this.messages);
497
+ actions = this.getMessageWithMap(`${key}.actions`, actionTokens, this.messages);
455
498
  }
456
499
  catch (e) {
457
500
  /* just ignore if actions aren't found */
458
501
  }
459
- return new sfError_1.SfError(errMessage, errName, errActions, exitCodeOrCause, cause);
502
+ return { message, name, actions };
460
503
  }
461
504
  getMessageWithMap(key, tokens = [], map) {
462
505
  // Allow nested keys for better grouping
@@ -59,6 +59,11 @@ export interface AccessTokenOptions {
59
59
  loginUrl?: string;
60
60
  instanceUrl?: string;
61
61
  }
62
+ export declare type AuthSideEffects = {
63
+ alias: string;
64
+ setDefault: boolean;
65
+ setDefaultDevHub: boolean;
66
+ };
62
67
  /**
63
68
  * A function to update a refresh token when the access token is expired.
64
69
  */
@@ -225,6 +230,14 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
225
230
  * **See** [SFDX Authorization](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_auth.htm#cli_reference_force_auth)
226
231
  */
227
232
  getSfdxAuthUrl(): string;
233
+ /**
234
+ * Convenience function to handle typical side effects encountered when dealing with an AuthInfo.
235
+ * Given the values supplied in parameter sideEffects, this functions will set auth alias, default auth
236
+ * and default dev hub.
237
+ *
238
+ * @param sideEffects - instance of AuthSideEffects
239
+ */
240
+ handleAliasAndDefaultSettings(sideEffects: AuthSideEffects): Promise<void>;
228
241
  /**
229
242
  * Set the target-env (default) or the target-dev-hub to the alias if
230
243
  * it exists otherwise to the username. Method will try to set the local