pim-import 4.30.2 → 4.30.4
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/dist/algolia/clean.js +10 -10
- package/dist/algolia/clean.js.map +1 -1
- package/dist/algolia/config.js +9 -9
- package/dist/algolia/config.js.map +1 -1
- package/dist/algolia/downloads.js +41 -41
- package/dist/algolia/downloads.js.map +1 -1
- package/dist/algolia/families.js +69 -69
- package/dist/algolia/families.js.map +1 -1
- package/dist/algolia/models.js +48 -48
- package/dist/algolia/models.js.map +1 -1
- package/dist/algolia/news.js +39 -39
- package/dist/algolia/news.js.map +1 -1
- package/dist/algolia/pressRelease.js +36 -36
- package/dist/algolia/pressRelease.js.map +1 -1
- package/dist/algolia/pressReview.js +34 -34
- package/dist/algolia/pressReview.js.map +1 -1
- package/dist/algolia/products.js +83 -83
- package/dist/algolia/products.js.map +1 -1
- package/dist/algolia/projects.js +43 -43
- package/dist/algolia/projects.js.map +1 -1
- package/dist/algolia/stories.js +52 -52
- package/dist/algolia/stories.js.map +1 -1
- package/dist/algolia/subFamilies.js +76 -76
- package/dist/algolia/subFamilies.js.map +1 -1
- package/dist/algolia/subModels.js +47 -47
- package/dist/algolia/subModels.js.map +1 -1
- package/dist/downloads/classes/manageEntry.js +3 -3
- package/dist/downloads/classes/manageEntry.js.map +1 -1
- package/dist/downloads/import.js +27 -27
- package/dist/downloads/import.js.map +1 -1
- package/dist/libs/contentful-cda.js +34 -34
- package/dist/libs/contentful-cda.js.map +1 -1
- package/dist/libs/contentful.js +131 -130
- package/dist/libs/contentful.js.map +1 -1
- package/dist/libs/imgix.js +23 -23
- package/dist/libs/imgix.js.map +1 -1
- package/dist/libs/logs.js +4 -4
- package/dist/libs/logs.js.map +1 -1
- package/dist/libs/pdf.js +5 -5
- package/dist/libs/pdf.js.map +1 -1
- package/dist/libs/s3.js +28 -28
- package/dist/libs/s3.js.map +1 -1
- package/dist/libs/sentry.js +6 -2
- package/dist/libs/sentry.js.map +1 -1
- package/dist/pim/config.js +3 -3
- package/dist/pim/config.js.map +1 -1
- package/dist/pim/endpoints.js +39 -39
- package/dist/pim/endpoints.js.map +1 -1
- package/dist/pim/methods/bulkPublish.js +10 -10
- package/dist/pim/methods/bulkPublish.js.map +1 -1
- package/dist/pim/methods/catalogs.js +62 -62
- package/dist/pim/methods/catalogs.js.map +1 -1
- package/dist/pim/methods/designers.js +19 -19
- package/dist/pim/methods/designers.js.map +1 -1
- package/dist/pim/methods/dictionary.js +66 -66
- package/dist/pim/methods/dictionary.js.map +1 -1
- package/dist/pim/methods/families.js +37 -37
- package/dist/pim/methods/families.js.map +1 -1
- package/dist/pim/methods/latestProducts.js +7 -7
- package/dist/pim/methods/latestProducts.js.map +1 -1
- package/dist/pim/methods/models.js +47 -47
- package/dist/pim/methods/models.js.map +1 -1
- package/dist/pim/methods/pages/catalogs.js +6 -6
- package/dist/pim/methods/pages/catalogs.js.map +1 -1
- package/dist/pim/methods/pages/families.js +7 -7
- package/dist/pim/methods/pages/families.js.map +1 -1
- package/dist/pim/methods/pages/subfamilies.js +11 -11
- package/dist/pim/methods/pages/subfamilies.js.map +1 -1
- package/dist/pim/methods/products.js +448 -415
- package/dist/pim/methods/products.js.map +1 -1
- package/dist/pim/methods/subfamilies.js +107 -107
- package/dist/pim/methods/subfamilies.js.map +1 -1
- package/dist/pim/methods/submodels.js +37 -37
- package/dist/pim/methods/submodels.js.map +1 -1
- package/dist/pim/request.js +2 -2
- package/dist/pim/request.js.map +1 -1
- package/dist/utils.js +23 -23
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/downloads/import.ts +1 -1
- package/src/libs/contentful.ts +8 -7
- package/src/libs/s3.ts +2 -2
- package/src/pim/endpoints.ts +8 -8
- package/src/pim/methods/bulkPublish.ts +1 -1
- package/src/pim/methods/dictionary.ts +1 -1
- package/src/pim/methods/families.ts +1 -1
- package/src/pim/methods/products.ts +40 -9
- package/types/algolia/clean.d.ts +1 -1
- package/types/algolia/config.d.ts +1 -1
- package/types/algolia/downloads.d.ts +1 -1
- package/types/algolia/families.d.ts +3 -3
- package/types/algolia/models.d.ts +1 -1
- package/types/algolia/news.d.ts +1 -1
- package/types/algolia/pressRelease.d.ts +1 -1
- package/types/algolia/pressReview.d.ts +1 -1
- package/types/algolia/products.d.ts +2 -2
- package/types/algolia/projects.d.ts +1 -1
- package/types/algolia/stories.d.ts +1 -1
- package/types/algolia/subFamilies.d.ts +1 -1
- package/types/algolia/subModels.d.ts +1 -1
- package/types/libs/contentful-cda.d.ts +2 -2
- package/types/libs/contentful.d.ts +10 -10
- package/types/libs/logs.d.ts +1 -1
- package/types/libs/pdf.d.ts +1 -1
- package/types/libs/s3.d.ts +1 -1
- package/types/pim/config.d.ts +1 -1
- package/types/pim/endpoints.d.ts +3 -3
- package/types/pim/methods/designers.d.ts +1 -1
- package/types/pim/methods/products.d.ts +3 -3
- package/types/resources/Audit.d.ts +1 -1
- package/types/types.d.ts +21 -21
- package/types/utils.d.ts +1 -1
|
@@ -21,119 +21,119 @@ const isTermsToAdd = async (productDetails, catalog) => {
|
|
|
21
21
|
if (!productDetails.code.includes(PIM_DUPLICATE_SEPARATOR)) {
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
|
-
logs_1.log(`Product used to create associations between product and additional taxonomy terms: ${productDetails.code}`);
|
|
24
|
+
(0, logs_1.log)(`Product used to create associations between product and additional taxonomy terms: ${productDetails.code}`);
|
|
25
25
|
const realCode = productDetails.code.substring(0, productDetails.code.indexOf(PIM_DUPLICATE_SEPARATOR));
|
|
26
|
-
let productEntry = await contentful_1.getEntryByCode(realCode, "topicProduct");
|
|
26
|
+
let productEntry = await (0, contentful_1.getEntryByCode)(realCode, "topicProduct");
|
|
27
27
|
if (!productEntry) {
|
|
28
|
-
logs_1.log(`The product ${realCode} does not exist, it is not possible to save the additional association with the ${productDetails?.currentCatalog?.subFamilyCode} family and the ${productDetails?.currentCatalog?.categoryCode} category`);
|
|
28
|
+
(0, logs_1.log)(`The product ${realCode} does not exist, it is not possible to save the additional association with the ${productDetails?.currentCatalog?.subFamilyCode} family and the ${productDetails?.currentCatalog?.categoryCode} category`);
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
31
|
else if (productEntry.isArchived()) {
|
|
32
|
-
logs_1.log(`The product ${realCode} is archived, it is not possible to save the additional association with the ${productDetails?.currentCatalog?.subFamilyCode} family and the ${productDetails?.currentCatalog?.categoryCode} category`);
|
|
32
|
+
(0, logs_1.log)(`The product ${realCode} is archived, it is not possible to save the additional association with the ${productDetails?.currentCatalog?.subFamilyCode} family and the ${productDetails?.currentCatalog?.categoryCode} category`);
|
|
33
33
|
return true;
|
|
34
34
|
}
|
|
35
35
|
const catalogFieldKey = "catalogs";
|
|
36
36
|
if (productDetails.currentCatalog?.catalogCode) {
|
|
37
|
-
const catalogEntry = await contentful_1.getEntryByCode(productDetails.currentCatalog.catalogCode, "topicCatalog", "sys");
|
|
37
|
+
const catalogEntry = await (0, contentful_1.getEntryByCode)(productDetails.currentCatalog.catalogCode, "topicCatalog", "sys");
|
|
38
38
|
if (catalogEntry) {
|
|
39
|
-
logs_1.log(`Start the association of the ${realCode} with the ${productDetails.currentCatalog.catalogCode} catalog`);
|
|
40
|
-
productEntry.fields = await contentful_1.addToRelationFields(productEntry, catalogFieldKey, catalogEntry.sys.id, true);
|
|
39
|
+
(0, logs_1.log)(`Start the association of the ${realCode} with the ${productDetails.currentCatalog.catalogCode} catalog`);
|
|
40
|
+
productEntry.fields = await (0, contentful_1.addToRelationFields)(productEntry, catalogFieldKey, catalogEntry.sys.id, true);
|
|
41
41
|
}
|
|
42
42
|
else {
|
|
43
|
-
logs_1.log(`The ${productDetails.currentCatalog.catalogCode} catalog does not exist`);
|
|
43
|
+
(0, logs_1.log)(`The ${productDetails.currentCatalog.catalogCode} catalog does not exist`);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
|
-
logs_1.log(`No catalog code found`, "WARN");
|
|
47
|
+
(0, logs_1.log)(`No catalog code found`, "WARN");
|
|
48
48
|
}
|
|
49
|
-
const categoriesFieldKey = "categories" + utils_1.capitalizeFirstLetter(catalog);
|
|
49
|
+
const categoriesFieldKey = "categories" + (0, utils_1.capitalizeFirstLetter)(catalog);
|
|
50
50
|
if (productDetails.currentCatalog?.categoryCode) {
|
|
51
|
-
const categoryTopicCode = catalogs_1.getCategoryTopicCode(productDetails.currentCatalog.categoryCode, catalog);
|
|
52
|
-
const categoryEntry = await contentful_1.getEntryByCode(categoryTopicCode, "topicCategory", "sys");
|
|
51
|
+
const categoryTopicCode = (0, catalogs_1.getCategoryTopicCode)(productDetails.currentCatalog.categoryCode, catalog);
|
|
52
|
+
const categoryEntry = await (0, contentful_1.getEntryByCode)(categoryTopicCode, "topicCategory", "sys");
|
|
53
53
|
if (categoryEntry) {
|
|
54
|
-
logs_1.log(`Start the association of the ${realCode} with the ${categoryTopicCode} category`);
|
|
55
|
-
productEntry.fields = await contentful_1.addToRelationFields(productEntry, categoriesFieldKey, categoryEntry.sys.id, true);
|
|
54
|
+
(0, logs_1.log)(`Start the association of the ${realCode} with the ${categoryTopicCode} category`);
|
|
55
|
+
productEntry.fields = await (0, contentful_1.addToRelationFields)(productEntry, categoriesFieldKey, categoryEntry.sys.id, true);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
logs_1.log(`The ${categoryTopicCode} category does not exist`);
|
|
58
|
+
(0, logs_1.log)(`The ${categoryTopicCode} category does not exist`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
logs_1.log(`No category code found`, "WARN");
|
|
62
|
+
(0, logs_1.log)(`No category code found`, "WARN");
|
|
63
63
|
}
|
|
64
64
|
const familiesFieldKey = "families";
|
|
65
65
|
if (productDetails.currentCatalog?.familyCode) {
|
|
66
|
-
const familyEntry = await contentful_1.getEntryByCode(productDetails.currentCatalog.familyCode, "topicFamily", "sys");
|
|
66
|
+
const familyEntry = await (0, contentful_1.getEntryByCode)(productDetails.currentCatalog.familyCode, "topicFamily", "sys");
|
|
67
67
|
if (familyEntry) {
|
|
68
|
-
logs_1.log(`Start the association of the ${realCode} with the ${productDetails.currentCatalog.familyCode} family`);
|
|
69
|
-
productEntry.fields = await contentful_1.addToRelationFields(productEntry, familiesFieldKey, familyEntry.sys.id, true);
|
|
68
|
+
(0, logs_1.log)(`Start the association of the ${realCode} with the ${productDetails.currentCatalog.familyCode} family`);
|
|
69
|
+
productEntry.fields = await (0, contentful_1.addToRelationFields)(productEntry, familiesFieldKey, familyEntry.sys.id, true);
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
logs_1.log(`The ${productDetails.currentCatalog.familyCode} family does not exist`);
|
|
72
|
+
(0, logs_1.log)(`The ${productDetails.currentCatalog.familyCode} family does not exist`);
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
else {
|
|
76
|
-
logs_1.log(`No family code found`, "WARN");
|
|
76
|
+
(0, logs_1.log)(`No family code found`, "WARN");
|
|
77
77
|
}
|
|
78
|
-
const subFamiliesFieldKey = "subFamilies" + utils_1.capitalizeFirstLetter(catalog);
|
|
78
|
+
const subFamiliesFieldKey = "subFamilies" + (0, utils_1.capitalizeFirstLetter)(catalog);
|
|
79
79
|
if (productDetails.currentCatalog?.subFamilyCode) {
|
|
80
|
-
const subFamilyEntry = await contentful_1.getEntryByCode(productDetails.currentCatalog.subFamilyCode, "topicSubFamily", "sys");
|
|
80
|
+
const subFamilyEntry = await (0, contentful_1.getEntryByCode)(productDetails.currentCatalog.subFamilyCode, "topicSubFamily", "sys");
|
|
81
81
|
if (subFamilyEntry) {
|
|
82
|
-
logs_1.log(`Start the association of the ${realCode} with the ${productDetails?.currentCatalog?.subFamilyCode} subFamily`);
|
|
83
|
-
productEntry.fields = await contentful_1.addToRelationFields(productEntry, subFamiliesFieldKey, subFamilyEntry.sys.id, true);
|
|
82
|
+
(0, logs_1.log)(`Start the association of the ${realCode} with the ${productDetails?.currentCatalog?.subFamilyCode} subFamily`);
|
|
83
|
+
productEntry.fields = await (0, contentful_1.addToRelationFields)(productEntry, subFamiliesFieldKey, subFamilyEntry.sys.id, true);
|
|
84
84
|
}
|
|
85
85
|
else {
|
|
86
|
-
logs_1.log(`The ${productDetails.currentCatalog.subFamilyCode} subFamily does not exist`);
|
|
86
|
+
(0, logs_1.log)(`The ${productDetails.currentCatalog.subFamilyCode} subFamily does not exist`);
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
|
-
logs_1.log(`No subFamily code found`, "WARN");
|
|
90
|
+
(0, logs_1.log)(`No subFamily code found`, "WARN");
|
|
91
91
|
}
|
|
92
|
-
const modelsFieldKey = "models" + utils_1.capitalizeFirstLetter(catalog);
|
|
92
|
+
const modelsFieldKey = "models" + (0, utils_1.capitalizeFirstLetter)(catalog);
|
|
93
93
|
if (productDetails.models) {
|
|
94
94
|
for (const model of productDetails.models) {
|
|
95
95
|
const modelCode = model.data.code;
|
|
96
96
|
if (modelCode) {
|
|
97
|
-
logs_1.log(`Get model entry with id ${modelCode}`);
|
|
98
|
-
const modelEntry = await contentful_1.getEntryByID(modelCode, "topicModel", "sys");
|
|
97
|
+
(0, logs_1.log)(`Get model entry with id ${modelCode}`);
|
|
98
|
+
const modelEntry = await (0, contentful_1.getEntryByID)(modelCode, "topicModel", "sys");
|
|
99
99
|
if (modelEntry) {
|
|
100
|
-
logs_1.log(`Start the association of the ${realCode} with the ${modelCode} model`);
|
|
101
|
-
productEntry.fields = await contentful_1.addToRelationFields(productEntry, modelsFieldKey, modelEntry.sys.id, true);
|
|
100
|
+
(0, logs_1.log)(`Start the association of the ${realCode} with the ${modelCode} model`);
|
|
101
|
+
productEntry.fields = await (0, contentful_1.addToRelationFields)(productEntry, modelsFieldKey, modelEntry.sys.id, true);
|
|
102
102
|
}
|
|
103
103
|
else {
|
|
104
|
-
logs_1.log(`The ${modelCode} model does not exist`);
|
|
104
|
+
(0, logs_1.log)(`The ${modelCode} model does not exist`);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
else {
|
|
108
|
-
logs_1.log(`No model code found`, "WARN");
|
|
108
|
+
(0, logs_1.log)(`No model code found`, "WARN");
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
113
|
-
logs_1.log(`No models found`);
|
|
113
|
+
(0, logs_1.log)(`No models found`);
|
|
114
114
|
}
|
|
115
|
-
const subModelsFieldKey = "subModels" + utils_1.capitalizeFirstLetter(catalog);
|
|
115
|
+
const subModelsFieldKey = "subModels" + (0, utils_1.capitalizeFirstLetter)(catalog);
|
|
116
116
|
if (productDetails.submodels) {
|
|
117
117
|
for (const submodel of productDetails.submodels) {
|
|
118
118
|
const subModelCode = submodel.data.code;
|
|
119
119
|
if (subModelCode) {
|
|
120
|
-
logs_1.log(`Get subModel entry with id ${subModelCode}`);
|
|
121
|
-
const subModelEntry = await contentful_1.getEntryByID(subModelCode, "topicSubModel", "sys");
|
|
120
|
+
(0, logs_1.log)(`Get subModel entry with id ${subModelCode}`);
|
|
121
|
+
const subModelEntry = await (0, contentful_1.getEntryByID)(subModelCode, "topicSubModel", "sys");
|
|
122
122
|
if (subModelEntry) {
|
|
123
|
-
logs_1.log(`Start the association of the ${realCode} with the ${subModelCode} subModel`);
|
|
124
|
-
productEntry.fields = await contentful_1.addToRelationFields(productEntry, subModelsFieldKey, subModelEntry.sys.id, true);
|
|
123
|
+
(0, logs_1.log)(`Start the association of the ${realCode} with the ${subModelCode} subModel`);
|
|
124
|
+
productEntry.fields = await (0, contentful_1.addToRelationFields)(productEntry, subModelsFieldKey, subModelEntry.sys.id, true);
|
|
125
125
|
}
|
|
126
126
|
else {
|
|
127
|
-
logs_1.log(`The ${subModelCode} subModel does not exist`);
|
|
127
|
+
(0, logs_1.log)(`The ${subModelCode} subModel does not exist`);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
else {
|
|
131
|
-
logs_1.log(`No subModel code found`, "WARN");
|
|
131
|
+
(0, logs_1.log)(`No subModel code found`, "WARN");
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
else {
|
|
136
|
-
logs_1.log(`No subModel found`);
|
|
136
|
+
(0, logs_1.log)(`No subModel found`);
|
|
137
137
|
}
|
|
138
138
|
productEntry = await productEntry.update();
|
|
139
139
|
if (productEntry.isPublished()) {
|
|
@@ -141,30 +141,30 @@ const isTermsToAdd = async (productDetails, catalog) => {
|
|
|
141
141
|
productEntry = await productEntry.publish();
|
|
142
142
|
}
|
|
143
143
|
catch (err) {
|
|
144
|
-
logs_1.log(`Cannot publish entry.`);
|
|
145
|
-
logs_1.log(err);
|
|
144
|
+
(0, logs_1.log)(`Cannot publish entry.`);
|
|
145
|
+
(0, logs_1.log)(err);
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
return productEntry;
|
|
149
149
|
};
|
|
150
150
|
const notVisibleToWebProduct = async (code) => {
|
|
151
|
-
let productEntry = await contentful_1.getEntryByCode(code, "topicProduct");
|
|
151
|
+
let productEntry = await (0, contentful_1.getEntryByCode)(code, "topicProduct");
|
|
152
152
|
if (productEntry) {
|
|
153
|
-
const pageId = exports.getProductPageIdByCode(productEntry.sys.id);
|
|
154
|
-
logs_1.log("The product exists, I proceed to archive it");
|
|
155
|
-
productEntry = await contentful_1.archiveEntry(productEntry, true);
|
|
156
|
-
let pageEntry = await contentful_1.getEntryByID(pageId, "page");
|
|
153
|
+
const pageId = (0, exports.getProductPageIdByCode)(productEntry.sys.id);
|
|
154
|
+
(0, logs_1.log)("The product exists, I proceed to archive it");
|
|
155
|
+
productEntry = await (0, contentful_1.archiveEntry)(productEntry, true);
|
|
156
|
+
let pageEntry = await (0, contentful_1.getEntryByID)(pageId, "page");
|
|
157
157
|
if (pageEntry) {
|
|
158
|
-
pageEntry = await contentful_1.archiveEntry(pageEntry);
|
|
158
|
+
pageEntry = await (0, contentful_1.archiveEntry)(pageEntry);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
else {
|
|
162
|
-
logs_1.log("The product has never been imported", "WARN");
|
|
162
|
+
(0, logs_1.log)("The product has never been imported", "WARN");
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
165
|
const setHideInRegionField = async (destinations, pageData) => {
|
|
166
|
-
const env = await contentful_1.getEnvironment();
|
|
167
|
-
const defEnvLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
166
|
+
const env = await (0, contentful_1.getEnvironment)();
|
|
167
|
+
const defEnvLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
168
168
|
let productRegions = destinations
|
|
169
169
|
?.filter((item) => item?.code?.includes("PROFESSIONAL_") ||
|
|
170
170
|
(typeof item === "string" && item?.includes("PROFESSIONAL_")))
|
|
@@ -180,7 +180,7 @@ const setHideInRegionField = async (destinations, pageData) => {
|
|
|
180
180
|
pageData.fields.hideInRegions[defEnvLocaleCode] = [];
|
|
181
181
|
}
|
|
182
182
|
if (productRegions?.length) {
|
|
183
|
-
logs_1.log(`Hide from other regions other than: ${productRegions.join(", ")}`);
|
|
183
|
+
(0, logs_1.log)(`Hide from other regions other than: ${productRegions.join(", ")}`);
|
|
184
184
|
const { items } = await env.getEntries({
|
|
185
185
|
content_type: "topicRegion",
|
|
186
186
|
limit: 100,
|
|
@@ -193,55 +193,55 @@ const setHideInRegionField = async (destinations, pageData) => {
|
|
|
193
193
|
for (const item of items) {
|
|
194
194
|
const region = item?.fields?.region?.[defEnvLocaleCode];
|
|
195
195
|
if (!productRegions.includes(region)) {
|
|
196
|
-
logs_1.log(`Hide in region: ${region}`);
|
|
197
|
-
pageData.fields = await contentful_1.addToRelationFields(pageData, "hideInRegions", item.sys.id, true, count++ === 0);
|
|
196
|
+
(0, logs_1.log)(`Hide in region: ${region}`);
|
|
197
|
+
pageData.fields = await (0, contentful_1.addToRelationFields)(pageData, "hideInRegions", item.sys.id, true, count++ === 0);
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
else if (pageData.fields?.hideInRegions?.[defEnvLocaleCode]) {
|
|
202
|
-
logs_1.log(`No region found remove old hideInRegions relations.`);
|
|
202
|
+
(0, logs_1.log)(`No region found remove old hideInRegions relations.`);
|
|
203
203
|
}
|
|
204
204
|
else {
|
|
205
|
-
logs_1.log(`No region found.`, "WARN");
|
|
205
|
+
(0, logs_1.log)(`No region found.`, "WARN");
|
|
206
206
|
}
|
|
207
207
|
return pageData.fields;
|
|
208
208
|
};
|
|
209
209
|
exports.setHideInRegionField = setHideInRegionField;
|
|
210
210
|
const getProductPageData = async (names, slugs, pageId, productEntry, productPageEntry) => {
|
|
211
|
-
const defEnvLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
211
|
+
const defEnvLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
212
212
|
const pageData = {
|
|
213
213
|
fields: productPageEntry?.fields || {},
|
|
214
214
|
};
|
|
215
215
|
pageData.fields.title = names;
|
|
216
216
|
pageData.fields.slug = slugs;
|
|
217
|
-
pageData.fields = await contentful_1.addFieldValue(pageData, "internalName", pageId);
|
|
218
|
-
pageData.fields = await contentful_1.addFieldValue(pageData, "type", "CatalogProduct");
|
|
219
|
-
pageData.fields = await contentful_1.addToRelationFields(pageData, "topic", productEntry.sys.id);
|
|
217
|
+
pageData.fields = await (0, contentful_1.addFieldValue)(pageData, "internalName", pageId);
|
|
218
|
+
pageData.fields = await (0, contentful_1.addFieldValue)(pageData, "type", "CatalogProduct");
|
|
219
|
+
pageData.fields = await (0, contentful_1.addToRelationFields)(pageData, "topic", productEntry.sys.id);
|
|
220
220
|
const destinations = productEntry?.fields?.productFields?.[defEnvLocaleCode]?.destinations;
|
|
221
|
-
pageData.fields = await exports.setHideInRegionField(destinations, pageData);
|
|
221
|
+
pageData.fields = await (0, exports.setHideInRegionField)(destinations, pageData);
|
|
222
222
|
return pageData;
|
|
223
223
|
};
|
|
224
224
|
const createOrUpdateProductPage = async (productEntry, unpublish) => {
|
|
225
|
-
const pageId = exports.getProductPageIdByCode(productEntry.sys.id);
|
|
225
|
+
const pageId = (0, exports.getProductPageIdByCode)(productEntry.sys.id);
|
|
226
226
|
const names = productEntry.fields.name;
|
|
227
227
|
const slugs = {};
|
|
228
228
|
const code = productEntry.fields.code["en"];
|
|
229
229
|
for (const name of Object.entries(productEntry.fields.name)) {
|
|
230
|
-
slugs[name[0]] = utils_1.stringToSlug(`${name[1]}-${code}`, true).toLowerCase();
|
|
230
|
+
slugs[name[0]] = (0, utils_1.stringToSlug)(`${name[1]}-${code}`, true).toLowerCase();
|
|
231
231
|
}
|
|
232
|
-
let productPageEntry = await contentful_1.getEntryByID(pageId, "page");
|
|
232
|
+
let productPageEntry = await (0, contentful_1.getEntryByID)(pageId, "page");
|
|
233
233
|
const pageData = await getProductPageData(names, slugs, pageId, productEntry, productPageEntry);
|
|
234
234
|
if (productPageEntry) {
|
|
235
235
|
if (productPageEntry.isArchived()) {
|
|
236
|
-
logs_1.log(`Unarchive product page with id ${pageId}`);
|
|
236
|
+
(0, logs_1.log)(`Unarchive product page with id ${pageId}`);
|
|
237
237
|
productPageEntry = await productPageEntry.unarchive();
|
|
238
238
|
}
|
|
239
|
-
logs_1.log(`Product page ${pageId} already exists. Updating...`);
|
|
240
|
-
productPageEntry = await contentful_1.updateEntry(productPageEntry, pageData, productPageEntry.isPublished() && !unpublish);
|
|
239
|
+
(0, logs_1.log)(`Product page ${pageId} already exists. Updating...`);
|
|
240
|
+
productPageEntry = await (0, contentful_1.updateEntry)(productPageEntry, pageData, productPageEntry.isPublished() && !unpublish);
|
|
241
241
|
}
|
|
242
242
|
else {
|
|
243
|
-
logs_1.log(`Product page ${pageId} not exists. Create new entry with data`);
|
|
244
|
-
productPageEntry = await contentful_1.createEntryWithId("page", pageId, pageData);
|
|
243
|
+
(0, logs_1.log)(`Product page ${pageId} not exists. Create new entry with data`);
|
|
244
|
+
productPageEntry = await (0, contentful_1.createEntryWithId)("page", pageId, pageData);
|
|
245
245
|
}
|
|
246
246
|
return productPageEntry;
|
|
247
247
|
};
|
|
@@ -257,7 +257,7 @@ exports.excludeCertificationFieldsKeys = [
|
|
|
257
257
|
"fMarking",
|
|
258
258
|
];
|
|
259
259
|
const getProductFields = async (pimDetails) => {
|
|
260
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
260
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
261
261
|
const productFields = {};
|
|
262
262
|
productFields_json_1.default.forEach((fieldData) => {
|
|
263
263
|
if (fieldData.parent) {
|
|
@@ -266,8 +266,8 @@ const getProductFields = async (pimDetails) => {
|
|
|
266
266
|
if (Array.isArray(pimDetails[fieldData.parent][fieldData.key])) {
|
|
267
267
|
pimDetails[fieldData.parent][fieldData.key].forEach((item) => {
|
|
268
268
|
if (item.code &&
|
|
269
|
-
utils_1.sanitizeValue(item.code) &&
|
|
270
|
-
utils_1.sanitizeValue(item[`value_${defaultEnvironmentLocaleCode}`])) {
|
|
269
|
+
(0, utils_1.sanitizeValue)(item.code) &&
|
|
270
|
+
(0, utils_1.sanitizeValue)(item[`value_${defaultEnvironmentLocaleCode}`])) {
|
|
271
271
|
if (!productFields?.[fieldData.parent]?.[fieldData.key]) {
|
|
272
272
|
if (!productFields?.[fieldData.parent]) {
|
|
273
273
|
productFields[fieldData.parent] = {};
|
|
@@ -283,8 +283,8 @@ const getProductFields = async (pimDetails) => {
|
|
|
283
283
|
else {
|
|
284
284
|
let value = "";
|
|
285
285
|
if (pimDetails?.[fieldData.parent]?.[fieldData.key]?.code &&
|
|
286
|
-
utils_1.sanitizeValue(pimDetails[fieldData.parent][fieldData.key].code) &&
|
|
287
|
-
utils_1.sanitizeValue(pimDetails[fieldData.parent][fieldData.key][`value_${defaultEnvironmentLocaleCode}`])) {
|
|
286
|
+
(0, utils_1.sanitizeValue)(pimDetails[fieldData.parent][fieldData.key].code) &&
|
|
287
|
+
(0, utils_1.sanitizeValue)(pimDetails[fieldData.parent][fieldData.key][`value_${defaultEnvironmentLocaleCode}`])) {
|
|
288
288
|
value = {
|
|
289
289
|
code: pimDetails[fieldData.parent][fieldData.key]?.code ||
|
|
290
290
|
pimDetails[fieldData.parent][fieldData.key] ||
|
|
@@ -292,7 +292,7 @@ const getProductFields = async (pimDetails) => {
|
|
|
292
292
|
};
|
|
293
293
|
}
|
|
294
294
|
else if (typeof pimDetails[fieldData.parent][fieldData.key] !== "object" &&
|
|
295
|
-
(utils_1.sanitizeValue(pimDetails[fieldData.parent][fieldData.key]) ||
|
|
295
|
+
((0, utils_1.sanitizeValue)(pimDetails[fieldData.parent][fieldData.key]) ||
|
|
296
296
|
pimDetails[fieldData.parent][fieldData.key] === false)) {
|
|
297
297
|
value = pimDetails[fieldData.parent][fieldData.key];
|
|
298
298
|
}
|
|
@@ -305,7 +305,7 @@ const getProductFields = async (pimDetails) => {
|
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
else {
|
|
308
|
-
logs_1.log(`${fieldData.parent}.${fieldData.key} product field not found on the pim or null`);
|
|
308
|
+
(0, logs_1.log)(`${fieldData.parent}.${fieldData.key} product field not found on the pim or null`);
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
else {
|
|
@@ -313,8 +313,8 @@ const getProductFields = async (pimDetails) => {
|
|
|
313
313
|
if (Array.isArray(pimDetails[fieldData.key])) {
|
|
314
314
|
pimDetails[fieldData.key].forEach((item) => {
|
|
315
315
|
if (item.code &&
|
|
316
|
-
utils_1.sanitizeValue(item.code) &&
|
|
317
|
-
utils_1.sanitizeValue(item[`value_${defaultEnvironmentLocaleCode}`])) {
|
|
316
|
+
(0, utils_1.sanitizeValue)(item.code) &&
|
|
317
|
+
(0, utils_1.sanitizeValue)(item[`value_${defaultEnvironmentLocaleCode}`])) {
|
|
318
318
|
if (!productFields?.[fieldData.key]) {
|
|
319
319
|
productFields[fieldData.key] = [];
|
|
320
320
|
}
|
|
@@ -327,8 +327,8 @@ const getProductFields = async (pimDetails) => {
|
|
|
327
327
|
else {
|
|
328
328
|
let value = "";
|
|
329
329
|
if (pimDetails[fieldData.key]?.code &&
|
|
330
|
-
utils_1.sanitizeValue(pimDetails[fieldData.key].code) &&
|
|
331
|
-
utils_1.sanitizeValue(pimDetails[fieldData.key][`value_${defaultEnvironmentLocaleCode}`])) {
|
|
330
|
+
(0, utils_1.sanitizeValue)(pimDetails[fieldData.key].code) &&
|
|
331
|
+
(0, utils_1.sanitizeValue)(pimDetails[fieldData.key][`value_${defaultEnvironmentLocaleCode}`])) {
|
|
332
332
|
value = {
|
|
333
333
|
code: pimDetails[fieldData.key]?.code ||
|
|
334
334
|
pimDetails[fieldData.key] ||
|
|
@@ -336,7 +336,7 @@ const getProductFields = async (pimDetails) => {
|
|
|
336
336
|
};
|
|
337
337
|
}
|
|
338
338
|
else if (typeof pimDetails[fieldData.key] !== "object" &&
|
|
339
|
-
(utils_1.sanitizeValue(pimDetails[fieldData.key]) ||
|
|
339
|
+
((0, utils_1.sanitizeValue)(pimDetails[fieldData.key]) ||
|
|
340
340
|
pimDetails[fieldData.key] === false)) {
|
|
341
341
|
value = pimDetails[fieldData.key];
|
|
342
342
|
}
|
|
@@ -346,17 +346,17 @@ const getProductFields = async (pimDetails) => {
|
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
348
|
else {
|
|
349
|
-
logs_1.log(`${fieldData.key} product field not found on the pim`);
|
|
349
|
+
(0, logs_1.log)(`${fieldData.key} product field not found on the pim`);
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
});
|
|
353
353
|
productFields.certifications = [];
|
|
354
354
|
for (const certificationField of exports.certificationFields) {
|
|
355
355
|
if (productFields?.[certificationField]) {
|
|
356
|
-
logs_1.log(`Manage certifications field: ${certificationField}`);
|
|
356
|
+
(0, logs_1.log)(`Manage certifications field: ${certificationField}`);
|
|
357
357
|
for (const [key, values] of Object.entries(productFields[certificationField])) {
|
|
358
358
|
if (!exports.excludeCertificationFieldsKeys.includes(key)) {
|
|
359
|
-
logs_1.log(`Add ${key} values to productFields.certifications`);
|
|
359
|
+
(0, logs_1.log)(`Add ${key} values to productFields.certifications`);
|
|
360
360
|
productFields.certifications =
|
|
361
361
|
productFields.certifications.concat(values);
|
|
362
362
|
}
|
|
@@ -364,9 +364,9 @@ const getProductFields = async (pimDetails) => {
|
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
if (productFields.certifications.length) {
|
|
367
|
-
logs_1.log(`Remove unwanted values to productFields.certifications`);
|
|
367
|
+
(0, logs_1.log)(`Remove unwanted values to productFields.certifications`);
|
|
368
368
|
productFields.certifications = productFields.certifications.filter((value) => {
|
|
369
|
-
return utils_1.sanitizeValue(value?.code);
|
|
369
|
+
return (0, utils_1.sanitizeValue)(value?.code);
|
|
370
370
|
});
|
|
371
371
|
}
|
|
372
372
|
return productFields;
|
|
@@ -388,7 +388,7 @@ const getProductAssets = async (pimAssets, productCode) => {
|
|
|
388
388
|
const assetCode = pimAsset?.assetType?.code;
|
|
389
389
|
const md5 = pimAsset?.md5;
|
|
390
390
|
if (!assetCode || !md5) {
|
|
391
|
-
logs_1.log(`No assetCode or md5 found for product: ${productCode} assetURL: ${pimAsset.url}`, "WARN");
|
|
391
|
+
(0, logs_1.log)(`No assetCode or md5 found for product: ${productCode} assetURL: ${pimAsset.url}`, "WARN");
|
|
392
392
|
continue;
|
|
393
393
|
}
|
|
394
394
|
if (!assets?.[assetCode]) {
|
|
@@ -407,20 +407,20 @@ const getProductAssets = async (pimAssets, productCode) => {
|
|
|
407
407
|
}
|
|
408
408
|
else {
|
|
409
409
|
const path = `product-assets/${md5}`;
|
|
410
|
-
const fileName = utils_1.basename(pimAsset.url);
|
|
411
|
-
const assetAlreadyExists = await s3_1.getFileFromS3(`${path}/${fileName}`, true);
|
|
410
|
+
const fileName = (0, utils_1.basename)(pimAsset.url);
|
|
411
|
+
const assetAlreadyExists = await (0, s3_1.getFileFromS3)(`${path}/${fileName}`, true);
|
|
412
412
|
if (assetAlreadyExists) {
|
|
413
|
-
logs_1.log(`Asset aleady exists: ${assetAlreadyExists}`);
|
|
413
|
+
(0, logs_1.log)(`Asset aleady exists: ${assetAlreadyExists}`);
|
|
414
414
|
assetUrl = assetAlreadyExists;
|
|
415
415
|
}
|
|
416
416
|
else {
|
|
417
|
-
logs_1.log(`Asset not exists, importing it to S3 path: ${path}/${fileName}`);
|
|
417
|
+
(0, logs_1.log)(`Asset not exists, importing it to S3 path: ${path}/${fileName}`);
|
|
418
418
|
try {
|
|
419
|
-
const res = await s3_1.upload(pimAsset.url, fileName, path);
|
|
419
|
+
const res = await (0, s3_1.upload)(pimAsset.url, fileName, path);
|
|
420
420
|
assetUrl = res.Location;
|
|
421
421
|
}
|
|
422
422
|
catch (err) {
|
|
423
|
-
logs_1.log(`Unable to upload file: ${err.response.status} - ${err.response.statusText}`, "WARN");
|
|
423
|
+
(0, logs_1.log)(`Unable to upload file: ${err.response.status} - ${err.response.statusText}`, "WARN");
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
426
|
}
|
|
@@ -429,226 +429,226 @@ const getProductAssets = async (pimAssets, productCode) => {
|
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
431
|
else {
|
|
432
|
-
logs_1.log(`The asset ${pimAsset?.assetType} cannot be imported beacuse the url or assetType.code parameters are empty`, "WARN");
|
|
432
|
+
(0, logs_1.log)(`The asset ${pimAsset?.assetType} cannot be imported beacuse the url or assetType.code parameters are empty`, "WARN");
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
return assets;
|
|
436
436
|
};
|
|
437
437
|
const getProductData = async (productEntry, productDetails) => {
|
|
438
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
438
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
439
439
|
const data = {
|
|
440
440
|
fields: productEntry?.fields || {},
|
|
441
441
|
};
|
|
442
|
-
data.fields.name = utils_1.getPimTranslations(productDetails, "webNaming", productDetails.name, 255);
|
|
443
|
-
data.fields = await contentful_1.addFieldValue(data, "code", productDetails.code);
|
|
444
|
-
data.fields.description = utils_1.getPimTranslations(productDetails, "description1");
|
|
445
|
-
data.fields.excerpt = utils_1.getPimTranslations(productDetails, "description2");
|
|
446
|
-
data.fields.note = utils_1.getPimTranslations(productDetails, "note");
|
|
442
|
+
data.fields.name = (0, utils_1.getPimTranslations)(productDetails, "webNaming", productDetails.name, 255);
|
|
443
|
+
data.fields = await (0, contentful_1.addFieldValue)(data, "code", productDetails.code);
|
|
444
|
+
data.fields.description = (0, utils_1.getPimTranslations)(productDetails, "description1");
|
|
445
|
+
data.fields.excerpt = (0, utils_1.getPimTranslations)(productDetails, "description2");
|
|
446
|
+
data.fields.note = (0, utils_1.getPimTranslations)(productDetails, "note");
|
|
447
447
|
const { currentCatalog, ...pimDetails } = productDetails;
|
|
448
|
-
logs_1.log(`Set productFields`);
|
|
448
|
+
(0, logs_1.log)(`Set productFields`);
|
|
449
449
|
const productFields = await getProductFields(pimDetails);
|
|
450
|
-
data.fields = await contentful_1.addFieldValue(data, "productFields", productFields);
|
|
450
|
+
data.fields = await (0, contentful_1.addFieldValue)(data, "productFields", productFields);
|
|
451
451
|
const catalog = productDetails?.currentCatalog?.catalogCode || "";
|
|
452
452
|
if (catalog) {
|
|
453
|
-
const catalogEntry = await contentful_1.getEntryByCode(catalog, "topicCatalog", "sys");
|
|
454
|
-
logs_1.log(`Set catalog relation: ${catalog}`);
|
|
455
|
-
data.fields = await contentful_1.addToRelationFields(data, "catalogs", catalogEntry.sys.id, true);
|
|
453
|
+
const catalogEntry = await (0, contentful_1.getEntryByCode)(catalog, "topicCatalog", "sys");
|
|
454
|
+
(0, logs_1.log)(`Set catalog relation: ${catalog}`);
|
|
455
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, "catalogs", catalogEntry.sys.id, true);
|
|
456
456
|
}
|
|
457
|
-
const categoriesFieldKey = "categories" + utils_1.capitalizeFirstLetter(catalog);
|
|
457
|
+
const categoriesFieldKey = "categories" + (0, utils_1.capitalizeFirstLetter)(catalog);
|
|
458
458
|
if (catalog && productDetails?.currentCatalog?.categoryCode) {
|
|
459
|
-
const categoryTopicCode = catalogs_1.getCategoryTopicCode(productDetails.currentCatalog.categoryCode, catalog);
|
|
460
|
-
const categoryEntry = await contentful_1.getEntryByCode(categoryTopicCode, "topicCategory", "sys");
|
|
459
|
+
const categoryTopicCode = (0, catalogs_1.getCategoryTopicCode)(productDetails.currentCatalog.categoryCode, catalog);
|
|
460
|
+
const categoryEntry = await (0, contentful_1.getEntryByCode)(categoryTopicCode, "topicCategory", "sys");
|
|
461
461
|
if (!categoryEntry) {
|
|
462
|
-
logs_1.log(`The topicCategory with code ${categoryTopicCode} not found`, "WARN");
|
|
462
|
+
(0, logs_1.log)(`The topicCategory with code ${categoryTopicCode} not found`, "WARN");
|
|
463
463
|
}
|
|
464
464
|
else {
|
|
465
|
-
logs_1.log(`Set category relation: ${categoryTopicCode} in the field ${categoriesFieldKey}`);
|
|
466
|
-
data.fields = await contentful_1.addToRelationFields(data, categoriesFieldKey, categoryEntry.sys.id, true);
|
|
465
|
+
(0, logs_1.log)(`Set category relation: ${categoryTopicCode} in the field ${categoriesFieldKey}`);
|
|
466
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, categoriesFieldKey, categoryEntry.sys.id, true);
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
469
|
if (productDetails?.currentCatalog?.familyCode) {
|
|
470
|
-
const familyEntry = await contentful_1.getEntryByCode(productDetails.currentCatalog.familyCode, "topicFamily", "sys");
|
|
470
|
+
const familyEntry = await (0, contentful_1.getEntryByCode)(productDetails.currentCatalog.familyCode, "topicFamily", "sys");
|
|
471
471
|
if (!familyEntry) {
|
|
472
|
-
logs_1.log(`The topicFamily with code ${productDetails.currentCatalog.familyCode} not found`, "WARN");
|
|
472
|
+
(0, logs_1.log)(`The topicFamily with code ${productDetails.currentCatalog.familyCode} not found`, "WARN");
|
|
473
473
|
}
|
|
474
474
|
else {
|
|
475
|
-
logs_1.log(`Set family relation: ${productDetails.currentCatalog.familyCode}`);
|
|
476
|
-
data.fields = await contentful_1.addToRelationFields(data, "families", familyEntry.sys.id, true);
|
|
475
|
+
(0, logs_1.log)(`Set family relation: ${productDetails.currentCatalog.familyCode}`);
|
|
476
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, "families", familyEntry.sys.id, true);
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
|
-
const subFamiliesFieldKey = "subFamilies" + utils_1.capitalizeFirstLetter(catalog);
|
|
479
|
+
const subFamiliesFieldKey = "subFamilies" + (0, utils_1.capitalizeFirstLetter)(catalog);
|
|
480
480
|
if (productDetails?.currentCatalog?.subFamilyCode) {
|
|
481
|
-
const subFamilyEntry = await contentful_1.getEntryByCode(productDetails.currentCatalog.subFamilyCode, "topicSubFamily", "sys");
|
|
481
|
+
const subFamilyEntry = await (0, contentful_1.getEntryByCode)(productDetails.currentCatalog.subFamilyCode, "topicSubFamily", "sys");
|
|
482
482
|
if (!subFamilyEntry) {
|
|
483
|
-
logs_1.log(`The topicSubFamily with code ${productDetails.currentCatalog.subFamilyCode} not found`, "WARN");
|
|
483
|
+
(0, logs_1.log)(`The topicSubFamily with code ${productDetails.currentCatalog.subFamilyCode} not found`, "WARN");
|
|
484
484
|
}
|
|
485
485
|
else {
|
|
486
|
-
logs_1.log(`Set subFamily relation: ${productDetails.currentCatalog.subFamilyCode} in the field ${subFamiliesFieldKey}`);
|
|
487
|
-
data.fields = await contentful_1.addToRelationFields(data, subFamiliesFieldKey, subFamilyEntry.sys.id, true);
|
|
486
|
+
(0, logs_1.log)(`Set subFamily relation: ${productDetails.currentCatalog.subFamilyCode} in the field ${subFamiliesFieldKey}`);
|
|
487
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, subFamiliesFieldKey, subFamilyEntry.sys.id, true);
|
|
488
488
|
}
|
|
489
489
|
}
|
|
490
490
|
if (productDetails?.productLine) {
|
|
491
|
-
const productLineEntry = await contentful_1.getEntryByCode(productDetails.productLine.code, "topicProductLine", "sys");
|
|
491
|
+
const productLineEntry = await (0, contentful_1.getEntryByCode)(productDetails.productLine.code, "topicProductLine", "sys");
|
|
492
492
|
if (!productLineEntry) {
|
|
493
|
-
logs_1.log(`The topicProductLine with code ${productDetails.productLine.code} not found`, "WARN");
|
|
493
|
+
(0, logs_1.log)(`The topicProductLine with code ${productDetails.productLine.code} not found`, "WARN");
|
|
494
494
|
}
|
|
495
495
|
else {
|
|
496
|
-
logs_1.log(`Set productLine relation: ${productDetails.productLine.code}`);
|
|
497
|
-
data.fields = await contentful_1.addToRelationFields(data, "productLine", productLineEntry.sys.id);
|
|
496
|
+
(0, logs_1.log)(`Set productLine relation: ${productDetails.productLine.code}`);
|
|
497
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, "productLine", productLineEntry.sys.id);
|
|
498
498
|
}
|
|
499
499
|
}
|
|
500
500
|
if (productDetails?.productLineDetail) {
|
|
501
|
-
const productSubLineEntry = await contentful_1.getEntryByCode(productDetails.productLineDetail.code, "topicProductSubLine", "sys");
|
|
501
|
+
const productSubLineEntry = await (0, contentful_1.getEntryByCode)(productDetails.productLineDetail.code, "topicProductSubLine", "sys");
|
|
502
502
|
if (!productSubLineEntry) {
|
|
503
|
-
logs_1.log(`The topicProductSubLine with code ${productDetails.productLineDetail.code} not found`, "WARN");
|
|
503
|
+
(0, logs_1.log)(`The topicProductSubLine with code ${productDetails.productLineDetail.code} not found`, "WARN");
|
|
504
504
|
}
|
|
505
505
|
else {
|
|
506
|
-
logs_1.log(`Set productSubLine relation: ${productDetails.productLineDetail.code}`);
|
|
507
|
-
data.fields = await contentful_1.addToRelationFields(data, "productSubLine", productSubLineEntry.sys.id);
|
|
506
|
+
(0, logs_1.log)(`Set productSubLine relation: ${productDetails.productLineDetail.code}`);
|
|
507
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, "productSubLine", productSubLineEntry.sys.id);
|
|
508
508
|
}
|
|
509
509
|
}
|
|
510
|
-
const modelsFieldKey = "models" + utils_1.capitalizeFirstLetter(catalog);
|
|
510
|
+
const modelsFieldKey = "models" + (0, utils_1.capitalizeFirstLetter)(catalog);
|
|
511
511
|
if (productDetails?.models) {
|
|
512
|
-
logs_1.log(`Set ${productDetails.models.length} model relations`);
|
|
512
|
+
(0, logs_1.log)(`Set ${productDetails.models.length} model relations`);
|
|
513
513
|
const modelCodes = productDetails.models.map((model) => {
|
|
514
514
|
return model.data.code;
|
|
515
515
|
});
|
|
516
|
-
const topicModelEntries = await contentful_1.getAllEntriesByCodes(modelCodes, "topicModel", "sys,fields.catalog");
|
|
516
|
+
const topicModelEntries = await (0, contentful_1.getAllEntriesByCodes)(modelCodes, "topicModel", "sys,fields.catalog");
|
|
517
517
|
if (topicModelEntries.length) {
|
|
518
518
|
for (const topicModelEntry of topicModelEntries) {
|
|
519
519
|
if (topicModelEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode]?.sys
|
|
520
520
|
?.id !== catalog) {
|
|
521
|
-
logs_1.log(`The model ${topicModelEntry.sys.id} belongs to the catalog ${topicModelEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode]?.sys?.id} and will not be imported`);
|
|
521
|
+
(0, logs_1.log)(`The model ${topicModelEntry.sys.id} belongs to the catalog ${topicModelEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode]?.sys?.id} and will not be imported`);
|
|
522
522
|
continue;
|
|
523
523
|
}
|
|
524
524
|
else {
|
|
525
|
-
logs_1.log(`Set relation with model ${topicModelEntry.sys.id} in the field ${modelsFieldKey}`);
|
|
526
|
-
data.fields = await contentful_1.addToRelationFields(data, modelsFieldKey, topicModelEntry.sys.id, true);
|
|
525
|
+
(0, logs_1.log)(`Set relation with model ${topicModelEntry.sys.id} in the field ${modelsFieldKey}`);
|
|
526
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, modelsFieldKey, topicModelEntry.sys.id, true);
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
529
|
}
|
|
530
530
|
else {
|
|
531
|
-
logs_1.log(`No topicModel found for product ${productDetails.code}: ${modelCodes.join(",")}`, "WARN");
|
|
531
|
+
(0, logs_1.log)(`No topicModel found for product ${productDetails.code}: ${modelCodes.join(",")}`, "WARN");
|
|
532
532
|
}
|
|
533
533
|
}
|
|
534
|
-
const subModelsFieldKey = "subModels" + utils_1.capitalizeFirstLetter(catalog);
|
|
534
|
+
const subModelsFieldKey = "subModels" + (0, utils_1.capitalizeFirstLetter)(catalog);
|
|
535
535
|
if (productDetails?.submodels) {
|
|
536
|
-
logs_1.log(`Set ${productDetails.submodels.length} subModels relations`);
|
|
536
|
+
(0, logs_1.log)(`Set ${productDetails.submodels.length} subModels relations`);
|
|
537
537
|
const subModelsCodes = productDetails.submodels.map((subModel) => {
|
|
538
538
|
return subModel.data.code;
|
|
539
539
|
});
|
|
540
|
-
const topicSubModelEntries = await contentful_1.getAllEntriesByCodes(subModelsCodes, "topicSubModel", "sys,fields.catalog");
|
|
540
|
+
const topicSubModelEntries = await (0, contentful_1.getAllEntriesByCodes)(subModelsCodes, "topicSubModel", "sys,fields.catalog");
|
|
541
541
|
if (topicSubModelEntries.length) {
|
|
542
542
|
for (const topicSubModelEntry of topicSubModelEntries) {
|
|
543
543
|
if (topicSubModelEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode]
|
|
544
544
|
?.sys?.id !== catalog) {
|
|
545
|
-
logs_1.log(`The subModel ${topicSubModelEntry.sys.id} belongs to the catalog ${topicSubModelEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode]?.sys?.id} and will not be imported`);
|
|
545
|
+
(0, logs_1.log)(`The subModel ${topicSubModelEntry.sys.id} belongs to the catalog ${topicSubModelEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode]?.sys?.id} and will not be imported`);
|
|
546
546
|
continue;
|
|
547
547
|
}
|
|
548
548
|
else {
|
|
549
|
-
logs_1.log(`Set relation with subModel ${topicSubModelEntry.sys.id} in the field ${subModelsFieldKey}`);
|
|
550
|
-
data.fields = await contentful_1.addToRelationFields(data, subModelsFieldKey, topicSubModelEntry.sys.id, true);
|
|
549
|
+
(0, logs_1.log)(`Set relation with subModel ${topicSubModelEntry.sys.id} in the field ${subModelsFieldKey}`);
|
|
550
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, subModelsFieldKey, topicSubModelEntry.sys.id, true);
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
553
|
}
|
|
554
554
|
else {
|
|
555
|
-
logs_1.log(`No topicSubModel found for product ${productDetails.code}: ${subModelsCodes.join(",")}`, "WARN");
|
|
555
|
+
(0, logs_1.log)(`No topicSubModel found for product ${productDetails.code}: ${subModelsCodes.join(",")}`, "WARN");
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
558
|
if (productDetails?.assets) {
|
|
559
559
|
const pimAssetThumb = productDetails.assets.find((asset) => asset?.assetType.code === "THUMB");
|
|
560
560
|
if (pimAssetThumb?.url && pimAssetThumb?.md5) {
|
|
561
|
-
logs_1.log(`Set THUMB`);
|
|
561
|
+
(0, logs_1.log)(`Set THUMB`);
|
|
562
562
|
const wrapperImgixID = pimAssetThumb.md5;
|
|
563
|
-
let wrapperImgix = await contentful_1.getEntryByID(wrapperImgixID, "wrapperImgix", "sys,fields");
|
|
563
|
+
let wrapperImgix = await (0, contentful_1.getEntryByID)(wrapperImgixID, "wrapperImgix", "sys,fields");
|
|
564
564
|
if (wrapperImgix) {
|
|
565
|
-
logs_1.log(`wrapperImgix with id ${wrapperImgixID} already exists`);
|
|
566
|
-
const imgixBasename = utils_1.basename(wrapperImgix.fields.imgixData[defaultEnvironmentLocaleCode].url);
|
|
567
|
-
const pimBasename = utils_1.basename(pimAssetThumb.url);
|
|
565
|
+
(0, logs_1.log)(`wrapperImgix with id ${wrapperImgixID} already exists`);
|
|
566
|
+
const imgixBasename = (0, utils_1.basename)(wrapperImgix.fields.imgixData[defaultEnvironmentLocaleCode].url);
|
|
567
|
+
const pimBasename = (0, utils_1.basename)(pimAssetThumb.url);
|
|
568
568
|
if (imgixBasename !== pimBasename) {
|
|
569
|
-
logs_1.log(`Update img url from ${imgixBasename} to ${pimBasename}`);
|
|
570
|
-
const newImgixUrl = imgix_1.getImgixPimUrlByOriginPath(imgix_1.getOriginPathByPimUrl(pimAssetThumb.url));
|
|
569
|
+
(0, logs_1.log)(`Update img url from ${imgixBasename} to ${pimBasename}`);
|
|
570
|
+
const newImgixUrl = (0, imgix_1.getImgixPimUrlByOriginPath)((0, imgix_1.getOriginPathByPimUrl)(pimAssetThumb.url));
|
|
571
571
|
wrapperImgix.fields.imgixData[defaultEnvironmentLocaleCode].url =
|
|
572
572
|
newImgixUrl;
|
|
573
573
|
wrapperImgix = await wrapperImgix.update();
|
|
574
574
|
if (wrapperImgix.isPublished()) {
|
|
575
575
|
wrapperImgix = await wrapperImgix.publish();
|
|
576
576
|
}
|
|
577
|
-
logs_1.log(`The new imgix url is: ${newImgixUrl}`);
|
|
577
|
+
(0, logs_1.log)(`The new imgix url is: ${newImgixUrl}`);
|
|
578
578
|
}
|
|
579
579
|
else {
|
|
580
|
-
logs_1.log(`wrapperImgix basename matched`);
|
|
580
|
+
(0, logs_1.log)(`wrapperImgix basename matched`);
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
583
|
else {
|
|
584
|
-
logs_1.log(`Add thumbnail imgix wrapper with id ${wrapperImgixID} to Contentful`);
|
|
585
|
-
const altText = utils_1.getPimTranslations(pimAssetThumb, "title");
|
|
584
|
+
(0, logs_1.log)(`Add thumbnail imgix wrapper with id ${wrapperImgixID} to Contentful`);
|
|
585
|
+
const altText = (0, utils_1.getPimTranslations)(pimAssetThumb, "title");
|
|
586
586
|
if (altText[defaultEnvironmentLocaleCode] === null) {
|
|
587
587
|
altText[defaultEnvironmentLocaleCode] = "Thumbnail";
|
|
588
588
|
}
|
|
589
|
-
const wrapperImgixAttributes = imgix_1.getDefaultWrapperImgixAttributesByPimUrl(pimAssetThumb.url);
|
|
589
|
+
const wrapperImgixAttributes = (0, imgix_1.getDefaultWrapperImgixAttributesByPimUrl)(pimAssetThumb.url);
|
|
590
590
|
if (wrapperImgixAttributes) {
|
|
591
591
|
const wrapperImgixFields = {
|
|
592
592
|
internalName: `${pimAssetThumb?.assetType?.code}_${pimAssetThumb.md5}`,
|
|
593
593
|
imgixData: wrapperImgixAttributes,
|
|
594
594
|
altText,
|
|
595
595
|
};
|
|
596
|
-
wrapperImgix = await contentful_1.createWrapperImgix(wrapperImgixID, wrapperImgixFields);
|
|
596
|
+
wrapperImgix = await (0, contentful_1.createWrapperImgix)(wrapperImgixID, wrapperImgixFields);
|
|
597
597
|
}
|
|
598
598
|
else {
|
|
599
|
-
logs_1.log(`Unable to create wrapperimagix because the image was not found on imgix. Image URL: ${pimAssetThumb.url}`, "WARN");
|
|
599
|
+
(0, logs_1.log)(`Unable to create wrapperimagix because the image was not found on imgix. Image URL: ${pimAssetThumb.url}`, "WARN");
|
|
600
600
|
}
|
|
601
601
|
}
|
|
602
602
|
if (wrapperImgix?.sys?.id) {
|
|
603
|
-
data.fields = await contentful_1.addToRelationFields(data, "thumbnailImgix", wrapperImgix.sys.id);
|
|
603
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, "thumbnailImgix", wrapperImgix.sys.id);
|
|
604
604
|
}
|
|
605
605
|
}
|
|
606
606
|
else {
|
|
607
|
-
logs_1.log(`No thumbnail found or md5 is null`, "WARN");
|
|
607
|
+
(0, logs_1.log)(`No thumbnail found or md5 is null`, "WARN");
|
|
608
608
|
}
|
|
609
609
|
const pimOtherAssets = productDetails.assets.filter((asset) => asset?.assetType.code !== "THUMB");
|
|
610
610
|
if (pimOtherAssets.length) {
|
|
611
|
-
logs_1.log(`Uploading ${pimOtherAssets.length} assets to S3`);
|
|
611
|
+
(0, logs_1.log)(`Uploading ${pimOtherAssets.length} assets to S3`);
|
|
612
612
|
const assets = await getProductAssets(pimOtherAssets, productDetails.code);
|
|
613
613
|
if (assets) {
|
|
614
|
-
data.fields = await contentful_1.addFieldValue(data, "assets", assets);
|
|
614
|
+
data.fields = await (0, contentful_1.addFieldValue)(data, "assets", assets);
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
617
|
else {
|
|
618
|
-
logs_1.log(`No other assets found`, "WARN");
|
|
618
|
+
(0, logs_1.log)(`No other assets found`, "WARN");
|
|
619
619
|
}
|
|
620
620
|
}
|
|
621
|
-
data.fields = await contentful_1.addFieldValue(data, "lastPimSyncDate", utils_1.getLocalISOTime());
|
|
621
|
+
data.fields = await (0, contentful_1.addFieldValue)(data, "lastPimSyncDate", (0, utils_1.getLocalISOTime)());
|
|
622
622
|
if (productDetails.designers) {
|
|
623
623
|
for (const designer of productDetails.designers) {
|
|
624
|
-
data.fields = await designers_1.addDesignerData(data, designer, true);
|
|
624
|
+
data.fields = await (0, designers_1.addDesignerData)(data, designer, true);
|
|
625
625
|
}
|
|
626
626
|
}
|
|
627
627
|
else {
|
|
628
|
-
logs_1.log(`No designers found`, "WARN");
|
|
628
|
+
(0, logs_1.log)(`No designers found`, "WARN");
|
|
629
629
|
if (data.fields.designers?.[defaultEnvironmentLocaleCode]) {
|
|
630
|
-
logs_1.log(`remove old designers relation`);
|
|
630
|
+
(0, logs_1.log)(`remove old designers relation`);
|
|
631
631
|
data.fields.designers = [];
|
|
632
632
|
}
|
|
633
633
|
}
|
|
634
634
|
data.fields.autoDescription = await getTopicProductAutodescription(data.fields);
|
|
635
635
|
if (productDetails?.destinations?.length) {
|
|
636
|
-
logs_1.log(`set destinations`);
|
|
637
|
-
data.fields = await contentful_1.addFieldValue(data, "destinations", productDetails.destinations.map((item) => item.code));
|
|
636
|
+
(0, logs_1.log)(`set destinations`);
|
|
637
|
+
data.fields = await (0, contentful_1.addFieldValue)(data, "destinations", productDetails.destinations.map((item) => item.code));
|
|
638
638
|
}
|
|
639
639
|
else {
|
|
640
|
-
logs_1.log(`destinations not found`, "WARN");
|
|
640
|
+
(0, logs_1.log)(`destinations not found`, "WARN");
|
|
641
641
|
}
|
|
642
642
|
const productEntryId = getTopicProductIdByCode(productDetails.code);
|
|
643
643
|
const { path, fileName } = getProductPayloadS3Details(productEntryId);
|
|
644
|
-
logs_1.log(`Uploading "${fileName}" to S3 path "${path}"`);
|
|
645
|
-
const { Location } = await s3_1.saveJsonToS3(pimDetails, fileName, path);
|
|
646
|
-
data.fields = await contentful_1.addFieldValue(data, "endpointPayload", Location);
|
|
647
|
-
logs_1.log(`"${fileName}" uploaded to ${Location}`);
|
|
644
|
+
(0, logs_1.log)(`Uploading "${fileName}" to S3 path "${path}"`);
|
|
645
|
+
const { Location } = await (0, s3_1.saveJsonToS3)(pimDetails, fileName, path);
|
|
646
|
+
data.fields = await (0, contentful_1.addFieldValue)(data, "endpointPayload", Location);
|
|
647
|
+
(0, logs_1.log)(`"${fileName}" uploaded to ${Location}`);
|
|
648
648
|
return data;
|
|
649
649
|
};
|
|
650
650
|
const getProductColourVariantsData = async (topicProductColourVariantsCode, productEntryId, topicProductColourVariants) => {
|
|
651
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
651
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
652
652
|
const data = {
|
|
653
653
|
fields: {
|
|
654
654
|
code: {},
|
|
@@ -660,50 +660,50 @@ const getProductColourVariantsData = async (topicProductColourVariantsCode, prod
|
|
|
660
660
|
}
|
|
661
661
|
data.fields.code[defaultEnvironmentLocaleCode] =
|
|
662
662
|
topicProductColourVariantsCode;
|
|
663
|
-
data.fields = await contentful_1.addToRelationFields(data, "products", productEntryId, true);
|
|
664
|
-
data.fields.lastPimSyncDate[defaultEnvironmentLocaleCode] = utils_1.getLocalISOTime();
|
|
663
|
+
data.fields = await (0, contentful_1.addToRelationFields)(data, "products", productEntryId, true);
|
|
664
|
+
data.fields.lastPimSyncDate[defaultEnvironmentLocaleCode] = (0, utils_1.getLocalISOTime)();
|
|
665
665
|
return data;
|
|
666
666
|
};
|
|
667
667
|
const addProductColourVariants = async (colourVariants, productEntryId) => {
|
|
668
668
|
for (const colourVariant of colourVariants) {
|
|
669
669
|
const topicId = `PCV_${colourVariant.code}`;
|
|
670
|
-
let topicProductColourVariants = await contentful_1.getEntryByID(topicId, "topicProductColourVariants");
|
|
670
|
+
let topicProductColourVariants = await (0, contentful_1.getEntryByID)(topicId, "topicProductColourVariants");
|
|
671
671
|
const data = await getProductColourVariantsData(colourVariant.code, productEntryId, topicProductColourVariants);
|
|
672
672
|
if (!topicProductColourVariants) {
|
|
673
|
-
logs_1.log(`Create topicProductColourVariants with code ${topicId}`);
|
|
674
|
-
topicProductColourVariants = await contentful_1.createEntryWithId("topicProductColourVariants", topicId, data, true);
|
|
673
|
+
(0, logs_1.log)(`Create topicProductColourVariants with code ${topicId}`);
|
|
674
|
+
topicProductColourVariants = await (0, contentful_1.createEntryWithId)("topicProductColourVariants", topicId, data, true);
|
|
675
675
|
}
|
|
676
676
|
else {
|
|
677
|
-
logs_1.log(`Update topicProductColourVariants with code ${topicId}`);
|
|
678
|
-
topicProductColourVariants = await contentful_1.updateEntry(topicProductColourVariants, data, topicProductColourVariants.isPublished());
|
|
677
|
+
(0, logs_1.log)(`Update topicProductColourVariants with code ${topicId}`);
|
|
678
|
+
topicProductColourVariants = await (0, contentful_1.updateEntry)(topicProductColourVariants, data, topicProductColourVariants.isPublished());
|
|
679
679
|
}
|
|
680
680
|
}
|
|
681
681
|
};
|
|
682
682
|
const addProduct = async (productDetails) => {
|
|
683
683
|
const title = productDetails.webNaming || productDetails.name;
|
|
684
684
|
if (!title) {
|
|
685
|
-
logs_1.log(`Can't possible to import the product ${productDetails.code}, name and webNaming not found`);
|
|
685
|
+
(0, logs_1.log)(`Can't possible to import the product ${productDetails.code}, name and webNaming not found`);
|
|
686
686
|
return false;
|
|
687
687
|
}
|
|
688
|
-
logs_1.log(`If exists get entry with code: ${productDetails.code}`);
|
|
689
|
-
let productEntry = await contentful_1.getEntryByCode(productDetails.code, "topicProduct");
|
|
688
|
+
(0, logs_1.log)(`If exists get entry with code: ${productDetails.code}`);
|
|
689
|
+
let productEntry = await (0, contentful_1.getEntryByCode)(productDetails.code, "topicProduct");
|
|
690
690
|
const productData = await getProductData(productEntry, productDetails);
|
|
691
691
|
let publishEntry = false;
|
|
692
692
|
if (!productEntry) {
|
|
693
693
|
const productEntryId = getTopicProductIdByCode(productDetails.code);
|
|
694
|
-
logs_1.log(`Create product with code ${productEntryId}`);
|
|
695
|
-
productEntry = await contentful_1.createEntryWithId("topicProduct", productEntryId, productData, false);
|
|
694
|
+
(0, logs_1.log)(`Create product with code ${productEntryId}`);
|
|
695
|
+
productEntry = await (0, contentful_1.createEntryWithId)("topicProduct", productEntryId, productData, false);
|
|
696
696
|
}
|
|
697
697
|
else {
|
|
698
698
|
if (productEntry.isArchived()) {
|
|
699
|
-
logs_1.log(`Unarchive product with code ${productDetails.code}`);
|
|
699
|
+
(0, logs_1.log)(`Unarchive product with code ${productDetails.code}`);
|
|
700
700
|
productEntry = await productEntry.unarchive();
|
|
701
701
|
}
|
|
702
|
-
logs_1.log(`Update product with code ${productDetails.code}`);
|
|
703
|
-
productEntry = await contentful_1.updateEntry(productEntry, productData, productEntry.isPublished());
|
|
702
|
+
(0, logs_1.log)(`Update product with code ${productDetails.code}`);
|
|
703
|
+
productEntry = await (0, contentful_1.updateEntry)(productEntry, productData, productEntry.isPublished());
|
|
704
704
|
publishEntry = productEntry?.isPublished();
|
|
705
705
|
}
|
|
706
|
-
logs_1.log(`Publish entry: ${publishEntry}`);
|
|
706
|
+
(0, logs_1.log)(`Publish entry: ${publishEntry}`);
|
|
707
707
|
await createOrUpdateProductPage(productEntry, !publishEntry);
|
|
708
708
|
if (productDetails?.colourVariants) {
|
|
709
709
|
await addProductColourVariants(productDetails.colourVariants, productEntry.sys.id);
|
|
@@ -712,17 +712,17 @@ const addProduct = async (productDetails) => {
|
|
|
712
712
|
};
|
|
713
713
|
const validateImportProduct = (productDetails, catalog, familyCodeIn, subFamilyCodeIn) => {
|
|
714
714
|
if (!productDetails.currentCatalog?.catalogCode) {
|
|
715
|
-
logs_1.log(`The product ${productDetails.code} does not belong to the ${catalog} catalog or the catalog is not specified. Catalog code: ${productDetails.currentCatalog?.catalogCode}`, "WARN");
|
|
715
|
+
(0, logs_1.log)(`The product ${productDetails.code} does not belong to the ${catalog} catalog or the catalog is not specified. Catalog code: ${productDetails.currentCatalog?.catalogCode}`, "WARN");
|
|
716
716
|
return false;
|
|
717
717
|
}
|
|
718
718
|
if (familyCodeIn?.length &&
|
|
719
719
|
!familyCodeIn.includes(productDetails.currentCatalog?.familyCode)) {
|
|
720
|
-
logs_1.log(`The product ${productDetails.code} does not belong to any of the ${familyCodeIn.join(",")} families or the family is not specified. Family code: ${productDetails.currentCatalog?.familyCode}`, "WARN");
|
|
720
|
+
(0, logs_1.log)(`The product ${productDetails.code} does not belong to any of the ${familyCodeIn.join(",")} families or the family is not specified. Family code: ${productDetails.currentCatalog?.familyCode}`, "WARN");
|
|
721
721
|
return false;
|
|
722
722
|
}
|
|
723
723
|
if (subFamilyCodeIn?.length &&
|
|
724
724
|
!subFamilyCodeIn.includes(productDetails.currentCatalog?.subFamilyCode)) {
|
|
725
|
-
logs_1.log(`The product ${productDetails.code} does not belong to any of the ${subFamilyCodeIn.join(",")} subFamilies or the subFamily is not specified. SubFamily code: ${productDetails.currentCatalog?.subFamilyCode}`, "WARN");
|
|
725
|
+
(0, logs_1.log)(`The product ${productDetails.code} does not belong to any of the ${subFamilyCodeIn.join(",")} subFamilies or the subFamily is not specified. SubFamily code: ${productDetails.currentCatalog?.subFamilyCode}`, "WARN");
|
|
726
726
|
return false;
|
|
727
727
|
}
|
|
728
728
|
return true;
|
|
@@ -732,7 +732,7 @@ const importProduct = async (productDetails, catalog, familyCodeIn, subFamilyCod
|
|
|
732
732
|
if (!validateImportProduct(productDetails, catalog, familyCodeIn, subFamilyCodeIn)) {
|
|
733
733
|
return false;
|
|
734
734
|
}
|
|
735
|
-
logs_1.log(`Import product ${productDetails.code}`, "INFO");
|
|
735
|
+
(0, logs_1.log)(`Import product ${productDetails.code}`, "INFO");
|
|
736
736
|
const isTermsToAddCode = await isTermsToAdd(productDetails, catalog);
|
|
737
737
|
if (isTermsToAddCode) {
|
|
738
738
|
return false;
|
|
@@ -748,13 +748,13 @@ const importProduct = async (productDetails, catalog, familyCodeIn, subFamilyCod
|
|
|
748
748
|
const destinations = productDetails.destinations
|
|
749
749
|
?.map((item) => item.code)
|
|
750
750
|
.join(", ");
|
|
751
|
-
logs_1.log(`Product not to be imported: ${productDetails.code} - visibleToWeb = ${productDetails.visibleToWeb} - destinations = [${destinations}]`);
|
|
751
|
+
(0, logs_1.log)(`Product not to be imported: ${productDetails.code} - visibleToWeb = ${productDetails.visibleToWeb} - destinations = [${destinations}]`);
|
|
752
752
|
return false;
|
|
753
753
|
}
|
|
754
754
|
};
|
|
755
755
|
exports.importProduct = importProduct;
|
|
756
756
|
const setProductRelationships = async (code, fieldKey = null) => {
|
|
757
|
-
logs_1.log(`setProductRelationships - code: ${code} fieldKey: ${fieldKey}`, "INFO");
|
|
757
|
+
(0, logs_1.log)(`setProductRelationships - code: ${code} fieldKey: ${fieldKey}`, "INFO");
|
|
758
758
|
const fieldKeys = [
|
|
759
759
|
"accessories",
|
|
760
760
|
"accessoryOf",
|
|
@@ -764,33 +764,33 @@ const setProductRelationships = async (code, fieldKey = null) => {
|
|
|
764
764
|
"spareparts",
|
|
765
765
|
];
|
|
766
766
|
if (!fieldKey) {
|
|
767
|
-
logs_1.log(`The fieldKey parameter is empty so all fields will be imported: ${fieldKeys.join(",")} `);
|
|
767
|
+
(0, logs_1.log)(`The fieldKey parameter is empty so all fields will be imported: ${fieldKeys.join(",")} `);
|
|
768
768
|
}
|
|
769
769
|
const currentFieldKeys = fieldKey ? [fieldKey] : fieldKeys;
|
|
770
|
-
let productEntry = await contentful_1.getEntryByCode(code, "topicProduct");
|
|
770
|
+
let productEntry = await (0, contentful_1.getEntryByCode)(code, "topicProduct");
|
|
771
771
|
if (!productEntry) {
|
|
772
|
-
logs_1.log(`Product with code ${code} not found`, "WARN");
|
|
772
|
+
(0, logs_1.log)(`Product with code ${code} not found`, "WARN");
|
|
773
773
|
}
|
|
774
774
|
else if (productEntry.isArchived()) {
|
|
775
|
-
logs_1.log(`Product with code ${code} is archived`, "WARN");
|
|
775
|
+
(0, logs_1.log)(`Product with code ${code} is archived`, "WARN");
|
|
776
776
|
}
|
|
777
777
|
else if (!productEntry.isArchived()) {
|
|
778
778
|
const { path, fileName } = getProductPayloadS3Details(productEntry.sys.id);
|
|
779
|
-
logs_1.log(`Get payload from ${path}${fileName} S3 path`);
|
|
780
|
-
const productDetails = await s3_1.getFileFromS3(`${path}${fileName}`);
|
|
779
|
+
(0, logs_1.log)(`Get payload from ${path}${fileName} S3 path`);
|
|
780
|
+
const productDetails = await (0, s3_1.getFileFromS3)(`${path}${fileName}`);
|
|
781
781
|
if (productDetails) {
|
|
782
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
782
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
783
783
|
let update = false;
|
|
784
784
|
let fieldKeysCount = 0;
|
|
785
785
|
for (const currentFieldKey of currentFieldKeys) {
|
|
786
|
-
logs_1.log(`Set ${currentFieldKey} relations to product with code ${code}`);
|
|
786
|
+
(0, logs_1.log)(`Set ${currentFieldKey} relations to product with code ${code}`);
|
|
787
787
|
const fieldValues = productDetails[currentFieldKey];
|
|
788
788
|
if (fieldValues) {
|
|
789
789
|
const relationships = [];
|
|
790
790
|
const producRelationCodes = fieldValues.map((fieldValue) => {
|
|
791
791
|
return fieldValue.code;
|
|
792
792
|
});
|
|
793
|
-
const entries = await contentful_1.getAllEntriesByCodes(producRelationCodes, "topicProduct", "sys,fields.code");
|
|
793
|
+
const entries = await (0, contentful_1.getAllEntriesByCodes)(producRelationCodes, "topicProduct", "sys,fields.code");
|
|
794
794
|
for (const fieldValue of fieldValues) {
|
|
795
795
|
const entry = entries.find((currentEntry) => currentEntry.fields.code[defaultEnvironmentLocaleCode] ===
|
|
796
796
|
fieldValue.code);
|
|
@@ -803,16 +803,16 @@ const setProductRelationships = async (code, fieldKey = null) => {
|
|
|
803
803
|
});
|
|
804
804
|
}
|
|
805
805
|
else {
|
|
806
|
-
logs_1.log(`The product with ${fieldValue.code} code was not found, it cannot be associated with the ${currentFieldKey} field of product ${code}`);
|
|
806
|
+
(0, logs_1.log)(`The product with ${fieldValue.code} code was not found, it cannot be associated with the ${currentFieldKey} field of product ${code}`);
|
|
807
807
|
}
|
|
808
808
|
}
|
|
809
809
|
const prevItemsCount = productEntry?.fields[currentFieldKey]?.length || 0;
|
|
810
810
|
if (relationships.length || prevItemsCount > 0) {
|
|
811
811
|
if (!relationships.length && prevItemsCount > 0) {
|
|
812
|
-
logs_1.log(`No product relationships found of the field ${currentFieldKey} for the product ${code}, i remove ${prevItemsCount} pre-existing relationships`);
|
|
812
|
+
(0, logs_1.log)(`No product relationships found of the field ${currentFieldKey} for the product ${code}, i remove ${prevItemsCount} pre-existing relationships`);
|
|
813
813
|
}
|
|
814
814
|
else {
|
|
815
|
-
logs_1.log(`Founded ${relationships.length} relationships of ${producRelationCodes.length} PIM relationships for the field ${currentFieldKey} of product ${code}`);
|
|
815
|
+
(0, logs_1.log)(`Founded ${relationships.length} relationships of ${producRelationCodes.length} PIM relationships for the field ${currentFieldKey} of product ${code}`);
|
|
816
816
|
}
|
|
817
817
|
productEntry.fields[currentFieldKey] = {};
|
|
818
818
|
productEntry.fields[currentFieldKey][defaultEnvironmentLocaleCode] =
|
|
@@ -820,45 +820,45 @@ const setProductRelationships = async (code, fieldKey = null) => {
|
|
|
820
820
|
update = true;
|
|
821
821
|
}
|
|
822
822
|
else {
|
|
823
|
-
logs_1.log(`No product relationships found of the field ${currentFieldKey} for the product ${code}`);
|
|
823
|
+
(0, logs_1.log)(`No product relationships found of the field ${currentFieldKey} for the product ${code}`);
|
|
824
824
|
}
|
|
825
825
|
if (++fieldKeysCount % 7 === 0) {
|
|
826
|
-
await utils_1.sleep(2000, true);
|
|
826
|
+
await (0, utils_1.sleep)(2000, true);
|
|
827
827
|
}
|
|
828
828
|
}
|
|
829
829
|
else {
|
|
830
|
-
logs_1.log(`No field ${currentFieldKey} found for the product ${code}`);
|
|
830
|
+
(0, logs_1.log)(`No field ${currentFieldKey} found for the product ${code}`);
|
|
831
831
|
}
|
|
832
832
|
}
|
|
833
833
|
if (update) {
|
|
834
834
|
productEntry = await productEntry.update();
|
|
835
|
-
logs_1.log(`Updated ${code} product changes`);
|
|
835
|
+
(0, logs_1.log)(`Updated ${code} product changes`);
|
|
836
836
|
if (productEntry.isPublished()) {
|
|
837
837
|
try {
|
|
838
838
|
productEntry = await productEntry.publish();
|
|
839
|
-
logs_1.log(`Published ${code} product`);
|
|
839
|
+
(0, logs_1.log)(`Published ${code} product`);
|
|
840
840
|
}
|
|
841
841
|
catch (err) {
|
|
842
|
-
logs_1.log(`Cannot publish entry.`);
|
|
843
|
-
logs_1.log(err);
|
|
842
|
+
(0, logs_1.log)(`Cannot publish entry.`);
|
|
843
|
+
(0, logs_1.log)(err);
|
|
844
844
|
}
|
|
845
845
|
}
|
|
846
846
|
}
|
|
847
847
|
}
|
|
848
848
|
else {
|
|
849
|
-
logs_1.log(`${productEntry.sys.id} product payload was not found on S3. Relationships cannot be set.`, "WARN");
|
|
849
|
+
(0, logs_1.log)(`${productEntry.sys.id} product payload was not found on S3. Relationships cannot be set.`, "WARN");
|
|
850
850
|
}
|
|
851
851
|
}
|
|
852
852
|
};
|
|
853
853
|
exports.setProductRelationships = setProductRelationships;
|
|
854
854
|
const setProductsRelationships = async (catalog, lastModified, fieldKey, offset = 0, limit = 150, s3FilePath = "") => {
|
|
855
855
|
const timeStart = new Date();
|
|
856
|
-
logs_1.log(`setProductsRelationships - catalog: ${catalog} lastModified: ${lastModified} fieldKey: ${fieldKey} offset: ${offset} limit: ${limit} s3FilePath: ${s3FilePath}`, "INFO");
|
|
856
|
+
(0, logs_1.log)(`setProductsRelationships - catalog: ${catalog} lastModified: ${lastModified} fieldKey: ${fieldKey} offset: ${offset} limit: ${limit} s3FilePath: ${s3FilePath}`, "INFO");
|
|
857
857
|
if (!s3FilePath) {
|
|
858
|
-
const s3Path = await s3_1.saveAllProductsToS3(catalog, lastModified);
|
|
858
|
+
const s3Path = await (0, s3_1.saveAllProductsToS3)(catalog, lastModified);
|
|
859
859
|
const tEnd = new Date();
|
|
860
|
-
const secs = utils_1.secondBetweenTwoDate(timeStart, tEnd);
|
|
861
|
-
logs_1.log(`Request time: ${secs} seconds`);
|
|
860
|
+
const secs = (0, utils_1.secondBetweenTwoDate)(timeStart, tEnd);
|
|
861
|
+
(0, logs_1.log)(`Request time: ${secs} seconds`);
|
|
862
862
|
return {
|
|
863
863
|
offset: Number(offset),
|
|
864
864
|
limit: Number(limit),
|
|
@@ -866,16 +866,16 @@ const setProductsRelationships = async (catalog, lastModified, fieldKey, offset
|
|
|
866
866
|
s3FilePath: s3Path,
|
|
867
867
|
};
|
|
868
868
|
}
|
|
869
|
-
const JSONData = await s3_1.getFileFromS3(s3FilePath);
|
|
869
|
+
const JSONData = await (0, s3_1.getFileFromS3)(s3FilePath);
|
|
870
870
|
const total = JSONData.length;
|
|
871
|
-
logs_1.log(`${total} products founded`);
|
|
871
|
+
(0, logs_1.log)(`${total} products founded`);
|
|
872
872
|
let count = 0;
|
|
873
873
|
let updated = 0;
|
|
874
874
|
let current = 0;
|
|
875
875
|
for (const product of JSONData) {
|
|
876
876
|
if (offset <= count || limit === -1) {
|
|
877
|
-
logs_1.log(`${count + 1} of ${JSONData.length}`);
|
|
878
|
-
await exports.setProductRelationships(product.code, fieldKey);
|
|
877
|
+
(0, logs_1.log)(`${count + 1} of ${JSONData.length}`);
|
|
878
|
+
await (0, exports.setProductRelationships)(product.code, fieldKey);
|
|
879
879
|
updated++;
|
|
880
880
|
if (logs_1.serverUtils) {
|
|
881
881
|
logs_1.serverUtils.log(product.code);
|
|
@@ -884,7 +884,7 @@ const setProductsRelationships = async (catalog, lastModified, fieldKey, offset
|
|
|
884
884
|
logs_1.serverUtils.updateProgress(progress);
|
|
885
885
|
}
|
|
886
886
|
if (updated % 7 === 0) {
|
|
887
|
-
await utils_1.sleep(500);
|
|
887
|
+
await (0, utils_1.sleep)(500);
|
|
888
888
|
}
|
|
889
889
|
if (limit !== -1 && count + 1 - offset >= limit) {
|
|
890
890
|
break;
|
|
@@ -893,8 +893,8 @@ const setProductsRelationships = async (catalog, lastModified, fieldKey, offset
|
|
|
893
893
|
count++;
|
|
894
894
|
}
|
|
895
895
|
const timeEnd = new Date();
|
|
896
|
-
const seconds = utils_1.secondBetweenTwoDate(timeStart, timeEnd);
|
|
897
|
-
logs_1.log(`Request time: ${seconds} seconds`);
|
|
896
|
+
const seconds = (0, utils_1.secondBetweenTwoDate)(timeStart, timeEnd);
|
|
897
|
+
(0, logs_1.log)(`Request time: ${seconds} seconds`);
|
|
898
898
|
if (logs_1.serverUtils) {
|
|
899
899
|
logs_1.serverUtils.updateProgress(100);
|
|
900
900
|
}
|
|
@@ -908,9 +908,9 @@ const setProductsRelationships = async (catalog, lastModified, fieldKey, offset
|
|
|
908
908
|
};
|
|
909
909
|
exports.setProductsRelationships = setProductsRelationships;
|
|
910
910
|
const getAllProductEntriesByCatalog = async (catalog, limit = 100, select = "") => {
|
|
911
|
-
logs_1.log(`getAllProductEntriesByCatalog - catalog: ${catalog}`, "INFO");
|
|
912
|
-
const env = await contentful_1.getEnvironment();
|
|
913
|
-
const defEnvLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
911
|
+
(0, logs_1.log)(`getAllProductEntriesByCatalog - catalog: ${catalog}`, "INFO");
|
|
912
|
+
const env = await (0, contentful_1.getEnvironment)();
|
|
913
|
+
const defEnvLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
914
914
|
let allItems = [];
|
|
915
915
|
let othersPagesToFetch = false;
|
|
916
916
|
let skip = 0;
|
|
@@ -926,24 +926,24 @@ const getAllProductEntriesByCatalog = async (catalog, limit = 100, select = "")
|
|
|
926
926
|
select,
|
|
927
927
|
});
|
|
928
928
|
allItems = [...allItems, ...(items || [])];
|
|
929
|
-
logs_1.log(`${allItems.length} topicProduct founded of ${total}`);
|
|
929
|
+
(0, logs_1.log)(`${allItems.length} topicProduct founded of ${total}`);
|
|
930
930
|
if (total && allItems.length < total) {
|
|
931
931
|
othersPagesToFetch = true;
|
|
932
932
|
skip += limit;
|
|
933
933
|
if (++count % 7 === 0) {
|
|
934
|
-
await utils_1.sleep(200);
|
|
934
|
+
await (0, utils_1.sleep)(200);
|
|
935
935
|
}
|
|
936
936
|
}
|
|
937
937
|
else {
|
|
938
938
|
othersPagesToFetch = false;
|
|
939
939
|
}
|
|
940
940
|
} while (othersPagesToFetch);
|
|
941
|
-
logs_1.log(`${allItems.length} topicProduct founded`);
|
|
941
|
+
(0, logs_1.log)(`${allItems.length} topicProduct founded`);
|
|
942
942
|
return allItems;
|
|
943
943
|
};
|
|
944
944
|
exports.getAllProductEntriesByCatalog = getAllProductEntriesByCatalog;
|
|
945
945
|
const productAudit = async (audit, productEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit, productPageEntries) => {
|
|
946
|
-
logs_1.log(`Search product entry with id ${audit.product}...`);
|
|
946
|
+
(0, logs_1.log)(`Search product entry with id ${audit.product}...`);
|
|
947
947
|
let productEntry = productEntries.find((currentEntry) => currentEntry?.fields?.code?.[defaultEnvironmentLocaleCode] ===
|
|
948
948
|
audit.product);
|
|
949
949
|
if (!productEntry) {
|
|
@@ -954,7 +954,7 @@ const productAudit = async (audit, productEntries, catalog, defaultEnvironmentLo
|
|
|
954
954
|
else {
|
|
955
955
|
logMessage = `The ${audit.product} product was not found in the CMS`;
|
|
956
956
|
}
|
|
957
|
-
logs_1.log(logMessage, "WARN");
|
|
957
|
+
(0, logs_1.log)(logMessage, "WARN");
|
|
958
958
|
if (logs_1.serverUtils) {
|
|
959
959
|
logs_1.serverUtils.log(logMessage);
|
|
960
960
|
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
@@ -962,78 +962,93 @@ const productAudit = async (audit, productEntries, catalog, defaultEnvironmentLo
|
|
|
962
962
|
}
|
|
963
963
|
return { current, continue: true };
|
|
964
964
|
}
|
|
965
|
-
logs_1.log(`Founded product with id ${productEntry.sys.id}`);
|
|
966
|
-
const pageEntryFromId = exports.getProductPageIdByCode(audit.product);
|
|
967
|
-
logs_1.log(`Search product page entry with id ${pageEntryFromId}...`);
|
|
965
|
+
(0, logs_1.log)(`Founded product with id ${productEntry.sys.id}`);
|
|
966
|
+
const pageEntryFromId = (0, exports.getProductPageIdByCode)(audit.product);
|
|
967
|
+
(0, logs_1.log)(`Search product page entry with id ${pageEntryFromId}...`);
|
|
968
968
|
let pageEntryFrom = productPageEntries.find((currentEntry) => currentEntry.sys.id === pageEntryFromId);
|
|
969
969
|
if (pageEntryFrom) {
|
|
970
|
-
logs_1.log(`Founded product page with id ${pageEntryFrom.sys.id}`);
|
|
970
|
+
(0, logs_1.log)(`Founded product page with id ${pageEntryFrom.sys.id}`);
|
|
971
971
|
}
|
|
972
972
|
else {
|
|
973
|
-
logs_1.log(`Product page with id ${pageEntryFromId} not found`, "WARN");
|
|
973
|
+
(0, logs_1.log)(`Product page with id ${pageEntryFromId} not found`, "WARN");
|
|
974
974
|
}
|
|
975
|
-
logs_1.log(`Get product catalogs...`);
|
|
975
|
+
(0, logs_1.log)(`Get product catalogs...`);
|
|
976
976
|
const productCatalogs = productEntry?.fields?.catalogs?.[defaultEnvironmentLocaleCode].map((entryCatalog) => {
|
|
977
977
|
return entryCatalog.sys.id;
|
|
978
978
|
});
|
|
979
979
|
if (catalog && !productCatalogs.includes(catalog)) {
|
|
980
|
-
logs_1.log(`Product ${audit.product} does not belong to the ${catalog} catalog`);
|
|
980
|
+
(0, logs_1.log)(`Product ${audit.product} does not belong to the ${catalog} catalog`);
|
|
981
981
|
}
|
|
982
982
|
else if (["PRODUCT_UNPUBLISH", "PRODUCT_WEBOFF"].includes(audit.what)) {
|
|
983
|
-
logs_1.log(`Set the product status as archive...`);
|
|
984
|
-
productEntry = await contentful_1.archiveEntry(productEntry, true);
|
|
983
|
+
(0, logs_1.log)(`Set the product status as archive...`);
|
|
984
|
+
productEntry = await (0, contentful_1.archiveEntry)(productEntry, true);
|
|
985
985
|
if (!pageEntryFrom) {
|
|
986
|
-
logs_1.log(`${pageEntryFromId} page from not found`);
|
|
986
|
+
(0, logs_1.log)(`${pageEntryFromId} page from not found`);
|
|
987
987
|
}
|
|
988
988
|
else if (pageEntryFrom.isArchived()) {
|
|
989
|
-
logs_1.log(`Can't create redirect ${audit.product} to ${audit.upgradeProduct} because the page ${pageEntryFrom.sys.id} is archived.`, "WARN");
|
|
989
|
+
(0, logs_1.log)(`Can't create redirect ${audit.product} to ${audit.upgradeProduct} because the page ${pageEntryFrom.sys.id} is archived.`, "WARN");
|
|
990
990
|
}
|
|
991
991
|
else if (pageEntryFrom?.fields) {
|
|
992
992
|
if (audit.upgradeProduct && audit.upgradeProduct !== "0") {
|
|
993
|
-
logs_1.log(`Creating redirect from ${audit.product} to ${audit.upgradeProduct}`);
|
|
994
|
-
const pageEntryToId = exports.getProductPageIdByCode(audit.upgradeProduct);
|
|
995
|
-
const pageEntryTo = await contentful_1.getEntryByID(pageEntryToId, "page", "sys.id");
|
|
993
|
+
(0, logs_1.log)(`Creating redirect from ${audit.product} to ${audit.upgradeProduct}`);
|
|
994
|
+
const pageEntryToId = (0, exports.getProductPageIdByCode)(audit.upgradeProduct);
|
|
995
|
+
const pageEntryTo = await (0, contentful_1.getEntryByID)(pageEntryToId, "page", "sys.id");
|
|
996
996
|
if (pageEntryTo) {
|
|
997
|
-
pageEntryFrom.fields = await contentful_1.addToRelationFields(pageEntryFrom, "redirectTo", pageEntryTo.sys.id);
|
|
997
|
+
pageEntryFrom.fields = await (0, contentful_1.addToRelationFields)(pageEntryFrom, "redirectTo", pageEntryTo.sys.id);
|
|
998
998
|
pageEntryFrom = await pageEntryFrom.update();
|
|
999
999
|
}
|
|
1000
1000
|
else {
|
|
1001
|
-
logs_1.log(`Can't create redirect ${audit.product} to ${audit.upgradeProduct} because the page ${pageEntryToId} not found.`, "WARN");
|
|
1001
|
+
(0, logs_1.log)(`Can't create redirect ${audit.product} to ${audit.upgradeProduct} because the page ${pageEntryToId} not found.`, "WARN");
|
|
1002
1002
|
}
|
|
1003
1003
|
}
|
|
1004
|
-
pageEntryFrom = await contentful_1.archiveEntry(pageEntryFrom);
|
|
1004
|
+
pageEntryFrom = await (0, contentful_1.archiveEntry)(pageEntryFrom);
|
|
1005
1005
|
}
|
|
1006
1006
|
}
|
|
1007
1007
|
else if (audit.what === "REMOVE_PRODUCT_RELATIONS" &&
|
|
1008
1008
|
!productEntry.isArchived()) {
|
|
1009
|
+
if (productEntry.isUpdated()) {
|
|
1010
|
+
try {
|
|
1011
|
+
(0, logs_1.log)(`Publish existing changes of entry ${productEntry.sys.id}.`);
|
|
1012
|
+
productEntry = await productEntry.publish();
|
|
1013
|
+
}
|
|
1014
|
+
catch (err) {
|
|
1015
|
+
(0, logs_1.log)(`Cannot publish changes of entry ${productEntry.sys.id}.`);
|
|
1016
|
+
(0, logs_1.log)(err);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1009
1019
|
for (const item of audit?.catalogs) {
|
|
1010
1020
|
if (!item?.where) {
|
|
1011
|
-
logs_1.log(`catalogs.where field not exists. Product: ${audit.product} `, "WARN");
|
|
1021
|
+
(0, logs_1.log)(`catalogs.where field not exists. Product: ${audit.product} `, "WARN");
|
|
1012
1022
|
}
|
|
1013
1023
|
else {
|
|
1014
1024
|
let edit = false;
|
|
1015
1025
|
if (item?.catalogCode) {
|
|
1016
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, "catalogs", item.catalogCode, true);
|
|
1026
|
+
productEntry.fields = await (0, contentful_1.removeFromRelationFields)(productEntry, "catalogs", item.catalogCode, true);
|
|
1027
|
+
(0, logs_1.log)(`edit catalogs`);
|
|
1017
1028
|
edit = true;
|
|
1018
1029
|
}
|
|
1019
1030
|
if (item?.categoryCode) {
|
|
1020
|
-
const categoriesFieldKey = "categories" + utils_1.capitalizeFirstLetter(item.where);
|
|
1021
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, categoriesFieldKey, item.categoryCode, true);
|
|
1031
|
+
const categoriesFieldKey = "categories" + (0, utils_1.capitalizeFirstLetter)(item.where);
|
|
1032
|
+
productEntry.fields = await (0, contentful_1.removeFromRelationFields)(productEntry, categoriesFieldKey, item.categoryCode, true);
|
|
1033
|
+
(0, logs_1.log)(`edit ${categoriesFieldKey}`);
|
|
1022
1034
|
edit = true;
|
|
1023
1035
|
}
|
|
1024
1036
|
if (item?.subfamilyCode) {
|
|
1025
|
-
const subFamiliesFieldKey = "subFamilies" + utils_1.capitalizeFirstLetter(item.where);
|
|
1026
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, subFamiliesFieldKey, item.subfamilyCode, true);
|
|
1037
|
+
const subFamiliesFieldKey = "subFamilies" + (0, utils_1.capitalizeFirstLetter)(item.where);
|
|
1038
|
+
productEntry.fields = await (0, contentful_1.removeFromRelationFields)(productEntry, subFamiliesFieldKey, item.subfamilyCode, true);
|
|
1039
|
+
(0, logs_1.log)(`edit ${subFamiliesFieldKey}`);
|
|
1027
1040
|
edit = true;
|
|
1028
1041
|
}
|
|
1029
1042
|
if (item?.models) {
|
|
1030
|
-
const modelsFieldKey = "models" + utils_1.capitalizeFirstLetter(item.where);
|
|
1031
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, modelsFieldKey, item.models, true);
|
|
1043
|
+
const modelsFieldKey = "models" + (0, utils_1.capitalizeFirstLetter)(item.where);
|
|
1044
|
+
productEntry.fields = await (0, contentful_1.removeFromRelationFields)(productEntry, modelsFieldKey, item.models, true);
|
|
1045
|
+
(0, logs_1.log)(`edit ${modelsFieldKey}`);
|
|
1032
1046
|
edit = true;
|
|
1033
1047
|
}
|
|
1034
1048
|
if (item?.subModels) {
|
|
1035
|
-
const subModelsFieldKey = "subModels" + utils_1.capitalizeFirstLetter(item.where);
|
|
1036
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, subModelsFieldKey, item.subModels, true);
|
|
1049
|
+
const subModelsFieldKey = "subModels" + (0, utils_1.capitalizeFirstLetter)(item.where);
|
|
1050
|
+
productEntry.fields = await (0, contentful_1.removeFromRelationFields)(productEntry, subModelsFieldKey, item.subModels, true);
|
|
1051
|
+
(0, logs_1.log)(`edit ${subModelsFieldKey}`);
|
|
1037
1052
|
edit = true;
|
|
1038
1053
|
}
|
|
1039
1054
|
const objectFieldsRelations = {
|
|
@@ -1043,20 +1058,21 @@ const productAudit = async (audit, productEntries, catalog, defaultEnvironmentLo
|
|
|
1043
1058
|
};
|
|
1044
1059
|
for (const objectFieldsRelationKey of Object.keys(objectFieldsRelations)) {
|
|
1045
1060
|
if (item.where === objectFieldsRelationKey) {
|
|
1046
|
-
logs_1.log(`Remove ${objectFieldsRelationKey} relations`);
|
|
1061
|
+
(0, logs_1.log)(`Remove ${objectFieldsRelationKey} relations`);
|
|
1047
1062
|
const codes = item.codes?.split(",") ?? [];
|
|
1048
1063
|
if (codes.length) {
|
|
1049
1064
|
const fieldKey = objectFieldsRelations[objectFieldsRelationKey];
|
|
1050
1065
|
const lengthBefore = productEntry.fields?.[fieldKey]?.[defaultEnvironmentLocaleCode]
|
|
1051
1066
|
.length;
|
|
1052
|
-
productEntry.fields = await contentful_1.removeFromFieldObject(productEntry, fieldKey, codes);
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1067
|
+
productEntry.fields = await (0, contentful_1.removeFromFieldObject)(productEntry, fieldKey, codes);
|
|
1068
|
+
const lengthAfter = productEntry.fields?.[fieldKey]?.[defaultEnvironmentLocaleCode]
|
|
1069
|
+
.length;
|
|
1070
|
+
if (lengthBefore !== lengthAfter) {
|
|
1071
|
+
(0, logs_1.log)(`edit field ${fieldKey} lengthBefore: ${lengthBefore} lengthAfter: ${lengthAfter}`);
|
|
1056
1072
|
edit = true;
|
|
1057
1073
|
}
|
|
1058
1074
|
else {
|
|
1059
|
-
logs_1.log(`No valid ${objectFieldsRelationKey} to remove found`);
|
|
1075
|
+
(0, logs_1.log)(`No valid ${objectFieldsRelationKey} to remove found`);
|
|
1060
1076
|
}
|
|
1061
1077
|
}
|
|
1062
1078
|
}
|
|
@@ -1066,35 +1082,52 @@ const productAudit = async (audit, productEntries, catalog, defaultEnvironmentLo
|
|
|
1066
1082
|
.length;
|
|
1067
1083
|
const designers = item.codes.split(",");
|
|
1068
1084
|
for (const designer of designers) {
|
|
1069
|
-
logs_1.log(`Remove ${designer} designer to ${productEntry.sys.id} product if exists`);
|
|
1070
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, "designer", designer, false);
|
|
1085
|
+
(0, logs_1.log)(`Remove ${designer} designer to ${productEntry.sys.id} product if exists`);
|
|
1086
|
+
productEntry.fields = await (0, contentful_1.removeFromRelationFields)(productEntry, "designer", designer, false);
|
|
1071
1087
|
}
|
|
1072
1088
|
if (lengthBefore !==
|
|
1073
1089
|
productEntry.fields?.designer?.[defaultEnvironmentLocaleCode].length) {
|
|
1090
|
+
(0, logs_1.log)(`edit designer`);
|
|
1074
1091
|
edit = true;
|
|
1075
1092
|
}
|
|
1076
1093
|
else {
|
|
1077
|
-
logs_1.log(`No valid designer to remove found`);
|
|
1094
|
+
(0, logs_1.log)(`No valid designer to remove found`);
|
|
1078
1095
|
}
|
|
1079
1096
|
}
|
|
1080
1097
|
if (edit) {
|
|
1081
|
-
productEntry.fields = await contentful_1.addFieldValue(productEntry, "lastPimSyncDate", utils_1.getLocalISOTime());
|
|
1082
|
-
|
|
1098
|
+
productEntry.fields = await (0, contentful_1.addFieldValue)(productEntry, "lastPimSyncDate", (0, utils_1.getLocalISOTime)());
|
|
1099
|
+
try {
|
|
1100
|
+
(0, logs_1.log)(`update ${productEntry.sys.id}`);
|
|
1101
|
+
productEntry = await productEntry.update();
|
|
1102
|
+
if (productEntry.isPublished()) {
|
|
1103
|
+
try {
|
|
1104
|
+
productEntry = await productEntry.publish();
|
|
1105
|
+
}
|
|
1106
|
+
catch (err) {
|
|
1107
|
+
(0, logs_1.log)(`Cannot publish entry ${productEntry.sys.id}.`);
|
|
1108
|
+
(0, logs_1.log)(err);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
catch (err) {
|
|
1113
|
+
(0, logs_1.log)(`Cannot update entry ${productEntry.sys.id}.`);
|
|
1114
|
+
(0, logs_1.log)(err);
|
|
1115
|
+
}
|
|
1083
1116
|
}
|
|
1084
1117
|
else {
|
|
1085
|
-
logs_1.log(`No valid editable criteria found`);
|
|
1118
|
+
(0, logs_1.log)(`No valid editable criteria found`);
|
|
1086
1119
|
console.log(productEntry.sys.id, "audit", audit);
|
|
1087
1120
|
}
|
|
1088
1121
|
}
|
|
1089
1122
|
}
|
|
1090
1123
|
}
|
|
1091
1124
|
else {
|
|
1092
|
-
logs_1.log(`It has not yet been defined how to process the state ${audit.what}`);
|
|
1125
|
+
(0, logs_1.log)(`It has not yet been defined how to process the state ${audit.what}`);
|
|
1093
1126
|
}
|
|
1094
1127
|
return { current, continue: false };
|
|
1095
1128
|
};
|
|
1096
1129
|
const familyAudit = async (audit, familyEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit) => {
|
|
1097
|
-
logs_1.log(`Search family entry with id ${audit.product}...`);
|
|
1130
|
+
(0, logs_1.log)(`Search family entry with id ${audit.product}...`);
|
|
1098
1131
|
let familyEntry = familyEntries.find((currentEntry) => currentEntry?.fields?.code?.[defaultEnvironmentLocaleCode] ===
|
|
1099
1132
|
audit.product);
|
|
1100
1133
|
if (!familyEntry) {
|
|
@@ -1105,7 +1138,7 @@ const familyAudit = async (audit, familyEntries, catalog, defaultEnvironmentLoca
|
|
|
1105
1138
|
else {
|
|
1106
1139
|
logMessage = `The ${audit.product} family was not found in the CMS`;
|
|
1107
1140
|
}
|
|
1108
|
-
logs_1.log(logMessage, "WARN");
|
|
1141
|
+
(0, logs_1.log)(logMessage, "WARN");
|
|
1109
1142
|
if (logs_1.serverUtils) {
|
|
1110
1143
|
logs_1.serverUtils.log(logMessage);
|
|
1111
1144
|
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
@@ -1113,25 +1146,25 @@ const familyAudit = async (audit, familyEntries, catalog, defaultEnvironmentLoca
|
|
|
1113
1146
|
}
|
|
1114
1147
|
return { current, continue: true };
|
|
1115
1148
|
}
|
|
1116
|
-
logs_1.log(`Founded family with id ${familyEntry.sys.id}`);
|
|
1117
|
-
logs_1.log(`Get family catalogs...`);
|
|
1149
|
+
(0, logs_1.log)(`Founded family with id ${familyEntry.sys.id}`);
|
|
1150
|
+
(0, logs_1.log)(`Get family catalogs...`);
|
|
1118
1151
|
const familyCatalogs = familyEntry?.fields?.catalogs?.[defaultEnvironmentLocaleCode].map((entryCatalog) => {
|
|
1119
1152
|
return entryCatalog.sys.id;
|
|
1120
1153
|
});
|
|
1121
1154
|
if (catalog && !familyCatalogs.includes(catalog)) {
|
|
1122
|
-
logs_1.log(`Family ${audit.product} does not belong to the ${catalog} catalog`);
|
|
1155
|
+
(0, logs_1.log)(`Family ${audit.product} does not belong to the ${catalog} catalog`);
|
|
1123
1156
|
}
|
|
1124
1157
|
else if (audit.what === "REMOVE_FAMILY_RELATIONS") {
|
|
1125
1158
|
for (const item of audit?.catalogs) {
|
|
1126
1159
|
if (!item?.where) {
|
|
1127
|
-
logs_1.log(`catalogs.where field not exists. Family: ${audit.product} `, "WARN");
|
|
1160
|
+
(0, logs_1.log)(`catalogs.where field not exists. Family: ${audit.product} `, "WARN");
|
|
1128
1161
|
}
|
|
1129
1162
|
else {
|
|
1130
1163
|
if (item.where === "DESIGNERS" && item?.codes) {
|
|
1131
1164
|
const designers = item.codes.split(",");
|
|
1132
1165
|
for (const designer of designers) {
|
|
1133
|
-
logs_1.log(`Remove ${designer} designer to ${familyEntry.sys.id} family if exists`);
|
|
1134
|
-
familyEntry.fields = await contentful_1.removeFromRelationFields(familyEntry, "designer", designer, false);
|
|
1166
|
+
(0, logs_1.log)(`Remove ${designer} designer to ${familyEntry.sys.id} family if exists`);
|
|
1167
|
+
familyEntry.fields = await (0, contentful_1.removeFromRelationFields)(familyEntry, "designer", designer, false);
|
|
1135
1168
|
}
|
|
1136
1169
|
familyEntry = await familyEntry.update();
|
|
1137
1170
|
}
|
|
@@ -1139,12 +1172,12 @@ const familyAudit = async (audit, familyEntries, catalog, defaultEnvironmentLoca
|
|
|
1139
1172
|
}
|
|
1140
1173
|
}
|
|
1141
1174
|
else {
|
|
1142
|
-
logs_1.log(`It has not yet been defined how to process the state ${audit.what}`);
|
|
1175
|
+
(0, logs_1.log)(`It has not yet been defined how to process the state ${audit.what}`);
|
|
1143
1176
|
}
|
|
1144
1177
|
return { current, continue: false };
|
|
1145
1178
|
};
|
|
1146
1179
|
const subFamilyAudit = async (audit, subfamilyEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit) => {
|
|
1147
|
-
logs_1.log(`Search subFamily entry with id ${audit.product}...`);
|
|
1180
|
+
(0, logs_1.log)(`Search subFamily entry with id ${audit.product}...`);
|
|
1148
1181
|
let subFamilyEntry = subfamilyEntries.find((currentEntry) => currentEntry?.fields?.code?.[defaultEnvironmentLocaleCode] ===
|
|
1149
1182
|
audit.product);
|
|
1150
1183
|
if (!subFamilyEntry) {
|
|
@@ -1155,7 +1188,7 @@ const subFamilyAudit = async (audit, subfamilyEntries, catalog, defaultEnvironme
|
|
|
1155
1188
|
else {
|
|
1156
1189
|
logMessage = `The ${audit.product} subFamily was not found in the CMS`;
|
|
1157
1190
|
}
|
|
1158
|
-
logs_1.log(logMessage, "WARN");
|
|
1191
|
+
(0, logs_1.log)(logMessage, "WARN");
|
|
1159
1192
|
if (logs_1.serverUtils) {
|
|
1160
1193
|
logs_1.serverUtils.log(logMessage);
|
|
1161
1194
|
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
@@ -1163,23 +1196,23 @@ const subFamilyAudit = async (audit, subfamilyEntries, catalog, defaultEnvironme
|
|
|
1163
1196
|
}
|
|
1164
1197
|
return { current, continue: true };
|
|
1165
1198
|
}
|
|
1166
|
-
logs_1.log(`Founded subFamily with id ${subFamilyEntry.sys.id}`);
|
|
1167
|
-
logs_1.log(`Get subFamily catalogs...`);
|
|
1199
|
+
(0, logs_1.log)(`Founded subFamily with id ${subFamilyEntry.sys.id}`);
|
|
1200
|
+
(0, logs_1.log)(`Get subFamily catalogs...`);
|
|
1168
1201
|
const subFamilyCatalog = subFamilyEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode].sys.id;
|
|
1169
1202
|
if (catalog && subFamilyCatalog !== catalog) {
|
|
1170
|
-
logs_1.log(`SubFamily ${audit.product} does not belong to the ${catalog} catalog`);
|
|
1203
|
+
(0, logs_1.log)(`SubFamily ${audit.product} does not belong to the ${catalog} catalog`);
|
|
1171
1204
|
}
|
|
1172
1205
|
else if (audit.what === "REMOVE_SUBFAMILY_RELATIONS") {
|
|
1173
1206
|
for (const item of audit?.catalogs) {
|
|
1174
1207
|
if (!item?.where) {
|
|
1175
|
-
logs_1.log(`catalogs.where field not exists. SubFamily: ${audit.product} `, "WARN");
|
|
1208
|
+
(0, logs_1.log)(`catalogs.where field not exists. SubFamily: ${audit.product} `, "WARN");
|
|
1176
1209
|
}
|
|
1177
1210
|
else {
|
|
1178
1211
|
if (item.where === "DESIGNERS" && item?.codes) {
|
|
1179
1212
|
const designers = item.codes.split(",");
|
|
1180
1213
|
for (const designer of designers) {
|
|
1181
|
-
logs_1.log(`Remove ${designer} designer to ${subFamilyEntry.sys.id} subFamily if exists`);
|
|
1182
|
-
subFamilyEntry.fields = await contentful_1.removeFromRelationFields(subFamilyEntry, "designer", designer, false);
|
|
1214
|
+
(0, logs_1.log)(`Remove ${designer} designer to ${subFamilyEntry.sys.id} subFamily if exists`);
|
|
1215
|
+
subFamilyEntry.fields = await (0, contentful_1.removeFromRelationFields)(subFamilyEntry, "designer", designer, false);
|
|
1183
1216
|
}
|
|
1184
1217
|
subFamilyEntry = await subFamilyEntry.update();
|
|
1185
1218
|
}
|
|
@@ -1187,7 +1220,7 @@ const subFamilyAudit = async (audit, subfamilyEntries, catalog, defaultEnvironme
|
|
|
1187
1220
|
}
|
|
1188
1221
|
}
|
|
1189
1222
|
else {
|
|
1190
|
-
logs_1.log(`It has not yet been defined how to process the state ${audit.what}`);
|
|
1223
|
+
(0, logs_1.log)(`It has not yet been defined how to process the state ${audit.what}`);
|
|
1191
1224
|
}
|
|
1192
1225
|
return { current, continue: false };
|
|
1193
1226
|
};
|
|
@@ -1195,11 +1228,11 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1195
1228
|
offset = Number(offset);
|
|
1196
1229
|
limit = Number(limit);
|
|
1197
1230
|
const timeStart = new Date();
|
|
1198
|
-
logs_1.log(`audit - lastModified: ${lastModified} catalog: ${catalog}`, "INFO");
|
|
1231
|
+
(0, logs_1.log)(`audit - lastModified: ${lastModified} catalog: ${catalog}`, "INFO");
|
|
1199
1232
|
if (!s3FilePath) {
|
|
1200
|
-
const allAudit = await endpoints_1.getAudit(lastModified);
|
|
1233
|
+
const allAudit = await (0, endpoints_1.getAudit)(lastModified);
|
|
1201
1234
|
if (!allAudit) {
|
|
1202
|
-
logs_1.log(`No audits were found to process for the date ${lastModified}`);
|
|
1235
|
+
(0, logs_1.log)(`No audits were found to process for the date ${lastModified}`);
|
|
1203
1236
|
return {
|
|
1204
1237
|
offset,
|
|
1205
1238
|
limit,
|
|
@@ -1211,7 +1244,7 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1211
1244
|
}
|
|
1212
1245
|
const filename = `${lastModified}-all-audit.json`;
|
|
1213
1246
|
const path = `audit`;
|
|
1214
|
-
await s3_1.saveJsonToS3(allAudit, filename, path);
|
|
1247
|
+
await (0, s3_1.saveJsonToS3)(allAudit, filename, path);
|
|
1215
1248
|
const s3Path = `${path}/${filename}`;
|
|
1216
1249
|
if (logs_1.serverUtils) {
|
|
1217
1250
|
logs_1.serverUtils.log(`Saved s3FilePath: ${s3Path}`);
|
|
@@ -1226,13 +1259,13 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1226
1259
|
processedEntries: 0,
|
|
1227
1260
|
};
|
|
1228
1261
|
}
|
|
1229
|
-
logs_1.log(`Get audit details from ${s3FilePath}`);
|
|
1230
|
-
let allAudit = await s3_1.getFileFromS3(s3FilePath);
|
|
1262
|
+
(0, logs_1.log)(`Get audit details from ${s3FilePath}`);
|
|
1263
|
+
let allAudit = await (0, s3_1.getFileFromS3)(s3FilePath);
|
|
1231
1264
|
const total = allAudit.length;
|
|
1232
1265
|
allAudit = allAudit.slice(offset, offset + limit);
|
|
1233
|
-
logs_1.log(`Founded ${allAudit.length} items`);
|
|
1266
|
+
(0, logs_1.log)(`Founded ${allAudit.length} items`);
|
|
1234
1267
|
if (allAudit) {
|
|
1235
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1268
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1236
1269
|
const productAuditWhat = [
|
|
1237
1270
|
"PRODUCT_UNPUBLISH",
|
|
1238
1271
|
"PRODUCT_WEBOFF",
|
|
@@ -1251,31 +1284,31 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1251
1284
|
if (catalog) {
|
|
1252
1285
|
otherFilters.push({ key: "fields.catalogs.sys.id[in]", value: catalog });
|
|
1253
1286
|
}
|
|
1254
|
-
logs_1.log(`Get ${productCodes.length} product entry from Contentful`);
|
|
1255
|
-
const productEntries = await contentful_1.getAllEntriesByCodes(productCodes, "topicProduct", "sys,fields", "fields.code", otherFilters);
|
|
1256
|
-
logs_1.log(`Founded ${productEntries.length} topicProduct`);
|
|
1287
|
+
(0, logs_1.log)(`Get ${productCodes.length} product entry from Contentful`);
|
|
1288
|
+
const productEntries = await (0, contentful_1.getAllEntriesByCodes)(productCodes, "topicProduct", "sys,fields", "fields.code", otherFilters);
|
|
1289
|
+
(0, logs_1.log)(`Founded ${productEntries.length} topicProduct`);
|
|
1257
1290
|
let familyEntries = [];
|
|
1258
1291
|
if (familyCodes.length) {
|
|
1259
|
-
familyEntries = await contentful_1.getAllEntriesByCodes(familyCodes, "topicFamily", "sys,fields", "fields.code", otherFilters);
|
|
1292
|
+
familyEntries = await (0, contentful_1.getAllEntriesByCodes)(familyCodes, "topicFamily", "sys,fields", "fields.code", otherFilters);
|
|
1260
1293
|
}
|
|
1261
|
-
logs_1.log(`Founded ${familyEntries.length} topicFamily`);
|
|
1294
|
+
(0, logs_1.log)(`Founded ${familyEntries.length} topicFamily`);
|
|
1262
1295
|
let subFamilyEntries = [];
|
|
1263
1296
|
if (subFamilyCodes.length) {
|
|
1264
|
-
subFamilyEntries = await contentful_1.getAllEntriesByCodes(subFamilyCodes, "topicSubFamily", "sys,fields", "fields.code", otherFilters);
|
|
1297
|
+
subFamilyEntries = await (0, contentful_1.getAllEntriesByCodes)(subFamilyCodes, "topicSubFamily", "sys,fields", "fields.code", otherFilters);
|
|
1265
1298
|
}
|
|
1266
|
-
logs_1.log(`Founded ${subFamilyEntries.length} topicSubFamily`);
|
|
1299
|
+
(0, logs_1.log)(`Founded ${subFamilyEntries.length} topicSubFamily`);
|
|
1267
1300
|
if (!productEntries.length &&
|
|
1268
1301
|
!familyEntries.length &&
|
|
1269
1302
|
!subFamilyEntries.length) {
|
|
1270
|
-
logs_1.log(`No items found between offset: ${offset} and limit: ${limit}. Total: ${total}`);
|
|
1303
|
+
(0, logs_1.log)(`No items found between offset: ${offset} and limit: ${limit}. Total: ${total}`);
|
|
1271
1304
|
const nextOffset = offset + limit;
|
|
1272
1305
|
const completed = limit === -1 || offset >= total;
|
|
1273
1306
|
if (completed) {
|
|
1274
|
-
logs_1.log(`Audit completed`);
|
|
1307
|
+
(0, logs_1.log)(`Audit completed`);
|
|
1275
1308
|
}
|
|
1276
1309
|
const tEnd = new Date();
|
|
1277
|
-
const secs = utils_1.secondBetweenTwoDate(timeStart, tEnd);
|
|
1278
|
-
logs_1.log(`Execution time: ${secs} seconds`);
|
|
1310
|
+
const secs = (0, utils_1.secondBetweenTwoDate)(timeStart, tEnd);
|
|
1311
|
+
(0, logs_1.log)(`Execution time: ${secs} seconds`);
|
|
1279
1312
|
if (logs_1.serverUtils) {
|
|
1280
1313
|
logs_1.serverUtils.log(`Audit completed`);
|
|
1281
1314
|
logs_1.serverUtils.updateProgress(100);
|
|
@@ -1289,15 +1322,15 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1289
1322
|
processedEntries: 0,
|
|
1290
1323
|
};
|
|
1291
1324
|
}
|
|
1292
|
-
const pageCodes = productEntries.map((entry) => exports.getProductPageIdByCode(entry.fields.code[defaultEnvironmentLocaleCode]));
|
|
1293
|
-
logs_1.log(`Get ${pageCodes.length} product page entry from Contentful`);
|
|
1294
|
-
const productPageEntries = await contentful_1.getAllEntriesByCodes(pageCodes, "page", "sys,fields", "sys.id");
|
|
1295
|
-
logs_1.log(`Founded ${productPageEntries.length} topicProduct pages`);
|
|
1325
|
+
const pageCodes = productEntries.map((entry) => (0, exports.getProductPageIdByCode)(entry.fields.code[defaultEnvironmentLocaleCode]));
|
|
1326
|
+
(0, logs_1.log)(`Get ${pageCodes.length} product page entry from Contentful`);
|
|
1327
|
+
const productPageEntries = await (0, contentful_1.getAllEntriesByCodes)(pageCodes, "page", "sys,fields", "sys.id");
|
|
1328
|
+
(0, logs_1.log)(`Founded ${productPageEntries.length} topicProduct pages`);
|
|
1296
1329
|
let count = offset;
|
|
1297
1330
|
let current = 0;
|
|
1298
1331
|
for (const audit of allAudit) {
|
|
1299
|
-
logs_1.log(`${++count} of ${total}`);
|
|
1300
|
-
logs_1.log(`I process the item ${audit.product} with status ${audit.what}`);
|
|
1332
|
+
(0, logs_1.log)(`${++count} of ${total}`);
|
|
1333
|
+
(0, logs_1.log)(`I process the item ${audit.product} with status ${audit.what}`);
|
|
1301
1334
|
if (productAuditWhat.includes(audit.what)) {
|
|
1302
1335
|
const result = await productAudit(audit, productEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit, productPageEntries);
|
|
1303
1336
|
current = result.current;
|
|
@@ -1327,8 +1360,8 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1327
1360
|
}
|
|
1328
1361
|
const nextOffset = offset + limit;
|
|
1329
1362
|
const tEnd = new Date();
|
|
1330
|
-
const secs = utils_1.secondBetweenTwoDate(timeStart, tEnd);
|
|
1331
|
-
logs_1.log(`Execution time: ${secs} seconds`);
|
|
1363
|
+
const secs = (0, utils_1.secondBetweenTwoDate)(timeStart, tEnd);
|
|
1364
|
+
(0, logs_1.log)(`Execution time: ${secs} seconds`);
|
|
1332
1365
|
return {
|
|
1333
1366
|
offset: nextOffset,
|
|
1334
1367
|
limit,
|
|
@@ -1339,15 +1372,15 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1339
1372
|
};
|
|
1340
1373
|
}
|
|
1341
1374
|
else {
|
|
1342
|
-
logs_1.log(`Execution completed`);
|
|
1375
|
+
(0, logs_1.log)(`Execution completed`);
|
|
1343
1376
|
if (logs_1.serverUtils) {
|
|
1344
1377
|
logs_1.serverUtils.log(`Execution completed`);
|
|
1345
1378
|
logs_1.serverUtils.updateProgress(100);
|
|
1346
1379
|
}
|
|
1347
1380
|
}
|
|
1348
1381
|
const tEnd = new Date();
|
|
1349
|
-
const secs = utils_1.secondBetweenTwoDate(timeStart, tEnd);
|
|
1350
|
-
logs_1.log(`Request time: ${secs} seconds`);
|
|
1382
|
+
const secs = (0, utils_1.secondBetweenTwoDate)(timeStart, tEnd);
|
|
1383
|
+
(0, logs_1.log)(`Request time: ${secs} seconds`);
|
|
1351
1384
|
return {
|
|
1352
1385
|
offset: offset,
|
|
1353
1386
|
limit: limit,
|
|
@@ -1359,20 +1392,20 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1359
1392
|
exports.audit = audit;
|
|
1360
1393
|
const importProductByCode = async (code, catalog) => {
|
|
1361
1394
|
const timeStart = new Date();
|
|
1362
|
-
logs_1.log(`importProductByCode - code: ${code} catalog: ${catalog}`, "INFO");
|
|
1363
|
-
const productDetails = await endpoints_1.getProductDetails(code);
|
|
1395
|
+
(0, logs_1.log)(`importProductByCode - code: ${code} catalog: ${catalog}`, "INFO");
|
|
1396
|
+
const productDetails = await (0, endpoints_1.getProductDetails)(code);
|
|
1364
1397
|
if (productDetails) {
|
|
1365
|
-
await exports.importProduct(productDetails, catalog);
|
|
1398
|
+
await (0, exports.importProduct)(productDetails, catalog);
|
|
1366
1399
|
}
|
|
1367
1400
|
const tEnd = new Date();
|
|
1368
|
-
const secs = utils_1.secondBetweenTwoDate(timeStart, tEnd);
|
|
1369
|
-
logs_1.log(`Request time: ${secs} seconds`);
|
|
1401
|
+
const secs = (0, utils_1.secondBetweenTwoDate)(timeStart, tEnd);
|
|
1402
|
+
(0, logs_1.log)(`Request time: ${secs} seconds`);
|
|
1370
1403
|
};
|
|
1371
1404
|
exports.importProductByCode = importProductByCode;
|
|
1372
1405
|
const generateTechSpecPdf = async (topicProductId, country = "global", locale = "en") => {
|
|
1373
|
-
logs_1.log(`generateTechSpecPdf - topicProductId: ${topicProductId}`);
|
|
1374
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1375
|
-
let topicProduct = await contentful_1.getEntryByID(topicProductId, "topicProduct", "", locale);
|
|
1406
|
+
(0, logs_1.log)(`generateTechSpecPdf - topicProductId: ${topicProductId}`);
|
|
1407
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1408
|
+
let topicProduct = await (0, contentful_1.getEntryByID)(topicProductId, "topicProduct", "", locale);
|
|
1376
1409
|
if (!topicProduct) {
|
|
1377
1410
|
throw new Error(`topicProduct with id ${topicProductId} not found`);
|
|
1378
1411
|
}
|
|
@@ -1382,8 +1415,8 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
|
|
|
1382
1415
|
if (logs_1.serverUtils) {
|
|
1383
1416
|
logs_1.serverUtils.updateProgress(10);
|
|
1384
1417
|
}
|
|
1385
|
-
const topicProductPageId = exports.getProductPageIdByCode(topicProduct.sys.id);
|
|
1386
|
-
const topicProductPage = await contentful_1.getEntryByID(topicProductPageId, "page", "", locale);
|
|
1418
|
+
const topicProductPageId = (0, exports.getProductPageIdByCode)(topicProduct.sys.id);
|
|
1419
|
+
const topicProductPage = await (0, contentful_1.getEntryByID)(topicProductPageId, "page", "", locale);
|
|
1387
1420
|
if (!topicProductPage) {
|
|
1388
1421
|
throw new Error(`topicProductPage with id ${topicProductPageId} not found`);
|
|
1389
1422
|
}
|
|
@@ -1402,19 +1435,19 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
|
|
|
1402
1435
|
: `tech-spec-${pageSlug}`) + `_${country}-${locale}`;
|
|
1403
1436
|
let baseUrl = process.env.FPI_TECH_SPEC_BASE_URL ?? "";
|
|
1404
1437
|
if (!baseUrl) {
|
|
1405
|
-
logs_1.log(`FPI_TECH_SPEC_BASE_URL process env not found`, "ERROR");
|
|
1438
|
+
(0, logs_1.log)(`FPI_TECH_SPEC_BASE_URL process env not found`, "ERROR");
|
|
1406
1439
|
}
|
|
1407
1440
|
baseUrl = baseUrl.replace(/\/?(\?|#|$)/, "/$1");
|
|
1408
1441
|
let footerBaseUrl = process.env.FPI_TECH_SPEC_FOOTER_BASE_URL ??
|
|
1409
1442
|
process.env.FPI_TECH_SPEC_BASE_URL ??
|
|
1410
1443
|
"";
|
|
1411
1444
|
if (!footerBaseUrl) {
|
|
1412
|
-
logs_1.log(`FPI_TECH_SPEC_FOOTER_BASE_URL process env not found`, "ERROR");
|
|
1445
|
+
(0, logs_1.log)(`FPI_TECH_SPEC_FOOTER_BASE_URL process env not found`, "ERROR");
|
|
1413
1446
|
}
|
|
1414
1447
|
footerBaseUrl = footerBaseUrl.replace(/\/?(\?|#|$)/, "/$1");
|
|
1415
1448
|
const layoutUrl = `${baseUrl}${locale}/${country}/tech-spec/${pageSlug}/v-${version}/`;
|
|
1416
1449
|
const pdpSiteUrl = `${footerBaseUrl}${locale}/${country}/product/${pageSlug}`.replace(/\/?(\?|#|$)/, "/$1");
|
|
1417
|
-
logs_1.log(`pdpSiteUrl: ${pdpSiteUrl}`);
|
|
1450
|
+
(0, logs_1.log)(`pdpSiteUrl: ${pdpSiteUrl}`);
|
|
1418
1451
|
const contents = {
|
|
1419
1452
|
footer: {
|
|
1420
1453
|
topLeft: `<a style="text-decoration: none; color:#000" href="${pdpSiteUrl}">${pdpSiteUrl}</a>`,
|
|
@@ -1429,30 +1462,30 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
|
|
|
1429
1462
|
if (logs_1.serverUtils) {
|
|
1430
1463
|
logs_1.serverUtils.updateProgress(35);
|
|
1431
1464
|
}
|
|
1432
|
-
const s3Url = await pdf_1.generatePDFByUrl(layoutUrl, fileName, contents);
|
|
1465
|
+
const s3Url = await (0, pdf_1.generatePDFByUrl)(layoutUrl, fileName, contents);
|
|
1433
1466
|
if (s3Url) {
|
|
1434
1467
|
if (logs_1.serverUtils) {
|
|
1435
1468
|
logs_1.serverUtils.log("PDF saved to S3!");
|
|
1436
1469
|
logs_1.serverUtils.log(`Update techSpec field...`);
|
|
1437
1470
|
logs_1.serverUtils.updateProgress(75);
|
|
1438
1471
|
}
|
|
1439
|
-
logs_1.log(`Update techSpec field...`);
|
|
1440
|
-
topicProduct.fields = await contentful_1.addFieldValue(topicProduct, "techSpec", s3Url, false, locale);
|
|
1472
|
+
(0, logs_1.log)(`Update techSpec field...`);
|
|
1473
|
+
topicProduct.fields = await (0, contentful_1.addFieldValue)(topicProduct, "techSpec", s3Url, false, locale);
|
|
1441
1474
|
topicProduct = await topicProduct.update();
|
|
1442
1475
|
if (topicProduct.isPublished()) {
|
|
1443
1476
|
try {
|
|
1444
1477
|
topicProduct = await topicProduct.publish();
|
|
1445
1478
|
}
|
|
1446
1479
|
catch (err) {
|
|
1447
|
-
logs_1.log(`Cannot publish entry.`);
|
|
1448
|
-
logs_1.log(err);
|
|
1480
|
+
(0, logs_1.log)(`Cannot publish entry.`);
|
|
1481
|
+
(0, logs_1.log)(err);
|
|
1449
1482
|
}
|
|
1450
1483
|
}
|
|
1451
1484
|
if (logs_1.serverUtils) {
|
|
1452
1485
|
logs_1.serverUtils.log("Updated!");
|
|
1453
1486
|
logs_1.serverUtils.updateProgress(100);
|
|
1454
1487
|
}
|
|
1455
|
-
logs_1.log(`${topicProductId} techSpec field updated!`);
|
|
1488
|
+
(0, logs_1.log)(`${topicProductId} techSpec field updated!`);
|
|
1456
1489
|
return s3Url;
|
|
1457
1490
|
}
|
|
1458
1491
|
else {
|
|
@@ -1462,7 +1495,7 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
|
|
|
1462
1495
|
exports.generateTechSpecPdf = generateTechSpecPdf;
|
|
1463
1496
|
const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
1464
1497
|
const autoDescription = {};
|
|
1465
|
-
const dictionaryJson = await contentful_1.getDictionaryJson();
|
|
1498
|
+
const dictionaryJson = await (0, contentful_1.getDictionaryJson)();
|
|
1466
1499
|
for (const locale of contentful_1.cfLocales) {
|
|
1467
1500
|
if (!autoDescription?.[locale]) {
|
|
1468
1501
|
autoDescription[locale] = "";
|
|
@@ -1471,7 +1504,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1471
1504
|
if (productFileds?.electrical?.lampCategories) {
|
|
1472
1505
|
const lampCategoriesLocalizedValues = [];
|
|
1473
1506
|
for (const lampCategory of productFileds.electrical.lampCategories) {
|
|
1474
|
-
const lampCategoryLocalizedValue = await contentful_1.getDictionaryLocaleValue(locale, "lampCategories", lampCategory.code, "electrical", dictionaryJson);
|
|
1507
|
+
const lampCategoryLocalizedValue = await (0, contentful_1.getDictionaryLocaleValue)(locale, "lampCategories", lampCategory.code, "electrical", dictionaryJson);
|
|
1475
1508
|
if (lampCategoryLocalizedValue) {
|
|
1476
1509
|
lampCategoriesLocalizedValues.push(lampCategoryLocalizedValue);
|
|
1477
1510
|
}
|
|
@@ -1488,7 +1521,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1488
1521
|
productFileds?.photometric?.ledTypes?.length) {
|
|
1489
1522
|
const ledTypeLocalizedValues = [];
|
|
1490
1523
|
for (const ledType of productFileds?.photometric?.ledTypes) {
|
|
1491
|
-
const ledTypeLocalizedValue = await contentful_1.getDictionaryLocaleValue(locale, "ledTypes", ledType.code, "photometric", dictionaryJson);
|
|
1524
|
+
const ledTypeLocalizedValue = await (0, contentful_1.getDictionaryLocaleValue)(locale, "ledTypes", ledType.code, "photometric", dictionaryJson);
|
|
1492
1525
|
if (ledTypeLocalizedValue) {
|
|
1493
1526
|
ledTypeLocalizedValues.push(ledTypeLocalizedValue);
|
|
1494
1527
|
}
|
|
@@ -1530,7 +1563,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1530
1563
|
autoDescription[locale] += `${productFileds.photometric.realNetFlow}lm`;
|
|
1531
1564
|
}
|
|
1532
1565
|
if (productFileds?.photometric?.temperatureColor?.code) {
|
|
1533
|
-
const temperatireColorLocalizedValue = await contentful_1.getDictionaryLocaleValue(locale, "temperatureColor", productFileds.photometric.temperatureColor.code, "photometric", dictionaryJson);
|
|
1566
|
+
const temperatireColorLocalizedValue = await (0, contentful_1.getDictionaryLocaleValue)(locale, "temperatureColor", productFileds.photometric.temperatureColor.code, "photometric", dictionaryJson);
|
|
1534
1567
|
if (temperatireColorLocalizedValue) {
|
|
1535
1568
|
if (addSeparator) {
|
|
1536
1569
|
autoDescription[locale] += " - ";
|
|
@@ -1542,7 +1575,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1542
1575
|
}
|
|
1543
1576
|
}
|
|
1544
1577
|
if (productFileds?.photometric?.cri?.code) {
|
|
1545
|
-
const CriLocalizedValue = await contentful_1.getDictionaryLocaleValue(locale, "cri", productFileds.photometric.cri.code, "photometric", dictionaryJson);
|
|
1578
|
+
const CriLocalizedValue = await (0, contentful_1.getDictionaryLocaleValue)(locale, "cri", productFileds.photometric.cri.code, "photometric", dictionaryJson);
|
|
1546
1579
|
if (CriLocalizedValue) {
|
|
1547
1580
|
if (addSeparator) {
|
|
1548
1581
|
autoDescription[locale] += " - ";
|
|
@@ -1567,7 +1600,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1567
1600
|
};
|
|
1568
1601
|
const getOtherAutoDescriptionByProductFields = async (productFileds) => {
|
|
1569
1602
|
const autoDescription = {};
|
|
1570
|
-
const dictionaryJson = await contentful_1.getDictionaryJson();
|
|
1603
|
+
const dictionaryJson = await (0, contentful_1.getDictionaryJson)();
|
|
1571
1604
|
for (const locale of contentful_1.cfLocales) {
|
|
1572
1605
|
if (!autoDescription?.[locale]) {
|
|
1573
1606
|
autoDescription[locale] = "";
|
|
@@ -1584,7 +1617,7 @@ const getOtherAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1584
1617
|
if (productFileds?.mountings) {
|
|
1585
1618
|
const mountingsLocalizedValues = [];
|
|
1586
1619
|
for (const mounting of productFileds.mountings) {
|
|
1587
|
-
const mountingLocalizedValue = await contentful_1.getDictionaryLocaleValue(locale, "mountings", mounting.code, "", dictionaryJson);
|
|
1620
|
+
const mountingLocalizedValue = await (0, contentful_1.getDictionaryLocaleValue)(locale, "mountings", mounting.code, "", dictionaryJson);
|
|
1588
1621
|
if (mountingLocalizedValue) {
|
|
1589
1622
|
mountingsLocalizedValues.push(mountingLocalizedValue);
|
|
1590
1623
|
}
|
|
@@ -1601,7 +1634,7 @@ const getOtherAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1601
1634
|
return autoDescription;
|
|
1602
1635
|
};
|
|
1603
1636
|
const getTopicProductAutodescription = async (topicProductFields) => {
|
|
1604
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1637
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1605
1638
|
const productLineCode = topicProductFields?.productLine?.[defaultEnvironmentLocaleCode]?.sys?.id;
|
|
1606
1639
|
const productFileds = topicProductFields?.productFields?.[defaultEnvironmentLocaleCode];
|
|
1607
1640
|
let autoDescription = {};
|
|
@@ -1622,7 +1655,7 @@ const getTopicProductAutodescription = async (topicProductFields) => {
|
|
|
1622
1655
|
return autoDescription;
|
|
1623
1656
|
};
|
|
1624
1657
|
const setProductAutodescription = async (topicProduct) => {
|
|
1625
|
-
logs_1.log(`Set audtodescription of the topic ${topicProduct.sys.id}`);
|
|
1658
|
+
(0, logs_1.log)(`Set audtodescription of the topic ${topicProduct.sys.id}`);
|
|
1626
1659
|
const autoDescription = await getTopicProductAutodescription(topicProduct.fields);
|
|
1627
1660
|
topicProduct.fields.autoDescription = autoDescription;
|
|
1628
1661
|
if (!topicProduct.isArchived()) {
|
|
@@ -1632,14 +1665,14 @@ const setProductAutodescription = async (topicProduct) => {
|
|
|
1632
1665
|
}
|
|
1633
1666
|
}
|
|
1634
1667
|
else {
|
|
1635
|
-
logs_1.log(`Product ${topicProduct.sys.id} is archived, it is not possible to update the autodescription`, "WARN");
|
|
1668
|
+
(0, logs_1.log)(`Product ${topicProduct.sys.id} is archived, it is not possible to update the autodescription`, "WARN");
|
|
1636
1669
|
}
|
|
1637
1670
|
return autoDescription;
|
|
1638
1671
|
};
|
|
1639
1672
|
const setProductsAutodescription = async (catalog, offset = 0, limit = 100) => {
|
|
1640
|
-
logs_1.log(`setProductAutodescription - catalog: ${catalog}, offset: ${offset}, limit: ${limit}`, "INFO");
|
|
1641
|
-
const env = await contentful_1.getEnvironment();
|
|
1642
|
-
const defEnvLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1673
|
+
(0, logs_1.log)(`setProductAutodescription - catalog: ${catalog}, offset: ${offset}, limit: ${limit}`, "INFO");
|
|
1674
|
+
const env = await (0, contentful_1.getEnvironment)();
|
|
1675
|
+
const defEnvLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1643
1676
|
const { items, total } = await env.getEntries({
|
|
1644
1677
|
content_type: "topicProduct",
|
|
1645
1678
|
"fields.catalogs.sys.id": catalog,
|
|
@@ -1654,8 +1687,8 @@ const setProductsAutodescription = async (catalog, offset = 0, limit = 100) => {
|
|
|
1654
1687
|
for (const item of items) {
|
|
1655
1688
|
setProductAutodescription(item);
|
|
1656
1689
|
if (++count % 5 === 0) {
|
|
1657
|
-
logs_1.log(`current: ${count} of ${limit} - global: ${offset + count} of ${total}`);
|
|
1658
|
-
await utils_1.sleep(3000, true);
|
|
1690
|
+
(0, logs_1.log)(`current: ${count} of ${limit} - global: ${offset + count} of ${total}`);
|
|
1691
|
+
await (0, utils_1.sleep)(3000, true);
|
|
1659
1692
|
}
|
|
1660
1693
|
}
|
|
1661
1694
|
return {
|
|
@@ -1668,33 +1701,33 @@ const setProductsAutodescription = async (catalog, offset = 0, limit = 100) => {
|
|
|
1668
1701
|
};
|
|
1669
1702
|
exports.setProductsAutodescription = setProductsAutodescription;
|
|
1670
1703
|
const setProductAutodescriptionByTopicId = async (topicProductId) => {
|
|
1671
|
-
const topicProduct = await contentful_1.getEntryByID(topicProductId, "topicProduct");
|
|
1704
|
+
const topicProduct = await (0, contentful_1.getEntryByID)(topicProductId, "topicProduct");
|
|
1672
1705
|
return await setProductAutodescription(topicProduct);
|
|
1673
1706
|
};
|
|
1674
1707
|
exports.setProductAutodescriptionByTopicId = setProductAutodescriptionByTopicId;
|
|
1675
1708
|
const getProductAutodescription = async (topicProductId) => {
|
|
1676
|
-
const topicProduct = await contentful_1.getEntryByID(topicProductId, "topicProduct");
|
|
1709
|
+
const topicProduct = await (0, contentful_1.getEntryByID)(topicProductId, "topicProduct");
|
|
1677
1710
|
return await getTopicProductAutodescription(topicProduct.fields);
|
|
1678
1711
|
};
|
|
1679
1712
|
exports.getProductAutodescription = getProductAutodescription;
|
|
1680
1713
|
const removeProductFromColorVariantsByProductLine = async (productLineCode) => {
|
|
1681
|
-
logs_1.log(`Serch topicProduct with productLine ${productLineCode}`);
|
|
1682
|
-
const topicProducts = await contentful_1.getAllEntries("topicProduct", "sys", "fields.productLine.sys.id", productLineCode);
|
|
1714
|
+
(0, logs_1.log)(`Serch topicProduct with productLine ${productLineCode}`);
|
|
1715
|
+
const topicProducts = await (0, contentful_1.getAllEntries)("topicProduct", "sys", "fields.productLine.sys.id", productLineCode);
|
|
1683
1716
|
const topicProductCodes = topicProducts.map((topicProduct) => topicProduct.sys.id);
|
|
1684
|
-
logs_1.log(`Founded ${topicProductCodes.length} topicProducts`);
|
|
1717
|
+
(0, logs_1.log)(`Founded ${topicProductCodes.length} topicProducts`);
|
|
1685
1718
|
let count = 0;
|
|
1686
1719
|
for (const topicProductCode of topicProductCodes) {
|
|
1687
|
-
logs_1.log(`${++count} of ${topicProductCodes.length}`);
|
|
1688
|
-
logs_1.log(`Serch topicProductColourVariants of the ${topicProductCode} topicProduct`);
|
|
1689
|
-
const topicProductColourVariants = await contentful_1.getAllEntries("topicProductColourVariants", "sys,fields", "fields.products.sys.id[in]", topicProductCode);
|
|
1720
|
+
(0, logs_1.log)(`${++count} of ${topicProductCodes.length}`);
|
|
1721
|
+
(0, logs_1.log)(`Serch topicProductColourVariants of the ${topicProductCode} topicProduct`);
|
|
1722
|
+
const topicProductColourVariants = await (0, contentful_1.getAllEntries)("topicProductColourVariants", "sys,fields", "fields.products.sys.id[in]", topicProductCode);
|
|
1690
1723
|
if (topicProductColourVariants.length) {
|
|
1691
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1692
|
-
logs_1.log(`${topicProductColourVariants.length} topicProductColourVariants founded`);
|
|
1724
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1725
|
+
(0, logs_1.log)(`${topicProductColourVariants.length} topicProductColourVariants founded`);
|
|
1693
1726
|
for (let topicProductColourVariant of topicProductColourVariants) {
|
|
1694
|
-
logs_1.log(`Remove the ${topicProductCode} topicProduct from the ${topicProductColourVariant.sys.id} topicProductColourVariants`);
|
|
1727
|
+
(0, logs_1.log)(`Remove the ${topicProductCode} topicProduct from the ${topicProductColourVariant.sys.id} topicProductColourVariants`);
|
|
1695
1728
|
topicProductColourVariant.fields.products[defaultEnvironmentLocaleCode] = topicProductColourVariant.fields.products[defaultEnvironmentLocaleCode].filter((item) => item.sys.id !== topicProductCode);
|
|
1696
1729
|
if (topicProductColourVariant.fields.products[defaultEnvironmentLocaleCode].length) {
|
|
1697
|
-
logs_1.log(`Update the ${topicProductColourVariant.sys.id} topicProductColourVariants`);
|
|
1730
|
+
(0, logs_1.log)(`Update the ${topicProductColourVariant.sys.id} topicProductColourVariants`);
|
|
1698
1731
|
topicProductColourVariant = await topicProductColourVariant.update();
|
|
1699
1732
|
if (topicProductColourVariant.isPublished()) {
|
|
1700
1733
|
topicProductColourVariant =
|
|
@@ -1702,7 +1735,7 @@ const removeProductFromColorVariantsByProductLine = async (productLineCode) => {
|
|
|
1702
1735
|
}
|
|
1703
1736
|
}
|
|
1704
1737
|
else {
|
|
1705
|
-
logs_1.log(`Remove the ${topicProductColourVariant.sys.id} topicProductColourVariants because don't have more topicProducts`);
|
|
1738
|
+
(0, logs_1.log)(`Remove the ${topicProductColourVariant.sys.id} topicProductColourVariants because don't have more topicProducts`);
|
|
1706
1739
|
if (topicProductColourVariant.isPublished()) {
|
|
1707
1740
|
topicProductColourVariant =
|
|
1708
1741
|
await topicProductColourVariant.unpublish();
|
|
@@ -1712,15 +1745,15 @@ const removeProductFromColorVariantsByProductLine = async (productLineCode) => {
|
|
|
1712
1745
|
}
|
|
1713
1746
|
}
|
|
1714
1747
|
else {
|
|
1715
|
-
logs_1.log(`No topicProductColourVariants found for the ${topicProductCode} topicProduct`);
|
|
1748
|
+
(0, logs_1.log)(`No topicProductColourVariants found for the ${topicProductCode} topicProduct`);
|
|
1716
1749
|
}
|
|
1717
1750
|
}
|
|
1718
1751
|
};
|
|
1719
1752
|
exports.removeProductFromColorVariantsByProductLine = removeProductFromColorVariantsByProductLine;
|
|
1720
1753
|
const removeAllProductModelProductRelations = async (modelCode) => {
|
|
1721
|
-
logs_1.log(`removeAllProductModelProductRelations - modelCode: ${modelCode}`);
|
|
1722
|
-
const env = await contentful_1.getEnvironment();
|
|
1723
|
-
const defEnvLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1754
|
+
(0, logs_1.log)(`removeAllProductModelProductRelations - modelCode: ${modelCode}`);
|
|
1755
|
+
const env = await (0, contentful_1.getEnvironment)();
|
|
1756
|
+
const defEnvLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1724
1757
|
const { items } = await env.getEntries({
|
|
1725
1758
|
content_type: "topicProduct",
|
|
1726
1759
|
locale: defEnvLocaleCode,
|
|
@@ -1728,7 +1761,7 @@ const removeAllProductModelProductRelations = async (modelCode) => {
|
|
|
1728
1761
|
links_to_entry: modelCode,
|
|
1729
1762
|
limit: 1000,
|
|
1730
1763
|
});
|
|
1731
|
-
logs_1.log(`Founded ${items.length} products`);
|
|
1764
|
+
(0, logs_1.log)(`Founded ${items.length} products`);
|
|
1732
1765
|
const allProductModelFields = [
|
|
1733
1766
|
"modelsArchitectural",
|
|
1734
1767
|
"modelsOutdoor",
|
|
@@ -1742,11 +1775,11 @@ const removeAllProductModelProductRelations = async (modelCode) => {
|
|
|
1742
1775
|
}
|
|
1743
1776
|
const productCode = item.fields.code[defEnvLocaleCode];
|
|
1744
1777
|
if (item.isArchived()) {
|
|
1745
|
-
logs_1.log(`Product with code ${productCode} is archived`, "WARN");
|
|
1778
|
+
(0, logs_1.log)(`Product with code ${productCode} is archived`, "WARN");
|
|
1746
1779
|
}
|
|
1747
1780
|
else {
|
|
1748
1781
|
item = await item.update();
|
|
1749
|
-
logs_1.log(`Updated product ${productCode}`);
|
|
1782
|
+
(0, logs_1.log)(`Updated product ${productCode}`);
|
|
1750
1783
|
}
|
|
1751
1784
|
if (item.isPublished()) {
|
|
1752
1785
|
item = await item.publish();
|
|
@@ -1756,10 +1789,10 @@ const removeAllProductModelProductRelations = async (modelCode) => {
|
|
|
1756
1789
|
exports.removeAllProductModelProductRelations = removeAllProductModelProductRelations;
|
|
1757
1790
|
const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath = "") => {
|
|
1758
1791
|
if (!s3FilePath) {
|
|
1759
|
-
const allAudit = await endpoints_1.getAudit(lastModified);
|
|
1792
|
+
const allAudit = await (0, endpoints_1.getAudit)(lastModified);
|
|
1760
1793
|
const allFilteredAudit = allAudit.filter((audit) => ["PRODUCT_WEBOFF", "PRODUCT_UNPUBLISH"].includes(audit.what));
|
|
1761
1794
|
if (!allFilteredAudit) {
|
|
1762
|
-
logs_1.log(`No audits were found to process for the date ${lastModified}`);
|
|
1795
|
+
(0, logs_1.log)(`No audits were found to process for the date ${lastModified}`);
|
|
1763
1796
|
return {
|
|
1764
1797
|
offset,
|
|
1765
1798
|
limit,
|
|
@@ -1771,7 +1804,7 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1771
1804
|
}
|
|
1772
1805
|
const filename = `${lastModified}-all-audit-web-off.json`;
|
|
1773
1806
|
const path = `audit/reimport`;
|
|
1774
|
-
await s3_1.saveJsonToS3(allFilteredAudit, filename, path);
|
|
1807
|
+
await (0, s3_1.saveJsonToS3)(allFilteredAudit, filename, path);
|
|
1775
1808
|
const s3Path = `${path}/${filename}`;
|
|
1776
1809
|
return {
|
|
1777
1810
|
offset: Number(offset),
|
|
@@ -1782,27 +1815,27 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1782
1815
|
processedEntries: 0,
|
|
1783
1816
|
};
|
|
1784
1817
|
}
|
|
1785
|
-
logs_1.log(`Get audit details from ${s3FilePath}`);
|
|
1786
|
-
let allAudit = await s3_1.getFileFromS3(s3FilePath);
|
|
1818
|
+
(0, logs_1.log)(`Get audit details from ${s3FilePath}`);
|
|
1819
|
+
let allAudit = await (0, s3_1.getFileFromS3)(s3FilePath);
|
|
1787
1820
|
const total = allAudit.length;
|
|
1788
1821
|
allAudit = allAudit.slice(offset, offset + limit);
|
|
1789
|
-
logs_1.log(`Founded ${allAudit.length} items`);
|
|
1822
|
+
(0, logs_1.log)(`Founded ${allAudit.length} items`);
|
|
1790
1823
|
if (allAudit) {
|
|
1791
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1824
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1792
1825
|
const productCodes = allAudit.map((audit) => audit.product);
|
|
1793
1826
|
const otherFilters = [];
|
|
1794
1827
|
if (catalog) {
|
|
1795
1828
|
otherFilters.push({ key: "fields.catalogs.sys.id[in]", value: catalog });
|
|
1796
1829
|
}
|
|
1797
|
-
logs_1.log(`Get ${productCodes.length} product entry from Contentful`);
|
|
1798
|
-
const entries = await contentful_1.getAllEntriesByCodes(productCodes, "topicProduct", "sys,fields", "fields.code", otherFilters);
|
|
1799
|
-
logs_1.log(`Founded ${entries.length} topicProduct`);
|
|
1830
|
+
(0, logs_1.log)(`Get ${productCodes.length} product entry from Contentful`);
|
|
1831
|
+
const entries = await (0, contentful_1.getAllEntriesByCodes)(productCodes, "topicProduct", "sys,fields", "fields.code", otherFilters);
|
|
1832
|
+
(0, logs_1.log)(`Founded ${entries.length} topicProduct`);
|
|
1800
1833
|
if (!entries.length) {
|
|
1801
|
-
logs_1.log(`No products found between offset: ${offset} and limit: ${limit}. Total: ${total}`);
|
|
1834
|
+
(0, logs_1.log)(`No products found between offset: ${offset} and limit: ${limit}. Total: ${total}`);
|
|
1802
1835
|
const nextOffset = offset + limit;
|
|
1803
1836
|
const completed = limit === -1 || offset >= total;
|
|
1804
1837
|
if (completed) {
|
|
1805
|
-
logs_1.log(`Audit completed`);
|
|
1838
|
+
(0, logs_1.log)(`Audit completed`);
|
|
1806
1839
|
}
|
|
1807
1840
|
return {
|
|
1808
1841
|
offset: nextOffset,
|
|
@@ -1813,15 +1846,15 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1813
1846
|
processedEntries: 0,
|
|
1814
1847
|
};
|
|
1815
1848
|
}
|
|
1816
|
-
const pageCodes = entries.map((entry) => exports.getProductPageIdByCode(entry.fields.code[defaultEnvironmentLocaleCode]));
|
|
1817
|
-
logs_1.log(`Get ${pageCodes.length} product page entry from Contentful`);
|
|
1818
|
-
const entriesPage = await contentful_1.getAllEntriesByCodes(pageCodes, "page", "sys,fields", "sys.id");
|
|
1819
|
-
logs_1.log(`Founded ${entriesPage.length} topicProduct pages`);
|
|
1849
|
+
const pageCodes = entries.map((entry) => (0, exports.getProductPageIdByCode)(entry.fields.code[defaultEnvironmentLocaleCode]));
|
|
1850
|
+
(0, logs_1.log)(`Get ${pageCodes.length} product page entry from Contentful`);
|
|
1851
|
+
const entriesPage = await (0, contentful_1.getAllEntriesByCodes)(pageCodes, "page", "sys,fields", "sys.id");
|
|
1852
|
+
(0, logs_1.log)(`Founded ${entriesPage.length} topicProduct pages`);
|
|
1820
1853
|
let count = offset;
|
|
1821
1854
|
for (const audit of allAudit) {
|
|
1822
|
-
logs_1.log(`${++count} of ${total}`);
|
|
1823
|
-
logs_1.log(`I process the product ${audit.product} with status ${audit.what}`);
|
|
1824
|
-
logs_1.log(`Search product entry with id ${audit.product}...`);
|
|
1855
|
+
(0, logs_1.log)(`${++count} of ${total}`);
|
|
1856
|
+
(0, logs_1.log)(`I process the product ${audit.product} with status ${audit.what}`);
|
|
1857
|
+
(0, logs_1.log)(`Search product entry with id ${audit.product}...`);
|
|
1825
1858
|
const productEntry = entries.find((currentEntry) => currentEntry?.fields?.code?.[defaultEnvironmentLocaleCode] ===
|
|
1826
1859
|
audit.product);
|
|
1827
1860
|
if (!productEntry) {
|
|
@@ -1832,21 +1865,21 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1832
1865
|
else {
|
|
1833
1866
|
logMessage = `The ${audit.product} product was not found in the CMS`;
|
|
1834
1867
|
}
|
|
1835
|
-
logs_1.log(logMessage, "WARN");
|
|
1868
|
+
(0, logs_1.log)(logMessage, "WARN");
|
|
1836
1869
|
continue;
|
|
1837
1870
|
}
|
|
1838
|
-
logs_1.log(`Founded product with id ${productEntry.sys.id}`);
|
|
1839
|
-
logs_1.log(`Get product catalogs...`);
|
|
1871
|
+
(0, logs_1.log)(`Founded product with id ${productEntry.sys.id}`);
|
|
1872
|
+
(0, logs_1.log)(`Get product catalogs...`);
|
|
1840
1873
|
const productCatalogs = productEntry?.fields?.catalogs?.[defaultEnvironmentLocaleCode].map((entryCatalog) => {
|
|
1841
1874
|
return entryCatalog.sys.id;
|
|
1842
1875
|
});
|
|
1843
1876
|
if (catalog && !productCatalogs.includes(catalog)) {
|
|
1844
|
-
logs_1.log(`Product ${audit.product} does not belong to the ${catalog} catalog`);
|
|
1877
|
+
(0, logs_1.log)(`Product ${audit.product} does not belong to the ${catalog} catalog`);
|
|
1845
1878
|
}
|
|
1846
1879
|
else {
|
|
1847
|
-
logs_1.log(`Import product...`);
|
|
1848
|
-
await exports.importProductByCode(audit.product, catalog);
|
|
1849
|
-
await products_1.reindexProduct(audit.product, true);
|
|
1880
|
+
(0, logs_1.log)(`Import product...`);
|
|
1881
|
+
await (0, exports.importProductByCode)(audit.product, catalog);
|
|
1882
|
+
await (0, products_1.reindexProduct)(audit.product, true);
|
|
1850
1883
|
}
|
|
1851
1884
|
}
|
|
1852
1885
|
const nextOffset = offset + limit;
|
|
@@ -1860,7 +1893,7 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1860
1893
|
};
|
|
1861
1894
|
}
|
|
1862
1895
|
else {
|
|
1863
|
-
logs_1.log(`Execution completed`);
|
|
1896
|
+
(0, logs_1.log)(`Execution completed`);
|
|
1864
1897
|
}
|
|
1865
1898
|
return {
|
|
1866
1899
|
offset: offset,
|
|
@@ -1872,8 +1905,8 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1872
1905
|
};
|
|
1873
1906
|
exports.reimportAuditProducts = reimportAuditProducts;
|
|
1874
1907
|
const populateDestinations = async (offset, limit) => {
|
|
1875
|
-
const env = await contentful_1.getEnvironment();
|
|
1876
|
-
const defEnvLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1908
|
+
const env = await (0, contentful_1.getEnvironment)();
|
|
1909
|
+
const defEnvLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1877
1910
|
const opts = {
|
|
1878
1911
|
content_type: "topicProduct",
|
|
1879
1912
|
skip: offset,
|
|
@@ -1884,24 +1917,24 @@ const populateDestinations = async (offset, limit) => {
|
|
|
1884
1917
|
const { items, total } = await env.getEntries(opts);
|
|
1885
1918
|
let count = offset;
|
|
1886
1919
|
for (let productEntry of items) {
|
|
1887
|
-
logs_1.log(`${++count} of ${total}`);
|
|
1888
|
-
logs_1.log(`Product: ${productEntry.sys.id}`);
|
|
1920
|
+
(0, logs_1.log)(`${++count} of ${total}`);
|
|
1921
|
+
(0, logs_1.log)(`Product: ${productEntry.sys.id}`);
|
|
1889
1922
|
const destinations = productEntry.fields.productFields[defEnvLocaleCode]?.destinations?.map((destination) => destination.code) || [];
|
|
1890
1923
|
if (destinations.length) {
|
|
1891
|
-
logs_1.log(`Set destinations: ${destinations.join(", ")}`);
|
|
1892
|
-
productEntry.fields = await contentful_1.addFieldValue(productEntry, "destinations", destinations);
|
|
1924
|
+
(0, logs_1.log)(`Set destinations: ${destinations.join(", ")}`);
|
|
1925
|
+
productEntry.fields = await (0, contentful_1.addFieldValue)(productEntry, "destinations", destinations);
|
|
1893
1926
|
productEntry = await productEntry.update();
|
|
1894
1927
|
}
|
|
1895
1928
|
else {
|
|
1896
|
-
logs_1.log(`No destinations found.`, "WARN");
|
|
1929
|
+
(0, logs_1.log)(`No destinations found.`, "WARN");
|
|
1897
1930
|
}
|
|
1898
1931
|
if (productEntry.isPublished()) {
|
|
1899
1932
|
try {
|
|
1900
1933
|
productEntry = await productEntry.publish();
|
|
1901
1934
|
}
|
|
1902
1935
|
catch (err) {
|
|
1903
|
-
logs_1.log(`Cannot publish entry.`);
|
|
1904
|
-
logs_1.log(err);
|
|
1936
|
+
(0, logs_1.log)(`Cannot publish entry.`);
|
|
1937
|
+
(0, logs_1.log)(err);
|
|
1905
1938
|
}
|
|
1906
1939
|
}
|
|
1907
1940
|
}
|