From 985c2f6b8fa90ee5302ecb84a07df8c4e2f214a4 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 22 Nov 2023 11:17:17 -0600 Subject: [PATCH 01/12] fix: jsdoc error --- src/org/org.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/org.ts b/src/org/org.ts index 4910bc1095..bd55f40b90 100644 --- a/src/org/org.ts +++ b/src/org/org.ts @@ -1564,7 +1564,7 @@ export namespace Org { */ IS_SCRATCH = 'isScratch', /** - * Is the current org a dev hub org. e.g. Organization has IsSandbox == true and TrialExpirationDate == null. + * 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. */ IS_SANDBOX = 'isSandbox', /** From 447b070d02badbe488f20c961b8db79ac6e9aef9 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 22 Nov 2023 11:17:37 -0600 Subject: [PATCH 02/12] feat: set some known props during scratch org creation --- src/org/scratchOrgInfoApi.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/org/scratchOrgInfoApi.ts b/src/org/scratchOrgInfoApi.ts index c8fdfe893c..57b46d7855 100644 --- a/src/org/scratchOrgInfoApi.ts +++ b/src/org/scratchOrgInfoApi.ts @@ -232,7 +232,11 @@ export const authorizeScratchOrg = async (options: { clientId: scratchOrgInfoComplete.ConnectedAppConsumerKey, createdOrgInstance: scratchOrgInfoComplete.SignupInstance, isDevHub: false, - snapshot: scratchOrgInfoComplete.Snapshot, + isScratch: true, + isSandbox: false, + // omit optional fields unless they are present + ...(scratchOrgInfoComplete.Namespace ? { namespacePrefix: scratchOrgInfoComplete.Namespace } : {}), + ...(scratchOrgInfoComplete.Snapshot ? { snapshot: scratchOrgInfoComplete.Snapshot } : {}), }); return authInfo; From c0f3845de26400381ee953782444abfdbaa530b9 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 27 Nov 2023 07:53:16 -0600 Subject: [PATCH 03/12] fix: only hit server for undefined values, not false --- src/org/org.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/org/org.ts b/src/org/org.ts index bd55f40b90..76ccde0de0 100644 --- a/src/org/org.ts +++ b/src/org/org.ts @@ -630,7 +630,7 @@ export class Org extends AsyncOptionalCreatable { public async determineIfScratch(): Promise { let cache = this.getField(Org.Fields.IS_SCRATCH); - if (!cache) { + if (cache === undefined) { await this.updateLocalInformation(); cache = this.getField(Org.Fields.IS_SCRATCH); } @@ -647,7 +647,7 @@ export class Org extends AsyncOptionalCreatable { public async determineIfSandbox(): Promise { let cache = this.getField(Org.Fields.IS_SANDBOX); - if (!cache) { + if (cache === undefined) { await this.updateLocalInformation(); cache = this.getField(Org.Fields.IS_SANDBOX); } @@ -877,11 +877,7 @@ export class Org extends AsyncOptionalCreatable { * Returns a map of requested fields. */ public getFields(keys: Org.Fields[]): JsonMap { - const json: JsonMap = {}; - return keys.reduce((map, key) => { - map[key] = this.getField(key); - return map; - }, json); + return Object.fromEntries(keys.map((key) => [key, this.getField(key)])); } /** From f5c6116a4c7f7b19ecac404df52738743bb05e6a Mon Sep 17 00:00:00 2001 From: svc-cli-bot Date: Mon, 27 Nov 2023 15:55:08 +0000 Subject: [PATCH 04/12] chore(release): 6.2.2-qa.0 [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 02d44d2dc7..4df452e1e6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/core", - "version": "6.2.1", + "version": "6.2.2-qa.0", "description": "Core libraries to interact with SFDX projects, orgs, and APIs.", "main": "lib/exported", "types": "lib/exported.d.ts", From b311cb1a9340e9494c8deff127900d04f921aab8 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 27 Nov 2023 17:07:06 -0600 Subject: [PATCH 05/12] feat: return a value, use that instead of mutating state --- src/org/org.ts | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/org/org.ts b/src/org/org.ts index 76ccde0de0..73cd860b28 100644 --- a/src/org/org.ts +++ b/src/org/org.ts @@ -628,13 +628,12 @@ export class Org extends AsyncOptionalCreatable { * using {@link Org.retrieveOrganizationInformation}. */ public async determineIfScratch(): Promise { - let cache = this.getField(Org.Fields.IS_SCRATCH); - - if (cache === undefined) { - await this.updateLocalInformation(); - cache = this.getField(Org.Fields.IS_SCRATCH); + const cache = this.getField(Org.Fields.IS_SCRATCH); + if (cache !== undefined) { + return cache; } - return cache as boolean; + const updated = await this.updateLocalInformation(); + return updated?.isScratch === true; } /** @@ -645,13 +644,12 @@ export class Org extends AsyncOptionalCreatable { * using {@link Org.retrieveOrganizationInformation}. */ public async determineIfSandbox(): Promise { - let cache = this.getField(Org.Fields.IS_SANDBOX); - - if (cache === undefined) { - await this.updateLocalInformation(); - cache = this.getField(Org.Fields.IS_SANDBOX); + const cache = this.getField(Org.Fields.IS_SANDBOX); + if (cache !== undefined) { + return cache; } - return cache as boolean; + const updated = await this.updateLocalInformation(); + return updated?.isSandbox === true; } /** @@ -670,22 +668,32 @@ export class Org extends AsyncOptionalCreatable { * Some organization information is locally cached, such as if the org name or if it is a scratch org. * This method populates/updates the filesystem from information retrieved from the org. */ - public async updateLocalInformation(): Promise { + public async updateLocalInformation(): Promise< + | { + name: string; + instanceName: string; + namespacePrefix: string | null; + isSandbox: boolean; + isScratch: boolean; + trailExpirationDate: string | null; + } + | undefined + > { const username = this.getUsername(); if (username) { const organization = await this.retrieveOrganizationInformation(); - const isScratch = organization.IsSandbox && Boolean(organization.TrialExpirationDate); - const isSandbox = organization.IsSandbox && !organization.TrialExpirationDate; - const stateAggregator = await StateAggregator.getInstance(); - stateAggregator.orgs.update(username, { + const updateFields = { [Org.Fields.NAME]: organization.Name, [Org.Fields.INSTANCE_NAME]: organization.InstanceName, [Org.Fields.NAMESPACE_PREFIX]: organization.NamespacePrefix, - [Org.Fields.IS_SANDBOX]: isSandbox, - [Org.Fields.IS_SCRATCH]: isScratch, + [Org.Fields.IS_SANDBOX]: organization.IsSandbox && Boolean(organization.TrialExpirationDate), + [Org.Fields.IS_SCRATCH]: organization.IsSandbox && !organization.TrialExpirationDate, [Org.Fields.TRIAL_EXPIRATION_DATE]: organization.TrialExpirationDate, - }); + }; + const stateAggregator = await StateAggregator.getInstance(); + stateAggregator.orgs.update(username, updateFields); await stateAggregator.orgs.write(username); + return updateFields; } } From 8903d468ca7e450164b99f0a7ea3f2e83d70aae3 Mon Sep 17 00:00:00 2001 From: svc-cli-bot Date: Mon, 4 Dec 2023 14:53:49 +0000 Subject: [PATCH 06/12] chore(release): 6.2.3-qa.0 [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ce13921cdc..05e38cb4c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/core", - "version": "6.2.2", + "version": "6.2.3-qa.0", "description": "Core libraries to interact with SFDX projects, orgs, and APIs.", "main": "lib/exported", "types": "lib/exported.d.ts", From 98762d510ad9fab37ede32a0670bf85a9fe9ab8f Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 4 Dec 2023 09:53:37 -0600 Subject: [PATCH 07/12] fix: backward logic on scratch/sbox --- src/org/org.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/org.ts b/src/org/org.ts index 73cd860b28..8313a90e89 100644 --- a/src/org/org.ts +++ b/src/org/org.ts @@ -686,8 +686,8 @@ export class Org extends AsyncOptionalCreatable { [Org.Fields.NAME]: organization.Name, [Org.Fields.INSTANCE_NAME]: organization.InstanceName, [Org.Fields.NAMESPACE_PREFIX]: organization.NamespacePrefix, - [Org.Fields.IS_SANDBOX]: organization.IsSandbox && Boolean(organization.TrialExpirationDate), - [Org.Fields.IS_SCRATCH]: organization.IsSandbox && !organization.TrialExpirationDate, + [Org.Fields.IS_SANDBOX]: organization.IsSandbox && !organization.TrialExpirationDate, + [Org.Fields.IS_SCRATCH]: organization.IsSandbox && Boolean(organization.TrialExpirationDate), [Org.Fields.TRIAL_EXPIRATION_DATE]: organization.TrialExpirationDate, }; const stateAggregator = await StateAggregator.getInstance(); From c01124a4b10e76ea86cadd64c3ecca5cce6ec4d1 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 4 Dec 2023 10:00:49 -0600 Subject: [PATCH 08/12] refactor: pick from existing type --- src/org/org.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/org/org.ts b/src/org/org.ts index 8313a90e89..3c69a14167 100644 --- a/src/org/org.ts +++ b/src/org/org.ts @@ -669,14 +669,15 @@ export class Org extends AsyncOptionalCreatable { * This method populates/updates the filesystem from information retrieved from the org. */ public async updateLocalInformation(): Promise< - | { - name: string; - instanceName: string; - namespacePrefix: string | null; - isSandbox: boolean; - isScratch: boolean; - trailExpirationDate: string | null; - } + | 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 > { const username = this.getUsername(); From 0c85ce6a7e7327a6212067e257c3ea1a08acf8fc Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 4 Dec 2023 10:06:26 -0600 Subject: [PATCH 09/12] refactor: fewer curlies --- src/org/org.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/org/org.ts b/src/org/org.ts index 3c69a14167..7d7fc3996b 100644 --- a/src/org/org.ts +++ b/src/org/org.ts @@ -721,15 +721,11 @@ export class Org extends AsyncOptionalCreatable { const thisUsername = ensure(this.getUsername()); const usernames: JsonArray = ensureJsonArray(contents.usernames ?? [thisUsername]); return Promise.all( - usernames.map((username) => { - if (username === thisUsername) { - return AuthInfo.create({ - username: this.getConnection().getUsername(), - }); - } else { - return AuthInfo.create({ username: ensureString(username) }); - } - }) + usernames.map((username) => + AuthInfo.create({ + username: username === thisUsername ? this.getConnection().getUsername() : ensureString(username), + }) + ) ); } From 1830bce7da9d1624b8dfc215ad8f8d600ddff5d6 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 4 Dec 2023 10:13:56 -0600 Subject: [PATCH 10/12] refactor: parallel awaits, remove optional --- src/org/org.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/org/org.ts b/src/org/org.ts index 7d7fc3996b..78fa75a00c 100644 --- a/src/org/org.ts +++ b/src/org/org.ts @@ -15,13 +15,11 @@ import { ensure, ensureJsonArray, ensureString, - isArray, isBoolean, isString, JsonArray, JsonMap, Nullable, - Optional, } from '@salesforce/ts-types'; import { HttpRequest, SaveResult } from 'jsforce'; import { Config } from '../config/config'; @@ -458,7 +456,7 @@ export class Org extends AsyncOptionalCreatable { /** * Returns the Org object or null if this org is not affiliated with a Dev Hub (according to the local config). */ - public async getDevHubOrg(): Promise> { + public async getDevHubOrg(): Promise { if (this.isDevHubOrg()) { return this; } else if (this.getField(Org.Fields.DEV_HUB_USERNAME)) { @@ -682,7 +680,10 @@ export class Org extends AsyncOptionalCreatable { > { const username = this.getUsername(); if (username) { - const organization = await this.retrieveOrganizationInformation(); + const [stateAggregator, organization] = await Promise.all([ + StateAggregator.getInstance(), + this.retrieveOrganizationInformation(), + ]); const updateFields = { [Org.Fields.NAME]: organization.Name, [Org.Fields.INSTANCE_NAME]: organization.InstanceName, @@ -691,7 +692,6 @@ export class Org extends AsyncOptionalCreatable { [Org.Fields.IS_SCRATCH]: organization.IsSandbox && Boolean(organization.TrialExpirationDate), [Org.Fields.TRIAL_EXPIRATION_DATE]: organization.TrialExpirationDate, }; - const stateAggregator = await StateAggregator.getInstance(); stateAggregator.orgs.update(username, updateFields); await stateAggregator.orgs.write(username); return updateFields; @@ -708,8 +708,7 @@ export class Org extends AsyncOptionalCreatable { method: 'GET', }; - const conn = this.getConnection(); - await conn.request(requestInfo); + await this.getConnection().request(requestInfo); } /** @@ -761,7 +760,7 @@ export class Org extends AsyncOptionalCreatable { // needs config refactoring to improve const usernames = contents.usernames ?? []; - if (!isArray(usernames)) { + if (!Array.isArray(usernames)) { throw new SfError('Usernames is not an array', 'UnexpectedDataFormat'); } @@ -847,7 +846,7 @@ export class Org extends AsyncOptionalCreatable { /** * Returns the admin username used to create the org. */ - public getUsername(): Optional { + public getUsername(): string | undefined { return this.getConnection().getUsername(); } From d294a11fb2ec05b31533032ed1e78f663062f993 Mon Sep 17 00:00:00 2001 From: svc-cli-bot Date: Mon, 4 Dec 2023 16:26:09 +0000 Subject: [PATCH 11/12] chore(release): 6.2.3-qa.1 [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 05e38cb4c4..18a3f0a717 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/core", - "version": "6.2.3-qa.0", + "version": "6.2.3-qa.1", "description": "Core libraries to interact with SFDX projects, orgs, and APIs.", "main": "lib/exported", "types": "lib/exported.d.ts", From 1a2e34068cc02a2412d15f5a159ea94e3a51b995 Mon Sep 17 00:00:00 2001 From: Steve Hetzel Date: Tue, 5 Dec 2023 11:12:17 -0700 Subject: [PATCH 12/12] chore: reset version for ci tests --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 18a3f0a717..ce13921cdc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/core", - "version": "6.2.3-qa.1", + "version": "6.2.2", "description": "Core libraries to interact with SFDX projects, orgs, and APIs.", "main": "lib/exported", "types": "lib/exported.d.ts",