@salesforce/plugin-bre-to-cml 1.0.2
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/LICENSE.txt +206 -0
- package/README.md +158 -0
- package/lib/commands/cml/convert/prod-cfg-rules.d.ts +29 -0
- package/lib/commands/cml/convert/prod-cfg-rules.js +226 -0
- package/lib/commands/cml/convert/prod-cfg-rules.js.map +1 -0
- package/lib/commands/cml/import/as-expression-set.d.ts +18 -0
- package/lib/commands/cml/import/as-expression-set.js +184 -0
- package/lib/commands/cml/import/as-expression-set.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +17 -0
- package/lib/index.js.map +1 -0
- package/lib/shared/bre-rules-generator.d.ts +20 -0
- package/lib/shared/bre-rules-generator.js +497 -0
- package/lib/shared/bre-rules-generator.js.map +1 -0
- package/lib/shared/cml.d.ts +2 -0
- package/lib/shared/cml.js +13 -0
- package/lib/shared/cml.js.map +1 -0
- package/lib/shared/constants/constants.d.ts +94 -0
- package/lib/shared/constants/constants.js +109 -0
- package/lib/shared/constants/constants.js.map +1 -0
- package/lib/shared/grouping.d.ts +4 -0
- package/lib/shared/grouping.js +88 -0
- package/lib/shared/grouping.js.map +1 -0
- package/lib/shared/models.d.ts +65 -0
- package/lib/shared/models.js +2 -0
- package/lib/shared/models.js.map +1 -0
- package/lib/shared/pcm-generator.d.ts +57 -0
- package/lib/shared/pcm-generator.js +418 -0
- package/lib/shared/pcm-generator.js.map +1 -0
- package/lib/shared/pcm-products.d.ts +14 -0
- package/lib/shared/pcm-products.js +125 -0
- package/lib/shared/pcm-products.js.map +1 -0
- package/lib/shared/pcm-products.types.d.ts +99 -0
- package/lib/shared/pcm-products.types.js +2 -0
- package/lib/shared/pcm-products.types.js.map +1 -0
- package/lib/shared/types/association.d.ts +15 -0
- package/lib/shared/types/association.js +64 -0
- package/lib/shared/types/association.js.map +1 -0
- package/lib/shared/types/base/annotated-cml-element-w-attributes.d.ts +10 -0
- package/lib/shared/types/base/annotated-cml-element-w-attributes.js +36 -0
- package/lib/shared/types/base/annotated-cml-element-w-attributes.js.map +1 -0
- package/lib/shared/types/base/annotated-cml-element.d.ts +9 -0
- package/lib/shared/types/base/annotated-cml-element.js +39 -0
- package/lib/shared/types/base/annotated-cml-element.js.map +1 -0
- package/lib/shared/types/base/types.d.ts +2 -0
- package/lib/shared/types/base/types.js +18 -0
- package/lib/shared/types/base/types.js.map +1 -0
- package/lib/shared/types/cml-attribute.d.ts +17 -0
- package/lib/shared/types/cml-attribute.js +84 -0
- package/lib/shared/types/cml-attribute.js.map +1 -0
- package/lib/shared/types/cml-constraint.d.ts +50 -0
- package/lib/shared/types/cml-constraint.js +277 -0
- package/lib/shared/types/cml-constraint.js.map +1 -0
- package/lib/shared/types/cml-domain.d.ts +25 -0
- package/lib/shared/types/cml-domain.js +132 -0
- package/lib/shared/types/cml-domain.js.map +1 -0
- package/lib/shared/types/cml-model.d.ts +39 -0
- package/lib/shared/types/cml-model.js +153 -0
- package/lib/shared/types/cml-model.js.map +1 -0
- package/lib/shared/types/cml-relation.d.ts +31 -0
- package/lib/shared/types/cml-relation.js +118 -0
- package/lib/shared/types/cml-relation.js.map +1 -0
- package/lib/shared/types/cml-type.d.ts +22 -0
- package/lib/shared/types/cml-type.js +111 -0
- package/lib/shared/types/cml-type.js.map +1 -0
- package/lib/shared/types/sobject.d.ts +13 -0
- package/lib/shared/types/sobject.js +2 -0
- package/lib/shared/types/sobject.js.map +1 -0
- package/lib/shared/types/types.d.ts +8 -0
- package/lib/shared/types/types.js +24 -0
- package/lib/shared/types/types.js.map +1 -0
- package/lib/shared/utils/association.utils.d.ts +61 -0
- package/lib/shared/utils/association.utils.js +175 -0
- package/lib/shared/utils/association.utils.js.map +1 -0
- package/lib/shared/utils/common.utils.d.ts +191 -0
- package/lib/shared/utils/common.utils.js +338 -0
- package/lib/shared/utils/common.utils.js.map +1 -0
- package/messages/call.external.service.md +20 -0
- package/messages/cml.convert.prod-cfg-rules.md +59 -0
- package/messages/cml.import.as-expression-set.md +32 -0
- package/messages/connect.org.md +19 -0
- package/messages/hello.world.md +29 -0
- package/oclif.lock +8313 -0
- package/oclif.manifest.json +209 -0
- package/package.json +227 -0
|
@@ -0,0 +1,418 @@
|
|
|
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
|
+
*/
|
|
16
|
+
import { ASSOCIATION_TYPES, CML_DATA_TYPES, CML_VARIABLE_VALUE_TYPES } from './constants/constants.js';
|
|
17
|
+
import { getRelationAssociationForRelationAndReferenceObjectId, getRelationNameForRelatedObjectId, getTypeAssociationForTypeAndReferenceObjectId, getTypeNameForRelatedObjectId, } from './utils/association.utils.js';
|
|
18
|
+
import { isRelationNameUnique, isScaledType, isTypeNameUnique } from './utils/common.utils.js';
|
|
19
|
+
import { Association, CmlAttribute, CmlDomain, CmlRelation, CmlType } from './types/types.js';
|
|
20
|
+
const dataTypeToCmlType = {
|
|
21
|
+
CHECKBOX: CML_DATA_TYPES.BOOLEAN,
|
|
22
|
+
DATE: CML_DATA_TYPES.DATE,
|
|
23
|
+
NUMBER: CML_DATA_TYPES.DECIMAL,
|
|
24
|
+
TEXT: CML_DATA_TYPES.STRING,
|
|
25
|
+
STRING: CML_DATA_TYPES.STRING,
|
|
26
|
+
CURRENCY: CML_DATA_TYPES.DECIMAL,
|
|
27
|
+
PERCENT: CML_DATA_TYPES.DECIMAL,
|
|
28
|
+
};
|
|
29
|
+
export class PcmGenerator {
|
|
30
|
+
static generateType(model, product, existingProductIdsToTypes) {
|
|
31
|
+
const existingTypeName = getTypeNameForRelatedObjectId(model.associations, product.id);
|
|
32
|
+
if (existingTypeName) {
|
|
33
|
+
const existingType = model.getType(existingTypeName);
|
|
34
|
+
if (existingType) {
|
|
35
|
+
return {
|
|
36
|
+
type: existingType,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const name = product.nodeType === 'productClass' ? product.productClassification.name : product.name;
|
|
41
|
+
const typeName = generateUniqueTypeName(model, name, existingProductIdsToTypes);
|
|
42
|
+
const type = new CmlType(typeName, product.id, product.productClassification?.id);
|
|
43
|
+
const hasExistingAssociation = getTypeAssociationForTypeAndReferenceObjectId(model.associations, type, product.id);
|
|
44
|
+
if (hasExistingAssociation) {
|
|
45
|
+
return {
|
|
46
|
+
type,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const referenceObjectId = product.nodeType === 'productClass' ? product.productClassification?.id : product.id;
|
|
50
|
+
const referenceObjectType = product.nodeType === 'productClass' ? 'ProductClassification' : 'Product2';
|
|
51
|
+
const referenceObjectReferenceValue = product.nodeType === 'productClass' ? product.productClassification?.name : product.name;
|
|
52
|
+
const association = new Association(null, typeName, ASSOCIATION_TYPES.TYPE, referenceObjectId, referenceObjectType, referenceObjectReferenceValue);
|
|
53
|
+
return {
|
|
54
|
+
association,
|
|
55
|
+
type,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
static setParentTypesToBaseType(model) {
|
|
59
|
+
const baseType = model.getType('LineItem');
|
|
60
|
+
for (const type of model.types) {
|
|
61
|
+
if (baseType && type !== baseType && type.parentType == null && type.properties?.virtual !== true) {
|
|
62
|
+
type.setParentType(baseType);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
static generateRelationsAndChildTypes(model, type, rootProduct, childProducts) {
|
|
67
|
+
const relations = [];
|
|
68
|
+
const types = [];
|
|
69
|
+
const associations = [];
|
|
70
|
+
const existingProductIdsToTypes = new Map();
|
|
71
|
+
const existingPrcIdsToRelations = new Map();
|
|
72
|
+
const rootProductId = rootProduct.id;
|
|
73
|
+
// generate association for root product's type
|
|
74
|
+
const existingAssociation = getTypeAssociationForTypeAndReferenceObjectId(model.associations, type, rootProductId);
|
|
75
|
+
if (!existingAssociation) {
|
|
76
|
+
associations.push(new Association(null, type.name, ASSOCIATION_TYPES.TYPE, rootProductId, 'Product2', rootProduct.name));
|
|
77
|
+
}
|
|
78
|
+
for (const childProduct of childProducts) {
|
|
79
|
+
// generate child type
|
|
80
|
+
const childTypeResult = PcmGenerator.generateType(model, childProduct, existingProductIdsToTypes);
|
|
81
|
+
const childProductType = childTypeResult.type;
|
|
82
|
+
types.push(childProductType);
|
|
83
|
+
existingProductIdsToTypes.set(childProduct.id, childProductType);
|
|
84
|
+
if (childTypeResult.association) {
|
|
85
|
+
associations.push(childTypeResult.association);
|
|
86
|
+
}
|
|
87
|
+
// generate relation to child type
|
|
88
|
+
const prc = childProduct.productRelatedComponent;
|
|
89
|
+
const childRelationResult = PcmGenerator.generateRelation(model, type, childProductType, childProduct, rootProduct, prc, existingPrcIdsToRelations);
|
|
90
|
+
relations.push(childRelationResult.relation);
|
|
91
|
+
existingPrcIdsToRelations.set(prc.id, childRelationResult.relation);
|
|
92
|
+
if (childRelationResult.association) {
|
|
93
|
+
associations.push(childRelationResult.association);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
associations,
|
|
98
|
+
relations,
|
|
99
|
+
types,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// generate types, attributes, relations, associations
|
|
103
|
+
static generateViewModels(model, productsToAdd) {
|
|
104
|
+
const types = [];
|
|
105
|
+
const associations = [];
|
|
106
|
+
const relations = new Map();
|
|
107
|
+
const attributes = new Map();
|
|
108
|
+
// prevent duplicates by keeping track of selected products and PRCs that are not yet added to the model
|
|
109
|
+
const existingProductIdsToTypes = new Map();
|
|
110
|
+
const existingPrcIdsToRelations = new Map();
|
|
111
|
+
for (const product of productsToAdd) {
|
|
112
|
+
// for single product/parent product, generate types, attributes, type associations
|
|
113
|
+
let type = existingProductIdsToTypes.get(product.id);
|
|
114
|
+
if (!type) {
|
|
115
|
+
const typeInfo = PcmGenerator.generateType(model, product, existingProductIdsToTypes);
|
|
116
|
+
type = typeInfo.type;
|
|
117
|
+
const baseType = model.getType('LineItem');
|
|
118
|
+
if (baseType) {
|
|
119
|
+
type.setParentType(baseType);
|
|
120
|
+
}
|
|
121
|
+
types.push(type);
|
|
122
|
+
existingProductIdsToTypes.set(product.id, type);
|
|
123
|
+
if (typeInfo.association) {
|
|
124
|
+
associations.push(typeInfo.association);
|
|
125
|
+
}
|
|
126
|
+
const existingTypeName = getTypeNameForRelatedObjectId(model.associations, product.id);
|
|
127
|
+
if (!existingTypeName) {
|
|
128
|
+
const productAttributes = PcmGenerator.getProductAttributes(product);
|
|
129
|
+
const typeAttributes = PcmGenerator.generateAttributes(productAttributes);
|
|
130
|
+
if (typeAttributes && typeAttributes.length > 0) {
|
|
131
|
+
attributes.set(type.name, typeAttributes);
|
|
132
|
+
// type.setPcmVariables(typeAttributes);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// if bundle product, generate view model for all levels
|
|
137
|
+
const productComponents = PcmGenerator.getProductComponents(product);
|
|
138
|
+
if (productComponents && productComponents.length > 0) {
|
|
139
|
+
const childTypesInfo = PcmGenerator.generateRelationsAttributesAndChildTypesRecursively(model, type, product, productComponents, existingProductIdsToTypes, existingPrcIdsToRelations);
|
|
140
|
+
if (childTypesInfo.types && childTypesInfo.types.length > 0) {
|
|
141
|
+
types.push(...childTypesInfo.types);
|
|
142
|
+
}
|
|
143
|
+
if (childTypesInfo.relations && childTypesInfo.relations.size > 0) {
|
|
144
|
+
childTypesInfo.relations.forEach((value, key) => {
|
|
145
|
+
relations.set(key, value);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (childTypesInfo.associations && childTypesInfo.associations.length > 0) {
|
|
149
|
+
associations.push(...childTypesInfo.associations);
|
|
150
|
+
}
|
|
151
|
+
if (childTypesInfo.attributes && childTypesInfo.attributes.size > 0) {
|
|
152
|
+
childTypesInfo.attributes.forEach((value, key) => {
|
|
153
|
+
attributes.set(key, value);
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
types,
|
|
160
|
+
attributes,
|
|
161
|
+
relations,
|
|
162
|
+
associations,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
static generateRelationsAttributesAndChildTypesRecursively(model, type, parentProduct, childProducts, existingProductIdsToTypes, existingPrcIdsToRelations, types = [], associations = [], relations = new Map(), attributes = new Map()) {
|
|
166
|
+
for (const childProduct of childProducts) {
|
|
167
|
+
// generate child type, type association, attributes if they don't exist
|
|
168
|
+
let childType = existingProductIdsToTypes.get(childProduct.id);
|
|
169
|
+
if (!childType) {
|
|
170
|
+
const childTypeInfo = PcmGenerator.generateType(model, childProduct, existingProductIdsToTypes);
|
|
171
|
+
childType = childTypeInfo.type;
|
|
172
|
+
const baseType = model.getType('LineItem');
|
|
173
|
+
if (baseType && !childType.hasParentType()) {
|
|
174
|
+
childType.setParentType(baseType);
|
|
175
|
+
}
|
|
176
|
+
types.push(childType);
|
|
177
|
+
if (childTypeInfo.association) {
|
|
178
|
+
associations.push(childTypeInfo.association);
|
|
179
|
+
}
|
|
180
|
+
existingProductIdsToTypes.set(childProduct.id, childType);
|
|
181
|
+
const existingTypeName = getTypeNameForRelatedObjectId(model.associations, childProduct.id);
|
|
182
|
+
if (!existingTypeName) {
|
|
183
|
+
const productAttributes = PcmGenerator.getProductAttributes(childProduct);
|
|
184
|
+
const childTypeAttributes = PcmGenerator.generateAttributes(productAttributes);
|
|
185
|
+
if (childTypeAttributes && childTypeAttributes.length > 0) {
|
|
186
|
+
attributes.set(childType.name, childTypeAttributes);
|
|
187
|
+
// childType.setPcmVariables(childTypeAttributes);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// generate relation to child type and relation association if they don't exist
|
|
192
|
+
const prc = childProduct.productRelatedComponent;
|
|
193
|
+
if (!existingPrcIdsToRelations.get(prc.id)) {
|
|
194
|
+
const childRelationInfo = PcmGenerator.generateRelation(model, type, childType, childProduct, parentProduct, prc, existingPrcIdsToRelations);
|
|
195
|
+
const relationsForTypeId = relations.get(type.name) ?? [];
|
|
196
|
+
if (!relationsForTypeId.includes(childRelationInfo.relation)) {
|
|
197
|
+
relationsForTypeId.push(childRelationInfo.relation);
|
|
198
|
+
relations.set(type.name, relationsForTypeId);
|
|
199
|
+
}
|
|
200
|
+
existingPrcIdsToRelations.set(prc.id, childRelationInfo.relation);
|
|
201
|
+
if (childRelationInfo.association) {
|
|
202
|
+
associations.push(childRelationInfo.association);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// generate entities for each level of bundle
|
|
206
|
+
const childProductComponents = this.getProductComponents(childProduct);
|
|
207
|
+
if (childProductComponents && childProductComponents.length > 0) {
|
|
208
|
+
this.generateRelationsAttributesAndChildTypesRecursively(model, childType, childProduct, childProductComponents, existingProductIdsToTypes, existingPrcIdsToRelations, types, associations, relations, attributes);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
associations,
|
|
213
|
+
attributes,
|
|
214
|
+
relations,
|
|
215
|
+
types,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
static generateRelation(model, parentProductType, childProductType, childProductComponent, parentProduct, prc, existingPrcIdsToRelations) {
|
|
219
|
+
const existingRelationName = getRelationNameForRelatedObjectId(model.associations, prc.id);
|
|
220
|
+
if (existingRelationName) {
|
|
221
|
+
const existingRelation = parentProductType.getRelation(existingRelationName);
|
|
222
|
+
if (existingRelation) {
|
|
223
|
+
// TODO: Potential bug here is that a different type could have a
|
|
224
|
+
// relation for this PRC record. Relation names are not unique
|
|
225
|
+
// across types, and associations could confuse this code.
|
|
226
|
+
return {
|
|
227
|
+
relation: existingRelation,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const relationName = generateUniqueRelationName(parentProductType, childProductType.name, existingPrcIdsToRelations);
|
|
232
|
+
const relation = new CmlRelation(relationName, childProductType.name);
|
|
233
|
+
relation.setPrcIds([prc.id]);
|
|
234
|
+
if (prc.minQuantity !== undefined) {
|
|
235
|
+
relation.setMinCardinality(prc.minQuantity);
|
|
236
|
+
}
|
|
237
|
+
else if (prc.isComponentRequired) {
|
|
238
|
+
relation.setMinCardinality(1);
|
|
239
|
+
}
|
|
240
|
+
if (prc.maxQuantity !== undefined) {
|
|
241
|
+
relation.setMaxCardinality(prc.maxQuantity);
|
|
242
|
+
}
|
|
243
|
+
else if (prc.isComponentRequired) {
|
|
244
|
+
relation.setMaxCardinality(9999);
|
|
245
|
+
}
|
|
246
|
+
// // all CML components have a default quantity of 1, so only set this if that is not the case
|
|
247
|
+
// if (prc.quantity > 1) {
|
|
248
|
+
// const component = new Component(childProductType.name);
|
|
249
|
+
// component.setDefaultQuantity(prc.quantity);
|
|
250
|
+
// relation.addDefaultComponent(component);
|
|
251
|
+
// }
|
|
252
|
+
const hasExistingAssociation = getRelationAssociationForRelationAndReferenceObjectId(model.associations, relation, prc.id);
|
|
253
|
+
if (hasExistingAssociation) {
|
|
254
|
+
return {
|
|
255
|
+
relation,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
let referenceObjectReferenceValue = `${parentProduct.name}||${childProductComponent.name}||`;
|
|
259
|
+
if (childProductComponent.nodeType === 'productClass') {
|
|
260
|
+
referenceObjectReferenceValue = `${parentProduct.name}||||${childProductComponent.productClassification.name}`;
|
|
261
|
+
}
|
|
262
|
+
const association = new Association(null, relationName, ASSOCIATION_TYPES.RELATION, prc.id, 'ProductRelatedComponent', referenceObjectReferenceValue);
|
|
263
|
+
return {
|
|
264
|
+
association,
|
|
265
|
+
relation,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
static getProductComponents(product) {
|
|
269
|
+
const components = [];
|
|
270
|
+
// Helper function to recursively process groups and child groups
|
|
271
|
+
function processGroup(group) {
|
|
272
|
+
components.push(...(group.components || []));
|
|
273
|
+
(group.childGroups || []).forEach(processGroup);
|
|
274
|
+
}
|
|
275
|
+
// // Add ungrouped components (legacy PCM support)
|
|
276
|
+
// components.push(...(product.components || []));
|
|
277
|
+
// Add grouped components recursively
|
|
278
|
+
(product.productComponentGroups || []).forEach(processGroup);
|
|
279
|
+
return components;
|
|
280
|
+
}
|
|
281
|
+
static generateAttributes(productAttributes) {
|
|
282
|
+
const attributes = [];
|
|
283
|
+
for (const productAttribute of productAttributes) {
|
|
284
|
+
attributes.push(PcmGenerator.generateAttribute(productAttribute));
|
|
285
|
+
}
|
|
286
|
+
return attributes;
|
|
287
|
+
}
|
|
288
|
+
static generateAttribute(productAttribute) {
|
|
289
|
+
const attributeId = productAttribute.id;
|
|
290
|
+
const attributeName = productAttribute.developerName;
|
|
291
|
+
const attributeType = PcmGenerator.dataTypeToCmlDataType(productAttribute);
|
|
292
|
+
const attribute = new CmlAttribute(attributeId, attributeName, attributeType);
|
|
293
|
+
if (isScaledType(attributeType)) {
|
|
294
|
+
// For now, we're hardcoding the scale to "2" for all PCM attribute types
|
|
295
|
+
// UOM feature may change this later
|
|
296
|
+
attribute.setTypeScale(2);
|
|
297
|
+
}
|
|
298
|
+
const domain = generateDomain(productAttribute);
|
|
299
|
+
if (domain) {
|
|
300
|
+
attribute.setValue(CML_VARIABLE_VALUE_TYPES.DOMAIN, domain);
|
|
301
|
+
}
|
|
302
|
+
if (productAttribute.isReadOnly) {
|
|
303
|
+
attribute.setProperties({ configurable: false });
|
|
304
|
+
}
|
|
305
|
+
if (productAttribute.defaultValue) {
|
|
306
|
+
attribute.setProperties({ defaultValue: productAttribute.defaultValue });
|
|
307
|
+
}
|
|
308
|
+
return attribute;
|
|
309
|
+
}
|
|
310
|
+
static getProductAttributes(product) {
|
|
311
|
+
const attributes = [];
|
|
312
|
+
// uncategorized attributes (legacy PCM support)
|
|
313
|
+
attributes.push(...(product.attributes || []));
|
|
314
|
+
// categorized attributes
|
|
315
|
+
attributes.push(...(product.attributeCategory?.flatMap((ac) => ac.attributes) ?? []));
|
|
316
|
+
// filter out Inactive and DateTime attributes
|
|
317
|
+
return attributes.filter((a) => a.status === 'Active' && a.dataType.toUpperCase() !== 'DATETIME');
|
|
318
|
+
}
|
|
319
|
+
static dataTypeToCmlDataType(attribute) {
|
|
320
|
+
if (attribute.dataType.toUpperCase() === 'PICKLIST') {
|
|
321
|
+
return this.dataTypeNameToCmlDataType(attribute.picklist.dataType);
|
|
322
|
+
}
|
|
323
|
+
return this.dataTypeNameToCmlDataType(attribute.dataType);
|
|
324
|
+
}
|
|
325
|
+
static dataTypeNameToCmlDataType(dataType) {
|
|
326
|
+
return dataTypeToCmlType[dataType.toUpperCase()];
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
export function generateDomain(attribute) {
|
|
330
|
+
if (attribute.dataType.toUpperCase() === 'PICKLIST') {
|
|
331
|
+
const domain = new CmlDomain();
|
|
332
|
+
const pickListDataType = attribute.picklist.dataType?.toUpperCase();
|
|
333
|
+
switch (pickListDataType) {
|
|
334
|
+
case 'TEXT':
|
|
335
|
+
domain.setDomainValues(attribute.picklist.values.map((v) => v.value));
|
|
336
|
+
break;
|
|
337
|
+
case 'NUMBER':
|
|
338
|
+
domain.setDomainValues(attribute.picklist.values.map((v) => Number(v.value)));
|
|
339
|
+
break;
|
|
340
|
+
case 'DATE':
|
|
341
|
+
domain.setDomainValues(attribute.picklist.values.map((v) => new Date(v.value)));
|
|
342
|
+
break;
|
|
343
|
+
case 'DATETIME':
|
|
344
|
+
domain.setDomainValues(attribute.picklist.values.map((v) => new Date(v.value)));
|
|
345
|
+
break;
|
|
346
|
+
case 'BOOLEAN':
|
|
347
|
+
domain.setDomainValues(attribute.picklist.values.map((v) => v.value === 'true'));
|
|
348
|
+
break;
|
|
349
|
+
case 'CURRENCY':
|
|
350
|
+
domain.setDomainValues(attribute.picklist.values.map((v) => Number(v.value)));
|
|
351
|
+
break;
|
|
352
|
+
case 'PERCENT':
|
|
353
|
+
domain.setDomainValues(attribute.picklist.values.map((v) => Number(v.value)));
|
|
354
|
+
break;
|
|
355
|
+
default:
|
|
356
|
+
domain.setDomainValues(attribute.picklist.values.map((v) => v.value));
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
return domain;
|
|
360
|
+
}
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Generates a unique type name for a product within the given model.
|
|
365
|
+
* Ensures the name has only alphanumeric characters and underscores, starts with a letter,
|
|
366
|
+
* and is no longer than 80 characters.
|
|
367
|
+
*
|
|
368
|
+
* @param {Object} model - The model containing existing type names.
|
|
369
|
+
* @param {string} productName - The base name of the product.
|
|
370
|
+
* @param {Map} existingProductIdsToTypes - A map of existing type names to types that have been created but not yet saved to the model.
|
|
371
|
+
* @returns {string} - A valid, unique type name.
|
|
372
|
+
*/
|
|
373
|
+
export function generateUniqueTypeName(model, productName, existingProductIdsToTypes) {
|
|
374
|
+
// Remove invalid characters and ensure the name starts with an alphabetic character
|
|
375
|
+
let name = productName
|
|
376
|
+
.replace(/[^a-zA-Z0-9_]/g, '') // Keep only alphanumeric and underscores
|
|
377
|
+
.replace(/^[^a-zA-Z]+/, ''); // Ensure it starts with a letter
|
|
378
|
+
if (!name) {
|
|
379
|
+
throw new Error('Product name must contain at least one alphabetic character.');
|
|
380
|
+
}
|
|
381
|
+
// Truncate the name to ensure it's no longer than 80 characters
|
|
382
|
+
const maxBaseLength = 80; // Max length for base name (excluding numeric suffixes)
|
|
383
|
+
if (name.length > maxBaseLength) {
|
|
384
|
+
name = name.substring(0, maxBaseLength);
|
|
385
|
+
}
|
|
386
|
+
let result = name;
|
|
387
|
+
let index = 1;
|
|
388
|
+
// Ensure uniqueness and handle length constraints when appending suffixes
|
|
389
|
+
while (!isTypeNameUnique(model, result, existingProductIdsToTypes) || result.length > 80) {
|
|
390
|
+
const suffix = `${index}`;
|
|
391
|
+
const truncatedName = name.substring(0, Math.min(maxBaseLength - suffix.length, name.length));
|
|
392
|
+
result = `${truncatedName}${suffix}`;
|
|
393
|
+
index += 1;
|
|
394
|
+
}
|
|
395
|
+
return result;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Generates a unique relation name for a parent product type based on a child product type name.
|
|
399
|
+
*
|
|
400
|
+
* @param {Object} parentProductType - The parent product type object containing existing relations.
|
|
401
|
+
* @param {string} childProductTypeName - The base name for the relation.
|
|
402
|
+
* @param {Map} existingPrcIdsToRelations - A map of existing relation names to relations that have been created but not yet saved to the model.
|
|
403
|
+
* @returns {string} - A unique, lowercased relation name.
|
|
404
|
+
*/
|
|
405
|
+
export function generateUniqueRelationName(parentProductType, childProductTypeName, existingPrcIdsToRelations) {
|
|
406
|
+
// product type name
|
|
407
|
+
const baseName = childProductTypeName.toLowerCase(); // lowercased child
|
|
408
|
+
let result = baseName;
|
|
409
|
+
let index = 1;
|
|
410
|
+
// Ensure uniqueness and handle length constraints when appending suffixes
|
|
411
|
+
while (!isRelationNameUnique(parentProductType, result, existingPrcIdsToRelations)) {
|
|
412
|
+
const suffix = `${index}`;
|
|
413
|
+
result = `${baseName}${suffix}`;
|
|
414
|
+
index += 1;
|
|
415
|
+
}
|
|
416
|
+
return result;
|
|
417
|
+
}
|
|
418
|
+
//# sourceMappingURL=pcm-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pcm-generator.js","sourceRoot":"","sources":["../../src/shared/pcm-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,wBAAwB,EAAE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GAAG,aAAa,GAAG,MAAM,EAAE,CAAC;QACrC,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CACxC,iBAA0B,EAC1B,oBAA4B,EAC5B,yBAAmD;IAEnD,oBAAoB;IACpB,MAAM,QAAQ,GAAG,oBAAoB,CAAC,WAAW,EAAE,CAAC,CAAC,mBAAmB;IAExE,IAAI,MAAM,GAAG,QAAQ,CAAC;IACtB,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,0EAA0E;IAC1E,OAAO,CAAC,oBAAoB,CAAC,iBAAiB,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,CAAC;QACnF,MAAM,MAAM,GAAG,GAAG,KAAK,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,QAAQ,GAAG,MAAM,EAAE,CAAC;QAChC,KAAK,IAAI,CAAC,CAAC;IACb,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Connection } from '@salesforce/core';
|
|
2
|
+
import { PCMProduct } from './pcm-products.types.js';
|
|
3
|
+
export type ProductWithIds = {
|
|
4
|
+
product: PCMProduct;
|
|
5
|
+
productIds: string[];
|
|
6
|
+
};
|
|
7
|
+
export declare function fetchProductsFromPcm(conn: Connection, allProductIds: string[]): Promise<Map<string, PCMProduct>>;
|
|
8
|
+
/**
|
|
9
|
+
* Reduces products map to only those products that are not contained in any other bundle product.
|
|
10
|
+
*
|
|
11
|
+
* @param {Map} productMap - Map of PCM products.
|
|
12
|
+
* @returns {Map} Reduced map of PCM products with all ids presented in PCM products structure.
|
|
13
|
+
*/
|
|
14
|
+
export declare function reduceProductsToRootLevelOnly(productMap: Map<string, PCMProduct>): Map<string, ProductWithIds>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { unescapeHtml } from './utils/common.utils.js';
|
|
2
|
+
const PCM_PRODUCTS_BULK_LIMIT = 20;
|
|
3
|
+
const PCM_PRODUCTS_BULK_URI = '/connect/pcm/products/bulk';
|
|
4
|
+
export async function fetchProductsFromPcm(conn, allProductIds) {
|
|
5
|
+
const chunk = (arr, size) => Array.from({ length: Math.ceil(arr.length / size) }, (v, i) => arr.slice(i * size, i * size + size));
|
|
6
|
+
const getPostBulkBody = (productIds) => ({
|
|
7
|
+
correlationId: `${Date.now()}`,
|
|
8
|
+
productIds,
|
|
9
|
+
});
|
|
10
|
+
const fetchPromises = chunk(allProductIds, PCM_PRODUCTS_BULK_LIMIT).map(async (productIds) => conn.requestPost(PCM_PRODUCTS_BULK_URI, getPostBulkBody(productIds)));
|
|
11
|
+
const allProducts = new Map();
|
|
12
|
+
(await Promise.all(fetchPromises))
|
|
13
|
+
.flatMap((resp) => resp.products)
|
|
14
|
+
.forEach((p) => allProducts.set(p.id, unescapeProductName(p)));
|
|
15
|
+
return allProducts;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Do unescape of PCMProduct.name recursively.
|
|
19
|
+
* - & -> &
|
|
20
|
+
*
|
|
21
|
+
* @param {PCMProduct} product - PCM product.
|
|
22
|
+
* @returns {PCMProduct} PCM Product with unescaped name.
|
|
23
|
+
*/
|
|
24
|
+
function unescapeProductName(product) {
|
|
25
|
+
product.name = unescapeHtml(product.name);
|
|
26
|
+
product.childProducts?.forEach((childProduct) => unescapeProductName(childProduct));
|
|
27
|
+
product.productComponentGroups?.forEach((group) => unescapeProductNameInPCGroup(group));
|
|
28
|
+
return product;
|
|
29
|
+
}
|
|
30
|
+
// helper function for unescapeProductName
|
|
31
|
+
function unescapeProductNameInPCGroup(productComponentGroup) {
|
|
32
|
+
productComponentGroup.childGroups?.forEach((childGroup) => unescapeProductNameInPCGroup(childGroup));
|
|
33
|
+
productComponentGroup.components?.forEach((component) => unescapeProductName(component));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reduces products map to only those products that are not contained in any other bundle product.
|
|
37
|
+
*
|
|
38
|
+
* @param {Map} productMap - Map of PCM products.
|
|
39
|
+
* @returns {Map} Reduced map of PCM products with all ids presented in PCM products structure.
|
|
40
|
+
*/
|
|
41
|
+
export function reduceProductsToRootLevelOnly(productMap) {
|
|
42
|
+
const newMap = new Map();
|
|
43
|
+
for (const [productId, product] of productMap) {
|
|
44
|
+
newMap.set(productId, { product, productIds: collectProductIds(product) });
|
|
45
|
+
}
|
|
46
|
+
for (const [productId] of productMap) {
|
|
47
|
+
for (const [, bundleProduct] of newMap) {
|
|
48
|
+
if (isBundleContainsProduct(bundleProduct.product, productId)) {
|
|
49
|
+
newMap.delete(productId);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return newMap;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks if bundle product contains product with id in PCM structure.
|
|
58
|
+
*
|
|
59
|
+
* @param {PCMProduct} bundleProduct - Bundle product.
|
|
60
|
+
* @param {string} productId - Product ID to check.
|
|
61
|
+
* @returns {boolean} Is bundleProduct contains product with id in PCM structure.
|
|
62
|
+
*/
|
|
63
|
+
function isBundleContainsProduct(bundleProduct, productId) {
|
|
64
|
+
if (bundleProduct.nodeType !== 'bundleProduct') {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
for (const childProduct of bundleProduct.childProducts) {
|
|
68
|
+
if (childProduct.id === productId) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
const isContains = isBundleContainsProduct(childProduct, productId);
|
|
72
|
+
if (isContains) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return bundleProduct.productComponentGroups.some((pcg) => isProductComponentGroupContainsProductId(pcg, productId));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Checks if product component group contains product with id.
|
|
80
|
+
*
|
|
81
|
+
* @param {PCMProductComponentGroup} productComponentGroup - Product component group of PCM structure.
|
|
82
|
+
* @param {string} productId - Product ID to check.
|
|
83
|
+
* @returns {boolean} Is productComponentGroup contains product with id.
|
|
84
|
+
*/
|
|
85
|
+
function isProductComponentGroupContainsProductId(productComponentGroup, productId) {
|
|
86
|
+
return (productComponentGroup.components.some((comp) => comp.id === productId || isBundleContainsProduct(comp, productId)) || productComponentGroup.childGroups.some((cg) => isProductComponentGroupContainsProductId(cg, productId)));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Collects product IDs that are presented in PCM structure of provided product
|
|
90
|
+
*
|
|
91
|
+
* @param {PCMProduct} product - PCM Product.
|
|
92
|
+
* @returns {Array} Array of product IDs that are presented in PCM structure of provided product.
|
|
93
|
+
*/
|
|
94
|
+
function collectProductIds(product) {
|
|
95
|
+
const productIds = new Set([product.id]);
|
|
96
|
+
if (product.nodeType === 'bundleProduct') {
|
|
97
|
+
for (const childProduct of product.childProducts) {
|
|
98
|
+
productIds.add(childProduct.id);
|
|
99
|
+
if (childProduct.nodeType === 'bundleProduct') {
|
|
100
|
+
collectProductIds(childProduct).forEach((id) => productIds.add(id));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
for (const pcg of product.productComponentGroups) {
|
|
104
|
+
collectProductIdsInProductComponentGroup(pcg).forEach((id) => productIds.add(id));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return Array.from(productIds);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Collects product IDs that are presented in PCM structure of provided product component group
|
|
111
|
+
*
|
|
112
|
+
* @param {PCMProductComponentGroup} productComponentGroup - PCM Product Component Group.
|
|
113
|
+
* @returns {Array} Array of product IDs that are presented in PCM structure of provided product component group.
|
|
114
|
+
*/
|
|
115
|
+
function collectProductIdsInProductComponentGroup(productComponentGroup) {
|
|
116
|
+
const productIds = new Set();
|
|
117
|
+
for (const comp of productComponentGroup.components) {
|
|
118
|
+
collectProductIds(comp).forEach((id) => productIds.add(id));
|
|
119
|
+
}
|
|
120
|
+
for (const cg of productComponentGroup.childGroups) {
|
|
121
|
+
collectProductIdsInProductComponentGroup(cg).forEach((id) => productIds.add(id));
|
|
122
|
+
}
|
|
123
|
+
return productIds;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=pcm-products.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pcm-products.js","sourceRoot":"","sources":["../../src/shared/pcm-products.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,MAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,MAAM,qBAAqB,GAAG,4BAA4B,CAAC;AAO3D,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAgB,EAChB,aAAuB;IAEvB,MAAM,KAAK,GAAG,CAAC,GAAa,EAAE,IAAY,EAAc,EAAE,CACxD,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;IAEvG,MAAM,eAAe,GAAG,CACtB,UAAoB,EAMpB,EAAE,CAAC,CAAC;QACJ,aAAa,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,EAAE;QAC9B,UAAU;KACX,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAC3F,IAAI,CAAC,WAAW,CAA6B,qBAAqB,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC,CACjG,CAAC;IACF,MAAM,WAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;IAClD,CAAC,MAAM,OAAO,CAAC,GAA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