pim-import 2.82.2 → 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.
- 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 +5 -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 +15 -0
- package/dist/pim/methods/dictionary.js.map +1 -1
- package/dist/pim/methods/families.js +7 -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 +17 -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 +9 -3
- 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 +19 -1
- package/src/pim/methods/families.ts +9 -1
- package/src/pim/methods/latestProducts.ts +44 -53
- package/src/pim/methods/models.ts +10 -1
- package/src/pim/methods/products.ts +21 -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
|
|
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,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,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);
|
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 } 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"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { AvailableCatalogs, PaginationResults } from "../../types";
|
|
2
|
-
import { getStaticDailyProducts } from "../endpoints";
|
|
3
|
-
import { log } from "../../libs/logs";
|
|
4
|
-
import { getFileFromS3 } from "../../libs/s3";
|
|
5
|
-
import { ProductDetails } from "../../resources/ProductDetails";
|
|
6
|
-
import { importProduct } from "./products";
|
|
7
|
-
import { secondBetweenTwoDate } from "../../utils";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Daily products update
|
|
11
|
-
*
|
|
12
|
-
* @param {string} catalogCode The catalog code. Format: ARCHITECTURAL
|
|
13
|
-
* @param {string} day The last modified data. Format: 20200426 - yearmonthday
|
|
14
|
-
* @param {number} offset Default 0
|
|
15
|
-
* @param {number} limit Default 50
|
|
16
|
-
* @param {string} s3FilePath Default 50
|
|
17
|
-
*/
|
|
18
|
-
export const dailyProductsUpdate = async (
|
|
19
|
-
catalog: AvailableCatalogs,
|
|
20
|
-
day: string,
|
|
21
|
-
offset: number = 0,
|
|
22
|
-
limit: number = 50,
|
|
23
|
-
s3FilePath: string = ""
|
|
24
|
-
): Promise<PaginationResults> => {
|
|
25
|
-
const timeStart = new Date();
|
|
26
|
-
offset = Number(offset);
|
|
27
|
-
limit = Number(limit);
|
|
28
|
-
log(
|
|
29
|
-
`dailyProductsUpdate - catalog: ${catalog} day: ${day} offset: ${offset} limit: ${limit} s3FilePath: ${s3FilePath}`,
|
|
30
|
-
"INFO"
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
if (!s3FilePath) {
|
|
34
|
-
const s3Path = await getStaticDailyProducts(catalog, day, true);
|
|
35
|
-
return {
|
|
36
|
-
offset,
|
|
37
|
-
limit,
|
|
38
|
-
completed: !s3Path,
|
|
39
|
-
s3FilePath: s3Path,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const JSONData = await getFileFromS3(s3FilePath);
|
|
44
|
-
const total: number = JSONData.length;
|
|
45
|
-
|
|
46
|
-
log(`${total} products founded`);
|
|
47
|
-
|
|
48
|
-
let count: number = 0;
|
|
49
|
-
let updated: number = 0;
|
|
50
|
-
for (const product of JSONData) {
|
|
51
|
-
const productDetails: ProductDetails = product.content;
|
|
52
|
-
if (offset <= count || limit === -1) {
|
|
53
|
-
await importProduct(productDetails, catalog);
|
|
54
|
-
updated++;
|
|
55
|
-
if (limit !== -1 && count + 1 - offset >= limit) {
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
count++;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const timeEnd = new Date();
|
|
63
|
-
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
64
|
-
log(`Request time: ${seconds} seconds`);
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
offset: offset + limit,
|
|
68
|
-
limit,
|
|
69
|
-
completed: limit === -1 || limit > updated,
|
|
70
|
-
s3FilePath,
|
|
71
|
-
total: JSONData.length,
|
|
72
|
-
};
|
|
73
|
-
};
|