pim-import 4.30.3 → 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 +426 -426
- 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 +7 -7
- 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,93 +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
1009
|
if (productEntry.isUpdated()) {
|
|
1010
1010
|
try {
|
|
1011
|
-
logs_1.log(`Publish existing changes of entry ${productEntry.sys.id}.`);
|
|
1011
|
+
(0, logs_1.log)(`Publish existing changes of entry ${productEntry.sys.id}.`);
|
|
1012
1012
|
productEntry = await productEntry.publish();
|
|
1013
1013
|
}
|
|
1014
1014
|
catch (err) {
|
|
1015
|
-
logs_1.log(`Cannot publish changes of entry ${productEntry.sys.id}.`);
|
|
1016
|
-
logs_1.log(err);
|
|
1015
|
+
(0, logs_1.log)(`Cannot publish changes of entry ${productEntry.sys.id}.`);
|
|
1016
|
+
(0, logs_1.log)(err);
|
|
1017
1017
|
}
|
|
1018
1018
|
}
|
|
1019
1019
|
for (const item of audit?.catalogs) {
|
|
1020
1020
|
if (!item?.where) {
|
|
1021
|
-
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");
|
|
1022
1022
|
}
|
|
1023
1023
|
else {
|
|
1024
1024
|
let edit = false;
|
|
1025
1025
|
if (item?.catalogCode) {
|
|
1026
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, "catalogs", item.catalogCode, true);
|
|
1027
|
-
logs_1.log(`edit catalogs`);
|
|
1026
|
+
productEntry.fields = await (0, contentful_1.removeFromRelationFields)(productEntry, "catalogs", item.catalogCode, true);
|
|
1027
|
+
(0, logs_1.log)(`edit catalogs`);
|
|
1028
1028
|
edit = true;
|
|
1029
1029
|
}
|
|
1030
1030
|
if (item?.categoryCode) {
|
|
1031
|
-
const categoriesFieldKey = "categories" + utils_1.capitalizeFirstLetter(item.where);
|
|
1032
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, categoriesFieldKey, item.categoryCode, true);
|
|
1033
|
-
logs_1.log(`edit ${categoriesFieldKey}`);
|
|
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}`);
|
|
1034
1034
|
edit = true;
|
|
1035
1035
|
}
|
|
1036
1036
|
if (item?.subfamilyCode) {
|
|
1037
|
-
const subFamiliesFieldKey = "subFamilies" + utils_1.capitalizeFirstLetter(item.where);
|
|
1038
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, subFamiliesFieldKey, item.subfamilyCode, true);
|
|
1039
|
-
logs_1.log(`edit ${subFamiliesFieldKey}`);
|
|
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}`);
|
|
1040
1040
|
edit = true;
|
|
1041
1041
|
}
|
|
1042
1042
|
if (item?.models) {
|
|
1043
|
-
const modelsFieldKey = "models" + utils_1.capitalizeFirstLetter(item.where);
|
|
1044
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, modelsFieldKey, item.models, true);
|
|
1045
|
-
logs_1.log(`edit ${modelsFieldKey}`);
|
|
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}`);
|
|
1046
1046
|
edit = true;
|
|
1047
1047
|
}
|
|
1048
1048
|
if (item?.subModels) {
|
|
1049
|
-
const subModelsFieldKey = "subModels" + utils_1.capitalizeFirstLetter(item.where);
|
|
1050
|
-
productEntry.fields = await contentful_1.removeFromRelationFields(productEntry, subModelsFieldKey, item.subModels, true);
|
|
1051
|
-
logs_1.log(`edit ${subModelsFieldKey}`);
|
|
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}`);
|
|
1052
1052
|
edit = true;
|
|
1053
1053
|
}
|
|
1054
1054
|
const objectFieldsRelations = {
|
|
@@ -1058,21 +1058,21 @@ const productAudit = async (audit, productEntries, catalog, defaultEnvironmentLo
|
|
|
1058
1058
|
};
|
|
1059
1059
|
for (const objectFieldsRelationKey of Object.keys(objectFieldsRelations)) {
|
|
1060
1060
|
if (item.where === objectFieldsRelationKey) {
|
|
1061
|
-
logs_1.log(`Remove ${objectFieldsRelationKey} relations`);
|
|
1061
|
+
(0, logs_1.log)(`Remove ${objectFieldsRelationKey} relations`);
|
|
1062
1062
|
const codes = item.codes?.split(",") ?? [];
|
|
1063
1063
|
if (codes.length) {
|
|
1064
1064
|
const fieldKey = objectFieldsRelations[objectFieldsRelationKey];
|
|
1065
1065
|
const lengthBefore = productEntry.fields?.[fieldKey]?.[defaultEnvironmentLocaleCode]
|
|
1066
1066
|
.length;
|
|
1067
|
-
productEntry.fields = await contentful_1.removeFromFieldObject(productEntry, fieldKey, codes);
|
|
1067
|
+
productEntry.fields = await (0, contentful_1.removeFromFieldObject)(productEntry, fieldKey, codes);
|
|
1068
1068
|
const lengthAfter = productEntry.fields?.[fieldKey]?.[defaultEnvironmentLocaleCode]
|
|
1069
1069
|
.length;
|
|
1070
1070
|
if (lengthBefore !== lengthAfter) {
|
|
1071
|
-
logs_1.log(`edit field ${fieldKey} lengthBefore: ${lengthBefore} lengthAfter: ${lengthAfter}`);
|
|
1071
|
+
(0, logs_1.log)(`edit field ${fieldKey} lengthBefore: ${lengthBefore} lengthAfter: ${lengthAfter}`);
|
|
1072
1072
|
edit = true;
|
|
1073
1073
|
}
|
|
1074
1074
|
else {
|
|
1075
|
-
logs_1.log(`No valid ${objectFieldsRelationKey} to remove found`);
|
|
1075
|
+
(0, logs_1.log)(`No valid ${objectFieldsRelationKey} to remove found`);
|
|
1076
1076
|
}
|
|
1077
1077
|
}
|
|
1078
1078
|
}
|
|
@@ -1082,52 +1082,52 @@ const productAudit = async (audit, productEntries, catalog, defaultEnvironmentLo
|
|
|
1082
1082
|
.length;
|
|
1083
1083
|
const designers = item.codes.split(",");
|
|
1084
1084
|
for (const designer of designers) {
|
|
1085
|
-
logs_1.log(`Remove ${designer} designer to ${productEntry.sys.id} product if exists`);
|
|
1086
|
-
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);
|
|
1087
1087
|
}
|
|
1088
1088
|
if (lengthBefore !==
|
|
1089
1089
|
productEntry.fields?.designer?.[defaultEnvironmentLocaleCode].length) {
|
|
1090
|
-
logs_1.log(`edit designer`);
|
|
1090
|
+
(0, logs_1.log)(`edit designer`);
|
|
1091
1091
|
edit = true;
|
|
1092
1092
|
}
|
|
1093
1093
|
else {
|
|
1094
|
-
logs_1.log(`No valid designer to remove found`);
|
|
1094
|
+
(0, logs_1.log)(`No valid designer to remove found`);
|
|
1095
1095
|
}
|
|
1096
1096
|
}
|
|
1097
1097
|
if (edit) {
|
|
1098
|
-
productEntry.fields = await contentful_1.addFieldValue(productEntry, "lastPimSyncDate", utils_1.getLocalISOTime());
|
|
1098
|
+
productEntry.fields = await (0, contentful_1.addFieldValue)(productEntry, "lastPimSyncDate", (0, utils_1.getLocalISOTime)());
|
|
1099
1099
|
try {
|
|
1100
|
-
logs_1.log(`update ${productEntry.sys.id}`);
|
|
1100
|
+
(0, logs_1.log)(`update ${productEntry.sys.id}`);
|
|
1101
1101
|
productEntry = await productEntry.update();
|
|
1102
1102
|
if (productEntry.isPublished()) {
|
|
1103
1103
|
try {
|
|
1104
1104
|
productEntry = await productEntry.publish();
|
|
1105
1105
|
}
|
|
1106
1106
|
catch (err) {
|
|
1107
|
-
logs_1.log(`Cannot publish entry ${productEntry.sys.id}.`);
|
|
1108
|
-
logs_1.log(err);
|
|
1107
|
+
(0, logs_1.log)(`Cannot publish entry ${productEntry.sys.id}.`);
|
|
1108
|
+
(0, logs_1.log)(err);
|
|
1109
1109
|
}
|
|
1110
1110
|
}
|
|
1111
1111
|
}
|
|
1112
1112
|
catch (err) {
|
|
1113
|
-
logs_1.log(`Cannot update entry ${productEntry.sys.id}.`);
|
|
1114
|
-
logs_1.log(err);
|
|
1113
|
+
(0, logs_1.log)(`Cannot update entry ${productEntry.sys.id}.`);
|
|
1114
|
+
(0, logs_1.log)(err);
|
|
1115
1115
|
}
|
|
1116
1116
|
}
|
|
1117
1117
|
else {
|
|
1118
|
-
logs_1.log(`No valid editable criteria found`);
|
|
1118
|
+
(0, logs_1.log)(`No valid editable criteria found`);
|
|
1119
1119
|
console.log(productEntry.sys.id, "audit", audit);
|
|
1120
1120
|
}
|
|
1121
1121
|
}
|
|
1122
1122
|
}
|
|
1123
1123
|
}
|
|
1124
1124
|
else {
|
|
1125
|
-
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}`);
|
|
1126
1126
|
}
|
|
1127
1127
|
return { current, continue: false };
|
|
1128
1128
|
};
|
|
1129
1129
|
const familyAudit = async (audit, familyEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit) => {
|
|
1130
|
-
logs_1.log(`Search family entry with id ${audit.product}...`);
|
|
1130
|
+
(0, logs_1.log)(`Search family entry with id ${audit.product}...`);
|
|
1131
1131
|
let familyEntry = familyEntries.find((currentEntry) => currentEntry?.fields?.code?.[defaultEnvironmentLocaleCode] ===
|
|
1132
1132
|
audit.product);
|
|
1133
1133
|
if (!familyEntry) {
|
|
@@ -1138,7 +1138,7 @@ const familyAudit = async (audit, familyEntries, catalog, defaultEnvironmentLoca
|
|
|
1138
1138
|
else {
|
|
1139
1139
|
logMessage = `The ${audit.product} family was not found in the CMS`;
|
|
1140
1140
|
}
|
|
1141
|
-
logs_1.log(logMessage, "WARN");
|
|
1141
|
+
(0, logs_1.log)(logMessage, "WARN");
|
|
1142
1142
|
if (logs_1.serverUtils) {
|
|
1143
1143
|
logs_1.serverUtils.log(logMessage);
|
|
1144
1144
|
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
@@ -1146,25 +1146,25 @@ const familyAudit = async (audit, familyEntries, catalog, defaultEnvironmentLoca
|
|
|
1146
1146
|
}
|
|
1147
1147
|
return { current, continue: true };
|
|
1148
1148
|
}
|
|
1149
|
-
logs_1.log(`Founded family with id ${familyEntry.sys.id}`);
|
|
1150
|
-
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...`);
|
|
1151
1151
|
const familyCatalogs = familyEntry?.fields?.catalogs?.[defaultEnvironmentLocaleCode].map((entryCatalog) => {
|
|
1152
1152
|
return entryCatalog.sys.id;
|
|
1153
1153
|
});
|
|
1154
1154
|
if (catalog && !familyCatalogs.includes(catalog)) {
|
|
1155
|
-
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`);
|
|
1156
1156
|
}
|
|
1157
1157
|
else if (audit.what === "REMOVE_FAMILY_RELATIONS") {
|
|
1158
1158
|
for (const item of audit?.catalogs) {
|
|
1159
1159
|
if (!item?.where) {
|
|
1160
|
-
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");
|
|
1161
1161
|
}
|
|
1162
1162
|
else {
|
|
1163
1163
|
if (item.where === "DESIGNERS" && item?.codes) {
|
|
1164
1164
|
const designers = item.codes.split(",");
|
|
1165
1165
|
for (const designer of designers) {
|
|
1166
|
-
logs_1.log(`Remove ${designer} designer to ${familyEntry.sys.id} family if exists`);
|
|
1167
|
-
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);
|
|
1168
1168
|
}
|
|
1169
1169
|
familyEntry = await familyEntry.update();
|
|
1170
1170
|
}
|
|
@@ -1172,12 +1172,12 @@ const familyAudit = async (audit, familyEntries, catalog, defaultEnvironmentLoca
|
|
|
1172
1172
|
}
|
|
1173
1173
|
}
|
|
1174
1174
|
else {
|
|
1175
|
-
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}`);
|
|
1176
1176
|
}
|
|
1177
1177
|
return { current, continue: false };
|
|
1178
1178
|
};
|
|
1179
1179
|
const subFamilyAudit = async (audit, subfamilyEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit) => {
|
|
1180
|
-
logs_1.log(`Search subFamily entry with id ${audit.product}...`);
|
|
1180
|
+
(0, logs_1.log)(`Search subFamily entry with id ${audit.product}...`);
|
|
1181
1181
|
let subFamilyEntry = subfamilyEntries.find((currentEntry) => currentEntry?.fields?.code?.[defaultEnvironmentLocaleCode] ===
|
|
1182
1182
|
audit.product);
|
|
1183
1183
|
if (!subFamilyEntry) {
|
|
@@ -1188,7 +1188,7 @@ const subFamilyAudit = async (audit, subfamilyEntries, catalog, defaultEnvironme
|
|
|
1188
1188
|
else {
|
|
1189
1189
|
logMessage = `The ${audit.product} subFamily was not found in the CMS`;
|
|
1190
1190
|
}
|
|
1191
|
-
logs_1.log(logMessage, "WARN");
|
|
1191
|
+
(0, logs_1.log)(logMessage, "WARN");
|
|
1192
1192
|
if (logs_1.serverUtils) {
|
|
1193
1193
|
logs_1.serverUtils.log(logMessage);
|
|
1194
1194
|
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
@@ -1196,23 +1196,23 @@ const subFamilyAudit = async (audit, subfamilyEntries, catalog, defaultEnvironme
|
|
|
1196
1196
|
}
|
|
1197
1197
|
return { current, continue: true };
|
|
1198
1198
|
}
|
|
1199
|
-
logs_1.log(`Founded subFamily with id ${subFamilyEntry.sys.id}`);
|
|
1200
|
-
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...`);
|
|
1201
1201
|
const subFamilyCatalog = subFamilyEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode].sys.id;
|
|
1202
1202
|
if (catalog && subFamilyCatalog !== catalog) {
|
|
1203
|
-
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`);
|
|
1204
1204
|
}
|
|
1205
1205
|
else if (audit.what === "REMOVE_SUBFAMILY_RELATIONS") {
|
|
1206
1206
|
for (const item of audit?.catalogs) {
|
|
1207
1207
|
if (!item?.where) {
|
|
1208
|
-
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");
|
|
1209
1209
|
}
|
|
1210
1210
|
else {
|
|
1211
1211
|
if (item.where === "DESIGNERS" && item?.codes) {
|
|
1212
1212
|
const designers = item.codes.split(",");
|
|
1213
1213
|
for (const designer of designers) {
|
|
1214
|
-
logs_1.log(`Remove ${designer} designer to ${subFamilyEntry.sys.id} subFamily if exists`);
|
|
1215
|
-
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);
|
|
1216
1216
|
}
|
|
1217
1217
|
subFamilyEntry = await subFamilyEntry.update();
|
|
1218
1218
|
}
|
|
@@ -1220,7 +1220,7 @@ const subFamilyAudit = async (audit, subfamilyEntries, catalog, defaultEnvironme
|
|
|
1220
1220
|
}
|
|
1221
1221
|
}
|
|
1222
1222
|
else {
|
|
1223
|
-
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}`);
|
|
1224
1224
|
}
|
|
1225
1225
|
return { current, continue: false };
|
|
1226
1226
|
};
|
|
@@ -1228,11 +1228,11 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1228
1228
|
offset = Number(offset);
|
|
1229
1229
|
limit = Number(limit);
|
|
1230
1230
|
const timeStart = new Date();
|
|
1231
|
-
logs_1.log(`audit - lastModified: ${lastModified} catalog: ${catalog}`, "INFO");
|
|
1231
|
+
(0, logs_1.log)(`audit - lastModified: ${lastModified} catalog: ${catalog}`, "INFO");
|
|
1232
1232
|
if (!s3FilePath) {
|
|
1233
|
-
const allAudit = await endpoints_1.getAudit(lastModified);
|
|
1233
|
+
const allAudit = await (0, endpoints_1.getAudit)(lastModified);
|
|
1234
1234
|
if (!allAudit) {
|
|
1235
|
-
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}`);
|
|
1236
1236
|
return {
|
|
1237
1237
|
offset,
|
|
1238
1238
|
limit,
|
|
@@ -1244,7 +1244,7 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1244
1244
|
}
|
|
1245
1245
|
const filename = `${lastModified}-all-audit.json`;
|
|
1246
1246
|
const path = `audit`;
|
|
1247
|
-
await s3_1.saveJsonToS3(allAudit, filename, path);
|
|
1247
|
+
await (0, s3_1.saveJsonToS3)(allAudit, filename, path);
|
|
1248
1248
|
const s3Path = `${path}/${filename}`;
|
|
1249
1249
|
if (logs_1.serverUtils) {
|
|
1250
1250
|
logs_1.serverUtils.log(`Saved s3FilePath: ${s3Path}`);
|
|
@@ -1259,13 +1259,13 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1259
1259
|
processedEntries: 0,
|
|
1260
1260
|
};
|
|
1261
1261
|
}
|
|
1262
|
-
logs_1.log(`Get audit details from ${s3FilePath}`);
|
|
1263
|
-
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);
|
|
1264
1264
|
const total = allAudit.length;
|
|
1265
1265
|
allAudit = allAudit.slice(offset, offset + limit);
|
|
1266
|
-
logs_1.log(`Founded ${allAudit.length} items`);
|
|
1266
|
+
(0, logs_1.log)(`Founded ${allAudit.length} items`);
|
|
1267
1267
|
if (allAudit) {
|
|
1268
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1268
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1269
1269
|
const productAuditWhat = [
|
|
1270
1270
|
"PRODUCT_UNPUBLISH",
|
|
1271
1271
|
"PRODUCT_WEBOFF",
|
|
@@ -1284,31 +1284,31 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1284
1284
|
if (catalog) {
|
|
1285
1285
|
otherFilters.push({ key: "fields.catalogs.sys.id[in]", value: catalog });
|
|
1286
1286
|
}
|
|
1287
|
-
logs_1.log(`Get ${productCodes.length} product entry from Contentful`);
|
|
1288
|
-
const productEntries = await contentful_1.getAllEntriesByCodes(productCodes, "topicProduct", "sys,fields", "fields.code", otherFilters);
|
|
1289
|
-
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`);
|
|
1290
1290
|
let familyEntries = [];
|
|
1291
1291
|
if (familyCodes.length) {
|
|
1292
|
-
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);
|
|
1293
1293
|
}
|
|
1294
|
-
logs_1.log(`Founded ${familyEntries.length} topicFamily`);
|
|
1294
|
+
(0, logs_1.log)(`Founded ${familyEntries.length} topicFamily`);
|
|
1295
1295
|
let subFamilyEntries = [];
|
|
1296
1296
|
if (subFamilyCodes.length) {
|
|
1297
|
-
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);
|
|
1298
1298
|
}
|
|
1299
|
-
logs_1.log(`Founded ${subFamilyEntries.length} topicSubFamily`);
|
|
1299
|
+
(0, logs_1.log)(`Founded ${subFamilyEntries.length} topicSubFamily`);
|
|
1300
1300
|
if (!productEntries.length &&
|
|
1301
1301
|
!familyEntries.length &&
|
|
1302
1302
|
!subFamilyEntries.length) {
|
|
1303
|
-
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}`);
|
|
1304
1304
|
const nextOffset = offset + limit;
|
|
1305
1305
|
const completed = limit === -1 || offset >= total;
|
|
1306
1306
|
if (completed) {
|
|
1307
|
-
logs_1.log(`Audit completed`);
|
|
1307
|
+
(0, logs_1.log)(`Audit completed`);
|
|
1308
1308
|
}
|
|
1309
1309
|
const tEnd = new Date();
|
|
1310
|
-
const secs = utils_1.secondBetweenTwoDate(timeStart, tEnd);
|
|
1311
|
-
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`);
|
|
1312
1312
|
if (logs_1.serverUtils) {
|
|
1313
1313
|
logs_1.serverUtils.log(`Audit completed`);
|
|
1314
1314
|
logs_1.serverUtils.updateProgress(100);
|
|
@@ -1322,15 +1322,15 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1322
1322
|
processedEntries: 0,
|
|
1323
1323
|
};
|
|
1324
1324
|
}
|
|
1325
|
-
const pageCodes = productEntries.map((entry) => exports.getProductPageIdByCode(entry.fields.code[defaultEnvironmentLocaleCode]));
|
|
1326
|
-
logs_1.log(`Get ${pageCodes.length} product page entry from Contentful`);
|
|
1327
|
-
const productPageEntries = await contentful_1.getAllEntriesByCodes(pageCodes, "page", "sys,fields", "sys.id");
|
|
1328
|
-
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`);
|
|
1329
1329
|
let count = offset;
|
|
1330
1330
|
let current = 0;
|
|
1331
1331
|
for (const audit of allAudit) {
|
|
1332
|
-
logs_1.log(`${++count} of ${total}`);
|
|
1333
|
-
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}`);
|
|
1334
1334
|
if (productAuditWhat.includes(audit.what)) {
|
|
1335
1335
|
const result = await productAudit(audit, productEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit, productPageEntries);
|
|
1336
1336
|
current = result.current;
|
|
@@ -1360,8 +1360,8 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1360
1360
|
}
|
|
1361
1361
|
const nextOffset = offset + limit;
|
|
1362
1362
|
const tEnd = new Date();
|
|
1363
|
-
const secs = utils_1.secondBetweenTwoDate(timeStart, tEnd);
|
|
1364
|
-
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`);
|
|
1365
1365
|
return {
|
|
1366
1366
|
offset: nextOffset,
|
|
1367
1367
|
limit,
|
|
@@ -1372,15 +1372,15 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1372
1372
|
};
|
|
1373
1373
|
}
|
|
1374
1374
|
else {
|
|
1375
|
-
logs_1.log(`Execution completed`);
|
|
1375
|
+
(0, logs_1.log)(`Execution completed`);
|
|
1376
1376
|
if (logs_1.serverUtils) {
|
|
1377
1377
|
logs_1.serverUtils.log(`Execution completed`);
|
|
1378
1378
|
logs_1.serverUtils.updateProgress(100);
|
|
1379
1379
|
}
|
|
1380
1380
|
}
|
|
1381
1381
|
const tEnd = new Date();
|
|
1382
|
-
const secs = utils_1.secondBetweenTwoDate(timeStart, tEnd);
|
|
1383
|
-
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`);
|
|
1384
1384
|
return {
|
|
1385
1385
|
offset: offset,
|
|
1386
1386
|
limit: limit,
|
|
@@ -1392,20 +1392,20 @@ const audit = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath
|
|
|
1392
1392
|
exports.audit = audit;
|
|
1393
1393
|
const importProductByCode = async (code, catalog) => {
|
|
1394
1394
|
const timeStart = new Date();
|
|
1395
|
-
logs_1.log(`importProductByCode - code: ${code} catalog: ${catalog}`, "INFO");
|
|
1396
|
-
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);
|
|
1397
1397
|
if (productDetails) {
|
|
1398
|
-
await exports.importProduct(productDetails, catalog);
|
|
1398
|
+
await (0, exports.importProduct)(productDetails, catalog);
|
|
1399
1399
|
}
|
|
1400
1400
|
const tEnd = new Date();
|
|
1401
|
-
const secs = utils_1.secondBetweenTwoDate(timeStart, tEnd);
|
|
1402
|
-
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`);
|
|
1403
1403
|
};
|
|
1404
1404
|
exports.importProductByCode = importProductByCode;
|
|
1405
1405
|
const generateTechSpecPdf = async (topicProductId, country = "global", locale = "en") => {
|
|
1406
|
-
logs_1.log(`generateTechSpecPdf - topicProductId: ${topicProductId}`);
|
|
1407
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1408
|
-
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);
|
|
1409
1409
|
if (!topicProduct) {
|
|
1410
1410
|
throw new Error(`topicProduct with id ${topicProductId} not found`);
|
|
1411
1411
|
}
|
|
@@ -1415,8 +1415,8 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
|
|
|
1415
1415
|
if (logs_1.serverUtils) {
|
|
1416
1416
|
logs_1.serverUtils.updateProgress(10);
|
|
1417
1417
|
}
|
|
1418
|
-
const topicProductPageId = exports.getProductPageIdByCode(topicProduct.sys.id);
|
|
1419
|
-
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);
|
|
1420
1420
|
if (!topicProductPage) {
|
|
1421
1421
|
throw new Error(`topicProductPage with id ${topicProductPageId} not found`);
|
|
1422
1422
|
}
|
|
@@ -1435,19 +1435,19 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
|
|
|
1435
1435
|
: `tech-spec-${pageSlug}`) + `_${country}-${locale}`;
|
|
1436
1436
|
let baseUrl = process.env.FPI_TECH_SPEC_BASE_URL ?? "";
|
|
1437
1437
|
if (!baseUrl) {
|
|
1438
|
-
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");
|
|
1439
1439
|
}
|
|
1440
1440
|
baseUrl = baseUrl.replace(/\/?(\?|#|$)/, "/$1");
|
|
1441
1441
|
let footerBaseUrl = process.env.FPI_TECH_SPEC_FOOTER_BASE_URL ??
|
|
1442
1442
|
process.env.FPI_TECH_SPEC_BASE_URL ??
|
|
1443
1443
|
"";
|
|
1444
1444
|
if (!footerBaseUrl) {
|
|
1445
|
-
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");
|
|
1446
1446
|
}
|
|
1447
1447
|
footerBaseUrl = footerBaseUrl.replace(/\/?(\?|#|$)/, "/$1");
|
|
1448
1448
|
const layoutUrl = `${baseUrl}${locale}/${country}/tech-spec/${pageSlug}/v-${version}/`;
|
|
1449
1449
|
const pdpSiteUrl = `${footerBaseUrl}${locale}/${country}/product/${pageSlug}`.replace(/\/?(\?|#|$)/, "/$1");
|
|
1450
|
-
logs_1.log(`pdpSiteUrl: ${pdpSiteUrl}`);
|
|
1450
|
+
(0, logs_1.log)(`pdpSiteUrl: ${pdpSiteUrl}`);
|
|
1451
1451
|
const contents = {
|
|
1452
1452
|
footer: {
|
|
1453
1453
|
topLeft: `<a style="text-decoration: none; color:#000" href="${pdpSiteUrl}">${pdpSiteUrl}</a>`,
|
|
@@ -1462,30 +1462,30 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
|
|
|
1462
1462
|
if (logs_1.serverUtils) {
|
|
1463
1463
|
logs_1.serverUtils.updateProgress(35);
|
|
1464
1464
|
}
|
|
1465
|
-
const s3Url = await pdf_1.generatePDFByUrl(layoutUrl, fileName, contents);
|
|
1465
|
+
const s3Url = await (0, pdf_1.generatePDFByUrl)(layoutUrl, fileName, contents);
|
|
1466
1466
|
if (s3Url) {
|
|
1467
1467
|
if (logs_1.serverUtils) {
|
|
1468
1468
|
logs_1.serverUtils.log("PDF saved to S3!");
|
|
1469
1469
|
logs_1.serverUtils.log(`Update techSpec field...`);
|
|
1470
1470
|
logs_1.serverUtils.updateProgress(75);
|
|
1471
1471
|
}
|
|
1472
|
-
logs_1.log(`Update techSpec field...`);
|
|
1473
|
-
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);
|
|
1474
1474
|
topicProduct = await topicProduct.update();
|
|
1475
1475
|
if (topicProduct.isPublished()) {
|
|
1476
1476
|
try {
|
|
1477
1477
|
topicProduct = await topicProduct.publish();
|
|
1478
1478
|
}
|
|
1479
1479
|
catch (err) {
|
|
1480
|
-
logs_1.log(`Cannot publish entry.`);
|
|
1481
|
-
logs_1.log(err);
|
|
1480
|
+
(0, logs_1.log)(`Cannot publish entry.`);
|
|
1481
|
+
(0, logs_1.log)(err);
|
|
1482
1482
|
}
|
|
1483
1483
|
}
|
|
1484
1484
|
if (logs_1.serverUtils) {
|
|
1485
1485
|
logs_1.serverUtils.log("Updated!");
|
|
1486
1486
|
logs_1.serverUtils.updateProgress(100);
|
|
1487
1487
|
}
|
|
1488
|
-
logs_1.log(`${topicProductId} techSpec field updated!`);
|
|
1488
|
+
(0, logs_1.log)(`${topicProductId} techSpec field updated!`);
|
|
1489
1489
|
return s3Url;
|
|
1490
1490
|
}
|
|
1491
1491
|
else {
|
|
@@ -1495,7 +1495,7 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
|
|
|
1495
1495
|
exports.generateTechSpecPdf = generateTechSpecPdf;
|
|
1496
1496
|
const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
1497
1497
|
const autoDescription = {};
|
|
1498
|
-
const dictionaryJson = await contentful_1.getDictionaryJson();
|
|
1498
|
+
const dictionaryJson = await (0, contentful_1.getDictionaryJson)();
|
|
1499
1499
|
for (const locale of contentful_1.cfLocales) {
|
|
1500
1500
|
if (!autoDescription?.[locale]) {
|
|
1501
1501
|
autoDescription[locale] = "";
|
|
@@ -1504,7 +1504,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1504
1504
|
if (productFileds?.electrical?.lampCategories) {
|
|
1505
1505
|
const lampCategoriesLocalizedValues = [];
|
|
1506
1506
|
for (const lampCategory of productFileds.electrical.lampCategories) {
|
|
1507
|
-
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);
|
|
1508
1508
|
if (lampCategoryLocalizedValue) {
|
|
1509
1509
|
lampCategoriesLocalizedValues.push(lampCategoryLocalizedValue);
|
|
1510
1510
|
}
|
|
@@ -1521,7 +1521,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1521
1521
|
productFileds?.photometric?.ledTypes?.length) {
|
|
1522
1522
|
const ledTypeLocalizedValues = [];
|
|
1523
1523
|
for (const ledType of productFileds?.photometric?.ledTypes) {
|
|
1524
|
-
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);
|
|
1525
1525
|
if (ledTypeLocalizedValue) {
|
|
1526
1526
|
ledTypeLocalizedValues.push(ledTypeLocalizedValue);
|
|
1527
1527
|
}
|
|
@@ -1563,7 +1563,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1563
1563
|
autoDescription[locale] += `${productFileds.photometric.realNetFlow}lm`;
|
|
1564
1564
|
}
|
|
1565
1565
|
if (productFileds?.photometric?.temperatureColor?.code) {
|
|
1566
|
-
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);
|
|
1567
1567
|
if (temperatireColorLocalizedValue) {
|
|
1568
1568
|
if (addSeparator) {
|
|
1569
1569
|
autoDescription[locale] += " - ";
|
|
@@ -1575,7 +1575,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1575
1575
|
}
|
|
1576
1576
|
}
|
|
1577
1577
|
if (productFileds?.photometric?.cri?.code) {
|
|
1578
|
-
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);
|
|
1579
1579
|
if (CriLocalizedValue) {
|
|
1580
1580
|
if (addSeparator) {
|
|
1581
1581
|
autoDescription[locale] += " - ";
|
|
@@ -1600,7 +1600,7 @@ const getLightModuleAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1600
1600
|
};
|
|
1601
1601
|
const getOtherAutoDescriptionByProductFields = async (productFileds) => {
|
|
1602
1602
|
const autoDescription = {};
|
|
1603
|
-
const dictionaryJson = await contentful_1.getDictionaryJson();
|
|
1603
|
+
const dictionaryJson = await (0, contentful_1.getDictionaryJson)();
|
|
1604
1604
|
for (const locale of contentful_1.cfLocales) {
|
|
1605
1605
|
if (!autoDescription?.[locale]) {
|
|
1606
1606
|
autoDescription[locale] = "";
|
|
@@ -1617,7 +1617,7 @@ const getOtherAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1617
1617
|
if (productFileds?.mountings) {
|
|
1618
1618
|
const mountingsLocalizedValues = [];
|
|
1619
1619
|
for (const mounting of productFileds.mountings) {
|
|
1620
|
-
const mountingLocalizedValue = await contentful_1.getDictionaryLocaleValue(locale, "mountings", mounting.code, "", dictionaryJson);
|
|
1620
|
+
const mountingLocalizedValue = await (0, contentful_1.getDictionaryLocaleValue)(locale, "mountings", mounting.code, "", dictionaryJson);
|
|
1621
1621
|
if (mountingLocalizedValue) {
|
|
1622
1622
|
mountingsLocalizedValues.push(mountingLocalizedValue);
|
|
1623
1623
|
}
|
|
@@ -1634,7 +1634,7 @@ const getOtherAutoDescriptionByProductFields = async (productFileds) => {
|
|
|
1634
1634
|
return autoDescription;
|
|
1635
1635
|
};
|
|
1636
1636
|
const getTopicProductAutodescription = async (topicProductFields) => {
|
|
1637
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1637
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1638
1638
|
const productLineCode = topicProductFields?.productLine?.[defaultEnvironmentLocaleCode]?.sys?.id;
|
|
1639
1639
|
const productFileds = topicProductFields?.productFields?.[defaultEnvironmentLocaleCode];
|
|
1640
1640
|
let autoDescription = {};
|
|
@@ -1655,7 +1655,7 @@ const getTopicProductAutodescription = async (topicProductFields) => {
|
|
|
1655
1655
|
return autoDescription;
|
|
1656
1656
|
};
|
|
1657
1657
|
const setProductAutodescription = async (topicProduct) => {
|
|
1658
|
-
logs_1.log(`Set audtodescription of the topic ${topicProduct.sys.id}`);
|
|
1658
|
+
(0, logs_1.log)(`Set audtodescription of the topic ${topicProduct.sys.id}`);
|
|
1659
1659
|
const autoDescription = await getTopicProductAutodescription(topicProduct.fields);
|
|
1660
1660
|
topicProduct.fields.autoDescription = autoDescription;
|
|
1661
1661
|
if (!topicProduct.isArchived()) {
|
|
@@ -1665,14 +1665,14 @@ const setProductAutodescription = async (topicProduct) => {
|
|
|
1665
1665
|
}
|
|
1666
1666
|
}
|
|
1667
1667
|
else {
|
|
1668
|
-
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");
|
|
1669
1669
|
}
|
|
1670
1670
|
return autoDescription;
|
|
1671
1671
|
};
|
|
1672
1672
|
const setProductsAutodescription = async (catalog, offset = 0, limit = 100) => {
|
|
1673
|
-
logs_1.log(`setProductAutodescription - catalog: ${catalog}, offset: ${offset}, limit: ${limit}`, "INFO");
|
|
1674
|
-
const env = await contentful_1.getEnvironment();
|
|
1675
|
-
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)();
|
|
1676
1676
|
const { items, total } = await env.getEntries({
|
|
1677
1677
|
content_type: "topicProduct",
|
|
1678
1678
|
"fields.catalogs.sys.id": catalog,
|
|
@@ -1687,8 +1687,8 @@ const setProductsAutodescription = async (catalog, offset = 0, limit = 100) => {
|
|
|
1687
1687
|
for (const item of items) {
|
|
1688
1688
|
setProductAutodescription(item);
|
|
1689
1689
|
if (++count % 5 === 0) {
|
|
1690
|
-
logs_1.log(`current: ${count} of ${limit} - global: ${offset + count} of ${total}`);
|
|
1691
|
-
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);
|
|
1692
1692
|
}
|
|
1693
1693
|
}
|
|
1694
1694
|
return {
|
|
@@ -1701,33 +1701,33 @@ const setProductsAutodescription = async (catalog, offset = 0, limit = 100) => {
|
|
|
1701
1701
|
};
|
|
1702
1702
|
exports.setProductsAutodescription = setProductsAutodescription;
|
|
1703
1703
|
const setProductAutodescriptionByTopicId = async (topicProductId) => {
|
|
1704
|
-
const topicProduct = await contentful_1.getEntryByID(topicProductId, "topicProduct");
|
|
1704
|
+
const topicProduct = await (0, contentful_1.getEntryByID)(topicProductId, "topicProduct");
|
|
1705
1705
|
return await setProductAutodescription(topicProduct);
|
|
1706
1706
|
};
|
|
1707
1707
|
exports.setProductAutodescriptionByTopicId = setProductAutodescriptionByTopicId;
|
|
1708
1708
|
const getProductAutodescription = async (topicProductId) => {
|
|
1709
|
-
const topicProduct = await contentful_1.getEntryByID(topicProductId, "topicProduct");
|
|
1709
|
+
const topicProduct = await (0, contentful_1.getEntryByID)(topicProductId, "topicProduct");
|
|
1710
1710
|
return await getTopicProductAutodescription(topicProduct.fields);
|
|
1711
1711
|
};
|
|
1712
1712
|
exports.getProductAutodescription = getProductAutodescription;
|
|
1713
1713
|
const removeProductFromColorVariantsByProductLine = async (productLineCode) => {
|
|
1714
|
-
logs_1.log(`Serch topicProduct with productLine ${productLineCode}`);
|
|
1715
|
-
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);
|
|
1716
1716
|
const topicProductCodes = topicProducts.map((topicProduct) => topicProduct.sys.id);
|
|
1717
|
-
logs_1.log(`Founded ${topicProductCodes.length} topicProducts`);
|
|
1717
|
+
(0, logs_1.log)(`Founded ${topicProductCodes.length} topicProducts`);
|
|
1718
1718
|
let count = 0;
|
|
1719
1719
|
for (const topicProductCode of topicProductCodes) {
|
|
1720
|
-
logs_1.log(`${++count} of ${topicProductCodes.length}`);
|
|
1721
|
-
logs_1.log(`Serch topicProductColourVariants of the ${topicProductCode} topicProduct`);
|
|
1722
|
-
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);
|
|
1723
1723
|
if (topicProductColourVariants.length) {
|
|
1724
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1725
|
-
logs_1.log(`${topicProductColourVariants.length} topicProductColourVariants founded`);
|
|
1724
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1725
|
+
(0, logs_1.log)(`${topicProductColourVariants.length} topicProductColourVariants founded`);
|
|
1726
1726
|
for (let topicProductColourVariant of topicProductColourVariants) {
|
|
1727
|
-
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`);
|
|
1728
1728
|
topicProductColourVariant.fields.products[defaultEnvironmentLocaleCode] = topicProductColourVariant.fields.products[defaultEnvironmentLocaleCode].filter((item) => item.sys.id !== topicProductCode);
|
|
1729
1729
|
if (topicProductColourVariant.fields.products[defaultEnvironmentLocaleCode].length) {
|
|
1730
|
-
logs_1.log(`Update the ${topicProductColourVariant.sys.id} topicProductColourVariants`);
|
|
1730
|
+
(0, logs_1.log)(`Update the ${topicProductColourVariant.sys.id} topicProductColourVariants`);
|
|
1731
1731
|
topicProductColourVariant = await topicProductColourVariant.update();
|
|
1732
1732
|
if (topicProductColourVariant.isPublished()) {
|
|
1733
1733
|
topicProductColourVariant =
|
|
@@ -1735,7 +1735,7 @@ const removeProductFromColorVariantsByProductLine = async (productLineCode) => {
|
|
|
1735
1735
|
}
|
|
1736
1736
|
}
|
|
1737
1737
|
else {
|
|
1738
|
-
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`);
|
|
1739
1739
|
if (topicProductColourVariant.isPublished()) {
|
|
1740
1740
|
topicProductColourVariant =
|
|
1741
1741
|
await topicProductColourVariant.unpublish();
|
|
@@ -1745,15 +1745,15 @@ const removeProductFromColorVariantsByProductLine = async (productLineCode) => {
|
|
|
1745
1745
|
}
|
|
1746
1746
|
}
|
|
1747
1747
|
else {
|
|
1748
|
-
logs_1.log(`No topicProductColourVariants found for the ${topicProductCode} topicProduct`);
|
|
1748
|
+
(0, logs_1.log)(`No topicProductColourVariants found for the ${topicProductCode} topicProduct`);
|
|
1749
1749
|
}
|
|
1750
1750
|
}
|
|
1751
1751
|
};
|
|
1752
1752
|
exports.removeProductFromColorVariantsByProductLine = removeProductFromColorVariantsByProductLine;
|
|
1753
1753
|
const removeAllProductModelProductRelations = async (modelCode) => {
|
|
1754
|
-
logs_1.log(`removeAllProductModelProductRelations - modelCode: ${modelCode}`);
|
|
1755
|
-
const env = await contentful_1.getEnvironment();
|
|
1756
|
-
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)();
|
|
1757
1757
|
const { items } = await env.getEntries({
|
|
1758
1758
|
content_type: "topicProduct",
|
|
1759
1759
|
locale: defEnvLocaleCode,
|
|
@@ -1761,7 +1761,7 @@ const removeAllProductModelProductRelations = async (modelCode) => {
|
|
|
1761
1761
|
links_to_entry: modelCode,
|
|
1762
1762
|
limit: 1000,
|
|
1763
1763
|
});
|
|
1764
|
-
logs_1.log(`Founded ${items.length} products`);
|
|
1764
|
+
(0, logs_1.log)(`Founded ${items.length} products`);
|
|
1765
1765
|
const allProductModelFields = [
|
|
1766
1766
|
"modelsArchitectural",
|
|
1767
1767
|
"modelsOutdoor",
|
|
@@ -1775,11 +1775,11 @@ const removeAllProductModelProductRelations = async (modelCode) => {
|
|
|
1775
1775
|
}
|
|
1776
1776
|
const productCode = item.fields.code[defEnvLocaleCode];
|
|
1777
1777
|
if (item.isArchived()) {
|
|
1778
|
-
logs_1.log(`Product with code ${productCode} is archived`, "WARN");
|
|
1778
|
+
(0, logs_1.log)(`Product with code ${productCode} is archived`, "WARN");
|
|
1779
1779
|
}
|
|
1780
1780
|
else {
|
|
1781
1781
|
item = await item.update();
|
|
1782
|
-
logs_1.log(`Updated product ${productCode}`);
|
|
1782
|
+
(0, logs_1.log)(`Updated product ${productCode}`);
|
|
1783
1783
|
}
|
|
1784
1784
|
if (item.isPublished()) {
|
|
1785
1785
|
item = await item.publish();
|
|
@@ -1789,10 +1789,10 @@ const removeAllProductModelProductRelations = async (modelCode) => {
|
|
|
1789
1789
|
exports.removeAllProductModelProductRelations = removeAllProductModelProductRelations;
|
|
1790
1790
|
const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit = 150, s3FilePath = "") => {
|
|
1791
1791
|
if (!s3FilePath) {
|
|
1792
|
-
const allAudit = await endpoints_1.getAudit(lastModified);
|
|
1792
|
+
const allAudit = await (0, endpoints_1.getAudit)(lastModified);
|
|
1793
1793
|
const allFilteredAudit = allAudit.filter((audit) => ["PRODUCT_WEBOFF", "PRODUCT_UNPUBLISH"].includes(audit.what));
|
|
1794
1794
|
if (!allFilteredAudit) {
|
|
1795
|
-
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}`);
|
|
1796
1796
|
return {
|
|
1797
1797
|
offset,
|
|
1798
1798
|
limit,
|
|
@@ -1804,7 +1804,7 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1804
1804
|
}
|
|
1805
1805
|
const filename = `${lastModified}-all-audit-web-off.json`;
|
|
1806
1806
|
const path = `audit/reimport`;
|
|
1807
|
-
await s3_1.saveJsonToS3(allFilteredAudit, filename, path);
|
|
1807
|
+
await (0, s3_1.saveJsonToS3)(allFilteredAudit, filename, path);
|
|
1808
1808
|
const s3Path = `${path}/${filename}`;
|
|
1809
1809
|
return {
|
|
1810
1810
|
offset: Number(offset),
|
|
@@ -1815,27 +1815,27 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1815
1815
|
processedEntries: 0,
|
|
1816
1816
|
};
|
|
1817
1817
|
}
|
|
1818
|
-
logs_1.log(`Get audit details from ${s3FilePath}`);
|
|
1819
|
-
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);
|
|
1820
1820
|
const total = allAudit.length;
|
|
1821
1821
|
allAudit = allAudit.slice(offset, offset + limit);
|
|
1822
|
-
logs_1.log(`Founded ${allAudit.length} items`);
|
|
1822
|
+
(0, logs_1.log)(`Founded ${allAudit.length} items`);
|
|
1823
1823
|
if (allAudit) {
|
|
1824
|
-
const defaultEnvironmentLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1824
|
+
const defaultEnvironmentLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1825
1825
|
const productCodes = allAudit.map((audit) => audit.product);
|
|
1826
1826
|
const otherFilters = [];
|
|
1827
1827
|
if (catalog) {
|
|
1828
1828
|
otherFilters.push({ key: "fields.catalogs.sys.id[in]", value: catalog });
|
|
1829
1829
|
}
|
|
1830
|
-
logs_1.log(`Get ${productCodes.length} product entry from Contentful`);
|
|
1831
|
-
const entries = await contentful_1.getAllEntriesByCodes(productCodes, "topicProduct", "sys,fields", "fields.code", otherFilters);
|
|
1832
|
-
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`);
|
|
1833
1833
|
if (!entries.length) {
|
|
1834
|
-
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}`);
|
|
1835
1835
|
const nextOffset = offset + limit;
|
|
1836
1836
|
const completed = limit === -1 || offset >= total;
|
|
1837
1837
|
if (completed) {
|
|
1838
|
-
logs_1.log(`Audit completed`);
|
|
1838
|
+
(0, logs_1.log)(`Audit completed`);
|
|
1839
1839
|
}
|
|
1840
1840
|
return {
|
|
1841
1841
|
offset: nextOffset,
|
|
@@ -1846,15 +1846,15 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1846
1846
|
processedEntries: 0,
|
|
1847
1847
|
};
|
|
1848
1848
|
}
|
|
1849
|
-
const pageCodes = entries.map((entry) => exports.getProductPageIdByCode(entry.fields.code[defaultEnvironmentLocaleCode]));
|
|
1850
|
-
logs_1.log(`Get ${pageCodes.length} product page entry from Contentful`);
|
|
1851
|
-
const entriesPage = await contentful_1.getAllEntriesByCodes(pageCodes, "page", "sys,fields", "sys.id");
|
|
1852
|
-
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`);
|
|
1853
1853
|
let count = offset;
|
|
1854
1854
|
for (const audit of allAudit) {
|
|
1855
|
-
logs_1.log(`${++count} of ${total}`);
|
|
1856
|
-
logs_1.log(`I process the product ${audit.product} with status ${audit.what}`);
|
|
1857
|
-
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}...`);
|
|
1858
1858
|
const productEntry = entries.find((currentEntry) => currentEntry?.fields?.code?.[defaultEnvironmentLocaleCode] ===
|
|
1859
1859
|
audit.product);
|
|
1860
1860
|
if (!productEntry) {
|
|
@@ -1865,21 +1865,21 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1865
1865
|
else {
|
|
1866
1866
|
logMessage = `The ${audit.product} product was not found in the CMS`;
|
|
1867
1867
|
}
|
|
1868
|
-
logs_1.log(logMessage, "WARN");
|
|
1868
|
+
(0, logs_1.log)(logMessage, "WARN");
|
|
1869
1869
|
continue;
|
|
1870
1870
|
}
|
|
1871
|
-
logs_1.log(`Founded product with id ${productEntry.sys.id}`);
|
|
1872
|
-
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...`);
|
|
1873
1873
|
const productCatalogs = productEntry?.fields?.catalogs?.[defaultEnvironmentLocaleCode].map((entryCatalog) => {
|
|
1874
1874
|
return entryCatalog.sys.id;
|
|
1875
1875
|
});
|
|
1876
1876
|
if (catalog && !productCatalogs.includes(catalog)) {
|
|
1877
|
-
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`);
|
|
1878
1878
|
}
|
|
1879
1879
|
else {
|
|
1880
|
-
logs_1.log(`Import product...`);
|
|
1881
|
-
await exports.importProductByCode(audit.product, catalog);
|
|
1882
|
-
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);
|
|
1883
1883
|
}
|
|
1884
1884
|
}
|
|
1885
1885
|
const nextOffset = offset + limit;
|
|
@@ -1893,7 +1893,7 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1893
1893
|
};
|
|
1894
1894
|
}
|
|
1895
1895
|
else {
|
|
1896
|
-
logs_1.log(`Execution completed`);
|
|
1896
|
+
(0, logs_1.log)(`Execution completed`);
|
|
1897
1897
|
}
|
|
1898
1898
|
return {
|
|
1899
1899
|
offset: offset,
|
|
@@ -1905,8 +1905,8 @@ const reimportAuditProducts = async (lastModified, catalog, offset = 0, limit =
|
|
|
1905
1905
|
};
|
|
1906
1906
|
exports.reimportAuditProducts = reimportAuditProducts;
|
|
1907
1907
|
const populateDestinations = async (offset, limit) => {
|
|
1908
|
-
const env = await contentful_1.getEnvironment();
|
|
1909
|
-
const defEnvLocaleCode = await contentful_1.getEnvironmentDefaultLocaleCode();
|
|
1908
|
+
const env = await (0, contentful_1.getEnvironment)();
|
|
1909
|
+
const defEnvLocaleCode = await (0, contentful_1.getEnvironmentDefaultLocaleCode)();
|
|
1910
1910
|
const opts = {
|
|
1911
1911
|
content_type: "topicProduct",
|
|
1912
1912
|
skip: offset,
|
|
@@ -1917,24 +1917,24 @@ const populateDestinations = async (offset, limit) => {
|
|
|
1917
1917
|
const { items, total } = await env.getEntries(opts);
|
|
1918
1918
|
let count = offset;
|
|
1919
1919
|
for (let productEntry of items) {
|
|
1920
|
-
logs_1.log(`${++count} of ${total}`);
|
|
1921
|
-
logs_1.log(`Product: ${productEntry.sys.id}`);
|
|
1920
|
+
(0, logs_1.log)(`${++count} of ${total}`);
|
|
1921
|
+
(0, logs_1.log)(`Product: ${productEntry.sys.id}`);
|
|
1922
1922
|
const destinations = productEntry.fields.productFields[defEnvLocaleCode]?.destinations?.map((destination) => destination.code) || [];
|
|
1923
1923
|
if (destinations.length) {
|
|
1924
|
-
logs_1.log(`Set destinations: ${destinations.join(", ")}`);
|
|
1925
|
-
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);
|
|
1926
1926
|
productEntry = await productEntry.update();
|
|
1927
1927
|
}
|
|
1928
1928
|
else {
|
|
1929
|
-
logs_1.log(`No destinations found.`, "WARN");
|
|
1929
|
+
(0, logs_1.log)(`No destinations found.`, "WARN");
|
|
1930
1930
|
}
|
|
1931
1931
|
if (productEntry.isPublished()) {
|
|
1932
1932
|
try {
|
|
1933
1933
|
productEntry = await productEntry.publish();
|
|
1934
1934
|
}
|
|
1935
1935
|
catch (err) {
|
|
1936
|
-
logs_1.log(`Cannot publish entry.`);
|
|
1937
|
-
logs_1.log(err);
|
|
1936
|
+
(0, logs_1.log)(`Cannot publish entry.`);
|
|
1937
|
+
(0, logs_1.log)(err);
|
|
1938
1938
|
}
|
|
1939
1939
|
}
|
|
1940
1940
|
}
|