@salesforce/core 3.19.4 → 3.20.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.20.0](https://github.com/forcedotcom/sfdx-core/compare/v3.19.6-dev.0...v3.20.0) (2022-06-08)
6
+
7
+ ### Features
8
+
9
+ - cache crypto keys by homedir ([dcd493e](https://github.com/forcedotcom/sfdx-core/commit/dcd493e7745bb2717da3a4ed9aff528a51391be6))
10
+
11
+ ### [3.19.6-dev.0](https://github.com/forcedotcom/sfdx-core/compare/v3.19.5...v3.19.6-dev.0) (2022-06-07)
12
+
13
+ ### Features
14
+
15
+ - stateAggregator by homedir ([6219b41](https://github.com/forcedotcom/sfdx-core/commit/6219b41a4d7bac5759a62663e71e16f4722fdeac))
16
+
17
+ ### [3.19.5](https://github.com/forcedotcom/sfdx-core/compare/v3.19.4...v3.19.5) (2022-06-06)
18
+
19
+ ### Bug Fixes
20
+
21
+ - update `NamedOrgNotFound` err name ([6a6a627](https://github.com/forcedotcom/sfdx-core/commit/6a6a62782046858c062ecb24a1d28631ea1f3bbe))
22
+
5
23
  ### [3.19.4](https://github.com/forcedotcom/sfdx-core/compare/v3.19.3...v3.19.4) (2022-06-06)
6
24
 
7
25
  ### Bug Fixes
@@ -16,6 +16,7 @@ const kit_1 = require("@salesforce/kit");
16
16
  const logger_1 = require("../logger");
17
17
  const messages_1 = require("../messages");
18
18
  const cache_1 = require("../util/cache");
19
+ const global_1 = require("../global");
19
20
  const keyChain_1 = require("./keyChain");
20
21
  const secureBuffer_1 = require("./secureBuffer");
21
22
  const TAG_DELIMITER = ':';
@@ -49,20 +50,21 @@ const keychainPromises = {
49
50
  * @param account The keychain account name.
50
51
  */
51
52
  getPassword(_keychain, service, account) {
52
- const sb = cache_1.Cache.get(`${service}:${account}`);
53
+ const cacheKey = `${global_1.Global.DIR}:${service}:${account}`;
54
+ const sb = cache_1.Cache.get(cacheKey);
53
55
  if (!sb) {
54
56
  return new Promise((resolve, reject) => {
55
57
  return _keychain.getPassword({ service, account }, (err, password) => {
56
58
  if (err)
57
59
  return reject(err);
58
- cache_1.Cache.set(`${service}:${account}`, makeSecureBuffer(password));
60
+ cache_1.Cache.set(cacheKey, makeSecureBuffer(password));
59
61
  return resolve({ username: account, password: (0, ts_types_1.ensure)(password) });
60
62
  });
61
63
  });
62
64
  }
63
65
  else {
64
66
  const pw = sb.value((buffer) => buffer.toString('utf8'));
65
- cache_1.Cache.set(`${service}:${account}`, makeSecureBuffer(pw));
67
+ cache_1.Cache.set(cacheKey, makeSecureBuffer(pw));
66
68
  return new Promise((resolve) => {
67
69
  return resolve({ username: account, password: (0, ts_types_1.ensure)(pw) });
68
70
  });
@@ -317,7 +317,6 @@ const _darwinImpl = {
317
317
  }
318
318
  },
319
319
  };
320
- const getSecretFile = () => path.join(global_1.Global.DIR, 'key.json');
321
320
  var SecretField;
322
321
  (function (SecretField) {
323
322
  SecretField["SERVICE"] = "service";
@@ -331,7 +330,7 @@ async function _writeFile(opts, fn) {
331
330
  [SecretField.KEY]: opts.password,
332
331
  [SecretField.SERVICE]: opts.service,
333
332
  };
334
- const secretFile = getSecretFile();
333
+ const secretFile = path.join(global_1.Global.DIR, 'key.json');
335
334
  await mkdirp(path.dirname(secretFile));
336
335
  await fs.promises.writeFile(secretFile, JSON.stringify(contents, null, 4), { mode: '600' });
337
336
  fn(null, contents);
@@ -342,7 +341,7 @@ async function _writeFile(opts, fn) {
342
341
  }
343
342
  async function _readFile() {
344
343
  // The file and access is validated before this method is called
345
- const fileContents = (0, kit_1.parseJsonMap)(await fs.promises.readFile(getSecretFile(), 'utf8'));
344
+ const fileContents = (0, kit_1.parseJsonMap)(await fs.promises.readFile(path.join(global_1.Global.DIR, 'key.json'), 'utf8'));
346
345
  return {
347
346
  account: (0, ts_types_1.ensureString)(fileContents[SecretField.ACCOUNT]),
348
347
  password: (0, ts_types_1.asString)(fileContents[SecretField.KEY]),
@@ -369,7 +368,7 @@ class GenericKeychainAccess {
369
368
  else {
370
369
  // if the service and account names don't match then maybe someone or something is editing
371
370
  // that file. #donotallow
372
- fn(messages.createError('genericKeychainServiceError', [getSecretFile()]));
371
+ fn(messages.createError('genericKeychainServiceError', [path.join(global_1.Global.DIR, 'key.json')]));
373
372
  }
374
373
  }
375
374
  catch (readJsonErr) {
@@ -429,7 +428,7 @@ class GenericUnixKeychainAccess extends GenericKeychainAccess {
429
428
  await cb(err);
430
429
  }
431
430
  else {
432
- const secretFile = getSecretFile();
431
+ const secretFile = path.join(global_1.Global.DIR, 'key.json');
433
432
  const stats = await fs.promises.stat(secretFile);
434
433
  const octalModeStr = (stats.mode & 0o777).toString(8);
435
434
  const EXPECTED_OCTAL_PERM_VALUE = '600';
@@ -455,7 +454,7 @@ class GenericWindowsKeychainAccess extends GenericKeychainAccess {
455
454
  }
456
455
  else {
457
456
  try {
458
- await fs.promises.access(getSecretFile(), fs.constants.R_OK | fs.constants.W_OK);
457
+ await fs.promises.access(path.join(global_1.Global.DIR, 'key.json'), fs.constants.R_OK | fs.constants.W_OK);
459
458
  await cb(null);
460
459
  }
461
460
  catch (e) {
package/lib/global.d.ts CHANGED
@@ -29,7 +29,7 @@ export declare class Global {
29
29
  */
30
30
  static readonly SF_STATE_FOLDER = ".sf";
31
31
  /**
32
- * The peferred global folder in which state is stored.
32
+ * The preferred global folder in which state is stored.
33
33
  */
34
34
  static readonly STATE_FOLDER = ".sfdx";
35
35
  /**
@@ -41,11 +41,11 @@ export declare class Global {
41
41
  /**
42
42
  * The full system path to the global sf state folder.
43
43
  *
44
- * **See** {@link Global.SF_STATE_FOLDER}
44
+ * **See** {@link Global.SF_STATE_FOLDER}
45
45
  */
46
46
  static get SF_DIR(): string;
47
47
  /**
48
- * The full system path to the peferred global state folder
48
+ * The full system path to the preferred global state folder
49
49
  */
50
50
  static get DIR(): string;
51
51
  /**
@@ -53,7 +53,7 @@ export declare class Global {
53
53
  */
54
54
  static readonly LOG_FILE_PATH: string;
55
55
  /**
56
- * Gets the current mode environment variable as a {@link Mode} instance.
56
+ * Gets the curr ent mode environment variable as a {@link Mode} instance.
57
57
  *
58
58
  * ```
59
59
  * console.log(Global.getEnvironmentMode() === Mode.PRODUCTION);
package/lib/global.js CHANGED
@@ -39,19 +39,19 @@ class Global {
39
39
  /**
40
40
  * The full system path to the global sf state folder.
41
41
  *
42
- * **See** {@link Global.SF_STATE_FOLDER}
42
+ * **See** {@link Global.SF_STATE_FOLDER}
43
43
  */
44
44
  static get SF_DIR() {
45
45
  return path.join(os.homedir(), Global.SF_STATE_FOLDER);
46
46
  }
47
47
  /**
48
- * The full system path to the peferred global state folder
48
+ * The full system path to the preferred global state folder
49
49
  */
50
50
  static get DIR() {
51
51
  return path.join(os.homedir(), Global.SFDX_STATE_FOLDER);
52
52
  }
53
53
  /**
54
- * Gets the current mode environment variable as a {@link Mode} instance.
54
+ * Gets the curr ent mode environment variable as a {@link Mode} instance.
55
55
  *
56
56
  * ```
57
57
  * console.log(Global.getEnvironmentMode() === Mode.PRODUCTION);
@@ -87,7 +87,7 @@ Global.SFDX_STATE_FOLDER = '.sfdx';
87
87
  */
88
88
  Global.SF_STATE_FOLDER = '.sf';
89
89
  /**
90
- * The peferred global folder in which state is stored.
90
+ * The preferred global folder in which state is stored.
91
91
  */
92
92
  Global.STATE_FOLDER = Global.SFDX_STATE_FOLDER;
93
93
  /**
@@ -203,7 +203,7 @@ const checkOrgDoesntExist = async (scratchOrgInfo) => {
203
203
  catch (error) {
204
204
  const sfError = sfError_1.SfError.wrap(error);
205
205
  // if an AuthInfo couldn't be created that means no AuthFile exists.
206
- if (sfError.name === 'NamedOrgNotFound') {
206
+ if (sfError.name === 'NamedOrgNotFoundError') {
207
207
  return;
208
208
  }
209
209
  // Something unexpected
@@ -4,17 +4,22 @@ import { OrgAccessor } from './accessors/orgAccessor';
4
4
  import { SandboxAccessor } from './accessors/sandboxAccessor';
5
5
  import { TokenAccessor } from './accessors/tokenAccessor';
6
6
  export declare class StateAggregator extends AsyncOptionalCreatable {
7
- private static instance;
7
+ private static instanceMap;
8
8
  aliases: AliasAccessor;
9
9
  orgs: OrgAccessor;
10
10
  sandboxes: SandboxAccessor;
11
11
  tokens: TokenAccessor;
12
+ /**
13
+ * Reuse a StateAggregator if one was already created for the current global state directory
14
+ * Otherwise, create one and adds it to map for future reuse.
15
+ * HomeDir might be stubbed in tests
16
+ */
12
17
  static getInstance(): Promise<StateAggregator>;
13
18
  /**
14
19
  * Clear the cache to force reading from disk.
15
20
  *
16
21
  * *NOTE: Only call this method if you must and you know what you are doing.*
17
22
  */
18
- static clearInstance(): void;
23
+ static clearInstance(path?: string): void;
19
24
  protected init(): Promise<void>;
20
25
  }
@@ -8,24 +8,31 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.StateAggregator = void 0;
10
10
  const kit_1 = require("@salesforce/kit");
11
+ const global_1 = require("../global");
11
12
  const aliasAccessor_1 = require("./accessors/aliasAccessor");
12
13
  const orgAccessor_1 = require("./accessors/orgAccessor");
13
14
  const sandboxAccessor_1 = require("./accessors/sandboxAccessor");
14
15
  const tokenAccessor_1 = require("./accessors/tokenAccessor");
15
16
  class StateAggregator extends kit_1.AsyncOptionalCreatable {
17
+ /**
18
+ * Reuse a StateAggregator if one was already created for the current global state directory
19
+ * Otherwise, create one and adds it to map for future reuse.
20
+ * HomeDir might be stubbed in tests
21
+ */
16
22
  static async getInstance() {
17
- if (!StateAggregator.instance) {
18
- StateAggregator.instance = await StateAggregator.create();
23
+ if (!StateAggregator.instanceMap.has(global_1.Global.DIR)) {
24
+ StateAggregator.instanceMap.set(global_1.Global.DIR, await StateAggregator.create());
19
25
  }
20
- return StateAggregator.instance;
26
+ // TS assertion is valid because there either was one OR it was just now instantiated
27
+ return StateAggregator.instanceMap.get(global_1.Global.DIR);
21
28
  }
22
29
  /**
23
30
  * Clear the cache to force reading from disk.
24
31
  *
25
32
  * *NOTE: Only call this method if you must and you know what you are doing.*
26
33
  */
27
- static clearInstance() {
28
- delete StateAggregator.instance;
34
+ static clearInstance(path = global_1.Global.DIR) {
35
+ StateAggregator.instanceMap.delete(path);
29
36
  }
30
37
  async init() {
31
38
  this.orgs = await orgAccessor_1.OrgAccessor.create();
@@ -35,4 +42,5 @@ class StateAggregator extends kit_1.AsyncOptionalCreatable {
35
42
  }
36
43
  }
37
44
  exports.StateAggregator = StateAggregator;
45
+ StateAggregator.instanceMap = new Map();
38
46
  //# sourceMappingURL=stateAggregator.js.map
@@ -48,7 +48,7 @@ export declare class SfdcUrl extends URL {
48
48
  */
49
49
  checkLightningDomain(): Promise<true | never>;
50
50
  /**
51
- * Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again untill timeout
51
+ * Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again until timeout
52
52
  * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
53
53
  *
54
54
  * @returns the resolved ip address.
@@ -155,7 +155,7 @@ class SfdcUrl extends url_1.URL {
155
155
  return true;
156
156
  }
157
157
  /**
158
- * Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again untill timeout
158
+ * Method that performs the dns lookup of the host. If the lookup fails the internal polling (1 second), client will try again until timeout
159
159
  * If SFDX_DOMAIN_RETRY environment variable is set (number) it overrides the default timeout duration (240 seconds)
160
160
  *
161
161
  * @returns the resolved ip address.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.19.4",
3
+ "version": "3.20.0",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",