@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.
Files changed (85) hide show
  1. package/LICENSE.txt +206 -0
  2. package/README.md +158 -0
  3. package/lib/commands/cml/convert/prod-cfg-rules.d.ts +29 -0
  4. package/lib/commands/cml/convert/prod-cfg-rules.js +226 -0
  5. package/lib/commands/cml/convert/prod-cfg-rules.js.map +1 -0
  6. package/lib/commands/cml/import/as-expression-set.d.ts +18 -0
  7. package/lib/commands/cml/import/as-expression-set.js +184 -0
  8. package/lib/commands/cml/import/as-expression-set.js.map +1 -0
  9. package/lib/index.d.ts +2 -0
  10. package/lib/index.js +17 -0
  11. package/lib/index.js.map +1 -0
  12. package/lib/shared/bre-rules-generator.d.ts +20 -0
  13. package/lib/shared/bre-rules-generator.js +497 -0
  14. package/lib/shared/bre-rules-generator.js.map +1 -0
  15. package/lib/shared/cml.d.ts +2 -0
  16. package/lib/shared/cml.js +13 -0
  17. package/lib/shared/cml.js.map +1 -0
  18. package/lib/shared/constants/constants.d.ts +94 -0
  19. package/lib/shared/constants/constants.js +109 -0
  20. package/lib/shared/constants/constants.js.map +1 -0
  21. package/lib/shared/grouping.d.ts +4 -0
  22. package/lib/shared/grouping.js +88 -0
  23. package/lib/shared/grouping.js.map +1 -0
  24. package/lib/shared/models.d.ts +65 -0
  25. package/lib/shared/models.js +2 -0
  26. package/lib/shared/models.js.map +1 -0
  27. package/lib/shared/pcm-generator.d.ts +57 -0
  28. package/lib/shared/pcm-generator.js +418 -0
  29. package/lib/shared/pcm-generator.js.map +1 -0
  30. package/lib/shared/pcm-products.d.ts +14 -0
  31. package/lib/shared/pcm-products.js +125 -0
  32. package/lib/shared/pcm-products.js.map +1 -0
  33. package/lib/shared/pcm-products.types.d.ts +99 -0
  34. package/lib/shared/pcm-products.types.js +2 -0
  35. package/lib/shared/pcm-products.types.js.map +1 -0
  36. package/lib/shared/types/association.d.ts +15 -0
  37. package/lib/shared/types/association.js +64 -0
  38. package/lib/shared/types/association.js.map +1 -0
  39. package/lib/shared/types/base/annotated-cml-element-w-attributes.d.ts +10 -0
  40. package/lib/shared/types/base/annotated-cml-element-w-attributes.js +36 -0
  41. package/lib/shared/types/base/annotated-cml-element-w-attributes.js.map +1 -0
  42. package/lib/shared/types/base/annotated-cml-element.d.ts +9 -0
  43. package/lib/shared/types/base/annotated-cml-element.js +39 -0
  44. package/lib/shared/types/base/annotated-cml-element.js.map +1 -0
  45. package/lib/shared/types/base/types.d.ts +2 -0
  46. package/lib/shared/types/base/types.js +18 -0
  47. package/lib/shared/types/base/types.js.map +1 -0
  48. package/lib/shared/types/cml-attribute.d.ts +17 -0
  49. package/lib/shared/types/cml-attribute.js +84 -0
  50. package/lib/shared/types/cml-attribute.js.map +1 -0
  51. package/lib/shared/types/cml-constraint.d.ts +50 -0
  52. package/lib/shared/types/cml-constraint.js +277 -0
  53. package/lib/shared/types/cml-constraint.js.map +1 -0
  54. package/lib/shared/types/cml-domain.d.ts +25 -0
  55. package/lib/shared/types/cml-domain.js +132 -0
  56. package/lib/shared/types/cml-domain.js.map +1 -0
  57. package/lib/shared/types/cml-model.d.ts +39 -0
  58. package/lib/shared/types/cml-model.js +153 -0
  59. package/lib/shared/types/cml-model.js.map +1 -0
  60. package/lib/shared/types/cml-relation.d.ts +31 -0
  61. package/lib/shared/types/cml-relation.js +118 -0
  62. package/lib/shared/types/cml-relation.js.map +1 -0
  63. package/lib/shared/types/cml-type.d.ts +22 -0
  64. package/lib/shared/types/cml-type.js +111 -0
  65. package/lib/shared/types/cml-type.js.map +1 -0
  66. package/lib/shared/types/sobject.d.ts +13 -0
  67. package/lib/shared/types/sobject.js +2 -0
  68. package/lib/shared/types/sobject.js.map +1 -0
  69. package/lib/shared/types/types.d.ts +8 -0
  70. package/lib/shared/types/types.js +24 -0
  71. package/lib/shared/types/types.js.map +1 -0
  72. package/lib/shared/utils/association.utils.d.ts +61 -0
  73. package/lib/shared/utils/association.utils.js +175 -0
  74. package/lib/shared/utils/association.utils.js.map +1 -0
  75. package/lib/shared/utils/common.utils.d.ts +191 -0
  76. package/lib/shared/utils/common.utils.js +338 -0
  77. package/lib/shared/utils/common.utils.js.map +1 -0
  78. package/messages/call.external.service.md +20 -0
  79. package/messages/cml.convert.prod-cfg-rules.md +59 -0
  80. package/messages/cml.import.as-expression-set.md +32 -0
  81. package/messages/connect.org.md +19 -0
  82. package/messages/hello.world.md +29 -0
  83. package/oclif.lock +8313 -0
  84. package/oclif.manifest.json +209 -0
  85. package/package.json +227 -0
@@ -0,0 +1,191 @@
1
+ import { CmlModel, CmlRelation, CmlType } from '../types/types.js';
2
+ export type Logger = {
3
+ info: (msg: string) => void;
4
+ warn: (msg: string) => void;
5
+ error: (msg: string) => void;
6
+ };
7
+ export declare function isSameIds(id1: string | null | undefined, id2: string | null | undefined): boolean;
8
+ /**
9
+ * Checks whether the passed parameter is specifically undefined or null and not an empty string.
10
+ *
11
+ * @param {String} value The string to check
12
+ * @returns {Boolean} Whether value is undefined or null
13
+ */
14
+ export declare function isUndefinedOrNull(value: unknown): boolean;
15
+ /**
16
+ * Checks if the input value is undefined, null, empty array and object.
17
+ *
18
+ * @param {String} value input string to evaluate
19
+ * @returns {boolean} return true for undefined, null or empty string otherwise false
20
+ */
21
+ export declare function isEmpty(value: unknown): boolean;
22
+ /**
23
+ * Determines if item is an object
24
+ *
25
+ * @param {*} item The item in question of being an object
26
+ * @returns {Boolean} Whether item is an object or not
27
+ */
28
+ export declare function isObject(item: unknown): boolean;
29
+ /**
30
+ * Capitalizes the first letter in a string.
31
+ *
32
+ * @param string - string to capitalize
33
+ * @returns {string} - capitalized version of the string.
34
+ */
35
+ export declare function capitalizeFirstLetter(string: string): string;
36
+ /**
37
+ * Generates a random uuid (Version 4 in rfc4122)
38
+ * Copied the method from ui-industries-epc-components
39
+ *
40
+ * @returns {string} a UUID string
41
+ */
42
+ export declare function uuid(): string;
43
+ /**
44
+ * Finds an entry in a Map based on a specified key-value pair.
45
+ *
46
+ * @param {Map} map - The map to search through, where values are objects.
47
+ * @param {string} key - The key to match within each entry's object.
48
+ * @param {*} value - The value to match for the specified key.
49
+ * @returns {Object|undefined} - The first entry in the map where the specified key has the given value, or `undefined` if no match is found.
50
+ */
51
+ export declare function findInMap<T>(map: Map<string, T>, key: string, value: unknown): T | undefined;
52
+ /**
53
+ * Checks that name is valid - it should have only alphanumeric chars and underscores and should start with a letter
54
+ *
55
+ * @param name - string to validate
56
+ * @returns {boolean} - whether name is valid or not
57
+ */
58
+ export declare function isNameValid(name: string): boolean;
59
+ /**
60
+ * Checks if a given name is already used in the model.
61
+ *
62
+ * @param {Object} model - The model containing existing types.
63
+ * @param {string} name - The name to check for uniqueness.
64
+ * @param {Map} existingProductIdsToTypes - A map of existing type names to types that have been created but not yet saved to the model.
65
+ * @returns {boolean} - Returns true if the name is not used, otherwise false.
66
+ */
67
+ export declare function isTypeNameUnique(model: CmlModel, name: string, existingProductIdsToTypes: Map<string, CmlType>): boolean;
68
+ /**
69
+ * Checks if a given relation name is unique within a specific type.
70
+ *
71
+ * @param {Object} type - The type object containing existing relations.
72
+ * @param {string} name - The name of the relation to check.
73
+ * @param {Map} existingPrcIdsToRelations - A map of existing relation names to relations that have been created but not yet saved to the model.
74
+ * @returns {boolean} - Returns true if the relation name is unique (not already used), otherwise false.
75
+ */
76
+ export declare function isRelationNameUnique(type: CmlType, name: string, existingPrcIdsToRelations: Map<string, CmlRelation>): boolean;
77
+ /**
78
+ * Checks that name length is 80 or fewer chars
79
+ *
80
+ * @param name - string to validate
81
+ * @returns {boolean} - whether name is valid or not
82
+ */
83
+ export declare function isNameLengthValid(name: string): boolean;
84
+ /**
85
+ * Checks if value is an integer
86
+ *
87
+ * @param value - string to validate
88
+ * @returns {boolean} - whether value is an integer or not
89
+ */
90
+ export declare function isInteger(value: string): boolean;
91
+ /**
92
+ * Checks if value is a double
93
+ *
94
+ * @param value - string to validate
95
+ * @returns {boolean} - whether value is a double or not
96
+ */
97
+ export declare function isDouble(value: string): boolean;
98
+ /**
99
+ * Checks if value is a boolean
100
+ *
101
+ * @param value - string to validate
102
+ * @returns {boolean} - whether value is a boolean or not
103
+ */
104
+ export declare function isBoolean(value: string): boolean;
105
+ /**
106
+ * Checks if value is a date
107
+ *
108
+ * @param value - string to validate
109
+ * @returns {boolean} - whether value is a date or not
110
+ */
111
+ export declare function isDate(value: string): boolean;
112
+ /**
113
+ * Checks if value is a string
114
+ *
115
+ * @param value - string to validate
116
+ * @returns {boolean} - whether value is a string or not
117
+ */
118
+ export declare function isString(value: string): boolean;
119
+ /**
120
+ * Checks if the given value is a Date object.
121
+ *
122
+ * @param {*} d - The value to check.
123
+ * @returns {boolean} True if the value is an instance of Date, otherwise false.
124
+ */
125
+ export declare function isDateType(d: unknown): boolean;
126
+ /**
127
+ * Determines whether a given CML data type requires scale precision.
128
+ *
129
+ * @param {string} type - The CML data type to check (e.g., "double", "decimal").
130
+ * @returns {boolean} - Returns `true` if the type requires scale precision, otherwise `false`.
131
+ */
132
+ export declare function isScaledType(type: string): boolean;
133
+ /**
134
+ * Parses a string by removing surrounding quotes (single or double).
135
+ *
136
+ * @param {string} value - The string to be parsed.
137
+ * @returns {string} - The parsed string with quotes removed, or the original string if no quotes are found.
138
+ */
139
+ export declare function parseString(value: string): string;
140
+ /**
141
+ * Parses a date string into a Date object or returns the original string if invalid
142
+ *
143
+ * We return the original string because it may be a CML constant variable reference
144
+ *
145
+ * @param {string} stringValue - A date string in the format "YYYY-MM-DD"
146
+ * @returns {Date|string} A valid Date object if parsing succeeds, or the original string if invalid
147
+ */
148
+ export declare function parseDate(stringValue: string): Date | string;
149
+ /**
150
+ * Parses a numeric string into a number (either integer or float).
151
+ *
152
+ * @param {string} value - The string representation of the number.
153
+ * @returns {number} - The parsed number.
154
+ * @throws {Error} - Throws an error if the value cannot be parsed as a number.
155
+ */
156
+ export declare function parseNumber(value: string): number;
157
+ /**
158
+ * Determines whether a given type is a number type.
159
+ *
160
+ * @param {string} type - The attribute type (e.g., "int", "double", "decimal").
161
+ * @returns {boolean} - True if the type is a number type, false otherwise.
162
+ */
163
+ export declare function isNumberType(type: string): boolean;
164
+ /**
165
+ * Determines whether a given type is a date type.
166
+ *
167
+ * @param {string} type - The attribute type (e.g., "date", "int").
168
+ * @returns {boolean} - True if the type is "date", false otherwise.
169
+ */
170
+ export declare function isDateDataType(type: string): boolean;
171
+ /**
172
+ * Formats a Date object to a CML-compatible date string in the format "YYYY-MM-DD".
173
+ *
174
+ * @param {Date} date - The Date object to format.
175
+ * @returns {string} The formatted date string in "YYYY-MM-DD" format, enclosed in double quotes.
176
+ */
177
+ export declare function formatToCmlDate(date: Date): string;
178
+ /**
179
+ * Formats a Date object to a user-friendly display string in the format "Month Day, Year".
180
+ *
181
+ * @param {Date} date - The Date object to format.
182
+ * @returns {string} The formatted date string in "Month Day, Year" format (e.g., "March 27, 1994").
183
+ */
184
+ export declare function formatToDisplayDate(date: Date): string;
185
+ /**
186
+ * Converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; in string to their corresponding characters.
187
+ *
188
+ * @param {string} source - The source string
189
+ * @returns {string} The string with unescaped HTML characters.
190
+ */
191
+ export declare function unescapeHtml(source: string): string;
@@ -0,0 +1,338 @@
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 { getRandomValues } from 'node:crypto';
17
+ import { CML_DATA_TYPES, CML_NUMBER_DATA_TYPES } from '../constants/constants.js';
18
+ export function isSameIds(id1, id2) {
19
+ if (!id1 || !id2) {
20
+ return false;
21
+ }
22
+ if (id1.length === id2.length) {
23
+ return id1.localeCompare(id2) === 0;
24
+ }
25
+ if (id1.length > id2.length) {
26
+ return id1.startsWith(id2);
27
+ }
28
+ return id2.startsWith(id1);
29
+ }
30
+ /**
31
+ * Checks whether the passed parameter is specifically undefined or null and not an empty string.
32
+ *
33
+ * @param {String} value The string to check
34
+ * @returns {Boolean} Whether value is undefined or null
35
+ */
36
+ export function isUndefinedOrNull(value) {
37
+ return value === undefined || value === null;
38
+ }
39
+ /**
40
+ * Checks if the input value is undefined, null, empty array and object.
41
+ *
42
+ * @param {String} value input string to evaluate
43
+ * @returns {boolean} return true for undefined, null or empty string otherwise false
44
+ */
45
+ export function isEmpty(value) {
46
+ if (value === undefined || value === null) {
47
+ return true;
48
+ }
49
+ else if (Array.isArray(value)) {
50
+ return value.length <= 0;
51
+ }
52
+ else if (isObject(value)) {
53
+ return Object.keys(value).length === 0;
54
+ }
55
+ else if (value === '') {
56
+ return true;
57
+ }
58
+ return false;
59
+ }
60
+ /**
61
+ * Determines if item is an object
62
+ *
63
+ * @param {*} item The item in question of being an object
64
+ * @returns {Boolean} Whether item is an object or not
65
+ */
66
+ export function isObject(item) {
67
+ return typeof item === 'object' && !Array.isArray(item) && !isUndefinedOrNull(item);
68
+ }
69
+ /**
70
+ * Capitalizes the first letter in a string.
71
+ *
72
+ * @param string - string to capitalize
73
+ * @returns {string} - capitalized version of the string.
74
+ */
75
+ export function capitalizeFirstLetter(string) {
76
+ return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
77
+ }
78
+ /**
79
+ * Generates a random uuid (Version 4 in rfc4122)
80
+ * Copied the method from ui-industries-epc-components
81
+ *
82
+ * @returns {string} a UUID string
83
+ */
84
+ export function uuid() {
85
+ const hexDigits = '0123456789abcdef';
86
+ const valueArray = new Uint32Array(32);
87
+ getRandomValues(valueArray);
88
+ let res = '';
89
+ for (let i = 0; i < 32; i++) {
90
+ if (i === 8 || i === 12 || i === 16 || i === 20) {
91
+ res += '_';
92
+ }
93
+ if (i === 12) {
94
+ res += '4'; // UUID version
95
+ }
96
+ else if (i === 16) {
97
+ res += hexDigits.charAt((valueArray[i] & 0x3) | 0x8); // Bits need to start with 10
98
+ }
99
+ else {
100
+ res += hexDigits.charAt(valueArray[i] & 0xf);
101
+ }
102
+ }
103
+ return res;
104
+ }
105
+ /**
106
+ * Finds an entry in a Map based on a specified key-value pair.
107
+ *
108
+ * @param {Map} map - The map to search through, where values are objects.
109
+ * @param {string} key - The key to match within each entry's object.
110
+ * @param {*} value - The value to match for the specified key.
111
+ * @returns {Object|undefined} - The first entry in the map where the specified key has the given value, or `undefined` if no match is found.
112
+ */
113
+ export function findInMap(map, key, value) {
114
+ return [...map.values()].find((entry) => entry[key] === value);
115
+ }
116
+ /**
117
+ * Checks that name is valid - it should have only alphanumeric chars and underscores and should start with a letter
118
+ *
119
+ * @param name - string to validate
120
+ * @returns {boolean} - whether name is valid or not
121
+ */
122
+ export function isNameValid(name) {
123
+ const validChars = /^[a-zA-Z0-9_]+$/;
124
+ const validFirstChar = /^[a-zA-Z]/;
125
+ return validFirstChar.test(name.charAt(0)) && validChars.test(name);
126
+ }
127
+ /**
128
+ * Checks if a given name is already used in the model.
129
+ *
130
+ * @param {Object} model - The model containing existing types.
131
+ * @param {string} name - The name to check for uniqueness.
132
+ * @param {Map} existingProductIdsToTypes - A map of existing type names to types that have been created but not yet saved to the model.
133
+ * @returns {boolean} - Returns true if the name is not used, otherwise false.
134
+ */
135
+ export function isTypeNameUnique(model, name, existingProductIdsToTypes) {
136
+ return !model.getType(name) && (!existingProductIdsToTypes || !findInMap(existingProductIdsToTypes, 'name', name));
137
+ }
138
+ /**
139
+ * Checks if a given relation name is unique within a specific type.
140
+ *
141
+ * @param {Object} type - The type object containing existing relations.
142
+ * @param {string} name - The name of the relation to check.
143
+ * @param {Map} existingPrcIdsToRelations - A map of existing relation names to relations that have been created but not yet saved to the model.
144
+ * @returns {boolean} - Returns true if the relation name is unique (not already used), otherwise false.
145
+ */
146
+ export function isRelationNameUnique(type, name, existingPrcIdsToRelations) {
147
+ return !type.getRelation(name) && (!existingPrcIdsToRelations || !findInMap(existingPrcIdsToRelations, 'name', name));
148
+ }
149
+ /**
150
+ * Checks that name length is 80 or fewer chars
151
+ *
152
+ * @param name - string to validate
153
+ * @returns {boolean} - whether name is valid or not
154
+ */
155
+ export function isNameLengthValid(name) {
156
+ return name.length <= 80;
157
+ }
158
+ /**
159
+ * Checks if value is an integer
160
+ *
161
+ * @param value - string to validate
162
+ * @returns {boolean} - whether value is an integer or not
163
+ */
164
+ export function isInteger(value) {
165
+ const num = Number(value);
166
+ return !isNaN(num) ? !value.toString().includes('.') : false;
167
+ }
168
+ /**
169
+ * Checks if value is a double
170
+ *
171
+ * @param value - string to validate
172
+ * @returns {boolean} - whether value is a double or not
173
+ */
174
+ export function isDouble(value) {
175
+ const num = Number(value);
176
+ return !isNaN(num) ? value.toString().includes('.') : false;
177
+ }
178
+ /**
179
+ * Checks if value is a boolean
180
+ *
181
+ * @param value - string to validate
182
+ * @returns {boolean} - whether value is a boolean or not
183
+ */
184
+ export function isBoolean(value) {
185
+ return value.toString().toLowerCase() === 'true' || value.toString().toLowerCase() === 'false';
186
+ }
187
+ /**
188
+ * Checks if value is a date
189
+ *
190
+ * @param value - string to validate
191
+ * @returns {boolean} - whether value is a date or not
192
+ */
193
+ export function isDate(value) {
194
+ const date = new Date(value);
195
+ return !isNaN(date.getTime());
196
+ }
197
+ /**
198
+ * Checks if value is a string
199
+ *
200
+ * @param value - string to validate
201
+ * @returns {boolean} - whether value is a string or not
202
+ */
203
+ export function isString(value) {
204
+ return typeof value === 'string';
205
+ }
206
+ /**
207
+ * Checks if the given value is a Date object.
208
+ *
209
+ * @param {*} d - The value to check.
210
+ * @returns {boolean} True if the value is an instance of Date, otherwise false.
211
+ */
212
+ export function isDateType(d) {
213
+ return d instanceof Date;
214
+ }
215
+ /**
216
+ * Determines whether a given CML data type requires scale precision.
217
+ *
218
+ * @param {string} type - The CML data type to check (e.g., "double", "decimal").
219
+ * @returns {boolean} - Returns `true` if the type requires scale precision, otherwise `false`.
220
+ */
221
+ export function isScaledType(type) {
222
+ return type === CML_DATA_TYPES.DOUBLE || type === CML_DATA_TYPES.DECIMAL;
223
+ }
224
+ /**
225
+ * Parses a string by removing surrounding quotes (single or double).
226
+ *
227
+ * @param {string} value - The string to be parsed.
228
+ * @returns {string} - The parsed string with quotes removed, or the original string if no quotes are found.
229
+ */
230
+ export function parseString(value) {
231
+ if (typeof value === 'string' &&
232
+ ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'")))) {
233
+ return value.slice(1, -1);
234
+ }
235
+ return value; // Return the original string if no surrounding quotes
236
+ }
237
+ /**
238
+ * Parses a date string into a Date object or returns the original string if invalid
239
+ *
240
+ * We return the original string because it may be a CML constant variable reference
241
+ *
242
+ * @param {string} stringValue - A date string in the format "YYYY-MM-DD"
243
+ * @returns {Date|string} A valid Date object if parsing succeeds, or the original string if invalid
244
+ */
245
+ export function parseDate(stringValue) {
246
+ const parts = stringValue.split('-');
247
+ // Ensure the format has exactly 3 parts (year, month, day)
248
+ if (parts.length !== 3) {
249
+ return stringValue;
250
+ }
251
+ // Convert parts to numbers
252
+ const [year, month, day] = parts.map(Number);
253
+ // Validate year, month, and day
254
+ if (!Number.isInteger(year) ||
255
+ !Number.isInteger(month) ||
256
+ !Number.isInteger(day) ||
257
+ month < 1 ||
258
+ month > 12 ||
259
+ day < 1 ||
260
+ day > 31) {
261
+ return stringValue;
262
+ }
263
+ // Create and validate the Date object
264
+ const date = new Date(year, month - 1, day);
265
+ // Ensure the Date object matches the input values
266
+ if (date.getFullYear() !== year || date.getMonth() + 1 !== month || date.getDate() !== day) {
267
+ return stringValue;
268
+ }
269
+ return date;
270
+ }
271
+ /**
272
+ * Parses a numeric string into a number (either integer or float).
273
+ *
274
+ * @param {string} value - The string representation of the number.
275
+ * @returns {number} - The parsed number.
276
+ * @throws {Error} - Throws an error if the value cannot be parsed as a number.
277
+ */
278
+ export function parseNumber(value) {
279
+ const parsedValue = parseFloat(value);
280
+ if (isNaN(parsedValue)) {
281
+ throw new Error(`Invalid number format: ${value}`);
282
+ }
283
+ return Number.isInteger(parsedValue) ? parseInt(value, 10) : parsedValue;
284
+ }
285
+ /**
286
+ * Determines whether a given type is a number type.
287
+ *
288
+ * @param {string} type - The attribute type (e.g., "int", "double", "decimal").
289
+ * @returns {boolean} - True if the type is a number type, false otherwise.
290
+ */
291
+ export function isNumberType(type) {
292
+ return Object.values(CML_NUMBER_DATA_TYPES).includes(type);
293
+ }
294
+ /**
295
+ * Determines whether a given type is a date type.
296
+ *
297
+ * @param {string} type - The attribute type (e.g., "date", "int").
298
+ * @returns {boolean} - True if the type is "date", false otherwise.
299
+ */
300
+ export function isDateDataType(type) {
301
+ return type === CML_DATA_TYPES.DATE;
302
+ }
303
+ /**
304
+ * Formats a Date object to a CML-compatible date string in the format "YYYY-MM-DD".
305
+ *
306
+ * @param {Date} date - The Date object to format.
307
+ * @returns {string} The formatted date string in "YYYY-MM-DD" format, enclosed in double quotes.
308
+ */
309
+ export function formatToCmlDate(date) {
310
+ const year = date.getFullYear();
311
+ const month = String(date.getMonth() + 1).padStart(2, '0');
312
+ const day = String(date.getDate()).padStart(2, '0');
313
+ return `"${year}-${month}-${day}"`;
314
+ }
315
+ /**
316
+ * Formats a Date object to a user-friendly display string in the format "Month Day, Year".
317
+ *
318
+ * @param {Date} date - The Date object to format.
319
+ * @returns {string} The formatted date string in "Month Day, Year" format (e.g., "March 27, 1994").
320
+ */
321
+ export function formatToDisplayDate(date) {
322
+ return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
323
+ }
324
+ /**
325
+ * Converts the HTML entities &amp;, &lt;, &gt;, &quot;, and &#39; in string to their corresponding characters.
326
+ *
327
+ * @param {string} source - The source string
328
+ * @returns {string} The string with unescaped HTML characters.
329
+ */
330
+ export function unescapeHtml(source) {
331
+ return source
332
+ .replace(/&amp;/g, '&')
333
+ .replace(/&gt;/g, '>')
334
+ .replace(/&lt;/g, '<')
335
+ .replace(/&quot;/g, '"')
336
+ .replace(/&#39;/g, "'");
337
+ }
338
+ //# sourceMappingURL=common.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.utils.js","sourceRoot":"","sources":["../../../src/shared/utils/common.utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAKlF,MAAM,UAAU,SAAS,CAAC,GAA8B,EAAE,GAA8B;IACtF,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACjB,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC;QAC9B,OAAO,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,OAAO,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAC,KAAc;IACpC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;Q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C,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACpD,OAAO,IAAI,IAAI,IAAI,KAAK,IAAI,GAAG,GAAG,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAU;IAC5C,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;AAC9F,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,MAAM;SACV,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;SACrB,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;SACvB,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,20 @@
1
+ # summary
2
+
3
+ Summary of a command.
4
+
5
+ # description
6
+
7
+ More information about a command. Don't repeat the summary.
8
+
9
+ # flags.name.summary
10
+
11
+ Description of a flag.
12
+
13
+ # flags.name.description
14
+
15
+ More information about a flag. Don't repeat the summary.
16
+
17
+ # examples
18
+
19
+ - <%= config.bin %> <%= command.id %>
20
+
@@ -0,0 +1,59 @@
1
+ # summary
2
+
3
+ Converts BRE based Standard Configurator rules represented as JSON to CML and saves it as a pair of CML and association files.
4
+
5
+ # description
6
+
7
+ Before you execute this command make sure to migrate you PCM or perform migration of rules within the same org.
8
+
9
+ Export BRE based Standard Configurator rules using sf data export bulk plugin and save results in a JSON file:
10
+ sf data export bulk -o breMigOrg --query "SELECT ApiName, ConfigurationRuleDefinition,Description, EffectiveFromDate, EffectiveToDate, Id, IsDeleted, Name, ProcessScope, RuleSubType, RuleType, Sequence, Status FROM ProductConfigurationRule WHERE RuleType = 'Configurator' AND ApiName = 'myTestBundle'" --output-file ./data/ProductConfigurationRules.json --result-format json --wait 10 --all-rows
11
+
12
+ This command executes following logic:
13
+
14
+ - Read SC Rules from the json file and build a list of `ConfiguratorRuleInput` to mimic the JSON structure of `ConfigurationRuleDefinition`
15
+ - Group rules by non-intersecting `Product2` IDs (CMLs can’t share products)
16
+ - For each group:
17
+ - Query PCM for related products (for bundle rules) or root definitions (for others)
18
+ - Build an in-memory representation of the CML
19
+ - Apply logic to build constraints
20
+ - Serialize the in-memory CML to a blob for import as an Expression Set, save it in a cml-api.cml file.
21
+ - Create `ExpressionSetConstraintObj` association records pointing to the `cml-api` name and write them to `cml-api_associations.csv` file.
22
+ - If multiple CML and association files are produced 1-N number will be appended to the names of files.
23
+
24
+ # flags.name.summary
25
+
26
+ Description of a flag.
27
+
28
+ # flags.name.description
29
+
30
+ More information about a flag. Don't repeat the summary.
31
+
32
+ # examples
33
+
34
+ - <%= config.bin %> <%= command.id %> --pcr-file data/ProductConfigurationRules.json --cml-api MY_TEST --workspace-dir data --target-org breMigOrg
35
+
36
+
37
+ # flags.pcr-file.summary
38
+
39
+ Name of the JSON file that contain exported standard Product Configuration Rules.
40
+
41
+ # flags.cml-api.summary
42
+
43
+ Unique CML API Name to be created.
44
+
45
+ # flags.workspace-dir.summary
46
+
47
+ Directory where working files are located, exported rules JSON and where CMLs will be created.
48
+
49
+ # flags.target-org.summary
50
+
51
+ Alias of the source target org.
52
+
53
+ # flags.additional-products.summary
54
+
55
+ Comma-separated list of additional product IDs for which CML types should be generated.
56
+
57
+ # flags.products-file.summary
58
+
59
+ Name of the JSON file that contain exported Products from PCM (if not present products will be fetched automatically).
@@ -0,0 +1,32 @@
1
+ # summary
2
+
3
+ Imports CML and associations to the target org
4
+
5
+ # description
6
+
7
+ Review CM created by conversion command before doing import.
8
+ This command executes following logic:
9
+ - Import one CML at a time
10
+ - Upsert the Expression Set using the `cml-api` name
11
+ - Read and upsert `ExpressionSetConstraintObj` rows from the `cml-api_associations.csv` file (resolving FKs)
12
+ - Upload the CML blob
13
+
14
+ # examples
15
+
16
+ - <%= config.bin %> <%= command.id %> --cml-api MY_TEST --context-definition PricingTransactionCD2 --workspace-dir data --target-org tgtOrg
17
+
18
+ # flags.context-definition.summary
19
+
20
+ Context Definition name to be assocciated with the CML.
21
+
22
+ # flags.cml-api.summary
23
+
24
+ Unique CML API Name to be created.
25
+
26
+ # flags.workspace-dir.summary
27
+
28
+ Directory where converted CML and assocciations csv files are located.
29
+
30
+ # flags.target-org.summary
31
+
32
+ Alias of the destination target org.
@@ -0,0 +1,19 @@
1
+ # summary
2
+
3
+ Summary of a command.
4
+
5
+ # description
6
+
7
+ More information about a command. Don't repeat the summary.
8
+
9
+ # flags.name.summary
10
+
11
+ Description of a flag.
12
+
13
+ # flags.name.description
14
+
15
+ More information about a flag. Don't repeat the summary.
16
+
17
+ # examples
18
+
19
+ - <%= config.bin %> <%= command.id %>