pim-import 2.82.3 → 3.1.1
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/families.js +6 -0
- package/dist/algolia/families.js.map +1 -1
- package/dist/algolia/models.js +6 -0
- package/dist/algolia/models.js.map +1 -1
- package/dist/algolia/products.js +6 -0
- package/dist/algolia/products.js.map +1 -1
- package/dist/algolia/subFamilies.js +6 -0
- package/dist/algolia/subFamilies.js.map +1 -1
- package/dist/algolia/subModels.js +6 -0
- package/dist/algolia/subModels.js.map +1 -1
- package/dist/browser.js +2 -4
- package/dist/browser.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/libs/logs.js +6 -1
- package/dist/libs/logs.js.map +1 -1
- package/dist/pim/endpoints.js +4 -3
- package/dist/pim/endpoints.js.map +1 -1
- package/dist/pim/methods/catalogs.js +9 -0
- package/dist/pim/methods/catalogs.js.map +1 -1
- package/dist/pim/methods/dictionary.js +25 -0
- package/dist/pim/methods/dictionary.js.map +1 -1
- package/dist/pim/methods/families.js +9 -0
- package/dist/pim/methods/families.js.map +1 -1
- package/dist/pim/methods/latestProducts.js +28 -36
- package/dist/pim/methods/latestProducts.js.map +1 -1
- package/dist/pim/methods/models.js +6 -0
- package/dist/pim/methods/models.js.map +1 -1
- package/dist/pim/methods/products.js +36 -1
- package/dist/pim/methods/products.js.map +1 -1
- package/dist/pim/methods/subfamilies.js +6 -0
- package/dist/pim/methods/subfamilies.js.map +1 -1
- package/dist/pim/methods/submodels.js +6 -0
- package/dist/pim/methods/submodels.js.map +1 -1
- package/package.json +1 -1
- package/src/algolia/families.ts +7 -1
- package/src/algolia/models.ts +7 -1
- package/src/algolia/products.ts +7 -1
- package/src/algolia/subFamilies.ts +7 -1
- package/src/algolia/subModels.ts +7 -1
- package/src/browser.ts +0 -1
- package/src/index.ts +2 -2
- package/src/libs/logs.ts +6 -0
- package/src/pim/endpoints.ts +7 -4
- package/src/pim/methods/catalogs.ts +12 -1
- package/src/pim/methods/dictionary.ts +33 -1
- package/src/pim/methods/families.ts +11 -1
- package/src/pim/methods/latestProducts.ts +44 -53
- package/src/pim/methods/models.ts +10 -1
- package/src/pim/methods/products.ts +44 -2
- package/src/pim/methods/subfamilies.ts +10 -1
- package/src/pim/methods/submodels.ts +10 -1
- package/types/browser.d.ts +0 -1
- package/types/fonts.d.ts +2 -0
- package/types/index.d.ts +2 -3
- package/types/libs/logs.d.ts +2 -0
- package/types/pim/endpoints.d.ts +1 -1
- package/types/pim/methods/latestProducts.d.ts +2 -12
- package/dist/pim/methods/dailyProductsUpdate.js +0 -51
- package/dist/pim/methods/dailyProductsUpdate.js.map +0 -1
- package/src/pim/methods/dailyProductsUpdate.ts +0 -73
- package/types/pim/methods/dailyProductsUpdate.d.ts +0 -2
|
@@ -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 && limit !== -1
|
|
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 && limit !== -1
|
|
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;
|
|
@@ -346,6 +364,13 @@ export const importDictionaryProductLine = async (): Promise<any> => {
|
|
|
346
364
|
}
|
|
347
365
|
|
|
348
366
|
++count;
|
|
367
|
+
if (serverUtils) {
|
|
368
|
+
serverUtils.log(productLine.code);
|
|
369
|
+
const progress = Math.floor(
|
|
370
|
+
(count / pimDictionaryData.DProductLine.length) * 100
|
|
371
|
+
);
|
|
372
|
+
serverUtils.updateProgress(progress);
|
|
373
|
+
}
|
|
349
374
|
}
|
|
350
375
|
}
|
|
351
376
|
|
|
@@ -448,6 +473,13 @@ export const importDictionaryProductSubLine = async (): Promise<any> => {
|
|
|
448
473
|
}
|
|
449
474
|
|
|
450
475
|
++count;
|
|
476
|
+
if (serverUtils) {
|
|
477
|
+
serverUtils.log(productSubLine.code);
|
|
478
|
+
const progress = Math.floor(
|
|
479
|
+
(count / pimDictionaryData.DProductSubLine.length) * 100
|
|
480
|
+
);
|
|
481
|
+
serverUtils.updateProgress(progress);
|
|
482
|
+
}
|
|
451
483
|
}
|
|
452
484
|
}
|
|
453
485
|
|
|
@@ -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)) {
|
|
@@ -277,6 +278,15 @@ export const importFamilies = async (
|
|
|
277
278
|
if (count % 2 === 0 && count < families.length) {
|
|
278
279
|
await sleep(1000);
|
|
279
280
|
}
|
|
281
|
+
if (serverUtils) {
|
|
282
|
+
serverUtils.log(family.data.code);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (serverUtils) {
|
|
286
|
+
const currentTotal =
|
|
287
|
+
families.length > limit && limit !== -1 ? limit : families.length;
|
|
288
|
+
const progress = Math.floor((++current / currentTotal) * 100);
|
|
289
|
+
serverUtils.updateProgress(progress);
|
|
280
290
|
}
|
|
281
291
|
}
|
|
282
292
|
count++;
|
|
@@ -1,71 +1,62 @@
|
|
|
1
|
-
import { AvailableCatalogs } from "../../types";
|
|
2
|
-
import { log } from "../../libs/logs";
|
|
1
|
+
import { AvailableCatalogs, PaginationResults } from "../../types";
|
|
3
2
|
import { getLatestProducts } from "../endpoints";
|
|
3
|
+
import { log, serverUtils } from "../../libs/logs";
|
|
4
|
+
import { ProductDetails } from "../../resources/ProductDetails";
|
|
4
5
|
import { importProduct } from "./products";
|
|
5
|
-
import {
|
|
6
|
+
import { secondBetweenTwoDate } from "../../utils";
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Import latest products
|
|
10
|
+
*
|
|
11
|
+
* @param {string} catalogCode The catalog code. Format: ARCHITECTURAL
|
|
12
|
+
* @param {string} lastModified The last modified data. Format: 20200426T07:50:00 - yearmonthdayThour:minute:second
|
|
13
|
+
* @param {number} offset Default 0
|
|
14
|
+
* @param {number} limit Default 50
|
|
15
|
+
*/
|
|
7
16
|
export const importLatestProducts = async (
|
|
8
17
|
catalog: AvailableCatalogs,
|
|
9
18
|
lastModified: string,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
offset: number = 0,
|
|
20
|
+
limit: number = 100
|
|
21
|
+
): Promise<PaginationResults> => {
|
|
22
|
+
const timeStart = new Date();
|
|
23
|
+
offset = Number(offset);
|
|
24
|
+
limit = Number(limit);
|
|
15
25
|
log(
|
|
16
|
-
`importLatestProducts -
|
|
17
|
-
","
|
|
18
|
-
)} subFamilyCodeIn: ${subFamilyCodeIn?.join(",")}`,
|
|
26
|
+
`importLatestProducts - catalog: ${catalog} lastModified: ${lastModified} offset: ${offset} limit: ${limit}`,
|
|
19
27
|
"INFO"
|
|
20
28
|
);
|
|
21
29
|
|
|
22
|
-
const
|
|
30
|
+
const data = await getLatestProducts(catalog, lastModified, offset, limit);
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
const total: number = data.totalCount;
|
|
33
|
+
const products = data.pagedCollection;
|
|
34
|
+
|
|
35
|
+
log(`${total} products founded`);
|
|
36
|
+
|
|
37
|
+
let count: number = offset + 1;
|
|
38
|
+
let current: number = 0;
|
|
26
39
|
for (const product of products) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
.toString()
|
|
36
|
-
.split("-")
|
|
37
|
-
.join("");
|
|
38
|
-
if (lastProductLastModified === lastModified) {
|
|
39
|
-
const tmplastProductLastModified: string[] = lastProductLastModified
|
|
40
|
-
.slice()
|
|
41
|
-
.split(":");
|
|
42
|
-
const seconds = Number(tmplastProductLastModified[2]);
|
|
43
|
-
tmplastProductLastModified.join(":");
|
|
44
|
-
lastProductLastModified = lastProductLastModified.replace(
|
|
45
|
-
`:${seconds}`,
|
|
46
|
-
`:${seconds + 1}`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
lastProductCode = product.content.code;
|
|
50
|
-
++count;
|
|
51
|
-
log(`${lastProductCode} lastModified: ${lastProductLastModified}`);
|
|
52
|
-
await sleep(100);
|
|
53
|
-
} else {
|
|
54
|
-
log(
|
|
55
|
-
`Skip product with code ${product.content.code} beacause is a productCodeOffset`
|
|
56
|
-
);
|
|
40
|
+
log(`${count} of ${total}`);
|
|
41
|
+
const productDetails: ProductDetails = product.content;
|
|
42
|
+
await importProduct(productDetails, catalog);
|
|
43
|
+
count++;
|
|
44
|
+
if (serverUtils) {
|
|
45
|
+
serverUtils.log(productDetails.code);
|
|
46
|
+
const progress = Math.floor((++current / products.length) * 100);
|
|
47
|
+
serverUtils.updateProgress(progress);
|
|
57
48
|
}
|
|
58
49
|
}
|
|
59
50
|
|
|
51
|
+
const timeEnd = new Date();
|
|
52
|
+
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
53
|
+
log(`Request time: ${seconds} seconds`);
|
|
54
|
+
|
|
55
|
+
const completed = limit === -1 || offset + limit >= total;
|
|
60
56
|
return {
|
|
61
|
-
|
|
62
|
-
limit
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
lastProductCode,
|
|
66
|
-
familyCodeIn,
|
|
67
|
-
subFamilyCodeIn,
|
|
68
|
-
count,
|
|
69
|
-
completed: count === 0,
|
|
57
|
+
offset: completed ? offset : offset + limit,
|
|
58
|
+
limit,
|
|
59
|
+
completed,
|
|
60
|
+
total,
|
|
70
61
|
};
|
|
71
62
|
};
|
|
@@ -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", "
|
|
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,25 @@ 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 =
|
|
1425
|
+
JSONData.length > limit && limit !== -1 ? limit : JSONData.length;
|
|
1426
|
+
const progress = Math.floor((++current / currentTotal) * 100);
|
|
1427
|
+
serverUtils.updateProgress(progress);
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1418
1430
|
if (updated % 7 === 0) {
|
|
1419
1431
|
await sleep(500);
|
|
1420
1432
|
}
|
|
1433
|
+
|
|
1421
1434
|
if (limit !== -1 && count + 1 - offset >= limit) {
|
|
1422
1435
|
break;
|
|
1423
1436
|
}
|
|
@@ -1600,6 +1613,7 @@ export const audit = async (
|
|
|
1600
1613
|
log(`Founded ${entriesPage.length} topicProduct pages`);
|
|
1601
1614
|
|
|
1602
1615
|
let count: number = offset;
|
|
1616
|
+
let current: number = 0;
|
|
1603
1617
|
for (const audit of allAudit) {
|
|
1604
1618
|
log(`${++count} of ${total}`);
|
|
1605
1619
|
log(`I process the product ${audit.product} with status ${audit.what}`);
|
|
@@ -1758,6 +1772,12 @@ export const audit = async (
|
|
|
1758
1772
|
`It has not yet been defined how to process the state ${audit.what}`
|
|
1759
1773
|
);
|
|
1760
1774
|
}
|
|
1775
|
+
|
|
1776
|
+
if (serverUtils) {
|
|
1777
|
+
serverUtils.log(audit.product);
|
|
1778
|
+
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
1779
|
+
serverUtils.updateProgress(progress);
|
|
1780
|
+
}
|
|
1761
1781
|
}
|
|
1762
1782
|
|
|
1763
1783
|
const nextOffset = offset + limit;
|
|
@@ -1821,6 +1841,10 @@ export const generateTechSpecPdf = async (topicProductId: string) => {
|
|
|
1821
1841
|
} else if (topicProduct.isArchived()) {
|
|
1822
1842
|
throw new Error(`topicProduct with id ${topicProductId} is archived`);
|
|
1823
1843
|
}
|
|
1844
|
+
if (serverUtils) {
|
|
1845
|
+
serverUtils.log(topicProductId);
|
|
1846
|
+
serverUtils.updateProgress(10);
|
|
1847
|
+
}
|
|
1824
1848
|
|
|
1825
1849
|
const topicProductPageId = getProductPageIdByCode(topicProduct.sys.id);
|
|
1826
1850
|
const topicProductPage = await getEntryByID(topicProductPageId, "page");
|
|
@@ -1832,6 +1856,10 @@ export const generateTechSpecPdf = async (topicProductId: string) => {
|
|
|
1832
1856
|
);
|
|
1833
1857
|
}
|
|
1834
1858
|
|
|
1859
|
+
if (serverUtils) {
|
|
1860
|
+
serverUtils.updateProgress(20);
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1835
1863
|
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
1836
1864
|
const topicCatalogIds = topicProduct?.fields?.catalogs?.[
|
|
1837
1865
|
defaultEnvironmentLocaleCode
|
|
@@ -1876,8 +1904,19 @@ export const generateTechSpecPdf = async (topicProductId: string) => {
|
|
|
1876
1904
|
: "info@flos.com"),
|
|
1877
1905
|
},
|
|
1878
1906
|
};
|
|
1907
|
+
|
|
1908
|
+
if (serverUtils) {
|
|
1909
|
+
serverUtils.updateProgress(35);
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1879
1912
|
const pdf = await generatePDFByUrl(layoutUrl, "", contents);
|
|
1913
|
+
if (serverUtils) {
|
|
1914
|
+
serverUtils.updateProgress(45);
|
|
1915
|
+
}
|
|
1880
1916
|
const s3Url = await savePDFToS3(pdf, fileName, "tech-spec");
|
|
1917
|
+
if (serverUtils) {
|
|
1918
|
+
serverUtils.updateProgress(75);
|
|
1919
|
+
}
|
|
1881
1920
|
|
|
1882
1921
|
log(`Update techSpec field...`);
|
|
1883
1922
|
topicProduct.fields = await addFieldValue(topicProduct, "techSpec", s3Url);
|
|
@@ -1893,6 +1932,9 @@ export const generateTechSpecPdf = async (topicProductId: string) => {
|
|
|
1893
1932
|
}
|
|
1894
1933
|
|
|
1895
1934
|
log(`${topicProductId} techSpec field updated!`);
|
|
1935
|
+
if (serverUtils) {
|
|
1936
|
+
serverUtils.updateProgress(100);
|
|
1937
|
+
}
|
|
1896
1938
|
|
|
1897
1939
|
return s3Url;
|
|
1898
1940
|
};
|
|
@@ -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);
|
package/types/browser.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export { init as initS3, upload as uploadS3, saveJsonToS3, getFileFromS3, savePD
|
|
|
4
4
|
export { importDictionaryFields, importDictionaryIcons, importDictionaryProductLine, importDictionaryProductSubLine, } from "./pim/methods/dictionary";
|
|
5
5
|
export { importCategories } from "./pim/methods/catalogs";
|
|
6
6
|
export { importLatestProducts } from "./pim/methods/latestProducts";
|
|
7
|
-
export { dailyProductsUpdate } from "./pim/methods/dailyProductsUpdate";
|
|
8
7
|
export { importModels } from "./pim/methods/models";
|
|
9
8
|
export { importSubModels } from "./pim/methods/submodels";
|
|
10
9
|
export { importSubFamilies } from "./pim/methods/subfamilies";
|
package/types/fonts.d.ts
ADDED
package/types/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export { init as initS3, upload as uploadS3, saveJsonToS3, getFileFromS3, savePD
|
|
|
4
4
|
export { importDictionaryFields, importDictionaryIcons, importDictionaryProductLine, importDictionaryProductSubLine, } from "./pim/methods/dictionary";
|
|
5
5
|
export { importCategories } from "./pim/methods/catalogs";
|
|
6
6
|
export { importLatestProducts } from "./pim/methods/latestProducts";
|
|
7
|
-
export { dailyProductsUpdate } from "./pim/methods/dailyProductsUpdate";
|
|
8
7
|
export { importModels } from "./pim/methods/models";
|
|
9
8
|
export { importSubModels } from "./pim/methods/submodels";
|
|
10
9
|
export { importSubFamilies } from "./pim/methods/subfamilies";
|
|
@@ -25,7 +24,7 @@ export { reindexPressRelease, reindexPressReleases, removePressReleaseObject, }
|
|
|
25
24
|
export { reindexPost, reindexPosts, removePostObject } from "./algolia/news";
|
|
26
25
|
export { importDownloads } from "./downloads/import";
|
|
27
26
|
export { getLocalISOTime } from "./utils";
|
|
28
|
-
export { getStaticDailyProducts } from "./pim/endpoints";
|
|
29
|
-
export { log, setLogId, setLogPath, setLogFilename, getLogFolder, } from "./libs/logs";
|
|
27
|
+
export { getStaticDailyProducts, getLatestProducts } from "./pim/endpoints";
|
|
28
|
+
export { log, setServerUtils, setLogId, setLogPath, setLogFilename, getLogFolder, } from "./libs/logs";
|
|
30
29
|
export { removeRecordsByStatus } from "./algolia/clean";
|
|
31
30
|
export { generatePDFByUrl } from "./libs/puppeteer";
|
package/types/libs/logs.d.ts
CHANGED
|
@@ -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;
|
package/types/pim/endpoints.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare const getPimDomain: () => string;
|
|
|
10
10
|
export declare const getCatalogTaxonomiesHierarchy: (catalogCode: AvailableCatalogs, jsonFile?: null | undefined) => Promise<CatalogDetails>;
|
|
11
11
|
export declare const getDictionary: () => Promise<any>;
|
|
12
12
|
export declare const getAllProducts: (lastModified?: string | null, catalogCode?: AvailableCatalogs | null) => Promise<any>;
|
|
13
|
-
export declare const getLatestProducts: (catalogCode: AvailableCatalogs, lastModified: string, limit
|
|
13
|
+
export declare const getLatestProducts: (catalogCode: AvailableCatalogs, lastModified: string, offset?: number, limit?: number) => Promise<any>;
|
|
14
14
|
export declare const getProductDetails: (code: string) => Promise<any>;
|
|
15
15
|
export declare const getAudit: (lastModified?: string) => Promise<Audit[]>;
|
|
16
16
|
export declare const getStaticDailyProducts: (catalogCode: AvailableCatalogs, day: string, saveToS3?: boolean) => Promise<any>;
|
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
import { AvailableCatalogs } from "../../types";
|
|
2
|
-
export declare const importLatestProducts: (catalog: AvailableCatalogs, lastModified: string,
|
|
3
|
-
catalog: AvailableCatalogs;
|
|
4
|
-
limit: number;
|
|
5
|
-
lastModified: string;
|
|
6
|
-
lastProductLastModified: string;
|
|
7
|
-
lastProductCode: string | undefined;
|
|
8
|
-
familyCodeIn: string[] | undefined;
|
|
9
|
-
subFamilyCodeIn: string[] | undefined;
|
|
10
|
-
count: number;
|
|
11
|
-
completed: boolean;
|
|
12
|
-
}>;
|
|
1
|
+
import { AvailableCatalogs, PaginationResults } from "../../types";
|
|
2
|
+
export declare const importLatestProducts: (catalog: AvailableCatalogs, lastModified: string, offset?: number, limit?: number) => Promise<PaginationResults>;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.dailyProductsUpdate = void 0;
|
|
4
|
-
const endpoints_1 = require("../endpoints");
|
|
5
|
-
const logs_1 = require("../../libs/logs");
|
|
6
|
-
const s3_1 = require("../../libs/s3");
|
|
7
|
-
const products_1 = require("./products");
|
|
8
|
-
const utils_1 = require("../../utils");
|
|
9
|
-
const dailyProductsUpdate = async (catalog, day, offset = 0, limit = 50, s3FilePath = "") => {
|
|
10
|
-
const timeStart = new Date();
|
|
11
|
-
offset = Number(offset);
|
|
12
|
-
limit = Number(limit);
|
|
13
|
-
logs_1.log(`dailyProductsUpdate - catalog: ${catalog} day: ${day} offset: ${offset} limit: ${limit} s3FilePath: ${s3FilePath}`, "INFO");
|
|
14
|
-
if (!s3FilePath) {
|
|
15
|
-
const s3Path = await endpoints_1.getStaticDailyProducts(catalog, day, true);
|
|
16
|
-
return {
|
|
17
|
-
offset,
|
|
18
|
-
limit,
|
|
19
|
-
completed: !s3Path,
|
|
20
|
-
s3FilePath: s3Path,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
const JSONData = await s3_1.getFileFromS3(s3FilePath);
|
|
24
|
-
const total = JSONData.length;
|
|
25
|
-
logs_1.log(`${total} products founded`);
|
|
26
|
-
let count = 0;
|
|
27
|
-
let updated = 0;
|
|
28
|
-
for (const product of JSONData) {
|
|
29
|
-
const productDetails = product.content;
|
|
30
|
-
if (offset <= count || limit === -1) {
|
|
31
|
-
await products_1.importProduct(productDetails, catalog);
|
|
32
|
-
updated++;
|
|
33
|
-
if (limit !== -1 && count + 1 - offset >= limit) {
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
count++;
|
|
38
|
-
}
|
|
39
|
-
const timeEnd = new Date();
|
|
40
|
-
const seconds = utils_1.secondBetweenTwoDate(timeStart, timeEnd);
|
|
41
|
-
logs_1.log(`Request time: ${seconds} seconds`);
|
|
42
|
-
return {
|
|
43
|
-
offset: offset + limit,
|
|
44
|
-
limit,
|
|
45
|
-
completed: limit === -1 || limit > updated,
|
|
46
|
-
s3FilePath,
|
|
47
|
-
total: JSONData.length,
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
exports.dailyProductsUpdate = dailyProductsUpdate;
|
|
51
|
-
//# sourceMappingURL=dailyProductsUpdate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dailyProductsUpdate.js","sourceRoot":"","sources":["../../../src/pim/methods/dailyProductsUpdate.ts"],"names":[],"mappings":";;;AACA,4CAAsD;AACtD,0CAAsC;AACtC,sCAA8C;AAE9C,yCAA2C;AAC3C,uCAAmD;AAW5C,MAAM,mBAAmB,GAAG,KAAK,EACtC,OAA0B,EAC1B,GAAW,EACX,SAAiB,CAAC,EAClB,QAAgB,EAAE,EAClB,aAAqB,EAAE,EACK,EAAE;IAC9B,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC7B,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IACxB,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,UAAG,CACD,kCAAkC,OAAO,SAAS,GAAG,YAAY,MAAM,WAAW,KAAK,gBAAgB,UAAU,EAAE,EACnH,MAAM,CACP,CAAC;IAEF,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,MAAM,GAAG,MAAM,kCAAsB,CAAC,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QAChE,OAAO;YACL,MAAM;YACN,KAAK;YACL,SAAS,EAAE,CAAC,MAAM;YAClB,UAAU,EAAE,MAAM;SACnB,CAAC;KACH;IAED,MAAM,QAAQ,GAAG,MAAM,kBAAa,CAAC,UAAU,CAAC,CAAC;IACjD,MAAM,KAAK,GAAW,QAAQ,CAAC,MAAM,CAAC;IAEtC,UAAG,CAAC,GAAG,KAAK,mBAAmB,CAAC,CAAC;IAEjC,IAAI,KAAK,GAAW,CAAC,CAAC;IACtB,IAAI,OAAO,GAAW,CAAC,CAAC;IACxB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,MAAM,cAAc,GAAmB,OAAO,CAAC,OAAO,CAAC;QACvD,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACnC,MAAM,wBAAa,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YAC7C,OAAO,EAAE,CAAC;YACV,IAAI,KAAK,KAAK,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,GAAG,MAAM,IAAI,KAAK,EAAE;gBAC/C,MAAM;aACP;SACF;QACD,KAAK,EAAE,CAAC;KACT;IAED,MAAM,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,4BAAoB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACzD,UAAG,CAAC,iBAAiB,OAAO,UAAU,CAAC,CAAC;IAExC,OAAO;QACL,MAAM,EAAE,MAAM,GAAG,KAAK;QACtB,KAAK;QACL,SAAS,EAAE,KAAK,KAAK,CAAC,CAAC,IAAI,KAAK,GAAG,OAAO;QAC1C,UAAU;QACV,KAAK,EAAE,QAAQ,CAAC,MAAM;KACvB,CAAC;AACJ,CAAC,CAAC;AAvDW,QAAA,mBAAmB,uBAuD9B"}
|