@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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2024, Salesforce.com, Inc.
1
+ Copyright (c) 2025, Salesforce.com, Inc.
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -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 decryptedFields = this.getFields(true);
520
- const instanceUrl = (0, ts_types_1.ensure)(decryptedFields.instanceUrl, 'undefined instanceUrl').replace(/^https?:\/\//, '');
521
- let sfdxAuthUrl = 'force://';
522
- if (decryptedFields.clientId) {
523
- sfdxAuthUrl += `${decryptedFields.clientId}:${decryptedFields.clientSecret ?? ''}:`;
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(conn, callback) {
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
- return await callback(null, fields.accessToken);
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;
@@ -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 get request on the baseUrl to force an auth refresh
152
- * Useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes
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;
@@ -334,14 +334,18 @@ class Connection extends jsforce_node_1.Connection {
334
334
  return result.records[0];
335
335
  }
336
336
  /**
337
- * Executes a get request on the baseUrl to force an auth refresh
338
- * Useful for the raw methods (request, requestRaw) that use the accessToken directly and don't handle refreshes
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: 'GET',
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
- * Refreshes the auth for this org's instance by calling HTTP GET on the baseUrl of the connection object.
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
- * Refreshes the auth for this org's instance by calling HTTP GET on the baseUrl of the connection object.
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: 'GET',
636
+ method: 'HEAD',
632
637
  };
633
638
  await this.getConnection().request(requestInfo);
634
639
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "8.7.0",
3
+ "version": "8.8.1",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index.d.ts",