@salesforce/core 4.0.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 (153) 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 +87 -22
  8. package/lib/config/config.js +117 -65
  9. package/lib/config/configAggregator.d.ts +41 -35
  10. package/lib/config/configAggregator.js +102 -73
  11. package/lib/config/configFile.d.ts +2 -2
  12. package/lib/config/configFile.js +38 -29
  13. package/lib/config/configGroup.d.ts +141 -0
  14. package/lib/config/configGroup.js +225 -0
  15. package/lib/config/configStore.d.ts +9 -9
  16. package/lib/config/configStore.js +17 -15
  17. package/lib/config/envVars.d.ts +15 -9
  18. package/lib/config/envVars.js +71 -47
  19. package/lib/config/orgUsersConfig.js +2 -0
  20. package/lib/config/sandboxOrgConfig.js +2 -0
  21. package/lib/config/sandboxProcessCache.d.ts +16 -0
  22. package/lib/config/sandboxProcessCache.js +38 -0
  23. package/lib/config/tokensConfig.d.ts +10 -0
  24. package/lib/config/tokensConfig.js +29 -0
  25. package/lib/config/ttlConfig.d.ts +34 -0
  26. package/lib/config/ttlConfig.js +50 -0
  27. package/lib/crypto/crypto.js +15 -22
  28. package/lib/crypto/keyChain.js +2 -3
  29. package/lib/crypto/keyChainImpl.d.ts +5 -3
  30. package/lib/crypto/keyChainImpl.js +58 -61
  31. package/lib/crypto/secureBuffer.d.ts +1 -1
  32. package/lib/deviceOauthService.d.ts +3 -3
  33. package/lib/deviceOauthService.js +27 -25
  34. package/lib/exported.d.ts +15 -12
  35. package/lib/exported.js +28 -16
  36. package/lib/global.d.ts +11 -3
  37. package/lib/global.js +39 -12
  38. package/lib/lifecycleEvents.d.ts +1 -1
  39. package/lib/lifecycleEvents.js +3 -0
  40. package/lib/logger.d.ts +19 -9
  41. package/lib/logger.js +112 -86
  42. package/lib/messages.d.ts +53 -36
  43. package/lib/messages.js +81 -91
  44. package/lib/org/authInfo.d.ts +56 -20
  45. package/lib/org/authInfo.js +232 -131
  46. package/lib/org/authRemover.d.ts +8 -7
  47. package/lib/org/authRemover.js +32 -28
  48. package/lib/org/connection.d.ts +13 -37
  49. package/lib/org/connection.js +78 -124
  50. package/lib/org/index.js +5 -1
  51. package/lib/org/org.d.ts +151 -48
  52. package/lib/org/org.js +466 -220
  53. package/lib/org/orgConfigProperties.d.ts +64 -3
  54. package/lib/org/orgConfigProperties.js +96 -4
  55. package/lib/org/permissionSetAssignment.js +4 -13
  56. package/lib/org/scratchOrgCache.d.ts +20 -0
  57. package/lib/org/scratchOrgCache.js +33 -0
  58. package/lib/org/scratchOrgCreate.d.ts +28 -17
  59. package/lib/org/scratchOrgCreate.js +125 -53
  60. package/lib/org/scratchOrgErrorCodes.d.ts +9 -3
  61. package/lib/org/scratchOrgErrorCodes.js +34 -17
  62. package/lib/org/scratchOrgFeatureDeprecation.js +1 -6
  63. package/lib/org/scratchOrgInfoApi.d.ts +21 -47
  64. package/lib/org/scratchOrgInfoApi.js +129 -63
  65. package/lib/org/scratchOrgInfoGenerator.d.ts +6 -5
  66. package/lib/org/scratchOrgInfoGenerator.js +76 -62
  67. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -0
  68. package/lib/org/scratchOrgLifecycleEvents.js +41 -0
  69. package/lib/org/scratchOrgSettingsGenerator.d.ts +44 -21
  70. package/lib/org/scratchOrgSettingsGenerator.js +165 -98
  71. package/lib/org/scratchOrgTypes.d.ts +43 -0
  72. package/lib/org/scratchOrgTypes.js +9 -0
  73. package/lib/org/user.d.ts +1 -1
  74. package/lib/org/user.js +25 -34
  75. package/lib/schema/printer.d.ts +6 -0
  76. package/lib/schema/printer.js +34 -31
  77. package/lib/schema/validator.d.ts +12 -10
  78. package/lib/schema/validator.js +56 -76
  79. package/lib/{sfdxError.d.ts → sfError.d.ts} +12 -20
  80. package/lib/{sfdxError.js → sfError.js} +40 -30
  81. package/lib/{sfdxProject.d.ts → sfProject.d.ts} +75 -35
  82. package/lib/sfProject.js +651 -0
  83. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.d.ts +27 -12
  84. package/lib/{globalInfo → stateAggregator}/accessors/aliasAccessor.js +47 -31
  85. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -0
  86. package/lib/stateAggregator/accessors/orgAccessor.js +240 -0
  87. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -0
  88. package/lib/stateAggregator/accessors/sandboxAccessor.js +28 -0
  89. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -0
  90. package/lib/stateAggregator/accessors/tokenAccessor.js +80 -0
  91. package/lib/stateAggregator/index.d.ts +4 -0
  92. package/lib/stateAggregator/index.js +27 -0
  93. package/lib/stateAggregator/stateAggregator.d.ts +25 -0
  94. package/lib/stateAggregator/stateAggregator.js +46 -0
  95. package/lib/status/myDomainResolver.d.ts +1 -1
  96. package/lib/status/myDomainResolver.js +4 -4
  97. package/lib/status/pollingClient.js +4 -4
  98. package/lib/status/streamingClient.d.ts +2 -2
  99. package/lib/status/streamingClient.js +58 -63
  100. package/lib/status/types.d.ts +2 -2
  101. package/lib/testSetup.d.ts +206 -75
  102. package/lib/testSetup.js +463 -165
  103. package/lib/util/cache.d.ts +2 -2
  104. package/lib/util/cache.js +6 -6
  105. package/lib/util/checkLightningDomain.js +3 -4
  106. package/lib/util/directoryWriter.d.ts +12 -0
  107. package/lib/util/directoryWriter.js +54 -0
  108. package/lib/util/getJwtAudienceUrl.js +1 -1
  109. package/lib/util/internal.d.ts +28 -2
  110. package/lib/util/internal.js +65 -8
  111. package/lib/util/jsonXmlTools.js +2 -4
  112. package/lib/util/mapKeys.d.ts +9 -9
  113. package/lib/util/mapKeys.js +13 -9
  114. package/lib/util/sfdc.d.ts +51 -51
  115. package/lib/util/sfdc.js +74 -79
  116. package/lib/util/sfdcUrl.d.ts +5 -19
  117. package/lib/util/sfdcUrl.js +40 -49
  118. package/lib/util/structuredWriter.d.ts +9 -0
  119. package/lib/util/structuredWriter.js +3 -0
  120. package/lib/util/zipWriter.d.ts +8 -6
  121. package/lib/util/zipWriter.js +13 -13
  122. package/lib/webOAuthServer.d.ts +20 -6
  123. package/lib/webOAuthServer.js +102 -56
  124. package/messageTransformer/messageTransformer.ts +93 -0
  125. package/messages/auth.md +9 -1
  126. package/messages/config.md +42 -6
  127. package/messages/connection.md +8 -0
  128. package/messages/core.md +10 -0
  129. package/messages/envVars.md +37 -3
  130. package/messages/org.md +21 -1
  131. package/messages/scratchOrgCreate.md +2 -6
  132. package/messages/scratchOrgErrorCodes.md +17 -1
  133. package/messages/scratchOrgInfoApi.md +9 -0
  134. package/messages/scratchOrgInfoGenerator.md +9 -1
  135. package/package.json +121 -46
  136. package/CHANGELOG.md +0 -1244
  137. package/lib/config/keychainConfig.d.ts +0 -19
  138. package/lib/config/keychainConfig.js +0 -43
  139. package/lib/globalInfo/accessors/orgAccessor.d.ts +0 -13
  140. package/lib/globalInfo/accessors/orgAccessor.js +0 -45
  141. package/lib/globalInfo/accessors/tokenAccessor.d.ts +0 -13
  142. package/lib/globalInfo/accessors/tokenAccessor.js +0 -35
  143. package/lib/globalInfo/globalInfoConfig.d.ts +0 -36
  144. package/lib/globalInfo/globalInfoConfig.js +0 -105
  145. package/lib/globalInfo/index.d.ts +0 -6
  146. package/lib/globalInfo/index.js +0 -29
  147. package/lib/globalInfo/sfdxDataHandler.d.ts +0 -43
  148. package/lib/globalInfo/sfdxDataHandler.js +0 -217
  149. package/lib/globalInfo/types.d.ts +0 -39
  150. package/lib/globalInfo/types.js +0 -10
  151. package/lib/sfdxProject.js +0 -557
  152. package/lib/util/fs.d.ts +0 -201
  153. package/lib/util/fs.js +0 -378
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
  }
@@ -148,7 +140,7 @@ const jsAndJsonLoader = (filePath, fileContents) => {
148
140
  *
149
141
  * // Now you can use the messages from anywhere in your code or file.
150
142
  * // If using importMessageDirectory, the bundle name is the file name.
151
- * const messages: Messages = Messages.load(packageName, bundleName);
143
+ * const messages: Messages = Messages.loadMessages(packageName, bundleName);
152
144
  *
153
145
  * // Messages now contains all the message in the bundleName file.
154
146
  * messages.getMessage('authInfoCreationError');
@@ -158,7 +150,7 @@ class Messages {
158
150
  /**
159
151
  * Create a new messages bundle.
160
152
  *
161
- * **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.
162
154
  *
163
155
  * @param bundleName The bundle name.
164
156
  * @param locale The locale.
@@ -177,14 +169,14 @@ class Messages {
177
169
  return 'en_US';
178
170
  }
179
171
  /**
180
- * 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}.
181
173
  *
182
174
  * @param packageName The npm package name.
183
175
  * @param bundle The name of the bundle.
184
176
  * @param loader The loader function.
185
177
  */
186
178
  static setLoaderFunction(packageName, bundle, loader) {
187
- this.loaders.set(new Key(packageName, bundle).toString(), loader);
179
+ this.loaders.set(getKey(packageName, bundle), loader);
188
180
  }
189
181
  /**
190
182
  * Generate a file loading function. Use {@link Messages.importMessageFile} unless
@@ -217,7 +209,7 @@ class Messages {
217
209
  if (!fileContents || fileContents.trim().length === 0) {
218
210
  // messages.js should have no internal dependencies.
219
211
  const error = new Error(`Invalid message file: ${filePath}. No content.`);
220
- error.name = 'SfdxError';
212
+ error.name = 'SfError';
221
213
  throw error;
222
214
  }
223
215
  const map = parser(filePath, fileContents);
@@ -239,7 +231,7 @@ class Messages {
239
231
  }
240
232
  /**
241
233
  * Import all json and js files in a messages directory. Use the file name as the bundle key when
242
- * {@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
243
235
  * typescript project and will truncate to root path (where the package.json file is). If your messages
244
236
  * directory is in another spot or you are not using typescript, pass in false for truncateToProjectPath.
245
237
  *
@@ -304,83 +296,33 @@ class Messages {
304
296
  * Load messages for a given package and bundle. If the bundle is not already cached, use the loader function
305
297
  * created from {@link Messages.setLoaderFunction} or {@link Messages.importMessagesDirectory}.
306
298
  *
307
- * **NOTE: Use {@link Messages.load} instead for safe message validation and usage.**
308
- *
309
299
  * ```typescript
310
300
  * Messages.importMessagesDirectory(__dirname);
311
- * const messages = Messages.load('packageName', 'bundleName');
301
+ * const messages = Messages.loadMessages('packageName', 'bundleName');
312
302
  * ```
313
303
  *
314
304
  * @param packageName The name of the npm package.
315
305
  * @param bundleName The name of the bundle to load.
316
306
  */
317
307
  static loadMessages(packageName, bundleName) {
318
- const key = new Key(packageName, bundleName);
319
- let messages;
320
- if (this.isCached(packageName, bundleName)) {
321
- messages = this.bundles.get(key.toString());
322
- }
323
- else if (this.loaders.has(key.toString())) {
324
- const loader = this.loaders.get(key.toString());
325
- if (loader) {
326
- messages = loader(Messages.getLocale());
327
- this.bundles.set(key.toString(), messages);
328
- messages = this.bundles.get(key.toString());
329
- }
330
- }
331
- if (messages) {
332
- return messages;
333
- }
334
- // Don't use messages inside messages
335
- throw new kit_1.NamedError('MissingBundleError', `Missing bundle ${key.toString()} for locale ${Messages.getLocale()}.`);
336
- }
337
- /**
338
- * Load messages for a given package and bundle. If the bundle is not already cached, use the loader function
339
- * created from {@link Messages.setLoaderFunction} or {@link Messages.importMessagesDirectory}.
340
- *
341
- * The message keys that will be used must be passed in for validation. This prevents runtime errors if messages are used but not defined.
342
- *
343
- * **NOTE: This should be defined at the top of the file so validation is done at load time rather than runtime.**
344
- *
345
- * ```typescript
346
- * Messages.importMessagesDirectory(__dirname);
347
- * const messages = Messages.load('packageName', 'bundleName', [
348
- * 'messageKey1',
349
- * 'messageKey2',
350
- * ]);
351
- * ```
352
- *
353
- * @param packageName The name of the npm package.
354
- * @param bundleName The name of the bundle to load.
355
- * @param keys The message keys that will be used.
356
- */
357
- static load(packageName, bundleName, keys) {
358
- const key = new Key(packageName, bundleName);
308
+ const key = getKey(packageName, bundleName);
359
309
  let messages;
360
310
  if (this.isCached(packageName, bundleName)) {
361
- messages = this.bundles.get(key.toString());
311
+ messages = this.bundles.get(key);
362
312
  }
363
- else if (this.loaders.has(key.toString())) {
364
- const loader = this.loaders.get(key.toString());
313
+ else if (this.loaders.has(key)) {
314
+ const loader = this.loaders.get(key);
365
315
  if (loader) {
366
316
  messages = loader(Messages.getLocale());
367
- this.bundles.set(key.toString(), messages);
368
- messages = this.bundles.get(key.toString());
317
+ this.bundles.set(key, messages);
318
+ messages = this.bundles.get(key);
369
319
  }
370
320
  }
371
321
  if (messages) {
372
- // Type guard on key length, but do a runtime check.
373
- if (!keys || keys.length === 0) {
374
- throw new kit_1.NamedError('MissingKeysError', 'Can not load messages without providing the message keys that will be used.');
375
- }
376
- // Get all messages to validate they are actually present
377
- for (const messageKey of keys) {
378
- messages.getMessage(messageKey);
379
- }
380
322
  return messages;
381
323
  }
382
324
  // Don't use messages inside messages
383
- 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()}.`);
384
326
  }
385
327
  /**
386
328
  * Check if a bundle already been loaded.
@@ -389,7 +331,7 @@ class Messages {
389
331
  * @param bundleName The bundle name.
390
332
  */
391
333
  static isCached(packageName, bundleName) {
392
- return this.bundles.has(new Key(packageName, bundleName).toString());
334
+ return this.bundles.has(getKey(packageName, bundleName));
393
335
  }
394
336
  /**
395
337
  * Get a message using a message key and use the tokens as values for tokenization.
@@ -438,25 +380,74 @@ class Messages {
438
380
  * @param key The key of the error message.
439
381
  * @param tokens The error message tokens.
440
382
  * @param actionTokens The action messages tokens.
441
- * @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.
442
384
  * @param cause The underlying error that caused this error to be raised.
443
385
  */
444
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}.`);
445
437
  // Convert key to name:
446
- // 'myMessage' -> `MyMessageError`
438
+ // 'myMessage' -> `MyMessageWarning`
447
439
  // 'myMessageError' -> `MyMessageError`
448
- // 'error.myMessage' -> `MyMessageError`
449
- // 'errors.myMessage' -> `MyMessageError`
450
- const errName = `${(0, kit_1.upperFirst)(key.replace(/^errors*\./, ''))}${/Error$/.exec(key) ? '' : 'Error'}`;
451
- const errMessage = this.getMessage(key, tokens);
452
- 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;
453
444
  try {
454
- errActions = this.getMessageWithMap(`${key}.actions`, actionTokens, this.messages);
445
+ actions = this.getMessageWithMap(`${key}.actions`, actionTokens, this.messages);
455
446
  }
456
447
  catch (e) {
457
448
  /* just ignore if actions aren't found */
458
449
  }
459
- return new sfdxError_1.SfdxError(errMessage, errName, errActions, exitCodeOrCause, cause);
450
+ return { message, name, actions };
460
451
  }
461
452
  getMessageWithMap(key, tokens = [], map) {
462
453
  // Allow nested keys for better grouping
@@ -470,12 +461,12 @@ class Messages {
470
461
  return this.getMessageWithMap(childKey, tokens, childMap);
471
462
  }
472
463
  }
473
- if (!map.has(key)) {
464
+ const msg = map.get(key);
465
+ if (!msg) {
474
466
  // Don't use messages inside messages
475
467
  throw new kit_1.NamedError('MissingMessageError', `Missing message ${this.bundleName}:${key} for locale ${Messages.getLocale()}.`);
476
468
  }
477
- const msg = map.get(key);
478
- const messages = ((0, ts_types_1.isArray)(msg) ? msg : [msg]);
469
+ const messages = (0, kit_1.ensureArray)(msg);
479
470
  return messages.map((message) => {
480
471
  (0, ts_types_1.ensureString)(message);
481
472
  return util.format(message, ...tokens);
@@ -496,7 +487,6 @@ Messages.bundles = new Map();
496
487
  * @param filePath read file target.
497
488
  * @ignore
498
489
  */
499
- Messages.readFile = (filePath) => {
500
- return require(filePath);
501
- };
490
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
491
+ Messages.readFile = (filePath) => require(filePath);
502
492
  //# sourceMappingURL=messages.js.map
@@ -1,18 +1,12 @@
1
1
  import { AsyncOptionalCreatable } from '@salesforce/kit';
2
2
  import { Nullable } from '@salesforce/ts-types';
3
- import { OAuth2, OAuth2Config as JsforceOAuth2Config } from 'jsforce';
3
+ import { JwtOAuth2Config, OAuth2 } from 'jsforce';
4
4
  import { Connection } from './connection';
5
- export declare type OAuth2Config = JsforceOAuth2Config & {
6
- privateKey?: string;
7
- privateKeyFile?: string;
8
- authCode?: string;
9
- refreshToken?: string;
10
- loginUrl?: string;
11
- };
5
+ import { Org } from './org';
12
6
  /**
13
7
  * Fields for authorization, org, and local information.
14
8
  */
15
- export declare type AuthFields = {
9
+ export type AuthFields = {
16
10
  accessToken?: string;
17
11
  alias?: string;
18
12
  authCode?: string;
@@ -37,8 +31,15 @@ export declare type AuthFields = {
37
31
  usernames?: string[];
38
32
  userProfileName?: string;
39
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>;
40
41
  };
41
- export declare type OrgAuthorization = {
42
+ export type OrgAuthorization = {
42
43
  orgId: string;
43
44
  username: string;
44
45
  oauthMethod: 'jwt' | 'web' | 'token' | 'unknown';
@@ -46,6 +47,7 @@ export declare type OrgAuthorization = {
46
47
  configs: Nullable<string[]>;
47
48
  isScratchOrg?: boolean;
48
49
  isDevHub?: boolean;
50
+ isSandbox?: boolean;
49
51
  instanceUrl?: string;
50
52
  accessToken?: string;
51
53
  error?: string;
@@ -59,18 +61,24 @@ export interface AccessTokenOptions {
59
61
  loginUrl?: string;
60
62
  instanceUrl?: string;
61
63
  }
64
+ export type AuthSideEffects = {
65
+ alias?: string;
66
+ setDefault: boolean;
67
+ setDefaultDevHub: boolean;
68
+ setTracksSource?: boolean;
69
+ };
62
70
  /**
63
71
  * A function to update a refresh token when the access token is expired.
64
72
  */
65
- export declare type RefreshFn = (conn: Connection, callback: (err: Nullable<Error>, accessToken?: string, res?: Record<string, unknown>) => Promise<void>) => Promise<void>;
73
+ export type RefreshFn = (conn: Connection, callback: (err: Nullable<Error>, accessToken?: string, res?: Record<string, unknown>) => Promise<void>) => Promise<void>;
66
74
  /**
67
75
  * Options for {@link Connection}.
68
76
  */
69
- export declare type ConnectionOptions = AuthFields & {
77
+ export type ConnectionOptions = AuthFields & {
70
78
  /**
71
79
  * OAuth options.
72
80
  */
73
- oauth2?: Partial<OAuth2Config>;
81
+ oauth2?: Partial<JwtOAuth2Config>;
74
82
  /**
75
83
  * Refresh token callback.
76
84
  */
@@ -78,8 +86,7 @@ export declare type ConnectionOptions = AuthFields & {
78
86
  };
79
87
  export declare const DEFAULT_CONNECTED_APP_INFO: {
80
88
  clientId: string;
81
- legacyClientId: string;
82
- legacyClientSecret: string;
89
+ clientSecret: string;
83
90
  };
84
91
  /**
85
92
  * Handles persistence and fetching of user authentication information using
@@ -118,7 +125,7 @@ export declare const DEFAULT_CONNECTED_APP_INFO: {
118
125
  export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
119
126
  private usingAccessToken;
120
127
  private logger;
121
- private globalInfo;
128
+ private stateAggregator;
122
129
  private username;
123
130
  private options;
124
131
  /**
@@ -153,7 +160,7 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
153
160
  *
154
161
  * @param options The options to generate the URL.
155
162
  */
156
- static getAuthorizationUrl(options: OAuth2Config & {
163
+ static getAuthorizationUrl(options: JwtOAuth2Config & {
157
164
  scope?: string;
158
165
  }, oauth2?: OAuth2): string;
159
166
  /**
@@ -166,6 +173,19 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
166
173
  * @param sfdxAuthUrl
167
174
  */
168
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;
169
189
  /**
170
190
  * Get the username.
171
191
  */
@@ -225,6 +245,14 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
225
245
  * **See** [SFDX Authorization](https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_force_auth.htm#cli_reference_force_auth)
226
246
  */
227
247
  getSfdxAuthUrl(): string;
248
+ /**
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>;
228
256
  /**
229
257
  * Set the target-env (default) or the target-dev-hub to the alias if
230
258
  * it exists otherwise to the username. Method will try to set the local
@@ -253,14 +281,16 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
253
281
  *
254
282
  * @param options Options to be used for creating an OAuth2 instance.
255
283
  *
256
- * **Throws** *{@link SfdxError}{ name: 'NamedOrgNotFoundError' }* Org information does not exist.
284
+ * **Throws** *{@link SfError}{ name: 'NamedOrgNotFoundError' }* Org information does not exist.
257
285
  * @returns {Promise<AuthInfo>}
258
286
  */
259
287
  private initAuthOptions;
260
288
  private loadDecryptedAuthFromConfig;
261
289
  private isTokenOptions;
262
290
  private refreshFn;
263
- private buildJwtConfig;
291
+ private readJwtKey;
292
+ private authJwt;
293
+ private tryJwtAuth;
264
294
  private buildRefreshTokenConfig;
265
295
  /**
266
296
  * Performs an authCode exchange but the Oauth2 feature of jsforce is extended to include a code_challenge
@@ -277,6 +307,12 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
277
307
  * @private
278
308
  */
279
309
  private throwUserGetException;
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;
280
316
  }
281
317
  export declare namespace AuthInfo {
282
318
  /**
@@ -290,7 +326,7 @@ export declare namespace AuthInfo {
290
326
  /**
291
327
  * OAuth options.
292
328
  */
293
- oauth2Options?: OAuth2Config;
329
+ oauth2Options?: JwtOAuth2Config;
294
330
  /**
295
331
  * Options for the access token auth.
296
332
  */