Skip to content

Commit

Permalink
fix: correct apiVersion and sourceApiVersion values before transfer a…
Browse files Browse the repository at this point in the history
…nd send events (#791)

* fix: correct apiVersion and sourceApiVersion values before transfer and send events

* test: record perf

* fix: add unit tests and make options take precendence over Connection

* chore: auto-update metadata coverage in METADATA_SUPPORT.md

* test: record perf

* fix: use specific directory for ComponentSetBuilder

* test: record perf

Co-authored-by: svc-cli-bot <[email protected]>
  • Loading branch information
shetzel and svc-cli-bot authored Dec 9, 2022
1 parent 464b8bb commit 2e865e9
Show file tree
Hide file tree
Showing 15 changed files with 457 additions and 78 deletions.
61 changes: 30 additions & 31 deletions METADATA_SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Supported CLI Metadata Types

This list compares metadata types found in Salesforce v56 with the [metadata registry file](./src/registry/metadataRegistry.json) included in this repository.
This list compares metadata types found in Salesforce v57 with the [metadata registry file](./src/registry/metadataRegistry.json) included in this repository.

This repository is used by both the Salesforce CLIs and Salesforce's VSCode Extensions.

Currently, there are 482/511 supported metadata types.
Currently, there are 495/534 supported metadata types.
For status on any existing gaps, please search or file an issue in the [Salesforce CLI issues only repo](https://github.com/forcedotcom/cli/issues).
To contribute a new metadata type, please see the [Contributing Metadata Types to the Registry](./contributing/metadata.md)

Expand All @@ -23,8 +23,10 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|AccountingModelConfig||Not supported, but support could be added|
|AccountingSettings|||
|AcctMgrTargetSettings|||
|ActionLauncherItemDef||Not supported, but support could be added|
|ActionLinkGroupTemplate|||
|ActionPlanTemplate|||
|ActionableListDefinition||Not supported, but support could be added|
|ActionsSettings|||
|ActivationPlatform|||
|ActivitiesSettings|||
Expand All @@ -44,6 +46,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|ApexTrigger|||
|AppAnalyticsSettings|||
|AppExperienceSettings|||
|AppExplorationDataConsent||Not supported, but support could be added|
|AppMenu|||
|ApplicationRecordTypeConfig|||
|ApplicationSubtypeDefinition|||
Expand Down Expand Up @@ -106,6 +109,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|ChatterEmailsMDSettings|||
|ChatterExtension|||
|ChatterSettings|||
|ClauseCatgConfiguration|||
|CleanDataService|||
|CollectionsDashboardSettings|||
|CommandAction|||
Expand Down Expand Up @@ -169,9 +173,12 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|DelegateGroup|||
|DeploymentSettings|||
|DevHubSettings|||
|DigitalExperience|⚠️|Supports deploy/retrieve but not source tracking|
|DigitalExperienceBundle|⚠️|Supports deploy/retrieve but not source tracking|
|DigitalExperienceConfig|⚠️|Supports deploy/retrieve but not source tracking|
|DigitalExperience|||
|DigitalExperienceBundle|||
|DigitalExperienceConfig|||
|DisclosureDefinition|||
|DisclosureDefinitionVersion|||
|DisclosureType|||
|DiscoveryAIModel|||
|DiscoveryGoal|||
|DiscoverySettings|||
Expand Down Expand Up @@ -222,13 +229,19 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|ExpressionSetDefinitionVersion|||
|ExpressionSetObjectAlias||Not supported, but support could be added|
|ExternalAIModel||Not supported, but support could be added|
|ExternalClientAppSettings|||
|ExternalClientApplication|||
|ExternalCredential|||
|ExternalDataConnector|||
|ExternalDataSource|||
|ExternalDataSrcDescriptor||Not supported, but support could be added|
|ExternalDataTranField||Not supported, but support could be added|
|ExternalDataTranObject||Not supported, but support could be added|
|ExternalServiceRegistration|||
|ExtlClntAppMobileConfigurablePolicies|||
|ExtlClntAppMobileSettings|||
|ExtlClntAppOauthConfigurablePolicies|||
|ExtlClntAppOauthSettings|||
|FeatureParameterBoolean|||
|FeatureParameterDate|||
|FeatureParameterInteger|||
Expand Down Expand Up @@ -267,6 +280,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|IPAddressRange|||
|Icon|||
|IdeasSettings|||
|IdentityProviderSettings|||
|IdentityVerificationProcDef|||
|IframeWhiteListUrlSettings|||
|InboundCertificate|||
Expand All @@ -279,6 +293,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|IndustriesManufacturingSettings|||
|IndustriesSettings|||
|InstalledPackage|⚠️|Supports deploy/retrieve but not source tracking|
|IntegrationProviderDef||Not supported, but support could be added|
|InterestTaggingSettings|||
|InternalDataConnector|||
|InvLatePymntRiskCalcSettings|||
Expand All @@ -305,6 +320,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|LiveChatDeployment|||
|LiveChatSensitiveDataRule|||
|LiveMessageSettings|||
|LocationUse||Not supported, but support could be added|
|LoyaltyProgramSetup|⚠️|Supports deploy/retrieve but not source tracking|
|MLDataDefinition|||
|MLPredictionDefinition|||
Expand Down Expand Up @@ -356,6 +372,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|OmniInteractionAccessConfig|⚠️|Supports deploy/retrieve but not source tracking|
|OmniInteractionConfig|⚠️|Supports deploy/retrieve but not source tracking|
|OmniScript|⚠️|Supports deploy/retrieve but not source tracking|
|OmniSupervisorConfig|||
|OmniUiCard|⚠️|Supports deploy/retrieve but not source tracking|
|OnlineSalesSettings|||
|OpportunityInsightsSettings|||
Expand All @@ -372,13 +389,16 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|PathAssistant|||
|PathAssistantSettings|||
|PaymentGatewayProvider|||
|PaymentsIngestEnabledSettings|||
|PaymentsManagementEnabledSettings|||
|PaymentsSettings|||
|PermissionSet|||
|PermissionSetGroup|||
|PermissionSetLicenseDefinition|||
|PersonAccountOwnerPowerUser||Not supported, but support could be added|
|PicklistSettings|||
|PicklistValue||Not supported, but support could be added|
|PipelineInspMetricConfig||Not supported, but support could be added|
|PlatformCachePartition|||
|PlatformEventChannel|||
|PlatformEventChannelMember|||
Expand All @@ -393,6 +413,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|PrivacySettings|||
|ProductAttributeSet|||
|ProductSettings|||
|ProductSpecificationTypeDefinition||Not supported, but support could be added|
|Profile|||
|ProfilePasswordPolicy|||
|ProfileSessionSetting|||
Expand Down Expand Up @@ -437,6 +458,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|ServiceChannel|||
|ServiceCloudVoiceSettings|||
|ServicePresenceStatus|||
|ServiceProcess||Not supported, but support could be added|
|ServiceSetupAssistantSettings|||
|SharingCriteriaRule|||
|SharingGuestRule|||
Expand Down Expand Up @@ -497,6 +519,7 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t
|VirtualVisitConfig||Not supported, but support could be added|
|VoiceSettings|||
|WarrantyLifecycleMgmtSettings|||
|WaveAnalyticAssetCollection||Not supported, but support could be added|
|WaveApplication|||
|WaveComponent|||
|WaveDashboard|||
Expand Down Expand Up @@ -524,35 +547,11 @@ To contribute a new metadata type, please see the [Contributing Metadata Types t



## Next Release (v57)
v57 introduces the following new types. Here's their current level of support
## Next Release (v58)
v58 introduces the following new types. Here's their current level of support

|Metadata Type|Support|Notes|
|:---|:---|:---|
|ActionLauncherItemDef||Not supported, but support could be added|
|ActionableListDefinition||Not supported, but support could be added|
|AppExplorationDataConsent||Not supported, but support could be added|
|ClaimFinancialSettings|||
|ClauseCatgConfiguration|||
|DisclosureDefinition|||
|DisclosureDefinitionVersion|||
|DisclosureType|||
|ExternalClientAppSettings|||
|ExternalClientApplication|||
|ExtlClntAppMobileConfigurablePolicies|||
|ExtlClntAppMobileSettings|||
|ExtlClntAppOauthConfigurablePolicies|||
|ExtlClntAppOauthSettings|||
|IdentityProviderSettings|||
|IntegrationProviderDef||Not supported, but support could be added|
|LocationUse||Not supported, but support could be added|
|OmniSupervisorConfig|||
|PaymentsIngestEnabledSettings|||
|PersonAccountOwnerPowerUser||Not supported, but support could be added|
|PipelineInspMetricConfig||Not supported, but support could be added|
|ProductSpecificationTypeDefinition||Not supported, but support could be added|
|ServiceProcess||Not supported, but support could be added|
|WaveAnalyticAssetCollection||Not supported, but support could be added|

## Additional Types

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"node": ">=14.0.0"
},
"dependencies": {
"@salesforce/core": "^3.32.6",
"@salesforce/core": "^3.32.8",
"@salesforce/kit": "^1.8.0",
"@salesforce/ts-types": "^1.7.1",
"archiver": "^5.3.1",
Expand Down Expand Up @@ -117,4 +117,4 @@
"yarn": "1.22.4"
},
"config": {}
}
}
25 changes: 21 additions & 4 deletions src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,20 @@ export class MetadataApiDeploy extends MetadataTransfer<MetadataApiDeployStatus,
protected async pre(): Promise<AsyncResult> {
const LifecycleInstance = Lifecycle.getInstance();
const connection = await this.getConnection();
const apiVersion = connection.getApiVersion();

// store for use in the scopedPostDeploy event
this.orgId = connection.getAuthInfoFields().orgId;
if (this.components && !this.components.apiVersion && !this.components.sourceApiVersion) {
// if we have a ComponentSet, but got no version info, let's use the org's max version for calculating what goes into the package.xml
this.components.apiVersion = connection.getApiVersion();
this.components.sourceApiVersion = connection.getApiVersion();

// If we have a ComponentSet but no version info, use the apiVersion from the Connection.
if (this.components) {
// this is the SOAP/REST API version of the connection
this.components.apiVersion ??= apiVersion;

// this is used as the version in the manifest (package.xml).
this.components.sourceApiVersion ??= apiVersion;
}

// only do event hooks if source, (NOT a metadata format) deploy
if (this.options.components) {
await LifecycleInstance.emit('scopedPreDeploy', {
Expand All @@ -345,6 +352,16 @@ export class MetadataApiDeploy extends MetadataTransfer<MetadataApiDeployStatus,
const [zipBuffer] = await Promise.all([this.getZipBuffer(), this.maybeSaveTempDirectory('metadata')]);
// SDR modifies what the mdapi expects by adding a rest param
const { rest, ...optionsWithoutRest } = this.options.apiOptions;

// Debug output for API version and source API version used for deploy
if (this.components?.apiVersion) {
const manifestVersion = this.components?.sourceApiVersion ?? apiVersion;
const webService = rest ? 'REST' : 'SOAP';

this.logger.debug(`Deploying metadata source in v${manifestVersion} shape using ${webService} v${apiVersion}`);
await LifecycleInstance.emit('apiVersionDeploy', { webService, manifestVersion, apiVersion });
}

return this.isRestDeploy
? connection.metadata.deployRest(zipBuffer, optionsWithoutRest)
: connection.metadata.deploy(zipBuffer, optionsWithoutRest);
Expand Down
17 changes: 15 additions & 2 deletions src/client/metadataApiRetrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,12 @@ export class MetadataApiRetrieve extends MetadataTransfer<MetadataApiRetrieveSta
}

const connection = await this.getConnection();
const apiVersion = connection.getApiVersion();
this.orgId = connection.getAuthInfoFields().orgId;

this.components.apiVersion ??= apiVersion;
this.components.sourceApiVersion ??= apiVersion;

// only do event hooks if source, (NOT a metadata format) retrieve
if (this.options.components) {
await Lifecycle.getInstance().emit('scopedPreRetrieve', {
Expand All @@ -217,9 +221,13 @@ export class MetadataApiRetrieve extends MetadataTransfer<MetadataApiRetrieveSta
} as ScopedPreRetrieve);
}

const manifestData = (await this.components.getObject()).Package;

const requestBody: RetrieveRequest = {
apiVersion: this.components.apiVersion ?? (await connection.retrieveMaxApiVersion()),
unpackaged: (await this.components.getObject()).Package,
// This apiVersion is only used when the version in the package.xml (manifestData) is not defined.
// see docs here: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_retrieve_request.htm
apiVersion: this.components.sourceApiVersion ?? (await connection.retrieveMaxApiVersion()),
unpackaged: manifestData,
};

// if we're retrieving with packageNames add it
Expand All @@ -236,6 +244,11 @@ export class MetadataApiRetrieve extends MetadataTransfer<MetadataApiRetrieveSta
requestBody.singlePackage = this.options.singlePackage;
}

// Debug output for API version used for retrieve
const manifestVersion = manifestData.version;
this.logger.debug(`Retrieving source in v${manifestVersion} shape using SOAP v${apiVersion}`);
await Lifecycle.getInstance().emit('apiVersionRetrieve', { manifestVersion, apiVersion });

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore required callback
return connection.metadata.retrieve(requestBody);
Expand Down
29 changes: 25 additions & 4 deletions src/collections/componentSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {

const resolveIncludeSet = options.resolveSourcePaths ? new ComponentSet([], options.registry) : undefined;
const result = new ComponentSet([], options.registry);
result.apiVersion = manifest.apiVersion;

result.logger.debug(`Setting sourceApiVersion of ${manifest.apiVersion} on ComponentSet from manifest`);
result.sourceApiVersion = manifest.apiVersion;
result.fullName = manifest.fullName;

const addComponent = (component: MetadataComponent, deletionType?: DestructiveChangesType): void => {
Expand Down Expand Up @@ -309,14 +311,22 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
throw new SfError(messages.getMessage('error_no_source_to_deploy'), 'ComponentSetError');
}

if (
typeof options.usernameOrConnection !== 'string' &&
this.apiVersion &&
this.apiVersion !== options.usernameOrConnection.version
) {
options.usernameOrConnection.setApiVersion(this.apiVersion);
this.logger.debug(
`Received conflicting apiVersion values for deploy. Using option=${this.apiVersion}, Ignoring apiVersion on connection=${options.usernameOrConnection.version}.`
);
}

const operationOptions = Object.assign({}, options, {
components: this,
registry: this.registry,
apiVersion: this.apiVersion,
});
// if (!options.apiVersion && !this.apiVersion && !this.sourceApiVersion) {
// operationOptions.apiVersion = `${await getCurrentApiVersion()}.0`;
// }

const mdapiDeploy = new MetadataApiDeploy(operationOptions);
await mdapiDeploy.start();
Expand All @@ -337,6 +347,17 @@ export class ComponentSet extends LazyCollection<MetadataComponent> {
apiVersion: this.apiVersion,
});

if (
typeof options.usernameOrConnection !== 'string' &&
this.apiVersion &&
this.apiVersion !== options.usernameOrConnection.version
) {
options.usernameOrConnection.setApiVersion(this.apiVersion);
this.logger.debug(
`Received conflicting apiVersion values for retrieve. Using option=${this.apiVersion}, Ignoring apiVersion on connection=${options.usernameOrConnection.version}.`
);
}

const mdapiRetrieve = new MetadataApiRetrieve(operationOptions);
await mdapiRetrieve.start();
return mdapiRetrieve;
Expand Down
11 changes: 4 additions & 7 deletions src/collections/componentSetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,10 @@ export class ComponentSetBuilder {
}
}

if (apiversion) {
componentSet.apiVersion = apiversion;
}

if (sourceapiversion) {
componentSet.sourceApiVersion = sourceapiversion;
}
componentSet.apiVersion ??= apiversion;
componentSet.sourceApiVersion ??= sourceapiversion;
logger.debug(`ComponentSet apiVersion = ${componentSet.apiVersion}`);
logger.debug(`ComponentSet sourceApiVersion = ${componentSet.sourceApiVersion}`);

return componentSet;
}
Expand Down
3 changes: 2 additions & 1 deletion test/client/metadataApiRetrieve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ describe('MetadataApiRetrieve', () => {
await operation.start();
const result = await operation.pollStatus();
const expected = new RetrieveResult(response, toRetrieve, toRetrieve);
expect(result).to.deep.equalInAnyOrder(expected);
expect(result.response).to.deep.equalInAnyOrder(expected.response);
expect(result.components.toArray()).to.deep.equalInAnyOrder(expected.components.toArray());
});

it('should construct a result object with no components when components are forceIgnored', async () => {
Expand Down
Loading

0 comments on commit 2e865e9

Please sign in to comment.