@salesforce/core 8.7.0 → 8.8.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/LICENSE.txt +1 -1
- package/lib/org/authInfo.js +14 -11
- package/lib/org/connection.d.ts +6 -2
- package/lib/org/connection.js +7 -3
- package/lib/org/org.d.ts +6 -1
- package/lib/org/org.js +7 -2
- package/package.json +1 -1
package/LICENSE.txt
CHANGED
package/lib/org/authInfo.js
CHANGED
|
@@ -239,7 +239,7 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
239
239
|
* @param sfdxAuthUrl
|
|
240
240
|
*/
|
|
241
241
|
static parseSfdxAuthUrl(sfdxAuthUrl) {
|
|
242
|
-
const match = sfdxAuthUrl.match(/^force:\/\/([a-zA-Z0-9._-]+={0,2}):([a-zA-Z0-9._-]*={0,2}):([a-zA-Z0-9._-]+={0,2})@([a-zA-Z0-9
|
|
242
|
+
const match = sfdxAuthUrl.match(/^force:\/\/([a-zA-Z0-9._-]+={0,2}):([a-zA-Z0-9._-]*={0,2}):([a-zA-Z0-9._-]+={0,2})@([a-zA-Z0-9:._-]+)/);
|
|
243
243
|
if (!match) {
|
|
244
244
|
throw new sfError_1.SfError(messages.getMessage('invalidSfdxAuthUrlError'), 'INVALID_SFDX_AUTH_URL');
|
|
245
245
|
}
|
|
@@ -516,14 +516,12 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
516
516
|
* **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)
|
|
517
517
|
*/
|
|
518
518
|
getSfdxAuthUrl() {
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
}
|
|
525
|
-
sfdxAuthUrl += `${(0, ts_types_1.ensure)(decryptedFields.refreshToken, 'undefined refreshToken')}@${instanceUrl}`;
|
|
526
|
-
return sfdxAuthUrl;
|
|
519
|
+
const { clientId, clientSecret, refreshToken, instanceUrl } = this.getFields(true);
|
|
520
|
+
// host includes an optional port on the instanceUrl
|
|
521
|
+
const url = new URL((0, ts_types_1.ensure)(instanceUrl, 'undefined instanceUrl')).host;
|
|
522
|
+
const clientIdAndSecret = clientId ? `${clientId}:${clientSecret ?? ''}` : '';
|
|
523
|
+
const token = (0, ts_types_1.ensure)(refreshToken, 'undefined refreshToken');
|
|
524
|
+
return `force://${clientIdAndSecret}:${token}@${url}`;
|
|
527
525
|
}
|
|
528
526
|
/**
|
|
529
527
|
* Convenience function to handle typical side effects encountered when dealing with an AuthInfo.
|
|
@@ -732,13 +730,18 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
|
|
|
732
730
|
}
|
|
733
731
|
// A callback function for a connection to refresh an access token. This is used
|
|
734
732
|
// both for a JWT connection and an OAuth connection.
|
|
735
|
-
async refreshFn(
|
|
733
|
+
async refreshFn(_conn, callback) {
|
|
736
734
|
this.logger.info('Access token has expired. Updating...');
|
|
737
735
|
try {
|
|
738
736
|
const fields = this.getFields(true);
|
|
737
|
+
// This method will request the new access token and save to the current AuthInfo instance (but don't persist them!).
|
|
739
738
|
await this.initAuthOptions(fields);
|
|
739
|
+
// Persist fields with refreshed access token to auth file.
|
|
740
740
|
await this.save();
|
|
741
|
-
|
|
741
|
+
// Pass new access token to the jsforce's session-refresh callback for proper propagation:
|
|
742
|
+
// https://jsforce.github.io/jsforce/types/session_refresh_delegate.SessionRefreshFunc.html
|
|
743
|
+
const { accessToken } = this.getFields(true);
|
|
744
|
+
return await callback(null, accessToken);
|
|
742
745
|
}
|
|
743
746
|
catch (err) {
|
|
744
747
|
const error = err;
|
package/lib/org/connection.d.ts
CHANGED
|
@@ -148,8 +148,12 @@ export declare class Connection<S extends Schema = Schema> extends JSForceConnec
|
|
|
148
148
|
*/
|
|
149
149
|
singleRecordQuery<T extends Record>(soql: string, options?: SingleRecordQueryOptions): Promise<T>;
|
|
150
150
|
/**
|
|
151
|
-
* Executes a
|
|
152
|
-
*
|
|
151
|
+
* Executes a HEAD request on the baseUrl to force an auth refresh.
|
|
152
|
+
* This is useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes.
|
|
153
|
+
*
|
|
154
|
+
* This method issues a request using the current access token to check if it is still valid.
|
|
155
|
+
* If the request returns 200, no refresh happens, and we keep the token.
|
|
156
|
+
* If it returns 401, jsforce will request a new token and set it in the connection instance.
|
|
153
157
|
*/
|
|
154
158
|
refreshAuth(): Promise<void>;
|
|
155
159
|
private getCachedApiVersion;
|
package/lib/org/connection.js
CHANGED
|
@@ -334,14 +334,18 @@ class Connection extends jsforce_node_1.Connection {
|
|
|
334
334
|
return result.records[0];
|
|
335
335
|
}
|
|
336
336
|
/**
|
|
337
|
-
* Executes a
|
|
338
|
-
*
|
|
337
|
+
* Executes a HEAD request on the baseUrl to force an auth refresh.
|
|
338
|
+
* This is useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes.
|
|
339
|
+
*
|
|
340
|
+
* This method issues a request using the current access token to check if it is still valid.
|
|
341
|
+
* If the request returns 200, no refresh happens, and we keep the token.
|
|
342
|
+
* If it returns 401, jsforce will request a new token and set it in the connection instance.
|
|
339
343
|
*/
|
|
340
344
|
async refreshAuth() {
|
|
341
345
|
this.logger.debug('Refreshing auth for org.');
|
|
342
346
|
const requestInfo = {
|
|
343
347
|
url: this.baseUrl(),
|
|
344
|
-
method: '
|
|
348
|
+
method: 'HEAD',
|
|
345
349
|
};
|
|
346
350
|
await this.request(requestInfo);
|
|
347
351
|
}
|
package/lib/org/org.d.ts
CHANGED
|
@@ -319,7 +319,12 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
|
|
|
319
319
|
*/
|
|
320
320
|
updateLocalInformation(): Promise<Pick<AuthFields, Org.Fields.NAME | Org.Fields.INSTANCE_NAME | Org.Fields.NAMESPACE_PREFIX | Org.Fields.IS_SANDBOX | Org.Fields.IS_SCRATCH | Org.Fields.TRIAL_EXPIRATION_DATE> | undefined>;
|
|
321
321
|
/**
|
|
322
|
-
*
|
|
322
|
+
* Executes a HEAD request on the baseUrl to force an auth refresh.
|
|
323
|
+
* This is useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes.
|
|
324
|
+
*
|
|
325
|
+
* This method issues a request using the current access token to check if it is still valid.
|
|
326
|
+
* If the request returns 200, no refresh happens, and we keep the token.
|
|
327
|
+
* If it returns 401, jsforce will request a new token and set it in the connection instance.
|
|
323
328
|
*/
|
|
324
329
|
refreshAuth(): Promise<void>;
|
|
325
330
|
/**
|
package/lib/org/org.js
CHANGED
|
@@ -622,13 +622,18 @@ class Org extends kit_1.AsyncOptionalCreatable {
|
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
624
|
/**
|
|
625
|
-
*
|
|
625
|
+
* Executes a HEAD request on the baseUrl to force an auth refresh.
|
|
626
|
+
* This is useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes.
|
|
627
|
+
*
|
|
628
|
+
* This method issues a request using the current access token to check if it is still valid.
|
|
629
|
+
* If the request returns 200, no refresh happens, and we keep the token.
|
|
630
|
+
* If it returns 401, jsforce will request a new token and set it in the connection instance.
|
|
626
631
|
*/
|
|
627
632
|
async refreshAuth() {
|
|
628
633
|
this.logger.debug('Refreshing auth for org.');
|
|
629
634
|
const requestInfo = {
|
|
630
635
|
url: this.getConnection().baseUrl(),
|
|
631
|
-
method: '
|
|
636
|
+
method: 'HEAD',
|
|
632
637
|
};
|
|
633
638
|
await this.getConnection().request(requestInfo);
|
|
634
639
|
}
|