@salesforce/core 4.0.0-v3.0 → 4.0.1

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 (160) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +93 -44
  3. package/lib/config/aliasesConfig.d.ts +12 -0
  4. package/lib/config/aliasesConfig.js +28 -0
  5. package/lib/config/authInfoConfig.d.ts +19 -0
  6. package/lib/config/authInfoConfig.js +35 -0
  7. package/lib/config/config.d.ts +181 -48
  8. package/lib/config/config.js +382 -159
  9. package/lib/config/configAggregator.d.ts +59 -42
  10. package/lib/config/configAggregator.js +135 -82
  11. package/lib/config/configFile.d.ts +2 -2
  12. package/lib/config/configFile.js +40 -31
  13. package/lib/config/configGroup.d.ts +9 -9
  14. package/lib/config/configGroup.js +13 -11
  15. package/lib/config/configStore.d.ts +9 -9
  16. package/lib/config/configStore.js +29 -26
  17. package/lib/config/envVars.d.ts +102 -0
  18. package/lib/config/envVars.js +457 -0
  19. package/lib/config/orgUsersConfig.d.ts +8 -0
  20. package/lib/config/orgUsersConfig.js +12 -0
  21. package/lib/config/sandboxOrgConfig.d.ts +8 -0
  22. package/lib/config/sandboxOrgConfig.js +12 -0
  23. package/lib/config/sandboxProcessCache.d.ts +16 -0
  24. package/lib/config/sandboxProcessCache.js +38 -0
  25. package/lib/config/tokensConfig.d.ts +10 -0
  26. package/lib/config/tokensConfig.js +29 -0
  27. package/lib/config/ttlConfig.d.ts +34 -0
  28. package/lib/config/ttlConfig.js +50 -0
  29. package/lib/crypto/crypto.js +29 -16
  30. package/lib/crypto/keyChain.js +4 -4
  31. package/lib/crypto/keyChainImpl.d.ts +5 -3
  32. package/lib/crypto/keyChainImpl.js +65 -66
  33. package/lib/crypto/secureBuffer.d.ts +1 -1
  34. package/lib/crypto/secureBuffer.js +1 -1
  35. package/lib/deviceOauthService.d.ts +5 -5
  36. package/lib/deviceOauthService.js +37 -33
  37. package/lib/exported.d.ts +22 -15
  38. package/lib/exported.js +49 -25
  39. package/lib/global.d.ts +17 -3
  40. package/lib/global.js +46 -13
  41. package/lib/lifecycleEvents.d.ts +39 -2
  42. package/lib/lifecycleEvents.js +77 -3
  43. package/lib/logger.d.ts +21 -11
  44. package/lib/logger.js +121 -105
  45. package/lib/messages.d.ts +53 -36
  46. package/lib/messages.js +89 -97
  47. package/lib/org/authInfo.d.ts +84 -72
  48. package/lib/org/authInfo.js +326 -320
  49. package/lib/org/authRemover.d.ts +16 -23
  50. package/lib/org/authRemover.js +62 -60
  51. package/lib/org/connection.d.ts +33 -59
  52. package/lib/org/connection.js +129 -190
  53. package/lib/org/index.js +6 -2
  54. package/lib/org/org.d.ts +263 -38
  55. package/lib/org/org.js +734 -149
  56. package/lib/org/orgConfigProperties.d.ts +69 -0
  57. package/lib/org/orgConfigProperties.js +121 -0
  58. package/lib/org/permissionSetAssignment.js +6 -15
  59. package/lib/org/scratchOrgCache.d.ts +20 -0
  60. package/lib/org/scratchOrgCache.js +33 -0
  61. package/lib/org/scratchOrgCreate.d.ts +54 -0
  62. package/lib/org/scratchOrgCreate.js +214 -0
  63. package/lib/org/scratchOrgErrorCodes.d.ts +10 -0
  64. package/lib/org/scratchOrgErrorCodes.js +79 -0
  65. package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -0
  66. package/lib/org/scratchOrgFeatureDeprecation.js +105 -0
  67. package/lib/org/scratchOrgInfoApi.d.ts +68 -0
  68. package/lib/org/scratchOrgInfoApi.js +416 -0
  69. package/lib/org/scratchOrgInfoGenerator.d.ts +64 -0
  70. package/lib/org/scratchOrgInfoGenerator.js +237 -0
  71. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
  72. package/lib/org/scratchOrgLifecycleEvents.js +41 -0
  73. package/lib/org/scratchOrgSettingsGenerator.d.ts +79 -0
  74. package/lib/org/scratchOrgSettingsGenerator.js +277 -0
  75. package/lib/org/scratchOrgTypes.d.ts +43 -0
  76. package/lib/{status/client.js → org/scratchOrgTypes.js} +1 -1
  77. package/lib/org/user.d.ts +7 -2
  78. package/lib/org/user.js +78 -54
  79. package/lib/schema/printer.d.ts +6 -0
  80. package/lib/schema/printer.js +49 -46
  81. package/lib/schema/validator.d.ts +12 -10
  82. package/lib/schema/validator.js +56 -76
  83. package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -15
  84. package/lib/{sfdxError.js → sfError.js} +42 -24
  85. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
  86. package/lib/sfProject.js +651 -0
  87. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -0
  88. package/lib/stateAggregator/accessors/aliasAccessor.js +146 -0
  89. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
  90. package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
  91. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
  92. package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
  93. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
  94. package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
  95. package/lib/stateAggregator/index.d.ts +4 -0
  96. package/lib/stateAggregator/index.js +27 -0
  97. package/lib/stateAggregator/stateAggregator.d.ts +25 -0
  98. package/lib/stateAggregator/stateAggregator.js +46 -0
  99. package/lib/status/myDomainResolver.d.ts +1 -1
  100. package/lib/status/myDomainResolver.js +10 -10
  101. package/lib/status/pollingClient.d.ts +2 -6
  102. package/lib/status/pollingClient.js +38 -64
  103. package/lib/status/streamingClient.d.ts +5 -80
  104. package/lib/status/streamingClient.js +74 -94
  105. package/lib/status/types.d.ts +89 -0
  106. package/lib/status/types.js +18 -0
  107. package/lib/testSetup.d.ts +212 -79
  108. package/lib/testSetup.js +478 -182
  109. package/lib/util/cache.d.ts +11 -0
  110. package/lib/util/cache.js +70 -0
  111. package/lib/util/checkLightningDomain.d.ts +1 -0
  112. package/lib/util/checkLightningDomain.js +29 -0
  113. package/lib/util/directoryWriter.d.ts +12 -0
  114. package/lib/util/directoryWriter.js +54 -0
  115. package/lib/util/getJwtAudienceUrl.d.ts +4 -0
  116. package/lib/util/getJwtAudienceUrl.js +19 -0
  117. package/lib/util/internal.d.ts +28 -2
  118. package/lib/util/internal.js +65 -8
  119. package/lib/util/jsonXmlTools.d.ts +14 -0
  120. package/lib/util/jsonXmlTools.js +39 -0
  121. package/lib/util/mapKeys.d.ts +14 -0
  122. package/lib/util/mapKeys.js +52 -0
  123. package/lib/util/sfdc.d.ts +51 -63
  124. package/lib/util/sfdc.js +75 -127
  125. package/lib/util/sfdcUrl.d.ts +64 -0
  126. package/lib/util/sfdcUrl.js +197 -0
  127. package/lib/util/structuredWriter.d.ts +9 -0
  128. package/lib/util/structuredWriter.js +3 -0
  129. package/lib/util/zipWriter.d.ts +16 -0
  130. package/lib/util/zipWriter.js +68 -0
  131. package/lib/webOAuthServer.d.ts +20 -7
  132. package/lib/webOAuthServer.js +107 -60
  133. package/messageTransformer/messageTransformer.ts +93 -0
  134. package/messages/auth.md +11 -3
  135. package/messages/config.md +94 -6
  136. package/messages/connection.md +8 -0
  137. package/messages/core.json +3 -3
  138. package/messages/core.md +11 -1
  139. package/messages/envVars.md +313 -0
  140. package/messages/org.md +64 -0
  141. package/messages/scratchOrgCreate.md +23 -0
  142. package/messages/scratchOrgErrorCodes.md +115 -0
  143. package/messages/scratchOrgFeatureDeprecation.md +11 -0
  144. package/messages/scratchOrgInfoApi.md +20 -0
  145. package/messages/scratchOrgInfoGenerator.md +27 -0
  146. package/messages/user.md +12 -0
  147. package/package.json +138 -66
  148. package/CHANGELOG.md +0 -699
  149. package/lib/config/aliases.d.ts +0 -56
  150. package/lib/config/aliases.js +0 -96
  151. package/lib/config/globalInfoConfig.d.ts +0 -74
  152. package/lib/config/globalInfoConfig.js +0 -144
  153. package/lib/config/keychainConfig.d.ts +0 -19
  154. package/lib/config/keychainConfig.js +0 -43
  155. package/lib/config/sfdxDataHandler.d.ts +0 -36
  156. package/lib/config/sfdxDataHandler.js +0 -165
  157. package/lib/sfdxProject.js +0 -546
  158. package/lib/status/client.d.ts +0 -15
  159. package/lib/util/fs.d.ts +0 -198
  160. package/lib/util/fs.js +0 -374
package/lib/messages.js CHANGED
@@ -13,16 +13,8 @@ const path = require("path");
13
13
  const util = require("util");
14
14
  const ts_types_1 = require("@salesforce/ts-types");
15
15
  const kit_1 = require("@salesforce/kit");
16
- const sfdxError_1 = require("./sfdxError");
17
- class Key {
18
- constructor(packageName, bundleName) {
19
- this.packageName = packageName;
20
- this.bundleName = bundleName;
21
- }
22
- toString() {
23
- return `${this.packageName}:${this.bundleName}`;
24
- }
25
- }
16
+ const sfError_1 = require("./sfError");
17
+ const getKey = (packageName, bundleName) => `${packageName}:${bundleName}`;
26
18
  const REGEXP_NO_CONTENT = /^\s*$/g;
27
19
  const REGEXP_NO_CONTENT_SECTION = /^#\s*/gm;
28
20
  const REGEXP_MD_IS_LIST_ROW = /^[*-]\s+|^ {2}/;
@@ -57,7 +49,7 @@ const markdownLoader = (filePath, fileContents) => {
57
49
  }
58
50
  }
59
51
  else {
60
- // use error instead of SfdxError because messages.js should have no internal dependencies.
52
+ // use error instead of SfError because messages.js should have no internal dependencies.
61
53
  throw new Error(`Invalid markdown message file: ${filePath}\nThe line "# <key>" must be immediately followed by the message on a new line.`);
62
54
  }
63
55
  }
@@ -67,16 +59,17 @@ const jsAndJsonLoader = (filePath, fileContents) => {
67
59
  let json;
68
60
  try {
69
61
  json = JSON.parse(fileContents);
70
- if (!ts_types_1.isObject(json)) {
62
+ if (!(0, ts_types_1.isObject)(json)) {
71
63
  // Bubble up
72
64
  throw new Error(`Unexpected token. Found returned content type '${typeof json}'.`);
73
65
  }
74
66
  }
75
67
  catch (err) {
76
68
  // Provide a nicer error message for a common JSON parse error; Unexpected token
77
- if (err.message.startsWith('Unexpected token')) {
78
- const parseError = new Error(`Invalid JSON content in message file: ${filePath}\n${err.message}`);
79
- parseError.name = err.name;
69
+ const error = err;
70
+ if (error.message.startsWith('Unexpected token')) {
71
+ const parseError = new Error(`Invalid JSON content in message file: ${filePath}\n${error.message}`);
72
+ parseError.name = error.name;
80
73
  throw parseError;
81
74
  }
82
75
  throw err;
@@ -147,7 +140,7 @@ const jsAndJsonLoader = (filePath, fileContents) => {
147
140
  *
148
141
  * // Now you can use the messages from anywhere in your code or file.
149
142
  * // If using importMessageDirectory, the bundle name is the file name.
150
- * const messages: Messages = Messages.load(packageName, bundleName);
143
+ * const messages: Messages = Messages.loadMessages(packageName, bundleName);
151
144
  *
152
145
  * // Messages now contains all the message in the bundleName file.
153
146
  * messages.getMessage('authInfoCreationError');
@@ -157,7 +150,7 @@ class Messages {
157
150
  /**
158
151
  * Create a new messages bundle.
159
152
  *
160
- * **Note:** Use {Messages.load} unless you are writing your own loader function.
153
+ * **Note:** Use {Messages.loadMessages} unless you are writing your own loader function.
161
154
  *
162
155
  * @param bundleName The bundle name.
163
156
  * @param locale The locale.
@@ -176,14 +169,14 @@ class Messages {
176
169
  return 'en_US';
177
170
  }
178
171
  /**
179
- * Set a custom loader function for a package and bundle that will be called on {@link Messages.load}.
172
+ * Set a custom loader function for a package and bundle that will be called on {@link Messages.loadMessages}.
180
173
  *
181
174
  * @param packageName The npm package name.
182
175
  * @param bundle The name of the bundle.
183
176
  * @param loader The loader function.
184
177
  */
185
178
  static setLoaderFunction(packageName, bundle, loader) {
186
- this.loaders.set(new Key(packageName, bundle).toString(), loader);
179
+ this.loaders.set(getKey(packageName, bundle), loader);
187
180
  }
188
181
  /**
189
182
  * Generate a file loading function. Use {@link Messages.importMessageFile} unless
@@ -216,7 +209,7 @@ class Messages {
216
209
  if (!fileContents || fileContents.trim().length === 0) {
217
210
  // messages.js should have no internal dependencies.
218
211
  const error = new Error(`Invalid message file: ${filePath}. No content.`);
219
- error.name = 'SfdxError';
212
+ error.name = 'SfError';
220
213
  throw error;
221
214
  }
222
215
  const map = parser(filePath, fileContents);
@@ -238,7 +231,7 @@ class Messages {
238
231
  }
239
232
  /**
240
233
  * Import all json and js files in a messages directory. Use the file name as the bundle key when
241
- * {@link Messages.load} is called. By default, we're assuming the moduleDirectoryPart is a
234
+ * {@link Messages.loadMessages} is called. By default, we're assuming the moduleDirectoryPart is a
242
235
  * typescript project and will truncate to root path (where the package.json file is). If your messages
243
236
  * directory is in another spot or you are not using typescript, pass in false for truncateToProjectPath.
244
237
  *
@@ -275,7 +268,7 @@ class Messages {
275
268
  if (!packageName) {
276
269
  const errMessage = `Invalid or missing package.json file at '${moduleMessagesDirPath}'. If not using a package.json, pass in a packageName.`;
277
270
  try {
278
- packageName = ts_types_1.asString(ts_types_1.ensureJsonMap(Messages.readFile(path.join(moduleMessagesDirPath, 'package.json'))).name);
271
+ packageName = (0, ts_types_1.asString)((0, ts_types_1.ensureJsonMap)(Messages.readFile(path.join(moduleMessagesDirPath, 'package.json'))).name);
279
272
  if (!packageName) {
280
273
  throw new kit_1.NamedError('MissingPackageName', errMessage);
281
274
  }
@@ -303,83 +296,33 @@ class Messages {
303
296
  * Load messages for a given package and bundle. If the bundle is not already cached, use the loader function
304
297
  * created from {@link Messages.setLoaderFunction} or {@link Messages.importMessagesDirectory}.
305
298
  *
306
- * **NOTE: Use {@link Messages.load} instead for safe message validation and usage.**
307
- *
308
299
  * ```typescript
309
300
  * Messages.importMessagesDirectory(__dirname);
310
- * const messages = Messages.load('packageName', 'bundleName');
301
+ * const messages = Messages.loadMessages('packageName', 'bundleName');
311
302
  * ```
312
303
  *
313
304
  * @param packageName The name of the npm package.
314
305
  * @param bundleName The name of the bundle to load.
315
306
  */
316
307
  static loadMessages(packageName, bundleName) {
317
- const key = new Key(packageName, bundleName);
318
- let messages;
319
- if (this.isCached(packageName, bundleName)) {
320
- messages = this.bundles.get(key.toString());
321
- }
322
- else if (this.loaders.has(key.toString())) {
323
- const loader = this.loaders.get(key.toString());
324
- if (loader) {
325
- messages = loader(Messages.getLocale());
326
- this.bundles.set(key.toString(), messages);
327
- messages = this.bundles.get(key.toString());
328
- }
329
- }
330
- if (messages) {
331
- return messages;
332
- }
333
- // Don't use messages inside messages
334
- throw new kit_1.NamedError('MissingBundleError', `Missing bundle ${key.toString()} for locale ${Messages.getLocale()}.`);
335
- }
336
- /**
337
- * Load messages for a given package and bundle. If the bundle is not already cached, use the loader function
338
- * created from {@link Messages.setLoaderFunction} or {@link Messages.importMessagesDirectory}.
339
- *
340
- * The message keys that will be used must be passed in for validation. This prevents runtime errors if messages are used but not defined.
341
- *
342
- * **NOTE: This should be defined at the top of the file so validation is done at load time rather than runtime.**
343
- *
344
- * ```typescript
345
- * Messages.importMessagesDirectory(__dirname);
346
- * const messages = Messages.load('packageName', 'bundleName', [
347
- * 'messageKey1',
348
- * 'messageKey2',
349
- * ]);
350
- * ```
351
- *
352
- * @param packageName The name of the npm package.
353
- * @param bundleName The name of the bundle to load.
354
- * @param keys The message keys that will be used.
355
- */
356
- static load(packageName, bundleName, keys) {
357
- const key = new Key(packageName, bundleName);
308
+ const key = getKey(packageName, bundleName);
358
309
  let messages;
359
310
  if (this.isCached(packageName, bundleName)) {
360
- messages = this.bundles.get(key.toString());
311
+ messages = this.bundles.get(key);
361
312
  }
362
- else if (this.loaders.has(key.toString())) {
363
- const loader = this.loaders.get(key.toString());
313
+ else if (this.loaders.has(key)) {
314
+ const loader = this.loaders.get(key);
364
315
  if (loader) {
365
316
  messages = loader(Messages.getLocale());
366
- this.bundles.set(key.toString(), messages);
367
- messages = this.bundles.get(key.toString());
317
+ this.bundles.set(key, messages);
318
+ messages = this.bundles.get(key);
368
319
  }
369
320
  }
370
321
  if (messages) {
371
- // Type gaurd on key length, but do a runtime check.
372
- if (!keys || keys.length === 0) {
373
- throw new kit_1.NamedError('MissingKeysError', 'Can not load messages without providing the message keys that will be used.');
374
- }
375
- // Get all messages to validate they are actually present
376
- for (const messageKey of keys) {
377
- messages.getMessage(messageKey);
378
- }
379
322
  return messages;
380
323
  }
381
324
  // Don't use messages inside messages
382
- throw new kit_1.NamedError('MissingBundleError', `Missing bundle ${key.toString()} for locale ${Messages.getLocale()}.`);
325
+ throw new kit_1.NamedError('MissingBundleError', `Missing bundle ${key} for locale ${Messages.getLocale()}.`);
383
326
  }
384
327
  /**
385
328
  * Check if a bundle already been loaded.
@@ -388,7 +331,7 @@ class Messages {
388
331
  * @param bundleName The bundle name.
389
332
  */
390
333
  static isCached(packageName, bundleName) {
391
- return this.bundles.has(new Key(packageName, bundleName).toString());
334
+ return this.bundles.has(getKey(packageName, bundleName));
392
335
  }
393
336
  /**
394
337
  * Get a message using a message key and use the tokens as values for tokenization.
@@ -437,24 +380,74 @@ class Messages {
437
380
  * @param key The key of the error message.
438
381
  * @param tokens The error message tokens.
439
382
  * @param actionTokens The action messages tokens.
440
- * @param exitCodeOrCause The exit code which will be used by SfdxCommand or he underlying error that caused this error to be raised.
383
+ * @param exitCodeOrCause The exit code which will be used by SfdxCommand or the underlying error that caused this error to be raised.
441
384
  * @param cause The underlying error that caused this error to be raised.
442
385
  */
443
386
  createError(key, tokens = [], actionTokens = [], exitCodeOrCause, cause) {
387
+ const { message, name, actions } = this.formatMessageContents({
388
+ type: 'error',
389
+ key,
390
+ tokens,
391
+ actionTokens,
392
+ });
393
+ return new sfError_1.SfError(message, name, actions, exitCodeOrCause, cause);
394
+ }
395
+ /**
396
+ * Convenience method to create warning using message labels.
397
+ *
398
+ * `warning.name` will be the upper-cased key, remove prefixed `warning.` and will always end in Warning.
399
+ * `warning.actions` will be loaded using `${key}.actions` if available.
400
+ *
401
+ * @param key The key of the warning message.
402
+ * @param tokens The warning message tokens.
403
+ * @param actionTokens The action messages tokens.
404
+ */
405
+ createWarning(key, tokens = [], actionTokens = []) {
406
+ return this.formatMessageContents({ type: 'warning', key, tokens, actionTokens });
407
+ }
408
+ /**
409
+ * Convenience method to create info using message labels.
410
+ *
411
+ * `info.name` will be the upper-cased key, remove prefixed `info.` and will always end in Info.
412
+ * `info.actions` will be loaded using `${key}.actions` if available.
413
+ *
414
+ * @param key The key of the warning message.
415
+ * @param tokens The warning message tokens.
416
+ * @param actionTokens The action messages tokens.
417
+ */
418
+ createInfo(key, tokens = [], actionTokens = []) {
419
+ return this.formatMessageContents({ type: 'info', key, tokens, actionTokens });
420
+ }
421
+ /**
422
+ * Formats message contents given a message type, key, tokens and actions tokens
423
+ *
424
+ * `<type>.name` will be the upper-cased key, remove prefixed `<type>.` and will always end in 'Error | Warning | Info.
425
+ * `<type>.actions` will be loaded using `${key}.actions` if available.
426
+ *
427
+ * @param type The type of the message set must 'error' | 'warning' | 'info'.
428
+ * @param key The key of the warning message.
429
+ * @param tokens The warning message tokens.
430
+ * @param actionTokens The action messages tokens.
431
+ * @param preserveName Do not require that the name end in the type ('error' | 'warning' | 'info').
432
+ */
433
+ formatMessageContents({ type, key, tokens = [], actionTokens = [], preserveName = false, }) {
434
+ const label = (0, kit_1.upperFirst)(type);
435
+ const labelRegExp = new RegExp(`${label}$`);
436
+ const searchValue = type === 'error' ? /^error.*\./ : new RegExp(`^${type}.`);
444
437
  // Convert key to name:
445
- // 'myMessage' -> `MyMessageError`
438
+ // 'myMessage' -> `MyMessageWarning`
446
439
  // 'myMessageError' -> `MyMessageError`
447
- // 'error.myMessage' -> `MyMessageError`
448
- const errName = `${kit_1.upperFirst(key.replace(/^error\./, ''))}${/Error$/.exec(key) ? '' : 'Error'}`;
449
- const errMessage = this.getMessage(key, tokens);
450
- let errActions;
440
+ // 'warning.myMessage' -> `MyMessageWarning`
441
+ const name = `${(0, kit_1.upperFirst)(key.replace(searchValue, ''))}${labelRegExp.exec(key) || preserveName ? '' : label}`;
442
+ const message = this.getMessage(key, tokens);
443
+ let actions;
451
444
  try {
452
- errActions = this.getMessageWithMap(`${key}.actions`, actionTokens, this.messages);
445
+ actions = this.getMessageWithMap(`${key}.actions`, actionTokens, this.messages);
453
446
  }
454
447
  catch (e) {
455
448
  /* just ignore if actions aren't found */
456
449
  }
457
- return new sfdxError_1.SfdxError(errMessage, errName, errActions, exitCodeOrCause, cause);
450
+ return { message, name, actions };
458
451
  }
459
452
  getMessageWithMap(key, tokens = [], map) {
460
453
  // Allow nested keys for better grouping
@@ -463,19 +456,19 @@ class Messages {
463
456
  const parentKey = group[1];
464
457
  const childKey = group[2];
465
458
  const childObject = map.get(parentKey);
466
- if (childObject && ts_types_1.isJsonMap(childObject)) {
459
+ if (childObject && (0, ts_types_1.isJsonMap)(childObject)) {
467
460
  const childMap = new Map(Object.entries(childObject));
468
461
  return this.getMessageWithMap(childKey, tokens, childMap);
469
462
  }
470
463
  }
471
- if (!map.has(key)) {
464
+ const msg = map.get(key);
465
+ if (!msg) {
472
466
  // Don't use messages inside messages
473
467
  throw new kit_1.NamedError('MissingMessageError', `Missing message ${this.bundleName}:${key} for locale ${Messages.getLocale()}.`);
474
468
  }
475
- const msg = map.get(key);
476
- const messages = (ts_types_1.isArray(msg) ? msg : [msg]);
469
+ const messages = (0, kit_1.ensureArray)(msg);
477
470
  return messages.map((message) => {
478
- ts_types_1.ensureString(message);
471
+ (0, ts_types_1.ensureString)(message);
479
472
  return util.format(message, ...tokens);
480
473
  });
481
474
  }
@@ -494,7 +487,6 @@ Messages.bundles = new Map();
494
487
  * @param filePath read file target.
495
488
  * @ignore
496
489
  */
497
- Messages.readFile = (filePath) => {
498
- return require(filePath);
499
- };
490
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
491
+ Messages.readFile = (filePath) => require(filePath);
500
492
  //# sourceMappingURL=messages.js.map
@@ -1,12 +1,12 @@
1
1
  import { AsyncOptionalCreatable } from '@salesforce/kit';
2
- import { AnyFunction, Nullable } from '@salesforce/ts-types';
3
- import { OAuth2, OAuth2Options, TokenResponse } from 'jsforce';
4
- import { SfOrg } from '../config/globalInfoConfig';
2
+ import { Nullable } from '@salesforce/ts-types';
3
+ import { JwtOAuth2Config, OAuth2 } from 'jsforce';
5
4
  import { Connection } from './connection';
5
+ import { Org } from './org';
6
6
  /**
7
7
  * Fields for authorization, org, and local information.
8
8
  */
9
- export declare type AuthFields = {
9
+ export type AuthFields = {
10
10
  accessToken?: string;
11
11
  alias?: string;
12
12
  authCode?: string;
@@ -31,6 +31,27 @@ export declare type AuthFields = {
31
31
  usernames?: string[];
32
32
  userProfileName?: string;
33
33
  expirationDate?: string;
34
+ tracksSource?: boolean;
35
+ [Org.Fields.NAME]?: string;
36
+ [Org.Fields.INSTANCE_NAME]?: string;
37
+ [Org.Fields.NAMESPACE_PREFIX]?: Nullable<string>;
38
+ [Org.Fields.IS_SANDBOX]?: boolean;
39
+ [Org.Fields.IS_SCRATCH]?: boolean;
40
+ [Org.Fields.TRIAL_EXPIRATION_DATE]?: Nullable<string>;
41
+ };
42
+ export type OrgAuthorization = {
43
+ orgId: string;
44
+ username: string;
45
+ oauthMethod: 'jwt' | 'web' | 'token' | 'unknown';
46
+ aliases: Nullable<string[]>;
47
+ configs: Nullable<string[]>;
48
+ isScratchOrg?: boolean;
49
+ isDevHub?: boolean;
50
+ isSandbox?: boolean;
51
+ instanceUrl?: string;
52
+ accessToken?: string;
53
+ error?: string;
54
+ isExpired: boolean | 'unknown';
34
55
  };
35
56
  /**
36
57
  * Options for access token flow.
@@ -40,71 +61,32 @@ export interface AccessTokenOptions {
40
61
  loginUrl?: string;
41
62
  instanceUrl?: string;
42
63
  }
64
+ export type AuthSideEffects = {
65
+ alias?: string;
66
+ setDefault: boolean;
67
+ setDefaultDevHub: boolean;
68
+ setTracksSource?: boolean;
69
+ };
43
70
  /**
44
71
  * A function to update a refresh token when the access token is expired.
45
72
  */
46
- export declare type RefreshFn = (conn: Connection, callback: (err: Nullable<Error>, accessToken?: string, res?: object) => Promise<void>) => Promise<void>;
73
+ export type RefreshFn = (conn: Connection, callback: (err: Nullable<Error>, accessToken?: string, res?: Record<string, unknown>) => Promise<void>) => Promise<void>;
47
74
  /**
48
75
  * Options for {@link Connection}.
49
76
  */
50
- export declare type ConnectionOptions = AuthFields & {
77
+ export type ConnectionOptions = AuthFields & {
51
78
  /**
52
79
  * OAuth options.
53
80
  */
54
- oauth2?: Partial<OAuth2Options>;
81
+ oauth2?: Partial<JwtOAuth2Config>;
55
82
  /**
56
83
  * Refresh token callback.
57
84
  */
58
85
  refreshFn?: RefreshFn;
59
86
  };
60
- /**
61
- * Extend OAuth2 to add code verifier support for the auth code (web auth) flow
62
- * const oauth2 = new OAuth2WithVerifier({ loginUrl, clientSecret, clientId, redirectUri });
63
- *
64
- * const authUrl = oauth2.getAuthorizationUrl({
65
- * state: 'foo',
66
- * prompt: 'login',
67
- * scope: 'api web'
68
- * });
69
- * console.log(authUrl);
70
- * const authCode = await retrieveCode();
71
- * const authInfo = await AuthInfo.create({ oauth2Options: { clientId, clientSecret, loginUrl, authCode }, oauth2});
72
- * console.log(`access token: ${authInfo.getFields(true).accessToken}`);
73
- */
74
- export declare class OAuth2WithVerifier extends OAuth2 {
75
- readonly codeVerifier: string;
76
- constructor(options: OAuth2Options);
77
- /**
78
- * Overrides jsforce.OAuth2.getAuthorizationUrl. Get Salesforce OAuth2 authorization page
79
- * URL to redirect user agent, adding a verification code for added security.
80
- *
81
- * @param params
82
- */
83
- getAuthorizationUrl(params: object): string;
84
- requestToken(code: string, callback?: (err: Error, tokenResponse: TokenResponse) => void): Promise<TokenResponse>;
85
- /**
86
- * Overrides jsforce.OAuth2._postParams because jsforce's oauth impl doesn't support
87
- * coder_verifier and code_challenge. This enables the server to disallow trading a one-time auth code
88
- * for an access/refresh token when the verifier and challenge are out of alignment.
89
- *
90
- * See https://github.com/jsforce/jsforce/issues/665
91
- */
92
- protected _postParams(params: object, callback: AnyFunction): Promise<any>;
93
- }
94
- /**
95
- * Salesforce URLs.
96
- */
97
- export declare enum SfdcUrl {
98
- SANDBOX = "https://test.salesforce.com",
99
- PRODUCTION = "https://login.salesforce.com"
100
- }
101
- export declare function getJwtAudienceUrl(options: OAuth2Options & {
102
- createdOrgInstance?: string;
103
- }): Promise<string>;
104
87
  export declare const DEFAULT_CONNECTED_APP_INFO: {
105
88
  clientId: string;
106
- legacyClientId: string;
107
- legacyClientSecret: string;
89
+ clientSecret: string;
108
90
  };
109
91
  /**
110
92
  * Handles persistence and fetching of user authentication information using
@@ -143,7 +125,7 @@ export declare const DEFAULT_CONNECTED_APP_INFO: {
143
125
  export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
144
126
  private usingAccessToken;
145
127
  private logger;
146
- private globalInfo;
128
+ private stateAggregator;
147
129
  private username;
148
130
  private options;
149
131
  /**
@@ -161,10 +143,14 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
161
143
  static getDefaultInstanceUrl(): string;
162
144
  /**
163
145
  * Get a list of all authorizations based on auth files stored in the global directory.
146
+ * One can supply a filter (see @param orgAuthFilter) and calling this function without
147
+ * a filter will return all authorizations.
164
148
  *
165
- * @returns {Promise<SfOrg[]>}
149
+ * @param orgAuthFilter A predicate function that returns true for those org authorizations that are to be retained.
150
+ *
151
+ * @returns {Promise<OrgAuthorization[]>}
166
152
  */
167
- static listAllAuthorizations(): Promise<SfOrg[]>;
153
+ static listAllAuthorizations(orgAuthFilter?: (orgAuth: OrgAuthorization) => boolean): Promise<OrgAuthorization[]>;
168
154
  /**
169
155
  * Returns true if one or more authentications are persisted.
170
156
  */
@@ -174,9 +160,9 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
174
160
  *
175
161
  * @param options The options to generate the URL.
176
162
  */
177
- static getAuthorizationUrl(options: OAuth2Options & {
163
+ static getAuthorizationUrl(options: JwtOAuth2Config & {
178
164
  scope?: string;
179
- }, oauth2?: OAuth2WithVerifier): string;
165
+ }, oauth2?: OAuth2): string;
180
166
  /**
181
167
  * Parse a sfdx auth url, usually obtained by `authInfo.getSfdxAuthUrl`.
182
168
  *
@@ -186,12 +172,20 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
186
172
  * ```
187
173
  * @param sfdxAuthUrl
188
174
  */
189
- static parseSfdxAuthUrl(sfdxAuthUrl: string): {
190
- clientId: string;
191
- clientSecret: string;
192
- refreshToken: string;
193
- loginUrl: string;
194
- };
175
+ static parseSfdxAuthUrl(sfdxAuthUrl: string): Pick<AuthFields, 'clientId' | 'clientSecret' | 'refreshToken' | 'loginUrl'>;
176
+ /**
177
+ * Given a set of decrypted fields and an authInfo, determine if the org belongs to an available
178
+ * dev hub.
179
+ *
180
+ * @param fields
181
+ * @param orgAuthInfo
182
+ */
183
+ static identifyPossibleScratchOrgs(fields: AuthFields, orgAuthInfo: AuthInfo): Promise<void>;
184
+ /**
185
+ * Find all dev hubs available in the local environment.
186
+ */
187
+ static getDevHubAuthInfos(): Promise<OrgAuthorization[]>;
188
+ private static queryScratchOrg;
195
189
  /**
196
190
  * Get the username.
197
191
  */
@@ -229,6 +223,8 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
229
223
  * Get the auth fields (decrypted) needed to make a connection.
230
224
  */
231
225
  getConnectionOptions(): ConnectionOptions;
226
+ getClientId(): string;
227
+ getRedirectUri(): string;
232
228
  /**
233
229
  * Get the authorization fields.
234
230
  *
@@ -250,15 +246,23 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
250
246
  */
251
247
  getSfdxAuthUrl(): string;
252
248
  /**
253
- * Set the defaultusername or the defaultdevhubusername to the alias if
249
+ * Convenience function to handle typical side effects encountered when dealing with an AuthInfo.
250
+ * Given the values supplied in parameter sideEffects, this function will set auth alias, default auth
251
+ * and default dev hub.
252
+ *
253
+ * @param sideEffects - instance of AuthSideEffects
254
+ */
255
+ handleAliasAndDefaultSettings(sideEffects: AuthSideEffects): Promise<void>;
256
+ /**
257
+ * Set the target-env (default) or the target-dev-hub to the alias if
254
258
  * it exists otherwise to the username. Method will try to set the local
255
259
  * config first but will default to global config if that fails.
256
260
  *
257
261
  * @param options
258
262
  */
259
- setAsDefault(options: {
260
- defaultUsername?: boolean;
261
- defaultDevhubUsername?: boolean;
263
+ setAsDefault(options?: {
264
+ org?: boolean;
265
+ devHub?: boolean;
262
266
  }): Promise<void>;
263
267
  /**
264
268
  * Sets the provided alias to the username
@@ -277,14 +281,16 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
277
281
  *
278
282
  * @param options Options to be used for creating an OAuth2 instance.
279
283
  *
280
- * **Throws** *{@link SfdxError}{ name: 'NamedOrgNotFoundError' }* Org information does not exist.
284
+ * **Throws** *{@link SfError}{ name: 'NamedOrgNotFoundError' }* Org information does not exist.
281
285
  * @returns {Promise<AuthInfo>}
282
286
  */
283
287
  private initAuthOptions;
284
288
  private loadDecryptedAuthFromConfig;
285
289
  private isTokenOptions;
286
290
  private refreshFn;
287
- private buildJwtConfig;
291
+ private readJwtKey;
292
+ private authJwt;
293
+ private tryJwtAuth;
288
294
  private buildRefreshTokenConfig;
289
295
  /**
290
296
  * Performs an authCode exchange but the Oauth2 feature of jsforce is extended to include a code_challenge
@@ -301,7 +307,12 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
301
307
  * @private
302
308
  */
303
309
  private throwUserGetException;
304
- private lookup;
310
+ /**
311
+ * Returns `true` if the org is a Dev Hub.
312
+ *
313
+ * Check access to the ScratchOrgInfo object to determine if the org is a dev hub.
314
+ */
315
+ private determineIfDevHub;
305
316
  }
306
317
  export declare namespace AuthInfo {
307
318
  /**
@@ -315,7 +326,7 @@ export declare namespace AuthInfo {
315
326
  /**
316
327
  * OAuth options.
317
328
  */
318
- oauth2Options?: OAuth2Options;
329
+ oauth2Options?: JwtOAuth2Config;
319
330
  /**
320
331
  * Options for the access token auth.
321
332
  */
@@ -327,5 +338,6 @@ export declare namespace AuthInfo {
327
338
  * creation.
328
339
  */
329
340
  parentUsername?: string;
341
+ isDevHub?: boolean;
330
342
  }
331
343
  }