1+ /*
2+ * Copyright 2025, Salesforce, Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
116import * as fs from 'node:fs/promises' ;
217import { SfCommand , Flags } from '@salesforce/sf-plugins-core' ;
318import { Messages } from '@salesforce/core' ;
@@ -73,12 +88,12 @@ export default class CmlImportAsExpressionSet extends SfCommand<CmlImportAsExpre
7388 const { id : expressionSetId } = existingExpressionSetId
7489 ? { id : existingExpressionSetId }
7590 : await conn . sobject ( 'ExpressionSet' ) . create ( {
76- ApiName : cmlApiName ,
77- Name : cmlApiName ,
78- UsageType : 'Constraint' ,
79- ResourceInitializationType : 'Off' ,
80- InterfaceSourceType : 'Constraint' ,
81- } ) ;
91+ ApiName : cmlApiName ,
92+ Name : cmlApiName ,
93+ UsageType : 'Constraint' ,
94+ ResourceInitializationType : 'Off' ,
95+ InterfaceSourceType : 'Constraint' ,
96+ } ) ;
8297 const { Id : expressionSetDefinitionId } =
8398 ( await conn . sobject ( 'ExpressionSetDefinition' ) . findOne ( { DeveloperName : cmlApiName } , [ 'Id' ] ) ) ?? { } ;
8499 const { Id : expressionSetDefinitionVersionId } =
@@ -114,9 +129,7 @@ export default class CmlImportAsExpressionSet extends SfCommand<CmlImportAsExpre
114129 if ( productIdsStr ?. length ) {
115130 const productsSoql = `SELECT Id,Name FROM Product2 WHERE Name IN (${ productIdsStr } )` ;
116131 const productsQuery = await conn . query ( productsSoql , { autoFetch : true } ) ;
117- productsQuery . records . forEach ( ( r ) =>
118- productNameToId . set ( `${ r . Name as string } ` , `${ r . Id as string } ` )
119- ) ;
132+ productsQuery . records . forEach ( ( r ) => productNameToId . set ( `${ r . Name as string } ` , `${ r . Id as string } ` ) ) ;
120133 }
121134
122135 const classNameToId = new Map < string , string > ( ) ;
@@ -127,23 +140,23 @@ export default class CmlImportAsExpressionSet extends SfCommand<CmlImportAsExpre
127140 if ( classIdsStr ?. length ) {
128141 const classificationsSoql = `SELECT Id,Name FROM ProductClassification WHERE Name IN (${ classIdsStr } )` ;
129142 const classificationsQuery = await conn . query ( classificationsSoql , { autoFetch : true } ) ;
130- classificationsQuery . records . forEach ( ( r ) =>
131- classNameToId . set ( `${ r . Name as string } ` , `${ r . Id as string } ` )
132- ) ;
143+ classificationsQuery . records . forEach ( ( r ) => classNameToId . set ( `${ r . Name as string } ` , `${ r . Id as string } ` ) ) ;
133144 }
134145
135146 const parentAndChildToPrcId = new Map < string , Map < string , string > > ( ) ;
136147 const parentProductIds : string [ ] = [ ...productNameToId . values ( ) ] ;
137148 if ( parentProductIds . length > 0 ) {
138- const prcSoql = `SELECT Id, ParentProductId, ChildProductId, ChildProductClassificationId FROM ProductRelatedComponent WHERE ParentProductId IN (${ parentProductIds . map ( ( id ) => `'${ id } '` ) . join ( ',' ) } )` ;
149+ const prcSoql = `SELECT Id, ParentProductId, ChildProductId, ChildProductClassificationId FROM ProductRelatedComponent WHERE ParentProductId IN (${ parentProductIds
150+ . map ( ( id ) => `'${ id } '` )
151+ . join ( ',' ) } )`;
139152 ( await conn . query ( prcSoql , { autoFetch : true } ) ) . records . forEach ( ( r ) => {
140153 if ( ! parentAndChildToPrcId . has ( r . ParentProductId as string ) ) {
141154 parentAndChildToPrcId . set ( r . ParentProductId as string , new Map < string , string > ( ) ) ;
142155 }
143156 const childToPrcId = parentAndChildToPrcId . get ( r . ParentProductId as string ) ;
144157 childToPrcId ?. set (
145158 ( r . ChildProductId as string ) ?? ( r . ChildProductClassificationId as string ) ?? 'unexpected' ,
146- ( r . Id as string ) ?? 'unexpected' ,
159+ ( r . Id as string ) ?? 'unexpected'
147160 ) ;
148161 } ) ;
149162 }
@@ -158,7 +171,7 @@ export default class CmlImportAsExpressionSet extends SfCommand<CmlImportAsExpre
158171 ReferenceObjectId : a . ReferenceObjectId . startsWith ( '01t' )
159172 ? productNameToId . get ( a . $Product2ReferenceId )
160173 : classNameToId . get ( a . $ProductClassificationName ) ,
161- } ) as ExpressionSetConstraintObj ,
174+ } as ExpressionSetConstraintObj )
162175 ) ,
163176 ...portAssociations . map ( ( a ) => {
164177 const [ parentProductName , childProductName , childClassName ] = a . $ProductRelatedComponentKey . split ( '||' ) ;
@@ -178,7 +191,7 @@ export default class CmlImportAsExpressionSet extends SfCommand<CmlImportAsExpre
178191
179192 const escoSoql = `SELECT Id, ExpressionSetId, ConstraintModelTag, ConstraintModelTagType, ReferenceObjectId FROM ExpressionSetConstraintObj WHERE ExpressionSetId = '${ expressionSetId ! } '` ;
180193 const escos = ( await conn . query ( escoSoql , { autoFetch : true } ) ) . records . map (
181- ( esco ) => esco as ExpressionSetConstraintObj ,
194+ ( esco ) => esco as ExpressionSetConstraintObj
182195 ) ;
183196
184197 this . log ( '📦 Upload CML associations' ) ;
@@ -188,8 +201,8 @@ export default class CmlImportAsExpressionSet extends SfCommand<CmlImportAsExpre
188201 ( esco ) =>
189202 ConstraintModelTag === esco . ConstraintModelTag &&
190203 ConstraintModelTagType === esco . ConstraintModelTagType &&
191- ReferenceObjectId === esco . ReferenceObjectId ,
192- ) ,
204+ ReferenceObjectId === esco . ReferenceObjectId
205+ )
193206 ) ;
194207 const saveResults = await conn . sobject ( 'ExpressionSetConstraintObj' ) . create ( associationtsToInsert ) ;
195208 this . log ( '✅ Uploaded CML associations:' ) ;
0 commit comments