@salesforce/core 5.1.6 → 5.2.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.
@@ -320,6 +320,7 @@ export declare class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
320
320
  * @private
321
321
  */
322
322
  private throwUserGetException;
323
+ private getNamespacePrefix;
323
324
  /**
324
325
  * Returns `true` if the org is a Dev Hub.
325
326
  *
@@ -662,6 +662,10 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
662
662
  }
663
663
  }
664
664
  authConfig.isDevHub = await this.determineIfDevHub((0, ts_types_1.ensureString)(authConfig.instanceUrl), (0, ts_types_1.ensureString)(authConfig.accessToken));
665
+ const namespacePrefix = await this.getNamespacePrefix((0, ts_types_1.ensureString)(authConfig.instanceUrl), (0, ts_types_1.ensureString)(authConfig.accessToken));
666
+ if (namespacePrefix) {
667
+ authConfig.namespacePrefix = namespacePrefix;
668
+ }
665
669
  if (authConfig.username)
666
670
  await this.stateAggregator.orgs.read(authConfig.username, false, false);
667
671
  // Update the auth fields WITH encryption
@@ -918,6 +922,28 @@ class AuthInfo extends kit_1.AsyncOptionalCreatable {
918
922
  }
919
923
  throw new sfError_1.SfError(errorMsg);
920
924
  }
925
+ async getNamespacePrefix(instanceUrl, accessToken) {
926
+ // Make a REST call for the Organization obj directly. Normally this is done via a connection
927
+ // but we don't want to create circular dependencies or lots of snowflakes
928
+ // within this file to support it.
929
+ const apiVersion = 'v51.0'; // hardcoding to v51.0 just for this call is okay.
930
+ const instance = (0, ts_types_1.ensure)(instanceUrl);
931
+ const baseUrl = new sfdcUrl_1.SfdcUrl(instance);
932
+ const namespacePrefixOrgUrl = `${baseUrl.toString()}/services/data/${apiVersion}/query?q=Select%20Namespaceprefix%20FROM%20Organization`;
933
+ const headers = Object.assign({ Authorization: `Bearer ${accessToken}` }, connection_1.SFDX_HTTP_HEADERS);
934
+ try {
935
+ const res = await new transport_1.default().httpRequest({ url: namespacePrefixOrgUrl, method: 'GET', headers });
936
+ if (res.statusCode >= 400) {
937
+ return;
938
+ }
939
+ const namespacePrefix = JSON.parse(res.body);
940
+ return (0, ts_types_1.ensureString)(namespacePrefix.records[0]?.NamespacePrefix);
941
+ }
942
+ catch (err) {
943
+ /* Doesn't have a namespace */
944
+ return;
945
+ }
946
+ }
921
947
  /**
922
948
  * Returns `true` if the org is a Dev Hub.
923
949
  *
@@ -474,6 +474,7 @@ export declare class MockTestOrgData {
474
474
  isScratchOrg?: boolean;
475
475
  isExpired?: boolean | 'unknown';
476
476
  password?: string;
477
+ namespacePrefix?: string;
477
478
  constructor(id?: string, options?: {
478
479
  username: string;
479
480
  });
package/lib/testSetup.js CHANGED
@@ -733,6 +733,7 @@ class MockTestOrgData {
733
733
  this.accessToken = `${this.testId}/accessToken`;
734
734
  this.refreshToken = `${this.testId}/refreshToken`;
735
735
  this.redirectUri = 'http://localhost:1717/OauthRedirect';
736
+ this.namespacePrefix = `acme_${this.testId}`;
736
737
  }
737
738
  /**
738
739
  * Add devhub username to properties.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "5.1.6",
3
+ "version": "5.2.0",
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",