@salesforce/core 4.0.0-v3.0 → 4.0.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 (125) hide show
  1. package/CHANGELOG.md +569 -24
  2. package/LICENSE.txt +1 -1
  3. package/lib/config/config.d.ts +110 -42
  4. package/lib/config/config.js +309 -138
  5. package/lib/config/configAggregator.d.ts +22 -11
  6. package/lib/config/configAggregator.js +50 -26
  7. package/lib/config/configFile.js +10 -10
  8. package/lib/config/configStore.js +15 -14
  9. package/lib/config/envVars.d.ts +96 -0
  10. package/lib/config/envVars.js +433 -0
  11. package/lib/config/keychainConfig.js +1 -1
  12. package/lib/config/orgUsersConfig.d.ts +8 -0
  13. package/lib/config/orgUsersConfig.js +10 -0
  14. package/lib/config/sandboxOrgConfig.d.ts +8 -0
  15. package/lib/config/sandboxOrgConfig.js +10 -0
  16. package/lib/crypto/crypto.js +28 -8
  17. package/lib/crypto/keyChain.js +2 -1
  18. package/lib/crypto/keyChainImpl.js +8 -6
  19. package/lib/crypto/secureBuffer.js +1 -1
  20. package/lib/deviceOauthService.d.ts +3 -3
  21. package/lib/deviceOauthService.js +22 -20
  22. package/lib/exported.d.ts +13 -9
  23. package/lib/exported.js +25 -13
  24. package/lib/global.d.ts +6 -0
  25. package/lib/global.js +7 -1
  26. package/lib/globalInfo/accessors/aliasAccessor.d.ts +83 -0
  27. package/lib/globalInfo/accessors/aliasAccessor.js +130 -0
  28. package/lib/globalInfo/accessors/orgAccessor.d.ts +13 -0
  29. package/lib/globalInfo/accessors/orgAccessor.js +45 -0
  30. package/lib/globalInfo/accessors/tokenAccessor.d.ts +13 -0
  31. package/lib/globalInfo/accessors/tokenAccessor.js +35 -0
  32. package/lib/globalInfo/globalInfoConfig.d.ts +36 -0
  33. package/lib/globalInfo/globalInfoConfig.js +105 -0
  34. package/lib/globalInfo/index.d.ts +6 -0
  35. package/lib/globalInfo/index.js +29 -0
  36. package/lib/{config → globalInfo}/sfdxDataHandler.d.ts +10 -3
  37. package/lib/{config → globalInfo}/sfdxDataHandler.js +71 -19
  38. package/lib/globalInfo/types.d.ts +39 -0
  39. package/lib/globalInfo/types.js +10 -0
  40. package/lib/lifecycleEvents.d.ts +38 -1
  41. package/lib/lifecycleEvents.js +74 -3
  42. package/lib/logger.d.ts +2 -2
  43. package/lib/logger.js +16 -26
  44. package/lib/messages.js +12 -10
  45. package/lib/org/authInfo.d.ts +41 -65
  46. package/lib/org/authInfo.js +138 -233
  47. package/lib/org/authRemover.d.ts +11 -19
  48. package/lib/org/authRemover.js +47 -49
  49. package/lib/org/connection.d.ts +24 -26
  50. package/lib/org/connection.js +77 -92
  51. package/lib/org/index.js +1 -1
  52. package/lib/org/org.d.ts +134 -12
  53. package/lib/org/org.js +436 -97
  54. package/lib/org/orgConfigProperties.d.ts +8 -0
  55. package/lib/org/orgConfigProperties.js +29 -0
  56. package/lib/org/permissionSetAssignment.js +3 -3
  57. package/lib/org/scratchOrgCreate.d.ts +43 -0
  58. package/lib/org/scratchOrgCreate.js +142 -0
  59. package/lib/org/scratchOrgErrorCodes.d.ts +4 -0
  60. package/lib/org/scratchOrgErrorCodes.js +62 -0
  61. package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -0
  62. package/lib/org/scratchOrgFeatureDeprecation.js +110 -0
  63. package/lib/org/scratchOrgInfoApi.d.ts +94 -0
  64. package/lib/org/scratchOrgInfoApi.js +350 -0
  65. package/lib/org/scratchOrgInfoGenerator.d.ts +63 -0
  66. package/lib/org/scratchOrgInfoGenerator.js +223 -0
  67. package/lib/org/scratchOrgSettingsGenerator.d.ts +56 -0
  68. package/lib/org/scratchOrgSettingsGenerator.js +210 -0
  69. package/lib/org/user.d.ts +6 -1
  70. package/lib/org/user.js +69 -36
  71. package/lib/schema/printer.js +18 -18
  72. package/lib/schema/validator.js +8 -8
  73. package/lib/sfdxError.d.ts +6 -1
  74. package/lib/sfdxError.js +10 -2
  75. package/lib/sfdxProject.js +33 -22
  76. package/lib/status/myDomainResolver.js +6 -6
  77. package/lib/status/pollingClient.d.ts +2 -6
  78. package/lib/status/pollingClient.js +37 -63
  79. package/lib/status/streamingClient.d.ts +5 -80
  80. package/lib/status/streamingClient.js +18 -33
  81. package/lib/status/types.d.ts +89 -0
  82. package/lib/status/types.js +18 -0
  83. package/lib/testSetup.d.ts +7 -5
  84. package/lib/testSetup.js +38 -40
  85. package/lib/util/cache.d.ts +11 -0
  86. package/lib/util/cache.js +70 -0
  87. package/lib/util/checkLightningDomain.d.ts +1 -0
  88. package/lib/util/checkLightningDomain.js +30 -0
  89. package/lib/util/fs.d.ts +3 -0
  90. package/lib/util/fs.js +16 -12
  91. package/lib/util/getJwtAudienceUrl.d.ts +4 -0
  92. package/lib/util/getJwtAudienceUrl.js +19 -0
  93. package/lib/util/jsonXmlTools.d.ts +14 -0
  94. package/lib/util/jsonXmlTools.js +41 -0
  95. package/lib/util/mapKeys.d.ts +14 -0
  96. package/lib/util/mapKeys.js +48 -0
  97. package/lib/util/sfdc.d.ts +1 -13
  98. package/lib/util/sfdc.js +5 -52
  99. package/lib/util/sfdcUrl.d.ts +78 -0
  100. package/lib/util/sfdcUrl.js +206 -0
  101. package/lib/util/zipWriter.d.ts +14 -0
  102. package/lib/util/zipWriter.js +68 -0
  103. package/lib/webOAuthServer.d.ts +2 -3
  104. package/lib/webOAuthServer.js +11 -10
  105. package/messages/auth.md +2 -2
  106. package/messages/config.md +58 -6
  107. package/messages/core.json +3 -3
  108. package/messages/core.md +1 -1
  109. package/messages/envVars.md +279 -0
  110. package/messages/org.md +44 -0
  111. package/messages/scratchOrgCreate.md +27 -0
  112. package/messages/scratchOrgErrorCodes.md +99 -0
  113. package/messages/scratchOrgFeatureDeprecation.md +11 -0
  114. package/messages/scratchOrgInfoApi.md +11 -0
  115. package/messages/scratchOrgInfoGenerator.md +19 -0
  116. package/messages/user.md +12 -0
  117. package/package.json +50 -53
  118. package/lib/config/aliases.d.ts +0 -56
  119. package/lib/config/aliases.js +0 -96
  120. package/lib/config/configGroup.d.ts +0 -141
  121. package/lib/config/configGroup.js +0 -223
  122. package/lib/config/globalInfoConfig.d.ts +0 -74
  123. package/lib/config/globalInfoConfig.js +0 -144
  124. package/lib/status/client.d.ts +0 -15
  125. package/lib/status/client.js +0 -9
@@ -1,37 +1,31 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthInfo = exports.DEFAULT_CONNECTED_APP_INFO = void 0;
2
4
  /*
3
5
  * Copyright (c) 2020, salesforce.com, inc.
4
6
  * All rights reserved.
5
7
  * Licensed under the BSD 3-Clause license.
6
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
9
  */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AuthInfo = exports.DEFAULT_CONNECTED_APP_INFO = exports.getJwtAudienceUrl = exports.SfdcUrl = exports.OAuth2WithVerifier = void 0;
10
10
  const crypto_1 = require("crypto");
11
- const url_1 = require("url");
12
- const dns = require("dns");
13
11
  const path_1 = require("path");
14
- const url_2 = require("url");
15
12
  const os = require("os");
16
13
  const kit_1 = require("@salesforce/kit");
17
14
  const ts_types_1 = require("@salesforce/ts-types");
18
15
  const jsforce_1 = require("jsforce");
19
- // No typings directly available for jsforce/lib/transport
20
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
21
- // @ts-ignore
22
- const Transport = require("jsforce/lib/transport");
16
+ const transport_1 = require("jsforce/lib/transport");
23
17
  const jwt = require("jsonwebtoken");
24
- const aliases_1 = require("../config/aliases");
25
18
  const config_1 = require("../config/config");
26
19
  const configAggregator_1 = require("../config/configAggregator");
27
20
  const logger_1 = require("../logger");
28
21
  const sfdxError_1 = require("../sfdxError");
29
22
  const fs_1 = require("../util/fs");
30
23
  const sfdc_1 = require("../util/sfdc");
31
- const myDomainResolver_1 = require("../status/myDomainResolver");
32
- const globalInfoConfig_1 = require("../config/globalInfoConfig");
24
+ const globalInfo_1 = require("../globalInfo");
33
25
  const messages_1 = require("../messages");
26
+ const sfdcUrl_1 = require("../util/sfdcUrl");
34
27
  const connection_1 = require("./connection");
28
+ const orgConfigProperties_1 = require("./orgConfigProperties");
35
29
  messages_1.Messages.importMessagesDirectory(__dirname);
36
30
  const messages = messages_1.Messages.load('@salesforce/core', 'core', [
37
31
  'authInfoCreationError',
@@ -49,116 +43,15 @@ class JwtOAuth2 extends jsforce_1.OAuth2 {
49
43
  constructor(options) {
50
44
  super(options);
51
45
  }
52
- jwtAuthorize(innerToken, callback) {
53
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
46
+ jwtAuthorize(innerToken) {
54
47
  // @ts-ignore
55
48
  return super._postParams({
49
+ // eslint-disable-next-line camelcase
56
50
  grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
57
51
  assertion: innerToken,
58
- }, callback);
59
- }
60
- }
61
- /**
62
- * Extend OAuth2 to add code verifier support for the auth code (web auth) flow
63
- * const oauth2 = new OAuth2WithVerifier({ loginUrl, clientSecret, clientId, redirectUri });
64
- *
65
- * const authUrl = oauth2.getAuthorizationUrl({
66
- * state: 'foo',
67
- * prompt: 'login',
68
- * scope: 'api web'
69
- * });
70
- * console.log(authUrl);
71
- * const authCode = await retrieveCode();
72
- * const authInfo = await AuthInfo.create({ oauth2Options: { clientId, clientSecret, loginUrl, authCode }, oauth2});
73
- * console.log(`access token: ${authInfo.getFields(true).accessToken}`);
74
- */
75
- class OAuth2WithVerifier extends jsforce_1.OAuth2 {
76
- constructor(options) {
77
- super(options);
78
- // Set a code verifier string for OAuth authorization
79
- this.codeVerifier = base64UrlEscape(crypto_1.randomBytes(Math.ceil(128)).toString('base64'));
80
- }
81
- /**
82
- * Overrides jsforce.OAuth2.getAuthorizationUrl. Get Salesforce OAuth2 authorization page
83
- * URL to redirect user agent, adding a verification code for added security.
84
- *
85
- * @param params
86
- */
87
- getAuthorizationUrl(params) {
88
- // code verifier must be a base 64 url encoded hash of 128 bytes of random data. Our random data is also
89
- // base 64 url encoded. See Connection.create();
90
- const codeChallenge = base64UrlEscape(crypto_1.createHash('sha256').update(this.codeVerifier).digest('base64'));
91
- kit_1.set(params, 'code_challenge', codeChallenge);
92
- return super.getAuthorizationUrl(params);
93
- }
94
- async requestToken(code, callback) {
95
- return super.requestToken(code, callback);
96
- }
97
- /**
98
- * Overrides jsforce.OAuth2._postParams because jsforce's oauth impl doesn't support
99
- * coder_verifier and code_challenge. This enables the server to disallow trading a one-time auth code
100
- * for an access/refresh token when the verifier and challenge are out of alignment.
101
- *
102
- * See https://github.com/jsforce/jsforce/issues/665
103
- */
104
- async _postParams(params, callback) {
105
- kit_1.set(params, 'code_verifier', this.codeVerifier);
106
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
107
- // @ts-ignore TODO: need better typings for jsforce
108
- return super._postParams(params, callback);
109
- }
110
- }
111
- exports.OAuth2WithVerifier = OAuth2WithVerifier;
112
- /**
113
- * Salesforce URLs.
114
- */
115
- var SfdcUrl;
116
- (function (SfdcUrl) {
117
- SfdcUrl["SANDBOX"] = "https://test.salesforce.com";
118
- SfdcUrl["PRODUCTION"] = "https://login.salesforce.com";
119
- })(SfdcUrl = exports.SfdcUrl || (exports.SfdcUrl = {}));
120
- function isSandboxUrl(options) {
121
- var _a;
122
- const createdOrgInstance = ts_types_1.getString(options, 'createdOrgInstance', '').trim().toLowerCase();
123
- const loginUrl = (_a = options.loginUrl) !== null && _a !== void 0 ? _a : '';
124
- return (/^cs|s$/gi.test(createdOrgInstance) ||
125
- /sandbox\.my\.salesforce\.com/gi.test(loginUrl) || // enhanced domains >= 230
126
- /(cs[0-9]+(\.my|)\.salesforce\.com)/gi.test(loginUrl) || // my domains on CS instance OR CS instance without my domain
127
- /([a-z]{3}[0-9]+s\.sfdc-.+\.salesforce\.com)/gi.test(loginUrl) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
128
- /([a-z]{3}[0-9]+s\.sfdc-.+\.force\.com)/gi.test(loginUrl) || // falcon sandbox ex: usa2s.sfdc-whatever.salesforce.com
129
- url_2.parse(loginUrl).hostname === 'test.salesforce.com');
130
- }
131
- async function resolvesToSandbox(options) {
132
- if (isSandboxUrl(options)) {
133
- return true;
134
- }
135
- let cnames = [];
136
- if (options.loginUrl) {
137
- const myDomainResolver = await myDomainResolver_1.MyDomainResolver.create({ url: new url_1.URL(options.loginUrl) });
138
- cnames = await myDomainResolver.getCnames();
139
- }
140
- return cnames.some((cname) => isSandboxUrl(Object.assign(Object.assign({}, options), { loginUrl: cname })));
141
- }
142
- async function getJwtAudienceUrl(options) {
143
- var _a;
144
- // environment variable is used as an override
145
- if (process.env.SFDX_AUDIENCE_URL) {
146
- return process.env.SFDX_AUDIENCE_URL;
147
- }
148
- if (options.loginUrl && sfdc_1.sfdc.isInternalUrl(options.loginUrl)) {
149
- // This is for internal developers when just doing authorize;
150
- return options.loginUrl;
151
- }
152
- if (await resolvesToSandbox(options)) {
153
- return SfdcUrl.SANDBOX;
154
- }
155
- const createdOrgInstance = ts_types_1.getString(options, 'createdOrgInstance', '').trim().toLowerCase();
156
- if (/^gs1/gi.test(createdOrgInstance) || /(gs1.my.salesforce.com)/gi.test((_a = options.loginUrl) !== null && _a !== void 0 ? _a : '')) {
157
- return 'https://gs1.salesforce.com';
52
+ });
158
53
  }
159
- return SfdcUrl.PRODUCTION;
160
54
  }
161
- exports.getJwtAudienceUrl = getJwtAudienceUrl;
162
55
  // parses the id field returned from jsForce oauth2 methods to get
163
56
  // user ID and org ID.
164
57
  function parseIdUrl(idUrl) {
@@ -183,13 +76,6 @@ exports.DEFAULT_CONNECTED_APP_INFO = {
183
76
  legacyClientId: 'SalesforceDevelopmentExperience',
184
77
  legacyClientSecret: '1384510088588713504',
185
78
  };
186
- // Makes a nodejs base64 encoded string compatible with rfc4648 alternative encoding for urls.
187
- // @param base64Encoded a nodejs base64 encoded string
188
- function base64UrlEscape(base64Encoded) {
189
- // builtin node js base 64 encoding is not 64 url compatible.
190
- // See https://toolsn.ietf.org/html/rfc4648#section-5
191
- return base64Encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
192
- }
193
79
  /**
194
80
  * Handles persistence and fetching of user authentication information using
195
81
  * JWT, OAuth, or refresh tokens. Sets up the refresh flows that jsForce will
@@ -244,62 +130,79 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
244
130
  */
245
131
  static getDefaultInstanceUrl() {
246
132
  const configuredInstanceUrl = configAggregator_1.ConfigAggregator.getValue('instanceUrl').value;
247
- return configuredInstanceUrl || 'https://login.salesforce.com';
133
+ return configuredInstanceUrl || sfdcUrl_1.SfdcUrl.PRODUCTION;
248
134
  }
249
135
  /**
250
136
  * Get a list of all authorizations based on auth files stored in the global directory.
137
+ * One can supply a filter (see @param orgAuthFilter) and calling this function without
138
+ * a filter will return all authorizations.
251
139
  *
252
- * @returns {Promise<SfOrg[]>}
140
+ * @param orgAuthFilter A predicate function that returns true for those org authorizations that are to be retained.
141
+ *
142
+ * @returns {Promise<OrgAuthorization[]>}
253
143
  */
254
- static async listAllAuthorizations() {
255
- const globalInfo = await globalInfoConfig_1.GlobalInfo.getInstance();
256
- const auths = Object.values(globalInfo.getOrgs());
257
- const aliases = await aliases_1.Aliases.create(aliases_1.Aliases.getDefaultOptions());
144
+ static async listAllAuthorizations(orgAuthFilter = (orgAuth) => !!orgAuth) {
145
+ var _a;
146
+ const globalInfo = await globalInfo_1.GlobalInfo.getInstance();
147
+ const config = (await configAggregator_1.ConfigAggregator.create()).getConfigInfo();
148
+ const orgs = Object.values(globalInfo.orgs.getAll());
258
149
  const final = [];
259
- for (const auth of auths) {
260
- const username = ts_types_1.ensureString(auth.username);
261
- const [alias] = aliases.getKeysByValue(username);
150
+ for (const org of orgs) {
151
+ const username = (0, ts_types_1.ensureString)(org.username);
152
+ const aliases = (_a = globalInfo.aliases.getAll(username)) !== null && _a !== void 0 ? _a : undefined;
153
+ // Get a list of configuration values that are set to either the username or one
154
+ // of the aliases
155
+ const configs = config
156
+ .filter((c) => aliases.includes(c.value) || c.value === username)
157
+ .map((c) => c.key);
262
158
  try {
263
159
  const authInfo = await AuthInfo.create({ username });
264
- const { orgId, instanceUrl } = authInfo.getFields();
160
+ const { orgId, instanceUrl, devHubUsername, expirationDate, isDevHub } = authInfo.getFields();
265
161
  final.push({
266
- alias,
162
+ aliases,
163
+ configs,
267
164
  username,
268
- orgId,
269
165
  instanceUrl,
166
+ isScratchOrg: Boolean(devHubUsername),
167
+ isDevHub: isDevHub || false,
168
+ orgId: orgId,
270
169
  accessToken: authInfo.getConnectionOptions().accessToken,
271
170
  oauthMethod: authInfo.isJwt() ? 'jwt' : authInfo.isOauth() ? 'web' : 'token',
272
- timestamp: auth.timestamp,
171
+ isExpired: Boolean(devHubUsername) && expirationDate
172
+ ? new Date((0, ts_types_1.ensureString)(expirationDate)).getTime() < new Date().getTime()
173
+ : 'unknown',
273
174
  });
274
175
  }
275
176
  catch (err) {
276
177
  final.push({
277
- alias,
178
+ aliases,
179
+ configs,
278
180
  username,
279
- orgId: auth.orgId,
280
- instanceUrl: auth.instanceUrl,
181
+ orgId: org.orgId,
182
+ instanceUrl: org.instanceUrl,
281
183
  accessToken: undefined,
282
184
  oauthMethod: 'unknown',
283
185
  error: err.message,
284
- timestamp: auth.timestamp,
186
+ isExpired: 'unknown',
285
187
  });
286
188
  }
287
189
  }
288
- return final;
190
+ return final.filter(orgAuthFilter);
289
191
  }
290
192
  /**
291
193
  * Returns true if one or more authentications are persisted.
292
194
  */
293
195
  static async hasAuthentications() {
294
196
  try {
295
- const auths = (await globalInfoConfig_1.GlobalInfo.getInstance()).getOrgs();
296
- return !kit_1.isEmpty(auths);
197
+ const auths = (await globalInfo_1.GlobalInfo.getInstance()).orgs.getAll();
198
+ return !(0, kit_1.isEmpty)(auths);
297
199
  }
298
200
  catch (err) {
299
- if (err.name === 'OrgDataNotAvailableError' || err.code === 'ENOENT') {
201
+ const error = err;
202
+ if (error.name === 'OrgDataNotAvailableError' || error.code === 'ENOENT') {
300
203
  return false;
301
204
  }
302
- throw err;
205
+ throw error;
303
206
  }
304
207
  }
305
208
  /**
@@ -308,11 +211,13 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
308
211
  * @param options The options to generate the URL.
309
212
  */
310
213
  static getAuthorizationUrl(options, oauth2) {
311
- const oauth2Verifier = oauth2 || new OAuth2WithVerifier(options);
214
+ // Always use a verifier for enhanced security
215
+ options.useVerifier = true;
216
+ const oauth2Verifier = oauth2 || new jsforce_1.OAuth2(options);
312
217
  // The state parameter allows the redirectUri callback listener to ignore request
313
218
  // that don't contain the state value.
314
219
  const params = {
315
- state: crypto_1.randomBytes(Math.ceil(6)).toString('hex'),
220
+ state: (0, crypto_1.randomBytes)(Math.ceil(6)).toString('hex'),
316
221
  prompt: 'login',
317
222
  // Default connected app is 'refresh_token api web'
318
223
  scope: options.scope || kit_1.env.getString('SFDX_AUTH_SCOPES', 'refresh_token api web'),
@@ -331,7 +236,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
331
236
  static parseSfdxAuthUrl(sfdxAuthUrl) {
332
237
  const match = sfdxAuthUrl.match(/^force:\/\/([a-zA-Z0-9._-]+):([a-zA-Z0-9._-]*):([a-zA-Z0-9._-]+={0,2})@([a-zA-Z0-9._-]+)/);
333
238
  if (!match) {
334
- throw new sfdxError_1.SfdxError('Invalid sfdx auth url. Must be in the format `force://<clientId>:<clientSecret>:<refreshToken>@<loginUrl>`. The instanceUrl must not have the protocol set.', 'INVALID_SFDX_AUTH_URL');
239
+ throw new sfdxError_1.SfdxError('Invalid SFDX auth URL. Must be in the format "force://<clientId>:<clientSecret>:<refreshToken>@<instanceUrl>". Note that the SFDX auth URL uses the "force" protocol, and not "http" or "https". Also note that the "instanceUrl" inside the SFDX auth URL doesn\'t include the protocol ("https://").', 'INVALID_SFDX_AUTH_URL');
335
240
  }
336
241
  const [, clientId, clientSecret, refreshToken, loginUrl] = match;
337
242
  return {
@@ -381,7 +286,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
381
286
  */
382
287
  async save(authData) {
383
288
  this.update(authData);
384
- const username = ts_types_1.ensure(this.getUsername());
289
+ const username = (0, ts_types_1.ensure)(this.getUsername());
385
290
  if (sfdc_1.sfdc.matchesAccessToken(username)) {
386
291
  this.logger.debug('Username is an accesstoken. Skip saving authinfo to disk.');
387
292
  return this;
@@ -398,11 +303,11 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
398
303
  */
399
304
  update(authData) {
400
305
  // todo move into configstore
401
- if (authData && ts_types_1.isPlainObject(authData)) {
306
+ if (authData && (0, ts_types_1.isPlainObject)(authData)) {
402
307
  this.username = authData.username || this.username;
403
- const existingFields = this.globalInfo.getOrg(this.getUsername());
308
+ const existingFields = this.globalInfo.orgs.get(this.getUsername());
404
309
  const mergedFields = Object.assign({}, existingFields || {}, authData);
405
- this.globalInfo.setOrg(this.getUsername(), mergedFields);
310
+ this.globalInfo.orgs.set(this.getUsername(), mergedFields);
406
311
  this.logger.info(`Updated auth info for username: ${this.getUsername()}`);
407
312
  }
408
313
  return this;
@@ -436,9 +341,9 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
436
341
  // Decrypt a user provided client secret or use the default.
437
342
  opts = {
438
343
  oauth2: {
439
- loginUrl: instanceUrl || 'https://login.salesforce.com',
440
- clientId: decryptedCopy.clientId || exports.DEFAULT_CONNECTED_APP_INFO.legacyClientId,
441
- redirectUri: 'http://localhost:1717/OauthRedirect',
344
+ loginUrl: instanceUrl || sfdcUrl_1.SfdcUrl.PRODUCTION,
345
+ clientId: this.getClientId(),
346
+ redirectUri: this.getRedirectUri(),
442
347
  },
443
348
  accessToken,
444
349
  instanceUrl,
@@ -448,21 +353,28 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
448
353
  // decrypt the fields
449
354
  return opts;
450
355
  }
356
+ getClientId() {
357
+ var _a;
358
+ return ((_a = this.getFields()) === null || _a === void 0 ? void 0 : _a.clientId) || exports.DEFAULT_CONNECTED_APP_INFO.legacyClientId;
359
+ }
360
+ getRedirectUri() {
361
+ return 'http://localhost:1717/OauthRedirect';
362
+ }
451
363
  /**
452
364
  * Get the authorization fields.
453
365
  *
454
366
  * @param decrypt Decrypt the fields.
455
367
  */
456
368
  getFields(decrypt) {
457
- return this.globalInfo.getOrg(this.username, decrypt);
369
+ return this.globalInfo.orgs.get(this.username, decrypt);
458
370
  }
459
371
  /**
460
372
  * Get the org front door (used for web based oauth flows)
461
373
  */
462
374
  getOrgFrontDoorUrl() {
463
375
  const authFields = this.getFields(true);
464
- const base = ts_types_1.ensureString(authFields.instanceUrl).replace(/\/+$/, '');
465
- const accessToken = ts_types_1.ensureString(authFields.accessToken);
376
+ const base = (0, ts_types_1.ensureString)(authFields.instanceUrl).replace(/\/+$/, '');
377
+ const accessToken = (0, ts_types_1.ensureString)(authFields.accessToken);
466
378
  return `${base}/secur/frontdoor.jsp?sid=${accessToken}`;
467
379
  }
468
380
  /**
@@ -478,38 +390,38 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
478
390
  */
479
391
  getSfdxAuthUrl() {
480
392
  const decryptedFields = this.getFields(true);
481
- const instanceUrl = ts_types_1.ensure(decryptedFields.instanceUrl, 'undefined instanceUrl').replace(/^https?:\/\//, '');
393
+ const instanceUrl = (0, ts_types_1.ensure)(decryptedFields.instanceUrl, 'undefined instanceUrl').replace(/^https?:\/\//, '');
482
394
  let sfdxAuthUrl = 'force://';
483
395
  if (decryptedFields.clientId) {
484
396
  sfdxAuthUrl += `${decryptedFields.clientId}:${decryptedFields.clientSecret || ''}:`;
485
397
  }
486
- sfdxAuthUrl += `${ts_types_1.ensure(decryptedFields.refreshToken, 'undefined refreshToken')}@${instanceUrl}`;
398
+ sfdxAuthUrl += `${(0, ts_types_1.ensure)(decryptedFields.refreshToken, 'undefined refreshToken')}@${instanceUrl}`;
487
399
  return sfdxAuthUrl;
488
400
  }
489
401
  /**
490
- * Set the defaultusername or the defaultdevhubusername to the alias if
402
+ * Set the target-env (default) or the target-dev-hub to the alias if
491
403
  * it exists otherwise to the username. Method will try to set the local
492
404
  * config first but will default to global config if that fails.
493
405
  *
494
406
  * @param options
495
407
  */
496
- async setAsDefault(options) {
408
+ async setAsDefault(options = { org: true }) {
497
409
  let config;
498
410
  // if we fail to create the local config, default to the global config
499
411
  try {
500
412
  config = await config_1.Config.create({ isGlobal: false });
501
413
  }
502
- catch (_a) {
414
+ catch {
503
415
  config = await config_1.Config.create({ isGlobal: true });
504
416
  }
505
- const username = ts_types_1.ensureString(this.getUsername());
506
- const aliases = await aliases_1.Aliases.create(aliases_1.Aliases.getDefaultOptions());
507
- const value = aliases.getKeysByValue(username)[0] || username;
508
- if (options.defaultUsername) {
509
- config.set(config_1.Config.DEFAULT_USERNAME, value);
417
+ const username = (0, ts_types_1.ensureString)(this.getUsername());
418
+ const alias = this.globalInfo.aliases.get(username);
419
+ const value = alias !== null && alias !== void 0 ? alias : username;
420
+ if (options.org) {
421
+ config.set(orgConfigProperties_1.OrgConfigProperties.TARGET_ORG, value);
510
422
  }
511
- if (options.defaultDevhubUsername) {
512
- config.set(config_1.Config.DEFAULT_DEV_HUB_USERNAME, value);
423
+ if (options.devHub) {
424
+ config.set(orgConfigProperties_1.OrgConfigProperties.TARGET_DEV_HUB, value);
513
425
  }
514
426
  await config.write();
515
427
  }
@@ -519,15 +431,14 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
519
431
  * @param alias alias to set
520
432
  */
521
433
  async setAlias(alias) {
522
- const username = this.getUsername();
523
- await aliases_1.Aliases.parseAndUpdate([`${alias}=${username}`]);
434
+ this.globalInfo.aliases.set(alias, this.getUsername());
524
435
  }
525
436
  /**
526
437
  * Initializes an instance of the AuthInfo class.
527
438
  */
528
439
  async init() {
529
440
  // We have to set the global instance here because we need synchronous access to it later
530
- this.globalInfo = await globalInfoConfig_1.GlobalInfo.getInstance();
441
+ this.globalInfo = await globalInfo_1.GlobalInfo.getInstance();
531
442
  const username = this.options.username;
532
443
  const authOptions = this.options.oauth2Options || this.options.accessTokenOptions;
533
444
  // Must specify either username and/or options
@@ -537,17 +448,17 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
537
448
  // If a username AND oauth options, ensure an authorization for the username doesn't
538
449
  // already exist. Throw if it does so we don't overwrite the authorization.
539
450
  if (username && authOptions) {
540
- const authExists = this.globalInfo.hasOrg(username);
451
+ const authExists = this.globalInfo.orgs.has(username);
541
452
  if (authExists) {
542
453
  throw messages.createError('authInfoOverwriteError');
543
454
  }
544
455
  }
545
- const oauthUsername = username || ts_types_1.getString(authOptions, 'username');
456
+ const oauthUsername = username || (0, ts_types_1.getString)(authOptions, 'username');
546
457
  if (oauthUsername) {
547
458
  this.username = oauthUsername;
548
459
  } // Else it will be set in initAuthOptions below.
549
460
  // If the username is an access token, use that for auth and don't persist
550
- if (ts_types_1.isString(oauthUsername) && sfdc_1.sfdc.matchesAccessToken(oauthUsername)) {
461
+ if ((0, ts_types_1.isString)(oauthUsername) && sfdc_1.sfdc.matchesAccessToken(oauthUsername)) {
551
462
  // Need to initAuthOptions the logger and authInfoCrypto since we don't call init()
552
463
  this.logger = await logger_1.Logger.child('AuthInfo');
553
464
  const aggregator = await configAggregator_1.ConfigAggregator.create();
@@ -561,7 +472,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
561
472
  this.usingAccessToken = true;
562
473
  }
563
474
  // If a username with NO oauth options, ensure authorization already exist.
564
- else if (username && !authOptions && !this.globalInfo.hasOrg(username)) {
475
+ else if (username && !authOptions && !this.globalInfo.orgs.has(username)) {
565
476
  throw messages.createError('namedOrgNotFound', [username]);
566
477
  }
567
478
  else {
@@ -569,8 +480,8 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
569
480
  }
570
481
  }
571
482
  getInstanceUrl(options, aggregator) {
572
- const instanceUrl = ts_types_1.getString(options, 'instanceUrl') || aggregator.getPropertyValue('instanceUrl');
573
- return instanceUrl || SfdcUrl.PRODUCTION;
483
+ const instanceUrl = (0, ts_types_1.getString)(options, 'instanceUrl') || aggregator.getPropertyValue('instanceUrl');
484
+ return instanceUrl || sfdcUrl_1.SfdcUrl.PRODUCTION;
574
485
  }
575
486
  /**
576
487
  * Initialize this AuthInfo instance with the specified options. If options are not provided, initialize it from cache
@@ -586,10 +497,10 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
586
497
  // If options were passed, use those before checking cache and reading an auth file.
587
498
  let authConfig;
588
499
  if (options) {
589
- options = kit_1.cloneJson(options);
500
+ options = (0, kit_1.cloneJson)(options);
590
501
  if (this.isTokenOptions(options)) {
591
502
  authConfig = options;
592
- const userInfo = await this.retrieveUserInfo(ts_types_1.ensureString(options.instanceUrl), ts_types_1.ensureString(options.accessToken));
503
+ const userInfo = await this.retrieveUserInfo((0, ts_types_1.ensureString)(options.instanceUrl), (0, ts_types_1.ensureString)(options.accessToken));
593
504
  this.update({ username: userInfo === null || userInfo === void 0 ? void 0 : userInfo.username, orgId: userInfo === null || userInfo === void 0 ? void 0 : userInfo.organizationId });
594
505
  }
595
506
  else {
@@ -603,14 +514,14 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
603
514
  // Grab whatever flow is defined
604
515
  Object.assign(options, {
605
516
  clientSecret: parentFields.clientSecret,
606
- privateKey: parentFields.privateKey ? path_1.resolve(parentFields.privateKey) : parentFields.privateKey,
517
+ privateKey: parentFields.privateKey ? (0, path_1.resolve)(parentFields.privateKey) : parentFields.privateKey,
607
518
  });
608
519
  }
609
520
  }
610
521
  // jwt flow
611
522
  // Support both sfdx and jsforce private key values
612
523
  if (!options.privateKey && options.privateKeyFile) {
613
- options.privateKey = path_1.resolve(options.privateKeyFile);
524
+ options.privateKey = (0, path_1.resolve)(options.privateKeyFile);
614
525
  }
615
526
  if (options.privateKey) {
616
527
  authConfig = await this.buildJwtConfig(options);
@@ -620,7 +531,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
620
531
  authConfig = await this.buildRefreshTokenConfig(options);
621
532
  }
622
533
  else {
623
- if (this.options.oauth2 instanceof OAuth2WithVerifier) {
534
+ if (this.options.oauth2 instanceof jsforce_1.OAuth2) {
624
535
  // authcode exchange / web auth flow
625
536
  authConfig = await this.exchangeToken(options, this.options.oauth2);
626
537
  }
@@ -636,15 +547,15 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
636
547
  }
637
548
  async loadDecryptedAuthFromConfig(username) {
638
549
  // Fetch from the persisted auth file
639
- const authInfo = this.globalInfo.getOrg(username, true);
550
+ const authInfo = this.globalInfo.orgs.get(username, true);
640
551
  if (!authInfo) {
641
552
  throw messages.createError('namedOrgNotFound', [username]);
642
553
  }
643
554
  return authInfo;
644
555
  }
645
556
  isTokenOptions(options) {
646
- // Although OAuth2Options does not contain refreshToken, privateKey, or privateKeyFile, a JS consumer could still pass those in
647
- // which WILL have an access token as well, but it should be considered an OAuth2Options at that point.
557
+ // Although OAuth2Config does not contain refreshToken, privateKey, or privateKeyFile, a JS consumer could still pass those in
558
+ // which WILL have an access token as well, but it should be considered an OAuth2Config at that point.
648
559
  return ('accessToken' in options &&
649
560
  !('refreshToken' in options) &&
650
561
  !('privateKey' in options) &&
@@ -654,6 +565,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
654
565
  // A callback function for a connection to refresh an access token. This is used
655
566
  // both for a JWT connection and an OAuth connection.
656
567
  async refreshFn(conn, callback) {
568
+ var _a;
657
569
  this.logger.info('Access token has expired. Updating...');
658
570
  try {
659
571
  const fields = this.getFields(true);
@@ -662,17 +574,21 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
662
574
  return await callback(null, fields.accessToken);
663
575
  }
664
576
  catch (err) {
665
- if (err.message && err.message.includes('Data Not Available')) {
577
+ const error = err;
578
+ if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('Data Not Available')) {
666
579
  // Set cause to keep original stacktrace
667
- return await callback(messages.createError('orgDataNotAvailableError', [this.getUsername()], [], err));
580
+ return await callback(messages.createError('orgDataNotAvailableError', [this.getUsername()], [], error));
668
581
  }
669
- return await callback(err);
582
+ return await callback(error);
670
583
  }
671
584
  }
672
585
  // Build OAuth config for a JWT auth flow
673
586
  async buildJwtConfig(options) {
674
- const privateKeyContents = await fs_1.fs.readFile(ts_types_1.ensure(options.privateKey), 'utf8');
675
- const audienceUrl = await getJwtAudienceUrl(options);
587
+ const privateKeyContents = await fs_1.fs.readFile((0, ts_types_1.ensure)(options.privateKey), 'utf8');
588
+ const { loginUrl = sfdcUrl_1.SfdcUrl.PRODUCTION } = options;
589
+ const url = new sfdcUrl_1.SfdcUrl(loginUrl);
590
+ const createdOrgInstance = (0, ts_types_1.getString)(options, 'createdOrgInstance', '').trim().toLowerCase();
591
+ const audienceUrl = await url.getJwtAudienceUrl(createdOrgInstance);
676
592
  const jwtToken = jwt.sign({
677
593
  iss: options.clientId,
678
594
  sub: this.getUsername(),
@@ -684,23 +600,23 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
684
600
  const oauth2 = new JwtOAuth2({ loginUrl: options.loginUrl });
685
601
  let authFieldsBuilder;
686
602
  try {
687
- authFieldsBuilder = ts_types_1.ensureJsonMap(await oauth2.jwtAuthorize(jwtToken));
603
+ authFieldsBuilder = (0, ts_types_1.ensureJsonMap)(await oauth2.jwtAuthorize(jwtToken));
688
604
  }
689
605
  catch (err) {
690
606
  throw messages.createError('jwtAuthError', [err.message]);
691
607
  }
692
608
  const authFields = {
693
- accessToken: ts_types_1.asString(authFieldsBuilder.access_token),
694
- orgId: parseIdUrl(ts_types_1.ensureString(authFieldsBuilder.id)).orgId,
609
+ accessToken: (0, ts_types_1.asString)(authFieldsBuilder.access_token),
610
+ orgId: parseIdUrl((0, ts_types_1.ensureString)(authFieldsBuilder.id)).orgId,
695
611
  loginUrl: options.loginUrl,
696
612
  privateKey: options.privateKey,
697
613
  clientId: options.clientId,
698
614
  };
699
- const instanceUrl = ts_types_1.ensureString(authFieldsBuilder.instance_url);
700
- const parsedUrl = url_2.parse(instanceUrl);
615
+ const instanceUrl = (0, ts_types_1.ensureString)(authFieldsBuilder.instance_url);
616
+ const sfdcUrl = new sfdcUrl_1.SfdcUrl(instanceUrl);
701
617
  try {
702
618
  // Check if the url is resolvable. This can fail when my-domains have not been replicated.
703
- await this.lookup(ts_types_1.ensure(parsedUrl.hostname));
619
+ await sfdcUrl.lookup();
704
620
  authFields.instanceUrl = instanceUrl;
705
621
  }
706
622
  catch (err) {
@@ -717,32 +633,31 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
717
633
  options.clientId = exports.DEFAULT_CONNECTED_APP_INFO.legacyClientId;
718
634
  options.clientSecret = exports.DEFAULT_CONNECTED_APP_INFO.legacyClientSecret;
719
635
  }
636
+ if (!options.redirectUri) {
637
+ options.redirectUri = this.getRedirectUri();
638
+ }
720
639
  const oauth2 = new jsforce_1.OAuth2(options);
721
640
  let authFieldsBuilder;
722
641
  try {
723
- authFieldsBuilder = await oauth2.refreshToken(ts_types_1.ensure(options.refreshToken));
642
+ authFieldsBuilder = await oauth2.refreshToken((0, ts_types_1.ensure)(options.refreshToken));
724
643
  }
725
644
  catch (err) {
726
645
  throw messages.createError('refreshTokenAuthError', [err.message]);
727
646
  }
728
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
729
647
  // @ts-ignore
730
648
  const { orgId } = parseIdUrl(authFieldsBuilder.id);
731
649
  let username = this.getUsername();
732
650
  if (!username) {
733
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
734
651
  // @ts-ignore
735
652
  const userInfo = await this.retrieveUserInfo(authFieldsBuilder.instance_url, authFieldsBuilder.access_token);
736
- username = ts_types_1.ensureString(userInfo === null || userInfo === void 0 ? void 0 : userInfo.username);
653
+ username = (0, ts_types_1.ensureString)(userInfo === null || userInfo === void 0 ? void 0 : userInfo.username);
737
654
  }
738
655
  return {
739
656
  orgId,
740
657
  username,
741
658
  accessToken: authFieldsBuilder.access_token,
742
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
743
659
  // @ts-ignore TODO: need better typings for jsforce
744
660
  instanceUrl: authFieldsBuilder.instance_url,
745
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
746
661
  // @ts-ignore TODO: need better typings for jsforce
747
662
  loginUrl: options.loginUrl || authFieldsBuilder.instance_url,
748
663
  refreshToken: options.refreshToken,
@@ -757,35 +672,37 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
757
672
  * @param oauth2 The oauth2 extension that includes a code_challenge
758
673
  */
759
674
  async exchangeToken(options, oauth2 = new jsforce_1.OAuth2(options)) {
675
+ if (!oauth2.redirectUri) {
676
+ oauth2.redirectUri = this.getRedirectUri();
677
+ }
678
+ if (!oauth2.clientId) {
679
+ oauth2.clientId = this.getClientId();
680
+ }
760
681
  // Exchange the auth code for an access token and refresh token.
761
682
  let authFields;
762
683
  try {
763
684
  this.logger.info(`Exchanging auth code for access token using loginUrl: ${options.loginUrl}`);
764
- authFields = await oauth2.requestToken(ts_types_1.ensure(options.authCode));
685
+ authFields = await oauth2.requestToken((0, ts_types_1.ensure)(options.authCode));
765
686
  }
766
687
  catch (err) {
767
688
  throw messages.createError('authCodeExchangeError', [err.message]);
768
689
  }
769
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
770
690
  // @ts-ignore TODO: need better typings for jsforce
771
691
  const { orgId } = parseIdUrl(authFields.id);
772
692
  let username = this.getUsername();
773
693
  // Only need to query for the username if it isn't known. For example, a new auth code exchange
774
694
  // rather than refreshing a token on an existing connection.
775
695
  if (!username) {
776
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
777
696
  // @ts-ignore
778
697
  const userInfo = await this.retrieveUserInfo(authFields.instance_url, authFields.access_token);
779
698
  username = userInfo === null || userInfo === void 0 ? void 0 : userInfo.username;
780
699
  }
781
700
  return {
782
701
  accessToken: authFields.access_token,
783
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
784
702
  // @ts-ignore TODO: need better typings for jsforce
785
703
  instanceUrl: authFields.instance_url,
786
704
  orgId,
787
705
  username,
788
- // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
789
706
  // @ts-ignore TODO: need better typings for jsforce
790
707
  loginUrl: options.loginUrl || authFields.instance_url,
791
708
  refreshToken: authFields.refresh_token,
@@ -798,26 +715,27 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
798
715
  // but we don't want to create circular dependencies or lots of snowflakes
799
716
  // within this file to support it.
800
717
  const apiVersion = 'v51.0'; // hardcoding to v51.0 just for this call is okay.
801
- const instance = ts_types_1.ensure(instanceUrl);
802
- const baseUrl = new url_1.URL(instance);
718
+ const instance = (0, ts_types_1.ensure)(instanceUrl);
719
+ const baseUrl = new sfdcUrl_1.SfdcUrl(instance);
803
720
  const userInfoUrl = `${baseUrl}services/oauth2/userinfo`;
804
721
  const headers = Object.assign({ Authorization: `Bearer ${accessToken}` }, connection_1.SFDX_HTTP_HEADERS);
805
722
  try {
806
723
  this.logger.info(`Sending request for Username after successful auth code exchange to URL: ${userInfoUrl}`);
807
- let response = await new Transport().httpRequest({ url: userInfoUrl, headers });
724
+ let response = await new transport_1.default().httpRequest({ url: userInfoUrl, method: 'GET', headers });
808
725
  if (response.statusCode >= 400) {
809
726
  this.throwUserGetException(response);
810
727
  }
811
728
  else {
812
- const userInfoJson = kit_1.parseJsonMap(response.body);
729
+ const userInfoJson = (0, kit_1.parseJsonMap)(response.body);
813
730
  const url = `${baseUrl}/services/data/${apiVersion}/sobjects/User/${userInfoJson.user_id}`;
814
731
  this.logger.info(`Sending request for User SObject after successful auth code exchange to URL: ${url}`);
815
- response = await new Transport().httpRequest({ url, headers });
732
+ response = await new transport_1.default().httpRequest({ url, method: 'GET', headers });
816
733
  if (response.statusCode >= 400) {
817
734
  this.throwUserGetException(response);
818
735
  }
819
736
  else {
820
- userInfoJson.preferred_username = kit_1.parseJsonMap(response.body).Username;
737
+ // eslint-disable-next-line camelcase
738
+ userInfoJson.preferred_username = (0, kit_1.parseJsonMap)(response.body).Username;
821
739
  }
822
740
  return { username: userInfoJson.preferred_username, organizationId: userInfoJson.organization_id };
823
741
  }
@@ -835,16 +753,16 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
835
753
  throwUserGetException(response) {
836
754
  var _a;
837
755
  let errorMsg = '';
838
- const bodyAsString = ts_types_1.getString(response, 'body', JSON.stringify({ message: 'UNKNOWN', errorCode: 'UNKNOWN' }));
756
+ const bodyAsString = (0, ts_types_1.getString)(response, 'body', JSON.stringify({ message: 'UNKNOWN', errorCode: 'UNKNOWN' }));
839
757
  try {
840
- const body = kit_1.parseJson(bodyAsString);
841
- if (ts_types_1.isArray(body)) {
758
+ const body = (0, kit_1.parseJson)(bodyAsString);
759
+ if ((0, ts_types_1.isArray)(body)) {
842
760
  errorMsg = body
843
- .map((line) => { var _a; return (_a = ts_types_1.getString(line, 'message')) !== null && _a !== void 0 ? _a : ts_types_1.getString(line, 'errorCode', 'UNKNOWN'); })
761
+ .map((line) => { var _a; return (_a = (0, ts_types_1.getString)(line, 'message')) !== null && _a !== void 0 ? _a : (0, ts_types_1.getString)(line, 'errorCode', 'UNKNOWN'); })
844
762
  .join(os.EOL);
845
763
  }
846
764
  else {
847
- errorMsg = (_a = ts_types_1.getString(body, 'message')) !== null && _a !== void 0 ? _a : ts_types_1.getString(body, 'errorCode', 'UNKNOWN');
765
+ errorMsg = (_a = (0, ts_types_1.getString)(body, 'message')) !== null && _a !== void 0 ? _a : (0, ts_types_1.getString)(body, 'errorCode', 'UNKNOWN');
848
766
  }
849
767
  }
850
768
  catch (err) {
@@ -852,19 +770,6 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
852
770
  }
853
771
  throw new sfdxError_1.SfdxError(errorMsg);
854
772
  }
855
- // See https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback
856
- async lookup(host) {
857
- return new Promise((resolve, reject) => {
858
- dns.lookup(host, (err, address, family) => {
859
- if (err) {
860
- reject(err);
861
- }
862
- else {
863
- resolve({ address, family });
864
- }
865
- });
866
- });
867
- }
868
773
  }
869
774
  exports.AuthInfo = AuthInfo;
870
775
  //# sourceMappingURL=authInfo.js.map