@salesforce/core 3.25.1 → 3.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
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.26.2](https://github.com/forcedotcom/sfdx-core/compare/v3.26.1...v3.26.2) (2022-08-16)
6
+
7
+ ### [3.26.1](https://github.com/forcedotcom/sfdx-core/compare/v3.26.0...v3.26.1) (2022-08-08)
8
+
9
+ ### Bug Fixes
10
+
11
+ - update jsforce ([0353330](https://github.com/forcedotcom/sfdx-core/commit/03533307f0ea1f8877027a5619c970e1ae2443ec))
12
+
13
+ ## [3.26.0](https://github.com/forcedotcom/sfdx-core/compare/v3.25.1...v3.26.0) (2022-08-04)
14
+
15
+ ### Features
16
+
17
+ - remove GlobalInfo ([57bd0fa](https://github.com/forcedotcom/sfdx-core/commit/57bd0fa50c5fe3cc859ca107fd0a18dc1b871c1f))
18
+
5
19
  ### [3.25.1](https://github.com/forcedotcom/sfdx-core/compare/v3.25.0...v3.25.1) (2022-08-03)
6
20
 
7
21
  ### Bug Fixes
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 { ConfigContents, ConfigEntry, ConfigStore, ConfigValue } from './config/configStore';
6
- export { GlobalInfo, SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfToken, SfTokens, StateAggregator } from './stateAggregator';
6
+ export { 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.StateAggregator = exports.SfInfoKeys = exports.GlobalInfo = 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.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.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.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 = void 0;
21
21
  const messages_1 = require("./messages");
22
22
  messages_1.Messages.importMessagesDirectory(__dirname);
23
23
  var configFile_1 = require("./config/configFile");
@@ -30,8 +30,6 @@ Object.defineProperty(exports, "EnvironmentVariable", { enumerable: true, get: f
30
30
  Object.defineProperty(exports, "SUPPORTED_ENV_VARS", { enumerable: true, get: function () { return envVars_1.SUPPORTED_ENV_VARS; } });
31
31
  Object.defineProperty(exports, "EnvVars", { enumerable: true, get: function () { return envVars_1.EnvVars; } });
32
32
  var stateAggregator_1 = require("./stateAggregator");
33
- Object.defineProperty(exports, "GlobalInfo", { enumerable: true, get: function () { return stateAggregator_1.GlobalInfo; } });
34
- Object.defineProperty(exports, "SfInfoKeys", { enumerable: true, get: function () { return stateAggregator_1.SfInfoKeys; } });
35
33
  Object.defineProperty(exports, "StateAggregator", { enumerable: true, get: function () { return stateAggregator_1.StateAggregator; } });
36
34
  var deviceOauthService_1 = require("./deviceOauthService");
37
35
  Object.defineProperty(exports, "DeviceOauthService", { enumerable: true, get: function () { return deviceOauthService_1.DeviceOauthService; } });
@@ -234,6 +234,9 @@ const requestScratchOrgCreation = async (hubOrg, scratchOrgRequest, settings) =>
234
234
  throw new sfError_1.SfError(messages.getMessage('DeprecatedPrefFormat'));
235
235
  }
236
236
  const scratchOrgInfo = (0, mapKeys_1.default)(scratchOrgRequest, kit_1.upperFirst, true);
237
+ if (typeof scratchOrgInfo.Username === 'string') {
238
+ scratchOrgInfo.Username = scratchOrgInfo.Username.toLowerCase();
239
+ }
237
240
  await checkOrgDoesntExist(scratchOrgInfo); // throw if it does exist.
238
241
  try {
239
242
  await (0, scratchOrgLifecycleEvents_1.emit)({ stage: 'send request' });
@@ -1,91 +1,8 @@
1
1
  import { AsyncOptionalCreatable } from '@salesforce/kit';
2
2
  import { Nullable } from '@salesforce/ts-types';
3
- import { ConfigContents } from '../../exported';
4
- import { GlobalInfo } from '../globalInfoConfig';
5
- import { SfAliases, SfOrg, SfToken } from '../types';
6
- export declare type Aliasable = string | Partial<SfOrg> | Partial<SfToken>;
7
- /**
8
- * @deprecated
9
- */
10
- export declare class GlobalInfoAliasAccessor {
11
- private globalInfo;
12
- constructor(globalInfo: GlobalInfo);
13
- /**
14
- * Returns all the aliases for all the values
15
- */
16
- getAll(): SfAliases;
17
- /**
18
- * Returns all the aliases for a given entity
19
- *
20
- * @param entity the aliasable entity that you want to get the aliases of
21
- */
22
- getAll(entity: Aliasable): string[];
23
- /**
24
- * Returns the first alias found for a given entity
25
- *
26
- * @param entity the aliasable entity that you want to get the alias of
27
- */
28
- get(entity: Aliasable): Nullable<string>;
29
- /**
30
- * Returns the value that corresponds to the given alias if it exists
31
- *
32
- * @param alias the alias that corresponds to a value
33
- */
34
- getValue(alias: string): Nullable<string>;
35
- /**
36
- * Returns the username that corresponds to the given alias if it exists
37
- *
38
- * @param alias the alias that corresponds to a username
39
- */
40
- getUsername(alias: string): Nullable<string>;
41
- /**
42
- * If the provided string is an alias, it returns the corresponding value.
43
- * If the provided string is not an alias, we assume that the provided string
44
- * is the value and return it.
45
- *
46
- * This method is helpful when you don't know if the string you have is a value
47
- * or an alias.
48
- *
49
- * @param valueOrAlias a string that might be a value or might be an alias
50
- */
51
- resolveValue(valueOrAlias: string): string;
52
- /**
53
- * If the provided string is an alias, it returns the corresponding username.
54
- * If the provided string is not an alias, we assume that the provided string
55
- * is the username and return it.
56
- *
57
- * This method is helpful when you don't know if the string you have is a username
58
- * or an alias.
59
- *
60
- * @param usernameOrAlias a string that might be a username or might be an alias
61
- */
62
- resolveUsername(usernameOrAlias: string): string;
63
- /**
64
- * Set an alias for the given aliasable entity
65
- *
66
- * @param alias the alias you want to set
67
- * @param entity the aliasable entity that's being aliased
68
- */
69
- set(alias: string, entity: Aliasable): void;
70
- /**
71
- * Updates the alias for the given aliasable entity
72
- *
73
- * @param alias the alias you want to set
74
- * @param entity the aliasable entity that's being aliased
75
- */
76
- update(alias: string, entity: Aliasable): void;
77
- unset(alias: string): void;
78
- /**
79
- * This method unsets all the aliases for the given entity.
80
- *
81
- * @param entity the aliasable entity for which you want to unset all aliases
82
- */
83
- unsetAll(entity: Aliasable): void;
84
- /**
85
- * Returns the username of given aliasable entity
86
- */
87
- private getNameOf;
88
- }
3
+ import { AuthFields, ConfigContents } from '../../exported';
4
+ import { SfToken } from './tokenAccessor';
5
+ export declare type Aliasable = string | (Partial<AuthFields> & Partial<SfToken>);
89
6
  export declare class AliasAccessor extends AsyncOptionalCreatable {
90
7
  private config;
91
8
  /**
@@ -6,126 +6,10 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AliasAccessor = exports.GlobalInfoAliasAccessor = void 0;
9
+ exports.AliasAccessor = void 0;
10
10
  const kit_1 = require("@salesforce/kit");
11
11
  const aliasesConfig_1 = require("../../config/aliasesConfig");
12
12
  const sfError_1 = require("../../sfError");
13
- const types_1 = require("../types");
14
- /**
15
- * @deprecated
16
- */
17
- class GlobalInfoAliasAccessor {
18
- constructor(globalInfo) {
19
- this.globalInfo = globalInfo;
20
- }
21
- getAll(entity) {
22
- const all = this.globalInfo.get(types_1.SfInfoKeys.ALIASES) || {};
23
- if (entity) {
24
- const value = this.getNameOf(entity);
25
- return Object.entries(all)
26
- .filter((entry) => entry[1] === value)
27
- .map((entry) => entry[0]);
28
- }
29
- else {
30
- return all;
31
- }
32
- }
33
- /**
34
- * Returns the first alias found for a given entity
35
- *
36
- * @param entity the aliasable entity that you want to get the alias of
37
- */
38
- get(entity) {
39
- return this.getAll(entity).find((alias) => alias) ?? null;
40
- }
41
- /**
42
- * Returns the value that corresponds to the given alias if it exists
43
- *
44
- * @param alias the alias that corresponds to a value
45
- */
46
- getValue(alias) {
47
- return this.getAll()[alias] ?? null;
48
- }
49
- /**
50
- * Returns the username that corresponds to the given alias if it exists
51
- *
52
- * @param alias the alias that corresponds to a username
53
- */
54
- getUsername(alias) {
55
- return this.getAll()[alias] ?? null;
56
- }
57
- /**
58
- * If the provided string is an alias, it returns the corresponding value.
59
- * If the provided string is not an alias, we assume that the provided string
60
- * is the value and return it.
61
- *
62
- * This method is helpful when you don't know if the string you have is a value
63
- * or an alias.
64
- *
65
- * @param valueOrAlias a string that might be a value or might be an alias
66
- */
67
- resolveValue(valueOrAlias) {
68
- return this.getValue(valueOrAlias) ?? valueOrAlias;
69
- }
70
- /**
71
- * If the provided string is an alias, it returns the corresponding username.
72
- * If the provided string is not an alias, we assume that the provided string
73
- * is the username and return it.
74
- *
75
- * This method is helpful when you don't know if the string you have is a username
76
- * or an alias.
77
- *
78
- * @param usernameOrAlias a string that might be a username or might be an alias
79
- */
80
- resolveUsername(usernameOrAlias) {
81
- return this.getUsername(usernameOrAlias) ?? usernameOrAlias;
82
- }
83
- /**
84
- * Set an alias for the given aliasable entity
85
- *
86
- * @param alias the alias you want to set
87
- * @param entity the aliasable entity that's being aliased
88
- */
89
- set(alias, entity) {
90
- const value = this.getNameOf(entity);
91
- this.globalInfo.set(`${types_1.SfInfoKeys.ALIASES}["${alias}"]`, value);
92
- }
93
- /**
94
- * Updates the alias for the given aliasable entity
95
- *
96
- * @param alias the alias you want to set
97
- * @param entity the aliasable entity that's being aliased
98
- */
99
- update(alias, entity) {
100
- const value = this.getNameOf(entity);
101
- this.globalInfo.update(`${types_1.SfInfoKeys.ALIASES}["${alias}"]`, value);
102
- }
103
- unset(alias) {
104
- delete this.globalInfo.get(types_1.SfInfoKeys.ALIASES)[alias];
105
- }
106
- /**
107
- * This method unsets all the aliases for the given entity.
108
- *
109
- * @param entity the aliasable entity for which you want to unset all aliases
110
- */
111
- unsetAll(entity) {
112
- const aliases = this.getAll(entity);
113
- aliases.forEach((alias) => this.unset(alias));
114
- }
115
- /**
116
- * Returns the username of given aliasable entity
117
- */
118
- getNameOf(entity) {
119
- if (typeof entity === 'string')
120
- return entity;
121
- const aliaseeName = entity.username ?? entity.user;
122
- if (!aliaseeName) {
123
- throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
124
- }
125
- return aliaseeName;
126
- }
127
- }
128
- exports.GlobalInfoAliasAccessor = GlobalInfoAliasAccessor;
129
13
  class AliasAccessor extends kit_1.AsyncOptionalCreatable {
130
14
  getAll(entity) {
131
15
  // This will only return aliases under "orgs". This will need to be modified
@@ -1,26 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import * as fs from 'fs';
3
- import { Nullable, Optional } from '@salesforce/ts-types';
3
+ import { Nullable } from '@salesforce/ts-types';
4
4
  import { AsyncOptionalCreatable } from '@salesforce/kit';
5
5
  import { AuthInfoConfig } from '../../config/authInfoConfig';
6
- import { GlobalInfo } from '../globalInfoConfig';
7
- import { SfOrgs, SfOrg } from '../types';
8
6
  import { AuthFields } from '../../org';
9
7
  import { ConfigFile } from '../../config/configFile';
10
8
  import { ConfigContents } from '../../config/configStore';
11
- /**
12
- * @deprecated
13
- */
14
- export declare class GlobalInfoOrgAccessor {
15
- private globalInfo;
16
- constructor(globalInfo: GlobalInfo);
17
- getAll(decrypt?: boolean): SfOrgs;
18
- get(username: string, decrypt?: boolean): Optional<SfOrg>;
19
- has(username: string): boolean;
20
- set(username: string, org: SfOrg): void;
21
- update(username: string, org: Partial<SfOrg>): void;
22
- unset(username: string): void;
23
- }
24
9
  export declare abstract class BaseOrgAccessor<T extends ConfigFile, P extends ConfigContents> extends AsyncOptionalCreatable {
25
10
  private configs;
26
11
  private contents;
@@ -6,50 +6,14 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.OrgAccessor = exports.BaseOrgAccessor = exports.GlobalInfoOrgAccessor = void 0;
9
+ exports.OrgAccessor = exports.BaseOrgAccessor = void 0;
10
10
  const fs = require("fs");
11
11
  const path = require("path");
12
12
  const kit_1 = require("@salesforce/kit");
13
13
  const authInfoConfig_1 = require("../../config/authInfoConfig");
14
14
  const global_1 = require("../../global");
15
- const types_1 = require("../types");
16
15
  const logger_1 = require("../../logger");
17
16
  const messages_1 = require("../../messages");
18
- /**
19
- * @deprecated
20
- */
21
- class GlobalInfoOrgAccessor {
22
- constructor(globalInfo) {
23
- this.globalInfo = globalInfo;
24
- }
25
- getAll(decrypt = false) {
26
- return this.globalInfo.get(types_1.SfInfoKeys.ORGS, decrypt);
27
- }
28
- get(username, decrypt = false) {
29
- const auth = this.globalInfo.get(`${types_1.SfInfoKeys.ORGS}["${username}"]`, decrypt);
30
- // For legacy, some things wants the username in the returned auth info.
31
- if (auth && !auth.username)
32
- auth.username = username;
33
- return auth;
34
- }
35
- has(username) {
36
- return !!this.getAll()[username];
37
- }
38
- set(username, org) {
39
- // For legacy, and to keep things standard, some things wants the username in auth info.
40
- org.username ?? (org.username = username);
41
- this.globalInfo.set(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
42
- }
43
- update(username, org) {
44
- // For legacy, and to keep things standard, some things wants the username in auth info.
45
- org.username ?? (org.username = username);
46
- this.globalInfo.update(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
47
- }
48
- unset(username) {
49
- delete this.globalInfo.get(types_1.SfInfoKeys.ORGS)[username];
50
- }
51
- }
52
- exports.GlobalInfoOrgAccessor = GlobalInfoOrgAccessor;
53
17
  function chunk(array, chunkSize) {
54
18
  const final = [];
55
19
  for (let i = 0, len = array.length; i < len; i += chunkSize)
@@ -1,45 +1,6 @@
1
- import { Nullable } from '@salesforce/ts-types';
2
1
  import { SandboxOrgConfig } from '../../config/sandboxOrgConfig';
3
2
  import { SandboxFields } from '../../org';
4
- import { GlobalInfo } from '../globalInfoConfig';
5
- import { SfSandbox, SfSandboxes } from '../types';
6
3
  import { BaseOrgAccessor } from './orgAccessor';
7
- /**
8
- * @deprecated
9
- */
10
- export declare class GlobalInfoSandboxAccessor {
11
- private globalInfo;
12
- constructor(globalInfo: GlobalInfo);
13
- /**
14
- * Returns all the sandboxes (or all the sandboxes for a given prod org)
15
- *
16
- * @param entity entity as a string should be a production org username
17
- * and when entity is a SfSandbox, the prod org entity.prodOrgUsername will
18
- * used in the filter.
19
- */
20
- getAll(entity?: string | SfSandbox): SfSandboxes;
21
- /**
22
- * Returns the SfSandbox config entry that corresponds to the given
23
- * sandbox org id if it exists
24
- *
25
- * @param sandboxOrgId the sandboxOrgId that corresponds to a sandbox
26
- */
27
- get(sandboxOrgId?: string): Nullable<SfSandbox>;
28
- /**
29
- * Returns true if the given sandbox org id exists
30
- *
31
- * @param sandboxOrgId the sandboxOrgId that corresponds to a sandbox
32
- */
33
- has(sandboxOrgId?: string): boolean;
34
- /**
35
- * Set an sandboxOrgId for the given sandbox entity
36
- *
37
- * @param sandboxOrgId the sandboxOrgId you want to set
38
- * @param entity the sandbox entity
39
- */
40
- set(sandboxOrgId: string, entity: SfSandbox): void;
41
- unset(sandboxOrgId: string): void;
42
- }
43
4
  export declare class SandboxAccessor extends BaseOrgAccessor<SandboxOrgConfig, SandboxFields> {
44
5
  protected initAuthFile(username: string, throwOnNotFound?: boolean): Promise<SandboxOrgConfig>;
45
6
  protected getFileRegex(): RegExp;
@@ -6,63 +6,9 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.SandboxAccessor = exports.GlobalInfoSandboxAccessor = void 0;
9
+ exports.SandboxAccessor = void 0;
10
10
  const sandboxOrgConfig_1 = require("../../config/sandboxOrgConfig");
11
- const types_1 = require("../types");
12
11
  const orgAccessor_1 = require("./orgAccessor");
13
- /**
14
- * @deprecated
15
- */
16
- class GlobalInfoSandboxAccessor {
17
- constructor(globalInfo) {
18
- this.globalInfo = globalInfo;
19
- }
20
- /**
21
- * Returns all the sandboxes (or all the sandboxes for a given prod org)
22
- *
23
- * @param entity entity as a string should be a production org username
24
- * and when entity is a SfSandbox, the prod org entity.prodOrgUsername will
25
- * used in the filter.
26
- */
27
- getAll(entity) {
28
- const all = this.globalInfo.get(types_1.SfInfoKeys.SANDBOXES) || {};
29
- if (!entity) {
30
- return all;
31
- }
32
- const prodOrgUsername = typeof entity === 'string' ? entity : entity.prodOrgUsername;
33
- return Object.fromEntries(Object.entries(all).filter(([, value]) => value.prodOrgUsername === prodOrgUsername));
34
- }
35
- /**
36
- * Returns the SfSandbox config entry that corresponds to the given
37
- * sandbox org id if it exists
38
- *
39
- * @param sandboxOrgId the sandboxOrgId that corresponds to a sandbox
40
- */
41
- get(sandboxOrgId) {
42
- return sandboxOrgId ? this.getAll()[sandboxOrgId] ?? null : null;
43
- }
44
- /**
45
- * Returns true if the given sandbox org id exists
46
- *
47
- * @param sandboxOrgId the sandboxOrgId that corresponds to a sandbox
48
- */
49
- has(sandboxOrgId) {
50
- return !!(sandboxOrgId ? this.getAll()[sandboxOrgId] ?? null : null);
51
- }
52
- /**
53
- * Set an sandboxOrgId for the given sandbox entity
54
- *
55
- * @param sandboxOrgId the sandboxOrgId you want to set
56
- * @param entity the sandbox entity
57
- */
58
- set(sandboxOrgId, entity) {
59
- this.globalInfo.set(`${types_1.SfInfoKeys.SANDBOXES}["${sandboxOrgId}"]`, entity);
60
- }
61
- unset(sandboxOrgId) {
62
- delete this.globalInfo.get(types_1.SfInfoKeys.SANDBOXES)[sandboxOrgId];
63
- }
64
- }
65
- exports.GlobalInfoSandboxAccessor = GlobalInfoSandboxAccessor;
66
12
  class SandboxAccessor extends orgAccessor_1.BaseOrgAccessor {
67
13
  async initAuthFile(username, throwOnNotFound = false) {
68
14
  return sandboxOrgConfig_1.SandboxOrgConfig.create({
@@ -1,20 +1,14 @@
1
1
  import { AsyncOptionalCreatable } from '@salesforce/kit';
2
- import { Optional } from '@salesforce/ts-types';
3
- import { GlobalInfo } from '../globalInfoConfig';
4
- import { SfTokens, SfToken, Timestamp } from '../types';
5
- /**
6
- * @deprecated
7
- */
8
- export declare class GlobaInfoTokenAccessor {
9
- private globalInfo;
10
- constructor(globalInfo: GlobalInfo);
11
- getAll(decrypt?: boolean): SfTokens;
12
- get(name: string, decrypt?: boolean): Optional<SfToken & Timestamp>;
13
- has(name: string): boolean;
14
- set(name: string, token: SfToken): void;
15
- update(name: string, token: Partial<SfToken>): void;
16
- unset(name: string): void;
17
- }
2
+ import { JsonMap, Optional } from '@salesforce/ts-types';
3
+ export declare type SfToken = {
4
+ token: string;
5
+ url: string;
6
+ user?: string;
7
+ timestamp: string;
8
+ } & JsonMap;
9
+ export declare type SfTokens = {
10
+ [key: string]: SfToken;
11
+ };
18
12
  export declare class TokenAccessor extends AsyncOptionalCreatable {
19
13
  private config;
20
14
  /**
@@ -29,9 +23,9 @@ export declare class TokenAccessor extends AsyncOptionalCreatable {
29
23
  *
30
24
  * @param name
31
25
  * @param decrypt
32
- * @returns {Optional<SfToken & Timestamp>}
26
+ * @returns {Optional<SfToken>}
33
27
  */
34
- get(name: string, decrypt?: boolean): Optional<SfToken & Timestamp>;
28
+ get(name: string, decrypt?: boolean): Optional<SfToken>;
35
29
  /**
36
30
  * Return true if a given name has a token associated with it.
37
31
  *
@@ -6,37 +6,9 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.TokenAccessor = exports.GlobaInfoTokenAccessor = void 0;
9
+ exports.TokenAccessor = void 0;
10
10
  const kit_1 = require("@salesforce/kit");
11
11
  const tokensConfig_1 = require("../../config/tokensConfig");
12
- const types_1 = require("../types");
13
- /**
14
- * @deprecated
15
- */
16
- class GlobaInfoTokenAccessor {
17
- constructor(globalInfo) {
18
- this.globalInfo = globalInfo;
19
- }
20
- getAll(decrypt = false) {
21
- return this.globalInfo.get(types_1.SfInfoKeys.TOKENS, decrypt) || {};
22
- }
23
- get(name, decrypt = false) {
24
- return this.globalInfo.get(`${types_1.SfInfoKeys.TOKENS}["${name}"]`, decrypt);
25
- }
26
- has(name) {
27
- return !!this.getAll()[name];
28
- }
29
- set(name, token) {
30
- this.globalInfo.set(`${types_1.SfInfoKeys.TOKENS}["${name}"]`, token);
31
- }
32
- update(name, token) {
33
- this.globalInfo.update(`${types_1.SfInfoKeys.TOKENS}["${name}"]`, token);
34
- }
35
- unset(name) {
36
- delete this.globalInfo.get(types_1.SfInfoKeys.TOKENS)[name];
37
- }
38
- }
39
- exports.GlobaInfoTokenAccessor = GlobaInfoTokenAccessor;
40
12
  class TokenAccessor extends kit_1.AsyncOptionalCreatable {
41
13
  /**
42
14
  * Return all tokens.
@@ -52,7 +24,7 @@ class TokenAccessor extends kit_1.AsyncOptionalCreatable {
52
24
  *
53
25
  * @param name
54
26
  * @param decrypt
55
- * @returns {Optional<SfToken & Timestamp>}
27
+ * @returns {Optional<SfToken>}
56
28
  */
57
29
  get(name, decrypt = false) {
58
30
  return this.config.get(name, decrypt);
@@ -1,7 +1,4 @@
1
- export * from './globalInfoConfig';
2
- export * from './sfdxDataHandler';
3
- export * from './types';
4
- export { GlobalInfoOrgAccessor, OrgAccessor } from './accessors/orgAccessor';
5
- export { GlobalInfoAliasAccessor, AliasAccessor } from './accessors/aliasAccessor';
6
- export { GlobaInfoTokenAccessor, TokenAccessor } from './accessors/tokenAccessor';
1
+ export * from './accessors/orgAccessor';
2
+ export * from './accessors/aliasAccessor';
3
+ export * from './accessors/tokenAccessor';
7
4
  export * from './stateAggregator';
@@ -16,18 +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.TokenAccessor = exports.GlobaInfoTokenAccessor = exports.AliasAccessor = exports.GlobalInfoAliasAccessor = exports.OrgAccessor = exports.GlobalInfoOrgAccessor = void 0;
20
- __exportStar(require("./globalInfoConfig"), exports);
21
- __exportStar(require("./sfdxDataHandler"), exports);
22
- __exportStar(require("./types"), exports);
23
- var orgAccessor_1 = require("./accessors/orgAccessor");
24
- Object.defineProperty(exports, "GlobalInfoOrgAccessor", { enumerable: true, get: function () { return orgAccessor_1.GlobalInfoOrgAccessor; } });
25
- Object.defineProperty(exports, "OrgAccessor", { enumerable: true, get: function () { return orgAccessor_1.OrgAccessor; } });
26
- var aliasAccessor_1 = require("./accessors/aliasAccessor");
27
- Object.defineProperty(exports, "GlobalInfoAliasAccessor", { enumerable: true, get: function () { return aliasAccessor_1.GlobalInfoAliasAccessor; } });
28
- Object.defineProperty(exports, "AliasAccessor", { enumerable: true, get: function () { return aliasAccessor_1.AliasAccessor; } });
29
- var tokenAccessor_1 = require("./accessors/tokenAccessor");
30
- Object.defineProperty(exports, "GlobaInfoTokenAccessor", { enumerable: true, get: function () { return tokenAccessor_1.GlobaInfoTokenAccessor; } });
31
- Object.defineProperty(exports, "TokenAccessor", { enumerable: true, get: function () { return tokenAccessor_1.TokenAccessor; } });
19
+ __exportStar(require("./accessors/orgAccessor"), exports);
20
+ __exportStar(require("./accessors/aliasAccessor"), exports);
21
+ __exportStar(require("./accessors/tokenAccessor"), exports);
32
22
  __exportStar(require("./stateAggregator"), exports);
33
23
  //# sourceMappingURL=index.js.map
package/lib/testSetup.js CHANGED
@@ -343,8 +343,6 @@ const restoreContext = (testContext) => {
343
343
  testContext.SANDBOX.restore();
344
344
  Object.values(testContext.SANDBOXES).forEach((theSandbox) => theSandbox.restore());
345
345
  testContext.configStubs = {};
346
- // Give each test run a clean GlobalInstance
347
- stateAggregator_1.GlobalInfo.clearInstance();
348
346
  // Give each test run a clean StateAggregator
349
347
  stateAggregator_1.StateAggregator.clearInstance();
350
348
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "3.25.1",
3
+ "version": "3.26.2",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/exported",
6
6
  "types": "lib/exported.d.ts",
@@ -48,7 +48,7 @@
48
48
  "form-data": "^4.0.0",
49
49
  "graceful-fs": "^4.2.9",
50
50
  "js2xmlparser": "^4.0.1",
51
- "jsforce": "^2.0.0-beta.16",
51
+ "jsforce": "beta",
52
52
  "jsonwebtoken": "8.5.1",
53
53
  "ts-retry-promise": "^0.6.0"
54
54
  },
@@ -1,41 +0,0 @@
1
- import { AnyJson } from '@salesforce/ts-types';
2
- import { ConfigFile } from '../config/configFile';
3
- import { ConfigValue } from '../config/configStore';
4
- import { GlobalInfoOrgAccessor } from './accessors/orgAccessor';
5
- import { GlobaInfoTokenAccessor } from './accessors/tokenAccessor';
6
- import { GlobalInfoAliasAccessor } from './accessors/aliasAccessor';
7
- import { SfInfo } from './types';
8
- import { GlobalInfoSandboxAccessor } from './accessors/sandboxAccessor';
9
- export declare function deepCopy<T extends AnyJson>(data: T): T;
10
- /**
11
- * @deprecated use StateAggregator instead.
12
- */
13
- export declare class GlobalInfo extends ConfigFile<ConfigFile.Options, SfInfo> {
14
- protected static encryptedKeys: RegExp[];
15
- private static EMPTY_DATA_MODEL;
16
- private static instance;
17
- private sfdxHandler;
18
- static get emptyDataModel(): SfInfo;
19
- static getInstance(): Promise<GlobalInfo>;
20
- /**
21
- * Clear the cache to force reading from disk.
22
- *
23
- * *NOTE: Only call this method if you must and you know what you are doing.*
24
- */
25
- static clearInstance(): void;
26
- static getFileName(): string;
27
- /**
28
- * Gets default options for the SfConfig
29
- */
30
- static getDefaultOptions(): ConfigFile.Options;
31
- get orgs(): GlobalInfoOrgAccessor;
32
- get tokens(): GlobaInfoTokenAccessor;
33
- get aliases(): GlobalInfoAliasAccessor;
34
- get sandboxes(): GlobalInfoSandboxAccessor;
35
- set(key: string, value: ConfigValue): void;
36
- write(newContents?: SfInfo): Promise<SfInfo>;
37
- protected init(): Promise<void>;
38
- private timestamp;
39
- private loadSfData;
40
- private mergeWithSfdxData;
41
- }
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GlobalInfo = exports.deepCopy = void 0;
4
- /*
5
- * Copyright (c) 2020, salesforce.com, inc.
6
- * All rights reserved.
7
- * Licensed under the BSD 3-Clause license.
8
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
- */
10
- const ts_types_1 = require("@salesforce/ts-types");
11
- const global_1 = require("../global");
12
- const configFile_1 = require("../config/configFile");
13
- const sfdxDataHandler_1 = require("./sfdxDataHandler");
14
- const orgAccessor_1 = require("./accessors/orgAccessor");
15
- const tokenAccessor_1 = require("./accessors/tokenAccessor");
16
- const aliasAccessor_1 = require("./accessors/aliasAccessor");
17
- const types_1 = require("./types");
18
- const sandboxAccessor_1 = require("./accessors/sandboxAccessor");
19
- function deepCopy(data) {
20
- return JSON.parse(JSON.stringify(data));
21
- }
22
- exports.deepCopy = deepCopy;
23
- /**
24
- * @deprecated use StateAggregator instead.
25
- */
26
- class GlobalInfo extends configFile_1.ConfigFile {
27
- constructor() {
28
- super(...arguments);
29
- this.sfdxHandler = new sfdxDataHandler_1.SfdxDataHandler();
30
- }
31
- static get emptyDataModel() {
32
- return deepCopy(GlobalInfo.EMPTY_DATA_MODEL);
33
- }
34
- static async getInstance() {
35
- if (!GlobalInfo.instance) {
36
- GlobalInfo.instance = await GlobalInfo.create();
37
- }
38
- return GlobalInfo.instance;
39
- }
40
- /**
41
- * Clear the cache to force reading from disk.
42
- *
43
- * *NOTE: Only call this method if you must and you know what you are doing.*
44
- */
45
- static clearInstance() {
46
- delete GlobalInfo.instance;
47
- }
48
- static getFileName() {
49
- return 'sf.json';
50
- }
51
- /**
52
- * Gets default options for the SfConfig
53
- */
54
- static getDefaultOptions() {
55
- return {
56
- isGlobal: true,
57
- isState: true,
58
- filename: GlobalInfo.getFileName(),
59
- stateFolder: global_1.Global.SF_STATE_FOLDER,
60
- };
61
- }
62
- get orgs() {
63
- return new orgAccessor_1.GlobalInfoOrgAccessor(this);
64
- }
65
- get tokens() {
66
- return new tokenAccessor_1.GlobaInfoTokenAccessor(this);
67
- }
68
- get aliases() {
69
- return new aliasAccessor_1.GlobalInfoAliasAccessor(this);
70
- }
71
- get sandboxes() {
72
- return new sandboxAccessor_1.GlobalInfoSandboxAccessor(this);
73
- }
74
- set(key, value) {
75
- if ((0, ts_types_1.isPlainObject)(value)) {
76
- value = this.timestamp(value);
77
- }
78
- super.set(key, value);
79
- }
80
- async write(newContents) {
81
- const result = await super.write(newContents);
82
- if (global_1.Global.SFDX_INTEROPERABILITY)
83
- await this.sfdxHandler.write(result);
84
- return result;
85
- }
86
- async init() {
87
- await this.initCrypto();
88
- const contents = global_1.Global.SFDX_INTEROPERABILITY ? await this.mergeWithSfdxData() : await this.loadSfData();
89
- this.setContents(contents);
90
- }
91
- timestamp(data) {
92
- return { ...data, timestamp: new Date() };
93
- }
94
- async loadSfData() {
95
- const data = await this.read();
96
- return { ...GlobalInfo.emptyDataModel, ...data };
97
- }
98
- async mergeWithSfdxData() {
99
- const sfData = await this.loadSfData();
100
- const merged = await this.sfdxHandler.merge(sfData);
101
- await this.write(merged);
102
- return merged;
103
- }
104
- }
105
- exports.GlobalInfo = GlobalInfo;
106
- GlobalInfo.encryptedKeys = [/token/i, /password/i, /secret/i];
107
- GlobalInfo.EMPTY_DATA_MODEL = {
108
- [types_1.SfInfoKeys.ORGS]: {},
109
- [types_1.SfInfoKeys.TOKENS]: {},
110
- [types_1.SfInfoKeys.ALIASES]: {},
111
- [types_1.SfInfoKeys.SANDBOXES]: {},
112
- };
113
- //# sourceMappingURL=globalInfoConfig.js.map
@@ -1,59 +0,0 @@
1
- import { ConfigFile } from '../config/configFile';
2
- import { SfInfo, SfInfoKeys, SfOrg, SfOrgs, SfSandbox } from './types';
3
- interface Handler<T extends SfInfoKeys> {
4
- sfKey: T;
5
- merge: (sfData: SfInfo) => Promise<Partial<SfInfo>>;
6
- migrate: () => Promise<Pick<SfInfo, T>>;
7
- write: (latest: SfInfo, original: SfInfo) => Promise<void>;
8
- }
9
- interface Changes<T> {
10
- changed: T;
11
- deleted: string[];
12
- }
13
- export declare class SfdxDataHandler {
14
- handlers: (AuthHandler | AliasesHandler | SandboxesHandler | TokensHandler)[];
15
- private original;
16
- write(latest?: SfInfo): Promise<void>;
17
- merge(sfData?: SfInfo): Promise<SfInfo>;
18
- private setOriginal;
19
- }
20
- declare abstract class BaseHandler<T extends SfInfoKeys> implements Handler<T> {
21
- abstract sfKey: T;
22
- merge(sfData?: SfInfo): Promise<Partial<SfInfo>>;
23
- abstract migrate(): Promise<Pick<SfInfo, T>>;
24
- abstract write(latest: SfInfo, original: SfInfo): Promise<void>;
25
- }
26
- export declare class AuthHandler extends BaseHandler<SfInfoKeys.ORGS> {
27
- private static authFilenameFilterRegEx;
28
- sfKey: typeof SfInfoKeys.ORGS;
29
- migrate(): Promise<Pick<SfInfo, SfInfoKeys.ORGS>>;
30
- write(latest: SfInfo, original: SfInfo): Promise<void>;
31
- findChanges(latest: SfInfo, original: SfInfo): Promise<Changes<SfOrgs>>;
32
- createAuthFileConfig(username: string): Promise<ConfigFile<ConfigFile.Options>>;
33
- listAllAuthFiles(): Promise<string[]>;
34
- listAllAuthorizations(): Promise<SfOrg[]>;
35
- }
36
- export declare class AliasesHandler extends BaseHandler<SfInfoKeys.ALIASES> {
37
- private static SFDX_ALIASES_FILENAME;
38
- sfKey: typeof SfInfoKeys.ALIASES;
39
- migrate(): Promise<Pick<SfInfo, SfInfoKeys.ALIASES>>;
40
- merge(sfData?: SfInfo): Promise<Partial<SfInfo>>;
41
- write(latest: SfInfo): Promise<void>;
42
- }
43
- export declare class SandboxesHandler extends BaseHandler<SfInfoKeys.SANDBOXES> {
44
- private static sandboxFilenameFilterRegEx;
45
- sfKey: typeof SfInfoKeys.SANDBOXES;
46
- merge(sfData?: SfInfo): Promise<Partial<SfInfo>>;
47
- migrate(): Promise<Pick<SfInfo, SfInfoKeys.SANDBOXES>>;
48
- write(latest: SfInfo, original: SfInfo): Promise<void>;
49
- listAllSandboxFiles(): Promise<string[]>;
50
- listAllSandboxes(): Promise<SfSandbox[]>;
51
- private findChanges;
52
- }
53
- export declare class TokensHandler extends BaseHandler<SfInfoKeys.TOKENS> {
54
- private static SFDX_TOKENS_FILENAME;
55
- sfKey: typeof SfInfoKeys.TOKENS;
56
- migrate(): Promise<Pick<SfInfo, SfInfoKeys.TOKENS>>;
57
- write(latest: SfInfo): Promise<void>;
58
- }
59
- export {};
@@ -1,328 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2020, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.TokensHandler = exports.SandboxesHandler = exports.AliasesHandler = exports.AuthHandler = exports.SfdxDataHandler = void 0;
10
- const path_1 = require("path");
11
- const fs = require("fs");
12
- const kit_1 = require("@salesforce/kit");
13
- const ts_types_1 = require("@salesforce/ts-types");
14
- const global_1 = require("../global");
15
- const configFile_1 = require("../config/configFile");
16
- const sandboxOrgConfig_1 = require("../config/sandboxOrgConfig");
17
- const globalInfoConfig_1 = require("./globalInfoConfig");
18
- const types_1 = require("./types");
19
- function isEqual(object1, object2) {
20
- const keys1 = Object.keys(object1).filter((k) => k !== 'timestamp');
21
- const keys2 = Object.keys(object2).filter((k) => k !== 'timestamp');
22
- if (keys1.length !== keys2.length)
23
- return false;
24
- for (const key of keys1) {
25
- if (object1[key] !== object2[key])
26
- return false;
27
- }
28
- return true;
29
- }
30
- class SfdxDataHandler {
31
- constructor() {
32
- this.handlers = [new AuthHandler(), new AliasesHandler(), new SandboxesHandler(), new TokensHandler()];
33
- }
34
- async write(latest = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
35
- await Promise.all(this.handlers.map((handler) => handler.write(latest, this.original)));
36
- this.setOriginal(latest);
37
- }
38
- async merge(sfData = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
39
- let merged = (0, globalInfoConfig_1.deepCopy)(sfData);
40
- for (const handler of this.handlers) {
41
- merged = Object.assign(merged, await handler.merge(merged));
42
- }
43
- this.setOriginal(merged);
44
- return merged;
45
- }
46
- setOriginal(data) {
47
- this.original = (0, globalInfoConfig_1.deepCopy)(data);
48
- }
49
- }
50
- exports.SfdxDataHandler = SfdxDataHandler;
51
- class BaseHandler {
52
- async merge(sfData = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
53
- const sfdxData = await this.migrate();
54
- const merged = (0, globalInfoConfig_1.deepCopy)(sfData);
55
- // Only merge the key this handler is responsible for.
56
- const key = this.sfKey;
57
- const sfKeys = Object.keys(sfData[key] ?? {});
58
- const sfdxKeys = Object.keys(sfdxData[key] ?? {});
59
- const commonKeys = sfKeys.filter((k) => sfdxKeys.includes(k));
60
- for (const k of commonKeys) {
61
- const [newer, older] = [sfData[key][k], sfdxData[key][k]].sort((a, b) => {
62
- if ((0, ts_types_1.isPlainObject)(a) && (0, ts_types_1.isPlainObject)(b))
63
- return new Date(a.timestamp) < new Date(b.timestamp) ? 1 : -1;
64
- return 0;
65
- });
66
- (0, kit_1.set)(merged, `${key}["${k}"]`, Object.assign({}, older, newer));
67
- }
68
- // Keys that exist in .sfdx but not .sf are added because we assume
69
- // that this means the key was created using sfdx.
70
- // However, this is not always a valid assumption because it could
71
- // also mean that the key was deleted using sf, in which case we
72
- // do not want to migrate the sfdx key to sf.
73
- // Programmatically differentiating between a new key and a deleted key
74
- // would be nearly impossible. Instead, we should ensure that whenever
75
- // sf deletes a key it also deletes it in sfdx. This way, we can safely
76
- // assume that we should migrate any keys that exist in in .sfdx
77
- const unhandledSfdxKeys = sfdxKeys.filter((k) => !sfKeys.includes(k));
78
- for (const k of unhandledSfdxKeys) {
79
- (0, kit_1.set)(merged, `${key}["${k}"]`, sfdxData[key][k]);
80
- }
81
- // Keys that exist in .sf but not .sfdx are deleted because we assume
82
- // that this means the key was deleted while using sfdx.
83
- // We can make this assumption because keys that are created by sf will
84
- // always be migrated back to sfdx
85
- const unhandledSfKeys = sfKeys.filter((k) => !sfdxKeys.includes(k));
86
- for (const k of unhandledSfKeys) {
87
- delete merged[key][k];
88
- }
89
- return merged;
90
- }
91
- }
92
- class AuthHandler extends BaseHandler {
93
- constructor() {
94
- super(...arguments);
95
- this.sfKey = types_1.SfInfoKeys.ORGS;
96
- }
97
- async migrate() {
98
- const oldAuths = await this.listAllAuthorizations();
99
- const newAuths = oldAuths.reduce((x, y) => Object.assign(x, { [(0, ts_types_1.ensureString)(y.username)]: y }), {});
100
- return { [this.sfKey]: newAuths };
101
- }
102
- async write(latest, original) {
103
- const { changed, deleted } = await this.findChanges(latest, original);
104
- await Promise.all(Object.entries(changed)
105
- .filter(([, authData]) => authData)
106
- .map(async ([username, authData]) => {
107
- const config = await this.createAuthFileConfig(username);
108
- config.setContentsFromObject(authData);
109
- return config.write();
110
- }));
111
- await Promise.all(deleted.map(async (username) => {
112
- const config = await this.createAuthFileConfig(username);
113
- return config.unlink();
114
- }));
115
- }
116
- async findChanges(latest, original) {
117
- const latestAuths = latest.orgs;
118
- const originalAuths = original.orgs;
119
- const changed = {};
120
- for (const [username, auth] of Object.entries(latestAuths)) {
121
- const originalAuth = originalAuths[username] ?? {};
122
- if (!isEqual(auth, originalAuth)) {
123
- changed[username] = auth;
124
- }
125
- }
126
- const deleted = Object.keys(originalAuths).filter((username) => !latestAuths[username]);
127
- return { changed, deleted };
128
- }
129
- async createAuthFileConfig(username) {
130
- const config = await configFile_1.ConfigFile.create({
131
- filename: `${username}.json`,
132
- isGlobal: true,
133
- isState: true,
134
- stateFolder: global_1.Global.SFDX_STATE_FOLDER,
135
- throwOnNotFound: false,
136
- encryptedKeys: ['accessToken', 'refreshToken', 'password', 'clientSecret'],
137
- });
138
- return config;
139
- }
140
- async listAllAuthFiles() {
141
- const globalFiles = await fs.promises.readdir(global_1.Global.SFDX_DIR);
142
- return globalFiles.filter((file) => file.match(AuthHandler.authFilenameFilterRegEx));
143
- }
144
- async listAllAuthorizations() {
145
- const filenames = await this.listAllAuthFiles();
146
- return Promise.all(filenames
147
- .map((f) => (0, path_1.basename)(f, (0, path_1.extname)(f)))
148
- .map(async (username) => {
149
- const configFile = await this.createAuthFileConfig(username);
150
- const contents = configFile.getContents();
151
- const stat = await configFile.stat();
152
- return { ...contents, timestamp: stat.mtime.toISOString() };
153
- }));
154
- }
155
- }
156
- exports.AuthHandler = AuthHandler;
157
- // The regular expression that filters files stored in $HOME/.sfdx
158
- AuthHandler.authFilenameFilterRegEx = /^[^.][^@]*@[^.]+(\.[^.\s]+)+\.json$/;
159
- class AliasesHandler extends BaseHandler {
160
- constructor() {
161
- super(...arguments);
162
- this.sfKey = types_1.SfInfoKeys.ALIASES;
163
- }
164
- async migrate() {
165
- const aliasesFilePath = (0, path_1.join)(global_1.Global.SFDX_DIR, AliasesHandler.SFDX_ALIASES_FILENAME);
166
- try {
167
- const x = await fs.promises.readFile(aliasesFilePath, 'utf8');
168
- const sfdxAliases = (0, kit_1.parseJson)(x).orgs;
169
- return { [this.sfKey]: { ...sfdxAliases } };
170
- }
171
- catch (e) {
172
- return { [this.sfKey]: {} };
173
- }
174
- }
175
- // AliasesHandler implements its own merge method because the structure of aliases is flat instead of nested by SfInfoKey types.
176
- async merge(sfData = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
177
- const sfdxAliases = (await this.migrate())[types_1.SfInfoKeys.ALIASES];
178
- const merged = (0, globalInfoConfig_1.deepCopy)(sfData);
179
- /* Overwrite `sf` aliases with `sfdx` aliases
180
- * `sf` will always modify `sfdx` files but `sfdx` won't modify `sf` files
181
- * because of this we can assume that any changes in `sfdx` files that aren't
182
- * in `sf` are the latest data
183
- *
184
- * This breaks down if a user of `sf` manually modifies the `~/.sf/sf.json` file
185
- * but we don't support that use case out-of-the-box (yet?)
186
- *
187
- * Note: See also the explanation on the merge method in the BaseHandler class
188
- */
189
- Object.keys(sfdxAliases).forEach((alias) => {
190
- merged[types_1.SfInfoKeys.ALIASES][alias] = sfdxAliases[alias];
191
- });
192
- /* Delete any aliases that don't exist in sfdx config files
193
- * Aliases that exist in .sf but not .sfdx are deleted because we assume
194
- * that this means the alias was deleted while using sfdx. We can make
195
- * this assumption because keys that are created by sf will always be
196
- * migrated back to sfdx.
197
- *
198
- * Note: See also the explanation on the merge method in the BaseHandler class
199
- */
200
- for (const alias in merged[types_1.SfInfoKeys.ALIASES]) {
201
- if (!sfdxAliases[alias])
202
- delete merged[types_1.SfInfoKeys.ALIASES][alias];
203
- }
204
- return merged;
205
- }
206
- async write(latest) {
207
- const aliasesFilePath = (0, path_1.join)(global_1.Global.SFDX_DIR, AliasesHandler.SFDX_ALIASES_FILENAME);
208
- await fs.promises.writeFile(aliasesFilePath, JSON.stringify({ orgs: latest[types_1.SfInfoKeys.ALIASES] }, null, 2));
209
- }
210
- }
211
- exports.AliasesHandler = AliasesHandler;
212
- AliasesHandler.SFDX_ALIASES_FILENAME = 'alias.json';
213
- class SandboxesHandler extends BaseHandler {
214
- constructor() {
215
- super(...arguments);
216
- this.sfKey = types_1.SfInfoKeys.SANDBOXES;
217
- }
218
- async merge(sfData = globalInfoConfig_1.GlobalInfo.emptyDataModel) {
219
- const sfdxData = await this.migrate();
220
- const merged = (0, globalInfoConfig_1.deepCopy)(sfData);
221
- // Only merge the key this handler is responsible for.
222
- const key = this.sfKey;
223
- const sfKeys = Object.keys(sfData[key] ?? {});
224
- const sfdxKeys = Object.keys(sfdxData[key] ?? {});
225
- // sandbox entries for .sf and .sfdx contain static data. Given there
226
- // can be no mutation during the life of the sandbox, having to merge common keys
227
- // is unnecessary.
228
- // Keys that exist in .sfdx but not .sf are added because we assume
229
- // that this means the key was created using sfdx.
230
- // However, this is not always a valid assumption because it could
231
- // also mean that the key was deleted using sf, in which case we
232
- // do not want to migrate the sfdx key to sf.
233
- // Programmatically differentiating between a new key and a deleted key
234
- // would be nearly impossible. Instead, we should ensure that whenever
235
- // sf deletes a key it also deletes it in sfdx. This way, we can safely
236
- // assume that we should migrate any keys that exist in .sfdx
237
- const unhandledSfdxKeys = sfdxKeys.filter((k) => !sfKeys.includes(k));
238
- for (const k of unhandledSfdxKeys) {
239
- (0, kit_1.set)(merged, `${key}["${k}"]`, sfdxData[key][k]);
240
- }
241
- // Keys that exist in .sf but not .sfdx are deleted because we assume
242
- // that this means the key was deleted while using sfdx.
243
- // We can make this assumption because keys that are created by sf will
244
- // always be migrated back to sfdx
245
- const unhandledSfKeys = sfKeys.filter((k) => !sfdxKeys.includes(k));
246
- for (const k of unhandledSfKeys) {
247
- delete merged[key][k];
248
- }
249
- return merged;
250
- }
251
- async migrate() {
252
- const oldSandboxes = await this.listAllSandboxes();
253
- const newSandboxes = Object.fromEntries(oldSandboxes.map((old) => [old.sandboxOrgId, old]));
254
- return { [this.sfKey]: newSandboxes };
255
- }
256
- async write(latest, original) {
257
- const { changed, deleted } = await this.findChanges(latest, original);
258
- for (const sandboxData of Object.values(changed)) {
259
- if (sandboxData) {
260
- const orgId = sandboxData.sandboxOrgId;
261
- const sandboxConfig = new sandboxOrgConfig_1.SandboxOrgConfig(sandboxOrgConfig_1.SandboxOrgConfig.getOptions(orgId));
262
- sandboxConfig.set(sandboxOrgConfig_1.SandboxOrgConfig.Fields.PROD_ORG_USERNAME, sandboxData.prodOrgUsername);
263
- await sandboxConfig.write();
264
- }
265
- }
266
- for (const username of deleted) {
267
- const originalSandbox = original.sandboxes[username];
268
- const orgId = originalSandbox.sandboxOrgId;
269
- const sandboxConfig = new sandboxOrgConfig_1.SandboxOrgConfig(sandboxOrgConfig_1.SandboxOrgConfig.getOptions(orgId));
270
- await sandboxConfig.unlink();
271
- }
272
- }
273
- async listAllSandboxFiles() {
274
- const globalFiles = await fs.promises.readdir(global_1.Global.SFDX_DIR);
275
- return globalFiles.filter((file) => file.match(SandboxesHandler.sandboxFilenameFilterRegEx));
276
- }
277
- async listAllSandboxes() {
278
- return Promise.all((await this.listAllSandboxFiles()).map(async (filename) => {
279
- const matches = filename.match(SandboxesHandler.sandboxFilenameFilterRegEx);
280
- const orgId = matches ? matches[1] : '';
281
- const sandboxConfig = new sandboxOrgConfig_1.SandboxOrgConfig(sandboxOrgConfig_1.SandboxOrgConfig.getOptions(orgId));
282
- const stat = await sandboxConfig.stat();
283
- const contents = { ...(await sandboxConfig.read(true)), sandboxOrgId: orgId };
284
- const sandbox = Object.assign(contents, { timestamp: stat.mtime.toISOString() });
285
- return sandbox;
286
- }));
287
- }
288
- async findChanges(latest, original) {
289
- const latestSandboxes = latest.sandboxes;
290
- const originalSandboxes = original.sandboxes;
291
- const changed = {};
292
- for (const [sandboxOrgId, sandbox] of Object.entries(latestSandboxes)) {
293
- const originalSandbox = originalSandboxes[sandboxOrgId] ?? {};
294
- if (!isEqual(sandbox, originalSandbox)) {
295
- changed[sandboxOrgId] = sandbox;
296
- }
297
- }
298
- const deleted = Object.keys(originalSandboxes).filter((sandboxOrgId) => !latestSandboxes[sandboxOrgId]);
299
- return { changed, deleted };
300
- }
301
- }
302
- exports.SandboxesHandler = SandboxesHandler;
303
- // The regular expression that filters files stored in $HOME/.sfdx
304
- SandboxesHandler.sandboxFilenameFilterRegEx = /^(00D.*?)\.sandbox\.json$/;
305
- class TokensHandler extends BaseHandler {
306
- constructor() {
307
- super(...arguments);
308
- this.sfKey = types_1.SfInfoKeys.TOKENS;
309
- }
310
- async migrate() {
311
- const filePath = (0, path_1.join)(global_1.Global.SFDX_DIR, TokensHandler.SFDX_TOKENS_FILENAME);
312
- try {
313
- const x = await fs.promises.readFile(filePath, 'utf8');
314
- const tokens = (0, kit_1.parseJson)(x);
315
- return { [this.sfKey]: tokens };
316
- }
317
- catch (e) {
318
- return { [this.sfKey]: {} };
319
- }
320
- }
321
- async write(latest) {
322
- const filePath = (0, path_1.join)(global_1.Global.SFDX_DIR, TokensHandler.SFDX_TOKENS_FILENAME);
323
- await fs.promises.writeFile(filePath, JSON.stringify(latest[types_1.SfInfoKeys.TOKENS], null, 2));
324
- }
325
- }
326
- exports.TokensHandler = TokensHandler;
327
- TokensHandler.SFDX_TOKENS_FILENAME = 'tokens.json';
328
- //# sourceMappingURL=sfdxDataHandler.js.map
@@ -1,72 +0,0 @@
1
- import { JsonMap } from '@salesforce/ts-types';
2
- import { AuthFields } from '../org';
3
- /**
4
- * @deprecated
5
- */
6
- export declare enum SfInfoKeys {
7
- ORGS = "orgs",
8
- TOKENS = "tokens",
9
- ALIASES = "aliases",
10
- SANDBOXES = "sandboxes"
11
- }
12
- export declare type Timestamp = {
13
- timestamp: string;
14
- };
15
- export declare type SfEntry = JsonMap;
16
- /**
17
- * @deprecated
18
- */
19
- export declare type SfOrg = AuthFields & SfEntry;
20
- /**
21
- * @deprecated
22
- */
23
- export interface SfOrgs {
24
- [key: string]: SfOrg & Timestamp;
25
- }
26
- export declare type SfToken = {
27
- token: string;
28
- url: string;
29
- user?: string;
30
- } & SfEntry;
31
- /**
32
- */
33
- export declare type SfTokens = {
34
- [key: string]: SfToken & Timestamp;
35
- };
36
- /**
37
- * The key will always be the alias and the value will always be the username, e.g.
38
- * { "MyAlias": "user@salesforce.com" }
39
- */
40
- export declare type SfAliases = {
41
- [alias: string]: string;
42
- };
43
- /**
44
- * @deprecated
45
- */
46
- export declare type SfSandbox = {
47
- sandboxOrgId: string;
48
- prodOrgUsername: string;
49
- sandboxName?: string;
50
- sandboxUsername?: string;
51
- sandboxProcessId?: string;
52
- sandboxInfoId?: string;
53
- } & Timestamp & SfEntry;
54
- /**
55
- * The key will always be the sandbox username and the value will always be the
56
- * production org username
57
- * { "user@salesforce.com.mysandbox": "user@salesforce.com" }
58
- *
59
- * @deprecated
60
- */
61
- export interface SfSandboxes {
62
- [sandboxOrgId: string]: SfSandbox;
63
- }
64
- /**
65
- * @deprecated
66
- */
67
- export declare type SfInfo = {
68
- [SfInfoKeys.ORGS]: SfOrgs;
69
- [SfInfoKeys.TOKENS]: SfTokens;
70
- [SfInfoKeys.ALIASES]: SfAliases;
71
- [SfInfoKeys.SANDBOXES]: SfSandboxes;
72
- };
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SfInfoKeys = void 0;
4
- /**
5
- * @deprecated
6
- */
7
- var SfInfoKeys;
8
- (function (SfInfoKeys) {
9
- SfInfoKeys["ORGS"] = "orgs";
10
- SfInfoKeys["TOKENS"] = "tokens";
11
- SfInfoKeys["ALIASES"] = "aliases";
12
- SfInfoKeys["SANDBOXES"] = "sandboxes";
13
- })(SfInfoKeys = exports.SfInfoKeys || (exports.SfInfoKeys = {}));
14
- //# sourceMappingURL=types.js.map