@contrail/cli 3.6.0-alpha-8-alpha.252e3f3 → 3.6.0-alpha-8-alpha.2ba81bf
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/README.md +1 -1
- package/node_modules/@contrail/entity-compare/package.json +6 -3
- package/node_modules/@contrail/loader/lib/common/conditional-columns.js +1 -1
- package/node_modules/@contrail/loader/lib/constants.d.ts +0 -8
- package/node_modules/@contrail/loader/lib/constants.js +1 -9
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.d.ts +0 -4
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.js +0 -57
- package/node_modules/@contrail/loader/lib/entities-v2/linesheet-v2/item-processor.spec.js +34 -492
- package/node_modules/@contrail/loader/lib/pipeline/validate.js +52 -2
- package/node_modules/@contrail/loader/lib/pipeline/validate.spec.js +85 -0
- package/node_modules/@contrail/loader/package.json +2 -2
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/index.js +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/package.json +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/image-search.d.ts +0 -34
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/image-search.js +0 -42
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/index.d.ts +0 -1
- package/node_modules/@contrail/org-config-migration/node_modules/@contrail/sdk/lib/image-search/index.js +0 -17
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ $ npm install -g @contrail/cli
|
|
|
17
17
|
$ contrail COMMAND
|
|
18
18
|
running command...
|
|
19
19
|
$ contrail (--version)
|
|
20
|
-
@contrail/cli/3.6.0-alpha-8-alpha.
|
|
20
|
+
@contrail/cli/3.6.0-alpha-8-alpha.2ba81bf linux-x64 node-v24.22.1
|
|
21
21
|
$ contrail --help [COMMAND]
|
|
22
22
|
USAGE
|
|
23
23
|
$ contrail COMMAND
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/entity-compare",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Library for comparing entities.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
"author": "",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@contrail/telemetry": "^2.0.0",
|
|
18
17
|
"@contrail/util": "^1.3.0",
|
|
19
18
|
"es6-promisify": "^6.1.1"
|
|
20
19
|
},
|
|
@@ -26,7 +25,8 @@
|
|
|
26
25
|
"ts-jest": "^29.1.1",
|
|
27
26
|
"tslint": "^5.11.0",
|
|
28
27
|
"tslint-config-prettier": "^1.18.0",
|
|
29
|
-
"typescript": "^5.0.0"
|
|
28
|
+
"typescript": "^5.0.0",
|
|
29
|
+
"@contrail/telemetry": "^2.0.0"
|
|
30
30
|
},
|
|
31
31
|
"jest": {
|
|
32
32
|
"moduleFileExtensions": [
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"coverageDirectory": "../coverage",
|
|
43
43
|
"testEnvironment": "node"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@contrail/telemetry": "^2.0.0"
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -66,7 +66,7 @@ class ColumnDefinitionEvaluator {
|
|
|
66
66
|
static getValue(value, row) {
|
|
67
67
|
if (util_1.StringUtil.isString(value) && value.includes('{')) {
|
|
68
68
|
try {
|
|
69
|
-
const val = evaluate(util_1.StringUtil.parseVariables(value, row, true));
|
|
69
|
+
const val = evaluate(util_1.StringUtil.parseVariables(String(value), row, true));
|
|
70
70
|
return val;
|
|
71
71
|
}
|
|
72
72
|
catch {
|
|
@@ -13,16 +13,8 @@ export declare const ENTITY_PROCESSOR_ERRORS: {
|
|
|
13
13
|
readonly SINGLE_LOAD_TYPE: (entityType: string) => string;
|
|
14
14
|
};
|
|
15
15
|
export declare const ITEM_PROCESSOR_ERRORS: {
|
|
16
|
-
readonly LOAD_TYPE_INVALID: "\"loadType\" must be either of values [\"ITEM\", \"PROJECT_ITEM\", \"ASSORTMENT\"] in the config file";
|
|
17
|
-
readonly TYPEPATH_INVALID: "\"typePath\" must be \"item\" or \"item:<subtypepath>\" in the config file";
|
|
18
16
|
readonly FAMILY_ID_EMPTY: "itemFamilyFederatedId is null or undefined or empty in the CSV file";
|
|
19
17
|
readonly CONFLICTING_IDS: (ids: any) => string;
|
|
20
18
|
};
|
|
21
19
|
export declare const FEDERATED_ID_FETCH_MAX_URL_BYTES = 4000;
|
|
22
20
|
export declare const FEDERATED_ID_FETCH_MAX_COUNT = 200;
|
|
23
|
-
export declare const ITEM_PROCESSOR_WARNINGS: {
|
|
24
|
-
readonly OPTIONNAME_UNMAPPED: "\"optionName\" is not found in the federatedMapping config, conditionalColumns config, or as a header in the CSV file.";
|
|
25
|
-
readonly OPTIONNAME_NOT_FOUND: (optionName: string) => string;
|
|
26
|
-
readonly OPTION_FEDERATED_ID_UNMAPPED: "\"itemOptionFederatedId\" is not found in the federatedMapping config, conditionalColumns config, or as a header in the CSV file.";
|
|
27
|
-
readonly OPTION_FEDERATED_ID_NOT_FOUND: (itemOptionFederatedId: string) => string;
|
|
28
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.FEDERATED_ID_FETCH_MAX_COUNT = exports.FEDERATED_ID_FETCH_MAX_URL_BYTES = exports.ITEM_PROCESSOR_ERRORS = exports.ENTITY_PROCESSOR_ERRORS = exports.CUSTOM_ENTITY_PROCESSOR_ERRORS = exports.COLOR_PROCESSOR_ERRORS = void 0;
|
|
4
4
|
exports.COLOR_PROCESSOR_ERRORS = {
|
|
5
5
|
TYPEPATH_MISSING: '"typePath" with value "color" is required property but is not found in the federatedMapping config, conditionalColumns config, or as a header in the CSV file. Please add a mapping "typePath" mapping with value "color" with one of these methods, then try the load again.',
|
|
6
6
|
};
|
|
@@ -16,16 +16,8 @@ exports.ENTITY_PROCESSOR_ERRORS = {
|
|
|
16
16
|
SINGLE_LOAD_TYPE: (entityType) => `"loadType" must be single value "${entityType}" in the config file`,
|
|
17
17
|
};
|
|
18
18
|
exports.ITEM_PROCESSOR_ERRORS = {
|
|
19
|
-
LOAD_TYPE_INVALID: '"loadType" must be either of values ["ITEM", "PROJECT_ITEM", "ASSORTMENT"] in the config file',
|
|
20
|
-
TYPEPATH_INVALID: '"typePath" must be "item" or "item:<subtypepath>" in the config file',
|
|
21
19
|
FAMILY_ID_EMPTY: 'itemFamilyFederatedId is null or undefined or empty in the CSV file',
|
|
22
20
|
CONFLICTING_IDS: (ids) => `Found conflicting family federated Ids: ${ids}`,
|
|
23
21
|
};
|
|
24
22
|
exports.FEDERATED_ID_FETCH_MAX_URL_BYTES = 4000;
|
|
25
23
|
exports.FEDERATED_ID_FETCH_MAX_COUNT = 200;
|
|
26
|
-
exports.ITEM_PROCESSOR_WARNINGS = {
|
|
27
|
-
OPTIONNAME_UNMAPPED: '"optionName" is not found in the federatedMapping config, conditionalColumns config, or as a header in the CSV file.',
|
|
28
|
-
OPTIONNAME_NOT_FOUND: (optionName) => `"${optionName}" column not found in the CSV file`,
|
|
29
|
-
OPTION_FEDERATED_ID_UNMAPPED: '"itemOptionFederatedId" is not found in the federatedMapping config, conditionalColumns config, or as a header in the CSV file.',
|
|
30
|
-
OPTION_FEDERATED_ID_NOT_FOUND: (itemOptionFederatedId) => `"${itemOptionFederatedId}" column not found in the CSV file`,
|
|
31
|
-
};
|
|
@@ -24,10 +24,6 @@ export declare class ItemProcessor extends BaseProcessorV2 {
|
|
|
24
24
|
generalErrors: GeneralIssueDetails[];
|
|
25
25
|
generalWarnings: GeneralIssueDetails[];
|
|
26
26
|
};
|
|
27
|
-
private static validateLoadType;
|
|
28
|
-
private static validateTypePathMapping;
|
|
29
|
-
private static validateOptionNameMapping;
|
|
30
|
-
private static validateItemOptionFederatedIdMapping;
|
|
31
27
|
private static validateFederatedIds;
|
|
32
28
|
private static prepareDataWithConditionalValues;
|
|
33
29
|
private static findConditionalColumn;
|
|
@@ -59,66 +59,9 @@ class ItemProcessor extends base_processor_v2_1.BaseProcessorV2 {
|
|
|
59
59
|
if (returnImmediately) {
|
|
60
60
|
return { errors, warnings, generalErrors, generalWarnings };
|
|
61
61
|
}
|
|
62
|
-
this.validateLoadType(config, generalErrors);
|
|
63
|
-
this.validateTypePathMapping(data, generalErrors);
|
|
64
|
-
this.validateOptionNameMapping(config, csvHeaders, generalWarnings);
|
|
65
|
-
this.validateItemOptionFederatedIdMapping(config, csvHeaders, generalWarnings);
|
|
66
62
|
this.validateFederatedIds(data, config, errors, generalErrors, csvHeaders);
|
|
67
63
|
return { errors, warnings, generalErrors, generalWarnings };
|
|
68
64
|
}
|
|
69
|
-
static validateLoadType(config, generalErrors) {
|
|
70
|
-
if (config?.loadType?.length &&
|
|
71
|
-
!config.loadType.every((type) => [entity_types_1.LoadType.ITEM, entity_types_1.LoadType.PROJECT_ITEM, entity_types_1.LoadType.ASSORTMENT].includes(type))) {
|
|
72
|
-
generalErrors.push({
|
|
73
|
-
message: constants_1.ITEM_PROCESSOR_ERRORS.LOAD_TYPE_INVALID,
|
|
74
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
static validateTypePathMapping(data, generalErrors) {
|
|
79
|
-
const hasCorrectTypePath = data.every((row) => row.typePath === 'item' || (row.typePath?.startsWith('item:') && row.typePath?.split(':')[1]?.length > 0));
|
|
80
|
-
if (!hasCorrectTypePath) {
|
|
81
|
-
generalErrors.push({
|
|
82
|
-
message: constants_1.ITEM_PROCESSOR_ERRORS.TYPEPATH_INVALID,
|
|
83
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
static validateOptionNameMapping(config, csvHeaders, generalWarnings) {
|
|
88
|
-
const optionNameInConditional = config?.conditionalColumns?.some((column) => column.toProperty === 'optionName');
|
|
89
|
-
const optionNameInFederatedMapping = config?.federatedMappings?.optionName;
|
|
90
|
-
const optionNameInCSV = csvHeaders.includes('optionName');
|
|
91
|
-
if (!optionNameInFederatedMapping && !optionNameInCSV && !optionNameInConditional) {
|
|
92
|
-
generalWarnings.push({
|
|
93
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
94
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else if (optionNameInFederatedMapping && !csvHeaders.includes(config.federatedMappings?.optionName)) {
|
|
98
|
-
generalWarnings.push({
|
|
99
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_NOT_FOUND(config.federatedMappings?.optionName),
|
|
100
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
static validateItemOptionFederatedIdMapping(config, csvHeaders, generalWarnings) {
|
|
105
|
-
const optionFederatedIdInConditional = config?.conditionalColumns?.some((column) => column.toProperty === 'itemOptionFederatedId');
|
|
106
|
-
const optionFederatedIdInFederatedMapping = config?.federatedMappings?.itemOptionFederatedId;
|
|
107
|
-
const optionFederatedIdInCSV = csvHeaders.includes('itemOptionFederatedId');
|
|
108
|
-
if (!optionFederatedIdInFederatedMapping && !optionFederatedIdInCSV && !optionFederatedIdInConditional) {
|
|
109
|
-
generalWarnings.push({
|
|
110
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_UNMAPPED,
|
|
111
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
else if (optionFederatedIdInFederatedMapping &&
|
|
115
|
-
!csvHeaders.includes(config.federatedMappings?.itemOptionFederatedId)) {
|
|
116
|
-
generalWarnings.push({
|
|
117
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_NOT_FOUND(config.federatedMappings?.itemOptionFederatedId),
|
|
118
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
65
|
static validateFederatedIds(data, config, errors, generalErrors, csvHeaders) {
|
|
123
66
|
const processedData = this.prepareDataWithConditionalValues(data, config);
|
|
124
67
|
this.validateEmptyItemFamilyFederatedIds(processedData, config, errors);
|
|
@@ -21,514 +21,56 @@ describe('Item Processor', () => {
|
|
|
21
21
|
],
|
|
22
22
|
};
|
|
23
23
|
describe('validateLoadFile', () => {
|
|
24
|
-
it('should
|
|
25
|
-
const
|
|
24
|
+
it('should throw error for the duplicate itemOptionFederatedId', () => {
|
|
25
|
+
const lineSheetData = [
|
|
26
26
|
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
input_col_2: 'value_2',
|
|
31
|
-
typePath: 'item',
|
|
27
|
+
itemName: 'foo',
|
|
28
|
+
itemFamilyFederatedId: '1',
|
|
29
|
+
itemOptionFederatedId: '11',
|
|
32
30
|
},
|
|
33
31
|
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
input_col_2: 'value_4',
|
|
38
|
-
typePath: 'item',
|
|
32
|
+
itemName: 'foo',
|
|
33
|
+
itemFamilyFederatedId: '1',
|
|
34
|
+
itemOptionFederatedId: '11',
|
|
39
35
|
},
|
|
40
36
|
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
input_col_2: 'value_6',
|
|
45
|
-
typePath: 'item',
|
|
37
|
+
itemName: 'bar',
|
|
38
|
+
itemFamilyFederatedId: '2',
|
|
39
|
+
itemOptionFederatedId: '12',
|
|
46
40
|
},
|
|
47
41
|
];
|
|
48
42
|
const config = {
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
loadType: ['ITEM'],
|
|
44
|
+
federatedMappings: {
|
|
45
|
+
name: 'itemName',
|
|
46
|
+
itemFamilyFederatedId: 'itemFamilyFederatedId',
|
|
47
|
+
},
|
|
51
48
|
};
|
|
52
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(
|
|
53
|
-
expect(result.
|
|
49
|
+
const result = item_processor_1.ItemProcessor.validateLoadFile(lineSheetData, config);
|
|
50
|
+
expect(result.errors).toEqual([
|
|
54
51
|
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
]);
|
|
59
|
-
});
|
|
60
|
-
describe('validate typepath', () => {
|
|
61
|
-
it('should throw general error if typePath is incorrect', () => {
|
|
62
|
-
const data = [
|
|
63
|
-
{
|
|
64
|
-
name: 'item1',
|
|
65
|
-
family_federated_id: 'family_1',
|
|
66
|
-
input_col_1: 'value_1',
|
|
67
|
-
input_col_2: 'value_2',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
name: 'item2',
|
|
71
|
-
family_federated_id: 'family_2',
|
|
72
|
-
input_col_1: 'value_3',
|
|
73
|
-
input_col_2: 'value_4',
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: 'item3',
|
|
77
|
-
family_federated_id: 'family_3',
|
|
78
|
-
input_col_1: 'value_5',
|
|
79
|
-
input_col_2: 'value_6',
|
|
80
|
-
},
|
|
81
|
-
];
|
|
82
|
-
const config = {
|
|
83
|
-
...loaderProcess,
|
|
84
|
-
conditionalColumns: [
|
|
52
|
+
rowNumber: 2,
|
|
53
|
+
columnIssues: [
|
|
85
54
|
{
|
|
86
|
-
|
|
87
|
-
|
|
55
|
+
columnName: 'itemOptionFederatedId',
|
|
56
|
+
message: 'Duplicate federatedId found: 11',
|
|
57
|
+
issueType: entity_types_1.IssueType.DUPLICATE_FEDERATED_ID,
|
|
58
|
+
data: '{"itemName":"foo","itemFamilyFederatedId":"1","itemOptionFederatedId":"11"}',
|
|
88
59
|
},
|
|
89
60
|
],
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
message: constants_1.ITEM_PROCESSOR_ERRORS.TYPEPATH_INVALID,
|
|
95
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
96
|
-
},
|
|
97
|
-
]);
|
|
98
|
-
});
|
|
99
|
-
it('should throw error if typepath is present in the config file but have incorrect typePath', () => {
|
|
100
|
-
const data = [
|
|
101
|
-
{
|
|
102
|
-
name: 'item1',
|
|
103
|
-
family_federated_id: 'family_1',
|
|
104
|
-
input_col_1: 'value_1',
|
|
105
|
-
input_col_2: 'value_2',
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: 'item2',
|
|
109
|
-
family_federated_id: 'family_2',
|
|
110
|
-
input_col_1: 'value_3',
|
|
111
|
-
input_col_2: 'value_4',
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: 'item3',
|
|
115
|
-
family_federated_id: 'family_3',
|
|
116
|
-
input_col_1: 'value_5',
|
|
117
|
-
input_col_2: 'value_6',
|
|
118
|
-
},
|
|
119
|
-
];
|
|
120
|
-
const config = {
|
|
121
|
-
...loaderProcess,
|
|
122
|
-
conditionalColumns: [
|
|
123
|
-
{
|
|
124
|
-
toProperty: 'typePath',
|
|
125
|
-
default: 'custom-entity1',
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
};
|
|
129
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
130
|
-
expect(result.generalErrors).toEqual([
|
|
131
|
-
{
|
|
132
|
-
message: constants_1.ITEM_PROCESSOR_ERRORS.TYPEPATH_INVALID,
|
|
133
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
134
|
-
},
|
|
135
|
-
]);
|
|
136
|
-
});
|
|
137
|
-
it('should throw error if typepath is present in the csv header but have incorrect typePath', () => {
|
|
138
|
-
const data = [
|
|
139
|
-
{
|
|
140
|
-
name: 'item1',
|
|
141
|
-
family_federated_id: 'family_1',
|
|
142
|
-
input_col_1: 'value_1',
|
|
143
|
-
input_col_2: 'value_2',
|
|
144
|
-
typePath: 'custom-entity1',
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: 'item2',
|
|
148
|
-
family_federated_id: 'family_2',
|
|
149
|
-
input_col_1: 'value_3',
|
|
150
|
-
input_col_2: 'value_4',
|
|
151
|
-
typePath: 'custom-entity1',
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
name: 'item3',
|
|
155
|
-
family_federated_id: 'family_3',
|
|
156
|
-
input_col_1: 'value_5',
|
|
157
|
-
input_col_2: 'value_6',
|
|
158
|
-
typePath: 'custom-entity1',
|
|
159
|
-
},
|
|
160
|
-
];
|
|
161
|
-
const config = {
|
|
162
|
-
...loaderProcess,
|
|
163
|
-
conditionalColumns: [],
|
|
164
|
-
};
|
|
165
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
166
|
-
expect(result.generalErrors).toEqual([
|
|
167
|
-
{
|
|
168
|
-
message: constants_1.ITEM_PROCESSOR_ERRORS.TYPEPATH_INVALID,
|
|
169
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
170
|
-
},
|
|
171
|
-
]);
|
|
172
|
-
});
|
|
173
|
-
it('should throw error if typepath is not present in csv header', () => {
|
|
174
|
-
const data = [
|
|
175
|
-
{
|
|
176
|
-
name: 'item1',
|
|
177
|
-
family_federated_id: 'family_1',
|
|
178
|
-
input_col_1: 'value_1',
|
|
179
|
-
input_col_2: 'value_2',
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
name: 'item2',
|
|
183
|
-
family_federated_id: 'family_2',
|
|
184
|
-
input_col_1: 'value_3',
|
|
185
|
-
input_col_2: 'value_4',
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
name: 'item3',
|
|
189
|
-
family_federated_id: 'family_3',
|
|
190
|
-
input_col_1: 'value_5',
|
|
191
|
-
input_col_2: 'value_6',
|
|
192
|
-
},
|
|
193
|
-
];
|
|
194
|
-
const config = {
|
|
195
|
-
...loaderProcess,
|
|
196
|
-
conditionalColumns: [],
|
|
197
|
-
};
|
|
198
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
199
|
-
expect(result.generalErrors).toEqual([
|
|
200
|
-
{
|
|
201
|
-
message: constants_1.ITEM_PROCESSOR_ERRORS.TYPEPATH_INVALID,
|
|
202
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
203
|
-
},
|
|
204
|
-
]);
|
|
205
|
-
});
|
|
206
|
-
it('should not throw error if every row has a valid typePath', () => {
|
|
207
|
-
const data = [
|
|
208
|
-
{
|
|
209
|
-
name: 'item1',
|
|
210
|
-
family_federated_id: 'family_1',
|
|
211
|
-
input_col_1: 'value_1',
|
|
212
|
-
input_col_2: 'value_2',
|
|
213
|
-
typePath: 'item',
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
name: 'item2',
|
|
217
|
-
family_federated_id: 'family_2',
|
|
218
|
-
input_col_1: 'value_3',
|
|
219
|
-
input_col_2: 'value_4',
|
|
220
|
-
typePath: 'item:material:fabric:yarn',
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
name: 'item3',
|
|
224
|
-
family_federated_id: 'family_3',
|
|
225
|
-
input_col_1: 'value_5',
|
|
226
|
-
input_col_2: 'value_6',
|
|
227
|
-
typePath: 'item:material:fabric:leather',
|
|
228
|
-
},
|
|
229
|
-
];
|
|
230
|
-
const config = {
|
|
231
|
-
...loaderProcess,
|
|
232
|
-
conditionalColumns: [],
|
|
233
|
-
};
|
|
234
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
235
|
-
expect(result.generalErrors).toEqual([]);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
describe('validate itemOptionFederatedId', () => {
|
|
239
|
-
it('should validate optionFederatedId in conditional columns', () => {
|
|
240
|
-
const data = [{ name: 'test1', optionName: 'Test Option 1' }];
|
|
241
|
-
const config = {
|
|
242
|
-
...loaderProcess,
|
|
243
|
-
conditionalColumns: [
|
|
244
|
-
{
|
|
245
|
-
toProperty: 'itemFamilyFederatedId',
|
|
246
|
-
default: 'test-{name}',
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
toProperty: 'itemOptionFederatedId',
|
|
250
|
-
default: 'test-{optionName}',
|
|
251
|
-
},
|
|
252
|
-
],
|
|
253
|
-
};
|
|
254
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
255
|
-
expect(result.generalWarnings).not.toContainEqual({
|
|
256
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_UNMAPPED,
|
|
257
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
it('should validate federatedId in CSV data', () => {
|
|
261
|
-
const data = [
|
|
262
|
-
{
|
|
263
|
-
itemFamilyFederatedId: 'test1',
|
|
264
|
-
itemOptionFederatedId: 'option1',
|
|
265
|
-
name: 'Test 1',
|
|
266
|
-
},
|
|
267
|
-
];
|
|
268
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, loaderProcess);
|
|
269
|
-
expect(result.generalErrors).not.toContainEqual({
|
|
270
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_UNMAPPED,
|
|
271
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
it('should validate federatedId in federatedMapping', () => {
|
|
275
|
-
const data = [{ code: 'test1', option: 'option1', name: 'Test 1' }];
|
|
276
|
-
const config = {
|
|
277
|
-
...loaderProcess,
|
|
278
|
-
federatedMappings: {
|
|
279
|
-
itemFamilyFederatedId: 'code',
|
|
280
|
-
itemOptionFederatedId: 'option',
|
|
281
|
-
},
|
|
282
|
-
};
|
|
283
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
284
|
-
expect(result.generalErrors).not.toContainEqual({
|
|
285
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_UNMAPPED,
|
|
286
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
it('should warning error if itemOptionfederatedId is missing in federatedmapping config, csv header and conditional column', () => {
|
|
290
|
-
const data = [{ name: 'color1', option: 'option1' }];
|
|
291
|
-
const config = {
|
|
292
|
-
id: 'mock-loader-process-id',
|
|
293
|
-
loadFileId: 'mock-load-file-id',
|
|
294
|
-
loadType: [entity_types_1.LoadType.COLOR],
|
|
295
|
-
status: entity_types_1.LoadStatus.COMPLETE,
|
|
296
|
-
conditionalColumns: [
|
|
297
|
-
{
|
|
298
|
-
toProperty: 'typePath',
|
|
299
|
-
default: 'color',
|
|
300
|
-
},
|
|
301
|
-
],
|
|
302
|
-
federatedMappings: {
|
|
303
|
-
name: 'name',
|
|
304
|
-
optionName: 'option',
|
|
305
|
-
},
|
|
306
|
-
};
|
|
307
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
308
|
-
expect(result.generalWarnings).toEqual([
|
|
309
|
-
{
|
|
310
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_UNMAPPED,
|
|
311
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
312
|
-
},
|
|
313
|
-
]);
|
|
314
|
-
});
|
|
315
|
-
it('should return error if itemOptionFederatedId is mapped incorrectly in federatedMappings', () => {
|
|
316
|
-
const lineSheetData = [{ header1: 'value1', test1: 'test1' }];
|
|
317
|
-
const config = {
|
|
318
|
-
loadType: ['ITEM'],
|
|
319
|
-
federatedMappings: {
|
|
320
|
-
name: 'header1',
|
|
321
|
-
itemFamilyFederatedId: 'someId',
|
|
322
|
-
optionName: 'test1',
|
|
323
|
-
itemOptionFederatedId: 'test2',
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(lineSheetData, config);
|
|
327
|
-
expect(result.generalWarnings).toEqual([
|
|
328
|
-
{
|
|
329
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTION_FEDERATED_ID_NOT_FOUND('test2'),
|
|
330
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
331
|
-
},
|
|
332
|
-
]);
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
describe('validate itemOptionName', () => {
|
|
336
|
-
it('should validate optionName in conditional columns', () => {
|
|
337
|
-
const data = [{ federatedId: 'test1' }];
|
|
338
|
-
const config = {
|
|
339
|
-
...loaderProcess,
|
|
340
|
-
federatedMappings: {},
|
|
341
|
-
conditionalColumns: [
|
|
342
|
-
{
|
|
343
|
-
toProperty: 'name',
|
|
344
|
-
default: 'Test {federatedId}',
|
|
345
|
-
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
rowNumber: 3,
|
|
64
|
+
columnIssues: [
|
|
346
65
|
{
|
|
347
|
-
|
|
348
|
-
|
|
66
|
+
columnName: 'itemOptionFederatedId',
|
|
67
|
+
message: 'Duplicate federatedId found: 11',
|
|
68
|
+
issueType: entity_types_1.IssueType.DUPLICATE_FEDERATED_ID,
|
|
69
|
+
data: '{"itemName":"foo","itemFamilyFederatedId":"1","itemOptionFederatedId":"11"}',
|
|
349
70
|
},
|
|
350
71
|
],
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
console.log(JSON.stringify(result, null, 2));
|
|
354
|
-
expect(result.generalWarnings).not.toContainEqual({
|
|
355
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
356
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
it('should validate name in CSV data', () => {
|
|
360
|
-
const data = [{ federatedId: 'test1', name: 'Test 1', optionName: 'Option 1' }];
|
|
361
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, loaderProcess);
|
|
362
|
-
expect(result.generalWarnings).not.toContainEqual({
|
|
363
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
364
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
it('should return warning if optionName is missing in federatedMappings, config and conditional column', () => {
|
|
368
|
-
const data = [{ id: 'custom-entity1', optionId: 'option1' }];
|
|
369
|
-
const config = {
|
|
370
|
-
...loaderProcess,
|
|
371
|
-
loadType: [entity_types_1.LoadType.CUSTOM_ENTITY],
|
|
372
|
-
federatedMappings: {
|
|
373
|
-
federatedId: 'id',
|
|
374
|
-
itemOptionFederatedId: 'optionId',
|
|
375
|
-
},
|
|
376
|
-
};
|
|
377
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
378
|
-
expect(result.generalWarnings).toEqual([
|
|
379
|
-
{
|
|
380
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
381
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
382
|
-
},
|
|
383
|
-
]);
|
|
384
|
-
});
|
|
385
|
-
it('should validate name in federatedMapping', () => {
|
|
386
|
-
const data = [
|
|
387
|
-
{
|
|
388
|
-
federatedId: 'test1',
|
|
389
|
-
display_name: 'Test 1',
|
|
390
|
-
display_option: 'Option 1',
|
|
391
|
-
},
|
|
392
|
-
];
|
|
393
|
-
const config = {
|
|
394
|
-
...loaderProcess,
|
|
395
|
-
federatedMappings: {
|
|
396
|
-
name: 'display_name',
|
|
397
|
-
optionName: 'display_option',
|
|
398
|
-
},
|
|
399
|
-
};
|
|
400
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
401
|
-
expect(result.generalWarnings).not.toContainEqual({
|
|
402
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
403
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
404
|
-
});
|
|
405
|
-
});
|
|
406
|
-
it('should return a warning if optionName is not mapped in federatedMappings', () => {
|
|
407
|
-
const data = [
|
|
408
|
-
{
|
|
409
|
-
name: 'item1',
|
|
410
|
-
family_federated_id: 'family_1',
|
|
411
|
-
input_col_1: 'value_1',
|
|
412
|
-
input_col_2: 'value_2',
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
name: 'item2',
|
|
416
|
-
family_federated_id: 'family_2',
|
|
417
|
-
input_col_1: 'value_3',
|
|
418
|
-
input_col_2: 'value_4',
|
|
419
|
-
},
|
|
420
|
-
{
|
|
421
|
-
name: 'item3',
|
|
422
|
-
family_federated_id: 'family_3',
|
|
423
|
-
input_col_1: 'value_5',
|
|
424
|
-
input_col_2: 'value_6',
|
|
425
|
-
},
|
|
426
|
-
];
|
|
427
|
-
const config = {
|
|
428
|
-
...loaderProcess,
|
|
429
|
-
conditionalColumns: [],
|
|
430
|
-
federatedMappings: {
|
|
431
|
-
itemFamilyFederatedId: 'family_federated_id',
|
|
432
|
-
itemOptionFederatedId: 'input_col_1',
|
|
433
|
-
},
|
|
434
|
-
};
|
|
435
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
436
|
-
expect(result.generalWarnings).toEqual([
|
|
437
|
-
{
|
|
438
|
-
message: constants_1.ITEM_PROCESSOR_WARNINGS.OPTIONNAME_UNMAPPED,
|
|
439
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
440
|
-
},
|
|
441
|
-
]);
|
|
442
|
-
});
|
|
443
|
-
it('should return a warning if optionName is mapped incorrectly in federatedMappings', () => {
|
|
444
|
-
const data = [
|
|
445
|
-
{
|
|
446
|
-
name: 'item1',
|
|
447
|
-
family_federated_id: 'family_1',
|
|
448
|
-
input_col_1: 'value_1',
|
|
449
|
-
input_col_2: 'value_2',
|
|
450
|
-
},
|
|
451
|
-
{
|
|
452
|
-
name: 'item2',
|
|
453
|
-
family_federated_id: 'family_2',
|
|
454
|
-
input_col_1: 'value_3',
|
|
455
|
-
input_col_2: 'value_4',
|
|
456
|
-
},
|
|
457
|
-
{
|
|
458
|
-
name: 'item3',
|
|
459
|
-
family_federated_id: 'family_3',
|
|
460
|
-
input_col_1: 'value_5',
|
|
461
|
-
input_col_2: 'value_6',
|
|
462
|
-
},
|
|
463
|
-
];
|
|
464
|
-
const config = {
|
|
465
|
-
...loaderProcess,
|
|
466
|
-
conditionalColumns: [],
|
|
467
|
-
federatedMappings: {
|
|
468
|
-
itemFamilyFederatedId: 'family_federated_id',
|
|
469
|
-
itemOptionFederatedId: 'input_col_1',
|
|
470
|
-
optionName: 'input_col_3',
|
|
471
|
-
},
|
|
472
|
-
};
|
|
473
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(data, config);
|
|
474
|
-
expect(result.generalWarnings).toEqual([
|
|
475
|
-
{
|
|
476
|
-
message: '"input_col_3" column not found in the CSV file',
|
|
477
|
-
issueType: entity_types_1.IssueType.CONFIG,
|
|
478
|
-
},
|
|
479
|
-
]);
|
|
480
|
-
});
|
|
481
|
-
it('should throw error for the duplicate itemOptionFederatedId', () => {
|
|
482
|
-
const lineSheetData = [
|
|
483
|
-
{
|
|
484
|
-
itemName: 'foo',
|
|
485
|
-
itemFamilyFederatedId: '1',
|
|
486
|
-
itemOptionFederatedId: '11',
|
|
487
|
-
},
|
|
488
|
-
{
|
|
489
|
-
itemName: 'foo',
|
|
490
|
-
itemFamilyFederatedId: '1',
|
|
491
|
-
itemOptionFederatedId: '11',
|
|
492
|
-
},
|
|
493
|
-
{
|
|
494
|
-
itemName: 'bar',
|
|
495
|
-
itemFamilyFederatedId: '2',
|
|
496
|
-
itemOptionFederatedId: '12',
|
|
497
|
-
},
|
|
498
|
-
];
|
|
499
|
-
const config = {
|
|
500
|
-
loadType: ['ITEM'],
|
|
501
|
-
federatedMappings: {
|
|
502
|
-
name: 'itemName',
|
|
503
|
-
itemFamilyFederatedId: 'itemFamilyFederatedId',
|
|
504
|
-
},
|
|
505
|
-
};
|
|
506
|
-
const result = item_processor_1.ItemProcessor.validateLoadFile(lineSheetData, config);
|
|
507
|
-
expect(result.errors).toEqual([
|
|
508
|
-
{
|
|
509
|
-
rowNumber: 2,
|
|
510
|
-
columnIssues: [
|
|
511
|
-
{
|
|
512
|
-
columnName: 'itemOptionFederatedId',
|
|
513
|
-
message: 'Duplicate federatedId found: 11',
|
|
514
|
-
issueType: entity_types_1.IssueType.DUPLICATE_FEDERATED_ID,
|
|
515
|
-
data: '{"itemName":"foo","itemFamilyFederatedId":"1","itemOptionFederatedId":"11"}',
|
|
516
|
-
},
|
|
517
|
-
],
|
|
518
|
-
},
|
|
519
|
-
{
|
|
520
|
-
rowNumber: 3,
|
|
521
|
-
columnIssues: [
|
|
522
|
-
{
|
|
523
|
-
columnName: 'itemOptionFederatedId',
|
|
524
|
-
message: 'Duplicate federatedId found: 11',
|
|
525
|
-
issueType: entity_types_1.IssueType.DUPLICATE_FEDERATED_ID,
|
|
526
|
-
data: '{"itemName":"foo","itemFamilyFederatedId":"1","itemOptionFederatedId":"11"}',
|
|
527
|
-
},
|
|
528
|
-
],
|
|
529
|
-
},
|
|
530
|
-
]);
|
|
531
|
-
});
|
|
72
|
+
},
|
|
73
|
+
]);
|
|
532
74
|
});
|
|
533
75
|
describe('validate duplicate optionName within family', () => {
|
|
534
76
|
it('should return errors when options in the same family have duplicate optionNames', () => {
|
|
@@ -49,6 +49,8 @@ async function validate(rows, config, columnAnalysis, client) {
|
|
|
49
49
|
}
|
|
50
50
|
const processorIssues = runProcessorValidation(rows, config);
|
|
51
51
|
issues.push(...processorIssues);
|
|
52
|
+
const itemTypePathIssues = validateItemTypePath(rows, config);
|
|
53
|
+
issues.push(...itemTypePathIssues);
|
|
52
54
|
const itemNameIssues = validateItemNames(rows, config);
|
|
53
55
|
issues.push(...itemNameIssues);
|
|
54
56
|
const identifierConflictIssues = validateStaticIdentifierConflicts(config);
|
|
@@ -135,7 +137,7 @@ function runProcessorValidation(rows, config) {
|
|
|
135
137
|
for (const error of validationResult?.generalErrors ?? []) {
|
|
136
138
|
issues.push({
|
|
137
139
|
severity: types_2.PreValidationSeverity.ERROR,
|
|
138
|
-
category:
|
|
140
|
+
category: issueTypeToCategory(error.issueType),
|
|
139
141
|
columnName: '',
|
|
140
142
|
propertySlug: '',
|
|
141
143
|
propertyType: '',
|
|
@@ -146,7 +148,7 @@ function runProcessorValidation(rows, config) {
|
|
|
146
148
|
for (const warning of validationResult?.generalWarnings ?? []) {
|
|
147
149
|
issues.push({
|
|
148
150
|
severity: types_2.PreValidationSeverity.WARNING,
|
|
149
|
-
category:
|
|
151
|
+
category: issueTypeToCategory(warning.issueType),
|
|
150
152
|
columnName: '',
|
|
151
153
|
propertySlug: '',
|
|
152
154
|
propertyType: '',
|
|
@@ -396,6 +398,54 @@ function validateMultiSelectFormats(rows, typePropertyMaps) {
|
|
|
396
398
|
}
|
|
397
399
|
return issues;
|
|
398
400
|
}
|
|
401
|
+
function validateItemTypePath(rows, config) {
|
|
402
|
+
const isItemCreate = config.loadType.includes(types_2.LoadType.ITEM);
|
|
403
|
+
const isCustomEntity = config.loadType.includes(types_2.LoadType.CUSTOM_ENTITY);
|
|
404
|
+
if (!isItemCreate && !isCustomEntity)
|
|
405
|
+
return [];
|
|
406
|
+
const issues = [];
|
|
407
|
+
if (isItemCreate) {
|
|
408
|
+
const invalidRows = [];
|
|
409
|
+
forEachRow(rows, (row, rowNumber) => {
|
|
410
|
+
const tp = row.typePath;
|
|
411
|
+
const valid = tp === 'item' || (typeof tp === 'string' && tp.startsWith('item:') && tp.split(':')[1]?.length > 0);
|
|
412
|
+
if (!valid)
|
|
413
|
+
invalidRows.push({ row: rowNumber, value: String(tp ?? '') });
|
|
414
|
+
});
|
|
415
|
+
if (invalidRows.length > 0) {
|
|
416
|
+
issues.push({
|
|
417
|
+
severity: types_2.PreValidationSeverity.ERROR,
|
|
418
|
+
category: MISSING_REQUIRED_FIELD_CATEGORY,
|
|
419
|
+
columnName: 'typePath',
|
|
420
|
+
propertySlug: 'typePath',
|
|
421
|
+
propertyType: 'string',
|
|
422
|
+
message: `"typePath" must be "item" or "item:<subtypepath>". ${invalidRows.length} row(s) have an invalid or missing typePath.`,
|
|
423
|
+
affectedRows: invalidRows,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (isCustomEntity) {
|
|
428
|
+
const invalidRows = [];
|
|
429
|
+
forEachRow(rows, (row, rowNumber) => {
|
|
430
|
+
const tp = row.typePath;
|
|
431
|
+
const valid = typeof tp === 'string' && tp.startsWith('custom-entity:') && tp.slice('custom-entity:'.length).length > 0;
|
|
432
|
+
if (!valid)
|
|
433
|
+
invalidRows.push({ row: rowNumber, value: String(tp ?? '') });
|
|
434
|
+
});
|
|
435
|
+
if (invalidRows.length > 0) {
|
|
436
|
+
issues.push({
|
|
437
|
+
severity: types_2.PreValidationSeverity.ERROR,
|
|
438
|
+
category: MISSING_REQUIRED_FIELD_CATEGORY,
|
|
439
|
+
columnName: 'typePath',
|
|
440
|
+
propertySlug: 'typePath',
|
|
441
|
+
propertyType: 'string',
|
|
442
|
+
message: `"typePath" must be "custom-entity:<subtypepath>". ${invalidRows.length} row(s) have an invalid or missing typePath.`,
|
|
443
|
+
affectedRows: invalidRows,
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return issues;
|
|
448
|
+
}
|
|
399
449
|
function validateItemNames(rows, config) {
|
|
400
450
|
const itemBasedLoadTypes = [types_2.LoadType.ITEM, types_2.LoadType.PROJECT_ITEM, types_2.LoadType.ASSORTMENT];
|
|
401
451
|
const isItemBased = config.loadType.some((lt) => itemBasedLoadTypes.includes(lt));
|
|
@@ -631,6 +631,91 @@ describe('validate', () => {
|
|
|
631
631
|
expect(issue).toBeUndefined();
|
|
632
632
|
});
|
|
633
633
|
});
|
|
634
|
+
describe('typePath format validation', () => {
|
|
635
|
+
const itemConfig = {
|
|
636
|
+
loadType: [types_1.LoadType.ITEM],
|
|
637
|
+
federatedMappings: { itemFamilyFederatedId: 'itemFamilyFederatedId', name: 'name' },
|
|
638
|
+
};
|
|
639
|
+
it('should error when rows have an invalid typePath', async () => {
|
|
640
|
+
const rows = [
|
|
641
|
+
{ itemFamilyFederatedId: 'fam-1', name: 'A', typePath: 'custom-entity:product' },
|
|
642
|
+
{ itemFamilyFederatedId: 'fam-2', name: 'B', typePath: 'item' },
|
|
643
|
+
];
|
|
644
|
+
const result = await (0, validate_1.validate)(rows, itemConfig, makeAnalysis());
|
|
645
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
646
|
+
expect(issue).toBeDefined();
|
|
647
|
+
expect(issue.affectedRows).toHaveLength(1);
|
|
648
|
+
expect(issue.affectedRows[0].row).toBe(2);
|
|
649
|
+
});
|
|
650
|
+
it('should error when typePath is missing on rows', async () => {
|
|
651
|
+
const rows = [
|
|
652
|
+
{ itemFamilyFederatedId: 'fam-1', name: 'A' },
|
|
653
|
+
{ itemFamilyFederatedId: 'fam-2', name: 'B' },
|
|
654
|
+
];
|
|
655
|
+
const result = await (0, validate_1.validate)(rows, itemConfig, makeAnalysis());
|
|
656
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
657
|
+
expect(issue).toBeDefined();
|
|
658
|
+
expect(issue.affectedRows).toHaveLength(2);
|
|
659
|
+
});
|
|
660
|
+
it('should not error when all rows have valid typePaths', async () => {
|
|
661
|
+
const rows = [
|
|
662
|
+
{ itemFamilyFederatedId: 'fam-1', name: 'A', typePath: 'item' },
|
|
663
|
+
{ itemFamilyFederatedId: 'fam-2', name: 'B', typePath: 'item:product' },
|
|
664
|
+
{ itemFamilyFederatedId: 'fam-3', name: 'C', typePath: 'item:material:fabric' },
|
|
665
|
+
];
|
|
666
|
+
const result = await (0, validate_1.validate)(rows, itemConfig, makeAnalysis());
|
|
667
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
668
|
+
expect(issue).toBeUndefined();
|
|
669
|
+
});
|
|
670
|
+
it('should not run for COLOR loads', async () => {
|
|
671
|
+
const colorConfig = {
|
|
672
|
+
loadType: [types_1.LoadType.COLOR],
|
|
673
|
+
federatedMappings: { federatedId: 'federatedId', name: 'name' },
|
|
674
|
+
};
|
|
675
|
+
const rows = [{ federatedId: '1', name: 'Red', typePath: 'bad-value' }];
|
|
676
|
+
const result = await (0, validate_1.validate)(rows, colorConfig, makeAnalysis());
|
|
677
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
678
|
+
expect(issue).toBeUndefined();
|
|
679
|
+
});
|
|
680
|
+
it('should not run for PROJECT_ITEM or ASSORTMENT loads (items already have a type)', async () => {
|
|
681
|
+
const projectItemConfig = {
|
|
682
|
+
loadType: [types_1.LoadType.PROJECT_ITEM, types_1.LoadType.ASSORTMENT],
|
|
683
|
+
federatedMappings: { itemFamilyFederatedId: 'itemFamilyFederatedId', name: 'name' },
|
|
684
|
+
};
|
|
685
|
+
const rows = [{ itemFamilyFederatedId: 'fam-1', name: 'A' }];
|
|
686
|
+
const result = await (0, validate_1.validate)(rows, projectItemConfig, makeAnalysis());
|
|
687
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
688
|
+
expect(issue).toBeUndefined();
|
|
689
|
+
});
|
|
690
|
+
it('should error for CUSTOM_ENTITY rows with missing subtype', async () => {
|
|
691
|
+
const customEntityConfig = {
|
|
692
|
+
loadType: [types_1.LoadType.CUSTOM_ENTITY],
|
|
693
|
+
federatedMappings: { federatedId: 'federatedId', name: 'name' },
|
|
694
|
+
};
|
|
695
|
+
const rows = [
|
|
696
|
+
{ federatedId: '1', name: 'A', typePath: 'custom-entity:material' },
|
|
697
|
+
{ federatedId: '2', name: 'B', typePath: 'custom-entity:' },
|
|
698
|
+
{ federatedId: '3', name: 'C' },
|
|
699
|
+
];
|
|
700
|
+
const result = await (0, validate_1.validate)(rows, customEntityConfig, makeAnalysis());
|
|
701
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
702
|
+
expect(issue).toBeDefined();
|
|
703
|
+
expect(issue.affectedRows).toHaveLength(2);
|
|
704
|
+
});
|
|
705
|
+
it('should not error for CUSTOM_ENTITY rows with valid typePath', async () => {
|
|
706
|
+
const customEntityConfig = {
|
|
707
|
+
loadType: [types_1.LoadType.CUSTOM_ENTITY],
|
|
708
|
+
federatedMappings: { federatedId: 'federatedId', name: 'name' },
|
|
709
|
+
};
|
|
710
|
+
const rows = [
|
|
711
|
+
{ federatedId: '1', name: 'A', typePath: 'custom-entity:material' },
|
|
712
|
+
{ federatedId: '2', name: 'B', typePath: 'custom-entity:material:fabric' },
|
|
713
|
+
];
|
|
714
|
+
const result = await (0, validate_1.validate)(rows, customEntityConfig, makeAnalysis());
|
|
715
|
+
const issue = result.issues.find((i) => i.columnName === 'typePath' && i.category === types_3.PreValidationCategory.MISSING_REQUIRED_FIELD);
|
|
716
|
+
expect(issue).toBeUndefined();
|
|
717
|
+
});
|
|
718
|
+
});
|
|
634
719
|
describe('typePath existence validation', () => {
|
|
635
720
|
it('should error when typesByPath contains entries with errors (non-existent type)', async () => {
|
|
636
721
|
const config = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/loader",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Client library for helping with loader jobs.",
|
|
5
5
|
"homepage": "https://archergreysorg.github.io/contrail-loader/",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"lib"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@contrail/entity-compare": "^1.
|
|
30
|
+
"@contrail/entity-compare": "^1.2.1",
|
|
31
31
|
"@contrail/entity-types": "1.6.1",
|
|
32
32
|
"@contrail/policies": "^2.0.7",
|
|
33
33
|
"@contrail/types": "^3.0.33",
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { InvocationContext } from '../config';
|
|
2
|
-
export declare type ImageSearchSource = {
|
|
3
|
-
contentId: string;
|
|
4
|
-
} | {
|
|
5
|
-
fileId: string;
|
|
6
|
-
} | {
|
|
7
|
-
imageBase64: string;
|
|
8
|
-
};
|
|
9
|
-
export interface ImageSearchOptions {
|
|
10
|
-
limit?: number;
|
|
11
|
-
minScore?: number;
|
|
12
|
-
hydrate?: boolean;
|
|
13
|
-
filterContentIds?: string[];
|
|
14
|
-
}
|
|
15
|
-
export interface ImageSearchResult {
|
|
16
|
-
contentId: string;
|
|
17
|
-
fileId: string;
|
|
18
|
-
contentHolderReference: string;
|
|
19
|
-
fileName: string;
|
|
20
|
-
contentType: string;
|
|
21
|
-
primaryFileUrl: string;
|
|
22
|
-
score: number;
|
|
23
|
-
contentHolder?: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
|
-
export interface ImageSearchResponse {
|
|
26
|
-
results: ImageSearchResult[];
|
|
27
|
-
}
|
|
28
|
-
export declare class ImageSearch {
|
|
29
|
-
private ctx;
|
|
30
|
-
constructor(ctx?: InvocationContext);
|
|
31
|
-
searchByText(query: string, options?: ImageSearchOptions): Promise<ImageSearchResponse>;
|
|
32
|
-
searchSimilar(source: ImageSearchSource, options?: ImageSearchOptions): Promise<ImageSearchResponse>;
|
|
33
|
-
private post;
|
|
34
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ImageSearch = void 0;
|
|
13
|
-
const request_1 = require("../core/request");
|
|
14
|
-
const SEARCH_RESOURCE = '/image-search/search';
|
|
15
|
-
const SEARCH_BY_IMAGE_RESOURCE = '/image-search/search-by-image';
|
|
16
|
-
class ImageSearch {
|
|
17
|
-
constructor(ctx) {
|
|
18
|
-
this.ctx = ctx;
|
|
19
|
-
}
|
|
20
|
-
searchByText(query, options = {}) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
return this.post(SEARCH_RESOURCE, Object.assign({ query }, options));
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
searchSimilar(source, options = {}) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
return this.post(SEARCH_BY_IMAGE_RESOURCE, Object.assign(Object.assign({}, source), options));
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
post(resource, body) {
|
|
31
|
-
var _a;
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
const response = (yield request_1.Request.request(resource, {
|
|
34
|
-
method: 'POST',
|
|
35
|
-
body: JSON.stringify(body),
|
|
36
|
-
headers: { Accept: 'application/json', 'Content-Type': 'application/json' },
|
|
37
|
-
}, this.ctx));
|
|
38
|
-
return { results: (_a = response === null || response === void 0 ? void 0 : response.results) !== null && _a !== void 0 ? _a : [] };
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.ImageSearch = ImageSearch;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './image-search';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./image-search"), exports);
|