@salesforce/core 6.2.2 → 6.2.3-qa.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/lib/org/org.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AsyncOptionalCreatable, Duration } from '@salesforce/kit';
2
- import { AnyJson, JsonMap, Nullable, Optional } from '@salesforce/ts-types';
2
+ import { AnyJson, JsonMap, Nullable } from '@salesforce/ts-types';
3
3
  import { ConfigAggregator } from '../config/configAggregator';
4
4
  import { OrgUsersConfig } from '../config/orgUsersConfig';
5
5
  import { Connection } from './connection';
@@ -208,7 +208,7 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
208
208
  /**
209
209
  * Returns the Org object or null if this org is not affiliated with a Dev Hub (according to the local config).
210
210
  */
211
- getDevHubOrg(): Promise<Optional<Org>>;
211
+ getDevHubOrg(): Promise<Org | undefined>;
212
212
  /**
213
213
  * Returns `true` if the org is a Dev Hub.
214
214
  *
@@ -284,7 +284,7 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
284
284
  * Some organization information is locally cached, such as if the org name or if it is a scratch org.
285
285
  * This method populates/updates the filesystem from information retrieved from the org.
286
286
  */
287
- updateLocalInformation(): Promise<void>;
287
+ 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>;
288
288
  /**
289
289
  * Refreshes the auth for this org's instance by calling HTTP GET on the baseUrl of the connection object.
290
290
  */
@@ -341,7 +341,7 @@ export declare class Org extends AsyncOptionalCreatable<Org.Options> {
341
341
  /**
342
342
  * Returns the admin username used to create the org.
343
343
  */
344
- getUsername(): Optional<string>;
344
+ getUsername(): string | undefined;
345
345
  /**
346
346
  * Returns the orgId for this org.
347
347
  */
@@ -546,7 +546,7 @@ export declare namespace Org {
546
546
  */
547
547
  IS_SCRATCH = "isScratch",
548
548
  /**
549
- * Is the current org a dev hub org. e.g. Organization has IsSandbox == true and TrialExpirationDate == null.
549
+ * Is the current org a sandbox (not a scratch org on a non-prod instance), but an actual Sandbox org). e.g. Organization has IsSandbox == true and TrialExpirationDate == null.
550
550
  */
551
551
  IS_SANDBOX = "isSandbox",
552
552
  /**
package/lib/org/org.js CHANGED
@@ -484,12 +484,12 @@ class Org extends kit_1.AsyncOptionalCreatable {
484
484
  * using {@link Org.retrieveOrganizationInformation}.
485
485
  */
486
486
  async determineIfScratch() {
487
- let cache = this.getField(Org.Fields.IS_SCRATCH);
488
- if (!cache) {
489
- await this.updateLocalInformation();
490
- cache = this.getField(Org.Fields.IS_SCRATCH);
487
+ const cache = this.getField(Org.Fields.IS_SCRATCH);
488
+ if (cache !== undefined) {
489
+ return cache;
491
490
  }
492
- return cache;
491
+ const updated = await this.updateLocalInformation();
492
+ return updated?.isScratch === true;
493
493
  }
494
494
  /**
495
495
  * Returns `true` if the org is a sandbox.
@@ -499,12 +499,12 @@ class Org extends kit_1.AsyncOptionalCreatable {
499
499
  * using {@link Org.retrieveOrganizationInformation}.
500
500
  */
501
501
  async determineIfSandbox() {
502
- let cache = this.getField(Org.Fields.IS_SANDBOX);
503
- if (!cache) {
504
- await this.updateLocalInformation();
505
- cache = this.getField(Org.Fields.IS_SANDBOX);
502
+ const cache = this.getField(Org.Fields.IS_SANDBOX);
503
+ if (cache !== undefined) {
504
+ return cache;
506
505
  }
507
- return cache;
506
+ const updated = await this.updateLocalInformation();
507
+ return updated?.isSandbox === true;
508
508
  }
509
509
  /**
510
510
  * Retrieve a handful of fields from the Organization table in Salesforce. If this does not have the
@@ -522,19 +522,21 @@ class Org extends kit_1.AsyncOptionalCreatable {
522
522
  async updateLocalInformation() {
523
523
  const username = this.getUsername();
524
524
  if (username) {
525
- const organization = await this.retrieveOrganizationInformation();
526
- const isScratch = organization.IsSandbox && Boolean(organization.TrialExpirationDate);
527
- const isSandbox = organization.IsSandbox && !organization.TrialExpirationDate;
528
- const stateAggregator = await stateAggregator_1.StateAggregator.getInstance();
529
- stateAggregator.orgs.update(username, {
525
+ const [stateAggregator, organization] = await Promise.all([
526
+ stateAggregator_1.StateAggregator.getInstance(),
527
+ this.retrieveOrganizationInformation(),
528
+ ]);
529
+ const updateFields = {
530
530
  [Org.Fields.NAME]: organization.Name,
531
531
  [Org.Fields.INSTANCE_NAME]: organization.InstanceName,
532
532
  [Org.Fields.NAMESPACE_PREFIX]: organization.NamespacePrefix,
533
- [Org.Fields.IS_SANDBOX]: isSandbox,
534
- [Org.Fields.IS_SCRATCH]: isScratch,
533
+ [Org.Fields.IS_SANDBOX]: organization.IsSandbox && !organization.TrialExpirationDate,
534
+ [Org.Fields.IS_SCRATCH]: organization.IsSandbox && Boolean(organization.TrialExpirationDate),
535
535
  [Org.Fields.TRIAL_EXPIRATION_DATE]: organization.TrialExpirationDate,
536
- });
536
+ };
537
+ stateAggregator.orgs.update(username, updateFields);
537
538
  await stateAggregator.orgs.write(username);
539
+ return updateFields;
538
540
  }
539
541
  }
540
542
  /**
@@ -546,8 +548,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
546
548
  url: this.getConnection().baseUrl(),
547
549
  method: 'GET',
548
550
  };
549
- const conn = this.getConnection();
550
- await conn.request(requestInfo);
551
+ await this.getConnection().request(requestInfo);
551
552
  }
552
553
  /**
553
554
  * Reads and returns the content of all user auth files for this org as an array.
@@ -557,16 +558,9 @@ class Org extends kit_1.AsyncOptionalCreatable {
557
558
  const contents = await config.read();
558
559
  const thisUsername = (0, ts_types_1.ensure)(this.getUsername());
559
560
  const usernames = (0, ts_types_1.ensureJsonArray)(contents.usernames ?? [thisUsername]);
560
- return Promise.all(usernames.map((username) => {
561
- if (username === thisUsername) {
562
- return authInfo_1.AuthInfo.create({
563
- username: this.getConnection().getUsername(),
564
- });
565
- }
566
- else {
567
- return authInfo_1.AuthInfo.create({ username: (0, ts_types_1.ensureString)(username) });
568
- }
569
- }));
561
+ return Promise.all(usernames.map((username) => authInfo_1.AuthInfo.create({
562
+ username: username === thisUsername ? this.getConnection().getUsername() : (0, ts_types_1.ensureString)(username),
563
+ })));
570
564
  }
571
565
  /**
572
566
  * Adds a username to the user config for this org. For convenience `this` object is returned.
@@ -596,7 +590,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
596
590
  // TODO: This is kind of screwy because contents values can be `AnyJson | object`...
597
591
  // needs config refactoring to improve
598
592
  const usernames = contents.usernames ?? [];
599
- if (!(0, ts_types_1.isArray)(usernames)) {
593
+ if (!Array.isArray(usernames)) {
600
594
  throw new sfError_1.SfError('Usernames is not an array', 'UnexpectedDataFormat');
601
595
  }
602
596
  let shouldUpdate = false;
@@ -698,11 +692,7 @@ class Org extends kit_1.AsyncOptionalCreatable {
698
692
  * Returns a map of requested fields.
699
693
  */
700
694
  getFields(keys) {
701
- const json = {};
702
- return keys.reduce((map, key) => {
703
- map[key] = this.getField(key);
704
- return map;
705
- }, json);
695
+ return Object.fromEntries(keys.map((key) => [key, this.getField(key)]));
706
696
  }
707
697
  /**
708
698
  * Returns the JSForce connection for the org.
@@ -1294,7 +1284,7 @@ exports.Org = Org;
1294
1284
  */
1295
1285
  Fields["IS_SCRATCH"] = "isScratch";
1296
1286
  /**
1297
- * Is the current org a dev hub org. e.g. Organization has IsSandbox == true and TrialExpirationDate == null.
1287
+ * Is the current org a sandbox (not a scratch org on a non-prod instance), but an actual Sandbox org). e.g. Organization has IsSandbox == true and TrialExpirationDate == null.
1298
1288
  */
1299
1289
  Fields["IS_SANDBOX"] = "isSandbox";
1300
1290
  /**
@@ -181,7 +181,11 @@ const authorizeScratchOrg = async (options) => {
181
181
  clientId: scratchOrgInfoComplete.ConnectedAppConsumerKey,
182
182
  createdOrgInstance: scratchOrgInfoComplete.SignupInstance,
183
183
  isDevHub: false,
184
- snapshot: scratchOrgInfoComplete.Snapshot,
184
+ isScratch: true,
185
+ isSandbox: false,
186
+ // omit optional fields unless they are present
187
+ ...(scratchOrgInfoComplete.Namespace ? { namespacePrefix: scratchOrgInfoComplete.Namespace } : {}),
188
+ ...(scratchOrgInfoComplete.Snapshot ? { snapshot: scratchOrgInfoComplete.Snapshot } : {}),
185
189
  });
186
190
  return authInfo;
187
191
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "6.2.2",
3
+ "version": "6.2.3-qa.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",