pim-import 5.0.1 → 5.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/algolia/clean.js +0 -1
  2. package/dist/algolia/config.js +0 -1
  3. package/dist/algolia/downloads.js +0 -1
  4. package/dist/algolia/families.js +0 -1
  5. package/dist/algolia/inspirations.js +0 -1
  6. package/dist/algolia/models.js +0 -1
  7. package/dist/algolia/news.js +0 -1
  8. package/dist/algolia/pressRelease.js +0 -1
  9. package/dist/algolia/pressReview.js +0 -1
  10. package/dist/algolia/products.js +0 -1
  11. package/dist/algolia/projects.js +0 -1
  12. package/dist/algolia/stories.js +0 -1
  13. package/dist/algolia/subFamilies.js +0 -1
  14. package/dist/algolia/subModels.js +0 -1
  15. package/dist/browser.js +0 -1
  16. package/dist/downloads/classes/manageEntry.js +0 -1
  17. package/dist/downloads/import.js +0 -1
  18. package/dist/index.js +0 -1
  19. package/dist/libs/contentful-cda.js +0 -1
  20. package/dist/libs/contentful.js +0 -1
  21. package/dist/libs/imgix.js +0 -1
  22. package/dist/libs/logs.js +0 -1
  23. package/dist/libs/netlify.js +0 -1
  24. package/dist/libs/notifications.js +0 -1
  25. package/dist/libs/pdf.js +0 -1
  26. package/dist/libs/s3.js +0 -1
  27. package/dist/libs/sentry.js +0 -1
  28. package/dist/pim/config.js +0 -1
  29. package/dist/pim/endpoints.js +0 -1
  30. package/dist/pim/methods/bulkPublish.js +0 -1
  31. package/dist/pim/methods/catalogs.js +0 -1
  32. package/dist/pim/methods/checkTopicDraftAndPagePublished.js +0 -1
  33. package/dist/pim/methods/designers.js +0 -1
  34. package/dist/pim/methods/dictionary.js +0 -1
  35. package/dist/pim/methods/families.js +0 -1
  36. package/dist/pim/methods/latestProducts.js +0 -1
  37. package/dist/pim/methods/migrateEntryFields.js +0 -1
  38. package/dist/pim/methods/models.js +0 -1
  39. package/dist/pim/methods/pages/catalogs.js +0 -1
  40. package/dist/pim/methods/pages/families.js +0 -1
  41. package/dist/pim/methods/pages/subfamilies.js +0 -1
  42. package/dist/pim/methods/products.js +0 -1
  43. package/dist/pim/methods/subfamilies.js +0 -1
  44. package/dist/pim/methods/submodels.js +0 -1
  45. package/dist/pim/request.js +0 -1
  46. package/dist/resources/AllProducts.js +0 -1
  47. package/dist/resources/Audit.js +0 -1
  48. package/dist/resources/CatalogDetails.js +0 -1
  49. package/dist/resources/CollectionModels.js +0 -1
  50. package/dist/resources/CollectionSubFamilies.js +0 -1
  51. package/dist/resources/CollectionSubModels.js +0 -1
  52. package/dist/resources/DProductSubLine.js +0 -1
  53. package/dist/resources/FamilyDetails.js +0 -1
  54. package/dist/resources/ProductDetails.js +0 -1
  55. package/dist/resources/ProductRelation.js +0 -1
  56. package/dist/resources/cfFields.js +0 -1
  57. package/dist/types.js +0 -1
  58. package/dist/utils.js +0 -1
  59. package/package.json +7 -2
  60. package/.env.example +0 -45
  61. package/.nvmrc +0 -1
  62. package/.vscode/settings.json +0 -21
  63. package/dist/algolia/clean.js.map +0 -1
  64. package/dist/algolia/config.js.map +0 -1
  65. package/dist/algolia/downloads.js.map +0 -1
  66. package/dist/algolia/families.js.map +0 -1
  67. package/dist/algolia/inspirations.js.map +0 -1
  68. package/dist/algolia/models.js.map +0 -1
  69. package/dist/algolia/news.js.map +0 -1
  70. package/dist/algolia/pressRelease.js.map +0 -1
  71. package/dist/algolia/pressReview.js.map +0 -1
  72. package/dist/algolia/products.js.map +0 -1
  73. package/dist/algolia/projects.js.map +0 -1
  74. package/dist/algolia/stories.js.map +0 -1
  75. package/dist/algolia/subFamilies.js.map +0 -1
  76. package/dist/algolia/subModels.js.map +0 -1
  77. package/dist/browser.js.map +0 -1
  78. package/dist/downloads/classes/manageEntry.js.map +0 -1
  79. package/dist/downloads/import.js.map +0 -1
  80. package/dist/index.js.map +0 -1
  81. package/dist/libs/contentful-cda.js.map +0 -1
  82. package/dist/libs/contentful.js.map +0 -1
  83. package/dist/libs/imgix.js.map +0 -1
  84. package/dist/libs/logs.js.map +0 -1
  85. package/dist/libs/netlify.js.map +0 -1
  86. package/dist/libs/notifications.js.map +0 -1
  87. package/dist/libs/pdf.js.map +0 -1
  88. package/dist/libs/s3.js.map +0 -1
  89. package/dist/libs/sentry.js.map +0 -1
  90. package/dist/pim/config.js.map +0 -1
  91. package/dist/pim/endpoints.js.map +0 -1
  92. package/dist/pim/methods/bulkPublish.js.map +0 -1
  93. package/dist/pim/methods/catalogs.js.map +0 -1
  94. package/dist/pim/methods/checkTopicDraftAndPagePublished.js.map +0 -1
  95. package/dist/pim/methods/designers.js.map +0 -1
  96. package/dist/pim/methods/dictionary.js.map +0 -1
  97. package/dist/pim/methods/families.js.map +0 -1
  98. package/dist/pim/methods/latestProducts.js.map +0 -1
  99. package/dist/pim/methods/migrateEntryFields.js.map +0 -1
  100. package/dist/pim/methods/models.js.map +0 -1
  101. package/dist/pim/methods/pages/catalogs.js.map +0 -1
  102. package/dist/pim/methods/pages/families.js.map +0 -1
  103. package/dist/pim/methods/pages/subfamilies.js.map +0 -1
  104. package/dist/pim/methods/products.js.map +0 -1
  105. package/dist/pim/methods/subfamilies.js.map +0 -1
  106. package/dist/pim/methods/submodels.js.map +0 -1
  107. package/dist/pim/request.js.map +0 -1
  108. package/dist/resources/AllProducts.js.map +0 -1
  109. package/dist/resources/Audit.js.map +0 -1
  110. package/dist/resources/CatalogDetails.js.map +0 -1
  111. package/dist/resources/CollectionModels.js.map +0 -1
  112. package/dist/resources/CollectionSubFamilies.js.map +0 -1
  113. package/dist/resources/CollectionSubModels.js.map +0 -1
  114. package/dist/resources/DProductSubLine.js.map +0 -1
  115. package/dist/resources/FamilyDetails.js.map +0 -1
  116. package/dist/resources/ProductDetails.js.map +0 -1
  117. package/dist/resources/ProductRelation.js.map +0 -1
  118. package/dist/resources/cfFields.js.map +0 -1
  119. package/dist/types.js.map +0 -1
  120. package/dist/utils.js.map +0 -1
  121. package/docs/import-data-from-the-dictionary.md +0 -83
  122. package/docs/import-products.md +0 -61
  123. package/docs/import-taxonomies-from-the-catalog.md +0 -60
  124. package/docs/settings.md +0 -47
  125. package/jest.config.js +0 -16
  126. package/local-fn/reindex.js +0 -182
  127. package/src/algolia/clean.ts +0 -164
  128. package/src/algolia/config.ts +0 -390
  129. package/src/algolia/downloads.ts +0 -346
  130. package/src/algolia/families.ts +0 -652
  131. package/src/algolia/inspirations.ts +0 -315
  132. package/src/algolia/models.ts +0 -589
  133. package/src/algolia/news.ts +0 -258
  134. package/src/algolia/pressRelease.ts +0 -255
  135. package/src/algolia/pressReview.ts +0 -247
  136. package/src/algolia/products.ts +0 -731
  137. package/src/algolia/projects.ts +0 -339
  138. package/src/algolia/stories.ts +0 -347
  139. package/src/algolia/subFamilies.ts +0 -709
  140. package/src/algolia/subModels.ts +0 -359
  141. package/src/browser.ts +0 -122
  142. package/src/downloads/classes/manageEntry.ts +0 -99
  143. package/src/downloads/csv/legal.csv +0 -5
  144. package/src/downloads/csv/products.csv +0 -373
  145. package/src/downloads/import.ts +0 -381
  146. package/src/index.ts +0 -140
  147. package/src/libs/contentful-cda.ts +0 -543
  148. package/src/libs/contentful.ts +0 -1453
  149. package/src/libs/imgix.ts +0 -297
  150. package/src/libs/logs.ts +0 -121
  151. package/src/libs/netlify.ts +0 -37
  152. package/src/libs/notifications.ts +0 -104
  153. package/src/libs/pdf.ts +0 -107
  154. package/src/libs/s3.ts +0 -305
  155. package/src/libs/sentry.ts +0 -33
  156. package/src/pim/config.ts +0 -84
  157. package/src/pim/data/productFields.json +0 -1178
  158. package/src/pim/endpoints.ts +0 -364
  159. package/src/pim/methods/bulkPublish.ts +0 -266
  160. package/src/pim/methods/catalogs.ts +0 -586
  161. package/src/pim/methods/checkTopicDraftAndPagePublished.ts +0 -70
  162. package/src/pim/methods/designers.ts +0 -128
  163. package/src/pim/methods/dictionary.ts +0 -611
  164. package/src/pim/methods/families.ts +0 -345
  165. package/src/pim/methods/latestProducts.ts +0 -70
  166. package/src/pim/methods/migrateEntryFields.ts +0 -99
  167. package/src/pim/methods/models.ts +0 -349
  168. package/src/pim/methods/pages/catalogs.ts +0 -28
  169. package/src/pim/methods/pages/families.ts +0 -50
  170. package/src/pim/methods/pages/subfamilies.ts +0 -98
  171. package/src/pim/methods/products.ts +0 -3297
  172. package/src/pim/methods/subfamilies.ts +0 -706
  173. package/src/pim/methods/submodels.ts +0 -262
  174. package/src/pim/request.ts +0 -61
  175. package/src/resources/AllProducts.ts +0 -41
  176. package/src/resources/Audit.ts +0 -24
  177. package/src/resources/CatalogDetails.ts +0 -51
  178. package/src/resources/CollectionModels.ts +0 -42
  179. package/src/resources/CollectionSubFamilies.ts +0 -45
  180. package/src/resources/CollectionSubModels.ts +0 -36
  181. package/src/resources/DProductSubLine.ts +0 -34
  182. package/src/resources/FamilyDetails.ts +0 -31
  183. package/src/resources/ProductDetails.ts +0 -352
  184. package/src/resources/ProductRelation.ts +0 -24
  185. package/src/resources/cfFields.ts +0 -8
  186. package/src/types.ts +0 -268
  187. package/src/utils.ts +0 -553
  188. package/tsconfig.json +0 -93
  189. package/tslint.json +0 -22
  190. package/types/libs/puppeteer.d.ts +0 -17
  191. package/types/pim/methods/checkIp.d.ts +0 -1
  192. /package/{types → dist}/algolia/clean.d.ts +0 -0
  193. /package/{types → dist}/algolia/config.d.ts +0 -0
  194. /package/{types → dist}/algolia/downloads.d.ts +0 -0
  195. /package/{types → dist}/algolia/families.d.ts +0 -0
  196. /package/{types → dist}/algolia/inspirations.d.ts +0 -0
  197. /package/{types → dist}/algolia/models.d.ts +0 -0
  198. /package/{types → dist}/algolia/news.d.ts +0 -0
  199. /package/{types → dist}/algolia/pressRelease.d.ts +0 -0
  200. /package/{types → dist}/algolia/pressReview.d.ts +0 -0
  201. /package/{types → dist}/algolia/products.d.ts +0 -0
  202. /package/{types → dist}/algolia/projects.d.ts +0 -0
  203. /package/{types → dist}/algolia/stories.d.ts +0 -0
  204. /package/{types → dist}/algolia/subFamilies.d.ts +0 -0
  205. /package/{types → dist}/algolia/subModels.d.ts +0 -0
  206. /package/{types → dist}/browser.d.ts +0 -0
  207. /package/{types → dist}/downloads/classes/manageEntry.d.ts +0 -0
  208. /package/{types → dist}/downloads/import.d.ts +0 -0
  209. /package/{types → dist}/index.d.ts +0 -0
  210. /package/{types → dist}/libs/contentful-cda.d.ts +0 -0
  211. /package/{types → dist}/libs/contentful.d.ts +0 -0
  212. /package/{types → dist}/libs/imgix.d.ts +0 -0
  213. /package/{types → dist}/libs/logs.d.ts +0 -0
  214. /package/{types → dist}/libs/netlify.d.ts +0 -0
  215. /package/{types → dist}/libs/notifications.d.ts +0 -0
  216. /package/{types → dist}/libs/pdf.d.ts +0 -0
  217. /package/{types → dist}/libs/s3.d.ts +0 -0
  218. /package/{types → dist}/libs/sentry.d.ts +0 -0
  219. /package/{types → dist}/pim/config.d.ts +0 -0
  220. /package/{types → dist}/pim/endpoints.d.ts +0 -0
  221. /package/{types → dist}/pim/methods/bulkPublish.d.ts +0 -0
  222. /package/{types → dist}/pim/methods/catalogs.d.ts +0 -0
  223. /package/{types → dist}/pim/methods/checkTopicDraftAndPagePublished.d.ts +0 -0
  224. /package/{types → dist}/pim/methods/designers.d.ts +0 -0
  225. /package/{types → dist}/pim/methods/dictionary.d.ts +0 -0
  226. /package/{types → dist}/pim/methods/families.d.ts +0 -0
  227. /package/{types → dist}/pim/methods/latestProducts.d.ts +0 -0
  228. /package/{types → dist}/pim/methods/migrateEntryFields.d.ts +0 -0
  229. /package/{types → dist}/pim/methods/models.d.ts +0 -0
  230. /package/{types → dist}/pim/methods/pages/catalogs.d.ts +0 -0
  231. /package/{types → dist}/pim/methods/pages/families.d.ts +0 -0
  232. /package/{types → dist}/pim/methods/pages/subfamilies.d.ts +0 -0
  233. /package/{types → dist}/pim/methods/products.d.ts +0 -0
  234. /package/{types → dist}/pim/methods/subfamilies.d.ts +0 -0
  235. /package/{types → dist}/pim/methods/submodels.d.ts +0 -0
  236. /package/{types → dist}/pim/request.d.ts +0 -0
  237. /package/{types → dist}/resources/AllProducts.d.ts +0 -0
  238. /package/{types → dist}/resources/Audit.d.ts +0 -0
  239. /package/{types → dist}/resources/CatalogDetails.d.ts +0 -0
  240. /package/{types → dist}/resources/CollectionModels.d.ts +0 -0
  241. /package/{types → dist}/resources/CollectionSubFamilies.d.ts +0 -0
  242. /package/{types → dist}/resources/CollectionSubModels.d.ts +0 -0
  243. /package/{types → dist}/resources/DProductSubLine.d.ts +0 -0
  244. /package/{types → dist}/resources/FamilyDetails.d.ts +0 -0
  245. /package/{types → dist}/resources/ProductDetails.d.ts +0 -0
  246. /package/{types → dist}/resources/ProductRelation.d.ts +0 -0
  247. /package/{types → dist}/resources/cfFields.d.ts +0 -0
  248. /package/{types → dist}/types.d.ts +0 -0
  249. /package/{types → dist}/utils.d.ts +0 -0
@@ -1,611 +0,0 @@
1
- import { getDictionary } from "../endpoints";
2
- import {
3
- ObjectPartial,
4
- CfLocalizedEntryField,
5
- ProductFieldsRequiredData,
6
- } from "../../types";
7
- import {
8
- createEntryWithId,
9
- updateEntry,
10
- getEntryByCode,
11
- addFieldValue,
12
- addToRelationFields,
13
- getDictionaryJson,
14
- } from "../../libs/contentful";
15
- import productFieldsRequiredData from "../data/productFields.json";
16
- import mime from "mime-types";
17
- import {
18
- checkConfig as checkS3Config,
19
- upload as uploadToS3,
20
- getFileFromS3,
21
- saveJsonToS3,
22
- } from "../../libs/s3";
23
- import type {
24
- CreateEntryProps,
25
- Entry,
26
- } from "contentful-management/dist/typings/entities/entry";
27
- import { log, serverUtils } from "../../libs/logs";
28
- import {
29
- getPimTranslations,
30
- getLocalISOTime,
31
- sanitizeValue,
32
- } from "../../utils";
33
- import { DProductSubLine } from "../../resources/DProductSubLine";
34
- import {
35
- certificationFields,
36
- excludeCertificationFieldsKeys,
37
- } from "./products";
38
-
39
- export const contentTypeId = "globalJsonFile";
40
- export const entryId = "globalJsonProductFields";
41
-
42
- type DictionaryRecord = {
43
- code: string;
44
- parentName: string | null;
45
- image: string | null;
46
- imageAlternative: string | null;
47
- value_en: string | null;
48
- value_en_US: string | null;
49
- value_it: string | null;
50
- value_es: string | null;
51
- value_de: string | null;
52
- value_fr: string | null;
53
- value_sv: string | null;
54
- value_no: string | null;
55
- value_da: string | null;
56
- value_ru: string | null;
57
- otherData: ObjectPartial;
58
- imageS3: string | null;
59
- imageAlternativeS3: string | null;
60
- priority: number | null;
61
- };
62
-
63
- const getRequiredDictionaryDataWithIcons = (): ProductFieldsRequiredData[] => {
64
- return productFieldsRequiredData.filter((field) => field.icon);
65
- };
66
-
67
- const importIcons = async (
68
- fieldValue: any,
69
- fieldProductKey: string,
70
- skipAlreadyExistsCheck: boolean = false
71
- ) => {
72
- log(`Import icons of field ${fieldProductKey}`);
73
- const imageFields = ["image", "imageAlternative"];
74
-
75
- for (const imageField of imageFields) {
76
- const s3FieldKey = `${imageField}S3`;
77
- if (fieldValue?.[imageField]) {
78
- const contentType = mime.lookup(fieldValue[imageField]);
79
- const imgUrl = fieldValue[imageField];
80
- const fileName = `${fieldValue.code}.${imgUrl.split(".").pop()}`;
81
- if (contentType) {
82
- const path = `icons/${fieldProductKey}/${imageField}`;
83
- const iconAlreadyExists = await getFileFromS3(
84
- `${path}/${fileName}`,
85
- true
86
- );
87
-
88
- if (iconAlreadyExists && !skipAlreadyExistsCheck) {
89
- log(
90
- `Icon ${imageField} "${fileName}" already exists to"${iconAlreadyExists}"`
91
- );
92
- fieldValue[s3FieldKey] = iconAlreadyExists;
93
- } else {
94
- log(
95
- `Uploading icon ${imageField} "${fileName}" to S3 path "${path}"`
96
- );
97
- try {
98
- const res = await uploadToS3(imgUrl, fileName, path);
99
- fieldValue[s3FieldKey] = res.Location;
100
- } catch (err: any) {
101
- log(
102
- `Uploading icon ${imageField} "${fileName}" to S3 path "${path}" failed. imgUrl: ${imgUrl}`,
103
- "WARN"
104
- );
105
- }
106
- }
107
- } else {
108
- log(
109
- `contentType not found. \nimageField: ${imageField} \nField: ${fieldProductKey} \nCode: ${fieldValue.code}`,
110
- "ERROR"
111
- );
112
- }
113
- } else {
114
- log(
115
- `image url not found. \n\nimageField: ${imageField} \nField: ${fieldProductKey} \nCode: ${fieldValue.code}`
116
- );
117
- }
118
- }
119
- return fieldValue;
120
- };
121
-
122
- export const importDictionaryIcons = async (
123
- skipAlreadyExistsCheck: boolean = false
124
- ): Promise<any> => {
125
- try {
126
- checkS3Config();
127
-
128
- log("importDictionaryIcons - Start", "INFO");
129
- log("Get S3 JSON dictionary file");
130
-
131
- const data = await getDictionaryJson();
132
-
133
- const requiredDictionaryDataWithIcons =
134
- getRequiredDictionaryDataWithIcons();
135
- let current: number = 0;
136
- for (const reqField of requiredDictionaryDataWithIcons) {
137
- const reqFieldKey = reqField.key;
138
- if (reqFieldKey && reqField.icon) {
139
- if (reqField.parent) {
140
- if (data?.[reqField.parent]?.[reqFieldKey]) {
141
- await Promise.all(
142
- data[reqField.parent][reqFieldKey].map(async (field: any) => {
143
- await importIcons(field, reqFieldKey, skipAlreadyExistsCheck);
144
- })
145
- );
146
- } else {
147
- log(`Field ${reqFieldKey} not found into contenful dictionary`);
148
- }
149
- } else {
150
- if (data?.[reqFieldKey]) {
151
- await Promise.all(
152
- data[reqFieldKey].map(async (field: any) => {
153
- await importIcons(field, reqFieldKey, skipAlreadyExistsCheck);
154
- })
155
- );
156
- } else {
157
- log(`Field ${reqFieldKey} not found into contenful dictionary`);
158
- }
159
- }
160
- }
161
- if (serverUtils) {
162
- serverUtils.log(reqFieldKey);
163
- const progress = Math.floor(
164
- (++current / requiredDictionaryDataWithIcons.length) * 100
165
- );
166
- serverUtils.updateProgress(progress);
167
- }
168
- }
169
-
170
- if (data?.certifications) {
171
- await Promise.all(
172
- data.certifications.map(async (field: any) => {
173
- await importIcons(field, "certifications", skipAlreadyExistsCheck);
174
- })
175
- );
176
- } else {
177
- log(`No certifications found into contenful dictionary`);
178
- }
179
-
180
- // Updating S3 dictionary entry data
181
- log("Updating S3 dictionary entry data");
182
- await saveJsonToS3(data, "dictionary.json");
183
- log("importDictionaryIcons - Completed");
184
-
185
- return { completed: true };
186
- } catch (err: any) {
187
- log(err, "ERROR");
188
- }
189
- };
190
-
191
- export const importDictionaryFields = async (
192
- offset: number = 0,
193
- limit: number = -1
194
- ): Promise<any> => {
195
- if (limit === 0) {
196
- log("the limit cannot be 0", "ERROR");
197
- }
198
- if (offset === 0) {
199
- await importDictionaryData();
200
- }
201
-
202
- log(`importDictionaryFields - offset: ${offset} limit: ${limit}`, "INFO");
203
-
204
- // Get dictionary data
205
- log("Get dictionary data");
206
- const pimDictionaryData: Partial<Record<string, DictionaryRecord[]>> =
207
- await getDictionary();
208
-
209
- // Icons Check
210
- log("Icons Check");
211
- const iconCodes = ["colour_18k-gold", "colour_alluminio-anodizzato-nero"];
212
- const iconsCheck = pimDictionaryData?.DWebColour?.filter((c) =>
213
- iconCodes.includes(c.code)
214
- );
215
- let iconEmpty = false;
216
- if (iconsCheck) {
217
- for (const icon of iconsCheck) {
218
- if (!icon?.image) {
219
- iconEmpty = true;
220
- console.log(icon);
221
- }
222
- }
223
- }
224
- if (iconEmpty) {
225
- throw new Error(`Icons not found. Codes: ${iconCodes.join(", ")}`);
226
- }
227
-
228
- if (pimDictionaryData) {
229
- // Filter required fields
230
- log("Filter required fields");
231
- let count: number = 0;
232
- let current: number = 0;
233
- const data: ObjectPartial = {};
234
- productFieldsRequiredData.push({
235
- key: "designer",
236
- parent: "",
237
- icon: false,
238
- dictionary: "Designer",
239
- type: "object",
240
- });
241
-
242
- // productFieldsRequiredData.push({
243
- // key: "categories",
244
- // parent: "",
245
- // icon: false,
246
- // dictionary: "DCategory",
247
- // type: "array",
248
- // });
249
- // productFieldsRequiredData.push({
250
- // key: "families",
251
- // parent: "",
252
- // icon: false,
253
- // dictionary: "Family",
254
- // type: "array",
255
- // });
256
- productFieldsRequiredData.push({
257
- key: "subFamilies",
258
- parent: "",
259
- icon: false,
260
- dictionary: "Subfamily",
261
- type: "array",
262
- });
263
- productFieldsRequiredData.push({
264
- key: "models",
265
- parent: "",
266
- icon: false,
267
- dictionary: "Model",
268
- type: "array",
269
- });
270
- productFieldsRequiredData.push({
271
- key: "productLine",
272
- parent: "",
273
- icon: false,
274
- dictionary: "DProductLine",
275
- type: "array",
276
- });
277
- productFieldsRequiredData.push({
278
- key: "categories",
279
- parent: "",
280
- icon: false,
281
- dictionary: "DCategory",
282
- type: "array",
283
- });
284
- // productFieldsRequiredData.push({
285
- // key: "subModels",
286
- // parent: "",
287
- // icon: false,
288
- // dictionary: "SubModel",
289
- // type: "array",
290
- // });
291
- for (const productFieldRequiredData of productFieldsRequiredData) {
292
- if (offset <= count || limit === -1) {
293
- if (
294
- productFieldRequiredData.dictionary &&
295
- pimDictionaryData?.[productFieldRequiredData.dictionary]
296
- ) {
297
- log(`Import ${productFieldRequiredData.dictionary}`);
298
- const dictionaryRecord =
299
- pimDictionaryData?.[productFieldRequiredData.dictionary];
300
- if (productFieldRequiredData.parent) {
301
- if (!data[productFieldRequiredData.parent]) {
302
- data[productFieldRequiredData.parent] = {};
303
- }
304
- data[productFieldRequiredData.parent][
305
- productFieldRequiredData.key
306
- ] = dictionaryRecord;
307
- } else {
308
- data[productFieldRequiredData.key] = dictionaryRecord;
309
- }
310
- } else if (productFieldRequiredData.dictionary) {
311
- log(`${productFieldRequiredData.dictionary} not found`, "WARN");
312
- }
313
- if (limit !== -1 && count + 1 - offset >= limit) {
314
- break;
315
- }
316
- }
317
- count++;
318
- if (serverUtils) {
319
- serverUtils.log(productFieldRequiredData.key);
320
- const currentTotal =
321
- productFieldsRequiredData.length > limit && limit !== -1
322
- ? limit
323
- : productFieldsRequiredData.length;
324
- const progress = Math.floor((++current / currentTotal) * 100);
325
- serverUtils.updateProgress(progress);
326
- }
327
- }
328
-
329
- const completed = count >= productFieldsRequiredData.length;
330
-
331
- if (completed) {
332
- log("Create certifications");
333
- let certifications: DictionaryRecord[] = [];
334
- for (const certificationField of certificationFields) {
335
- const pimCertifications: { string: DictionaryRecord[] } =
336
- data[certificationField];
337
- for (const [key, values] of Object.entries(pimCertifications)) {
338
- if (!excludeCertificationFieldsKeys.includes(key)) {
339
- log(`Add ${key} values to certifications`);
340
- certifications = certifications.concat(values);
341
- }
342
- }
343
- log(`Remove unwanted values to certifications`);
344
- certifications = certifications.filter((value) => {
345
- return sanitizeValue(value?.code);
346
- });
347
- }
348
- log(`Add certifications to data`);
349
- data.certifications = certifications;
350
-
351
- log("Create catalogs");
352
- data.catalogs = pimDictionaryData.Catalog;
353
- }
354
-
355
- if (Object.entries(data).length) {
356
- // Create/Update Contentful entry
357
- log("Create/Update Contentful entry");
358
- // await updateContentfulDictionaryData(data, offset === 0);
359
-
360
- await saveJsonToS3(data, "dictionary.json", "");
361
- } else {
362
- log("no matches found", "ERROR");
363
- }
364
-
365
- return {
366
- offset: Number(offset) + Number(limit),
367
- limit: Number(limit),
368
- completed, // if is true the import is completed
369
- total: productFieldsRequiredData.length,
370
- };
371
- } else {
372
- log("no data found in the dictionary", "ERROR");
373
- }
374
- };
375
-
376
- export const importDictionaryData = async (): Promise<any> => {
377
- log(`importDictionaryData`, "INFO");
378
-
379
- // Get dictionary data
380
- log("Get dictionary data");
381
- const pimDictionaryData: Partial<Record<string, DictionaryRecord[]>> =
382
- await getDictionary();
383
-
384
- if (pimDictionaryData && Object.keys(pimDictionaryData).length) {
385
- const dictionaryData = {} as any;
386
-
387
- for (const key in pimDictionaryData) {
388
- if (Array.isArray(pimDictionaryData[key])) {
389
- //@ts-ignore
390
- dictionaryData[key] = pimDictionaryData[key].map((item) => ({
391
- code: item.code,
392
- parentName: item.parentName,
393
- image: item.image,
394
- imageAlternative: item.imageAlternative,
395
- value_en: item.value_en,
396
- imageS3: item.imageS3,
397
- imageAlternativeS3: item.imageAlternativeS3,
398
- }));
399
- } else {
400
- dictionaryData[key] = pimDictionaryData[key];
401
- }
402
- }
403
-
404
- if (Object.entries(dictionaryData).length) {
405
- // Create/Update Contentful entry
406
- log("Create/Update Contentful entry");
407
- // await updateContentfulDictionaryData(data, offset === 0);
408
-
409
- await saveJsonToS3(dictionaryData, "dictionary-data.json", "");
410
- } else {
411
- log("no matches found", "ERROR");
412
- }
413
- } else {
414
- log("no data found in the dictionary", "ERROR");
415
- }
416
- };
417
-
418
- const getProductLineData = async (
419
- names: CfLocalizedEntryField,
420
- code: string,
421
- productLineEntry: Entry | null
422
- ) => {
423
- const data: CreateEntryProps = {
424
- fields: productLineEntry?.fields || {},
425
- };
426
- data.fields.name = names;
427
- data.fields = await addFieldValue(data, "code", code);
428
-
429
- // lastPimSyncDate
430
- data.fields = await addFieldValue(data, "lastPimSyncDate", getLocalISOTime());
431
-
432
- return data;
433
- };
434
-
435
- /**
436
- * Import producLine
437
- * - name
438
- * - code
439
- * - lastPimSyncDate
440
- *
441
- * @returns
442
- */
443
- export const importDictionaryProductLine = async (): Promise<any> => {
444
- log(`importDictionaryProductLine`, "INFO");
445
-
446
- // Get dictionary data
447
- log("Get dictionary data");
448
- const pimDictionaryData = await getDictionary();
449
- if (pimDictionaryData) {
450
- let count: number = 0;
451
- if (pimDictionaryData?.DProductLine.length) {
452
- for (const item of pimDictionaryData.DProductLine) {
453
- const names: CfLocalizedEntryField = getPimTranslations(item);
454
- const productLine: DictionaryRecord = item;
455
- log(`Import productLine ${productLine.code}`);
456
-
457
- let productLineEntry = await getEntryByCode(
458
- productLine.code,
459
- "topicProductLine"
460
- );
461
-
462
- const data: CreateEntryProps = await getProductLineData(
463
- names,
464
- productLine.code,
465
- productLineEntry
466
- );
467
-
468
- if (productLineEntry) {
469
- log(`ProductLine ${productLine.code} already exists. Updating...`);
470
- productLineEntry = await updateEntry(
471
- productLineEntry,
472
- data,
473
- productLineEntry.isPublished()
474
- );
475
- } else {
476
- log(
477
- `ProductLine ${productLine.code} not exists. Create new entry with data`
478
- );
479
- productLineEntry = await createEntryWithId(
480
- "topicProductLine",
481
- productLine.code,
482
- data,
483
- true
484
- );
485
- }
486
-
487
- ++count;
488
- if (serverUtils) {
489
- serverUtils.log(productLine.code);
490
- const progress = Math.floor(
491
- (count / pimDictionaryData.DProductLine.length) * 100
492
- );
493
- serverUtils.updateProgress(progress);
494
- }
495
- }
496
- }
497
-
498
- return count;
499
- } else {
500
- log("no data found in the dictionary", "ERROR");
501
- }
502
- };
503
-
504
- const getProductSubLineData = async (
505
- names: CfLocalizedEntryField,
506
- code: string,
507
- productLineEntry: Entry | null,
508
- productSubLineEntry: Entry | null
509
- ) => {
510
- const data: CreateEntryProps = {
511
- fields: productSubLineEntry?.fields || {},
512
- };
513
- data.fields.name = names;
514
- data.fields = await addFieldValue(data, "code", code);
515
-
516
- // parentProductLine
517
- if (productLineEntry) {
518
- data.fields = await addToRelationFields(
519
- data,
520
- "parentProductLine",
521
- productLineEntry.sys.id
522
- );
523
- }
524
-
525
- // lastPimSyncDate
526
- data.fields = await addFieldValue(data, "lastPimSyncDate", getLocalISOTime());
527
-
528
- return data;
529
- };
530
-
531
- export const importDictionaryProductSubLine = async (): Promise<any> => {
532
- log(`importDictionaryProductSubLine`, "INFO");
533
-
534
- // Get dictionary data
535
- log("Get dictionary data");
536
- const pimDictionaryData = await getDictionary();
537
- if (pimDictionaryData) {
538
- let count: number = 0;
539
- if (pimDictionaryData?.DProductSubLine.length) {
540
- for (const item of pimDictionaryData.DProductSubLine) {
541
- const names: CfLocalizedEntryField = getPimTranslations(item);
542
- const productSubLine: DProductSubLine = item;
543
- log(`Import productSubLine ${productSubLine.code}`);
544
-
545
- let productSubLineEntry = await getEntryByCode(
546
- productSubLine.code,
547
- "topicProductSubLine"
548
- );
549
-
550
- let productLineEntry = null;
551
- if (productSubLine.othersData.productLine.code) {
552
- productLineEntry = await getEntryByCode(
553
- productSubLine.othersData.productLine.code,
554
- "topicProductLine"
555
- );
556
-
557
- if (!productLineEntry) {
558
- log(
559
- `No topicProductLine with code ${productSubLine.othersData.productLine.code} found for the productSubLine ${productSubLine.code}`
560
- );
561
- }
562
- } else {
563
- log(
564
- `No parent productLine found for the productSubLine ${productSubLine.code} from PIM`
565
- );
566
- }
567
-
568
- const data: CreateEntryProps = await getProductSubLineData(
569
- names,
570
- productSubLine.code,
571
- productLineEntry,
572
- productSubLineEntry
573
- );
574
-
575
- if (productSubLineEntry) {
576
- log(
577
- `ProductSubLine ${productSubLine.code} already exists. Updating...`
578
- );
579
- productSubLineEntry = await updateEntry(
580
- productSubLineEntry,
581
- data,
582
- productSubLineEntry.isPublished()
583
- );
584
- } else {
585
- log(
586
- `ProductSubLine ${productSubLine.code} not exists. Create new entry with data`
587
- );
588
- productSubLineEntry = await createEntryWithId(
589
- "topicProductSubLine",
590
- productSubLine.code,
591
- data,
592
- true
593
- );
594
- }
595
-
596
- ++count;
597
- if (serverUtils) {
598
- serverUtils.log(productSubLine.code);
599
- const progress = Math.floor(
600
- (count / pimDictionaryData.DProductSubLine.length) * 100
601
- );
602
- serverUtils.updateProgress(progress);
603
- }
604
- }
605
- }
606
-
607
- return count;
608
- } else {
609
- log("no data found in the dictionary", "ERROR");
610
- }
611
- };