pim-import 3.0.0 → 3.1.0

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 (49) hide show
  1. package/dist/algolia/families.js +6 -0
  2. package/dist/algolia/families.js.map +1 -1
  3. package/dist/algolia/models.js +6 -0
  4. package/dist/algolia/models.js.map +1 -1
  5. package/dist/algolia/products.js +6 -0
  6. package/dist/algolia/products.js.map +1 -1
  7. package/dist/algolia/subFamilies.js +6 -0
  8. package/dist/algolia/subFamilies.js.map +1 -1
  9. package/dist/algolia/subModels.js +6 -0
  10. package/dist/algolia/subModels.js.map +1 -1
  11. package/dist/index.js +2 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/libs/logs.js +6 -1
  14. package/dist/libs/logs.js.map +1 -1
  15. package/dist/pim/methods/catalogs.js +9 -0
  16. package/dist/pim/methods/catalogs.js.map +1 -1
  17. package/dist/pim/methods/dictionary.js +15 -0
  18. package/dist/pim/methods/dictionary.js.map +1 -1
  19. package/dist/pim/methods/families.js +7 -0
  20. package/dist/pim/methods/families.js.map +1 -1
  21. package/dist/pim/methods/latestProducts.js +6 -0
  22. package/dist/pim/methods/latestProducts.js.map +1 -1
  23. package/dist/pim/methods/models.js +6 -0
  24. package/dist/pim/methods/models.js.map +1 -1
  25. package/dist/pim/methods/products.js +17 -1
  26. package/dist/pim/methods/products.js.map +1 -1
  27. package/dist/pim/methods/subfamilies.js +6 -0
  28. package/dist/pim/methods/subfamilies.js.map +1 -1
  29. package/dist/pim/methods/submodels.js +6 -0
  30. package/dist/pim/methods/submodels.js.map +1 -1
  31. package/package.json +1 -1
  32. package/src/algolia/families.ts +7 -1
  33. package/src/algolia/models.ts +7 -1
  34. package/src/algolia/products.ts +7 -1
  35. package/src/algolia/subFamilies.ts +7 -1
  36. package/src/algolia/subModels.ts +7 -1
  37. package/src/index.ts +1 -0
  38. package/src/libs/logs.ts +6 -0
  39. package/src/pim/methods/catalogs.ts +12 -1
  40. package/src/pim/methods/dictionary.ts +19 -1
  41. package/src/pim/methods/families.ts +9 -1
  42. package/src/pim/methods/latestProducts.ts +7 -1
  43. package/src/pim/methods/models.ts +10 -1
  44. package/src/pim/methods/products.ts +21 -2
  45. package/src/pim/methods/subfamilies.ts +10 -1
  46. package/src/pim/methods/submodels.ts +10 -1
  47. package/types/fonts.d.ts +2 -0
  48. package/types/index.d.ts +1 -1
  49. package/types/libs/logs.d.ts +2 -0
@@ -14,7 +14,7 @@ import {
14
14
  WrapperImageFields,
15
15
  } from "../types";
16
16
  import type { Entry } from "contentful-management/dist/typings/entities/entry";
17
- import { log } from "../libs/logs";
17
+ import { log, serverUtils } from "../libs/logs";
18
18
  import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
19
19
  import {
20
20
  getLocalISOTime,
@@ -441,6 +441,7 @@ const getObjects = async (
441
441
 
442
442
  const objects: AlgoliaProductRecord[] = [];
443
443
  let count: number = Number(offset);
444
+ let current: number = 0;
444
445
  for (const topicProduct of items) {
445
446
  log(`${++count} of ${total}`, "INFO");
446
447
  const timeStart = new Date();
@@ -449,6 +450,11 @@ const getObjects = async (
449
450
  const seconds = secondBetweenTwoDate(timeStart, timeEnd);
450
451
  log(`Execution time: ${seconds} seconds`);
451
452
  objects.push(record);
453
+ if (serverUtils) {
454
+ serverUtils.log(topicProduct.sys.id);
455
+ const progress = Math.floor((++current / items.length) * 100);
456
+ serverUtils.updateProgress(progress);
457
+ }
452
458
  }
453
459
 
454
460
  return {
@@ -10,7 +10,7 @@ import {
10
10
  } from "../libs/contentful-cda";
11
11
  import { AlgoliaPaginateRecords, AvailableCatalogs } from "../types";
12
12
  import type { Entry } from "contentful-management/dist/typings/entities/entry";
13
- import { log } from "../libs/logs";
13
+ import { log, serverUtils } from "../libs/logs";
14
14
  import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
15
15
  import {
16
16
  getLocalISOTime,
@@ -355,6 +355,7 @@ const getObjects = async (
355
355
 
356
356
  const objects: AlgoliaFamilyRecord[] = [];
357
357
  let count: number = Number(offset);
358
+ let current: number = 0;
358
359
  for (const topicSubFamily of items) {
359
360
  log(`${++count} of ${total}`, "INFO");
360
361
  const timeStart = new Date();
@@ -363,6 +364,11 @@ const getObjects = async (
363
364
  const seconds = secondBetweenTwoDate(timeStart, timeEnd);
364
365
  log(`Execution time: ${seconds} seconds`);
365
366
  objects.push(record);
367
+ if (serverUtils) {
368
+ serverUtils.log(topicSubFamily.sys.id);
369
+ const progress = Math.floor((++current / items.length) * 100);
370
+ serverUtils.updateProgress(progress);
371
+ }
366
372
  }
367
373
 
368
374
  return {
@@ -16,7 +16,7 @@ import {
16
16
  TopicProductFieldsResponse,
17
17
  WrapperImageFields,
18
18
  } from "../types";
19
- import { log } from "../libs/logs";
19
+ import { log, serverUtils } from "../libs/logs";
20
20
  import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
21
21
  import type { Entry } from "contentful-management/dist/typings/entities/entry";
22
22
  import {
@@ -287,6 +287,7 @@ const getObjects = async (
287
287
 
288
288
  const objects: AlgoliaSubModelRecord[] = [];
289
289
  let count: number = Number(offset);
290
+ let current: number = 0;
290
291
  for (const topicSubModel of items) {
291
292
  log(`${++count} of ${total}`, "INFO");
292
293
  const timeStart = new Date();
@@ -295,6 +296,11 @@ const getObjects = async (
295
296
  const seconds = secondBetweenTwoDate(timeStart, timeEnd);
296
297
  log(`Execution time: ${seconds} seconds`);
297
298
  objects.push(record);
299
+ if (serverUtils) {
300
+ serverUtils.log(topicSubModel.sys.id);
301
+ const progress = Math.floor((++current / items.length) * 100);
302
+ serverUtils.updateProgress(progress);
303
+ }
298
304
  }
299
305
 
300
306
  return {
package/src/index.ts CHANGED
@@ -113,6 +113,7 @@ export { getLocalISOTime } from "./utils";
113
113
  export { getStaticDailyProducts, getLatestProducts } from "./pim/endpoints";
114
114
  export {
115
115
  log,
116
+ setServerUtils,
116
117
  setLogId,
117
118
  setLogPath,
118
119
  setLogFilename,
package/src/libs/logs.ts CHANGED
@@ -14,6 +14,7 @@ let logId: string = "";
14
14
  let logPath: string = "";
15
15
  let logFilename: string = "";
16
16
  let Logger: any = null;
17
+ export let serverUtils: any = null;
17
18
 
18
19
  export const setLogId = (id: string) => {
19
20
  if (logId !== id) {
@@ -45,6 +46,10 @@ export const setLogFilename = (filename: string) => {
45
46
  }
46
47
  };
47
48
 
49
+ export const setServerUtils = (utils: any) => {
50
+ serverUtils = utils;
51
+ };
52
+
48
53
  export const getLogFolder = () => {
49
54
  return logPath ? `logs/${logPath}/` : `logs/`;
50
55
  };
@@ -81,6 +86,7 @@ export const log = (message: string, level: LogLevels = "INFO") => {
81
86
  }
82
87
  const winstonLevel: string = level.toLowerCase();
83
88
  message = logId ? `[${logId}] - ${message}` : message;
89
+
84
90
  if (level === "ERROR") {
85
91
  if (Logger) {
86
92
  Logger.log(winstonLevel, message);
@@ -26,7 +26,7 @@ import {
26
26
  addFieldValue,
27
27
  } from "../../libs/contentful";
28
28
  import { getCatalogTaxonomiesHierarchy } from "../endpoints";
29
- import { log } from "../../libs/logs";
29
+ import { log, serverUtils } from "../../libs/logs";
30
30
  import {
31
31
  sleep,
32
32
  getPimTranslations,
@@ -512,6 +512,7 @@ export const importCategories = async (
512
512
  const categoryEntries: string[] = [];
513
513
  if (catalogDetails.categories?.length) {
514
514
  let count: number = 0;
515
+ let current: number = 0;
515
516
  for (const categoryDetails of catalogDetails.categories) {
516
517
  if (offset <= count || limit === -1) {
517
518
  log(`${count + 1} of ${catalogDetails.categories.length}`);
@@ -530,6 +531,16 @@ export const importCategories = async (
530
531
  }
531
532
  await sleep(100);
532
533
 
534
+ if (serverUtils) {
535
+ serverUtils.log(categoryDetails.data.code);
536
+ const currentTotal =
537
+ catalogDetails.categories.length > limit
538
+ ? limit
539
+ : catalogDetails.categories.length;
540
+ const progress = Math.floor((++current / currentTotal) * 100);
541
+ serverUtils.updateProgress(progress);
542
+ }
543
+
533
544
  if (limit !== -1 && count + 1 - offset >= limit) {
534
545
  break;
535
546
  }
@@ -23,7 +23,7 @@ import type {
23
23
  CreateEntryProps,
24
24
  Entry,
25
25
  } from "contentful-management/dist/typings/entities/entry";
26
- import { log } from "../../libs/logs";
26
+ import { log, serverUtils } from "../../libs/logs";
27
27
  import {
28
28
  getPimTranslations,
29
29
  getLocalISOTime,
@@ -118,6 +118,7 @@ export const importDictionaryIcons = async (
118
118
 
119
119
  const requiredDictionaryDataWithIcons =
120
120
  getRequiredDictionaryDataWithIcons();
121
+ let current: number = 0;
121
122
  for (const reqField of requiredDictionaryDataWithIcons) {
122
123
  const reqFieldKey = reqField.key;
123
124
  if (reqFieldKey && reqField.icon) {
@@ -143,6 +144,13 @@ export const importDictionaryIcons = async (
143
144
  }
144
145
  }
145
146
  }
147
+ if (serverUtils) {
148
+ serverUtils.log(reqFieldKey);
149
+ const progress = Math.floor(
150
+ (++current / requiredDictionaryDataWithIcons.length) * 100
151
+ );
152
+ serverUtils.updateProgress(progress);
153
+ }
146
154
  }
147
155
 
148
156
  if (data?.certifications) {
@@ -203,6 +211,7 @@ export const importDictionaryFields = async (
203
211
  // Filter required fields
204
212
  log("Filter required fields");
205
213
  let count: number = 0;
214
+ let current: number = 0;
206
215
  const data: ObjectPartial = {};
207
216
  for (const productFieldRequiredData of productFieldsRequiredData) {
208
217
  if (offset <= count || limit === -1) {
@@ -231,6 +240,15 @@ export const importDictionaryFields = async (
231
240
  }
232
241
  }
233
242
  count++;
243
+ if (serverUtils) {
244
+ serverUtils.log(productFieldRequiredData.key);
245
+ const currentTotal =
246
+ productFieldsRequiredData.length > limit
247
+ ? limit
248
+ : productFieldsRequiredData.length;
249
+ const progress = Math.floor((++current / currentTotal) * 100);
250
+ serverUtils.updateProgress(progress);
251
+ }
234
252
  }
235
253
 
236
254
  const completed = count >= productFieldsRequiredData.length;
@@ -1,5 +1,5 @@
1
1
  import { getFamilies } from "../endpoints";
2
- import { log } from "../../libs/logs";
2
+ import { log, serverUtils } from "../../libs/logs";
3
3
  import type {
4
4
  Entry,
5
5
  CreateEntryProps,
@@ -260,6 +260,7 @@ export const importFamilies = async (
260
260
  const families = await getFamilies();
261
261
 
262
262
  let count: number = 0;
263
+ let current: number = 0;
263
264
  for (const family of families) {
264
265
  if (offset <= count || limit === -1) {
265
266
  if (!sanitizeValue(family.data.code)) {
@@ -273,6 +274,13 @@ export const importFamilies = async (
273
274
  if (limit !== -1 && count + 1 - offset >= limit) {
274
275
  break;
275
276
  }
277
+ if (serverUtils) {
278
+ serverUtils.log(family.data.code);
279
+ const currentTotal =
280
+ families.length > limit ? limit : families.length;
281
+ const progress = Math.floor((++current / currentTotal) * 100);
282
+ serverUtils.updateProgress(progress);
283
+ }
276
284
  // Max 7 calls per seconds
277
285
  if (count % 2 === 0 && count < families.length) {
278
286
  await sleep(1000);
@@ -1,6 +1,6 @@
1
1
  import { AvailableCatalogs, PaginationResults } from "../../types";
2
2
  import { getLatestProducts } from "../endpoints";
3
- import { log } from "../../libs/logs";
3
+ import { log, serverUtils } from "../../libs/logs";
4
4
  import { ProductDetails } from "../../resources/ProductDetails";
5
5
  import { importProduct } from "./products";
6
6
  import { secondBetweenTwoDate } from "../../utils";
@@ -35,11 +35,17 @@ export const importLatestProducts = async (
35
35
  log(`${total} products founded`);
36
36
 
37
37
  let count: number = offset + 1;
38
+ let current: number = 0;
38
39
  for (const product of products) {
39
40
  log(`${count} of ${total}`);
40
41
  const productDetails: ProductDetails = product.content;
41
42
  await importProduct(productDetails, catalog);
42
43
  count++;
44
+ if (serverUtils) {
45
+ serverUtils.log(productDetails.code);
46
+ const progress = Math.floor((++current / products.length) * 100);
47
+ serverUtils.updateProgress(progress);
48
+ }
43
49
  }
44
50
 
45
51
  const timeEnd = new Date();
@@ -9,7 +9,7 @@ import {
9
9
  addFieldValue,
10
10
  addToRelationFields,
11
11
  } from "../../libs/contentful";
12
- import { log } from "../../libs/logs";
12
+ import { log, serverUtils } from "../../libs/logs";
13
13
  import type {
14
14
  Entry,
15
15
  CreateEntryProps,
@@ -258,6 +258,7 @@ export const importModels = async (
258
258
  if (models?.pagedCollection?.length) {
259
259
  log(`Founded ${total} models`);
260
260
  let count = offset;
261
+ let current: number = 0;
261
262
  for (const model of models.pagedCollection) {
262
263
  log(`${++count} of ${models.totalCount}`);
263
264
 
@@ -266,6 +267,14 @@ export const importModels = async (
266
267
  await createOrUpdatePage(topicModel);
267
268
  await updateComponentModelOfSubFamilyPages(topicModel);
268
269
 
270
+ if (serverUtils) {
271
+ serverUtils.log(model.code);
272
+ const progress = Math.floor(
273
+ (++current / models.pagedCollection.length) * 100
274
+ );
275
+ serverUtils.updateProgress(progress);
276
+ }
277
+
269
278
  // Max 7 calls per seconds
270
279
  if (count % 2 === 0 && count < models.totalCount) {
271
280
  await sleep(1000);
@@ -13,7 +13,7 @@ import {
13
13
  WrapperImageFields,
14
14
  CfSys,
15
15
  } from "../../types";
16
- import { log } from "../../libs/logs";
16
+ import { log, serverUtils } from "../../libs/logs";
17
17
  import {
18
18
  getEntryByCode,
19
19
  getAllEntriesByCodes,
@@ -537,12 +537,14 @@ const getProductAssets = async (
537
537
  if (
538
538
  process.env.FPI_IMGIX_PIM_IMAGE_DOMAIN &&
539
539
  pimAsset.url.indexOf(pimDomain) !== -1 &&
540
- ["jpg", "svg", "png", "gif"].includes(fileExtension)
540
+ ["jpg", "png", "gif"].includes(fileExtension)
541
541
  ) {
542
542
  assetUrl = pimAsset.url.replace(
543
543
  pimDomain,
544
544
  process.env.FPI_IMGIX_PIM_IMAGE_DOMAIN
545
545
  );
546
+ } else if (["svg"].includes(fileExtension)) {
547
+ assetUrl = pimAsset.url;
546
548
  } else {
547
549
  const path = `product-assets/${md5}`;
548
550
  const fileName = basename(pimAsset.url);
@@ -1410,14 +1412,24 @@ export const setProductsRelationships = async (
1410
1412
 
1411
1413
  let count: number = 0;
1412
1414
  let updated: number = 0;
1415
+ let current: number = 0;
1413
1416
  for (const product of JSONData) {
1414
1417
  if (offset <= count || limit === -1) {
1415
1418
  log(`${count + 1} of ${JSONData.length}`);
1416
1419
  await setProductRelationships(product.code, fieldKey);
1417
1420
  updated++;
1421
+
1422
+ if (serverUtils) {
1423
+ serverUtils.log(product.code);
1424
+ const currentTotal = JSONData.length > limit ? limit : JSONData.length;
1425
+ const progress = Math.floor((++current / currentTotal) * 100);
1426
+ serverUtils.updateProgress(progress);
1427
+ }
1428
+
1418
1429
  if (updated % 7 === 0) {
1419
1430
  await sleep(500);
1420
1431
  }
1432
+
1421
1433
  if (limit !== -1 && count + 1 - offset >= limit) {
1422
1434
  break;
1423
1435
  }
@@ -1600,6 +1612,7 @@ export const audit = async (
1600
1612
  log(`Founded ${entriesPage.length} topicProduct pages`);
1601
1613
 
1602
1614
  let count: number = offset;
1615
+ let current: number = 0;
1603
1616
  for (const audit of allAudit) {
1604
1617
  log(`${++count} of ${total}`);
1605
1618
  log(`I process the product ${audit.product} with status ${audit.what}`);
@@ -1758,6 +1771,12 @@ export const audit = async (
1758
1771
  `It has not yet been defined how to process the state ${audit.what}`
1759
1772
  );
1760
1773
  }
1774
+
1775
+ if (serverUtils) {
1776
+ serverUtils.log(audit.product);
1777
+ const progress = Math.floor((++current / allAudit.length) * 100);
1778
+ serverUtils.updateProgress(progress);
1779
+ }
1761
1780
  }
1762
1781
 
1763
1782
  const nextOffset = offset + limit;
@@ -11,7 +11,7 @@ import {
11
11
  addFieldValue,
12
12
  addDesignerData,
13
13
  } from "../../libs/contentful";
14
- import { log } from "../../libs/logs";
14
+ import { log, serverUtils } from "../../libs/logs";
15
15
  import type {
16
16
  Entry,
17
17
  CreateEntryProps,
@@ -496,6 +496,7 @@ export const importSubFamilies = async (
496
496
  if (subFamilies?.pagedCollection?.length) {
497
497
  log(`Import ${total} subFamilies`);
498
498
  let count = offset;
499
+ let current: number = 0;
499
500
  for (const subFamily of subFamilies.pagedCollection) {
500
501
  log(`${++count} of ${subFamilies.totalCount}`);
501
502
 
@@ -515,6 +516,14 @@ export const importSubFamilies = async (
515
516
 
516
517
  await createOrUpdatePage(topicSubFamily);
517
518
 
519
+ if (serverUtils) {
520
+ serverUtils.log(subFamily.data.code);
521
+ const progress = Math.floor(
522
+ (++current / subFamilies.pagedCollection.length) * 100
523
+ );
524
+ serverUtils.updateProgress(progress);
525
+ }
526
+
518
527
  // Max 7 calls per seconds
519
528
  if (count % 2 === 0 && count < subFamilies.totalCount) {
520
529
  await sleep(1000);
@@ -1,5 +1,5 @@
1
1
  import { PaginationResults } from "../../types";
2
- import { log } from "../../libs/logs";
2
+ import { log, serverUtils } from "../../libs/logs";
3
3
  import { getOtherCatalogData } from "../endpoints";
4
4
  import {
5
5
  CollectionSubModels,
@@ -218,11 +218,20 @@ export const importSubModels = async (
218
218
  if (subModels?.pagedCollection?.length) {
219
219
  log(`Founded ${total} subModels`);
220
220
  let count = offset;
221
+ let current: number = 0;
221
222
  for (const subModel of subModels.pagedCollection) {
222
223
  log(`${++count} of ${subModels.totalCount}`);
223
224
 
224
225
  await importSubModel(subModel);
225
226
 
227
+ if (serverUtils) {
228
+ serverUtils.log(subModel.code);
229
+ const progress = Math.floor(
230
+ (++current / subModels.pagedCollection.length) * 100
231
+ );
232
+ serverUtils.updateProgress(progress);
233
+ }
234
+
226
235
  // Max 7 calls per seconds
227
236
  if (count % 2 === 0 && count < subModels.totalCount) {
228
237
  await sleep(1000);
@@ -0,0 +1,2 @@
1
+ export declare module "*.woff";
2
+ export declare module "*.woff2";
package/types/index.d.ts CHANGED
@@ -25,6 +25,6 @@ export { reindexPost, reindexPosts, removePostObject } from "./algolia/news";
25
25
  export { importDownloads } from "./downloads/import";
26
26
  export { getLocalISOTime } from "./utils";
27
27
  export { getStaticDailyProducts, getLatestProducts } from "./pim/endpoints";
28
- export { log, setLogId, setLogPath, setLogFilename, getLogFolder, } from "./libs/logs";
28
+ export { log, setServerUtils, setLogId, setLogPath, setLogFilename, getLogFolder, } from "./libs/logs";
29
29
  export { removeRecordsByStatus } from "./algolia/clean";
30
30
  export { generatePDFByUrl } from "./libs/puppeteer";
@@ -1,9 +1,11 @@
1
1
  import winston from "winston";
2
2
  export declare type LogLevels = "VERBOSE" | "DEBUG" | "INFO" | "WARN" | "ERROR" | "SILLY" | "HTTP";
3
3
  export declare const logStatus = true;
4
+ export declare let serverUtils: any;
4
5
  export declare const setLogId: (id: string) => void;
5
6
  export declare const setLogPath: (path: string) => void;
6
7
  export declare const setLogFilename: (filename: string) => void;
8
+ export declare const setServerUtils: (utils: any) => void;
7
9
  export declare const getLogFolder: () => string;
8
10
  export declare const getLogger: () => winston.Logger;
9
11
  export declare const log: (message: string, level?: LogLevels) => void;