@salesforce/core 3.11.0 → 3.12.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.
- package/CHANGELOG.md +14 -0
- package/lib/deviceOauthService.d.ts +1 -1
- package/lib/deviceOauthService.js +14 -15
- package/lib/org/authInfo.d.ts +13 -0
- package/lib/org/authInfo.js +56 -0
- package/lib/testSetup.js +2 -2
- package/package.json +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [3.12.1](https://github.com/forcedotcom/sfdx-core/compare/v3.12.0...v3.12.1) (2022-04-05)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- more FormData with buffers and headers ([5ebf78f](https://github.com/forcedotcom/sfdx-core/commit/5ebf78fe2b037df395c87197b90ee06a0d34d5d0))
|
|
10
|
+
|
|
11
|
+
## [3.12.0](https://github.com/forcedotcom/sfdx-core/compare/v3.11.1...v3.12.0) (2022-04-04)
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- move common authinfo utils to core ([01b8cf3](https://github.com/forcedotcom/sfdx-core/commit/01b8cf3fa38162380da5ce15f6dee1d2a5d2d72d))
|
|
16
|
+
|
|
17
|
+
### [3.11.1](https://github.com/forcedotcom/sfdx-core/compare/v3.11.0...v3.11.1) (2022-04-01)
|
|
18
|
+
|
|
5
19
|
## [3.11.0](https://github.com/forcedotcom/sfdx-core/compare/v3.10.1...v3.11.0) (2022-03-30)
|
|
6
20
|
|
|
7
21
|
### Features
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncCreatable } from '@salesforce/kit';
|
|
2
2
|
import { OAuth2Config } from 'jsforce/lib/oauth2';
|
|
3
|
-
import {
|
|
3
|
+
import { JsonMap, Nullable } from '@salesforce/ts-types';
|
|
4
4
|
import { AuthInfo } from './org/authInfo';
|
|
5
5
|
export interface DeviceCodeResponse extends JsonMap {
|
|
6
6
|
device_code: string;
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.DeviceOauthService = void 0;
|
|
12
|
-
const url_1 = require("url");
|
|
13
12
|
const transport_1 = require("jsforce/lib/transport");
|
|
14
13
|
const kit_1 = require("@salesforce/kit");
|
|
15
14
|
const ts_types_1 = require("@salesforce/ts-types");
|
|
15
|
+
const FormData = require("form-data");
|
|
16
16
|
const logger_1 = require("./logger");
|
|
17
17
|
const authInfo_1 = require("./org/authInfo");
|
|
18
18
|
const sfError_1 = require("./sfError");
|
|
@@ -82,8 +82,7 @@ class DeviceOauthService extends kit_1.AsyncCreatable {
|
|
|
82
82
|
const deviceFlowRequestUrl = this.getDeviceFlowRequestUrl();
|
|
83
83
|
const pollingOptions = this.getPollingOptions(deviceFlowRequestUrl, loginData.device_code);
|
|
84
84
|
const interval = kit_1.Duration.seconds(loginData.interval).milliseconds;
|
|
85
|
-
|
|
86
|
-
return response;
|
|
85
|
+
return await this.pollForDeviceApproval(pollingOptions, interval);
|
|
87
86
|
}
|
|
88
87
|
/**
|
|
89
88
|
* Creates and saves new AuthInfo
|
|
@@ -108,27 +107,27 @@ class DeviceOauthService extends kit_1.AsyncCreatable {
|
|
|
108
107
|
this.logger.debug(`this.options.loginUrl: ${this.options.loginUrl}`);
|
|
109
108
|
}
|
|
110
109
|
getLoginOptions(url) {
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
const form = new FormData();
|
|
111
|
+
form.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
|
|
112
|
+
form.append('response_type', DeviceOauthService.RESPONSE_TYPE);
|
|
113
|
+
form.append('scope', DeviceOauthService.SCOPE);
|
|
115
114
|
return {
|
|
116
115
|
url,
|
|
117
|
-
headers: connection_1.SFDX_HTTP_HEADERS,
|
|
116
|
+
headers: { ...connection_1.SFDX_HTTP_HEADERS, ...form.getHeaders() },
|
|
118
117
|
method: 'POST',
|
|
119
|
-
body,
|
|
118
|
+
body: form.getBuffer(),
|
|
120
119
|
};
|
|
121
120
|
}
|
|
122
121
|
getPollingOptions(url, code) {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
const form = new FormData();
|
|
123
|
+
form.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
|
|
124
|
+
form.append('grant_type', DeviceOauthService.GRANT_TYPE);
|
|
125
|
+
form.append('code', code);
|
|
127
126
|
return {
|
|
128
127
|
url,
|
|
129
|
-
headers: connection_1.SFDX_HTTP_HEADERS,
|
|
128
|
+
headers: { ...connection_1.SFDX_HTTP_HEADERS, ...form.getHeaders() },
|
|
130
129
|
method: 'POST',
|
|
131
|
-
body,
|
|
130
|
+
body: form.getBuffer(),
|
|
132
131
|
};
|
|
133
132
|
}
|
|
134
133
|
getDeviceFlowRequestUrl() {
|
package/lib/org/authInfo.d.ts
CHANGED
|
@@ -171,6 +171,19 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
|
|
|
171
171
|
* @param sfdxAuthUrl
|
|
172
172
|
*/
|
|
173
173
|
static parseSfdxAuthUrl(sfdxAuthUrl: string): Pick<AuthFields, 'clientId' | 'clientSecret' | 'refreshToken' | 'loginUrl'>;
|
|
174
|
+
/**
|
|
175
|
+
* Given a set of decrypted fields and an authInfo, determine if the org belongs to an available
|
|
176
|
+
* dev hub.
|
|
177
|
+
*
|
|
178
|
+
* @param fields
|
|
179
|
+
* @param orgAuthInfo
|
|
180
|
+
*/
|
|
181
|
+
static identifyPossibleScratchOrgs(fields: AuthFields, orgAuthInfo: AuthInfo): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Find all dev hubs available in the local environment.
|
|
184
|
+
*/
|
|
185
|
+
static getDevHubAuthInfos(): Promise<OrgAuthorization[]>;
|
|
186
|
+
private static queryScratchOrg;
|
|
174
187
|
/**
|
|
175
188
|
* Get the username.
|
|
176
189
|
*/
|
package/lib/org/authInfo.js
CHANGED
|
@@ -26,6 +26,7 @@ const messages_1 = require("../messages");
|
|
|
26
26
|
const sfdcUrl_1 = require("../util/sfdcUrl");
|
|
27
27
|
const connection_1 = require("./connection");
|
|
28
28
|
const orgConfigProperties_1 = require("./orgConfigProperties");
|
|
29
|
+
const org_1 = require("./org");
|
|
29
30
|
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
30
31
|
const messages = messages_1.Messages.load('@salesforce/core', 'core', [
|
|
31
32
|
'authInfoCreationError',
|
|
@@ -246,6 +247,61 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
246
247
|
loginUrl: `https://${loginUrl}`,
|
|
247
248
|
};
|
|
248
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Given a set of decrypted fields and an authInfo, determine if the org belongs to an available
|
|
252
|
+
* dev hub.
|
|
253
|
+
*
|
|
254
|
+
* @param fields
|
|
255
|
+
* @param orgAuthInfo
|
|
256
|
+
*/
|
|
257
|
+
static async identifyPossibleScratchOrgs(fields, orgAuthInfo) {
|
|
258
|
+
// fields property is passed in because the consumers of this method have performed the decrypt.
|
|
259
|
+
// This is so we don't have to call authInfo.getFields(true) and decrypt again OR accidentally save an
|
|
260
|
+
// authInfo before it is necessary.
|
|
261
|
+
const logger = await logger_1.Logger.child('Common', { tag: 'identifyPossibleScratchOrgs' });
|
|
262
|
+
// return if we already know the hub org we know it is a devhub or prod-like or no orgId present
|
|
263
|
+
if (fields.isDevHub || fields.devHubUsername || !fields.orgId)
|
|
264
|
+
return;
|
|
265
|
+
logger.debug('getting devHubs');
|
|
266
|
+
// TODO: return if url is not sandbox-like to avoid constantly asking about production orgs
|
|
267
|
+
// TODO: someday we make this easier by asking the org if it is a scratch org
|
|
268
|
+
const hubAuthInfos = await AuthInfo.getDevHubAuthInfos();
|
|
269
|
+
logger.debug(`found ${hubAuthInfos.length} DevHubs`);
|
|
270
|
+
if (hubAuthInfos.length === 0)
|
|
271
|
+
return;
|
|
272
|
+
// ask all those orgs if they know this orgId
|
|
273
|
+
await Promise.all(hubAuthInfos.map(async (hubAuthInfo) => {
|
|
274
|
+
try {
|
|
275
|
+
const data = await AuthInfo.queryScratchOrg(hubAuthInfo.username, fields.orgId);
|
|
276
|
+
if (data.totalSize > 0) {
|
|
277
|
+
// if any return a result
|
|
278
|
+
logger.debug(`found orgId ${fields.orgId} in devhub ${hubAuthInfo.username}`);
|
|
279
|
+
try {
|
|
280
|
+
await orgAuthInfo.save({ ...fields, devHubUsername: hubAuthInfo.username });
|
|
281
|
+
logger.debug(`set ${hubAuthInfo.username} as devhub for scratch org ${orgAuthInfo.getUsername()}`);
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
logger.debug(`error updating auth file for ${orgAuthInfo.getUsername()}`, error);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
logger.error(`Error connecting to devhub ${hubAuthInfo.username}`, error);
|
|
290
|
+
}
|
|
291
|
+
}));
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Find all dev hubs available in the local environment.
|
|
295
|
+
*/
|
|
296
|
+
static async getDevHubAuthInfos() {
|
|
297
|
+
return (await AuthInfo.listAllAuthorizations()).filter((possibleHub) => possibleHub === null || possibleHub === void 0 ? void 0 : possibleHub.isDevHub);
|
|
298
|
+
}
|
|
299
|
+
static async queryScratchOrg(devHubUsername, scratchOrgId) {
|
|
300
|
+
const devHubOrg = await org_1.Org.create({ aliasOrUsername: devHubUsername });
|
|
301
|
+
const conn = devHubOrg.getConnection();
|
|
302
|
+
const data = await conn.query(`select Id from ScratchOrgInfo where ScratchOrg = '${sfdc_1.sfdc.trimTo15(scratchOrgId)}'`);
|
|
303
|
+
return data;
|
|
304
|
+
}
|
|
249
305
|
/**
|
|
250
306
|
* Get the username.
|
|
251
307
|
*/
|
package/lib/testSetup.js
CHANGED
|
@@ -480,8 +480,8 @@ class MockTestOrgData {
|
|
|
480
480
|
this.userId = `user_id_${this.testId}`;
|
|
481
481
|
this.orgId = `${this.testId}`;
|
|
482
482
|
this.username = (options === null || options === void 0 ? void 0 : options.username) || `admin_${this.testId}@gb.org`;
|
|
483
|
-
this.loginUrl = `
|
|
484
|
-
this.instanceUrl = `
|
|
483
|
+
this.loginUrl = `https://login.${this.testId}.salesforce.com`;
|
|
484
|
+
this.instanceUrl = `https://instance.${this.testId}.salesforce.com`;
|
|
485
485
|
this.clientId = `${this.testId}/client_id`;
|
|
486
486
|
this.clientSecret = `${this.testId}/client_secret`;
|
|
487
487
|
this.authcode = `${this.testId}/authcode`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.1",
|
|
4
4
|
"description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
|
|
5
5
|
"main": "lib/exported",
|
|
6
6
|
"types": "lib/exported.d.ts",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"!lib/**/*.map"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@oclif/core": "^1.5.1",
|
|
38
37
|
"@salesforce/bunyan": "^2.0.0",
|
|
39
38
|
"@salesforce/kit": "^1.5.34",
|
|
40
39
|
"@salesforce/schemas": "^1.1.0",
|