@salesforce/core 3.19.2 → 3.19.5

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 (54) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +6 -18
  3. package/lib/config/aliasesConfig.d.ts +12 -0
  4. package/lib/config/aliasesConfig.js +27 -0
  5. package/lib/config/authInfoConfig.d.ts +19 -0
  6. package/lib/config/authInfoConfig.js +35 -0
  7. package/lib/config/configAggregator.d.ts +5 -3
  8. package/lib/config/configAggregator.js +13 -1
  9. package/lib/config/configFile.js +2 -2
  10. package/lib/config/configGroup.d.ts +141 -0
  11. package/lib/config/configGroup.js +224 -0
  12. package/lib/config/configStore.d.ts +2 -2
  13. package/lib/config/configStore.js +1 -2
  14. package/lib/config/tokensConfig.d.ts +10 -0
  15. package/lib/config/tokensConfig.js +28 -0
  16. package/lib/crypto/keyChainImpl.js +1 -1
  17. package/lib/exported.d.ts +1 -1
  18. package/lib/exported.js +6 -5
  19. package/lib/global.d.ts +8 -0
  20. package/lib/global.js +10 -0
  21. package/lib/org/authInfo.d.ts +1 -1
  22. package/lib/org/authInfo.js +22 -22
  23. package/lib/org/authRemover.d.ts +6 -5
  24. package/lib/org/authRemover.js +22 -16
  25. package/lib/org/connection.js +1 -1
  26. package/lib/org/org.d.ts +12 -4
  27. package/lib/org/org.js +28 -26
  28. package/lib/org/scratchOrgCreate.js +5 -7
  29. package/lib/org/scratchOrgInfoApi.js +1 -1
  30. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +79 -1
  31. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +119 -2
  32. package/lib/stateAggregator/accessors/orgAccessor.d.ts +53 -0
  33. package/lib/stateAggregator/accessors/orgAccessor.js +201 -0
  34. package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.d.ts +12 -1
  35. package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.js +22 -2
  36. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +28 -0
  37. package/lib/{globalInfo → stateAggregator}/accessors/tokenAccessor.js +34 -2
  38. package/lib/{globalInfo → stateAggregator}/globalInfoConfig.d.ts +11 -8
  39. package/lib/{globalInfo → stateAggregator}/globalInfoConfig.js +7 -4
  40. package/lib/stateAggregator/index.d.ts +7 -0
  41. package/lib/{globalInfo → stateAggregator}/index.js +5 -1
  42. package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.d.ts +7 -1
  43. package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.js +25 -2
  44. package/lib/stateAggregator/stateAggregator.d.ts +20 -0
  45. package/lib/stateAggregator/stateAggregator.js +38 -0
  46. package/lib/{globalInfo → stateAggregator}/types.d.ts +25 -10
  47. package/lib/{globalInfo → stateAggregator}/types.js +3 -0
  48. package/lib/testSetup.d.ts +30 -6
  49. package/lib/testSetup.js +79 -11
  50. package/package.json +1 -1
  51. package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
  52. package/lib/globalInfo/accessors/orgAccessor.js +0 -45
  53. package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
  54. package/lib/globalInfo/index.d.ts +0 -6
@@ -317,7 +317,7 @@ const _darwinImpl = {
317
317
  }
318
318
  },
319
319
  };
320
- const getSecretFile = () => path.join(global_1.Global.SFDX_DIR, 'key.json');
320
+ const getSecretFile = () => path.join(global_1.Global.DIR, 'key.json');
321
321
  var SecretField;
322
322
  (function (SecretField) {
323
323
  SecretField["SERVICE"] = "service";
package/lib/exported.d.ts CHANGED
@@ -3,7 +3,7 @@ export { ConfigFile } from './config/configFile';
3
3
  export { TTLConfig } from './config/ttlConfig';
4
4
  export { envVars, EnvironmentVariable, SUPPORTED_ENV_VARS, EnvVars } from './config/envVars';
5
5
  export { BaseConfigStore, ConfigContents, ConfigEntry, ConfigStore, ConfigValue } from './config/configStore';
6
- export { GlobalInfo, SfEntry, SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfToken, SfTokens } from './globalInfo';
6
+ export { GlobalInfo, SfEntry, SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfToken, SfTokens, StateAggregator, } from './stateAggregator';
7
7
  export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } from './deviceOauthService';
8
8
  export { OrgUsersConfig } from './config/orgUsersConfig';
9
9
  export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config, SfdxPropertyKeys, SfConfigProperties, SFDX_ALLOWED_PROPERTIES, SF_ALLOWED_PROPERTIES, } from './config/config';
package/lib/exported.js CHANGED
@@ -16,8 +16,8 @@ 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.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.SfdxConfigAggregator = exports.ConfigAggregator = exports.SandboxRequestCache = exports.SF_ALLOWED_PROPERTIES = exports.SFDX_ALLOWED_PROPERTIES = exports.SfConfigProperties = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.TTLConfig = exports.ConfigFile = void 0;
20
- exports.ScratchOrgCache = exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = exports.scratchOrgResume = exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = void 0;
19
+ 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.SfdxConfigAggregator = exports.ConfigAggregator = exports.SandboxRequestCache = exports.SF_ALLOWED_PROPERTIES = exports.SFDX_ALLOWED_PROPERTIES = exports.SfConfigProperties = exports.SfdxPropertyKeys = exports.Config = exports.OrgUsersConfig = exports.DeviceOauthService = exports.StateAggregator = exports.SfInfoKeys = exports.GlobalInfo = exports.BaseConfigStore = exports.EnvVars = exports.SUPPORTED_ENV_VARS = exports.EnvironmentVariable = exports.envVars = exports.TTLConfig = exports.ConfigFile = void 0;
20
+ exports.ScratchOrgCache = exports.scratchOrgLifecycleStages = exports.scratchOrgLifecycleEventName = exports.scratchOrgResume = exports.scratchOrgCreate = exports.PermissionSetAssignment = exports.User = exports.REQUIRED_FIELDS = exports.DefaultUserFields = void 0;
21
21
  const messages_1 = require("./messages");
22
22
  messages_1.Messages.importMessagesDirectory(__dirname);
23
23
  var configFile_1 = require("./config/configFile");
@@ -31,9 +31,10 @@ Object.defineProperty(exports, "SUPPORTED_ENV_VARS", { enumerable: true, get: fu
31
31
  Object.defineProperty(exports, "EnvVars", { enumerable: true, get: function () { return envVars_1.EnvVars; } });
32
32
  var configStore_1 = require("./config/configStore");
33
33
  Object.defineProperty(exports, "BaseConfigStore", { enumerable: true, get: function () { return configStore_1.BaseConfigStore; } });
34
- var globalInfo_1 = require("./globalInfo");
35
- Object.defineProperty(exports, "GlobalInfo", { enumerable: true, get: function () { return globalInfo_1.GlobalInfo; } });
36
- Object.defineProperty(exports, "SfInfoKeys", { enumerable: true, get: function () { return globalInfo_1.SfInfoKeys; } });
34
+ var stateAggregator_1 = require("./stateAggregator");
35
+ Object.defineProperty(exports, "GlobalInfo", { enumerable: true, get: function () { return stateAggregator_1.GlobalInfo; } });
36
+ Object.defineProperty(exports, "SfInfoKeys", { enumerable: true, get: function () { return stateAggregator_1.SfInfoKeys; } });
37
+ Object.defineProperty(exports, "StateAggregator", { enumerable: true, get: function () { return stateAggregator_1.StateAggregator; } });
37
38
  var deviceOauthService_1 = require("./deviceOauthService");
38
39
  Object.defineProperty(exports, "DeviceOauthService", { enumerable: true, get: function () { return deviceOauthService_1.DeviceOauthService; } });
39
40
  var orgUsersConfig_1 = require("./config/orgUsersConfig");
package/lib/global.d.ts CHANGED
@@ -28,6 +28,10 @@ export declare class Global {
28
28
  * The global folder in which sf state is stored.
29
29
  */
30
30
  static readonly SF_STATE_FOLDER = ".sf";
31
+ /**
32
+ * The peferred global folder in which state is stored.
33
+ */
34
+ static readonly STATE_FOLDER = ".sfdx";
31
35
  /**
32
36
  * The full system path to the global sfdx state folder.
33
37
  *
@@ -40,6 +44,10 @@ export declare class Global {
40
44
  * **See** {@link Global.SF_STATE_FOLDER}
41
45
  */
42
46
  static get SF_DIR(): string;
47
+ /**
48
+ * The full system path to the peferred global state folder
49
+ */
50
+ static get DIR(): string;
43
51
  /**
44
52
  * The full system path to the global log file.
45
53
  */
package/lib/global.js CHANGED
@@ -44,6 +44,12 @@ class Global {
44
44
  static get SF_DIR() {
45
45
  return path.join(os.homedir(), Global.SF_STATE_FOLDER);
46
46
  }
47
+ /**
48
+ * The full system path to the peferred global state folder
49
+ */
50
+ static get DIR() {
51
+ return path.join(os.homedir(), Global.SFDX_STATE_FOLDER);
52
+ }
47
53
  /**
48
54
  * Gets the current mode environment variable as a {@link Mode} instance.
49
55
  *
@@ -80,6 +86,10 @@ Global.SFDX_STATE_FOLDER = '.sfdx';
80
86
  * The global folder in which sf state is stored.
81
87
  */
82
88
  Global.SF_STATE_FOLDER = '.sf';
89
+ /**
90
+ * The peferred global folder in which state is stored.
91
+ */
92
+ Global.STATE_FOLDER = Global.SFDX_STATE_FOLDER;
83
93
  /**
84
94
  * The full system path to the global log file.
85
95
  */
@@ -126,7 +126,7 @@ export declare const DEFAULT_CONNECTED_APP_INFO: {
126
126
  export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
127
127
  private usingAccessToken;
128
128
  private logger;
129
- private globalInfo;
129
+ private stateAggregator;
130
130
  private username;
131
131
  private options;
132
132
  /**
@@ -21,7 +21,7 @@ const configAggregator_1 = require("../config/configAggregator");
21
21
  const logger_1 = require("../logger");
22
22
  const sfError_1 = require("../sfError");
23
23
  const sfdc_1 = require("../util/sfdc");
24
- const globalInfo_1 = require("../globalInfo");
24
+ const stateAggregator_1 = require("../stateAggregator");
25
25
  const messages_1 = require("../messages");
26
26
  const sfdcUrl_1 = require("../util/sfdcUrl");
27
27
  const connection_1 = require("./connection");
@@ -145,13 +145,13 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
145
145
  */
146
146
  static async listAllAuthorizations(orgAuthFilter = (orgAuth) => !!orgAuth) {
147
147
  var _a;
148
- const globalInfo = await globalInfo_1.GlobalInfo.getInstance();
148
+ const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
149
149
  const config = (await configAggregator_1.ConfigAggregator.create()).getConfigInfo();
150
- const orgs = Object.values(globalInfo.orgs.getAll());
150
+ const orgs = await stateAggregator.orgs.readAll();
151
151
  const final = [];
152
152
  for (const org of orgs) {
153
153
  const username = (0, ts_types_1.ensureString)(org.username);
154
- const aliases = (_a = globalInfo.aliases.getAll(username)) !== null && _a !== void 0 ? _a : undefined;
154
+ const aliases = (_a = stateAggregator.aliases.getAll(username)) !== null && _a !== void 0 ? _a : undefined;
155
155
  // Get a list of configuration values that are set to either the username or one
156
156
  // of the aliases
157
157
  const configs = config
@@ -167,7 +167,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
167
167
  instanceUrl,
168
168
  isScratchOrg: Boolean(devHubUsername),
169
169
  isDevHub: isDevHub || false,
170
- isSandbox: globalInfo.sandboxes.has(orgId),
170
+ isSandbox: await stateAggregator.sandboxes.hasFile(orgId),
171
171
  orgId: orgId,
172
172
  accessToken: authInfo.getConnectionOptions().accessToken,
173
173
  oauthMethod: authInfo.isJwt() ? 'jwt' : authInfo.isOauth() ? 'web' : 'token',
@@ -197,7 +197,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
197
197
  */
198
198
  static async hasAuthentications() {
199
199
  try {
200
- const auths = (await globalInfo_1.GlobalInfo.getInstance()).orgs.getAll();
200
+ const auths = await (await stateAggregator_1.StateAggregator.getInstance()).orgs.list();
201
201
  return !(0, kit_1.isEmpty)(auths);
202
202
  }
203
203
  catch (err) {
@@ -296,7 +296,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
296
296
  * Find all dev hubs available in the local environment.
297
297
  */
298
298
  static async getDevHubAuthInfos() {
299
- return (await AuthInfo.listAllAuthorizations()).filter((possibleHub) => possibleHub === null || possibleHub === void 0 ? void 0 : possibleHub.isDevHub);
299
+ return await AuthInfo.listAllAuthorizations((possibleHub) => { var _a; return (_a = possibleHub === null || possibleHub === void 0 ? void 0 : possibleHub.isDevHub) !== null && _a !== void 0 ? _a : false; });
300
300
  }
301
301
  static async queryScratchOrg(devHubUsername, scratchOrgId) {
302
302
  const devHubOrg = await org_1.Org.create({ aliasOrUsername: devHubUsername });
@@ -349,7 +349,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
349
349
  this.logger.debug('Username is an accesstoken. Skip saving authinfo to disk.');
350
350
  return this;
351
351
  }
352
- await this.globalInfo.write();
352
+ await this.stateAggregator.orgs.write(username);
353
353
  this.logger.info(`Saved auth info for username: ${username}`);
354
354
  return this;
355
355
  }
@@ -360,13 +360,10 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
360
360
  * @param authData Authorization fields to update.
361
361
  */
362
362
  update(authData) {
363
- // todo move into configstore
364
363
  if (authData && (0, ts_types_1.isPlainObject)(authData)) {
365
364
  this.username = authData.username || this.username;
366
- const existingFields = this.globalInfo.orgs.get(this.getUsername());
367
- const mergedFields = Object.assign({}, existingFields || {}, authData);
368
- this.globalInfo.orgs.set(this.getUsername(), mergedFields);
369
- this.logger.info(`Updated auth info for username: ${this.getUsername()}`);
365
+ this.stateAggregator.orgs.update(this.username, authData);
366
+ this.logger.info(`Updated auth info for username: ${this.username}`);
370
367
  }
371
368
  return this;
372
369
  }
@@ -424,7 +421,8 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
424
421
  * @param decrypt Decrypt the fields.
425
422
  */
426
423
  getFields(decrypt) {
427
- return this.globalInfo.orgs.get(this.username, decrypt);
424
+ var _a;
425
+ return (_a = this.stateAggregator.orgs.get(this.username, decrypt)) !== null && _a !== void 0 ? _a : {};
428
426
  }
429
427
  /**
430
428
  * Get the org front door (used for web based oauth flows)
@@ -499,7 +497,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
499
497
  config = await config_1.Config.create({ isGlobal: true });
500
498
  }
501
499
  const username = (0, ts_types_1.ensureString)(this.getUsername());
502
- const alias = this.globalInfo.aliases.get(username);
500
+ const alias = this.stateAggregator.aliases.get(username);
503
501
  const value = alias !== null && alias !== void 0 ? alias : username;
504
502
  if (options.org) {
505
503
  config.set(orgConfigProperties_1.OrgConfigProperties.TARGET_ORG, value);
@@ -515,14 +513,14 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
515
513
  * @param alias alias to set
516
514
  */
517
515
  async setAlias(alias) {
518
- this.globalInfo.aliases.set(alias, this.getUsername());
516
+ this.stateAggregator.aliases.set(alias, this.getUsername());
517
+ await this.stateAggregator.aliases.write();
519
518
  }
520
519
  /**
521
520
  * Initializes an instance of the AuthInfo class.
522
521
  */
523
522
  async init() {
524
- // We have to set the global instance here because we need synchronous access to it later
525
- this.globalInfo = await globalInfo_1.GlobalInfo.getInstance();
523
+ this.stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
526
524
  const username = this.options.username;
527
525
  const authOptions = this.options.oauth2Options || this.options.accessTokenOptions;
528
526
  // Must specify either username and/or options
@@ -532,14 +530,14 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
532
530
  // If a username AND oauth options, ensure an authorization for the username doesn't
533
531
  // already exist. Throw if it does so we don't overwrite the authorization.
534
532
  if (username && authOptions) {
535
- const authExists = this.globalInfo.orgs.has(username);
536
- if (authExists) {
533
+ if (await this.stateAggregator.orgs.hasFile(username)) {
537
534
  throw messages.createError('authInfoOverwriteError');
538
535
  }
539
536
  }
540
537
  const oauthUsername = username || (0, ts_types_1.getString)(authOptions, 'username');
541
538
  if (oauthUsername) {
542
539
  this.username = oauthUsername;
540
+ await this.stateAggregator.orgs.read(oauthUsername, false, false);
543
541
  } // Else it will be set in initAuthOptions below.
544
542
  // If the username is an access token, use that for auth and don't persist
545
543
  if ((0, ts_types_1.isString)(oauthUsername) && sfdc_1.sfdc.matchesAccessToken(oauthUsername)) {
@@ -556,7 +554,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
556
554
  this.usingAccessToken = true;
557
555
  }
558
556
  // If a username with NO oauth options, ensure authorization already exist.
559
- else if (username && !authOptions && !this.globalInfo.orgs.has(username)) {
557
+ else if (username && !authOptions && !(await this.stateAggregator.orgs.exists(username))) {
560
558
  throw messages.createError('namedOrgNotFound', [username]);
561
559
  }
562
560
  else {
@@ -625,6 +623,8 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
625
623
  }
626
624
  }
627
625
  authConfig.isDevHub = await this.determineIfDevHub((0, ts_types_1.ensureString)(authConfig.instanceUrl), (0, ts_types_1.ensureString)(authConfig.accessToken));
626
+ if (authConfig.username)
627
+ await this.stateAggregator.orgs.read(authConfig.username, false, false);
628
628
  // Update the auth fields WITH encryption
629
629
  this.update(authConfig);
630
630
  }
@@ -632,7 +632,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
632
632
  }
633
633
  async loadDecryptedAuthFromConfig(username) {
634
634
  // Fetch from the persisted auth file
635
- const authInfo = this.globalInfo.orgs.get(username, true);
635
+ const authInfo = this.stateAggregator.orgs.get(username, true);
636
636
  if (!authInfo) {
637
637
  throw messages.createError('namedOrgNotFound', [username]);
638
638
  }
@@ -1,5 +1,6 @@
1
1
  import { AsyncOptionalCreatable } from '@salesforce/kit';
2
- import { SfOrg, SfOrgs } from '../globalInfo';
2
+ import { JsonMap } from '@salesforce/ts-types';
3
+ import { AuthFields } from '.';
3
4
  /**
4
5
  * Handles the removing of authorizations, which includes deleting the auth file
5
6
  * in the global .sfdx folder, deleting any configs that are associated with the username/alias,
@@ -25,7 +26,7 @@ import { SfOrg, SfOrgs } from '../globalInfo';
25
26
  */
26
27
  export declare class AuthRemover extends AsyncOptionalCreatable {
27
28
  private config;
28
- private globalInfo;
29
+ private stateAggregator;
29
30
  private logger;
30
31
  /**
31
32
  * Removes the authentication and any configs or aliases associated with it
@@ -45,13 +46,13 @@ export declare class AuthRemover extends AsyncOptionalCreatable {
45
46
  * @param usernameOrAlias username or alias of the auth you want to find, defaults to the configured target-org
46
47
  * @returns {Promise<SfOrg>}
47
48
  */
48
- findAuth(usernameOrAlias?: string): Promise<SfOrg>;
49
+ findAuth(usernameOrAlias?: string): Promise<AuthFields>;
49
50
  /**
50
51
  * Finds all org authorizations in the global info file (.sf/sf.json)
51
52
  *
52
- * @returns {SfOrgs}
53
+ * @returns {Record<string, AuthFields>}
53
54
  */
54
- findAllAuths(): SfOrgs;
55
+ findAllAuths(): Record<string, AuthFields & JsonMap>;
55
56
  protected init(): Promise<void>;
56
57
  /**
57
58
  * Returns the username for a given alias if the alias exists.
@@ -11,7 +11,7 @@ const kit_1 = require("@salesforce/kit");
11
11
  const configAggregator_1 = require("../config/configAggregator");
12
12
  const logger_1 = require("../logger");
13
13
  const messages_1 = require("../messages");
14
- const globalInfo_1 = require("../globalInfo");
14
+ const stateAggregator_1 = require("../stateAggregator");
15
15
  const orgConfigProperties_1 = require("./orgConfigProperties");
16
16
  messages_1.Messages.importMessagesDirectory(__dirname);
17
17
  const coreMessages = messages_1.Messages.load('@salesforce/core', 'core', ['namedOrgNotFound']);
@@ -50,9 +50,8 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
50
50
  this.logger.debug(`Removing authorization for user ${username}`);
51
51
  await this.unsetConfigValues(username);
52
52
  await this.unsetAliases(username);
53
- this.unsetTokens(username);
54
- this.globalInfo.orgs.unset(username);
55
- await this.globalInfo.write();
53
+ await this.unsetTokens(username);
54
+ await this.stateAggregator.orgs.remove(username);
56
55
  }
57
56
  /**
58
57
  * Removes all authentication files and any configs or aliases associated with them
@@ -73,8 +72,8 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
73
72
  * @returns {Promise<SfOrg>}
74
73
  */
75
74
  async findAuth(usernameOrAlias) {
76
- const username = usernameOrAlias ? await this.resolveUsername(usernameOrAlias) : this.getTargetOrg();
77
- const auth = this.globalInfo.orgs.get(username);
75
+ const username = await this.resolveUsername(usernameOrAlias || this.getTargetOrg());
76
+ const auth = this.stateAggregator.orgs.get(username);
78
77
  if (!auth) {
79
78
  throw coreMessages.createError('namedOrgNotFound');
80
79
  }
@@ -83,15 +82,20 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
83
82
  /**
84
83
  * Finds all org authorizations in the global info file (.sf/sf.json)
85
84
  *
86
- * @returns {SfOrgs}
85
+ * @returns {Record<string, AuthFields>}
87
86
  */
88
87
  findAllAuths() {
89
- return this.globalInfo.orgs.getAll();
88
+ const orgs = this.stateAggregator.orgs.getAll();
89
+ return orgs.reduce((x, y) => {
90
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
91
+ return { ...x, [y.username]: y };
92
+ }, {});
90
93
  }
91
94
  async init() {
92
95
  this.logger = await logger_1.Logger.child(this.constructor.name);
93
96
  this.config = await configAggregator_1.ConfigAggregator.create();
94
- this.globalInfo = await globalInfo_1.GlobalInfo.getInstance();
97
+ this.stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
98
+ await this.stateAggregator.orgs.readAll();
95
99
  }
96
100
  /**
97
101
  * Returns the username for a given alias if the alias exists.
@@ -100,7 +104,7 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
100
104
  * @returns {Promise<string>}
101
105
  */
102
106
  async resolveUsername(usernameOrAlias) {
103
- return this.globalInfo.aliases.resolveUsername(usernameOrAlias);
107
+ return this.stateAggregator.aliases.resolveUsername(usernameOrAlias);
104
108
  }
105
109
  /**
106
110
  * @returns {string}
@@ -119,7 +123,7 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
119
123
  * @returns {Promise<string[]>}
120
124
  */
121
125
  getAliases(username) {
122
- return this.globalInfo.aliases.getAll(username);
126
+ return this.stateAggregator.aliases.getAll(username);
123
127
  }
124
128
  /**
125
129
  * Unsets any configured values (both global and local) for provided username
@@ -158,20 +162,22 @@ class AuthRemover extends kit_1.AsyncOptionalCreatable {
158
162
  */
159
163
  async unsetAliases(username) {
160
164
  this.logger.debug(`Clearing aliases for username: ${username}`);
161
- const existingAliases = this.globalInfo.aliases.getAll(username);
165
+ const existingAliases = this.stateAggregator.aliases.getAll(username);
162
166
  if (existingAliases.length === 0)
163
167
  return;
164
168
  this.logger.debug(`Found these aliases to remove: ${existingAliases}`);
165
- existingAliases.forEach((alias) => this.globalInfo.aliases.unset(alias));
169
+ existingAliases.forEach((alias) => this.stateAggregator.aliases.unset(alias));
170
+ await this.stateAggregator.aliases.write();
166
171
  }
167
- unsetTokens(username) {
172
+ async unsetTokens(username) {
168
173
  this.logger.debug(`Clearing tokens for username: ${username}`);
169
- const tokens = this.globalInfo.tokens.getAll();
174
+ const tokens = this.stateAggregator.tokens.getAll();
170
175
  for (const [key, token] of Object.entries(tokens)) {
171
176
  if (token.user === username) {
172
- this.globalInfo.tokens.unset(key);
177
+ this.stateAggregator.tokens.unset(key);
173
178
  }
174
179
  }
180
+ await this.stateAggregator.tokens.write();
175
181
  }
176
182
  }
177
183
  exports.AuthRemover = AuthRemover;
@@ -293,7 +293,7 @@ class Connection extends jsforce_1.Connection {
293
293
  * Getter for the AuthInfo fields.
294
294
  */
295
295
  getAuthInfoFields() {
296
- // If the GlobalInfo.unsetOrg is called, the AuthFields are no longer accessible.
296
+ // If the StateAggregator.orgs.remove is called, the AuthFields are no longer accessible.
297
297
  return this.options.authInfo.getFields() || {};
298
298
  }
299
299
  /**
package/lib/org/org.d.ts CHANGED
@@ -2,7 +2,6 @@ import { AsyncOptionalCreatable, Duration } from '@salesforce/kit';
2
2
  import { AnyJson, JsonMap, Nullable, Optional } from '@salesforce/ts-types';
3
3
  import { ConfigAggregator } from '../config/configAggregator';
4
4
  import { OrgUsersConfig } from '../config/orgUsersConfig';
5
- import { SfSandbox } from '../globalInfo';
6
5
  import { Connection } from './connection';
7
6
  import { AuthFields, AuthInfo } from './authInfo';
8
7
  import { ScratchOrgCreateOptions, ScratchOrgCreateResult } from './scratchOrgCreate';
@@ -70,6 +69,14 @@ export declare type ResumeSandboxRequest = {
70
69
  SandboxProcessObjId?: string;
71
70
  };
72
71
  export declare type ScratchOrgRequest = Pick<ScratchOrgCreateOptions, 'connectedAppConsumerKey' | 'durationDays' | 'nonamespace' | 'noancestors' | 'wait' | 'retry' | 'apiversion' | 'definitionjson' | 'definitionfile' | 'orgConfig' | 'clientSecret'>;
72
+ export declare type SandboxFields = {
73
+ sandboxOrgId: string;
74
+ prodOrgUsername: string;
75
+ sandboxName?: string;
76
+ sandboxUsername?: string;
77
+ sandboxProcessId?: string;
78
+ sandboxInfoId?: string;
79
+ };
73
80
  /**
74
81
  * Provides a way to manage a locally authenticated Org.
75
82
  *
@@ -312,15 +319,15 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
312
319
  * set the sandbox config related to this given org
313
320
  *
314
321
  * @param orgId {string} orgId of the sandbox
315
- * @param config {SfSandbox} config of the sandbox
322
+ * @param config {SandboxFields} config of the sandbox
316
323
  */
317
- setSandboxConfig(orgId: string, config: SfSandbox): Promise<Org>;
324
+ setSandboxConfig(orgId: string, config: SandboxFields): Promise<Org>;
318
325
  /**
319
326
  * get the sandbox config for the given orgId
320
327
  *
321
328
  * @param orgId {string} orgId of the sandbox
322
329
  */
323
- getSandboxConfig(orgId: string): Promise<Nullable<SfSandbox>>;
330
+ getSandboxConfig(orgId: string): Promise<Nullable<SandboxFields>>;
324
331
  /**
325
332
  * Retrieves the highest api version that is supported by the target server instance. If the apiVersion configured for
326
333
  * Sfdx is greater than the one returned in this call an api version mismatch occurs. In the case of the CLI that
@@ -381,6 +388,7 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
381
388
  * **Throws** *{@link SfError}{ name: 'NotSupportedError' }* Throws an unsupported error.
382
389
  */
383
390
  protected getDefaultOptions(): Org.Options;
391
+ private getLocalDataDir;
384
392
  /**
385
393
  * Gets the sandboxProcessObject and then polls for it to complete.
386
394
  *
package/lib/org/org.js CHANGED
@@ -21,7 +21,7 @@ const sfError_1 = require("../sfError");
21
21
  const sfdc_1 = require("../util/sfdc");
22
22
  const webOAuthServer_1 = require("../webOAuthServer");
23
23
  const messages_1 = require("../messages");
24
- const globalInfo_1 = require("../globalInfo");
24
+ const stateAggregator_1 = require("../stateAggregator");
25
25
  const pollingClient_1 = require("../status/pollingClient");
26
26
  const connection_1 = require("./connection");
27
27
  const authInfo_1 = require("./authInfo");
@@ -225,8 +225,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
225
225
  async cleanLocalOrgData(orgDataPath, throwWhenRemoveFails = false) {
226
226
  let dataPath;
227
227
  try {
228
- const rootFolder = await config_1.Config.resolveRootFolder(false);
229
- dataPath = (0, path_1.join)(rootFolder, global_1.Global.SFDX_STATE_FOLDER, orgDataPath ? orgDataPath : 'orgs');
228
+ dataPath = await this.getLocalDataDir(orgDataPath);
230
229
  this.logger.debug(`cleaning data for path: ${dataPath}`);
231
230
  }
232
231
  catch (err) {
@@ -271,7 +270,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
271
270
  *
272
271
  */
273
272
  async isSandbox() {
274
- return (await globalInfo_1.GlobalInfo.getInstance()).sandboxes.has(this.getOrgId());
273
+ return await (await stateAggregator_1.StateAggregator.getInstance()).sandboxes.hasFile(this.getOrgId());
275
274
  }
276
275
  /**
277
276
  * Check that this org is a scratch org by asking the dev hub if it knows about it.
@@ -502,8 +501,8 @@ class Org extends kit_1.AsyncOptionalCreatable {
502
501
  const organization = await this.retrieveOrganizationInformation();
503
502
  const isScratch = organization.IsSandbox && organization.TrialExpirationDate;
504
503
  const isSandbox = organization.IsSandbox && !organization.TrialExpirationDate;
505
- const info = await globalInfo_1.GlobalInfo.getInstance();
506
- info.orgs.update(username, {
504
+ const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
505
+ stateAggregator.orgs.update(username, {
507
506
  [Org.Fields.NAME]: organization.Name,
508
507
  [Org.Fields.INSTANCE_NAME]: organization.InstanceName,
509
508
  [Org.Fields.NAMESPACE_PREFIX]: organization.NamespacePrefix,
@@ -511,7 +510,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
511
510
  [Org.Fields.IS_SCRATCH]: isScratch,
512
511
  [Org.Fields.TRIAL_EXPIRATION_DATE]: organization.TrialExpirationDate,
513
512
  });
514
- await info.write();
513
+ await stateAggregator.orgs.write(username);
515
514
  }
516
515
  }
517
516
  /**
@@ -618,10 +617,10 @@ class Org extends kit_1.AsyncOptionalCreatable {
618
617
  * set the sandbox config related to this given org
619
618
  *
620
619
  * @param orgId {string} orgId of the sandbox
621
- * @param config {SfSandbox} config of the sandbox
620
+ * @param config {SandboxFields} config of the sandbox
622
621
  */
623
622
  async setSandboxConfig(orgId, config) {
624
- (await globalInfo_1.GlobalInfo.getInstance()).sandboxes.set(orgId, config);
623
+ (await stateAggregator_1.StateAggregator.getInstance()).sandboxes.set(orgId, config);
625
624
  return this;
626
625
  }
627
626
  /**
@@ -630,7 +629,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
630
629
  * @param orgId {string} orgId of the sandbox
631
630
  */
632
631
  async getSandboxConfig(orgId) {
633
- return (await globalInfo_1.GlobalInfo.getInstance()).sandboxes.get(orgId);
632
+ return (await stateAggregator_1.StateAggregator.getInstance()).sandboxes.read(orgId);
634
633
  }
635
634
  /**
636
635
  * Retrieves the highest api version that is supported by the target server instance. If the apiVersion configured for
@@ -733,7 +732,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
733
732
  * Initialize async components.
734
733
  */
735
734
  async init() {
736
- const globalInfo = await globalInfo_1.GlobalInfo.getInstance();
735
+ const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
737
736
  this.logger = await logger_1.Logger.child('Org');
738
737
  this.configAggregator = this.options.aggregator ? this.options.aggregator : await configAggregator_1.ConfigAggregator.create();
739
738
  if (!this.options.connection) {
@@ -744,7 +743,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
744
743
  : this.configAggregator.getPropertyValue(orgConfigProperties_1.OrgConfigProperties.TARGET_ORG);
745
744
  this.options.aliasOrUsername = aliasOrUsername || undefined;
746
745
  }
747
- const username = globalInfo.aliases.resolveUsername(this.options.aliasOrUsername);
746
+ const username = stateAggregator.aliases.resolveUsername(this.options.aliasOrUsername);
748
747
  if (!username) {
749
748
  throw messages.createError('noUsernameFound');
750
749
  }
@@ -764,6 +763,10 @@ class Org extends kit_1.AsyncOptionalCreatable {
764
763
  getDefaultOptions() {
765
764
  throw new sfError_1.SfError('Not Supported', 'NotSupportedError');
766
765
  }
766
+ async getLocalDataDir(orgDataPath) {
767
+ const rootFolder = await config_1.Config.resolveRootFolder(false);
768
+ return (0, path_1.join)(rootFolder, global_1.Global.SFDX_STATE_FOLDER, orgDataPath ? orgDataPath : 'orgs');
769
+ }
767
770
  /**
768
771
  * Gets the sandboxProcessObject and then polls for it to complete.
769
772
  *
@@ -926,14 +929,14 @@ class Org extends kit_1.AsyncOptionalCreatable {
926
929
  * this Org. You don't want to call this method directly. Instead consider calling Org.remove()
927
930
  */
928
931
  async removeAuth() {
929
- const config = await globalInfo_1.GlobalInfo.getInstance();
932
+ const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
930
933
  const username = this.getUsername();
931
934
  // If there is no username, it has already been removed from the globalInfo.
932
935
  // We can skip the unset and just ensure that globalInfo is updated.
933
936
  if (username) {
934
937
  this.logger.debug(`Removing auth for user: ${username}`);
935
938
  this.logger.debug(`Clearing auth cache for user: ${username}`);
936
- config.orgs.unset(username);
939
+ await stateAggregator.orgs.remove(username);
937
940
  }
938
941
  }
939
942
  /**
@@ -964,7 +967,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
964
967
  */
965
968
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
966
969
  async removeUsers(throwWhenRemoveFails) {
967
- const globalInfo = await globalInfo_1.GlobalInfo.getInstance();
970
+ const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
968
971
  this.logger.debug(`Removing users associate with org: ${this.getOrgId()}`);
969
972
  const config = await this.retrieveOrgUsersConfig();
970
973
  this.logger.debug(`using path for org users: ${config.getPath()}`);
@@ -972,8 +975,8 @@ class Org extends kit_1.AsyncOptionalCreatable {
972
975
  await Promise.all(authInfos
973
976
  .map((auth) => auth.getFields().username)
974
977
  .map(async (username) => {
975
- const aliasKeys = (username && globalInfo.aliases.getAll(username)) || [];
976
- globalInfo.aliases.unsetAll(username);
978
+ const aliasKeys = (username && stateAggregator.aliases.getAll(username)) || [];
979
+ stateAggregator.aliases.unsetAll(username);
977
980
  const orgForUser = username === this.getUsername()
978
981
  ? this
979
982
  : await Org.create({
@@ -988,12 +991,11 @@ class Org extends kit_1.AsyncOptionalCreatable {
988
991
  needsConfigUpdate ? config_1.Config.update(configInfo.isGlobal(), orgType, undefined) : undefined,
989
992
  ].filter(Boolean);
990
993
  }));
991
- await globalInfo.write();
994
+ await stateAggregator.aliases.write();
992
995
  }
993
996
  async removeSandboxConfig() {
994
- const globalInfo = await globalInfo_1.GlobalInfo.getInstance();
995
- globalInfo.sandboxes.unset(this.getOrgId());
996
- await globalInfo.write();
997
+ const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
998
+ await stateAggregator.sandboxes.remove(this.getOrgId());
997
999
  }
998
1000
  async writeSandboxAuthFile(sandboxProcessObj, sandboxRes) {
999
1001
  this.logger.debug(`writeSandboxAuthFile sandboxProcessObj: ${JSON.stringify(sandboxProcessObj)}, sandboxRes: ${JSON.stringify(sandboxRes)}`);
@@ -1023,22 +1025,22 @@ class Org extends kit_1.AsyncOptionalCreatable {
1023
1025
  this.logger.debug('Creating AuthInfo for sandbox', sandboxRes.authUserName, productionAuthFields.username, oauth2Options);
1024
1026
  // save auth info for new sandbox
1025
1027
  await authInfo.save();
1026
- if (!authInfo.getFields().orgId) {
1028
+ const sandboxOrgId = authInfo.getFields().orgId;
1029
+ if (!sandboxOrgId) {
1027
1030
  throw messages.createError('AuthInfoOrgIdUndefined');
1028
1031
  }
1029
1032
  // set the sandbox config value
1030
1033
  const sfSandbox = {
1031
1034
  sandboxUsername: sandboxRes.authUserName,
1032
- sandboxOrgId: authInfo.getFields().orgId,
1035
+ sandboxOrgId,
1033
1036
  prodOrgUsername: this.getUsername(),
1034
1037
  sandboxName: sandboxProcessObj.SandboxName,
1035
1038
  sandboxProcessId: sandboxProcessObj.Id,
1036
1039
  sandboxInfoId: sandboxProcessObj.SandboxInfoId,
1037
1040
  timestamp: new Date().toISOString(),
1038
1041
  };
1039
- await this.setSandboxConfig(authInfo.getFields().orgId, sfSandbox);
1040
- const globalInfo = await globalInfo_1.GlobalInfo.getInstance();
1041
- await globalInfo.write();
1042
+ await this.setSandboxConfig(sandboxOrgId, sfSandbox);
1043
+ (await stateAggregator_1.StateAggregator.getInstance()).sandboxes.write(sandboxOrgId);
1042
1044
  await lifecycleEvents_1.Lifecycle.getInstance().emit(SandboxEvents.EVENT_RESULT, {
1043
1045
  sandboxProcessObj,
1044
1046
  sandboxRes,