pim-import 3.0.0 → 3.1.2
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/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/libs/logs.js +6 -1
- package/dist/libs/logs.js.map +1 -1
- package/dist/libs/puppeteer.js +45 -37
- package/dist/libs/puppeteer.js.map +1 -1
- package/dist/pim/data/productFields.json +3 -3
- 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 +12 -0
- package/dist/pim/methods/families.js.map +1 -1
- package/dist/pim/methods/latestProducts.js +6 -0
- 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 +59 -14
- package/dist/pim/methods/products.js.map +1 -1
- package/dist/pim/methods/subfamilies.js +9 -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/index.ts +1 -0
- package/src/libs/logs.ts +6 -0
- package/src/libs/puppeteer.ts +75 -59
- package/src/pim/data/productFields.json +3 -3
- package/src/pim/methods/catalogs.ts +12 -1
- package/src/pim/methods/dictionary.ts +33 -1
- package/src/pim/methods/families.ts +16 -1
- package/src/pim/methods/latestProducts.ts +7 -1
- package/src/pim/methods/models.ts +10 -1
- package/src/pim/methods/products.ts +73 -16
- package/src/pim/methods/subfamilies.ts +14 -1
- package/src/pim/methods/submodels.ts +10 -1
- package/types/fonts.d.ts +2 -0
- package/types/index.d.ts +1 -1
- package/types/libs/logs.d.ts +2 -0
- package/types/libs/puppeteer.d.ts +1 -1
package/src/libs/puppeteer.ts
CHANGED
|
@@ -44,71 +44,87 @@ export const generatePDFByUrl = async (
|
|
|
44
44
|
const browser = await puppeteer.connect({
|
|
45
45
|
browserWSEndpoint: `wss://chrome.browserless.io?token=${process.env.BROWSERLESS_TOKEN}`,
|
|
46
46
|
});
|
|
47
|
-
log(
|
|
48
|
-
`After puppeteer.connect - ${secondBetweenTwoDate(
|
|
49
|
-
timeStart,
|
|
50
|
-
new Date()
|
|
51
|
-
)} seconds`,
|
|
52
|
-
"DEBUG"
|
|
53
|
-
);
|
|
54
|
-
const page = await browser.newPage();
|
|
55
47
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
try {
|
|
49
|
+
log(
|
|
50
|
+
`After puppeteer.connect - ${secondBetweenTwoDate(
|
|
51
|
+
timeStart,
|
|
52
|
+
new Date()
|
|
53
|
+
)} seconds`,
|
|
54
|
+
"DEBUG"
|
|
55
|
+
);
|
|
56
|
+
const page = await browser.newPage();
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
log(
|
|
59
|
+
`Before page.goto - ${secondBetweenTwoDate(
|
|
60
|
+
timeStart,
|
|
61
|
+
new Date()
|
|
62
|
+
)} seconds`,
|
|
63
|
+
"DEBUG"
|
|
64
|
+
);
|
|
65
|
+
const res = await page.goto(url, { waitUntil: "networkidle0", timeout: 0 });
|
|
66
|
+
log(
|
|
67
|
+
`After page.goto - ${secondBetweenTwoDate(
|
|
68
|
+
timeStart,
|
|
69
|
+
new Date()
|
|
70
|
+
)} seconds`,
|
|
71
|
+
"DEBUG"
|
|
72
|
+
);
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const headerRight = contents?.header?.right ?? "";
|
|
74
|
-
const headerTemplate = `<div class="pdf-header" style="margin: 10px 32px 0; padding:0; border-bottom: 0.3pt solid #000000; width:100%"><div class="page-logo" style="display: inline-block; vertical-align: bottom; width: 14%; margin-left: 2%;">${headerLeft}</div><div class="page-title" style="display: inline-block; vertical-align: bottom; margin-bottom: 3px; width: 81%; text-align: right;font-size: 7pt; letter-spacing: 0.2px; font-weight: 300;">${headerRight}</div></div>`;
|
|
74
|
+
if (res.status() !== 200) {
|
|
75
|
+
throw new Error(`Error ${res.status()} - ${res.url()}`);
|
|
76
|
+
}
|
|
75
77
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
const headerLeft =
|
|
79
|
+
contents?.header?.left ??
|
|
80
|
+
'<a href="https://flos.com"><?xml version="1.0" encoding="UTF-8"?><svg style="width: 100%;" width="116px" height="44px" viewBox="0 0 116 44" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Flos_logo</title> <defs> <polygon id="path-1" points="0.06 0.039 115.026 0.039 115.026 43.986 0.06 43.986"></polygon> </defs> <g id="Product-finder" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="03_Components/Footer/1680" transform="translate(-1377.000000, -598.000000)"> <g id="Flos_logo" transform="translate(1377.000000, 598.000000)"> <g id="Group-5"> <mask id="mask-2" fill="white"> <use xlink:href="#path-1"></use> </mask> <g id="Clip-2"></g> <path d="M103.938,43.986 C103.389,43.986 102.841,43.954 102.303,43.89 C101.425,43.762 100.579,43.569 99.749,43.314 C98.201,42.819 96.748,42.118 95.359,41.256 C95.072,41.063 94.817,40.793 94.77,40.441 L94.753,39.483 L94.625,35.796 L94.513,32.795 C94.545,32.636 94.609,32.46 94.77,32.395 C94.858,32.377 94.952,32.355 95.04,32.355 C95.11,32.355 95.176,32.369 95.232,32.412 C95.487,32.523 95.535,32.795 95.615,33.003 C96.126,34.631 96.557,36.274 97.323,37.792 C98.169,39.468 99.701,41.111 101.441,41.83 C102.511,42.356 103.708,42.612 104.969,42.66 C106.246,42.612 107.491,42.356 108.545,41.734 C109.87,40.968 111.194,39.707 111.674,38.255 C111.945,37.456 112.2,36.626 112.152,35.701 C112.041,34.406 111.833,33.163 111.194,32.108 C110.828,31.47 110.396,30.895 109.902,30.337 C109.902,30.337 106.519,26.745 106.39,26.601 L100.563,20.328 C99.206,18.891 97.898,17.359 96.716,15.81 C96.253,15.108 95.806,14.406 95.503,13.64 C95.152,12.809 94.896,11.964 94.785,11.054 C94.641,10.224 94.641,9.33 94.673,8.468 C94.833,7.015 95.264,5.642 96.03,4.429 C96.461,3.646 97.195,2.961 97.865,2.322 C98.249,2.002 98.68,1.763 99.095,1.492 C100.053,0.965 101.074,0.566 102.176,0.359 C103.002,0.162 103.884,0.061 104.767,0.061 C105.537,0.061 106.308,0.138 107.044,0.295 C108.225,0.534 109.327,0.949 110.381,1.476 C111.051,1.827 111.737,2.21 112.296,2.753 C112.521,2.945 112.567,3.2 112.615,3.455 L112.759,4.828 C112.855,6.312 113.063,7.717 113.143,9.202 C113.126,9.425 112.983,9.665 112.759,9.745 C112.615,9.745 112.488,9.713 112.408,9.601 C112.168,9.266 112.136,8.835 111.993,8.452 C111.643,7.255 111.258,6.104 110.524,5.083 L110.492,5.036 C110.141,4.589 109.774,4.094 109.327,3.679 C108.481,2.817 107.491,2.258 106.47,1.827 C105.714,1.55 104.832,1.414 103.948,1.414 C103,1.414 102.05,1.569 101.25,1.874 C100.1,2.306 98.951,3.216 98.36,4.365 C97.771,5.354 97.626,6.648 97.738,7.861 L97.757,8.027 C97.869,9.112 98.36,10.048 98.887,10.974 C99.334,11.692 99.877,12.363 100.437,13.033 L102.782,15.538 L105.959,18.874 L108.609,21.669 C111.003,24.175 113.525,26.681 114.515,29.842 C114.866,31.07 115.09,32.428 115.01,33.768 L114.994,33.801 C115.042,34.089 114.962,34.406 114.93,34.694 C114.675,36.194 114.371,37.68 113.525,38.957 C113.015,39.818 112.393,40.585 111.626,41.303 C111.131,41.798 110.572,42.196 109.982,42.517 C108.736,43.171 107.364,43.586 105.943,43.842 C105.284,43.938 104.61,43.986 103.938,43.986" id="Fill-1" fill="#000000" mask="url(#mask-2)"></path> <path d="M22.857,43.785 C22.667,43.785 22.479,43.772 22.296,43.729 C22.153,43.698 22.041,43.554 21.977,43.41 C21.93,43.251 21.914,43.075 22.025,42.948 C22.185,42.724 22.457,42.692 22.695,42.612 C23.638,42.484 24.58,42.373 25.346,41.813 C25.904,41.303 26.191,40.617 26.255,39.867 L26.224,18.668 L26.319,3.87 C26.239,3.152 26.128,2.418 25.441,1.987 C24.611,1.316 23.431,1.444 22.457,1.125 C22.313,1.013 22.266,0.853 22.266,0.694 C22.266,0.55 22.296,0.39 22.424,0.311 C22.601,0.215 22.808,0.167 23.016,0.151 L34.477,0.199 C34.535,0.199 34.56,0.199 34.687,0.192 C34.719,0.194 34.752,0.194 34.786,0.194 C34.846,0.194 34.907,0.192 34.968,0.19 C35.03,0.188 35.092,0.186 35.154,0.186 C35.429,0.186 35.692,0.228 35.833,0.502 C35.881,0.646 35.93,0.837 35.85,0.981 C35.706,1.22 35.451,1.22 35.21,1.252 C34.062,1.252 32.913,1.348 31.938,1.843 C31.603,1.987 31.285,2.29 31.044,2.609 C30.9,2.928 30.773,3.248 30.789,3.631 L30.726,8.627 L30.598,19.657 C30.565,21.462 30.598,23.329 30.582,25.133 L30.582,34.95 L30.613,40.713 C30.623,41.362 30.492,42.011 30.997,42.228 C31.279,42.309 31.587,42.33 31.897,42.33 C32.147,42.33 32.399,42.316 32.641,42.308 C34.173,42.213 35.659,42.038 37.079,41.671 C38.291,41.367 39.474,40.968 40.526,40.234 C42.027,39.02 42.426,37.281 43.097,35.7 L43.911,33.322 C43.991,33.178 44.119,33.067 44.277,33.067 C44.47,33.083 44.662,33.178 44.756,33.353 L44.82,33.593 L44.692,34.79 L43.64,43.314 C43.543,43.601 43.241,43.618 42.984,43.634 L39.889,43.618 L35.387,43.65 L29.161,43.729 L23.782,43.762 C23.742,43.76 23.703,43.76 23.664,43.76 C23.53,43.76 23.395,43.766 23.26,43.772 C23.125,43.779 22.99,43.785 22.857,43.785" id="Fill-3" fill="#000000" mask="url(#mask-2)"></path> <path d="M13.23,43.475 L6.654,43.458 L1.098,43.475 C0.715,43.458 0.252,43.522 0.045,43.155 C-0.019,42.995 -0.019,42.804 0.077,42.66 C0.108,42.533 0.236,42.5 0.348,42.468 C1.354,42.309 2.375,42.149 3.221,41.59 C3.764,41.112 3.972,40.441 4.115,39.787 C4.259,38.574 4.291,37.329 4.339,36.083 L4.371,34.423 L4.498,23.84 L4.515,21.605 L4.546,17.886 L4.53,13.767 L4.498,12.554 L4.45,7.27 L4.387,3.71 C4.291,3.008 4.163,2.258 3.509,1.811 C2.726,1.284 1.785,1.172 0.859,0.997 C0.715,0.933 0.588,0.789 0.556,0.645 C0.524,0.518 0.571,0.374 0.619,0.262 C0.731,0.071 0.939,0.071 1.13,0.039 C1.602,0.051 2.071,0.055 2.54,0.055 C3.008,0.055 3.475,0.051 3.944,0.047 C4.411,0.043 4.88,0.039 5.35,0.039 C5.824,0.039 6.3,0.043 6.781,0.055 L10.293,0.071 L17.827,0.055 L19.775,0.039 C19.966,0.071 20.11,0.198 20.19,0.358 L20.238,0.55 L20.43,4.397 L20.749,8.898 C20.749,9.122 20.749,9.329 20.573,9.473 C20.491,9.537 20.378,9.564 20.267,9.564 C20.182,9.564 20.099,9.549 20.03,9.521 C19.823,9.441 19.759,9.202 19.695,9.026 C19.248,7.605 18.801,6.201 18.195,4.86 C17.795,4.03 17.253,3.088 16.375,2.609 C14.38,1.508 11.857,1.571 9.479,1.508 C9.351,1.539 9.159,1.508 9.096,1.651 L9.064,1.97 L8.968,7.478 L8.952,9.441 L8.824,19.29 L8.84,20.232 C8.856,20.328 8.984,20.36 9.064,20.376 C9.314,20.381 9.566,20.384 9.818,20.384 C11.171,20.384 12.532,20.295 13.757,19.945 C14.874,19.53 15.449,18.396 15.8,17.375 C16.088,16.465 16.327,15.523 16.614,14.629 C16.699,14.489 16.846,14.385 17.011,14.385 C17.032,14.385 17.055,14.386 17.077,14.39 C17.237,14.437 17.412,14.517 17.492,14.677 L17.556,14.916 L17.428,20.104 L17.412,22.18 L17.54,27.432 C17.524,27.639 17.38,27.831 17.189,27.894 C17.147,27.907 17.103,27.913 17.059,27.913 C16.934,27.913 16.809,27.865 16.726,27.782 C16.598,27.671 16.55,27.543 16.503,27.399 C16.135,26.362 15.992,25.244 15.561,24.239 C15.257,23.489 14.874,22.61 14.044,22.259 C13.358,21.908 12.512,21.908 11.698,21.828 C11.027,21.794 10.365,21.734 9.699,21.734 C9.446,21.734 9.191,21.743 8.936,21.765 L8.824,21.94 L8.713,28.629 L8.713,28.932 L8.76,34.471 L8.84,39.084 C8.888,39.531 8.856,40.01 9.048,40.409 C9.191,41.064 9.782,41.67 10.437,41.878 C11.363,42.277 12.432,42.293 13.438,42.5 C13.581,42.533 13.693,42.66 13.741,42.788 C13.773,42.931 13.821,43.139 13.709,43.251 C13.597,43.442 13.406,43.442 13.23,43.475" id="Fill-4" fill="#000000" mask="url(#mask-2)"></path> </g> <path d="M69.161,44 C61.377,44 53.858,40.286 50,33.602 C43.185,21.799 48.795,9.012 59,3.12 C62.599,1.042 66.558,0.052 70.458,0.03 L70.73,0.03 C78.47,0.075 85.934,3.927 89.814,10.649 C95.6,20.668 92.782,34.367 80.823,41.006 C77.167,43.035 73.13,44 69.161,44 M68.056,1.896 C65.21,1.896 62.354,2.659 59.644,4.261 C51.285,9.203 48.923,21.517 54.271,31.095 C57.575,37.014 64.48,42.234 71.875,42.234 C74.626,42.234 77.444,41.512 80.171,39.835 C90.623,33.405 89.577,19.536 85.518,13.057 C81.044,5.915 74.581,1.896 68.056,1.896" id="Fill-6" fill="#000000"></path> </g> </g> </g> </svg></a>';
|
|
81
|
+
const headerRight = contents?.header?.right ?? "";
|
|
82
|
+
const headerTemplate = `<div class="pdf-header" style="margin: 10px 32px 0; padding:0; border-bottom: 0.3pt solid #000000; width:100%"><div class="page-logo" style="display: inline-block; vertical-align: bottom; width: 14%; margin-left: 2%;">${headerLeft}</div><div class="page-title" style="display: inline-block; vertical-align: bottom; margin-bottom: 3px; width: 81%; text-align: right;font-size: 7pt; letter-spacing: 0.2px; font-weight: 300;">${headerRight}</div></div>`;
|
|
79
83
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
displayHeaderFooter: !!(contents?.header || contents?.footer),
|
|
85
|
-
headerTemplate,
|
|
86
|
-
footerTemplate,
|
|
87
|
-
margin: {
|
|
88
|
-
top: "110px",
|
|
89
|
-
left: "44px",
|
|
90
|
-
right: "44px",
|
|
91
|
-
bottom: "60px",
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
if (path) {
|
|
95
|
-
options.path = path;
|
|
96
|
-
}
|
|
97
|
-
log(
|
|
98
|
-
`Before page.pdf - ${secondBetweenTwoDate(timeStart, new Date())} seconds`,
|
|
99
|
-
"DEBUG"
|
|
100
|
-
);
|
|
101
|
-
const pdf = await page.pdf(options);
|
|
102
|
-
log(
|
|
103
|
-
`After page.pdf - ${secondBetweenTwoDate(timeStart, new Date())} seconds`,
|
|
104
|
-
"DEBUG"
|
|
105
|
-
);
|
|
84
|
+
const footerLeft = contents?.footer?.left ?? "";
|
|
85
|
+
const footerRight =
|
|
86
|
+
contents?.footer?.right ?? "www.flos.com - info@flos.com";
|
|
87
|
+
const footerTemplate = `<div class="pdf-footer" style="margin: 0 32px; padding: 10px 0; width: 100%; border-top: 0.3pt solid #000000; font-size: 4pt; font-weight:300;"> <div class="pdf-row" style="margin:0; padding: 0"> <span class="left" style="margin:0; padding: 0; width: 70%; white-space: normal; overflow: hidden; text-overflow: hidden; float: left;">${footerLeft}</span> <span class="right" style="margin:0; padding: 0; width: 30%; float: right; text-align: right;">${footerRight}</span> </div> </div>`;
|
|
106
88
|
|
|
107
|
-
|
|
89
|
+
// See: https://github.com/puppeteer/puppeteer/blob/v11.0.0/docs/api.md#pagepdfoptions
|
|
90
|
+
const options: PDFOptions = {
|
|
91
|
+
format: "a4",
|
|
92
|
+
printBackground: true,
|
|
93
|
+
displayHeaderFooter: !!(contents?.header || contents?.footer),
|
|
94
|
+
headerTemplate,
|
|
95
|
+
footerTemplate,
|
|
96
|
+
margin: {
|
|
97
|
+
top: "110px",
|
|
98
|
+
left: "44px",
|
|
99
|
+
right: "44px",
|
|
100
|
+
bottom: "60px",
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
if (path) {
|
|
104
|
+
options.path = path;
|
|
105
|
+
}
|
|
106
|
+
log(
|
|
107
|
+
`Before page.pdf - ${secondBetweenTwoDate(
|
|
108
|
+
timeStart,
|
|
109
|
+
new Date()
|
|
110
|
+
)} seconds`,
|
|
111
|
+
"DEBUG"
|
|
112
|
+
);
|
|
113
|
+
const pdf = await page.pdf(options);
|
|
114
|
+
log(
|
|
115
|
+
`After page.pdf - ${secondBetweenTwoDate(timeStart, new Date())} seconds`,
|
|
116
|
+
"DEBUG"
|
|
117
|
+
);
|
|
108
118
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
const timeEnd = new Date();
|
|
120
|
+
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
121
|
+
log(`Request time: ${seconds} seconds - generatePDFByUrl`);
|
|
112
122
|
|
|
113
|
-
|
|
123
|
+
return pdf;
|
|
124
|
+
} catch (err) {
|
|
125
|
+
console.log(err);
|
|
126
|
+
return "";
|
|
127
|
+
} finally {
|
|
128
|
+
await browser.close();
|
|
129
|
+
}
|
|
114
130
|
};
|
|
@@ -785,21 +785,21 @@
|
|
|
785
785
|
},
|
|
786
786
|
{
|
|
787
787
|
"key": "theoreticalGrossFlow",
|
|
788
|
-
"parent": "
|
|
788
|
+
"parent": "photometric",
|
|
789
789
|
"icon": false,
|
|
790
790
|
"dictionary": "",
|
|
791
791
|
"type": "string"
|
|
792
792
|
},
|
|
793
793
|
{
|
|
794
794
|
"key": "rfFidelityIndex",
|
|
795
|
-
"parent": "
|
|
795
|
+
"parent": "photometric",
|
|
796
796
|
"icon": false,
|
|
797
797
|
"dictionary": "",
|
|
798
798
|
"type": "number"
|
|
799
799
|
},
|
|
800
800
|
{
|
|
801
801
|
"key": "rgGamutIndex",
|
|
802
|
-
"parent": "
|
|
802
|
+
"parent": "photometric",
|
|
803
803
|
"icon": false,
|
|
804
804
|
"dictionary": "",
|
|
805
805
|
"type": "number"
|
|
@@ -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)) {
|
|
@@ -270,6 +271,13 @@ export const importFamilies = async (
|
|
|
270
271
|
|
|
271
272
|
await createOrUpdatePage(topicFamily);
|
|
272
273
|
|
|
274
|
+
if (serverUtils) {
|
|
275
|
+
const currentTotal =
|
|
276
|
+
families.length > limit && limit !== -1 ? limit : families.length;
|
|
277
|
+
const progress = Math.floor((++current / currentTotal) * 100);
|
|
278
|
+
serverUtils.updateProgress(progress);
|
|
279
|
+
}
|
|
280
|
+
|
|
273
281
|
if (limit !== -1 && count + 1 - offset >= limit) {
|
|
274
282
|
break;
|
|
275
283
|
}
|
|
@@ -277,6 +285,9 @@ export const importFamilies = async (
|
|
|
277
285
|
if (count % 2 === 0 && count < families.length) {
|
|
278
286
|
await sleep(1000);
|
|
279
287
|
}
|
|
288
|
+
if (serverUtils) {
|
|
289
|
+
serverUtils.log(family.data.code);
|
|
290
|
+
}
|
|
280
291
|
}
|
|
281
292
|
}
|
|
282
293
|
count++;
|
|
@@ -284,6 +295,10 @@ export const importFamilies = async (
|
|
|
284
295
|
|
|
285
296
|
const nextOffset = Number(offset) + Number(limit);
|
|
286
297
|
|
|
298
|
+
if (serverUtils) {
|
|
299
|
+
serverUtils.updateProgress(100);
|
|
300
|
+
}
|
|
301
|
+
|
|
287
302
|
return {
|
|
288
303
|
offset: nextOffset,
|
|
289
304
|
limit: Number(limit),
|
|
@@ -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", "
|
|
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);
|
|
@@ -1222,7 +1224,10 @@ export const importProduct = async (
|
|
|
1222
1224
|
return false;
|
|
1223
1225
|
}
|
|
1224
1226
|
|
|
1225
|
-
if (
|
|
1227
|
+
if (
|
|
1228
|
+
productDetails.visibleToWeb === true ||
|
|
1229
|
+
productDetails.code === "0000000-TEST"
|
|
1230
|
+
) {
|
|
1226
1231
|
await addProduct(productDetails);
|
|
1227
1232
|
return true;
|
|
1228
1233
|
} else {
|
|
@@ -1410,14 +1415,25 @@ export const setProductsRelationships = async (
|
|
|
1410
1415
|
|
|
1411
1416
|
let count: number = 0;
|
|
1412
1417
|
let updated: number = 0;
|
|
1418
|
+
let current: number = 0;
|
|
1413
1419
|
for (const product of JSONData) {
|
|
1414
1420
|
if (offset <= count || limit === -1) {
|
|
1415
1421
|
log(`${count + 1} of ${JSONData.length}`);
|
|
1416
1422
|
await setProductRelationships(product.code, fieldKey);
|
|
1417
1423
|
updated++;
|
|
1424
|
+
|
|
1425
|
+
if (serverUtils) {
|
|
1426
|
+
serverUtils.log(product.code);
|
|
1427
|
+
const currentTotal =
|
|
1428
|
+
JSONData.length > limit && limit !== -1 ? limit : JSONData.length;
|
|
1429
|
+
const progress = Math.floor((++current / currentTotal) * 100);
|
|
1430
|
+
serverUtils.updateProgress(progress);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1418
1433
|
if (updated % 7 === 0) {
|
|
1419
1434
|
await sleep(500);
|
|
1420
1435
|
}
|
|
1436
|
+
|
|
1421
1437
|
if (limit !== -1 && count + 1 - offset >= limit) {
|
|
1422
1438
|
break;
|
|
1423
1439
|
}
|
|
@@ -1429,6 +1445,10 @@ export const setProductsRelationships = async (
|
|
|
1429
1445
|
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
1430
1446
|
log(`Request time: ${seconds} seconds`);
|
|
1431
1447
|
|
|
1448
|
+
if (serverUtils) {
|
|
1449
|
+
serverUtils.updateProgress(100);
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1432
1452
|
return {
|
|
1433
1453
|
offset: Number(offset) + Number(limit),
|
|
1434
1454
|
limit: Number(limit),
|
|
@@ -1600,6 +1620,7 @@ export const audit = async (
|
|
|
1600
1620
|
log(`Founded ${entriesPage.length} topicProduct pages`);
|
|
1601
1621
|
|
|
1602
1622
|
let count: number = offset;
|
|
1623
|
+
let current: number = 0;
|
|
1603
1624
|
for (const audit of allAudit) {
|
|
1604
1625
|
log(`${++count} of ${total}`);
|
|
1605
1626
|
log(`I process the product ${audit.product} with status ${audit.what}`);
|
|
@@ -1758,6 +1779,12 @@ export const audit = async (
|
|
|
1758
1779
|
`It has not yet been defined how to process the state ${audit.what}`
|
|
1759
1780
|
);
|
|
1760
1781
|
}
|
|
1782
|
+
|
|
1783
|
+
if (serverUtils) {
|
|
1784
|
+
serverUtils.log(audit.product);
|
|
1785
|
+
const progress = Math.floor((++current / allAudit.length) * 100);
|
|
1786
|
+
serverUtils.updateProgress(progress);
|
|
1787
|
+
}
|
|
1761
1788
|
}
|
|
1762
1789
|
|
|
1763
1790
|
const nextOffset = offset + limit;
|
|
@@ -1821,6 +1848,10 @@ export const generateTechSpecPdf = async (topicProductId: string) => {
|
|
|
1821
1848
|
} else if (topicProduct.isArchived()) {
|
|
1822
1849
|
throw new Error(`topicProduct with id ${topicProductId} is archived`);
|
|
1823
1850
|
}
|
|
1851
|
+
if (serverUtils) {
|
|
1852
|
+
serverUtils.log(topicProductId);
|
|
1853
|
+
serverUtils.updateProgress(10);
|
|
1854
|
+
}
|
|
1824
1855
|
|
|
1825
1856
|
const topicProductPageId = getProductPageIdByCode(topicProduct.sys.id);
|
|
1826
1857
|
const topicProductPage = await getEntryByID(topicProductPageId, "page");
|
|
@@ -1832,6 +1863,10 @@ export const generateTechSpecPdf = async (topicProductId: string) => {
|
|
|
1832
1863
|
);
|
|
1833
1864
|
}
|
|
1834
1865
|
|
|
1866
|
+
if (serverUtils) {
|
|
1867
|
+
serverUtils.updateProgress(20);
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1835
1870
|
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
1836
1871
|
const topicCatalogIds = topicProduct?.fields?.catalogs?.[
|
|
1837
1872
|
defaultEnvironmentLocaleCode
|
|
@@ -1876,25 +1911,47 @@ export const generateTechSpecPdf = async (topicProductId: string) => {
|
|
|
1876
1911
|
: "info@flos.com"),
|
|
1877
1912
|
},
|
|
1878
1913
|
};
|
|
1914
|
+
|
|
1915
|
+
if (serverUtils) {
|
|
1916
|
+
serverUtils.updateProgress(35);
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1879
1919
|
const pdf = await generatePDFByUrl(layoutUrl, "", contents);
|
|
1880
|
-
|
|
1920
|
+
if (pdf) {
|
|
1921
|
+
if (serverUtils) {
|
|
1922
|
+
serverUtils.updateProgress(45);
|
|
1923
|
+
}
|
|
1924
|
+
const s3Url = await savePDFToS3(pdf, fileName, "tech-spec");
|
|
1925
|
+
if (serverUtils) {
|
|
1926
|
+
serverUtils.updateProgress(75);
|
|
1927
|
+
}
|
|
1881
1928
|
|
|
1882
|
-
|
|
1883
|
-
|
|
1929
|
+
log(`Update techSpec field...`);
|
|
1930
|
+
topicProduct.fields = await addFieldValue(topicProduct, "techSpec", s3Url);
|
|
1884
1931
|
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1932
|
+
topicProduct = await topicProduct.update();
|
|
1933
|
+
if (topicProduct.isPublished()) {
|
|
1934
|
+
try {
|
|
1935
|
+
topicProduct = await topicProduct.publish();
|
|
1936
|
+
} catch (err) {
|
|
1937
|
+
log(`Cannot publish entry.`);
|
|
1938
|
+
log(err);
|
|
1939
|
+
}
|
|
1892
1940
|
}
|
|
1893
|
-
}
|
|
1894
1941
|
|
|
1895
|
-
|
|
1942
|
+
if (serverUtils) {
|
|
1943
|
+
serverUtils.updateProgress(100);
|
|
1944
|
+
}
|
|
1896
1945
|
|
|
1897
|
-
|
|
1946
|
+
log(`${topicProductId} techSpec field updated!`);
|
|
1947
|
+
return s3Url;
|
|
1948
|
+
} else {
|
|
1949
|
+
log(
|
|
1950
|
+
`TechSpec PDF generation failed for product: ${topicProductId}!`,
|
|
1951
|
+
"ERROR"
|
|
1952
|
+
);
|
|
1953
|
+
return "";
|
|
1954
|
+
}
|
|
1898
1955
|
};
|
|
1899
1956
|
|
|
1900
1957
|
const getLightModuleAutoDescriptionByProductFields = async (
|
|
@@ -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);
|
|
@@ -526,6 +535,10 @@ export const importSubFamilies = async (
|
|
|
526
535
|
|
|
527
536
|
const nextOffset = Number(offset) + Number(limit);
|
|
528
537
|
|
|
538
|
+
if (serverUtils) {
|
|
539
|
+
serverUtils.updateProgress(100);
|
|
540
|
+
}
|
|
541
|
+
|
|
529
542
|
return {
|
|
530
543
|
offset: nextOffset,
|
|
531
544
|
limit: Number(limit),
|