@salesforce/core 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +93 -44
  3. package/lib/config/authInfoConfig.d.ts +19 -0
  4. package/lib/config/authInfoConfig.js +35 -0
  5. package/lib/config/config.d.ts +87 -22
  6. package/lib/config/config.js +117 -65
  7. package/lib/config/configAggregator.d.ts +41 -35
  8. package/lib/config/configAggregator.js +102 -73
  9. package/lib/config/configFile.d.ts +2 -2
  10. package/lib/config/configFile.js +38 -29
  11. package/lib/config/configStore.d.ts +9 -9
  12. package/lib/config/configStore.js +17 -15
  13. package/lib/config/envVars.d.ts +15 -9
  14. package/lib/config/envVars.js +71 -47
  15. package/lib/config/orgUsersConfig.js +2 -0
  16. package/lib/config/sandboxOrgConfig.js +2 -0
  17. package/lib/config/sandboxProcessCache.d.ts +16 -0
  18. package/lib/config/sandboxProcessCache.js +38 -0
  19. package/lib/config/tokensConfig.d.ts +10 -0
  20. package/lib/config/tokensConfig.js +29 -0
  21. package/lib/config/ttlConfig.d.ts +34 -0
  22. package/lib/config/ttlConfig.js +50 -0
  23. package/lib/crypto/crypto.js +15 -22
  24. package/lib/crypto/keyChain.js +2 -3
  25. package/lib/crypto/keyChainImpl.d.ts +5 -3
  26. package/lib/crypto/keyChainImpl.js +58 -61
  27. package/lib/crypto/secureBuffer.d.ts +1 -1
  28. package/lib/deviceOauthService.d.ts +3 -3
  29. package/lib/deviceOauthService.js +27 -25
  30. package/lib/exported.d.ts +15 -12
  31. package/lib/exported.js +28 -16
  32. package/lib/global.d.ts +11 -3
  33. package/lib/global.js +39 -12
  34. package/lib/lifecycleEvents.d.ts +1 -1
  35. package/lib/lifecycleEvents.js +3 -0
  36. package/lib/logger.d.ts +19 -9
  37. package/lib/logger.js +112 -86
  38. package/lib/messages.d.ts +53 -36
  39. package/lib/messages.js +81 -91
  40. package/lib/org/authInfo.d.ts +56 -20
  41. package/lib/org/authInfo.js +232 -131
  42. package/lib/org/authRemover.d.ts +8 -7
  43. package/lib/org/authRemover.js +32 -28
  44. package/lib/org/connection.d.ts +13 -37
  45. package/lib/org/connection.js +78 -124
  46. package/lib/org/index.js +5 -1
  47. package/lib/org/org.d.ts +151 -48
  48. package/lib/org/org.js +468 -225
  49. package/lib/org/orgConfigProperties.d.ts +64 -3
  50. package/lib/org/orgConfigProperties.js +96 -4
  51. package/lib/org/permissionSetAssignment.js +4 -13
  52. package/lib/org/scratchOrgCache.d.ts +20 -0
  53. package/lib/org/scratchOrgCache.js +33 -0
  54. package/lib/org/scratchOrgCreate.d.ts +28 -17
  55. package/lib/org/scratchOrgCreate.js +125 -53
  56. package/lib/org/scratchOrgErrorCodes.d.ts +9 -3
  57. package/lib/org/scratchOrgErrorCodes.js +34 -17
  58. package/lib/org/scratchOrgFeatureDeprecation.js +1 -6
  59. package/lib/org/scratchOrgInfoApi.d.ts +21 -47
  60. package/lib/org/scratchOrgInfoApi.js +129 -63
  61. package/lib/org/scratchOrgInfoGenerator.d.ts +6 -5
  62. package/lib/org/scratchOrgInfoGenerator.js +76 -62
  63. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
  64. package/lib/org/scratchOrgLifecycleEvents.js +41 -0
  65. package/lib/org/scratchOrgSettingsGenerator.d.ts +44 -21
  66. package/lib/org/scratchOrgSettingsGenerator.js +165 -98
  67. package/lib/org/scratchOrgTypes.d.ts +43 -0
  68. package/lib/org/scratchOrgTypes.js +9 -0
  69. package/lib/org/user.d.ts +1 -1
  70. package/lib/org/user.js +25 -34
  71. package/lib/schema/printer.d.ts +6 -0
  72. package/lib/schema/printer.js +34 -31
  73. package/lib/schema/validator.d.ts +12 -10
  74. package/lib/schema/validator.js +56 -76
  75. package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -20
  76. package/lib/{sfdxError.js → sfError.js} +40 -30
  77. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
  78. package/lib/sfProject.js +651 -0
  79. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +129 -0
  80. package/lib/stateAggregator/accessors/aliasAccessor.js +263 -0
  81. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
  82. package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
  83. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
  84. package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
  85. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
  86. package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
  87. package/lib/stateAggregator/index.d.ts +4 -0
  88. package/lib/stateAggregator/index.js +27 -0
  89. package/lib/stateAggregator/stateAggregator.d.ts +25 -0
  90. package/lib/stateAggregator/stateAggregator.js +46 -0
  91. package/lib/status/myDomainResolver.d.ts +1 -1
  92. package/lib/status/myDomainResolver.js +4 -4
  93. package/lib/status/pollingClient.js +4 -4
  94. package/lib/status/streamingClient.d.ts +2 -2
  95. package/lib/status/streamingClient.js +58 -63
  96. package/lib/status/types.d.ts +2 -2
  97. package/lib/testSetup.d.ts +204 -75
  98. package/lib/testSetup.js +468 -164
  99. package/lib/util/cache.d.ts +2 -2
  100. package/lib/util/cache.js +6 -6
  101. package/lib/util/checkLightningDomain.js +3 -4
  102. package/lib/util/directoryWriter.d.ts +12 -0
  103. package/lib/util/directoryWriter.js +54 -0
  104. package/lib/util/getJwtAudienceUrl.js +1 -1
  105. package/lib/util/internal.d.ts +28 -2
  106. package/lib/util/internal.js +65 -8
  107. package/lib/util/jsonXmlTools.js +2 -4
  108. package/lib/util/mapKeys.d.ts +9 -9
  109. package/lib/util/mapKeys.js +13 -9
  110. package/lib/util/sfdc.d.ts +51 -51
  111. package/lib/util/sfdc.js +74 -79
  112. package/lib/util/sfdcUrl.d.ts +5 -19
  113. package/lib/util/sfdcUrl.js +40 -49
  114. package/lib/util/structuredWriter.d.ts +9 -0
  115. package/lib/util/structuredWriter.js +3 -0
  116. package/lib/util/zipWriter.d.ts +8 -6
  117. package/lib/util/zipWriter.js +13 -13
  118. package/lib/webOAuthServer.d.ts +20 -6
  119. package/lib/webOAuthServer.js +102 -56
  120. package/messageTransformer/messageTransformer.ts +93 -0
  121. package/messages/auth.md +9 -1
  122. package/messages/config.md +42 -6
  123. package/messages/connection.md +8 -0
  124. package/messages/core.md +10 -0
  125. package/messages/envVars.md +37 -3
  126. package/messages/org.md +21 -1
  127. package/messages/scratchOrgCreate.md +2 -6
  128. package/messages/scratchOrgErrorCodes.md +17 -1
  129. package/messages/scratchOrgInfoApi.md +9 -0
  130. package/messages/scratchOrgInfoGenerator.md +9 -1
  131. package/package.json +123 -46
  132. package/CHANGELOG.md +0 -1244
  133. package/lib/config/keychainConfig.d.ts +0 -19
  134. package/lib/config/keychainConfig.js +0 -43
  135. package/lib/globalInfo/accessors/aliasAccessor.d.ts +0 -83
  136. package/lib/globalInfo/accessors/aliasAccessor.js +0 -130
  137. package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
  138. package/lib/globalInfo/accessors/orgAccessor.js +0 -45
  139. package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
  140. package/lib/globalInfo/accessors/tokenAccessor.js +0 -35
  141. package/lib/globalInfo/globalInfoConfig.d.ts +0 -36
  142. package/lib/globalInfo/globalInfoConfig.js +0 -105
  143. package/lib/globalInfo/index.d.ts +0 -6
  144. package/lib/globalInfo/index.js +0 -29
  145. package/lib/globalInfo/sfdxDataHandler.d.ts +0 -43
  146. package/lib/globalInfo/sfdxDataHandler.js +0 -217
  147. package/lib/globalInfo/types.d.ts +0 -39
  148. package/lib/globalInfo/types.js +0 -10
  149. package/lib/sfdxProject.js +0 -557
  150. package/lib/util/fs.d.ts +0 -201
  151. package/lib/util/fs.js +0 -378
@@ -0,0 +1,240 @@
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 = 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 logger_1 = require("../../logger");
16
+ const messages_1 = require("../../messages");
17
+ function chunk(array, chunkSize) {
18
+ const final = [];
19
+ for (let i = 0, len = array.length; i < len; i += chunkSize)
20
+ final.push(array.slice(i, i + chunkSize));
21
+ return final;
22
+ }
23
+ class BaseOrgAccessor extends kit_1.AsyncOptionalCreatable {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.configs = new Map();
27
+ this.contents = new Map();
28
+ }
29
+ /**
30
+ * Read the auth file for the given username. Once the file has been read, it can be re-accessed with the `get` method.
31
+ *
32
+ * @param username username to read
33
+ * @param decrypt if true, decrypt encrypted values
34
+ * @param throwOnNotFound throw if file is not found for username
35
+ */
36
+ async read(username, decrypt = false, throwOnNotFound = true) {
37
+ try {
38
+ const config = await this.initAuthFile(username, throwOnNotFound);
39
+ this.configs.set(username, config);
40
+ return this.get(username, decrypt);
41
+ }
42
+ catch (err) {
43
+ return null;
44
+ }
45
+ }
46
+ /**
47
+ * Read all the auth files under the global state directory
48
+ *
49
+ * @param decrypt if true, decrypt encrypted values
50
+ */
51
+ async readAll(decrypt = false) {
52
+ const fileChunks = chunk(await this.getAllFiles(), 50);
53
+ for (const fileChunk of fileChunks) {
54
+ const promises = fileChunk.map(async (f) => {
55
+ const username = this.parseUsername(f);
56
+ const config = await this.initAuthFile(username);
57
+ this.configs.set(username, config);
58
+ });
59
+ // eslint-disable-next-line no-await-in-loop
60
+ await Promise.all(promises);
61
+ }
62
+ return this.getAll(decrypt);
63
+ }
64
+ /**
65
+ * Return the contents of the username's auth file from cache.
66
+ * The `read` or `readAll` methods must be called first in order to populate the cache.
67
+ * If throwOnNotFound is not true, an empty object {} is returned if the org is not found.
68
+ *
69
+ * @param username username to get
70
+ * @param decrypt if true, decrypt encrypted values
71
+ * @param throwOnNotFound if true, throw if the auth file does not already exist in the cache
72
+ */
73
+ get(username, decrypt = false, throwOnNotFound = false) {
74
+ const config = this.configs.get(username);
75
+ if (throwOnNotFound && config?.keys().length === 0) {
76
+ const messages = new messages_1.Messages('@salesforce/core', 'core', new Map([["authInfoCreationError", "Must pass a username and/or OAuth options when creating an AuthInfo instance."], ["authInfoOverwriteError", "Cannot create an AuthInfo instance that will overwrite existing auth data."], ["authInfoOverwriteError.actions", ["Create the AuthInfo instance using existing auth data by just passing the username. E.g., `AuthInfo.create({ username: 'my@user.org' });`."]], ["authCodeExchangeError", "Error authenticating with auth code due to: %s"], ["authCodeUsernameRetrievalError", "Could not retrieve the username after successful auth code exchange.\n\nDue to: %s"], ["jwtAuthError", "Error authenticating with JWT config due to: %s"], ["jwtAuthErrors", "Error authenticating with JWT.\nErrors encountered:\n%s"], ["refreshTokenAuthError", "Error authenticating with the refresh token due to: %s"], ["orgDataNotAvailableError", "An attempt to refresh the authentication token failed with a 'Data Not Found Error'. The org identified by username %s does not appear to exist. Likely cause is that the org was deleted by another user or has expired."], ["orgDataNotAvailableError.actions", ["Run `sfdx force:org:list --clean` to remove stale org authentications.", "Use `sfdx force:config:set` to update the defaultusername.", "Use `sfdx force:org:create` to create a new org.", "Use `sfdx auth` to authenticate an existing org."]], ["namedOrgNotFound", "No authorization information found for %s."], ["noAliasesFound", "Nothing to set."], ["invalidFormat", "Setting aliases must be in the format <key>=<value> but found: [%s]."], ["invalidJsonCasing", "All JSON input must have heads down camelcase keys. E.g., `{ sfdcLoginUrl: \"https://login.salesforce.com\" }`\nFound \"%s\" at %s"], ["missingClientId", "Client ID is required for JWT authentication."]]));
77
+ throw messages.createError('namedOrgNotFound', [username]);
78
+ }
79
+ if (config) {
80
+ this.contents.set(username, config.getContents(decrypt));
81
+ }
82
+ return this.contents.get(username);
83
+ }
84
+ /**
85
+ * Return the contents of all the auth files from cache. The `read` or `readAll` methods must be called first in order to populate the cache.
86
+ *
87
+ * @param decrypt if true, decrypt encrypted values
88
+ * @returns
89
+ */
90
+ getAll(decrypt = false) {
91
+ return [...this.configs.keys()].map((username) => this.get(username, decrypt)).filter((org) => !(0, kit_1.isEmpty)(org));
92
+ }
93
+ /**
94
+ * Returns true if the username has been cached.
95
+ *
96
+ * @param username
97
+ */
98
+ has(username) {
99
+ return this.contents.has(username);
100
+ }
101
+ /**
102
+ * Returns true if there is an auth file for the given username. The `read` or `readAll` methods must be called first in order to populate the cache.
103
+ *
104
+ * @param username
105
+ */
106
+ async exists(username) {
107
+ const config = this.configs.get(username);
108
+ return config ? config.exists() : false;
109
+ }
110
+ /**
111
+ * Return the file stats for a given userame's auth file.
112
+ *
113
+ * @param username
114
+ */
115
+ async stat(username) {
116
+ const config = this.configs.get(username);
117
+ return config ? config.stat() : null;
118
+ }
119
+ /**
120
+ * Returns true if there is an auth file for the given username
121
+ *
122
+ * @param username
123
+ */
124
+ async hasFile(username) {
125
+ try {
126
+ await fs.promises.access(this.parseFilename(username));
127
+ return true;
128
+ }
129
+ catch {
130
+ this.logger.debug(`No auth file found for ${username}`);
131
+ return false;
132
+ }
133
+ }
134
+ /**
135
+ * Return all auth files under the global state directory.
136
+ */
137
+ async list() {
138
+ return this.getAllFiles();
139
+ }
140
+ /**
141
+ * Set the contents for a given username.
142
+ *
143
+ * @param username
144
+ * @param org
145
+ */
146
+ set(username, org) {
147
+ const config = this.configs.get(username);
148
+ if (config) {
149
+ config.setContentsFromObject(org);
150
+ const contents = config.getContents();
151
+ contents.username ??= username;
152
+ this.contents.set(username, contents);
153
+ }
154
+ else {
155
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
156
+ // @ts-ignore
157
+ org.username ??= username;
158
+ this.contents.set(username, org);
159
+ }
160
+ }
161
+ /**
162
+ * Update the contents for a given username.
163
+ *
164
+ * @param username
165
+ * @param org
166
+ */
167
+ update(username, org) {
168
+ const existing = this.get(username) || {};
169
+ const merged = Object.assign({}, existing, org);
170
+ return this.set(username, merged);
171
+ }
172
+ /**
173
+ * Delete the auth file for a given username.
174
+ *
175
+ * @param username
176
+ */
177
+ async remove(username) {
178
+ await this.configs.get(username)?.unlink();
179
+ this.configs.delete(username);
180
+ this.contents.delete(username);
181
+ }
182
+ /**
183
+ * Write the contents of the auth file for a given username.
184
+ *
185
+ * @param username
186
+ */
187
+ async write(username) {
188
+ const config = this.configs.get(username);
189
+ if (config) {
190
+ return (await config.write());
191
+ }
192
+ else {
193
+ const contents = this.contents.get(username) ?? {};
194
+ await this.read(username, false, false);
195
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
196
+ const readConfig = this.configs.get(username);
197
+ readConfig.setContentsFromObject(contents);
198
+ return (await readConfig.write());
199
+ }
200
+ }
201
+ async init() {
202
+ this.logger = await logger_1.Logger.child(this.constructor.name);
203
+ }
204
+ async getAllFiles() {
205
+ const regex = this.getFileRegex();
206
+ try {
207
+ return (await fs.promises.readdir(global_1.Global.DIR)).filter((file) => regex.test(file));
208
+ }
209
+ catch {
210
+ return [];
211
+ }
212
+ }
213
+ parseUsername(filename) {
214
+ return filename.replace(this.getFileExtension(), '');
215
+ }
216
+ parseFilename(username) {
217
+ return path.join(global_1.Global.DIR, `${username}${this.getFileExtension()}`);
218
+ }
219
+ }
220
+ exports.BaseOrgAccessor = BaseOrgAccessor;
221
+ class OrgAccessor extends BaseOrgAccessor {
222
+ // eslint-disable-next-line class-methods-use-this
223
+ async initAuthFile(username, throwOnNotFound = false) {
224
+ return authInfoConfig_1.AuthInfoConfig.create({
225
+ ...authInfoConfig_1.AuthInfoConfig.getOptions(username),
226
+ throwOnNotFound,
227
+ });
228
+ }
229
+ // eslint-disable-next-line class-methods-use-this
230
+ getFileRegex() {
231
+ // The regular expression that filters files stored in $HOME/.sfdx
232
+ return /^[^.][^@]*@[^.]+(\.[^.\s]+)+\.json$/;
233
+ }
234
+ // eslint-disable-next-line class-methods-use-this
235
+ getFileExtension() {
236
+ return '.json';
237
+ }
238
+ }
239
+ exports.OrgAccessor = OrgAccessor;
240
+ //# sourceMappingURL=orgAccessor.js.map
@@ -0,0 +1,8 @@
1
+ import { SandboxOrgConfig } from '../../config/sandboxOrgConfig';
2
+ import { SandboxFields } from '../../org';
3
+ import { BaseOrgAccessor } from './orgAccessor';
4
+ export declare class SandboxAccessor extends BaseOrgAccessor<SandboxOrgConfig, SandboxFields> {
5
+ protected initAuthFile(username: string, throwOnNotFound?: boolean): Promise<SandboxOrgConfig>;
6
+ protected getFileRegex(): RegExp;
7
+ protected getFileExtension(): string;
8
+ }
@@ -0,0 +1,28 @@
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
+ /* eslint-disable class-methods-use-this */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.SandboxAccessor = void 0;
11
+ const sandboxOrgConfig_1 = require("../../config/sandboxOrgConfig");
12
+ const orgAccessor_1 = require("./orgAccessor");
13
+ class SandboxAccessor extends orgAccessor_1.BaseOrgAccessor {
14
+ async initAuthFile(username, throwOnNotFound = false) {
15
+ return sandboxOrgConfig_1.SandboxOrgConfig.create({
16
+ ...sandboxOrgConfig_1.SandboxOrgConfig.getOptions(username),
17
+ throwOnNotFound,
18
+ });
19
+ }
20
+ getFileRegex() {
21
+ return /^(00D.*?)\.sandbox\.json$/;
22
+ }
23
+ getFileExtension() {
24
+ return '.sandbox.json';
25
+ }
26
+ }
27
+ exports.SandboxAccessor = SandboxAccessor;
28
+ //# sourceMappingURL=sandboxAccessor.js.map
@@ -0,0 +1,63 @@
1
+ import { AsyncOptionalCreatable } from '@salesforce/kit';
2
+ import { JsonMap, Optional } from '@salesforce/ts-types';
3
+ export type SfToken = {
4
+ token: string;
5
+ url: string;
6
+ user?: string;
7
+ timestamp: string;
8
+ } & JsonMap;
9
+ export type SfTokens = {
10
+ [key: string]: SfToken;
11
+ };
12
+ export declare class TokenAccessor extends AsyncOptionalCreatable {
13
+ private config;
14
+ /**
15
+ * Return all tokens.
16
+ *
17
+ * @param decrypt
18
+ * @returns {SfTokens}
19
+ */
20
+ getAll(decrypt?: boolean): SfTokens;
21
+ /**
22
+ * Return a token for the provided name.
23
+ *
24
+ * @param name
25
+ * @param decrypt
26
+ * @returns {Optional<SfToken>}
27
+ */
28
+ get(name: string, decrypt?: boolean): Optional<SfToken>;
29
+ /**
30
+ * Return true if a given name has a token associated with it.
31
+ *
32
+ * @param name
33
+ * @returns {boolean}
34
+ */
35
+ has(name: string): boolean;
36
+ /**
37
+ * Set the token for the provided name.
38
+ *
39
+ * @param name
40
+ * @param token
41
+ */
42
+ set(name: string, token: Partial<SfToken>): void;
43
+ /**
44
+ * Update the token for the provided name.
45
+ *
46
+ * @param name
47
+ * @param token
48
+ */
49
+ update(name: string, token: Partial<SfToken>): void;
50
+ /**
51
+ * Unet the token for the provided name.
52
+ *
53
+ * @param name
54
+ */
55
+ unset(name: string): void;
56
+ /**
57
+ * Write the contents to the token file.
58
+ *
59
+ * @returns {Promise<SfTokens>}
60
+ */
61
+ write(): Promise<SfTokens>;
62
+ protected init(): Promise<void>;
63
+ }
@@ -0,0 +1,80 @@
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.TokenAccessor = void 0;
10
+ const kit_1 = require("@salesforce/kit");
11
+ const tokensConfig_1 = require("../../config/tokensConfig");
12
+ class TokenAccessor extends kit_1.AsyncOptionalCreatable {
13
+ /**
14
+ * Return all tokens.
15
+ *
16
+ * @param decrypt
17
+ * @returns {SfTokens}
18
+ */
19
+ getAll(decrypt = false) {
20
+ return this.config.getContents(decrypt) || {};
21
+ }
22
+ /**
23
+ * Return a token for the provided name.
24
+ *
25
+ * @param name
26
+ * @param decrypt
27
+ * @returns {Optional<SfToken>}
28
+ */
29
+ get(name, decrypt = false) {
30
+ return this.config.get(name, decrypt);
31
+ }
32
+ /**
33
+ * Return true if a given name has a token associated with it.
34
+ *
35
+ * @param name
36
+ * @returns {boolean}
37
+ */
38
+ has(name) {
39
+ return !!this.getAll()[name];
40
+ }
41
+ /**
42
+ * Set the token for the provided name.
43
+ *
44
+ * @param name
45
+ * @param token
46
+ */
47
+ set(name, token) {
48
+ this.config.set(name, token);
49
+ }
50
+ /**
51
+ * Update the token for the provided name.
52
+ *
53
+ * @param name
54
+ * @param token
55
+ */
56
+ update(name, token) {
57
+ this.config.update(name, token);
58
+ }
59
+ /**
60
+ * Unet the token for the provided name.
61
+ *
62
+ * @param name
63
+ */
64
+ unset(name) {
65
+ this.config.unset(name);
66
+ }
67
+ /**
68
+ * Write the contents to the token file.
69
+ *
70
+ * @returns {Promise<SfTokens>}
71
+ */
72
+ async write() {
73
+ return this.config.write();
74
+ }
75
+ async init() {
76
+ this.config = await tokensConfig_1.TokensConfig.create();
77
+ }
78
+ }
79
+ exports.TokenAccessor = TokenAccessor;
80
+ //# sourceMappingURL=tokenAccessor.js.map
@@ -0,0 +1,4 @@
1
+ export * from './accessors/orgAccessor';
2
+ export * from './accessors/aliasAccessor';
3
+ export * from './accessors/tokenAccessor';
4
+ export * from './stateAggregator';
@@ -0,0 +1,27 @@
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
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./accessors/orgAccessor"), exports);
24
+ __exportStar(require("./accessors/aliasAccessor"), exports);
25
+ __exportStar(require("./accessors/tokenAccessor"), exports);
26
+ __exportStar(require("./stateAggregator"), exports);
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,25 @@
1
+ import { AsyncOptionalCreatable } from '@salesforce/kit';
2
+ import { AliasAccessor } from './accessors/aliasAccessor';
3
+ import { OrgAccessor } from './accessors/orgAccessor';
4
+ import { SandboxAccessor } from './accessors/sandboxAccessor';
5
+ import { TokenAccessor } from './accessors/tokenAccessor';
6
+ export declare class StateAggregator extends AsyncOptionalCreatable {
7
+ private static instanceMap;
8
+ aliases: AliasAccessor;
9
+ orgs: OrgAccessor;
10
+ sandboxes: SandboxAccessor;
11
+ tokens: TokenAccessor;
12
+ /**
13
+ * Reuse a StateAggregator if one was already created for the current global state directory
14
+ * Otherwise, create one and adds it to map for future reuse.
15
+ * HomeDir might be stubbed in tests
16
+ */
17
+ static getInstance(): Promise<StateAggregator>;
18
+ /**
19
+ * Clear the cache to force reading from disk.
20
+ *
21
+ * *NOTE: Only call this method if you must and you know what you are doing.*
22
+ */
23
+ static clearInstance(path?: string): void;
24
+ protected init(): Promise<void>;
25
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, 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.StateAggregator = void 0;
10
+ const kit_1 = require("@salesforce/kit");
11
+ const global_1 = require("../global");
12
+ const aliasAccessor_1 = require("./accessors/aliasAccessor");
13
+ const orgAccessor_1 = require("./accessors/orgAccessor");
14
+ const sandboxAccessor_1 = require("./accessors/sandboxAccessor");
15
+ const tokenAccessor_1 = require("./accessors/tokenAccessor");
16
+ class StateAggregator extends kit_1.AsyncOptionalCreatable {
17
+ /**
18
+ * Reuse a StateAggregator if one was already created for the current global state directory
19
+ * Otherwise, create one and adds it to map for future reuse.
20
+ * HomeDir might be stubbed in tests
21
+ */
22
+ static async getInstance() {
23
+ if (!StateAggregator.instanceMap.has(global_1.Global.DIR)) {
24
+ StateAggregator.instanceMap.set(global_1.Global.DIR, await StateAggregator.create());
25
+ }
26
+ // TS assertion is valid because there either was one OR it was just now instantiated
27
+ return StateAggregator.instanceMap.get(global_1.Global.DIR);
28
+ }
29
+ /**
30
+ * Clear the cache to force reading from disk.
31
+ *
32
+ * *NOTE: Only call this method if you must and you know what you are doing.*
33
+ */
34
+ static clearInstance(path = global_1.Global.DIR) {
35
+ StateAggregator.instanceMap.delete(path);
36
+ }
37
+ async init() {
38
+ this.orgs = await orgAccessor_1.OrgAccessor.create();
39
+ this.sandboxes = await sandboxAccessor_1.SandboxAccessor.create();
40
+ this.aliases = await aliasAccessor_1.AliasAccessor.create();
41
+ this.tokens = await tokenAccessor_1.TokenAccessor.create();
42
+ }
43
+ }
44
+ exports.StateAggregator = StateAggregator;
45
+ StateAggregator.instanceMap = new Map();
46
+ //# sourceMappingURL=stateAggregator.js.map
@@ -2,7 +2,7 @@
2
2
  import { URL } from 'url';
3
3
  import { AsyncOptionalCreatable, Duration } from '@salesforce/kit';
4
4
  /**
5
- * A class used to resolve MyDomains. After a ScratchOrg is created it's host name my not be propagated to the
5
+ * A class used to resolve MyDomains. After a ScratchOrg is created its host name my not be propagated to the
6
6
  * Salesforce DNS service. This service is not exclusive to Salesforce My Domain URL and could be used for any hostname.
7
7
  *
8
8
  * ```
@@ -20,7 +20,7 @@ const DNS_TIMEOUT = Math.max(3, new kit_1.Env().getNumber('SFDX_DNS_TIMEOUT', 3)
20
20
  // Retry frequency for DNS lookup polling defaults to 1 second and should be at least 1 second
21
21
  const DNS_RETRY_FREQ = Math.max(1, new kit_1.Env().getNumber('SFDX_DNS_RETRY_FREQUENCY', 1));
22
22
  /**
23
- * A class used to resolve MyDomains. After a ScratchOrg is created it's host name my not be propagated to the
23
+ * A class used to resolve MyDomains. After a ScratchOrg is created its host name my not be propagated to the
24
24
  * Salesforce DNS service. This service is not exclusive to Salesforce My Domain URL and could be used for any hostname.
25
25
  *
26
26
  * ```
@@ -45,13 +45,13 @@ class MyDomainResolver extends kit_1.AsyncOptionalCreatable {
45
45
  */
46
46
  constructor(options) {
47
47
  super(options);
48
- this.options = options || { url: MyDomainResolver.DEFAULT_DOMAIN };
48
+ this.options = options ?? { url: MyDomainResolver.DEFAULT_DOMAIN };
49
49
  }
50
50
  getTimeout() {
51
- return this.options.timeout || kit_1.Duration.seconds(DNS_TIMEOUT);
51
+ return this.options.timeout ?? kit_1.Duration.seconds(DNS_TIMEOUT);
52
52
  }
53
53
  getFrequency() {
54
- return this.options.frequency || kit_1.Duration.seconds(DNS_RETRY_FREQ);
54
+ return this.options.frequency ?? kit_1.Duration.seconds(DNS_RETRY_FREQ);
55
55
  }
56
56
  /**
57
57
  * Method that performs the dns lookup of the host. If the lookup fails the internal polling client will try again
@@ -11,7 +11,7 @@ const kit_1 = require("@salesforce/kit");
11
11
  const ts_types_1 = require("@salesforce/ts-types");
12
12
  const ts_retry_promise_1 = require("ts-retry-promise");
13
13
  const logger_1 = require("../logger");
14
- const sfdxError_1 = require("../sfdxError");
14
+ const sfError_1 = require("../sfError");
15
15
  const lifecycleEvents_1 = require("../lifecycleEvents");
16
16
  /**
17
17
  * This is a polling client that can be used to poll the status of long running tasks. It can be used as a replacement
@@ -53,7 +53,6 @@ class PollingClient extends kit_1.AsyncOptionalCreatable {
53
53
  * in the polling options.
54
54
  */
55
55
  async subscribe() {
56
- var _a;
57
56
  let errorInPollingFunction; // keep this around for returning in the catch block
58
57
  const doPoll = async () => {
59
58
  let result;
@@ -65,7 +64,7 @@ class PollingClient extends kit_1.AsyncOptionalCreatable {
65
64
  if (['ETIMEDOUT', 'ENOTFOUND', 'ECONNRESET', 'socket hang up'].some((retryableNetworkError) => err.message.includes(retryableNetworkError))) {
66
65
  this.logger.debug('Network error on the request', err);
67
66
  await lifecycleEvents_1.Lifecycle.getInstance().emitWarning('Network error occurred. Continuing to poll.');
68
- throw sfdxError_1.SfdxError.wrap(err);
67
+ throw sfError_1.SfError.wrap(err);
69
68
  }
70
69
  // there was an actual error thrown, so we don't want to keep retrying
71
70
  throw new ts_retry_promise_1.NotRetryableError(err.name);
@@ -87,8 +86,9 @@ class PollingClient extends kit_1.AsyncOptionalCreatable {
87
86
  if (errorInPollingFunction) {
88
87
  throw errorInPollingFunction;
89
88
  }
89
+ await lifecycleEvents_1.Lifecycle.getInstance().emit('POLLING_TIME_OUT', error);
90
90
  this.logger.debug('Polling timed out');
91
- throw new sfdxError_1.SfdxError('The client has timed out.', (_a = this.options.timeoutErrorName) !== null && _a !== void 0 ? _a : 'PollingClientTimeout');
91
+ throw new sfError_1.SfError('The client has timed out.', this.options.timeoutErrorName ?? 'PollingClientTimeout');
92
92
  }
93
93
  }
94
94
  }
@@ -1,6 +1,6 @@
1
1
  import { AsyncOptionalCreatable, Duration, Env } from '@salesforce/kit/lib';
2
2
  import { AnyJson } from '@salesforce/ts-types/lib';
3
- import { Org } from '../org';
3
+ import { Org } from '../org/org';
4
4
  import { CometClient, CometSubscription, Message, StatusResult, StreamingExtension, StreamProcessor } from './types';
5
5
  export { CometClient, CometSubscription, Message, StatusResult, StreamingExtension, StreamProcessor };
6
6
  /**
@@ -113,7 +113,7 @@ export declare class StreamingClient extends AsyncOptionalCreatable<StreamingCli
113
113
  * Subscribe to streaming events. When the streaming processor that's set in the options completes execution it
114
114
  * returns a payload in the StatusResult object. The payload is just echoed here for convenience.
115
115
  *
116
- * **Throws** *{@link SfdxError}{ name: '{@link StreamingClient.TimeoutErrorType.SUBSCRIBE}'}* When the subscribe timeout occurs.
116
+ * **Throws** *{@link SfError}{ name: '{@link StreamingClient.TimeoutErrorType.SUBSCRIBE}'}* When the subscribe timeout occurs.
117
117
  *
118
118
  * @param streamInit This function should call the platform apis that result in streaming updates on push topics.
119
119
  * {@link StatusResult}