@salesforce/core 3.31.4 → 3.31.7
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/LICENSE.txt +11 -11
- package/README.md +222 -222
- package/lib/config/aliasesConfig.d.ts +12 -12
- package/lib/config/aliasesConfig.js +27 -27
- package/lib/config/authInfoConfig.d.ts +19 -19
- package/lib/config/authInfoConfig.js +34 -34
- package/lib/config/config.d.ts +311 -311
- package/lib/config/config.js +574 -574
- package/lib/config/configAggregator.d.ts +232 -232
- package/lib/config/configAggregator.js +379 -379
- package/lib/config/configFile.d.ts +199 -199
- package/lib/config/configFile.js +340 -340
- package/lib/config/configGroup.d.ts +141 -141
- package/lib/config/configGroup.js +224 -224
- package/lib/config/configStore.d.ts +241 -241
- package/lib/config/configStore.js +352 -352
- package/lib/config/envVars.d.ts +101 -101
- package/lib/config/envVars.js +456 -456
- package/lib/config/orgUsersConfig.d.ts +31 -31
- package/lib/config/orgUsersConfig.js +41 -41
- package/lib/config/sandboxOrgConfig.d.ts +37 -37
- package/lib/config/sandboxOrgConfig.js +50 -50
- package/lib/config/sandboxProcessCache.d.ts +16 -16
- package/lib/config/sandboxProcessCache.js +37 -37
- package/lib/config/tokensConfig.d.ts +10 -10
- package/lib/config/tokensConfig.js +28 -28
- package/lib/config/ttlConfig.d.ts +34 -34
- package/lib/config/ttlConfig.js +54 -54
- package/lib/crypto/crypto.d.ts +54 -54
- package/lib/crypto/crypto.js +220 -220
- package/lib/crypto/keyChain.d.ts +8 -8
- package/lib/crypto/keyChain.js +61 -61
- package/lib/crypto/keyChainImpl.d.ts +116 -116
- package/lib/crypto/keyChainImpl.js +486 -486
- package/lib/crypto/secureBuffer.d.ts +46 -46
- package/lib/crypto/secureBuffer.js +82 -82
- package/lib/deviceOauthService.d.ts +71 -71
- package/lib/deviceOauthService.js +191 -191
- package/lib/exported.d.ts +38 -38
- package/lib/exported.js +118 -118
- package/lib/global.d.ts +70 -70
- package/lib/global.js +109 -109
- package/lib/lifecycleEvents.d.ts +93 -93
- package/lib/lifecycleEvents.js +188 -188
- package/lib/logger.d.ts +381 -381
- package/lib/logger.js +734 -734
- package/lib/messages.d.ts +291 -291
- package/lib/messages.js +543 -543
- package/lib/org/authInfo.d.ts +344 -344
- package/lib/org/authInfo.js +892 -892
- package/lib/org/authRemover.d.ts +88 -88
- package/lib/org/authRemover.js +182 -182
- package/lib/org/connection.d.ts +197 -197
- package/lib/org/connection.js +395 -395
- package/lib/org/index.d.ts +6 -6
- package/lib/org/index.js +28 -28
- package/lib/org/org.d.ts +558 -558
- package/lib/org/org.js +1267 -1267
- package/lib/org/orgConfigProperties.d.ts +69 -69
- package/lib/org/orgConfigProperties.js +136 -136
- package/lib/org/permissionSetAssignment.d.ts +35 -35
- package/lib/org/permissionSetAssignment.js +125 -125
- package/lib/org/scratchOrgCache.d.ts +20 -20
- package/lib/org/scratchOrgCache.js +32 -32
- package/lib/org/scratchOrgCreate.d.ts +54 -54
- package/lib/org/scratchOrgCreate.js +216 -216
- package/lib/org/scratchOrgErrorCodes.d.ts +10 -10
- package/lib/org/scratchOrgErrorCodes.js +88 -88
- package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -26
- package/lib/org/scratchOrgFeatureDeprecation.js +109 -109
- package/lib/org/scratchOrgInfoApi.d.ts +68 -68
- package/lib/org/scratchOrgInfoApi.js +413 -413
- package/lib/org/scratchOrgInfoGenerator.d.ts +64 -64
- package/lib/org/scratchOrgInfoGenerator.js +241 -241
- package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -10
- package/lib/org/scratchOrgLifecycleEvents.js +40 -40
- package/lib/org/scratchOrgSettingsGenerator.d.ts +78 -78
- package/lib/org/scratchOrgSettingsGenerator.js +276 -276
- package/lib/org/scratchOrgTypes.d.ts +43 -43
- package/lib/org/scratchOrgTypes.js +8 -8
- package/lib/org/user.d.ts +187 -187
- package/lib/org/user.js +448 -448
- package/lib/schema/printer.d.ts +79 -79
- package/lib/schema/printer.js +260 -260
- package/lib/schema/validator.d.ts +70 -70
- package/lib/schema/validator.js +169 -169
- package/lib/sfError.d.ts +73 -73
- package/lib/sfError.js +136 -136
- package/lib/sfProject.d.ts +357 -357
- package/lib/sfProject.js +671 -671
- package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -98
- package/lib/stateAggregator/accessors/aliasAccessor.js +145 -145
- package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -101
- package/lib/stateAggregator/accessors/orgAccessor.js +240 -240
- package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -8
- package/lib/stateAggregator/accessors/sandboxAccessor.js +27 -27
- package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -63
- package/lib/stateAggregator/accessors/tokenAccessor.js +79 -79
- package/lib/stateAggregator/index.d.ts +4 -4
- package/lib/stateAggregator/index.js +26 -26
- package/lib/stateAggregator/stateAggregator.d.ts +25 -25
- package/lib/stateAggregator/stateAggregator.js +45 -45
- package/lib/status/myDomainResolver.d.ts +66 -66
- package/lib/status/myDomainResolver.js +124 -124
- package/lib/status/pollingClient.d.ts +85 -85
- package/lib/status/pollingClient.js +115 -115
- package/lib/status/streamingClient.d.ts +244 -244
- package/lib/status/streamingClient.js +436 -436
- package/lib/status/types.d.ts +89 -89
- package/lib/status/types.js +17 -17
- package/lib/testSetup.d.ts +553 -553
- package/lib/testSetup.js +871 -871
- package/lib/util/cache.d.ts +11 -11
- package/lib/util/cache.js +69 -69
- package/lib/util/checkLightningDomain.d.ts +1 -1
- package/lib/util/checkLightningDomain.js +28 -28
- package/lib/util/directoryWriter.d.ts +12 -12
- package/lib/util/directoryWriter.js +53 -53
- package/lib/util/getJwtAudienceUrl.d.ts +4 -4
- package/lib/util/getJwtAudienceUrl.js +18 -18
- package/lib/util/internal.d.ts +58 -58
- package/lib/util/internal.js +118 -118
- package/lib/util/jsonXmlTools.d.ts +14 -14
- package/lib/util/jsonXmlTools.js +38 -38
- package/lib/util/mapKeys.d.ts +14 -14
- package/lib/util/mapKeys.js +51 -51
- package/lib/util/sfdc.d.ts +52 -52
- package/lib/util/sfdc.js +85 -85
- package/lib/util/sfdcUrl.d.ts +72 -72
- package/lib/util/sfdcUrl.js +215 -215
- package/lib/util/structuredWriter.d.ts +9 -9
- package/lib/util/structuredWriter.js +2 -2
- package/lib/util/zipWriter.d.ts +16 -16
- package/lib/util/zipWriter.js +67 -67
- package/lib/webOAuthServer.d.ts +156 -156
- package/lib/webOAuthServer.js +388 -388
- package/messages/auth.md +37 -37
- package/messages/config.md +156 -156
- package/messages/connection.md +30 -30
- package/messages/core.json +20 -20
- package/messages/core.md +67 -67
- package/messages/encryption.md +85 -85
- package/messages/envVars.md +303 -303
- package/messages/org.md +63 -63
- package/messages/permissionSetAssignment.md +31 -31
- package/messages/scratchOrgCreate.md +23 -23
- package/messages/scratchOrgErrorCodes.md +115 -115
- package/messages/scratchOrgFeatureDeprecation.md +11 -11
- package/messages/scratchOrgInfoApi.md +15 -15
- package/messages/scratchOrgInfoGenerator.md +23 -23
- package/messages/streaming.md +23 -23
- package/messages/user.md +35 -35
- package/package.json +97 -97
|
@@ -1,192 +1,192 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2020, salesforce.com, inc.
|
|
4
|
-
* All rights reserved.
|
|
5
|
-
* Licensed under the BSD 3-Clause license.
|
|
6
|
-
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
-
*/
|
|
8
|
-
/* eslint-disable camelcase */
|
|
9
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.DeviceOauthService = void 0;
|
|
12
|
-
const transport_1 = require("jsforce/lib/transport");
|
|
13
|
-
const kit_1 = require("@salesforce/kit");
|
|
14
|
-
const ts_types_1 = require("@salesforce/ts-types");
|
|
15
|
-
const FormData = require("form-data");
|
|
16
|
-
const logger_1 = require("./logger");
|
|
17
|
-
const org_1 = require("./org");
|
|
18
|
-
const sfError_1 = require("./sfError");
|
|
19
|
-
const messages_1 = require("./messages");
|
|
20
|
-
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
21
|
-
const messages = messages_1.Messages.load('@salesforce/core', 'auth', ['pollingTimeout']);
|
|
22
|
-
async function wait(ms = 1000) {
|
|
23
|
-
return new Promise((resolve) => {
|
|
24
|
-
setTimeout(resolve, ms);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
async function makeRequest(options) {
|
|
28
|
-
const rawResponse = await new transport_1.default().httpRequest(options);
|
|
29
|
-
const response = (0, kit_1.parseJsonMap)(rawResponse.body);
|
|
30
|
-
if (response.error) {
|
|
31
|
-
const err = new sfError_1.SfError('Request Failed.');
|
|
32
|
-
err.data = Object.assign(response, { status: rawResponse.statusCode });
|
|
33
|
-
throw err;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return response;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Handles device based login flows
|
|
41
|
-
*
|
|
42
|
-
* Usage:
|
|
43
|
-
* ```
|
|
44
|
-
* const oauthConfig = {
|
|
45
|
-
* loginUrl: this.flags.instanceurl,
|
|
46
|
-
* clientId: this.flags.clientid,
|
|
47
|
-
* };
|
|
48
|
-
* const deviceOauthService = await DeviceOauthService.create(oauthConfig);
|
|
49
|
-
* const loginData = await deviceOauthService.requestDeviceLogin();
|
|
50
|
-
* console.log(loginData);
|
|
51
|
-
* const approval = await deviceOauthService.awaitDeviceApproval(loginData);
|
|
52
|
-
* const authInfo = await deviceOauthService.authorizeAndSave(approval);
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
class DeviceOauthService extends kit_1.AsyncCreatable {
|
|
56
|
-
constructor(options) {
|
|
57
|
-
super(options);
|
|
58
|
-
this.pollingCount = 0;
|
|
59
|
-
this.options = options;
|
|
60
|
-
if (!this.options.clientId)
|
|
61
|
-
this.options.clientId = org_1.DEFAULT_CONNECTED_APP_INFO.clientId;
|
|
62
|
-
if (!this.options.loginUrl)
|
|
63
|
-
this.options.loginUrl = org_1.AuthInfo.getDefaultInstanceUrl();
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Begin the authorization flow by requesting the login
|
|
67
|
-
*
|
|
68
|
-
* @returns {Promise<DeviceCodeResponse>}
|
|
69
|
-
*/
|
|
70
|
-
async requestDeviceLogin() {
|
|
71
|
-
const deviceFlowRequestUrl = this.getDeviceFlowRequestUrl();
|
|
72
|
-
const loginOptions = this.getLoginOptions(deviceFlowRequestUrl);
|
|
73
|
-
return makeRequest(loginOptions);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Polls the server until successful response OR max attempts have been made
|
|
77
|
-
*
|
|
78
|
-
* @returns {Promise<Nullable<DeviceCodePollingResponse>>}
|
|
79
|
-
*/
|
|
80
|
-
async awaitDeviceApproval(loginData) {
|
|
81
|
-
const deviceFlowRequestUrl = this.getDeviceFlowRequestUrl();
|
|
82
|
-
const pollingOptions = this.getPollingOptions(deviceFlowRequestUrl, loginData.device_code);
|
|
83
|
-
const interval = kit_1.Duration.seconds(loginData.interval).milliseconds;
|
|
84
|
-
return this.pollForDeviceApproval(pollingOptions, interval);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Creates and saves new AuthInfo
|
|
88
|
-
*
|
|
89
|
-
* @returns {Promise<AuthInfo>}
|
|
90
|
-
*/
|
|
91
|
-
async authorizeAndSave(approval) {
|
|
92
|
-
const authInfo = await org_1.AuthInfo.create({
|
|
93
|
-
oauth2Options: {
|
|
94
|
-
loginUrl: approval.instance_url,
|
|
95
|
-
refreshToken: approval.refresh_token,
|
|
96
|
-
clientSecret: this.options.clientSecret,
|
|
97
|
-
clientId: this.options.clientId,
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
await authInfo.save();
|
|
101
|
-
return authInfo;
|
|
102
|
-
}
|
|
103
|
-
async init() {
|
|
104
|
-
this.logger = await logger_1.Logger.child(this.constructor.name);
|
|
105
|
-
this.logger.debug(`this.options.clientId: ${this.options.clientId}`);
|
|
106
|
-
this.logger.debug(`this.options.loginUrl: ${this.options.loginUrl}`);
|
|
107
|
-
}
|
|
108
|
-
getLoginOptions(url) {
|
|
109
|
-
const form = new FormData();
|
|
110
|
-
form.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
|
|
111
|
-
form.append('response_type', DeviceOauthService.RESPONSE_TYPE);
|
|
112
|
-
form.append('scope', DeviceOauthService.SCOPE);
|
|
113
|
-
return {
|
|
114
|
-
url,
|
|
115
|
-
headers: { ...org_1.SFDX_HTTP_HEADERS, ...form.getHeaders() },
|
|
116
|
-
method: 'POST',
|
|
117
|
-
body: form.getBuffer(),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
getPollingOptions(url, code) {
|
|
121
|
-
const form = new FormData();
|
|
122
|
-
form.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
|
|
123
|
-
form.append('grant_type', DeviceOauthService.GRANT_TYPE);
|
|
124
|
-
form.append('code', code);
|
|
125
|
-
return {
|
|
126
|
-
url,
|
|
127
|
-
headers: { ...org_1.SFDX_HTTP_HEADERS, ...form.getHeaders() },
|
|
128
|
-
method: 'POST',
|
|
129
|
-
body: form.getBuffer(),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
getDeviceFlowRequestUrl() {
|
|
133
|
-
return `${(0, ts_types_1.ensureString)(this.options.loginUrl)}/services/oauth2/token`;
|
|
134
|
-
}
|
|
135
|
-
async poll(httpRequest) {
|
|
136
|
-
this.logger.debug(`polling for device approval (attempt ${this.pollingCount} of ${DeviceOauthService.POLLING_COUNT_MAX})`);
|
|
137
|
-
try {
|
|
138
|
-
return await makeRequest(httpRequest);
|
|
139
|
-
}
|
|
140
|
-
catch (e) {
|
|
141
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions */
|
|
142
|
-
const err = e.data;
|
|
143
|
-
if (err.error && err.status === 400 && err.error === 'authorization_pending') {
|
|
144
|
-
// do nothing because we're still waiting
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
if (err.error && err.error_description) {
|
|
148
|
-
this.logger.error(`Polling error: ${err.error}: ${err.error_description}`);
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
this.logger.error('Unknown Polling Error:');
|
|
152
|
-
this.logger.error(err);
|
|
153
|
-
}
|
|
154
|
-
throw err;
|
|
155
|
-
}
|
|
156
|
-
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions */
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
shouldContinuePolling() {
|
|
160
|
-
return this.pollingCount < DeviceOauthService.POLLING_COUNT_MAX;
|
|
161
|
-
}
|
|
162
|
-
async pollForDeviceApproval(httpRequest, interval) {
|
|
163
|
-
this.logger.debug('BEGIN POLLING FOR DEVICE APPROVAL');
|
|
164
|
-
let result;
|
|
165
|
-
while (this.shouldContinuePolling()) {
|
|
166
|
-
// eslint-disable-next-line no-await-in-loop
|
|
167
|
-
result = await this.poll(httpRequest);
|
|
168
|
-
if (result) {
|
|
169
|
-
this.logger.debug('POLLING FOR DEVICE APPROVAL SUCCESS');
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
this.logger.debug(`waiting ${interval} ms...`);
|
|
174
|
-
// eslint-disable-next-line no-await-in-loop
|
|
175
|
-
await wait(interval);
|
|
176
|
-
this.pollingCount += 1;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (this.pollingCount >= DeviceOauthService.POLLING_COUNT_MAX) {
|
|
180
|
-
// stop polling, the user has likely abandoned the command...
|
|
181
|
-
this.logger.error(`Polling timed out because max polling was hit: ${this.pollingCount}`);
|
|
182
|
-
throw messages.createError('pollingTimeout');
|
|
183
|
-
}
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
exports.DeviceOauthService = DeviceOauthService;
|
|
188
|
-
DeviceOauthService.RESPONSE_TYPE = 'device_code';
|
|
189
|
-
DeviceOauthService.GRANT_TYPE = 'device';
|
|
190
|
-
DeviceOauthService.SCOPE = 'refresh_token web api';
|
|
191
|
-
DeviceOauthService.POLLING_COUNT_MAX = 100;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2020, salesforce.com, inc.
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* Licensed under the BSD 3-Clause license.
|
|
6
|
+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
|
+
*/
|
|
8
|
+
/* eslint-disable camelcase */
|
|
9
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.DeviceOauthService = void 0;
|
|
12
|
+
const transport_1 = require("jsforce/lib/transport");
|
|
13
|
+
const kit_1 = require("@salesforce/kit");
|
|
14
|
+
const ts_types_1 = require("@salesforce/ts-types");
|
|
15
|
+
const FormData = require("form-data");
|
|
16
|
+
const logger_1 = require("./logger");
|
|
17
|
+
const org_1 = require("./org");
|
|
18
|
+
const sfError_1 = require("./sfError");
|
|
19
|
+
const messages_1 = require("./messages");
|
|
20
|
+
messages_1.Messages.importMessagesDirectory(__dirname);
|
|
21
|
+
const messages = messages_1.Messages.load('@salesforce/core', 'auth', ['pollingTimeout']);
|
|
22
|
+
async function wait(ms = 1000) {
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
setTimeout(resolve, ms);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async function makeRequest(options) {
|
|
28
|
+
const rawResponse = await new transport_1.default().httpRequest(options);
|
|
29
|
+
const response = (0, kit_1.parseJsonMap)(rawResponse.body);
|
|
30
|
+
if (response.error) {
|
|
31
|
+
const err = new sfError_1.SfError('Request Failed.');
|
|
32
|
+
err.data = Object.assign(response, { status: rawResponse.statusCode });
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Handles device based login flows
|
|
41
|
+
*
|
|
42
|
+
* Usage:
|
|
43
|
+
* ```
|
|
44
|
+
* const oauthConfig = {
|
|
45
|
+
* loginUrl: this.flags.instanceurl,
|
|
46
|
+
* clientId: this.flags.clientid,
|
|
47
|
+
* };
|
|
48
|
+
* const deviceOauthService = await DeviceOauthService.create(oauthConfig);
|
|
49
|
+
* const loginData = await deviceOauthService.requestDeviceLogin();
|
|
50
|
+
* console.log(loginData);
|
|
51
|
+
* const approval = await deviceOauthService.awaitDeviceApproval(loginData);
|
|
52
|
+
* const authInfo = await deviceOauthService.authorizeAndSave(approval);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
class DeviceOauthService extends kit_1.AsyncCreatable {
|
|
56
|
+
constructor(options) {
|
|
57
|
+
super(options);
|
|
58
|
+
this.pollingCount = 0;
|
|
59
|
+
this.options = options;
|
|
60
|
+
if (!this.options.clientId)
|
|
61
|
+
this.options.clientId = org_1.DEFAULT_CONNECTED_APP_INFO.clientId;
|
|
62
|
+
if (!this.options.loginUrl)
|
|
63
|
+
this.options.loginUrl = org_1.AuthInfo.getDefaultInstanceUrl();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Begin the authorization flow by requesting the login
|
|
67
|
+
*
|
|
68
|
+
* @returns {Promise<DeviceCodeResponse>}
|
|
69
|
+
*/
|
|
70
|
+
async requestDeviceLogin() {
|
|
71
|
+
const deviceFlowRequestUrl = this.getDeviceFlowRequestUrl();
|
|
72
|
+
const loginOptions = this.getLoginOptions(deviceFlowRequestUrl);
|
|
73
|
+
return makeRequest(loginOptions);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Polls the server until successful response OR max attempts have been made
|
|
77
|
+
*
|
|
78
|
+
* @returns {Promise<Nullable<DeviceCodePollingResponse>>}
|
|
79
|
+
*/
|
|
80
|
+
async awaitDeviceApproval(loginData) {
|
|
81
|
+
const deviceFlowRequestUrl = this.getDeviceFlowRequestUrl();
|
|
82
|
+
const pollingOptions = this.getPollingOptions(deviceFlowRequestUrl, loginData.device_code);
|
|
83
|
+
const interval = kit_1.Duration.seconds(loginData.interval).milliseconds;
|
|
84
|
+
return this.pollForDeviceApproval(pollingOptions, interval);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates and saves new AuthInfo
|
|
88
|
+
*
|
|
89
|
+
* @returns {Promise<AuthInfo>}
|
|
90
|
+
*/
|
|
91
|
+
async authorizeAndSave(approval) {
|
|
92
|
+
const authInfo = await org_1.AuthInfo.create({
|
|
93
|
+
oauth2Options: {
|
|
94
|
+
loginUrl: approval.instance_url,
|
|
95
|
+
refreshToken: approval.refresh_token,
|
|
96
|
+
clientSecret: this.options.clientSecret,
|
|
97
|
+
clientId: this.options.clientId,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
await authInfo.save();
|
|
101
|
+
return authInfo;
|
|
102
|
+
}
|
|
103
|
+
async init() {
|
|
104
|
+
this.logger = await logger_1.Logger.child(this.constructor.name);
|
|
105
|
+
this.logger.debug(`this.options.clientId: ${this.options.clientId}`);
|
|
106
|
+
this.logger.debug(`this.options.loginUrl: ${this.options.loginUrl}`);
|
|
107
|
+
}
|
|
108
|
+
getLoginOptions(url) {
|
|
109
|
+
const form = new FormData();
|
|
110
|
+
form.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
|
|
111
|
+
form.append('response_type', DeviceOauthService.RESPONSE_TYPE);
|
|
112
|
+
form.append('scope', DeviceOauthService.SCOPE);
|
|
113
|
+
return {
|
|
114
|
+
url,
|
|
115
|
+
headers: { ...org_1.SFDX_HTTP_HEADERS, ...form.getHeaders() },
|
|
116
|
+
method: 'POST',
|
|
117
|
+
body: form.getBuffer(),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
getPollingOptions(url, code) {
|
|
121
|
+
const form = new FormData();
|
|
122
|
+
form.append('client_id', (0, ts_types_1.ensureString)(this.options.clientId));
|
|
123
|
+
form.append('grant_type', DeviceOauthService.GRANT_TYPE);
|
|
124
|
+
form.append('code', code);
|
|
125
|
+
return {
|
|
126
|
+
url,
|
|
127
|
+
headers: { ...org_1.SFDX_HTTP_HEADERS, ...form.getHeaders() },
|
|
128
|
+
method: 'POST',
|
|
129
|
+
body: form.getBuffer(),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
getDeviceFlowRequestUrl() {
|
|
133
|
+
return `${(0, ts_types_1.ensureString)(this.options.loginUrl)}/services/oauth2/token`;
|
|
134
|
+
}
|
|
135
|
+
async poll(httpRequest) {
|
|
136
|
+
this.logger.debug(`polling for device approval (attempt ${this.pollingCount} of ${DeviceOauthService.POLLING_COUNT_MAX})`);
|
|
137
|
+
try {
|
|
138
|
+
return await makeRequest(httpRequest);
|
|
139
|
+
}
|
|
140
|
+
catch (e) {
|
|
141
|
+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions */
|
|
142
|
+
const err = e.data;
|
|
143
|
+
if (err.error && err.status === 400 && err.error === 'authorization_pending') {
|
|
144
|
+
// do nothing because we're still waiting
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
if (err.error && err.error_description) {
|
|
148
|
+
this.logger.error(`Polling error: ${err.error}: ${err.error_description}`);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
this.logger.error('Unknown Polling Error:');
|
|
152
|
+
this.logger.error(err);
|
|
153
|
+
}
|
|
154
|
+
throw err;
|
|
155
|
+
}
|
|
156
|
+
/* eslint-enable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions */
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
shouldContinuePolling() {
|
|
160
|
+
return this.pollingCount < DeviceOauthService.POLLING_COUNT_MAX;
|
|
161
|
+
}
|
|
162
|
+
async pollForDeviceApproval(httpRequest, interval) {
|
|
163
|
+
this.logger.debug('BEGIN POLLING FOR DEVICE APPROVAL');
|
|
164
|
+
let result;
|
|
165
|
+
while (this.shouldContinuePolling()) {
|
|
166
|
+
// eslint-disable-next-line no-await-in-loop
|
|
167
|
+
result = await this.poll(httpRequest);
|
|
168
|
+
if (result) {
|
|
169
|
+
this.logger.debug('POLLING FOR DEVICE APPROVAL SUCCESS');
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
this.logger.debug(`waiting ${interval} ms...`);
|
|
174
|
+
// eslint-disable-next-line no-await-in-loop
|
|
175
|
+
await wait(interval);
|
|
176
|
+
this.pollingCount += 1;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (this.pollingCount >= DeviceOauthService.POLLING_COUNT_MAX) {
|
|
180
|
+
// stop polling, the user has likely abandoned the command...
|
|
181
|
+
this.logger.error(`Polling timed out because max polling was hit: ${this.pollingCount}`);
|
|
182
|
+
throw messages.createError('pollingTimeout');
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
exports.DeviceOauthService = DeviceOauthService;
|
|
188
|
+
DeviceOauthService.RESPONSE_TYPE = 'device_code';
|
|
189
|
+
DeviceOauthService.GRANT_TYPE = 'device';
|
|
190
|
+
DeviceOauthService.SCOPE = 'refresh_token web api';
|
|
191
|
+
DeviceOauthService.POLLING_COUNT_MAX = 100;
|
|
192
192
|
//# sourceMappingURL=deviceOauthService.js.map
|
package/lib/exported.d.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
export { OAuth2Config } from 'jsforce';
|
|
2
|
-
export { ConfigFile } from './config/configFile';
|
|
3
|
-
export { TTLConfig } from './config/ttlConfig';
|
|
4
|
-
export { envVars, EnvironmentVariable, SUPPORTED_ENV_VARS, EnvVars } from './config/envVars';
|
|
5
|
-
export { ConfigContents, ConfigEntry, ConfigStore, ConfigValue } from './config/configStore';
|
|
6
|
-
export { SfTokens, StateAggregator } from './stateAggregator';
|
|
7
|
-
export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } from './deviceOauthService';
|
|
8
|
-
export { OrgUsersConfig } from './config/orgUsersConfig';
|
|
9
|
-
export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config, SfdxPropertyKeys, SfConfigProperties, SFDX_ALLOWED_PROPERTIES, SF_ALLOWED_PROPERTIES, } from './config/config';
|
|
10
|
-
export { SandboxRequestCacheEntry, SandboxRequestCache } from './config/sandboxProcessCache';
|
|
11
|
-
export { ConfigInfo, ConfigAggregator, SfdxConfigAggregator } from './config/configAggregator';
|
|
12
|
-
export { AuthFields, AuthInfo, AuthSideEffects, OrgAuthorization } from './org/authInfo';
|
|
13
|
-
export { AuthRemover } from './org/authRemover';
|
|
14
|
-
export { Connection, SFDX_HTTP_HEADERS } from './org/connection';
|
|
15
|
-
export { Mode, Global } from './global';
|
|
16
|
-
export { Lifecycle } from './lifecycleEvents';
|
|
17
|
-
export { WebOAuthServer } from './webOAuthServer';
|
|
18
|
-
export { SfdcUrl } from './util/sfdcUrl';
|
|
19
|
-
export { getJwtAudienceUrl } from './util/getJwtAudienceUrl';
|
|
20
|
-
export { Fields, FieldValue, LoggerLevel, LoggerLevelValue, LogLine, LoggerOptions, LoggerStream, Logger, } from './logger';
|
|
21
|
-
export { Messages, StructuredMessage } from './messages';
|
|
22
|
-
export { Org, SandboxProcessObject, StatusEvent, SandboxEvents, SandboxUserAuthResponse, SandboxUserAuthRequest, SandboxRequest, ResumeSandboxRequest, OrgTypes, ResultEvent, ScratchOrgRequest, } from './org';
|
|
23
|
-
export { OrgConfigProperties, ORG_CONFIG_ALLOWED_PROPERTIES } from './org/orgConfigProperties';
|
|
24
|
-
export { PackageDir, NamedPackageDir, PackageDirDependency, SfProject, SfProjectJson, SfdxProject, SfdxProjectJson, } from './sfProject';
|
|
25
|
-
export { SchemaPrinter } from './schema/printer';
|
|
26
|
-
export { SchemaValidator } from './schema/validator';
|
|
27
|
-
export { SfError, SfdxError } from './sfError';
|
|
28
|
-
export { PollingClient } from './status/pollingClient';
|
|
29
|
-
export { CometClient, CometSubscription, StreamingClient, StatusResult } from './status/streamingClient';
|
|
30
|
-
export { MyDomainResolver } from './status/myDomainResolver';
|
|
31
|
-
export { DefaultUserFields, REQUIRED_FIELDS, User, UserFields } from './org/user';
|
|
32
|
-
export { PermissionSetAssignment, PermissionSetAssignmentFields } from './org/permissionSetAssignment';
|
|
33
|
-
export { ScratchOrgCreateOptions, ScratchOrgCreateResult, scratchOrgCreate, scratchOrgResume, } from './org/scratchOrgCreate';
|
|
34
|
-
export { ScratchOrgInfo } from './org/scratchOrgTypes';
|
|
35
|
-
export { ScratchOrgLifecycleEvent, scratchOrgLifecycleEventName, scratchOrgLifecycleStages, } from './org/scratchOrgLifecycleEvents';
|
|
36
|
-
export { ScratchOrgCache } from './org/scratchOrgCache';
|
|
37
|
-
export * from './util/sfdc';
|
|
38
|
-
export * from './util/sfdcUrl';
|
|
1
|
+
export { OAuth2Config } from 'jsforce';
|
|
2
|
+
export { ConfigFile } from './config/configFile';
|
|
3
|
+
export { TTLConfig } from './config/ttlConfig';
|
|
4
|
+
export { envVars, EnvironmentVariable, SUPPORTED_ENV_VARS, EnvVars } from './config/envVars';
|
|
5
|
+
export { ConfigContents, ConfigEntry, ConfigStore, ConfigValue } from './config/configStore';
|
|
6
|
+
export { SfTokens, StateAggregator } from './stateAggregator';
|
|
7
|
+
export { DeviceOauthService, DeviceCodeResponse, DeviceCodePollingResponse } from './deviceOauthService';
|
|
8
|
+
export { OrgUsersConfig } from './config/orgUsersConfig';
|
|
9
|
+
export { ConfigPropertyMeta, ConfigPropertyMetaInput, Config, SfdxPropertyKeys, SfConfigProperties, SFDX_ALLOWED_PROPERTIES, SF_ALLOWED_PROPERTIES, } from './config/config';
|
|
10
|
+
export { SandboxRequestCacheEntry, SandboxRequestCache } from './config/sandboxProcessCache';
|
|
11
|
+
export { ConfigInfo, ConfigAggregator, SfdxConfigAggregator } from './config/configAggregator';
|
|
12
|
+
export { AuthFields, AuthInfo, AuthSideEffects, OrgAuthorization } from './org/authInfo';
|
|
13
|
+
export { AuthRemover } from './org/authRemover';
|
|
14
|
+
export { Connection, SFDX_HTTP_HEADERS } from './org/connection';
|
|
15
|
+
export { Mode, Global } from './global';
|
|
16
|
+
export { Lifecycle } from './lifecycleEvents';
|
|
17
|
+
export { WebOAuthServer } from './webOAuthServer';
|
|
18
|
+
export { SfdcUrl } from './util/sfdcUrl';
|
|
19
|
+
export { getJwtAudienceUrl } from './util/getJwtAudienceUrl';
|
|
20
|
+
export { Fields, FieldValue, LoggerLevel, LoggerLevelValue, LogLine, LoggerOptions, LoggerStream, Logger, } from './logger';
|
|
21
|
+
export { Messages, StructuredMessage } from './messages';
|
|
22
|
+
export { Org, SandboxProcessObject, StatusEvent, SandboxEvents, SandboxUserAuthResponse, SandboxUserAuthRequest, SandboxRequest, ResumeSandboxRequest, OrgTypes, ResultEvent, ScratchOrgRequest, } from './org';
|
|
23
|
+
export { OrgConfigProperties, ORG_CONFIG_ALLOWED_PROPERTIES } from './org/orgConfigProperties';
|
|
24
|
+
export { PackageDir, NamedPackageDir, PackageDirDependency, SfProject, SfProjectJson, SfdxProject, SfdxProjectJson, } from './sfProject';
|
|
25
|
+
export { SchemaPrinter } from './schema/printer';
|
|
26
|
+
export { SchemaValidator } from './schema/validator';
|
|
27
|
+
export { SfError, SfdxError } from './sfError';
|
|
28
|
+
export { PollingClient } from './status/pollingClient';
|
|
29
|
+
export { CometClient, CometSubscription, StreamingClient, StatusResult } from './status/streamingClient';
|
|
30
|
+
export { MyDomainResolver } from './status/myDomainResolver';
|
|
31
|
+
export { DefaultUserFields, REQUIRED_FIELDS, User, UserFields } from './org/user';
|
|
32
|
+
export { PermissionSetAssignment, PermissionSetAssignmentFields } from './org/permissionSetAssignment';
|
|
33
|
+
export { ScratchOrgCreateOptions, ScratchOrgCreateResult, scratchOrgCreate, scratchOrgResume, } from './org/scratchOrgCreate';
|
|
34
|
+
export { ScratchOrgInfo } from './org/scratchOrgTypes';
|
|
35
|
+
export { ScratchOrgLifecycleEvent, scratchOrgLifecycleEventName, scratchOrgLifecycleStages, } from './org/scratchOrgLifecycleEvents';
|
|
36
|
+
export { ScratchOrgCache } from './org/scratchOrgCache';
|
|
37
|
+
export * from './util/sfdc';
|
|
38
|
+
export * from './util/sfdcUrl';
|