@salesforce/core 3.19.0 → 3.19.3

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 (60) 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 +7 -5
  8. package/lib/config/configAggregator.js +25 -9
  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/envVars.d.ts +2 -3
  15. package/lib/config/envVars.js +8 -13
  16. package/lib/config/tokensConfig.d.ts +10 -0
  17. package/lib/config/tokensConfig.js +28 -0
  18. package/lib/crypto/keyChainImpl.js +1 -1
  19. package/lib/exported.d.ts +1 -1
  20. package/lib/exported.js +6 -5
  21. package/lib/global.d.ts +8 -0
  22. package/lib/global.js +10 -0
  23. package/lib/org/authInfo.d.ts +3 -2
  24. package/lib/org/authInfo.js +55 -37
  25. package/lib/org/authRemover.d.ts +6 -5
  26. package/lib/org/authRemover.js +22 -16
  27. package/lib/org/connection.js +3 -2
  28. package/lib/org/org.d.ts +12 -4
  29. package/lib/org/org.js +28 -26
  30. package/lib/org/scratchOrgCreate.js +5 -8
  31. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +79 -1
  32. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +119 -2
  33. package/lib/stateAggregator/accessors/orgAccessor.d.ts +50 -0
  34. package/lib/stateAggregator/accessors/orgAccessor.js +197 -0
  35. package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.d.ts +12 -1
  36. package/lib/{globalInfo → stateAggregator}/accessors/sandboxAccessor.js +22 -2
  37. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +28 -0
  38. package/lib/{globalInfo → stateAggregator}/accessors/tokenAccessor.js +34 -2
  39. package/lib/{globalInfo → stateAggregator}/globalInfoConfig.d.ts +11 -8
  40. package/lib/{globalInfo → stateAggregator}/globalInfoConfig.js +7 -4
  41. package/lib/stateAggregator/index.d.ts +7 -0
  42. package/lib/{globalInfo → stateAggregator}/index.js +5 -1
  43. package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.d.ts +7 -1
  44. package/lib/{globalInfo → stateAggregator}/sfdxDataHandler.js +25 -2
  45. package/lib/stateAggregator/stateAggregator.d.ts +20 -0
  46. package/lib/stateAggregator/stateAggregator.js +38 -0
  47. package/lib/{globalInfo → stateAggregator}/types.d.ts +25 -10
  48. package/lib/{globalInfo → stateAggregator}/types.js +3 -0
  49. package/lib/testSetup.d.ts +30 -6
  50. package/lib/testSetup.js +79 -11
  51. package/lib/util/sfdcUrl.d.ts +3 -9
  52. package/lib/util/sfdcUrl.js +29 -28
  53. package/messages/core.md +10 -0
  54. package/messages/scratchOrgCreate.md +0 -4
  55. package/messages/scratchOrgInfoApi.md +4 -0
  56. package/package.json +4 -4
  57. package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
  58. package/lib/globalInfo/accessors/orgAccessor.js +0 -45
  59. package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
  60. package/lib/globalInfo/index.d.ts +0 -6
@@ -13,7 +13,7 @@ const messages_1 = require("../messages");
13
13
  const logger_1 = require("../logger");
14
14
  const configAggregator_1 = require("../config/configAggregator");
15
15
  const sfProject_1 = require("../sfProject");
16
- const globalInfo_1 = require("../globalInfo");
16
+ const stateAggregator_1 = require("../stateAggregator");
17
17
  const org_1 = require("./org");
18
18
  const scratchOrgInfoApi_1 = require("./scratchOrgInfoApi");
19
19
  const scratchOrgSettingsGenerator_1 = require("./scratchOrgSettingsGenerator");
@@ -24,7 +24,6 @@ const scratchOrgCache_1 = require("./scratchOrgCache");
24
24
  const scratchOrgErrorCodes_1 = require("./scratchOrgErrorCodes");
25
25
  messages_1.Messages.importMessagesDirectory(__dirname);
26
26
  const messages = messages_1.Messages.load('@salesforce/core', 'scratchOrgCreate', [
27
- 'SourceStatusResetFailureError',
28
27
  'DurationDaysValidationMaxError',
29
28
  'DurationDaysValidationMinError',
30
29
  'RetryNotIntError',
@@ -74,12 +73,10 @@ const scratchOrgResume = async (jobId) => {
74
73
  // At this point, the scratch org is "good".
75
74
  // Some hubs have all the usernames set to `null`
76
75
  const username = (_a = soi.Username) !== null && _a !== void 0 ? _a : soi.SignupUsername;
77
- // re-auth only if the org isn't in GlobalInfo
78
- const globalInfo = await globalInfo_1.GlobalInfo.getInstance();
79
- const scratchOrgAuthInfo = globalInfo.orgs.has(username)
80
- ? await authInfo_1.AuthInfo.create({
81
- username,
82
- })
76
+ // re-auth only if the org isn't in StateAggregator
77
+ const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
78
+ const scratchOrgAuthInfo = (await stateAggregator.orgs.exists(username))
79
+ ? await authInfo_1.AuthInfo.create({ username })
83
80
  : await (0, scratchOrgInfoApi_1.authorizeScratchOrg)({
84
81
  scratchOrgInfoComplete: soi,
85
82
  hubOrg,
@@ -1,8 +1,13 @@
1
+ import { AsyncOptionalCreatable } from '@salesforce/kit';
1
2
  import { Nullable } from '@salesforce/ts-types';
3
+ import { ConfigContents } from '../../exported';
2
4
  import { GlobalInfo } from '../globalInfoConfig';
3
5
  import { SfAliases, SfOrg, SfToken } from '../types';
4
6
  export declare type Aliasable = string | Partial<SfOrg> | Partial<SfToken>;
5
- export declare class AliasAccessor {
7
+ /**
8
+ * @deprecated
9
+ */
10
+ export declare class GlobalInfoAliasAccessor {
6
11
  private globalInfo;
7
12
  constructor(globalInfo: GlobalInfo);
8
13
  /**
@@ -81,3 +86,76 @@ export declare class AliasAccessor {
81
86
  */
82
87
  private getNameOf;
83
88
  }
89
+ export declare class AliasAccessor extends AsyncOptionalCreatable {
90
+ private config;
91
+ /**
92
+ * Returns all the aliases for all the values
93
+ */
94
+ getAll(): ConfigContents<string>;
95
+ /**
96
+ * Returns all the aliases for a given entity
97
+ *
98
+ * @param entity the aliasable entity that you want to get the aliases of
99
+ */
100
+ getAll(entity: Aliasable): string[];
101
+ /**
102
+ * Returns the first alias found for a given entity
103
+ *
104
+ * @param entity the aliasable entity that you want to get the alias of
105
+ */
106
+ get(entity: Aliasable): Nullable<string>;
107
+ /**
108
+ * Returns the value that corresponds to the given alias if it exists
109
+ *
110
+ * @param alias the alias that corresponds to a value
111
+ */
112
+ getValue(alias: string): Nullable<string>;
113
+ /**
114
+ * Returns the username that corresponds to the given alias if it exists
115
+ *
116
+ * @param alias the alias that corresponds to a username
117
+ */
118
+ getUsername(alias: string): Nullable<string>;
119
+ /**
120
+ * If the provided string is an alias, it returns the corresponding value.
121
+ * If the provided string is not an alias, we assume that the provided string
122
+ * is the value and return it.
123
+ *
124
+ * This method is helpful when you don't know if the string you have is a value
125
+ * or an alias.
126
+ *
127
+ * @param valueOrAlias a string that might be a value or might be an alias
128
+ */
129
+ resolveValue(valueOrAlias: string): string;
130
+ /**
131
+ * If the provided string is an alias, it returns the corresponding username.
132
+ * If the provided string is not an alias, we assume that the provided string
133
+ * is the username and return it.
134
+ *
135
+ * This method is helpful when you don't know if the string you have is a username
136
+ * or an alias.
137
+ *
138
+ * @param usernameOrAlias a string that might be a username or might be an alias
139
+ */
140
+ resolveUsername(usernameOrAlias: string): string;
141
+ /**
142
+ * Set an alias for the given aliasable entity
143
+ *
144
+ * @param alias the alias you want to set
145
+ * @param entity the aliasable entity that's being aliased
146
+ */
147
+ set(alias: string, entity: Aliasable): void;
148
+ unset(alias: string): void;
149
+ /**
150
+ * This method unsets all the aliases for the given entity.
151
+ *
152
+ * @param entity the aliasable entity for which you want to unset all aliases
153
+ */
154
+ unsetAll(entity: Aliasable): void;
155
+ write(): Promise<ConfigContents>;
156
+ protected init(): Promise<void>;
157
+ /**
158
+ * Returns the username of given aliasable entity
159
+ */
160
+ private getNameOf;
161
+ }
@@ -6,10 +6,15 @@
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 = void 0;
9
+ exports.AliasAccessor = exports.GlobalInfoAliasAccessor = void 0;
10
+ const kit_1 = require("@salesforce/kit");
11
+ const aliasesConfig_1 = require("../../config/aliasesConfig");
10
12
  const sfError_1 = require("../../sfError");
11
13
  const types_1 = require("../types");
12
- class AliasAccessor {
14
+ /**
15
+ * @deprecated
16
+ */
17
+ class GlobalInfoAliasAccessor {
13
18
  constructor(globalInfo) {
14
19
  this.globalInfo = globalInfo;
15
20
  }
@@ -126,5 +131,117 @@ class AliasAccessor {
126
131
  return aliaseeName;
127
132
  }
128
133
  }
134
+ exports.GlobalInfoAliasAccessor = GlobalInfoAliasAccessor;
135
+ class AliasAccessor extends kit_1.AsyncOptionalCreatable {
136
+ getAll(entity) {
137
+ // This will only return aliases under "orgs". This will need to be modified
138
+ // if/when we want to support more aliases groups.
139
+ const all = (this.config.getGroup() || {});
140
+ if (entity) {
141
+ const value = this.getNameOf(entity);
142
+ return Object.entries(all)
143
+ .filter((entry) => entry[1] === value)
144
+ .map((entry) => entry[0]);
145
+ }
146
+ else {
147
+ return all;
148
+ }
149
+ }
150
+ /**
151
+ * Returns the first alias found for a given entity
152
+ *
153
+ * @param entity the aliasable entity that you want to get the alias of
154
+ */
155
+ get(entity) {
156
+ var _a;
157
+ return (_a = this.getAll(entity).find((alias) => alias)) !== null && _a !== void 0 ? _a : null;
158
+ }
159
+ /**
160
+ * Returns the value that corresponds to the given alias if it exists
161
+ *
162
+ * @param alias the alias that corresponds to a value
163
+ */
164
+ getValue(alias) {
165
+ var _a;
166
+ return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
167
+ }
168
+ /**
169
+ * Returns the username that corresponds to the given alias if it exists
170
+ *
171
+ * @param alias the alias that corresponds to a username
172
+ */
173
+ getUsername(alias) {
174
+ var _a;
175
+ return (_a = this.getAll()[alias]) !== null && _a !== void 0 ? _a : null;
176
+ }
177
+ /**
178
+ * If the provided string is an alias, it returns the corresponding value.
179
+ * If the provided string is not an alias, we assume that the provided string
180
+ * is the value and return it.
181
+ *
182
+ * This method is helpful when you don't know if the string you have is a value
183
+ * or an alias.
184
+ *
185
+ * @param valueOrAlias a string that might be a value or might be an alias
186
+ */
187
+ resolveValue(valueOrAlias) {
188
+ var _a;
189
+ return (_a = this.getValue(valueOrAlias)) !== null && _a !== void 0 ? _a : valueOrAlias;
190
+ }
191
+ /**
192
+ * If the provided string is an alias, it returns the corresponding username.
193
+ * If the provided string is not an alias, we assume that the provided string
194
+ * is the username and return it.
195
+ *
196
+ * This method is helpful when you don't know if the string you have is a username
197
+ * or an alias.
198
+ *
199
+ * @param usernameOrAlias a string that might be a username or might be an alias
200
+ */
201
+ resolveUsername(usernameOrAlias) {
202
+ var _a;
203
+ return (_a = this.getUsername(usernameOrAlias)) !== null && _a !== void 0 ? _a : usernameOrAlias;
204
+ }
205
+ /**
206
+ * Set an alias for the given aliasable entity
207
+ *
208
+ * @param alias the alias you want to set
209
+ * @param entity the aliasable entity that's being aliased
210
+ */
211
+ set(alias, entity) {
212
+ this.config.set(alias, this.getNameOf(entity));
213
+ }
214
+ unset(alias) {
215
+ this.config.unset(alias);
216
+ }
217
+ /**
218
+ * This method unsets all the aliases for the given entity.
219
+ *
220
+ * @param entity the aliasable entity for which you want to unset all aliases
221
+ */
222
+ unsetAll(entity) {
223
+ const aliases = this.getAll(entity);
224
+ aliases.forEach((alias) => this.unset(alias));
225
+ }
226
+ async write() {
227
+ return this.config.write();
228
+ }
229
+ async init() {
230
+ this.config = await aliasesConfig_1.AliasesConfig.create(aliasesConfig_1.AliasesConfig.getDefaultOptions());
231
+ }
232
+ /**
233
+ * Returns the username of given aliasable entity
234
+ */
235
+ getNameOf(entity) {
236
+ var _a;
237
+ if (typeof entity === 'string')
238
+ return entity;
239
+ const aliaseeName = (_a = entity.username) !== null && _a !== void 0 ? _a : entity.user;
240
+ if (!aliaseeName) {
241
+ throw new sfError_1.SfError(`Invalid aliasee, it must contain a user or username property: ${JSON.stringify(entity)}`);
242
+ }
243
+ return aliaseeName;
244
+ }
245
+ }
129
246
  exports.AliasAccessor = AliasAccessor;
130
247
  //# sourceMappingURL=aliasAccessor.js.map
@@ -0,0 +1,50 @@
1
+ import { JsonMap, Nullable, Optional } from '@salesforce/ts-types';
2
+ import { AsyncOptionalCreatable } from '@salesforce/kit';
3
+ import { AuthInfoConfig } from '../../config/authInfoConfig';
4
+ import { GlobalInfo } from '../globalInfoConfig';
5
+ import { SfOrgs, SfOrg } from '../types';
6
+ import { AuthFields } from '../../org';
7
+ import { ConfigFile } from '../../config/configFile';
8
+ import { ConfigContents } from '../../config/configStore';
9
+ /**
10
+ * @deprecated
11
+ */
12
+ export declare class GlobalInfoOrgAccessor {
13
+ private globalInfo;
14
+ constructor(globalInfo: GlobalInfo);
15
+ getAll(decrypt?: boolean): SfOrgs;
16
+ get(username: string, decrypt?: boolean): Optional<SfOrg>;
17
+ has(username: string): boolean;
18
+ set(username: string, org: SfOrg): void;
19
+ update(username: string, org: Partial<SfOrg>): void;
20
+ unset(username: string): void;
21
+ }
22
+ export declare abstract class BaseOrgAccessor<T extends ConfigFile, P extends ConfigContents> extends AsyncOptionalCreatable {
23
+ private configs;
24
+ private contents;
25
+ private logger;
26
+ read(username: string, decrypt?: boolean, throwOnNotFound?: boolean): Promise<Nullable<P>>;
27
+ readAll(decrypt?: boolean): Promise<P[]>;
28
+ get(username: string, decrypt?: boolean): Nullable<P>;
29
+ getAll(decrypt?: boolean): P[];
30
+ has(username: string): boolean;
31
+ exists(username: string): Promise<boolean>;
32
+ hasFile(username: string): Promise<boolean>;
33
+ list(): Promise<string[]>;
34
+ set(username: string, org: P): void;
35
+ update(username: string, org: Partial<P> & JsonMap): void;
36
+ remove(username: string): Promise<void>;
37
+ write(username: string): Promise<Nullable<P>>;
38
+ protected init(): Promise<void>;
39
+ private getAllFiles;
40
+ private parseUsername;
41
+ private parseFilename;
42
+ protected abstract initAuthFile(username: string, throwOnNotFound?: boolean): Promise<T>;
43
+ protected abstract getFileRegex(): RegExp;
44
+ protected abstract getFileExtension(): string;
45
+ }
46
+ export declare class OrgAccessor extends BaseOrgAccessor<AuthInfoConfig, AuthFields> {
47
+ protected initAuthFile(username: string, throwOnNotFound?: boolean): Promise<AuthInfoConfig>;
48
+ protected getFileRegex(): RegExp;
49
+ protected getFileExtension(): string;
50
+ }
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021, 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.OrgAccessor = exports.BaseOrgAccessor = exports.GlobalInfoOrgAccessor = void 0;
10
+ const fs = require("fs");
11
+ const path = require("path");
12
+ const kit_1 = require("@salesforce/kit");
13
+ const authInfoConfig_1 = require("../../config/authInfoConfig");
14
+ const global_1 = require("../../global");
15
+ const types_1 = require("../types");
16
+ const logger_1 = require("../../logger");
17
+ /**
18
+ * @deprecated
19
+ */
20
+ class GlobalInfoOrgAccessor {
21
+ constructor(globalInfo) {
22
+ this.globalInfo = globalInfo;
23
+ }
24
+ getAll(decrypt = false) {
25
+ return this.globalInfo.get(types_1.SfInfoKeys.ORGS, decrypt);
26
+ }
27
+ get(username, decrypt = false) {
28
+ const auth = this.globalInfo.get(`${types_1.SfInfoKeys.ORGS}["${username}"]`, decrypt);
29
+ // For legacy, some things wants the username in the returned auth info.
30
+ if (auth && !auth.username)
31
+ auth.username = username;
32
+ return auth;
33
+ }
34
+ has(username) {
35
+ return !!this.getAll()[username];
36
+ }
37
+ set(username, org) {
38
+ var _a;
39
+ // For legacy, and to keep things standard, some things wants the username in auth info.
40
+ (_a = org.username) !== null && _a !== void 0 ? _a : (org.username = username);
41
+ this.globalInfo.set(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
42
+ }
43
+ update(username, org) {
44
+ var _a;
45
+ // For legacy, and to keep things standard, some things wants the username in auth info.
46
+ (_a = org.username) !== null && _a !== void 0 ? _a : (org.username = username);
47
+ this.globalInfo.update(`${types_1.SfInfoKeys.ORGS}["${username}"]`, org);
48
+ }
49
+ unset(username) {
50
+ delete this.globalInfo.get(types_1.SfInfoKeys.ORGS)[username];
51
+ }
52
+ }
53
+ exports.GlobalInfoOrgAccessor = GlobalInfoOrgAccessor;
54
+ function chunk(array, chunkSize) {
55
+ const final = [];
56
+ for (let i = 0, len = array.length; i < len; i += chunkSize)
57
+ final.push(array.slice(i, i + chunkSize));
58
+ return final;
59
+ }
60
+ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
61
+ constructor() {
62
+ super(...arguments);
63
+ this.configs = new Map();
64
+ this.contents = new Map();
65
+ }
66
+ async read(username, decrypt = false, throwOnNotFound = true) {
67
+ try {
68
+ const config = await this.initAuthFile(username, throwOnNotFound);
69
+ this.configs.set(username, config);
70
+ return this.get(username, decrypt);
71
+ }
72
+ catch (err) {
73
+ return null;
74
+ }
75
+ }
76
+ async readAll(decrypt = false) {
77
+ const fileChunks = chunk(await this.getAllFiles(), 50);
78
+ for (const fileChunk of fileChunks) {
79
+ const promises = fileChunk.map(async (f) => {
80
+ const username = this.parseUsername(f);
81
+ const config = await this.initAuthFile(username);
82
+ this.configs.set(username, config);
83
+ });
84
+ await Promise.all(promises);
85
+ }
86
+ return this.getAll(decrypt);
87
+ }
88
+ get(username, decrypt = false) {
89
+ const config = this.configs.get(username);
90
+ if (config) {
91
+ this.contents.set(username, config.getContents(decrypt));
92
+ }
93
+ return this.contents.get(username);
94
+ }
95
+ getAll(decrypt = false) {
96
+ return [...this.configs.keys()].reduce((orgs, username) => {
97
+ const org = this.get(username, decrypt);
98
+ return org && !(0, kit_1.isEmpty)(org) ? orgs.concat([org]) : orgs;
99
+ }, []);
100
+ }
101
+ has(username) {
102
+ return this.contents.has(username);
103
+ }
104
+ async exists(username) {
105
+ const config = this.configs.get(username);
106
+ return config ? await config.exists() : false;
107
+ }
108
+ async hasFile(username) {
109
+ try {
110
+ await fs.promises.access(this.parseFilename(username));
111
+ return true;
112
+ }
113
+ catch {
114
+ this.logger.debug(`No auth file found for ${username}`);
115
+ return false;
116
+ }
117
+ }
118
+ async list() {
119
+ return this.getAllFiles();
120
+ }
121
+ set(username, org) {
122
+ var _a, _b;
123
+ const config = this.configs.get(username);
124
+ if (config) {
125
+ config.setContentsFromObject(org);
126
+ const contents = config.getContents();
127
+ (_a = contents.username) !== null && _a !== void 0 ? _a : (contents.username = username);
128
+ this.contents.set(username, contents);
129
+ }
130
+ else {
131
+ // @ts-ignore
132
+ (_b = org.username) !== null && _b !== void 0 ? _b : (org.username = username);
133
+ this.contents.set(username, org);
134
+ }
135
+ }
136
+ update(username, org) {
137
+ const existing = this.get(username) || {};
138
+ const merged = Object.assign({}, existing, org);
139
+ return this.set(username, merged);
140
+ }
141
+ async remove(username) {
142
+ var _a;
143
+ await ((_a = this.configs.get(username)) === null || _a === void 0 ? void 0 : _a.unlink());
144
+ this.configs.delete(username);
145
+ this.contents.delete(username);
146
+ }
147
+ async write(username) {
148
+ const config = this.configs.get(username);
149
+ if (config) {
150
+ return (await config.write());
151
+ }
152
+ else {
153
+ const contents = this.contents.get(username) || {};
154
+ await this.read(username, false, false);
155
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
156
+ const config = this.configs.get(username);
157
+ config.setContentsFromObject(contents);
158
+ return (await config.write());
159
+ }
160
+ }
161
+ async init() {
162
+ this.logger = await logger_1.Logger.child(this.constructor.name);
163
+ }
164
+ async getAllFiles() {
165
+ const regex = this.getFileRegex();
166
+ try {
167
+ return (await fs.promises.readdir(global_1.Global.DIR)).filter((file) => regex.test(file));
168
+ }
169
+ catch {
170
+ return [];
171
+ }
172
+ }
173
+ parseUsername(filename) {
174
+ return filename.replace(this.getFileExtension(), '');
175
+ }
176
+ parseFilename(username) {
177
+ return path.join(global_1.Global.DIR, `${username}${this.getFileExtension()}`);
178
+ }
179
+ }
180
+ exports.BaseOrgAccessor = BaseOrgAccessor;
181
+ class OrgAccessor extends BaseOrgAccessor {
182
+ async initAuthFile(username, throwOnNotFound = false) {
183
+ return authInfoConfig_1.AuthInfoConfig.create({
184
+ ...authInfoConfig_1.AuthInfoConfig.getOptions(username),
185
+ throwOnNotFound,
186
+ });
187
+ }
188
+ getFileRegex() {
189
+ // The regular expression that filters files stored in $HOME/.sfdx
190
+ return /^[^.][^@]*@[^.]+(\.[^.\s]+)+\.json$/;
191
+ }
192
+ getFileExtension() {
193
+ return '.json';
194
+ }
195
+ }
196
+ exports.OrgAccessor = OrgAccessor;
197
+ //# sourceMappingURL=orgAccessor.js.map
@@ -1,7 +1,13 @@
1
1
  import { Nullable } from '@salesforce/ts-types';
2
+ import { SandboxOrgConfig } from '../../config/sandboxOrgConfig';
3
+ import { SandboxFields } from '../../org';
2
4
  import { GlobalInfo } from '../globalInfoConfig';
3
5
  import { SfSandbox, SfSandboxes } from '../types';
4
- export declare class SandboxAccessor {
6
+ import { BaseOrgAccessor } from './orgAccessor';
7
+ /**
8
+ * @deprecated
9
+ */
10
+ export declare class GlobalInfoSandboxAccessor {
5
11
  private globalInfo;
6
12
  constructor(globalInfo: GlobalInfo);
7
13
  /**
@@ -34,3 +40,8 @@ export declare class SandboxAccessor {
34
40
  set(sandboxOrgId: string, entity: SfSandbox): void;
35
41
  unset(sandboxOrgId: string): void;
36
42
  }
43
+ export declare class SandboxAccessor extends BaseOrgAccessor<SandboxOrgConfig, SandboxFields> {
44
+ protected initAuthFile(username: string, throwOnNotFound?: boolean): Promise<SandboxOrgConfig>;
45
+ protected getFileRegex(): RegExp;
46
+ protected getFileExtension(): string;
47
+ }
@@ -6,9 +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.SandboxAccessor = void 0;
9
+ exports.SandboxAccessor = exports.GlobalInfoSandboxAccessor = void 0;
10
+ const sandboxOrgConfig_1 = require("../../config/sandboxOrgConfig");
10
11
  const types_1 = require("../types");
11
- class SandboxAccessor {
12
+ const orgAccessor_1 = require("./orgAccessor");
13
+ /**
14
+ * @deprecated
15
+ */
16
+ class GlobalInfoSandboxAccessor {
12
17
  constructor(globalInfo) {
13
18
  this.globalInfo = globalInfo;
14
19
  }
@@ -59,5 +64,20 @@ class SandboxAccessor {
59
64
  delete this.globalInfo.get(types_1.SfInfoKeys.SANDBOXES)[sandboxOrgId];
60
65
  }
61
66
  }
67
+ exports.GlobalInfoSandboxAccessor = GlobalInfoSandboxAccessor;
68
+ class SandboxAccessor extends orgAccessor_1.BaseOrgAccessor {
69
+ async initAuthFile(username, throwOnNotFound = false) {
70
+ return sandboxOrgConfig_1.SandboxOrgConfig.create({
71
+ ...sandboxOrgConfig_1.SandboxOrgConfig.getOptions(username),
72
+ throwOnNotFound,
73
+ });
74
+ }
75
+ getFileRegex() {
76
+ return /^(00D.*?)\.sandbox\.json$/;
77
+ }
78
+ getFileExtension() {
79
+ return '.sandbox.json';
80
+ }
81
+ }
62
82
  exports.SandboxAccessor = SandboxAccessor;
63
83
  //# sourceMappingURL=sandboxAccessor.js.map
@@ -0,0 +1,28 @@
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
+ }
18
+ export declare class TokenAccessor extends AsyncOptionalCreatable {
19
+ private config;
20
+ getAll(decrypt?: boolean): SfTokens;
21
+ get(name: string, decrypt?: boolean): Optional<SfToken & Timestamp>;
22
+ has(name: string): boolean;
23
+ set(name: string, token: SfToken): void;
24
+ update(name: string, token: Partial<SfToken>): void;
25
+ unset(name: string): void;
26
+ write(): Promise<SfTokens>;
27
+ protected init(): Promise<void>;
28
+ }
@@ -6,9 +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.TokenAccessor = void 0;
9
+ exports.TokenAccessor = exports.GlobaInfoTokenAccessor = void 0;
10
+ const kit_1 = require("@salesforce/kit");
11
+ const tokensConfig_1 = require("../../config/tokensConfig");
10
12
  const types_1 = require("../types");
11
- class TokenAccessor {
13
+ /**
14
+ * @deprecated
15
+ */
16
+ class GlobaInfoTokenAccessor {
12
17
  constructor(globalInfo) {
13
18
  this.globalInfo = globalInfo;
14
19
  }
@@ -31,5 +36,32 @@ class TokenAccessor {
31
36
  delete this.globalInfo.get(types_1.SfInfoKeys.TOKENS)[name];
32
37
  }
33
38
  }
39
+ exports.GlobaInfoTokenAccessor = GlobaInfoTokenAccessor;
40
+ class TokenAccessor extends kit_1.AsyncOptionalCreatable {
41
+ getAll(decrypt = false) {
42
+ return this.config.getContents(decrypt) || {};
43
+ }
44
+ get(name, decrypt = false) {
45
+ return this.config.get(name, decrypt);
46
+ }
47
+ has(name) {
48
+ return !!this.getAll()[name];
49
+ }
50
+ set(name, token) {
51
+ this.config.set(name, token);
52
+ }
53
+ update(name, token) {
54
+ this.config.update(name, token);
55
+ }
56
+ unset(name) {
57
+ this.config.unset(name);
58
+ }
59
+ async write() {
60
+ return this.config.write();
61
+ }
62
+ async init() {
63
+ this.config = await tokensConfig_1.TokensConfig.create();
64
+ }
65
+ }
34
66
  exports.TokenAccessor = TokenAccessor;
35
67
  //# sourceMappingURL=tokenAccessor.js.map
@@ -1,12 +1,15 @@
1
1
  import { AnyJson } from '@salesforce/ts-types';
2
2
  import { ConfigFile } from '../config/configFile';
3
3
  import { ConfigValue } from '../config/configStore';
4
- import { OrgAccessor } from './accessors/orgAccessor';
5
- import { TokenAccessor } from './accessors/tokenAccessor';
6
- import { AliasAccessor } from './accessors/aliasAccessor';
4
+ import { GlobalInfoOrgAccessor } from './accessors/orgAccessor';
5
+ import { GlobaInfoTokenAccessor } from './accessors/tokenAccessor';
6
+ import { GlobalInfoAliasAccessor } from './accessors/aliasAccessor';
7
7
  import { SfInfo } from './types';
8
- import { SandboxAccessor } from './accessors/sandboxAccessor';
8
+ import { GlobalInfoSandboxAccessor } from './accessors/sandboxAccessor';
9
9
  export declare function deepCopy<T extends AnyJson>(data: T): T;
10
+ /**
11
+ * @deprecated use StateAggregator instead.
12
+ */
10
13
  export declare class GlobalInfo extends ConfigFile<ConfigFile.Options, SfInfo> {
11
14
  protected static encryptedKeys: RegExp[];
12
15
  private static EMPTY_DATA_MODEL;
@@ -25,10 +28,10 @@ export declare class GlobalInfo extends ConfigFile<ConfigFile.Options, SfInfo> {
25
28
  * Gets default options for the SfConfig
26
29
  */
27
30
  static getDefaultOptions(): ConfigFile.Options;
28
- get orgs(): OrgAccessor;
29
- get tokens(): TokenAccessor;
30
- get aliases(): AliasAccessor;
31
- get sandboxes(): SandboxAccessor;
31
+ get orgs(): GlobalInfoOrgAccessor;
32
+ get tokens(): GlobaInfoTokenAccessor;
33
+ get aliases(): GlobalInfoAliasAccessor;
34
+ get sandboxes(): GlobalInfoSandboxAccessor;
32
35
  set(key: string, value: ConfigValue): void;
33
36
  write(newContents?: SfInfo): Promise<SfInfo>;
34
37
  protected init(): Promise<void>;